bookish-press 0.12.0 → 0.12.1
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/components/chapter/ChapterBody.test.js +10 -0
- package/dist/components/chapter/Format.svelte +7 -1
- package/dist/components/editor/ImageChooser.svelte +8 -5
- package/dist/components/editor/ImageChooser.test.d.ts +1 -0
- package/dist/components/editor/ImageChooser.test.js +67 -0
- package/dist/components/page/TitlePage.svelte.d.ts +9 -9
- package/dist/models/book/Theme.js +34 -34
- package/package.json +5 -5
|
@@ -68,6 +68,16 @@ test('renders footnote content in a marginal', () => {
|
|
|
68
68
|
expect(footnote).not.toBeNull();
|
|
69
69
|
expect(footnote?.textContent).toContain('And this is the footnote that supports it.');
|
|
70
70
|
});
|
|
71
|
+
// Regression (#383): inline parse errors used to fall through Format's
|
|
72
|
+
// branches and render as "Unknown segment type node=[object Object]".
|
|
73
|
+
test.each([
|
|
74
|
+
['some *bold text', 'Error: Unclosed *'],
|
|
75
|
+
['a [broken link here', "Error: Missing '|' in link"],
|
|
76
|
+
])('shows the parser’s message for %s', (markup, message) => {
|
|
77
|
+
const { container } = renderChapter(markup);
|
|
78
|
+
expect(container.textContent).toContain(message);
|
|
79
|
+
expect(container.textContent).not.toContain('Unknown segment type');
|
|
80
|
+
});
|
|
71
81
|
// This guards the marginal layout contract: every render of a marginal
|
|
72
82
|
// component must request a chapter-wide layout pass, including re-renders
|
|
73
83
|
// caused by content changes. (Marginal components do this in an $effect
|
|
@@ -8,7 +8,9 @@ import LabelNode from "../../models/chapter/LabelNode.js";
|
|
|
8
8
|
import SymbolNode from "../../models/chapter/SymbolNode.js";
|
|
9
9
|
import LinkNode from "../../models/chapter/LinkNode.js";
|
|
10
10
|
import TextNode from "../../models/chapter/TextNode.js";
|
|
11
|
+
import ErrorNode from "../../models/chapter/ErrorNode.js";
|
|
11
12
|
import Problem from "./Problem.svelte";
|
|
13
|
+
import ErrorMessage from "./ErrorMessage.svelte";
|
|
12
14
|
import Citations from "./Citations.svelte";
|
|
13
15
|
import Definition from "./Definition.svelte";
|
|
14
16
|
import Footnote from "./Footnote.svelte";
|
|
@@ -58,7 +60,11 @@ let showPlaceholder = $derived(node.isEmptyText() && placeholder !== undefined &
|
|
|
58
60
|
node={segment}
|
|
59
61
|
/>{:else if segment instanceof FormatNode}<Format
|
|
60
62
|
node={segment}
|
|
61
|
-
/>{:else
|
|
63
|
+
/>{:else if segment instanceof ErrorNode}<ErrorMessage
|
|
64
|
+
node={segment}
|
|
65
|
+
/>{:else}<Problem
|
|
66
|
+
>Unknown segment type {(segment as object).constructor
|
|
67
|
+
.name}</Problem
|
|
62
68
|
>{/if}{/each}</svelte:element
|
|
63
69
|
>
|
|
64
70
|
|
|
@@ -3,8 +3,13 @@ import { getBook } from "../page/Contexts.js";
|
|
|
3
3
|
import ImageThumbnail from "./ImageThumbnail.svelte";
|
|
4
4
|
let { select, selection } = $props();
|
|
5
5
|
let book = getBook();
|
|
6
|
-
|
|
6
|
+
// Replaced whole whenever the media changes, so it needn't be deeply reactive.
|
|
7
|
+
let images = $state.raw(undefined);
|
|
7
8
|
let expanded = $state(false);
|
|
9
|
+
// Sort the images by their URL. There's probably a more meaningful sort,
|
|
10
|
+
// such as placing unused images at the front of the list. Sort a copy:
|
|
11
|
+
// sorting state in place while rendering is an unsafe mutation.
|
|
12
|
+
const sorted = $derived(images === undefined ? undefined : [...images].sort((a, b) => a.url.localeCompare(b.url)));
|
|
8
13
|
function updateImages(newImages) {
|
|
9
14
|
images = newImages;
|
|
10
15
|
}
|
|
@@ -29,12 +34,10 @@ onMount(() => {
|
|
|
29
34
|
onmouseenter={() => (expanded = true)}
|
|
30
35
|
onmouseleave={() => (expanded = false)}
|
|
31
36
|
>
|
|
32
|
-
{#if
|
|
37
|
+
{#if sorted === undefined}
|
|
33
38
|
Loading images
|
|
34
39
|
{:else}
|
|
35
|
-
|
|
36
|
-
such as placing unused images at the front of the list. -->
|
|
37
|
-
{#each images.sort((a, b) => a.url.localeCompare(b.url)) as image}
|
|
40
|
+
{#each sorted as image (image.url)}
|
|
38
41
|
<ImageThumbnail
|
|
39
42
|
{image}
|
|
40
43
|
selected={image.url === selection}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
2
|
+
import { render } from '@testing-library/svelte';
|
|
3
|
+
import { tick } from 'svelte';
|
|
4
|
+
import { writable } from 'svelte/store';
|
|
5
|
+
import ImageChooser from './ImageChooser.svelte';
|
|
6
|
+
import { BOOK } from '../page/Contexts.js';
|
|
7
|
+
function image(name) {
|
|
8
|
+
return {
|
|
9
|
+
url: `https://example.com/${name}.png`,
|
|
10
|
+
thumb: `https://example.com/${name}-thumb.png`,
|
|
11
|
+
ref: {},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
// A book whose media reports the given images, as BookMedia.notify does.
|
|
15
|
+
function bookWith(images) {
|
|
16
|
+
const media = {
|
|
17
|
+
notify: (observer) => observer(images),
|
|
18
|
+
stopNotifying: () => undefined,
|
|
19
|
+
};
|
|
20
|
+
return writable({ getMedia: () => media });
|
|
21
|
+
}
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
// jsdom never loads images, so thumbnails would stay in their loading
|
|
24
|
+
// state; load every image right away instead.
|
|
25
|
+
vi.stubGlobal('Image', class {
|
|
26
|
+
onload = null;
|
|
27
|
+
onerror = null;
|
|
28
|
+
set src(_) {
|
|
29
|
+
queueMicrotask(() => this.onload?.());
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
34
|
+
async function renderChooser(images) {
|
|
35
|
+
const screen = render(ImageChooser, {
|
|
36
|
+
props: { select: () => undefined, selection: '' },
|
|
37
|
+
context: new Map([[BOOK, bookWith(images)]]),
|
|
38
|
+
});
|
|
39
|
+
await tick();
|
|
40
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
41
|
+
await tick();
|
|
42
|
+
return screen;
|
|
43
|
+
}
|
|
44
|
+
// Regression: sorting the images in place inside the template mutated state
|
|
45
|
+
// during rendering, which crashed the editor whenever a book had images.
|
|
46
|
+
test('lists a book’s images sorted by URL without mutating state', async () => {
|
|
47
|
+
const images = [image('zebra'), image('apple'), image('mango')];
|
|
48
|
+
const screen = await renderChooser(images);
|
|
49
|
+
const alts = screen
|
|
50
|
+
.getAllByRole('img')
|
|
51
|
+
.map((img) => img.getAttribute('alt'));
|
|
52
|
+
expect(alts).toEqual([
|
|
53
|
+
'Image named https://example.com/apple.png',
|
|
54
|
+
'Image named https://example.com/mango.png',
|
|
55
|
+
'Image named https://example.com/zebra.png',
|
|
56
|
+
]);
|
|
57
|
+
// The book's own list is left in its original order.
|
|
58
|
+
expect(images.map((i) => i.url)).toEqual([
|
|
59
|
+
'https://example.com/zebra.png',
|
|
60
|
+
'https://example.com/apple.png',
|
|
61
|
+
'https://example.com/mango.png',
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
test('says so when a book has no images', async () => {
|
|
65
|
+
const screen = await renderChooser([]);
|
|
66
|
+
expect(screen.getByText('No images uploaded')).toBeTruthy();
|
|
67
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
* A full-page state that looks like a book's title page: a title, a
|
|
3
|
+
* sentence or two below it, and optional links. Used for drafts that are
|
|
4
|
+
* coming soon, and for pages that can't show a book (missing, private, or
|
|
5
|
+
* failed to load). Only genuine failures set `error`, which colors the
|
|
6
|
+
* title; missing and private books are not errors.
|
|
7
|
+
*
|
|
8
|
+
* Fonts come from the book's theme inside a book, and fall back to the
|
|
9
|
+
* app's otherwise, so it reads the same in the reader and the editor.
|
|
10
|
+
*/
|
|
11
11
|
import type { Snippet } from 'svelte';
|
|
12
12
|
interface Props {
|
|
13
13
|
title: string;
|
|
@@ -13,12 +13,12 @@ export const BookishTheme = {
|
|
|
13
13
|
borderColorBold: '#000000',
|
|
14
14
|
// Foreground colors
|
|
15
15
|
paragraphColor: '#000000',
|
|
16
|
-
mutedColor: '#
|
|
16
|
+
mutedColor: '#6C747C',
|
|
17
17
|
highlightColor: '#E8AF22',
|
|
18
18
|
commentColor: '#257F31',
|
|
19
19
|
errorColor: '#721C24',
|
|
20
20
|
linkColor: '#1B499C',
|
|
21
|
-
bulletColor: '#
|
|
21
|
+
bulletColor: '#E31A15',
|
|
22
22
|
},
|
|
23
23
|
dark: {
|
|
24
24
|
// Background colors;
|
|
@@ -30,12 +30,12 @@ export const BookishTheme = {
|
|
|
30
30
|
borderColorBold: '#DADADA',
|
|
31
31
|
// Foreground colors
|
|
32
32
|
paragraphColor: '#DADADA',
|
|
33
|
-
mutedColor: '#
|
|
33
|
+
mutedColor: '#9C9C9C',
|
|
34
34
|
highlightColor: '#c5a248',
|
|
35
|
-
commentColor: '#
|
|
35
|
+
commentColor: '#45AF54',
|
|
36
36
|
errorColor: '#F8D7DA',
|
|
37
37
|
linkColor: '#73a3fa',
|
|
38
|
-
bulletColor: '#
|
|
38
|
+
bulletColor: '#E07F88',
|
|
39
39
|
},
|
|
40
40
|
// Fonts
|
|
41
41
|
fonts: {
|
|
@@ -92,7 +92,7 @@ export const SeriousTheme = {
|
|
|
92
92
|
borderColorBold: '#000000',
|
|
93
93
|
// Foreground colors
|
|
94
94
|
paragraphColor: '#000000',
|
|
95
|
-
mutedColor: '#
|
|
95
|
+
mutedColor: '#6C747C',
|
|
96
96
|
highlightColor: '#bb4242',
|
|
97
97
|
commentColor: '#257F31',
|
|
98
98
|
errorColor: '#721C24',
|
|
@@ -109,12 +109,12 @@ export const SeriousTheme = {
|
|
|
109
109
|
borderColorBold: '#DADADA',
|
|
110
110
|
// Foreground colors
|
|
111
111
|
paragraphColor: '#DADADA',
|
|
112
|
-
mutedColor: '#
|
|
112
|
+
mutedColor: '#9C9C9C',
|
|
113
113
|
highlightColor: '#b36363',
|
|
114
|
-
commentColor: '#
|
|
114
|
+
commentColor: '#45AF54',
|
|
115
115
|
errorColor: '#F8D7DA',
|
|
116
|
-
linkColor: '#
|
|
117
|
-
bulletColor: '#
|
|
116
|
+
linkColor: '#C78C8C',
|
|
117
|
+
bulletColor: '#C78C8C',
|
|
118
118
|
},
|
|
119
119
|
// Fonts
|
|
120
120
|
fonts: {
|
|
@@ -171,12 +171,12 @@ export const TechTheme = {
|
|
|
171
171
|
borderColorBold: '#000000',
|
|
172
172
|
// Foreground colors
|
|
173
173
|
paragraphColor: '#000000',
|
|
174
|
-
mutedColor: '#
|
|
174
|
+
mutedColor: '#6C747C',
|
|
175
175
|
highlightColor: '#6480ff',
|
|
176
176
|
commentColor: '#257F31',
|
|
177
177
|
errorColor: '#721C24',
|
|
178
|
-
linkColor: '#
|
|
179
|
-
bulletColor: '#
|
|
178
|
+
linkColor: '#4063FF',
|
|
179
|
+
bulletColor: '#4063FF',
|
|
180
180
|
},
|
|
181
181
|
dark: {
|
|
182
182
|
// Background colors;
|
|
@@ -188,12 +188,12 @@ export const TechTheme = {
|
|
|
188
188
|
borderColorBold: '#DADADA',
|
|
189
189
|
// Foreground colors
|
|
190
190
|
paragraphColor: '#DADADA',
|
|
191
|
-
mutedColor: '#
|
|
191
|
+
mutedColor: '#9B9B9B',
|
|
192
192
|
highlightColor: '#7589e6',
|
|
193
193
|
commentColor: '#2bb33e',
|
|
194
194
|
errorColor: '#F8D7DA',
|
|
195
|
-
linkColor: '#
|
|
196
|
-
bulletColor: '#
|
|
195
|
+
linkColor: '#8496E9',
|
|
196
|
+
bulletColor: '#8496E9',
|
|
197
197
|
},
|
|
198
198
|
// Fonts
|
|
199
199
|
fonts: {
|
|
@@ -250,12 +250,12 @@ export const HumanTheme = {
|
|
|
250
250
|
borderColorBold: '#000000',
|
|
251
251
|
// Foreground colors
|
|
252
252
|
paragraphColor: '#000000',
|
|
253
|
-
mutedColor: '#
|
|
253
|
+
mutedColor: '#6C747C',
|
|
254
254
|
highlightColor: '#3b92e4',
|
|
255
255
|
commentColor: '#257F31',
|
|
256
256
|
errorColor: '#721C24',
|
|
257
|
-
linkColor: '#
|
|
258
|
-
bulletColor: '#
|
|
257
|
+
linkColor: '#1C75C9',
|
|
258
|
+
bulletColor: '#1C75C9',
|
|
259
259
|
},
|
|
260
260
|
dark: {
|
|
261
261
|
// Background colors;
|
|
@@ -267,12 +267,12 @@ export const HumanTheme = {
|
|
|
267
267
|
borderColorBold: '#DADADA',
|
|
268
268
|
// Foreground colors
|
|
269
269
|
paragraphColor: '#DADADA',
|
|
270
|
-
mutedColor: '#
|
|
270
|
+
mutedColor: '#9C9C9C',
|
|
271
271
|
highlightColor: '#2b8ae3',
|
|
272
|
-
commentColor: '#
|
|
272
|
+
commentColor: '#45AF54',
|
|
273
273
|
errorColor: '#F8D7DA',
|
|
274
|
-
linkColor: '#
|
|
275
|
-
bulletColor: '#
|
|
274
|
+
linkColor: '#54A0E8',
|
|
275
|
+
bulletColor: '#54A0E8',
|
|
276
276
|
},
|
|
277
277
|
// Fonts
|
|
278
278
|
fonts: {
|
|
@@ -329,12 +329,12 @@ export const SketchyTheme = {
|
|
|
329
329
|
borderColorBold: '#000000',
|
|
330
330
|
// Foreground colors
|
|
331
331
|
paragraphColor: '#000000',
|
|
332
|
-
mutedColor: '#
|
|
332
|
+
mutedColor: '#6C747C',
|
|
333
333
|
highlightColor: '#dbb13e',
|
|
334
334
|
commentColor: '#257F31',
|
|
335
335
|
errorColor: '#721C24',
|
|
336
|
-
linkColor: '#
|
|
337
|
-
bulletColor: '#
|
|
336
|
+
linkColor: '#8E6F1B',
|
|
337
|
+
bulletColor: '#8E6F1B',
|
|
338
338
|
},
|
|
339
339
|
dark: {
|
|
340
340
|
// Background colors;
|
|
@@ -346,12 +346,12 @@ export const SketchyTheme = {
|
|
|
346
346
|
borderColorBold: '#DADADA',
|
|
347
347
|
// Foreground colors
|
|
348
348
|
paragraphColor: '#DADADA',
|
|
349
|
-
mutedColor: '#
|
|
349
|
+
mutedColor: '#9C9C9C',
|
|
350
350
|
highlightColor: '#9c7e2c',
|
|
351
|
-
commentColor: '#
|
|
351
|
+
commentColor: '#45AF54',
|
|
352
352
|
errorColor: '#F8D7DA',
|
|
353
|
-
linkColor: '#
|
|
354
|
-
bulletColor: '#
|
|
353
|
+
linkColor: '#BA9634',
|
|
354
|
+
bulletColor: '#BA9634',
|
|
355
355
|
},
|
|
356
356
|
// Fonts
|
|
357
357
|
fonts: {
|
|
@@ -411,12 +411,12 @@ export const CriticalTheme = {
|
|
|
411
411
|
borderColorBold: '#000000',
|
|
412
412
|
// Foreground colors
|
|
413
413
|
paragraphColor: '#000000',
|
|
414
|
-
mutedColor: '#
|
|
414
|
+
mutedColor: '#6C747C',
|
|
415
415
|
highlightColor: '#E8AF22',
|
|
416
416
|
commentColor: '#257F31',
|
|
417
417
|
errorColor: '#721C24',
|
|
418
418
|
linkColor: '#1B499C',
|
|
419
|
-
bulletColor: '#
|
|
419
|
+
bulletColor: '#E31A15',
|
|
420
420
|
},
|
|
421
421
|
dark: {
|
|
422
422
|
// Background colors;
|
|
@@ -430,10 +430,10 @@ export const CriticalTheme = {
|
|
|
430
430
|
paragraphColor: '#DADADA',
|
|
431
431
|
mutedColor: '#CCCCCC',
|
|
432
432
|
highlightColor: '#5c4d28',
|
|
433
|
-
commentColor: '#
|
|
433
|
+
commentColor: '#45AF54',
|
|
434
434
|
errorColor: '#F8D7DA',
|
|
435
435
|
linkColor: '#73a3fa',
|
|
436
|
-
bulletColor: '#
|
|
436
|
+
bulletColor: '#E07F88',
|
|
437
437
|
},
|
|
438
438
|
// Fonts
|
|
439
439
|
fonts: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bookish-press",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A platform for reading and writing readable, accessible, beautiful online books.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
"@types/prismjs": "^1.26",
|
|
54
54
|
"@types/smoothscroll-polyfill": "^0",
|
|
55
55
|
"@vitest/coverage-v8": "5.1.2",
|
|
56
|
-
"firebase-tools": "^15.
|
|
56
|
+
"firebase-tools": "^15.38.1",
|
|
57
57
|
"jsdom": "^31",
|
|
58
58
|
"prettier": "^3",
|
|
59
59
|
"prettier-plugin-svelte": "^4",
|
|
60
|
-
"svelte": "^5.
|
|
61
|
-
"svelte-check": "^4.7.
|
|
60
|
+
"svelte": "^5.60.2",
|
|
61
|
+
"svelte-check": "^4.7.9",
|
|
62
62
|
"tslib": "^2",
|
|
63
63
|
"typescript": "^6",
|
|
64
|
-
"vite": "^8.4.
|
|
64
|
+
"vite": "^8.4.1",
|
|
65
65
|
"vitest": "^5"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|