@toolbox-web/grid 0.4.0 → 0.4.2
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/README.md +10 -13
- package/all.js +1124 -1047
- package/all.js.map +1 -1
- package/index.js +688 -515
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +10 -0
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/config-manager.d.ts +1 -0
- package/lib/core/internal/config-manager.d.ts.map +1 -1
- package/lib/core/internal/keyboard.d.ts.map +1 -1
- package/lib/core/internal/utils.d.ts +1 -0
- package/lib/core/internal/utils.d.ts.map +1 -1
- package/lib/core/internal/validate-config.d.ts +14 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +105 -1
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/expander-column.d.ts +51 -0
- package/lib/core/plugin/expander-column.d.ts.map +1 -0
- package/lib/core/plugin/index.d.ts +1 -0
- package/lib/core/plugin/index.d.ts.map +1 -1
- package/lib/core/plugin/plugin-manager.d.ts +1 -1
- package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +117 -1
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +4 -2
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +9 -2
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.d.ts +1 -1
- package/lib/plugins/clipboard/index.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +303 -185
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +72 -2
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js +116 -24
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +0 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +164 -72
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +1 -7
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +213 -133
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/ExportPlugin.d.ts +0 -1
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +195 -103
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +5 -2
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +145 -43
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +1 -2
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +162 -68
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +14 -2
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +246 -138
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +13 -11
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js +281 -196
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +0 -10
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +1 -2
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js +121 -31
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +0 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.js +144 -52
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -2
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +178 -88
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts +26 -4
- package/lib/plugins/pivot/PivotPlugin.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js +414 -310
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-rows.d.ts +2 -1
- package/lib/plugins/pivot/pivot-rows.d.ts.map +1 -1
- package/lib/plugins/reorder/ReorderPlugin.d.ts +13 -10
- package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js +304 -226
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts +21 -3
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
- package/lib/plugins/selection/index.d.ts +2 -2
- package/lib/plugins/selection/index.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +292 -145
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/types.d.ts +24 -0
- package/lib/plugins/selection/types.d.ts.map +1 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
- package/lib/plugins/server-side/index.js +95 -3
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +5 -1
- package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
- package/lib/plugins/tree/index.js +213 -112
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +0 -10
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +7 -2
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +112 -12
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +14 -5
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +168 -65
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +21 -17
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +14 -8
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +5 -7
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -15,7 +15,6 @@ import { ExportConfig, ExportFormat, ExportParams } from './types';
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class ExportPlugin extends BaseGridPlugin<ExportConfig> {
|
|
17
17
|
readonly name = "export";
|
|
18
|
-
readonly version = "1.0.0";
|
|
19
18
|
protected get defaultConfig(): Partial<ExportConfig>;
|
|
20
19
|
private isExportingFlag;
|
|
21
20
|
private lastExportInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/export/ExportPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAwB,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAO9F;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAa,SAAQ,cAAc,CAAC,YAAY,CAAC;IAC5D,QAAQ,CAAC,IAAI,YAAY;
|
|
1
|
+
{"version":3,"file":"ExportPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/export/ExportPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAwB,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAO9F;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAa,SAAQ,cAAc,CAAC,YAAY,CAAC;IAC5D,QAAQ,CAAC,IAAI,YAAY;IAEzB,cAAuB,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC,CAO5D;IAGD,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,cAAc,CAA0D;IAKhF,OAAO,CAAC,aAAa;IAyFrB,OAAO,CAAC,iBAAiB;IAWzB;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAI/C;;;OAGG;IACH,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAIjD;;;OAGG;IACH,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAIhD;;;OAGG;IACH,WAAW,IAAI,OAAO;IAItB;;;OAGG;IACH,aAAa,IAAI;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,SAAS,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI;CAIlE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const w = {
|
|
2
2
|
expand: "▶",
|
|
3
3
|
collapse: "▼",
|
|
4
4
|
sortAsc: "▲",
|
|
@@ -8,9 +8,28 @@ const x = {
|
|
|
8
8
|
dragHandle: "⋮⋮",
|
|
9
9
|
toolPanel: "☰"
|
|
10
10
|
};
|
|
11
|
-
class
|
|
12
|
-
/**
|
|
13
|
-
|
|
11
|
+
class x {
|
|
12
|
+
/**
|
|
13
|
+
* Plugin dependencies - declare other plugins this one requires.
|
|
14
|
+
*
|
|
15
|
+
* Dependencies are validated when the plugin is attached.
|
|
16
|
+
* Required dependencies throw an error if missing.
|
|
17
|
+
* Optional dependencies log an info message if missing.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* static readonly dependencies: PluginDependency[] = [
|
|
22
|
+
* { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
|
|
23
|
+
* { name: 'selection', required: false, reason: 'Enables selection-based undo' },
|
|
24
|
+
* ];
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
static dependencies;
|
|
28
|
+
/**
|
|
29
|
+
* Plugin version - defaults to grid version for built-in plugins.
|
|
30
|
+
* Third-party plugins can override with their own semver.
|
|
31
|
+
*/
|
|
32
|
+
version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
|
|
14
33
|
/** CSS styles to inject into the grid's shadow DOM */
|
|
15
34
|
styles;
|
|
16
35
|
/** Custom cell renderers keyed by type name */
|
|
@@ -39,8 +58,8 @@ class w {
|
|
|
39
58
|
get defaultConfig() {
|
|
40
59
|
return {};
|
|
41
60
|
}
|
|
42
|
-
constructor(
|
|
43
|
-
this.userConfig =
|
|
61
|
+
constructor(e = {}) {
|
|
62
|
+
this.userConfig = e;
|
|
44
63
|
}
|
|
45
64
|
/**
|
|
46
65
|
* Called when the plugin is attached to a grid.
|
|
@@ -57,8 +76,8 @@ class w {
|
|
|
57
76
|
* }
|
|
58
77
|
* ```
|
|
59
78
|
*/
|
|
60
|
-
attach(
|
|
61
|
-
this.#e?.abort(), this.#e = new AbortController(), this.grid =
|
|
79
|
+
attach(e) {
|
|
80
|
+
this.#e?.abort(), this.#e = new AbortController(), this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
|
|
62
81
|
}
|
|
63
82
|
/**
|
|
64
83
|
* Called when the plugin is detached from a grid.
|
|
@@ -88,14 +107,22 @@ class w {
|
|
|
88
107
|
* }
|
|
89
108
|
* ```
|
|
90
109
|
*/
|
|
91
|
-
getPlugin(
|
|
92
|
-
return this.grid?.getPlugin(
|
|
110
|
+
getPlugin(e) {
|
|
111
|
+
return this.grid?.getPlugin(e);
|
|
93
112
|
}
|
|
94
113
|
/**
|
|
95
114
|
* Emit a custom event from the grid.
|
|
96
115
|
*/
|
|
97
|
-
emit(
|
|
98
|
-
this.grid?.dispatchEvent?.(new CustomEvent(
|
|
116
|
+
emit(e, t) {
|
|
117
|
+
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Emit a cancelable custom event from the grid.
|
|
121
|
+
* @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
|
|
122
|
+
*/
|
|
123
|
+
emitCancelable(e, t) {
|
|
124
|
+
const n = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
|
|
125
|
+
return this.grid?.dispatchEvent?.(n), n.defaultPrevented;
|
|
99
126
|
}
|
|
100
127
|
/**
|
|
101
128
|
* Request a re-render of the grid.
|
|
@@ -103,6 +130,14 @@ class w {
|
|
|
103
130
|
requestRender() {
|
|
104
131
|
this.grid?.requestRender?.();
|
|
105
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Request a re-render and restore focus styling afterward.
|
|
135
|
+
* Use this when a plugin action (like expand/collapse) triggers a render
|
|
136
|
+
* but needs to maintain keyboard navigation focus.
|
|
137
|
+
*/
|
|
138
|
+
requestRenderWithFocus() {
|
|
139
|
+
this.grid?.requestRenderWithFocus?.();
|
|
140
|
+
}
|
|
106
141
|
/**
|
|
107
142
|
* Request a lightweight style update without rebuilding DOM.
|
|
108
143
|
* Use this instead of requestRender() when only CSS classes need updating.
|
|
@@ -136,6 +171,19 @@ class w {
|
|
|
136
171
|
get visibleColumns() {
|
|
137
172
|
return this.grid?._visibleColumns ?? [];
|
|
138
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Get the grid as an HTMLElement for direct DOM operations.
|
|
176
|
+
* Use sparingly - prefer the typed GridElementRef API when possible.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const width = this.gridElement.clientWidth;
|
|
181
|
+
* this.gridElement.classList.add('my-plugin-active');
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
get gridElement() {
|
|
185
|
+
return this.grid;
|
|
186
|
+
}
|
|
139
187
|
/**
|
|
140
188
|
* Get the shadow root of the grid.
|
|
141
189
|
*/
|
|
@@ -167,9 +215,54 @@ class w {
|
|
|
167
215
|
* Returns merged icons (user config + defaults).
|
|
168
216
|
*/
|
|
169
217
|
get gridIcons() {
|
|
170
|
-
const
|
|
171
|
-
return { ...
|
|
218
|
+
const e = this.grid?.gridConfig?.icons ?? {};
|
|
219
|
+
return { ...w, ...e };
|
|
220
|
+
}
|
|
221
|
+
// #region Animation Helpers
|
|
222
|
+
/**
|
|
223
|
+
* Check if animations are enabled at the grid level.
|
|
224
|
+
* Respects gridConfig.animation.mode and the CSS variable set by the grid.
|
|
225
|
+
*
|
|
226
|
+
* Plugins should use this to skip animations when:
|
|
227
|
+
* - Animation mode is 'off' or `false`
|
|
228
|
+
* - User prefers reduced motion and mode is 'reduced-motion' (default)
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* private get animationStyle(): 'slide' | 'fade' | false {
|
|
233
|
+
* if (!this.isAnimationEnabled) return false;
|
|
234
|
+
* return this.config.animation ?? 'slide';
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
get isAnimationEnabled() {
|
|
239
|
+
const e = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
|
|
240
|
+
if (e === !1 || e === "off") return !1;
|
|
241
|
+
if (e === !0 || e === "on") return !0;
|
|
242
|
+
const t = this.shadowRoot?.host;
|
|
243
|
+
return t ? getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
|
|
172
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Get the animation duration in milliseconds from CSS variable.
|
|
247
|
+
* Falls back to 200ms if not set.
|
|
248
|
+
*
|
|
249
|
+
* Plugins can use this for their animation timing to stay consistent
|
|
250
|
+
* with the grid-level animation.duration setting.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* element.animate(keyframes, { duration: this.animationDuration });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
get animationDuration() {
|
|
258
|
+
const e = this.shadowRoot?.host;
|
|
259
|
+
if (e) {
|
|
260
|
+
const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), n = parseInt(t, 10);
|
|
261
|
+
if (!isNaN(n)) return n;
|
|
262
|
+
}
|
|
263
|
+
return 200;
|
|
264
|
+
}
|
|
265
|
+
// #endregion
|
|
173
266
|
/**
|
|
174
267
|
* Resolve an icon value to string or HTMLElement.
|
|
175
268
|
* Checks plugin config first, then grid-level icons, then defaults.
|
|
@@ -178,8 +271,8 @@ class w {
|
|
|
178
271
|
* @param pluginOverride - Optional plugin-level override
|
|
179
272
|
* @returns The resolved icon value
|
|
180
273
|
*/
|
|
181
|
-
resolveIcon(
|
|
182
|
-
return
|
|
274
|
+
resolveIcon(e, t) {
|
|
275
|
+
return t !== void 0 ? t : this.gridIcons[e];
|
|
183
276
|
}
|
|
184
277
|
/**
|
|
185
278
|
* Set an icon value on an element.
|
|
@@ -188,96 +281,95 @@ class w {
|
|
|
188
281
|
* @param element - The element to set the icon on
|
|
189
282
|
* @param icon - The icon value (string or HTMLElement)
|
|
190
283
|
*/
|
|
191
|
-
setIcon(
|
|
192
|
-
typeof
|
|
284
|
+
setIcon(e, t) {
|
|
285
|
+
typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
|
|
193
286
|
}
|
|
194
287
|
/**
|
|
195
288
|
* Log a warning message.
|
|
196
289
|
*/
|
|
197
|
-
warn(
|
|
198
|
-
console.warn(`[tbw-grid:${this.name}] ${
|
|
290
|
+
warn(e) {
|
|
291
|
+
console.warn(`[tbw-grid:${this.name}] ${e}`);
|
|
199
292
|
}
|
|
200
293
|
// #endregion
|
|
201
294
|
}
|
|
202
|
-
function
|
|
295
|
+
function m(i, e = !0) {
|
|
203
296
|
if (i == null) return "";
|
|
204
297
|
if (i instanceof Date) return i.toISOString();
|
|
205
298
|
if (typeof i == "object") return JSON.stringify(i);
|
|
206
|
-
const
|
|
207
|
-
return
|
|
208
|
-
`) ||
|
|
299
|
+
const t = String(i);
|
|
300
|
+
return e && (t.includes(",") || t.includes('"') || t.includes(`
|
|
301
|
+
`) || t.includes("\r")) ? `"${t.replace(/"/g, '""')}"` : t;
|
|
209
302
|
}
|
|
210
|
-
function C(i,
|
|
211
|
-
const c =
|
|
212
|
-
`,
|
|
213
|
-
if (
|
|
214
|
-
const
|
|
215
|
-
const d =
|
|
216
|
-
return
|
|
303
|
+
function C(i, e, t, n = {}) {
|
|
304
|
+
const c = n.delimiter ?? ",", l = n.newline ?? `
|
|
305
|
+
`, o = [], r = n.bom ? "\uFEFF" : "";
|
|
306
|
+
if (t.includeHeaders !== !1) {
|
|
307
|
+
const s = e.map((a) => {
|
|
308
|
+
const d = a.header || a.field, u = t.processHeader ? t.processHeader(d, a.field) : d;
|
|
309
|
+
return m(u);
|
|
217
310
|
});
|
|
218
|
-
|
|
311
|
+
o.push(s.join(c));
|
|
219
312
|
}
|
|
220
|
-
for (const
|
|
221
|
-
const
|
|
222
|
-
let
|
|
223
|
-
return
|
|
313
|
+
for (const s of i) {
|
|
314
|
+
const a = e.map((d) => {
|
|
315
|
+
let u = s[d.field];
|
|
316
|
+
return t.processCell && (u = t.processCell(u, d.field, s)), m(u);
|
|
224
317
|
});
|
|
225
|
-
|
|
318
|
+
o.push(a.join(c));
|
|
226
319
|
}
|
|
227
|
-
return r +
|
|
320
|
+
return r + o.join(l);
|
|
228
321
|
}
|
|
229
|
-
function h(i,
|
|
230
|
-
const
|
|
231
|
-
|
|
322
|
+
function h(i, e) {
|
|
323
|
+
const t = URL.createObjectURL(i), n = document.createElement("a");
|
|
324
|
+
n.href = t, n.download = e, n.style.display = "none", document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(t);
|
|
232
325
|
}
|
|
233
|
-
function
|
|
234
|
-
const
|
|
235
|
-
h(
|
|
326
|
+
function E(i, e) {
|
|
327
|
+
const t = new Blob([i], { type: "text/csv;charset=utf-8;" });
|
|
328
|
+
h(t, e);
|
|
236
329
|
}
|
|
237
|
-
function
|
|
330
|
+
function b(i) {
|
|
238
331
|
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
239
332
|
}
|
|
240
|
-
function
|
|
241
|
-
let
|
|
333
|
+
function S(i, e, t) {
|
|
334
|
+
let n = `<?xml version="1.0" encoding="UTF-8"?>
|
|
242
335
|
<?mso-application progid="Excel.Sheet"?>
|
|
243
336
|
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
|
|
244
337
|
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
245
338
|
<Worksheet ss:Name="Sheet1">
|
|
246
339
|
<Table>`;
|
|
247
|
-
if (
|
|
248
|
-
|
|
340
|
+
if (t.includeHeaders !== !1) {
|
|
341
|
+
n += `
|
|
249
342
|
<Row>`;
|
|
250
|
-
for (const c of
|
|
251
|
-
const l = c.header || c.field,
|
|
252
|
-
|
|
343
|
+
for (const c of e) {
|
|
344
|
+
const l = c.header || c.field, o = t.processHeader ? t.processHeader(l, c.field) : l;
|
|
345
|
+
n += `<Cell><Data ss:Type="String">${b(o)}</Data></Cell>`;
|
|
253
346
|
}
|
|
254
|
-
|
|
347
|
+
n += "</Row>";
|
|
255
348
|
}
|
|
256
349
|
for (const c of i) {
|
|
257
|
-
|
|
350
|
+
n += `
|
|
258
351
|
<Row>`;
|
|
259
|
-
for (const l of
|
|
260
|
-
let
|
|
261
|
-
|
|
262
|
-
let r = "String",
|
|
263
|
-
|
|
352
|
+
for (const l of e) {
|
|
353
|
+
let o = c[l.field];
|
|
354
|
+
t.processCell && (o = t.processCell(o, l.field, c));
|
|
355
|
+
let r = "String", s = "";
|
|
356
|
+
o == null ? s = "" : typeof o == "number" && !isNaN(o) ? (r = "Number", s = String(o)) : o instanceof Date ? (r = "DateTime", s = o.toISOString()) : s = b(String(o)), n += `<Cell><Data ss:Type="${r}">${s}</Data></Cell>`;
|
|
264
357
|
}
|
|
265
|
-
|
|
358
|
+
n += "</Row>";
|
|
266
359
|
}
|
|
267
|
-
return
|
|
360
|
+
return n += `
|
|
268
361
|
</Table>
|
|
269
362
|
</Worksheet>
|
|
270
|
-
</Workbook>`,
|
|
363
|
+
</Workbook>`, n;
|
|
271
364
|
}
|
|
272
|
-
function y(i,
|
|
273
|
-
const
|
|
365
|
+
function y(i, e) {
|
|
366
|
+
const t = e.endsWith(".xls") ? e : `${e}.xls`, n = new Blob([i], {
|
|
274
367
|
type: "application/vnd.ms-excel;charset=utf-8;"
|
|
275
368
|
});
|
|
276
|
-
h(
|
|
369
|
+
h(n, t);
|
|
277
370
|
}
|
|
278
|
-
class R extends
|
|
371
|
+
class R extends x {
|
|
279
372
|
name = "export";
|
|
280
|
-
version = "1.0.0";
|
|
281
373
|
get defaultConfig() {
|
|
282
374
|
return {
|
|
283
375
|
fileName: "export",
|
|
@@ -291,59 +383,59 @@ class R extends w {
|
|
|
291
383
|
lastExportInfo = null;
|
|
292
384
|
// #endregion
|
|
293
385
|
// #region Private Methods
|
|
294
|
-
performExport(
|
|
295
|
-
const
|
|
296
|
-
format:
|
|
297
|
-
fileName:
|
|
298
|
-
includeHeaders:
|
|
299
|
-
processCell:
|
|
300
|
-
processHeader:
|
|
301
|
-
columns:
|
|
302
|
-
rowIndices:
|
|
386
|
+
performExport(e, t) {
|
|
387
|
+
const n = this.config, c = {
|
|
388
|
+
format: e,
|
|
389
|
+
fileName: t?.fileName ?? n.fileName ?? "export",
|
|
390
|
+
includeHeaders: t?.includeHeaders ?? n.includeHeaders,
|
|
391
|
+
processCell: t?.processCell,
|
|
392
|
+
processHeader: t?.processHeader,
|
|
393
|
+
columns: t?.columns,
|
|
394
|
+
rowIndices: t?.rowIndices
|
|
303
395
|
};
|
|
304
396
|
let l = [...this.columns];
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
l = l.filter((
|
|
397
|
+
if (n.onlyVisible && (l = l.filter((s) => !s.hidden && !s.field.startsWith("__"))), t?.columns) {
|
|
398
|
+
const s = new Set(t.columns);
|
|
399
|
+
l = l.filter((a) => s.has(a.field));
|
|
308
400
|
}
|
|
309
|
-
let
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
312
|
-
|
|
401
|
+
let o = [...this.rows];
|
|
402
|
+
if (n.onlySelected) {
|
|
403
|
+
const s = this.getSelectionState();
|
|
404
|
+
s?.selected?.size && (o = [...s.selected].sort((d, u) => d - u).map((d) => this.rows[d]).filter(Boolean));
|
|
313
405
|
}
|
|
314
|
-
|
|
406
|
+
t?.rowIndices && (o = t.rowIndices.map((s) => this.rows[s]).filter(Boolean)), this.isExportingFlag = !0;
|
|
315
407
|
let r = c.fileName;
|
|
316
408
|
try {
|
|
317
|
-
switch (
|
|
409
|
+
switch (e) {
|
|
318
410
|
case "csv": {
|
|
319
|
-
const
|
|
320
|
-
r = r.endsWith(".csv") ? r : `${r}.csv`,
|
|
411
|
+
const s = C(o, l, c, { bom: !0 });
|
|
412
|
+
r = r.endsWith(".csv") ? r : `${r}.csv`, E(s, r);
|
|
321
413
|
break;
|
|
322
414
|
}
|
|
323
415
|
case "excel": {
|
|
324
|
-
const
|
|
325
|
-
r = r.endsWith(".xls") ? r : `${r}.xls`, y(
|
|
416
|
+
const s = S(o, l, c);
|
|
417
|
+
r = r.endsWith(".xls") ? r : `${r}.xls`, y(s, r);
|
|
326
418
|
break;
|
|
327
419
|
}
|
|
328
420
|
case "json": {
|
|
329
|
-
const
|
|
421
|
+
const s = o.map((u) => {
|
|
330
422
|
const p = {};
|
|
331
423
|
for (const f of l) {
|
|
332
|
-
let g =
|
|
333
|
-
c.processCell && (g = c.processCell(g, f.field,
|
|
424
|
+
let g = u[f.field];
|
|
425
|
+
c.processCell && (g = c.processCell(g, f.field, u)), p[f.field] = g;
|
|
334
426
|
}
|
|
335
427
|
return p;
|
|
336
|
-
}),
|
|
428
|
+
}), a = JSON.stringify(s, null, 2);
|
|
337
429
|
r = r.endsWith(".json") ? r : `${r}.json`;
|
|
338
|
-
const d = new Blob([
|
|
430
|
+
const d = new Blob([a], { type: "application/json" });
|
|
339
431
|
h(d, r);
|
|
340
432
|
break;
|
|
341
433
|
}
|
|
342
434
|
}
|
|
343
|
-
this.lastExportInfo = { format:
|
|
344
|
-
format:
|
|
435
|
+
this.lastExportInfo = { format: e, timestamp: /* @__PURE__ */ new Date() }, this.emit("export-complete", {
|
|
436
|
+
format: e,
|
|
345
437
|
fileName: r,
|
|
346
|
-
rowCount:
|
|
438
|
+
rowCount: o.length,
|
|
347
439
|
columnCount: l.length
|
|
348
440
|
});
|
|
349
441
|
} finally {
|
|
@@ -363,22 +455,22 @@ class R extends w {
|
|
|
363
455
|
* Export data to CSV format.
|
|
364
456
|
* @param params - Optional export parameters
|
|
365
457
|
*/
|
|
366
|
-
exportCsv(
|
|
367
|
-
this.performExport("csv",
|
|
458
|
+
exportCsv(e) {
|
|
459
|
+
this.performExport("csv", e);
|
|
368
460
|
}
|
|
369
461
|
/**
|
|
370
462
|
* Export data to Excel format (XML Spreadsheet).
|
|
371
463
|
* @param params - Optional export parameters
|
|
372
464
|
*/
|
|
373
|
-
exportExcel(
|
|
374
|
-
this.performExport("excel",
|
|
465
|
+
exportExcel(e) {
|
|
466
|
+
this.performExport("excel", e);
|
|
375
467
|
}
|
|
376
468
|
/**
|
|
377
469
|
* Export data to JSON format.
|
|
378
470
|
* @param params - Optional export parameters
|
|
379
471
|
*/
|
|
380
|
-
exportJson(
|
|
381
|
-
this.performExport("json",
|
|
472
|
+
exportJson(e) {
|
|
473
|
+
this.performExport("json", e);
|
|
382
474
|
}
|
|
383
475
|
/**
|
|
384
476
|
* Check if an export is currently in progress.
|