@next-core/brick-kit 2.170.0 → 2.171.1

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.
@@ -537,7 +537,7 @@
537
537
 
538
538
  // Omit all mutable methods from moment.
539
539
  var shouldOmitInMoment = new Set(["lang", "langData", "locale", "localeData", "defineLocale", "updateLocale", "updateOffset"]);
540
- var allowedGlobalObjects = new Set(["Array", "Boolean", "Date", "Infinity", "JSON", "Math", "NaN", "Number", "String", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "isFinite", "isNaN", "parseFloat", "parseInt", "Map", "Set", "URLSearchParams", "WeakMap", "WeakSet", "atob", "btoa"]);
540
+ var allowedGlobalObjects = new Set(["Array", "Boolean", "Date", "Infinity", "JSON", "Math", "NaN", "Number", "String", "RegExp", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "isFinite", "isNaN", "parseFloat", "parseInt", "Map", "Set", "URLSearchParams", "WeakMap", "WeakSet", "atob", "btoa"]);
541
541
  function supplyIndividual(variableName, mock) {
542
542
  switch (variableName) {
543
543
  case "Object":
@@ -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.formContextId ? "formstate.change" : this.tplContextId ? "state.change" : "context.change", {
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
- (_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.formContextId ? "formstate.change" : this.tplContextId ? "state.change" : "context.change", {
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(storyboardContextWrapper.formContextId ? "formstate.change" : storyboardContextWrapper.tplContextId ? "state.change" : "context.change", listenerFactory(handler, mergedContext, brick));
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(storyboardContextWrapper.formContextId ? "formstate.change" : isTemplateState ? "state.change" : "context.change", () => {
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 {
@@ -5936,6 +6000,7 @@
5936
6000
  };
5937
6001
  }
5938
6002
  function listenerFactory(handler, context, runtimeBrick) {
6003
+ var _handler$batch, _handler$batch2;
5939
6004
  if (isConditionalEventHandler(handler)) {
5940
6005
  return runConditionalEventHandler(handler, context, runtimeBrick);
5941
6006
  }
@@ -6004,11 +6069,11 @@
6004
6069
  case "context.replace":
6005
6070
  case "context.refresh":
6006
6071
  case "context.load":
6007
- 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);
6008
6073
  case "state.update":
6009
6074
  case "state.refresh":
6010
6075
  case "state.load":
6011
- 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);
6012
6077
  case "formstate.update":
6013
6078
  return builtinFormStateListenerFactory(method, handler.args, handler, handler.callback, context, runtimeBrick);
6014
6079
  case "tpl.dispatchEvent":
@@ -6122,7 +6187,22 @@
6122
6187
  tpl.dispatchEvent(new CustomEvent(type, init));
6123
6188
  };
6124
6189
  }
6125
- function builtinContextListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {
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) {
6126
6206
  return function (event) {
6127
6207
  if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
6128
6208
  event
@@ -6130,11 +6210,16 @@
6130
6210
  return;
6131
6211
  }
6132
6212
  var storyboardContext = _internalApiGetStoryboardContextWrapper();
6133
- var [name, value] = argsFactory(args, context, event);
6134
- storyboardContext.updateValue(name, value, method, callback);
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
+ }
6135
6220
  };
6136
6221
  }
6137
- function builtinStateListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {
6222
+ function builtinStateListenerFactory(method, args, batch, ifContainer, callback, context, runtimeBrick) {
6138
6223
  return function (event) {
6139
6224
  if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
6140
6225
  event
@@ -6142,8 +6227,14 @@
6142
6227
  return;
6143
6228
  }
6144
6229
  var tplContext = getTplContext(context.tplContextId);
6145
- var [name, value] = argsFactory(args, context, event);
6146
- tplContext.state.updateValue(name, value, method === "update" ? "replace" : method, callback);
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
+ }
6147
6238
  };
6148
6239
  }
6149
6240
  function builtinFormStateListenerFactory(method, args, ifContainer, callback, context, runtimeBrick) {