1 |
|
2 |
|
3 |
|
4 |
|
5 | import { isWidget } from 'ckeditor5/src/widget';
|
6 |
|
7 |
|
8 |
|
9 | export function getSelectedTableWidget(selection) {
|
10 | const viewElement = selection.getSelectedElement();
|
11 | if (viewElement && isTableWidget(viewElement)) {
|
12 | return viewElement;
|
13 | }
|
14 | return null;
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 | export function getTableWidgetAncestor(selection) {
|
20 | const selectionPosition = selection.getFirstPosition();
|
21 | if (!selectionPosition) {
|
22 | return null;
|
23 | }
|
24 | let parent = selectionPosition.parent;
|
25 | while (parent) {
|
26 | if (parent.is('element') && isTableWidget(parent)) {
|
27 | return parent;
|
28 | }
|
29 | parent = parent.parent;
|
30 | }
|
31 | return null;
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 | function isTableWidget(viewElement) {
|
37 | return !!viewElement.getCustomProperty('table') && isWidget(viewElement);
|
38 | }
|