@atlaskit/editor-plugin-table 7.4.6 → 7.4.8
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 +13 -0
- package/dist/cjs/commands/insert.js +5 -12
- package/dist/cjs/plugin.js +17 -11
- package/dist/cjs/pm-plugins/table-width.js +53 -34
- package/dist/cjs/utils/create.js +28 -0
- package/dist/cjs/utils/index.js +8 -1
- package/dist/es2019/commands/insert.js +7 -14
- package/dist/es2019/plugin.js +16 -10
- package/dist/es2019/pm-plugins/table-width.js +133 -114
- package/dist/es2019/utils/create.js +18 -0
- package/dist/es2019/utils/index.js +2 -1
- package/dist/esm/commands/insert.js +7 -14
- package/dist/esm/plugin.js +16 -10
- package/dist/esm/pm-plugins/table-width.js +53 -34
- package/dist/esm/utils/create.js +21 -0
- package/dist/esm/utils/index.js +2 -1
- package/dist/types/commands/insert.d.ts +3 -3
- package/dist/types/plugin.d.ts +4 -0
- package/dist/types/pm-plugins/table-width.d.ts +2 -1
- package/dist/types/utils/create.d.ts +6 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/commands/insert.d.ts +3 -3
- package/dist/types-ts4.5/plugin.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +2 -1
- package/dist/types-ts4.5/utils/create.d.ts +6 -0
- package/dist/types-ts4.5/utils/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/commands/insert.ts +35 -19
- package/src/plugin.tsx +32 -9
- package/src/pm-plugins/table-width.ts +71 -38
- package/src/utils/create.ts +32 -0
- package/src/utils/index.ts +1 -0
|
@@ -11,130 +11,149 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
11
11
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
12
12
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
13
13
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
14
|
+
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
14
15
|
export const pluginKey = new PluginKey('tableWidthPlugin');
|
|
15
|
-
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
apply(tr, pluginState) {
|
|
24
|
-
const meta = tr.getMeta(pluginKey);
|
|
25
|
-
if (meta && meta.resizing !== pluginState.resizing) {
|
|
26
|
-
const newState = {
|
|
27
|
-
resizing: meta.resizing
|
|
16
|
+
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, getEditorFeatureFlags) => {
|
|
17
|
+
return new SafePlugin({
|
|
18
|
+
key: pluginKey,
|
|
19
|
+
state: {
|
|
20
|
+
init() {
|
|
21
|
+
return {
|
|
22
|
+
resizing: false
|
|
28
23
|
};
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
},
|
|
25
|
+
apply(tr, pluginState) {
|
|
26
|
+
const meta = tr.getMeta(pluginKey);
|
|
27
|
+
if (meta && meta.resizing !== pluginState.resizing) {
|
|
28
|
+
const newState = {
|
|
29
|
+
resizing: meta.resizing
|
|
30
|
+
};
|
|
31
|
+
dispatch(pluginKey, newState);
|
|
32
|
+
return newState;
|
|
33
|
+
}
|
|
34
|
+
return pluginState;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const selectedTableOldState = findTable(oldState.selection);
|
|
38
|
-
const selectedTableNewState = findTable(newState.selection);
|
|
36
|
+
},
|
|
37
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
38
|
+
// do not fire select table analytics events when a table is being created or deleted
|
|
39
|
+
const selectedTableOldState = findTable(oldState.selection);
|
|
40
|
+
const selectedTableNewState = findTable(newState.selection);
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
// When document first load in Confluence, initially it is an empty document
|
|
57
|
-
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
58
|
-
// what we need to do is to add width attr to all tables in the real document
|
|
59
|
-
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
60
|
-
const isReplaceDocumentOperation = transactions.some(tr => {
|
|
61
|
-
if (tr.getMeta('replaceDocument')) {
|
|
62
|
-
return true;
|
|
42
|
+
/**
|
|
43
|
+
* Select table event
|
|
44
|
+
* condition: 1
|
|
45
|
+
* When users selection changes to table
|
|
46
|
+
*/
|
|
47
|
+
if (!selectedTableOldState && selectedTableNewState) {
|
|
48
|
+
dispatchAnalyticsEvent({
|
|
49
|
+
action: ACTION.SELECTED,
|
|
50
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
51
|
+
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
52
|
+
eventType: EVENT_TYPE.TRACK,
|
|
53
|
+
attributes: {
|
|
54
|
+
localId: selectedTableNewState.node.attrs.localId || ''
|
|
55
|
+
}
|
|
56
|
+
});
|
|
63
57
|
}
|
|
64
|
-
const hasStepReplacingEntireDocument = tr.steps.some(step => {
|
|
65
|
-
if (!(step instanceof ReplaceStep)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
const isStepReplacingFromDocStart = step.from === 0;
|
|
69
|
-
const isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
|
|
70
|
-
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
});
|
|
75
|
-
return hasStepReplacingEntireDocument;
|
|
76
|
-
});
|
|
77
|
-
if (!isReplaceDocumentOperation) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const tr = newState.tr;
|
|
81
|
-
const {
|
|
82
|
-
table
|
|
83
|
-
} = newState.schema.nodes;
|
|
84
58
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
action: ACTION.SELECTED,
|
|
93
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
94
|
-
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
95
|
-
eventType: EVENT_TYPE.TRACK,
|
|
96
|
-
attributes: {
|
|
97
|
-
localId: selectedTableOldState.node.attrs.localId || ''
|
|
59
|
+
// When document first load in Confluence, initially it is an empty document
|
|
60
|
+
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
61
|
+
// what we need to do is to add width attr to all tables in the real document
|
|
62
|
+
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
63
|
+
const isReplaceDocumentOperation = transactions.some(tr => {
|
|
64
|
+
if (tr.getMeta('replaceDocument')) {
|
|
65
|
+
return true;
|
|
98
66
|
}
|
|
67
|
+
const hasStepReplacingEntireDocument = tr.steps.some(step => {
|
|
68
|
+
if (!(step instanceof ReplaceStep)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const isStepReplacingFromDocStart = step.from === 0;
|
|
72
|
+
const isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
|
|
73
|
+
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
return hasStepReplacingEntireDocument;
|
|
99
79
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
80
|
+
const referentialityTr = transactions.find(tr => tr.getMeta('referentialityTableInserted'));
|
|
81
|
+
const shouldPatchTable = fullWidthEnabled && getEditorFeatureFlags && getEditorFeatureFlags()['tablePreserveWidth'];
|
|
82
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTable || !referentialityTr)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const {
|
|
86
|
+
table
|
|
87
|
+
} = newState.schema.nodes;
|
|
88
|
+
const tr = newState.tr;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Select table event
|
|
92
|
+
* condition: 2
|
|
93
|
+
* Users selection defaults to table, if first node
|
|
94
|
+
*/
|
|
95
|
+
if (selectedTableOldState) {
|
|
96
|
+
dispatchAnalyticsEvent({
|
|
97
|
+
action: ACTION.SELECTED,
|
|
98
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
99
|
+
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
100
|
+
eventType: EVENT_TYPE.TRACK,
|
|
101
|
+
attributes: {
|
|
102
|
+
localId: selectedTableOldState.node.attrs.localId || ''
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (isReplaceDocumentOperation) {
|
|
107
|
+
newState.doc.forEach((node, offset) => {
|
|
108
|
+
if (node.type === table) {
|
|
109
|
+
const width = node.attrs.width;
|
|
110
|
+
const layout = node.attrs.layout;
|
|
111
|
+
if (!width && layout) {
|
|
112
|
+
let tableWidthCal;
|
|
113
|
+
if (fullWidthEnabled) {
|
|
115
114
|
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
} else {
|
|
116
|
+
switch (layout) {
|
|
117
|
+
case 'wide':
|
|
118
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
119
|
+
break;
|
|
120
|
+
case 'full-width':
|
|
121
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
122
|
+
break;
|
|
123
|
+
// when in fix-width appearance, no need to assign value to table width attr
|
|
124
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
125
|
+
default:
|
|
126
|
+
tableWidthCal = akEditorDefaultLayoutWidth;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const {
|
|
131
|
+
width,
|
|
132
|
+
...rest
|
|
133
|
+
} = node.attrs;
|
|
134
|
+
if (tableWidthCal) {
|
|
135
|
+
tr.step(new SetAttrsStep(offset, {
|
|
136
|
+
width: tableWidthCal,
|
|
137
|
+
...rest
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
122
140
|
}
|
|
123
141
|
}
|
|
124
|
-
|
|
125
|
-
width,
|
|
126
|
-
...rest
|
|
127
|
-
} = node.attrs;
|
|
128
|
-
if (tableWidthCal) {
|
|
129
|
-
tr.step(new SetAttrsStep(offset, {
|
|
130
|
-
width: tableWidthCal,
|
|
131
|
-
...rest
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
142
|
+
});
|
|
135
143
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
144
|
+
if (referentialityTr) {
|
|
145
|
+
referentialityTr.steps.forEach(step => {
|
|
146
|
+
step.getMap().forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
147
|
+
newState.doc.nodesBetween(newStart, newEnd, (node, pos) => {
|
|
148
|
+
if (node.type === table && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
149
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return tr;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
140
159
|
export { createPlugin };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
2
|
+
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
3
|
+
export const createTableWithWidth = (isFullWidthModeEnabled, getEditorFeatureFlags, createTableProps) => schema => {
|
|
4
|
+
const {
|
|
5
|
+
tablePreserveWidth = false
|
|
6
|
+
} = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
|
|
7
|
+
if (tablePreserveWidth && isFullWidthModeEnabled) {
|
|
8
|
+
return createTable({
|
|
9
|
+
schema,
|
|
10
|
+
tableWidth: TABLE_MAX_WIDTH,
|
|
11
|
+
...createTableProps
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return createTable({
|
|
15
|
+
schema,
|
|
16
|
+
...createTableProps
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -8,4 +8,5 @@ export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getR
|
|
|
8
8
|
export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
|
|
9
9
|
export { getMergedCellsPositions } from './table';
|
|
10
10
|
export { updatePluginStateDecorations } from './update-plugin-state-decorations';
|
|
11
|
-
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells } from './merged-cells';
|
|
11
|
+
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells } from './merged-cells';
|
|
12
|
+
export { createTableWithWidth } from './create';
|
|
@@ -4,12 +4,12 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, TABLE_OVERFLOW_C
|
|
|
4
4
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
7
|
-
import { addColumnAt as addColumnAtPMUtils, addRowAt,
|
|
7
|
+
import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
|
|
8
8
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
9
9
|
import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
|
|
10
10
|
import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
11
11
|
import { rescaleColumns } from '../transforms/column-width';
|
|
12
|
-
import { checkIfHeaderRowEnabled, copyPreviousRow } from '../utils';
|
|
12
|
+
import { checkIfHeaderRowEnabled, copyPreviousRow, createTableWithWidth } from '../utils';
|
|
13
13
|
import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
|
|
14
14
|
function addColumnAtCustomStep(column) {
|
|
15
15
|
return function (tr) {
|
|
@@ -80,8 +80,6 @@ export var addColumnAfter = function addColumnAfter(getEditorContainerWidth) {
|
|
|
80
80
|
return true;
|
|
81
81
|
};
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
// #region Commands
|
|
85
83
|
export var insertColumn = function insertColumn(getEditorContainerWidth) {
|
|
86
84
|
return function (column) {
|
|
87
85
|
return function (state, dispatch, view) {
|
|
@@ -134,28 +132,23 @@ export var insertRow = function insertRow(row, moveCursorToTheNewRow) {
|
|
|
134
132
|
return true;
|
|
135
133
|
};
|
|
136
134
|
};
|
|
137
|
-
export var createTable = function createTable() {
|
|
135
|
+
export var createTable = function createTable(isFullWidthModeEnabled, getEditorFeatureFlags) {
|
|
138
136
|
return function (state, dispatch) {
|
|
139
|
-
var table =
|
|
140
|
-
schema: state.schema
|
|
141
|
-
});
|
|
137
|
+
var table = createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags)(state.schema);
|
|
142
138
|
if (dispatch) {
|
|
143
139
|
dispatch(safeInsert(table)(state.tr).scrollIntoView());
|
|
144
140
|
}
|
|
145
141
|
return true;
|
|
146
142
|
};
|
|
147
143
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
export var insertTableWithSize = function insertTableWithSize(editorAnalyticsAPI) {
|
|
144
|
+
export var insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, getEditorFeatureFlags, editorAnalyticsAPI) {
|
|
151
145
|
return function (rowsCount, colsCount, inputMethod) {
|
|
152
146
|
return function (_ref) {
|
|
153
147
|
var tr = _ref.tr;
|
|
154
|
-
var tableNode =
|
|
155
|
-
schema: tr.doc.type.schema,
|
|
148
|
+
var tableNode = createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags, {
|
|
156
149
|
rowsCount: rowsCount,
|
|
157
150
|
colsCount: colsCount
|
|
158
|
-
});
|
|
151
|
+
})(tr.doc.type.schema);
|
|
159
152
|
var newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
160
153
|
if (inputMethod) {
|
|
161
154
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
package/dist/esm/plugin.js
CHANGED
|
@@ -9,7 +9,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
9
9
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
10
10
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
11
11
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
12
|
-
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
13
12
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
13
|
import { insertTableWithSize } from './commands/insert';
|
|
15
14
|
import { pluginConfig } from './create-plugin-config';
|
|
@@ -34,7 +33,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
|
34
33
|
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
35
34
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
36
35
|
import LayoutButton from './ui/LayoutButton';
|
|
37
|
-
import { isLayoutSupported } from './utils';
|
|
36
|
+
import { createTableWithWidth, isLayoutSupported } from './utils';
|
|
38
37
|
var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
39
38
|
return {};
|
|
40
39
|
};
|
|
@@ -59,13 +58,19 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
59
58
|
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
60
59
|
return {
|
|
61
60
|
name: 'table',
|
|
61
|
+
// Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
|
|
62
|
+
// to most up to date values - passing to createPluginState will not re-initialise the state
|
|
63
|
+
getSharedState: function getSharedState() {
|
|
64
|
+
return {
|
|
65
|
+
isFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.fullWidthEnabled),
|
|
66
|
+
wasFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasFullWidthEnabled)
|
|
67
|
+
};
|
|
68
|
+
},
|
|
62
69
|
actions: {
|
|
63
70
|
insertTable: function insertTable(analyticsPayload) {
|
|
64
71
|
return function (state, dispatch) {
|
|
65
72
|
var _api$contentInsertion, _api$contentInsertion2;
|
|
66
|
-
var node =
|
|
67
|
-
schema: state.schema
|
|
68
|
-
});
|
|
73
|
+
var node = createTableWithWidth(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema);
|
|
69
74
|
return (_api$contentInsertion = api === null || api === void 0 || (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 || (_api$contentInsertion2 = _api$contentInsertion2.actions) === null || _api$contentInsertion2 === void 0 ? void 0 : _api$contentInsertion2.insert({
|
|
70
75
|
state: state,
|
|
71
76
|
dispatch: dispatch,
|
|
@@ -79,7 +84,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
79
84
|
}
|
|
80
85
|
},
|
|
81
86
|
commands: {
|
|
82
|
-
insertTableWithSize: insertTableWithSize(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
87
|
+
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
83
88
|
},
|
|
84
89
|
nodes: function nodes() {
|
|
85
90
|
var tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? tableWithCustomWidth : table;
|
|
@@ -201,7 +206,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
201
206
|
var _options$fullWidthEna;
|
|
202
207
|
var dispatchAnalyticsEvent = _ref12.dispatchAnalyticsEvent,
|
|
203
208
|
dispatch = _ref12.dispatch;
|
|
204
|
-
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) : undefined;
|
|
209
|
+
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 === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) : undefined;
|
|
205
210
|
}
|
|
206
211
|
},
|
|
207
212
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -384,9 +389,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
384
389
|
return /*#__PURE__*/React.createElement(IconTable, null);
|
|
385
390
|
},
|
|
386
391
|
action: function action(insert, state) {
|
|
387
|
-
var
|
|
388
|
-
|
|
389
|
-
|
|
392
|
+
var _api$table;
|
|
393
|
+
// see comment on tablesPlugin.getSharedState on usage
|
|
394
|
+
var tableState = api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
395
|
+
var tr = insert(createTableWithWidth(tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema));
|
|
390
396
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
391
397
|
action: ACTION.INSERTED,
|
|
392
398
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -16,8 +16,9 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
16
16
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
17
17
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
18
18
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
19
|
+
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
19
20
|
export var pluginKey = new PluginKey('tableWidthPlugin');
|
|
20
|
-
var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled) {
|
|
21
|
+
var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, getEditorFeatureFlags) {
|
|
21
22
|
return new SafePlugin({
|
|
22
23
|
key: pluginKey,
|
|
23
24
|
state: {
|
|
@@ -59,6 +60,7 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
}
|
|
63
|
+
|
|
62
64
|
// When document first load in Confluence, initially it is an empty document
|
|
63
65
|
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
64
66
|
// what we need to do is to add width attr to all tables in the real document
|
|
@@ -80,11 +82,15 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
80
82
|
});
|
|
81
83
|
return hasStepReplacingEntireDocument;
|
|
82
84
|
});
|
|
83
|
-
|
|
85
|
+
var referentialityTr = transactions.find(function (tr) {
|
|
86
|
+
return tr.getMeta('referentialityTableInserted');
|
|
87
|
+
});
|
|
88
|
+
var shouldPatchTable = fullWidthEnabled && getEditorFeatureFlags && getEditorFeatureFlags()['tablePreserveWidth'];
|
|
89
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTable || !referentialityTr)) {
|
|
84
90
|
return null;
|
|
85
91
|
}
|
|
86
|
-
var tr = newState.tr;
|
|
87
92
|
var table = newState.schema.nodes.table;
|
|
93
|
+
var tr = newState.tr;
|
|
88
94
|
|
|
89
95
|
/**
|
|
90
96
|
* Select table event
|
|
@@ -102,40 +108,53 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
102
108
|
}
|
|
103
109
|
});
|
|
104
110
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
if (isReplaceDocumentOperation) {
|
|
112
|
+
newState.doc.forEach(function (node, offset) {
|
|
113
|
+
if (node.type === table) {
|
|
114
|
+
var width = node.attrs.width;
|
|
115
|
+
var layout = node.attrs.layout;
|
|
116
|
+
if (!width && layout) {
|
|
117
|
+
var tableWidthCal;
|
|
118
|
+
if (fullWidthEnabled) {
|
|
119
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
120
|
+
} else {
|
|
121
|
+
switch (layout) {
|
|
122
|
+
case 'wide':
|
|
123
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
124
|
+
break;
|
|
125
|
+
case 'full-width':
|
|
126
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
127
|
+
break;
|
|
128
|
+
// when in fix-width appearance, no need to assign value to table width attr
|
|
129
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
130
|
+
default:
|
|
131
|
+
tableWidthCal = akEditorDefaultLayoutWidth;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
var _node$attrs = node.attrs,
|
|
136
|
+
_width = _node$attrs.width,
|
|
137
|
+
rest = _objectWithoutProperties(_node$attrs, _excluded);
|
|
138
|
+
if (tableWidthCal) {
|
|
139
|
+
tr.step(new SetAttrsStep(offset, _objectSpread({
|
|
140
|
+
width: tableWidthCal
|
|
141
|
+
}, rest)));
|
|
126
142
|
}
|
|
127
|
-
}
|
|
128
|
-
var _node$attrs = node.attrs,
|
|
129
|
-
_width = _node$attrs.width,
|
|
130
|
-
rest = _objectWithoutProperties(_node$attrs, _excluded);
|
|
131
|
-
if (tableWidthCal) {
|
|
132
|
-
tr.step(new SetAttrsStep(offset, _objectSpread({
|
|
133
|
-
width: tableWidthCal
|
|
134
|
-
}, rest)));
|
|
135
143
|
}
|
|
136
144
|
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (referentialityTr) {
|
|
148
|
+
referentialityTr.steps.forEach(function (step) {
|
|
149
|
+
step.getMap().forEach(function (oldStart, oldEnd, newStart, newEnd) {
|
|
150
|
+
newState.doc.nodesBetween(newStart, newEnd, function (node, pos) {
|
|
151
|
+
if (node.type === table && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
152
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
139
158
|
return tr;
|
|
140
159
|
}
|
|
141
160
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { createTable } from '@atlaskit/editor-tables/utils';
|
|
5
|
+
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
6
|
+
export var createTableWithWidth = function createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags, createTableProps) {
|
|
7
|
+
return function (schema) {
|
|
8
|
+
var _ref = getEditorFeatureFlags ? getEditorFeatureFlags() : {},
|
|
9
|
+
_ref$tablePreserveWid = _ref.tablePreserveWidth,
|
|
10
|
+
tablePreserveWidth = _ref$tablePreserveWid === void 0 ? false : _ref$tablePreserveWid;
|
|
11
|
+
if (tablePreserveWidth && isFullWidthModeEnabled) {
|
|
12
|
+
return createTable(_objectSpread({
|
|
13
|
+
schema: schema,
|
|
14
|
+
tableWidth: TABLE_MAX_WIDTH
|
|
15
|
+
}, createTableProps));
|
|
16
|
+
}
|
|
17
|
+
return createTable(_objectSpread({
|
|
18
|
+
schema: schema
|
|
19
|
+
}, createTableProps));
|
|
20
|
+
};
|
|
21
|
+
};
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -8,4 +8,5 @@ export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getR
|
|
|
8
8
|
export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
|
|
9
9
|
export { getMergedCellsPositions } from './table';
|
|
10
10
|
export { updatePluginStateDecorations } from './update-plugin-state-decorations';
|
|
11
|
-
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells } from './merged-cells';
|
|
11
|
+
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells } from './merged-cells';
|
|
12
|
+
export { createTableWithWidth } from './create';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import type { Command, EditorCommand, GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Command, EditorCommand, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
export declare function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth): (column: number, allowAddColumnCustomStep: boolean | undefined, view: EditorView | undefined) => (tr: Transaction) => Transaction;
|
|
@@ -7,5 +7,5 @@ export declare const addColumnBefore: (getEditorContainerWidth: GetEditorContain
|
|
|
7
7
|
export declare const addColumnAfter: (getEditorContainerWidth: GetEditorContainerWidth) => Command;
|
|
8
8
|
export declare const insertColumn: (getEditorContainerWidth: GetEditorContainerWidth) => (column: number) => Command;
|
|
9
9
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean) => Command;
|
|
10
|
-
export declare const createTable: () => Command;
|
|
11
|
-
export declare const insertTableWithSize: (editorAnalyticsAPI
|
|
10
|
+
export declare const createTable: (isFullWidthModeEnabled?: boolean, getEditorFeatureFlags?: GetEditorFeatureFlags) => Command;
|
|
11
|
+
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, getEditorFeatureFlags?: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export type TablePlugin = NextEditorPlugin<'table', {
|
|
|
23
23
|
actions: {
|
|
24
24
|
insertTable: InsertTableAction;
|
|
25
25
|
};
|
|
26
|
+
sharedState: {
|
|
27
|
+
isFullWidthModeEnabled: boolean;
|
|
28
|
+
wasFullWidthModeEnabled: boolean;
|
|
29
|
+
};
|
|
26
30
|
commands: {
|
|
27
31
|
insertTableWithSize: (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
28
32
|
};
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
7
7
|
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
8
8
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
|
+
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
9
10
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
10
11
|
type TableWidthPluginState = {
|
|
11
12
|
resizing: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
14
|
-
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean) => SafePlugin<{
|
|
15
|
+
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, getEditorFeatureFlags?: GetEditorFeatureFlags) => SafePlugin<{
|
|
15
16
|
resizing: boolean;
|
|
16
17
|
}>;
|
|
17
18
|
export { createPlugin };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
export declare const createTableWithWidth: (isFullWidthModeEnabled?: boolean, getEditorFeatureFlags?: GetEditorFeatureFlags, createTableProps?: {
|
|
4
|
+
rowsCount?: number;
|
|
5
|
+
colsCount?: number;
|
|
6
|
+
}) => (schema: Schema) => import("prosemirror-model").Node;
|
|
@@ -10,3 +10,4 @@ export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
|
|
|
10
10
|
export { getMergedCellsPositions } from './table';
|
|
11
11
|
export { updatePluginStateDecorations } from './update-plugin-state-decorations';
|
|
12
12
|
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells, } from './merged-cells';
|
|
13
|
+
export { createTableWithWidth } from './create';
|