@zikojs/notebook 0.7.3 → 0.9.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.
@@ -0,0 +1,10 @@
1
+ .ziko-notebook .error-output {
2
+ color: #e11d48;
3
+ font-family: ui-monospace, SFMono-Regular, monospace;
4
+ white-space: pre-wrap;
5
+ font-size: 12px;
6
+ background: #fff1f2;
7
+ padding: 8px;
8
+ border-radius: 4px;
9
+ border: 1px solid #fecdd3;
10
+ }
@@ -0,0 +1,2 @@
1
+ import { tags } from "ziko/dom"
2
+ export const ErrorOutput = (err) => tags.div({ class: "error-output" }, err.toString())
@@ -0,0 +1,47 @@
1
+ /* --- HEADER & TOOLBAR --- */
2
+
3
+ .ziko-notebook .header {
4
+ border-bottom: 1px solid var(--border-color);
5
+ background: #ffffff;
6
+ padding: 10px 16px;
7
+ display: flex;
8
+ align-items: center;
9
+ justify-content: space-between;
10
+ gap: 12px;
11
+ flex-wrap: wrap;
12
+ position: sticky;
13
+ top: 0;
14
+ z-index: 100;
15
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
16
+ width: 100%;
17
+ }
18
+
19
+ .ziko-notebook .brand {
20
+ font-weight: 600;
21
+ font-size: 16px;
22
+ color: #0f172a;
23
+ display: flex;
24
+ align-items: center;
25
+ gap: 12px;
26
+ flex-shrink: 0;
27
+ }
28
+
29
+ .ziko-notebook .toolbar {
30
+ display: flex;
31
+ gap: 6px;
32
+ align-items: center;
33
+ flex-wrap: wrap;
34
+ max-width: 100%;
35
+ }
36
+
37
+ .ziko-notebook .status-badge {
38
+ font-size: 12px;
39
+ font-weight: 500;
40
+ color: var(--primary);
41
+ background: #e0f2fe;
42
+ padding: 4px 8px;
43
+ border-radius: 4px;
44
+ display: inline-flex;
45
+ align-items: center;
46
+ gap: 6px;
47
+ }
@@ -0,0 +1,46 @@
1
+ import van from 'vanjs-core';
2
+
3
+ import {
4
+ FileText,
5
+ Plus,
6
+ Trash2,
7
+ PlayForward,
8
+ Eraser,
9
+ Download,
10
+ Loader2
11
+ } from '../icons/index.js';
12
+
13
+ const { button } = van.tags;
14
+
15
+ import { tags } from 'ziko/dom'
16
+
17
+ const { div, span } = tags
18
+
19
+ export const Button = ({ class: className = '', title = '', disabled = false, onclick }, ...children) =>
20
+ button({ class: `btn ${className}`, title, disabled, onclick }, ...children);
21
+
22
+ export function Header({ store, actions }) {
23
+ const statusBadge = span({ class: 'status-badge' }, Loader2(), span('Loading ...'));
24
+ const runAllBtn = Button({ class: 'btn-primary', onclick: actions.runAll, title : 'Run All' }, PlayForward());
25
+ const clearBtn = Button({ onclick: actions.clearOutputs, title : 'Clear Outputs' }, Eraser());
26
+ const addCodeBtn = Button({ onclick: actions.addCode, title : 'Add Code'}, Plus());
27
+ const addMdBtn = Button({ onclick: actions.addMarkdown, title : 'Add Markdown' }, FileText());
28
+ const deleteActiveBtn = Button({ onclick: actions.deleteActive, title : 'Delete Active cell' }, Trash2());
29
+ const exportBtn = Button({ onclick: actions.exportData, title : 'Export Data' }, Download());
30
+
31
+ store.on('change:executionQueueState', (q) => {
32
+ statusBadge.style({display :q.isRunning ? 'inline-flex' : 'none' })
33
+ statusBadge.element.lastChild.textContent = `Executing Queue (${q.currentIndex + 1}/${q.total})`;
34
+ [runAllBtn, clearBtn, deleteActiveBtn].forEach(b => { b.disabled = q.isRunning; });
35
+ const maxReached = store.get('cells').length >= store.get('maxCells');
36
+ addCodeBtn.disabled = q.isRunning || maxReached;
37
+ addMdBtn.disabled = q.isRunning || maxReached;
38
+ });
39
+
40
+ return div({ class: 'header' },
41
+ // div({ class: 'brand' }, '</>', statusBadge),
42
+ div({ class: 'toolbar' },
43
+ runAllBtn, clearBtn, addCodeBtn, addMdBtn, deleteActiveBtn, exportBtn
44
+ )
45
+ ).element;
46
+ }
@@ -0,0 +1,90 @@
1
+ /* --- MARKDOWN --- */
2
+
3
+ .ziko-notebook .markdown-rendered-cell {
4
+ grid-column: 1 / 3;
5
+ padding: 8px 12px;
6
+ cursor: pointer;
7
+ min-height: 38px;
8
+ border: 1px dashed transparent;
9
+ border-radius: 4px;
10
+ transition: background 0.15s ease, border-color 0.15s ease;
11
+ }
12
+
13
+ .ziko-notebook .markdown-rendered-cell:hover {
14
+ background: #f8fafc;
15
+ border-color: #cbd5e1;
16
+ }
17
+
18
+ .ziko-notebook .cell.active .markdown-rendered-cell {
19
+ border-color: #94a3b8;
20
+ }
21
+
22
+ .ziko-notebook .markdown-body {
23
+ line-height: 1.6;
24
+ }
25
+
26
+ .ziko-notebook .markdown-body h1,
27
+ .ziko-notebook .markdown-body h2,
28
+ .ziko-notebook .markdown-body h3 {
29
+ margin-top: 8px;
30
+ margin-bottom: 8px;
31
+ font-weight: 600;
32
+ }
33
+
34
+ .ziko-notebook .markdown-body h1 {
35
+ font-size: 1.5em;
36
+ border-bottom: 1px solid var(--border-color);
37
+ padding-bottom: 4px;
38
+ }
39
+
40
+ .ziko-notebook .markdown-body h2 {
41
+ font-size: 1.25em;
42
+ }
43
+
44
+ .ziko-notebook .markdown-body h3 {
45
+ font-size: 1.1em;
46
+ }
47
+
48
+ .ziko-notebook .markdown-body p {
49
+ margin-bottom: 8px;
50
+ }
51
+
52
+ .ziko-notebook .markdown-body p:last-child {
53
+ margin-bottom: 0;
54
+ }
55
+
56
+ .ziko-notebook .markdown-body ul,
57
+ .ziko-notebook .markdown-body ol {
58
+ padding-left: 20px;
59
+ margin-bottom: 8px;
60
+ }
61
+
62
+ .ziko-notebook .markdown-body code {
63
+ background: #f1f5f9;
64
+ padding: 2px 4px;
65
+ border-radius: 4px;
66
+ font-family: ui-monospace, SFMono-Regular, monospace;
67
+ font-size: 0.9em;
68
+ }
69
+
70
+ .ziko-notebook .markdown-body pre {
71
+ background: #1e293b;
72
+ color: #f8fafc;
73
+ padding: 10px;
74
+ border-radius: 6px;
75
+ overflow-x: auto;
76
+ margin: 8px 0;
77
+ }
78
+
79
+ .ziko-notebook .markdown-body pre code {
80
+ background: transparent;
81
+ color: inherit;
82
+ padding: 0;
83
+ }
84
+
85
+ .ziko-notebook .markdown-body blockquote {
86
+ border-left: 4px solid var(--primary);
87
+ padding-left: 10px;
88
+ color: #64748b;
89
+ margin: 8px 0;
90
+ }
@@ -0,0 +1,133 @@
1
+ import { remark } from "remark";
2
+ import remarkRehype from "remark-rehype";
3
+ import rehypeStringify from "rehype-stringify";
4
+
5
+ import { tags } from "ziko/dom";
6
+
7
+ const { div } = tags;
8
+
9
+ export function MarkdownView({
10
+ cellData,
11
+ actions,
12
+ remarkPlugins = [],
13
+ rehypePlugins = [],
14
+ }) {
15
+ const content = div();
16
+
17
+ remark()
18
+ .use(remarkPlugins)
19
+ .use(remarkRehype, { allowDangerousHtml: true })
20
+ .use(rehypePlugins)
21
+ .use(rehypeStringify)
22
+ .process(cellData.code || "*Empty Markdown Cell*")
23
+ .then((file) => {
24
+ content.element.innerHTML = String(file);
25
+ })
26
+ .catch((err) => {
27
+ content.element.innerHTML =
28
+ `<div class="error-output">Markdown rendering error: ${err.message}</div>`;
29
+ });
30
+
31
+ const wrap = div(
32
+ { class: "markdown-rendered-cell markdown-body" },
33
+ content
34
+ );
35
+
36
+ wrap.onClick(() => actions.editMarkdown());
37
+
38
+ return wrap.element;
39
+ }
40
+
41
+
42
+
43
+ // import { remark } from "remark";
44
+ // import remarkRehype from "remark-rehype";
45
+ // import rehypeStringify from "rehype-stringify";
46
+
47
+ // import { tags } from "ziko/dom";
48
+
49
+ // const { div } = tags;
50
+
51
+ // /**
52
+ // * Activate elements inserted through innerHTML.
53
+ // *
54
+ // * Scripts created by innerHTML are inert, so recreate them
55
+ // * as real DOM nodes. This also handles external scripts.
56
+ // */
57
+ // async function activateHTML(container) {
58
+ // const scripts = [
59
+ // ...container.querySelectorAll("script"),
60
+ // ];
61
+
62
+ // for (const oldScript of scripts) {
63
+ // const script = document.createElement("script");
64
+
65
+ // for (const attribute of oldScript.attributes) {
66
+ // script.setAttribute(
67
+ // attribute.name,
68
+ // attribute.value
69
+ // );
70
+ // }
71
+
72
+ // script.textContent = oldScript.textContent;
73
+
74
+ // oldScript.replaceWith(script);
75
+
76
+ // if (script.src) {
77
+ // await new Promise((resolve, reject) => {
78
+ // script.addEventListener(
79
+ // "load",
80
+ // resolve,
81
+ // { once: true }
82
+ // );
83
+
84
+ // script.addEventListener(
85
+ // "error",
86
+ // reject,
87
+ // { once: true }
88
+ // );
89
+ // });
90
+ // }
91
+ // }
92
+ // }
93
+
94
+ // export function MarkdownView({
95
+ // cellData,
96
+ // actions,
97
+ // remarkPlugins = [],
98
+ // rehypePlugins = [],
99
+ // }) {
100
+ // const content = div();
101
+
102
+ // remark()
103
+ // .use(remarkPlugins)
104
+ // .use(remarkRehype, {
105
+ // allowDangerousHtml: true,
106
+ // })
107
+ // .use(rehypePlugins)
108
+ // .use(rehypeStringify)
109
+ // .process(cellData.code || "*Empty Markdown Cell*")
110
+ // .then(async (file) => {
111
+ // content.element.innerHTML = String(file);
112
+
113
+ // await activateHTML(content.element);
114
+ // })
115
+ // .catch((err) => {
116
+ // content.element.innerHTML = `
117
+ // <div class="error-output">
118
+ // Markdown rendering error: ${err.message}
119
+ // </div>
120
+ // `;
121
+ // });
122
+
123
+ // const wrap = div(
124
+ // {
125
+ // class: "markdown-rendered-cell markdown-body",
126
+ // },
127
+ // content
128
+ // );
129
+
130
+ // wrap.onClick(() => actions.editMarkdown());
131
+
132
+ // return wrap.element;
133
+ // }
@@ -0,0 +1,21 @@
1
+ @import url('./ErrorOutput/index.css');
2
+ @import url('./Button/index.css');
3
+ @import url('./Header/index.css');
4
+ @import url('./MarkdownView//index.css');
5
+
6
+ .ziko-notebook .runtime-select {
7
+ font-family: inherit;
8
+ font-size: 11px;
9
+ padding: 2px 4px;
10
+ border: 1px solid var(--border-color);
11
+ border-radius: 4px;
12
+ background: #ffffff;
13
+ color: #1e293b;
14
+ cursor: pointer;
15
+ height: 24px;
16
+ }
17
+
18
+ .ziko-notebook .runtime-select:focus {
19
+ outline: none;
20
+ border-color: var(--primary);
21
+ }
@@ -0,0 +1,4 @@
1
+ export * from './MarkdownView/index.js'
2
+ export * from './CellItem/index.js'
3
+ export * from './Header/index.js'
4
+ export * from './ErrorOutput/index.js'
package/src/index.css CHANGED
@@ -1,3 +1,5 @@
1
+ @import url('./components/index.css');
2
+
1
3
  .ziko-notebook {
2
4
  --primary: #0284c7;
3
5
  --primary-hover: #0369a1;
@@ -10,53 +12,6 @@
10
12
  color: #1e293b;
11
13
  }
