@tiptap/react 2.5.2 → 2.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +48 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +7 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/useEditor.ts +7 -1
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,11 @@ var ReactDOM = require('react-dom');
|
|
|
6
6
|
var core = require('@tiptap/core');
|
|
7
7
|
var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
|
|
8
8
|
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
12
|
+
var ReactDOM__default = /*#__PURE__*/_interopDefaultCompat(ReactDOM);
|
|
13
|
+
|
|
9
14
|
const mergeRefs = (...refs) => {
|
|
10
15
|
return (node) => {
|
|
11
16
|
refs.forEach(ref => {
|
|
@@ -19,14 +24,14 @@ const mergeRefs = (...refs) => {
|
|
|
19
24
|
};
|
|
20
25
|
};
|
|
21
26
|
const Portals = ({ renderers }) => {
|
|
22
|
-
return (
|
|
23
|
-
return
|
|
27
|
+
return (React__default.default.createElement(React__default.default.Fragment, null, Object.entries(renderers).map(([key, renderer]) => {
|
|
28
|
+
return ReactDOM__default.default.createPortal(renderer.reactElement, renderer.element, key);
|
|
24
29
|
})));
|
|
25
30
|
};
|
|
26
|
-
class PureEditorContent extends
|
|
31
|
+
class PureEditorContent extends React__default.default.Component {
|
|
27
32
|
constructor(props) {
|
|
28
33
|
super(props);
|
|
29
|
-
this.editorContentRef =
|
|
34
|
+
this.editorContentRef = React__default.default.createRef();
|
|
30
35
|
this.initialized = false;
|
|
31
36
|
this.state = {
|
|
32
37
|
renderers: {},
|
|
@@ -108,24 +113,24 @@ class PureEditorContent extends React.Component {
|
|
|
108
113
|
}
|
|
109
114
|
render() {
|
|
110
115
|
const { editor, innerRef, ...rest } = this.props;
|
|
111
|
-
return (
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
return (React__default.default.createElement(React__default.default.Fragment, null,
|
|
117
|
+
React__default.default.createElement("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }),
|
|
118
|
+
React__default.default.createElement(Portals, { renderers: this.state.renderers })));
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
// EditorContent should be re-created whenever the Editor instance changes
|
|
117
122
|
const EditorContentWithKey = React.forwardRef((props, ref) => {
|
|
118
|
-
const key =
|
|
123
|
+
const key = React__default.default.useMemo(() => {
|
|
119
124
|
return Math.floor(Math.random() * 0xFFFFFFFF).toString();
|
|
120
125
|
}, [props.editor]);
|
|
121
126
|
// Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
|
|
122
|
-
return
|
|
127
|
+
return React__default.default.createElement(PureEditorContent, {
|
|
123
128
|
key,
|
|
124
129
|
innerRef: ref,
|
|
125
130
|
...props,
|
|
126
131
|
});
|
|
127
132
|
});
|
|
128
|
-
const EditorContent =
|
|
133
|
+
const EditorContent = React__default.default.memo(EditorContentWithKey);
|
|
129
134
|
|
|
130
135
|
class Editor extends core.Editor {
|
|
131
136
|
constructor() {
|
|
@@ -157,7 +162,7 @@ var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
|
157
162
|
function requireUseSyncExternalStoreShim_production_min () {
|
|
158
163
|
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
159
164
|
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
160
|
-
var e=
|
|
165
|
+
var e=React__default.default;function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
|
|
161
166
|
function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
|
|
162
167
|
return useSyncExternalStoreShim_production_min;
|
|
163
168
|
}
|
|
@@ -191,9 +196,9 @@ function requireUseSyncExternalStoreShim_development () {
|
|
|
191
196
|
) {
|
|
192
197
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
193
198
|
}
|
|
194
|
-
var React
|
|
199
|
+
var React = React__default.default;
|
|
195
200
|
|
|
196
|
-
var ReactSharedInternals = React
|
|
201
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
197
202
|
|
|
198
203
|
function error(format) {
|
|
199
204
|
{
|
|
@@ -245,10 +250,10 @@ function requireUseSyncExternalStoreShim_development () {
|
|
|
245
250
|
|
|
246
251
|
// dispatch for CommonJS interop named imports.
|
|
247
252
|
|
|
248
|
-
var useState = React
|
|
249
|
-
useEffect = React
|
|
250
|
-
useLayoutEffect = React
|
|
251
|
-
useDebugValue = React
|
|
253
|
+
var useState = React.useState,
|
|
254
|
+
useEffect = React.useEffect,
|
|
255
|
+
useLayoutEffect = React.useLayoutEffect,
|
|
256
|
+
useDebugValue = React.useDebugValue;
|
|
252
257
|
var didWarnOld18Alpha = false;
|
|
253
258
|
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
254
259
|
// because of a very particular set of implementation details and assumptions
|
|
@@ -268,7 +273,7 @@ function requireUseSyncExternalStoreShim_development () {
|
|
|
268
273
|
getServerSnapshot) {
|
|
269
274
|
{
|
|
270
275
|
if (!didWarnOld18Alpha) {
|
|
271
|
-
if (React
|
|
276
|
+
if (React.startTransition !== undefined) {
|
|
272
277
|
didWarnOld18Alpha = true;
|
|
273
278
|
|
|
274
279
|
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
|
|
@@ -391,7 +396,7 @@ function requireUseSyncExternalStoreShim_development () {
|
|
|
391
396
|
var isServerEnvironment = !canUseDOM;
|
|
392
397
|
|
|
393
398
|
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
394
|
-
var useSyncExternalStore$2 = React
|
|
399
|
+
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
395
400
|
|
|
396
401
|
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
|
|
397
402
|
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
@@ -437,7 +442,7 @@ var hasRequiredWithSelector_production_min;
|
|
|
437
442
|
function requireWithSelector_production_min () {
|
|
438
443
|
if (hasRequiredWithSelector_production_min) return withSelector_production_min;
|
|
439
444
|
hasRequiredWithSelector_production_min = 1;
|
|
440
|
-
var h=
|
|
445
|
+
var h=React__default.default,n=requireShim();function p(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var q="function"===typeof Object.is?Object.is:p,r=n.useSyncExternalStore,t=h.useRef,u=h.useEffect,v=h.useMemo,w=h.useDebugValue;
|
|
441
446
|
withSelector_production_min.useSyncExternalStoreWithSelector=function(a,b,e,l,g){var c=t(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f;}else f=c.current;c=v(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==g&&f.hasValue){var b=f.value;if(g(b,a))return k=b}return k=a}b=k;if(q(d,a))return b;var e=l(a);if(void 0!==g&&g(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return [function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,g]);var d=r(a,c[0],c[1]);
|
|
442
447
|
u(function(){f.hasValue=!0;f.value=d;},[d]);w(d);return d};
|
|
443
448
|
return withSelector_production_min;
|
|
@@ -472,7 +477,7 @@ function requireWithSelector_development () {
|
|
|
472
477
|
) {
|
|
473
478
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
474
479
|
}
|
|
475
|
-
var React
|
|
480
|
+
var React = React__default.default;
|
|
476
481
|
var shim = requireShim();
|
|
477
482
|
|
|
478
483
|
/**
|
|
@@ -490,10 +495,10 @@ function requireWithSelector_development () {
|
|
|
490
495
|
|
|
491
496
|
// for CommonJS interop.
|
|
492
497
|
|
|
493
|
-
var useRef = React
|
|
494
|
-
useEffect = React
|
|
495
|
-
useMemo = React
|
|
496
|
-
useDebugValue = React
|
|
498
|
+
var useRef = React.useRef,
|
|
499
|
+
useEffect = React.useEffect,
|
|
500
|
+
useMemo = React.useMemo,
|
|
501
|
+
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
|
|
497
502
|
|
|
498
503
|
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
499
504
|
// Use this to track the rendered snapshot.
|
|
@@ -737,8 +742,14 @@ function useEditor(options = {}, deps = []) {
|
|
|
737
742
|
// for ssr, this is the first time the editor is created
|
|
738
743
|
setEditor(editorInstance);
|
|
739
744
|
}
|
|
745
|
+
else if (Array.isArray(deps) && deps.length) {
|
|
746
|
+
// the deps array is used to re-initialize the editor instance
|
|
747
|
+
editorInstance = new Editor(options);
|
|
748
|
+
setEditor(editorInstance);
|
|
749
|
+
}
|
|
740
750
|
else {
|
|
741
|
-
// if the editor does exist,
|
|
751
|
+
// if the editor does exist & deps are empty, we don't need to re-initialize the editor
|
|
752
|
+
// we can fast-path to update the editor options on the existing instance
|
|
742
753
|
editorInstance.setOptions(options);
|
|
743
754
|
}
|
|
744
755
|
}, deps);
|
|
@@ -875,9 +886,9 @@ function EditorProvider({ children, slotAfter, slotBefore, ...editorOptions }) {
|
|
|
875
886
|
if (!editor) {
|
|
876
887
|
return null;
|
|
877
888
|
}
|
|
878
|
-
return (
|
|
889
|
+
return (React__default.default.createElement(EditorContext.Provider, { value: { editor } },
|
|
879
890
|
slotBefore,
|
|
880
|
-
|
|
891
|
+
React__default.default.createElement(EditorConsumer, null, ({ editor: currentEditor }) => (React__default.default.createElement(EditorContent, { editor: currentEditor }))),
|
|
881
892
|
children,
|
|
882
893
|
slotAfter));
|
|
883
894
|
}
|
|
@@ -910,7 +921,7 @@ const BubbleMenu = (props) => {
|
|
|
910
921
|
menuEditor.registerPlugin(plugin);
|
|
911
922
|
return () => menuEditor.unregisterPlugin(pluginKey);
|
|
912
923
|
}, [props.editor, currentEditor, element]);
|
|
913
|
-
return (
|
|
924
|
+
return (React__default.default.createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
|
|
914
925
|
};
|
|
915
926
|
|
|
916
927
|
const FloatingMenu = (props) => {
|
|
@@ -944,7 +955,7 @@ const FloatingMenu = (props) => {
|
|
|
944
955
|
currentEditor,
|
|
945
956
|
element,
|
|
946
957
|
]);
|
|
947
|
-
return (
|
|
958
|
+
return (React__default.default.createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
|
|
948
959
|
};
|
|
949
960
|
|
|
950
961
|
const ReactNodeViewContext = React.createContext({
|
|
@@ -955,16 +966,16 @@ const useReactNodeView = () => React.useContext(ReactNodeViewContext);
|
|
|
955
966
|
const NodeViewContent = props => {
|
|
956
967
|
const Tag = props.as || 'div';
|
|
957
968
|
const { nodeViewContentRef } = useReactNodeView();
|
|
958
|
-
return (
|
|
969
|
+
return (React__default.default.createElement(Tag, { ...props, ref: nodeViewContentRef, "data-node-view-content": "", style: {
|
|
959
970
|
whiteSpace: 'pre-wrap',
|
|
960
971
|
...props.style,
|
|
961
972
|
} }));
|
|
962
973
|
};
|
|
963
974
|
|
|
964
|
-
const NodeViewWrapper =
|
|
975
|
+
const NodeViewWrapper = React__default.default.forwardRef((props, ref) => {
|
|
965
976
|
const { onDragStart } = useReactNodeView();
|
|
966
977
|
const Tag = props.as || 'div';
|
|
967
|
-
return (
|
|
978
|
+
return (React__default.default.createElement(Tag, { ...props, ref: ref, "data-node-view-wrapper": "", onDragStart: onDragStart, style: {
|
|
968
979
|
whiteSpace: 'normal',
|
|
969
980
|
...props.style,
|
|
970
981
|
} }));
|
|
@@ -1029,7 +1040,7 @@ class ReactRenderer {
|
|
|
1029
1040
|
this.ref = ref;
|
|
1030
1041
|
};
|
|
1031
1042
|
}
|
|
1032
|
-
this.reactElement =
|
|
1043
|
+
this.reactElement = React__default.default.createElement(Component, { ...props });
|
|
1033
1044
|
(_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.setRenderer(this.id, this);
|
|
1034
1045
|
}
|
|
1035
1046
|
updateProps(props = {}) {
|
|
@@ -1071,9 +1082,9 @@ class ReactNodeView extends core.NodeView {
|
|
|
1071
1082
|
element.appendChild(this.contentDOMElement);
|
|
1072
1083
|
}
|
|
1073
1084
|
};
|
|
1074
|
-
return (
|
|
1075
|
-
|
|
1076
|
-
|
|
1085
|
+
return (React__default.default.createElement(React__default.default.Fragment, null,
|
|
1086
|
+
React__default.default.createElement(ReactNodeViewContext.Provider, { value: { onDragStart, nodeViewContentRef } },
|
|
1087
|
+
React__default.default.createElement(Component, { ...componentProps }))));
|
|
1077
1088
|
};
|
|
1078
1089
|
ReactNodeViewProvider.displayName = 'ReactNodeView';
|
|
1079
1090
|
if (this.node.isLeaf) {
|