wenay-react2 1.0.35 → 1.0.36

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 (95) hide show
  1. package/README.md +12 -56
  2. package/lib/common/api.d.ts +28 -28
  3. package/lib/common/api.js +31 -31
  4. package/lib/common/src/components/Buttons/MiniButton.d.ts +1 -3
  5. package/lib/common/src/components/Buttons/MiniButton.js +1 -3
  6. package/lib/common/src/components/Dnd/{RNDFunc.d.ts → DragArea.d.ts} +1 -1
  7. package/lib/common/src/components/Dnd/{RNDFunc.js → DragArea.js} +1 -1
  8. package/lib/common/src/components/Dnd/{RNDFunc3.d.ts → FloatingWindow.d.ts} +7 -7
  9. package/lib/common/src/components/Dnd/{RNDFunc3.js → FloatingWindow.js} +10 -10
  10. package/lib/common/src/components/Dnd/OutlineDragDemo.d.ts +1 -0
  11. package/lib/common/src/components/Dnd/{DraggableOutlineDiv.js → OutlineDragDemo.js} +1 -2
  12. package/lib/common/src/components/Dnd/Resizable.js +1 -1
  13. package/lib/common/src/components/Dnd/index.d.ts +3 -3
  14. package/lib/common/src/components/Dnd/index.js +3 -3
  15. package/lib/common/src/components/Input.d.ts +5 -5
  16. package/lib/common/src/components/Input.js +10 -10
  17. package/lib/common/src/components/Menu/RightMenu.d.ts +25 -5
  18. package/lib/common/src/components/Menu/RightMenu.js +27 -19
  19. package/lib/common/src/components/Menu/RightMenuStore.d.ts +2 -2
  20. package/lib/common/src/components/Menu/RightMenuStore.js +1 -1
  21. package/lib/common/src/components/Modal/LeftModal.js +4 -4
  22. package/lib/common/src/components/Modal/Modal.d.ts +11 -17
  23. package/lib/common/src/components/Modal/Modal.js +15 -21
  24. package/lib/common/src/components/Modal/ModalContextProvider.d.ts +0 -6
  25. package/lib/common/src/components/Modal/ModalContextProvider.js +2 -9
  26. package/lib/common/src/components/Other.d.ts +2 -2
  27. package/lib/common/src/components/Other.js +5 -5
  28. package/lib/common/src/components/Parameters.d.ts +3 -3
  29. package/lib/common/src/components/Parameters.js +3 -3
  30. package/lib/common/src/components/{ParametersEngine.d.ts → ParamsEditor.d.ts} +1 -1
  31. package/lib/common/src/components/{ParametersEngine.js → ParamsEditor.js} +10 -10
  32. package/lib/common/src/components/Settings/SettingsDialog.d.ts +4 -4
  33. package/lib/common/src/components/Toolbar/Toolbar.d.ts +50 -37
  34. package/lib/common/src/components/Toolbar/Toolbar.js +60 -23
  35. package/lib/common/src/components/UiSlot/UiSlot.d.ts +3 -3
  36. package/lib/common/src/components/UiSlot/UiSlot.js +6 -6
  37. package/lib/common/src/grid/agGrid4/agGrid4.d.ts +4 -4
  38. package/lib/common/src/grid/agGrid4/agGrid4.js +6 -6
  39. package/lib/common/src/grid/agGrid4/index.d.ts +3 -3
  40. package/lib/common/src/grid/agGrid4/index.js +1 -1
  41. package/lib/common/src/grid/agGrid4/theme.d.ts +3 -3
  42. package/lib/common/src/grid/columnState/CardList.d.ts +11 -0
  43. package/lib/common/src/grid/columnState/CardList.js +28 -0
  44. package/lib/common/src/grid/columnState/ColumnDots.d.ts +9 -0
  45. package/lib/common/src/grid/columnState/ColumnDots.js +121 -0
  46. package/lib/common/src/grid/columnState/ColumnsMenu.d.ts +65 -0
  47. package/lib/common/src/grid/columnState/ColumnsMenu.js +123 -0
  48. package/lib/common/src/grid/columnState/columnState.d.ts +113 -0
  49. package/lib/common/src/grid/columnState/columnState.js +284 -0
  50. package/lib/common/src/grid/columnState/index.d.ts +4 -0
  51. package/lib/common/src/grid/columnState/index.js +4 -0
  52. package/lib/common/src/hooks/index.d.ts +1 -1
  53. package/lib/common/src/hooks/index.js +1 -1
  54. package/lib/common/src/hooks/useKeyboard.d.ts +18 -0
  55. package/lib/common/src/hooks/{useAddDownAnyKey.js → useKeyboard.js} +16 -24
  56. package/lib/common/src/hooks/useObserveStore.d.ts +12 -12
  57. package/lib/common/src/hooks/useObserveStore.js +2 -2
  58. package/lib/common/src/hooks/useOutside.d.ts +12 -19
  59. package/lib/common/src/hooks/useOutside.js +9 -16
  60. package/lib/common/src/hooks/useReorder.d.ts +4 -4
  61. package/lib/common/src/hooks/useReorderBoard.d.ts +15 -15
  62. package/lib/common/src/hooks/useReplay.d.ts +9 -9
  63. package/lib/common/src/hooks/useReplay.js +7 -7
  64. package/lib/common/src/logs/logs.d.ts +3 -3
  65. package/lib/common/src/logs/logs.js +11 -13
  66. package/lib/common/src/logs/{logs3.d.ts → logsContext.d.ts} +4 -4
  67. package/lib/common/src/logs/{logs3.js → logsContext.js} +4 -4
  68. package/lib/common/src/menu/menu.d.ts +16 -16
  69. package/lib/common/src/menu/menu.js +12 -11
  70. package/lib/common/src/menu/menuMouse.d.ts +71 -13
  71. package/lib/common/src/menu/menuMouse.js +189 -21
  72. package/lib/common/src/menu/menuR.d.ts +3 -3
  73. package/lib/common/src/menu/menuR.js +5 -5
  74. package/lib/common/src/styles/styleGrid.d.ts +1 -1
  75. package/lib/common/src/styles/tokens.d.ts +1 -1
  76. package/lib/common/src/styles/tokens.js +1 -1
  77. package/lib/common/src/utils/cache.d.ts +11 -11
  78. package/lib/common/src/utils/cache.js +0 -0
  79. package/lib/common/src/utils/gridRows.d.ts +37 -0
  80. package/lib/common/src/utils/{applyTransactionAsyncUpdate.js → gridRows.js} +6 -38
  81. package/lib/common/src/utils/index.d.ts +2 -2
  82. package/lib/common/src/utils/index.js +2 -2
  83. package/lib/common/src/utils/inputAutoStep.d.ts +2 -2
  84. package/lib/common/src/utils/inputAutoStep.js +26 -37
  85. package/lib/common/src/utils/{mapMemory.d.ts → memoryStore.d.ts} +13 -13
  86. package/lib/common/src/utils/{mapMemory.js → memoryStore.js} +32 -32
  87. package/lib/common/src/utils/observableMap.d.ts +5 -5
  88. package/lib/common/src/utils/observableMap.js +3 -3
  89. package/lib/common/updateBy.js +2 -2
  90. package/lib/style/style.css +3 -3
  91. package/lib/style/tokens.css +1 -1
  92. package/package.json +49 -49
  93. package/lib/common/src/components/Dnd/DraggableOutlineDiv.d.ts +0 -2
  94. package/lib/common/src/hooks/useAddDownAnyKey.d.ts +0 -24
  95. package/lib/common/src/utils/applyTransactionAsyncUpdate.d.ts +0 -53
