@object-ui/plugin-tree 7.1.0 → 7.3.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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @object-ui/plugin-tree
2
2
 
3
+ ## 7.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @object-ui/types@7.3.0
8
+ - @object-ui/core@7.3.0
9
+ - @object-ui/react@7.3.0
10
+ - @object-ui/components@7.3.0
11
+
12
+ ## 7.2.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [d23db5c]
17
+ - @object-ui/types@7.2.0
18
+ - @object-ui/components@7.2.0
19
+ - @object-ui/react@7.2.0
20
+ - @object-ui/core@7.2.0
21
+
3
22
  ## 7.1.0
4
23
 
5
24
  ### Patch Changes
@@ -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;AA8JD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA8PhD,CAAC;AAEF,eAAe,UAAU,CAAC"}
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,CA8PhD,CAAC;AAEF,eAAe,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -15,15 +15,19 @@ function m(e) {
15
15
  } : null;
16
16
  }
17
17
  function h(e) {
18
- let t = e.tree || e.filter?.tree || {};
18
+ if (typeof e == "string") return e;
19
+ if (e && typeof e == "object") return e.name || e.fieldName || e.field || e.key;
20
+ }
21
+ function g(e) {
22
+ let t = e.tree || e.filter?.tree || {}, n = Array.isArray(e.fields) ? e.fields : Array.isArray(t.fields) ? t.fields : [];
19
23
  return {
20
- parentField: e.parentField ?? t.parentField,
21
- labelField: e.labelField ?? t.labelField ?? e.titleField ?? "name",
22
- fields: Array.isArray(e.fields) ? e.fields : Array.isArray(t.fields) ? t.fields : [],
24
+ parentField: h(e.parentField ?? t.parentField),
25
+ labelField: h(e.labelField ?? t.labelField ?? e.titleField) ?? "name",
26
+ fields: n.map(h).filter((e) => !!e),
23
27
  defaultExpandedDepth: e.defaultExpandedDepth ?? t.defaultExpandedDepth
24
28
  };
25
29
  }
