@nordcraft/runtime 1.0.88 → 1.0.90

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 (66) hide show
  1. package/dist/custom-element.main.esm.js +24 -24
  2. package/dist/custom-element.main.esm.js.map +4 -4
  3. package/dist/page.main.esm.js +3 -3
  4. package/dist/page.main.esm.js.map +4 -4
  5. package/dist/src/components/createComponent.js +37 -36
  6. package/dist/src/components/createComponent.js.map +1 -1
  7. package/dist/src/components/createElement.js +0 -2
  8. package/dist/src/components/createElement.js.map +1 -1
  9. package/dist/src/components/createNode.js +12 -4
  10. package/dist/src/components/createNode.js.map +1 -1
  11. package/dist/src/components/createNode.test.d.ts +1 -0
  12. package/dist/src/components/createNode.test.js +608 -0
  13. package/dist/src/components/createNode.test.js.map +1 -0
  14. package/dist/src/components/meta.d.ts +3 -0
  15. package/dist/src/components/meta.js +18 -0
  16. package/dist/src/components/meta.js.map +1 -0
  17. package/dist/src/components/meta.test.d.ts +1 -0
  18. package/dist/src/components/meta.test.js +80 -0
  19. package/dist/src/components/meta.test.js.map +1 -0
  20. package/dist/src/components/renderComponent.js +2 -4
  21. package/dist/src/components/renderComponent.js.map +1 -1
  22. package/dist/src/editor/postMessageToEditor.d.ts +2 -0
  23. package/dist/src/editor/postMessageToEditor.js +4 -0
  24. package/dist/src/editor/postMessageToEditor.js.map +1 -0
  25. package/dist/src/editor-preview.main.js +12 -13
  26. package/dist/src/editor-preview.main.js.map +1 -1
  27. package/dist/src/page.main.js +46 -59
  28. package/dist/src/page.main.js.map +1 -1
  29. package/dist/src/styles/CustomPropertyStyleSheet.d.ts +0 -1
  30. package/dist/src/styles/CustomPropertyStyleSheet.js +1 -1
  31. package/dist/src/styles/CustomPropertyStyleSheet.js.map +1 -1
  32. package/dist/src/styles/CustomPropertyStyleSheet.test.js +2 -5
  33. package/dist/src/styles/CustomPropertyStyleSheet.test.js.map +1 -1
  34. package/dist/src/utils/BatchQueue.d.ts +1 -0
  35. package/dist/src/utils/BatchQueue.js +2 -1
  36. package/dist/src/utils/BatchQueue.js.map +1 -1
  37. package/dist/src/utils/getComponent.d.ts +5 -0
  38. package/dist/src/utils/getComponent.js +8 -0
  39. package/dist/src/utils/getComponent.js.map +1 -0
  40. package/dist/src/utils/getComponent.test.d.ts +1 -0
  41. package/dist/src/utils/getComponent.test.js +24 -0
  42. package/dist/src/utils/getComponent.test.js.map +1 -0
  43. package/dist/src/utils/markSelectedElement.d.ts +1 -0
  44. package/dist/src/utils/markSelectedElement.js +9 -0
  45. package/dist/src/utils/markSelectedElement.js.map +1 -0
  46. package/dist/src/utils/subscribeCustomProperty.d.ts +3 -3
  47. package/dist/src/utils/subscribeCustomProperty.js +2 -3
  48. package/dist/src/utils/subscribeCustomProperty.js.map +1 -1
  49. package/package.json +3 -3
  50. package/src/components/createComponent.ts +57 -51
  51. package/src/components/createElement.ts +0 -2
  52. package/src/components/createNode.test.ts +686 -0
  53. package/src/components/createNode.ts +17 -6
  54. package/src/components/meta.test.ts +90 -0
  55. package/src/components/meta.ts +23 -0
  56. package/src/components/renderComponent.ts +2 -4
  57. package/src/editor/postMessageToEditor.ts +5 -0
  58. package/src/editor-preview.main.ts +12 -15
  59. package/src/page.main.ts +47 -59
  60. package/src/styles/CustomPropertyStyleSheet.test.ts +2 -7
  61. package/src/styles/CustomPropertyStyleSheet.ts +1 -2
  62. package/src/utils/BatchQueue.ts +2 -2
  63. package/src/utils/getComponent.test.ts +29 -0
  64. package/src/utils/getComponent.ts +15 -0
  65. package/src/utils/markSelectedElement.ts +8 -0
  66. package/src/utils/subscribeCustomProperty.ts +1 -5
@@ -21,6 +21,7 @@ import { signal } from '../signal/signal'
21
21
  import type { ComponentChild, ComponentContext, ContextApi } from '../types'
22
22
  import { createFormulaCache } from '../utils/createFormulaCache'
23
23
  import { formulaHasValue } from '../utils/formulaHasValue'
24
+ import { getComponent } from '../utils/getComponent'
24
25
  import { subscribeCustomProperty } from '../utils/subscribeCustomProperty'
25
26
  import { renderComponent } from './renderComponent'
26
27
 