12
14
 
13
- /* --- HEADER & TOOLBAR --- */
14
-
15
- .ziko-notebook .header {
16
- border-bottom: 1px solid var(--border-color);
17
- background: #ffffff;
18
- padding: 10px 16px;
19
- display: flex;
20
- align-items: center;
21
- justify-content: space-between;
22
- gap: 12px;
23
- flex-wrap: wrap;
24
- position: sticky;
25
- top: 0;
26
- z-index: 100;
27
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
28
- width: 100%;
29
- }
30
-
31
- .ziko-notebook .brand {
32
- font-weight: 600;
33
- font-size: 16px;
34
- color: #0f172a;
35
- display: flex;
36
- align-items: center;
37
- gap: 12px;
38
- flex-shrink: 0;
39
- }
40
-
41
- .ziko-notebook .toolbar {
42
- display: flex;
43
- gap: 6px;
44
- align-items: center;
45
- flex-wrap: wrap;
46
- max-width: 100%;
47
- }
48
-
49
- .ziko-notebook .status-badge {
50
- font-size: 12px;
51
- font-weight: 500;
52
- color: var(--primary);
53
- background: #e0f2fe;
54
- padding: 4px 8px;
55
- border-radius: 4px;
56
- display: inline-flex;
57
- align-items: center;
58
- gap: 6px;
59
- }
60
15
 
