@jpmorganchase/mosaic-content-editor-plugin 0.1.0-beta.72 → 0.1.0-beta.73
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/package.json +6 -3
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -687
- package/src/components/ActionMenu/ActionMenu.css.ts +0 -9
- package/src/components/ActionMenu/ActionMenu.tsx +0 -26
- package/src/components/BaseToolbar/BaseToolbar.css.ts +0 -21
- package/src/components/BaseToolbar/BaseToolbar.tsx +0 -13
- package/src/components/BaseTooltray/BaseTooltray.css.ts +0 -31
- package/src/components/BaseTooltray/BaseTooltray.tsx +0 -22
- package/src/components/ContentEditor.tsx +0 -14
- package/src/components/Dialog.css.ts +0 -7
- package/src/components/Dialog.tsx +0 -12
- package/src/components/Editor.css.ts +0 -64
- package/src/components/Editor.tsx +0 -145
- package/src/components/EditorControls.css.ts +0 -6
- package/src/components/EditorControls.tsx +0 -37
- package/src/components/LinkEditor/EditLinkButton.tsx +0 -9
- package/src/components/LinkEditor/LinkEditor.css.ts +0 -15
- package/src/components/LinkEditor/LinkEditor.tsx +0 -136
- package/src/components/LinkEditor/SaveAdornment.tsx +0 -17
- package/src/components/PersistEditDialog/PersistStatus.css.ts +0 -21
- package/src/components/PersistEditDialog/PersistStatus.tsx +0 -57
- package/src/components/PersistEditDialog/__tests__/index.test.tsx +0 -90
- package/src/components/PersistEditDialog/index.css.ts +0 -14
- package/src/components/PersistEditDialog/index.tsx +0 -152
- package/src/components/Popper/Popper.css.ts +0 -12
- package/src/components/Popper/Popper.tsx +0 -36
- package/src/components/SaveButton.tsx +0 -23
- package/src/components/ScrollableSection/ScrollableSection.css.ts +0 -10
- package/src/components/ScrollableSection/ScrollableSection.tsx +0 -20
- package/src/components/StatusBanner.tsx +0 -16
- package/src/components/Toolbar/InsertBlockDropdown.tsx +0 -134
- package/src/components/Toolbar/InsertHorizontalRule.tsx +0 -18
- package/src/components/Toolbar/InsertImage.css.ts +0 -7
- package/src/components/Toolbar/InsertImage.tsx +0 -138
- package/src/components/Toolbar/InsertLink.css.ts +0 -7
- package/src/components/Toolbar/InsertLink.tsx +0 -148
- package/src/components/Toolbar/InsertTable.css.ts +0 -52
- package/src/components/Toolbar/InsertTable.tsx +0 -196
- package/src/components/Toolbar/TextFormatTooltray.css.ts +0 -22
- package/src/components/Toolbar/TextFormatTooltray.tsx +0 -113
- package/src/components/Toolbar/Toolbar.tsx +0 -52
- package/src/components/Toolbar/ToolbarButton.css.ts +0 -11
- package/src/components/Toolbar/ToolbarButton.tsx +0 -41
- package/src/components/Toolbar/ToolbarSeparator.css.ts +0 -28
- package/src/components/Toolbar/ToolbarSepartor.tsx +0 -13
- package/src/components/__tests__/EditorControls.test.tsx +0 -69
- package/src/components/__tests__/StatusBanner.test.tsx +0 -33
- package/src/hooks/useEditHistory.ts +0 -49
- package/src/hooks/useWorkflowFeed.ts +0 -69
- package/src/index.ts +0 -5
- package/src/nodes/index.ts +0 -23
- package/src/plugins/FloatingToolbarPlugin.css.ts +0 -14
- package/src/plugins/FloatingToolbarPlugin.tsx +0 -101
- package/src/plugins/HorizontalRulePlugin.tsx +0 -39
- package/src/plugins/MarkdownImagePlugin.tsx +0 -58
- package/src/plugins/MarkdownLinkPlugin.tsx +0 -69
- package/src/plugins/PreviewPlugin.tsx +0 -71
- package/src/plugins/TableActionMenuPlugin.css.ts +0 -29
- package/src/plugins/TableActionMenuPlugin.tsx +0 -274
- package/src/store/__tests__/index.test.ts +0 -171
- package/src/store/index.ts +0 -84
- package/src/theme/index.css.ts +0 -39
- package/src/theme/index.ts +0 -22
- package/src/transformers/horizontalRule.ts +0 -25
- package/src/transformers/index.ts +0 -6
- package/src/transformers/link.ts +0 -3
- package/src/transformers/tableRule.ts +0 -193
- package/src/utils/getSelectedNode.ts +0 -16
- package/tsconfig.json +0 -8
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { ElementTransformer } from '@lexical/markdown';
|
|
2
|
-
import type { ElementNode, LexicalNode } from 'lexical';
|
|
3
|
-
import {
|
|
4
|
-
$createTableCellNode,
|
|
5
|
-
$createTableNode,
|
|
6
|
-
$createTableRowNode,
|
|
7
|
-
$isTableNode,
|
|
8
|
-
$isTableRowNode,
|
|
9
|
-
TableCellHeaderStates,
|
|
10
|
-
TableCellNode,
|
|
11
|
-
TableNode,
|
|
12
|
-
TableRowNode
|
|
13
|
-
} from '@lexical/table';
|
|
14
|
-
import {
|
|
15
|
-
$createParagraphNode,
|
|
16
|
-
$createTextNode,
|
|
17
|
-
$isElementNode,
|
|
18
|
-
$isParagraphNode,
|
|
19
|
-
$isTextNode
|
|
20
|
-
} from 'lexical';
|
|
21
|
-
|
|
22
|
-
import LINK_TRANSFORMER from './link';
|
|
23
|
-
|
|
24
|
-
const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;
|
|
25
|
-
const TABLE_HEADER_REG_EXP = /(---)/;
|
|
26
|
-
|
|
27
|
-
export const TABLE_RULE: ElementTransformer = {
|
|
28
|
-
dependencies: [TableNode, TableRowNode, TableCellNode],
|
|
29
|
-
export: (node: LexicalNode, exportChildren: (elementNode: ElementNode) => string) => {
|
|
30
|
-
if (!$isTableNode(node)) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const output: string[] = [];
|
|
35
|
-
let columnCount: number | null = null;
|
|
36
|
-
|
|
37
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
38
|
-
for (const row of node.getChildren()) {
|
|
39
|
-
const rowOutput: string[] = [];
|
|
40
|
-
|
|
41
|
-
if ($isTableRowNode(row)) {
|
|
42
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
43
|
-
for (const cell of row.getChildren()) {
|
|
44
|
-
if ($isElementNode(cell)) {
|
|
45
|
-
rowOutput.push(exportChildren(cell));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (columnCount === null) {
|
|
49
|
-
columnCount = rowOutput.length;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
output.push(`| ${rowOutput.join(' | ')} |`);
|
|
53
|
-
}
|
|
54
|
-
addHeaderDividerToOutput(output, columnCount);
|
|
55
|
-
return output.join('\n');
|
|
56
|
-
},
|
|
57
|
-
regExp: TABLE_ROW_REG_EXP,
|
|
58
|
-
replace: (parentNode, _1, match) => {
|
|
59
|
-
const matchCells = mapToTableCells(match[0]);
|
|
60
|
-
|
|
61
|
-
if (matchCells == null) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const rows = handleHeaderDashes(matchCells);
|
|
66
|
-
let sibling = parentNode.getPreviousSibling();
|
|
67
|
-
let maxCells = matchCells.length;
|
|
68
|
-
|
|
69
|
-
while (sibling) {
|
|
70
|
-
if (!$isParagraphNode(sibling)) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (sibling.getChildrenSize() !== 1) {
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const firstChild = sibling.getFirstChild();
|
|
79
|
-
|
|
80
|
-
if (!$isTextNode(firstChild)) {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const cells = mapToTableCells(firstChild.getTextContent());
|
|
85
|
-
|
|
86
|
-
if (cells == null) {
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
maxCells = Math.max(maxCells, cells.length);
|
|
91
|
-
rows.unshift(cells);
|
|
92
|
-
const previousSibling = sibling.getPreviousSibling();
|
|
93
|
-
sibling.remove();
|
|
94
|
-
sibling = previousSibling;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const table = createTableNode(rows, maxCells);
|
|
98
|
-
|
|
99
|
-
const previousSibling = parentNode.getPreviousSibling();
|
|
100
|
-
if ($isTableNode(previousSibling) && getTableColumnsSize(previousSibling) === maxCells) {
|
|
101
|
-
previousSibling.append(...table.getChildren());
|
|
102
|
-
parentNode.remove();
|
|
103
|
-
} else {
|
|
104
|
-
parentNode.replace(table);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
table.selectEnd();
|
|
108
|
-
},
|
|
109
|
-
type: 'element'
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
function getTableColumnsSize(table: TableNode) {
|
|
113
|
-
const row = table.getFirstChild();
|
|
114
|
-
return $isTableRowNode(row) ? row.getChildrenSize() : 0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const createTableCell = (textContent: string | null | undefined): TableCellNode => {
|
|
118
|
-
const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
|
|
119
|
-
const paragraph = $createParagraphNode();
|
|
120
|
-
|
|
121
|
-
if (textContent != null) {
|
|
122
|
-
const textNode = $createTextNode(textContent.trim());
|
|
123
|
-
paragraph.append(textNode);
|
|
124
|
-
/**
|
|
125
|
-
* Table cells are treated as text only.
|
|
126
|
-
* However, it is very common to see links inside tables
|
|
127
|
-
* so we check if the content is a markdown link and render a link accordingly
|
|
128
|
-
*/
|
|
129
|
-
const linkMatch = textContent.trim().match(LINK_TRANSFORMER.regExp);
|
|
130
|
-
if (linkMatch) {
|
|
131
|
-
LINK_TRANSFORMER.replace(textNode, linkMatch);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
cell.append(paragraph);
|
|
136
|
-
return cell;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const mapToTableCells = (textContent: string): Array<TableCellNode> | null => {
|
|
140
|
-
const match = textContent.match(TABLE_ROW_REG_EXP);
|
|
141
|
-
|
|
142
|
-
if (!match || !match[1]) {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return match[1].split('|').map(text => createTableCell(text));
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const addHeaderDividerToOutput = (output: string[], columnCount?: number | null) => {
|
|
150
|
-
let divider = '';
|
|
151
|
-
|
|
152
|
-
if (!columnCount) {
|
|
153
|
-
return output;
|
|
154
|
-
}
|
|
155
|
-
for (let i = 0; i < columnCount + 1; i++) {
|
|
156
|
-
divider = divider.concat('|');
|
|
157
|
-
|
|
158
|
-
if (i < columnCount) {
|
|
159
|
-
divider = divider.concat('----');
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const headerMatch = output[1]?.match(TABLE_HEADER_REG_EXP);
|
|
164
|
-
if (headerMatch) {
|
|
165
|
-
// output already has the header dashes
|
|
166
|
-
return output;
|
|
167
|
-
}
|
|
168
|
-
return output.splice(1, 0, divider);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* if a table has the markdown dashes then
|
|
173
|
-
* we don't want to render them as part of the table
|
|
174
|
-
*/
|
|
175
|
-
const handleHeaderDashes = (matchCells: TableCellNode[]) => {
|
|
176
|
-
const test = matchCells[0].getFirstChild()?.getTextContent();
|
|
177
|
-
const headerMatch = test?.match(TABLE_HEADER_REG_EXP);
|
|
178
|
-
return headerMatch === null ? [matchCells] : [];
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const createTableNode = (rows: TableCellNode[][], maxCells: number) => {
|
|
182
|
-
const table = $createTableNode();
|
|
183
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
184
|
-
for (const cells of rows) {
|
|
185
|
-
const tableRow = $createTableRowNode();
|
|
186
|
-
table.append(tableRow);
|
|
187
|
-
|
|
188
|
-
for (let i = 0; i < maxCells; i++) {
|
|
189
|
-
tableRow.append(i < cells.length ? cells[i] : createTableCell(null));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return table;
|
|
193
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { $isAtNodeEnd } from '@lexical/selection';
|
|
2
|
-
import { ElementNode, RangeSelection, TextNode } from 'lexical';
|
|
3
|
-
|
|
4
|
-
export function getSelectedNode(selection: RangeSelection): TextNode | ElementNode {
|
|
5
|
-
const { anchor, focus } = selection;
|
|
6
|
-
const anchorNode = selection.anchor.getNode();
|
|
7
|
-
const focusNode = selection.focus.getNode();
|
|
8
|
-
if (anchorNode === focusNode) {
|
|
9
|
-
return anchorNode;
|
|
10
|
-
}
|
|
11
|
-
const isBackward = selection.isBackward();
|
|
12
|
-
if (isBackward) {
|
|
13
|
-
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
14
|
-
}
|
|
15
|
-
return $isAtNodeEnd(anchor) ? focusNode : anchorNode;
|
|
16
|
-
}
|