@ishibashi0112/spreadsheet-grid-solid 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/API_REFERENCE.md +2864 -0
  2. package/README.md +41 -17
  3. package/dist/ColumnFilterPopover-CzSRfcDF.js +1426 -0
  4. package/dist/columnVirtualizer-Bv79_vW1.js +186 -0
  5. package/dist/createSpreadsheetGrid.d.ts +14 -0
  6. package/dist/devWarnings.d.ts +3 -0
  7. package/dist/editors/CellEditorLayer.d.ts +2 -0
  8. package/dist/editors/DateCellEditor.d.ts +1 -0
  9. package/dist/editors/NumberCellEditor.d.ts +1 -0
  10. package/dist/editors/SelectCellEditor.d.ts +3 -1
  11. package/dist/editors/TextCellEditor.d.ts +1 -0
  12. package/dist/features/contextMenu.d.ts +0 -14
  13. package/dist/features/types.d.ts +1 -1
  14. package/dist/index.js +2656 -2670
  15. package/dist/primitives/externalStore.d.ts +1 -0
  16. package/dist/primitives/userCallback.d.ts +10 -0
  17. package/dist/source/chunks/{ColumnFilterPopover-BMKPRELT.jsx → ColumnFilterPopover-2DW5SZT3.jsx} +29 -10
  18. package/dist/source/chunks/chunk-FTQFOPXC.jsx +293 -0
  19. package/dist/source/chunks/{toolPanelViews-W6KROURU.jsx → toolPanelViews-HIQGRX3N.jsx} +4 -2
  20. package/dist/source/index.jsx +745 -775
  21. package/dist/style.css +1 -1
  22. package/dist/style.layer.css +1 -1
  23. package/dist/{toolPanelViews-BE4gv_L0.js → toolPanelViews-BISN9iaG.js} +120 -119
  24. package/dist/view/DetailToggleButton.d.ts +1 -0
  25. package/dist/view/GridBodyLayer.d.ts +1 -1
  26. package/package.json +8 -5
  27. package/skills/spreadsheet-grid-solid/SKILL.md +106 -0
  28. package/dist/ColumnFilterPopover-BmxumbB7.js +0 -1418
  29. package/dist/columnVirtualizer-CGHyzbwH.js +0 -95
  30. package/dist/source/chunks/chunk-5KX4SR2S.jsx +0 -143
@@ -1,5 +1,6 @@
1
1
  export type ExternalStoreLike<V> = {
2
2
  subscribe: (listener: () => void) => () => void;
3
3
  getSnapshot: () => V;
4
+ getServerSnapshot?: () => V;
4
5
  };
5
6
  export declare function createExternalStoreSignal<V>(store: ExternalStoreLike<V>, name?: string): () => V;
