ember-source 6.0.0-alpha.9 → 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/blueprints/component/index.js +8 -71
- package/blueprints/component-class/index.js +8 -47
- package/build-metadata.json +3 -3
- package/dist/ember-template-compiler.js +4200 -6302
- package/dist/ember-testing.js +1 -1
- package/dist/ember.debug.js +4040 -8666
- package/dist/ember.prod.js +3734 -8082
- package/dist/packages/@glimmer/debug/index.js +87 -1440
- package/dist/packages/@glimmer/destroyable/index.js +59 -113
- package/dist/packages/@glimmer/encoder/index.js +4 -11
- package/dist/packages/@glimmer/global-context/index.js +40 -144
- package/dist/packages/@glimmer/manager/index.js +191 -312
- package/dist/packages/@glimmer/node/index.js +34 -76
- package/dist/packages/@glimmer/opcode-compiler/index.js +794 -1422
- package/dist/packages/@glimmer/owner/index.js +2 -1
- package/dist/packages/@glimmer/program/index.js +105 -192
- package/dist/packages/@glimmer/reference/index.js +109 -237
- package/dist/packages/@glimmer/runtime/index.js +1939 -3715
- package/dist/packages/@glimmer/util/index.js +114 -241
- package/dist/packages/@glimmer/validator/index.js +203 -409
- package/dist/packages/@glimmer/vm/index.js +163 -176
- package/dist/packages/@glimmer/wire-format/index.js +70 -71
- package/dist/packages/ember/version.js +1 -1
- package/docs/data.json +1 -1
- package/lib/browsers.js +40 -68
- package/package.json +21 -24
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { debugToString as debugToString$1, castToBrowser } from '../util/index.js';
|
|
2
2
|
import { associateDestroyableChild, registerDestructor } from '../destroyable/index.js';
|
|
3
3
|
import { createComputeRef, createConstRef, UNDEFINED_REFERENCE, valueForRef } from '../reference/index.js';
|
|
4
|
-
import { untrack,
|
|
5
|
-
import {
|
|
6
|
-
import { InternalComponentCapabilities } from '../vm/index.js';
|
|
4
|
+
import { untrack, track, createUpdatableTag } from '../validator/index.js';
|
|
5
|
+
import { Op, InternalComponentCapabilities } from '../vm/index.js';
|
|
7
6
|
import { isDevelopingApp } from '@embroider/macros';
|
|
8
7
|
|
|
9
8
|
const CUSTOM_TAG_FOR = new WeakMap();
|
|
@@ -14,30 +13,9 @@ function setCustomTagFor(obj, customTagFn) {
|
|
|
14
13
|
CUSTOM_TAG_FOR.set(obj, customTagFn);
|
|
15
14
|
}
|
|
16
15
|
function convertToInt(prop) {
|
|
17
|
-
if (typeof prop
|
|
16
|
+
if ("symbol" == typeof prop) return null;
|
|
18
17
|
const num = Number(prop);
|
|
19
|
-
|
|
20
|
-
return num % 1 === 0 ? num : null;
|
|
21
|
-
}
|
|
22
|
-
function tagForNamedArg(namedArgs, key) {
|
|
23
|
-
return track(() => {
|
|
24
|
-
if (key in namedArgs) {
|
|
25
|
-
valueForRef(namedArgs[key]);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function tagForPositionalArg(positionalArgs, key) {
|
|
30
|
-
return track(() => {
|
|
31
|
-
if (key === '[]') {
|
|
32
|
-
// consume all of the tags in the positional array
|
|
33
|
-
positionalArgs.forEach(valueForRef);
|
|
34
|
-
}
|
|
35
|
-
const parsed = convertToInt(key);
|
|
36
|
-
if (parsed !== null && parsed < positionalArgs.length) {
|
|
37
|
-
// consume the tag of the referenced index
|
|
38
|
-
valueForRef(positionalArgs[parsed]);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
18
|
+
return isNaN(num) ? null : num % 1 == 0 ? num : null;
|
|
41
19
|
}
|
|
42
20
|
class NamedArgsProxy {
|
|
43
21
|
constructor(named) {
|
|
@@ -45,9 +23,7 @@ class NamedArgsProxy {
|
|
|
45
23
|
}
|
|
46
24
|
get(_target, prop) {
|
|
47
25
|
const ref = this.named[prop];
|
|
48
|
-
if (
|
|
49
|
-
return valueForRef(ref);
|
|
50
|
-
}
|
|
26
|
+
if (void 0 !== ref) return valueForRef(ref);
|
|
51
27
|
}
|
|
52
28
|
has(_target, prop) {
|
|
53
29
|
return prop in this.named;
|
|
@@ -56,15 +32,13 @@ class NamedArgsProxy {
|
|
|
56
32
|
return Object.keys(this.named);
|
|
57
33
|
}
|
|
58
34
|
isExtensible() {
|
|
59
|
-
return
|
|
35
|
+
return !1;
|
|
60
36
|
}
|
|
61
37
|
getOwnPropertyDescriptor(_target, prop) {
|
|
62
|
-
if (isDevelopingApp() && !(prop in this.named)) {
|
|
63
|
-
throw new Error(`args proxies do not have real property descriptors, so you should never need to call getOwnPropertyDescriptor yourself. This code exists for enumerability, such as in for-in loops and Object.keys(). Attempted to get the descriptor for \`${String(prop)}\``);
|
|
64
|
-
}
|
|
38
|
+
if (isDevelopingApp() && !(prop in this.named)) throw new Error(`args proxies do not have real property descriptors, so you should never need to call getOwnPropertyDescriptor yourself. This code exists for enumerability, such as in for-in loops and Object.keys(). Attempted to get the descriptor for \`${String(prop)}\``);
|
|
65
39
|
return {
|
|
66
|
-
enumerable:
|
|
67
|
-
configurable:
|
|
40
|
+
enumerable: !0,
|
|
41
|
+
configurable: !0
|
|
68
42
|
};
|
|
69
43
|
}
|
|
70
44
|
}
|
|
@@ -74,92 +48,86 @@ class PositionalArgsProxy {
|
|
|
74
48
|
}
|
|
75
49
|
get(target, prop) {
|
|
76
50
|
let {
|
|
77
|
-
positional
|
|
51
|
+
positional: positional
|
|
78
52
|
} = this;
|
|
79
|
-
if (
|
|
80
|
-
return positional.length;
|
|
81
|
-
}
|
|
53
|
+
if ("length" === prop) return positional.length;
|
|
82
54
|
const parsed = convertToInt(prop);
|
|
83
|
-
|
|
84
|
-
return valueForRef(positional[parsed]);
|
|
85
|
-
}
|
|
86
|
-
return target[prop];
|
|
55
|
+
return null !== parsed && parsed < positional.length ? valueForRef(positional[parsed]) : target[prop];
|
|
87
56
|
}
|
|
88
57
|
isExtensible() {
|
|
89
|
-
return
|
|
58
|
+
return !1;
|
|
90
59
|
}
|
|
91
60
|
has(_target, prop) {
|
|
92
61
|
const parsed = convertToInt(prop);
|
|
93
|
-
return
|
|
62
|
+
return null !== parsed && parsed < this.positional.length;
|
|
94
63
|
}
|
|
95
64
|
}
|
|
96
65
|
const argsProxyFor = (capturedArgs, type) => {
|
|
97
66
|
const {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const positionalHandler = new PositionalArgsProxy(positional);
|
|
105
|
-
const namedTarget = Object.create(null);
|
|
106
|
-
const positionalTarget = [];
|
|
67
|
+
named: named,
|
|
68
|
+
positional: positional
|
|
69
|
+
} = capturedArgs,
|
|
70
|
+
namedHandler = new NamedArgsProxy(named),
|
|
71
|
+
positionalHandler = new PositionalArgsProxy(positional),
|
|
72
|
+
namedTarget = Object.create(null);
|
|
107
73
|
if (isDevelopingApp()) {
|
|
108
74
|
const setHandler = function (_target, prop) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
namedHandler.set = setHandler;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
75
|
+
throw new Error(`You attempted to set ${String(prop)} on the arguments of a component, helper, or modifier. Arguments are immutable and cannot be updated directly; they always represent the values that are passed down. If you want to set default values, you should use a getter and local tracked state instead.`);
|
|
76
|
+
},
|
|
77
|
+
forInDebugHandler = () => {
|
|
78
|
+
throw new Error(`Object.keys() was called on the positional arguments array for a ${type}, which is not supported. This function is a low-level function that should not need to be called for positional argument arrays. You may be attempting to iterate over the array using for...in instead of for...of.`);
|
|
79
|
+
};
|
|
80
|
+
namedHandler.set = setHandler, positionalHandler.set = setHandler, positionalHandler.ownKeys = forInDebugHandler;
|
|
81
|
+
}
|
|
82
|
+
const namedProxy = new Proxy(namedTarget, namedHandler),
|
|
83
|
+
positionalProxy = new Proxy([], positionalHandler);
|
|
84
|
+
return setCustomTagFor(namedProxy, (_obj, key) => function (namedArgs, key) {
|
|
85
|
+
return track(() => {
|
|
86
|
+
key in namedArgs && valueForRef(namedArgs[key]);
|
|
87
|
+
});
|
|
88
|
+
}(named, key)), setCustomTagFor(positionalProxy, (_obj, key) => function (positionalArgs, key) {
|
|
89
|
+
return track(() => {
|
|
90
|
+
"[]" === key &&
|
|
91
|
+
// consume all of the tags in the positional array
|
|
92
|
+
positionalArgs.forEach(valueForRef);
|
|
93
|
+
const parsed = convertToInt(key);
|
|
94
|
+
null !== parsed && parsed < positionalArgs.length &&
|
|
95
|
+
// consume the tag of the referenced index
|
|
96
|
+
valueForRef(positionalArgs[parsed]);
|
|
97
|
+
});
|
|
98
|
+
}(positional, key)), {
|
|
123
99
|
named: namedProxy,
|
|
124
100
|
positional: positionalProxy
|
|
125
101
|
};
|
|
126
102
|
};
|
|
127
|
-
|
|
103
|
+
|
|
104
|
+
/* This file is generated by build/debug.js */
|
|
105
|
+
new Array(Op.Size).fill(null), new Array(Op.Size).fill(null);
|
|
106
|
+
const FROM_CAPABILITIES = isDevelopingApp() ? new WeakSet() : void 0;
|
|
128
107
|
function buildCapabilities(capabilities) {
|
|
129
|
-
|
|
130
|
-
FROM_CAPABILITIES.add(capabilities);
|
|
131
|
-
Object.freeze(capabilities);
|
|
132
|
-
}
|
|
133
|
-
return capabilities;
|
|
108
|
+
return isDevelopingApp() && (FROM_CAPABILITIES.add(capabilities), Object.freeze(capabilities)), capabilities;
|
|
134
109
|
}
|
|
135
110
|
const EMPTY = InternalComponentCapabilities.Empty;
|
|
111
|
+
|
|
136
112
|
/**
|
|
137
113
|
* Converts a ComponentCapabilities object into a 32-bit integer representation.
|
|
138
114
|
*/
|
|
139
115
|
function capabilityFlagsFrom(capabilities) {
|
|
140
|
-
return EMPTY | capability(capabilities,
|
|
116
|
+
return EMPTY | capability(capabilities, "dynamicLayout") | capability(capabilities, "dynamicTag") | capability(capabilities, "prepareArgs") | capability(capabilities, "createArgs") | capability(capabilities, "attributeHook") | capability(capabilities, "elementHook") | capability(capabilities, "dynamicScope") | capability(capabilities, "createCaller") | capability(capabilities, "updateHook") | capability(capabilities, "createInstance") | capability(capabilities, "wrapped") | capability(capabilities, "willDestroy") | capability(capabilities, "hasSubOwner");
|
|
141
117
|
}
|
|
142
118
|
function capability(capabilities, capability) {
|
|
143
119
|
return capabilities[capability] ? InternalComponentCapabilities[capability] : EMPTY;
|
|
144
120
|
}
|
|
145
121
|
function managerHasCapability(_manager, capabilities, capability) {
|
|
146
|
-
check(capabilities, CheckNumber);
|
|
147
122
|
return !!(capabilities & capability);
|
|
148
123
|
}
|
|
149
124
|
function hasCapability(capabilities, capability) {
|
|
150
|
-
check(capabilities, CheckNumber);
|
|
151
125
|
return !!(capabilities & capability);
|
|
152
126
|
}
|
|
153
127
|
function helperCapabilities(managerAPI, options = {}) {
|
|
154
|
-
if (isDevelopingApp() &&
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (isDevelopingApp() && (!(options.hasValue || options.hasScheduledEffect) || options.hasValue && options.hasScheduledEffect)) {
|
|
158
|
-
throw new Error('You must pass either the `hasValue` OR the `hasScheduledEffect` capability when defining a helper manager. Passing neither, or both, is not permitted.');
|
|
159
|
-
}
|
|
160
|
-
if (isDevelopingApp() && options.hasScheduledEffect) {
|
|
161
|
-
throw new Error('The `hasScheduledEffect` capability has not yet been implemented for helper managers. Please pass `hasValue` instead');
|
|
162
|
-
}
|
|
128
|
+
if (isDevelopingApp() && "3.23" !== managerAPI) throw new Error("Invalid helper manager compatibility specified");
|
|
129
|
+
if (isDevelopingApp() && (!options.hasValue && !options.hasScheduledEffect || options.hasValue && options.hasScheduledEffect)) throw new Error("You must pass either the `hasValue` OR the `hasScheduledEffect` capability when defining a helper manager. Passing neither, or both, is not permitted.");
|
|
130
|
+
if (isDevelopingApp() && options.hasScheduledEffect) throw new Error("The `hasScheduledEffect` capability has not yet been implemented for helper managers. Please pass `hasValue` instead");
|
|
163
131
|
return buildCapabilities({
|
|
164
132
|
hasValue: Boolean(options.hasValue),
|
|
165
133
|
hasDestroyable: Boolean(options.hasDestroyable),
|
|
@@ -168,7 +136,6 @@ function helperCapabilities(managerAPI, options = {}) {
|
|
|
168
136
|
}
|
|
169
137
|
|
|
170
138
|
////////////
|
|
171
|
-
|
|
172
139
|
function hasValue(manager) {
|
|
173
140
|
return manager.capabilities.hasValue;
|
|
174
141
|
}
|
|
@@ -177,7 +144,6 @@ function hasDestroyable(manager) {
|
|
|
177
144
|
}
|
|
178
145
|
|
|
179
146
|
////////////
|
|
180
|
-
|
|
181
147
|
class CustomHelperManager {
|
|
182
148
|
constructor(factory) {
|
|
183
149
|
this.factory = factory;
|
|
@@ -186,130 +152,99 @@ class CustomHelperManager {
|
|
|
186
152
|
undefinedDelegate = null;
|
|
187
153
|
getDelegateForOwner(owner) {
|
|
188
154
|
let delegate = this.helperManagerDelegates.get(owner);
|
|
189
|
-
if (
|
|
155
|
+
if (void 0 === delegate) {
|
|
190
156
|
let {
|
|
191
|
-
factory
|
|
157
|
+
factory: factory
|
|
192
158
|
} = this;
|
|
193
|
-
delegate = factory(owner)
|
|
194
|
-
if (isDevelopingApp() && !FROM_CAPABILITIES.has(delegate.capabilities)) {
|
|
159
|
+
if (delegate = factory(owner), isDevelopingApp() && !FROM_CAPABILITIES.has(delegate.capabilities))
|
|
195
160
|
// TODO: This error message should make sense in both Ember and Glimmer https://github.com/glimmerjs/glimmer-vm/issues/1200
|
|
196
161
|
throw new Error(`Custom helper managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.23')\` (imported via \`import { capabilities } from '@ember/helper';\`). Received: \`${JSON.stringify(delegate.capabilities)}\` for: \`${delegate}\``);
|
|
197
|
-
}
|
|
198
162
|
this.helperManagerDelegates.set(owner, delegate);
|
|
199
163
|
}
|
|
200
164
|
return delegate;
|
|
201
165
|
}
|
|
202
166
|
getDelegateFor(owner) {
|
|
203
|
-
if (
|
|
167
|
+
if (void 0 === owner) {
|
|
204
168
|
let {
|
|
205
|
-
undefinedDelegate
|
|
169
|
+
undefinedDelegate: undefinedDelegate
|
|
206
170
|
} = this;
|
|
207
|
-
if (
|
|
171
|
+
if (null === undefinedDelegate) {
|
|
208
172
|
let {
|
|
209
|
-
factory
|
|
173
|
+
factory: factory
|
|
210
174
|
} = this;
|
|
211
|
-
this.undefinedDelegate = undefinedDelegate = factory(
|
|
175
|
+
this.undefinedDelegate = undefinedDelegate = factory(void 0);
|
|
212
176
|
}
|
|
213
177
|
return undefinedDelegate;
|
|
214
|
-
} else {
|
|
215
|
-
return this.getDelegateForOwner(owner);
|
|
216
178
|
}
|
|
179
|
+
return this.getDelegateForOwner(owner);
|
|
217
180
|
}
|
|
218
181
|
getHelper(definition) {
|
|
219
182
|
return (capturedArgs, owner) => {
|
|
220
183
|
let manager = this.getDelegateFor(owner);
|
|
221
|
-
const args = argsProxyFor(capturedArgs,
|
|
222
|
-
|
|
184
|
+
const args = argsProxyFor(capturedArgs, "helper"),
|
|
185
|
+
bucket = manager.createHelper(definition, args);
|
|
223
186
|
if (hasValue(manager)) {
|
|
224
187
|
let cache = createComputeRef(() => manager.getValue(bucket), null, isDevelopingApp() && manager.getDebugName && manager.getDebugName(definition));
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
let ref = createConstRef(undefined, isDevelopingApp() && (manager.getDebugName?.(definition) ?? 'unknown helper'));
|
|
231
|
-
associateDestroyableChild(ref, manager.getDestroyable(bucket));
|
|
232
|
-
return ref;
|
|
233
|
-
} else {
|
|
234
|
-
return UNDEFINED_REFERENCE;
|
|
188
|
+
return hasDestroyable(manager) && associateDestroyableChild(cache, manager.getDestroyable(bucket)), cache;
|
|
189
|
+
}
|
|
190
|
+
if (hasDestroyable(manager)) {
|
|
191
|
+
let ref = createConstRef(void 0, isDevelopingApp() && (manager.getDebugName?.(definition) ?? "unknown helper"));
|
|
192
|
+
return associateDestroyableChild(ref, manager.getDestroyable(bucket)), ref;
|
|
235
193
|
}
|
|
194
|
+
return UNDEFINED_REFERENCE;
|
|
236
195
|
};
|
|
237
196
|
}
|
|
238
197
|
}
|
|
239
198
|
class FunctionHelperManager {
|
|
240
199
|
capabilities = buildCapabilities({
|
|
241
|
-
hasValue:
|
|
242
|
-
hasDestroyable:
|
|
243
|
-
hasScheduledEffect:
|
|
200
|
+
hasValue: !0,
|
|
201
|
+
hasDestroyable: !1,
|
|
202
|
+
hasScheduledEffect: !1
|
|
244
203
|
});
|
|
245
204
|
createHelper(fn, args) {
|
|
246
205
|
return {
|
|
247
|
-
fn,
|
|
248
|
-
args
|
|
206
|
+
fn: fn,
|
|
207
|
+
args: args
|
|
249
208
|
};
|
|
250
209
|
}
|
|
251
210
|
getValue({
|
|
252
|
-
fn,
|
|
253
|
-
args
|
|
211
|
+
fn: fn,
|
|
212
|
+
args: args
|
|
254
213
|
}) {
|
|
255
|
-
|
|
256
|
-
let argsForFn = [...args.positional, args.named];
|
|
257
|
-
return fn(...argsForFn);
|
|
258
|
-
}
|
|
259
|
-
return fn(...args.positional);
|
|
214
|
+
return Object.keys(args.named).length > 0 ? fn(...args.positional, args.named) : fn(...args.positional);
|
|
260
215
|
}
|
|
261
216
|
getDebugName(fn) {
|
|
262
|
-
|
|
263
|
-
return `(helper function ${fn.name})`;
|
|
264
|
-
}
|
|
265
|
-
return '(anonymous helper function)';
|
|
217
|
+
return fn.name ? `(helper function ${fn.name})` : "(anonymous helper function)";
|
|
266
218
|
}
|
|
267
219
|
}
|
|
268
|
-
const COMPONENT_MANAGERS = new WeakMap()
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
///////////
|
|
273
|
-
|
|
274
|
-
const getPrototypeOf$1 = Object.getPrototypeOf;
|
|
220
|
+
const COMPONENT_MANAGERS = new WeakMap(),
|
|
221
|
+
MODIFIER_MANAGERS = new WeakMap(),
|
|
222
|
+
HELPER_MANAGERS = new WeakMap(),
|
|
223
|
+
getPrototypeOf$1 = Object.getPrototypeOf;
|
|
275
224
|
function setManager(map, manager, obj) {
|
|
276
|
-
if (isDevelopingApp() && (typeof obj
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (isDevelopingApp() && map.has(obj)) {
|
|
280
|
-
throw new Error(`Attempted to set the same type of manager multiple times on a value. You can only associate one manager of each type with a given value. Value was ${debugToString$1(obj)}`);
|
|
281
|
-
}
|
|
282
|
-
map.set(obj, manager);
|
|
283
|
-
return obj;
|
|
225
|
+
if (isDevelopingApp() && ("object" != typeof obj || null === obj) && "function" != typeof obj) throw new Error(`Attempted to set a manager on a non-object value. Managers can only be associated with objects or functions. Value was ${debugToString$1(obj)}`);
|
|
226
|
+
if (isDevelopingApp() && map.has(obj)) throw new Error(`Attempted to set the same type of manager multiple times on a value. You can only associate one manager of each type with a given value. Value was ${debugToString$1(obj)}`);
|
|
227
|
+
return map.set(obj, manager), obj;
|
|
284
228
|
}
|
|
285
229
|
function getManager(map, obj) {
|
|
286
230
|
let pointer = obj;
|
|
287
|
-
|
|
231
|
+
for (; null != pointer;) {
|
|
288
232
|
const manager = map.get(pointer);
|
|
289
|
-
if (
|
|
290
|
-
return manager;
|
|
291
|
-
}
|
|
233
|
+
if (void 0 !== manager) return manager;
|
|
292
234
|
pointer = getPrototypeOf$1(pointer);
|
|
293
235
|
}
|
|
294
|
-
return undefined;
|
|
295
236
|
}
|
|
296
237
|
|
|
297
238
|
///////////
|
|
298
|
-
|
|
299
239
|
function setInternalModifierManager(manager, definition) {
|
|
300
240
|
return setManager(MODIFIER_MANAGERS, manager, definition);
|
|
301
241
|
}
|
|
302
242
|
function getInternalModifierManager(definition, isOptional) {
|
|
303
|
-
if (isDevelopingApp() && typeof definition
|
|
304
|
-
throw new Error(`Attempted to use a value as a modifier, but it was not an object or function. Modifier definitions must be objects or functions with an associated modifier manager. The value was: ${definition}`);
|
|
305
|
-
}
|
|
243
|
+
if (isDevelopingApp() && "function" != typeof definition && ("object" != typeof definition || null === definition)) throw new Error(`Attempted to use a value as a modifier, but it was not an object or function. Modifier definitions must be objects or functions with an associated modifier manager. The value was: ${definition}`);
|
|
306
244
|
const manager = getManager(MODIFIER_MANAGERS, definition);
|
|
307
|
-
if (
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
} else if (isDevelopingApp()) {
|
|
311
|
-
throw new Error(`Attempted to load a modifier, but there wasn't a modifier manager associated with the definition. The definition was: ${debugToString$1(definition)}`);
|
|
312
|
-
}
|
|
245
|
+
if (void 0 === manager) {
|
|
246
|
+
if (!0 === isOptional) return null;
|
|
247
|
+
if (isDevelopingApp()) throw new Error(`Attempted to load a modifier, but there wasn't a modifier manager associated with the definition. The definition was: ${debugToString$1(definition)}`);
|
|
313
248
|
}
|
|
314
249
|
return manager;
|
|
315
250
|
}
|
|
@@ -318,81 +253,62 @@ function setInternalHelperManager(manager, definition) {
|
|
|
318
253
|
}
|
|
319
254
|
const DEFAULT_MANAGER = new CustomHelperManager(() => new FunctionHelperManager());
|
|
320
255
|
function getInternalHelperManager(definition, isOptional) {
|
|
321
|
-
if (isDevelopingApp() && typeof definition
|
|
322
|
-
throw new Error(`Attempted to use a value as a helper, but it was not an object or function. Helper definitions must be objects or functions with an associated helper manager. The value was: ${definition}`);
|
|
323
|
-
}
|
|
256
|
+
if (isDevelopingApp() && "function" != typeof definition && ("object" != typeof definition || null === definition)) throw new Error(`Attempted to use a value as a helper, but it was not an object or function. Helper definitions must be objects or functions with an associated helper manager. The value was: ${definition}`);
|
|
324
257
|
let manager = getManager(HELPER_MANAGERS, definition);
|
|
325
|
-
|
|
326
258
|
// Functions are special-cased because functions are defined
|
|
327
259
|
// as the "default" helper, per: https://github.com/emberjs/rfcs/pull/756
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
if (manager) {
|
|
332
|
-
return manager;
|
|
333
|
-
} else if (isOptional === true) {
|
|
334
|
-
return null;
|
|
335
|
-
} else if (isDevelopingApp()) {
|
|
336
|
-
throw new Error(`Attempted to load a helper, but there wasn't a helper manager associated with the definition. The definition was: ${debugToString$1(definition)}`);
|
|
337
|
-
}
|
|
260
|
+
if (void 0 === manager && "function" == typeof definition && (manager = DEFAULT_MANAGER), manager) return manager;
|
|
261
|
+
if (!0 === isOptional) return null;
|
|
262
|
+
if (isDevelopingApp()) throw new Error(`Attempted to load a helper, but there wasn't a helper manager associated with the definition. The definition was: ${debugToString$1(definition)}`);
|
|
338
263
|
return null;
|
|
339
264
|
}
|
|
340
265
|
function setInternalComponentManager(factory, obj) {
|
|
341
266
|
return setManager(COMPONENT_MANAGERS, factory, obj);
|
|
342
267
|
}
|
|
343
268
|
function getInternalComponentManager(definition, isOptional) {
|
|
344
|
-
if (isDevelopingApp() && typeof definition
|
|
345
|
-
throw new Error(`Attempted to use a value as a component, but it was not an object or function. Component definitions must be objects or functions with an associated component manager. The value was: ${definition}`);
|
|
346
|
-
}
|
|
269
|
+
if (isDevelopingApp() && "function" != typeof definition && ("object" != typeof definition || null === definition)) throw new Error(`Attempted to use a value as a component, but it was not an object or function. Component definitions must be objects or functions with an associated component manager. The value was: ${definition}`);
|
|
347
270
|
const manager = getManager(COMPONENT_MANAGERS, definition);
|
|
348
|
-
if (
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
} else if (isDevelopingApp()) {
|
|
352
|
-
throw new Error(`Attempted to load a component, but there wasn't a component manager associated with the definition. The definition was: ${debugToString$1(definition)}`);
|
|
353
|
-
}
|
|
271
|
+
if (void 0 === manager) {
|
|
272
|
+
if (!0 === isOptional) return null;
|
|
273
|
+
if (isDevelopingApp()) throw new Error(`Attempted to load a component, but there wasn't a component manager associated with the definition. The definition was: ${debugToString$1(definition)}`);
|
|
354
274
|
}
|
|
355
275
|
return manager;
|
|
356
276
|
}
|
|
357
277
|
|
|
358
278
|
///////////
|
|
359
|
-
|
|
360
279
|
function hasInternalComponentManager(definition) {
|
|
361
|
-
return getManager(COMPONENT_MANAGERS, definition)
|
|
280
|
+
return void 0 !== getManager(COMPONENT_MANAGERS, definition);
|
|
362
281
|
}
|
|
363
282
|
function hasInternalHelperManager(definition) {
|
|
364
|
-
return
|
|
283
|
+
return function (definition) {
|
|
284
|
+
return "function" == typeof definition;
|
|
285
|
+
}(definition) || void 0 !== getManager(HELPER_MANAGERS, definition);
|
|
365
286
|
}
|
|
366
287
|
function hasInternalModifierManager(definition) {
|
|
367
|
-
return getManager(MODIFIER_MANAGERS, definition)
|
|
368
|
-
}
|
|
369
|
-
function hasDefaultHelperManager(definition) {
|
|
370
|
-
return typeof definition === 'function';
|
|
288
|
+
return void 0 !== getManager(MODIFIER_MANAGERS, definition);
|
|
371
289
|
}
|
|
372
290
|
const CAPABILITIES = {
|
|
373
|
-
dynamicLayout:
|
|
374
|
-
dynamicTag:
|
|
375
|
-
prepareArgs:
|
|
376
|
-
createArgs:
|
|
377
|
-
attributeHook:
|
|
378
|
-
elementHook:
|
|
379
|
-
createCaller:
|
|
380
|
-
dynamicScope:
|
|
381
|
-
updateHook:
|
|
382
|
-
createInstance:
|
|
383
|
-
wrapped:
|
|
384
|
-
willDestroy:
|
|
385
|
-
hasSubOwner:
|
|
291
|
+
dynamicLayout: !1,
|
|
292
|
+
dynamicTag: !1,
|
|
293
|
+
prepareArgs: !1,
|
|
294
|
+
createArgs: !0,
|
|
295
|
+
attributeHook: !1,
|
|
296
|
+
elementHook: !1,
|
|
297
|
+
createCaller: !1,
|
|
298
|
+
dynamicScope: !0,
|
|
299
|
+
updateHook: !0,
|
|
300
|
+
createInstance: !0,
|
|
301
|
+
wrapped: !1,
|
|
302
|
+
willDestroy: !1,
|
|
303
|
+
hasSubOwner: !1
|
|
386
304
|
};
|
|
387
305
|
function componentCapabilities(managerAPI, options = {}) {
|
|
388
|
-
if (isDevelopingApp() &&
|
|
389
|
-
throw new Error('Invalid component manager compatibility specified');
|
|
390
|
-
}
|
|
306
|
+
if (isDevelopingApp() && "3.13" !== managerAPI) throw new Error("Invalid component manager compatibility specified");
|
|
391
307
|
let updateHook = Boolean(options.updateHook);
|
|
392
308
|
return buildCapabilities({
|
|
393
309
|
asyncLifeCycleCallbacks: Boolean(options.asyncLifecycleCallbacks),
|
|
394
310
|
destructor: Boolean(options.destructor),
|
|
395
|
-
updateHook
|
|
311
|
+
updateHook: updateHook
|
|
396
312
|
});
|
|
397
313
|
}
|
|
398
314
|
function hasAsyncLifeCycleCallbacks(delegate) {
|
|
@@ -401,12 +317,6 @@ function hasAsyncLifeCycleCallbacks(delegate) {
|
|
|
401
317
|
function hasUpdateHook(delegate) {
|
|
402
318
|
return delegate.capabilities.updateHook;
|
|
403
319
|
}
|
|
404
|
-
function hasAsyncUpdateHook(delegate) {
|
|
405
|
-
return hasAsyncLifeCycleCallbacks(delegate) && hasUpdateHook(delegate);
|
|
406
|
-
}
|
|
407
|
-
function hasDestructors(delegate) {
|
|
408
|
-
return delegate.capabilities.destructor;
|
|
409
|
-
}
|
|
410
320
|
|
|
411
321
|
/**
|
|
412
322
|
The CustomComponentManager allows addons to provide custom component
|
|
@@ -440,77 +350,74 @@ class CustomComponentManager {
|
|
|
440
350
|
}
|
|
441
351
|
getDelegateFor(owner) {
|
|
442
352
|
let {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (
|
|
353
|
+
componentManagerDelegates: componentManagerDelegates
|
|
354
|
+
} = this,
|
|
355
|
+
delegate = componentManagerDelegates.get(owner);
|
|
356
|
+
if (void 0 === delegate) {
|
|
447
357
|
let {
|
|
448
|
-
factory
|
|
358
|
+
factory: factory
|
|
449
359
|
} = this;
|
|
450
|
-
delegate = factory(owner)
|
|
451
|
-
if (isDevelopingApp() && !FROM_CAPABILITIES.has(delegate.capabilities)) {
|
|
360
|
+
if (delegate = factory(owner), isDevelopingApp() && !FROM_CAPABILITIES.has(delegate.capabilities))
|
|
452
361
|
// TODO: This error message should make sense in both Ember and Glimmer https://github.com/glimmerjs/glimmer-vm/issues/1200
|
|
453
362
|
throw new Error(`Custom component managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.13')\` (imported via \`import { capabilities } from '@ember/component';\`). Received: \`${JSON.stringify(delegate.capabilities)}\` for: \`${delegate}\``);
|
|
454
|
-
}
|
|
455
363
|
componentManagerDelegates.set(owner, delegate);
|
|
456
364
|
}
|
|
457
365
|
return delegate;
|
|
458
366
|
}
|
|
459
367
|
create(owner, definition, vmArgs) {
|
|
460
|
-
let delegate = this.getDelegateFor(owner)
|
|
461
|
-
|
|
462
|
-
|
|
368
|
+
let delegate = this.getDelegateFor(owner),
|
|
369
|
+
args = argsProxyFor(vmArgs.capture(), "component"),
|
|
370
|
+
component = delegate.createComponent(definition, args);
|
|
463
371
|
return new CustomComponentState(component, delegate, args);
|
|
464
372
|
}
|
|
465
373
|
getDebugName(definition) {
|
|
466
|
-
return typeof definition
|
|
374
|
+
return "function" == typeof definition ? definition.name : definition.toString();
|
|
467
375
|
}
|
|
468
376
|
update(bucket) {
|
|
469
377
|
let {
|
|
470
|
-
delegate
|
|
378
|
+
delegate: delegate
|
|
471
379
|
} = bucket;
|
|
472
380
|
if (hasUpdateHook(delegate)) {
|
|
473
381
|
let {
|
|
474
|
-
component,
|
|
475
|
-
args
|
|
382
|
+
component: component,
|
|
383
|
+
args: args
|
|
476
384
|
} = bucket;
|
|
477
385
|
delegate.updateComponent(component, args);
|
|
478
386
|
}
|
|
479
387
|
}
|
|
480
388
|
didCreate({
|
|
481
|
-
component,
|
|
482
|
-
delegate
|
|
389
|
+
component: component,
|
|
390
|
+
delegate: delegate
|
|
483
391
|
}) {
|
|
484
|
-
|
|
485
|
-
delegate.didCreateComponent(component);
|
|
486
|
-
}
|
|
392
|
+
hasAsyncLifeCycleCallbacks(delegate) && delegate.didCreateComponent(component);
|
|
487
393
|
}
|
|
488
394
|
didUpdate({
|
|
489
|
-
component,
|
|
490
|
-
delegate
|
|
395
|
+
component: component,
|
|
396
|
+
delegate: delegate
|
|
491
397
|
}) {
|
|
492
|
-
|
|
493
|
-
delegate
|
|
494
|
-
}
|
|
398
|
+
(function (delegate) {
|
|
399
|
+
return hasAsyncLifeCycleCallbacks(delegate) && hasUpdateHook(delegate);
|
|
400
|
+
})(delegate) && delegate.didUpdateComponent(component);
|
|
495
401
|
}
|
|
496
402
|
didRenderLayout() {}
|
|
497
403
|
didUpdateLayout() {}
|
|
498
404
|
getSelf({
|
|
499
|
-
component,
|
|
500
|
-
delegate
|
|
405
|
+
component: component,
|
|
406
|
+
delegate: delegate
|
|
501
407
|
}) {
|
|
502
|
-
return createConstRef(delegate.getContext(component),
|
|
408
|
+
return createConstRef(delegate.getContext(component), "this");
|
|
503
409
|
}
|
|
504
410
|
getDestroyable(bucket) {
|
|
505
411
|
const {
|
|
506
|
-
delegate
|
|
412
|
+
delegate: delegate
|
|
507
413
|
} = bucket;
|
|
508
|
-
if (
|
|
414
|
+
if (function (delegate) {
|
|
415
|
+
return delegate.capabilities.destructor;
|
|
416
|
+
}(delegate)) {
|
|
509
417
|
const {
|
|
510
|
-
component
|
|
418
|
+
component: component
|
|
511
419
|
} = bucket;
|
|
512
|
-
registerDestructor(bucket, () => delegate.destroyComponent(component));
|
|
513
|
-
return bucket;
|
|
420
|
+
return registerDestructor(bucket, () => delegate.destroyComponent(component)), bucket;
|
|
514
421
|
}
|
|
515
422
|
return null;
|
|
516
423
|
}
|
|
@@ -524,19 +431,16 @@ class CustomComponentManager {
|
|
|
524
431
|
*/
|
|
525
432
|
class CustomComponentState {
|
|
526
433
|
constructor(component, delegate, args) {
|
|
527
|
-
this.component = component;
|
|
528
|
-
this.delegate = delegate;
|
|
529
|
-
this.args = args;
|
|
434
|
+
this.component = component, this.delegate = delegate, this.args = args;
|
|
530
435
|
}
|
|
531
436
|
}
|
|
532
437
|
function modifierCapabilities(managerAPI, optionalFeatures = {}) {
|
|
533
|
-
if (isDevelopingApp() &&
|
|
534
|
-
throw new Error('Invalid modifier manager compatibility specified');
|
|
535
|
-
}
|
|
438
|
+
if (isDevelopingApp() && "3.22" !== managerAPI) throw new Error("Invalid modifier manager compatibility specified");
|
|
536
439
|
return buildCapabilities({
|
|
537
440
|
disableAutoTracking: Boolean(optionalFeatures.disableAutoTracking)
|
|
538
441
|
});
|
|
539
442
|
}
|
|
443
|
+
|
|
540
444
|
/**
|
|
541
445
|
The CustomModifierManager allows addons to provide custom modifier
|
|
542
446
|
implementations that integrate seamlessly into Ember. This is accomplished
|
|
@@ -568,83 +472,66 @@ class CustomModifierManager {
|
|
|
568
472
|
}
|
|
569
473
|
getDelegateFor(owner) {
|
|
570
474
|
let {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if (
|
|
475
|
+
componentManagerDelegates: componentManagerDelegates
|
|
476
|
+
} = this,
|
|
477
|
+
delegate = componentManagerDelegates.get(owner);
|
|
478
|
+
if (void 0 === delegate) {
|
|
575
479
|
let {
|
|
576
|
-
factory
|
|
480
|
+
factory: factory
|
|
577
481
|
} = this;
|
|
578
|
-
delegate = factory(owner)
|
|
579
|
-
if (isDevelopingApp() && !FROM_CAPABILITIES.has(delegate.capabilities)) {
|
|
482
|
+
if (delegate = factory(owner), isDevelopingApp() && !FROM_CAPABILITIES.has(delegate.capabilities))
|
|
580
483
|
// TODO: This error message should make sense in both Ember and Glimmer https://github.com/glimmerjs/glimmer-vm/issues/1200
|
|
581
484
|
throw new Error(`Custom modifier managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.22')\` (imported via \`import { capabilities } from '@ember/modifier';\`). Received: \`${JSON.stringify(delegate.capabilities)}\` for: \`${delegate}\``);
|
|
582
|
-
}
|
|
583
485
|
componentManagerDelegates.set(owner, delegate);
|
|
584
486
|
}
|
|
585
487
|
return delegate;
|
|
586
488
|
}
|
|
587
489
|
create(owner, element, definition, capturedArgs) {
|
|
588
|
-
let
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
args,
|
|
490
|
+
let state,
|
|
491
|
+
delegate = this.getDelegateFor(owner),
|
|
492
|
+
args = argsProxyFor(capturedArgs, "modifier"),
|
|
493
|
+
instance = delegate.createModifier(definition, args);
|
|
494
|
+
return state = {
|
|
495
|
+
tag: createUpdatableTag(),
|
|
496
|
+
element: element,
|
|
497
|
+
delegate: delegate,
|
|
498
|
+
args: args,
|
|
598
499
|
modifier: instance
|
|
599
|
-
};
|
|
600
|
-
registerDestructor(state, () => delegate.destroyModifier(instance, args));
|
|
601
|
-
return state;
|
|
500
|
+
}, registerDestructor(state, () => delegate.destroyModifier(instance, args)), state;
|
|
602
501
|
}
|
|
603
502
|
getDebugName(definition) {
|
|
604
|
-
|
|
605
|
-
return definition.name || definition.toString();
|
|
606
|
-
} else {
|
|
607
|
-
return '<unknown>';
|
|
608
|
-
}
|
|
503
|
+
return "function" == typeof definition ? definition.name || definition.toString() : "<unknown>";
|
|
609
504
|
}
|
|
610
505
|
getDebugInstance({
|
|
611
|
-
modifier
|
|
506
|
+
modifier: modifier
|
|
612
507
|
}) {
|
|
613
508
|
return modifier;
|
|
614
509
|
}
|
|
615
510
|
getTag({
|
|
616
|
-
tag
|
|
511
|
+
tag: tag
|
|
617
512
|
}) {
|
|
618
513
|
return tag;
|
|
619
514
|
}
|
|
620
515
|
install({
|
|
621
|
-
element,
|
|
622
|
-
args,
|
|
623
|
-
modifier,
|
|
624
|
-
delegate
|
|
516
|
+
element: element,
|
|
517
|
+
args: args,
|
|
518
|
+
modifier: modifier,
|
|
519
|
+
delegate: delegate
|
|
625
520
|
}) {
|
|
626
521
|
let {
|
|
627
|
-
capabilities
|
|
522
|
+
capabilities: capabilities
|
|
628
523
|
} = delegate;
|
|
629
|
-
|
|
630
|
-
untrack(() => delegate.installModifier(modifier, castToBrowser(element, 'ELEMENT'), args));
|
|
631
|
-
} else {
|
|
632
|
-
delegate.installModifier(modifier, castToBrowser(element, 'ELEMENT'), args);
|
|
633
|
-
}
|
|
524
|
+
!0 === capabilities.disableAutoTracking ? untrack(() => delegate.installModifier(modifier, castToBrowser(element, "ELEMENT"), args)) : delegate.installModifier(modifier, castToBrowser(element, "ELEMENT"), args);
|
|
634
525
|
}
|
|
635
526
|
update({
|
|
636
|
-
args,
|
|
637
|
-
modifier,
|
|
638
|
-
delegate
|
|
527
|
+
args: args,
|
|
528
|
+
modifier: modifier,
|
|
529
|
+
delegate: delegate
|
|
639
530
|
}) {
|
|
640
531
|
let {
|
|
641
|
-
capabilities
|
|
532
|
+
capabilities: capabilities
|
|
642
533
|
} = delegate;
|
|
643
|
-
|
|
644
|
-
untrack(() => delegate.updateModifier(modifier, args));
|
|
645
|
-
} else {
|
|
646
|
-
delegate.updateModifier(modifier, args);
|
|
647
|
-
}
|
|
534
|
+
!0 === capabilities.disableAutoTracking ? untrack(() => delegate.updateModifier(modifier, args)) : delegate.updateModifier(modifier, args);
|
|
648
535
|
}
|
|
649
536
|
getDestroyable(state) {
|
|
650
537
|
return state;
|
|
@@ -659,28 +546,20 @@ function setModifierManager(factory, obj) {
|
|
|
659
546
|
function setHelperManager(factory, obj) {
|
|
660
547
|
return setInternalHelperManager(new CustomHelperManager(factory), obj);
|
|
661
548
|
}
|
|
662
|
-
const TEMPLATES = new WeakMap()
|
|
663
|
-
|
|
549
|
+
const TEMPLATES = new WeakMap(),
|
|
550
|
+
getPrototypeOf = Object.getPrototypeOf;
|
|
664
551
|
function setComponentTemplate(factory, obj) {
|
|
665
|
-
if (isDevelopingApp() &&
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
if (isDevelopingApp() && TEMPLATES.has(obj)) {
|
|
669
|
-
throw new Error(`Cannot call \`setComponentTemplate\` multiple times on the same class (\`${debugToString$1(obj)}\`)`);
|
|
670
|
-
}
|
|
671
|
-
TEMPLATES.set(obj, factory);
|
|
672
|
-
return obj;
|
|
552
|
+
if (isDevelopingApp() && (null === obj || "object" != typeof obj && "function" != typeof obj)) throw new Error(`Cannot call \`setComponentTemplate\` on \`${debugToString$1(obj)}\``);
|
|
553
|
+
if (isDevelopingApp() && TEMPLATES.has(obj)) throw new Error(`Cannot call \`setComponentTemplate\` multiple times on the same class (\`${debugToString$1(obj)}\`)`);
|
|
554
|
+
return TEMPLATES.set(obj, factory), obj;
|
|
673
555
|
}
|
|
674
556
|
function getComponentTemplate(obj) {
|
|
675
557
|
let pointer = obj;
|
|
676
|
-
|
|
558
|
+
for (; null !== pointer;) {
|
|
677
559
|
let template = TEMPLATES.get(pointer);
|
|
678
|
-
if (
|
|
679
|
-
return template;
|
|
680
|
-
}
|
|
560
|
+
if (void 0 !== template) return template;
|
|
681
561
|
pointer = getPrototypeOf(pointer);
|
|
682
562
|
}
|
|
683
|
-
return undefined;
|
|
684
563
|
}
|
|
685
564
|
|
|
686
565
|
export { CustomComponentManager, CustomHelperManager, CustomModifierManager, capabilityFlagsFrom, componentCapabilities, getComponentTemplate, getCustomTagFor, getInternalComponentManager, getInternalHelperManager, getInternalModifierManager, hasCapability, hasDestroyable, hasInternalComponentManager, hasInternalHelperManager, hasInternalModifierManager, hasValue, helperCapabilities, managerHasCapability, modifierCapabilities, setComponentManager, setComponentTemplate, setCustomTagFor, setHelperManager, setInternalComponentManager, setInternalHelperManager, setInternalModifierManager, setModifierManager };
|