@toolbox-web/grid 1.24.2 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.d.ts +0 -1
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/constants.d.ts +0 -1
- package/lib/core/grid.d.ts +145 -33
- package/lib/core/internal/aggregators.d.ts +0 -1
- package/lib/core/internal/aria.d.ts +8 -1
- package/lib/core/internal/columns.d.ts +3 -4
- package/lib/core/internal/config-manager.d.ts +2 -54
- package/lib/core/internal/dom-builder.d.ts +0 -1
- package/lib/core/internal/event-delegation.d.ts +3 -4
- package/lib/core/internal/feature-hook.d.ts +0 -1
- package/lib/core/internal/focus-manager.d.ts +49 -0
- package/lib/core/internal/header.d.ts +2 -3
- package/lib/core/internal/idle-scheduler.d.ts +0 -1
- package/lib/core/internal/inference.d.ts +0 -1
- package/lib/core/internal/keyboard.d.ts +3 -4
- package/lib/core/internal/loading.d.ts +0 -1
- package/lib/core/internal/render-scheduler.d.ts +3 -66
- package/lib/core/internal/resize.d.ts +2 -3
- package/lib/core/internal/row-animation.d.ts +0 -1
- package/lib/core/internal/row-manager.d.ts +31 -0
- package/lib/core/internal/rows.d.ts +4 -5
- package/lib/core/internal/sanitize.d.ts +0 -1
- package/lib/core/internal/shell.d.ts +7 -25
- package/lib/core/internal/sorting.d.ts +3 -4
- package/lib/core/internal/style-injector.d.ts +0 -1
- package/lib/core/internal/touch-scroll.d.ts +31 -12
- package/lib/core/internal/utils.d.ts +8 -1
- package/lib/core/internal/validate-config.d.ts +4 -5
- package/lib/core/internal/virtualization-manager.d.ts +48 -0
- package/lib/core/internal/virtualization.d.ts +0 -1
- package/lib/core/plugin/base-plugin.d.ts +2 -3
- package/lib/core/plugin/expander-column.d.ts +0 -1
- package/lib/core/plugin/index.d.ts +0 -1
- package/lib/core/plugin/plugin-manager.d.ts +2 -1
- package/lib/core/plugin/types.d.ts +7 -2
- package/lib/core/styles/index.d.ts +0 -1
- package/lib/core/types.d.ts +364 -54
- package/lib/features/clipboard.d.ts +0 -1
- package/lib/features/column-virtualization.d.ts +0 -1
- package/lib/features/context-menu.d.ts +0 -1
- package/lib/features/editing.d.ts +0 -1
- package/lib/features/export.d.ts +0 -1
- package/lib/features/filtering.d.ts +0 -1
- package/lib/features/grouping-columns.d.ts +0 -1
- package/lib/features/grouping-rows.d.ts +0 -1
- package/lib/features/master-detail.d.ts +0 -1
- package/lib/features/multi-sort.d.ts +1 -2
- package/lib/features/multi-sort.js.map +1 -1
- package/lib/features/pinned-columns.d.ts +0 -1
- package/lib/features/pinned-rows.d.ts +0 -1
- package/lib/features/pivot.d.ts +0 -1
- package/lib/features/print.d.ts +0 -1
- package/lib/features/registry.d.ts +0 -1
- package/lib/features/reorder-columns.d.ts +1 -2
- package/lib/features/reorder-columns.js.map +1 -1
- package/lib/features/reorder-rows.d.ts +1 -2
- package/lib/features/reorder-rows.js.map +1 -1
- package/lib/features/responsive.d.ts +0 -1
- package/lib/features/selection.d.ts +0 -1
- package/lib/features/server-side.d.ts +0 -1
- package/lib/features/tree.d.ts +0 -1
- package/lib/features/undo-redo.d.ts +0 -1
- package/lib/features/visibility.d.ts +0 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +0 -1
- package/lib/plugins/clipboard/copy.d.ts +0 -1
- package/lib/plugins/clipboard/index.d.ts +0 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/paste.d.ts +0 -1
- package/lib/plugins/clipboard/types.d.ts +6 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -1
- package/lib/plugins/column-virtualization/column-virtualization.d.ts +0 -1
- package/lib/plugins/column-virtualization/index.d.ts +0 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/column-virtualization/types.d.ts +0 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +16 -1
- package/lib/plugins/context-menu/index.d.ts +1 -2
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/menu.d.ts +14 -1
- package/lib/plugins/context-menu/types.d.ts +13 -3
- package/lib/plugins/editing/EditingPlugin.d.ts +4 -6
- package/lib/plugins/editing/editors.d.ts +0 -1
- package/lib/plugins/editing/index.d.ts +0 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/cell-validation.d.ts +0 -1
- package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +0 -1
- package/lib/plugins/editing/internal/dirty-tracking.d.ts +2 -2
- package/lib/plugins/editing/internal/editor-injection.d.ts +3 -4
- package/lib/plugins/editing/internal/helpers.d.ts +0 -1
- package/lib/plugins/editing/types.d.ts +15 -14
- package/lib/plugins/export/ExportPlugin.d.ts +0 -1
- package/lib/plugins/export/csv.d.ts +0 -1
- package/lib/plugins/export/excel.d.ts +0 -1
- package/lib/plugins/export/index.d.ts +0 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/export/types.d.ts +4 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +0 -1
- package/lib/plugins/filtering/filter-model.d.ts +0 -1
- package/lib/plugins/filtering/filter-panel-date.d.ts +0 -1
- package/lib/plugins/filtering/filter-panel-default.d.ts +0 -1
- package/lib/plugins/filtering/filter-panel-number.d.ts +0 -1
- package/lib/plugins/filtering/index.d.ts +0 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +4 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +0 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +0 -1
- package/lib/plugins/grouping-columns/index.d.ts +0 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-columns/types.d.ts +0 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +0 -1
- package/lib/plugins/grouping-rows/grouping-rows.d.ts +0 -1
- package/lib/plugins/grouping-rows/index.d.ts +0 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/grouping-rows/types.d.ts +4 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +0 -1
- package/lib/plugins/master-detail/index.d.ts +0 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/master-detail.d.ts +0 -1
- package/lib/plugins/master-detail/types.d.ts +4 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +3 -3
- package/lib/plugins/multi-sort/index.d.ts +1 -2
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/multi-sort/multi-sort.d.ts +0 -1
- package/lib/plugins/multi-sort/types.d.ts +5 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +0 -1
- package/lib/plugins/pinned-columns/index.d.ts +0 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-columns/pinned-columns.d.ts +0 -1
- package/lib/plugins/pinned-columns/types.d.ts +0 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +0 -1
- package/lib/plugins/pinned-rows/index.d.ts +0 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pinned-rows/pinned-rows.d.ts +0 -1
- package/lib/plugins/pinned-rows/types.d.ts +0 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts +0 -1
- package/lib/plugins/pivot/index.d.ts +0 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-engine.d.ts +0 -1
- package/lib/plugins/pivot/pivot-model.d.ts +0 -1
- package/lib/plugins/pivot/pivot-panel.d.ts +0 -1
- package/lib/plugins/pivot/pivot-rows.d.ts +0 -1
- package/lib/plugins/pivot/types.d.ts +0 -1
- package/lib/plugins/print/PrintPlugin.d.ts +0 -1
- package/lib/plugins/print/index.d.ts +0 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/print/print-isolated.d.ts +0 -1
- package/lib/plugins/print/types.d.ts +6 -1
- package/lib/plugins/reorder-columns/ReorderPlugin.d.ts +5 -5
- package/lib/plugins/reorder-columns/column-drag.d.ts +3 -2
- package/lib/plugins/reorder-columns/index.d.ts +0 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/reorder-columns/types.d.ts +4 -1
- package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts +3 -3
- package/lib/plugins/reorder-rows/index.d.ts +0 -1
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js.map +1 -1
- package/lib/plugins/reorder-rows/types.d.ts +4 -1
- package/lib/plugins/responsive/ResponsivePlugin.d.ts +0 -1
- package/lib/plugins/responsive/index.d.ts +0 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/responsive/types.d.ts +4 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts +1 -3
- package/lib/plugins/selection/index.d.ts +0 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/range-selection.d.ts +0 -1
- package/lib/plugins/selection/row-selection.d.ts +0 -1
- package/lib/plugins/selection/types.d.ts +4 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -1
- package/lib/plugins/server-side/cache.d.ts +0 -1
- package/lib/plugins/server-side/datasource.d.ts +0 -1
- package/lib/plugins/server-side/index.d.ts +0 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/server-side/types.d.ts +0 -1
- package/lib/plugins/shared/data-collection.d.ts +0 -1
- package/lib/plugins/tree/TreePlugin.d.ts +0 -1
- package/lib/plugins/tree/index.d.ts +0 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/tree-data.d.ts +0 -1
- package/lib/plugins/tree/tree-detect.d.ts +0 -1
- package/lib/plugins/tree/types.d.ts +4 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +1 -2
- package/lib/plugins/undo-redo/history.d.ts +0 -1
- package/lib/plugins/undo-redo/index.d.ts +0 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +6 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +0 -1
- package/lib/plugins/visibility/index.d.ts +0 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/lib/plugins/visibility/types.d.ts +0 -1
- package/lib/plugins/visibility/visibility.d.ts +0 -1
- package/package.json +1 -1
- package/public.d.ts +31 -12
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -1
- 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/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/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/print.umd.js +1 -1
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/reorder-columns.umd.js +1 -1
- package/umd/plugins/reorder-columns.umd.js.map +1 -1
- package/umd/plugins/reorder-rows.umd.js +1 -1
- package/umd/plugins/reorder-rows.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.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.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.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
- package/all.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/lib/core/constants.d.ts.map +0 -1
- package/lib/core/grid.d.ts.map +0 -1
- package/lib/core/internal/aggregators.d.ts.map +0 -1
- package/lib/core/internal/aria.d.ts.map +0 -1
- package/lib/core/internal/columns.d.ts.map +0 -1
- package/lib/core/internal/config-manager.d.ts.map +0 -1
- package/lib/core/internal/dom-builder.d.ts.map +0 -1
- package/lib/core/internal/event-delegation.d.ts.map +0 -1
- package/lib/core/internal/feature-hook.d.ts.map +0 -1
- package/lib/core/internal/header.d.ts.map +0 -1
- package/lib/core/internal/idle-scheduler.d.ts.map +0 -1
- package/lib/core/internal/inference.d.ts.map +0 -1
- package/lib/core/internal/keyboard.d.ts.map +0 -1
- package/lib/core/internal/loading.d.ts.map +0 -1
- package/lib/core/internal/render-scheduler.d.ts.map +0 -1
- package/lib/core/internal/resize.d.ts.map +0 -1
- package/lib/core/internal/row-animation.d.ts.map +0 -1
- package/lib/core/internal/rows.d.ts.map +0 -1
- package/lib/core/internal/sanitize.d.ts.map +0 -1
- package/lib/core/internal/shell.d.ts.map +0 -1
- package/lib/core/internal/sorting.d.ts.map +0 -1
- package/lib/core/internal/style-injector.d.ts.map +0 -1
- package/lib/core/internal/touch-scroll.d.ts.map +0 -1
- package/lib/core/internal/utils.d.ts.map +0 -1
- package/lib/core/internal/validate-config.d.ts.map +0 -1
- package/lib/core/internal/virtualization.d.ts.map +0 -1
- package/lib/core/plugin/base-plugin.d.ts.map +0 -1
- package/lib/core/plugin/expander-column.d.ts.map +0 -1
- package/lib/core/plugin/index.d.ts.map +0 -1
- package/lib/core/plugin/plugin-manager.d.ts.map +0 -1
- package/lib/core/plugin/types.d.ts.map +0 -1
- package/lib/core/styles/index.d.ts.map +0 -1
- package/lib/core/types.d.ts.map +0 -1
- package/lib/features/clipboard.d.ts.map +0 -1
- package/lib/features/column-virtualization.d.ts.map +0 -1
- package/lib/features/context-menu.d.ts.map +0 -1
- package/lib/features/editing.d.ts.map +0 -1
- package/lib/features/export.d.ts.map +0 -1
- package/lib/features/filtering.d.ts.map +0 -1
- package/lib/features/grouping-columns.d.ts.map +0 -1
- package/lib/features/grouping-rows.d.ts.map +0 -1
- package/lib/features/magic-string.es-CkyDP9Ir.mjs.map +0 -1
- package/lib/features/master-detail.d.ts.map +0 -1
- package/lib/features/multi-sort.d.ts.map +0 -1
- package/lib/features/pinned-columns.d.ts.map +0 -1
- package/lib/features/pinned-rows.d.ts.map +0 -1
- package/lib/features/pivot.d.ts.map +0 -1
- package/lib/features/print.d.ts.map +0 -1
- package/lib/features/registry.d.ts.map +0 -1
- package/lib/features/registry.spec.js +0 -5
- package/lib/features/registry.spec.js.map +0 -1
- package/lib/features/reorder-columns.d.ts.map +0 -1
- package/lib/features/reorder-rows.d.ts.map +0 -1
- package/lib/features/responsive.d.ts.map +0 -1
- package/lib/features/selection.d.ts.map +0 -1
- package/lib/features/server-side.d.ts.map +0 -1
- package/lib/features/tree.d.ts.map +0 -1
- package/lib/features/undo-redo.d.ts.map +0 -1
- package/lib/features/visibility.d.ts.map +0 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +0 -1
- package/lib/plugins/clipboard/copy.d.ts.map +0 -1
- package/lib/plugins/clipboard/index.d.ts.map +0 -1
- package/lib/plugins/clipboard/paste.d.ts.map +0 -1
- package/lib/plugins/clipboard/types.d.ts.map +0 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +0 -1
- package/lib/plugins/column-virtualization/column-virtualization.d.ts.map +0 -1
- package/lib/plugins/column-virtualization/index.d.ts.map +0 -1
- package/lib/plugins/column-virtualization/types.d.ts.map +0 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +0 -1
- package/lib/plugins/context-menu/index.d.ts.map +0 -1
- package/lib/plugins/context-menu/menu.d.ts.map +0 -1
- package/lib/plugins/context-menu/types.d.ts.map +0 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +0 -1
- package/lib/plugins/editing/editors.d.ts.map +0 -1
- package/lib/plugins/editing/index.d.ts.map +0 -1
- package/lib/plugins/editing/internal/cell-validation.d.ts.map +0 -1
- package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts.map +0 -1
- package/lib/plugins/editing/internal/dirty-tracking.d.ts.map +0 -1
- package/lib/plugins/editing/internal/editor-injection.d.ts.map +0 -1
- package/lib/plugins/editing/internal/helpers.d.ts.map +0 -1
- package/lib/plugins/editing/types.d.ts.map +0 -1
- package/lib/plugins/export/ExportPlugin.d.ts.map +0 -1
- package/lib/plugins/export/csv.d.ts.map +0 -1
- package/lib/plugins/export/excel.d.ts.map +0 -1
- package/lib/plugins/export/index.d.ts.map +0 -1
- package/lib/plugins/export/types.d.ts.map +0 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +0 -1
- package/lib/plugins/filtering/filter-model.d.ts.map +0 -1
- package/lib/plugins/filtering/filter-panel-date.d.ts.map +0 -1
- package/lib/plugins/filtering/filter-panel-default.d.ts.map +0 -1
- package/lib/plugins/filtering/filter-panel-number.d.ts.map +0 -1
- package/lib/plugins/filtering/index.d.ts.map +0 -1
- package/lib/plugins/filtering/types.d.ts.map +0 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +0 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +0 -1
- package/lib/plugins/grouping-columns/index.d.ts.map +0 -1
- package/lib/plugins/grouping-columns/types.d.ts.map +0 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +0 -1
- package/lib/plugins/grouping-rows/grouping-rows.d.ts.map +0 -1
- package/lib/plugins/grouping-rows/index.d.ts.map +0 -1
- package/lib/plugins/grouping-rows/types.d.ts.map +0 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +0 -1
- package/lib/plugins/master-detail/index.d.ts.map +0 -1
- package/lib/plugins/master-detail/master-detail.d.ts.map +0 -1
- package/lib/plugins/master-detail/types.d.ts.map +0 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +0 -1
- package/lib/plugins/multi-sort/index.d.ts.map +0 -1
- package/lib/plugins/multi-sort/multi-sort.d.ts.map +0 -1
- package/lib/plugins/multi-sort/types.d.ts.map +0 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +0 -1
- package/lib/plugins/pinned-columns/index.d.ts.map +0 -1
- package/lib/plugins/pinned-columns/pinned-columns.d.ts.map +0 -1
- package/lib/plugins/pinned-columns/types.d.ts.map +0 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +0 -1
- package/lib/plugins/pinned-rows/index.d.ts.map +0 -1
- package/lib/plugins/pinned-rows/pinned-rows.d.ts.map +0 -1
- package/lib/plugins/pinned-rows/types.d.ts.map +0 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts.map +0 -1
- package/lib/plugins/pivot/index.d.ts.map +0 -1
- package/lib/plugins/pivot/pivot-engine.d.ts.map +0 -1
- package/lib/plugins/pivot/pivot-model.d.ts.map +0 -1
- package/lib/plugins/pivot/pivot-panel.d.ts.map +0 -1
- package/lib/plugins/pivot/pivot-rows.d.ts.map +0 -1
- package/lib/plugins/pivot/types.d.ts.map +0 -1
- package/lib/plugins/print/PrintPlugin.d.ts.map +0 -1
- package/lib/plugins/print/index.d.ts.map +0 -1
- package/lib/plugins/print/print-isolated.d.ts.map +0 -1
- package/lib/plugins/print/types.d.ts.map +0 -1
- package/lib/plugins/reorder-columns/ReorderPlugin.d.ts.map +0 -1
- package/lib/plugins/reorder-columns/column-drag.d.ts.map +0 -1
- package/lib/plugins/reorder-columns/index.d.ts.map +0 -1
- package/lib/plugins/reorder-columns/types.d.ts.map +0 -1
- package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts.map +0 -1
- package/lib/plugins/reorder-rows/index.d.ts.map +0 -1
- package/lib/plugins/reorder-rows/types.d.ts.map +0 -1
- package/lib/plugins/responsive/ResponsivePlugin.d.ts.map +0 -1
- package/lib/plugins/responsive/index.d.ts.map +0 -1
- package/lib/plugins/responsive/types.d.ts.map +0 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +0 -1
- package/lib/plugins/selection/index.d.ts.map +0 -1
- package/lib/plugins/selection/range-selection.d.ts.map +0 -1
- package/lib/plugins/selection/row-selection.d.ts.map +0 -1
- package/lib/plugins/selection/types.d.ts.map +0 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +0 -1
- package/lib/plugins/server-side/cache.d.ts.map +0 -1
- package/lib/plugins/server-side/datasource.d.ts.map +0 -1
- package/lib/plugins/server-side/index.d.ts.map +0 -1
- package/lib/plugins/server-side/types.d.ts.map +0 -1
- package/lib/plugins/shared/data-collection.d.ts.map +0 -1
- package/lib/plugins/tree/TreePlugin.d.ts.map +0 -1
- package/lib/plugins/tree/index.d.ts.map +0 -1
- package/lib/plugins/tree/tree-data.d.ts.map +0 -1
- package/lib/plugins/tree/tree-detect.d.ts.map +0 -1
- package/lib/plugins/tree/types.d.ts.map +0 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +0 -1
- package/lib/plugins/undo-redo/history.d.ts.map +0 -1
- package/lib/plugins/undo-redo/index.d.ts.map +0 -1
- package/lib/plugins/undo-redo/types.d.ts.map +0 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +0 -1
- package/lib/plugins/visibility/index.d.ts.map +0 -1
- package/lib/plugins/visibility/types.d.ts.map +0 -1
- package/lib/plugins/visibility/visibility.d.ts.map +0 -1
- package/public.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-menu.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/context-menu/menu.ts","../../../../../libs/grid/src/lib/plugins/context-menu/ContextMenuPlugin.ts"],"sourcesContent":["/**\n * Context Menu Rendering Logic\n *\n * Pure functions for building and positioning context menus.\n */\n\nimport type { IconValue } from '../../core/types';\nimport { DEFAULT_GRID_ICONS } from '../../core/types';\nimport type { ContextMenuItem, ContextMenuParams } from './types';\n\n/**\n * Build the visible menu items by resolving dynamic items and filtering hidden ones.\n *\n * @param items - Menu items configuration (array or factory function)\n * @param params - Context menu parameters for evaluating dynamic properties\n * @returns Filtered array of visible menu items\n */\nexport function buildMenuItems(\n items: ContextMenuItem[] | ((params: ContextMenuParams) => ContextMenuItem[]),\n params: ContextMenuParams,\n): ContextMenuItem[] {\n const menuItems = typeof items === 'function' ? items(params) : items;\n\n return menuItems.filter((item) => {\n if (item.hidden === true) return false;\n if (typeof item.hidden === 'function' && item.hidden(params)) return false;\n return true;\n });\n}\n\n/**\n * Remove consecutive, leading, and trailing separators from a menu item list.\n *\n * @param items - Array of menu items\n * @returns Cleaned array with no redundant separators\n */\nexport function collapseSeparators(items: ContextMenuItem[]): ContextMenuItem[] {\n const result: ContextMenuItem[] = [];\n for (const item of items) {\n if (item.separator) {\n // Skip if the last item is already a separator (consecutive) or list is empty (leading)\n if (result.length === 0 || result[result.length - 1].separator) continue;\n }\n result.push(item);\n }\n // Remove trailing separator\n if (result.length > 0 && result[result.length - 1].separator) {\n result.pop();\n }\n return result;\n}\n\n/**\n * Check if a menu item is disabled.\n *\n * @param item - The menu item to check\n * @param params - Context menu parameters for evaluating dynamic disabled state\n * @returns True if the item is disabled\n */\nexport function isItemDisabled(item: ContextMenuItem, params: ContextMenuParams): boolean {\n if (item.disabled === true) return true;\n if (typeof item.disabled === 'function') return item.disabled(params);\n return false;\n}\n\n/**\n * Create the menu DOM element from a list of menu items.\n *\n * @param items - Array of menu items to render\n * @param params - Context menu parameters for evaluating dynamic properties\n * @param onAction - Callback when a menu item action is triggered\n * @param submenuArrow - Optional custom submenu arrow icon\n * @returns The created menu element\n */\nexport function createMenuElement(\n items: ContextMenuItem[],\n params: ContextMenuParams,\n onAction: (item: ContextMenuItem) => void,\n submenuArrow: IconValue = DEFAULT_GRID_ICONS.submenuArrow,\n): HTMLElement {\n const menu = document.createElement('div');\n menu.className = 'tbw-context-menu';\n menu.setAttribute('role', 'menu');\n\n // Check if any non-separator item has an icon\n const hasAnyIcon = items.some((item) => !item.separator && item.icon);\n\n for (const item of items) {\n if (item.separator) {\n const separator = document.createElement('div');\n separator.className = 'tbw-context-menu-separator';\n separator.setAttribute('role', 'separator');\n menu.appendChild(separator);\n continue;\n }\n\n const menuItem = document.createElement('div');\n menuItem.className = 'tbw-context-menu-item';\n if (item.cssClass) menuItem.classList.add(item.cssClass);\n menuItem.setAttribute('role', 'menuitem');\n menuItem.setAttribute('data-id', item.id);\n\n const disabled = isItemDisabled(item, params);\n if (disabled) {\n menuItem.classList.add('disabled');\n menuItem.setAttribute('aria-disabled', 'true');\n }\n\n if (item.icon) {\n const icon = document.createElement('span');\n icon.className = 'tbw-context-menu-icon';\n icon.innerHTML = item.icon;\n menuItem.appendChild(icon);\n } else if (hasAnyIcon) {\n // Add empty placeholder to align labels when other items have icons\n const icon = document.createElement('span');\n icon.className = 'tbw-context-menu-icon';\n icon.innerHTML = ' ';\n menuItem.appendChild(icon);\n }\n\n const label = document.createElement('span');\n label.className = 'tbw-context-menu-label';\n label.textContent = item.name;\n menuItem.appendChild(label);\n\n if (item.shortcut) {\n const shortcut = document.createElement('span');\n shortcut.className = 'tbw-context-menu-shortcut';\n if (Array.isArray(item.shortcut)) {\n item.shortcut.forEach((key, i) => {\n if (i > 0) shortcut.appendChild(document.createTextNode('+'));\n const kbd = document.createElement('kbd');\n kbd.textContent = key;\n shortcut.appendChild(kbd);\n });\n } else {\n const kbd = document.createElement('kbd');\n kbd.textContent = item.shortcut;\n shortcut.appendChild(kbd);\n }\n menuItem.appendChild(shortcut);\n }\n\n if (item.subMenu?.length) {\n const arrow = document.createElement('span');\n arrow.className = 'tbw-context-menu-arrow';\n // Use provided submenu arrow icon (string or HTMLElement)\n if (typeof submenuArrow === 'string') {\n arrow.innerHTML = submenuArrow;\n } else if (submenuArrow instanceof HTMLElement) {\n arrow.appendChild(submenuArrow.cloneNode(true));\n }\n menuItem.appendChild(arrow);\n\n // Add submenu on hover\n menuItem.addEventListener('mouseenter', () => {\n const existingSubMenu = menuItem.querySelector('.tbw-context-menu');\n if (existingSubMenu) return;\n if (!item.subMenu) return;\n\n const subMenuItems = buildMenuItems(item.subMenu, params);\n const subMenu = createMenuElement(subMenuItems, params, onAction, submenuArrow);\n subMenu.classList.add('tbw-context-submenu');\n subMenu.style.position = 'absolute';\n subMenu.style.left = '100%';\n subMenu.style.top = '0';\n menuItem.style.position = 'relative';\n menuItem.appendChild(subMenu);\n });\n\n menuItem.addEventListener('mouseleave', () => {\n const subMenu = menuItem.querySelector('.tbw-context-menu');\n if (subMenu) subMenu.remove();\n });\n }\n\n if (!disabled && item.action && !item.subMenu) {\n menuItem.addEventListener('click', (e) => {\n e.stopPropagation();\n onAction(item);\n });\n }\n\n menu.appendChild(menuItem);\n }\n\n return menu;\n}\n\n/**\n * Position the menu at the given viewport coordinates.\n * Menu is rendered in document.body with fixed positioning for top-layer behavior.\n *\n * @param menu - The menu element to position\n * @param x - Desired X coordinate (viewport)\n * @param y - Desired Y coordinate (viewport)\n */\nexport function positionMenu(menu: HTMLElement, x: number, y: number): void {\n // Use fixed positioning for top-layer behavior\n menu.style.position = 'fixed';\n menu.style.left = `${x}px`;\n menu.style.top = `${y}px`;\n menu.style.visibility = 'hidden';\n menu.style.zIndex = '10000';\n\n // Force layout to get dimensions\n const menuRect = menu.getBoundingClientRect();\n\n // Calculate visible area within viewport\n const viewportWidth = window.innerWidth;\n const viewportHeight = window.innerHeight;\n\n let left = x;\n let top = y;\n\n // Check if menu overflows right edge of viewport\n if (x + menuRect.width > viewportWidth) {\n left = x - menuRect.width;\n }\n // Check if menu overflows bottom edge of viewport\n if (y + menuRect.height > viewportHeight) {\n top = y - menuRect.height;\n }\n\n // Ensure we don't go negative\n left = Math.max(0, left);\n top = Math.max(0, top);\n\n menu.style.left = `${left}px`;\n menu.style.top = `${top}px`;\n menu.style.visibility = 'visible';\n}\n","/**\n * Context Menu Plugin (Class-based)\n *\n * Provides right-click context menu functionality for tbw-grid.\n * Supports custom menu items, submenus, icons, shortcuts, and dynamic item generation.\n */\n\nimport type { PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport contextMenuStyles from './context-menu.css?inline';\nimport { buildMenuItems, collapseSeparators, createMenuElement, positionMenu } from './menu';\nimport type { ContextMenuConfig, ContextMenuItem, ContextMenuParams, HeaderContextMenuItem } from './types';\n\n/** Query type for collecting context menu items from plugins */\nconst QUERY_GET_CONTEXT_MENU_ITEMS = 'getContextMenuItems';\n\n/** Global click handler reference for cleanup */\nlet globalClickHandler: ((e: Event) => void) | null = null;\n/** Global keydown handler reference for cleanup */\nlet globalKeydownHandler: ((e: KeyboardEvent) => void) | null = null;\n/** Global scroll handler reference for cleanup */\nlet globalScrollHandler: (() => void) | null = null;\n/** Global stylesheet for context menu (injected once) */\nlet globalStyleSheet: HTMLStyleElement | null = null;\n/** Reference count for instances using global handlers */\nlet globalHandlerRefCount = 0;\n\n/** Default menu items when none are configured */\nconst defaultItems: ContextMenuItem[] = [\n {\n id: 'copy',\n name: 'Copy',\n shortcut: 'Ctrl+C',\n action: (params) => {\n const grid = (params as ContextMenuParams & { grid?: { plugins?: { clipboard?: { copy?: () => void } } } }).grid;\n grid?.plugins?.clipboard?.copy?.();\n },\n },\n { separator: true, id: 'sep1', name: '' },\n {\n id: 'export-csv',\n name: 'Export CSV',\n action: (params) => {\n const grid = (params as ContextMenuParams & { grid?: { plugins?: { export?: { exportCsv?: () => void } } } })\n .grid;\n grid?.plugins?.export?.exportCsv?.();\n },\n },\n];\n\n/**\n * Context Menu Plugin for tbw-grid\n *\n * Adds a customizable right-click menu to grid cells. Build anything from simple\n * copy/paste actions to complex nested menus with conditional visibility, icons,\n * and keyboard shortcuts.\n *\n * ## Installation\n *\n * ```ts\n * import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';\n * ```\n *\n * ## Menu Item Structure\n *\n * | Property | Type | Description |\n * |----------|------|-------------|\n * | `id` | `string` | Unique item identifier |\n * | `name` | `string` | Display label |\n * | `icon` | `string` | Icon class or HTML |\n * | `shortcut` | `string` | Keyboard shortcut hint |\n * | `action` | `(params) => void` | Click handler |\n * | `disabled` | `boolean \\| (params) => boolean` | Disable condition |\n * | `visible` | `boolean \\| (params) => boolean` | Visibility condition |\n * | `items` | `MenuItem[]` | Submenu items |\n * | `separator` | `boolean` | Create a divider line |\n *\n * ## Menu Context (params)\n *\n * | Property | Type | Description |\n * |----------|------|-------------|\n * | `rowIndex` | `number` | Clicked row index |\n * | `colIndex` | `number` | Clicked column index |\n * | `field` | `string` | Column field name |\n * | `value` | `any` | Cell value |\n * | `row` | `any` | Full row data |\n * | `column` | `ColumnConfig` | Column configuration |\n *\n * ## CSS Custom Properties\n *\n * | Property | Default | Description |\n * |----------|---------|-------------|\n * | `--tbw-context-menu-bg` | `var(--tbw-color-panel-bg)` | Menu background |\n * | `--tbw-context-menu-fg` | `var(--tbw-color-fg)` | Menu text color |\n * | `--tbw-context-menu-hover` | `var(--tbw-color-row-hover)` | Item hover background |\n *\n * @example Basic Context Menu\n * ```ts\n * import '@toolbox-web/grid';\n * import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';\n *\n * grid.gridConfig = {\n * plugins: [\n * new ContextMenuPlugin({\n * items: [\n * { id: 'copy', name: 'Copy', shortcut: 'Ctrl+C', action: (ctx) => navigator.clipboard.writeText(ctx.value) },\n * { separator: true, id: 'sep1', name: '' },\n * { id: 'delete', name: 'Delete', action: (ctx) => removeRow(ctx.rowIndex) },\n * ],\n * }),\n * ],\n * };\n * ```\n *\n * @example Conditional Menu Items\n * ```ts\n * new ContextMenuPlugin({\n * items: [\n * { id: 'edit', name: 'Edit', visible: (ctx) => ctx.column.editable === true },\n * { id: 'delete', name: 'Delete', disabled: (ctx) => ctx.row.locked === true },\n * ],\n * })\n * ```\n *\n * @see {@link ContextMenuConfig} for configuration options\n * @see {@link ContextMenuItem} for menu item structure\n * @see {@link ContextMenuParams} for action callback parameters\n *\n * @internal Extends BaseGridPlugin\n */\nexport class ContextMenuPlugin extends BaseGridPlugin<ContextMenuConfig> {\n /**\n * Plugin manifest - declares queries used by this plugin.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n queries: [\n {\n type: QUERY_GET_CONTEXT_MENU_ITEMS,\n description: 'Collects context menu items from other plugins for header right-click menus',\n },\n ],\n };\n\n /** @internal */\n readonly name = 'contextMenu';\n\n /** @internal */\n protected override get defaultConfig(): Partial<ContextMenuConfig> {\n return {\n items: defaultItems,\n };\n }\n\n // #region Internal State\n private isOpen = false;\n private position = { x: 0, y: 0 };\n private params: ContextMenuParams | null = null;\n private menuElement: HTMLElement | null = null;\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: import('../../core/plugin/base-plugin').GridElement): void {\n super.attach(grid);\n this.installGlobalHandlers();\n globalHandlerRefCount++;\n }\n\n /** @internal */\n override detach(): void {\n if (this.menuElement) {\n this.menuElement.remove();\n this.menuElement = null;\n }\n this.isOpen = false;\n this.params = null;\n this.uninstallGlobalHandlers();\n }\n // #endregion\n\n // #region Private Methods\n\n /**\n * Sync selection with the right-clicked row.\n * If the right-clicked row is already selected, keeps the multi-selection.\n * If not, selects only the right-clicked row (standard behavior in file managers / spreadsheets).\n *\n * @returns Sorted array of selected row indices after sync\n */\n private syncSelectionOnContextMenu(rowIndex: number): number[] {\n if (rowIndex < 0) return [];\n\n // Use the query system for loose coupling — no import of SelectionPlugin needed\n const selectionResult = this.grid?.query<number[]>('getSelectedRowIndices');\n const currentSelection = selectionResult?.[0];\n\n // No selection plugin loaded\n if (!currentSelection) return [rowIndex];\n\n if (currentSelection.includes(rowIndex)) {\n // Right-clicked row is already selected — preserve multi-selection\n return currentSelection;\n }\n\n // Right-clicked row is NOT selected — select only this row\n this.grid?.query('selectRows', [rowIndex]);\n return [rowIndex];\n }\n\n /**\n * CSS variables to copy from the grid element to the context menu.\n * Includes both base variables and context-menu specific overrides.\n */\n private static readonly CSS_VARS_TO_COPY = [\n // Base palette (for themes that only set base vars)\n '--tbw-color-panel-bg',\n '--tbw-color-fg',\n '--tbw-color-fg-muted',\n '--tbw-color-border',\n '--tbw-color-row-hover',\n '--tbw-color-shadow',\n '--tbw-color-danger',\n '--tbw-border-radius',\n '--tbw-font-family',\n '--tbw-font-size-sm',\n '--tbw-font-size-xs',\n '--tbw-font-size-2xs',\n '--tbw-spacing-xs',\n '--tbw-icon-size',\n '--tbw-menu-min-width',\n '--tbw-menu-item-padding',\n '--tbw-menu-item-gap',\n // Context menu specific overrides\n '--tbw-context-menu-bg',\n '--tbw-context-menu-fg',\n '--tbw-context-menu-border',\n '--tbw-context-menu-radius',\n '--tbw-context-menu-shadow',\n '--tbw-context-menu-hover',\n '--tbw-context-menu-danger',\n '--tbw-context-menu-muted',\n '--tbw-context-menu-min-width',\n '--tbw-context-menu-font-size',\n '--tbw-context-menu-font-family',\n '--tbw-context-menu-item-padding',\n '--tbw-context-menu-item-gap',\n '--tbw-context-menu-icon-size',\n '--tbw-context-menu-shortcut-size',\n '--tbw-context-menu-arrow-size',\n ];\n\n /**\n * Copy CSS custom properties from the grid element to the menu element.\n * This allows the context menu (appended to document.body) to inherit\n * theme variables set on tbw-grid.\n */\n private copyGridStyles(menuElement: HTMLElement): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n const computed = getComputedStyle(gridEl);\n const styles: string[] = [];\n\n // Copy color-scheme so light-dark() can resolve in the context menu\n const colorScheme = computed.getPropertyValue('color-scheme').trim();\n if (colorScheme) {\n styles.push(`color-scheme: ${colorScheme}`);\n }\n\n for (const varName of ContextMenuPlugin.CSS_VARS_TO_COPY) {\n const value = computed.getPropertyValue(varName).trim();\n if (value) {\n styles.push(`${varName}: ${value}`);\n }\n }\n\n if (styles.length > 0) {\n // Append to existing inline styles (don't overwrite)\n const existing = menuElement.getAttribute('style') || '';\n menuElement.setAttribute('style', existing + styles.join('; ') + ';');\n }\n }\n\n private installGlobalHandlers(): void {\n // Inject global stylesheet for context menu (once)\n // Only inject if we have valid CSS text (Vite's ?inline import)\n // When importing from source without Vite, the import is a module object, not a string\n if (\n !globalStyleSheet &&\n typeof document !== 'undefined' &&\n typeof contextMenuStyles === 'string' &&\n contextMenuStyles\n ) {\n globalStyleSheet = document.createElement('style');\n globalStyleSheet.id = 'tbw-context-menu-styles';\n globalStyleSheet.textContent = contextMenuStyles;\n document.head.appendChild(globalStyleSheet);\n }\n\n // Close menu on click outside\n if (!globalClickHandler) {\n globalClickHandler = () => {\n const menus = document.querySelectorAll('.tbw-context-menu');\n menus.forEach((menu) => menu.remove());\n };\n document.addEventListener('click', globalClickHandler);\n }\n\n // Close on escape\n if (!globalKeydownHandler) {\n globalKeydownHandler = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n const menus = document.querySelectorAll('.tbw-context-menu');\n menus.forEach((menu) => menu.remove());\n }\n };\n document.addEventListener('keydown', globalKeydownHandler);\n }\n\n // Close on scroll (any scrollable ancestor)\n if (!globalScrollHandler) {\n globalScrollHandler = () => {\n const menus = document.querySelectorAll('.tbw-context-menu');\n menus.forEach((menu) => menu.remove());\n };\n document.addEventListener('scroll', globalScrollHandler, true);\n }\n }\n\n /**\n * Clean up global handlers when the last instance detaches.\n * Uses reference counting to ensure handlers persist while any grid uses the plugin.\n */\n private uninstallGlobalHandlers(): void {\n globalHandlerRefCount--;\n if (globalHandlerRefCount > 0) return;\n\n // Last instance - clean up all global resources\n if (globalClickHandler) {\n document.removeEventListener('click', globalClickHandler);\n globalClickHandler = null;\n }\n if (globalKeydownHandler) {\n document.removeEventListener('keydown', globalKeydownHandler);\n globalKeydownHandler = null;\n }\n if (globalScrollHandler) {\n document.removeEventListener('scroll', globalScrollHandler, true);\n globalScrollHandler = null;\n }\n if (globalStyleSheet) {\n globalStyleSheet.remove();\n globalStyleSheet = null;\n }\n }\n\n /**\n * Query all plugins for context menu items via the query system.\n * Each plugin that handles `getContextMenuItems` can return an array of HeaderContextMenuItem.\n */\n private collectPluginItems(params: ContextMenuParams): HeaderContextMenuItem[] {\n if (!this.grid) return [];\n\n const responses = this.grid.query<HeaderContextMenuItem[]>(QUERY_GET_CONTEXT_MENU_ITEMS, params);\n const items: HeaderContextMenuItem[] = [];\n\n for (const response of responses) {\n if (Array.isArray(response)) {\n items.push(...response);\n }\n }\n\n // Sort by order (default 100), then stable by insertion order\n items.sort((a, b) => (a.order ?? 100) - (b.order ?? 100));\n\n // Insert separators between different order groups\n return this.insertGroupSeparators(items);\n }\n\n /**\n * Insert separators between groups of items with different order ranges.\n * Groups are defined by the tens digit (10-19, 20-29, etc.).\n */\n private insertGroupSeparators(items: HeaderContextMenuItem[]): HeaderContextMenuItem[] {\n if (items.length <= 1) return items;\n\n const result: HeaderContextMenuItem[] = [];\n let lastGroup = -1;\n\n for (const item of items) {\n if (item.separator) {\n result.push(item);\n continue;\n }\n const group = Math.floor((item.order ?? 100) / 10);\n if (lastGroup >= 0 && group !== lastGroup) {\n result.push({\n id: `__sep-${lastGroup}-${group}`,\n label: '',\n separator: true,\n action: () => {\n /* noop */\n },\n });\n }\n lastGroup = group;\n result.push(item);\n }\n\n return result;\n }\n\n /**\n * Convert plugin-contributed HeaderContextMenuItems to the internal ContextMenuItem format.\n */\n private convertPluginItems(items: HeaderContextMenuItem[]): ContextMenuItem[] {\n return items.map((item) => ({\n id: item.id,\n name: item.label,\n icon: item.icon,\n shortcut: item.shortcut,\n disabled: item.disabled ?? false,\n action: () => item.action(),\n separator: item.separator,\n cssClass: item.cssClass,\n }));\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal */\n override afterRender(): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n // Use querySelector instead of children[0] because light DOM children\n // (e.g. <tbw-grid-column>) are re-appended before .tbw-grid-root, making\n // children[0] point to a declarative element instead of the data container.\n const container = gridEl.querySelector('.tbw-grid-root');\n if (!container) return;\n\n // Check if handler already attached\n if (container.getAttribute('data-context-menu-bound') === 'true') return;\n container.setAttribute('data-context-menu-bound', 'true');\n\n container.addEventListener('contextmenu', (e: Event) => {\n const event = e as MouseEvent;\n event.preventDefault();\n\n const target = event.target as HTMLElement;\n const cell = target.closest('[data-row][data-col]');\n const header = target.closest('[part~=\"header-cell\"]');\n\n let params: ContextMenuParams;\n\n if (cell) {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n const column = this.visibleColumns[colIndex];\n const row = this.rows[rowIndex];\n\n // Sync selection: if the right-clicked row is not already selected,\n // select it (clearing multi-selection). If it IS selected, keep all.\n const selectedRows = this.syncSelectionOnContextMenu(rowIndex);\n\n params = {\n row,\n rowIndex,\n column,\n columnIndex: colIndex,\n field: column?.field ?? '',\n value: row?.[column?.field as keyof typeof row] ?? null,\n isHeader: false,\n event,\n selectedRows,\n };\n } else if (header) {\n const colIndex = parseInt(header.getAttribute('data-col') ?? '-1', 10);\n const column = this.visibleColumns[colIndex];\n\n params = {\n row: null,\n rowIndex: -1,\n column,\n columnIndex: colIndex,\n field: column?.field ?? '',\n value: null,\n isHeader: true,\n event,\n selectedRows: [],\n };\n } else {\n return;\n }\n\n this.params = params;\n this.position = { x: event.clientX, y: event.clientY };\n\n // Collect plugin-contributed items via the query system\n const pluginItems = this.collectPluginItems(params);\n\n // Build configured items\n let items = buildMenuItems(this.config.items ?? defaultItems, params);\n\n // Merge plugin items with configured items\n if (pluginItems.length > 0) {\n const converted = this.convertPluginItems(pluginItems);\n if (items.length > 0 && converted.length > 0) {\n // Add separator between configured and plugin items\n items = [...items, { id: '__plugin-sep', name: '', separator: true }, ...converted];\n } else {\n items = [...items, ...converted];\n }\n }\n\n // Collapse consecutive/leading/trailing separators\n items = collapseSeparators(items);\n\n if (!items.length) return;\n\n // Close any open context menu (including from other grids)\n document.querySelectorAll('.tbw-context-menu').forEach((m) => m.remove());\n this.menuElement = null;\n\n this.menuElement = createMenuElement(\n items,\n params,\n (item) => {\n if (item.action) {\n item.action(params);\n }\n this.menuElement?.remove();\n this.menuElement = null;\n this.isOpen = false;\n },\n this.gridIcons.submenuArrow,\n );\n\n document.body.appendChild(this.menuElement);\n this.copyGridStyles(this.menuElement);\n positionMenu(this.menuElement, event.clientX, event.clientY);\n this.isOpen = true;\n\n this.emit('context-menu-open', { params, items });\n });\n }\n // #endregion\n\n // #region Public API\n\n /**\n * Programmatically show the context menu at the specified position.\n * @param x - X coordinate\n * @param y - Y coordinate\n * @param params - Partial context menu parameters\n */\n showMenu(x: number, y: number, params: Partial<ContextMenuParams>): void {\n const fullParams: ContextMenuParams = {\n row: params.row ?? null,\n rowIndex: params.rowIndex ?? -1,\n column: params.column ?? null,\n columnIndex: params.columnIndex ?? -1,\n field: params.field ?? '',\n value: params.value ?? null,\n isHeader: params.isHeader ?? false,\n event: params.event ?? new MouseEvent('contextmenu'),\n selectedRows: params.selectedRows ?? [],\n };\n\n const pluginItems = this.collectPluginItems(fullParams);\n let items = buildMenuItems(this.config.items ?? defaultItems, fullParams);\n\n if (pluginItems.length > 0) {\n const converted = this.convertPluginItems(pluginItems);\n if (items.length > 0 && converted.length > 0) {\n items = [...items, { id: '__plugin-sep', name: '', separator: true }, ...converted];\n } else {\n items = [...items, ...converted];\n }\n }\n\n // Collapse consecutive/leading/trailing separators\n items = collapseSeparators(items);\n\n // Close any open context menu (including from other grids)\n document.querySelectorAll('.tbw-context-menu').forEach((m) => m.remove());\n this.menuElement = null;\n\n this.menuElement = createMenuElement(\n items,\n fullParams,\n (item) => {\n if (item.action) item.action(fullParams);\n this.menuElement?.remove();\n this.menuElement = null;\n this.isOpen = false;\n },\n this.gridIcons.submenuArrow,\n );\n\n document.body.appendChild(this.menuElement);\n this.copyGridStyles(this.menuElement);\n positionMenu(this.menuElement, x, y);\n this.isOpen = true;\n }\n\n /**\n * Hide the context menu.\n */\n hideMenu(): void {\n if (this.menuElement) {\n this.menuElement.remove();\n this.menuElement = null;\n this.isOpen = false;\n }\n }\n\n /**\n * Check if the context menu is currently open.\n * @returns Whether the menu is open\n */\n isMenuOpen(): boolean {\n return this.isOpen;\n }\n // #endregion\n\n // Styles are injected globally via installGlobalHandlers() since menu renders in document.body\n}\n"],"names":["buildMenuItems","items","params","filter","item","hidden","collapseSeparators","result","separator","length","push","pop","isItemDisabled","disabled","createMenuElement","onAction","submenuArrow","DEFAULT_GRID_ICONS","menu","document","createElement","className","setAttribute","hasAnyIcon","some","icon","appendChild","menuItem","cssClass","classList","add","id","innerHTML","label","textContent","name","shortcut","Array","isArray","forEach","key","i","createTextNode","kbd","subMenu","arrow","HTMLElement","cloneNode","addEventListener","querySelector","style","position","left","top","remove","action","e","stopPropagation","positionMenu","x","y","visibility","zIndex","menuRect","getBoundingClientRect","viewportWidth","window","innerWidth","viewportHeight","innerHeight","width","height","Math","max","QUERY_GET_CONTEXT_MENU_ITEMS","globalClickHandler","globalKeydownHandler","globalScrollHandler","globalStyleSheet","globalHandlerRefCount","defaultItems","grid","plugins","clipboard","copy","export","exportCsv","ContextMenuPlugin","BaseGridPlugin","static","queries","type","description","defaultConfig","isOpen","menuElement","attach","super","this","installGlobalHandlers","detach","uninstallGlobalHandlers","syncSelectionOnContextMenu","rowIndex","selectionResult","query","currentSelection","includes","copyGridStyles","gridEl","gridElement","computed","getComputedStyle","styles","colorScheme","getPropertyValue","trim","varName","CSS_VARS_TO_COPY","value","existing","getAttribute","join","contextMenuStyles","head","querySelectorAll","removeEventListener","collectPluginItems","responses","response","sort","a","b","order","insertGroupSeparators","lastGroup","group","floor","convertPluginItems","map","afterRender","container","event","preventDefault","target","cell","closest","header","parseInt","colIndex","column","visibleColumns","row","rows","selectedRows","columnIndex","field","isHeader","clientX","clientY","pluginItems","config","converted","m","gridIcons","body","emit","showMenu","fullParams","MouseEvent","hideMenu","isMenuOpen"],"mappings":"klEAiBO,SAASA,EACdC,EACAC,GAIA,OAFmC,mBAAVD,EAAuBA,EAAMC,GAAUD,GAE/CE,OAAQC,IACH,IAAhBA,EAAKC,SACkB,mBAAhBD,EAAKC,SAAyBD,EAAKC,OAAOH,IAGzD,CAQO,SAASI,EAAmBL,GACjC,MAAMM,EAA4B,GAClC,IAAA,MAAWH,KAAQH,EACbG,EAAKI,YAEe,IAAlBD,EAAOE,QAAgBF,EAAOA,EAAOE,OAAS,GAAGD,YAEvDD,EAAOG,KAAKN,GAMd,OAHIG,EAAOE,OAAS,GAAKF,EAAOA,EAAOE,OAAS,GAAGD,WACjDD,EAAOI,MAEFJ,CACT,CASO,SAASK,EAAeR,EAAuBF,GACpD,OAAsB,I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QpJ,EAAOoJ,QAAU,KACzBK,YAAazJ,EAAOyJ,cAAe,EACnCC,MAAO1J,EAAO0J,OAAS,GACvBrC,MAAOrH,EAAOqH,OAAS,KACvBsC,SAAU3J,EAAO2J,WAAY,EAC7Bf,MAAO5I,EAAO4I,OAAS,IAAI2B,WAAW,eACtCf,aAAcxJ,EAAOwJ,cAAgB,IAGjCM,EAAc9D,KAAK6B,mBAAmByC,GAC5C,IAAIvK,EAAQD,EAAekG,KAAK+D,OAAOhK,OAAS+E,EAAcwF,GAE9D,GAAIR,EAAYvJ,OAAS,EAAG,CAC1B,MAAMyJ,EAAYhE,KAAKwC,mBAAmBsB,GAExC/J,EADEA,EAAMQ,OAAS,GAAKyJ,EAAUzJ,OAAS,EACjC,IAAIR,EAAO,CAAE8B,GAAI,eAAgBI,KAAM,GAAI3B,WAAW,MAAW0J,GAEjE,IAAIjK,KAAUiK,EAE1B,CAGAjK,EAAQK,EAAmBL,GAG3BkB,SAAS0G,iBAAiB,qBAAqBtF,QAAS4H,GAAMA,EAAE7G,UAChE4C,KAAKH,YAAc,KAEnBG,KAAKH,YAAcjF,EACjBb,EACAuK,EACCpK,IACKA,EAAKmD,QAAQnD,EAAKmD,OAAOiH,GAC7BtE,KAAKH,aAAazC,SAClB4C,KAAKH,YAAc,KACnBG,KAAKJ,QAAS,GAEhBI,KAAKkE,UAAUpJ,cAGjBG,SAASkJ,KAAK3I,YAAYwE,KAAKH,aAC/BG,KAAKU,eAAeV,KAAKH,aACzBrC,EAAawC,KAAKH,YAAapC,EAAGC,GAClCsC,KAAKJ,QAAS,CAChB,CAKA,QAAA4E,GACMxE,KAAKH,cACPG,KAAKH,YAAYzC,SACjB4C,KAAKH,YAAc,KACnBG,KAAKJ,QAAS,EAElB,CAMA,UAAA6E,GACE,OAAOzE,KAAKJ,MACd"}
|
|
1
|
+
{"version":3,"file":"context-menu.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/context-menu/menu.ts","../../../../../libs/grid/src/lib/plugins/context-menu/ContextMenuPlugin.ts"],"sourcesContent":["/**\n * Context Menu Rendering Logic\n *\n * Pure functions for building and positioning context menus.\n */\n\nimport type { IconValue } from '../../core/types';\nimport { DEFAULT_GRID_ICONS } from '../../core/types';\nimport type { ContextMenuItem, ContextMenuParams } from './types';\n\n/**\n * Build the visible menu items by resolving dynamic items and filtering hidden ones.\n *\n * @param items - Menu items configuration (array or factory function)\n * @param params - Context menu parameters for evaluating dynamic properties\n * @returns Filtered array of visible menu items\n */\nexport function buildMenuItems(\n items: ContextMenuItem[] | ((params: ContextMenuParams) => ContextMenuItem[]),\n params: ContextMenuParams,\n): ContextMenuItem[] {\n const menuItems = typeof items === 'function' ? items(params) : items;\n\n return menuItems.filter((item) => {\n if (item.hidden === true) return false;\n if (typeof item.hidden === 'function' && item.hidden(params)) return false;\n return true;\n });\n}\n\n/**\n * Remove consecutive, leading, and trailing separators from a menu item list.\n *\n * @param items - Array of menu items\n * @returns Cleaned array with no redundant separators\n */\nexport function collapseSeparators(items: ContextMenuItem[]): ContextMenuItem[] {\n const result: ContextMenuItem[] = [];\n for (const item of items) {\n if (item.separator) {\n // Skip if the last item is already a separator (consecutive) or list is empty (leading)\n if (result.length === 0 || result[result.length - 1].separator) continue;\n }\n result.push(item);\n }\n // Remove trailing separator\n if (result.length > 0 && result[result.length - 1].separator) {\n result.pop();\n }\n return result;\n}\n\n/**\n * Check if a menu item is disabled.\n *\n * @param item - The menu item to check\n * @param params - Context menu parameters for evaluating dynamic disabled state\n * @returns True if the item is disabled\n */\nexport function isItemDisabled(item: ContextMenuItem, params: ContextMenuParams): boolean {\n if (item.disabled === true) return true;\n if (typeof item.disabled === 'function') return item.disabled(params);\n return false;\n}\n\n/**\n * Create the menu DOM element from a list of menu items.\n *\n * @param items - Array of menu items to render\n * @param params - Context menu parameters for evaluating dynamic properties\n * @param onAction - Callback when a menu item action is triggered\n * @param submenuArrow - Optional custom submenu arrow icon\n * @returns The created menu element\n */\nexport function createMenuElement(\n items: ContextMenuItem[],\n params: ContextMenuParams,\n onAction: (item: ContextMenuItem) => void,\n submenuArrow: IconValue = DEFAULT_GRID_ICONS.submenuArrow,\n): HTMLElement {\n const menu = document.createElement('div');\n menu.className = 'tbw-context-menu';\n menu.setAttribute('role', 'menu');\n\n // Check if any non-separator item has an icon\n const hasAnyIcon = items.some((item) => !item.separator && item.icon);\n\n for (const item of items) {\n if (item.separator) {\n const separator = document.createElement('div');\n separator.className = 'tbw-context-menu-separator';\n separator.setAttribute('role', 'separator');\n menu.appendChild(separator);\n continue;\n }\n\n const menuItem = document.createElement('div');\n menuItem.className = 'tbw-context-menu-item';\n if (item.cssClass) menuItem.classList.add(item.cssClass);\n menuItem.setAttribute('role', 'menuitem');\n menuItem.setAttribute('data-id', item.id);\n menuItem.setAttribute('tabindex', '-1');\n\n const disabled = isItemDisabled(item, params);\n if (disabled) {\n menuItem.classList.add('disabled');\n menuItem.setAttribute('aria-disabled', 'true');\n }\n\n if (item.icon) {\n const icon = document.createElement('span');\n icon.className = 'tbw-context-menu-icon';\n icon.innerHTML = item.icon;\n menuItem.appendChild(icon);\n } else if (hasAnyIcon) {\n // Add empty placeholder to align labels when other items have icons\n const icon = document.createElement('span');\n icon.className = 'tbw-context-menu-icon';\n icon.innerHTML = ' ';\n menuItem.appendChild(icon);\n }\n\n const label = document.createElement('span');\n label.className = 'tbw-context-menu-label';\n label.textContent = item.name;\n menuItem.appendChild(label);\n\n if (item.shortcut) {\n const shortcut = document.createElement('span');\n shortcut.className = 'tbw-context-menu-shortcut';\n if (Array.isArray(item.shortcut)) {\n item.shortcut.forEach((key, i) => {\n if (i > 0) shortcut.appendChild(document.createTextNode('+'));\n const kbd = document.createElement('kbd');\n kbd.textContent = key;\n shortcut.appendChild(kbd);\n });\n } else {\n const kbd = document.createElement('kbd');\n kbd.textContent = item.shortcut;\n shortcut.appendChild(kbd);\n }\n menuItem.appendChild(shortcut);\n }\n\n if (item.subMenu?.length) {\n const arrow = document.createElement('span');\n arrow.className = 'tbw-context-menu-arrow';\n // Use provided submenu arrow icon (string or HTMLElement)\n if (typeof submenuArrow === 'string') {\n arrow.innerHTML = submenuArrow;\n } else if (submenuArrow instanceof HTMLElement) {\n arrow.appendChild(submenuArrow.cloneNode(true));\n }\n menuItem.appendChild(arrow);\n\n // Add submenu on hover\n menuItem.addEventListener('mouseenter', () => {\n const existingSubMenu = menuItem.querySelector('.tbw-context-menu');\n if (existingSubMenu) return;\n if (!item.subMenu) return;\n\n const subMenuItems = buildMenuItems(item.subMenu, params);\n const subMenu = createMenuElement(subMenuItems, params, onAction, submenuArrow);\n subMenu.classList.add('tbw-context-submenu');\n subMenu.style.position = 'absolute';\n subMenu.style.left = '100%';\n subMenu.style.top = '0';\n menuItem.style.position = 'relative';\n menuItem.appendChild(subMenu);\n });\n\n menuItem.addEventListener('mouseleave', () => {\n const subMenu = menuItem.querySelector('.tbw-context-menu');\n if (subMenu) subMenu.remove();\n });\n }\n\n if (!disabled && item.action && !item.subMenu) {\n menuItem.addEventListener('click', (e) => {\n e.stopPropagation();\n onAction(item);\n });\n }\n\n menu.appendChild(menuItem);\n }\n\n return menu;\n}\n\n/**\n * Position the menu at the given viewport coordinates.\n * Menu is rendered in document.body with fixed positioning for top-layer behavior.\n *\n * @param menu - The menu element to position\n * @param x - Desired X coordinate (viewport)\n * @param y - Desired Y coordinate (viewport)\n */\nexport function positionMenu(menu: HTMLElement, x: number, y: number): void {\n // Use fixed positioning for top-layer behavior\n menu.style.position = 'fixed';\n menu.style.left = `${x}px`;\n menu.style.top = `${y}px`;\n menu.style.visibility = 'hidden';\n menu.style.zIndex = '10000';\n\n // Force layout to get dimensions\n const menuRect = menu.getBoundingClientRect();\n\n // Calculate visible area within viewport\n const viewportWidth = window.innerWidth;\n const viewportHeight = window.innerHeight;\n\n let left = x;\n let top = y;\n\n // Check if menu overflows right edge of viewport\n if (x + menuRect.width > viewportWidth) {\n left = x - menuRect.width;\n }\n // Check if menu overflows bottom edge of viewport\n if (y + menuRect.height > viewportHeight) {\n top = y - menuRect.height;\n }\n\n // Ensure we don't go negative\n left = Math.max(0, left);\n top = Math.max(0, top);\n\n menu.style.left = `${left}px`;\n menu.style.top = `${top}px`;\n menu.style.visibility = 'visible';\n}\n\n/**\n * Attach keyboard navigation to a context menu element.\n * Handles ArrowUp/Down to move between items, Enter to activate, Escape to close.\n *\n * @param menu - The menu element (must have role=\"menu\" children with role=\"menuitem\")\n * @param onClose - Callback to run when the menu is closed via keyboard\n */\nexport function setupMenuKeyboard(menu: HTMLElement, onClose: () => void): void {\n menu.addEventListener('keydown', (e: KeyboardEvent) => {\n const items = Array.from(menu.querySelectorAll<HTMLElement>('[role=\"menuitem\"]:not(.disabled)'));\n if (!items.length) return;\n\n const current = document.activeElement as HTMLElement;\n const idx = items.indexOf(current);\n\n switch (e.key) {\n case 'ArrowDown': {\n e.preventDefault();\n const next = idx < items.length - 1 ? idx + 1 : 0;\n items[next].focus();\n break;\n }\n case 'ArrowUp': {\n e.preventDefault();\n const prev = idx > 0 ? idx - 1 : items.length - 1;\n items[prev].focus();\n break;\n }\n case 'Enter':\n case ' ': {\n e.preventDefault();\n if (current && items.includes(current)) {\n current.click();\n }\n break;\n }\n case 'Escape': {\n e.preventDefault();\n onClose();\n break;\n }\n }\n });\n}\n\n/**\n * Focus the first non-disabled menu item.\n *\n * @param menu - The menu element\n */\nexport function focusFirstMenuItem(menu: HTMLElement): void {\n const first = menu.querySelector<HTMLElement>('[role=\"menuitem\"]:not(.disabled)');\n first?.focus();\n}\n","/**\n * Context Menu Plugin (Class-based)\n *\n * Provides right-click context menu functionality for tbw-grid.\n * Supports custom menu items, submenus, icons, shortcuts, and dynamic item generation.\n */\n\nimport type { PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport contextMenuStyles from './context-menu.css?inline';\nimport {\n buildMenuItems,\n collapseSeparators,\n createMenuElement,\n focusFirstMenuItem,\n positionMenu,\n setupMenuKeyboard,\n} from './menu';\nimport type { ContextMenuConfig, ContextMenuItem, ContextMenuParams, HeaderContextMenuItem } from './types';\n\n/** Query type for collecting context menu items from plugins */\nconst QUERY_GET_CONTEXT_MENU_ITEMS = 'getContextMenuItems';\n\n/** Global click handler reference for cleanup */\nlet globalClickHandler: ((e: Event) => void) | null = null;\n/** Global keydown handler reference for cleanup */\nlet globalKeydownHandler: ((e: KeyboardEvent) => void) | null = null;\n/** Global scroll handler reference for cleanup */\nlet globalScrollHandler: (() => void) | null = null;\n/** Global stylesheet for context menu (injected once) */\nlet globalStyleSheet: HTMLStyleElement | null = null;\n/** Reference count for instances using global handlers */\nlet globalHandlerRefCount = 0;\n\n/** Default menu items when none are configured */\nconst defaultItems: ContextMenuItem[] = [\n {\n id: 'copy',\n name: 'Copy',\n shortcut: 'Ctrl+C',\n action: (params) => {\n const grid = (params as ContextMenuParams & { grid?: { plugins?: { clipboard?: { copy?: () => void } } } }).grid;\n grid?.plugins?.clipboard?.copy?.();\n },\n },\n { separator: true, id: 'sep1', name: '' },\n {\n id: 'export-csv',\n name: 'Export CSV',\n action: (params) => {\n const grid = (params as ContextMenuParams & { grid?: { plugins?: { export?: { exportCsv?: () => void } } } })\n .grid;\n grid?.plugins?.export?.exportCsv?.();\n },\n },\n];\n\n/**\n * Context Menu Plugin for tbw-grid\n *\n * Adds a customizable right-click menu to grid cells. Build anything from simple\n * copy/paste actions to complex nested menus with conditional visibility, icons,\n * and keyboard shortcuts.\n *\n * ## Installation\n *\n * ```ts\n * import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';\n * ```\n *\n * ## Menu Item Structure\n *\n * | Property | Type | Description |\n * |----------|------|-------------|\n * | `id` | `string` | Unique item identifier |\n * | `name` | `string` | Display label |\n * | `icon` | `string` | Icon class or HTML |\n * | `shortcut` | `string` | Keyboard shortcut hint |\n * | `action` | `(params) => void` | Click handler |\n * | `disabled` | `boolean \\| (params) => boolean` | Disable condition |\n * | `visible` | `boolean \\| (params) => boolean` | Visibility condition |\n * | `items` | `MenuItem[]` | Submenu items |\n * | `separator` | `boolean` | Create a divider line |\n *\n * ## Menu Context (params)\n *\n * | Property | Type | Description |\n * |----------|------|-------------|\n * | `rowIndex` | `number` | Clicked row index |\n * | `colIndex` | `number` | Clicked column index |\n * | `field` | `string` | Column field name |\n * | `value` | `any` | Cell value |\n * | `row` | `any` | Full row data |\n * | `column` | `ColumnConfig` | Column configuration |\n *\n * ## CSS Custom Properties\n *\n * | Property | Default | Description |\n * |----------|---------|-------------|\n * | `--tbw-context-menu-bg` | `var(--tbw-color-panel-bg)` | Menu background |\n * | `--tbw-context-menu-fg` | `var(--tbw-color-fg)` | Menu text color |\n * | `--tbw-context-menu-hover` | `var(--tbw-color-row-hover)` | Item hover background |\n *\n * @example Basic Context Menu\n * ```ts\n * import '@toolbox-web/grid';\n * import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';\n *\n * grid.gridConfig = {\n * plugins: [\n * new ContextMenuPlugin({\n * items: [\n * { id: 'copy', name: 'Copy', shortcut: 'Ctrl+C', action: (ctx) => navigator.clipboard.writeText(ctx.value) },\n * { separator: true, id: 'sep1', name: '' },\n * { id: 'delete', name: 'Delete', action: (ctx) => removeRow(ctx.rowIndex) },\n * ],\n * }),\n * ],\n * };\n * ```\n *\n * @example Conditional Menu Items\n * ```ts\n * new ContextMenuPlugin({\n * items: [\n * { id: 'edit', name: 'Edit', visible: (ctx) => ctx.column.editable === true },\n * { id: 'delete', name: 'Delete', disabled: (ctx) => ctx.row.locked === true },\n * ],\n * })\n * ```\n *\n * @see {@link ContextMenuConfig} for configuration options\n * @see {@link ContextMenuItem} for menu item structure\n * @see {@link ContextMenuParams} for action callback parameters\n *\n * @internal Extends BaseGridPlugin\n */\nexport class ContextMenuPlugin extends BaseGridPlugin<ContextMenuConfig> {\n /**\n * Plugin manifest - declares queries used by this plugin.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n queries: [\n {\n type: QUERY_GET_CONTEXT_MENU_ITEMS,\n description: 'Collects context menu items from other plugins for header right-click menus',\n },\n ],\n };\n\n /** @internal */\n readonly name = 'contextMenu';\n\n /** @internal */\n protected override get defaultConfig(): Partial<ContextMenuConfig> {\n return {\n items: defaultItems,\n };\n }\n\n // #region Internal State\n private isOpen = false;\n private position = { x: 0, y: 0 };\n private params: ContextMenuParams | null = null;\n private menuElement: HTMLElement | null = null;\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: import('../../core/plugin/base-plugin').GridElement): void {\n super.attach(grid);\n this.installGlobalHandlers();\n globalHandlerRefCount++;\n }\n\n /** @internal */\n override detach(): void {\n if (this.menuElement) {\n this.menuElement.remove();\n this.menuElement = null;\n }\n this.isOpen = false;\n this.params = null;\n this.uninstallGlobalHandlers();\n }\n // #endregion\n\n // #region Private Methods\n\n /**\n * Sync selection with the right-clicked row.\n * If the right-clicked row is already selected, keeps the multi-selection.\n * If not, selects only the right-clicked row (standard behavior in file managers / spreadsheets).\n *\n * @returns Sorted array of selected row indices after sync\n */\n private syncSelectionOnContextMenu(rowIndex: number): number[] {\n if (rowIndex < 0) return [];\n\n // Use the query system for loose coupling — no import of SelectionPlugin needed\n const selectionResult = this.grid?.query<number[]>('getSelectedRowIndices');\n const currentSelection = selectionResult?.[0];\n\n // No selection plugin loaded\n if (!currentSelection) return [rowIndex];\n\n if (currentSelection.includes(rowIndex)) {\n // Right-clicked row is already selected — preserve multi-selection\n return currentSelection;\n }\n\n // Right-clicked row is NOT selected — select only this row\n this.grid?.query('selectRows', [rowIndex]);\n return [rowIndex];\n }\n\n /**\n * CSS variables to copy from the grid element to the context menu.\n * Includes both base variables and context-menu specific overrides.\n */\n private static readonly CSS_VARS_TO_COPY = [\n // Base palette (for themes that only set base vars)\n '--tbw-color-panel-bg',\n '--tbw-color-fg',\n '--tbw-color-fg-muted',\n '--tbw-color-border',\n '--tbw-color-row-hover',\n '--tbw-color-shadow',\n '--tbw-color-danger',\n '--tbw-border-radius',\n '--tbw-font-family',\n '--tbw-font-size-sm',\n '--tbw-font-size-xs',\n '--tbw-font-size-2xs',\n '--tbw-spacing-xs',\n '--tbw-icon-size',\n '--tbw-menu-min-width',\n '--tbw-menu-item-padding',\n '--tbw-menu-item-gap',\n // Context menu specific overrides\n '--tbw-context-menu-bg',\n '--tbw-context-menu-fg',\n '--tbw-context-menu-border',\n '--tbw-context-menu-radius',\n '--tbw-context-menu-shadow',\n '--tbw-context-menu-hover',\n '--tbw-context-menu-danger',\n '--tbw-context-menu-muted',\n '--tbw-context-menu-min-width',\n '--tbw-context-menu-font-size',\n '--tbw-context-menu-font-family',\n '--tbw-context-menu-item-padding',\n '--tbw-context-menu-item-gap',\n '--tbw-context-menu-icon-size',\n '--tbw-context-menu-shortcut-size',\n '--tbw-context-menu-arrow-size',\n ];\n\n /**\n * Copy CSS custom properties from the grid element to the menu element.\n * This allows the context menu (appended to document.body) to inherit\n * theme variables set on tbw-grid.\n */\n private copyGridStyles(menuElement: HTMLElement): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n const computed = getComputedStyle(gridEl);\n const styles: string[] = [];\n\n // Copy color-scheme so light-dark() can resolve in the context menu\n const colorScheme = computed.getPropertyValue('color-scheme').trim();\n if (colorScheme) {\n styles.push(`color-scheme: ${colorScheme}`);\n }\n\n for (const varName of ContextMenuPlugin.CSS_VARS_TO_COPY) {\n const value = computed.getPropertyValue(varName).trim();\n if (value) {\n styles.push(`${varName}: ${value}`);\n }\n }\n\n if (styles.length > 0) {\n // Append to existing inline styles (don't overwrite)\n const existing = menuElement.getAttribute('style') || '';\n menuElement.setAttribute('style', existing + styles.join('; ') + ';');\n }\n }\n\n private installGlobalHandlers(): void {\n // Inject global stylesheet for context menu (once)\n // Only inject if we have valid CSS text (Vite's ?inline import)\n // When importing from source without Vite, the import is a module object, not a string\n if (\n !globalStyleSheet &&\n typeof document !== 'undefined' &&\n typeof contextMenuStyles === 'string' &&\n contextMenuStyles\n ) {\n globalStyleSheet = document.createElement('style');\n globalStyleSheet.id = 'tbw-context-menu-styles';\n globalStyleSheet.textContent = contextMenuStyles;\n document.head.appendChild(globalStyleSheet);\n }\n\n // Close menu on click outside\n if (!globalClickHandler) {\n globalClickHandler = () => {\n const menus = document.querySelectorAll('.tbw-context-menu');\n menus.forEach((menu) => menu.remove());\n };\n document.addEventListener('click', globalClickHandler);\n }\n\n // Close on escape\n if (!globalKeydownHandler) {\n globalKeydownHandler = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n const menus = document.querySelectorAll('.tbw-context-menu');\n menus.forEach((menu) => menu.remove());\n }\n };\n document.addEventListener('keydown', globalKeydownHandler);\n }\n\n // Close on scroll (any scrollable ancestor)\n if (!globalScrollHandler) {\n globalScrollHandler = () => {\n const menus = document.querySelectorAll('.tbw-context-menu');\n menus.forEach((menu) => menu.remove());\n };\n document.addEventListener('scroll', globalScrollHandler, true);\n }\n }\n\n /**\n * Clean up global handlers when the last instance detaches.\n * Uses reference counting to ensure handlers persist while any grid uses the plugin.\n */\n private uninstallGlobalHandlers(): void {\n globalHandlerRefCount--;\n if (globalHandlerRefCount > 0) return;\n\n // Last instance - clean up all global resources\n if (globalClickHandler) {\n document.removeEventListener('click', globalClickHandler);\n globalClickHandler = null;\n }\n if (globalKeydownHandler) {\n document.removeEventListener('keydown', globalKeydownHandler);\n globalKeydownHandler = null;\n }\n if (globalScrollHandler) {\n document.removeEventListener('scroll', globalScrollHandler, true);\n globalScrollHandler = null;\n }\n if (globalStyleSheet) {\n globalStyleSheet.remove();\n globalStyleSheet = null;\n }\n }\n\n /**\n * Query all plugins for context menu items via the query system.\n * Each plugin that handles `getContextMenuItems` can return an array of HeaderContextMenuItem.\n */\n private collectPluginItems(params: ContextMenuParams): HeaderContextMenuItem[] {\n if (!this.grid) return [];\n\n const responses = this.grid.query<HeaderContextMenuItem[]>(QUERY_GET_CONTEXT_MENU_ITEMS, params);\n const items: HeaderContextMenuItem[] = [];\n\n for (const response of responses) {\n if (Array.isArray(response)) {\n items.push(...response);\n }\n }\n\n // Sort by order (default 100), then stable by insertion order\n items.sort((a, b) => (a.order ?? 100) - (b.order ?? 100));\n\n // Insert separators between different order groups\n return this.insertGroupSeparators(items);\n }\n\n /**\n * Insert separators between groups of items with different order ranges.\n * Groups are defined by the tens digit (10-19, 20-29, etc.).\n */\n private insertGroupSeparators(items: HeaderContextMenuItem[]): HeaderContextMenuItem[] {\n if (items.length <= 1) return items;\n\n const result: HeaderContextMenuItem[] = [];\n let lastGroup = -1;\n\n for (const item of items) {\n if (item.separator) {\n result.push(item);\n continue;\n }\n const group = Math.floor((item.order ?? 100) / 10);\n if (lastGroup >= 0 && group !== lastGroup) {\n result.push({\n id: `__sep-${lastGroup}-${group}`,\n label: '',\n separator: true,\n action: () => {\n /* noop */\n },\n });\n }\n lastGroup = group;\n result.push(item);\n }\n\n return result;\n }\n\n /**\n * Convert plugin-contributed HeaderContextMenuItems to the internal ContextMenuItem format.\n */\n private convertPluginItems(items: HeaderContextMenuItem[]): ContextMenuItem[] {\n return items.map((item) => ({\n id: item.id,\n name: item.label,\n icon: item.icon,\n shortcut: item.shortcut,\n disabled: item.disabled ?? false,\n action: () => item.action(),\n separator: item.separator,\n cssClass: item.cssClass,\n }));\n }\n // #endregion\n\n // #region Hooks\n\n /**\n * Shared logic to build menu items, create the menu element, and show it.\n * Used by both the contextmenu mouse handler and keyboard triggers.\n *\n * @param params - Context menu parameters\n * @param x - Viewport X coordinate\n * @param y - Viewport Y coordinate\n * @param focusFirst - Whether to focus the first menu item (keyboard-triggered)\n */\n private openMenuAt(params: ContextMenuParams, x: number, y: number, focusFirst = false): void {\n this.params = params;\n this.position = { x, y };\n\n // Collect plugin-contributed items via the query system\n const pluginItems = this.collectPluginItems(params);\n\n // Build configured items\n let items = buildMenuItems(this.config.items ?? defaultItems, params);\n\n // Merge plugin items with configured items\n if (pluginItems.length > 0) {\n const converted = this.convertPluginItems(pluginItems);\n if (items.length > 0 && converted.length > 0) {\n items = [...items, { id: '__plugin-sep', name: '', separator: true }, ...converted];\n } else {\n items = [...items, ...converted];\n }\n }\n\n // Collapse consecutive/leading/trailing separators\n items = collapseSeparators(items);\n\n if (!items.length) return;\n\n // Close any open context menu (including from other grids)\n document.querySelectorAll('.tbw-context-menu').forEach((m) => m.remove());\n this.menuElement = null;\n\n this.menuElement = createMenuElement(\n items,\n params,\n (item) => {\n if (item.action) {\n item.action(params);\n }\n this.menuElement?.remove();\n this.menuElement = null;\n this.isOpen = false;\n },\n this.gridIcons.submenuArrow,\n );\n\n // Attach keyboard navigation (arrow keys, Enter, Escape)\n setupMenuKeyboard(this.menuElement, () => this.hideMenu());\n\n document.body.appendChild(this.menuElement);\n this.copyGridStyles(this.menuElement);\n positionMenu(this.menuElement, x, y);\n this.isOpen = true;\n\n if (focusFirst) {\n focusFirstMenuItem(this.menuElement);\n }\n\n this.emit('context-menu-open', { params, items });\n }\n\n /** @internal */\n override afterRender(): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n // Use querySelector instead of children[0] because light DOM children\n // (e.g. <tbw-grid-column>) are re-appended before .tbw-grid-root, making\n // children[0] point to a declarative element instead of the data container.\n const container = gridEl.querySelector('.tbw-grid-root');\n if (!container) return;\n\n // Check if handler already attached\n if (container.getAttribute('data-context-menu-bound') === 'true') return;\n container.setAttribute('data-context-menu-bound', 'true');\n\n container.addEventListener('contextmenu', (e: Event) => {\n const event = e as MouseEvent;\n event.preventDefault();\n\n const target = event.target as HTMLElement;\n const cell = target.closest('[data-row][data-col]');\n const header = target.closest('[part~=\"header-cell\"]');\n\n let params: ContextMenuParams;\n\n if (cell) {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n const column = this.visibleColumns[colIndex];\n const row = this.rows[rowIndex];\n\n // Sync selection: if the right-clicked row is not already selected,\n // select it (clearing multi-selection). If it IS selected, keep all.\n const selectedRows = this.syncSelectionOnContextMenu(rowIndex);\n\n params = {\n row,\n rowIndex,\n column,\n columnIndex: colIndex,\n field: column?.field ?? '',\n value: row?.[column?.field as keyof typeof row] ?? null,\n isHeader: false,\n event,\n selectedRows,\n };\n } else if (header) {\n const colIndex = parseInt(header.getAttribute('data-col') ?? '-1', 10);\n const column = this.visibleColumns[colIndex];\n\n params = {\n row: null,\n rowIndex: -1,\n column,\n columnIndex: colIndex,\n field: column?.field ?? '',\n value: null,\n isHeader: true,\n event,\n selectedRows: [],\n };\n } else {\n return;\n }\n\n this.openMenuAt(params, event.clientX, event.clientY);\n });\n }\n\n /**\n * Handle keyboard shortcuts to open the context menu.\n * Shift+F10 and the dedicated ContextMenu key open the menu at the focused cell.\n * @internal\n */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n // Shift+F10 or the dedicated ContextMenu/Application key\n const isShiftF10 = event.key === 'F10' && event.shiftKey;\n const isContextMenuKey = event.key === 'ContextMenu';\n\n if (!isShiftF10 && !isContextMenuKey) return;\n\n // Prevent the browser's native context menu from appearing\n event.preventDefault();\n\n const grid = this.grid;\n if (!grid) return;\n\n const rowIndex = grid._focusRow;\n const colIndex = grid._focusCol;\n const column = this.visibleColumns[colIndex];\n const row = this.rows[rowIndex];\n\n // Find the focused cell element to position the menu near it\n const gridEl = this.gridElement;\n const cellEl = gridEl?.querySelector<HTMLElement>(`[data-row=\"${rowIndex}\"][data-col=\"${colIndex}\"]`);\n let x = 0;\n let y = 0;\n if (cellEl) {\n const rect = cellEl.getBoundingClientRect();\n x = rect.left + rect.width / 2;\n y = rect.bottom;\n }\n\n const selectedRows = this.syncSelectionOnContextMenu(rowIndex);\n\n const params: ContextMenuParams = {\n row,\n rowIndex,\n column,\n columnIndex: colIndex,\n field: column?.field ?? '',\n value: row?.[column?.field as keyof typeof row] ?? null,\n isHeader: false,\n event: event,\n selectedRows,\n };\n\n this.openMenuAt(params, x, y, true);\n return true;\n }\n // #endregion\n\n // #region Public API\n\n /**\n * Programmatically show the context menu at the specified position.\n * @param x - X coordinate\n * @param y - Y coordinate\n * @param params - Partial context menu parameters\n */\n showMenu(x: number, y: number, params: Partial<ContextMenuParams>): void {\n const fullParams: ContextMenuParams = {\n row: params.row ?? null,\n rowIndex: params.rowIndex ?? -1,\n column: params.column ?? null,\n columnIndex: params.columnIndex ?? -1,\n field: params.field ?? '',\n value: params.value ?? null,\n isHeader: params.isHeader ?? false,\n event: params.event ?? new MouseEvent('contextmenu'),\n selectedRows: params.selectedRows ?? [],\n };\n\n this.openMenuAt(fullParams, x, y);\n }\n\n /**\n * Hide the context menu.\n */\n hideMenu(): void {\n if (this.menuElement) {\n this.menuElement.remove();\n this.menuElement = null;\n this.isOpen = false;\n }\n }\n\n /**\n * Check if the context menu is currently open.\n * @returns Whether the menu is open\n */\n isMenuOpen(): boolean {\n return this.isOpen;\n }\n // #endregion\n\n // Styles are injected globally via installGlobalHandlers() since menu renders in document.body\n}\n"],"names":["buildMenuItems","items","params","filter","item","hidden","isItemDisabled","disabled","createMenuElement","onAction","submenuArrow","DEFAULT_GRID_ICONS","menu","document","createElement","className","setAttribute","hasAnyIcon","some","separator","icon","appendChild","menuItem","cssClass","classList","add","id","innerHTML","label","textContent","name","shortcut","Array","isArray","forEach","key","i","createTextNode","kbd","subMenu","length","arrow","HTMLElement","cloneNode","addEventListener","querySelector","style","position","left","top","remove","action","e","stopPropagation","QUERY_GET_CONTEXT_MENU_ITEMS","globalClickHandler","globalKeydownHandler","globalScrollHandler","globalStyleSheet","globalHandlerRefCount","defaultItems","grid","plugins","clipboard","copy","export","exportCsv","ContextMenuPlugin","BaseGridPlugin","static","queries","type","description","defaultConfig","isOpen","x","y","menuElement","attach","super","this","installGlobalHandlers","detach","uninstallGlobalHandlers","syncSelectionOnContextMenu","rowIndex","selectionResult","query","currentSelection","includes","copyGridStyles","gridEl","gridElement","computed","getComputedStyle","styles","colorScheme","getPropertyValue","trim","push","varName","CSS_VARS_TO_COPY","value","existing","getAttribute","join","contextMenuStyles","head","querySelectorAll","removeEventListener","collectPluginItems","responses","response","sort","a","b","order","insertGroupSeparators","result","lastGroup","group","Math","floor","convertPluginItems","map","openMenuAt","focusFirst","pluginItems","config","converted","onClose","pop","collapseSeparators","m","gridIcons","hideMenu","from","current","activeElement","idx","indexOf","preventDefault","focus","click","body","visibility","zIndex","menuRect","getBoundingClientRect","viewportWidth","window","innerWidth","viewportHeight","innerHeight","width","height","max","positionMenu","first","focusFirstMenuItem","emit","afterRender","container","event","target","cell","closest","header","parseInt","colIndex","column","visibleColumns","row","rows","selectedRows","columnIndex","field","isHeader","clientX","clientY","onKeyDown","isShiftF10","shiftKey","isContextMenuKey","_focusRow","_focusCol","cellEl","rect","bottom","showMenu","fullParams","MouseEvent","isMenuOpen"],"mappings":"klEAiBO,SAASA,EACdC,EACAC,GAIA,OAFmC,mBAAVD,EAAuBA,EAAMC,GAAUD,GAE/CE,OAAQC,IACH,IAAhBA,EAAKC,SACkB,mBAAhBD,EAAKC,SAAyBD,EAAKC,OAAOH,IAGzD,CA+BO,SAASI,EAAeF,EAAuBF,GACpD,OAAsB,IAAlBE,EAAKG,UACoB,mBAAlBH,EAAKG,UAAgCH,EAAKG,SAASL,EAEhE,CAWO,SAASM,EACdP,EACAC,EACAO,EACAC,EAA0BC,EAAAA,mBAAmBD,cAE7C,MAAME,EAAOC,SAASC,cAAc,OACpCF,EAAKG,UAAY,mBACjBH,EAAKI,aAAa,OAAQ,QAG1B,MAAMC,EAAahB,EAAMiB,KAAMd,IAAUA,EAAKe,WAAaf,EAAKgB,MAEhE,IAAA,MAAWhB,KAAQH,EAAO,CACxB,GAAIG,EAAKe,UAAW,CAClB,MAAMA,EAAYN,SAASC,cAAc,OACzCK,EAAUJ,UAAY,6BACtBI,EAAUH,aAAa,OAAQ,aAC/BJ,EAAKS,YAAYF,GACjB,QACF,CAEA,MAAMG,EAAWT,SAASC,cAAc,OACxCQ,EAASP,UAAY,wBACjBX,EAAKmB,UAAUD,EAASE,UAAUC,IAAIrB,EAAKmB,UAC/CD,EAASN,aAAa,OAAQ,YAC9BM,EAASN,aAAa,UAAWZ,EAAKsB,IACtCJ,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F,SAAUnF,EAAOmF,WAAY,EAC7BqF,OAAQxK,EAAOwK,QAAU,KACzBK,YAAa7K,EAAO6K,cAAe,EACnCC,MAAO9K,EAAO8K,OAAS,GACvB1E,MAAOpG,EAAOoG,OAAS,KACvB2E,SAAU/K,EAAO+K,WAAY,EAC7Bd,MAAOjK,EAAOiK,OAAS,IAAI4B,WAAW,eACtCjB,aAAc5K,EAAO4K,cAAgB,IAGvC9F,KAAK6C,WAAWiE,EAAYnH,EAAGC,EACjC,CAKA,QAAA2D,GACMvD,KAAKH,cACPG,KAAKH,YAAY3B,SACjB8B,KAAKH,YAAc,KACnBG,KAAKN,QAAS,EAElB,CAMA,UAAAsH,GACE,OAAOhH,KAAKN,MACd"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/keyboard"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/keyboard","../../core/plugin/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid)}(this,function(t,e,i){"use strict";function n(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}const r="__tbw_null__";function s(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return n(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const s=document.createElement("option");s.value=t.nullable?r:"",s.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(s.selected=!0),n.appendChild(s)}const s=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);s.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===r?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function o(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class d{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=new Map,this.#t.set(t,n)),n.set(e,i),this.#e(t,e,!0)}clearInvalid(t,e){const i=this.#t.get(t);i&&(i.delete(e),0===i.size&&this.#t.delete(t)),this.#e(t,e,!1)}clearRowInvalid(t){const e=this.#t.get(t);if(e){const i=Array.from(e.keys());this.#t.delete(t),i.forEach(e=>this.#e(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#t.entries());this.#t.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#e(t,i,!1))})}isCellInvalid(t,e){return this.#t.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#t.get(t)?.get(e)}hasInvalidCells(t){const e=this.#t.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#t.get(t)??[])}}function l(t,e,i){const n=t.get(e);return!!n&&!a(n,i)}function a(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!a(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!a(i[t],n[t]))return!1;return!0}return!1}function c(t,e,i){t.set(e,structuredClone(i))}function u(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class h{baselines=new Map;baselinesWereCaptured=!1;newRowIds=new Set;changedRowIds=new Set;committedDirtyRowIds=new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return l(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&l(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!a(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&l(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){c(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&c(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&l(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&l(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=u(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&u(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const g='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function f(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function w(t){}function m(t,e){return!1===t.onBeforeEditClose?.(e)}function v(t,e,i,n,r,d,l){if(!n.editable)return;if(d.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:v}=t;let p;try{p=a.getRowId?.(e)}catch{}const y=p?t=>a.updateRow(p,t,"cascade"):w,E=f(n.field)?e[n.field]:void 0;d.classList.add("editing"),h.add(`${i}:${r}`);const R=d.parentElement;R&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(R);let b=!1;const I=r=>{if(b||!c&&!t.isEditSessionActive())return;const s=p?a._getRowEntry(p):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},C=()=>{if(b=!0,f(n.field)){const t=p?a._getRowEntry(p):void 0;(t?.row??e)[n.field]=E}},k=document.createElement("div");k.className="tbw-editor-host",d.innerHTML="",d.appendChild(k),k.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=k.querySelector("input,textarea,select");return void(t&&I(o(t,n,E)))}if(m(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(m(u,e))return;e.stopPropagation(),e.preventDefault(),C(),t.exitRowEdit(i,!0)}});const x=n,_=x.__editorTemplate,M=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,x)??s(n),S=E,A=`${i}:${n.field}`,L=[];v.set(A,t=>{for(const e of L)e(t)});const D=t=>{L.push(t)};if("template"===M&&_)!function(t,e,i,n,r,s,d,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:d}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!f(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(o(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(m(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(o(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(m(t.config,l))return;l.stopPropagation(),l.preventDefault(),d(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,k,x,e,E,I,C,l,i),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof M){const t=document.createElement(M);t.value=S,t.addEventListener("change",()=>I(t.value)),D(e=>{t.value=e}),k.appendChild(t),l||queueMicrotask(()=>{const t=k.querySelector(g);t?.focus({preventScroll:!0})})}else if("function"==typeof M){const t=M({row:e,rowId:p??"",value:S,field:n.field,column:n,commit:I,cancel:C,updateRow:y,onValueChange:D});if("string"==typeof t)k.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(o(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(o(r,e,n))))}(k,n,I,E),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){k.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?D(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):d.setAttribute("data-editor-managed","")}else!t&&k.hasChildNodes()&&d.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=k.querySelector(g);t?.focus({preventScroll:!0})})}else if(M&&"object"==typeof M){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),k.appendChild(t),d.setAttribute("data-editor-managed","");const i={row:e,rowId:p??"",value:S,field:n.field,column:n,commit:I,cancel:C,updateRow:y,onValueChange:D};if(M.mount)try{M.mount({placeholder:t,context:i,spec:M})}catch(T){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,T)}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:M,context:i}}))}}class p extends i.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n=-1;#r;#s;#o=-1;#d=new Map;#l=new Set;#a=new Map;#c=!1;#u=-1;#h;#g=!1;#f=!1;#w=!1;#m=null;#v=new h;#p;attach(t){super.attach(t);const e=this.disconnectSignal,i=t;if(this.#h=new d((t,e,i)=>{this.#y(t,e,i)}),this.#p={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#l,editorValueCallbacks:this.#a,isEditSessionActive:()=>-1!==this.#n,commitCellValue:(t,e,i,n)=>this.#E(t,e,i,n),exitRowEdit:(t,e)=>this.#R(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#n){if(m(this.config,t))return;this.#R(this.#n,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#n)return;const e=i.findRenderedRowElement?.(this.#n);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||m(this.config,t)||queueMicrotask(()=>{-1!==this.#n&&this.#R(this.#n,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#n)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#n&&this.#b()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#a.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#v.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#v.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(g)){if(this.#f)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#m;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#m={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#g=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(g)||(this.#g=!1,this.#m=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#g){if(m(this.config,t))return void queueMicrotask(()=>{if(this.#g){this.#I();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0}});this.#I();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(g)&&(this.#f=!1)},{signal:e}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#d.clear(),this.#v.clear(),this.#l.clear(),this.#a.clear(),this.#g=!1,this.#f=!1,this.#m=null,this.#w=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#n}onCellClick(t){if(this.#i)return!1;const e=this.grid,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(t){const i=this.grid;if("Escape"===t.key){if(this.#i&&this.#g){this.#I();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,this.requestAfterRender(),!0}if(-1!==this.#n&&!this.#i)return m(this.config,t)||this.#R(this.#n,!0),!0}if(this.#i&&!this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#n&&!this.#i){if(m(this.config,t))return!0;const n=i._rows.length-1,r=this.#n;return this.#R(r,!1),"ArrowDown"===t.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),t.preventDefault(),e.ensureCellVisible(i),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#n||this.#i)){if(t.preventDefault(),this.#w)return this.#R(this.#n,!1),!0;const e=!t.shiftKey;return this.#C(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#n)return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[e];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(f(i)){const n=!s[i];return this.#E(e,r,n,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#i&&!this.#g)return this.#b(),!0;if(-1!==this.#n)return!!m(this.config,t);const e=this.config.editOn??i.effectiveConfig?.editOn;if(!1===e||"manual"===e)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const e=i._columns?.some(t=>t.editable);if(e){const e=i._visibleColumns[r],s=i._rows[n],o=e?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:t}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===t.key){if(-1!==this.#n||this.#i)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return t.preventDefault(),this.beginCellEdit(e,r.field),!0}return!1}return!1}processColumns(t){const e=this.grid,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.grid;if(this.config.dirtyTracking&&e.getRowId&&this.#v.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#n||this.#i)return t;const i=this.#r,n=this.#s;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#n!==s&&this.#k(this.#n,s),r)}afterRender(){const t=this.grid;if(-1!==this.#n&&this.#s&&!this.#i&&t._rows[this.#n]!==this.#s){const e=t._rows.indexOf(this.#s);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#k(this.#n,e)}if(this.#c&&(this.#c=!1,this.#x(t)),-1!==this.#u){const e=this.#u;this.#u=-1,t.animateRow?.(e,"change")}const e=this.#v.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#l.size)for(const i of this.#l){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#_(l,r,a,s,d,!0)}}afterCellRender(t){if(!this.#i)return;const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable&&(s.classList.contains("editing")||this.#_(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.gridElement,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#v.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#v.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#v.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#v.getChangedRowIds()}get activeEditRow(){return this.#n}get activeEditCol(){return this.#o}isRowEditing(t){return this.#n===t}isCellEditing(t,e){return this.#l.has(`${t}:${e}`)}isRowChanged(t){const e=this.grid,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#v.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#v.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#v.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#v.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.grid;return this.#v.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#v.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#v.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#v.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#v.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#v.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#v.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#v.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#v.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#h.setInvalid(t,e,i)}clearInvalid(t,e){this.#h.clearInvalid(t,e)}clearRowInvalid(t){this.#h.clearRowInvalid(t)}clearAllInvalid(){this.#h.clearAllInvalid()}isCellInvalid(t,e){return this.#h.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#h.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#h.hasInvalidCells(t)}getInvalidFields(t){return this.#h.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#v.changedRowIds.clear(),this.#v.committedDirtyRowIds.clear(),this.#M(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.grid;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.grid,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#w=!0,this.#S(t,n,o))}beginBulkEdit(t){const e=this.grid;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#w=!1;const r=e._rows[t];this.#A(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#_(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(g);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#n&&this.#R(this.#n,!1)}cancelActiveRowEdit(){-1!==this.#n&&this.#R(this.#n,!0)}#y(t,e,i){const n=this.grid,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#h.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#k(t,e){this.#n=e;const i=new Set,n=`${t}:`;for(const o of this.#l)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#l.clear();for(const o of i)this.#l.add(o);const r=this.#d.get(t);void 0!==r&&(this.#d.delete(t),this.#d.set(e,r));const s=[];for(const[o,d]of this.#a)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#a.delete(o));for(const[o,d]of s)this.#a.set(o,d);this.#M()}#S(t,e,i){const n=this.grid,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#n!==t&&this.#A(t,r),this.#o=e,this.#_(r,t,s,e,i,!1)))}#I(){const t=this.#m;if(!t)return;const e=this.grid,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#a.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#m=null}#b(){const t=this.grid,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(g);t&&(this.#f=!1,t.focus(),this.#g=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#C(t){const i=this.grid,n=i._rows,r=this.#i?i._focusRow:this.#n,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(t?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const t=i.findRenderedRowElement?.(r),n=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(g);t?.focus({preventScroll:!0})}return void e.ensureCellVisible(i,{forceHorizontalScroll:!0})}const d=r+(t?1:-1);d>=0&&d<n.length&&(this.#i?(i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],e.ensureCellVisible(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(g);t?.focus({preventScroll:!0})}},0)):(this.#R(r,!1),i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(d),e.ensureCellVisible(i,{forceHorizontalScroll:!0})))}#M(){const t=this.grid;t._activeEditRows=this.#n,t._rowEditSnapshots=this.#d}#A(t,e){if(this.#n!==t){-1!==this.#n&&this.#R(this.#n,!1),this.#d.set(t,{...e}),this.#n=t,this.#s=e;const i=this.grid;try{this.#r=i.getRowId?.(e)??void 0}catch{this.#r=void 0}this.#M(),this.#i||this.emit("edit-open",{rowIndex:t,rowId:this.#r??"",row:e})}}#R(t,e){if(this.#n!==t)return;const i=this.grid,n=this.#d.get(t),r=i.findRenderedRowElement?.(t);let s=this.#r;const d=s?i._getRowEntry(s):void 0,l=d?.row??this.#s??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=o(s,r,i);i!==n&&this.#E(t,r,n,l)}})}if(e||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#v.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#v.isRowDirty(s,l)?this.#v.committedDirtyRowIds.add(s):this.#v.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#u=t))}this.#d.delete(t),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#w=!1,this.#M();for(const o of this.#l)o.startsWith(`${t}:`)&&this.#l.delete(o);for(const o of this.#a.keys())o.startsWith(`${t}:`)&&this.#a.delete(o);this.#c=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#x(i),this.#c=!1),!this.#i&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#E(t,e,i,n){const r=e.field;if(!f(r))return;const s=n[r];if(s===i)return;const o=this.grid;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#v.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):w;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#v.changedRowIds.add(d),this.#M(),this.config.dirtyTracking&&d){const t=this.#v.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#v.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#_(t,e,i,n,r,s){v(this.#p,t,e,i,n,r,s)}#x(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}t.EditingPlugin=p,t.defaultEditorFor=s,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/keyboard"),require("../../core/plugin/base-plugin"),require("../../core/internal/utils")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/keyboard","../../core/plugin/base-plugin","../../core/internal/utils"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid,t.TbwGrid)}(this,function(t,e,i,n){"use strict";function r(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}const s="__tbw_null__";function o(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return r(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?s:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===s?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function d(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class l{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=new Map,this.#t.set(t,n)),n.set(e,i),this.#e(t,e,!0)}clearInvalid(t,e){const i=this.#t.get(t);i&&(i.delete(e),0===i.size&&this.#t.delete(t)),this.#e(t,e,!1)}clearRowInvalid(t){const e=this.#t.get(t);if(e){const i=Array.from(e.keys());this.#t.delete(t),i.forEach(e=>this.#e(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#t.entries());this.#t.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#e(t,i,!1))})}isCellInvalid(t,e){return this.#t.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#t.get(t)?.get(e)}hasInvalidCells(t){const e=this.#t.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#t.get(t)??[])}}function a(t,e,i){const n=t.get(e);return!!n&&!c(n,i)}function c(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!c(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!c(i[t],n[t]))return!1;return!0}return!1}function u(t,e,i){t.set(e,structuredClone(i))}function h(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class g{baselines=new Map;baselinesWereCaptured=!1;newRowIds=new Set;changedRowIds=new Set;committedDirtyRowIds=new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return a(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&a(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!c(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&a(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){u(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&u(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&a(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&a(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=h(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&h(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const f='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function w(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function m(t){}function v(t,e){return!1===t.onBeforeEditClose?.(e)}function p(t,e,i,r,s,l,a){if(!r.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:g,editorValueCallbacks:p}=t;let y;try{y=c.getRowId?.(e)}catch{}const E=y?t=>c.updateRow(y,t,"cascade"):m,R=w(r.field)?e[r.field]:void 0;l.classList.add("editing"),g.add(`${i}:${s}`);const b=l.parentElement;b&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(b);let I=!1;const C=n=>{if(I||!u&&!t.isEditSessionActive())return;const s=y?c._getRowEntry(y):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,r,n,o)},k=()=>{if(I=!0,w(r.field)){const t=y?c._getRowEntry(y):void 0;(t?.row??e)[r.field]=R}},x=document.createElement("div");x.className="tbw-editor-host",l.innerHTML="",l.appendChild(x),x.addEventListener("keydown",e=>{if("Enter"===e.key){if(u){e.stopPropagation(),e.preventDefault();const t=x.querySelector("input,textarea,select");return void(t&&C(d(t,r,R)))}if(v(h,e))return;e.stopPropagation(),e.preventDefault(),I=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(u)return e.stopPropagation(),void e.preventDefault();if(v(h,e))return;e.stopPropagation(),e.preventDefault(),k(),t.exitRowEdit(i,!0)}});const _=r,S=_.__editorTemplate,M=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(c,_)??o(r),A=R,L=`${i}:${r.field}`,D=[];p.set(L,t=>{for(const e of D)e(t)});const G=t=>{D.push(t)};if("template"===M&&S)!function(t,e,i,n,r,s,o,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:o}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!w(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(d(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(d(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,x,_,e,R,C,k,a,i),G(t=>{const e=x.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof M){const t=document.createElement(M);t.value=A,t.addEventListener("change",()=>C(t.value)),G(e=>{t.value=e}),x.appendChild(t),a||queueMicrotask(()=>{const t=x.querySelector(f);t?.focus({preventScroll:!0})})}else if("function"==typeof M){const t=M({row:e,rowId:y??"",value:A,field:r.field,column:r,commit:C,cancel:k,updateRow:E,onValueChange:G});if("string"==typeof t)x.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(d(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(d(r,e,n))))}(x,r,C,R),G(t=>{const e=x.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){x.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?G(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):l.setAttribute("data-editor-managed","")}else!t&&x.hasChildNodes()&&l.setAttribute("data-editor-managed","");a||queueMicrotask(()=>{const t=x.querySelector(f);t?.focus({preventScroll:!0})})}else if(M&&"object"==typeof M){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",r.field),x.appendChild(i),l.setAttribute("data-editor-managed","");const s={row:e,rowId:y??"",value:A,field:r.field,column:r,commit:C,cancel:k,updateRow:E,onValueChange:G};if(M.mount)try{M.mount({placeholder:i,context:s,spec:M})}catch(T){console.warn(`${n.gridPrefix(t.grid.id)} External editor mount error for column '${r.field}':`,T)}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:M,context:s}}))}}class y extends i.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n=-1;#r;#s;#o=-1;#d=new Map;#l=new Set;#a=new Map;#c=!1;#u=-1;#h;#g=!1;#f=!1;#w=!1;#m=null;#v=new g;#p;get#y(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#y;if(this.#h=new l((t,e,i)=>{this.#E(t,e,i)}),this.#p={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#l,editorValueCallbacks:this.#a,isEditSessionActive:()=>-1!==this.#n,commitCellValue:(t,e,i,n)=>this.#R(t,e,i,n),exitRowEdit:(t,e)=>this.#b(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#v.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#n){if(v(this.config,t))return;this.#b(this.#n,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#n)return;const e=i.findRenderedRowElement?.(this.#n);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||v(this.config,t)||queueMicrotask(()=>{-1!==this.#n&&this.#b(this.#n,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#n)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#n&&this.#I()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#a.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#v.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#v.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(f)){if(this.#f)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#m;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#m={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#g=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(f)||(this.#g=!1,this.#m=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#g){if(v(this.config,t))return void queueMicrotask(()=>{if(this.#g){this.#C();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0}});this.#C();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(f)&&(this.#f=!1)},{signal:e}))}detach(){this.#y._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#d.clear(),this.#v.clear(),this.#l.clear(),this.#a.clear(),this.#g=!1,this.#f=!1,this.#m=null,this.#w=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#n}onCellClick(t){if(this.#i)return!1;const e=this.#y,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(t){const i=this.#y;if("Escape"===t.key){if(this.#i&&this.#g){this.#C();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,this.requestAfterRender(),!0}if(-1!==this.#n&&!this.#i)return v(this.config,t)||this.#b(this.#n,!0),!0}if(this.#i&&!this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#n&&!this.#i){if(v(this.config,t))return!0;const n=i._rows.length-1,r=this.#n;return this.#b(r,!1),"ArrowDown"===t.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),t.preventDefault(),e.ensureCellVisible(i),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#n||this.#i)){if(t.preventDefault(),this.#w)return this.#b(this.#n,!1),!0;const e=!t.shiftKey;return this.#k(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#n)return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[e];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(w(i)){const n=!s[i];return this.#R(e,r,n,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#i&&!this.#g)return this.#I(),!0;if(-1!==this.#n)return!!v(this.config,t);const e=this.config.editOn??i.effectiveConfig?.editOn;if(!1===e||"manual"===e)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const e=i._columns?.some(t=>t.editable);if(e){const e=i._visibleColumns[r],s=i._rows[n],o=e?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:t}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===t.key){if(-1!==this.#n||this.#i)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return t.preventDefault(),this.beginCellEdit(e,r.field),!0}return!1}return!1}processColumns(t){const e=this.#y,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.#y;if(this.config.dirtyTracking&&e.getRowId&&this.#v.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#n||this.#i)return t;const i=this.#r,n=this.#s;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#n!==s&&this.#x(this.#n,s),r)}afterRender(){const t=this.#y;if(-1!==this.#n&&this.#s&&!this.#i&&t._rows[this.#n]!==this.#s){const e=t._rows.indexOf(this.#s);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#x(this.#n,e)}if(this.#c&&(this.#c=!1,this.#_(t)),-1!==this.#u){const e=this.#u;this.#u=-1,t.animateRow?.(e,"change")}const e=this.#v.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#l.size)for(const i of this.#l){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#S(l,r,a,s,d,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable?s.removeAttribute("aria-readonly"):s.setAttribute("aria-readonly","true"),this.#i&&n.editable&&(s.classList.contains("editing")||this.#S(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#y,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#v.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#v.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#v.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#v.getChangedRowIds()}get activeEditRow(){return this.#n}get activeEditCol(){return this.#o}isRowEditing(t){return this.#n===t}isCellEditing(t,e){return this.#l.has(`${t}:${e}`)}isRowChanged(t){const e=this.#y,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#v.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#v.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#v.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#v.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#y;return this.#v.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#v.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#y;this.#v.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#v.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#v.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#y;return this.#v.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#y;return this.#v.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#v.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#y;this.#v.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#h.setInvalid(t,e,i)}clearInvalid(t,e){this.#h.clearInvalid(t,e)}clearRowInvalid(t){this.#h.clearRowInvalid(t)}clearAllInvalid(){this.#h.clearAllInvalid()}isCellInvalid(t,e){return this.#h.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#h.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#h.hasInvalidCells(t)}getInvalidFields(t){return this.#h.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#v.changedRowIds.clear(),this.#v.committedDirtyRowIds.clear(),this.#M(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.#y;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#y,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#w=!0,this.#A(t,n,o))}beginBulkEdit(t){const e=this.#y;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#w=!1;const r=e._rows[t];this.#L(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#S(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(f);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#n&&this.#b(this.#n,!1)}cancelActiveRowEdit(){-1!==this.#n&&this.#b(this.#n,!0)}#E(t,e,i){const n=this.#y,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#h.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#x(t,e){this.#n=e;const i=new Set,n=`${t}:`;for(const o of this.#l)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#l.clear();for(const o of i)this.#l.add(o);const r=this.#d.get(t);void 0!==r&&(this.#d.delete(t),this.#d.set(e,r));const s=[];for(const[o,d]of this.#a)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#a.delete(o));for(const[o,d]of s)this.#a.set(o,d);this.#M()}#A(t,e,i){const n=this.#y,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#n!==t&&this.#L(t,r),this.#o=e,this.#S(r,t,s,e,i,!1)))}#C(){const t=this.#m;if(!t)return;const e=this.#y,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#a.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#m=null}#I(){const t=this.#y,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(f);t&&(this.#f=!1,t.focus(),this.#g=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#k(t){const i=this.#y,n=i._rows,r=this.#i?i._focusRow:this.#n,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(t?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const t=i.findRenderedRowElement?.(r),n=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(f);t?.focus({preventScroll:!0})}return void e.ensureCellVisible(i,{forceHorizontalScroll:!0})}const d=r+(t?1:-1);d>=0&&d<n.length&&(this.#i?(i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],e.ensureCellVisible(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(f);t?.focus({preventScroll:!0})}},0)):(this.#b(r,!1),i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(d),e.ensureCellVisible(i,{forceHorizontalScroll:!0})))}#M(){const t=this.#y;t._activeEditRows=this.#n,t._rowEditSnapshots=this.#d}#L(t,e){if(this.#n!==t){-1!==this.#n&&this.#b(this.#n,!1),this.#d.set(t,{...e}),this.#n=t,this.#s=e;const i=this.#y;try{this.#r=i.getRowId?.(e)??void 0}catch{this.#r=void 0}this.#M(),this.#i||this.emit("edit-open",{rowIndex:t,rowId:this.#r??"",row:e})}}#b(t,e){if(this.#n!==t)return;const i=this.#y,n=this.#d.get(t),r=i.findRenderedRowElement?.(t);let s=this.#r;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#s??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=d(s,r,i);i!==n&&this.#R(t,r,n,l)}})}if(e||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#v.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#v.isRowDirty(s,l)?this.#v.committedDirtyRowIds.add(s):this.#v.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#u=t))}this.#d.delete(t),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#w=!1,this.#M();for(const d of this.#l)d.startsWith(`${t}:`)&&this.#l.delete(d);for(const d of this.#a.keys())d.startsWith(`${t}:`)&&this.#a.delete(d);this.#c=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#_(i),this.#c=!1),!this.#i&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#R(t,e,i,n){const r=e.field;if(!w(r))return;const s=n[r];if(s===i)return;const o=this.#y;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#v.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):m;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#v.changedRowIds.add(d),this.#M(),this.config.dirtyTracking&&d){const t=this.#v.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#v.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#S(t,e,i,n,r,s){p(this.#p,t,e,i,n,r,s)}#_(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}t.EditingPlugin=y,t.defaultEditorFor=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=editing.umd.js.map
|