@atlaskit/editor-plugin-table 7.25.19 → 7.25.20
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 +9 -0
- package/dist/cjs/plugin.js +42 -34
- package/dist/cjs/pm-plugins/table-width-in-comment-fix.js +99 -0
- package/dist/es2019/plugin.js +9 -0
- package/dist/es2019/pm-plugins/table-width-in-comment-fix.js +100 -0
- package/dist/esm/plugin.js +42 -34
- package/dist/esm/pm-plugins/table-width-in-comment-fix.js +95 -0
- package/dist/types/pm-plugins/table-width-in-comment-fix.d.ts +11 -0
- package/dist/types-ts4.5/pm-plugins/table-width-in-comment-fix.d.ts +11 -0
- package/package.json +1 -1
- package/src/plugin.tsx +11 -0
- package/src/pm-plugins/table-width-in-comment-fix.ts +113 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.25.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#137344](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137344)
|
|
8
|
+
[`00c81bdf34c46`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/00c81bdf34c46) -
|
|
9
|
+
[ux] Fixes an issue where tables that existed before "Support Table in Comment" are displayed as
|
|
10
|
+
centered 760px width tables when FF for Support Table in Comment is enabled.
|
|
11
|
+
|
|
3
12
|
## 7.25.19
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -36,6 +36,7 @@ var _tableLocalId = require("./pm-plugins/table-local-id");
|
|
|
36
36
|
var _tableResizing = require("./pm-plugins/table-resizing");
|
|
37
37
|
var _tableSelectionKeymap = require("./pm-plugins/table-selection-keymap");
|
|
38
38
|
var _tableWidth = require("./pm-plugins/table-width");
|
|
39
|
+
var _tableWidthInCommentFix = require("./pm-plugins/table-width-in-comment-fix");
|
|
39
40
|
var _viewModeSort = require("./pm-plugins/view-mode-sort");
|
|
40
41
|
var _toDOM = require("./toDOM");
|
|
41
42
|
var _toolbar = require("./toolbar");
|
|
@@ -290,21 +291,28 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
290
291
|
dispatch = _ref14.dispatch;
|
|
291
292
|
return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
|
|
292
293
|
}
|
|
294
|
+
}, {
|
|
295
|
+
name: 'tableWidthInCommentFix',
|
|
296
|
+
plugin: function plugin(_ref15) {
|
|
297
|
+
var _options$isTableAlign2;
|
|
298
|
+
var dispatch = _ref15.dispatch;
|
|
299
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled && options !== null && options !== void 0 && options.isCommentEditor ? (0, _tableWidthInCommentFix.createPlugin)(dispatch, (_options$isTableAlign2 = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign2 !== void 0 ? _options$isTableAlign2 : false) : undefined;
|
|
300
|
+
}
|
|
293
301
|
},
|
|
294
302
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
295
303
|
{
|
|
296
304
|
name: 'tableOverflowAnalyticsPlugin',
|
|
297
|
-
plugin: function plugin(
|
|
305
|
+
plugin: function plugin(_ref16) {
|
|
298
306
|
var _options$tableResizin;
|
|
299
|
-
var dispatch =
|
|
300
|
-
dispatchAnalyticsEvent =
|
|
307
|
+
var dispatch = _ref16.dispatch,
|
|
308
|
+
dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
|
|
301
309
|
return (0, _tableAnalytics.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
|
|
302
310
|
}
|
|
303
311
|
}, {
|
|
304
312
|
name: 'tableAnalyticsPlugin',
|
|
305
|
-
plugin: function plugin(
|
|
306
|
-
var dispatch =
|
|
307
|
-
dispatchAnalyticsEvent =
|
|
313
|
+
plugin: function plugin(_ref17) {
|
|
314
|
+
var dispatch = _ref17.dispatch,
|
|
315
|
+
dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
|
|
308
316
|
return (0, _plugin.createPlugin)(dispatch, dispatchAnalyticsEvent);
|
|
309
317
|
}
|
|
310
318
|
}, {
|
|
@@ -335,13 +343,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
335
343
|
}
|
|
336
344
|
return plugins;
|
|
337
345
|
},
|
|
338
|
-
contentComponent: function contentComponent(
|
|
346
|
+
contentComponent: function contentComponent(_ref18) {
|
|
339
347
|
var _api$featureFlags;
|
|
340
|
-
var editorView =
|
|
341
|
-
popupsMountPoint =
|
|
342
|
-
popupsBoundariesElement =
|
|
343
|
-
popupsScrollableElement =
|
|
344
|
-
dispatchAnalyticsEvent =
|
|
348
|
+
var editorView = _ref18.editorView,
|
|
349
|
+
popupsMountPoint = _ref18.popupsMountPoint,
|
|
350
|
+
popupsBoundariesElement = _ref18.popupsBoundariesElement,
|
|
351
|
+
popupsScrollableElement = _ref18.popupsScrollableElement,
|
|
352
|
+
dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
|
|
345
353
|
return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
|
|
346
354
|
component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
|
|
347
355
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -357,32 +365,32 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
357
365
|
stickyHeadersState: _stickyHeaders.pluginKey,
|
|
358
366
|
dragAndDropState: _dragAndDrop.pluginKey
|
|
359
367
|
},
|
|
360
|
-
render: function render(
|
|
361
|
-
var resizingPluginState =
|
|
362
|
-
stickyHeadersState =
|
|
363
|
-
tablePluginState =
|
|
364
|
-
tableWidthPluginState =
|
|
365
|
-
dragAndDropState =
|
|
368
|
+
render: function render(_ref19) {
|
|
369
|
+
var resizingPluginState = _ref19.tableResizingPluginState,
|
|
370
|
+
stickyHeadersState = _ref19.stickyHeadersState,
|
|
371
|
+
tablePluginState = _ref19.tablePluginState,
|
|
372
|
+
tableWidthPluginState = _ref19.tableWidthPluginState,
|
|
373
|
+
dragAndDropState = _ref19.dragAndDropState;
|
|
366
374
|
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
367
375
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
368
376
|
var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
369
377
|
var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
370
378
|
var isResizing = isColumnResizing || isTableResizing;
|
|
371
379
|
var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
372
|
-
var
|
|
373
|
-
tableNode =
|
|
374
|
-
tablePos =
|
|
375
|
-
targetCellPosition =
|
|
376
|
-
isContextualMenuOpen =
|
|
377
|
-
tableRef =
|
|
378
|
-
pluginConfig =
|
|
379
|
-
insertColumnButtonIndex =
|
|
380
|
-
insertRowButtonIndex =
|
|
381
|
-
isHeaderColumnEnabled =
|
|
382
|
-
isHeaderRowEnabled =
|
|
383
|
-
isDragAndDropEnabled =
|
|
384
|
-
tableWrapperTarget =
|
|
385
|
-
isCellMenuOpenByKeyboard =
|
|
380
|
+
var _ref20 = tablePluginState,
|
|
381
|
+
tableNode = _ref20.tableNode,
|
|
382
|
+
tablePos = _ref20.tablePos,
|
|
383
|
+
targetCellPosition = _ref20.targetCellPosition,
|
|
384
|
+
isContextualMenuOpen = _ref20.isContextualMenuOpen,
|
|
385
|
+
tableRef = _ref20.tableRef,
|
|
386
|
+
pluginConfig = _ref20.pluginConfig,
|
|
387
|
+
insertColumnButtonIndex = _ref20.insertColumnButtonIndex,
|
|
388
|
+
insertRowButtonIndex = _ref20.insertRowButtonIndex,
|
|
389
|
+
isHeaderColumnEnabled = _ref20.isHeaderColumnEnabled,
|
|
390
|
+
isHeaderRowEnabled = _ref20.isHeaderRowEnabled,
|
|
391
|
+
isDragAndDropEnabled = _ref20.isDragAndDropEnabled,
|
|
392
|
+
tableWrapperTarget = _ref20.tableWrapperTarget,
|
|
393
|
+
isCellMenuOpenByKeyboard = _ref20.isCellMenuOpenByKeyboard;
|
|
386
394
|
var allowControls = pluginConfig.allowControls;
|
|
387
395
|
var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
|
|
388
396
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard && (0, _platformFeatureFlags.fg)('platform_editor_a11y_table_context_menu')) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/_react.default.createElement(_FloatingContextualButton.default, {
|
|
@@ -475,8 +483,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
475
483
|
}));
|
|
476
484
|
},
|
|
477
485
|
pluginsOptions: {
|
|
478
|
-
quickInsert: function quickInsert(
|
|
479
|
-
var formatMessage =
|
|
486
|
+
quickInsert: function quickInsert(_ref21) {
|
|
487
|
+
var formatMessage = _ref21.formatMessage;
|
|
480
488
|
return [{
|
|
481
489
|
id: 'table',
|
|
482
490
|
title: formatMessage(_messages.toolbarInsertBlockMessages.table),
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.pluginKey = exports.createPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
13
|
+
var _alignment = require("../utils/alignment");
|
|
14
|
+
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; }
|
|
15
|
+
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) { (0, _defineProperty2.default)(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; } /*
|
|
16
|
+
Existing legacy tables in Comment editor have set attributes:
|
|
17
|
+
- width = 760
|
|
18
|
+
- layout = 'default'.
|
|
19
|
+
|
|
20
|
+
When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
|
|
21
|
+
It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
|
|
22
|
+
the editor container until a user decided to edit their old comment and set a custom table width themselves.
|
|
23
|
+
|
|
24
|
+
This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
|
|
25
|
+
existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
|
|
26
|
+
*/
|
|
27
|
+
var pluginKey = exports.pluginKey = new _state.PluginKey('tableWidthInCommentFixPlugin');
|
|
28
|
+
var getPluginState = function getPluginState(state) {
|
|
29
|
+
return state && pluginKey.getState(state);
|
|
30
|
+
};
|
|
31
|
+
var createPlugin = exports.createPlugin = function createPlugin(dispatch, isTableAlignmentEnabled) {
|
|
32
|
+
return new _safePlugin.SafePlugin({
|
|
33
|
+
key: pluginKey,
|
|
34
|
+
state: {
|
|
35
|
+
init: function init() {
|
|
36
|
+
return {
|
|
37
|
+
documentHasLoadedOnce: false
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
apply: function apply(tr, pluginState) {
|
|
41
|
+
var meta = tr.getMeta(pluginKey);
|
|
42
|
+
if (meta) {
|
|
43
|
+
var keys = Object.keys(meta);
|
|
44
|
+
var changed = keys.some(function (key) {
|
|
45
|
+
return pluginState[key] !== meta[key];
|
|
46
|
+
});
|
|
47
|
+
if (changed) {
|
|
48
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), meta);
|
|
49
|
+
dispatch(pluginKey, newState);
|
|
50
|
+
return newState;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return pluginState;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
view: function view() {
|
|
57
|
+
return {
|
|
58
|
+
update: function update(editorView) {
|
|
59
|
+
var state = editorView.state;
|
|
60
|
+
var pluginState = getPluginState(state);
|
|
61
|
+
if (!pluginState) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var documentHasLoadedOnce = pluginState.documentHasLoadedOnce;
|
|
65
|
+
if (documentHasLoadedOnce) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var table = state.schema.nodes.table;
|
|
69
|
+
(0, _rafSchd.default)(function () {
|
|
70
|
+
var tr = editorView.state.tr;
|
|
71
|
+
var tableWidthAndLayoutUpdated = false;
|
|
72
|
+
editorView.state.doc.descendants(function (node, pos) {
|
|
73
|
+
var isTable = node.type === table;
|
|
74
|
+
var width = node.attrs.width;
|
|
75
|
+
var layout = node.attrs.layout;
|
|
76
|
+
if (isTable && width === _editorSharedStyles.akEditorDefaultLayoutWidth && layout === 'default') {
|
|
77
|
+
tableWidthAndLayoutUpdated = true;
|
|
78
|
+
tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
79
|
+
width: null,
|
|
80
|
+
layout: isTableAlignmentEnabled ? _alignment.ALIGN_START : 'default'
|
|
81
|
+
}));
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// Returning false here because don't need to change nested tables
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
if (tableWidthAndLayoutUpdated) {
|
|
88
|
+
tr.setMeta('addToHistory', false);
|
|
89
|
+
editorView.dispatch(tr);
|
|
90
|
+
}
|
|
91
|
+
})();
|
|
92
|
+
editorView.dispatch(state.tr.setMeta(pluginKey, {
|
|
93
|
+
documentHasLoadedOnce: true
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -28,6 +28,7 @@ import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-loc
|
|
|
28
28
|
import { createPlugin as createFlexiResizingPlugin, getPluginState as getFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
29
29
|
import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
|
|
30
30
|
import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
31
|
+
import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
|
|
31
32
|
import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
|
|
32
33
|
import { tableNodeSpecWithFixedToDOM } from './toDOM';
|
|
33
34
|
import { getToolbarConfig } from './toolbar';
|
|
@@ -278,6 +279,14 @@ const tablesPlugin = ({
|
|
|
278
279
|
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign, _options$isCommentEdi;
|
|
279
280
|
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
|
|
280
281
|
}
|
|
282
|
+
}, {
|
|
283
|
+
name: 'tableWidthInCommentFix',
|
|
284
|
+
plugin: ({
|
|
285
|
+
dispatch
|
|
286
|
+
}) => {
|
|
287
|
+
var _options$isTableAlign2;
|
|
288
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled && options !== null && options !== void 0 && options.isCommentEditor ? createTableWidthInCommentFixPlugin(dispatch, (_options$isTableAlign2 = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign2 !== void 0 ? _options$isTableAlign2 : false) : undefined;
|
|
289
|
+
}
|
|
281
290
|
},
|
|
282
291
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
283
292
|
{
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Existing legacy tables in Comment editor have set attributes:
|
|
3
|
+
- width = 760
|
|
4
|
+
- layout = 'default'.
|
|
5
|
+
|
|
6
|
+
When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
|
|
7
|
+
It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
|
|
8
|
+
the editor container until a user decided to edit their old comment and set a custom table width themselves.
|
|
9
|
+
|
|
10
|
+
This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
|
|
11
|
+
existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import rafSchedule from 'raf-schd';
|
|
15
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
16
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
17
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
18
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
19
|
+
export const pluginKey = new PluginKey('tableWidthInCommentFixPlugin');
|
|
20
|
+
const getPluginState = state => state && pluginKey.getState(state);
|
|
21
|
+
const createPlugin = (dispatch, isTableAlignmentEnabled) => {
|
|
22
|
+
return new SafePlugin({
|
|
23
|
+
key: pluginKey,
|
|
24
|
+
state: {
|
|
25
|
+
init() {
|
|
26
|
+
return {
|
|
27
|
+
documentHasLoadedOnce: false
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
apply(tr, pluginState) {
|
|
31
|
+
const meta = tr.getMeta(pluginKey);
|
|
32
|
+
if (meta) {
|
|
33
|
+
const keys = Object.keys(meta);
|
|
34
|
+
const changed = keys.some(key => {
|
|
35
|
+
return pluginState[key] !== meta[key];
|
|
36
|
+
});
|
|
37
|
+
if (changed) {
|
|
38
|
+
const newState = {
|
|
39
|
+
...pluginState,
|
|
40
|
+
...meta
|
|
41
|
+
};
|
|
42
|
+
dispatch(pluginKey, newState);
|
|
43
|
+
return newState;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return pluginState;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
view: () => {
|
|
50
|
+
return {
|
|
51
|
+
update(editorView) {
|
|
52
|
+
const {
|
|
53
|
+
state
|
|
54
|
+
} = editorView;
|
|
55
|
+
const pluginState = getPluginState(state);
|
|
56
|
+
if (!pluginState) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const {
|
|
60
|
+
documentHasLoadedOnce
|
|
61
|
+
} = pluginState;
|
|
62
|
+
if (documentHasLoadedOnce) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const {
|
|
66
|
+
table
|
|
67
|
+
} = state.schema.nodes;
|
|
68
|
+
rafSchedule(() => {
|
|
69
|
+
const tr = editorView.state.tr;
|
|
70
|
+
let tableWidthAndLayoutUpdated = false;
|
|
71
|
+
editorView.state.doc.descendants((node, pos) => {
|
|
72
|
+
const isTable = node.type === table;
|
|
73
|
+
const width = node.attrs.width;
|
|
74
|
+
const layout = node.attrs.layout;
|
|
75
|
+
if (isTable && width === akEditorDefaultLayoutWidth && layout === 'default') {
|
|
76
|
+
tableWidthAndLayoutUpdated = true;
|
|
77
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
78
|
+
...node.attrs,
|
|
79
|
+
width: null,
|
|
80
|
+
layout: isTableAlignmentEnabled ? ALIGN_START : 'default'
|
|
81
|
+
});
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// Returning false here because don't need to change nested tables
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
if (tableWidthAndLayoutUpdated) {
|
|
88
|
+
tr.setMeta('addToHistory', false);
|
|
89
|
+
editorView.dispatch(tr);
|
|
90
|
+
}
|
|
91
|
+
})();
|
|
92
|
+
editorView.dispatch(state.tr.setMeta(pluginKey, {
|
|
93
|
+
documentHasLoadedOnce: true
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
export { createPlugin };
|
package/dist/esm/plugin.js
CHANGED
|
@@ -31,6 +31,7 @@ import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-loc
|
|
|
31
31
|
import { createPlugin as createFlexiResizingPlugin, getPluginState as getFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
32
32
|
import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
|
|
33
33
|
import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
34
|
+
import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
|
|
34
35
|
import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
|
|
35
36
|
import { tableNodeSpecWithFixedToDOM } from './toDOM';
|
|
36
37
|
import { getToolbarConfig } from './toolbar';
|
|
@@ -283,21 +284,28 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
283
284
|
dispatch = _ref14.dispatch;
|
|
284
285
|
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false, (_options$isCommentEdi = options === null || options === void 0 ? void 0 : options.isCommentEditor) !== null && _options$isCommentEdi !== void 0 ? _options$isCommentEdi : false) : undefined;
|
|
285
286
|
}
|
|
287
|
+
}, {
|
|
288
|
+
name: 'tableWidthInCommentFix',
|
|
289
|
+
plugin: function plugin(_ref15) {
|
|
290
|
+
var _options$isTableAlign2;
|
|
291
|
+
var dispatch = _ref15.dispatch;
|
|
292
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled && options !== null && options !== void 0 && options.isCommentEditor ? createTableWidthInCommentFixPlugin(dispatch, (_options$isTableAlign2 = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign2 !== void 0 ? _options$isTableAlign2 : false) : undefined;
|
|
293
|
+
}
|
|
286
294
|
},
|
|
287
295
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
288
296
|
{
|
|
289
297
|
name: 'tableOverflowAnalyticsPlugin',
|
|
290
|
-
plugin: function plugin(
|
|
298
|
+
plugin: function plugin(_ref16) {
|
|
291
299
|
var _options$tableResizin;
|
|
292
|
-
var dispatch =
|
|
293
|
-
dispatchAnalyticsEvent =
|
|
300
|
+
var dispatch = _ref16.dispatch,
|
|
301
|
+
dispatchAnalyticsEvent = _ref16.dispatchAnalyticsEvent;
|
|
294
302
|
return createTableOverflowAnalyticsPlugin(dispatch, dispatchAnalyticsEvent, (_options$tableResizin = options === null || options === void 0 ? void 0 : options.tableResizingEnabled) !== null && _options$tableResizin !== void 0 ? _options$tableResizin : false);
|
|
295
303
|
}
|
|
296
304
|
}, {
|
|
297
305
|
name: 'tableAnalyticsPlugin',
|
|
298
|
-
plugin: function plugin(
|
|
299
|
-
var dispatch =
|
|
300
|
-
dispatchAnalyticsEvent =
|
|
306
|
+
plugin: function plugin(_ref17) {
|
|
307
|
+
var dispatch = _ref17.dispatch,
|
|
308
|
+
dispatchAnalyticsEvent = _ref17.dispatchAnalyticsEvent;
|
|
301
309
|
return createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent);
|
|
302
310
|
}
|
|
303
311
|
}, {
|
|
@@ -328,13 +336,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
328
336
|
}
|
|
329
337
|
return plugins;
|
|
330
338
|
},
|
|
331
|
-
contentComponent: function contentComponent(
|
|
339
|
+
contentComponent: function contentComponent(_ref18) {
|
|
332
340
|
var _api$featureFlags;
|
|
333
|
-
var editorView =
|
|
334
|
-
popupsMountPoint =
|
|
335
|
-
popupsBoundariesElement =
|
|
336
|
-
popupsScrollableElement =
|
|
337
|
-
dispatchAnalyticsEvent =
|
|
341
|
+
var editorView = _ref18.editorView,
|
|
342
|
+
popupsMountPoint = _ref18.popupsMountPoint,
|
|
343
|
+
popupsBoundariesElement = _ref18.popupsBoundariesElement,
|
|
344
|
+
popupsScrollableElement = _ref18.popupsScrollableElement,
|
|
345
|
+
dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
|
|
338
346
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
339
347
|
component: ACTION_SUBJECT.TABLES_PLUGIN,
|
|
340
348
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -350,32 +358,32 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
350
358
|
stickyHeadersState: stickyHeadersPluginKey,
|
|
351
359
|
dragAndDropState: dragAndDropPluginKey
|
|
352
360
|
},
|
|
353
|
-
render: function render(
|
|
354
|
-
var resizingPluginState =
|
|
355
|
-
stickyHeadersState =
|
|
356
|
-
tablePluginState =
|
|
357
|
-
tableWidthPluginState =
|
|
358
|
-
dragAndDropState =
|
|
361
|
+
render: function render(_ref19) {
|
|
362
|
+
var resizingPluginState = _ref19.tableResizingPluginState,
|
|
363
|
+
stickyHeadersState = _ref19.stickyHeadersState,
|
|
364
|
+
tablePluginState = _ref19.tablePluginState,
|
|
365
|
+
tableWidthPluginState = _ref19.tableWidthPluginState,
|
|
366
|
+
dragAndDropState = _ref19.dragAndDropState;
|
|
359
367
|
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
360
368
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
361
369
|
var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
362
370
|
var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
363
371
|
var isResizing = isColumnResizing || isTableResizing;
|
|
364
372
|
var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
365
|
-
var
|
|
366
|
-
tableNode =
|
|
367
|
-
tablePos =
|
|
368
|
-
targetCellPosition =
|
|
369
|
-
isContextualMenuOpen =
|
|
370
|
-
tableRef =
|
|
371
|
-
pluginConfig =
|
|
372
|
-
insertColumnButtonIndex =
|
|
373
|
-
insertRowButtonIndex =
|
|
374
|
-
isHeaderColumnEnabled =
|
|
375
|
-
isHeaderRowEnabled =
|
|
376
|
-
isDragAndDropEnabled =
|
|
377
|
-
tableWrapperTarget =
|
|
378
|
-
isCellMenuOpenByKeyboard =
|
|
373
|
+
var _ref20 = tablePluginState,
|
|
374
|
+
tableNode = _ref20.tableNode,
|
|
375
|
+
tablePos = _ref20.tablePos,
|
|
376
|
+
targetCellPosition = _ref20.targetCellPosition,
|
|
377
|
+
isContextualMenuOpen = _ref20.isContextualMenuOpen,
|
|
378
|
+
tableRef = _ref20.tableRef,
|
|
379
|
+
pluginConfig = _ref20.pluginConfig,
|
|
380
|
+
insertColumnButtonIndex = _ref20.insertColumnButtonIndex,
|
|
381
|
+
insertRowButtonIndex = _ref20.insertRowButtonIndex,
|
|
382
|
+
isHeaderColumnEnabled = _ref20.isHeaderColumnEnabled,
|
|
383
|
+
isHeaderRowEnabled = _ref20.isHeaderRowEnabled,
|
|
384
|
+
isDragAndDropEnabled = _ref20.isDragAndDropEnabled,
|
|
385
|
+
tableWrapperTarget = _ref20.tableWrapperTarget,
|
|
386
|
+
isCellMenuOpenByKeyboard = _ref20.isCellMenuOpenByKeyboard;
|
|
379
387
|
var allowControls = pluginConfig.allowControls;
|
|
380
388
|
var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
|
|
381
389
|
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard && fg('platform_editor_a11y_table_context_menu')) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
|
|
@@ -468,8 +476,8 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
468
476
|
}));
|
|
469
477
|
},
|
|
470
478
|
pluginsOptions: {
|
|
471
|
-
quickInsert: function quickInsert(
|
|
472
|
-
var formatMessage =
|
|
479
|
+
quickInsert: function quickInsert(_ref21) {
|
|
480
|
+
var formatMessage = _ref21.formatMessage;
|
|
473
481
|
return [{
|
|
474
482
|
id: 'table',
|
|
475
483
|
title: formatMessage(messages.table),
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
/*
|
|
5
|
+
Existing legacy tables in Comment editor have set attributes:
|
|
6
|
+
- width = 760
|
|
7
|
+
- layout = 'default'.
|
|
8
|
+
|
|
9
|
+
When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
|
|
10
|
+
It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
|
|
11
|
+
the editor container until a user decided to edit their old comment and set a custom table width themselves.
|
|
12
|
+
|
|
13
|
+
This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
|
|
14
|
+
existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import rafSchedule from 'raf-schd';
|
|
18
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
19
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
20
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
21
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
22
|
+
export var pluginKey = new PluginKey('tableWidthInCommentFixPlugin');
|
|
23
|
+
var getPluginState = function getPluginState(state) {
|
|
24
|
+
return state && pluginKey.getState(state);
|
|
25
|
+
};
|
|
26
|
+
var createPlugin = function createPlugin(dispatch, isTableAlignmentEnabled) {
|
|
27
|
+
return new SafePlugin({
|
|
28
|
+
key: pluginKey,
|
|
29
|
+
state: {
|
|
30
|
+
init: function init() {
|
|
31
|
+
return {
|
|
32
|
+
documentHasLoadedOnce: false
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
apply: function apply(tr, pluginState) {
|
|
36
|
+
var meta = tr.getMeta(pluginKey);
|
|
37
|
+
if (meta) {
|
|
38
|
+
var keys = Object.keys(meta);
|
|
39
|
+
var changed = keys.some(function (key) {
|
|
40
|
+
return pluginState[key] !== meta[key];
|
|
41
|
+
});
|
|
42
|
+
if (changed) {
|
|
43
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), meta);
|
|
44
|
+
dispatch(pluginKey, newState);
|
|
45
|
+
return newState;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return pluginState;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
view: function view() {
|
|
52
|
+
return {
|
|
53
|
+
update: function update(editorView) {
|
|
54
|
+
var state = editorView.state;
|
|
55
|
+
var pluginState = getPluginState(state);
|
|
56
|
+
if (!pluginState) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
var documentHasLoadedOnce = pluginState.documentHasLoadedOnce;
|
|
60
|
+
if (documentHasLoadedOnce) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
var table = state.schema.nodes.table;
|
|
64
|
+
rafSchedule(function () {
|
|
65
|
+
var tr = editorView.state.tr;
|
|
66
|
+
var tableWidthAndLayoutUpdated = false;
|
|
67
|
+
editorView.state.doc.descendants(function (node, pos) {
|
|
68
|
+
var isTable = node.type === table;
|
|
69
|
+
var width = node.attrs.width;
|
|
70
|
+
var layout = node.attrs.layout;
|
|
71
|
+
if (isTable && width === akEditorDefaultLayoutWidth && layout === 'default') {
|
|
72
|
+
tableWidthAndLayoutUpdated = true;
|
|
73
|
+
tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
74
|
+
width: null,
|
|
75
|
+
layout: isTableAlignmentEnabled ? ALIGN_START : 'default'
|
|
76
|
+
}));
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
// Returning false here because don't need to change nested tables
|
|
80
|
+
return false;
|
|
81
|
+
});
|
|
82
|
+
if (tableWidthAndLayoutUpdated) {
|
|
83
|
+
tr.setMeta('addToHistory', false);
|
|
84
|
+
editorView.dispatch(tr);
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
editorView.dispatch(state.tr.setMeta(pluginKey, {
|
|
88
|
+
documentHasLoadedOnce: true
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
export { createPlugin };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
type TableWidthInCommentFixPluginState = {
|
|
5
|
+
documentHasLoadedOnce: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const pluginKey: PluginKey<TableWidthInCommentFixPluginState>;
|
|
8
|
+
declare const createPlugin: (dispatch: Dispatch, isTableAlignmentEnabled: boolean) => SafePlugin<{
|
|
9
|
+
documentHasLoadedOnce: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
export { createPlugin };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
type TableWidthInCommentFixPluginState = {
|
|
5
|
+
documentHasLoadedOnce: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const pluginKey: PluginKey<TableWidthInCommentFixPluginState>;
|
|
8
|
+
declare const createPlugin: (dispatch: Dispatch, isTableAlignmentEnabled: boolean) => SafePlugin<{
|
|
9
|
+
documentHasLoadedOnce: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
export { createPlugin };
|
package/package.json
CHANGED
package/src/plugin.tsx
CHANGED
|
@@ -72,6 +72,7 @@ import {
|
|
|
72
72
|
createPlugin as createTableWidthPlugin,
|
|
73
73
|
pluginKey as tableWidthPluginKey,
|
|
74
74
|
} from './pm-plugins/table-width';
|
|
75
|
+
import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins/table-width-in-comment-fix';
|
|
75
76
|
import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
|
|
76
77
|
import { tableNodeSpecWithFixedToDOM } from './toDOM';
|
|
77
78
|
import { getToolbarConfig } from './toolbar';
|
|
@@ -457,6 +458,16 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
457
458
|
)
|
|
458
459
|
: undefined,
|
|
459
460
|
},
|
|
461
|
+
{
|
|
462
|
+
name: 'tableWidthInCommentFix',
|
|
463
|
+
plugin: ({ dispatch }) =>
|
|
464
|
+
options?.tableResizingEnabled && options?.isCommentEditor
|
|
465
|
+
? createTableWidthInCommentFixPlugin(
|
|
466
|
+
dispatch,
|
|
467
|
+
options?.isTableAlignmentEnabled ?? false,
|
|
468
|
+
)
|
|
469
|
+
: undefined,
|
|
470
|
+
},
|
|
460
471
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
461
472
|
{
|
|
462
473
|
name: 'tableOverflowAnalyticsPlugin',
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Existing legacy tables in Comment editor have set attributes:
|
|
3
|
+
- width = 760
|
|
4
|
+
- layout = 'default'.
|
|
5
|
+
|
|
6
|
+
When "Support Table in Comment" FF is enabled, table resizing (and table alignment in Confluence comments) is turned.
|
|
7
|
+
It results in (ED-24795) all exising tables being set 760px width. Instead they all should inherit width from
|
|
8
|
+
the editor container until a user decided to edit their old comment and set a custom table width themselves.
|
|
9
|
+
|
|
10
|
+
This plugin exists to fix the described issue. It ensures that once "Support Table in Comment" FF turned on,
|
|
11
|
+
existing tables continue to inherit the width of editor container and are 'left-aligned' by default.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import rafSchedule from 'raf-schd';
|
|
15
|
+
|
|
16
|
+
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
17
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
18
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
19
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
20
|
+
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
21
|
+
|
|
22
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
23
|
+
|
|
24
|
+
type TableWidthInCommentFixPluginState = {
|
|
25
|
+
documentHasLoadedOnce: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const pluginKey = new PluginKey<TableWidthInCommentFixPluginState>(
|
|
29
|
+
'tableWidthInCommentFixPlugin',
|
|
30
|
+
);
|
|
31
|
+
const getPluginState = (state: EditorState): TableWidthInCommentFixPluginState | undefined | null =>
|
|
32
|
+
state && pluginKey.getState(state);
|
|
33
|
+
|
|
34
|
+
const createPlugin = (dispatch: Dispatch, isTableAlignmentEnabled: boolean) => {
|
|
35
|
+
return new SafePlugin({
|
|
36
|
+
key: pluginKey,
|
|
37
|
+
state: {
|
|
38
|
+
init() {
|
|
39
|
+
return {
|
|
40
|
+
documentHasLoadedOnce: false,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
apply(tr, pluginState) {
|
|
44
|
+
const meta = tr.getMeta(pluginKey);
|
|
45
|
+
if (meta) {
|
|
46
|
+
const keys = Object.keys(meta) as Array<keyof TableWidthInCommentFixPluginState>;
|
|
47
|
+
const changed = keys.some((key) => {
|
|
48
|
+
return pluginState[key] !== meta[key];
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (changed) {
|
|
52
|
+
const newState = { ...pluginState, ...meta };
|
|
53
|
+
|
|
54
|
+
dispatch(pluginKey, newState);
|
|
55
|
+
return newState;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return pluginState;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
view: () => {
|
|
63
|
+
return {
|
|
64
|
+
update(editorView) {
|
|
65
|
+
const { state } = editorView;
|
|
66
|
+
const pluginState = getPluginState(state);
|
|
67
|
+
if (!pluginState) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const { documentHasLoadedOnce } = pluginState;
|
|
71
|
+
|
|
72
|
+
if (documentHasLoadedOnce) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const { table } = state.schema.nodes;
|
|
77
|
+
rafSchedule(() => {
|
|
78
|
+
const tr = editorView.state.tr;
|
|
79
|
+
let tableWidthAndLayoutUpdated = false;
|
|
80
|
+
editorView.state.doc.descendants((node, pos) => {
|
|
81
|
+
const isTable = node.type === table;
|
|
82
|
+
const width = node.attrs.width;
|
|
83
|
+
const layout = node.attrs.layout;
|
|
84
|
+
if (isTable && width === akEditorDefaultLayoutWidth && layout === 'default') {
|
|
85
|
+
tableWidthAndLayoutUpdated = true;
|
|
86
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
87
|
+
...node.attrs,
|
|
88
|
+
width: null,
|
|
89
|
+
layout: isTableAlignmentEnabled ? ALIGN_START : 'default',
|
|
90
|
+
});
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
// Returning false here because don't need to change nested tables
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
if (tableWidthAndLayoutUpdated) {
|
|
97
|
+
tr.setMeta('addToHistory', false);
|
|
98
|
+
editorView.dispatch(tr);
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
|
|
102
|
+
editorView.dispatch(
|
|
103
|
+
state.tr.setMeta(pluginKey, {
|
|
104
|
+
documentHasLoadedOnce: true,
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { createPlugin };
|