diff --git a/src/components/global/Playground/index.tsx b/src/components/global/Playground/index.tsx index 541e510b51e..9e01b1902bb 100644 --- a/src/components/global/Playground/index.tsx +++ b/src/components/global/Playground/index.tsx @@ -85,6 +85,21 @@ interface UsageTargetOptions { files: { [key: string]: MdxContent; }; + /** + * The list of dependencies to use in the Stackblitz example. + * The key is the package name and the value is the version. + * The version must be a valid semver range. + * + * For example: + * ```ts + * dependencies: { + * '@maskito/core': '^0.11.0', + * } + * ``` + */ + dependencies?: { + [key: string]: string; + }; } /** @@ -326,6 +341,7 @@ export default function Playground({ .outerText, })) .reduce((acc, curr) => ({ ...acc, ...curr }), {}); + editorOptions.dependencies = (code[usageTarget] as UsageTargetOptions).dependencies; } switch (usageTarget) { diff --git a/src/components/global/Playground/stackblitz.utils.ts b/src/components/global/Playground/stackblitz.utils.ts index 1fe697a350f..acfcc0adf3b 100644 --- a/src/components/global/Playground/stackblitz.utils.ts +++ b/src/components/global/Playground/stackblitz.utils.ts @@ -19,6 +19,14 @@ export interface EditorOptions { [key: string]: string; }; + /** + * List of dependencies to add to the Stackblitz example. + * The key is the name of the dependency and the value is the version. + */ + dependencies?: { + [key: string]: string; + } + /** * `true` if `ion-app` and `ion-content` should automatically be injected into the * Stackblitz example. @@ -79,6 +87,7 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => { dependencies = { ...dependencies, ...JSON.parse(package_json).dependencies, + ...options?.dependencies, }; } catch (e) { console.error('Failed to parse package.json contents', e); @@ -130,6 +139,7 @@ const openAngularEditor = async (code: string, options?: EditorOptions) => { 'angular.json': defaultFiles[9], 'tsconfig.json': defaultFiles[10], ...options?.files, + ...options?.dependencies, }; const package_json = defaultFiles[11]; @@ -144,6 +154,7 @@ const openAngularEditor = async (code: string, options?: EditorOptions) => { dependencies = { ...dependencies, ...JSON.parse(package_json).dependencies, + ...options?.dependencies, }; } catch (e) { console.error('Failed to parse package.json contents', e); @@ -183,6 +194,7 @@ const openReactEditor = async (code: string, options?: EditorOptions) => { 'package.json': defaultFiles[4], 'package-lock.json': defaultFiles[5], ...options?.files, + ...options?.dependencies, '.stackblitzrc': `{ "startCommand": "yarn run start" }`,