@atlaskit/editor-plugin-table 5.1.0 → 5.2.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 +6 -0
- package/dist/cjs/plugins/table/index.js +3 -2
- package/dist/cjs/plugins/table/nodeviews/TableCell.js +111 -0
- package/dist/cjs/plugins/table/nodeviews/TableNodeViewBase.js +30 -0
- package/dist/cjs/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +313 -307
- package/dist/cjs/plugins/table/pm-plugins/main.js +16 -13
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/index.js +1 -8
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
- package/dist/cjs/plugins/table/utils/dom.js +31 -1
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/cjs/plugins/table/utils/nodes.js +31 -7
- package/dist/es2019/plugins/table/index.js +3 -2
- package/dist/es2019/plugins/table/nodeviews/{tableCell.js → TableCell.js} +28 -24
- package/dist/es2019/plugins/table/nodeviews/TableNodeViewBase.js +22 -0
- package/dist/es2019/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +273 -284
- package/dist/es2019/plugins/table/pm-plugins/main.js +8 -8
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
- package/dist/es2019/plugins/table/utils/dom.js +30 -0
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/es2019/plugins/table/utils/nodes.js +16 -0
- package/dist/esm/plugins/table/index.js +3 -2
- package/dist/esm/plugins/table/nodeviews/TableCell.js +105 -0
- package/dist/esm/plugins/table/nodeviews/TableNodeViewBase.js +24 -0
- package/dist/esm/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +314 -307
- package/dist/esm/plugins/table/pm-plugins/main.js +16 -13
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
- package/dist/esm/plugins/table/utils/dom.js +30 -0
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/utils/nodes.js +24 -0
- package/dist/types/plugins/table/nodeviews/TableCell.d.ts +13 -0
- package/dist/types/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +60 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
- package/dist/types/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/utils/dom.d.ts +6 -0
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types/plugins/table/utils/nodes.d.ts +12 -2
- package/dist/types-ts4.5/plugins/table/nodeviews/TableCell.d.ts +13 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +60 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/utils/nodes.d.ts +12 -2
- package/package.json +1 -1
- package/src/__tests__/unit/nodeviews/cell.ts +2 -2
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +25 -148
- package/src/plugins/table/index.tsx +2 -0
- package/src/plugins/table/nodeviews/{tableCell.tsx → TableCell.ts} +41 -46
- package/src/plugins/table/nodeviews/TableNodeViewBase.ts +32 -0
- package/src/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.ts → nodeviews/TableRow.ts} +193 -246
- package/src/plugins/table/pm-plugins/main.ts +10 -19
- package/src/plugins/table/pm-plugins/sticky-headers/index.ts +0 -1
- package/src/plugins/table/pm-plugins/sticky-headers/plugin.ts +1 -9
- package/src/plugins/table/types.ts +2 -0
- package/src/plugins/table/utils/dom.ts +38 -0
- package/src/plugins/table/utils/index.ts +2 -0
- package/src/plugins/table/utils/nodes.ts +30 -2
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +0 -99
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -35
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
- package/dist/esm/plugins/table/nodeviews/tableCell.js +0 -93
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
- package/dist/types/plugins/table/nodeviews/tableCell.d.ts +0 -17
- package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
- package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +0 -17
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.ts +0 -37
|
@@ -33,10 +33,11 @@ import {
|
|
|
33
33
|
|
|
34
34
|
import tablePlugin from '../../../../plugins/table';
|
|
35
35
|
import TableComponent from '../../../../plugins/table/nodeviews/TableComponent';
|
|
36
|
+
import TableRow from '../../../../plugins/table/nodeviews/TableRow';
|
|
36
37
|
import { pluginKey } from '../../../../plugins/table/pm-plugins/plugin-key';
|
|
37
|
-
import { TableRowNodeView } from '../../../../plugins/table/pm-plugins/sticky-headers';
|
|
38
38
|
import { updateStickyState } from '../../../../plugins/table/pm-plugins/sticky-headers/commands';
|
|
39
39
|
import { TableCssClassName } from '../../../../plugins/table/types';
|
|
40
|
+
import type { PluginConfig } from '../../../../plugins/table/types';
|
|
40
41
|
import {
|
|
41
42
|
stickyRowOffsetTop,
|
|
42
43
|
tableScrollbarOffset,
|
|
@@ -56,8 +57,17 @@ jest.mock('@atlaskit/editor-common/ui', () => ({
|
|
|
56
57
|
findOverflowScrollParent: jest.fn(() => jest.fn()),
|
|
57
58
|
}));
|
|
58
59
|
|
|
59
|
-
describe('
|
|
60
|
-
|
|
60
|
+
describe('TableRow', () => {
|
|
61
|
+
const tableOptions = {
|
|
62
|
+
allowNumberColumn: true,
|
|
63
|
+
allowHeaderRow: true,
|
|
64
|
+
allowHeaderColumn: true,
|
|
65
|
+
permittedLayouts: 'all',
|
|
66
|
+
allowColumnResizing: true,
|
|
67
|
+
stickyHeaders: true,
|
|
68
|
+
} as PluginConfig;
|
|
69
|
+
|
|
70
|
+
let tableRowNodeView: TableRow;
|
|
61
71
|
const fakeGetEditorFeatureFlags = jest.fn(() => ({}));
|
|
62
72
|
const createEditor = createProsemirrorEditorFactory();
|
|
63
73
|
const editor = (doc: DocBuilder) => {
|
|
@@ -72,7 +82,12 @@ describe('TableRowNodeView', () => {
|
|
|
72
82
|
.add(widthPlugin)
|
|
73
83
|
.add(guidelinePlugin)
|
|
74
84
|
.add(selectionPlugin)
|
|
75
|
-
.add(
|
|
85
|
+
.add([
|
|
86
|
+
tablePlugin,
|
|
87
|
+
{
|
|
88
|
+
tableOptions,
|
|
89
|
+
},
|
|
90
|
+
]),
|
|
76
91
|
pluginKey,
|
|
77
92
|
attachTo: document.body,
|
|
78
93
|
});
|
|
@@ -94,121 +109,6 @@ describe('TableRowNodeView', () => {
|
|
|
94
109
|
toJSON: jest.fn(),
|
|
95
110
|
};
|
|
96
111
|
|
|
97
|
-
describe('stickyHeader', () => {
|
|
98
|
-
beforeEach(() => {
|
|
99
|
-
const editorWithTableSticky = (doc: DocBuilder) =>
|
|
100
|
-
createEditor({
|
|
101
|
-
doc,
|
|
102
|
-
preset: new Preset<LightEditorPlugin>()
|
|
103
|
-
.add([featureFlagsPlugin, {}])
|
|
104
|
-
.add([analyticsPlugin, {}])
|
|
105
|
-
.add(contentInsertionPlugin)
|
|
106
|
-
.add(widthPlugin)
|
|
107
|
-
.add(guidelinePlugin)
|
|
108
|
-
.add(selectionPlugin)
|
|
109
|
-
.add(tablePlugin),
|
|
110
|
-
pluginKey,
|
|
111
|
-
});
|
|
112
|
-
const editorData = editorWithTableSticky(
|
|
113
|
-
doc(table({ localId: '' })(tr(tdEmpty, tdEmpty))),
|
|
114
|
-
);
|
|
115
|
-
editorView = editorData.editorView;
|
|
116
|
-
eventDispatcher = editorData.eventDispatcher;
|
|
117
|
-
tableRowNode = editorView.state.doc.firstChild!.firstChild!;
|
|
118
|
-
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
119
|
-
tableRowNodeView = new TableRowNodeView(
|
|
120
|
-
tableRowNode,
|
|
121
|
-
editorView,
|
|
122
|
-
jest.fn(),
|
|
123
|
-
eventDispatcher,
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
afterEach(() => {
|
|
127
|
-
jest.clearAllMocks();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
function createBoundingClientRect(rect: any) {
|
|
131
|
-
return {
|
|
132
|
-
getBoundingClientRect: () => {
|
|
133
|
-
return rect;
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function setupMocks(
|
|
139
|
-
tableRowNodeView: any,
|
|
140
|
-
editorRect: any,
|
|
141
|
-
tableRect: any,
|
|
142
|
-
) {
|
|
143
|
-
jest.spyOn(tableRowNodeView as any, 'tree', 'get').mockReturnValue({
|
|
144
|
-
wrapper: createBoundingClientRect(tableRect),
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
Object.defineProperty(tableRowNodeView, 'editorScrollableElement', {
|
|
148
|
-
get() {
|
|
149
|
-
return createBoundingClientRect(editorRect);
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
Object.defineProperty(tableRowNodeView, 'dom', {
|
|
153
|
-
get() {
|
|
154
|
-
return {
|
|
155
|
-
previousElementSibling: false,
|
|
156
|
-
nextElementSibling: true,
|
|
157
|
-
clientHeight: 20,
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
Object.defineProperty(tableRowNodeView, 'topPosEditorElement', {
|
|
163
|
-
get() {
|
|
164
|
-
return 50;
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
it('should make it sticky if table is taller than viewport', () => {
|
|
170
|
-
const tableRect = { top: 10, bottom: 110, height: 100 };
|
|
171
|
-
const editorRect = { top: 50, bottom: 100, height: 50 };
|
|
172
|
-
setupMocks(tableRowNodeView, editorRect, tableRect);
|
|
173
|
-
const res = tableRowNodeView.shouldHeaderStick(
|
|
174
|
-
tableRowNodeView.tree as any,
|
|
175
|
-
);
|
|
176
|
-
expect(res).toBe(true);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should make it sticky if table is lower than the editor', () => {
|
|
180
|
-
const tableRect = { top: 20, bottom: 120, height: 100 };
|
|
181
|
-
const editorRect = { top: 50, bottom: 100, height: 50 };
|
|
182
|
-
setupMocks(tableRowNodeView, editorRect, tableRect);
|
|
183
|
-
const res = tableRowNodeView.shouldHeaderStick(
|
|
184
|
-
tableRowNodeView.tree as any,
|
|
185
|
-
);
|
|
186
|
-
expect(res).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('should make it non-sticky if table is higher than the editor', () => {
|
|
190
|
-
const tableRect = { top: 60, bottom: 70, height: 50 };
|
|
191
|
-
const editorRect = { top: 50, bottom: 150, height: 100 };
|
|
192
|
-
setupMocks(tableRowNodeView, editorRect, tableRect);
|
|
193
|
-
|
|
194
|
-
const res = tableRowNodeView.shouldHeaderStick(
|
|
195
|
-
tableRowNodeView.tree as any,
|
|
196
|
-
);
|
|
197
|
-
expect(res).toBe(false);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('should make it non-sticky if table out of viewport', () => {
|
|
201
|
-
const tableRect = { top: -50, bottom: 20, height: 70 };
|
|
202
|
-
const editorRect = { top: 50, bottom: 150, height: 100 };
|
|
203
|
-
setupMocks(tableRowNodeView, editorRect, tableRect);
|
|
204
|
-
|
|
205
|
-
const res = tableRowNodeView.shouldHeaderStick(
|
|
206
|
-
tableRowNodeView.tree as any,
|
|
207
|
-
);
|
|
208
|
-
expect(res).toBe(false);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
112
|
describe('ignoreMutation', () => {
|
|
213
113
|
beforeEach(() => {
|
|
214
114
|
const editorData = editor(
|
|
@@ -217,10 +117,10 @@ describe('TableRowNodeView', () => {
|
|
|
217
117
|
editorView = editorData.editorView;
|
|
218
118
|
eventDispatcher = editorData.eventDispatcher;
|
|
219
119
|
tableRowNode = editorView.state.doc.firstChild!.firstChild!;
|
|
220
|
-
tableRowNodeView = new
|
|
120
|
+
tableRowNodeView = new TableRow(
|
|
221
121
|
tableRowNode,
|
|
222
122
|
editorView,
|
|
223
|
-
|
|
123
|
+
() => 0,
|
|
224
124
|
eventDispatcher,
|
|
225
125
|
);
|
|
226
126
|
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
@@ -363,10 +263,10 @@ describe('TableRowNodeView', () => {
|
|
|
363
263
|
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
364
264
|
scrollContainer = mockScrollPositions(tableRowDom)!;
|
|
365
265
|
|
|
366
|
-
tableRowNodeView = new
|
|
266
|
+
tableRowNodeView = new TableRow(
|
|
367
267
|
tableRowNode,
|
|
368
268
|
editorView,
|
|
369
|
-
|
|
269
|
+
() => 0,
|
|
370
270
|
eventDispatcher,
|
|
371
271
|
);
|
|
372
272
|
tableRowNodeView.dom = tableRowDom;
|
|
@@ -616,19 +516,14 @@ describe('TableRowNodeView', () => {
|
|
|
616
516
|
tableRowNode = editorView.state.doc.firstChild!.firstChild!;
|
|
617
517
|
tableRowDom = editorView.dom.getElementsByTagName('tr')[0];
|
|
618
518
|
|
|
619
|
-
tableRowNodeView = new
|
|
519
|
+
tableRowNodeView = new TableRow(
|
|
620
520
|
tableRowNode,
|
|
621
521
|
editorView,
|
|
622
|
-
|
|
522
|
+
() => 0,
|
|
623
523
|
eventDispatcher,
|
|
624
524
|
);
|
|
625
525
|
tableRowNodeView.dom = tableRowDom;
|
|
626
526
|
|
|
627
|
-
// Initialize with sticky off
|
|
628
|
-
tableRowNodeView.isSticky = false;
|
|
629
|
-
tableRowNodeView.top = 0;
|
|
630
|
-
tableRowNodeView.padding = 0;
|
|
631
|
-
|
|
632
527
|
makeRowHeaderNotStickySpy = jest.spyOn(
|
|
633
528
|
tableRowNodeView as any,
|
|
634
529
|
'makeRowHeaderNotSticky',
|
|
@@ -665,23 +560,5 @@ describe('TableRowNodeView', () => {
|
|
|
665
560
|
});
|
|
666
561
|
expect(makeRowHeaderNotStickySpy).toHaveBeenCalled();
|
|
667
562
|
});
|
|
668
|
-
|
|
669
|
-
it('should cause isSticky state to be set to false when called', () => {
|
|
670
|
-
// Begin test with stickyheaders state on
|
|
671
|
-
tableRowNodeView.isSticky = true;
|
|
672
|
-
tableRowNodeView.top = 1;
|
|
673
|
-
tableRowNodeView.padding = 1;
|
|
674
|
-
|
|
675
|
-
tableRowNodeView.makeRowHeaderNotSticky(tableRef);
|
|
676
|
-
|
|
677
|
-
expect(updateStickyState).toHaveBeenCalledWith(
|
|
678
|
-
expect.objectContaining({
|
|
679
|
-
sticky: false,
|
|
680
|
-
}),
|
|
681
|
-
);
|
|
682
|
-
expect(tableRowNodeView.isSticky).toBe(false);
|
|
683
|
-
expect(tableRowNodeView.top).toBe(0);
|
|
684
|
-
expect(tableRowNodeView.padding).toBe(0);
|
|
685
|
-
});
|
|
686
563
|
});
|
|
687
564
|
});
|
|
@@ -184,6 +184,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
184
184
|
breakoutEnabled,
|
|
185
185
|
tableOptions,
|
|
186
186
|
getEditorFeatureFlags,
|
|
187
|
+
dragAndDropEnabled,
|
|
187
188
|
} = options || ({} as TablePluginOptions);
|
|
188
189
|
return createPlugin(
|
|
189
190
|
dispatchAnalyticsEvent,
|
|
@@ -198,6 +199,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
198
199
|
fullWidthEnabled,
|
|
199
200
|
tableResizingEnabled,
|
|
200
201
|
wasFullWidthEnabled,
|
|
202
|
+
dragAndDropEnabled,
|
|
201
203
|
editorAnalyticsAPI,
|
|
202
204
|
api,
|
|
203
205
|
);
|
|
@@ -1,53 +1,62 @@
|
|
|
1
1
|
import uuid from 'uuid';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@atlaskit/
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import
|
|
3
|
+
import type { CellDomAttrs } from '@atlaskit/adf-schema';
|
|
4
|
+
import { getCellAttrs, getCellDomAttrs } from '@atlaskit/adf-schema';
|
|
5
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
6
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
+
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
+
|
|
9
|
+
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
10
|
+
|
|
11
|
+
import TableNodeView from './TableNodeViewBase';
|
|
12
12
|
|
|
13
13
|
const DEFAULT_COL_SPAN = 1;
|
|
14
14
|
const DEFAULT_ROW_SPAN = 1;
|
|
15
15
|
|
|
16
|
-
export default class
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
getPos: getPosHandler;
|
|
21
|
-
view: EditorView;
|
|
22
|
-
providerFactory?: ProviderFactory;
|
|
23
|
-
observer?: ResizeObserver;
|
|
24
|
-
|
|
16
|
+
export default class TableCell
|
|
17
|
+
extends TableNodeView<HTMLElement>
|
|
18
|
+
implements NodeView
|
|
19
|
+
{
|
|
25
20
|
constructor(
|
|
26
|
-
node:
|
|
21
|
+
node: PMNode,
|
|
27
22
|
view: EditorView,
|
|
28
|
-
getPos:
|
|
29
|
-
|
|
23
|
+
getPos: () => number | undefined,
|
|
24
|
+
eventDispatcher: EventDispatcher,
|
|
25
|
+
private readonly observer?: ResizeObserver,
|
|
30
26
|
) {
|
|
31
|
-
|
|
32
|
-
this.node = node;
|
|
27
|
+
super(node, view, getPos, eventDispatcher);
|
|
33
28
|
|
|
34
|
-
const {
|
|
35
|
-
document,
|
|
36
|
-
node.type.spec.toDOM!(node),
|
|
37
|
-
);
|
|
29
|
+
const { pluginConfig, isDragAndDropEnabled } = getPluginState(view.state);
|
|
38
30
|
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.contentDOM = contentDOM as HTMLElement;
|
|
31
|
+
this.isStickyHeaderEnabled = !!pluginConfig.stickyHeaders;
|
|
32
|
+
this.isDragAndDropEnabled = !!isDragAndDropEnabled;
|
|
42
33
|
|
|
43
34
|
if (observer) {
|
|
44
35
|
this.contentDOM.id = uuid();
|
|
45
|
-
this.observer = observer;
|
|
46
36
|
observer.observe(this.contentDOM);
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
39
|
|
|
50
|
-
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
private isStickyHeaderEnabled: boolean;
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
private isDragAndDropEnabled: boolean;
|
|
44
|
+
|
|
45
|
+
update(node: PMNode) {
|
|
46
|
+
const didUpdate = this.updateNodeView(node);
|
|
47
|
+
if (didUpdate) {
|
|
48
|
+
this.node = node;
|
|
49
|
+
}
|
|
50
|
+
return didUpdate;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
destroy() {
|
|
54
|
+
if (this.observer) {
|
|
55
|
+
this.observer.unobserve(this.contentDOM);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private updateNodeView(node: PMNode) {
|
|
51
60
|
if (this.node.type !== node.type) {
|
|
52
61
|
return false;
|
|
53
62
|
}
|
|
@@ -90,18 +99,4 @@ export default class TableCellNodeView implements NodeView {
|
|
|
90
99
|
|
|
91
100
|
return false;
|
|
92
101
|
}
|
|
93
|
-
|
|
94
|
-
update(node: Node) {
|
|
95
|
-
const didUpdate = this.updateNodeView(node);
|
|
96
|
-
if (didUpdate) {
|
|
97
|
-
this.node = node;
|
|
98
|
-
}
|
|
99
|
-
return didUpdate;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
destroy() {
|
|
103
|
-
if (this.observer) {
|
|
104
|
-
this.observer.unobserve(this.contentDOM);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
102
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
|
|
6
|
+
export default abstract class TableNodeView<T extends HTMLElement>
|
|
7
|
+
implements NodeView
|
|
8
|
+
{
|
|
9
|
+
/**
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor(
|
|
13
|
+
protected node: PmNode,
|
|
14
|
+
protected readonly view: EditorView,
|
|
15
|
+
protected readonly getPos: () => number | undefined,
|
|
16
|
+
protected readonly eventDispatcher: EventDispatcher,
|
|
17
|
+
) {
|
|
18
|
+
const { dom, contentDOM } = DOMSerializer.renderSpec(
|
|
19
|
+
document,
|
|
20
|
+
node.type.spec.toDOM!(node),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
this.dom = dom as T;
|
|
24
|
+
this.contentDOM = contentDOM as T;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Variables
|
|
29
|
+
*/
|
|
30
|
+
dom: T;
|
|
31
|
+
contentDOM: T;
|
|
32
|
+
}
|