@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.
Files changed (67) hide show
  1. package/dist/cjs/plugins/beforeInputPlugin.js +3 -9
  2. package/dist/cjs/tiptap/TiptapEditorContent.js +8 -4
  3. package/dist/cjs/tiptap/TiptapNodeView.js +26 -0
  4. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +59 -0
  5. package/dist/esm/plugins/beforeInputPlugin.js +3 -9
  6. package/dist/esm/tiptap/TiptapEditorContent.js +9 -5
  7. package/dist/esm/tiptap/TiptapNodeView.js +22 -0
  8. package/dist/esm/tiptap/extensions/ReactProseMirror.js +60 -2
  9. package/dist/tsconfig.tsbuildinfo +1 -1
  10. package/dist/types/constants.d.ts +1 -1
  11. package/dist/types/props.d.ts +26 -26
  12. package/dist/types/tiptap/TiptapNodeView.d.ts +15 -0
  13. package/package.json +1 -1
  14. package/dist/esm/@jest/pattern/src/__tests__/TestPathPatterns.test.js +0 -241
  15. package/dist/esm/@swc/cli/lib/swc/__tests__/compile.test.js +0 -19
  16. package/dist/esm/@swc/cli/lib/swc/__tests__/options.test.js +0 -315
  17. package/dist/esm/@swc/cli/lib/swc/__tests__/sources.test.js +0 -161
  18. package/dist/esm/@uiw/react-codemirror/src/__tests__/index.test.js +0 -111
  19. package/dist/esm/cheerio/src/__tests__/deprecated.spec.js +0 -249
  20. package/dist/esm/cheerio/src/__tests__/xml.spec.js +0 -55
  21. package/dist/esm/components/__tests__/ProseMirror.composition.test.js +0 -395
  22. package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +0 -266
  23. package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +0 -968
  24. package/dist/esm/components/__tests__/ProseMirror.draw.test.js +0 -335
  25. package/dist/esm/components/__tests__/ProseMirror.mobile.test.js +0 -54
  26. package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +0 -553
  27. package/dist/esm/components/__tests__/ProseMirror.selection.test.js +0 -440
  28. package/dist/esm/components/__tests__/ProseMirror.test.js +0 -324
  29. package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +0 -98
  30. package/dist/esm/hooks/__tests__/useEditorEffect.test.js +0 -134
  31. package/dist/esm/jsx-ast-utils/__tests__/helper.js +0 -83
  32. package/dist/esm/jsx-ast-utils/__tests__/src/elementType-test.js +0 -76
  33. package/dist/esm/jsx-ast-utils/__tests__/src/eventHandlers-test.js +0 -98
  34. package/dist/esm/jsx-ast-utils/__tests__/src/getProp-parser-test.js +0 -188
  35. package/dist/esm/jsx-ast-utils/__tests__/src/getProp-test.js +0 -119
  36. package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-babelparser-test.js +0 -393
  37. package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-flowparser-test.js +0 -379
  38. package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-babelparser-test.js +0 -925
  39. package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-flowparser-test.js +0 -700
  40. package/dist/esm/jsx-ast-utils/__tests__/src/hasProp-test.js +0 -350
  41. package/dist/esm/jsx-ast-utils/__tests__/src/index-test.js +0 -24
  42. package/dist/esm/jsx-ast-utils/__tests__/src/propName-test.js +0 -37
  43. package/dist/esm/plugins/__tests__/reactKeys.test.js +0 -77
  44. package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.d.js +0 -1
  45. package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.js +0 -97
  46. package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.d.js +0 -1
  47. package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.js +0 -319
  48. package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.d.js +0 -1
  49. package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.js +0 -62
  50. package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.d.js +0 -1
  51. package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.js +0 -80
  52. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.d.js +0 -1
  53. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.js +0 -22
  54. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.d.js +0 -1
  55. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.js +0 -20
  56. package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.d.js +0 -1
  57. package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.js +0 -219
  58. package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.d.js +0 -1
  59. package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.js +0 -323
  60. package/dist/esm/tsconfig-paths/src/__tests__/config-loader.test.js +0 -89
  61. package/dist/esm/tsconfig-paths/src/__tests__/data/match-path-data.js +0 -314
  62. package/dist/esm/tsconfig-paths/src/__tests__/filesystem.test.js +0 -58
  63. package/dist/esm/tsconfig-paths/src/__tests__/mapping-entry.test.js +0 -76
  64. package/dist/esm/tsconfig-paths/src/__tests__/match-path-async.test.js +0 -12
  65. package/dist/esm/tsconfig-paths/src/__tests__/match-path-sync.test.js +0 -10
  66. package/dist/esm/tsconfig-paths/src/__tests__/try-path.test.js +0 -214
  67. 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
- // if (
20
- // view.someProp("handleTextInput", (f) =>
21
- // f(view, from, to, eventData, () =>
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 _useEditorEffect = require("../hooks/useEditorEffect.js");
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, _useEditorEffect.useEditorEffect)((view)=>{
106
- if (editor.view === view) {
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
- // if (
10
- // view.someProp("handleTextInput", (f) =>
11
- // f(view, from, to, eventData, () =>
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 { useEditorEffect } from "../hooks/useEditorEffect.js";
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
- useEditorEffect((view)=>{
55
- if (editor.view === view) {
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 { // ReactKeysPluginMeta,
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
  });