@gravity-ui/markdown-editor 13.1.0 → 13.1.1
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/build/cjs/extensions/yfm/YfmTable/plugins/YfmTableControls/yfmTableCellView.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmTable/plugins/YfmTableControls/yfmTableCellView.js +34 -22
- package/build/cjs/version.js +1 -1
- package/build/esm/extensions/yfm/YfmTable/plugins/YfmTableControls/yfmTableCellView.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmTable/plugins/YfmTableControls/yfmTableCellView.js +37 -25
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -6,12 +6,13 @@ const react_1 = tslib_1.__importDefault(require("react"));
|
|
|
6
6
|
const icons_1 = require("@gravity-ui/icons");
|
|
7
7
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
8
8
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
9
|
-
const react_dom_1 = require("react-dom");
|
|
10
9
|
const classname_1 = require("../../../../../classname");
|
|
11
10
|
const core_1 = require("../../../../../core");
|
|
12
11
|
const yfm_table_1 = require("../../../../../i18n/yfm-table");
|
|
13
12
|
const ErrorBoundary_1 = require("../../../../../react-utils/ErrorBoundary");
|
|
14
13
|
const table_utils_1 = require("../../../../../table-utils");
|
|
14
|
+
const node_children_1 = require("../../../../../utils/node-children");
|
|
15
|
+
const nodes_1 = require("../../../../../utils/nodes");
|
|
15
16
|
const ReactRenderer_1 = require("../../../../behavior/ReactRenderer");
|
|
16
17
|
const actions_1 = require("./actions");
|
|
17
18
|
exports.yfmTableCellCn = (0, classname_1.cn)('table-cell-view');
|
|
@@ -163,34 +164,30 @@ const Controls = function Controls({ columnNumber, rowNumber, view, getParentTab
|
|
|
163
164
|
return controls.length ? react_1.default.createElement(react_1.default.Fragment, null, controls) : null;
|
|
164
165
|
};
|
|
165
166
|
const yfmTableCellView = (node, view, getPos) => {
|
|
167
|
+
const getParentTable = () => (0, prosemirror_utils_1.findParentNodeClosestToPos)(view.state.doc.resolve(getPos()), table_utils_1.isTableNode);
|
|
168
|
+
const parentTable = getParentTable();
|
|
169
|
+
const cellCoords = parentTable ? findCellCoords(parentTable.node, node) : null;
|
|
170
|
+
// @ts-expect-error
|
|
171
|
+
if (!cellCoords)
|
|
172
|
+
return {};
|
|
173
|
+
const { cellIndex, rowIndex } = cellCoords;
|
|
174
|
+
const isFirstRow = rowIndex === 0;
|
|
175
|
+
const isFirstColumn = cellIndex === 0;
|
|
176
|
+
if (!isFirstRow && !isFirstColumn) {
|
|
177
|
+
// in this case, we don't need custom nodeView.
|
|
178
|
+
// @ts-expect-error
|
|
179
|
+
return {};
|
|
180
|
+
}
|
|
166
181
|
const dom = document.createElement('td');
|
|
167
182
|
const contentDOM = document.createElement('div');
|
|
168
183
|
const control = document.createElement('span');
|
|
169
184
|
control.setAttribute('style', 'width: 0; height: 0; float: left;');
|
|
170
185
|
dom.setAttribute('style', 'position: relative; overflow: visible;');
|
|
171
|
-
const getParentTable = () => (0, prosemirror_utils_1.findParentNodeClosestToPos)(view.state.doc.resolve(getPos()), table_utils_1.isTableNode);
|
|
172
|
-
const parentTable = getParentTable();
|
|
173
|
-
// @ts-expect-error
|
|
174
|
-
if (!parentTable)
|
|
175
|
-
return {};
|
|
176
|
-
const rowNodes = (0, prosemirror_utils_1.findChildren)(parentTable === null || parentTable === void 0 ? void 0 : parentTable.node, table_utils_1.isTableRowNode);
|
|
177
|
-
const relativeCelPos = getPos() - (parentTable === null || parentTable === void 0 ? void 0 : parentTable.pos);
|
|
178
|
-
const rowNumber = rowNodes.findIndex((_v, i) => {
|
|
179
|
-
var _a;
|
|
180
|
-
return relativeCelPos > rowNodes[i].pos &&
|
|
181
|
-
relativeCelPos < (((_a = rowNodes[i + 1]) === null || _a === void 0 ? void 0 : _a.pos) || Number.MAX_SAFE_INTEGER);
|
|
182
|
-
});
|
|
183
|
-
const parentRow = rowNodes[rowNumber];
|
|
184
|
-
const columnNumber = (0, prosemirror_utils_1.findChildren)(parentRow.node, table_utils_1.isTableCellNode).findIndex((c) => {
|
|
185
|
-
return c.pos === relativeCelPos - parentRow.pos - 2;
|
|
186
|
-
});
|
|
187
|
-
const isFirstInRow = rowNodes.findIndex((r) => r.pos === relativeCelPos - 2) >= 0;
|
|
188
186
|
dom.appendChild(contentDOM);
|
|
189
187
|
dom.appendChild(control);
|
|
190
|
-
const renderItem = (0, ReactRenderer_1.getReactRendererFromState)(view.state).createItem('yfm-table-cell-view', () => (
|
|
191
|
-
react_1.default.createElement(
|
|
192
|
-
|
|
193
|
-
contentDOM.setAttribute('data-col-number', String(columnNumber));
|
|
188
|
+
const renderItem = (0, ReactRenderer_1.getReactRendererFromState)(view.state).createItem('yfm-table-cell-view', () => (react_1.default.createElement(uikit_1.Portal, { container: control },
|
|
189
|
+
react_1.default.createElement(ErrorBoundary_1.ErrorLoggerBoundary, null,
|
|
190
|
+
react_1.default.createElement(Controls, { columnNumber: cellIndex, rowNumber: rowIndex, isFirstInRow: isFirstColumn, isInFirstRow: isFirstRow, getParentTable: getParentTable, view: view })))));
|
|
194
191
|
return {
|
|
195
192
|
dom,
|
|
196
193
|
contentDOM,
|
|
@@ -208,3 +205,18 @@ const yfmTableCellView = (node, view, getPos) => {
|
|
|
208
205
|
};
|
|
209
206
|
};
|
|
210
207
|
exports.yfmTableCellView = yfmTableCellView;
|
|
208
|
+
function findCellCoords(table, cell) {
|
|
209
|
+
if (!table.lastChild)
|
|
210
|
+
return null;
|
|
211
|
+
const rows = (0, nodes_1.getChildrenOfNode)(table.lastChild); // children of tBody
|
|
212
|
+
for (const row of rows) {
|
|
213
|
+
const node = (0, node_children_1.getChildByNode)(row.node, cell);
|
|
214
|
+
if (node) {
|
|
215
|
+
return {
|
|
216
|
+
rowIndex: row.index,
|
|
217
|
+
cellIndex: node.index,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
package/build/cjs/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
/** During build process, the current version will be injected here */
|
|
5
|
-
exports.VERSION = typeof '13.1.
|
|
5
|
+
exports.VERSION = typeof '13.1.1' !== 'undefined' ? '13.1.1' : 'unknown';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeViewConstructor } from 'prosemirror-view';
|
|
1
|
+
import type { NodeViewConstructor } from 'prosemirror-view';
|
|
2
2
|
import './yfmTableCellView.css';
|
|
3
3
|
export declare const yfmTableCellCn: import("@bem-react/classname").ClassNameFormatter;
|
|
4
4
|
export declare const yfmTableCellView: NodeViewConstructor;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, EllipsisVertical, TrashBin, Xmark, } from '@gravity-ui/icons';
|
|
3
|
-
import { Button, DropdownMenu, Icon } from '@gravity-ui/uikit';
|
|
4
|
-
import {
|
|
5
|
-
import { createPortal } from 'react-dom';
|
|
3
|
+
import { Button, DropdownMenu, Icon, Portal } from '@gravity-ui/uikit';
|
|
4
|
+
import { findParentNodeClosestToPos } from 'prosemirror-utils';
|
|
6
5
|
import { cn } from '../../../../../classname';
|
|
7
6
|
import { bindActions } from '../../../../../core';
|
|
8
7
|
import { i18n } from '../../../../../i18n/yfm-table';
|
|
9
8
|
import { ErrorLoggerBoundary } from '../../../../../react-utils/ErrorBoundary';
|
|
10
|
-
import { getTableDimensions,
|
|
9
|
+
import { getTableDimensions, isTableNode } from '../../../../../table-utils';
|
|
10
|
+
import { getChildByNode } from '../../../../../utils/node-children';
|
|
11
|
+
import { getChildrenOfNode } from '../../../../../utils/nodes';
|
|
11
12
|
import { getReactRendererFromState } from '../../../../behavior/ReactRenderer';
|
|
12
13
|
import { controlActions } from './actions';
|
|
13
14
|
import './yfmTableCellView.css';
|
|
@@ -160,34 +161,30 @@ const Controls = function Controls({ columnNumber, rowNumber, view, getParentTab
|
|
|
160
161
|
return controls.length ? React.createElement(React.Fragment, null, controls) : null;
|
|
161
162
|
};
|
|
162
163
|
export const yfmTableCellView = (node, view, getPos) => {
|
|
164
|
+
const getParentTable = () => findParentNodeClosestToPos(view.state.doc.resolve(getPos()), isTableNode);
|
|
165
|
+
const parentTable = getParentTable();
|
|
166
|
+
const cellCoords = parentTable ? findCellCoords(parentTable.node, node) : null;
|
|
167
|
+
// @ts-expect-error
|
|
168
|
+
if (!cellCoords)
|
|
169
|
+
return {};
|
|
170
|
+
const { cellIndex, rowIndex } = cellCoords;
|
|
171
|
+
const isFirstRow = rowIndex === 0;
|
|
172
|
+
const isFirstColumn = cellIndex === 0;
|
|
173
|
+
if (!isFirstRow && !isFirstColumn) {
|
|
174
|
+
// in this case, we don't need custom nodeView.
|
|
175
|
+
// @ts-expect-error
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
163
178
|
const dom = document.createElement('td');
|
|
164
179
|
const contentDOM = document.createElement('div');
|
|
165
180
|
const control = document.createElement('span');
|
|
166
181
|
control.setAttribute('style', 'width: 0; height: 0; float: left;');
|
|
167
182
|
dom.setAttribute('style', 'position: relative; overflow: visible;');
|
|
168
|
-
const getParentTable = () => findParentNodeClosestToPos(view.state.doc.resolve(getPos()), isTableNode);
|
|
169
|
-
const parentTable = getParentTable();
|
|
170
|
-
// @ts-expect-error
|
|
171
|
-
if (!parentTable)
|
|
172
|
-
return {};
|
|
173
|
-
const rowNodes = findChildren(parentTable === null || parentTable === void 0 ? void 0 : parentTable.node, isTableRowNode);
|
|
174
|
-
const relativeCelPos = getPos() - (parentTable === null || parentTable === void 0 ? void 0 : parentTable.pos);
|
|
175
|
-
const rowNumber = rowNodes.findIndex((_v, i) => {
|
|
176
|
-
var _a;
|
|
177
|
-
return relativeCelPos > rowNodes[i].pos &&
|
|
178
|
-
relativeCelPos < (((_a = rowNodes[i + 1]) === null || _a === void 0 ? void 0 : _a.pos) || Number.MAX_SAFE_INTEGER);
|
|
179
|
-
});
|
|
180
|
-
const parentRow = rowNodes[rowNumber];
|
|
181
|
-
const columnNumber = findChildren(parentRow.node, isTableCellNode).findIndex((c) => {
|
|
182
|
-
return c.pos === relativeCelPos - parentRow.pos - 2;
|
|
183
|
-
});
|
|
184
|
-
const isFirstInRow = rowNodes.findIndex((r) => r.pos === relativeCelPos - 2) >= 0;
|
|
185
183
|
dom.appendChild(contentDOM);
|
|
186
184
|
dom.appendChild(control);
|
|
187
|
-
const renderItem = getReactRendererFromState(view.state).createItem('yfm-table-cell-view', () =>
|
|
188
|
-
React.createElement(
|
|
189
|
-
|
|
190
|
-
contentDOM.setAttribute('data-col-number', String(columnNumber));
|
|
185
|
+
const renderItem = getReactRendererFromState(view.state).createItem('yfm-table-cell-view', () => (React.createElement(Portal, { container: control },
|
|
186
|
+
React.createElement(ErrorLoggerBoundary, null,
|
|
187
|
+
React.createElement(Controls, { columnNumber: cellIndex, rowNumber: rowIndex, isFirstInRow: isFirstColumn, isInFirstRow: isFirstRow, getParentTable: getParentTable, view: view })))));
|
|
191
188
|
return {
|
|
192
189
|
dom,
|
|
193
190
|
contentDOM,
|
|
@@ -204,3 +201,18 @@ export const yfmTableCellView = (node, view, getPos) => {
|
|
|
204
201
|
},
|
|
205
202
|
};
|
|
206
203
|
};
|
|
204
|
+
function findCellCoords(table, cell) {
|
|
205
|
+
if (!table.lastChild)
|
|
206
|
+
return null;
|
|
207
|
+
const rows = getChildrenOfNode(table.lastChild); // children of tBody
|
|
208
|
+
for (const row of rows) {
|
|
209
|
+
const node = getChildByNode(row.node, cell);
|
|
210
|
+
if (node) {
|
|
211
|
+
return {
|
|
212
|
+
rowIndex: row.index,
|
|
213
|
+
cellIndex: node.index,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
package/build/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** During build process, the current version will be injected here */
|
|
2
|
-
export const VERSION = typeof '13.1.
|
|
2
|
+
export const VERSION = typeof '13.1.1' !== 'undefined' ? '13.1.1' : 'unknown';
|