@@ -1,33 +1,201 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { GetMenuR } from "./menuR";
3
- import { MenuBase } from "./menu";
4
- function GetMouseMenuApi(data) {
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { Menu } from "./menu";
4
+ import { OutsideClickArea } from "../hooks/useOutside";
5
+ function normalizeItems(items) {
6
+ return (items ?? []).filter(Boolean);
7
+ }
8
+ function anchorPoint(anchor) {
9
+ if ("clientX" in anchor)
10
+ return { x: anchor.clientX, y: anchor.clientY };
11
+ return anchor;
12
+ }
13
+ function anchorLayerId(anchor) {
14
+ const target = "clientX" in anchor ? anchor.target : undefined;
15
+ return target instanceof Element
16
+ ? target.closest("[data-wenay-menu-layer-id]")?.getAttribute("data-wenay-menu-layer-id") ?? undefined
17
+ : undefined;
18
+ }
19
+ function preventNative(anchor) {
20
+ if ("clientX" in anchor) {
21
+ anchor.preventDefault?.();
22
+ anchor.stopPropagation?.();
23
+ }
24
+ }
25
+ export function createContextMenu(data) {
5
26
  const { name = "mouse" } = data ?? {};
6
- const { MenuR, bb } = GetMenuR();
7
- const value = {
8
- status: true,
9
- clicks: 0
10
- };
27
+ const value = { status: true, clicks: 0 };
11
28
  const menuMouse = {
12
29
  name,
13
30
  get value() { return value; }
14
31
  };
15
32
  const map = new Map();
16
- function other() {
33
+ const state = { open: false, items: [], point: { x: 0, y: 0 }, seq: 0 };
34
+ const listeners = new Set();
35
+ const layers = new Set();
36
+ let layerSeq = 0;
37
+ function emit() {
38
+ state.seq += 1;
39
+ for (const cb of [...listeners])
40
+ cb();
41
+ }
42
+ function subscribe(cb) {
43
+ listeners.add(cb);
44
+ return () => { listeners.delete(cb); };
45
+ }
46
+ function legacyItems() {
17
47
  if (map.has("only"))
18
- return map.get("only");
19
- const t = [];
20
- map.forEach(e => { t.unshift(...e); });
21
- return t;
48
+ return normalizeItems(map.get("only"));
49
+ const items = [];
50
+ map.forEach(e => { items.unshift(...e); });
51
+ return normalizeItems(items);
52
+ }
53
+ function hasQueuedItems(other) {
54
+ return !!other || map.size > 0;
55
+ }
56
+ function close() {
57
+ if (!state.open && state.items.length == 0)
58
+ return;
59
+ state.open = false;
60
+ state.items = [];
61
+ state.layerId = undefined;
62
+ emit();
63
+ }
64
+ function openAt(anchor, items, opts = {}) {
65
+ preventNative(anchor);
66
+ const nextItems = normalizeItems(items);
67
+ if (nextItems.length == 0) {
68
+ close();
69
+ return false;
70
+ }
71
+ state.open = true;
72
+ state.items = nextItems;
73
+ state.point = anchorPoint(anchor);
74
+ state.source = opts.source;
75
+ state.layerId = opts.layerId ?? anchorLayerId(anchor) ?? [...layers][0];
76
+ emit();
77
+ return true;
78
+ }
79
+ function openAtPoint(point, items, opts = {}) {
80
+ return openAt(point, items, opts);
81
+ }
82
+ function getState() {
83
+ return {
84
+ open: state.open,
85
+ items: state.items.slice(),
86
+ point: { ...state.point },
87
+ source: state.source,
88
+ layerId: state.layerId,
89
+ seq: state.seq,
90
+ };
91
+ }
92
+ function bb(b) {
93
+ if (b != undefined) {
94
+ if (b) {
95
+ state.open = true;
96
+ emit();
97
+ }
98
+ else {
99
+ close();
100
+ }
101
+ return;
102
+ }
103
+ return state.open;
22
104
  }
23
- function ReactMouse(agr) {
24
- const datum = menuMouse.value; //staticGetAdd(menuMouse.name, menuMouse.value
25
- // JSX instead of a direct call: MenuR's hooks must live in its own fiber,
26
- // a direct call ties them to whichever component renders ReactMouse
27
- return _jsx(MenuR, { ...agr, other: agr.other ?? other, statusOn: datum.status, onConsume: () => { map.clear(); } });
105
+ function Layer({ children, other, statusOn, onUnClick, onConsume, zIndex, className }) {
106
+ const [, forceRender] = useState(0);
107
+ const [layerId] = useState(() => `${name}-${++layerSeq}`);
108
+ const layerRef = useRef(null);
109
+ const timeEvent = useRef(Date.now());
110
+ const touchXY = useRef({ x: 0, y: 0 });
111
+ const touchTime = useRef(null);
112
+ const enabled = statusOn ?? menuMouse.value.status;
113
+ useEffect(() => {
114
+ layers.add(layerId);
115
+ return () => {
116
+ layers.delete(layerId);
117
+ if (state.layerId == layerId)
118
+ close();
119
+ };
120
+ }, [layerId]);
121
+ useEffect(() => subscribe(() => forceRender(v => v + 1)), []);
122
+ function queuedItems() {
123
+ return other ? normalizeItems(other()) : legacyItems();
124
+ }
125
+ function openQueued(anchor) {
126
+ const opened = openAt(anchor, queuedItems(), { source: "layer", layerId });
127
+ if (opened) {
128
+ map.clear();
129
+ onConsume?.();
130
+ }
131
+ return opened;
132
+ }
133
+ function handleClose() {
134
+ if (!state.open)
135
+ return;
136
+ close();
137
+ onUnClick?.(false);
138
+ }
139
+ function relativePoint() {
140
+ const rect = layerRef.current?.getBoundingClientRect();
141
+ return {
142
+ x: state.point.x - (rect?.left ?? 0),
143
+ y: state.point.y - (rect?.top ?? 0),
144
+ };
145
+ }
146
+ return _jsxs("div", { "data-wenay-menu-layer": "root", "data-wenay-menu-layer-id": layerId, className: "maxSize", style: { position: "relative" }, ref: layerRef, onContextMenu: e => {
147
+ if (!enabled)
148
+ return;
149
+ e.preventDefault();
150
+ e.stopPropagation();
151
+ if (!state.open || hasQueuedItems(other))
152
+ openQueued(e);
153
+ }, onTouchStart: e => {
154
+ if (touchXY.current.x == 0)
155
+ touchXY.current.x = e.touches[0].screenX;
156
+ if (touchXY.current.y == 0)
157
+ touchXY.current.y = e.touches[0].screenY;
158
+ touchTime.current = Date.now();
159
+ }, onTouchMove: e => {
160
+ const x2 = e.touches[0].screenX;
161
+ const y2 = e.touches[0].screenY;
162
+ const pX = Math.max(1, Math.abs(e.touches[0].pageX));
163
+ const pY = Math.max(1, Math.abs(e.touches[0].pageY));
164
+ if ((Math.abs(x2 - touchXY.current.x) / pX > 0.05) || (Math.abs(y2 - touchXY.current.y) / pY > 0.05)) {
165
+ touchTime.current = null;
166
+ }
167
+ }, onTouchEnd: e => {
168
+ if (!enabled)
169
+ return;
170
+ if (touchTime.current && Date.now() - touchTime.current > 300) {
171
+ touchTime.current = null;
172
+ touchXY.current.x = touchXY.current.y = 0;
173
+ if (!state.open || hasQueuedItems(other)) {
174
+ openQueued({ clientX: e.changedTouches[0].clientX, clientY: e.changedTouches[0].clientY, target: e.target, preventDefault: () => e.preventDefault(), stopPropagation: () => e.stopPropagation() });
175
+ }
176
+ }
177
+ }, onDoubleClick: () => {
178
+ timeEvent.current = Date.now();
179
+ }, onMouseUp: event => {
180
+ if (!enabled)
181
+ return;
182
+ if (event.button == 2 || Date.now() - timeEvent.current < 300) {
183
+ if (!state.open || hasQueuedItems(other))
184
+ openQueued(event);
185
+ }
186
+ }, children: [children, state.open && enabled && state.layerId == layerId && _jsx(OutsideClickArea, { outsideClick: handleClose, children: _jsx(Menu, { className: className, data: state.items, coordinate: relativePoint(), zIndex: zIndex }) })] });
28
187
  }
29
188
  return {
30
- bb, get map() { return map; }, get menuMouse() { return menuMouse; }, ReactMouse, ReactMenu: MenuBase
189
+ bb,
190
+ get map() { return map; },
191
+ get menuMouse() { return menuMouse; },
192
+ getState,
193
+ subscribe,
194
+ openAt,
195
+ openAtPoint,
196
+ close,
197
+ Layer,
198
+ MenuView: Menu,
31
199
  };
32
200
  }
33
- export const mouseMenuApi = GetMouseMenuApi();
201
+ export const contextMenu = createContextMenu();
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
- import { tMenuReact } from "./menu";
3
- export declare function GetMenuR(): {
2
+ import { MenuItem } from "./menu";
3
+ export declare function createRightClickMenu(): {
4
4
  /**
5
5
  * Manage the global `bb` variable that prevents opening multiple
6
6
  * menus.
@@ -9,7 +9,7 @@ export declare function GetMenuR(): {
9
9
  MenuR: ({ children, other, statusOn, onUnClick, onConsume, zIndex, className }: {
10
10
  children: React.ReactElement;
11
11
  zIndex?: number;
12
- other?: () => (tMenuReact)[];
12
+ other?: () => (MenuItem)[];
13
13
  statusOn?: boolean;
14
14
  onUnClick?: (e: boolean) => void;
15
15
  onConsume?: () => void;
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React, { useEffect, useRef } from "react";
3
- import { MenuBase } from "./menu";
4
- import { DivOutsideClick } from "../hooks/useOutside";
3
+ import { Menu } from "./menu";
4
+ import { OutsideClickArea } from "../hooks/useOutside";
5
5
  // Wrapper function for creating MenuR and managing the global `bb` variable.
6
- export function GetMenuR() {
6
+ export function createRightClickMenu() {
7
7
  let bb = false; // Global activity flag that prevents opening multiple menus.
8
8
  // Main MenuR component
9
9
  function MenuR({ children, other = () => [], statusOn = true, onUnClick, onConsume, zIndex, className }) {
@@ -92,13 +92,13 @@ export function GetMenuR() {
92
92
  }
93
93
  }, children: [children /* Child element whose events are tracked */, show.status && statusOn && (
94
94
  // Show the context menu
95
- _jsx(DivOutsideClick, { outsideClick: () => {
95
+ _jsx(OutsideClickArea, { outsideClick: () => {
96
96
  if (!bb)
97
97
  return; // Menu is already inactive; do not call close handler
98
98
  bb = false; // Menu is no longer active
99
99
  onUnClick?.(false); // Call close handler
100
100
  setShow({ status: false }); // Hide the menu
101
- }, children: _jsx(MenuBase, { className: className, data: [
101
+ }, children: _jsx(Menu, { className: className, data: [
102
102
  ...(show.plusMenu ?? []),
103
103
  ...(show.menu ?? [])
104
104
  ], coordinate: { ...show.coordinate }, zIndex: zIndex }) }))] }));
@@ -16,6 +16,6 @@ export declare const StyleGridDefault: {
16
16
  };
17
17
  export declare function StyleCSSHeadGridEdit(name: string, rules: string): void;
18
18
  export declare function StyleCSSHeadGrid(): void;
19
- export type tCallFuncAgGrid<T> = (params: CellClassParams & {
19
+ export type AgGridClassRule<T> = (params: CellClassParams & {
20
20
  data: T;
21
21
  }) => CSSProperties | Record<string, any>;
@@ -19,7 +19,7 @@ export declare const tokens: {
19
19
  readonly itemHoverBgColor: "#fff";
20
20
  readonly shadow: "0 0 20px 14px rgba(34, 60, 80, 0.2)";
21
21
  };
22
- /** DivRnd3 window chrome (--wnd-*). Defaults = legacy look; apps re-skin via :root[data-theme].
22
+ /** FloatingWindow window chrome (--wnd-*). Defaults = legacy look; apps re-skin via :root[data-theme].
23
23
  * --wnd-header-height/color/font-size/letter-spacing/transform are intentionally undeclared
24
24
  * (inherit/auto) until a theme sets them. */
25
25
  readonly wnd: {
@@ -21,7 +21,7 @@ export const tokens = {
21
21
  itemHoverBgColor: '#fff',
22
22
  shadow: '0 0 20px 14px rgba(34, 60, 80, 0.2)',
23
23
  },
24
- /** DivRnd3 window chrome (--wnd-*). Defaults = legacy look; apps re-skin via :root[data-theme].
24
+ /** FloatingWindow window chrome (--wnd-*). Defaults = legacy look; apps re-skin via :root[data-theme].
25
25
  * --wnd-header-height/color/font-size/letter-spacing/transform are intentionally undeclared
26
26
  * (inherit/auto) until a theme sets them. */
27
27
  wnd: {
@@ -1,24 +1,24 @@
1
- export type tDirtyListener = (scope?: string, key?: string) => void;
2
- export interface IServerSaveBasePromise {
1
+ export type DirtyListener = (scope?: string, key?: string) => void;
2
+ export interface CacheStorage {
3
3
  set(key: string, value: object): Promise<boolean>;
4
4
  get<T extends (object)>(key: string): Promise<T | null>;
5
5
  delete(key: string): Promise<boolean>;
6
6
  }
7
- export declare class CSaveToCache implements IServerSaveBasePromise {
7
+ export declare class BrowserCacheStorage implements CacheStorage {
8
8
  set(key: string, value: object): Promise<boolean>;
9
9
  get<T extends object>(key: string): Promise<T | null>;
10
10
  delete<T extends object>(key: string): Promise<boolean>;
11
11
  }
12
- export declare class CSaveToLocalStorage implements IServerSaveBasePromise {
12
+ export declare class LocalStorageCache implements CacheStorage {
13
13
  set(key: string, value: object): Promise<boolean>;
14
14
  get<T extends object>(key: string): Promise<T | null>;
15
15
  delete<T extends object>(key: string): Promise<boolean>;
16
16
  deleteAll(): Promise<boolean>;
17
17
  }
18
- export declare const CacheG: CSaveToCache;
19
- export declare const CacheLocal: CSaveToLocalStorage;
20
- export declare const ObjectStringToDate: (obj: unknown) => void;
21
- export declare function CacheFuncMapBase(arr: [k: string, v: Map<string, unknown>][], Save: IServerSaveBasePromise): {
18
+ export declare const browserCacheStorage: BrowserCacheStorage;
19
+ export declare const localStorageCache: LocalStorageCache;
20
+ export declare const restoreDates: (obj: unknown) => void;
21
+ export declare function createCacheMapWithStorage(arr: [k: string, v: Map<string, unknown>][], Save: CacheStorage): {
22
22
  load(): Promise<void>;
23
23
  save(): Promise<void>;
24
24
  saveDebounced(delay?: number): void;
@@ -27,12 +27,12 @@ export declare function CacheFuncMapBase(arr: [k: string, v: Map<string, unknown
27
27
  /** Manual announcement for state the observable maps cannot see (plain Map entries). */
28
28
  markDirty: (scope?: string, key?: string) => void;
29
29
  /** Subscribe to this instance's dirty events (coalesced, async); returns unsubscribe. */
30
- onDirty(cb: tDirtyListener): () => void;
30
+ onDirty(cb: DirtyListener): () => void;
31
31
  /** Cheap hint (e.g. a beforeunload guard); the save diff is the source of truth. */
32
32
  isDirty(): boolean;
33
33
  getArr: [k: string, v: Map<string, unknown>][];
34
34
  };
35
- export declare function CacheFuncMap(arr: [k: string, v: Map<string, unknown>][]): {
35
+ export declare function createCacheMap(arr: [k: string, v: Map<string, unknown>][]): {
36
36
  load(): Promise<void>;
37
37
  save(): Promise<void>;
38
38
  saveDebounced(delay?: number): void;
@@ -41,7 +41,7 @@ export declare function CacheFuncMap(arr: [k: string, v: Map<string, unknown>][]
41
41
  /** Manual announcement for state the observable maps cannot see (plain Map entries). */
42
42
  markDirty: (scope?: string, key?: string) => void;
43
43
  /** Subscribe to this instance's dirty events (coalesced, async); returns unsubscribe. */
44
- onDirty(cb: tDirtyListener): () => void;
44
+ onDirty(cb: DirtyListener): () => void;
45
45
  /** Cheap hint (e.g. a beforeunload guard); the save diff is the source of truth. */
46
46
  isDirty(): boolean;
47
47
  getArr: [k: string, v: Map<string, unknown>][];
Binary file
@@ -0,0 +1,37 @@
1
+ import type { GridReadyEvent } from "ag-grid-community";
2
+ import type { RefObject } from "react";
3
+ declare const defaultGridRowsOptions: {
4
+ update: boolean;
5
+ add: boolean;
6
+ updateBuffer: boolean;
7
+ sync: boolean;
8
+ };
9
+ export type GridRowsOptions = Partial<typeof defaultGridRowsOptions>;
10
+ type CommonGridRowsParams<T> = {
11
+ getId: (...a: any[]) => string;
12
+ bufTable: {
13
+ [id: string]: Partial<T>;
14
+ };
15
+ option?: GridRowsOptions;
16
+ };
17
+ export type ApplyGridRowsParams<T> = CommonGridRowsParams<T> & ({
18
+ newData?: (Partial<T>)[];
19
+ removeData?: (Partial<T>)[];
20
+ synchronization?: never;
21
+ gridRef?: RefObject<GridReadyEvent<T, any> | null | undefined>;
22
+ grid?: GridReadyEvent<T, any> | null | undefined;
23
+ onlyMemo?: boolean;
24
+ } | ({
25
+ newData?: never;
26
+ removeData?: never;
27
+ synchronization: true;
28
+ onlyMemo?: never;
29
+ } & ({
30
+ grid: GridReadyEvent<T, any> | null | undefined;
31
+ gridRef?: never;
32
+ } | {
33
+ gridRef: RefObject<GridReadyEvent<T, any> | null | undefined>;
34
+ grid?: never;
35
+ })));
36
+ export declare function applyGridRows<T>(params: ApplyGridRowsParams<T>): void;
37
+ export {};
@@ -1,15 +1,13 @@
1
- // Wrapper to simplify working with the grid through a memory point
2
- const optionsDef = {
1
+ const defaultGridRowsOptions = {
3
2
  update: true,
4
3
  add: true,
5
4
  updateBuffer: true,
6
5
  sync: false,
7
6
  };
8
- function applyTransactionAsyncUpdate3({ getId, bufTable, option, newData, grid, remove }) {
9
- const op = { ...optionsDef, ...(option ?? {}) };
7
+ function applyGridRowsCore({ getId, bufTable, option, newData, grid, remove }) {
8
+ const op = { ...defaultGridRowsOptions, ...(option ?? {}) };
10
9
  if (!grid?.api.getRowNode)
11
10
  return;
12
- // Determine which rows must be added and which only need updates
13
11
  const arrNew = [];
14
12
  const arr = newData.map(e => {
15
13
  const id = getId(e);
@@ -31,25 +29,11 @@ function applyTransactionAsyncUpdate3({ getId, bufTable, option, newData, grid,
31
29
  });
32
30
  return;
33
31
  }
34
- // Apply remove once and independently: otherwise removal was lost with empty add/update and duplicated with both
35
32
  if ((arrNew.length && op.add) || remove?.length)
36
33
  grid.api.applyTransaction({ add: (arrNew.length && op.add) ? arrNew : [], remove: remove });
37
34
  if (arr.length && op.update)
38
35
  grid.api.applyTransactionAsync({ update: arr });
39
36
  }
40
- // There is no removal here, but this version may still be used somewhere
41
- /**
42
- * @deprecated v1: does not support row removal and silently loses data while the grid is not ready.
43
- * Use `useAgGrid`/`createGridBuffer` (grid/agGrid4) - buffer + attach/sync,
44
- * or at least `applyTransactionAsyncUpdate2`.
45
- */
46
- export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, option) {
47
- return applyTransactionAsyncUpdate3({ getId, option, newData, grid, bufTable });
48
- }
49
- /** @deprecated No-op stub: always returns {}. Never implemented; will be removed in a major version. */
50
- export function getUpdateTable(grid, newData, getId, bufTable, option) {
51
- return {};
52
- }
53
37
  function resolveGrid(params) {
54
38
  if (params.grid?.api?.getRowNode)
55
39
  return params.grid;
@@ -57,13 +41,12 @@ function resolveGrid(params) {
57
41
  return params.gridRef.current;
58
42
  return null;
59
43
  }
60
- export function applyTransactionAsyncUpdate2(params) {
44
+ export function applyGridRows(params) {
61
45
  const { getId, bufTable, newData, removeData } = params;
62
- const op = { ...optionsDef, ...(params.option ?? {}) };
46
+ const op = { ...defaultGridRowsOptions, ...(params.option ?? {}) };
63
47
  const g = resolveGrid(params);
64
48
  if (g && params.onlyMemo != true) {
65
49
  if (params.synchronization) {
66
- // === SYNCHRONIZATION: bufTable is the source of truth ===
67
50
  const bufIds = new Set(Object.keys(bufTable));
68
51
  const gridIds = new Set();
69
52
  const arrAdd = [];
@@ -99,7 +82,7 @@ export function applyTransactionAsyncUpdate2(params) {
99
82
  toRemove.push(existing);
100
83
  });
101
84
  if (newData?.length || toRemove.length)
102
- applyTransactionAsyncUpdate3({ grid: g, newData: newData ?? [], getId, bufTable, option: op, remove: toRemove });
85
+ applyGridRowsCore({ grid: g, newData: newData ?? [], getId, bufTable, option: op, remove: toRemove });
103
86
  }
104
87
  }
105
88
  else {
@@ -112,18 +95,3 @@ export function applyTransactionAsyncUpdate2(params) {
112
95
  });
113
96
  }
114
97
  }
115
- /** @deprecated Duplicate of `numericComparator` from grid/agGrid4 (core.ts) - use that instead. */
116
- export function getComparatorGrid(func) {
117
- return (...param) => {
118
- const [a1, b1, modeA, modeB, inv] = param; // Unpack parameters into the function
119
- const [a, b] = func ? func(...param) : [a1, b1]; // Use the transforming func if provided
120
- return ((typeof a == "number" && !Number.isNaN(a)) &&
121
- (typeof b == "number" && !Number.isNaN(b))) // If both a and b are valid numbers
122
- ? a - b // Difference between numbers
123
- : a == b
124
- ? 0 // If values are equal, return 0
125
- : (!Number.isNaN(b) && b != undefined)
126
- ? (inv ? -1 : 1) // If b exists: order is determined by inv
127
- : (inv ? 1 : -1); // If b is missing: order is determined by inv
128
- };
129
- }
@@ -1,8 +1,8 @@
1
- export * from './applyTransactionAsyncUpdate';
1
+ export * from './gridRows';
2
2
  export * from './arrayPromise';
3
3
  export * from './cache';
4
4
  export * from './callbackHub';
5
5
  export * from './inputAutoStep';
6
- export * from './mapMemory';
6
+ export * from './memoryStore';
7
7
  export * from './observableMap';
8
8
  export * from './pageVisibilityContext';
@@ -1,8 +1,8 @@
1
- export * from './applyTransactionAsyncUpdate';
1
+ export * from './gridRows';
2
2
  export * from './arrayPromise';
3
3
  export * from './cache';
4
4
  export * from './callbackHub';
5
5
  export * from './inputAutoStep';
6
- export * from './mapMemory';
6
+ export * from './memoryStore';
7
7
  export * from './observableMap';
8
8
  export * from './pageVisibilityContext';
@@ -1,10 +1,10 @@
1
- interface IStepInputElement extends HTMLElement {
1
+ interface StepInputElement extends HTMLElement {
2
2
  value: string;
3
3
  step: string;
4
4
  min: string;
5
5
  max: string;
6
6
  }
7
- export declare function SetAutoStepForElement(element: IStepInputElement, params?: {
7
+ export declare function setAutoStepForElement(element: StepInputElement, params?: {
8
8
  minStep?: number | undefined;
9
9
  maxStep?: number;
10
10
  }): () => void;
@@ -1,78 +1,69 @@
1
1
  /// <reference lib="dom" />
2
- // Set automatic step control for an input element
3
- import { GetDblPrecision, GetDblPrecision2, NormalizeDouble } from "wenay-common2";
4
- // step is a power of 0.1 (0.1, 0.01, ...) - resilient to float noise,
5
- // unlike the previous Math.log10(step)%1==0
2
+ import { decimals, round } from "wenay-common2";
6
3
  function isPowerOfTenth(step) {
7
4
  if (!(step > 0 && step < 1))
8
5
  return false;
9
6
  const digits = Math.round(-Math.log10(step));
10
7
  return Math.abs(Math.pow(0.1, digits) - step) < step * 1e-9;
11
8
  }
12
- // Own handlers on the element: repeated calls remove previous ones (like the old on* overwrite)
13
9
  const appliedHandlers = new WeakMap();
14
- export function SetAutoStepForElement(element, params = { maxStep: 1 }) {
10
+ export function setAutoStepForElement(element, params = { maxStep: 1 }) {
15
11
  appliedHandlers.get(element)?.();
16
- function parse(valueStr) { let val = parseFloat(valueStr); return isNaN(val) ? null : val; }
12
+ function parse(valueStr) { const val = parseFloat(valueStr); return isNaN(val) ? null : val; }
17
13
  const { minStep, maxStep = 1 } = params;
18
- const maxDigits = minStep ? GetDblPrecision(minStep) : undefined;
14
+ const maxDigits = minStep ? decimals(minStep) : undefined;
19
15
  const stepDefault = parse(element.step);
20
16
  const minDefault = parse(element.min);
21
17
  const maxDefault = parse(element.max);
22
18
  const minDigits = maxStep > 0 ? Math.max(0, -Math.round(Math.log10(maxStep))) : 0;
23
- let _digits = null;
24
- let _step = parse(element.step);
25
- let _min = parse(element.min);
19
+ let digitsCurrent = null;
20
+ let stepCurrent = parse(element.step);
21
+ let minCurrent = parse(element.min);
26
22
  function calculateStep(valueStr) {
27
- //function NormalizeDouble(value :number, digits :number) { let factor=Math.pow(10, digits); return Math.round(value * factor)/factor; }
28
- //if (dotPos===valueStr.length-1) dotPos--;
29
- //let digits= GetDblPrecision2(parseFloat(valueStr), minDigits, 10);
30
- let dotPos = valueStr.search(/\.|,/); // Find a dot or comma
31
- let digits = (dotPos >= 0) ? valueStr.length - dotPos - 1 : 0;
23
+ const dotPos = valueStr.search(/\.|,/);
24
+ let digits = dotPos >= 0 ? valueStr.length - dotPos - 1 : 0;
32
25
  digits = Math.max(digits, minDigits);
33
26
  if (digits > 10)
34
- digits = GetDblPrecision2(parseFloat(valueStr), minDigits, 10);
27
+ digits = decimals(parseFloat(valueStr), 10, minDigits);
35
28
  if (maxDigits != null)
36
29
  digits = Math.min(digits, maxDigits);
37
- let step = NormalizeDouble(Math.pow(0.1, digits), digits);
30
+ let step = round(Math.pow(0.1, digits), digits);
38
31
  if (minStep)
39
- step = NormalizeDouble(Math.round(step / minStep) * minStep, digits);
32
+ step = round(Math.round(step / minStep) * minStep, digits);
40
33
  if (maxDefault != null && minDefault != null)
41
34
  if (maxDefault - minDefault < step * 2)
42
- return _step;
43
- _digits = digits;
44
- _step = step;
45
- //if (Math.abs(min) < step) min= Math.floor(Math.abs(min)/step)*step * Math.sign(min);
46
- if (_min != null) {
47
- if (Math.abs(_min) % step != 0)
48
- _min = Math.floor(Math.abs(_min) / step) * step * Math.sign(_min);
49
- element.min = _min + "";
35
+ return stepCurrent;
36
+ digitsCurrent = digits;
37
+ stepCurrent = step;
38
+ if (minCurrent != null) {
39
+ if (Math.abs(minCurrent) % step != 0)
40
+ minCurrent = Math.floor(Math.abs(minCurrent) / step) * step * Math.sign(minCurrent);
41
+ element.min = minCurrent + "";
50
42
  }
51
43
  element.step = step + "";
52
44
  return step;
53
45
  }
54
- let modeAuto = !_step || isPowerOfTenth(_step);
46
+ let modeAuto = !stepCurrent || isPowerOfTenth(stepCurrent);
55
47
  if (modeAuto) {
56
- calculateStep((_step ? (Math.round(parseFloat(element.value) / _step) * _step) : element.value) + "");
48
+ calculateStep((stepCurrent ? (Math.round(parseFloat(element.value) / stepCurrent) * stepCurrent) : element.value) + "");
57
49
  }
58
- if (_step && minDefault && Math.abs(minDefault % _step) > 1e-10)
50
+ if (stepCurrent && minDefault && Math.abs(minDefault % stepCurrent) > 1e-10)
59
51
  modeAuto = false;
60
- else if (_step && maxDefault && Math.abs(maxDefault % _step) > 1e-10)
52
+ else if (stepCurrent && maxDefault && Math.abs(maxDefault % stepCurrent) > 1e-10)
61
53
  modeAuto = false;
62
54
  else
63
- modeAuto ||= (_step != null && (minStep == null || _step > minStep));
64
- // addEventListener instead of on*=: do not overwrite other handlers; return a disposer
55
+ modeAuto ||= (stepCurrent != null && (minStep == null || stepCurrent > minStep));
65
56
  const onKeyUp = () => { if (modeAuto)
66
57
  calculateStep(element.value); };
67
58
  const onChange = () => {
68
- let digits = _digits;
59
+ const digits = digitsCurrent;
69
60
  if (digits != null)
70
61
  element.value = parseFloat(element.value).toFixed(digits);
71
62
  if (minDefault != null && parseFloat(element.value) < minDefault) {
72
63
  element.step = stepDefault + "";
73
64
  element.value = minDefault + "";
74
65
  element.min = minDefault + "";
75
- _digits = null;
66
+ digitsCurrent = null;
76
67
  }
77
68
  element.setAttribute("value", element.value);
78
69
  };
@@ -86,5 +77,3 @@ export function SetAutoStepForElement(element, params = { maxStep: 1 }) {
86
77
  appliedHandlers.set(element, dispose);
87
78
  return dispose;
88
79
  }
89
- //import * as Time from "./Time"
90
- //import {const_Date} from "./Time";