@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.
- package/dist/patterns/table/TableWrapper.d.ts.map +1 -1
- package/dist/patterns/table/TableWrapper.js +454 -449
- package/dist/patterns/table/integrateTableUndoRedo.d.ts +6 -2
- package/dist/patterns/table/integrateTableUndoRedo.d.ts.map +1 -1
- package/dist/patterns/table/integrateTableUndoRedo.js +19 -15
- package/dist/patterns/table/storyHelpers/useMockTableState.d.ts +1 -0
- package/dist/patterns/table/storyHelpers/useMockTableState.d.ts.map +1 -1
- package/dist/patterns/table/tableUndoRedo.d.ts +4 -0
- package/dist/patterns/table/tableUndoRedo.d.ts.map +1 -1
- package/dist/patterns/table/tableUndoRedo.js +47 -37
- package/dist/patterns/table/tableUndoRedo.test.d.ts +2 -0
- package/dist/patterns/table/tableUndoRedo.test.d.ts.map +1 -0
- package/dist/patterns/table/toolbar/ColumnHeaderMenu.d.ts +9 -0
- package/dist/patterns/table/toolbar/ColumnHeaderMenu.d.ts.map +1 -1
- package/dist/patterns/table/toolbar/ColumnHeaderMenu.js +123 -110
- package/dist/patterns/table/types.d.ts +5 -0
- package/dist/patterns/table/types.d.ts.map +1 -1
- package/dist/patterns/table/useTableUndoRedo.d.ts +1 -1
- package/dist/patterns/table/useTableUndoRedo.d.ts.map +1 -1
- package/dist/patterns/table/useTableUndoRedo.js +179 -165
- package/dist/styles/components.css +1 -1
- package/package.json +1 -1
|
@@ -1,258 +1,272 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { captureTableUndoSnapshot as
|
|
3
|
-
import { wrapColumnHeaderActionWithUndoRedo as
|
|
4
|
-
const
|
|
5
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
24
|
+
function F(n, t) {
|
|
25
25
|
let o = [...n, t];
|
|
26
|
-
for (;
|
|
27
|
-
o =
|
|
26
|
+
for (; ne(o, t) > V; )
|
|
27
|
+
o = $(o, t);
|
|
28
28
|
return o;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
30
|
+
function te() {
|
|
31
|
+
return b(Z);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ue({
|
|
34
34
|
children: n,
|
|
35
35
|
shortcuts: t = !0,
|
|
36
36
|
isDisabled: o = !1
|
|
37
37
|
}) {
|
|
38
|
-
const f =
|
|
39
|
-
H((
|
|
40
|
-
}, []),
|
|
41
|
-
(
|
|
42
|
-
c.current = c.current.filter((
|
|
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
|
-
),
|
|
46
|
-
(
|
|
47
|
-
f.current.delete(
|
|
48
|
-
const
|
|
49
|
-
|
|
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
|
-
[
|
|
52
|
-
),
|
|
53
|
-
(
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
return f.current.set(
|
|
58
|
-
f.current.delete(
|
|
59
|
-
const
|
|
60
|
-
|
|
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
|
-
|
|
62
|
+
g.current.set(e.tableId, y);
|
|
63
63
|
};
|
|
64
64
|
},
|
|
65
|
-
[u,
|
|
66
|
-
),
|
|
67
|
-
(
|
|
68
|
-
var
|
|
69
|
-
c.current = [...c.current,
|
|
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
|
-
),
|
|
73
|
-
(
|
|
74
|
-
const
|
|
75
|
-
|
|
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
|
-
),
|
|
79
|
-
(
|
|
80
|
-
const
|
|
81
|
-
|
|
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
|
-
),
|
|
85
|
-
(
|
|
86
|
-
const
|
|
87
|
-
|
|
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
|
-
),
|
|
90
|
+
), v = d(() => {
|
|
91
91
|
for (; c.current.length > 0; ) {
|
|
92
|
-
const
|
|
92
|
+
const e = c.current[c.current.length - 1];
|
|
93
93
|
c.current = c.current.slice(0, -1);
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
|
|
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]),
|
|
102
|
-
for (;
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
|
|
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]),
|
|
113
|
-
() => c.current.some((
|
|
114
|
-
var
|
|
115
|
-
return (
|
|
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
|
-
[
|
|
118
|
-
),
|
|
119
|
-
() =>
|
|
120
|
-
var
|
|
121
|
-
return (
|
|
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
|
-
[
|
|
123
|
+
[C]
|
|
124
124
|
);
|
|
125
|
-
|
|
125
|
+
Q(() => {
|
|
126
126
|
if (!t || o) return;
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
129
|
-
const
|
|
130
|
-
|
|
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",
|
|
133
|
-
}, [t, o,
|
|
134
|
-
const
|
|
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:
|
|
137
|
-
canRedo:
|
|
138
|
-
undo:
|
|
139
|
-
redo:
|
|
140
|
-
recordCommit:
|
|
141
|
-
recordLocalUndo:
|
|
142
|
-
recordLocalRedo:
|
|
143
|
-
recordHistoryEviction:
|
|
144
|
-
registerTable:
|
|
145
|
-
unregisterTable:
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
p,
|
|
158
|
-
x
|
|
155
|
+
S,
|
|
156
|
+
l,
|
|
157
|
+
E,
|
|
158
|
+
C
|
|
159
159
|
]
|
|
160
160
|
);
|
|
161
|
-
return Z
|
|
161
|
+
return G(Z.Provider, { value: x }, n);
|
|
162
162
|
}
|
|
163
|
-
function
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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 =
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
columnTextWrap: i,
|
|
182
|
+
setColumnTextWrap: g,
|
|
183
|
+
summaryFooterProps: C,
|
|
184
|
+
appliedFilterConditions: H,
|
|
185
|
+
data: u,
|
|
186
|
+
getData: L,
|
|
187
|
+
onDataRestore: E
|
|
184
188
|
}),
|
|
185
|
-
[
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
206
|
+
w.current = !0;
|
|
193
207
|
try {
|
|
194
|
-
const
|
|
195
|
-
return
|
|
208
|
+
const h = y(), O = l.current.pop();
|
|
209
|
+
return a.current = [h, ...a.current], q(O, R), !0;
|
|
196
210
|
} finally {
|
|
197
|
-
|
|
211
|
+
w.current = !1, S((h) => h + 1);
|
|
198
212
|
}
|
|
199
|
-
}, [n,
|
|
200
|
-
if (!n ||
|
|
201
|
-
|
|
213
|
+
}, [n, y, R]), k = d(() => {
|
|
214
|
+
if (!n || a.current.length === 0) return !1;
|
|
215
|
+
w.current = !0;
|
|
202
216
|
try {
|
|
203
|
-
const
|
|
204
|
-
return l.current = [...l.current,
|
|
217
|
+
const h = y(), O = a.current.shift();
|
|
218
|
+
return l.current = [...l.current, h], q(O, R), !0;
|
|
205
219
|
} finally {
|
|
206
|
-
|
|
220
|
+
w.current = !1, S((h) => h + 1);
|
|
207
221
|
}
|
|
208
|
-
}, [n,
|
|
209
|
-
|
|
210
|
-
}, []),
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
}, [
|
|
215
|
-
|
|
216
|
-
}, [
|
|
217
|
-
return
|
|
218
|
-
if (!(!n || !t || !
|
|
219
|
-
return
|
|
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:
|
|
222
|
-
canRedo:
|
|
235
|
+
canUndo: B,
|
|
236
|
+
canRedo: W,
|
|
223
237
|
undo: () => {
|
|
224
|
-
|
|
238
|
+
N.current();
|
|
225
239
|
},
|
|
226
240
|
redo: () => {
|
|
227
|
-
|
|
241
|
+
X.current();
|
|
228
242
|
},
|
|
229
243
|
clearRedo: () => {
|
|
230
|
-
|
|
244
|
+
Y.current();
|
|
231
245
|
}
|
|
232
246
|
});
|
|
233
|
-
}, [n, t,
|
|
247
|
+
}, [n, t, m, B, W]), P(
|
|
234
248
|
() => ({
|
|
235
|
-
canUndo:
|
|
236
|
-
canRedo:
|
|
237
|
-
undo:
|
|
238
|
-
redo:
|
|
239
|
-
commitBeforeMutation:
|
|
240
|
-
shortcut:
|
|
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
|
-
[
|
|
257
|
+
[B, W, _, j, K, p, A]
|
|
244
258
|
);
|
|
245
259
|
}
|
|
246
260
|
export {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
};
|