uncial 3.0.0 → 5.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/README.md +6 -1
- package/dist/core/defineBlock.js +5 -2
- package/dist/core/types.d.ts +5 -1
- package/dist/editor/AttributeFieldControl.svelte +156 -3
- package/dist/editor/AttributeFieldControl.svelte.d.ts +4 -0
- package/dist/editor/BlockAttributesPanel.svelte +12 -3
- package/dist/editor/BlockAttributesPanel.svelte.d.ts +5 -0
- package/dist/editor/BlockNodeView.svelte +2 -1
- package/dist/editor/DocumentMetaPanel.svelte +12 -2
- package/dist/editor/DocumentMetaPanel.svelte.d.ts +4 -0
- package/dist/editor/Editor.svelte +26 -9
- package/dist/editor/Editor.svelte.d.ts +3 -0
- package/dist/editor/ImagePicker.svelte +85 -0
- package/dist/editor/ImagePicker.svelte.d.ts +13 -0
- package/dist/editor/bindEditor.d.ts +3 -0
- package/dist/editor/bindEditor.js +1 -1
- package/dist/editor/imageSource.d.ts +14 -0
- package/dist/editor/imageSource.js +1 -0
- package/dist/editor/index.d.ts +1 -0
- package/dist/editor/metaController.js +0 -5
- package/dist/editor/zonedDateTime.d.ts +4 -0
- package/dist/editor/zonedDateTime.js +38 -0
- package/dist/render/SuperscriptMarkFixture.svelte +1 -1
- package/dist/render/SuperscriptMarkFixture.svelte.d.ts +1 -1
- package/dist/render/Tabs.svelte +1 -1
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.js +1 -0
- package/dist/render/resolveImageSrc.d.ts +6 -0
- package/dist/render/resolveImageSrc.js +10 -0
- package/dist/render/tabSelection.svelte.js +2 -0
- package/dist/shared/ImageBlockFixture.svelte +29 -0
- package/dist/shared/ImageBlockFixture.svelte.d.ts +11 -0
- package/dist/shared/imagePreviews.d.ts +24 -0
- package/dist/shared/imagePreviews.js +78 -0
- package/dist/shared/tiptap.d.ts +2 -1
- package/dist/shared/tiptap.js +16 -13
- package/dist/styles/base.css +89 -9
- package/dist/styles/controls.css +6 -1
- package/dist/ui/ThemeSwitcher.svelte +1 -1
- package/dist/ui/theme.svelte.js +1 -1
- package/dist/web-components/UncialEditor.svelte +4 -0
- package/dist/web-components/UncialEditor.svelte.d.ts +2 -1
- package/dist/web-components/index.d.ts +4 -1
- package/dist/web-components/index.js +6 -0
- package/package.json +3 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ImagePreviews } from '../shared/imagePreviews.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
browse: () => Promise<string[]>;
|
|
4
|
+
thumbnail?: (src: string) => string;
|
|
5
|
+
imagePreviews?: ImagePreviews;
|
|
6
|
+
current: string;
|
|
7
|
+
onPick: (value: string) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const ImagePicker: import("svelte").Component<Props, {
|
|
10
|
+
open: () => void;
|
|
11
|
+
}, "">;
|
|
12
|
+
type ImagePicker = ReturnType<typeof ImagePicker>;
|
|
13
|
+
export default ImagePicker;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Editor as TiptapEditor, type AnyExtension, type JSONContent } from '@tiptap/core';
|
|
2
2
|
import type { ActionReturn } from 'svelte/action';
|
|
3
3
|
import type { BlockDefinition, BlockRegistry, ContentSchema, ValidationIssue } from '../core/types.js';
|
|
4
|
+
import type { ImagePreviews } from '../shared/imagePreviews.js';
|
|
4
5
|
import { type BlockAttributesController } from './attributesController.js';
|
|
5
6
|
export interface BindEditorOptions {
|
|
6
7
|
blocks?: BlockRegistry | BlockDefinition[];
|
|
@@ -16,6 +17,8 @@ export interface BindEditorOptions {
|
|
|
16
17
|
* gutter label opens it.
|
|
17
18
|
*/
|
|
18
19
|
autoOpenAttributes?: boolean;
|
|
20
|
+
/** Previews the canvas shows in place of just-uploaded `input: 'image'` values. */
|
|
21
|
+
imagePreviews?: ImagePreviews;
|
|
19
22
|
onIssue?: (issue: ValidationIssue) => void;
|
|
20
23
|
onChange?: (json: JSONContent) => void;
|
|
21
24
|
onMetaChange?: (meta: Record<string, unknown>) => void;
|
|
@@ -159,7 +159,7 @@ export function bindEditor(node, initialOptions = {}) {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
function createEditor() {
|
|
162
|
-
const extensions = createEditorExtensions(registry, schema, (pos) => controller.openAttributesAt(pos), options.extensions ?? []);
|
|
162
|
+
const extensions = createEditorExtensions(registry, schema, (pos) => controller.openAttributesAt(pos), options.extensions ?? [], options.imagePreviews);
|
|
163
163
|
const initialContent = normalizeAndValidate(options.json ?? emptyDocument());
|
|
164
164
|
rememberReadOnlyAttrs(initialContent);
|
|
165
165
|
const sanitized = sanitizeForEditorSchema(toEditorDocument(initialContent), getSchema(extensions));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an `input: 'image'` attribute's values come from. The field offers
|
|
3
|
+
* only the actions the host supplies.
|
|
4
|
+
*/
|
|
5
|
+
export interface ImageSource {
|
|
6
|
+
/** Commit a file and answer the value to store. */
|
|
7
|
+
upload?: (file: File) => Promise<string>;
|
|
8
|
+
/** Values of existing images to choose from. */
|
|
9
|
+
browse?: () => Promise<string[]>;
|
|
10
|
+
/** A displayable URL for a stored value; identity when absent. */
|
|
11
|
+
thumbnail?: (src: string) => string;
|
|
12
|
+
/** Whether a stored value names an image that no longer exists; the canvas shows a placeholder for it. */
|
|
13
|
+
missing?: (src: string) => boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { createBlockAttributesController, createInitialState } from './attribute
|
|
|
10
10
|
export { createDocumentMetaController } from './metaController.js';
|
|
11
11
|
export { CHOOSE_ATTRIBUTE_EVENT } from './chooseAttribute.js';
|
|
12
12
|
export type { ChooseAttributeRequest } from './chooseAttribute.js';
|
|
13
|
+
export type { ImageSource } from './imageSource.js';
|
|
13
14
|
export { builtinToolbarFeatures, defaultToolbarFeatures, resolveToolbarFeatures } from './toolbarFeatures.js';
|
|
14
15
|
export type { BindEditorOptions } from './bindEditor.js';
|
|
15
16
|
export type { ToolbarFeature, ToolbarFeatureContext, ToolbarFeatureId, ToolbarFeatureSelection } from './toolbarFeatures.js';
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { get, writable } from 'svelte/store';
|
|
2
2
|
import { parseMetaDraftValues, toMetaDraftValues, validateMeta } from '../core/meta.js';
|
|
3
|
-
const INITIAL_STATE = {
|
|
4
|
-
draft: {},
|
|
5
|
-
errors: {},
|
|
6
|
-
dirty: false
|
|
7
|
-
};
|
|
8
3
|
function errorsFromIssues(issues) {
|
|
9
4
|
const errors = {};
|
|
10
5
|
for (const issue of issues) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The wall-clock `YYYY-MM-DDTHH:mm` of an ISO instant in `timeZone`, or '' if it is not one. */
|
|
2
|
+
export declare function toWallClock(iso: string, timeZone?: string): string;
|
|
3
|
+
/** The ISO instant, with `timeZone`'s offset, of a `YYYY-MM-DDTHH:mm` wall clock there. */
|
|
4
|
+
export declare function fromWallClock(wallClock: string, timeZone?: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function offsetMinutes(instant, timeZone) {
|
|
2
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {
|
|
3
|
+
timeZone,
|
|
4
|
+
hourCycle: 'h23',
|
|
5
|
+
year: 'numeric',
|
|
6
|
+
month: '2-digit',
|
|
7
|
+
day: '2-digit',
|
|
8
|
+
hour: '2-digit',
|
|
9
|
+
minute: '2-digit',
|
|
10
|
+
second: '2-digit'
|
|
11
|
+
})
|
|
12
|
+
.formatToParts(instant)
|
|
13
|
+
.map(({ type, value }) => [type, Number(value)]));
|
|
14
|
+
const wall = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
15
|
+
return Math.round((wall - Math.floor(instant / 1000) * 1000) / 60_000);
|
|
16
|
+
}
|
|
17
|
+
function pad(n) {
|
|
18
|
+
return String(n).padStart(2, '0');
|
|
19
|
+
}
|
|
20
|
+
/** The wall-clock `YYYY-MM-DDTHH:mm` of an ISO instant in `timeZone`, or '' if it is not one. */
|
|
21
|
+
export function toWallClock(iso, timeZone) {
|
|
22
|
+
const instant = Date.parse(iso);
|
|
23
|
+
if (!iso || Number.isNaN(instant))
|
|
24
|
+
return '';
|
|
25
|
+
return new Date(instant + offsetMinutes(instant, timeZone) * 60_000).toISOString().slice(0, 16);
|
|
26
|
+
}
|
|
27
|
+
/** The ISO instant, with `timeZone`'s offset, of a `YYYY-MM-DDTHH:mm` wall clock there. */
|
|
28
|
+
export function fromWallClock(wallClock, timeZone) {
|
|
29
|
+
const wall = Date.parse(`${wallClock}Z`);
|
|
30
|
+
if (!wallClock || Number.isNaN(wall))
|
|
31
|
+
return '';
|
|
32
|
+
let instant = wall - offsetMinutes(wall, timeZone) * 60_000;
|
|
33
|
+
instant = wall - offsetMinutes(instant, timeZone) * 60_000;
|
|
34
|
+
const offset = offsetMinutes(instant, timeZone);
|
|
35
|
+
const sign = offset < 0 ? '-' : '+';
|
|
36
|
+
const zone = `${sign}${pad(Math.floor(Math.abs(offset) / 60))}:${pad(Math.abs(offset) % 60)}`;
|
|
37
|
+
return `${toWallClock(new Date(instant).toISOString(), timeZone)}:00${zone}`;
|
|
38
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { MarkComponentProps } from '../core/types.js';
|
|
2
|
-
declare const SuperscriptMarkFixture: import("svelte").Component<MarkComponentProps, {}, "">;
|
|
2
|
+
declare const SuperscriptMarkFixture: import("svelte").Component<Pick<MarkComponentProps, "children">, {}, "">;
|
|
3
3
|
type SuperscriptMarkFixture = ReturnType<typeof SuperscriptMarkFixture>;
|
|
4
4
|
export default SuperscriptMarkFixture;
|
package/dist/render/Tabs.svelte
CHANGED
package/dist/render/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { default as RichText } from './RichText.svelte';
|
|
|
3
3
|
export { default as Tab } from './Tab.svelte';
|
|
4
4
|
export { default as Tabs } from './Tabs.svelte';
|
|
5
5
|
export { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
|
|
6
|
+
export { resolveImageSrc } from './resolveImageSrc.js';
|
package/dist/render/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { default as Tabs } from './Tabs.svelte';
|
|
|
6
6
|
// a document — has to read the same as a fence the renderer produced, so the
|
|
7
7
|
// highlighter the renderer uses is part of the render surface.
|
|
8
8
|
export { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
|
|
9
|
+
export { resolveImageSrc } from './resolveImageSrc.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a SvelteKit-style `base` (`''` or `/sub`) to a root-relative image `src`.
|
|
3
|
+
* Anything else — `blob:` editor previews, `data:` URIs, protocol-relative and
|
|
4
|
+
* absolute URLs, relative paths — is already displayable and passes through.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveImageSrc(src: string, base: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a SvelteKit-style `base` (`''` or `/sub`) to a root-relative image `src`.
|
|
3
|
+
* Anything else — `blob:` editor previews, `data:` URIs, protocol-relative and
|
|
4
|
+
* absolute URLs, relative paths — is already displayable and passes through.
|
|
5
|
+
*/
|
|
6
|
+
export function resolveImageSrc(src, base) {
|
|
7
|
+
if (!src.startsWith('/') || src.startsWith('//'))
|
|
8
|
+
return src;
|
|
9
|
+
return base.replace(/\/+$/, '') + src;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// Test fixture: a block that renders exactly the image values it is handed.
|
|
3
|
+
interface Props {
|
|
4
|
+
src?: string;
|
|
5
|
+
items?: Array<{ image?: string; caption?: string }>;
|
|
6
|
+
updateAttributes?: (attrs: Record<string, unknown>) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let { src = '', items = [], updateAttributes }: Props = $props();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div data-testid="image-block-fixture">
|
|
13
|
+
{#if src}
|
|
14
|
+
<img data-testid="canvas-image" {src} alt="" />
|
|
15
|
+
{/if}
|
|
16
|
+
{#each items as item, index (index)}
|
|
17
|
+
{#if item.image}
|
|
18
|
+
<img data-testid="canvas-gallery-image" src={item.image} alt="" />
|
|
19
|
+
{/if}
|
|
20
|
+
{/each}
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
data-testid="edit-captions"
|
|
24
|
+
onclick={() =>
|
|
25
|
+
updateAttributes?.({ items: items.map((item) => ({ ...item, caption: 'edited' })) })}
|
|
26
|
+
>
|
|
27
|
+
Edit captions
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
src?: string;
|
|
3
|
+
items?: Array<{
|
|
4
|
+
image?: string;
|
|
5
|
+
caption?: string;
|
|
6
|
+
}>;
|
|
7
|
+
updateAttributes?: (attrs: Record<string, unknown>) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const ImageBlockFixture: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type ImageBlockFixture = ReturnType<typeof ImageBlockFixture>;
|
|
11
|
+
export default ImageBlockFixture;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BlockDefinition } from '../core/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Local `blob:` previews of images uploaded this session, keyed by the value
|
|
4
|
+
* the image source returned. An uploaded file is not served until the site
|
|
5
|
+
* redeploys, so the canvas shows the preview in the meantime.
|
|
6
|
+
*/
|
|
7
|
+
export interface ImagePreviews {
|
|
8
|
+
get(src: string): string | undefined;
|
|
9
|
+
/** The value a preview URL stands in for. */
|
|
10
|
+
sourceOf(url: string): string | undefined;
|
|
11
|
+
register(src: string, file: Blob): void;
|
|
12
|
+
revokeAll(): void;
|
|
13
|
+
}
|
|
14
|
+
/** Unique per value, so {@link ImagePreviews.sourceOf} can map a placeholder back. */
|
|
15
|
+
export declare function missingImagePlaceholder(src: string): string;
|
|
16
|
+
/** `placeholder` answers a stand-in URL for a value with no preview, e.g. a missing image. */
|
|
17
|
+
export declare function createImagePreviews(placeholder?: (src: string) => string | undefined): ImagePreviews;
|
|
18
|
+
/** The attrs a Block component renders on the canvas, with previews in place of image values. */
|
|
19
|
+
export declare function withImagePreviews(block: BlockDefinition, attrs: Record<string, unknown>, previews: ImagePreviews): Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* The attrs a Block component writes back, with its previews turned into the
|
|
22
|
+
* values they stand in for, so a preview is never stored.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withoutImagePreviews(block: BlockDefinition, attrs: Record<string, unknown>, previews: ImagePreviews): Record<string, unknown>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { attributeListFields, attributeListValueSpec, inferAttributeInputKind } from '../core/attributes.js';
|
|
2
|
+
const MISSING_IMAGE_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="320" height="200" viewBox="0 0 320 200"><rect width="320" height="200" fill="#f4f4f5" stroke="#d4d4d8" stroke-dasharray="6 4"/><text x="160" y="106" font-family="system-ui, sans-serif" font-size="16" fill="#71717a" text-anchor="middle">Missing image</text></svg>`;
|
|
3
|
+
/** Unique per value, so {@link ImagePreviews.sourceOf} can map a placeholder back. */
|
|
4
|
+
export function missingImagePlaceholder(src) {
|
|
5
|
+
return `data:image/svg+xml,${encodeURIComponent(MISSING_IMAGE_SVG)}#${encodeURIComponent(src)}`;
|
|
6
|
+
}
|
|
7
|
+
/** `placeholder` answers a stand-in URL for a value with no preview, e.g. a missing image. */
|
|
8
|
+
export function createImagePreviews(placeholder = () => undefined) {
|
|
9
|
+
const previews = new Map();
|
|
10
|
+
const sources = new Map();
|
|
11
|
+
return {
|
|
12
|
+
get(src) {
|
|
13
|
+
const known = previews.get(src);
|
|
14
|
+
if (known)
|
|
15
|
+
return known;
|
|
16
|
+
const url = placeholder(src);
|
|
17
|
+
if (url) {
|
|
18
|
+
previews.set(src, url);
|
|
19
|
+
sources.set(url, src);
|
|
20
|
+
}
|
|
21
|
+
return url;
|
|
22
|
+
},
|
|
23
|
+
sourceOf: (url) => sources.get(url),
|
|
24
|
+
register(src, file) {
|
|
25
|
+
// A re-upload answers the same src, so nothing re-renders and the canvas
|
|
26
|
+
// and field keep the earlier URL; it is not revoked until teardown.
|
|
27
|
+
const url = URL.createObjectURL(file);
|
|
28
|
+
sources.set(url, src);
|
|
29
|
+
previews.set(src, url);
|
|
30
|
+
},
|
|
31
|
+
revokeAll() {
|
|
32
|
+
sources.forEach((_src, url) => {
|
|
33
|
+
if (url.startsWith('blob:'))
|
|
34
|
+
URL.revokeObjectURL(url);
|
|
35
|
+
});
|
|
36
|
+
sources.clear();
|
|
37
|
+
previews.clear();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function substituteValue(spec, value, lookup) {
|
|
42
|
+
const kind = inferAttributeInputKind(spec);
|
|
43
|
+
if (kind === 'image') {
|
|
44
|
+
return typeof value === 'string' ? (lookup(value) ?? value) : value;
|
|
45
|
+
}
|
|
46
|
+
if (kind !== 'list' || !spec.list || !Array.isArray(value))
|
|
47
|
+
return value;
|
|
48
|
+
const valueSpec = attributeListValueSpec(spec.list);
|
|
49
|
+
if (valueSpec)
|
|
50
|
+
return value.map((item) => substituteValue(valueSpec, item, lookup));
|
|
51
|
+
const fields = attributeListFields(spec.list);
|
|
52
|
+
return value.map((item) => {
|
|
53
|
+
if (typeof item !== 'object' || item === null)
|
|
54
|
+
return item;
|
|
55
|
+
const record = item;
|
|
56
|
+
return Object.fromEntries(Object.entries(record).map(([name, fieldValue]) => {
|
|
57
|
+
const fieldSpec = fields.find(([fieldName]) => fieldName === name)?.[1];
|
|
58
|
+
return [name, fieldSpec ? substituteValue(fieldSpec, fieldValue, lookup) : fieldValue];
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function substituteAttrs(block, attrs, lookup) {
|
|
63
|
+
return Object.fromEntries(Object.entries(attrs).map(([name, value]) => {
|
|
64
|
+
const spec = block.attributes[name];
|
|
65
|
+
return [name, spec ? substituteValue(spec, value, lookup) : value];
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
/** The attrs a Block component renders on the canvas, with previews in place of image values. */
|
|
69
|
+
export function withImagePreviews(block, attrs, previews) {
|
|
70
|
+
return substituteAttrs(block, attrs, (value) => previews.get(value));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The attrs a Block component writes back, with its previews turned into the
|
|
74
|
+
* values they stand in for, so a preview is never stored.
|
|
75
|
+
*/
|
|
76
|
+
export function withoutImagePreviews(block, attrs, previews) {
|
|
77
|
+
return substituteAttrs(block, attrs, (value) => previews.sourceOf(value));
|
|
78
|
+
}
|
package/dist/shared/tiptap.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type AnyExtension } from '@tiptap/core';
|
|
2
2
|
import type { BlockDefinition, BlockRegistry, ContentSchema } from '../core/types.js';
|
|
3
3
|
import type { RichTextFeature } from '../core/types.js';
|
|
4
|
+
import { type ImagePreviews } from './imagePreviews.js';
|
|
4
5
|
export type BlockActivationCallback = (pos: number) => void;
|
|
5
6
|
export declare function getBlockDefaultAttrs(block: BlockDefinition): Record<string, unknown>;
|
|
6
7
|
export declare function createRichTextExtensions(features: ReadonlySet<RichTextFeature>): AnyExtension[];
|
|
7
|
-
export declare function createEditorExtensions(blocks?: BlockRegistry | BlockDefinition[], schema?: ContentSchema, onActivateBlock?: BlockActivationCallback, extensions?: AnyExtension[]): AnyExtension[];
|
|
8
|
+
export declare function createEditorExtensions(blocks?: BlockRegistry | BlockDefinition[], schema?: ContentSchema, onActivateBlock?: BlockActivationCallback, extensions?: AnyExtension[], imagePreviews?: ImagePreviews): AnyExtension[];
|
package/dist/shared/tiptap.js
CHANGED
|
@@ -7,6 +7,7 @@ import { DEFAULT_MARKS, resolveRegistry } from '../core/registry.js';
|
|
|
7
7
|
import { coerceAttributeValue, normalizeBlockAttributes, serializeBlockAttributes } from '../core/attributes.js';
|
|
8
8
|
import { lowlight } from './syntaxHighlight.js';
|
|
9
9
|
import { sanitizeHref } from '../render/sanitize.js';
|
|
10
|
+
import { withImagePreviews, withoutImagePreviews } from './imagePreviews.js';
|
|
10
11
|
function safeParseJSON(raw) {
|
|
11
12
|
if (!raw)
|
|
12
13
|
return {};
|
|
@@ -21,9 +22,10 @@ function safeParseJSON(raw) {
|
|
|
21
22
|
export function getBlockDefaultAttrs(block) {
|
|
22
23
|
return normalizeBlockAttributes(block, {});
|
|
23
24
|
}
|
|
24
|
-
function buildBlockEditorProps(block, node, editor, onActivate, getPos) {
|
|
25
|
+
function buildBlockEditorProps(block, node, editor, onActivate, getPos, imagePreviews) {
|
|
26
|
+
const attrs = node.attrs ?? {};
|
|
25
27
|
return {
|
|
26
|
-
attrs:
|
|
28
|
+
attrs: imagePreviews ? withImagePreviews(block, attrs, imagePreviews) : attrs,
|
|
27
29
|
content: (node.content?.toJSON() ?? []),
|
|
28
30
|
blockId: block.id,
|
|
29
31
|
label: block.label,
|
|
@@ -52,7 +54,8 @@ function buildBlockEditorProps(block, node, editor, onActivate, getPos) {
|
|
|
52
54
|
const current = editor.state.doc.nodeAt(pos);
|
|
53
55
|
if (!current)
|
|
54
56
|
return;
|
|
55
|
-
|
|
57
|
+
const stored = imagePreviews ? withoutImagePreviews(block, attrs, imagePreviews) : attrs;
|
|
58
|
+
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, ...stored }));
|
|
56
59
|
},
|
|
57
60
|
// ProseMirror's getPos can return undefined when the node is not currently
|
|
58
61
|
// in the document (e.g. mid-transaction); skip activation in that case
|
|
@@ -66,7 +69,7 @@ function buildBlockEditorProps(block, node, editor, onActivate, getPos) {
|
|
|
66
69
|
: undefined
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
|
-
function mountBlockEditorComponent(block, node, container, contentDOM, mounted, editor, onActivate, getPos) {
|
|
72
|
+
function mountBlockEditorComponent(block, node, container, contentDOM, mounted, editor, onActivate, getPos, imagePreviews) {
|
|
70
73
|
mounted?.destroy();
|
|
71
74
|
const createEditorMount = block.components.editor.plugin.createEditorMount;
|
|
72
75
|
if (!createEditorMount) {
|
|
@@ -77,7 +80,7 @@ function mountBlockEditorComponent(block, node, container, contentDOM, mounted,
|
|
|
77
80
|
inline: block.behaviors.inline ?? false,
|
|
78
81
|
component: block.components.editor,
|
|
79
82
|
contentDOM,
|
|
80
|
-
props: buildBlockEditorProps(block, node, editor, onActivate, getPos)
|
|
83
|
+
props: buildBlockEditorProps(block, node, editor, onActivate, getPos, imagePreviews)
|
|
81
84
|
});
|
|
82
85
|
}
|
|
83
86
|
function isDragHandleEvent(event) {
|
|
@@ -90,7 +93,7 @@ function isInteractiveNodeViewEvent(event) {
|
|
|
90
93
|
return false;
|
|
91
94
|
return Boolean(target.closest('input, textarea, select, button:not([data-drag-handle]), a[href]'));
|
|
92
95
|
}
|
|
93
|
-
function createBlockNodeView(block, node, getPos, onActivate, editor) {
|
|
96
|
+
function createBlockNodeView(block, node, getPos, onActivate, editor, imagePreviews) {
|
|
94
97
|
const dom = document.createElement(block.behaviors.inline ? 'span' : 'div');
|
|
95
98
|
dom.className = 'uncial-nodeview';
|
|
96
99
|
dom.dataset.uncialBlockId = block.id;
|
|
@@ -111,7 +114,7 @@ function createBlockNodeView(block, node, getPos, onActivate, editor) {
|
|
|
111
114
|
contentDOM.className = 'uncial-nodeview-content';
|
|
112
115
|
}
|
|
113
116
|
let mounted = null;
|
|
114
|
-
mounted = mountBlockEditorComponent(block, node, dom, contentDOM, mounted, editor, onActivate, getPos);
|
|
117
|
+
mounted = mountBlockEditorComponent(block, node, dom, contentDOM, mounted, editor, onActivate, getPos, imagePreviews);
|
|
115
118
|
syncBlockPosition();
|
|
116
119
|
return {
|
|
117
120
|
dom,
|
|
@@ -136,12 +139,12 @@ function createBlockNodeView(block, node, getPos, onActivate, editor) {
|
|
|
136
139
|
// reach it — the block would keep rendering its old attributes until
|
|
137
140
|
// something else re-rendered it. A microtask is outside that window
|
|
138
141
|
// and still lands before paint.
|
|
139
|
-
const nextProps = buildBlockEditorProps(block, nextNode, editor, onActivate, getPos);
|
|
142
|
+
const nextProps = buildBlockEditorProps(block, nextNode, editor, onActivate, getPos, imagePreviews);
|
|
140
143
|
queueMicrotask(() => mounted?.update?.(nextProps));
|
|
141
144
|
}
|
|
142
145
|
else {
|
|
143
146
|
// Fall back to a full remount for runtimes without update support.
|
|
144
|
-
mounted = mountBlockEditorComponent(block, nextNode, dom, contentDOM, mounted, editor, onActivate, getPos);
|
|
147
|
+
mounted = mountBlockEditorComponent(block, nextNode, dom, contentDOM, mounted, editor, onActivate, getPos, imagePreviews);
|
|
145
148
|
}
|
|
146
149
|
return true;
|
|
147
150
|
},
|
|
@@ -186,7 +189,7 @@ function containerContentExpression(content) {
|
|
|
186
189
|
return 'block*';
|
|
187
190
|
}
|
|
188
191
|
}
|
|
189
|
-
function createBlockNodeExtension(block, onActivate) {
|
|
192
|
+
function createBlockNodeExtension(block, onActivate, imagePreviews) {
|
|
190
193
|
const isContainer = Boolean(block.content);
|
|
191
194
|
return Node.create({
|
|
192
195
|
name: block.id,
|
|
@@ -223,7 +226,7 @@ function createBlockNodeExtension(block, onActivate) {
|
|
|
223
226
|
return [{ tag: block.html?.parseTag ?? `div[data-uncial-block="${block.id}"]` }];
|
|
224
227
|
},
|
|
225
228
|
addNodeView() {
|
|
226
|
-
return ({ node, getPos, editor }) => createBlockNodeView(block, node, getPos, onActivate, editor);
|
|
229
|
+
return ({ node, getPos, editor }) => createBlockNodeView(block, node, getPos, onActivate, editor, imagePreviews);
|
|
227
230
|
},
|
|
228
231
|
renderHTML({ HTMLAttributes, node }) {
|
|
229
232
|
const normalizedAttrs = normalizeBlockAttributes(block, node.attrs ?? {});
|
|
@@ -375,11 +378,11 @@ export function createRichTextExtensions(features) {
|
|
|
375
378
|
...(features.has('codeBlock') ? [CodeBlockLowlight.configure({ lowlight })] : [])
|
|
376
379
|
];
|
|
377
380
|
}
|
|
378
|
-
export function createEditorExtensions(blocks = [], schema, onActivateBlock, extensions = []) {
|
|
381
|
+
export function createEditorExtensions(blocks = [], schema, onActivateBlock, extensions = [], imagePreviews) {
|
|
379
382
|
const registry = resolveRegistry(blocks);
|
|
380
383
|
const blockExtensions = registry.blocks
|
|
381
384
|
.filter((block) => !schema || schema.allowedBlocks.has(block.id))
|
|
382
|
-
.map((block) => createBlockNodeExtension(block, onActivateBlock));
|
|
385
|
+
.map((block) => createBlockNodeExtension(block, onActivateBlock, imagePreviews));
|
|
383
386
|
return [
|
|
384
387
|
...createBaseExtensions(schema),
|
|
385
388
|
createDocumentIdentityExtension(registry),
|
package/dist/styles/base.css
CHANGED
|
@@ -396,6 +396,25 @@
|
|
|
396
396
|
gap: var(--uncial-space-2);
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
+
.uncial-image-field {
|
|
400
|
+
display: grid;
|
|
401
|
+
gap: var(--uncial-space-2);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.uncial-image-field__thumbnail {
|
|
405
|
+
max-width: 100%;
|
|
406
|
+
max-height: 8rem;
|
|
407
|
+
object-fit: contain;
|
|
408
|
+
justify-self: start;
|
|
409
|
+
border: 1px solid var(--uncial-color-border);
|
|
410
|
+
border-radius: var(--uncial-radius-lg);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.uncial-image-field__actions {
|
|
414
|
+
display: flex;
|
|
415
|
+
gap: var(--uncial-space-2);
|
|
416
|
+
}
|
|
417
|
+
|
|
399
418
|
.uncial-list-item {
|
|
400
419
|
border: 1px solid var(--uncial-color-border);
|
|
401
420
|
border-radius: var(--uncial-radius-lg);
|
|
@@ -471,16 +490,18 @@
|
|
|
471
490
|
-1 *
|
|
472
491
|
(
|
|
473
492
|
max(
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
493
|
+
var(--uncial-gutter-width-sm),
|
|
494
|
+
var(--uncial-reserved-gutter-width, var(--uncial-gutter-width-sm))
|
|
495
|
+
) -
|
|
496
|
+
0.5rem
|
|
477
497
|
)
|
|
478
498
|
);
|
|
479
499
|
width: calc(
|
|
480
500
|
max(
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
501
|
+
var(--uncial-gutter-width-sm),
|
|
502
|
+
var(--uncial-reserved-gutter-width, var(--uncial-gutter-width-sm))
|
|
503
|
+
) -
|
|
504
|
+
1rem
|
|
484
505
|
);
|
|
485
506
|
}
|
|
486
507
|
|
|
@@ -488,9 +509,10 @@
|
|
|
488
509
|
font-size: 0.5rem;
|
|
489
510
|
max-width: calc(
|
|
490
511
|
max(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
512
|
+
var(--uncial-gutter-width-sm),
|
|
513
|
+
var(--uncial-reserved-gutter-width, var(--uncial-gutter-width-sm))
|
|
514
|
+
) -
|
|
515
|
+
1rem
|
|
494
516
|
);
|
|
495
517
|
}
|
|
496
518
|
|
|
@@ -600,3 +622,61 @@
|
|
|
600
622
|
border-top: 1px solid var(--uncial-color-border);
|
|
601
623
|
}
|
|
602
624
|
}
|
|
625
|
+
|
|
626
|
+
.uncial-image-picker {
|
|
627
|
+
width: min(40rem, calc(100vw - 2rem));
|
|
628
|
+
max-height: calc(100vh - 4rem);
|
|
629
|
+
padding: var(--uncial-space-4);
|
|
630
|
+
border: 1px solid var(--uncial-color-border);
|
|
631
|
+
border-radius: var(--uncial-radius-lg);
|
|
632
|
+
background: var(--uncial-color-surface);
|
|
633
|
+
color: var(--uncial-color-text);
|
|
634
|
+
box-shadow: var(--uncial-shadow-md);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
.uncial-image-picker::backdrop {
|
|
638
|
+
background: color-mix(in srgb, black 40%, transparent);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
.uncial-image-picker__head {
|
|
642
|
+
display: flex;
|
|
643
|
+
align-items: center;
|
|
644
|
+
justify-content: space-between;
|
|
645
|
+
margin-bottom: var(--uncial-space-3);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
.uncial-image-picker__head h2 {
|
|
649
|
+
margin: 0;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
.uncial-image-picker__grid {
|
|
653
|
+
display: grid;
|
|
654
|
+
grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
|
|
655
|
+
gap: var(--uncial-space-2);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
.uncial-image-picker__tile {
|
|
659
|
+
aspect-ratio: 1;
|
|
660
|
+
padding: 0;
|
|
661
|
+
overflow: hidden;
|
|
662
|
+
border: 1px solid var(--uncial-color-border);
|
|
663
|
+
border-radius: var(--uncial-radius-md);
|
|
664
|
+
background: var(--uncial-color-surface-elevated);
|
|
665
|
+
cursor: pointer;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
.uncial-image-picker__tile:focus-visible {
|
|
669
|
+
outline: 2px solid var(--uncial-color-focus-ring);
|
|
670
|
+
outline-offset: 2px;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
.uncial-image-picker__tile[aria-pressed='true'] {
|
|
674
|
+
border-color: var(--uncial-color-primary);
|
|
675
|
+
box-shadow: 0 0 0 2px var(--uncial-color-primary);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
.uncial-image-picker__tile img {
|
|
679
|
+
width: 100%;
|
|
680
|
+
height: 100%;
|
|
681
|
+
object-fit: cover;
|
|
682
|
+
}
|
package/dist/styles/controls.css
CHANGED
|
@@ -135,10 +135,15 @@
|
|
|
135
135
|
color: var(--uncial-color-text-muted);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
.uncial-field__error
|
|
138
|
+
.uncial-field__error,
|
|
139
|
+
.uncial-field__warning {
|
|
139
140
|
font-size: 0.75rem;
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
.uncial-field__warning {
|
|
144
|
+
color: var(--uncial-color-accent);
|
|
145
|
+
}
|
|
146
|
+
|
|
142
147
|
.uncial-input,
|
|
143
148
|
.uncial-select,
|
|
144
149
|
.uncial-textarea {
|
package/dist/ui/theme.svelte.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import Editor from '../editor/Editor.svelte';
|
|
4
4
|
import type {
|
|
5
5
|
BlockAttributesController,
|
|
6
|
+
ImageSource,
|
|
6
7
|
ToolbarFeature,
|
|
7
8
|
ToolbarFeatureSelection
|
|
8
9
|
} from '../editor/index.js';
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
attributesController?: BlockAttributesController | null;
|
|
29
30
|
attributesPanel?: boolean | 'docked' | 'overlay' | 'off';
|
|
30
31
|
presentation?: 'card' | 'bare';
|
|
32
|
+
imageSource?: ImageSource;
|
|
31
33
|
onIssue?: (issue: ValidationIssue) => void;
|
|
32
34
|
onChange?: (document: JSONContent) => void;
|
|
33
35
|
onMetaChange?: (meta: Record<string, unknown>) => void;
|
|
@@ -45,6 +47,7 @@
|
|
|
45
47
|
attributesController = null,
|
|
46
48
|
attributesPanel = true,
|
|
47
49
|
presentation = 'card',
|
|
50
|
+
imageSource,
|
|
48
51
|
onIssue,
|
|
49
52
|
onChange,
|
|
50
53
|
onMetaChange
|
|
@@ -70,6 +73,7 @@
|
|
|
70
73
|
{attributesController}
|
|
71
74
|
{attributesPanel}
|
|
72
75
|
{presentation}
|
|
76
|
+
{imageSource}
|
|
73
77
|
onIssue={dispatchIssue}
|
|
74
78
|
{onChange}
|
|
75
79
|
{onMetaChange}
|