svedit 0.1.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/LICENSE +21 -0
- package/README.md +323 -0
- package/dist/AnnotatedStringProperty.svelte +126 -0
- package/dist/AnnotatedStringProperty.svelte.d.ts +7 -0
- package/dist/AnnotatedStringProperty.svelte.d.ts.map +1 -0
- package/dist/CustomProperty.svelte +40 -0
- package/dist/CustomProperty.svelte.d.ts +8 -0
- package/dist/CustomProperty.svelte.d.ts.map +1 -0
- package/dist/Document.svelte.d.ts +191 -0
- package/dist/Document.svelte.d.ts.map +1 -0
- package/dist/Document.svelte.js +681 -0
- package/dist/Node.svelte +41 -0
- package/dist/Node.svelte.d.ts +7 -0
- package/dist/Node.svelte.d.ts.map +1 -0
- package/dist/NodeArrayProperty.svelte +45 -0
- package/dist/NodeArrayProperty.svelte.d.ts +7 -0
- package/dist/NodeArrayProperty.svelte.d.ts.map +1 -0
- package/dist/Svedit.svelte +936 -0
- package/dist/Svedit.svelte.d.ts +12 -0
- package/dist/Svedit.svelte.d.ts.map +1 -0
- package/dist/Transaction.svelte.d.ts +198 -0
- package/dist/Transaction.svelte.d.ts.map +1 -0
- package/dist/Transaction.svelte.js +577 -0
- package/dist/UnknownNode.svelte +12 -0
- package/dist/UnknownNode.svelte.d.ts +12 -0
- package/dist/UnknownNode.svelte.d.ts.map +1 -0
- package/dist/commands.svelte.d.ts +5 -0
- package/dist/commands.svelte.d.ts.map +1 -0
- package/dist/commands.svelte.js +261 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/types.d.ts +264 -0
- package/dist/util.d.ts +4 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +78 -0
- package/package.json +65 -0
- package/src/lib/AnnotatedStringProperty.svelte +126 -0
- package/src/lib/CustomProperty.svelte +40 -0
- package/src/lib/Document.svelte.js +681 -0
- package/src/lib/Node.svelte +41 -0
- package/src/lib/NodeArrayProperty.svelte +45 -0
- package/src/lib/Svedit.svelte +936 -0
- package/src/lib/Transaction.svelte.js +577 -0
- package/src/lib/UnknownNode.svelte +12 -0
- package/src/lib/commands.svelte.js +261 -0
- package/src/lib/index.js +14 -0
- package/src/lib/types.d.ts +264 -0
- package/src/lib/util.js +78 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* NodeId,
|
|
4
|
+
* DocumentPath,
|
|
5
|
+
* Selection,
|
|
6
|
+
* Annotation,
|
|
7
|
+
* PrimitiveType,
|
|
8
|
+
* DocumentSchemaPrimitive,
|
|
9
|
+
* NodeProperty,
|
|
10
|
+
* NodeArrayProperty,
|
|
11
|
+
* DocumentSchema,
|
|
12
|
+
* SerializedDocument
|
|
13
|
+
* } from './types.d.ts';
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Identity function — keeps schema at runtime & makes IDE infer types.
|
|
17
|
+
* Similar to your define_schema pattern but for document schemas.
|
|
18
|
+
*
|
|
19
|
+
* @template {Record<string, Record<string, {type: DocumentSchemaPrimitive}>>} S
|
|
20
|
+
* @param {S} schema - The document schema to validate
|
|
21
|
+
* @returns {S} The same schema, but with type information preserved
|
|
22
|
+
*/
|
|
23
|
+
export function define_document_schema<S extends Record<string, Record<string, {
|
|
24
|
+
type: DocumentSchemaPrimitive;
|
|
25
|
+
}>>>(schema: S): S;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a string represents a valid primitive type.
|
|
28
|
+
* @param {string} type - The type string to check
|
|
29
|
+
* @returns {type is PrimitiveType} True if it's a valid primitive type
|
|
30
|
+
*/
|
|
31
|
+
export function is_primitive_type(type: string): type is PrimitiveType;
|
|
32
|
+
/**
|
|
33
|
+
* Get the default node type for a property that references nodes.
|
|
34
|
+
* @param {NodeProperty | NodeArrayProperty} property_definition - The property definition
|
|
35
|
+
* @returns {string | null} The default node type, or null if none specified
|
|
36
|
+
*/
|
|
37
|
+
export function get_default_node_type(property_definition: NodeProperty | NodeArrayProperty): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Validate a document schema to ensure all referenced node types exist.
|
|
40
|
+
* @param {DocumentSchema} document_schema - The document schema to validate
|
|
41
|
+
* @throws {Error} Throws if the document schema is invalid
|
|
42
|
+
*/
|
|
43
|
+
export function validate_document_schema(document_schema: DocumentSchema): void;
|
|
44
|
+
export default class Document {
|
|
45
|
+
/**
|
|
46
|
+
* @param {DocumentSchema} schema - The document schema
|
|
47
|
+
* @param {SerializedDocument} serialized_doc - The serialized document array
|
|
48
|
+
* @param {object} [options] - Optional configuration
|
|
49
|
+
* @param {Selection} [options.selection] - Initial selection state
|
|
50
|
+
* @param {any} [options.config] - Document configuration
|
|
51
|
+
*/
|
|
52
|
+
constructor(schema: DocumentSchema, serialized_doc: SerializedDocument, { selection, config }?: {
|
|
53
|
+
selection?: Selection;
|
|
54
|
+
config?: any;
|
|
55
|
+
});
|
|
56
|
+
/** @type {Selection | undefined} */
|
|
57
|
+
selection: Selection | undefined;
|
|
58
|
+
config: any;
|
|
59
|
+
document_id: any;
|
|
60
|
+
nodes: any;
|
|
61
|
+
history: any[];
|
|
62
|
+
history_index: number;
|
|
63
|
+
can_undo: boolean;
|
|
64
|
+
can_redo: boolean;
|
|
65
|
+
selected_node: any;
|
|
66
|
+
schema: DocumentSchema;
|
|
67
|
+
generate_id(): any;
|
|
68
|
+
get_selected_node(): any;
|
|
69
|
+
_apply_op(op: any): void;
|
|
70
|
+
/**
|
|
71
|
+
* Validate a node against the document schema.
|
|
72
|
+
* @param {any} node - The node to validate
|
|
73
|
+
* @throws {Error} Throws if the node is invalid
|
|
74
|
+
*/
|
|
75
|
+
validate_node(node: any): void;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new transaction for making atomic changes to the document.
|
|
78
|
+
*
|
|
79
|
+
* @returns {Transaction} A new transaction instance
|
|
80
|
+
*/
|
|
81
|
+
get tr(): Transaction;
|
|
82
|
+
/**
|
|
83
|
+
* Applies a transaction to the document.
|
|
84
|
+
*
|
|
85
|
+
* @param {Transaction} transaction - The transaction to apply
|
|
86
|
+
*/
|
|
87
|
+
apply(transaction: Transaction): this;
|
|
88
|
+
undo(): this;
|
|
89
|
+
redo(): this;
|
|
90
|
+
/**
|
|
91
|
+
* Gets a node instance or property value at the specified path.
|
|
92
|
+
* @param {DocumentPath|string} path - Path to the node or property
|
|
93
|
+
* @returns {any} Either a node instance object or the value of a property
|
|
94
|
+
* @example
|
|
95
|
+
* // Get a node by ID
|
|
96
|
+
* doc.get('list_1') // => { type: 'list', id: 'list_1', ... }
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // Get a node array property
|
|
100
|
+
* doc.get(['list_1', 'list_items']) // => [ 'list_item_1', 'list_item_2' ]
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // Get a specific node from an array
|
|
104
|
+
* doc.get(['page_1', 'body', 3, 'list_items', 0]) // => { type: 'list_item', id: 'list_item_1', ... }
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Get an annotated string property
|
|
108
|
+
* doc.get(['page_1', 'cover', 'title']) // => ['Hello world', []]
|
|
109
|
+
*/
|
|
110
|
+
get(path: DocumentPath | string): any;
|
|
111
|
+
/**
|
|
112
|
+
* While .get gives you the value of a path, inspect gives you
|
|
113
|
+
* the type info of that value.
|
|
114
|
+
*
|
|
115
|
+
* @todo The layout of these should be improved and more explictly typed
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* doc.inspect(['page_1', 'body']) => {
|
|
119
|
+
* kind: 'property',
|
|
120
|
+
* name: 'body',
|
|
121
|
+
* type: 'node_array',
|
|
122
|
+
* node_types: ['text', 'story', 'list'],
|
|
123
|
+
* default_node_type: 'text'
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* doc.inspect(['page_1', 'body', 1]) => {
|
|
128
|
+
* kind: 'node',
|
|
129
|
+
* id: 'paragraph_234',
|
|
130
|
+
* type: 'paragraph',
|
|
131
|
+
* properties: {...}
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* @param {DocumentPath} path
|
|
135
|
+
* @returns {{kind: 'property'|'node', [key: string]: any}}
|
|
136
|
+
*/
|
|
137
|
+
inspect(path: DocumentPath): {
|
|
138
|
+
kind: "property" | "node";
|
|
139
|
+
[key: string]: any;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Determines the kind of a node ('text' for pure text nodes or 'node' for anything else)
|
|
143
|
+
* NOTE: currently we assume a 'content' property for pure text nodes
|
|
144
|
+
* @param {any} node
|
|
145
|
+
* @returns {'text'|'node'}
|
|
146
|
+
*/
|
|
147
|
+
kind(node: any): "text" | "node";
|
|
148
|
+
/**
|
|
149
|
+
* Returns the annotation object that is currently "under the cursor".
|
|
150
|
+
* NOTE: Annotations in Svedit are exclusive, so there can only be one active_annotation
|
|
151
|
+
*
|
|
152
|
+
* @param {string} annotation_type
|
|
153
|
+
* @returns {Annotation|null}
|
|
154
|
+
*/
|
|
155
|
+
active_annotation(annotation_type: string): Annotation | null;
|
|
156
|
+
get_selected_plain_text(): any;
|
|
157
|
+
get_selected_nodes(): any;
|
|
158
|
+
move_node_cursor(direction: any): void;
|
|
159
|
+
expand_node_selection(direction: any): void;
|
|
160
|
+
select_parent(): void;
|
|
161
|
+
get_selection_range(): {
|
|
162
|
+
start: number;
|
|
163
|
+
end: number;
|
|
164
|
+
length: number;
|
|
165
|
+
};
|
|
166
|
+
traverse(node_id: any): any[];
|
|
167
|
+
/**
|
|
168
|
+
* Convert the document to serialized format.
|
|
169
|
+
* @returns {SerializedDocument} The serialized document array
|
|
170
|
+
*/
|
|
171
|
+
to_json(): SerializedDocument;
|
|
172
|
+
property_type(type: any, property: any): "string" | "number" | "boolean" | "node" | "node_array" | "integer" | "datetime" | "string_array" | "number_array" | "boolean_array" | "integer_array" | "annotated_string";
|
|
173
|
+
count_references(node_id: any): number;
|
|
174
|
+
/**
|
|
175
|
+
* @param {NodeId} node_id
|
|
176
|
+
* @returns {NodeId[]}
|
|
177
|
+
*/
|
|
178
|
+
get_referenced_nodes(node_id: NodeId): NodeId[];
|
|
179
|
+
}
|
|
180
|
+
import type { DocumentSchemaPrimitive } from './types.d.ts';
|
|
181
|
+
import type { PrimitiveType } from './types.d.ts';
|
|
182
|
+
import type { NodeProperty } from './types.d.ts';
|
|
183
|
+
import type { NodeArrayProperty } from './types.d.ts';
|
|
184
|
+
import type { DocumentSchema } from './types.d.ts';
|
|
185
|
+
import type { Selection } from './types.d.ts';
|
|
186
|
+
import Transaction from './Transaction.svelte.js';
|
|
187
|
+
import type { DocumentPath } from './types.d.ts';
|
|
188
|
+
import type { Annotation } from './types.d.ts';
|
|
189
|
+
import type { SerializedDocument } from './types.d.ts';
|
|
190
|
+
import type { NodeId } from './types.d.ts';
|
|
191
|
+
//# sourceMappingURL=Document.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Document.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Document.svelte.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AACH,uCAJ+E,CAAC,SAAlE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;IAAC,IAAI,EAAE,uBAAuB,CAAA;CAAC,CAAC,CAAE,UACnE,CAAC,GACC,CAAC,CAIb;AAED;;;;GAIG;AACH,wCAHW,MAAM,GACJ,IAAI,IAAI,aAAa,CAQjC;AAED;;;;GAIG;AACH,2DAHW,YAAY,GAAG,iBAAiB,GAC9B,MAAM,GAAG,IAAI,CASzB;AAED;;;;GAIG;AACH,0DAHW,cAAc,QAexB;AAuGD;IAgBE;;;;;;OAMG;IACH,oBANW,cAAc,kBACd,kBAAkB,0BAE1B;QAA4B,SAAS,GAA7B,SAAS;QACK,MAAM,GAApB,GAAG;KACb,EAmBA;IAxCD,oCAAoC;IACpC,WADW,SAAS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