svedit 0.13.0 → 0.15.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.
Files changed (42) hide show
  1. package/README.md +155 -1
  2. package/dist/NodeCaret.svelte +1 -1
  3. package/dist/NodeGapMarkers.svelte +17 -4
  4. package/dist/NodeGapMarkers.svelte.d.ts.map +1 -1
  5. package/dist/NodeSelectionMarkers.svelte +14 -3
  6. package/dist/Session.svelte.d.ts.map +1 -1
  7. package/dist/Session.svelte.js +17 -9
  8. package/dist/Svedit.svelte +101 -29
  9. package/dist/Svedit.svelte.d.ts.map +1 -1
  10. package/dist/TextProperty.svelte +5 -5
  11. package/dist/Transaction.svelte.d.ts +6 -2
  12. package/dist/Transaction.svelte.d.ts.map +1 -1
  13. package/dist/Transaction.svelte.js +7 -6
  14. package/dist/html_export.d.ts +11 -0
  15. package/dist/html_export.d.ts.map +1 -0
  16. package/dist/html_export.js +25 -0
  17. package/dist/html_paste.d.ts +59 -0
  18. package/dist/html_paste.d.ts.map +1 -0
  19. package/dist/html_paste.js +229 -0
  20. package/dist/html_utils.d.ts +4 -0
  21. package/dist/html_utils.d.ts.map +1 -0
  22. package/dist/html_utils.js +16 -0
  23. package/dist/index.d.ts +5 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -0
  26. package/dist/styles/svedit-colors.css +8 -5
  27. package/dist/types.d.ts +23 -1
  28. package/dist/types.d.ts.map +1 -1
  29. package/package.json +28 -26
  30. package/src/lib/NodeCaret.svelte +1 -1
  31. package/src/lib/NodeGapMarkers.svelte +17 -4
  32. package/src/lib/NodeSelectionMarkers.svelte +14 -3
  33. package/src/lib/Session.svelte.ts +16 -11
  34. package/src/lib/Svedit.svelte +101 -29
  35. package/src/lib/TextProperty.svelte +5 -5
  36. package/src/lib/Transaction.svelte.ts +12 -6
  37. package/src/lib/html_export.ts +37 -0
  38. package/src/lib/html_paste.ts +279 -0
  39. package/src/lib/html_utils.ts +17 -0
  40. package/src/lib/index.ts +15 -0
  41. package/src/lib/styles/svedit-colors.css +8 -5
  42. package/src/lib/types.ts +24 -1
package/README.md CHANGED
@@ -436,6 +436,138 @@ Defaults make it safe to add new defaultable properties, but they are not a repl
436
436
 
437
437
  Documents need a config object that tells Svedit how to render and manipulate your content. See the full example in [`src/routes/demo_config.ts`](src/routes/demo_config.ts).
438
438
 