26
- function g(e, t) {
30
+ function _(e, t) {
27
31
  let n = e?.fields;
28
32
  if (!n || typeof n != "object") return;
29
33
  let r;
@@ -34,11 +38,11 @@ function g(e, t) {
34
38
  }
35
39
  return r;
36
40
  }
37
- function _(e) {
41
+ function v(e) {
38
42
  let t = e?.id ?? e?._id;
39
43
  return t == null ? void 0 : String(t);
40
44
  }
41
- function v(e, t) {
45
+ function y(e, t) {
42
46
  if (!t) return;
43
47
  let n = e?.[t];
44
48
  if (n != null) {
@@ -49,10 +53,10 @@ function v(e, t) {
49
53
  return String(n);
50
54
  }
51
55
  }
52
- function y(e, t) {
56
+ function b(e, t) {
53
57
  let n = /* @__PURE__ */ new Map(), r = [];
54
58
  for (let t of e) {
55
- let e = _(t);
59
+ let e = v(t);
56
60
  e != null && (n.set(e, {
57
61
  id: e,
58
62
  record: t,
@@ -62,7 +66,7 @@ function y(e, t) {
62
66
  }
63
67
  let i = [];
64
68
  for (let e of r) {
65
- let r = n.get(e), a = v(r.record, t), o = a == null ? void 0 : n.get(a);
69
+ let r = n.get(e), a = y(r.record, t), o = a == null ? void 0 : n.get(a);
66
70
  o && o !== r ? o.children.push(r) : i.push(r);
67
71
  }
68
72
  let a = (e, t) => {
@@ -70,23 +74,23 @@ function y(e, t) {
70
74
  };
71
75
  return a(i, 0), i;
72
76
  }
73
- function b(e, t) {
77
+ function x(e, t) {
74
78
  let n = [], r = (e) => {
75
79
  for (let i of e) n.push(i), i.children.length > 0 && t.has(i.id) && r(i.children);
76
80
  };
77
81
  return r(e), n;
78
82
  }
79
- function x(e, t) {
83
+ function S(e, t) {
80
84
  let n = /* @__PURE__ */ new Set(), r = (e) => {
81
85
  for (let i of e) i.children.length !== 0 && (t == null || i.depth < t) && (n.add(i.id), r(i.children));
82
86
  };
83
87
  return r(e), n;
84
88
  }
85
- function S(e) {
89
+ function C(e) {
86
90
  return e == null ? "" : String(typeof e == "object" ? e.name ?? e.label ?? e.id ?? e._id ?? "" : e);
87
91
  }
88
- var C = ({ schema: r, dataSource: s, className: _, onRowClick: v, ...C }) => {
89
- let [w, T] = n([]), [E, D] = n(!0), [O, k] = n(null), [A, j] = n(null), M = t(() => m(r), [r]), N = Array.isArray(C.data) || Array.isArray(r.data) || M?.provider === "value";
92
+ var w = ({ schema: r, dataSource: s, className: h, onRowClick: v, ...y }) => {
93
+ let [w, T] = n([]), [E, D] = n(!0), [O, k] = n(null), [A, j] = n(null), M = t(() => m(r), [r]), N = Array.isArray(y.data) || Array.isArray(r.data) || M?.provider === "value";
90
94
  e(() => {
91
95
  let e = !1;
92
96
  return N || (async () => {
@@ -119,7 +123,7 @@ var C = ({ schema: r, dataSource: s, className: _, onRowClick: v, ...C }) => {
119
123
  e || (T(a(n)), D(!1));
120
124
  return;
121
125
  }
122
- let t = C.data ?? r.data;
126
+ let t = y.data ?? r.data;
123
127
  if (Array.isArray(t)) {
124
128
  e || (T(t), D(!1));
125
129
  return;
@@ -140,35 +144,35 @@ var C = ({ schema: r, dataSource: s, className: _, onRowClick: v, ...C }) => {
140
144
  s,
141
145
  r.filter,
142
146
  A,
143
- C.data
147
+ y.data
144
148
  ]);
145
- let P = t(() => h(r), [r]), F = t(() => P.parentField ?? g(A, r.objectName), [
149
+ let P = t(() => g(r), [r]), F = t(() => P.parentField ?? _(A, r.objectName), [
146
150
  P.parentField,
147
151
  A,
148
152
  r.objectName
149
- ]), I = t(() => y(w, F), [w, F]), [L, R] = n(/* @__PURE__ */ new Set());
153
+ ]), I = t(() => b(w, F), [w, F]), [L, R] = n(/* @__PURE__ */ new Set());
150
154
  e(() => {
151
- R(x(I, P.defaultExpandedDepth));
155
+ R(S(I, P.defaultExpandedDepth));
152
156
  }, [I, P.defaultExpandedDepth]);
153
157
  let z = (e) => R((t) => {
154
158
  let n = new Set(t);
155
159
  return n.has(e) ? n.delete(e) : n.add(e), n;
156
- }), B = t(() => b(I, L), [I, L]), V = (e) => A?.fields?.[e]?.label || e.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), H = o({
160
+ }), B = t(() => x(I, L), [I, L]), V = (e) => A?.fields?.[e]?.label || e.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), H = o({
157
161
  navigation: r.navigation,
158
162
  objectName: r.objectName,
159
163
  onRowClick: v
160
164
  });
161
165
  return O ? /* @__PURE__ */ f("div", {
162
- className: l("flex items-center justify-center h-40 text-destructive", _),
166
+ className: l("flex items-center justify-center h-40 text-destructive", h),
163
167
  children: /* @__PURE__ */ p("p", { children: ["Failed to load tree: ", O.message] })
164
168
  }) : E ? /* @__PURE__ */ f("div", {
165
- className: l("flex items-center justify-center h-40 text-muted-foreground", _),
169
+ className: l("flex items-center justify-center h-40 text-muted-foreground", h),
166
170
  children: /* @__PURE__ */ f("p", { children: "Loading…" })
167
171
  }) : w.length === 0 ? /* @__PURE__ */ f("div", {
168
- className: l("flex items-center justify-center h-40 text-muted-foreground", _),
172
+ className: l("flex items-center justify-center h-40 text-muted-foreground", h),
169
173
  children: /* @__PURE__ */ f("p", { children: "No records" })
170
174
  }) : /* @__PURE__ */ p("div", {
171
- className: l("w-full overflow-auto", _),
175
+ className: l("w-full overflow-auto", h),
172
176
  "data-testid": "object-tree",
173
177
  children: [/* @__PURE__ */ p("table", {
174
178
  className: "w-full border-collapse text-sm",
@@ -203,12 +207,12 @@ var C = ({ schema: r, dataSource: s, className: _, onRowClick: v, ...C }) => {
203
207
  children: f(n ? u : d, { className: "h-4 w-4" })
204
208
  }) : /* @__PURE__ */ f("span", { className: "inline-block h-5 w-5" }), /* @__PURE__ */ f("span", {
205
209
  className: "truncate",
206
- children: S(e.record[P.labelField]) || "—"
210
+ children: C(e.record[P.labelField]) || "—"
207
211
  })]
208
212
  })
209
213
  }), P.fields.filter((e) => e !== P.labelField).map((t) => /* @__PURE__ */ f("td", {
210
214
  className: "px-3 py-2 text-muted-foreground",
211
- children: S(e.record[t])
215
+ children: C(e.record[t])
212
216
  }, t))]
213
217
  }, e.id);
214
218
  }) })]
@@ -224,20 +228,20 @@ var C = ({ schema: r, dataSource: s, className: _, onRowClick: v, ...C }) => {
224
228
  children: e.replace(/_/g, " ")
225
229
  }), /* @__PURE__ */ f("span", {
226
230
  className: "text-sm",
227
- children: S(t) || "—"
231
+ children: C(t) || "—"
228
232
  })]
229
233
  }, e))
230
234
  })
231
235
  })]
