@handlewithcare/react-prosemirror 2.8.0-tiptap.10 → 2.8.0-tiptap.12
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/cjs/tiptap/TiptapEditorView.js +2 -1
- package/dist/cjs/tiptap/tiptapNodeView.js +26 -13
- package/dist/esm/tiptap/TiptapEditorView.js +2 -1
- package/dist/esm/tiptap/tiptapNodeView.js +27 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/props.d.ts +26 -26
- package/dist/types/tiptap/TiptapEditorView.d.ts +2 -1
- package/package.json +1 -1
- package/dist/esm/@jest/pattern/src/__tests__/TestPathPatterns.test.js +0 -241
- package/dist/esm/@swc/cli/lib/swc/__tests__/compile.test.js +0 -19
- package/dist/esm/@swc/cli/lib/swc/__tests__/options.test.js +0 -315
- package/dist/esm/@swc/cli/lib/swc/__tests__/sources.test.js +0 -161
- package/dist/esm/@uiw/react-codemirror/src/__tests__/index.test.js +0 -111
- package/dist/esm/cheerio/src/__tests__/deprecated.spec.js +0 -249
- package/dist/esm/cheerio/src/__tests__/xml.spec.js +0 -55
- package/dist/esm/components/__tests__/ProseMirror.composition.test.js +0 -395
- package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +0 -266
- package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +0 -968
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +0 -335
- package/dist/esm/components/__tests__/ProseMirror.mobile.test.js +0 -54
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +0 -553
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +0 -440
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -324
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +0 -98
- package/dist/esm/hooks/__tests__/useEditorEffect.test.js +0 -134
- package/dist/esm/jsx-ast-utils/__tests__/helper.js +0 -83
- package/dist/esm/jsx-ast-utils/__tests__/src/elementType-test.js +0 -76
- package/dist/esm/jsx-ast-utils/__tests__/src/eventHandlers-test.js +0 -98
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-parser-test.js +0 -188
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-test.js +0 -119
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-babelparser-test.js +0 -393
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-flowparser-test.js +0 -379
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-babelparser-test.js +0 -925
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-flowparser-test.js +0 -700
- package/dist/esm/jsx-ast-utils/__tests__/src/hasProp-test.js +0 -350
- package/dist/esm/jsx-ast-utils/__tests__/src/index-test.js +0 -24
- package/dist/esm/jsx-ast-utils/__tests__/src/propName-test.js +0 -37
- package/dist/esm/plugins/__tests__/reactKeys.test.js +0 -77
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.js +0 -97
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.js +0 -319
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.js +0 -62
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.js +0 -80
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.js +0 -22
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.js +0 -20
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.js +0 -219
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.js +0 -323
- package/dist/esm/tsconfig-paths/src/__tests__/config-loader.test.js +0 -89
- package/dist/esm/tsconfig-paths/src/__tests__/data/match-path-data.js +0 -314
- package/dist/esm/tsconfig-paths/src/__tests__/filesystem.test.js +0 -58
- package/dist/esm/tsconfig-paths/src/__tests__/mapping-entry.test.js +0 -76
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-async.test.js +0 -12
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-sync.test.js +0 -10
- package/dist/esm/tsconfig-paths/src/__tests__/try-path.test.js +0 -214
- package/dist/esm/tsconfig-paths/src/__tests__/tsconfig-loader.test.js +0 -296
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { screen } from "@testing-library/react";
|
|
2
|
-
import { Plugin } from "prosemirror-state";
|
|
3
|
-
import { blockquote, br, doc, p } from "prosemirror-test-builder";
|
|
4
|
-
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
5
|
-
import React, { forwardRef, useEffect } from "react";
|
|
6
|
-
import { useEditorState } from "../../hooks/useEditorState.js";
|
|
7
|
-
import { useStopEvent } from "../../hooks/useStopEvent.js";
|
|
8
|
-
import { tempEditor } from "../../testing/editorViewTestHelpers.js";
|
|
9
|
-
describe("nodeViews prop", ()=>{
|
|
10
|
-
it("can replace a node's representation", async ()=>{
|
|
11
|
-
const { view } = tempEditor({
|
|
12
|
-
doc: doc(p("foo", br())),
|
|
13
|
-
nodeViews: {
|
|
14
|
-
hard_break: /*#__PURE__*/ forwardRef(function Var(props, ref) {
|
|
15
|
-
return /*#__PURE__*/ React.createElement("var", {
|
|
16
|
-
ref: ref
|
|
17
|
-
}, props.children);
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
expect(view.dom.querySelector("var")).not.toBeNull();
|
|
22
|
-
});
|
|
23
|
-
it("can override drawing of a node's content", async ()=>{
|
|
24
|
-
const { view } = tempEditor({
|
|
25
|
-
doc: doc(p("foo")),
|
|
26
|
-
nodeViews: {
|
|
27
|
-
paragraph: /*#__PURE__*/ forwardRef(function Paragraph(props, ref) {
|
|
28
|
-
return /*#__PURE__*/ React.createElement("p", {
|
|
29
|
-
ref: ref
|
|
30
|
-
}, props.nodeProps.node.textContent.toUpperCase());
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
expect(view.dom.querySelector("p").textContent).toBe("FOO");
|
|
35
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
36
|
-
expect(view.dom.querySelector("p").textContent).toBe("AFOO");
|
|
37
|
-
});
|
|
38
|
-
// React makes this more or less trivial; the render
|
|
39
|
-
// method of the component _is_ the update (and create)
|
|
40
|
-
// method
|
|
41
|
-
// eslint-disable-next-line jest/no-disabled-tests
|
|
42
|
-
it.skip("can register its own update method", async ()=>{
|
|
43
|
-
const { view } = tempEditor({
|
|
44
|
-
doc: doc(p("foo")),
|
|
45
|
-
nodeViews: {
|
|
46
|
-
paragraph: /*#__PURE__*/ forwardRef(function Paragraph(props, ref) {
|
|
47
|
-
return /*#__PURE__*/ React.createElement("p", {
|
|
48
|
-
ref: ref
|
|
49
|
-
}, props.nodeProps.node.textContent.toUpperCase());
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const para = view.dom.querySelector("p");
|
|
54
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
55
|
-
expect(view.dom.querySelector("p")).toBe(para);
|
|
56
|
-
expect(para.textContent).toBe("AFOO");
|
|
57
|
-
});
|
|
58
|
-
it("allows decoration updates for node views with an update method", async ()=>{
|
|
59
|
-
const { view, rerender } = tempEditor({
|
|
60
|
-
doc: doc(p("foo")),
|
|
61
|
-
nodeViews: {
|
|
62
|
-
paragraph: /*#__PURE__*/ forwardRef(function Paragraph(param, ref) {
|
|
63
|
-
let { children, nodeProps, ...props } = param;
|
|
64
|
-
return /*#__PURE__*/ React.createElement("p", {
|
|
65
|
-
...props,
|
|
66
|
-
ref: ref
|
|
67
|
-
}, children);
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
rerender({
|
|
72
|
-
decorations (state) {
|
|
73
|
-
return DecorationSet.create(state.doc, [
|
|
74
|
-
Decoration.inline(2, 3, {
|
|
75
|
-
someattr: "ok"
|
|
76
|
-
}),
|
|
77
|
-
Decoration.node(0, 5, {
|
|
78
|
-
otherattr: "ok"
|
|
79
|
-
})
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
expect(view.dom.querySelector("[someattr]")).not.toBeNull();
|
|
84
|
-
expect(view.dom.querySelector("[otherattr]")).not.toBeNull();
|
|
85
|
-
});
|
|
86
|
-
it("can provide a contentDOM property", async ()=>{
|
|
87
|
-
const { view } = tempEditor({
|
|
88
|
-
doc: doc(p("foo")),
|
|
89
|
-
nodeViews: {
|
|
90
|
-
paragraph: /*#__PURE__*/ forwardRef(function Paragraph(props, ref) {
|
|
91
|
-
return(// ContentDOM is inferred from where props.children is rendered
|
|
92
|
-
/*#__PURE__*/ React.createElement("p", {
|
|
93
|
-
ref: ref
|
|
94
|
-
}, props.children));
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
const para = view.dom.querySelector("p");
|
|
99
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
100
|
-
expect(view.dom.querySelector("p")).toBe(para);
|
|
101
|
-
expect(para.textContent).toBe("afoo");
|
|
102
|
-
});
|
|
103
|
-
it("has its destroy method called", async ()=>{
|
|
104
|
-
let destroyed = 0;
|
|
105
|
-
const { view } = tempEditor({
|
|
106
|
-
doc: doc(p("foo", br())),
|
|
107
|
-
nodeViews: {
|
|
108
|
-
hard_break: /*#__PURE__*/ forwardRef(function BR(_props, ref) {
|
|
109
|
-
// React implements "destroy methods" with effect
|
|
110
|
-
// hooks
|
|
111
|
-
useEffect(()=>{
|
|
112
|
-
return ()=>{
|
|
113
|
-
destroyed++;
|
|
114
|
-
};
|
|
115
|
-
}, []);
|
|
116
|
-
return /*#__PURE__*/ React.createElement("br", {
|
|
117
|
-
ref: ref
|
|
118
|
-
});
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
view.dispatch(view.state.tr.delete(3, 5));
|
|
123
|
-
expect(destroyed).toBe(1);
|
|
124
|
-
});
|
|
125
|
-
it("can query its own position", async ()=>{
|
|
126
|
-
let pos;
|
|
127
|
-
const { view } = tempEditor({
|
|
128
|
-
doc: doc(blockquote(p("abc"), p("foo", br()))),
|
|
129
|
-
nodeViews: {
|
|
130
|
-
hard_break: /*#__PURE__*/ forwardRef(function BR(param, ref) {
|
|
131
|
-
let { nodeProps, children, ...props } = param;
|
|
132
|
-
// trigger a re-render on every update, otherwise we won't
|
|
133
|
-
// re-render when an updated doesn't directly affect us
|
|
134
|
-
useEditorState();
|
|
135
|
-
pos = nodeProps.getPos();
|
|
136
|
-
return /*#__PURE__*/ React.createElement("br", {
|
|
137
|
-
...props,
|
|
138
|
-
ref: ref
|
|
139
|
-
});
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
expect(pos).toBe(10);
|
|
144
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
145
|
-
expect(pos).toBe(11);
|
|
146
|
-
});
|
|
147
|
-
it("has access to outer decorations", async ()=>{
|
|
148
|
-
const plugin = new Plugin({
|
|
149
|
-
state: {
|
|
150
|
-
init () {
|
|
151
|
-
return null;
|
|
152
|
-
},
|
|
153
|
-
apply (tr, prev) {
|
|
154
|
-
return tr.getMeta("setDeco") || prev;
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
props: {
|
|
158
|
-
decorations (state) {
|
|
159
|
-
const deco = this.getState(state);
|
|
160
|
-
return deco && DecorationSet.create(state.doc, [
|
|
161
|
-
Decoration.inline(0, state.doc.content.size, {}, {
|
|
162
|
-
name: deco
|
|
163
|
-
})
|
|
164
|
-
]);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
const { view } = tempEditor({
|
|
169
|
-
doc: doc(p("foo", br())),
|
|
170
|
-
plugins: [
|
|
171
|
-
plugin
|
|
172
|
-
],
|
|
173
|
-
nodeViews: {
|
|
174
|
-
hard_break: /*#__PURE__*/ forwardRef(function Var(props, ref) {
|
|
175
|
-
return /*#__PURE__*/ React.createElement("var", {
|
|
176
|
-
ref: ref
|
|
177
|
-
}, props.nodeProps.decorations.length ? props.nodeProps.decorations[0].spec.name : "[]");
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
expect(view.dom.querySelector("var").textContent).toBe("[]");
|
|
182
|
-
view.dispatch(view.state.tr.setMeta("setDeco", "foo"));
|
|
183
|
-
expect(view.dom.querySelector("var").textContent).toBe("foo");
|
|
184
|
-
view.dispatch(view.state.tr.setMeta("setDeco", "bar"));
|
|
185
|
-
expect(view.dom.querySelector("var").textContent).toBe("bar");
|
|
186
|
-
});
|
|
187
|
-
it("provides access to inner decorations in the constructor", async ()=>{
|
|
188
|
-
tempEditor({
|
|
189
|
-
doc: doc(p("foo")),
|
|
190
|
-
nodeViews: {
|
|
191
|
-
paragraph: /*#__PURE__*/ forwardRef(function Paragraph(props, ref) {
|
|
192
|
-
expect(props.nodeProps.innerDecorations.find().map((d)=>`${d.from}-${d.to}`).join()).toBe("1-2");
|
|
193
|
-
return /*#__PURE__*/ React.createElement("p", {
|
|
194
|
-
ref: ref
|
|
195
|
-
}, props.children);
|
|
196
|
-
})
|
|
197
|
-
},
|
|
198
|
-
decorations (state) {
|
|
199
|
-
return DecorationSet.create(state.doc, [
|
|
200
|
-
Decoration.inline(2, 3, {
|
|
201
|
-
someattr: "ok"
|
|
202
|
-
}),
|
|
203
|
-
Decoration.node(0, 5, {
|
|
204
|
-
otherattr: "ok"
|
|
205
|
-
})
|
|
206
|
-
]);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
it("provides access to inner decorations in the update method", async ()=>{
|
|
211
|
-
let innerDecos = [];
|
|
212
|
-
const { rerender } = tempEditor({
|
|
213
|
-
doc: doc(p("foo")),
|
|
214
|
-
nodeViews: {
|
|
215
|
-
paragraph: /*#__PURE__*/ forwardRef(function Paragraph(props, ref) {
|
|
216
|
-
innerDecos = props.nodeProps.innerDecorations.find().map((d)=>`${d.from}-${d.to}`);
|
|
217
|
-
return /*#__PURE__*/ React.createElement("p", {
|
|
218
|
-
ref: ref
|
|
219
|
-
}, props.children);
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
rerender({
|
|
224
|
-
decorations (state) {
|
|
225
|
-
return DecorationSet.create(state.doc, [
|
|
226
|
-
Decoration.inline(2, 3, {
|
|
227
|
-
someattr: "ok"
|
|
228
|
-
}),
|
|
229
|
-
Decoration.node(0, 5, {
|
|
230
|
-
otherattr: "ok"
|
|
231
|
-
})
|
|
232
|
-
]);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
expect(innerDecos.join()).toBe("1-2");
|
|
236
|
-
});
|
|
237
|
-
it("can provide a stopEvent hook", async ()=>{
|
|
238
|
-
tempEditor({
|
|
239
|
-
doc: doc(p("input value")),
|
|
240
|
-
nodeViews: {
|
|
241
|
-
paragraph: /*#__PURE__*/ forwardRef(function ParagraphInput(param, ref) {
|
|
242
|
-
let { nodeProps, children, ...props } = param;
|
|
243
|
-
useStopEvent(()=>{
|
|
244
|
-
return true;
|
|
245
|
-
});
|
|
246
|
-
return /*#__PURE__*/ React.createElement("input", {
|
|
247
|
-
...props,
|
|
248
|
-
ref: ref,
|
|
249
|
-
type: "text",
|
|
250
|
-
defaultValue: nodeProps.node.textContent
|
|
251
|
-
});
|
|
252
|
-
})
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
const input = screen.getByDisplayValue("input value");
|
|
256
|
-
input.focus();
|
|
257
|
-
await browser.keys("z");
|
|
258
|
-
expect(await $(input).getValue()).toBe("input valuez");
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
describe("customNodeViews prop", ()=>{
|
|
262
|
-
it("can replace a node's representation", async ()=>{
|
|
263
|
-
const { view } = tempEditor({
|
|
264
|
-
doc: doc(p("foo", br())),
|
|
265
|
-
customNodeViews: {
|
|
266
|
-
hard_break () {
|
|
267
|
-
return {
|
|
268
|
-
dom: document.createElement("var")
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
expect(view.dom.querySelector("var")).not.toBeNull();
|
|
274
|
-
});
|
|
275
|
-
it("can override drawing of a node's content", async ()=>{
|
|
276
|
-
const { view } = tempEditor({
|
|
277
|
-
doc: doc(p("foo")),
|
|
278
|
-
customNodeViews: {
|
|
279
|
-
paragraph (node) {
|
|
280
|
-
const dom = document.createElement("p");
|
|
281
|
-
dom.appendChild(document.createTextNode(node.textContent.toUpperCase()));
|
|
282
|
-
return {
|
|
283
|
-
dom
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
expect(view.dom.querySelector("p").textContent).toBe("FOO");
|
|
289
|
-
});
|
|
290
|
-
it("can register its own update method", async ()=>{
|
|
291
|
-
const { view } = tempEditor({
|
|
292
|
-
doc: doc(p("foo")),
|
|
293
|
-
customNodeViews: {
|
|
294
|
-
paragraph (node) {
|
|
295
|
-
const dom = document.createElement("p");
|
|
296
|
-
dom.textContent = node.textContent.toUpperCase();
|
|
297
|
-
return {
|
|
298
|
-
dom,
|
|
299
|
-
update (node) {
|
|
300
|
-
dom.textContent = node.textContent.toUpperCase();
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
const para = view.dom.querySelector("p");
|
|
308
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
309
|
-
expect(view.dom.querySelector("p")).toBe(para);
|
|
310
|
-
expect(para.textContent).toBe("AFOO");
|
|
311
|
-
});
|
|
312
|
-
it("allows decoration updates for node views with an update method", async ()=>{
|
|
313
|
-
const { view, rerender } = tempEditor({
|
|
314
|
-
doc: doc(p("foo")),
|
|
315
|
-
customNodeViews: {
|
|
316
|
-
paragraph (node) {
|
|
317
|
-
const dom = document.createElement("p");
|
|
318
|
-
return {
|
|
319
|
-
dom,
|
|
320
|
-
contentDOM: dom,
|
|
321
|
-
update (node_) {
|
|
322
|
-
return node.sameMarkup(node_);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
rerender({
|
|
329
|
-
decorations (state) {
|
|
330
|
-
return DecorationSet.create(state.doc, [
|
|
331
|
-
Decoration.inline(2, 3, {
|
|
332
|
-
someattr: "ok"
|
|
333
|
-
}),
|
|
334
|
-
Decoration.node(0, 5, {
|
|
335
|
-
otherattr: "ok"
|
|
336
|
-
})
|
|
337
|
-
]);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
expect(view.dom.querySelector("[someattr]")).not.toBeNull();
|
|
341
|
-
expect(view.dom.querySelector("[otherattr]")).not.toBeNull();
|
|
342
|
-
});
|
|
343
|
-
it("can provide a contentDOM property", async ()=>{
|
|
344
|
-
const { view } = tempEditor({
|
|
345
|
-
doc: doc(p("foo")),
|
|
346
|
-
customNodeViews: {
|
|
347
|
-
paragraph () {
|
|
348
|
-
const dom = document.createElement("p");
|
|
349
|
-
return {
|
|
350
|
-
dom,
|
|
351
|
-
contentDOM: dom
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
const para = view.dom.querySelector("p");
|
|
357
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
358
|
-
expect(view.dom.querySelector("p")).toBe(para);
|
|
359
|
-
expect(para.textContent).toBe("afoo");
|
|
360
|
-
});
|
|
361
|
-
// Skipping for now... We don't use a mutation observer to
|
|
362
|
-
// detect changes, so we don't have an obvious place to call
|
|
363
|
-
// ignoreMutation at the moment.
|
|
364
|
-
// TODO: Add this check to beforeInputPlugin
|
|
365
|
-
// eslint-disable-next-line jest/no-disabled-tests
|
|
366
|
-
it.skip("has its ignoreMutation method called", async ()=>{
|
|
367
|
-
let mutation;
|
|
368
|
-
const { view } = tempEditor({
|
|
369
|
-
doc: doc(p("foo")),
|
|
370
|
-
customNodeViews: {
|
|
371
|
-
paragraph () {
|
|
372
|
-
const dom = document.createElement("div");
|
|
373
|
-
const contentDOM = document.createElement("p");
|
|
374
|
-
const info = document.createElement("x-info");
|
|
375
|
-
dom.append(contentDOM, info);
|
|
376
|
-
return {
|
|
377
|
-
dom,
|
|
378
|
-
contentDOM,
|
|
379
|
-
ignoreMutation: (m)=>{
|
|
380
|
-
mutation = m;
|
|
381
|
-
return true;
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
expect(mutation).toBeFalsy();
|
|
388
|
-
view.dispatch(view.state.tr.delete(3, 5));
|
|
389
|
-
expect(mutation).toBeTruthy();
|
|
390
|
-
expect(mutation.target.tagName).toBe("X-INFO");
|
|
391
|
-
});
|
|
392
|
-
it("has its destroy method called", async ()=>{
|
|
393
|
-
let destroyed = 0;
|
|
394
|
-
const { view } = tempEditor({
|
|
395
|
-
doc: doc(p("foo", br())),
|
|
396
|
-
customNodeViews: {
|
|
397
|
-
hard_break () {
|
|
398
|
-
return {
|
|
399
|
-
dom: document.createElement("br"),
|
|
400
|
-
destroy: ()=>destroyed++
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
view.dispatch(view.state.tr.delete(3, 5));
|
|
406
|
-
expect(destroyed).toBe(1);
|
|
407
|
-
});
|
|
408
|
-
it("can query its own position", async ()=>{
|
|
409
|
-
let get;
|
|
410
|
-
const { view } = tempEditor({
|
|
411
|
-
doc: doc(blockquote(p("abc"), p("foo", br()))),
|
|
412
|
-
customNodeViews: {
|
|
413
|
-
hard_break (_n, _v, getPos) {
|
|
414
|
-
expect(getPos()).toBe(10);
|
|
415
|
-
get = getPos;
|
|
416
|
-
return {
|
|
417
|
-
dom: document.createElement("br")
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
expect(get()).toBe(10);
|
|
423
|
-
view.dispatch(view.state.tr.insertText("a"));
|
|
424
|
-
expect(get()).toBe(11);
|
|
425
|
-
});
|
|
426
|
-
it("has access to outer decorations", async ()=>{
|
|
427
|
-
const plugin = new Plugin({
|
|
428
|
-
state: {
|
|
429
|
-
init () {
|
|
430
|
-
return null;
|
|
431
|
-
},
|
|
432
|
-
apply (tr, prev) {
|
|
433
|
-
return tr.getMeta("setDeco") || prev;
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
props: {
|
|
437
|
-
decorations (state) {
|
|
438
|
-
const deco = this.getState(state);
|
|
439
|
-
return deco && DecorationSet.create(state.doc, [
|
|
440
|
-
Decoration.inline(0, state.doc.content.size, {}, {
|
|
441
|
-
name: deco
|
|
442
|
-
})
|
|
443
|
-
]);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
const { view } = tempEditor({
|
|
448
|
-
doc: doc(p("foo", br())),
|
|
449
|
-
plugins: [
|
|
450
|
-
plugin
|
|
451
|
-
],
|
|
452
|
-
customNodeViews: {
|
|
453
|
-
hard_break (_n, _v, _p, deco) {
|
|
454
|
-
const dom = document.createElement("var");
|
|
455
|
-
function update(deco) {
|
|
456
|
-
dom.textContent = deco.length ? deco[0].spec.name : "[]";
|
|
457
|
-
}
|
|
458
|
-
update(deco);
|
|
459
|
-
return {
|
|
460
|
-
dom,
|
|
461
|
-
update (_, deco) {
|
|
462
|
-
update(deco);
|
|
463
|
-
return true;
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
expect(view.dom.querySelector("var").textContent).toBe("[]");
|
|
470
|
-
view.dispatch(view.state.tr.setMeta("setDeco", "foo"));
|
|
471
|
-
expect(view.dom.querySelector("var").textContent).toBe("foo");
|
|
472
|
-
view.dispatch(view.state.tr.setMeta("setDeco", "bar"));
|
|
473
|
-
expect(view.dom.querySelector("var").textContent).toBe("bar");
|
|
474
|
-
});
|
|
475
|
-
it("provides access to inner decorations in the constructor", async ()=>{
|
|
476
|
-
tempEditor({
|
|
477
|
-
doc: doc(p("foo")),
|
|
478
|
-
customNodeViews: {
|
|
479
|
-
paragraph (_node, _v, _pos, _outer, innerDeco) {
|
|
480
|
-
const dom = document.createElement("p");
|
|
481
|
-
expect(innerDeco.find().map((d)=>`${d.from}-${d.to}`).join()).toBe("1-2");
|
|
482
|
-
return {
|
|
483
|
-
dom,
|
|
484
|
-
contentDOM: dom
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
},
|
|
488
|
-
decorations (state) {
|
|
489
|
-
return DecorationSet.create(state.doc, [
|
|
490
|
-
Decoration.inline(2, 3, {
|
|
491
|
-
someattr: "ok"
|
|
492
|
-
}),
|
|
493
|
-
Decoration.node(0, 5, {
|
|
494
|
-
otherattr: "ok"
|
|
495
|
-
})
|
|
496
|
-
]);
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
it("provides access to inner decorations in the update method", async ()=>{
|
|
501
|
-
let innerDecos = [];
|
|
502
|
-
const { rerender } = tempEditor({
|
|
503
|
-
doc: doc(p("foo")),
|
|
504
|
-
customNodeViews: {
|
|
505
|
-
paragraph (node) {
|
|
506
|
-
const dom = document.createElement("p");
|
|
507
|
-
return {
|
|
508
|
-
dom,
|
|
509
|
-
contentDOM: dom,
|
|
510
|
-
update (node_, _, innerDecoSet) {
|
|
511
|
-
innerDecos = innerDecoSet.find().map((d)=>`${d.from}-${d.to}`);
|
|
512
|
-
return node.sameMarkup(node_);
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
rerender({
|
|
519
|
-
decorations (state) {
|
|
520
|
-
return DecorationSet.create(state.doc, [
|
|
521
|
-
Decoration.inline(2, 3, {
|
|
522
|
-
someattr: "ok"
|
|
523
|
-
}),
|
|
524
|
-
Decoration.node(0, 5, {
|
|
525
|
-
otherattr: "ok"
|
|
526
|
-
})
|
|
527
|
-
]);
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
expect(innerDecos.join()).toBe("1-2");
|
|
531
|
-
});
|
|
532
|
-
it("can provide a stopEvent hook", async ()=>{
|
|
533
|
-
tempEditor({
|
|
534
|
-
doc: doc(p("input value")),
|
|
535
|
-
customNodeViews: {
|
|
536
|
-
paragraph (node) {
|
|
537
|
-
const dom = document.createElement("input");
|
|
538
|
-
dom.value = node.textContent;
|
|
539
|
-
return {
|
|
540
|
-
dom,
|
|
541
|
-
stopEvent () {
|
|
542
|
-
return true;
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
const input = screen.getByDisplayValue("input value");
|
|
549
|
-
input.focus();
|
|
550
|
-
await browser.keys("z");
|
|
551
|
-
expect(await $(input).getValue()).toBe("input valuez");
|
|
552
|
-
});
|
|
553
|
-
});
|