svedit 0.12.0 → 0.13.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 (86) hide show
  1. package/README.md +33 -21
  2. package/dist/Command.svelte.d.ts +38 -30
  3. package/dist/Command.svelte.d.ts.map +1 -1
  4. package/dist/Command.svelte.js +271 -326
  5. package/dist/CustomProperty.svelte +3 -5
  6. package/dist/CustomProperty.svelte.d.ts +3 -6
  7. package/dist/CustomProperty.svelte.d.ts.map +1 -1
  8. package/dist/KeyMapper.svelte.d.ts +19 -6
  9. package/dist/KeyMapper.svelte.d.ts.map +1 -1
  10. package/dist/KeyMapper.svelte.js +95 -112
  11. package/dist/Node.svelte +16 -13
  12. package/dist/Node.svelte.d.ts +3 -5
  13. package/dist/Node.svelte.d.ts.map +1 -1
  14. package/dist/NodeArrayProperty.svelte +39 -22
  15. package/dist/NodeArrayProperty.svelte.d.ts +3 -5
  16. package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
  17. package/dist/NodeCaret.svelte +1 -1
  18. package/dist/NodeCaret.svelte.d.ts +6 -14
  19. package/dist/NodeCaret.svelte.d.ts.map +1 -1
  20. package/dist/NodeGap.svelte +12 -6
  21. package/dist/NodeGap.svelte.d.ts +7 -14
  22. package/dist/NodeGap.svelte.d.ts.map +1 -1
  23. package/dist/NodeGapMarkers.svelte +19 -10
  24. package/dist/NodeGapMarkers.svelte.d.ts +6 -11
  25. package/dist/NodeGapMarkers.svelte.d.ts.map +1 -1
  26. package/dist/NodeSelectionMarkers.svelte +20 -6
  27. package/dist/NodeSelectionMarkers.svelte.d.ts +2 -5
  28. package/dist/NodeSelectionMarkers.svelte.d.ts.map +1 -1
  29. package/dist/Session.svelte.d.ts +81 -129
  30. package/dist/Session.svelte.d.ts.map +1 -1
  31. package/dist/Session.svelte.js +542 -648
  32. package/dist/Svedit.svelte +144 -138
  33. package/dist/Svedit.svelte.d.ts +30 -10
  34. package/dist/Svedit.svelte.d.ts.map +1 -1
  35. package/dist/TextProperty.svelte +32 -18
  36. package/dist/TextProperty.svelte.d.ts +3 -5
  37. package/dist/TextProperty.svelte.d.ts.map +1 -1
  38. package/dist/Transaction.svelte.d.ts +64 -127
  39. package/dist/Transaction.svelte.d.ts.map +1 -1
  40. package/dist/Transaction.svelte.js +839 -1001
  41. package/dist/UnknownNode.svelte +4 -3
  42. package/dist/UnknownNode.svelte.d.ts +5 -9
  43. package/dist/UnknownNode.svelte.d.ts.map +1 -1
  44. package/dist/doc_utils.d.ts +67 -155
  45. package/dist/doc_utils.d.ts.map +1 -1
  46. package/dist/doc_utils.js +619 -863
  47. package/dist/index.d.ts +20 -17
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +1 -17
  50. package/dist/node_visibility.svelte.d.ts +110 -9
  51. package/dist/node_visibility.svelte.d.ts.map +1 -1
  52. package/dist/node_visibility.svelte.js +473 -544
  53. package/dist/paste_utils.d.ts +11 -44
  54. package/dist/paste_utils.d.ts.map +1 -1
  55. package/dist/paste_utils.js +111 -152
  56. package/dist/transforms.svelte.d.ts +9 -7
  57. package/dist/transforms.svelte.d.ts.map +1 -1
  58. package/dist/transforms.svelte.js +125 -150
  59. package/dist/types.d.ts +277 -309
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +1 -0
  62. package/dist/utils.d.ts +40 -119
  63. package/dist/utils.d.ts.map +1 -1
  64. package/dist/utils.js +346 -473
  65. package/package.json +69 -70
  66. package/src/lib/{Command.svelte.js → Command.svelte.ts} +29 -17
  67. package/src/lib/CustomProperty.svelte +3 -5
  68. package/src/lib/{KeyMapper.svelte.js → KeyMapper.svelte.ts} +28 -11
  69. package/src/lib/Node.svelte +16 -13
  70. package/src/lib/NodeArrayProperty.svelte +39 -22
  71. package/src/lib/NodeCaret.svelte +1 -1
  72. package/src/lib/NodeGap.svelte +12 -6
  73. package/src/lib/NodeGapMarkers.svelte +19 -10
  74. package/src/lib/NodeSelectionMarkers.svelte +20 -6
  75. package/src/lib/{Session.svelte.js → Session.svelte.ts} +130 -127
  76. package/src/lib/Svedit.svelte +144 -138
  77. package/src/lib/TextProperty.svelte +32 -18
  78. package/src/lib/{Transaction.svelte.js → Transaction.svelte.ts} +139 -143
  79. package/src/lib/UnknownNode.svelte +4 -3
  80. package/src/lib/{doc_utils.js → doc_utils.ts} +247 -206
  81. package/src/lib/{index.js → index.ts} +47 -0
  82. package/src/lib/{node_visibility.svelte.js → node_visibility.svelte.ts} +68 -92
  83. package/src/lib/{paste_utils.js → paste_utils.ts} +47 -58
  84. package/src/lib/{transforms.svelte.js → transforms.svelte.ts} +39 -21
  85. package/src/lib/{types.d.ts → types.ts} +143 -66
  86. package/src/lib/{utils.js → utils.ts} +110 -129
