ember-repl 3.0.0 → 4.0.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/package.json +34 -25
- package/src/compile/formats/gjs/babel.ts +7 -0
- package/src/{browser/cjs → compile/formats/gjs}/eval.ts +2 -4
- package/src/compile/formats/gjs/index.ts +123 -0
- package/src/{browser → compile/formats}/hbs.ts +7 -4
- package/src/{browser/compile/markdown-to-ember.ts → compile/formats/markdown.ts} +8 -1
- package/src/{browser/compile → compile}/formats.ts +6 -7
- package/src/{browser/compile → compile}/index.ts +2 -3
- package/src/compile/types.ts +26 -0
- package/src/index.ts +5 -0
- package/src/test-support/index.ts +1 -1
- package/declarations/browser/__PRIVATE__.d.ts +0 -2
- package/declarations/browser/__PRIVATE__.d.ts.map +0 -1
- package/declarations/browser/cjs/eval.d.ts +0 -9
- package/declarations/browser/cjs/eval.d.ts.map +0 -1
- package/declarations/browser/cjs/index.d.ts +0 -7
- package/declarations/browser/cjs/index.d.ts.map +0 -1
- package/declarations/browser/compile/formats.d.ts +0 -18
- package/declarations/browser/compile/formats.d.ts.map +0 -1
- package/declarations/browser/compile/index.d.ts +0 -71
- package/declarations/browser/compile/index.d.ts.map +0 -1
- package/declarations/browser/compile/markdown-to-ember.d.ts +0 -21
- package/declarations/browser/compile/markdown-to-ember.d.ts.map +0 -1
- package/declarations/browser/compile/types.d.ts +0 -9
- package/declarations/browser/compile/types.d.ts.map +0 -1
- package/declarations/browser/esm/index.d.ts +0 -8
- package/declarations/browser/esm/index.d.ts.map +0 -1
- package/declarations/browser/gjs.d.ts +0 -4
- package/declarations/browser/gjs.d.ts.map +0 -1
- package/declarations/browser/hbs.d.ts +0 -17
- package/declarations/browser/hbs.d.ts.map +0 -1
- package/declarations/browser/index.d.ts +0 -7
- package/declarations/browser/index.d.ts.map +0 -1
- package/declarations/browser/js.d.ts +0 -20
- package/declarations/browser/js.d.ts.map +0 -1
- package/declarations/browser/known-modules.d.ts +0 -65
- package/declarations/browser/known-modules.d.ts.map +0 -1
- package/declarations/browser/types.d.ts +0 -21
- package/declarations/browser/types.d.ts.map +0 -1
- package/declarations/browser/utils.d.ts +0 -19
- package/declarations/browser/utils.d.ts.map +0 -1
- package/declarations/test-support/index.d.ts +0 -2
- package/declarations/test-support/index.d.ts.map +0 -1
- package/dist/browser/__PRIVATE__.js +0 -2
- package/dist/browser/__PRIVATE__.js.map +0 -1
- package/dist/browser/cjs/eval.js +0 -22
- package/dist/browser/cjs/eval.js.map +0 -1
- package/dist/browser/cjs/index.js +0 -43
- package/dist/browser/cjs/index.js.map +0 -1
- package/dist/browser/compile/formats.js +0 -172
- package/dist/browser/compile/formats.js.map +0 -1
- package/dist/browser/compile/index.js +0 -113
- package/dist/browser/compile/index.js.map +0 -1
- package/dist/browser/compile/markdown-to-ember.js +0 -254
- package/dist/browser/compile/markdown-to-ember.js.map +0 -1
- package/dist/browser/compile/types.js +0 -2
- package/dist/browser/compile/types.js.map +0 -1
- package/dist/browser/esm/index.js +0 -67
- package/dist/browser/esm/index.js.map +0 -1
- package/dist/browser/gjs.js +0 -43
- package/dist/browser/gjs.js.map +0 -1
- package/dist/browser/hbs.js +0 -100
- package/dist/browser/hbs.js.map +0 -1
- package/dist/browser/index.js +0 -6
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/js.js +0 -38
- package/dist/browser/js.js.map +0 -1
- package/dist/browser/known-modules.js +0 -48
- package/dist/browser/known-modules.js.map +0 -1
- package/dist/browser/types.js +0 -2
- package/dist/browser/types.js.map +0 -1
- package/dist/browser/utils.js +0 -46
- package/dist/browser/utils.js.map +0 -1
- package/dist/build/ember-cli.cjs +0 -36
- package/dist/test-support/index.js +0 -8
- package/dist/test-support/index.js.map +0 -1
- package/src/browser/cjs/index.ts +0 -44
- package/src/browser/compile/types.ts +0 -11
- package/src/browser/esm/index.ts +0 -80
- package/src/browser/gjs.ts +0 -59
- package/src/browser/index.ts +0 -8
- package/src/browser/js.ts +0 -42
- package/src/browser/types.ts +0 -24
- package/src/build/ember-cli.cjs +0 -36
- /package/src/{browser/__PRIVATE__.ts → __PRIVATE__.ts} +0 -0
- /package/src/{browser → compile/formats/gjs}/known-modules.ts +0 -0
- /package/src/{browser → compile}/utils.ts +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CompileResult } from './types.ts';
|
|
2
|
-
/**
|
|
3
|
-
* compile a template with an empty scope
|
|
4
|
-
* to use components, helpers, etc, you will need to compile with JS
|
|
5
|
-
*
|
|
6
|
-
* (templates alone do not have a way to import / define complex structures)
|
|
7
|
-
*/
|
|
8
|
-
export declare function compileHBS(template: string, options?: CompileTemplateOptions): CompileResult;
|
|
9
|
-
interface CompileTemplateOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Used for debug viewing
|
|
12
|
-
*/
|
|
13
|
-
moduleName?: string;
|
|
14
|
-
scope?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=hbs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hbs.d.ts","sourceRoot":"","sources":["../../src/browser/hbs.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAQhD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B,GAAG,aAAa,CAehG;AAED,UAAU,sBAAsB;IAC9B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { compile, Compiled } from './compile/index.ts';
|
|
2
|
-
export { compileHBS } from './hbs.ts';
|
|
3
|
-
export { compileJS } from './js.ts';
|
|
4
|
-
export { modules as frameworkModules } from './known-modules.ts';
|
|
5
|
-
export { invocationName, invocationOf, nameFor } from './utils.ts';
|
|
6
|
-
export type { CompileResult } from './types';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGnE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CompileResult, ExtraModules, Options } from './types.ts';
|
|
2
|
-
/**
|
|
3
|
-
* @public
|
|
4
|
-
* Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.
|
|
5
|
-
* The returned component can be invoked explicitly in the consuming project.
|
|
6
|
-
*
|
|
7
|
-
* SEE: README for example usage
|
|
8
|
-
*
|
|
9
|
-
* @param {string} code: the code to be compiled
|
|
10
|
-
* @param {Object} extraModules: map of import paths to modules. This isn't needed
|
|
11
|
-
* for classic ember projects, but for strict static ember projects, extraModules
|
|
12
|
-
* will need to be pasesd if compileJS is intended to be used in a styleguide or
|
|
13
|
-
* if there are additional modules that could be imported in the passed `code`.
|
|
14
|
-
*
|
|
15
|
-
* Later on, imports that are not present by default (ember/glimmer) or that
|
|
16
|
-
* are not provided by extraModules will be searched on npm to see if a package
|
|
17
|
-
* needs to be downloaded before running the `code` / invoking the component
|
|
18
|
-
*/
|
|
19
|
-
export declare function compileJS(code: string, extraModules?: ExtraModules, options?: Options): Promise<CompileResult>;
|
|
20
|
-
//# sourceMappingURL=js.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"js.d.ts","sourceRoot":"","sources":["../../src/browser/js.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,YAAY,EAC3B,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,aAAa,CAAC,CAexB"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/// <reference types="ember-source/types/stable/@glimmer/tracking" />
|
|
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/owner" />
|
|
12
|
-
/// <reference types="ember-source/types/stable/@ember/controller/owner-ext" />
|
|
13
|
-
/// <reference types="ember-source/types/stable/@ember/routing/owner-ext" />
|
|
14
|
-
/// <reference types="ember-source/types/stable/@ember/service/owner-ext" />
|
|
15
|
-
/// <reference types="ember-source/types/stable/@ember/runloop" />
|
|
16
|
-
/// <reference types="ember-source/types/stable/@ember/service" />
|
|
17
|
-
/// <reference types="ember-source/types/stable/@ember/routing/service-ext" />
|
|
18
|
-
/// <reference types="ember-source/types/stable/@ember/template" />
|
|
19
|
-
/// <reference types="ember-source/types/stable/@ember/template-factory" />
|
|
20
|
-
/// <reference types="ember-source/types/stable/@ember/utils" />
|
|
21
|
-
/// <reference types="ember-source/types/stable/@ember/component/template-only" />
|
|
22
|
-
/**
|
|
23
|
-
* We need to import and hang on to these references so that they
|
|
24
|
-
* don't get optimized away during deploy
|
|
25
|
-
*/
|
|
26
|
-
import _GlimmerComponent from '@glimmer/component';
|
|
27
|
-
import * as _tracking from '@glimmer/tracking';
|
|
28
|
-
import * as _application from '@ember/application';
|
|
29
|
-
import * as _array from '@ember/array';
|
|
30
|
-
import * as _EmberComponent from '@ember/component';
|
|
31
|
-
import * as _EmberComponentHelper from '@ember/component/helper';
|
|
32
|
-
import * as _debug from '@ember/debug';
|
|
33
|
-
import * as _destroyable from '@ember/destroyable';
|
|
34
|
-
import * as _helpers from '@ember/helper';
|
|
35
|
-
import * as _modifier from '@ember/modifier';
|
|
36
|
-
import * as _object from '@ember/object';
|
|
37
|
-
import * as _owner from '@ember/owner';
|
|
38
|
-
import * as _runloop from '@ember/runloop';
|
|
39
|
-
import * as _service from '@ember/service';
|
|
40
|
-
import * as _template from '@ember/template';
|
|
41
|
-
import { createTemplateFactory } from '@ember/template-factory';
|
|
42
|
-
import * as _utils from '@ember/utils';
|
|
43
|
-
export declare const modules: {
|
|
44
|
-
'@ember/application': typeof _application;
|
|
45
|
-
'@ember/array': typeof _array;
|
|
46
|
-
'@ember/component': typeof _EmberComponent;
|
|
47
|
-
'@ember/component/helper': typeof _EmberComponentHelper;
|
|
48
|
-
'@ember/component/template-only': <S>(moduleName?: string | undefined, name?: string | undefined) => import("@ember/component/template-only").TemplateOnlyComponent<S>;
|
|
49
|
-
'@ember/debug': typeof _debug;
|
|
50
|
-
'@ember/destroyable': typeof _destroyable;
|
|
51
|
-
'@ember/helper': typeof _helpers;
|
|
52
|
-
'@ember/modifier': typeof _modifier;
|
|
53
|
-
'@ember/object': typeof _object;
|
|
54
|
-
'@ember/runloop': typeof _runloop;
|
|
55
|
-
'@ember/service': typeof _service;
|
|
56
|
-
'@ember/template-factory': {
|
|
57
|
-
createTemplateFactory: typeof createTemplateFactory;
|
|
58
|
-
};
|
|
59
|
-
'@ember/utils': typeof _utils;
|
|
60
|
-
'@ember/template': typeof _template;
|
|
61
|
-
'@ember/owner': typeof _owner;
|
|
62
|
-
'@glimmer/component': typeof _GlimmerComponent;
|
|
63
|
-
'@glimmer/tracking': typeof _tracking;
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=known-modules.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../src/browser/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,21 +0,0 @@
|
|
|
1
|
-
import type { availablePlugins, availablePresets, transform } from '@babel/standalone';
|
|
2
|
-
import type { ComponentLike } from '@glint/template';
|
|
3
|
-
export interface CompileResult {
|
|
4
|
-
component?: ComponentLike;
|
|
5
|
-
error?: Error;
|
|
6
|
-
name: string;
|
|
7
|
-
}
|
|
8
|
-
export interface Babel {
|
|
9
|
-
availablePlugins: typeof availablePlugins;
|
|
10
|
-
availablePresets: typeof availablePresets;
|
|
11
|
-
transform: typeof transform;
|
|
12
|
-
}
|
|
13
|
-
export type Options = {
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
* @deprecated do not use - not under semver
|
|
17
|
-
*/
|
|
18
|
-
skypack?: boolean;
|
|
19
|
-
};
|
|
20
|
-
export type ExtraModules = Record<string, unknown>;
|
|
21
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/browser/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,gBAAgB,EAAE,OAAO,gBAAgB,CAAC;IAC1C,gBAAgB,EAAE,OAAO,gBAAgB,CAAC;IAC1C,SAAS,EAAE,OAAO,SAAS,CAAC;CAC7B;AAED,MAAM,MAAM,OAAO,GAAG;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For any given code block, a reasonably stable name can be
|
|
3
|
-
* generated.
|
|
4
|
-
* This can help with cacheing previously compiled components,
|
|
5
|
-
* and generally allowing a consumer to derive "known references" to user-input
|
|
6
|
-
*/
|
|
7
|
-
export declare function nameFor(code: string, prefix?: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* Returns the text for invoking a component with a given name.
|
|
10
|
-
* It is assumed the component takes no arguments, as would be the
|
|
11
|
-
* case in REPLs / Playgrounds for the "root" component.
|
|
12
|
-
*/
|
|
13
|
-
export declare function invocationOf(name: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Core team does not want to support changes to '@ember/string' (v2 addonification, specifically)
|
|
16
|
-
* inflection does not support hyphens
|
|
17
|
-
*/
|
|
18
|
-
export declare function invocationName(name: string): string;
|
|
19
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/browser/utils.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAiB,UAI5D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAWxC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,UAE1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-support/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,SAEhC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"__PRIVATE__.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/browser/cjs/eval.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { modules } from '../known-modules.js';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
|
-
function evalSnippet(compiled, extraModules = {}) {
|
|
5
|
-
const exports = {};
|
|
6
|
-
function require(moduleName) {
|
|
7
|
-
let preConfigured = modules[moduleName] || extraModules[moduleName];
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
return preConfigured || window.require(moduleName);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// https://github.com/glimmerjs/glimmer-experimental/blob/master/packages/examples/playground/src/utils/eval-snippet.ts
|
|
15
|
-
eval(compiled);
|
|
16
|
-
return Object.assign(exports, {
|
|
17
|
-
require
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { evalSnippet };
|
|
22
|
-
//# sourceMappingURL=eval.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eval.js","sources":["../../../src/browser/cjs/eval.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { modules } from '../known-modules.ts';\n\nimport type { ExtraModules } from '../types.ts';\nimport type Component from '@glimmer/component';\n\nexport function evalSnippet(\n compiled: string,\n extraModules: ExtraModules = {}\n): {\n default: Component;\n services?: { [key: string]: unknown };\n} {\n const exports = {};\n\n function require(moduleName: keyof typeof modules): unknown {\n let preConfigured = modules[moduleName] || extraModules[moduleName];\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return preConfigured || window.require(moduleName);\n }\n\n // https://github.com/glimmerjs/glimmer-experimental/blob/master/packages/examples/playground/src/utils/eval-snippet.ts\n eval(compiled);\n\n return Object.assign(exports, { require }) as {\n default: Component;\n services?: { [key: string]: unknown };\n require: unknown;\n };\n}\n"],"names":["evalSnippet","compiled","extraModules","exports","require","moduleName","preConfigured","modules","window","eval","Object","assign"],"mappings":";;AAAA;AAMO,SAASA,WAAWA,CACzBC,QAAgB,EAChBC,YAA0B,GAAG,EAAE,EAI/B;EACA,MAAMC,OAAO,GAAG,EAAE,CAAA;EAElB,SAASC,OAAOA,CAACC,UAAgC,EAAW;IAC1D,IAAIC,aAAa,GAAGC,OAAO,CAACF,UAAU,CAAC,IAAIH,YAAY,CAACG,UAAU,CAAC,CAAA;;AAEnE;AACA;AACA,IAAA,OAAOC,aAAa,IAAIE,MAAM,CAACJ,OAAO,CAACC,UAAU,CAAC,CAAA;AACpD,GAAA;;AAEA;EACAI,IAAI,CAACR,QAAQ,CAAC,CAAA;AAEd,EAAA,OAAOS,MAAM,CAACC,MAAM,CAACR,OAAO,EAAE;AAAEC,IAAAA,OAAAA;AAAQ,GAAC,CAAC,CAAA;AAK5C;;;;"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { preprocess, transform } from '../gjs.js';
|
|
2
|
-
import { nameFor } from '../utils.js';
|
|
3
|
-
import { evalSnippet } from './eval.js';
|
|
4
|
-
|
|
5
|
-
async function compileJS(code, extraModules) {
|
|
6
|
-
let name = nameFor(code);
|
|
7
|
-
let component;
|
|
8
|
-
let error;
|
|
9
|
-
try {
|
|
10
|
-
let compiled = await compileGJS({
|
|
11
|
-
code: code,
|
|
12
|
-
name
|
|
13
|
-
});
|
|
14
|
-
if (!compiled) {
|
|
15
|
-
throw new Error(`Compiled output is missing`);
|
|
16
|
-
}
|
|
17
|
-
component = evalSnippet(compiled, extraModules).default;
|
|
18
|
-
} catch (e) {
|
|
19
|
-
error = e;
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
name,
|
|
23
|
-
component,
|
|
24
|
-
error
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
async function compileGJS({
|
|
28
|
-
code: input,
|
|
29
|
-
name
|
|
30
|
-
}) {
|
|
31
|
-
let preprocessed = await preprocess(input, name);
|
|
32
|
-
let result = await transform(preprocessed, name);
|
|
33
|
-
if (!result) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
let {
|
|
37
|
-
code
|
|
38
|
-
} = result;
|
|
39
|
-
return code;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { compileJS };
|
|
43
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/browser/cjs/index.ts"],"sourcesContent":["import { preprocess, transform } from '../gjs.ts';\nimport { nameFor } from '../utils.ts';\nimport { evalSnippet } from './eval.ts';\n\nimport type { CompileResult, ExtraModules } from '../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\nexport async function compileJS(code: string, extraModules?: ExtraModules): Promise<CompileResult> {\n let name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n let compiled = await compileGJS({ 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 compileGJS({ 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"],"names":["compileJS","code","extraModules","name","nameFor","component","error","compiled","compileGJS","Error","evalSnippet","default","e","input","preprocessed","preprocess","result","transform"],"mappings":";;;;AAYO,eAAeA,SAASA,CAACC,IAAY,EAAEC,YAA2B,EAA0B;AACjG,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,UAAU,CAAC;AAAEP,MAAAA,IAAI,EAAEA,IAAI;AAAEE,MAAAA,IAAAA;AAAK,KAAC,CAAC,CAAA;IAErD,IAAI,CAACI,QAAQ,EAAE;AACb,MAAA,MAAM,IAAIE,KAAK,CAAE,CAAA,0BAAA,CAA2B,CAAC,CAAA;AAC/C,KAAA;IAEAJ,SAAS,GAAGK,WAAW,CAACH,QAAQ,EAAEL,YAAY,CAAC,CAACS,OAAmC,CAAA;GACpF,CAAC,OAAOC,CAAC,EAAE;AACVN,IAAAA,KAAK,GAAGM,CAAsB,CAAA;AAChC,GAAA;EAEA,OAAO;IAAET,IAAI;IAAEE,SAAS;AAAEC,IAAAA,KAAAA;GAAO,CAAA;AACnC,CAAA;AAEA,eAAeE,UAAUA,CAAC;AAAEP,EAAAA,IAAI,EAAEY,KAAK;AAAEV,EAAAA,IAAAA;AAAW,CAAC,EAAE;EACrD,IAAIW,YAAY,GAAG,MAAMC,UAAU,CAACF,KAAK,EAAEV,IAAI,CAAC,CAAA;EAChD,IAAIa,MAAM,GAAG,MAAMC,SAAS,CAACH,YAAY,EAAEX,IAAI,CAAC,CAAA;EAEhD,IAAI,CAACa,MAAM,EAAE;AACX,IAAA,OAAA;AACF,GAAA;EAEA,IAAI;AAAEf,IAAAA,IAAAA;AAAK,GAAC,GAAGe,MAAM,CAAA;AAErB,EAAA,OAAOf,IAAI,CAAA;AACb;;;;"}
|
|
@@ -1,172 +0,0 @@
|
|
|
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('../js.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('../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('./markdown-to-ember.js');
|
|
86
|
-
let {
|
|
87
|
-
templateOnlyGlimdown,
|
|
88
|
-
blocks
|
|
89
|
-
} = await parseMarkdown(glimdownInput, {
|
|
90
|
-
CopyComponent: options?.CopyComponent,
|
|
91
|
-
ShadowComponent: options?.ShadowComponent,
|
|
92
|
-
remarkPlugins: options?.remarkPlugins
|
|
93
|
-
});
|
|
94
|
-
rootTemplate = templateOnlyGlimdown;
|
|
95
|
-
liveCode = blocks;
|
|
96
|
-
} catch (error) {
|
|
97
|
-
return {
|
|
98
|
-
error: error,
|
|
99
|
-
name: 'unknown'
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Step 2: Compile the live code samples
|
|
105
|
-
*/
|
|
106
|
-
if (liveCode.length > 0) {
|
|
107
|
-
try {
|
|
108
|
-
scope = await extractScope(liveCode, options);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.info({
|
|
111
|
-
scope
|
|
112
|
-
});
|
|
113
|
-
console.error(error);
|
|
114
|
-
return {
|
|
115
|
-
error: error,
|
|
116
|
-
rootTemplate,
|
|
117
|
-
name: 'unknown'
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Make sure non of our snippets errored
|
|
124
|
-
*
|
|
125
|
-
* TODO: for these errors, report them differently so that we
|
|
126
|
-
* can render the 'Ember' and still highlight the correct line?
|
|
127
|
-
* or maybe there is a way to highlight in the editor instead?
|
|
128
|
-
*/
|
|
129
|
-
for (let {
|
|
130
|
-
error,
|
|
131
|
-
component
|
|
132
|
-
} of scope) {
|
|
133
|
-
if (!component) {
|
|
134
|
-
if (error) {
|
|
135
|
-
return {
|
|
136
|
-
error,
|
|
137
|
-
rootTemplate,
|
|
138
|
-
name: 'unknown'
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Step 4: Compile the Ember Template
|
|
146
|
-
*/
|
|
147
|
-
try {
|
|
148
|
-
let localScope = scope.reduce((accum, {
|
|
149
|
-
component,
|
|
150
|
-
name
|
|
151
|
-
}) => {
|
|
152
|
-
accum[invocationName(name)] = component;
|
|
153
|
-
return accum;
|
|
154
|
-
}, {});
|
|
155
|
-
return await compileHBS(rootTemplate, {
|
|
156
|
-
moduleName: 'DynamicRootTemplate',
|
|
157
|
-
scope: {
|
|
158
|
-
...topLevelScope,
|
|
159
|
-
...localScope
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
} catch (error) {
|
|
163
|
-
return {
|
|
164
|
-
error: error,
|
|
165
|
-
rootTemplate,
|
|
166
|
-
name: 'unknown'
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export { compileGJS, compileHBS, compileMD };
|
|
172
|
-
//# sourceMappingURL=formats.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sources":["../../../src/browser/compile/formats.ts"],"sourcesContent":["import { invocationName } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ExtractedCode } from './markdown-to-ember.ts';\nimport type { 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('../js.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('../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 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('./markdown-to-ember.ts');\n let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\n ShadowComponent: options?.ShadowComponent,\n remarkPlugins: options?.remarkPlugins,\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","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAOA,eAAeA,eAAeA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAChF,IAAIC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC7BJ,EAAE,CAACK,GAAG,CAAC,OAAO;AA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AK,KAAC,KAAK;AAC9B6B,MAAAA,KAAK,CAACC,cAAc,CAAC9B,IAAI,CAAC,CAAC,GAAG0B,SAAS,CAAA;AAEvC,MAAA,OAAOG,KAAK,CAAA;KACb,EACD,EACF,CAAC,CAAA;AAED,IAAA,OAAO,MAAM5B,UAAU,CAACiB,YAAY,EAAE;AACpCa,MAAAA,UAAU,EAAE,qBAAqB;AACjCzB,MAAAA,KAAK,EAAE;AACL,QAAA,GAAGS,aAAa;QAChB,GAAGY,UAAAA;AACL,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAC,OAAO5B,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;MAAEmB,YAAY;AAAElB,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACjE,GAAA;AACF;;;;"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { resourceFactory, resource, cell } from 'ember-resources';
|
|
2
|
-
import { nameFor } from '../utils.js';
|
|
3
|
-
import { compileMD, compileGJS, compileHBS } from './formats.js';
|
|
4
|
-
|
|
5
|
-
const CACHE = new Map();
|
|
6
|
-
const SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compile GitHub-flavored Markdown with GJS support
|
|
10
|
-
* and optionally render gjs-snippets via a `live` meta tag
|
|
11
|
-
* on the code fences.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Compile GJS
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Compile a stateless component using just the template
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* This compileMD is a more robust version of the raw compiling used in "formats".
|
|
24
|
-
* This function manages cache, and has events for folks building UIs to hook in to
|
|
25
|
-
*/
|
|
26
|
-
async function compile(text, options) {
|
|
27
|
-
let {
|
|
28
|
-
onSuccess,
|
|
29
|
-
onError,
|
|
30
|
-
onCompileStart
|
|
31
|
-
} = options;
|
|
32
|
-
let id = nameFor(text);
|
|
33
|
-
let existing = CACHE.get(id);
|
|
34
|
-
if (existing) {
|
|
35
|
-
onSuccess(existing);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (!SUPPORTED_FORMATS.includes(options.format)) {
|
|
39
|
-
await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
await onCompileStart();
|
|
43
|
-
if (!text) {
|
|
44
|
-
await onError('No Input Document yet');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
let result;
|
|
48
|
-
if (options.format === 'glimdown') {
|
|
49
|
-
result = await compileMD(text, options);
|
|
50
|
-
} else if (options.format === 'gjs') {
|
|
51
|
-
result = await compileGJS(text, options.importMap);
|
|
52
|
-
} else if (options.format === 'hbs') {
|
|
53
|
-
result = await compileHBS(text, {
|
|
54
|
-
scope: options.topLevelScope
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (result.error) {
|
|
61
|
-
await onError(result.error.message || `${result.error}`);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
CACHE.set(id, result.component);
|
|
65
|
-
await onSuccess(result.component);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* By default, this compiles to `glimdown`. A Markdown format which
|
|
74
|
-
* extracts `live` tagged code snippets and compiles them to components.
|
|
75
|
-
*/
|
|
76
|
-
function Compiled(markdownText, maybeOptions) {
|
|
77
|
-
return resource(() => {
|
|
78
|
-
let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;
|
|
79
|
-
let format = (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';
|
|
80
|
-
let options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};
|
|
81
|
-
let input = typeof markdownText === 'function' ? markdownText() : markdownText;
|
|
82
|
-
let ready = cell(false);
|
|
83
|
-
let error = cell();
|
|
84
|
-
let result = cell();
|
|
85
|
-
if (input) {
|
|
86
|
-
compile(input, {
|
|
87
|
-
// narrowing is hard here, but this is an implementation detail
|
|
88
|
-
format: format,
|
|
89
|
-
onSuccess: async component => {
|
|
90
|
-
result.current = component;
|
|
91
|
-
ready.set(true);
|
|
92
|
-
error.set(null);
|
|
93
|
-
},
|
|
94
|
-
onError: async e => {
|
|
95
|
-
error.set(e);
|
|
96
|
-
},
|
|
97
|
-
onCompileStart: async () => {
|
|
98
|
-
ready.set(false);
|
|
99
|
-
},
|
|
100
|
-
...options
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return () => ({
|
|
104
|
-
isReady: ready.current,
|
|
105
|
-
error: error.current,
|
|
106
|
-
component: result.current
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
resourceFactory(Compiled);
|
|
111
|
-
|
|
112
|
-
export { CACHE, Compiled, compile };
|
|
113
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/browser/compile/index.ts"],"sourcesContent":["import { cell, resource, resourceFactory } from 'ember-resources';\n\nimport { nameFor } from '../utils.ts';\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { 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 CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n}\ninterface GJSOptions extends Scope, Events {\n format: 'gjs';\n}\n\ninterface HBSOptions extends Scope, Events {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n}\n\n/**\n * Compile GitHub-flavored Markdown with GJS support\n * and optionally render gjs-snippets via a `live` meta tag\n * on the code fences.\n */\nexport async function compile(text: string, options: GlimdownOptions): Promise<void>;\n\n/**\n * Compile GJS\n */\nexport async function compile(text: string, options: GJSOptions): Promise<void>;\n\n/**\n * Compile a stateless component using just the template\n */\nexport async function compile(text: string, options: HBSOptions): Promise<void>;\n\n/**\n * This compileMD is a more robust version of the raw compiling used in \"formats\".\n * This function manages cache, and has events for folks building UIs to hook in to\n */\nexport async function compile(\n text: string,\n options: GlimdownOptions | GJSOptions | HBSOptions\n): Promise<void> {\n let { onSuccess, onError, onCompileStart } = options;\n let id = nameFor(text);\n\n let existing = CACHE.get(id);\n\n if (existing) {\n onSuccess(existing);\n\n return;\n }\n\n if (!SUPPORTED_FORMATS.includes(options.format)) {\n await onError(`Unsupported format: ${options.format}. Supported formats: ${SUPPORTED_FORMATS}`);\n\n return;\n }\n\n await onCompileStart();\n\n if (!text) {\n await onError('No Input Document yet');\n\n return;\n }\n\n let result: CompileResult;\n\n if (options.format === 'glimdown') {\n result = await processMD(text, options);\n } else if (options.format === 'gjs') {\n result = await processGJS(text, options.importMap);\n } else if (options.format === 'hbs') {\n result = await processHBS(text, {\n scope: options.topLevelScope,\n });\n } else {\n await onError(\n `Unsupported format: ${(options as any).format}. Supported formats: ${SUPPORTED_FORMATS}`\n );\n\n return;\n }\n\n if (result.error) {\n await onError(result.error.message || `${result.error}`);\n\n return;\n }\n\n CACHE.set(id, result.component as ComponentLike);\n\n await onSuccess(result.component as ComponentLike);\n}\n\ntype Input = string | undefined | null;\n\ntype ExtraOptions =\n | {\n format: 'glimdown';\n remarkPlugins?: UnifiedPlugin[];\n importMap?: EvalImportMap;\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'hbs';\n topLevelScope?: ScopeMap;\n }\n | {\n format: 'gjs';\n importMap?: EvalImportMap;\n };\n\n/**\n * @internal\n */\nexport interface Value {\n isReady: boolean;\n error: string | null;\n component: ComponentLike;\n}\n\nexport function Compiled(markdownText: Input | (() => Input)): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => Format): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: ExtraOptions): Value;\nexport function Compiled(markdownText: Input | (() => Input), options?: () => ExtraOptions): Value;\n\n/**\n * By default, this compiles to `glimdown`. A Markdown format which\n * extracts `live` tagged code snippets and compiles them to components.\n */\nexport function Compiled(\n markdownText: Input | (() => Input),\n maybeOptions?: Format | (() => Format) | ExtraOptions | (() => ExtraOptions)\n): Value {\n return resource(() => {\n let maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;\n let format =\n (typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';\n let options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};\n\n let input = typeof markdownText === 'function' ? markdownText() : markdownText;\n let ready = cell(false);\n let error = cell<string | null>();\n let result = cell<ComponentLike>();\n\n if (input) {\n compile(input, {\n // narrowing is hard here, but this is an implementation detail\n format: format as any,\n onSuccess: async (component) => {\n result.current = component;\n ready.set(true);\n error.set(null);\n },\n onError: async (e) => {\n error.set(e);\n },\n onCompileStart: async () => {\n ready.set(false);\n },\n ...options,\n });\n }\n\n return () => ({\n isReady: ready.current,\n error: error.current,\n component: result.current,\n });\n });\n}\n\nresourceFactory(Compiled);\n"],"names":["CACHE","Map","SUPPORTED_FORMATS","compile","text","options","onSuccess","onError","onCompileStart","id","nameFor","existing","get","includes","format","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","markdownText","maybeOptions","resource","maybeObject","input","ready","cell","current","e","isReady","resourceFactory"],"mappings":";;;;MAeaA,KAAK,GAAG,IAAIC,GAAG,GAAyB;AAYrD,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;;AAkBpD;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,eAAeC,OAAOA,CAC3BC,IAAY,EACZC,OAAkD,EACnC;EACf,IAAI;IAAEC,SAAS;IAAEC,OAAO;AAAEC,IAAAA,cAAAA;AAAe,GAAC,GAAGH,OAAO,CAAA;AACpD,EAAA,IAAII,EAAE,GAAGC,OAAO,CAACN,IAAI,CAAC,CAAA;AAEtB,EAAA,IAAIO,QAAQ,GAAGX,KAAK,CAACY,GAAG,CAACH,EAAE,CAAC,CAAA;AAE5B,EAAA,IAAIE,QAAQ,EAAE;IACZL,SAAS,CAACK,QAAQ,CAAC,CAAA;AAEnB,IAAA,OAAA;AACF,GAAA;EAEA,IAAI,CAACT,iBAAiB,CAACW,QAAQ,CAACR,OAAO,CAACS,MAAM,CAAC,EAAE;IAC/C,MAAMP,OAAO,CAAE,CAAsBF,oBAAAA,EAAAA,OAAO,CAACS,MAAO,CAAA,qBAAA,EAAuBZ,iBAAkB,CAAA,CAAC,CAAC,CAAA;AAE/F,IAAA,OAAA;AACF,GAAA;EAEA,MAAMM,cAAc,EAAE,CAAA;EAEtB,IAAI,CAACJ,IAAI,EAAE;IACT,MAAMG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAEtC,IAAA,OAAA;AACF,GAAA;AAEA,EAAA,IAAIQ,MAAqB,CAAA;AAEzB,EAAA,I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