@atlaskit/editor-plugin-table 0.1.0 → 0.1.1
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/CHANGELOG.md +8 -0
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/esm/version.json +1 -1
- package/examples/99-testing.tsx +35 -30
- package/package.json +2 -11
- package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
- package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
- package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
- package/src/__tests__/integration/resize.ts +1 -2
- package/src/__tests__/unit/analytics.ts +33 -32
- package/src/__tests__/unit/collab.ts +12 -9
- package/src/__tests__/unit/commands/sort.ts +28 -28
- package/src/__tests__/unit/copy-paste.ts +6 -8
- package/src/__tests__/unit/event-handlers.ts +7 -10
- package/src/__tests__/unit/fix-tables.ts +17 -23
- package/src/__tests__/unit/get-toolbar-config.ts +0 -5
- package/src/__tests__/unit/hover-selection.ts +1 -66
- package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
- package/src/__tests__/unit/index.ts +5 -5
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
- package/src/__tests__/unit/nodeviews/cell.ts +12 -10
- package/src/__tests__/unit/nodeviews/table.ts +25 -26
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
- package/src/__tests__/unit/toolbar.ts +18 -5
- package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
- package/src/__tests__/unit/ui/RowControls.tsx +112 -141
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
- package/src/__tests__/unit/undo-redo.ts +10 -9
- package/src/__tests__/unit/utils/nodes.ts +8 -4
- package/src/__tests__/unit/utils/row-controls.ts +8 -4
- package/src/plugins/table/commands/clear.ts +30 -29
- package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
- package/src/plugins/table/commands/insert.ts +91 -91
- package/src/plugins/table/commands/misc.ts +123 -125
- package/src/plugins/table/commands/selection.ts +329 -319
- package/src/plugins/table/commands-with-analytics.ts +299 -294
- package/src/plugins/table/event-handlers.ts +111 -111
- package/src/plugins/table/handlers.ts +95 -94
- package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
- package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
- package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
- package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
- package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
- package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
- package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
- package/src/plugins/table/toolbar.tsx +116 -113
- package/src/plugins/table/transforms/column-width.ts +143 -146
- package/src/plugins/table/transforms/delete-columns.ts +144 -142
- package/src/plugins/table/transforms/delete-rows.ts +110 -111
- package/src/plugins/table/transforms/metadata.ts +9 -9
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
- package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
- package/src/plugins/table/ui/common-styles.ts +1 -3
- package/src/plugins/table/utils/analytics.ts +24 -25
- package/src/plugins/table/utils/dom.ts +3 -3
- package/src/plugins/table/utils/row-controls.ts +92 -93
- package/dist/types-ts4.0/index.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
- package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
- package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
- package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
- package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
- package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
- package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
- package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
- package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
- package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
- package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
|
@@ -179,9 +179,8 @@ export const handleMouseOver = (
|
|
|
179
179
|
}
|
|
180
180
|
const { state, dispatch } = view;
|
|
181
181
|
const target = mouseEvent.target;
|
|
182
|
-
const { insertColumnButtonIndex, insertRowButtonIndex } =
|
|
183
|
-
state
|
|
184
|
-
);
|
|
182
|
+
const { insertColumnButtonIndex, insertRowButtonIndex } =
|
|
183
|
+
getPluginState(state);
|
|
185
184
|
|
|
186
185
|
if (isInsertRowButton(target)) {
|
|
187
186
|
const [startIndex, endIndex] = getColumnOrRowIndex(target);
|
|
@@ -276,9 +275,8 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
|
|
|
276
275
|
}
|
|
277
276
|
|
|
278
277
|
const { state, dispatch } = view;
|
|
279
|
-
const { insertColumnButtonIndex, insertRowButtonIndex } =
|
|
280
|
-
state
|
|
281
|
-
);
|
|
278
|
+
const { insertColumnButtonIndex, insertRowButtonIndex } =
|
|
279
|
+
getPluginState(state);
|
|
282
280
|
|
|
283
281
|
const target = event.target;
|
|
284
282
|
if (isTableControlsButton(target)) {
|
|
@@ -296,99 +294,99 @@ export const handleMouseLeave = (view: EditorView, event: Event): boolean => {
|
|
|
296
294
|
return false;
|
|
297
295
|
};
|
|
298
296
|
|
|
299
|
-
export const handleMouseMove =
|
|
300
|
-
getEditorFeatureFlags: GetEditorFeatureFlags
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
) => {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (isColumnControlsDecorations(element)) {
|
|
313
|
-
const { state, dispatch } = view;
|
|
314
|
-
const { insertColumnButtonIndex } = getPluginState(state);
|
|
315
|
-
const [startIndex, endIndex] = getColumnOrRowIndex(element);
|
|
316
|
-
|
|
317
|
-
const positionColumn =
|
|
318
|
-
getMousePositionHorizontalRelativeByElement(
|
|
319
|
-
event as MouseEvent,
|
|
320
|
-
tableCellOptimization,
|
|
321
|
-
elementContentRects,
|
|
322
|
-
) === 'right'
|
|
323
|
-
? endIndex
|
|
324
|
-
: startIndex;
|
|
297
|
+
export const handleMouseMove =
|
|
298
|
+
(getEditorFeatureFlags: GetEditorFeatureFlags) =>
|
|
299
|
+
(
|
|
300
|
+
view: EditorView,
|
|
301
|
+
event: Event,
|
|
302
|
+
tableCellOptimization?: boolean,
|
|
303
|
+
elementContentRects?: ElementContentRects,
|
|
304
|
+
) => {
|
|
305
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
const element = event.target;
|
|
325
309
|
|
|
326
|
-
if (
|
|
327
|
-
|
|
310
|
+
if (isColumnControlsDecorations(element)) {
|
|
311
|
+
const { state, dispatch } = view;
|
|
312
|
+
const { insertColumnButtonIndex } = getPluginState(state);
|
|
313
|
+
const [startIndex, endIndex] = getColumnOrRowIndex(element);
|
|
314
|
+
|
|
315
|
+
const positionColumn =
|
|
316
|
+
getMousePositionHorizontalRelativeByElement(
|
|
317
|
+
event as MouseEvent,
|
|
318
|
+
tableCellOptimization,
|
|
319
|
+
elementContentRects,
|
|
320
|
+
) === 'right'
|
|
321
|
+
? endIndex
|
|
322
|
+
: startIndex;
|
|
323
|
+
|
|
324
|
+
if (positionColumn !== insertColumnButtonIndex) {
|
|
325
|
+
return showInsertColumnButton(positionColumn)(state, dispatch);
|
|
326
|
+
}
|
|
328
327
|
}
|
|
329
|
-
}
|
|
330
328
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
329
|
+
if (isRowControlsButton(element)) {
|
|
330
|
+
const { state, dispatch } = view;
|
|
331
|
+
const { insertRowButtonIndex } = getPluginState(state);
|
|
332
|
+
const [startIndex, endIndex] = getColumnOrRowIndex(element);
|
|
335
333
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
const positionRow =
|
|
335
|
+
getMousePositionVerticalRelativeByElement(event as MouseEvent) ===
|
|
336
|
+
'bottom'
|
|
337
|
+
? endIndex
|
|
338
|
+
: startIndex;
|
|
341
339
|
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
if (positionRow !== insertRowButtonIndex) {
|
|
341
|
+
return showInsertRowButton(positionRow)(state, dispatch);
|
|
342
|
+
}
|
|
344
343
|
}
|
|
345
|
-
}
|
|
346
344
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (!isResizeHandleDecoration(element) && isCell(element)) {
|
|
354
|
-
const positionColumn = getMousePositionHorizontalRelativeByElement(
|
|
355
|
-
event as MouseEvent,
|
|
356
|
-
useMouseMoveOptimisation,
|
|
357
|
-
elementContentRects,
|
|
358
|
-
RESIZE_HANDLE_AREA_DECORATION_GAP,
|
|
359
|
-
);
|
|
345
|
+
const { mouseMoveOptimization } = getEditorFeatureFlags();
|
|
346
|
+
// we only want to allow mouseMoveOptimisation when tableCellOptimization is enabled
|
|
347
|
+
// because it relies on tableCell node view that is added via tableCellOptimization
|
|
348
|
+
const useMouseMoveOptimisation =
|
|
349
|
+
tableCellOptimization && mouseMoveOptimization;
|
|
360
350
|
|
|
361
|
-
if (
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
) as HTMLTableCellElement;
|
|
368
|
-
const cellStartPosition = view.posAtDOM(tableCell, 0);
|
|
369
|
-
const rect = findCellRectClosestToPos(
|
|
370
|
-
state.doc.resolve(cellStartPosition),
|
|
351
|
+
if (!isResizeHandleDecoration(element) && isCell(element)) {
|
|
352
|
+
const positionColumn = getMousePositionHorizontalRelativeByElement(
|
|
353
|
+
event as MouseEvent,
|
|
354
|
+
useMouseMoveOptimisation,
|
|
355
|
+
elementContentRects,
|
|
356
|
+
RESIZE_HANDLE_AREA_DECORATION_GAP,
|
|
371
357
|
);
|
|
372
358
|
|
|
373
|
-
if (
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
)
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
359
|
+
if (positionColumn !== null) {
|
|
360
|
+
const { state, dispatch } = view;
|
|
361
|
+
const { resizeHandleColumnIndex } = getPluginState(state);
|
|
362
|
+
const tableCell = closestElement(
|
|
363
|
+
element,
|
|
364
|
+
'td, th',
|
|
365
|
+
) as HTMLTableCellElement;
|
|
366
|
+
const cellStartPosition = view.posAtDOM(tableCell, 0);
|
|
367
|
+
const rect = findCellRectClosestToPos(
|
|
368
|
+
state.doc.resolve(cellStartPosition),
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
if (rect) {
|
|
372
|
+
const columnEndIndexTarget =
|
|
373
|
+
positionColumn === 'left' ? rect.left : rect.right;
|
|
374
|
+
|
|
375
|
+
if (
|
|
376
|
+
columnEndIndexTarget !== resizeHandleColumnIndex ||
|
|
377
|
+
!hasResizeHandler({ target: element, columnEndIndexTarget })
|
|
378
|
+
) {
|
|
379
|
+
return addResizeHandleDecorations(columnEndIndexTarget)(
|
|
380
|
+
state,
|
|
381
|
+
dispatch,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
385
384
|
}
|
|
386
385
|
}
|
|
387
386
|
}
|
|
388
|
-
}
|
|
389
387
|
|
|
390
|
-
|
|
391
|
-
};
|
|
388
|
+
return false;
|
|
389
|
+
};
|
|
392
390
|
|
|
393
391
|
export function handleTripleClick(view: EditorView, pos: number) {
|
|
394
392
|
const { state, dispatch } = view;
|
|
@@ -482,31 +480,33 @@ export const handleCut = (
|
|
|
482
480
|
return tr;
|
|
483
481
|
};
|
|
484
482
|
|
|
485
|
-
export const whenTableInFocus =
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
483
|
+
export const whenTableInFocus =
|
|
484
|
+
(
|
|
485
|
+
eventHandler: (
|
|
486
|
+
view: EditorView,
|
|
487
|
+
mouseEvent: Event,
|
|
488
|
+
tableCellOptimization?: boolean,
|
|
489
|
+
elementContentRects?: ElementContentRects,
|
|
490
|
+
) => boolean,
|
|
490
491
|
elementContentRects?: ElementContentRects,
|
|
491
|
-
) =>
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
492
|
+
) =>
|
|
493
|
+
(view: EditorView, mouseEvent: Event): boolean => {
|
|
494
|
+
const tableResizePluginState = getResizePluginState(view.state);
|
|
495
|
+
const tablePluginState = getPluginState(view.state);
|
|
496
|
+
const isDragging =
|
|
497
|
+
tableResizePluginState && !!tableResizePluginState.dragging;
|
|
498
|
+
const hasTableNode = tablePluginState && tablePluginState.tableNode;
|
|
499
|
+
const tableCellOptimization =
|
|
500
|
+
tablePluginState?.pluginConfig?.tableCellOptimization;
|
|
501
|
+
|
|
502
|
+
if (!hasTableNode || isDragging) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
505
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
};
|
|
506
|
+
return eventHandler(
|
|
507
|
+
view,
|
|
508
|
+
mouseEvent,
|
|
509
|
+
tableCellOptimization,
|
|
510
|
+
elementContentRects,
|
|
511
|
+
);
|
|
512
|
+
};
|
|
@@ -47,112 +47,113 @@ type BuilderTablePluginState = (props: {
|
|
|
47
47
|
table?: ContentNodeWithPos;
|
|
48
48
|
}) => (pluginState: TablePluginState) => TablePluginState;
|
|
49
49
|
|
|
50
|
-
const updateTargetCellPosition: BuilderTablePluginState =
|
|
51
|
-
|
|
52
|
-
) => {
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const updateTargetCellPosition: BuilderTablePluginState =
|
|
51
|
+
({ tr, table }) =>
|
|
52
|
+
(pluginState: TablePluginState) => {
|
|
53
|
+
const tableNode = table && table.node;
|
|
54
|
+
if (!tableNode) {
|
|
55
|
+
return {
|
|
56
|
+
...pluginState,
|
|
57
|
+
targetCellPosition: undefined,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { tableCell, tableHeader } = tr.doc.type.schema.nodes;
|
|
62
|
+
const cell = findParentNodeOfType([tableCell, tableHeader])(tr.selection);
|
|
63
|
+
const targetCellPosition = cell ? cell.pos : undefined;
|
|
64
|
+
|
|
65
|
+
if (pluginState.targetCellPosition === targetCellPosition) {
|
|
66
|
+
return pluginState;
|
|
67
|
+
}
|
|
68
|
+
|
|
55
69
|
return {
|
|
56
70
|
...pluginState,
|
|
57
|
-
targetCellPosition
|
|
71
|
+
targetCellPosition,
|
|
58
72
|
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const { tableCell, tableHeader } = tr.doc.type.schema.nodes;
|
|
62
|
-
const cell = findParentNodeOfType([tableCell, tableHeader])(tr.selection);
|
|
63
|
-
const targetCellPosition = cell ? cell.pos : undefined;
|
|
64
|
-
|
|
65
|
-
if (pluginState.targetCellPosition === targetCellPosition) {
|
|
66
|
-
return pluginState;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
...pluginState,
|
|
71
|
-
targetCellPosition,
|
|
72
73
|
};
|
|
73
|
-
};
|
|
74
74
|
|
|
75
|
-
const updateTableNodePluginState: BuilderTablePluginState =
|
|
76
|
-
|
|
77
|
-
) => {
|
|
78
|
-
|
|
75
|
+
const updateTableNodePluginState: BuilderTablePluginState =
|
|
76
|
+
({ tr, table }) =>
|
|
77
|
+
(pluginState) => {
|
|
78
|
+
const tableNode = table && table.node;
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
if (!tableNode || isTextInput(tr)) {
|
|
81
|
+
return pluginState;
|
|
82
|
+
}
|
|
83
83
|
|
|
84
|
-
return {
|
|
85
|
-
...pluginState,
|
|
86
|
-
...defaultTableSelection,
|
|
87
|
-
tableNode,
|
|
88
|
-
ordering: nextTableSorting(tr, table),
|
|
89
|
-
resizeHandleColumnIndex: nextResizeHandleColumnIndex(
|
|
90
|
-
tr,
|
|
91
|
-
pluginState.resizeHandleColumnIndex,
|
|
92
|
-
),
|
|
93
|
-
isNumberColumnEnabled: checkIfNumberColumnEnabled(tr.selection),
|
|
94
|
-
isHeaderColumnEnabled: checkIfHeaderColumnEnabled(tr.selection),
|
|
95
|
-
isHeaderRowEnabled: checkIfHeaderRowEnabled(tr.selection),
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const updateCollapseHandler: BuilderTablePluginState = ({ tr, table }) => (
|
|
100
|
-
pluginState,
|
|
101
|
-
) => {
|
|
102
|
-
const tableNode = table && table.node;
|
|
103
|
-
const schema = tr.doc.type.schema;
|
|
104
|
-
const allowCollapse = pluginState.pluginConfig.allowCollapse;
|
|
105
|
-
const isExpandInSchema = schema.nodes.expand !== undefined;
|
|
106
|
-
const isCollapseEnabled = allowCollapse && isExpandInSchema;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* If we don't have focus, or collapse isn't allowed, or a table node doesn't
|
|
110
|
-
* exist, we don't need to waste extra checks below
|
|
111
|
-
*/
|
|
112
|
-
if (!pluginState.editorHasFocus || !isCollapseEnabled || !tableNode) {
|
|
113
|
-
return pluginState;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const expandNodeType = schema.nodes.expand as NodeType;
|
|
117
|
-
const isTableCollapsed =
|
|
118
|
-
expandNodeType && !!findParentNodeOfType(expandNodeType)(tr.selection);
|
|
119
|
-
|
|
120
|
-
const trCanBeCollapsed = isTableCollapsible(tr).tableIsCollapsible;
|
|
121
|
-
|
|
122
|
-
// We're focused on a table + we're not inside an expand
|
|
123
|
-
const canCollapseTable: boolean =
|
|
124
|
-
!!pluginState.tableNode &&
|
|
125
|
-
// is it already collapsed?
|
|
126
|
-
!isTableCollapsed &&
|
|
127
|
-
!!trCanBeCollapsed;
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
pluginState.isTableCollapsed !== isTableCollapsed ||
|
|
131
|
-
pluginState.canCollapseTable !== canCollapseTable
|
|
132
|
-
) {
|
|
133
84
|
return {
|
|
134
85
|
...pluginState,
|
|
135
|
-
|
|
136
|
-
|
|
86
|
+
...defaultTableSelection,
|
|
87
|
+
tableNode,
|
|
88
|
+
ordering: nextTableSorting(tr, table),
|
|
89
|
+
resizeHandleColumnIndex: nextResizeHandleColumnIndex(
|
|
90
|
+
tr,
|
|
91
|
+
pluginState.resizeHandleColumnIndex,
|
|
92
|
+
),
|
|
93
|
+
isNumberColumnEnabled: checkIfNumberColumnEnabled(tr.selection),
|
|
94
|
+
isHeaderColumnEnabled: checkIfHeaderColumnEnabled(tr.selection),
|
|
95
|
+
isHeaderRowEnabled: checkIfHeaderRowEnabled(tr.selection),
|
|
137
96
|
};
|
|
138
|
-
}
|
|
97
|
+
};
|
|
139
98
|
|
|
140
|
-
|
|
141
|
-
}
|
|
99
|
+
const updateCollapseHandler: BuilderTablePluginState =
|
|
100
|
+
({ tr, table }) =>
|
|
101
|
+
(pluginState) => {
|
|
102
|
+
const tableNode = table && table.node;
|
|
103
|
+
const schema = tr.doc.type.schema;
|
|
104
|
+
const allowCollapse = pluginState.pluginConfig.allowCollapse;
|
|
105
|
+
const isExpandInSchema = schema.nodes.expand !== undefined;
|
|
106
|
+
const isCollapseEnabled = allowCollapse && isExpandInSchema;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* If we don't have focus, or collapse isn't allowed, or a table node doesn't
|
|
110
|
+
* exist, we don't need to waste extra checks below
|
|
111
|
+
*/
|
|
112
|
+
if (!pluginState.editorHasFocus || !isCollapseEnabled || !tableNode) {
|
|
113
|
+
return pluginState;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const expandNodeType = schema.nodes.expand as NodeType;
|
|
117
|
+
const isTableCollapsed =
|
|
118
|
+
expandNodeType && !!findParentNodeOfType(expandNodeType)(tr.selection);
|
|
119
|
+
|
|
120
|
+
const trCanBeCollapsed = isTableCollapsible(tr).tableIsCollapsible;
|
|
121
|
+
|
|
122
|
+
// We're focused on a table + we're not inside an expand
|
|
123
|
+
const canCollapseTable: boolean =
|
|
124
|
+
!!pluginState.tableNode &&
|
|
125
|
+
// is it already collapsed?
|
|
126
|
+
!isTableCollapsed &&
|
|
127
|
+
!!trCanBeCollapsed;
|
|
128
|
+
|
|
129
|
+
if (
|
|
130
|
+
pluginState.isTableCollapsed !== isTableCollapsed ||
|
|
131
|
+
pluginState.canCollapseTable !== canCollapseTable
|
|
132
|
+
) {
|
|
133
|
+
return {
|
|
134
|
+
...pluginState,
|
|
135
|
+
isTableCollapsed,
|
|
136
|
+
canCollapseTable,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
return pluginState;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const buildPluginState =
|
|
144
|
+
(builders: Array<BuilderTablePluginState>): BuilderTablePluginState =>
|
|
145
|
+
(props) =>
|
|
146
|
+
(pluginState) => {
|
|
147
|
+
if (!props.table) {
|
|
148
|
+
return pluginState.targetCellPosition
|
|
149
|
+
? { ...pluginState, targetCellPosition: undefined }
|
|
150
|
+
: pluginState;
|
|
151
|
+
}
|
|
152
|
+
return builders.reduce(
|
|
153
|
+
(_pluginState, transform) => transform(props)(_pluginState),
|
|
154
|
+
pluginState,
|
|
155
|
+
);
|
|
156
|
+
};
|
|
156
157
|
|
|
157
158
|
export const handleDocOrSelectionChanged = (
|
|
158
159
|
tr: Transaction | ReadonlyTransaction,
|
|
@@ -170,9 +170,10 @@ export class OverflowShadowsObserver {
|
|
|
170
170
|
}px`;
|
|
171
171
|
// Use getElementsByClassName here for a live node list to capture
|
|
172
172
|
// sticky shadows
|
|
173
|
-
const liveRightShadows =
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
const liveRightShadows =
|
|
174
|
+
this.wrapper?.parentElement?.getElementsByClassName(
|
|
175
|
+
`${ClassName.TABLE_RIGHT_SHADOW}`,
|
|
176
|
+
);
|
|
176
177
|
const liveLeftShadows = this.wrapper?.parentElement?.getElementsByClassName(
|
|
177
178
|
`${ClassName.TABLE_LEFT_SHADOW}`,
|
|
178
179
|
);
|
|
@@ -198,9 +198,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
198
198
|
componentDidUpdate(prevProps: ComponentProps) {
|
|
199
199
|
const { getNode, isMediaFullscreen, allowColumnResizing } = this.props;
|
|
200
200
|
|
|
201
|
-
const {
|
|
202
|
-
|
|
203
|
-
} = this.props.getEditorFeatureFlags();
|
|
201
|
+
const { tableOverflowShadowsOptimization } =
|
|
202
|
+
this.props.getEditorFeatureFlags();
|
|
204
203
|
|
|
205
204
|
if (!tableOverflowShadowsOptimization) {
|
|
206
205
|
this.updateShadows();
|
|
@@ -281,9 +280,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
281
280
|
};
|
|
282
281
|
|
|
283
282
|
onStickyState = (state: StickyPluginState) => {
|
|
284
|
-
const {
|
|
285
|
-
|
|
286
|
-
} = this.props.getEditorFeatureFlags();
|
|
283
|
+
const { tableOverflowShadowsOptimization } =
|
|
284
|
+
this.props.getEditorFeatureFlags();
|
|
287
285
|
|
|
288
286
|
const pos = this.props.getPos();
|
|
289
287
|
if (!isValidPosition(pos, this.props.view.state)) {
|
|
@@ -507,9 +505,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
507
505
|
}
|
|
508
506
|
}
|
|
509
507
|
|
|
510
|
-
const {
|
|
511
|
-
|
|
512
|
-
} = this.props.getEditorFeatureFlags();
|
|
508
|
+
const { tableOverflowShadowsOptimization } =
|
|
509
|
+
this.props.getEditorFeatureFlags();
|
|
513
510
|
|
|
514
511
|
if (!tableOverflowShadowsOptimization) {
|
|
515
512
|
this.updateShadows();
|
|
@@ -22,51 +22,51 @@ export const updateShadowListForStickyStyles = (
|
|
|
22
22
|
* Update overflow shadows for a given wrapper & table.
|
|
23
23
|
* if `overflowShadowOptimization` is enabled, this will exit early.
|
|
24
24
|
*/
|
|
25
|
-
export const updateOverflowShadows =
|
|
26
|
-
getEditorFeatureFlags: GetEditorFeatureFlags
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
export const updateOverflowShadows =
|
|
26
|
+
(getEditorFeatureFlags: GetEditorFeatureFlags) =>
|
|
27
|
+
(
|
|
28
|
+
editorState: EditorState,
|
|
29
|
+
wrapper?: HTMLElement | null,
|
|
30
|
+
table?: HTMLElement | null,
|
|
31
|
+
rightShadows?: NodeListOf<HTMLElement> | null,
|
|
32
|
+
leftShadows?: NodeListOf<HTMLElement> | null,
|
|
33
|
+
) => {
|
|
34
|
+
if (getEditorFeatureFlags()?.tableOverflowShadowsOptimization === true) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// Right shadow
|
|
38
|
+
if (table && wrapper) {
|
|
39
|
+
const stickyRow = wrapper.querySelector('tr.sticky');
|
|
40
|
+
const stickyCell = stickyRow && stickyRow.firstElementChild;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (rightShadows) {
|
|
43
|
+
const diff = table.offsetWidth - wrapper.offsetWidth;
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
for (let i = 0; i < rightShadows.length; i++) {
|
|
46
|
+
const rightShadow = rightShadows[i];
|
|
47
|
+
rightShadow.style.display =
|
|
48
|
+
diff > 0 && diff > wrapper.scrollLeft ? 'block' : 'none';
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if (
|
|
51
|
+
rightShadow.classList.contains(ClassName.TABLE_STICKY_SHADOW) &&
|
|
52
|
+
stickyCell
|
|
53
|
+
) {
|
|
54
|
+
rightShadow.style.height = `${stickyCell.clientHeight + 1}px`;
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
leftShadow.style.display = wrapper.scrollLeft > 0 ? 'block' : 'none';
|
|
58
|
+
if (leftShadows) {
|
|
59
|
+
for (let i = 0; i < leftShadows.length; i++) {
|
|
60
|
+
const leftShadow = leftShadows[i];
|
|
61
|
+
leftShadow.style.display = wrapper.scrollLeft > 0 ? 'block' : 'none';
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
if (
|
|
64
|
+
leftShadow.classList.contains(ClassName.TABLE_STICKY_SHADOW) &&
|
|
65
|
+
stickyCell
|
|
66
|
+
) {
|
|
67
|
+
leftShadow.style.height = `${stickyCell.clientHeight + 1}px`;
|
|
68
|
+
}
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
72
|
+
};
|
|
@@ -65,16 +65,14 @@ const removeColumnControlsSelectedDecoration: DecorationTransformer = ({
|
|
|
65
65
|
const hasColumnSelectedDecorations = (decorationSet: DecorationSet): boolean =>
|
|
66
66
|
!!findColumnControlSelectedDecoration(decorationSet).length;
|
|
67
67
|
|
|
68
|
-
export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer =
|
|
69
|
-
decorationSet,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return decorationSet;
|
|
74
|
-
}
|
|
68
|
+
export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer =
|
|
69
|
+
({ decorationSet, tr }): DecorationSet => {
|
|
70
|
+
if (!hasColumnSelectedDecorations(decorationSet)) {
|
|
71
|
+
return decorationSet;
|
|
72
|
+
}
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
};
|
|
74
|
+
return removeColumnControlsSelectedDecoration({ decorationSet, tr });
|
|
75
|
+
};
|
|
78
76
|
|
|
79
77
|
export const buildColumnControlsDecorations: DecorationTransformer = ({
|
|
80
78
|
decorationSet,
|