@almadar/ui 2.9.2 → 2.9.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.
@@ -183,22 +183,50 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
183
183
  navigate: optionsRef.current?.navigate,
184
184
  notify: optionsRef.current?.notify,
185
185
  enrichPattern: (pattern) => {
186
- const patternType = pattern?.type;
187
- if (patternType && isEntityAwarePattern(patternType) && fetchedDataContext) {
188
- const patternRecord = pattern;
189
- if (typeof patternRecord.entity === "string") {
190
- const records = fetchedDataContext.getData(patternRecord.entity);
191
- if (records.length > 0) {
192
- return { type: patternType, ...patternRecord, entity: records };
186
+ const enrichNode = (node) => {
187
+ if (!node || typeof node !== "object") return node;
188
+ const rec = node;
189
+ const nodeType = rec.type;
190
+ let enriched = rec;
191
+ if (Array.isArray(rec.children)) {
192
+ const enrichedChildren = rec.children.map(enrichNode);
193
+ enriched = { ...rec, children: enrichedChildren };
194
+ }
195
+ if (nodeType && isEntityAwarePattern(nodeType) && fetchedDataContext) {
196
+ let injected = false;
197
+ if (typeof enriched.entity === "string") {
198
+ const records = fetchedDataContext.getData(enriched.entity);
199
+ if (records.length > 0) {
200
+ enriched = { ...enriched, entity: records };
201
+ injected = true;
202
+ }
203
+ } else if (!enriched.entity && linkedEntity) {
204
+ const records = fetchedDataContext.getData(linkedEntity);
205
+ if (records.length > 0) {
206
+ enriched = { ...enriched, entity: records };
207
+ injected = true;
208
+ }
193
209
  }
194
- } else if (!patternRecord.entity && linkedEntity) {
195
- const records = fetchedDataContext.getData(linkedEntity);
196
- if (records.length > 0) {
197
- return { type: patternType, ...patternRecord, entity: records };
210
+ if (injected && !enriched.fields && !enriched.columns) {
211
+ const sample = enriched.entity[0];
212
+ if (sample && typeof sample === "object") {
213
+ const keys = Object.keys(sample).filter((k) => k !== "id" && k !== "_id");
214
+ enriched = {
215
+ ...enriched,
216
+ fields: keys.map((k, i) => ({
217
+ name: k,
218
+ variant: i === 0 ? "h4" : "body"
219
+ })),
220
+ // Remove pattern-config children that components
221
+ // can't render (they expect a function or nothing)
222
+ children: void 0
223
+ };
224
+ }
198
225
  }
199
226
  }
200
- }
201
- return pattern;
227
+ return enriched;
228
+ };
229
+ return enrichNode(pattern);
202
230
  }
203
231
  });
204
232
  const bindingCtx = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "main": "./dist/components/index.js",