@omnigrid/react 0.1.7 → 0.1.9

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/dist/OmniGrid.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { flushSync } from "react-dom";
3
4
  import { DomPool } from "@omnigrid/core";
4
5
  import { contentToReactNode } from "./content";
5
6
  import { computeGroupSegments } from "./groupHeader";
@@ -285,7 +286,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
285
286
  * React effects (structural changes) and directly from the scroll rAF
286
287
  * handler (imperative, no React re-render).
287
288
  */
288
- const syncPool = () => {
289
+ const syncPool = (synchronousColumnWindow = false) => {
289
290
  const state = grid.getState();
290
291
  const currentViewportData = grid.getViewportData();
291
292
  const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
@@ -314,9 +315,19 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
314
315
  const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
315
316
  if (columnWindowKey !== columnWindowKeyRef.current) {
316
317
  columnWindowKeyRef.current = columnWindowKey;
317
- for (const pane of layers.central.panes)
318
- pane.updateColumns(layers.central.columns, layers.central.originX);
319
- setColumnWindowVersion((v) => v + 1);
318
+ const updateColumnWindow = () => {
319
+ for (const pane of layers.central.panes)
320
+ pane.updateColumns(layers.central.columns, layers.central.originX);
321
+ setColumnWindowVersion((v) => v + 1);
322
+ };
323
+ if (synchronousColumnWindow) {
324
+ // Keep React-rendered cell content and headers in step with the
325
+ // imperative cell repositioning before the browser paints.
326
+ flushSync(updateColumnWindow);
327
+ }
328
+ else {
329
+ updateColumnWindow();
330
+ }
320
331
  }
321
332
  };
322
333
  /**
@@ -434,7 +445,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
434
445
  // so this does NOT trigger a React re-render. The DomPool is
435
446
  // updated imperatively below.
436
447
  grid.setViewport({ scrollTop, scrollLeft });
437
- syncPool();
448
+ syncPool(true);
438
449
  });
439
450
  };
440
451
  if (!isMeasured) {
@@ -499,6 +510,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
499
510
  left: Math.round(item.offset - originX),
500
511
  top: fullHeight ? -(gapRows * rowHeight) : 0,
501
512
  bottom: 0,
513
+ touchAction: "none",
502
514
  whiteSpace: "nowrap",
503
515
  width: item.width,
504
516
  }, children: item.column.headerRenderer ? (contentToReactNode(item.column.headerRenderer(item.column), {
package/dist/content.js CHANGED
@@ -33,6 +33,10 @@ const SLOT_NODE_EVENTS = {
33
33
  click: "onClick",
34
34
  change: "onChange",
35
35
  keydown: "onKeyDown",
36
+ pointerdown: "onPointerDown",
37
+ pointermove: "onPointerMove",
38
+ pointerup: "onPointerUp",
39
+ dblclick: "onDoubleClick",
36
40
  };
37
41
  const SLOT_NODE_ATTRS = {
38
42
  class: "className",
@@ -40,11 +44,43 @@ const SLOT_NODE_ATTRS = {
40
44
  readonly: "readOnly",
41
45
  };
42
46
  const VOID_TAGS = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
47
+ function parseStyleAttribute(rawValue) {
48
+ if (rawValue === undefined || rawValue === null || typeof rawValue === "boolean")
49
+ return undefined;
50
+ const value = String(rawValue).trim();
51
+ if (!value)
52
+ return undefined;
53
+ const style = {};
54
+ for (const entry of value.split(";")) {
55
+ const trimmed = entry.trim();
56
+ if (!trimmed)
57
+ continue;
58
+ const index = trimmed.indexOf(":");
59
+ if (index === -1)
60
+ continue;
61
+ const cssName = trimmed.slice(0, index).trim();
62
+ const cssValue = trimmed.slice(index + 1).trim();
63
+ if (!cssName || !cssValue)
64
+ continue;
65
+ const camelName = cssName
66
+ .split("-")
67
+ .map((part, idx) => (idx === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)))
68
+ .join("");
69
+ style[camelName] = cssValue;
70
+ }
71
+ return Object.keys(style).length ? style : undefined;
72
+ }
43
73
  function slotNodeToReact(node, bridge) {
44
74
  const context = bridge.context();
45
75
  const props = {};
46
76
  for (const [name, rawValue] of Object.entries(node.attrs ?? {})) {
47
77
  const key = SLOT_NODE_ATTRS[name] ?? name;
78
+ if (name === "style") {
79
+ const parsedStyle = parseStyleAttribute(rawValue);
80
+ if (parsedStyle)
81
+ props.style = parsedStyle;
82
+ continue;
83
+ }
48
84
  if (typeof rawValue === "boolean") {
49
85
  if (rawValue)
50
86
  props[key] = true;
@@ -58,10 +94,17 @@ function slotNodeToReact(node, bridge) {
58
94
  if (!reactEvent || !handler)
59
95
  continue;
60
96
  props[reactEvent] = (nativeEvent) => {
61
- if (eventName === "click")
97
+ if (["click", "pointerdown", "pointermove", "pointerup", "dblclick"].includes(eventName)) {
62
98
  nativeEvent.preventDefault();
99
+ }
63
100
  nativeEvent.stopPropagation();
64
- handler(context, { value: nativeEvent.currentTarget.value, key: nativeEvent.key });
101
+ handler(context, {
102
+ value: nativeEvent.currentTarget.value,
103
+ key: nativeEvent.key,
104
+ clientX: nativeEvent.clientX,
105
+ clientY: nativeEvent.clientY,
106
+ button: nativeEvent.button,
107
+ });
65
108
  };
66
109
  }
67
110
  if (VOID_TAGS.has(node.tag))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",