@@ -1,18 +1,11 @@
1
- export default NodeGap;
2
- type NodeGap = {
3
- $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<$$ComponentProps>): void;
5
- };
6
- declare const NodeGap: import("svelte").Component<{
7
- array_path: any;
8
- offset: any;
9
- count: any;
10
- empty?: boolean;
11
- }, {}, "">;
1
+ import type { DocumentPath } from './types.js';
12
2
  type $$ComponentProps = {
13
- array_path: any;
14
- offset: any;
15
- count: any;
3
+ array_path: DocumentPath;
4
+ offset: number;
5
+ count: number;
16
6
  empty?: boolean;
17
7
  };
8
+ declare const NodeGap: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type NodeGap = ReturnType<typeof NodeGap>;
10
+ export default NodeGap;
18
11
  //# sourceMappingURL=NodeGap.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeGap.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeGap.svelte.js"],"names":[],"mappings":";;;;;AA6HA;gBA1DgC,GAAG;YAAU,GAAG;WAAS,GAAG;YAAU,OAAO;WA0DvB;wBA1DpC;IAAE,UAAU,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE"}
1
+ {"version":3,"file":"NodeGap.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeGap.svelte.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAEnE,KAAK,gBAAgB,GAAI;IAAE,UAAU,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAkHvG,QAAA,MAAM,OAAO,sDAAwC,CAAC;AACtD,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C,eAAe,OAAO,CAAC"}
@@ -1,7 +1,8 @@
1
- <script>
1
+ <script lang="ts">
2
2
  import { getContext } from 'svelte';
3
3
  import NodeCaret from './NodeCaret.svelte';
4
4
  import { PATH_SEPARATOR, serialize_path } from './utils.js';
5
+ import type { DocumentPath, SveditRenderContext } from './types.js';
5
6
 
6
7
  /**
7
8
  * ┌─────────────────────────────────────────────────────────────────┐
@@ -28,9 +29,9 @@
28
29
  * re-evaluates when THIS array's visible-index set changes.
29
30
  */
30
31
 
31
- let { path, count } = $props();
32
+ let { path, count }: { path: DocumentPath; count: number } = $props();
32
33
 
