@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,161 +0,0 @@
1
- import i18n from '@jsb188/app/i18n/index.ts';
2
- import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
3
- import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
4
- import { copyTextToClipboard } from '@jsb188/react-web/utils/dom';
5
- import { useEffect } from 'react';
6
- import { getGridContextMenuPopOverId, useGridContextMenu } from './grid-context-menu.ts';
7
-
8
- const SHEET_CONTEXT_MENU_ID = 'sheet-context-menu';
9
-
10
- const SHEET_CONTEXT_MENU_ACTIONS = {
11
- copyCellValue: 'COPY_CELL_VALUE',
12
- editCell: 'EDIT_CELL',
13
- } as const;
14
-
15
- const SHEET_CONTEXT_MENU_FORMAT_NAMES = {
16
- fillColor: 'fillColor',
17
- textColor: 'textColor',
18
- } as const;
19
-
20
- export type SheetContextMenuAction = typeof SHEET_CONTEXT_MENU_ACTIONS[keyof typeof SHEET_CONTEXT_MENU_ACTIONS];
21
-
22
- export type SheetContextMenuFormatName = typeof SHEET_CONTEXT_MENU_FORMAT_NAMES[keyof typeof SHEET_CONTEXT_MENU_FORMAT_NAMES];
23
-
24
- export type SheetContextMenuFormat = {
25
- name: SheetContextMenuFormatName;
26
- value: string;
27
- };
28
-
29
- export type SheetContextMenuCellTarget = {
30
- cellKey: string;
31
- rowId: string;
32
- };
33
-
34
- export type SheetContextMenuTarget = {
35
- canEdit: boolean;
36
- cells: SheetContextMenuCellTarget[];
37
- cellKey: string;
38
- displayValue: string;
39
- fillColor?: string | null;
40
- rowId: string;
41
- textColor?: string | null;
42
- };
43
-
44
- type UseSheetContextMenuParams = {
45
- onEditCell: (target: SheetContextMenuTarget) => void;
46
- onFormatCells: (target: SheetContextMenuTarget, format: SheetContextMenuFormat) => void;
47
- };
48
-
49
- /*
50
- * Copy one Sheet context-menu target's display value to the clipboard.
51
- */
52
-
53
- function copySheetContextMenuCellValue(target: SheetContextMenuTarget) {
54
- void copyTextToClipboard(target.displayValue || '');
55
- }
56
-
57
- /*
58
- * Build the PopOver list options for one Sheet context-menu target.
59
- */
60
-
61
- function getSheetContextMenuOptions(target: SheetContextMenuTarget): POListIfaceItem[] {
62
- return [{
63
- __type: 'LIST_ITEM',
64
- disabled: !target.canEdit,
65
- iconName: COMMON_ICON_NAMES.edit_note,
66
- text: i18n.t('sheet.edit_cell'),
67
- value: SHEET_CONTEXT_MENU_ACTIONS.editCell,
68
- }, {
69
- __type: 'LIST_SUBMENU_ITEM',
70
- disabled: !target.canEdit,
71
- submenu: {
72
- className: 'min_w_220',
73
- initialState: {
74
- [SHEET_CONTEXT_MENU_FORMAT_NAMES.fillColor]: target.fillColor || null,
75
- [SHEET_CONTEXT_MENU_FORMAT_NAMES.textColor]: target.textColor || null,
76
- },
77
- options: [{
78
- __type: 'LIST_SUBTITLE',
79
- text: i18n.t('sheet.text_color'),
80
- }, {
81
- __type: 'LIST_COLORS',
82
- name: SHEET_CONTEXT_MENU_FORMAT_NAMES.textColor,
83
- selectedValue: target.textColor || null,
84
- }, {
85
- __type: 'LIST_SUBTITLE',
86
- text: i18n.t('sheet.fill_color'),
87
- }, {
88
- __type: 'LIST_COLORS',
89
- name: SHEET_CONTEXT_MENU_FORMAT_NAMES.fillColor,
90
- selectedValue: target.fillColor || null,
91
- }],
92
- },
93
- text: i18n.t('sheet.format_cells'),
94
- value: true,
95
- }, {
96
- __type: 'LIST_ITEM',
97
- iconName: COMMON_ICON_NAMES.copy,
98
- text: i18n.t('sheet.copy_cell_value'),
99
- value: SHEET_CONTEXT_MENU_ACTIONS.copyCellValue,
100
- }];
101
- }
102
-
103
- /*
104
- * Own the Sheet context-menu PopOver actions.
105
- */
106
-
107
- export function useSheetContextMenu(p: UseSheetContextMenuParams) {
108
- const {
109
- onEditCell,
110
- onFormatCells,
111
- } = p;
112
- const {
113
- activeTargetRef,
114
- closeContextMenu: closeSheetContextMenu,
115
- closePopOver,
116
- openContextMenu: openSheetContextMenu,
117
- popOver,
118
- } = useGridContextMenu({
119
- contextMenuId: SHEET_CONTEXT_MENU_ID,
120
- getOptions: getSheetContextMenuOptions,
121
- });
122
-
123
- useEffect(() => {
124
- const { action, id, name, value } = popOver?.globalState || {};
125
- const target = activeTargetRef.current;
126
-
127
- if (!target || id !== getGridContextMenuPopOverId(SHEET_CONTEXT_MENU_ID, target) || action !== 'ITEM') {
128
- return;
129
- }
130
-
131
- if (name === SHEET_CONTEXT_MENU_FORMAT_NAMES.textColor || name === SHEET_CONTEXT_MENU_FORMAT_NAMES.fillColor) {
132
- if (target.canEdit && typeof value === 'string') {
133
- onFormatCells(target, {
134
- name,
135
- value,
136
- });
137
- }
138
- closePopOver();
139
- return;
140
- }
141
-
142
- switch (value as SheetContextMenuAction) {
143
- case SHEET_CONTEXT_MENU_ACTIONS.copyCellValue:
144
- copySheetContextMenuCellValue(target);
145
- closePopOver();
146
- break;
147
- case SHEET_CONTEXT_MENU_ACTIONS.editCell:
148
- if (target.canEdit) {
149
- onEditCell(target);
150
- }
151
- closePopOver();
152
- break;
153
- default:
154
- }
155
- }, [closePopOver, onEditCell, onFormatCells, popOver?.globalState]);
156
-
157
- return {
158
- closeSheetContextMenu,
159
- openSheetContextMenu,
160
- };
161
- }
@@ -1,28 +0,0 @@
1
- import i18n from '@jsb188/app/i18n/index.ts';
2
- import { cn } from '@jsb188/app/utils/string.ts';
3
- import type { SheetGQL } from '@jsb188/mday/types/sheet.d.ts';
4
- import type { SetFloatingMessage } from '@jsb188/react-web/modules/Layout';
5
- import type { ReactNode } from 'react';
6
-
7
- export interface SheetProps {
8
- sheet: SheetGQL;
9
- bufferColumns?: number;
10
- bufferRows?: number;
11
- children?: ReactNode;
12
- className?: string;
13
- disabled?: boolean;
14
- organizationId?: string | null;
15
- setFloatingMessage?: SetFloatingMessage;
16
- }
17
-
18
- /*
19
- * Render the temporary Sheet boundary while the canvas renderer is being built.
20
- */
21
-
22
- export function Sheet(p: SheetProps) {
23
- return <div className={cn('v_stretch h_f w_f rel bg center cl_md ft_sm', p.className)}>
24
- {i18n.t('sheet.work_in_progress')}
25
- </div>;
26
- }
27
-
28
- export default Sheet;
@@ -1,67 +0,0 @@
1
- import { getENVVariable } from '@jsb188/app';
2
- import { getAuthToken } from '@jsb188/app/utils/api.ts';
3
-
4
- type CellSaveBeaconParams = {
5
- cells: any[];
6
- organizationId: string | number | bigint | null;
7
- targetId: string | number | bigint | null;
8
- targetType: 'dataTable' | 'sheet';
9
- };
10
-
11
- /**
12
- * Return the REST server URL by deriving it from the configured GraphQL server URL.
13
- */
14
-
15
- function getCellSaveRESTServer() {
16
- const gqlServer = String(getENVVariable('GQL_SERVER') || '');
17
- return gqlServer.replace(/\/graphql\/?$/, '');
18
- }
19
-
20
- /**
21
- * Return the REST endpoint path for the target cell save resource.
22
- */
23
-
24
- function getCellSaveRESTPath(params: Pick<CellSaveBeaconParams, 'targetId' | 'targetType'>) {
25
- if (params.targetType === 'sheet') {
26
- return `/api/sheets/${params.targetId}/cells`;
27
- }
28
-
29
- return `/api/data-tables/${params.targetId}/cells`;
30
- }
31
-
32
- /**
33
- * Convert bigint values to strings so JSON.stringify can serialize beacon payloads.
34
- */
35
-
36
- function stringifyCellSaveBeaconBody(body: Record<string, any>) {
37
- return JSON.stringify(body, (_key, value) => typeof value === 'bigint' ? String(value) : value);
38
- }
39
-
40
- /**
41
- * Send one batch of pending cell saves with navigator.sendBeacon.
42
- */
43
-
44
- export function sendCellSaveBeacon(params: CellSaveBeaconParams) {
45
- if (
46
- typeof navigator === 'undefined' ||
47
- typeof navigator.sendBeacon !== 'function' ||
48
- !params.organizationId ||
49
- !params.targetId ||
50
- !params.cells.length
51
- ) {
52
- return false;
53
- }
54
-
55
- const body = {
56
- apiKey: getENVVariable('GQL_API_KEY') || '',
57
- authorization: getAuthToken() || '',
58
- organizationId: params.organizationId,
59
- cells: params.cells,
60
- };
61
- const blob = new Blob([stringifyCellSaveBeaconBody(body)], {
62
- type: 'text/plain;charset=UTF-8',
63
- });
64
- const url = getCellSaveRESTServer() + getCellSaveRESTPath(params);
65
-
66
- return navigator.sendBeacon(url, blob);
67
- }
@@ -1,276 +0,0 @@
1
- import type {
2
- SheetUISelectedCellKeyMap,
3
- SheetUIEditState,
4
- SheetUIEditorClickSource,
5
- SheetUIHeaderEditState,
6
- SheetUISelectedCellState,
7
- } from '@jsb188/react-web/ui/SheetUI';
8
- import { getSheetCellKey } from '@jsb188/react-web/ui/SheetUI';
9
-
10
- export type DataTableInteractionLocalEditorState<Lookup = unknown> = {
11
- clickSource: SheetUIEditorClickSource;
12
- displayValue: string;
13
- lookup: Lookup;
14
- };
15
-
16
- export type DataTableInteractionCellSelection = {
17
- activeCell: SheetUISelectedCellState;
18
- anchorCell: SheetUISelectedCellState;
19
- rangeEndCell?: SheetUISelectedCellState;
20
- selectedCellKeyMap: SheetUISelectedCellKeyMap;
21
- };
22
-
23
- export type DataTableInteractionState<Lookup = unknown> =
24
- | {
25
- mode: 'idle';
26
- }
27
- | {
28
- dismissedLocalEditorCell?: SheetUISelectedCellState | null;
29
- mode: 'cellSelected';
30
- selection: DataTableInteractionCellSelection;
31
- }
32
- | {
33
- editState: SheetUIEditState;
34
- mode: 'cellEditing';
35
- }
36
- | {
37
- cellKey: string;
38
- mode: 'headerSelected';
39
- }
40
- | {
41
- headerEditState: SheetUIHeaderEditState;
42
- mode: 'headerEditing';
43
- }
44
- | {
45
- editState: SheetUIEditState;
46
- localEditorState: DataTableInteractionLocalEditorState<Lookup>;
47
- mode: 'localEditorOpen';
48
- };
49
-
50
- export type DataTableInteractionAction<Lookup = unknown> =
51
- | {
52
- type: 'reset';
53
- }
54
- | {
55
- type: 'clear';
56
- }
57
- | {
58
- cell: SheetUISelectedCellState;
59
- type: 'cell_selected';
60
- }
61
- | {
62
- selection: DataTableInteractionCellSelection;
63
- type: 'cell_range_selected';
64
- }
65
- | {
66
- cell: SheetUISelectedCellState;
67
- type: 'local_editor_dismissed_to_cell';
68
- }
69
- | {
70
- editState: SheetUIEditState;
71
- type: 'cell_edit_started';
72
- }
73
- | {
74
- editState: SheetUIEditState;
75
- localEditorState: DataTableInteractionLocalEditorState<Lookup>;
76
- type: 'local_editor_opened';
77
- }
78
- | {
79
- editState?: SheetUIEditState | null;
80
- type: 'cell_editor_dismissed';
81
- }
82
- | {
83
- cellKey: string | null;
84
- type: 'header_selected';
85
- }
86
- | {
87
- headerEditState: SheetUIHeaderEditState;
88
- type: 'header_edit_started';
89
- }
90
- | {
91
- type: 'header_edit_dismissed';
92
- };
93
-
94
- /*
95
- * Build the default no-selection dataTable interaction state.
96
- */
97
-
98
- export function getInitialDataTableInteractionState<Lookup = unknown>(): DataTableInteractionState<Lookup> {
99
- return {
100
- mode: 'idle',
101
- };
102
- }
103
-
104
- /*
105
- * Return the selected-cell state matching one active cell editor.
106
- */
107
-
108
- export function getDataTableSelectedCellStateFromEditState(editState: SheetUIEditState | null | undefined): SheetUISelectedCellState | null {
109
- if (!editState?.rowId || !editState.cellKey) {
110
- return null;
111
- }
112
-
113
- return {
114
- cellKey: editState.cellKey,
115
- rowId: editState.rowId,
116
- };
117
- }
118
-
119
- /*
120
- * Return whether two selected-cell identities point at the same visual cell.
121
- */
122
-
123
- export function areDataTableSelectedCellsEqual(a?: SheetUISelectedCellState | null, b?: SheetUISelectedCellState | null) {
124
- return a?.rowId === b?.rowId && a?.cellKey === b?.cellKey;
125
- }
126
-
127
- /*
128
- * Build a single-cell selection state for one active dataTable cell.
129
- */
130
-
131
- export function getDataTableSingleCellSelection(cell: SheetUISelectedCellState): DataTableInteractionCellSelection {
132
- return {
133
- activeCell: cell,
134
- anchorCell: cell,
135
- rangeEndCell: cell,
136
- selectedCellKeyMap: {
137
- [getSheetCellKey(cell.rowId, cell.cellKey)]: true,
138
- },
139
- };
140
- }
141
-
142
- /*
143
- * Return the cell currently highlighted by the interaction state.
144
- */
145
-
146
- export function getSelectedCellState(state: DataTableInteractionState): SheetUISelectedCellState | null {
147
- return state.mode === 'cellSelected' ? state.selection.activeCell : null;
148
- }
149
-
150
- /*
151
- * Return the active rectangular cell selection from the interaction state.
152
- */
153
-
154
- export function getSelectedCellSelection(state: DataTableInteractionState): DataTableInteractionCellSelection | null {
155
- return state.mode === 'cellSelected' ? state.selection : null;
156
- }
157
-
158
- /*
159
- * Return the inline or dataTable-local active edit state.
160
- */
161
-
162
- export function getActiveEditState(state: DataTableInteractionState): SheetUIEditState | null {
163
- if (state.mode === 'cellEditing' || state.mode === 'localEditorOpen') {
164
- return state.editState;
165
- }
166
-
167
- return null;
168
- }
169
-
170
- /*
171
- * Return the active header edit state.
172
- */
173
-
174
- export function getActiveHeaderEditState(state: DataTableInteractionState): SheetUIHeaderEditState | null {
175
- return state.mode === 'headerEditing' ? state.headerEditState : null;
176
- }
177
-
178
- /*
179
- * Return the currently selected header cell key.
180
- */
181
-
182
- export function getSelectedHeaderCellKey(state: DataTableInteractionState): string | null {
183
- return state.mode === 'headerSelected' ? state.cellKey : null;
184
- }
185
-
186
- /*
187
- * Return the dataTable-local editor state when one is open.
188
- */
189
-
190
- export function getOpenLocalEditorState<Lookup>(state: DataTableInteractionState<Lookup>): DataTableInteractionLocalEditorState<Lookup> | null {
191
- return state.mode === 'localEditorOpen' ? state.localEditorState : null;
192
- }
193
-
194
- /*
195
- * Return the last local-editor cell that was dismissed by clicking the cell again.
196
- */
197
-
198
- export function getDismissedLocalEditorCell(state: DataTableInteractionState): SheetUISelectedCellState | null {
199
- return state.mode === 'cellSelected' ? state.dismissedLocalEditorCell || null : null;
200
- }
201
-
202
- /*
203
- * Own all transient dataTable selection and edit-mode transitions.
204
- */
205
-
206
- export function dataTableInteractionReducer<Lookup>(
207
- state: DataTableInteractionState<Lookup>,
208
- action: DataTableInteractionAction<Lookup>,
209
- ): DataTableInteractionState<Lookup> {
210
- switch (action.type) {
211
- case 'reset':
212
- case 'clear':
213
- case 'header_edit_dismissed':
214
- return getInitialDataTableInteractionState();
215
- case 'cell_selected':
216
- if (
217
- state.mode === 'cellSelected' &&
218
- areDataTableSelectedCellsEqual(state.selection.activeCell, action.cell) &&
219
- Object.keys(state.selection.selectedCellKeyMap).length === 1 &&
220
- !state.dismissedLocalEditorCell
221
- ) {
222
- return state;
223
- }
224
-
225
- return {
226
- mode: 'cellSelected',
227
- selection: getDataTableSingleCellSelection(action.cell),
228
- };
229
- case 'cell_range_selected':
230
- return {
231
- mode: 'cellSelected',
232
- selection: action.selection,
233
- };
234
- case 'local_editor_dismissed_to_cell':
235
- return {
236
- dismissedLocalEditorCell: action.cell,
237
- mode: 'cellSelected',
238
- selection: getDataTableSingleCellSelection(action.cell),
239
- };
240
- case 'cell_edit_started':
241
- return {
242
- editState: action.editState,
243
- mode: 'cellEditing',
244
- };
245
- case 'local_editor_opened':
246
- return {
247
- editState: action.editState,
248
- localEditorState: action.localEditorState,
249
- mode: 'localEditorOpen',
250
- };
251
- case 'cell_editor_dismissed': {
252
- const selectedCell = getDataTableSelectedCellStateFromEditState(action.editState || getActiveEditState(state));
253
-
254
- return selectedCell
255
- ? {
256
- mode: 'cellSelected',
257
- selection: getDataTableSingleCellSelection(selectedCell),
258
- }
259
- : getInitialDataTableInteractionState();
260
- }
261
- case 'header_selected':
262
- return action.cellKey
263
- ? {
264
- cellKey: action.cellKey,
265
- mode: 'headerSelected',
266
- }
267
- : getInitialDataTableInteractionState();
268
- case 'header_edit_started':
269
- return {
270
- headerEditState: action.headerEditState,
271
- mode: 'headerEditing',
272
- };
273
- default:
274
- return state;
275
- }
276
- }