ember-repl 5.0.1 → 6.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/declarations/compile/formats/gjs/eval.d.ts.map +1 -1
- package/declarations/compile/formats/gjs/index.d.ts.map +1 -1
- package/declarations/compile/formats/gjs/known-modules.d.ts +3 -1
- package/declarations/compile/formats/gjs/known-modules.d.ts.map +1 -1
- package/declarations/compile/formats/hbs.d.ts.map +1 -1
- package/declarations/compile/formats/markdown.d.ts.map +1 -1
- package/declarations/compile/formats.d.ts +1 -2
- package/declarations/compile/formats.d.ts.map +1 -1
- package/declarations/compile/index.d.ts +1 -2
- package/declarations/compile/index.d.ts.map +1 -1
- package/dist/compile/formats/gjs/eval.js +1 -2
- package/dist/compile/formats/gjs/eval.js.map +1 -1
- package/dist/compile/formats/gjs/index.js +12 -10
- package/dist/compile/formats/gjs/index.js.map +1 -1
- package/dist/compile/formats/gjs/known-modules.js +3 -1
- package/dist/compile/formats/gjs/known-modules.js.map +1 -1
- package/dist/compile/formats/hbs.js +10 -11
- package/dist/compile/formats/hbs.js.map +1 -1
- package/dist/compile/formats/markdown.js +23 -21
- package/dist/compile/formats/markdown.js.map +1 -1
- package/dist/compile/formats.js +14 -14
- package/dist/compile/formats.js.map +1 -1
- package/dist/compile/index.js +10 -10
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/utils.js +1 -1
- package/dist/compile/utils.js.map +1 -1
- package/package.json +42 -50
- package/src/compile/formats/gjs/eval.ts +1 -2
- package/src/compile/formats/gjs/index.ts +12 -10
- package/src/compile/formats/gjs/known-modules.ts +1 -1
- package/src/compile/formats/hbs.ts +10 -11
- package/src/compile/formats/markdown.ts +22 -21
- package/src/compile/formats.ts +15 -16
- package/src/compile/index.ts +12 -12
- package/src/compile/utils.ts +1 -1
|
@@ -63,7 +63,7 @@ function isBelow(meta: string) {
|
|
|
63
63
|
|
|
64
64
|
// TODO: extract and publish remark plugin
|
|
65
65
|
function liveCodeExtraction(options: Options = {}) {
|
|
66
|
-
|
|
66
|
+
const { copyComponent, snippets, demo } = options;
|
|
67
67
|
let { classList: snippetClasses } = snippets || {};
|
|
68
68
|
let { classList: demoClasses } = demo || {};
|
|
69
69
|
|
|
@@ -73,7 +73,8 @@ function liveCodeExtraction(options: Options = {}) {
|
|
|
73
73
|
function isRelevantCode(node: Code): node is RelevantCode {
|
|
74
74
|
if (node.type !== 'code') return false;
|
|
75
75
|
|
|
76
|
-
let { meta
|
|
76
|
+
let { meta } = node;
|
|
77
|
+
const { lang } = node;
|
|
77
78
|
|
|
78
79
|
meta = meta?.trim();
|
|
79
80
|
|
|
@@ -88,7 +89,7 @@ function liveCodeExtraction(options: Options = {}) {
|
|
|
88
89
|
return true;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
const copyNode = {
|
|
92
93
|
type: 'html',
|
|
93
94
|
value: copyComponent,
|
|
94
95
|
};
|
|
@@ -123,7 +124,7 @@ function liveCodeExtraction(options: Options = {}) {
|
|
|
123
124
|
if (index === null || index === undefined) return;
|
|
124
125
|
|
|
125
126
|
if (!isRelevantCode(node as Code)) {
|
|
126
|
-
|
|
127
|
+
const enhanced = enhance(node as Code);
|
|
127
128
|
|
|
128
129
|
parent.children[index] = enhanced;
|
|
129
130
|
|
|
@@ -134,26 +135,26 @@ function liveCodeExtraction(options: Options = {}) {
|
|
|
134
135
|
|
|
135
136
|
seen.add(node);
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
const { meta, lang, value } = node as Code;
|
|
138
139
|
|
|
139
140
|
if (!meta) return 'skip';
|
|
140
141
|
if (!lang) return 'skip';
|
|
141
142
|
|
|
142
143
|
file.data.liveCode ??= [];
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
const code = value.trim();
|
|
146
|
+
const name = nameFor(code);
|
|
146
147
|
let invocation = invocationOf(name);
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
const shadow = options.shadowComponent;
|
|
149
150
|
|
|
150
|
-
|
|
151
|
+
const wrapInShadow = shadow && !meta?.includes('no-shadow');
|
|
151
152
|
|
|
152
153
|
if (wrapInShadow) {
|
|
153
154
|
invocation = `<${shadow}>${invocation}</${shadow}>`;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
const invokeNode = {
|
|
157
158
|
type: 'html',
|
|
158
159
|
data: {
|
|
159
160
|
hProperties: { [GLIMDOWN_RENDER]: true },
|
|
@@ -161,7 +162,7 @@ function liveCodeExtraction(options: Options = {}) {
|
|
|
161
162
|
value: `<div class="${demoClasses}">${invocation}</div>`,
|
|
162
163
|
};
|
|
163
164
|
|
|
164
|
-
|
|
165
|
+
const wrapper = enhance(node as Code);
|
|
165
166
|
|
|
166
167
|
file.data.liveCode.push({
|
|
167
168
|
lang,
|
|
@@ -169,9 +170,9 @@ function liveCodeExtraction(options: Options = {}) {
|
|
|
169
170
|
code,
|
|
170
171
|
});
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
const live = isLive(meta);
|
|
174
|
+
const preview = isPreview(meta);
|
|
175
|
+
const below = isBelow(meta);
|
|
175
176
|
|
|
176
177
|
if (live && preview && below) {
|
|
177
178
|
flatReplaceAt(parent.children, index, [wrapper, invokeNode]);
|
|
@@ -227,7 +228,7 @@ function buildCompiler(options: ParseMarkdownOptions) {
|
|
|
227
228
|
options.remarkPlugins.forEach((plugin) => {
|
|
228
229
|
// Arrays are how plugins are passed options (for some reason?)
|
|
229
230
|
// why not just invoke the the function?
|
|
230
|
-
|
|
231
|
+
const p = Array.isArray(plugin) ? plugin : [plugin];
|
|
231
232
|
|
|
232
233
|
compiler = compiler.use(...(p as [any]));
|
|
233
234
|
});
|
|
@@ -256,7 +257,7 @@ function buildCompiler(options: ParseMarkdownOptions) {
|
|
|
256
257
|
compiler = compiler.use(() => (tree: Node) => {
|
|
257
258
|
visit(tree, function (node) {
|
|
258
259
|
// We rely on an implicit transformation of data.hProperties => properties
|
|
259
|
-
|
|
260
|
+
const properties = (node as any).properties;
|
|
260
261
|
|
|
261
262
|
if (properties?.[GLIMDOWN_PREVIEW]) {
|
|
262
263
|
return 'skip';
|
|
@@ -295,7 +296,7 @@ function buildCompiler(options: ParseMarkdownOptions) {
|
|
|
295
296
|
options.rehypePlugins.forEach((plugin) => {
|
|
296
297
|
// Arrays are how plugins are passed options (for some reason?)
|
|
297
298
|
// why not just invoke the the function?
|
|
298
|
-
|
|
299
|
+
const p = Array.isArray(plugin) ? plugin : [plugin];
|
|
299
300
|
|
|
300
301
|
compiler = compiler.use(...(p as [any]));
|
|
301
302
|
});
|
|
@@ -335,10 +336,10 @@ export async function parseMarkdown(
|
|
|
335
336
|
input: string,
|
|
336
337
|
options: ParseMarkdownOptions = {}
|
|
337
338
|
): Promise<LiveCodeExtraction> {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
const markdownCompiler = buildCompiler(options);
|
|
340
|
+
const processed = await markdownCompiler.process(input);
|
|
341
|
+
const liveCode = (processed.data as LiveData).liveCode || [];
|
|
342
|
+
const templateOnly = processed.toString();
|
|
342
343
|
|
|
343
344
|
return { templateOnlyGlimdown: templateOnly, blocks: liveCode };
|
|
344
345
|
}
|
package/src/compile/formats.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { invocationName } from './utils.ts';
|
|
2
2
|
|
|
3
3
|
import type { ExtractedCode } from './formats/markdown.ts';
|
|
4
|
-
import type { CompileResult, UnifiedPlugin } from './types.ts';
|
|
5
|
-
import type { EvalImportMap, ScopeMap } from './types.ts';
|
|
4
|
+
import type { CompileResult, EvalImportMap, ScopeMap, UnifiedPlugin } from './types.ts';
|
|
6
5
|
|
|
7
6
|
async function compileGJSArray(js: { code: string }[], importMap?: EvalImportMap) {
|
|
8
|
-
|
|
7
|
+
const modules = await Promise.all(
|
|
9
8
|
js.map(async ({ code }) => {
|
|
10
9
|
return await compileGJS(code, importMap);
|
|
11
10
|
})
|
|
@@ -19,7 +18,7 @@ export async function compileGJS(
|
|
|
19
18
|
importMap?: EvalImportMap
|
|
20
19
|
): Promise<CompileResult> {
|
|
21
20
|
try {
|
|
22
|
-
|
|
21
|
+
const { compileJS } = await import('./formats/gjs/index.ts');
|
|
23
22
|
|
|
24
23
|
return await compileJS(gjsInput, importMap);
|
|
25
24
|
} catch (error) {
|
|
@@ -35,7 +34,7 @@ export async function compileHBS(
|
|
|
35
34
|
}
|
|
36
35
|
): Promise<CompileResult> {
|
|
37
36
|
try {
|
|
38
|
-
|
|
37
|
+
const { compileHBS } = await import('./formats/hbs.ts');
|
|
39
38
|
|
|
40
39
|
return compileHBS(hbsInput, options);
|
|
41
40
|
} catch (error) {
|
|
@@ -50,13 +49,13 @@ async function extractScope(
|
|
|
50
49
|
topLevelScope?: ScopeMap;
|
|
51
50
|
}
|
|
52
51
|
): Promise<CompileResult[]> {
|
|
53
|
-
|
|
52
|
+
const scope: CompileResult[] = [];
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const hbs = liveCode.filter((code) => code.lang === 'hbs');
|
|
55
|
+
const js = liveCode.filter((code) => ['js', 'gjs'].includes(code.lang));
|
|
57
56
|
|
|
58
57
|
if (js.length > 0) {
|
|
59
|
-
|
|
58
|
+
const compiled = await compileGJSArray(js, options?.importMap);
|
|
60
59
|
|
|
61
60
|
await Promise.all(
|
|
62
61
|
compiled.map(async (info) => {
|
|
@@ -75,8 +74,8 @@ async function extractScope(
|
|
|
75
74
|
);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
for (
|
|
79
|
-
|
|
77
|
+
for (const { code } of hbs) {
|
|
78
|
+
const compiled = await compileHBS(code, { scope: options?.topLevelScope });
|
|
80
79
|
|
|
81
80
|
scope.push(compiled);
|
|
82
81
|
}
|
|
@@ -95,7 +94,7 @@ export async function compileMD(
|
|
|
95
94
|
ShadowComponent?: string;
|
|
96
95
|
}
|
|
97
96
|
): Promise<CompileResult & { rootTemplate?: string }> {
|
|
98
|
-
|
|
97
|
+
const topLevelScope = options?.topLevelScope ?? {};
|
|
99
98
|
let rootTemplate: string;
|
|
100
99
|
let liveCode: ExtractedCode[];
|
|
101
100
|
let scope: CompileResult[] = [];
|
|
@@ -110,8 +109,8 @@ export async function compileMD(
|
|
|
110
109
|
* compiled rootTemplate can invoke them
|
|
111
110
|
*/
|
|
112
111
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
const { parseMarkdown } = await import('./formats/markdown.ts');
|
|
113
|
+
const { templateOnlyGlimdown, blocks } = await parseMarkdown(glimdownInput, {
|
|
115
114
|
CopyComponent: options?.CopyComponent,
|
|
116
115
|
ShadowComponent: options?.ShadowComponent,
|
|
117
116
|
remarkPlugins: options?.remarkPlugins,
|
|
@@ -145,7 +144,7 @@ export async function compileMD(
|
|
|
145
144
|
* can render the 'Ember' and still highlight the correct line?
|
|
146
145
|
* or maybe there is a way to highlight in the editor instead?
|
|
147
146
|
*/
|
|
148
|
-
for (
|
|
147
|
+
for (const { error, component } of scope) {
|
|
149
148
|
if (!component) {
|
|
150
149
|
if (error) {
|
|
151
150
|
return { error, rootTemplate, name: 'unknown' };
|
|
@@ -157,7 +156,7 @@ export async function compileMD(
|
|
|
157
156
|
* Step 4: Compile the Ember Template
|
|
158
157
|
*/
|
|
159
158
|
try {
|
|
160
|
-
|
|
159
|
+
const localScope = scope.reduce(
|
|
161
160
|
(accum, { component, name }) => {
|
|
162
161
|
accum[invocationName(name)] = component;
|
|
163
162
|
|
package/src/compile/index.ts
CHANGED
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
} from './formats.ts';
|
|
8
8
|
import { nameFor } from './utils.ts';
|
|
9
9
|
|
|
10
|
-
import type { CompileResult, UnifiedPlugin } from './types.ts';
|
|
11
|
-
import type { EvalImportMap, ScopeMap } from './types.ts';
|
|
10
|
+
import type { CompileResult, EvalImportMap, ScopeMap, UnifiedPlugin } from './types.ts';
|
|
12
11
|
import type { ComponentLike } from '@glint/template';
|
|
12
|
+
|
|
13
13
|
type Format = 'glimdown' | 'gjs' | 'hbs';
|
|
14
14
|
|
|
15
15
|
export const CACHE = new Map<string, ComponentLike>();
|
|
@@ -80,10 +80,10 @@ export async function compile(
|
|
|
80
80
|
text: string,
|
|
81
81
|
options: GlimdownOptions | GJSOptions | HBSOptions
|
|
82
82
|
): Promise<void> {
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const { onSuccess, onError, onCompileStart } = options;
|
|
84
|
+
const id = nameFor(`${options.format}:${text}`);
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
const existing = CACHE.get(id);
|
|
87
87
|
|
|
88
88
|
if (existing) {
|
|
89
89
|
onSuccess(existing);
|
|
@@ -179,15 +179,15 @@ export function Compiled(
|
|
|
179
179
|
maybeOptions?: Format | (() => Format) | ExtraOptions | (() => ExtraOptions)
|
|
180
180
|
): Value {
|
|
181
181
|
return resource(() => {
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
const maybeObject = typeof maybeOptions === 'function' ? maybeOptions() : maybeOptions;
|
|
183
|
+
const format =
|
|
184
184
|
(typeof maybeObject === 'string' ? maybeObject : maybeObject?.format) || 'glimdown';
|
|
185
|
-
|
|
185
|
+
const options = (typeof maybeObject === 'string' ? {} : maybeObject) || {};
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
const input = typeof markdownText === 'function' ? markdownText() : markdownText;
|
|
188
|
+
const ready = cell(false);
|
|
189
|
+
const error = cell<string | null>();
|
|
190
|
+
const result = cell<ComponentLike>();
|
|
191
191
|
|
|
192
192
|
if (input) {
|
|
193
193
|
compile(input, {
|
package/src/compile/utils.ts
CHANGED
|
@@ -18,7 +18,7 @@ const DEFAULT_PREFIX = 'ember-repl';
|
|
|
18
18
|
* and generally allowing a consumer to derive "known references" to user-input
|
|
19
19
|
*/
|
|
20
20
|
export function nameFor(code: string, prefix = DEFAULT_PREFIX) {
|
|
21
|
-
|
|
21
|
+
const id = uuidv5(code, NAMESPACE);
|
|
22
22
|
|
|
23
23
|
return `${prefix ? `${prefix}-` : ''}${id}`;
|
|
24
24
|
}
|