@atlaskit/editor-plugin-table 2.0.0 → 2.1.0
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/plugins/table/nodeviews/TableComponent.js +7 -3
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +23 -19
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +2 -1
- package/dist/cjs/plugins/table/nodeviews/table.js +5 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +7 -3
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +22 -18
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +3 -2
- package/dist/es2019/plugins/table/nodeviews/table.js +5 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +7 -3
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +23 -19
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +3 -2
- package/dist/esm/plugins/table/nodeviews/table.js +5 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +5 -3
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +5 -3
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +2 -1
- package/package.json +4 -7
- package/src/__tests__/integration/layout.ts +1 -6
- package/src/__tests__/unit/analytics.ts +0 -21
- package/src/__tests__/unit/commands/misc.ts +0 -2
- package/src/__tests__/unit/commands/sort.ts +0 -131
- package/src/__tests__/unit/commands.ts +2 -264
- package/src/__tests__/unit/copy-paste.ts +1 -36
- package/src/__tests__/unit/event-handlers.ts +1 -113
- package/src/__tests__/unit/get-toolbar-config.ts +0 -29
- package/src/__tests__/unit/index.ts +3 -101
- package/src/__tests__/unit/layout.ts +1 -64
- package/src/__tests__/unit/nodeviews/cell.ts +1 -48
- package/src/__tests__/unit/pm-plugins/main.ts +1 -3
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +2 -20
- package/src/__tests__/unit/sort-column.ts +21 -148
- package/src/__tests__/unit/utils/collapse.ts +3 -39
- package/src/plugins/table/nodeviews/TableComponent.tsx +10 -4
- package/src/plugins/table/nodeviews/TableContainer.tsx +28 -19
- package/src/plugins/table/nodeviews/TableResizer.tsx +3 -2
- package/src/plugins/table/nodeviews/table.tsx +6 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +10 -1
- package/.eslintrc.js +0 -37
- package/src/__tests__/unit/color-picker.ts +0 -110
- package/src/__tests__/unit/floating-toolbar.ts +0 -95
- package/src/__tests__/unit/keymap.ts +0 -609
- package/src/__tests__/unit/pm-plugins/main-with-allow-collapse.ts +0 -110
- package/src/__tests__/unit/pm-plugins/table-selection-keymap.ts +0 -574
|
@@ -7,11 +7,9 @@ import {
|
|
|
7
7
|
doc,
|
|
8
8
|
p,
|
|
9
9
|
table,
|
|
10
|
-
h1,
|
|
11
10
|
tr,
|
|
12
11
|
td,
|
|
13
12
|
th,
|
|
14
|
-
strong,
|
|
15
13
|
DocBuilder,
|
|
16
14
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
17
15
|
import {
|
|
@@ -20,8 +18,6 @@ import {
|
|
|
20
18
|
} from '../../plugins/table/types';
|
|
21
19
|
import { uuid } from '@atlaskit/adf-schema';
|
|
22
20
|
import { TableSortOrder as SortOrder } from '@atlaskit/adf-schema/steps';
|
|
23
|
-
import textFormattingPlugin from '@atlaskit/editor-core/src/plugins/text-formatting';
|
|
24
|
-
import blockTypePlugin from '@atlaskit/editor-core/src/plugins/block-type';
|
|
25
21
|
import { sortByColumn } from '../../plugins/table/commands';
|
|
26
22
|
import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
27
23
|
import tablePlugin from '../../plugins/table-plugin';
|
|
@@ -56,9 +52,7 @@ describe('table plugin', () => {
|
|
|
56
52
|
.add([analyticsPlugin, {}])
|
|
57
53
|
.add(contentInsertionPlugin)
|
|
58
54
|
.add(widthPlugin)
|
|
59
|
-
.add([tablePlugin, { tableOptions }])
|
|
60
|
-
.add(textFormattingPlugin)
|
|
61
|
-
.add(blockTypePlugin);
|
|
55
|
+
.add([tablePlugin, { tableOptions }]);
|
|
62
56
|
|
|
63
57
|
const editor = (doc: DocBuilder) => {
|
|
64
58
|
return createEditor<TablePluginState, PluginKey>({
|
|
@@ -75,11 +69,11 @@ describe('table plugin', () => {
|
|
|
75
69
|
doc(
|
|
76
70
|
table({ isNumberColumnEnabled: false, layout: 'default' })(
|
|
77
71
|
tr(
|
|
78
|
-
th({})(p(
|
|
79
|
-
th({})(p(
|
|
80
|
-
th({})(p(
|
|
81
|
-
th({})(p(
|
|
82
|
-
th({})(p(
|
|
72
|
+
th({})(p('1')),
|
|
73
|
+
th({})(p('2')),
|
|
74
|
+
th({})(p('3')),
|
|
75
|
+
th({})(p('4')),
|
|
76
|
+
th({})(p('5')),
|
|
83
77
|
),
|
|
84
78
|
tr(
|
|
85
79
|
td({})(p('c')),
|
|
@@ -139,11 +133,11 @@ describe('table plugin', () => {
|
|
|
139
133
|
localId: TABLE_LOCAL_ID,
|
|
140
134
|
})(
|
|
141
135
|
tr(
|
|
142
|
-
th({})(p(
|
|
143
|
-
th({})(p(
|
|
144
|
-
th({})(p(
|
|
145
|
-
th({})(p(
|
|
146
|
-
th({})(p(
|
|
136
|
+
th({})(p('1')),
|
|
137
|
+
th({})(p('2')),
|
|
138
|
+
th({})(p('3')),
|
|
139
|
+
th({})(p('4')),
|
|
140
|
+
th({})(p('5')),
|
|
147
141
|
),
|
|
148
142
|
tr(
|
|
149
143
|
td({})(p('1')),
|
|
@@ -196,11 +190,11 @@ describe('table plugin', () => {
|
|
|
196
190
|
doc(
|
|
197
191
|
table({ isNumberColumnEnabled: false, layout: 'default' })(
|
|
198
192
|
tr(
|
|
199
|
-
th({})(p(
|
|
200
|
-
th({})(p(
|
|
201
|
-
th({})(p(
|
|
202
|
-
th({})(p(
|
|
203
|
-
th({})(p(
|
|
193
|
+
th({})(p('1')),
|
|
194
|
+
th({})(p('2')),
|
|
195
|
+
th({})(p('3')),
|
|
196
|
+
th({})(p('4')),
|
|
197
|
+
th({})(p('5')),
|
|
204
198
|
),
|
|
205
199
|
tr(
|
|
206
200
|
td({})(p('c')),
|
|
@@ -260,11 +254,11 @@ describe('table plugin', () => {
|
|
|
260
254
|
localId: TABLE_LOCAL_ID,
|
|
261
255
|
})(
|
|
262
256
|
tr(
|
|
263
|
-
th({})(p(
|
|
264
|
-
th({})(p(
|
|
265
|
-
th({})(p(
|
|
266
|
-
th({})(p(
|
|
267
|
-
th({})(p(
|
|
257
|
+
th({})(p('1')),
|
|
258
|
+
th({})(p('2')),
|
|
259
|
+
th({})(p('3')),
|
|
260
|
+
th({})(p('4')),
|
|
261
|
+
th({})(p('5')),
|
|
268
262
|
),
|
|
269
263
|
tr(
|
|
270
264
|
td({})(p('c')),
|
|
@@ -312,127 +306,6 @@ describe('table plugin', () => {
|
|
|
312
306
|
),
|
|
313
307
|
);
|
|
314
308
|
});
|
|
315
|
-
it('sorts the given column with header text in ascending order', () => {
|
|
316
|
-
const { editorView } = editor(
|
|
317
|
-
doc(
|
|
318
|
-
table({ isNumberColumnEnabled: false, layout: 'default' })(
|
|
319
|
-
tr(
|
|
320
|
-
th({})(h1(strong('asdasdasd'))),
|
|
321
|
-
th({})(p(strong('asdasd'))),
|
|
322
|
-
th({})(p(strong('sdfsdf'))),
|
|
323
|
-
th({})(p('sdfsdfsdf')),
|
|
324
|
-
th({})(p(strong('asdasda'))),
|
|
325
|
-
),
|
|
326
|
-
tr(
|
|
327
|
-
td({})(h1(strong('c'))),
|
|
328
|
-
td({})(p('cda')),
|
|
329
|
-
td({})(p()),
|
|
330
|
-
td({})(p('cz')),
|
|
331
|
-
td({})(p()),
|
|
332
|
-
),
|
|
333
|
-
tr(
|
|
334
|
-
td({})(h1(strong('b'))),
|
|
335
|
-
td({})(p()),
|
|
336
|
-
td({})(p('dfsf')),
|
|
337
|
-
td({})(p()),
|
|
338
|
-
td({})(p('cvsd')),
|
|
339
|
-
),
|
|
340
|
-
tr(
|
|
341
|
-
td({})(p(strong('a'))),
|
|
342
|
-
td({})(p('zc')),
|
|
343
|
-
td({})(p()),
|
|
344
|
-
td({})(p()),
|
|
345
|
-
td({})(p('fsdf')),
|
|
346
|
-
),
|
|
347
|
-
tr(
|
|
348
|
-
td({})(p(strong('2'))),
|
|
349
|
-
td({})(p()),
|
|
350
|
-
td({})(p()),
|
|
351
|
-
td({})(p()),
|
|
352
|
-
td({})(p()),
|
|
353
|
-
),
|
|
354
|
-
tr(
|
|
355
|
-
td({})(p(strong('1'))),
|
|
356
|
-
td({})(p()),
|
|
357
|
-
td({})(p('cxzcz')),
|
|
358
|
-
td({})(p()),
|
|
359
|
-
td({})(p()),
|
|
360
|
-
),
|
|
361
|
-
tr(
|
|
362
|
-
td({})(p()),
|
|
363
|
-
td({})(p()),
|
|
364
|
-
td({})(p()),
|
|
365
|
-
td({})(p('sdfs')),
|
|
366
|
-
td({})(p()),
|
|
367
|
-
),
|
|
368
|
-
),
|
|
369
|
-
),
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
const sortByColumnCommand = sortByColumn(0, SortOrder.ASC);
|
|
373
|
-
|
|
374
|
-
sortByColumnCommand(editorView.state, editorView.dispatch);
|
|
375
|
-
|
|
376
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
377
|
-
doc(
|
|
378
|
-
table({
|
|
379
|
-
isNumberColumnEnabled: false,
|
|
380
|
-
layout: 'default',
|
|
381
|
-
localId: TABLE_LOCAL_ID,
|
|
382
|
-
})(
|
|
383
|
-
tr(
|
|
384
|
-
th({})(h1(strong('asdasdasd'))),
|
|
385
|
-
th({})(p(strong('asdasd'))),
|
|
386
|
-
th({})(p(strong('sdfsdf'))),
|
|
387
|
-
th({})(p('sdfsdfsdf')),
|
|
388
|
-
th({})(p(strong('asdasda'))),
|
|
389
|
-
),
|
|
390
|
-
tr(
|
|
391
|
-
td({})(p(strong('1'))),
|
|
392
|
-
td({})(p()),
|
|
393
|
-
td({})(p('cxzcz')),
|
|
394
|
-
td({})(p()),
|
|
395
|
-
td({})(p()),
|
|
396
|
-
),
|
|
397
|
-
tr(
|
|
398
|
-
td({})(p(strong('2'))),
|
|
399
|
-
td({})(p()),
|
|
400
|
-
td({})(p()),
|
|
401
|
-
td({})(p()),
|
|
402
|
-
td({})(p()),
|
|
403
|
-
),
|
|
404
|
-
tr(
|
|
405
|
-
td({})(p(strong('a'))),
|
|
406
|
-
td({})(p('zc')),
|
|
407
|
-
td({})(p()),
|
|
408
|
-
td({})(p()),
|
|
409
|
-
td({})(p('fsdf')),
|
|
410
|
-
),
|
|
411
|
-
tr(
|
|
412
|
-
td({})(h1(strong('b'))),
|
|
413
|
-
td({})(p()),
|
|
414
|
-
td({})(p('dfsf')),
|
|
415
|
-
td({})(p()),
|
|
416
|
-
td({})(p('cvsd')),
|
|
417
|
-
),
|
|
418
|
-
tr(
|
|
419
|
-
td({})(h1(strong('c'))),
|
|
420
|
-
td({})(p('cda')),
|
|
421
|
-
td({})(p()),
|
|
422
|
-
td({})(p('cz')),
|
|
423
|
-
td({})(p()),
|
|
424
|
-
),
|
|
425
|
-
tr(
|
|
426
|
-
td({})(p()),
|
|
427
|
-
td({})(p()),
|
|
428
|
-
td({})(p()),
|
|
429
|
-
td({})(p('sdfs')),
|
|
430
|
-
td({})(p()),
|
|
431
|
-
),
|
|
432
|
-
),
|
|
433
|
-
),
|
|
434
|
-
);
|
|
435
|
-
});
|
|
436
309
|
|
|
437
310
|
describe('case sensitivity', () => {
|
|
438
311
|
describe('ascending order', () => {
|
|
@@ -12,22 +12,17 @@ import {
|
|
|
12
12
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
13
13
|
|
|
14
14
|
import tablePlugin from '../../../plugins/table';
|
|
15
|
-
import expandPlugin from '@atlaskit/editor-core/src/plugins/expand';
|
|
16
15
|
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
17
16
|
|
|
18
|
-
import {
|
|
19
|
-
isTableCollapsible,
|
|
20
|
-
collapseSelectedTable,
|
|
21
|
-
} from '../../../plugins/table/utils/collapse';
|
|
17
|
+
import { isTableCollapsible } from '../../../plugins/table/utils/collapse';
|
|
22
18
|
import featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
|
|
23
19
|
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
24
20
|
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
25
|
-
import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
26
21
|
|
|
27
22
|
describe('collapse', () => {
|
|
28
23
|
const createEditor = createProsemirrorEditorFactory();
|
|
29
24
|
|
|
30
|
-
const editor = (doc: DocBuilder
|
|
25
|
+
const editor = (doc: DocBuilder) => {
|
|
31
26
|
const preset = new Preset<LightEditorPlugin>()
|
|
32
27
|
.add([featureFlagsPlugin, {}])
|
|
33
28
|
.add([analyticsPlugin, {}])
|
|
@@ -35,11 +30,7 @@ describe('collapse', () => {
|
|
|
35
30
|
.add(widthPlugin)
|
|
36
31
|
.add(tablePlugin);
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
? preset.add(decorationsPlugin).add(expandPlugin)
|
|
40
|
-
: preset;
|
|
41
|
-
|
|
42
|
-
return createEditor({ doc, preset: finalPreset });
|
|
33
|
+
return createEditor({ doc, preset });
|
|
43
34
|
};
|
|
44
35
|
|
|
45
36
|
describe('isTableCollapsible', () => {
|
|
@@ -55,32 +46,5 @@ describe('collapse', () => {
|
|
|
55
46
|
expect(newTr.steps.length).toEqual(0);
|
|
56
47
|
expect(isTableCollapsibleRes.tableIsCollapsible).toEqual(false);
|
|
57
48
|
});
|
|
58
|
-
|
|
59
|
-
it('should allow collapsing a table when expands are in schema', () => {
|
|
60
|
-
const editorData = editor(doc(table()(tr(tdEmpty, tdEmpty))), true);
|
|
61
|
-
const editorView = editorData.editorView;
|
|
62
|
-
const newTr = editorView.state.tr;
|
|
63
|
-
|
|
64
|
-
expect(newTr.steps.length).toEqual(0);
|
|
65
|
-
|
|
66
|
-
const isTableCollapsibleRes = isTableCollapsible(newTr);
|
|
67
|
-
|
|
68
|
-
expect(newTr.steps.length).toEqual(0);
|
|
69
|
-
expect(isTableCollapsibleRes.tableIsCollapsible).toEqual(true);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('collapseSelectedTable', () => {
|
|
74
|
-
it('should add steps to tr when called', () => {
|
|
75
|
-
const editorData = editor(doc(table()(tr(tdEmpty, tdEmpty))), true);
|
|
76
|
-
const editorView = editorData.editorView;
|
|
77
|
-
const newTr = editorView.state.tr;
|
|
78
|
-
|
|
79
|
-
expect(newTr.steps.length).toEqual(0);
|
|
80
|
-
|
|
81
|
-
const collapseTr = collapseSelectedTable(newTr);
|
|
82
|
-
expect(collapseTr).toBeDefined();
|
|
83
|
-
expect(collapseTr!.steps.length).toEqual(1);
|
|
84
|
-
});
|
|
85
49
|
});
|
|
86
50
|
});
|
|
@@ -48,7 +48,6 @@ import {
|
|
|
48
48
|
import type { TableOptions } from './types';
|
|
49
49
|
import { updateOverflowShadows } from './update-overflow-shadows';
|
|
50
50
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
51
|
-
|
|
52
51
|
import memoizeOne from 'memoize-one';
|
|
53
52
|
import { OverflowShadowsObserver } from './OverflowShadowsObserver';
|
|
54
53
|
import { TableContainer } from './TableContainer';
|
|
@@ -151,7 +150,9 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
151
150
|
* We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
|
|
152
151
|
* Instead we use the resize event to only trigger updates when necessary.
|
|
153
152
|
*/
|
|
154
|
-
|
|
153
|
+
if (!getBooleanFF('platform.editor.custom-table-width')) {
|
|
154
|
+
window.addEventListener('resize', this.handleWindowResizeDebounced);
|
|
155
|
+
}
|
|
155
156
|
this.handleTableResizingDebounced();
|
|
156
157
|
}
|
|
157
158
|
|
|
@@ -175,9 +176,14 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
175
176
|
this.scaleTableDebounced.cancel();
|
|
176
177
|
this.handleTableResizingDebounced.cancel();
|
|
177
178
|
this.handleAutoSizeDebounced.cancel();
|
|
178
|
-
|
|
179
|
+
if (!getBooleanFF('platform.editor.custom-table-width')) {
|
|
180
|
+
this.handleWindowResizeDebounced.cancel();
|
|
181
|
+
}
|
|
179
182
|
|
|
180
|
-
if (
|
|
183
|
+
if (
|
|
184
|
+
!getBooleanFF('platform.editor.custom-table-width') &&
|
|
185
|
+
this.props.allowColumnResizing
|
|
186
|
+
) {
|
|
181
187
|
window.removeEventListener('resize', this.handleWindowResizeDebounced);
|
|
182
188
|
}
|
|
183
189
|
|
|
@@ -14,6 +14,7 @@ import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
|
14
14
|
|
|
15
15
|
import { TableCssClassName as ClassName } from '../types';
|
|
16
16
|
import { TableResizer } from './TableResizer';
|
|
17
|
+
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
17
18
|
|
|
18
19
|
interface GetMarginLeftOpts {
|
|
19
20
|
lineLength: number;
|
|
@@ -35,22 +36,21 @@ const getMarginLeft = ({ lineLength, tableWidth }: GetMarginLeftOpts) => {
|
|
|
35
36
|
|
|
36
37
|
type InnerContainerProps = {
|
|
37
38
|
className: string;
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
style?: {
|
|
40
|
+
width: number | 'inherit';
|
|
41
|
+
marginLeft: number | undefined;
|
|
42
|
+
};
|
|
40
43
|
node: PMNode;
|
|
41
44
|
};
|
|
42
45
|
|
|
43
46
|
export const InnerContainer = forwardRef<
|
|
44
47
|
HTMLDivElement,
|
|
45
48
|
PropsWithChildren<InnerContainerProps>
|
|
46
|
-
>(({
|
|
49
|
+
>(({ className, style, node, children }, ref) => {
|
|
47
50
|
return (
|
|
48
51
|
<div
|
|
49
52
|
ref={ref}
|
|
50
|
-
style={
|
|
51
|
-
width,
|
|
52
|
-
marginLeft,
|
|
53
|
-
}}
|
|
53
|
+
style={style}
|
|
54
54
|
className={className}
|
|
55
55
|
data-number-column={node.attrs.isNumberColumnEnabled}
|
|
56
56
|
data-layout={node.attrs.layout}
|
|
@@ -76,6 +76,7 @@ export const ResizableTableContainer = ({
|
|
|
76
76
|
className,
|
|
77
77
|
node,
|
|
78
78
|
lineLength,
|
|
79
|
+
containerWidth,
|
|
79
80
|
editorView,
|
|
80
81
|
getPos,
|
|
81
82
|
tableRef,
|
|
@@ -89,25 +90,32 @@ export const ResizableTableContainer = ({
|
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
innerContainerRef.current.style.width = `${width}px`;
|
|
93
|
-
|
|
94
93
|
const marginLeft = getMarginLeft({
|
|
95
94
|
lineLength,
|
|
96
95
|
tableWidth: width,
|
|
97
96
|
});
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
if (marginLeft) {
|
|
99
|
+
containerRef.current.style.marginLeft = `${marginLeft}px`;
|
|
100
|
+
}
|
|
101
101
|
},
|
|
102
102
|
[lineLength],
|
|
103
103
|
);
|
|
104
104
|
|
|
105
|
-
const
|
|
105
|
+
const tableWidth = getTableContainerWidth(node);
|
|
106
|
+
|
|
107
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
108
|
+
const responsiveContainerWidth = containerWidth - 76;
|
|
109
|
+
|
|
110
|
+
const width = Math.min(tableWidth, responsiveContainerWidth);
|
|
111
|
+
|
|
106
112
|
const marginLeft = getMarginLeft({
|
|
107
113
|
lineLength,
|
|
108
114
|
tableWidth: width,
|
|
109
115
|
});
|
|
110
116
|
|
|
117
|
+
const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
|
|
118
|
+
|
|
111
119
|
return (
|
|
112
120
|
<div
|
|
113
121
|
style={{ marginLeft, width }}
|
|
@@ -116,6 +124,7 @@ export const ResizableTableContainer = ({
|
|
|
116
124
|
>
|
|
117
125
|
<TableResizer
|
|
118
126
|
width={width}
|
|
127
|
+
maxWidth={maxResizerWidth}
|
|
119
128
|
updateWidth={updateWidth}
|
|
120
129
|
editorView={editorView}
|
|
121
130
|
getPos={getPos}
|
|
@@ -126,8 +135,6 @@ export const ResizableTableContainer = ({
|
|
|
126
135
|
ref={innerContainerRef}
|
|
127
136
|
className={className}
|
|
128
137
|
node={node}
|
|
129
|
-
width={width}
|
|
130
|
-
marginLeft={0}
|
|
131
138
|
>
|
|
132
139
|
{children}
|
|
133
140
|
</InnerContainer>
|
|
@@ -188,11 +195,13 @@ export const TableContainer = ({
|
|
|
188
195
|
<InnerContainer
|
|
189
196
|
node={node}
|
|
190
197
|
className={className}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
style={{
|
|
199
|
+
width: tableWidth,
|
|
200
|
+
marginLeft: getMarginLeft({
|
|
201
|
+
lineLength: lineLength!,
|
|
202
|
+
tableWidth,
|
|
203
|
+
}),
|
|
204
|
+
}}
|
|
196
205
|
>
|
|
197
206
|
{children}
|
|
198
207
|
</InnerContainer>
|
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
previewScaleTable,
|
|
11
11
|
getColgroupChildrenLength,
|
|
12
12
|
COLUMN_MIN_WIDTH,
|
|
13
|
-
TABLE_MAX_WIDTH,
|
|
14
13
|
} from '../pm-plugins/table-resizing/utils';
|
|
15
14
|
|
|
16
15
|
interface TableResizerProps {
|
|
17
16
|
width: number;
|
|
17
|
+
maxWidth: number;
|
|
18
18
|
updateWidth: (width: number) => void;
|
|
19
19
|
editorView: EditorView;
|
|
20
20
|
getPos: () => number | undefined;
|
|
@@ -27,6 +27,7 @@ const handles = { right: true };
|
|
|
27
27
|
export const TableResizer = ({
|
|
28
28
|
children,
|
|
29
29
|
width,
|
|
30
|
+
maxWidth,
|
|
30
31
|
updateWidth,
|
|
31
32
|
editorView,
|
|
32
33
|
getPos,
|
|
@@ -99,7 +100,7 @@ export const TableResizer = ({
|
|
|
99
100
|
}}
|
|
100
101
|
resizeRatio={2}
|
|
101
102
|
minWidth={minColumnWidth}
|
|
102
|
-
maxWidth={
|
|
103
|
+
maxWidth={maxWidth}
|
|
103
104
|
>
|
|
104
105
|
{children}
|
|
105
106
|
</ResizerNext>
|
|
@@ -29,16 +29,22 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
29
29
|
import TableComponent from './TableComponent';
|
|
30
30
|
import { Props, TableOptions } from './types';
|
|
31
31
|
import type { TableColumnOrdering } from '@atlaskit/adf-schema/steps';
|
|
32
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
33
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
32
34
|
|
|
33
35
|
type ForwardRef = (node: HTMLElement | null) => void;
|
|
34
36
|
|
|
35
37
|
const tableAttributes = (node: PmNode) => {
|
|
38
|
+
const style = getBooleanFF('platform.editor.custom-table-width')
|
|
39
|
+
? `width: ${getTableContainerWidth(node)}px`
|
|
40
|
+
: undefined;
|
|
36
41
|
return {
|
|
37
42
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
38
43
|
'data-layout': node.attrs.layout,
|
|
39
44
|
'data-autosize': node.attrs.__autoSize,
|
|
40
45
|
'data-table-local-id': node.attrs.localId || '',
|
|
41
46
|
'data-table-width': node.attrs.width,
|
|
47
|
+
style,
|
|
42
48
|
};
|
|
43
49
|
};
|
|
44
50
|
|
|
@@ -5,6 +5,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
|
5
5
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
|
|
7
7
|
import type { DomAtPos } from 'prosemirror-utils';
|
|
8
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
9
|
|
|
9
10
|
import { getTableWidth } from '../../../utils';
|
|
10
11
|
import { getLayoutSize } from '../utils/misc';
|
|
@@ -152,7 +153,15 @@ export const previewScaleTable = (
|
|
|
152
153
|
) => {
|
|
153
154
|
const { node, start, parentWidth } = options;
|
|
154
155
|
|
|
155
|
-
if (!tableRef
|
|
156
|
+
if (!tableRef) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (getBooleanFF('platform.editor.custom-table-width') && parentWidth) {
|
|
161
|
+
tableRef.style.width = `${parentWidth}px`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!hasTableBeenResized(node)) {
|
|
156
165
|
return;
|
|
157
166
|
}
|
|
158
167
|
|
package/.eslintrc.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
rules: {
|
|
3
|
-
// Ensure the table plugin is not coupled to editor-core and avoid circular dependencies
|
|
4
|
-
'no-restricted-imports': [
|
|
5
|
-
'error',
|
|
6
|
-
{
|
|
7
|
-
patterns: [
|
|
8
|
-
{
|
|
9
|
-
group: ['@atlaskit/editor-core/*', '@atlaskit/editor-core'],
|
|
10
|
-
message:
|
|
11
|
-
'Importing editor-core is not allowed in editor-plugin-table. Consider using editor-common instead.',
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
'react/no-danger': 'error',
|
|
17
|
-
},
|
|
18
|
-
// Disable restricted import for tests
|
|
19
|
-
overrides: [
|
|
20
|
-
{
|
|
21
|
-
files: ['**/__tests__/**/*.{js,ts,tsx}', 'examples/**/*.{js,ts,tsx}'],
|
|
22
|
-
rules: {
|
|
23
|
-
'no-restricted-imports': [
|
|
24
|
-
'off',
|
|
25
|
-
{
|
|
26
|
-
patterns: [
|
|
27
|
-
{
|
|
28
|
-
group: ['@atlaskit/editor-core/*', '@atlaskit/editor-core'],
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
'react/no-danger': 'off',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
doc,
|
|
3
|
-
DocBuilder,
|
|
4
|
-
p,
|
|
5
|
-
table,
|
|
6
|
-
tdCursor,
|
|
7
|
-
tdEmpty,
|
|
8
|
-
tr,
|
|
9
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
10
|
-
import {
|
|
11
|
-
createProsemirrorEditorFactory,
|
|
12
|
-
LightEditorPlugin,
|
|
13
|
-
Preset,
|
|
14
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
15
|
-
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
16
|
-
import type {
|
|
17
|
-
FloatingToolbarButton,
|
|
18
|
-
FloatingToolbarItem,
|
|
19
|
-
GetEditorFeatureFlags,
|
|
20
|
-
} from '@atlaskit/editor-common/types';
|
|
21
|
-
import dataConsumerPlugin from '@atlaskit/editor-core/src/plugins/data-consumer';
|
|
22
|
-
import extensionPlugin from '@atlaskit/editor-core/src/plugins/extension';
|
|
23
|
-
import tablePlugin from '../../plugins/table';
|
|
24
|
-
import { setEditorFocus, setTableRef } from '../../plugins/table/commands';
|
|
25
|
-
import { getToolbarConfig } from '../../plugins/table/toolbar';
|
|
26
|
-
import featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
|
|
27
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
28
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
29
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
30
|
-
import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
31
|
-
|
|
32
|
-
const formatMessage: (t: { id: string }) => string = (message) =>
|
|
33
|
-
`${message.id}`;
|
|
34
|
-
|
|
35
|
-
describe('color picker', () => {
|
|
36
|
-
/**
|
|
37
|
-
* Use `createEditorFactory` here to enable referentiality as
|
|
38
|
-
* `createProsemirrorEditorFactory` has some issues with correctly mimicking
|
|
39
|
-
* old state for the unique localId plugin
|
|
40
|
-
*/
|
|
41
|
-
const createEditorFn = createProsemirrorEditorFactory();
|
|
42
|
-
const createEditor = (doc: DocBuilder) => {
|
|
43
|
-
const output = createEditorFn({
|
|
44
|
-
doc,
|
|
45
|
-
|
|
46
|
-
attachTo: document.body,
|
|
47
|
-
preset: new Preset<LightEditorPlugin>()
|
|
48
|
-
.add([featureFlagsPlugin, {}])
|
|
49
|
-
.add([analyticsPlugin, {}])
|
|
50
|
-
.add(decorationsPlugin)
|
|
51
|
-
.add(contentInsertionPlugin)
|
|
52
|
-
.add(widthPlugin)
|
|
53
|
-
.add(dataConsumerPlugin)
|
|
54
|
-
.add(extensionPlugin)
|
|
55
|
-
.add(tablePlugin),
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Prep the table plugin state a little
|
|
59
|
-
const { editorView } = output;
|
|
60
|
-
const { dispatch } = editorView;
|
|
61
|
-
const tableRef = document.querySelector(
|
|
62
|
-
'.ProseMirror table',
|
|
63
|
-
) as HTMLTableElement;
|
|
64
|
-
setEditorFocus(true)(output.editorView.state, dispatch);
|
|
65
|
-
setTableRef(tableRef)(output.editorView.state, dispatch);
|
|
66
|
-
|
|
67
|
-
return output;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
it('should return a corect color picker option if allowBackgroundColor enabled', async () => {
|
|
71
|
-
const { editorView } = createEditor(
|
|
72
|
-
doc(p('text'), table()(tr(tdCursor, tdEmpty))),
|
|
73
|
-
);
|
|
74
|
-
const getEditorContainerWidth = () => ({ width: 500 });
|
|
75
|
-
const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
|
|
76
|
-
attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// Enable tableCellOptionsInFloatingToolbar
|
|
80
|
-
const getEditorFeatureFlags: GetEditorFeatureFlags = jest
|
|
81
|
-
.fn()
|
|
82
|
-
.mockReturnValue({
|
|
83
|
-
tableCellOptionsInFloatingToolbar: true,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Enable allowBackgroundColor feature flag
|
|
87
|
-
const { state } = editorView;
|
|
88
|
-
(state as any).tablePlugin$.pluginConfig.allowBackgroundColor = true;
|
|
89
|
-
|
|
90
|
-
// Create the editor
|
|
91
|
-
const config = getToolbarConfig(
|
|
92
|
-
getEditorContainerWidth,
|
|
93
|
-
editorAnalyticsAPIFake,
|
|
94
|
-
getEditorFeatureFlags,
|
|
95
|
-
() => editorView,
|
|
96
|
-
)({})(state, { formatMessage } as any, {} as any)!;
|
|
97
|
-
|
|
98
|
-
// Let's find the colorPicker from the option items list
|
|
99
|
-
const items =
|
|
100
|
-
typeof config.items === 'function'
|
|
101
|
-
? config.items(state.doc.firstChild!)
|
|
102
|
-
: config.items;
|
|
103
|
-
|
|
104
|
-
const option = items.find(
|
|
105
|
-
(item: FloatingToolbarItem<any>) =>
|
|
106
|
-
item.type === 'select' && item.id === 'editor.table.colorPicker',
|
|
107
|
-
)! as FloatingToolbarButton<any>;
|
|
108
|
-
expect(option).not.toBeUndefined();
|
|
109
|
-
});
|
|
110
|
-
});
|