@@ -44,7 +45,11 @@ export function createComponent({
44
45
  namespace,
45
46
  }: RenderComponentNodeProps): ReadonlyArray<Element | Text> {
46
47
  const nodeLookupKey = [ctx.package, node.name].filter(isDefined).join('/')
47
- const component = ctx.components?.find((comp) => comp.name === nodeLookupKey)
48
+ const component = getComponent(
49
+ nodeLookupKey,
50
+ ctx.components,
51
+ ctx.env.runtime !== 'preview',
52
+ )
48
53
  if (!component) {
49
54
  // eslint-disable-next-line no-console
50
55
  console.warn(
@@ -76,55 +81,6 @@ export function createComponent({
76
81
  ])
77
82
  })
78
83
 
79
- Object.entries(node.customProperties ?? {})
80
- .filter(([_, { formula }]) => formulaHasValue(formula))
81
- .forEach(([customPropertyName, customProperty]) =>
82
- subscribeCustomProperty({
83
- selector: getNodeSelector(path, {
84
- componentName: ctx.component.name,
85
- nodeId: node.id,
86
- }),
87
- signal: dataSignal.map((data) =>
88
- appendUnit(
89
- applyFormula(customProperty.formula, {
90
- ...formulaCtx,
91
- data,
92
- }),
93
- customProperty.unit,
94
- ),
95
- ),
96
- customPropertyName,
97
- root: ctx.root,
98
- runtime: ctx.env.runtime,
99
- }),
100
- )
101
- node.variants?.forEach((variant) => {
102
- Object.entries(variant.customProperties ?? {})
103
- .filter(([_, { formula }]) => formulaHasValue(formula))
104
- .forEach(([customPropertyName, customProperty]) =>
105
- subscribeCustomProperty({
106
- selector: getNodeSelector(path, {
107
- componentName: ctx.component.name,
108
- nodeId: node.id,
109
- variant,
110
- }),
111
- signal: dataSignal.map((data) =>
112
- appendUnit(
113
- applyFormula(customProperty.formula, {
114
- ...formulaCtx,
115
- data,
116
- }),
117
- customProperty.unit,
118
- ),
119
- ),
120
- customPropertyName,
121
- variant,
122
- root: ctx.root,
123
- runtime: ctx.env.runtime,
124
- }),
125
- )
126
- })
127
-
128
84
  const componentDataSignal = signal<ComponentData>({
129
85
  Location: dataSignal.get().Location,
130
86
  Attributes: attributesSignal.get(),
@@ -321,7 +277,7 @@ export function createComponent({
321
277
  { destroy: () => componentDataSignal.destroy() },
322
278
  )
323
279
 
324
- return renderComponent({
280
+ const renderedComponent = renderComponent({
325
281
  dataSignal: componentDataSignal,
326
282
  component,
327
283
  components: ctx.components,
@@ -346,4 +302,54 @@ export function createComponent({
346
302
  ? { ...instance, [ctx.component.name]: 'root' }
347
303
  : { [ctx.component.name]: node.id ?? '' },
348
304
  })
305
+
306
+ // Custom properties instance overrides are added after the child tree is rendered to ensure correct order
307
+ Object.entries(node.customProperties ?? {})
308
+ .filter(([_, { formula }]) => formulaHasValue(formula))
309
+ .forEach(([customPropertyName, customProperty]) =>
310
+ subscribeCustomProperty({
311
+ selector: getNodeSelector(path, {
312
+ componentName: ctx.component.name,
313
+ nodeId: node.id,
314
+ }),
315
+ signal: dataSignal.map((data) =>
316
+ appendUnit(
317
+ applyFormula(customProperty.formula, {
318
+ ...formulaCtx,
319
+ data,
320
+ }),
321
+ customProperty.unit,
322
+ ),
323
+ ),
324
+ customPropertyName,
325
+ root: ctx.root,
326
+ }),
327
+ )
328
+ node.variants?.forEach((variant) => {
329
+ Object.entries(variant.customProperties ?? {})
330
+ .filter(([_, { formula }]) => formulaHasValue(formula))
331
+ .forEach(([customPropertyName, customProperty]) =>
332
+ subscribeCustomProperty({
333
+ selector: getNodeSelector(path, {
334
+ componentName: ctx.component.name,
335
+ nodeId: node.id,
336
+ variant,
337
+ }),
338
+ signal: dataSignal.map((data) =>
339
+ appendUnit(
340
+ applyFormula(customProperty.formula, {
341
+ ...formulaCtx,
342
+ data,
343
+ }),
344
+ customProperty.unit,
345
+ ),
346
+ ),
347
+ customPropertyName,
348
+ variant,
349
+ root: ctx.root,
350
+ }),
351
+ )
352
+ })
353
+
354
+ return renderedComponent
349
355
  }
@@ -169,7 +169,6 @@ export function createElement({
169
169
  ),
170
170
  ),
171
171
  root: ctx.root,
172
- runtime: ctx.env.runtime,
173
172
  })
174
173
  })
175
174
 
@@ -193,7 +192,6 @@ export function createElement({
193
192
  ),
194
193
  ),
195
194
  root: ctx.root,
196
- runtime: ctx.env.runtime,
197
195
  })
198
196
  })
199
197
  })