@griddo/ax 12.15.0-astro-rc.0 → 12.15.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/package.json +4 -4
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.caption.test.tsx +328 -39
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.test.tsx +1 -0
- package/src/__tests__/modules/GlobalSettings/Llms/Llms.uc.test.tsx +2861 -0
- package/src/api/domains.tsx +98 -2
- package/src/components/Fields/Wysiwyg/helpers.tsx +188 -0
- package/src/components/Fields/Wysiwyg/index.tsx +75 -39
- package/src/components/Fields/Wysiwyg/style.tsx +5 -0
- package/src/modules/GlobalSettings/Llms/AutomaticSelection/index.tsx +317 -0
- package/src/modules/GlobalSettings/Llms/DomainList/index.tsx +65 -0
- package/src/modules/GlobalSettings/Llms/IndexModelEditor/index.tsx +325 -0
- package/src/modules/GlobalSettings/Llms/MirrorExample/index.tsx +61 -0
- package/src/modules/GlobalSettings/Llms/MirrorOptions/index.tsx +82 -0
- package/src/modules/GlobalSettings/Llms/Outline/index.tsx +183 -0
- package/src/modules/GlobalSettings/Llms/PagePicker/index.tsx +105 -0
- package/src/modules/GlobalSettings/Llms/Preview/index.tsx +65 -0
- package/src/modules/GlobalSettings/Llms/ResolvedPages/index.tsx +191 -0
- package/src/modules/GlobalSettings/Llms/SectionEditor/index.tsx +262 -0
- package/src/modules/GlobalSettings/Llms/atoms.tsx +37 -0
- package/src/modules/GlobalSettings/Llms/index.tsx +383 -0
- package/src/modules/GlobalSettings/Llms/style.tsx +541 -0
- package/src/modules/GlobalSettings/Llms/utils.tsx +307 -0
- package/src/modules/GlobalSettings/index.tsx +7 -0
- package/src/routes/multisite.tsx +8 -1
- package/src/schemas/pages/GlobalPage.ts +2 -2
- package/src/schemas/pages/Page.ts +2 -2
- package/src/types/index.tsx +80 -12
- package/src/types/llms.tsx +315 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "12.15.0
|
|
4
|
+
"version": "12.15.0",
|
|
5
5
|
"homepage": "https://griddo.io",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
129
|
"@biomejs/biome": "2.5.15",
|
|
130
|
-
"@griddo/core": "12.15.0
|
|
130
|
+
"@griddo/core": "12.15.0",
|
|
131
131
|
"@types/redux-mock-store": "1.5.0",
|
|
132
132
|
"@vitest/coverage-v8": "4.1.11",
|
|
133
133
|
"axios-mock-adapter": "1.22.0",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"vitest-styled-components": "1.0.0"
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"@griddo/core": "12.15.0
|
|
141
|
+
"@griddo/core": "12.15.0"
|
|
142
142
|
},
|
|
143
143
|
"babel": {
|
|
144
144
|
"presets": [
|
|
@@ -171,5 +171,5 @@
|
|
|
171
171
|
"publishConfig": {
|
|
172
172
|
"access": "public"
|
|
173
173
|
},
|
|
174
|
-
"gitHead": "
|
|
174
|
+
"gitHead": "dee58968ea076b5d6f0ee92f0a6d4e7a1bf65630"
|
|
175
175
|
}
|
|
@@ -14,11 +14,13 @@ import { cleanup, render, waitFor } from "../../../../../config/tests/test-utils
|
|
|
14
14
|
|
|
15
15
|
const schemasConfig = config.schemas.config;
|
|
16
16
|
const store = configureStore()({ app: { token: "token" } });
|
|
17
|
+
// What AX keeps of the content: the editor's HTML only reaches it through here
|
|
18
|
+
const onChange = vi.fn();
|
|
17
19
|
|
|
18
20
|
const mountEditor = async (value: string) => {
|
|
19
21
|
const { container } = render(
|
|
20
22
|
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
21
|
-
<Wysiwyg value={value} onChange={
|
|
23
|
+
<Wysiwyg value={value} onChange={onChange} site={null} />
|
|
22
24
|
</ThemeProvider>,
|
|
23
25
|
{ store },
|
|
24
26
|
);
|
|
@@ -42,6 +44,20 @@ const rect = (width: number) =>
|
|
|
42
44
|
|
|
43
45
|
const caption = (editor: any): HTMLElement | null => editor.el.querySelector(".fr-img-caption");
|
|
44
46
|
|
|
47
|
+
// The editor's top level: each paragraph by its text, anything else by its class
|
|
48
|
+
const outline = (editor: any) =>
|
|
49
|
+
[...editor.el.children].map((el: HTMLElement) => (el.tagName === "P" ? `p: ${el.textContent}` : el.className));
|
|
50
|
+
|
|
51
|
+
const caretAt = (node: Node, offset: number) => {
|
|
52
|
+
const range = document.createRange();
|
|
53
|
+
range.setStart(node, offset);
|
|
54
|
+
getSelection()?.removeAllRanges();
|
|
55
|
+
getSelection()?.addRange(range);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const press = (editor: any, key: string) =>
|
|
59
|
+
editor.el.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
|
|
60
|
+
|
|
45
61
|
describe("Wysiwyg image caption", () => {
|
|
46
62
|
beforeAll(() => {
|
|
47
63
|
// Froala's licence check splits document.domain, which jsdom leaves undefined
|
|
@@ -72,32 +88,39 @@ describe("Wysiwyg image caption", () => {
|
|
|
72
88
|
expect(inner?.getAttribute("contenteditable")).toBe("true");
|
|
73
89
|
});
|
|
74
90
|
|
|
75
|
-
|
|
91
|
+
// The site sizes an image that has no width of its own: a width taken from
|
|
92
|
+
// how it shows in the editor would override that
|
|
93
|
+
it("should give no width to a never resized image, or to its caption", async () => {
|
|
76
94
|
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
77
|
-
|
|
95
|
+
const img = editor.el.querySelector("img");
|
|
96
|
+
vi.spyOn(img, "getBoundingClientRect").mockReturnValue(rect(300));
|
|
78
97
|
vi.spyOn(editor.el.querySelector("p"), "getBoundingClientRect").mockReturnValue(rect(600));
|
|
79
98
|
|
|
80
99
|
toggleCaption(editor);
|
|
81
100
|
|
|
82
|
-
expect(caption(editor)?.style
|
|
101
|
+
expect(caption(editor)?.hasAttribute("style")).toBe(false);
|
|
102
|
+
expect(img.hasAttribute("style")).toBe(false);
|
|
83
103
|
});
|
|
84
104
|
|
|
85
|
-
it("should
|
|
86
|
-
const editor = await mountEditor(
|
|
105
|
+
it("should keep a never resized image's other styles when it is captioned", async () => {
|
|
106
|
+
const editor = await mountEditor(
|
|
107
|
+
'<p><img src="http://x/a.png" alt="" class="fr-dib" style="height: 200px;"></p>',
|
|
108
|
+
);
|
|
109
|
+
const img = editor.el.querySelector("img");
|
|
87
110
|
|
|
88
111
|
toggleCaption(editor);
|
|
89
112
|
|
|
90
|
-
expect(
|
|
113
|
+
expect(img.getAttribute("style")).toBe("height: 200px;");
|
|
91
114
|
});
|
|
92
115
|
|
|
93
|
-
it("should
|
|
116
|
+
it("should give a resized image's width to its caption, and keep it on the image", async () => {
|
|
94
117
|
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib" style="width: 40%;"></p>');
|
|
95
118
|
const img = editor.el.querySelector("img");
|
|
96
119
|
|
|
97
120
|
toggleCaption(editor);
|
|
98
121
|
|
|
99
122
|
expect(caption(editor)?.style.width).toBe("40%");
|
|
100
|
-
expect(img.style.width).toBe("");
|
|
123
|
+
expect(img.style.width).toBe("40%");
|
|
101
124
|
|
|
102
125
|
toggleCaption(editor);
|
|
103
126
|
|
|
@@ -111,7 +134,6 @@ describe("Wysiwyg image caption", () => {
|
|
|
111
134
|
toggleCaption(editor);
|
|
112
135
|
|
|
113
136
|
expect(editor.el.querySelector("[width]")).toBeNull();
|
|
114
|
-
expect(editor.el.querySelector("img").hasAttribute("style")).toBe(false);
|
|
115
137
|
});
|
|
116
138
|
|
|
117
139
|
it("should turn a pixel width from before percentages into the caption's share", async () => {
|
|
@@ -125,7 +147,7 @@ describe("Wysiwyg image caption", () => {
|
|
|
125
147
|
toggleCaption(editor);
|
|
126
148
|
|
|
127
149
|
expect(caption(editor)?.style.width).toBe("50%");
|
|
128
|
-
expect(img.style.width).toBe("");
|
|
150
|
+
expect(img.style.width).toBe("50%");
|
|
129
151
|
});
|
|
130
152
|
|
|
131
153
|
it("should keep a resized image's size when its caption is put back", async () => {
|
|
@@ -137,28 +159,10 @@ describe("Wysiwyg image caption", () => {
|
|
|
137
159
|
toggleCaption(editor);
|
|
138
160
|
|
|
139
161
|
expect(caption(editor)?.style.width).toBe("40%");
|
|
140
|
-
expect(img.style.width).toBe("");
|
|
162
|
+
expect(img.style.width).toBe("40%");
|
|
141
163
|
expect(editor.el.querySelectorAll(".fr-img-space-wrap")).toHaveLength(1);
|
|
142
164
|
});
|
|
143
165
|
|
|
144
|
-
it("should leave the other captions alone when an image is captioned again", async () => {
|
|
145
|
-
const editor = await mountEditor(
|
|
146
|
-
'<p><img id="first" src="http://x/a.png" alt="" class="fr-dib"></p><p><img id="second" src="http://x/b.png" alt="" class="fr-dib"></p>',
|
|
147
|
-
);
|
|
148
|
-
const first = editor.el.querySelector("#first");
|
|
149
|
-
const second = editor.el.querySelector("#second");
|
|
150
|
-
|
|
151
|
-
toggleCaption(editor, first);
|
|
152
|
-
toggleCaption(editor, second);
|
|
153
|
-
toggleCaption(editor, second);
|
|
154
|
-
toggleCaption(editor, second);
|
|
155
|
-
|
|
156
|
-
expect(first.closest(".fr-img-space-wrap")).not.toBeNull();
|
|
157
|
-
expect(first.closest(".fr-img-caption")).not.toBeNull();
|
|
158
|
-
expect(second.closest(".fr-img-caption")).not.toBeNull();
|
|
159
|
-
expect(editor.el.querySelectorAll(".fr-img-space-wrap")).toHaveLength(2);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
166
|
describe("with the size popup", () => {
|
|
163
167
|
const widthInput = (editor: any) => editor.popups.get("image.size").find('input[name="width"]');
|
|
164
168
|
|
|
@@ -177,14 +181,14 @@ describe("Wysiwyg image caption", () => {
|
|
|
177
181
|
expect(widthInput(editor).val()).toBe("40%");
|
|
178
182
|
});
|
|
179
183
|
|
|
180
|
-
it("should size a captioned image
|
|
184
|
+
it("should size a captioned image and its caption alike", async () => {
|
|
181
185
|
const { editor, img } = await captionedAt40();
|
|
182
186
|
|
|
183
187
|
widthInput(editor).val("30%");
|
|
184
188
|
editor.commands.exec("imageSetSize");
|
|
185
189
|
|
|
186
190
|
expect(caption(editor)?.style.width).toBe("30%");
|
|
187
|
-
expect(img.style.width).toBe("");
|
|
191
|
+
expect(img.style.width).toBe("30%");
|
|
188
192
|
});
|
|
189
193
|
|
|
190
194
|
it("should keep a captioned image's height on the image", async () => {
|
|
@@ -219,14 +223,14 @@ describe("Wysiwyg image caption", () => {
|
|
|
219
223
|
});
|
|
220
224
|
|
|
221
225
|
describe("when resizing a captioned image", () => {
|
|
222
|
-
// jsdom has no layout: the column is 600px, and the caption, with
|
|
223
|
-
//
|
|
226
|
+
// jsdom has no layout: the column is 600px, and the caption, with
|
|
227
|
+
// everything inside it, takes the share its style asks for
|
|
224
228
|
const COLUMN = 600;
|
|
225
229
|
|
|
226
230
|
beforeEach(() => {
|
|
227
231
|
vi.spyOn(HTMLElement.prototype, "offsetWidth", "get").mockImplementation(function (this: HTMLElement) {
|
|
228
232
|
const box = this.closest(".fr-img-caption") as HTMLElement | null;
|
|
229
|
-
return box ? (Number.parseFloat(box.style.width) / 100) * COLUMN : COLUMN;
|
|
233
|
+
return box?.style.width ? (Number.parseFloat(box.style.width) / 100) * COLUMN : COLUMN;
|
|
230
234
|
});
|
|
231
235
|
});
|
|
232
236
|
|
|
@@ -238,6 +242,16 @@ describe("Wysiwyg image caption", () => {
|
|
|
238
242
|
return { editor, img };
|
|
239
243
|
};
|
|
240
244
|
|
|
245
|
+
// As captions were saved before the paragraph inside them was dropped
|
|
246
|
+
const captionedWithParagraph = async () => {
|
|
247
|
+
const editor = await mountEditor(
|
|
248
|
+
'<div class="fr-img-space-wrap"><span contenteditable="false" class="fr-img-caption fr-dib" draggable="false" style="width: 50%;"><span class="fr-img-wrap"><p><img src="http://x/a.png" alt="" class="fr-dib"><span class="fr-inner" contenteditable="true">Image Caption</span></p></span></span></div>',
|
|
249
|
+
);
|
|
250
|
+
const img = editor.el.querySelector("img");
|
|
251
|
+
editor.image.edit(editor.$(img));
|
|
252
|
+
return { editor, img };
|
|
253
|
+
};
|
|
254
|
+
|
|
241
255
|
// Froala reads pageX, which jsdom does not derive from clientX
|
|
242
256
|
const mouse = (type: string, pageX = 0) =>
|
|
243
257
|
Object.defineProperty(new MouseEvent(type, { bubbles: true }), "pageX", { value: pageX });
|
|
@@ -251,14 +265,41 @@ describe("Wysiwyg image caption", () => {
|
|
|
251
265
|
});
|
|
252
266
|
};
|
|
253
267
|
|
|
254
|
-
it(
|
|
255
|
-
|
|
268
|
+
it.each([
|
|
269
|
+
["a new caption", captioned],
|
|
270
|
+
["a caption saved with a paragraph in it", captionedWithParagraph],
|
|
271
|
+
])("should follow the pointer without bouncing, with %s", async (_, setup) => {
|
|
272
|
+
await setup();
|
|
256
273
|
|
|
257
274
|
expect(dragHandle([160, 160, 160, 130])).toEqual(["60%", "60%", "60%", "55%"]);
|
|
258
275
|
});
|
|
259
276
|
|
|
260
|
-
it("should
|
|
261
|
-
const { img } = await captioned();
|
|
277
|
+
it("should give the image the width the drag leaves on its caption", async () => {
|
|
278
|
+
const { editor, img } = await captioned();
|
|
279
|
+
|
|
280
|
+
dragHandle([160]);
|
|
281
|
+
document.body.dispatchEvent(mouse("mouseup"));
|
|
282
|
+
|
|
283
|
+
expect(img.style.width).toBe("60%");
|
|
284
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("should size a never resized image and its caption alike", async () => {
|
|
288
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
289
|
+
const img = editor.el.querySelector("img");
|
|
290
|
+
toggleCaption(editor);
|
|
291
|
+
editor.image.edit(editor.$(img));
|
|
292
|
+
|
|
293
|
+
dragHandle([40]);
|
|
294
|
+
document.body.dispatchEvent(mouse("mouseup"));
|
|
295
|
+
|
|
296
|
+
expect(caption(editor)?.style.width).toBe("90%");
|
|
297
|
+
expect(img.style.width).toBe("90%");
|
|
298
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("should put a caption saved with a paragraph in it back in its paragraph when the drag ends", async () => {
|
|
302
|
+
const { editor, img } = await captionedWithParagraph();
|
|
262
303
|
|
|
263
304
|
dragHandle([160]);
|
|
264
305
|
document.body.dispatchEvent(mouse("mouseup"));
|
|
@@ -266,6 +307,7 @@ describe("Wysiwyg image caption", () => {
|
|
|
266
307
|
const paragraph = img.closest(".fr-img-wrap > p");
|
|
267
308
|
expect(paragraph).not.toBeNull();
|
|
268
309
|
expect(paragraph.querySelector(".fr-inner")?.textContent).toBe("Image Caption");
|
|
310
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
269
311
|
});
|
|
270
312
|
});
|
|
271
313
|
|
|
@@ -281,6 +323,253 @@ describe("Wysiwyg image caption", () => {
|
|
|
281
323
|
});
|
|
282
324
|
});
|
|
283
325
|
|
|
326
|
+
describe.each([
|
|
327
|
+
["on", { imageResize: true }],
|
|
328
|
+
["off", undefined],
|
|
329
|
+
])("with image resizing %s", (_, richTextConfig) => {
|
|
330
|
+
beforeEach(() => {
|
|
331
|
+
if (richTextConfig) schemasConfig.richTextConfig = richTextConfig;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("should put the caption's text right after the image, with no paragraph around them", async () => {
|
|
335
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
336
|
+
|
|
337
|
+
toggleCaption(editor);
|
|
338
|
+
|
|
339
|
+
expect(caption(editor)?.querySelector("p")).toBeNull();
|
|
340
|
+
expect(caption(editor)?.querySelector(".fr-img-wrap > img + .fr-inner")?.textContent).toBe("Image Caption");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("should leave the caption's placeholder selected, to type over it", async () => {
|
|
344
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
345
|
+
|
|
346
|
+
toggleCaption(editor);
|
|
347
|
+
|
|
348
|
+
expect(getSelection()?.toString()).toBe("Image Caption");
|
|
349
|
+
expect(getSelection()?.anchorNode?.parentElement?.closest(".fr-inner")).not.toBeNull();
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("should leave the text sharing the image's paragraph out of the caption", async () => {
|
|
353
|
+
const editor = await mountEditor('<p>Above<img src="http://x/a.png" alt="" class="fr-dib">Below</p>');
|
|
354
|
+
|
|
355
|
+
toggleCaption(editor);
|
|
356
|
+
|
|
357
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
358
|
+
expect(caption(editor)?.textContent).toBe("Image Caption");
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("should keep the text around the image when its caption is removed", async () => {
|
|
362
|
+
const editor = await mountEditor('<p>Above<img src="http://x/a.png" alt="" class="fr-dib">Below</p>');
|
|
363
|
+
|
|
364
|
+
toggleCaption(editor);
|
|
365
|
+
toggleCaption(editor);
|
|
366
|
+
|
|
367
|
+
expect(caption(editor)).toBeNull();
|
|
368
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("should give back the text an earlier caption took in, when that caption is removed", async () => {
|
|
372
|
+
const editor = await mountEditor(
|
|
373
|
+
'<div class="fr-img-space-wrap"><span contenteditable="false" class="fr-img-caption fr-dib" draggable="false"><span class="fr-img-wrap"><p>Above<img src="http://x/a.png" alt="" class="fr-dib"><span class="fr-inner" contenteditable="true">Caption</span>Below</p></span></span></div>',
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
toggleCaption(editor);
|
|
377
|
+
|
|
378
|
+
expect(caption(editor)).toBeNull();
|
|
379
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("should not put a linked image's caption inside a paragraph", async () => {
|
|
383
|
+
const editor = await mountEditor(
|
|
384
|
+
'<p><a href="http://x"><img src="http://x/a.png" alt="" class="fr-dib"></a>Below</p>',
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
toggleCaption(editor);
|
|
388
|
+
|
|
389
|
+
expect(outline(editor)).toEqual(["fr-img-space-wrap", "p: Below"]);
|
|
390
|
+
expect(caption(editor)?.querySelector("a > img")).not.toBeNull();
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// As when the image goes in with the caret inside a link
|
|
394
|
+
it("should leave out of the caption, still linked, the text of a link the image is in", async () => {
|
|
395
|
+
const editor = await mountEditor(
|
|
396
|
+
'<p>Above <a href="http://x">link<img src="http://x/a.png" alt="" class="fr-dib">more</a> below</p>',
|
|
397
|
+
);
|
|
398
|
+
const links = () => [...editor.el.querySelectorAll(":scope > p > a")].map((a: HTMLElement) => a.textContent);
|
|
399
|
+
|
|
400
|
+
toggleCaption(editor);
|
|
401
|
+
|
|
402
|
+
expect(outline(editor)).toEqual(["p: Above link", "fr-img-space-wrap", "p: more below"]);
|
|
403
|
+
expect(links()).toEqual(["link", "more"]);
|
|
404
|
+
expect(caption(editor)?.querySelector("a > img + .fr-inner")?.textContent).toBe("Image Caption");
|
|
405
|
+
|
|
406
|
+
toggleCaption(editor);
|
|
407
|
+
|
|
408
|
+
expect(outline(editor)).toEqual(["p: Above link", "fr-img-space-wrap", "p: more below"]);
|
|
409
|
+
expect(links()).toEqual(["link", "more"]);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// As when the image goes in with the caret inside bold text
|
|
413
|
+
it("should leave out of the caption, still bold, the text around an image in bold", async () => {
|
|
414
|
+
const editor = await mountEditor(
|
|
415
|
+
'<p><strong>Above<img src="http://x/a.png" alt="" class="fr-dib">Below</strong></p>',
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
toggleCaption(editor);
|
|
419
|
+
|
|
420
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
421
|
+
const bold = [...editor.el.querySelectorAll(":scope > p > strong")].map((b: HTMLElement) => b.textContent);
|
|
422
|
+
expect(bold).toEqual(["Above", "Below"]);
|
|
423
|
+
expect(caption(editor)?.querySelector("strong")).toBeNull();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("should leave the other captions alone when an image is captioned again", async () => {
|
|
427
|
+
const editor = await mountEditor(
|
|
428
|
+
'<p><img id="first" src="http://x/a.png" alt="" class="fr-dib"></p><p><img id="second" src="http://x/b.png" alt="" class="fr-dib"></p>',
|
|
429
|
+
);
|
|
430
|
+
const first = editor.el.querySelector("#first");
|
|
431
|
+
const second = editor.el.querySelector("#second");
|
|
432
|
+
|
|
433
|
+
toggleCaption(editor, first);
|
|
434
|
+
toggleCaption(editor, second);
|
|
435
|
+
toggleCaption(editor, second);
|
|
436
|
+
toggleCaption(editor, second);
|
|
437
|
+
|
|
438
|
+
expect(first.closest(".fr-img-space-wrap")).not.toBeNull();
|
|
439
|
+
expect(first.closest(".fr-img-caption")).not.toBeNull();
|
|
440
|
+
expect(second.closest(".fr-img-caption")).not.toBeNull();
|
|
441
|
+
expect(editor.el.querySelectorAll(".fr-img-space-wrap")).toHaveLength(2);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe("with the keyboard around a captioned image", () => {
|
|
446
|
+
const captioned = async (
|
|
447
|
+
html = '<p>Above</p><p><img src="http://x/a.png" alt="" class="fr-dib"></p><p>Below</p>',
|
|
448
|
+
) => {
|
|
449
|
+
const editor = await mountEditor(html);
|
|
450
|
+
const img = editor.el.querySelector("img");
|
|
451
|
+
toggleCaption(editor, img);
|
|
452
|
+
return { editor, img };
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const paragraph = (editor: any, text: string) =>
|
|
456
|
+
[...editor.el.querySelectorAll(":scope > p")].find((p: HTMLElement) => p.textContent === text);
|
|
457
|
+
|
|
458
|
+
const caretBlock = () => {
|
|
459
|
+
const node = getSelection()?.anchorNode;
|
|
460
|
+
return (node instanceof Element ? node : node?.parentElement)?.closest("p");
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
it("should select the image instead of merging the block after it into its wrapper", async () => {
|
|
464
|
+
const { editor, img } = await captioned();
|
|
465
|
+
caretAt(paragraph(editor, "Below").firstChild, 0);
|
|
466
|
+
|
|
467
|
+
press(editor, "Backspace");
|
|
468
|
+
|
|
469
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
470
|
+
expect(editor.image.get()?.get(0)).toBe(img);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it("should select the image instead of merging its caption into the block before it", async () => {
|
|
474
|
+
const { editor, img } = await captioned();
|
|
475
|
+
caretAt(paragraph(editor, "Above").firstChild, "Above".length);
|
|
476
|
+
|
|
477
|
+
press(editor, "Delete");
|
|
478
|
+
|
|
479
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
480
|
+
expect(editor.image.get()?.get(0)).toBe(img);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it.each([
|
|
484
|
+
[
|
|
485
|
+
"Backspace",
|
|
486
|
+
"after",
|
|
487
|
+
'<p><img src="http://x/a.png" alt="" class="fr-dib"></p><p><br></p><p>Below</p>',
|
|
488
|
+
["fr-img-space-wrap", "p: Below"],
|
|
489
|
+
],
|
|
490
|
+
[
|
|
491
|
+
"Delete",
|
|
492
|
+
"before",
|
|
493
|
+
'<p>Above</p><p><br></p><p><img src="http://x/a.png" alt="" class="fr-dib"></p>',
|
|
494
|
+
["p: Above", "fr-img-space-wrap"],
|
|
495
|
+
],
|
|
496
|
+
])("should drop an empty block on %s %s the image, and select it", async (key, _, html, expected) => {
|
|
497
|
+
const { editor, img } = await captioned(html);
|
|
498
|
+
caretAt(paragraph(editor, ""), 0);
|
|
499
|
+
|
|
500
|
+
press(editor, key);
|
|
501
|
+
|
|
502
|
+
expect(outline(editor)).toEqual(expected);
|
|
503
|
+
expect(editor.image.get()?.get(0)).toBe(img);
|
|
504
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("should leave Backspace alone away from the start of the block", async () => {
|
|
508
|
+
const { editor } = await captioned();
|
|
509
|
+
caretAt(paragraph(editor, "Below").firstChild, 2);
|
|
510
|
+
|
|
511
|
+
press(editor, "Backspace");
|
|
512
|
+
|
|
513
|
+
expect(editor.image.get()).toBeFalsy();
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it.each([
|
|
517
|
+
["ArrowRight", "Below"],
|
|
518
|
+
["ArrowDown", "Below"],
|
|
519
|
+
["Escape", "Below"],
|
|
520
|
+
["ArrowLeft", "Above"],
|
|
521
|
+
["ArrowUp", "Above"],
|
|
522
|
+
])("should take the caret out of the image's wrapper on %s", async (key, text) => {
|
|
523
|
+
const { editor, img } = await captioned();
|
|
524
|
+
editor.image.edit(editor.$(img));
|
|
525
|
+
|
|
526
|
+
press(editor, key);
|
|
527
|
+
|
|
528
|
+
expect(editor.image.get()).toBeFalsy();
|
|
529
|
+
expect(caretBlock()?.textContent).toBe(text);
|
|
530
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: Below"]);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("should start a paragraph to take the caret to when there is none", async () => {
|
|
534
|
+
const { editor, img } = await captioned('<p>Above</p><p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
535
|
+
editor.image.edit(editor.$(img));
|
|
536
|
+
|
|
537
|
+
press(editor, "ArrowRight");
|
|
538
|
+
|
|
539
|
+
expect(outline(editor)).toEqual(["p: Above", "fr-img-space-wrap", "p: "]);
|
|
540
|
+
expect(caretBlock()).toBe(editor.el.lastElementChild);
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it("should hand AX the paragraph it starts between two images", async () => {
|
|
544
|
+
const { editor, img } = await captioned(
|
|
545
|
+
'<p><img src="http://x/a.png" alt="" class="fr-dib"></p><p><img id="second" src="http://x/b.png" alt="" class="fr-dib"></p>',
|
|
546
|
+
);
|
|
547
|
+
toggleCaption(editor, editor.el.querySelector("#second"));
|
|
548
|
+
editor.image.edit(editor.$(img));
|
|
549
|
+
|
|
550
|
+
press(editor, "ArrowRight");
|
|
551
|
+
|
|
552
|
+
expect(outline(editor)).toEqual(["fr-img-space-wrap", "p: ", "fr-img-space-wrap"]);
|
|
553
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it.each([
|
|
557
|
+
["with Backspace", (editor: any) => press(editor, "Backspace")],
|
|
558
|
+
["with Delete", (editor: any) => press(editor, "Delete")],
|
|
559
|
+
["from its popup", (editor: any) => editor.commands.exec("imageRemove")],
|
|
560
|
+
])("should leave a paragraph where the image was when it is removed %s", async (_, remove) => {
|
|
561
|
+
const { editor, img } = await captioned();
|
|
562
|
+
editor.image.edit(editor.$(img));
|
|
563
|
+
|
|
564
|
+
remove(editor);
|
|
565
|
+
|
|
566
|
+
expect(editor.el.querySelector("img")).toBeNull();
|
|
567
|
+
expect(outline(editor)).toEqual(["p: Above", "p: ", "p: Below"]);
|
|
568
|
+
expect(caretBlock()).toBe(editor.el.children[1]);
|
|
569
|
+
expect(onChange).toHaveBeenLastCalledWith(editor.html.get());
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
|
|
284
573
|
it("should leave Froala's pixel caption alone when resizing is off", async () => {
|
|
285
574
|
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib"></p>');
|
|
286
575
|
|
|
@@ -19,6 +19,7 @@ vi.mock("react-froala-wysiwyg", () => ({
|
|
|
19
19
|
$el: { get: vi.fn(() => editorElRef.current!) },
|
|
20
20
|
el: editorElRef.current,
|
|
21
21
|
edit: { on: vi.fn(), off: vi.fn() },
|
|
22
|
+
events: { on: vi.fn() },
|
|
22
23
|
commands: { exec: vi.fn() },
|
|
23
24
|
opts: { zIndex: 1 },
|
|
24
25
|
$tb: { css: vi.fn() },
|