@next-core/runtime 1.19.3 → 1.19.4

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 (36) hide show
  1. package/dist/cjs/internal/CustomTemplates/constants.js.map +1 -1
  2. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +3 -3
  3. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  4. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +10 -13
  5. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  6. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js +2 -2
  7. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -1
  8. package/dist/cjs/internal/Renderer.js +8 -11
  9. package/dist/cjs/internal/Renderer.js.map +1 -1
  10. package/dist/cjs/internal/compute/computeRealProperties.js +24 -10
  11. package/dist/cjs/internal/compute/computeRealProperties.js.map +1 -1
  12. package/dist/cjs/internal/data/DataStore.js +6 -5
  13. package/dist/cjs/internal/data/DataStore.js.map +1 -1
  14. package/dist/cjs/internal/interfaces.js.map +1 -1
  15. package/dist/esm/internal/CustomTemplates/constants.js.map +1 -1
  16. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +3 -3
  17. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  18. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +12 -20
  19. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  20. package/dist/esm/internal/FormRenderer/expandFormRenderer.js +2 -2
  21. package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -1
  22. package/dist/esm/internal/Renderer.js +9 -12
  23. package/dist/esm/internal/Renderer.js.map +1 -1
  24. package/dist/esm/internal/compute/computeRealProperties.js +32 -19
  25. package/dist/esm/internal/compute/computeRealProperties.js.map +1 -1
  26. package/dist/esm/internal/data/DataStore.js +6 -5
  27. package/dist/esm/internal/data/DataStore.js.map +1 -1
  28. package/dist/esm/internal/interfaces.js.map +1 -1
  29. package/dist/types/internal/CustomTemplates/constants.d.ts +2 -2
  30. package/dist/types/internal/CustomTemplates/expandCustomTemplate.d.ts +2 -2
  31. package/dist/types/internal/CustomTemplates/setupTemplateProxy.d.ts +2 -2
  32. package/dist/types/internal/FormRenderer/expandFormRenderer.d.ts +2 -2
  33. package/dist/types/internal/compute/computeRealProperties.d.ts +4 -3
  34. package/dist/types/internal/data/DataStore.d.ts +2 -2
  35. package/dist/types/internal/interfaces.d.ts +6 -3
  36. package/package.json +2 -2
@@ -12,6 +12,7 @@ var _computeRealValue = require("../compute/computeRealValue.js");
12
12
  var _resolveData = require("./resolveData.js");
13
13
  var _resolveDataStore = require("./resolveDataStore.js");
14
14
  var _handleHttpError = require("../../handleHttpError.js");
15
+ var _computeRealProperties = require("../compute/computeRealProperties.js");
15
16
  const supportContextResolveTriggerBrickLifeCycle = ["onBeforePageLoad", "onPageLoad", "onBeforePageLeave", "onPageLeave", "onAnchorLoad", "onAnchorUnload"];
16
17
  class DataStore {
17
18
  type;
@@ -154,9 +155,9 @@ class DataStore {
154
155
  detail: item.value
155
156
  }));
156
157
  }
157
- define(dataConfs, runtimeContext, asyncHostProperties) {
158
+ define(dataConfs, runtimeContext, asyncHostPropertyEntries) {
158
159
  if (Array.isArray(dataConfs) && dataConfs.length > 0) {
159
- const pending = (0, _resolveDataStore.resolveDataStore)(dataConfs, dataConf => this.resolve(dataConf, runtimeContext, asyncHostProperties), this.type);
160
+ const pending = (0, _resolveDataStore.resolveDataStore)(dataConfs, dataConf => this.resolve(dataConf, runtimeContext, asyncHostPropertyEntries), this.type);
160
161
  this.pendingStack.push(pending);
161
162
  }
162
163
  }
@@ -198,13 +199,13 @@ class DataStore {
198
199
  }
199
200
  });
200
201
  }