232
236
  });
233
- }, w = ({ schema: e, ...t }) => {
237
+ }, T = ({ schema: e, ...t }) => {
234
238
  let { dataSource: n } = s() || {};
235
- return /* @__PURE__ */ f(C, {
239
+ return /* @__PURE__ */ f(w, {
236
240
  schema: e,
237
241
  dataSource: n,
238
242
  ...t
239
243
  });
240
- }, T = [{
244
+ }, E = [{
241
245
  name: "objectName",
242
246
  type: "string",
243
247
  label: "Object Name",
@@ -248,16 +252,16 @@ var C = ({ schema: r, dataSource: s, className: _, onRowClick: v, ...C }) => {
248
252
  label: "Tree Config",
249
253
  description: "parentField, labelField, fields, defaultExpandedDepth"
250
254
  }];
251
- r.register("object-tree", w, {
255
+ r.register("object-tree", T, {
252
256
  namespace: "plugin-tree",
253
257
  label: "Object Tree",
254
258
  category: "view",
255
- inputs: T
256
- }), r.register("tree", w, {
259
+ inputs: E
260
+ }), r.register("tree", T, {
257
261
  namespace: "view",
258
262
  label: "Tree View",
259
263
  category: "view",
260
- inputs: T
264
+ inputs: E
261
265
  });
262
266
  //#endregion
263
- export { C as ObjectTree, w as ObjectTreeRenderer };
267
+ export { w as ObjectTree, T as ObjectTreeRenderer };
@@ -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){let t=e.tree||e.filter?.tree||{};return{parentField:e.parentField??t.parentField,labelField:e.labelField??t.labelField??e.titleField??`name`,fields:Array.isArray(e.fields)?e.fields:Array.isArray(t.fields)?t.fields:[],defaultExpandedDepth:e.defaultExpandedDepth??t.defaultExpandedDepth}}function g(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 _(e){let t=e?.id??e?._id;return t==null?void 0:String(t)}function v(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 y(e,t){let n=new Map,r=[];for(let t of e){let e=_(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=v(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 b(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 x(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 S(e){return e==null?``:String(typeof e==`object`?e.name??e.label??e.id??e._id??``:e)}var C=({schema:e,dataSource:s,className:c,onRowClick:l,...u})=>{let[d,f]=(0,t.useState)([]),[p,_]=(0,t.useState)(!0),[v,C]=(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(_(!0),C(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)),_(!1));return}let r=u.data??e.data;if(Array.isArray(r)){t||(f(r),_(!1));return}if(E?.provider===`value`){t||(f(E.items??[]),_(!1));return}t||(f([]),_(!1))}catch(e){t||(C(e),_(!1))}})(),()=>{t=!0}},[E,s,e.filter,w,u.data]);let O=(0,t.useMemo)(()=>h(e),[e]),k=(0,t.useMemo)(()=>O.parentField??g(w,e.objectName),[O.parentField,w,e.objectName]),A=(0,t.useMemo)(()=>y(d,k),[d,k]),[j,M]=(0,t.useState)(new Set);(0,t.useEffect)(()=>{M(x(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)(()=>b(A,j),[A,j]),F=e=>w?.fields?.[e]?.label||e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),I=(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:F(O.labelField)}),O.fields.filter(e=>e!==O.labelField).map(e=>(0,o.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:F(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=>I.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:S(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:S(e.record[t])},t))]},e.id)})})]}),I.isOverlay&&(0,o.jsx)(i.NavigationOverlay,{...I,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:S(t)||`—`})]},e))})})]})},w=({schema:e,...t})=>{let{dataSource:n}=(0,r.useSchemaContext)()||{};return(0,o.jsx)(C,{schema:e,dataSource:n,...t})},T=[{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`,w,{namespace:`plugin-tree`,label:`Object Tree`,category:`view`,inputs:T}),n.ComponentRegistry.register(`tree`,w,{namespace:`view`,label:`Tree View`,category:`view`,inputs:T}),e.ObjectTree=C,e.ObjectTreeRenderer=w});
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()),I=(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:F(O.labelField)}),O.fields.filter(e=>e!==O.labelField).map(e=>(0,o.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:F(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=>I.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)})})]}),I.isOverlay&&(0,o.jsx)(i.NavigationOverlay,{...I,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": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Tree / tree-grid visualization plugin for Object UI",
@@ -26,10 +26,10 @@
26
26
  "dependencies": {
27
27
  "@objectstack/spec": "^10.0.0",
28
28
  "lucide-react": "^1.21.0",
29
- "@object-ui/components": "7.1.0",
30
- "@object-ui/core": "7.1.0",
31
- "@object-ui/react": "7.1.0",
32
- "@object-ui/types": "7.1.0"
29
+ "@object-ui/components": "7.3.0",
30
+ "@object-ui/core": "7.3.0",
31
+ "@object-ui/react": "7.3.0",
32
+ "@object-ui/types": "7.3.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^18.0.0 || ^19.0.0",