@object-ui/plugin-tree 13.1.0 → 14.0.0
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/CHANGELOG.md +50 -0
- package/dist/ObjectTree.d.ts.map +1 -1
- package/dist/index.js +100 -97
- package/dist/index.umd.cjs +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @object-ui/plugin-tree
|
|
2
2
|
|
|
3
|
+
## 14.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5971cc4: i18n: translate the Profile page, honor inline i18n label objects under bare
|
|
8
|
+
base-language codes, and localize managed-by badges / record quick actions.
|
|
9
|
+
|
|
10
|
+
- `pickLocalized` now upgrades a bare base language (`zh`) to any
|
|
11
|
+
region-qualified key sharing the base (`zh-CN`) — runtime language is
|
|
12
|
+
normalized to the base code while metadata authors write full BCP-47 tags,
|
|
13
|
+
so inline `{ en, 'zh-CN', ... }` label objects previously fell back to
|
|
14
|
+
English.
|
|
15
|
+
- ProfilePage (`account:profile_card` / `/system/profile`): every hardcoded
|
|
16
|
+
string — page title/subtitle, avatar Upload/Replace/Remove, Personal
|
|
17
|
+
Information card, Change/Set Password card — now goes through
|
|
18
|
+
`useObjectTranslation()` with `profile.*` keys (new namespace in all ten
|
|
19
|
+
locale bundles); the lazy-load fallback reuses `common.loading`.
|
|
20
|
+
- `ManagedByBadge` chips/tooltips (Config/System/Append-only/Identity) now
|
|
21
|
+
resolve through new `managedByBadge.*` keys with `{{provider}}`
|
|
22
|
+
interpolation.
|
|
23
|
+
- `record:quick_actions` resolves action labels via the
|
|
24
|
+
`objects.{object}._actions.{action}.label` convention plus `pickLocalized`,
|
|
25
|
+
so object action buttons (Change Password, Enable 2FA, …) localize.
|
|
26
|
+
- `record:details` / `record:related_list` / `record:alert` / `ObjectTree`
|
|
27
|
+
pass inline label objects through `pickLocalized`.
|
|
28
|
+
- Locale bundles: added `managedByBadge` namespace to all ten locales and
|
|
29
|
+
backfilled `list.inlineEditShort` / `inlineEditLabel` /
|
|
30
|
+
`recordEditingTitle` for ja/es/ko/de/fr/pt/ru/ar.
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [443360a]
|
|
33
|
+
- Updated dependencies [86c69c3]
|
|
34
|
+
- Updated dependencies [05e56ca]
|
|
35
|
+
- Updated dependencies [a44e7b6]
|
|
36
|
+
- Updated dependencies [6a74160]
|
|
37
|
+
- @object-ui/core@14.0.0
|
|
38
|
+
- @object-ui/react@14.0.0
|
|
39
|
+
- @object-ui/types@14.0.0
|
|
40
|
+
- @object-ui/components@14.0.0
|
|
41
|
+
|
|
42
|
+
## 13.2.0
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [80901aa]
|
|
47
|
+
- Updated dependencies [e492b9d]
|
|
48
|
+
- @object-ui/components@13.2.0
|
|
49
|
+
- @object-ui/react@13.2.0
|
|
50
|
+
- @object-ui/types@13.2.0
|
|
51
|
+
- @object-ui/core@13.2.0
|
|
52
|
+
|
|
3
53
|
## 13.1.0
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/dist/ObjectTree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectTree.d.ts","sourceRoot":"","sources":["../src/ObjectTree.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,kBAAkB,CAAC;AAM7D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,sEAAsE;IACtE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA6KD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"ObjectTree.d.ts","sourceRoot":"","sources":["../src/ObjectTree.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,kBAAkB,CAAC;AAM7D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,sEAAsE;IACtE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA6KD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAoQhD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useEffect as e, useMemo as t, useState as n } from "react";
|
|
2
2
|
import { ComponentRegistry as r, buildExpandFields as i, extractRecords as a } from "@object-ui/core";
|
|
3
|
-
import { useNavigationOverlay as o,
|
|
4
|
-
import { NavigationOverlay as
|
|
5
|
-
import { ChevronDown as
|
|
6
|
-
import { jsx as
|
|
3
|
+
import { useNavigationOverlay as o, useSafeFieldLabel as s, useSchemaContext as c } from "@object-ui/react";
|
|
4
|
+
import { NavigationOverlay as l, cn as u } from "@object-ui/components";
|
|
5
|
+
import { ChevronDown as d, ChevronRight as f } from "lucide-react";
|
|
6
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
7
7
|
//#region src/ObjectTree.tsx
|
|
8
|
-
function
|
|
8
|
+
function h(e) {
|
|
9
9
|
return e.data ? e.data : e.staticData ? {
|
|
10
10
|
provider: "value",
|
|
11
11
|
items: e.staticData
|
|
@@ -14,20 +14,20 @@ function m(e) {
|
|
|
14
14
|
object: e.objectName
|
|
15
15
|
} : null;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function g(e) {
|
|
18
18
|
if (typeof e == "string") return e;
|
|
19
19
|
if (e && typeof e == "object") return e.name || e.fieldName || e.field || e.key;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function _(e) {
|
|
22
22
|
let t = e.tree || e.filter?.tree || {}, n = Array.isArray(e.fields) ? e.fields : Array.isArray(t.fields) ? t.fields : [];
|
|
23
23
|
return {
|
|
24
|
-
parentField:
|
|
25
|
-
labelField:
|
|
26
|
-
fields: n.map(
|
|
24
|
+
parentField: g(e.parentField ?? t.parentField),
|
|
25
|
+
labelField: g(e.labelField ?? t.labelField ?? e.titleField) ?? "name",
|
|
26
|
+
fields: n.map(g).filter((e) => !!e),
|
|
27
27
|
defaultExpandedDepth: e.defaultExpandedDepth ?? t.defaultExpandedDepth
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function v(e, t) {
|
|
31
31
|
let n = e?.fields;
|
|
32
32
|
if (!n || typeof n != "object") return;
|
|
33
33
|
let r;
|
|
@@ -38,11 +38,11 @@ function _(e, t) {
|
|
|
38
38
|
}
|
|
39
39
|
return r;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function y(e) {
|
|
42
42
|
let t = e?.id ?? e?._id;
|
|
43
43
|
return t == null ? void 0 : String(t);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function b(e, t) {
|
|
46
46
|
if (!t) return;
|
|
47
47
|
let n = e?.[t];
|
|
48
48
|
if (n != null) {
|
|
@@ -53,10 +53,10 @@ function y(e, t) {
|
|
|
53
53
|
return String(n);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function x(e, t) {
|
|
57
57
|
let n = /* @__PURE__ */ new Map(), r = [];
|
|
58
58
|
for (let t of e) {
|
|
59
|
-
let e =
|
|
59
|
+
let e = y(t);
|
|
60
60
|
e != null && (n.set(e, {
|
|
61
61
|
id: e,
|
|
62
62
|
record: t,
|
|
@@ -66,7 +66,7 @@ function b(e, t) {
|
|
|
66
66
|
}
|
|
67
67
|
let i = [];
|
|
68
68
|
for (let e of r) {
|
|
69
|
-
let r = n.get(e), a =
|
|
69
|
+
let r = n.get(e), a = b(r.record, t), o = a == null ? void 0 : n.get(a);
|
|
70
70
|
o && o !== r ? o.children.push(r) : i.push(r);
|
|
71
71
|
}
|
|
72
72
|
let a = (e, t) => {
|
|
@@ -74,32 +74,32 @@ function b(e, t) {
|
|
|
74
74
|
};
|
|
75
75
|
return a(i, 0), i;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function S(e, t) {
|
|
78
78
|
let n = [], r = (e) => {
|
|
79
79
|
for (let i of e) n.push(i), i.children.length > 0 && t.has(i.id) && r(i.children);
|
|
80
80
|
};
|
|
81
81
|
return r(e), n;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function C(e, t) {
|
|
84
84
|
let n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
85
85
|
for (let i of e) i.children.length !== 0 && (t == null || i.depth < t) && (n.add(i.id), r(i.children));
|
|
86
86
|
};
|
|
87
87
|
return r(e), n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function w(e) {
|
|
90
90
|
return e == null ? "" : String(typeof e == "object" ? e.name ?? e.label ?? e.id ?? e._id ?? "" : e);
|
|
91
91
|
}
|
|
92
|
-
var
|
|
93
|
-
let [
|
|
92
|
+
var T = ({ schema: r, dataSource: c, className: g, onRowClick: y, ...b }) => {
|
|
93
|
+
let [T, E] = n([]), [D, O] = n(!0), [k, A] = n(null), [j, M] = n(null), N = t(() => h(r), [r]), P = Array.isArray(b.data) || Array.isArray(r.data) || N?.provider === "value";
|
|
94
94
|
e(() => {
|
|
95
95
|
let e = !1;
|
|
96
|
-
return
|
|
96
|
+
return P || (async () => {
|
|
97
97
|
try {
|
|
98
|
-
if (!
|
|
99
|
-
let t =
|
|
98
|
+
if (!c || typeof c.getObjectSchema != "function") return;
|
|
99
|
+
let t = N?.provider === "object" ? N.object : r.objectName;
|
|
100
100
|
if (!t) return;
|
|
101
|
-
let n = await
|
|
102
|
-
e ||
|
|
101
|
+
let n = await c.getObjectSchema(t);
|
|
102
|
+
e || M(n);
|
|
103
103
|
} catch (e) {
|
|
104
104
|
console.error("[ObjectTree] Failed to fetch object schema:", e);
|
|
105
105
|
}
|
|
@@ -108,140 +108,143 @@ var w = ({ schema: r, dataSource: s, className: h, onRowClick: v, ...y }) => {
|
|
|
108
108
|
};
|
|
109
109
|
}, [
|
|
110
110
|
r.objectName,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
c,
|
|
112
|
+
N,
|
|
113
|
+
P
|
|
114
114
|
]), e(() => {
|
|
115
115
|
let e = !1;
|
|
116
116
|
return (async () => {
|
|
117
117
|
try {
|
|
118
|
-
if (
|
|
119
|
-
let t = i(
|
|
118
|
+
if (O(!0), A(null), N?.provider === "object" && c && typeof c.find == "function") {
|
|
119
|
+
let t = i(j?.fields), n = await c.find(N.object, {
|
|
120
120
|
$filter: r.filter,
|
|
121
121
|
...t.length > 0 ? { $expand: t } : {}
|
|
122
122
|
});
|
|
123
|
-
e || (
|
|
123
|
+
e || (E(a(n)), O(!1));
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
-
let t =
|
|
126
|
+
let t = b.data ?? r.data;
|
|
127
127
|
if (Array.isArray(t)) {
|
|
128
|
-
e || (
|
|
128
|
+
e || (E(t), O(!1));
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
|
-
if (
|
|
132
|
-
e || (
|
|
131
|
+
if (N?.provider === "value") {
|
|
132
|
+
e || (E(N.items ?? []), O(!1));
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
e || (
|
|
135
|
+
e || (E([]), O(!1));
|
|
136
136
|
} catch (t) {
|
|
137
|
-
e || (
|
|
137
|
+
e || (A(t), O(!1));
|
|
138
138
|
}
|
|
139
139
|
})(), () => {
|
|
140
140
|
e = !0;
|
|
141
141
|
};
|
|
142
142
|
}, [
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
N,
|
|
144
|
+
c,
|
|
145
145
|
r.filter,
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
j,
|
|
147
|
+
b.data
|
|
148
148
|
]);
|
|
149
|
-
let
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
let F = t(() => _(r), [r]), I = t(() => F.parentField ?? v(j, r.objectName), [
|
|
150
|
+
F.parentField,
|
|
151
|
+
j,
|
|
152
152
|
r.objectName
|
|
153
|
-
]),
|
|
153
|
+
]), L = t(() => x(T, I), [T, I]), [R, z] = n(/* @__PURE__ */ new Set());
|
|
154
154
|
e(() => {
|
|
155
|
-
|
|
156
|
-
}, [
|
|
157
|
-
let
|
|
155
|
+
z(C(L, F.defaultExpandedDepth));
|
|
156
|
+
}, [L, F.defaultExpandedDepth]);
|
|
157
|
+
let B = (e) => z((t) => {
|
|
158
158
|
let n = new Set(t);
|
|
159
159
|
return n.has(e) ? n.delete(e) : n.add(e), n;
|
|
160
|
-
}),
|
|
160
|
+
}), V = t(() => S(L, R), [L, R]), H = s(), U = (N?.provider === "object" ? N.object : void 0) ?? r.objectName, W = (e) => {
|
|
161
|
+
let t = j?.fields?.[e]?.label || e.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
|
|
162
|
+
return U ? H.fieldLabel(U, e, t) : t;
|
|
163
|
+
}, G = o({
|
|
161
164
|
navigation: r.navigation,
|
|
162
165
|
objectName: r.objectName,
|
|
163
|
-
onRowClick:
|
|
166
|
+
onRowClick: y
|
|
164
167
|
});
|
|
165
|
-
return
|
|
166
|
-
className:
|
|
167
|
-
children: /* @__PURE__ */
|
|
168
|
-
}) :
|
|
169
|
-
className:
|
|
170
|
-
children: /* @__PURE__ */
|
|
171
|
-
}) :
|
|
172
|
-
className:
|
|
173
|
-
children: /* @__PURE__ */
|
|
174
|
-
}) : /* @__PURE__ */
|
|
175
|
-
className:
|
|
168
|
+
return k ? /* @__PURE__ */ p("div", {
|
|
169
|
+
className: u("flex items-center justify-center h-40 text-destructive", g),
|
|
170
|
+
children: /* @__PURE__ */ m("p", { children: ["Failed to load tree: ", k.message] })
|
|
171
|
+
}) : D ? /* @__PURE__ */ p("div", {
|
|
172
|
+
className: u("flex items-center justify-center h-40 text-muted-foreground", g),
|
|
173
|
+
children: /* @__PURE__ */ p("p", { children: "Loading…" })
|
|
174
|
+
}) : T.length === 0 ? /* @__PURE__ */ p("div", {
|
|
175
|
+
className: u("flex items-center justify-center h-40 text-muted-foreground", g),
|
|
176
|
+
children: /* @__PURE__ */ p("p", { children: "No records" })
|
|
177
|
+
}) : /* @__PURE__ */ m("div", {
|
|
178
|
+
className: u("w-full overflow-auto", g),
|
|
176
179
|
"data-testid": "object-tree",
|
|
177
|
-
children: [/* @__PURE__ */
|
|
180
|
+
children: [/* @__PURE__ */ m("table", {
|
|
178
181
|
className: "w-full border-collapse text-sm",
|
|
179
|
-
children: [/* @__PURE__ */
|
|
182
|
+
children: [/* @__PURE__ */ p("thead", { children: /* @__PURE__ */ m("tr", {
|
|
180
183
|
className: "border-b text-left text-muted-foreground",
|
|
181
|
-
children: [/* @__PURE__ */
|
|
184
|
+
children: [/* @__PURE__ */ p("th", {
|
|
182
185
|
className: "px-3 py-2 font-medium",
|
|
183
|
-
children:
|
|
184
|
-
}),
|
|
186
|
+
children: W(F.labelField)
|
|
187
|
+
}), F.fields.filter((e) => e !== F.labelField).map((e) => /* @__PURE__ */ p("th", {
|
|
185
188
|
className: "px-3 py-2 font-medium",
|
|
186
|
-
children:
|
|
189
|
+
children: W(e)
|
|
187
190
|
}, e))]
|
|
188
|
-
}) }), /* @__PURE__ */
|
|
189
|
-
let t = e.children.length > 0, n =
|
|
190
|
-
return /* @__PURE__ */
|
|
191
|
+
}) }), /* @__PURE__ */ p("tbody", { children: V.map((e) => {
|
|
192
|
+
let t = e.children.length > 0, n = R.has(e.id);
|
|
193
|
+
return /* @__PURE__ */ m("tr", {
|
|
191
194
|
className: "border-b hover:bg-accent/50 cursor-pointer",
|
|
192
195
|
"data-testid": "object-tree-row",
|
|
193
196
|
"data-depth": e.depth,
|
|
194
|
-
onClick: (t) =>
|
|
195
|
-
children: [/* @__PURE__ */
|
|
197
|
+
onClick: (t) => G.handleClick(e.record, t),
|
|
198
|
+
children: [/* @__PURE__ */ p("td", {
|
|
196
199
|
className: "px-3 py-2",
|
|
197
|
-
children: /* @__PURE__ */
|
|
200
|
+
children: /* @__PURE__ */ m("div", {
|
|
198
201
|
className: "flex items-center gap-1",
|
|
199
202
|
style: { paddingLeft: `${e.depth * 20}px` },
|
|
200
|
-
children: [t ? /* @__PURE__ */
|
|
203
|
+
children: [t ? /* @__PURE__ */ p("button", {
|
|
201
204
|
type: "button",
|
|
202
205
|
"aria-label": n ? "Collapse" : "Expand",
|
|
203
206
|
className: "flex h-5 w-5 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted",
|
|
204
207
|
onClick: (t) => {
|
|
205
|
-
t.stopPropagation(),
|
|
208
|
+
t.stopPropagation(), B(e.id);
|
|
206
209
|
},
|
|
207
|
-
children:
|
|
208
|
-
}) : /* @__PURE__ */
|
|
210
|
+
children: p(n ? d : f, { className: "h-4 w-4" })
|
|
211
|
+
}) : /* @__PURE__ */ p("span", { className: "inline-block h-5 w-5" }), /* @__PURE__ */ p("span", {
|
|
209
212
|
className: "truncate",
|
|
210
|
-
children:
|
|
213
|
+
children: w(e.record[F.labelField]) || "—"
|
|
211
214
|
})]
|
|
212
215
|
})
|
|
213
|
-
}),
|
|
216
|
+
}), F.fields.filter((e) => e !== F.labelField).map((t) => /* @__PURE__ */ p("td", {
|
|
214
217
|
className: "px-3 py-2 text-muted-foreground",
|
|
215
|
-
children:
|
|
218
|
+
children: w(e.record[t])
|
|
216
219
|
}, t))]
|
|
217
220
|
}, e.id);
|
|
218
221
|
}) })]
|
|
219
|
-
}),
|
|
220
|
-
...
|
|
222
|
+
}), G.isOverlay && /* @__PURE__ */ p(l, {
|
|
223
|
+
...G,
|
|
221
224
|
title: "Record Details",
|
|
222
|
-
children: (e) => /* @__PURE__ */
|
|
225
|
+
children: (e) => /* @__PURE__ */ p("div", {
|
|
223
226
|
className: "space-y-3",
|
|
224
|
-
children: Object.entries(e).map(([e, t]) => /* @__PURE__ */
|
|
227
|
+
children: Object.entries(e).map(([e, t]) => /* @__PURE__ */ m("div", {
|
|
225
228
|
className: "flex flex-col",
|
|
226
|
-
children: [/* @__PURE__ */
|
|
229
|
+
children: [/* @__PURE__ */ p("span", {
|
|
227
230
|
className: "text-xs font-medium text-muted-foreground uppercase tracking-wide",
|
|
228
231
|
children: e.replace(/_/g, " ")
|
|
229
|
-
}), /* @__PURE__ */
|
|
232
|
+
}), /* @__PURE__ */ p("span", {
|
|
230
233
|
className: "text-sm",
|
|
231
|
-
children:
|
|
234
|
+
children: w(t) || "—"
|
|
232
235
|
})]
|
|
233
236
|
}, e))
|
|
234
237
|
})
|
|
235
238
|
})]
|
|
236
239
|
});
|
|
237
|
-
},
|
|
238
|
-
let { dataSource: n } =
|
|
239
|
-
return /* @__PURE__ */
|
|
240
|
+
}, E = ({ schema: e, ...t }) => {
|
|
241
|
+
let { dataSource: n } = c() || {};
|
|
242
|
+
return /* @__PURE__ */ p(T, {
|
|
240
243
|
schema: e,
|
|
241
244
|
dataSource: n,
|
|
242
245
|
...t
|
|
243
246
|
});
|
|
244
|
-
},
|
|
247
|
+
}, D = [{
|
|
245
248
|
name: "objectName",
|
|
246
249
|
type: "string",
|
|
247
250
|
label: "Object Name",
|
|
@@ -252,16 +255,16 @@ var w = ({ schema: r, dataSource: s, className: h, onRowClick: v, ...y }) => {
|
|
|
252
255
|
label: "Tree Config",
|
|
253
256
|
description: "parentField, labelField, fields, defaultExpandedDepth"
|
|
254
257
|
}];
|
|
255
|
-
r.register("object-tree",
|
|
258
|
+
r.register("object-tree", E, {
|
|
256
259
|
namespace: "plugin-tree",
|
|
257
260
|
label: "Object Tree",
|
|
258
261
|
category: "view",
|
|
259
|
-
inputs:
|
|
260
|
-
}), r.register("tree",
|
|
262
|
+
inputs: D
|
|
263
|
+
}), r.register("tree", E, {
|
|
261
264
|
namespace: "view",
|
|
262
265
|
label: "Tree View",
|
|
263
266
|
category: "view",
|
|
264
|
-
inputs:
|
|
267
|
+
inputs: D
|
|
265
268
|
});
|
|
266
269
|
//#endregion
|
|
267
|
-
export {
|
|
270
|
+
export { T as ObjectTree, E as ObjectTreeRenderer };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/components"),require("lucide-react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/components`,`lucide-react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginTree={},e.React,e.ObjectUICore,e.ObjectUIReact,e.ObjectUIComponents,e.LucideReact,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:s(d(e)),p(t||!e||!e.__esModule?c(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function m(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function h(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`)return e.name||e.fieldName||e.field||e.key}function g(e){let t=e.tree||e.filter?.tree||{},n=Array.isArray(e.fields)?e.fields:Array.isArray(t.fields)?t.fields:[];return{parentField:h(e.parentField??t.parentField),labelField:h(e.labelField??t.labelField??e.titleField)??`name`,fields:n.map(h).filter(e=>!!e),defaultExpandedDepth:e.defaultExpandedDepth??t.defaultExpandedDepth}}function _(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){if(i?.type===`tree`)return e;let n=i?.reference||i?.reference_to||i?.referenceTo;!r&&(i?.type===`lookup`||i?.type===`master_detail`)&&n&&t&&n===t&&(r=e)}return r}function v(e){let t=e?.id??e?._id;return t==null?void 0:String(t)}function y(e,t){if(!t)return;let n=e?.[t];if(n!=null){if(typeof n==`object`){let e=n.id??n._id;return e==null?void 0:String(e)}return String(n)}}function b(e,t){let n=new Map,r=[];for(let t of e){let e=v(t);e!=null&&(n.set(e,{id:e,record:t,depth:0,children:[]}),r.push(e))}let i=[];for(let e of r){let r=n.get(e),a=y(r.record,t),o=a==null?void 0:n.get(a);o&&o!==r?o.children.push(r):i.push(r)}let a=(e,t)=>{for(let n of e)n.depth=t,a(n.children,t+1)};return a(i,0),i}function x(e,t){let n=[],r=e=>{for(let i of e)n.push(i),i.children.length>0&&t.has(i.id)&&r(i.children)};return r(e),n}function S(e,t){let n=new Set,r=e=>{for(let i of e)i.children.length!==0&&(t==null||i.depth<t)&&(n.add(i.id),r(i.children))};return r(e),n}function C(e){return e==null?``:String(typeof e==`object`?e.name??e.label??e.id??e._id??``:e)}var w=({schema:e,dataSource:s,className:c,onRowClick:l,...u})=>{let[d,f]=(0,t.useState)([]),[p,h]=(0,t.useState)(!0),[v,y]=(0,t.useState)(null),[w,T]=(0,t.useState)(null),E=(0,t.useMemo)(()=>m(e),[e]),D=Array.isArray(u.data)||Array.isArray(e.data)||E?.provider===`value`;(0,t.useEffect)(()=>{let t=!1;return D||(async()=>{try{if(!s||typeof s.getObjectSchema!=`function`)return;let n=E?.provider===`object`?E.object:e.objectName;if(!n)return;let r=await s.getObjectSchema(n);t||T(r)}catch(e){console.error(`[ObjectTree] Failed to fetch object schema:`,e)}})(),()=>{t=!0}},[e.objectName,s,E,D]),(0,t.useEffect)(()=>{let t=!1;return(async()=>{try{if(h(!0),y(null),E?.provider===`object`&&s&&typeof s.find==`function`){let r=(0,n.buildExpandFields)(w?.fields),i=await s.find(E.object,{$filter:e.filter,...r.length>0?{$expand:r}:{}});t||(f((0,n.extractRecords)(i)),h(!1));return}let r=u.data??e.data;if(Array.isArray(r)){t||(f(r),h(!1));return}if(E?.provider===`value`){t||(f(E.items??[]),h(!1));return}t||(f([]),h(!1))}catch(e){t||(y(e),h(!1))}})(),()=>{t=!0}},[E,s,e.filter,w,u.data]);let O=(0,t.useMemo)(()=>g(e),[e]),k=(0,t.useMemo)(()=>O.parentField??_(w,e.objectName),[O.parentField,w,e.objectName]),A=(0,t.useMemo)(()=>b(d,k),[d,k]),[j,M]=(0,t.useState)(new Set);(0,t.useEffect)(()=>{M(S(A,O.defaultExpandedDepth))},[A,O.defaultExpandedDepth]);let N=e=>M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),P=(0,t.useMemo)(()=>x(A,j),[A,j]),F=e=>w?.fields?.[e]?.label||e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/components"),require("lucide-react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/components`,`lucide-react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginTree={},e.React,e.ObjectUICore,e.ObjectUIReact,e.ObjectUIComponents,e.LucideReact,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:s(d(e)),p(t||!e||!e.__esModule?c(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function m(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function h(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`)return e.name||e.fieldName||e.field||e.key}function g(e){let t=e.tree||e.filter?.tree||{},n=Array.isArray(e.fields)?e.fields:Array.isArray(t.fields)?t.fields:[];return{parentField:h(e.parentField??t.parentField),labelField:h(e.labelField??t.labelField??e.titleField)??`name`,fields:n.map(h).filter(e=>!!e),defaultExpandedDepth:e.defaultExpandedDepth??t.defaultExpandedDepth}}function _(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){if(i?.type===`tree`)return e;let n=i?.reference||i?.reference_to||i?.referenceTo;!r&&(i?.type===`lookup`||i?.type===`master_detail`)&&n&&t&&n===t&&(r=e)}return r}function v(e){let t=e?.id??e?._id;return t==null?void 0:String(t)}function y(e,t){if(!t)return;let n=e?.[t];if(n!=null){if(typeof n==`object`){let e=n.id??n._id;return e==null?void 0:String(e)}return String(n)}}function b(e,t){let n=new Map,r=[];for(let t of e){let e=v(t);e!=null&&(n.set(e,{id:e,record:t,depth:0,children:[]}),r.push(e))}let i=[];for(let e of r){let r=n.get(e),a=y(r.record,t),o=a==null?void 0:n.get(a);o&&o!==r?o.children.push(r):i.push(r)}let a=(e,t)=>{for(let n of e)n.depth=t,a(n.children,t+1)};return a(i,0),i}function x(e,t){let n=[],r=e=>{for(let i of e)n.push(i),i.children.length>0&&t.has(i.id)&&r(i.children)};return r(e),n}function S(e,t){let n=new Set,r=e=>{for(let i of e)i.children.length!==0&&(t==null||i.depth<t)&&(n.add(i.id),r(i.children))};return r(e),n}function C(e){return e==null?``:String(typeof e==`object`?e.name??e.label??e.id??e._id??``:e)}var w=({schema:e,dataSource:s,className:c,onRowClick:l,...u})=>{let[d,f]=(0,t.useState)([]),[p,h]=(0,t.useState)(!0),[v,y]=(0,t.useState)(null),[w,T]=(0,t.useState)(null),E=(0,t.useMemo)(()=>m(e),[e]),D=Array.isArray(u.data)||Array.isArray(e.data)||E?.provider===`value`;(0,t.useEffect)(()=>{let t=!1;return D||(async()=>{try{if(!s||typeof s.getObjectSchema!=`function`)return;let n=E?.provider===`object`?E.object:e.objectName;if(!n)return;let r=await s.getObjectSchema(n);t||T(r)}catch(e){console.error(`[ObjectTree] Failed to fetch object schema:`,e)}})(),()=>{t=!0}},[e.objectName,s,E,D]),(0,t.useEffect)(()=>{let t=!1;return(async()=>{try{if(h(!0),y(null),E?.provider===`object`&&s&&typeof s.find==`function`){let r=(0,n.buildExpandFields)(w?.fields),i=await s.find(E.object,{$filter:e.filter,...r.length>0?{$expand:r}:{}});t||(f((0,n.extractRecords)(i)),h(!1));return}let r=u.data??e.data;if(Array.isArray(r)){t||(f(r),h(!1));return}if(E?.provider===`value`){t||(f(E.items??[]),h(!1));return}t||(f([]),h(!1))}catch(e){t||(y(e),h(!1))}})(),()=>{t=!0}},[E,s,e.filter,w,u.data]);let O=(0,t.useMemo)(()=>g(e),[e]),k=(0,t.useMemo)(()=>O.parentField??_(w,e.objectName),[O.parentField,w,e.objectName]),A=(0,t.useMemo)(()=>b(d,k),[d,k]),[j,M]=(0,t.useState)(new Set);(0,t.useEffect)(()=>{M(S(A,O.defaultExpandedDepth))},[A,O.defaultExpandedDepth]);let N=e=>M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),P=(0,t.useMemo)(()=>x(A,j),[A,j]),F=(0,r.useSafeFieldLabel)(),I=(E?.provider===`object`?E.object:void 0)??e.objectName,L=e=>{let t=w?.fields?.[e]?.label||e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase());return I?F.fieldLabel(I,e,t):t},R=(0,r.useNavigationOverlay)({navigation:e.navigation,objectName:e.objectName,onRowClick:l});return v?(0,o.jsx)(`div`,{className:(0,i.cn)(`flex items-center justify-center h-40 text-destructive`,c),children:(0,o.jsxs)(`p`,{children:[`Failed to load tree: `,v.message]})}):p?(0,o.jsx)(`div`,{className:(0,i.cn)(`flex items-center justify-center h-40 text-muted-foreground`,c),children:(0,o.jsx)(`p`,{children:`Loading…`})}):d.length===0?(0,o.jsx)(`div`,{className:(0,i.cn)(`flex items-center justify-center h-40 text-muted-foreground`,c),children:(0,o.jsx)(`p`,{children:`No records`})}):(0,o.jsxs)(`div`,{className:(0,i.cn)(`w-full overflow-auto`,c),"data-testid":`object-tree`,children:[(0,o.jsxs)(`table`,{className:`w-full border-collapse text-sm`,children:[(0,o.jsx)(`thead`,{children:(0,o.jsxs)(`tr`,{className:`border-b text-left text-muted-foreground`,children:[(0,o.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:L(O.labelField)}),O.fields.filter(e=>e!==O.labelField).map(e=>(0,o.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:L(e)},e))]})}),(0,o.jsx)(`tbody`,{children:P.map(e=>{let t=e.children.length>0,n=j.has(e.id);return(0,o.jsxs)(`tr`,{className:`border-b hover:bg-accent/50 cursor-pointer`,"data-testid":`object-tree-row`,"data-depth":e.depth,onClick:t=>R.handleClick(e.record,t),children:[(0,o.jsx)(`td`,{className:`px-3 py-2`,children:(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,style:{paddingLeft:`${e.depth*20}px`},children:[t?(0,o.jsx)(`button`,{type:`button`,"aria-label":n?`Collapse`:`Expand`,className:`flex h-5 w-5 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted`,onClick:t=>{t.stopPropagation(),N(e.id)},children:n?(0,o.jsx)(a.ChevronDown,{className:`h-4 w-4`}):(0,o.jsx)(a.ChevronRight,{className:`h-4 w-4`})}):(0,o.jsx)(`span`,{className:`inline-block h-5 w-5`}),(0,o.jsx)(`span`,{className:`truncate`,children:C(e.record[O.labelField])||`—`})]})}),O.fields.filter(e=>e!==O.labelField).map(t=>(0,o.jsx)(`td`,{className:`px-3 py-2 text-muted-foreground`,children:C(e.record[t])},t))]},e.id)})})]}),R.isOverlay&&(0,o.jsx)(i.NavigationOverlay,{...R,title:`Record Details`,children:e=>(0,o.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,o.jsxs)(`div`,{className:`flex flex-col`,children:[(0,o.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,o.jsx)(`span`,{className:`text-sm`,children:C(t)||`—`})]},e))})})]})},T=({schema:e,...t})=>{let{dataSource:n}=(0,r.useSchemaContext)()||{};return(0,o.jsx)(w,{schema:e,dataSource:n,...t})},E=[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`tree`,type:`object`,label:`Tree Config`,description:`parentField, labelField, fields, defaultExpandedDepth`}];n.ComponentRegistry.register(`object-tree`,T,{namespace:`plugin-tree`,label:`Object Tree`,category:`view`,inputs:E}),n.ComponentRegistry.register(`tree`,T,{namespace:`view`,label:`Tree View`,category:`view`,inputs:E}),e.ObjectTree=w,e.ObjectTreeRenderer=T});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-tree",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Tree / tree-grid visualization plugin for Object UI",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@objectstack/spec": "^
|
|
28
|
-
"lucide-react": "^1.
|
|
29
|
-
"@object-ui/components": "
|
|
30
|
-
"@object-ui/core": "
|
|
31
|
-
"@object-ui/react": "
|
|
32
|
-
"@object-ui/types": "
|
|
27
|
+
"@objectstack/spec": "^14.6.0",
|
|
28
|
+
"lucide-react": "^1.24.0",
|
|
29
|
+
"@object-ui/components": "14.0.0",
|
|
30
|
+
"@object-ui/core": "14.0.0",
|
|
31
|
+
"@object-ui/react": "14.0.0",
|
|
32
|
+
"@object-ui/types": "14.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@types/react-dom": "19.2.3",
|
|
41
41
|
"@vitejs/plugin-react": "^6.0.3",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
|
-
"vite": "^8.1.
|
|
43
|
+
"vite": "^8.1.4",
|
|
44
44
|
"vite-plugin-dts": "^5.0.3"
|
|
45
45
|
},
|
|
46
46
|
"keywords": [
|