@object-ui/plugin-grid 0.3.1 → 0.5.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/dist/index.js CHANGED
@@ -1,425 +1,1148 @@
1
- import le, { useState as z, useEffect as J, useCallback as Z } from "react";
2
- import { ComponentRegistry as oe } from "@object-ui/core";
3
- import { SchemaRenderer as se } from "@object-ui/react";
4
- import { getCellRenderer as ue } from "@object-ui/fields";
5
- import { DropdownMenu as ce, DropdownMenuTrigger as fe, Button as de, DropdownMenuContent as pe, DropdownMenuItem as Q } from "@object-ui/components";
6
- import { MoreVertical as be, Edit as ge, Trash2 as ve } from "lucide-react";
7
- var I = { exports: {} }, h = {};
8
- var ee;
9
- function me() {
10
- if (ee) return h;
11
- ee = 1;
12
- var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), g = /* @__PURE__ */ Symbol.for("react.fragment");
13
- function j(_, p, b) {
14
- var y = null;
15
- if (b !== void 0 && (y = "" + b), p.key !== void 0 && (y = "" + p.key), "key" in p) {
16
- b = {};
17
- for (var T in p)
18
- T !== "key" && (b[T] = p[T]);
19
- } else b = p;
20
- return p = b.ref, {
21
- $$typeof: r,
22
- type: _,
23
- key: y,
24
- ref: p !== void 0 ? p : null,
25
- props: b
1
+ import * as H from "react";
2
+ import de, { useState as B, useEffect as Q, useCallback as ee, useRef as pe } from "react";
3
+ import { ComponentRegistry as fe } from "@object-ui/core";
4
+ import { useDataScope as be, SchemaRenderer as ve, useSchemaContext as Ee } from "@object-ui/react";
5
+ import { getCellRenderer as ye } from "@object-ui/fields";
6
+ import { DropdownMenu as xe, DropdownMenuTrigger as Se, Button as we, DropdownMenuContent as Oe, DropdownMenuItem as te } from "@object-ui/components";
7
+ import { MoreVertical as _e, Edit as je, Trash2 as Ce } from "lucide-react";
8
+ import { flushSync as Re } from "react-dom";
9
+ var G = { exports: {} }, W = {};
10
+ var ne;
11
+ function Ae() {
12
+ if (ne) return W;
13
+ ne = 1;
14
+ var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
15
+ function e(s, n, i) {
16
+ var o = null;
17
+ if (i !== void 0 && (o = "" + i), n.key !== void 0 && (o = "" + n.key), "key" in n) {
18
+ i = {};
19
+ for (var l in n)
20
+ l !== "key" && (i[l] = n[l]);
21
+ } else i = n;
22
+ return n = i.ref, {
23
+ $$typeof: t,
24
+ type: s,
25
+ key: o,
26
+ ref: n !== void 0 ? n : null,
27
+ props: i
26
28
  };
27
29
  }
28
- return h.Fragment = g, h.jsx = j, h.jsxs = j, h;
30
+ return W.Fragment = a, W.jsx = e, W.jsxs = e, W;
29
31
  }
30
- var C = {};
31
- var re;
32
- function Ee() {
33
- return re || (re = 1, process.env.NODE_ENV !== "production" && (function() {
34
- function r(e) {
35
- if (e == null) return null;
36
- if (typeof e == "function")
37
- return e.$$typeof === v ? null : e.displayName || e.name || null;
38
- if (typeof e == "string") return e;
39
- switch (e) {
40
- case w:
32
+ var L = {};
33
+ var se;
34
+ function Te() {
35
+ return se || (se = 1, process.env.NODE_ENV !== "production" && (function() {
36
+ function t(r) {
37
+ if (r == null) return null;
38
+ if (typeof r == "function")
39
+ return r.$$typeof === J ? null : r.displayName || r.name || null;
40
+ if (typeof r == "string") return r;
41
+ switch (r) {
42
+ case _:
41
43
  return "Fragment";
42
- case R:
44
+ case p:
43
45
  return "Profiler";
44
- case $:
46
+ case T:
45
47
  return "StrictMode";
46
- case U:
48
+ case V:
47
49
  return "Suspense";
48
- case W:
50
+ case z:
49
51
  return "SuspenseList";
50
- case c:
52
+ case P:
51
53
  return "Activity";
52
54
  }
53
- if (typeof e == "object")
54
- switch (typeof e.tag == "number" && console.error(
55
+ if (typeof r == "object")
56
+ switch (typeof r.tag == "number" && console.error(
55
57
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
56
- ), e.$$typeof) {
57
- case M:
58
+ ), r.$$typeof) {
59
+ case g:
58
60
  return "Portal";
59
- case L:
60
- return e.displayName || "Context";
61
- case D:
62
- return (e._context.displayName || "Context") + ".Consumer";
63
- case O:
64
- var t = e.render;
65
- return e = e.displayName, e || (e = t.displayName || t.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
66
- case q:
67
- return t = e.displayName || null, t !== null ? t : r(e.type) || "Memo";
61
+ case M:
62
+ return r.displayName || "Context";
63
+ case j:
64
+ return (r._context.displayName || "Context") + ".Consumer";
68
65
  case N:
69
- t = e._payload, e = e._init;
66
+ var u = r.render;
67
+ return r = r.displayName, r || (r = u.displayName || u.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
68
+ case Y:
69
+ return u = r.displayName || null, u !== null ? u : t(r.type) || "Memo";
70
+ case F:
71
+ u = r._payload, r = r._init;
70
72
  try {
71
- return r(e(t));
73
+ return t(r(u));
72
74
  } catch {
73
75
  }
74
76
  }
75
77
  return null;
76
78
  }
77
- function g(e) {
78
- return "" + e;
79
+ function a(r) {
80
+ return "" + r;
79
81
  }
80
- function j(e) {
82
+ function e(r) {
81
83
  try {
82
- g(e);
83
- var t = !1;
84
+ a(r);
85
+ var u = !1;
84
86
  } catch {
85
- t = !0;
87
+ u = !0;
86
88
  }
87
- if (t) {
88
- t = console;
89
- var o = t.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
90
- return o.call(
91
- t,
89
+ if (u) {
90
+ u = console;
91
+ var x = u.error, w = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
92
+ return x.call(
93
+ u,
92
94
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
93
- a
94
- ), g(e);
95
+ w
96
+ ), a(r);
95
97
  }
96
98
  }
97
- function _(e) {
98
- if (e === w) return "<>";
99
- if (typeof e == "object" && e !== null && e.$$typeof === N)
99
+ function s(r) {
100
+ if (r === _) return "<>";
101
+ if (typeof r == "object" && r !== null && r.$$typeof === F)
100
102
  return "<...>";
101
103
  try {
102
- var t = r(e);
103
- return t ? "<" + t + ">" : "<...>";
104
+ var u = t(r);
105
+ return u ? "<" + u + ">" : "<...>";
104
106
  } catch {
105
107
  return "<...>";
106
108
  }
107
109
  }
108
- function p() {
109
- var e = f.A;
110
- return e === null ? null : e.getOwner();
110
+ function n() {
111
+ var r = $.A;
112
+ return r === null ? null : r.getOwner();
111
113
  }
112
- function b() {
114
+ function i() {
113
115
  return Error("react-stack-top-frame");
114
116
  }
115
- function y(e) {
116
- if (n.call(e, "key")) {
117
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
118
- if (t && t.isReactWarning) return !1;
117
+ function o(r) {
118
+ if (U.call(r, "key")) {
119
+ var u = Object.getOwnPropertyDescriptor(r, "key").get;
120
+ if (u && u.isReactWarning) return !1;
119
121
  }
120
- return e.key !== void 0;
122
+ return r.key !== void 0;
121
123
  }
122
- function T(e, t) {
123
- function o() {
124
- F || (F = !0, console.error(
124
+ function l(r, u) {
125
+ function x() {
126
+ A || (A = !0, console.error(
125
127
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
126
- t
128
+ u
127
129
  ));
128
130
  }
129
- o.isReactWarning = !0, Object.defineProperty(e, "key", {
130
- get: o,
131
+ x.isReactWarning = !0, Object.defineProperty(r, "key", {
132
+ get: x,
131
133
  configurable: !0
132
134
  });
133
135
  }
134
- function S() {
135
- var e = r(this.type);
136
- return X[e] || (X[e] = !0, console.error(
136
+ function f() {
137
+ var r = t(this.type);
138
+ return R[r] || (R[r] = !0, console.error(
137
139
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
138
- )), e = this.props.ref, e !== void 0 ? e : null;
140
+ )), r = this.props.ref, r !== void 0 ? r : null;
139
141
  }
140
- function P(e, t, o, a, Y, V) {
141
- var i = o.ref;
142
- return e = {
143
- $$typeof: d,
144
- type: e,
145
- key: t,
146
- props: o,
147
- _owner: a
148
- }, (i !== void 0 ? i : null) !== null ? Object.defineProperty(e, "ref", {
142
+ function b(r, u, x, w, q, X) {
143
+ var O = x.ref;
144
+ return r = {
145
+ $$typeof: C,
146
+ type: r,
147
+ key: u,
148
+ props: x,
149
+ _owner: w
150
+ }, (O !== void 0 ? O : null) !== null ? Object.defineProperty(r, "ref", {
149
151
  enumerable: !1,
150
- get: S
151
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
152
+ get: f
153
+ }) : Object.defineProperty(r, "ref", { enumerable: !1, value: null }), r._store = {}, Object.defineProperty(r._store, "validated", {
152
154
  configurable: !1,
153
155
  enumerable: !1,
154
156
  writable: !0,
155
157
  value: 0
156
- }), Object.defineProperty(e, "_debugInfo", {
158
+ }), Object.defineProperty(r, "_debugInfo", {
157
159
  configurable: !1,
158
160
  enumerable: !1,
159
161
  writable: !0,
160
162
  value: null
161
- }), Object.defineProperty(e, "_debugStack", {
163
+ }), Object.defineProperty(r, "_debugStack", {
162
164
  configurable: !1,
163
165
  enumerable: !1,
164
166
  writable: !0,
165
- value: Y
166
- }), Object.defineProperty(e, "_debugTask", {
167
+ value: q
168
+ }), Object.defineProperty(r, "_debugTask", {
167
169
  configurable: !1,
168
170
  enumerable: !1,
169
171
  writable: !0,
170
- value: V
171
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
172
+ value: X
173
+ }), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
172
174
  }
173
- function A(e, t, o, a, Y, V) {
174
- var i = t.children;
175
- if (i !== void 0)
176
- if (a)
177
- if (u(i)) {
178
- for (a = 0; a < i.length; a++)
179
- m(i[a]);
180
- Object.freeze && Object.freeze(i);
175
+ function d(r, u, x, w, q, X) {
176
+ var O = u.children;
177
+ if (O !== void 0)
178
+ if (w)
179
+ if (K(O)) {
180
+ for (w = 0; w < O.length; w++)
181
+ S(O[w]);
182
+ Object.freeze && Object.freeze(O);
181
183
  } else
182
184
  console.error(
183
185
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
184
186
  );
185
- else m(i);
186
- if (n.call(t, "key")) {
187
- i = r(e);
188
- var x = Object.keys(t).filter(function(ie) {
189
- return ie !== "key";
187
+ else S(O);
188
+ if (U.call(u, "key")) {
189
+ O = t(r);
190
+ var I = Object.keys(u).filter(function(ge) {
191
+ return ge !== "key";
190
192
  });
191
- a = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", H[i + a] || (x = 0 < x.length ? "{" + x.join(": ..., ") + ": ...}" : "{}", console.error(
193
+ w = 0 < I.length ? "{key: someKey, " + I.join(": ..., ") + ": ...}" : "{key: someKey}", k[O + w] || (I = 0 < I.length ? "{" + I.join(": ..., ") + ": ...}" : "{}", console.error(
192
194
  `A props object containing a "key" prop is being spread into JSX:
193
195
  let props = %s;
194
196
  <%s {...props} />
195
197
  React keys must be passed directly to JSX without using spread:
196
198
  let props = %s;
197
199
  <%s key={someKey} {...props} />`,
198
- a,
199
- i,
200
- x,
201
- i
202
- ), H[i + a] = !0);
200
+ w,
201
+ O,
202
+ I,
203
+ O
204
+ ), k[O + w] = !0);
203
205
  }
204
- if (i = null, o !== void 0 && (j(o), i = "" + o), y(t) && (j(t.key), i = "" + t.key), "key" in t) {
205
- o = {};
206
- for (var G in t)
207
- G !== "key" && (o[G] = t[G]);
208
- } else o = t;
209
- return i && T(
210
- o,
211
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
212
- ), P(
213
- e,
214
- i,
215
- o,
216
- p(),
217
- Y,
218
- V
206
+ if (O = null, x !== void 0 && (e(x), O = "" + x), o(u) && (e(u.key), O = "" + u.key), "key" in u) {
207
+ x = {};
208
+ for (var Z in u)
209
+ Z !== "key" && (x[Z] = u[Z]);
210
+ } else x = u;
211
+ return O && l(
212
+ x,
213
+ typeof r == "function" ? r.displayName || r.name || "Unknown" : r
214
+ ), b(
215
+ r,
216
+ O,
217
+ x,
218
+ n(),
219
+ q,
220
+ X
219
221
  );
220
222
  }
221
- function m(e) {
222
- k(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === N && (e._payload.status === "fulfilled" ? k(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
223
+ function S(r) {
224
+ c(r) ? r._store && (r._store.validated = 1) : typeof r == "object" && r !== null && r.$$typeof === F && (r._payload.status === "fulfilled" ? c(r._payload.value) && r._payload.value._store && (r._payload.value._store.validated = 1) : r._store && (r._store.validated = 1));
223
225
  }
224
- function k(e) {
225
- return typeof e == "object" && e !== null && e.$$typeof === d;
226
+ function c(r) {
227
+ return typeof r == "object" && r !== null && r.$$typeof === C;
226
228
  }
227
- var s = le, d = /* @__PURE__ */ Symbol.for("react.transitional.element"), M = /* @__PURE__ */ Symbol.for("react.portal"), w = /* @__PURE__ */ Symbol.for("react.fragment"), $ = /* @__PURE__ */ Symbol.for("react.strict_mode"), R = /* @__PURE__ */ Symbol.for("react.profiler"), D = /* @__PURE__ */ Symbol.for("react.consumer"), L = /* @__PURE__ */ Symbol.for("react.context"), O = /* @__PURE__ */ Symbol.for("react.forward_ref"), U = /* @__PURE__ */ Symbol.for("react.suspense"), W = /* @__PURE__ */ Symbol.for("react.suspense_list"), q = /* @__PURE__ */ Symbol.for("react.memo"), N = /* @__PURE__ */ Symbol.for("react.lazy"), c = /* @__PURE__ */ Symbol.for("react.activity"), v = /* @__PURE__ */ Symbol.for("react.client.reference"), f = s.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, n = Object.prototype.hasOwnProperty, u = Array.isArray, E = console.createTask ? console.createTask : function() {
229
+ var m = de, C = /* @__PURE__ */ Symbol.for("react.transitional.element"), g = /* @__PURE__ */ Symbol.for("react.portal"), _ = /* @__PURE__ */ Symbol.for("react.fragment"), T = /* @__PURE__ */ Symbol.for("react.strict_mode"), p = /* @__PURE__ */ Symbol.for("react.profiler"), j = /* @__PURE__ */ Symbol.for("react.consumer"), M = /* @__PURE__ */ Symbol.for("react.context"), N = /* @__PURE__ */ Symbol.for("react.forward_ref"), V = /* @__PURE__ */ Symbol.for("react.suspense"), z = /* @__PURE__ */ Symbol.for("react.suspense_list"), Y = /* @__PURE__ */ Symbol.for("react.memo"), F = /* @__PURE__ */ Symbol.for("react.lazy"), P = /* @__PURE__ */ Symbol.for("react.activity"), J = /* @__PURE__ */ Symbol.for("react.client.reference"), $ = m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, K = Array.isArray, y = console.createTask ? console.createTask : function() {
228
230
  return null;
229
231
  };
230
- s = {
231
- react_stack_bottom_frame: function(e) {
232
- return e();
232
+ m = {
233
+ react_stack_bottom_frame: function(r) {
234
+ return r();
233
235
  }
234
236
  };
235
- var F, X = {}, B = s.react_stack_bottom_frame.bind(
236
- s,
237
- b
238
- )(), K = E(_(b)), H = {};
239
- C.Fragment = w, C.jsx = function(e, t, o) {
240
- var a = 1e4 > f.recentlyCreatedOwnerStacks++;
241
- return A(
242
- e,
243
- t,
244
- o,
237
+ var A, R = {}, E = m.react_stack_bottom_frame.bind(
238
+ m,
239
+ i
240
+ )(), h = y(s(i)), k = {};
241
+ L.Fragment = _, L.jsx = function(r, u, x) {
242
+ var w = 1e4 > $.recentlyCreatedOwnerStacks++;
243
+ return d(
244
+ r,
245
+ u,
246
+ x,
245
247
  !1,
246
- a ? Error("react-stack-top-frame") : B,
247
- a ? E(_(e)) : K
248
+ w ? Error("react-stack-top-frame") : E,
249
+ w ? y(s(r)) : h
248
250
  );
249
- }, C.jsxs = function(e, t, o) {
250
- var a = 1e4 > f.recentlyCreatedOwnerStacks++;
251
- return A(
252
- e,
253
- t,
254
- o,
251
+ }, L.jsxs = function(r, u, x) {
252
+ var w = 1e4 > $.recentlyCreatedOwnerStacks++;
253
+ return d(
254
+ r,
255
+ u,
256
+ x,
255
257
  !0,
256
- a ? Error("react-stack-top-frame") : B,
257
- a ? E(_(e)) : K
258
+ w ? Error("react-stack-top-frame") : E,
259
+ w ? y(s(r)) : h
258
260
  );
259
261
  };
260
- })()), C;
262
+ })()), L;
261
263
  }
262
- var te;
263
- function je() {
264
- return te || (te = 1, process.env.NODE_ENV === "production" ? I.exports = me() : I.exports = Ee()), I.exports;
264
+ var re;
265
+ function Me() {
266
+ return re || (re = 1, process.env.NODE_ENV === "production" ? G.exports = Ae() : G.exports = Te()), G.exports;
265
267
  }
266
- var l = je();
267
- function _e(r) {
268
- return r.data ? r.data : r.staticData ? {
268
+ var v = Me();
269
+ function ze(t) {
270
+ return t.data ? Array.isArray(t.data) ? {
271
+ provider: "value",
272
+ items: t.data
273
+ } : t.data : t.staticData ? {
269
274
  provider: "value",
270
- items: r.staticData
271
- } : r.objectName ? {
275
+ items: t.staticData
276
+ } : t.objectName ? {
272
277
  provider: "object",
273
- object: r.objectName
278
+ object: t.objectName
274
279
  } : null;
275
280
  }
276
- function ne(r) {
277
- if (!(!r || r.length === 0))
278
- return typeof r[0] == "object" && r[0] !== null, r;
281
+ function ie(t) {
282
+ if (!(!t || t.length === 0))
283
+ return typeof t[0] == "object" && t[0] !== null, t;
279
284
  }
280
- const ye = ({
281
- schema: r,
282
- dataSource: g,
283
- onEdit: j,
284
- onDelete: _,
285
- onRowSelect: p
285
+ const ke = ({
286
+ schema: t,
287
+ dataSource: a,
288
+ onEdit: e,
289
+ onDelete: s,
290
+ onRowSelect: n,
291
+ onRowClick: i,
292
+ ...o
286
293
  }) => {
287
- const [b, y] = z([]), [T, S] = z(!0), [P, A] = z(null), [m, k] = z(null), s = _e(r), d = s?.provider === "value";
288
- J(() => {
289
- d && s?.provider === "value" && (y(s.items), S(!1));
290
- }, [d, s]), J(() => {
291
- const c = async () => {
294
+ const [l, f] = B([]), [b, d] = B(!0), [S, c] = B(null), [m, C] = B(null), g = o.data, _ = be(t.bind), T = ze(t), p = de.useMemo(() => g && Array.isArray(g) ? {
295
+ provider: "value",
296
+ items: g
297
+ } : _ && Array.isArray(_) ? {
298
+ provider: "value",
299
+ items: _
300
+ } : T, [JSON.stringify(T), _, g]), j = p?.provider === "value";
301
+ Q(() => {
302
+ j && p?.provider === "value" && (f((y) => {
303
+ const A = p.items;
304
+ return JSON.stringify(y) !== JSON.stringify(A) ? A : y;
305
+ }), d(!1));
306
+ }, [j, p]), Q(() => {
307
+ const y = async () => {
292
308
  try {
293
- if (!g)
309
+ if (!a)
294
310
  throw new Error("DataSource required");
295
- const f = s?.provider === "object" ? s.object : r.objectName;
296
- if (!f)
311
+ const R = p?.provider === "object" && "object" in p ? p.object : t.objectName;
312
+ if (!R)
297
313
  throw new Error("Object name required for object provider");
298
- const n = await g.getObjectSchema(f);
299
- k(n);
300
- } catch (f) {
301
- A(f);
314
+ const E = await a.getObjectSchema(R);
315
+ C(E);
316
+ } catch (R) {
317
+ c(R);
302
318
  }
303
- }, v = ne(r.columns) || r.fields;
304
- d && v ? k({ name: r.objectName, fields: {} }) : r.objectName && !d && g && c();
305
- }, [r.objectName, r.columns, r.fields, g, d, s]);
306
- const M = Z(() => {
307
- const c = ne(r.columns);
308
- if (c)
309
- return c.length > 0 && typeof c[0] == "object" && c[0] !== null ? c.filter((n) => n?.field && typeof n.field == "string").map((n) => ({
310
- header: n.label || n.field.charAt(0).toUpperCase() + n.field.slice(1).replace(/_/g, " "),
311
- accessorKey: n.field,
312
- ...n.width && { width: n.width },
313
- ...n.align && { align: n.align },
314
- sortable: n.sortable !== !1
315
- })) : c.filter((n) => typeof n == "string" && n.trim().length > 0).map((n) => ({
316
- header: n.charAt(0).toUpperCase() + n.slice(1).replace(/_/g, " "),
317
- accessorKey: n
319
+ }, A = ie(t.columns) || t.fields;
320
+ j && A ? C({ name: t.objectName, fields: {} }) : t.objectName && !j && a && y();
321
+ }, [t.objectName, t.columns, t.fields, a, j, p]);
322
+ const M = ee(() => {
323
+ const y = ie(t.columns);
324
+ if (y) {
325
+ if (y.length > 0 && typeof y[0] == "object" && y[0] !== null) {
326
+ const E = y[0];
327
+ if ("accessorKey" in E)
328
+ return y;
329
+ if ("field" in E)
330
+ return y.filter((h) => h?.field && typeof h.field == "string").map((h) => ({
331
+ header: h.label || h.field.charAt(0).toUpperCase() + h.field.slice(1).replace(/_/g, " "),
332
+ accessorKey: h.field,
333
+ ...h.width && { width: h.width },
334
+ ...h.align && { align: h.align },
335
+ sortable: h.sortable !== !1
336
+ }));
337
+ }
338
+ return y.filter((E) => typeof E == "string" && E.trim().length > 0).map((E) => ({
339
+ header: m?.fields?.[E]?.label || E.charAt(0).toUpperCase() + E.slice(1).replace(/_/g, " "),
340
+ accessorKey: E
318
341
  }));
319
- if (d) {
320
- const n = s?.provider === "value" ? s.items : [];
321
- if (n.length > 0)
322
- return (r.fields || Object.keys(n[0])).map((E) => ({
323
- header: E.charAt(0).toUpperCase() + E.slice(1).replace(/_/g, " "),
324
- accessorKey: E
342
+ }
343
+ if (j) {
344
+ const E = p?.provider === "value" ? p.items : [];
345
+ if (E.length > 0)
346
+ return (t.fields || Object.keys(E[0])).map((k) => ({
347
+ header: k.charAt(0).toUpperCase() + k.slice(1).replace(/_/g, " "),
348
+ accessorKey: k
325
349
  }));
326
350
  }
327
351
  if (!m) return [];
328
- const v = [];
329
- return (r.fields || Object.keys(m.fields || {})).forEach((n) => {
330
- const u = m.fields?.[n];
331
- if (!u || u.permissions && u.permissions.read === !1) return;
332
- const E = ue(u.type);
333
- v.push({
334
- header: u.label || n,
335
- accessorKey: n,
336
- cell: (F) => /* @__PURE__ */ l.jsx(E, { value: F, field: u }),
337
- sortable: u.sortable !== !1
352
+ const A = [];
353
+ return (t.fields || Object.keys(m.fields || {})).forEach((E) => {
354
+ const h = m.fields?.[E];
355
+ if (!h || h.permissions && h.permissions.read === !1) return;
356
+ const k = ye(h.type);
357
+ A.push({
358
+ header: h.label || E,
359
+ accessorKey: E,
360
+ cell: (r) => /* @__PURE__ */ v.jsx(k, { value: r, field: h }),
361
+ sortable: h.sortable !== !1
338
362
  });
339
- }), v;
340
- }, [m, r.fields, r.columns, s, d]), w = Z(async () => {
341
- if (!(d || !g)) {
342
- S(!0);
363
+ }), A;
364
+ }, [m, t.fields, t.columns, p, j]), N = ee(async () => {
365
+ if (!(j || !a)) {
366
+ d(!0);
343
367
  try {
344
- const c = s?.provider === "object" ? s.object : r.objectName;
345
- if (!c)
368
+ const y = p?.provider === "object" && "object" in p ? p.object : t.objectName;
369
+ if (!y)
346
370
  throw new Error("Object name required for data fetching");
347
- const f = {
371
+ const R = {
348
372
  $select: (() => {
349
- if (r.fields) return r.fields;
350
- if (r.columns && Array.isArray(r.columns))
351
- return r.columns.map((u) => typeof u == "string" ? u : u.field);
373
+ if (t.fields) return t.fields;
374
+ if (t.columns && Array.isArray(t.columns))
375
+ return t.columns.map((h) => typeof h == "string" ? h : h.field);
352
376
  })(),
353
- $top: r.pagination?.pageSize || r.pageSize || 50
377
+ $top: t.pagination?.pageSize || t.pageSize || 50
354
378
  };
355
- r.filter && Array.isArray(r.filter) ? f.$filter = r.filter : "defaultFilters" in r && r.defaultFilters && (f.$filter = r.defaultFilters), r.sort ? typeof r.sort == "string" ? f.$orderby = r.sort : Array.isArray(r.sort) && (f.$orderby = r.sort.map((u) => `${u.field} ${u.order}`).join(", ")) : "defaultSort" in r && r.defaultSort && (f.$orderby = `${r.defaultSort.field} ${r.defaultSort.order}`);
356
- const n = await g.find(c, f);
357
- y(n.data || []);
358
- } catch (c) {
359
- A(c);
379
+ t.filter && Array.isArray(t.filter) ? R.$filter = t.filter : "defaultFilters" in t && t.defaultFilters && (R.$filter = t.defaultFilters), t.sort ? typeof t.sort == "string" ? R.$orderby = t.sort : Array.isArray(t.sort) && (R.$orderby = t.sort.map((h) => `${h.field} ${h.order}`).join(", ")) : "defaultSort" in t && t.defaultSort && (R.$orderby = `${t.defaultSort.field} ${t.defaultSort.order}`);
380
+ const E = await a.find(y, R);
381
+ f(E.data || []);
382
+ } catch (y) {
383
+ c(y);
360
384
  } finally {
361
- S(!1);
385
+ d(!1);
362
386
  }
363
387
  }
364
- }, [r, g, d, s]);
365
- if (J(() => {
366
- (m || d) && w();
367
- }, [m, d, w]), P)
368
- return /* @__PURE__ */ l.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
369
- /* @__PURE__ */ l.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading grid" }),
370
- /* @__PURE__ */ l.jsx("p", { className: "text-red-600 text-sm mt-1", children: P.message })
388
+ }, [t, a, j, p]);
389
+ if (Q(() => {
390
+ (m || j) && N();
391
+ }, [m, j, N]), S)
392
+ return /* @__PURE__ */ v.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
393
+ /* @__PURE__ */ v.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading grid" }),
394
+ /* @__PURE__ */ v.jsx("p", { className: "text-red-600 text-sm mt-1", children: S.message })
371
395
  ] });
372
- if (T && b.length === 0)
373
- return /* @__PURE__ */ l.jsxs("div", { className: "p-8 text-center", children: [
374
- /* @__PURE__ */ l.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
375
- /* @__PURE__ */ l.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading grid..." })
396
+ if (b && l.length === 0)
397
+ return /* @__PURE__ */ v.jsxs("div", { className: "p-8 text-center", children: [
398
+ /* @__PURE__ */ v.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
399
+ /* @__PURE__ */ v.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading grid..." })
376
400
  ] });
377
- const $ = M(), R = "operations" in r ? r.operations : void 0, D = R && (R.update || R.delete), L = D ? [
378
- ...$,
401
+ const V = M(), z = "operations" in t ? t.operations : void 0, Y = z && (z.update || z.delete), F = Y ? [
402
+ ...V,
379
403
  {
380
404
  header: "Actions",
381
405
  accessorKey: "_actions",
382
- cell: (c, v) => /* @__PURE__ */ l.jsxs(ce, { children: [
383
- /* @__PURE__ */ l.jsx(fe, { asChild: !0, children: /* @__PURE__ */ l.jsxs(de, { variant: "ghost", size: "icon", className: "h-8 w-8", children: [
384
- /* @__PURE__ */ l.jsx(be, { className: "h-4 w-4" }),
385
- /* @__PURE__ */ l.jsx("span", { className: "sr-only", children: "Open menu" })
406
+ cell: (y, A) => /* @__PURE__ */ v.jsxs(xe, { children: [
407
+ /* @__PURE__ */ v.jsx(Se, { asChild: !0, children: /* @__PURE__ */ v.jsxs(we, { variant: "ghost", size: "icon", className: "h-8 w-8", children: [
408
+ /* @__PURE__ */ v.jsx(_e, { className: "h-4 w-4" }),
409
+ /* @__PURE__ */ v.jsx("span", { className: "sr-only", children: "Open menu" })
386
410
  ] }) }),
387
- /* @__PURE__ */ l.jsxs(pe, { align: "end", children: [
388
- R?.update && j && /* @__PURE__ */ l.jsxs(Q, { onClick: () => j(v), children: [
389
- /* @__PURE__ */ l.jsx(ge, { className: "mr-2 h-4 w-4" }),
411
+ /* @__PURE__ */ v.jsxs(Oe, { align: "end", children: [
412
+ z?.update && e && /* @__PURE__ */ v.jsxs(te, { onClick: () => e(A), children: [
413
+ /* @__PURE__ */ v.jsx(je, { className: "mr-2 h-4 w-4" }),
390
414
  "Edit"
391
415
  ] }),
392
- R?.delete && _ && /* @__PURE__ */ l.jsxs(Q, { variant: "destructive", onClick: () => _(v), children: [
393
- /* @__PURE__ */ l.jsx(ve, { className: "mr-2 h-4 w-4" }),
416
+ z?.delete && s && /* @__PURE__ */ v.jsxs(te, { onClick: () => s(A), children: [
417
+ /* @__PURE__ */ v.jsx(Ce, { className: "mr-2 h-4 w-4" }),
394
418
  "Delete"
395
419
  ] })
396
420
  ] })
397
421
  ] }),
398
422
  sortable: !1
399
423
  }
400
- ] : $;
401
- let O = !1;
402
- r.selection?.type ? O = r.selection.type === "none" ? !1 : r.selection.type : r.selectable !== void 0 && (O = r.selectable);
403
- const U = r.pagination !== void 0 ? !0 : r.showPagination !== void 0 ? r.showPagination : !0, W = r.pagination?.pageSize || r.pageSize || 10, q = r.searchableFields !== void 0 ? r.searchableFields.length > 0 : r.showSearch !== void 0 ? r.showSearch : !0, N = {
424
+ ] : V;
425
+ let P = !1;
426
+ t.selection?.type ? P = t.selection.type === "none" ? !1 : t.selection.type : t.selectable !== void 0 && (P = t.selectable);
427
+ const J = t.pagination !== void 0 ? !0 : t.showPagination !== void 0 ? t.showPagination : !0, $ = t.pagination?.pageSize || t.pageSize || 10, U = t.searchableFields !== void 0 ? t.searchableFields.length > 0 : t.showSearch !== void 0 ? t.showSearch : !0, K = {
404
428
  type: "data-table",
405
- caption: r.label || r.title,
406
- columns: L,
407
- data: b,
408
- pagination: U,
409
- pageSize: W,
410
- searchable: q,
411
- selectable: O,
429
+ caption: t.label || t.title,
430
+ columns: F,
431
+ data: l,
432
+ pagination: J,
433
+ pageSize: $,
434
+ searchable: U,
435
+ selectable: P,
412
436
  sortable: !0,
413
- exportable: R?.export,
414
- rowActions: D,
415
- resizableColumns: r.resizable ?? r.resizableColumns ?? !0,
416
- className: r.className,
417
- onSelectionChange: p
437
+ exportable: z?.export,
438
+ rowActions: Y,
439
+ resizableColumns: t.resizable ?? t.resizableColumns ?? !0,
440
+ reorderableColumns: t.reorderableColumns ?? !1,
441
+ className: t.className,
442
+ onSelectionChange: n,
443
+ onRowClick: i
444
+ };
445
+ return /* @__PURE__ */ v.jsx(ve, { schema: K });
446
+ };
447
+ function D(t, a, e) {
448
+ let s = e.initialDeps ?? [], n, i = !0;
449
+ function o() {
450
+ var l, f, b;
451
+ let d;
452
+ e.key && ((l = e.debug) != null && l.call(e)) && (d = Date.now());
453
+ const S = t();
454
+ if (!(S.length !== s.length || S.some((C, g) => s[g] !== C)))
455
+ return n;
456
+ s = S;
457
+ let m;
458
+ if (e.key && ((f = e.debug) != null && f.call(e)) && (m = Date.now()), n = a(...S), e.key && ((b = e.debug) != null && b.call(e))) {
459
+ const C = Math.round((Date.now() - d) * 100) / 100, g = Math.round((Date.now() - m) * 100) / 100, _ = g / 16, T = (p, j) => {
460
+ for (p = String(p); p.length < j; )
461
+ p = " " + p;
462
+ return p;
463
+ };
464
+ console.info(
465
+ `%c⏱ ${T(g, 5)} /${T(C, 5)} ms`,
466
+ `
467
+ font-size: .6rem;
468
+ font-weight: bold;
469
+ color: hsl(${Math.max(
470
+ 0,
471
+ Math.min(120 - 120 * _, 120)
472
+ )}deg 100% 31%);`,
473
+ e?.key
474
+ );
475
+ }
476
+ return e?.onChange && !(i && e.skipInitialOnChange) && e.onChange(n), i = !1, n;
477
+ }
478
+ return o.updateDeps = (l) => {
479
+ s = l;
480
+ }, o;
481
+ }
482
+ function oe(t, a) {
483
+ if (t === void 0)
484
+ throw new Error("Unexpected undefined");
485
+ return t;
486
+ }
487
+ const Ne = (t, a) => Math.abs(t - a) < 1.01, Ie = (t, a, e) => {
488
+ let s;
489
+ return function(...n) {
490
+ t.clearTimeout(s), s = t.setTimeout(() => a.apply(this, n), e);
491
+ };
492
+ }, le = (t) => {
493
+ const { offsetWidth: a, offsetHeight: e } = t;
494
+ return { width: a, height: e };
495
+ }, De = (t) => t, Fe = (t) => {
496
+ const a = Math.max(t.startIndex - t.overscan, 0), e = Math.min(t.endIndex + t.overscan, t.count - 1), s = [];
497
+ for (let n = a; n <= e; n++)
498
+ s.push(n);
499
+ return s;
500
+ }, Pe = (t, a) => {
501
+ const e = t.scrollElement;
502
+ if (!e)
503
+ return;
504
+ const s = t.targetWindow;
505
+ if (!s)
506
+ return;
507
+ const n = (o) => {
508
+ const { width: l, height: f } = o;
509
+ a({ width: Math.round(l), height: Math.round(f) });
510
+ };
511
+ if (n(le(e)), !s.ResizeObserver)
512
+ return () => {
513
+ };
514
+ const i = new s.ResizeObserver((o) => {
515
+ const l = () => {
516
+ const f = o[0];
517
+ if (f?.borderBoxSize) {
518
+ const b = f.borderBoxSize[0];
519
+ if (b) {
520
+ n({ width: b.inlineSize, height: b.blockSize });
521
+ return;
522
+ }
523
+ }
524
+ n(le(e));
525
+ };
526
+ t.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(l) : l();
527
+ });
528
+ return i.observe(e, { box: "border-box" }), () => {
529
+ i.unobserve(e);
530
+ };
531
+ }, ae = {
532
+ passive: !0
533
+ }, ce = typeof window > "u" ? !0 : "onscrollend" in window, $e = (t, a) => {
534
+ const e = t.scrollElement;
535
+ if (!e)
536
+ return;
537
+ const s = t.targetWindow;
538
+ if (!s)
539
+ return;
540
+ let n = 0;
541
+ const i = t.options.useScrollendEvent && ce ? () => {
542
+ } : Ie(
543
+ s,
544
+ () => {
545
+ a(n, !1);
546
+ },
547
+ t.options.isScrollingResetDelay
548
+ ), o = (d) => () => {
549
+ const { horizontal: S, isRtl: c } = t.options;
550
+ n = S ? e.scrollLeft * (c && -1 || 1) : e.scrollTop, i(), a(n, d);
551
+ }, l = o(!0), f = o(!1);
552
+ e.addEventListener("scroll", l, ae);
553
+ const b = t.options.useScrollendEvent && ce;
554
+ return b && e.addEventListener("scrollend", f, ae), () => {
555
+ e.removeEventListener("scroll", l), b && e.removeEventListener("scrollend", f);
418
556
  };
419
- return /* @__PURE__ */ l.jsx(se, { schema: N });
420
- }, ae = ({ schema: r }) => /* @__PURE__ */ l.jsx(ye, { schema: r, dataSource: null });
421
- oe.register("object-grid", ae);
422
- oe.register("grid", ae);
557
+ }, We = (t, a, e) => {
558
+ if (a?.borderBoxSize) {
559
+ const s = a.borderBoxSize[0];
560
+ if (s)
561
+ return Math.round(
562
+ s[e.options.horizontal ? "inlineSize" : "blockSize"]
563
+ );
564
+ }
565
+ return t[e.options.horizontal ? "offsetWidth" : "offsetHeight"];
566
+ }, Le = (t, {
567
+ adjustments: a = 0,
568
+ behavior: e
569
+ }, s) => {
570
+ var n, i;
571
+ const o = t + a;
572
+ (i = (n = s.scrollElement) == null ? void 0 : n.scrollTo) == null || i.call(n, {
573
+ [s.options.horizontal ? "left" : "top"]: o,
574
+ behavior: e
575
+ });
576
+ };
577
+ class Ve {
578
+ constructor(a) {
579
+ this.unsubs = [], this.scrollElement = null, this.targetWindow = null, this.isScrolling = !1, this.currentScrollToIndex = null, this.measurementsCache = [], this.itemSizeCache = /* @__PURE__ */ new Map(), this.laneAssignments = /* @__PURE__ */ new Map(), this.pendingMeasuredCacheIndexes = [], this.prevLanes = void 0, this.lanesChangedFlag = !1, this.lanesSettling = !1, this.scrollRect = null, this.scrollOffset = null, this.scrollDirection = null, this.scrollAdjustments = 0, this.elementsCache = /* @__PURE__ */ new Map(), this.observer = /* @__PURE__ */ (() => {
580
+ let e = null;
581
+ const s = () => e || (!this.targetWindow || !this.targetWindow.ResizeObserver ? null : e = new this.targetWindow.ResizeObserver((n) => {
582
+ n.forEach((i) => {
583
+ const o = () => {
584
+ this._measureElement(i.target, i);
585
+ };
586
+ this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(o) : o();
587
+ });
588
+ }));
589
+ return {
590
+ disconnect: () => {
591
+ var n;
592
+ (n = s()) == null || n.disconnect(), e = null;
593
+ },
594
+ observe: (n) => {
595
+ var i;
596
+ return (i = s()) == null ? void 0 : i.observe(n, { box: "border-box" });
597
+ },
598
+ unobserve: (n) => {
599
+ var i;
600
+ return (i = s()) == null ? void 0 : i.unobserve(n);
601
+ }
602
+ };
603
+ })(), this.range = null, this.setOptions = (e) => {
604
+ Object.entries(e).forEach(([s, n]) => {
605
+ typeof n > "u" && delete e[s];
606
+ }), this.options = {
607
+ debug: !1,
608
+ initialOffset: 0,
609
+ overscan: 1,
610
+ paddingStart: 0,
611
+ paddingEnd: 0,
612
+ scrollPaddingStart: 0,
613
+ scrollPaddingEnd: 0,
614
+ horizontal: !1,
615
+ getItemKey: De,
616
+ rangeExtractor: Fe,
617
+ onChange: () => {
618
+ },
619
+ measureElement: We,
620
+ initialRect: { width: 0, height: 0 },
621
+ scrollMargin: 0,
622
+ gap: 0,
623
+ indexAttribute: "data-index",
624
+ initialMeasurementsCache: [],
625
+ lanes: 1,
626
+ isScrollingResetDelay: 150,
627
+ enabled: !0,
628
+ isRtl: !1,
629
+ useScrollendEvent: !1,
630
+ useAnimationFrameWithResizeObserver: !1,
631
+ ...e
632
+ };
633
+ }, this.notify = (e) => {
634
+ var s, n;
635
+ (n = (s = this.options).onChange) == null || n.call(s, this, e);
636
+ }, this.maybeNotify = D(
637
+ () => (this.calculateRange(), [
638
+ this.isScrolling,
639
+ this.range ? this.range.startIndex : null,
640
+ this.range ? this.range.endIndex : null
641
+ ]),
642
+ (e) => {
643
+ this.notify(e);
644
+ },
645
+ {
646
+ key: process.env.NODE_ENV !== "production" && "maybeNotify",
647
+ debug: () => this.options.debug,
648
+ initialDeps: [
649
+ this.isScrolling,
650
+ this.range ? this.range.startIndex : null,
651
+ this.range ? this.range.endIndex : null
652
+ ]
653
+ }
654
+ ), this.cleanup = () => {
655
+ this.unsubs.filter(Boolean).forEach((e) => e()), this.unsubs = [], this.observer.disconnect(), this.scrollElement = null, this.targetWindow = null;
656
+ }, this._didMount = () => () => {
657
+ this.cleanup();
658
+ }, this._willUpdate = () => {
659
+ var e;
660
+ const s = this.options.enabled ? this.options.getScrollElement() : null;
661
+ if (this.scrollElement !== s) {
662
+ if (this.cleanup(), !s) {
663
+ this.maybeNotify();
664
+ return;
665
+ }
666
+ this.scrollElement = s, this.scrollElement && "ownerDocument" in this.scrollElement ? this.targetWindow = this.scrollElement.ownerDocument.defaultView : this.targetWindow = ((e = this.scrollElement) == null ? void 0 : e.window) ?? null, this.elementsCache.forEach((n) => {
667
+ this.observer.observe(n);
668
+ }), this.unsubs.push(
669
+ this.options.observeElementRect(this, (n) => {
670
+ this.scrollRect = n, this.maybeNotify();
671
+ })
672
+ ), this.unsubs.push(
673
+ this.options.observeElementOffset(this, (n, i) => {
674
+ this.scrollAdjustments = 0, this.scrollDirection = i ? this.getScrollOffset() < n ? "forward" : "backward" : null, this.scrollOffset = n, this.isScrolling = i, this.maybeNotify();
675
+ })
676
+ ), this._scrollToOffset(this.getScrollOffset(), {
677
+ adjustments: void 0,
678
+ behavior: void 0
679
+ });
680
+ }
681
+ }, this.getSize = () => this.options.enabled ? (this.scrollRect = this.scrollRect ?? this.options.initialRect, this.scrollRect[this.options.horizontal ? "width" : "height"]) : (this.scrollRect = null, 0), this.getScrollOffset = () => this.options.enabled ? (this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset == "function" ? this.options.initialOffset() : this.options.initialOffset), this.scrollOffset) : (this.scrollOffset = null, 0), this.getFurthestMeasurement = (e, s) => {
682
+ const n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
683
+ for (let o = s - 1; o >= 0; o--) {
684
+ const l = e[o];
685
+ if (n.has(l.lane))
686
+ continue;
687
+ const f = i.get(
688
+ l.lane
689
+ );
690
+ if (f == null || l.end > f.end ? i.set(l.lane, l) : l.end < f.end && n.set(l.lane, !0), n.size === this.options.lanes)
691
+ break;
692
+ }
693
+ return i.size === this.options.lanes ? Array.from(i.values()).sort((o, l) => o.end === l.end ? o.index - l.index : o.end - l.end)[0] : void 0;
694
+ }, this.getMeasurementOptions = D(
695
+ () => [
696
+ this.options.count,
697
+ this.options.paddingStart,
698
+ this.options.scrollMargin,
699
+ this.options.getItemKey,
700
+ this.options.enabled,
701
+ this.options.lanes
702
+ ],
703
+ (e, s, n, i, o, l) => (this.prevLanes !== void 0 && this.prevLanes !== l && (this.lanesChangedFlag = !0), this.prevLanes = l, this.pendingMeasuredCacheIndexes = [], {
704
+ count: e,
705
+ paddingStart: s,
706
+ scrollMargin: n,
707
+ getItemKey: i,
708
+ enabled: o,
709
+ lanes: l
710
+ }),
711
+ {
712
+ key: !1
713
+ }
714
+ ), this.getMeasurements = D(
715
+ () => [this.getMeasurementOptions(), this.itemSizeCache],
716
+ ({ count: e, paddingStart: s, scrollMargin: n, getItemKey: i, enabled: o, lanes: l }, f) => {
717
+ if (!o)
718
+ return this.measurementsCache = [], this.itemSizeCache.clear(), this.laneAssignments.clear(), [];
719
+ if (this.laneAssignments.size > e)
720
+ for (const c of this.laneAssignments.keys())
721
+ c >= e && this.laneAssignments.delete(c);
722
+ this.lanesChangedFlag && (this.lanesChangedFlag = !1, this.lanesSettling = !0, this.measurementsCache = [], this.itemSizeCache.clear(), this.laneAssignments.clear(), this.pendingMeasuredCacheIndexes = []), this.measurementsCache.length === 0 && !this.lanesSettling && (this.measurementsCache = this.options.initialMeasurementsCache, this.measurementsCache.forEach((c) => {
723
+ this.itemSizeCache.set(c.key, c.size);
724
+ }));
725
+ const b = this.lanesSettling ? 0 : this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
726
+ this.pendingMeasuredCacheIndexes = [], this.lanesSettling && this.measurementsCache.length === e && (this.lanesSettling = !1);
727
+ const d = this.measurementsCache.slice(0, b), S = new Array(l).fill(
728
+ void 0
729
+ );
730
+ for (let c = 0; c < b; c++) {
731
+ const m = d[c];
732
+ m && (S[m.lane] = c);
733
+ }
734
+ for (let c = b; c < e; c++) {
735
+ const m = i(c), C = this.laneAssignments.get(c);
736
+ let g, _;
737
+ if (C !== void 0 && this.options.lanes > 1) {
738
+ g = C;
739
+ const M = S[g], N = M !== void 0 ? d[M] : void 0;
740
+ _ = N ? N.end + this.options.gap : s + n;
741
+ } else {
742
+ const M = this.options.lanes === 1 ? d[c - 1] : this.getFurthestMeasurement(d, c);
743
+ _ = M ? M.end + this.options.gap : s + n, g = M ? M.lane : c % this.options.lanes, this.options.lanes > 1 && this.laneAssignments.set(c, g);
744
+ }
745
+ const T = f.get(m), p = typeof T == "number" ? T : this.options.estimateSize(c), j = _ + p;
746
+ d[c] = {
747
+ index: c,
748
+ start: _,
749
+ size: p,
750
+ end: j,
751
+ key: m,
752
+ lane: g
753
+ }, S[g] = c;
754
+ }
755
+ return this.measurementsCache = d, d;
756
+ },
757
+ {
758
+ key: process.env.NODE_ENV !== "production" && "getMeasurements",
759
+ debug: () => this.options.debug
760
+ }
761
+ ), this.calculateRange = D(
762
+ () => [
763
+ this.getMeasurements(),
764
+ this.getSize(),
765
+ this.getScrollOffset(),
766
+ this.options.lanes
767
+ ],
768
+ (e, s, n, i) => this.range = e.length > 0 && s > 0 ? Ye({
769
+ measurements: e,
770
+ outerSize: s,
771
+ scrollOffset: n,
772
+ lanes: i
773
+ }) : null,
774
+ {
775
+ key: process.env.NODE_ENV !== "production" && "calculateRange",
776
+ debug: () => this.options.debug
777
+ }
778
+ ), this.getVirtualIndexes = D(
779
+ () => {
780
+ let e = null, s = null;
781
+ const n = this.calculateRange();
782
+ return n && (e = n.startIndex, s = n.endIndex), this.maybeNotify.updateDeps([this.isScrolling, e, s]), [
783
+ this.options.rangeExtractor,
784
+ this.options.overscan,
785
+ this.options.count,
786
+ e,
787
+ s
788
+ ];
789
+ },
790
+ (e, s, n, i, o) => i === null || o === null ? [] : e({
791
+ startIndex: i,
792
+ endIndex: o,
793
+ overscan: s,
794
+ count: n
795
+ }),
796
+ {
797
+ key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
798
+ debug: () => this.options.debug
799
+ }
800
+ ), this.indexFromElement = (e) => {
801
+ const s = this.options.indexAttribute, n = e.getAttribute(s);
802
+ return n ? parseInt(n, 10) : (console.warn(
803
+ `Missing attribute name '${s}={index}' on measured element.`
804
+ ), -1);
805
+ }, this._measureElement = (e, s) => {
806
+ const n = this.indexFromElement(e), i = this.measurementsCache[n];
807
+ if (!i)
808
+ return;
809
+ const o = i.key, l = this.elementsCache.get(o);
810
+ l !== e && (l && this.observer.unobserve(l), this.observer.observe(e), this.elementsCache.set(o, e)), e.isConnected && this.resizeItem(n, this.options.measureElement(e, s, this));
811
+ }, this.resizeItem = (e, s) => {
812
+ const n = this.measurementsCache[e];
813
+ if (!n)
814
+ return;
815
+ const i = this.itemSizeCache.get(n.key) ?? n.size, o = s - i;
816
+ o !== 0 && ((this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(n, o, this) : n.start < this.getScrollOffset() + this.scrollAdjustments) && (process.env.NODE_ENV !== "production" && this.options.debug && console.info("correction", o), this._scrollToOffset(this.getScrollOffset(), {
817
+ adjustments: this.scrollAdjustments += o,
818
+ behavior: void 0
819
+ })), this.pendingMeasuredCacheIndexes.push(n.index), this.itemSizeCache = new Map(this.itemSizeCache.set(n.key, s)), this.notify(!1));
820
+ }, this.measureElement = (e) => {
821
+ if (!e) {
822
+ this.elementsCache.forEach((s, n) => {
823
+ s.isConnected || (this.observer.unobserve(s), this.elementsCache.delete(n));
824
+ });
825
+ return;
826
+ }
827
+ this._measureElement(e, void 0);
828
+ }, this.getVirtualItems = D(
829
+ () => [this.getVirtualIndexes(), this.getMeasurements()],
830
+ (e, s) => {
831
+ const n = [];
832
+ for (let i = 0, o = e.length; i < o; i++) {
833
+ const l = e[i], f = s[l];
834
+ n.push(f);
835
+ }
836
+ return n;
837
+ },
838
+ {
839
+ key: process.env.NODE_ENV !== "production" && "getVirtualItems",
840
+ debug: () => this.options.debug
841
+ }
842
+ ), this.getVirtualItemForOffset = (e) => {
843
+ const s = this.getMeasurements();
844
+ if (s.length !== 0)
845
+ return oe(
846
+ s[he(
847
+ 0,
848
+ s.length - 1,
849
+ (n) => oe(s[n]).start,
850
+ e
851
+ )]
852
+ );
853
+ }, this.getMaxScrollOffset = () => {
854
+ if (!this.scrollElement) return 0;
855
+ if ("scrollHeight" in this.scrollElement)
856
+ return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
857
+ {
858
+ const e = this.scrollElement.document.documentElement;
859
+ return this.options.horizontal ? e.scrollWidth - this.scrollElement.innerWidth : e.scrollHeight - this.scrollElement.innerHeight;
860
+ }
861
+ }, this.getOffsetForAlignment = (e, s, n = 0) => {
862
+ if (!this.scrollElement) return 0;
863
+ const i = this.getSize(), o = this.getScrollOffset();
864
+ s === "auto" && (s = e >= o + i ? "end" : "start"), s === "center" ? e += (n - i) / 2 : s === "end" && (e -= i);
865
+ const l = this.getMaxScrollOffset();
866
+ return Math.max(Math.min(l, e), 0);
867
+ }, this.getOffsetForIndex = (e, s = "auto") => {
868
+ e = Math.max(0, Math.min(e, this.options.count - 1));
869
+ const n = this.measurementsCache[e];
870
+ if (!n)
871
+ return;
872
+ const i = this.getSize(), o = this.getScrollOffset();
873
+ if (s === "auto")
874
+ if (n.end >= o + i - this.options.scrollPaddingEnd)
875
+ s = "end";
876
+ else if (n.start <= o + this.options.scrollPaddingStart)
877
+ s = "start";
878
+ else
879
+ return [o, s];
880
+ if (s === "end" && e === this.options.count - 1)
881
+ return [this.getMaxScrollOffset(), s];
882
+ const l = s === "end" ? n.end + this.options.scrollPaddingEnd : n.start - this.options.scrollPaddingStart;
883
+ return [
884
+ this.getOffsetForAlignment(l, s, n.size),
885
+ s
886
+ ];
887
+ }, this.isDynamicMode = () => this.elementsCache.size > 0, this.scrollToOffset = (e, { align: s = "start", behavior: n } = {}) => {
888
+ n === "smooth" && this.isDynamicMode() && console.warn(
889
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
890
+ ), this._scrollToOffset(this.getOffsetForAlignment(e, s), {
891
+ adjustments: void 0,
892
+ behavior: n
893
+ });
894
+ }, this.scrollToIndex = (e, { align: s = "auto", behavior: n } = {}) => {
895
+ n === "smooth" && this.isDynamicMode() && console.warn(
896
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
897
+ ), e = Math.max(0, Math.min(e, this.options.count - 1)), this.currentScrollToIndex = e;
898
+ let i = 0;
899
+ const o = 10, l = (b) => {
900
+ if (!this.targetWindow) return;
901
+ const d = this.getOffsetForIndex(e, b);
902
+ if (!d) {
903
+ console.warn("Failed to get offset for index:", e);
904
+ return;
905
+ }
906
+ const [S, c] = d;
907
+ this._scrollToOffset(S, { adjustments: void 0, behavior: n }), this.targetWindow.requestAnimationFrame(() => {
908
+ const m = () => {
909
+ if (this.currentScrollToIndex !== e) return;
910
+ const C = this.getScrollOffset(), g = this.getOffsetForIndex(e, c);
911
+ if (!g) {
912
+ console.warn("Failed to get offset for index:", e);
913
+ return;
914
+ }
915
+ Ne(g[0], C) || f(c);
916
+ };
917
+ this.isDynamicMode() ? this.targetWindow.requestAnimationFrame(m) : m();
918
+ });
919
+ }, f = (b) => {
920
+ this.targetWindow && this.currentScrollToIndex === e && (i++, i < o ? (process.env.NODE_ENV !== "production" && this.options.debug && console.info("Schedule retry", i, o), this.targetWindow.requestAnimationFrame(() => l(b))) : console.warn(
921
+ `Failed to scroll to index ${e} after ${o} attempts.`
922
+ ));
923
+ };
924
+ l(s);
925
+ }, this.scrollBy = (e, { behavior: s } = {}) => {
926
+ s === "smooth" && this.isDynamicMode() && console.warn(
927
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
928
+ ), this._scrollToOffset(this.getScrollOffset() + e, {
929
+ adjustments: void 0,
930
+ behavior: s
931
+ });
932
+ }, this.getTotalSize = () => {
933
+ var e;
934
+ const s = this.getMeasurements();
935
+ let n;
936
+ if (s.length === 0)
937
+ n = this.options.paddingStart;
938
+ else if (this.options.lanes === 1)
939
+ n = ((e = s[s.length - 1]) == null ? void 0 : e.end) ?? 0;
940
+ else {
941
+ const i = Array(this.options.lanes).fill(null);
942
+ let o = s.length - 1;
943
+ for (; o >= 0 && i.some((l) => l === null); ) {
944
+ const l = s[o];
945
+ i[l.lane] === null && (i[l.lane] = l.end), o--;
946
+ }
947
+ n = Math.max(...i.filter((l) => l !== null));
948
+ }
949
+ return Math.max(
950
+ n - this.options.scrollMargin + this.options.paddingEnd,
951
+ 0
952
+ );
953
+ }, this._scrollToOffset = (e, {
954
+ adjustments: s,
955
+ behavior: n
956
+ }) => {
957
+ this.options.scrollToFn(e, { behavior: n, adjustments: s }, this);
958
+ }, this.measure = () => {
959
+ this.itemSizeCache = /* @__PURE__ */ new Map(), this.laneAssignments = /* @__PURE__ */ new Map(), this.notify(!1);
960
+ }, this.setOptions(a);
961
+ }
962
+ }
963
+ const he = (t, a, e, s) => {
964
+ for (; t <= a; ) {
965
+ const n = (t + a) / 2 | 0, i = e(n);
966
+ if (i < s)
967
+ t = n + 1;
968
+ else if (i > s)
969
+ a = n - 1;
970
+ else
971
+ return n;
972
+ }
973
+ return t > 0 ? t - 1 : 0;
974
+ };
975
+ function Ye({
976
+ measurements: t,
977
+ outerSize: a,
978
+ scrollOffset: e,
979
+ lanes: s
980
+ }) {
981
+ const n = t.length - 1, i = (f) => t[f].start;
982
+ if (t.length <= s)
983
+ return {
984
+ startIndex: 0,
985
+ endIndex: n
986
+ };
987
+ let o = he(
988
+ 0,
989
+ n,
990
+ i,
991
+ e
992
+ ), l = o;
993
+ if (s === 1)
994
+ for (; l < n && t[l].end < e + a; )
995
+ l++;
996
+ else if (s > 1) {
997
+ const f = Array(s).fill(0);
998
+ for (; l < n && f.some((d) => d < e + a); ) {
999
+ const d = t[l];
1000
+ f[d.lane] = d.end, l++;
1001
+ }
1002
+ const b = Array(s).fill(e + a);
1003
+ for (; o >= 0 && b.some((d) => d >= e); ) {
1004
+ const d = t[o];
1005
+ b[d.lane] = d.start, o--;
1006
+ }
1007
+ o = Math.max(0, o - o % s), l = Math.min(n, l + (s - 1 - l % s));
1008
+ }
1009
+ return { startIndex: o, endIndex: l };
1010
+ }
1011
+ const ue = typeof document < "u" ? H.useLayoutEffect : H.useEffect;
1012
+ function Ue({
1013
+ useFlushSync: t = !0,
1014
+ ...a
1015
+ }) {
1016
+ const e = H.useReducer(() => ({}), {})[1], s = {
1017
+ ...a,
1018
+ onChange: (i, o) => {
1019
+ var l;
1020
+ t && o ? Re(e) : e(), (l = a.onChange) == null || l.call(a, i, o);
1021
+ }
1022
+ }, [n] = H.useState(
1023
+ () => new Ve(s)
1024
+ );
1025
+ return n.setOptions(s), ue(() => n._didMount(), []), ue(() => n._willUpdate()), n;
1026
+ }
1027
+ function qe(t) {
1028
+ return Ue({
1029
+ observeElementRect: Pe,
1030
+ observeElementOffset: $e,
1031
+ scrollToFn: Le,
1032
+ ...t
1033
+ });
1034
+ }
1035
+ const Qe = ({
1036
+ data: t,
1037
+ columns: a,
1038
+ rowHeight: e = 40,
1039
+ height: s = 600,
1040
+ className: n = "",
1041
+ headerClassName: i = "",
1042
+ rowClassName: o,
1043
+ onRowClick: l,
1044
+ overscan: f = 5
1045
+ }) => {
1046
+ const b = pe(null), d = qe({
1047
+ count: t.length,
1048
+ getScrollElement: () => b.current,
1049
+ estimateSize: () => e,
1050
+ overscan: f
1051
+ }), S = d.getVirtualItems();
1052
+ return /* @__PURE__ */ v.jsxs("div", { className: n, children: [
1053
+ /* @__PURE__ */ v.jsx(
1054
+ "div",
1055
+ {
1056
+ className: `grid border-b sticky top-0 bg-background z-10 ${i}`,
1057
+ style: {
1058
+ gridTemplateColumns: a.map((c) => c.width || "1fr").join(" ")
1059
+ },
1060
+ children: a.map((c, m) => /* @__PURE__ */ v.jsx(
1061
+ "div",
1062
+ {
1063
+ className: `px-4 py-2 font-semibold text-sm ${c.align === "center" ? "text-center" : c.align === "right" ? "text-right" : "text-left"}`,
1064
+ children: c.header
1065
+ },
1066
+ m
1067
+ ))
1068
+ }
1069
+ ),
1070
+ /* @__PURE__ */ v.jsx(
1071
+ "div",
1072
+ {
1073
+ ref: b,
1074
+ className: "overflow-auto",
1075
+ style: {
1076
+ height: typeof s == "number" ? `${s}px` : s,
1077
+ contain: "strict"
1078
+ },
1079
+ children: /* @__PURE__ */ v.jsx(
1080
+ "div",
1081
+ {
1082
+ style: {
1083
+ height: `${d.getTotalSize()}px`,
1084
+ width: "100%",
1085
+ position: "relative"
1086
+ },
1087
+ children: S.map((c) => {
1088
+ const m = t[c.index], C = typeof o == "function" ? o(m, c.index) : o || "";
1089
+ return /* @__PURE__ */ v.jsx(
1090
+ "div",
1091
+ {
1092
+ className: `grid border-b hover:bg-muted/50 cursor-pointer ${C}`,
1093
+ style: {
1094
+ position: "absolute",
1095
+ top: 0,
1096
+ left: 0,
1097
+ width: "100%",
1098
+ height: `${c.size}px`,
1099
+ transform: `translateY(${c.start}px)`,
1100
+ gridTemplateColumns: a.map((g) => g.width || "1fr").join(" ")
1101
+ },
1102
+ onClick: () => l?.(m, c.index),
1103
+ children: a.map((g, _) => {
1104
+ const T = m[g.accessorKey], p = g.cell ? g.cell(T, m) : T;
1105
+ return /* @__PURE__ */ v.jsx(
1106
+ "div",
1107
+ {
1108
+ className: `px-4 py-2 text-sm flex items-center ${g.align === "center" ? "text-center justify-center" : g.align === "right" ? "text-right justify-end" : "text-left justify-start"}`,
1109
+ children: p
1110
+ },
1111
+ _
1112
+ );
1113
+ })
1114
+ },
1115
+ c.key
1116
+ );
1117
+ })
1118
+ }
1119
+ )
1120
+ }
1121
+ ),
1122
+ /* @__PURE__ */ v.jsxs("div", { className: "px-4 py-2 text-xs text-muted-foreground border-t", children: [
1123
+ "Showing ",
1124
+ S.length,
1125
+ " of ",
1126
+ t.length,
1127
+ " rows (virtual scrolling enabled)"
1128
+ ] })
1129
+ ] });
1130
+ }, me = ({ schema: t, ...a }) => {
1131
+ const { dataSource: e } = Ee() || {};
1132
+ return /* @__PURE__ */ v.jsx(ke, { schema: t, dataSource: e, ...a });
1133
+ };
1134
+ fe.register("object-grid", me, {
1135
+ namespace: "plugin-grid",
1136
+ label: "Object Grid",
1137
+ category: "plugin"
1138
+ });
1139
+ fe.register("grid", me, {
1140
+ namespace: "view",
1141
+ label: "Data Grid",
1142
+ category: "view"
1143
+ });
423
1144
  export {
424
- ye as ObjectGrid
1145
+ ke as ObjectGrid,
1146
+ me as ObjectGridRenderer,
1147
+ Qe as VirtualGrid
425
1148
  };