@blocknote/core 0.17.1 → 0.18.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/dist/angular-html-HQGguTAE.js +33 -0
- package/dist/angular-html-HQGguTAE.js.map +1 -0
- package/dist/angular-ts-q9PqJiJb.js +22 -0
- package/dist/angular-ts-q9PqJiJb.js.map +1 -0
- package/dist/astro-0iWgpDaK.js +17 -0
- package/dist/astro-0iWgpDaK.js.map +1 -0
- package/dist/blade-C3Z8AhvY.js +19 -0
- package/dist/blade-C3Z8AhvY.js.map +1 -0
- package/dist/blocknote.js +2338 -1491
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +10 -7
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/c-TKJGJdXV.js +7 -0
- package/dist/c-TKJGJdXV.js.map +1 -0
- package/dist/coffee-CN_y6cG3.js +9 -0
- package/dist/coffee-CN_y6cG3.js.map +1 -0
- package/dist/cpp-Be_e67JE.js +19 -0
- package/dist/cpp-Be_e67JE.js.map +1 -0
- package/dist/css-DHLSoXzW.js +7 -0
- package/dist/css-DHLSoXzW.js.map +1 -0
- package/dist/glsl-8qSUIm5B.js +9 -0
- package/dist/glsl-8qSUIm5B.js.map +1 -0
- package/dist/graphql-D7_Dk2ma.js +15 -0
- package/dist/graphql-D7_Dk2ma.js.map +1 -0
- package/dist/haml-S3dmcfEW.js +11 -0
- package/dist/haml-S3dmcfEW.js.map +1 -0
- package/dist/handlebars-DaIrqVg3.js +15 -0
- package/dist/handlebars-DaIrqVg3.js.map +1 -0
- package/dist/html-Bx3A18fV.js +11 -0
- package/dist/html-Bx3A18fV.js.map +1 -0
- package/dist/html-derivative-Cf3KTZBS.js +9 -0
- package/dist/html-derivative-Cf3KTZBS.js.map +1 -0
- package/dist/http-BphR83YX.js +15 -0
- package/dist/http-BphR83YX.js.map +1 -0
- package/dist/imba-CmP25v0O.js +9 -0
- package/dist/imba-CmP25v0O.js.map +1 -0
- package/dist/java-Dg4kxH6C.js +7 -0
- package/dist/java-Dg4kxH6C.js.map +1 -0
- package/dist/javascript-CipAzIn1.js +7 -0
- package/dist/javascript-CipAzIn1.js.map +1 -0
- package/dist/jinja-tioldiz6.js +12 -0
- package/dist/jinja-tioldiz6.js.map +1 -0
- package/dist/jison-DWJFEE_I.js +9 -0
- package/dist/jison-DWJFEE_I.js.map +1 -0
- package/dist/json-_04EL6MS.js +7 -0
- package/dist/json-_04EL6MS.js.map +1 -0
- package/dist/json5-Dwmp5XFI.js +7 -0
- package/dist/json5-Dwmp5XFI.js.map +1 -0
- package/dist/jsonc-LqD5auy0.js +7 -0
- package/dist/jsonc-LqD5auy0.js.map +1 -0
- package/dist/jsonl-B4yVuYQH.js +7 -0
- package/dist/jsonl-B4yVuYQH.js.map +1 -0
- package/dist/jsx-Mg4WaD5k.js +7 -0
- package/dist/jsx-Mg4WaD5k.js.map +1 -0
- package/dist/julia-CWi-ZdpN.js +17 -0
- package/dist/julia-CWi-ZdpN.js.map +1 -0
- package/dist/less-BBvTHIGe.js +7 -0
- package/dist/less-BBvTHIGe.js.map +1 -0
- package/dist/markdown-DAXqtk9a.js +7 -0
- package/dist/markdown-DAXqtk9a.js.map +1 -0
- package/dist/marko-0aaNgUGV.js +15 -0
- package/dist/marko-0aaNgUGV.js.map +1 -0
- package/dist/mdc-hXJ2B4O0.js +13 -0
- package/dist/mdc-hXJ2B4O0.js.map +1 -0
- package/dist/mdx-CSCKbb_f.js +7 -0
- package/dist/mdx-CSCKbb_f.js.map +1 -0
- package/dist/php-B_-4RJ09.js +19 -0
- package/dist/php-B_-4RJ09.js.map +1 -0
- package/dist/postcss-SJfTvo_B.js +7 -0
- package/dist/postcss-SJfTvo_B.js.map +1 -0
- package/dist/pug-3q2tx0nf.js +13 -0
- package/dist/pug-3q2tx0nf.js.map +1 -0
- package/dist/python-Dpup1-fE.js +7 -0
- package/dist/python-Dpup1-fE.js.map +1 -0
- package/dist/r-Chyv38Fv.js +7 -0
- package/dist/r-Chyv38Fv.js.map +1 -0
- package/dist/regexp-BF0hfxNW.js +7 -0
- package/dist/regexp-BF0hfxNW.js.map +1 -0
- package/dist/sass-p2RMoqDT.js +7 -0
- package/dist/sass-p2RMoqDT.js.map +1 -0
- package/dist/scss-DmlHSoOY.js +9 -0
- package/dist/scss-DmlHSoOY.js.map +1 -0
- package/dist/shellscript-CZpPN8_x.js +7 -0
- package/dist/shellscript-CZpPN8_x.js.map +1 -0
- package/dist/sql-DtlkUz2m.js +7 -0
- package/dist/sql-DtlkUz2m.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/stylus-DEr8eSLm.js +7 -0
- package/dist/stylus-DEr8eSLm.js.map +1 -0
- package/dist/svelte-BRIJF62h.js +15 -0
- package/dist/svelte-BRIJF62h.js.map +1 -0
- package/dist/ts-tags-qkUtuI0N.js +42 -0
- package/dist/ts-tags-qkUtuI0N.js.map +1 -0
- package/dist/tsx-DTfbgJxi.js +7 -0
- package/dist/tsx-DTfbgJxi.js.map +1 -0
- package/dist/typescript-CCd4aQHh.js +7 -0
- package/dist/typescript-CCd4aQHh.js.map +1 -0
- package/dist/vue-B3TdbERm.js +32 -0
- package/dist/vue-B3TdbERm.js.map +1 -0
- package/dist/vue-html-BGmTBZk0.js +11 -0
- package/dist/vue-html-BGmTBZk0.js.map +1 -0
- package/dist/wasm-VDIDph3E.js +7 -0
- package/dist/wasm-VDIDph3E.js.map +1 -0
- package/dist/webpack-stats.json +1 -1
- package/dist/wgsl-2np_U3Z8.js +7 -0
- package/dist/wgsl-2np_U3Z8.js.map +1 -0
- package/dist/xml-CNyphW9R.js +9 -0
- package/dist/xml-CNyphW9R.js.map +1 -0
- package/dist/yaml-DxFiVFcM.js +7 -0
- package/dist/yaml-DxFiVFcM.js.map +1 -0
- package/package.json +6 -4
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +30 -0
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +25 -0
- package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +40 -0
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +10 -0
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +40 -0
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +30 -0
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +87 -0
- package/src/api/clipboard/clipboard.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts +1 -0
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +49 -0
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/table/allColWidths/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/allColWidths/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedColWidths/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedColWidths/internal.html +1 -0
- package/src/api/exporters/html/internalHTMLSerializer.ts +2 -7
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +20 -15
- package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/table/allColWidths/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/table/basic/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/table/mixedColWidths/markdown.md +5 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +711 -0
- package/src/api/nodeConversions/blockToNode.ts +13 -2
- package/src/api/nodeConversions/nodeToBlock.ts +11 -1
- package/src/api/parsers/html/__snapshots__/parse-notion-html.json +5 -0
- package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
- package/src/api/testUtil/cases/defaultSchema.ts +95 -0
- package/src/api/testUtil/partialBlockTestUtil.ts +26 -1
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +369 -0
- package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +96 -0
- package/src/blocks/FileBlockContent/fileBlockHelpers.ts +7 -0
- package/src/blocks/TableBlockContent/TableBlockContent.ts +83 -8
- package/src/blocks/TableBlockContent/TableExtension.ts +10 -1
- package/src/blocks/defaultBlocks.ts +4 -0
- package/src/editor/Block.css +49 -2
- package/src/editor/editor.css +33 -5
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -0
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +5 -0
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +5 -0
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +18 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +224 -119
- package/src/i18n/locales/ar.ts +6 -0
- package/src/i18n/locales/de.ts +299 -294
- package/src/i18n/locales/en.ts +6 -0
- package/src/i18n/locales/es.ts +310 -274
- package/src/i18n/locales/fr.ts +6 -0
- package/src/i18n/locales/is.ts +6 -0
- package/src/i18n/locales/ja.ts +6 -0
- package/src/i18n/locales/ko.ts +6 -0
- package/src/i18n/locales/nl.ts +6 -0
- package/src/i18n/locales/pl.ts +6 -0
- package/src/i18n/locales/pt.ts +6 -0
- package/src/i18n/locales/ru.ts +6 -0
- package/src/i18n/locales/vi.ts +6 -0
- package/src/i18n/locales/zh.ts +6 -0
- package/src/index.ts +10 -5
- package/src/schema/blocks/types.ts +2 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +22 -8
- package/types/src/api/clipboard/fromClipboard/acceptedMIMETypes.d.ts +1 -1
- package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +3 -0
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +2 -3
- package/types/src/api/testUtil/cases/customBlocks.d.ts +22 -8
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +22 -8
- package/types/src/api/testUtil/cases/customStyles.d.ts +22 -8
- package/types/src/blocks/CodeBlockContent/CodeBlockContent.d.ts +57 -0
- package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -12
- package/types/src/blocks/TableBlockContent/TableExtension.d.ts +3 -0
- package/types/src/blocks/defaultBlocks.d.ts +45 -16
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +9 -5
- package/types/src/i18n/locales/de.d.ts +6 -0
- package/types/src/i18n/locales/en.d.ts +6 -0
- package/types/src/i18n/locales/es.d.ts +6 -0
- package/types/src/index.d.ts +7 -5
- package/types/src/schema/blocks/types.d.ts +2 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
|
|
2
2
|
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
3
3
|
import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js";
|
|
4
|
+
import { getNodeById } from "../../api/nodeUtil.js";
|
|
4
5
|
import { checkBlockIsDefaultType } from "../../blocks/defaultBlockTypeGuards.js";
|
|
5
|
-
import {
|
|
6
|
+
import { DefaultBlockSchema } from "../../blocks/defaultBlocks.js";
|
|
6
7
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
7
8
|
import {
|
|
8
9
|
BlockFromConfigNoChildren,
|
|
@@ -20,12 +21,14 @@ export type TableHandlesState<
|
|
|
20
21
|
S extends StyleSchema
|
|
21
22
|
> = {
|
|
22
23
|
show: boolean;
|
|
23
|
-
|
|
24
|
+
showAddOrRemoveRowsButton: boolean;
|
|
25
|
+
showAddOrRemoveColumnsButton: boolean;
|
|
26
|
+
referencePosCell: DOMRect | undefined;
|
|
24
27
|
referencePosTable: DOMRect;
|
|
25
28
|
|
|
26
29
|
block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], I, S>;
|
|
27
|
-
colIndex: number;
|
|
28
|
-
rowIndex: number;
|
|
30
|
+
colIndex: number | undefined;
|
|
31
|
+
rowIndex: number | undefined;
|
|
29
32
|
|
|
30
33
|
draggingState:
|
|
31
34
|
| {
|
|
@@ -34,6 +37,8 @@ export type TableHandlesState<
|
|
|
34
37
|
mousePos: number;
|
|
35
38
|
}
|
|
36
39
|
| undefined;
|
|
40
|
+
|
|
41
|
+
widgetContainer: HTMLElement | undefined;
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
function setHiddenDragImage(rootEl: Document | ShadowRoot) {
|
|
@@ -70,28 +75,45 @@ function getChildIndex(node: Element) {
|
|
|
70
75
|
|
|
71
76
|
// Finds the DOM element corresponding to the table cell that the target element
|
|
72
77
|
// is currently in. If the target element is not in a table cell, returns null.
|
|
73
|
-
function domCellAround(target: Element
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
function domCellAround(target: Element) {
|
|
79
|
+
let currentTarget: Element | undefined = target;
|
|
80
|
+
while (
|
|
81
|
+
currentTarget &&
|
|
82
|
+
currentTarget.nodeName !== "TD" &&
|
|
83
|
+
currentTarget.nodeName !== "TH" &&
|
|
84
|
+
!currentTarget.classList.contains("tableWrapper")
|
|
85
|
+
) {
|
|
86
|
+
if (currentTarget.classList.contains("ProseMirror")) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const parent: ParentNode | null = currentTarget.parentNode;
|
|
90
|
+
|
|
91
|
+
if (!parent || !(parent instanceof Element)) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
currentTarget = parent;
|
|
79
95
|
}
|
|
80
|
-
|
|
96
|
+
|
|
97
|
+
return currentTarget.nodeName === "TD" || currentTarget.nodeName === "TH"
|
|
98
|
+
? {
|
|
99
|
+
type: "cell",
|
|
100
|
+
domNode: currentTarget,
|
|
101
|
+
tbodyNode: currentTarget.closest("tbody"),
|
|
102
|
+
}
|
|
103
|
+
: {
|
|
104
|
+
type: "wrapper",
|
|
105
|
+
domNode: currentTarget,
|
|
106
|
+
tbodyNode: currentTarget.querySelector("tbody"),
|
|
107
|
+
};
|
|
81
108
|
}
|
|
82
109
|
|
|
83
110
|
// Hides elements in the DOMwith the provided class names.
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < elementsToHide.length; i++) {
|
|
92
|
-
(elementsToHide[i] as HTMLElement).style.visibility = "hidden";
|
|
93
|
-
}
|
|
94
|
-
});
|
|
111
|
+
function hideElements(selector: string, rootEl: Document | ShadowRoot) {
|
|
112
|
+
const elementsToHide = rootEl.querySelectorAll(selector);
|
|
113
|
+
|
|
114
|
+
for (let i = 0; i < elementsToHide.length; i++) {
|
|
115
|
+
(elementsToHide[i] as HTMLElement).style.visibility = "hidden";
|
|
116
|
+
}
|
|
95
117
|
}
|
|
96
118
|
|
|
97
119
|
export class TableHandlesView<
|
|
@@ -104,6 +126,7 @@ export class TableHandlesView<
|
|
|
104
126
|
|
|
105
127
|
public tableId: string | undefined;
|
|
106
128
|
public tablePos: number | undefined;
|
|
129
|
+
public tableElement: HTMLElement | undefined;
|
|
107
130
|
|
|
108
131
|
public menuFrozen = false;
|
|
109
132
|
|
|
@@ -130,25 +153,20 @@ export class TableHandlesView<
|
|
|
130
153
|
|
|
131
154
|
pmView.dom.addEventListener("mousemove", this.mouseMoveHandler);
|
|
132
155
|
pmView.dom.addEventListener("mousedown", this.viewMousedownHandler);
|
|
133
|
-
|
|
156
|
+
window.addEventListener("mouseup", this.mouseUpHandler);
|
|
134
157
|
|
|
135
158
|
pmView.root.addEventListener(
|
|
136
159
|
"dragover",
|
|
137
160
|
this.dragOverHandler as EventListener
|
|
138
161
|
);
|
|
139
162
|
pmView.root.addEventListener("drop", this.dropHandler as EventListener);
|
|
140
|
-
|
|
141
|
-
// Setting capture=true ensures that any parent container of the editor that
|
|
142
|
-
// gets scrolled will trigger the scroll event. Scroll events do not bubble
|
|
143
|
-
// and so won't propagate to the document by default.
|
|
144
|
-
pmView.root.addEventListener("scroll", this.scrollHandler, true);
|
|
145
163
|
}
|
|
146
164
|
|
|
147
165
|
viewMousedownHandler = () => {
|
|
148
166
|
this.mouseState = "down";
|
|
149
167
|
};
|
|
150
168
|
|
|
151
|
-
|
|
169
|
+
mouseUpHandler = (event: MouseEvent) => {
|
|
152
170
|
this.mouseState = "up";
|
|
153
171
|
this.mouseMoveHandler(event);
|
|
154
172
|
};
|
|
@@ -158,100 +176,150 @@ export class TableHandlesView<
|
|
|
158
176
|
return;
|
|
159
177
|
}
|
|
160
178
|
|
|
161
|
-
if (this.mouseState === "
|
|
179
|
+
if (this.mouseState === "selecting") {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (
|
|
184
|
+
!(event.target instanceof Element) ||
|
|
185
|
+
!this.pmView.dom.contains(event.target)
|
|
186
|
+
) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const target = domCellAround(event.target);
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
target?.type === "cell" &&
|
|
194
|
+
this.mouseState === "down" &&
|
|
195
|
+
!this.state?.draggingState
|
|
196
|
+
) {
|
|
197
|
+
// hide draghandles when selecting text as they could be in the way of the user
|
|
162
198
|
this.mouseState = "selecting";
|
|
163
199
|
|
|
164
200
|
if (this.state?.show) {
|
|
165
201
|
this.state.show = false;
|
|
202
|
+
this.state.showAddOrRemoveRowsButton = false;
|
|
203
|
+
this.state.showAddOrRemoveColumnsButton = false;
|
|
166
204
|
this.emitUpdate();
|
|
167
205
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (this.mouseState === "selecting") {
|
|
171
206
|
return;
|
|
172
207
|
}
|
|
173
208
|
|
|
174
|
-
const target = domCellAround(event.target as HTMLElement);
|
|
175
|
-
|
|
176
209
|
if (!target || !this.editor.isEditable) {
|
|
177
210
|
if (this.state?.show) {
|
|
178
211
|
this.state.show = false;
|
|
212
|
+
this.state.showAddOrRemoveRowsButton = false;
|
|
213
|
+
this.state.showAddOrRemoveColumnsButton = false;
|
|
179
214
|
this.emitUpdate();
|
|
180
215
|
}
|
|
181
216
|
return;
|
|
182
217
|
}
|
|
183
218
|
|
|
184
|
-
|
|
185
|
-
const rowIndex = getChildIndex(target.parentElement!);
|
|
186
|
-
const cellRect = target.getBoundingClientRect();
|
|
187
|
-
const tableRect =
|
|
188
|
-
target.parentElement?.parentElement?.getBoundingClientRect();
|
|
189
|
-
|
|
190
|
-
if (!tableRect) {
|
|
219
|
+
if (!target.tbodyNode) {
|
|
191
220
|
return;
|
|
192
221
|
}
|
|
193
222
|
|
|
194
|
-
const
|
|
223
|
+
const tableRect = target.tbodyNode.getBoundingClientRect();
|
|
224
|
+
|
|
225
|
+
const blockEl = getDraggableBlockFromElement(target.domNode, this.pmView);
|
|
195
226
|
if (!blockEl) {
|
|
196
227
|
return;
|
|
197
228
|
}
|
|
229
|
+
this.tableElement = blockEl.node;
|
|
198
230
|
|
|
199
|
-
let tableBlock:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
// node for the table, so we would effectively be doing the same work twice.
|
|
203
|
-
this.editor._tiptapEditor.state.doc.descendants((node, pos) => {
|
|
204
|
-
if (typeof tableBlock !== "undefined") {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (node.type.name !== "blockContainer" || node.attrs.id !== blockEl.id) {
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
231
|
+
let tableBlock:
|
|
232
|
+
| BlockFromConfigNoChildren<DefaultBlockSchema["table"], I, S>
|
|
233
|
+
| undefined;
|
|
211
234
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.editor.schema.styleSchema,
|
|
217
|
-
this.editor.blockCache
|
|
218
|
-
);
|
|
235
|
+
const pmNodeInfo = getNodeById(
|
|
236
|
+
blockEl.id,
|
|
237
|
+
this.editor._tiptapEditor.state.doc
|
|
238
|
+
);
|
|
219
239
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
240
|
+
const block = nodeToBlock(
|
|
241
|
+
pmNodeInfo.node,
|
|
242
|
+
this.editor.schema.blockSchema,
|
|
243
|
+
this.editor.schema.inlineContentSchema,
|
|
244
|
+
this.editor.schema.styleSchema,
|
|
245
|
+
this.editor.blockCache
|
|
246
|
+
);
|
|
224
247
|
|
|
225
|
-
|
|
226
|
-
|
|
248
|
+
if (checkBlockIsDefaultType("table", block, this.editor)) {
|
|
249
|
+
this.tablePos = pmNodeInfo.posBeforeNode + 1;
|
|
250
|
+
tableBlock = block;
|
|
251
|
+
}
|
|
227
252
|
|
|
228
253
|
if (!tableBlock) {
|
|
229
254
|
return;
|
|
230
255
|
}
|
|
231
256
|
|
|
232
257
|
this.tableId = blockEl.id;
|
|
258
|
+
const widgetContainer = target.domNode
|
|
259
|
+
.closest(".tableWrapper")
|
|
260
|
+
?.querySelector(".table-widgets-container") as HTMLElement;
|
|
261
|
+
|
|
262
|
+
if (target?.type === "wrapper") {
|
|
263
|
+
// if we're just to the right or below the table, show the extend buttons
|
|
264
|
+
// (this is a bit hacky. It would probably be cleaner to render the extend buttons in the Table NodeView instead)
|
|
265
|
+
const belowTable =
|
|
266
|
+
event.clientY >= tableRect.bottom - 1 && // -1 to account for fractions of pixels in "bottom"
|
|
267
|
+
event.clientY < tableRect.bottom + 20;
|
|
268
|
+
const toRightOfTable =
|
|
269
|
+
event.clientX >= tableRect.right - 1 &&
|
|
270
|
+
event.clientX < tableRect.right + 20;
|
|
271
|
+
|
|
272
|
+
// without this check, we'd also hide draghandles when hovering over them
|
|
273
|
+
const hideHandles =
|
|
274
|
+
event.clientX > tableRect.right || event.clientY > tableRect.bottom;
|
|
275
|
+
|
|
276
|
+
this.state = {
|
|
277
|
+
...this.state!,
|
|
278
|
+
show: true,
|
|
279
|
+
showAddOrRemoveRowsButton: belowTable,
|
|
280
|
+
showAddOrRemoveColumnsButton: toRightOfTable,
|
|
281
|
+
referencePosTable: tableRect,
|
|
282
|
+
block: tableBlock,
|
|
283
|
+
widgetContainer,
|
|
284
|
+
colIndex: hideHandles ? undefined : this.state!.colIndex,
|
|
285
|
+
rowIndex: hideHandles ? undefined : this.state!.rowIndex,
|
|
286
|
+
referencePosCell: hideHandles
|
|
287
|
+
? undefined
|
|
288
|
+
: this.state!.referencePosCell,
|
|
289
|
+
};
|
|
290
|
+
} else {
|
|
291
|
+
const colIndex = getChildIndex(target.domNode);
|
|
292
|
+
const rowIndex = getChildIndex(target.domNode.parentElement!);
|
|
293
|
+
const cellRect = target.domNode.getBoundingClientRect();
|
|
294
|
+
|
|
295
|
+
if (
|
|
296
|
+
this.state !== undefined &&
|
|
297
|
+
this.state.show &&
|
|
298
|
+
this.tableId === blockEl.id &&
|
|
299
|
+
this.state.rowIndex === rowIndex &&
|
|
300
|
+
this.state.colIndex === colIndex
|
|
301
|
+
) {
|
|
302
|
+
// no update needed
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
233
305
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
306
|
+
this.state = {
|
|
307
|
+
show: true,
|
|
308
|
+
showAddOrRemoveColumnsButton:
|
|
309
|
+
colIndex === tableBlock.content.rows[0].cells.length - 1,
|
|
310
|
+
showAddOrRemoveRowsButton:
|
|
311
|
+
rowIndex === tableBlock.content.rows.length - 1,
|
|
312
|
+
referencePosTable: tableRect,
|
|
313
|
+
|
|
314
|
+
block: tableBlock,
|
|
315
|
+
draggingState: undefined,
|
|
316
|
+
referencePosCell: cellRect,
|
|
317
|
+
colIndex: colIndex,
|
|
318
|
+
rowIndex: rowIndex,
|
|
319
|
+
|
|
320
|
+
widgetContainer,
|
|
321
|
+
};
|
|
242
322
|
}
|
|
243
|
-
|
|
244
|
-
this.state = {
|
|
245
|
-
show: true,
|
|
246
|
-
referencePosCell: cellRect,
|
|
247
|
-
referencePosTable: tableRect,
|
|
248
|
-
|
|
249
|
-
block: tableBlock,
|
|
250
|
-
colIndex: colIndex,
|
|
251
|
-
rowIndex: rowIndex,
|
|
252
|
-
|
|
253
|
-
draggingState: undefined,
|
|
254
|
-
};
|
|
255
323
|
this.emitUpdate();
|
|
256
324
|
|
|
257
325
|
return false;
|
|
@@ -265,12 +333,8 @@ export class TableHandlesView<
|
|
|
265
333
|
event.preventDefault();
|
|
266
334
|
event.dataTransfer!.dropEffect = "move";
|
|
267
335
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
"column-resize-handle",
|
|
271
|
-
"prosemirror-dropcursor-block",
|
|
272
|
-
"prosemirror-dropcursor-inline",
|
|
273
|
-
],
|
|
336
|
+
hideElements(
|
|
337
|
+
".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",
|
|
274
338
|
this.pmView.root
|
|
275
339
|
);
|
|
276
340
|
|
|
@@ -358,25 +422,37 @@ export class TableHandlesView<
|
|
|
358
422
|
};
|
|
359
423
|
|
|
360
424
|
dropHandler = (event: DragEvent) => {
|
|
425
|
+
this.mouseState = "up";
|
|
361
426
|
if (this.state === undefined || this.state.draggingState === undefined) {
|
|
362
427
|
return;
|
|
363
428
|
}
|
|
364
429
|
|
|
430
|
+
if (
|
|
431
|
+
this.state.rowIndex === undefined ||
|
|
432
|
+
this.state.colIndex === undefined
|
|
433
|
+
) {
|
|
434
|
+
throw new Error(
|
|
435
|
+
"Attempted to drop table row or column, but no table block was hovered prior."
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
365
439
|
event.preventDefault();
|
|
366
440
|
|
|
441
|
+
const { draggingState, colIndex, rowIndex } = this.state;
|
|
442
|
+
|
|
367
443
|
const rows = this.state.block.content.rows;
|
|
368
444
|
|
|
369
|
-
if (
|
|
370
|
-
const rowToMove = rows[
|
|
371
|
-
rows.splice(
|
|
372
|
-
rows.splice(
|
|
445
|
+
if (draggingState.draggedCellOrientation === "row") {
|
|
446
|
+
const rowToMove = rows[draggingState.originalIndex];
|
|
447
|
+
rows.splice(draggingState.originalIndex, 1);
|
|
448
|
+
rows.splice(rowIndex, 0, rowToMove);
|
|
373
449
|
} else {
|
|
374
450
|
const cellsToMove = rows.map(
|
|
375
|
-
(row) => row.cells[
|
|
451
|
+
(row) => row.cells[draggingState.originalIndex]
|
|
376
452
|
);
|
|
377
453
|
rows.forEach((row, rowIndex) => {
|
|
378
|
-
row.cells.splice(
|
|
379
|
-
row.cells.splice(
|
|
454
|
+
row.cells.splice(draggingState.originalIndex, 1);
|
|
455
|
+
row.cells.splice(colIndex, 0, cellsToMove[rowIndex]);
|
|
380
456
|
});
|
|
381
457
|
}
|
|
382
458
|
|
|
@@ -392,26 +468,45 @@ export class TableHandlesView<
|
|
|
392
468
|
// the existing selection out of the block.
|
|
393
469
|
this.editor.setTextCursorPosition(this.state.block.id);
|
|
394
470
|
};
|
|
471
|
+
// Updates drag handle positions on table content updates.
|
|
472
|
+
update() {
|
|
473
|
+
if (!this.state || !this.state.show) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
395
476
|
|
|
396
|
-
|
|
397
|
-
if (
|
|
398
|
-
|
|
399
|
-
`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`
|
|
400
|
-
)!;
|
|
401
|
-
const cellElement = tableElement.querySelector(
|
|
402
|
-
`tr:nth-child(${this.state.rowIndex + 1}) > td:nth-child(${
|
|
403
|
-
this.state.colIndex + 1
|
|
404
|
-
})`
|
|
405
|
-
)!;
|
|
406
|
-
|
|
407
|
-
this.state.referencePosTable = tableElement.getBoundingClientRect();
|
|
408
|
-
this.state.referencePosCell = cellElement.getBoundingClientRect();
|
|
409
|
-
this.emitUpdate();
|
|
477
|
+
const tableBody = this.tableElement!.querySelector("tbody");
|
|
478
|
+
if (!tableBody) {
|
|
479
|
+
return;
|
|
410
480
|
}
|
|
411
|
-
|
|
481
|
+
|
|
482
|
+
if (
|
|
483
|
+
this.state.rowIndex !== undefined &&
|
|
484
|
+
this.state.colIndex !== undefined
|
|
485
|
+
) {
|
|
486
|
+
// If rows or columns are deleted in the update, the hovered indices for
|
|
487
|
+
// those may now be out of bounds. If this is the case, they are moved to
|
|
488
|
+
// the new last row or column.
|
|
489
|
+
if (this.state.rowIndex >= tableBody.children.length) {
|
|
490
|
+
this.state.rowIndex = tableBody.children.length - 1;
|
|
491
|
+
}
|
|
492
|
+
if (this.state.colIndex >= tableBody.children[0].children.length) {
|
|
493
|
+
this.state.colIndex = tableBody.children[0].children.length - 1;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const row = tableBody.children[this.state.rowIndex];
|
|
497
|
+
const cell = row.children[this.state.colIndex];
|
|
498
|
+
this.state.referencePosCell = cell.getBoundingClientRect();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
this.state.block = this.editor.getBlock(this.state.block.id)!;
|
|
502
|
+
this.state.referencePosTable = tableBody.getBoundingClientRect();
|
|
503
|
+
this.emitUpdate();
|
|
504
|
+
}
|
|
412
505
|
|
|
413
506
|
destroy() {
|
|
414
507
|
this.pmView.dom.removeEventListener("mousemove", this.mouseMoveHandler);
|
|
508
|
+
window.removeEventListener("mouseup", this.mouseUpHandler);
|
|
509
|
+
this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler);
|
|
415
510
|
this.pmView.root.removeEventListener(
|
|
416
511
|
"dragover",
|
|
417
512
|
this.dragOverHandler as EventListener
|
|
@@ -420,7 +515,6 @@ export class TableHandlesView<
|
|
|
420
515
|
"drop",
|
|
421
516
|
this.dropHandler as EventListener
|
|
422
517
|
);
|
|
423
|
-
this.pmView.root.removeEventListener("scroll", this.scrollHandler, true);
|
|
424
518
|
}
|
|
425
519
|
}
|
|
426
520
|
|
|
@@ -467,6 +561,10 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
467
561
|
? this.view.state.rowIndex
|
|
468
562
|
: this.view.state.colIndex;
|
|
469
563
|
|
|
564
|
+
if (newIndex === undefined) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
|
|
470
568
|
const decorations: Decoration[] = [];
|
|
471
569
|
|
|
472
570
|
if (newIndex === this.view.state.draggingState.originalIndex) {
|
|
@@ -547,6 +645,7 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
547
645
|
(newIndex > this.view.state.draggingState.originalIndex
|
|
548
646
|
? cellNode.nodeSize - 2
|
|
549
647
|
: 0);
|
|
648
|
+
|
|
550
649
|
decorations.push(
|
|
551
650
|
// The widget is a small bar which spans the height of the cell.
|
|
552
651
|
Decoration.widget(decorationPos, () => {
|
|
@@ -592,7 +691,10 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
592
691
|
dataTransfer: DataTransfer | null;
|
|
593
692
|
clientX: number;
|
|
594
693
|
}) => {
|
|
595
|
-
if (
|
|
694
|
+
if (
|
|
695
|
+
this.view!.state === undefined ||
|
|
696
|
+
this.view!.state.colIndex === undefined
|
|
697
|
+
) {
|
|
596
698
|
throw new Error(
|
|
597
699
|
"Attempted to drag table column, but no table block was hovered prior."
|
|
598
700
|
);
|
|
@@ -628,7 +730,10 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
628
730
|
dataTransfer: DataTransfer | null;
|
|
629
731
|
clientY: number;
|
|
630
732
|
}) => {
|
|
631
|
-
if (
|
|
733
|
+
if (
|
|
734
|
+
this.view!.state === undefined ||
|
|
735
|
+
this.view!.state.rowIndex === undefined
|
|
736
|
+
) {
|
|
632
737
|
throw new Error(
|
|
633
738
|
"Attempted to drag table row, but no table block was hovered prior."
|
|
634
739
|
);
|
package/src/i18n/locales/ar.ts
CHANGED
|
@@ -52,6 +52,12 @@ export const ar: Dictionary = {
|
|
|
52
52
|
aliases: ["ف", "فقرة"],
|
|
53
53
|
group: "الكتل الأساسية",
|
|
54
54
|
},
|
|
55
|
+
code_block: {
|
|
56
|
+
title: "كود",
|
|
57
|
+
subtext: "يستخدم لعرض الكود مع تحديد الصيغة",
|
|
58
|
+
aliases: ["كود", "مسبق"],
|
|
59
|
+
group: "الكتل الأساسية",
|
|
60
|
+
},
|
|
55
61
|
table: {
|
|
56
62
|
title: "جدول",
|
|
57
63
|
subtext: "يستخدم للجداول",
|