uncial 2.0.1 → 2.0.3
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.
|
@@ -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.
|