@handlewithcare/react-prosemirror 2.8.0-tiptap.18 → 2.8.0-tiptap.20

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 (62) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/components/ChildNodeViews.js +6 -4
  3. package/dist/cjs/components/ProseMirror.js +6 -3
  4. package/dist/cjs/components/ProseMirrorDoc.js +1 -1
  5. package/dist/cjs/components/marks/CustomMarkView.js +107 -0
  6. package/dist/cjs/components/marks/DefaultMarkView.js +69 -0
  7. package/dist/cjs/components/marks/MarkView.js +85 -0
  8. package/dist/cjs/components/marks/MarkViewComponentProps.js +4 -0
  9. package/dist/cjs/components/marks/OldMarkView.js +120 -0
  10. package/dist/cjs/components/marks/ReactMarkView.js +97 -0
  11. package/dist/cjs/components/nodes/CustomNodeView.js +132 -0
  12. package/dist/cjs/components/nodes/DefaultNodeView.js +67 -0
  13. package/dist/cjs/components/nodes/DocNodeView.js +96 -0
  14. package/dist/cjs/components/nodes/NodeView.js +86 -0
  15. package/dist/cjs/components/nodes/NodeViewComponentProps.js +4 -0
  16. package/dist/cjs/components/nodes/ReactNodeView.js +174 -0
  17. package/dist/cjs/contexts/NodeViewContext.js +1 -1
  18. package/dist/cjs/hooks/useMarkViewDescription.js +125 -0
  19. package/dist/cjs/tiptap/TiptapEditorView.js +4 -5
  20. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +12 -0
  21. package/dist/cjs/tiptap/tiptapNodeView.js +37 -3
  22. package/dist/esm/components/ChildNodeViews.js +6 -4
  23. package/dist/esm/components/ProseMirror.js +6 -3
  24. package/dist/esm/components/ProseMirrorDoc.js +1 -1
  25. package/dist/esm/components/marks/CustomMarkView.js +56 -0
  26. package/dist/esm/components/marks/DefaultMarkView.js +18 -0
  27. package/dist/esm/components/marks/MarkView.js +34 -0
  28. package/dist/esm/components/marks/MarkViewComponentProps.js +1 -0
  29. package/dist/esm/components/marks/OldMarkView.js +69 -0
  30. package/dist/esm/components/marks/ReactMarkView.js +46 -0
  31. package/dist/esm/components/nodes/CustomNodeView.js +81 -0
  32. package/dist/esm/components/nodes/DefaultNodeView.js +16 -0
  33. package/dist/esm/components/nodes/DocNodeView.js +45 -0
  34. package/dist/esm/components/nodes/NodeView.js +35 -0
  35. package/dist/esm/components/nodes/NodeViewComponentProps.js +1 -0
  36. package/dist/esm/components/nodes/ReactNodeView.js +123 -0
  37. package/dist/esm/contexts/NodeViewContext.js +1 -1
  38. package/dist/esm/hooks/useMarkViewDescription.js +115 -0
  39. package/dist/esm/tiptap/TiptapEditorView.js +4 -5
  40. package/dist/esm/tiptap/hooks/useTiptapEditor.js +12 -0
  41. package/dist/esm/tiptap/tiptapNodeView.js +38 -4
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/dist/types/components/ProseMirror.d.ts +10 -3
  44. package/dist/types/components/marks/CustomMarkView.d.ts +12 -0
  45. package/dist/types/components/marks/DefaultMarkView.d.ts +3 -0
  46. package/dist/types/components/marks/MarkView.d.ts +10 -0
  47. package/dist/types/components/marks/MarkViewComponentProps.d.ts +10 -0
  48. package/dist/types/components/marks/OldMarkView.d.ts +10 -0
  49. package/dist/types/components/marks/ReactMarkView.d.ts +12 -0
  50. package/dist/types/components/nodes/CustomNodeView.d.ts +12 -0
  51. package/dist/types/components/nodes/DefaultNodeView.d.ts +3 -0
  52. package/dist/types/components/nodes/DocNodeView.d.ts +12 -0
  53. package/dist/types/components/nodes/NodeView.d.ts +11 -0
  54. package/dist/types/components/nodes/NodeViewComponentProps.d.ts +12 -0
  55. package/dist/types/components/nodes/ReactNodeView.d.ts +13 -0
  56. package/dist/types/contexts/NodeViewContext.d.ts +3 -2
  57. package/dist/types/hooks/useMarkViewDescription.d.ts +19 -0
  58. package/dist/types/hooks/useNodeViewDescriptor.d.ts +1 -1
  59. package/dist/types/index.d.ts +2 -1
  60. package/dist/types/tiptap/TiptapEditorView.d.ts +4 -2
  61. package/dist/types/tiptap/tiptapNodeView.d.ts +1 -1
  62. package/package.json +1 -1