201
- async resolve(dataConf, runtimeContext, asyncHostProperties) {
202
+ async resolve(dataConf, runtimeContext, asyncHostPropertyEntries) {
202
203
  if (!(await (0, _checkIf.asyncCheckIf)(dataConf, runtimeContext))) {
203
204
  return false;
204
205
  }
205
206
  let value;
206
- if (asyncHostProperties && (this.type === "STATE" ? dataConf.expose : this.type === "FORM_STATE") && (0, _general.hasOwnProperty)(asyncHostProperties, dataConf.name)) {
207
- value = await asyncHostProperties[dataConf.name];
207
+ if (asyncHostPropertyEntries && (this.type === "STATE" ? dataConf.expose : this.type === "FORM_STATE")) {
208
+ value = await (0, _computeRealProperties.computePropertyValue)(asyncHostPropertyEntries, dataConf.name);
208
209
  }
209
210
  let load;
210
211
  let loading;
@@ -1 +1 @@
1
- {"version":3,"file":"DataStore.js","names":["_general","require","_storyboard","_bindListeners","_checkIf","_computeRealValue","_resolveData","_resolveDataStore","_handleHttpError","supportContextResolveTriggerBrickLifeCycle","DataStore","type","data","Map","changeEventType","pendingStack","hostBrick","batchUpdate","batchUpdateContextsNames","rendererContext","constructor","getAllValues","Object","fromEntries","entries","map","name","value","getValue","_this$data$get","get","getAffectListByContext","affectNames","forEach","key","deps","isInDeps","some","item","includes","push","shift","Set","updateValues","values","method","argsFactory","length","Error","updateContexts","affectContexts","affectDepsContextNames","arg","updateContextItem","updateValue","filter","affectContextItem","triggerEvent","contexts","_context$eventTarget","context","eventTarget","dispatchEvent","CustomEvent","detail","callback","callbackRuntimeContext","load","promise","loaded","Promise","resolve","loading","cache","then","val","err","error","handleHttpError","callbackFactory","eventCallbackFactory","isObject","assign","console","warn","define","dataConfs","runtimeContext","asyncHostProperties","Array","isArray","pending","resolveDataStore","dataConf","onChange","dataName","listener","_this$data$get2","addEventListener","waitFor","dataNames","pendingContexts","all","ctx","p","waitForAll","pendingResult","handleAsyncAfterMount","async","asyncCheckIf","expose","hasOwnProperty","resolvePolicy","undefined","resolveConf","transform","options","resolveData","lazy","asyncComputeRealValue","newData","EventTarget","trigger","_this$rendererContext","registerArbitraryLifeCycle","listenerFactory","track","strictCollectMemberUsage","dep","batchAddListener","computeRealValue","has","set","contextConf","event","exports"],"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 getAllValues(): Record<string, unknown> {\n return Object.fromEntries(\n [...this.data.entries()].map(([name, { value }]) => [name, value])\n );\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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAIA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAMA,IAAAO,gBAAA,GAAAP,OAAA;AAGA,MAAMQ,0CAA0C,GAAG,CACjD,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,gBAAgB,CACwB;AAcnC,MAAMC,SAAS,CAAkC;EACrCC,IAAI;EACJC,IAAI,GAAG,IAAIC,GAAG,CAAwB,CAAC;EACvCC,eAAe;EACfC,YAAY,GAC3B,EAAE;EACYC,SAAS;EAClBC,WAAW,GAAG,KAAK;EACnBC,wBAAwB,GAAa,EAAE;EAC7BC,eAAe;;EAEhC;EACAC,WAAWA,CACTT,IAAO,EACPK,SAAwB,EACxBG,eAAiC,EACjC;IACA,IAAI,CAACR,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACG,eAAe,GAClB,IAAI,CAACH,IAAI,KAAK,YAAY,GACtB,kBAAkB,GAClB,IAAI,CAACA,IAAI,KAAK,OAAO,GACrB,cAAc,GACd,gBAAgB;IACtB,IAAI,CAACK,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACG,eAAe,GAAGA,eAAe;EACxC;EAEAE,YAAYA,CAAA,EAA4B;IACtC,OAAOC,MAAM,CAACC,WAAW,CACvB,CAAC,GAAG,IAAI,CAACX,IAAI,CAACY,OAAO,CAAC,CAAC,CAAC,CAACC,GAAG,CAAC,CAAC,CAACC,IAAI,EAAE;MAAEC;IAAM,CAAC,CAAC,KAA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ChC,MAAM,IAAIsB,KAAK,CACZ,GAAE,IAAI,CAACrC,IAAK,KAAIkF,QAAQ,CAACnE,IAAK,6BACjC,CAAC;IACH;IACA,IAAI,CAACd,IAAI,CAACwH,GAAG,CAACvC,QAAQ,CAACnE,IAAI,EAAE8F,OAAO,CAAC;IAErC,OAAO,IAAI;EACb;EAEQS,gBAAgBA,CACtBjC,QAAuB,EACvBqC,WAAwB,EACT;IACf,OAAQC,KAA0B,IAAW;MAC3C,IACE,IAAI,CAACrH,WAAW,IAChB,IAAI,CAACC,wBAAwB,CAACqB,QAAQ,CAAC8F,WAAW,CAAC3G,IAAI,CAAC,EACxD;QACA;MACF;MACAsE,QAAQ,CAACsC,KAAK,CAAC;IACjB,CAAC;EACH;AACF;AAACC,OAAA,CAAA7H,SAAA,GAAAA,SAAA"}
1
+ {"version":3,"file":"DataStore.js","names":["_general","require","_storyboard","_bindListeners","_checkIf","_computeRealValue","_resolveData","_resolveDataStore","_handleHttpError","_computeRealProperties","supportContextResolveTriggerBrickLifeCycle","DataStore","type","data","Map","changeEventType","pendingStack","hostBrick","batchUpdate","batchUpdateContextsNames","rendererContext","constructor","getAllValues","Object","fromEntries","entries","map","name","value","getValue","_this$data$get","get","getAffectListByContext","affectNames","forEach","key","deps","isInDeps","some","item","includes","push","shift","Set","updateValues","values","method","argsFactory","length","Error","updateContexts","affectContexts","affectDepsContextNames","arg","updateContextItem","updateValue","filter","affectContextItem","triggerEvent","contexts","_context$eventTarget","context","eventTarget","dispatchEvent","CustomEvent","detail","callback","callbackRuntimeContext","load","promise","loaded","Promise","resolve","loading","cache","then","val","err","error","handleHttpError","callbackFactory","eventCallbackFactory","isObject","assign","console","warn","define","dataConfs","runtimeContext","asyncHostPropertyEntries","Array","isArray","pending","resolveDataStore","dataConf","onChange","dataName","listener","_this$data$get2","addEventListener","waitFor","dataNames","pendingContexts","all","ctx","p","waitForAll","pendingResult","handleAsyncAfterMount","async","asyncCheckIf","expose","computePropertyValue","resolvePolicy","undefined","resolveConf","transform","options","resolveData","lazy","hasOwnProperty","asyncComputeRealValue","newData","EventTarget","trigger","_this$rendererContext","registerArbitraryLifeCycle","listenerFactory","track","strictCollectMemberUsage","dep","batchAddListener","computeRealValue","has","set","contextConf","event","exports"],"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 AsyncPropertyEntry,\n RuntimeBrick,\n RuntimeContext,\n} from \"../interfaces.js\";\nimport { handleHttpError } from \"../../handleHttpError.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.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 getAllValues(): Record<string, unknown> {\n return Object.fromEntries(\n [...this.data.entries()].map(([name, { value }]) => [name, value])\n );\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 asyncHostPropertyEntries?: AsyncPropertyEntry[]\n ): void {\n if (Array.isArray(dataConfs) && dataConfs.length > 0) {\n const pending = resolveDataStore(\n dataConfs,\n (dataConf: ContextConf) =>\n this.resolve(dataConf, runtimeContext, asyncHostPropertyEntries),\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 asyncHostPropertyEntries?: AsyncPropertyEntry[]\n ): Promise<boolean> {\n if (!(await asyncCheckIf(dataConf, runtimeContext))) {\n return false;\n }\n let value: unknown;\n if (\n asyncHostPropertyEntries &&\n (this.type === \"STATE\" ? dataConf.expose : this.type === \"FORM_STATE\")\n ) {\n value = await computePropertyValue(\n asyncHostPropertyEntries,\n dataConf.name\n );\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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAIA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAMA,IAAAO,gBAAA,GAAAP,OAAA;AAEA,IAAAQ,sBAAA,GAAAR,OAAA;AAEA,MAAMS,0CAA0C,GAAG,CACjD,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,gBAAgB,CACwB;AAcnC,MAAMC,SAAS,CAAkC;EACrCC,IAAI;EACJC,IAAI,GAAG,IAAIC,GAAG,CAAwB,CAAC;EACvCC,eAAe;EACfC,YAAY,GAC3B,EAAE;EACYC,SAAS;EAClBC,WAAW,GAAG,KAAK;EACnBC,wBAAwB,GAAa,EAAE;EAC7BC,eAAe;;EAEhC;EACAC,WAAWA,CACTT,IAAO,EACPK,SAAwB,EACxBG,eAAiC,EACjC;IACA,IAAI,CAACR,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACG,eAAe,GAClB,IAAI,CAACH,IAAI,KAAK,YAAY,GACtB,kBAAkB,GAClB,IAAI,CAACA,IAAI,KAAK,OAAO,GACrB,cAAc,GACd,gBAAgB;IACtB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,EACb,IAAAyG,kCAAgB,EAACtC,QAAQ,CAAClE,KAAK,EAAE4D,cAAc,CAAC,EAChD,SACF,CAAC;UACH;QACF,CAAC,EAAEM,QAAQ,CACb,CAAC;MACH;IACF;IAEA,IAAI,IAAI,CAACjF,IAAI,CAACwH,GAAG,CAACvC,QAAQ,CAACnE,IAAI,CAAC,EAAE;MAChC,MAAM,IAAIsB,KAAK,CACZ,GAAE,IAAI,CAACrC,IAAK,KAAIkF,QAAQ,CAACnE,IAAK,6BACjC,CAAC;IACH;IACA,IAAI,CAACd,IAAI,CAACyH,GAAG,CAACxC,QAAQ,CAACnE,IAAI,EAAE+F,OAAO,CAAC;IAErC,OAAO,IAAI;EACb;EAEQS,gBAAgBA,CACtBlC,QAAuB,EACvBsC,WAAwB,EACT;IACf,OAAQC,KAA0B,IAAW;MAC3C,IACE,IAAI,CAACtH,WAAW,IAChB,IAAI,CAACC,wBAAwB,CAACqB,QAAQ,CAAC+F,WAAW,CAAC5G,IAAI,CAAC,EACxD;QACA;MACF;MACAsE,QAAQ,CAACuC,KAAK,CAAC;IACjB,CAAC;EACH;AACF;AAACC,OAAA,CAAA9H,SAAA,GAAAA,SAAA"}
@@ -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 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\nexport interface DataValueOption {\n tplStateStoreId?: string;\n}\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 AsyncPropertyEntry = [\n name: string,\n value: Promise<unknown>,\n ignoreUndefined?: boolean\n];\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 asyncHostPropertyEntries: AsyncPropertyEntry[];\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\nexport interface DataValueOption {\n tplStateStoreId?: string;\n}\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","Symbol","for","symbolForTplStateStoreId","symbolForTPlExternalForEachItem"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncComputedProperties } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncComputedProperties;\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n}\n"],"mappings":"AAGA,OAAO,IAAMA,mCAAmC,GAAGC,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AACD,OAAO,IAAMC,wBAAwB,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AACtE,OAAO,IAAME,+BAA+B,GAAGH,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC"}
1
+ {"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","Symbol","for","symbolForTplStateStoreId","symbolForTPlExternalForEachItem"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncPropertyEntry } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n}\n"],"mappings":"AAGA,OAAO,IAAMA,mCAAmC,GAAGC,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AACD,OAAO,IAAMC,wBAAwB,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AACtE,OAAO,IAAME,+BAA+B,GAAGH,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC"}
@@ -9,7 +9,7 @@ import { setupTemplateProxy } from "./setupTemplateProxy.js";
9
9
  import { setupUseBrickInTemplate } from "./setupUseBrickInTemplate.js";
