@xleddyl/443-components-vue 0.16.70 → 0.16.72

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.
Files changed (76) hide show
  1. package/CATALOG.md +130 -127
  2. package/README.md +71 -16
  3. package/dist/components/core/Button.vue +67 -5
  4. package/dist/components/core/Button.vue.d.ts +9 -4
  5. package/dist/components/core/Form.vue +8 -2
  6. package/dist/components/core/Form.vue.d.ts +1 -0
  7. package/dist/components/core/Input.vue.d.ts +2 -2
  8. package/dist/components/data/RecordList.vue +29 -7
  9. package/dist/components/forms/ColorInput.vue.d.ts +2 -2
  10. package/dist/components/forms/DateInput.vue.d.ts +2 -2
  11. package/dist/components/forms/Fieldset.vue +16 -2
  12. package/dist/components/forms/Fieldset.vue.d.ts +3 -3
  13. package/dist/components/forms/NumberInput.vue.d.ts +2 -2
  14. package/dist/components/forms/PaletteSelect.vue.d.ts +4 -4
  15. package/dist/components/forms/PasswordInput.vue.d.ts +2 -2
  16. package/dist/components/forms/PinInput.vue.d.ts +2 -2
  17. package/dist/components/forms/Slider.vue.d.ts +2 -2
  18. package/dist/components/forms/TimeInput.vue.d.ts +2 -2
  19. package/dist/components/layout/Tabs.vue +10 -1
  20. package/dist/components/layout/ThemeSwitch.vue.d.ts +4 -0
  21. package/dist/components/overlays/CommandButton.vue +1 -0
  22. package/dist/components/overlays/ConfirmDialog.vue.d.ts +8 -2
  23. package/dist/components/overlays/ConfirmHost.vue.d.ts +8 -2
  24. package/dist/components/overlays/ContextMenu.vue.d.ts +2 -2
  25. package/dist/components/overlays/Drawer.vue +9 -1
  26. package/dist/components/overlays/Drawer.vue.d.ts +9 -0
  27. package/dist/components/overlays/Modal.vue +8 -0
  28. package/dist/components/overlays/Modal.vue.d.ts +9 -0
  29. package/dist/components/overlays/Tooltip.vue +3 -1
  30. package/dist/components/overlays/types.d.ts +2 -0
  31. package/dist/components/templates/AuthLogin.vue +4 -2
  32. package/dist/components/templates/FormDrawer.vue +18 -34
  33. package/dist/components/templates/FormDrawer.vue.d.ts +8 -1
  34. package/dist/components/templates/FormModal.vue +156 -0
  35. package/dist/components/templates/FormModal.vue.d.ts +306 -0
  36. package/dist/components/templates/FormPage.vue +1 -0
  37. package/dist/components/templates/SettingsModal.vue +61 -7
  38. package/dist/components/templates/SettingsModal.vue.d.ts +7 -0
  39. package/dist/components/templates/index.d.ts +1 -0
  40. package/dist/components/templates/index.mjs +1 -0
  41. package/dist/components/templates/types.d.ts +4 -2
  42. package/dist/composables/templates.d.ts +1 -0
  43. package/dist/composables/templates.mjs +1 -0
  44. package/dist/composables/useConfirm.mjs +11 -8
  45. package/dist/composables/useDirtyGuard.mjs +7 -47
  46. package/dist/composables/useForm.d.ts +4 -0
  47. package/dist/composables/useForm.mjs +9 -1
  48. package/dist/composables/useLeaveGuard.d.ts +19 -0
  49. package/dist/composables/useLeaveGuard.mjs +52 -0
  50. package/dist/composables/useRouteRecord.mjs +6 -5
  51. package/dist/grid/DataGrid.vue +170 -8
  52. package/dist/grid/DataGrid.vue.d.ts +8 -23
  53. package/dist/grid/cells/ButtonCell.vue +21 -1
  54. package/dist/grid/cells/ButtonCell.vue.d.ts +4 -0
  55. package/dist/grid/data-grid.css +7 -1
  56. package/dist/grid/types.d.ts +12 -0
  57. package/dist/internal/forms/form-overlay.d.ts +25 -0
  58. package/dist/internal/forms/form-overlay.mjs +31 -0
  59. package/dist/internal/forms/leave.d.ts +30 -0
  60. package/dist/internal/forms/leave.mjs +135 -0
  61. package/dist/internal/keys.d.ts +1 -0
  62. package/dist/internal/keys.mjs +1 -0
  63. package/dist/internal/layout/query.d.ts +4 -0
  64. package/dist/internal/layout/query.mjs +3 -0
  65. package/dist/internal/overlays/DialogFrame.vue +43 -5
  66. package/dist/internal/overlays/DialogFrame.vue.d.ts +11 -1
  67. package/dist/internal/overlays/HintTooltip.vue +65 -0
  68. package/dist/internal/overlays/HintTooltip.vue.d.ts +402 -0
  69. package/dist/internal/overlays/MenuList.vue +21 -0
  70. package/dist/internal/overlays/OverlayView.vue.d.ts +10 -4
  71. package/dist/styles/data/record-list.css +31 -1
  72. package/dist/styles/forms/fieldset.css +8 -0
  73. package/dist/styles/overlays/tooltip.css +11 -0
  74. package/dist/styles/templates/form-modal.css +16 -0
  75. package/dist/styles/templates.css +1 -0
  76. package/package.json +1 -1