package/README.md CHANGED
@@ -471,6 +471,14 @@ type ProseMirror = (
471
471
  customNodeViews?: {
472
472
  [nodeType: string]: NodeViewConstructor;
473
473
  };
474
+ markViews?: {
475
+ [markType: string]: ForwardRefExoticComponent<
476
+ MarkViewComponentProps & RefAttributes<any>
477
+ >;
478
+ };
479
+ customMarkViews?: {
480
+ [markType: string]: MarkViewConstructor;
481
+ };
474
482
  }
475
483
  ) => JSX.Element;
476
484
  ```
@@ -22,13 +22,13 @@ const _EditorContext = require("../contexts/EditorContext.js");
22
22
  const _iterDeco = require("../decorations/iterDeco.js");
23
23
  const _useReactKeys = require("../hooks/useReactKeys.js");
24
24
  const _props = require("../props.js");
25
- const _MarkView = require("./MarkView.js");
26
25
  const _NativeWidgetView = require("./NativeWidgetView.js");
27
- const _NodeView = require("./NodeView.js");
28
26
  const _SeparatorHackView = require("./SeparatorHackView.js");
29
27
  const _TextNodeView = require("./TextNodeView.js");
30
28
  const _TrailingHackView = require("./TrailingHackView.js");
31
29
  const _WidgetView = require("./WidgetView.js");
30
+ const _MarkView = require("./marks/MarkView.js");
31
+ const _NodeView = require("./nodes/NodeView.js");
32
32
  function _getRequireWildcardCache(nodeInterop) {
33
33
  if (typeof WeakMap !== "function") return null;
34
34
  var cacheBabelInterop = new WeakMap();
@@ -149,7 +149,8 @@ const InlinePartition = /*#__PURE__*/ (0, _react.memo)(function InlinePartition(
149
149
  return /*#__PURE__*/ _react.default.createElement(_MarkView.MarkView, {
150
150
  key: firstChild.key,
151
151
  mark: firstMark,
152
- getPos: getPos
152
+ getPos: getPos,
153
+ inline: true
153
154
  }, /*#__PURE__*/ _react.default.createElement(InlineView, {
154
155
  key: firstChild.key,
155
156
  getInnerPos: getInnerPos,
@@ -261,7 +262,8 @@ const ChildElement = /*#__PURE__*/ (0, _react.memo)(function ChildElement(param)
261
262
  if (child.type === "node") {
262
263
  return child.marks.reduce((element, mark)=>/*#__PURE__*/ _react.default.createElement(_MarkView.MarkView, {
263
264
  mark: mark,
264
- getPos: getPos
265
+ getPos: getPos,
266
+ inline: false
265
267
  }, element), /*#__PURE__*/ _react.default.createElement(_NodeView.NodeView, {
266
268
  key: child.key,
267
269
  outerDeco: child.outerDeco,
@@ -71,21 +71,24 @@ const rootChildDescriptorsContextValue = {
71
71
  }
72
72
  };
73
73
  function ProseMirrorInner(param) {
74
- let { className, children, nodeViews, customNodeViews, ...props } = param;
74
+ let { className, children, nodeViews, customNodeViews, markViews, customMarkViews, ...props } = param;
75
75
  const [mount, setMount] = (0, _react.useState)(null);
76
76
  const { editor, state } = (0, _useEditor.useEditor)(mount, {
77
77
  ...props,
78
- nodeViews: customNodeViews
78
+ nodeViews: customNodeViews,
79
+ markViews: customMarkViews
79
80
  });
80
81
  const nodeViewConstructors = editor.view.nodeViews;
81
82
  const nodeViewContextValue = (0, _react.useMemo)(()=>{
82
83
  return {
83
84
  components: {
84
- ...nodeViews
85
+ ...nodeViews,
86
+ ...markViews
85
87
  },
86
88
  constructors: nodeViewConstructors
87
89
  };
88
90
  }, [
91
+ markViews,
89
92
  nodeViewConstructors,
90
93
  nodeViews
91
94
  ]);
@@ -17,7 +17,7 @@ _export(exports, {
17
17
  }
18
18
  });
19
19
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
20
- const _DocNodeView = require("./DocNodeView.js");
20
+ const _DocNodeView = require("./nodes/DocNodeView.js");
21
21
  function _getRequireWildcardCache(nodeInterop) {
22
22
  if (typeof WeakMap !== "function") return null;
23
23
  var cacheBabelInterop = new WeakMap();
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "CustomMarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return CustomMarkView;
9
+ }
10
+ });
11
+ const _prosemirrormodel = require("prosemirror-model");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
+ const _reactdom = require("react-dom");
14
+ const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
15
+ const _useMarkViewDescription = require("../../hooks/useMarkViewDescription.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
+ const CustomMarkView = /*#__PURE__*/ (0, _react.memo)(function CustomMarkView(param) {
58
+ let { constructor, mark, inline, getPos, children } = param;
59
+ const ref = (0, _react.useRef)(null);
60
+ const innerRef = (0, _react.useRef)(null);
61
+ const markProps = (0, _react.useMemo)(()=>({
62
+ mark,
63
+ inline,
64
+ getPos
65
+ }), [
66
+ mark,
67
+ inline,
68
+ getPos
69
+ ]);
70
+ const createMarkView = function() {
71
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
72
+ args[_key] = arguments[_key];
73
+ }
74
+ const markView = constructor(...args);
75
+ if (!markView || !markView.dom) {
76
+ const spec = mark.type.spec.toDOM?.(mark, inline);
77
+ if (!spec) {
78
+ throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
79
+ }
80
+ return _prosemirrormodel.DOMSerializer.renderSpec(document, spec, null);
81
+ }
82
+ return markView;
83
+ };
84
+ const { childContextValue, contentDOM } = (0, _useMarkViewDescription.useMarkViewDescription)(ref, function() {
85
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
86
+ args[_key] = arguments[_key];
87
+ }
88
+ const markView = createMarkView(...args);
89
+ const dom = markView.dom;
90
+ const wrapperDOM = innerRef.current ?? ref.current;
91
+ return {
92
+ ...markView,
93
+ destroy () {
94
+ markView.destroy?.();
95
+ wrapperDOM.removeChild(dom);
96
+ },
97
+ ignoreMutation: markView.ignoreMutation
98
+ };
99
+ }, markProps);
100
+ const Component = inline ? "span" : "div";
101
+ const props = {
102
+ ref: innerRef
103
+ };
104
+ return /*#__PURE__*/ _react.default.createElement(Component, props, contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
105
+ value: childContextValue
106
+ }, children), contentDOM) : null);
107
+ });
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "DefaultMarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return DefaultMarkView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _OutputSpec = require("../OutputSpec.js");
13
+ function _getRequireWildcardCache(nodeInterop) {
14
+ if (typeof WeakMap !== "function") return null;
15
+ var cacheBabelInterop = new WeakMap();
16
+ var cacheNodeInterop = new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop) {
18
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {
35
+ __proto__: null
36
+ };
37
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
38
+ for(var key in obj){
39
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
40
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
41
+ if (desc && (desc.get || desc.set)) {
42
+ Object.defineProperty(newObj, key, desc);
43
+ } else {
44
+ newObj[key] = obj[key];
45
+ }
46
+ }
47
+ }
48
+ newObj.default = obj;
49
+ if (cache) {
50
+ cache.set(obj, newObj);
51
+ }
52
+ return newObj;
53
+ }
54
+ const DefaultMarkView = /*#__PURE__*/ (0, _react.forwardRef)(function DefaultMarkView(param, ref) {
55
+ let { markProps: { mark, inline }, children, ...props } = param;
56
+ const spec = (0, _react.useMemo)(()=>mark.type.spec.toDOM?.(mark, inline), [
57
+ mark,
58
+ inline
59
+ ]);
60
+ if (!spec) {
61
+ throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
62
+ }
63
+ return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
64
+ ...props,
65
+ outputSpec: spec,
66
+ ref: ref,
67
+ isMark: true
68
+ }, children);
69
+ });
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MarkView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _NodeViewContext = require("../../contexts/NodeViewContext.js");
13
+ const _CustomMarkView = require("./CustomMarkView.js");
14
+ const _DefaultMarkView = require("./DefaultMarkView.js");
15
+ const _ReactMarkView = require("./ReactMarkView.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
+ const MarkView = /*#__PURE__*/ (0, _react.memo)(function MarkView(props) {
58
+ const { components, constructors } = (0, _react.useContext)(_NodeViewContext.NodeViewContext);
59
+ const component = components[props.mark.type.name] ?? _DefaultMarkView.DefaultMarkView;
60
+ const constructor = constructors[props.mark.type.name];
61
+ // Construct a wrapper component so that the mark view remounts when either
62
+ // its component or constructor changes. A React mark view would remount
63
+ // if its underlying component changed without this wrapper, but a custom
64
+ // mark view otherwise uses the same React components for all custom mark views.
65
+ const Component = (0, _react.useMemo)(()=>{
66
+ if (constructor) {
67
+ return function MarkView(props) {
68
+ return /*#__PURE__*/ _react.default.createElement(_CustomMarkView.CustomMarkView, {
69
+ constructor: constructor,
70
+ ...props
71
+ });
72
+ };
73
+ }
74
+ return function NodeView(props) {
75
+ return /*#__PURE__*/ _react.default.createElement(_ReactMarkView.ReactMarkView, {
76
+ component: component,
77
+ ...props
78
+ });
79
+ };
80
+ }, [
81
+ component,
82
+ constructor
83
+ ]);
84
+ return /*#__PURE__*/ _react.default.createElement(Component, props);
85
+ });
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MarkView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
13
+ const _useClientLayoutEffect = require("../../hooks/useClientLayoutEffect.js");
14
+ const _viewdesc = require("../../viewdesc.js");
15
+ const _OutputSpec = require("../OutputSpec.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
+ const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function MarkView(param, ref) {
58
+ let { mark, getPos, children, inline = false } = param;
59
+ const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
60
+ const viewDescRef = (0, _react.useRef)(undefined);
61
+ const childDescriptors = (0, _react.useRef)([]);
62
+ const domRef = (0, _react.useRef)(null);
63
+ (0, _react.useImperativeHandle)(ref, ()=>{
64
+ return domRef.current;
65
+ }, []);
66
+ const outputSpec = (0, _react.useMemo)(()=>mark.type.spec.toDOM?.(mark, inline), [
67
+ inline,
68
+ mark
69
+ ]);
70
+ if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
71
+ (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
72
+ const siblings = siblingsRef.current;
73
+ return ()=>{
74
+ if (!viewDescRef.current) return;
75
+ if (siblings.includes(viewDescRef.current)) {
76
+ const index = siblings.indexOf(viewDescRef.current);
77
+ siblings.splice(index, 1);
78
+ }
79
+ };
80
+ }, [
81
+ siblingsRef
82
+ ]);
83
+ (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
84
+ if (!domRef.current) return;
85
+ const firstChildDesc = childDescriptors.current[0];
86
+ if (!viewDescRef.current) {
87
+ viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
88
+ dom: domRef.current,
89
+ contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
90
+ });
91
+ } else {
92
+ viewDescRef.current.parent = parentRef.current;
93
+ viewDescRef.current.spec.dom = viewDescRef.current.dom = domRef.current;
94
+ viewDescRef.current.children = childDescriptors.current;
95
+ viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
96
+ viewDescRef.current.mark = mark;
97
+ }
98
+ if (!siblingsRef.current.includes(viewDescRef.current)) {
99
+ siblingsRef.current.push(viewDescRef.current);
100
+ }
101
+ siblingsRef.current.sort(_viewdesc.sortViewDescs);
102
+ for (const childDesc of childDescriptors.current){
103
+ childDesc.parent = viewDescRef.current;
104
+ }
105
+ });
106
+ const childContextValue = (0, _react.useMemo)(()=>({
107
+ parentRef: viewDescRef,
108
+ siblingsRef: childDescriptors
109
+ }), [
110
+ childDescriptors,
111
+ viewDescRef
112
+ ]);
113
+ return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
114
+ ref: domRef,
115
+ outputSpec: outputSpec,
116
+ isMark: true
117
+ }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
118
+ value: childContextValue
119
+ }, children));
120
+ }));
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ReactMarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ReactMarkView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
13
+ const _IgnoreMutationContext = require("../../contexts/IgnoreMutationContext.js");
14
+ const _useMarkViewDescription = require("../../hooks/useMarkViewDescription.js");
15
+ function _getRequireWildcardCache(nodeInterop) {
16
+ if (typeof WeakMap !== "function") return null;
17
+ var cacheBabelInterop = new WeakMap();
18
+ var cacheNodeInterop = new WeakMap();
19
+ return (_getRequireWildcardCache = function(nodeInterop) {
20
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
21
+ })(nodeInterop);
22
+ }
23
+ function _interop_require_wildcard(obj, nodeInterop) {
24
+ if (!nodeInterop && obj && obj.__esModule) {
25
+ return obj;
26
+ }
27
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
28
+ return {
29
+ default: obj
30
+ };
31
+ }
32
+ var cache = _getRequireWildcardCache(nodeInterop);
33
+ if (cache && cache.has(obj)) {
34
+ return cache.get(obj);
35
+ }
36
+ var newObj = {
37
+ __proto__: null
38
+ };
39
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
40
+ for(var key in obj){
41
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
42
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
43
+ if (desc && (desc.get || desc.set)) {
44
+ Object.defineProperty(newObj, key, desc);
45
+ } else {
46
+ newObj[key] = obj[key];
47
+ }
48
+ }
49
+ }
50
+ newObj.default = obj;
51
+ if (cache) {
52
+ cache.set(obj, newObj);
53
+ }
54
+ return newObj;
55
+ }
56
+ const ReactMarkView = /*#__PURE__*/ (0, _react.memo)(function ReactMarkView(param) {
57
+ let { component: Component, mark, inline, getPos, children } = param;
58
+ const ref = (0, _react.useRef)(null);
59
+ const ignoreMutationRef = (0, _react.useRef)(null);
60
+ const setIgnoreMutation = (0, _react.useCallback)((handler)=>{
61
+ ignoreMutationRef.current = handler;
62
+ return ()=>{
63
+ ignoreMutationRef.current = null;
64
+ return ()=>{
65
+ ignoreMutationRef.current = null;
66
+ };
67
+ };
68
+ }, []);
69
+ const markProps = (0, _react.useMemo)(()=>({
70
+ mark,
71
+ getPos,
72
+ inline
73
+ }), [
74
+ getPos,
75
+ inline,
76
+ mark
77
+ ]);
78
+ const { childContextValue } = (0, _useMarkViewDescription.useMarkViewDescription)(ref, ()=>({
79
+ dom: ref.current,
80
+ ignoreMutation (mutation) {
81
+ const ignoreMutation = ignoreMutationRef.current;
82
+ if (ignoreMutation) {
83
+ return ignoreMutation(mutation);
84
+ }
85
+ return false;
86
+ }
87
+ }), markProps);
88
+ const props = {
89
+ markProps,
90
+ ref
91
+ };
92
+ return /*#__PURE__*/ _react.default.createElement(_IgnoreMutationContext.IgnoreMutationContext.Provider, {
93
+ value: setIgnoreMutation
94
+ }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
95
+ value: childContextValue
96
+ }, /*#__PURE__*/ _react.default.createElement(Component, props, children)));
97
+ });