@next-core/brick-kit 2.181.1 → 2.182.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/dist/index.bundle.js +53 -38
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +53 -38
- package/dist/index.esm.js.map +1 -1
- package/dist/types/core/StoryboardContext.d.ts +1 -0
- package/dist/types/core/StoryboardContext.d.ts.map +1 -1
- package/dist/types/getRealValue.d.ts.map +1 -1
- package/dist/types/internal/evaluate.d.ts +0 -1
- package/dist/types/internal/evaluate.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.esm.js
CHANGED
|
@@ -1934,7 +1934,7 @@ class StoryboardContextWrapper {
|
|
|
1934
1934
|
return;
|
|
1935
1935
|
}
|
|
1936
1936
|
updateValue(name, value, method, callback) {
|
|
1937
|
-
var _item$
|
|
1937
|
+
var _item$eventTarget;
|
|
1938
1938
|
if (!this.data.has(name)) {
|
|
1939
1939
|
if (this.tplContextId) {
|
|
1940
1940
|
throw new Error("State not found: ".concat(name));
|
|
@@ -1955,8 +1955,8 @@ class StoryboardContextWrapper {
|
|
|
1955
1955
|
return;
|
|
1956
1956
|
}
|
|
1957
1957
|
if (method === "refresh" || method === "load") {
|
|
1958
|
-
if (!item.
|
|
1959
|
-
throw new Error("You can not ".concat(method, " the storyboard context \"").concat(name, "\" which
|
|
1958
|
+
if (!item.useResolve) {
|
|
1959
|
+
throw new Error("You can not ".concat(method, " the storyboard context \"").concat(name, "\" which is not using resolve."));
|
|
1960
1960
|
}
|
|
1961
1961
|
var promise;
|
|
1962
1962
|
if (method === "load") {
|
|
@@ -1980,12 +1980,7 @@ class StoryboardContextWrapper {
|
|
|
1980
1980
|
}, value));
|
|
1981
1981
|
// Do not use the chained promise, since the callbacks need the original promise.
|
|
1982
1982
|
promise.then(val => {
|
|
1983
|
-
|
|
1984
|
-
item.loaded = true;
|
|
1985
|
-
item.value = val;
|
|
1986
|
-
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1987
|
-
detail: item.value
|
|
1988
|
-
}));
|
|
1983
|
+
this.finishLoad(item, val);
|
|
1989
1984
|
}, err => {
|
|
1990
1985
|
// Let users to override error handling.
|
|
1991
1986
|
if (!shouldDismiss(err) && !(callback !== null && callback !== void 0 && callback.error)) {
|
|
@@ -2021,10 +2016,24 @@ class StoryboardContextWrapper {
|
|
|
2021
2016
|
}
|
|
2022
2017
|
}
|
|
2023
2018
|
if (this.batchUpdate) return;
|
|
2024
|
-
(_item$
|
|
2019
|
+
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
2025
2020
|
detail: item.value
|
|
2026
2021
|
}));
|
|
2027
2022
|
}
|
|
2023
|
+
finishLoad(item, value) {
|
|
2024
|
+
var _item$eventTarget2;
|
|
2025
|
+
if (!item.useResolve) {
|
|
2026
|
+
// This happens when a tracked conditional resolve switches from
|
|
2027
|
+
// resolve to fallback after an dep update triggered refresh but
|
|
2028
|
+
// before it's been resolved.
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
item.loaded = true;
|
|
2032
|
+
item.value = value;
|
|
2033
|
+
(_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.eventName, {
|
|
2034
|
+
detail: value
|
|
2035
|
+
}));
|
|
2036
|
+
}
|
|
2028
2037
|
waitForUsedContext(data) {
|
|
2029
2038
|
var _this = this;
|
|
2030
2039
|
return _asyncToGenerator$3(function* () {
|
|
@@ -2067,11 +2076,7 @@ class StoryboardContextWrapper {
|
|
|
2067
2076
|
// An async data always has `loading`
|
|
2068
2077
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2069
2078
|
item.loading.then(value => {
|
|
2070
|
-
item
|
|
2071
|
-
item.value = value;
|
|
2072
|
-
item.eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
2073
|
-
detail: value
|
|
2074
|
-
}));
|
|
2079
|
+
this.finishLoad(item, value);
|
|
2075
2080
|
});
|
|
2076
2081
|
}
|
|
2077
2082
|
});
|
|
@@ -2160,14 +2165,24 @@ function _resolveNormalStoryboardContext() {
|
|
|
2160
2165
|
return false;
|
|
2161
2166
|
}
|
|
2162
2167
|
var isTemplateState = !!storyboardContextWrapper.tplContextId;
|
|
2168
|
+
var isFormState = !!storyboardContextWrapper.formContextId;
|
|
2163
2169
|
var value = getDefinedTemplateState(isTemplateState, contextConf, brick);
|
|
2164
2170
|
var load = null;
|
|
2165
2171
|
var loading;
|
|
2166
|
-
var
|
|
2172
|
+
var useResolve;
|
|
2173
|
+
var trackConditionalResolve;
|
|
2174
|
+
var resolvePolicy;
|
|
2167
2175
|
if (value === undefined) {
|
|
2168
2176
|
if (contextConf.resolve) {
|
|
2177
|
+
var hasFallbackValue = hasOwnProperty(contextConf, "value");
|
|
2178
|
+
// Track conditional resolve only if all matches:
|
|
2179
|
+
// - Track enabled
|
|
2180
|
+
// - Has fallback value
|
|
2181
|
+
// - Referencing other data in `resolve.if`
|
|
2182
|
+
trackConditionalResolve = contextConf.track && hasFallbackValue && hasOwnProperty(contextConf.resolve, "if") && collectContextUsage(contextConf.resolve.if, isTemplateState ? "STATE" : isFormState ? "FORM_STATE" : "CTX").usedContexts.length > 0;
|
|
2169
2183
|
yield storyboardContextWrapper.waitForUsedContext(contextConf.resolve.if);
|
|
2170
|
-
|
|
2184
|
+
useResolve = looseCheckIf$1(contextConf.resolve, mergedContext);
|
|
2185
|
+
if (useResolve || trackConditionalResolve) {
|
|
2171
2186
|
load = /*#__PURE__*/function () {
|
|
2172
2187
|
var _ref = _asyncToGenerator$3(function* (options) {
|
|
2173
2188
|
var valueConf = {};
|
|
@@ -2181,6 +2196,8 @@ function _resolveNormalStoryboardContext() {
|
|
|
2181
2196
|
return _ref.apply(this, arguments);
|
|
2182
2197
|
};
|
|
2183
2198
|
}();
|
|
2199
|
+
}
|
|
2200
|
+
if (useResolve) {
|
|
2184
2201
|
// `async` take precedence over `lazy`
|
|
2185
2202
|
resolvePolicy = contextConf.resolve.async && !isTemplateState ? "async" : contextConf.resolve.lazy ? "lazy" : "eager";
|
|
2186
2203
|
if (resolvePolicy === "eager") {
|
|
@@ -2202,18 +2219,18 @@ function _resolveNormalStoryboardContext() {
|
|
|
2202
2219
|
console.error("unsupported lifecycle: \"".concat(lifecycleName, "\""));
|
|
2203
2220
|
}
|
|
2204
2221
|
}
|
|
2205
|
-
} else if (!
|
|
2222
|
+
} else if (!hasFallbackValue) {
|
|
2206
2223
|
return false;
|
|
2207
2224
|
}
|
|
2208
2225
|
}
|
|
2209
|
-
if ((!
|
|
2226
|
+
if ((!useResolve || resolvePolicy !== "eager") && contextConf.value !== undefined) {
|
|
2210
2227
|
yield storyboardContextWrapper.waitForUsedContext(contextConf.value);
|
|
2211
2228
|
// If the context has no resolve, just use its `value`.
|
|
2212
2229
|
// Or if the resolve is ignored or lazy, use its `value` as a fallback.
|
|
2213
2230
|
value = computeRealValue(contextConf.value, mergedContext, true);
|
|
2214
2231
|
}
|
|
2215
2232
|
}
|
|
2216
|
-
resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, resolvePolicy === "eager", loading, resolvePolicy === "async");
|
|
2233
|
+
resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, resolvePolicy === "eager", loading, resolvePolicy === "async", useResolve, trackConditionalResolve);
|
|
2217
2234
|
return true;
|
|
2218
2235
|
});
|
|
2219
2236
|
return _resolveNormalStoryboardContext.apply(this, arguments);
|
|
@@ -2237,12 +2254,13 @@ function getDefinedTemplateState(isTemplateState, contextConf, brick) {
|
|
|
2237
2254
|
return brick.properties[contextConf.name];
|
|
2238
2255
|
}
|
|
2239
2256
|
}
|
|
2240
|
-
function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, loaded, loading, async) {
|
|
2257
|
+
function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, loaded, loading, async, useResolve, trackConditionalResolve) {
|
|
2241
2258
|
var newContext = {
|
|
2242
2259
|
type: "free-variable",
|
|
2243
2260
|
value,
|
|
2244
2261
|
// This is required for tracking context, even if no `onChange` is specified.
|
|
2245
2262
|
eventTarget: new EventTarget$1(),
|
|
2263
|
+
useResolve,
|
|
2246
2264
|
load,
|
|
2247
2265
|
loaded,
|
|
2248
2266
|
loading,
|
|
@@ -2262,13 +2280,14 @@ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardC
|
|
|
2262
2280
|
var isTemplateState = !!storyboardContextWrapper.tplContextId;
|
|
2263
2281
|
var isFormState = !!storyboardContextWrapper.formContextId;
|
|
2264
2282
|
// Track its dependencies and auto update when each of them changed.
|
|
2265
|
-
var deps = (isFormState ? trackUsedFormState : isTemplateState ? trackUsedState : trackUsedContext)(load ? contextConf.resolve : contextConf.value);
|
|
2283
|
+
var deps = (isFormState ? trackUsedFormState : isTemplateState ? trackUsedState : trackUsedContext)(trackConditionalResolve ? [contextConf.resolve, contextConf.value] : load ? contextConf.resolve : contextConf.value);
|
|
2266
2284
|
!load && (newContext.deps = deps);
|
|
2267
2285
|
for (var dep of deps) {
|
|
2268
2286
|
var _eventTarget;
|
|
2269
2287
|
var ctx = storyboardContextWrapper.get().get(dep);
|
|
2270
2288
|
ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(eventName, batchAddListener(() => {
|
|
2271
|
-
|
|
2289
|
+
newContext.useResolve = trackConditionalResolve ? looseCheckIf$1(contextConf.resolve, mergedContext) : !!load;
|
|
2290
|
+
if (newContext.useResolve) {
|
|
2272
2291
|
storyboardContextWrapper.updateValue(contextConf.name, {
|
|
2273
2292
|
cache: "default"
|
|
2274
2293
|
}, "refresh");
|
|
@@ -2595,15 +2614,9 @@ function evaluate(raw) {
|
|
|
2595
2614
|
}
|
|
2596
2615
|
});
|
|
2597
2616
|
case "QUERY":
|
|
2598
|
-
|
|
2599
|
-
var params = options.useRealTimeQuery ? new URLSearchParams(getHistory().location.search) : query;
|
|
2600
|
-
return Object.fromEntries(Array.from(params.keys()).map(key => [key, params.get(key)]));
|
|
2601
|
-
}
|
|
2617
|
+
return Object.fromEntries(Array.from(query.keys()).map(key => [key, query.get(key)]));
|
|
2602
2618
|
case "QUERY_ARRAY":
|
|
2603
|
-
|
|
2604
|
-
var _params = options.useRealTimeQuery ? new URLSearchParams(getHistory().location.search) : query;
|
|
2605
|
-
return Object.fromEntries(Array.from(_params.keys()).map(key => [key, _params.getAll(key)]));
|
|
2606
|
-
}
|
|
2619
|
+
return Object.fromEntries(Array.from(query.keys()).map(key => [key, query.getAll(key)]));
|
|
2607
2620
|
case "SEGUE":
|
|
2608
2621
|
return {
|
|
2609
2622
|
getUrl: getUrlBySegueFactory(app, segues)
|
|
@@ -14804,12 +14817,14 @@ function getRealValue(value) {
|
|
|
14804
14817
|
var {
|
|
14805
14818
|
useRealTimeQuery
|
|
14806
14819
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
14807
|
-
var
|
|
14820
|
+
var ctx = _objectSpread({}, _internalApiGetCurrentContext());
|
|
14821
|
+
if (useRealTimeQuery) {
|
|
14822
|
+
ctx.query = new URLSearchParams(getHistory().location.search);
|
|
14823
|
+
}
|
|
14824
|
+
var compute = data => {
|
|
14808
14825
|
if (typeof data === "string") {
|
|
14809
14826
|
if (isEvaluable(data)) {
|
|
14810
|
-
var result = evaluate(data,
|
|
14811
|
-
useRealTimeQuery
|
|
14812
|
-
});
|
|
14827
|
+
var result = evaluate(data, ctx);
|
|
14813
14828
|
recursiveMarkAsInjected(result);
|
|
14814
14829
|
return result;
|
|
14815
14830
|
}
|
|
@@ -14819,14 +14834,14 @@ function getRealValue(value) {
|
|
|
14819
14834
|
return data;
|
|
14820
14835
|
}
|
|
14821
14836
|
if (Array.isArray(data)) {
|
|
14822
|
-
return data.map(v => compute(v
|
|
14837
|
+
return data.map(v => compute(v));
|
|
14823
14838
|
}
|
|
14824
14839
|
return Object.fromEntries(Object.entries(data).map(_ref => {
|
|
14825
14840
|
var [k, v] = _ref;
|
|
14826
|
-
return [compute(k
|
|
14841
|
+
return [compute(k), compute(v)];
|
|
14827
14842
|
}));
|
|
14828
14843
|
};
|
|
14829
|
-
return compute(value
|
|
14844
|
+
return compute(value);
|
|
14830
14845
|
}
|
|
14831
14846
|
|
|
14832
14847
|
function constructEventListener(handler) {
|