@atlaskit/editor-plugin-table 10.8.0 → 10.8.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 +22 -0
- package/dist/cjs/nodeviews/TableRow.js +68 -28
- package/dist/cjs/nodeviews/table.js +1 -1
- package/dist/cjs/nodeviews/toDOM.js +4 -2
- package/dist/cjs/pm-plugins/table-size-selector.js +40 -0
- package/dist/cjs/tablePlugin.js +63 -32
- package/dist/cjs/ui/SizeSelector/index.js +65 -0
- package/dist/es2019/nodeviews/TableRow.js +65 -24
- package/dist/es2019/nodeviews/table.js +1 -1
- package/dist/es2019/nodeviews/toDOM.js +4 -2
- package/dist/es2019/pm-plugins/table-size-selector.js +31 -0
- package/dist/es2019/tablePlugin.js +33 -3
- package/dist/es2019/ui/SizeSelector/index.js +61 -0
- package/dist/esm/nodeviews/TableRow.js +68 -28
- package/dist/esm/nodeviews/table.js +1 -1
- package/dist/esm/nodeviews/toDOM.js +4 -2
- package/dist/esm/pm-plugins/table-size-selector.js +33 -0
- package/dist/esm/tablePlugin.js +63 -32
- package/dist/esm/ui/SizeSelector/index.js +58 -0
- package/dist/types/nodeviews/TableRow.d.ts +1 -0
- package/dist/types/pm-plugins/table-size-selector.d.ts +10 -0
- package/dist/types/ui/SizeSelector/index.d.ts +9 -0
- package/dist/types-ts4.5/nodeviews/TableRow.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-size-selector.d.ts +10 -0
- package/dist/types-ts4.5/ui/SizeSelector/index.d.ts +9 -0
- package/package.json +10 -4
- package/src/nodeviews/TableRow.ts +72 -30
- package/src/nodeviews/table.tsx +1 -1
- package/src/nodeviews/toDOM.ts +2 -0
- package/src/pm-plugins/table-size-selector.ts +39 -0
- package/src/tablePlugin.tsx +49 -0
- package/src/ui/SizeSelector/index.tsx +74 -0
|
@@ -52,7 +52,8 @@ export const tableNodeSpecWithFixedToDOM = config => {
|
|
|
52
52
|
}]];
|
|
53
53
|
if (!config.tableResizingEnabled) {
|
|
54
54
|
return ['div', {
|
|
55
|
-
class: 'tableView-content-wrap'
|
|
55
|
+
class: 'tableView-content-wrap',
|
|
56
|
+
'data-prosemirror-initial-toDOM-render': 'true'
|
|
56
57
|
}, tableContainerDiv];
|
|
57
58
|
}
|
|
58
59
|
const tableWidthAttribute = node.attrs.width ? `${node.attrs.width}px` : `100%`;
|
|
@@ -79,7 +80,8 @@ export const tableNodeSpecWithFixedToDOM = config => {
|
|
|
79
80
|
class: 'resizer-hover-zone'
|
|
80
81
|
}, tableContainerDiv]]]];
|
|
81
82
|
return ['div', {
|
|
82
|
-
class: 'tableView-content-wrap'
|
|
83
|
+
class: 'tableView-content-wrap',
|
|
84
|
+
'data-prosemirror-initial-toDOM-render': 'true'
|
|
83
85
|
}, tableResizingDiv];
|
|
84
86
|
}
|
|
85
87
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export const pluginKey = new PluginKey('tableSizeSelectorPlugin');
|
|
4
|
+
export const createPlugin = dispatch => {
|
|
5
|
+
return new SafePlugin({
|
|
6
|
+
key: pluginKey,
|
|
7
|
+
state: {
|
|
8
|
+
init: () => ({
|
|
9
|
+
isSelectorOpen: false
|
|
10
|
+
}),
|
|
11
|
+
apply: (tr, currentPluginState) => {
|
|
12
|
+
const meta = tr.getMeta(pluginKey);
|
|
13
|
+
if (meta) {
|
|
14
|
+
const keys = Object.keys(meta);
|
|
15
|
+
const changed = keys.some(key => {
|
|
16
|
+
return currentPluginState[key] !== meta[key];
|
|
17
|
+
});
|
|
18
|
+
if (changed) {
|
|
19
|
+
const newState = {
|
|
20
|
+
...currentPluginState,
|
|
21
|
+
...meta
|
|
22
|
+
};
|
|
23
|
+
dispatch(pluginKey, newState);
|
|
24
|
+
return newState;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return currentPluginState;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -3,6 +3,7 @@ import { tableCell, tableCellWithNestedTable, tableHeader, tableHeaderWithNested
|
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { browser } from '@atlaskit/editor-common/browser';
|
|
5
5
|
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
6
|
+
import { getDomRefFromSelection } from '@atlaskit/editor-common/get-dom-ref-from-selection';
|
|
6
7
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
7
8
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
8
9
|
import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
@@ -39,6 +40,7 @@ import { createPlugin as createFlexiResizingPlugin } from './pm-plugins/table-re
|
|
|
39
40
|
import { getPluginState as getFlexiResizingPlugin } from './pm-plugins/table-resizing/plugin-factory';
|
|
40
41
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing/plugin-key';
|
|
41
42
|
import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
|
|
43
|
+
import { createPlugin as createSizeSelectorPlugin, pluginKey as sizeSelectorPluginKey } from './pm-plugins/table-size-selector';
|
|
42
44
|
import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
43
45
|
import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
|
|
44
46
|
import { createTableWithWidth } from './pm-plugins/utils/create';
|
|
@@ -52,6 +54,7 @@ import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
|
52
54
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
53
55
|
import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
|
|
54
56
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
57
|
+
import { SizeSelector } from './ui/SizeSelector';
|
|
55
58
|
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
56
59
|
import { getToolbarConfig } from './ui/toolbar';
|
|
57
60
|
const defaultGetEditorFeatureFlags = () => ({});
|
|
@@ -64,7 +67,7 @@ const tablePlugin = ({
|
|
|
64
67
|
config: options,
|
|
65
68
|
api
|
|
66
69
|
}) => {
|
|
67
|
-
var _api$analytics, _api$accessibilityUti, _options$getEditorFea, _api$analytics2;
|
|
70
|
+
var _api$analytics, _api$accessibilityUti, _options$getEditorFea, _options$getEditorFea2, _api$analytics2;
|
|
68
71
|
const editorViewRef = {
|
|
69
72
|
current: null
|
|
70
73
|
};
|
|
@@ -79,6 +82,9 @@ const tablePlugin = ({
|
|
|
79
82
|
const isTableFixedColumnWidthsOptionEnabled = (options === null || options === void 0 ? void 0 : (_options$getEditorFea = options.getEditorFeatureFlags) === null || _options$getEditorFea === void 0 ? void 0 : _options$getEditorFea.call(options).tableWithFixedColumnWidthsOption) || false;
|
|
80
83
|
const shouldUseIncreasedScalingPercent = (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && (isTableFixedColumnWidthsOptionEnabled || ( // When in comment editor, we need the scaling percent to be 40% while tableWithFixedColumnWidthsOption is not visible
|
|
81
84
|
options === null || options === void 0 ? void 0 : options.isCommentEditor));
|
|
85
|
+
const isTableSelectorEnabled =
|
|
86
|
+
// eslint-disable-next-line @atlaskit/platform/no-preconditioning
|
|
87
|
+
!(options !== null && options !== void 0 && options.isChromelessEditor) && !(options !== null && options !== void 0 && options.isCommentEditor) && (options === null || options === void 0 ? void 0 : (_options$getEditorFea2 = options.getEditorFeatureFlags) === null || _options$getEditorFea2 === void 0 ? void 0 : _options$getEditorFea2.call(options).tableSelector) && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_table_picker');
|
|
82
88
|
return {
|
|
83
89
|
name: 'table',
|
|
84
90
|
// Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
|
|
@@ -383,6 +389,11 @@ const tablePlugin = ({
|
|
|
383
389
|
}
|
|
384
390
|
});
|
|
385
391
|
}
|
|
392
|
+
}, {
|
|
393
|
+
name: 'tableSizeSelectorPlugin',
|
|
394
|
+
plugin: ({
|
|
395
|
+
dispatch
|
|
396
|
+
}) => isTableSelectorEnabled ? createSizeSelectorPlugin(dispatch) : undefined
|
|
386
397
|
}];
|
|
387
398
|
|
|
388
399
|
// Workaround for table element breaking issue caused by composition event with an inputType of deleteCompositionText.
|
|
@@ -420,21 +431,25 @@ const tablePlugin = ({
|
|
|
420
431
|
tableWidthPluginState: tableWidthPluginKey,
|
|
421
432
|
tableResizingPluginState: tableResizingPluginKey,
|
|
422
433
|
stickyHeadersState: stickyHeadersPluginKey,
|
|
423
|
-
dragAndDropState: dragAndDropPluginKey
|
|
434
|
+
dragAndDropState: dragAndDropPluginKey,
|
|
435
|
+
sizeSelectorPluginState: sizeSelectorPluginKey
|
|
424
436
|
},
|
|
425
437
|
render: ({
|
|
426
438
|
tableResizingPluginState: resizingPluginState,
|
|
427
439
|
stickyHeadersState,
|
|
428
440
|
tablePluginState,
|
|
429
441
|
tableWidthPluginState,
|
|
430
|
-
dragAndDropState
|
|
442
|
+
dragAndDropState,
|
|
443
|
+
sizeSelectorPluginState
|
|
431
444
|
}) => {
|
|
445
|
+
var _sizeSelectorPluginSt, _api$analytics3;
|
|
432
446
|
const isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
433
447
|
const isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
434
448
|
const resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
435
449
|
const resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
436
450
|
const isResizing = isColumnResizing || isTableResizing;
|
|
437
451
|
const widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
452
|
+
const isSizeSelectorOpen = sizeSelectorPluginState === null || sizeSelectorPluginState === void 0 ? void 0 : sizeSelectorPluginState.isSelectorOpen;
|
|
438
453
|
const {
|
|
439
454
|
tableNode,
|
|
440
455
|
tablePos,
|
|
@@ -543,6 +558,13 @@ const tablePlugin = ({
|
|
|
543
558
|
forcePlacement: true,
|
|
544
559
|
zIndex: akEditorFloatingPanelZIndex,
|
|
545
560
|
offset: [0, 10]
|
|
561
|
+
}), isTableSelectorEnabled && isSizeSelectorOpen && /*#__PURE__*/React.createElement(SizeSelector, {
|
|
562
|
+
api: api,
|
|
563
|
+
isOpenedByKeyboard: false,
|
|
564
|
+
popupsMountPoint: popupsMountPoint,
|
|
565
|
+
target: (_sizeSelectorPluginSt = sizeSelectorPluginState === null || sizeSelectorPluginState === void 0 ? void 0 : sizeSelectorPluginState.targetRef) !== null && _sizeSelectorPluginSt !== void 0 ? _sizeSelectorPluginSt : getDomRefFromSelection(editorView, ACTION_SUBJECT_ID.PICKER_TABLE_SIZE, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent),
|
|
566
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
567
|
+
popupsScrollableElement: popupsScrollableElement
|
|
546
568
|
}));
|
|
547
569
|
}
|
|
548
570
|
}));
|
|
@@ -560,6 +582,14 @@ const tablePlugin = ({
|
|
|
560
582
|
icon: () => /*#__PURE__*/React.createElement(IconTable, null),
|
|
561
583
|
action(insert, state) {
|
|
562
584
|
var _api$table, _options$tableOptions6;
|
|
585
|
+
if (isTableSelectorEnabled) {
|
|
586
|
+
const tr = insert('');
|
|
587
|
+
tr.setMeta(sizeSelectorPluginKey, {
|
|
588
|
+
isSelectorOpen: true
|
|
589
|
+
});
|
|
590
|
+
return tr;
|
|
591
|
+
}
|
|
592
|
+
|
|
563
593
|
// see comment on tablesPlugin.getSharedState on usage
|
|
564
594
|
const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
565
595
|
const tableNodeProps = {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
|
|
8
|
+
import { jsx } from '@emotion/react';
|
|
9
|
+
import { TableSelectorPopup } from '@atlaskit/editor-common/ui';
|
|
10
|
+
import { pluginKey } from '../../pm-plugins/table-size-selector';
|
|
11
|
+
const DEFAULT_TABLE_SELECTOR_COLS = 3;
|
|
12
|
+
const DEFAULT_TABLE_SELECTOR_ROWS = 3;
|
|
13
|
+
export const SizeSelector = ({
|
|
14
|
+
api,
|
|
15
|
+
target,
|
|
16
|
+
popupsMountPoint,
|
|
17
|
+
popupsBoundariesElement,
|
|
18
|
+
popupsScrollableElement
|
|
19
|
+
}) => {
|
|
20
|
+
const closeSelectorPopup = useCallback(() => {
|
|
21
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
22
|
+
tr
|
|
23
|
+
}) => {
|
|
24
|
+
tr.setMeta(pluginKey, {
|
|
25
|
+
isSelectorOpen: false
|
|
26
|
+
});
|
|
27
|
+
return tr;
|
|
28
|
+
});
|
|
29
|
+
}, [api]);
|
|
30
|
+
const onSelection = useCallback((rowsCount, colsCount) => {
|
|
31
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
32
|
+
tr
|
|
33
|
+
}) => {
|
|
34
|
+
api === null || api === void 0 ? void 0 : api.table.commands.insertTableWithSize(rowsCount, colsCount)({
|
|
35
|
+
tr
|
|
36
|
+
});
|
|
37
|
+
tr.setMeta(pluginKey, {
|
|
38
|
+
isSelectorOpen: false
|
|
39
|
+
});
|
|
40
|
+
return tr;
|
|
41
|
+
});
|
|
42
|
+
}, [api]);
|
|
43
|
+
const onUnmount = () => {
|
|
44
|
+
api === null || api === void 0 ? void 0 : api.core.actions.focus();
|
|
45
|
+
};
|
|
46
|
+
return jsx(TableSelectorPopup, {
|
|
47
|
+
defaultSize: {
|
|
48
|
+
row: DEFAULT_TABLE_SELECTOR_ROWS,
|
|
49
|
+
col: DEFAULT_TABLE_SELECTOR_COLS
|
|
50
|
+
},
|
|
51
|
+
target: target,
|
|
52
|
+
onUnmount: onUnmount,
|
|
53
|
+
onSelection: onSelection,
|
|
54
|
+
popupsMountPoint: popupsMountPoint,
|
|
55
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
56
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
57
|
+
isOpenedByKeyboard: true,
|
|
58
|
+
handleClickOutside: closeSelectorPopup,
|
|
59
|
+
handleEscapeKeydown: closeSelectorPopup
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -24,7 +24,7 @@ import TableNodeView from './TableNodeViewBase';
|
|
|
24
24
|
// limit scroll event calls
|
|
25
25
|
var HEADER_ROW_SCROLL_THROTTLE_TIMEOUT = 200;
|
|
26
26
|
|
|
27
|
-
// timeout for resetting the scroll class - if it
|
|
27
|
+
// timeout for resetting the scroll class - if it's too long then users won't be able to click on the header cells,
|
|
28
28
|
// if too short it would trigger too many dom updates.
|
|
29
29
|
var HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT = 400;
|
|
30
30
|
var TableRow = /*#__PURE__*/function (_TableNodeView) {
|
|
@@ -137,6 +137,9 @@ var TableRow = /*#__PURE__*/function (_TableNodeView) {
|
|
|
137
137
|
}
|
|
138
138
|
this.emitOff(true);
|
|
139
139
|
}
|
|
140
|
+
if (this.tableContainerObserver) {
|
|
141
|
+
this.tableContainerObserver.disconnect();
|
|
142
|
+
}
|
|
140
143
|
}
|
|
141
144
|
}, {
|
|
142
145
|
key: "ignoreMutation",
|
|
@@ -245,26 +248,29 @@ var TableRow = /*#__PURE__*/function (_TableNodeView) {
|
|
|
245
248
|
this.resizeObserver.observe(this.editorScrollableElement);
|
|
246
249
|
}
|
|
247
250
|
window.requestAnimationFrame(function () {
|
|
248
|
-
var
|
|
251
|
+
var getTableContainer = function getTableContainer() {
|
|
252
|
+
var _getTree;
|
|
253
|
+
return (_getTree = getTree(_this2.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(TableCssClassName.NODEVIEW_WRAPPER));
|
|
254
|
+
};
|
|
255
|
+
|
|
249
256
|
// we expect tree to be defined after animation frame
|
|
250
|
-
var tableContainer = (
|
|
257
|
+
var tableContainer = getTableContainer();
|
|
251
258
|
if (tableContainer) {
|
|
252
259
|
var getSentinelTop = function getSentinelTop() {
|
|
253
|
-
return
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
);
|
|
260
|
+
return tableContainer &&
|
|
261
|
+
// Ignored via go/ees005
|
|
262
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
263
|
+
tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_TOP).item(0);
|
|
258
264
|
};
|
|
259
265
|
var getSentinelBottom = function getSentinelBottom() {
|
|
260
266
|
// Multiple bottom sentinels may be found if there are nested tables.
|
|
261
267
|
// We need to make sure we get the last one which will belong to the parent table.
|
|
262
|
-
var bottomSentinels = tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_BOTTOM);
|
|
268
|
+
var bottomSentinels = tableContainer && tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_BOTTOM);
|
|
263
269
|
// Ignored via go/ees005
|
|
264
270
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
265
271
|
return fg('platform_editor_nested_tables_bottom_sentinel') ?
|
|
266
272
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
267
|
-
bottomSentinels.item(bottomSentinels.length - 1) :
|
|
273
|
+
bottomSentinels && bottomSentinels.item(bottomSentinels.length - 1) : tableContainer &&
|
|
268
274
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
269
275
|
tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_BOTTOM).item(0);
|
|
270
276
|
};
|
|
@@ -284,26 +290,60 @@ var TableRow = /*#__PURE__*/function (_TableNodeView) {
|
|
|
284
290
|
}
|
|
285
291
|
});
|
|
286
292
|
};
|
|
287
|
-
if (
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
293
|
+
if (fg('platform_editor_table_initial_load_fix')) {
|
|
294
|
+
var isInitialProsemirrorToDomRender = tableContainer.hasAttribute('data-prosemirror-initial-toDOM-render');
|
|
295
|
+
|
|
296
|
+
// Sentinels may be in the DOM but they're part of the prosemirror placeholder structure which is replaced with the fully rendered React node.
|
|
297
|
+
if (sentinelsInDom() && !isInitialProsemirrorToDomRender) {
|
|
298
|
+
// great - DOM ready, observe as normal
|
|
299
|
+
observeStickySentinels();
|
|
300
|
+
} else {
|
|
301
|
+
// concurrent loading issue - here TableRow is too eager trying to
|
|
302
|
+
// observe sentinels before they are in the DOM, use MutationObserver
|
|
303
|
+
// to wait for sentinels to be added to the parent Table node DOM
|
|
304
|
+
// then attach the IntersectionObserver
|
|
305
|
+
_this2.tableContainerObserver = new MutationObserver(function () {
|
|
306
|
+
// Check if the tableContainer is still connected to the DOM. It can become disconnected when the placholder
|
|
307
|
+
// prosemirror node is replaced with the fully rendered React node (see _handleTableRef).
|
|
308
|
+
if (!tableContainer || !tableContainer.isConnected) {
|
|
309
|
+
tableContainer = getTableContainer();
|
|
310
|
+
}
|
|
311
|
+
if (sentinelsInDom()) {
|
|
312
|
+
var _this2$tableContainer;
|
|
313
|
+
observeStickySentinels();
|
|
314
|
+
(_this2$tableContainer = _this2.tableContainerObserver) === null || _this2$tableContainer === void 0 || _this2$tableContainer.disconnect();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
var mutatingNode = tableContainer;
|
|
318
|
+
if (mutatingNode && _this2.tableContainerObserver) {
|
|
319
|
+
_this2.tableContainerObserver.observe(mutatingNode, {
|
|
320
|
+
subtree: true,
|
|
321
|
+
childList: true
|
|
322
|
+
});
|
|
299
323
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
if (sentinelsInDom()) {
|
|
327
|
+
// great - DOM ready, observe as normal
|
|
328
|
+
observeStickySentinels();
|
|
329
|
+
} else {
|
|
330
|
+
// concurrent loading issue - here TableRow is too eager trying to
|
|
331
|
+
// observe sentinels before they are in the DOM, use MutationObserver
|
|
332
|
+
// to wait for sentinels to be added to the parent Table node DOM
|
|
333
|
+
// then attach the IntersectionObserver
|
|
334
|
+
var tableContainerObserver = new MutationObserver(function () {
|
|
335
|
+
if (sentinelsInDom()) {
|
|
336
|
+
observeStickySentinels();
|
|
337
|
+
tableContainerObserver.disconnect();
|
|
338
|
+
}
|
|
306
339
|
});
|
|
340
|
+
var _mutatingNode = tableContainer;
|
|
341
|
+
if (_mutatingNode) {
|
|
342
|
+
tableContainerObserver.observe(_mutatingNode, {
|
|
343
|
+
subtree: true,
|
|
344
|
+
childList: true
|
|
345
|
+
});
|
|
346
|
+
}
|
|
307
347
|
}
|
|
308
348
|
}
|
|
309
349
|
}
|
|
@@ -61,7 +61,7 @@ var handleInlineTableWidth = function handleInlineTableWidth(table, width) {
|
|
|
61
61
|
table.style.setProperty('width', "".concat(width, "px"));
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
//
|
|
64
|
+
// Remove after removing the platform_editor_table_initial_load_fix flag.
|
|
65
65
|
var toDOM = function toDOM(node, props) {
|
|
66
66
|
var colgroup = '';
|
|
67
67
|
if (props.allowColumnResizing) {
|
|
@@ -61,7 +61,8 @@ export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(co
|
|
|
61
61
|
}]];
|
|
62
62
|
if (!config.tableResizingEnabled) {
|
|
63
63
|
return ['div', {
|
|
64
|
-
class: 'tableView-content-wrap'
|
|
64
|
+
class: 'tableView-content-wrap',
|
|
65
|
+
'data-prosemirror-initial-toDOM-render': 'true'
|
|
65
66
|
}, tableContainerDiv];
|
|
66
67
|
}
|
|
67
68
|
var tableWidthAttribute = node.attrs.width ? "".concat(node.attrs.width, "px") : "100%";
|
|
@@ -88,7 +89,8 @@ export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(co
|
|
|
88
89
|
class: 'resizer-hover-zone'
|
|
89
90
|
}, tableContainerDiv]]]];
|
|
90
91
|
return ['div', {
|
|
91
|
-
class: 'tableView-content-wrap'
|
|
92
|
+
class: 'tableView-content-wrap',
|
|
93
|
+
'data-prosemirror-initial-toDOM-render': 'true'
|
|
92
94
|
}, tableResizingDiv];
|
|
93
95
|
}
|
|
94
96
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
export var pluginKey = new PluginKey('tableSizeSelectorPlugin');
|
|
7
|
+
export var createPlugin = function createPlugin(dispatch) {
|
|
8
|
+
return new SafePlugin({
|
|
9
|
+
key: pluginKey,
|
|
10
|
+
state: {
|
|
11
|
+
init: function init() {
|
|
12
|
+
return {
|
|
13
|
+
isSelectorOpen: false
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
apply: function apply(tr, currentPluginState) {
|
|
17
|
+
var meta = tr.getMeta(pluginKey);
|
|
18
|
+
if (meta) {
|
|
19
|
+
var keys = Object.keys(meta);
|
|
20
|
+
var changed = keys.some(function (key) {
|
|
21
|
+
return currentPluginState[key] !== meta[key];
|
|
22
|
+
});
|
|
23
|
+
if (changed) {
|
|
24
|
+
var newState = _objectSpread(_objectSpread({}, currentPluginState), meta);
|
|
25
|
+
dispatch(pluginKey, newState);
|
|
26
|
+
return newState;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return currentPluginState;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
package/dist/esm/tablePlugin.js
CHANGED
|
@@ -6,6 +6,7 @@ import { tableCell, tableCellWithNestedTable, tableHeader, tableHeaderWithNested
|
|
|
6
6
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
7
7
|
import { browser } from '@atlaskit/editor-common/browser';
|
|
8
8
|
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
9
|
+
import { getDomRefFromSelection } from '@atlaskit/editor-common/get-dom-ref-from-selection';
|
|
9
10
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
10
11
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
11
12
|
import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
@@ -42,6 +43,7 @@ import { createPlugin as createFlexiResizingPlugin } from './pm-plugins/table-re
|
|
|
42
43
|
import { getPluginState as getFlexiResizingPlugin } from './pm-plugins/table-resizing/plugin-factory';
|
|
43
44
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing/plugin-key';
|
|
44
45
|
import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
|
|
46
|
+
import { createPlugin as createSizeSelectorPlugin, pluginKey as sizeSelectorPluginKey } from './pm-plugins/table-size-selector';
|
|
45
47
|
import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
46
48
|
import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
|
|
47
49
|
import { createTableWithWidth } from './pm-plugins/utils/create';
|
|
@@ -55,6 +57,7 @@ import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
|
55
57
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
56
58
|
import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
|
|
57
59
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
60
|
+
import { SizeSelector } from './ui/SizeSelector';
|
|
58
61
|
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
59
62
|
import { getToolbarConfig } from './ui/toolbar';
|
|
60
63
|
var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
@@ -66,7 +69,7 @@ var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
|
66
69
|
* from `@atlaskit/editor-core`.
|
|
67
70
|
*/
|
|
68
71
|
var tablePlugin = function tablePlugin(_ref) {
|
|
69
|
-
var _api$analytics, _api$accessibilityUti, _options$getEditorFea, _api$analytics2;
|
|
72
|
+
var _api$analytics, _api$accessibilityUti, _options$getEditorFea, _options$getEditorFea2, _api$analytics2;
|
|
70
73
|
var options = _ref.config,
|
|
71
74
|
api = _ref.api;
|
|
72
75
|
var editorViewRef = {
|
|
@@ -83,6 +86,9 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
83
86
|
var isTableFixedColumnWidthsOptionEnabled = (options === null || options === void 0 || (_options$getEditorFea = options.getEditorFeatureFlags) === null || _options$getEditorFea === void 0 ? void 0 : _options$getEditorFea.call(options).tableWithFixedColumnWidthsOption) || false;
|
|
84
87
|
var shouldUseIncreasedScalingPercent = (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && (isTableFixedColumnWidthsOptionEnabled || ( // When in comment editor, we need the scaling percent to be 40% while tableWithFixedColumnWidthsOption is not visible
|
|
85
88
|
options === null || options === void 0 ? void 0 : options.isCommentEditor));
|
|
89
|
+
var isTableSelectorEnabled =
|
|
90
|
+
// eslint-disable-next-line @atlaskit/platform/no-preconditioning
|
|
91
|
+
!(options !== null && options !== void 0 && options.isChromelessEditor) && !(options !== null && options !== void 0 && options.isCommentEditor) && (options === null || options === void 0 || (_options$getEditorFea2 = options.getEditorFeatureFlags) === null || _options$getEditorFea2 === void 0 ? void 0 : _options$getEditorFea2.call(options).tableSelector) && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_table_picker');
|
|
86
92
|
return {
|
|
87
93
|
name: 'table',
|
|
88
94
|
// Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
|
|
@@ -386,6 +392,12 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
386
392
|
}
|
|
387
393
|
});
|
|
388
394
|
}
|
|
395
|
+
}, {
|
|
396
|
+
name: 'tableSizeSelectorPlugin',
|
|
397
|
+
plugin: function plugin(_ref19) {
|
|
398
|
+
var dispatch = _ref19.dispatch;
|
|
399
|
+
return isTableSelectorEnabled ? createSizeSelectorPlugin(dispatch) : undefined;
|
|
400
|
+
}
|
|
389
401
|
}];
|
|
390
402
|
|
|
391
403
|
// Workaround for table element breaking issue caused by composition event with an inputType of deleteCompositionText.
|
|
@@ -400,13 +412,13 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
400
412
|
}
|
|
401
413
|
return plugins;
|
|
402
414
|
},
|
|
403
|
-
contentComponent: function contentComponent(
|
|
415
|
+
contentComponent: function contentComponent(_ref20) {
|
|
404
416
|
var _api$featureFlags;
|
|
405
|
-
var editorView =
|
|
406
|
-
popupsMountPoint =
|
|
407
|
-
popupsBoundariesElement =
|
|
408
|
-
popupsScrollableElement =
|
|
409
|
-
dispatchAnalyticsEvent =
|
|
417
|
+
var editorView = _ref20.editorView,
|
|
418
|
+
popupsMountPoint = _ref20.popupsMountPoint,
|
|
419
|
+
popupsBoundariesElement = _ref20.popupsBoundariesElement,
|
|
420
|
+
popupsScrollableElement = _ref20.popupsScrollableElement,
|
|
421
|
+
dispatchAnalyticsEvent = _ref20.dispatchAnalyticsEvent;
|
|
410
422
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
411
423
|
component: ACTION_SUBJECT.TABLES_PLUGIN,
|
|
412
424
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -422,34 +434,38 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
422
434
|
tableWidthPluginState: tableWidthPluginKey,
|
|
423
435
|
tableResizingPluginState: tableResizingPluginKey,
|
|
424
436
|
stickyHeadersState: stickyHeadersPluginKey,
|
|
425
|
-
dragAndDropState: dragAndDropPluginKey
|
|
437
|
+
dragAndDropState: dragAndDropPluginKey,
|
|
438
|
+
sizeSelectorPluginState: sizeSelectorPluginKey
|
|
426
439
|
},
|
|
427
|
-
render: function render(
|
|
428
|
-
var
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
440
|
+
render: function render(_ref21) {
|
|
441
|
+
var _sizeSelectorPluginSt, _api$analytics3;
|
|
442
|
+
var resizingPluginState = _ref21.tableResizingPluginState,
|
|
443
|
+
stickyHeadersState = _ref21.stickyHeadersState,
|
|
444
|
+
tablePluginState = _ref21.tablePluginState,
|
|
445
|
+
tableWidthPluginState = _ref21.tableWidthPluginState,
|
|
446
|
+
dragAndDropState = _ref21.dragAndDropState,
|
|
447
|
+
sizeSelectorPluginState = _ref21.sizeSelectorPluginState;
|
|
433
448
|
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
434
449
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
435
450
|
var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
436
451
|
var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
437
452
|
var isResizing = isColumnResizing || isTableResizing;
|
|
438
453
|
var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
454
|
+
var isSizeSelectorOpen = sizeSelectorPluginState === null || sizeSelectorPluginState === void 0 ? void 0 : sizeSelectorPluginState.isSelectorOpen;
|
|
455
|
+
var _ref22 = tablePluginState,
|
|
456
|
+
tableNode = _ref22.tableNode,
|
|
457
|
+
tablePos = _ref22.tablePos,
|
|
458
|
+
targetCellPosition = _ref22.targetCellPosition,
|
|
459
|
+
isContextualMenuOpen = _ref22.isContextualMenuOpen,
|
|
460
|
+
tableRef = _ref22.tableRef,
|
|
461
|
+
pluginConfig = _ref22.pluginConfig,
|
|
462
|
+
insertColumnButtonIndex = _ref22.insertColumnButtonIndex,
|
|
463
|
+
insertRowButtonIndex = _ref22.insertRowButtonIndex,
|
|
464
|
+
isHeaderColumnEnabled = _ref22.isHeaderColumnEnabled,
|
|
465
|
+
isHeaderRowEnabled = _ref22.isHeaderRowEnabled,
|
|
466
|
+
isDragAndDropEnabled = _ref22.isDragAndDropEnabled,
|
|
467
|
+
tableWrapperTarget = _ref22.tableWrapperTarget,
|
|
468
|
+
isCellMenuOpenByKeyboard = _ref22.isCellMenuOpenByKeyboard;
|
|
453
469
|
var allowControls = pluginConfig.allowControls;
|
|
454
470
|
var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
|
|
455
471
|
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
|
|
@@ -539,13 +555,20 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
539
555
|
forcePlacement: true,
|
|
540
556
|
zIndex: akEditorFloatingPanelZIndex,
|
|
541
557
|
offset: [0, 10]
|
|
558
|
+
}), isTableSelectorEnabled && isSizeSelectorOpen && /*#__PURE__*/React.createElement(SizeSelector, {
|
|
559
|
+
api: api,
|
|
560
|
+
isOpenedByKeyboard: false,
|
|
561
|
+
popupsMountPoint: popupsMountPoint,
|
|
562
|
+
target: (_sizeSelectorPluginSt = sizeSelectorPluginState === null || sizeSelectorPluginState === void 0 ? void 0 : sizeSelectorPluginState.targetRef) !== null && _sizeSelectorPluginSt !== void 0 ? _sizeSelectorPluginSt : getDomRefFromSelection(editorView, ACTION_SUBJECT_ID.PICKER_TABLE_SIZE, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent),
|
|
563
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
564
|
+
popupsScrollableElement: popupsScrollableElement
|
|
542
565
|
}));
|
|
543
566
|
}
|
|
544
567
|
}));
|
|
545
568
|
},
|
|
546
569
|
pluginsOptions: {
|
|
547
|
-
quickInsert: function quickInsert(
|
|
548
|
-
var formatMessage =
|
|
570
|
+
quickInsert: function quickInsert(_ref23) {
|
|
571
|
+
var formatMessage = _ref23.formatMessage;
|
|
549
572
|
return [{
|
|
550
573
|
id: 'table',
|
|
551
574
|
title: formatMessage(messages.table),
|
|
@@ -558,6 +581,14 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
558
581
|
},
|
|
559
582
|
action: function action(insert, state) {
|
|
560
583
|
var _api$table, _options$tableOptions6;
|
|
584
|
+
if (isTableSelectorEnabled) {
|
|
585
|
+
var _tr = insert('');
|
|
586
|
+
_tr.setMeta(sizeSelectorPluginKey, {
|
|
587
|
+
isSelectorOpen: true
|
|
588
|
+
});
|
|
589
|
+
return _tr;
|
|
590
|
+
}
|
|
591
|
+
|
|
561
592
|
// see comment on tablesPlugin.getSharedState on usage
|
|
562
593
|
var tableState = api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
563
594
|
var tableNodeProps = {
|
|
@@ -608,8 +639,8 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
608
639
|
return editorViewRef.current;
|
|
609
640
|
}, options, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent)(pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions))
|
|
610
641
|
},
|
|
611
|
-
usePluginHook: function usePluginHook(
|
|
612
|
-
var editorView =
|
|
642
|
+
usePluginHook: function usePluginHook(_ref24) {
|
|
643
|
+
var editorView = _ref24.editorView;
|
|
613
644
|
var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode']),
|
|
614
645
|
editorViewModeState = _useSharedPluginState.editorViewModeState;
|
|
615
646
|
var mode = editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
|