@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.
- package/dist/runtime/index.js +41 -13
- package/package.json +1 -1
package/dist/runtime/index.js
CHANGED
|
@@ -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
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
227
|
+
return enriched;
|
|
228
|
+
};
|
|
229
|
+
return enrichNode(pattern);
|
|
202
230
|
}
|
|
203
231
|
});
|
|
204
232
|
const bindingCtx = {
|