@almadar/ui 4.6.2 → 4.6.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.
@@ -4094,6 +4094,7 @@ var init_ThemeContext = __esm({
4094
4094
  });
4095
4095
  function EntitySchemaProvider({
4096
4096
  entities,
4097
+ traitLinkedEntities,
4097
4098
  children
4098
4099
  }) {
4099
4100
  const entitiesMap = React126.useMemo(() => {
@@ -4103,11 +4104,15 @@ function EntitySchemaProvider({
4103
4104
  }
4104
4105
  return map;
4105
4106
  }, [entities]);
4107
+ const linkedMap = React126.useMemo(() => {
4108
+ return traitLinkedEntities ?? /* @__PURE__ */ new Map();
4109
+ }, [traitLinkedEntities]);
4106
4110
  const contextValue = React126.useMemo(
4107
4111
  () => ({
4108
- entities: entitiesMap
4112
+ entities: entitiesMap,
4113
+ traitLinkedEntities: linkedMap
4109
4114
  }),
4110
- [entitiesMap]
4115
+ [entitiesMap, linkedMap]
4111
4116
  );
4112
4117
  return /* @__PURE__ */ jsxRuntime.jsx(EntitySchemaContext.Provider, { value: contextValue, children });
4113
4118
  }
@@ -31748,6 +31753,16 @@ function evaluateFormExpression(expr, formCtx) {
31748
31753
  const ctx = toSharedContext2(formCtx);
31749
31754
  return evaluator.evaluate(expr, ctx);
31750
31755
  }
31756
+ function isOrbitalEntitySchema(value) {
31757
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
31758
+ const fields = value.fields;
31759
+ return Array.isArray(fields);
31760
+ }
31761
+ function isPlainEntityRow(value) {
31762
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
31763
+ const fields = value.fields;
31764
+ return !Array.isArray(fields);
31765
+ }
31751
31766
  function getEnumOptions(field) {
31752
31767
  if (field.options && field.options.length > 0) {
31753
31768
  return [...field.options];
@@ -31893,9 +31908,12 @@ var init_Form = __esm({
31893
31908
  const { t } = useTranslate();
31894
31909
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
31895
31910
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
31896
- const normalizedInitialData = initialData ?? {};
31897
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
31911
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
31912
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
31898
31913
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
31914
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
31915
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
31916
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
31899
31917
  const entityDerivedFields = React126__namespace.default.useMemo(() => {
31900
31918
  if (fields && fields.length > 0) return void 0;
31901
31919
  if (!resolvedEntity) return void 0;
@@ -31932,11 +31950,10 @@ var init_Form = __esm({
31932
31950
  [formData, externalContext]
31933
31951
  );
31934
31952
  React126__namespace.default.useEffect(() => {
31935
- const data = initialData;
31936
- if (data && Object.keys(data).length > 0) {
31937
- setFormData(data);
31953
+ if (Object.keys(normalizedInitialData).length > 0) {
31954
+ setFormData(normalizedInitialData);
31938
31955
  }
31939
- }, [initialData]);
31956
+ }, [normalizedInitialData]);
31940
31957
  const processCalculations = React126__namespace.default.useCallback(
31941
31958
  (changedFieldId, newFormData) => {
31942
31959
  if (!hiddenCalculations.length) return;
@@ -46685,7 +46702,7 @@ function getToastPosition(position) {
46685
46702
  return "top-4 right-4";
46686
46703
  }
46687
46704
  }
46688
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
46705
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
46689
46706
  if (!children || !Array.isArray(children) || children.length === 0) {
46690
46707
  return null;
46691
46708
  }
@@ -46712,7 +46729,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
46712
46729
  pattern: child.type,
46713
46730
  props: resolvedProps,
46714
46731
  priority: 0,
46715
- nodeId: child._id
46732
+ nodeId: child._id,
46733
+ // Inherit sourceTrait from the parent slot so nested patterns
46734
+ // (e.g. form-section inside a stack) can resolve entityDef via
46735
+ // the trait's linkedEntity for form-field enrichment.
46736
+ ...sourceTrait !== void 0 && { sourceTrait }
46716
46737
  };
46717
46738
  return /* @__PURE__ */ jsxRuntime.jsx(
46718
46739
  SlotContentRenderer,
@@ -46763,13 +46784,21 @@ function SlotContentRenderer({
46763
46784
  }
46764
46785
  }
46765
46786
  const schemaCtx = useEntitySchemaOptional();
46766
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
46787
+ let entityDef;
46788
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
46789
+ entityDef = schemaCtx.entities.get(entityProp);
46790
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
46791
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
46792
+ if (linkedEntity !== void 0) {
46793
+ entityDef = schemaCtx.entities.get(linkedEntity);
46794
+ }
46795
+ }
46767
46796
  const PatternComponent = getComponentForPattern(content.pattern);
46768
46797
  if (PatternComponent) {
46769
46798
  const childrenConfig = content.props.children;
46770
46799
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
46771
46800
  const myPath = patternPath ?? "root";
46772
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
46801
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
46773
46802
  const { children: _childrenConfig, ...restProps } = content.props;
46774
46803
  const renderedProps = renderPatternProps(restProps, onDismiss);
46775
46804
  const finalProps = renderedProps;
@@ -52250,20 +52279,39 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
52250
52279
  if (!orbitals) return [];
52251
52280
  return orbitals.filter((o) => typeof o.name === "string").map((o) => o.name);
52252
52281
  }, [schema]);
52253
- const inner = /* @__PURE__ */ jsxRuntime.jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsxRuntime.jsx(SlotsProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
52254
- /* @__PURE__ */ jsxRuntime.jsx(
52255
- TraitInitializer,
52256
- {
52257
- traits: allPageTraits,
52258
- orbitalNames: serverUrl ? orbitalNames : void 0,
52259
- onNavigate,
52260
- onLocalFallback,
52261
- persistence
52262
- }
52263
- ),
52264
- /* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
52265
- /* @__PURE__ */ jsxRuntime.jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsxRuntime.jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
52266
- ] }) }) });
52282
+ const inner = /* @__PURE__ */ jsxRuntime.jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsxRuntime.jsx(SlotsProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(
52283
+ EntitySchemaProvider,
52284
+ {
52285
+ entities: Array.from(allEntities.values()),
52286
+ traitLinkedEntities: (() => {
52287
+ const map = /* @__PURE__ */ new Map();
52288
+ if (ir) {
52289
+ for (const page of ir.pages.values()) {
52290
+ for (const binding of page.traits) {
52291
+ if (binding.linkedEntity) {
52292
+ map.set(binding.trait.name, binding.linkedEntity);
52293
+ }
52294
+ }
52295
+ }
52296
+ }
52297
+ return map;
52298
+ })(),
52299
+ children: [
52300
+ /* @__PURE__ */ jsxRuntime.jsx(
52301
+ TraitInitializer,
52302
+ {
52303
+ traits: allPageTraits,
52304
+ orbitalNames: serverUrl ? orbitalNames : void 0,
52305
+ onNavigate,
52306
+ onLocalFallback,
52307
+ persistence
52308
+ }
52309
+ ),
52310
+ /* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
52311
+ /* @__PURE__ */ jsxRuntime.jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsxRuntime.jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
52312
+ ]
52313
+ }
52314
+ ) }) });
52267
52315
  if (serverUrl) {
52268
52316
  return /* @__PURE__ */ jsxRuntime.jsx(ServerBridgeProvider, { schema, serverUrl, children: inner });
52269
52317
  }
