@atlaskit/editor-plugin-table 3.1.2 → 3.1.3
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 +6 -0
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +7 -1
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +11 -1
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +7 -1
- package/package.json +1 -1
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +43 -18
- package/src/plugins/table/nodeviews/TableResizer.tsx +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -133,11 +133,17 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
133
133
|
// only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
|
|
134
134
|
// deleted this table
|
|
135
135
|
if (isResizing.current) {
|
|
136
|
+
var dispatch = editorView.dispatch,
|
|
137
|
+
_tr = editorView.state.tr;
|
|
136
138
|
displayGapCursor(true);
|
|
137
139
|
displayGuideline([]);
|
|
140
|
+
_tr.setMeta(_tableWidth.pluginKey, {
|
|
141
|
+
resizing: false
|
|
142
|
+
});
|
|
143
|
+
dispatch(_tr);
|
|
138
144
|
}
|
|
139
145
|
};
|
|
140
|
-
}, [displayGuideline, displayGapCursor]);
|
|
146
|
+
}, [editorView, displayGuideline, displayGapCursor]);
|
|
141
147
|
var handleResizeStart = (0, _react.useCallback)(function () {
|
|
142
148
|
startMeasure();
|
|
143
149
|
isResizing.current = true;
|
|
@@ -119,11 +119,21 @@ export const TableResizer = ({
|
|
|
119
119
|
// only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
|
|
120
120
|
// deleted this table
|
|
121
121
|
if (isResizing.current) {
|
|
122
|
+
const {
|
|
123
|
+
dispatch,
|
|
124
|
+
state: {
|
|
125
|
+
tr
|
|
126
|
+
}
|
|
127
|
+
} = editorView;
|
|
122
128
|
displayGapCursor(true);
|
|
123
129
|
displayGuideline([]);
|
|
130
|
+
tr.setMeta(tableWidthPluginKey, {
|
|
131
|
+
resizing: false
|
|
132
|
+
});
|
|
133
|
+
dispatch(tr);
|
|
124
134
|
}
|
|
125
135
|
};
|
|
126
|
-
}, [displayGuideline, displayGapCursor]);
|
|
136
|
+
}, [editorView, displayGuideline, displayGapCursor]);
|
|
127
137
|
const handleResizeStart = useCallback(() => {
|
|
128
138
|
startMeasure();
|
|
129
139
|
isResizing.current = true;
|
|
@@ -123,11 +123,17 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
123
123
|
// only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
|
|
124
124
|
// deleted this table
|
|
125
125
|
if (isResizing.current) {
|
|
126
|
+
var dispatch = editorView.dispatch,
|
|
127
|
+
_tr = editorView.state.tr;
|
|
126
128
|
displayGapCursor(true);
|
|
127
129
|
displayGuideline([]);
|
|
130
|
+
_tr.setMeta(tableWidthPluginKey, {
|
|
131
|
+
resizing: false
|
|
132
|
+
});
|
|
133
|
+
dispatch(_tr);
|
|
128
134
|
}
|
|
129
135
|
};
|
|
130
|
-
}, [displayGuideline, displayGapCursor]);
|
|
136
|
+
}, [editorView, displayGuideline, displayGapCursor]);
|
|
131
137
|
var handleResizeStart = useCallback(function () {
|
|
132
138
|
startMeasure();
|
|
133
139
|
isResizing.current = true;
|
package/package.json
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
TableContainer,
|
|
30
30
|
} from '../../../plugins/table/nodeviews/TableContainer';
|
|
31
31
|
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
32
|
+
import { pluginKey as tableResizingPluginKey } from '../../../plugins/table/pm-plugins/table-width';
|
|
32
33
|
import type { TablePluginState } from '../../../plugins/table/types';
|
|
33
34
|
|
|
34
35
|
const mockStartMeasure = jest.fn();
|
|
@@ -66,9 +67,14 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
66
67
|
return createEditor({
|
|
67
68
|
doc,
|
|
68
69
|
editorProps: {
|
|
70
|
+
appearance: 'full-page',
|
|
69
71
|
allowTables: false,
|
|
70
72
|
dangerouslyAppendPlugins: {
|
|
71
|
-
__plugins: [
|
|
73
|
+
__plugins: [
|
|
74
|
+
tablePlugin({
|
|
75
|
+
config: { tableResizingEnabled: true, tableOptions: {} },
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
72
78
|
},
|
|
73
79
|
featureFlags,
|
|
74
80
|
},
|
|
@@ -228,21 +234,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
228
234
|
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
229
235
|
fireEvent.mouseUp(container.querySelector('.resizer-handle.right')!);
|
|
230
236
|
|
|
231
|
-
expect(analyticsMock).
|
|
232
|
-
action: TABLE_ACTION.RESIZED,
|
|
233
|
-
actionSubject: ACTION_SUBJECT.TABLE,
|
|
234
|
-
eventType: EVENT_TYPE.TRACK,
|
|
235
|
-
attributes: {
|
|
236
|
-
width: undefined, // Can't get the events right to trigger re-resizeable
|
|
237
|
-
prevWidth: null,
|
|
238
|
-
nodeSize: 20,
|
|
239
|
-
totalTableWidth: null,
|
|
240
|
-
totalRowCount: 1,
|
|
241
|
-
totalColumnCount: 3,
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
expect(analyticsMock).toHaveBeenCalledWith({
|
|
237
|
+
expect(analyticsMock).toHaveBeenNthCalledWith(1, {
|
|
246
238
|
action: TABLE_ACTION.RESIZE_PERF_SAMPLING,
|
|
247
239
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
248
240
|
eventType: EVENT_TYPE.OPERATIONAL,
|
|
@@ -254,7 +246,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
254
246
|
},
|
|
255
247
|
});
|
|
256
248
|
|
|
257
|
-
expect(analyticsMock).
|
|
249
|
+
expect(analyticsMock).toHaveBeenNthCalledWith(2, {
|
|
258
250
|
action: TABLE_ACTION.RESIZE_PERF_SAMPLING,
|
|
259
251
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
260
252
|
eventType: EVENT_TYPE.OPERATIONAL,
|
|
@@ -266,6 +258,20 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
266
258
|
},
|
|
267
259
|
});
|
|
268
260
|
|
|
261
|
+
expect(analyticsMock).toHaveBeenNthCalledWith(3, {
|
|
262
|
+
action: TABLE_ACTION.RESIZED,
|
|
263
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
264
|
+
eventType: EVENT_TYPE.TRACK,
|
|
265
|
+
attributes: {
|
|
266
|
+
newWidth: 0, // Can't get the events right to trigger re-resizeable
|
|
267
|
+
prevWidth: 960,
|
|
268
|
+
nodeSize: 20,
|
|
269
|
+
totalTableWidth: null,
|
|
270
|
+
totalRowCount: 1,
|
|
271
|
+
totalColumnCount: 3,
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
|
|
269
275
|
analyticsMock.mockReset();
|
|
270
276
|
});
|
|
271
277
|
|
|
@@ -378,7 +384,13 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
378
384
|
/>,
|
|
379
385
|
);
|
|
380
386
|
|
|
381
|
-
return {
|
|
387
|
+
return {
|
|
388
|
+
container,
|
|
389
|
+
unmount,
|
|
390
|
+
editorView,
|
|
391
|
+
selectionActionMock,
|
|
392
|
+
actualGuidelineMock,
|
|
393
|
+
};
|
|
382
394
|
};
|
|
383
395
|
|
|
384
396
|
afterEach(() => {
|
|
@@ -408,5 +420,18 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
408
420
|
unmount();
|
|
409
421
|
expect(actualGuidelineMock).toHaveBeenCalledWith({ guidelines: [] });
|
|
410
422
|
});
|
|
423
|
+
|
|
424
|
+
// this is testing logic inside TableResizer, targeting the clean up in the useEffect
|
|
425
|
+
it('should call restore resizing plugin state when removed', () => {
|
|
426
|
+
const { container, unmount, editorView } = buildContainer({});
|
|
427
|
+
|
|
428
|
+
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
429
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
430
|
+
|
|
431
|
+
unmount();
|
|
432
|
+
expect(tableResizingPluginKey.getState(editorView.state)).toStrictEqual({
|
|
433
|
+
resizing: false,
|
|
434
|
+
});
|
|
435
|
+
});
|
|
411
436
|
});
|
|
412
437
|
});
|
|
@@ -201,11 +201,17 @@ export const TableResizer = ({
|
|
|
201
201
|
// only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
|
|
202
202
|
// deleted this table
|
|
203
203
|
if (isResizing.current) {
|
|
204
|
+
const {
|
|
205
|
+
dispatch,
|
|
206
|
+
state: { tr },
|
|
207
|
+
} = editorView;
|
|
204
208
|
displayGapCursor(true);
|
|
205
209
|
displayGuideline([]);
|
|
210
|
+
tr.setMeta(tableWidthPluginKey, { resizing: false });
|
|
211
|
+
dispatch(tr);
|
|
206
212
|
}
|
|
207
213
|
};
|
|
208
|
-
}, [displayGuideline, displayGapCursor]);
|
|
214
|
+
}, [editorView, displayGuideline, displayGapCursor]);
|
|
209
215
|
|
|
210
216
|
const handleResizeStart = useCallback(() => {
|
|
211
217
|
startMeasure();
|