@atlaskit/editor-plugin-table 1.1.1 → 1.1.2
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 +6 -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 +82 -188
- 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 +12 -42
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +16 -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 +0 -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 +15 -36
- 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 +15 -71
- 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 +12 -45
- 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 +6 -19
- 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 +27 -100
- 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 +7 -15
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +9 -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 +0 -4
- 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 +10 -18
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +29 -59
- 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 +16 -28
- 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 +6 -5
- 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 +82 -181
- 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 +12 -24
- package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +16 -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 +0 -4
- 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 +15 -23
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +15 -60
- 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 +12 -32
- 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 +6 -7
- 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/package.json +2 -2
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
import { unitToNumber } from './unit-to-number';
|
|
1
|
+
import { unitToNumber } from './unit-to-number';
|
|
2
2
|
|
|
3
|
+
// calculates content width of a cell
|
|
3
4
|
export function contentWidth(elem, container) {
|
|
4
5
|
var colWidths = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
5
6
|
var canvas = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : document.createElement('canvas');
|
|
6
7
|
return calcContentWidth(elem, container || elem, canvas, colWidths);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
9
|
function calcContentWidth(elem, container, canvas, colWidths) {
|
|
10
10
|
var flowWidths = [];
|
|
11
11
|
var curWidth = 0;
|
|
12
|
-
|
|
13
12
|
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
14
13
|
var child = elem.childNodes[i];
|
|
15
|
-
|
|
16
14
|
if (child.nodeType === Node.COMMENT_NODE) {
|
|
17
15
|
continue;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
if (child.nodeType === Node.TEXT_NODE) {
|
|
21
18
|
var parent = child.parentNode;
|
|
22
19
|
var parentStyle = getComputedStyle(parent);
|
|
23
20
|
var contentLength = 0;
|
|
24
|
-
|
|
25
21
|
if (parent.nodeName === 'CODE' || parent.nodeName === 'PRE') {
|
|
26
22
|
contentLength = handlePreText(canvas, parent, child.textContent, parentStyle.font);
|
|
27
23
|
} else {
|
|
28
24
|
contentLength = measureText(canvas, child.textContent, parentStyle.font);
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
var left = parent.offsetLeft - container.offsetLeft;
|
|
32
27
|
flowWidths.push(curWidth);
|
|
33
|
-
curWidth += contentLength + left;
|
|
28
|
+
curWidth += contentLength + left;
|
|
34
29
|
|
|
30
|
+
// If the text isn't meant to wrap, we should set that as a hard limit.
|
|
35
31
|
if (parentStyle.whiteSpace === 'nowrap') {
|
|
36
32
|
// + 3 is for date offset plus cursor
|
|
37
33
|
// TODO There should be a programmatic way to get this.
|
|
@@ -40,14 +36,11 @@ function calcContentWidth(elem, container, canvas, colWidths) {
|
|
|
40
36
|
} else {
|
|
41
37
|
// FIXME: doesn't quite work right with spacing
|
|
42
38
|
var style = getComputedStyle(child);
|
|
43
|
-
|
|
44
39
|
if (style.minWidth && style.minWidth.endsWith('px') && style.minWidth !== '0px') {
|
|
45
40
|
colWidths.push(unitToNumber(style.minWidth));
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
var _contentWidth = contentWidth(child, container, colWidths, canvas),
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
width = _contentWidth.width;
|
|
51
44
|
if (style.display && style.display.indexOf('inline') > -1) {
|
|
52
45
|
// is inline element, add to curWidth
|
|
53
46
|
curWidth += width;
|
|
@@ -58,7 +51,6 @@ function calcContentWidth(elem, container, canvas, colWidths) {
|
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
flowWidths.push(curWidth);
|
|
63
55
|
return {
|
|
64
56
|
minWidth: colWidths.reduce(function (oldMax, width) {
|
|
@@ -69,36 +61,27 @@ function calcContentWidth(elem, container, canvas, colWidths) {
|
|
|
69
61
|
}, 0)
|
|
70
62
|
};
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
function measureText(canvas, text, font) {
|
|
74
65
|
var ctx = canvas.getContext('2d');
|
|
75
|
-
|
|
76
66
|
if (!ctx) {
|
|
77
67
|
return 0;
|
|
78
68
|
}
|
|
79
|
-
|
|
80
69
|
if (font) {
|
|
81
70
|
ctx.font = font;
|
|
82
71
|
}
|
|
83
|
-
|
|
84
72
|
return Math.round(ctx.measureText(text || '').width);
|
|
85
73
|
}
|
|
86
|
-
|
|
87
74
|
function handlePreText(canvas, node, textContent, font) {
|
|
88
75
|
var parent = node;
|
|
89
|
-
|
|
90
76
|
if (node.nodeName === 'CODE') {
|
|
91
77
|
parent = node.parentNode;
|
|
92
78
|
}
|
|
93
|
-
|
|
94
79
|
var computedStyle = getComputedStyle(parent);
|
|
95
|
-
|
|
96
80
|
if (textContent && computedStyle.whiteSpace === 'pre') {
|
|
97
81
|
// If white space is pre grab the longest line in the block.
|
|
98
82
|
return textContent.split('\n').reduce(function (acc, current) {
|
|
99
83
|
return Math.max(measureText(canvas, current, font), acc);
|
|
100
84
|
}, 0);
|
|
101
85
|
}
|
|
102
|
-
|
|
103
86
|
return measureText(canvas, textContent, font);
|
|
104
87
|
}
|
|
@@ -8,41 +8,33 @@ import { getPluginState as getMainPluginState } from '../../plugin-factory';
|
|
|
8
8
|
export var updateControls = function updateControls(getEditorFeatureFlags) {
|
|
9
9
|
return function (state) {
|
|
10
10
|
var _getMainPluginState = getMainPluginState(state),
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
tableRef = _getMainPluginState.tableRef;
|
|
13
12
|
if (!tableRef) {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
var tr = tableRef.querySelector('tr');
|
|
18
|
-
|
|
19
16
|
if (!tr) {
|
|
20
17
|
return;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
var wrapper = tableRef.parentElement;
|
|
24
|
-
|
|
25
20
|
if (!(wrapper && wrapper.parentElement)) {
|
|
26
21
|
return;
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
var rowControls = wrapper.parentElement.querySelectorAll(".".concat(ClassName.ROW_CONTROLS_BUTTON_WRAP));
|
|
30
24
|
var numberedRows = wrapper.parentElement.querySelectorAll(ClassName.NUMBERED_COLUMN_BUTTON);
|
|
31
25
|
syncStickyRowToTable(tableRef);
|
|
32
|
-
var rowHeights = getRowHeights(tableRef);
|
|
26
|
+
var rowHeights = getRowHeights(tableRef);
|
|
33
27
|
|
|
28
|
+
// update rows controls height on resize
|
|
34
29
|
for (var i = 0, count = rowControls.length; i < count; i++) {
|
|
35
30
|
var height = rowHeights[i];
|
|
36
|
-
|
|
37
31
|
if (height) {
|
|
38
32
|
rowControls[i].style.height = "".concat(height, "px");
|
|
39
|
-
|
|
40
33
|
if (numberedRows.length) {
|
|
41
34
|
numberedRows[i].style.height = "".concat(height, "px");
|
|
42
35
|
}
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
var rightShadows = wrapper.parentElement.querySelectorAll(".".concat(ClassName.TABLE_RIGHT_SHADOW));
|
|
47
39
|
var leftShadows = wrapper.parentElement.querySelectorAll(".".concat(ClassName.TABLE_LEFT_SHADOW));
|
|
48
40
|
updateOverflowShadows(getEditorFeatureFlags)(state, wrapper, tableRef, rightShadows, leftShadows);
|
|
@@ -50,33 +42,27 @@ export var updateControls = function updateControls(getEditorFeatureFlags) {
|
|
|
50
42
|
};
|
|
51
43
|
export var isClickNear = function isClickNear(event, click) {
|
|
52
44
|
var dx = click.x - event.clientX,
|
|
53
|
-
|
|
45
|
+
dy = click.y - event.clientY;
|
|
54
46
|
return dx * dx + dy * dy < 100;
|
|
55
47
|
};
|
|
56
48
|
export var getResizeCellPos = function getResizeCellPos(view, event, lastColumnResizable) {
|
|
57
49
|
var target = event.target;
|
|
58
|
-
|
|
59
50
|
if (!containsClassName(target, ClassName.RESIZE_HANDLE_DECORATION)) {
|
|
60
51
|
return null;
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
var tableCell = closestElement(target, 'td, th');
|
|
64
|
-
|
|
65
54
|
if (!tableCell) {
|
|
66
55
|
return null;
|
|
67
56
|
}
|
|
68
|
-
|
|
69
57
|
var cellStartPosition = view.posAtDOM(tableCell, 0);
|
|
70
58
|
return cellStartPosition - 1;
|
|
71
59
|
};
|
|
72
60
|
export var updateStickyMargins = function updateStickyMargins(table) {
|
|
73
61
|
var row = table.querySelector('tr.sticky');
|
|
74
|
-
|
|
75
62
|
if (!row) {
|
|
76
63
|
table.style.marginTop = '';
|
|
77
64
|
return;
|
|
78
65
|
}
|
|
79
|
-
|
|
80
66
|
var paddingTop = parsePx(window.getComputedStyle(row).paddingTop || '') || 0;
|
|
81
67
|
var firstRowHeight = row.getBoundingClientRect().height - paddingTop - tableCellBorderWidth;
|
|
82
68
|
table.style.marginTop = "".concat(tableMarginTop + firstRowHeight, "px");
|
|
@@ -84,7 +70,6 @@ export var updateStickyMargins = function updateStickyMargins(table) {
|
|
|
84
70
|
export var applyColWidthsToStickyRow = function applyColWidthsToStickyRow(colGroup, headerRow) {
|
|
85
71
|
// sync column widths for the sticky row
|
|
86
72
|
var newCols = colWidthsForRow(colGroup, headerRow);
|
|
87
|
-
|
|
88
73
|
if (newCols) {
|
|
89
74
|
headerRow.style.gridTemplateColumns = newCols;
|
|
90
75
|
}
|
|
@@ -93,20 +78,16 @@ export var syncStickyRowToTable = function syncStickyRowToTable(tableRef) {
|
|
|
93
78
|
if (!tableRef) {
|
|
94
79
|
return;
|
|
95
80
|
}
|
|
96
|
-
|
|
97
81
|
var headerRow = tableRef.querySelector('tr[data-header-row]');
|
|
98
|
-
|
|
99
82
|
if (!headerRow) {
|
|
100
83
|
return;
|
|
101
84
|
}
|
|
102
|
-
|
|
103
85
|
applyColWidthsToStickyRow(tableRef.querySelector('colgroup'), headerRow);
|
|
104
86
|
applyTableWidthToStickyRow(tableRef, headerRow);
|
|
105
87
|
};
|
|
106
88
|
export var applyTableWidthToStickyRow = function applyTableWidthToStickyRow(tableRef, headerRow) {
|
|
107
89
|
var tbody = tableRef.querySelector('tbody');
|
|
108
90
|
var wrapper = tableRef.parentElement;
|
|
109
|
-
|
|
110
91
|
if (tbody && wrapper) {
|
|
111
92
|
// when resizing in Chrome, clientWidth will give us 759px
|
|
112
93
|
// but toggling the sticky class will reset it to 760px.
|
|
@@ -7,50 +7,45 @@ export var tableLayoutToSize = {
|
|
|
7
7
|
default: akEditorDefaultLayoutWidth,
|
|
8
8
|
wide: akEditorWideLayoutWidth,
|
|
9
9
|
'full-width': akEditorFullWidthLayoutWidth
|
|
10
|
-
};
|
|
10
|
+
};
|
|
11
11
|
|
|
12
|
+
// Translates named layouts in number values.
|
|
12
13
|
export function getLayoutSize(tableLayout) {
|
|
13
14
|
var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
14
15
|
var options = arguments.length > 2 ? arguments[2] : undefined;
|
|
15
16
|
var isFullWidthModeEnabled = options.isFullWidthModeEnabled;
|
|
16
|
-
|
|
17
17
|
if (isFullWidthModeEnabled) {
|
|
18
18
|
return containerWidth ? Math.min(containerWidth - akEditorGutterPadding * 2, akEditorFullWidthLayoutWidth) : akEditorFullWidthLayoutWidth;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
var calculatedTableWidth = calcTableWidth(tableLayout, containerWidth, true);
|
|
22
|
-
|
|
23
21
|
if (calculatedTableWidth.endsWith('px')) {
|
|
24
22
|
return parseInt(calculatedTableWidth, 10);
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
if (tableLayout === 'default') {
|
|
28
25
|
return getDefaultLayoutMaxWidth(containerWidth);
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
return tableLayoutToSize[tableLayout] || containerWidth;
|
|
32
28
|
}
|
|
33
29
|
export function getDefaultLayoutMaxWidth(containerWidth) {
|
|
34
30
|
return mapBreakpointToLayoutMaxWidth(getBreakpoint(containerWidth));
|
|
35
|
-
}
|
|
31
|
+
}
|
|
36
32
|
|
|
33
|
+
// Does the current position point at a cell.
|
|
37
34
|
export function pointsAtCell($pos) {
|
|
38
35
|
return $pos.parent.type.spec.tableRole === 'row' && $pos.nodeAfter;
|
|
39
|
-
}
|
|
36
|
+
}
|
|
40
37
|
|
|
38
|
+
// Get the current col width, handles colspan.
|
|
41
39
|
export function currentColWidth(view, cellPos, _ref) {
|
|
42
40
|
var colspan = _ref.colspan,
|
|
43
|
-
|
|
41
|
+
colwidth = _ref.colwidth;
|
|
44
42
|
var width = colwidth && colwidth[colwidth.length - 1];
|
|
45
|
-
|
|
46
43
|
if (width) {
|
|
47
44
|
return width;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
}
|
|
46
|
+
// Not fixed, read current width from DOM
|
|
51
47
|
var domWidth = view.domAtPos(cellPos + 1).node.offsetWidth;
|
|
52
48
|
var parts = colspan || 0;
|
|
53
|
-
|
|
54
49
|
if (colwidth) {
|
|
55
50
|
for (var i = 0; i < (colspan || 0); i++) {
|
|
56
51
|
if (colwidth[i]) {
|
|
@@ -59,30 +54,27 @@ export function currentColWidth(view, cellPos, _ref) {
|
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
56
|
}
|
|
62
|
-
|
|
63
57
|
return domWidth / parts;
|
|
64
|
-
}
|
|
58
|
+
}
|
|
65
59
|
|
|
60
|
+
// Attempts to find a parent TD/TH depending on target element.
|
|
66
61
|
export function domCellAround(target) {
|
|
67
62
|
while (target && target.nodeName !== 'TD' && target.nodeName !== 'TH') {
|
|
68
63
|
target = containsClassName(target, 'ProseMirror') ? null : target.parentNode;
|
|
69
64
|
}
|
|
70
|
-
|
|
71
65
|
return target;
|
|
72
66
|
}
|
|
73
67
|
export var getTableMaxWidth = function getTableMaxWidth(_ref2) {
|
|
74
68
|
var table = _ref2.table,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
tableStart = _ref2.tableStart,
|
|
70
|
+
state = _ref2.state,
|
|
71
|
+
layout = _ref2.layout,
|
|
72
|
+
getEditorContainerWidth = _ref2.getEditorContainerWidth;
|
|
79
73
|
var containerWidth = getEditorContainerWidth();
|
|
80
74
|
var parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
|
|
81
75
|
var maxWidth = parentWidth || getLayoutSize(layout, containerWidth.width, {});
|
|
82
|
-
|
|
83
76
|
if (table.attrs.isNumberColumnEnabled) {
|
|
84
77
|
maxWidth -= akEditorTableNumberColumnWidth;
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
return maxWidth;
|
|
88
80
|
};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
|
|
5
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
|
|
7
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
-
|
|
9
6
|
import { getFreeSpace } from './column-state';
|
|
10
7
|
import { bulkColumnsResize, getTotalWidth } from './resize-state';
|
|
11
8
|
export var growColumn = function growColumn(state, colIndex, amount, selectedColumns) {
|
|
@@ -13,73 +10,60 @@ export var growColumn = function growColumn(state, colIndex, amount, selectedCol
|
|
|
13
10
|
if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
|
|
14
11
|
return state;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
var res = moveSpaceFrom(state, colIndex + 1, colIndex, amount);
|
|
18
14
|
var remaining = amount - res.amount;
|
|
19
15
|
var newState = res.state;
|
|
20
|
-
|
|
21
16
|
if (remaining > 0) {
|
|
22
17
|
newState = stackSpace(newState, colIndex, remaining).state;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
if (selectedColumns) {
|
|
26
20
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
return newState;
|
|
30
23
|
};
|
|
31
24
|
export var shrinkColumn = function shrinkColumn(state, colIndex, amount, selectedColumns) {
|
|
32
25
|
// can't shrink if columns don't exist
|
|
33
26
|
if (!state.cols[colIndex]) {
|
|
34
27
|
return state;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
}
|
|
29
|
+
// try to shrink dragging column by giving from the column to the right first
|
|
38
30
|
var res = moveSpaceFrom(state, colIndex, colIndex + 1, -amount);
|
|
39
31
|
var newState = res.state;
|
|
40
32
|
var isOverflownTable = getTotalWidth(newState) > newState.maxSize;
|
|
41
|
-
var isLastColumn = !newState.cols[colIndex + 1];
|
|
42
|
-
|
|
33
|
+
var isLastColumn = !newState.cols[colIndex + 1];
|
|
34
|
+
// stop resizing the last column once table is not overflown
|
|
43
35
|
if (isLastColumn && !isOverflownTable) {
|
|
44
36
|
return newState;
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
var remaining = amount + res.amount;
|
|
48
|
-
|
|
49
39
|
if (remaining < 0) {
|
|
50
40
|
newState = stackSpace(newState, colIndex + 1, remaining).state;
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
if (selectedColumns) {
|
|
54
43
|
return bulkColumnsResize(newState, selectedColumns, colIndex);
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
return newState;
|
|
58
46
|
};
|
|
59
47
|
export function reduceSpace(state, amount) {
|
|
60
48
|
var ignoreCols = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
61
|
-
var remaining = amount;
|
|
62
|
-
// or nothing to resize
|
|
49
|
+
var remaining = amount;
|
|
63
50
|
|
|
51
|
+
// keep trying to resolve resize request until we run out of free space,
|
|
52
|
+
// or nothing to resize
|
|
64
53
|
var _loop = function _loop() {
|
|
65
54
|
// filter candidates only with free space
|
|
66
55
|
var candidates = state.cols.filter(function (column) {
|
|
67
56
|
return getFreeSpace(column) && ignoreCols.indexOf(column.index) === -1;
|
|
68
57
|
});
|
|
69
|
-
|
|
70
58
|
if (candidates.length === 0) {
|
|
71
59
|
return "break";
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
var requestedResize = Math.floor(remaining / candidates.length);
|
|
75
|
-
|
|
76
62
|
if (requestedResize === 0) {
|
|
77
63
|
return "break";
|
|
78
64
|
}
|
|
79
|
-
|
|
80
65
|
candidates.forEach(function (candidate) {
|
|
81
66
|
var newWidth = candidate.width - requestedResize;
|
|
82
|
-
|
|
83
67
|
if (newWidth < candidate.minWidth) {
|
|
84
68
|
// If the new requested width is less than our min
|
|
85
69
|
// Calc what width we didn't use, we'll try extract that
|
|
@@ -90,7 +74,6 @@ export function reduceSpace(state, amount) {
|
|
|
90
74
|
} else {
|
|
91
75
|
remaining -= requestedResize;
|
|
92
76
|
}
|
|
93
|
-
|
|
94
77
|
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
95
78
|
cols: [].concat(_toConsumableArray(state.cols.slice(0, candidate.index)), [_objectSpread(_objectSpread({}, candidate), {}, {
|
|
96
79
|
width: newWidth
|
|
@@ -98,59 +81,48 @@ export function reduceSpace(state, amount) {
|
|
|
98
81
|
});
|
|
99
82
|
});
|
|
100
83
|
};
|
|
101
|
-
|
|
102
84
|
while (remaining > 0) {
|
|
103
85
|
var _ret = _loop();
|
|
104
|
-
|
|
105
86
|
if (_ret === "break") break;
|
|
106
87
|
}
|
|
107
|
-
|
|
108
88
|
return state;
|
|
109
89
|
}
|
|
110
90
|
var ColType; // TODO: should handle when destIdx:
|
|
111
91
|
// - is beyond the range, and then not give it back
|
|
112
|
-
|
|
113
92
|
(function (ColType) {
|
|
114
93
|
ColType["SOURCE"] = "src";
|
|
115
94
|
ColType["DEST"] = "dest";
|
|
116
95
|
})(ColType || (ColType = {}));
|
|
117
|
-
|
|
118
96
|
function moveSpaceFrom(state, srcIdx, destIdx, amount) {
|
|
119
97
|
var useFreeSpace = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
120
98
|
var srcCol = state.cols[srcIdx];
|
|
121
99
|
var destCol = state.cols[destIdx];
|
|
122
|
-
|
|
123
100
|
if (useFreeSpace) {
|
|
124
|
-
var freeSpace = getFreeSpace(srcCol);
|
|
125
|
-
|
|
101
|
+
var freeSpace = getFreeSpace(srcCol);
|
|
102
|
+
// if taking more than source column's free space, only take that much
|
|
126
103
|
if (amountFor(ColType.DEST)(amount) > freeSpace) {
|
|
127
104
|
amount = amount > 0 ? freeSpace : -freeSpace;
|
|
128
105
|
}
|
|
129
|
-
}
|
|
130
|
-
|
|
106
|
+
}
|
|
131
107
|
|
|
108
|
+
// if the source column shrinks past its min size, don't give the space away
|
|
132
109
|
if (amountFor(ColType.SOURCE)(amount) < 0 && widthFor(ColType.SOURCE)(amount, srcCol, destCol) < srcCol.minWidth) {
|
|
133
110
|
amount = srcCol.width - srcCol.minWidth;
|
|
134
111
|
}
|
|
135
|
-
|
|
136
112
|
var newDest = destCol ? _objectSpread(_objectSpread({}, destCol), {}, {
|
|
137
113
|
width: widthFor(ColType.DEST)(amount, srcCol, destCol)
|
|
138
114
|
}) : undefined;
|
|
139
|
-
|
|
140
115
|
if (!newDest && amountFor(ColType.SOURCE)(amount) < 0) {
|
|
141
116
|
// non-zero-sum game, ensure that we're not removing more than the total table width either
|
|
142
117
|
var totalWidth = getTotalWidth(state);
|
|
143
|
-
|
|
144
118
|
if (totalWidth - srcCol.width + widthFor(ColType.SOURCE)(amount, srcCol, destCol) < state.maxSize) {
|
|
145
119
|
// would shrink table below max width, stop it
|
|
146
120
|
amount = state.maxSize - (totalWidth - srcCol.width) - srcCol.width - 1;
|
|
147
121
|
}
|
|
148
122
|
}
|
|
149
|
-
|
|
150
123
|
var newSrc = _objectSpread(_objectSpread({}, srcCol), {}, {
|
|
151
124
|
width: widthFor(ColType.SOURCE)(amount, srcCol, destCol)
|
|
152
125
|
});
|
|
153
|
-
|
|
154
126
|
var newCols = state.cols.map(function (existingCol, idx) {
|
|
155
127
|
return idx === srcIdx ? newSrc : idx === destIdx ? newDest : existingCol;
|
|
156
128
|
}).filter(Boolean);
|
|
@@ -161,14 +133,11 @@ function moveSpaceFrom(state, srcIdx, destIdx, amount) {
|
|
|
161
133
|
amount: amount
|
|
162
134
|
};
|
|
163
135
|
}
|
|
164
|
-
|
|
165
136
|
function stackSpace(state, destIdx, amount) {
|
|
166
137
|
var candidates = getCandidates(state, destIdx, amount);
|
|
167
|
-
|
|
168
138
|
var _loop2 = function _loop2() {
|
|
169
139
|
// search for most (or least) free space in candidates
|
|
170
140
|
var candidateIdx = findNextFreeColumn(candidates, amount);
|
|
171
|
-
|
|
172
141
|
if (candidateIdx === -1) {
|
|
173
142
|
// stack to the right -> growing the dragging column and go overflow
|
|
174
143
|
if (amount > 0) {
|
|
@@ -182,21 +151,18 @@ function stackSpace(state, destIdx, amount) {
|
|
|
182
151
|
remaining: amount
|
|
183
152
|
}
|
|
184
153
|
};
|
|
185
|
-
}
|
|
186
|
-
|
|
154
|
+
}
|
|
187
155
|
|
|
156
|
+
// stacking to the left, if no free space remains
|
|
188
157
|
return "break";
|
|
189
158
|
}
|
|
190
|
-
|
|
191
159
|
var column = candidates.find(function (col) {
|
|
192
160
|
return col.index === candidateIdx;
|
|
193
161
|
});
|
|
194
|
-
|
|
195
162
|
if (!column || getFreeSpace(column) <= 0) {
|
|
196
163
|
// no more columns with free space remain
|
|
197
164
|
return "break";
|
|
198
165
|
}
|
|
199
|
-
|
|
200
166
|
var res = moveSpaceFrom(state, column.index, destIdx, amount);
|
|
201
167
|
state = res.state;
|
|
202
168
|
amount -= res.amount;
|
|
@@ -204,59 +170,48 @@ function stackSpace(state, destIdx, amount) {
|
|
|
204
170
|
return col.index !== candidateIdx;
|
|
205
171
|
});
|
|
206
172
|
};
|
|
207
|
-
|
|
208
173
|
while (candidates.length && amount) {
|
|
209
174
|
var _ret2 = _loop2();
|
|
210
|
-
|
|
211
175
|
if (_ret2 === "break") break;
|
|
212
176
|
if (_typeof(_ret2) === "object") return _ret2.v;
|
|
213
177
|
}
|
|
214
|
-
|
|
215
178
|
return {
|
|
216
179
|
state: state,
|
|
217
180
|
remaining: amount
|
|
218
181
|
};
|
|
219
182
|
}
|
|
220
|
-
|
|
221
183
|
function findNextFreeColumn(columns, amount) {
|
|
222
184
|
if (columns.length === 0) {
|
|
223
185
|
return -1;
|
|
224
186
|
}
|
|
225
|
-
|
|
226
187
|
var direction = amount < 0 ? 'left' : 'right';
|
|
227
|
-
|
|
228
188
|
if (direction === 'left') {
|
|
229
189
|
columns = columns.slice().reverse();
|
|
230
190
|
}
|
|
231
|
-
|
|
232
191
|
var freeIndex = -1;
|
|
233
192
|
columns.forEach(function (column) {
|
|
234
193
|
if (getFreeSpace(column) && freeIndex === -1) {
|
|
235
194
|
freeIndex = column.index;
|
|
236
195
|
}
|
|
237
196
|
});
|
|
238
|
-
|
|
239
197
|
if (freeIndex === -1) {
|
|
240
198
|
return -1;
|
|
241
199
|
}
|
|
242
|
-
|
|
243
200
|
return freeIndex;
|
|
244
201
|
}
|
|
245
|
-
|
|
246
202
|
function amountFor(colType) {
|
|
247
203
|
return function (amount) {
|
|
248
204
|
return colType === ColType.SOURCE ? amount > 0 ? -amount : amount : amount < 0 ? -amount : amount;
|
|
249
205
|
};
|
|
250
206
|
}
|
|
251
|
-
|
|
252
207
|
function widthFor(colType) {
|
|
253
208
|
return function (amount, srcCol, destCol) {
|
|
254
209
|
return (colType === ColType.SOURCE ? srcCol : destCol).width + amountFor(colType)(amount);
|
|
255
210
|
};
|
|
256
211
|
}
|
|
257
|
-
|
|
258
212
|
function getCandidates(state, destIdx, amount) {
|
|
259
|
-
var candidates = state.cols;
|
|
213
|
+
var candidates = state.cols;
|
|
260
214
|
|
|
215
|
+
// only consider rows after the selected column in the direction of resize
|
|
261
216
|
return amount < 0 ? candidates.slice(0, destIdx) : candidates.slice(destIdx + 1);
|
|
262
217
|
}
|