@webiny/website-builder-sdk 6.6.0-alpha.1 → 6.6.0-alpha.11

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 (198) hide show
  1. package/BindingsResolver.d.ts +4 -1
  2. package/BindingsResolver.js.map +1 -1
  3. package/ComponentInputTraverser.js +1 -0
  4. package/ComponentInputTraverser.js.map +1 -1
  5. package/ComponentManifestToAstConverter.d.ts +23 -1
  6. package/ComponentManifestToAstConverter.js +122 -2
  7. package/ComponentManifestToAstConverter.js.map +1 -1
  8. package/ComponentRegistry.d.ts +2 -1
  9. package/ComponentRegistry.js +7 -0
  10. package/ComponentRegistry.js.map +1 -1
  11. package/ComponentResolver.d.ts +6 -3
  12. package/ComponentResolver.js +9 -4
  13. package/ComponentResolver.js.map +1 -1
  14. package/ConstraintEvaluator.d.ts +5 -0
  15. package/ConstraintEvaluator.js +20 -4
  16. package/ConstraintEvaluator.js.map +1 -1
  17. package/ConstraintEvaluator.test.js +137 -0
  18. package/ConstraintEvaluator.test.js.map +1 -1
  19. package/ContentSdk.d.ts +64 -2
  20. package/ContentSdk.js +90 -12
  21. package/ContentSdk.js.map +1 -1
  22. package/DocumentStoreManager.d.ts +9 -2
  23. package/DocumentStoreManager.js +24 -5
  24. package/DocumentStoreManager.js.map +1 -1
  25. package/EditingSdk.d.ts +18 -2
  26. package/EditingSdk.js +30 -5
  27. package/EditingSdk.js.map +1 -1
  28. package/ElementBindings.d.ts +28 -0
  29. package/ElementBindings.js +88 -0
  30. package/ElementBindings.js.map +1 -0
  31. package/ElementBindings.test.d.ts +1 -0
  32. package/ElementBindings.test.js +127 -0
  33. package/ElementBindings.test.js.map +1 -0
  34. package/ElementFactory.d.ts +10 -1
  35. package/ElementFactory.js +38 -7
  36. package/ElementFactory.js.map +1 -1
  37. package/ElementFactory.test.js +260 -0
  38. package/ElementFactory.test.js.map +1 -1
  39. package/ElementSelection.d.ts +20 -0
  40. package/ElementSelection.js +32 -0
  41. package/ElementSelection.js.map +1 -0
  42. package/ElementSelection.test.d.ts +1 -0
  43. package/ElementSelection.test.js +73 -0
  44. package/ElementSelection.test.js.map +1 -0
  45. package/Environment.d.ts +7 -0
  46. package/Environment.js +2 -1
  47. package/Environment.js.map +1 -1
  48. package/Environment.test.d.ts +1 -0
  49. package/Environment.test.js +39 -0
  50. package/Environment.test.js.map +1 -0
  51. package/GlobalComponentLanguage.d.ts +31 -0
  52. package/GlobalComponentLanguage.js +37 -0
  53. package/GlobalComponentLanguage.js.map +1 -0
  54. package/InheritanceProcessor.test.js +8 -0
  55. package/InheritanceProcessor.test.js.map +1 -1
  56. package/InheritedValueResolver.d.ts +6 -0
  57. package/InheritedValueResolver.js +7 -0
  58. package/InheritedValueResolver.js.map +1 -1
  59. package/InputBindingsProcessor.js +6 -2
  60. package/InputBindingsProcessor.js.map +1 -1
  61. package/InputRenderer.test.d.ts +1 -0
  62. package/InputRenderer.test.js +186 -0
  63. package/InputRenderer.test.js.map +1 -0
  64. package/InputsBindingsProcessor.test.js +130 -0
  65. package/InputsBindingsProcessor.test.js.map +1 -1
  66. package/InputsUpdater.js +1 -0
  67. package/InputsUpdater.js.map +1 -1
  68. package/LayoutContentArea.d.ts +68 -0
  69. package/LayoutContentArea.js +78 -0
  70. package/LayoutContentArea.js.map +1 -0
  71. package/LayoutContentArea.test.d.ts +1 -0
  72. package/LayoutContentArea.test.js +111 -0
  73. package/LayoutContentArea.test.js.map +1 -0
  74. package/LiveSdk.d.ts +5 -2
  75. package/LiveSdk.js +6 -2
  76. package/LiveSdk.js.map +1 -1
  77. package/NullSdk.d.ts +2 -1
  78. package/NullSdk.js +3 -0
  79. package/NullSdk.js.map +1 -1
  80. package/PreviewDocument.d.ts +2 -1
  81. package/PreviewDocument.js +2 -2
  82. package/PreviewDocument.js.map +1 -1
  83. package/PreviewSdk.d.ts +5 -2
  84. package/PreviewSdk.js +6 -2
  85. package/PreviewSdk.js.map +1 -1
  86. package/PreviewViewport.d.ts +5 -0
  87. package/PreviewViewport.js +9 -0
  88. package/PreviewViewport.js.map +1 -1
  89. package/PreviewViewport.test.d.ts +1 -0
  90. package/PreviewViewport.test.js +27 -0
  91. package/PreviewViewport.test.js.map +1 -0
  92. package/RadioOptionInputs.test.d.ts +1 -0
  93. package/RadioOptionInputs.test.js +521 -0
  94. package/RadioOptionInputs.test.js.map +1 -0
  95. package/ResizeObserver.js +1 -1
  96. package/ResizeObserver.js.map +1 -1
  97. package/StylesUpdater.js +4 -1
  98. package/StylesUpdater.js.map +1 -1
  99. package/asset/deliveryUrl.test.js +1 -1
  100. package/asset/deliveryUrl.test.js.map +1 -1
  101. package/asset/imageSrcSet.test.js +1 -1
  102. package/asset/imageSrcSet.test.js.map +1 -1
  103. package/asset/normalize.d.ts +1 -1
  104. package/asset/normalize.js +18 -14
  105. package/asset/normalize.js.map +1 -1
  106. package/asset/normalize.test.js +15 -8
  107. package/asset/normalize.test.js.map +1 -1
  108. package/componentLoader/ComponentLoader.d.ts +16 -0
  109. package/componentLoader/ComponentLoader.js +0 -0
  110. package/componentLoader/RegistryOnlyComponentLoader.d.ts +9 -0
  111. package/componentLoader/RegistryOnlyComponentLoader.js +8 -0
  112. package/componentLoader/RegistryOnlyComponentLoader.js.map +1 -0
  113. package/componentLoader/createComponentLoader.d.ts +7 -0
  114. package/componentLoader/createComponentLoader.js +10 -0
  115. package/componentLoader/createComponentLoader.js.map +1 -0
  116. package/componentLoader/defaultComponentLoader.d.ts +7 -0
  117. package/componentLoader/defaultComponentLoader.js +8 -0
  118. package/componentLoader/defaultComponentLoader.js.map +1 -0
  119. package/componentLoader/index.d.ts +3 -0
  120. package/componentLoader/index.js +3 -0
  121. package/contentClientState.test.d.ts +1 -0
  122. package/contentClientState.test.js +404 -0
  123. package/contentClientState.test.js.map +1 -0
  124. package/contentEntry/ContentEntryBindingsResolver.d.ts +33 -0
  125. package/contentEntry/ContentEntryBindingsResolver.js +52 -0
  126. package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
  127. package/contentEntry/ContentEntryCache.d.ts +49 -0
  128. package/contentEntry/ContentEntryCache.js +51 -0
  129. package/contentEntry/ContentEntryCache.js.map +1 -0
  130. package/contentEntry/resolveContentEntry.d.ts +74 -0
  131. package/contentEntry/resolveContentEntry.js +53 -0
  132. package/contentEntry/resolveContentEntry.js.map +1 -0
  133. package/contentEntry/resolveContentEntry.test.d.ts +1 -0
  134. package/contentEntry/resolveContentEntry.test.js +213 -0
  135. package/contentEntry/resolveContentEntry.test.js.map +1 -0
  136. package/createContentClient.d.ts +17 -0
  137. package/createContentClient.js +16 -0
  138. package/createContentClient.js.map +1 -0
  139. package/createContentClient.test.d.ts +1 -0
  140. package/createContentClient.test.js +165 -0
  141. package/createContentClient.test.js.map +1 -0
  142. package/createGlobalElementDocument.d.ts +6 -0
  143. package/createGlobalElementDocument.js +23 -0
  144. package/createGlobalElementDocument.js.map +1 -0
  145. package/createInput.d.ts +10 -2
  146. package/createInput.js +8 -1
  147. package/createInput.js.map +1 -1
  148. package/dataProviders/ApiClient.d.ts +3 -0
  149. package/dataProviders/ApiClient.js +23 -5
  150. package/dataProviders/ApiClient.js.map +1 -1
  151. package/dataProviders/ApiClient.test.d.ts +1 -0
  152. package/dataProviders/ApiClient.test.js +116 -0
  153. package/dataProviders/ApiClient.test.js.map +1 -0
  154. package/dataProviders/DefaultDataProvider.d.ts +2 -1
  155. package/dataProviders/DefaultDataProvider.js +12 -0
  156. package/dataProviders/DefaultDataProvider.js.map +1 -1
  157. package/dataProviders/DefaultDataProvider.test.d.ts +1 -0
  158. package/dataProviders/DefaultDataProvider.test.js +81 -0
  159. package/dataProviders/DefaultDataProvider.test.js.map +1 -0
  160. package/dataProviders/GET_LAYOUT_BY_SLUG.d.ts +1 -0
  161. package/dataProviders/GET_LAYOUT_BY_SLUG.js +27 -0
  162. package/dataProviders/GET_LAYOUT_BY_SLUG.js.map +1 -0
  163. package/dataProviders/GET_PAGE_BY_ID.d.ts +1 -1
  164. package/dataProviders/GET_PAGE_BY_ID.js +7 -0
  165. package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
  166. package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -1
  167. package/dataProviders/GET_PAGE_BY_PATH.js +7 -0
  168. package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
  169. package/dataProviders/NullDataProvider.d.ts +2 -1
  170. package/dataProviders/NullDataProvider.js +3 -0
  171. package/dataProviders/NullDataProvider.js.map +1 -1
  172. package/dataProviders/queries.test.d.ts +1 -0
  173. package/dataProviders/queries.test.js +53 -0
  174. package/dataProviders/queries.test.js.map +1 -0
  175. package/experiments/render.d.ts +3 -0
  176. package/experiments/render.js +1 -1
  177. package/experiments/render.js.map +1 -1
  178. package/globalElements.d.ts +43 -0
  179. package/globalElements.js +79 -0
  180. package/globalElements.js.map +1 -0
  181. package/globalElements.test.d.ts +1 -0
  182. package/globalElements.test.js +343 -0
  183. package/globalElements.test.js.map +1 -0
  184. package/headersProvider.d.ts +1 -2
  185. package/headersProvider.js.map +1 -1
  186. package/index.d.ts +14 -0
  187. package/index.js +14 -0
  188. package/messages.d.ts +3 -0
  189. package/messages.js +4 -1
  190. package/messages.js.map +1 -1
  191. package/package.json +10 -10
  192. package/radioOptionInputs.d.ts +24 -0
  193. package/radioOptionInputs.js +26 -0
  194. package/radioOptionInputs.js.map +1 -0
  195. package/types.d.ts +159 -7
  196. package/withGlobalElementDefaults.d.ts +8 -0
  197. package/withGlobalElementDefaults.js +60 -0
  198. package/withGlobalElementDefaults.js.map +1 -0