439
+ ### Importing pasted HTML
440
+
441
+ Set `config.html_paste` to enable external HTML import. Without it, paste keeps its
442
+ existing plain-text behavior. Native Svedit clipboard data and media paste keep
443
+ their existing paths and bypass this importer.
444
+
445
+ ```ts
446
+ import type { HtmlPasteConfig } from 'svedit';
447
+
448
+ const html_paste: HtmlPasteConfig = {
449
+ blocks: {
450
+ p: { type: 'paragraph', text_property: 'content' },
451
+ h1: { type: 'heading1', text_property: 'content' },
452
+ h2: { type: 'heading2', text_property: 'content' }
453
+ },
454
+ marks: {
455
+ bold: { type: 'strong' },
456
+ link: ({ href }) => ({ type: 'link', properties: { href } })
457
+ }
458
+ };
459
+
460
+ const config = { /* other configuration */ html_paste };
461
+ ```
462
+
463
+ Use your app's schema names (the demo uses `heading_1`, for example). Blocks accept
464
+ `p` and `h1` through `h6`. Each mapping names a text node type and its text property.
465
+ A block mapping can also be a synchronous factory returning the same descriptor,
466
+ with extra node properties, or `null` to use the destination's default text node:
467
+
468
+ ```ts
469
+ h1: ({ tag }) => ({
470
+ type: 'heading',
471
+ text_property: 'content',
472
+ properties: { level: Number(tag.slice(1)) }
473
+ });
474
+ ```
475
+
476
+ `<strong>` and `<b>` use the `bold` mapping. Link factories receive the decoded,
477
+ trimmed `href`; they may return `null` to discard link formatting. The importer
478
+ accepts HTTP(S), mailto, tel, and relative links, and drops unsafe schemes.
479
+ Mappings describe data; they should not mutate the session. Svedit creates IDs
480
+ and fills schema defaults through its normal insertion transaction.
481
+
482
+ Map HTML lists separately because they contain an array of text nodes:
483
+
484
+ ```ts
485
+ html_paste.lists = {
486
+ ul: {
487
+ type: 'list',
488
+ children_property: 'list_items',
489
+ item: { type: 'list_item', text_property: 'content' },
490
+ properties: { layout: 'square' }
491
+ },
492
+ ol: {
493
+ type: 'list',
494
+ children_property: 'list_items',
495
+ item: { type: 'list_item', text_property: 'content' },
496
+ properties: { layout: 'decimal' }
497
+ }
498
+ };
499
+ ```
500
+
501
+ All type and property names come from your schema. Nested HTML lists flatten into
502
+ one list in item order, using the outer list's mapping. An item with multiple
503
+ paragraphs becomes one text node. Unmapped or disallowed lists fall back to the
504
+ destination's default text nodes; text fields receive flattened list text.
505
+
506
+ If a destination requires a containing block, configure an optional wrapper:
507
+
508
+ ```ts
509
+ html_paste.wrapper = { type: 'prose', children_property: 'body' };
510
+ ```
511
+
512
+ The wrapper is used only when blocks cannot be mapped directly to the destination
513
+ and the destination allows its type. Its `children_property` must be a node array;
514
+ blocks are mapped against that property's allowed node types. Wrapper mappings
515
+ also accept `properties` for schema-specific defaults.
516
+
517
+ Import respects the destination's allowed node and mark types. Unmapped or
518
+ disallowed headings fall back to its default text node; unsupported marks keep
519
+ their text. Marks are exclusive in Svedit, so a supported link takes precedence
520
+ over bold where they overlap. Existing active-mark insertion behavior still applies.
521
+
522
+ At a node caret, HTML blocks become nodes. A single text block pasted into text
523
+ retains the destination node type. A configured list follows the node insertion
524
+ path, even when it contains only one item. Multiple blocks pasted into a text node
525
+ follow the existing multi-paragraph behavior: insert nodes after that node without splitting
526
+ or replacing its text. In block fields such as titles and captions, blocks are
527
+ joined with blank lines, or spaces when `allow_newlines` is false.
528
+
529
+ The importer recognizes semantic tags, common block wrappers, entities and
530
+ `<br>`. Unsupported containers retain their text but do not import table
531
+ structure, images, or CSS formatting. Lists retain structure when a list mapping
532
+ is configured. Script/style content is ignored. Empty or
533
+ unusable HTML, and mapping errors, fall back to the existing plain-text path.
534
+
535
+ ### Exporting copied rich text
536
+
537
+ Copy and cut include both the embedded `data-svedit` payload and readable HTML.
538
+ Configure `mark_html_exporters` to map your schema's marks to HTML. Unknown marks
539
+ keep their text; data-only annotations remain in the native payload.
540
+
541
+ ```ts
542
+ import { export_text_html, escape_html, safe_html_href } from 'svedit';
543
+ import type { MarkHtmlExporter } from 'svedit';
544
+
545
+ const mark_html_exporters = {
546
+ strong: (_node, content) => `<strong>${content}</strong>`,
547
+ link: (node, content) => {
548
+ const href = safe_html_href(node.href || '');
549
+ return href ? `<a href="${escape_html(href)}">${content}</a>` : content;
550
+ }
551
+ } satisfies Record<string, MarkHtmlExporter>;
552
+
553
+ const config = {
554
+ mark_html_exporters,
555
+ html_exporters: {
556
+ paragraph: (node, session) => `<p>${export_text_html(node.content, session)}</p>`,
557
+ heading1: (node, session) => `<h1>${export_text_html(node.content, session)}</h1>`
558
+ }
559
+ };
560
+ ```
561
+
562
+ Text selections and the default node exporter use this automatically. Existing
563
+ custom `html_exporters` should call `export_text_html` for their text properties,
564
+ as above. The helper escapes text, preserves line breaks with `<br>`, and uses
565
+ Svedit's grapheme offsets. Mark exporters receive already escaped inline HTML;
566
+ only attribute values need escaping. Import and export mappings are separate
567
+ because import factories cannot be reliably reversed.
568
+
569
+ ### Custom handlers
570
+
439
571
  Two optional hooks are especially useful when integrating custom media workflows:
