@jsb188/mday-web 1.1.10 → 1.1.11

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 (33) hide show
  1. package/package.json +34 -24
  2. package/src/libs/route-metadata.server.ts +67 -0
  3. package/src/modules/AgentDocs.tsx +800 -0
  4. package/src/modules/DocAccessSettings.tsx +963 -0
  5. package/src/modules/Grids.tsx +842 -0
  6. package/src/modules/RouteShell.tsx +76 -0
  7. package/src/utils/account-web.ts +64 -0
  8. package/src/utils/list-web.ts +17 -0
  9. package/src/utils/log-web.ts +162 -52
  10. package/src/utils/org-web.ts +35 -8
  11. package/src/utils/route-helpers.ts +902 -596
  12. package/src/utils/workflow-web.ts +96 -0
  13. package/tsconfig.json +11 -11
  14. package/src/modules/DataTable-ContextMenu.tsx +0 -169
  15. package/src/modules/DataTable-InboundContact.tsx +0 -523
  16. package/src/modules/DataTable.tsx +0 -5060
  17. package/src/modules/Sheet-ContextMenu.tsx +0 -161
  18. package/src/modules/Sheet.tsx +0 -28
  19. package/src/modules/cell-save-beacon.ts +0 -67
  20. package/src/modules/dataTable-interaction-state.ts +0 -276
  21. package/src/modules/dataTable-shortcuts.ts +0 -192
  22. package/src/modules/dataTable-viewport.ts +0 -89
  23. package/src/modules/grid-cell-render.ts +0 -72
  24. package/src/modules/grid-context-menu.ts +0 -112
  25. package/src/modules/grid-keyboard.ts +0 -267
  26. package/src/modules/grid-render-store.ts +0 -103
  27. package/src/modules/grid-runtime.ts +0 -178
  28. package/src/modules/grid-selection.ts +0 -336
  29. package/src/modules/grid-viewport.ts +0 -57
  30. package/src/modules/use-dataTable-states.ts +0 -529
  31. package/src/modules/use-debounced-cell-save-batch.ts +0 -160
  32. package/tests/DataTable.test.tsx +0 -4466
  33. package/tests/dataTable-interaction-state.test.ts +0 -127