package/dist/avl/index.js CHANGED
@@ -4048,6 +4048,7 @@ var init_ThemeContext = __esm({
4048
4048
  });
4049
4049
  function EntitySchemaProvider({
4050
4050
  entities,
4051
+ traitLinkedEntities,
4051
4052
  children
4052
4053
  }) {
4053
4054
  const entitiesMap = useMemo(() => {
@@ -4057,11 +4058,15 @@ function EntitySchemaProvider({
4057
4058
  }
4058
4059
  return map;
4059
4060
  }, [entities]);
4061
+ const linkedMap = useMemo(() => {
4062
+ return traitLinkedEntities ?? /* @__PURE__ */ new Map();
4063
+ }, [traitLinkedEntities]);
4060
4064
  const contextValue = useMemo(
4061
4065
  () => ({
4062
- entities: entitiesMap
4066
+ entities: entitiesMap,
4067
+ traitLinkedEntities: linkedMap
4063
4068
  }),
4064
- [entitiesMap]
4069
+ [entitiesMap, linkedMap]
4065
4070
  );
4066
4071
  return /* @__PURE__ */ jsx(EntitySchemaContext.Provider, { value: contextValue, children });
4067
4072
  }
@@ -31702,6 +31707,16 @@ function evaluateFormExpression(expr, formCtx) {
31702
31707
  const ctx = toSharedContext2(formCtx);
31703
31708
  return evaluate(expr, ctx);
31704
31709
  }
31710
+ function isOrbitalEntitySchema(value) {
31711
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
31712
+ const fields = value.fields;
31713
+ return Array.isArray(fields);
31714
+ }
31715
+ function isPlainEntityRow(value) {
31716
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
31717
+ const fields = value.fields;
31718
+ return !Array.isArray(fields);
31719
+ }
31705
31720
  function getEnumOptions(field) {
31706
31721
  if (field.options && field.options.length > 0) {
31707
31722
  return [...field.options];
@@ -31847,9 +31862,12 @@ var init_Form = __esm({
31847
31862
  const { t } = useTranslate();
31848
31863
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
31849
31864
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
31850
- const normalizedInitialData = initialData ?? {};
31851
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
31865
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
31866
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
31852
31867
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
31868
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
31869
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
31870
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
31853
31871
  const entityDerivedFields = React126__default.useMemo(() => {
31854
31872
  if (fields && fields.length > 0) return void 0;
31855
31873
  if (!resolvedEntity) return void 0;
@@ -31886,11 +31904,10 @@ var init_Form = __esm({
31886
31904
  [formData, externalContext]
31887
31905
  );
31888
31906
  React126__default.useEffect(() => {
31889
- const data = initialData;
31890
- if (data && Object.keys(data).length > 0) {
31891
- setFormData(data);
31907
+ if (Object.keys(normalizedInitialData).length > 0) {
31908
+ setFormData(normalizedInitialData);
31892
31909
  }
31893
- }, [initialData]);
31910
+ }, [normalizedInitialData]);
31894
31911
  const processCalculations = React126__default.useCallback(
31895
31912
  (changedFieldId, newFormData) => {
31896
31913
  if (!hiddenCalculations.length) return;
@@ -46639,7 +46656,7 @@ function getToastPosition(position) {
46639
46656
  return "top-4 right-4";
46640
46657
  }
46641
46658
  }
46642
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
46659
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
46643
46660
  if (!children || !Array.isArray(children) || children.length === 0) {
46644
46661
  return null;
46645
46662
  }
@@ -46666,7 +46683,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
46666
46683
  pattern: child.type,
46667
46684
  props: resolvedProps,
46668
46685
  priority: 0,
46669
- nodeId: child._id
46686
+ nodeId: child._id,
46687
+ // Inherit sourceTrait from the parent slot so nested patterns
46688
+ // (e.g. form-section inside a stack) can resolve entityDef via
46689
+ // the trait's linkedEntity for form-field enrichment.
46690
+ ...sourceTrait !== void 0 && { sourceTrait }
46670
46691
  };
46671
46692
  return /* @__PURE__ */ jsx(
46672
46693
  SlotContentRenderer,
@@ -46717,13 +46738,21 @@ function SlotContentRenderer({
46717
46738
  }
46718
46739
  }
46719
46740
  const schemaCtx = useEntitySchemaOptional();
46720
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
46741
+ let entityDef;
46742
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
46743
+ entityDef = schemaCtx.entities.get(entityProp);
46744
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
46745
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
46746
+ if (linkedEntity !== void 0) {
46747
+ entityDef = schemaCtx.entities.get(linkedEntity);
46748
+ }
46749
+ }
46721
46750
  const PatternComponent = getComponentForPattern(content.pattern);
46722
46751
  if (PatternComponent) {
46723
46752
  const childrenConfig = content.props.children;
46724
46753
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
46725
46754
  const myPath = patternPath ?? "root";
46726
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
46755
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
46727
46756
  const { children: _childrenConfig, ...restProps } = content.props;
46728
46757
  const renderedProps = renderPatternProps(restProps, onDismiss);
46729
46758
  const finalProps = renderedProps;
@@ -52204,20 +52233,39 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
52204
52233
  if (!orbitals) return [];
52205
52234
  return orbitals.filter((o) => typeof o.name === "string").map((o) => o.name);
52206
52235
  }, [schema]);
52207
- const inner = /* @__PURE__ */ jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsx(SlotsProvider, { children: /* @__PURE__ */ jsxs(EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
52208
- /* @__PURE__ */ jsx(
52209
- TraitInitializer,
52210
- {
52211
- traits: allPageTraits,
52212
- orbitalNames: serverUrl ? orbitalNames : void 0,
52213
- onNavigate,
52214
- onLocalFallback,
52215
- persistence
52216
- }
52217
- ),
52218
- /* @__PURE__ */ jsx(SlotBridge, {}),
52219
- /* @__PURE__ */ jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
52220
- ] }) }) });
52236
+ const inner = /* @__PURE__ */ jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsx(SlotsProvider, { children: /* @__PURE__ */ jsxs(
52237
+ EntitySchemaProvider,
52238
+ {
52239
+ entities: Array.from(allEntities.values()),
52240
+ traitLinkedEntities: (() => {
52241
+ const map = /* @__PURE__ */ new Map();
52242
+ if (ir) {
52243
+ for (const page of ir.pages.values()) {
52244
+ for (const binding of page.traits) {
52245
+ if (binding.linkedEntity) {
52246
+ map.set(binding.trait.name, binding.linkedEntity);
52247
+ }
52248
+ }
52249
+ }
52250
+ }
52251
+ return map;
52252
+ })(),
52253
+ children: [
52254
+ /* @__PURE__ */ jsx(
52255
+ TraitInitializer,
52256
+ {
52257
+ traits: allPageTraits,
52258
+ orbitalNames: serverUrl ? orbitalNames : void 0,
52259
+ onNavigate,
52260
+ onLocalFallback,
52261
+ persistence
52262
+ }
52263
+ ),
52264
+ /* @__PURE__ */ jsx(SlotBridge, {}),
52265
+ /* @__PURE__ */ jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
52266
+ ]
52267
+ }
52268
+ ) }) });
52221
52269
  if (serverUrl) {
52222
52270
  return /* @__PURE__ */ jsx(ServerBridgeProvider, { schema, serverUrl, children: inner });
52223
52271
  }
