@handlewithcare/react-prosemirror 2.8.0-tiptap.23 → 2.8.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.
Files changed (90) hide show
  1. package/dist/cjs/StaticEditorView.js +0 -3
  2. package/dist/cjs/commands/reorderSiblings.js +60 -45
  3. package/dist/cjs/components/nodes/CustomNodeView.js +1 -1
  4. package/dist/cjs/components/nodes/DocNodeView.js +1 -1
  5. package/dist/cjs/components/nodes/ReactNodeView.js +7 -5
  6. package/dist/cjs/hooks/useEditor.js +0 -4
  7. package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
  8. package/dist/cjs/hooks/useNodeViewDescriptor.js +1 -4
  9. package/dist/cjs/viewdesc.js +5 -5
  10. package/dist/esm/StaticEditorView.js +0 -3
  11. package/dist/esm/commands/reorderSiblings.js +49 -42
  12. package/dist/esm/components/nodes/CustomNodeView.js +1 -1
  13. package/dist/esm/components/nodes/DocNodeView.js +1 -1
  14. package/dist/esm/components/nodes/ReactNodeView.js +8 -6
  15. package/dist/esm/hooks/useEditor.js +0 -4
  16. package/dist/esm/hooks/useEditorEffect.js +0 -4
  17. package/dist/esm/hooks/useEditorEventCallback.js +6 -4
  18. package/dist/esm/hooks/useNodeViewDescriptor.js +1 -4
  19. package/dist/esm/viewdesc.js +5 -5
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/dist/types/AbstractEditorView.d.ts +0 -1
  22. package/dist/types/StaticEditorView.d.ts +0 -1
  23. package/dist/types/commands/__tests__/reorderSiblings.test.d.ts +1 -0
  24. package/dist/types/commands/reorderSiblings.d.ts +3 -1
  25. package/dist/types/constants.d.ts +1 -1
  26. package/dist/types/hooks/useEditorEffect.d.ts +0 -4
  27. package/dist/types/hooks/useEditorEventCallback.d.ts +6 -4
  28. package/dist/types/hooks/useNodeViewDescriptor.d.ts +3 -1
  29. package/dist/types/props.d.ts +26 -26
  30. package/package.json +12 -20
  31. package/dist/cjs/components/CustomNodeView.js +0 -132
  32. package/dist/cjs/components/DefaultNodeView.js +0 -67
  33. package/dist/cjs/components/DocNodeView.js +0 -96
  34. package/dist/cjs/components/MarkView.js +0 -119
  35. package/dist/cjs/components/NodeView.js +0 -86
  36. package/dist/cjs/components/NodeViewComponentProps.js +0 -4
  37. package/dist/cjs/components/ReactNodeView.js +0 -174
  38. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +0 -26
  39. package/dist/cjs/tiptap/TiptapEditor.js +0 -34
  40. package/dist/cjs/tiptap/TiptapEditorContent.js +0 -142
  41. package/dist/cjs/tiptap/TiptapEditorView.js +0 -118
  42. package/dist/cjs/tiptap/TiptapNodeView.js +0 -26
  43. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +0 -12
  44. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +0 -79
  45. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +0 -15
  46. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +0 -43
  47. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +0 -35
  48. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  49. package/dist/cjs/tiptap/index.js +0 -48
  50. package/dist/cjs/tiptap/tiptapNodeView.js +0 -237
  51. package/dist/esm/components/CustomNodeView.js +0 -81
  52. package/dist/esm/components/DefaultNodeView.js +0 -16
  53. package/dist/esm/components/DocNodeView.js +0 -45
  54. package/dist/esm/components/MarkView.js +0 -68
  55. package/dist/esm/components/NodeView.js +0 -35
  56. package/dist/esm/components/NodeViewComponentProps.js +0 -1
  57. package/dist/esm/components/ReactNodeView.js +0 -123
  58. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +0 -22
  59. package/dist/esm/tiptap/TiptapEditor.js +0 -24
  60. package/dist/esm/tiptap/TiptapEditorContent.js +0 -91
  61. package/dist/esm/tiptap/TiptapEditorView.js +0 -69
  62. package/dist/esm/tiptap/TiptapNodeView.js +0 -22
  63. package/dist/esm/tiptap/contexts/TiptapEditorContext.js +0 -2
  64. package/dist/esm/tiptap/extensions/ReactProseMirror.js +0 -69
  65. package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +0 -5
  66. package/dist/esm/tiptap/hooks/useTiptapEditor.js +0 -33
  67. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +0 -42
  68. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  69. package/dist/esm/tiptap/index.js +0 -9
  70. package/dist/esm/tiptap/tiptapNodeView.js +0 -205
  71. package/dist/types/components/CustomNodeView.d.ts +0 -12
  72. package/dist/types/components/DefaultNodeView.d.ts +0 -3
  73. package/dist/types/components/DocNodeView.d.ts +0 -12
  74. package/dist/types/components/MarkView.d.ts +0 -9
  75. package/dist/types/components/NodeView.d.ts +0 -11
  76. package/dist/types/components/NodeViewComponentProps.d.ts +0 -12
  77. package/dist/types/components/ReactNodeView.d.ts +0 -13
  78. package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +0 -15
  79. package/dist/types/tiptap/TiptapEditor.d.ts +0 -6
  80. package/dist/types/tiptap/TiptapEditorContent.d.ts +0 -19
  81. package/dist/types/tiptap/TiptapEditorView.d.ts +0 -16
  82. package/dist/types/tiptap/TiptapNodeView.d.ts +0 -15
  83. package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +0 -6
  84. package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +0 -9
  85. package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +0 -1
  86. package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +0 -4
  87. package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +0 -21
  88. package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +0 -13
  89. package/dist/types/tiptap/index.d.ts +0 -9
  90. package/dist/types/tiptap/tiptapNodeView.d.ts +0 -50
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "TiptapEditorView", {
6
- enumerable: true,
7
- get: function() {
8
- return TiptapEditorView;
9
- }
10
- });
11
- const _react = require("@tiptap/react");
12
- const _react1 = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
- const _ProseMirror = require("../components/ProseMirror.js");
14
- const _useForceUpdate = require("../hooks/useForceUpdate.js");
15
- const _TiptapEditorContext = require("./contexts/TiptapEditorContext.js");
16
- function _getRequireWildcardCache(nodeInterop) {
17
- if (typeof WeakMap !== "function") return null;
18
- var cacheBabelInterop = new WeakMap();
19
- var cacheNodeInterop = new WeakMap();
20
- return (_getRequireWildcardCache = function(nodeInterop) {
21
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
22
- })(nodeInterop);
23
- }
24
- function _interop_require_wildcard(obj, nodeInterop) {
25
- if (!nodeInterop && obj && obj.__esModule) {
26
- return obj;
27
- }
28
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
29
- return {
30
- default: obj
31
- };
32
- }
33
- var cache = _getRequireWildcardCache(nodeInterop);
34
- if (cache && cache.has(obj)) {
35
- return cache.get(obj);
36
- }
37
- var newObj = {
38
- __proto__: null
39
- };
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
- function TiptapEditorView(param) {
58
- let { editor, nodeViews, markViews, children, static: isStatic = false } = param;
59
- const [isEditorInitialized, setIsEditorInitialized] = (0, _react1.useState)(editor.isInitialized);
60
- const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
61
- const dispatchTransaction = (0, _react1.useCallback)((tr)=>{
62
- // @ts-expect-error calling private method
63
- editor.dispatchTransaction(tr);
64
- // Tiptap's dispatchTransaction doesn't trigger
65
- // a re-render, so we need to manually force
66
- // one to ensure that React stays in sync.
67
- forceUpdate();
68
- }, [
69
- editor,
70
- forceUpdate
71
- ]);
72
- const initialEditorProps = {
73
- ...editor.options.editorProps,
74
- attributes: {
75
- role: "textbox",
76
- ...editor.options.editorProps?.attributes
77
- }
78
- };
79
- const { nodeViews: customNodeViews, markViews: customMarkViews } = editor.isDestroyed ? {
80
- nodeViews: undefined,
81
- markViews: undefined
82
- } : editor.view.props;
83
- const contextValue = (0, _react1.useMemo)(()=>({
84
- editor
85
- }), [
86
- editor
87
- ]);
88
- const onEditorInitialize = (0, _react1.useCallback)(()=>{
89
- setIsEditorInitialized(true);
90
- }, []);
91
- const onEditorDeinitialize = (0, _react1.useCallback)(()=>{
92
- setIsEditorInitialized(false);
93
- }, []);
94
- const tiptapEditorContextValue = (0, _react1.useMemo)(()=>({
95
- isEditorInitialized,
96
- onEditorInitialize,
97
- onEditorDeinitialize
98
- }), [
99
- isEditorInitialized,
100
- onEditorDeinitialize,
101
- onEditorInitialize
102
- ]);
103
- return /*#__PURE__*/ _react1.default.createElement(_ProseMirror.ProseMirror, {
104
- static: isStatic,
105
- className: "tiptap",
106
- ...initialEditorProps,
107
- markViews: markViews,
108
- customMarkViews: customMarkViews,
109
- nodeViews: nodeViews,
110
- customNodeViews: customNodeViews,
111
- state: editor.state,
112
- dispatchTransaction: dispatchTransaction
113
- }, /*#__PURE__*/ _react1.default.createElement(_react.EditorContext.Provider, {
114
- value: contextValue
115
- }, /*#__PURE__*/ _react1.default.createElement(_TiptapEditorContext.TiptapEditorContext.Provider, {
116
- value: tiptapEditorContextValue
117
- }, children)));
118
- }
@@ -1,26 +0,0 @@
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
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "TiptapEditorContext", {
6
- enumerable: true,
7
- get: function() {
8
- return TiptapEditorContext;
9
- }
10
- });
11
- const _react = require("react");
12
- const TiptapEditorContext = (0, _react.createContext)(null);
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ReactProseMirror", {
6
- enumerable: true,
7
- get: function() {
8
- return ReactProseMirror;
9
- }
10
- });
11
- const _core = require("@tiptap/core");
12
- const _reactKeys = require("../../plugins/reactKeys.js");
13
- const ReactProseMirror = _core.Extension.create({
14
- name: "@handlewithcare/react-prosemirror/reactKeys",
15
- addProseMirrorPlugins () {
16
- return [
17
- (0, _reactKeys.reactKeys)()
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
- };
78
- }
79
- });
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useIsInReactProseMirror", {
6
- enumerable: true,
7
- get: function() {
8
- return useIsInReactProseMirror;
9
- }
10
- });
11
- const _react = require("react");
12
- const _EditorContext = require("../../contexts/EditorContext.js");
13
- function useIsInReactProseMirror() {
14
- return (0, _react.useContext)(_EditorContext.EditorContext) !== null;
15
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useTiptapEditor", {
6
- enumerable: true,
7
- get: function() {
8
- return useTiptapEditor;
9
- }
10
- });
11
- const _react = require("@tiptap/react");
12
- const _StaticEditorView = require("../../StaticEditorView.js");
13
- function useTiptapEditor(options, deps) {
14
- const editor = (0, _react.useEditor)({
15
- ...options,
16
- element: null
17
- }, deps);
18
- // @ts-expect-error private property
19
- editor.editorView ??= new _StaticEditorView.StaticEditorView({
20
- // @ts-expect-error private property
21
- state: editor.editorState,
22
- ...editor.options.editorProps,
23
- attributes: {
24
- role: "textbox",
25
- ...editor.options.editorProps.attributes
26
- }
27
- });
28
- // @ts-expect-error private property
29
- const stateHasPlugins = !!editor.editorState.plugins.length;
30
- const stateNeedsReconfigure = !stateHasPlugins && !editor.isDestroyed;
31
- if (stateNeedsReconfigure) {
32
- const managerPlugins = editor.extensionManager.plugins;
33
- if (managerPlugins.length) {
34
- // @ts-expect-error private property
35
- editor.editorState = editor.editorState.reconfigure({
36
- plugins: editor.extensionManager.plugins
37
- });
38
- // @ts-expect-error private property
39
- editor.editorView.updateState(editor.editorState);
40
- }
41
- }
42
- return editor;
43
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useTiptapEditorEffect", {
6
- enumerable: true,
7
- get: function() {
8
- return useTiptapEditorEffect;
9
- }
10
- });
11
- const _react = require("@tiptap/react");
12
- const _react1 = require("react");
13
- const _ReactEditorView = require("../../ReactEditorView.js");
14
- const _EditorContext = require("../../contexts/EditorContext.js");
15
- const _useEditorEffect = require("../../hooks/useEditorEffect.js");
16
- const _TiptapEditorContext = require("../contexts/TiptapEditorContext.js");
17
- function useTiptapEditorEffect(effect, dependencies) {
18
- const { view } = (0, _react1.useContext)(_EditorContext.EditorContext);
19
- const { editor } = (0, _react.useCurrentEditor)();
20
- const { isEditorInitialized } = (0, _react1.useContext)(_TiptapEditorContext.TiptapEditorContext);
21
- (0, _useEditorEffect.useEditorEffect)(()=>{
22
- if (editor?.view instanceof _ReactEditorView.ReactEditorView && view instanceof _ReactEditorView.ReactEditorView && isEditorInitialized) {
23
- return effect(editor);
24
- }
25
- // The rules of hooks want to be able to statically
26
- // verify the dependencies for the effect, but this will
27
- // have already happened at the call-site.
28
- // eslint-disable-next-line react-hooks/exhaustive-deps
29
- }, dependencies && [
30
- editor,
31
- view,
32
- isEditorInitialized,
33
- ...dependencies
34
- ]);
35
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useTiptapEditorEventCallback", {
6
- enumerable: true,
7
- get: function() {
8
- return useTiptapEditorEventCallback;
9
- }
10
- });
11
- const _react = require("@tiptap/react");
12
- const _react1 = require("react");
13
- const _useEditorEffect = require("../../hooks/useEditorEffect.js");
14
- function assertEditor(editor) {
15
- if (editor) return;
16
- throw new DOMException("Tiptap Editor is not initialized", "InvalidStateError");
17
- }
18
- function useTiptapEditorEventCallback(callback) {
19
- const ref = (0, _react1.useRef)(callback);
20
- const { editor } = (0, _react.useCurrentEditor)();
21
- (0, _useEditorEffect.useEditorEffect)(()=>{
22
- ref.current = callback;
23
- }, [
24
- callback
25
- ]);
26
- return (0, _react1.useCallback)(function() {
27
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
28
- args[_key] = arguments[_key];
29
- }
30
- assertEditor(editor);
31
- return ref.current(editor, ...args);
32
- }, [
33
- editor
34
- ]);
35
- }
@@ -1,48 +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
- ReactProseMirror: function() {
13
- return _ReactProseMirror.ReactProseMirror;
14
- },
15
- TiptapEditor: function() {
16
- return _TiptapEditor.TiptapEditor;
17
- },
18
- TiptapEditorContent: function() {
19
- return _TiptapEditorContent.TiptapEditorContent;
20
- },
21
- TiptapEditorView: function() {
22
- return _TiptapEditorView.TiptapEditorView;
23
- },
24
- tiptapNodeView: function() {
25
- return _tiptapNodeView.tiptapNodeView;
26
- },
27
- useIsInReactProseMirror: function() {
28
- return _useIsInReactProseMirror.useIsInReactProseMirror;
29
- },
30
- useTiptapEditor: function() {
31
- return _useTiptapEditor.useTiptapEditor;
32
- },
33
- useTiptapEditorEffect: function() {
34
- return _useTiptapEditorEffect.useTiptapEditorEffect;
35
- },
36
- useTiptapEditorEventCallback: function() {
37
- return _useTiptapEditorEventCallback.useTiptapEditorEventCallback;
38
- }
39
- });
40
- const _tiptapNodeView = require("./tiptapNodeView.js");
41
- const _TiptapEditorView = require("./TiptapEditorView.js");
42
- const _TiptapEditorContent = require("./TiptapEditorContent.js");
43
- const _useTiptapEditorEffect = require("./hooks/useTiptapEditorEffect.js");
44
- const _useIsInReactProseMirror = require("./hooks/useIsInReactProseMirror.js");
45
- const _useTiptapEditorEventCallback = require("./hooks/useTiptapEditorEventCallback.js");
46
- const _TiptapEditor = require("./TiptapEditor.js");
47
- const _useTiptapEditor = require("./hooks/useTiptapEditor.js");
48
- const _ReactProseMirror = require("./extensions/ReactProseMirror.js");
@@ -1,237 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "tiptapNodeView", {
6
- enumerable: true,
7
- get: function() {
8
- return tiptapNodeView;
9
- }
10
- });
11
- const _core = require("@tiptap/core");
12
- const _react = require("@tiptap/react");
13
- const _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
14
- const _react1 = /*#__PURE__*/ _interop_require_wildcard(require("react"));
15
- const _useEditorEventCallback = require("../hooks/useEditorEventCallback.js");
16
- const _useIgnoreMutation = require("../hooks/useIgnoreMutation.js");
17
- const _useIsNodeSelected = require("../hooks/useIsNodeSelected.js");
18
- const _useStopEvent = require("../hooks/useStopEvent.js");
19
- const _props = require("../props.js");
20
- const _ReactProseMirrorNodeView = require("./ReactProseMirrorNodeView.js");
21
- const _useTiptapEditorEventCallback = require("./hooks/useTiptapEditorEventCallback.js");
22
- function _interop_require_default(obj) {
23
- return obj && obj.__esModule ? obj : {
24
- default: obj
25
- };
26
- }
27
- function _getRequireWildcardCache(nodeInterop) {
28
- if (typeof WeakMap !== "function") return null;
29
- var cacheBabelInterop = new WeakMap();
30
- var cacheNodeInterop = new WeakMap();
31
- return (_getRequireWildcardCache = function(nodeInterop) {
32
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
33
- })(nodeInterop);
34
- }
35
- function _interop_require_wildcard(obj, nodeInterop) {
36
- if (!nodeInterop && obj && obj.__esModule) {
37
- return obj;
38
- }
39
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
40
- return {
41
- default: obj
42
- };
43
- }
44
- var cache = _getRequireWildcardCache(nodeInterop);
45
- if (cache && cache.has(obj)) {
46
- return cache.get(obj);
47
- }
48
- var newObj = {
49
- __proto__: null
50
- };
51
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
52
- for(var key in obj){
53
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
54
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
55
- if (desc && (desc.get || desc.set)) {
56
- Object.defineProperty(newObj, key, desc);
57
- } else {
58
- newObj[key] = obj[key];
59
- }
60
- }
61
- }
62
- newObj.default = obj;
63
- if (cache) {
64
- cache.set(obj, newObj);
65
- }
66
- return newObj;
67
- }
68
- function tiptapNodeView(param) {
69
- let { component: WrappedComponent, extension, as, className = "", attrs, contentDOMElementTag: InnerTag = "div", stopEvent, ignoreMutation } = param;
70
- const TiptapNodeView = /*#__PURE__*/ (0, _react1.memo)(/*#__PURE__*/ (0, _react1.forwardRef)(function TiptapNodeView(param, ref) {
71
- let { children, nodeProps, ...props } = param;
72
- const { node, getPos, decorations, innerDecorations } = nodeProps;
73
- const OuterTag = as ?? (node.type.isInline ? "span" : "div");
74
- const { editor } = (0, _react.useCurrentEditor)();
75
- const extensionManager = editor?.extensionManager ?? null;
76
- const extensions = extensionManager?.extensions ?? null;
77
- const selected = (0, _useIsNodeSelected.useIsNodeSelected)();
78
- const htmlAttributes = (0, _react1.useMemo)(()=>{
79
- if (!extensions) return {};
80
- const attributes = (0, _core.getAttributesFromExtensions)(extensions);
81
- const extensionAttributes = attributes.filter((attribute)=>attribute.type === extension.name);
82
- return (0, _core.getRenderedAttributes)(node, extensionAttributes);
83
- }, [
84
- extensions,
85
- node
86
- ]);
87
- (0, _useStopEvent.useStopEvent)(function(_, event) {
88
- if (stopEvent) {
89
- return stopEvent.call({
90
- name: extension.name,
91
- editor,
92
- type: node.type
93
- }, {
94
- event
95
- });
96
- }
97
- if (!editor || !(this.dom instanceof HTMLElement)) return false;
98
- const nodeView = new _ReactProseMirrorNodeView.ReactProseMirrorNodeView(WrappedComponent, {
99
- extension,
100
- decorations,
101
- editor,
102
- getPos,
103
- HTMLAttributes: htmlAttributes,
104
- innerDecorations,
105
- node,
106
- view: editor.view
107
- }, this.dom, this.contentDOM);
108
- return nodeView.stopEvent(event) ?? false;
109
- });
110
- (0, _useIgnoreMutation.useIgnoreMutation)(function(_, mutation) {
111
- if (ignoreMutation) {
112
- return ignoreMutation.call({
113
- name: extension.name,
114
- editor,
115
- type: node.type
116
- }, {
117
- mutation
118
- });
119
- }
120
- if (!editor || !(this.dom instanceof HTMLElement)) return false;
121
- const nodeView = new _ReactProseMirrorNodeView.ReactProseMirrorNodeView(WrappedComponent, {
122
- extension,
123
- decorations,
124
- editor,
125
- getPos,
126
- HTMLAttributes: htmlAttributes,
127
- innerDecorations,
128
- node,
129
- view: editor.view
130
- }, this.dom, this.contentDOM);
131
- return nodeView.ignoreMutation(mutation) ?? false;
132
- });
133
- const { extraClassName, htmlProps } = (0, _react1.useMemo)(()=>{
134
- if (!attrs) return {};
135
- const resolvedAttrs = typeof attrs === "function" ? attrs({
136
- node,
137
- HTMLAttributes: htmlAttributes
138
- }) : attrs;
139
- const { className: extraClassName, ...htmlProps } = (0, _props.htmlAttrsToReactProps)(resolvedAttrs);
140
- return {
141
- extraClassName,
142
- htmlProps
143
- };
144
- }, [
145
- htmlAttributes,
146
- node
147
- ]);
148
- const finalClassName = (0, _classnames.default)("react-renderer", `node-${node.type.name}`, props.className, className, extraClassName, {
149
- "ProseMirror-selectednode": selected
150
- });
151
- const updateAttributes = (0, _useEditorEventCallback.useEditorEventCallback)((_, attributes)=>{
152
- if (!editor) {
153
- return;
154
- }
155
- editor.commands.command((param)=>{
156
- let { tr } = param;
157
- const pos = getPos();
158
- tr.setNodeMarkup(pos, undefined, {
159
- ...node.attrs,
160
- ...attributes
161
- });
162
- return true;
163
- });
164
- });
165
- const deleteNode = (0, _useEditorEventCallback.useEditorEventCallback)(()=>{
166
- if (!editor) {
167
- return;
168
- }
169
- const from = getPos();
170
- const to = from + node.nodeSize;
171
- editor.commands.deleteRange({
172
- from,
173
- to
174
- });
175
- });
176
- const nodeViewContent = (0, _react1.useMemo)(()=>/*#__PURE__*/ _react1.default.createElement(InnerTag, {
177
- "data-node-view-content-inner": node.type.name,
178
- style: {
179
- whitespace: "inherit"
180
- }
181
- }, children), [
182
- children,
183
- node.type.name
184
- ]);
185
- const onDragStart = (0, _useTiptapEditorEventCallback.useTiptapEditorEventCallback)((editor, event)=>{
186
- // TODO: We should probably just merge this with our own
187
- // ref, I'm being lazy since we are providing this
188
- // ref in the first place (in ReactNodeView), so we know
189
- // it's an object
190
- const dom = typeof ref === "object" ? ref?.current : null;
191
- if (!dom) return;
192
- const viewDesc = dom.pmViewDesc;
193
- if (!viewDesc) return;
194
- const nodeView = new _ReactProseMirrorNodeView.ReactProseMirrorNodeView(WrappedComponent, {
195
- extension,
196
- decorations,
197
- editor,
198
- getPos,
199
- HTMLAttributes: htmlAttributes,
200
- innerDecorations,
201
- node,
202
- view: editor.view
203
- }, viewDesc.dom, viewDesc.contentDOM);
204
- return nodeView.onDragStart(event);
205
- });
206
- const nodeViewContext = (0, _react1.useMemo)(()=>({
207
- nodeViewContentChildren: nodeViewContent,
208
- onDragStart
209
- }), [
210
- nodeViewContent,
211
- onDragStart
212
- ]);
213
- if (!editor) return null;
214
- return /*#__PURE__*/ _react1.default.createElement(_react.ReactNodeViewContext.Provider, {
215
- value: nodeViewContext
216
- }, /*#__PURE__*/ _react1.default.createElement(OuterTag, {
217
- ref: ref,
218
- ...props,
219
- ...htmlProps,
220
- className: finalClassName
221
- }, /*#__PURE__*/ _react1.default.createElement(WrappedComponent, {
222
- node: node,
223
- getPos: getPos,
224
- view: editor.view,
225
- editor: editor,
226
- decorations: decorations,
227
- innerDecorations: innerDecorations,
228
- extension: extension,
229
- HTMLAttributes: htmlAttributes,
230
- selected: selected,
231
- updateAttributes: updateAttributes,
232
- deleteNode: deleteNode
233
- })));
234
- }));
235
- TiptapNodeView.displayName = `TiptapNodeView(${WrappedComponent.displayName ?? "Anonymous"})`;
236
- return TiptapNodeView;
237
- } // const defaultOnDragStart = NodeView.