440
572
 
441
573
  - `handle_media_paste(session, pasted_media)`
@@ -481,6 +613,7 @@ const session_config = {
481
613
  - **`system_components`** - Optional overrides for internal editor components and a slot for your own overlays:
482
614
  - `overlays` — A Svelte component rendered inside `<Svedit>` but outside the content canvas. Use it to add floating UI like link editors, image toolbars, or annotation popovers that appear near the current selection. See [`src/routes/components/Overlays.svelte`](src/routes/components/Overlays.svelte) for an example.
483
615
  - `node_gap`, `node_gap_markers`, `node_selection_markers` — Override the default system components if you need custom visuals for node gaps or selection indicators.
616
+ - `node_gap_tools` — A component rendered inside the active node gap marker, next to the caret. Use it for gap-scoped tools like an insert button: it inherits the `--row` orientation variable from the node array, and it appears and disappears together with the caret. Receives `{ path, offset, is_first, is_last }` (see the `NodeGapToolsProps` type). The marker has `pointer-events: none`, so interactive tools must set `pointer-events: auto`. See [`src/routes/components/GapInsertTool.svelte`](src/routes/components/GapInsertTool.svelte) for an example.
484
617
  - **`inserters`** - Functions that create blank nodes of each type and set up the selection
485
618
  - **`create_commands_and_keymap`** - Factory function that creates commands and keybindings for an editor instance
486
619
  - **`handle_image_paste`** - Optional handler for image paste events
@@ -1174,7 +1307,7 @@ For styling, you usually don't need the props at all: `<Node>` adds range classe
1174
1307
 
1175
1308
  ```css
1176
1309
  .anno-marker {
1177
- background: color-mix(in oklch, var(--app-primary-fill) 13%, transparent);
1310
+ background: color-mix(in oklch, var(--accent) 13%, transparent);
1178
1311
  }
1179
1312
  ```
1180
1313
 
@@ -1452,12 +1585,33 @@ The source code is compact and readable — less than 3000 LOC across a handful
1452
1585
 
1453
1586
  ## Developing Svedit
1454
1587
 
1588
+ Development requires Node.js 22.17 or newer.
1589
+
1455
1590
  Once you've cloned the Svedit repository and installed dependencies with `pnpm install`, start a development server:
1456
1591
 
1457
1592
  ```bash
1458
1593
  pnpm dev
1459
1594
  ```
1460
1595
 
1596
+ ### Running tests
1597
+
1598
+ Run the browser tests in Vitest's interactive watch mode:
1599
+
1600
+ ```bash
1601
+ pnpm test:unit
1602
+ ```
1603
+
1604
+ For a single run, use `pnpm test`.
1605
+
1606
+ The tests exercise real browser focus, selection, and keyboard behavior. Keep the
1607
+ browser runner tab and window focused and let each run finish uninterrupted.
1608
+ Do not switch tabs or applications, open DevTools, or click inside the runner
1609
+ while tests are running. Losing focus can cause selection and keyboard tests to
1610
+ fail even when the editor works correctly.
1611
+
1612
+ If a run was interrupted, return focus to the runner and rerun the tests. Failures
1613
+ that persist during a focused, uninterrupted run should be investigated.
1614
+
1461
1615
  ## Building
1462
1616
 
1463
1617
  To create a production version of your app:
@@ -30,7 +30,7 @@
30
30
  --_cp: var(--node-caret-row-inline-position, 50%);
31
31
  content: '';
32
32
  position: absolute;
33
- background: var(--node-caret-bg, var(--svedit-editing-stroke));
33
+ background: var(--node-caret-bg, var(--editing));
34
34
  /* Increase the visibility of the caret by contrasting it with a box shadow that's the inverted brightness of the current text color. */
35
35
  /* Component developers must set their background color and text color on the node itself, not a child element, for this to work. */
36
36
  box-shadow: var(--node-caret-shadow, 0 0 0 0.5px oklch(from currentColor calc(1 - l) c h));
@@ -27,11 +27,20 @@
27
27
  * Reads visibility state directly from the registry. SvelteSet's per-key
28
28
  * tracking on `.has()` and iteration means this component only
29
29
  * re-evaluates when THIS array's visible-index set changes.
30
+ *
31
+ * The active marker (the one carrying the caret) additionally renders the
32
+ * consumer's `system_components.node_gap_tools` component when configured
33
+ * — an extension point for gap-scoped tools (e.g. an insert button).
34
+ * Rendering inside the marker means the tool inherits --row for
35
+ * orientation-aware styling and shows/hides together with the caret.
36
+ * The marker has pointer-events: none — interactive tools must set
37
+ * pointer-events: auto themselves.
30
38
  */
31
39
 
32
40
  let { path, count }: { path: DocumentPath; count: number } = $props();
33
41
 
34
42
  const svedit = getContext<SveditRenderContext>('svedit');
43
+ let NodeGapTools = $derived(svedit.session.config.system_components?.node_gap_tools);
35
44
  let path_str = $derived(serialize_path(path));
36
45
  let visible = $derived(svedit.visibility_registry.get_array_indices(path_str));
37
46
 
@@ -163,6 +172,9 @@
163
172
  >
164
173
  {#if gap.key === caret_gap_key}
165
174
  <NodeCaret />
175
+ {#if NodeGapTools}
176
+ <NodeGapTools {path} offset={gap.offset} is_first={gap.is_first} is_last={gap.is_last} />
177
+ {/if}
166
178
  {/if}
167
179
  </div>
168
180
  {/each}
@@ -170,6 +182,7 @@
170
182
  <style>
171
183
  /*
172
184
  * Public customization tokens (set on an ancestor or this component):
185
+ * --editing-stroke
173
186
  * --node-caret-gap-color
174
187
  * --node-caret-symbol-size
175
188
  * --node-caret-symbol-stroke
@@ -611,8 +624,8 @@
611
624
  calc(var(--_mi) + var(--_R) * 9999999px),
612
625
  calc(50% + var(--_C) * 9999999px)
613
626
  );
614
- border-top: calc(var(--_C) * 1px) dashed var(--node-caret-gap-color, var(--svedit-canvas-stroke));
615
- border-left: calc(var(--_R) * 1px) dashed var(--node-caret-gap-color, var(--svedit-canvas-stroke));
627
+ border-top: calc(var(--_C) * 1px) dashed var(--node-caret-gap-color, var(--editing-stroke));
628
+ border-left: calc(var(--_R) * 1px) dashed var(--node-caret-gap-color, var(--editing-stroke));
616
629
  transform:
617
630
  translateY(calc(var(--_C) * -0.5px))
618
631
  translateX(calc(var(--_R) * -0.5px));
@@ -626,7 +639,7 @@
626
639
  /* Empty array marker (dashed outline for discoverability). */
627
640
  &.gap-empty::before {
628
641
  inset: 0px;
629
- border: var(--node-caret-empty-border, 1px dashed var(--node-caret-gap-color, var(--svedit-canvas-stroke)));
642
+ border: var(--node-caret-empty-border, 1px dashed var(--node-caret-gap-color, var(--editing-stroke)));
630
643
  border-radius: var(--node-caret-empty-border-radius, 3px);
631
644
  }
632
645
 
@@ -639,7 +652,7 @@
639
652
  top: 50%;
640
653
  left: 50%;
641
654
  transform: translate(-50%, -50%);
642
- background: var(--node-caret-symbol-bg, var(--node-caret-gap-color, var(--svedit-canvas-stroke)));
655
+ background: var(--node-caret-symbol-bg, var(--node-caret-gap-color, var(--editing-stroke)));
643
656
  mask: var(--node-caret-symbol-mask,
644
657
  linear-gradient(black, black) center / 100% var(--node-caret-symbol-stroke, 1px) no-repeat,
645
658
  linear-gradient(black, black) center / var(--node-caret-symbol-stroke, 1px) 100% no-repeat
@@ -1 +1 @@
1
- {"version":3,"file":"NodeGapMarkers.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeGapMarkers.svelte.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAEnE,KAAK,gBAAgB,GAAI;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAoKhE,QAAA,MAAM,cAAc,sDAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"NodeGapMarkers.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeGapMarkers.svelte.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAEnE,KAAK,gBAAgB,GAAI;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAgLhE,QAAA,MAAM,cAAc,sDAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
@@ -24,13 +24,18 @@
24
24
  {#if svedit.session.selection?.type === 'property'}
25
25
  <div
26
26
  class="selected-property-overlay"
27
+ class:unfocused={!svedit.canvas_focused}
27
28
  style="position-anchor: --{serialize_path(svedit.session.selection.path)};"
28
29
  ></div>
29
30
  {/if}
30
31
 
31
32
  {#if selected_node_paths}
32
33
  {#each selected_node_paths as path (serialize_path(path))}
33
- <div class="selected-node-overlay" style="position-anchor: --{serialize_path(path)};"></div>
34
+ <div
35
+ class="selected-node-overlay"
36
+ class:unfocused={!svedit.canvas_focused}
37
+ style="position-anchor: --{serialize_path(path)};"
38
+ ></div>
34
39
  {/each}
35
40
  {/if}
36
41
 
@@ -50,8 +55,8 @@
50
55
  Performance note: outlines don't participate in layout, so
51
56
  selection changes can't trigger reflows. */
52
57
  position: absolute;
53
- background: var(--svedit-editing-fill);
54
- outline: 1px solid var(--svedit-editing-stroke);
58
+ background: var(--editing-muted);
59
+ outline: 1px solid var(--editing);
55
60
  outline-offset: -0.5px;
56
61
  border-radius: 1px;
57
62
  top: anchor(top);
@@ -61,4 +66,10 @@
61
66
  pointer-events: none;
62
67
  z-index: 12;
63
68
  }
69
+
70
+ .selected-node-overlay.unfocused,
71
+ .selected-property-overlay.unfocused {
72
+ background: oklch(from var(--editing-muted) l 0 h / alpha);
73
+ outline-color: oklch(from var(--editing) l 0 h);
74
+ }
64
75
  </style>
@@ -1 +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,GAAE,SAAS,GAAG,IAAqB,GAAG,SAAS,GAAG,IAAI;IAoB1F,iBAAiB,IAAI,CAAC,IAAI,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;KAAE,CAAC,GAAG,IAAI;IAuC5E,4BAA4B,IAAI;QAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACpC,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,KAAK,EAAE,UAAU,EAAE,CAAC;QACpB,WAAW,EAAE,UAAU,EAAE,CAAC;KAC1B,GAAG,IAAI;IA2CR,uBAAuB,IAAI,MAAM,GAAG,IAAI;IASxC,kBAAkB,IAAI,MAAM,EAAE,GAAG,IAAI;IAWrC,aAAa,IAAI,IAAI;IAqCrB;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC;IAQ9C;;;;;OAKG;IACH,OAAO,IAAI,QAAQ;IAanB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAKrD,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAKzC,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;CAI/C"}
@@ -361,17 +361,25 @@ export default class Session {
361
361
  * @returns The next node insert caret selection, or null if none is available
362
362
  */
363
363
  get_next_node_insert_caret(selection = this.selection) {
364
- // There's no parent path to insert into
365
- if (!selection || selection.path.length <= 2) {
364
+ if (!selection)
366
365
  return null;
366
+ // Array indexes identify insertion positions. Single-node references can
367
+ // occur between arrays, so removing a fixed pair of segments is unsafe.
368
+ for (let index = selection.path.length - 1; index >= 1; index--) {
369
+ const node_index = selection.path[index];
370
+ if (typeof node_index !== 'number')
371
+ continue;
372
+ const parent_path = selection.path.slice(0, index);
373
+ if (this.inspect(parent_path).type !== 'node_array')
374
+ continue;
375
+ return {
376
+ type: 'node',
377
+ path: parent_path,
378
+ anchor_offset: node_index + 1,
379
+ focus_offset: node_index + 1
380
+ };
367
381
  }
368
- const node_offset = selection.path.at(-2) + 1;
369
- return {
370
- type: 'node',
371
- path: selection.path.slice(0, -2),
372
- anchor_offset: node_offset,
373
- focus_offset: node_offset
374
- };
382
+ return null;
375
383
  }
376
384
  get_selected_text() {
377
385
  if (this.selection?.type !== 'text')
@@ -19,6 +19,9 @@
19
19
  get_default_text_node,
20
20
  create_plain_text_nodes_payload
21
21
  } from './paste_utils.js';
22
+ import { export_text_html } from './html_export.js';
23
+ import { escape_html } from './html_utils.js';
24
+ import { parse_html_paste, map_html_text, map_html_blocks } from './html_paste.js';
22
25
  import { create_node_visibility } from './node_visibility.svelte.js';
23
26
  import DefaultNodeSelectionMarkers from './NodeSelectionMarkers.svelte';
24
27
  import './styles/svedit-colors.css';
@@ -31,6 +34,7 @@
31
34
  NodeSelection,
32
35
  TextSelection,
33
36
  PropertySelection,
37
+ PropertyDefinition,
34
38
  DocumentNode,
35
39
  DocumentPath,
36
40
  DynamicRecord,
@@ -394,12 +398,12 @@ ${fallback_html}`;
394
398
  if (prop_name === 'id' || prop_name === 'type') continue;
395
399
  const property_definition = node_schema.properties[prop_name];
396
400
  // Check if this is a text property.
397
- if (property_definition.type === 'text') {
401
+ if (property_definition?.type === 'text') {
398
402
  const text_content = prop_value.content;
399
403
  if (text_content.trim()) {
400
- html += `<p>${text_content}</p>`;
404
+ html += `<p>${export_text_html(prop_value, session)}</p>`;
401
405
  }
402
- } else if (property_definition.type === 'node_array') {
406
+ } else if (property_definition?.type === 'node_array') {
403
407
  for (const child_id of prop_value.nodes) {
404
408
  const child = session.get(child_id);
405
409
  const child_exporter = html_exporters[child.type] || default_node_html_exporter;
@@ -480,7 +484,7 @@ ${fallback_html}`;
480
484
  if (session.selection?.type === 'text') {
481
485
  plain_text = session.get_selected_plain_text();
482
486
  text = session.get_selected_text();
483
- const fallback_html = `<span>${text.content}</span>`;
487
+ const fallback_html = `<span>${export_text_html(text, session, text.nodes)}</span>`;
484
488
 
485
489
  // console.log('Text copy:', {
486
490
  // text,
@@ -517,8 +521,12 @@ ${fallback_html}`;
517
521
  type: property_definition.type,
518
522
  value
519
523
  };
520
- html = create_svedit_html_format(json_data, `<span>${value}</span>`);
521
- plain_text = String(value);
524
+ const fallback_html =
525
+ property_definition.type === 'text'
526
+ ? export_text_html(value, session)
527
+ : escape_html(String(value));
528
+ html = create_svedit_html_format(json_data, `<span>${fallback_html}</span>`);
529
+ plain_text = property_definition.type === 'text' ? value.content : String(value);
522
530
  }
523
531
 
524
532
  // Write to clipboard using event.clipboardData
@@ -611,21 +619,22 @@ ${fallback_html}`;
611
619
  const { nodes, main_nodes, marks = [], annotations = [] } = pasted_json || {};
612
620
  if (!nodes || !main_nodes?.length) return false;
613
621
 
614
- let tr = session.tr;
615
- if (selection) {
616
- tr.set_selection(selection);
617
- }
618
- if (tr.selection?.type !== 'node') return false;
619
-
620
- const property_definition = session.inspect(tr.selection.path);
622
+ const target_selection = selection || session.selection;
623
+ if (target_selection?.type !== 'node') return false;
624
+ const property_definition = session.inspect(target_selection.path);
621
625
  if (property_definition?.type !== 'node_array') return false;
622
626
 
627
+ const tr = session.tr;
628
+ if (selection) tr.set_selection(selection);
629
+
623
630
  const default_text_node_type = get_default_text_node(property_definition, session.schema);
624
631
  const target_text_property_name = get_text_property_name(
625
632
  default_text_node_type,
626
633
  session.schema
627
634
  );
628
635
 
636
+ // Decide for the whole clipboard graph before creating any nodes or replacing the selection.
637
+ const preserve_ids = Object.values(nodes).every((node: DocumentNode) => !tr.doc.nodes[node.id]);
629
638
  const nodes_to_insert = [];
630
639
  let rejected = false;
631
640
  for (const node_id of main_nodes) {
@@ -642,30 +651,36 @@ ${fallback_html}`;
642
651
  default_text_node_type &&
643
652
  target_text_property_name
644
653
  ) {
645
- const new_node_id = tr.build('the_node', {
646
- the_node: {
647
- id: 'the_node',
648
- type: default_text_node_type,
649
- [target_text_property_name]: text_content || {
650
- content: '',
651
- marks: [],
652
- annotations: []
654
+ // Keep the clipboard graph so converted text retains its marks and annotations.
655
+ const new_node_id = tr.build(
656
+ node_id,
657
+ {
658
+ ...nodes,
659
+ [node_id]: {
660
+ id: node_id,
661
+ type: default_text_node_type,
662
+ [target_text_property_name]: text_content || {
663
+ content: '',
664
+ marks: [],
665
+ annotations: []
666
+ }
653
667
  }
654
- }
655
- });
668
+ },
669
+ { preserve_ids }
670
+ );
656
671
  nodes_to_insert.push(new_node_id);
657
672
  } else {
658
673
  rejected = true;
659
674
  break;
660
675
  }
661
676
  } else {
662
- const new_node_id = tr.build(node_id, nodes);
677
+ const new_node_id = tr.build(node_id, nodes, { preserve_ids });
663
678
  nodes_to_insert.push(new_node_id);
664
679
  }
665
680
  }
666
681
 
667
682
  if (!rejected) {
668
- tr.insert_nodes(nodes_to_insert, marks, annotations, nodes);
683
+ tr.insert_nodes(nodes_to_insert, marks, annotations, nodes, { preserve_ids });
669
684
  session.apply(tr);
670
685
  return true;
671
686
  }
@@ -679,13 +694,62 @@ ${fallback_html}`;
679
694
  return false;
680
695
  }
681
696
 
697
+ function try_html_paste(html: string): boolean {
698
+ const config = session.config.html_paste;
699
+ const selection = session.selection;
700
+ if (!config || !selection) return false;
701
+ const blocks = parse_html_paste(html);
702
+ if (!blocks.length) return false;
703
+ if (selection.type === 'text') {
704
+ const owner = session.get(selection.path.slice(0, -1));
705
+ const insert_as_nodes =
706
+ blocks.length > 1 ||
707
+ blocks.some(
708
+ (block) =>
709
+ 'items' in block && (config.lists?.[block.tag] || block.items.flat().length > 1)
710
+ );
711
+ if (insert_as_nodes && owner && session.kind(owner) === 'text') {
712
+ const caret = get_node_insert_caret_after_text_selection(selection);
713
+ if (caret) {
714
+ const payload = map_html_blocks(
715
+ blocks,
716
+ config,
717
+ session.schema,
718
+ session.inspect(caret.path) as unknown as PropertyDefinition
719
+ );
720
+ if (payload && try_node_paste(payload, caret)) return true;
721
+ }
722
+ }
723
+ const nodes: Record<string, DocumentNode> = {};
724
+ const text = map_html_text(
725
+ blocks,
726
+ config,
727
+ session.schema,
728
+ session.inspect(selection.path) as unknown as PropertyDefinition,
729
+ nodes
730
+ );
731
+ session.apply(session.tr.insert_text(text.content, text.marks, [], nodes));
732
+ return true;
733
+ }
734
+ const caret = get_target_node_insert_caret(selection);
735
+ if (!caret) return false;
736
+ const payload = map_html_blocks(
737
+ blocks,
738
+ config,
739
+ session.schema,
740
+ session.inspect(caret.path) as unknown as PropertyDefinition
741
+ );
742
+ return !!payload && try_node_paste(payload, caret);
743
+ }
744
+
682
745
  async function onpaste(event: ClipboardEvent) {
683
746
  // Only handle paste events if editable and focus is within the canvas
684
747
  if (!editable) return;
685
748
  if (!canvas_el?.contains(document.activeElement)) return;
686
749
  event.preventDefault();
687
750
 
688
- let plain_text,
751
+ let html_content,
752
+ plain_text,
689
753
  pasted_json,
690
754
  pasted_media = [];
691
755
 
@@ -718,7 +782,7 @@ ${fallback_html}`;
718
782
  } else {
719
783
  // First try to extract svedit data from HTML format
720
784
  try {
721
- const html_content = event.clipboardData?.getData('text/html');
785
+ html_content = event.clipboardData?.getData('text/html');
722
786
  if (html_content) {
723
787
  pasted_json = extract_svedit_data_from_html(html_content);
724
788
  }
@@ -733,6 +797,14 @@ ${fallback_html}`;
733
797
  console.error('Failed to paste any content:', e);
734
798
  }
735
799
 
800
+ if (!pasted_json && html_content && session.config.html_paste) {
801
+ try {
802
+ if (try_html_paste(html_content)) return;
803
+ } catch (error) {
804
+ console.warn('Failed to import pasted HTML; falling back to plain text:', error);
805
+ }
806
+ }
807
+
736
808
  // Try to construct a node payload from plain text when applicable
737
809
  if (!pasted_json && typeof plain_text === 'string') {
738
810
  plain_text = normalize_line_endings(plain_text);
@@ -1683,7 +1755,7 @@ ${fallback_html}`;
1683
1755
 
1684
1756
  <style>
1685
1757
  .svedit-canvas {
1686
- caret-color: var(--svedit-caret-color);
1758
+ caret-color: var(--editing);
1687
1759
  caret-shape: bar;
1688
1760
  /* Default to vertical/ column flow with: --row: 0; (the most common case)
1689
1761
  Prevents silent failures when developers forget to set the row property in their top level node component.
@@ -1699,7 +1771,7 @@ ${fallback_html}`;
1699
1771
  the :where(), but the wrapper zeroes its specificity contribution.
1700
1772
  Final specificity is just (0,0,1), trivially beatable. */
1701
1773
  :where(.svedit-canvas) :global(::selection) {
1702
- background: var(--svedit-editing-fill);
1774
+ background: var(--editing-muted);
1703
1775
  }
1704
1776
 
1705
1777
  @media not (pointer: coarse) {
@@ -1 +1 @@
1
- {"version":3,"file":"Svedit.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Svedit.svelte.ts"],"names":[],"mappings":"AAyBA,OAAO,4BAA4B,CAAC;AACpC,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EASX,MAAM,YAAY,CAAC;AAGrB,iBAAS,QAAQ,CAAC,CAAC,SAAS,cAAc;WA8lDb,WAAW,CAAC,CAAC,CAAC;aAAwB;QAAE,YAAY,aAAqB;KAAE;;;;EAAuE;AAC/K,cAAM,iBAAiB,CAAC,CAAC,SAAS,cAAc;IAC5C,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,QAAQ;IACR,OAAO;;;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,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,CAAC,CAAC,SAAS,cAAc,IAAI,YAAY,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,eAAe,MAAM,CAAC"}
@@ -186,9 +186,9 @@
186
186
  display: inline-block;
187
187
  /* we use box-shadow to draw the caret shape, matching the native caret */
188
188
  box-shadow:
189
- 0 -0.4cap 0 0.65px var(--svedit-caret-color, AccentColor),
190
- 0 0 0 0.65px var(--svedit-caret-color, AccentColor),
191
- 0 0.4cap 0 0.65px var(--svedit-caret-color, AccentColor);
189
+ 0 -0.4cap 0 0.65px var(--editing, AccentColor),
190
+ 0 0 0 0.65px var(--editing, AccentColor),
191
+ 0 0.4cap 0 0.65px var(--editing, AccentColor);
192
192
  animation: var(
193
193
  --node-caret-animation,
194
194
  node-caret-blink var(--node-caret-blink-duration, 1.1s) ease-in-out infinite
@@ -207,12 +207,12 @@
207
207
 
208
208
  /* Dim the selection highlight when canvas loses native focus */
209
209
  :global(.svedit-canvas:not(:focus-within)) .selection-highlight {
210
- background: oklch(from var(--svedit-editing-fill) l 0 h / alpha);
210
+ background: oklch(from var(--editing-muted) l 0 h / alpha);
211
211
  }
212
212
 
213
213
  /* Make a collapsed caret visible */
214
214
  :global(.svedit-canvas:not(:focus-within)) .selection-highlight:empty {
215
215
  background: none;
216
- outline: 0.5px solid oklch(from var(--svedit-editing-stroke) l 0 h / alpha);
216
+ outline: 0.5px solid oklch(from var(--editing) l 0 h / alpha);
217
217
  }
218
218
  </style>
@@ -109,7 +109,9 @@ export default class Transaction {
109
109
  * ```
110
110
  */
111
111
  set(path: DocumentPath, value: any): this;
112
- build(node_id: NodeId, nodes: Record<string, DocumentNode>): NodeId;
112
+ build(node_id: NodeId, nodes: Record<string, DocumentNode>, { preserve_ids }?: {
113
+ preserve_ids?: boolean;
114
+ }): NodeId;
113
115
  /**
114
116
  * Creates a new node in the document.
115
117
  *
@@ -230,7 +232,9 @@ export default class Transaction {
230
232
  * @param nodes - Node graph for restored marks and annotations
231
233
  * @returns This transaction instance for method chaining
232
234
  */
233
- insert_nodes(node_ids: NodeId[], marks?: Array<Mark>, annotations?: Array<Annotation>, nodes?: Record<NodeId, DocumentNode>): this;
235
+ insert_nodes(node_ids: NodeId[], marks?: Array<Mark>, annotations?: Array<Annotation>, nodes?: Record<NodeId, DocumentNode>, { preserve_ids }?: {
236
+ preserve_ids?: boolean;
237
+ }): this;
234
238
  /**
235
239
  * Inserts text at the current text selection position.
236
240
  *