@warkypublic/svelix 0.1.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/LICENSE +73 -0
- package/README.md +3 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +2 -0
- package/dist/components/BetterMenu/BetterMenu.stories.js +68 -0
- package/dist/components/BetterMenu/BetterMenu.svelte +38 -0
- package/dist/components/BetterMenu/BetterMenu.svelte.d.ts +14 -0
- package/dist/components/BetterMenu/BetterMenuAsyncButton.svelte +34 -0
- package/dist/components/BetterMenu/BetterMenuAsyncButton.svelte.d.ts +8 -0
- package/dist/components/BetterMenu/BetterMenuPreview.svelte +43 -0
- package/dist/components/BetterMenu/BetterMenuPreview.svelte.d.ts +7 -0
- package/dist/components/BetterMenu/MenuRenderer.svelte +75 -0
- package/dist/components/BetterMenu/MenuRenderer.svelte.d.ts +6 -0
- package/dist/components/BetterMenu/Plan.mdx +155 -0
- package/dist/components/BetterMenu/index.d.ts +4 -0
- package/dist/components/BetterMenu/index.js +4 -0
- package/dist/components/BetterMenu/store.d.ts +10 -0
- package/dist/components/BetterMenu/store.js +48 -0
- package/dist/components/BetterMenu/types.d.ts +24 -0
- package/dist/components/BetterMenu/types.js +1 -0
- package/dist/components/Boxer/Boxer.stories.d.ts +19 -0
- package/dist/components/Boxer/Boxer.stories.js +102 -0
- package/dist/components/Boxer/Boxer.svelte +411 -0
- package/dist/components/Boxer/Boxer.svelte.d.ts +11 -0
- package/dist/components/Boxer/BoxerTarget.svelte +88 -0
- package/dist/components/Boxer/BoxerTarget.svelte.d.ts +20 -0
- package/dist/components/Boxer/Plan.mdx +140 -0
- package/dist/components/Boxer/features.mdx +81 -0
- package/dist/components/Boxer/index.d.ts +4 -0
- package/dist/components/Boxer/index.js +4 -0
- package/dist/components/Boxer/store.d.ts +26 -0
- package/dist/components/Boxer/store.js +103 -0
- package/dist/components/Boxer/types.d.ts +46 -0
- package/dist/components/Boxer/types.js +1 -0
- package/dist/components/Button.stories.d.ts +11 -0
- package/dist/components/Button.stories.js +109 -0
- package/dist/components/Button.svelte +50 -0
- package/dist/components/Button.svelte.d.ts +12 -0
- package/dist/components/ButtonPreview.svelte +14 -0
- package/dist/components/ButtonPreview.svelte.d.ts +4 -0
- package/dist/components/ErrorBoundary/ErrorBoundary.stories.js +17 -0
- package/dist/components/ErrorBoundary/ErrorBoundary.svelte +127 -0
- package/dist/components/ErrorBoundary/ErrorBoundary.svelte.d.ts +13 -0
- package/dist/components/ErrorBoundary/ErrorBoundaryPreview.svelte +28 -0
- package/dist/components/ErrorBoundary/ErrorBoundaryPreview.svelte.d.ts +6 -0
- package/dist/components/ErrorBoundary/ErrorManager.d.ts +15 -0
- package/dist/components/ErrorBoundary/ErrorManager.js +158 -0
- package/dist/components/ErrorBoundary/Plan.mdx +182 -0
- package/dist/components/ErrorBoundary/index.d.ts +3 -0
- package/dist/components/ErrorBoundary/index.js +3 -0
- package/dist/components/ErrorBoundary/types.d.ts +43 -0
- package/dist/components/ErrorBoundary/types.js +1 -0
- package/dist/components/Former/Former.stories.js +228 -0
- package/dist/components/Former/Former.svelte +405 -0
- package/dist/components/Former/Former.svelte.d.ts +33 -0
- package/dist/components/Former/FormerButtonArea.svelte +93 -0
- package/dist/components/Former/FormerButtonArea.svelte.d.ts +15 -0
- package/dist/components/Former/FormerDrawer.svelte +115 -0
- package/dist/components/Former/FormerDrawer.svelte.d.ts +19 -0
- package/dist/components/Former/FormerDrawerPreview.svelte +226 -0
- package/dist/components/Former/FormerDrawerPreview.svelte.d.ts +7 -0
- package/dist/components/Former/FormerModal.svelte +108 -0
- package/dist/components/Former/FormerModal.svelte.d.ts +14 -0
- package/dist/components/Former/FormerModalPreview.svelte +226 -0
- package/dist/components/Former/FormerModalPreview.svelte.d.ts +7 -0
- package/dist/components/Former/FormerPreview.svelte +238 -0
- package/dist/components/Former/FormerPreview.svelte.d.ts +8 -0
- package/dist/components/Former/FormerResolveSpecAPI.d.ts +26 -0
- package/dist/components/Former/FormerResolveSpecAPI.js +44 -0
- package/dist/components/Former/FormerRestApiPreview.svelte +198 -0
- package/dist/components/Former/FormerRestApiPreview.svelte.d.ts +3 -0
- package/dist/components/Former/FormerRestHeadSpecAPI.d.ts +8 -0
- package/dist/components/Former/FormerRestHeadSpecAPI.js +38 -0
- package/dist/components/Former/Plan.mdx +115 -0
- package/dist/components/Former/formerState.svelte.d.ts +21 -0
- package/dist/components/Former/formerState.svelte.js +57 -0
- package/dist/components/Former/index.d.ts +8 -0
- package/dist/components/Former/index.js +8 -0
- package/dist/components/Former/types.d.ts +61 -0
- package/dist/components/Former/types.js +1 -0
- package/dist/components/FormerControllers/ButtonCtrl.stories.js +102 -0
- package/dist/components/FormerControllers/ButtonCtrl.svelte +65 -0
- package/dist/components/FormerControllers/ButtonCtrl.svelte.d.ts +14 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.stories.js +73 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.svelte +630 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.svelte.d.ts +54 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.utils.d.ts +40 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.utils.js +688 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlCalendar.svelte +193 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlCalendar.svelte.d.ts +13 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlPickerPanel.svelte +119 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlPickerPanel.svelte.d.ts +39 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlTimeFields.svelte +343 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlTimeFields.svelte.d.ts +27 -0
- package/dist/components/FormerControllers/DateTimeCtrl/index.d.ts +2 -0
- package/dist/components/FormerControllers/DateTimeCtrl/index.js +1 -0
- package/dist/components/FormerControllers/FormerControllers.stories.js +76 -0
- package/dist/components/FormerControllers/IconButtonCtrl.stories.js +77 -0
- package/dist/components/FormerControllers/IconButtonCtrl.svelte +64 -0
- package/dist/components/FormerControllers/IconButtonCtrl.svelte.d.ts +13 -0
- package/dist/components/FormerControllers/InlineWrapper.stories.js +133 -0
- package/dist/components/FormerControllers/InlineWrapper.svelte +85 -0
- package/dist/components/FormerControllers/InlineWrapper.svelte.d.ts +16 -0
- package/dist/components/FormerControllers/InlineWrapperPreview.svelte +41 -0
- package/dist/components/FormerControllers/InlineWrapperPreview.svelte.d.ts +13 -0
- package/dist/components/FormerControllers/NativeSelectCtrl.stories.js +79 -0
- package/dist/components/FormerControllers/NativeSelectCtrl.svelte +61 -0
- package/dist/components/FormerControllers/NativeSelectCtrl.svelte.d.ts +13 -0
- package/dist/components/FormerControllers/NumberInputCtrl.stories.js +77 -0
- package/dist/components/FormerControllers/NumberInputCtrl.svelte +61 -0
- package/dist/components/FormerControllers/NumberInputCtrl.svelte.d.ts +11 -0
- package/dist/components/FormerControllers/PasswordInputCtrl.stories.js +79 -0
- package/dist/components/FormerControllers/PasswordInputCtrl.svelte +57 -0
- package/dist/components/FormerControllers/PasswordInputCtrl.svelte.d.ts +8 -0
- package/dist/components/FormerControllers/Plan.mdx +129 -0
- package/dist/components/FormerControllers/SwitchCtrl.stories.js +73 -0
- package/dist/components/FormerControllers/SwitchCtrl.svelte +38 -0
- package/dist/components/FormerControllers/SwitchCtrl.svelte.d.ts +8 -0
- package/dist/components/FormerControllers/TextAreaCtrl.stories.js +71 -0
- package/dist/components/FormerControllers/TextAreaCtrl.svelte +47 -0
- package/dist/components/FormerControllers/TextAreaCtrl.svelte.d.ts +9 -0
- package/dist/components/FormerControllers/TextInputCtrl.svelte +47 -0
- package/dist/components/FormerControllers/TextInputCtrl.svelte.d.ts +9 -0
- package/dist/components/FormerControllers/index.d.ts +12 -0
- package/dist/components/FormerControllers/index.js +11 -0
- package/dist/components/FormerControllers/types.d.ts +10 -0
- package/dist/components/FormerControllers/types.js +1 -0
- package/dist/components/GlobalStateStore/GlobalStateStore.d.ts +19 -0
- package/dist/components/GlobalStateStore/GlobalStateStore.js +349 -0
- package/dist/components/GlobalStateStore/GlobalStateStore.types.d.ts +127 -0
- package/dist/components/GlobalStateStore/GlobalStateStore.types.js +2 -0
- package/dist/components/GlobalStateStore/GlobalStateStore.utils.d.ts +4 -0
- package/dist/components/GlobalStateStore/GlobalStateStore.utils.js +92 -0
- package/dist/components/GlobalStateStore/GlobalStateStoreContext.d.ts +10 -0
- package/dist/components/GlobalStateStore/GlobalStateStoreContext.js +10 -0
- package/dist/components/GlobalStateStore/GlobalStateStoreProvider.svelte +113 -0
- package/dist/components/GlobalStateStore/GlobalStateStoreProvider.svelte.d.ts +16 -0
- package/dist/components/GlobalStateStore/index.d.ts +5 -0
- package/dist/components/GlobalStateStore/index.js +3 -0
- package/dist/components/Gridler/CellEditor.svelte +126 -0
- package/dist/components/Gridler/CellEditor.svelte.d.ts +15 -0
- package/dist/components/Gridler/Gridler.stories.d.ts +56 -0
- package/dist/components/Gridler/Gridler.stories.js +262 -0
- package/dist/components/Gridler/Gridler.svelte +778 -0
- package/dist/components/Gridler/Gridler.svelte.d.ts +11 -0
- package/dist/components/Gridler/GridlerHeader.svelte +179 -0
- package/dist/components/Gridler/GridlerHeader.svelte.d.ts +13 -0
- package/dist/components/Gridler/Plan.mdx +692 -0
- package/dist/components/Gridler/index.d.ts +6 -0
- package/dist/components/Gridler/index.js +6 -0
- package/dist/components/Gridler/types.d.ts +84 -0
- package/dist/components/Gridler/types.js +16 -0
- package/dist/components/Gridler/utils/rendering.d.ts +16 -0
- package/dist/components/Gridler/utils/rendering.js +202 -0
- package/dist/components/Gridler/utils/scrolling.d.ts +12 -0
- package/dist/components/Gridler/utils/scrolling.js +97 -0
- package/dist/components/Portal/Portal.mdx +125 -0
- package/dist/components/Portal/Portal.svelte +47 -0
- package/dist/components/Portal/Portal.svelte.d.ts +18 -0
- package/dist/components/Screenshot/Screenshot.stories.d.ts +16 -0
- package/dist/components/Screenshot/Screenshot.stories.js +15 -0
- package/dist/components/Screenshot/Screenshot.svelte +54 -0
- package/dist/components/Screenshot/Screenshot.svelte.d.ts +3 -0
- package/dist/components/Screenshot/Screenshot.util.d.ts +1 -0
- package/dist/components/Screenshot/Screenshot.util.js +49 -0
- package/dist/components/Screenshot/index.d.ts +2 -0
- package/dist/components/Screenshot/index.js +2 -0
- package/dist/components/Svark/Svark.stories.js +659 -0
- package/dist/components/Svark/Svark.svelte +691 -0
- package/dist/components/Svark/Svark.svelte.d.ts +26 -0
- package/dist/components/Svark/SvarkResolveSpecAdapter.d.ts +16 -0
- package/dist/components/Svark/SvarkResolveSpecAdapter.js +68 -0
- package/dist/components/Svark/SvarkSelectionDemo.svelte +59 -0
- package/dist/components/Svark/SvarkSelectionDemo.svelte.d.ts +4 -0
- package/dist/components/Svark/index.d.ts +3 -0
- package/dist/components/Svark/index.js +3 -0
- package/dist/components/Svark/types.d.ts +63 -0
- package/dist/components/Svark/types.js +1 -0
- package/dist/components/VTree/VTree.models.d.ts +12 -0
- package/dist/components/VTree/VTree.models.js +1 -0
- package/dist/components/VTree/VTree.stories.d.ts +40 -0
- package/dist/components/VTree/VTree.stories.js +112 -0
- package/dist/components/VTree/VTree.svelte +471 -0
- package/dist/components/VTree/VTree.svelte.d.ts +5 -0
- package/dist/components/VTree/VTreeContextMenu.svelte +40 -0
- package/dist/components/VTree/VTreeContextMenu.svelte.d.ts +11 -0
- package/dist/components/VTree/VTreeEventsDemo.svelte +88 -0
- package/dist/components/VTree/VTreeEventsDemo.svelte.d.ts +3 -0
- package/dist/components/VTree/VTreeResolveSpecAdapter.d.ts +14 -0
- package/dist/components/VTree/VTreeResolveSpecAdapter.js +103 -0
- package/dist/components/VTree/VTreeRow.svelte +136 -0
- package/dist/components/VTree/VTreeRow.svelte.d.ts +37 -0
- package/dist/components/VTree/VTreeSearch.svelte +25 -0
- package/dist/components/VTree/VTreeSearch.svelte.d.ts +8 -0
- package/dist/components/VTree/VTreeVirtualViewport.svelte +154 -0
- package/dist/components/VTree/VTreeVirtualViewport.svelte.d.ts +45 -0
- package/dist/components/VTree/index.d.ts +3 -0
- package/dist/components/VTree/index.js +3 -0
- package/dist/components/VTree/types.d.ts +83 -0
- package/dist/components/VTree/types.js +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.js +11 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +20 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.js +1 -0
- package/dist/themes/svelix_orange.css +205 -0
- package/dist/utils/PropsWithChildren.d.ts +5 -0
- package/dist/utils/PropsWithChildren.js +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -0
- package/package.json +85 -0
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { GridlerProps, GridlerColumn, GridlerCell, GridlerTheme, Item, Selection, VisibleRange } from './types';
|
|
4
|
+
import { DEFAULT_THEME } from './types';
|
|
5
|
+
import { drawCell, drawHeaderCell, isInSelection } from './utils/rendering';
|
|
6
|
+
import { calculateVisibleRange, getColumnX, getTotalWidth, getTotalHeight, getCellFromPoint, scrollToCell, getResizeHandle, getColumnFromX } from './utils/scrolling';
|
|
7
|
+
|
|
8
|
+
export interface Props extends Partial<GridlerProps> {
|
|
9
|
+
columns: GridlerColumn[];
|
|
10
|
+
rows: number;
|
|
11
|
+
getCellContent: (item: Item) => GridlerCell;
|
|
12
|
+
children?: Snippet;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
columns,
|
|
17
|
+
rows,
|
|
18
|
+
getCellContent,
|
|
19
|
+
onCellEdited,
|
|
20
|
+
onRowAppended,
|
|
21
|
+
onColumnMoved,
|
|
22
|
+
onDelete,
|
|
23
|
+
onSelectionCleared,
|
|
24
|
+
width = '100%',
|
|
25
|
+
height = '400px',
|
|
26
|
+
rowHeight = 34,
|
|
27
|
+
headerHeight = 36,
|
|
28
|
+
readonly = false,
|
|
29
|
+
fixedColumns = 0,
|
|
30
|
+
rowMarkers = 'none',
|
|
31
|
+
showSearch = false,
|
|
32
|
+
searchValue = '',
|
|
33
|
+
theme = {},
|
|
34
|
+
selection = { type: 'none' } as Selection,
|
|
35
|
+
onSelectionChange,
|
|
36
|
+
children,
|
|
37
|
+
}: Props = $props();
|
|
38
|
+
|
|
39
|
+
const mergedTheme: GridlerTheme = $derived({ ...DEFAULT_THEME, ...theme });
|
|
40
|
+
|
|
41
|
+
let scrollX = $state(0);
|
|
42
|
+
let scrollY = $state(0);
|
|
43
|
+
let currentSelection = $state<Selection>(selection);
|
|
44
|
+
let focusedCell = $state<Item | null>(null);
|
|
45
|
+
let isEditing = $state(false);
|
|
46
|
+
let editingCell = $state<Item | null>(null);
|
|
47
|
+
let isDragging = $state(false);
|
|
48
|
+
let dragStart = $state<Item | null>(null);
|
|
49
|
+
let resizingColumn = $state<number | null>(null);
|
|
50
|
+
let draggingHeaderCol = $state<number | null>(null);
|
|
51
|
+
let dragHeaderCurrentX = $state(0);
|
|
52
|
+
let announcement = $state('');
|
|
53
|
+
|
|
54
|
+
let containerRef: HTMLDivElement | undefined = $state();
|
|
55
|
+
let canvasRef: HTMLCanvasElement | undefined = $state();
|
|
56
|
+
let scrollRef: HTMLDivElement | undefined = $state();
|
|
57
|
+
let ctx: CanvasRenderingContext2D | null = $derived(canvasRef?.getContext('2d') ?? null);
|
|
58
|
+
|
|
59
|
+
let containerWidth = $state(0);
|
|
60
|
+
let containerHeight = $state(0);
|
|
61
|
+
|
|
62
|
+
let drawPending = false;
|
|
63
|
+
|
|
64
|
+
const rowMarkerWidth = $derived(rowMarkers !== 'none' ? 40 : 0);
|
|
65
|
+
const totalWidth = $derived(getTotalWidth(columns) + rowMarkerWidth);
|
|
66
|
+
const totalHeight = $derived(getTotalHeight(rows, rowHeight));
|
|
67
|
+
|
|
68
|
+
const visibleRange: VisibleRange = $derived.by(() => {
|
|
69
|
+
if (!containerWidth || !containerHeight) {
|
|
70
|
+
return { firstCol: 0, lastCol: 0, firstRow: 0, lastRow: 0 };
|
|
71
|
+
}
|
|
72
|
+
return calculateVisibleRange(
|
|
73
|
+
scrollX,
|
|
74
|
+
scrollY,
|
|
75
|
+
containerWidth,
|
|
76
|
+
containerHeight,
|
|
77
|
+
columns,
|
|
78
|
+
rowHeight,
|
|
79
|
+
headerHeight,
|
|
80
|
+
rows
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
$effect(() => {
|
|
85
|
+
void visibleRange;
|
|
86
|
+
void searchValue;
|
|
87
|
+
void currentSelection;
|
|
88
|
+
if (ctx && containerWidth > 0 && containerHeight > 0) {
|
|
89
|
+
scheduleDraw();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
function scheduleDraw() {
|
|
94
|
+
if (drawPending) return;
|
|
95
|
+
drawPending = true;
|
|
96
|
+
requestAnimationFrame(() => {
|
|
97
|
+
drawPending = false;
|
|
98
|
+
renderFrame();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function renderFrame() {
|
|
103
|
+
if (!ctx || !canvasRef) return;
|
|
104
|
+
|
|
105
|
+
const dpr = window.devicePixelRatio || 1;
|
|
106
|
+
const canvasWidth = containerWidth;
|
|
107
|
+
const canvasHeight = containerHeight;
|
|
108
|
+
|
|
109
|
+
canvasRef.width = canvasWidth * dpr;
|
|
110
|
+
canvasRef.height = canvasHeight * dpr;
|
|
111
|
+
canvasRef.style.width = `${canvasWidth}px`;
|
|
112
|
+
canvasRef.style.height = `${canvasHeight}px`;
|
|
113
|
+
ctx.scale(dpr, dpr);
|
|
114
|
+
|
|
115
|
+
ctx.fillStyle = mergedTheme.bgCell;
|
|
116
|
+
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
|
|
117
|
+
|
|
118
|
+
renderHeaders(ctx, visibleRange);
|
|
119
|
+
renderCells(ctx, visibleRange);
|
|
120
|
+
renderRowMarkers(ctx, visibleRange);
|
|
121
|
+
renderDragIndicator(ctx);
|
|
122
|
+
|
|
123
|
+
if (fixedColumns > 0) {
|
|
124
|
+
renderFixedColumns(ctx, visibleRange);
|
|
125
|
+
renderFixedHeaders(ctx);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function renderHeaders(ctx: CanvasRenderingContext2D, range: VisibleRange) {
|
|
130
|
+
const isColSelected = (col: number) =>
|
|
131
|
+
currentSelection.type === 'column' && currentSelection.columns.includes(col);
|
|
132
|
+
|
|
133
|
+
for (let col = Math.max(range.firstCol, fixedColumns); col <= range.lastCol; col++) {
|
|
134
|
+
const column = columns[col];
|
|
135
|
+
if (!column) continue;
|
|
136
|
+
const x = getColumnX(columns, col) - scrollX + rowMarkerWidth;
|
|
137
|
+
drawHeaderCell(ctx, x, 0, column.width, headerHeight, column.title, mergedTheme, isColSelected(col));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function renderFixedHeaders(ctx: CanvasRenderingContext2D) {
|
|
142
|
+
const isColSelected = (col: number) =>
|
|
143
|
+
currentSelection.type === 'column' && currentSelection.columns.includes(col);
|
|
144
|
+
|
|
145
|
+
for (let col = 0; col < fixedColumns && col < columns.length; col++) {
|
|
146
|
+
const column = columns[col];
|
|
147
|
+
const x = getColumnX(columns, col) + rowMarkerWidth;
|
|
148
|
+
drawHeaderCell(ctx, x, 0, column.width, headerHeight, column.title, mergedTheme, isColSelected(col));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Frozen column separator shadow
|
|
152
|
+
const frozenBoundaryX = getColumnX(columns, fixedColumns) + rowMarkerWidth;
|
|
153
|
+
const grad = ctx.createLinearGradient(frozenBoundaryX, 0, frozenBoundaryX + 6, 0);
|
|
154
|
+
grad.addColorStop(0, 'rgba(0,0,0,0.12)');
|
|
155
|
+
grad.addColorStop(1, 'rgba(0,0,0,0)');
|
|
156
|
+
ctx.fillStyle = grad;
|
|
157
|
+
ctx.fillRect(frozenBoundaryX, 0, 6, containerHeight);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function renderCells(ctx: CanvasRenderingContext2D, range: VisibleRange) {
|
|
161
|
+
const search = searchValue?.toLowerCase() ?? '';
|
|
162
|
+
for (let row = range.firstRow; row <= range.lastRow; row++) {
|
|
163
|
+
for (let col = Math.max(range.firstCol, fixedColumns); col <= range.lastCol; col++) {
|
|
164
|
+
const column = columns[col];
|
|
165
|
+
if (!column) continue;
|
|
166
|
+
const x = getColumnX(columns, col) - scrollX + rowMarkerWidth;
|
|
167
|
+
const y = row * rowHeight - scrollY + headerHeight;
|
|
168
|
+
const item: Item = [col, row];
|
|
169
|
+
const cell = getCellContent(item);
|
|
170
|
+
const selected = isInSelection(item, currentSelection);
|
|
171
|
+
const isSearchMatch = search.length > 0 && cell.displayData.toLowerCase().includes(search);
|
|
172
|
+
drawCell(ctx, x, y, column.width, rowHeight, cell, mergedTheme, selected, false, isSearchMatch);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function renderFixedColumns(ctx: CanvasRenderingContext2D, range: VisibleRange) {
|
|
178
|
+
const search = searchValue?.toLowerCase() ?? '';
|
|
179
|
+
for (let row = range.firstRow; row <= range.lastRow; row++) {
|
|
180
|
+
for (let col = 0; col < fixedColumns && col < columns.length; col++) {
|
|
181
|
+
const column = columns[col];
|
|
182
|
+
const x = getColumnX(columns, col) + rowMarkerWidth;
|
|
183
|
+
const y = row * rowHeight - scrollY + headerHeight;
|
|
184
|
+
const item: Item = [col, row];
|
|
185
|
+
const cell = getCellContent(item);
|
|
186
|
+
const selected = isInSelection(item, currentSelection);
|
|
187
|
+
const isSearchMatch = search.length > 0 && cell.displayData.toLowerCase().includes(search);
|
|
188
|
+
drawCell(ctx, x, y, column.width, rowHeight, cell, mergedTheme, selected, false, isSearchMatch);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function renderRowMarkers(ctx: CanvasRenderingContext2D, range: VisibleRange) {
|
|
194
|
+
if (rowMarkers === 'none') return;
|
|
195
|
+
|
|
196
|
+
ctx.fillStyle = mergedTheme.bgHeader;
|
|
197
|
+
ctx.fillRect(0, headerHeight, rowMarkerWidth, containerHeight - headerHeight);
|
|
198
|
+
|
|
199
|
+
ctx.strokeStyle = mergedTheme.borderColor;
|
|
200
|
+
ctx.lineWidth = 1;
|
|
201
|
+
ctx.beginPath();
|
|
202
|
+
ctx.moveTo(rowMarkerWidth, headerHeight);
|
|
203
|
+
ctx.lineTo(rowMarkerWidth, containerHeight);
|
|
204
|
+
ctx.stroke();
|
|
205
|
+
|
|
206
|
+
// Corner cell
|
|
207
|
+
ctx.fillStyle = mergedTheme.bgHeader;
|
|
208
|
+
ctx.fillRect(0, 0, rowMarkerWidth, headerHeight);
|
|
209
|
+
ctx.strokeStyle = mergedTheme.borderColor;
|
|
210
|
+
ctx.strokeRect(0, 0, rowMarkerWidth, headerHeight);
|
|
211
|
+
|
|
212
|
+
for (let row = range.firstRow; row <= range.lastRow; row++) {
|
|
213
|
+
const y = row * rowHeight - scrollY + headerHeight;
|
|
214
|
+
|
|
215
|
+
if (rowMarkers === 'number') {
|
|
216
|
+
const isRowSelected = currentSelection.type === 'row' && currentSelection.rows.includes(row);
|
|
217
|
+
if (isRowSelected) {
|
|
218
|
+
ctx.fillStyle = mergedTheme.bgHeaderHasFocus;
|
|
219
|
+
ctx.fillRect(0, y, rowMarkerWidth, rowHeight);
|
|
220
|
+
}
|
|
221
|
+
ctx.font = `${mergedTheme.fontSize}px ${mergedTheme.fontFamily}`;
|
|
222
|
+
ctx.fillStyle = mergedTheme.foreground;
|
|
223
|
+
ctx.textAlign = 'right';
|
|
224
|
+
ctx.textBaseline = 'middle';
|
|
225
|
+
ctx.fillText(String(row + 1), rowMarkerWidth - 8, y + rowHeight / 2);
|
|
226
|
+
ctx.textAlign = 'left';
|
|
227
|
+
} else if (rowMarkers === 'checkbox') {
|
|
228
|
+
const isSelected = currentSelection.type === 'row' && currentSelection.rows.includes(row);
|
|
229
|
+
const checkboxX = rowMarkerWidth / 2 - 6;
|
|
230
|
+
const checkboxY = y + rowHeight / 2 - 6;
|
|
231
|
+
|
|
232
|
+
ctx.strokeStyle = mergedTheme.borderColor;
|
|
233
|
+
ctx.lineWidth = 1;
|
|
234
|
+
ctx.strokeRect(checkboxX, checkboxY, 12, 12);
|
|
235
|
+
|
|
236
|
+
if (isSelected) {
|
|
237
|
+
ctx.fillStyle = mergedTheme.accentColor;
|
|
238
|
+
ctx.fillRect(checkboxX + 2, checkboxY + 2, 8, 8);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function renderDragIndicator(ctx: CanvasRenderingContext2D) {
|
|
245
|
+
if (draggingHeaderCol === null) return;
|
|
246
|
+
const col = columns[draggingHeaderCol];
|
|
247
|
+
if (!col) return;
|
|
248
|
+
|
|
249
|
+
const dropCol = getColumnFromX(dragHeaderCurrentX + scrollX - rowMarkerWidth, columns);
|
|
250
|
+
const dropX = getColumnX(columns, dropCol) - scrollX + rowMarkerWidth;
|
|
251
|
+
|
|
252
|
+
ctx.fillStyle = 'rgba(79,70,229,0.15)';
|
|
253
|
+
const colX = getColumnX(columns, draggingHeaderCol) - scrollX + rowMarkerWidth;
|
|
254
|
+
ctx.fillRect(colX, 0, col.width, containerHeight);
|
|
255
|
+
|
|
256
|
+
ctx.fillStyle = mergedTheme.accentColor;
|
|
257
|
+
ctx.fillRect(dropX - 2, 0, 3, containerHeight);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleScroll(e: Event) {
|
|
261
|
+
const target = e.target as HTMLElement;
|
|
262
|
+
scrollX = target.scrollLeft;
|
|
263
|
+
scrollY = target.scrollTop;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function handleMouseDown(e: MouseEvent) {
|
|
267
|
+
containerRef?.focus();
|
|
268
|
+
if (readonly) return;
|
|
269
|
+
|
|
270
|
+
// Header interactions
|
|
271
|
+
if (e.offsetY < headerHeight) {
|
|
272
|
+
const adjustedX = e.offsetX - rowMarkerWidth;
|
|
273
|
+
|
|
274
|
+
const resizeCol = getResizeHandle(adjustedX + scrollX, columns, 0);
|
|
275
|
+
if (resizeCol !== null) {
|
|
276
|
+
resizingColumn = resizeCol;
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Column drag reorder (only if onColumnMoved provided)
|
|
281
|
+
if (onColumnMoved) {
|
|
282
|
+
const col = getColumnFromX(adjustedX + scrollX, columns);
|
|
283
|
+
draggingHeaderCol = col;
|
|
284
|
+
dragHeaderCurrentX = e.offsetX;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Column header click → column selection
|
|
289
|
+
const col = getColumnFromX(adjustedX + scrollX, columns);
|
|
290
|
+
if (col >= 0 && col < columns.length) {
|
|
291
|
+
if (e.shiftKey && currentSelection.type === 'column') {
|
|
292
|
+
const cols = [...currentSelection.columns];
|
|
293
|
+
if (!cols.includes(col)) cols.push(col);
|
|
294
|
+
currentSelection = { type: 'column', columns: cols };
|
|
295
|
+
} else {
|
|
296
|
+
currentSelection = { type: 'column', columns: [col] };
|
|
297
|
+
}
|
|
298
|
+
onSelectionChange?.(currentSelection);
|
|
299
|
+
announcement = `Column ${columns[col].title} selected`;
|
|
300
|
+
}
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const cell = getCellFromPoint(
|
|
305
|
+
e.offsetX - rowMarkerWidth,
|
|
306
|
+
e.offsetY,
|
|
307
|
+
scrollX,
|
|
308
|
+
scrollY,
|
|
309
|
+
columns,
|
|
310
|
+
rowHeight,
|
|
311
|
+
headerHeight
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
if (rowMarkers !== 'none' && e.offsetX < rowMarkerWidth) {
|
|
315
|
+
if (e.offsetY >= headerHeight) {
|
|
316
|
+
const row = Math.floor((e.offsetY - headerHeight + scrollY) / rowHeight);
|
|
317
|
+
if (row >= 0 && row < rows) toggleRowSelection(row);
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (cell) {
|
|
323
|
+
if (e.shiftKey && focusedCell) {
|
|
324
|
+
const newSelection: Selection = { type: 'range', start: focusedCell, end: cell };
|
|
325
|
+
currentSelection = newSelection;
|
|
326
|
+
onSelectionChange?.(newSelection);
|
|
327
|
+
} else {
|
|
328
|
+
focusedCell = cell;
|
|
329
|
+
dragStart = cell;
|
|
330
|
+
isDragging = true;
|
|
331
|
+
currentSelection = { type: 'cell', item: cell };
|
|
332
|
+
onSelectionChange?.(currentSelection);
|
|
333
|
+
announcement = `Row ${cell[1] + 1}, column ${columns[cell[0]]?.title ?? cell[0] + 1}`;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function handleMouseMove(e: MouseEvent) {
|
|
339
|
+
if (resizingColumn !== null) {
|
|
340
|
+
const baseX = getColumnX(columns, resizingColumn) + rowMarkerWidth;
|
|
341
|
+
const newWidth = Math.max(50, e.offsetX - baseX + scrollX);
|
|
342
|
+
columns[resizingColumn].width = newWidth;
|
|
343
|
+
scheduleDraw();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (draggingHeaderCol !== null) {
|
|
348
|
+
dragHeaderCurrentX = e.offsetX;
|
|
349
|
+
scheduleDraw();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (!isDragging || !dragStart) return;
|
|
354
|
+
|
|
355
|
+
const cell = getCellFromPoint(
|
|
356
|
+
e.offsetX - rowMarkerWidth,
|
|
357
|
+
e.offsetY,
|
|
358
|
+
scrollX,
|
|
359
|
+
scrollY,
|
|
360
|
+
columns,
|
|
361
|
+
rowHeight,
|
|
362
|
+
headerHeight
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
if (cell && (cell[0] !== dragStart[0] || cell[1] !== dragStart[1])) {
|
|
366
|
+
currentSelection = { type: 'range', start: dragStart, end: cell };
|
|
367
|
+
onSelectionChange?.(currentSelection);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function handleMouseUp(e: MouseEvent) {
|
|
372
|
+
if (draggingHeaderCol !== null && onColumnMoved) {
|
|
373
|
+
const adjustedX = e.offsetX - rowMarkerWidth;
|
|
374
|
+
const targetCol = getColumnFromX(adjustedX + scrollX, columns);
|
|
375
|
+
if (targetCol !== draggingHeaderCol) {
|
|
376
|
+
onColumnMoved(draggingHeaderCol, targetCol);
|
|
377
|
+
}
|
|
378
|
+
draggingHeaderCol = null;
|
|
379
|
+
scheduleDraw();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
isDragging = false;
|
|
383
|
+
dragStart = null;
|
|
384
|
+
resizingColumn = null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function handleWheel(e: WheelEvent) {
|
|
388
|
+
if (scrollRef) {
|
|
389
|
+
scrollRef.scrollLeft += e.deltaX;
|
|
390
|
+
scrollRef.scrollTop += e.deltaY;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async function copySelection(): Promise<void> {
|
|
395
|
+
const lines: string[] = [];
|
|
396
|
+
|
|
397
|
+
if (currentSelection.type === 'cell') {
|
|
398
|
+
lines.push(getCellContent(currentSelection.item).displayData);
|
|
399
|
+
} else if (currentSelection.type === 'range') {
|
|
400
|
+
const [startCol, startRow] = currentSelection.start;
|
|
401
|
+
const [endCol, endRow] = currentSelection.end;
|
|
402
|
+
const minCol = Math.min(startCol, endCol);
|
|
403
|
+
const maxCol = Math.max(startCol, endCol);
|
|
404
|
+
const minRow = Math.min(startRow, endRow);
|
|
405
|
+
const maxRow = Math.max(startRow, endRow);
|
|
406
|
+
for (let row = minRow; row <= maxRow; row++) {
|
|
407
|
+
const rowData: string[] = [];
|
|
408
|
+
for (let col = minCol; col <= maxCol; col++) {
|
|
409
|
+
rowData.push(getCellContent([col, row]).displayData);
|
|
410
|
+
}
|
|
411
|
+
lines.push(rowData.join('\t'));
|
|
412
|
+
}
|
|
413
|
+
} else if (currentSelection.type === 'row') {
|
|
414
|
+
for (const row of currentSelection.rows) {
|
|
415
|
+
const rowData = columns.map((_, col) => getCellContent([col, row]).displayData);
|
|
416
|
+
lines.push(rowData.join('\t'));
|
|
417
|
+
}
|
|
418
|
+
} else if (currentSelection.type === 'column') {
|
|
419
|
+
for (let row = 0; row < rows; row++) {
|
|
420
|
+
const rowData = currentSelection.columns.map((col) => getCellContent([col, row]).displayData);
|
|
421
|
+
lines.push(rowData.join('\t'));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (lines.length > 0) {
|
|
426
|
+
await navigator.clipboard.writeText(lines.join('\n'));
|
|
427
|
+
announcement = `Copied ${lines.length} row${lines.length > 1 ? 's' : ''} to clipboard`;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async function pasteFromClipboard(): Promise<void> {
|
|
432
|
+
if (readonly || !focusedCell) return;
|
|
433
|
+
const text = await navigator.clipboard.readText();
|
|
434
|
+
const pastedRows = text.split('\n').map((line) => line.split('\t'));
|
|
435
|
+
const [startCol, startRow] = focusedCell;
|
|
436
|
+
|
|
437
|
+
for (let r = 0; r < pastedRows.length; r++) {
|
|
438
|
+
for (let c = 0; c < pastedRows[r].length; c++) {
|
|
439
|
+
const col = startCol + c;
|
|
440
|
+
const row = startRow + r;
|
|
441
|
+
if (col >= columns.length || row >= rows) continue;
|
|
442
|
+
const item: Item = [col, row];
|
|
443
|
+
const cell = getCellContent(item);
|
|
444
|
+
if (!cell.readonly && cell.allowEditing !== false) {
|
|
445
|
+
const newCell: GridlerCell = { ...cell, displayData: pastedRows[r][c], data: pastedRows[r][c] };
|
|
446
|
+
onCellEdited?.(item, newCell);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
announcement = `Pasted ${pastedRows.length} row${pastedRows.length > 1 ? 's' : ''}`;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
454
|
+
// Copy/paste shortcuts
|
|
455
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
|
|
456
|
+
copySelection();
|
|
457
|
+
e.preventDefault();
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'v') {
|
|
461
|
+
pasteFromClipboard();
|
|
462
|
+
e.preventDefault();
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
|
|
466
|
+
if (rows > 0 && columns.length > 0) {
|
|
467
|
+
currentSelection = { type: 'range', start: [0, 0], end: [columns.length - 1, rows - 1] };
|
|
468
|
+
onSelectionChange?.(currentSelection);
|
|
469
|
+
announcement = 'All cells selected';
|
|
470
|
+
}
|
|
471
|
+
e.preventDefault();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (!focusedCell) return;
|
|
476
|
+
|
|
477
|
+
const [col, row] = focusedCell;
|
|
478
|
+
let newCol = col;
|
|
479
|
+
let newRow = row;
|
|
480
|
+
|
|
481
|
+
switch (e.key) {
|
|
482
|
+
case 'ArrowUp':
|
|
483
|
+
newRow = Math.max(0, row - 1);
|
|
484
|
+
e.preventDefault();
|
|
485
|
+
break;
|
|
486
|
+
case 'ArrowDown':
|
|
487
|
+
newRow = Math.min(rows - 1, row + 1);
|
|
488
|
+
e.preventDefault();
|
|
489
|
+
break;
|
|
490
|
+
case 'ArrowLeft':
|
|
491
|
+
newCol = Math.max(0, col - 1);
|
|
492
|
+
e.preventDefault();
|
|
493
|
+
break;
|
|
494
|
+
case 'ArrowRight':
|
|
495
|
+
newCol = Math.min(columns.length - 1, col + 1);
|
|
496
|
+
e.preventDefault();
|
|
497
|
+
break;
|
|
498
|
+
case 'Enter':
|
|
499
|
+
if (!readonly) {
|
|
500
|
+
beginEdit(focusedCell);
|
|
501
|
+
}
|
|
502
|
+
e.preventDefault();
|
|
503
|
+
return;
|
|
504
|
+
case 'Escape':
|
|
505
|
+
cancelEdit();
|
|
506
|
+
if (currentSelection.type !== 'none') {
|
|
507
|
+
onSelectionCleared?.();
|
|
508
|
+
}
|
|
509
|
+
return;
|
|
510
|
+
case 'Tab':
|
|
511
|
+
if (e.shiftKey) {
|
|
512
|
+
newCol = col - 1;
|
|
513
|
+
if (newCol < 0) {
|
|
514
|
+
newCol = columns.length - 1;
|
|
515
|
+
newRow = Math.max(0, row - 1);
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
newCol = col + 1;
|
|
519
|
+
if (newCol >= columns.length) {
|
|
520
|
+
newCol = 0;
|
|
521
|
+
newRow = Math.min(rows - 1, row + 1);
|
|
522
|
+
onRowAppended?.();
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
e.preventDefault();
|
|
526
|
+
break;
|
|
527
|
+
case 'Delete':
|
|
528
|
+
case 'Backspace':
|
|
529
|
+
if (!readonly && currentSelection.type !== 'none') {
|
|
530
|
+
onDelete?.(currentSelection);
|
|
531
|
+
}
|
|
532
|
+
return;
|
|
533
|
+
default:
|
|
534
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !readonly) {
|
|
535
|
+
beginEdit(focusedCell);
|
|
536
|
+
}
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (newCol !== col || newRow !== row) {
|
|
541
|
+
focusedCell = [newCol, newRow];
|
|
542
|
+
currentSelection = { type: 'cell', item: focusedCell };
|
|
543
|
+
onSelectionChange?.(currentSelection);
|
|
544
|
+
announcement = `Row ${newRow + 1}, column ${columns[newCol]?.title ?? newCol + 1}`;
|
|
545
|
+
|
|
546
|
+
if (scrollRef) {
|
|
547
|
+
const scrollTarget = scrollToCell(
|
|
548
|
+
focusedCell,
|
|
549
|
+
columns,
|
|
550
|
+
rowHeight,
|
|
551
|
+
headerHeight,
|
|
552
|
+
containerWidth,
|
|
553
|
+
containerHeight
|
|
554
|
+
);
|
|
555
|
+
if (scrollTarget) {
|
|
556
|
+
scrollRef.scrollLeft = scrollTarget.scrollX;
|
|
557
|
+
scrollRef.scrollTop = scrollTarget.scrollY;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function beginEdit(cell: Item) {
|
|
564
|
+
const cellContent = getCellContent(cell);
|
|
565
|
+
if (cellContent.readonly) return;
|
|
566
|
+
editingCell = cell;
|
|
567
|
+
isEditing = true;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function cancelEdit() {
|
|
571
|
+
isEditing = false;
|
|
572
|
+
editingCell = null;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function handleEditComplete(value: string) {
|
|
576
|
+
if (editingCell) {
|
|
577
|
+
const cell = getCellContent(editingCell);
|
|
578
|
+
const newCell: GridlerCell = { ...cell, displayData: value, data: value };
|
|
579
|
+
onCellEdited?.(editingCell, newCell);
|
|
580
|
+
}
|
|
581
|
+
cancelEdit();
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function toggleRowSelection(row: number) {
|
|
585
|
+
if (currentSelection.type === 'row' && currentSelection.rows.includes(row)) {
|
|
586
|
+
const newRows = currentSelection.rows.filter(r => r !== row);
|
|
587
|
+
currentSelection = newRows.length > 0 ? { type: 'row', rows: newRows } : { type: 'none' };
|
|
588
|
+
} else if (currentSelection.type === 'row') {
|
|
589
|
+
currentSelection = { type: 'row', rows: [...currentSelection.rows, row] };
|
|
590
|
+
} else {
|
|
591
|
+
currentSelection = { type: 'row', rows: [row] };
|
|
592
|
+
}
|
|
593
|
+
onSelectionChange?.(currentSelection);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
$effect(() => {
|
|
597
|
+
if (!containerRef) return;
|
|
598
|
+
|
|
599
|
+
const observer = new ResizeObserver((entries) => {
|
|
600
|
+
const entry = entries[0];
|
|
601
|
+
if (entry) {
|
|
602
|
+
containerWidth = entry.contentRect.width;
|
|
603
|
+
containerHeight = entry.contentRect.height;
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
observer.observe(containerRef);
|
|
608
|
+
return () => observer.disconnect();
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
const containerWidthStyle = $derived(typeof width === 'number' ? `${width}px` : width);
|
|
612
|
+
const containerHeightStyle = $derived(typeof height === 'number' ? `${height}px` : height);
|
|
613
|
+
</script>
|
|
614
|
+
|
|
615
|
+
<div
|
|
616
|
+
bind:this={containerRef}
|
|
617
|
+
class="gridler"
|
|
618
|
+
role="grid"
|
|
619
|
+
tabindex="0"
|
|
620
|
+
aria-rowcount={rows}
|
|
621
|
+
aria-colcount={columns.length}
|
|
622
|
+
aria-label="Data grid"
|
|
623
|
+
style:width={containerWidthStyle}
|
|
624
|
+
style:height={containerHeightStyle}
|
|
625
|
+
onkeydown={handleKeyDown}
|
|
626
|
+
>
|
|
627
|
+
<canvas
|
|
628
|
+
bind:this={canvasRef}
|
|
629
|
+
class="gridler-canvas"
|
|
630
|
+
aria-hidden="true"
|
|
631
|
+
onmousedown={handleMouseDown}
|
|
632
|
+
onmousemove={handleMouseMove}
|
|
633
|
+
onmouseup={handleMouseUp}
|
|
634
|
+
onmouseleave={handleMouseUp}
|
|
635
|
+
onwheel={handleWheel}
|
|
636
|
+
></canvas>
|
|
637
|
+
|
|
638
|
+
<div
|
|
639
|
+
bind:this={scrollRef}
|
|
640
|
+
class="gridler-scroll"
|
|
641
|
+
role="presentation"
|
|
642
|
+
onscroll={handleScroll}
|
|
643
|
+
>
|
|
644
|
+
<div
|
|
645
|
+
class="gridler-content"
|
|
646
|
+
style:width={`${totalWidth}px`}
|
|
647
|
+
style:height={`${totalHeight}px`}
|
|
648
|
+
></div>
|
|
649
|
+
</div>
|
|
650
|
+
|
|
651
|
+
{#if isEditing && editingCell}
|
|
652
|
+
<div
|
|
653
|
+
class="gridler-editor"
|
|
654
|
+
role="gridcell"
|
|
655
|
+
style:left={`${getColumnX(columns, editingCell[0]) - scrollX + rowMarkerWidth}px`}
|
|
656
|
+
style:top={`${editingCell[1] * rowHeight - scrollY + headerHeight}px`}
|
|
657
|
+
style:width={`${columns[editingCell[0]].width}px`}
|
|
658
|
+
style:height={`${rowHeight}px`}
|
|
659
|
+
>
|
|
660
|
+
<input
|
|
661
|
+
type="text"
|
|
662
|
+
value={getCellContent(editingCell).displayData}
|
|
663
|
+
onkeydown={(e) => {
|
|
664
|
+
if (e.key === 'Enter') {
|
|
665
|
+
handleEditComplete(e.currentTarget.value);
|
|
666
|
+
} else if (e.key === 'Escape') {
|
|
667
|
+
cancelEdit();
|
|
668
|
+
}
|
|
669
|
+
}}
|
|
670
|
+
onblur={(e) => handleEditComplete(e.currentTarget.value)}
|
|
671
|
+
/>
|
|
672
|
+
</div>
|
|
673
|
+
{/if}
|
|
674
|
+
|
|
675
|
+
{#if showSearch}
|
|
676
|
+
<div class="gridler-search" role="search">
|
|
677
|
+
<input
|
|
678
|
+
type="search"
|
|
679
|
+
placeholder="Search…"
|
|
680
|
+
value={searchValue}
|
|
681
|
+
aria-label="Search grid"
|
|
682
|
+
class="gridler-search-input"
|
|
683
|
+
/>
|
|
684
|
+
</div>
|
|
685
|
+
{/if}
|
|
686
|
+
|
|
687
|
+
<div role="status" aria-live="polite" class="sr-only">
|
|
688
|
+
{announcement}
|
|
689
|
+
</div>
|
|
690
|
+
|
|
691
|
+
{#if children}
|
|
692
|
+
{@render children()}
|
|
693
|
+
{/if}
|
|
694
|
+
</div>
|
|
695
|
+
|
|
696
|
+
<style>
|
|
697
|
+
.gridler {
|
|
698
|
+
position: relative;
|
|
699
|
+
display: flex;
|
|
700
|
+
flex-direction: column;
|
|
701
|
+
overflow: hidden;
|
|
702
|
+
border: 1px solid var(--gridler-border, #e2e8f0);
|
|
703
|
+
border-radius: 4px;
|
|
704
|
+
background: var(--gridler-bg, #ffffff);
|
|
705
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
.gridler-scroll {
|
|
709
|
+
flex: 1;
|
|
710
|
+
overflow: auto;
|
|
711
|
+
position: relative;
|
|
712
|
+
z-index: 1;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
.gridler-content {
|
|
716
|
+
position: relative;
|
|
717
|
+
pointer-events: none;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
.gridler-canvas {
|
|
721
|
+
position: absolute;
|
|
722
|
+
top: 0;
|
|
723
|
+
left: 0;
|
|
724
|
+
z-index: 2;
|
|
725
|
+
cursor: default;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
.gridler-editor {
|
|
729
|
+
position: absolute;
|
|
730
|
+
z-index: 10;
|
|
731
|
+
pointer-events: auto;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
.gridler-editor input {
|
|
735
|
+
width: 100%;
|
|
736
|
+
height: 100%;
|
|
737
|
+
padding: 4px 8px;
|
|
738
|
+
border: 2px solid var(--gridler-accent, #4f46e5);
|
|
739
|
+
border-radius: 2px;
|
|
740
|
+
font-size: 13px;
|
|
741
|
+
font-family: inherit;
|
|
742
|
+
outline: none;
|
|
743
|
+
box-sizing: border-box;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
.gridler-search {
|
|
747
|
+
position: absolute;
|
|
748
|
+
top: 8px;
|
|
749
|
+
right: 8px;
|
|
750
|
+
z-index: 20;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
.gridler-search-input {
|
|
754
|
+
padding: 4px 8px;
|
|
755
|
+
border: 1px solid var(--gridler-border, #e2e8f0);
|
|
756
|
+
border-radius: 4px;
|
|
757
|
+
font-size: 12px;
|
|
758
|
+
outline: none;
|
|
759
|
+
background: white;
|
|
760
|
+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
.gridler-search-input:focus {
|
|
764
|
+
border-color: var(--gridler-accent, #4f46e5);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
.sr-only {
|
|
768
|
+
position: absolute;
|
|
769
|
+
width: 1px;
|
|
770
|
+
height: 1px;
|
|
771
|
+
padding: 0;
|
|
772
|
+
margin: -1px;
|
|
773
|
+
overflow: hidden;
|
|
774
|
+
clip: rect(0, 0, 0, 0);
|
|
775
|
+
white-space: nowrap;
|
|
776
|
+
border: 0;
|
|
777
|
+
}
|
|
778
|
+
</style>
|