@toolbox-web/grid-vue 0.11.0 → 0.11.1
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/features/filtering.d.ts +16 -4
- package/features/filtering.d.ts.map +1 -1
- package/features/filtering.js +25 -25
- package/features/filtering.js.map +1 -1
- package/package.json +1 -1
package/features/filtering.d.ts
CHANGED
|
@@ -7,8 +7,11 @@ export interface FilteringMethods {
|
|
|
7
7
|
* Set a filter on a specific field.
|
|
8
8
|
* @param field - The field name to filter
|
|
9
9
|
* @param filter - Filter configuration, or null to remove
|
|
10
|
+
* @param options - `{ silent: true }` applies the filter without emitting `filter-change`
|
|
10
11
|
*/
|
|
11
|
-
setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null
|
|
12
|
+
setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null, options?: {
|
|
13
|
+
silent?: boolean;
|
|
14
|
+
}) => void;
|
|
12
15
|
/**
|
|
13
16
|
* Get the current filter for a field.
|
|
14
17
|
*/
|
|
@@ -19,16 +22,25 @@ export interface FilteringMethods {
|
|
|
19
22
|
getFilters: () => FilterModel[];
|
|
20
23
|
/**
|
|
21
24
|
* Set all filters at once (replaces existing).
|
|
25
|
+
* @param options - `{ silent: true }` applies filters without emitting `filter-change`
|
|
22
26
|
*/
|
|
23
|
-
setFilterModel: (filters: FilterModel[]
|
|
27
|
+
setFilterModel: (filters: FilterModel[], options?: {
|
|
28
|
+
silent?: boolean;
|
|
29
|
+
}) => void;
|
|
24
30
|
/**
|
|
25
31
|
* Clear all active filters.
|
|
32
|
+
* @param options - `{ silent: true }` clears filters without emitting `filter-change`
|
|
26
33
|
*/
|
|
27
|
-
clearAllFilters: (
|
|
34
|
+
clearAllFilters: (options?: {
|
|
35
|
+
silent?: boolean;
|
|
36
|
+
}) => void;
|
|
28
37
|
/**
|
|
29
38
|
* Clear filter for a specific field.
|
|
39
|
+
* @param options - `{ silent: true }` clears filter without emitting `filter-change`
|
|
30
40
|
*/
|
|
31
|
-
clearFieldFilter: (field: string
|
|
41
|
+
clearFieldFilter: (field: string, options?: {
|
|
42
|
+
silent?: boolean;
|
|
43
|
+
}) => void;
|
|
32
44
|
/**
|
|
33
45
|
* Check if a field has an active filter.
|
|
34
46
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../../libs/grid-vue/src/features/filtering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,WAAW,EAEjB,MAAM,qCAAqC,CAAC;AAqC7C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../../libs/grid-vue/src/features/filtering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,WAAW,EAEjB,MAAM,qCAAqC,CAAC;AAqC7C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAE9G;;OAEG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;IAEtD;;OAEG;IACH,UAAU,EAAE,MAAM,WAAW,EAAE,CAAC;IAEhC;;;OAGG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAEjF;;;OAGG;IACH,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAE1D;;;OAGG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAE1E;;OAEG;IACH,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAE5C;;OAEG;IACH,mBAAmB,EAAE,MAAM,MAAM,CAAC;IAElC;;OAEG;IACH,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EAAE,CAAC;IAE9C;;OAEG;IACH,eAAe,EAAE,MAAM,WAAW,EAAE,CAAC;IAErC;;OAEG;IACH,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAE3C;;OAEG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CAC7D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,CAwFnD"}
|
package/features/filtering.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { FilteringPlugin as
|
|
1
|
+
import { FilteringPlugin as o } from "@toolbox-web/grid/plugins/filtering";
|
|
2
2
|
import { inject as d, ref as u, createApp as f } from "vue";
|
|
3
3
|
import { registerFeature as s } from "@toolbox-web/grid/features/registry";
|
|
4
4
|
import { G as a } from "../chunks/use-grid-B59B6XdD.js";
|
|
5
5
|
s("filtering", (r) => {
|
|
6
6
|
if (r === !0)
|
|
7
|
-
return new
|
|
7
|
+
return new o();
|
|
8
8
|
if (!r)
|
|
9
|
-
return new
|
|
9
|
+
return new o();
|
|
10
10
|
const t = r, e = { ...t };
|
|
11
11
|
if (typeof t.filterPanelRenderer == "function" && t.filterPanelRenderer.length <= 1) {
|
|
12
12
|
const i = t.filterPanelRenderer;
|
|
13
|
-
e.filterPanelRenderer = (n,
|
|
14
|
-
const
|
|
15
|
-
|
|
13
|
+
e.filterPanelRenderer = (n, l) => {
|
|
14
|
+
const g = document.createElement("div");
|
|
15
|
+
g.style.display = "contents", f({
|
|
16
16
|
render() {
|
|
17
|
-
return i(
|
|
17
|
+
return i(l);
|
|
18
18
|
}
|
|
19
|
-
}).mount(
|
|
19
|
+
}).mount(g), n.appendChild(g);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
return new
|
|
22
|
+
return new o(e);
|
|
23
23
|
});
|
|
24
24
|
function m() {
|
|
25
25
|
const r = d(a, u(null)), t = () => r.value?.getPluginByName("filtering");
|
|
26
26
|
return {
|
|
27
|
-
setFilter: (e, i) => {
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
27
|
+
setFilter: (e, i, n) => {
|
|
28
|
+
const l = t();
|
|
29
|
+
if (!l) {
|
|
30
30
|
console.warn(
|
|
31
31
|
`[tbw-grid:filtering] FilteringPlugin not found.
|
|
32
32
|
|
|
@@ -35,13 +35,13 @@ function m() {
|
|
|
35
35
|
);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
l.setFilter(e, i, n);
|
|
39
39
|
},
|
|
40
40
|
getFilter: (e) => t()?.getFilter(e),
|
|
41
41
|
getFilters: () => t()?.getFilters() ?? [],
|
|
42
|
-
setFilterModel: (e) => {
|
|
43
|
-
const
|
|
44
|
-
if (!
|
|
42
|
+
setFilterModel: (e, i) => {
|
|
43
|
+
const n = t();
|
|
44
|
+
if (!n) {
|
|
45
45
|
console.warn(
|
|
46
46
|
`[tbw-grid:filtering] FilteringPlugin not found.
|
|
47
47
|
|
|
@@ -50,11 +50,11 @@ function m() {
|
|
|
50
50
|
);
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
n.setFilterModel(e, i);
|
|
54
54
|
},
|
|
55
|
-
clearAllFilters: () => {
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
55
|
+
clearAllFilters: (e) => {
|
|
56
|
+
const i = t();
|
|
57
|
+
if (!i) {
|
|
58
58
|
console.warn(
|
|
59
59
|
`[tbw-grid:filtering] FilteringPlugin not found.
|
|
60
60
|
|
|
@@ -63,11 +63,11 @@ function m() {
|
|
|
63
63
|
);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
i.clearAllFilters(e);
|
|
67
67
|
},
|
|
68
|
-
clearFieldFilter: (e) => {
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
68
|
+
clearFieldFilter: (e, i) => {
|
|
69
|
+
const n = t();
|
|
70
|
+
if (!n) {
|
|
71
71
|
console.warn(
|
|
72
72
|
`[tbw-grid:filtering] FilteringPlugin not found.
|
|
73
73
|
|
|
@@ -76,7 +76,7 @@ function m() {
|
|
|
76
76
|
);
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
n.clearFieldFilter(e, i);
|
|
80
80
|
},
|
|
81
81
|
isFieldFiltered: (e) => t()?.isFieldFiltered(e) ?? !1,
|
|
82
82
|
getFilteredRowCount: () => t()?.getFilteredRowCount() ?? 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.js","sources":["../../../../libs/grid-vue/src/features/filtering.ts"],"sourcesContent":["/**\n * Filtering feature for @toolbox-web/grid-vue\n *\n * Import this module to enable the `filtering` prop on TbwGrid.\n * Also exports `useGridFiltering()` composable for programmatic filter control.\n *\n * @example\n * ```vue\n * <script setup>\n * import '@toolbox-web/grid-vue/features/filtering';\n * </script>\n *\n * <template>\n * <TbwGrid filtering />\n * </template>\n * ```\n *\n * @example Using the composable\n * ```vue\n * <script setup>\n * import { useGridFiltering } from '@toolbox-web/grid-vue/features/filtering';\n *\n * const { setFilter, clearAllFilters, getFilteredRowCount } = useGridFiltering();\n *\n * function filterByStatus(status: string) {\n * setFilter('status', { operator: 'equals', value: status });\n * }\n * </script>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { DataGridElement } from '@toolbox-web/grid';\nimport {\n FilteringPlugin,\n type BlankMode,\n type FilterConfig,\n type FilterModel,\n type FilterPanelParams,\n} from '@toolbox-web/grid/plugins/filtering';\nimport { createApp, inject, ref, type VNode } from 'vue';\nimport { registerFeature } from '../lib/feature-registry';\nimport { GRID_ELEMENT_KEY } from '../lib/use-grid';\n\nregisterFeature('filtering', (rawConfig) => {\n if (rawConfig === true) {\n return new FilteringPlugin();\n }\n if (!rawConfig) {\n return new FilteringPlugin();\n }\n\n const config = rawConfig as FilterConfig & { filterPanelRenderer?: unknown };\n const options = { ...config } as FilterConfig;\n\n // Bridge Vue filterPanelRenderer (1 arg: params → VNode) to vanilla (2 args: container, params)\n if (typeof config.filterPanelRenderer === 'function' && config.filterPanelRenderer.length <= 1) {\n const vueFn = config.filterPanelRenderer as unknown as (params: FilterPanelParams) => VNode;\n options.filterPanelRenderer = (container: HTMLElement, params: FilterPanelParams) => {\n const wrapper = document.createElement('div');\n wrapper.style.display = 'contents';\n\n const app = createApp({\n render() {\n return vueFn(params);\n },\n });\n\n app.mount(wrapper);\n container.appendChild(wrapper);\n };\n }\n\n return new FilteringPlugin(options);\n});\n\n/**\n * Filtering methods returned from useGridFiltering.\n */\nexport interface FilteringMethods {\n /**\n * Set a filter on a specific field.\n * @param field - The field name to filter\n * @param filter - Filter configuration, or null to remove\n */\n setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null) => void;\n\n /**\n * Get the current filter for a field.\n */\n getFilter: (field: string) => FilterModel | undefined;\n\n /**\n * Get all active filters.\n */\n getFilters: () => FilterModel[];\n\n /**\n * Set all filters at once (replaces existing).\n */\n setFilterModel: (filters: FilterModel[]) => void;\n\n /**\n * Clear all active filters.\n */\n clearAllFilters: () => void;\n\n /**\n * Clear filter for a specific field.\n */\n clearFieldFilter: (field: string) => void;\n\n /**\n * Check if a field has an active filter.\n */\n isFieldFiltered: (field: string) => boolean;\n\n /**\n * Get the count of rows after filtering.\n */\n getFilteredRowCount: () => number;\n\n /**\n * Get unique values for a field (for building filter dropdowns).\n */\n getUniqueValues: (field: string) => unknown[];\n\n /**\n * Get set filters whose values no longer match any rows in the current data.\n */\n getStaleFilters: () => FilterModel[];\n\n /**\n * Get the current blank mode for a field.\n */\n getBlankMode: (field: string) => BlankMode;\n\n /**\n * Toggle blank filter mode for a field.\n */\n toggleBlankFilter: (field: string, mode: BlankMode) => void;\n}\n\n/**\n * Composable for programmatic filter control.\n *\n * Must be used within a component that contains a TbwGrid with filtering enabled.\n *\n * @example\n * ```vue\n * <script setup>\n * import { useGridFiltering } from '@toolbox-web/grid-vue/features/filtering';\n *\n * const { setFilter, clearAllFilters, getFilteredRowCount, isFieldFiltered } = useGridFiltering();\n *\n * function applyQuickFilter(field: string, value: string) {\n * setFilter(field, { operator: 'contains', value });\n * }\n * </script>\n *\n * <template>\n * <input @input=\"applyQuickFilter('name', $event.target.value)\" placeholder=\"Filter by name...\" />\n * <span>{{ getFilteredRowCount() }} results</span>\n * <button @click=\"clearAllFilters\">Clear Filters</button>\n * </template>\n * ```\n */\nexport function useGridFiltering(): FilteringMethods {\n const gridElement = inject(GRID_ELEMENT_KEY, ref(null));\n\n const getPlugin = (): FilteringPlugin | undefined => {\n const grid = gridElement.value as DataGridElement | null;\n return grid?.getPluginByName('filtering');\n };\n\n return {\n setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.setFilter(field, filter);\n },\n\n getFilter: (field: string) => getPlugin()?.getFilter(field),\n\n getFilters: () => getPlugin()?.getFilters() ?? [],\n\n setFilterModel: (filters: FilterModel[]) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.setFilterModel(filters);\n },\n\n clearAllFilters: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.clearAllFilters();\n },\n\n clearFieldFilter: (field: string) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.clearFieldFilter(field);\n },\n\n isFieldFiltered: (field: string) => getPlugin()?.isFieldFiltered(field) ?? false,\n\n getFilteredRowCount: () => getPlugin()?.getFilteredRowCount() ?? 0,\n\n getUniqueValues: (field: string) => getPlugin()?.getUniqueValues(field) ?? [],\n\n getStaleFilters: () => getPlugin()?.getStaleFilters() ?? [],\n\n getBlankMode: (field: string): BlankMode => getPlugin()?.getBlankMode(field) ?? 'all',\n\n toggleBlankFilter: (field: string, mode: BlankMode) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.toggleBlankFilter(field, mode);\n },\n };\n}\n"],"names":["registerFeature","rawConfig","FilteringPlugin","config","options","vueFn","container","params","wrapper","createApp","useGridFiltering","gridElement","inject","GRID_ELEMENT_KEY","ref","getPlugin","field","filter","plugin","filters","mode"],"mappings":";;;;AA6CAA,EAAgB,aAAa,CAACC,MAAc;AAC1C,MAAIA,MAAc;AAChB,WAAO,IAAIC,EAAA;AAEb,MAAI,CAACD;AACH,WAAO,IAAIC,EAAA;AAGb,QAAMC,IAASF,GACTG,IAAU,EAAE,GAAGD,EAAA;AAGrB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gBAAA;AAAA,IACT;AAAA,IAEA,kBAAkB,CAACF,MAAkB;AACnC,YAAME,IAASH,EAAA;AACf,UAAI,CAACG,GAAQ;AACX,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA;AAAA,QAAA;AAIF;AAAA,MACF;AACA,MAAAA,EAAO,iBAAiBF,CAAK;AAAA,IAC/B;AAAA,IAEA,iBAAiB,CAACA,MAAkBD,KAAa,gBAAgBC,CAAK,KAAK;AAAA,IAE3E,qBAAqB,MAAMD,KAAa,yBAAyB;AAAA,IAEjE,iBAAiB,CAACC,MAAkBD,EAAA,GAAa,gBAAgBC,CAAK,KAAK,CAAA;AAAA,IAE3E,iBAAiB,MAAMD,KAAa,gBAAA,KAAqB,CAAA;AAAA,IAEzD,cAAc,CAACC,MAA6BD,KAAa,aAAaC,CAAK,KAAK;AAAA,IAEhF,mBAAmB,CAACA,GAAeI,MAAoB;AACrD,YAAMF,IAASH,EAAA;AACf,UAAI,CAACG,GAAQ;AACX,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA;AAAA,QAAA;AAIF;AAAA,MACF;AACA,MAAAA,EAAO,kBAAkBF,GAAOI,CAAI;AAAA,IACtC;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"filtering.js","sources":["../../../../libs/grid-vue/src/features/filtering.ts"],"sourcesContent":["/**\n * Filtering feature for @toolbox-web/grid-vue\n *\n * Import this module to enable the `filtering` prop on TbwGrid.\n * Also exports `useGridFiltering()` composable for programmatic filter control.\n *\n * @example\n * ```vue\n * <script setup>\n * import '@toolbox-web/grid-vue/features/filtering';\n * </script>\n *\n * <template>\n * <TbwGrid filtering />\n * </template>\n * ```\n *\n * @example Using the composable\n * ```vue\n * <script setup>\n * import { useGridFiltering } from '@toolbox-web/grid-vue/features/filtering';\n *\n * const { setFilter, clearAllFilters, getFilteredRowCount } = useGridFiltering();\n *\n * function filterByStatus(status: string) {\n * setFilter('status', { operator: 'equals', value: status });\n * }\n * </script>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { DataGridElement } from '@toolbox-web/grid';\nimport {\n FilteringPlugin,\n type BlankMode,\n type FilterConfig,\n type FilterModel,\n type FilterPanelParams,\n} from '@toolbox-web/grid/plugins/filtering';\nimport { createApp, inject, ref, type VNode } from 'vue';\nimport { registerFeature } from '../lib/feature-registry';\nimport { GRID_ELEMENT_KEY } from '../lib/use-grid';\n\nregisterFeature('filtering', (rawConfig) => {\n if (rawConfig === true) {\n return new FilteringPlugin();\n }\n if (!rawConfig) {\n return new FilteringPlugin();\n }\n\n const config = rawConfig as FilterConfig & { filterPanelRenderer?: unknown };\n const options = { ...config } as FilterConfig;\n\n // Bridge Vue filterPanelRenderer (1 arg: params → VNode) to vanilla (2 args: container, params)\n if (typeof config.filterPanelRenderer === 'function' && config.filterPanelRenderer.length <= 1) {\n const vueFn = config.filterPanelRenderer as unknown as (params: FilterPanelParams) => VNode;\n options.filterPanelRenderer = (container: HTMLElement, params: FilterPanelParams) => {\n const wrapper = document.createElement('div');\n wrapper.style.display = 'contents';\n\n const app = createApp({\n render() {\n return vueFn(params);\n },\n });\n\n app.mount(wrapper);\n container.appendChild(wrapper);\n };\n }\n\n return new FilteringPlugin(options);\n});\n\n/**\n * Filtering methods returned from useGridFiltering.\n */\nexport interface FilteringMethods {\n /**\n * Set a filter on a specific field.\n * @param field - The field name to filter\n * @param filter - Filter configuration, or null to remove\n * @param options - `{ silent: true }` applies the filter without emitting `filter-change`\n */\n setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null, options?: { silent?: boolean }) => void;\n\n /**\n * Get the current filter for a field.\n */\n getFilter: (field: string) => FilterModel | undefined;\n\n /**\n * Get all active filters.\n */\n getFilters: () => FilterModel[];\n\n /**\n * Set all filters at once (replaces existing).\n * @param options - `{ silent: true }` applies filters without emitting `filter-change`\n */\n setFilterModel: (filters: FilterModel[], options?: { silent?: boolean }) => void;\n\n /**\n * Clear all active filters.\n * @param options - `{ silent: true }` clears filters without emitting `filter-change`\n */\n clearAllFilters: (options?: { silent?: boolean }) => void;\n\n /**\n * Clear filter for a specific field.\n * @param options - `{ silent: true }` clears filter without emitting `filter-change`\n */\n clearFieldFilter: (field: string, options?: { silent?: boolean }) => void;\n\n /**\n * Check if a field has an active filter.\n */\n isFieldFiltered: (field: string) => boolean;\n\n /**\n * Get the count of rows after filtering.\n */\n getFilteredRowCount: () => number;\n\n /**\n * Get unique values for a field (for building filter dropdowns).\n */\n getUniqueValues: (field: string) => unknown[];\n\n /**\n * Get set filters whose values no longer match any rows in the current data.\n */\n getStaleFilters: () => FilterModel[];\n\n /**\n * Get the current blank mode for a field.\n */\n getBlankMode: (field: string) => BlankMode;\n\n /**\n * Toggle blank filter mode for a field.\n */\n toggleBlankFilter: (field: string, mode: BlankMode) => void;\n}\n\n/**\n * Composable for programmatic filter control.\n *\n * Must be used within a component that contains a TbwGrid with filtering enabled.\n *\n * @example\n * ```vue\n * <script setup>\n * import { useGridFiltering } from '@toolbox-web/grid-vue/features/filtering';\n *\n * const { setFilter, clearAllFilters, getFilteredRowCount, isFieldFiltered } = useGridFiltering();\n *\n * function applyQuickFilter(field: string, value: string) {\n * setFilter(field, { operator: 'contains', value });\n * }\n * </script>\n *\n * <template>\n * <input @input=\"applyQuickFilter('name', $event.target.value)\" placeholder=\"Filter by name...\" />\n * <span>{{ getFilteredRowCount() }} results</span>\n * <button @click=\"clearAllFilters\">Clear Filters</button>\n * </template>\n * ```\n */\nexport function useGridFiltering(): FilteringMethods {\n const gridElement = inject(GRID_ELEMENT_KEY, ref(null));\n\n const getPlugin = (): FilteringPlugin | undefined => {\n const grid = gridElement.value as DataGridElement | null;\n return grid?.getPluginByName('filtering');\n };\n\n return {\n setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null, options?: { silent?: boolean }) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.setFilter(field, filter, options);\n },\n\n getFilter: (field: string) => getPlugin()?.getFilter(field),\n\n getFilters: () => getPlugin()?.getFilters() ?? [],\n\n setFilterModel: (filters: FilterModel[], options?: { silent?: boolean }) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.setFilterModel(filters, options);\n },\n\n clearAllFilters: (options?: { silent?: boolean }) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.clearAllFilters(options);\n },\n\n clearFieldFilter: (field: string, options?: { silent?: boolean }) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.clearFieldFilter(field, options);\n },\n\n isFieldFiltered: (field: string) => getPlugin()?.isFieldFiltered(field) ?? false,\n\n getFilteredRowCount: () => getPlugin()?.getFilteredRowCount() ?? 0,\n\n getUniqueValues: (field: string) => getPlugin()?.getUniqueValues(field) ?? [],\n\n getStaleFilters: () => getPlugin()?.getStaleFilters() ?? [],\n\n getBlankMode: (field: string): BlankMode => getPlugin()?.getBlankMode(field) ?? 'all',\n\n toggleBlankFilter: (field: string, mode: BlankMode) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:filtering] FilteringPlugin not found.\\n\\n` +\n ` → Enable filtering on the grid:\\n` +\n ` <TbwGrid filtering />`,\n );\n return;\n }\n plugin.toggleBlankFilter(field, mode);\n },\n };\n}\n"],"names":["registerFeature","rawConfig","FilteringPlugin","config","options","vueFn","container","params","wrapper","createApp","useGridFiltering","gridElement","inject","GRID_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