@toolbox-web/grid-react 2.0.0-rc.1 → 2.0.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,54 +1,61 @@
1
+ import { a as e, i as t } from "../chunks/portal-bridge-zxgm_jwK.js";
2
+ import { t as n } from "../chunks/feature-registry-8K2rOVnC.js";
1
3
  import "@toolbox-web/grid/features/pinned-rows";
2
- import { PinnedRowsPlugin as u } from "@toolbox-web/grid/plugins/pinned-rows";
3
- import { registerFeature as d } from "@toolbox-web/grid/features/registry";
4
- import { a as f, r as l } from "../chunks/portal-bridge-CvxNt40O.js";
5
- function c(e, n) {
6
- let r = null, t = !1;
7
- return (i) => {
8
- const o = e(i);
9
- if (o == null || o === !1) return null;
10
- if (o instanceof HTMLElement) return o;
11
- if (!r) {
12
- const s = document.createElement("div");
13
- s.style.display = "contents", r = { host: s, portalKey: null };
14
- }
15
- return r.portalKey = f(r.host, o, r.portalKey ?? void 0), t || (t = !0, n(() => {
16
- r?.portalKey && l(r.portalKey, { sync: !1 }), r = null;
17
- })), r.host;
18
- };
4
+ import { PinnedRowsPlugin as r } from "@toolbox-web/grid/plugins/pinned-rows";
5
+ //#region libs/grid-react/src/features/pinned-rows.ts
6
+ function i(n, r) {
7
+ let i = null, a = !1;
8
+ return (o) => {
9
+ let s = n(o);
10
+ if (s == null || s === !1) return null;
11
+ if (s instanceof HTMLElement) return s;
12
+ if (!i) {
13
+ let e = document.createElement("div");
14
+ e.style.display = "contents", i = {
15
+ host: e,
16
+ portalKey: null
17
+ };
18
+ }
19
+ return i.portalKey = e(i.host, s, i.portalKey ?? void 0), a || (a = !0, r(() => {
20
+ i?.portalKey && t(i.portalKey, { sync: !1 }), i = null;
21
+ })), i.host;
22
+ };
19
23
  }
20
- function p(e, n) {
21
- if (!("render" in e) || e.render == null) return e;
22
- if (Array.isArray(e.render)) {
23
- const r = e.render.map((t) => typeof t?.render != "function" ? t : { zone: t.zone, render: c(t.render, n) });
24
- return { ...e, render: r };
25
- }
26
- return typeof e.render == "function" ? { ...e, render: c(e.render, n) } : e;
24
+ function a(e, t) {
25
+ if (!("render" in e) || e.render == null) return e;
26
+ if (Array.isArray(e.render)) {
27
+ let n = e.render.map((e) => typeof e?.render == "function" ? {
28
+ zone: e.zone,
29
+ render: i(e.render, t)
30
+ } : e);
31
+ return {
32
+ ...e,
33
+ render: n
34
+ };
35
+ }
36
+ return typeof e.render == "function" ? {
37
+ ...e,
38
+ render: i(e.render, t)
39
+ } : e;
27
40
  }
28
- class h extends u {
29
- #e;
30
- constructor(n, r) {
31
- super(n), this.#e = r;
32
- }
33
- detach() {
34
- super.detach();
35
- for (const n of this.#e)
36
- try {
37
- n();
38
- } catch {
39
- }
40
- this.#e.length = 0;
41
- }
42
- }
43
- d(
44
- "pinnedRows",
45
- (e) => {
46
- if (typeof e == "boolean") return new u();
47
- if (!e) return new u();
48
- const n = e, { slots: r, ...t } = n, i = { ...t }, o = [], s = (a) => {
49
- o.push(a);
50
- };
51
- return Array.isArray(r) && (i.slots = r.map((a) => p(a, s))), new h(i, o);
52
- },
53
- { override: !0 }
54
- );
41
+ var o = class extends r {
42
+ #e;
43
+ constructor(e, t) {
44
+ super(e), this.#e = t;
45
+ }
46
+ detach() {
47
+ super.detach();
48
+ for (let e of this.#e) try {
49
+ e();
50
+ } catch {}
51
+ this.#e.length = 0;
52
+ }
53
+ };
54
+ n("pinnedRows", (e) => {
55
+ if (typeof e == "boolean" || !e) return new r();
56
+ let { slots: t, ...n } = e, i = { ...n }, s = [], c = (e) => {
57
+ s.push(e);
58
+ };
59
+ return Array.isArray(t) && (i.slots = t.map((e) => a(e, c))), new o(i, s);
60
+ }, { override: !0 });
61
+ //#endregion
package/features/print.js CHANGED
@@ -1,25 +1,20 @@
1
- import { useContext as s, useCallback as r } from "react";
2
- import { G as a } from "../chunks/grid-element-context-BU3WvNtM.js";
1
+ import { t as e } from "../chunks/grid-element-context-DpuQsoie.js";
2
+ import { useCallback as t, useContext as n } from "react";
3
3
  import "@toolbox-web/grid/features/print";
4
- function l(t) {
5
- const i = s(a), n = r(() => (t ? document.querySelector(t) : i?.current)?.getPluginByName("print"), [i, t]), u = r(
6
- async (e) => {
7
- const o = n();
8
- if (!o) {
9
- console.warn(
10
- `[tbw-grid:print] PrintPlugin not found.
11
-
12
- → Enable print on the grid:
13
- <DataGrid print />`
14
- );
15
- return;
16
- }
17
- await o.print(e);
18
- },
19
- [n]
20
- ), g = r(() => n()?.isPrinting() ?? !1, [n]);
21
- return { print: u, isPrinting: g };
4
+ //#region libs/grid-react/src/features/print.ts
5
+ function r(r) {
6
+ let i = n(e), a = t(() => (r ? document.querySelector(r) : i?.current)?.getPluginByName("print"), [i, r]);
7
+ return {
8
+ print: t(async (e) => {
9
+ let t = a();
10
+ if (!t) {
11
+ console.warn("[tbw-grid:print] PrintPlugin not found.\n\n → Enable print on the grid:\n <DataGrid print />");
12
+ return;
13
+ }
14
+ await t.print(e);
15
+ }, [a]),
16
+ isPrinting: t(() => a()?.isPrinting() ?? !1, [a])
17
+ };
22
18
  }
23
- export {
24
- l as useGridPrint
25
- };
19
+ //#endregion
20
+ export { r as useGridPrint };
@@ -1,65 +1,53 @@
1
+ import { o as e } from "../chunks/react-grid-adapter-CZfpPJvo.js";
2
+ import { a as t, i as n } from "../chunks/portal-bridge-zxgm_jwK.js";
3
+ import { n as r } from "../chunks/post-mount-refresh-hooks-D7BDK4Kl.js";
4
+ import { t as i } from "../chunks/feature-registry-8K2rOVnC.js";
5
+ import { n as a } from "../chunks/grid-responsive-card-Dx5U6Prm.js";
1
6
  import "@toolbox-web/grid/features/responsive";
2
- import { ResponsivePlugin as u } from "@toolbox-web/grid/plugins/responsive";
3
- import { registerFeature as l } from "@toolbox-web/grid/features/registry";
4
- import { g as p } from "../chunks/grid-responsive-card-CSZhDCoN.js";
5
- import { r as v, a as f } from "../chunks/portal-bridge-CvxNt40O.js";
6
- import { r as R } from "../chunks/post-mount-refresh-hooks-Dt7mPoZC.js";
7
- import { b as y } from "../chunks/react-grid-adapter-BhC9x425.js";
8
- y((e, { trackPortal: r }) => {
9
- const t = p(e);
10
- if (t)
11
- return (n, s) => {
12
- const o = document.createElement("div");
13
- o.className = "react-responsive-card";
14
- const i = f(
15
- o,
16
- t({ row: n, index: s }),
17
- void 0,
18
- e
19
- );
20
- return r(i, o, !1), o;
21
- };
7
+ import { ResponsivePlugin as o } from "@toolbox-web/grid/plugins/responsive";
8
+ e((e, { trackPortal: n }) => {
9
+ let r = a(e);
10
+ if (r) return (i, a) => {
11
+ let o = document.createElement("div");
12
+ return o.className = "react-responsive-card", n(t(o, r({
13
+ row: i,
14
+ index: a
15
+ }), void 0, e), o, !1), o;
16
+ };
17
+ }), r("responsive", ({ gridEl: e }) => {
18
+ if (!e.querySelector("tbw-grid-responsive-card") || !a(e)) return;
19
+ let t = e, n = t.getPluginByName("responsive");
20
+ if (!n?.setCardRenderer) return;
21
+ let r = t.__frameworkAdapter?.createResponsiveCardRenderer?.(e);
22
+ r && n.setCardRenderer(r);
22
23
  });
23
- R("responsive", ({ gridEl: e }) => {
24
- if (!e.querySelector("tbw-grid-responsive-card") || !p(e)) return;
25
- const t = e, n = t.getPluginByName("responsive");
26
- if (!n?.setCardRenderer) return;
27
- const s = t.__frameworkAdapter?.createResponsiveCardRenderer?.(e);
28
- s && n.setCardRenderer(s);
29
- });
30
- class h extends u {
31
- #e;
32
- constructor(r, t) {
33
- super(r), this.#e = t;
34
- }
35
- detach() {
36
- super.detach();
37
- for (const r of this.#e)
38
- try {
39
- v(r, { sync: !1 });
40
- } catch {
41
- }
42
- this.#e.clear();
43
- }
44
- }
45
- l(
46
- "responsive",
47
- (e) => {
48
- const r = e == null || typeof e == "boolean" ? {} : e, t = r.cardRenderer;
49
- if (typeof t != "function")
50
- return new u(r);
51
- const n = /* @__PURE__ */ new Set(), s = (o, d, i) => {
52
- const a = t(o, d, i);
53
- if (a instanceof HTMLElement) return a;
54
- const c = document.createElement("div");
55
- if (c.className = "react-responsive-card", a == null || a === !1) return c;
56
- const m = f(c, a);
57
- return n.add(m), c;
58
- };
59
- return new h(
60
- { ...r, cardRenderer: s },
61
- n
62
- );
63
- },
64
- { override: !0 }
65
- );
24
+ var s = class extends o {
25
+ #e;
26
+ constructor(e, t) {
27
+ super(e), this.#e = t;
28
+ }
29
+ detach() {
30
+ super.detach();
31
+ for (let e of this.#e) try {
32
+ n(e, { sync: !1 });
33
+ } catch {}
34
+ this.#e.clear();
35
+ }
36
+ };
37
+ i("responsive", (e) => {
38
+ let n = e == null || typeof e == "boolean" ? {} : e, r = n.cardRenderer;
39
+ if (typeof r != "function") return new o(n);
40
+ let i = /* @__PURE__ */ new Set(), a = (e, n, a) => {
41
+ let o = r(e, n, a);
42
+ if (o instanceof HTMLElement) return o;
43
+ let s = document.createElement("div");
44
+ if (s.className = "react-responsive-card", o == null || o === !1) return s;
45
+ let c = t(s, o);
46
+ return i.add(c), s;
47
+ };
48
+ return new s({
49
+ ...n,
50
+ cardRenderer: a
51
+ }, i);
52
+ }, { override: !0 });
53
+ //#endregion
@@ -1,47 +1,49 @@
1
- import { useContext as w, useCallback as n } from "react";
2
- import { G as C } from "../chunks/grid-element-context-BU3WvNtM.js";
1
+ import { t as e } from "../chunks/grid-element-context-DpuQsoie.js";
2
+ import { useCallback as t, useContext as n } from "react";
3
3
  import "@toolbox-web/grid/features/selection";
4
- function G(o) {
5
- const l = w(C), e = n(() => (o ? document.querySelector(o) : l?.current)?.getPluginByName("selection"), [l, o]), g = n(() => {
6
- const t = e();
7
- if (!t) {
8
- console.warn(
9
- `[tbw-grid:selection] SelectionPlugin not found.
10
-
11
- → Enable selection on the grid:
12
- <DataGrid selection="range" />`
13
- );
14
- return;
15
- }
16
- const r = o ? document.querySelector(o) : l?.current, u = t.config?.mode;
17
- if (u === "row") {
18
- const s = r?.rows?.length ?? 0, c = /* @__PURE__ */ new Set();
19
- for (let i = 0; i < s; i++) c.add(i);
20
- t.selected = c, t.requestAfterRender?.();
21
- } else if (u === "range") {
22
- const s = r?.rows?.length ?? 0, c = r?._columns?.length ?? 0;
23
- s > 0 && c > 0 && t.setRanges([{ from: { row: 0, col: 0 }, to: { row: s - 1, col: c - 1 } }]);
24
- }
25
- }, [e, l, o]), d = n(() => {
26
- e()?.clearSelection();
27
- }, [e]), a = n(() => e()?.getSelection() ?? null, [e]), f = n(
28
- (t, r) => e()?.isCellSelected(t, r) ?? !1,
29
- [e]
30
- ), m = n(
31
- (t) => {
32
- e()?.setRanges(t);
33
- },
34
- [e]
35
- ), S = n(() => e()?.getSelectedRows() ?? [], [e]);
36
- return {
37
- selectAll: g,
38
- clearSelection: d,
39
- getSelection: a,
40
- isCellSelected: f,
41
- setRanges: m,
42
- getSelectedRows: S
43
- };
4
+ //#region libs/grid-react/src/features/selection.ts
5
+ function r(r) {
6
+ let i = n(e), a = t(() => (r ? document.querySelector(r) : i?.current)?.getPluginByName("selection"), [i, r]);
7
+ return {
8
+ selectAll: t(() => {
9
+ let e = a();
10
+ if (!e) {
11
+ console.warn("[tbw-grid:selection] SelectionPlugin not found.\n\n → Enable selection on the grid:\n <DataGrid selection=\"range\" />");
12
+ return;
13
+ }
14
+ let t = r ? document.querySelector(r) : i?.current, n = e.config?.mode;
15
+ if (n === "row") {
16
+ let n = t?.rows?.length ?? 0, r = /* @__PURE__ */ new Set();
17
+ for (let e = 0; e < n; e++) r.add(e);
18
+ e.selected = r, e.requestAfterRender?.();
19
+ } else if (n === "range") {
20
+ let n = t?.rows?.length ?? 0, r = t?._columns?.length ?? 0;
21
+ n > 0 && r > 0 && e.setRanges([{
22
+ from: {
23
+ row: 0,
24
+ col: 0
25
+ },
26
+ to: {
27
+ row: n - 1,
28
+ col: r - 1
29
+ }
30
+ }]);
31
+ }
32
+ }, [
33
+ a,
34
+ i,
35
+ r
36
+ ]),
37
+ clearSelection: t(() => {
38
+ a()?.clearSelection();
39
+ }, [a]),
40
+ getSelection: t(() => a()?.getSelection() ?? null, [a]),
41
+ isCellSelected: t((e, t) => a()?.isCellSelected(e, t) ?? !1, [a]),
42
+ setRanges: t((e) => {
43
+ a()?.setRanges(e);
44
+ }, [a]),
45
+ getSelectedRows: t(() => a()?.getSelectedRows() ?? [], [a])
46
+ };
44
47
  }
45
- export {
46
- G as useGridSelection
47
- };
48
+ //#endregion
49
+ export { r as useGridSelection };
@@ -1,88 +1,55 @@
1
- import { useContext as p, useCallback as d } from "react";
2
- import { G as E } from "../chunks/grid-element-context-BU3WvNtM.js";
1
+ import { t as e } from "../chunks/grid-element-context-DpuQsoie.js";
2
+ import { useCallback as t, useContext as n } from "react";
3
3
  import "@toolbox-web/grid/features/undo-redo";
4
- function h(e) {
5
- const t = p(E), n = d(() => (e ? document.querySelector(e) : t?.current)?.getPluginByName("undoRedo"), [t, e]), i = d(() => {
6
- const o = n();
7
- return o ? o.undo() : (console.warn(
8
- `[tbw-grid:undoRedo] UndoRedoPlugin not found.
9
-
10
- → Enable undo/redo on the grid:
11
- <DataGrid editing="dblclick" undoRedo />`
12
- ), null);
13
- }, [n]), u = d(() => {
14
- const o = n();
15
- return o ? o.redo() : (console.warn(
16
- `[tbw-grid:undoRedo] UndoRedoPlugin not found.
17
-
18
- → Enable undo/redo on the grid:
19
- <DataGrid editing="dblclick" undoRedo />`
20
- ), null);
21
- }, [n]), c = d(() => n()?.canUndo() ?? !1, [n]), a = d(() => n()?.canRedo() ?? !1, [n]), l = d(() => {
22
- const o = n();
23
- if (!o) {
24
- console.warn(
25
- `[tbw-grid:undoRedo] UndoRedoPlugin not found.
26
-
27
- → Enable undo/redo on the grid:
28
- <DataGrid editing="dblclick" undoRedo />`
29
- );
30
- return;
31
- }
32
- o.clearHistory();
33
- }, [n]), g = d(() => n()?.getUndoStack() ?? [], [n]), s = d(() => n()?.getRedoStack() ?? [], [n]), R = d(
34
- (o, w, k, U) => {
35
- const r = n();
36
- if (!r) {
37
- console.warn(
38
- `[tbw-grid:undoRedo] UndoRedoPlugin not found.
39
-
40
- → Enable undo/redo on the grid:
41
- <DataGrid editing="dblclick" undoRedo />`
42
- );
43
- return;
44
- }
45
- r.recordEdit(o, w, k, U);
46
- },
47
- [n]
48
- ), b = d(() => {
49
- const o = n();
50
- if (!o) {
51
- console.warn(
52
- `[tbw-grid:undoRedo] UndoRedoPlugin not found.
53
-
54
- → Enable undo/redo on the grid:
55
- <DataGrid editing="dblclick" undoRedo />`
56
- );
57
- return;
58
- }
59
- o.beginTransaction();
60
- }, [n]), f = d(() => {
61
- const o = n();
62
- if (!o) {
63
- console.warn(
64
- `[tbw-grid:undoRedo] UndoRedoPlugin not found.
65
-
66
- → Enable undo/redo on the grid:
67
- <DataGrid editing="dblclick" undoRedo />`
68
- );
69
- return;
70
- }
71
- o.endTransaction();
72
- }, [n]);
73
- return {
74
- undo: i,
75
- redo: u,
76
- canUndo: c,
77
- canRedo: a,
78
- clearHistory: l,
79
- getUndoStack: g,
80
- getRedoStack: s,
81
- recordEdit: R,
82
- beginTransaction: b,
83
- endTransaction: f
84
- };
4
+ //#region libs/grid-react/src/features/undo-redo.ts
5
+ function r(r) {
6
+ let i = n(e), a = t(() => (r ? document.querySelector(r) : i?.current)?.getPluginByName("undoRedo"), [i, r]);
7
+ return {
8
+ undo: t(() => {
9
+ let e = a();
10
+ return e ? e.undo() : (console.warn("[tbw-grid:undoRedo] UndoRedoPlugin not found.\n\n → Enable undo/redo on the grid:\n <DataGrid editing=\"dblclick\" undoRedo />"), null);
11
+ }, [a]),
12
+ redo: t(() => {
13
+ let e = a();
14
+ return e ? e.redo() : (console.warn("[tbw-grid:undoRedo] UndoRedoPlugin not found.\n\n → Enable undo/redo on the grid:\n <DataGrid editing=\"dblclick\" undoRedo />"), null);
15
+ }, [a]),
16
+ canUndo: t(() => a()?.canUndo() ?? !1, [a]),
17
+ canRedo: t(() => a()?.canRedo() ?? !1, [a]),
18
+ clearHistory: t(() => {
19
+ let e = a();
20
+ if (!e) {
21
+ console.warn("[tbw-grid:undoRedo] UndoRedoPlugin not found.\n\n → Enable undo/redo on the grid:\n <DataGrid editing=\"dblclick\" undoRedo />");
22
+ return;
23
+ }
24
+ e.clearHistory();
25
+ }, [a]),
26
+ getUndoStack: t(() => a()?.getUndoStack() ?? [], [a]),
27
+ getRedoStack: t(() => a()?.getRedoStack() ?? [], [a]),
28
+ recordEdit: t((e, t, n, r) => {
29
+ let i = a();
30
+ if (!i) {
31
+ console.warn("[tbw-grid:undoRedo] UndoRedoPlugin not found.\n\n → Enable undo/redo on the grid:\n <DataGrid editing=\"dblclick\" undoRedo />");
32
+ return;
33
+ }
34
+ i.recordEdit(e, t, n, r);
35
+ }, [a]),
36
+ beginTransaction: t(() => {
37
+ let e = a();
38
+ if (!e) {
39
+ console.warn("[tbw-grid:undoRedo] UndoRedoPlugin not found.\n\n → Enable undo/redo on the grid:\n <DataGrid editing=\"dblclick\" undoRedo />");
40
+ return;
41
+ }
42
+ e.beginTransaction();
43
+ }, [a]),
44
+ endTransaction: t(() => {
45
+ let e = a();
46
+ if (!e) {
47
+ console.warn("[tbw-grid:undoRedo] UndoRedoPlugin not found.\n\n → Enable undo/redo on the grid:\n <DataGrid editing=\"dblclick\" undoRedo />");
48
+ return;
49
+ }
50
+ e.endTransaction();
51
+ }, [a])
52
+ };
85
53
  }
86
- export {
87
- h as useGridUndoRedo
88
- };
54
+ //#endregion
55
+ export { r as useGridUndoRedo };