@@ -1,192 +0,0 @@
1
- import type { DataTableRowGQL } from '@jsb188/mday/types/dataTable.d.ts';
2
- import {
3
- type SheetColumnMetric,
4
- type SheetUISelectedCellState,
5
- } from '@jsb188/react-web/ui/SheetUI';
6
- import { type DataTableInteractionCellSelection } from './dataTable-interaction-state.ts';
7
- import {
8
- getGridRangeSelection,
9
- getNextActiveGridSelectedCell,
10
- getOrderedGridSelectedCells,
11
- } from './grid-selection.ts';
12
-
13
- /*
14
- * Return DataTable row ids in their rendered order for shared grid helpers.
15
- */
16
-
17
- function getDataTableRenderedRowIds(renderedRows: DataTableRowGQL[]) {
18
- return renderedRows.map((row) => row.id);
19
- }
20
-
21
- /*
22
- * Build a rectangular selection between an anchor cell and active cell.
23
- */
24
-
25
- export function getDataTableRangeSelection(params: {
26
- activeCell: SheetUISelectedCellState;
27
- anchorCell: SheetUISelectedCellState;
28
- columnMetrics: SheetColumnMetric[];
29
- renderedRows: DataTableRowGQL[];
30
- selectedActiveCell?: SheetUISelectedCellState;
31
- }): DataTableInteractionCellSelection {
32
- return getGridRangeSelection({
33
- activeCell: params.activeCell,
34
- anchorCell: params.anchorCell,
35
- columnMetrics: params.columnMetrics,
36
- rowIds: getDataTableRenderedRowIds(params.renderedRows),
37
- selectedActiveCell: params.selectedActiveCell,
38
- });
39
- }
40
-
41
- /*
42
- * Return selected cells in row-major order for clipboard operations.
43
- */
44
-
45
- export function getDataTableOrderedSelectedCells(params: {
46
- columnMetrics: SheetColumnMetric[];
47
- renderedRows: DataTableRowGQL[];
48
- selection: DataTableInteractionCellSelection;
49
- }) {
50
- return getOrderedGridSelectedCells({
51
- columnMetrics: params.columnMetrics,
52
- rowIds: getDataTableRenderedRowIds(params.renderedRows),
53
- selectedCellKeyMap: params.selection.selectedCellKeyMap,
54
- });
55
- }
56
-
57
- /*
58
- * Return the next active cell within the current selected cells.
59
- */
60
-
61
- export function getDataTableNextActiveSelectedCell(params: {
62
- columnMetrics: SheetColumnMetric[];
63
- direction: 'forward' | 'backward';
64
- renderedRows: DataTableRowGQL[];
65
- selection: DataTableInteractionCellSelection;
66
- }) {
67
- return getNextActiveGridSelectedCell({
68
- activeCell: params.selection.activeCell,
69
- columnMetrics: params.columnMetrics,
70
- direction: params.direction,
71
- rowIds: getDataTableRenderedRowIds(params.renderedRows),
72
- selectedCellKeyMap: params.selection.selectedCellKeyMap,
73
- });
74
- }
75
-
76
- /*
77
- * Parse one delimited clipboard row with basic quoted-cell support.
78
- */
79
-
80
- function parseDataTableDelimitedClipboardRow(rowText: string, delimiter: string) {
81
- const values: string[] = [];
82
- let currentValue = '';
83
- let quoted = false;
84
-
85
- for (let index = 0; index < rowText.length; index += 1) {
86
- const char = rowText[index];
87
- const nextChar = rowText[index + 1];
88
-
89
- if (char === '"' && quoted && nextChar === '"') {
90
- currentValue += '"';
91
- index += 1;
92
- continue;
93
- }
94
-
95
- if (char === '"') {
96
- quoted = !quoted;
97
- continue;
98
- }
99
-
100
- if (char === delimiter && !quoted) {
101
- values.push(currentValue);
102
- currentValue = '';
103
- continue;
104
- }
105
-
106
- currentValue += char;
107
- }
108
-
109
- values.push(currentValue);
110
-
111
- return values;
112
- }
113
-
114
- /*
115
- * Convert clipboard text from spreadsheets into a rectangular value grid.
116
- */
117
-
118
- export function parseDataTableClipboardText(text: string) {
119
- const normalizedText = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
120
- const textWithoutTrailingLineBreak = normalizedText.endsWith('\n') ? normalizedText.slice(0, -1) : normalizedText;
121
- const delimiter = textWithoutTrailingLineBreak.includes('\t') ? '\t' : ',';
122
-
123
- if (!textWithoutTrailingLineBreak) {
124
- return [['']];
125
- }
126
-
127
- return textWithoutTrailingLineBreak.split('\n').map((rowText) => {
128
- return parseDataTableDelimitedClipboardRow(rowText, delimiter);
129
- });
130
- }
131
-
132
- /*
133
- * Map pasted clipboard values onto loaded dataTable cells.
134
- */
135
-
136
- export function getDataTablePasteTargets(params: {
137
- activeCell: SheetUISelectedCellState;
138
- clipboardGrid: string[][];
139
- columnMetrics: SheetColumnMetric[];
140
- renderedRows: DataTableRowGQL[];
141
- selection: DataTableInteractionCellSelection;
142
- }) {
143
- const selectionCells = getDataTableOrderedSelectedCells({
144
- columnMetrics: params.columnMetrics,
145
- renderedRows: params.renderedRows,
146
- selection: params.selection,
147
- });
148
- const shouldFillSelection = params.clipboardGrid.length === 1 && params.clipboardGrid[0]?.length === 1 && selectionCells.length > 1;
149
- const targets: Array<SheetUISelectedCellState & { value: string }> = [];
150
-
151
- if (shouldFillSelection) {
152
- const value = params.clipboardGrid[0]?.[0] || '';
153
-
154
- selectionCells.forEach((cell) => {
155
- targets.push({
156
- ...cell,
157
- value,
158
- });
159
- });
160
-
161
- return targets;
162
- }
163
-
164
- const startColumnIndex = params.columnMetrics.findIndex((metric) => metric.column.key === params.activeCell.cellKey);
165
- const startRowIndex = params.renderedRows.findIndex((row) => row.id === params.activeCell.rowId);
166
-
167
- if (startColumnIndex < 0 || startRowIndex < 0) {
168
- return targets;
169
- }
170
-
171
- params.clipboardGrid.forEach((rowValues, rowOffset) => {
172
- const row = params.renderedRows[startRowIndex + rowOffset];
173
- if (!row) {
174
- return;
175
- }
176
-
177
- rowValues.forEach((value, columnOffset) => {
178
- const column = params.columnMetrics[startColumnIndex + columnOffset]?.column;
179
- if (!column) {
180
- return;
181
- }
182
-
183
- targets.push({
184
- cellKey: column.key,
185
- rowId: row.id,
186
- value,
187
- });
188
- });
189
- });
190
-
191
- return targets;
192
- }
@@ -1,89 +0,0 @@
1
- import type { DataTableRowGQL } from '@jsb188/mday/types/dataTable.d.ts';
2
- import {
3
- SHEET_ROW_HEIGHT,
4
- SHEET_ROW_NUMBER_WIDTH,
5
- SHEET_STICKY_SPACER_SIZE,
6
- type SheetColumnMetric,
7
- type SheetUISelectedCellState,
8
- } from '@jsb188/react-web/ui/SheetUI';
9
- import type { DataTableArrowNavigationDirection } from './DataTable-ContextMenu.tsx';
10
- import { getGridArrowNavigationSelection } from './grid-selection.ts';
11
-
12
- export type DataTableArrowNavigationRuntime = {
13
- columnMetrics: SheetColumnMetric[];
14
- renderedRows: DataTableRowGQL[];
15
- scrollLeft: number;
16
- scrollNode: HTMLDivElement | null;
17
- scrollTop: number;
18
- stickyColumnCount: number;
19
- stickyColumnEndLeft: number;
20
- stickyHeaderHeight: number;
21
- totalHeight: number;
22
- totalWidth: number;
23
- viewportHeight: number;
24
- viewportWidth: number;
25
- };
26
-
27
- /*
28
- * Return the next selected dataTable cell after one arrow-key movement.
29
- */
30
-
31
- export function getDataTableArrowNavigationSelection(params: {
32
- columnMetrics: SheetColumnMetric[];
33
- direction: DataTableArrowNavigationDirection;
34
- renderedRows: DataTableRowGQL[];
35
- selectedCellState?: SheetUISelectedCellState | null;
36
- }) {
37
- return getGridArrowNavigationSelection({
38
- columnMetrics: params.columnMetrics,
39
- direction: params.direction,
40
- rowIds: params.renderedRows.map((row) => row.id),
41
- selectedCellState: params.selectedCellState,
42
- });
43
- }
44
-
45
- /*
46
- * Keep a dataTable scroll position inside the current canvas bounds.
47
- */
48
-
49
- function clampDataTableScrollPosition(value: number, maxValue: number) {
50
- return Math.min(Math.max(0, value), Math.max(0, maxValue));
51
- }
52
-
53
- /*
54
- * Return the scroll position needed to keep one selected dataTable cell in view.
55
- */
56
-
57
- export function getDataTableArrowNavigationScrollState(params: { columnMetric: SheetColumnMetric; rowIndex: number; runtime: DataTableArrowNavigationRuntime }) {
58
- const { columnMetric, rowIndex, runtime } = params;
59
- let nextScrollLeft = runtime.scrollLeft;
60
- let nextScrollTop = runtime.scrollTop;
61
- const cellTop = runtime.stickyHeaderHeight + rowIndex * SHEET_ROW_HEIGHT;
62
- const cellBottom = cellTop + SHEET_ROW_HEIGHT;
63
- const visibleTop = runtime.scrollTop + runtime.stickyHeaderHeight;
64
- const visibleBottom = runtime.scrollTop + runtime.viewportHeight;
65
-
66
- if (cellTop < visibleTop) {
67
- nextScrollTop = cellTop - runtime.stickyHeaderHeight;
68
- } else if (cellBottom > visibleBottom) {
69
- nextScrollTop = cellBottom - runtime.viewportHeight;
70
- }
71
-
72
- if (columnMetric.columnIndex >= runtime.stickyColumnCount) {
73
- const cellLeft = SHEET_ROW_NUMBER_WIDTH + columnMetric.left + SHEET_STICKY_SPACER_SIZE;
74
- const cellRight = cellLeft + columnMetric.width;
75
- const visibleLeft = runtime.scrollLeft + runtime.stickyColumnEndLeft;
76
- const visibleRight = runtime.scrollLeft + runtime.viewportWidth;
77
-
78
- if (cellLeft < visibleLeft) {
79
- nextScrollLeft = cellLeft - runtime.stickyColumnEndLeft;
80
- } else if (cellRight > visibleRight) {
81
- nextScrollLeft = cellRight - runtime.viewportWidth;
82
- }
83
- }
84
-
85
- return {
86
- scrollLeft: clampDataTableScrollPosition(nextScrollLeft, runtime.totalWidth - runtime.viewportWidth),
87
- scrollTop: clampDataTableScrollPosition(nextScrollTop, runtime.totalHeight - runtime.viewportHeight),
88
- };
89
- }
@@ -1,72 +0,0 @@
1
- import {
2
- getSheetCellKey,
3
- type SheetUICell,
4
- type SheetUICellRenderSnapshot,
5
- type SheetUIEditState,
6
- type SheetUISelectedCellKeyMap,
7
- type SheetUISelectedCellState,
8
- } from '@jsb188/react-web/ui/SheetUI';
9
-
10
- /*
11
- * Build the external render-store snapshot for one visual grid cell.
12
- */
13
-
14
- export function getGridCellRenderSnapshot(params: {
15
- cell?: SheetUICell;
16
- cellKey: string;
17
- editState?: SheetUIEditState | null;
18
- rowId: string;
19
- selectedCellKeyMap?: SheetUISelectedCellKeyMap | null;
20
- selectedCellState?: SheetUISelectedCellState | null;
21
- }): SheetUICellRenderSnapshot {
22
- const cellRenderKey = getSheetCellKey(params.rowId, params.cellKey);
23
- const active = params.selectedCellState?.rowId === params.rowId && params.selectedCellState.cellKey === params.cellKey;
24
- const selected = Boolean(
25
- params.selectedCellKeyMap?.[cellRenderKey] ||
26
- active
27
- );
28
-
29
- return {
30
- active,
31
- cell: params.cell,
32
- editState: params.editState?.rowId === params.rowId && params.editState.cellKey === params.cellKey ? params.editState : null,
33
- selected,
34
- };
35
- }
36
-
37
- /*
38
- * Return the render-store keys touched by a selected or editing cell transition.
39
- */
40
-
41
- export function getGridInteractionRenderKeys(params: {
42
- currentEditState?: SheetUIEditState | null;
43
- currentSelectedCellKeyMap?: SheetUISelectedCellKeyMap | null;
44
- currentSelectedCellState?: SheetUISelectedCellState | null;
45
- nextEditState?: SheetUIEditState | null;
46
- nextSelectedCellKeyMap?: SheetUISelectedCellKeyMap | null;
47
- nextSelectedCellState?: SheetUISelectedCellState | null;
48
- }) {
49
- const keys = new Set<string>();
50
-
51
- [
52
- params.currentEditState,
53
- params.currentSelectedCellState,
54
- params.nextEditState,
55
- params.nextSelectedCellState,
56
- ].forEach((cellState) => {
57
- if (cellState?.rowId && cellState.cellKey) {
58
- keys.add(getSheetCellKey(cellState.rowId, cellState.cellKey));
59
- }
60
- });
61
-
62
- [
63
- params.currentSelectedCellKeyMap,
64
- params.nextSelectedCellKeyMap,
65
- ].forEach((cellKeyMap) => {
66
- Object.keys(cellKeyMap || {}).forEach((cellKey) => {
67
- keys.add(cellKey);
68
- });
69
- });
70
-
71
- return keys;
72
- }
@@ -1,112 +0,0 @@
1
- import { usePopOver } from '@jsb188/react/states';
2
- import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
3
- import { useCallback, useRef } from 'react';
4
-
5
- export type GridContextMenuTargetBase = {
6
- cellKey: string;
7
- rowId: string;
8
- };
9
-
10
- type UseGridContextMenuParams<Target extends GridContextMenuTargetBase> = {
11
- contextMenuId: string;
12
- getOptions: (target: Target) => POListIfaceItem[];
13
- };
14
-
15
- /*
16
- * Return the PopOver remount key for one shared grid context menu target.
17
- */
18
-
19
- export function getGridContextMenuPopOverId(contextMenuId: string, target: GridContextMenuTargetBase) {
20
- return `${contextMenuId}:${target.rowId}:${target.cellKey}`;
21
- }
22
-
23
- /*
24
- * Return whether one event target lives inside a mounted PopOver.
25
- */
26
-
27
- function isGridContextMenuPopOverTarget(target: EventTarget | null) {
28
- return target instanceof Element && Boolean(target.closest('.popover'));
29
- }
30
-
31
- /*
32
- * Return whether one grid pointerdown should dismiss the mounted context menu.
33
- */
34
-
35
- export function shouldDismissGridContextMenuOnPointerDown(event: PointerEvent) {
36
- return event.button === 0 && !isGridContextMenuPopOverTarget(event.target);
37
- }
38
-
39
- /*
40
- * Close a mounted grid context menu when one primary pointerdown starts in the grid.
41
- */
42
-
43
- export function dismissGridContextMenuOnPointerDown(event: PointerEvent, closeContextMenu: () => void) {
44
- if (shouldDismissGridContextMenuOnPointerDown(event)) {
45
- closeContextMenu();
46
- }
47
- }
48
-
49
- /*
50
- * Own shared PopOver open, close, and active-target state for grid context menus.
51
- */
52
-
53
- export function useGridContextMenu<Target extends GridContextMenuTargetBase>(params: UseGridContextMenuParams<Target>) {
54
- const { contextMenuId, getOptions } = params;
55
- const { closePopOver, openPopOver, popOver } = usePopOver();
56
- const activeTargetRef = useRef<Target | null>(null);
57
-
58
- /*
59
- * Open a PopOver menu at the user's pointer position.
60
- */
61
-
62
- const openContextMenu = useCallback((event: MouseEvent, target: Target) => {
63
- activeTargetRef.current = target;
64
- openPopOver({
65
- animationClassName: 'anim_dropdown_top_right on_mount spd_0',
66
- doNotFixToBottom: true,
67
- id: getGridContextMenuPopOverId(contextMenuId, target),
68
- name: 'PO_LIST',
69
- offsetX: 0,
70
- offsetY: 4,
71
- position: 'bottom_left',
72
- rect: {
73
- bottom: event.clientY,
74
- height: 0,
75
- left: event.clientX,
76
- right: event.clientX,
77
- top: event.clientY,
78
- width: 0,
79
- x: event.clientX,
80
- y: event.clientY,
81
- },
82
- variables: {
83
- className: 'min_w_180',
84
- options: getOptions(target),
85
- },
86
- zClassName: 'z8',
87
- });
88
- }, [contextMenuId, getOptions, openPopOver]);
89
-
90
- /*
91
- * Close the active context menu when it is currently mounted.
92
- */
93
-
94
- const closeContextMenu = useCallback(() => {
95
- const target = activeTargetRef.current;
96
-
97
- if (!target || popOver?.id !== getGridContextMenuPopOverId(contextMenuId, target)) {
98
- return;
99
- }
100
-
101
- activeTargetRef.current = null;
102
- closePopOver();
103
- }, [closePopOver, contextMenuId, popOver?.id]);
104
-
105
- return {
106
- activeTargetRef,
107
- closeContextMenu,
108
- closePopOver,
109
- openContextMenu,
110
- popOver,
111
- };
112
- }