uncial 2.0.0 → 2.0.2
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/editor/BlockAttributesPanel.svelte +8 -2
- package/dist/shared/EditorBlockFixture.svelte +16 -2
- package/dist/shared/EditorBlockFixture.svelte.d.ts +3 -1
- package/dist/shared/tiptap.js +21 -1
- package/dist/styles/base.css +8 -1
- package/dist/styles/controls.css +2 -0
- package/package.json +3 -2
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
});
|
|
82
82
|
let draggingChildIndex = $state<number | null>(null);
|
|
83
83
|
let draggingPointerId = $state<number | null>(null);
|
|
84
|
+
let panelElement = $state<HTMLElement>();
|
|
84
85
|
|
|
85
86
|
function moveUp(index: number): void {
|
|
86
87
|
if (index > 0) controller.moveContainerChild(index, index - 1);
|
|
@@ -129,7 +130,12 @@
|
|
|
129
130
|
|
|
130
131
|
function handleChildDragMove(event: PointerEvent): void {
|
|
131
132
|
if (draggingChildIndex === null || draggingPointerId !== event.pointerId) return;
|
|
132
|
-
|
|
133
|
+
// Hit-test from the panel's own root: inside the web component's shadow
|
|
134
|
+
// tree, `document.elementFromPoint` retargets to the host element and the
|
|
135
|
+
// list items are never found.
|
|
136
|
+
const root = panelElement?.getRootNode();
|
|
137
|
+
const scope = root instanceof ShadowRoot ? root : document;
|
|
138
|
+
const target = scope
|
|
133
139
|
.elementFromPoint(event.clientX, event.clientY)
|
|
134
140
|
?.closest('[data-child-index]');
|
|
135
141
|
if (!(target instanceof HTMLElement)) return;
|
|
@@ -161,7 +167,7 @@
|
|
|
161
167
|
onpointercancel={stopChildDrag}
|
|
162
168
|
/>
|
|
163
169
|
|
|
164
|
-
<div class="uncial-attrs-panel">
|
|
170
|
+
<div class="uncial-attrs-panel" bind:this={panelElement}>
|
|
165
171
|
{#if controllerState.link.open}
|
|
166
172
|
<LinkAttributesPanel
|
|
167
173
|
attrs={controllerState.link.attrs}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type UpdateAttributes = (attrs: Record<string, unknown>) => void;
|
|
3
|
+
|
|
4
|
+
// Lets a test reach one block instance's `updateAttributes` prop directly,
|
|
5
|
+
// keyed by that instance's root element, without going through a control
|
|
6
|
+
// whose own focus or selection side effects would confuse the assertion.
|
|
7
|
+
export const fixtureUpdateAttributes = new WeakMap<Element, UpdateAttributes>();
|
|
8
|
+
</script>
|
|
9
|
+
|
|
1
10
|
<script lang="ts">
|
|
2
11
|
// Test fixture: a custom block editor component with an attribute-bound input.
|
|
3
12
|
import type { Snippet } from 'svelte';
|
|
@@ -5,13 +14,18 @@
|
|
|
5
14
|
interface Props {
|
|
6
15
|
title?: string;
|
|
7
16
|
children?: Snippet;
|
|
8
|
-
updateAttributes?:
|
|
17
|
+
updateAttributes?: UpdateAttributes;
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
let { title = '', children, updateAttributes }: Props = $props();
|
|
12
21
|
</script>
|
|
13
22
|
|
|
14
|
-
<div
|
|
23
|
+
<div
|
|
24
|
+
data-testid="editor-block-fixture"
|
|
25
|
+
{@attach (node) => {
|
|
26
|
+
if (updateAttributes) fixtureUpdateAttributes.set(node, updateAttributes);
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
15
29
|
<input
|
|
16
30
|
data-testid="title-input"
|
|
17
31
|
value={title}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export type UpdateAttributes = (attrs: Record<string, unknown>) => void;
|
|
2
|
+
export declare const fixtureUpdateAttributes: WeakMap<Element, UpdateAttributes>;
|
|
1
3
|
import type { Snippet } from 'svelte';
|
|
2
4
|
interface Props {
|
|
3
5
|
title?: string;
|
|
4
6
|
children?: Snippet;
|
|
5
|
-
updateAttributes?:
|
|
7
|
+
updateAttributes?: UpdateAttributes;
|
|
6
8
|
}
|
|
7
9
|
declare const EditorBlockFixture: import("svelte").Component<Props, {}, "">;
|
|
8
10
|
type EditorBlockFixture = ReturnType<typeof EditorBlockFixture>;
|
package/dist/shared/tiptap.js
CHANGED
|
@@ -28,12 +28,32 @@ function buildBlockEditorProps(block, node, editor, onActivate, getPos) {
|
|
|
28
28
|
blockId: block.id,
|
|
29
29
|
label: block.label,
|
|
30
30
|
draggable: block.behaviors.draggable ?? true,
|
|
31
|
+
// Addressed by position, not by selection: Tiptap's `updateAttributes`
|
|
32
|
+
// command writes to the node at the current selection, and nothing in a
|
|
33
|
+
// block's own component moves the selection onto it, so the write would
|
|
34
|
+
// land on whichever block the reader last selected.
|
|
35
|
+
//
|
|
31
36
|
// Deliberately no `.focus()` here: updates often originate from form
|
|
32
37
|
// controls inside the block component, and refocusing the editor view
|
|
33
38
|
// would steal focus from them on every keystroke.
|
|
34
39
|
updateAttributes: block.readOnly
|
|
35
40
|
? undefined
|
|
36
|
-
: (attrs) =>
|
|
41
|
+
: (attrs) => {
|
|
42
|
+
if (!editor || !getPos)
|
|
43
|
+
return;
|
|
44
|
+
// Same guard as `onActivate` below.
|
|
45
|
+
const pos = getPos();
|
|
46
|
+
if (pos === undefined)
|
|
47
|
+
return;
|
|
48
|
+
// Read the node from the live document rather than the `node`
|
|
49
|
+
// captured when these props were built: that capture is stale as
|
|
50
|
+
// soon as any attribute has been written, and merging over it
|
|
51
|
+
// would drop earlier writes.
|
|
52
|
+
const current = editor.state.doc.nodeAt(pos);
|
|
53
|
+
if (!current)
|
|
54
|
+
return;
|
|
55
|
+
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, ...attrs }));
|
|
56
|
+
},
|
|
37
57
|
// ProseMirror's getPos can return undefined when the node is not currently
|
|
38
58
|
// in the document (e.g. mid-transaction); skip activation in that case
|
|
39
59
|
// rather than reporting a bogus position.
|
package/dist/styles/base.css
CHANGED
|
@@ -60,14 +60,21 @@
|
|
|
60
60
|
overflow-y: auto;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/* Pinned to the top of the screen so the controls stay in reach however far
|
|
64
|
+
down a long document the caret sits. Opaque, because the document scrolls
|
|
65
|
+
beneath it; layered above the block handles (z 10) and below the overlay
|
|
66
|
+
sidebar (z 30). */
|
|
63
67
|
.uncial-toolbar {
|
|
64
68
|
grid-area: toolbar;
|
|
69
|
+
position: sticky;
|
|
70
|
+
top: 0;
|
|
71
|
+
z-index: 20;
|
|
65
72
|
display: flex;
|
|
66
73
|
flex-wrap: wrap;
|
|
67
74
|
align-items: center;
|
|
68
75
|
gap: var(--uncial-toolbar-gap);
|
|
69
76
|
border-bottom: 1px solid var(--uncial-color-border);
|
|
70
|
-
background:
|
|
77
|
+
background: var(--uncial-color-surface-elevated);
|
|
71
78
|
padding: var(--uncial-space-2) var(--uncial-space-3);
|
|
72
79
|
}
|
|
73
80
|
|
package/dist/styles/controls.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uncial",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"./styles/base": "./dist/styles/base.css",
|
|
55
55
|
"./styles/controls": "./dist/styles/controls.css",
|
|
56
56
|
"./styles/prose": "./dist/styles/prose.css",
|
|
57
|
+
"./styles/*.css": "./dist/styles/*.css",
|
|
57
58
|
"./runtime/svelte": {
|
|
58
59
|
"types": "./dist/runtime/svelte.d.ts",
|
|
59
60
|
"svelte": "./dist/runtime/svelte.js",
|
|
@@ -119,7 +120,7 @@
|
|
|
119
120
|
"dev": "vite dev",
|
|
120
121
|
"build": "vite build",
|
|
121
122
|
"preview": "vite preview",
|
|
122
|
-
"package": "svelte-kit sync && svelte-package",
|
|
123
|
+
"package": "svelte-kit sync && svelte-package --tsconfig ./tsconfig.package.json",
|
|
123
124
|
"changeset": "changeset",
|
|
124
125
|
"version": "changeset version",
|
|
125
126
|
"release": "pnpm run prepack && changeset publish",
|