61
16
  /* --- NOTEBOOK & CELLS --- */
62
17
 
@@ -133,12 +88,6 @@
133
88
  border-color: #cbd5e1;
134
89
  }
135
90
 
136
- /*
137
- * CodeMirror is an external component.
138
- *
139
- * Don't globally style .CodeMirror.
140
- * Scope only the CodeMirror instances owned by the notebook.
141
- */
142
91
  .ziko-notebook .input-wrapper .CodeMirror {
143
92
  font-family: "Fira Code", SFMono-Regular, Consolas, monospace;
144
93
  font-size: 13px;
@@ -162,7 +111,11 @@
162
111
  gap: 4px;
163
112
  flex-shrink: 0;
164
113
  flex-wrap: wrap;
165
- max-width: 120px;
114
+ max-width: 60px;
115
+ }
116
+
117
+ .ziko-notebook .cm-line{
118
+ line-height: 1.3 !important;
166
119
  }
167
120
 
168
121
  /* --- OUTPUT --- */
@@ -177,163 +130,7 @@
177
130
  word-break: break-word;
178
131
  }
179
132
 
180
- .ziko-notebook .error-output {
181
- color: #e11d48;
182
- font-family: ui-monospace, SFMono-Regular, monospace;
183
- white-space: pre-wrap;
184
- font-size: 12px;
185
- background: #fff1f2;
186
- padding: 8px;
187
- border-radius: 4px;
188
- border: 1px solid #fecdd3;
189
- }
190
-
191
- /* --- MARKDOWN --- */
192
-
193
- .ziko-notebook .markdown-rendered-cell {
194
- grid-column: 1 / 3;
195
- padding: 8px 12px;
196
- cursor: pointer;
197
- min-height: 38px;
198
- border: 1px dashed transparent;
199
- border-radius: 4px;
200
- transition: background 0.15s ease, border-color 0.15s ease;
201
- }
202
-
203
- .ziko-notebook .markdown-rendered-cell:hover {
204
- background: #f8fafc;
205
- border-color: #cbd5e1;
206
- }
207
-
208
- .ziko-notebook .cell.active .markdown-rendered-cell {
209
- border-color: #94a3b8;
210
- }
211
-
212
- .ziko-notebook .markdown-body {
213
- line-height: 1.6;
214
- }
215
-
216
- .ziko-notebook .markdown-body h1,
217
- .ziko-notebook .markdown-body h2,
218
- .ziko-notebook .markdown-body h3 {
219
- margin-top: 8px;
220
- margin-bottom: 8px;
221
- font-weight: 600;
222
- }
223
-
224
- .ziko-notebook .markdown-body h1 {
225
- font-size: 1.5em;
226
- border-bottom: 1px solid var(--border-color);
227
- padding-bottom: 4px;
228
- }
229
-
230
- .ziko-notebook .markdown-body h2 {
231
- font-size: 1.25em;
232
- }
233
-
234
- .ziko-notebook .markdown-body h3 {
235
- font-size: 1.1em;
236
- }
237
-
238
- .ziko-notebook .markdown-body p {
239
- margin-bottom: 8px;
240
- }
241
-
242
- .ziko-notebook .markdown-body p:last-child {
243
- margin-bottom: 0;
244
- }
245
-
246
- .ziko-notebook .markdown-body ul,
247
- .ziko-notebook .markdown-body ol {
248
- padding-left: 20px;
249
- margin-bottom: 8px;
250
- }
251
-
252
- .ziko-notebook .markdown-body code {
253
- background: #f1f5f9;
254
- padding: 2px 4px;
255
- border-radius: 4px;
256
- font-family: ui-monospace, SFMono-Regular, monospace;
257
- font-size: 0.9em;
258
- }
259
-
260
- .ziko-notebook .markdown-body pre {
261
- background: #1e293b;
262
- color: #f8fafc;
263
- padding: 10px;
264
- border-radius: 6px;
265
- overflow-x: auto;
266
- margin: 8px 0;
267
- }
268
-
269
- .ziko-notebook .markdown-body pre code {
270
- background: transparent;
271
- color: inherit;
272
- padding: 0;
273
- }
274
-
275
- .ziko-notebook .markdown-body blockquote {
276
- border-left: 4px solid var(--primary);
277
- padding-left: 10px;
278
- color: #64748b;
279
- margin: 8px 0;
280
- }
281
-
282
- /* --- BUTTONS --- */
283
133
 
