@handlewithcare/react-prosemirror 2.0.0
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/LICENSE.txt +12 -0
- package/README.md +705 -0
- package/dist/cjs/browser.js +53 -0
- package/dist/cjs/components/ChildNodeViews.js +376 -0
- package/dist/cjs/components/CursorWrapper.js +91 -0
- package/dist/cjs/components/CustomNodeView.js +79 -0
- package/dist/cjs/components/DocNodeView.js +104 -0
- package/dist/cjs/components/LayoutGroup.js +111 -0
- package/dist/cjs/components/MarkView.js +115 -0
- package/dist/cjs/components/NativeWidgetView.js +109 -0
- package/dist/cjs/components/NodeView.js +196 -0
- package/dist/cjs/components/NodeViewComponentProps.js +4 -0
- package/dist/cjs/components/OutputSpec.js +88 -0
- package/dist/cjs/components/ProseMirror.js +103 -0
- package/dist/cjs/components/ProseMirrorDoc.js +92 -0
- package/dist/cjs/components/SeparatorHackView.js +100 -0
- package/dist/cjs/components/TextNodeView.js +112 -0
- package/dist/cjs/components/TrailingHackView.js +90 -0
- package/dist/cjs/components/WidgetView.js +95 -0
- package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
- package/dist/cjs/components/__tests__/ProseMirror.composition.test.js +398 -0
- package/dist/cjs/components/__tests__/ProseMirror.domchange.test.js +270 -0
- package/dist/cjs/components/__tests__/ProseMirror.draw-decoration.test.js +1010 -0
- package/dist/cjs/components/__tests__/ProseMirror.draw.test.js +337 -0
- package/dist/cjs/components/__tests__/ProseMirror.node-view.test.js +315 -0
- package/dist/cjs/components/__tests__/ProseMirror.selection.test.js +444 -0
- package/dist/cjs/components/__tests__/ProseMirror.test.js +382 -0
- package/dist/cjs/contexts/ChildDescriptorsContext.js +19 -0
- package/dist/cjs/contexts/EditorContext.js +12 -0
- package/dist/cjs/contexts/EditorStateContext.js +12 -0
- package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
- package/dist/cjs/contexts/NodeViewContext.js +12 -0
- package/dist/cjs/contexts/SelectNodeContext.js +12 -0
- package/dist/cjs/contexts/StopEventContext.js +12 -0
- package/dist/cjs/contexts/__tests__/DeferredLayoutEffects.test.js +141 -0
- package/dist/cjs/decorations/ReactWidgetType.js +58 -0
- package/dist/cjs/decorations/computeDocDeco.js +44 -0
- package/dist/cjs/decorations/internalTypes.js +4 -0
- package/dist/cjs/decorations/iterDeco.js +79 -0
- package/dist/cjs/decorations/viewDecorations.js +163 -0
- package/dist/cjs/dom.js +142 -0
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +108 -0
- package/dist/cjs/hooks/useClientOnly.js +18 -0
- package/dist/cjs/hooks/useComponentEventListeners.js +39 -0
- package/dist/cjs/hooks/useEditor.js +287 -0
- package/dist/cjs/hooks/useEditorEffect.js +35 -0
- package/dist/cjs/hooks/useEditorEventCallback.js +33 -0
- package/dist/cjs/hooks/useEditorEventListener.js +34 -0
- package/dist/cjs/hooks/useEditorState.js +16 -0
- package/dist/cjs/hooks/useForceUpdate.js +15 -0
- package/dist/cjs/hooks/useLayoutGroupEffect.js +19 -0
- package/dist/cjs/hooks/useNodeViewDescriptor.js +115 -0
- package/dist/cjs/hooks/useReactKeys.js +17 -0
- package/dist/cjs/hooks/useSelectNode.js +28 -0
- package/dist/cjs/hooks/useStopEvent.js +24 -0
- package/dist/cjs/index.js +53 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/plugins/__tests__/reactKeys.test.js +81 -0
- package/dist/cjs/plugins/beforeInputPlugin.js +143 -0
- package/dist/cjs/plugins/componentEventListeners.js +35 -0
- package/dist/cjs/plugins/componentEventListenersPlugin.js +35 -0
- package/dist/cjs/plugins/reactKeys.js +96 -0
- package/dist/cjs/props.js +269 -0
- package/dist/cjs/selection/SelectionDOMObserver.js +174 -0
- package/dist/cjs/selection/hasFocusAndSelection.js +35 -0
- package/dist/cjs/selection/selectionFromDOM.js +77 -0
- package/dist/cjs/selection/selectionToDOM.js +226 -0
- package/dist/cjs/ssr.js +85 -0
- package/dist/cjs/testing/editorViewTestHelpers.js +111 -0
- package/dist/cjs/testing/setupProseMirrorView.js +94 -0
- package/dist/cjs/viewdesc.js +664 -0
- package/dist/esm/browser.js +43 -0
- package/dist/esm/components/ChildNodeViews.js +318 -0
- package/dist/esm/components/CursorWrapper.js +40 -0
- package/dist/esm/components/CustomNodeView.js +28 -0
- package/dist/esm/components/DocNodeView.js +53 -0
- package/dist/esm/components/LayoutGroup.js +66 -0
- package/dist/esm/components/MarkView.js +64 -0
- package/dist/esm/components/NativeWidgetView.js +58 -0
- package/dist/esm/components/NodeView.js +145 -0
- package/dist/esm/components/NodeViewComponentProps.js +1 -0
- package/dist/esm/components/OutputSpec.js +38 -0
- package/dist/esm/components/ProseMirror.js +52 -0
- package/dist/esm/components/ProseMirrorDoc.js +34 -0
- package/dist/esm/components/SeparatorHackView.js +49 -0
- package/dist/esm/components/TextNodeView.js +102 -0
- package/dist/esm/components/TrailingHackView.js +39 -0
- package/dist/esm/components/WidgetView.js +44 -0
- package/dist/esm/components/WidgetViewComponentProps.js +1 -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 +967 -0
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +294 -0
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +272 -0
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +440 -0
- package/dist/esm/components/__tests__/ProseMirror.test.js +339 -0
- package/dist/esm/contexts/ChildDescriptorsContext.js +9 -0
- package/dist/esm/contexts/EditorContext.js +7 -0
- package/dist/esm/contexts/EditorStateContext.js +2 -0
- package/dist/esm/contexts/LayoutGroupContext.js +2 -0
- package/dist/esm/contexts/NodeViewContext.js +2 -0
- package/dist/esm/contexts/SelectNodeContext.js +2 -0
- package/dist/esm/contexts/StopEventContext.js +2 -0
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +98 -0
- package/dist/esm/decorations/ReactWidgetType.js +40 -0
- package/dist/esm/decorations/computeDocDeco.js +44 -0
- package/dist/esm/decorations/internalTypes.js +1 -0
- package/dist/esm/decorations/iterDeco.js +73 -0
- package/dist/esm/decorations/viewDecorations.js +163 -0
- package/dist/esm/dom.js +105 -0
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +99 -0
- package/dist/esm/hooks/useClientOnly.js +8 -0
- package/dist/esm/hooks/useComponentEventListeners.js +54 -0
- package/dist/esm/hooks/useEditor.js +278 -0
- package/dist/esm/hooks/useEditorEffect.js +38 -0
- package/dist/esm/hooks/useEditorEventCallback.js +35 -0
- package/dist/esm/hooks/useEditorEventListener.js +28 -0
- package/dist/esm/hooks/useEditorState.js +8 -0
- package/dist/esm/hooks/useForceUpdate.js +8 -0
- package/dist/esm/hooks/useLayoutGroupEffect.js +9 -0
- package/dist/esm/hooks/useNodeViewDescriptor.js +105 -0
- package/dist/esm/hooks/useReactKeys.js +7 -0
- package/dist/esm/hooks/useSelectNode.js +18 -0
- package/dist/esm/hooks/useStopEvent.js +14 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/plugins/__tests__/reactKeys.test.js +77 -0
- package/dist/esm/plugins/beforeInputPlugin.js +133 -0
- package/dist/esm/plugins/componentEventListeners.js +25 -0
- package/dist/esm/plugins/componentEventListenersPlugin.js +25 -0
- package/dist/esm/plugins/reactKeys.js +81 -0
- package/dist/esm/props.js +251 -0
- package/dist/esm/selection/SelectionDOMObserver.js +164 -0
- package/dist/esm/selection/hasFocusAndSelection.js +17 -0
- package/dist/esm/selection/selectionFromDOM.js +59 -0
- package/dist/esm/selection/selectionToDOM.js +196 -0
- package/dist/esm/ssr.js +82 -0
- package/dist/esm/testing/editorViewTestHelpers.js +88 -0
- package/dist/esm/testing/setupProseMirrorView.js +76 -0
- package/dist/esm/viewdesc.js +654 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/browser.d.ts +15 -0
- package/dist/types/components/ChildNodeViews.d.ts +9 -0
- package/dist/types/components/CursorWrapper.d.ts +5 -0
- package/dist/types/components/CustomNodeView.d.ts +21 -0
- package/dist/types/components/DocNodeView.d.ts +20 -0
- package/dist/types/components/LayoutGroup.d.ts +12 -0
- package/dist/types/components/MarkView.d.ts +9 -0
- package/dist/types/components/NativeWidgetView.d.ts +8 -0
- package/dist/types/components/NodeView.d.ts +11 -0
- package/dist/types/components/NodeViewComponentProps.d.ts +12 -0
- package/dist/types/components/OutputSpec.d.ts +8 -0
- package/dist/types/components/ProseMirror.d.ts +15 -0
- package/dist/types/components/ProseMirrorDoc.d.ts +10 -0
- package/dist/types/components/SeparatorHackView.d.ts +6 -0
- package/dist/types/components/TextNodeView.d.ts +23 -0
- package/dist/types/components/TrailingHackView.d.ts +6 -0
- package/dist/types/components/WidgetView.d.ts +8 -0
- package/dist/types/components/WidgetViewComponentProps.d.ts +6 -0
- package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
- package/dist/types/contexts/ChildDescriptorsContext.d.ts +6 -0
- package/dist/types/contexts/EditorContext.d.ts +14 -0
- package/dist/types/contexts/EditorStateContext.d.ts +2 -0
- package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
- package/dist/types/contexts/NodeViewContext.d.ts +6 -0
- package/dist/types/contexts/SelectNodeContext.d.ts +3 -0
- package/dist/types/contexts/StopEventContext.d.ts +3 -0
- package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
- package/dist/types/decorations/ReactWidgetType.d.ts +39 -0
- package/dist/types/decorations/computeDocDeco.d.ts +13 -0
- package/dist/types/decorations/internalTypes.d.ts +16 -0
- package/dist/types/decorations/iterDeco.d.ts +3 -0
- package/dist/types/decorations/viewDecorations.d.ts +13 -0
- package/dist/types/dom.d.ts +22 -0
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +1 -0
- package/dist/types/hooks/useClientOnly.d.ts +1 -0
- package/dist/types/hooks/useComponentEventListeners.d.ts +33 -0
- package/dist/types/hooks/useEditor.d.ts +66 -0
- package/dist/types/hooks/useEditorEffect.d.ts +17 -0
- package/dist/types/hooks/useEditorEventCallback.d.ts +15 -0
- package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
- package/dist/types/hooks/useEditorState.d.ts +5 -0
- package/dist/types/hooks/useForceUpdate.d.ts +5 -0
- package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +11 -0
- package/dist/types/hooks/useReactKeys.d.ts +5 -0
- package/dist/types/hooks/useSelectNode.d.ts +1 -0
- package/dist/types/hooks/useStopEvent.d.ts +2 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
- package/dist/types/plugins/beforeInputPlugin.d.ts +3 -0
- package/dist/types/plugins/componentEventListeners.d.ts +4 -0
- package/dist/types/plugins/componentEventListenersPlugin.d.ts +4 -0
- package/dist/types/plugins/reactKeys.d.ts +19 -0
- package/dist/types/props.d.ts +1174 -0
- package/dist/types/selection/SelectionDOMObserver.d.ts +34 -0
- package/dist/types/selection/hasFocusAndSelection.d.ts +3 -0
- package/dist/types/selection/selectionFromDOM.d.ts +4 -0
- package/dist/types/selection/selectionToDOM.d.ts +9 -0
- package/dist/types/ssr.d.ts +19 -0
- package/dist/types/testing/editorViewTestHelpers.d.ts +23 -0
- package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
- package/dist/types/viewdesc.d.ts +131 -0
- package/package.json +113 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = require("@testing-library/react");
|
|
6
|
+
const _prosemirrorModel = require("prosemirror-model");
|
|
7
|
+
const _prosemirrorState = require("prosemirror-state");
|
|
8
|
+
const _prosemirrorTestBuilder = require("prosemirror-test-builder");
|
|
9
|
+
const _react1 = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
10
|
+
const _useEditorEffectJs = require("../../hooks/useEditorEffect.js");
|
|
11
|
+
const _useStopEventJs = require("../../hooks/useStopEvent.js");
|
|
12
|
+
const _reactKeysJs = require("../../plugins/reactKeys.js");
|
|
13
|
+
const _editorViewTestHelpersJs = require("../../testing/editorViewTestHelpers.js");
|
|
14
|
+
const _proseMirrorJs = require("../ProseMirror.js");
|
|
15
|
+
const _proseMirrorDocJs = require("../ProseMirrorDoc.js");
|
|
16
|
+
function _extends() {
|
|
17
|
+
_extends = Object.assign || function(target) {
|
|
18
|
+
for(var i = 1; i < arguments.length; i++){
|
|
19
|
+
var source = arguments[i];
|
|
20
|
+
for(var key in source){
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
22
|
+
target[key] = source[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
return _extends.apply(this, arguments);
|
|
29
|
+
}
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
31
|
+
if (typeof WeakMap !== "function") return null;
|
|
32
|
+
var cacheBabelInterop = new WeakMap();
|
|
33
|
+
var cacheNodeInterop = new WeakMap();
|
|
34
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
35
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
36
|
+
})(nodeInterop);
|
|
37
|
+
}
|
|
38
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
39
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
43
|
+
return {
|
|
44
|
+
default: obj
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
48
|
+
if (cache && cache.has(obj)) {
|
|
49
|
+
return cache.get(obj);
|
|
50
|
+
}
|
|
51
|
+
var newObj = {};
|
|
52
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
53
|
+
for(var key in obj){
|
|
54
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
55
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
56
|
+
if (desc && (desc.get || desc.set)) {
|
|
57
|
+
Object.defineProperty(newObj, key, desc);
|
|
58
|
+
} else {
|
|
59
|
+
newObj[key] = obj[key];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
newObj.default = obj;
|
|
64
|
+
if (cache) {
|
|
65
|
+
cache.set(obj, newObj);
|
|
66
|
+
}
|
|
67
|
+
return newObj;
|
|
68
|
+
}
|
|
69
|
+
describe("ProseMirror", ()=>{
|
|
70
|
+
it("renders a contenteditable", async ()=>{
|
|
71
|
+
const schema = new _prosemirrorModel.Schema({
|
|
72
|
+
nodes: {
|
|
73
|
+
text: {},
|
|
74
|
+
doc: {
|
|
75
|
+
content: "text*"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const editorState = _prosemirrorState.EditorState.create({
|
|
80
|
+
schema
|
|
81
|
+
});
|
|
82
|
+
function TestEditor() {
|
|
83
|
+
return /*#__PURE__*/ _react1.default.createElement(_proseMirrorJs.ProseMirror, {
|
|
84
|
+
defaultState: editorState
|
|
85
|
+
}, /*#__PURE__*/ _react1.default.createElement(_proseMirrorDocJs.ProseMirrorDoc, {
|
|
86
|
+
"data-testid": "editor"
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
(0, _react.render)(/*#__PURE__*/ _react1.default.createElement(TestEditor, null));
|
|
90
|
+
const editor = _react.screen.getByTestId("editor");
|
|
91
|
+
editor.focus();
|
|
92
|
+
await browser.keys("H");
|
|
93
|
+
await browser.keys("e");
|
|
94
|
+
await browser.keys("l");
|
|
95
|
+
await browser.keys("l");
|
|
96
|
+
await browser.keys("o");
|
|
97
|
+
await browser.keys(",");
|
|
98
|
+
await browser.keys(" ");
|
|
99
|
+
await browser.keys("w");
|
|
100
|
+
await browser.keys("o");
|
|
101
|
+
await browser.keys("r");
|
|
102
|
+
await browser.keys("l");
|
|
103
|
+
await browser.keys("d");
|
|
104
|
+
await browser.keys("!");
|
|
105
|
+
expect(editor.textContent).toBe("Hello, world!");
|
|
106
|
+
});
|
|
107
|
+
it("supports lifted editor state", async ()=>{
|
|
108
|
+
const schema = new _prosemirrorModel.Schema({
|
|
109
|
+
nodes: {
|
|
110
|
+
text: {},
|
|
111
|
+
doc: {
|
|
112
|
+
content: "text*"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
let outerEditorState = _prosemirrorState.EditorState.create({
|
|
117
|
+
schema
|
|
118
|
+
});
|
|
119
|
+
function TestEditor() {
|
|
120
|
+
const [editorState, setEditorState] = (0, _react1.useState)(outerEditorState);
|
|
121
|
+
(0, _react1.useEffect)(()=>{
|
|
122
|
+
outerEditorState = editorState;
|
|
123
|
+
}, [
|
|
124
|
+
editorState
|
|
125
|
+
]);
|
|
126
|
+
return /*#__PURE__*/ _react1.default.createElement(_proseMirrorJs.ProseMirror, {
|
|
127
|
+
state: editorState,
|
|
128
|
+
dispatchTransaction: (tr)=>setEditorState(editorState.apply(tr))
|
|
129
|
+
}, /*#__PURE__*/ _react1.default.createElement(_proseMirrorDocJs.ProseMirrorDoc, {
|
|
130
|
+
"data-testid": "editor"
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
(0, _react.render)(/*#__PURE__*/ _react1.default.createElement(TestEditor, null));
|
|
134
|
+
const editor = _react.screen.getByTestId("editor");
|
|
135
|
+
editor.focus();
|
|
136
|
+
await browser.keys("H");
|
|
137
|
+
await browser.keys("e");
|
|
138
|
+
await browser.keys("l");
|
|
139
|
+
await browser.keys("l");
|
|
140
|
+
await browser.keys("o");
|
|
141
|
+
await browser.keys(",");
|
|
142
|
+
await browser.keys(" ");
|
|
143
|
+
await browser.keys("w");
|
|
144
|
+
await browser.keys("o");
|
|
145
|
+
await browser.keys("r");
|
|
146
|
+
await browser.keys("l");
|
|
147
|
+
await browser.keys("d");
|
|
148
|
+
await browser.keys("!");
|
|
149
|
+
expect(outerEditorState.doc.textContent).toBe("Hello, world!");
|
|
150
|
+
});
|
|
151
|
+
it("supports React NodeViews", async ()=>{
|
|
152
|
+
const schema = new _prosemirrorModel.Schema({
|
|
153
|
+
nodes: {
|
|
154
|
+
text: {},
|
|
155
|
+
paragraph: {
|
|
156
|
+
content: "text*",
|
|
157
|
+
toDOM () {
|
|
158
|
+
return [
|
|
159
|
+
"p",
|
|
160
|
+
0
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
doc: {
|
|
165
|
+
content: "paragraph+"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const editorState = _prosemirrorState.EditorState.create({
|
|
170
|
+
schema
|
|
171
|
+
});
|
|
172
|
+
const Paragraph = /*#__PURE__*/ (0, _react1.forwardRef)(function Paragraph(param, ref) {
|
|
173
|
+
let { children } = param;
|
|
174
|
+
return /*#__PURE__*/ _react1.default.createElement("p", {
|
|
175
|
+
ref: ref,
|
|
176
|
+
"data-testid": "paragraph"
|
|
177
|
+
}, children);
|
|
178
|
+
});
|
|
179
|
+
const reactNodeViews = {
|
|
180
|
+
paragraph: Paragraph
|
|
181
|
+
};
|
|
182
|
+
function TestEditor() {
|
|
183
|
+
return /*#__PURE__*/ _react1.default.createElement(_proseMirrorJs.ProseMirror, {
|
|
184
|
+
defaultState: editorState,
|
|
185
|
+
nodeViews: reactNodeViews
|
|
186
|
+
}, /*#__PURE__*/ _react1.default.createElement(_proseMirrorDocJs.ProseMirrorDoc, {
|
|
187
|
+
"data-testid": "editor"
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
(0, _react.render)(/*#__PURE__*/ _react1.default.createElement(TestEditor, null));
|
|
191
|
+
const editor = _react.screen.getByTestId("editor");
|
|
192
|
+
editor.focus();
|
|
193
|
+
await browser.keys("H");
|
|
194
|
+
await browser.keys("e");
|
|
195
|
+
await browser.keys("l");
|
|
196
|
+
await browser.keys("l");
|
|
197
|
+
await browser.keys("o");
|
|
198
|
+
await browser.keys(",");
|
|
199
|
+
await browser.keys(" ");
|
|
200
|
+
await browser.keys("w");
|
|
201
|
+
await browser.keys("o");
|
|
202
|
+
await browser.keys("r");
|
|
203
|
+
await browser.keys("l");
|
|
204
|
+
await browser.keys("d");
|
|
205
|
+
await browser.keys("!");
|
|
206
|
+
expect(editor.textContent).toBe("Hello, world!");
|
|
207
|
+
// Ensure that ProseMirror really rendered our Paragraph
|
|
208
|
+
// component, not just any old <p> tag
|
|
209
|
+
expect(_react.screen.getAllByTestId("paragraph").length).toBeGreaterThanOrEqual(1);
|
|
210
|
+
});
|
|
211
|
+
it("reflects the current state in .props", async ()=>{
|
|
212
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
213
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)())
|
|
214
|
+
});
|
|
215
|
+
expect(view.state).toBe(view.props.state);
|
|
216
|
+
});
|
|
217
|
+
it("calls handleScrollToSelection when appropriate", async ()=>{
|
|
218
|
+
let scrolled = 0;
|
|
219
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
220
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)()),
|
|
221
|
+
handleScrollToSelection: ()=>{
|
|
222
|
+
scrolled++;
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
view.dispatch(view.state.tr.scrollIntoView());
|
|
227
|
+
expect(scrolled).toBe(1);
|
|
228
|
+
});
|
|
229
|
+
it("can be queried for the DOM position at a doc position", async ()=>{
|
|
230
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
231
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.ul)((0, _prosemirrorTestBuilder.li)((0, _prosemirrorTestBuilder.p)((0, _prosemirrorTestBuilder.strong)("foo")))))
|
|
232
|
+
});
|
|
233
|
+
const inText = view.domAtPos(4);
|
|
234
|
+
expect(inText.offset).toBe(1);
|
|
235
|
+
expect(inText.node.nodeValue).toBe("foo");
|
|
236
|
+
const beforeLI = view.domAtPos(1);
|
|
237
|
+
expect(beforeLI.offset).toBe(0);
|
|
238
|
+
expect(beforeLI.node.nodeName).toBe("UL");
|
|
239
|
+
const afterP = view.domAtPos(7);
|
|
240
|
+
expect(afterP.offset).toBe(1);
|
|
241
|
+
expect(afterP.node.nodeName).toBe("LI");
|
|
242
|
+
});
|
|
243
|
+
it("can bias DOM position queries to enter nodes", async ()=>{
|
|
244
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
245
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)((0, _prosemirrorTestBuilder.em)((0, _prosemirrorTestBuilder.strong)("a"), "b"), "c"))
|
|
246
|
+
});
|
|
247
|
+
function get(pos, bias) {
|
|
248
|
+
const r = view.domAtPos(pos, bias);
|
|
249
|
+
return (r.node.nodeType == 1 ? r.node.nodeName : r.node.nodeValue) + "@" + r.offset;
|
|
250
|
+
}
|
|
251
|
+
expect(get(1, 0)).toBe("P@0");
|
|
252
|
+
expect(get(1, -1)).toBe("P@0");
|
|
253
|
+
expect(get(1, 1)).toBe("a@0");
|
|
254
|
+
expect(get(2, -1)).toBe("a@1");
|
|
255
|
+
expect(get(2, 0)).toBe("EM@1");
|
|
256
|
+
expect(get(2, 1)).toBe("b@0");
|
|
257
|
+
expect(get(3, -1)).toBe("b@1");
|
|
258
|
+
expect(get(3, 0)).toBe("P@1");
|
|
259
|
+
expect(get(3, 1)).toBe("c@0");
|
|
260
|
+
expect(get(4, -1)).toBe("c@1");
|
|
261
|
+
expect(get(4, 0)).toBe("P@2");
|
|
262
|
+
expect(get(4, 1)).toBe("P@2");
|
|
263
|
+
});
|
|
264
|
+
it("can be queried for a node's DOM representation", async ()=>{
|
|
265
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
266
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)("foo"), (0, _prosemirrorTestBuilder.hr)())
|
|
267
|
+
});
|
|
268
|
+
expect(view.nodeDOM(0).nodeName).toBe("P");
|
|
269
|
+
expect(view.nodeDOM(5).nodeName).toBe("HR");
|
|
270
|
+
expect(view.nodeDOM(3)).toBeNull();
|
|
271
|
+
});
|
|
272
|
+
it("can map DOM positions to doc positions", async ()=>{
|
|
273
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
274
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)("foo"), (0, _prosemirrorTestBuilder.hr)())
|
|
275
|
+
});
|
|
276
|
+
expect(view.posAtDOM(view.dom.firstChild.firstChild, 2)).toBe(3);
|
|
277
|
+
expect(view.posAtDOM(view.dom, 1)).toBe(5);
|
|
278
|
+
expect(view.posAtDOM(view.dom, 2)).toBe(6);
|
|
279
|
+
expect(view.posAtDOM(view.dom.lastChild, 0, -1)).toBe(5);
|
|
280
|
+
expect(view.posAtDOM(view.dom.lastChild, 0, 1)).toBe(6);
|
|
281
|
+
});
|
|
282
|
+
it("binds this to itself in dispatchTransaction prop", async ()=>{
|
|
283
|
+
let thisBinding;
|
|
284
|
+
const { view } = (0, _editorViewTestHelpersJs.tempEditor)({
|
|
285
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)("foo"), (0, _prosemirrorTestBuilder.hr)()),
|
|
286
|
+
dispatchTransaction () {
|
|
287
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
288
|
+
thisBinding = this;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
view.dispatch(view.state.tr.insertText("x"));
|
|
292
|
+
expect(view).toBe(thisBinding);
|
|
293
|
+
});
|
|
294
|
+
it("replaces the EditorView when ProseMirror would redraw", async ()=>{
|
|
295
|
+
const viewPlugin = ()=>new _prosemirrorState.Plugin({
|
|
296
|
+
props: {
|
|
297
|
+
nodeViews: {
|
|
298
|
+
horizontal_rule () {
|
|
299
|
+
const dom = document.createElement("hr");
|
|
300
|
+
return {
|
|
301
|
+
dom
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
const startDoc = (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.p)());
|
|
308
|
+
const firstState = _prosemirrorState.EditorState.create({
|
|
309
|
+
doc: startDoc,
|
|
310
|
+
schema: _prosemirrorTestBuilder.schema,
|
|
311
|
+
plugins: [
|
|
312
|
+
viewPlugin(),
|
|
313
|
+
(0, _reactKeysJs.reactKeys)()
|
|
314
|
+
]
|
|
315
|
+
});
|
|
316
|
+
let firstView = null;
|
|
317
|
+
let secondView = null;
|
|
318
|
+
function Test() {
|
|
319
|
+
(0, _useEditorEffectJs.useEditorEffect)((v)=>{
|
|
320
|
+
if (firstView === null) {
|
|
321
|
+
firstView = v;
|
|
322
|
+
} else {
|
|
323
|
+
secondView = v;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
const Paragraph = /*#__PURE__*/ (0, _react1.forwardRef)(function Paragraph(param, ref) {
|
|
329
|
+
let { nodeProps , children , ...props } = param;
|
|
330
|
+
return /*#__PURE__*/ _react1.default.createElement("p", _extends({
|
|
331
|
+
ref: ref,
|
|
332
|
+
"data-testid": "node-view"
|
|
333
|
+
}, props), children);
|
|
334
|
+
});
|
|
335
|
+
const { rerender } = (0, _react.render)(/*#__PURE__*/ _react1.default.createElement(_proseMirrorJs.ProseMirror, {
|
|
336
|
+
state: firstState,
|
|
337
|
+
nodeViews: {
|
|
338
|
+
paragraph: Paragraph
|
|
339
|
+
}
|
|
340
|
+
}, /*#__PURE__*/ _react1.default.createElement(Test, null), /*#__PURE__*/ _react1.default.createElement(_proseMirrorDocJs.ProseMirrorDoc, null)));
|
|
341
|
+
expect(()=>_react.screen.getByTestId("node-view")).not.toThrow();
|
|
342
|
+
const secondState = _prosemirrorState.EditorState.create({
|
|
343
|
+
doc: startDoc,
|
|
344
|
+
schema: _prosemirrorTestBuilder.schema,
|
|
345
|
+
plugins: [
|
|
346
|
+
viewPlugin(),
|
|
347
|
+
(0, _reactKeysJs.reactKeys)()
|
|
348
|
+
]
|
|
349
|
+
});
|
|
350
|
+
rerender(/*#__PURE__*/ _react1.default.createElement(_proseMirrorJs.ProseMirror, {
|
|
351
|
+
state: secondState,
|
|
352
|
+
nodeViews: {
|
|
353
|
+
paragraph: Paragraph
|
|
354
|
+
}
|
|
355
|
+
}, /*#__PURE__*/ _react1.default.createElement(Test, null), /*#__PURE__*/ _react1.default.createElement(_proseMirrorDocJs.ProseMirrorDoc, null)));
|
|
356
|
+
expect(()=>_react.screen.getByTestId("node-view")).not.toThrow();
|
|
357
|
+
expect(firstView).not.toBeNull();
|
|
358
|
+
expect(secondView).not.toBeNull();
|
|
359
|
+
expect(firstView === secondView).toBeFalsy();
|
|
360
|
+
});
|
|
361
|
+
it("supports focusing interactive controls", async ()=>{
|
|
362
|
+
(0, _editorViewTestHelpersJs.tempEditor)({
|
|
363
|
+
doc: (0, _prosemirrorTestBuilder.doc)((0, _prosemirrorTestBuilder.hr)()),
|
|
364
|
+
nodeViews: {
|
|
365
|
+
horizontal_rule: /*#__PURE__*/ (0, _react1.forwardRef)(function Button(param, ref) {
|
|
366
|
+
let { nodeProps , ...props } = param;
|
|
367
|
+
(0, _useStopEventJs.useStopEvent)(()=>{
|
|
368
|
+
return true;
|
|
369
|
+
});
|
|
370
|
+
return /*#__PURE__*/ _react1.default.createElement("button", _extends({
|
|
371
|
+
id: "button",
|
|
372
|
+
ref: ref,
|
|
373
|
+
type: "button"
|
|
374
|
+
}, props), "Click me");
|
|
375
|
+
})
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
const button = _react.screen.getByText("Click me");
|
|
379
|
+
await $("#button").click();
|
|
380
|
+
expect(document.activeElement === button).toBeTruthy();
|
|
381
|
+
});
|
|
382
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ChildDescriptorsContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ChildDescriptorsContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const ChildDescriptorsContext = (0, _react.createContext)({
|
|
13
|
+
parentRef: {
|
|
14
|
+
current: undefined
|
|
15
|
+
},
|
|
16
|
+
siblingsRef: {
|
|
17
|
+
current: []
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EditorContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return EditorContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const EditorContext = (0, _react.createContext)(null);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EditorStateContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return EditorStateContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const EditorStateContext = (0, _react.createContext)(null);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LayoutGroupContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LayoutGroupContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const LayoutGroupContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "NodeViewContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return NodeViewContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const NodeViewContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SelectNodeContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SelectNodeContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const SelectNodeContext = (0, _react.createContext)(null);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "StopEventContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return StopEventContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const StopEventContext = (0, _react.createContext)(null);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = require("@testing-library/react");
|
|
6
|
+
const _react1 = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
7
|
+
const _layoutGroupJs = require("../../components/LayoutGroup.js");
|
|
8
|
+
const _useLayoutGroupEffectJs = require("../../hooks/useLayoutGroupEffect.js");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
10
|
+
if (typeof WeakMap !== "function") return null;
|
|
11
|
+
var cacheBabelInterop = new WeakMap();
|
|
12
|
+
var cacheNodeInterop = new WeakMap();
|
|
13
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
14
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
15
|
+
})(nodeInterop);
|
|
16
|
+
}
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
18
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
22
|
+
return {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
27
|
+
if (cache && cache.has(obj)) {
|
|
28
|
+
return cache.get(obj);
|
|
29
|
+
}
|
|
30
|
+
var newObj = {};
|
|
31
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
32
|
+
for(var key in obj){
|
|
33
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
34
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
35
|
+
if (desc && (desc.get || desc.set)) {
|
|
36
|
+
Object.defineProperty(newObj, key, desc);
|
|
37
|
+
} else {
|
|
38
|
+
newObj[key] = obj[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
newObj.default = obj;
|
|
43
|
+
if (cache) {
|
|
44
|
+
cache.set(obj, newObj);
|
|
45
|
+
}
|
|
46
|
+
return newObj;
|
|
47
|
+
}
|
|
48
|
+
describe("DeferredLayoutEffects", ()=>{
|
|
49
|
+
jest.useFakeTimers("modern");
|
|
50
|
+
it("registers multiple effects and runs them", ()=>{
|
|
51
|
+
function Parent() {
|
|
52
|
+
return /*#__PURE__*/ _react1.default.createElement(_layoutGroupJs.LayoutGroup, null, /*#__PURE__*/ _react1.default.createElement(Child, null));
|
|
53
|
+
}
|
|
54
|
+
function Child() {
|
|
55
|
+
const [double, setDouble] = (0, _react1.useState)(1);
|
|
56
|
+
(0, _react1.useLayoutEffect)(()=>{
|
|
57
|
+
if (double === 2) {
|
|
58
|
+
setTimeout(()=>{
|
|
59
|
+
setDouble((d)=>d * 2.5);
|
|
60
|
+
}, 500);
|
|
61
|
+
}
|
|
62
|
+
if (double === 20) {
|
|
63
|
+
setDouble((d)=>d * 2.5);
|
|
64
|
+
}
|
|
65
|
+
}, [
|
|
66
|
+
double
|
|
67
|
+
]);
|
|
68
|
+
(0, _useLayoutGroupEffectJs.useLayoutGroupEffect)(()=>{
|
|
69
|
+
const timeout = setTimeout(()=>{
|
|
70
|
+
setDouble((d)=>d * 2);
|
|
71
|
+
}, 1000);
|
|
72
|
+
return ()=>{
|
|
73
|
+
clearTimeout(timeout);
|
|
74
|
+
};
|
|
75
|
+
}, [
|
|
76
|
+
double
|
|
77
|
+
]);
|
|
78
|
+
return /*#__PURE__*/ _react1.default.createElement("div", null, /*#__PURE__*/ _react1.default.createElement("div", {
|
|
79
|
+
"data-testid": "double"
|
|
80
|
+
}, double));
|
|
81
|
+
}
|
|
82
|
+
// The component mounts ...
|
|
83
|
+
// ... the initial value should be 1
|
|
84
|
+
// ... there should be one timeout scheduled by the deferred effect
|
|
85
|
+
(0, _react.render)(/*#__PURE__*/ _react1.default.createElement(Parent, null));
|
|
86
|
+
expect(_react.screen.getByTestId("double").innerHTML).toBe("1");
|
|
87
|
+
// This block assert that deferred effects run.
|
|
88
|
+
// --------------------------------------------
|
|
89
|
+
// 1000 milliseconds go by ...
|
|
90
|
+
// ... the timeout set by the deferred effect should run
|
|
91
|
+
// ... the timeout should double the new value to 2
|
|
92
|
+
// ... the immediate effect should set a timeout
|
|
93
|
+
// ... the deferred effect should set a timeout
|
|
94
|
+
(0, _react.act)(()=>{
|
|
95
|
+
jest.advanceTimersByTime(1000);
|
|
96
|
+
});
|
|
97
|
+
expect(_react.screen.getByTestId("double").innerHTML).toBe("2");
|
|
98
|
+
// The next three blocks assert that cleanup of deferred effects run.
|
|
99
|
+
// ------------------------------------------------------------------
|
|
100
|
+
// 500 milliseconds go by ...
|
|
101
|
+
// ... the timeout set by the immediate effect should run
|
|
102
|
+
// ... the timeout should set the value to 5
|
|
103
|
+
// ... the old deferred effect should cancel its timeout
|
|
104
|
+
// ... the new deferred effect should set a new timeout
|
|
105
|
+
(0, _react.act)(()=>{
|
|
106
|
+
jest.advanceTimersByTime(500);
|
|
107
|
+
});
|
|
108
|
+
expect(_react.screen.getByTestId("double").innerHTML).toBe("5");
|
|
109
|
+
// ... 500 more milliseconds go by ...
|
|
110
|
+
// ... the canceled timeout should not run
|
|
111
|
+
// ... the rescheduled timoeut should not yet run
|
|
112
|
+
(0, _react.act)(()=>{
|
|
113
|
+
jest.advanceTimersByTime(500);
|
|
114
|
+
});
|
|
115
|
+
expect(_react.screen.getByTestId("double").innerHTML).toBe("5");
|
|
116
|
+
// ... 500 more milliseconds go by ...
|
|
117
|
+
// ... the rescheduled timeout should run
|
|
118
|
+
// ... the timeout should double the value to 10
|
|
119
|
+
// ... the deferred effect should set a new timeout
|
|
120
|
+
(0, _react.act)(()=>{
|
|
121
|
+
jest.advanceTimersByTime(500);
|
|
122
|
+
});
|
|
123
|
+
expect(_react.screen.getByTestId("double").innerHTML).toBe("10");
|
|
124
|
+
// The next block asserts that cancelation of deferred effects works.
|
|
125
|
+
// ------------------------------------------------------------------
|
|
126
|
+
// 1000 milliseconds go by ...
|
|
127
|
+
// ... the timeout set by the deferred effect should run
|
|
128
|
+
// ... the timeout should double the value to 20
|
|
129
|
+
// ... the immediate effect should then set the value to 50
|
|
130
|
+
// ... the deferred effect from the first render should not run
|
|
131
|
+
// ... the deferred effect from the second render should run
|
|
132
|
+
// ... the deferred effect that does run should set a new timeout
|
|
133
|
+
(0, _react.act)(()=>{
|
|
134
|
+
jest.advanceTimersByTime(1000);
|
|
135
|
+
});
|
|
136
|
+
// For this assertion, we need to clear a timer from the React scheduler.
|
|
137
|
+
jest.advanceTimersByTime(1);
|
|
138
|
+
expect(_react.screen.getByTestId("double").innerHTML).toBe("50");
|
|
139
|
+
expect(jest.getTimerCount()).toBe(1);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
ReactWidgetType: function() {
|
|
13
|
+
return ReactWidgetType;
|
|
14
|
+
},
|
|
15
|
+
widget: function() {
|
|
16
|
+
return widget;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _prosemirrorview = require("prosemirror-view");
|
|
20
|
+
function compareObjs(a, b) {
|
|
21
|
+
if (a == b) return true;
|
|
22
|
+
for(const p in a)if (a[p] !== b[p]) return false;
|
|
23
|
+
for(const p in b)if (!(p in a)) return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const noSpec = {
|
|
27
|
+
side: 0
|
|
28
|
+
};
|
|
29
|
+
let ReactWidgetType = class ReactWidgetType {
|
|
30
|
+
Component;
|
|
31
|
+
side;
|
|
32
|
+
spec;
|
|
33
|
+
constructor(Component, spec){
|
|
34
|
+
this.Component = Component;
|
|
35
|
+
this.spec = spec ?? noSpec;
|
|
36
|
+
this.side = this.spec.side ?? 0;
|
|
37
|
+
}
|
|
38
|
+
map(mapping, span, offset, oldOffset) {
|
|
39
|
+
const { pos, deleted } = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1);
|
|
40
|
+
// @ts-expect-error The Decoration constructor is private/internal, but
|
|
41
|
+
// we need to use it for our custom widget implementation here.
|
|
42
|
+
return deleted ? null : new _prosemirrorview.Decoration(pos - offset, pos - offset, this);
|
|
43
|
+
}
|
|
44
|
+
valid() {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
eq(other) {
|
|
48
|
+
return this == other || other instanceof ReactWidgetType && (this.spec.key && this.spec.key == other.spec.key || this.Component == other.Component && compareObjs(this.spec, other.spec));
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
// Can be implemented with React effect hooks
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function widget(pos, component, spec) {
|
|
55
|
+
// @ts-expect-error The Decoration constructor is private/internal, but
|
|
56
|
+
// we need to use it for our custom widget implementation here.
|
|
57
|
+
return new _prosemirrorview.Decoration(pos, pos, new ReactWidgetType(component, spec));
|
|
58
|
+
}
|