ember-repl 2.0.63 → 3.0.0-beta.1
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/README.md +200 -35
- package/addon-main.cjs +5 -0
- package/dist/browser/cjs/eval.d.ts +10 -0
- package/dist/browser/cjs/eval.d.ts.map +1 -0
- package/dist/browser/cjs/eval.js +22 -0
- package/dist/browser/cjs/eval.js.map +1 -0
- package/dist/browser/cjs/index.d.ts +7 -0
- package/dist/browser/cjs/index.js +43 -0
- package/dist/browser/cjs/index.js.map +1 -0
- package/dist/browser/compile/formats.d.ts +15 -0
- package/dist/browser/compile/formats.js +169 -0
- package/dist/browser/compile/formats.js.map +1 -0
- package/dist/browser/compile/index.d.ts +32 -0
- package/dist/browser/compile/index.js +90 -0
- package/dist/browser/compile/index.js.map +1 -0
- package/dist/browser/compile/markdown-to-ember.d.ts +18 -0
- package/dist/browser/compile/markdown-to-ember.js +237 -0
- package/dist/browser/compile/markdown-to-ember.js.map +1 -0
- package/dist/browser/compile/types.d.ts +7 -0
- package/dist/browser/compile/types.js +2 -0
- package/dist/browser/compile/types.js.map +1 -0
- package/dist/browser/esm/index.d.ts +8 -0
- package/dist/browser/esm/index.js +67 -0
- package/dist/browser/esm/index.js.map +1 -0
- package/dist/browser/eti/babel-plugin.d.ts +54 -0
- package/dist/browser/eti/babel-plugin.js +95 -0
- package/dist/browser/eti/babel-plugin.js.map +1 -0
- package/dist/browser/eti/debug.d.ts +2 -0
- package/dist/browser/eti/debug.js +9 -0
- package/dist/browser/eti/debug.js.map +1 -0
- package/dist/browser/eti/parse-templates.d.ts +56 -0
- package/dist/browser/eti/parse-templates.js +181 -0
- package/dist/browser/eti/parse-templates.js.map +1 -0
- package/dist/browser/eti/preprocess.d.ts +57 -0
- package/dist/browser/eti/preprocess.js +270 -0
- package/dist/browser/eti/preprocess.js.map +1 -0
- package/dist/browser/eti/template-tag-transform.d.ts +15 -0
- package/dist/browser/eti/template-tag-transform.js +46 -0
- package/dist/browser/eti/template-tag-transform.js.map +1 -0
- package/dist/browser/eti/util.d.ts +14 -0
- package/dist/browser/eti/util.js +39 -0
- package/dist/browser/eti/util.js.map +1 -0
- package/dist/browser/gjs.d.ts +4 -0
- package/dist/browser/gjs.js +40 -0
- package/dist/browser/gjs.js.map +1 -0
- package/{hbs.d.ts → dist/browser/hbs.d.ts} +7 -7
- package/dist/browser/hbs.js +91 -0
- package/dist/browser/hbs.js.map +1 -0
- package/dist/browser/index.d.ts +6 -0
- package/dist/browser/index.js +6 -0
- package/dist/browser/index.js.map +1 -0
- package/{js.d.ts → dist/browser/js.d.ts} +3 -6
- package/dist/browser/js.js +38 -0
- package/dist/browser/js.js.map +1 -0
- package/{known-modules.d.ts → dist/browser/known-modules.d.ts} +6 -5
- package/dist/browser/known-modules.js +46 -0
- package/dist/browser/known-modules.js.map +1 -0
- package/dist/browser/types.d.ts +21 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/{utils.d.ts → dist/browser/utils.d.ts} +8 -3
- package/dist/browser/utils.js +46 -0
- package/dist/browser/utils.js.map +1 -0
- package/dist/build/ember-cli.cjs +36 -0
- package/dist/test-support/index.d.ts +2 -0
- package/dist/test-support/index.js +8 -0
- package/dist/test-support/index.js.map +1 -0
- package/package.json +122 -125
- package/{addon → src/browser}/cjs/eval.ts +9 -5
- package/src/browser/cjs/index.ts +44 -0
- package/src/browser/compile/formats.ts +168 -0
- package/src/browser/compile/index.ts +131 -0
- package/src/browser/compile/markdown-to-ember.ts +318 -0
- package/src/browser/compile/types.ts +7 -0
- package/src/browser/esm/index.ts +80 -0
- package/src/browser/eti/babel-plugin.ts +105 -0
- package/src/browser/eti/debug.ts +7 -0
- package/src/browser/eti/parse-templates.ts +284 -0
- package/src/browser/eti/preprocess.ts +187 -0
- package/src/browser/eti/template-tag-transform.ts +100 -0
- package/src/browser/eti/util.ts +72 -0
- package/src/browser/gjs.ts +59 -0
- package/{addon → src/browser}/hbs.ts +24 -12
- package/{addon → src/browser}/index.ts +1 -0
- package/{addon → src/browser}/js.ts +6 -2
- package/{addon → src/browser}/known-modules.ts +4 -2
- package/{addon → src/browser}/types.ts +6 -1
- package/{addon → src/browser}/utils.ts +6 -2
- package/src/build/ember-cli.cjs +36 -0
- package/src/test-support/index.ts +5 -0
- package/.github/renovate.json5 +0 -93
- package/.github/workflows/ci.yml +0 -120
- package/.github/workflows/lint.yml +0 -88
- package/.github/workflows/types.yml +0 -30
- package/CHANGELOG.md +0 -745
- package/addon/cjs/index.ts +0 -100
- package/addon/esm/index.ts +0 -131
- package/cjs/eval.d.ts +0 -8
- package/cjs/index.d.ts +0 -10
- package/config/environment.js +0 -5
- package/esm/index.d.ts +0 -11
- package/index.d.ts +0 -5
- package/index.js +0 -105
- package/tsconfig.json +0 -56
- package/types/dummy/index.d.ts +0 -1
- package/types/global.d.ts +0 -43
- package/types/overrides.d.ts +0 -18
- package/types.d.ts +0 -15
package/README.md
CHANGED
|
@@ -21,6 +21,11 @@ your app's initial time-to-interactive/etc stats.
|
|
|
21
21
|
* ember-auto-import v2 or above
|
|
22
22
|
* Node.js v14 or above
|
|
23
23
|
|
|
24
|
+
## Capabilities
|
|
25
|
+
|
|
26
|
+
* gjs
|
|
27
|
+
* hbs
|
|
28
|
+
* markdown with gjs/hbs blocks (glimdown)
|
|
24
29
|
|
|
25
30
|
## Installation
|
|
26
31
|
|
|
@@ -28,9 +33,91 @@ your app's initial time-to-interactive/etc stats.
|
|
|
28
33
|
ember install ember-repl
|
|
29
34
|
```
|
|
30
35
|
|
|
36
|
+
## Setup
|
|
37
|
+
|
|
38
|
+
This library uses babel, which does some goofy things in the browser.
|
|
39
|
+
You'll need to define a global `process` and `Buffer` somewhere in your app.
|
|
40
|
+
|
|
41
|
+
For example:
|
|
42
|
+
```js
|
|
43
|
+
// app/app.js
|
|
44
|
+
|
|
45
|
+
// @babel/traverse (from babel-plugin-ember-template-imports)
|
|
46
|
+
// accesses process.....
|
|
47
|
+
// maybe one day we can have a browser-only verison?
|
|
48
|
+
// But they aren't used.... so.. that's fun.
|
|
49
|
+
Object.assign(window, {
|
|
50
|
+
process: { env: {} },
|
|
51
|
+
Buffer: {},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
31
56
|
## Usage
|
|
32
57
|
|
|
33
|
-
|
|
58
|
+
### Compiling GJS
|
|
59
|
+
|
|
60
|
+
There are two ways to compile gjs text, imperatively via `compileJS`, where you manage the reactivity yourself.
|
|
61
|
+
Or `Compiled`, which is a resource that manages the reactivity for you.
|
|
62
|
+
|
|
63
|
+
#### Automatic reactivity via the Resource
|
|
64
|
+
|
|
65
|
+
Following the Resources documentation, you can use `Compiled` in both
|
|
66
|
+
template-only or class-backed contexts:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import { Compiled } from 'ember-repl';
|
|
70
|
+
|
|
71
|
+
<template>
|
|
72
|
+
{{#let (Compiled @gjsText 'gjs') as |compileResult|}}
|
|
73
|
+
|
|
74
|
+
{{#if compileResult.error}}
|
|
75
|
+
an error! {{compileResult.error}}
|
|
76
|
+
{{/if}}
|
|
77
|
+
|
|
78
|
+
{{#if compileResult.component}}
|
|
79
|
+
<compileResult.component />
|
|
80
|
+
{{/if}}
|
|
81
|
+
|
|
82
|
+
{{/let}}
|
|
83
|
+
</template>
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
One advantage of using a backing JS context, is that you can utilize the `keepLatest`
|
|
88
|
+
resource so that when an error occurs, you could keep rendering the latest successful compile.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
import Component from '@glimmer/component';
|
|
92
|
+
import { Compiled } from 'ember-repl';
|
|
93
|
+
import { use } from 'ember-resources';
|
|
94
|
+
import { keepLatest } from 'ember-resources/util/keep-latest';
|
|
95
|
+
|
|
96
|
+
export class Renderer extends Component {
|
|
97
|
+
@use compile = Compiled(() => this.args.gjsText, 'gjs');
|
|
98
|
+
|
|
99
|
+
@use latest = keepLatest({
|
|
100
|
+
value: () => this.compile.component,
|
|
101
|
+
when: () => this.compile.error,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
<template>
|
|
105
|
+
{{#if this.compile.error}}
|
|
106
|
+
Error! {{this.compile.error}}
|
|
107
|
+
{{/if}}
|
|
108
|
+
|
|
109
|
+
{{! This will keep showing even when there is an error.
|
|
110
|
+
Which can help reduce visual jitter }}
|
|
111
|
+
{{#if this.latest.value}}
|
|
112
|
+
<this.latest.latest />
|
|
113
|
+
{{/if}}
|
|
114
|
+
|
|
115
|
+
</template>
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
#### Managing your own reactivity
|
|
34
121
|
|
|
35
122
|
```js
|
|
36
123
|
import Component from '@glimmer/component';
|
|
@@ -53,7 +140,14 @@ export class Renderer extends Component {
|
|
|
53
140
|
{{/if}}
|
|
54
141
|
```
|
|
55
142
|
|
|
56
|
-
|
|
143
|
+
|
|
144
|
+
### Compiling HBS
|
|
145
|
+
|
|
146
|
+
#### Automatic reactivity via the Resource
|
|
147
|
+
|
|
148
|
+
The hbs utilities do not provide a utility Resource.
|
|
149
|
+
|
|
150
|
+
#### Managing your own reactivity
|
|
57
151
|
|
|
58
152
|
```js
|
|
59
153
|
import Component from '@glimmer/component';
|
|
@@ -67,6 +161,110 @@ export class Renderer extends Component {
|
|
|
67
161
|
<this.compileResult.component />
|
|
68
162
|
```
|
|
69
163
|
|
|
164
|
+
|
|
165
|
+
### Compiling Markdown
|
|
166
|
+
|
|
167
|
+
There are two ways to compile markdown text, imperatively via `compile` (passing the `glimdown` format), where you manage the reactivity yourself.
|
|
168
|
+
Or `CompileMarkdown`, which is a resource that manages the reactivity for you.
|
|
169
|
+
|
|
170
|
+
#### Automatic reactivity via the Resource
|
|
171
|
+
|
|
172
|
+
Following the Resources documentation, you can use `Compiled` in both
|
|
173
|
+
template-only or class-backed contexts:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
import { Compiled } from 'ember-repl';
|
|
177
|
+
|
|
178
|
+
<template>
|
|
179
|
+
{{#let (Compiled @mdText 'glimdown') as |compileResult|}}
|
|
180
|
+
|
|
181
|
+
{{#if compileResult.error}}
|
|
182
|
+
an error! {{compileResult.error}}
|
|
183
|
+
{{/if}}
|
|
184
|
+
|
|
185
|
+
{{#if compileResult.component}}
|
|
186
|
+
<compileResult.component />
|
|
187
|
+
{{/if}}
|
|
188
|
+
|
|
189
|
+
{{/let}}
|
|
190
|
+
</template>
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
One advantage of using a backing JS context, is that you can utilize the `keepLatest`
|
|
195
|
+
resource so that when an error occurs, you could keep rendering the latest successful compile.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import Component from '@glimmer/component';
|
|
199
|
+
import { Compiled } from 'ember-repl';
|
|
200
|
+
import { use } from 'ember-resources';
|
|
201
|
+
import { keepLatest } from 'ember-resources/util/keep-latest';
|
|
202
|
+
|
|
203
|
+
export class Renderer extends Component {
|
|
204
|
+
@use compile = Compiled(() => this.args.mdText, 'glimdown');
|
|
205
|
+
|
|
206
|
+
@use latest = keepLatest({
|
|
207
|
+
value: () => this.compile.component,
|
|
208
|
+
when: () => this.compile.error,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
<template>
|
|
212
|
+
{{#if this.compile.error}}
|
|
213
|
+
Error! {{this.compile.error}}
|
|
214
|
+
{{/if}}
|
|
215
|
+
|
|
216
|
+
{{! This will keep showing even when there is an error.
|
|
217
|
+
Which can help reduce visual jitter }}
|
|
218
|
+
{{#if this.latest.value}}
|
|
219
|
+
<this.latest.latest />
|
|
220
|
+
{{/if}}
|
|
221
|
+
|
|
222
|
+
</template>
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
#### Managing your own reactivity
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
import Component from '@glimmer/component';
|
|
231
|
+
import { tracked } from '@glimmer/tracking';
|
|
232
|
+
import { compile } from 'ember-repl';
|
|
233
|
+
|
|
234
|
+
export class Renderer extends Component {
|
|
235
|
+
@tracked component;
|
|
236
|
+
@tracked error;
|
|
237
|
+
@tracked isCompiling;
|
|
238
|
+
|
|
239
|
+
constructor(...args) {
|
|
240
|
+
super(...args);
|
|
241
|
+
|
|
242
|
+
compile('...', {
|
|
243
|
+
format: 'glimdown', // or 'gjs' or 'hbs'
|
|
244
|
+
onSuccess: async (component) => {
|
|
245
|
+
this.error = null;
|
|
246
|
+
this.isCompiling = false;
|
|
247
|
+
this.component = component;
|
|
248
|
+
|
|
249
|
+
},
|
|
250
|
+
onError: async (error) => {
|
|
251
|
+
this.isCompiling = false;
|
|
252
|
+
this.error = error;
|
|
253
|
+
},
|
|
254
|
+
onCompileStart: async () => {
|
|
255
|
+
this.isCompiling = true;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
```hbs
|
|
262
|
+
{{#if this.component}}
|
|
263
|
+
<this.component />
|
|
264
|
+
{{/if}}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
|
|
70
268
|
### Using existing components
|
|
71
269
|
|
|
72
270
|
`ember-repl` is strict-mode only, so any component that you want to invoke
|
|
@@ -211,39 +409,6 @@ packagerOptions: {
|
|
|
211
409
|
},
|
|
212
410
|
```
|
|
213
411
|
|
|
214
|
-
If you are using ember-repl to showcase a styleguide _and_ have maximum strictness enabled in embroider,
|
|
215
|
-
you'll need to manually (or programatically) list out each of the components you want to force to be
|
|
216
|
-
included in the build output using the `buildComponentMap` function in your `ember-cli-build.js`.
|
|
217
|
-
For example:
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
const { Webpack } = require('@embroider/webpack');
|
|
221
|
-
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
222
|
-
|
|
223
|
-
return require('@embroider/compat').compatBuild(app, Webpack, {
|
|
224
|
-
extraPublicTrees: [
|
|
225
|
-
require('ember-repl').buildComponentMap([
|
|
226
|
-
'limber/components/limber/menu',
|
|
227
|
-
'limber/components/limber/header',
|
|
228
|
-
'limber/components/external-link',
|
|
229
|
-
'limber/components/popper-j-s',
|
|
230
|
-
'ember-repl',
|
|
231
|
-
]),
|
|
232
|
-
],
|
|
233
|
-
// ...
|
|
234
|
-
});
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
this emits an `/ember-repl/component-map.js` file in your public tree,
|
|
238
|
-
which can then be `await import`ed and used via:
|
|
239
|
-
|
|
240
|
-
```js
|
|
241
|
-
let { COMPONENT_MAP } = await import('/ember-repl/component-map.js');
|
|
242
|
-
|
|
243
|
-
let { component, error, name } = await compileJS(code, COMPONENT_MAP);
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
|
|
247
412
|
## Security
|
|
248
413
|
|
|
249
414
|
Many developers know that evaluating runnable user input is a huge security risk.
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExtraModules } from "../types.js";
|
|
2
|
+
import Component from '@glimmer/component';
|
|
3
|
+
declare function evalSnippet(compiled: string, extraModules?: ExtraModules): {
|
|
4
|
+
default: Component;
|
|
5
|
+
services?: {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export { evalSnippet };
|
|
10
|
+
//# sourceMappingURL=browser/cjs/eval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser/cjs/eval.d.ts","sourceRoot":"","sources":["../src/browser/cjs/eval.ts"],"names":[],"mappings":"AAGA,OAAO,gBAAqB,oBAAiB;AAC7C,OAAO,SAAc,MAAM,oBAAoB,CAAC;AAEhD,iBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,YAAiB,GAC9B;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvC,CAmBA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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';\n\nimport type { ExtraModules } from '../types';\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;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 = 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/browser/cjs/index.ts"],"sourcesContent":["import { preprocess, transform } from '../gjs';\nimport { nameFor } from '../utils';\nimport { evalSnippet } from './eval';\n\nimport type { CompileResult, ExtraModules } from '../types';\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 = 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;AACrD,EAAA,IAAIW,YAAY,GAAGC,UAAU,CAACF,KAAK,EAAEV,IAAI,CAAC,CAAA;EAC1C,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;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompileResult } from "../types.js";
|
|
2
|
+
import { EvalImportMap, ScopeMap } from "./types.js";
|
|
3
|
+
declare function compileGJS(gjsInput: string, importMap?: EvalImportMap): Promise<CompileResult>;
|
|
4
|
+
declare function compileHBS(hbsInput: string, options?: {
|
|
5
|
+
moduleName?: string;
|
|
6
|
+
scope?: Record<string, unknown>;
|
|
7
|
+
}): Promise<CompileResult>;
|
|
8
|
+
declare function compileMD(glimdownInput: string, options?: {
|
|
9
|
+
importMap?: EvalImportMap;
|
|
10
|
+
topLevelScope?: ScopeMap;
|
|
11
|
+
CopyComponent?: string;
|
|
12
|
+
}): Promise<CompileResult & {
|
|
13
|
+
rootTemplate?: string;
|
|
14
|
+
}>;
|
|
15
|
+
export { compileGJS, compileHBS, compileMD };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { invocationName } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
async function compileAll(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, importMap) {
|
|
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 compileAll(js, 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.push(compiled);
|
|
62
|
+
}
|
|
63
|
+
return scope;
|
|
64
|
+
}
|
|
65
|
+
async function compileMD(glimdownInput, options) {
|
|
66
|
+
let importMap = options?.importMap;
|
|
67
|
+
let topLevelScope = options?.topLevelScope ?? {};
|
|
68
|
+
let rootTemplate;
|
|
69
|
+
let liveCode;
|
|
70
|
+
let scope = [];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Step 1: Convert Markdown To HTML (Ember).
|
|
74
|
+
*
|
|
75
|
+
* The remark plugin, remark-code-extra also extracts
|
|
76
|
+
* and transforms the code blocks we care about.
|
|
77
|
+
*
|
|
78
|
+
* These blocks will be compiled through babel and eval'd so the
|
|
79
|
+
* compiled rootTemplate can invoke them
|
|
80
|
+
*/
|
|
81
|
+
try {
|
|
82
|
+
let {
|
|
83
|
+
parseMarkdown
|
|
84
|
+
} = await import('./markdown-to-ember.js');
|
|
85
|
+
let {
|
|
86
|
+
templateOnlyGlimdown,
|
|
87
|
+
blocks
|
|
88
|
+
} = await parseMarkdown(glimdownInput, {
|
|
89
|
+
CopyComponent: options?.CopyComponent
|
|
90
|
+
});
|
|
91
|
+
rootTemplate = templateOnlyGlimdown;
|
|
92
|
+
liveCode = blocks;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return {
|
|
95
|
+
error: error,
|
|
96
|
+
name: 'unknown'
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Step 2: Compile the live code samples
|
|
102
|
+
*/
|
|
103
|
+
if (liveCode.length > 0) {
|
|
104
|
+
try {
|
|
105
|
+
scope = await extractScope(liveCode, importMap);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.info({
|
|
108
|
+
scope
|
|
109
|
+
});
|
|
110
|
+
console.error(error);
|
|
111
|
+
return {
|
|
112
|
+
error: error,
|
|
113
|
+
rootTemplate,
|
|
114
|
+
name: 'unknown'
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Make sure non of our snippets errored
|
|
121
|
+
*
|
|
122
|
+
* TODO: for these errors, report them differently so that we
|
|
123
|
+
* can render the 'Ember' and still highlight the correct line?
|
|
124
|
+
* or maybe there is a way to highlight in the editor instead?
|
|
125
|
+
*/
|
|
126
|
+
for (let {
|
|
127
|
+
error,
|
|
128
|
+
component
|
|
129
|
+
} of scope) {
|
|
130
|
+
if (!component) {
|
|
131
|
+
if (error) {
|
|
132
|
+
return {
|
|
133
|
+
error,
|
|
134
|
+
rootTemplate,
|
|
135
|
+
name: 'unknown'
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Step 4: Compile the Ember Template
|
|
143
|
+
*/
|
|
144
|
+
try {
|
|
145
|
+
let localScope = scope.reduce((accum, {
|
|
146
|
+
component,
|
|
147
|
+
name
|
|
148
|
+
}) => {
|
|
149
|
+
accum[invocationName(name)] = component;
|
|
150
|
+
return accum;
|
|
151
|
+
}, {});
|
|
152
|
+
return await compileHBS(rootTemplate, {
|
|
153
|
+
moduleName: 'DynamicRootTemplate',
|
|
154
|
+
scope: {
|
|
155
|
+
...topLevelScope,
|
|
156
|
+
...localScope
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
return {
|
|
161
|
+
error: error,
|
|
162
|
+
rootTemplate,
|
|
163
|
+
name: 'unknown'
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { compileGJS, compileHBS, compileMD };
|
|
169
|
+
//# sourceMappingURL=formats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.js","sources":["../../../src/browser/compile/formats.ts"],"sourcesContent":["import { invocationName } from '../utils';\n\nimport type { CompileResult } from '../types';\nimport type { ExtractedCode } from './markdown-to-ember';\nimport type { EvalImportMap, ScopeMap } from './types';\n\nasync function compileAll(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');\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');\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 importMap?: EvalImportMap\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 compileAll(js, 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);\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 CopyComponent?: string;\n }\n): Promise<CompileResult & { rootTemplate?: string }> {\n let importMap = options?.importMap;\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');\n let { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {\n CopyComponent: options?.CopyComponent,\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, importMap);\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((accum, { component, name }) => {\n accum[invocationName(name)] = component;\n\n return accum;\n }, {} as Record<string, unknown>);\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":["compileAll","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","compileMD","glimdownInput","topLevelScope","rootTemplate","parseMarkdown","templateOnlyGlimdown","blocks","CopyComponent","console","component","localScope","reduce","accum","invocationName","moduleName"],"mappings":";;AAMA,eAAeA,UAAUA,CAACC,EAAsB,EAAEC,SAAyB,EAAE;EAC3E,IAAIC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC7BJ,EAAE,CAACK,GAAG,CAAC,OAAO;AAAEC,IAAAA,IAAAA;AAAK,GAAC,KAAK;AACzB,IAAA,OAAO,MAAMC,UAAU,CAACD,IAAI,EAAEL,SAAS,CAAC,CAAA;AAC1C,GAAC,CACH,CAAC,CAAA;AAED,EAAA,OAAOC,OAAO,CAAA;AAChB,CAAA;AAEO,eAAeK,UAAUA,CAC9BC,QAAgB,EAChBP,SAAyB,EACD;EACxB,IAAI;IACF,IAAI;AAAEQ,MAAAA,SAAAA;AAAU,KAAC,GAAG,MAAM,OAAO,UAAO,CAAC,CAAA;AAEzC,IAAA,OAAO,MAAMA,SAAS,CAACD,QAAQ,EAAEP,SAAS,CAAC,CAAA;GAC5C,CAAC,OAAOS,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACnD,GAAA;AACF,CAAA;AAEO,eAAeC,UAAUA,CAC9BC,QAAgB,EAChBC,OAGC,EACuB;EACxB,IAAI;IACF,IAAI;AAAEF,MAAAA,UAAAA;AAAW,KAAC,GAAG,MAAM,OAAO,WAAQ,CAAC,CAAA;AAE3C,IAAA,OAAOA,UAAU,CAACC,QAAQ,EAAEC,OAAO,CAAC,CAAA;GACrC,CAAC,OAAOJ,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACnD,GAAA;AACF,CAAA;AAEA,eAAeI,YAAYA,CACzBC,QAAyB,EACzBf,SAAyB,EACC;EAC1B,IAAIgB,KAAsB,GAAG,EAAE,CAAA;AAE/B,EAAA,IAAIC,GAAG,GAAGF,QAAQ,CAACG,MAAM,CAAEb,IAAI,IAAKA,IAAI,CAACc,IAAI,KAAK,KAAK,CAAC,CAAA;EACxD,IAAIpB,EAAE,GAAGgB,QAAQ,CAACG,MAAM,CAAEb,IAAI,IAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAACe,QAAQ,CAACf,IAAI,CAACc,IAAI,CAAC,CAAC,CAAA;AAErE,EAAA,IAAIpB,EAAE,CAACsB,MAAM,GAAG,CAAC,EAAE;IACjB,IAAIC,QAAQ,GAAG,MAAMxB,UAAU,CAACC,EAAE,EAAEC,SAAS,CAAC,CAAA;IAE9C,MAAME,OAAO,CAACC,GAAG,CACfmB,QAAQ,CAAClB,GAAG,CAAC,MAAOmB,IAAI,IAAK;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAA,OAAOP,KAAK,CAACQ,IAAI,CAACD,IAAI,CAAC,CAAA;AACzB,KAAC,CACH,CAAC,CAAA;AACH,GAAA;AAEA,EAAA,KAAK,IAAI;AAAElB,IAAAA,IAAAA;GAAM,IAAIY,GAAG,EAAE;AACxB,IAAA,IAAIK,QAAQ,GAAG,MAAMX,UAAU,CAACN,IAAI,CAAC,CAAA;AAErCW,IAAAA,KAAK,CAACQ,IAAI,CAACF,QAAQ,CAAC,CAAA;AACtB,GAAA;AAEA,EAAA,OAAON,KAAK,CAAA;AACd,CAAA;AAEO,eAAeS,SAASA,CAC7BC,aAAqB,EACrBb,OAIC,EACmD;AACpD,EAAA,IAAIb,SAAS,GAAGa,OAAO,EAAEb,SAAS,CAAA;AAClC,EAAA,IAAI2B,aAAa,GAAGd,OAAO,EAAEc,aAAa,IAAI,EAAE,CAAA;AAChD,EAAA,IAAIC,YAAoB,CAAA;AACxB,EAAA,IAAIb,QAAyB,CAAA;EAC7B,IAAIC,KAAsB,GAAG,EAAE,CAAA;;AAE/B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,IAAI;IACF,IAAI;AAAEa,MAAAA,aAAAA;AAAc,KAAC,GAAG,MAAM,OAAO,wBAAqB,CAAC,CAAA;IAC3D,IAAI;MAAEC,oBAAoB;AAAEC,MAAAA,MAAAA;AAAO,KAAC,GAAG,MAAMF,aAAa,CAACH,aAAa,EAAE;MACxEM,aAAa,EAAEnB,OAAO,EAAEmB,aAAAA;AAC1B,KAAC,CAAC,CAAA;AAEFJ,IAAAA,YAAY,GAAGE,oBAAoB,CAAA;AACnCf,IAAAA,QAAQ,GAAGgB,MAAM,CAAA;GAClB,CAAC,OAAOtB,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;AAAEC,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACnD,GAAA;;AAEA;AACF;AACA;AACE,EAAA,IAAIK,QAAQ,CAACM,MAAM,GAAG,CAAC,EAAE;IACvB,IAAI;AACFL,MAAAA,KAAK,GAAG,MAAMF,YAAY,CAACC,QAAQ,EAAEf,SAAS,CAAC,CAAA;KAChD,CAAC,OAAOS,KAAK,EAAE;MACdwB,OAAO,CAACV,IAAI,CAAC;AAAEP,QAAAA,KAAAA;AAAM,OAAC,CAAC,CAAA;AACvBiB,MAAAA,OAAO,CAACxB,KAAK,CAACA,KAAK,CAAC,CAAA;MAEpB,OAAO;AAAEA,QAAAA,KAAK,EAAEA,KAAc;QAAEmB,YAAY;AAAElB,QAAAA,IAAI,EAAE,SAAA;OAAW,CAAA;AACjE,KAAA;AACF,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACE,EAAA,KAAK,IAAI;IAAED,KAAK;AAAEyB,IAAAA,SAAAA;GAAW,IAAIlB,KAAK,EAAE;IACtC,IAAI,CAACkB,SAAS,EAAE;AACd,MAAA,IAAIzB,KAAK,EAAE;QACT,OAAO;UAAEA,KAAK;UAAEmB,YAAY;AAAElB,UAAAA,IAAI,EAAE,SAAA;SAAW,CAAA;AACjD,OAAA;AACF,KAAA;AACF,GAAA;;AAEA;AACF;AACA;EACE,IAAI;IACF,IAAIyB,UAAU,GAAGnB,KAAK,CAACoB,MAAM,CAAC,CAACC,KAAK,EAAE;MAAEH,SAAS;AAAExB,MAAAA,IAAAA;AAAK,KAAC,KAAK;AAC5D2B,MAAAA,KAAK,CAACC,cAAc,CAAC5B,IAAI,CAAC,CAAC,GAAGwB,SAAS,CAAA;AAEvC,MAAA,OAAOG,KAAK,CAAA;KACb,EAAE,EAA6B,CAAC,CAAA;AAEjC,IAAA,OAAO,MAAM1B,UAAU,CAACiB,YAAY,EAAE;AACpCW,MAAAA,UAAU,EAAE,qBAAqB;AACjCvB,MAAAA,KAAK,EAAE;AACL,QAAA,GAAGW,aAAa;QAChB,GAAGQ,UAAAA;AACL,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAC,OAAO1B,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;MAAEmB,YAAY;AAAElB,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACjE,GAAA;AACF;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EvalImportMap, ScopeMap } from "./types.js";
|
|
2
|
+
import { ComponentLike } from '@glint/template';
|
|
3
|
+
type Format = 'glimdown' | 'gjs' | 'hbs';
|
|
4
|
+
declare const CACHE: Map<string, ComponentLike>;
|
|
5
|
+
/**
|
|
6
|
+
* This compileMD is a more robust version of the raw compiling used in "formats".
|
|
7
|
+
* This function manages cache, and has events for folks building UIs to hook in to
|
|
8
|
+
*/
|
|
9
|
+
declare function compile(text: string, { format, onSuccess, onError, onCompileStart, ...options }: {
|
|
10
|
+
format: Format;
|
|
11
|
+
onSuccess: (component: ComponentLike) => Promise<unknown> | unknown;
|
|
12
|
+
onError: (error: string) => Promise<unknown> | unknown;
|
|
13
|
+
onCompileStart: () => Promise<unknown> | unknown;
|
|
14
|
+
importMap?: EvalImportMap;
|
|
15
|
+
CopyComponent?: string;
|
|
16
|
+
topLevelScope?: ScopeMap;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
type Input = string | undefined | null;
|
|
19
|
+
/**
|
|
20
|
+
* By default, this compiles to `glimdown`. A Markdown format which
|
|
21
|
+
* extracts `live` tagged code snippets and compiles them to components.
|
|
22
|
+
*/
|
|
23
|
+
declare const Compiled: ((markdownText: Input | (() => Input), format?: Format | (() => Format) | undefined) => {
|
|
24
|
+
isReady: boolean;
|
|
25
|
+
error: unknown;
|
|
26
|
+
component: ComponentLike;
|
|
27
|
+
}) | (() => {
|
|
28
|
+
isReady: boolean;
|
|
29
|
+
error: unknown;
|
|
30
|
+
component: ComponentLike;
|
|
31
|
+
});
|
|
32
|
+
export { CACHE, compile, Compiled };
|