@handlewithcare/react-prosemirror 2.7.0 → 2.8.0-tiptap.10
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/README.md +71 -5
- package/dist/cjs/StaticEditorView.js +3 -0
- package/dist/cjs/tiptap/TiptapEditor.js +34 -0
- package/dist/cjs/tiptap/TiptapEditorContent.js +136 -0
- package/dist/cjs/tiptap/TiptapEditorView.js +99 -0
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +20 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +29 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +32 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
- package/dist/cjs/tiptap/index.js +44 -0
- package/dist/cjs/tiptap/tiptapNodeView.js +188 -0
- package/dist/esm/@jest/pattern/src/__tests__/TestPathPatterns.test.js +241 -0
- package/dist/esm/@swc/cli/lib/swc/__tests__/compile.test.js +19 -0
- package/dist/esm/@swc/cli/lib/swc/__tests__/options.test.js +315 -0
- package/dist/esm/@swc/cli/lib/swc/__tests__/sources.test.js +161 -0
- package/dist/esm/@uiw/react-codemirror/src/__tests__/index.test.js +111 -0
- package/dist/esm/StaticEditorView.js +3 -0
- package/dist/esm/cheerio/src/__tests__/deprecated.spec.js +249 -0
- package/dist/esm/cheerio/src/__tests__/xml.spec.js +55 -0
- package/dist/esm/components/__tests__/ProseMirror.composition.test.js +395 -0
- package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +266 -0
- package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +968 -0
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +335 -0
- package/dist/esm/components/__tests__/ProseMirror.mobile.test.js +54 -0
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +553 -0
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +440 -0
- package/dist/esm/components/__tests__/ProseMirror.test.js +324 -0
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +98 -0
- package/dist/esm/hooks/__tests__/useEditorEffect.test.js +134 -0
- package/dist/esm/hooks/useEditorEffect.js +4 -0
- package/dist/esm/hooks/useEditorEventCallback.js +3 -5
- package/dist/esm/jsx-ast-utils/__tests__/helper.js +83 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/elementType-test.js +76 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/eventHandlers-test.js +98 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-parser-test.js +188 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-test.js +119 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-babelparser-test.js +393 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-flowparser-test.js +379 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-babelparser-test.js +925 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-flowparser-test.js +700 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/hasProp-test.js +350 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/index-test.js +24 -0
- package/dist/esm/jsx-ast-utils/__tests__/src/propName-test.js +37 -0
- package/dist/esm/plugins/__tests__/reactKeys.test.js +77 -0
- package/dist/esm/tiptap/TiptapEditor.js +24 -0
- package/dist/esm/tiptap/TiptapEditorContent.js +85 -0
- package/dist/esm/tiptap/TiptapEditorView.js +50 -0
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +10 -0
- package/dist/esm/tiptap/hooks/useTiptapEditor.js +19 -0
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +39 -0
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
- package/dist/esm/tiptap/index.js +8 -0
- package/dist/esm/tiptap/tiptapNodeView.js +156 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.js +97 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.js +319 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.js +62 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.js +80 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.js +22 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.js +20 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.js +219 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.d.js +1 -0
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.js +323 -0
- package/dist/esm/tsconfig-paths/src/__tests__/config-loader.test.js +89 -0
- package/dist/esm/tsconfig-paths/src/__tests__/data/match-path-data.js +314 -0
- package/dist/esm/tsconfig-paths/src/__tests__/filesystem.test.js +58 -0
- package/dist/esm/tsconfig-paths/src/__tests__/mapping-entry.test.js +76 -0
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-async.test.js +12 -0
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-sync.test.js +10 -0
- package/dist/esm/tsconfig-paths/src/__tests__/try-path.test.js +214 -0
- package/dist/esm/tsconfig-paths/src/__tests__/tsconfig-loader.test.js +296 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +1 -0
- package/dist/types/StaticEditorView.d.ts +1 -0
- package/dist/types/hooks/useEditorEffect.d.ts +4 -0
- package/dist/types/hooks/useEditorEventCallback.d.ts +3 -5
- package/dist/types/tiptap/TiptapEditor.d.ts +6 -0
- package/dist/types/tiptap/TiptapEditorContent.d.ts +19 -0
- package/dist/types/tiptap/TiptapEditorView.d.ts +13 -0
- package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +2 -0
- package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +4 -0
- package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +21 -0
- package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +13 -0
- package/dist/types/tiptap/index.d.ts +8 -0
- package/dist/types/tiptap/tiptapNodeView.d.ts +48 -0
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://gitter.im/nytimes/react-prosemirror?utm_source=badge&utm_medium=badge&utm_content=badge)
|
|
11
11
|
|
|
12
|
+
## What happened to `@nytimes/react-prosemirror`?
|
|
13
|
+
|
|
14
|
+
On Jan. 17, 2025, the maintainers of the `@nytimes/react-prosemirror` library
|
|
15
|
+
decided fork the v2 release into its own project. It had been developed entirely
|
|
16
|
+
by one developer, @smoores-dev, who had not worked for NYT in years, and was
|
|
17
|
+
struggling to move the project at the speed he desired.
|
|
18
|
+
|
|
19
|
+
This project is that fork, and all future development on the React-based
|
|
20
|
+
ProseMirror renderer will happen in this repository, published as
|
|
21
|
+
`@handlewithcare/react-prosemirror` on NPM.
|
|
22
|
+
|
|
12
23
|
## Installation
|
|
13
24
|
|
|
14
25
|
_Note_: React ProseMirror releases are coupled to specific prosemirror-view
|
|
@@ -77,6 +88,8 @@ import "prosemirror-view/style/prosemirror.css";
|
|
|
77
88
|
- [`useEditorEventCallback`](#useeditoreventcallback)
|
|
78
89
|
- [`useEditorEventListener`](#useeditoreventlistener)
|
|
79
90
|
- [Building node views with React](#building-node-views-with-react)
|
|
91
|
+
- [What's new in v2?](#whats-new-in-v2)
|
|
92
|
+
- [API changes](#api-changes)
|
|
80
93
|
- [API](#api)
|
|
81
94
|
- [`ProseMirror`](#prosemirror)
|
|
82
95
|
- [`ProseMirrorDoc`](#prosemirrordoc)
|
|
@@ -92,7 +105,6 @@ import "prosemirror-view/style/prosemirror.css";
|
|
|
92
105
|
- [`widget`](#widget)
|
|
93
106
|
- [`reorderSiblings`](#reordersiblings)
|
|
94
107
|
- [When should I use this?](#when-should-i-use-this)
|
|
95
|
-
- [Migrations](#migrations)
|
|
96
108
|
- [Looking for someone to collaborate with?](#looking-for-someone-to-collaborate-with)
|
|
97
109
|
|
|
98
110
|
<!-- tocstop -->
|
|
@@ -454,6 +466,64 @@ function ProseMirrorEditor() {
|
|
|
454
466
|
}
|
|
455
467
|
```
|
|
456
468
|
|
|
469
|
+
## What's new in v2?
|
|
470
|
+
|
|
471
|
+
The v2 release constitutes a significant re-write of the library.
|
|
472
|
+
|
|
473
|
+
Previously, React ProseMirror relied on ProseMirror's EditorView to manage the
|
|
474
|
+
DOM for the editor. To integrate it with React, we used React
|
|
475
|
+
[portals](https://react.dev/reference/react-dom/createPortal) to render
|
|
476
|
+
components into ProseMirror-managed DOM nodes, and a
|
|
477
|
+
[useLayoutEffect](https://react.dev/reference/react/useLayoutEffect) to sync
|
|
478
|
+
state updates with the EditorView instance.
|
|
479
|
+
|
|
480
|
+
This approach provided some challenges. First, portals have to be rendered into
|
|
481
|
+
existing, stable DOM nodes, so all React-based custom node views ended up
|
|
482
|
+
wrapped in extra HTML elements. This made styling and producing valid DOM more
|
|
483
|
+
challenging than it should be, and introduced corner cases in browser
|
|
484
|
+
contenteditable implementations. Second, we induced a double render for every
|
|
485
|
+
ProseMirror update, and during the first render, React-based custom node views
|
|
486
|
+
will be rendered with the previous state. This is technically another form of
|
|
487
|
+
the state tearing that this library was designed to prevent, as all _other_
|
|
488
|
+
React components will be rendered with the new state!
|
|
489
|
+
|
|
490
|
+
To overcome these challenges, the new release moves rendering responsibility
|
|
491
|
+
entirely into React. We disabled the EditorView's DOM update cycle, and
|
|
492
|
+
implemented the same update algorithm that prosemirror-view uses with React
|
|
493
|
+
components. The result is a more idiomatic, React-based library, which doesn't
|
|
494
|
+
have any of the issues of the original implementation.
|
|
495
|
+
|
|
496
|
+
### API changes
|
|
497
|
+
|
|
498
|
+
- The [`ProseMirror`](#prosemirror) component API has changed slightly:
|
|
499
|
+
- Instead of passing a `mount` prop with a ref to a child element, users must
|
|
500
|
+
render a [`ProseMirrorDoc`](#prosemirrordoc) component as a child of the
|
|
501
|
+
`ProseMirror` component.
|
|
502
|
+
- The `nodeViews` prop no longer matches the ProseMirror API. Instead,
|
|
503
|
+
`nodeViews` should be a map from node type name to React components, each of
|
|
504
|
+
which must take [`NodeViewComponentProps`](#nodeviewcomponentprops) as
|
|
505
|
+
props. This map should be memoized, or defined outside the React component
|
|
506
|
+
entirely.
|
|
507
|
+
- To pass standard ProseMirror node view constructors, use the
|
|
508
|
+
`customNodeViews` prop
|
|
509
|
+
- The API that React-based node views must implement has changed:
|
|
510
|
+
- There is no longer any need to provide a ProseMirror node view constructor
|
|
511
|
+
function. React-based node views are now just React components that accept
|
|
512
|
+
`NodeViewComponentProps` as props.
|
|
513
|
+
- Props related to the ProseMirror node, such as the node itself, the `getPos`
|
|
514
|
+
function, and decorations, now live in the `nodeProps` property. All other
|
|
515
|
+
props _must_ be spread onto the root element of the node view component,
|
|
516
|
+
aside from `children`, which may be rendered anywhere in the component, as
|
|
517
|
+
appropriate.
|
|
518
|
+
- All node view components must forward their ref to the root element of the
|
|
519
|
+
component.
|
|
520
|
+
- To implement features that would normally live in the node view spec, there
|
|
521
|
+
are new hooks, such as [`useStopEvent`](#usestopevent) and
|
|
522
|
+
[`useSelectNode`](#useselectnode)
|
|
523
|
+
- There is a new export, [`widget`](#widget), which behaves similarly to
|
|
524
|
+
`Decoration.widget` from `prosemirror-view`, but takes a React component
|
|
525
|
+
instead of a `toDOM` method.
|
|
526
|
+
|
|
457
527
|
## API
|
|
458
528
|
|
|
459
529
|
### `ProseMirror`
|
|
@@ -735,10 +805,6 @@ properly track the new positions for the reordered nodes, allowing it to reuse
|
|
|
735
805
|
the same keys. This prevents any issues that could be caused by unexpected
|
|
736
806
|
component remounts.
|
|
737
807
|
|
|
738
|
-
## Migrations
|
|
739
|
-
|
|
740
|
-
- [Migrating from v1 to v2](migration-guides/v2.md)
|
|
741
|
-
|
|
742
808
|
## Looking for someone to collaborate with?
|
|
743
809
|
|
|
744
810
|
Reach out to [Handle with Care](https://handlewithcare.dev/#get-in-touch)! We're
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TiptapEditor", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TiptapEditor;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@tiptap/core");
|
|
12
|
+
const _prosemirrorstate = require("prosemirror-state");
|
|
13
|
+
const _StaticEditorView = require("../StaticEditorView.js");
|
|
14
|
+
let TiptapEditor = class TiptapEditor extends _core.Editor {
|
|
15
|
+
constructor(options = {}){
|
|
16
|
+
super({
|
|
17
|
+
...options,
|
|
18
|
+
element: null
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
get view() {
|
|
22
|
+
return(// @ts-expect-error private property
|
|
23
|
+
this.editorView ?? new _StaticEditorView.StaticEditorView({
|
|
24
|
+
state: _prosemirrorstate.EditorState.create({
|
|
25
|
+
schema: this.extensionManager.schema
|
|
26
|
+
}),
|
|
27
|
+
...this.options.editorProps,
|
|
28
|
+
attributes: {
|
|
29
|
+
role: "textbox",
|
|
30
|
+
...this.extensionManager.attributes
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TiptapEditorContent", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TiptapEditorContent;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _reactdom = require("react-dom");
|
|
13
|
+
const _ProseMirrorDoc = require("../components/ProseMirrorDoc.js");
|
|
14
|
+
const _useEditorEffect = require("../hooks/useEditorEffect.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
|
+
/**
|
|
57
|
+
* This component renders all of the editor's registered "React renderers".
|
|
58
|
+
*/ const Portals = (param)=>{
|
|
59
|
+
let { contentComponent } = param;
|
|
60
|
+
const renderers = (0, _react.useSyncExternalStore)(contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot);
|
|
61
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, Object.values(renderers));
|
|
62
|
+
};
|
|
63
|
+
function getInstance() {
|
|
64
|
+
const subscribers = new Set();
|
|
65
|
+
let renderers = {};
|
|
66
|
+
return {
|
|
67
|
+
/**
|
|
68
|
+
* Subscribe to the editor instance's changes.
|
|
69
|
+
*/ subscribe (callback) {
|
|
70
|
+
subscribers.add(callback);
|
|
71
|
+
return ()=>{
|
|
72
|
+
subscribers.delete(callback);
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
getSnapshot () {
|
|
76
|
+
return renderers;
|
|
77
|
+
},
|
|
78
|
+
getServerSnapshot () {
|
|
79
|
+
return renderers;
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Adds a new React Renderer to the editor.
|
|
83
|
+
*/ setRenderer (id, renderer) {
|
|
84
|
+
renderers = {
|
|
85
|
+
...renderers,
|
|
86
|
+
[id]: /*#__PURE__*/ (0, _reactdom.createPortal)(renderer.reactElement, renderer.element, id)
|
|
87
|
+
};
|
|
88
|
+
subscribers.forEach((subscriber)=>subscriber());
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Removes a React Renderer from the editor.
|
|
92
|
+
*/ removeRenderer (id) {
|
|
93
|
+
const nextRenderers = {
|
|
94
|
+
...renderers
|
|
95
|
+
};
|
|
96
|
+
delete nextRenderers[id];
|
|
97
|
+
renderers = nextRenderers;
|
|
98
|
+
subscribers.forEach((subscriber)=>subscriber());
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function TiptapEditorContent(param) {
|
|
103
|
+
let { editor: editorProp, ...props } = param;
|
|
104
|
+
const editor = editorProp;
|
|
105
|
+
(0, _useEditorEffect.useEditorEffect)((view)=>{
|
|
106
|
+
if (editor.view === view) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// @ts-expect-error private property
|
|
110
|
+
editor.editorView = view;
|
|
111
|
+
editor.contentComponent = getInstance();
|
|
112
|
+
// @ts-expect-error private method
|
|
113
|
+
editor.injectCSS();
|
|
114
|
+
const dom = view.dom;
|
|
115
|
+
dom.editor = editor;
|
|
116
|
+
setTimeout(()=>{
|
|
117
|
+
if (editor.isDestroyed) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
editor.commands.focus(editor.options.autofocus);
|
|
121
|
+
editor.emit("create", {
|
|
122
|
+
editor
|
|
123
|
+
});
|
|
124
|
+
editor.isInitialized = true;
|
|
125
|
+
});
|
|
126
|
+
return ()=>{
|
|
127
|
+
editor.isInitialized = false;
|
|
128
|
+
editor.contentComponent = null;
|
|
129
|
+
};
|
|
130
|
+
}, [
|
|
131
|
+
editor
|
|
132
|
+
]);
|
|
133
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_ProseMirrorDoc.ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ _react.default.createElement(Portals, {
|
|
134
|
+
contentComponent: editor.contentComponent
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
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
|
+
function TiptapEditorView(param) {
|
|
57
|
+
let { editor, nodeViews, children } = param;
|
|
58
|
+
const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
59
|
+
const dispatchTransaction = (0, _react1.useCallback)((tr)=>{
|
|
60
|
+
// @ts-expect-error calling private method
|
|
61
|
+
editor.dispatchTransaction(tr);
|
|
62
|
+
// Tiptap's dispatchTransaction doesn't trigger
|
|
63
|
+
// a re-render, so we need to manually force
|
|
64
|
+
// one to ensure that React stays in sync.
|
|
65
|
+
forceUpdate();
|
|
66
|
+
}, [
|
|
67
|
+
editor,
|
|
68
|
+
forceUpdate
|
|
69
|
+
]);
|
|
70
|
+
const initialEditorProps = {
|
|
71
|
+
...editor.options.editorProps,
|
|
72
|
+
attributes: {
|
|
73
|
+
role: "textbox",
|
|
74
|
+
...editor.options.editorProps?.attributes
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const { nodeViews: customNodeViews, markViews } = editor.isDestroyed ? {
|
|
78
|
+
nodeViews: undefined,
|
|
79
|
+
markViews: undefined
|
|
80
|
+
} : editor.view.props;
|
|
81
|
+
const contextValue = (0, _react1.useMemo)(()=>({
|
|
82
|
+
editor
|
|
83
|
+
}), [
|
|
84
|
+
editor
|
|
85
|
+
]);
|
|
86
|
+
return /*#__PURE__*/ _react1.default.createElement(_ProseMirror.ProseMirror, {
|
|
87
|
+
className: "tiptap",
|
|
88
|
+
...initialEditorProps,
|
|
89
|
+
markViews: markViews,
|
|
90
|
+
nodeViews: nodeViews,
|
|
91
|
+
customNodeViews: customNodeViews,
|
|
92
|
+
state: editor.isDestroyed || editor.state.plugins.length ? editor.state : editor.state.reconfigure({
|
|
93
|
+
plugins: editor.extensionManager.plugins
|
|
94
|
+
}),
|
|
95
|
+
dispatchTransaction: dispatchTransaction
|
|
96
|
+
}, /*#__PURE__*/ _react1.default.createElement(_react.EditorContext.Provider, {
|
|
97
|
+
value: contextValue
|
|
98
|
+
}, children));
|
|
99
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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.extensionManager.attributes
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return editor;
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
function useTiptapEditorEffect(effect, dependencies) {
|
|
17
|
+
const { view } = (0, _react1.useContext)(_EditorContext.EditorContext);
|
|
18
|
+
const { editor } = (0, _react.useCurrentEditor)();
|
|
19
|
+
(0, _useEditorEffect.useEditorEffect)(()=>{
|
|
20
|
+
if (editor?.view instanceof _ReactEditorView.ReactEditorView && view instanceof _ReactEditorView.ReactEditorView) {
|
|
21
|
+
return effect(editor);
|
|
22
|
+
}
|
|
23
|
+
// The rules of hooks want to be able to statically
|
|
24
|
+
// verify the dependencies for the effect, but this will
|
|
25
|
+
// have already happened at the call-site.
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, dependencies && [
|
|
28
|
+
editor,
|
|
29
|
+
view,
|
|
30
|
+
...dependencies
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
useTiptapEditor: function() {
|
|
28
|
+
return _useTiptapEditor.useTiptapEditor;
|
|
29
|
+
},
|
|
30
|
+
useTiptapEditorEffect: function() {
|
|
31
|
+
return _useTiptapEditorEffect.useTiptapEditorEffect;
|
|
32
|
+
},
|
|
33
|
+
useTiptapEditorEventCallback: function() {
|
|
34
|
+
return _useTiptapEditorEventCallback.useTiptapEditorEventCallback;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const _tiptapNodeView = require("./tiptapNodeView.js");
|
|
38
|
+
const _TiptapEditorView = require("./TiptapEditorView.js");
|
|
39
|
+
const _TiptapEditorContent = require("./TiptapEditorContent.js");
|
|
40
|
+
const _useTiptapEditorEffect = require("./hooks/useTiptapEditorEffect.js");
|
|
41
|
+
const _useTiptapEditorEventCallback = require("./hooks/useTiptapEditorEventCallback.js");
|
|
42
|
+
const _TiptapEditor = require("./TiptapEditor.js");
|
|
43
|
+
const _useTiptapEditor = require("./hooks/useTiptapEditor.js");
|
|
44
|
+
const _ReactProseMirror = require("./extensions/ReactProseMirror.js");
|