@jsb188/mday-web 1.1.8 → 1.1.10
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/package.json +12 -6
- package/src/modules/DataTable-ContextMenu.tsx +169 -0
- package/src/modules/DataTable-InboundContact.tsx +523 -0
- package/src/modules/DataTable.tsx +5060 -0
- package/src/modules/Sheet-ContextMenu.tsx +161 -0
- package/src/modules/Sheet.tsx +28 -0
- package/src/modules/cell-save-beacon.ts +67 -0
- package/src/modules/dataTable-interaction-state.ts +276 -0
- package/src/modules/dataTable-shortcuts.ts +192 -0
- package/src/modules/dataTable-viewport.ts +89 -0
- package/src/modules/grid-cell-render.ts +72 -0
- package/src/modules/grid-context-menu.ts +112 -0
- package/src/modules/grid-keyboard.ts +267 -0
- package/src/modules/grid-render-store.ts +103 -0
- package/src/modules/grid-runtime.ts +178 -0
- package/src/modules/grid-selection.ts +336 -0
- package/src/modules/grid-viewport.ts +57 -0
- package/src/modules/use-dataTable-states.ts +529 -0
- package/src/modules/use-debounced-cell-save-batch.ts +160 -0
- package/src/types/css.d.ts +1 -0
- package/src/utils/log-web.ts +440 -0
- package/src/utils/org-web.ts +40 -0
- package/src/utils/route-helpers.ts +244 -137
- package/tests/DataTable.test.tsx +4466 -0
- package/tests/dataTable-interaction-state.test.ts +127 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +11 -0
package/package.json
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/mday-web",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Web components and utilities for Marketday app.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
|
-
"./
|
|
9
|
+
"./DataTable": "./src/modules/DataTable.tsx",
|
|
10
|
+
"./Sheet": "./src/modules/Sheet.tsx",
|
|
11
|
+
"./utils/route": "./src/utils/route-helpers.ts",
|
|
12
|
+
"./utils/log-web": "./src/utils/log-web.ts",
|
|
13
|
+
"./utils/org-web": "./src/utils/org-web.ts"
|
|
10
14
|
},
|
|
11
15
|
"dependencies": {},
|
|
12
16
|
"peerDependencies": {
|
|
13
|
-
"@jsb188/app": "1.1.
|
|
14
|
-
"@jsb188/
|
|
15
|
-
"@jsb188/
|
|
17
|
+
"@jsb188/app": "1.1.10",
|
|
18
|
+
"@jsb188/graphql": "1.1.10",
|
|
19
|
+
"@jsb188/mday": "1.1.10",
|
|
20
|
+
"@jsb188/react": "1.1.10",
|
|
21
|
+
"@jsb188/react-web": "1.1.10"
|
|
16
22
|
},
|
|
17
23
|
"scripts": {
|
|
18
|
-
"test": "
|
|
24
|
+
"test": "vitest run --config ./vitest.config.ts"
|
|
19
25
|
}
|
|
20
26
|
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
|
|
3
|
+
import { type OpenModalPopUpFn } from '@jsb188/react/states';
|
|
4
|
+
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
5
|
+
import { copyTextToClipboard } from '@jsb188/react-web/utils/dom';
|
|
6
|
+
import { useEffect } from 'react';
|
|
7
|
+
import { getGridContextMenuPopOverId, useGridContextMenu } from './grid-context-menu.ts';
|
|
8
|
+
|
|
9
|
+
export const SHEET_CONTEXT_MENU_ID = 'dataTable-context-menu';
|
|
10
|
+
export const SHEET_DELETE_ROW_POPUP_PRESET = 'DELETE_SHEET_ROW';
|
|
11
|
+
|
|
12
|
+
export const SHEET_CONTEXT_MENU_ACTIONS = {
|
|
13
|
+
copyCellValue: 'COPY_CELL_VALUE',
|
|
14
|
+
deleteRow: 'DELETE_ROW',
|
|
15
|
+
editCell: 'EDIT_CELL',
|
|
16
|
+
openCell: 'OPEN_CELL',
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
export type DataTableArrowNavigationDirection = 'left' | 'right' | 'up' | 'down';
|
|
20
|
+
export type DataTableContextMenuAction = typeof SHEET_CONTEXT_MENU_ACTIONS[keyof typeof SHEET_CONTEXT_MENU_ACTIONS];
|
|
21
|
+
|
|
22
|
+
export type DataTableContextMenuTarget<Lookup = unknown> = {
|
|
23
|
+
canDeleteRow: boolean;
|
|
24
|
+
canEdit: boolean;
|
|
25
|
+
canOpen: boolean;
|
|
26
|
+
cellKey: string;
|
|
27
|
+
displayValue: string;
|
|
28
|
+
lookup: Lookup;
|
|
29
|
+
organizationId: string;
|
|
30
|
+
rowId: string;
|
|
31
|
+
rowNumber?: number | null;
|
|
32
|
+
dataTableId: string;
|
|
33
|
+
viewId?: string | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type UseDataTableContextMenuParams<Lookup> = {
|
|
37
|
+
openModalPopUp: OpenModalPopUpFn;
|
|
38
|
+
onEditCell: (target: DataTableContextMenuTarget<Lookup>) => void;
|
|
39
|
+
onOpenCell: (target: DataTableContextMenuTarget<Lookup>) => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Copy one dataTable context-menu target's display value to the clipboard.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
function copyDataTableContextMenuCellValue(target: DataTableContextMenuTarget) {
|
|
47
|
+
void copyTextToClipboard(target.displayValue || '');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Build the PopOver list options for one dataTable context-menu target.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
function getDataTableContextMenuOptions(target: DataTableContextMenuTarget): POListIfaceItem[] {
|
|
55
|
+
const options: POListIfaceItem[] = [{
|
|
56
|
+
__type: 'LIST_ITEM',
|
|
57
|
+
disabled: !target.canEdit,
|
|
58
|
+
iconName: COMMON_ICON_NAMES.edit_note,
|
|
59
|
+
text: i18n.t('dataTable.context_menu_edit_cell'),
|
|
60
|
+
value: SHEET_CONTEXT_MENU_ACTIONS.editCell,
|
|
61
|
+
}, {
|
|
62
|
+
__type: 'LIST_ITEM',
|
|
63
|
+
disabled: !target.canOpen,
|
|
64
|
+
iconName: 'external-link',
|
|
65
|
+
text: i18n.t('dataTable.context_menu_open_cell'),
|
|
66
|
+
value: SHEET_CONTEXT_MENU_ACTIONS.openCell,
|
|
67
|
+
}, {
|
|
68
|
+
__type: 'LIST_ITEM',
|
|
69
|
+
iconName: COMMON_ICON_NAMES.copy,
|
|
70
|
+
text: i18n.t('dataTable.context_menu_copy_cell_value'),
|
|
71
|
+
value: SHEET_CONTEXT_MENU_ACTIONS.copyCellValue,
|
|
72
|
+
}];
|
|
73
|
+
|
|
74
|
+
if (target.canDeleteRow) {
|
|
75
|
+
options.push({
|
|
76
|
+
__type: 'BREAK',
|
|
77
|
+
}, {
|
|
78
|
+
__type: 'LIST_ITEM',
|
|
79
|
+
className: 'cl_err',
|
|
80
|
+
iconName: COMMON_ICON_NAMES.delete,
|
|
81
|
+
text: i18n.t('dataTable.delete_row'),
|
|
82
|
+
value: SHEET_CONTEXT_MENU_ACTIONS.deleteRow,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return options;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* Open the delete-row confirmation popup for a menu target.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
function openDataTableDeleteRowPopUp<Lookup>(
|
|
94
|
+
openModalPopUp: OpenModalPopUpFn,
|
|
95
|
+
target: DataTableContextMenuTarget<Lookup>,
|
|
96
|
+
) {
|
|
97
|
+
openModalPopUp({
|
|
98
|
+
name: SHEET_DELETE_ROW_POPUP_PRESET,
|
|
99
|
+
preset: SHEET_DELETE_ROW_POPUP_PRESET,
|
|
100
|
+
props: {
|
|
101
|
+
allowDelete: target.canDeleteRow,
|
|
102
|
+
organizationId: target.organizationId,
|
|
103
|
+
rowNumber: target.rowNumber,
|
|
104
|
+
dataTableId: target.dataTableId,
|
|
105
|
+
dataTableRowId: target.rowId,
|
|
106
|
+
viewId: target.viewId || null,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
* Own the DataTable context-menu PopOver actions.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
export function useDataTableContextMenu<Lookup>(p: UseDataTableContextMenuParams<Lookup>) {
|
|
116
|
+
const {
|
|
117
|
+
onEditCell,
|
|
118
|
+
onOpenCell,
|
|
119
|
+
openModalPopUp,
|
|
120
|
+
} = p;
|
|
121
|
+
const {
|
|
122
|
+
activeTargetRef,
|
|
123
|
+
closeContextMenu: closeDataTableContextMenu,
|
|
124
|
+
closePopOver,
|
|
125
|
+
openContextMenu: openDataTableContextMenu,
|
|
126
|
+
popOver,
|
|
127
|
+
} = useGridContextMenu<DataTableContextMenuTarget<Lookup>>({
|
|
128
|
+
contextMenuId: SHEET_CONTEXT_MENU_ID,
|
|
129
|
+
getOptions: getDataTableContextMenuOptions,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const { action, id, value } = popOver?.globalState || {};
|
|
134
|
+
const target = activeTargetRef.current;
|
|
135
|
+
|
|
136
|
+
if (!target || id !== getGridContextMenuPopOverId(SHEET_CONTEXT_MENU_ID, target) || action !== 'ITEM') {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
switch (value as DataTableContextMenuAction) {
|
|
141
|
+
case SHEET_CONTEXT_MENU_ACTIONS.copyCellValue:
|
|
142
|
+
copyDataTableContextMenuCellValue(target);
|
|
143
|
+
closePopOver();
|
|
144
|
+
break;
|
|
145
|
+
case SHEET_CONTEXT_MENU_ACTIONS.deleteRow:
|
|
146
|
+
openDataTableDeleteRowPopUp(openModalPopUp, target);
|
|
147
|
+
closePopOver();
|
|
148
|
+
break;
|
|
149
|
+
case SHEET_CONTEXT_MENU_ACTIONS.editCell:
|
|
150
|
+
if (target.canEdit) {
|
|
151
|
+
onEditCell(target);
|
|
152
|
+
}
|
|
153
|
+
closePopOver();
|
|
154
|
+
break;
|
|
155
|
+
case SHEET_CONTEXT_MENU_ACTIONS.openCell:
|
|
156
|
+
if (target.canOpen) {
|
|
157
|
+
onOpenCell(target);
|
|
158
|
+
}
|
|
159
|
+
closePopOver();
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
}
|
|
163
|
+
}, [closePopOver, onEditCell, onOpenCell, openModalPopUp, popOver?.globalState]);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
closeDataTableContextMenu,
|
|
167
|
+
openDataTableContextMenu,
|
|
168
|
+
};
|
|
169
|
+
}
|