@handlewithcare/react-prosemirror 2.4.12 → 2.5.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/cjs/AbstractEditorView.js +4 -0
- package/dist/cjs/ReactEditorView.js +156 -0
- package/dist/cjs/StaticEditorView.js +86 -0
- package/dist/cjs/components/ChildNodeViews.js +59 -30
- package/dist/cjs/components/CustomNodeView.js +9 -25
- package/dist/cjs/components/DocNodeView.js +6 -15
- package/dist/cjs/components/MarkView.js +1 -2
- package/dist/cjs/components/NativeWidgetView.js +2 -3
- package/dist/cjs/components/NodeView.js +1 -1
- package/dist/cjs/components/ProseMirror.js +11 -14
- package/dist/cjs/components/ReactNodeView.js +3 -4
- package/dist/cjs/components/SeparatorHackView.js +1 -2
- package/dist/cjs/components/TextNodeView.js +4 -5
- package/dist/cjs/components/TrailingHackView.js +1 -2
- package/dist/cjs/components/WidgetView.js +2 -4
- package/dist/cjs/constants.js +33 -0
- package/dist/cjs/hooks/useEditor.js +32 -228
- package/dist/cjs/hooks/useEditorEffect.js +2 -2
- package/dist/cjs/hooks/useEditorEventCallback.js +8 -5
- package/dist/cjs/hooks/useNodeViewDescriptor.js +10 -10
- package/dist/cjs/hooks/useReactKeys.js +1 -1
- package/dist/cjs/testing/editorViewTestHelpers.js +0 -2
- package/dist/cjs/viewdesc.js +10 -9
- package/dist/esm/AbstractEditorView.js +1 -0
- package/dist/esm/ReactEditorView.js +156 -0
- package/dist/esm/StaticEditorView.js +76 -0
- package/dist/esm/components/ChildNodeViews.js +60 -32
- package/dist/esm/components/CustomNodeView.js +9 -25
- package/dist/esm/components/DocNodeView.js +6 -15
- package/dist/esm/components/MarkView.js +1 -2
- package/dist/esm/components/NativeWidgetView.js +2 -3
- package/dist/esm/components/NodeView.js +1 -1
- package/dist/esm/components/ProseMirror.js +11 -14
- package/dist/esm/components/ReactNodeView.js +3 -4
- package/dist/esm/components/SeparatorHackView.js +1 -2
- package/dist/esm/components/TextNodeView.js +4 -5
- package/dist/esm/components/TrailingHackView.js +1 -2
- package/dist/esm/components/WidgetView.js +2 -4
- package/dist/esm/constants.js +15 -0
- package/dist/esm/hooks/useEditor.js +28 -217
- package/dist/esm/hooks/useEditorEffect.js +2 -2
- package/dist/esm/hooks/useEditorEventCallback.js +8 -5
- package/dist/esm/hooks/useNodeViewDescriptor.js +10 -10
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/testing/editorViewTestHelpers.js +0 -2
- package/dist/esm/viewdesc.js +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +27 -0
- package/dist/types/ReactEditorView.d.ts +79 -0
- package/dist/types/StaticEditorView.d.ts +24 -0
- package/dist/types/components/ChildNodeViews.d.ts +2 -2
- package/dist/types/components/CustomNodeView.d.ts +2 -2
- package/dist/types/components/DocNodeView.d.ts +2 -5
- package/dist/types/components/MarkView.d.ts +2 -2
- package/dist/types/components/NativeWidgetView.d.ts +2 -2
- package/dist/types/components/NodeView.d.ts +2 -2
- package/dist/types/components/ReactNodeView.d.ts +2 -2
- package/dist/types/components/SeparatorHackView.d.ts +2 -2
- package/dist/types/components/TextNodeView.d.ts +4 -3
- package/dist/types/components/TrailingHackView.d.ts +2 -2
- package/dist/types/components/WidgetView.d.ts +2 -2
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/contexts/EditorContext.d.ts +6 -4
- package/dist/types/decorations/computeDocDeco.d.ts +3 -2
- package/dist/types/decorations/viewDecorations.d.ts +3 -2
- package/dist/types/hooks/useEditor.d.ts +5 -46
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +1 -1
- package/dist/types/hooks/useReactKeys.d.ts +1 -1
- package/dist/types/props.d.ts +3 -3
- package/dist/types/viewdesc.d.ts +6 -5
- package/package.json +6 -2
- package/dist/cjs/components/Editor.js +0 -28
- package/dist/cjs/components/NodeViews.js +0 -73
- package/dist/cjs/components/__tests__/LayoutGroup.test.js +0 -141
- package/dist/cjs/components/__tests__/ProseMirror.test.js +0 -255
- package/dist/cjs/contexts/NodeViewsContext.js +0 -10
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -107
- package/dist/cjs/hooks/__tests__/useNodeViews.test.js +0 -159
- package/dist/cjs/hooks/useEditorView.js +0 -100
- package/dist/cjs/hooks/useNodePos.js +0 -69
- package/dist/cjs/hooks/useNodeViews.js +0 -100
- package/dist/cjs/nodeViews/createReactNodeViewConstructor.js +0 -244
- package/dist/cjs/nodeViews/phrasingContentTags.js +0 -57
- package/dist/cjs/plugins/__tests__/react.test.js +0 -139
- package/dist/cjs/plugins/react.js +0 -71
- package/dist/cjs/selection/SelectionDOMObserver.js +0 -171
- package/dist/cjs/selection/hasFocusAndSelection.js +0 -35
- package/dist/cjs/selection/selectionFromDOM.js +0 -77
- package/dist/cjs/selection/selectionToDOM.js +0 -226
- package/dist/cjs/ssr.js +0 -85
- package/dist/esm/components/Editor.js +0 -15
- package/dist/esm/components/NodeViews.js +0 -26
- package/dist/esm/components/__tests__/LayoutGroup.test.js +0 -98
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -207
- package/dist/esm/contexts/NodeViewsContext.js +0 -9
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -98
- package/dist/esm/hooks/__tests__/useNodeViews.test.js +0 -116
- package/dist/esm/hooks/useEditorView.js +0 -99
- package/dist/esm/hooks/useNodePos.js +0 -16
- package/dist/esm/hooks/useNodeViews.js +0 -53
- package/dist/esm/nodeViews/createReactNodeViewConstructor.js +0 -214
- package/dist/esm/nodeViews/phrasingContentTags.js +0 -49
- package/dist/esm/plugins/__tests__/react.test.js +0 -135
- package/dist/esm/plugins/react.js +0 -64
- package/dist/esm/selection/SelectionDOMObserver.js +0 -161
- package/dist/esm/selection/hasFocusAndSelection.js +0 -17
- package/dist/esm/selection/selectionFromDOM.js +0 -59
- package/dist/esm/selection/selectionToDOM.js +0 -196
- package/dist/esm/ssr.js +0 -82
- package/dist/types/components/Editor.d.ts +0 -7
- package/dist/types/components/NodeViews.d.ts +0 -6
- package/dist/types/components/__tests__/LayoutGroup.test.d.ts +0 -1
- package/dist/types/contexts/NodeViewsContext.d.ts +0 -19
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +0 -1
- package/dist/types/hooks/__tests__/useNodeViews.test.d.ts +0 -1
- package/dist/types/hooks/useEditorView.d.ts +0 -23
- package/dist/types/hooks/useNodePos.d.ts +0 -9
- package/dist/types/hooks/useNodeViews.d.ts +0 -5
- package/dist/types/nodeViews/createReactNodeViewConstructor.d.ts +0 -48
- package/dist/types/nodeViews/phrasingContentTags.d.ts +0 -1
- package/dist/types/plugins/__tests__/react.test.d.ts +0 -1
- package/dist/types/plugins/react.d.ts +0 -21
- package/dist/types/selection/SelectionDOMObserver.d.ts +0 -33
- package/dist/types/selection/hasFocusAndSelection.d.ts +0 -3
- package/dist/types/selection/selectionFromDOM.d.ts +0 -4
- package/dist/types/selection/selectionToDOM.d.ts +0 -9
- package/dist/types/ssr.d.ts +0 -19
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "useEditorView", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>useEditorView
|
|
8
|
-
});
|
|
9
|
-
const _prosemirrorModel = require("prosemirror-model");
|
|
10
|
-
const _prosemirrorState = require("prosemirror-state");
|
|
11
|
-
const _prosemirrorView = require("prosemirror-view");
|
|
12
|
-
const _react = require("react");
|
|
13
|
-
const _reactDom = require("react-dom");
|
|
14
|
-
const _useComponentEventListenersJs = require("./useComponentEventListeners.js");
|
|
15
|
-
const EMPTY_SCHEMA = new _prosemirrorModel.Schema({
|
|
16
|
-
nodes: {
|
|
17
|
-
doc: {
|
|
18
|
-
content: "text*"
|
|
19
|
-
},
|
|
20
|
-
text: {
|
|
21
|
-
inline: true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const EMPTY_STATE = _prosemirrorState.EditorState.create({
|
|
26
|
-
schema: EMPTY_SCHEMA
|
|
27
|
-
});
|
|
28
|
-
let didWarnValueDefaultValue = false;
|
|
29
|
-
function useEditorView(mount, options) {
|
|
30
|
-
if (process.env.NODE_ENV !== "production") {
|
|
31
|
-
if (options.defaultState !== undefined && options.state !== undefined && !didWarnValueDefaultValue) {
|
|
32
|
-
console.error("A component contains a ProseMirror editor with both value and defaultValue props. " + "ProseMirror editors must be either controlled or uncontrolled " + "(specify either the state prop, or the defaultState prop, but not both). " + "Decide between using a controlled or uncontrolled ProseMirror editor " + "and remove one of these props. More info: " + "https://reactjs.org/link/controlled-components");
|
|
33
|
-
didWarnValueDefaultValue = true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const defaultState = options.defaultState ?? EMPTY_STATE;
|
|
37
|
-
const [_state, setState] = (0, _react.useState)(defaultState);
|
|
38
|
-
const state = options.state ?? _state;
|
|
39
|
-
const { componentEventListenersPlugin , registerEventListener , unregisterEventListener } = (0, _useComponentEventListenersJs.useComponentEventListeners)();
|
|
40
|
-
const plugins = (0, _react.useMemo)(()=>[
|
|
41
|
-
...options.plugins ?? [],
|
|
42
|
-
componentEventListenersPlugin
|
|
43
|
-
], [
|
|
44
|
-
options.plugins,
|
|
45
|
-
componentEventListenersPlugin
|
|
46
|
-
]);
|
|
47
|
-
function dispatchTransaction(tr) {
|
|
48
|
-
(0, _reactDom.flushSync)(()=>{
|
|
49
|
-
if (!options.state) {
|
|
50
|
-
setState((s)=>s.apply(tr));
|
|
51
|
-
}
|
|
52
|
-
if (options.dispatchTransaction) {
|
|
53
|
-
options.dispatchTransaction.call(this, tr);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const directEditorProps = {
|
|
58
|
-
...options,
|
|
59
|
-
state,
|
|
60
|
-
plugins,
|
|
61
|
-
dispatchTransaction
|
|
62
|
-
};
|
|
63
|
-
const [_view, setView] = (0, _react.useState)(null);
|
|
64
|
-
const view = options.view ?? _view;
|
|
65
|
-
(0, _react.useLayoutEffect)(()=>{
|
|
66
|
-
return ()=>{
|
|
67
|
-
if (_view) {
|
|
68
|
-
_view.destroy();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}, [
|
|
72
|
-
_view
|
|
73
|
-
]);
|
|
74
|
-
// This effect runs on every render and handles the view lifecycle.
|
|
75
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
-
(0, _react.useLayoutEffect)(()=>{
|
|
77
|
-
if (_view) {
|
|
78
|
-
if (_view.dom === mount) {
|
|
79
|
-
_view.setProps(directEditorProps);
|
|
80
|
-
} else {
|
|
81
|
-
setView(null);
|
|
82
|
-
}
|
|
83
|
-
} else if (mount) {
|
|
84
|
-
setView(new _prosemirrorView.EditorView({
|
|
85
|
-
mount
|
|
86
|
-
}, directEditorProps));
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return (0, _react.useMemo)(()=>({
|
|
90
|
-
editorState: state,
|
|
91
|
-
editorView: view,
|
|
92
|
-
registerEventListener,
|
|
93
|
-
unregisterEventListener
|
|
94
|
-
}), [
|
|
95
|
-
state,
|
|
96
|
-
_view,
|
|
97
|
-
registerEventListener,
|
|
98
|
-
unregisterEventListener
|
|
99
|
-
]);
|
|
100
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
NodePosProvider: ()=>NodePosProvider,
|
|
13
|
-
useNodePos: ()=>useNodePos
|
|
14
|
-
});
|
|
15
|
-
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
16
|
-
const _reactJs = require("../plugins/react.js");
|
|
17
|
-
const _useEditorStateJs = require("./useEditorState.js");
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
19
|
-
if (typeof WeakMap !== "function") return null;
|
|
20
|
-
var cacheBabelInterop = new WeakMap();
|
|
21
|
-
var cacheNodeInterop = new WeakMap();
|
|
22
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
23
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
24
|
-
})(nodeInterop);
|
|
25
|
-
}
|
|
26
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
27
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
28
|
-
return obj;
|
|
29
|
-
}
|
|
30
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
31
|
-
return {
|
|
32
|
-
default: obj
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
36
|
-
if (cache && cache.has(obj)) {
|
|
37
|
-
return cache.get(obj);
|
|
38
|
-
}
|
|
39
|
-
var newObj = {};
|
|
40
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
|
-
for(var key in obj){
|
|
42
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
43
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
44
|
-
if (desc && (desc.get || desc.set)) {
|
|
45
|
-
Object.defineProperty(newObj, key, desc);
|
|
46
|
-
} else {
|
|
47
|
-
newObj[key] = obj[key];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
newObj.default = obj;
|
|
52
|
-
if (cache) {
|
|
53
|
-
cache.set(obj, newObj);
|
|
54
|
-
}
|
|
55
|
-
return newObj;
|
|
56
|
-
}
|
|
57
|
-
const NodePosContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
58
|
-
function NodePosProvider(param) {
|
|
59
|
-
let { nodeKey , children } = param;
|
|
60
|
-
const editorState = (0, _useEditorStateJs.useEditorState)();
|
|
61
|
-
const pluginState = _reactJs.reactPluginKey.getState(editorState);
|
|
62
|
-
if (!pluginState) return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, children);
|
|
63
|
-
return /*#__PURE__*/ _react.default.createElement(NodePosContext.Provider, {
|
|
64
|
-
value: pluginState.keyToPos.get(nodeKey) ?? 0
|
|
65
|
-
}, children);
|
|
66
|
-
}
|
|
67
|
-
function useNodePos() {
|
|
68
|
-
return (0, _react.useContext)(NodePosContext);
|
|
69
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "useNodeViews", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>useNodeViews
|
|
8
|
-
});
|
|
9
|
-
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
10
|
-
const _nodeViewsJs = require("../components/NodeViews.js");
|
|
11
|
-
const _createReactNodeViewConstructorJs = require("../nodeViews/createReactNodeViewConstructor.js");
|
|
12
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
13
|
-
if (typeof WeakMap !== "function") return null;
|
|
14
|
-
var cacheBabelInterop = new WeakMap();
|
|
15
|
-
var cacheNodeInterop = new WeakMap();
|
|
16
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
17
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
18
|
-
})(nodeInterop);
|
|
19
|
-
}
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
21
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
25
|
-
return {
|
|
26
|
-
default: obj
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
30
|
-
if (cache && cache.has(obj)) {
|
|
31
|
-
return cache.get(obj);
|
|
32
|
-
}
|
|
33
|
-
var newObj = {};
|
|
34
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
35
|
-
for(var key in obj){
|
|
36
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
37
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
38
|
-
if (desc && (desc.get || desc.set)) {
|
|
39
|
-
Object.defineProperty(newObj, key, desc);
|
|
40
|
-
} else {
|
|
41
|
-
newObj[key] = obj[key];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
newObj.default = obj;
|
|
46
|
-
if (cache) {
|
|
47
|
-
cache.set(obj, newObj);
|
|
48
|
-
}
|
|
49
|
-
return newObj;
|
|
50
|
-
}
|
|
51
|
-
function useNodeViews(nodeViews) {
|
|
52
|
-
const [portals, setPortals] = (0, _react.useState)({});
|
|
53
|
-
const registerPortal = (0, _react.useCallback)((view, getPos, portal)=>{
|
|
54
|
-
const nearestAncestorKey = (0, _createReactNodeViewConstructorJs.findNodeKeyUp)(view, getPos());
|
|
55
|
-
setPortals((oldPortals)=>{
|
|
56
|
-
const oldChildPortals = oldPortals[nearestAncestorKey] ?? [];
|
|
57
|
-
const newChildPortals = oldChildPortals.concat({
|
|
58
|
-
getPos,
|
|
59
|
-
portal
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
...oldPortals,
|
|
63
|
-
[nearestAncestorKey]: newChildPortals
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
return ()=>{
|
|
67
|
-
setPortals((oldPortals)=>{
|
|
68
|
-
const oldChildPortals = oldPortals[nearestAncestorKey] ?? [];
|
|
69
|
-
const newChildPortals = oldChildPortals.filter((param)=>{
|
|
70
|
-
let { portal: p } = param;
|
|
71
|
-
return p !== portal;
|
|
72
|
-
});
|
|
73
|
-
return {
|
|
74
|
-
...oldPortals,
|
|
75
|
-
[nearestAncestorKey]: newChildPortals
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
}, []);
|
|
80
|
-
const wrappedNodeViews = (0, _react.useMemo)(()=>{
|
|
81
|
-
const nodeViewEntries = Object.entries(nodeViews ?? {});
|
|
82
|
-
const wrappedNodeViewEntries = nodeViewEntries.map((param)=>{
|
|
83
|
-
let [name, constructor] = param;
|
|
84
|
-
return [
|
|
85
|
-
name,
|
|
86
|
-
(0, _createReactNodeViewConstructorJs.createReactNodeViewConstructor)(constructor, registerPortal)
|
|
87
|
-
];
|
|
88
|
-
});
|
|
89
|
-
return Object.fromEntries(wrappedNodeViewEntries);
|
|
90
|
-
}, [
|
|
91
|
-
nodeViews,
|
|
92
|
-
registerPortal
|
|
93
|
-
]);
|
|
94
|
-
return {
|
|
95
|
-
nodeViews: wrappedNodeViews,
|
|
96
|
-
nodeViewsComponent: /*#__PURE__*/ _react.default.createElement(_nodeViewsJs.NodeViews, {
|
|
97
|
-
portals: portals
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
REACT_NODE_VIEW: ()=>REACT_NODE_VIEW,
|
|
13
|
-
findNodeKeyUp: ()=>findNodeKeyUp,
|
|
14
|
-
createReactNodeViewConstructor: ()=>createReactNodeViewConstructor
|
|
15
|
-
});
|
|
16
|
-
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
17
|
-
const _reactDom = require("react-dom");
|
|
18
|
-
const _nodeViewsContextJs = require("../contexts/NodeViewsContext.js");
|
|
19
|
-
const _useEditorEffectJs = require("../hooks/useEditorEffect.js");
|
|
20
|
-
const _useNodePosJs = require("../hooks/useNodePos.js");
|
|
21
|
-
const _reactJs = require("../plugins/react.js");
|
|
22
|
-
const _phrasingContentTagsJs = require("./phrasingContentTags.js");
|
|
23
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
24
|
-
if (typeof WeakMap !== "function") return null;
|
|
25
|
-
var cacheBabelInterop = new WeakMap();
|
|
26
|
-
var cacheNodeInterop = new WeakMap();
|
|
27
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
28
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
29
|
-
})(nodeInterop);
|
|
30
|
-
}
|
|
31
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
32
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
33
|
-
return obj;
|
|
34
|
-
}
|
|
35
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
36
|
-
return {
|
|
37
|
-
default: obj
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
41
|
-
if (cache && cache.has(obj)) {
|
|
42
|
-
return cache.get(obj);
|
|
43
|
-
}
|
|
44
|
-
var newObj = {};
|
|
45
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
46
|
-
for(var key in obj){
|
|
47
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
48
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
49
|
-
if (desc && (desc.get || desc.set)) {
|
|
50
|
-
Object.defineProperty(newObj, key, desc);
|
|
51
|
-
} else {
|
|
52
|
-
newObj[key] = obj[key];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
newObj.default = obj;
|
|
57
|
-
if (cache) {
|
|
58
|
-
cache.set(obj, newObj);
|
|
59
|
-
}
|
|
60
|
-
return newObj;
|
|
61
|
-
}
|
|
62
|
-
const REACT_NODE_VIEW = Symbol("react node view");
|
|
63
|
-
let didWarnReactPlugin = false;
|
|
64
|
-
function findNodeKeyUp(editorView, pos) {
|
|
65
|
-
const pluginState = _reactJs.reactPluginKey.getState(editorView.state);
|
|
66
|
-
if (!pluginState) return _reactJs.ROOT_NODE_KEY;
|
|
67
|
-
const $pos = editorView.state.doc.resolve(pos);
|
|
68
|
-
for(let d = $pos.depth; d > 0; d--){
|
|
69
|
-
const ancestorNodeTypeName = $pos.node(d).type.name;
|
|
70
|
-
const ancestorNodeView = editorView.props.nodeViews?.[ancestorNodeTypeName];
|
|
71
|
-
if (!ancestorNodeView?.[REACT_NODE_VIEW]) continue;
|
|
72
|
-
const ancestorPos = $pos.before(d);
|
|
73
|
-
const ancestorKey = pluginState.posToKey.get(ancestorPos);
|
|
74
|
-
if (ancestorKey) return ancestorKey;
|
|
75
|
-
}
|
|
76
|
-
return _reactJs.ROOT_NODE_KEY;
|
|
77
|
-
}
|
|
78
|
-
function createReactNodeViewConstructor(nodeViewConstructor, registerPortal) {
|
|
79
|
-
function nodeViewConstructorWrapper(node, editorView, getPos, decorations, innerDecorations) {
|
|
80
|
-
const nodeView = nodeViewConstructor(node, editorView, getPos, decorations, innerDecorations);
|
|
81
|
-
const { component: NodeView } = nodeView;
|
|
82
|
-
if (!NodeView) {
|
|
83
|
-
return nodeView;
|
|
84
|
-
}
|
|
85
|
-
const reactPluginState = _reactJs.reactPluginKey.getState(editorView.state);
|
|
86
|
-
if (!reactPluginState) {
|
|
87
|
-
if (!didWarnReactPlugin) {
|
|
88
|
-
console.error("The React ProseMirror plugin is required to use React node views. " + "Make sure to add it to the ProseMirror editor state.");
|
|
89
|
-
didWarnReactPlugin = true;
|
|
90
|
-
}
|
|
91
|
-
return nodeView;
|
|
92
|
-
}
|
|
93
|
-
const { dom , contentDOM } = nodeView;
|
|
94
|
-
// Use a span if the provided contentDOM is in the "phrasing" content
|
|
95
|
-
// category. Otherwise use a div. This is our best attempt at not
|
|
96
|
-
// breaking the intended content model, for now.
|
|
97
|
-
//
|
|
98
|
-
// https://developer.mozilla.org/en-US/docs/Web/HTML/Content_categories#phrasing_content
|
|
99
|
-
const ContentDOMWrapper = contentDOM && (_phrasingContentTagsJs.phrasingContentTags.includes(contentDOM.tagName.toLocaleLowerCase()) ? "span" : "div");
|
|
100
|
-
const nodeKey = reactPluginState.posToKey.get(getPos()) ?? (0, _reactJs.createNodeKey)();
|
|
101
|
-
/**
|
|
102
|
-
* Wrapper component to provide some imperative handles for updating
|
|
103
|
-
* and re-rendering its child. Takes and renders an arbitrary ElementType
|
|
104
|
-
* that expects NodeViewComponentProps as props.
|
|
105
|
-
*/ const NodeViewWrapper = /*#__PURE__*/ (0, _react.forwardRef)(function NodeViewWrapper(param, ref) {
|
|
106
|
-
let { initialState } = param;
|
|
107
|
-
const [node, setNode] = (0, _react.useState)(initialState.node);
|
|
108
|
-
const [decorations, setDecorations] = (0, _react.useState)(initialState.decorations);
|
|
109
|
-
const [isSelected, setIsSelected] = (0, _react.useState)(initialState.isSelected);
|
|
110
|
-
const nodeViews = (0, _react.useContext)(_nodeViewsContextJs.NodeViewsContext);
|
|
111
|
-
const childNodeViews = nodeViews[nodeKey];
|
|
112
|
-
const [childNodeViewPortals, setChildNodeViewPortals] = (0, _react.useState)(childNodeViews?.map((param)=>{
|
|
113
|
-
let { portal } = param;
|
|
114
|
-
return portal;
|
|
115
|
-
}));
|
|
116
|
-
// `getPos` is technically derived from the EditorView
|
|
117
|
-
// state, so it's not safe to call until after the EditorView
|
|
118
|
-
// has been updated
|
|
119
|
-
(0, _useEditorEffectJs.useEditorEffect)(()=>{
|
|
120
|
-
setChildNodeViewPortals(childNodeViews?.sort((a, b)=>a.getPos() - b.getPos()).map((param)=>{
|
|
121
|
-
let { portal } = param;
|
|
122
|
-
return portal;
|
|
123
|
-
}));
|
|
124
|
-
}, [
|
|
125
|
-
childNodeViews
|
|
126
|
-
]);
|
|
127
|
-
const [contentDOMWrapper, setContentDOMWrapper] = (0, _react.useState)(null);
|
|
128
|
-
const [contentDOMParent, setContentDOMParent] = (0, _react.useState)(null);
|
|
129
|
-
(0, _react.useImperativeHandle)(ref, ()=>({
|
|
130
|
-
node,
|
|
131
|
-
contentDOMWrapper: contentDOMWrapper,
|
|
132
|
-
contentDOMParent: contentDOMParent,
|
|
133
|
-
setNode,
|
|
134
|
-
setDecorations,
|
|
135
|
-
setIsSelected
|
|
136
|
-
}), [
|
|
137
|
-
node,
|
|
138
|
-
contentDOMWrapper,
|
|
139
|
-
contentDOMParent
|
|
140
|
-
]);
|
|
141
|
-
return /*#__PURE__*/ _react.default.createElement(_useNodePosJs.NodePosProvider, {
|
|
142
|
-
nodeKey: nodeKey
|
|
143
|
-
}, /*#__PURE__*/ _react.default.createElement(NodeView, {
|
|
144
|
-
node: node,
|
|
145
|
-
decorations: decorations,
|
|
146
|
-
isSelected: isSelected
|
|
147
|
-
}, childNodeViewPortals, ContentDOMWrapper && /*#__PURE__*/ _react.default.createElement(ContentDOMWrapper, {
|
|
148
|
-
style: {
|
|
149
|
-
display: "contents"
|
|
150
|
-
},
|
|
151
|
-
ref: (nextContentDOMWrapper)=>{
|
|
152
|
-
setContentDOMWrapper(nextContentDOMWrapper);
|
|
153
|
-
// we preserve a reference to the contentDOMWrapper'
|
|
154
|
-
// parent so that later we can reassemble the DOM hierarchy
|
|
155
|
-
// React expects when cleaning up the ContentDOMWrapper element
|
|
156
|
-
if (nextContentDOMWrapper?.parentNode) {
|
|
157
|
-
setContentDOMParent(nextContentDOMWrapper.parentNode);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
})));
|
|
161
|
-
});
|
|
162
|
-
NodeViewWrapper.displayName = `NodeView(${NodeView.displayName ?? NodeView.name})`;
|
|
163
|
-
let componentRef = null;
|
|
164
|
-
const element = /*#__PURE__*/ _react.default.createElement(NodeViewWrapper, {
|
|
165
|
-
initialState: {
|
|
166
|
-
node,
|
|
167
|
-
decorations,
|
|
168
|
-
isSelected: false
|
|
169
|
-
},
|
|
170
|
-
ref: (c)=>{
|
|
171
|
-
componentRef = c;
|
|
172
|
-
if (!componentRef || componentRef.node.isLeaf) return;
|
|
173
|
-
const contentDOMWrapper = componentRef.contentDOMWrapper;
|
|
174
|
-
if (!contentDOMWrapper || !(contentDOMWrapper instanceof HTMLElement)) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
// We always set contentDOM when !node.isLeaf, which is checked above
|
|
178
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
179
|
-
contentDOMWrapper.appendChild(contentDOM);
|
|
180
|
-
// Synchronize the ProseMirror selection to the DOM, because mounting the
|
|
181
|
-
// component changes the DOM outside of a ProseMirror update.
|
|
182
|
-
const { node } = componentRef;
|
|
183
|
-
const pos = getPos();
|
|
184
|
-
const end = pos + node.nodeSize;
|
|
185
|
-
const { from , to } = editorView.state.selection;
|
|
186
|
-
if (editorView.hasFocus() && pos < from && to < end) {
|
|
187
|
-
// This call seems like it should be a no-op, given the editor already has
|
|
188
|
-
// focus, but it causes ProseMirror to synchronize the DOM selection with
|
|
189
|
-
// its state again, placing the DOM selection in a reasonable place within
|
|
190
|
-
// the node.
|
|
191
|
-
editorView.focus();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const portal = /*#__PURE__*/ (0, _reactDom.createPortal)(element, dom, nodeKey);
|
|
196
|
-
const unregisterPortal = registerPortal(editorView, getPos, portal);
|
|
197
|
-
return {
|
|
198
|
-
ignoreMutation (record) {
|
|
199
|
-
return !contentDOM?.contains(record.target);
|
|
200
|
-
},
|
|
201
|
-
...nodeView,
|
|
202
|
-
selectNode () {
|
|
203
|
-
componentRef?.setIsSelected(true);
|
|
204
|
-
nodeView.selectNode?.();
|
|
205
|
-
},
|
|
206
|
-
deselectNode () {
|
|
207
|
-
componentRef?.setIsSelected(false);
|
|
208
|
-
nodeView.deselectNode?.();
|
|
209
|
-
},
|
|
210
|
-
update (node, decorations, innerDecorations) {
|
|
211
|
-
// If this node view's parent has been removed from the registry, we
|
|
212
|
-
// need to rebuild it and its children with new registry keys
|
|
213
|
-
const positionRegistry = _reactJs.reactPluginKey.getState(editorView.state);
|
|
214
|
-
if (positionRegistry && nodeKey !== positionRegistry.posToKey.get(getPos())) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
if (nodeView.update?.(node, decorations, innerDecorations) === false) {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
if (node.type === componentRef?.node.type) {
|
|
221
|
-
componentRef?.setNode(node);
|
|
222
|
-
componentRef?.setDecorations(decorations);
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
return false;
|
|
226
|
-
},
|
|
227
|
-
destroy () {
|
|
228
|
-
// React expects the contentDOMParent to be a child of the
|
|
229
|
-
// DOM element where the portal was mounted, but in some situations
|
|
230
|
-
// contenteditable may have already detached the contentDOMParent
|
|
231
|
-
// from the DOM. Here we attempt to reassemble the DOM that React
|
|
232
|
-
// expects when cleaning up the portal.
|
|
233
|
-
if (componentRef?.contentDOMParent) {
|
|
234
|
-
this.dom.appendChild(componentRef.contentDOMParent);
|
|
235
|
-
}
|
|
236
|
-
unregisterPortal();
|
|
237
|
-
nodeView.destroy?.();
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
return Object.assign(nodeViewConstructorWrapper, {
|
|
242
|
-
[REACT_NODE_VIEW]: true
|
|
243
|
-
});
|
|
244
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "phrasingContentTags", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>phrasingContentTags
|
|
8
|
-
});
|
|
9
|
-
const phrasingContentTags = [
|
|
10
|
-
"abbr",
|
|
11
|
-
"audio",
|
|
12
|
-
"b",
|
|
13
|
-
"bdo",
|
|
14
|
-
"br",
|
|
15
|
-
"button",
|
|
16
|
-
"canvas",
|
|
17
|
-
"cite",
|
|
18
|
-
"code",
|
|
19
|
-
"data",
|
|
20
|
-
"datalist",
|
|
21
|
-
"dfn",
|
|
22
|
-
"em",
|
|
23
|
-
"embed",
|
|
24
|
-
"i",
|
|
25
|
-
"iframe",
|
|
26
|
-
"img",
|
|
27
|
-
"input",
|
|
28
|
-
"kbd",
|
|
29
|
-
"keygen",
|
|
30
|
-
"label",
|
|
31
|
-
"mark",
|
|
32
|
-
"math",
|
|
33
|
-
"meter",
|
|
34
|
-
"noscript",
|
|
35
|
-
"object",
|
|
36
|
-
"output",
|
|
37
|
-
"picture",
|
|
38
|
-
"progress",
|
|
39
|
-
"q",
|
|
40
|
-
"ruby",
|
|
41
|
-
"s",
|
|
42
|
-
"samp",
|
|
43
|
-
"script",
|
|
44
|
-
"select",
|
|
45
|
-
"small",
|
|
46
|
-
"span",
|
|
47
|
-
"strong",
|
|
48
|
-
"sub",
|
|
49
|
-
"sup",
|
|
50
|
-
"svg",
|
|
51
|
-
"textarea",
|
|
52
|
-
"time",
|
|
53
|
-
"u",
|
|
54
|
-
"var",
|
|
55
|
-
"video",
|
|
56
|
-
"wbr"
|
|
57
|
-
];
|