@atlaskit/editor-plugin-table 1.2.4 → 1.2.6
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 +14 -0
- package/dist/cjs/plugins/table/commands/selection.js +4 -4
- package/dist/cjs/plugins/table/event-handlers.js +3 -3
- package/dist/cjs/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -6
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +9 -16
- package/dist/cjs/plugins/table/pm-plugins/table-local-id.js +65 -37
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
- package/dist/cjs/plugins/table/transforms/delete-rows.js +2 -2
- package/dist/cjs/plugins/table/types.js +8 -8
- package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +2 -0
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +6 -7
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/commands/selection.js +3 -3
- package/dist/es2019/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -7
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +8 -14
- package/dist/es2019/plugins/table/pm-plugins/table-local-id.js +47 -38
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
- package/dist/es2019/plugins/table/types.js +6 -6
- package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +2 -0
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +6 -8
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/commands/selection.js +3 -3
- package/dist/esm/plugins/table/event-handlers.js +3 -3
- package/dist/esm/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -6
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +9 -16
- package/dist/esm/plugins/table/pm-plugins/table-local-id.js +66 -38
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
- package/dist/esm/plugins/table/transforms/delete-rows.js +2 -2
- package/dist/esm/plugins/table/types.js +6 -6
- package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +2 -0
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +6 -7
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +1 -1
- package/dist/esm/version.json +1 -1
- package/package.json +6 -5
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +2 -14
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +2 -2
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +2 -2
- package/src/__tests__/visual-regression/sticky-header.ts +1 -2
- package/src/plugins/table/pm-plugins/table-local-id.ts +57 -41
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@atlaskit/adf-schema": "^25.5.0",
|
|
22
|
-
"@atlaskit/editor-common": "^
|
|
22
|
+
"@atlaskit/editor-common": "^73.0.0",
|
|
23
|
+
"@atlaskit/editor-palette": "1.3.0",
|
|
23
24
|
"@atlaskit/editor-shared-styles": "^2.3.0",
|
|
24
25
|
"@atlaskit/editor-tables": "^2.2.0",
|
|
25
26
|
"@atlaskit/icon": "^21.11.0",
|
|
@@ -51,11 +52,11 @@
|
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@atlaskit/analytics-next": "^9.0.0",
|
|
53
54
|
"@atlaskit/button": "^16.6.0",
|
|
54
|
-
"@atlaskit/editor-core": "^182.
|
|
55
|
-
"@atlaskit/editor-plugin-feature-flags": "^0.0.
|
|
55
|
+
"@atlaskit/editor-core": "^182.2.0",
|
|
56
|
+
"@atlaskit/editor-plugin-feature-flags": "^0.0.4",
|
|
56
57
|
"@atlaskit/editor-test-helpers": "^18.2.0",
|
|
57
58
|
"@atlaskit/link-provider": "^1.5.0",
|
|
58
|
-
"@atlaskit/logo": "^13.
|
|
59
|
+
"@atlaskit/logo": "^13.13.0",
|
|
59
60
|
"@atlaskit/media-integration-test-helpers": "^2.6.0",
|
|
60
61
|
"@atlaskit/synchrony-test-helpers": "^2.3.0",
|
|
61
62
|
"@atlaskit/util-data-test": "^17.7.0",
|
|
@@ -347,23 +347,11 @@ describe('table local id plugin', () => {
|
|
|
347
347
|
editorView.updateState(state3);
|
|
348
348
|
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
349
349
|
|
|
350
|
-
/**
|
|
351
|
-
* The end result order of IDs that we'll now observe is the following:
|
|
352
|
-
* 1. flooFirst
|
|
353
|
-
* 2. flooThird
|
|
354
|
-
* 3. flooSecond
|
|
355
|
-
*
|
|
356
|
-
* This is because we had `flooFirst` in our clipboard. We've now pasted
|
|
357
|
-
* it into the expand, so that becomes the first observed instance of
|
|
358
|
-
* the table. The "third" ID (second unique regeneration) then gets
|
|
359
|
-
* replaced in the first layout column.
|
|
360
|
-
*
|
|
361
|
-
*/
|
|
362
350
|
expect(editorView.state.doc).toEqualDocument(
|
|
363
351
|
doc(
|
|
364
|
-
expand({ title: '' })(generateTableWithLocalId(
|
|
352
|
+
expand({ title: '' })(generateTableWithLocalId(flooThird)),
|
|
365
353
|
layoutSection(
|
|
366
|
-
layoutColumn({ width: 50 })(generateTableWithLocalId(
|
|
354
|
+
layoutColumn({ width: 50 })(generateTableWithLocalId(flooFirst)),
|
|
367
355
|
layoutColumn({ width: 50 })(generateTableWithLocalId(flooSecond)),
|
|
368
356
|
),
|
|
369
357
|
p(),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
version https://git-lfs.github.com/spec/v1
|
|
2
|
-
oid sha256:
|
|
3
|
-
size
|
|
2
|
+
oid sha256:7e4711c029f049a837051d496f231798f2242062e12e31917fa6ea29e6b8c642
|
|
3
|
+
size 20453
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
version https://git-lfs.github.com/spec/v1
|
|
2
|
-
oid sha256:
|
|
3
|
-
size
|
|
2
|
+
oid sha256:a063075cc5504c85ba5809ece337a3a687f58a74fdb9e2b820e8ab6d234b8dd7
|
|
3
|
+
size 19687
|
|
@@ -38,8 +38,7 @@ describe('Snapshot Test: Table', () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
describe('sticky header', () => {
|
|
41
|
-
|
|
42
|
-
it.skip('should align with table cell when active', async () => {
|
|
41
|
+
it('should align with table cell when active', async () => {
|
|
43
42
|
await initEditor(page, stickyHeaderWithHorizontalScroll);
|
|
44
43
|
|
|
45
44
|
await clickFirstCell(page, true);
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
14
14
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
15
|
-
import { EditorState, PluginKey
|
|
16
|
-
import {
|
|
15
|
+
import { EditorState, PluginKey } from 'prosemirror-state';
|
|
16
|
+
import { Node as ProsemirrorNode } from 'prosemirror-model';
|
|
17
17
|
import rafSchedule from 'raf-schd';
|
|
18
18
|
|
|
19
19
|
import { uuid } from '@atlaskit/adf-schema';
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import { stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
22
22
|
|
|
23
23
|
interface TableLocalIdPluginState {
|
|
24
24
|
// One time parse for initial load with existing tables without localIds
|
|
@@ -31,15 +31,6 @@ const getPluginState = (
|
|
|
31
31
|
): TableLocalIdPluginState | undefined | null =>
|
|
32
32
|
state && pluginKey.getState(state);
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Traverses a transaction's steps to see if we're inserting any tables
|
|
36
|
-
*/
|
|
37
|
-
const checkIsAddingTable = (transaction: Transaction, nodeType: NodeType) => {
|
|
38
|
-
return transaction.steps.some((step) =>
|
|
39
|
-
stepAddsOneOf(step, new Set([nodeType])),
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
34
|
/**
|
|
44
35
|
* Ensures uniqueness of `localId`s on tables being created or edited
|
|
45
36
|
*/
|
|
@@ -143,7 +134,9 @@ const createPlugin = (dispatch: Dispatch) =>
|
|
|
143
134
|
const tr = newState.tr;
|
|
144
135
|
const { table } = newState.schema.nodes;
|
|
145
136
|
|
|
146
|
-
const
|
|
137
|
+
const addedTableNodes: Set<ProsemirrorNode> = new Set();
|
|
138
|
+
const addedTableNodePos: Map<ProsemirrorNode, number> = new Map();
|
|
139
|
+
const localIds: Set<string> = new Set();
|
|
147
140
|
|
|
148
141
|
transactions.forEach((transaction) => {
|
|
149
142
|
if (!transaction.docChanged) {
|
|
@@ -157,43 +150,66 @@ const createPlugin = (dispatch: Dispatch) =>
|
|
|
157
150
|
return;
|
|
158
151
|
}
|
|
159
152
|
|
|
160
|
-
/**
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
/** Get the tables we are adding and their position */
|
|
154
|
+
for (const step of transaction.steps) {
|
|
155
|
+
if (!stepHasSlice(step)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
165
158
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const localId = node.attrs.localId;
|
|
170
|
-
|
|
171
|
-
// Dealing with a table - make sure it's a unique ID
|
|
172
|
-
if (isTable) {
|
|
173
|
-
if (localId && !idsObserved.has(localId)) {
|
|
174
|
-
idsObserved.add(localId);
|
|
175
|
-
// Also add a localId if it happens to not have one,
|
|
176
|
-
} else if (!localId || idsObserved.has(localId)) {
|
|
177
|
-
modified = true;
|
|
178
|
-
tr.setNodeMarkup(pos, undefined, {
|
|
179
|
-
...node.attrs,
|
|
180
|
-
localId: uuid.generate(),
|
|
181
|
-
});
|
|
159
|
+
step.slice.content.descendants((node, pos) => {
|
|
160
|
+
if (node.type === table) {
|
|
161
|
+
addedTableNodes.add(node);
|
|
182
162
|
}
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
163
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (!addedTableNodes.size) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Get the existing localIds on the page
|
|
174
|
+
newState.doc.descendants((node, pos) => {
|
|
175
|
+
// Skip if this is position of added table
|
|
176
|
+
if (addedTableNodes.has(node)) {
|
|
177
|
+
addedTableNodePos.set(node, pos);
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (node.type !== table) {
|
|
190
182
|
return true;
|
|
191
|
-
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
localIds.add(node.attrs.localId);
|
|
186
|
+
|
|
187
|
+
// can't have table within a table
|
|
188
|
+
return false;
|
|
192
189
|
});
|
|
193
190
|
|
|
191
|
+
// If the added nodes have duplicate id, generate a new one
|
|
192
|
+
for (const node of addedTableNodes) {
|
|
193
|
+
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
194
|
+
const pos = addedTableNodePos.get(node);
|
|
195
|
+
|
|
196
|
+
if (pos === undefined) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
201
|
+
...node.attrs,
|
|
202
|
+
localId: uuid.generate(),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
modified = true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
194
209
|
if (modified) {
|
|
195
210
|
return tr;
|
|
196
211
|
}
|
|
212
|
+
|
|
197
213
|
return;
|
|
198
214
|
},
|
|
199
215
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Component } from 'react';
|
|
3
3
|
import { jsx } from '@emotion/react';
|
|
4
4
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
5
|
+
import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
|
|
5
6
|
import { splitCell } from '@atlaskit/editor-tables/utils';
|
|
6
7
|
import { EditorView } from 'prosemirror-view';
|
|
7
8
|
import {
|
|
@@ -252,6 +253,7 @@ export class ContextualMenu extends Component<
|
|
|
252
253
|
palette: cellBackgroundColorPalette,
|
|
253
254
|
paletteColorTooltipMessages:
|
|
254
255
|
backgroundPaletteTooltipMessages,
|
|
256
|
+
hexToPaletteColor: hexToEditorBackgroundPaletteColor,
|
|
255
257
|
// We did not want to create new FF or update
|
|
256
258
|
// useSomewhatSemanticTextColorNames name
|
|
257
259
|
// because it is temporary and require extra work.
|