ember-repl 8.0.2 → 8.2.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/Compiled.d.ts +17 -0
- package/declarations/compile/Compiled.d.ts.map +1 -1
- package/declarations/compile/compile.d.ts +9 -0
- package/declarations/compile/compile.d.ts.map +1 -1
- package/declarations/compile/state.d.ts.map +1 -1
- package/declarations/index.d.ts +1 -0
- package/declarations/index.d.ts.map +1 -1
- package/declarations/services/compiler.d.ts +2 -1
- package/declarations/services/compiler.d.ts.map +1 -1
- package/declarations/services/known-modules.d.ts.map +1 -1
- package/dist/compile/Compiled.js +25 -4
- package/dist/compile/Compiled.js.map +1 -1
- package/dist/compile/compile.js +1 -1
- package/dist/compile/compile.js.map +1 -1
- package/dist/compile/state.js +2 -1
- package/dist/compile/state.js.map +1 -1
- package/dist/{index-F3Sr0JFE.js → index-C0sat7kP.js} +61 -8
- package/dist/index-C0sat7kP.js.map +1 -0
- package/dist/{plugin-DATxmrFU.js → plugin-ZDtYFKJg.js} +2 -8
- package/dist/{plugin-DATxmrFU.js.map → plugin-ZDtYFKJg.js.map} +1 -1
- package/dist/services/compiler.js +3 -2
- package/dist/services/compiler.js.map +1 -1
- package/dist/services/known-modules.js +4 -2
- package/dist/services/known-modules.js.map +1 -1
- package/package.json +23 -22
- package/src/compile/Compiled.ts +56 -7
- package/src/compile/compile.ts +13 -1
- package/src/compile/state.ts +3 -1
- package/src/index.ts +1 -0
- package/src/services/compiler.ts +6 -2
- package/src/services/known-modules.ts +2 -0
- package/dist/index-F3Sr0JFE.js.map +0 -1
package/src/compile/Compiled.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assert } from '@ember/debug';
|
|
2
|
+
|
|
1
3
|
import { resource, resourceFactory } from 'ember-resources';
|
|
2
4
|
|
|
3
5
|
import { getCompiler } from '../services/compiler.ts';
|
|
@@ -6,7 +8,28 @@ import { compile } from './compile.ts';
|
|
|
6
8
|
import type { CompileState } from './state.ts';
|
|
7
9
|
import type { Format, Input } from './types.ts';
|
|
8
10
|
|
|
11
|
+
export interface CompiledOptions {
|
|
12
|
+
format?: Format;
|
|
13
|
+
flavor?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Arguments forwarded to the compiled component.
|
|
16
|
+
*
|
|
17
|
+
* Pass a stable object reference whose property values are reactive
|
|
18
|
+
* (e.g. a `TrackedObject` or a plain object with getters reading
|
|
19
|
+
* `@tracked` state). Property updates propagate to the rendered
|
|
20
|
+
* component without triggering a recompile.
|
|
21
|
+
*
|
|
22
|
+
* Keys must be present when compilation happens — additional keys
|
|
23
|
+
* added later will not become reactive.
|
|
24
|
+
*/
|
|
25
|
+
args?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
9
28
|
export function Compiled(markdownText: Input | (() => Input)): CompileState;
|
|
29
|
+
export function Compiled(
|
|
30
|
+
markdownText: Input | (() => Input),
|
|
31
|
+
options: CompiledOptions
|
|
32
|
+
): CompileState;
|
|
10
33
|
export function Compiled(
|
|
11
34
|
markdownText: Input | (() => Input),
|
|
12
35
|
format?: Format,
|
|
@@ -25,27 +48,53 @@ export function Compiled(
|
|
|
25
48
|
/**
|
|
26
49
|
* By default, this compiles to `glimdown`. A Markdown format which
|
|
27
50
|
* extracts `live` tagged code snippets and compiles them to components.
|
|
51
|
+
*
|
|
52
|
+
* Pass a `CompiledOptions` bag as the second argument to specify
|
|
53
|
+
* `format`, `flavor`, and `args` forwarded to the rendered component.
|
|
28
54
|
*/
|
|
29
55
|
export function Compiled(
|
|
30
56
|
markdownText: Input | (() => Input),
|
|
31
|
-
|
|
57
|
+
maybeFormatOrOptions?: Format | (() => Format) | CompiledOptions,
|
|
32
58
|
maybeFlavor?: string | (() => string)
|
|
33
59
|
): CompileState {
|
|
34
60
|
return resource(({ owner }) => {
|
|
35
61
|
const input =
|
|
36
62
|
typeof markdownText === 'function' ? markdownText() : markdownText;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
|
|
64
|
+
let format: Format | undefined;
|
|
65
|
+
let flavor: string | undefined;
|
|
66
|
+
let args: Record<string, unknown> | undefined;
|
|
67
|
+
|
|
68
|
+
if (typeof maybeFormatOrOptions === 'function') {
|
|
69
|
+
format = maybeFormatOrOptions();
|
|
70
|
+
} else if (typeof maybeFormatOrOptions === 'string') {
|
|
71
|
+
format = maybeFormatOrOptions;
|
|
72
|
+
} else if (maybeFormatOrOptions) {
|
|
73
|
+
format = maybeFormatOrOptions.format;
|
|
74
|
+
flavor = maybeFormatOrOptions.flavor;
|
|
75
|
+
args = maybeFormatOrOptions.args;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
format ??= 'glimdown';
|
|
79
|
+
|
|
80
|
+
if (flavor === undefined) {
|
|
81
|
+
const positional =
|
|
82
|
+
typeof maybeFlavor === 'function' ? maybeFlavor() : maybeFlavor;
|
|
83
|
+
|
|
84
|
+
flavor = typeof positional === 'string' ? positional : undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
assert(
|
|
88
|
+
`second parameter to Compiled must be a format, an options bag, or a function that returns a format`,
|
|
89
|
+
typeof format === 'string'
|
|
90
|
+
);
|
|
43
91
|
|
|
44
92
|
const compiler = getCompiler(owner);
|
|
45
93
|
|
|
46
94
|
return compile(compiler, input, {
|
|
47
95
|
format,
|
|
48
96
|
flavor,
|
|
97
|
+
args,
|
|
49
98
|
});
|
|
50
99
|
});
|
|
51
100
|
}
|
package/src/compile/compile.ts
CHANGED
|
@@ -12,6 +12,15 @@ interface Options {
|
|
|
12
12
|
flavor?: string;
|
|
13
13
|
remarkPlugins?: unknown[];
|
|
14
14
|
rehypePlugins?: unknown[];
|
|
15
|
+
/**
|
|
16
|
+
* Arguments forwarded to the compiled component.
|
|
17
|
+
*
|
|
18
|
+
* Keys present on this object at compile time become reactive `@arg`
|
|
19
|
+
* references in the rendered component. Update the values on this object
|
|
20
|
+
* (e.g. via `@tracked` or `TrackedObject`) to propagate changes into the
|
|
21
|
+
* rendered component without recompiling.
|
|
22
|
+
*/
|
|
23
|
+
args?: Record<string, unknown>;
|
|
15
24
|
onSuccess?: (component: ComponentLike) => Promise<unknown> | unknown;
|
|
16
25
|
onError?: (error: string) => Promise<unknown> | unknown;
|
|
17
26
|
onCompileStart?: () => Promise<unknown> | unknown;
|
|
@@ -67,7 +76,10 @@ async function runTheCompiler({
|
|
|
67
76
|
if (options.format === 'glimdown') {
|
|
68
77
|
result = await service.compile('gmd', text, options as any);
|
|
69
78
|
} else if (options.format === 'gjs') {
|
|
70
|
-
result = await service.compileGJS(
|
|
79
|
+
result = await service.compileGJS(
|
|
80
|
+
text,
|
|
81
|
+
options as unknown as Record<string, unknown>
|
|
82
|
+
);
|
|
71
83
|
} else if (options.format === 'hbs') {
|
|
72
84
|
result = await service.compileHBS(text, options as any);
|
|
73
85
|
} else {
|
package/src/compile/state.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { tracked } from '@glimmer/tracking';
|
|
2
2
|
|
|
3
|
+
import { errorMessage } from 'repl-sdk';
|
|
4
|
+
|
|
3
5
|
import type { ComponentLike } from '@glint/template';
|
|
4
6
|
|
|
5
7
|
export const RESOLVE = Symbol('CompileState::resolve');
|
|
@@ -42,7 +44,7 @@ export class CompileState implements State {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
get reason() {
|
|
45
|
-
return this.error
|
|
47
|
+
return this.error ? errorMessage(this.error) : undefined;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
get isWaiting() {
|
package/src/index.ts
CHANGED
|
@@ -5,5 +5,6 @@ export { getCompiler } from './services/compiler.ts';
|
|
|
5
5
|
export { setup as setupCompiler } from './setup.ts';
|
|
6
6
|
|
|
7
7
|
// Public Types
|
|
8
|
+
export type { CompiledOptions } from './compile/Compiled.ts';
|
|
8
9
|
export type { CompileState } from './compile/state.ts';
|
|
9
10
|
export type { Format, ModuleMap, ScopeMap } from './compile/types.ts';
|
package/src/services/compiler.ts
CHANGED
|
@@ -383,9 +383,13 @@ export default class CompilerService {
|
|
|
383
383
|
* The returned component can be invoked explicitly in the consuming project.
|
|
384
384
|
*
|
|
385
385
|
* @param {string} code the code to be compiled
|
|
386
|
+
* @param {object} [options] additional render options (e.g. `args`)
|
|
386
387
|
*/
|
|
387
|
-
compileGJS(
|
|
388
|
-
|
|
388
|
+
compileGJS(
|
|
389
|
+
code: string,
|
|
390
|
+
options?: Record<string, unknown>
|
|
391
|
+
): Promise<CompileResult> {
|
|
392
|
+
return this.compile('gjs', code, options);
|
|
389
393
|
}
|
|
390
394
|
|
|
391
395
|
/**
|
|
@@ -8,11 +8,13 @@ const frameworkModules = {
|
|
|
8
8
|
'@ember/component/helper': () => import('@ember/component/helper'),
|
|
9
9
|
'@ember/component/template-only': () =>
|
|
10
10
|
import('@ember/component/template-only'),
|
|
11
|
+
'@ember/controller': () => import('@ember/controller'),
|
|
11
12
|
'@ember/debug': () => import('@ember/debug'),
|
|
12
13
|
'@ember/destroyable': () => import('@ember/destroyable'),
|
|
13
14
|
'@ember/helper': () => import('@ember/helper'),
|
|
14
15
|
'@ember/modifier': () => import('@ember/modifier'),
|
|
15
16
|
'@ember/object': () => import('@ember/object'),
|
|
17
|
+
'@ember/object/compat': () => import('@ember/object/compat'),
|
|
16
18
|
'@ember/object/internals': () => import('@ember/object/internals'),
|
|
17
19
|
'@ember/object/observers': () => import('@ember/object/observers'),
|
|
18
20
|
'@ember/owner': () => import('@ember/owner'),
|