@@ -89,8 +89,8 @@
89
89
 
90
90
  <div v-if="showFooter" class="k-data-grid-footer">
91
91
  <span class="k-data-grid-footer-info" aria-live="polite">
92
- <template v-if="selectedCount > 0">{{
93
- formatLocaleMessage(locale.code, text.selected, { count: selectedCount })
92
+ <template v-if="footerSelectedCount > 0">{{
93
+ formatLocaleMessage(locale.code, text.selected, { count: footerSelectedCount })
94
94
  }}</template>
95
95
  </span>
96
96
  <Pagination
@@ -117,7 +117,17 @@
117
117
 
118
118
  <script setup>
119
119
  import { AgGridVue } from "ag-grid-vue3";
120
- import { computed, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
120
+ import {
121
+ computed,
122
+ getCurrentInstance,
123
+ nextTick,
124
+ onBeforeUnmount,
125
+ onMounted,
126
+ ref,
127
+ shallowRef,
128
+ warn,
129
+ watch
130
+ } from "vue";
121
131
  import Pagination from "../components/data/Pagination.vue";
122
132
  import Spinner from "../components/core/Spinner.vue";
123
133
  import { useCopy } from "../composables/useCopy";
@@ -147,6 +157,7 @@ const props = defineProps({
147
157
  storageKey: { type: String, required: false },
148
158
  density: { type: String, required: false, default: void 0 },
149
159
  selectable: { type: [Boolean, String], required: false, default: false },
160
+ keepHiddenSelected: { type: Boolean, required: false },
150
161
  loading: { type: Boolean, required: false },
151
162
  height: { type: String, required: false, default: "28rem" },
152
163
  fill: { type: Boolean, required: false },
@@ -187,6 +198,7 @@ const query = defineModel("query", { type: String, ...{ default: "" } });
187
198
  const page = defineModel("page", { type: Number, ...{ default: 1 } });
188
199
  const pageSize = defineModel("pageSize", { type: [Number, String], ...{ default: 25 } });
189
200
  const sort = defineModel("sort", { type: null, ...{ default: void 0 } });
201
+ const selected = defineModel("selected", { type: Array });
190
202
  if (props.filterable) registerGridFilterModules();
191
203
  function hasEditableColumn() {
192
204
  return props.editable || props.spreadsheet || Boolean(props.gridOptions?.defaultColDef?.editable) || props.columns.some((column) => Boolean(column.editable));
@@ -250,6 +262,9 @@ const theme = computed(
250
262
  const mounted = ref(false);
251
263
  const api = shallowRef(null);
252
264
  const selectedCount = ref(0);
265
+ const footerSelectedCount = computed(
266
+ () => props.serverPagination && selected.value ? selected.value.length : selectedCount.value
267
+ );
253
268
  const clientTotal = ref(0);
254
269
  const clientPageCount = ref(1);
255
270
  const { copied, copy } = useCopy();
@@ -314,9 +329,12 @@ const loadingTemplate = computed(
314
329
  );
315
330
  const gridRowSelection = computed(() => {
316
331
  if (!props.selectable) return props.gridOptions?.rowSelection;
332
+ if (props.selectable === "single")
333
+ return { mode: "singleRow", enableClickSelection: false };
317
334
  return {
318
- mode: props.selectable === "single" ? "singleRow" : "multiRow",
319
- enableClickSelection: false
335
+ mode: "multiRow",
336
+ enableClickSelection: false,
337
+ selectAll: "filtered"
320
338
  };
321
339
  });
322
340
  const defaultColDef = computed(() => ({
@@ -425,6 +443,7 @@ function onGridReady(event) {
425
443
  if (stored?.length) event.api.applyColumnState({ state: stored, applyOrder: true });
426
444
  applySort();
427
445
  syncPagination();
446
+ applySelection();
428
447
  }
429
448
  function sameSort(a, b) {
430
449
  return (a?.column ?? null) === (b?.column ?? null) && (a?.direction ?? null) === (b?.direction ?? null);
@@ -462,6 +481,7 @@ function onModelUpdated() {
462
481
  syncPagination();
463
482
  const current = api.value;
464
483
  if (!current) return;
484
+ deselectHidden();
465
485
  const count = props.serverPagination ? props.total : current.getDisplayedRowCount();
466
486
  if (props.loading) return;
467
487
  if (announcedCount !== null && announcedCount !== count)
@@ -476,11 +496,138 @@ function goToPage(next) {
476
496
  page.value = target;
477
497
  if (paginated.value) api.value?.paginationGoToPage(target - 1);
478
498
  }
499
+ const instance = getCurrentInstance();
500
+ let warnedMissingRowId = false;
501
+ function isSelectionBound() {
502
+ const vnodeProps = instance?.vnode.props;
503
+ return Boolean(vnodeProps && ("selected" in vnodeProps || "onUpdate:selected" in vnodeProps));
504
+ }
505
+ function checkSelectionRowIds() {
506
+ if (warnedMissingRowId || !isSelectionBound() || rowIdGetter.value) return;
507
+ warnedMissingRowId = true;
508
+ warn(
509
+ "[@xleddyl/443-components-vue] DataGrid v-model:selected needs row ids: set rowIdKey, getRowId or gridOptions.getRowId."
510
+ );
511
+ }
512
+ function sameIds(a, b) {
513
+ if (a.length !== b.length) return false;
514
+ const lookup = new Set(a);
515
+ return b.every((id) => lookup.has(id));
516
+ }
517
+ function hiddenNodeIds(current) {
518
+ const hidden = /* @__PURE__ */ new Set();
519
+ if (props.keepHiddenSelected || !current.isAnyFilterPresent()) return hidden;
520
+ const visible = /* @__PURE__ */ new Set();
521
+ current.forEachNodeAfterFilter((node) => {
522
+ if (node.id !== void 0) visible.add(node.id);
523
+ });
524
+ current.forEachNode((node) => {
525
+ if (node.id !== void 0 && !visible.has(node.id)) hidden.add(node.id);
526
+ });
527
+ return hidden;
528
+ }
529
+ let serverRowsReceived = false;
530
+ watch(
531
+ () => [props.rows, props.loading],
532
+ ([, loading]) => {
533
+ if (!loading) serverRowsReceived = true;
534
+ }
535
+ );
536
+ function serverResultLoaded() {
537
+ if (!props.serverPagination || props.loading || props.keepHiddenSelected) return false;
538
+ if (props.total > 0) return props.rows.length >= props.total;
539
+ return serverRowsReceived && props.rows.length === 0;
540
+ }
541
+ function readNodeIds(current) {
542
+ const present = /* @__PURE__ */ new Set();
543
+ current.forEachNode((node) => {
544
+ if (node.id !== void 0) present.add(node.id);
545
+ });
546
+ return present;
547
+ }
548
+ function mergedSelection(current) {
549
+ const gridIds = current.getSelectedNodes().flatMap((node) => node.id ? [node.id] : []);
550
+ const model = selected.value ?? [];
551
+ const keepUnknown = (props.serverPagination || props.loading) && !serverResultLoaded();
552
+ if (!keepUnknown) return gridIds;
553
+ const present = readNodeIds(current);
554
+ const kept = model.filter((id) => !present.has(id));
555
+ return props.selectable === "single" ? gridIds : [...kept, ...gridIds];
556
+ }
557
+ function applyIds(ids) {
558
+ const current = api.value;
559
+ if (!current || !props.selectable) return;
560
+ const wanted = new Set(ids);
561
+ const hidden = hiddenNodeIds(current);
562
+ const single = props.selectable === "single";
563
+ const select = [];
564
+ const deselect = [];
565
+ let chosen = false;
566
+ current.forEachNode((node) => {
567
+ const id = node.id;
568
+ const should = id !== void 0 && wanted.has(id) && !hidden.has(id) && !(single && chosen);
569
+ if (should) chosen = true;
570
+ if (Boolean(node.isSelected()) === should) return;
571
+ (should ? select : deselect).push(node);
572
+ });
573
+ if (deselect.length) current.setNodesSelected({ nodes: deselect, newValue: false });
574
+ if (select.length) current.setNodesSelected({ nodes: select, newValue: true });
575
+ }
576
+ function applySelection() {
577
+ if (!isSelectionBound() || !selected.value) return;
578
+ const current = api.value;
579
+ const hidden = current ? hiddenNodeIds(current) : null;
580
+ const ids = hidden?.size ? selected.value.filter((id) => !hidden.has(id)) : selected.value;
581
+ if (ids.length !== selected.value.length) selected.value = ids;
582
+ applyIds(ids);
583
+ }
584
+ function reconcileSelection() {
585
+ const current = api.value;
586
+ if (!current || !isSelectionBound() || !selected.value) return;
587
+ const complete = !props.serverPagination && !props.loading || serverResultLoaded();
588
+ if (complete) {
589
+ const present = readNodeIds(current);
590
+ if (present.size || props.serverPagination) {
591
+ const pruned = selected.value.filter((id) => present.has(id));
592
+ if (pruned.length !== selected.value.length) selected.value = pruned;
593
+ }
594
+ }
595
+ applySelection();
596
+ }
597
+ function deselectHidden() {
598
+ const current = api.value;
599
+ if (!current || !props.selectable) return;
600
+ const hidden = hiddenNodeIds(current);
601
+ if (!hidden.size) return;
602
+ const nodes = current.getSelectedNodes().filter((node) => node.id !== void 0 && hidden.has(node.id));
603
+ if (nodes.length) current.setNodesSelected({ nodes, newValue: false });
604
+ }
605
+ function writeSelection(current) {
606
+ if (!isSelectionBound()) return;
607
+ const next = mergedSelection(current);
608
+ if (!sameIds(next, selected.value ?? [])) selected.value = next;
609
+ }
479
610
  function onSelectionChanged(event) {
480
611
  const rows = event.api.getSelectedRows();
481
612
  selectedCount.value = rows.length;
482
613
  emit("selectionChange", rows);
614
+ if (event.source === "rowDataChanged") return;
615
+ writeSelection(event.api);
483
616
  }
617
+ watch(selected, applySelection, { deep: true });
618
+ watch(
619
+ () => props.loading,
620
+ (value) => {
621
+ if (!value) nextTick(reconcileSelection);
622
+ }
623
+ );
624
+ watch(rowIdGetter, checkSelectionRowIds);
625
+ watch(
626
+ () => props.keepHiddenSelected,
627
+ (keep) => {
628
+ if (!keep) deselectHidden();
629
+ }
630
+ );
484
631
  function onSortChanged(event) {
485
632
  const change = readSort(event.api);
486
633
  if (!sameSort(change, sort.value)) sort.value = change;
@@ -523,6 +670,7 @@ const gridEvents = {
523
670
  cellContextMenu: onCellContextMenu,
524
671
  paginationChanged: syncPagination,
525
672
  modelUpdated: onModelUpdated,
673
+ rowDataUpdated: reconcileSelection,
526
674
  columnMoved: persistState,
527
675
  columnResized: persistState,
528
676
  columnVisible: persistState,
@@ -533,17 +681,31 @@ watch(pageSize, () => {
533
681
  else nextTick(syncPagination);
534
682
  });
535
683
  onMounted(() => {
684
+ checkSelectionRowIds();
536
685
  hasStoredState.value = readStoredState() !== null;
537
686
  mounted.value = true;
538
687
  });
539
- defineExpose({
688
+ const exposed = {
540
689
  ...sheet.methods,
541
690
  api,
542
691
  getSelectedRows: () => api.value?.getSelectedRows() ?? [],
543
- deselectAll: () => api.value?.deselectAll(),
692
+ getSelectedIds: () => {
693
+ if (isSelectionBound() && selected.value) return [...selected.value];
694
+ return api.value?.getSelectedNodes().flatMap((node) => node.id ? [node.id] : []) ?? [];
695
+ },
696
+ selectRows: (ids) => {
697
+ if (isSelectionBound()) selected.value = [...ids];
698
+ else applyIds(ids);
699
+ },
700
+ selectAllRows: () => api.value?.selectAll("filtered"),
701
+ deselectAll: () => {
702
+ if (isSelectionBound()) selected.value = [];
703
+ api.value?.deselectAll();
704
+ },
544
705
  resetColumns: () => {
545
706
  api.value?.resetColumnState();
546
707
  clearStoredState();
547
708
  }
548
- });
709
+ };
710
+ defineExpose(exposed);
549
711
  </script>
@@ -1,6 +1,7 @@
1
1
  import type { FilterChangedEvent, FilterModel, ColDef, GetRowIdParams, GridApi, GridOptions, RowClickedEvent } from 'ag-grid-community';
2
+ import type { ShallowRef } from 'vue';
2
3
  import type { PageSize } from '../components/data/types';
3
- import type { GridCellRange, GridCellsChange, GridCellsInvalid, GridActiveFilter, GridDensity, GridMessages, GridSelection, GridSortChange } from './types';
4
+ import type { GridCellRange, GridCellsChange, GridCellsInvalid, GridActiveFilter, DataGridMethods, GridDensity, GridMessages, GridSelection, GridSortChange } from './types';
4
5
  declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
5
6
  props: import("vue").PublicProps & __VLS_PrettifyLocal<({
6
7
  rows?: T[];
@@ -10,6 +11,7 @@ declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_se
10
11
  storageKey?: string;
11
12
  density?: GridDensity;
12
13
  selectable?: GridSelection;
14
+ keepHiddenSelected?: boolean;
13
15
  loading?: boolean;
14
16
  height?: string;
15
17
  fill?: boolean;
@@ -44,12 +46,14 @@ declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_se
44
46
  page?: number;
45
47
  pageSize?: PageSize;
46
48
  sort?: GridSortChange | null | undefined;
49
+ selected?: string[];
47
50
  }) & {
48
51
  onCopy?: ((text: string) => any) | undefined;
49
52
  "onUpdate:page"?: ((value: number) => any) | undefined;
50
53
  "onUpdate:pageSize"?: ((value: PageSize) => any) | undefined;
51
54
  onRowClick?: ((event: RowClickedEvent<T, any>) => any) | undefined;
52
55
  "onUpdate:sort"?: ((value: GridSortChange | null | undefined) => any) | undefined;
56
+ "onUpdate:selected"?: ((value: string[] | undefined) => any) | undefined;
53
57
  "onUpdate:query"?: ((value: string) => any) | undefined;
54
58
  onFiltersReset?: (() => any) | undefined;
55
59
  onFilterRemove?: ((id: string) => any) | undefined;
@@ -63,27 +67,8 @@ declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_se
63
67
  } & Partial<import("vue").HTMLAttributes & import("vue").ReservedProps>> & (typeof globalThis extends {
64
68
  __VLS_PROPS_FALLBACK: infer P;
65
69
  } ? P : {});
66
- expose: (exposed: import("vue").ShallowUnwrapRef<{
67
- api: import("vue").ShallowRef<GridApi<T> | null, GridApi<T> | null>;
68
- getSelectedRows: () => T[];
69
- deselectAll: () => void | undefined;
70
- resetColumns: () => void;
71
- getRange: () => GridCellRange | null;
72
- getSelectedCells: () => import("./types").GridSelectedCell<T>[];
73
- selectRange: (range: import("./types").GridRangeInput) => void;
74
- selectAll: () => void;
75
- clearRange: () => void;
76
- setRangeValue: (value: unknown, options?: import("./types").GridSetRangeValueOptions) => number;
77
- copyRange: () => Promise<string | null>;
78
- paste: (text: string) => number;
79
- fillDown: () => number;
80
- fillRight: () => number;
81
- clearCells: () => number;
82
- undo: () => boolean;
83
- redo: () => boolean;
84
- clearHistory: () => void;
85
- getDirtyCells: () => import("./types").GridDirtyCell[];
86
- clearDirty: (rowIds?: string[]) => void;
70
+ expose: (exposed: import("vue").ShallowUnwrapRef<Omit<DataGridMethods<T>, "api"> & {
71
+ api: ShallowRef<GridApi<T> | null>;
87
72
  }>) => void;
88
73
  attrs: any;
89
74
  slots: {
@@ -142,7 +127,7 @@ declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_se
142
127
  count: number;
143
128
  }) => any;
144
129
  };
145
- emit: (((evt: "copy", text: string) => void) & ((evt: "rowClick", event: RowClickedEvent<T, any>) => void) & ((evt: "filtersReset") => void) & ((evt: "filterRemove", id: string) => void) & ((evt: "selectionChange", rows: T[]) => void) & ((evt: "sortChange", change: GridSortChange | null) => void) & ((evt: "filterChange", model: FilterModel, event: FilterChangedEvent<T, any>) => void) & ((evt: "cellsChange", event: GridCellsChange) => void) & ((evt: "cellsInvalid", event: GridCellsInvalid) => void) & ((evt: "dirtyChange", count: number) => void) & ((evt: "rangeChange", range: GridCellRange | null) => void)) & (((event: "update:page", value: number) => void) & ((event: "update:pageSize", value: PageSize) => void) & ((event: "update:sort", value: GridSortChange | null | undefined) => void) & ((event: "update:query", value: string) => void));
130
+ emit: (((evt: "copy", text: string) => void) & ((evt: "rowClick", event: RowClickedEvent<T, any>) => void) & ((evt: "filtersReset") => void) & ((evt: "filterRemove", id: string) => void) & ((evt: "selectionChange", rows: T[]) => void) & ((evt: "sortChange", change: GridSortChange | null) => void) & ((evt: "filterChange", model: FilterModel, event: FilterChangedEvent<T, any>) => void) & ((evt: "cellsChange", event: GridCellsChange) => void) & ((evt: "cellsInvalid", event: GridCellsInvalid) => void) & ((evt: "dirtyChange", count: number) => void) & ((evt: "rangeChange", range: GridCellRange | null) => void)) & (((event: "update:page", value: number) => void) & ((event: "update:pageSize", value: PageSize) => void) & ((event: "update:sort", value: GridSortChange | null | undefined) => void) & ((event: "update:selected", value: string[] | undefined) => void) & ((event: "update:query", value: string) => void));
146
131
  }>) => import("vue").VNode & {
147
132
  __ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
148
133
  };
@@ -7,6 +7,9 @@
7
7
  :variant="params.variant ?? 'link'"
8
8
  :icon="params.icon"
9
9
  :aria-label="ariaLabel"
10
+ :tooltip="tooltip"
11
+ :disabled="disabled"
12
+ :disabled-reason="disabledReason"
10
13
  @click.stop="onClick"
11
14
  @mousedown.stop
12
15
  >
@@ -17,17 +20,22 @@
17
20
  type="button"
18
21
  class="k-data-grid-button"
19
22
  :aria-label="ariaLabel"
23
+ :aria-disabled="disabled ? 'true' : void 0"
24
+ :aria-describedby="hint && hydrated ? hintId : void 0"
25
+ :title="hydrated ? void 0 : hint"
20
26
  @click.stop="onClick"
21
27
  @mousedown.stop
22
28
  >
23
29
  {{ text }}
30
+ <HintTooltip v-if="hint && hydrated" :id="hintId" :text="hint" />
24
31
  </button>
25
32
  <EmptyCell v-else :context="cellContext" />
26
33
  </template>
27
34
 
28
35
  <script setup>
29
- import { computed } from "vue";
36
+ import { computed, onMounted, ref, useId } from "vue";
30
37
  import Button from "../../components/core/Button.vue";
38
+ import HintTooltip from "../../internal/overlays/HintTooltip.vue";
31
39
  import EmptyCell from "./EmptyCell.vue";
32
40
  const props = defineProps({
33
41
  params: { type: Object, required: true }
@@ -45,7 +53,19 @@ const styled = computed(
45
53
  () => Boolean(props.params.tone || props.params.variant || props.params.icon)
46
54
  );
47
55
  const ariaLabel = computed(() => props.params.ariaLabel?.(raw.value, props.params.data));
56
+ const tooltip = computed(() => props.params.tooltip?.(raw.value, props.params.data));
57
+ const disabled = computed(() => Boolean(props.params.disabled?.(raw.value, props.params.data)));
58
+ const disabledReason = computed(
59
+ () => disabled.value ? props.params.disabledReason?.(raw.value, props.params.data) : void 0
60
+ );
61
+ const hint = computed(() => disabledReason.value ?? tooltip.value);
62
+ const hintId = `${useId()}-hint`;
63
+ const hydrated = ref(false);
64
+ onMounted(() => {
65
+ hydrated.value = true;
66
+ });
48
67
  function onClick(event) {
68
+ if (disabled.value) return;
49
69
  props.params.onClick?.(raw.value, props.params.data, event);
50
70
  }
51
71
  const cellContext = computed(() => props.params.context);
@@ -16,6 +16,8 @@ declare const __VLS_export: import("vue").DefineComponent<{
16
16
  loading?: boolean;
17
17
  block?: boolean;
18
18
  square?: boolean;
19
+ tooltip?: string | false;
20
+ disabledReason?: string;
19
21
  download?: any;
20
22
  hreflang?: string | undefined;
21
23
  media?: string | undefined;
@@ -249,6 +251,8 @@ declare const __VLS_export: import("vue").DefineComponent<{
249
251
  loading?: boolean;
250
252
  block?: boolean;
251
253
  square?: boolean;
254
+ tooltip?: string | false;
255
+ disabledReason?: string;
252
256
  download?: any;
253
257
  hreflang?: string | undefined;
254
258
  media?: string | undefined;
@@ -343,10 +343,16 @@
343
343
  transition: text-decoration-color var(--k-duration) var(--k-ease);
344
344
  }
345
345
 
346
- .k-data-grid-button:hover {
346
+ .k-data-grid-button:hover:not([aria-disabled='true']) {
347
347
  text-decoration-color: currentColor;
348
348
  }
349
349
 
350
+ .k-data-grid-button[aria-disabled='true'] {
351
+ color: var(--k-text-muted);
352
+ text-decoration: none;
353
+ cursor: not-allowed;
354
+ }
355
+
350
356
  .k-data-grid-action {
351
357
  max-width: 100%;
352
358
  }
@@ -83,6 +83,9 @@ export interface ButtonCellParams<T = unknown> {
83
83
  onClick?: (value: unknown, data: T | undefined, event: MouseEvent) => void;
84
84
  label?: (value: unknown, data: T | undefined) => string | undefined;
85
85
  ariaLabel?: (value: unknown, data: T | undefined) => string | undefined;
86
+ tooltip?: (value: unknown, data: T | undefined) => string | undefined;
87
+ disabled?: (value: unknown, data: T | undefined) => boolean;
88
+ disabledReason?: (value: unknown, data: T | undefined) => string | undefined;
86
89
  emptyLabel?: string;
87
90
  tone?: Tone;
88
91
  variant?: ButtonVariant;
@@ -173,3 +176,12 @@ export interface GridSpreadsheetSlotProps<T = unknown> extends GridSpreadsheetMe
173
176
  canUndo: boolean;
174
177
  canRedo: boolean;
175
178
  }
179
+ export interface DataGridMethods<T = unknown> extends GridSpreadsheetMethods<T> {
180
+ api: GridApi<T> | null;
181
+ getSelectedRows: () => T[];
182
+ getSelectedIds: () => string[];
183
+ selectRows: (ids: string[]) => void;
184
+ selectAllRows: () => void;
185
+ deselectAll: () => void;
186
+ resetColumns: () => void;
187
+ }
@@ -0,0 +1,25 @@
1
+ import type { FormContext } from '../../composables/useForm';
2
+ import type { useLocale } from '../../composables/useLocale';
3
+ export interface FormOverlayProps {
4
+ form?: Pick<FormContext, 'submitting'> & {
5
+ dirty: {
6
+ value: boolean;
7
+ };
8
+ };
9
+ loading?: boolean;
10
+ readonly?: boolean;
11
+ creating?: boolean;
12
+ requireDirty?: boolean;
13
+ submitLabel?: string;
14
+ cancelLabel?: string;
15
+ deleteLabel?: string;
16
+ }
17
+ export declare function useFormOverlay(props: FormOverlayProps, t: ReturnType<typeof useLocale>['t']): {
18
+ formKey: import("vue").ComputedRef<number | undefined>;
19
+ isDirty: import("vue").ComputedRef<boolean>;
20
+ isSaving: import("vue").ComputedRef<boolean>;
21
+ submitDisabled: import("vue").ComputedRef<boolean>;
22
+ submitText: import("vue").ComputedRef<string>;
23
+ cancelText: import("vue").ComputedRef<string>;
24
+ deleteText: import("vue").ComputedRef<string>;
25
+ };
@@ -0,0 +1,31 @@
1
+ import { computed } from "vue";
2
+ export function useFormOverlay(props, t) {
3
+ const formKeys = /* @__PURE__ */ new WeakMap();
4
+ let nextFormKey = 0;
5
+ const formKey = computed(() => {
6
+ const form = props.form;
7
+ if (!form) return void 0;
8
+ if (!formKeys.has(form)) formKeys.set(form, nextFormKey++);
9
+ return formKeys.get(form);
10
+ });
11
+ const isDirty = computed(() => Boolean(props.form?.dirty.value));
12
+ const isSaving = computed(() => Boolean(props.form?.submitting.value));
13
+ const needsDirty = computed(() => props.requireDirty ?? !props.creating);
14
+ const submitDisabled = computed(() => props.loading || needsDirty.value && !isDirty.value);
15
+ const submitText = computed(
16
+ () => props.submitLabel ?? (props.creating ? t("common.create") : t("common.save"))
17
+ );
18
+ const cancelText = computed(
19
+ () => props.cancelLabel ?? (props.readonly ? t("common.dismiss") : t("common.cancel"))
20
+ );
21
+ const deleteText = computed(() => props.deleteLabel ?? t("common.delete"));
22
+ return {
23
+ formKey,
24
+ isDirty,
25
+ isSaving,
26
+ submitDisabled,
27
+ submitText,
28
+ cancelText,
29
+ deleteText
30
+ };
31
+ }
@@ -0,0 +1,30 @@
1
+ import type { ComputedRef, InjectionKey } from 'vue';
2
+ import type { ConfirmOptions } from '../overlays/confirm';
3
+ export interface LeaveEntry {
4
+ dirty: () => boolean;
5
+ options?: () => ConfirmOptions | undefined;
6
+ }
7
+ export interface LeaveScope {
8
+ readonly dirty: ComputedRef<boolean>;
9
+ register: (entry: LeaveEntry) => () => void;
10
+ confirmOptions: () => ConfirmOptions;
11
+ confirmLeave: (options?: ConfirmOptions) => Promise<boolean>;
12
+ allowNext: () => void;
13
+ }
14
+ export interface LeaveScopeOptions {
15
+ enabled?: () => boolean;
16
+ options?: () => ConfirmOptions | undefined;
17
+ }
18
+ export type DiscardConfirm = (options?: ConfirmOptions) => Promise<boolean>;
19
+ export declare const LEAVE_SCOPE_KEY: InjectionKey<LeaveScope>;
20
+ export declare function askDiscard(ask: () => Promise<boolean>): Promise<boolean>;
21
+ export declare function runNavigationGuard(to: object, run: () => boolean | void | Promise<boolean | void>): Promise<boolean>;
22
+ export declare function createLeaveScope(discard: DiscardConfirm, options?: LeaveScopeOptions & {
23
+ allowNext?: () => void;
24
+ }): LeaveScope;
25
+ export declare function rootLeaveScope(discard: DiscardConfirm, page: () => ConfirmOptions): LeaveScope;
26
+ export declare function injectedLeaveScope(): LeaveScope | null;
27
+ export declare function registerLeaveEntry(scope: LeaveScope, entry: LeaveEntry): () => void;
28
+ export declare function provideScope(scope: LeaveScope, parent: LeaveScope): LeaveScope;
29
+ export declare function setDialogScope(dialog: Element, scope: LeaveScope | null): void;
30
+ export declare function dialogScope(dialog: Element | null | undefined): LeaveScope | undefined;
@@ -0,0 +1,135 @@
1
+ import {
2
+ computed,
3
+ getCurrentInstance,
4
+ getCurrentScope,
5
+ hasInjectionContext,
6
+ inject,
7
+ onScopeDispose,
8
+ provide,
9
+ shallowReactive
10
+ } from "vue";
11
+ import { isClient } from "../core/env.mjs";
12
+ export const LEAVE_SCOPE_KEY = Symbol("k-leave-scope");
13
+ let pendingAsk = null;
14
+ let activeNavigation = null;
15
+ let acceptedNavigation = null;
16
+ export function askDiscard(ask) {
17
+ if (activeNavigation && acceptedNavigation === activeNavigation) return Promise.resolve(true);
18
+ if (pendingAsk) return pendingAsk;
19
+ const navigation = activeNavigation;
20
+ const request = ask().then((confirmed) => {
21
+ if (confirmed && navigation) acceptedNavigation = navigation;
22
+ return confirmed;
23
+ }).finally(() => {
24
+ if (pendingAsk === request) pendingAsk = null;
25
+ });
26
+ pendingAsk = request;
27
+ return request;
28
+ }
29
+ export async function runNavigationGuard(to, run) {
30
+ activeNavigation = to;
31
+ try {
32
+ return await run() !== false;
33
+ } finally {
34
+ if (activeNavigation === to) activeNavigation = null;
35
+ }
36
+ }
37
+ function definedOptions(options) {
38
+ if (!options) return {};
39
+ return Object.fromEntries(
40
+ Object.entries(options).filter(([, value]) => value !== void 0 && value !== "")
41
+ );
42
+ }
43
+ export function createLeaveScope(discard, options = {}) {
44
+ const entries = shallowReactive(/* @__PURE__ */ new Set());
45
+ const enabled = () => options.enabled?.() ?? true;
46
+ function firstDirty() {
47
+ if (!enabled()) return void 0;
48
+ for (const entry of entries) if (entry.dirty()) return entry;
49
+ return void 0;
50
+ }
51
+ const dirty = computed(() => Boolean(firstDirty()));
52
+ function register(entry) {
53
+ entries.add(entry);
54
+ return () => {
55
+ entries.delete(entry);
56
+ };
57
+ }
58
+ function confirmOptions() {
59
+ return {
60
+ ...definedOptions(options.options?.()),
61
+ ...definedOptions(firstDirty()?.options?.())
62
+ };
63
+ }
64
+ function confirmLeave(extra) {
65
+ if (!dirty.value) return Promise.resolve(true);
66
+ return discard({ ...confirmOptions(), ...definedOptions(extra) });
67
+ }
68
+ return {
69
+ dirty,
70
+ register,
71
+ confirmOptions,
72
+ confirmLeave,
73
+ allowNext: () => options.allowNext?.()
74
+ };
75
+ }
76
+ const rootScopes = /* @__PURE__ */ new WeakMap();
77
+ const detachedRoot = {};
78
+ function createRootScope(discard, page) {
79
+ let bypass = false;
80
+ const scope = createLeaveScope(discard, {
81
+ options: page,
82
+ allowNext: () => {
83
+ bypass = true;
84
+ }
85
+ });
86
+ const instance = getCurrentInstance();
87
+ const router = instance?.appContext.config.globalProperties.$router;
88
+ if (isClient()) {
89
+ window.addEventListener("beforeunload", (event) => {
90
+ if (bypass || !scope.dirty.value) return;
91
+ event.preventDefault();
92
+ event.returnValue = "";
93
+ });
94
+ router?.beforeEach((to, from) => {
95
+ if (bypass) {
96
+ bypass = false;
97
+ return true;
98
+ }
99
+ if (to.path === from.path || !scope.dirty.value) return true;
100
+ return runNavigationGuard(to, () => scope.confirmLeave());
101
+ });
102
+ }
103
+ return scope;
104
+ }
105
+ export function rootLeaveScope(discard, page) {
106
+ const app = getCurrentInstance()?.appContext.app;
107
+ if (!app) return detachedRoot.scope ??= createLeaveScope(discard, { options: page });
108
+ let scope = rootScopes.get(app);
109
+ if (!scope) {
110
+ scope = createRootScope(discard, page);
111
+ rootScopes.set(app, scope);
112
+ }
113
+ return scope;
114
+ }
115
+ export function injectedLeaveScope() {
116
+ return hasInjectionContext() ? inject(LEAVE_SCOPE_KEY, null) : null;
117
+ }
118
+ export function registerLeaveEntry(scope, entry) {
119
+ const unregister = scope.register(entry);
120
+ if (getCurrentScope()) onScopeDispose(unregister);
121
+ return unregister;
122
+ }
123
+ export function provideScope(scope, parent) {
124
+ provide(LEAVE_SCOPE_KEY, scope);
125
+ registerLeaveEntry(parent, { dirty: () => scope.dirty.value, options: scope.confirmOptions });
126
+ return scope;
127
+ }
128
+ const dialogScopes = /* @__PURE__ */ new WeakMap();
129
+ export function setDialogScope(dialog, scope) {
130
+ if (scope) dialogScopes.set(dialog, scope);
131
+ else dialogScopes.delete(dialog);
132
+ }
133
+ export function dialogScope(dialog) {
134
+ return dialog ? dialogScopes.get(dialog) : void 0;
135
+ }
@@ -19,3 +19,4 @@ export declare const FORM_CONFIG_KEY: InjectionKey<FormConfig>;
19
19
  export declare const GRID_CONFIG_KEY: InjectionKey<GridConfig>;
20
20
  export declare const LOCALE_KEY: InjectionKey<ComputedRef<KLocale>>;
21
21
  export declare const ROUTE_LOCATION_KEY: InjectionKey<'query' | 'hash'>;
22
+ export declare const TOOLTIP_TRIGGER_KEY: InjectionKey<true>;