@mhkeller/layercake-annotations 0.1.0 → 0.2.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 CHANGED
@@ -50,6 +50,14 @@ pnpm add @mhkeller/layercake-annotations
50
50
  | `annotations` | `Annotation[]` | `[]` | Array of annotation objects (bindable) |
51
51
  | `editable` | `boolean` | `true` | Enable editing. Set `false` for read-only display |
52
52
 
53
+ **Note:** The `annotations` prop uses Svelte 5's `$bindable` for two-way binding. For edits to persist, the parent component must store annotations in a `$state` variable:
54
+
55
+ ```svelte
56
+ let annotations = $state([]); // ✓ edits persist
57
+ let annotations = []; // ✗ edits won't persist
58
+ import annotations from 'annotations.js' // ✗ edits won't persist
59
+ ```
60
+
53
61
  ## Annotation Data Structure
54
62
 
55
63
  ```js
@@ -12,13 +12,13 @@
12
12
  </script>
13
13
 
14
14
  {#snippet defs()}
15
- <ArrowheadMarker />
15
+ <ArrowheadMarker />
16
16
  {/snippet}
17
17
 
18
- <Svg {defs}>
18
+ <Svg {defs} pointerEvents={false}>
19
19
  <Arrows {annotations} />
20
20
  </Svg>
21
21
 
22
- <Html>
22
+ <Html pointerEvents={false}>
23
23
  <AnnotationsData {annotations} />
24
24
  </Html>
@@ -109,7 +109,12 @@
109
109
  {containerClass}
110
110
  >
111
111
  <div class="layercake-annotation" data-id={d.id}>
112
- <EditableText bind:text={d.text} bind:isEditable {alignment} />
112
+ <EditableText
113
+ bind:text={d.text}
114
+ bind:isEditable
115
+ {alignment}
116
+ onSave={(newText) => modifyAnnotation(d.id, { text: newText })}
117
+ />
113
118
  </div>
114
119
  <ResizeHandles bind:width {ondrag} {grabbers} {containerClass} />
115
120
  </Draggable>
@@ -9,7 +9,7 @@
9
9
  /** @type {Ref<boolean>} */
10
10
  const isEditing = getContext('isEditing');
11
11
 
12
- let { text = $bindable(), isEditable = $bindable(false), alignment } = $props();
12
+ let { text = $bindable(), isEditable = $bindable(false), alignment, onSave } = $props();
13
13
 
14
14
  let textarea = $state(null);
15
15
 
@@ -21,12 +21,15 @@
21
21
  selection.addRange(range);
22
22
  }
23
23
 
24
- function cancelEdit() {
24
+ function endEdit() {
25
25
  isEditable = false;
26
26
  text = text.trim();
27
27
  window.removeEventListener('keydown', handleKeydown);
28
28
  document.removeEventListener('click', handleClickOutside);
29
29
 
30
+ // Save the text change
31
+ onSave?.(text);
32
+
30
33
  // Wait for the click event to propagate before setting isEditing to false
31
34
  setTimeout(() => {
32
35
  isEditing.value = false;
@@ -83,7 +86,7 @@
83
86
  aria-multiline="true"
84
87
  tabindex="0"
85
88
  bind:this={textarea}
86
- onblur={cancelEdit}
89
+ onblur={endEdit}
87
90
  {onclick}
88
91
  ondblclick={handleDoubleClick}
89
92
  contenteditable
@@ -8,9 +8,11 @@ declare const EditableText: import("svelte").Component<{
8
8
  text?: any;
9
9
  isEditable?: boolean;
10
10
  alignment: any;
11
+ onSave: any;
11
12
  }, {}, "text" | "isEditable">;
12
13
  type $$ComponentProps = {
13
14
  text?: any;
14
15
  isEditable?: boolean;
15
16
  alignment: any;
17
+ onSave: any;
16
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhkeller/layercake-annotations",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && pnpm package",
@@ -51,9 +51,6 @@
51
51
  "svelte": "./dist/index.js",
52
52
  "types": "./dist/index.d.ts",
53
53
  "type": "module",
54
- "publishConfig": {
55
- "access": "public"
56
- },
57
54
  "dependencies": {
58
55
  "layercake": "^10.0.2",
59
56
  "underscore": "^1.13.7"