@aionbuilders/nabu 0.1.0-alpha.7 → 0.1.0-alpha.9
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/blocks/Block.svelte +3 -3
- package/dist/blocks/BlockGap.svelte +55 -0
- package/dist/blocks/BlockGap.svelte.d.ts +11 -0
- package/dist/blocks/index.d.ts +1 -0
- package/dist/blocks/index.js +1 -0
- package/dist/blocks/nabu.svelte.js +20 -25
- package/dist/blocks/paragraph/index.js +8 -0
- package/dist/blocks/selection.svelte.d.ts +1 -0
- package/dist/blocks/selection.svelte.js +202 -16
- package/dist/blocks/zone/Zone.svelte +258 -0
- package/dist/blocks/zone/Zone.svelte.d.ts +11 -0
- package/dist/blocks/zone/index.d.ts +2 -0
- package/dist/blocks/zone/index.js +2 -0
- package/dist/blocks/zone/zone.extension.d.ts +2 -0
- package/dist/blocks/zone/zone.extension.js +221 -0
- package/dist/blocks/zone/zone.svelte.d.ts +112 -0
- package/dist/blocks/zone/zone.svelte.js +321 -0
- package/dist/presets.js +2 -1
- package/package.json +1 -1
package/dist/blocks/Block.svelte
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import BlockGap from './BlockGap.svelte';
|
|
3
|
+
|
|
2
4
|
/** @type {{ block: import('./block.svelte.js').Block }} */
|
|
3
5
|
let { block } = $props();
|
|
4
6
|
|
|
@@ -8,11 +10,9 @@
|
|
|
8
10
|
</script>
|
|
9
11
|
|
|
10
12
|
{#if Component}
|
|
11
|
-
<!-- On passe l'instance du bloc au composant spécifique -->
|
|
12
13
|
<Component {block} />
|
|
13
14
|
{:else}
|
|
14
|
-
<!-- Fallback pour les types inconnus (utile en dev) -->
|
|
15
15
|
<div style="color: red; border: 1px dashed red; padding: 0.5rem; margin: 0.5rem 0;" contenteditable="false">
|
|
16
16
|
⚠️ Unknown block type: <strong>{block.type}</strong>
|
|
17
17
|
</div>
|
|
18
|
-
{/if}
|
|
18
|
+
{/if}<BlockGap {block} />
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {{ block: import('./block.svelte.js').Block }} */
|
|
3
|
+
let { block } = $props();
|
|
4
|
+
|
|
5
|
+
function onclick() {
|
|
6
|
+
const parentId = block.parent?.node.id.toString() ?? null;
|
|
7
|
+
const insertIndex = block.index + 1;
|
|
8
|
+
block.nabu.exec('gap:click', { parentId, insertIndex });
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
|
|
13
|
+
<div
|
|
14
|
+
class="nabu-block-gap"
|
|
15
|
+
contenteditable="false"
|
|
16
|
+
data-nabu-inert
|
|
17
|
+
aria-hidden="true"
|
|
18
|
+
{onclick}
|
|
19
|
+
>
|
|
20
|
+
<div class="nabu-block-gap-line"></div>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<style>
|
|
24
|
+
.nabu-block-gap {
|
|
25
|
+
position: relative;
|
|
26
|
+
height: 0.75rem;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
user-select: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.nabu-block-gap-line {
|
|
32
|
+
position: absolute;
|
|
33
|
+
inset: 50% 0 auto 0;
|
|
34
|
+
transform: translateY(-50%);
|
|
35
|
+
height: 1px;
|
|
36
|
+
background: color-mix(in srgb, currentColor 20%, transparent);
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
opacity: 0;
|
|
41
|
+
transition: opacity 0.15s;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.nabu-block-gap:hover .nabu-block-gap-line {
|
|
45
|
+
opacity: 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.nabu-block-gap-plus {
|
|
49
|
+
font-size: 0.6rem;
|
|
50
|
+
line-height: 1;
|
|
51
|
+
background: white;
|
|
52
|
+
padding: 0 0.25rem;
|
|
53
|
+
color: #aaa;
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default BlockGap;
|
|
2
|
+
type BlockGap = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const BlockGap: import("svelte").Component<{
|
|
7
|
+
block: import("./block.svelte.js").Block;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./block.svelte.js").Block;
|
|
11
|
+
};
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./paragraph";
|
|
|
7
7
|
export * from "./heading";
|
|
8
8
|
export * from "./list";
|
|
9
9
|
export * from "./dialogue";
|
|
10
|
+
export * from "./zone";
|
|
10
11
|
export * from "./selection.svelte.js";
|
|
11
12
|
export { default as NabuEditor } from "./Nabu.svelte";
|
|
12
13
|
export { default as BlockComponent } from "./Block.svelte";
|
package/dist/blocks/index.js
CHANGED
|
@@ -461,24 +461,29 @@ export class Nabu {
|
|
|
461
461
|
const startFrom = this.selection.start?.from ?? 0;
|
|
462
462
|
const endTo = this.selection.end?.to ?? null;
|
|
463
463
|
|
|
464
|
-
// Find the
|
|
465
|
-
//
|
|
466
|
-
//
|
|
467
|
-
//
|
|
468
|
-
|
|
469
|
-
|
|
464
|
+
// Find the root block(s) to serialize.
|
|
465
|
+
// - Same block: serialize it directly (partial 'both'). Going up to its parent
|
|
466
|
+
// would wrap it in its container (e.g. List), producing a fragment with children
|
|
467
|
+
// that bypasses the inline paste path on the receiving end.
|
|
468
|
+
// - Cross-block: use LCA so nested containers are serialized as a unit.
|
|
469
|
+
// - LCA is null: selection spans root-level blocks, fall back to nabu-level slice.
|
|
470
470
|
/** @type {Block[]} */
|
|
471
471
|
let rootBlocks;
|
|
472
|
-
if (
|
|
473
|
-
rootBlocks = [
|
|
472
|
+
if (startBlock === endBlock) {
|
|
473
|
+
rootBlocks = [startBlock];
|
|
474
474
|
} else {
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
475
|
+
const lca = findLCA(startBlock, endBlock);
|
|
476
|
+
if (lca) {
|
|
477
|
+
rootBlocks = [/** @type {Block} */ (/** @type {any} */ (lca))];
|
|
478
|
+
} else {
|
|
479
|
+
const startRoot = findDirectChildOf(startBlock, this);
|
|
480
|
+
const endRoot = findDirectChildOf(endBlock, this);
|
|
481
|
+
if (!startRoot || !endRoot) return;
|
|
482
|
+
const si = this.children.indexOf(startRoot);
|
|
483
|
+
const ei = this.children.indexOf(endRoot);
|
|
484
|
+
if (si === -1 || ei === -1) return;
|
|
485
|
+
rootBlocks = this.children.slice(si, ei + 1);
|
|
486
|
+
}
|
|
482
487
|
}
|
|
483
488
|
|
|
484
489
|
const lastI = rootBlocks.length - 1;
|
|
@@ -609,16 +614,6 @@ export class Nabu {
|
|
|
609
614
|
const delta = pb.delta || [];
|
|
610
615
|
const len = delta.reduce((s, op) => s + (typeof op.insert === 'string' ? op.insert.length : 0), 0);
|
|
611
616
|
|
|
612
|
-
// If the pasted block has a different type (e.g. heading pasted into paragraph),
|
|
613
|
-
// transform the anchor block in the same transaction before applying the delta.
|
|
614
|
-
if (pb.type !== anchorBlock.type) {
|
|
615
|
-
const data = /** @type {any} */ (anchorBlock.node.data);
|
|
616
|
-
data.set('type', pb.type);
|
|
617
|
-
for (const [key, value] of Object.entries(pb.props || {})) {
|
|
618
|
-
data.set(key, value);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
617
|
textBehavior.applyDelta([{ retain: offset }, ...delta]);
|
|
623
618
|
this.commit();
|
|
624
619
|
tick().then(() => this.selection.setCursor(anchorBlock, offset + len));
|
|
@@ -11,6 +11,14 @@ const ParagraphExtension = extension("paragraph", {
|
|
|
11
11
|
component: ParagraphComponent,
|
|
12
12
|
actions: {
|
|
13
13
|
'paragraph': (nabu) => nabu.exec('block:transform', { type: 'paragraph' }),
|
|
14
|
+
'gap:click': (nabu, data) => {
|
|
15
|
+
const { parentId = null, insertIndex = undefined } = data ?? {};
|
|
16
|
+
const newBlock = nabu.insert('paragraph', {}, parentId, insertIndex);
|
|
17
|
+
nabu.commit().then(() => {
|
|
18
|
+
const fresh = nabu.blocks.get(newBlock.id);
|
|
19
|
+
if (fresh) nabu.selection.setCursor(fresh, 0);
|
|
20
|
+
});
|
|
21
|
+
},
|
|
14
22
|
},
|
|
15
23
|
hooks: {
|
|
16
24
|
onInit: (nabu) => {
|
|
@@ -32,6 +32,7 @@ export class NabuSelection extends SvelteSelection {
|
|
|
32
32
|
*/
|
|
33
33
|
setCursor(block: Block, offset: number): void;
|
|
34
34
|
blocks: Set<Block>;
|
|
35
|
+
#private;
|
|
35
36
|
}
|
|
36
37
|
import { SvelteSelection } from "../utils/selection.svelte.js";
|
|
37
38
|
import type { Nabu } from "./nabu.svelte.js";
|
|
@@ -15,25 +15,101 @@ export class NabuSelection extends SvelteSelection {
|
|
|
15
15
|
|
|
16
16
|
$effect.root(() => {
|
|
17
17
|
$effect(() => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
if (this.blocks) {
|
|
19
|
+
this.previous.forEach(block => block.clearSelection());
|
|
20
|
+
let i = 0;
|
|
21
|
+
const lastIndex = this.blocks.size - 1;
|
|
22
|
+
this.blocks.forEach((block) => {
|
|
23
|
+
block.selected = true;
|
|
24
|
+
block.isSelectionStart = (i === 0);
|
|
25
|
+
block.isSelectionEnd = i === lastIndex;
|
|
26
|
+
i++;
|
|
27
|
+
});
|
|
28
|
+
this.previous = new Set(this.blocks);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
// Track the intended navigation direction from arrow key presses.
|
|
33
|
+
// This is the only reliable source of direction — DOM position comparisons
|
|
34
|
+
// break when anchorNode is an ancestor of the previous position.
|
|
35
|
+
$effect(() => {
|
|
36
|
+
/** @param {KeyboardEvent} e */
|
|
37
|
+
const onKeydown = (e) => {
|
|
38
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
|
39
|
+
this.#pendingDirection = 'forward';
|
|
40
|
+
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
|
41
|
+
this.#pendingDirection = 'backward';
|
|
42
|
+
} else {
|
|
43
|
+
this.#pendingDirection = null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
document.addEventListener('keydown', onKeydown, true);
|
|
47
|
+
return () => document.removeEventListener('keydown', onKeydown, true);
|
|
48
|
+
});
|
|
33
49
|
|
|
34
|
-
|
|
50
|
+
// Normalize invalid caret/focus positions: inert elements and element-node
|
|
51
|
+
// cursors (which happen in container padding / between block children).
|
|
52
|
+
// Works for both collapsed cursors and non-collapsed selections (shift+arrow):
|
|
53
|
+
// - anchor invalid → collapse to corrected anchor
|
|
54
|
+
// - only focus invalid → keep anchor, correct only focus (preserves the selection)
|
|
55
|
+
$effect(() => {
|
|
56
|
+
const activeEl = document.activeElement;
|
|
57
|
+
if (activeEl && activeEl.closest?.('[data-nabu-ui], input, textarea, select, button')) {
|
|
58
|
+
this.#pendingDirection = null;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const anchor = this.anchorNode;
|
|
63
|
+
const anchorOffset = this.anchorOffset;
|
|
64
|
+
const focus = this.focusNode;
|
|
65
|
+
const focusOffset = this.focusOffset;
|
|
66
|
+
if (!anchor) return;
|
|
67
|
+
|
|
68
|
+
const anchorEl = /** @type {Element | null} */ (anchor.nodeType === Node.ELEMENT_NODE ? anchor : anchor.parentElement);
|
|
69
|
+
const focusEl = /** @type {Element | null} */ (focus?.nodeType === Node.ELEMENT_NODE ? focus : focus?.parentElement);
|
|
70
|
+
|
|
71
|
+
// Skip normalization when the selection touches a UI element (e.g. zone title input).
|
|
72
|
+
if (anchorEl?.closest('[data-nabu-ui]') || focusEl?.closest('[data-nabu-ui]')) {
|
|
73
|
+
this.#pendingDirection = null;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const anchorInvalid = isInInert(anchor) || (
|
|
78
|
+
anchor.nodeType !== Node.TEXT_NODE &&
|
|
79
|
+
!!/** @type {Element} */ (anchor).closest?.('[data-block-id]')
|
|
80
|
+
);
|
|
81
|
+
const focusInvalid = !!focus && (isInInert(focus) || (
|
|
82
|
+
focus.nodeType !== Node.TEXT_NODE &&
|
|
83
|
+
!!/** @type {Element} */ (focus).closest?.('[data-block-id]')
|
|
84
|
+
));
|
|
85
|
+
|
|
86
|
+
if (!anchorInvalid && !focusInvalid) {
|
|
87
|
+
this.#pendingDirection = null;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (anchorInvalid) {
|
|
92
|
+
const dir = this.#pendingDirection ?? offsetHeuristic(anchor, anchorOffset);
|
|
93
|
+
this.#pendingDirection = null;
|
|
94
|
+
const target = findNearestTextNode(anchor, anchorOffset, dir);
|
|
95
|
+
if (!target) return;
|
|
96
|
+
const offset = dir === 'forward' ? 0 : (target.textContent?.length ?? 0);
|
|
97
|
+
this.setBaseAndExtent(target, offset, target, offset);
|
|
98
|
+
} else if (focusInvalid && focus) {
|
|
99
|
+
const dir = this.#pendingDirection ?? offsetHeuristic(focus, focusOffset);
|
|
100
|
+
this.#pendingDirection = null;
|
|
101
|
+
const target = findNearestTextNode(focus, focusOffset, dir);
|
|
102
|
+
if (!target) return;
|
|
103
|
+
const offset = dir === 'forward' ? 0 : (target.textContent?.length ?? 0);
|
|
104
|
+
this.setBaseAndExtent(anchor, anchorOffset, target, offset);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
35
108
|
}
|
|
36
|
-
|
|
109
|
+
|
|
110
|
+
/** @type {'forward' | 'backward' | null} */
|
|
111
|
+
#pendingDirection = null;
|
|
112
|
+
|
|
37
113
|
anchorBlock = $derived.by(() => {
|
|
38
114
|
this.anchorNode;
|
|
39
115
|
const id = this.anchorNode?.parentElement?.closest("[data-block-id]")?.getAttribute("data-block-id");
|
|
@@ -95,6 +171,116 @@ export class NabuSelection extends SvelteSelection {
|
|
|
95
171
|
|
|
96
172
|
|
|
97
173
|
|
|
174
|
+
/** @param {Node | null} node */
|
|
175
|
+
function isInInert(node) {
|
|
176
|
+
if (!node) return false;
|
|
177
|
+
const el = node.nodeType === Node.ELEMENT_NODE
|
|
178
|
+
? /** @type {Element} */ (node)
|
|
179
|
+
: node.parentElement;
|
|
180
|
+
return !!el?.closest('[data-nabu-inert]');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Heuristic for mouse clicks: infer direction from where in the element the
|
|
185
|
+
* cursor landed. At/past the last child → user likely moving forward; otherwise
|
|
186
|
+
* backward.
|
|
187
|
+
* @param {Node} anchor
|
|
188
|
+
* @param {number} anchorOffset
|
|
189
|
+
* @returns {'forward' | 'backward'}
|
|
190
|
+
*/
|
|
191
|
+
function offsetHeuristic(anchor, anchorOffset) {
|
|
192
|
+
if (anchor.nodeType !== Node.TEXT_NODE) {
|
|
193
|
+
return anchorOffset >= anchor.childNodes.length ? 'forward' : 'backward';
|
|
194
|
+
}
|
|
195
|
+
return 'backward';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @type {NodeFilter} */
|
|
199
|
+
const TEXT_FILTER = {
|
|
200
|
+
acceptNode(/** @type {Node} */ node) {
|
|
201
|
+
if (isInInert(node)) return NodeFilter.FILTER_REJECT;
|
|
202
|
+
if (!/** @type {Text} */ (node).parentElement?.closest('[data-block-id]')) return NodeFilter.FILTER_REJECT;
|
|
203
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns the deepest last descendant of a node (for positioning a TreeWalker
|
|
209
|
+
* so that nextNode() starts at the node immediately after the subtree).
|
|
210
|
+
* @param {Node} node
|
|
211
|
+
*/
|
|
212
|
+
function getLastDescendant(node) {
|
|
213
|
+
let n = node;
|
|
214
|
+
while (n.lastChild) n = n.lastChild;
|
|
215
|
+
return n;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Find the nearest valid (non-inert, inside a block) text node from a given
|
|
220
|
+
* DOM position, respecting the intended navigation direction.
|
|
221
|
+
*
|
|
222
|
+
* For element-node cursors, (fromNode, fromOffset) means the caret sits between
|
|
223
|
+
* child[fromOffset-1] and child[fromOffset]. We use fromOffset to start the
|
|
224
|
+
* search at the right position — NOT from the beginning/end of the element —
|
|
225
|
+
* so we never jump back to a position the user is trying to leave.
|
|
226
|
+
*
|
|
227
|
+
* @param {Node} fromNode
|
|
228
|
+
* @param {number} fromOffset
|
|
229
|
+
* @param {'forward' | 'backward'} direction
|
|
230
|
+
* @returns {Text | null}
|
|
231
|
+
*/
|
|
232
|
+
function findNearestTextNode(fromNode, fromOffset, direction) {
|
|
233
|
+
// @ts-ignore — TreeWalker filter shape is correct, TS typedef is overly strict
|
|
234
|
+
const bodyWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, TEXT_FILTER);
|
|
235
|
+
|
|
236
|
+
if (fromNode.nodeType === Node.TEXT_NODE) {
|
|
237
|
+
bodyWalker.currentNode = fromNode;
|
|
238
|
+
return /** @type {Text | null} */ (
|
|
239
|
+
direction === 'backward' ? bodyWalker.previousNode() : bodyWalker.nextNode()
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Element-node cursor: caret is between child[fromOffset-1] and child[fromOffset].
|
|
244
|
+
const childCount = fromNode.childNodes.length;
|
|
245
|
+
|
|
246
|
+
if (direction === 'backward') {
|
|
247
|
+
if (fromOffset === 0) {
|
|
248
|
+
// Before all children → escape before element
|
|
249
|
+
bodyWalker.currentNode = fromNode;
|
|
250
|
+
return /** @type {Text | null} */ (bodyWalker.previousNode());
|
|
251
|
+
}
|
|
252
|
+
if (fromOffset < childCount) {
|
|
253
|
+
// Between child[fromOffset-1] and child[fromOffset]:
|
|
254
|
+
// last valid text before child[fromOffset] (may be inside or before element)
|
|
255
|
+
bodyWalker.currentNode = fromNode.childNodes[fromOffset];
|
|
256
|
+
return /** @type {Text | null} */ (bodyWalker.previousNode());
|
|
257
|
+
}
|
|
258
|
+
// Past last child → last valid text inside the element (sub-walker), or before it
|
|
259
|
+
// @ts-ignore
|
|
260
|
+
const sub = document.createTreeWalker(fromNode, NodeFilter.SHOW_TEXT, TEXT_FILTER);
|
|
261
|
+
let last = null, n;
|
|
262
|
+
while ((n = sub.nextNode())) last = n;
|
|
263
|
+
if (last) return /** @type {Text} */ (last);
|
|
264
|
+
bodyWalker.currentNode = fromNode;
|
|
265
|
+
return /** @type {Text | null} */ (bodyWalker.previousNode());
|
|
266
|
+
} else {
|
|
267
|
+
if (fromOffset >= childCount) {
|
|
268
|
+
// Past last child → escape after element
|
|
269
|
+
bodyWalker.currentNode = getLastDescendant(fromNode);
|
|
270
|
+
return /** @type {Text | null} */ (bodyWalker.nextNode());
|
|
271
|
+
}
|
|
272
|
+
// Between child[fromOffset-1] and child[fromOffset]:
|
|
273
|
+
// first valid text at or after child[fromOffset] (may be inside or after element).
|
|
274
|
+
// Pivot to the last descendant of child[fromOffset-1] so nextNode() starts
|
|
275
|
+
// from child[fromOffset] onward — never re-entering already-visited content.
|
|
276
|
+
const pivot = fromOffset > 0
|
|
277
|
+
? getLastDescendant(fromNode.childNodes[fromOffset - 1])
|
|
278
|
+
: fromNode;
|
|
279
|
+
bodyWalker.currentNode = pivot;
|
|
280
|
+
return /** @type {Text | null} */ (bodyWalker.nextNode());
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
98
284
|
/**
|
|
99
285
|
* Récupère tous les nœuds situés entre deux nœuds dans un arbre Loro (version aplatie).
|
|
100
286
|
* L'ordre dans lequel on passe A et B n'a pas d'importance.
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Block from '../Block.svelte';
|
|
3
|
+
/** @type {{ block: import('./zone.svelte.js').ZoneBlock }} */
|
|
4
|
+
let { block } = $props();
|
|
5
|
+
|
|
6
|
+
let editing = $state(false);
|
|
7
|
+
let titleDraft = $state('');
|
|
8
|
+
/** @type {HTMLInputElement | null} */
|
|
9
|
+
let inputEl = $state(null);
|
|
10
|
+
|
|
11
|
+
// Ancestor zones, ordered from outermost to nearest parent
|
|
12
|
+
const ancestors = $derived.by(() => {
|
|
13
|
+
/** @type {import('./zone.svelte.js').ZoneBlock[]} */
|
|
14
|
+
const crumbs = [];
|
|
15
|
+
let p = block.parent;
|
|
16
|
+
while (p) {
|
|
17
|
+
if (p.type === 'zone') crumbs.unshift(/** @type {any} */ (p));
|
|
18
|
+
p = p.parent;
|
|
19
|
+
}
|
|
20
|
+
return crumbs;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function startEdit() {
|
|
24
|
+
titleDraft = block.title;
|
|
25
|
+
editing = true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function commitTitle() {
|
|
29
|
+
block.title = titleDraft.trim();
|
|
30
|
+
editing = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @param {KeyboardEvent} e */
|
|
34
|
+
function onKeydown(e) {
|
|
35
|
+
e.stopPropagation();
|
|
36
|
+
if (e.key === 'Enter' || e.key === 'Escape') {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
commitTitle();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {InputEvent} e */
|
|
43
|
+
function onBeforeInput(e) {
|
|
44
|
+
e.stopPropagation();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
$effect(() => {
|
|
48
|
+
if (editing && inputEl) {
|
|
49
|
+
inputEl.focus();
|
|
50
|
+
inputEl.select();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div
|
|
56
|
+
class="nabu-zone"
|
|
57
|
+
data-block-id={block.id}
|
|
58
|
+
data-block-type="zone"
|
|
59
|
+
data-zone-id={block.id}
|
|
60
|
+
data-zone-status={block.status}
|
|
61
|
+
>
|
|
62
|
+
{#each block.children as child (child.id)}
|
|
63
|
+
<Block block={child} />
|
|
64
|
+
{/each}<!--
|
|
65
|
+
Zone UI overlay: boundaries + title (contenteditable=false = hors-flux éditeur)
|
|
66
|
+
--><div class="nabu-zone-ui" contenteditable="false" aria-hidden="true" style="user-select: none;">
|
|
67
|
+
|
|
68
|
+
<!-- <div class="nabu-zone-boundary nabu-zone-boundary--top" data-nabu-inert></div> -->
|
|
69
|
+
<div class="nabu-zone-boundary nabu-zone-boundary--bottom" data-nabu-inert style="user-select: none;">
|
|
70
|
+
<div class="nabu-zone-close">
|
|
71
|
+
{#each ancestors as anc}
|
|
72
|
+
<span class="nabu-zone-close-sep">‹</span>
|
|
73
|
+
<span class="nabu-zone-close-crumb">{anc.title || '…'}</span>
|
|
74
|
+
{/each}
|
|
75
|
+
<span class="nabu-zone-close-sep">‹</span>
|
|
76
|
+
<span class="nabu-zone-close-current">{block.title || '…'}</span>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<div
|
|
81
|
+
class="nabu-zone-title"
|
|
82
|
+
data-nabu-ui
|
|
83
|
+
|
|
84
|
+
>
|
|
85
|
+
<span class="nabu-zone-crumb-sep">›</span>
|
|
86
|
+
{#if ancestors.length > 0}
|
|
87
|
+
<!-- Breadcrumb for nested zones -->
|
|
88
|
+
{#each ancestors as anc}
|
|
89
|
+
<span class="nabu-zone-crumb">{anc.title || '…'}</span>
|
|
90
|
+
<span class="nabu-zone-crumb-sep">›</span>
|
|
91
|
+
{/each}
|
|
92
|
+
{/if}
|
|
93
|
+
|
|
94
|
+
{#if editing}
|
|
95
|
+
<input
|
|
96
|
+
bind:this={inputEl}
|
|
97
|
+
bind:value={titleDraft}
|
|
98
|
+
class="nabu-zone-title-input"
|
|
99
|
+
placeholder="Titre de la zone…"
|
|
100
|
+
onblur={commitTitle}
|
|
101
|
+
onkeydown={onKeydown}
|
|
102
|
+
onbeforeinput={onBeforeInput}
|
|
103
|
+
/>
|
|
104
|
+
{:else}
|
|
105
|
+
<span class="nabu-zone-title-label" onclick={startEdit}>
|
|
106
|
+
{block.title || '+ Titre'}
|
|
107
|
+
</span>
|
|
108
|
+
{/if}
|
|
109
|
+
|
|
110
|
+
<span class="nabu-zone-meta">
|
|
111
|
+
<!-- <span class="nabu-zone-sep">·</span>
|
|
112
|
+
<span class="nabu-zone-status">{block.status}</span> -->
|
|
113
|
+
{#if block.wordCount > 0}
|
|
114
|
+
<span class="nabu-zone-sep">·</span>
|
|
115
|
+
<span class="nabu-zone-wc">{block.wordCount} mots</span>
|
|
116
|
+
{/if}
|
|
117
|
+
</span>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<style>
|
|
124
|
+
.nabu-zone {
|
|
125
|
+
margin: 1rem 0;
|
|
126
|
+
padding: 0.75rem 0;
|
|
127
|
+
position: relative;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.nabu-zone-ui {
|
|
131
|
+
position: absolute;
|
|
132
|
+
inset: 0;
|
|
133
|
+
pointer-events: none;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.nabu-zone-boundary {
|
|
137
|
+
position: absolute;
|
|
138
|
+
left: 0;
|
|
139
|
+
right: 0;
|
|
140
|
+
opacity: 0.6;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
.nabu-zone-boundary--bottom {
|
|
145
|
+
bottom: 0; display: flex; justify-content: flex-start; align-items: center;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.nabu-zone-close {
|
|
149
|
+
transform: translateY(50%);
|
|
150
|
+
display: flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
gap: 0;
|
|
153
|
+
line-height: 1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.nabu-zone-close-sep {
|
|
157
|
+
font-size: 0.6rem;
|
|
158
|
+
color: #ccc;
|
|
159
|
+
margin: 0 0.8em;
|
|
160
|
+
&:first-child {
|
|
161
|
+
margin-left: 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.nabu-zone-close-crumb {
|
|
166
|
+
font-size: 0.6rem;
|
|
167
|
+
color: #bbb;
|
|
168
|
+
letter-spacing: 0.04em;
|
|
169
|
+
&:first-child {
|
|
170
|
+
margin-left: 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.nabu-zone-close-current {
|
|
175
|
+
font-size: 0.6rem;
|
|
176
|
+
color: #aaa;
|
|
177
|
+
letter-spacing: 0.04em;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
[data-zone-status="revised"] .nabu-zone-boundary { background: #f59e0b; opacity: 0.35; }
|
|
181
|
+
[data-zone-status="done"] .nabu-zone-boundary { background: #10b981; opacity: 0.35; }
|
|
182
|
+
|
|
183
|
+
/* Title — flotte sur la boundary top */
|
|
184
|
+
.nabu-zone-title {
|
|
185
|
+
position: absolute;
|
|
186
|
+
top: 0;
|
|
187
|
+
transform: translateY(-50%);
|
|
188
|
+
pointer-events: all;
|
|
189
|
+
line-height: 1;
|
|
190
|
+
display: flex;
|
|
191
|
+
align-items: center;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.nabu-zone-title-label {
|
|
195
|
+
font-size: 0.6rem;
|
|
196
|
+
font-weight: 400;
|
|
197
|
+
letter-spacing: 0.04em;
|
|
198
|
+
color: #aaa;
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
user-select: none;
|
|
201
|
+
transition: color 0.15s;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.nabu-zone-title-label:hover {
|
|
205
|
+
color: #666;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.nabu-zone-title-input {
|
|
209
|
+
font-size: 0.7rem;
|
|
210
|
+
font-weight: 400;
|
|
211
|
+
letter-spacing: 0.04em;
|
|
212
|
+
color: #666;
|
|
213
|
+
border: none;
|
|
214
|
+
outline: none;
|
|
215
|
+
background: transparent;
|
|
216
|
+
padding: 0;
|
|
217
|
+
width: 14rem;
|
|
218
|
+
max-width: 40vw;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.nabu-zone-crumb {
|
|
222
|
+
font-size: 0.6rem;
|
|
223
|
+
font-weight: 400;
|
|
224
|
+
letter-spacing: 0.04em;
|
|
225
|
+
color: #bbb;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.nabu-zone-crumb-sep {
|
|
229
|
+
font-size: 0.6rem;
|
|
230
|
+
color: #ccc;
|
|
231
|
+
margin: 0 0.8em;
|
|
232
|
+
&:first-child {
|
|
233
|
+
margin-left: 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.nabu-zone-meta {
|
|
238
|
+
display: contents;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.nabu-zone-sep {
|
|
242
|
+
font-size: 0.6rem;
|
|
243
|
+
color: #ccc;
|
|
244
|
+
margin: 0 0.8em;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.nabu-zone-status {
|
|
248
|
+
font-size: 0.6rem;
|
|
249
|
+
color: #bbb;
|
|
250
|
+
letter-spacing: 0.04em;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.nabu-zone-wc {
|
|
254
|
+
font-size: 0.6rem;
|
|
255
|
+
color: #bbb;
|
|
256
|
+
letter-spacing: 0.04em;
|
|
257
|
+
}
|
|
258
|
+
</style>
|