@nubisco/ui 5.57.0 → 5.59.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.
@@ -1,869 +0,0 @@
1
- import { t as e } from "./_plugin-vue_export-helper-C6QCLu9I.js";
2
- import { t } from "./Icon-B2tiGiqZ.js";
3
- import { useStableId as n } from "./composables/useStableId.composable.mjs";
4
- import { usePhoneLayout as r } from "./composables/usePhoneLayout.composable.mjs";
5
- import { Fragment as i, computed as a, createBlock as o, createCommentVNode as s, createElementBlock as c, createElementVNode as l, defineComponent as u, nextTick as d, normalizeClass as f, normalizeStyle as p, onBeforeUnmount as ee, onMounted as te, openBlock as m, ref as h, renderList as ne, renderSlot as re, toDisplayString as g, useTemplateRef as ie, vModelText as ae, watch as oe, withDirectives as se, withModifiers as _ } from "vue";
6
- import * as ce from "@nubisco/ui/icons/arrow-down";
7
- import * as le from "@nubisco/ui/icons/arrow-up";
8
- import * as ue from "@nubisco/ui/icons/arrows-down-up";
9
- //#region src/components/Spreadsheet.vue?vue&type=script&setup=true&lang.ts
10
- var de = {
11
- key: 0,
12
- class: "nb-spreadsheet__toolbar"
13
- }, fe = [
14
- "aria-label",
15
- "aria-rowcount",
16
- "aria-colcount",
17
- "aria-activedescendant"
18
- ], pe = {
19
- class: "nb-spreadsheet__row",
20
- role: "row",
21
- "aria-rowindex": "1"
22
- }, me = [
23
- "aria-colindex",
24
- "aria-sort",
25
- "data-header-col",
26
- "onMousedown"
27
- ], he = ["title"], ge = ["onMousedown"], _e = ["aria-rowindex"], ve = ["onMousedown"], ye = [
28
- "id",
29
- "aria-colindex",
30
- "aria-selected",
31
- "aria-readonly",
32
- "title",
33
- "data-cell",
34
- "data-row",
35
- "data-col",
36
- "onMousedown",
37
- "onMouseenter",
38
- "onDblclick"
39
- ], be = ["inputmode", "aria-label"], xe = 20, Se = /* @__PURE__ */ e(/* @__PURE__ */ u({
40
- __name: "Spreadsheet",
41
- props: {
42
- columns: {},
43
- rows: {},
44
- cellAttrs: {},
45
- computed: {},
46
- resizable: {
47
- type: Boolean,
48
- default: !0
49
- },
50
- rowReorderable: {
51
- type: Boolean,
52
- default: !1
53
- },
54
- showGutter: {
55
- type: Boolean,
56
- default: !0
57
- },
58
- gutterWidth: { default: 44 },
59
- windowRows: { default: 80 },
60
- locale: { default: "pt-PT" },
61
- fit: {
62
- type: Boolean,
63
- default: !1
64
- },
65
- size: { default: "sm" },
66
- ariaLabel: { default: void 0 }
67
- },
68
- emits: [
69
- "commit",
70
- "change",
71
- "selection",
72
- "focus",
73
- "row-reorder"
74
- ],
75
- setup(e, { expose: u, emit: Se }) {
76
- let v = e, y = Se, b = ie("rootRef"), x = ie("scrollerRef"), Ce = ie("editorRef"), S = h({}), C = h(null), we = n({}), w = h(null), T = h(null), Te = h(!1), E = h(null), Ee = h(0), De = h(0), Oe = "", ke = h([]), Ae = h([]), D = a(() => {
77
- let e = v.columns.filter((e) => e.pinned === "left"), t = v.columns.filter((e) => e.pinned === "right"), n = v.columns.filter((e) => !e.pinned);
78
- return [
79
- ...e,
80
- ...n,
81
- ...t
82
- ];
83
- }), O = a(() => v.showGutter ? 1 : 0), k = a(() => new Map(v.rows.map((e) => [e.id, e]))), A = a(() => new Map(v.columns.map((e) => [e.id, e]))), j = a(() => new Map(D.value.map((e, t) => [e.id, t])));
84
- function M(e) {
85
- return S.value[e.id] ?? e.width ?? 120;
86
- }
87
- let je = {
88
- xs: 24,
89
- sm: 32,
90
- md: 40,
91
- lg: 48
92
- }, N = a(() => je[v.size] ?? je.sm), { phoneTouch: Me } = r(), P = h(null), Ne = a(() => P.value ?? N.value);
93
- function Pe() {
94
- let e = b.value, t = x.value;
95
- if (!v.fit || Me.value || !e || !t || !v.rows.length) {
96
- P.value = null;
97
- return;
98
- }
99
- let n = e.querySelector(".nb-spreadsheet__toolbar"), r = t.offsetHeight - t.clientHeight, i = e.clientHeight - (n?.offsetHeight ?? 0) - r, a = Z(".nb-spreadsheet__header") || N.value, o = Math.floor((i - a) / v.rows.length);
100
- P.value = Math.min(N.value, Math.max(xe, o));
101
- }
102
- let F = null;
103
- oe(() => [
104
- v.fit,
105
- v.rows.length,
106
- Me.value,
107
- v.size
108
- ], () => Pe());
109
- let Fe = a(() => P.value === null ? void 0 : { "--nbss-row-height": `${P.value}px` }), Ie = a(() => ({
110
- gridTemplateColumns: (v.showGutter ? `${v.gutterWidth}px ` : "") + D.value.map((e) => v.fit && !e.pinned ? `minmax(${M(e)}px, 1fr)` : `${M(e)}px`).join(" "),
111
- gridTemplateRows: "var(--nbss-header-height)"
112
- })), I = h(/* @__PURE__ */ new Set()), Le = /* @__PURE__ */ new Map();
113
- function L() {
114
- let e = x.value;
115
- if (!e) return;
116
- let t = [], n = !1, r = !1;
117
- for (let i of v.columns) {
118
- if (!i.shortLabel) continue;
119
- let a = e.querySelector(`[data-header-col="${X(i.id)}"] .nb-spreadsheet__header-label`);
120
- if (!a) continue;
121
- let o = `${i.id}::${i.label}`;
122
- I.value.has(i.id) || Le.set(o, a.scrollWidth);
123
- let s = Le.get(o);
124
- if (s === void 0) {
125
- r = !0;
126
- continue;
127
- }
128
- t.push(i.id), s > a.clientWidth && (n = !0);
129
- }
130
- I.value = new Set(n ? t : []), r && d(L);
131
- }
132
- oe(() => [v.columns, S.value], () => void d(L), { deep: !0 });
133
- let R = a(() => {
134
- let e = v.rows.filter((e) => !e.pinned);
135
- if (!C.value) return e;
136
- let t = A.value.get(C.value.columnId);
137
- if (!t) return e;
138
- let n = C.value.direction === "asc" ? 1 : -1, r = (e, t) => e == null && t == null ? 0 : e == null ? -1 : t == null ? 1 : typeof e == "number" && typeof t == "number" ? (e - t) * n : String(e).localeCompare(String(t)) * n;
139
- return [...e].sort((e, n) => r(e.values[t.id], n.values[t.id]));
140
- }), z = a(() => v.rows.filter((e) => e.pinned === "top")), B = a(() => v.rows.filter((e) => e.pinned === "bottom")), V = a(() => [
141
- ...z.value,
142
- ...R.value,
143
- ...B.value
144
- ]), H = a(() => new Map(V.value.map((e, t) => [e.id, t]))), Re = a(() => {
145
- let e = Math.max(1, Math.ceil((x.value?.clientHeight ?? 600) / Ne.value)), t = Math.max(10, Math.floor(v.windowRows / 4)), n = Math.floor(Ee.value / Ne.value) - z.value.length - t, r = Math.max(0, n), i = Math.min(R.value.length, r + e + t * 2), a = z.value.map((e, t) => ({
146
- ...e,
147
- __virtualIndex: t,
148
- gutterLabel: ""
149
- })), o = R.value.slice(r, i).map((e, t) => ({
150
- ...e,
151
- __virtualIndex: r + t + z.value.length
152
- })), s = B.value.map((e, t) => ({
153
- ...e,
154
- __virtualIndex: z.value.length + R.value.length + t,
155
- gutterLabel: ""
156
- }));
157
- return [
158
- ...a,
159
- ...o,
160
- ...s
161
- ];
162
- });
163
- function ze(e, t) {
164
- if (t == null || t === "") return "";
165
- if (e.type === "number") {
166
- let e = typeof t == "number" ? t : Number(t);
167
- return Number.isFinite(e) ? new Intl.NumberFormat(v.locale, { maximumFractionDigits: 4 }).format(e) : String(t);
168
- }
169
- if (e.type === "date") {
170
- let e = t instanceof Date ? t : new Date(t);
171
- return Number.isNaN(e.getTime()) ? String(t) : new Intl.DateTimeFormat(v.locale).format(e);
172
- }
173
- return String(t);
174
- }
175
- function Be(e, t) {
176
- if (t === "") return null;
177
- if (e.type === "number") {
178
- let e = t.replace(/\s/g, "").replace(",", "."), n = Number(e);
179
- if (!Number.isFinite(n)) throw Error("Invalid number");
180
- return n;
181
- }
182
- if (e.type === "date") {
183
- let e = new Date(t);
184
- if (Number.isNaN(e.getTime())) throw Error("Invalid date");
185
- return e.toISOString().slice(0, 10);
186
- }
187
- return t;
188
- }
189
- function U(e, t) {
190
- let n = k.value.get(e);
191
- if (!n) return;
192
- let r = n.values[t];
193
- if (r !== void 0) return r;
194
- if (v.computed) return v.computed(e, t, U);
195
- }
196
- function W(e, t) {
197
- return v.cellAttrs ? v.cellAttrs(e.id, t.id, e, t) ?? {} : {};
198
- }
199
- function Ve(e, t) {
200
- let n = W(e, t);
201
- if (n.display !== void 0) return n.display;
202
- let r = U(e.id, t.id);
203
- return t.format ? t.format(r, e) : ze(t, r);
204
- }
205
- function He(e, t) {
206
- let n = W(e, t), r = w.value?.rowId === e.id && w.value?.columnId === t.id, i = nt(e.id, t.id);
207
- return {
208
- [`nb-spreadsheet__cell--${t.align ?? (t.type === "number" || t.type === "date" ? "right" : "left")}`]: !0,
209
- "nb-spreadsheet__cell--focused": r,
210
- "nb-spreadsheet__cell--selected": i,
211
- "nb-spreadsheet__cell--readonly": G(e, t),
212
- "nb-spreadsheet__cell--computed": !!n.computed || !!e.computed,
213
- "nb-spreadsheet__cell--pinned-top": e.pinned === "top",
214
- "nb-spreadsheet__cell--pinned-bottom": e.pinned === "bottom",
215
- [n.className ?? ""]: !!n.className,
216
- [e.className ?? ""]: !!e.className
217
- };
218
- }
219
- function G(e, t) {
220
- if (e.computed || t.readOnly) return !0;
221
- let n = W(e, t);
222
- return !!n.readOnly || !!n.computed;
223
- }
224
- function Ue(e, t) {
225
- return W(e, t).tooltip ?? "";
226
- }
227
- function We(e, t) {
228
- return `${we}-r${H.value.get(e)}-c${j.value.get(t)}`;
229
- }
230
- let Ge = a(() => w.value ? We(w.value.rowId, w.value.columnId) : void 0);
231
- function Ke(e, t) {
232
- let n = K.value;
233
- return {
234
- "nb-spreadsheet__header--sortable": !!e.sortable,
235
- "nb-spreadsheet__header--sorted": C.value?.columnId === e.id,
236
- "nb-spreadsheet__header--selected": !!n && t >= n.c1 && t <= n.c2,
237
- "nb-spreadsheet__header--pinned-left": e.pinned === "left",
238
- "nb-spreadsheet__header--pinned-right": e.pinned === "right",
239
- "nb-spreadsheet__header--last": t === D.value.length - 1
240
- };
241
- }
242
- function qe(e) {
243
- if (e.sortable) return C.value?.columnId === e.id ? C.value.direction === "asc" ? "ascending" : "descending" : "none";
244
- }
245
- function Je(e) {
246
- return C.value?.columnId === e.id ? C.value.direction === "asc" ? le : ce : ue;
247
- }
248
- function Ye(e) {
249
- if (e.pinned !== "left") return 0;
250
- let t = v.showGutter ? v.gutterWidth : 0;
251
- for (let n of D.value) {
252
- if (n.id === e.id) break;
253
- n.pinned === "left" && (t += M(n));
254
- }
255
- return t;
256
- }
257
- function Xe(e) {
258
- if (e.pinned !== "right") return 0;
259
- let t = 0, n = [...D.value].reverse();
260
- for (let r of n) {
261
- if (r.id === e.id) break;
262
- r.pinned === "right" && (t += M(r));
263
- }
264
- return t;
265
- }
266
- function Ze(e, t) {
267
- let n = O.value + 1 + t, r = {};
268
- return e.pinned === "left" ? (r.position = "sticky", r.left = `${Ye(e)}px`, r.zIndex = "3") : e.pinned === "right" && (r.position = "sticky", r.right = `${Xe(e)}px`, r.zIndex = "3"), {
269
- gridRow: 1,
270
- gridColumn: n,
271
- ...r
272
- };
273
- }
274
- function Qe(e, t, n) {
275
- let r = O.value + 1 + n, i = e.__virtualIndex + 2, a = {};
276
- return t.pinned === "left" ? (a.position = "sticky", a.left = `${Ye(t)}px`, a.zIndex = "2") : t.pinned === "right" && (a.position = "sticky", a.right = `${Xe(t)}px`, a.zIndex = "2"), (e.pinned === "top" || e.pinned === "bottom") && (a.position = "sticky", a.zIndex = String(Math.max(Number(a.zIndex ?? 0), 2)), Object.assign(a, $e(e))), {
277
- gridRow: i,
278
- gridColumn: r,
279
- ...a
280
- };
281
- }
282
- function $e(e) {
283
- if (e.pinned === "top") {
284
- let t = z.value.findIndex((t) => t.id === e.id);
285
- return { top: `calc(var(--nbss-header-height) + var(--nbss-row-height) * ${Math.max(0, t)})` };
286
- }
287
- if (e.pinned === "bottom") {
288
- let t = B.value, n = t.findIndex((t) => t.id === e.id);
289
- return { bottom: `calc(var(--nbss-row-height) * ${Math.max(0, t.length - 1 - n)})` };
290
- }
291
- return {};
292
- }
293
- function et(e) {
294
- return e.label === void 0 ? e.gutterLabel === void 0 ? String(e.__virtualIndex - z.value.length + 1) : e.gutterLabel : e.label;
295
- }
296
- function tt(e) {
297
- let t = {
298
- position: "sticky",
299
- left: "0",
300
- zIndex: "2"
301
- };
302
- return e.pinned && (Object.assign(t, $e(e)), t.zIndex = "4"), {
303
- gridRow: e.__virtualIndex + 2,
304
- gridColumn: 1,
305
- ...t
306
- };
307
- }
308
- let K = a(() => {
309
- let e = T.value;
310
- if (!e) return null;
311
- let t = H.value.get(e.startRowId) ?? -1, n = H.value.get(e.endRowId) ?? -1, r = j.value.get(e.startColumnId) ?? -1, i = j.value.get(e.endColumnId) ?? -1;
312
- return t < 0 || n < 0 || r < 0 || i < 0 ? null : {
313
- r1: Math.min(t, n),
314
- r2: Math.max(t, n),
315
- c1: Math.min(r, i),
316
- c2: Math.max(r, i)
317
- };
318
- });
319
- function nt(e, t) {
320
- let n = K.value;
321
- if (!n) return !1;
322
- let r = H.value.get(e) ?? -1, i = j.value.get(t) ?? -1;
323
- return r >= n.r1 && r <= n.r2 && i >= n.c1 && i <= n.c2;
324
- }
325
- function rt(e) {
326
- let t = K.value;
327
- if (!t) return !1;
328
- let n = H.value.get(e) ?? -1;
329
- return n >= t.r1 && n <= t.r2;
330
- }
331
- function q(e, t, n = !1) {
332
- w.value = {
333
- rowId: e,
334
- columnId: t
335
- }, n && T.value ? T.value = {
336
- ...T.value,
337
- endRowId: e,
338
- endColumnId: t
339
- } : T.value = {
340
- startRowId: e,
341
- startColumnId: t,
342
- endRowId: e,
343
- endColumnId: t
344
- }, y("focus", w.value), y("selection", T.value);
345
- }
346
- function it(e, t, n) {
347
- w.value = {
348
- rowId: e,
349
- columnId: t
350
- }, T.value = n, y("focus", w.value), y("selection", T.value);
351
- }
352
- function at(e, t = !1) {
353
- let n = V.value;
354
- if (!n.length) return;
355
- let r = t && T.value ? T.value.startColumnId : e;
356
- it(n[0].id, r, {
357
- startRowId: n[0].id,
358
- startColumnId: r,
359
- endRowId: n[n.length - 1].id,
360
- endColumnId: e
361
- });
362
- }
363
- function ot(e, t = !1) {
364
- let n = D.value;
365
- if (!n.length) return;
366
- let r = t && T.value ? T.value.startRowId : e;
367
- it(r, n[0].id, {
368
- startRowId: r,
369
- startColumnId: n[0].id,
370
- endRowId: e,
371
- endColumnId: n[n.length - 1].id
372
- });
373
- }
374
- function st() {
375
- let e = V.value, t = D.value;
376
- !e.length || !t.length || it(e[0].id, t[0].id, {
377
- startRowId: e[0].id,
378
- startColumnId: t[0].id,
379
- endRowId: e[e.length - 1].id,
380
- endColumnId: t[t.length - 1].id
381
- });
382
- }
383
- function ct(e) {
384
- Oe = e.pointerType;
385
- }
386
- function lt(e, t, n) {
387
- let r = Oe === "touch" && !e.shiftKey && w.value?.rowId === t.id && w.value?.columnId === n.id;
388
- if (Oe = "", E.value && $(), Te.value = !0, q(t.id, n.id, e.shiftKey), J(), e.preventDefault(), document.addEventListener("mouseup", dt, { once: !0 }), r && !G(t, n)) {
389
- let e = U(t.id, n.id);
390
- Q(t, n, e == null ? "" : String(e), "edit");
391
- }
392
- }
393
- function ut(e, t) {
394
- !Te.value || !T.value || (T.value = {
395
- ...T.value,
396
- endRowId: e.id,
397
- endColumnId: t.id
398
- }, y("selection", T.value));
399
- }
400
- function dt() {
401
- Te.value = !1;
402
- }
403
- function ft(e, t) {
404
- if (G(e, t)) return;
405
- let n = U(e.id, t.id);
406
- Q(e, t, n == null ? "" : String(n), "edit");
407
- }
408
- function pt(e, t) {
409
- e.button === 0 && (e.preventDefault(), E.value && $(), J(), t.sortable ? Nt(t) : at(t.id, e.shiftKey));
410
- }
411
- function mt(e, t) {
412
- e.button === 0 && (E.value && $(), J(), ot(t.id, e.shiftKey));
413
- }
414
- function ht(e) {
415
- e.button === 0 && (E.value && $(), J(), st());
416
- }
417
- function J() {
418
- x.value?.focus({ preventScroll: !0 });
419
- }
420
- function Y(e, t, n = !1) {
421
- if (!w.value) {
422
- let e = D.value[0], t = Re.value[0];
423
- e && t && q(t.id, e.id);
424
- return;
425
- }
426
- let r = V.value, i = H.value.get(w.value.rowId) ?? 0, a = j.value.get(w.value.columnId) ?? 0, o = Math.max(0, Math.min(r.length - 1, i + e)), s = Math.max(0, Math.min(D.value.length - 1, a + t)), c = r[o].id, l = D.value[s].id;
427
- q(c, l, n), vt(c, l);
428
- }
429
- function X(e) {
430
- return e.replace(/["\\]/g, "\\$&");
431
- }
432
- function Z(e) {
433
- let t = x.value?.querySelector(e);
434
- return t ? t.offsetHeight : 0;
435
- }
436
- function gt(e) {
437
- let t = 0;
438
- for (let n of e) t += Z(`[data-row="${X(n.id)}"]`);
439
- return t;
440
- }
441
- function _t(e) {
442
- let t = e === "left" && v.showGutter ? v.gutterWidth : 0;
443
- for (let n of D.value) n.pinned === e && (t += M(n));
444
- return t;
445
- }
446
- function vt(e, t) {
447
- let n = x.value;
448
- if (!n) return;
449
- let r = R.value.findIndex((t) => t.id === e);
450
- if (r >= 0) {
451
- let e = Z(".nb-spreadsheet__header") || N.value, t = Z(".nb-spreadsheet__cell") || Ne.value, i = e + (z.value.length + r) * t, a = e + gt(z.value), o = gt(B.value);
452
- i - a < n.scrollTop ? n.scrollTop = i - a : i + t > n.scrollTop + n.clientHeight - o && (n.scrollTop = i + t - n.clientHeight + o);
453
- }
454
- let i = t ? A.value.get(t) : void 0;
455
- if (i && !i.pinned) {
456
- let e = v.showGutter ? v.gutterWidth : 0;
457
- for (let t of D.value) {
458
- if (t.id === i.id) break;
459
- e += M(t);
460
- }
461
- let t = M(i), r = _t("left"), a = _t("right");
462
- e - r < n.scrollLeft ? n.scrollLeft = e - r : e + t > n.scrollLeft + n.clientWidth - a && (n.scrollLeft = e + t - n.clientWidth + a);
463
- }
464
- yt();
465
- }
466
- function yt() {
467
- Ee.value = x.value?.scrollTop ?? 0, De.value = x.value?.scrollLeft ?? 0;
468
- }
469
- function bt() {
470
- if (!w.value) return null;
471
- let e = k.value.get(w.value.rowId), t = A.value.get(w.value.columnId);
472
- return e && t ? {
473
- r: e,
474
- c: t
475
- } : null;
476
- }
477
- function xt(e) {
478
- return !e.metaKey && !e.ctrlKey && !e.altKey && e.key.length === 1;
479
- }
480
- function St(e) {
481
- if (E.value) {
482
- e.target !== Ce.value && (xt(e) ? (e.preventDefault(), E.value.draft += e.key) : Et(e));
483
- return;
484
- }
485
- let t = e.metaKey || e.ctrlKey;
486
- if (t && e.key.toLowerCase() === "z") {
487
- e.preventDefault(), e.shiftKey ? It() : Ft();
488
- return;
489
- }
490
- if (t && e.key.toLowerCase() === "a") {
491
- e.preventDefault(), st();
492
- return;
493
- }
494
- if (e.key === " " && (e.ctrlKey || e.shiftKey) && !e.metaKey && !e.altKey) {
495
- let t = w.value;
496
- if (!t) return;
497
- e.preventDefault(), e.ctrlKey ? at(t.columnId) : ot(t.rowId);
498
- return;
499
- }
500
- switch (e.key) {
501
- case "ArrowDown":
502
- e.preventDefault(), Y(1, 0, e.shiftKey);
503
- break;
504
- case "ArrowUp":
505
- e.preventDefault(), Y(-1, 0, e.shiftKey);
506
- break;
507
- case "ArrowLeft":
508
- e.preventDefault(), Y(0, -1, e.shiftKey);
509
- break;
510
- case "ArrowRight":
511
- e.preventDefault(), Y(0, 1, e.shiftKey);
512
- break;
513
- case "Tab":
514
- e.preventDefault(), Y(0, e.shiftKey ? -1 : 1);
515
- break;
516
- case "Enter":
517
- e.preventDefault(), Y(e.shiftKey ? -1 : 1, 0);
518
- break;
519
- case "Escape":
520
- T.value = null, y("selection", null);
521
- break;
522
- case "Delete":
523
- case "Backspace":
524
- e.preventDefault(), Ot();
525
- break;
526
- case "F2": {
527
- e.preventDefault();
528
- let t = bt();
529
- if (t && !G(t.r, t.c)) {
530
- let e = U(t.r.id, t.c.id);
531
- Q(t.r, t.c, e == null ? "" : String(e), "edit");
532
- }
533
- break;
534
- }
535
- default: {
536
- if (!xt(e)) break;
537
- let t = bt();
538
- t && !G(t.r, t.c) && (e.preventDefault(), Q(t.r, t.c, e.key, "enter"));
539
- }
540
- }
541
- }
542
- function Q(e, t, n, r) {
543
- vt(e.id, t.id), E.value = {
544
- rowId: e.id,
545
- columnId: t.id,
546
- draft: n,
547
- mode: r
548
- }, d(() => {
549
- let e = Ce.value;
550
- if (e) if (e.focus({ preventScroll: !0 }), r === "enter") {
551
- let t = e.value.length;
552
- e.setSelectionRange(t, t);
553
- } else e.select();
554
- });
555
- }
556
- let Ct = a(() => {
557
- if (E.value) return A.value.get(E.value.columnId)?.type === "number" ? "decimal" : "text";
558
- }), wt = a(() => {
559
- if (!E.value) return;
560
- let e = A.value.get(E.value.columnId), t = k.value.get(E.value.rowId), n = H.value.get(E.value.rowId) ?? 0, r = t?.label ?? String(n - z.value.length + 1);
561
- return [e?.label, r].filter(Boolean).join(" ");
562
- }), Tt = a(() => {
563
- if (!E.value) return { display: "none" };
564
- let e = x.value, t = e?.querySelector(`[data-cell="${X(`${E.value.rowId}::${E.value.columnId}`)}"]`);
565
- if (!e || !t) return { display: "none" };
566
- let n = t.getBoundingClientRect(), r = e.getBoundingClientRect();
567
- return {
568
- top: `${n.top - r.top - e.clientTop + Ee.value}px`,
569
- left: `${n.left - r.left - e.clientLeft + De.value}px`,
570
- width: `${n.width}px`,
571
- height: `${n.height}px`
572
- };
573
- });
574
- function Et(e) {
575
- let t = E.value?.mode, n = null;
576
- switch (e.key) {
577
- case "Enter":
578
- n = [e.shiftKey ? -1 : 1, 0];
579
- break;
580
- case "Tab":
581
- n = [0, e.shiftKey ? -1 : 1];
582
- break;
583
- case "ArrowDown":
584
- n = [1, 0];
585
- break;
586
- case "ArrowUp":
587
- n = [-1, 0];
588
- break;
589
- case "ArrowLeft":
590
- t === "enter" && (n = [0, -1]);
591
- break;
592
- case "ArrowRight":
593
- t === "enter" && (n = [0, 1]);
594
- break;
595
- case "Escape":
596
- e.preventDefault(), E.value = null, J();
597
- return;
598
- }
599
- n && (e.preventDefault(), $(), Y(n[0], n[1]));
600
- }
601
- function $(e = !0) {
602
- if (!E.value) return;
603
- let { rowId: t, columnId: n, draft: r } = E.value;
604
- E.value = null;
605
- let i = A.value.get(n);
606
- if (!i) return;
607
- let a;
608
- try {
609
- a = i.parse ? i.parse(r) : Be(i, r);
610
- } catch {
611
- e && J();
612
- return;
613
- }
614
- let o = U(t, n);
615
- if (o !== a) {
616
- let e = {
617
- rowId: t,
618
- columnId: n,
619
- before: o,
620
- after: a
621
- };
622
- Pt([e]), y("commit", e), y("change", [e]);
623
- }
624
- e && J();
625
- }
626
- function Dt() {
627
- let e = K.value;
628
- if (!e) return [];
629
- let t = V.value, n = D.value, r = [];
630
- for (let i = e.r1; i <= e.r2; i++) for (let a = e.c1; a <= e.c2; a++) r.push({
631
- rowId: t[i].id,
632
- columnId: n[a].id
633
- });
634
- return r;
635
- }
636
- function Ot() {
637
- let e = Dt(), t = [];
638
- for (let { rowId: n, columnId: r } of e) {
639
- let e = k.value.get(n), i = A.value.get(r);
640
- if (!e || !i || G(e, i)) continue;
641
- let a = U(n, r);
642
- a == null || a === "" || t.push({
643
- rowId: n,
644
- columnId: r,
645
- before: a,
646
- after: null
647
- });
648
- }
649
- if (t.length !== 0) {
650
- Pt(t);
651
- for (let e of t) y("commit", e);
652
- y("change", t);
653
- }
654
- }
655
- function kt(e) {
656
- let t = K.value;
657
- if (!t) return;
658
- let n = V.value.map((e) => e.id), r = D.value.map((e) => e.id), i = [];
659
- for (let e = t.r1; e <= t.r2; e++) {
660
- let a = [];
661
- for (let i = t.c1; i <= t.c2; i++) {
662
- let t = U(n[e], r[i]);
663
- a.push(t == null ? "" : String(t));
664
- }
665
- i.push(a.join(" "));
666
- }
667
- e.preventDefault(), e.clipboardData?.setData("text/plain", i.join("\n"));
668
- }
669
- function At(e) {
670
- kt(e), Ot();
671
- }
672
- function jt(e) {
673
- if (!w.value) return;
674
- let t = e.clipboardData?.getData("text/plain") ?? "";
675
- if (!t) return;
676
- e.preventDefault();
677
- let n = t.replace(/\r\n?/g, "\n").split("\n").map((e) => e.split(" ")), r = V.value.map((e) => e.id), i = D.value.map((e) => e.id), a = H.value.get(w.value.rowId) ?? 0, o = j.value.get(w.value.columnId) ?? 0, s = [];
678
- if (n.forEach((e, t) => {
679
- e.forEach((e, n) => {
680
- let c = r[a + t], l = i[o + n];
681
- if (!c || !l) return;
682
- let u = k.value.get(c), d = A.value.get(l);
683
- if (!u || !d || G(u, d)) return;
684
- let f;
685
- try {
686
- f = d.parse ? d.parse(e) : Be(d, e);
687
- } catch {
688
- return;
689
- }
690
- let p = U(c, l);
691
- p !== f && s.push({
692
- rowId: c,
693
- columnId: l,
694
- before: p,
695
- after: f
696
- });
697
- });
698
- }), s.length !== 0) {
699
- Pt(s);
700
- for (let e of s) y("commit", e);
701
- y("change", s);
702
- }
703
- }
704
- function Mt(e, t) {
705
- let n = e.clientX, r = M(t), i = t.minWidth ?? 60, a = (e) => {
706
- let a = Math.max(i, r + (e.clientX - n));
707
- S.value = {
708
- ...S.value,
709
- [t.id]: a
710
- };
711
- }, o = () => {
712
- window.removeEventListener("mousemove", a), window.removeEventListener("mouseup", o);
713
- };
714
- window.addEventListener("mousemove", a), window.addEventListener("mouseup", o);
715
- }
716
- function Nt(e) {
717
- C.value?.columnId === e.id ? C.value = C.value.direction === "asc" ? {
718
- columnId: e.id,
719
- direction: "desc"
720
- } : null : C.value = {
721
- columnId: e.id,
722
- direction: "asc"
723
- };
724
- }
725
- function Pt(e) {
726
- ke.value.push(e), Ae.value = [];
727
- }
728
- function Ft() {
729
- let e = ke.value.pop();
730
- if (!e) return;
731
- let t = e.map((e) => ({
732
- ...e,
733
- before: e.after,
734
- after: e.before
735
- }));
736
- for (let e of t) y("commit", e);
737
- y("change", t), Ae.value.push(e);
738
- }
739
- function It() {
740
- let e = Ae.value.pop();
741
- if (e) {
742
- for (let t of e) y("commit", t);
743
- y("change", e), ke.value.push(e);
744
- }
745
- }
746
- return te(() => {
747
- J(), Pe(), L(), typeof ResizeObserver < "u" && x.value && (F = new ResizeObserver(() => {
748
- Pe(), L();
749
- }), F.observe(x.value), b.value && F.observe(b.value));
750
- }), ee(() => F?.disconnect()), u({
751
- focus: (e, t) => q(e, t),
752
- undo: Ft,
753
- redo: It,
754
- getSelection: () => T.value,
755
- selectAll: st,
756
- selectColumn: (e) => at(e),
757
- selectRow: (e) => ot(e)
758
- }), (n, r) => (m(), c("div", {
759
- ref_key: "rootRef",
760
- ref: b,
761
- class: f(["nb-spreadsheet", [`nb-spreadsheet--${e.size}`, {
762
- "nb-spreadsheet--editing": !!E.value,
763
- "nb-spreadsheet--fit": e.fit
764
- }]]),
765
- style: p(Fe.value)
766
- }, [n.$slots.toolbar ? (m(), c("div", de, [re(n.$slots, "toolbar", {}, void 0, !0)])) : s("", !0), l("div", {
767
- ref_key: "scrollerRef",
768
- ref: x,
769
- class: "nb-spreadsheet__scroller",
770
- tabindex: "0",
771
- role: "grid",
772
- "aria-multiselectable": "true",
773
- "aria-label": e.ariaLabel,
774
- "aria-rowcount": V.value.length + 1,
775
- "aria-colcount": D.value.length + (e.showGutter ? 1 : 0),
776
- "aria-activedescendant": Ge.value,
777
- onKeydown: St,
778
- onCopy: kt,
779
- onCut: At,
780
- onPaste: jt,
781
- onScroll: yt
782
- }, [l("div", {
783
- class: "nb-spreadsheet__grid",
784
- style: p(Ie.value)
785
- }, [l("div", pe, [e.showGutter ? (m(), c("div", {
786
- key: 0,
787
- class: "nb-spreadsheet__corner",
788
- role: "columnheader",
789
- "aria-colindex": "1",
790
- style: {
791
- gridRow: 1,
792
- gridColumn: 1
793
- },
794
- onMousedown: _(ht, ["prevent"])
795
- }, null, 32)) : s("", !0), (m(!0), c(i, null, ne(D.value, (n, r) => (m(), c("div", {
796
- key: `h-${n.id}`,
797
- class: f(["nb-spreadsheet__header", Ke(n, r)]),
798
- role: "columnheader",
799
- "aria-colindex": r + O.value + 1,
800
- "aria-sort": qe(n),
801
- "data-header-col": n.id,
802
- style: p(Ze(n, r)),
803
- onMousedown: (e) => pt(e, n)
804
- }, [
805
- l("span", {
806
- class: "nb-spreadsheet__header-label",
807
- title: I.value.has(n.id) ? n.label : void 0
808
- }, g(I.value.has(n.id) ? n.shortLabel : n.label), 9, he),
809
- n.sortable ? (m(), o(t, {
810
- key: 0,
811
- name: Je(n),
812
- class: "nb-spreadsheet__sort",
813
- "aria-hidden": "true"
814
- }, null, 8, ["name"])) : s("", !0),
815
- e.resizable ? (m(), c("span", {
816
- key: 1,
817
- class: "nb-spreadsheet__resize-handle",
818
- onMousedown: _((e) => Mt(e, n), ["stop"])
819
- }, null, 40, ge)) : s("", !0)
820
- ], 46, me))), 128))]), (m(!0), c(i, null, ne(Re.value, (t) => (m(), c("div", {
821
- key: `r-${t.id}`,
822
- class: "nb-spreadsheet__row",
823
- role: "row",
824
- "aria-rowindex": t.__virtualIndex + 2
825
- }, [e.showGutter ? (m(), c("div", {
826
- key: 0,
827
- class: f(["nb-spreadsheet__gutter", {
828
- "nb-spreadsheet__gutter--pinned-top": t.pinned === "top",
829
- "nb-spreadsheet__gutter--pinned-bottom": t.pinned === "bottom",
830
- "nb-spreadsheet__gutter--selected": rt(t.id)
831
- }]),
832
- role: "rowheader",
833
- "aria-colindex": "1",
834
- style: p(tt(t)),
835
- onMousedown: _((e) => mt(e, t), ["prevent"])
836
- }, g(et(t)), 47, ve)) : s("", !0), (m(!0), c(i, null, ne(D.value, (e, n) => (m(), c("div", {
837
- id: We(t.id, e.id),
838
- key: `c-${t.id}-${e.id}`,
839
- class: f(["nb-spreadsheet__cell", He(t, e)]),
840
- role: "gridcell",
841
- "aria-colindex": n + O.value + 1,
842
- "aria-selected": nt(t.id, e.id),
843
- "aria-readonly": G(t, e) || void 0,
844
- style: p(Qe(t, e, n)),
845
- title: Ue(t, e),
846
- "data-cell": `${t.id}::${e.id}`,
847
- "data-row": t.id,
848
- "data-col": e.id,
849
- onPointerdown: r[0] ||= (e) => ct(e),
850
- onMousedown: (n) => lt(n, t, e),
851
- onMouseenter: (n) => ut(t, e),
852
- onDblclick: (n) => ft(t, e)
853
- }, [l("span", null, g(Ve(t, e)), 1)], 46, ye))), 128))], 8, _e))), 128))], 4), E.value ? se((m(), c("input", {
854
- key: 0,
855
- ref_key: "editorRef",
856
- ref: Ce,
857
- "onUpdate:modelValue": r[1] ||= (e) => E.value.draft = e,
858
- class: "nb-spreadsheet__editor",
859
- style: p(Tt.value),
860
- inputmode: Ct.value,
861
- "aria-label": wt.value,
862
- enterkeyhint: "next",
863
- onBlur: r[2] ||= (e) => $(!1),
864
- onKeydown: _(Et, ["stop"])
865
- }, null, 44, be)), [[ae, E.value.draft]]) : s("", !0)], 40, fe)], 6));
866
- }
867
- }), [["__scopeId", "data-v-cace060c"]]);
868
- //#endregion
869
- export { Se as t };