@umbraci/jsmind 0.9.1-rich-text

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.
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Event callback payload
3
+ * @typedef {{ evt?: string, data?: unknown[], node?: string }} EventData
4
+ */
5
+ /**
6
+ * jsMind runtime: orchestrates data/layout/view/shortcut and exposes public API.
7
+ */
8
+ export default class jsMind {
9
+ static mind: typeof Mind;
10
+ static node: typeof Node;
11
+ static direction: import("./jsmind.common.js").DirectionType;
12
+ static event_type: {
13
+ show: number;
14
+ resize: number;
15
+ edit: number;
16
+ select: number;
17
+ };
18
+ static $: {
19
+ w: Window;
20
+ d: Document;
21
+ g: (id: string) => HTMLElement | null;
22
+ c: (tag: string) => HTMLElement;
23
+ t: (n: HTMLElement, t: string) => void;
24
+ h: (n: HTMLElement, t: string | HTMLElement) => void;
25
+ i: (el: unknown) => el is HTMLElement;
26
+ on: (t: HTMLElement, e: string, h: (ev: Event) => void) => void;
27
+ };
28
+ static plugin: typeof Plugin;
29
+ static register_plugin: typeof _register_plugin;
30
+ static util: {
31
+ file: {
32
+ read: (file: File, cb: (result: string, name: string) => void) => void;
33
+ save: (data: string, type: string, name: string) => void;
34
+ };
35
+ json: {
36
+ json2string: (v: unknown) => string;
37
+ string2json: (s: string) => unknown;
38
+ merge: (b: object, a: object) => object;
39
+ };
40
+ uuid: {
41
+ newid: () => string;
42
+ };
43
+ text: {
44
+ is_empty: (s?: string) => boolean;
45
+ };
46
+ };
47
+ /**
48
+ * Deprecated: static show constructor helper.
49
+ * @param {import('./jsmind.option.js').JsMindRuntimeOptions} options
50
+ * @param {object | null} mind
51
+ * @returns {jsMind}
52
+ */
53
+ static show(options: import("./jsmind.option.js").JsMindRuntimeOptions, mind: object | null): jsMind;
54
+ /**
55
+ * Create a jsMind instance.
56
+ * @param {import('./jsmind.option.js').JsMindRuntimeOptions} options
57
+ */
58
+ constructor(options: import("./jsmind.option.js").JsMindRuntimeOptions);
59
+ options: import("./jsmind.option.js").JsMindRuntimeOptions;
60
+ version: string;
61
+ initialized: boolean;
62
+ mind: Mind;
63
+ /** @type {Array<(type: number, data: EventData) => void>} */
64
+ event_handles: Array<(type: number, data: EventData) => void>;
65
+ /** Initialize sub-systems and plugins. */
66
+ init(): void;
67
+ data: DataProvider;
68
+ layout: LayoutProvider;
69
+ view: ViewProvider;
70
+ shortcut: ShortcutProvider;
71
+ /** @returns {boolean} whether current mind map is editable */
72
+ get_editable(): boolean;
73
+ /** enable editing */
74
+ enable_edit(): void;
75
+ /** disable editing */
76
+ disable_edit(): void;
77
+ /** @returns {boolean} whether view is draggable */
78
+ get_view_draggable(): boolean;
79
+ /** enable view dragging */
80
+ enable_view_draggable(): void;
81
+ /** disable view dragging */
82
+ disable_view_draggable(): void;
83
+ /**
84
+ * Enable default event handle.
85
+ * @param {'mousedown'|'click'|'dblclick'|'mousewheel'} event_handle
86
+ */
87
+ enable_event_handle(event_handle: "mousedown" | "click" | "dblclick" | "mousewheel"): void;
88
+ /**
89
+ * Disable default event handle.
90
+ * @param {'mousedown'|'click'|'dblclick'|'mousewheel'} event_handle
91
+ */
92
+ disable_event_handle(event_handle: "mousedown" | "click" | "dblclick" | "mousewheel"): void;
93
+ /**
94
+ * Set theme name.
95
+ * @param {string|null=} theme
96
+ */
97
+ set_theme(theme?: (string | null) | undefined): void;
98
+ /** bind internal DOM events */
99
+ _event_bind(): void;
100
+ /** @param {MouseEvent} e */
101
+ mousedown_handle(e: MouseEvent): void;
102
+ /** @param {MouseEvent} e */
103
+ click_handle(e: MouseEvent): void;
104
+ /** @param {MouseEvent} e */
105
+ dblclick_handle(e: MouseEvent): void;
106
+ /** @param {WheelEvent} e */
107
+ mousewheel_handle(e: WheelEvent): void;
108
+ /**
109
+ * Begin editing a node.
110
+ * @param {string | import('./jsmind.node.js').Node} node
111
+ * @returns {boolean|void}
112
+ */
113
+ begin_edit(node: string | import("./jsmind.node.js").Node): boolean | void;
114
+ /** End editing */
115
+ end_edit(): void;
116
+ /**
117
+ * Toggle a node's expanded state.
118
+ * @param {string | import('./jsmind.node.js').Node} node
119
+ * @returns {void}
120
+ */
121
+ toggle_node(node: string | import("./jsmind.node.js").Node): void;
122
+ /**
123
+ * Expand a node.
124
+ * @param {string | import('./jsmind.node.js').Node} node
125
+ * @returns {void}
126
+ */
127
+ expand_node(node: string | import("./jsmind.node.js").Node): void;
128
+ /**
129
+ * Collapse a node.
130
+ * @param {string | import('./jsmind.node.js').Node} node
131
+ * @returns {void}
132
+ */
133
+ collapse_node(node: string | import("./jsmind.node.js").Node): void;
134
+ /** Expand all nodes */
135
+ expand_all(): void;
136
+ /** Collapse all nodes */
137
+ collapse_all(): void;
138
+ /**
139
+ * Expand nodes up to a specified depth level.
140
+ * @param {number} depth
141
+ */
142
+ expand_to_depth(depth: number): void;
143
+ /** reset view/layout/data */
144
+ _reset(): void;
145
+ /**
146
+ * Internal show flow.
147
+ * @param {object | null} mind
148
+ * @param {boolean=} skip_centering
149
+ */
150
+ _show(mind: object | null, skip_centering?: boolean | undefined): void;
151
+ /**
152
+ * Show a mind (or example) on the canvas.
153
+ * @param {object | null} mind
154
+ * @param {boolean=} skip_centering
155
+ */
156
+ show(mind: object | null, skip_centering?: boolean | undefined): void;
157
+ /** @returns {{name:string,author:string,version:string}} */
158
+ get_meta(): {
159
+ name: string;
160
+ author: string;
161
+ version: string;
162
+ };
163
+ /**
164
+ * Serialize current mind to given format.
165
+ * @param {'node_tree'|'node_array'|'freemind'|'text'} [data_format]
166
+ * @returns {object}
167
+ */
168
+ get_data(data_format?: "node_tree" | "node_array" | "freemind" | "text"): object;
169
+ /** @returns {import('./jsmind.node.js').Node} */
170
+ get_root(): import("./jsmind.node.js").Node;
171
+ /**
172
+ * @param {string | import('./jsmind.node.js').Node} node
173
+ * @returns {import('./jsmind.node.js').Node}
174
+ */
175
+ get_node(node: string | import("./jsmind.node.js").Node): import("./jsmind.node.js").Node;
176
+ /**
177
+ * Add node data to the mind map without triggering UI refresh.
178
+ * @private
179
+ * @param {import('./jsmind.node.js').Node} parent_node
180
+ * @param {string} node_id
181
+ * @param {string} topic
182
+ * @param {Record<string, any>=} data
183
+ * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction
184
+ * @returns {import('./jsmind.node.js').Node|null}
185
+ */
186
+ private _add_node_data;
187
+ /**
188
+ * Refresh UI after node changes.
189
+ * @private
190
+ * @param {import('./jsmind.node.js').Node} parent_node
191
+ */
192
+ private _refresh_node_ui;
193
+ /**
194
+ * Add a new node to the mind map.
195
+ * @param {string | import('./jsmind.node.js').Node} parent_node
196
+ * @param {string} node_id
197
+ * @param {string} topic
198
+ * @param {Record<string, any>=} data
199
+ * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction - Direction for node placement. Supports string values ('left', 'center', 'right'), numeric strings ('-1', '0', '1'), and numbers (-1, 0, 1)
200
+ * @returns {import('./jsmind.node.js').Node|null}
201
+ */
202
+ add_node(parent_node: string | import("./jsmind.node.js").Node, node_id: string, topic: string, data?: Record<string, any> | undefined, direction?: ("left" | "center" | "right" | "-1" | "0" | "1" | number) | undefined): import("./jsmind.node.js").Node | null;
203
+ /**
204
+ * Add multiple nodes to the mind map with optimized performance.
205
+ * @param {string | import('./jsmind.node.js').Node} parent_node - Parent node for all new nodes
206
+ * @param {Array<{node_id: string, topic: string, data?: Record<string, any>, direction?: ('left'|'center'|'right'|'-1'|'0'|'1'|number)}>} nodes_data - Array of node data objects
207
+ * @returns {Array<import('./jsmind.node.js').Node|null>} Array of created nodes
208
+ */
209
+ add_nodes(parent_node: string | import("./jsmind.node.js").Node, nodes_data: Array<{
210
+ node_id: string;
211
+ topic: string;
212
+ data?: Record<string, any>;
213
+ direction?: ("left" | "center" | "right" | "-1" | "0" | "1" | number);
214
+ }>): Array<import("./jsmind.node.js").Node | null>;
215
+ /**
216
+ * Insert a node before target node.
217
+ * @param {string | import('./jsmind.node.js').Node} node_before
218
+ * @param {string} node_id
219
+ * @param {string} topic
220
+ * @param {Record<string, any>=} data
221
+ * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction - Direction for node placement. Supports string values ('left', 'center', 'right'), numeric strings ('-1', '0', '1'), and numbers (-1, 0, 1)
222
+ * @returns {import('./jsmind.node.js').Node|null}
223
+ */
224
+ insert_node_before(node_before: string | import("./jsmind.node.js").Node, node_id: string, topic: string, data?: Record<string, any> | undefined, direction?: ("left" | "center" | "right" | "-1" | "0" | "1" | number) | undefined): import("./jsmind.node.js").Node | null;
225
+ /**
226
+ * Insert a node after target node.
227
+ * @param {string | import('./jsmind.node.js').Node} node_after
228
+ * @param {string} node_id
229
+ * @param {string} topic
230
+ * @param {Record<string, any>=} data
231
+ * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction - Direction for node placement. Supports string values ('left', 'center', 'right'), numeric strings ('-1', '0', '1'), and numbers (-1, 0, 1)
232
+ * @returns {import('./jsmind.node.js').Node|null}
233
+ */
234
+ insert_node_after(node_after: string | import("./jsmind.node.js").Node, node_id: string, topic: string, data?: Record<string, any> | undefined, direction?: ("left" | "center" | "right" | "-1" | "0" | "1" | number) | undefined): import("./jsmind.node.js").Node | null;
235
+ /**
236
+ * Remove a node.
237
+ * @param {string | import('./jsmind.node.js').Node} node
238
+ * @returns {boolean}
239
+ */
240
+ remove_node(node: string | import("./jsmind.node.js").Node): boolean;
241
+ /**
242
+ * Update the topic (text content) of a node.
243
+ * @param {string} node_id
244
+ * @param {string} topic
245
+ */
246
+ update_node(node_id: string, topic: string): void;
247
+ /**
248
+ * Move a node and optionally change direction.
249
+ * @param {string} node_id
250
+ * @param {string=} before_id - The ID of the node before which to place the moved node. Special values: "_first_", "_last_"
251
+ * @param {string=} parent_id
252
+ * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction - Direction for node placement. Supports string values ('left', 'center', 'right'), numeric strings ('-1', '0', '1'), and numbers (-1, 0, 1). Only effective for second-level nodes (children of root). If not provided, direction will be determined automatically.
253
+ */
254
+ move_node(node_id: string, before_id?: string | undefined, parent_id?: string | undefined, direction?: ("left" | "center" | "right" | "-1" | "0" | "1" | number) | undefined): void;
255
+ /**
256
+ * @param {string | import('./jsmind.node.js').Node} node
257
+ * @returns {void}
258
+ */
259
+ select_node(node: string | import("./jsmind.node.js").Node): void;
260
+ /** @returns {import('./jsmind.node.js').Node|null} */
261
+ get_selected_node(): import("./jsmind.node.js").Node | null;
262
+ /** clear selection */
263
+ select_clear(): void;
264
+ /** @param {string | import('./jsmind.node.js').Node} node */
265
+ is_node_visible(node: string | import("./jsmind.node.js").Node): boolean;
266
+ /**
267
+ * Scroll the mind map to center the specified node.
268
+ * @param {string | import('./jsmind.node.js').Node} node
269
+ */
270
+ scroll_node_to_center(node: string | import("./jsmind.node.js").Node): void;
271
+ /**
272
+ * Find the previous sibling node of the given node.
273
+ *
274
+ * @param {string | import('./jsmind.node.js').Node} node - Node id or Node instance
275
+ * @returns {import('./jsmind.node.js').Node | null}
276
+ */
277
+ find_node_before(node: string | import("./jsmind.node.js").Node): import("./jsmind.node.js").Node | null;
278
+ /**
279
+ * Find the next sibling node of the given node.
280
+ * @param {string | import('./jsmind.node.js').Node} node
281
+ * @returns {import('./jsmind.node.js').Node | null}
282
+ */
283
+ find_node_after(node: string | import("./jsmind.node.js").Node): import("./jsmind.node.js").Node | null;
284
+ /**
285
+ * Set background and foreground colors for a node.
286
+ * @param {string} node_id
287
+ * @param {string=} bg_color
288
+ * @param {string=} fg_color
289
+ * @returns {void}
290
+ */
291
+ set_node_color(node_id: string, bg_color?: string | undefined, fg_color?: string | undefined): void;
292
+ /**
293
+ * Set font style for a node.
294
+ * @param {string} node_id
295
+ * @param {number=} size
296
+ * @param {string=} weight
297
+ * @param {string=} style
298
+ * @returns {void}
299
+ */
300
+ set_node_font_style(node_id: string, size?: number | undefined, weight?: string | undefined, style?: string | undefined): void;
301
+ /**
302
+ * Set background image for a node.
303
+ * @param {string} node_id
304
+ * @param {string=} image
305
+ * @param {number=} width
306
+ * @param {number=} height
307
+ * @param {number=} rotation
308
+ * @returns {void}
309
+ */
310
+ set_node_background_image(node_id: string, image?: string | undefined, width?: number | undefined, height?: number | undefined, rotation?: number | undefined): void;
311
+ /**
312
+ * @param {string} node_id
313
+ * @param {number} rotation
314
+ * @returns {void}
315
+ */
316
+ set_node_background_rotation(node_id: string, rotation: number): void;
317
+ /** trigger view resize */
318
+ resize(): void;
319
+ /** @param {(type:number, data: EventData)=>void} callback */
320
+ add_event_listener(callback: (type: number, data: EventData) => void): void;
321
+ /** clear event listeners */
322
+ clear_event_listener(): void;
323
+ /** @param {number} type @param {EventData} data */
324
+ invoke_event_handle(type: number, data: EventData): void;
325
+ /** @param {number} type @param {EventData} data */
326
+ _invoke_event_handle(type: number, data: EventData): void;
327
+ }
328
+ /**
329
+ * Event callback payload
330
+ */
331
+ export type EventData = {
332
+ evt?: string;
333
+ data?: unknown[];
334
+ node?: string;
335
+ };
336
+ import { Mind } from './jsmind.mind.js';
337
+ import { DataProvider } from './jsmind.data_provider.js';
338
+ import { LayoutProvider } from './jsmind.layout_provider.js';
339
+ import { ViewProvider } from './jsmind.view_provider.js';
340
+ import { ShortcutProvider } from './jsmind.shortcut_provider.js';
341
+ import { Node } from './jsmind.node.js';
342
+ import { Plugin } from './jsmind.plugin.js';
343
+ import { register as _register_plugin } from './jsmind.plugin.js';
@@ -0,0 +1,56 @@
1
+ export class DataProvider {
2
+ /**
3
+ * Data provider: loads and serializes mind data by format.
4
+ * @param {import('./jsmind.js').default} jm - jsMind instance
5
+ */
6
+ constructor(jm: import("./jsmind.js").default);
7
+ jm: import("./jsmind.js").default;
8
+ /** Initialize data provider. */
9
+ init(): void;
10
+ /** Reset data provider state. */
11
+ reset(): void;
12
+ /**
13
+ * Load a Mind from mixed source.
14
+ * @param {import('./jsmind.format.js').NodeTreeFormat|import('./jsmind.format.js').NodeArrayFormat|{meta?:{name:string,author:string,version:string},format:'freemind',data:string}|{meta?:{name:string,author:string,version:string},format:'text',data:string}} mind_data - object with {format,data} or a format-specific payload
15
+ * @returns {import('./jsmind.mind.js').Mind|null}
16
+ */
17
+ load(mind_data: import("./jsmind.format.js").NodeTreeFormat | import("./jsmind.format.js").NodeArrayFormat | {
18
+ meta?: {
19
+ name: string;
20
+ author: string;
21
+ version: string;
22
+ };
23
+ format: "freemind";
24
+ data: string;
25
+ } | {
26
+ meta?: {
27
+ name: string;
28
+ author: string;
29
+ version: string;
30
+ };
31
+ format: "text";
32
+ data: string;
33
+ }): import("./jsmind.mind.js").Mind | null;
34
+ /**
35
+ * Serialize current mind to target format.
36
+ * @param {'node_tree'|'node_array'|'freemind'|'text'} data_format
37
+ * @returns {import('./jsmind.format.js').NodeTreeFormat|import('./jsmind.format.js').NodeArrayFormat|{meta:{name:string,author:string,version:string},format:'freemind',data:string}|{meta:{name:string,author:string,version:string},format:'text',data:string}}
38
+ */
39
+ get_data(data_format: "node_tree" | "node_array" | "freemind" | "text"): import("./jsmind.format.js").NodeTreeFormat | import("./jsmind.format.js").NodeArrayFormat | {
40
+ meta: {
41
+ name: string;
42
+ author: string;
43
+ version: string;
44
+ };
45
+ format: "freemind";
46
+ data: string;
47
+ } | {
48
+ meta: {
49
+ name: string;
50
+ author: string;
51
+ version: string;
52
+ };
53
+ format: "text";
54
+ data: string;
55
+ };
56
+ }
@@ -0,0 +1,59 @@
1
+ export const $: Dom;
2
+ /**
3
+ * @license BSD
4
+ * @copyright 2014-2025 hizzgdev@163.com
5
+ *
6
+ * Project Home:
7
+ * https://github.com/hizzgdev/jsmind/
8
+ */
9
+ /**
10
+ * Lightweight DOM helpers bound to a window.
11
+ */
12
+ declare class Dom {
13
+ /**
14
+ * @param {Window} w
15
+ */
16
+ constructor(w: Window);
17
+ /** @type {Window} */
18
+ w: Window;
19
+ /** @type {Document} */
20
+ d: Document;
21
+ /**
22
+ * Get element by id.
23
+ * @param {string} id
24
+ * @returns {HTMLElement|null}
25
+ */
26
+ g: (id: string) => HTMLElement | null;
27
+ /**
28
+ * Create element with given tag.
29
+ * @param {string} tag
30
+ * @returns {HTMLElement}
31
+ */
32
+ c: (tag: string) => HTMLElement;
33
+ /**
34
+ * Set text content for element.
35
+ * @param {HTMLElement} n
36
+ * @param {string} t
37
+ */
38
+ t: (n: HTMLElement, t: string) => void;
39
+ /**
40
+ * Set inner HTML or append element.
41
+ * @param {HTMLElement} n
42
+ * @param {string|HTMLElement} t
43
+ */
44
+ h: (n: HTMLElement, t: string | HTMLElement) => void;
45
+ /**
46
+ * Runtime check for HTMLElement.
47
+ * @param {unknown} el
48
+ * @returns {el is HTMLElement}
49
+ */
50
+ i: (el: unknown) => el is HTMLElement;
51
+ /**
52
+ * Add event listener with legacy fallback.
53
+ * @param {HTMLElement} t
54
+ * @param {string} e
55
+ * @param {(ev:Event)=>void} h
56
+ */
57
+ on: (t: HTMLElement, e: string, h: (ev: Event) => void) => void;
58
+ }
59
+ export {};
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Mind data format handlers.
3
+ * @type {{
4
+ * node_tree: { example:NodeTreeFormat, get_mind:(src:NodeTreeFormat)=>Mind, get_data:(mind:Mind)=>NodeTreeFormat },
5
+ * node_array: { example:NodeArrayFormat, get_mind:(src:NodeArrayFormat)=>Mind, get_data:(mind:Mind)=>NodeArrayFormat },
6
+ * freemind: { example:{meta:MindMapMeta,format:'freemind',data:string}, get_mind:(src:{meta?:MindMapMeta,format:'freemind',data:string})=>Mind, get_data:(mind:Mind)=>{meta:MindMapMeta,format:'freemind',data:string} },
7
+ * text: { example:{meta:MindMapMeta,format:'text',data:string}, get_mind:(src:{meta?:MindMapMeta,format:'text',data:string})=>Mind, get_data:(mind:Mind)=>{meta:MindMapMeta,format:'text',data:string} }
8
+ * }}
9
+ */
10
+ export const format: {
11
+ node_tree: {
12
+ example: NodeTreeFormat;
13
+ get_mind: (src: NodeTreeFormat) => Mind;
14
+ get_data: (mind: Mind) => NodeTreeFormat;
15
+ };
16
+ node_array: {
17
+ example: NodeArrayFormat;
18
+ get_mind: (src: NodeArrayFormat) => Mind;
19
+ get_data: (mind: Mind) => NodeArrayFormat;
20
+ };
21
+ freemind: {
22
+ example: {
23
+ meta: MindMapMeta;
24
+ format: "freemind";
25
+ data: string;
26
+ };
27
+ get_mind: (src: {
28
+ meta?: MindMapMeta;
29
+ format: "freemind";
30
+ data: string;
31
+ }) => Mind;
32
+ get_data: (mind: Mind) => {
33
+ meta: MindMapMeta;
34
+ format: "freemind";
35
+ data: string;
36
+ };
37
+ };
38
+ text: {
39
+ example: {
40
+ meta: MindMapMeta;
41
+ format: "text";
42
+ data: string;
43
+ };
44
+ get_mind: (src: {
45
+ meta?: MindMapMeta;
46
+ format: "text";
47
+ data: string;
48
+ }) => Mind;
49
+ get_data: (mind: Mind) => {
50
+ meta: MindMapMeta;
51
+ format: "text";
52
+ data: string;
53
+ };
54
+ };
55
+ };
56
+ export type MindMapMeta = {
57
+ name: string;
58
+ author: string;
59
+ version: string;
60
+ };
61
+ /**
62
+ * Node tree data item
63
+ */
64
+ export type NodeTreeData = {
65
+ id: string;
66
+ topic: string;
67
+ data?: Record<string, any>;
68
+ direction?: (number | string);
69
+ expanded?: boolean;
70
+ children?: NodeTreeData[];
71
+ };
72
+ /**
73
+ * Node tree formatted payload
74
+ */
75
+ export type NodeTreeFormat = {
76
+ meta?: MindMapMeta;
77
+ format: "node_tree";
78
+ data: NodeTreeData;
79
+ };
80
+ /**
81
+ * Node array data item
82
+ */
83
+ export type NodeArrayItem = {
84
+ id: string;
85
+ topic: string;
86
+ parentid?: string;
87
+ data?: Record<string, any>;
88
+ direction?: (number | string);
89
+ expanded?: boolean;
90
+ isroot?: boolean;
91
+ };
92
+ /**
93
+ * Node array formatted payload
94
+ */
95
+ export type NodeArrayFormat = {
96
+ meta?: MindMapMeta;
97
+ format: "node_array";
98
+ data: NodeArrayItem[];
99
+ };
100
+ import { Mind } from './jsmind.mind.js';