@velo-sci/notebook-svelte 0.6.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VeloSci
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SciNotebookSvelte: () => SciNotebookSvelte,
24
+ createNotebookStore: () => createNotebookStore
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/sci-notebook-svelte.ts
29
+ var import_notebook_core = require("@velo-sci/notebook-core");
30
+ var import_notebook_renderer = require("@velo-sci/notebook-renderer");
31
+
32
+ // src/stores.ts
33
+ function createNotebookStore(engine) {
34
+ const notebook = createReadable(engine.getNotebook(), (set) => {
35
+ return engine.on("notebook:updated", (payload) => {
36
+ set(payload.data.notebook);
37
+ });
38
+ });
39
+ const cells = createReadable([...engine.getCells()], (set) => {
40
+ return engine.on("notebook:updated", (payload) => {
41
+ set([...payload.data.notebook.cells]);
42
+ });
43
+ });
44
+ const focusedCellId = createReadable(null, (set) => {
45
+ return engine.on("cell:focused", (payload) => {
46
+ set(payload.data.cellId);
47
+ });
48
+ });
49
+ return { notebook, cells, focusedCellId, engine };
50
+ }
51
+ function createReadable(initialValue, start) {
52
+ let value = initialValue;
53
+ const subscribers = /* @__PURE__ */ new Set();
54
+ let stop = null;
55
+ function set(newValue) {
56
+ value = newValue;
57
+ for (const sub of subscribers) {
58
+ sub(value);
59
+ }
60
+ }
61
+ return {
62
+ subscribe(run) {
63
+ subscribers.add(run);
64
+ run(value);
65
+ if (subscribers.size === 1) {
66
+ stop = start(set);
67
+ }
68
+ return () => {
69
+ subscribers.delete(run);
70
+ if (subscribers.size === 0 && stop) {
71
+ stop();
72
+ stop = null;
73
+ }
74
+ };
75
+ }
76
+ };
77
+ }
78
+
79
+ // src/sci-notebook-svelte.ts
80
+ var SciNotebookSvelte = class {
81
+ engine;
82
+ container;
83
+ pipeline;
84
+ options;
85
+ unsubscribers = [];
86
+ destroyed = false;
87
+ store;
88
+ constructor(options) {
89
+ this.options = options;
90
+ if (typeof options.target === "string") {
91
+ const el = document.querySelector(options.target);
92
+ if (!el) throw new Error(`SciNotebookSvelte: target "${options.target}" not found`);
93
+ this.container = el;
94
+ } else {
95
+ this.container = options.target;
96
+ }
97
+ if (options.engine) {
98
+ this.engine = options.engine;
99
+ } else {
100
+ this.engine = (0, import_notebook_core.createNotebook)({
101
+ notebook: options.notebook,
102
+ config: { plugins: options.plugins }
103
+ });
104
+ }
105
+ this.pipeline = new import_notebook_renderer.RenderPipeline();
106
+ this.store = createNotebookStore(this.engine);
107
+ this.render();
108
+ this.bindEvents();
109
+ }
110
+ getEngine() {
111
+ return this.engine;
112
+ }
113
+ getNotebook() {
114
+ return this.engine.getNotebook();
115
+ }
116
+ setTheme(theme) {
117
+ this.options.theme = theme;
118
+ this.container.dataset.theme = theme;
119
+ }
120
+ insertCell(index, type, source) {
121
+ return this.engine.insertCell(index, type, source);
122
+ }
123
+ destroy() {
124
+ if (this.destroyed) return;
125
+ this.destroyed = true;
126
+ for (const unsub of this.unsubscribers) unsub();
127
+ this.unsubscribers = [];
128
+ this.engine.destroy();
129
+ this.container.innerHTML = "";
130
+ }
131
+ render() {
132
+ this.container.innerHTML = "";
133
+ this.container.className = "sci-nb sci-nb--svelte";
134
+ this.container.dataset.theme = this.options.theme || "light";
135
+ this.container.tabIndex = 0;
136
+ if (this.options.showToolbar !== false) {
137
+ this.container.appendChild(this.createToolbar());
138
+ }
139
+ const cellsContainer = document.createElement("div");
140
+ cellsContainer.className = "sci-nb-cells";
141
+ this.container.appendChild(cellsContainer);
142
+ this.renderCells(cellsContainer);
143
+ }
144
+ renderCells(container) {
145
+ container.innerHTML = "";
146
+ const cells = this.engine.getCells();
147
+ if (cells.length === 0) {
148
+ container.innerHTML = `<div class="sci-nb-empty"><p>Empty notebook. Add a cell to get started.</p></div>`;
149
+ return;
150
+ }
151
+ for (const cell of cells) {
152
+ const el = document.createElement("div");
153
+ el.className = `sci-nb-cell sci-nb-cell--${cell.type}`;
154
+ el.dataset.cellId = cell.id;
155
+ const content = document.createElement("div");
156
+ content.className = "sci-nb-cell-content";
157
+ if (cell.editing) {
158
+ const editor = document.createElement("textarea");
159
+ editor.className = "sci-nb-cell-editor";
160
+ editor.value = cell.source;
161
+ editor.rows = Math.max(3, cell.source.split("\n").length + 1);
162
+ editor.addEventListener("input", () => {
163
+ this.engine.updateCellSource(cell.id, editor.value);
164
+ });
165
+ editor.addEventListener("keydown", (e) => {
166
+ if (e.key === "Escape") {
167
+ e.preventDefault();
168
+ this.engine.setViewMode(cell.id);
169
+ }
170
+ });
171
+ content.appendChild(editor);
172
+ } else {
173
+ content.innerHTML = this.pipeline.render(cell).html;
174
+ content.addEventListener("click", () => {
175
+ if (!this.options.readOnly) {
176
+ this.engine.focusCell(cell.id);
177
+ this.engine.setEditMode(cell.id);
178
+ }
179
+ });
180
+ }
181
+ el.appendChild(content);
182
+ container.appendChild(el);
183
+ }
184
+ }
185
+ createToolbar() {
186
+ const toolbar = document.createElement("div");
187
+ toolbar.className = "sci-nb-toolbar";
188
+ const nb = this.engine.getNotebook();
189
+ toolbar.innerHTML = `
190
+ <div class="sci-nb-toolbar-group">
191
+ <span class="sci-nb-toolbar-title">${nb.title}</span>
192
+ </div>
193
+ <div class="sci-nb-toolbar-group">
194
+ <button class="sci-nb-toolbar-btn" data-toolbar="undo">Undo</button>
195
+ <button class="sci-nb-toolbar-btn" data-toolbar="redo">Redo</button>
196
+ <button class="sci-nb-toolbar-btn" data-toolbar="edit-all">Edit All</button>
197
+ <button class="sci-nb-toolbar-btn" data-toolbar="view-all">View All</button>
198
+ </div>
199
+ `;
200
+ toolbar.addEventListener("click", (e) => {
201
+ const btn = e.target.closest("[data-toolbar]");
202
+ if (!btn) return;
203
+ switch (btn.dataset.toolbar) {
204
+ case "undo":
205
+ this.engine.undo();
206
+ break;
207
+ case "redo":
208
+ this.engine.redo();
209
+ break;
210
+ case "edit-all":
211
+ this.engine.setAllEditMode();
212
+ break;
213
+ case "view-all":
214
+ this.engine.setAllViewMode();
215
+ break;
216
+ }
217
+ });
218
+ return toolbar;
219
+ }
220
+ bindEvents() {
221
+ const unsub = this.engine.on("notebook:updated", (payload) => {
222
+ const cellsContainer = this.container.querySelector(".sci-nb-cells");
223
+ if (cellsContainer) this.renderCells(cellsContainer);
224
+ if (this.options.onChange) this.options.onChange(payload.data.notebook);
225
+ });
226
+ this.unsubscribers.push(unsub);
227
+ }
228
+ };
229
+ // Annotate the CommonJS export names for ESM import in node:
230
+ 0 && (module.exports = {
231
+ SciNotebookSvelte,
232
+ createNotebookStore
233
+ });
@@ -0,0 +1,108 @@
1
+ import { Notebook, Cell, EditorEngine, SciNotebookPlugin, CellType } from '@velo-sci/notebook-core';
2
+
3
+ /**
4
+ * Svelte-compatible store interface (subscribe pattern).
5
+ * Works with Svelte's `$store` syntax.
6
+ */
7
+ interface Readable<T> {
8
+ subscribe(run: (value: T) => void): () => void;
9
+ }
10
+ interface NotebookStore {
11
+ notebook: Readable<Readonly<Notebook>>;
12
+ cells: Readable<ReadonlyArray<Cell>>;
13
+ focusedCellId: Readable<string | null>;
14
+ engine: EditorEngine;
15
+ }
16
+ /**
17
+ * Create a Svelte-compatible store from an EditorEngine.
18
+ *
19
+ * Usage in Svelte:
20
+ * ```svelte
21
+ * <script>
22
+ * import { createNotebookStore } from '@velo-sci/notebook-svelte';
23
+ * const { notebook, cells, focusedCellId, engine } = createNotebookStore(myEngine);
24
+ * </script>
25
+ *
26
+ * <p>{$notebook.title}</p>
27
+ * {#each $cells as cell}
28
+ * <div>{cell.source}</div>
29
+ * {/each}
30
+ * ```
31
+ */
32
+ declare function createNotebookStore(engine: EditorEngine): NotebookStore;
33
+
34
+ interface SciNotebookSvelteOptions {
35
+ /** Target DOM element or CSS selector */
36
+ target: HTMLElement | string;
37
+ /** Pre-built notebook object */
38
+ notebook?: Notebook;
39
+ /** Pre-built engine (takes priority over notebook) */
40
+ engine?: EditorEngine;
41
+ /** Plugins to register */
42
+ plugins?: SciNotebookPlugin[];
43
+ /** Theme */
44
+ theme?: "light" | "dark" | string;
45
+ /** Callback when notebook changes */
46
+ onChange?: (notebook: Notebook) => void;
47
+ /** Read-only mode */
48
+ readOnly?: boolean;
49
+ /** Show toolbar */
50
+ showToolbar?: boolean;
51
+ }
52
+ /**
53
+ * Svelte 5+ adapter for sci-notebook.
54
+ *
55
+ * Provides a store-based API that integrates with Svelte's reactivity.
56
+ * Can also be used imperatively for mounting into a DOM element.
57
+ *
58
+ * Usage (imperative):
59
+ * ```ts
60
+ * const nb = new SciNotebookSvelte({
61
+ * target: '#app',
62
+ * notebook: myNotebook,
63
+ * theme: 'dark',
64
+ * });
65
+ * // Access stores: nb.store.notebook, nb.store.cells, nb.store.focusedCellId
66
+ * nb.destroy();
67
+ * ```
68
+ *
69
+ * Usage (Svelte component):
70
+ * ```svelte
71
+ * <script>
72
+ * import { createNotebookStore } from '@velo-sci/notebook-svelte';
73
+ * import { createNotebook } from '@velo-sci/notebook-core';
74
+ *
75
+ * const engine = createNotebook({ notebook: myNotebook });
76
+ * const { notebook, cells, focusedCellId } = createNotebookStore(engine);
77
+ * </script>
78
+ *
79
+ * <div class="sci-nb" data-theme="dark">
80
+ * {#each $cells as cell, idx}
81
+ * <div class="sci-nb-cell sci-nb-cell--{cell.type}">
82
+ * {cell.source}
83
+ * </div>
84
+ * {/each}
85
+ * </div>
86
+ * ```
87
+ */
88
+ declare class SciNotebookSvelte {
89
+ private engine;
90
+ private container;
91
+ private pipeline;
92
+ private options;
93
+ private unsubscribers;
94
+ private destroyed;
95
+ readonly store: NotebookStore;
96
+ constructor(options: SciNotebookSvelteOptions);
97
+ getEngine(): EditorEngine;
98
+ getNotebook(): Readonly<Notebook>;
99
+ setTheme(theme: string): void;
100
+ insertCell(index: number, type?: CellType, source?: string): Cell;
101
+ destroy(): void;
102
+ private render;
103
+ private renderCells;
104
+ private createToolbar;
105
+ private bindEvents;
106
+ }
107
+
108
+ export { type NotebookStore, SciNotebookSvelte, type SciNotebookSvelteOptions, createNotebookStore };
@@ -0,0 +1,108 @@
1
+ import { Notebook, Cell, EditorEngine, SciNotebookPlugin, CellType } from '@velo-sci/notebook-core';
2
+
3
+ /**
4
+ * Svelte-compatible store interface (subscribe pattern).
5
+ * Works with Svelte's `$store` syntax.
6
+ */
7
+ interface Readable<T> {
8
+ subscribe(run: (value: T) => void): () => void;
9
+ }
10
+ interface NotebookStore {
11
+ notebook: Readable<Readonly<Notebook>>;
12
+ cells: Readable<ReadonlyArray<Cell>>;
13
+ focusedCellId: Readable<string | null>;
14
+ engine: EditorEngine;
15
+ }
16
+ /**
17
+ * Create a Svelte-compatible store from an EditorEngine.
18
+ *
19
+ * Usage in Svelte:
20
+ * ```svelte
21
+ * <script>
22
+ * import { createNotebookStore } from '@velo-sci/notebook-svelte';
23
+ * const { notebook, cells, focusedCellId, engine } = createNotebookStore(myEngine);
24
+ * </script>
25
+ *
26
+ * <p>{$notebook.title}</p>
27
+ * {#each $cells as cell}
28
+ * <div>{cell.source}</div>
29
+ * {/each}
30
+ * ```
31
+ */
32
+ declare function createNotebookStore(engine: EditorEngine): NotebookStore;
33
+
34
+ interface SciNotebookSvelteOptions {
35
+ /** Target DOM element or CSS selector */
36
+ target: HTMLElement | string;
37
+ /** Pre-built notebook object */
38
+ notebook?: Notebook;
39
+ /** Pre-built engine (takes priority over notebook) */
40
+ engine?: EditorEngine;
41
+ /** Plugins to register */
42
+ plugins?: SciNotebookPlugin[];
43
+ /** Theme */
44
+ theme?: "light" | "dark" | string;
45
+ /** Callback when notebook changes */
46
+ onChange?: (notebook: Notebook) => void;
47
+ /** Read-only mode */
48
+ readOnly?: boolean;
49
+ /** Show toolbar */
50
+ showToolbar?: boolean;
51
+ }
52
+ /**
53
+ * Svelte 5+ adapter for sci-notebook.
54
+ *
55
+ * Provides a store-based API that integrates with Svelte's reactivity.
56
+ * Can also be used imperatively for mounting into a DOM element.
57
+ *
58
+ * Usage (imperative):
59
+ * ```ts
60
+ * const nb = new SciNotebookSvelte({
61
+ * target: '#app',
62
+ * notebook: myNotebook,
63
+ * theme: 'dark',
64
+ * });
65
+ * // Access stores: nb.store.notebook, nb.store.cells, nb.store.focusedCellId
66
+ * nb.destroy();
67
+ * ```
68
+ *
69
+ * Usage (Svelte component):
70
+ * ```svelte
71
+ * <script>
72
+ * import { createNotebookStore } from '@velo-sci/notebook-svelte';
73
+ * import { createNotebook } from '@velo-sci/notebook-core';
74
+ *
75
+ * const engine = createNotebook({ notebook: myNotebook });
76
+ * const { notebook, cells, focusedCellId } = createNotebookStore(engine);
77
+ * </script>
78
+ *
79
+ * <div class="sci-nb" data-theme="dark">
80
+ * {#each $cells as cell, idx}
81
+ * <div class="sci-nb-cell sci-nb-cell--{cell.type}">
82
+ * {cell.source}
83
+ * </div>
84
+ * {/each}
85
+ * </div>
86
+ * ```
87
+ */
88
+ declare class SciNotebookSvelte {
89
+ private engine;
90
+ private container;
91
+ private pipeline;
92
+ private options;
93
+ private unsubscribers;
94
+ private destroyed;
95
+ readonly store: NotebookStore;
96
+ constructor(options: SciNotebookSvelteOptions);
97
+ getEngine(): EditorEngine;
98
+ getNotebook(): Readonly<Notebook>;
99
+ setTheme(theme: string): void;
100
+ insertCell(index: number, type?: CellType, source?: string): Cell;
101
+ destroy(): void;
102
+ private render;
103
+ private renderCells;
104
+ private createToolbar;
105
+ private bindEvents;
106
+ }
107
+
108
+ export { type NotebookStore, SciNotebookSvelte, type SciNotebookSvelteOptions, createNotebookStore };
package/dist/index.js ADDED
@@ -0,0 +1,207 @@
1
+ // src/sci-notebook-svelte.ts
2
+ import {
3
+ createNotebook
4
+ } from "@velo-sci/notebook-core";
5
+ import { RenderPipeline } from "@velo-sci/notebook-renderer";
6
+
7
+ // src/stores.ts
8
+ function createNotebookStore(engine) {
9
+ const notebook = createReadable(engine.getNotebook(), (set) => {
10
+ return engine.on("notebook:updated", (payload) => {
11
+ set(payload.data.notebook);
12
+ });
13
+ });
14
+ const cells = createReadable([...engine.getCells()], (set) => {
15
+ return engine.on("notebook:updated", (payload) => {
16
+ set([...payload.data.notebook.cells]);
17
+ });
18
+ });
19
+ const focusedCellId = createReadable(null, (set) => {
20
+ return engine.on("cell:focused", (payload) => {
21
+ set(payload.data.cellId);
22
+ });
23
+ });
24
+ return { notebook, cells, focusedCellId, engine };
25
+ }
26
+ function createReadable(initialValue, start) {
27
+ let value = initialValue;
28
+ const subscribers = /* @__PURE__ */ new Set();
29
+ let stop = null;
30
+ function set(newValue) {
31
+ value = newValue;
32
+ for (const sub of subscribers) {
33
+ sub(value);
34
+ }
35
+ }
36
+ return {
37
+ subscribe(run) {
38
+ subscribers.add(run);
39
+ run(value);
40
+ if (subscribers.size === 1) {
41
+ stop = start(set);
42
+ }
43
+ return () => {
44
+ subscribers.delete(run);
45
+ if (subscribers.size === 0 && stop) {
46
+ stop();
47
+ stop = null;
48
+ }
49
+ };
50
+ }
51
+ };
52
+ }
53
+
54
+ // src/sci-notebook-svelte.ts
55
+ var SciNotebookSvelte = class {
56
+ engine;
57
+ container;
58
+ pipeline;
59
+ options;
60
+ unsubscribers = [];
61
+ destroyed = false;
62
+ store;
63
+ constructor(options) {
64
+ this.options = options;
65
+ if (typeof options.target === "string") {
66
+ const el = document.querySelector(options.target);
67
+ if (!el) throw new Error(`SciNotebookSvelte: target "${options.target}" not found`);
68
+ this.container = el;
69
+ } else {
70
+ this.container = options.target;
71
+ }
72
+ if (options.engine) {
73
+ this.engine = options.engine;
74
+ } else {
75
+ this.engine = createNotebook({
76
+ notebook: options.notebook,
77
+ config: { plugins: options.plugins }
78
+ });
79
+ }
80
+ this.pipeline = new RenderPipeline();
81
+ this.store = createNotebookStore(this.engine);
82
+ this.render();
83
+ this.bindEvents();
84
+ }
85
+ getEngine() {
86
+ return this.engine;
87
+ }
88
+ getNotebook() {
89
+ return this.engine.getNotebook();
90
+ }
91
+ setTheme(theme) {
92
+ this.options.theme = theme;
93
+ this.container.dataset.theme = theme;
94
+ }
95
+ insertCell(index, type, source) {
96
+ return this.engine.insertCell(index, type, source);
97
+ }
98
+ destroy() {
99
+ if (this.destroyed) return;
100
+ this.destroyed = true;
101
+ for (const unsub of this.unsubscribers) unsub();
102
+ this.unsubscribers = [];
103
+ this.engine.destroy();
104
+ this.container.innerHTML = "";
105
+ }
106
+ render() {
107
+ this.container.innerHTML = "";
108
+ this.container.className = "sci-nb sci-nb--svelte";
109
+ this.container.dataset.theme = this.options.theme || "light";
110
+ this.container.tabIndex = 0;
111
+ if (this.options.showToolbar !== false) {
112
+ this.container.appendChild(this.createToolbar());
113
+ }
114
+ const cellsContainer = document.createElement("div");
115
+ cellsContainer.className = "sci-nb-cells";
116
+ this.container.appendChild(cellsContainer);
117
+ this.renderCells(cellsContainer);
118
+ }
119
+ renderCells(container) {
120
+ container.innerHTML = "";
121
+ const cells = this.engine.getCells();
122
+ if (cells.length === 0) {
123
+ container.innerHTML = `<div class="sci-nb-empty"><p>Empty notebook. Add a cell to get started.</p></div>`;
124
+ return;
125
+ }
126
+ for (const cell of cells) {
127
+ const el = document.createElement("div");
128
+ el.className = `sci-nb-cell sci-nb-cell--${cell.type}`;
129
+ el.dataset.cellId = cell.id;
130
+ const content = document.createElement("div");
131
+ content.className = "sci-nb-cell-content";
132
+ if (cell.editing) {
133
+ const editor = document.createElement("textarea");
134
+ editor.className = "sci-nb-cell-editor";
135
+ editor.value = cell.source;
136
+ editor.rows = Math.max(3, cell.source.split("\n").length + 1);
137
+ editor.addEventListener("input", () => {
138
+ this.engine.updateCellSource(cell.id, editor.value);
139
+ });
140
+ editor.addEventListener("keydown", (e) => {
141
+ if (e.key === "Escape") {
142
+ e.preventDefault();
143
+ this.engine.setViewMode(cell.id);
144
+ }
145
+ });
146
+ content.appendChild(editor);
147
+ } else {
148
+ content.innerHTML = this.pipeline.render(cell).html;
149
+ content.addEventListener("click", () => {
150
+ if (!this.options.readOnly) {
151
+ this.engine.focusCell(cell.id);
152
+ this.engine.setEditMode(cell.id);
153
+ }
154
+ });
155
+ }
156
+ el.appendChild(content);
157
+ container.appendChild(el);
158
+ }
159
+ }
160
+ createToolbar() {
161
+ const toolbar = document.createElement("div");
162
+ toolbar.className = "sci-nb-toolbar";
163
+ const nb = this.engine.getNotebook();
164
+ toolbar.innerHTML = `
165
+ <div class="sci-nb-toolbar-group">
166
+ <span class="sci-nb-toolbar-title">${nb.title}</span>
167
+ </div>
168
+ <div class="sci-nb-toolbar-group">
169
+ <button class="sci-nb-toolbar-btn" data-toolbar="undo">Undo</button>
170
+ <button class="sci-nb-toolbar-btn" data-toolbar="redo">Redo</button>
171
+ <button class="sci-nb-toolbar-btn" data-toolbar="edit-all">Edit All</button>
172
+ <button class="sci-nb-toolbar-btn" data-toolbar="view-all">View All</button>
173
+ </div>
174
+ `;
175
+ toolbar.addEventListener("click", (e) => {
176
+ const btn = e.target.closest("[data-toolbar]");
177
+ if (!btn) return;
178
+ switch (btn.dataset.toolbar) {
179
+ case "undo":
180
+ this.engine.undo();
181
+ break;
182
+ case "redo":
183
+ this.engine.redo();
184
+ break;
185
+ case "edit-all":
186
+ this.engine.setAllEditMode();
187
+ break;
188
+ case "view-all":
189
+ this.engine.setAllViewMode();
190
+ break;
191
+ }
192
+ });
193
+ return toolbar;
194
+ }
195
+ bindEvents() {
196
+ const unsub = this.engine.on("notebook:updated", (payload) => {
197
+ const cellsContainer = this.container.querySelector(".sci-nb-cells");
198
+ if (cellsContainer) this.renderCells(cellsContainer);
199
+ if (this.options.onChange) this.options.onChange(payload.data.notebook);
200
+ });
201
+ this.unsubscribers.push(unsub);
202
+ }
203
+ };
204
+ export {
205
+ SciNotebookSvelte,
206
+ createNotebookStore
207
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@velo-sci/notebook-svelte",
3
+ "version": "0.6.2",
4
+ "description": "Svelte 5+ adapter for sci-notebook",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "@velo-sci/notebook-core": "0.6.2",
17
+ "@velo-sci/notebook-renderer": "0.6.2"
18
+ },
19
+ "peerDependencies": {
20
+ "svelte": "^5.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "tsup": "^8.0.0",
24
+ "vitest": "^1.0.0"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup src/index.ts --format esm,cjs --dts",
28
+ "dev": "tsup src/index.ts --format esm --watch --dts",
29
+ "test": "vitest run"
30
+ }
31
+ }