@@ -0,0 +1,10 @@
1
+ export declare function runGridUpdate<R>(fn: () => R): R;
2
+ export declare function runHandleCall<R>(fn: () => R): R;
3
+ export declare function isIsolatingFlush(): boolean;
4
+ export declare function deferControllerUpdate(replay: () => void): void;
5
+ export declare function callInOwnFrame<A extends unknown[], R>(fn: (...args: A) => R, ...args: A): R;
6
+ export type UserCallbacks = {
7
+ wrap: <A extends unknown[], R>(fn: ((...args: A) => R) | undefined) => ((...args: A) => R | undefined) | undefined;
8
+ call: <A extends unknown[], R>(fn: (...args: A) => R, ...args: A) => R | undefined;
9
+ };
10
+ export declare function createUserCallbacks(): UserCallbacks;
@@ -1,6 +1,8 @@
1
1
  import {
2
- createColumnVirtualizer
3
- } from "./chunk-5KX4SR2S.jsx";
2
+ connectController,
3
+ createColumnVirtualizer,
4
+ createExternalStoreSignal
5
+ } from "./chunk-FTQFOPXC.jsx";
4
6
  import {
5
7
  controlledToggle,
6
8
  createIndeterminate,
@@ -27,6 +29,7 @@ import {
27
29
  } from "solid-js";
28
30
  import { Portal } from "@solidjs/web";
29
31
  import { isEscapePreventedInside } from "@ishibashi0112/spreadsheet-grid-core/internal/controllers/escapeClaimController";
32
+ import { keepFocusAfterPress } from "@ishibashi0112/spreadsheet-grid-core/internal/controllers/popoverSupport";
30
33
  import { resolveFocusWrapTarget } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/focusCycle";
31
34
  import {
32
35
  filterSetOptionsBySearch,
@@ -55,8 +58,10 @@ import {
55
58
  buildParsedDateFilterFromDraft,
56
59
  dateFilterOperandCount,
57
60
  filterOptionsByDateCondition,
58
- normalizeFilterDateInputValue
61
+ normalizeFilterDateInputValue,
62
+ resolveComboReferenceDate
59
63
  } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/dateFilterCondition";
64
+ import { createDateRolloverStore } from "@ishibashi0112/spreadsheet-grid-core/internal/controllers/dateRolloverStore";
60
65
  import {
61
66
  normalizeDateFilterPresets
62
67
  } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/dateFilterPresets";
@@ -68,6 +73,7 @@ import { DEFAULT_FILTER_LOCALE_TEXT } from "@ishibashi0112/spreadsheet-grid-core
68
73
  // src/view/FilterDateField.tsx
69
74
  import { For, Show, createEffect, createMemo, createSignal, onCleanup, untrack } from "solid-js";
70
75
  import { toDateKey } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/filtering";
76
+ import { parseFilterDateText } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/editorValues";
71
77
  import {
72
78
  buildCalendarDayCells,
73
79
  buildYearGrid,
@@ -76,6 +82,7 @@ import {
76
82
  } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/datePickerCalendar";
77
83
  import { isImeComposingKeyEvent } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/domGuards";
78
84
  import { formatLocaleText } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/localeText";
85
+ import { getEventTarget } from "@ishibashi0112/spreadsheet-grid-core/internal/utils/shadowDom";
79
86
  function FilterDateField(props) {
80
87
  const texts = usePopupLocaleText();
81
88
  const [editingText, setEditingText] = createSignal(null);
@@ -108,7 +115,7 @@ function FilterDateField(props) {
108
115
  setIsInvalid(false);
109
116
  return;
110
117
  }
111
- const key = toDateKey(raw);
118
+ const key = parseFilterDateText(raw);
112
119
  if (key === null) {
113
120
  setIsInvalid(true);
114
121
  return;
@@ -139,7 +146,7 @@ function FilterDateField(props) {
139
146
  return void 0;
140
147
  }
141
148
  const handleDocumentPointerDown = (event) => {
142
- const target = event.target;
149
+ const target = getEventTarget(event, rootElement ?? null);
143
150
  if (target && rootElement?.contains(target)) {
144
151
  return;
145
152
  }
@@ -407,13 +414,13 @@ var pressHandlers = (action) => ({
407
414
  onPointerDown: (event) => {
408
415
  event.preventDefault();
409
416
  event.stopPropagation();
410
- action();
417
+ action(event.currentTarget);
411
418
  },
412
419
  onKeyDown: (event) => {
413
420
  stopButtonKeyPropagation(event);
414
421
  if (event.key === "Enter" || event.key === " ") {
415
422
  event.preventDefault();
416
- action();
423
+ action(event.currentTarget);
417
424
  }
418
425
  }
419
426
  });
@@ -777,7 +784,10 @@ function DateConditionEditor(props) {
777
784
  <For2 each={props.presets} keyed={(option) => option.id}>
778
785
  {(option) => <button
779
786
  type="button"
780
- {...pressHandlers(() => togglePreset(option().id))}
787
+ {...pressHandlers((element) => {
788
+ togglePreset(option().id);
789
+ keepFocusAfterPress(element);
790
+ })}
781
791
  class={["ssg-filter-preset-chip", { "ssg-filter-preset-chip--active": props.draft.preset === option().id }]}
782
792
  >
783
793
  {option().label}
@@ -1151,7 +1161,16 @@ function ColumnFilterPopover(props) {
1151
1161
  const portal = useGridPortal();
1152
1162
  const container = portal.container();
1153
1163
  const comboSearchInputRef = { current: null };
1154
- const comboNow = /* @__PURE__ */ new Date();
1164
+ const comboOpenedAt = /* @__PURE__ */ new Date();
1165
+ const comboDateRollover = createDateRolloverStore();
1166
+ connectController(
1167
+ comboDateRollover,
1168
+ () => ({ active: props.filterType === "dateSet" && (props.dateConditionDraft?.preset ?? null) !== null }),
1169
+ "render",
1170
+ "filterDateRollover"
1171
+ );
1172
+ const comboDateKey = createExternalStoreSignal(comboDateRollover, "filterDateRolloverStore");
1173
+ const comboNow = () => resolveComboReferenceDate(comboOpenedAt, comboDateKey());
1155
1174
  const [panel, setPanel] = createSignal2();
1156
1175
  let panelNode;
1157
1176
  onCleanup2(() => {
@@ -1189,7 +1208,7 @@ function ColumnFilterPopover(props) {
1189
1208
  () => numberComboCondition() !== null || textComboCondition() !== null || dateComboCondition() !== null
1190
1209
  );
1191
1210
  const comboOptions = createMemo2(
1192
- () => isNumberSetFilter() ? filterOptionsByNumberCondition(props.selectOptions, numberComboCondition()) : isTextSetFilter() ? filterOptionsByTextCondition(props.selectOptions, textComboCondition()) : isDateSetFilter() ? filterOptionsByDateCondition(props.selectOptions, dateComboCondition(), comboNow, resolvedDatePresets()) : props.selectOptions
1211
+ () => isNumberSetFilter() ? filterOptionsByNumberCondition(props.selectOptions, numberComboCondition()) : isTextSetFilter() ? filterOptionsByTextCondition(props.selectOptions, textComboCondition()) : isDateSetFilter() ? filterOptionsByDateCondition(props.selectOptions, dateComboCondition(), comboNow(), resolvedDatePresets()) : props.selectOptions
1193
1212
  );
1194
1213
  const comboOptionsMeta = createMemo2(() => {
1195
1214
  const phase = optionsPhase();
@@ -0,0 +1,293 @@
1
+ // src/primitives/externalStore.ts
2
+ import { createSignal, isHydrating } from "solid-js";
3
+
4
+ // src/primitives/mountGate.ts
5
+ import { onSettled, untrack } from "solid-js";
6
+ var current = null;
7
+ function createMountGate() {
8
+ return { queue: [], done: false };
9
+ }
10
+ function runInMountGate(gate, fn) {
11
+ const previous = current;
12
+ current = gate;
13
+ try {
14
+ return fn();
15
+ } finally {
16
+ current = previous;
17
+ }
18
+ }
19
+ function flushMountGate(gate) {
20
+ if (gate.done) {
21
+ return;
22
+ }
23
+ gate.done = true;
24
+ const queue = gate.queue;
25
+ gate.queue = [];
26
+ for (const run of queue) {
27
+ run();
28
+ }
29
+ }
30
+ function closeMountGateOnSettled(gate) {
31
+ onSettled(() => {
32
+ gate.done = true;
33
+ gate.queue = [];
34
+ });
35
+ }
36
+ function onGridMounted(fn) {
37
+ const gate = current;
38
+ let ran = false;
39
+ let cleanup;
40
+ const run = () => {
41
+ if (ran) {
42
+ return;
43
+ }
44
+ ran = true;
45
+ cleanup = untrack(fn);
46
+ };
47
+ gate?.queue.push(run);
48
+ onSettled(() => {
49
+ run();
50
+ return () => {
51
+ if (typeof cleanup === "function") {
52
+ cleanup();
53
+ }
54
+ };
55
+ });
56
+ }
57
+
58
+ // src/primitives/externalStore.ts
59
+ function createExternalStoreSignal(store, name) {
60
+ const initial = isHydrating() && store.getServerSnapshot ? store.getServerSnapshot() : store.getSnapshot();
61
+ const [value, setValue] = createSignal(initial, name === void 0 ? void 0 : { name });
62
+ onGridMounted(() => {
63
+ setValue(() => store.getSnapshot());
64
+ return store.subscribe(() => setValue(() => store.getSnapshot()));
65
+ });
66
+ return value;
67
+ }
68
+
69
+ // src/primitives/controller.ts
70
+ import { createEffect, createRenderEffect, createSignal as createSignal2, untrack as untrack2 } from "solid-js";
71
+
72
+ // src/primitives/userCallback.ts
73
+ import { flush, getOwner, isDisposed } from "solid-js";
74
+ var gridUpdateDepth = 0;
75
+ var handleCallDepth = 0;
76
+ var isolatingDepth = 0;
77
+ var pendingReplays = /* @__PURE__ */ new Set();
78
+ function runGridUpdate(fn) {
79
+ gridUpdateDepth++;
80
+ try {
81
+ return fn();
82
+ } finally {
83
+ gridUpdateDepth--;
84
+ }
85
+ }
86
+ function runHandleCall(fn) {
87
+ handleCallDepth++;
88
+ try {
89
+ return fn();
90
+ } finally {
91
+ handleCallDepth--;
92
+ }
93
+ }
94
+ function isIsolatingFlush() {
95
+ return isolatingDepth > 0;
96
+ }
97
+ function deferControllerUpdate(replay) {
98
+ pendingReplays.add(replay);
99
+ }
100
+ var flushQuietly = () => {
101
+ try {
102
+ flush();
103
+ } catch {
104
+ }
105
+ };
106
+ var isolatedFlush = () => {
107
+ isolatingDepth++;
108
+ try {
109
+ flushQuietly();
110
+ } finally {
111
+ isolatingDepth--;
112
+ }
113
+ };
114
+ var releaseReplays = () => {
115
+ if (pendingReplays.size === 0) {
116
+ return;
117
+ }
118
+ const replays = Array.from(pendingReplays);
119
+ pendingReplays.clear();
120
+ for (const replay of replays) {
121
+ replay();
122
+ }
123
+ };
124
+ function callInOwnFrame(fn, ...args) {
125
+ if (handleCallDepth > 0 || gridUpdateDepth > 0 || getOwner() !== null) {
126
+ return fn(...args);
127
+ }
128
+ isolatedFlush();
129
+ try {
130
+ return fn(...args);
131
+ } finally {
132
+ isolatedFlush();
133
+ releaseReplays();
134
+ }
135
+ }
136
+ function createUserCallbacks() {
137
+ const owner = getOwner();
138
+ const call = (fn, ...args) => {
139
+ if (handleCallDepth > 0 || gridUpdateDepth === 0 && getOwner() !== null) {
140
+ return fn(...args);
141
+ }
142
+ if (gridUpdateDepth > 0) {
143
+ queueMicrotask(() => {
144
+ if (owner && isDisposed(owner)) {
145
+ return;
146
+ }
147
+ flushQuietly();
148
+ fn(...args);
149
+ flushQuietly();
150
+ });
151
+ return void 0;
152
+ }
153
+ return callInOwnFrame(fn, ...args);
154
+ };
155
+ return {
156
+ call,
157
+ wrap: (fn) => fn ? (...args) => call(fn, ...args) : void 0
158
+ };
159
+ }
160
+
161
+ // src/primitives/controller.ts
162
+ function connectController(controller, args, timing = "render", name) {
163
+ let mounted = false;
164
+ let latest = null;
165
+ const [replay, setReplay] = createSignal2(0, name === void 0 ? void 0 : { name: `${name}Replay` });
166
+ const requestReplay = () => {
167
+ setReplay((value) => value + 1);
168
+ };
169
+ const run = (value) => {
170
+ runGridUpdate(() => untrack2(() => controller.update(value)));
171
+ };
172
+ const apply = (next) => {
173
+ latest = { value: next };
174
+ if (!mounted) {
175
+ return;
176
+ }
177
+ if (isIsolatingFlush()) {
178
+ deferControllerUpdate(requestReplay);
179
+ return;
180
+ }
181
+ run(next);
182
+ };
183
+ const compute = () => {
184
+ replay();
185
+ return args();
186
+ };
187
+ const options = name === void 0 ? void 0 : { name };
188
+ if (timing === "render") {
189
+ createRenderEffect(compute, apply, options);
190
+ } else {
191
+ createEffect(compute, apply, options);
192
+ }
193
+ onGridMounted(() => {
194
+ mounted = true;
195
+ if (latest) {
196
+ run(latest.value);
197
+ }
198
+ return () => controller.dispose?.();
199
+ });
200
+ }
201
+
202
+ // src/primitives/columnVirtualizer.ts
203
+ import { createMemo, createRenderEffect as createRenderEffect2, createSignal as createSignal3, untrack as untrack3 } from "solid-js";
204
+ import {
205
+ Virtualizer,
206
+ elementScroll,
207
+ observeElementOffset,
208
+ observeElementRect
209
+ } from "@tanstack/virtual-core";
210
+ var observeShownElementRect = (instance, cb) => observeElementRect(instance, (rect) => {
211
+ if (rect.width) {
212
+ cb(rect);
213
+ }
214
+ });
215
+ function createColumnVirtualizer(options) {
216
+ const [version, setVersion] = createSignal3(0);
217
+ let mounted = false;
218
+ let syncing = false;
219
+ const resolve = (next) => {
220
+ const rest = { ...next };
221
+ delete rest.measureKey;
222
+ return {
223
+ observeElementRect: observeShownElementRect,
224
+ observeElementOffset,
225
+ scrollToFn: elementScroll,
226
+ ...rest,
227
+ onChange: (instance2, sync) => {
228
+ if (mounted && !syncing) {
229
+ setVersion((value) => value + 1);
230
+ }
231
+ rest.onChange?.(instance2, sync);
232
+ }
233
+ };
234
+ };
235
+ const instance = new Virtualizer(resolve(untrack3(options)));
236
+ let measuredKey;
237
+ const items = createMemo(() => {
238
+ version();
239
+ const next = options();
240
+ syncing = true;
241
+ try {
242
+ instance.setOptions(resolve(next));
243
+ if (next.measureKey !== measuredKey) {
244
+ measuredKey = next.measureKey;
245
+ instance.measure();
246
+ }
247
+ } finally {
248
+ syncing = false;
249
+ }
250
+ return instance.getVirtualItems();
251
+ });
252
+ createRenderEffect2(options, () => {
253
+ if (!mounted) {
254
+ return;
255
+ }
256
+ syncing = true;
257
+ try {
258
+ instance._willUpdate();
259
+ } finally {
260
+ syncing = false;
261
+ }
262
+ }, { name: "columnVirtualizerElement" });
263
+ onGridMounted(() => {
264
+ mounted = true;
265
+ const cleanup = instance._didMount();
266
+ syncing = true;
267
+ try {
268
+ instance._willUpdate();
269
+ } finally {
270
+ syncing = false;
271
+ }
272
+ setVersion((value) => value + 1);
273
+ return () => {
274
+ mounted = false;
275
+ cleanup();
276
+ };
277
+ });
278
+ return { instance, items };
279
+ }
280
+
281
+ export {
282
+ runHandleCall,
283
+ callInOwnFrame,
284
+ createUserCallbacks,
285
+ createMountGate,
286
+ runInMountGate,
287
+ flushMountGate,
288
+ closeMountGateOnSettled,
289
+ onGridMounted,
290
+ createExternalStoreSignal,
291
+ connectController,
292
+ createColumnVirtualizer
293
+ };
@@ -15,6 +15,7 @@ import { Portal } from "@solidjs/web";
15
15
  import { createPanelHeaderDragController } from "@ishibashi0112/spreadsheet-grid-core/internal/controllers/panelHeaderDragController";
16
16
  import { resolveFocusWrapTarget } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/focusCycle";
17
17
  import { isImeComposingKeyEvent } from "@ishibashi0112/spreadsheet-grid-core/internal/logic/domGuards";
18
+ import { getActiveElement } from "@ishibashi0112/spreadsheet-grid-core/internal/utils/shadowDom";
18
19
  var FLASH_CLASS_NAME = "ssg-toolpanel--flash";
19
20
  function ToolPanel(props) {
20
21
  const texts = usePopupLocaleText();
@@ -35,7 +36,7 @@ function ToolPanel(props) {
35
36
  createPortalTokens(panel, () => props.themeClassName, layout);
36
37
  onSettled(() => {
37
38
  const element = panelNode;
38
- if (!element || element.contains(element.ownerDocument.activeElement)) {
39
+ if (!element || element.contains(getActiveElement(element))) {
39
40
  return;
40
41
  }
41
42
  const target = element.querySelector('[role="tab"][aria-selected="true"]') ?? element;
@@ -335,6 +336,7 @@ function DragHandleGlyph(props) {
335
336
  }
336
337
 
337
338
  // src/view/ColumnChooserPanel.tsx
339
+ import { getDeepActiveElement } from "@ishibashi0112/spreadsheet-grid-core/internal/utils/shadowDom";
338
340
  var AUTO_SCROLL_EDGE = 28;
339
341
  var AUTO_SCROLL_SPEED = 12;
340
342
  var PANE_ORDER = ["left", "center", "right"];
@@ -399,7 +401,7 @@ function ColumnChooserPanel(props) {
399
401
  const [query, setQuery] = createSignal2("");
400
402
  let searchInput;
401
403
  const bindQuery = createInputValue(query);
402
- const focusSearchOnMount = typeof document !== "undefined" && document.activeElement?.closest(".ssg-toolpanel") != null;
404
+ const focusSearchOnMount = typeof document !== "undefined" && getDeepActiveElement()?.closest(".ssg-toolpanel") != null;
403
405
  let focusFrame = null;
404
406
  onSettled2(() => {
405
407
  if (!searchInput || !focusSearchOnMount || typeof window.matchMedia === "function" && window.matchMedia("(pointer: coarse)").matches) {