@mhkeller/layercake-annotations 0.1.0 → 0.1.1

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.
@@ -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.1.1",
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"