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.
Files changed (53) hide show
  1. package/declarations/__PRIVATE__.d.ts +2 -0
  2. package/declarations/__PRIVATE__.d.ts.map +1 -0
  3. package/declarations/compile/formats/gjs/babel.d.ts +7 -0
  4. package/declarations/compile/formats/gjs/babel.d.ts.map +1 -0
  5. package/declarations/compile/formats/gjs/eval.d.ts +8 -0
  6. package/declarations/compile/formats/gjs/eval.d.ts.map +1 -0
  7. package/declarations/compile/formats/gjs/index.d.ts +24 -0
  8. package/declarations/compile/formats/gjs/index.d.ts.map +1 -0
  9. package/declarations/compile/formats/gjs/known-modules.d.ts +65 -0
  10. package/declarations/compile/formats/gjs/known-modules.d.ts.map +1 -0
  11. package/declarations/compile/formats/hbs.d.ts +17 -0
  12. package/declarations/compile/formats/hbs.d.ts.map +1 -0
  13. package/declarations/compile/formats/markdown.d.ts +22 -0
  14. package/declarations/compile/formats/markdown.d.ts.map +1 -0
  15. package/declarations/compile/formats.d.ts +18 -0
  16. package/declarations/compile/formats.d.ts.map +1 -0
  17. package/declarations/compile/index.d.ts +72 -0
  18. package/declarations/compile/index.d.ts.map +1 -0
  19. package/declarations/compile/types.d.ts +22 -0
  20. package/declarations/compile/types.d.ts.map +1 -0
  21. package/declarations/compile/utils.d.ts +19 -0
  22. package/declarations/compile/utils.d.ts.map +1 -0
  23. package/declarations/index.d.ts +4 -0
  24. package/declarations/index.d.ts.map +1 -0
  25. package/declarations/test-support/index.d.ts +2 -0
  26. package/declarations/test-support/index.d.ts.map +1 -0
  27. package/dist/__PRIVATE__.js +2 -0
  28. package/dist/__PRIVATE__.js.map +1 -0
  29. package/dist/compile/formats/gjs/babel.js +2 -0
  30. package/dist/compile/formats/gjs/babel.js.map +1 -0
  31. package/dist/compile/formats/gjs/eval.js +20 -0
  32. package/dist/compile/formats/gjs/eval.js.map +1 -0
  33. package/dist/compile/formats/gjs/index.js +98 -0
  34. package/dist/compile/formats/gjs/index.js.map +1 -0
  35. package/dist/compile/formats/gjs/known-modules.js +48 -0
  36. package/dist/compile/formats/gjs/known-modules.js.map +1 -0
  37. package/dist/compile/formats/hbs.js +100 -0
  38. package/dist/compile/formats/hbs.js.map +1 -0
  39. package/dist/compile/formats/markdown.js +259 -0
  40. package/dist/compile/formats/markdown.js.map +1 -0
  41. package/dist/compile/formats.js +173 -0
  42. package/dist/compile/formats.js.map +1 -0
  43. package/dist/compile/index.js +113 -0
  44. package/dist/compile/index.js.map +1 -0
  45. package/dist/compile/types.js +2 -0
  46. package/dist/compile/types.js.map +1 -0
  47. package/dist/compile/utils.js +46 -0
  48. package/dist/compile/utils.js.map +1 -0
  49. package/dist/index.js +3 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/test-support/index.js +8 -0
  52. package/dist/test-support/index.js.map +1 -0
  53. package/package.json +1 -1
