ember-repl 3.0.0-beta.0 → 3.0.0-beta.2
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 +176 -42
- package/dist/browser/compile/formats.d.ts +16 -0
- package/dist/browser/compile/formats.js +170 -0
- package/dist/browser/compile/formats.js.map +1 -0
- package/dist/browser/compile/index.d.ts +33 -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/eti/preprocess.js +0 -1
- package/dist/browser/eti/preprocess.js.map +1 -1
- package/dist/browser/hbs.d.ts +5 -2
- package/dist/browser/hbs.js +2 -5
- package/dist/browser/hbs.js.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/known-modules.d.ts +0 -2
- package/dist/browser/known-modules.js +0 -2
- package/dist/browser/known-modules.js.map +1 -1
- package/dist/browser/types.d.ts +4 -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 +37 -13
- package/src/browser/compile/formats.ts +170 -0
- package/src/browser/compile/index.ts +132 -0
- package/src/browser/compile/markdown-to-ember.ts +318 -0
- package/src/browser/compile/types.ts +7 -0
- package/src/browser/hbs.ts +7 -7
- package/src/browser/index.ts +1 -0
- package/src/browser/known-modules.ts +0 -2
- package/src/browser/types.ts +4 -0
- package/src/test-support/index.ts +5 -0
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
|
|
|
@@ -48,20 +53,71 @@ Object.assign(window, {
|
|
|
48
53
|
|
|
49
54
|
```
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
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:
|
|
52
67
|
|
|
53
68
|
```js
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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>
|
|
58
84
|
|
|
59
|
-
// ...
|
|
60
85
|
```
|
|
61
86
|
|
|
62
|
-
|
|
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
|
+
|
|
63
119
|
|
|
64
|
-
|
|
120
|
+
#### Managing your own reactivity
|
|
65
121
|
|
|
66
122
|
```js
|
|
67
123
|
import Component from '@glimmer/component';
|
|
@@ -84,7 +140,14 @@ export class Renderer extends Component {
|
|
|
84
140
|
{{/if}}
|
|
85
141
|
```
|
|
86
142
|
|
|
87
|
-
|
|
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
|
|
88
151
|
|
|
89
152
|
```js
|
|
90
153
|
import Component from '@glimmer/component';
|
|
@@ -98,6 +161,110 @@ export class Renderer extends Component {
|
|
|
98
161
|
<this.compileResult.component />
|
|
99
162
|
```
|
|
100
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
|
+
|
|
101
268
|
### Using existing components
|
|
102
269
|
|
|
103
270
|
`ember-repl` is strict-mode only, so any component that you want to invoke
|
|
@@ -242,39 +409,6 @@ packagerOptions: {
|
|
|
242
409
|
},
|
|
243
410
|
```
|
|
244
411
|
|
|
245
|
-
If you are using ember-repl to showcase a styleguide _and_ have maximum strictness enabled in embroider,
|
|
246
|
-
you'll need to manually (or programatically) list out each of the components you want to force to be
|
|
247
|
-
included in the build output using the `buildComponentMap` function in your `ember-cli-build.js`.
|
|
248
|
-
For example:
|
|
249
|
-
|
|
250
|
-
```js
|
|
251
|
-
const { Webpack } = require('@embroider/webpack');
|
|
252
|
-
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
253
|
-
|
|
254
|
-
return require('@embroider/compat').compatBuild(app, Webpack, {
|
|
255
|
-
extraPublicTrees: [
|
|
256
|
-
require('ember-repl').buildComponentMap([
|
|
257
|
-
'limber/components/limber/menu',
|
|
258
|
-
'limber/components/limber/header',
|
|
259
|
-
'limber/components/external-link',
|
|
260
|
-
'limber/components/popper-j-s',
|
|
261
|
-
'ember-repl',
|
|
262
|
-
]),
|
|
263
|
-
],
|
|
264
|
-
// ...
|
|
265
|
-
});
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
this emits an `/ember-repl/component-map.js` file in your public tree,
|
|
269
|
-
which can then be `await import`ed and used via:
|
|
270
|
-
|
|
271
|
-
```js
|
|
272
|
-
let { COMPONENT_MAP } = await import('/ember-repl/component-map.js');
|
|
273
|
-
|
|
274
|
-
let { component, error, name } = await compileJS(code, COMPONENT_MAP);
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
|
|
278
412
|
## Security
|
|
279
413
|
|
|
280
414
|
Many developers know that evaluating runnable user input is a huge security risk.
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
ShadowComponent?: string;
|
|
13
|
+
}): Promise<CompileResult & {
|
|
14
|
+
rootTemplate?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export { compileGJS, compileHBS, compileMD };
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
ShadowComponent: options?.ShadowComponent
|
|
91
|
+
});
|
|
92
|
+
rootTemplate = templateOnlyGlimdown;
|
|
93
|
+
liveCode = blocks;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return {
|
|
96
|
+
error: error,
|
|
97
|
+
name: 'unknown'
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Step 2: Compile the live code samples
|
|
103
|
+
*/
|
|
104
|
+
if (liveCode.length > 0) {
|
|
105
|
+
try {
|
|
106
|
+
scope = await extractScope(liveCode, importMap);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.info({
|
|
109
|
+
scope
|
|
110
|
+
});
|
|
111
|
+
console.error(error);
|
|
112
|
+
return {
|
|
113
|
+
error: error,
|
|
114
|
+
rootTemplate,
|
|
115
|
+
name: 'unknown'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Make sure non of our snippets errored
|
|
122
|
+
*
|
|
123
|
+
* TODO: for these errors, report them differently so that we
|
|
124
|
+
* can render the 'Ember' and still highlight the correct line?
|
|
125
|
+
* or maybe there is a way to highlight in the editor instead?
|
|
126
|
+
*/
|
|
127
|
+
for (let {
|
|
128
|
+
error,
|
|
129
|
+
component
|
|
130
|
+
} of scope) {
|
|
131
|
+
if (!component) {
|
|
132
|
+
if (error) {
|
|
133
|
+
return {
|
|
134
|
+
error,
|
|
135
|
+
rootTemplate,
|
|
136
|
+
name: 'unknown'
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Step 4: Compile the Ember Template
|
|
144
|
+
*/
|
|
145
|
+
try {
|
|
146
|
+
let localScope = scope.reduce((accum, {
|
|
147
|
+
component,
|
|
148
|
+
name
|
|
149
|
+
}) => {
|
|
150
|
+
accum[invocationName(name)] = component;
|
|
151
|
+
return accum;
|
|
152
|
+
}, {});
|
|
153
|
+
return await compileHBS(rootTemplate, {
|
|
154
|
+
moduleName: 'DynamicRootTemplate',
|
|
155
|
+
scope: {
|
|
156
|
+
...topLevelScope,
|
|
157
|
+
...localScope
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return {
|
|
162
|
+
error: error,
|
|
163
|
+
rootTemplate,
|
|
164
|
+
name: 'unknown'
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { compileGJS, compileHBS, compileMD };
|
|
170
|
+
//# 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 ShadowComponent?: 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 ShadowComponent: options?.ShadowComponent,\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","ShadowComponent","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,CAC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OAAO;UAAEA,KAAK;UAAEmB,YAAY;AAAElB,UAAAA,IAAI,EAAE,SAAA;SAAW,CAAA;AACjD,OAAA;AACF,KAAA;AACF,GAAA;;AAEA;AACF;AACA;EACE,IAAI;IACF,IAAI0B,UAAU,GAAGpB,KAAK,CAACqB,MAAM,CAAC,CAACC,KAAK,EAAE;MAAEH,SAAS;AAAEzB,MAAAA,IAAAA;AAAK,KAAC,KAAK;AAC5D4B,MAAAA,KAAK,CAACC,cAAc,CAAC7B,IAAI,CAAC,CAAC,GAAGyB,SAAS,CAAA;AAEvC,MAAA,OAAOG,KAAK,CAAA;KACb,EAAE,EAA6B,CAAC,CAAA;AAEjC,IAAA,OAAO,MAAM3B,UAAU,CAACiB,YAAY,EAAE;AACpCY,MAAAA,UAAU,EAAE,qBAAqB;AACjCxB,MAAAA,KAAK,EAAE;AACL,QAAA,GAAGW,aAAa;QAChB,GAAGS,UAAAA;AACL,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAC,OAAO3B,KAAK,EAAE;IACd,OAAO;AAAEA,MAAAA,KAAK,EAAEA,KAAc;MAAEmB,YAAY;AAAElB,MAAAA,IAAI,EAAE,SAAA;KAAW,CAAA;AACjE,GAAA;AACF;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
ShadowComponent?: string;
|
|
17
|
+
topLevelScope?: ScopeMap;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
type Input = string | undefined | null;
|
|
20
|
+
/**
|
|
21
|
+
* By default, this compiles to `glimdown`. A Markdown format which
|
|
22
|
+
* extracts `live` tagged code snippets and compiles them to components.
|
|
23
|
+
*/
|
|
24
|
+
declare const Compiled: ((markdownText: Input | (() => Input), format?: Format | (() => Format) | undefined) => {
|
|
25
|
+
isReady: boolean;
|
|
26
|
+
error: unknown;
|
|
27
|
+
component: ComponentLike;
|
|
28
|
+
}) | (() => {
|
|
29
|
+
isReady: boolean;
|
|
30
|
+
error: unknown;
|
|
31
|
+
component: ComponentLike;
|
|
32
|
+
});
|
|
33
|
+
export { CACHE, compile, Compiled };
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
* This compileMD is a more robust version of the raw compiling used in "formats".
|
|
10
|
+
* This function manages cache, and has events for folks building UIs to hook in to
|
|
11
|
+
*/
|
|
12
|
+
async function compile(text, {
|
|
13
|
+
format,
|
|
14
|
+
onSuccess,
|
|
15
|
+
onError,
|
|
16
|
+
onCompileStart,
|
|
17
|
+
...options
|
|
18
|
+
}) {
|
|
19
|
+
let id = nameFor(text);
|
|
20
|
+
let existing = CACHE.get(id);
|
|
21
|
+
if (existing) {
|
|
22
|
+
onSuccess(existing);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!SUPPORTED_FORMATS.includes(format)) {
|
|
26
|
+
await onError(`Unsupported format: ${format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
await onCompileStart();
|
|
30
|
+
if (!text) {
|
|
31
|
+
await onError('No Input Document yet');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let result;
|
|
35
|
+
if (format === 'glimdown') {
|
|
36
|
+
result = await compileMD(text, options);
|
|
37
|
+
} else if (format === 'gjs') {
|
|
38
|
+
result = await compileGJS(text, options.importMap);
|
|
39
|
+
} else if (format === 'hbs') {
|
|
40
|
+
result = await compileHBS(text, {
|
|
41
|
+
scope: options.topLevelScope
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
await onError(`Unsupported format: ${format}. Supported formats: ${SUPPORTED_FORMATS}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (result.error) {
|
|
48
|
+
await onError(result.error.message || `${result.error}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
CACHE.set(id, result.component);
|
|
52
|
+
await onSuccess(result.component);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* By default, this compiles to `glimdown`. A Markdown format which
|
|
56
|
+
* extracts `live` tagged code snippets and compiles them to components.
|
|
57
|
+
*/
|
|
58
|
+
const Compiled = resourceFactory((markdownText, format) => {
|
|
59
|
+
return resource(() => {
|
|
60
|
+
let _format = (typeof format === 'function' ? format() : format) || 'glimdown';
|
|
61
|
+
let input = typeof markdownText === 'function' ? markdownText() : markdownText;
|
|
62
|
+
let ready = cell(false);
|
|
63
|
+
let error = cell();
|
|
64
|
+
let result = cell();
|
|
65
|
+
if (input) {
|
|
66
|
+
compile(input, {
|
|
67
|
+
format: _format,
|
|
68
|
+
onSuccess: async component => {
|
|
69
|
+
result.current = component;
|
|
70
|
+
ready.set(true);
|
|
71
|
+
error.set(null);
|
|
72
|
+
},
|
|
73
|
+
onError: async e => {
|
|
74
|
+
error.set(e);
|
|
75
|
+
},
|
|
76
|
+
onCompileStart: async () => {
|
|
77
|
+
ready.set(false);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return () => ({
|
|
82
|
+
isReady: ready.current,
|
|
83
|
+
error: error.current,
|
|
84
|
+
component: result.current
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export { CACHE, Compiled, compile };
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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';\nimport {\n compileGJS as processGJS,\n compileHBS as processHBS,\n compileMD as processMD,\n} from './formats';\n\nimport type { CompileResult } from '../types';\nimport type { EvalImportMap, ScopeMap } from './types';\nimport type { ComponentLike } from '@glint/template';\ntype Format = 'glimdown' | 'gjs' | 'hbs';\n\nexport const CACHE = new Map<string, ComponentLike>();\n\nconst SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];\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 {\n format,\n onSuccess,\n onError,\n onCompileStart,\n ...options\n }: {\n format: Format;\n onSuccess: (component: ComponentLike) => Promise<unknown> | unknown;\n onError: (error: string) => Promise<unknown> | unknown;\n onCompileStart: () => Promise<unknown> | unknown;\n importMap?: EvalImportMap;\n CopyComponent?: string;\n ShadowComponent?: string;\n topLevelScope?: ScopeMap;\n }\n) {\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(format)) {\n await onError(`Unsupported format: ${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 (format === 'glimdown') {\n result = await processMD(text, options);\n } else if (format === 'gjs') {\n result = await processGJS(text, options.importMap);\n } else if (format === 'hbs') {\n result = await processHBS(text, {\n scope: options.topLevelScope,\n });\n } else {\n await onError(`Unsupported format: ${format}. Supported formats: ${SUPPORTED_FORMATS}`);\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\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 const Compiled = resourceFactory(\n (markdownText: Input | (() => Input), format?: Format | (() => Format)) => {\n return resource(() => {\n let _format: Format = (typeof format === 'function' ? format() : format) || 'glimdown';\n let input = typeof markdownText === 'function' ? markdownText() : markdownText;\n let ready = cell(false);\n let error = cell();\n let result = cell<ComponentLike>();\n\n if (input) {\n compile(input, {\n format: _format,\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 });\n }\n\n return () => ({\n isReady: ready.current,\n error: error.current,\n component: result.current,\n });\n });\n }\n);\n"],"names":["CACHE","Map","SUPPORTED_FORMATS","compile","text","format","onSuccess","onError","onCompileStart","options","id","nameFor","existing","get","includes","result","processMD","processGJS","importMap","processHBS","scope","topLevelScope","error","message","set","component","Compiled","resourceFactory","markdownText","resource","_format","input","ready","cell","current","e","isReady"],"mappings":";;;;MAcaA,KAAK,GAAG,IAAIC,GAAG,GAAyB;AAErD,MAAMC,iBAAiB,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;;AAEpD;AACA;AACA;AACA;AACO,eAAeC,OAAOA,CAC3BC,IAAY,EACZ;EACEC,MAAM;EACNC,SAAS;EACTC,OAAO;EACPC,cAAc;E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,CAAC,CAAA;SACb;QACD3B,cAAc,EAAE,YAAY;AAC1BwB,UAAAA,KAAK,CAACR,GAAG,CAAC,KAAK,CAAC,CAAA;AAClB,SAAA;AACF,OAAC,CAAC,CAAA;AACJ,KAAA;AAEA,IAAA,OAAO,OAAO;MACZY,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,CACF;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface ExtractedCode {
|
|
2
|
+
name: string;
|
|
3
|
+
code: string;
|
|
4
|
+
lang: string;
|
|
5
|
+
}
|
|
6
|
+
interface LiveCodeExtraction {
|
|
7
|
+
templateOnlyGlimdown: string;
|
|
8
|
+
blocks: ExtractedCode[];
|
|
9
|
+
}
|
|
10
|
+
interface ParseMarkdownOptions {
|
|
11
|
+
CopyComponent?: string;
|
|
12
|
+
ShadowComponent?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @internal not under semver
|
|
16
|
+
*/
|
|
17
|
+
declare function parseMarkdown(input: string, options?: ParseMarkdownOptions): Promise<LiveCodeExtraction>;
|
|
18
|
+
export { ExtractedCode, LiveCodeExtraction, parseMarkdown };
|