284
- .ziko-notebook .btn {
285
- display: inline-flex;
286
- align-items: center;
287
- justify-content: center;
288
- gap: 6px;
289
- background: #ffffff;
290
- border: 1px solid var(--border-color);
291
- padding: 6px 10px;
292
- border-radius: 4px;
293
- font-size: 12px;
294
- font-weight: 500;
295
- color: #334155;
296
- cursor: pointer;
297
- line-height: 1;
298
- white-space: nowrap;
299
- transition: background 0.12s ease, border-color 0.12s ease;
300
- }
301
-
302
- .ziko-notebook .btn:hover {
303
- background: #f1f5f9;
304
- }
305
-
306
- .ziko-notebook .btn:disabled {
307
- opacity: 0.5;
308
- cursor: not-allowed;
309
- }
310
-
311
- .ziko-notebook .btn-icon {
312
- padding: 6px;
313
- border-radius: 4px;
314
- }
315
-
316
- .ziko-notebook .btn-primary {
317
- background: var(--primary);
318
- color: #ffffff;
319
- border-color: var(--primary);
320
- }
321
-
322
- .ziko-notebook .btn-primary:hover {
323
- background: var(--primary-hover);
324
- border-color: var(--primary-hover);
325
- }
326
-
327
- .ziko-notebook .btn-active {
328
- background: #e2e8f0;
329
- border-color: #cbd5e1;
330
- }
331
-
332
- .ziko-notebook .icon {
333
- width: 14px;
334
- height: 14px;
335
- stroke-width: 2;
336
- }
337
134
 
338
135
  /* --- MOBILE --- */
339
136
 
@@ -344,7 +141,7 @@
344
141
 
345
142
  .ziko-notebook .toolbar {
346
143
  width: 100%;
347
- justify-content: flex-start;
144
+ justify-content: center;
348
145
  }
349
146
 
350
147
  .ziko-notebook .cell-input-grid {