@next-core/brick-kit 2.169.1 → 2.171.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 +134 -14
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +134 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/types/core/BrickNode.d.ts.map +1 -1
- package/dist/types/core/Runtime.d.ts +4 -2
- package/dist/types/core/Runtime.d.ts.map +1 -1
- package/dist/types/core/StoryboardContext.d.ts +6 -1
- package/dist/types/core/StoryboardContext.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +3 -0
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/developHelper.d.ts +3 -1
- package/dist/types/developHelper.d.ts.map +1 -1
- package/dist/types/internal/bindListeners.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.bundle.js
CHANGED
|
@@ -1784,11 +1784,15 @@
|
|
|
1784
1784
|
class StoryboardContextWrapper {
|
|
1785
1785
|
constructor(tplContextId, formContextId) {
|
|
1786
1786
|
_defineProperty__default["default"](this, "data", new Map());
|
|
1787
|
+
_defineProperty__default["default"](this, "batchUpdate", false);
|
|
1788
|
+
_defineProperty__default["default"](this, "batchUpdateContextsNames", []);
|
|
1787
1789
|
_defineProperty__default["default"](this, "tplContextId", void 0);
|
|
1788
1790
|
_defineProperty__default["default"](this, "formContextId", void 0);
|
|
1791
|
+
_defineProperty__default["default"](this, "eventName", void 0);
|
|
1789
1792
|
_defineProperty__default["default"](this, "pendingStack", []);
|
|
1790
1793
|
this.tplContextId = tplContextId;
|
|
1791
1794
|
this.formContextId = formContextId;
|
|
1795
|
+
this.eventName = this.formContextId ? "formstate.change" : this.tplContextId ? "state.change" : "context.change";
|
|
1792
1796
|
}
|
|
1793
1797
|
set(name, item) {
|
|
1794
1798
|
if (this.data.has(name)) {
|
|
@@ -1806,6 +1810,54 @@
|
|
|
1806
1810
|
var _this$data$get;
|
|
1807
1811
|
return (_this$data$get = this.data.get(name)) === null || _this$data$get === void 0 ? void 0 : _this$data$get.value;
|
|
1808
1812
|
}
|
|
1813
|
+
getAffectListByContext(name) {
|
|
1814
|
+
var affectNames = [name];
|
|
1815
|
+
this.data.forEach((value, key) => {
|
|
1816
|
+
if (value.type === "free-variable" && value.deps) {
|
|
1817
|
+
var isInDeps = value.deps.some(item => affectNames.includes(item));
|
|
1818
|
+
isInDeps && affectNames.push(key) && affectNames.push(...this.getAffectListByContext(key));
|
|
1819
|
+
}
|
|
1820
|
+
});
|
|
1821
|
+
affectNames.shift();
|
|
1822
|
+
return [...new Set(affectNames)];
|
|
1823
|
+
}
|
|
1824
|
+
updateValues(values, method, argsFactory) {
|
|
1825
|
+
this.batchUpdate = true;
|
|
1826
|
+
this.batchUpdateContextsNames = values.map(item => item.name);
|
|
1827
|
+
if ([...new Set(this.batchUpdateContextsNames)].length !== this.batchUpdateContextsNames.length) {
|
|
1828
|
+
throw new Error("Batch update not allow to update same item");
|
|
1829
|
+
}
|
|
1830
|
+
var updateContexts = {};
|
|
1831
|
+
var affectContexts = {};
|
|
1832
|
+
var affectDepsContextNames = [];
|
|
1833
|
+
values.forEach(arg => {
|
|
1834
|
+
var {
|
|
1835
|
+
name,
|
|
1836
|
+
value
|
|
1837
|
+
} = argsFactory([arg]);
|
|
1838
|
+
var updateContextItem = this.data.get(name);
|
|
1839
|
+
affectDepsContextNames.push(...this.getAffectListByContext(name));
|
|
1840
|
+
updateContextItem.type === "free-variable" && (updateContexts[name] = updateContextItem);
|
|
1841
|
+
this.updateValue(name, value, method);
|
|
1842
|
+
});
|
|
1843
|
+
affectDepsContextNames.filter(item => !updateContexts[item]).forEach(name => {
|
|
1844
|
+
var affectContextItem = this.data.get(name);
|
|
1845
|
+
affectContextItem.type === "free-variable" && (affectContexts[name] = affectContextItem);
|
|
1846
|
+
});
|
|
1847
|
+
var triggerEvent = contexts => {
|
|
1848
|
+
for (var key in contexts) {
|
|
1849
|
+
var _context$eventTarget;
|
|
1850
|
+
var context = contexts[key];
|
|
1851
|
+
(_context$eventTarget = context.eventTarget) === null || _context$eventTarget === void 0 ? void 0 : _context$eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1852
|
+
detail: context.value
|
|
1853
|
+
}));
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
triggerEvent(updateContexts);
|
|
1857
|
+
triggerEvent(affectContexts);
|
|
1858
|
+
this.batchUpdate = false;
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1809
1861
|
updateValue(name, value, method, callback) {
|
|
1810
1862
|
var _item$eventTarget2;
|
|
1811
1863
|
if (!this.data.has(name)) {
|
|
@@ -1849,7 +1901,7 @@
|
|
|
1849
1901
|
var _item$eventTarget;
|
|
1850
1902
|
item.loaded = true;
|
|
1851
1903
|
item.value = val;
|
|
1852
|
-
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.
|
|
1904
|
+
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1853
1905
|
detail: item.value
|
|
1854
1906
|
}));
|
|
1855
1907
|
}, err => {
|
|
@@ -1884,7 +1936,8 @@
|
|
|
1884
1936
|
item.value = value;
|
|
1885
1937
|
}
|
|
1886
1938
|
}
|
|
1887
|
-
|
|
1939
|
+
if (this.batchUpdate) return;
|
|
1940
|
+
(_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1888
1941
|
detail: item.value
|
|
1889
1942
|
}));
|
|
1890
1943
|
}
|
|
@@ -2068,11 +2121,13 @@
|
|
|
2068
2121
|
// This is required for tracking context, even if no `onChange` is specified.
|
|
2069
2122
|
eventTarget: new EventTarget$1(),
|
|
2070
2123
|
load,
|
|
2071
|
-
loaded
|
|
2124
|
+
loaded,
|
|
2125
|
+
deps: []
|
|
2072
2126
|
};
|
|
2127
|
+
var eventName = storyboardContextWrapper.formContextId ? "formstate.change" : storyboardContextWrapper.tplContextId ? "state.change" : "context.change";
|
|
2073
2128
|
if (contextConf.onChange) {
|
|
2074
2129
|
for (var handler of [].concat(contextConf.onChange)) {
|
|
2075
|
-
newContext.eventTarget.addEventListener(
|
|
2130
|
+
newContext.eventTarget.addEventListener(eventName, listenerFactory(handler, mergedContext, brick));
|
|
2076
2131
|
}
|
|
2077
2132
|
}
|
|
2078
2133
|
if (contextConf.track) {
|
|
@@ -2080,10 +2135,11 @@
|
|
|
2080
2135
|
var isFormState = !!storyboardContextWrapper.formContextId;
|
|
2081
2136
|
// Track its dependencies and auto update when each of them changed.
|
|
2082
2137
|
var deps = (isFormState ? brickUtils.trackUsedFormState : isTemplateState ? brickUtils.trackUsedState : brickUtils.trackUsedContext)(load ? contextConf.resolve : contextConf.value);
|
|
2138
|
+
!load && (newContext.deps = deps);
|
|
2083
2139
|
for (var dep of deps) {
|
|
2084
2140
|
var _eventTarget;
|
|
2085
2141
|
var ctx = storyboardContextWrapper.get().get(dep);
|
|
2086
|
-
ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(
|
|
2142
|
+
ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(eventName, batchAddListener(() => {
|
|
2087
2143
|
if (load) {
|
|
2088
2144
|
storyboardContextWrapper.updateValue(contextConf.name, {
|
|
2089
2145
|
cache: "default"
|
|
@@ -2091,11 +2147,19 @@
|
|
|
2091
2147
|
} else {
|
|
2092
2148
|
storyboardContextWrapper.updateValue(contextConf.name, computeRealValue(contextConf.value, mergedContext, true), "replace");
|
|
2093
2149
|
}
|
|
2094
|
-
});
|
|
2150
|
+
}, contextConf, storyboardContextWrapper));
|
|
2095
2151
|
}
|
|
2096
2152
|
}
|
|
2097
2153
|
storyboardContextWrapper.set(contextConf.name, newContext);
|
|
2098
2154
|
}
|
|
2155
|
+
function batchAddListener(listener, contextConf, storyboardContextWrapper) {
|
|
2156
|
+
return event => {
|
|
2157
|
+
if (storyboardContextWrapper.batchUpdate && storyboardContextWrapper.batchUpdateContextsNames.includes(contextConf.name)) {
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
listener(event);
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2099
2163
|
|
|
2100
2164
|
var tplContextMap = new Map();
|
|
2101
2165
|
class CustomTemplateContext {
|
|
@@ -3376,6 +3440,30 @@
|
|
|
3376
3440
|
kernel._dev_only_updateStoryboardBySnippet(appId, newSnippet);
|
|
3377
3441
|
}
|
|
3378
3442
|
|
|
3443
|
+
/* istanbul ignore next */
|
|
3444
|
+
function _dev_only_getContextValue(name, _ref) {
|
|
3445
|
+
var {
|
|
3446
|
+
tplContextId
|
|
3447
|
+
} = _ref;
|
|
3448
|
+
if (tplContextId) {
|
|
3449
|
+
var tplContext = getCustomTemplateContext(tplContextId);
|
|
3450
|
+
return tplContext.state.getValue(name);
|
|
3451
|
+
}
|
|
3452
|
+
return kernel.router.getStoryboardContextWrapper().getValue(name);
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3455
|
+
/* istanbul ignore next */
|
|
3456
|
+
function _dev_only_getAllContextValues(_ref2) {
|
|
3457
|
+
var {
|
|
3458
|
+
tplContextId
|
|
3459
|
+
} = _ref2;
|
|
3460
|
+
if (tplContextId) {
|
|
3461
|
+
var tplContext = getCustomTemplateContext(tplContextId);
|
|
3462
|
+
return tplContext.state.get();
|
|
3463
|
+
}
|
|
3464
|
+
return kernel.router.getStoryboardContextWrapper().get();
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3379
3467
|
/* istanbul ignore next */
|
|
3380
3468
|
function _dev_only_updateFormPreviewSettings(appId, formId, settings) {
|
|
3381
3469
|
kernel._dev_only_updateFormPreviewSettings(appId, formId, settings);
|
|
@@ -5912,6 +6000,7 @@
|
|
|
5912
6000
|
};
|
|
5913
6001
|
}
|
|
5914
6002
|
function listenerFactory(handler, context, runtimeBrick) {
|
|
6003
|
+
var _handler$batch, _handler$batch2;
|
|
5915
6004
|
if (isConditionalEventHandler(handler)) {
|
|
5916
6005
|
return runConditionalEventHandler(handler, context, runtimeBrick);
|
|
5917
6006
|
}
|
|
@@ -5980,11 +6069,11 @@
|
|
|
5980
6069
|
case "context.replace":
|
|
5981
6070
|
case "context.refresh":
|
|
5982
6071
|
case "context.load":
|
|
5983
|
-
return builtinContextListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
|
|
6072
|
+
return builtinContextListenerFactory(method, handler.args, (_handler$batch = handler.batch) !== null && _handler$batch !== void 0 ? _handler$batch : true, handler, handler.callback, context, runtimeBrick);
|
|
5984
6073
|
case "state.update":
|
|
5985
6074
|
case "state.refresh":
|
|
5986
6075
|
case "state.load":
|
|
5987
|
-
return builtinStateListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
|
|
6076
|
+
return builtinStateListenerFactory(method, handler.args, (_handler$batch2 = handler.batch) !== null && _handler$batch2 !== void 0 ? _handler$batch2 : true, handler, handler.callback, context, runtimeBrick);
|
|
5988
6077
|
case "formstate.update":
|
|
5989
6078
|
return builtinFormStateListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
|
|
5990
6079
|
case "tpl.dispatchEvent":
|
|
@@ -6098,7 +6187,22 @@
|
|
|
6098
6187
|
tpl.dispatchEvent(new CustomEvent(type, init));
|
|
6099
6188
|
};
|
|
6100
6189
|
}
|
|
6101
|
-
function
|
|
6190
|
+
function batchUpdate(args, batch, method, context, event) {
|
|
6191
|
+
if (batch) {
|
|
6192
|
+
context.updateValues(args, method, arg => {
|
|
6193
|
+
return argsFactory(arg, context, event)[0];
|
|
6194
|
+
});
|
|
6195
|
+
} else {
|
|
6196
|
+
args.forEach(arg => {
|
|
6197
|
+
var {
|
|
6198
|
+
name,
|
|
6199
|
+
value
|
|
6200
|
+
} = argsFactory([arg], context, event)[0];
|
|
6201
|
+
context.updateValue(name, value, method);
|
|
6202
|
+
});
|
|
6203
|
+
}
|
|
6204
|
+
}
|
|
6205
|
+
function builtinContextListenerFactory(method, args, batch, ifContainer, callback, context, runtimeBrick) {
|
|
6102
6206
|
return function (event) {
|
|
6103
6207
|
if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
|
|
6104
6208
|
event
|
|
@@ -6106,11 +6210,16 @@
|
|
|
6106
6210
|
return;
|
|
6107
6211
|
}
|
|
6108
6212
|
var storyboardContext = _internalApiGetStoryboardContextWrapper();
|
|
6109
|
-
var
|
|
6110
|
-
|
|
6213
|
+
var isBatch = Array.isArray(args) && args.every(brickUtils.isObject);
|
|
6214
|
+
if (isBatch && (method === "assign" || method === "replace")) {
|
|
6215
|
+
batchUpdate(args, batch, method, storyboardContext, event);
|
|
6216
|
+
} else {
|
|
6217
|
+
var [name, value] = argsFactory(args, context, event);
|
|
6218
|
+
storyboardContext.updateValue(name, value, method, callback);
|
|
6219
|
+
}
|
|
6111
6220
|
};
|
|
6112
6221
|
}
|
|
6113
|
-
function builtinStateListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {
|
|
6222
|
+
function builtinStateListenerFactory(method, args, batch, ifContainer, callback, context, runtimeBrick) {
|
|
6114
6223
|
return function (event) {
|
|
6115
6224
|
if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
|
|
6116
6225
|
event
|
|
@@ -6118,8 +6227,14 @@
|
|
|
6118
6227
|
return;
|
|
6119
6228
|
}
|
|
6120
6229
|
var tplContext = getTplContext(context.tplContextId);
|
|
6121
|
-
var
|
|
6122
|
-
|
|
6230
|
+
var isBatch = Array.isArray(args) && args.every(brickUtils.isObject);
|
|
6231
|
+
var computedMethod = method === "update" ? "replace" : method;
|
|
6232
|
+
if (isBatch && computedMethod === "replace") {
|
|
6233
|
+
batchUpdate(args, batch, computedMethod, tplContext.state, event);
|
|
6234
|
+
} else {
|
|
6235
|
+
var [name, value] = argsFactory(args, context, event);
|
|
6236
|
+
tplContext.state.updateValue(name, value, computedMethod, callback);
|
|
6237
|
+
}
|
|
6123
6238
|
};
|
|
6124
6239
|
}
|
|
6125
6240
|
function builtinFormStateListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {
|
|
@@ -6559,6 +6674,9 @@
|
|
|
6559
6674
|
if (brick.iid) {
|
|
6560
6675
|
node.dataset.iid = brick.iid;
|
|
6561
6676
|
}
|
|
6677
|
+
if (brick.tplContextId) {
|
|
6678
|
+
node.dataset.tplContextId = brick.tplContextId;
|
|
6679
|
+
}
|
|
6562
6680
|
setRealProperties(node, brick.properties);
|
|
6563
6681
|
bindListeners(node, brick.events, brick.context);
|
|
6564
6682
|
if (Array.isArray(brick.children)) {
|
|
@@ -13952,6 +14070,8 @@
|
|
|
13952
14070
|
updateTemplatePreviewSettings: _dev_only_updateTemplatePreviewSettings,
|
|
13953
14071
|
updateSnippetPreviewSettings: _dev_only_updateSnippetPreviewSettings,
|
|
13954
14072
|
updateFormPreviewSettings: _dev_only_updateFormPreviewSettings,
|
|
14073
|
+
getContextValue: _dev_only_getContextValue,
|
|
14074
|
+
getAllContextValues: _dev_only_getAllContextValues,
|
|
13955
14075
|
render: _dev_only_render
|
|
13956
14076
|
};
|
|
13957
14077
|
|