@toolbox-web/grid-vue 0.11.2 → 0.11.3
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 +69 -22
- package/chunks/use-grid-DjGoQOoZ.js +52 -0
- package/chunks/use-grid-DjGoQOoZ.js.map +1 -0
- package/features/export.js +1 -1
- package/features/filtering.js +1 -1
- package/features/print.js +1 -1
- package/features/selection.js +1 -1
- package/features/undo-redo.js +1 -1
- package/index.js +320 -253
- package/index.js.map +1 -1
- package/lib/TbwGrid.vue.d.ts +13 -2
- package/lib/TbwGrid.vue.d.ts.map +1 -1
- package/lib/use-grid.d.ts +17 -5
- package/lib/use-grid.d.ts.map +1 -1
- package/package.json +1 -1
- package/chunks/use-grid-CeVD1azo.js +0 -28
- package/chunks/use-grid-CeVD1azo.js.map +0 -1
package/README.md
CHANGED
|
@@ -80,6 +80,20 @@ const employees = ref<Employee[]>([
|
|
|
80
80
|
</template>
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
+
## TbwGrid Props
|
|
84
|
+
|
|
85
|
+
| Prop | Type | Description |
|
|
86
|
+
| -------------- | ------------------------------------------ | ---------------------------------------------- |
|
|
87
|
+
| `rows` | `TRow[]` | Row data to display |
|
|
88
|
+
| `columns` | `ColumnConfig[]` | Column definitions |
|
|
89
|
+
| `gridConfig` | `GridConfig` | Full configuration object |
|
|
90
|
+
| `fitMode` | `'stretch' \| 'fit-columns' \| 'auto-fit'` | Column sizing mode |
|
|
91
|
+
| `sortable` | `boolean` | Grid-wide sorting toggle (default: `true`) |
|
|
92
|
+
| `filterable` | `boolean` | Grid-wide filtering toggle (default: `true`) |
|
|
93
|
+
| `selectable` | `boolean` | Grid-wide selection toggle (default: `true`) |
|
|
94
|
+
| `loading` | `boolean` | Show loading overlay (default: `false`) |
|
|
95
|
+
| `customStyles` | `string` | CSS injected via `document.adoptedStyleSheets` |
|
|
96
|
+
|
|
83
97
|
## Enabling Features
|
|
84
98
|
|
|
85
99
|
Features are enabled using **declarative props** with **side-effect imports**. This gives you the best of both worlds: clean, intuitive templates and tree-shakeable bundles.
|
|
@@ -246,17 +260,33 @@ function onSortChange(e: CustomEvent<SortChangeDetail>) {
|
|
|
246
260
|
|
|
247
261
|
### Available Events
|
|
248
262
|
|
|
249
|
-
| Event | Detail Type
|
|
250
|
-
| ---------------------- |
|
|
251
|
-
| `@cell-click` | `CellClickDetail`
|
|
252
|
-
| `@row-click` | `RowClickDetail`
|
|
253
|
-
| `@cell-
|
|
254
|
-
| `@
|
|
255
|
-
| `@cell-
|
|
256
|
-
| `@
|
|
257
|
-
| `@
|
|
258
|
-
| `@
|
|
259
|
-
| `@
|
|
263
|
+
| Event | Detail Type | Description |
|
|
264
|
+
| ---------------------- | ------------------------ | --------------------------------- |
|
|
265
|
+
| `@cell-click` | `CellClickDetail` | Cell was clicked |
|
|
266
|
+
| `@row-click` | `RowClickDetail` | Row was clicked |
|
|
267
|
+
| `@cell-activate` | `CellActivateDetail` | Cell activated (cancelable) |
|
|
268
|
+
| `@cell-change` | `CellChangeDetail` | Row updated via API |
|
|
269
|
+
| `@cell-commit` | `CellCommitDetail` | Cell value committed (cancelable) |
|
|
270
|
+
| `@row-commit` | `RowCommitDetail` | Row edit completed (cancelable) |
|
|
271
|
+
| `@changed-rows-reset` | `ChangedRowsResetDetail` | Changed rows state was reset |
|
|
272
|
+
| `@sort-change` | `SortChangeDetail` | Sort state changed |
|
|
273
|
+
| `@filter-change` | `FilterChangeDetail` | Filter state changed |
|
|
274
|
+
| `@column-resize` | `ColumnResizeDetail` | Column was resized |
|
|
275
|
+
| `@column-move` | `ColumnMoveDetail` | Column was reordered |
|
|
276
|
+
| `@column-visibility` | `ColumnVisibilityDetail` | Column visibility toggled |
|
|
277
|
+
| `@column-state-change` | `GridColumnState` | Column visibility/order changed |
|
|
278
|
+
| `@selection-change` | `SelectionChangeDetail` | Selection state changed |
|
|
279
|
+
| `@row-move` | `RowMoveDetail` | Row was reordered |
|
|
280
|
+
| `@group-toggle` | `GroupToggleDetail` | Row group expanded/collapsed |
|
|
281
|
+
| `@tree-expand` | `TreeExpandDetail` | Tree node expanded/collapsed |
|
|
282
|
+
| `@detail-expand` | `DetailExpandDetail` | Master-detail row toggled |
|
|
283
|
+
| `@responsive-change` | `ResponsiveChangeDetail` | Responsive layout mode changed |
|
|
284
|
+
| `@copy` | `CopyDetail` | Data copied to clipboard |
|
|
285
|
+
| `@paste` | `PasteDetail` | Data pasted from clipboard |
|
|
286
|
+
| `@undo-redo` | `UndoRedoDetail` | Undo/redo action performed |
|
|
287
|
+
| `@export-complete` | `ExportCompleteDetail` | Export operation completed |
|
|
288
|
+
| `@print-start` | `PrintStartDetail` | Print operation started |
|
|
289
|
+
| `@print-complete` | `PrintCompleteDetail` | Print operation completed |
|
|
260
290
|
|
|
261
291
|
## Using Plugins (Advanced)
|
|
262
292
|
|
|
@@ -287,25 +317,42 @@ const gridConfig = {
|
|
|
287
317
|
|
|
288
318
|
### useGrid
|
|
289
319
|
|
|
290
|
-
Access grid methods programmatically:
|
|
320
|
+
Access grid methods and state programmatically:
|
|
291
321
|
|
|
292
322
|
```vue
|
|
293
323
|
<script setup lang="ts">
|
|
294
324
|
import { useGrid } from '@toolbox-web/grid-vue';
|
|
295
325
|
|
|
296
|
-
const {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
326
|
+
const {
|
|
327
|
+
isReady,
|
|
328
|
+
config,
|
|
329
|
+
forceLayout,
|
|
330
|
+
getConfig,
|
|
331
|
+
ready,
|
|
332
|
+
getPlugin,
|
|
333
|
+
toggleGroup,
|
|
334
|
+
registerStyles,
|
|
335
|
+
unregisterStyles,
|
|
336
|
+
getVisibleColumns,
|
|
337
|
+
} = useGrid();
|
|
306
338
|
</script>
|
|
307
339
|
```
|
|
308
340
|
|
|
341
|
+
| Property / Method | Type | Description |
|
|
342
|
+
| ------------------------- | -------------------------------------------- | ----------------------------------------- |
|
|
343
|
+
| `isReady` | `Ref<boolean>` | Reactive flag — `true` once grid is ready |
|
|
344
|
+
| `config` | `Ref<GridConfig \| null>` | Reactive effective grid configuration |
|
|
345
|
+
| `gridElement` | `Ref<DataGridElement \| null>` | Raw grid element reference |
|
|
346
|
+
| `ready()` | `() => Promise<void>` | Wait for grid to finish initializing |
|
|
347
|
+
| `forceLayout()` | `() => Promise<void>` | Force layout recalculation |
|
|
348
|
+
| `getConfig()` | `() => GridConfig \| undefined` | Get effective configuration snapshot |
|
|
349
|
+
| `getPlugin(pluginClass)` | `<T>(cls: new (...) => T) => T \| undefined` | Get plugin by class |
|
|
350
|
+
| `getPluginByName(name)` | `(name: string) => Plugin \| undefined` | Get plugin by name |
|
|
351
|
+
| `toggleGroup(key)` | `(key: string) => Promise<void>` | Toggle group expansion |
|
|
352
|
+
| `registerStyles(id, css)` | `(id: string, css: string) => void` | Register custom stylesheet |
|
|
353
|
+
| `unregisterStyles(id)` | `(id: string) => void` | Remove custom stylesheet |
|
|
354
|
+
| `getVisibleColumns()` | `() => ColumnConfig[]` | Get non-hidden columns |
|
|
355
|
+
|
|
309
356
|
### useGridEvent
|
|
310
357
|
|
|
311
358
|
Subscribe to grid events with automatic cleanup:
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ref as i, inject as a, onMounted as l } from "vue";
|
|
2
|
+
const c = /* @__PURE__ */ Symbol("tbw-grid");
|
|
3
|
+
function d(u) {
|
|
4
|
+
const r = u ? i(null) : a(c, i(null)), o = i(!1), g = i(null), t = () => {
|
|
5
|
+
if (u) {
|
|
6
|
+
const e = document.querySelector(u);
|
|
7
|
+
return e && !r.value && (r.value = e), e;
|
|
8
|
+
}
|
|
9
|
+
return r.value;
|
|
10
|
+
};
|
|
11
|
+
return l(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const e = t();
|
|
14
|
+
if (!e) return;
|
|
15
|
+
await e.ready?.(), o.value = !0;
|
|
16
|
+
const n = await e.getConfig?.();
|
|
17
|
+
n && (g.value = n);
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}), {
|
|
21
|
+
gridElement: r,
|
|
22
|
+
isReady: o,
|
|
23
|
+
config: g,
|
|
24
|
+
forceLayout: async () => {
|
|
25
|
+
await t()?.forceLayout();
|
|
26
|
+
},
|
|
27
|
+
getConfig: () => t()?.getConfig(),
|
|
28
|
+
ready: async () => {
|
|
29
|
+
await t()?.ready();
|
|
30
|
+
},
|
|
31
|
+
getPlugin: (e) => t()?.getPlugin(e),
|
|
32
|
+
getPluginByName: ((e) => t()?.getPluginByName(e)),
|
|
33
|
+
toggleGroup: async (e) => {
|
|
34
|
+
await t()?.toggleGroup?.(e);
|
|
35
|
+
},
|
|
36
|
+
registerStyles: (e, n) => {
|
|
37
|
+
t()?.registerStyles?.(e, n);
|
|
38
|
+
},
|
|
39
|
+
unregisterStyles: (e) => {
|
|
40
|
+
t()?.unregisterStyles?.(e);
|
|
41
|
+
},
|
|
42
|
+
getVisibleColumns: () => {
|
|
43
|
+
const e = t();
|
|
44
|
+
return e ? (e.gridConfig?.columns ?? []).filter((s) => !s.hidden) : [];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
c as G,
|
|
50
|
+
d as u
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=use-grid-DjGoQOoZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-grid-DjGoQOoZ.js","sources":["../../../../libs/grid-vue/src/lib/use-grid.ts"],"sourcesContent":["import type { ColumnConfig, DataGridElement, GridConfig } from '@toolbox-web/grid';\nimport { inject, onMounted, ref, type InjectionKey, type Ref } from 'vue';\n\n/**\n * Injection key for the grid element.\n */\nexport const GRID_ELEMENT_KEY: InjectionKey<Ref<DataGridElement | null>> = Symbol('tbw-grid');\n\n/**\n * Return type for useGrid composable.\n */\nexport interface UseGridReturn<TRow = unknown> {\n /** The grid element reference */\n gridElement: Ref<DataGridElement<TRow> | null>;\n /** Whether the grid is ready */\n isReady: Ref<boolean>;\n /** Current grid configuration (reactive) */\n config: Ref<GridConfig<TRow> | null>;\n /** Force a layout recalculation */\n forceLayout: () => Promise<void>;\n /** Get current grid configuration */\n getConfig: () => ReturnType<DataGridElement['getConfig']> | undefined;\n /** Wait for grid to be ready */\n ready: () => Promise<void>;\n /** Get a plugin by its class */\n getPlugin: <T>(pluginClass: new (...args: unknown[]) => T) => T | undefined;\n /**\n * Get a plugin by its registered name (preferred).\n * Uses the type-safe PluginNameMap for auto-completion and return type narrowing.\n */\n getPluginByName: DataGridElement['getPluginByName'];\n /** Toggle a group row */\n toggleGroup: (key: string) => Promise<void>;\n /** Register custom styles via `document.adoptedStyleSheets` */\n registerStyles: (id: string, css: string) => void;\n /** Unregister previously registered custom styles */\n unregisterStyles: (id: string) => void;\n /** Get currently visible columns (excluding hidden columns) */\n getVisibleColumns: () => ColumnConfig<TRow>[];\n}\n\n/**\n * Composable for programmatic access to the grid.\n *\n * @example\n * ```vue\n * <script setup>\n * import { useGrid } from '@toolbox-web/grid-vue';\n *\n * const { forceLayout, getConfig, isReady, getVisibleColumns } = useGrid();\n *\n * async function handleResize() {\n * await forceLayout();\n * }\n * </script>\n * ```\n * @param selector - Optional CSS selector to target a specific grid element via\n * DOM query instead of using Vue's provide/inject. Use when the component\n * contains multiple grids, e.g. `'tbw-grid.primary'` or `'#my-grid'`.\n */\nexport function useGrid<TRow = unknown>(selector?: string): UseGridReturn<TRow> {\n const gridElement = selector\n ? (ref(null) as Ref<DataGridElement<TRow> | null>)\n : (inject(GRID_ELEMENT_KEY, ref(null)) as Ref<DataGridElement<TRow> | null>);\n const isReady = ref(false) as Ref<boolean>;\n const config = ref<GridConfig<TRow> | null>(null) as Ref<GridConfig<TRow> | null>;\n\n /**\n * Resolve the grid element. When a selector is provided, uses a DOM query;\n * otherwise falls back to the injected ref.\n */\n const getGrid = (): DataGridElement<TRow> | null => {\n if (selector) {\n const el = document.querySelector(selector) as DataGridElement<TRow> | null;\n if (el && !gridElement.value) gridElement.value = el;\n return el;\n }\n return gridElement.value;\n };\n\n // Track ready state\n onMounted(async () => {\n try {\n const grid = getGrid();\n if (!grid) return;\n await grid.ready?.();\n isReady.value = true;\n const effectiveConfig = await grid.getConfig?.();\n if (effectiveConfig) {\n config.value = effectiveConfig as GridConfig<TRow>;\n }\n } catch {\n // Grid may not be available yet\n }\n });\n\n return {\n gridElement,\n isReady,\n config,\n forceLayout: async () => {\n await getGrid()?.forceLayout();\n },\n getConfig: () => {\n return getGrid()?.getConfig();\n },\n ready: async () => {\n await getGrid()?.ready();\n },\n getPlugin: <T>(pluginClass: new (...args: unknown[]) => T) => {\n return getGrid()?.getPlugin(pluginClass);\n },\n getPluginByName: ((name: string) => {\n return getGrid()?.getPluginByName(name);\n }) as DataGridElement['getPluginByName'],\n toggleGroup: async (key: string) => {\n const grid = getGrid() as DataGridElement<TRow> & { toggleGroup?: (key: string) => Promise<void> };\n await grid?.toggleGroup?.(key);\n },\n registerStyles: (id: string, css: string) => {\n getGrid()?.registerStyles?.(id, css);\n },\n unregisterStyles: (id: string) => {\n getGrid()?.unregisterStyles?.(id);\n },\n getVisibleColumns: () => {\n const grid = getGrid();\n if (!grid) return [];\n const cfg = grid.gridConfig;\n const columns = cfg?.columns ?? [];\n return columns.filter((col: ColumnConfig<TRow>) => !col.hidden) as ColumnConfig<TRow>[];\n },\n };\n}\n"],"names":["GRID_ELEMENT_KEY","useGrid","selector","gridElement","ref","inject","isReady","config","getGrid","el","onMounted","grid","effectiveConfig","pluginClass","name","key","id","css","col"],"mappings":";AAMO,MAAMA,2BAAqE,UAAU;AAsDrF,SAASC,EAAwBC,GAAwC;AAC9E,QAAMC,IAAcD,IACfE,EAAI,IAAI,IACRC,EAAOL,GAAkBI,EAAI,IAAI,CAAC,GACjCE,IAAUF,EAAI,EAAK,GACnBG,IAASH,EAA6B,IAAI,GAM1CI,IAAU,M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@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref as i, inject as l } from "vue";
|
|
2
|
-
import { G as p } from "../chunks/use-grid-
|
|
2
|
+
import { G as p } from "../chunks/use-grid-DjGoQOoZ.js";
|
|
3
3
|
import "@toolbox-web/grid/features/export";
|
|
4
4
|
function E(n) {
|
|
5
5
|
const x = n ? i(null) : l(p, i(null)), o = () => (n ? document.querySelector(n) : x.value)?.getPluginByName("export");
|
package/features/filtering.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FilteringPlugin as o } from "@toolbox-web/grid/plugins/filtering";
|
|
2
2
|
import { ref as u, inject as d, createApp as f } from "vue";
|
|
3
3
|
import { registerFeature as s } from "@toolbox-web/grid/features/registry";
|
|
4
|
-
import { G as a } from "../chunks/use-grid-
|
|
4
|
+
import { G as a } from "../chunks/use-grid-DjGoQOoZ.js";
|
|
5
5
|
s("filtering", (r) => {
|
|
6
6
|
if (r === !0)
|
|
7
7
|
return new o();
|
package/features/print.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref as e, inject as u } from "vue";
|
|
2
|
-
import { G as g } from "../chunks/use-grid-
|
|
2
|
+
import { G as g } from "../chunks/use-grid-DjGoQOoZ.js";
|
|
3
3
|
import "@toolbox-web/grid/features/print";
|
|
4
4
|
function d(n) {
|
|
5
5
|
const o = n ? e(null) : u(g, e(null)), i = () => (n ? document.querySelector(n) : o.value)?.getPluginByName("print");
|
package/features/selection.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref as u, inject as d } from "vue";
|
|
2
|
-
import { G as a } from "../chunks/use-grid-
|
|
2
|
+
import { G as a } from "../chunks/use-grid-DjGoQOoZ.js";
|
|
3
3
|
import "@toolbox-web/grid/features/selection";
|
|
4
4
|
function S(r) {
|
|
5
5
|
const g = r ? u(null) : d(a, u(null)), i = () => r ? document.querySelector(r) : g.value, t = () => i()?.getPluginByName("selection");
|
package/features/undo-redo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref as i, inject as c } from "vue";
|
|
2
|
-
import { G as g } from "../chunks/use-grid-
|
|
2
|
+
import { G as g } from "../chunks/use-grid-DjGoQOoZ.js";
|
|
3
3
|
import "@toolbox-web/grid/features/undo-redo";
|
|
4
4
|
function s(d) {
|
|
5
5
|
const r = d ? i(null) : c(g, i(null)), o = () => (d ? document.querySelector(d) : r.value)?.getPluginByName("undoRedo");
|