repl-sdk 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { renderApp } from './render-app-island.js';
|
|
1
|
+
import { makeOwner } from './owner.js';
|
|
3
2
|
|
|
4
3
|
let elementId = 0;
|
|
5
4
|
|
|
@@ -168,35 +167,12 @@ export async function compiler(config, api) {
|
|
|
168
167
|
|
|
169
168
|
element.setAttribute(attribute, '');
|
|
170
169
|
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
'@ember/routing/route',
|
|
178
|
-
'@ember/test-waiters',
|
|
179
|
-
'@ember/runloop',
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
// We don't want to await here, because we need to early
|
|
183
|
-
// return the element so that the app can render in to it.
|
|
184
|
-
// (Ember will only render in to an element if it's present in the DOM)
|
|
185
|
-
return renderApp({
|
|
186
|
-
element,
|
|
187
|
-
selector: `[${attribute}]`,
|
|
188
|
-
component: compiled,
|
|
189
|
-
log: compiler.announce,
|
|
190
|
-
modules: {
|
|
191
|
-
application,
|
|
192
|
-
destroyable,
|
|
193
|
-
resolver,
|
|
194
|
-
router,
|
|
195
|
-
route,
|
|
196
|
-
testWaiters,
|
|
197
|
-
runloop,
|
|
198
|
-
},
|
|
199
|
-
});
|
|
170
|
+
const { renderComponent } = await compiler.tryResolve('@ember/renderer');
|
|
171
|
+
|
|
172
|
+
const owner = makeOwner(config.owner);
|
|
173
|
+
const result = renderComponent(compiled, { into: element, owner });
|
|
174
|
+
|
|
175
|
+
return () => result.destroy();
|
|
200
176
|
},
|
|
201
177
|
handlers: {
|
|
202
178
|
js: async (text) => {
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { assert, isRecord } from '../../utils.js';
|
|
5
5
|
import { buildCodeFenceMetaUtils } from '../markdown/utils.js';
|
|
6
|
-
import { renderApp } from './render-app-island.js';
|
|
7
6
|
|
|
8
7
|
let elementId = 0;
|
|
9
8
|
|
|
@@ -15,6 +14,7 @@ let elementId = 0;
|
|
|
15
14
|
* rehypePlugins: Plugin[],
|
|
16
15
|
* ShadowComponent: string | undefined,
|
|
17
16
|
* CopyComponent: string | undefined
|
|
17
|
+
* owner?: unknown | undefined
|
|
18
18
|
* }}
|
|
19
19
|
*/
|
|
20
20
|
export function filterOptions(options) {
|
|
@@ -29,6 +29,7 @@ export function filterOptions(options) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
return {
|
|
32
|
+
owner: options?.owner,
|
|
32
33
|
scope: /** @type {Record<string, unknown>}*/ (options?.scope || {}),
|
|
33
34
|
remarkPlugins: /** @type {Plugin[]}*/ (options?.remarkPlugins || []),
|
|
34
35
|
rehypePlugins: /** @type {Plugin[]}*/ (options?.rehypePlugins || []),
|
|
@@ -95,36 +96,15 @@ export async function compiler(config, api) {
|
|
|
95
96
|
|
|
96
97
|
element.setAttribute(attribute, '');
|
|
97
98
|
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
'@ember/routing/router',
|
|
104
|
-
'@ember/routing/route',
|
|
105
|
-
'@ember/test-waiters',
|
|
106
|
-
'@ember/runloop',
|
|
107
|
-
]);
|
|
108
|
-
|
|
109
|
-
// We don't want to await here, because we need to early
|
|
110
|
-
// return the element so that the app can render in to it.
|
|
111
|
-
// (Ember will only render in to an element if it's present in the DOM)
|
|
112
|
-
const destroy = await renderApp({
|
|
113
|
-
element,
|
|
114
|
-
selector: `[${attribute}]`,
|
|
115
|
-
component: compiled,
|
|
116
|
-
log: compiler.announce,
|
|
117
|
-
modules: {
|
|
118
|
-
application,
|
|
119
|
-
destroyable,
|
|
120
|
-
resolver,
|
|
121
|
-
router,
|
|
122
|
-
route,
|
|
123
|
-
testWaiters,
|
|
124
|
-
runloop,
|
|
125
|
-
},
|
|
99
|
+
const { renderComponent } = await compiler.tryResolve('@ember/renderer');
|
|
100
|
+
|
|
101
|
+
const result = renderComponent(compiled, {
|
|
102
|
+
into: element,
|
|
103
|
+
owner: userOptions.owner,
|
|
126
104
|
});
|
|
127
105
|
|
|
106
|
+
const destroy = () => result.destroy();
|
|
107
|
+
|
|
128
108
|
/**
|
|
129
109
|
* @type {(() => void)[]}
|
|
130
110
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isRecord } from '../../utils.js';
|
|
2
|
-
import {
|
|
2
|
+
import { makeOwner } from './owner.js';
|
|
3
3
|
|
|
4
4
|
let elementId = 0;
|
|
5
5
|
|
|
@@ -65,32 +65,11 @@ export async function compiler(config, api) {
|
|
|
65
65
|
|
|
66
66
|
element.setAttribute(attribute, '');
|
|
67
67
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'@ember/destroyable',
|
|
72
|
-
'ember-resolver',
|
|
73
|
-
'@ember/routing/router',
|
|
74
|
-
'@ember/routing/route',
|
|
75
|
-
'@ember/test-waiters',
|
|
76
|
-
'@ember/runloop',
|
|
77
|
-
]);
|
|
68
|
+
const { renderComponent } = await compiler.tryResolve('@ember/renderer');
|
|
69
|
+
const owner = makeOwner(config.owner);
|
|
70
|
+
const result = renderComponent(compiled, { into: element, owner });
|
|
78
71
|
|
|
79
|
-
return
|
|
80
|
-
element,
|
|
81
|
-
selector: `[${attribute}]`,
|
|
82
|
-
component: compiled,
|
|
83
|
-
log: compiler.announce,
|
|
84
|
-
modules: {
|
|
85
|
-
application,
|
|
86
|
-
destroyable,
|
|
87
|
-
resolver,
|
|
88
|
-
router,
|
|
89
|
-
route,
|
|
90
|
-
testWaiters,
|
|
91
|
-
runloop,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
72
|
+
return () => result.destroy();
|
|
94
73
|
},
|
|
95
74
|
};
|
|
96
75
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {unknown} [owner]
|
|
3
|
+
*/
|
|
4
|
+
export function makeOwner(owner) {
|
|
5
|
+
return {
|
|
6
|
+
name: 'inner owner',
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} name
|
|
9
|
+
*/
|
|
10
|
+
lookup(name) {
|
|
11
|
+
if (typeof owner !== 'object') return;
|
|
12
|
+
if (!owner) return;
|
|
13
|
+
if (!('lookup' in owner)) return;
|
|
14
|
+
if (typeof owner.lookup !== 'function') return;
|
|
15
|
+
|
|
16
|
+
return owner.lookup(name);
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} name
|
|
20
|
+
*/
|
|
21
|
+
resolveRegistration(name) {
|
|
22
|
+
if (typeof owner !== 'object') return;
|
|
23
|
+
if (!owner) return;
|
|
24
|
+
if (!('resolveRegistration' in owner)) return;
|
|
25
|
+
if (typeof owner.resolveRegistration !== 'function') return;
|
|
26
|
+
|
|
27
|
+
return owner.resolveRegistration(name);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/** @type {any} */
|
|
2
|
-
let bootWaiter;
|
|
3
|
-
/** @type {any} */
|
|
4
|
-
let createWaiter;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Wait to boot the app until the Element is in the DOM.
|
|
8
|
-
* because This old way of making a whole app requires that the element
|
|
9
|
-
* be present in the app.
|
|
10
|
-
*
|
|
11
|
-
* We really need renderComponent(...)
|
|
12
|
-
* https://github.com/emberjs/ember.js/pull/20781
|
|
13
|
-
*
|
|
14
|
-
* @param {{
|
|
15
|
-
* element: Element,
|
|
16
|
-
* modules: { [name: string]: any},
|
|
17
|
-
* selector: string,
|
|
18
|
-
* log: (type: 'error' | 'info', message: string) => void;
|
|
19
|
-
* component: unknown
|
|
20
|
-
* }} options
|
|
21
|
-
*/
|
|
22
|
-
export async function renderApp({ element, modules, selector, component, log }) {
|
|
23
|
-
const App = modules.application.default;
|
|
24
|
-
const registerDestructor = modules.destroyable.registerDestructor;
|
|
25
|
-
const destroy = modules.destroyable.destroy;
|
|
26
|
-
const Resolver = modules.resolver.default;
|
|
27
|
-
const Router = modules.router.default;
|
|
28
|
-
const Route = modules.route.default;
|
|
29
|
-
const schedule = modules.runloop.schedule;
|
|
30
|
-
|
|
31
|
-
bootWaiter ||= modules.testWaiters.buildWaiter('repl-output:waiting-for-boot');
|
|
32
|
-
createWaiter ||= modules.testWaiters.buildWaiter('repl-output:waiting-for-creation');
|
|
33
|
-
|
|
34
|
-
const bootToken = bootWaiter.beginAsync();
|
|
35
|
-
const createToken = createWaiter.beginAsync();
|
|
36
|
-
|
|
37
|
-
class EphemeralApp extends App {
|
|
38
|
-
modulePrefix = 'ephemeral-render-output';
|
|
39
|
-
rootElement = element;
|
|
40
|
-
Resolver = Resolver.withModules({
|
|
41
|
-
'ephemeral-render-output/templates/application': { default: component },
|
|
42
|
-
'ephemeral-render-output/routes/application': {
|
|
43
|
-
default: class Application extends Route {
|
|
44
|
-
/**
|
|
45
|
-
* @param {unknown[]} args
|
|
46
|
-
*/
|
|
47
|
-
constructor(...args) {
|
|
48
|
-
super(...args);
|
|
49
|
-
|
|
50
|
-
registerDestructor(() => {
|
|
51
|
-
bootWaiter.endAsync(bootToken);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
afterModel() {
|
|
55
|
-
schedule('afterRender', () => {
|
|
56
|
-
requestAnimationFrame(() => {
|
|
57
|
-
log('info', 'Ember Island Rendered');
|
|
58
|
-
bootWaiter.endAsync(bootToken);
|
|
59
|
-
createWaiter.endAsync(createToken);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
'ephemeral-render-output/router': {
|
|
66
|
-
default: class BoilerplateRouter extends Router {
|
|
67
|
-
location = 'none';
|
|
68
|
-
rootURL = '/';
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
log('info', 'Booting Ember Island');
|
|
75
|
-
|
|
76
|
-
const app = EphemeralApp.create({
|
|
77
|
-
rootElement: element,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return () => {
|
|
81
|
-
destroy(app);
|
|
82
|
-
};
|
|
83
|
-
}
|