@@ -9,7 +9,10 @@ export type ResolveElementParams = {
9
9
  inputAst: InputAstNode[];
10
10
  onResolved?: OnResolved;
11
11
  };
12
- export declare class BindingsResolver {
12
+ export interface IBindingsResolver {
13
+ resolveElement(params: ResolveElementParams): ResolvedElement[];
14
+ }
15
+ export declare class BindingsResolver implements IBindingsResolver {
13
16
  private readonly state;
14
17
  constructor(state: DocumentState);
15
18
  resolveElement({ element, elementBindings, inputAst, onResolved }: ResolveElementParams): ResolvedElement[];
@@ -1 +1 @@
1
- {"version":3,"file":"BindingsResolver.js","sources":["../src/BindingsResolver.ts"],"sourcesContent":["import { toJS } from \"mobx\";\nimport type {\n ComponentInput,\n DocumentElement,\n DocumentElementBindings,\n DocumentElementStyleBindings,\n DocumentState,\n ResolvedElement,\n SerializableCSSStyleDeclaration,\n ValueBinding\n} from \"~/types.js\";\nimport type { InputAstNode } from \"./ComponentManifestToAstConverter.js\";\n\nexport interface OnResolved {\n (value: any, input: ComponentInput): any;\n}\n\nexport type ResolveElementParams = {\n element: DocumentElement;\n elementBindings: DocumentElementBindings;\n inputAst: InputAstNode[];\n onResolved?: OnResolved;\n};\n\nexport class BindingsResolver {\n private readonly state: DocumentState;\n\n constructor(state: DocumentState) {\n this.state = state;\n }\n\n public resolveElement({\n element,\n elementBindings,\n inputAst,\n onResolved\n }: ResolveElementParams): ResolvedElement[] {\n const repeatBindingArray = elementBindings.$repeat;\n\n if (repeatBindingArray) {\n const items = this.resolveBinding(repeatBindingArray, { state: toJS(this.state) });\n\n if (!Array.isArray(items)) {\n return [];\n }\n\n return items.map(item => {\n return this.resolveSingleInstance(\n element,\n elementBindings,\n item,\n inputAst,\n onResolved\n );\n });\n }\n\n return [\n this.resolveSingleInstance(element, elementBindings, undefined, inputAst, onResolved)\n ];\n }\n\n private resolveSingleInstance(\n element: DocumentElement,\n elementBindings: DocumentElementBindings,\n item: Record<string, any> | undefined,\n inputAst: InputAstNode[],\n onResolved?: OnResolved\n ): ResolvedElement {\n const resolvedElement: ResolvedElement = {\n id: element.id,\n inputs: {},\n styles: {}\n };\n\n const context = { state: this.state, $: item };\n const bindings = elementBindings.inputs ?? {};\n\n const resolveInputsFromAst = (\n nodes: InputAstNode[],\n prefix: string[],\n target: Record<string, any>\n ) => {\n for (const node of nodes) {\n const pathParts = [...prefix, node.name];\n const path = pathParts.join(\"/\");\n const binding = bindings[path];\n const value = this.resolveBinding(binding, context) ?? node.input.defaultValue;\n\n const finalValue = onResolved ? onResolved(value, node.input) : value;\n\n if (node.children.length > 0) {\n if (node.list) {\n const uniqueIndexes = this.getUniqueIndexesFromPath(path, bindings);\n\n target[node.name] = uniqueIndexes.map(index => {\n const childTarget: Record<string, any> = {};\n resolveInputsFromAst(\n node.children,\n [...pathParts.slice(0, -1), `${node.name}/${index}`],\n childTarget\n );\n return childTarget;\n });\n } else {\n const childTarget: Record<string, any> = {};\n resolveInputsFromAst(node.children, pathParts, childTarget);\n target[node.name] = childTarget;\n }\n } else if (node.list) {\n // List node with no children (e.g., slot or primitive list)\n const uniqueIndexes = this.getUniqueIndexesFromPath(path, bindings);\n\n // If binding is e.g., `leftColumn/0`, we'll have `0` in unique indexes.\n if (uniqueIndexes.length > 0) {\n target[node.name] = uniqueIndexes.map(index => {\n const binding = bindings[`${node.name}/${index}`];\n const value =\n this.resolveBinding(binding, context) ?? node.input.defaultValue;\n return onResolved ? onResolved(value, node.input) : value;\n });\n } else {\n // If binding is a simple `children`, we simply assign the resolved value.\n target[node.name] = finalValue;\n }\n } else if (finalValue !== undefined) {\n target[node.name] = finalValue;\n }\n }\n };\n\n resolveInputsFromAst(inputAst, [], resolvedElement.inputs);\n\n // Resolve styles\n const styles: DocumentElementStyleBindings = elementBindings.styles\n ? (elementBindings.styles ?? {})\n : {};\n\n const resolvedStyles: SerializableCSSStyleDeclaration = {};\n\n for (const [path, binding] of Object.entries(styles)) {\n if (binding) {\n // @ts-expect-error We're positive this is correct.\n resolvedStyles[path] = this.resolveBinding(binding, context);\n }\n }\n\n return {\n ...resolvedElement,\n styles: resolvedStyles\n };\n }\n\n private getUniqueIndexesFromPath(flatKey: string, bindings: DocumentElementBindings) {\n const pattern = new RegExp(`^${flatKey}\\\\/(\\\\d+)`);\n\n const indexes = Object.keys(bindings).reduce((acc: number[], key) => {\n const match = key.match(pattern);\n if (match) {\n acc.push(parseInt(match[1], 10));\n }\n return acc;\n }, []);\n\n return Array.from(new Set(indexes)).sort((a, b) => a - b);\n }\n\n private resolveBinding(binding: ValueBinding | undefined, context: Record<string, any>): any {\n if (typeof binding === \"undefined\") {\n return undefined;\n }\n\n if (binding.expression) {\n return this.evaluateExpression(binding.expression, context);\n }\n\n return binding.static;\n }\n\n private evaluateExpression(expression: string | undefined, context: Record<string, any> = {}) {\n if (!expression || expression === \"$noop\") {\n return undefined;\n }\n\n try {\n let finalExpression = expression.trim();\n\n if (finalExpression.startsWith(\"$state\")) {\n finalExpression = finalExpression.replace(/^\\$state/, \"state\");\n }\n\n finalExpression = finalExpression.replace(/\\.([0-9]+)/g, \"[$1]\");\n\n const scopedFn = new Function(...Object.keys(context), `return ${finalExpression};`);\n return scopedFn(...Object.values(context));\n } catch {\n return undefined;\n }\n }\n}\n"],"names":["BindingsResolver","state","element","elementBindings","inputAst","onResolved","repeatBindingArray","items","toJS","Array","item","undefined","resolvedElement","context","bindings","resolveInputsFromAst","nodes","prefix","target","node","pathParts","path","binding","value","finalValue","uniqueIndexes","index","childTarget","styles","resolvedStyles","Object","flatKey","pattern","RegExp","indexes","acc","key","match","parseInt","Set","a","b","expression","finalExpression","scopedFn","Function"],"mappings":";AAwBO,MAAMA;IAGT,YAAYC,KAAoB,CAAE;QAC9B,IAAI,CAAC,KAAK,GAAGA;IACjB;IAEO,eAAe,EAClBC,OAAO,EACPC,eAAe,EACfC,QAAQ,EACRC,UAAU,EACS,EAAqB;QACxC,MAAMC,qBAAqBH,gBAAgB,OAAO;QAElD,IAAIG,oBAAoB;YACpB,MAAMC,QAAQ,IAAI,CAAC,cAAc,CAACD,oBAAoB;gBAAE,OAAOE,KAAK,IAAI,CAAC,KAAK;YAAE;YAEhF,IAAI,CAACC,MAAM,OAAO,CAACF,QACf,OAAO,EAAE;YAGb,OAAOA,MAAM,GAAG,CAACG,CAAAA,OACN,IAAI,CAAC,qBAAqB,CAC7BR,SACAC,iBACAO,MACAN,UACAC;QAGZ;QAEA,OAAO;YACH,IAAI,CAAC,qBAAqB,CAACH,SAASC,iBAAiBQ,QAAWP,UAAUC;SAC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AAM,IAAI,CAAC,IAAI8B,IAAIL,UAAU,IAAI,CAAC,CAACM,GAAGC,IAAMD,IAAIC;IAC3D;IAEQ,eAAenB,OAAiC,EAAET,OAA4B,EAAO;QACzF,IAAI,AAAmB,WAAZS,SACP;QAGJ,IAAIA,QAAQ,UAAU,EAClB,OAAO,IAAI,CAAC,kBAAkB,CAACA,QAAQ,UAAU,EAAET;QAGvD,OAAOS,QAAQ,MAAM;IACzB;IAEQ,mBAAmBoB,UAA8B,EAAE7B,UAA+B,CAAC,CAAC,EAAE;QAC1F,IAAI,CAAC6B,cAAcA,AAAe,YAAfA,YACf;QAGJ,IAAI;YACA,IAAIC,kBAAkBD,WAAW,IAAI;YAErC,IAAIC,gBAAgB,UAAU,CAAC,WAC3BA,kBAAkBA,gBAAgB,OAAO,CAAC,YAAY;YAG1DA,kBAAkBA,gBAAgB,OAAO,CAAC,eAAe;YAEzD,MAAMC,WAAW,IAAIC,YAAYf,OAAO,IAAI,CAACjB,UAAU,CAAC,OAAO,EAAE8B,gBAAgB,CAAC,CAAC;YACnF,OAAOC,YAAYd,OAAO,MAAM,CAACjB;QACrC,EAAE,OAAM;YACJ;QACJ;IACJ;AACJ"}
1
+ {"version":3,"file":"BindingsResolver.js","sources":["../src/BindingsResolver.ts"],"sourcesContent":["import { toJS } from \"mobx\";\nimport type {\n ComponentInput,\n DocumentElement,\n DocumentElementBindings,\n DocumentElementStyleBindings,\n DocumentState,\n ResolvedElement,\n SerializableCSSStyleDeclaration,\n ValueBinding\n} from \"~/types.js\";\nimport type { InputAstNode } from \"./ComponentManifestToAstConverter.js\";\n\nexport interface OnResolved {\n (value: any, input: ComponentInput): any;\n}\n\nexport type ResolveElementParams = {\n element: DocumentElement;\n elementBindings: DocumentElementBindings;\n inputAst: InputAstNode[];\n onResolved?: OnResolved;\n};\n\nexport interface IBindingsResolver {\n resolveElement(params: ResolveElementParams): ResolvedElement[];\n}\n\nexport class BindingsResolver implements IBindingsResolver {\n private readonly state: DocumentState;\n\n constructor(state: DocumentState) {\n this.state = state;\n }\n\n public resolveElement({\n element,\n elementBindings,\n inputAst,\n onResolved\n }: ResolveElementParams): ResolvedElement[] {\n const repeatBindingArray = elementBindings.$repeat;\n\n if (repeatBindingArray) {\n const items = this.resolveBinding(repeatBindingArray, { state: toJS(this.state) });\n\n if (!Array.isArray(items)) {\n return [];\n }\n\n return items.map(item => {\n return this.resolveSingleInstance(\n element,\n elementBindings,\n item,\n inputAst,\n onResolved\n );\n });\n }\n\n return [\n this.resolveSingleInstance(element, elementBindings, undefined, inputAst, onResolved)\n ];\n }\n\n private resolveSingleInstance(\n element: DocumentElement,\n elementBindings: DocumentElementBindings,\n item: Record<string, any> | undefined,\n inputAst: InputAstNode[],\n onResolved?: OnResolved\n ): ResolvedElement {\n const resolvedElement: ResolvedElement = {\n id: element.id,\n inputs: {},\n styles: {}\n };\n\n const context = { state: this.state, $: item };\n const bindings = elementBindings.inputs ?? {};\n\n const resolveInputsFromAst = (\n nodes: InputAstNode[],\n prefix: string[],\n target: Record<string, any>\n ) => {\n for (const node of nodes) {\n const pathParts = [...prefix, node.name];\n const path = pathParts.join(\"/\");\n const binding = bindings[path];\n const value = this.resolveBinding(binding, context) ?? node.input.defaultValue;\n\n const finalValue = onResolved ? onResolved(value, node.input) : value;\n\n if (node.children.length > 0) {\n if (node.list) {\n const uniqueIndexes = this.getUniqueIndexesFromPath(path, bindings);\n\n target[node.name] = uniqueIndexes.map(index => {\n const childTarget: Record<string, any> = {};\n resolveInputsFromAst(\n node.children,\n [...pathParts.slice(0, -1), `${node.name}/${index}`],\n childTarget\n );\n return childTarget;\n });\n } else {\n const childTarget: Record<string, any> = {};\n resolveInputsFromAst(node.children, pathParts, childTarget);\n target[node.name] = childTarget;\n }\n } else if (node.list) {\n // List node with no children (e.g., slot or primitive list)\n const uniqueIndexes = this.getUniqueIndexesFromPath(path, bindings);\n\n // If binding is e.g., `leftColumn/0`, we'll have `0` in unique indexes.\n if (uniqueIndexes.length > 0) {\n target[node.name] = uniqueIndexes.map(index => {\n const binding = bindings[`${node.name}/${index}`];\n const value =\n this.resolveBinding(binding, context) ?? node.input.defaultValue;\n return onResolved ? onResolved(value, node.input) : value;\n });\n } else {\n // If binding is a simple `children`, we simply assign the resolved value.\n target[node.name] = finalValue;\n }\n } else if (finalValue !== undefined) {\n target[node.name] = finalValue;\n }\n }\n };\n\n resolveInputsFromAst(inputAst, [], resolvedElement.inputs);\n\n // Resolve styles\n const styles: DocumentElementStyleBindings = elementBindings.styles\n ? (elementBindings.styles ?? {})\n : {};\n\n const resolvedStyles: SerializableCSSStyleDeclaration = {};\n\n for (const [path, binding] of Object.entries(styles)) {\n if (binding) {\n // @ts-expect-error We're positive this is correct.\n resolvedStyles[path] = this.resolveBinding(binding, context);\n }\n }\n\n return {\n ...resolvedElement,\n styles: resolvedStyles\n };\n }\n\n private getUniqueIndexesFromPath(flatKey: string, bindings: DocumentElementBindings) {\n const pattern = new RegExp(`^${flatKey}\\\\/(\\\\d+)`);\n\n const indexes = Object.keys(bindings).reduce((acc: number[], key) => {\n const match = key.match(pattern);\n if (match) {\n acc.push(parseInt(match[1], 10));\n }\n return acc;\n }, []);\n\n return Array.from(new Set(indexes)).sort((a, b) => a - b);\n }\n\n private resolveBinding(binding: ValueBinding | undefined, context: Record<string, any>): any {\n if (typeof binding === \"undefined\") {\n return undefined;\n }\n\n if (binding.expression) {\n return this.evaluateExpression(binding.expression, context);\n }\n\n return binding.static;\n }\n\n private evaluateExpression(expression: string | undefined, context: Record<string, any> = {}) {\n if (!expression || expression === \"$noop\") {\n return undefined;\n }\n\n try {\n let finalExpression = expression.trim();\n\n if (finalExpression.startsWith(\"$state\")) {\n finalExpression = finalExpression.replace(/^\\$state/, \"state\");\n }\n\n finalExpression = finalExpression.replace(/\\.([0-9]+)/g, \"[$1]\");\n\n const scopedFn = new Function(...Object.keys(context), `return ${finalExpression};`);\n return scopedFn(...Object.values(context));\n } catch {\n return undefined;\n }\n }\n}\n"],"names":["BindingsResolver","state","element","elementBindings","inputAst","onResolved","repeatBindingArray","items","toJS","Array","item","undefined","resolvedElement","context","bindings","resolveInputsFromAst","nodes","prefix","target","node","pathParts","path","binding","value","finalValue","uniqueIndexes","index","childTarget","styles","resolvedStyles","Object","flatKey","pattern","RegExp","indexes","acc","key","match","parseInt","Set","a","b","expression","finalExpression","scopedFn","Function"],"mappings":";AA4BO,MAAMA;IAGT,YAAYC,KAAoB,CAAE;QAC9B,IAAI,CAAC,KAAK,GAAGA;IACjB;IAEO,eAAe,EAClBC,OAAO,EACPC,eAAe,EACfC,QAAQ,EACRC,UAAU,EACS,EAAqB;QACxC,MAAMC,qBAAqBH,gBAAgB,OAAO;QAElD,IAAIG,oBAAoB;YACpB,MAAMC,QAAQ,IAAI,CAAC,cAAc,CAACD,oBAAoB;gBAAE,OAAOE,KAAK,IAAI,CAAC,KAAK;YAAE;YAEhF,IAAI,CAACC,MAAM,OAAO,CAACF,QACf,OAAO,EAAE;YAGb,OAAOA,MAAM,GAAG,CAACG,CAAAA,OACN,IAAI,CAAC,qBAAqB,CAC7BR,SACAC,iBACAO,MACAN,UACAC;QAGZ;QAEA,OAAO;YACH,IAAI,CAAC,qBAAqB,CAACH,SAASC,iBAAiBQ,QAAWP,UAAUC;SAC7E;IACL;IAEQ,sBACJH,OAAwB,EACxBC,eAAwC,EACxCO,IAAqC,EACrCN,QAAwB,EACxBC,UAAuB,EACR;QACf,MAAMO,kBAAmC;YACrC,IAAIV,QAAQ,EAAE;YACd,QAAQ,CAAC;YACT,QAAQ,CAAC;QACb;QAEA,MAAMW,UAAU;YAAE,OAAO,IAAI,CAAC,KAAK;YAAE,GAAGH;QAAK;QAC7C,MAAMI,WAAWX,gBAAgB,MAAM,IAAI,CAAC;QAE5C,MAAMY,uBAAuB,CACzBC,OACAC,QACAC;YAEA,KAAK,MAAMC,QAAQH,MAAO;gBACtB,MAAMI,YAAY;uBAAIH;oBAAQE,KAAK,IAAI;iBAAC;gBACxC,MAAME,OAAOD,UAAU,IAA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AAC,WAC3BA,kBAAkBA,gBAAgB,OAAO,CAAC,YAAY;YAG1DA,kBAAkBA,gBAAgB,OAAO,CAAC,eAAe;YAEzD,MAAMC,WAAW,IAAIC,YAAYf,OAAO,IAAI,CAACjB,UAAU,CAAC,OAAO,EAAE8B,gBAAgB,CAAC,CAAC;YACnF,OAAOC,YAAYd,OAAO,MAAM,CAACjB;QACrC,EAAE,OAAM;YACJ;QACJ;IACJ;AACJ"}
@@ -10,6 +10,7 @@ class ComponentInputTraverser {
10
10
  }
11
11
  traverseNode(node, value, currentPath, visitor) {
12
12
  if (node.list) {
13
+ if (0 === node.children.length && "slot" !== node.type) return void visitor(node, currentPath, value);
13
14
  value = value ?? [];
14
15
  if (0 === value.length) visitor(node, currentPath, value);
15
16
  value.forEach((item, index)=>{
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentInputTraverser.js","sources":["../src/ComponentInputTraverser.ts"],"sourcesContent":["import type { InputAstNode } from \"./ComponentManifestToAstConverter.js\";\n\n// Visitor signature: called for every resolved leaf\nexport type InputVisitor = (node: InputAstNode, path: string, value: any) => void;\n\n/**\n * ComponentInputTraverser\n *\n * Walks an input AST and a matching data object,\n * invoking `visitor` for each leaf value found.\n */\nexport class ComponentInputTraverser {\n private readonly ast: InputAstNode[];\n\n constructor(ast: InputAstNode[]) {\n this.ast = ast;\n }\n\n /**\n * Traverse the given `data` object according to the AST,\n * calling `visitor(node, path, value)` for each leaf.\n */\n public traverse(data: Record<string, any>, visitor: InputVisitor): void {\n for (const node of this.ast) {\n const rootValue = data[node.name];\n this.traverseNode(node, rootValue, node.name, visitor);\n }\n }\n\n private traverseNode(\n node: InputAstNode,\n value: any,\n currentPath: string,\n visitor: InputVisitor\n ): void {\n if (node.list) {\n value = value ?? [];\n\n if (value.length === 0) {\n visitor(node, currentPath, value);\n }\n\n value.forEach((item: any, index: number) => {\n if (node.children.length > 0) {\n const itemPath = `${currentPath}/${index}`;\n for (const child of node.children) {\n const childValue = item?.[child.name];\n const childPath = `${itemPath}/${child.name}`;\n this.traverseNode(child, childValue, childPath, visitor);\n }\n } else {\n visitor(node, currentPath, item);\n }\n });\n } else {\n if (node.children.length > 0) {\n for (const child of node.children) {\n const childValue = value?.[child.name];\n const childPath = `${currentPath}/${child.name}`;\n this.traverseNode(child, childValue, childPath, visitor);\n }\n } else {\n visitor(node, currentPath, value);\n }\n }\n }\n}\n"],"names":["ComponentInputTraverser","ast","data","visitor","node","rootValue","value","currentPath","item","index","itemPath","child","childValue","childPath"],"mappings":"AAWO,MAAMA;IAGT,YAAYC,GAAmB,CAAE;QAC7B,IAAI,CAAC,GAAG,GAAGA;IACf;IAMO,SAASC,IAAyB,EAAEC,OAAqB,EAAQ;QACpE,KAAK,MAAMC,QAAQ,IAAI,CAAC,GAAG,CAAE;YACzB,MAAMC,YAAYH,IAAI,CAACE,KAAK,IAAI,CAAC;YACjC,IAAI,CAAC,YAAY,CAACA,MAAMC,WAAWD,KAAK,IAAI,EAAED;QAClD;IACJ;IAEQ,aACJC,IAAkB,EAClBE,KAAU,EACVC,WAAmB,EACnBJ,OAAqB,EACjB;QACJ,IAAIC,KAAK,IAAI,EAAE;YACXE,QAAQA,SAAS,EAAE;YAEnB,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZH,QAAQC,MAAMG,aAAaD;YAG/BA,MAAM,OAAO,CAAC,CAACE,MAAWC;gBACtB,IAAIL,KAAK,QAAQ,CAAC,MAAM,GAAG,GAAG;oBAC1B,MAAMM,WAAW,GAAGH,YAAY,CAAC,EAAEE,OAAO;oBAC1C,KAAK,MAAME,SAASP,KAAK,QAAQ,CAAE;wBAC/B,MAAMQ,aAAaJ,MAAM,CAACG,MAAM,IAAI,CAAC;wBACrC,MAAME,YAAY,GAAGH,SAAS,CAAC,EAAEC,MAAM,IAAI,EAAE;wBAC7C,IAAI,CAAC,YAAY,CAACA,OAAOC,YAAYC,WAAWV;oBACpD;gBACJ,OACIA,QAAQC,MAAMG,aAAaC;YAEnC;QACJ,OACI,IAAIJ,KAAK,QAAQ,CAAC,MAAM,GAAG,GACvB,KAAK,MAAMO,SAASP,KAAK,QAAQ,CAAE;YAC/B,MAAMQ,aAAaN,OAAO,CAACK,MAAM,IAAI,CAAC;YACtC,MAAME,YAAY,GAAGN,YAAY,CAAC,EAAEI,MAAM,IAAI,EAAE;YAChD,IAAI,CAAC,YAAY,CAACA,OAAOC,YAAYC,WAAWV;QACpD;aAEAA,QAAQC,MAAMG,aAAaD;IAGvC;AACJ"}
1
+ {"version":3,"file":"ComponentInputTraverser.js","sources":["../src/ComponentInputTraverser.ts"],"sourcesContent":["import type { InputAstNode } from \"./ComponentManifestToAstConverter.js\";\n\n// Visitor signature: called for every resolved leaf\nexport type InputVisitor = (node: InputAstNode, path: string, value: any) => void;\n\n/**\n * ComponentInputTraverser\n *\n * Walks an input AST and a matching data object,\n * invoking `visitor` for each leaf value found.\n */\nexport class ComponentInputTraverser {\n private readonly ast: InputAstNode[];\n\n constructor(ast: InputAstNode[]) {\n this.ast = ast;\n }\n\n /**\n * Traverse the given `data` object according to the AST,\n * calling `visitor(node, path, value)` for each leaf.\n */\n public traverse(data: Record<string, any>, visitor: InputVisitor): void {\n for (const node of this.ast) {\n const rootValue = data[node.name];\n this.traverseNode(node, rootValue, node.name, visitor);\n }\n }\n\n private traverseNode(\n node: InputAstNode,\n value: any,\n currentPath: string,\n visitor: InputVisitor\n ): void {\n if (node.list) {\n // A list of primitives (e.g. tags) is a single leaf: its value is the whole array.\n // Visiting each item would write every item to the same path, leaving only the last.\n // A missing value is passed on as `undefined` (not `[]`), so the visitor can apply the\n // input's `defaultValue` (ElementFactory: `value ?? node.input.defaultValue`).\n // Slot lists are still visited per item, as each item creates its own element.\n if (node.children.length === 0 && node.type !== \"slot\") {\n visitor(node, currentPath, value);\n return;\n }\n\n value = value ?? [];\n\n if (value.length === 0) {\n visitor(node, currentPath, value);\n }\n\n value.forEach((item: any, index: number) => {\n if (node.children.length > 0) {\n const itemPath = `${currentPath}/${index}`;\n for (const child of node.children) {\n const childValue = item?.[child.name];\n const childPath = `${itemPath}/${child.name}`;\n this.traverseNode(child, childValue, childPath, visitor);\n }\n } else {\n visitor(node, currentPath, item);\n }\n });\n } else {\n if (node.children.length > 0) {\n for (const child of node.children) {\n const childValue = value?.[child.name];\n const childPath = `${currentPath}/${child.name}`;\n this.traverseNode(child, childValue, childPath, visitor);\n }\n } else {\n visitor(node, currentPath, value);\n }\n }\n }\n}\n"],"names":["ComponentInputTraverser","ast","data","visitor","node","rootValue","value","currentPath","item","index","itemPath","child","childValue","childPath"],"mappings":"AAWO,MAAMA;IAGT,YAAYC,GAAmB,CAAE;QAC7B,IAAI,CAAC,GAAG,GAAGA;IACf;IAMO,SAASC,IAAyB,EAAEC,OAAqB,EAAQ;QACpE,KAAK,MAAMC,QAAQ,IAAI,CAAC,GAAG,CAAE;YACzB,MAAMC,YAAYH,IAAI,CAACE,KAAK,IAAI,CAAC;YACjC,IAAI,CAAC,YAAY,CAACA,MAAMC,WAAWD,KAAK,IAAI,EAAED;QAClD;IACJ;IAEQ,aACJC,IAAkB,EAClBE,KAAU,EACVC,WAAmB,EACnBJ,OAAqB,EACjB;QACJ,IAAIC,KAAK,IAAI,EAAE;YAMX,IAAIA,AAAyB,MAAzBA,KAAK,QAAQ,CAAC,MAAM,IAAUA,AAAc,WAAdA,KAAK,IAAI,EAAa,YACpDD,QAAQC,MAAMG,aAAaD;YAI/BA,QAAQA,SAAS,EAAE;YAEnB,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZH,QAAQC,MAAMG,aAAaD;YAG/BA,MAAM,OAAO,CAAC,CAACE,MAAWC;gBACtB,IAAIL,KAAK,QAAQ,CAAC,MAAM,GAAG,GAAG;oBAC1B,MAAMM,WAAW,GAAGH,YAAY,CAAC,EAAEE,OAAO;oBAC1C,KAAK,MAAME,SAASP,KAAK,QAAQ,CAAE;wBAC/B,MAAMQ,aAAaJ,MAAM,CAACG,MAAM,IAAI,CAAC;wBACrC,MAAME,YAAY,GAAGH,SAAS,CAAC,EAAEC,MAAM,IAAI,EAAE;wBAC7C,IAAI,CAAC,YAAY,CAACA,OAAOC,YAAYC,WAAWV;oBACpD;gBACJ,OACIA,QAAQC,MAAMG,aAAaC;YAEnC;QACJ,OACI,IAAIJ,KAAK,QAAQ,CAAC,MAAM,GAAG,GACvB,KAAK,MAAMO,SAASP,KAAK,QAAQ,CAAE;YAC/B,MAAMQ,aAAaN,OAAO,CAACK,MAAM,IAAI,CAAC;YACtC,MAAME,YAAY,GAAGN,YAAY,CAAC,EAAEI,MAAM,IAAI,EAAE;YAChD,IAAI,CAAC,YAAY,CAACA,OAAOC,YAAYC,WAAWV;QACpD;aAEAA,QAAQC,MAAMG,aAAaD;IAGvC;AACJ"}
@@ -1,4 +1,4 @@
1
- import type { ComponentInput } from "./types.js";
1
+ import type { ComponentInput, ResolvedInputRenderer } from "./types.js";
2
2
  export type InputAstNode = {
3
3
  name: string;
4
4
  type: string;
@@ -6,8 +6,30 @@ export type InputAstNode = {
6
6
  path: string;
7
7
  children: InputAstNode[];
8
8
  input: ComponentInput;
9
+ /**
10
+ * The input's renderer in one shape, whichever form the manifest used (`"Webiny/Input"` or
11
+ * `{ name, settings }`). Read the renderer from here, not from `input.renderer`.
12
+ */
13
+ renderer: ResolvedInputRenderer;
9
14
  };
15
+ /**
16
+ * The name of the child that holds the selected option of a radio with option inputs.
17
+ */
18
+ export declare const RADIO_VALUE_INPUT = "value";
10
19
  export declare class ComponentManifestToAstConverter {
11
20
  static convert(inputs: ComponentInput[]): InputAstNode[];
21
+ /**
22
+ * Returns the AST nodes of one option's inputs, at the radio node's paths, with that option's
23
+ * definitions (labels, validation). Renderers draw the selected option's inputs with these.
24
+ * The paths are the same as those of the radio's merged children, so values are shared.
25
+ */
26
+ static convertRadioOptionInputs(radioNode: InputAstNode, optionValue: string): InputAstNode[];
12
27
  private static buildAst;
28
+ private static getRadioChildInputs;
29
+ /**
30
+ * One stored value for same-named inputs of several options. They must agree on what is stored
31
+ * (checked in development), and same-named object inputs store the fields of all their definitions.
32
+ */
33
+ private static mergeOptionInput;
34
+ private static assertSameStoredValue;
13
35
  }
@@ -1,7 +1,52 @@
1
+ import deep_equal from "deep-equal";
2
+ function resolveInputRenderer(input) {
3
+ const renderer = input.renderer;
4
+ if (!renderer) return {
5
+ name: "",
6
+ settings: {}
7
+ };
8
+ if ("string" == typeof renderer) return {
9
+ name: renderer,
10
+ settings: {}
11
+ };
12
+ return {
13
+ name: renderer.name ?? "",
14
+ settings: renderer.settings ?? {}
15
+ };
16
+ }
17
+ const RADIO_VALUE_INPUT = "value";
18
+ const SHARED_OPTION_INPUT_KEYS = [
19
+ "type",
20
+ "list",
21
+ "translatable",
22
+ "defaultValue"
23
+ ];
24
+ const STRUCTURAL_OPTION_INPUT_KEYS = [
25
+ "type",
26
+ "list"
27
+ ];
28
+ const isDevelopment = ()=>{
29
+ try {
30
+ return "production" !== process.env.NODE_ENV;
31
+ } catch {
32
+ return false;
33
+ }
34
+ };
35
+ const isRadioWithOptionInputs = (input)=>{
36
+ if ("radio" !== input.type) return false;
37
+ const options = input.options ?? [];
38
+ return options.some((option)=>Array.isArray(option.inputs) && option.inputs.length > 0);
39
+ };
1
40
  class ComponentManifestToAstConverter {
2
41
  static convert(inputs) {
3
42
  return this.buildAst(inputs);
4
43
  }
44
+ static convertRadioOptionInputs(radioNode, optionValue) {
45
+ const input = radioNode.input;
46
+ const option = (input.options ?? []).find((option)=>option.value === optionValue);
47
+ if (!option?.inputs) return [];
48
+ return this.buildAst(option.inputs, radioNode.path);
49
+ }
5
50
  static buildAst(inputs, basePath = "") {
6
51
  return inputs.map((input)=>{
7
52
  const path = basePath ? `${basePath}/${input.name}` : input.name;
@@ -11,13 +56,88 @@ class ComponentManifestToAstConverter {
11
56
  list: input.list || false,
12
57
  path,
13
58
  children: [],
14
- input
59
+ input,
60
+ renderer: resolveInputRenderer(input)
15
61
  };
16
62
  if ("object" === input.type && input.fields) node.children = this.buildAst(input.fields, path);
63
+ else if (isRadioWithOptionInputs(input)) {
64
+ node.type = "object";
65
+ node.children = this.buildAst(this.getRadioChildInputs(input), path);
66
+ }
17
67
  return node;
18
68
  });
19
69
  }
70
+ static getRadioChildInputs(input) {
71
+ const options = input.options.map((option)=>{
72
+ const { inputs: _inputs, ...rest } = option;
73
+ return rest;
74
+ });
75
+ const valueInput = {
76
+ name: RADIO_VALUE_INPUT,
77
+ type: "radio",
78
+ label: input.label,
79
+ renderer: input.renderer,
80
+ defaultValue: input.defaultValue,
81
+ required: input.required,
82
+ responsive: input.responsive,
83
+ translatable: input.translatable,
84
+ options
85
+ };
86
+ const merged = new Map();
87
+ for (const option of input.options)for (const optionInput of option.inputs ?? []){
88
+ const existing = merged.get(optionInput.name);
89
+ if (!existing) {
90
+ merged.set(optionInput.name, {
91
+ input: optionInput,
92
+ option: option.value
93
+ });
94
+ continue;
95
+ }
96
+ existing.input = this.mergeOptionInput(input, existing, {
97
+ input: optionInput,
98
+ option: option.value
99
+ });
100
+ }
101
+ if (merged.has(RADIO_VALUE_INPUT)) throw new Error(`Radio input "${input.name}": an option input can't be named "${RADIO_VALUE_INPUT}", the name of the selected option.`);
102
+ return [
103
+ valueInput,
104
+ ...Array.from(merged.values()).map((entry)=>entry.input)
105
+ ];
106
+ }
107
+ static mergeOptionInput(radio, first, other) {
108
+ this.assertSameStoredValue(radio, first, other, isDevelopment() ? SHARED_OPTION_INPUT_KEYS : STRUCTURAL_OPTION_INPUT_KEYS);
109
+ if ("object" !== first.input.type || "object" !== other.input.type) return first.input;
110
+ const fields = new Map();
111
+ for (const field of first.input.fields ?? [])fields.set(field.name, field);
112
+ for (const field of other.input.fields ?? []){
113
+ const existing = fields.get(field.name);
114
+ fields.set(field.name, existing ? this.mergeOptionInput(radio, {
115
+ input: existing,
116
+ option: first.option
117
+ }, {
118
+ input: field,
119
+ option: other.option
120
+ }) : field);
121
+ }
122
+ return {
123
+ ...first.input,
124
+ fields: Array.from(fields.values())
125
+ };
126
+ }
127
+ static assertSameStoredValue(radio, first, other, keys) {
128
+ for (const key of keys){
129
+ const a = normalizeSharedValue(key, first.input[key]);
130
+ const b = normalizeSharedValue(key, other.input[key]);
131
+ if (!deep_equal(a, b, {
132
+ strict: true
133
+ })) throw new Error(`Radio input "${radio.name}": option input "${other.input.name}" has a different "${key}" in options "${first.option}" and "${other.option}". Inputs with the same name share one stored value, so they must agree on ${SHARED_OPTION_INPUT_KEYS.join(", ")}.`);
134
+ }
135
+ }
136
+ }
137
+ function normalizeSharedValue(key, value) {
138
+ if ("list" === key || "translatable" === key) return Boolean(value);
139
+ return value;
20
140
  }
21
- export { ComponentManifestToAstConverter };
141
+ export { ComponentManifestToAstConverter, RADIO_VALUE_INPUT };
22
142
 
23
143
  //# sourceMappingURL=ComponentManifestToAstConverter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentManifestToAstConverter.js","sources":["../src/ComponentManifestToAstConverter.ts"],"sourcesContent":["import type { ComponentInput } from \"./types.js\";\n\nexport type InputAstNode = {\n name: string;\n type: string;\n list: boolean;\n path: string;\n children: InputAstNode[];\n input: ComponentInput;\n};\n\nexport class ComponentManifestToAstConverter {\n static convert(inputs: ComponentInput[]): InputAstNode[] {\n return this.buildAst(inputs);\n }\n\n private static buildAst(inputs: ComponentInput[], basePath = \"\"): InputAstNode[] {\n return inputs.map(input => {\n const path = basePath ? `${basePath}/${input.name}` : input.name;\n const node: InputAstNode = {\n name: input.name,\n type: input.type,\n list: input.list || false,\n path,\n children: [],\n input\n };\n\n if (input.type === \"object\" && input.fields) {\n node.children = this.buildAst(input.fields, path);\n }\n\n return node;\n });\n }\n}\n"],"names":["ComponentManifestToAstConverter","inputs","basePath","input","path","node"],"mappings":"AAWO,MAAMA;IACT,OAAO,QAAQC,MAAwB,EAAkB;QACrD,OAAO,IAAI,CAAC,QAAQ,CAACA;IACzB;IAEA,OAAe,SAASA,MAAwB,EAAEC,WAAW,EAAE,EAAkB;QAC7E,OAAOD,OAAO,GAAG,CAACE,CAAAA;YACd,MAAMC,OAAOF,WAAW,GAAGA,SAAS,CAAC,EAAEC,MAAM,IAAI,EAAE,GAAGA,MAAM,IAAI;YAChE,MAAME,OAAqB;gBACvB,MAAMF,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI,IAAI;gBACpBC;gBACA,UAAU,EAAE;gBACZD;YACJ;YAEA,IAAIA,AAAe,aAAfA,MAAM,IAAI,IAAiBA,MAAM,MAAM,EACvCE,KAAK,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAACF,MAAM,MAAM,EAAEC;YAGhD,OAAOC;QACX;IACJ;AACJ"}
1
+ {"version":3,"file":"ComponentManifestToAstConverter.js","sources":["../src/ComponentManifestToAstConverter.ts"],"sourcesContent":["import deepEqual from \"deep-equal\";\nimport type { ComponentInput, RadioInput, RadioOption, ResolvedInputRenderer } from \"./types.js\";\n\nexport type InputAstNode = {\n name: string;\n type: string;\n list: boolean;\n path: string;\n children: InputAstNode[];\n input: ComponentInput;\n /**\n * The input's renderer in one shape, whichever form the manifest used (`\"Webiny/Input\"` or\n * `{ name, settings }`). Read the renderer from here, not from `input.renderer`.\n */\n renderer: ResolvedInputRenderer;\n};\n\n/**\n * The input's renderer as an object: a plain name gets empty settings, a missing renderer an empty\n * name (the sidebar then shows \"Missing renderer\").\n */\nfunction resolveInputRenderer(input: Pick<ComponentInput, \"renderer\">): ResolvedInputRenderer {\n const renderer = input.renderer;\n if (!renderer) {\n return { name: \"\", settings: {} };\n }\n if (typeof renderer === \"string\") {\n return { name: renderer, settings: {} };\n }\n return { name: renderer.name ?? \"\", settings: renderer.settings ?? {} };\n}\n\n/**\n * The name of the child that holds the selected option of a radio with option inputs.\n */\nexport const RADIO_VALUE_INPUT = \"value\";\n\n/**\n * The properties that copies of an option input (the same name in several options) must agree on,\n * because they are one stored value.\n */\nconst SHARED_OPTION_INPUT_KEYS = [\"type\", \"list\", \"translatable\", \"defaultValue\"] as const;\n\n/**\n * The shared properties that decide the stored value's shape: checked in production too, since a mismatch\n * would drop one definition's fields (and their defaults) from the merged input.\n */\nconst STRUCTURAL_OPTION_INPUT_KEYS = [\"type\", \"list\"] as const;\n\n/**\n * Bundlers replace `process.env.NODE_ENV` at build time, so a production admin build skips the checks.\n * Where nothing replaced it and there is no `process` (an unbundled browser), they are skipped too.\n */\nconst isDevelopment = () => {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n};\n\nconst isRadioWithOptionInputs = (input: ComponentInput): input is RadioInput => {\n if (input.type !== \"radio\") {\n return false;\n }\n const options = (input as RadioInput).options ?? [];\n return options.some(option => Array.isArray(option.inputs) && option.inputs.length > 0);\n};\n\nexport class ComponentManifestToAstConverter {\n static convert(inputs: ComponentInput[]): InputAstNode[] {\n return this.buildAst(inputs);\n }\n\n /**\n * Returns the AST nodes of one option's inputs, at the radio node's paths, with that option's\n * definitions (labels, validation). Renderers draw the selected option's inputs with these.\n * The paths are the same as those of the radio's merged children, so values are shared.\n */\n static convertRadioOptionInputs(radioNode: InputAstNode, optionValue: string): InputAstNode[] {\n const input = radioNode.input as RadioInput;\n const option = (input.options ?? []).find(option => option.value === optionValue);\n if (!option?.inputs) {\n return [];\n }\n return this.buildAst(option.inputs, radioNode.path);\n }\n\n private static buildAst(inputs: ComponentInput[], basePath = \"\"): InputAstNode[] {\n return inputs.map(input => {\n const path = basePath ? `${basePath}/${input.name}` : input.name;\n const node: InputAstNode = {\n name: input.name,\n type: input.type,\n list: input.list || false,\n path,\n children: [],\n input,\n renderer: resolveInputRenderer(input)\n };\n\n if (input.type === \"object\" && input.fields) {\n node.children = this.buildAst(input.fields, path);\n } else if (isRadioWithOptionInputs(input)) {\n // A radio whose options carry inputs is stored as an object: `value` holds the\n // selected option, the options' inputs (merged by name) are the other children.\n node.type = \"object\";\n node.children = this.buildAst(this.getRadioChildInputs(input), path);\n }\n\n return node;\n });\n }\n\n private static getRadioChildInputs(input: RadioInput): ComponentInput[] {\n const options: RadioOption[] = input.options.map(option => {\n const { inputs: _inputs, ...rest } = option;\n return rest;\n });\n\n const valueInput: RadioInput = {\n name: RADIO_VALUE_INPUT,\n type: \"radio\",\n label: input.label,\n renderer: input.renderer,\n defaultValue: input.defaultValue,\n required: input.required,\n responsive: input.responsive,\n translatable: input.translatable,\n options\n };\n\n const merged = new Map<string, { input: ComponentInput; option: string }>();\n for (const option of input.options) {\n for (const optionInput of option.inputs ?? []) {\n const existing = merged.get(optionInput.name);\n if (!existing) {\n merged.set(optionInput.name, {\n input: optionInput,\n option: option.value\n });\n continue;\n }\n existing.input = this.mergeOptionInput(input, existing, {\n input: optionInput,\n option: option.value\n });\n }\n }\n\n if (merged.has(RADIO_VALUE_INPUT)) {\n throw new Error(\n `Radio input \"${input.name}\": an option input can't be named \"${RADIO_VALUE_INPUT}\", the name of the selected option.`\n );\n }\n\n return [valueInput, ...Array.from(merged.values()).map(entry => entry.input)];\n }\n\n /**\n * One stored value for same-named inputs of several options. They must agree on what is stored\n * (checked in development), and same-named object inputs store the fields of all their definitions.\n */\n private static mergeOptionInput(\n radio: RadioInput,\n first: { input: ComponentInput; option: string },\n other: { input: ComponentInput; option: string }\n ): ComponentInput {\n this.assertSameStoredValue(\n radio,\n first,\n other,\n isDevelopment() ? SHARED_OPTION_INPUT_KEYS : STRUCTURAL_OPTION_INPUT_KEYS\n );\n if (first.input.type !== \"object\" || other.input.type !== \"object\") {\n return first.input;\n }\n\n const fields = new Map<string, ComponentInput>();\n for (const field of first.input.fields ?? []) {\n fields.set(field.name, field);\n }\n for (const field of other.input.fields ?? []) {\n const existing = fields.get(field.name);\n fields.set(\n field.name,\n existing\n ? this.mergeOptionInput(\n radio,\n { input: existing, option: first.option },\n { input: field, option: other.option }\n )\n : field\n );\n }\n return {\n ...first.input,\n fields: Array.from(fields.values())\n } as ComponentInput;\n }\n\n private static assertSameStoredValue(\n radio: RadioInput,\n first: { input: ComponentInput; option: string },\n other: { input: ComponentInput; option: string },\n keys: readonly (typeof SHARED_OPTION_INPUT_KEYS)[number][]\n ) {\n for (const key of keys) {\n const a = normalizeSharedValue(key, first.input[key]);\n const b = normalizeSharedValue(key, other.input[key]);\n if (!deepEqual(a, b, { strict: true })) {\n throw new Error(\n `Radio input \"${radio.name}\": option input \"${other.input.name}\" has a different \"${key}\" in options \"${first.option}\" and \"${other.option}\". Inputs with the same name share one stored value, so they must agree on ${SHARED_OPTION_INPUT_KEYS.join(\", \")}.`\n );\n }\n }\n }\n}\n\nfunction normalizeSharedValue(key: string, value: unknown) {\n if (key === \"list\" || key === \"translatable\") {\n return Boolean(value);\n }\n return value;\n}\n"],"names":["resolveInputRenderer","input","renderer","RADIO_VALUE_INPUT","SHARED_OPTION_INPUT_KEYS","STRUCTURAL_OPTION_INPUT_KEYS","isDevelopment","process","isRadioWithOptionInputs","options","option","Array","ComponentManifestToAstConverter","inputs","radioNode","optionValue","basePath","path","node","_inputs","rest","valueInput","merged","Map","optionInput","existing","Error","entry","radio","first","other","fields","field","keys","key","a","normalizeSharedValue","b","deepEqual","value","Boolean"],"mappings":";AAqBA,SAASA,qBAAqBC,KAAuC;IACjE,MAAMC,WAAWD,MAAM,QAAQ;IAC/B,IAAI,CAACC,UACD,OAAO;QAAE,MAAM;QAAI,UAAU,CAAC;IAAE;IAEpC,IAAI,AAAoB,YAApB,OAAOA,UACP,OAAO;QAAE,MAAMA;QAAU,UAAU,CAAC;IAAE;IAE1C,OAAO;QAAE,MAAMA,SAAS,IAAI,IAAI;QAAI,UAAUA,SAAS,QAAQ,IAAI,CAAC;IAAE;AAC1E;AAKO,MAAMC,oBAAoB;AAMjC,MAAMC,2BAA2B;IAAC;IAAQ;IAAQ;IAAgB;CAAe;AAMjF,MAAMC,+BAA+B;IAAC;IAAQ;CAAO;AAMrD,MAAMC,gBAAgB;IAClB,IAAI;QACA,OAAOC,AAAyB,iBAAzBA,QAAQ,GAAG,CAAC,QAAQ;IAC/B,EAAE,OAAM;QACJ,OAAO;IACX;AACJ;AAEA,MAAMC,0BAA0B,CAACP;IA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;AAEA,SAASgC,qBAAqBF,GAAW,EAAEK,KAAc;IACrD,IAAIL,AAAQ,WAARA,OAAkBA,AAAQ,mBAARA,KAClB,OAAOM,QAAQD;IAEnB,OAAOA;AACX"}
@@ -1,4 +1,4 @@
1
- import type { Component } from "./types.js";
1
+ import type { Component, ComponentManifest } from "./types.js";
2
2
  type Registration = {
3
3
  name: string;
4
4
  component: Component;
@@ -8,6 +8,7 @@ export declare class ComponentRegistry {
8
8
  private listeners;
9
9
  register(component: Component): void;
10
10
  get(name: string): Component | undefined;
11
+ getManifests(): Record<string, ComponentManifest>;
11
12
  /** subscribe to *all* registrations */
12
13
  onRegister(fn: (reg: Registration) => void): () => boolean;
13
14
  }
@@ -17,6 +17,13 @@ class ComponentRegistry {
17
17
  get(name) {
18
18
  return this.registry.get(name);
19
19
  }
20
+ getManifests() {
21
+ const manifests = {};
22
+ this.registry.forEach((component, name)=>{
23
+ manifests[name] = component.manifest;
24
+ });
25
+ return manifests;
26
+ }
20
27
  onRegister(fn) {
21
28
  this.listeners.add(fn);
22
29
  return ()=>this.listeners.delete(fn);
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentRegistry.js","sources":["../src/ComponentRegistry.ts"],"sourcesContent":["import type { Component } from \"~/types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\ntype Registration = { name: string; component: Component };\n\nexport class ComponentRegistry {\n private registry = new Map<string, Component>();\n private listeners = new Set<(reg: Registration) => void>();\n\n public register(component: Component) {\n const name = component.manifest.name;\n // Normalize optional fields so downstream code never sees undefined.\n component.manifest.tags = component.manifest.tags ?? [];\n // Serialize constraint and handler functions for cross-boundary transport\n if (component.manifest.constraints) {\n // @ts-expect-error Serialized form is string[], but type expects function[].\n component.manifest.constraints = component.manifest.constraints.map(fn =>\n functionConverter.serialize(fn)\n );\n }\n if (component.manifest.descendantConstraints) {\n // @ts-expect-error Serialized form is string[], but type expects function[].\n component.manifest.descendantConstraints = component.manifest.descendantConstraints.map(\n fn => functionConverter.serialize(fn)\n );\n }\n if (component.manifest.canDelete && typeof component.manifest.canDelete === \"function\") {\n // @ts-expect-error Serialized form is a string, but type expects a function.\n component.manifest.canDelete = functionConverter.serialize(\n component.manifest.canDelete\n );\n }\n if (component.manifest.onChange) {\n // @ts-expect-error Serialized form is a string (or string[]), but type expects a function.\n component.manifest.onChange = serializeHandlers(component.manifest.onChange);\n }\n if (component.manifest.onDescendantChange) {\n // @ts-expect-error Serialized form is a string (or string[]), but type expects a function.\n component.manifest.onDescendantChange = serializeHandlers(\n component.manifest.onDescendantChange\n );\n }\n this.registry.set(name, component);\n // notify subscribers\n this.listeners.forEach(fn => fn({ name, component }));\n }\n\n public get(name: string) {\n return this.registry.get(name);\n }\n\n /** subscribe to *all* registrations */\n public onRegister(fn: (reg: Registration) => void) {\n this.listeners.add(fn);\n return () => this.listeners.delete(fn);\n }\n}\n\nfunction serializeHandlers(\n handler: ((...args: any[]) => any) | ((...args: any[]) => any)[]\n): string | string[] {\n if (Array.isArray(handler)) {\n return handler.map(h => functionConverter.serialize(h));\n }\n return functionConverter.serialize(handler);\n}\n\nexport const componentRegistry = new ComponentRegistry();\n"],"names":["ComponentRegistry","component","name","fn","functionConverter","serializeHandlers","Map","Set","handler","Array","h","componentRegistry"],"mappings":";AAKO,MAAMA;IAIF,SAASC,SAAoB,EAAE;QAClC,MAAMC,OAAOD,UAAU,QAAQ,CAAC,IAAI;QAEpCA,UAAU,QAAQ,CAAC,IAAI,GAAGA,UAAU,QAAQ,CAAC,IAAI,IAAI,EAAE;QAEvD,IAAIA,UAAU,QAAQ,CAAC,WAAW,EAE9BA,UAAU,QAAQ,CAAC,WAAW,GAAGA,UAAU,QAAQ,CAAC,WAAW,CAAC,GAAG,CAACE,CAAAA,KAChEC,kBAAkB,SAAS,CAACD;QAGpC,IAAIF,UAAU,QAAQ,CAAC,qBAAqB,EAExCA,UAAU,QAAQ,CAAC,qBAAqB,GAAGA,UAAU,QAAQ,CAAC,qBAAqB,CAAC,GAAG,CACnFE,CAAAA,KAAMC,kBAAkB,SAAS,CAACD;QAG1C,IAAIF,UAAU,QAAQ,CAAC,SAAS,IAAI,AAAwC,cAAxC,OAAOA,UAAU,QAAQ,CAAC,SAAS,EAEnEA,UAAU,QAAQ,CAAC,SAAS,GAAGG,kBAAkB,SAAS,CACtDH,UAAU,QAAQ,CAAC,SAAS;QAGpC,IAAIA,UAAU,QAAQ,CAAC,QAAQ,EAE3BA,UAAU,QAAQ,CAAC,QAAQ,GAAGI,kBAAkBJ,UAAU,QAAQ,CAAC,QAAQ;QAE/E,IAAIA,UAAU,QAAQ,CAAC,kBAAkB,EAErCA,UAAU,QAAQ,CAAC,kBAAkB,GAAGI,kBACpCJ,UAAU,QAAQ,CAAC,kBAAkB;QAG7C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACC,MAAMD;QAExB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACE,CAAAA,KAAMA,GAAG;gBAAED;gBAAMD;YAAU;IACtD;IAEO,IAAIC,IAAY,EAAE;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA;IAC7B;IAGO,WAAWC,EAA+B,EAAE;QAC/C,IAAI,CAAC,SAAS,CAAC,GAAG,CAACA;QACnB,OAAO,IAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;IACvC;;aAjDQ,QAAQ,GAAG,IAAIG;aACf,SAAS,GAAG,IAAIC;;AAiD5B;AAEA,SAASF,kBACLG,OAAgE;IAEhE,IAAIC,MAAM,OAAO,CAACD,UACd,OAAOA,QAAQ,GAAG,CAACE,CAAAA,IAAKN,kBAAkB,SAAS,CAACM;IAExD,OAAON,kBAAkB,SAAS,CAACI;AACvC;AAEO,MAAMG,oBAAoB,IAAIX"}
1
+ {"version":3,"file":"ComponentRegistry.js","sources":["../src/ComponentRegistry.ts"],"sourcesContent":["import type { Component, ComponentManifest } from \"~/types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\ntype Registration = { name: string; component: Component };\n\nexport class ComponentRegistry {\n private registry = new Map<string, Component>();\n private listeners = new Set<(reg: Registration) => void>();\n\n public register(component: Component) {\n const name = component.manifest.name;\n // Normalize optional fields so downstream code never sees undefined.\n component.manifest.tags = component.manifest.tags ?? [];\n // Serialize constraint and handler functions for cross-boundary transport\n if (component.manifest.constraints) {\n // @ts-expect-error Serialized form is string[], but type expects function[].\n component.manifest.constraints = component.manifest.constraints.map(fn =>\n functionConverter.serialize(fn)\n );\n }\n if (component.manifest.descendantConstraints) {\n // @ts-expect-error Serialized form is string[], but type expects function[].\n component.manifest.descendantConstraints = component.manifest.descendantConstraints.map(\n fn => functionConverter.serialize(fn)\n );\n }\n if (component.manifest.canDelete && typeof component.manifest.canDelete === \"function\") {\n // @ts-expect-error Serialized form is a string, but type expects a function.\n component.manifest.canDelete = functionConverter.serialize(\n component.manifest.canDelete\n );\n }\n if (component.manifest.onChange) {\n // @ts-expect-error Serialized form is a string (or string[]), but type expects a function.\n component.manifest.onChange = serializeHandlers(component.manifest.onChange);\n }\n if (component.manifest.onDescendantChange) {\n // @ts-expect-error Serialized form is a string (or string[]), but type expects a function.\n component.manifest.onDescendantChange = serializeHandlers(\n component.manifest.onDescendantChange\n );\n }\n this.registry.set(name, component);\n // notify subscribers\n this.listeners.forEach(fn => fn({ name, component }));\n }\n\n public get(name: string) {\n return this.registry.get(name);\n }\n\n public getManifests(): Record<string, ComponentManifest> {\n const manifests: Record<string, ComponentManifest> = {};\n this.registry.forEach((component, name) => {\n manifests[name] = component.manifest;\n });\n return manifests;\n }\n\n /** subscribe to *all* registrations */\n public onRegister(fn: (reg: Registration) => void) {\n this.listeners.add(fn);\n return () => this.listeners.delete(fn);\n }\n}\n\nfunction serializeHandlers(\n handler: ((...args: any[]) => any) | ((...args: any[]) => any)[]\n): string | string[] {\n if (Array.isArray(handler)) {\n return handler.map(h => functionConverter.serialize(h));\n }\n return functionConverter.serialize(handler);\n}\n\nexport const componentRegistry = new ComponentRegistry();\n"],"names":["ComponentRegistry","component","name","fn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tD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAACL,WAAWC;YAC9BI,SAAS,CAACJ,KAAK,GAAGD,UAAU,QAAQ;QACxC;QACA,OAAOK;IACX;IAGO,WAAWH,EAA+B,EAAE;QAC/C,IAAI,CAAC,SAAS,CAAC,GAAG,CAACA;QACnB,OAAO,IAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;IACvC;;aAzDQ,QAAQ,GAAG,IAAII;aACf,SAAS,GAAG,IAAIC;;AAyD5B;AAEA,SAASH,kBACLI,OAAgE;IAEhE,IAAIC,MAAM,OAAO,CAACD,UACd,OAAOA,QAAQ,GAAG,CAACE,CAAAA,IAAKP,kBAAkB,SAAS,CAACO;IAExD,OAAOP,kBAAkB,SAAS,CAACK;AACvC;AAEO,MAAMG,oBAAoB,IAAIZ"}
@@ -1,14 +1,17 @@
1
1
  import type { ComponentRegistry } from "./ComponentRegistry.js";
2
- import type { DocumentElement, DocumentElementBindings, DocumentState, ResolvedComponent } from "./types.js";
2
+ import type { DocumentCache, DocumentElement, DocumentElementBindings, DocumentState, ResolvedComponent } from "./types.js";
3
3
  import type { OnResolved } from "./BindingsResolver.js";
4
+ import type { ContentEntryCache } from "./contentEntry/ContentEntryCache.js";
4
5
  export type ResolveElementParams = {
5
6
  element: DocumentElement;
6
7
  elementBindings: DocumentElementBindings;
7
8
  state: DocumentState;
9
+ cache?: DocumentCache;
8
10
  onResolved?: OnResolved;
9
11
  };
10
12
  export declare class ComponentResolver {
11
13
  private components;
12
- constructor(registry: ComponentRegistry);
13
- resolve({ element, elementBindings, onResolved, state }: ResolveElementParams): ResolvedComponent[] | null;
14
+ private contentEntryCache;
15
+ constructor(registry: ComponentRegistry, cache?: ContentEntryCache);
16
+ resolve({ element, elementBindings, onResolved, state, cache }: ResolveElementParams): ResolvedComponent[] | null;
14
17
  }
@@ -1,19 +1,24 @@
1
1
  import { logger } from "./Logger.js";
2
2
  import { BindingsResolver } from "./BindingsResolver.js";
3
+ import { ContentEntryBindingsResolver } from "./contentEntry/ContentEntryBindingsResolver.js";
4
+ import { contentEntryCache } from "./contentEntry/ContentEntryCache.js";
3
5
  import { ComponentManifestToAstConverter } from "./ComponentManifestToAstConverter.js";
4
6
  class ComponentResolver {
5
- constructor(registry){
7
+ constructor(registry, cache = contentEntryCache){
6
8
  this.components = registry;
9
+ this.contentEntryCache = cache;
7
10
  }
8
- resolve({ element, elementBindings = {}, onResolved, state }) {
11
+ resolve({ element, elementBindings = {}, onResolved, state, cache }) {
9
12
  const componentName = element.component.name;
10
13
  const blueprint = this.components.get(componentName);
11
14
  if (!blueprint) {
12
15
  logger.warn(`Unknown component: ${componentName}`);
13
16
  return null;
14
17
  }
15
- const bindingsResolver = new BindingsResolver(state);
16
- const instances = bindingsResolver.resolveElement({
18
+ const embedded = cache?.contentEntries;
19
+ const resolvedEntries = embedded ? new Map(Object.entries(embedded)) : void 0;
20
+ const resolver = new ContentEntryBindingsResolver(new BindingsResolver(state), resolvedEntries, this.contentEntryCache);
21
+ const instances = resolver.resolveElement({
17
22
  element,
18
23
  elementBindings,
19
24
  inputAst: ComponentManifestToAstConverter.convert(blueprint.manifest.inputs ?? []),
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentResolver.js","sources":["../src/ComponentResolver.ts"],"sourcesContent":["import type { ComponentRegistry } from \"~/ComponentRegistry.js\";\nimport type {\n DocumentElement,\n DocumentElementBindings,\n DocumentState,\n ResolvedComponent\n} from \"~/types.js\";\nimport { logger } from \"./Logger.js\";\nimport type { OnResolved } from \"./BindingsResolver.js\";\nimport { BindingsResolver } from \"./BindingsResolver.js\";\nimport { ComponentManifestToAstConverter } from \"~/ComponentManifestToAstConverter.js\";\n\nexport type ResolveElementParams = {\n element: DocumentElement;\n elementBindings: DocumentElementBindings;\n state: DocumentState;\n onResolved?: OnResolved;\n};\n\nexport class ComponentResolver {\n private components: ComponentRegistry;\n\n constructor(registry: ComponentRegistry) {\n this.components = registry;\n }\n\n resolve({\n element,\n elementBindings = {},\n onResolved,\n state\n }: ResolveElementParams): ResolvedComponent[] | null {\n const componentName = element.component.name;\n const blueprint = this.components.get(componentName);\n\n if (!blueprint) {\n logger.warn(`Unknown component: ${componentName}`);\n return null;\n }\n\n const bindingsResolver = new BindingsResolver(state);\n const instances = bindingsResolver.resolveElement({\n element,\n elementBindings,\n inputAst: ComponentManifestToAstConverter.convert(blueprint.manifest.inputs ?? []),\n onResolved\n });\n\n return instances.map(instance => ({\n component: blueprint.component,\n manifest: blueprint.manifest!,\n styles: instance.styles,\n inputs: instance.inputs\n }));\n }\n}\n"],"names":["ComponentResolver","registry","element","elementBindings","onResolved","state","componentName","blueprint","logger","bindingsResolver","BindingsResolver","instances","ComponentManifestToAstConverter","instance"],"mappings":";;;AAmBO,MAAMA;IAGT,YAAYC,QAA2B,CAAE;QACrC,IAAI,CAAC,UAAU,GAAGA;IACtB;IAEA,QAAQ,EACJC,OAAO,EACPC,kBAAkB,CAAC,CAAC,EACpBC,UAAU,EACVC,KAAK,EACc,EAA8B;QACjD,MAAMC,gBAAgBJ,QAAQ,SAAS,CAAC,IAAI;QAC5C,MAAMK,YAAY,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD;QAEtC,IAAI,CAACC,WAAW;YACZC,OAAO,IAAI,CAAC,CAAC,mBAAmB,EAAEF,eAAe;YACjD,OAAO;QACX;QAEA,MAAMG,mBAAmB,IAAIC,iBAAiBL;QAC9C,MAAMM,YAAYF,iBAAiB,cAAc,CAAC;YAC9CP;YACAC;YACA,UAAUS,gCAAgC,OAAO,CAACL,UAAU,QAAQ,CAAC,MAAM,IAAI,EAAE;YACjFH;QACJ;QAEA,OAAOO,UAAU,GAAG,CAACE,CAAAA,WAAa;gBAC9B,WAAWN,UAAU,SAAS;gBAC9B,UAAUA,UAAU,QAAQ;gBAC5B,QAAQM,SAAS,MAAM;gBACvB,QAAQA,SAAS,MAAM;YAC3B;IACJ;AACJ"}
1
+ {"version":3,"file":"ComponentResolver.js","sources":["../src/ComponentResolver.ts"],"sourcesContent":["import type { ComponentRegistry } from \"~/ComponentRegistry.js\";\nimport type {\n DocumentCache,\n DocumentElement,\n DocumentElementBindings,\n DocumentState,\n ResolvedComponent\n} from \"~/types.js\";\nimport { logger } from \"./Logger.js\";\nimport type { OnResolved } from \"./BindingsResolver.js\";\nimport { BindingsResolver } from \"./BindingsResolver.js\";\nimport { ContentEntryBindingsResolver } from \"./contentEntry/ContentEntryBindingsResolver.js\";\nimport type { ContentEntryCache } from \"./contentEntry/ContentEntryCache.js\";\nimport { contentEntryCache } from \"./contentEntry/ContentEntryCache.js\";\nimport { ComponentManifestToAstConverter } from \"~/ComponentManifestToAstConverter.js\";\nexport type ResolveElementParams = {\n element: DocumentElement;\n elementBindings: DocumentElementBindings;\n state: DocumentState;\n cache?: DocumentCache;\n onResolved?: OnResolved;\n};\n\nexport class ComponentResolver {\n private components: ComponentRegistry;\n private contentEntryCache: ContentEntryCache;\n\n constructor(registry: ComponentRegistry, cache: ContentEntryCache = contentEntryCache) {\n this.components = registry;\n this.contentEntryCache = cache;\n }\n\n resolve({\n element,\n elementBindings = {},\n onResolved,\n state,\n cache\n }: ResolveElementParams): ResolvedComponent[] | null {\n const componentName = element.component.name;\n const blueprint = this.components.get(componentName);\n\n if (!blueprint) {\n logger.warn(`Unknown component: ${componentName}`);\n return null;\n }\n\n // Build the pre-resolved entries map from the document cache\n // (populated by `resolveContentEntries` on the server).\n const embedded = cache?.contentEntries as Record<string, unknown> | undefined;\n const resolvedEntries = embedded ? new Map(Object.entries(embedded)) : undefined;\n\n const resolver = new ContentEntryBindingsResolver(\n new BindingsResolver(state),\n resolvedEntries,\n this.contentEntryCache\n );\n\n const instances = resolver.resolveElement({\n element,\n elementBindings,\n inputAst: ComponentManifestToAstConverter.convert(blueprint.manifest.inputs ?? []),\n onResolved\n });\n\n return instances.map(instance => ({\n component: blueprint.component,\n manifest: blueprint.manifest!,\n styles: instance.styles,\n inputs: instance.inputs\n }));\n }\n}\n"],"names":["ComponentResolver","registry","cache","contentEntryCache","element","elementBindings","onResolved","state","componentName","blueprint","logger","embedded","resolvedEntries","Map","Object","undefined","resolver","ContentEntryBindingsResolver","BindingsResolver","instances","ComponentManifestToAstConverter","instance"],"mappings":";;;;;AAuBO,MAAMA;IAIT,YAAYC,QAA2B,EAAEC,QAA2BC,iBAAiB,CAAE;QACnF,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,iBAAiB,GAAGC;IAC7B;IAEA,QAAQ,EACJE,OAAO,EACPC,kBAAkB,CAAC,CAAC,EACpBC,UAAU,EACVC,KAAK,EACLL,KAAK,EACc,EAA8B;QACjD,MAAMM,gBAAgBJ,QAAQ,SAAS,CAAC,IAAI;QAC5C,MAAMK,YAAY,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD;QAEtC,IAAI,CAACC,WAAW;YACZC,OAAO,IAAI,CAAC,CAAC,mBAAmB,EAAEF,eAAe;YACjD,OAAO;QACX;QAIA,MAAMG,WAAWT,OAAO;QACxB,MAAMU,kBAAkBD,WAAW,IAAIE,IAAIC,OAAO,OAAO,CAACH,aAAaI;QAEvE,MAAMC,WAAW,IAAIC,6BACjB,IAAIC,iBAAiBX,QACrBK,iBACA,IAAI,CAAC,iBAAiB;QAG1B,MAAMO,YAAYH,SAAS,cAAc,CAAC;YACtCZ;YACAC;YACA,UAAUe,gCAAgC,OAAO,CAACX,UAAU,QAAQ,CAAC,MAAM,IAAI,EAAE;YACjFH;QACJ;QAEA,OAAOa,UAAU,GAAG,CAACE,CAAAA,WAAa;gBAC9B,WAAWZ,UAAU,SAAS;gBAC9B,UAAUA,UAAU,QAAQ;gBAC5B,QAAQY,SAAS,MAAM;gBACvB,QAAQA,SAAS,MAAM;YAC3B;IACJ;AACJ"}
@@ -17,6 +17,11 @@ export interface EvaluateConstraintsParams {
17
17
  document: Document;
18
18
  /** All registered component manifests */
19
19
  components: Record<string, ComponentManifest>;
20
+ /**
21
+ * The element being moved, when the placement is a move: it is already in the document, so
22
+ * `countInstances` leaves it out and a move counts like a new placement.
23
+ */
24
+ movedElementId?: string;
20
25
  }
21
26
  export declare function buildElementContext(element: DocumentElement, components: Record<string, ComponentManifest>, document: Document): ConstraintElementContext | undefined;
22
27
  export interface InternalAncestor {
@@ -1,3 +1,5 @@
1
+ import { GlobalElementId } from "./globalElements.js";
2
+ import { LayoutContentArea } from "./LayoutContentArea.js";
1
3
  class ConstraintBlockError extends Error {
2
4
  constructor(message){
3
5
  super(message);
@@ -92,9 +94,11 @@ function buildAncestors(parentElement, components, document) {
92
94
  }
93
95
  return ancestors;
94
96
  }
95
- function countInstances(document, componentName) {
97
+ function countInstances(document, componentName, excludeId) {
96
98
  let count = 0;
97
- for(const id in document.elements)if (document.elements[id].component.name === componentName) count++;
99
+ for(const id in document.elements)if (id !== excludeId) {
100
+ if (document.elements[id].component.name === componentName) count++;
101
+ }
98
102
  return count;
99
103
  }
100
104
  function hasDescendantWithTag(document, components, elementId, tag) {
@@ -117,7 +121,7 @@ function hasDescendantWithTag(document, components, elementId, tag) {
117
121
  return false;
118
122
  }
119
123
  function evaluateConstraints(params) {
120
- const { componentName, parentId, slot, document, components } = params;
124
+ const { componentName, parentId, slot, document, components, movedElementId } = params;
121
125
  const componentManifest = components[componentName];
122
126
  if (!componentManifest) return {
123
127
  allowed: true
@@ -155,7 +159,7 @@ function evaluateConstraints(params) {
155
159
  const items = parentInputs[slot]?.static;
156
160
  return Array.isArray(items) ? items.length : 0;
157
161
  },
158
- countInstances: (name)=>countInstances(document, name),
162
+ countInstances: (name)=>countInstances(document, name, movedElementId),
159
163
  hasDescendantWithTag: ()=>false,
160
164
  getAncestorInputs: ()=>void 0,
161
165
  getElementInputs: ()=>({}),
@@ -199,6 +203,18 @@ function evaluateDeleteConstraint(params) {
199
203
  allowed: true
200
204
  };
201
205
  const manifest = components[element.component.name];
206
+ if (GlobalElementId.isGlobal(element.id)) return {
207
+ allowed: false,
208
+ violation: {
209
+ message: `${manifest?.label ?? element.component.name} is a global component, so it can't be deleted here.`
210
+ }
211
+ };
212
+ if (LayoutContentArea.mainWithin(document, elementId)) return {
213
+ allowed: false,
214
+ violation: {
215
+ message: element.component.name === LayoutContentArea.MAIN_COMPONENT ? "Main content can't be deleted." : `${manifest?.label ?? element.component.name} holds Main content, so it can't be deleted.`
216
+ }
217
+ };
202
218
  if (!manifest) return {
203
219
  allowed: true
204
220
  };