@next-core/runtime 1.16.0 → 1.17.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.
Files changed (42) hide show
  1. package/dist/cjs/createRoot.js +6 -1
  2. package/dist/cjs/createRoot.js.map +1 -1
  3. package/dist/cjs/internal/CustomTemplates/constants.js.map +1 -1
  4. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +7 -5
  5. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  6. package/dist/cjs/internal/Renderer.js +3 -5
  7. package/dist/cjs/internal/Renderer.js.map +1 -1
  8. package/dist/cjs/internal/Router.js +6 -1
  9. package/dist/cjs/internal/Router.js.map +1 -1
  10. package/dist/cjs/internal/Runtime.js.map +1 -1
  11. package/dist/cjs/internal/compute/computeRealProperties.js +27 -38
  12. package/dist/cjs/internal/compute/computeRealProperties.js.map +1 -1
  13. package/dist/cjs/internal/data/DataStore.js +31 -11
  14. package/dist/cjs/internal/data/DataStore.js.map +1 -1
  15. package/dist/cjs/internal/interfaces.js.map +1 -1
  16. package/dist/cjs/internal/secret_internals.js +9 -3
  17. package/dist/cjs/internal/secret_internals.js.map +1 -1
  18. package/dist/esm/createRoot.js +6 -1
  19. package/dist/esm/createRoot.js.map +1 -1
  20. package/dist/esm/internal/CustomTemplates/constants.js.map +1 -1
  21. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +23 -15
  22. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  23. package/dist/esm/internal/Renderer.js +4 -6
  24. package/dist/esm/internal/Renderer.js.map +1 -1
  25. package/dist/esm/internal/Router.js +6 -1
  26. package/dist/esm/internal/Router.js.map +1 -1
  27. package/dist/esm/internal/Runtime.js.map +1 -1
  28. package/dist/esm/internal/compute/computeRealProperties.js +47 -58
  29. package/dist/esm/internal/compute/computeRealProperties.js.map +1 -1
  30. package/dist/esm/internal/data/DataStore.js +31 -11
  31. package/dist/esm/internal/data/DataStore.js.map +1 -1
  32. package/dist/esm/internal/interfaces.js.map +1 -1
  33. package/dist/esm/internal/secret_internals.js +9 -3
  34. package/dist/esm/internal/secret_internals.js.map +1 -1
  35. package/dist/types/internal/CustomTemplates/constants.d.ts +2 -2
  36. package/dist/types/internal/CustomTemplates/setupTemplateProxy.d.ts +2 -2
  37. package/dist/types/internal/Runtime.d.ts +2 -2
  38. package/dist/types/internal/compute/computeRealProperties.d.ts +4 -3
  39. package/dist/types/internal/data/DataStore.d.ts +3 -0
  40. package/dist/types/internal/interfaces.d.ts +3 -2
  41. package/dist/types/internal/secret_internals.d.ts +3 -1
  42. package/package.json +6 -6
@@ -3,71 +3,60 @@ import { isObject } from "@next-core/utils/general";
3
3
  import { asyncComputeRealValue, computeRealValue } from "./computeRealValue.js";
4
4
  import { StateOfUseBrick } from "./getNextStateOfUseBrick.js";
5
5
  import { getTracks } from "./getTracks.js";
