ember-repl 4.2.1 → 4.3.0
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/compile/formats/gjs/known-modules.d.ts +1 -22
- package/declarations/compile/formats/gjs/known-modules.d.ts.map +1 -1
- package/dist/compile/formats/gjs/index.js.map +1 -1
- package/dist/compile/formats/hbs.js.map +1 -1
- package/dist/compile/formats/markdown.js +13 -13
- package/dist/compile/formats/markdown.js.map +1 -1
- package/dist/compile/index.js +1 -1
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/utils.js.map +1 -1
- package/package.json +36 -36
- package/src/compile/formats/markdown.ts +13 -13
- package/src/compile/index.ts +1 -1
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
/// <reference types="ember-source/types/stable/@ember/component/template-only" />
|
|
2
|
-
/// <reference types="ember-source/types/stable/@ember/application" />
|
|
3
|
-
/// <reference types="ember-source/types/stable/@ember/array" />
|
|
4
|
-
/// <reference types="ember-source/types/stable/@ember/component" />
|
|
5
|
-
/// <reference types="ember-source/types/stable/@ember/component/helper" />
|
|
6
|
-
/// <reference types="ember-source/types/stable/@ember/debug" />
|
|
7
|
-
/// <reference types="ember-source/types/stable/@ember/destroyable" />
|
|
8
|
-
/// <reference types="ember-source/types/stable/@ember/helper" />
|
|
9
|
-
/// <reference types="ember-source/types/stable/@ember/modifier" />
|
|
10
|
-
/// <reference types="ember-source/types/stable/@ember/object" />
|
|
11
|
-
/// <reference types="ember-source/types/stable/@ember/runloop" />
|
|
12
|
-
/// <reference types="ember-source/types/stable/@ember/service" />
|
|
13
|
-
/// <reference types="ember-source/types/stable/@ember/routing/service-ext" />
|
|
14
|
-
/// <reference types="ember-source/types/stable/@ember/template-factory" />
|
|
15
|
-
/// <reference types="ember-source/types/stable/@ember/utils" />
|
|
16
|
-
/// <reference types="ember-source/types/stable/@ember/template" />
|
|
17
|
-
/// <reference types="ember-source/types/stable/@ember/owner" />
|
|
18
|
-
/// <reference types="ember-source/types/stable/@ember/controller/owner-ext" />
|
|
19
|
-
/// <reference types="ember-source/types/stable/@ember/routing/owner-ext" />
|
|
20
|
-
/// <reference types="ember-source/types/stable/@ember/service/owner-ext" />
|
|
21
|
-
/// <reference types="ember-source/types/stable/@glimmer/tracking" />
|
|
22
1
|
/**
|
|
23
2
|
* We need to import and hang on to these references so that they
|
|
24
3
|
* don't get optimized away during deploy
|
|
@@ -45,7 +24,7 @@ export declare const modules: {
|
|
|
45
24
|
'@ember/array': typeof _array;
|
|
46
25
|
'@ember/component': typeof _EmberComponent;
|
|
47
26
|
'@ember/component/helper': typeof _EmberComponentHelper;
|
|
48
|
-
'@ember/component/template-only': <S>(moduleName?: string
|
|
27
|
+
'@ember/component/template-only': <S>(moduleName?: string, name?: string) => import("@ember/component/template-only").TemplateOnlyComponent<S>;
|
|
49
28
|
'@ember/debug': typeof _debug;
|
|
50
29
|
'@ember/destroyable': typeof _destroyable;
|
|
51
30
|
'@ember/helper': typeof _helpers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/known-modules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/known-modules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,eAAe,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAEvC,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;CAoBnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/compile/formats/gjs/index.ts"],"sourcesContent":["import { importSync } from '@embroider/macros';\n\nimport babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';\n\nimport { nameFor } from '../../utils.ts';\nimport { evalSnippet } from './eval.ts';\n\nimport type { CompileResult } from '../../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\n/**\n * @public\n * Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.\n * The returned component can be invoked explicitly in the consuming project.\n *\n * SEE: README for example usage\n *\n * @param {string} code: the code to be compiled\n * @param {Object} extraModules: map of import paths to modules. This isn't needed\n * for classic ember projects, but for strict static ember projects, extraModules\n * will need to be pasesd if compileJS is intended to be used in a styleguide or\n * if there are additional modules that could be imported in the passed `code`.\n *\n * Later on, imports that are not present by default (ember/glimmer) or that\n * are not provided by extraModules will be searched on npm to see if a package\n * needs to be downloaded before running the `code` / invoking the component\n */\nexport async function compileJS(\n code: string,\n extraModules?: Record<string, unknown>\n): Promise<CompileResult> {\n let name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n let compiled = await transpile({ code: code, name });\n\n if (!compiled) {\n throw new Error(`Compiled output is missing`);\n }\n\n component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\nasync function transpile({ code: input, name }: Info) {\n let preprocessed = await preprocess(input, name);\n let result = await transform(preprocessed, name);\n\n if (!result) {\n return;\n }\n\n let { code } = result;\n\n return code;\n}\n\nimport type { Babel } from './babel.ts';\n\nconst compiler = importSync('ember-source/dist/ember-template-compiler.js');\n\nlet processor: any;\nlet fetchingPromise: Promise<any>;\n\nasync function preprocess(input: string, name: string): Promise<string> {\n if (!fetchingPromise) {\n fetchingPromise = import('content-tag');\n }\n\n if (!processor) {\n let { Preprocessor } = await fetchingPromise;\n\n processor = new Preprocessor();\n }\n\n return processor.process(input, `${name}.js`);\n}\n\nasync function transform(\n intermediate: string,\n name: string,\n options: any = {}\n): Promise<ReturnType<Babel['transform']>> {\n let babel = (await import('@babel/standalone')) as Babel;\n\n return babel.transform(intermediate, {\n filename: `${name}.js`,\n plugins: [\n // [babelPluginIntermediateGJS],\n [\n babelPluginEmberTemplateCompilation,\n {\n compiler,\n },\n ],\n [babel.availablePlugins['proposal-decorators'], { legacy: true }],\n [babel.availablePlugins['proposal-class-properties']],\n ],\n presets: [\n [\n babel.availablePresets['env'],\n {\n // false -- keeps ES Modules\n modules: 'cjs',\n targets: { esmodules: true },\n forceAllTransforms: false,\n ...options,\n },\n ],\n ],\n });\n}\n"],"names":["compileJS","code","extraModules","name","nameFor","component","error","compiled","transpile","Error","evalSnippet","default","e","input","preprocessed","preprocess","result","transform","compiler","importSync","processor","fetchingPromise","Preprocessor","process","intermediate","options","babel","filename","plugins","babelPluginEmberTemplateCompilation","availablePlugins","legacy","presets","availablePresets","modules","targets","esmodules","forceAllTransforms"],"mappings":";;;;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,SAASA,CAC7BC,IAAY,EACZC,YAAsC,EACd;AACxB,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,IAAI,CAAC,CAAA;AACxB,EAAA,IAAII,SAAoC,CAAA;AACxC,EAAA,IAAIC,KAAwB,CAAA;EAE5B,IAAI;AACF,IAAA,IAAIC,QAAQ,GAAG,MAAMC,SAAS,CAAC;AAAEP,MAAAA,IAAI,EAAEA,IAAI;AAAEE,MAAAA,IAAAA;AAAK,KAAC,CAAC,CAAA;IAEpD,IAAI,CAACI,QAAQ,EAAE;AACb,MAAA,MAAM,IAAIE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/compile/formats/gjs/index.ts"],"sourcesContent":["import { importSync } from '@embroider/macros';\n\nimport babelPluginEmberTemplateCompilation from 'babel-plugin-ember-template-compilation';\n\nimport { nameFor } from '../../utils.ts';\nimport { evalSnippet } from './eval.ts';\n\nimport type { CompileResult } from '../../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\n/**\n * @public\n * Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.\n * The returned component can be invoked explicitly in the consuming project.\n *\n * SEE: README for example usage\n *\n * @param {string} code: the code to be compiled\n * @param {Object} extraModules: map of import paths to modules. This isn't needed\n * for classic ember projects, but for strict static ember projects, extraModules\n * will need to be pasesd if compileJS is intended to be used in a styleguide or\n * if there are additional modules that could be imported in the passed `code`.\n *\n * Later on, imports that are not present by default (ember/glimmer) or that\n * are not provided by extraModules will be searched on npm to see if a package\n * needs to be downloaded before running the `code` / invoking the component\n */\nexport async function compileJS(\n code: string,\n extraModules?: Record<string, unknown>\n): Promise<CompileResult> {\n let name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n let compiled = await transpile({ code: code, name });\n\n if (!compiled) {\n throw new Error(`Compiled output is missing`);\n }\n\n component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\nasync function transpile({ code: input, name }: Info) {\n let preprocessed = await preprocess(input, name);\n let result = await transform(preprocessed, name);\n\n if (!result) {\n return;\n }\n\n let { code } = result;\n\n return code;\n}\n\nimport type { Babel } from './babel.ts';\n\nconst compiler = importSync('ember-source/dist/ember-template-compiler.js');\n\nlet processor: any;\nlet fetchingPromise: Promise<any>;\n\nasync function preprocess(input: string, name: string): Promise<string> {\n if (!fetchingPromise) {\n fetchingPromise = import('content-tag');\n }\n\n if (!processor) {\n let { Preprocessor } = await fetchingPromise;\n\n processor = new Preprocessor();\n }\n\n return processor.process(input, `${name}.js`);\n}\n\nasync function transform(\n intermediate: string,\n name: string,\n options: any = {}\n): Promise<ReturnType<Babel['transform']>> {\n let babel = (await import('@babel/standalone')) as Babel;\n\n return babel.transform(intermediate, {\n filename: `${name}.js`,\n plugins: [\n // [babelPluginIntermediateGJS],\n [\n babelPluginEmberTemplateCompilation,\n {\n compiler,\n },\n ],\n [babel.availablePlugins['proposal-decorators'], { legacy: true }],\n [babel.availablePlugins['proposal-class-properties']],\n ],\n presets: [\n [\n babel.availablePresets['env'],\n {\n // false -- keeps ES Modules\n modules: 'cjs',\n targets: { esmodules: true },\n forceAllTransforms: false,\n ...options,\n },\n ],\n ],\n });\n}\n"],"names":["compileJS","code","extraModules","name","nameFor","component","error","compiled","transpile","Error","evalSnippet","default","e","input","preprocessed","preprocess","result","transform","compiler","importSync","processor","fetchingPromise","Preprocessor","process","intermediate","options","babel","filename","plugins","babelPluginEmberTemplateCompilation","availablePlugins","legacy","presets","availablePresets","modules","targets","esmodules","forceAllTransforms"],"mappings":";;;;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,SAASA,CAC7BC,IAAY,EACZC,YAAsC,EACd;AACxB,EAAA,IAAIC,IAAI,GAAGC,OAAO,CAACH,IAAI,CAAC,CAAA;AACxB,EAAA,IAAII,SAAoC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,CAACD,SAAS,EAAE;IACd,IAAI;AAAEE,MAAAA,YAAAA;KAAc,GAAG,MAAMD,eAAe,CAAA;AAE5CD,IAAAA,SAAS,GAAG,IAAIE,YAAY,EAAE,CAAA;AAChC,GAAA;EAEA,OAAOF,SAAS,CAACG,OAAO,CAACV,KAAK,EAAE,CAAA,EAAGV,IAAI,CAAA,GAAA,CAAK,CAAC,CAAA;AAC/C,CAAA;AAEA,eAAec,SAASA,CACtBO,YAAoB,EACpBrB,IAAY,EACZsB,OAAY,GAAG,EAAE,EACwB;AACzC,EAAA,IAAIC,KAAK,GAAI,MAAM,OAAO,mBAAmB,CAAW,CAAA;AAExD,EAAA,OAAOA,KAAK,CAACT,SAAS,CAACO,YAAY,EAAE;IACnCG,QAAQ,EAAE,CAAGxB,EAAAA,IAAI,CAAK,GAAA,CAAA;AACtByB,IAAAA,OAAO,EAAE;AACP;AACA,IAAA,CACEC,mCAAmC,EACnC;AACEX,MAAAA,QAAAA;KACD,CACF,EACD,CAACQ,KAAK,CAACI,gBAAgB,CAAC,qBAAqB,CAAC,EAAE;AAAEC,MAAAA,MAAM,EAAE,IAAA;KAAM,CAAC,EACjE,CAACL,KAAK,CAACI,gBAAgB,CAAC,2BAA2B,CAAC,CAAC,CACtD;IACDE,OAAO,EAAE,CACP,CACEN,KAAK,CAACO,gBAAgB,CAAC,KAAK,CAAC,EAC7B;AACE;AACAC,MAAAA,OAAO,EAAE,KAAK;AACdC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,SAAS,EAAE,IAAA;OAAM;AAC5BC,MAAAA,kBAAkB,EAAE,KAAK;MACzB,GAAGZ,OAAAA;AACL,KAAC,CACF,CAAA;AAEL,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -1 +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,OAAO,CAACO,UAAU,IAAIN,IAAI;MAAE,GAAGD,OAAAA;KAAS,CAAC,EACjFQ,GAAqB,CAACR,OAAO,CAACO,UAAU,IAAIN,IAAI,CAClD,CAAkB,CAAA;GACnB,CAAC,OAAOQ,CAAC,EAAE;AACVL,IAAAA,KAAK,GAAGK,CAAsB,CAAA;AAChC,GAAA;EAEA,OAAO;IAAER,IAAI;IAAEE,SAAS;AAAEC,IAAAA,KAAAA;GAAO,CAAA;AACnC,CAAA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAeA,CAACI,MAAc,EAAE;EAAEH,UAAU;AAAEI,EAAAA,KAAK,GAAG,EAAC;AAA0B,CAAC,EAAE;AAC3F,EAAA,IAAIC,UAAU,GAAG;IAAEC,KAAK;IAAEC,MAAM;IAAEC,EAAE;IAAEC,GAAG;IAAEC,IAAI;IAAEC,EAAE;IAAE,GAAGP,KAAAA;GAAc,CAAA;AACtE,EAAA,IAAIQ,MAAM,GAAGtB,iBAAiB,CAACa,MAAM,CAAC,CAAA;AAEtC,EAAA,IAAIV,OAAO,GAAG;AACZoB,IAAAA,UAAU,EAAE,IAAI;IAChBb,UAAU;IACVY,MAAM;AACNE,IAAAA,YAAY,EAAE,KAAK;AACnBC,IAAAA,IAAI,EAAE;AAAEf,MAAAA,UAAAA;AAAW,KAAA;GACpB,CAAA;;AAED;EACA,IAAI,CAACgB,KAAK,EAAEC,UAAU,CAAC,GAAG7B,cAAc,CAACe,MAAM,EAAEV,OAAO,CAAC,CAAA;AAEzD,EAAA,IAAIyB,SAAS,GAAGD,UAAU,CAACE,GAAG,CAAEC,GAAW,IAAK;AAC9C,IAAA,IAAIC,KAAK,GAAGhB,UAAU,CAACe,GAAG,CAAC,CAAA;IAE3B,IAAI,CAACC,KAAK,EAAE;AACV,MAAA,MAAM,IAAIC,KAAK,
|
|
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,OAAO,CAACO,UAAU,IAAIN,IAAI;MAAE,GAAGD,OAAAA;KAAS,CAAC,EACjFQ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,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;;;;"}
|
|
@@ -159,19 +159,6 @@ function sanitizeForGlimmer( /* options */
|
|
|
159
159
|
function buildCompiler(options) {
|
|
160
160
|
let compiler = unified().use(remarkParse).use(remarkGfm);
|
|
161
161
|
|
|
162
|
-
// TODO: we only want to do this when we have pre > code.
|
|
163
|
-
// code can exist inline.
|
|
164
|
-
compiler = compiler.use(liveCodeExtraction, {
|
|
165
|
-
snippets: {
|
|
166
|
-
classList: ['glimdown-snippet', 'relative']
|
|
167
|
-
},
|
|
168
|
-
demo: {
|
|
169
|
-
classList: ['glimdown-render']
|
|
170
|
-
},
|
|
171
|
-
copyComponent: options?.CopyComponent,
|
|
172
|
-
shadowComponent: options?.ShadowComponent
|
|
173
|
-
});
|
|
174
|
-
|
|
175
162
|
/**
|
|
176
163
|
* If this were "use"d after `remarkRehype`,
|
|
177
164
|
* remark is gone, and folks would need to work with rehype trees
|
|
@@ -185,6 +172,19 @@ function buildCompiler(options) {
|
|
|
185
172
|
});
|
|
186
173
|
}
|
|
187
174
|
|
|
175
|
+
// TODO: we only want to do this when we have pre > code.
|
|
176
|
+
// code can exist inline.
|
|
177
|
+
compiler = compiler.use(liveCodeExtraction, {
|
|
178
|
+
snippets: {
|
|
179
|
+
classList: ['glimdown-snippet', 'relative']
|
|
180
|
+
},
|
|
181
|
+
demo: {
|
|
182
|
+
classList: ['glimdown-render']
|
|
183
|
+
},
|
|
184
|
+
copyComponent: options?.CopyComponent,
|
|
185
|
+
shadowComponent: options?.ShadowComponent
|
|
186
|
+
});
|
|
187
|
+
|
|
188
188
|
// .use(() => (tree) => visit(tree, (node) => console.log('i', node)))
|
|
189
189
|
// remark rehype is needed to convert markdown to HTML
|
|
190
190
|
// However, it also changes all the nodes, so we need another pass
|
|
@@ -1 +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\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 sanitizeForGlimmer(/* options */) {\n return (tree: Parent) => {\n visit(tree, 'element', (node: Parent) => {\n if ('tagName' in node) {\n if (node.tagName !== 'pre') return;\n\n visit(node, 'text', (textNode: Text) => {\n if ('value' in textNode && textNode.value) {\n textNode.value = textNode.value.replace(/{{/g, '\\\\{{');\n }\n });\n\n return 'skip';\n }\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 // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p 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 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 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 // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p 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 compiler = compiler.use(sanitizeForGlimmer);\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","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","node","type","lang","trim","copyNode","value","enhance","code","data","hProperties","className","children","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","sanitizeForGlimmer","tagName","textNode","replace","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","CopyComponent","ShadowComponent","remarkPlugins","forEach","plugin","p","Array","isArray","remarkRehype","allowDangerousHtml","properties","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,SAASC,MAAMA,CAACC,IAAY,EAAE;AAC5B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAA;AAEA,SAASC,SAASA,CAACF,IAAY,EAAE;AAC/B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACjC,CAAA;AAEA,S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ACbjF,OAA6B,GAAG,EAAE,EACL;AAC7B,EAAA,IAAIkF,gBAAgB,GAAG5B,aAAa,CAACtD,OAAO,CAAC,CAAA;EAC7C,IAAImF,SAAS,GAAG,MAAMD,gBAAgB,CAACE,OAAO,CAACH,KAAK,CAAC,CAAA;EACrD,IAAI7C,QAAQ,GAAI+C,SAAS,CAACnE,IAAI,CAAcoB,QAAQ,IAAI,EAAE,CAAA;AAC1D,EAAA,IAAIiD,YAAY,GAAGF,SAAS,CAACG,QAAQ,EAAE,CAAA;EAEvC,OAAO;AAAEC,IAAAA,oBAAoB,EAAEF,YAAY;AAAEG,IAAAA,MAAM,EAAEpD,QAAAA;GAAU,CAAA;AACjE;;;;"}
|
|
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\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 sanitizeForGlimmer(/* options */) {\n return (tree: Parent) => {\n visit(tree, 'element', (node: Parent) => {\n if ('tagName' in node) {\n if (node.tagName !== 'pre') return;\n\n visit(node, 'text', (textNode: Text) => {\n if ('value' in textNode && textNode.value) {\n textNode.value = textNode.value.replace(/{{/g, '\\\\{{');\n }\n });\n\n return 'skip';\n }\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\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 // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\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 // .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 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 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 // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p 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 compiler = compiler.use(sanitizeForGlimmer);\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","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","node","type","lang","trim","copyNode","value","enhance","code","data","hProperties","className","children","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","sanitizeForGlimmer","tagName","textNode","replace","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","remarkPlugins","forEach","plugin","p","Array","isArray","CopyComponent","ShadowComponent","remarkRehype","allowDangerousHtml","properties","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,SAASC,MAAMA,CAACC,IAAY,EAAE;AAC5B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC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AE,IAAA;AACtB,GAAC,CAAQ,CAAA;AAET,EAAA,OAAOd,QAAQ,CAAA;AACjB,CAAA;AASA;AACA;AACA;AACO,eAAeyB,aAAaA,CACjCC,KAAa,EACbjF,OAA6B,GAAG,EAAE,EACL;AAC7B,EAAA,IAAIkF,gBAAgB,GAAG5B,aAAa,CAACtD,OAAO,CAAC,CAAA;EAC7C,IAAImF,SAAS,GAAG,MAAMD,gBAAgB,CAACE,OAAO,CAACH,KAAK,CAAC,CAAA;EACrD,IAAI7C,QAAQ,GAAI+C,SAAS,CAACnE,IAAI,CAAcoB,QAAQ,IAAI,EAAE,CAAA;AAC1D,EAAA,IAAIiD,YAAY,GAAGF,SAAS,CAACG,QAAQ,EAAE,CAAA;EAEvC,OAAO;AAAEC,IAAAA,oBAAoB,EAAEF,YAAY;AAAEG,IAAAA,MAAM,EAAEpD,QAAAA;GAAU,CAAA;AACjE;;;;"}
|
package/dist/compile/index.js
CHANGED
|
@@ -1 +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 // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\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 rehypePlugins?: 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","
|
|
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 // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n\n // Make overloads easier?\n remarkPlugins?: never;\n rehypePlugins?: never;\n CopyComponent?: never;\n ShadowComponent?: never;\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(`${options.format}:${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 rehypePlugins?: 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","format","existing","get","includes","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;;AA+BpD;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,cAAA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AK,EAAE;AACb;AACApB,QAAAA,MAAM,EAAEA,MAAa;QACrBL,SAAS,EAAE,MAAOmB,SAAS,IAAK;UAC9BV,MAAM,CAACmB,OAAO,GAAGT,SAAS,CAAA;AAC1BO,UAAAA,KAAK,CAACR,GAAG,CAAC,IAAI,CAAC,CAAA;AACfF,UAAAA,KAAK,CAACE,GAAG,CAAC,IAAI,CAAC,CAAA;SAChB;QACDjB,OAAO,EAAE,MAAO4B,CAAC,IAAK;AACpBb,UAAAA,KAAK,CAACE,GAAG,CAACW,CAAC,CAAC,CAAA;SACb;QACD3B,cAAc,EAAE,YAAY;AAC1BwB,UAAAA,KAAK,CAACR,GAAG,CAAC,KAAK,CAAC,CAAA;SACjB;QACD,GAAGnB,OAAAA;AACL,OAAC,CAAC,CAAA;AACJ,KAAA;AAEA,IAAA,OAAO,OAAO;MACZ+B,OAAO,EAAEJ,KAAK,CAACE,OAAO;MACtBZ,KAAK,EAAEA,KAAK,CAACY,OAAO;MACpBT,SAAS,EAAEV,MAAM,CAACmB,OAAAA;AACpB,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AACJ,CAAA;AAEAG,eAAe,CAACX,QAAQ,CAAC;;;;"}
|
|
@@ -1 +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,
|
|
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,OAAO,CAAA,EAAGI,MAAM,GAAG,CAAGA,EAAAA,MAAM,GAAG,GAAG,EAAE,CAAGC,EAAAA,EAAE,CAAE,CAAA,CAAA;AAC7C,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,IAAY,EAAE;AACzCC,EAAAA,MAAM,CACJ,CAAA,kDAAA,EAAqDD,IAAI,CAAA,EAAA,CAAI,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,CAAC,CAAA,kDAAA,CAAoD,CAAC,CAAA;AACvE,GAAA;AAEA,EAAA,OAAO,CAAIC,CAAAA,EAAAA,cAAc,CAACJ,IAAI,CAAC,CAAK,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-repl",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Addon for enabling REPL and Playground creation with Ember/Glimmer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"addon-main.cjs"
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@babel/helper-plugin-utils": "^7.
|
|
64
|
-
"@babel/standalone": "^7.
|
|
65
|
-
"@embroider/addon-shim": "1.8.
|
|
66
|
-
"@embroider/macros": "1.
|
|
67
|
-
"babel-import-util": "^
|
|
68
|
-
"babel-plugin-ember-template-compilation": "^2.2.
|
|
63
|
+
"@babel/helper-plugin-utils": "^7.24.5",
|
|
64
|
+
"@babel/standalone": "^7.24.5",
|
|
65
|
+
"@embroider/addon-shim": "1.8.9",
|
|
66
|
+
"@embroider/macros": "1.16.3",
|
|
67
|
+
"babel-import-util": "^3.0.0",
|
|
68
|
+
"babel-plugin-ember-template-compilation": "^2.2.5",
|
|
69
69
|
"broccoli-file-creator": "^2.1.1",
|
|
70
|
-
"change-case": "^5.4.
|
|
70
|
+
"change-case": "^5.4.4",
|
|
71
71
|
"common-tags": "^1.8.2",
|
|
72
72
|
"content-tag": "^1.2.1",
|
|
73
|
-
"decorator-transforms": "^
|
|
74
|
-
"ember-resources": "
|
|
73
|
+
"decorator-transforms": "^2.0.0",
|
|
74
|
+
"ember-resources": "^7.0.1",
|
|
75
75
|
"line-column": "^1.0.2",
|
|
76
76
|
"magic-string": "^0.30.6",
|
|
77
77
|
"mdast": "^3.0.0",
|
|
@@ -87,53 +87,53 @@
|
|
|
87
87
|
"vfile": "^6.0.1"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@babel/core": "^7.
|
|
91
|
-
"@babel/plugin-transform-typescript": "^7.
|
|
90
|
+
"@babel/core": "^7.24.5",
|
|
91
|
+
"@babel/plugin-transform-typescript": "^7.24.5",
|
|
92
92
|
"@babel/preset-typescript": "^7.23.3",
|
|
93
|
-
"@babel/types": "^7.
|
|
93
|
+
"@babel/types": "^7.24.5",
|
|
94
94
|
"@ember/test-helpers": "^3.2.1",
|
|
95
95
|
"@ember/test-waiters": "^3.1.0",
|
|
96
|
-
"@embroider/addon-dev": "4.
|
|
97
|
-
"@glimmer/compiler": "
|
|
96
|
+
"@embroider/addon-dev": "4.3.1",
|
|
97
|
+
"@glimmer/compiler": "^0.92.0",
|
|
98
98
|
"@glimmer/component": "^1.1.2",
|
|
99
|
-
"@glimmer/interfaces": "
|
|
100
|
-
"@glimmer/reference": "
|
|
101
|
-
"@glimmer/syntax": "
|
|
99
|
+
"@glimmer/interfaces": "^0.92.0",
|
|
100
|
+
"@glimmer/reference": "^0.92.0",
|
|
101
|
+
"@glimmer/syntax": "^0.92.0",
|
|
102
102
|
"@glimmer/tracking": "^1.1.2",
|
|
103
|
-
"@glimmer/util": "^0.
|
|
104
|
-
"@glint/core": "1.
|
|
105
|
-
"@glint/environment-ember-loose": "1.
|
|
106
|
-
"@glint/environment-ember-template-imports": "1.
|
|
107
|
-
"@glint/template": "1.
|
|
108
|
-
"@nullvoxpopuli/eslint-configs": "^
|
|
103
|
+
"@glimmer/util": "^0.92.0",
|
|
104
|
+
"@glint/core": "1.4.0",
|
|
105
|
+
"@glint/environment-ember-loose": "1.4.0",
|
|
106
|
+
"@glint/environment-ember-template-imports": "1.4.0",
|
|
107
|
+
"@glint/template": "1.4.0",
|
|
108
|
+
"@nullvoxpopuli/eslint-configs": "^4.0.0",
|
|
109
109
|
"@rollup/plugin-babel": "^6.0.4",
|
|
110
110
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
111
|
-
"@tsconfig/ember": "^3.0.
|
|
111
|
+
"@tsconfig/ember": "^3.0.7",
|
|
112
112
|
"@types/babel__core": "^7.20.5",
|
|
113
113
|
"@types/babel__standalone": "^7.1.7",
|
|
114
114
|
"@types/babel__traverse": "^7.20.4",
|
|
115
115
|
"@types/hast": "^3.0.3",
|
|
116
|
-
"@types/mdast": "^4.0.
|
|
116
|
+
"@types/mdast": "^4.0.4",
|
|
117
117
|
"@types/unist": "^3.0.2",
|
|
118
118
|
"@types/uuid": "^9.0.8",
|
|
119
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
120
|
-
"@typescript-eslint/parser": "^
|
|
119
|
+
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
120
|
+
"@typescript-eslint/parser": "^7.9.0",
|
|
121
121
|
"concurrently": "^8.2.2",
|
|
122
122
|
"ember-resources": "^7.0.0",
|
|
123
|
-
"ember-source": ">= 5.
|
|
124
|
-
"ember-template-imports": "^
|
|
125
|
-
"ember-template-lint": "^
|
|
123
|
+
"ember-source": ">= 5.9.0",
|
|
124
|
+
"ember-template-imports": "^4.1.1",
|
|
125
|
+
"ember-template-lint": "^6.0.0",
|
|
126
126
|
"eslint": "^8.55.0",
|
|
127
|
-
"eslint-plugin-ember": "^12.
|
|
128
|
-
"eslint-plugin-n": "^
|
|
127
|
+
"eslint-plugin-ember": "^12.1.0",
|
|
128
|
+
"eslint-plugin-n": "^17.7.0",
|
|
129
129
|
"eslint-plugin-prettier": "^5.1.3",
|
|
130
130
|
"execa": "^8.0.1",
|
|
131
131
|
"prettier": "^3.2.5",
|
|
132
|
-
"prettier-plugin-ember-template-tag": "2.0.
|
|
132
|
+
"prettier-plugin-ember-template-tag": "2.0.2",
|
|
133
133
|
"publint": "^0.2.6",
|
|
134
|
-
"rollup": "~4.
|
|
134
|
+
"rollup": "~4.17.2",
|
|
135
135
|
"rollup-plugin-copy": "^3.5.0",
|
|
136
|
-
"typescript": "^5.
|
|
136
|
+
"typescript": "^5.4.5",
|
|
137
137
|
"@nullvoxpopuli/limber-untyped": "0.0.1"
|
|
138
138
|
},
|
|
139
139
|
"volta": {
|
|
@@ -219,19 +219,6 @@ function sanitizeForGlimmer(/* options */) {
|
|
|
219
219
|
function buildCompiler(options: ParseMarkdownOptions) {
|
|
220
220
|
let compiler = unified().use(remarkParse).use(remarkGfm);
|
|
221
221
|
|
|
222
|
-
// TODO: we only want to do this when we have pre > code.
|
|
223
|
-
// code can exist inline.
|
|
224
|
-
compiler = compiler.use(liveCodeExtraction, {
|
|
225
|
-
snippets: {
|
|
226
|
-
classList: ['glimdown-snippet', 'relative'],
|
|
227
|
-
},
|
|
228
|
-
demo: {
|
|
229
|
-
classList: ['glimdown-render'],
|
|
230
|
-
},
|
|
231
|
-
copyComponent: options?.CopyComponent,
|
|
232
|
-
shadowComponent: options?.ShadowComponent,
|
|
233
|
-
});
|
|
234
|
-
|
|
235
222
|
/**
|
|
236
223
|
* If this were "use"d after `remarkRehype`,
|
|
237
224
|
* remark is gone, and folks would need to work with rehype trees
|
|
@@ -246,6 +233,19 @@ function buildCompiler(options: ParseMarkdownOptions) {
|
|
|
246
233
|
});
|
|
247
234
|
}
|
|
248
235
|
|
|
236
|
+
// TODO: we only want to do this when we have pre > code.
|
|
237
|
+
// code can exist inline.
|
|
238
|
+
compiler = compiler.use(liveCodeExtraction, {
|
|
239
|
+
snippets: {
|
|
240
|
+
classList: ['glimdown-snippet', 'relative'],
|
|
241
|
+
},
|
|
242
|
+
demo: {
|
|
243
|
+
classList: ['glimdown-render'],
|
|
244
|
+
},
|
|
245
|
+
copyComponent: options?.CopyComponent,
|
|
246
|
+
shadowComponent: options?.ShadowComponent,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
249
|
// .use(() => (tree) => visit(tree, (node) => console.log('i', node)))
|
|
250
250
|
// remark rehype is needed to convert markdown to HTML
|
|
251
251
|
// However, it also changes all the nodes, so we need another pass
|
package/src/compile/index.ts
CHANGED
|
@@ -81,7 +81,7 @@ export async function compile(
|
|
|
81
81
|
options: GlimdownOptions | GJSOptions | HBSOptions
|
|
82
82
|
): Promise<void> {
|
|
83
83
|
let { onSuccess, onError, onCompileStart } = options;
|
|
84
|
-
let id = nameFor(text);
|
|
84
|
+
let id = nameFor(`${options.format}:${text}`);
|
|
85
85
|
|
|
86
86
|
let existing = CACHE.get(id);
|
|
87
87
|
|