@next-core/brick-kit 2.130.0 → 2.131.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/CHANGELOG.md +12 -0
- package/dist/index.bundle.js +95 -27
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +96 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/types/core/Resolver.d.ts.map +1 -1
- package/dist/types/core/StoryboardContext.d.ts +1 -1
- package/dist/types/core/StoryboardContext.d.ts.map +1 -1
- package/dist/types/internal/bindListeners.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
4
4
|
import _asyncToGenerator$3 from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
5
|
import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
|
|
6
6
|
import React, { useState, useEffect, useRef, forwardRef, useImperativeHandle, useMemo, useContext, createContext, useReducer, useCallback } from 'react';
|
|
7
|
-
import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, matchPath, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
|
|
7
|
+
import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, matchPath, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
|
|
8
8
|
import _, { set, get, difference, identity, uniqueId, cloneDeep, clamp, isNil, isEmpty, sortBy, merge, isObject as isObject$1, pick, orderBy, omit, findLastIndex, noop, isString } from 'lodash';
|
|
9
9
|
import { http, HttpResponseError, HttpFetchError } from '@next-core/brick-http';
|
|
10
10
|
import moment from 'moment';
|
|
@@ -2041,7 +2041,7 @@ class StoryboardContextWrapper {
|
|
|
2041
2041
|
}
|
|
2042
2042
|
|
|
2043
2043
|
updateValue(name, value, method) {
|
|
2044
|
-
var _item$
|
|
2044
|
+
var _item$eventTarget2;
|
|
2045
2045
|
|
|
2046
2046
|
if (!this.data.has(name)) {
|
|
2047
2047
|
if (this.tplContextId) {
|
|
@@ -2065,6 +2065,22 @@ class StoryboardContextWrapper {
|
|
|
2065
2065
|
return;
|
|
2066
2066
|
}
|
|
2067
2067
|
|
|
2068
|
+
if (method === "refresh") {
|
|
2069
|
+
if (!item.refresh) {
|
|
2070
|
+
throw new Error("You can not refresh the storyboard context \"".concat(name, "\" which has no resolve."));
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
item.refresh().then(val => {
|
|
2074
|
+
var _item$eventTarget;
|
|
2075
|
+
|
|
2076
|
+
item.value = val;
|
|
2077
|
+
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
|
|
2078
|
+
detail: item.value
|
|
2079
|
+
}));
|
|
2080
|
+
}, handleHttpError);
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2068
2084
|
if (method === "replace") {
|
|
2069
2085
|
item.value = value;
|
|
2070
2086
|
} else {
|
|
@@ -2077,7 +2093,7 @@ class StoryboardContextWrapper {
|
|
|
2077
2093
|
}
|
|
2078
2094
|
}
|
|
2079
2095
|
|
|
2080
|
-
(_item$
|
|
2096
|
+
(_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
|
|
2081
2097
|
detail: item.value
|
|
2082
2098
|
}));
|
|
2083
2099
|
}
|
|
@@ -2158,30 +2174,65 @@ function _resolveNormalStoryboardContext() {
|
|
|
2158
2174
|
return false;
|
|
2159
2175
|
}
|
|
2160
2176
|
|
|
2161
|
-
var
|
|
2162
|
-
var value = getDefinedTemplateState(
|
|
2177
|
+
var isTemplateState = !!storyboardContextWrapper.tplContextId;
|
|
2178
|
+
var value = getDefinedTemplateState(isTemplateState, contextConf, brick);
|
|
2179
|
+
var refresh = null;
|
|
2180
|
+
var isLazyResolve = false;
|
|
2163
2181
|
|
|
2164
2182
|
if (value === undefined) {
|
|
2165
2183
|
if (contextConf.resolve) {
|
|
2166
2184
|
if (looseCheckIf(contextConf.resolve, mergedContext)) {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2185
|
+
refresh = /*#__PURE__*/function () {
|
|
2186
|
+
var _ref = _asyncToGenerator$3(function* () {
|
|
2187
|
+
var valueConf = {};
|
|
2188
|
+
yield _internalApiGetResolver().resolveOne("reference", _objectSpread({
|
|
2189
|
+
transform: "value",
|
|
2190
|
+
transformMapArray: false
|
|
2191
|
+
}, contextConf.resolve), valueConf, null, mergedContext);
|
|
2192
|
+
return valueConf.value;
|
|
2193
|
+
});
|
|
2194
|
+
|
|
2195
|
+
return function refresh() {
|
|
2196
|
+
return _ref.apply(this, arguments);
|
|
2197
|
+
};
|
|
2198
|
+
}();
|
|
2199
|
+
|
|
2200
|
+
isLazyResolve = contextConf.resolve.lazy;
|
|
2201
|
+
|
|
2202
|
+
if (!isLazyResolve) {
|
|
2203
|
+
value = yield refresh();
|
|
2204
|
+
}
|
|
2174
2205
|
} else if (!hasOwnProperty(contextConf, "value")) {
|
|
2175
2206
|
return false;
|
|
2176
2207
|
}
|
|
2177
2208
|
}
|
|
2178
2209
|
|
|
2179
|
-
if (!
|
|
2210
|
+
if ((!refresh || isLazyResolve) && contextConf.value !== undefined) {
|
|
2211
|
+
// If the context has no resolve, just use its `value`.
|
|
2212
|
+
// Or if the resolve is ignored or lazy, use its `value` as a fallback.
|
|
2180
2213
|
value = computeRealValue(contextConf.value, mergedContext, true);
|
|
2181
2214
|
}
|
|
2215
|
+
|
|
2216
|
+
if (contextConf.track) {
|
|
2217
|
+
// Track its dependencies and auto update when each of them changed.
|
|
2218
|
+
var deps = (isTemplateState ? trackUsedState : trackUsedContext)(refresh ? contextConf.resolve : contextConf.value);
|
|
2219
|
+
|
|
2220
|
+
for (var dep of deps) {
|
|
2221
|
+
var _eventTarget;
|
|
2222
|
+
|
|
2223
|
+
var ctx = storyboardContextWrapper.get().get(dep);
|
|
2224
|
+
ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(isTemplateState ? "state.change" : "context.change", () => {
|
|
2225
|
+
if (refresh) {
|
|
2226
|
+
storyboardContextWrapper.updateValue(contextConf.name, undefined, "refresh");
|
|
2227
|
+
} else {
|
|
2228
|
+
storyboardContextWrapper.updateValue(contextConf.name, computeRealValue(contextConf.value, mergedContext, true), "replace");
|
|
2229
|
+
}
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2182
2233
|
}
|
|
2183
2234
|
|
|
2184
|
-
resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
|
|
2235
|
+
resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh);
|
|
2185
2236
|
return true;
|
|
2186
2237
|
});
|
|
2187
2238
|
return _resolveNormalStoryboardContext.apply(this, arguments);
|
|
@@ -2212,12 +2263,13 @@ function getDefinedTemplateState(isTemplateState, contextConf, brick) {
|
|
|
2212
2263
|
}
|
|
2213
2264
|
}
|
|
2214
2265
|
|
|
2215
|
-
function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick) {
|
|
2266
|
+
function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh) {
|
|
2216
2267
|
var newContext = {
|
|
2217
2268
|
type: "free-variable",
|
|
2218
2269
|
value,
|
|
2219
2270
|
// This is required for tracking context, even if no `onChange` is specified.
|
|
2220
|
-
eventTarget: new EventTarget$1()
|
|
2271
|
+
eventTarget: new EventTarget$1(),
|
|
2272
|
+
refresh
|
|
2221
2273
|
};
|
|
2222
2274
|
|
|
2223
2275
|
if (contextConf.onChange) {
|
|
@@ -6288,10 +6340,12 @@ function listenerFactory(handler, context, runtimeBrick) {
|
|
|
6288
6340
|
|
|
6289
6341
|
case "context.assign":
|
|
6290
6342
|
case "context.replace":
|
|
6343
|
+
case "context.refresh":
|
|
6291
6344
|
return builtinContextListenerFactory(method, handler.args, handler, context);
|
|
6292
6345
|
|
|
6293
6346
|
case "state.update":
|
|
6294
|
-
|
|
6347
|
+
case "state.refresh":
|
|
6348
|
+
return builtinStateListenerFactory(method, handler.args, handler, context);
|
|
6295
6349
|
|
|
6296
6350
|
case "tpl.dispatchEvent":
|
|
6297
6351
|
return builtinTplDispatchEventFactory(handler.args, handler, context);
|
|
@@ -6435,7 +6489,7 @@ function builtinContextListenerFactory(method, args, ifContainer, context) {
|
|
|
6435
6489
|
};
|
|
6436
6490
|
}
|
|
6437
6491
|
|
|
6438
|
-
function builtinStateListenerFactory(args, ifContainer, context) {
|
|
6492
|
+
function builtinStateListenerFactory(method, args, ifContainer, context) {
|
|
6439
6493
|
return function (event) {
|
|
6440
6494
|
if (!looseCheckIf(ifContainer, _objectSpread(_objectSpread({}, context), {}, {
|
|
6441
6495
|
event
|
|
@@ -6445,7 +6499,7 @@ function builtinStateListenerFactory(args, ifContainer, context) {
|
|
|
6445
6499
|
|
|
6446
6500
|
var tplContext = getTplContext(context.tplContextId);
|
|
6447
6501
|
var [name, value] = argsFactory(args, context, event);
|
|
6448
|
-
tplContext.state.updateValue(name, value, "replace");
|
|
6502
|
+
tplContext.state.updateValue(name, value, method === "refresh" ? method : "replace");
|
|
6449
6503
|
};
|
|
6450
6504
|
}
|
|
6451
6505
|
|
|
@@ -10802,7 +10856,7 @@ class LocationContext {
|
|
|
10802
10856
|
if (expandedBrickConf.exports) {
|
|
10803
10857
|
for (var [prop, ctxName] of Object.entries(expandedBrickConf.exports)) {
|
|
10804
10858
|
if (typeof ctxName === "string" && ctxName.startsWith("CTX.")) {
|
|
10805
|
-
_this6.storyboardContextWrapper.set(ctxName.
|
|
10859
|
+
_this6.storyboardContextWrapper.set(ctxName.substring(4), {
|
|
10806
10860
|
type: "brick-property",
|
|
10807
10861
|
brick,
|
|
10808
10862
|
prop
|
|
@@ -11381,19 +11435,33 @@ class Resolver {
|
|
|
11381
11435
|
}
|
|
11382
11436
|
}
|
|
11383
11437
|
|
|
11384
|
-
var
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
|
|
11388
|
-
|
|
11389
|
-
|
|
11438
|
+
var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
|
|
11439
|
+
: context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
|
|
11440
|
+
var cacheKey;
|
|
11441
|
+
|
|
11442
|
+
try {
|
|
11443
|
+
// `actualArgs` may contain circular references, which makes
|
|
11444
|
+
// JSON stringify failed, thus we fallback to original args.
|
|
11445
|
+
cacheKey = JSON.stringify({
|
|
11446
|
+
provider,
|
|
11447
|
+
useProvider,
|
|
11448
|
+
method,
|
|
11449
|
+
actualArgs
|
|
11450
|
+
});
|
|
11451
|
+
} catch (e) {
|
|
11452
|
+
cacheKey = JSON.stringify({
|
|
11453
|
+
provider,
|
|
11454
|
+
useProvider,
|
|
11455
|
+
method,
|
|
11456
|
+
args
|
|
11457
|
+
});
|
|
11458
|
+
}
|
|
11459
|
+
|
|
11390
11460
|
var promise;
|
|
11391
11461
|
|
|
11392
11462
|
if (_this2.cache.has(cacheKey)) {
|
|
11393
11463
|
promise = _this2.cache.get(cacheKey);
|
|
11394
11464
|
} else {
|
|
11395
|
-
var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
|
|
11396
|
-
: context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
|
|
11397
11465
|
promise = _asyncToGenerator$3(function* () {
|
|
11398
11466
|
if (useProvider) {
|
|
11399
11467
|
actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
|