33
- const svedit = getContext('svedit');
34
+ const svedit = getContext<SveditRenderContext>('svedit');
34
35
  let path_str = $derived(serialize_path(path));
35
36
  let visible = $derived(svedit.visibility_registry.get_array_indices(path_str));
36
37
 
@@ -51,8 +52,16 @@
51
52
  ? `;--_f:${anchor_prefix}${PATH_SEPARATOR}0;--_s:${anchor_prefix}${PATH_SEPARATOR}1`
52
53
  : '';
53
54
 
54
- /** @type {Array<{key:string,offset:number,type:string,vars:string,is_first:boolean,is_last:boolean,has_pair:boolean}>} */
55
- const result = [];
55
+ type GapMarker = {
56
+ key: string;
57
+ offset: number;
58
+ type: string;
59
+ vars: string;
60
+ is_first: boolean;
61
+ is_last: boolean;
62
+ has_pair: boolean;
63
+ };
64
+ const result: GapMarker[] = [];
56
65
 
57
66
  if (count === 0) {
58
67
  if (visible.has(0)) {
@@ -73,15 +82,15 @@
73
82
  // 1000 nodes with ~30 visible, this drops 1001 SvelteSet/SvelteMap
74
83
  // reads per re-derivation to ~30. Filter stale indices >= count
75
84
  // that may briefly remain after a node delete (until MO fires).
76
- const sorted = [];
85
+ const sorted: number[] = [];
77
86
  for (const i of visible) {
78
87
  if (i >= 0 && i < count) sorted.push(i);
79
88
  }
80
89
  sorted.sort((a, b) => a - b);
81
90
  if (sorted.length === 0) return result;
82
91
 
83
- const offsets = [];
84
- function add_offset(offset) {
92
+ const offsets: number[] = [];
93
+ function add_offset(offset: number) {
85
94
  if (!offsets.includes(offset)) offsets.push(offset);
86
95
  }
87
96
 
@@ -112,7 +121,7 @@
112
121
  ? `${g_prefix}${PATH_SEPARATOR}0-gap-before`
113
122
  : `${g_prefix}${PATH_SEPARATOR}${offset - 1}-gap-after`;
114
123
 
115
- let type, vars;
124
+ let type: string, vars: string;
116
125
  if (is_first || is_last) {
117
126
  type = 'gap-edge';
118
127
  const adjacent = is_first
@@ -646,4 +655,4 @@
646
655
  outline: 1px solid blue;
647
656
  outline-offset: 0.5px;
648
657
  } */
649
- </style>
658
+ </style>
@@ -1,14 +1,9 @@
1
- export default NodeGapMarkers;
2
- type NodeGapMarkers = {
3
- $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<$$ComponentProps>): void;
5
- };
6
- declare const NodeGapMarkers: import("svelte").Component<{
7
- path: any;
8
- count: any;
9
- }, {}, "">;
1
+ import type { DocumentPath } from './types.js';
10
2
  type $$ComponentProps = {
11
- path: any;
12
- count: any;
3
+ path: DocumentPath;
4
+ count: number;
13
5
  };
6
+ declare const NodeGapMarkers: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type NodeGapMarkers = ReturnType<typeof NodeGapMarkers>;
8
+ export default NodeGapMarkers;
14
9
  //# sourceMappingURL=NodeGapMarkers.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeGapMarkers.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeGapMarkers.svelte.js"],"names":[],"mappings":";;;;;AAgKA;UA3H0B,GAAG;WAAS,GAAG;WA2HoB;wBA3H3C;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,GAAG,CAAA;CAAE"}
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,12 +1,13 @@
1
- <script>
1
+ <script lang="ts">
2
2
  import { getContext } from 'svelte';
3
3
  import { serialize_path } from './utils.js';
4
+ import type { DocumentPath, SveditContext } from './types.js';
4
5
 
5
- const svedit = getContext('svedit');
6
+ const svedit = getContext<SveditContext>('svedit');
6
7
  let selected_node_paths = $derived(get_selected_node_paths());
7
8
 
8
- function get_selected_node_paths() {
9
- const paths = [];
9
+ function get_selected_node_paths(): DocumentPath[] | undefined {
10
+ const paths: DocumentPath[] = [];
10
11
  const selection = svedit.session.selection;
11
12
  if (!selection) return;
12
13
  if (selection.type !== 'node' || selection.anchor_offset === selection.focus_offset) return;
@@ -36,10 +37,23 @@
36
37
  <style>
37
38
  .selected-node-overlay,
38
39
  .selected-property-overlay {
40
+ /* Selection frame: a single 1px outline, offset -0.5px so the
41
+ hairline centers on the node's edge and neighboring frames merge
42
+ into one shared line. Alternatives tried and rejected:
43
+ - Plain 1px border: adjacent selected nodes stack their borders
44
+ into a 2px seam between them, which looks ugly.
45
+ - Thick translucent frame (8px border) plus an inner hairline
46
+ outline: multiple nested lines take more cognitive effort to
47
+ parse than a single line.
48
+ - Inset box-shadow rings (1px stroke + 8px translucent): same
49
+ layered-frame look, same objection.
50
+ Performance note: outlines don't participate in layout, so
51
+ selection changes can't trigger reflows. */
39
52
  position: absolute;
40
53
  background: var(--svedit-editing-fill);
41
- border: 1px solid var(--svedit-editing-stroke);
42
- border-radius: 2px;
54
+ outline: 1px solid var(--svedit-editing-stroke);
55
+ outline-offset: -0.5px;
56
+ border-radius: 1px;
43
57
  top: anchor(top);
44
58
  left: anchor(left);
45
59
  bottom: anchor(bottom);
@@ -1,7 +1,4 @@
1
- export default NodeSelectionMarkers;
2
- type NodeSelectionMarkers = {
3
- $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<Record<string, never>>): void;
5
- };
6
1
  declare const NodeSelectionMarkers: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type NodeSelectionMarkers = ReturnType<typeof NodeSelectionMarkers>;
3
+ export default NodeSelectionMarkers;
7
4
  //# sourceMappingURL=NodeSelectionMarkers.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSelectionMarkers.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeSelectionMarkers.svelte.js"],"names":[],"mappings":";;;;;AA0CA,8FAAmE"}
1
+ {"version":3,"file":"NodeSelectionMarkers.svelte.d.ts","sourceRoot":"","sources":["../src/lib/NodeSelectionMarkers.svelte.ts"],"names":[],"mappings":"AA4CA,QAAA,MAAM,oBAAoB,2DAAwC,CAAC;AACnE,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACpE,eAAe,oBAAoB,CAAC"}
@@ -1,72 +1,58 @@
1
- /**
2
- * @typedef {Object} SessionOptions
3
- * @property {Selection} [selection] - Initial selection state
4
- */
5
- export default class Session {
6
- /**
7
- * @param {DocumentSchema} schema - The document schema
8
- * @param {Document} doc - The document
9
- * @param {object} config - configuration object
10
- * @param {Object} [options]
11
- * @param {Selection} [options.selection] - Initial selection state
12
- */
13
- constructor(schema: DocumentSchema, doc: Document, config: object, options?: {
14
- selection?: Selection;
15
- });
16
- /** @type {DocumentSchema} */
17
- schema: DocumentSchema;
18
- /** @type {Document} */
1
+ import Transaction from './Transaction.svelte.js';
2
+ import type { SelectedAttachment } from './doc_utils.js';
3
+ import type { NodeId, DocumentPath, Selection, Attachment, NodeKind, DocumentSchema, DocumentNode, Document, AnyNode, Text, CommandRegistry, Inspection, SessionConfig, SveditContext } from './types.js';
4
+ import type { Keymap } from './KeyMapper.svelte.js';
5
+ type HistoryEntry = {
6
+ ops: Transaction['ops'];
7
+ inverse_ops: Transaction['inverse_ops'];
8
+ selection_before: Selection | null;
9
+ selection_after: Selection | null;
10
+ };
11
+ export default class Session<S extends DocumentSchema = DocumentSchema> {
12
+ #private;
13
+ schema: S;
19
14
  doc: Document;
20
- /** @type {any} */
21
- config: any;
22
- history: any[];
15
+ config: SessionConfig;
16
+ history: HistoryEntry[];
23
17
  history_index: number;
24
- last_batch_started: any;
25
- commands: {};
26
- keymap: {};
18
+ last_batch_started: number | undefined;
19
+ commands: CommandRegistry;
20
+ keymap: Keymap;
27
21
  can_undo: boolean;
28
22
  can_redo: boolean;
29
- selected_node: any;
30
- available_mark_types: any;
31
- available_annotation_types: any;
32
- selected_marks: (Attachment & {
33
- index: number;
34
- node: any;
35
- })[];
36
- active_mark: Attachment & {
37
- index: number;
38
- node: any;
39
- };
40
- selected_annotations: (Attachment & {
41
- index: number;
42
- node: any;
43
- })[];
44
- active_annotation: Attachment & {
45
- index: number;
46
- node: any;
47
- };
23
+ selected_node: AnyNode<S> | null;
24
+ available_mark_types: string[];
25
+ available_annotation_types: string[];
26
+ selected_marks: SelectedAttachment[];
27
+ active_mark: SelectedAttachment | null;
28
+ selected_annotations: SelectedAttachment[];
29
+ active_annotation: SelectedAttachment | null;
30
+ /**
31
+ * @param schema - The document schema
32
+ * @param doc - The document
33
+ * @param config - configuration object
34
+ * @param options - Optional settings (e.g. initial selection state)
35
+ */
36
+ constructor(schema: S, doc: Document, config: SessionConfig, options?: {
37
+ selection?: Selection | null;
38
+ });
39
+ /**
40
+ * Gets the current selection
41
+ */
42
+ get selection(): Selection | null;
48
43
  /**
49
44
  * Sets the selection with validation
50
- * @param {Selection | null} value - The new selection
51
45
  * @throws {Error} Throws if the selection is invalid
52
46
  */
53
47
  set selection(value: Selection | null);
54
- /**
55
- * Gets the current selection
56
- * @returns {Selection | null}
57
- */
58
- get selection(): Selection | null;
59
48
  /**
60
49
  * Validates that a selection is within bounds and refers to valid paths.
61
50
  *
62
- * @param {Selection} selection - The selection to validate
63
51
  * @throws {Error} Throws if the selection is invalid
64
- * @private
65
52
  */
66
53
  private _validate_selection;
67
54
  /**
68
55
  * Gets the document_id from the doc
69
- * @returns {string}
70
56
  */
71
57
  get document_id(): string;
72
58
  /**
@@ -77,11 +63,10 @@ export default class Session {
77
63
  * deleted nodes. That catches local node invariants and dangling references left
78
64
  * behind by deletes without scanning every node on every apply.
79
65
  *
80
- * @param {Transaction} transaction - The transaction result to validate
81
66
  * @throws {Error} Throws if the transaction result is invalid
82
67
  */
83
68
  validate_transaction_result(transaction: Transaction): void;
84
- generate_id(): any;
69
+ generate_id(): string;
85
70
  /**
86
71
  * Initialize commands and keymap for this session.
87
72
  * Called by Svedit component when it has the necessary context.
@@ -90,35 +75,34 @@ export default class Session {
90
75
  * For multiple editors on the same document, this architecture would need
91
76
  * to be refactored to support multiple sessions per document.
92
77
  *
93
- * @param {object} context - The svedit context with session, editable, canvas, etc.
78
+ * @param context - The svedit context with session, editable, canvas, etc.
94
79
  */
95
- initialize_commands(context: object): void;
96
- get_available_mark_types(): any;
97
- get_available_annotation_types(): any;
98
- get_selected_node(): any;
80
+ initialize_commands(context: SveditContext<S>): void;
81
+ get_available_mark_types(): string[];
82
+ get_available_annotation_types(): string[];
83
+ get_selected_node(): AnyNode<S> | null;
99
84
  /**
100
85
  * Creates a new transaction for making atomic changes to the document.
101
- *
102
- * @returns {Transaction} A new transaction instance
103
86
  */
104
87
  get tr(): Transaction;
105
88
  /**
106
89
  * Applies a transaction to the document.
107
- * Auto-batches history entries with debounced behavior (max one entry per 2 seconds) when batch is true.
90
+ * Auto-batches history entries with debounced behavior (max one entry per second) when batch is true.
108
91
  *
109
- * @param {Transaction} transaction - The transaction to apply
110
- * @param {object} [options] - Optional configuration
111
- * @param {boolean} [options.batch=false] - Whether to allow batching with previous transaction
92
+ * @param transaction - The transaction to apply
93
+ * @param options - Optional configuration (batch: whether to allow batching with previous transaction)
112
94
  */
113
95
  apply(transaction: Transaction, { batch }?: {
114
96
  batch?: boolean;
115
97
  }): this;
116
- undo(): this;
117
- redo(): this;
98
+ undo(): this | undefined;
99
+ redo(): this | undefined;
118
100
  /**
119
101
  * Gets a node instance or property value at the specified path.
120
- * @param {DocumentPath|string} path - Path to the node or property
121
- * @returns {any} Either a node instance object or the value of a property
102
+ *
103
+ * The result type defaults to `any` because a path can address a node or
104
+ * any property value. Annotate the target to type the result.
105
+ *
122
106
  * @example
123
107
  * // Get a node by ID
124
108
  * session.get('list_1') // => { type: 'list', id: 'list_1', ... }
@@ -135,7 +119,7 @@ export default class Session {
135
119
  * // Get a text property
136
120
  * session.get(['page_1', 'cover', 'title']) // => {content: 'Hello world', marks: [], annotations: []}
137
121
  */
138
- get(path: DocumentPath | string): any;
122
+ get<T = any>(path: DocumentPath | string): T;
139
123
  /**
140
124
  * While .get gives you the value of a path, inspect gives you
141
125
  * the type info of that value.
@@ -158,49 +142,40 @@ export default class Session {
158
142
  * type: 'paragraph',
159
143
  * properties: {...}
160
144
  * }
161
- *
162
- * @param {DocumentPath} path
163
- * @returns {{kind: 'property'|'node', [key: string]: any}}
164
145
  */
165
- inspect(path: DocumentPath): {
166
- kind: "property" | "node";
167
- [key: string]: any;
168
- };
146
+ inspect(path: DocumentPath): Inspection;
169
147
  /**
170
- * Determines the kind of a node ('block' for structured blocks, 'text' for pure
171
- * text nodes, 'mark' for mark nodes or 'annotation' for annotation nodes.
172
- * @param {any} node
173
- * @returns {NodeKind}
148
+ * Determines the kind of a node ('document' for root nodes, 'block' for
149
+ * structured blocks, 'text' for pure text nodes, 'mark' for mark nodes or
150
+ * 'annotation' for annotation nodes).
174
151
  */
175
- kind(node: any): NodeKind;
152
+ kind(node: DocumentNode): NodeKind;
176
153
  /**
177
154
  * Determines whether a node type can be inserted at a given selection.
178
- * @param {string} node_type - The type of node to insert.
179
- * @param {Selection} [selection] - The selection at which to insert the node.
180
- * @returns {boolean} True if the node type can be inserted, false otherwise.
155
+ *
156
+ * @param node_type - The type of node to insert.
157
+ * @param selection - The selection at which to insert the node.
158
+ * @returns True if the node type can be inserted, false otherwise.
181
159
  */
182
- can_insert(node_type: string, selection?: Selection): boolean;
160
+ can_insert(node_type: string, selection?: Selection | null): boolean;
183
161
  /**
184
162
  * Compute next possible insert position from a given selection
185
163
  *
186
- * @param {Selection} [selection] - Reference selection
187
- * @returns {Selection|null} The next node insert caret selection, or null if none is available
164
+ * @param selection - Reference selection
165
+ * @returns The next node insert caret selection, or null if none is available
188
166
  */
189
- get_next_node_insert_caret(selection?: Selection): Selection | null;
190
- get_selected_text(): {
191
- content: string;
192
- marks: any;
193
- annotations: any;
194
- nodes: {};
195
- };
167
+ get_next_node_insert_caret(selection?: Selection | null): Selection | null;
168
+ get_selected_text(): (Text & {
169
+ nodes: Record<string, DocumentNode>;
170
+ }) | null;
196
171
  get_selected_annotated_nodes(): {
197
- nodes: {};
198
- main_nodes: any;
199
- marks: any;
200
- annotations: any;
201
- };
202
- get_selected_plain_text(): string;
203
- get_selected_nodes(): any;
172
+ nodes: Record<string, DocumentNode>;
173
+ main_nodes: NodeId[];
174
+ marks: Attachment[];
175
+ annotations: Attachment[];
176
+ } | null;
177
+ get_selected_plain_text(): string | null;
178
+ get_selected_nodes(): NodeId[] | null;
204
179
  select_parent(): void;
205
180
  /**
206
181
  * Traverses the document and returns a list of nodes in depth-first order.
@@ -210,9 +185,7 @@ export default class Session {
210
185
  * 2. Branch nodes second
211
186
  * 3. Root node (entry point) last
212
187
  *
213
- * @param {string} node_id - The ID of the node to start traversing from
214
- * @returns {Array<DocumentNode>} Array of nodes in depth-first order
215
- * @note Nodes that are not reachable from the entry point node will not be included
188
+ * Nodes that are not reachable from the entry point node will not be included.
216
189
  */
217
190
  traverse(node_id: string): Array<DocumentNode>;
218
191
  /**
@@ -220,32 +193,11 @@ export default class Session {
220
193
  *
221
194
  * We make a traversal to ensure that orphaned nodes are not included,
222
195
  * and that leaf nodes go first, followed by branches and the root node at last.
223
- *
224
- * @returns {Document} The document
225
196
  */
226
197
  to_json(): Document;
227
- property_type(type: any, property: any): string;
228
- count_references(node_id: any): number;
229
- /**
230
- * @param {NodeId} node_id
231
- * @returns {NodeId[]}
232
- */
198
+ property_type(type: string, property: string): string;
199
+ count_references(node_id: NodeId): number;
233
200
  get_referenced_nodes(node_id: NodeId): NodeId[];
234
- #private;
235
201
  }
236
- export type SessionOptions = {
237
- /**
238
- * - Initial selection state
239
- */
240
- selection?: Selection;
241
- };
242
- import type { DocumentSchema } from './types.d.ts';
243
- import type { Document } from './types.d.ts';
244
- import type { Attachment } from './types.d.ts';
245
- import type { Selection } from './types.d.ts';
246
- import Transaction from './Transaction.svelte.js';
247
- import type { DocumentPath } from './types.d.ts';
248
- import type { NodeKind } from './types.d.ts';
249
- import type { DocumentNode } from './types.d.ts';
250
- import type { NodeId } from './types.d.ts';
202
+ export {};
251
203
  //# sourceMappingURL=Session.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Session.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Session.svelte.js"],"names":[],"mappings":"AAsCA;;;GAGG;AAEH;IAqCC;;;;;;OAMG;IACH,oBANW,cAAc,OACd,QAAQ,UACR,MAAM,YAEd;QAA4B,SAAS,GAA7B,SAAS;KACnB,EAaA;IApDD,6BAA6B;IAC7B,QADW,cAA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