@@ -27641,6 +27641,16 @@ function evaluateFormExpression(expr, formCtx) {
27641
27641
  const ctx = toSharedContext2(formCtx);
27642
27642
  return evaluator.evaluate(expr, ctx);
27643
27643
  }
27644
+ function isOrbitalEntitySchema(value) {
27645
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
27646
+ const fields = value.fields;
27647
+ return Array.isArray(fields);
27648
+ }
27649
+ function isPlainEntityRow(value) {
27650
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
27651
+ const fields = value.fields;
27652
+ return !Array.isArray(fields);
27653
+ }
27644
27654
  function getEnumOptions(field) {
27645
27655
  if (field.options && field.options.length > 0) {
27646
27656
  return [...field.options];
@@ -27786,9 +27796,12 @@ var init_Form = __esm({
27786
27796
  const { t } = useTranslate();
27787
27797
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
27788
27798
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
27789
- const normalizedInitialData = initialData ?? {};
27790
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
27799
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
27800
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
27791
27801
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
27802
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
27803
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
27804
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
27792
27805
  const entityDerivedFields = React110__namespace.default.useMemo(() => {
27793
27806
  if (fields && fields.length > 0) return void 0;
27794
27807
  if (!resolvedEntity) return void 0;
@@ -27825,11 +27838,10 @@ var init_Form = __esm({
27825
27838
  [formData, externalContext]
27826
27839
  );
27827
27840
  React110__namespace.default.useEffect(() => {
27828
- const data = initialData;
27829
- if (data && Object.keys(data).length > 0) {
27830
- setFormData(data);
27841
+ if (Object.keys(normalizedInitialData).length > 0) {
27842
+ setFormData(normalizedInitialData);
27831
27843
  }
27832
- }, [initialData]);
27844
+ }, [normalizedInitialData]);
27833
27845
  const processCalculations = React110__namespace.default.useCallback(
27834
27846
  (changedFieldId, newFormData) => {
27835
27847
  if (!hiddenCalculations.length) return;
@@ -37531,7 +37543,7 @@ function getToastPosition(position) {
37531
37543
  return "top-4 right-4";
37532
37544
  }
37533
37545
  }
37534
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
37546
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
37535
37547
  if (!children || !Array.isArray(children) || children.length === 0) {
37536
37548
  return null;
37537
37549
  }
@@ -37558,7 +37570,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
37558
37570
  pattern: child.type,
37559
37571
  props: resolvedProps,
37560
37572
  priority: 0,
37561
- nodeId: child._id
37573
+ nodeId: child._id,
37574
+ // Inherit sourceTrait from the parent slot so nested patterns
37575
+ // (e.g. form-section inside a stack) can resolve entityDef via
37576
+ // the trait's linkedEntity for form-field enrichment.
37577
+ ...sourceTrait !== void 0 && { sourceTrait }
37562
37578
  };
37563
37579
  return /* @__PURE__ */ jsxRuntime.jsx(
37564
37580
  SlotContentRenderer,
@@ -37609,13 +37625,21 @@ function SlotContentRenderer({
37609
37625
  }
37610
37626
  }
37611
37627
  const schemaCtx = useEntitySchemaOptional();
37612
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
37628
+ let entityDef;
37629
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
37630
+ entityDef = schemaCtx.entities.get(entityProp);
37631
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
37632
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
37633
+ if (linkedEntity !== void 0) {
37634
+ entityDef = schemaCtx.entities.get(linkedEntity);
37635
+ }
37636
+ }
37613
37637
  const PatternComponent = getComponentForPattern(content.pattern);
37614
37638
  if (PatternComponent) {
37615
37639
  const childrenConfig = content.props.children;
37616
37640
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
37617
37641
  const myPath = patternPath ?? "root";
37618
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
37642
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
37619
37643
  const { children: _childrenConfig, ...restProps } = content.props;
37620
37644
  const renderedProps = renderPatternProps(restProps, onDismiss);
37621
37645
  const finalProps = renderedProps;
@@ -27596,6 +27596,16 @@ function evaluateFormExpression(expr, formCtx) {
27596
27596
  const ctx = toSharedContext2(formCtx);
27597
27597
  return evaluate(expr, ctx);
27598
27598
  }
27599
+ function isOrbitalEntitySchema(value) {
27600
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
27601
+ const fields = value.fields;
27602
+ return Array.isArray(fields);
27603
+ }
27604
+ function isPlainEntityRow(value) {
27605
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
27606
+ const fields = value.fields;
27607
+ return !Array.isArray(fields);
27608
+ }
27599
27609
  function getEnumOptions(field) {
27600
27610
  if (field.options && field.options.length > 0) {
27601
27611
  return [...field.options];
@@ -27741,9 +27751,12 @@ var init_Form = __esm({
27741
27751
  const { t } = useTranslate();
27742
27752
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
27743
27753
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
27744
- const normalizedInitialData = initialData ?? {};
27745
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
27754
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
27755
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
27746
27756
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
27757
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
27758
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
27759
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
27747
27760
  const entityDerivedFields = React110__default.useMemo(() => {
27748
27761
  if (fields && fields.length > 0) return void 0;
27749
27762
  if (!resolvedEntity) return void 0;
@@ -27780,11 +27793,10 @@ var init_Form = __esm({
27780
27793
  [formData, externalContext]
27781
27794
  );
27782
27795
  React110__default.useEffect(() => {
27783
- const data = initialData;
27784
- if (data && Object.keys(data).length > 0) {
27785
- setFormData(data);
27796
+ if (Object.keys(normalizedInitialData).length > 0) {
27797
+ setFormData(normalizedInitialData);
27786
27798
  }
27787
- }, [initialData]);
27799
+ }, [normalizedInitialData]);
27788
27800
  const processCalculations = React110__default.useCallback(
27789
27801
  (changedFieldId, newFormData) => {
27790
27802
  if (!hiddenCalculations.length) return;
@@ -37486,7 +37498,7 @@ function getToastPosition(position) {
37486
37498
  return "top-4 right-4";
37487
37499
  }
37488
37500
  }
37489
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
37501
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
37490
37502
  if (!children || !Array.isArray(children) || children.length === 0) {
37491
37503
  return null;
37492
37504
  }
@@ -37513,7 +37525,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
37513
37525
  pattern: child.type,
37514
37526
  props: resolvedProps,
37515
37527
  priority: 0,
37516
- nodeId: child._id
37528
+ nodeId: child._id,
37529
+ // Inherit sourceTrait from the parent slot so nested patterns
37530
+ // (e.g. form-section inside a stack) can resolve entityDef via
37531
+ // the trait's linkedEntity for form-field enrichment.
37532
+ ...sourceTrait !== void 0 && { sourceTrait }
37517
37533
  };
37518
37534
  return /* @__PURE__ */ jsx(
37519
37535
  SlotContentRenderer,
@@ -37564,13 +37580,21 @@ function SlotContentRenderer({
37564
37580
  }
37565
37581
  }
37566
37582
  const schemaCtx = useEntitySchemaOptional();
37567
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
37583
+ let entityDef;
37584
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
37585
+ entityDef = schemaCtx.entities.get(entityProp);
37586
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
37587
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
37588
+ if (linkedEntity !== void 0) {
37589
+ entityDef = schemaCtx.entities.get(linkedEntity);
37590
+ }
37591
+ }
37568
37592
  const PatternComponent = getComponentForPattern(content.pattern);
37569
37593
  if (PatternComponent) {
37570
37594
  const childrenConfig = content.props.children;
37571
37595
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
37572
37596
  const myPath = patternPath ?? "root";
37573
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
37597
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
37574
37598
  const { children: _childrenConfig, ...restProps } = content.props;
37575
37599
  const renderedProps = renderPatternProps(restProps, onDismiss);
37576
37600
  const finalProps = renderedProps;
@@ -28588,6 +28588,16 @@ function evaluateFormExpression(expr, formCtx) {
28588
28588
  const ctx = toSharedContext2(formCtx);
28589
28589
  return evaluator.evaluate(expr, ctx);
28590
28590
  }
28591
+ function isOrbitalEntitySchema(value) {
28592
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28593
+ const fields = value.fields;
28594
+ return Array.isArray(fields);
28595
+ }
28596
+ function isPlainEntityRow(value) {
28597
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28598
+ const fields = value.fields;
28599
+ return !Array.isArray(fields);
28600
+ }
28591
28601
  function getEnumOptions(field) {
28592
28602
  if (field.options && field.options.length > 0) {
28593
28603
  return [...field.options];
@@ -28733,9 +28743,12 @@ var init_Form = __esm({
28733
28743
  const { t } = useTranslate();
28734
28744
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
28735
28745
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
28736
- const normalizedInitialData = initialData ?? {};
28737
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
28746
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
28747
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
28738
28748
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
28749
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
28750
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
28751
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
28739
28752
  const entityDerivedFields = React115__namespace.default.useMemo(() => {
28740
28753
  if (fields && fields.length > 0) return void 0;
28741
28754
  if (!resolvedEntity) return void 0;
@@ -28772,11 +28785,10 @@ var init_Form = __esm({
28772
28785
  [formData, externalContext]
28773
28786
  );
28774
28787
  React115__namespace.default.useEffect(() => {
28775
- const data = initialData;
28776
- if (data && Object.keys(data).length > 0) {
28777
- setFormData(data);
28788
+ if (Object.keys(normalizedInitialData).length > 0) {
28789
+ setFormData(normalizedInitialData);
28778
28790
  }
28779
- }, [initialData]);
28791
+ }, [normalizedInitialData]);
28780
28792
  const processCalculations = React115__namespace.default.useCallback(
28781
28793
  (changedFieldId, newFormData) => {
28782
28794
  if (!hiddenCalculations.length) return;
@@ -38040,7 +38052,7 @@ function getToastPosition(position) {
38040
38052
  return "top-4 right-4";
38041
38053
  }
38042
38054
  }
38043
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
38055
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
38044
38056
  if (!children || !Array.isArray(children) || children.length === 0) {
38045
38057
  return null;
38046
38058
  }
@@ -38067,7 +38079,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
38067
38079
  pattern: child.type,
38068
38080
  props: resolvedProps,
38069
38081
  priority: 0,
38070
- nodeId: child._id
38082
+ nodeId: child._id,
38083
+ // Inherit sourceTrait from the parent slot so nested patterns
38084
+ // (e.g. form-section inside a stack) can resolve entityDef via
38085
+ // the trait's linkedEntity for form-field enrichment.
38086
+ ...sourceTrait !== void 0 && { sourceTrait }
38071
38087
  };
38072
38088
  return /* @__PURE__ */ jsxRuntime.jsx(
38073
38089
  SlotContentRenderer,
@@ -38118,13 +38134,21 @@ function SlotContentRenderer({
38118
38134
  }
38119
38135
  }
38120
38136
  const schemaCtx = useEntitySchemaOptional();
38121
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
38137
+ let entityDef;
38138
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
38139
+ entityDef = schemaCtx.entities.get(entityProp);
38140
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
38141
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
38142
+ if (linkedEntity !== void 0) {
38143
+ entityDef = schemaCtx.entities.get(linkedEntity);
38144
+ }
38145
+ }
38122
38146
  const PatternComponent = getComponentForPattern(content.pattern);
38123
38147
  if (PatternComponent) {
38124
38148
  const childrenConfig = content.props.children;
38125
38149
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
38126
38150
  const myPath = patternPath ?? "root";
38127
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
38151
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
38128
38152
  const { children: _childrenConfig, ...restProps } = content.props;
38129
38153
  const renderedProps = renderPatternProps(restProps, onDismiss);
38130
38154
  const finalProps = renderedProps;
@@ -28543,6 +28543,16 @@ function evaluateFormExpression(expr, formCtx) {
28543
28543
  const ctx = toSharedContext2(formCtx);
28544
28544
  return evaluate(expr, ctx);
28545
28545
  }
28546
+ function isOrbitalEntitySchema(value) {
28547
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28548
+ const fields = value.fields;
28549
+ return Array.isArray(fields);
28550
+ }
28551
+ function isPlainEntityRow(value) {
28552
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28553
+ const fields = value.fields;
28554
+ return !Array.isArray(fields);
28555
+ }
28546
28556
  function getEnumOptions(field) {
28547
28557
  if (field.options && field.options.length > 0) {
28548
28558
  return [...field.options];
@@ -28688,9 +28698,12 @@ var init_Form = __esm({
28688
28698
  const { t } = useTranslate();
28689
28699
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
28690
28700
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
28691
- const normalizedInitialData = initialData ?? {};
28692
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
28701
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
28702
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
28693
28703
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
28704
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
28705
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
28706
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
28694
28707
  const entityDerivedFields = React115__default.useMemo(() => {
28695
28708
  if (fields && fields.length > 0) return void 0;
28696
28709
  if (!resolvedEntity) return void 0;
@@ -28727,11 +28740,10 @@ var init_Form = __esm({
28727
28740
  [formData, externalContext]
28728
28741
  );
28729
28742
  React115__default.useEffect(() => {
28730
- const data = initialData;
28731
- if (data && Object.keys(data).length > 0) {
28732
- setFormData(data);
28743
+ if (Object.keys(normalizedInitialData).length > 0) {
28744
+ setFormData(normalizedInitialData);
28733
28745
  }
28734
- }, [initialData]);
28746
+ }, [normalizedInitialData]);
28735
28747
  const processCalculations = React115__default.useCallback(
28736
28748
  (changedFieldId, newFormData) => {
28737
28749
  if (!hiddenCalculations.length) return;
@@ -37995,7 +38007,7 @@ function getToastPosition(position) {
37995
38007
  return "top-4 right-4";
37996
38008
  }
37997
38009
  }
37998
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
38010
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
37999
38011
  if (!children || !Array.isArray(children) || children.length === 0) {
38000
38012
  return null;
38001
38013
  }
@@ -38022,7 +38034,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
38022
38034
  pattern: child.type,
38023
38035
  props: resolvedProps,
38024
38036
  priority: 0,
38025
- nodeId: child._id
38037
+ nodeId: child._id,
38038
+ // Inherit sourceTrait from the parent slot so nested patterns
38039
+ // (e.g. form-section inside a stack) can resolve entityDef via
38040
+ // the trait's linkedEntity for form-field enrichment.
38041
+ ...sourceTrait !== void 0 && { sourceTrait }
38026
38042
  };
38027
38043
  return /* @__PURE__ */ jsx(
38028
38044
  SlotContentRenderer,
@@ -38073,13 +38089,21 @@ function SlotContentRenderer({
38073
38089
  }
38074
38090
  }
38075
38091
  const schemaCtx = useEntitySchemaOptional();
38076
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
38092
+ let entityDef;
38093
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
38094
+ entityDef = schemaCtx.entities.get(entityProp);
38095
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
38096
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
38097
+ if (linkedEntity !== void 0) {
38098
+ entityDef = schemaCtx.entities.get(linkedEntity);
38099
+ }
38100
+ }
38077
38101
  const PatternComponent = getComponentForPattern(content.pattern);
38078
38102
  if (PatternComponent) {
38079
38103
  const childrenConfig = content.props.children;
38080
38104
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
38081
38105
  const myPath = patternPath ?? "root";
38082
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
38106
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
38083
38107
  const { children: _childrenConfig, ...restProps } = content.props;
38084
38108
  const renderedProps = renderPatternProps(restProps, onDismiss);
38085
38109
  const finalProps = renderedProps;
@@ -15,10 +15,31 @@ import type { ResolvedEntity } from '@almadar/core';
15
15
  export interface EntitySchemaContextValue {
16
16
  /** Entity definitions (schema metadata only) */
17
17
  entities: Map<string, ResolvedEntity>;
18
+ /**
19
+ * Per-trait linkedEntity name. `ResolvedTrait` itself doesn't carry
20
+ * linkedEntity (it lives on `ResolvedTraitBinding` at the page-binding
21
+ * level), so OrbPreview pre-projects every page's trait bindings into
22
+ * a flat `traitName → entityName` map for the slot renderer.
23
+ *
24
+ * Used by SlotContentRenderer to resolve `entityDef` via
25
+ * `traitLinkedEntities.get(sourceTrait) → entities.get(...)` when the
26
+ * rendered pattern's `entity:` prop is a resolved value (V2 path)
27
+ * rather than a string entity-name. Without this lookup, form-section
28
+ * can't enrich its fields with entity field metadata (values enum,
29
+ * etc.) and an enum field renders as a plain text input. Closes VR3.
30
+ */
31
+ traitLinkedEntities: ReadonlyMap<string, string>;
18
32
  }
19
33
  export interface EntitySchemaProviderProps {
20
34
  /** Entity definitions from resolved schema */
21
35
  entities: ResolvedEntity[];
36
+ /**
37
+ * Per-trait linkedEntity name, projected from every page's
38
+ * ResolvedTraitBinding. Optional for back-compat; when omitted,
39
+ * SlotContentRenderer's enrichment path can only follow the
40
+ * legacy V1 string-entity-name lookup.
41
+ */
42
+ traitLinkedEntities?: ReadonlyMap<string, string>;
22
43
  /** Children */
23
44
  children: React.ReactNode;
24
45
  }
@@ -29,7 +50,7 @@ export interface EntitySchemaProviderProps {
29
50
  * Actual entity rows arrive via `@payload.data` on the rendering trait's
30
51
  * success transition — they do NOT live in this context.
31
52
  */
32
- export declare function EntitySchemaProvider({ entities, children, }: EntitySchemaProviderProps): React.ReactElement;
53
+ export declare function EntitySchemaProvider({ entities, traitLinkedEntities, children, }: EntitySchemaProviderProps): React.ReactElement;
33
54
  /**
34
55
  * Access entity schema definitions.
35
56
  * Use this for field metadata (form building, filter enrichment).
@@ -784,6 +784,7 @@ var init_usePullToRefresh = __esm({
784
784
  });
785
785
  function EntitySchemaProvider({
786
786
  entities,
787
+ traitLinkedEntities,
787
788
  children
788
789
  }) {
789
790
  const entitiesMap = React115.useMemo(() => {
@@ -793,11 +794,15 @@ function EntitySchemaProvider({
793
794
  }
794
795
  return map;
795
796
  }, [entities]);
797
+ const linkedMap = React115.useMemo(() => {
798
+ return traitLinkedEntities ?? /* @__PURE__ */ new Map();
799
+ }, [traitLinkedEntities]);
796
800
  const contextValue = React115.useMemo(
797
801
  () => ({
798
- entities: entitiesMap
802
+ entities: entitiesMap,
803
+ traitLinkedEntities: linkedMap
799
804
  }),
800
- [entitiesMap]
805
+ [entitiesMap, linkedMap]
801
806
  );
802
807
  return /* @__PURE__ */ jsxRuntime.jsx(EntitySchemaContext.Provider, { value: contextValue, children });
803
808
  }
@@ -28190,6 +28195,16 @@ function evaluateFormExpression(expr, formCtx) {
28190
28195
  const ctx = toSharedContext2(formCtx);
28191
28196
  return evaluator.evaluate(expr, ctx);
28192
28197
  }
28198
+ function isOrbitalEntitySchema(value) {
28199
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28200
+ const fields = value.fields;
28201
+ return Array.isArray(fields);
28202
+ }
28203
+ function isPlainEntityRow(value) {
28204
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28205
+ const fields = value.fields;
28206
+ return !Array.isArray(fields);
28207
+ }
28193
28208
  function getEnumOptions(field) {
28194
28209
  if (field.options && field.options.length > 0) {
28195
28210
  return [...field.options];
@@ -28335,9 +28350,12 @@ var init_Form = __esm({
28335
28350
  const { t } = useTranslate();
28336
28351
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
28337
28352
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
28338
- const normalizedInitialData = initialData ?? {};
28339
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
28353
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
28354
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
28340
28355
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
28356
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
28357
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
28358
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
28341
28359
  const entityDerivedFields = React115__namespace.default.useMemo(() => {
28342
28360
  if (fields && fields.length > 0) return void 0;
28343
28361
  if (!resolvedEntity) return void 0;
@@ -28374,11 +28392,10 @@ var init_Form = __esm({
28374
28392
  [formData, externalContext]
28375
28393
  );
28376
28394
  React115__namespace.default.useEffect(() => {
28377
- const data = initialData;
28378
- if (data && Object.keys(data).length > 0) {
28379
- setFormData(data);
28395
+ if (Object.keys(normalizedInitialData).length > 0) {
28396
+ setFormData(normalizedInitialData);
28380
28397
  }
28381
- }, [initialData]);
28398
+ }, [normalizedInitialData]);
28382
28399
  const processCalculations = React115__namespace.default.useCallback(
28383
28400
  (changedFieldId, newFormData) => {
28384
28401
  if (!hiddenCalculations.length) return;
@@ -37626,7 +37643,7 @@ function getToastPosition(position) {
37626
37643
  return "top-4 right-4";
37627
37644
  }
37628
37645
  }
37629
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
37646
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
37630
37647
  if (!children || !Array.isArray(children) || children.length === 0) {
37631
37648
  return null;
37632
37649
  }
@@ -37653,7 +37670,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
37653
37670
  pattern: child.type,
37654
37671
  props: resolvedProps,
37655
37672
  priority: 0,
37656
- nodeId: child._id
37673
+ nodeId: child._id,
37674
+ // Inherit sourceTrait from the parent slot so nested patterns
37675
+ // (e.g. form-section inside a stack) can resolve entityDef via
37676
+ // the trait's linkedEntity for form-field enrichment.
37677
+ ...sourceTrait !== void 0 && { sourceTrait }
37657
37678
  };
37658
37679
  return /* @__PURE__ */ jsxRuntime.jsx(
37659
37680
  SlotContentRenderer,
@@ -37704,13 +37725,21 @@ function SlotContentRenderer({
37704
37725
  }
37705
37726
  }
37706
37727
  const schemaCtx = useEntitySchemaOptional();
37707
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
37728
+ let entityDef;
37729
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
37730
+ entityDef = schemaCtx.entities.get(entityProp);
37731
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
37732
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
37733
+ if (linkedEntity !== void 0) {
37734
+ entityDef = schemaCtx.entities.get(linkedEntity);
37735
+ }
37736
+ }
37708
37737
  const PatternComponent = getComponentForPattern(content.pattern);
37709
37738
  if (PatternComponent) {
37710
37739
  const childrenConfig = content.props.children;
37711
37740
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
37712
37741
  const myPath = patternPath ?? "root";
37713
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
37742
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
37714
37743
  const { children: _childrenConfig, ...restProps } = content.props;
37715
37744
  const renderedProps = renderPatternProps(restProps, onDismiss);
37716
37745
  const finalProps = renderedProps;
@@ -39090,20 +39119,39 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
39090
39119
  if (!orbitals) return [];
39091
39120
  return orbitals.filter((o) => typeof o.name === "string").map((o) => o.name);
39092
39121
  }, [schema]);
39093
- const inner = /* @__PURE__ */ jsxRuntime.jsx(providers.VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsxRuntime.jsx(SlotsProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
39094
- /* @__PURE__ */ jsxRuntime.jsx(
39095
- TraitInitializer,
39096
- {
39097
- traits: allPageTraits,
39098
- orbitalNames: serverUrl ? orbitalNames : void 0,
39099
- onNavigate,
39100
- onLocalFallback,
39101
- persistence
39102
- }
39103
- ),
39104
- /* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
39105
- /* @__PURE__ */ jsxRuntime.jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsxRuntime.jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
39106
- ] }) }) });
39122
+ const inner = /* @__PURE__ */ jsxRuntime.jsx(providers.VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsxRuntime.jsx(SlotsProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(
39123
+ EntitySchemaProvider,
39124
+ {
39125
+ entities: Array.from(allEntities.values()),
39126
+ traitLinkedEntities: (() => {
39127
+ const map = /* @__PURE__ */ new Map();
39128
+ if (ir) {
39129
+ for (const page of ir.pages.values()) {
39130
+ for (const binding of page.traits) {
39131
+ if (binding.linkedEntity) {
39132
+ map.set(binding.trait.name, binding.linkedEntity);
39133
+ }
39134
+ }
39135
+ }
39136
+ }
39137
+ return map;
39138
+ })(),
39139
+ children: [
39140
+ /* @__PURE__ */ jsxRuntime.jsx(
39141
+ TraitInitializer,
39142
+ {
39143
+ traits: allPageTraits,
39144
+ orbitalNames: serverUrl ? orbitalNames : void 0,
39145
+ onNavigate,
39146
+ onLocalFallback,
39147
+ persistence
39148
+ }
39149
+ ),
39150
+ /* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
39151
+ /* @__PURE__ */ jsxRuntime.jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsxRuntime.jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
39152
+ ]
39153
+ }
39154
+ ) }) });
39107
39155
  if (serverUrl) {
39108
39156
  return /* @__PURE__ */ jsxRuntime.jsx(ServerBridgeProvider, { schema, serverUrl, children: inner });
39109
39157
  }
@@ -739,6 +739,7 @@ var init_usePullToRefresh = __esm({
739
739
  });
740
740
  function EntitySchemaProvider({
741
741
  entities,
742
+ traitLinkedEntities,
742
743
  children
743
744
  }) {
744
745
  const entitiesMap = useMemo(() => {
@@ -748,11 +749,15 @@ function EntitySchemaProvider({
748
749
  }
749
750
  return map;
750
751
  }, [entities]);
752
+ const linkedMap = useMemo(() => {
753
+ return traitLinkedEntities ?? /* @__PURE__ */ new Map();
754
+ }, [traitLinkedEntities]);
751
755
  const contextValue = useMemo(
752
756
  () => ({
753
- entities: entitiesMap
757
+ entities: entitiesMap,
758
+ traitLinkedEntities: linkedMap
754
759
  }),
755
- [entitiesMap]
760
+ [entitiesMap, linkedMap]
756
761
  );
757
762
  return /* @__PURE__ */ jsx(EntitySchemaContext.Provider, { value: contextValue, children });
758
763
  }
@@ -28145,6 +28150,16 @@ function evaluateFormExpression(expr, formCtx) {
28145
28150
  const ctx = toSharedContext2(formCtx);
28146
28151
  return evaluate(expr, ctx);
28147
28152
  }
28153
+ function isOrbitalEntitySchema(value) {
28154
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28155
+ const fields = value.fields;
28156
+ return Array.isArray(fields);
28157
+ }
28158
+ function isPlainEntityRow(value) {
28159
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
28160
+ const fields = value.fields;
28161
+ return !Array.isArray(fields);
28162
+ }
28148
28163
  function getEnumOptions(field) {
28149
28164
  if (field.options && field.options.length > 0) {
28150
28165
  return [...field.options];
@@ -28290,9 +28305,12 @@ var init_Form = __esm({
28290
28305
  const { t } = useTranslate();
28291
28306
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
28292
28307
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
28293
- const normalizedInitialData = initialData ?? {};
28294
- const resolvedEntity = entity && typeof entity === "object" && !Array.isArray(entity) ? entity : void 0;
28308
+ const isSchemaEntity = isOrbitalEntitySchema(entity);
28309
+ const resolvedEntity = isSchemaEntity ? entity : void 0;
28295
28310
  const entityName = typeof entity === "string" ? entity : resolvedEntity?.name;
28311
+ const entityRowAsInitial = isPlainEntityRow(entity) ? entity : void 0;
28312
+ const callerInitial = initialData !== null && typeof initialData === "object" && !Array.isArray(initialData) ? initialData : {};
28313
+ const normalizedInitialData = entityRowAsInitial !== void 0 ? { ...entityRowAsInitial, ...callerInitial } : callerInitial;
28296
28314
  const entityDerivedFields = React115__default.useMemo(() => {
28297
28315
  if (fields && fields.length > 0) return void 0;
28298
28316
  if (!resolvedEntity) return void 0;
@@ -28329,11 +28347,10 @@ var init_Form = __esm({
28329
28347
  [formData, externalContext]
28330
28348
  );
28331
28349
  React115__default.useEffect(() => {
28332
- const data = initialData;
28333
- if (data && Object.keys(data).length > 0) {
28334
- setFormData(data);
28350
+ if (Object.keys(normalizedInitialData).length > 0) {
28351
+ setFormData(normalizedInitialData);
28335
28352
  }
28336
- }, [initialData]);
28353
+ }, [normalizedInitialData]);
28337
28354
  const processCalculations = React115__default.useCallback(
28338
28355
  (changedFieldId, newFormData) => {
28339
28356
  if (!hiddenCalculations.length) return;
@@ -37581,7 +37598,7 @@ function getToastPosition(position) {
37581
37598
  return "top-4 right-4";
37582
37599
  }
37583
37600
  }
37584
- function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root") {
37601
+ function renderPatternChildren(children, onDismiss, parentId = "root", parentPath = "root", sourceTrait) {
37585
37602
  if (!children || !Array.isArray(children) || children.length === 0) {
37586
37603
  return null;
37587
37604
  }
@@ -37608,7 +37625,11 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
37608
37625
  pattern: child.type,
37609
37626
  props: resolvedProps,
37610
37627
  priority: 0,
37611
- nodeId: child._id
37628
+ nodeId: child._id,
37629
+ // Inherit sourceTrait from the parent slot so nested patterns
37630
+ // (e.g. form-section inside a stack) can resolve entityDef via
37631
+ // the trait's linkedEntity for form-field enrichment.
37632
+ ...sourceTrait !== void 0 && { sourceTrait }
37612
37633
  };
37613
37634
  return /* @__PURE__ */ jsx(
37614
37635
  SlotContentRenderer,
@@ -37659,13 +37680,21 @@ function SlotContentRenderer({
37659
37680
  }
37660
37681
  }
37661
37682
  const schemaCtx = useEntitySchemaOptional();
37662
- const entityDef = typeof entityProp === "string" && entityProp.length > 0 && schemaCtx ? schemaCtx.entities.get(entityProp) : void 0;
37683
+ let entityDef;
37684
+ if (typeof entityProp === "string" && entityProp.length > 0 && schemaCtx) {
37685
+ entityDef = schemaCtx.entities.get(entityProp);
37686
+ } else if (schemaCtx && content.sourceTrait !== void 0) {
37687
+ const linkedEntity = schemaCtx.traitLinkedEntities.get(content.sourceTrait);
37688
+ if (linkedEntity !== void 0) {
37689
+ entityDef = schemaCtx.entities.get(linkedEntity);
37690
+ }
37691
+ }
37663
37692
  const PatternComponent = getComponentForPattern(content.pattern);
37664
37693
  if (PatternComponent) {
37665
37694
  const childrenConfig = content.props.children;
37666
37695
  const hasChildren = PATTERNS_WITH_CHILDREN.has(content.pattern) || Array.isArray(childrenConfig) && childrenConfig.length > 0;
37667
37696
  const myPath = patternPath ?? "root";
37668
- const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath) : void 0;
37697
+ const renderedChildren = hasChildren ? renderPatternChildren(childrenConfig, onDismiss, content.id, myPath, content.sourceTrait) : void 0;
37669
37698
  const { children: _childrenConfig, ...restProps } = content.props;
37670
37699
  const renderedProps = renderPatternProps(restProps, onDismiss);
37671
37700
  const finalProps = renderedProps;
@@ -39045,20 +39074,39 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
39045
39074
  if (!orbitals) return [];
39046
39075
  return orbitals.filter((o) => typeof o.name === "string").map((o) => o.name);
39047
39076
  }, [schema]);
39048
- const inner = /* @__PURE__ */ jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsx(SlotsProvider, { children: /* @__PURE__ */ jsxs(EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
39049
- /* @__PURE__ */ jsx(
39050
- TraitInitializer,
39051
- {
39052
- traits: allPageTraits,
39053
- orbitalNames: serverUrl ? orbitalNames : void 0,
39054
- onNavigate,
39055
- onLocalFallback,
39056
- persistence
39057
- }
39058
- ),
39059
- /* @__PURE__ */ jsx(SlotBridge, {}),
39060
- /* @__PURE__ */ jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
39061
- ] }) }) });
39077
+ const inner = /* @__PURE__ */ jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsx(SlotsProvider, { children: /* @__PURE__ */ jsxs(
39078
+ EntitySchemaProvider,
39079
+ {
39080
+ entities: Array.from(allEntities.values()),
39081
+ traitLinkedEntities: (() => {
39082
+ const map = /* @__PURE__ */ new Map();
39083
+ if (ir) {
39084
+ for (const page of ir.pages.values()) {
39085
+ for (const binding of page.traits) {
39086
+ if (binding.linkedEntity) {
39087
+ map.set(binding.trait.name, binding.linkedEntity);
39088
+ }
39089
+ }
39090
+ }
39091
+ }
39092
+ return map;
39093
+ })(),
39094
+ children: [
39095
+ /* @__PURE__ */ jsx(
39096
+ TraitInitializer,
39097
+ {
39098
+ traits: allPageTraits,
39099
+ orbitalNames: serverUrl ? orbitalNames : void 0,
39100
+ onNavigate,
39101
+ onLocalFallback,
39102
+ persistence
39103
+ }
39104
+ ),
39105
+ /* @__PURE__ */ jsx(SlotBridge, {}),
39106
+ /* @__PURE__ */ jsx(Box, { className: "h-full p-4", children: /* @__PURE__ */ jsx(UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
39107
+ ]
39108
+ }
39109
+ ) }) });
39062
39110
  if (serverUrl) {
39063
39111
  return /* @__PURE__ */ jsx(ServerBridgeProvider, { schema, serverUrl, children: inner });
39064
39112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "4.6.2",
3
+ "version": "4.6.4",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "main": "./dist/components/index.js",