10
10
  import { childrenToSlots } from "../Renderer.js";
11
11
  import { hooks } from "../Runtime.js";
12
- export function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostProperties, rendererContext) {
12
+ export function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
13
13
  var _hooks$flowApi;
14
14
  var tplStateStoreId = uniqueId("tpl-state-");
15
15
  var runtimeContext = _objectSpread(_objectSpread({}, hostBrick.runtimeContext), {}, {
@@ -31,7 +31,7 @@ export function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHost
31
31
  contracts
32
32
  } = customTemplates.get(tplTagName);
33
33
  hooks === null || hooks === void 0 || (_hooks$flowApi = hooks.flowApi) === null || _hooks$flowApi === void 0 ? void 0 : _hooks$flowApi.collectWidgetContract(contracts);
34
- tplStateStore.define(state, runtimeContext, asyncHostProperties);
34
+ tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);
35
35
  var {
36
36
  slots: originalExternalSlots,
37
37
  children: externalChildren
@@ -81,7 +81,7 @@ export function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHost
81
81
  }
82
82
  var hostContext = {
83
83
  reversedProxies,
84
- asyncHostProperties,
84
+ asyncHostPropertyEntries,
85
85
  externalSlots: childrenToSlots(externalChildren, originalExternalSlots),
86
86
  tplStateStoreId,
87
87
  hostBrick: hostBrick
@@ -1 +1 @@
1
- {"version":3,"file":"expandCustomTemplate.js","names":["uniqueId","customTemplates","DataStore","setupTemplateProxy","setupUseBrickInTemplate","childrenToSlots","hooks","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostProperties","rendererContext","_hooks$flowApi","tplStateStoreId","runtimeContext","_objectSpread","forEachItem","formStateStoreId","tplStateStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","get","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","_objectWithoutProperties","_excluded","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","_excluded2","transpiledSlots","fromEntries","_ref","_slotConf$bricks","slotName","slotConf"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties,\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick, rendererContext);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostProperties);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostProperties,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;AAOA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAEhD,SAASC,kBAAkB,QAAQ,yBAAyB;AAO5D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,KAAK,QAAQ,eAAe;AAGrC,OAAO,SAASC,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,mBAAoC,EACpCC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,IAAMC,eAAe,GAAGd,QAAQ,CAAC,YAAY,CAAC;EAC9C,IAAMe,cAAc,GAAAC,aAAA,CAAAA,aAAA,KACfN,SAAS,CAACK,cAAc;IAC3BD;EAAe,EAChB;;EAED;EACA,OAAOC,cAAc,CAACE,WAAW;EACjC,OAAOF,cAAc,CAACG,gBAAgB;EAEtC,IAAMC,aAAa,GAAG,IAAIjB,SAAS,CAAC,OAAO,EAAEQ,SAAS,EAAEE,eAAe,CAAC;EACxEG,cAAc,CAACK,gBAAgB,CAACC,GAAG,CAACP,eAAe,EAAEK,aAAa,CAAC;EACnE,IAAIJ,cAAc,CAACO,kBAAkB,EAAE;IACrCP,cAAc,CAACO,kBAAkB,CAACC,IAAI,CAACJ,aAAa,CAAC;EACvD;EAEA,IAAM;IAAEK,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAG1B,eAAe,CAAC2B,GAAG,CAACpB,UAAU,CAAE;EAC5EF,KAAK,aAALA,KAAK,gBAAAO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AAGgB,MAAM,CAACiB,WAAW,CACjDjB,MAAM,CAACC,OAAO,CAACe,eAAe,aAAfA,eAAe,cAAfA,eAAe,GAAI,CAAC,CAAC,CAAC,CAACT,GAAG,CAACW,IAAA;IAAA,IAAAC,gBAAA;IAAA,IAAC,CAACC,QAAQ,EAAEC,QAAQ,CAAC,GAAAH,IAAA;IAAA,OAAK,CAClEE,QAAQ,EACR;MACEd,IAAI,EAAE,QAAQ;MACd9B,MAAM,EAAE,EAAA2C,gBAAA,GAACE,QAAQ,CAAC7C,MAAM,cAAA2C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEJ,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAApC,aAAA,CAAAA,aAAA,KACK8C,uBAAuB;IAC1BjB,UAAU,EAAEzC,uBAAuB,CAACyC,UAAU,EAAEO,WAAW,CAAC;IAC5DpB;EAAK,GACF7B,kBAAkB,CAACiD,WAAW,EAAEU,uBAAuB,CAACX,GAAG,EAAEnB,KAAK,CAAC;AAE1E"}
1
+ {"version":3,"file":"expandCustomTemplate.js","names":["uniqueId","customTemplates","DataStore","setupTemplateProxy","setupUseBrickInTemplate","childrenToSlots","hooks","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","runtimeContext","_objectSpread","forEachItem","formStateStoreId","tplStateStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","get","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","_objectWithoutProperties","_excluded","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","_excluded2","transpiledSlots","fromEntries","_ref","_slotConf$bricks","slotName","slotConf"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick, rendererContext);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;AAOA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAEhD,SAASC,kBAAkB,QAAQ,yBAAyB;AAO5D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,KAAK,QAAQ,eAAe;AAGrC,OAAO,SAASC,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,IAAMC,eAAe,GAAGd,QAAQ,CAAC,YAAY,CAAC;EAC9C,IAAMe,cAAc,GAAAC,aAAA,CAAAA,aAAA,KACfN,SAAS,CAACK,cAAc;IAC3BD;EAAe,EAChB;;EAED;EACA,OAAOC,cAAc,CAACE,WAAW;EACjC,OAAOF,cAAc,CAACG,gBAAgB;EAEtC,IAAMC,aAAa,GAAG,IAAIjB,SAAS,CAAC,OAAO,EAAEQ,SAAS,EAAEE,eAAe,CAAC;EACxEG,cAAc,CAACK,gBAAgB,CAACC,GAAG,CAACP,eAAe,EAAEK,aAAa,CAAC;EACnE,IAAIJ,cAAc,CAACO,kBAAkB,EAAE;IACrCP,cAAc,CAACO,kBAAkB,CAACC,IAAI,CAACJ,aAAa,CAAC;EACvD;EAEA,IAAM;IAAEK,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAG1B,eAAe,CAAC2B,GAAG,CAACpB,UAAU,CAAE;EAC5EF,KAAK,aAALA,KAAK,gBAAAO,cAAA,GAALP,KAAK,CAAEuB,OAAO,cAAAhB,cAAA,uBAAdA,cAAA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e,aAAfA,eAAe,cAAfA,eAAe,GAAI,CAAC,CAAC,CAAC,CAACT,GAAG,CAACW,IAAA;IAAA,IAAAC,gBAAA;IAAA,IAAC,CAACC,QAAQ,EAAEC,QAAQ,CAAC,GAAAH,IAAA;IAAA,OAAK,CAClEE,QAAQ,EACR;MACEd,IAAI,EAAE,QAAQ;MACd9B,MAAM,EAAE,EAAA2C,gBAAA,GAACE,QAAQ,CAAC7C,MAAM,cAAA2C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEJ,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAApC,aAAA,CAAAA,aAAA,KACK8C,uBAAuB;IAC1BjB,UAAU,EAAEzC,uBAAuB,CAACyC,UAAU,EAAEO,WAAW,CAAC;IAC5DpB;EAAK,GACF7B,kBAAkB,CAACiD,WAAW,EAAEU,uBAAuB,CAACX,GAAG,EAAEnB,KAAK,CAAC;AAE1E"}
@@ -1,12 +1,12 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
2
  import { hasOwnProperty } from "@next-core/utils/general";
4
3
  import { clamp } from "lodash";
5
4
  import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachItem, symbolForTplStateStoreId } from "./constants.js";
5
+ import { computePropertyValue } from "../compute/computeRealProperties.js";
6
6
  export function setupTemplateProxy(hostContext, ref, slots) {
7
7
  var {
8
8
  reversedProxies,
9
- asyncHostProperties,
9
+ asyncHostPropertyEntries,
10
10
  externalSlots,
11
11
  tplStateStoreId,
12
12
  hostBrick
@@ -15,27 +15,19 @@ export function setupTemplateProxy(hostContext, ref, slots) {
15
15
  if (ref && reversedProxies) {
16
16
  var propertyProxies = reversedProxies.properties.get(ref);
17
17
  if (propertyProxies) {
18
- var getComputedProps = /*#__PURE__*/function () {
19
- var _ref = _asyncToGenerator(function* (asyncHostProps) {
20
- var props = {};
21
- for (var {
18
+ var getComputedProps = asyncHostProps => {
19
+ return propertyProxies.map(_ref => {
20
+ var {
22
21
  from,
23
22
  to
24
- } of propertyProxies) {
25
- if (hasOwnProperty(asyncHostProps, from) && to.refProperty) {
26
- var propValue = yield asyncHostProps[from];
27
- if (propValue !== undefined) {
28
- props[to.refProperty] = propValue;
29
- }
30
- }
23
+ } = _ref;
24
+ var filtered = asyncHostProps.filter(entry => entry[0] === from);
25
+ if (filtered.length > 0 && to.refProperty) {
26
+ return [to.refProperty, computePropertyValue(filtered, from), true];
31
27
  }
32
- return props;
33
- });
34
- return function getComputedProps(_x) {
35
- return _ref.apply(this, arguments);
36
- };
37
- }();
38
- asyncComputedProps = getComputedProps(asyncHostProperties);
28
+ }).filter(Boolean);
29
+ };
30
+ asyncComputedProps = getComputedProps(asyncHostPropertyEntries);
39
31
  }
40
32
  var slotProxies = reversedProxies.slots.get(ref);
41
33
  if (slotProxies && externalSlots) {
@@ -1 +1 @@
1
- {"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachItem","symbolForTplStateStoreId","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostProperties","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","_ref","_asyncToGenerator","asyncHostProps","props","from","to","refProperty","propValue","undefined","_x","apply","arguments","slotProxies","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","length","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","runtimeContext","setupTemplateExternalBricks","forEachItem","_loop","slotName","type","slotConf","quasis","flatMap","index","concat","entries","map","brick","_brick$slots","_objectSpread","Object","fromEntries","_ref2","_slotConf$bricks","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachItem,\n symbolForTplStateStoreId,\n} from \"./constants.js\";\nimport type {\n AsyncComputedProperties,\n AsyncProperties,\n TemplateHostContext,\n} from \"../interfaces.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostProperties,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncComputedProperties | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = async (\n asyncHostProps: AsyncProperties\n ): AsyncComputedProperties => {\n const props: Record<string, unknown> = {};\n for (const { from, to } of propertyProxies) {\n if (hasOwnProperty(asyncHostProps, from) && to.refProperty) {\n const propValue = await asyncHostProps[from];\n if (propValue !== undefined) {\n props[to.refProperty] = propValue;\n }\n }\n }\n return props;\n };\n\n asyncComputedProps = getComputedProps(asyncHostProperties);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(hasOwnProperty(hostBrick.runtimeContext, \"forEachItem\")\n ? setupTemplateExternalBricks(\n insertBricks,\n hostBrick.runtimeContext.forEachItem\n )\n : insertBricks)\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n forEachItem: unknown\n): BrickConf[] {\n return bricks.map((brick) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n slots: Object.fromEntries(\n Object.entries(brick.slots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks ?? [],\n forEachItem\n ),\n },\n ])\n ),\n }));\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n forEachItem: unknown\n): RouteConf[] {\n return routes.map((route) =>\n route.type && route.type !== \"bricks\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(route.bricks, forEachItem),\n }\n );\n}\n"],"mappings":";;AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9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AW,CACvBD,MAAM,CAACL,OAAO,EAAAG,YAAA,GAACD,KAAK,CAACtD,KAAK,cAAAuD,YAAA,cAAAA,YAAA,GAAI,CAAC,CAAC,CAAC,CAACF,GAAG,CAACM,KAAA;QAAA,IAAAC,gBAAA;QAAA,IAAC,CAACf,QAAQ,EAAEE,QAAQ,CAAC,GAAAY,KAAA;QAAA,OAAK,CAC9Dd,QAAQ,EACRE,QAAQ,CAACD,IAAI,KAAK,QAAQ,GACtB;UACEA,IAAI,EAAE,QAAQ;UACde,MAAM,EAAEC,2BAA2B,CAACf,QAAQ,CAACc,MAAM,EAAElB,WAAW;QAClE,CAAC,GACD;UACEG,IAAI,EAAE,QAAQ;UACdf,MAAM,EAAEW,2BAA2B,EAAAkB,gBAAA,GACjCb,QAAQ,CAAChB,MAAM,cAAA6B,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EACrBjB,WACF;QACF,CAAC,CACN;MAAA,EACH;IAAC;EAAA,CACD,CAAC;AACL;AAEA,SAASmB,2BAA2BA,CAClCD,MAAmB,EACnBlB,WAAoB,EACP;EACb,OAAOkB,MAAM,CAACR,GAAG,CAAEU,KAAK,IACtBA,KAAK,CAACjB,IAAI,IAAIiB,KAAK,CAACjB,IAAI,KAAK,QAAQ,GACjCiB,KAAK,GAAAP,aAAA,CAAAA,aAAA,KAEAO,KAAK;IACRhC,MAAM,EAAEW,2BAA2B,CAACqB,KAAK,CAAChC,MAAM,EAAEY,WAAW;EAAC,EAEtE,CAAC;AACH"}
1
+ {"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachItem","symbolForTplStateStoreId","computePropertyValue","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","_ref","from","to","filtered","filter","entry","length","refProperty","Boolean","slotProxies","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","runtimeContext","setupTemplateExternalBricks","forEachItem","_loop","slotName","type","slotConf","quasis","flatMap","index","concat","entries","brick","_brick$slots","_objectSpread","Object","fromEntries","_ref2","_slotConf$bricks","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachItem,\n symbolForTplStateStoreId,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(hasOwnProperty(hostBrick.runtimeContext, \"forEachItem\")\n ? setupTemplateExternalBricks(\n insertBricks,\n hostBrick.runtimeContext.forEachItem\n )\n : insertBricks)\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n forEachItem: unknown\n): BrickConf[] {\n return bricks.map((brick) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n slots: Object.fromEntries(\n Object.entries(brick.slots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks ?? [],\n forEachItem\n ),\n },\n ])\n ),\n }));\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n forEachItem: unknown\n): RouteConf[] {\n return routes.map((route) =>\n route.type && route.type !== \"bricks\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(route.bricks, forEachItem),\n }\n );\n}\n"],"mappings":";AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,+BAA+B,EAC/BC,wBAAwB,QACnB,gBAAgB;AAEvB,SAASC,oBAAoB,QAAQ,qCAAqC;AAE1E,OAAO,SAASC,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,IAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAAoD;EAExD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,IAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,IAAMG,gBAAgB,GACpBC,cAAoC,IACX;QACzB,OAAOJ,eAAe,CACnBK,GAAG,CAACC,IAAA,IAAkB;UAAA,IAAjB;YAAEC,IAAI;YAAEC;UAAG,CAAC,GAAAF,IAAA;UAChB,IAAMG,QAAQ,GAAGL,cAAc,CAACM,MAAM,CACnCC,KAAK,IAAKA,KAAK,CAAC,CAAC,CAAC,KAAKJ,IAC1B,CAAC;UACD,IAAIE,QAAQ,CAACG,MAAM,GAAG,CAAC,IAAIJ,EAAE,CAACK,WAAW,EAAE;YACzC,OAAO,CACLL,EAAE,CAACK,WAAW,EACdxB,oBAAoB,CAACoB,QAAQ,EAAEF,IAAI,CAAC,EACpC,IAAI,CACL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tE,CAAC;AACH"}
@@ -5,7 +5,7 @@ import { DataStore } from "../data/DataStore.js";
5
5
  import { getDefaultProperties } from "./getDefaultProperties.js";
6
6
  import { symbolForFormStateStoreId } from "./constants.js";
7
7
  var formContainers = ["forms.general-form", "form.general-form", "eo-form"];
8
- export function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostProperties, rendererContext) {
8
+ export function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
9
9
  var _normalizedFormData$c, _hostBrickConf$proper;
10
10
  var normalizedFormData = typeof formData === "string" ? JSON.parse(formData) : formData;
11
11
  var formStateStoreId = uniqueId("form-state-");
@@ -29,7 +29,7 @@ export function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHost
29
29
  name: "params"
30
30
  });
31
31
  }
32
- formStateStore.define(context, runtimeContext, asyncHostProperties);
32
+ formStateStore.define(context, runtimeContext, asyncHostPropertyEntries);
33
33
  var formConf = formSchemaToBrick(normalizedFormData.formSchema, normalizedFormData.fields, formStateStoreId);
34
34
  if (formContainers.includes(formConf.brick) && hostBrickConf.events) {
35
35
  formConf.events = mergeEvents(formConf.events, hostBrickConf.events);
@@ -1 +1 @@
1
- {"version":3,"file":"expandFormRenderer.js","names":["hasOwnProperty","uniqueId","DataStore","getDefaultProperties","symbolForFormStateStoreId","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostProperties","rendererContext","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","runtimeContext","_objectSpread","forEachItem","tplStateStoreId","formStateStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","brickConf","slot","formSchemasToBricks","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncProperties, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst formContainers = [\"forms.general-form\", \"form.general-form\", \"eo-form\"];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties,\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext\n );\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostProperties);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formContainers.includes(formConf.brick) && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"eo-micro-view\",\n properties: { style: { padding: \"12px\" } },\n children: [formConf],\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,SAAS,QAAQ,sBAAsB;AAOhD,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE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AAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAO9B,MAAM;AACf"}
1
+ {"version":3,"file":"expandFormRenderer.js","names":["hasOwnProperty","uniqueId","DataStore","getDefaultProperties","symbolForFormStateStoreId","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","runtimeContext","_objectSpread","forEachItem","tplStateStoreId","formStateStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","brickConf","slot","formSchemasToBricks","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncPropertyEntry, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst formContainers = [\"forms.general-form\", \"form.general-form\", \"eo-form\"];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext\n );\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostPropertyEntries);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formContainers.includes(formConf.brick) && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"eo-micro-view\",\n properties: { style: { padding: \"12px\" } },\n children: [formConf],\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,SAAS,QAAQ,sBAAsB;AAOhD,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,yBAAyB,QAAQ,gBAAgB;AAG1D,IAAMC,cAAc,GAAG,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,SAAS,CAAC;AAE7E,OAAO,SAASC,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EACrB;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EACX,IAAMC,kBAAkB,GACtB,OAAOP,QAAQ,KAAK,QAAQ,GAAGQ,IAAI,CAACC,KAAK,CAACT,QAAQ,CAAC,GAAGA,QACjC;EAEvB,IAAMU,gBAAgB,GAAGhB,QAAQ,CAAC,aAAa,CAAC;EAChD,IAAMiB,cAAc,GAAAC,aAAA,CAAAA,aAAA,KACfV,SAAS,CAACS,cAAc;IAC3BD;EAAgB,EACjB;;EAED;EACA,OAAOC,cAAc,CAACE,WAAW;EACjC,OAAOF,cAAc,CAACG,eAAe;EAErC,IAAMC,cAAc,GAAG,IAAIpB,S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AS;AAClB;AAEA,SAASE,mBAAmBA,CAC1BE,OAA2C,EAC3C1B,MAAyB,EACzBnB,gBAAwB,EACC;EACzB,IAAI8C,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAAE;IAC1B,OAAOA,OAAO,CAACG,GAAG,CAAElB,MAAM,IACxBb,iBAAiB,CAACa,MAAM,EAAEX,MAAM,EAAEnB,gBAAgB,CACpD,CAAC;EACH;AACF;AAEA,SAASuB,WAAWA,CAClB0B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,IAAM5B,MAAM,GAAG2B,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,CAAC,CAAC;EAEjC,KAAK,IAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChE5B,MAAM,CAAC6B,SAAS,CAAC,GAAGpE,cAAc,CAACuC,MAAM,EAAE6B,SAAS,CAAC,GACjD,CAAC7B,MAAM,CAAC6B,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAO9B,MAAM;AACf"}
@@ -9,7 +9,7 @@ import { isTrackAll } from "@next-core/cook";
9
9
  import { hasOwnProperty } from "@next-core/utils/general";
10
10
  import { debounce } from "lodash";
11
11
  import { asyncCheckBrickIf } from "./compute/checkIf.js";
12
- import { asyncComputeRealProperties, constructAsyncProperties } from "./compute/computeRealProperties.js";
12
+ import { asyncComputeRealPropertyEntries, constructAsyncProperties } from "./compute/computeRealProperties.js";
13
13
  import { resolveData } from "./data/resolveData.js";
14
14
  import { asyncComputeRealValue } from "./compute/computeRealValue.js";
15
15
  import { listenOnTrackingContext } from "./compute/listenOnTrackingContext.js";
@@ -330,17 +330,14 @@ function _renderBrick() {
330
330
  // 加载构件属性和加载子构件等任务,可以并行。
331
331
  var blockingList = [];
332
332
  var trackingContextList = [];
333
- var asyncProperties = asyncComputeRealProperties(confProps, runtimeContext, trackingContextList);
333
+ var asyncPropertyEntries = asyncComputeRealPropertyEntries(confProps, runtimeContext, trackingContextList);
334
+ var computedPropsFromHost = brickConf[symbolForAsyncComputedPropsFromHost];
335
+ if (computedPropsFromHost) {
336
+ asyncPropertyEntries.push(...computedPropsFromHost);
337
+ }
334
338
  var loadProperties = /*#__PURE__*/function () {
335
339
  var _ref4 = _asyncToGenerator(function* () {
336
- brick.properties = yield constructAsyncProperties(asyncProperties);
337
- var computedPropsFromHost = brickConf[symbolForAsyncComputedPropsFromHost];
338
- if (computedPropsFromHost) {
339
- var computed = yield computedPropsFromHost;
340
- for (var [propName, propValue] of Object.entries(computed)) {
341
- brick.properties[propName] = propValue;
342
- }
343
- }
340
+ brick.properties = yield constructAsyncProperties(asyncPropertyEntries);
344
341
  listenOnTrackingContext(brick, trackingContextList);
345
342
  return brick.properties;
346
343
  });
@@ -352,9 +349,9 @@ function _renderBrick() {
352
349
  rendererContext.registerBrickLifeCycle(brick, brickConf.lifeCycle);
353
350
  var expandedBrickConf = brickConf;
354
351
  if (tplTagName) {
355
- expandedBrickConf = expandCustomTemplate(tplTagName, brickConf, brick, asyncProperties, rendererContext);
352
+ expandedBrickConf = expandCustomTemplate(tplTagName, brickConf, brick, asyncPropertyEntries, rendererContext);
356
353
  } else if (brickName === FORM_RENDERER) {
357
- expandedBrickConf = expandFormRenderer(formData, brickConf, brick, asyncProperties, rendererContext);
354
+ expandedBrickConf = expandFormRenderer(formData, brickConf, brick, asyncPropertyEntries, rendererContext);
358
355
  }
359
356
  if (expandedBrickConf.portal) {
360
357
  // A portal brick has no slotId.