6
- export function asyncComputeRealProperties(_x, _x2, _x3) {
7
- return _asyncComputeRealProperties.apply(this, arguments);
8
- }
9
- function _asyncComputeRealProperties() {
10
- _asyncComputeRealProperties = _asyncToGenerator(function* (properties, runtimeContext, trackingContextList) {
11
- if (isObject(properties)) {
12
- return Object.fromEntries((yield Promise.all(Object.entries(properties).map( /*#__PURE__*/function () {
13
- var _ref3 = _asyncToGenerator(function* (_ref2) {
14
- var [propName, propValue] = _ref2;
15
- if (Array.isArray(trackingContextList)) {
16
- var {
17
- contextNames,
18
- stateNames,
19
- formStateNames
20
- } = getTracks(propValue);
21
- if (contextNames || stateNames || formStateNames) {
22
- trackingContextList.push({
23
- contextNames,
24
- stateNames,
25
- formStateNames,
26
- propName,
27
- propValue
28
- });
29
- }
30
- }
31
- // Related: https://github.com/facebook/react/issues/11347
32
- var realValue = yield asyncComputeRealValue(propValue, runtimeContext, {
33
- $$lazyForUseBrick: true,
34
- $$stateOfUseBrick: propName === "useBrick" ? StateOfUseBrick.USE_BRICK : StateOfUseBrick.INITIAL
35
- });
36
- // For `style` and `dataset`, only object is acceptable.
37
- if (propName !== "style" && propName !== "dataset" || isObject(realValue)) {
38
- return [propName, realValue];
39
- }
40
- });
41
- return function (_x4) {
42
- return _ref3.apply(this, arguments);
43
- };
44
- }()))).filter(Boolean));
45
- }
46
- return {};
47
- });
48
- return _asyncComputeRealProperties.apply(this, arguments);
49
- }
50
- export function computeRealProperties(properties, runtimeContext, trackingContextList) {
6
+ export function asyncComputeRealProperties(properties, runtimeContext, trackingContextList) {
51
7
  if (isObject(properties)) {
52
8
  return Object.fromEntries(Object.entries(properties).map(_ref => {
53
9
  var [propName, propValue] = _ref;
54
- if (Array.isArray(trackingContextList)) {
55
- var {
10
+ var {
11
+ contextNames,
12
+ stateNames,
13
+ formStateNames
14
+ } = getTracks(propValue);
15
+ if (contextNames || stateNames || formStateNames) {
16
+ trackingContextList.push({
56
17
  contextNames,
57
18
  stateNames,
58
- formStateNames
59
- } = getTracks(propValue);
60
- if (contextNames || stateNames || formStateNames) {
61
- trackingContextList.push({
62
- contextNames,
63
- stateNames,
64
- formStateNames,
65
- propName,
66
- propValue
67
- });
68
- }
19
+ formStateNames,
20
+ propName,
21
+ propValue
22
+ });
69
23
  }
70
24
  // Related: https://github.com/facebook/react/issues/11347
25
+ var asyncValue = asyncComputeRealValue(propValue, runtimeContext, {
26
+ $$lazyForUseBrick: true,
27
+ $$stateOfUseBrick: propName === "useBrick" ? StateOfUseBrick.USE_BRICK : StateOfUseBrick.INITIAL
28
+ });
29
+ return [propName, asyncValue];
30
+ }));
31
+ }
32
+ return {};
33
+ }
34
+ export function constructAsyncProperties(_x) {
35
+ return _constructAsyncProperties.apply(this, arguments);
36
+ }
37
+ function _constructAsyncProperties() {
38
+ _constructAsyncProperties = _asyncToGenerator(function* (asyncProperties) {
39
+ return Object.fromEntries((yield Promise.all(Object.entries(asyncProperties).map( /*#__PURE__*/function () {
40
+ var _ref4 = _asyncToGenerator(function* (_ref3) {
41
+ var [propName, asyncValue] = _ref3;
42
+ var value = yield asyncValue;
43
+ // For `style` and `dataset`, only object is acceptable.
44
+ if (propName !== "style" && propName !== "dataset" || isObject(value)) {
45
+ return [propName, value];
46
+ }
47
+ });
48
+ return function (_x2) {
49
+ return _ref4.apply(this, arguments);
50
+ };
51
+ }()))).filter(Boolean));
52
+ });
53
+ return _constructAsyncProperties.apply(this, arguments);
54
+ }
55
+ export function computeRealProperties(properties, runtimeContext) {
56
+ if (isObject(properties)) {
57
+ return Object.fromEntries(Object.entries(properties).map(_ref2 => {
58
+ var [propName, propValue] = _ref2;
59
+ // Related: https://github.com/facebook/react/issues/11347
71
60
  var realValue = computeRealValue(propValue, runtimeContext, {
72
61
  $$lazyForUseBrick: true,
73
62
  $$stateOfUseBrick: propName === "useBrick" ? StateOfUseBrick.USE_BRICK : StateOfUseBrick.INITIAL
@@ -1 +1 @@
1
- {"version":3,"file":"computeRealProperties.js","names":["isObject","asyncComputeRealValue","computeRealValue","StateOfUseBrick","getTracks","asyncComputeRealProperties","_x","_x2","_x3","_asyncComputeRealProperties","apply","arguments","_asyncToGenerator","properties","runtimeContext","trackingContextList","Object","fromEntries","Promise","all","entries","map","_ref3","_ref2","propName","propValue","Array","isArray","contextNames","stateNames","formStateNames","push","realValue","$$lazyForUseBrick","$$stateOfUseBrick","USE_BRICK","INITIAL","_x4","filter","Boolean","computeRealProperties","_ref"],"sources":["../../../../src/internal/compute/computeRealProperties.ts"],"sourcesContent":["import { isObject } from \"@next-core/utils/general\";\nimport { asyncComputeRealValue, computeRealValue } from \"./computeRealValue.js\";\nimport { TrackingContextItem } from \"./listenOnTrackingContext.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\nimport { StateOfUseBrick } from \"./getNextStateOfUseBrick.js\";\nimport { getTracks } from \"./getTracks.js\";\n\nexport async function asyncComputeRealProperties(\n properties: Record<string, unknown> | undefined,\n runtimeContext: RuntimeContext,\n trackingContextList?: TrackingContextItem[]\n): Promise<Record<string, unknown>> {\n if (isObject(properties)) {\n return Object.fromEntries(\n (\n await Promise.all(\n Object.entries(properties).map<\n Promise<[string, unknown] | undefined>\n >(async ([propName, propValue]) => {\n if (Array.isArray(trackingContextList)) {\n const { contextNames, stateNames, formStateNames } =\n getTracks(propValue);\n if (contextNames || stateNames || formStateNames) {\n trackingContextList.push({\n contextNames,\n stateNames,\n formStateNames,\n propName,\n propValue,\n });\n }\n }\n // Related: https://github.com/facebook/react/issues/11347\n const realValue = await asyncComputeRealValue(\n propValue,\n runtimeContext,\n {\n $$lazyForUseBrick: true,\n $$stateOfUseBrick:\n propName === \"useBrick\"\n ? StateOfUseBrick.USE_BRICK\n : StateOfUseBrick.INITIAL,\n }\n );\n // For `style` and `dataset`, only object is acceptable.\n if (\n (propName !== \"style\" && propName !== \"dataset\") ||\n isObject(realValue)\n ) {\n return [propName, realValue];\n }\n })\n )\n ).filter(Boolean) as [string, unknown][]\n );\n }\n\n return {};\n}\n\nexport function computeRealProperties(\n properties: Record<string, unknown> | undefined,\n runtimeContext: RuntimeContext,\n trackingContextList?: TrackingContextItem[]\n): Record<string, unknown> {\n if (isObject(properties)) {\n return Object.fromEntries(\n Object.entries(properties)\n .map<[string, unknown] | undefined>(([propName, propValue]) => {\n if (Array.isArray(trackingContextList)) {\n const { contextNames, stateNames, formStateNames } =\n getTracks(propValue);\n if (contextNames || stateNames || formStateNames) {\n trackingContextList.push({\n contextNames,\n stateNames,\n formStateNames,\n propName,\n propValue,\n });\n }\n }\n // Related: https://github.com/facebook/react/issues/11347\n const realValue = computeRealValue(propValue, runtimeContext, {\n $$lazyForUseBrick: true,\n $$stateOfUseBrick:\n propName === \"useBrick\"\n ? StateOfUseBrick.USE_BRICK\n : StateOfUseBrick.INITIAL,\n });\n // For `style` and `dataset`, only object is acceptable.\n if (\n (propName !== \"style\" && propName !== \"dataset\") ||\n isObject(realValue)\n ) {\n return [propName, realValue];\n }\n })\n .filter(Boolean) as [string, unknown][]\n );\n }\n\n return {};\n}\n"],"mappings":";AAAA,SAASA,QAAQ,QAAQ,0BAA0B;AACnD,SAASC,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AAS,CAAC,EACnB;QACA,OAAO,CAACR,QAAQ,EAAEQ,SAAS,CAAC;MAC9B;IACF,CAAC,CAAC,CACDM,MAAM,CAACC,OAAO,CACnB,CAAC;EACH;EAEA,OAAO,CAAC,CAAC;AACX"}
1
+ {"version":3,"file":"computeRealProperties.js","names":["isObject","asyncComputeRealValue","computeRealValue","StateOfUseBrick","getTracks","asyncComputeRealProperties","properties","runtimeContext","trackingContextList","Object","fromEntries","entries","map","_ref","propName","propValue","contextNames","stateNames","formStateNames","push","asyncValue","$$lazyForUseBrick","$$stateOfUseBrick","USE_BRICK","INITIAL","constructAsyncProperties","_x","_constructAsyncProperties","apply","arguments","_asyncToGenerator","asyncProperties","Promise","all","_ref4","_ref3","value","_x2","filter","Boolean","computeRealProperties","_ref2","realValue"],"sources":["../../../../src/internal/compute/computeRealProperties.ts"],"sourcesContent":["import { isObject } from \"@next-core/utils/general\";\nimport { asyncComputeRealValue, computeRealValue } from \"./computeRealValue.js\";\nimport { TrackingContextItem } from \"./listenOnTrackingContext.js\";\nimport type { AsyncProperties, RuntimeContext } from \"../interfaces.js\";\nimport { StateOfUseBrick } from \"./getNextStateOfUseBrick.js\";\nimport { getTracks } from \"./getTracks.js\";\n\nexport function asyncComputeRealProperties(\n properties: Record<string, unknown> | undefined,\n runtimeContext: RuntimeContext,\n trackingContextList: TrackingContextItem[]\n): AsyncProperties {\n if (isObject(properties)) {\n return Object.fromEntries(\n Object.entries(properties).map<[string, Promise<unknown>]>(\n ([propName, propValue]) => {\n const { contextNames, stateNames, formStateNames } =\n getTracks(propValue);\n if (contextNames || stateNames || formStateNames) {\n trackingContextList.push({\n contextNames,\n stateNames,\n formStateNames,\n propName,\n propValue,\n });\n }\n // Related: https://github.com/facebook/react/issues/11347\n const asyncValue = asyncComputeRealValue(propValue, runtimeContext, {\n $$lazyForUseBrick: true,\n $$stateOfUseBrick:\n propName === \"useBrick\"\n ? StateOfUseBrick.USE_BRICK\n : StateOfUseBrick.INITIAL,\n });\n return [propName, asyncValue];\n }\n )\n );\n }\n\n return {};\n}\n\nexport async function constructAsyncProperties(\n asyncProperties: AsyncProperties\n): Promise<Record<string, unknown>> {\n return Object.fromEntries(\n (\n await Promise.all(\n Object.entries(asyncProperties).map(async ([propName, asyncValue]) => {\n const value = await asyncValue;\n // For `style` and `dataset`, only object is acceptable.\n if (\n (propName !== \"style\" && propName !== \"dataset\") ||\n isObject(value)\n ) {\n return [propName, value];\n }\n })\n )\n ).filter(Boolean) as [string, unknown][]\n );\n}\n\nexport function computeRealProperties(\n properties: Record<string, unknown> | undefined,\n runtimeContext: RuntimeContext\n): Record<string, unknown> {\n if (isObject(properties)) {\n return Object.fromEntries(\n Object.entries(properties)\n .map<[string, unknown] | undefined>(([propName, propValue]) => {\n // Related: https://github.com/facebook/react/issues/11347\n const realValue = computeRealValue(propValue, runtimeContext, {\n $$lazyForUseBrick: true,\n $$stateOfUseBrick:\n propName === \"useBrick\"\n ? StateOfUseBrick.USE_BRICK\n : StateOfUseBrick.INITIAL,\n });\n // For `style` and `dataset`, only object is acceptable.\n if (\n (propName !== \"style\" && propName !== \"dataset\") ||\n isObject(realValue)\n ) {\n return [propName, realValue];\n }\n })\n .filter(Boolean) as [string, unknown][]\n );\n }\n\n return {};\n}\n"],"mappings":";AAAA,SAASA,QAAQ,QAAQ,0BAA0B;AACnD,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,uBAAuB;AAG/E,SAASC,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,SAAS,QAAQ,gBAAgB;AAE1C,OAAO,SAASC,0BAA0BA,CACxCC,UAA+C,EAC/CC,cAA8B,EAC9BC,mBAA0C,EACzB;EACjB,IAAIR,QAAQ,CAACM,UAAU,CAAC,EAAE;IACxB,OAAOG,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACL,UAAU,CAAC,CAACM,GAAG,CAC5BC,IAAA,IAA2B;MAAA,IAA1B,CAACC,QAAQ,EAAEC,SAAS,CAAC,GAAAF,I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OAAAC,SAAA;MAAA;IAAA,IACH,CAAC,EACDS,MAAM,CAACC,OAAO,CAClB,CAAC;EACH,CAAC;EAAA,OAAAZ,yBAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAED,OAAO,SAASW,qBAAqBA,CACnClC,UAA+C,EAC/CC,cAA8B,EACL;EACzB,IAAIP,QAAQ,CAACM,UAAU,CAAC,EAAE;IACxB,OAAOG,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACL,UAAU,CAAC,CACvBM,GAAG,CAAgC6B,KAAA,IAA2B;MAAA,IAA1B,CAAC3B,QAAQ,EAAEC,SAAS,CAAC,GAAA0B,KAAA;MACxD;MACA,IAAMC,SAAS,GAAGxC,gBAAgB,CAACa,SAAS,EAAER,cAAc,EAAE;QAC5Dc,iBAAiB,EAAE,IAAI;QACvBC,iBAAiB,EACfR,QAAQ,KAAK,UAAU,GACnBX,eAAe,CAACoB,SAAS,GACzBpB,eAAe,CAACqB;MACxB,CAAC,CAAC;MACF;MACA,IACGV,QAAQ,KAAK,OAAO,IAAIA,QAAQ,KAAK,SAAS,IAC/Cd,QAAQ,CAAC0C,SAAS,CAAC,EACnB;QACA,OAAO,CAAC5B,QAAQ,EAAE4B,SAAS,CAAC;MAC9B;IACF,CAAC,CAAC,CACDJ,MAAM,CAACC,OAAO,CACnB,CAAC;EACH;EAEA,OAAO,CAAC,CAAC;AACX"}
@@ -180,6 +180,23 @@ export class DataStore {
180
180
  }
181
181
  })();
182
182
  }
183
+
184
+ /** After mount, dispatch the change event when an async data is loaded */
185
+ handleAsyncAfterMount() {
186
+ this.data.forEach(item => {
187
+ if (item.async) {
188
+ // An async data always has `loading`
189
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
190
+ item.loading.then(value => {
191
+ item.loaded = true;
192
+ item.value = value;
193
+ item.eventTarget.dispatchEvent(new CustomEvent(this.changeEventType, {
194
+ detail: value
195
+ }));
196
+ });
197
+ }
198
+ });
199
+ }
183
200
  resolve(dataConf, runtimeContext, asyncHostProperties) {
184
201
  var _this3 = this;
185
202
  return _asyncToGenerator(function* () {
@@ -187,14 +204,12 @@ export class DataStore {
187
204
  return false;
188
205
  }
189
206
  var value;
190
- if (asyncHostProperties && (_this3.type === "STATE" ? dataConf.expose : _this3.type === "FORM_STATE")) {
191
- var hostProps = yield asyncHostProperties;
192
- if (hasOwnProperty(hostProps, dataConf.name)) {
193
- value = hostProps[dataConf.name];
194
- }
207
+ if (asyncHostProperties && (_this3.type === "STATE" ? dataConf.expose : _this3.type === "FORM_STATE") && hasOwnProperty(asyncHostProperties, dataConf.name)) {
208
+ value = yield asyncHostProperties[dataConf.name];
195
209
  }
196
210
  var load;
197
- var isLazyResolve = false;
211
+ var loading;
212
+ var resolvePolicy = "eager";
198
213
  if (value === undefined) {
199
214
  if (dataConf.resolve) {
200
215
  var resolveConf = _objectSpread({
@@ -209,15 +224,18 @@ export class DataStore {
209
224
  return _ref.apply(this, arguments);
210
225
  };
211
226
  }();
212
- isLazyResolve = dataConf.resolve.lazy;
213
- if (!isLazyResolve) {
227
+ // `async` take precedence over `lazy`
228
+ resolvePolicy = dataConf.resolve.async ? "async" : dataConf.resolve.lazy ? "lazy" : "eager";
229
+ if (resolvePolicy === "eager") {
214
230
  value = yield load();
231
+ } else if (resolvePolicy === "async") {
232
+ loading = load();
215
233
  }
216
234
  } else if (!hasOwnProperty(dataConf, "value")) {
217
235
  return false;
218
236
  }
219
237
  }
220
- if ((!load || isLazyResolve) && dataConf.value !== undefined) {
238
+ if ((!load || resolvePolicy !== "eager") && dataConf.value !== undefined) {
221
239
  // If the context has no resolve, just use its `value`.
222
240
  // Or if the resolve is ignored or lazy, use its `value` as a fallback.
223
241
  value = yield asyncComputeRealValue(dataConf.value, runtimeContext);
@@ -228,10 +246,12 @@ export class DataStore {
228
246
  // This is required for tracking context, even if no `onChange` is specified.
229
247
  eventTarget: new EventTarget(),
230
248
  load,
231
- loaded: !isLazyResolve,
249
+ loaded: resolvePolicy === "eager",
250
+ loading,
251
+ async: resolvePolicy === "async",
232
252
  deps: []
233
253
  };
234
- if (isLazyResolve) {
254
+ if (resolvePolicy === "lazy") {
235
255
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
236
256
  var {
237
257
  trigger
@@ -1 +1 @@
1
- {"version":3,"file":"DataStore.js","names":["hasOwnProperty","isObject","strictCollectMemberUsage","eventCallbackFactory","listenerFactory","asyncCheckIf","asyncComputeRealValue","computeRealValue","resolveData","resolveDataStore","handleHttpError","supportContextResolveTriggerBrickLifeCycle","DataStore","constructor","type","hostBrick","rendererContext","_defineProperty","Map","changeEventType","getValue","name","_this$data$get","data","get","value","getAffectListByContext","affectNames","forEach","key","deps","isInDeps","some","item","includes","push","shift","Set","updateValues","values","method","argsFactory","batchUpdate","batchUpdateContextsNames","map","length","Error","updateContexts","affectContexts","affectDepsContextNames","arg","updateContextItem","updateValue","filter","affectContextItem","triggerEvent","contexts","_context$eventTarget","context","eventTarget","dispatchEvent","CustomEvent","detail","callback","callbackRuntimeContext","concat","load","promise","loaded","Promise","resolve","loading","_objectSpread","cache","then","val","err","error","callbackFactory","Object","assign","console","warn","define","dataConfs","runtimeContext","asyncHostProperties","Array","isArray","pending","dataConf","pendingStack","onChange","dataName","listener","_this$data$get2","addEventListener","waitFor","dataNames","_this","_asyncToGenerator","_loop","pendingContexts","all","ctx","p","waitForAll","_this2","pendingResult","_this3","expose","hostProps","isLazyResolve","undefined","resolveConf","transform","_ref","options","_x","apply","arguments","lazy","newData","EventTarget","trigger","_this3$rendererContex","registerArbitraryLifeCycle","track","dep","batchAddListener","has","set","contextConf","event"],"sources":["../../../../src/internal/data/DataStore.ts"],"sourcesContent":["import type {\n BatchUpdateContextItem,\n BrickEventHandlerCallback,\n ContextConf,\n ContextResolveTriggerBrickLifeCycle,\n} from \"@next-core/types\";\nimport { hasOwnProperty, isObject } from \"@next-core/utils/general\";\nimport { strictCollectMemberUsage } from \"@next-core/utils/storyboard\";\nimport { eventCallbackFactory, listenerFactory } from \"../bindListeners.js\";\nimport { asyncCheckIf } from \"../compute/checkIf.js\";\nimport {\n asyncComputeRealValue,\n computeRealValue,\n} from \"../compute/computeRealValue.js\";\nimport { ResolveOptions, resolveData } from \"./resolveData.js\";\nimport { resolveDataStore } from \"./resolveDataStore.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n RuntimeContext,\n} from \"../interfaces.js\";\nimport { handleHttpError } from \"../../handleHttpError.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst supportContextResolveTriggerBrickLifeCycle = [\n \"onBeforePageLoad\",\n \"onPageLoad\",\n \"onBeforePageLeave\",\n \"onPageLeave\",\n \"onAnchorLoad\",\n \"onAnchorUnload\",\n] as ContextResolveTriggerBrickLifeCycle[];\n\nexport type DataStoreType = \"CTX\" | \"STATE\" | \"FORM_STATE\";\n\nexport interface DataStoreItem {\n value: unknown;\n eventTarget: EventTarget;\n loaded?: boolean;\n loading?: Promise<unknown>;\n load?: (options?: ResolveOptions) => Promise<unknown>;\n deps: string[];\n}\n\nexport class DataStore<T extends DataStoreType = \"CTX\"> {\n private readonly type: T;\n private readonly data = new Map<string, DataStoreItem>();\n private readonly changeEventType: string;\n private readonly pendingStack: Array<ReturnType<typeof resolveDataStore>> =\n [];\n public readonly hostBrick?: RuntimeBrick;\n public batchUpdate = false;\n public batchUpdateContextsNames: string[] = [];\n private readonly rendererContext?: RendererContext;\n\n // 把 `rendererContext` 放在参数列表的最后,并作为可选,以减少测试文件的调整\n constructor(\n type: T,\n hostBrick?: RuntimeBrick,\n rendererContext?: RendererContext\n ) {\n this.type = type;\n this.changeEventType =\n this.type === \"FORM_STATE\"\n ? \"formstate.change\"\n : this.type === \"STATE\"\n ? \"state.change\"\n : \"context.change\";\n this.hostBrick = hostBrick;\n this.rendererContext = rendererContext;\n }\n\n getValue(name: string): unknown {\n return this.data.get(name)?.value;\n }\n\n private getAffectListByContext(name: string): string[] {\n const affectNames = [name];\n this.data.forEach((value, key) => {\n if (value.deps) {\n const isInDeps = value.deps.some((item) => affectNames.includes(item));\n isInDeps &&\n affectNames.push(key) &&\n affectNames.push(...this.getAffectListByContext(key));\n }\n });\n affectNames.shift();\n return [...new Set(affectNames)];\n }\n\n updateValues(\n values: BatchUpdateContextItem[],\n method: \"assign\" | \"replace\",\n argsFactory: (arg: unknown[]) => BatchUpdateContextItem\n ): void {\n this.batchUpdate = true;\n this.batchUpdateContextsNames = values.map((item) => item.name);\n if (\n [...new Set(this.batchUpdateContextsNames)].length !==\n this.batchUpdateContextsNames.length\n ) {\n throw new Error(`Batch update not allow to update same item`);\n }\n\n const updateContexts: Record<string, DataStoreItem> = {};\n const affectContexts: Record<string, DataStoreItem> = {};\n const affectDepsContextNames: string[] = [];\n\n values.forEach((arg) => {\n const { name, value } = argsFactory([arg]);\n const updateContextItem = this.data.get(name);\n affectDepsContextNames.push(...this.getAffectListByContext(name));\n updateContextItem && (updateContexts[name] = updateContextItem);\n this.updateValue(name as string, value, method);\n });\n\n affectDepsContextNames\n .filter((item) => !updateContexts[item])\n .forEach((name) => {\n const affectContextItem = this.data.get(name);\n affectContextItem && (affectContexts[name] = affectContextItem);\n });\n\n const triggerEvent = (contexts: Record<string, DataStoreItem>): void => {\n for (const key in contexts) {\n const context = contexts[key];\n context.eventTarget?.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: context.value,\n })\n );\n }\n };\n\n triggerEvent(updateContexts);\n triggerEvent(affectContexts);\n\n this.batchUpdate = false;\n\n return;\n }\n\n updateValue(\n name: string,\n value: unknown,\n method: \"assign\" | \"replace\" | \"refresh\" | \"load\",\n callback?: BrickEventHandlerCallback,\n callbackRuntimeContext?: RuntimeContext\n ): void {\n const item = this.data.get(name);\n if (!item) {\n throw new Error(`${this.type} '${name}' is not defined`);\n }\n\n if (method === \"refresh\" || method === \"load\") {\n if (!item.load) {\n throw new Error(\n `You can not ${method} \"${this.type}.${name}\" which has no resolve`\n );\n }\n\n let promise: Promise<unknown> | undefined;\n if (method === \"load\") {\n // Try to reuse previous request when calling `load`.\n if (item.loaded) {\n promise = Promise.resolve(item.value);\n } else if (item.loading) {\n promise = item.loading;\n }\n }\n\n if (!promise) {\n promise = item.loading = item.load({\n cache: method === \"load\" ? \"default\" : \"reload\",\n ...(value as ResolveOptions),\n });\n // Do not use the chained promise, since the callbacks need the original promise.\n promise.then(\n (val) => {\n item.loaded = true;\n item.value = val;\n item.eventTarget.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: item.value,\n })\n );\n },\n (err) => {\n // Let users override error handling.\n if (!callback?.error) {\n handleHttpError(err);\n }\n }\n );\n }\n\n if (callback) {\n const callbackFactory = eventCallbackFactory(\n callback,\n callbackRuntimeContext!\n );\n\n promise.then(\n (val) => {\n callbackFactory(\"success\")({ value: val });\n callbackFactory(\"finally\")();\n },\n (err) => {\n callbackFactory(\"error\")(err);\n callbackFactory(\"finally\")();\n }\n );\n }\n\n return;\n }\n\n if (method === \"replace\") {\n item.value = value;\n } else {\n if (isObject(item.value)) {\n Object.assign(item.value, value);\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n `Non-object current value of \"${this.type}.${name}\" for \"context.assign\", try \"context.replace\" instead.`\n );\n item.value = value;\n }\n }\n\n if (this.batchUpdate) return;\n\n item.eventTarget.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: item.value,\n })\n );\n }\n\n define(\n dataConfs: ContextConf[] | undefined,\n runtimeContext: RuntimeContext,\n asyncHostProperties?: AsyncProperties\n ): void {\n if (Array.isArray(dataConfs) && dataConfs.length > 0) {\n const pending = resolveDataStore(\n dataConfs,\n (dataConf: ContextConf) =>\n this.resolve(dataConf, runtimeContext, asyncHostProperties),\n this.type\n );\n this.pendingStack.push(pending);\n }\n }\n\n onChange(dataName: string, listener: EventListener): void {\n this.data\n .get(dataName)\n ?.eventTarget.addEventListener(this.changeEventType, listener);\n }\n\n async waitFor(dataNames: string[] | Set<string>): Promise<void> {\n for (const { pendingContexts } of this.pendingStack) {\n await Promise.all(\n [...dataNames].map((ctx) => {\n const p = pendingContexts.get(ctx);\n return p;\n })\n );\n }\n }\n\n async waitForAll(): Promise<void> {\n for (const { pendingResult } of this.pendingStack) {\n await pendingResult;\n }\n }\n\n private async resolve(\n dataConf: ContextConf,\n runtimeContext: RuntimeContext,\n asyncHostProperties?: AsyncProperties\n ): Promise<boolean> {\n if (!(await asyncCheckIf(dataConf, runtimeContext))) {\n return false;\n }\n let value: unknown;\n if (\n asyncHostProperties &&\n (this.type === \"STATE\" ? dataConf.expose : this.type === \"FORM_STATE\")\n ) {\n const hostProps = await asyncHostProperties;\n if (hasOwnProperty(hostProps, dataConf.name)) {\n value = hostProps[dataConf.name];\n }\n }\n let load: DataStoreItem[\"load\"];\n let isLazyResolve: boolean | undefined = false;\n if (value === undefined) {\n if (dataConf.resolve) {\n const resolveConf = {\n transform: \"value\",\n ...dataConf.resolve,\n };\n if (await asyncCheckIf(dataConf.resolve, runtimeContext)) {\n load = async (options) =>\n (\n (await resolveData(resolveConf, runtimeContext, options)) as {\n value: unknown;\n }\n ).value;\n isLazyResolve = dataConf.resolve.lazy;\n if (!isLazyResolve) {\n value = await load();\n }\n } else if (!hasOwnProperty(dataConf, \"value\")) {\n return false;\n }\n }\n if ((!load || isLazyResolve) && dataConf.value !== undefined) {\n // If the context has no resolve, just use its `value`.\n // Or if the resolve is ignored or lazy, use its `value` as a fallback.\n value = await asyncComputeRealValue(dataConf.value, runtimeContext);\n }\n }\n\n const newData: DataStoreItem = {\n value,\n // This is required for tracking context, even if no `onChange` is specified.\n eventTarget: new EventTarget(),\n load,\n loaded: !isLazyResolve,\n deps: [],\n };\n\n if (isLazyResolve) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { trigger } = dataConf.resolve!;\n if (\n trigger &&\n supportContextResolveTriggerBrickLifeCycle.includes(trigger)\n ) {\n this.rendererContext?.registerArbitraryLifeCycle(trigger, () => {\n this.updateValue(dataConf.name, undefined, \"load\");\n });\n }\n }\n\n if (dataConf.onChange) {\n newData.eventTarget.addEventListener(\n this.changeEventType,\n listenerFactory(dataConf.onChange, runtimeContext)\n );\n }\n\n if (dataConf.track) {\n const deps = strictCollectMemberUsage(\n load ? dataConf.resolve : dataConf.value,\n this.type\n );\n !load && (newData.deps = [...deps]);\n for (const dep of deps) {\n this.onChange(\n dep,\n this.batchAddListener(() => {\n if (load) {\n this.updateValue(dataConf.name, { cache: \"default\" }, \"refresh\");\n } else {\n this.updateValue(\n dataConf.name,\n computeRealValue(dataConf.value, runtimeContext),\n \"replace\"\n );\n }\n }, dataConf)\n );\n }\n }\n\n if (this.data.has(dataConf.name)) {\n throw new Error(\n `${this.type} '${dataConf.name}' has already been declared`\n );\n }\n this.data.set(dataConf.name, newData);\n\n return true;\n }\n\n private batchAddListener(\n listener: EventListener,\n contextConf: ContextConf\n ): EventListener {\n return (event: Event | CustomEvent): void => {\n if (\n this.batchUpdate &&\n this.batchUpdateContextsNames.includes(contextConf.name)\n ) {\n return;\n }\n listener(event);\n };\n }\n}\n"],"mappings":";;;AAMA,SAASA,cAAc,EAAEC,QAAQ,QAAQ,0BAA0B;AACnE,SAASC,wBAAwB,QAAQ,6BAA6B;AACtE,SAASC,oBAAoB,EAAEC,eAAe,QAAQ,qBAAqB;AAC3E,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SACEC,qBAAqB,EACrBC,gBAAgB,QACX,gCAAgC;AACvC,SAAyBC,WAAW,QAAQ,kBAAkB;AAC9D,SAASC,gBAAgB,QAAQ,uBAAuB;AAMxD,SAASC,eAAe,QAAQ,0BAA0B;AAG1D,IAAMC,0CAA0C,GAAG,CACjD,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,gBAAgB,CACwB;AAa1C,OAAO,MAAMC,SAAS,CAAkC;EAWtD;EACAC,WAAWA,CACTC,IAAO,EACPC,SAAwB,EACxBC,eAAiC,EACjC;IAAAC,eAAA;IAAAA,eAAA,eAdsB,IAAIC,GAAG,CAAwB,CAAC;IAA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IAAI,QAAAmD,MAAA,CAAKyB,QAAQ,CAACrE,IAAI,gCAChC,CAAC;MACH;MACAwF,MAAI,CAACtF,IAAI,CAAC4G,GAAG,CAACzC,QAAQ,CAACrE,IAAI,EAAEqG,OAAO,CAAC;MAErC,OAAO,IAAI;IAAC;EACd;EAEQO,gBAAgBA,CACtBnC,QAAuB,EACvBsC,WAAwB,EACT;IACf,OAAQC,KAA0B,IAAW;MAC3C,IACE,IAAI,CAAC3F,WAAW,IAChB,IAAI,CAACC,wBAAwB,CAACT,QAAQ,CAACkG,WAAW,CAAC/G,IAAI,CAAC,EACxD;QACA;MACF;MACAyE,QAAQ,CAACuC,KAAK,CAAC;IACjB,CAAC;EACH;AACF"}
1
+ {"version":3,"file":"DataStore.js","names":["hasOwnProperty","isObject","strictCollectMemberUsage","eventCallbackFactory","listenerFactory","asyncCheckIf","asyncComputeRealValue","computeRealValue","resolveData","resolveDataStore","handleHttpError","supportContextResolveTriggerBrickLifeCycle","DataStore","constructor","type","hostBrick","rendererContext","_defineProperty","Map","changeEventType","getValue","name","_this$data$get","data","get","value","getAffectListByContext","affectNames","forEach","key","deps","isInDeps","some","item","includes","push","shift","Set","updateValues","values","method","argsFactory","batchUpdate","batchUpdateContextsNames","map","length","Error","updateContexts","affectContexts","affectDepsContextNames","arg","updateContextItem","updateValue","filter","affectContextItem","triggerEvent","contexts","_context$eventTarget","context","eventTarget","dispatchEvent","CustomEvent","detail","callback","callbackRuntimeContext","concat","load","promise","loaded","Promise","resolve","loading","_objectSpread","cache","then","val","err","error","callbackFactory","Object","assign","console","warn","define","dataConfs","runtimeContext","asyncHostProperties","Array","isArray","pending","dataConf","pendingStack","onChange","dataName","listener","_this$data$get2","addEventListener","waitFor","dataNames","_this","_asyncToGenerator","_loop","pendingContexts","all","ctx","p","waitForAll","_this2","pendingResult","handleAsyncAfterMount","async","_this3","expose","resolvePolicy","undefined","resolveConf","transform","_ref","options","_x","apply","arguments","lazy","newData","EventTarget","trigger","_this3$rendererContex","registerArbitraryLifeCycle","track","dep","batchAddListener","has","set","contextConf","event"],"sources":["../../../../src/internal/data/DataStore.ts"],"sourcesContent":["import type {\n BatchUpdateContextItem,\n BrickEventHandlerCallback,\n ContextConf,\n ContextResolveTriggerBrickLifeCycle,\n} from \"@next-core/types\";\nimport { hasOwnProperty, isObject } from \"@next-core/utils/general\";\nimport { strictCollectMemberUsage } from \"@next-core/utils/storyboard\";\nimport { eventCallbackFactory, listenerFactory } from \"../bindListeners.js\";\nimport { asyncCheckIf } from \"../compute/checkIf.js\";\nimport {\n asyncComputeRealValue,\n computeRealValue,\n} from \"../compute/computeRealValue.js\";\nimport { ResolveOptions, resolveData } from \"./resolveData.js\";\nimport { resolveDataStore } from \"./resolveDataStore.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n RuntimeContext,\n} from \"../interfaces.js\";\nimport { handleHttpError } from \"../../handleHttpError.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst supportContextResolveTriggerBrickLifeCycle = [\n \"onBeforePageLoad\",\n \"onPageLoad\",\n \"onBeforePageLeave\",\n \"onPageLeave\",\n \"onAnchorLoad\",\n \"onAnchorUnload\",\n] as ContextResolveTriggerBrickLifeCycle[];\n\nexport type DataStoreType = \"CTX\" | \"STATE\" | \"FORM_STATE\";\n\nexport interface DataStoreItem {\n value: unknown;\n eventTarget: EventTarget;\n loaded?: boolean;\n loading?: Promise<unknown>;\n load?: (options?: ResolveOptions) => Promise<unknown>;\n async?: boolean;\n deps: string[];\n}\n\nexport class DataStore<T extends DataStoreType = \"CTX\"> {\n private readonly type: T;\n private readonly data = new Map<string, DataStoreItem>();\n private readonly changeEventType: string;\n private readonly pendingStack: Array<ReturnType<typeof resolveDataStore>> =\n [];\n public readonly hostBrick?: RuntimeBrick;\n public batchUpdate = false;\n public batchUpdateContextsNames: string[] = [];\n private readonly rendererContext?: RendererContext;\n\n // 把 `rendererContext` 放在参数列表的最后,并作为可选,以减少测试文件的调整\n constructor(\n type: T,\n hostBrick?: RuntimeBrick,\n rendererContext?: RendererContext\n ) {\n this.type = type;\n this.changeEventType =\n this.type === \"FORM_STATE\"\n ? \"formstate.change\"\n : this.type === \"STATE\"\n ? \"state.change\"\n : \"context.change\";\n this.hostBrick = hostBrick;\n this.rendererContext = rendererContext;\n }\n\n getValue(name: string): unknown {\n return this.data.get(name)?.value;\n }\n\n private getAffectListByContext(name: string): string[] {\n const affectNames = [name];\n this.data.forEach((value, key) => {\n if (value.deps) {\n const isInDeps = value.deps.some((item) => affectNames.includes(item));\n isInDeps &&\n affectNames.push(key) &&\n affectNames.push(...this.getAffectListByContext(key));\n }\n });\n affectNames.shift();\n return [...new Set(affectNames)];\n }\n\n updateValues(\n values: BatchUpdateContextItem[],\n method: \"assign\" | \"replace\",\n argsFactory: (arg: unknown[]) => BatchUpdateContextItem\n ): void {\n this.batchUpdate = true;\n this.batchUpdateContextsNames = values.map((item) => item.name);\n if (\n [...new Set(this.batchUpdateContextsNames)].length !==\n this.batchUpdateContextsNames.length\n ) {\n throw new Error(`Batch update not allow to update same item`);\n }\n\n const updateContexts: Record<string, DataStoreItem> = {};\n const affectContexts: Record<string, DataStoreItem> = {};\n const affectDepsContextNames: string[] = [];\n\n values.forEach((arg) => {\n const { name, value } = argsFactory([arg]);\n const updateContextItem = this.data.get(name);\n affectDepsContextNames.push(...this.getAffectListByContext(name));\n updateContextItem && (updateContexts[name] = updateContextItem);\n this.updateValue(name as string, value, method);\n });\n\n affectDepsContextNames\n .filter((item) => !updateContexts[item])\n .forEach((name) => {\n const affectContextItem = this.data.get(name);\n affectContextItem && (affectContexts[name] = affectContextItem);\n });\n\n const triggerEvent = (contexts: Record<string, DataStoreItem>): void => {\n for (const key in contexts) {\n const context = contexts[key];\n context.eventTarget?.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: context.value,\n })\n );\n }\n };\n\n triggerEvent(updateContexts);\n triggerEvent(affectContexts);\n\n this.batchUpdate = false;\n\n return;\n }\n\n updateValue(\n name: string,\n value: unknown,\n method: \"assign\" | \"replace\" | \"refresh\" | \"load\",\n callback?: BrickEventHandlerCallback,\n callbackRuntimeContext?: RuntimeContext\n ): void {\n const item = this.data.get(name);\n if (!item) {\n throw new Error(`${this.type} '${name}' is not defined`);\n }\n\n if (method === \"refresh\" || method === \"load\") {\n if (!item.load) {\n throw new Error(\n `You can not ${method} \"${this.type}.${name}\" which has no resolve`\n );\n }\n\n let promise: Promise<unknown> | undefined;\n if (method === \"load\") {\n // Try to reuse previous request when calling `load`.\n if (item.loaded) {\n promise = Promise.resolve(item.value);\n } else if (item.loading) {\n promise = item.loading;\n }\n }\n\n if (!promise) {\n promise = item.loading = item.load({\n cache: method === \"load\" ? \"default\" : \"reload\",\n ...(value as ResolveOptions),\n });\n // Do not use the chained promise, since the callbacks need the original promise.\n promise.then(\n (val) => {\n item.loaded = true;\n item.value = val;\n item.eventTarget.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: item.value,\n })\n );\n },\n (err) => {\n // Let users override error handling.\n if (!callback?.error) {\n handleHttpError(err);\n }\n }\n );\n }\n\n if (callback) {\n const callbackFactory = eventCallbackFactory(\n callback,\n callbackRuntimeContext!\n );\n\n promise.then(\n (val) => {\n callbackFactory(\"success\")({ value: val });\n callbackFactory(\"finally\")();\n },\n (err) => {\n callbackFactory(\"error\")(err);\n callbackFactory(\"finally\")();\n }\n );\n }\n\n return;\n }\n\n if (method === \"replace\") {\n item.value = value;\n } else {\n if (isObject(item.value)) {\n Object.assign(item.value, value);\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n `Non-object current value of \"${this.type}.${name}\" for \"context.assign\", try \"context.replace\" instead.`\n );\n item.value = value;\n }\n }\n\n if (this.batchUpdate) return;\n\n item.eventTarget.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: item.value,\n })\n );\n }\n\n define(\n dataConfs: ContextConf[] | undefined,\n runtimeContext: RuntimeContext,\n asyncHostProperties?: AsyncProperties\n ): void {\n if (Array.isArray(dataConfs) && dataConfs.length > 0) {\n const pending = resolveDataStore(\n dataConfs,\n (dataConf: ContextConf) =>\n this.resolve(dataConf, runtimeContext, asyncHostProperties),\n this.type\n );\n this.pendingStack.push(pending);\n }\n }\n\n onChange(dataName: string, listener: EventListener): void {\n this.data\n .get(dataName)\n ?.eventTarget.addEventListener(this.changeEventType, listener);\n }\n\n async waitFor(dataNames: string[] | Set<string>): Promise<void> {\n for (const { pendingContexts } of this.pendingStack) {\n await Promise.all(\n [...dataNames].map((ctx) => {\n const p = pendingContexts.get(ctx);\n return p;\n })\n );\n }\n }\n\n async waitForAll(): Promise<void> {\n for (const { pendingResult } of this.pendingStack) {\n await pendingResult;\n }\n }\n\n /** After mount, dispatch the change event when an async data is loaded */\n handleAsyncAfterMount() {\n this.data.forEach((item) => {\n if (item.async) {\n // An async data always has `loading`\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n item.loading!.then((value) => {\n item.loaded = true;\n item.value = value;\n item.eventTarget.dispatchEvent(\n new CustomEvent(this.changeEventType, {\n detail: value,\n })\n );\n });\n }\n });\n }\n\n private async resolve(\n dataConf: ContextConf,\n runtimeContext: RuntimeContext,\n asyncHostProperties?: AsyncProperties\n ): Promise<boolean> {\n if (!(await asyncCheckIf(dataConf, runtimeContext))) {\n return false;\n }\n let value: unknown;\n if (\n asyncHostProperties &&\n (this.type === \"STATE\" ? dataConf.expose : this.type === \"FORM_STATE\") &&\n hasOwnProperty(asyncHostProperties, dataConf.name)\n ) {\n value = await asyncHostProperties[dataConf.name];\n }\n let load: DataStoreItem[\"load\"];\n let loading: Promise<unknown> | undefined;\n let resolvePolicy: \"eager\" | \"lazy\" | \"async\" = \"eager\";\n if (value === undefined) {\n if (dataConf.resolve) {\n const resolveConf = {\n transform: \"value\",\n ...dataConf.resolve,\n };\n if (await asyncCheckIf(dataConf.resolve, runtimeContext)) {\n load = async (options) =>\n (\n (await resolveData(resolveConf, runtimeContext, options)) as {\n value: unknown;\n }\n ).value;\n // `async` take precedence over `lazy`\n resolvePolicy = dataConf.resolve.async\n ? \"async\"\n : dataConf.resolve.lazy\n ? \"lazy\"\n : \"eager\";\n if (resolvePolicy === \"eager\") {\n value = await load();\n } else if (resolvePolicy === \"async\") {\n loading = load();\n }\n } else if (!hasOwnProperty(dataConf, \"value\")) {\n return false;\n }\n }\n if (\n (!load || resolvePolicy !== \"eager\") &&\n dataConf.value !== undefined\n ) {\n // If the context has no resolve, just use its `value`.\n // Or if the resolve is ignored or lazy, use its `value` as a fallback.\n value = await asyncComputeRealValue(dataConf.value, runtimeContext);\n }\n }\n\n const newData: DataStoreItem = {\n value,\n // This is required for tracking context, even if no `onChange` is specified.\n eventTarget: new EventTarget(),\n load,\n loaded: resolvePolicy === \"eager\",\n loading,\n async: resolvePolicy === \"async\",\n deps: [],\n };\n\n if (resolvePolicy === \"lazy\") {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { trigger } = dataConf.resolve!;\n if (\n trigger &&\n supportContextResolveTriggerBrickLifeCycle.includes(trigger)\n ) {\n this.rendererContext?.registerArbitraryLifeCycle(trigger, () => {\n this.updateValue(dataConf.name, undefined, \"load\");\n });\n }\n }\n\n if (dataConf.onChange) {\n newData.eventTarget.addEventListener(\n this.changeEventType,\n listenerFactory(dataConf.onChange, runtimeContext)\n );\n }\n\n if (dataConf.track) {\n const deps = strictCollectMemberUsage(\n load ? dataConf.resolve : dataConf.value,\n this.type\n );\n !load && (newData.deps = [...deps]);\n for (const dep of deps) {\n this.onChange(\n dep,\n this.batchAddListener(() => {\n if (load) {\n this.updateValue(dataConf.name, { cache: \"default\" }, \"refresh\");\n } else {\n this.updateValue(\n dataConf.name,\n computeRealValue(dataConf.value, runtimeContext),\n \"replace\"\n );\n }\n }, dataConf)\n );\n }\n }\n\n if (this.data.has(dataConf.name)) {\n throw new Error(\n `${this.type} '${dataConf.name}' has already been declared`\n );\n }\n this.data.set(dataConf.name, newData);\n\n return true;\n }\n\n private batchAddListener(\n listener: EventListener,\n contextConf: ContextConf\n ): EventListener {\n return (event: Event | CustomEvent): void => {\n if (\n this.batchUpdate &&\n this.batchUpdateContextsNames.includes(contextConf.name)\n ) {\n return;\n }\n listener(event);\n };\n }\n}\n"],"mappings":";;;AAMA,SAASA,cAAc,EAAEC,QAAQ,QAAQ,0BAA0B;AACnE,SAASC,wBAAwB,QAAQ,6BAA6B;AACtE,SAASC,oBAAoB,EAAEC,eAAe,QAAQ,qBAAqB;AAC3E,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SACEC,qBAAqB,EACrBC,gBAAgB,QACX,gCAAgC;AACvC,SAAyBC,WAAW,QAAQ,kBAAkB;AAC9D,SAASC,gBAAgB,QAAQ,uBAAuB;AAMxD,SAASC,eAAe,QAAQ,0BAA0B;AAG1D,IAAMC,0CAA0C,GAAG,CACjD,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,gBAAgB,CACwB;AAc1C,OAAO,MAAMC,SAAS,CAAkC;EAWtD;EACAC,WAAWA,CACTC,IAAO,EACPC,SAAwB,EACxBC,eAAiC,EACjC;IAAAC,eAAA;IAAAA,eAAA,eAdsB,IAAIC,GAAG,CAAwB,CAAC;IAAAD,eAAA;IAAAA,eAAA,uBAGtD,EAAE;IAAAA,eAAA;IAAAA,eAAA,sBAEiB,KAAK;IAAAA,eAAA,mCACkB,EAAE;IAAAA,eAAA;IAS5C,IAAI,CAACH,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACK,eAAe,GAClB,IAAI,CAACL,IAAI,KAAK,YAAY,GACtB,kBAAkB,GAClB,IAAI,CAACA,IAAI,KAAK,OAAO,GACrB,cAAc,GACd,gBAAgB;IACtB,IAAI,CAACC,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,eAAe,GAAGA,eAAe;EACxC;EAEAI,QAAQA,CAACC,IAAY,EAAW;IAAA,IAAAC,cAAA;IAC9B,QAAAA,cAAA,GAAO,IAAI,CAACC,IAAI,CAACC,GAAG,CAACH,IAAI,CAAC,cAAAC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AEK,QAAQ,CACb,CAAC;QACH;MACF;MAEA,IAAIqB,MAAI,CAACxF,IAAI,CAAC4G,GAAG,CAACzC,QAAQ,CAACrE,IAAI,CAAC,EAAE;QAChC,MAAM,IAAIyB,KAAK,IAAAmB,MAAA,CACV8C,MAAI,CAACjG,IAAI,QAAAmD,MAAA,CAAKyB,QAAQ,CAACrE,IAAI,gCAChC,CAAC;MACH;MACA0F,MAAI,CAACxF,IAAI,CAAC6G,GAAG,CAAC1C,QAAQ,CAACrE,IAAI,EAAEsG,OAAO,CAAC;MAErC,OAAO,IAAI;IAAC;EACd;EAEQO,gBAAgBA,CACtBpC,QAAuB,EACvBuC,WAAwB,EACT;IACf,OAAQC,KAA0B,IAAW;MAC3C,IACE,IAAI,CAAC5F,WAAW,IAChB,IAAI,CAACC,wBAAwB,CAACT,QAAQ,CAACmG,WAAW,CAAChH,IAAI,CAAC,EACxD;QACA;MACF;MACAyE,QAAQ,CAACwC,KAAK,CAAC;IACjB,CAAC;EACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","names":[],"sources":["../../../src/internal/interfaces.ts"],"sourcesContent":["import type { LegacyCompatibleRuntimeContext } from \"@next-core/inject\";\nimport type {\n BrickEventHandler,\n BrickEventsMap,\n CustomTemplateProxy,\n CustomTemplateProxyBasicProperty,\n CustomTemplateProxySlot,\n SlotsConfOfBricks,\n} from \"@next-core/types\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./CustomTemplates/constants.js\";\nimport { RuntimeBrickConfOfFormSymbols } from \"./FormRenderer/constants.js\";\n\nexport interface RuntimeContext extends LegacyCompatibleRuntimeContext {\n ctxStore: DataStore<\"CTX\">;\n tplStateStoreMap: Map<string, DataStore<\"STATE\">>;\n pendingPermissionsPreCheck: (Promise<unknown> | undefined)[];\n tplStateStoreId?: string;\n // `useBrick` has a local tpl state store scope\n tplStateStoreScope?: DataStore<\"STATE\">[];\n forEachItem?: unknown;\n appendI18nNamespace?: string;\n\n formStateStoreMap: Map<string, DataStore<\"FORM_STATE\">>;\n formStateStoreId?: string;\n formStateStoreScope?: DataStore<\"FORM_STATE\">[];\n}\n\nexport type AsyncProperties = Promise<Record<string, unknown>>;\n\nexport interface ElementHolder {\n element?: HTMLElement | null;\n}\n\nexport interface RenderRoot extends BaseRenderNode {\n tag: RenderTag.ROOT;\n container?: HTMLElement | DocumentFragment;\n createPortal:\n | HTMLElement\n | DocumentFragment\n | (() => HTMLElement | DocumentFragment);\n}\n\nexport interface RenderBrick extends BaseRenderNode, RuntimeBrick {\n tag: RenderTag.BRICK;\n return: RenderNode;\n hasTrackingControls?: boolean;\n}\n\nexport interface BaseRenderNode {\n tag: RenderTag;\n child?: RenderBrick;\n sibling?: RenderBrick;\n return?: RenderNode | null;\n childElements?: HTMLElement[];\n}\n\nexport type RenderNode = RenderRoot | RenderBrick;\n\nexport interface RuntimeBrick {\n type: string;\n properties?: Record<string, unknown>;\n events?: BrickEventsMap;\n slotId?: string;\n element?: RuntimeBrickElement | null;\n iid?: string;\n runtimeContext: RuntimeContext;\n tplHostMetadata?: TemplateHostMetadata;\n portal?: boolean;\n ref?: string;\n}\n\nexport type MetaInfoOfEventListener = [\n string,\n // For compatibility of devtools, leave the second argument there.\n null | undefined,\n BrickEventHandler\n];\n\nexport type RememberedEventListener = [string, EventListener];\n\nexport interface RuntimeBrickElement extends HTMLElement {\n $$typeof?: \"brick\" | \"provider\" | \"custom-template\" | \"native\" | \"invalid\";\n /** Meta info of listeners, for devtools only */\n $$eventListeners?: MetaInfoOfEventListener[];\n /** Remembered listeners for unbinding */\n $$listeners?: RememberedEventListener[];\n /** Remembered proxy listeners for unbinding */\n $$proxyListeners?: RememberedEventListener[];\n /** Find element by ref in a custom template */\n $$getElementByRef?: (ref: string) => HTMLElement | null | undefined;\n $$tplStateStore?: DataStore<\"STATE\">;\n}\n\nexport interface TemplateHostMetadata {\n internalBricksByRef: Map<string, RuntimeBrick>;\n tplStateStoreId: string;\n proxy?: CustomTemplateProxy;\n}\n\nexport type TemplateHostBrick = RuntimeBrick & {\n tplHostMetadata: TemplateHostMetadata;\n};\n\nexport interface TemplateHostContext {\n reversedProxies: ReversedProxies;\n asyncHostProperties?: AsyncProperties;\n externalSlots?: SlotsConfOfBricks;\n tplStateStoreId: string;\n hostBrick: TemplateHostBrick;\n}\n\ninterface ReversedProxies {\n properties: Map<string, ReversedPropertyProxy[]>;\n slots: Map<string, ReversedSlotProxy[]>;\n}\n\ninterface ReversedPropertyProxy {\n from: string;\n to: CustomTemplateProxyBasicProperty;\n}\n\ninterface ReversedSlotProxy {\n from: string;\n to: CustomTemplateProxySlot;\n}\n\nexport type RuntimeBrickConfWithSymbols = RuntimeBrickConfWithTplSymbols &\n RuntimeBrickConfOfFormSymbols;\n"],"mappings":""}
1
+ {"version":3,"file":"interfaces.js","names":[],"sources":["../../../src/internal/interfaces.ts"],"sourcesContent":["import type { LegacyCompatibleRuntimeContext } from \"@next-core/inject\";\nimport type {\n BrickEventHandler,\n BrickEventsMap,\n CustomTemplateProxy,\n CustomTemplateProxyBasicProperty,\n CustomTemplateProxySlot,\n SlotsConfOfBricks,\n} from \"@next-core/types\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./CustomTemplates/constants.js\";\nimport { RuntimeBrickConfOfFormSymbols } from \"./FormRenderer/constants.js\";\n\nexport interface RuntimeContext extends LegacyCompatibleRuntimeContext {\n ctxStore: DataStore<\"CTX\">;\n tplStateStoreMap: Map<string, DataStore<\"STATE\">>;\n pendingPermissionsPreCheck: (Promise<unknown> | undefined)[];\n tplStateStoreId?: string;\n // `useBrick` has a local tpl state store scope\n tplStateStoreScope?: DataStore<\"STATE\">[];\n forEachItem?: unknown;\n appendI18nNamespace?: string;\n\n formStateStoreMap: Map<string, DataStore<\"FORM_STATE\">>;\n formStateStoreId?: string;\n formStateStoreScope?: DataStore<\"FORM_STATE\">[];\n}\n\nexport type AsyncComputedProperties = Promise<Record<string, unknown>>;\n\nexport type AsyncProperties = Record<string, Promise<unknown>>;\n\nexport interface ElementHolder {\n element?: HTMLElement | null;\n}\n\nexport interface RenderRoot extends BaseRenderNode {\n tag: RenderTag.ROOT;\n container?: HTMLElement | DocumentFragment;\n createPortal:\n | HTMLElement\n | DocumentFragment\n | (() => HTMLElement | DocumentFragment);\n}\n\nexport interface RenderBrick extends BaseRenderNode, RuntimeBrick {\n tag: RenderTag.BRICK;\n return: RenderNode;\n hasTrackingControls?: boolean;\n}\n\nexport interface BaseRenderNode {\n tag: RenderTag;\n child?: RenderBrick;\n sibling?: RenderBrick;\n return?: RenderNode | null;\n childElements?: HTMLElement[];\n}\n\nexport type RenderNode = RenderRoot | RenderBrick;\n\nexport interface RuntimeBrick {\n type: string;\n properties?: Record<string, unknown>;\n events?: BrickEventsMap;\n slotId?: string;\n element?: RuntimeBrickElement | null;\n iid?: string;\n runtimeContext: RuntimeContext;\n tplHostMetadata?: TemplateHostMetadata;\n portal?: boolean;\n ref?: string;\n}\n\nexport type MetaInfoOfEventListener = [\n string,\n // For compatibility of devtools, leave the second argument there.\n null | undefined,\n BrickEventHandler\n];\n\nexport type RememberedEventListener = [string, EventListener];\n\nexport interface RuntimeBrickElement extends HTMLElement {\n $$typeof?: \"brick\" | \"provider\" | \"custom-template\" | \"native\" | \"invalid\";\n /** Meta info of listeners, for devtools only */\n $$eventListeners?: MetaInfoOfEventListener[];\n /** Remembered listeners for unbinding */\n $$listeners?: RememberedEventListener[];\n /** Remembered proxy listeners for unbinding */\n $$proxyListeners?: RememberedEventListener[];\n /** Find element by ref in a custom template */\n $$getElementByRef?: (ref: string) => HTMLElement | null | undefined;\n $$tplStateStore?: DataStore<\"STATE\">;\n}\n\nexport interface TemplateHostMetadata {\n internalBricksByRef: Map<string, RuntimeBrick>;\n tplStateStoreId: string;\n proxy?: CustomTemplateProxy;\n}\n\nexport type TemplateHostBrick = RuntimeBrick & {\n tplHostMetadata: TemplateHostMetadata;\n};\n\nexport interface TemplateHostContext {\n reversedProxies: ReversedProxies;\n asyncHostProperties: AsyncProperties;\n externalSlots?: SlotsConfOfBricks;\n tplStateStoreId: string;\n hostBrick: TemplateHostBrick;\n}\n\ninterface ReversedProxies {\n properties: Map<string, ReversedPropertyProxy[]>;\n slots: Map<string, ReversedSlotProxy[]>;\n}\n\ninterface ReversedPropertyProxy {\n from: string;\n to: CustomTemplateProxyBasicProperty;\n}\n\ninterface ReversedSlotProxy {\n from: string;\n to: CustomTemplateProxySlot;\n}\n\nexport type RuntimeBrickConfWithSymbols = RuntimeBrickConfWithTplSymbols &\n RuntimeBrickConfOfFormSymbols;\n"],"mappings":""}
@@ -42,9 +42,10 @@ function _renderUseBrick() {
42
42
  properties: _objectSpread(_objectSpread({}, useBrick.properties), transform)
43
43
  }), runtimeContext, rendererContext);
44
44
  flushStableLoadBricks();
45
+ var scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
45
46
  yield Promise.all([...output.blockingList,
46
47
  // Wait for local tpl state stores belong to current `useBrick` only.
47
- ...[...tplStateStoreScope, ...formStateStoreScope].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
48
+ ...scopedStores.map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
48
49
  if ((_output$node = output.node) !== null && _output$node !== void 0 && _output$node.portal) {
49
50
  throw new Error("The root brick of useBrick cannot be a portal brick");
50
51
  }
@@ -53,7 +54,8 @@ function _renderUseBrick() {
53
54
  return {
54
55
  tagName,
55
56
  renderRoot,
56
- rendererContext
57
+ rendererContext,
58
+ scopedStores
57
59
  };
58
60
  });
59
61
  return _renderUseBrick.apply(this, arguments);
@@ -61,7 +63,8 @@ function _renderUseBrick() {
61
63
  export function mountUseBrick(_ref, element) {
62
64
  var {
63
65
  renderRoot,
64
- rendererContext
66
+ rendererContext,
67
+ scopedStores
65
68
  } = _ref;
66
69
  var portal;
67
70
  renderRoot.createPortal = () => {
@@ -71,6 +74,9 @@ export function mountUseBrick(_ref, element) {
71
74
  return portal;
72
75
  };
73
76
  mountTree(renderRoot, element);
77
+ for (var store of scopedStores) {
78
+ store.handleAsyncAfterMount();
79
+ }
74
80
  rendererContext.dispatchOnMount();
75
81
  rendererContext.initializeScrollIntoView();
76
82
  rendererContext.initializeMediaChange();
@@ -1 +1 @@
1
- {"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","renderBrick","RendererContext","mountTree","unmountTree","RenderTag","computeRealValue","isStrictMode","warnAboutStrictMode","customTemplates","registerAppI18n","renderUseBrick","_x","_x2","_renderUseBrick","apply","arguments","_asyncToGenerator","useBrick","data","_runtimeContext$tplSt","_runtimeContext$formS","_output$node","tplStateStoreScope","formStateStoreScope","runtimeContext","_objectSpread","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","rendererContext","renderRoot","tag","ROOT","createPortal","transform","strict","output","properties","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","_ref","element","portalRoot","document","querySelector","createElement","appendChild","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmountUseBrick","_ref2","mountResult","remove","dispatchOnUnmount","dispose","legacyDoTransform","to","options","noInject","updateStoryboard","appId","storyboardPatch","storyboard","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","updateStoryboardByRoute","newRoute","match","getKey","route","concat","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n} from \"./Runtime.js\";\nimport { renderBrick } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\n\nexport type { RuntimeContext } from \"./interfaces.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const formStateStoreScope: DataStore<\"FORM_STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n formStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n runtimeContext.formStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"fragment\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...[...tplStateStoreScope, ...formStateStoreScope].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\n/** For v2 compatibility of `doTransform` from brick-kit. */\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;AAOA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SACEC,6BAA6B,EAC7BC,wCAAwC,QACnC,cAAc;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,eAAe,QAAQ,sBAAsB;AAGtD,SAASC,SAAS,EAAEC,WAAW,QAAQ,YAAY;AACnD,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,oBAAoB;AACtE,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,eAAe,QAAQ,sBAAsB;AAUtD,gBAAsBC,cAAcA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,eAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAwEnC,SAAAF,gBAAA;EAAAA,eAAA,GAAAG,iBAAA,CAxEM,WACLC,QAA4B,EAC5BC,IAAa,EACkB;IAAA,IAAAC,qBAAA,EAAAC,qBAAA,EAAAC,YAAA;IAC/B,IAAMC,kBAAwC,GAAG,EAAE;IACnD,IAAMC,mBAA8C,GAAG,EAAE;IACzD,IAAMC,cAA8B,GAAAC,aAAA,CAAAA,aAAA,KAC/B3B,6BAA6B,CAAC,CAAC;MAClCoB,IAAI;MACJQ,0BAA0B,EAAE,EAAE;MAC9BJ,kBAAkB;MAClBC;IAAmB,EACpB;IAED,CAAAJ,qBAAA,GAAAK,cAAc,CAACG,gBAAgB,cAAAR,qBAAA,cAAAA,qBAAA,GAA/BK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AAA,CAC0CsB,WAAW,CAACE,SAAS,GACpE,CAAAD,mBAAA,GAAAD,WAAW,CAACR,MAAM,cAAAS,mBAAA,eAAlBA,mBAAA,CAAoBE,MAAM,GAAGH,WAAW,CAACR,MAAM,GAAG,CAAC;IAAEM,KAAK,EAAE;EAAO,CAAC,CACtE,CAAC;AACH;AAEA,OAAO,IAAMM,4BAA4B,GAAGL,yBAAyB;AAErE,SAASF,sBAAsBA,CAC7BhC,KAAa,EACbc,IAAY,EACZa,MAAmB,EACnB;EACA,IAAM;IAAEV;EAAO,CAAC,GAAG5F,wCAAwC,CAAC2E,KAAK,CAAE;EACnE,IAAMwC,iBAAiB,GAAGvB,MAAM,CAACwB,SAAS,CAAE7B,KAAK,IAAKA,KAAK,CAACE,IAAI,KAAKA,IAAI,CAAC;EAC1E,IAAM4B,eAA0B,GAAG;IACjC5B,IAAI;IACJa,MAAM;IACNgB,IAAI,EAAE,KAAK;IACX5B,KAAK,EAAE;EACT,CAAC;EACD,IAAIyB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BvB,MAAM,CAACG,OAAO,CAACsB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLzB,MAAM,CAAC2B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
1
+ {"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","renderBrick","RendererContext","mountTree","unmountTree","RenderTag","computeRealValue","isStrictMode","warnAboutStrictMode","customTemplates","registerAppI18n","renderUseBrick","_x","_x2","_renderUseBrick","apply","arguments","_asyncToGenerator","useBrick","data","_runtimeContext$tplSt","_runtimeContext$formS","_output$node","tplStateStoreScope","formStateStoreScope","runtimeContext","_objectSpread","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","rendererContext","renderRoot","tag","ROOT","createPortal","transform","strict","output","properties","scopedStores","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","_ref","element","portalRoot","document","querySelector","createElement","appendChild","handleAsyncAfterMount","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmountUseBrick","_ref2","mountResult","remove","dispatchOnUnmount","dispose","legacyDoTransform","to","options","noInject","updateStoryboard","appId","storyboardPatch","storyboard","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","updateStoryboardByRoute","newRoute","match","getKey","route","concat","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n} from \"./Runtime.js\";\nimport { renderBrick } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\n\nexport type { RuntimeContext } from \"./interfaces.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n scopedStores: DataStore<\"STATE\" | \"FORM_STATE\">[];\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const formStateStoreScope: DataStore<\"FORM_STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n formStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n runtimeContext.formStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"fragment\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n const scopedStores: DataStore<\"STATE\" | \"FORM_STATE\">[] = [\n ...tplStateStoreScope,\n ...formStateStoreScope,\n ];\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...scopedStores.map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext, scopedStores };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext, scopedStores }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n for (const store of scopedStores) {\n store.handleAsyncAfterMount();\n }\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\n/** For v2 compatibility of `doTransform` from brick-kit. */\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;AAOA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SACEC,6BAA6B,EAC7BC,wCAAwC,QACnC,cAAc;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,eAAe,QAAQ,sBAAsB;AAGtD,SAASC,SAAS,EAAEC,WAAW,QAAQ,YA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,GAAG9F,wCAAwC,CAAC6E,KAAK,CAAE;EACnE,IAAMwC,iBAAiB,GAAGvB,MAAM,CAACwB,SAAS,CAAE7B,KAAK,IAAKA,KAAK,CAACE,IAAI,KAAKA,IAAI,CAAC;EAC1E,IAAM4B,eAA0B,GAAG;IACjC5B,IAAI;IACJa,MAAM;IACNgB,IAAI,EAAE,KAAK;IACX5B,KAAK,EAAE;EACT,CAAC;EACD,IAAIyB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BvB,MAAM,CAACG,OAAO,CAACsB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLzB,MAAM,CAAC2B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
@@ -1,11 +1,11 @@
1
1
  import type { BrickConf } from "@next-core/types";
2
- import type { AsyncProperties } from "../interfaces.js";
2
+ import type { AsyncComputedProperties } from "../interfaces.js";
3
3
  export declare const symbolForAsyncComputedPropsFromHost: unique symbol;
4
4
  export declare const symbolForTplStateStoreId: unique symbol;
5
5
  export declare const symbolForTPlExternalForEachItem: unique symbol;
6
6
  export type RuntimeBrickConfWithTplSymbols = BrickConf & RuntimeBrickConfOfTplSymbols;
7
7
  export interface RuntimeBrickConfOfTplSymbols {
8
- [symbolForAsyncComputedPropsFromHost]?: AsyncProperties;
8
+ [symbolForAsyncComputedPropsFromHost]?: AsyncComputedProperties;
9
9
  [symbolForTplStateStoreId]?: string;
10
10
  [symbolForTPlExternalForEachItem]?: unknown;
11
11
  }
@@ -1,7 +1,7 @@
1
1
  import type { SlotsConfOfBricks } from "@next-core/types";
2
2
  import { symbolForAsyncComputedPropsFromHost, symbolForTplStateStoreId } from "./constants.js";
3
- import type { AsyncProperties, TemplateHostContext } from "../interfaces.js";
3
+ import type { AsyncComputedProperties, TemplateHostContext } from "../interfaces.js";
4
4
  export declare function setupTemplateProxy(hostContext: TemplateHostContext, ref: string | undefined, slots: SlotsConfOfBricks): {
5
- [symbolForAsyncComputedPropsFromHost]: AsyncProperties | undefined;
5
+ [symbolForAsyncComputedPropsFromHost]: AsyncComputedProperties | undefined;
6
6
  [symbolForTplStateStoreId]: string;
7
7
  };
@@ -46,8 +46,8 @@ export interface RuntimeHooks {
46
46
  widgetImagesFactory(widgetId: string, widgetVersion?: string): ImagesFactory;
47
47
  };
48
48
  messageDispatcher?: {
49
- subscribe(...args: unknown[]): Promise<Event>;
50
- unsubscribe(...args: unknown[]): Promise<Event>;
49
+ subscribe(...args: unknown[]): Promise<unknown>;
50
+ unsubscribe(...args: unknown[]): Promise<unknown>;
51
51
  onMessage(channel: string, listener: (data: unknown) => void): void;
52
52
  onClose(listener: () => void): void;
53
53
  reset(): void;
@@ -1,4 +1,5 @@
1
1
  import { TrackingContextItem } from "./listenOnTrackingContext.js";
2
- import type { RuntimeContext } from "../interfaces.js";
3
- export declare function asyncComputeRealProperties(properties: Record<string, unknown> | undefined, runtimeContext: RuntimeContext, trackingContextList?: TrackingContextItem[]): Promise<Record<string, unknown>>;
4
- export declare function computeRealProperties(properties: Record<string, unknown> | undefined, runtimeContext: RuntimeContext, trackingContextList?: TrackingContextItem[]): Record<string, unknown>;
2
+ import type { AsyncProperties, RuntimeContext } from "../interfaces.js";
3
+ export declare function asyncComputeRealProperties(properties: Record<string, unknown> | undefined, runtimeContext: RuntimeContext, trackingContextList: TrackingContextItem[]): AsyncProperties;
4
+ export declare function constructAsyncProperties(asyncProperties: AsyncProperties): Promise<Record<string, unknown>>;
5
+ export declare function computeRealProperties(properties: Record<string, unknown> | undefined, runtimeContext: RuntimeContext): Record<string, unknown>;
@@ -9,6 +9,7 @@ export interface DataStoreItem {
9
9
  loaded?: boolean;
10
10
  loading?: Promise<unknown>;
11
11
  load?: (options?: ResolveOptions) => Promise<unknown>;
12
+ async?: boolean;
12
13
  deps: string[];
13
14
  }
14
15
  export declare class DataStore<T extends DataStoreType = "CTX"> {
@@ -29,6 +30,8 @@ export declare class DataStore<T extends DataStoreType = "CTX"> {
29
30
  onChange(dataName: string, listener: EventListener): void;
30
31
  waitFor(dataNames: string[] | Set<string>): Promise<void>;
31
32
  waitForAll(): Promise<void>;
33
+ /** After mount, dispatch the change event when an async data is loaded */
34
+ handleAsyncAfterMount(): void;
32
35
  private resolve;
33
36
  private batchAddListener;
34
37
  }
@@ -16,7 +16,8 @@ export interface RuntimeContext extends LegacyCompatibleRuntimeContext {
16
16
  formStateStoreId?: string;
17
17
  formStateStoreScope?: DataStore<"FORM_STATE">[];
18
18
  }
19
- export type AsyncProperties = Promise<Record<string, unknown>>;
19
+ export type AsyncComputedProperties = Promise<Record<string, unknown>>;
20
+ export type AsyncProperties = Record<string, Promise<unknown>>;
20
21
  export interface ElementHolder {
21
22
  element?: HTMLElement | null;
22
23
  }
@@ -78,7 +79,7 @@ export type TemplateHostBrick = RuntimeBrick & {
78
79
  };
79
80
  export interface TemplateHostContext {
80
81
  reversedProxies: ReversedProxies;
81
- asyncHostProperties?: AsyncProperties;
82
+ asyncHostProperties: AsyncProperties;
82
83
  externalSlots?: SlotsConfOfBricks;
83
84
  tplStateStoreId: string;
84
85
  hostBrick: TemplateHostBrick;