@atlaskit/editor-plugin-table 1.1.1 → 1.1.3
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 +18 -0
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/plugins/table/commands/clear.js +4 -16
- package/dist/cjs/plugins/table/commands/collapse.js +0 -6
- package/dist/cjs/plugins/table/commands/go-to-next-cell.js +7 -18
- package/dist/cjs/plugins/table/commands/hover.js +7 -37
- package/dist/cjs/plugins/table/commands/index.js +0 -8
- package/dist/cjs/plugins/table/commands/insert.js +17 -56
- package/dist/cjs/plugins/table/commands/misc.js +36 -132
- package/dist/cjs/plugins/table/commands/referentiality.js +0 -4
- package/dist/cjs/plugins/table/commands/selection.js +21 -87
- package/dist/cjs/plugins/table/commands/sort.js +2 -23
- package/dist/cjs/plugins/table/commands/split-cell.js +3 -11
- package/dist/cjs/plugins/table/commands/toggle.js +8 -34
- package/dist/cjs/plugins/table/commands-with-analytics.js +50 -139
- package/dist/cjs/plugins/table/create-plugin-config.js +0 -6
- package/dist/cjs/plugins/table/event-handlers.js +58 -160
- package/dist/cjs/plugins/table/handlers.js +10 -39
- package/dist/cjs/plugins/table/index.js +47 -91
- package/dist/cjs/plugins/table/nodeviews/OverflowShadowsObserver.js +8 -41
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +95 -191
- package/dist/cjs/plugins/table/nodeviews/table.js +12 -70
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +15 -39
- package/dist/cjs/plugins/table/nodeviews/update-overflow-shadows.js +3 -15
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +0 -18
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -27
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-resizing.js +8 -20
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/compose-decorations.js +1 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/index.js +0 -3
- package/dist/cjs/plugins/table/pm-plugins/keymap.js +2 -15
- package/dist/cjs/plugins/table/pm-plugins/main.js +20 -72
- package/dist/cjs/plugins/table/pm-plugins/plugin-factory.js +25 -42
- package/dist/cjs/plugins/table/pm-plugins/plugin-key.js +0 -2
- package/dist/cjs/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.js +8 -8
- package/dist/cjs/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.js +4 -23
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/commands.js +0 -5
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/index.js +0 -5
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +4 -13
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +56 -138
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin-key.js +0 -2
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin-state.js +15 -30
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin.js +0 -6
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/util.js +0 -5
- package/dist/cjs/plugins/table/pm-plugins/table-local-id.js +13 -44
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/commands.js +18 -43
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +20 -52
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/index.js +0 -4
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/plugin-factory.js +0 -10
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/plugin-key.js +0 -2
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/plugin.js +5 -19
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/reducer.js +0 -10
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +16 -15
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +8 -28
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/content-width.js +3 -23
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/dom.js +4 -46
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/index.js +0 -9
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +51 -40
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-column.js +1 -4
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +17 -73
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +34 -82
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +12 -36
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.js +0 -2
- package/dist/cjs/plugins/table/pm-plugins/table-selection-keymap.js +0 -5
- package/dist/cjs/plugins/table/reducer.js +0 -24
- package/dist/cjs/plugins/table/toolbar.js +14 -94
- package/dist/cjs/plugins/table/transforms/column-width.js +58 -49
- package/dist/cjs/plugins/table/transforms/delete-columns.js +11 -76
- package/dist/cjs/plugins/table/transforms/delete-rows.js +4 -42
- package/dist/cjs/plugins/table/transforms/fix-tables.js +24 -61
- package/dist/cjs/plugins/table/transforms/index.js +0 -7
- package/dist/cjs/plugins/table/transforms/merge.js +14 -90
- package/dist/cjs/plugins/table/transforms/metadata.js +0 -5
- package/dist/cjs/plugins/table/transforms/replace-table.js +2 -13
- package/dist/cjs/plugins/table/transforms/split.js +18 -32
- package/dist/cjs/plugins/table/types.js +0 -11
- package/dist/cjs/plugins/table/ui/FloatingContextualButton/index.js +10 -51
- package/dist/cjs/plugins/table/ui/FloatingContextualButton/styles.js +0 -12
- package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +46 -145
- package/dist/cjs/plugins/table/ui/FloatingContextualMenu/index.js +12 -35
- package/dist/cjs/plugins/table/ui/FloatingContextualMenu/styles.js +0 -11
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/DeleteButton.js +5 -12
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.js +3 -16
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +19 -89
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/InsertButton.js +6 -31
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +5 -22
- package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +25 -80
- package/dist/cjs/plugins/table/ui/LayoutButton/index.js +16 -64
- package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +14 -47
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +20 -48
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +10 -43
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +33 -74
- package/dist/cjs/plugins/table/ui/common-styles.js +10 -22
- package/dist/cjs/plugins/table/ui/consts.js +3 -8
- package/dist/cjs/plugins/table/ui/messages.js +0 -3
- package/dist/cjs/plugins/table/ui/ui-styles.js +0 -32
- package/dist/cjs/plugins/table/utils/analytics.js +4 -19
- package/dist/cjs/plugins/table/utils/collapse.js +4 -21
- package/dist/cjs/plugins/table/utils/column-controls.js +25 -61
- package/dist/cjs/plugins/table/utils/decoration.js +46 -114
- package/dist/cjs/plugins/table/utils/dom.js +4 -51
- package/dist/cjs/plugins/table/utils/get-allow-add-column-custom-step.js +0 -2
- package/dist/cjs/plugins/table/utils/index.js +0 -10
- package/dist/cjs/plugins/table/utils/nodes.js +5 -48
- package/dist/cjs/plugins/table/utils/paste.js +22 -47
- package/dist/cjs/plugins/table/utils/row-controls.js +6 -67
- package/dist/cjs/plugins/table/utils/selection.js +3 -36
- package/dist/cjs/plugins/table/utils/table.js +0 -11
- package/dist/cjs/plugins/table/utils/update-plugin-state-decorations.js +0 -4
- package/dist/cjs/plugins/table-plugin.js +0 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/commands/clear.js +3 -8
- package/dist/es2019/plugins/table/commands/collapse.js +0 -3
- package/dist/es2019/plugins/table/commands/go-to-next-cell.js +4 -7
- package/dist/es2019/plugins/table/commands/hover.js +7 -17
- package/dist/es2019/plugins/table/commands/insert.js +16 -36
- package/dist/es2019/plugins/table/commands/misc.js +37 -67
- package/dist/es2019/plugins/table/commands/selection.js +7 -62
- package/dist/es2019/plugins/table/commands/sort.js +0 -12
- package/dist/es2019/plugins/table/commands/split-cell.js +0 -4
- package/dist/es2019/plugins/table/commands/toggle.js +13 -15
- package/dist/es2019/plugins/table/commands-with-analytics.js +4 -14
- package/dist/es2019/plugins/table/event-handlers.js +14 -62
- package/dist/es2019/plugins/table/handlers.js +16 -26
- package/dist/es2019/plugins/table/index.js +12 -25
- package/dist/es2019/plugins/table/nodeviews/OverflowShadowsObserver.js +8 -40
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +40 -103
- package/dist/es2019/plugins/table/nodeviews/table.js +3 -33
- package/dist/es2019/plugins/table/nodeviews/tableCell.js +7 -16
- package/dist/es2019/plugins/table/nodeviews/update-overflow-shadows.js +3 -10
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +0 -5
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +4 -13
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-resizing.js +0 -3
- package/dist/es2019/plugins/table/pm-plugins/keymap.js +2 -3
- package/dist/es2019/plugins/table/pm-plugins/main.js +19 -43
- package/dist/es2019/plugins/table/pm-plugins/plugin-factory.js +2 -6
- package/dist/es2019/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.js +8 -3
- package/dist/es2019/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.js +0 -12
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +4 -9
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +55 -130
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/plugin-state.js +2 -9
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/util.js +0 -3
- package/dist/es2019/plugins/table/pm-plugins/table-local-id.js +20 -39
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/commands.js +14 -17
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +13 -27
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/plugin-factory.js +2 -4
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/plugin.js +2 -5
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/reducer.js +8 -8
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +14 -3
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +8 -11
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/content-width.js +4 -21
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -22
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +46 -21
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +31 -61
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +54 -51
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +9 -14
- package/dist/es2019/plugins/table/reducer.js +26 -30
- package/dist/es2019/plugins/table/toolbar.js +5 -48
- package/dist/es2019/plugins/table/transforms/column-width.js +60 -32
- package/dist/es2019/plugins/table/transforms/delete-columns.js +17 -58
- package/dist/es2019/plugins/table/transforms/delete-rows.js +8 -25
- package/dist/es2019/plugins/table/transforms/fix-tables.js +25 -42
- package/dist/es2019/plugins/table/transforms/merge.js +22 -70
- package/dist/es2019/plugins/table/transforms/metadata.js +3 -2
- package/dist/es2019/plugins/table/transforms/replace-table.js +0 -2
- package/dist/es2019/plugins/table/transforms/split.js +16 -19
- package/dist/es2019/plugins/table/types.js +2 -4
- package/dist/es2019/plugins/table/ui/FloatingContextualButton/index.js +2 -16
- package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +8 -54
- package/dist/es2019/plugins/table/ui/FloatingContextualMenu/index.js +4 -13
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/DeleteButton.js +0 -2
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.js +2 -11
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +13 -49
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/InsertButton.js +0 -8
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +16 -24
- package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +3 -31
- package/dist/es2019/plugins/table/ui/LayoutButton/index.js +2 -29
- package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +0 -12
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +6 -12
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +0 -9
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -19
- package/dist/es2019/plugins/table/ui/common-styles.js +11 -7
- package/dist/es2019/plugins/table/ui/consts.js +4 -3
- package/dist/es2019/plugins/table/ui/ui-styles.js +0 -10
- package/dist/es2019/plugins/table/utils/analytics.js +0 -8
- package/dist/es2019/plugins/table/utils/collapse.js +3 -14
- package/dist/es2019/plugins/table/utils/column-controls.js +22 -37
- package/dist/es2019/plugins/table/utils/decoration.js +13 -51
- package/dist/es2019/plugins/table/utils/dom.js +3 -19
- package/dist/es2019/plugins/table/utils/nodes.js +2 -15
- package/dist/es2019/plugins/table/utils/paste.js +17 -22
- package/dist/es2019/plugins/table/utils/row-controls.js +12 -45
- package/dist/es2019/plugins/table/utils/selection.js +0 -21
- package/dist/es2019/plugins/table/utils/table.js +0 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/commands/clear.js +3 -8
- package/dist/esm/plugins/table/commands/collapse.js +0 -3
- package/dist/esm/plugins/table/commands/go-to-next-cell.js +6 -9
- package/dist/esm/plugins/table/commands/hover.js +8 -18
- package/dist/esm/plugins/table/commands/insert.js +16 -36
- package/dist/esm/plugins/table/commands/misc.js +39 -78
- package/dist/esm/plugins/table/commands/selection.js +21 -78
- package/dist/esm/plugins/table/commands/sort.js +2 -14
- package/dist/esm/plugins/table/commands/split-cell.js +3 -8
- package/dist/esm/plugins/table/commands/toggle.js +11 -20
- package/dist/esm/plugins/table/commands-with-analytics.js +50 -85
- package/dist/esm/plugins/table/create-plugin-config.js +0 -3
- package/dist/esm/plugins/table/event-handlers.js +58 -123
- package/dist/esm/plugins/table/handlers.js +11 -29
- package/dist/esm/plugins/table/index.js +47 -60
- package/dist/esm/plugins/table/nodeviews/OverflowShadowsObserver.js +8 -44
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +95 -184
- package/dist/esm/plugins/table/nodeviews/table.js +12 -52
- package/dist/esm/plugins/table/nodeviews/tableCell.js +15 -33
- package/dist/esm/plugins/table/nodeviews/update-overflow-shadows.js +3 -10
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +0 -5
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -19
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-resizing.js +8 -13
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/compose-decorations.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/keymap.js +2 -3
- package/dist/esm/plugins/table/pm-plugins/main.js +20 -47
- package/dist/esm/plugins/table/pm-plugins/plugin-factory.js +25 -37
- package/dist/esm/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.js +8 -3
- package/dist/esm/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.js +3 -15
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +4 -9
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +58 -147
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/plugin-state.js +15 -27
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/util.js +0 -3
- package/dist/esm/plugins/table/pm-plugins/table-local-id.js +14 -37
- package/dist/esm/plugins/table/pm-plugins/table-resizing/commands.js +18 -25
- package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +20 -36
- package/dist/esm/plugins/table/pm-plugins/table-resizing/plugin-factory.js +0 -6
- package/dist/esm/plugins/table/pm-plugins/table-resizing/plugin.js +5 -8
- package/dist/esm/plugins/table/pm-plugins/table-resizing/reducer.js +0 -7
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +14 -3
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +8 -12
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/content-width.js +5 -22
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/dom.js +4 -23
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +49 -26
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +17 -62
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +34 -55
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +12 -24
- package/dist/esm/plugins/table/reducer.js +0 -20
- package/dist/esm/plugins/table/toolbar.js +13 -63
- package/dist/esm/plugins/table/transforms/column-width.js +58 -36
- package/dist/esm/plugins/table/transforms/delete-columns.js +11 -62
- package/dist/esm/plugins/table/transforms/delete-rows.js +4 -30
- package/dist/esm/plugins/table/transforms/fix-tables.js +24 -49
- package/dist/esm/plugins/table/transforms/merge.js +16 -75
- package/dist/esm/plugins/table/transforms/metadata.js +3 -2
- package/dist/esm/plugins/table/transforms/replace-table.js +2 -6
- package/dist/esm/plugins/table/transforms/split.js +18 -29
- package/dist/esm/plugins/table/types.js +0 -6
- package/dist/esm/plugins/table/ui/FloatingContextualButton/index.js +10 -31
- package/dist/esm/plugins/table/ui/FloatingContextualButton/styles.js +0 -2
- package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +46 -126
- package/dist/esm/plugins/table/ui/FloatingContextualMenu/index.js +13 -24
- package/dist/esm/plugins/table/ui/FloatingContextualMenu/styles.js +0 -2
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/DeleteButton.js +5 -7
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.js +3 -13
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +19 -68
- package/dist/esm/plugins/table/ui/FloatingInsertButton/InsertButton.js +6 -14
- package/dist/esm/plugins/table/ui/FloatingInsertButton/getPopupOptions.js +5 -18
- package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +25 -57
- package/dist/esm/plugins/table/ui/LayoutButton/index.js +16 -47
- package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +14 -35
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +20 -38
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +10 -29
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +33 -62
- package/dist/esm/plugins/table/ui/common-styles.js +9 -10
- package/dist/esm/plugins/table/ui/consts.js +4 -3
- package/dist/esm/plugins/table/ui/ui-styles.js +0 -12
- package/dist/esm/plugins/table/utils/analytics.js +4 -13
- package/dist/esm/plugins/table/utils/collapse.js +4 -15
- package/dist/esm/plugins/table/utils/column-controls.js +25 -41
- package/dist/esm/plugins/table/utils/decoration.js +46 -88
- package/dist/esm/plugins/table/utils/dom.js +4 -20
- package/dist/esm/plugins/table/utils/nodes.js +5 -18
- package/dist/esm/plugins/table/utils/paste.js +24 -29
- package/dist/esm/plugins/table/utils/row-controls.js +6 -46
- package/dist/esm/plugins/table/utils/selection.js +3 -26
- package/dist/esm/plugins/table/utils/table.js +0 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +7 -0
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +2 -1
- package/dist/types/plugins/table/ui/common-styles.d.ts +1 -0
- package/package.json +8 -6
- package/src/__tests__/integration/__fixtures__/empty-layout.ts +35 -0
- package/src/__tests__/integration/__fixtures__/nested-in-expand.ts +129 -0
- package/src/__tests__/integration/horizontal-scroll.ts +489 -0
- package/src/__tests__/unit/commands/insert.ts +3 -3
- package/src/__tests__/unit/keymap.ts +3 -1
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +38 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +5 -2
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +2 -2
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +2 -2
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +2 -2
- package/src/__tests__/visual-regression/sticky-header.ts +2 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +16 -3
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +6 -2
- package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +9 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/colgroup.ts +19 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +57 -5
- package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +2 -2
- package/src/plugins/table/transforms/column-width.ts +60 -6
- package/src/plugins/table/ui/common-styles.ts +5 -2
|
@@ -4,87 +4,70 @@ import { findTable } from '@atlaskit/editor-tables/utils';
|
|
|
4
4
|
import { AddColumnStep } from '@atlaskit/adf-schema/steps';
|
|
5
5
|
import { setMeta } from './metadata';
|
|
6
6
|
import { splitCellsInColumns } from './split';
|
|
7
|
-
|
|
8
7
|
const deleteColumnsCustomStep = rect => tr => {
|
|
9
8
|
const table = findTable(tr.selection);
|
|
10
|
-
|
|
11
9
|
if (!table) {
|
|
12
10
|
return tr;
|
|
13
|
-
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Need to split all the merge in the ranges (this is the current behaviour)
|
|
14
14
|
// Maybe is better to split only the last column?
|
|
15
15
|
// TODO: After talking with Roto about this behaviour, he likes when we dont split the columns, I am keeping this for consistency of the current implementation.
|
|
16
|
+
splitCellsInColumns(tr, table.pos, rect.left, rect.right);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
splitCellsInColumns(tr, table.pos, rect.left, rect.right); // Delete the columns
|
|
19
|
-
|
|
18
|
+
// Delete the columns
|
|
20
19
|
let mapStart = tr.mapping.maps.length;
|
|
21
20
|
const originalDoc = tr.doc;
|
|
22
21
|
const deletedColumns = [];
|
|
23
|
-
|
|
24
22
|
for (let i = rect.left; i < rect.right; i++) {
|
|
25
23
|
const step = AddColumnStep.create(originalDoc, table.pos, i, true);
|
|
26
24
|
deletedColumns.push(i);
|
|
27
25
|
tr.step(step.map(tr.mapping.slice(mapStart)));
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
const tablePosResult = tr.mapping.mapResult(table.pos);
|
|
31
|
-
|
|
32
28
|
if (tablePosResult.deleted) {
|
|
33
29
|
const pos = Math.min(tablePosResult.pos, tr.doc.nodeSize - 1);
|
|
34
30
|
tr.setSelection(Selection.near(tr.doc.resolve(pos)));
|
|
35
31
|
} else {
|
|
36
32
|
const newTable = tr.doc.nodeAt(tablePosResult.pos);
|
|
37
|
-
|
|
38
33
|
if (newTable) {
|
|
39
34
|
const cursorPos = getNextCursorPos(newTable, deletedColumns);
|
|
40
35
|
tr.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos)));
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
return tr;
|
|
45
39
|
};
|
|
46
|
-
|
|
47
40
|
const deleteColumnsLegacy = rect => tr => {
|
|
48
41
|
const table = findTable(tr.selection);
|
|
49
|
-
|
|
50
42
|
if (!table) {
|
|
51
43
|
return tr;
|
|
52
44
|
}
|
|
53
|
-
|
|
54
45
|
const columnsToDelete = [];
|
|
55
|
-
|
|
56
46
|
for (let i = rect.left; i < rect.right; i++) {
|
|
57
47
|
columnsToDelete.push(i);
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
if (!columnsToDelete.length) {
|
|
61
50
|
return tr;
|
|
62
51
|
}
|
|
63
|
-
|
|
64
52
|
const map = TableMap.get(table.node);
|
|
65
53
|
const rows = [];
|
|
66
54
|
const seen = {};
|
|
67
55
|
const deletedCells = {};
|
|
68
|
-
|
|
69
56
|
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
70
57
|
const rowCells = [];
|
|
71
58
|
const row = table.node.child(rowIndex);
|
|
72
|
-
|
|
73
59
|
for (let colIndex = 0; colIndex < map.width; colIndex++) {
|
|
74
60
|
const cellPos = map.map[rowIndex * map.width + colIndex];
|
|
75
61
|
const cell = table.node.nodeAt(cellPos);
|
|
76
|
-
|
|
77
62
|
if (!cell) {
|
|
78
63
|
continue;
|
|
79
64
|
}
|
|
80
|
-
|
|
81
65
|
const cellsInColumn = map.cellsInRect({
|
|
82
66
|
left: colIndex,
|
|
83
67
|
top: 0,
|
|
84
68
|
right: colIndex + 1,
|
|
85
69
|
bottom: map.height
|
|
86
70
|
});
|
|
87
|
-
|
|
88
71
|
if (columnsToDelete.indexOf(colIndex) === -1) {
|
|
89
72
|
// decrement colspans for col-spanning cells that overlap deleted columns
|
|
90
73
|
if (cellsInColumn.indexOf(cellPos) > -1 && !seen[cellPos]) {
|
|
@@ -94,12 +77,11 @@ const deleteColumnsLegacy = rect => tr => {
|
|
|
94
77
|
overlappingCols += 1;
|
|
95
78
|
}
|
|
96
79
|
});
|
|
97
|
-
|
|
98
80
|
if (overlappingCols > 0) {
|
|
99
|
-
const attrs = {
|
|
81
|
+
const attrs = {
|
|
82
|
+
...cell.attrs,
|
|
100
83
|
colspan: cell.attrs.colspan - overlappingCols
|
|
101
84
|
};
|
|
102
|
-
|
|
103
85
|
if (cell.attrs.colwidth) {
|
|
104
86
|
const minColIndex = Math.min(...columnsToDelete);
|
|
105
87
|
const pos = minColIndex > 0 ? minColIndex - map.colCount(cellPos) : 0;
|
|
@@ -107,7 +89,6 @@ const deleteColumnsLegacy = rect => tr => {
|
|
|
107
89
|
colwidth.splice(pos, overlappingCols);
|
|
108
90
|
attrs.colwidth = colwidth;
|
|
109
91
|
}
|
|
110
|
-
|
|
111
92
|
const newCell = cell.type.createChecked(attrs, cell.content, cell.marks);
|
|
112
93
|
rowCells.push(newCell);
|
|
113
94
|
seen[cellPos] = true;
|
|
@@ -115,22 +96,21 @@ const deleteColumnsLegacy = rect => tr => {
|
|
|
115
96
|
}
|
|
116
97
|
} else if (deletedCells[cellPos]) {
|
|
117
98
|
// if we're removing a col-spanning cell, we need to add missing cells to columns to the right
|
|
118
|
-
const attrs = {
|
|
99
|
+
const attrs = {
|
|
100
|
+
...cell.attrs,
|
|
119
101
|
colspan: 1,
|
|
120
102
|
rowspan: 1
|
|
121
103
|
};
|
|
122
|
-
|
|
123
104
|
if (cell.attrs.colwidth) {
|
|
124
105
|
const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
|
|
125
106
|
attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
|
|
126
107
|
}
|
|
127
|
-
|
|
128
108
|
const newCell = cell.type.createChecked(attrs, cell.type.schema.nodes.paragraph.createChecked(), cell.marks);
|
|
129
109
|
rowCells.push(newCell);
|
|
130
110
|
continue;
|
|
131
|
-
}
|
|
132
|
-
|
|
111
|
+
}
|
|
133
112
|
|
|
113
|
+
// normal cells that we want to keep
|
|
134
114
|
if (!seen[cellPos]) {
|
|
135
115
|
seen[cellPos] = true;
|
|
136
116
|
rowCells.push(cell);
|
|
@@ -139,109 +119,88 @@ const deleteColumnsLegacy = rect => tr => {
|
|
|
139
119
|
deletedCells[cellPos] = true;
|
|
140
120
|
}
|
|
141
121
|
}
|
|
142
|
-
|
|
143
122
|
if (rowCells.length) {
|
|
144
123
|
rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
|
|
145
124
|
}
|
|
146
125
|
}
|
|
147
|
-
|
|
148
126
|
if (!rows.length) {
|
|
149
127
|
return setMeta({
|
|
150
128
|
type: 'DELETE_COLUMNS',
|
|
151
129
|
problem: 'EMPTY_TABLE'
|
|
152
130
|
})(tr);
|
|
153
131
|
}
|
|
154
|
-
|
|
155
132
|
const newTable = table.node.type.createChecked(table.node.attrs, rows, table.node.marks);
|
|
156
133
|
const fixedTable = fixRowSpans(newTable);
|
|
157
|
-
|
|
158
134
|
if (fixedTable === null) {
|
|
159
135
|
return setMeta({
|
|
160
136
|
type: 'DELETE_COLUMNS',
|
|
161
137
|
problem: 'FIX_ROWSPANS'
|
|
162
138
|
})(tr);
|
|
163
139
|
}
|
|
164
|
-
|
|
165
140
|
const cursorPos = getNextCursorPos(newTable, columnsToDelete);
|
|
166
141
|
return setMeta({
|
|
167
142
|
type: 'DELETE_COLUMNS'
|
|
168
|
-
})(tr.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
143
|
+
})(tr.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
144
|
+
// move cursor to the left of the deleted columns if possible, otherwise - to the first column
|
|
169
145
|
.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))));
|
|
170
146
|
};
|
|
171
|
-
|
|
172
147
|
function getNextCursorPos(table, deletedColumns) {
|
|
173
148
|
const minColumn = Math.min(...deletedColumns);
|
|
174
149
|
const nextColumnWithCursor = minColumn > 0 ? minColumn - 1 : 0;
|
|
175
150
|
const map = TableMap.get(table);
|
|
176
151
|
return map.map[nextColumnWithCursor];
|
|
177
|
-
}
|
|
178
|
-
|
|
152
|
+
}
|
|
179
153
|
|
|
154
|
+
// returns an array of numbers, each number indicates the minimum rowSpan in each row
|
|
180
155
|
function getMinRowSpans(table) {
|
|
181
156
|
const minRowSpans = [];
|
|
182
|
-
|
|
183
157
|
for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
|
|
184
158
|
const rowSpans = [];
|
|
185
159
|
const row = table.child(rowIndex);
|
|
186
|
-
|
|
187
160
|
for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
|
|
188
161
|
const cell = row.child(colIndex);
|
|
189
162
|
rowSpans.push(cell.attrs.rowspan);
|
|
190
163
|
}
|
|
191
|
-
|
|
192
164
|
minRowSpans[rowIndex] = Math.min(...rowSpans);
|
|
193
165
|
}
|
|
194
|
-
|
|
195
166
|
return minRowSpans;
|
|
196
167
|
}
|
|
197
|
-
|
|
198
168
|
function fixRowSpans(table) {
|
|
199
169
|
const map = TableMap.get(table);
|
|
200
170
|
const minRowSpans = getMinRowSpans(table);
|
|
201
|
-
|
|
202
171
|
if (!minRowSpans.some(rowspan => rowspan > 1)) {
|
|
203
172
|
return table;
|
|
204
173
|
}
|
|
205
|
-
|
|
206
174
|
const rows = [];
|
|
207
|
-
|
|
208
175
|
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
209
176
|
const row = table.child(rowIndex);
|
|
210
|
-
|
|
211
177
|
if (minRowSpans[rowIndex] === 1) {
|
|
212
178
|
rows.push(row);
|
|
213
179
|
} else {
|
|
214
180
|
const rowCells = [];
|
|
215
|
-
|
|
216
181
|
for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
|
|
217
182
|
const cell = row.child(colIndex);
|
|
218
183
|
const rowspan = cell.attrs.rowspan - minRowSpans[rowIndex] + 1;
|
|
219
|
-
|
|
220
184
|
if (rowspan < 1) {
|
|
221
185
|
return null;
|
|
222
186
|
}
|
|
223
|
-
|
|
224
|
-
|
|
187
|
+
const newCell = cell.type.createChecked({
|
|
188
|
+
...cell.attrs,
|
|
225
189
|
rowspan
|
|
226
190
|
}, cell.content, cell.marks);
|
|
227
191
|
rowCells.push(newCell);
|
|
228
192
|
}
|
|
229
|
-
|
|
230
193
|
rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
|
|
231
194
|
}
|
|
232
195
|
}
|
|
233
|
-
|
|
234
196
|
if (!rows.length) {
|
|
235
197
|
return null;
|
|
236
198
|
}
|
|
237
|
-
|
|
238
199
|
return table.type.createChecked(table.attrs, rows, table.marks);
|
|
239
200
|
}
|
|
240
|
-
|
|
241
201
|
export const deleteColumns = (rect, allowAddColumnCustomStep = false) => tr => {
|
|
242
202
|
if (allowAddColumnCustomStep) {
|
|
243
203
|
return deleteColumnsCustomStep(rect)(tr);
|
|
244
204
|
}
|
|
245
|
-
|
|
246
205
|
return deleteColumnsLegacy(rect)(tr);
|
|
247
206
|
};
|
|
@@ -5,19 +5,15 @@ import { removeEmptyColumns } from './merge';
|
|
|
5
5
|
import { setMeta } from './metadata';
|
|
6
6
|
export const deleteRows = (rect, isHeaderRowRequired = false) => tr => {
|
|
7
7
|
const table = findTable(tr.selection);
|
|
8
|
-
|
|
9
8
|
if (!table) {
|
|
10
9
|
return tr;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const rowsToDelete = [];
|
|
14
12
|
const map = TableMap.get(table.node);
|
|
15
|
-
|
|
16
13
|
for (let i = rect.top; i < rect.bottom; i++) {
|
|
17
14
|
// skip header row if its required
|
|
18
15
|
if (isHeaderRowRequired) {
|
|
19
16
|
const cell = table.node.nodeAt(map.map[i * map.width]);
|
|
20
|
-
|
|
21
17
|
if (cell && cell.type !== cell.type.schema.nodes.tableHeader) {
|
|
22
18
|
rowsToDelete.push(i);
|
|
23
19
|
}
|
|
@@ -25,34 +21,27 @@ export const deleteRows = (rect, isHeaderRowRequired = false) => tr => {
|
|
|
25
21
|
rowsToDelete.push(i);
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
if (!rowsToDelete.length) {
|
|
30
25
|
return tr;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
const rows = [];
|
|
34
28
|
const seen = {};
|
|
35
29
|
const deletedCells = {};
|
|
36
|
-
|
|
37
30
|
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
38
31
|
const rowCells = [];
|
|
39
32
|
const row = table.node.child(rowIndex);
|
|
40
|
-
|
|
41
33
|
for (let colIndex = 0; colIndex < map.width; colIndex++) {
|
|
42
34
|
const cellPos = map.map[rowIndex * map.width + colIndex];
|
|
43
35
|
const cell = table.node.nodeAt(cellPos);
|
|
44
|
-
|
|
45
36
|
if (!cell) {
|
|
46
37
|
continue;
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
const cellsInRow = map.cellsInRect({
|
|
50
40
|
left: 0,
|
|
51
41
|
top: rowIndex,
|
|
52
42
|
right: map.width,
|
|
53
43
|
bottom: rowIndex + 1
|
|
54
44
|
});
|
|
55
|
-
|
|
56
45
|
if (rowsToDelete.indexOf(rowIndex) === -1 && !seen[cellPos]) {
|
|
57
46
|
// decrement rowspans for row-spanning cells that overlap deleted rows
|
|
58
47
|
if (cellsInRow.indexOf(cellPos) > -1) {
|
|
@@ -62,9 +51,9 @@ export const deleteRows = (rect, isHeaderRowRequired = false) => tr => {
|
|
|
62
51
|
overlappingRows += 1;
|
|
63
52
|
}
|
|
64
53
|
});
|
|
65
|
-
|
|
66
54
|
if (overlappingRows > 0) {
|
|
67
|
-
const newCell = cell.type.createChecked({
|
|
55
|
+
const newCell = cell.type.createChecked({
|
|
56
|
+
...cell.attrs,
|
|
68
57
|
rowspan: cell.attrs.rowspan - overlappingRows
|
|
69
58
|
}, cell.content, cell.marks);
|
|
70
59
|
rowCells.push(newCell);
|
|
@@ -73,22 +62,21 @@ export const deleteRows = (rect, isHeaderRowRequired = false) => tr => {
|
|
|
73
62
|
}
|
|
74
63
|
} else if (deletedCells[cellPos]) {
|
|
75
64
|
// if we're removing a row-spanning cell, we need to add missing cells to rows below
|
|
76
|
-
const attrs = {
|
|
65
|
+
const attrs = {
|
|
66
|
+
...cell.attrs,
|
|
77
67
|
colspan: 1,
|
|
78
68
|
rowspan: 1
|
|
79
69
|
};
|
|
80
|
-
|
|
81
70
|
if (cell.attrs.colwidth) {
|
|
82
71
|
const pos = colIndex > 0 ? colIndex - map.colCount(cellPos) : 0;
|
|
83
72
|
attrs.colwidth = cell.attrs.colwidth.slice().splice(pos, 1);
|
|
84
73
|
}
|
|
85
|
-
|
|
86
74
|
const newCell = cell.type.createChecked(attrs, cell.type.schema.nodes.paragraph.createChecked(), cell.marks);
|
|
87
75
|
rowCells.push(newCell);
|
|
88
76
|
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
77
|
+
}
|
|
91
78
|
|
|
79
|
+
// normal cells that we want to keep
|
|
92
80
|
if (!seen[cellPos]) {
|
|
93
81
|
seen[cellPos] = true;
|
|
94
82
|
rowCells.push(cell);
|
|
@@ -97,36 +85,31 @@ export const deleteRows = (rect, isHeaderRowRequired = false) => tr => {
|
|
|
97
85
|
deletedCells[cellPos] = true;
|
|
98
86
|
}
|
|
99
87
|
}
|
|
100
|
-
|
|
101
88
|
if (rowCells.length) {
|
|
102
89
|
rows.push(row.type.createChecked(row.attrs, rowCells, row.marks));
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
|
-
|
|
106
92
|
if (!rows.length) {
|
|
107
93
|
return setMeta({
|
|
108
94
|
type: 'DELETE_ROWS',
|
|
109
95
|
problem: 'EMPTY_TABLE'
|
|
110
96
|
})(tr);
|
|
111
97
|
}
|
|
112
|
-
|
|
113
98
|
const newTable = table.node.type.createChecked(table.node.attrs, rows, table.node.marks);
|
|
114
99
|
const fixedTable = removeEmptyColumns(newTable);
|
|
115
|
-
|
|
116
100
|
if (fixedTable === null) {
|
|
117
101
|
return setMeta({
|
|
118
102
|
type: 'DELETE_ROWS',
|
|
119
103
|
problem: 'REMOVE_EMPTY_COLUMNS'
|
|
120
104
|
})(tr);
|
|
121
105
|
}
|
|
122
|
-
|
|
123
106
|
const cursorPos = getNextCursorPos(newTable, rowsToDelete);
|
|
124
107
|
return setMeta({
|
|
125
108
|
type: 'DELETE_ROWS'
|
|
126
|
-
})(tr.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
109
|
+
})(tr.replaceWith(table.pos, table.pos + table.node.nodeSize, fixedTable)
|
|
110
|
+
// move cursor before the deleted rows if possible, otherwise - to the first row
|
|
127
111
|
.setSelection(Selection.near(tr.doc.resolve(table.pos + cursorPos))));
|
|
128
112
|
};
|
|
129
|
-
|
|
130
113
|
function getNextCursorPos(table, deletedRows) {
|
|
131
114
|
const minRow = Math.min(...deletedRows);
|
|
132
115
|
const nextRowWithCursor = minRow > 0 ? minRow - 1 : 0;
|
|
@@ -12,7 +12,6 @@ export const fireAnalytics = (properties = {}) => sendLogs({
|
|
|
12
12
|
user: '-'
|
|
13
13
|
}]
|
|
14
14
|
});
|
|
15
|
-
|
|
16
15
|
const validateTableCellNodeAttrs = ({
|
|
17
16
|
colspan,
|
|
18
17
|
rowspan,
|
|
@@ -27,7 +26,6 @@ const validateTableCellNodeAttrs = ({
|
|
|
27
26
|
spanValue: colspan
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
if (rowspan && rowspan < 0) {
|
|
32
30
|
reportInvalidTableCellSpanAttrs({
|
|
33
31
|
nodeType: 'tableCell',
|
|
@@ -37,17 +35,16 @@ const validateTableCellNodeAttrs = ({
|
|
|
37
35
|
spanValue: rowspan
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
|
-
|
|
41
38
|
return;
|
|
42
|
-
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// We attempt to patch the document when we have extra, unneeded, column widths
|
|
43
42
|
// Take this node for example:
|
|
44
43
|
//
|
|
45
44
|
// ['td', { colwidth: [100, 100, 100], colspan: 2 }]
|
|
46
45
|
//
|
|
47
46
|
// This row only spans two columns, yet it contains widths for 3.
|
|
48
47
|
// We remove the third width here, assumed duplicate content.
|
|
49
|
-
|
|
50
|
-
|
|
51
48
|
export const removeExtraneousColumnWidths = (node, basePos, tr, reportInvalidTableCellSpanAttrs) => {
|
|
52
49
|
let hasProblems = false;
|
|
53
50
|
tr = replaceCells(tr, node, basePos, cell => {
|
|
@@ -56,7 +53,6 @@ export const removeExtraneousColumnWidths = (node, basePos, tr, reportInvalidTab
|
|
|
56
53
|
colspan,
|
|
57
54
|
rowspan
|
|
58
55
|
} = cell.attrs;
|
|
59
|
-
|
|
60
56
|
if (reportInvalidTableCellSpanAttrs) {
|
|
61
57
|
validateTableCellNodeAttrs({
|
|
62
58
|
colspan,
|
|
@@ -64,24 +60,21 @@ export const removeExtraneousColumnWidths = (node, basePos, tr, reportInvalidTab
|
|
|
64
60
|
tableLocalId: node.attrs.localId
|
|
65
61
|
}, reportInvalidTableCellSpanAttrs);
|
|
66
62
|
}
|
|
67
|
-
|
|
68
63
|
if (colwidth && colwidth.length > colspan) {
|
|
69
64
|
hasProblems = true;
|
|
70
|
-
return cell.type.createChecked({
|
|
65
|
+
return cell.type.createChecked({
|
|
66
|
+
...cell.attrs,
|
|
71
67
|
colwidth: colwidth.slice(0, colspan)
|
|
72
68
|
}, cell.content, cell.marks);
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
return cell;
|
|
76
71
|
});
|
|
77
|
-
|
|
78
72
|
if (hasProblems) {
|
|
79
73
|
fireAnalytics({
|
|
80
74
|
message: 'removeExtraneousColumnWidths'
|
|
81
75
|
});
|
|
82
76
|
return true;
|
|
83
77
|
}
|
|
84
|
-
|
|
85
78
|
return false;
|
|
86
79
|
};
|
|
87
80
|
export const fixTables = (tr, reportInvalidTableCellSpanAttrs) => {
|
|
@@ -92,11 +85,12 @@ export const fixTables = (tr, reportInvalidTableCellSpanAttrs) => {
|
|
|
92
85
|
hasProblems = removeExtraneousColumnWidths(node, tr.mapping.map(pos), tr, reportInvalidTableCellSpanAttrs);
|
|
93
86
|
}
|
|
94
87
|
});
|
|
95
|
-
|
|
96
88
|
if (hasProblems) {
|
|
97
89
|
return tr;
|
|
98
90
|
}
|
|
99
|
-
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// When we get a table with an 'auto' attribute, we want to:
|
|
100
94
|
// 1. render with table-layout: auto
|
|
101
95
|
// 2. capture the column widths
|
|
102
96
|
// 3. set the column widths as attributes, and remove the 'auto' attribute,
|
|
@@ -107,7 +101,6 @@ export const fixTables = (tr, reportInvalidTableCellSpanAttrs) => {
|
|
|
107
101
|
//
|
|
108
102
|
// We use this when migrating TinyMCE tables for Confluence, for example:
|
|
109
103
|
// https://pug.jira-dev.com/wiki/spaces/AEC/pages/3362882215/How+do+we+map+TinyMCE+tables+to+Fabric+tables
|
|
110
|
-
|
|
111
104
|
export const fixAutoSizedTable = (view, tableNode, tableRef, tablePos, opts) => {
|
|
112
105
|
let {
|
|
113
106
|
tr
|
|
@@ -117,30 +110,31 @@ export const fixAutoSizedTable = (view, tableNode, tableRef, tablePos, opts) =>
|
|
|
117
110
|
const colWidths = parseDOMColumnWidths(domAtPos, tableNode, tableStart, tableRef);
|
|
118
111
|
const totalContentWidth = colWidths.reduce((acc, current) => acc + current, 0);
|
|
119
112
|
const tableLayout = getLayoutBasedOnWidth(totalContentWidth);
|
|
120
|
-
const maxLayoutSize = getLayoutSize(tableLayout, opts.containerWidth, {});
|
|
113
|
+
const maxLayoutSize = getLayoutSize(tableLayout, opts.containerWidth, {});
|
|
114
|
+
|
|
115
|
+
// Content width will generally not meet the constraints of the layout
|
|
121
116
|
// whether it be below or above, so we scale our columns widths
|
|
122
117
|
// to meet these requirements
|
|
123
|
-
|
|
124
118
|
let scale = 1;
|
|
125
|
-
|
|
126
119
|
if (totalContentWidth !== maxLayoutSize) {
|
|
127
120
|
scale = maxLayoutSize / totalContentWidth;
|
|
128
121
|
}
|
|
129
|
-
|
|
130
122
|
const scaledColumnWidths = colWidths.map(width => Math.floor(width * scale));
|
|
131
123
|
tr = replaceCells(tr, tableNode, tablePos, (cell, _rowIndex, colIndex) => {
|
|
132
124
|
const newColWidths = scaledColumnWidths.slice(colIndex, colIndex + cell.attrs.colspan);
|
|
133
|
-
return cell.type.createChecked({
|
|
125
|
+
return cell.type.createChecked({
|
|
126
|
+
...cell.attrs,
|
|
134
127
|
colwidth: newColWidths.length ? newColWidths : null
|
|
135
128
|
}, cell.content, cell.marks);
|
|
136
|
-
});
|
|
129
|
+
});
|
|
137
130
|
|
|
138
|
-
|
|
131
|
+
// clear autosizing on the table node
|
|
132
|
+
return tr.setNodeMarkup(tablePos, undefined, {
|
|
133
|
+
...tableNode.attrs,
|
|
139
134
|
layout: tableLayout,
|
|
140
135
|
__autoSize: false
|
|
141
136
|
}).setMeta('addToHistory', false);
|
|
142
137
|
};
|
|
143
|
-
|
|
144
138
|
const getLayoutBasedOnWidth = totalWidth => {
|
|
145
139
|
if (totalWidth > akEditorWideLayoutWidth) {
|
|
146
140
|
return 'full-width';
|
|
@@ -150,20 +144,15 @@ const getLayoutBasedOnWidth = totalWidth => {
|
|
|
150
144
|
return 'default';
|
|
151
145
|
}
|
|
152
146
|
};
|
|
153
|
-
|
|
154
147
|
function parseDOMColumnWidths(domAtPos, tableNode, tableStart, tableRef) {
|
|
155
148
|
const row = tableRef.querySelector('tr');
|
|
156
|
-
|
|
157
149
|
if (!row) {
|
|
158
150
|
return [];
|
|
159
151
|
}
|
|
160
|
-
|
|
161
152
|
let cols = [];
|
|
162
|
-
|
|
163
153
|
for (let col = 0; col < row.childElementCount; col++) {
|
|
164
154
|
const currentCol = row.children[col];
|
|
165
155
|
const colspan = Number(currentCol.getAttribute('colspan') || 1);
|
|
166
|
-
|
|
167
156
|
for (let span = 0; span < colspan; span++) {
|
|
168
157
|
const colIdx = col + span;
|
|
169
158
|
const cells = getCellsRefsInColumn(colIdx, tableNode, tableStart, domAtPos);
|
|
@@ -173,44 +162,38 @@ function parseDOMColumnWidths(domAtPos, tableNode, tableStart, tableRef) {
|
|
|
173
162
|
cols[colIdx] = Math.max(colWidth, tableCellMinWidth);
|
|
174
163
|
}
|
|
175
164
|
}
|
|
176
|
-
|
|
177
165
|
return cols;
|
|
178
|
-
}
|
|
179
|
-
|
|
166
|
+
}
|
|
180
167
|
|
|
168
|
+
// TODO: move to prosemirror-utils
|
|
181
169
|
const replaceCells = (tr, table, tablePos, modifyCell) => {
|
|
182
170
|
const rows = [];
|
|
183
171
|
let modifiedCells = 0;
|
|
184
|
-
|
|
185
172
|
for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
|
|
186
173
|
const row = table.child(rowIndex);
|
|
187
174
|
const cells = [];
|
|
188
|
-
|
|
189
175
|
for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
|
|
190
|
-
const cell = row.child(colIndex);
|
|
176
|
+
const cell = row.child(colIndex);
|
|
177
|
+
|
|
178
|
+
// FIXME
|
|
191
179
|
// The rowIndex and colIndex are not accurate in a merged cell scenario
|
|
192
180
|
// e.g. table with 5 columns might have only one cell in a row, colIndex will be 1, where it should be 4
|
|
193
|
-
|
|
194
181
|
const node = modifyCell(cell, rowIndex, colIndex);
|
|
195
|
-
|
|
196
182
|
if (node.sameMarkup(cell) === false) {
|
|
197
183
|
modifiedCells++;
|
|
198
184
|
}
|
|
199
|
-
|
|
200
185
|
cells.push(node);
|
|
201
186
|
}
|
|
202
|
-
|
|
203
187
|
if (cells.length) {
|
|
204
188
|
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
205
189
|
}
|
|
206
|
-
}
|
|
207
|
-
// If no cells are modified our counter will be zero.
|
|
208
|
-
|
|
190
|
+
}
|
|
209
191
|
|
|
192
|
+
// Check if the table has changed before replacing.
|
|
193
|
+
// If no cells are modified our counter will be zero.
|
|
210
194
|
if (rows.length && modifiedCells !== 0) {
|
|
211
195
|
const newTable = table.type.createChecked(table.attrs, rows, table.marks);
|
|
212
196
|
return tr.replaceWith(tablePos, tablePos + table.nodeSize, newTable);
|
|
213
197
|
}
|
|
214
|
-
|
|
215
198
|
return tr;
|
|
216
199
|
};
|