svedit 0.1.1 → 0.3.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 +38 -0
- package/dist/AnnotatedStringProperty.svelte +42 -39
- package/dist/AnnotatedStringProperty.svelte.d.ts.map +1 -1
- package/dist/CustomProperty.svelte +21 -10
- package/dist/CustomProperty.svelte.d.ts +1 -2
- package/dist/CustomProperty.svelte.d.ts.map +1 -1
- package/dist/Document.svelte.d.ts +1 -1
- package/dist/Document.svelte.d.ts.map +1 -1
- package/dist/Document.svelte.js +5 -2
- package/dist/Node.svelte +18 -14
- package/dist/Node.svelte.d.ts.map +1 -1
- package/dist/NodeArrayProperty.svelte +1 -1
- package/dist/Svedit.svelte +552 -84
- package/dist/Svedit.svelte.d.ts +1 -1
- package/dist/Svedit.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.d.ts +0 -3
- package/dist/Transaction.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.js +19 -9
- package/dist/commands.svelte.d.ts.map +1 -1
- package/dist/commands.svelte.js +6 -4
- package/dist/util.d.ts +125 -3
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +170 -12
- package/package.json +1 -1
- package/src/lib/AnnotatedStringProperty.svelte +42 -39
- package/src/lib/CustomProperty.svelte +21 -10
- package/src/lib/Document.svelte.js +5 -2
- package/src/lib/Node.svelte +18 -14
- package/src/lib/NodeArrayProperty.svelte +1 -1
- package/src/lib/Svedit.svelte +552 -84
- package/src/lib/Transaction.svelte.js +19 -9
- package/src/lib/commands.svelte.js +6 -4
- package/src/lib/util.js +170 -12
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
|
|
2
4
|
/** @import { CustomPropertyProps } from './types.d.ts'; */
|
|
3
5
|
|
|
6
|
+
const svedit = getContext('svedit');
|
|
7
|
+
|
|
4
8
|
/** @type {CustomPropertyProps} */
|
|
5
9
|
let {
|
|
6
10
|
path,
|
|
@@ -9,16 +13,23 @@
|
|
|
9
13
|
} = $props();
|
|
10
14
|
</script>
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
{#if svedit.editable}
|
|
17
|
+
<!-- NOTE: It's super crucial that there is no extra whitespace, to not introduce additional cursor positions in contenteditable -->
|
|
18
|
+
<div
|
|
19
|
+
class="property {css_class}"
|
|
20
|
+
data-type="property"
|
|
21
|
+
data-path={path.join('.')}
|
|
22
|
+
style="anchor-name: --{path.join('-')};"
|
|
23
|
+
>
|
|
24
|
+
<div class="cursor-trap">
|
|
25
|
+
<div class="svedit-selectable"><br/></div>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<div class="property-content" contenteditable="false">{@render children()}</div>
|
|
29
|
+
</div>
|
|
30
|
+
{:else}
|
|
31
|
+
{@render children()}
|
|
32
|
+
{/if}
|
|
22
33
|
|
|
23
34
|
<style>
|
|
24
35
|
.property {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Transaction from './Transaction.svelte.js';
|
|
2
|
+
import { char_slice } from './util.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @import {
|
|
@@ -239,7 +240,9 @@ export default class Document {
|
|
|
239
240
|
return node_id ? this.get(node_id) : null;
|
|
240
241
|
} else {
|
|
241
242
|
// we are assuming we are either in a text or property (=custom) selection
|
|
242
|
-
const
|
|
243
|
+
const node_id = this.selection?.path?.slice(0, -1);
|
|
244
|
+
if (!node_id) return null;
|
|
245
|
+
const owner_node = this.get(node_id);
|
|
243
246
|
return owner_node;
|
|
244
247
|
}
|
|
245
248
|
}
|
|
@@ -489,7 +492,7 @@ export default class Document {
|
|
|
489
492
|
const start = Math.min(this.selection.anchor_offset, this.selection.focus_offset);
|
|
490
493
|
const end = Math.max(this.selection.anchor_offset, this.selection.focus_offset);
|
|
491
494
|
const annotated_string = this.get(this.selection.path);
|
|
492
|
-
return annotated_string[0]
|
|
495
|
+
return char_slice(annotated_string[0], start, end);
|
|
493
496
|
}
|
|
494
497
|
|
|
495
498
|
get_selected_nodes() {
|
package/src/lib/Node.svelte
CHANGED
|
@@ -18,21 +18,25 @@
|
|
|
18
18
|
let is_first_node_array_child = $derived(is_inside_node_array && parseInt(String(path.at(-1)), 10) === 0);
|
|
19
19
|
</script>
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
{#if svedit.editable}
|
|
22
|
+
<div
|
|
23
|
+
class="node"
|
|
24
|
+
data-node-id={node.id}
|
|
25
|
+
data-path={path.join('.')}
|
|
26
|
+
data-type="node"
|
|
27
|
+
style="anchor-name: --{path.join('-')};"
|
|
28
|
+
>
|
|
29
|
+
{#if is_first_node_array_child}
|
|
30
|
+
<NodeCursorTrap {path} type="position-zero-cursor-trap" />
|
|
31
|
+
{/if}
|
|
32
|
+
{@render children()}
|
|
33
|
+
{#if is_inside_node_array}
|
|
34
|
+
<NodeCursorTrap {path} type="after-node-cursor-trap" />
|
|
35
|
+
{/if}
|
|
36
|
+
</div>
|
|
37
|
+
{:else}
|
|
31
38
|
{@render children()}
|
|
32
|
-
|
|
33
|
-
<NodeCursorTrap {path} type="after-node-cursor-trap" />
|
|
34
|
-
{/if}
|
|
35
|
-
</div>
|
|
39
|
+
{/if}
|
|
36
40
|
|
|
37
41
|
<style>
|
|
38
42
|
div {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
</script>
|
|
19
19
|
|
|
20
20
|
<div class={css_class} data-type="node_array" data-path={path.join('.')}>
|
|
21
|
-
{#if nodes.length === 0}
|
|
21
|
+
{#if nodes.length === 0 && svedit.editable}
|
|
22
22
|
<!--
|
|
23
23
|
Experimental: We'll let .empty-node-array act like a node, so the existing
|
|
24
24
|
code paths for selection mapping will work as expected.
|