@next-core/brick-kit 2.170.0 → 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 +105 -14
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +105 -14
- package/dist/index.esm.js.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/internal/bindListeners.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.esm.js
CHANGED
|
@@ -1785,11 +1785,15 @@ function _checkIf(rawIf, ctx, fn) {
|
|
|
1785
1785
|
class StoryboardContextWrapper {
|
|
1786
1786
|
constructor(tplContextId, formContextId) {
|
|
1787
1787
|
_defineProperty$1(this, "data", new Map());
|
|
1788
|
+
_defineProperty$1(this, "batchUpdate", false);
|
|
1789
|
+
_defineProperty$1(this, "batchUpdateContextsNames", []);
|
|
1788
1790
|
_defineProperty$1(this, "tplContextId", void 0);
|
|
1789
1791
|
_defineProperty$1(this, "formContextId", void 0);
|
|
1792
|
+
_defineProperty$1(this, "eventName", void 0);
|
|
1790
1793
|
_defineProperty$1(this, "pendingStack", []);
|
|
1791
1794
|
this.tplContextId = tplContextId;
|
|
1792
1795
|
this.formContextId = formContextId;
|
|
1796
|
+
this.eventName = this.formContextId ? "formstate.change" : this.tplContextId ? "state.change" : "context.change";
|
|
1793
1797
|
}
|
|
1794
1798
|
set(name, item) {
|
|
1795
1799
|
if (this.data.has(name)) {
|
|
@@ -1807,6 +1811,54 @@ class StoryboardContextWrapper {
|
|
|
1807
1811
|
var _this$data$get;
|
|
1808
1812
|
return (_this$data$get = this.data.get(name)) === null || _this$data$get === void 0 ? void 0 : _this$data$get.value;
|
|
1809
1813
|
}
|
|
1814
|
+
getAffectListByContext(name) {
|
|
1815
|
+
var affectNames = [name];
|
|
1816
|
+
this.data.forEach((value, key) => {
|
|
1817
|
+
if (value.type === "free-variable" && value.deps) {
|
|
1818
|
+
var isInDeps = value.deps.some(item => affectNames.includes(item));
|
|
1819
|
+
isInDeps && affectNames.push(key) && affectNames.push(...this.getAffectListByContext(key));
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
affectNames.shift();
|
|
1823
|
+
return [...new Set(affectNames)];
|
|
1824
|
+
}
|
|
1825
|
+
updateValues(values, method, argsFactory) {
|
|
1826
|
+
this.batchUpdate = true;
|
|
1827
|
+
this.batchUpdateContextsNames = values.map(item => item.name);
|
|
1828
|
+
if ([...new Set(this.batchUpdateContextsNames)].length !== this.batchUpdateContextsNames.length) {
|
|
1829
|
+
throw new Error("Batch update not allow to update same item");
|
|
1830
|
+
}
|
|
1831
|
+
var updateContexts = {};
|
|
1832
|
+
var affectContexts = {};
|
|
1833
|
+
var affectDepsContextNames = [];
|
|
1834
|
+
values.forEach(arg => {
|
|
1835
|
+
var {
|
|
1836
|
+
name,
|
|
1837
|
+
value
|
|
1838
|
+
} = argsFactory([arg]);
|
|
1839
|
+
var updateContextItem = this.data.get(name);
|
|
1840
|
+
affectDepsContextNames.push(...this.getAffectListByContext(name));
|
|
1841
|
+
updateContextItem.type === "free-variable" && (updateContexts[name] = updateContextItem);
|
|
1842
|
+
this.updateValue(name, value, method);
|
|
1843
|
+
});
|
|
1844
|
+
affectDepsContextNames.filter(item => !updateContexts[item]).forEach(name => {
|
|
1845
|
+
var affectContextItem = this.data.get(name);
|
|
1846
|
+
affectContextItem.type === "free-variable" && (affectContexts[name] = affectContextItem);
|
|
1847
|
+
});
|
|
1848
|
+
var triggerEvent = contexts => {
|
|
1849
|
+
for (var key in contexts) {
|
|
1850
|
+
var _context$eventTarget;
|
|
1851
|
+
var context = contexts[key];
|
|
1852
|
+
(_context$eventTarget = context.eventTarget) === null || _context$eventTarget === void 0 ? void 0 : _context$eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1853
|
+
detail: context.value
|
|
1854
|
+
}));
|
|
1855
|
+
}
|
|
1856
|
+
};
|
|
1857
|
+
triggerEvent(updateContexts);
|
|
1858
|
+
triggerEvent(affectContexts);
|
|
1859
|
+
this.batchUpdate = false;
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1810
1862
|
updateValue(name, value, method, callback) {
|
|
1811
1863
|
var _item$eventTarget2;
|
|
1812
1864
|
if (!this.data.has(name)) {
|
|
@@ -1850,7 +1902,7 @@ class StoryboardContextWrapper {
|
|
|
1850
1902
|
var _item$eventTarget;
|
|
1851
1903
|
item.loaded = true;
|
|
1852
1904
|
item.value = val;
|
|
1853
|
-
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.
|
|
1905
|
+
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1854
1906
|
detail: item.value
|
|
1855
1907
|
}));
|
|
1856
1908
|
}, err => {
|
|
@@ -1885,7 +1937,8 @@ class StoryboardContextWrapper {
|
|
|
1885
1937
|
item.value = value;
|
|
1886
1938
|
}
|
|
1887
1939
|
}
|
|
1888
|
-
|
|
1940
|
+
if (this.batchUpdate) return;
|
|
1941
|
+
(_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.eventName, {
|
|
1889
1942
|
detail: item.value
|
|
1890
1943
|
}));
|
|
1891
1944
|
}
|
|
@@ -2069,11 +2122,13 @@ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardC
|
|
|
2069
2122
|
// This is required for tracking context, even if no `onChange` is specified.
|
|
2070
2123
|
eventTarget: new EventTarget$1(),
|
|
2071
2124
|
load,
|
|
2072
|
-
loaded
|
|
2125
|
+
loaded,
|
|
2126
|
+
deps: []
|
|
2073
2127
|
};
|
|
2128
|
+
var eventName = storyboardContextWrapper.formContextId ? "formstate.change" : storyboardContextWrapper.tplContextId ? "state.change" : "context.change";
|
|
2074
2129
|
if (contextConf.onChange) {
|
|
2075
2130
|
for (var handler of [].concat(contextConf.onChange)) {
|
|
2076
|
-
newContext.eventTarget.addEventListener(
|
|
2131
|
+
newContext.eventTarget.addEventListener(eventName, listenerFactory(handler, mergedContext, brick));
|
|
2077
2132
|
}
|
|
2078
2133
|
}
|
|
2079
2134
|
if (contextConf.track) {
|
|
@@ -2081,10 +2136,11 @@ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardC
|
|
|
2081
2136
|
var isFormState = !!storyboardContextWrapper.formContextId;
|
|
2082
2137
|
// Track its dependencies and auto update when each of them changed.
|
|
2083
2138
|
var deps = (isFormState ? trackUsedFormState : isTemplateState ? trackUsedState : trackUsedContext)(load ? contextConf.resolve : contextConf.value);
|
|
2139
|
+
!load && (newContext.deps = deps);
|
|
2084
2140
|
for (var dep of deps) {
|
|
2085
2141
|
var _eventTarget;
|
|
2086
2142
|
var ctx = storyboardContextWrapper.get().get(dep);
|
|
2087
|
-
ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(
|
|
2143
|
+
ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(eventName, batchAddListener(() => {
|
|
2088
2144
|
if (load) {
|
|
2089
2145
|
storyboardContextWrapper.updateValue(contextConf.name, {
|
|
2090
2146
|
cache: "default"
|
|
@@ -2092,11 +2148,19 @@ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardC
|
|
|
2092
2148
|
} else {
|
|
2093
2149
|
storyboardContextWrapper.updateValue(contextConf.name, computeRealValue(contextConf.value, mergedContext, true), "replace");
|
|
2094
2150
|
}
|
|
2095
|
-
});
|
|
2151
|
+
}, contextConf, storyboardContextWrapper));
|
|
2096
2152
|
}
|
|
2097
2153
|
}
|
|
2098
2154
|
storyboardContextWrapper.set(contextConf.name, newContext);
|
|
2099
2155
|
}
|
|
2156
|
+
function batchAddListener(listener, contextConf, storyboardContextWrapper) {
|
|
2157
|
+
return event => {
|
|
2158
|
+
if (storyboardContextWrapper.batchUpdate && storyboardContextWrapper.batchUpdateContextsNames.includes(contextConf.name)) {
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
listener(event);
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2100
2164
|
|
|
2101
2165
|
var tplContextMap = new Map();
|
|
2102
2166
|
class CustomTemplateContext {
|
|
@@ -5937,6 +6001,7 @@ function runConditionalEventHandler(handler, context, runtimeBrick) {
|
|
|
5937
6001
|
};
|
|
5938
6002
|
}
|
|
5939
6003
|
function listenerFactory(handler, context, runtimeBrick) {
|
|
6004
|
+
var _handler$batch, _handler$batch2;
|
|
5940
6005
|
if (isConditionalEventHandler(handler)) {
|
|
5941
6006
|
return runConditionalEventHandler(handler, context, runtimeBrick);
|
|
5942
6007
|
}
|
|
@@ -6005,11 +6070,11 @@ function listenerFactory(handler, context, runtimeBrick) {
|
|
|
6005
6070
|
case "context.replace":
|
|
6006
6071
|
case "context.refresh":
|
|
6007
6072
|
case "context.load":
|
|
6008
|
-
return builtinContextListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
|
|
6073
|
+
return builtinContextListenerFactory(method, handler.args, (_handler$batch = handler.batch) !== null && _handler$batch !== void 0 ? _handler$batch : true, handler, handler.callback, context, runtimeBrick);
|
|
6009
6074
|
case "state.update":
|
|
6010
6075
|
case "state.refresh":
|
|
6011
6076
|
case "state.load":
|
|
6012
|
-
return builtinStateListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
|
|
6077
|
+
return builtinStateListenerFactory(method, handler.args, (_handler$batch2 = handler.batch) !== null && _handler$batch2 !== void 0 ? _handler$batch2 : true, handler, handler.callback, context, runtimeBrick);
|
|
6013
6078
|
case "formstate.update":
|
|
6014
6079
|
return builtinFormStateListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
|
|
6015
6080
|
case "tpl.dispatchEvent":
|
|
@@ -6123,7 +6188,22 @@ function builtinTplDispatchEventFactory(args, ifContainer, context, runtimeBrick
|
|
|
6123
6188
|
tpl.dispatchEvent(new CustomEvent(type, init));
|
|
6124
6189
|
};
|
|
6125
6190
|
}
|
|
6126
|
-
function
|
|
6191
|
+
function batchUpdate(args, batch, method, context, event) {
|
|
6192
|
+
if (batch) {
|
|
6193
|
+
context.updateValues(args, method, arg => {
|
|
6194
|
+
return argsFactory(arg, context, event)[0];
|
|
6195
|
+
});
|
|
6196
|
+
} else {
|
|
6197
|
+
args.forEach(arg => {
|
|
6198
|
+
var {
|
|
6199
|
+
name,
|
|
6200
|
+
value
|
|
6201
|
+
} = argsFactory([arg], context, event)[0];
|
|
6202
|
+
context.updateValue(name, value, method);
|
|
6203
|
+
});
|
|
6204
|
+
}
|
|
6205
|
+
}
|
|
6206
|
+
function builtinContextListenerFactory(method, args, batch, ifContainer, callback, context, runtimeBrick) {
|
|
6127
6207
|
return function (event) {
|
|
6128
6208
|
if (!looseCheckIf(ifContainer, _objectSpread(_objectSpread({}, context), {}, {
|
|
6129
6209
|
event
|
|
@@ -6131,11 +6211,16 @@ function builtinContextListenerFactory(method, args, ifContainer, callback, cont
|
|
|
6131
6211
|
return;
|
|
6132
6212
|
}
|
|
6133
6213
|
var storyboardContext = _internalApiGetStoryboardContextWrapper();
|
|
6134
|
-
var
|
|
6135
|
-
|
|
6214
|
+
var isBatch = Array.isArray(args) && args.every(isObject);
|
|
6215
|
+
if (isBatch && (method === "assign" || method === "replace")) {
|
|
6216
|
+
batchUpdate(args, batch, method, storyboardContext, event);
|
|
6217
|
+
} else {
|
|
6218
|
+
var [name, value] = argsFactory(args, context, event);
|
|
6219
|
+
storyboardContext.updateValue(name, value, method, callback);
|
|
6220
|
+
}
|
|
6136
6221
|
};
|
|
6137
6222
|
}
|
|
6138
|
-
function builtinStateListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {
|
|
6223
|
+
function builtinStateListenerFactory(method, args, batch, ifContainer, callback, context, runtimeBrick) {
|
|
6139
6224
|
return function (event) {
|
|
6140
6225
|
if (!looseCheckIf(ifContainer, _objectSpread(_objectSpread({}, context), {}, {
|
|
6141
6226
|
event
|
|
@@ -6143,8 +6228,14 @@ function builtinStateListenerFactory(method, args, ifContainer, callback, contex
|
|
|
6143
6228
|
return;
|
|
6144
6229
|
}
|
|
6145
6230
|
var tplContext = getTplContext(context.tplContextId);
|
|
6146
|
-
var
|
|
6147
|
-
|
|
6231
|
+
var isBatch = Array.isArray(args) && args.every(isObject);
|
|
6232
|
+
var computedMethod = method === "update" ? "replace" : method;
|
|
6233
|
+
if (isBatch && computedMethod === "replace") {
|
|
6234
|
+
batchUpdate(args, batch, computedMethod, tplContext.state, event);
|
|
6235
|
+
} else {
|
|
6236
|
+
var [name, value] = argsFactory(args, context, event);
|
|
6237
|
+
tplContext.state.updateValue(name, value, computedMethod, callback);
|
|
6238
|
+
}
|
|
6148
6239
|
};
|
|
6149
6240
|
}
|
|
6150
6241
|
function builtinFormStateListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {
|