@pibit.ai/cure-design-system 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,258 +1,272 @@
1
- import { useRef as h, useState as D, useCallback as d, useMemo as P, useEffect as F, createElement as Z, createContext as $, useContext as G } from "react";
2
- import { captureTableUndoSnapshot as I, applyTableUndoSnapshot as _ } from "./tableUndoRedo.js";
3
- import { wrapColumnHeaderActionWithUndoRedo as ie, wrapEditChromeWithUndoRedo as de, wrapRowActionsWithUndoRedo as fe, wrapSummaryFooterWithUndoRedo as le, wrapToolbarWithUndoRedo as ae } from "./tableUndoRedo.js";
4
- const J = 50, Q = $(null);
5
- function b(n) {
1
+ import { useRef as U, useState as J, useCallback as d, useMemo as P, useEffect as Q, createElement as G, createContext as I, useContext as b } from "react";
2
+ import { captureTableUndoSnapshot as ee, applyTableUndoSnapshot as q } from "./tableUndoRedo.js";
3
+ import { wrapColumnHeaderActionWithUndoRedo as fe, wrapEditChromeWithUndoRedo as le, wrapRowActionsWithUndoRedo as ae, wrapSummaryFooterWithUndoRedo as pe, wrapToolbarWithUndoRedo as Re } from "./tableUndoRedo.js";
4
+ const V = 50, Z = I(null);
5
+ function re(n) {
6
6
  if (!(n instanceof HTMLElement)) return !1;
7
7
  const t = n.tagName;
8
8
  return !!(t === "INPUT" || t === "TEXTAREA" || t === "SELECT" || n.isContentEditable);
9
9
  }
10
- function j(n, t) {
10
+ function D(n, t) {
11
11
  const o = n.lastIndexOf(t);
12
12
  return o === -1 ? n : [...n.slice(0, o), ...n.slice(o + 1)];
13
13
  }
14
- function V(n, t) {
14
+ function $(n, t) {
15
15
  const o = n.indexOf(t);
16
16
  return o === -1 ? n : [...n.slice(0, o), ...n.slice(o + 1)];
17
17
  }
18
- function ee(n, t) {
18
+ function ne(n, t) {
19
19
  let o = 0;
20
20
  for (const f of n)
21
21
  f === t && (o += 1);
22
22
  return o;
23
23
  }
24
- function q(n, t) {
24
+ function F(n, t) {
25
25
  let o = [...n, t];
26
- for (; ee(o, t) > J; )
27
- o = V(o, t);
26
+ for (; ne(o, t) > V; )
27
+ o = $(o, t);
28
28
  return o;
29
29
  }
30
- function re() {
31
- return G(Q);
30
+ function te() {
31
+ return b(Z);
32
32
  }
33
- function ce({
33
+ function ue({
34
34
  children: n,
35
35
  shortcuts: t = !0,
36
36
  isDisabled: o = !1
37
37
  }) {
38
- const f = h(/* @__PURE__ */ new Map()), c = h([]), s = h([]), y = h(/* @__PURE__ */ new Map()), [x, H] = D(0), u = d(() => {
39
- H((r) => r + 1);
40
- }, []), l = d(
41
- (r) => {
42
- c.current = c.current.filter((e) => e !== r), s.current = s.current.filter((e) => e !== r), u();
38
+ const f = U(/* @__PURE__ */ new Map()), c = U([]), i = U([]), g = U(/* @__PURE__ */ new Map()), [C, H] = J(0), u = d(() => {
39
+ H((e) => e + 1);
40
+ }, []), L = d(
41
+ (e) => {
42
+ c.current = c.current.filter((r) => r !== e), i.current = i.current.filter((r) => r !== e), u();
43
43
  },
44
44
  [u]
45
- ), p = d(
46
- (r) => {
47
- f.current.delete(r);
48
- const e = y.current.get(r);
49
- e !== void 0 && (clearTimeout(e), y.current.delete(r)), l(r);
45
+ ), E = d(
46
+ (e) => {
47
+ f.current.delete(e);
48
+ const r = g.current.get(e);
49
+ r !== void 0 && (clearTimeout(r), g.current.delete(e)), L(e);
50
50
  },
51
- [l]
52
- ), U = d(
53
- (r) => {
54
- const e = y.current.get(r.tableId);
55
- e !== void 0 && (clearTimeout(e), y.current.delete(r.tableId));
56
- const a = f.current.get(r.tableId);
57
- return f.current.set(r.tableId, r), (!a || a.canUndo !== r.canUndo || a.canRedo !== r.canRedo) && u(), () => {
58
- f.current.delete(r.tableId);
59
- const L = setTimeout(() => {
60
- y.current.delete(r.tableId), f.current.has(r.tableId) || l(r.tableId);
51
+ [L]
52
+ ), l = d(
53
+ (e) => {
54
+ const r = g.current.get(e.tableId);
55
+ r !== void 0 && (clearTimeout(r), g.current.delete(e.tableId));
56
+ const m = f.current.get(e.tableId);
57
+ return f.current.set(e.tableId, e), (!m || m.canUndo !== e.canUndo || m.canRedo !== e.canRedo) && u(), () => {
58
+ f.current.delete(e.tableId);
59
+ const y = setTimeout(() => {
60
+ g.current.delete(e.tableId), f.current.has(e.tableId) || L(e.tableId);
61
61
  }, 0);
62
- y.current.set(r.tableId, L);
62
+ g.current.set(e.tableId, y);
63
63
  };
64
64
  },
65
- [u, l]
66
- ), A = d(
67
- (r) => {
68
- var e;
69
- c.current = [...c.current, r], s.current = s.current.filter((a) => a !== r), (e = f.current.get(r)) == null || e.clearRedo(), u();
65
+ [u, L]
66
+ ), a = d(
67
+ (e) => {
68
+ var r;
69
+ c.current = [...c.current, e], i.current = i.current.filter((m) => m !== e), (r = f.current.get(e)) == null || r.clearRedo(), u();
70
70
  },
71
71
  [u]
72
- ), C = d(
73
- (r) => {
74
- const e = j(c.current, r);
75
- e !== c.current && (c.current = e), s.current = [...s.current, r], u();
72
+ ), w = d(
73
+ (e) => {
74
+ const r = D(c.current, e);
75
+ r !== c.current && (c.current = r), i.current = [...i.current, e], u();
76
76
  },
77
77
  [u]
78
- ), K = d(
79
- (r) => {
80
- const e = j(s.current, r);
81
- e !== s.current && (s.current = e), c.current = q(c.current, r), u();
78
+ ), A = d(
79
+ (e) => {
80
+ const r = D(i.current, e);
81
+ r !== i.current && (i.current = r), c.current = F(c.current, e), u();
82
82
  },
83
83
  [u]
84
- ), i = d(
85
- (r) => {
86
- const e = V(c.current, r);
87
- e !== c.current && (c.current = e, u());
84
+ ), S = d(
85
+ (e) => {
86
+ const r = $(c.current, e);
87
+ r !== c.current && (c.current = r, u());
88
88
  },
89
89
  [u]
90
- ), R = d(() => {
90
+ ), v = d(() => {
91
91
  for (; c.current.length > 0; ) {
92
- const r = c.current[c.current.length - 1];
92
+ const e = c.current[c.current.length - 1];
93
93
  c.current = c.current.slice(0, -1);
94
- const e = f.current.get(r);
95
- if (e && e.canUndo) {
96
- e.undo(), s.current = [...s.current, r], u();
94
+ const r = f.current.get(e);
95
+ if (r && r.canUndo) {
96
+ r.undo(), i.current = [...i.current, e], u();
97
97
  return;
98
98
  }
99
99
  }
100
100
  u();
101
- }, [u]), g = d(() => {
102
- for (; s.current.length > 0; ) {
103
- const r = s.current[s.current.length - 1];
104
- s.current = s.current.slice(0, -1);
105
- const e = f.current.get(r);
106
- if (e && e.canRedo) {
107
- e.redo(), c.current = q(c.current, r), u();
101
+ }, [u]), s = d(() => {
102
+ for (; i.current.length > 0; ) {
103
+ const e = i.current[i.current.length - 1];
104
+ i.current = i.current.slice(0, -1);
105
+ const r = f.current.get(e);
106
+ if (r && r.canRedo) {
107
+ r.redo(), c.current = F(c.current, e), u();
108
108
  return;
109
109
  }
110
110
  }
111
111
  u();
112
- }, [u]), T = P(
113
- () => c.current.some((r) => {
114
- var e;
115
- return (e = f.current.get(r)) == null ? void 0 : e.canUndo;
112
+ }, [u]), p = P(
113
+ () => c.current.some((e) => {
114
+ var r;
115
+ return (r = f.current.get(e)) == null ? void 0 : r.canUndo;
116
116
  }),
117
- [x]
118
- ), w = P(
119
- () => s.current.some((r) => {
120
- var e;
121
- return (e = f.current.get(r)) == null ? void 0 : e.canRedo;
117
+ [C]
118
+ ), T = P(
119
+ () => i.current.some((e) => {
120
+ var r;
121
+ return (r = f.current.get(e)) == null ? void 0 : r.canRedo;
122
122
  }),
123
- [x]
123
+ [C]
124
124
  );
125
- F(() => {
125
+ Q(() => {
126
126
  if (!t || o) return;
127
- const r = (e) => {
128
- if (b(e.target) || !(e.metaKey || e.ctrlKey) || e.altKey) return;
129
- const S = e.key.toLowerCase(), L = S === "z" && !e.shiftKey, v = S === "z" && e.shiftKey || S === "y";
130
- L && T ? (e.preventDefault(), e.stopPropagation(), R()) : v && w && (e.preventDefault(), e.stopPropagation(), g());
127
+ const e = (r) => {
128
+ if (re(r.target) || !(r.metaKey || r.ctrlKey) || r.altKey) return;
129
+ const R = r.key.toLowerCase(), y = R === "z" && !r.shiftKey, K = R === "z" && r.shiftKey || R === "y";
130
+ y && p ? (r.preventDefault(), r.stopPropagation(), v()) : K && T && (r.preventDefault(), r.stopPropagation(), s());
131
131
  };
132
- return window.addEventListener("keydown", r, { capture: !0 }), () => window.removeEventListener("keydown", r, { capture: !0 });
133
- }, [t, o, T, w, R, g]);
134
- const E = P(
132
+ return window.addEventListener("keydown", e, { capture: !0 }), () => window.removeEventListener("keydown", e, { capture: !0 });
133
+ }, [t, o, p, T, v, s]);
134
+ const x = P(
135
135
  () => ({
136
- canUndo: T,
137
- canRedo: w,
138
- undo: R,
139
- redo: g,
140
- recordCommit: A,
141
- recordLocalUndo: C,
142
- recordLocalRedo: K,
143
- recordHistoryEviction: i,
144
- registerTable: U,
145
- unregisterTable: p
136
+ canUndo: p,
137
+ canRedo: T,
138
+ undo: v,
139
+ redo: s,
140
+ recordCommit: a,
141
+ recordLocalUndo: w,
142
+ recordLocalRedo: A,
143
+ recordHistoryEviction: S,
144
+ registerTable: l,
145
+ unregisterTable: E
146
146
  }),
147
147
  [
148
+ p,
148
149
  T,
150
+ v,
151
+ s,
152
+ a,
149
153
  w,
150
- R,
151
- g,
152
154
  A,
153
- C,
154
- K,
155
- i,
156
- U,
157
- p,
158
- x
155
+ S,
156
+ l,
157
+ E,
158
+ C
159
159
  ]
160
160
  );
161
- return Z(Q.Provider, { value: E }, n);
161
+ return G(Z.Provider, { value: x }, n);
162
162
  }
163
- function oe({
163
+ function se({
164
164
  enabled: n = !1,
165
165
  tableId: t,
166
166
  sharedUndoGroup: o,
167
167
  toolbar: f,
168
168
  columnAlignments: c,
169
- summaryFooterProps: s,
170
- appliedFilterConditions: y,
171
- data: x,
172
- getData: H,
173
- onDataRestore: u
169
+ columnTextWrap: i,
170
+ setColumnTextWrap: g,
171
+ summaryFooterProps: C,
172
+ appliedFilterConditions: H,
173
+ data: u,
174
+ getData: L,
175
+ onDataRestore: E
174
176
  }) {
175
- const l = h([]), p = h([]), U = h(!1), [A, C] = D(0), K = re(), i = o === void 0 ? K : o, R = !!(n && t && i), g = i == null ? void 0 : i.recordCommit, T = i == null ? void 0 : i.recordLocalUndo, w = i == null ? void 0 : i.recordLocalRedo, E = i == null ? void 0 : i.recordHistoryEviction, r = i == null ? void 0 : i.registerTable, e = P(
177
+ const l = U([]), a = U([]), w = U(!1), [A, S] = J(0), v = te(), s = o === void 0 ? v : o, p = !!(n && t && s), T = s == null ? void 0 : s.recordCommit, x = s == null ? void 0 : s.recordLocalUndo, e = s == null ? void 0 : s.recordLocalRedo, r = s == null ? void 0 : s.recordHistoryEviction, m = s == null ? void 0 : s.registerTable, R = P(
176
178
  () => ({
177
179
  toolbar: f,
178
180
  columnAlignments: c,
179
- summaryFooterProps: s,
180
- appliedFilterConditions: y,
181
- data: x,
182
- getData: H,
183
- onDataRestore: u
181
+ columnTextWrap: i,
182
+ setColumnTextWrap: g,
183
+ summaryFooterProps: C,
184
+ appliedFilterConditions: H,
185
+ data: u,
186
+ getData: L,
187
+ onDataRestore: E
184
188
  }),
185
- [f, c, s, y, x, H, u]
186
- ), a = d(() => I(e), [e]), S = d(() => {
187
- if (!n || U.current) return;
188
- const m = l.current.length >= J;
189
- l.current = [...l.current.slice(-49), a()], p.current = [], t && g && (g(t), m && E && E(t)), C((O) => O + 1);
190
- }, [n, a, g, E, t]), L = d(() => {
189
+ [
190
+ f,
191
+ c,
192
+ i,
193
+ g,
194
+ C,
195
+ H,
196
+ u,
197
+ L,
198
+ E
199
+ ]
200
+ ), y = d(() => ee(R), [R]), K = d(() => {
201
+ if (!n || w.current) return;
202
+ const h = l.current.length >= V;
203
+ l.current = [...l.current.slice(-49), y()], a.current = [], t && T && (T(t), h && r && r(t)), S((O) => O + 1);
204
+ }, [n, y, T, r, t]), M = d(() => {
191
205
  if (!n || l.current.length === 0) return !1;
192
- U.current = !0;
206
+ w.current = !0;
193
207
  try {
194
- const m = a(), O = l.current.pop();
195
- return p.current = [m, ...p.current], _(O, e), !0;
208
+ const h = y(), O = l.current.pop();
209
+ return a.current = [h, ...a.current], q(O, R), !0;
196
210
  } finally {
197
- U.current = !1, C((m) => m + 1);
211
+ w.current = !1, S((h) => h + 1);
198
212
  }
199
- }, [n, a, e]), v = d(() => {
200
- if (!n || p.current.length === 0) return !1;
201
- U.current = !0;
213
+ }, [n, y, R]), k = d(() => {
214
+ if (!n || a.current.length === 0) return !1;
215
+ w.current = !0;
202
216
  try {
203
- const m = a(), O = p.current.shift();
204
- return l.current = [...l.current, m], _(O, e), !0;
217
+ const h = y(), O = a.current.shift();
218
+ return l.current = [...l.current, h], q(O, R), !0;
205
219
  } finally {
206
- U.current = !1, C((m) => m + 1);
220
+ w.current = !1, S((h) => h + 1);
207
221
  }
208
- }, [n, a, e]), W = d(() => {
209
- p.current.length !== 0 && (p.current = [], C((m) => m + 1));
210
- }, []), M = n && l.current.length > 0, k = n && p.current.length > 0, B = h(L), z = h(v), N = h(W);
211
- B.current = L, z.current = v, N.current = W;
212
- const X = d(() => {
213
- L() && R && t && T && T(t);
214
- }, [L, R, t, T]), Y = d(() => {
215
- v() && R && t && w && w(t);
216
- }, [v, R, t, w]);
217
- return F(() => {
218
- if (!(!n || !t || !r))
219
- return r({
222
+ }, [n, y, R]), z = d(() => {
223
+ a.current.length !== 0 && (a.current = [], S((h) => h + 1));
224
+ }, []), B = n && l.current.length > 0, W = n && a.current.length > 0, N = U(M), X = U(k), Y = U(z);
225
+ N.current = M, X.current = k, Y.current = z;
226
+ const _ = d(() => {
227
+ M() && p && t && x && x(t);
228
+ }, [M, p, t, x]), j = d(() => {
229
+ k() && p && t && e && e(t);
230
+ }, [k, p, t, e]);
231
+ return Q(() => {
232
+ if (!(!n || !t || !m))
233
+ return m({
220
234
  tableId: t,
221
- canUndo: M,
222
- canRedo: k,
235
+ canUndo: B,
236
+ canRedo: W,
223
237
  undo: () => {
224
- B.current();
238
+ N.current();
225
239
  },
226
240
  redo: () => {
227
- z.current();
241
+ X.current();
228
242
  },
229
243
  clearRedo: () => {
230
- N.current();
244
+ Y.current();
231
245
  }
232
246
  });
233
- }, [n, t, r, M, k]), P(
247
+ }, [n, t, m, B, W]), P(
234
248
  () => ({
235
- canUndo: M,
236
- canRedo: k,
237
- undo: X,
238
- redo: Y,
239
- commitBeforeMutation: S,
240
- shortcut: R ? !1 : void 0
249
+ canUndo: B,
250
+ canRedo: W,
251
+ undo: _,
252
+ redo: j,
253
+ commitBeforeMutation: K,
254
+ shortcut: p ? !1 : void 0
241
255
  }),
242
256
  // revision drives canUndo/canRedo updates after history mutations
243
- [M, k, X, Y, S, R, A]
257
+ [B, W, _, j, K, p, A]
244
258
  );
245
259
  }
246
260
  export {
247
- J as MAX_HISTORY,
248
- ce as TableUndoRedoProvider,
249
- _ as applyTableUndoSnapshot,
250
- I as captureTableUndoSnapshot,
251
- oe as useTableUndoRedo,
252
- re as useTableUndoRedoScope,
253
- ie as wrapColumnHeaderActionWithUndoRedo,
254
- de as wrapEditChromeWithUndoRedo,
255
- fe as wrapRowActionsWithUndoRedo,
256
- le as wrapSummaryFooterWithUndoRedo,
257
- ae as wrapToolbarWithUndoRedo
261
+ V as MAX_HISTORY,
262
+ ue as TableUndoRedoProvider,
263
+ q as applyTableUndoSnapshot,
264
+ ee as captureTableUndoSnapshot,
265
+ se as useTableUndoRedo,
266
+ te as useTableUndoRedoScope,
267
+ fe as wrapColumnHeaderActionWithUndoRedo,
268
+ le as wrapEditChromeWithUndoRedo,
269
+ ae as wrapRowActionsWithUndoRedo,
270
+ pe as wrapSummaryFooterWithUndoRedo,
271
+ Re as wrapToolbarWithUndoRedo
258
272
  };