ember-repl 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/__PRIVATE__.d.ts +2 -0
- package/declarations/__PRIVATE__.d.ts.map +1 -0
- package/declarations/compile/formats/gjs/babel.d.ts +7 -0
- package/declarations/compile/formats/gjs/babel.d.ts.map +1 -0
- package/declarations/compile/formats/gjs/eval.d.ts +8 -0
- package/declarations/compile/formats/gjs/eval.d.ts.map +1 -0
- package/declarations/compile/formats/gjs/index.d.ts +24 -0
- package/declarations/compile/formats/gjs/index.d.ts.map +1 -0
- package/declarations/compile/formats/gjs/known-modules.d.ts +65 -0
- package/declarations/compile/formats/gjs/known-modules.d.ts.map +1 -0
- package/declarations/compile/formats/hbs.d.ts +17 -0
- package/declarations/compile/formats/hbs.d.ts.map +1 -0
- package/declarations/compile/formats/markdown.d.ts +22 -0
- package/declarations/compile/formats/markdown.d.ts.map +1 -0
- package/declarations/compile/formats.d.ts +18 -0
- package/declarations/compile/formats.d.ts.map +1 -0
- package/declarations/compile/index.d.ts +72 -0
- package/declarations/compile/index.d.ts.map +1 -0
- package/declarations/compile/types.d.ts +22 -0
- package/declarations/compile/types.d.ts.map +1 -0
- package/declarations/compile/utils.d.ts +19 -0
- package/declarations/compile/utils.d.ts.map +1 -0
- package/declarations/index.d.ts +4 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/test-support/index.d.ts +2 -0
- package/declarations/test-support/index.d.ts.map +1 -0
- package/dist/__PRIVATE__.js +2 -0
- package/dist/__PRIVATE__.js.map +1 -0
- package/dist/compile/formats/gjs/babel.js +2 -0
- package/dist/compile/formats/gjs/babel.js.map +1 -0
- package/dist/compile/formats/gjs/eval.js +20 -0
- package/dist/compile/formats/gjs/eval.js.map +1 -0
- package/dist/compile/formats/gjs/index.js +98 -0
- package/dist/compile/formats/gjs/index.js.map +1 -0
- package/dist/compile/formats/gjs/known-modules.js +48 -0
- package/dist/compile/formats/gjs/known-modules.js.map +1 -0
- package/dist/compile/formats/hbs.js +100 -0
- package/dist/compile/formats/hbs.js.map +1 -0
- package/dist/compile/formats/markdown.js +259 -0
- package/dist/compile/formats/markdown.js.map +1 -0
- package/dist/compile/formats.js +173 -0
- package/dist/compile/formats.js.map +1 -0
- package/dist/compile/index.js +113 -0
- package/dist/compile/index.js.map +1 -0
- package/dist/compile/types.js +2 -0
- package/dist/compile/types.js.map +1 -0
- package/dist/compile/utils.js +46 -0
- package/dist/compile/utils.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/test-support/index.js +8 -0
- package/dist/test-support/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { resourceFactory, resource, cell } from 'ember-resources';
|
|
2
|
+
import { compileMD, compileGJS, compileHBS } from './formats.js';
|
|
3
|
+
import { nameFor } from './utils.js';
|
|
4
|
+
|
|
5
|
+
const CACHE = new Map();
|
|
6
|
+
const SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compile GitHub-flavored Markdown with GJS support
|
|
10
|
+
* and optionally render gjs-snippets via a `live` meta tag
|
|
11
|
+
* on the code fences.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Compile GJS
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Compile a stateless component using just the template
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This compileMD is a more robust version of the raw compiling used in "formats".
|
|
24
|
+
* This function manages cache, and has events for folks building UIs to hook in to
|
|
25
|
+
*/
|
|
26
|
+
async function compile(text, options) {
|
|
27
|
+
let {
|
|
28
|
+
onSuccess,
|
|
29
|
+
onError,
|
|
30
|
+
onCompileStart
|
|
31
|
+
} = options;
|
|
32
|
+
let id = nameFor(text);
|
|
33
|
+
let existing = CACHE.get(id);
|
|
34
|
+
if (existing) {
|
|
35
|
+
onSuccess(existing);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!SUPPORTED_FORMATS.includes(options.format)) {
|
|
39
|
+
await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await onCompileStart();
|
|
43
|
+
if (!text) {
|
|
44
|
+
await onError('No Input Document yet');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
let result;
|
|
48
|
+
if (options.format === 'glimdown') {
|
|
49
|
+
result = await compileMD(text, options);
|
|
50
|
+
} else if (options.format === 'gjs') {
|
|
51
|
+
result = await compileGJS(text, options.importMap);
|
|
52
|
+
} else if (options.format === 'hbs') {
|
|
53
|
+
result = await compileHBS(text, {
|
|
54
|
+
scope: options.topLevelScope
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (result.error) {
|
|
61
|
+
await onError(result.error.message || `${result.error}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
CACHE.set(id, result.component);
|
|
65
|
+
await onSuccess(result.component);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* By default, this compiles to `glimdown`. A Markdown format which
|
|
74
|
+
* extracts `live` tagged code snippets and compiles them to components.
|
|
75
|
+
*/
|
|
76
|
+
function Compiled(markdownText, maybeOptions) {
|
|
77
|
+
return resource(() => {
|
|
78
|
+
let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;
|
|
79
|
+
let format = (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';
|
|
80
|
+
let options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};
|
|
81
|
+
let input = typeof markdownText === 'function' ? markdownText() : markdownText;
|
|
82
|
+
let ready = cell(false);
|
|
83
|
+
let error = cell();
|
|
84
|
+
let result = cell();
|
|
85
|
+
if (input) {
|
|
86
|
+
compile(input, {
|
|
87
|
+
// narrowing is hard here, but this is an implementation detail
|
|
88
|
+
format: format,
|
|
89
|
+
onSuccess: async component => {
|
|
90
|
+
result.current = component;
|
|
91
|
+
ready.set(true);
|
|
92
|
+
error.set(null);
|
|
93
|
+
},
|
|
94
|
+
onError: async e => {
|
|
95
|
+
error.set(e);
|
|
96
|
+
},
|
|
97
|
+
onCompileStart: async () => {
|
|
98
|
+
ready.set(false);
|
|
99
|
+
},
|
|
100
|
+
...options
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return () => ({
|
|
104
|
+
isReady: ready.current,
|
|
105
|
+
error: error.current,
|
|
106
|
+
component: result.current
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
resourceFactory(Compiled);
|
|
111
|
+
|
|
112
|
+
export { CACHE, Compiled, compile };
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\nimport { nameFor } from './utils.ts';\n\nimport type { CompileResult, UnifiedPlugin } from './types.ts';\nimport type { EvalImportMap, ScopeMap } from './types.ts';\nimport type { ComponentLike } from '@glint/template';\ntype Format = 'glimdown' | 'gjs' | 'hbs';\n\nexport const CACHE = new Map<string, ComponentLike>();\n\ninterface Events {\n onSuccess: (component: ComponentLike) => Promise<unknown> | unknown;\n onError: (error: string) => Promise<unknown> | unknown;\n onCompileStart: () => Promise<unknown> | unknown;\n}\n\ninterface Scope {\n importMap?: EvalImportMap;\n}\n\nconst SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];\n\ninterface GlimdownOptions extends Scope, Events {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n}\n\n/**\n * Compile GitHub-flavored Markdown with GJS support\n * and optionally render gjs-snippets via a `live` meta tag\n * on the code fences.\n */\nexport async function compile(text: string, options: GlimdownOptions): Promise<void>;\n\n/**\n * Compile GJS\n */\nexport async function compile(text: string, options: GJSOptions): Promise<void>;\n\n/**\n * Compile a stateless component using just the template\n */\nexport async function compile(text: string, options: HBSOptions): Promise<void>;\n\n/**\n * This compileMD is a more robust version of the raw compiling used in \"formats\".\n * This function manages cache, and has events for folks building UIs to hook in to\n */\nexport async function compile(\n text: string,\n options: GlimdownOptions | GJSOptions | HBSOptions\n): Promise<void> {\n let { onSuccess, onError, onCompileStart } = options;\n let id = nameFor(text);\n\n let existing = CACHE.get(id);\n\n if (existing) {\n onSuccess(existing);\n\n return;\n }\n\n if (!SUPPORTED_FORMATS.includes(options.format)) {\n await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);\n\n return;\n }\n\n await onCompileStart();\n\n if (!text) {\n await onError('No Input Document yet');\n\n return;\n }\n\n let result: CompileResult;\n\n if (options.format === 'glimdown') {\n result = await processMD(text, options);\n } else if (options.format === 'gjs') {\n result = await processGJS(text, options.importMap);\n } else if (options.format === 'hbs') {\n result = await processHBS(text, {\n scope: options.topLevelScope,\n });\n } else {\n await onError(\n `Unsupported format: ${(options as any).format}. Supported formats: ${SUPPORTED_FORMATS}`\n );\n\n return;\n }\n\n if (result.error) {\n await onError(result.error.message || `${result.error}`);\n\n return;\n }\n\n CACHE.set(id, result.component as ComponentLike);\n\n await onSuccess(result.component as ComponentLike);\n}\n\ntype Input = string | undefined | null;\n\ntype ExtraOptions =\n | {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n importMap?: EvalImportMap;\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'gjs';\n importMap?: EvalImportMap;\n };\n\n/**\n * @internal\n */\nexport interface Value {\n isReady: boolean;\n error: string | null;\n component: ComponentLike;\n}\n\nexport function Compiled(markdownText: Input | (() => Input)): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: ExtraOptions): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => ExtraOptions): Value;\n\n/**\n * By default, this compiles to `glimdown`. A Markdown format which\n * extracts `live` tagged code snippets and compiles them to components.\n */\nexport function Compiled(\n markdownText: Input | (() => Input),\n maybeOptions?: Format | (() => Format) | ExtraOptions | (() => ExtraOptions)\n): Value {\n return resource(() => {\n let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;\n let format =\n (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';\n let options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};\n\n let input = typeof markdownText === 'function' ? markdownText() : markdownText;\n let ready = cell(false);\n let error = cell<string | null>();\n let result = cell<ComponentLike>();\n\n if (input) {\n compile(input, {\n // narrowing is hard here, but this is an implementation detail\n format: format as any,\n onSuccess: async (component) => {\n result.current = component;\n ready.set(true);\n error.set(null);\n },\n onError: async (e) => {\n error.set(e);\n },\n onCompileStart: async () => {\n ready.set(false);\n },\n ...options,\n });\n }\n\n return () => ({\n isReady: ready.current,\n error: error.current,\n component: result.current,\n });\n });\n}\n\nresourceFactory(Compiled);\n"],"names":["CACHE","Map","SUPPORTED_FORMATS","compile","text","options","onSuccess","onError","onCompileStart","id","nameFor","existing","get","includes","format","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","markdownText","maybeOptions","resource","maybeObject","input","ready","cell","current","e","isReady","resourceFactory"],"mappings":";;;;MAcaA,KAAK,GAAG,IAAIC,GAAG,GAAyB;AAYrD,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;;AAmBpD;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,eAAeC,OAAOA,CAC3BC,IAAY,EACZC,OAAkD,EACnC;EACf,IAAI;IAAEC,SAAS;IAAEC,OAAO;AAAEC,IAAAA,cAAAA;AAAe,GAAC,GAAGH,OAAO,CAAA;AACpD,EAAA,IAAII,EAAE,GAAGC,OAAO,CAACN,IAAI,CAAC,CAAA;AAEtB,EAAA,IAAIO,QAAQ,GAAGX,KAAK,CAACY,GAAG,CAACH,EAAE,CAAC,CAAA;AAE5B,EAAA,IAAIE,QAAQ,EAAE;IACZL,SAAS,CAACK,QAAQ,CAAC,CAAA;AAEnB,IAAA,OAAA;AACF,GAAA;EAEA,IAAI,CAACT,iBAAiB,CAACW,QAAQ,CAACR,OAAO,CAACS,MAAM,CAAC,EAAE;IAC/C,MAAMP,OAAO,CAAE,CAAsBF,oBAAAA,EAAAA,OAAO,CAACS,MAAO,CAAA,qBAAA,EAAuBZ,iBAAkB,CAAA,CAAC,CAAC,CAAA;AAE/F,IAAA,OAAA;AACF,GAAA;EAEA,MAAMM,cAAc,EAAE,CAAA;EAEtB,IAAI,CAACJ,IAAI,EAAE;IACT,MAAMG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAEtC,IAAA,OAAA;AACF,GAAA;AAEA,EAAA,IAAIQ,MAAqB,CAAA;AAEzB,EAAA,IAAIV,OAAO,CAACS,MAAM,KAAK,UAAU,EAAE;AACjCC,IAAAA,MAAM,GAAG,MAAMC,S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":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { assert } from '@ember/debug';
|
|
2
|
+
import { pascalCase } from 'change-case';
|
|
3
|
+
import { v5 } from 'uuid';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* a namespace is required for uuid v5
|
|
7
|
+
*
|
|
8
|
+
* it helps generate stable outputs for for any given input.
|
|
9
|
+
*/
|
|
10
|
+
const NAMESPACE = '926f034a-f480-4112-a363-321244f4e5de';
|
|
11
|
+
const DEFAULT_PREFIX = 'ember-repl';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* For any given code block, a reasonably stable name can be
|
|
15
|
+
* generated.
|
|
16
|
+
* This can help with cacheing previously compiled components,
|
|
17
|
+
* and generally allowing a consumer to derive "known references" to user-input
|
|
18
|
+
*/
|
|
19
|
+
function nameFor(code, prefix = DEFAULT_PREFIX) {
|
|
20
|
+
let id = v5(code, NAMESPACE);
|
|
21
|
+
return `${prefix ? `${prefix}-` : ''}${id}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the text for invoking a component with a given name.
|
|
26
|
+
* It is assumed the component takes no arguments, as would be the
|
|
27
|
+
* case in REPLs / Playgrounds for the "root" component.
|
|
28
|
+
*/
|
|
29
|
+
function invocationOf(name) {
|
|
30
|
+
assert(`You must pass a name to invocationOf. Received: \`${name}\``, typeof name === 'string' && name.length > 0);
|
|
31
|
+
if (name.length === 0) {
|
|
32
|
+
throw new Error(`name passed to invocationOf must have non-0 length`);
|
|
33
|
+
}
|
|
34
|
+
return `<${invocationName(name)} />`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)
|
|
39
|
+
* inflection does not support hyphens
|
|
40
|
+
*/
|
|
41
|
+
function invocationName(name) {
|
|
42
|
+
return pascalCase(name).replaceAll('_', '');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { invocationName, invocationOf, nameFor };
|
|
46
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/compile/utils.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { pascalCase } from 'change-case';\nimport { v5 as uuidv5 } from 'uuid';\n\n/**\n * a namespace is required for uuid v5\n *\n * it helps generate stable outputs for for any given input.\n */\nconst NAMESPACE = '926f034a-f480-4112-a363-321244f4e5de';\nconst DEFAULT_PREFIX = 'ember-repl';\n\n/**\n * For any given code block, a reasonably stable name can be\n * generated.\n * This can help with cacheing previously compiled components,\n * and generally allowing a consumer to derive \"known references\" to user-input\n */\nexport function nameFor(code: string, prefix = DEFAULT_PREFIX) {\n let id = uuidv5(code, NAMESPACE);\n\n return `${prefix ? `${prefix}-` : ''}${id}`;\n}\n\n/**\n * Returns the text for invoking a component with a given name.\n * It is assumed the component takes no arguments, as would be the\n * case in REPLs / Playgrounds for the \"root\" component.\n */\nexport function invocationOf(name: string) {\n assert(\n `You must pass a name to invocationOf. Received: \\`${name}\\``,\n typeof name === 'string' && name.length > 0\n );\n\n if (name.length === 0) {\n throw new Error(`name passed to invocationOf must have non-0 length`);\n }\n\n return `<${invocationName(name)} />`;\n}\n\n/**\n * Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)\n * inflection does not support hyphens\n */\nexport function invocationName(name: string) {\n return pascalCase(name).replaceAll('_', '');\n}\n"],"names":["NAMESPACE","DEFAULT_PREFIX","nameFor","code","prefix","id","uuidv5","invocationOf","name","assert","length","Error","invocationName","pascalCase","replaceAll"],"mappings":";;;;AAKA;AACA;AACA;AACA;AACA;AACA,MAAMA,SAAS,GAAG,sCAAsC,CAAA;AACxD,MAAMC,cAAc,GAAG,YAAY,CAAA;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAACC,IAAY,EAAEC,MAAM,GAAGH,cAAc,EAAE;AAC7D,EAAA,IAAII,EAAE,GAAGC,EAAM,CAACH,IAAI,EAAEH,SAAS,CAAC,CAAA;EAEhC,OAAQ,CAAA,EAAEI,MAAM,GAAI,CAAEA,EAAAA,MAAO,GAAE,GAAG,EAAG,CAAEC,EAAAA,EAAG,CAAC,CAAA,CAAA;AAC7C,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,IAAY,EAAE;AACzCC,EAAAA,MAAM,CACH,CAAA,kDAAA,EAAoDD,IAAK,CAAA,EAAA,CAAG,EAC7D,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,CAACE,MAAM,GAAG,CAC5C,CAAC,CAAA;AAED,EAAA,IAAIF,IAAI,CAACE,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,MAAM,IAAIC,KAAK,CAAE,CAAA,kDAAA,CAAmD,CAAC,CAAA;AACvE,GAAA;AAEA,EAAA,OAAQ,CAAGC,CAAAA,EAAAA,cAAc,CAACJ,IAAI,CAAE,CAAI,GAAA,CAAA,CAAA;AACtC,CAAA;;AAEA;AACA;AACA;AACA;AACO,SAASI,cAAcA,CAACJ,IAAY,EAAE;EAC3C,OAAOK,UAAU,CAACL,IAAI,CAAC,CAACM,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAC7C;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { CACHE } from '../compile/index.ts';\n\nexport function clearCompileCache() {\n CACHE.clear();\n}\n"],"names":["clearCompileCache","CACHE","clear"],"mappings":";;AAEO,SAASA,iBAAiBA,GAAG;EAClCC,KAAK,CAACC,KAAK,EAAE,CAAA;AACf;;;;"}
|