@@ -0,0 +1,100 @@
1
+ import { setComponentTemplate } from '@ember/component';
2
+ import _TO from '@ember/component/template-only';
3
+ import { array, concat, fn, get, hash } from '@ember/helper';
4
+ import { on } from '@ember/modifier';
5
+ import { createTemplateFactory } from '@ember/template-factory';
6
+ import { importSync } from '@embroider/macros';
7
+ import { nameFor } from '../utils.js';
8
+
9
+ /* eslint-disable @typescript-eslint/no-explicit-any */
10
+ // import { precompileJSON } from '@glimmer/compiler';
11
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
+ // @ts-ignore
13
+ // These things are pre-bundled in the old system.
14
+ // ember-template-compiler defines them in AMD/requirejs
15
+ const {
16
+ precompileJSON
17
+ } = importSync('@glimmer/compiler');
18
+ const {
19
+ getTemplateLocals
20
+ } = importSync('@glimmer/syntax');
21
+
22
+ /**
23
+ * compile a template with an empty scope
24
+ * to use components, helpers, etc, you will need to compile with JS
25
+ *
26
+ * (templates alone do not have a way to import / define complex structures)
27
+ */
28
+ function compileHBS(template, options = {}) {
29
+ let name = nameFor(template);
30
+ let component;
31
+ let error;
32
+ try {
33
+ component = setComponentTemplate(compileTemplate(template, {
34
+ moduleName: options.moduleName || name,
35
+ ...options
36
+ }), _TO(options.moduleName || name));
37
+ } catch (e) {
38
+ error = e;
39
+ }
40
+ return {
41
+ name,
42
+ component,
43
+ error
44
+ };
45
+ }
46
+ /**
47
+ * The reason why we can't use precompile directly is because of this:
48
+ * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132
49
+ *
50
+ * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.
51
+ * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,
52
+ * which means that *everything* is undefined.
53
+ */
54
+ function compileTemplate(source, {
55
+ moduleName,
56
+ scope = {}
57
+ }) {
58
+ let localScope = {
59
+ array,
60
+ concat,
61
+ fn,
62
+ get,
63
+ hash,
64
+ on,
65
+ ...scope
66
+ };
67
+ let locals = getTemplateLocals(source);
68
+ let options = {
69
+ strictMode: true,
70
+ moduleName,
71
+ locals,
72
+ isProduction: false,
73
+ meta: {
74
+ moduleName
75
+ }
76
+ };
77
+
78
+ // Copied from @glimmer/compiler/lib/compiler#precompile
79
+ let [block, usedLocals] = precompileJSON(source, options);
80
+ let usedScope = usedLocals.map(key => {
81
+ let value = localScope[key];
82
+ if (!value) {
83
+ throw new Error(`Attempt to use ${key} in compiled hbs, but it was not available in scope. ` + `Available scope includes: ${Object.keys(localScope)}`);
84
+ }
85
+ return value;
86
+ });
87
+ let blockJSON = JSON.stringify(block);
88
+ let templateJSONObject = {
89
+ id: moduleName,
90
+ block: blockJSON,
91
+ moduleName: moduleName ?? '(dynamically compiled component)',
92
+ scope: () => usedScope,
93
+ isStrictMode: true
94
+ };
95
+ let factory = createTemplateFactory(templateJSONObject);
96
+ return factory;
97
+ }
98
+
99
+ export { compileHBS };
100
+ //# sourceMappingURL=hbs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hbs.js","sources":["../../../src/compile/formats/hbs.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// import { precompileJSON } from '@glimmer/compiler';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { setComponentTemplate } from '@ember/component';\nimport templateOnlyComponent from '@ember/component/template-only';\nimport { array, concat, fn, get, hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport { importSync } from '@embroider/macros';\n\nimport { nameFor } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nconst { precompileJSON } = importSync('@glimmer/compiler') as any;\nconst { getTemplateLocals } = importSync('@glimmer/syntax') as any;\n\n/**\n * compile a template with an empty scope\n * to use components, helpers, etc, you will need to compile with JS\n *\n * (templates alone do not have a way to import / define complex structures)\n */\nexport function compileHBS(template: string, options: CompileTemplateOptions = {}): CompileResult {\n let name = nameFor(template);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n component = setComponentTemplate(\n compileTemplate(template, { moduleName: options.moduleName || name, ...options }),\n templateOnlyComponent(options.moduleName || name)\n ) as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\ninterface CompileTemplateOptions {\n /**\n * Used for debug viewing\n */\n moduleName?: string;\n scope?: Record<string, unknown>;\n}\n\n/**\n * The reason why we can't use precompile directly is because of this:\n * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132\n *\n * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.\n * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,\n * which means that *everything* is undefined.\n */\nfunction compileTemplate(source: string, { moduleName, scope = {} }: CompileTemplateOptions) {\n let localScope = { array, concat, fn, get, hash, on, ...scope } as any;\n let locals = getTemplateLocals(source);\n\n let options = {\n strictMode: true,\n moduleName,\n locals,\n isProduction: false,\n meta: { moduleName },\n };\n\n // Copied from @glimmer/compiler/lib/compiler#precompile\n let [block, usedLocals] = precompileJSON(source, options);\n\n let usedScope = usedLocals.map((key: string) => {\n let value = localScope[key];\n\n if (!value) {\n throw new Error(\n `Attempt to use ${key} in compiled hbs, but it was not available in scope. ` +\n `Available scope includes: ${Object.keys(localScope)}`\n );\n }\n\n return value;\n });\n\n let blockJSON = JSON.stringify(block);\n let templateJSONObject = {\n id: moduleName,\n block: blockJSON,\n moduleName: moduleName ?? '(dynamically compiled component)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n let factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["precompileJSON","importSync","getTemplateLocals","compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","strictMode","isProduction","meta","block","usedLocals","usedScope","map","key","value","Error","Object","keys","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAeA;AACA;AACA,MAAM;AAAEA,EAAAA,cAAAA;AAAe,CAAC,GAAGC,UAAU,CAAC,mBAAmB,CAAQ,CAAA;AACjE,MAAM;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,GAAGD,UAAU,CAAC,iBAAiB,CAAQ,CAAA;;AAElE;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,UAAUA,CAACC,QAAgB,EAAEC,OAA+B,GAAG,EAAE,EAAiB;AAChG,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,QAAQ,CAAC,CAAA;AAC5B,EAAA,IAAII,SAAoC,CAAA;AACxC,EAAA,IAAIC,KAAwB,CAAA;EAE5B,IAAI;AACFD,IAAAA,SAAS,GAAGE,oBAAoB,CAC9BC,eAAe,CAACP,QAAQ,EAAE;AAAEQ,MAAAA,UAAU,EAAEP,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MAAM,CAACC,IAAI,CAACnB,UAAU,CAAE,EACzD,CAAC,CAAA;AACH,KAAA;AAEA,IAAA,OAAOgB,KAAK,CAAA;AACd,GAAC,CAAC,CAAA;AAEF,EAAA,IAAII,SAAS,GAAGC,IAAI,CAACC,SAAS,CAACX,KAAK,CAAC,CAAA;AACrC,EAAA,IAAIY,kBAAkB,GAAG;AACvBC,IAAAA,EAAE,EAAE7B,UAAU;AACdgB,IAAAA,KAAK,EAAES,SAAS;IAChBzB,UAAU,EAAEA,UAAU,IAAI,kCAAkC;IAC5DI,KAAK,EAAEA,MAAMc,SAAS;AACtBY,IAAAA,YAAY,EAAE,IAAA;GACf,CAAA;AAED,EAAA,IAAIC,OAAO,GAAGC,qBAAqB,CAACJ,kBAAkB,CAAC,CAAA;AAEvD,EAAA,OAAOG,OAAO,CAAA;AAChB;;;;"}
@@ -0,0 +1,259 @@
1
+ import rehypeRaw from 'rehype-raw';
2
+ import rehypeStringify from 'rehype-stringify';
3
+ import remarkGfm from 'remark-gfm';
4
+ import remarkParse from 'remark-parse';
5
+ import remarkRehype from 'remark-rehype';
6
+ import { unified } from 'unified';
7
+ import { visit } from 'unist-util-visit';
8
+ import { nameFor, invocationOf } from '../utils.js';
9
+
10
+ const GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');
11
+ const GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');
12
+ const ALLOWED_LANGUAGES = ['gjs', 'hbs'];
13
+ const escapeCurlies = node => {
14
+ if ('value' in node && node.value) {
15
+ node.value = node.value.replace(/{{/g, '\\{{');
16
+ }
17
+ if ('children' in node && node.children) {
18
+ node.children.forEach(child => escapeCurlies(child));
19
+ }
20
+ if (!node.data) {
21
+ return;
22
+ }
23
+ if ('hChildren' in node.data && Array.isArray(node.data['hChildren'])) {
24
+ node.data['hChildren'].forEach(escapeCurlies);
25
+ return;
26
+ }
27
+ };
28
+ function isLive(meta) {
29
+ return meta.includes('live');
30
+ }
31
+ function isPreview(meta) {
32
+ return meta.includes('preview');
33
+ }
34
+ function isBelow(meta) {
35
+ return meta.includes('below');
36
+ }
37
+
38
+ // TODO: extract and publish remark plugin
39
+ function liveCodeExtraction(options = {}) {
40
+ let {
41
+ copyComponent,
42
+ snippets,
43
+ demo
44
+ } = options;
45
+ let {
46
+ classList: snippetClasses
47
+ } = snippets || {};
48
+ let {
49
+ classList: demoClasses
50
+ } = demo || {};
51
+ snippetClasses ??= [];
52
+ demoClasses ??= [];
53
+ function isRelevantCode(node) {
54
+ if (node.type !== 'code') return false;
55
+ let {
56
+ meta,
57
+ lang
58
+ } = node;
59
+ meta = meta?.trim();
60
+ if (!meta || !lang) return false;
61
+ if (!meta.includes('live')) {
62
+ return false;
63
+ }
64
+ if (!ALLOWED_LANGUAGES.includes(lang)) return false;
65
+ return true;
66
+ }
67
+ let copyNode = {
68
+ type: 'html',
69
+ value: copyComponent
70
+ };
71
+ function enhance(code) {
72
+ code.data ??= {};
73
+ code.data['hProperties'] ??= {};
74
+ // This is secret-to-us-only API, so we don't really care about the type
75
+ code.data['hProperties'][GLIMDOWN_PREVIEW] = true;
76
+ return {
77
+ data: {
78
+ hProperties: {
79
+ className: snippetClasses
80
+ }
81
+ },
82
+ type: 'div',
83
+ hProperties: {
84
+ className: snippetClasses
85
+ },
86
+ children: [code, copyNode]
87
+ };
88
+ }
89
+ function flatReplaceAt(array, index, replacement) {
90
+ array.splice(index, 1, ...replacement);
91
+ }
92
+
93
+ // because we mutate the tree as we iterate,
94
+ // we need to make sure we don't loop forever
95
+ const seen = new Set();
96
+ return function transformer(tree, file) {
97
+ visit(tree, ['code'], function (node, index, parent) {
98
+ if (parent === null || parent === undefined) return;
99
+ if (index === null || index === undefined) return;
100
+ if (!isRelevantCode(node)) {
101
+ let enhanced = enhance(node);
102
+ parent.children[index] = enhanced;
103
+ return 'skip';
104
+ }
105
+ if (seen.has(node)) return 'skip';
106
+ seen.add(node);
107
+ let {
108
+ meta,
109
+ lang,
110
+ value
111
+ } = node;
112
+ if (!meta) return 'skip';
113
+ if (!lang) return 'skip';
114
+ file.data.liveCode ??= [];
115
+ let code = value.trim();
116
+ let name = nameFor(code);
117
+ let invocation = invocationOf(name);
118
+ let shadow = options.shadowComponent;
119
+ let wrapInShadow = shadow && !meta?.includes('no-shadow');
120
+ if (wrapInShadow) {
121
+ invocation = `<${shadow}>${invocation}</${shadow}>`;
122
+ }
123
+ let invokeNode = {
124
+ type: 'html',
125
+ data: {
126
+ hProperties: {
127
+ [GLIMDOWN_RENDER]: true
128
+ }
129
+ },
130
+ value: `<div class="${demoClasses}">${invocation}</div>`
131
+ };
132
+ let wrapper = enhance(node);
133
+ file.data.liveCode.push({
134
+ lang,
135
+ name,
136
+ code
137
+ });
138
+ let live = isLive(meta);
139
+ let preview = isPreview(meta);
140
+ let below = isBelow(meta);
141
+ if (live && preview && below) {
142
+ flatReplaceAt(parent.children, index, [wrapper, invokeNode]);
143
+ return 'skip';
144
+ }
145
+ if (live && preview) {
146
+ flatReplaceAt(parent.children, index, [invokeNode, wrapper]);
147
+ return 'skip';
148
+ }
149
+ if (live) {
150
+ parent.children[index] = invokeNode;
151
+ return 'skip';
152
+ }
153
+ parent.children[index] = wrapper;
154
+ return;
155
+ });
156
+ };
157
+ }
158
+ function buildCompiler(options) {
159
+ let compiler = unified().use(remarkParse).use(remarkGfm);
160
+
161
+ // TODO: we only want to do this when we have pre > code.
162
+ // code can exist inline.
163
+ compiler = compiler.use(liveCodeExtraction, {
164
+ snippets: {
165
+ classList: ['glimdown-snippet', 'relative']
166
+ },
167
+ demo: {
168
+ classList: ['glimdown-render']
169
+ },
170
+ copyComponent: options?.CopyComponent,
171
+ shadowComponent: options?.ShadowComponent
172
+ });
173
+
174
+ /**
175
+ * If this were "use"d after `remarkRehype`,
176
+ * remark is gone, and folks would need to work with rehype trees
177
+ */
178
+ if (options.remarkPlugins) {
179
+ options.remarkPlugins.forEach(plugin => {
180
+ compiler = compiler.use(plugin);
181
+ });
182
+ }
183
+
184
+ // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))
185
+ // remark rehype is needed to convert markdown to HTML
186
+ // However, it also changes all the nodes, so we need another pass
187
+ // to make sure our Glimmer-aware nodes are in tact
188
+ compiler = compiler.use(remarkRehype, {
189
+ allowDangerousHtml: true
190
+ });
191
+
192
+ // Convert invocables to raw format, so Glimmer can invoke them
193
+ compiler = compiler.use(() => tree => {
194
+ visit(tree, function (node) {
195
+ // We rely on an implicit transformation of data.hProperties => properties
196
+ let properties = node.properties;
197
+ if (properties?.[GLIMDOWN_PREVIEW]) {
198
+ // Have to sanitize anything Glimmer could try to render
199
+ escapeCurlies(node);
200
+ return 'skip';
201
+ }
202
+ if (node.type === 'element' || 'tagName' in node && node.tagName === 'code') {
203
+ if (properties?.[GLIMDOWN_RENDER]) {
204
+ node.type = 'glimmer_raw';
205
+ return;
206
+ }
207
+ escapeCurlies(node);
208
+ return 'skip';
209
+ }
210
+ if (node.type === 'text' || node.type === 'raw') {
211
+ // definitively not the better way, but this is supposed to detect "glimmer" nodes
212
+ if ('value' in node && typeof node.value === 'string' && node.value.match(/<\/?[_A-Z:0-9].*>/g)) {
213
+ node.type = 'glimmer_raw';
214
+ }
215
+ node.type = 'glimmer_raw';
216
+ return 'skip';
217
+ }
218
+ return;
219
+ });
220
+ });
221
+ if (options.rehypePlugins) {
222
+ options.rehypePlugins.forEach(plugin => {
223
+ compiler = compiler.use(plugin);
224
+ });
225
+ }
226
+ compiler = compiler.use(rehypeRaw, {
227
+ passThrough: ['glimmer_raw', 'raw']
228
+ }).use(() => tree => {
229
+ visit(tree, 'glimmer_raw', node => {
230
+ node.type = 'raw';
231
+ });
232
+ });
233
+
234
+ // Finally convert to string! oofta!
235
+ compiler = compiler.use(rehypeStringify, {
236
+ collapseEmptyAttributes: true,
237
+ closeSelfClosing: true,
238
+ allowParseErrors: true,
239
+ allowDangerousCharacters: true,
240
+ allowDangerousHtml: true
241
+ });
242
+ return compiler;
243
+ }
244
+ /**
245
+ * @internal not under semver
246
+ */
247
+ async function parseMarkdown(input, options = {}) {
248
+ let markdownCompiler = buildCompiler(options);
249
+ let processed = await markdownCompiler.process(input);
250
+ let liveCode = processed.data.liveCode || [];
251
+ let templateOnly = processed.toString();
252
+ return {
253
+ templateOnlyGlimdown: templateOnly,
254
+ blocks: liveCode
255
+ };
256
+ }
257
+
258
+ export { parseMarkdown };
259
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sources":["../../../src/compile/formats/markdown.ts"],"sourcesContent":["import rehypeRaw from 'rehype-raw';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport { unified } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nimport { invocationOf, nameFor } from '../utils.ts';\n\nimport type { UnifiedPlugin } from '../types.ts';\nimport type { Node } from 'hast';\nimport type { Code, Text } from 'mdast';\nimport type { Parent } from 'unist';\nimport type { VFile } from 'vfile';\n\nexport interface ExtractedCode {\n name: string;\n code: string;\n lang: string;\n}\n\nexport interface LiveCodeExtraction {\n templateOnlyGlimdown: string;\n blocks: ExtractedCode[];\n}\ntype LiveData = {\n liveCode?: ExtractedCode[];\n};\ntype VFileWithMeta = VFile & {\n data: LiveData;\n};\n\ninterface Options {\n snippets?: {\n classList?: string[];\n };\n demo?: {\n classList?: string[];\n };\n copyComponent?: string;\n shadowComponent?: string;\n}\n\nconst GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');\nconst GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');\nconst ALLOWED_LANGUAGES = ['gjs', 'hbs'] as const;\n\ntype AllowedLanguage = (typeof ALLOWED_LANGUAGES)[number];\ntype RelevantCode = Omit<Code, 'lang'> & { lang: AllowedLanguage };\n\nconst escapeCurlies = (node: Text | Parent) => {\n if ('value' in node && node.value) {\n node.value = node.value.replace(/{{/g, '\\\\{{');\n }\n\n if ('children' in node && node.children) {\n node.children.forEach((child) => escapeCurlies(child as Parent));\n }\n\n if (!node.data) {\n return;\n }\n\n if ('hChildren' in node.data && Array.isArray(node.data['hChildren'])) {\n node.data['hChildren'].forEach(escapeCurlies);\n\n return;\n }\n};\n\nfunction isLive(meta: string) {\n return meta.includes('live');\n}\n\nfunction isPreview(meta: string) {\n return meta.includes('preview');\n}\n\nfunction isBelow(meta: string) {\n return meta.includes('below');\n}\n\n// TODO: extract and publish remark plugin\nfunction liveCodeExtraction(options: Options = {}) {\n let { copyComponent, snippets, demo } = options;\n let { classList: snippetClasses } = snippets || {};\n let { classList: demoClasses } = demo || {};\n\n snippetClasses ??= [];\n demoClasses ??= [];\n\n function isRelevantCode(node: Code): node is RelevantCode {\n if (node.type !== 'code') return false;\n\n let { meta, lang } = node;\n\n meta = meta?.trim();\n\n if (!meta || !lang) return false;\n\n if (!meta.includes('live')) {\n return false;\n }\n\n if (!(ALLOWED_LANGUAGES as unknown as string[]).includes(lang)) return false;\n\n return true;\n }\n\n let copyNode = {\n type: 'html',\n value: copyComponent,\n };\n\n function enhance(code: Code) {\n code.data ??= {};\n (code.data as any)['hProperties'] ??= {};\n // This is secret-to-us-only API, so we don't really care about the type\n (code.data as any)['hProperties'][GLIMDOWN_PREVIEW] = true;\n\n return {\n data: {\n hProperties: { className: snippetClasses },\n },\n type: 'div',\n hProperties: { className: snippetClasses },\n children: [code, copyNode],\n };\n }\n\n function flatReplaceAt<T>(array: T[], index: number, replacement: T[]) {\n array.splice(index, 1, ...replacement);\n }\n\n // because we mutate the tree as we iterate,\n // we need to make sure we don't loop forever\n const seen = new Set();\n\n return function transformer(tree: Parent, file: VFileWithMeta) {\n visit(tree, ['code'], function (node, index, parent) {\n if (parent === null || parent === undefined) return;\n if (index === null || index === undefined) return;\n\n if (!isRelevantCode(node as Code)) {\n let enhanced = enhance(node as Code);\n\n parent.children[index] = enhanced;\n\n return 'skip';\n }\n\n if (seen.has(node)) return 'skip';\n\n seen.add(node);\n\n let { meta, lang, value } = node as Code;\n\n if (!meta) return 'skip';\n if (!lang) return 'skip';\n\n file.data.liveCode ??= [];\n\n let code = value.trim();\n let name = nameFor(code);\n let invocation = invocationOf(name);\n\n let shadow = options.shadowComponent;\n\n let wrapInShadow = shadow && !meta?.includes('no-shadow');\n\n if (wrapInShadow) {\n invocation = `<${shadow}>${invocation}</${shadow}>`;\n }\n\n let invokeNode = {\n type: 'html',\n data: {\n hProperties: { [GLIMDOWN_RENDER]: true },\n },\n value: `<div class=\"${demoClasses}\">${invocation}</div>`,\n };\n\n let wrapper = enhance(node as Code);\n\n file.data.liveCode.push({\n lang,\n name,\n code,\n });\n\n let live = isLive(meta);\n let preview = isPreview(meta);\n let below = isBelow(meta);\n\n if (live && preview && below) {\n flatReplaceAt(parent.children, index, [wrapper, invokeNode]);\n\n return 'skip';\n }\n\n if (live && preview) {\n flatReplaceAt(parent.children, index, [invokeNode, wrapper]);\n\n return 'skip';\n }\n\n if (live) {\n parent.children[index] = invokeNode;\n\n return 'skip';\n }\n\n parent.children[index] = wrapper;\n\n return;\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\n\n // TODO: we only want to do this when we have pre > code.\n // code can exist inline.\n compiler = compiler.use(liveCodeExtraction, {\n snippets: {\n classList: ['glimdown-snippet', 'relative'],\n },\n demo: {\n classList: ['glimdown-render'],\n },\n copyComponent: options?.CopyComponent,\n shadowComponent: options?.ShadowComponent,\n });\n\n /**\n * If this were \"use\"d after `remarkRehype`,\n * remark is gone, and folks would need to work with rehype trees\n */\n if (options.remarkPlugins) {\n options.remarkPlugins.forEach((plugin) => {\n compiler = compiler.use(plugin) as any;\n });\n }\n\n // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))\n // remark rehype is needed to convert markdown to HTML\n // However, it also changes all the nodes, so we need another pass\n // to make sure our Glimmer-aware nodes are in tact\n compiler = compiler.use(remarkRehype, { allowDangerousHtml: true });\n\n // Convert invocables to raw format, so Glimmer can invoke them\n compiler = compiler.use(() => (tree: Node) => {\n visit(tree, function (node) {\n // We rely on an implicit transformation of data.hProperties => properties\n let properties = (node as any).properties;\n\n if (properties?.[GLIMDOWN_PREVIEW]) {\n // Have to sanitize anything Glimmer could try to render\n escapeCurlies(node as Parent);\n\n return 'skip';\n }\n\n if (node.type === 'element' || ('tagName' in node && node.tagName === 'code')) {\n if (properties?.[GLIMDOWN_RENDER]) {\n node.type = 'glimmer_raw';\n\n return;\n }\n\n escapeCurlies(node as Parent);\n\n return 'skip';\n }\n\n if (node.type === 'text' || node.type === 'raw') {\n // definitively not the better way, but this is supposed to detect \"glimmer\" nodes\n if (\n 'value' in node &&\n typeof node.value === 'string' &&\n node.value.match(/<\\/?[_A-Z:0-9].*>/g)\n ) {\n node.type = 'glimmer_raw';\n }\n\n node.type = 'glimmer_raw';\n\n return 'skip';\n }\n\n return;\n });\n });\n\n if (options.rehypePlugins) {\n options.rehypePlugins.forEach((plugin) => {\n compiler = compiler.use(plugin) as any;\n });\n }\n\n compiler = compiler.use(rehypeRaw, { passThrough: ['glimmer_raw', 'raw'] }).use(() => (tree) => {\n visit(tree, 'glimmer_raw', (node: Node) => {\n node.type = 'raw';\n });\n });\n\n // Finally convert to string! oofta!\n compiler = compiler.use(rehypeStringify, {\n collapseEmptyAttributes: true,\n closeSelfClosing: true,\n allowParseErrors: true,\n allowDangerousCharacters: true,\n allowDangerousHtml: true,\n }) as any;\n\n return compiler as ReturnType<typeof unified>;\n}\n\ninterface ParseMarkdownOptions {\n CopyComponent?: string;\n ShadowComponent?: string;\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n}\n\n/**\n * @internal not under semver\n */\nexport async function parseMarkdown(\n input: string,\n options: ParseMarkdownOptions = {}\n): Promise<LiveCodeExtraction> {\n let markdownCompiler = buildCompiler(options);\n let processed = await markdownCompiler.process(input);\n let liveCode = (processed.data as LiveData).liveCode || [];\n let templateOnly = processed.toString();\n\n return { templateOnlyGlimdown: templateOnly, blocks: liveCode };\n}\n"],"names":["GLIMDOWN_PREVIEW","Symbol","GLIMDOWN_RENDER","ALLOWED_LANGUAGES","escapeCurlies","node","value","replace","children","forEach","child","data","Array","isArray","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","type","lang","trim","copyNode","enhance","code","hProperties","className","flatReplaceAt","array","index","replacement","splice","seen","Set","transformer","tree","file","visit","parent","undefined","enhanced","has","add","liveCode","name","nameFor","invocation","invocationOf","shadow","shadowComponent","wrapInShadow","invokeNode","wrapper","push","live","preview","below","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","CopyComponent","ShadowComponent","remarkPlugins","plugin","remarkRehype","allowDangerousHtml","properties","tagName","match","rehypePlugins","rehypeRaw","passThrough","rehypeStringify","collapseEmptyAttributes","closeSelfClosing","allowParseErrors","allowDangerousCharacters","parseMarkdown","input","markdownCompiler","processed","process","templateOnly","toString","templateOnlyGlimdown","blocks"],"mappings":";;;;;;;;;AA4CA,MAAMA,gBAAgB,GAAGC,MAAM,CAAC,sBAAsB,CAAC,CAAA;AACvD,MAAMC,eAAe,GAAGD,MAAM,CAAC,qBAAqB,CAAC,CAAA;AACrD,MAAME,iBAAiB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAA;AAKjD,MAAMC,aAAa,GAAIC,IAAmB,IAAK;AAC7C,EAAA,IAAI,OAAO,IAAIA,IAAI,IAAIA,IAAI,CAACC,KAAK,EAAE;AACjCD,IAAAA,IAAI,CAACC,KAAK,GAAGD,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAChD,GAAA;AAEA,EAAA,IAAI,UAAU,IAAIF,IAAI,IAAIA,IAAI,CAACG,QAAQ,EAAE;IACvCH,IAAI,CAACG,QAAQ,CAACC,OAAO,CAAEC,KAAK,IAAKN,aAAa,CAACM,KAAe,CAAC,CAAC,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IAAI,EAAE,CAAA;AAC1D,EAAA,IAAI0C,YAAY,GAAGF,SAAS,CAACG,QAAQ,EAAE,CAAA;EAEvC,OAAO;AAAEC,IAAAA,oBAAoB,EAAEF,YAAY;AAAEG,IAAAA,MAAM,EAAE7C,QAAAA;GAAU,CAAA;AACjE;;;;"}
@@ -0,0 +1,173 @@
1
+ import { invocationName } from './utils.js';
2
+
3
+ async function compileGJSArray(js, importMap) {
4
+ let modules = await Promise.all(js.map(async ({
5
+ code
6
+ }) => {
7
+ return await compileGJS(code, importMap);
8
+ }));
9
+ return modules;
10
+ }
11
+ async function compileGJS(gjsInput, importMap) {
12
+ try {
13
+ let {
14
+ compileJS
15
+ } = await import('./formats/gjs/index.js');
16
+ return await compileJS(gjsInput, importMap);
17
+ } catch (error) {
18
+ return {
19
+ error: error,
20
+ name: 'unknown'
21
+ };
22
+ }
23
+ }
24
+ async function compileHBS(hbsInput, options) {
25
+ try {
26
+ let {
27
+ compileHBS
28
+ } = await import('./formats/hbs.js');
29
+ return compileHBS(hbsInput, options);
30
+ } catch (error) {
31
+ return {
32
+ error: error,
33
+ name: 'unknown'
34
+ };
35
+ }
36
+ }
37
+ async function extractScope(liveCode, options) {
38
+ let scope = [];
39
+ let hbs = liveCode.filter(code => code.lang === 'hbs');
40
+ let js = liveCode.filter(code => ['js', 'gjs'].includes(code.lang));
41
+ if (js.length > 0) {
42
+ let compiled = await compileGJSArray(js, options?.importMap);
43
+ await Promise.all(compiled.map(async info => {
44
+ // using web worker + import maps is not available yet (need firefox support)
45
+ // (and to somehow be able to point at npm)
46
+ //
47
+ // if ('importPath' in info) {
48
+ // return scope.push({
49
+ // moduleName: name,
50
+ // component: await import(/* webpackIgnore: true */ info.importPath),
51
+ // });
52
+ // }
53
+
54
+ return scope.push(info);
55
+ }));
56
+ }
57
+ for (let {
58
+ code
59
+ } of hbs) {
60
+ let compiled = await compileHBS(code, {
61
+ scope: options?.topLevelScope
62
+ });
63
+ scope.push(compiled);
64
+ }
65
+ return scope;
66
+ }
67
+ async function compileMD(glimdownInput, options) {
68
+ let topLevelScope = options?.topLevelScope ?? {};
69
+ let rootTemplate;
70
+ let liveCode;
71
+ let scope = [];
72
+
73
+ /**
74
+ * Step 1: Convert Markdown To HTML (Ember).
75
+ *
76
+ * The remark plugin, remark-code-extra also extracts
77
+ * and transforms the code blocks we care about.
78
+ *
79
+ * These blocks will be compiled through babel and eval'd so the
80
+ * compiled rootTemplate can invoke them
81
+ */
82
+ try {
83
+ let {
84
+ parseMarkdown
85
+ } = await import('./formats/markdown.js');
86
+ let {
87
+ templateOnlyGlimdown,
88
+ blocks
89
+ } = await parseMarkdown(glimdownInput, {
90
+ CopyComponent: options?.CopyComponent,
91
+ ShadowComponent: options?.ShadowComponent,
92
+ remarkPlugins: options?.remarkPlugins,
93
+ rehypePlugins: options?.rehypePlugins
94
+ });
95
+ rootTemplate = templateOnlyGlimdown;
96
+ liveCode = blocks;
97
+ } catch (error) {
98
+ return {
99
+ error: error,
100
+ name: 'unknown'
101
+ };
102
+ }
103
+
104
+ /**
105
+ * Step 2: Compile the live code samples
106
+ */
107
+ if (liveCode.length > 0) {
108
+ try {
109
+ scope = await extractScope(liveCode, options);
110
+ } catch (error) {
111
+ console.info({
112
+ scope
113
+ });
114
+ console.error(error);
115
+ return {
116
+ error: error,
117
+ rootTemplate,
118
+ name: 'unknown'
119
+ };
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Make sure non of our snippets errored
125
+ *
126
+ * TODO: for these errors, report them differently so that we
127
+ * can render the 'Ember' and still highlight the correct line?
128
+ * or maybe there is a way to highlight in the editor instead?
129
+ */
130
+ for (let {
131
+ error,
132
+ component
133
+ } of scope) {
134
+ if (!component) {
135
+ if (error) {
136
+ return {
137
+ error,
138
+ rootTemplate,
139
+ name: 'unknown'
140
+ };
141
+ }
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Step 4: Compile the Ember Template
147
+ */
148
+ try {
149
+ let localScope = scope.reduce((accum, {
150
+ component,
151
+ name
152
+ }) => {
153
+ accum[invocationName(name)] = component;
154
+ return accum;
155
+ }, {});
156
+ return await compileHBS(rootTemplate, {
157
+ moduleName: 'DynamicRootTemplate',
158
+ scope: {
159
+ ...topLevelScope,
160
+ ...localScope
161
+ }
162
+ });
163
+ } catch (error) {
164
+ return {
165
+ error: error,
166
+ rootTemplate,
167
+ name: 'unknown'
168
+ };
169
+ }
170
+ }
171
+
172
+ export { compileGJS, compileHBS, compileMD };
173
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sources":["../../src/compile/formats.ts"],"sourcesContent":["import { invocationName } from './utils.ts';\n\nimport type { ExtractedCode } from './formats/markdown.ts';\nimport type { CompileResult, UnifiedPlugin } from './types.ts';\nimport type { EvalImportMap, ScopeMap } from './types.ts';\n\nasync function compileGJSArray(js: { code: string }[], importMap?: EvalImportMap) {\n let modules = await Promise.all(\n js.map(async ({ code }) => {\n return await compileGJS(code, importMap);\n })\n );\n\n return modules;\n}\n\nexport async function compileGJS(\n gjsInput: string,\n importMap?: EvalImportMap\n): Promise<CompileResult> {\n try {\n let { compileJS } = await import('./formats/gjs/index.ts');\n\n return await compileJS(gjsInput, importMap);\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n}\n\nexport async function compileHBS(\n hbsInput: string,\n options?: {\n moduleName?: string;\n scope?: Record<string, unknown>;\n }\n): Promise<CompileResult> {\n try {\n let { compileHBS } = await import('./formats/hbs.ts');\n\n return compileHBS(hbsInput, options);\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n}\n\nasync function extractScope(\n liveCode: ExtractedCode[],\n options?: {\n importMap?: EvalImportMap;\n topLevelScope?: ScopeMap;\n }\n): Promise<CompileResult[]> {\n let scope: CompileResult[] = [];\n\n let hbs = liveCode.filter((code) => code.lang === 'hbs');\n let js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));\n\n if (js.length > 0) {\n let compiled = await compileGJSArray(js, options?.importMap);\n\n await Promise.all(\n compiled.map(async (info) => {\n // using web worker + import maps is not available yet (need firefox support)\n // (and to somehow be able to point at npm)\n //\n // if ('importPath' in info) {\n // return scope.push({\n // moduleName: name,\n // component: await import(/* webpackIgnore: true */ info.importPath),\n // });\n // }\n\n return scope.push(info);\n })\n );\n }\n\n for (let { code } of hbs) {\n let compiled = await compileHBS(code, { scope: options?.topLevelScope });\n\n scope.push(compiled);\n }\n\n return scope;\n}\n\nexport async function compileMD(\n glimdownInput: string,\n options?: {\n importMap?: EvalImportMap;\n topLevelScope?: ScopeMap;\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n CopyComponent?: string;\n ShadowComponent?: string;\n }\n): Promise<CompileResult & { rootTemplate?: string }> {\n let topLevelScope = options?.topLevelScope ?? {};\n let rootTemplate: string;\n let liveCode: ExtractedCode[];\n let scope: CompileResult[] = [];\n\n /**\n * Step 1: Convert Markdown To HTML (Ember).\n *\n * The remark plugin, remark-code-extra also extracts\n * and transforms the code blocks we care about.\n *\n * These blocks will be compiled through babel and eval'd so the\n * compiled rootTemplate can invoke them\n */\n try {\n let { parseMarkdown } = await import('./formats/markdown.ts');\n let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\n ShadowComponent: options?.ShadowComponent,\n remarkPlugins: options?.remarkPlugins,\n rehypePlugins: options?.rehypePlugins,\n });\n\n rootTemplate = templateOnlyGlimdown;\n liveCode = blocks;\n } catch (error) {\n return { error: error as Error, name: 'unknown' };\n }\n\n /**\n * Step 2: Compile the live code samples\n */\n if (liveCode.length > 0) {\n try {\n scope = await extractScope(liveCode, options);\n } catch (error) {\n console.info({ scope });\n console.error(error);\n\n return { error: error as Error, rootTemplate, name: 'unknown' };\n }\n }\n\n /**\n * Make sure non of our snippets errored\n *\n * TODO: for these errors, report them differently so that we\n * can render the 'Ember' and still highlight the correct line?\n * or maybe there is a way to highlight in the editor instead?\n */\n for (let { error, component } of scope) {\n if (!component) {\n if (error) {\n return { error, rootTemplate, name: 'unknown' };\n }\n }\n }\n\n /**\n * Step 4: Compile the Ember Template\n */\n try {\n let localScope = scope.reduce(\n (accum, { component, name }) => {\n accum[invocationName(name)] = component;\n\n return accum;\n },\n {} as Record<string, unknown>\n );\n\n return await compileHBS(rootTemplate, {\n moduleName: 'DynamicRootTemplate',\n scope: {\n ...topLevelScope,\n ...localScope,\n },\n });\n } catch (error) {\n return { error: error as Error, rootTemplate, name: 'unknown' };\n }\n}\n"],"names":["compileGJSArray","js","importMap","modules","Promise","all","map","code","compileGJS","gjsInput","compileJS","error","name","compileHBS","hbsInput","options","extractScope","liveCode","scope","hbs","filter","lang","includes","length","compiled","info","push","topLevelScope","compileMD","glimdownInput","rootTemplate","parseMarkdown","templateOnlyGlimdown","blocks","CopyComponent","ShadowComponent","remarkPlugins","rehypePlugins","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAMA,eAAeA,eAAeA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAChF,IAAIC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC7BJ,EAAE,CAACK,GAAG,CAAC,OAAO;AAAEC,IAAAA,IAAAA;AAAK,GAAC,KAAK;AACzB,IAAA,OAAO,MAAMC,UAAU,CAACD,IAAI,EAAEL,SAAS,CAAC,CAAA;AAC1C,GAAC,CACH,CAAC,CAAA;AAED,EAAA,OAAOC,OAAO,CAAA;AAChB,CAAA;AAEO,eAAeK,UAAUA,CAC9BC,QAAgB,EAChBP,SAAyB,EACD;EACxB,IAAI;IACF,IAAI;AAAEQ,MAAAA,SAAAA;AAAU,KAAC,GAAG,MAAM,OAAO,wBAAwB,CAAC,CAAA;AAE1D,IAAA,OAAO,MAAMA,SAAS,CAACD,QAAQ,EAAEP,SAAS,CAAC,CAAA;GAC5C,CAAC,OAAOS,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CA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