@handlewithcare/react-prosemirror 2.8.0-tiptap.16 → 2.8.0-tiptap.17
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/cjs/plugins/beforeInputPlugin.js +3 -9
- package/dist/cjs/tiptap/TiptapEditorContent.js +8 -4
- package/dist/cjs/tiptap/TiptapNodeView.js +26 -0
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +59 -0
- package/dist/esm/plugins/beforeInputPlugin.js +3 -9
- package/dist/esm/tiptap/TiptapEditorContent.js +9 -5
- package/dist/esm/tiptap/TiptapNodeView.js +22 -0
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +60 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/props.d.ts +26 -26
- package/dist/types/tiptap/TiptapNodeView.d.ts +15 -0
- package/package.json +1 -1
- package/dist/esm/@jest/pattern/src/__tests__/TestPathPatterns.test.js +0 -241
- package/dist/esm/@swc/cli/lib/swc/__tests__/compile.test.js +0 -19
- package/dist/esm/@swc/cli/lib/swc/__tests__/options.test.js +0 -315
- package/dist/esm/@swc/cli/lib/swc/__tests__/sources.test.js +0 -161
- package/dist/esm/@uiw/react-codemirror/src/__tests__/index.test.js +0 -111
- package/dist/esm/cheerio/src/__tests__/deprecated.spec.js +0 -249
- package/dist/esm/cheerio/src/__tests__/xml.spec.js +0 -55
- package/dist/esm/components/__tests__/ProseMirror.composition.test.js +0 -395
- package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +0 -266
- package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +0 -968
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +0 -335
- package/dist/esm/components/__tests__/ProseMirror.mobile.test.js +0 -54
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +0 -553
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +0 -440
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -324
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +0 -98
- package/dist/esm/hooks/__tests__/useEditorEffect.test.js +0 -134
- package/dist/esm/jsx-ast-utils/__tests__/helper.js +0 -83
- package/dist/esm/jsx-ast-utils/__tests__/src/elementType-test.js +0 -76
- package/dist/esm/jsx-ast-utils/__tests__/src/eventHandlers-test.js +0 -98
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-parser-test.js +0 -188
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-test.js +0 -119
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-babelparser-test.js +0 -393
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-flowparser-test.js +0 -379
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-babelparser-test.js +0 -925
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-flowparser-test.js +0 -700
- package/dist/esm/jsx-ast-utils/__tests__/src/hasProp-test.js +0 -350
- package/dist/esm/jsx-ast-utils/__tests__/src/index-test.js +0 -24
- package/dist/esm/jsx-ast-utils/__tests__/src/propName-test.js +0 -37
- package/dist/esm/plugins/__tests__/reactKeys.test.js +0 -77
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.js +0 -97
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.js +0 -319
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.js +0 -62
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.js +0 -80
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.js +0 -22
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.js +0 -20
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.js +0 -219
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.js +0 -323
- package/dist/esm/tsconfig-paths/src/__tests__/config-loader.test.js +0 -89
- package/dist/esm/tsconfig-paths/src/__tests__/data/match-path-data.js +0 -314
- package/dist/esm/tsconfig-paths/src/__tests__/filesystem.test.js +0 -58
- package/dist/esm/tsconfig-paths/src/__tests__/mapping-entry.test.js +0 -76
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-async.test.js +0 -12
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-sync.test.js +0 -10
- package/dist/esm/tsconfig-paths/src/__tests__/try-path.test.js +0 -214
- package/dist/esm/tsconfig-paths/src/__tests__/tsconfig-loader.test.js +0 -296
|
@@ -16,15 +16,9 @@ function insertText(view, eventData) {
|
|
|
16
16
|
if (eventData === null) return false;
|
|
17
17
|
const from = options.from ?? view.state.selection.from;
|
|
18
18
|
const to = options.to ?? view.state.selection.to;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// view.state.tr.insertText(eventData, from, to)
|
|
23
|
-
// )
|
|
24
|
-
// )
|
|
25
|
-
// ) {
|
|
26
|
-
// return true;
|
|
27
|
-
// }
|
|
19
|
+
if (view.someProp("handleTextInput", (f)=>f(view, from, to, eventData, ()=>view.state.tr.insertText(eventData, from, to)))) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
28
22
|
const { tr } = view.state;
|
|
29
23
|
if (options.marks) tr.ensureMarks(options.marks);
|
|
30
24
|
tr.insertText(eventData, from, to);
|
|
@@ -10,8 +10,10 @@ Object.defineProperty(exports, "TiptapEditorContent", {
|
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _reactdom = require("react-dom");
|
|
13
|
+
const _ReactEditorView = require("../ReactEditorView.js");
|
|
13
14
|
const _ProseMirrorDoc = require("../components/ProseMirrorDoc.js");
|
|
14
|
-
const
|
|
15
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
16
|
+
const _useClientLayoutEffect = require("../hooks/useClientLayoutEffect.js");
|
|
15
17
|
function _getRequireWildcardCache(nodeInterop) {
|
|
16
18
|
if (typeof WeakMap !== "function") return null;
|
|
17
19
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -102,8 +104,9 @@ function getInstance() {
|
|
|
102
104
|
function TiptapEditorContent(param) {
|
|
103
105
|
let { editor: editorProp, ...props } = param;
|
|
104
106
|
const editor = editorProp;
|
|
105
|
-
(0,
|
|
106
|
-
|
|
107
|
+
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
108
|
+
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
109
|
+
if (!(view instanceof _ReactEditorView.ReactEditorView) || editor.view === view) {
|
|
107
110
|
return;
|
|
108
111
|
}
|
|
109
112
|
// @ts-expect-error private property
|
|
@@ -128,7 +131,8 @@ function TiptapEditorContent(param) {
|
|
|
128
131
|
editor.contentComponent = null;
|
|
129
132
|
};
|
|
130
133
|
}, [
|
|
131
|
-
editor
|
|
134
|
+
editor,
|
|
135
|
+
view
|
|
132
136
|
]);
|
|
133
137
|
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_ProseMirrorDoc.ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ _react.default.createElement(Portals, {
|
|
134
138
|
contentComponent: editor.contentComponent
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ReactProseMirrorNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ReactProseMirrorNodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@tiptap/core");
|
|
12
|
+
let ReactProseMirrorNodeView = class ReactProseMirrorNodeView extends _core.NodeView {
|
|
13
|
+
_dom;
|
|
14
|
+
_contentDOM;
|
|
15
|
+
constructor(component, props, dom, contentDOM, options){
|
|
16
|
+
super(component, props, options);
|
|
17
|
+
this._dom = dom;
|
|
18
|
+
this._contentDOM = contentDOM;
|
|
19
|
+
}
|
|
20
|
+
get dom() {
|
|
21
|
+
return this._dom;
|
|
22
|
+
}
|
|
23
|
+
get contentDOM() {
|
|
24
|
+
return this._contentDOM;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -16,5 +16,64 @@ const ReactProseMirror = _core.Extension.create({
|
|
|
16
16
|
return [
|
|
17
17
|
(0, _reactKeys.reactKeys)()
|
|
18
18
|
];
|
|
19
|
+
},
|
|
20
|
+
addCommands () {
|
|
21
|
+
return {
|
|
22
|
+
/**
|
|
23
|
+
* Command that reorders the adjacent nodes starting
|
|
24
|
+
* at the provided position.
|
|
25
|
+
*
|
|
26
|
+
* @param pos - The `start` position of the parent of the nodes being reordered
|
|
27
|
+
* @param order - The new order for the nodes, expressed as an array of indices. For
|
|
28
|
+
* example, to swap the first two nodes in a set of three, `order`
|
|
29
|
+
* would be set to `[1, 0, 2]`. To move the first node to the end,
|
|
30
|
+
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
31
|
+
*/ reorderSiblings (initialPos, order) {
|
|
32
|
+
return function reorderSiblingsCommand(param) {
|
|
33
|
+
let { tr, dispatch } = param;
|
|
34
|
+
const pos = tr.mapping.map(initialPos);
|
|
35
|
+
const $pos = tr.doc.resolve(pos);
|
|
36
|
+
if ($pos.start() !== pos) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (!dispatch) return true;
|
|
40
|
+
const nodes = $pos.parent.children;
|
|
41
|
+
const reordered = nodes.map((node, i)=>[
|
|
42
|
+
node,
|
|
43
|
+
i
|
|
44
|
+
]).sort((param, param1)=>{
|
|
45
|
+
let [, a] = param, [, b] = param1;
|
|
46
|
+
return order[a] - order[b];
|
|
47
|
+
}).map((param)=>{
|
|
48
|
+
let [node] = param;
|
|
49
|
+
return node;
|
|
50
|
+
});
|
|
51
|
+
tr.replaceWith(pos, $pos.parent.content.size + pos, reordered);
|
|
52
|
+
const meta = {
|
|
53
|
+
overrides: {}
|
|
54
|
+
};
|
|
55
|
+
const oldPositions = [];
|
|
56
|
+
let start = pos;
|
|
57
|
+
for (const node of nodes){
|
|
58
|
+
oldPositions.push(start);
|
|
59
|
+
start += node.nodeSize;
|
|
60
|
+
}
|
|
61
|
+
start = pos;
|
|
62
|
+
const newPositions = [];
|
|
63
|
+
for(let i = 0; i < reordered.length; i++){
|
|
64
|
+
const node = reordered[i];
|
|
65
|
+
newPositions[order[i]] = start;
|
|
66
|
+
start += node.nodeSize;
|
|
67
|
+
}
|
|
68
|
+
for(let i = 0; i < oldPositions.length; i++){
|
|
69
|
+
const oldPosition = oldPositions[i];
|
|
70
|
+
const newPosition = newPositions[i];
|
|
71
|
+
meta.overrides[oldPosition] = newPosition;
|
|
72
|
+
}
|
|
73
|
+
tr.setMeta(_reactKeys.reactKeysPluginKey, meta);
|
|
74
|
+
return true;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
19
78
|
}
|
|
20
79
|
});
|
|
@@ -6,15 +6,9 @@ function insertText(view, eventData) {
|
|
|
6
6
|
if (eventData === null) return false;
|
|
7
7
|
const from = options.from ?? view.state.selection.from;
|
|
8
8
|
const to = options.to ?? view.state.selection.to;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// view.state.tr.insertText(eventData, from, to)
|
|
13
|
-
// )
|
|
14
|
-
// )
|
|
15
|
-
// ) {
|
|
16
|
-
// return true;
|
|
17
|
-
// }
|
|
9
|
+
if (view.someProp("handleTextInput", (f)=>f(view, from, to, eventData, ()=>view.state.tr.insertText(eventData, from, to)))) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
18
12
|
const { tr } = view.state;
|
|
19
13
|
if (options.marks) tr.ensureMarks(options.marks);
|
|
20
14
|
tr.insertText(eventData, from, to);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import React, { useSyncExternalStore } from "react";
|
|
1
|
+
import React, { useContext, useSyncExternalStore } from "react";
|
|
2
2
|
import { createPortal } from "react-dom";
|
|
3
|
+
import { ReactEditorView } from "../ReactEditorView.js";
|
|
3
4
|
import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js";
|
|
4
|
-
import {
|
|
5
|
+
import { EditorContext } from "../contexts/EditorContext.js";
|
|
6
|
+
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
5
7
|
/**
|
|
6
8
|
* This component renders all of the editor's registered "React renderers".
|
|
7
9
|
*/ const Portals = (param)=>{
|
|
@@ -51,8 +53,9 @@ function getInstance() {
|
|
|
51
53
|
export function TiptapEditorContent(param) {
|
|
52
54
|
let { editor: editorProp, ...props } = param;
|
|
53
55
|
const editor = editorProp;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const { view } = useContext(EditorContext);
|
|
57
|
+
useClientLayoutEffect(()=>{
|
|
58
|
+
if (!(view instanceof ReactEditorView) || editor.view === view) {
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
// @ts-expect-error private property
|
|
@@ -77,7 +80,8 @@ export function TiptapEditorContent(param) {
|
|
|
77
80
|
editor.contentComponent = null;
|
|
78
81
|
};
|
|
79
82
|
}, [
|
|
80
|
-
editor
|
|
83
|
+
editor,
|
|
84
|
+
view
|
|
81
85
|
]);
|
|
82
86
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ React.createElement(Portals, {
|
|
83
87
|
contentComponent: editor.contentComponent
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NodeView } from "@tiptap/core";
|
|
2
|
+
/**
|
|
3
|
+
* Subclass of Tiptap's NodeView to be used in tiptapNodeView.
|
|
4
|
+
*
|
|
5
|
+
* Allows us to pass in an existing dom and contentODM from React ProseMirror's
|
|
6
|
+
* ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
|
|
7
|
+
* methods
|
|
8
|
+
*/ export class ReactProseMirrorNodeView extends NodeView {
|
|
9
|
+
_dom;
|
|
10
|
+
_contentDOM;
|
|
11
|
+
constructor(component, props, dom, contentDOM, options){
|
|
12
|
+
super(component, props, options);
|
|
13
|
+
this._dom = dom;
|
|
14
|
+
this._contentDOM = contentDOM;
|
|
15
|
+
}
|
|
16
|
+
get dom() {
|
|
17
|
+
return this._dom;
|
|
18
|
+
}
|
|
19
|
+
get contentDOM() {
|
|
20
|
+
return this._contentDOM;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,11 +1,69 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
|
-
import {
|
|
3
|
-
reactKeys } from "../../plugins/reactKeys.js";
|
|
2
|
+
import { reactKeys, reactKeysPluginKey } from "../../plugins/reactKeys.js";
|
|
4
3
|
export const ReactProseMirror = Extension.create({
|
|
5
4
|
name: "@handlewithcare/react-prosemirror/reactKeys",
|
|
6
5
|
addProseMirrorPlugins () {
|
|
7
6
|
return [
|
|
8
7
|
reactKeys()
|
|
9
8
|
];
|
|
9
|
+
},
|
|
10
|
+
addCommands () {
|
|
11
|
+
return {
|
|
12
|
+
/**
|
|
13
|
+
* Command that reorders the adjacent nodes starting
|
|
14
|
+
* at the provided position.
|
|
15
|
+
*
|
|
16
|
+
* @param pos - The `start` position of the parent of the nodes being reordered
|
|
17
|
+
* @param order - The new order for the nodes, expressed as an array of indices. For
|
|
18
|
+
* example, to swap the first two nodes in a set of three, `order`
|
|
19
|
+
* would be set to `[1, 0, 2]`. To move the first node to the end,
|
|
20
|
+
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
21
|
+
*/ reorderSiblings (initialPos, order) {
|
|
22
|
+
return function reorderSiblingsCommand(param) {
|
|
23
|
+
let { tr, dispatch } = param;
|
|
24
|
+
const pos = tr.mapping.map(initialPos);
|
|
25
|
+
const $pos = tr.doc.resolve(pos);
|
|
26
|
+
if ($pos.start() !== pos) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!dispatch) return true;
|
|
30
|
+
const nodes = $pos.parent.children;
|
|
31
|
+
const reordered = nodes.map((node, i)=>[
|
|
32
|
+
node,
|
|
33
|
+
i
|
|
34
|
+
]).sort((param, param1)=>{
|
|
35
|
+
let [, a] = param, [, b] = param1;
|
|
36
|
+
return order[a] - order[b];
|
|
37
|
+
}).map((param)=>{
|
|
38
|
+
let [node] = param;
|
|
39
|
+
return node;
|
|
40
|
+
});
|
|
41
|
+
tr.replaceWith(pos, $pos.parent.content.size + pos, reordered);
|
|
42
|
+
const meta = {
|
|
43
|
+
overrides: {}
|
|
44
|
+
};
|
|
45
|
+
const oldPositions = [];
|
|
46
|
+
let start = pos;
|
|
47
|
+
for (const node of nodes){
|
|
48
|
+
oldPositions.push(start);
|
|
49
|
+
start += node.nodeSize;
|
|
50
|
+
}
|
|
51
|
+
start = pos;
|
|
52
|
+
const newPositions = [];
|
|
53
|
+
for(let i = 0; i < reordered.length; i++){
|
|
54
|
+
const node = reordered[i];
|
|
55
|
+
newPositions[order[i]] = start;
|
|
56
|
+
start += node.nodeSize;
|
|
57
|
+
}
|
|
58
|
+
for(let i = 0; i < oldPositions.length; i++){
|
|
59
|
+
const oldPosition = oldPositions[i];
|
|
60
|
+
const newPosition = newPositions[i];
|
|
61
|
+
meta.overrides[oldPosition] = newPosition;
|
|
62
|
+
}
|
|
63
|
+
tr.setMeta(reactKeysPluginKey, meta);
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
10
68
|
}
|
|
11
69
|
});
|