@vizel/svelte 0.0.1-alpha.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.
- package/README.md +83 -0
- package/dist/components/Vizel.svelte +158 -0
- package/dist/components/Vizel.svelte.d.ts +82 -0
- package/dist/components/Vizel.svelte.d.ts.map +1 -0
- package/dist/components/VizelBubbleMenu.svelte +96 -0
- package/dist/components/VizelBubbleMenu.svelte.d.ts +28 -0
- package/dist/components/VizelBubbleMenu.svelte.d.ts.map +1 -0
- package/dist/components/VizelBubbleMenuButton.svelte +45 -0
- package/dist/components/VizelBubbleMenuButton.svelte.d.ts +21 -0
- package/dist/components/VizelBubbleMenuButton.svelte.d.ts.map +1 -0
- package/dist/components/VizelBubbleMenuColorPicker.svelte +135 -0
- package/dist/components/VizelBubbleMenuColorPicker.svelte.d.ts +19 -0
- package/dist/components/VizelBubbleMenuColorPicker.svelte.d.ts.map +1 -0
- package/dist/components/VizelBubbleMenuDefault.svelte +111 -0
- package/dist/components/VizelBubbleMenuDefault.svelte.d.ts +13 -0
- package/dist/components/VizelBubbleMenuDefault.svelte.d.ts.map +1 -0
- package/dist/components/VizelBubbleMenuDivider.svelte +12 -0
- package/dist/components/VizelBubbleMenuDivider.svelte.d.ts +8 -0
- package/dist/components/VizelBubbleMenuDivider.svelte.d.ts.map +1 -0
- package/dist/components/VizelColorPicker.svelte +269 -0
- package/dist/components/VizelColorPicker.svelte.d.ts +25 -0
- package/dist/components/VizelColorPicker.svelte.d.ts.map +1 -0
- package/dist/components/VizelContext.d.ts +27 -0
- package/dist/components/VizelContext.d.ts.map +1 -0
- package/dist/components/VizelContext.js +34 -0
- package/dist/components/VizelEditor.svelte +61 -0
- package/dist/components/VizelEditor.svelte.d.ts +17 -0
- package/dist/components/VizelEditor.svelte.d.ts.map +1 -0
- package/dist/components/VizelEmbedView.svelte +162 -0
- package/dist/components/VizelEmbedView.svelte.d.ts +13 -0
- package/dist/components/VizelEmbedView.svelte.d.ts.map +1 -0
- package/dist/components/VizelIcon.svelte +54 -0
- package/dist/components/VizelIcon.svelte.d.ts +32 -0
- package/dist/components/VizelIcon.svelte.d.ts.map +1 -0
- package/dist/components/VizelIconContext.d.ts +27 -0
- package/dist/components/VizelIconContext.d.ts.map +1 -0
- package/dist/components/VizelIconContext.js +31 -0
- package/dist/components/VizelIconProvider.svelte +43 -0
- package/dist/components/VizelIconProvider.svelte.d.ts +31 -0
- package/dist/components/VizelIconProvider.svelte.d.ts.map +1 -0
- package/dist/components/VizelLinkEditor.svelte +143 -0
- package/dist/components/VizelLinkEditor.svelte.d.ts +15 -0
- package/dist/components/VizelLinkEditor.svelte.d.ts.map +1 -0
- package/dist/components/VizelNodeSelector.svelte +172 -0
- package/dist/components/VizelNodeSelector.svelte.d.ts +13 -0
- package/dist/components/VizelNodeSelector.svelte.d.ts.map +1 -0
- package/dist/components/VizelPortal.svelte +70 -0
- package/dist/components/VizelPortal.svelte.d.ts +19 -0
- package/dist/components/VizelPortal.svelte.d.ts.map +1 -0
- package/dist/components/VizelProvider.svelte +26 -0
- package/dist/components/VizelProvider.svelte.d.ts +14 -0
- package/dist/components/VizelProvider.svelte.d.ts.map +1 -0
- package/dist/components/VizelSaveIndicator.svelte +94 -0
- package/dist/components/VizelSaveIndicator.svelte.d.ts +15 -0
- package/dist/components/VizelSaveIndicator.svelte.d.ts.map +1 -0
- package/dist/components/VizelSlashMenu.svelte +211 -0
- package/dist/components/VizelSlashMenu.svelte.d.ts +31 -0
- package/dist/components/VizelSlashMenu.svelte.d.ts.map +1 -0
- package/dist/components/VizelSlashMenuEmpty.svelte +22 -0
- package/dist/components/VizelSlashMenuEmpty.svelte.d.ts +11 -0
- package/dist/components/VizelSlashMenuEmpty.svelte.d.ts.map +1 -0
- package/dist/components/VizelSlashMenuItem.svelte +57 -0
- package/dist/components/VizelSlashMenuItem.svelte.d.ts +17 -0
- package/dist/components/VizelSlashMenuItem.svelte.d.ts.map +1 -0
- package/dist/components/VizelThemeProvider.svelte +79 -0
- package/dist/components/VizelThemeProvider.svelte.d.ts +11 -0
- package/dist/components/VizelThemeProvider.svelte.d.ts.map +1 -0
- package/dist/components/index.d.ts +23 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +64 -0
- package/dist/iconRenderer.d.ts +6 -0
- package/dist/iconRenderer.d.ts.map +1 -0
- package/dist/iconRenderer.js +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/runes/createVizelAutoSave.svelte.d.ts +44 -0
- package/dist/runes/createVizelAutoSave.svelte.d.ts.map +1 -0
- package/dist/runes/createVizelAutoSave.svelte.js +91 -0
- package/dist/runes/createVizelEditor.svelte.d.ts +43 -0
- package/dist/runes/createVizelEditor.svelte.d.ts.map +1 -0
- package/dist/runes/createVizelEditor.svelte.js +65 -0
- package/dist/runes/createVizelEditorState.svelte.d.ts +27 -0
- package/dist/runes/createVizelEditorState.svelte.d.ts.map +1 -0
- package/dist/runes/createVizelEditorState.svelte.js +35 -0
- package/dist/runes/createVizelMarkdown.svelte.d.ts +68 -0
- package/dist/runes/createVizelMarkdown.svelte.d.ts.map +1 -0
- package/dist/runes/createVizelMarkdown.svelte.js +123 -0
- package/dist/runes/createVizelSlashMenuRenderer.d.ts +22 -0
- package/dist/runes/createVizelSlashMenuRenderer.d.ts.map +1 -0
- package/dist/runes/createVizelSlashMenuRenderer.js +84 -0
- package/dist/runes/createVizelState.svelte.d.ts +22 -0
- package/dist/runes/createVizelState.svelte.d.ts.map +1 -0
- package/dist/runes/createVizelState.svelte.js +50 -0
- package/dist/runes/getVizelTheme.svelte.d.ts +23 -0
- package/dist/runes/getVizelTheme.svelte.d.ts.map +1 -0
- package/dist/runes/getVizelTheme.svelte.js +31 -0
- package/dist/runes/index.d.ts +8 -0
- package/dist/runes/index.d.ts.map +1 -0
- package/dist/runes/index.js +7 -0
- package/package.json +64 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Editor, type VizelEditorState } from "@vizel/core";
|
|
2
|
+
/**
|
|
3
|
+
* Rune that returns the current editor state and updates on state changes.
|
|
4
|
+
* This is a convenience rune that combines `createVizelState` (for reactivity)
|
|
5
|
+
* and `getVizelEditorState` (for state extraction).
|
|
6
|
+
*
|
|
7
|
+
* @param getEditor - A function that returns the editor instance
|
|
8
|
+
* @returns An object with a `current` getter for the editor state
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```svelte
|
|
12
|
+
* <script lang="ts">
|
|
13
|
+
* const editorState = createVizelEditorState(() => editor);
|
|
14
|
+
* </script>
|
|
15
|
+
*
|
|
16
|
+
* <div class="status-bar">
|
|
17
|
+
* <span>{editorState.current.characterCount} characters</span>
|
|
18
|
+
* <span>{editorState.current.wordCount} words</span>
|
|
19
|
+
* <button disabled={!editorState.current.canUndo}>Undo</button>
|
|
20
|
+
* <button disabled={!editorState.current.canRedo}>Redo</button>
|
|
21
|
+
* </div>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createVizelEditorState(getEditor: () => Editor | null | undefined): {
|
|
25
|
+
readonly current: VizelEditorState;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=createVizelEditorState.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVizelEditorState.svelte.d.ts","sourceRoot":"","sources":["../../src/runes/createVizelEditorState.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAuB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGtF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG;IAClF,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;CACpC,CAWA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getVizelEditorState } from "@vizel/core";
|
|
2
|
+
import { createVizelState } from "./createVizelState.svelte.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Rune that returns the current editor state and updates on state changes.
|
|
5
|
+
* This is a convenience rune that combines `createVizelState` (for reactivity)
|
|
6
|
+
* and `getVizelEditorState` (for state extraction).
|
|
7
|
+
*
|
|
8
|
+
* @param getEditor - A function that returns the editor instance
|
|
9
|
+
* @returns An object with a `current` getter for the editor state
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <script lang="ts">
|
|
14
|
+
* const editorState = createVizelEditorState(() => editor);
|
|
15
|
+
* </script>
|
|
16
|
+
*
|
|
17
|
+
* <div class="status-bar">
|
|
18
|
+
* <span>{editorState.current.characterCount} characters</span>
|
|
19
|
+
* <span>{editorState.current.wordCount} words</span>
|
|
20
|
+
* <button disabled={!editorState.current.canUndo}>Undo</button>
|
|
21
|
+
* <button disabled={!editorState.current.canRedo}>Redo</button>
|
|
22
|
+
* </div>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function createVizelEditorState(getEditor) {
|
|
26
|
+
// Subscribe to editor state changes for reactivity
|
|
27
|
+
const state = createVizelState(getEditor);
|
|
28
|
+
return {
|
|
29
|
+
get current() {
|
|
30
|
+
// Access state.current to establish reactivity dependency
|
|
31
|
+
void state.current;
|
|
32
|
+
return getVizelEditorState(getEditor());
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Editor, type VizelMarkdownSyncOptions } from "@vizel/core";
|
|
2
|
+
export interface CreateVizelMarkdownOptions extends VizelMarkdownSyncOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Initial markdown value. If provided, this will be set to the editor on mount.
|
|
5
|
+
*/
|
|
6
|
+
initialValue?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CreateVizelMarkdownResult {
|
|
9
|
+
/**
|
|
10
|
+
* Current markdown content (reactive getter).
|
|
11
|
+
* Updates with debounce when editor content changes.
|
|
12
|
+
*/
|
|
13
|
+
readonly markdown: string;
|
|
14
|
+
/**
|
|
15
|
+
* Set markdown content to the editor.
|
|
16
|
+
* Automatically transforms diagram code blocks if transformDiagrams is enabled.
|
|
17
|
+
*/
|
|
18
|
+
setMarkdown: (markdown: string) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Whether markdown export is currently pending (debounced).
|
|
21
|
+
*/
|
|
22
|
+
readonly isPending: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Force immediate export (flush pending debounced export).
|
|
25
|
+
*/
|
|
26
|
+
flush: () => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Svelte 5 rune for bidirectional Markdown synchronization with the editor.
|
|
30
|
+
*
|
|
31
|
+
* @param getEditor - Function to get the editor instance
|
|
32
|
+
* @param options - Sync options
|
|
33
|
+
* @returns Markdown state and control functions
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```svelte
|
|
37
|
+
* <script lang="ts">
|
|
38
|
+
* import { createVizelEditor, createVizelMarkdown, VizelEditor } from '@vizel/svelte';
|
|
39
|
+
*
|
|
40
|
+
* const editorState = createVizelEditor();
|
|
41
|
+
* const markdownState = createVizelMarkdown(() => editorState.current, {
|
|
42
|
+
* debounceMs: 300,
|
|
43
|
+
* });
|
|
44
|
+
* </script>
|
|
45
|
+
*
|
|
46
|
+
* <VizelEditor editor={editorState.current} />
|
|
47
|
+
* <textarea
|
|
48
|
+
* value={markdownState.markdown}
|
|
49
|
+
* oninput={(e) => markdownState.setMarkdown(e.currentTarget.value)}
|
|
50
|
+
* />
|
|
51
|
+
* {#if markdownState.isPending}
|
|
52
|
+
* <span>Syncing...</span>
|
|
53
|
+
* {/if}
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```svelte
|
|
58
|
+
* <script lang="ts">
|
|
59
|
+
* // With initial markdown value
|
|
60
|
+
* const markdownState = createVizelMarkdown(() => editorState.current, {
|
|
61
|
+
* initialValue: "# Hello World",
|
|
62
|
+
* transformDiagrams: true,
|
|
63
|
+
* });
|
|
64
|
+
* </script>
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function createVizelMarkdown(getEditor: () => Editor | null | undefined, options?: CreateVizelMarkdownOptions): CreateVizelMarkdownResult;
|
|
68
|
+
//# sourceMappingURL=createVizelMarkdown.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVizelMarkdown.svelte.d.ts","sourceRoot":"","sources":["../../src/runes/createVizelMarkdown.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EAGX,KAAK,wBAAwB,EAC9B,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB;IAC1E;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAC1C,OAAO,GAAE,0BAA+B,GACvC,yBAAyB,CA6F3B"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createVizelMarkdownSyncHandlers, getVizelMarkdown, } from "@vizel/core";
|
|
2
|
+
/**
|
|
3
|
+
* Svelte 5 rune for bidirectional Markdown synchronization with the editor.
|
|
4
|
+
*
|
|
5
|
+
* @param getEditor - Function to get the editor instance
|
|
6
|
+
* @param options - Sync options
|
|
7
|
+
* @returns Markdown state and control functions
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```svelte
|
|
11
|
+
* <script lang="ts">
|
|
12
|
+
* import { createVizelEditor, createVizelMarkdown, VizelEditor } from '@vizel/svelte';
|
|
13
|
+
*
|
|
14
|
+
* const editorState = createVizelEditor();
|
|
15
|
+
* const markdownState = createVizelMarkdown(() => editorState.current, {
|
|
16
|
+
* debounceMs: 300,
|
|
17
|
+
* });
|
|
18
|
+
* </script>
|
|
19
|
+
*
|
|
20
|
+
* <VizelEditor editor={editorState.current} />
|
|
21
|
+
* <textarea
|
|
22
|
+
* value={markdownState.markdown}
|
|
23
|
+
* oninput={(e) => markdownState.setMarkdown(e.currentTarget.value)}
|
|
24
|
+
* />
|
|
25
|
+
* {#if markdownState.isPending}
|
|
26
|
+
* <span>Syncing...</span>
|
|
27
|
+
* {/if}
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```svelte
|
|
32
|
+
* <script lang="ts">
|
|
33
|
+
* // With initial markdown value
|
|
34
|
+
* const markdownState = createVizelMarkdown(() => editorState.current, {
|
|
35
|
+
* initialValue: "# Hello World",
|
|
36
|
+
* transformDiagrams: true,
|
|
37
|
+
* });
|
|
38
|
+
* </script>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function createVizelMarkdown(getEditor, options = {}) {
|
|
42
|
+
const { initialValue, ...syncOptions } = options;
|
|
43
|
+
let markdown = $state(initialValue ?? "");
|
|
44
|
+
let isPending = $state(false);
|
|
45
|
+
// Create sync handlers
|
|
46
|
+
let handlers = null;
|
|
47
|
+
const initHandlers = () => {
|
|
48
|
+
if (!handlers) {
|
|
49
|
+
handlers = createVizelMarkdownSyncHandlers(syncOptions);
|
|
50
|
+
}
|
|
51
|
+
return handlers;
|
|
52
|
+
};
|
|
53
|
+
// Track if initial value has been set
|
|
54
|
+
let initialSet = false;
|
|
55
|
+
// Watch for editor availability and subscribe to updates
|
|
56
|
+
$effect(() => {
|
|
57
|
+
const editor = getEditor();
|
|
58
|
+
if (!editor)
|
|
59
|
+
return;
|
|
60
|
+
const h = initHandlers();
|
|
61
|
+
// Initialize markdown on first editor availability
|
|
62
|
+
if (!initialSet) {
|
|
63
|
+
if (initialValue !== undefined) {
|
|
64
|
+
h.setMarkdown(editor, initialValue);
|
|
65
|
+
markdown = initialValue;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Get initial markdown from editor
|
|
69
|
+
markdown = getVizelMarkdown(editor);
|
|
70
|
+
}
|
|
71
|
+
initialSet = true;
|
|
72
|
+
}
|
|
73
|
+
// Subscribe to editor updates
|
|
74
|
+
const handleUpdate = () => {
|
|
75
|
+
h.handleUpdate(editor);
|
|
76
|
+
isPending = h.isPending();
|
|
77
|
+
// Schedule state update after debounce
|
|
78
|
+
const checkPending = () => {
|
|
79
|
+
if (h.isPending()) {
|
|
80
|
+
requestAnimationFrame(checkPending);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
markdown = h.getMarkdown();
|
|
84
|
+
isPending = false;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
requestAnimationFrame(checkPending);
|
|
88
|
+
};
|
|
89
|
+
editor.on("update", handleUpdate);
|
|
90
|
+
return () => {
|
|
91
|
+
editor.off("update", handleUpdate);
|
|
92
|
+
handlers?.destroy();
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const setMarkdown = (newMarkdown) => {
|
|
96
|
+
const editor = getEditor();
|
|
97
|
+
if (!editor)
|
|
98
|
+
return;
|
|
99
|
+
const h = initHandlers();
|
|
100
|
+
h.setMarkdown(editor, newMarkdown);
|
|
101
|
+
markdown = newMarkdown;
|
|
102
|
+
isPending = false;
|
|
103
|
+
};
|
|
104
|
+
const flush = () => {
|
|
105
|
+
const editor = getEditor();
|
|
106
|
+
if (!editor)
|
|
107
|
+
return;
|
|
108
|
+
const h = initHandlers();
|
|
109
|
+
h.flush(editor);
|
|
110
|
+
markdown = h.getMarkdown();
|
|
111
|
+
isPending = false;
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
get markdown() {
|
|
115
|
+
return markdown;
|
|
116
|
+
},
|
|
117
|
+
setMarkdown,
|
|
118
|
+
get isPending() {
|
|
119
|
+
return isPending;
|
|
120
|
+
},
|
|
121
|
+
flush,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type SuggestionOptions, type VizelSlashCommandItem, type VizelSlashMenuRendererOptions } from "@vizel/core";
|
|
2
|
+
export type { VizelSlashMenuRendererOptions };
|
|
3
|
+
/**
|
|
4
|
+
* Creates a suggestion render configuration for the SlashCommand extension.
|
|
5
|
+
* This handles the popup positioning and Svelte component lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createVizelSlashMenuRenderer } from '@vizel/svelte';
|
|
10
|
+
* import { VizelSlashCommand } from '@vizel/core';
|
|
11
|
+
*
|
|
12
|
+
* const editor = new Editor({
|
|
13
|
+
* extensions: [
|
|
14
|
+
* VizelSlashCommand.configure({
|
|
15
|
+
* suggestion: createVizelSlashMenuRenderer(),
|
|
16
|
+
* }),
|
|
17
|
+
* ],
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createVizelSlashMenuRenderer(options?: VizelSlashMenuRendererOptions): Partial<SuggestionOptions<VizelSlashCommandItem>>;
|
|
22
|
+
//# sourceMappingURL=createVizelSlashMenuRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVizelSlashMenuRenderer.d.ts","sourceRoot":"","sources":["../../src/runes/createVizelSlashMenuRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EAEtB,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EACnC,MAAM,aAAa,CAAC;AAIrB,YAAY,EAAE,6BAA6B,EAAE,CAAC;AAU9C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,CAmEnD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createVizelSuggestionContainer, handleVizelSuggestionEscape, } from "@vizel/core";
|
|
2
|
+
import { mount, unmount } from "svelte";
|
|
3
|
+
import VizelSlashMenu from "../components/VizelSlashMenu.svelte";
|
|
4
|
+
/** Type guard for SlashMenuRef */
|
|
5
|
+
const isSlashMenuRef = (value) => typeof value === "object" && value !== null && "onKeyDown" in value;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a suggestion render configuration for the SlashCommand extension.
|
|
8
|
+
* This handles the popup positioning and Svelte component lifecycle.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createVizelSlashMenuRenderer } from '@vizel/svelte';
|
|
13
|
+
* import { VizelSlashCommand } from '@vizel/core';
|
|
14
|
+
*
|
|
15
|
+
* const editor = new Editor({
|
|
16
|
+
* extensions: [
|
|
17
|
+
* VizelSlashCommand.configure({
|
|
18
|
+
* suggestion: createVizelSlashMenuRenderer(),
|
|
19
|
+
* }),
|
|
20
|
+
* ],
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createVizelSlashMenuRenderer(options = {}) {
|
|
25
|
+
return {
|
|
26
|
+
render: () => {
|
|
27
|
+
let component = null;
|
|
28
|
+
let suggestionContainer = null;
|
|
29
|
+
let items = [];
|
|
30
|
+
let commandFn = null;
|
|
31
|
+
const mountComponent = () => {
|
|
32
|
+
if (!suggestionContainer)
|
|
33
|
+
return;
|
|
34
|
+
component = mount(VizelSlashMenu, {
|
|
35
|
+
target: suggestionContainer.menuContainer,
|
|
36
|
+
props: {
|
|
37
|
+
items,
|
|
38
|
+
...(options.className !== undefined && { class: options.className }),
|
|
39
|
+
oncommand: (item) => {
|
|
40
|
+
commandFn?.(item);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
onStart: (props) => {
|
|
47
|
+
items = props.items;
|
|
48
|
+
commandFn = props.command;
|
|
49
|
+
suggestionContainer = createVizelSuggestionContainer();
|
|
50
|
+
mountComponent();
|
|
51
|
+
suggestionContainer.updatePosition(props.clientRect);
|
|
52
|
+
},
|
|
53
|
+
onUpdate: (props) => {
|
|
54
|
+
items = props.items;
|
|
55
|
+
commandFn = props.command;
|
|
56
|
+
// Svelte 5 mount doesn't support updating props after mount
|
|
57
|
+
// We need to remount the component with new props
|
|
58
|
+
if (component && suggestionContainer) {
|
|
59
|
+
unmount(component);
|
|
60
|
+
mountComponent();
|
|
61
|
+
}
|
|
62
|
+
suggestionContainer?.updatePosition(props.clientRect);
|
|
63
|
+
},
|
|
64
|
+
onKeyDown: (props) => {
|
|
65
|
+
if (handleVizelSuggestionEscape(props.event)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (component && isSlashMenuRef(component)) {
|
|
69
|
+
return component.onKeyDown(props.event);
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
},
|
|
73
|
+
onExit: () => {
|
|
74
|
+
if (component) {
|
|
75
|
+
unmount(component);
|
|
76
|
+
}
|
|
77
|
+
suggestionContainer?.destroy();
|
|
78
|
+
component = null;
|
|
79
|
+
suggestionContainer = null;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Editor } from "@vizel/core";
|
|
2
|
+
/**
|
|
3
|
+
* Rune that forces a re-render whenever the editor's state changes.
|
|
4
|
+
* This is useful for components that need to reflect the current editor state
|
|
5
|
+
* (e.g., formatting buttons that show active state).
|
|
6
|
+
*
|
|
7
|
+
* @param getEditor - A function that returns the editor instance
|
|
8
|
+
* @returns An object with a `current` getter for the update count
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```svelte
|
|
12
|
+
* <script lang="ts">
|
|
13
|
+
* const state = createVizelState(() => editor);
|
|
14
|
+
* // Access state.current to trigger reactivity
|
|
15
|
+
* </script>
|
|
16
|
+
* <button class:active={state.current >= 0 && editor.isActive('bold')}>Bold</button>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function createVizelState(getEditor: () => Editor | null | undefined): {
|
|
20
|
+
readonly current: number;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=createVizelState.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVizelState.svelte.d.ts","sourceRoot":"","sources":["../../src/runes/createVizelState.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG;IAC5E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAuCA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rune that forces a re-render whenever the editor's state changes.
|
|
3
|
+
* This is useful for components that need to reflect the current editor state
|
|
4
|
+
* (e.g., formatting buttons that show active state).
|
|
5
|
+
*
|
|
6
|
+
* @param getEditor - A function that returns the editor instance
|
|
7
|
+
* @returns An object with a `current` getter for the update count
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```svelte
|
|
11
|
+
* <script lang="ts">
|
|
12
|
+
* const state = createVizelState(() => editor);
|
|
13
|
+
* // Access state.current to trigger reactivity
|
|
14
|
+
* </script>
|
|
15
|
+
* <button class:active={state.current >= 0 && editor.isActive('bold')}>Bold</button>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function createVizelState(getEditor) {
|
|
19
|
+
let updateCount = $state(0);
|
|
20
|
+
let currentEditor = null;
|
|
21
|
+
function handleTransaction() {
|
|
22
|
+
updateCount++;
|
|
23
|
+
}
|
|
24
|
+
function subscribe(editor) {
|
|
25
|
+
// Unsubscribe from previous editor
|
|
26
|
+
if (currentEditor) {
|
|
27
|
+
currentEditor.off("transaction", handleTransaction);
|
|
28
|
+
}
|
|
29
|
+
currentEditor = editor ?? null;
|
|
30
|
+
// Subscribe to new editor
|
|
31
|
+
if (currentEditor) {
|
|
32
|
+
currentEditor.on("transaction", handleTransaction);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Use $effect to watch for editor changes - $effect cleanup handles unmount
|
|
36
|
+
$effect(() => {
|
|
37
|
+
const editor = getEditor();
|
|
38
|
+
subscribe(editor);
|
|
39
|
+
return () => {
|
|
40
|
+
if (currentEditor) {
|
|
41
|
+
currentEditor.off("transaction", handleTransaction);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
get current() {
|
|
47
|
+
return updateCount;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { VizelThemeState } from "@vizel/core";
|
|
2
|
+
/**
|
|
3
|
+
* Get theme state and controls from context
|
|
4
|
+
*
|
|
5
|
+
* Must be used within a VizelThemeProvider
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <script>
|
|
10
|
+
* const theme = getVizelTheme();
|
|
11
|
+
* </script>
|
|
12
|
+
*
|
|
13
|
+
* <button onclick={() => theme.setTheme(theme.resolvedTheme === 'dark' ? 'light' : 'dark')}>
|
|
14
|
+
* Toggle theme
|
|
15
|
+
* </button>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function getVizelTheme(): VizelThemeState;
|
|
19
|
+
/**
|
|
20
|
+
* Get theme state safely (returns null if not in provider)
|
|
21
|
+
*/
|
|
22
|
+
export declare function getVizelThemeSafe(): VizelThemeState | null;
|
|
23
|
+
//# sourceMappingURL=getVizelTheme.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVizelTheme.svelte.d.ts","sourceRoot":"","sources":["../../src/runes/getVizelTheme.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,IAAI,eAAe,CAQ/C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,eAAe,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getContext } from "svelte";
|
|
2
|
+
import { VIZEL_THEME_CONTEXT_KEY } from "../components/VizelThemeProvider.svelte";
|
|
3
|
+
/**
|
|
4
|
+
* Get theme state and controls from context
|
|
5
|
+
*
|
|
6
|
+
* Must be used within a VizelThemeProvider
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```svelte
|
|
10
|
+
* <script>
|
|
11
|
+
* const theme = getVizelTheme();
|
|
12
|
+
* </script>
|
|
13
|
+
*
|
|
14
|
+
* <button onclick={() => theme.setTheme(theme.resolvedTheme === 'dark' ? 'light' : 'dark')}>
|
|
15
|
+
* Toggle theme
|
|
16
|
+
* </button>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function getVizelTheme() {
|
|
20
|
+
const context = getContext(VIZEL_THEME_CONTEXT_KEY);
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error("getVizelTheme must be used within a VizelThemeProvider");
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get theme state safely (returns null if not in provider)
|
|
28
|
+
*/
|
|
29
|
+
export function getVizelThemeSafe() {
|
|
30
|
+
return getContext(VIZEL_THEME_CONTEXT_KEY) ?? null;
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { type CreateVizelAutoSaveResult, createVizelAutoSave, } from "./createVizelAutoSave.svelte.ts";
|
|
2
|
+
export { type CreateVizelEditorOptions, createVizelEditor, } from "./createVizelEditor.svelte.ts";
|
|
3
|
+
export { createVizelEditorState } from "./createVizelEditorState.svelte.ts";
|
|
4
|
+
export { type CreateVizelMarkdownOptions, type CreateVizelMarkdownResult, createVizelMarkdown, } from "./createVizelMarkdown.svelte.ts";
|
|
5
|
+
export { createVizelSlashMenuRenderer, type VizelSlashMenuRendererOptions, } from "./createVizelSlashMenuRenderer.ts";
|
|
6
|
+
export { createVizelState } from "./createVizelState.svelte.ts";
|
|
7
|
+
export { getVizelTheme, getVizelThemeSafe } from "./getVizelTheme.svelte.ts";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,yBAAyB,EAC9B,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,wBAAwB,EAC7B,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,4BAA4B,EAC5B,KAAK,6BAA6B,GACnC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createVizelAutoSave, } from "./createVizelAutoSave.svelte.ts";
|
|
2
|
+
export { createVizelEditor, } from "./createVizelEditor.svelte.ts";
|
|
3
|
+
export { createVizelEditorState } from "./createVizelEditorState.svelte.ts";
|
|
4
|
+
export { createVizelMarkdown, } from "./createVizelMarkdown.svelte.ts";
|
|
5
|
+
export { createVizelSlashMenuRenderer, } from "./createVizelSlashMenuRenderer.ts";
|
|
6
|
+
export { createVizelState } from "./createVizelState.svelte.ts";
|
|
7
|
+
export { getVizelTheme, getVizelThemeSafe } from "./getVizelTheme.svelte.ts";
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vizel/svelte",
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
|
+
"description": "Svelte 5 components for Vizel block-based Markdown editor",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"svelte",
|
|
7
|
+
"svelte5",
|
|
8
|
+
"tiptap",
|
|
9
|
+
"editor",
|
|
10
|
+
"markdown",
|
|
11
|
+
"wysiwyg",
|
|
12
|
+
"rich-text",
|
|
13
|
+
"block-editor"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Seiji Kohara",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/seijikohara/vizel.git",
|
|
20
|
+
"directory": "packages/svelte"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/seijikohara/vizel",
|
|
23
|
+
"bugs": "https://github.com/seijikohara/vizel/issues",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"svelte": "./dist/index.js",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"svelte": "./dist/index.js",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "svelte-package -i src -o dist",
|
|
50
|
+
"typecheck": "svelte-check --tsconfig ./tsconfig.json"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@iconify/svelte": "^5",
|
|
54
|
+
"@vizel/core": "^0.0.1-alpha.1"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"svelte": "^5"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@sveltejs/package": "^2",
|
|
61
|
+
"@sveltejs/vite-plugin-svelte": "^6",
|
|
62
|
+
"svelte-check": "^4"
|
|
63
|
+
}
|
|
64
|
+
}
|