@zikojs/notebook 0.7.1 → 0.7.3
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/package.json +2 -2
- package/src/codeEditor.js +3 -3
- package/src/components.js +19 -20
- package/src/index.css +66 -68
- package/src/main.js +0 -1
- package/src/notebook.js +15 -7
- /package/src/{main.ts → index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zikojs/notebook",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"./no-css": {
|
|
25
25
|
"import": "./src/main.js",
|
|
26
|
-
"types": "./src/
|
|
26
|
+
"types": "./src/index.d.ts"
|
|
27
27
|
},
|
|
28
28
|
"./style": {
|
|
29
29
|
"import": "./src/index.css"
|
package/src/codeEditor.js
CHANGED
|
@@ -13,7 +13,7 @@ const languageFor = (type) =>
|
|
|
13
13
|
type === "markdown" ? markdown() : javascript();
|
|
14
14
|
|
|
15
15
|
export function createCodeEditor(app, cellData, actions) {
|
|
16
|
-
const editorDom = div({ class: "input-wrapper" })
|
|
16
|
+
const editorDom = div({ class: "input-wrapper" });
|
|
17
17
|
|
|
18
18
|
const languageCompartment = new Compartment();
|
|
19
19
|
const readOnlyCompartment = new Compartment();
|
|
@@ -143,7 +143,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
143
143
|
|
|
144
144
|
view = new EditorView({
|
|
145
145
|
state,
|
|
146
|
-
parent: editorDom
|
|
146
|
+
parent: editorDom.element
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
const lineHeight = view.defaultLineHeight || 19;
|
|
@@ -159,7 +159,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
159
159
|
};
|
|
160
160
|
|
|
161
161
|
return {
|
|
162
|
-
dom: editorDom,
|
|
162
|
+
dom: editorDom.element,
|
|
163
163
|
|
|
164
164
|
getValue: () =>
|
|
165
165
|
view
|
package/src/components.js
CHANGED
|
@@ -31,17 +31,17 @@ export const Button = ({ class: className = "", title = "", disabled = false, on
|
|
|
31
31
|
button({ class: `btn ${className}`, title, disabled, onclick }, ...children);
|
|
32
32
|
|
|
33
33
|
export function Header({ store, actions }) {
|
|
34
|
-
const statusBadge = span({ class: "status-badge" }, Loader2(), span('Loading ...'))
|
|
34
|
+
const statusBadge = span({ class: "status-badge" }, Loader2(), span('Loading ...'));
|
|
35
35
|
const runAllBtn = Button({ class: "btn-primary", onclick: actions.runAll }, PlayForward(), "Run All");
|
|
36
36
|
const clearBtn = Button({ onclick: actions.clearOutputs }, Eraser(), "Clear Outputs");
|
|
37
|
-
const addCodeBtn = Button({ onclick: actions.addCode },
|
|
37
|
+
const addCodeBtn = Button({ onclick: actions.addCode }, Plus(), "Add Code");
|
|
38
38
|
const addMdBtn = Button({ onclick: actions.addMarkdown }, FileText(), "Add Markdown");
|
|
39
39
|
const deleteActiveBtn = Button({ onclick: actions.deleteActive }, Trash2(), "Delete Active");
|
|
40
40
|
const exportBtn = Button({ onclick: actions.exportData }, Download(), "Export Data");
|
|
41
41
|
|
|
42
42
|
store.on('change:executionQueueState', (q) => {
|
|
43
|
-
statusBadge.style
|
|
44
|
-
statusBadge.lastChild.textContent = `Executing Queue (${q.currentIndex + 1}/${q.total})`;
|
|
43
|
+
statusBadge.style({display :q.isRunning ? "inline-flex" : "none" })
|
|
44
|
+
statusBadge.element.lastChild.textContent = `Executing Queue (${q.currentIndex + 1}/${q.total})`;
|
|
45
45
|
[runAllBtn, clearBtn, deleteActiveBtn].forEach(b => { b.disabled = q.isRunning; });
|
|
46
46
|
const maxReached = store.get('cells').length >= store.get('maxCells');
|
|
47
47
|
addCodeBtn.disabled = q.isRunning || maxReached;
|
|
@@ -57,7 +57,7 @@ export function Header({ store, actions }) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export function MarkdownView({ cellData, actions }) {
|
|
60
|
-
const content = div()
|
|
60
|
+
const content = div();
|
|
61
61
|
|
|
62
62
|
// Process Markdown asynchronously using Remark + Rehype
|
|
63
63
|
remark()
|
|
@@ -65,10 +65,10 @@ export function MarkdownView({ cellData, actions }) {
|
|
|
65
65
|
.use(rehypeStringify)
|
|
66
66
|
.process(cellData.code || "*Empty Markdown Cell*")
|
|
67
67
|
.then((file) => {
|
|
68
|
-
content.innerHTML = String(file);
|
|
68
|
+
content.element.innerHTML = String(file);
|
|
69
69
|
})
|
|
70
70
|
.catch((err) => {
|
|
71
|
-
content.innerHTML = `<div class="error-output">Markdown rendering error: ${err.message}</div>`;
|
|
71
|
+
content.element.innerHTML = `<div class="error-output">Markdown rendering error: ${err.message}</div>`;
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
const wrap = div({ class: "markdown-rendered-cell markdown-body" }, content);
|
|
@@ -150,30 +150,29 @@ export function CellControls({ cellData, store, actions }) {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export function CellItem({ cellData, app, store }) {
|
|
153
|
-
const outputRef = div({ class: "output-area" })
|
|
154
|
-
if (cellData.outputNode) outputRef.
|
|
155
|
-
cellData._outputRef = outputRef;
|
|
153
|
+
const outputRef = div({ class: "output-area" });
|
|
154
|
+
if (cellData.outputNode) outputRef.append(cellData.outputNode);
|
|
155
|
+
cellData._outputRef = outputRef.element;
|
|
156
156
|
|
|
157
157
|
const actions = app._cellActions(cellData);
|
|
158
158
|
cellData._actions = actions;
|
|
159
159
|
cellData._editor = createCodeEditor(app, cellData, actions);
|
|
160
160
|
|
|
161
|
-
const inPrompt = span({ class: "prompt" })
|
|
162
|
-
const outPrompt = span({ class: "prompt out" })
|
|
163
|
-
const bodySlot = div().style({ display : 'contents'})
|
|
161
|
+
const inPrompt = span({ class: "prompt" });
|
|
162
|
+
const outPrompt = span({ class: "prompt out" });
|
|
163
|
+
const bodySlot = div().style({ display : 'contents'});
|
|
164
164
|
const controlsEl = CellControls({ cellData, store, actions });
|
|
165
165
|
|
|
166
|
-
const outputGrid = div({ class: "cell-output-grid" }, outPrompt, div({ class: "output-wrapper" }, outputRef))
|
|
167
|
-
const inputGrid = div({ class: "cell-input-grid" }, inPrompt, bodySlot, controlsEl)
|
|
166
|
+
const outputGrid = div({ class: "cell-output-grid" }, outPrompt, div({ class: "output-wrapper" }, outputRef));
|
|
167
|
+
const inputGrid = div({ class: "cell-input-grid" }, inPrompt, bodySlot, controlsEl);
|
|
168
168
|
const root = div({ class: "cell" }, inputGrid, outputGrid);
|
|
169
169
|
root.onClick(() => app.setActiveCell(cellData.id));
|
|
170
|
-
// root.onclick = () => app.setActiveCell(cellData.id);
|
|
171
170
|
|
|
172
171
|
cellData._dom = root.element;
|
|
173
|
-
cellData._inPrompt = inPrompt;
|
|
174
|
-
cellData._outPrompt = outPrompt;
|
|
175
|
-
cellData._bodySlot = bodySlot;
|
|
176
|
-
cellData._outputGrid = outputGrid;
|
|
172
|
+
cellData._inPrompt = inPrompt.element;
|
|
173
|
+
cellData._outPrompt = outPrompt.element;
|
|
174
|
+
cellData._bodySlot = bodySlot.element;
|
|
175
|
+
cellData._outputGrid = outputGrid.element;
|
|
177
176
|
|
|
178
177
|
app._refreshCell(cellData);
|
|
179
178
|
return root.element;
|
package/src/index.css
CHANGED
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
.ziko-notebook {
|
|
2
2
|
--primary: #0284c7;
|
|
3
3
|
--primary-hover: #0369a1;
|
|
4
4
|
--border-color: #e2e8f0;
|
|
5
5
|
--prompt-in: #303f9f;
|
|
6
6
|
--prompt-out: #d62728;
|
|
7
7
|
--bg-editor: #f8fafc;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
* {
|
|
11
|
-
box-sizing: border-box;
|
|
12
|
-
margin: 0;
|
|
13
|
-
padding: 0;
|
|
14
|
-
}
|
|
15
8
|
|
|
16
|
-
body {
|
|
17
9
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
18
|
-
background: #ffffff;
|
|
19
10
|
color: #1e293b;
|
|
20
11
|
}
|
|
21
12
|
|
|
22
13
|
/* --- HEADER & TOOLBAR --- */
|
|
23
14
|
|
|
24
|
-
.header {
|
|
15
|
+
.ziko-notebook .header {
|
|
25
16
|
border-bottom: 1px solid var(--border-color);
|
|
26
17
|
background: #ffffff;
|
|
27
18
|
padding: 10px 16px;
|
|
@@ -37,7 +28,7 @@ body {
|
|
|
37
28
|
width: 100%;
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
.brand {
|
|
31
|
+
.ziko-notebook .brand {
|
|
41
32
|
font-weight: 600;
|
|
42
33
|
font-size: 16px;
|
|
43
34
|
color: #0f172a;
|
|
@@ -47,7 +38,7 @@ body {
|
|
|
47
38
|
flex-shrink: 0;
|
|
48
39
|
}
|
|
49
40
|
|
|
50
|
-
.toolbar {
|
|
41
|
+
.ziko-notebook .toolbar {
|
|
51
42
|
display: flex;
|
|
52
43
|
gap: 6px;
|
|
53
44
|
align-items: center;
|
|
@@ -55,10 +46,10 @@ body {
|
|
|
55
46
|
max-width: 100%;
|
|
56
47
|
}
|
|
57
48
|
|
|
58
|
-
.status-badge {
|
|
49
|
+
.ziko-notebook .status-badge {
|
|
59
50
|
font-size: 12px;
|
|
60
51
|
font-weight: 500;
|
|
61
|
-
color:
|
|
52
|
+
color: var(--primary);
|
|
62
53
|
background: #e0f2fe;
|
|
63
54
|
padding: 4px 8px;
|
|
64
55
|
border-radius: 4px;
|
|
@@ -69,7 +60,7 @@ body {
|
|
|
69
60
|
|
|
70
61
|
/* --- NOTEBOOK & CELLS --- */
|
|
71
62
|
|
|
72
|
-
.notebook {
|
|
63
|
+
.ziko-notebook .notebook {
|
|
73
64
|
max-width: 900px;
|
|
74
65
|
margin: 16px auto;
|
|
75
66
|
padding: 0 8px;
|
|
@@ -78,7 +69,7 @@ body {
|
|
|
78
69
|
gap: 12px;
|
|
79
70
|
}
|
|
80
71
|
|
|
81
|
-
.cell {
|
|
72
|
+
.ziko-notebook .cell {
|
|
82
73
|
display: flex;
|
|
83
74
|
flex-direction: column;
|
|
84
75
|
border: 1px solid var(--border-color);
|
|
@@ -91,12 +82,12 @@ body {
|
|
|
91
82
|
position: relative;
|
|
92
83
|
}
|
|
93
84
|
|
|
94
|
-
.cell.active {
|
|
85
|
+
.ziko-notebook .cell.active {
|
|
95
86
|
border-left-color: var(--primary);
|
|
96
87
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
|
97
88
|
}
|
|
98
89
|
|
|
99
|
-
.cell-input-grid {
|
|
90
|
+
.ziko-notebook .cell-input-grid {
|
|
100
91
|
display: grid;
|
|
101
92
|
grid-template-columns: 56px 1fr auto;
|
|
102
93
|
align-items: flex-start;
|
|
@@ -104,7 +95,7 @@ body {
|
|
|
104
95
|
width: 100%;
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
.cell-output-grid {
|
|
98
|
+
.ziko-notebook .cell-output-grid {
|
|
108
99
|
display: grid;
|
|
109
100
|
grid-template-columns: 56px 1fr;
|
|
110
101
|
align-items: flex-start;
|
|
@@ -112,7 +103,7 @@ body {
|
|
|
112
103
|
width: 100%;
|
|
113
104
|
}
|
|
114
105
|
|
|
115
|
-
.prompt {
|
|
106
|
+
.ziko-notebook .prompt {
|
|
116
107
|
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
117
108
|
font-size: 11px;
|
|
118
109
|
color: var(--prompt-in);
|
|
@@ -123,13 +114,13 @@ body {
|
|
|
123
114
|
font-weight: 700;
|
|
124
115
|
}
|
|
125
116
|
|
|
126
|
-
.prompt.out {
|
|
117
|
+
.ziko-notebook .prompt.out {
|
|
127
118
|
color: var(--prompt-out);
|
|
128
119
|
}
|
|
129
120
|
|
|
130
|
-
/* ---
|
|
121
|
+
/* --- INPUT --- */
|
|
131
122
|
|
|
132
|
-
.input-wrapper {
|
|
123
|
+
.ziko-notebook .input-wrapper {
|
|
133
124
|
border: 1px solid var(--border-color);
|
|
134
125
|
border-radius: 4px;
|
|
135
126
|
background: var(--bg-editor);
|
|
@@ -138,11 +129,17 @@ body {
|
|
|
138
129
|
transition: border-color 0.15s ease;
|
|
139
130
|
}
|
|
140
131
|
|
|
141
|
-
.cell.active .input-wrapper {
|
|
132
|
+
.ziko-notebook .cell.active .input-wrapper {
|
|
142
133
|
border-color: #cbd5e1;
|
|
143
134
|
}
|
|
144
135
|
|
|
145
|
-
|
|
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
|
+
.ziko-notebook .input-wrapper .CodeMirror {
|
|
146
143
|
font-family: "Fira Code", SFMono-Regular, Consolas, monospace;
|
|
147
144
|
font-size: 13px;
|
|
148
145
|
height: auto !important;
|
|
@@ -150,17 +147,16 @@ body {
|
|
|
150
147
|
border-radius: 4px;
|
|
151
148
|
}
|
|
152
149
|
|
|
153
|
-
.CodeMirror-scroll {
|
|
154
|
-
/* Overflow reset ensures height auto-fits custom minLines properly */
|
|
150
|
+
.ziko-notebook .input-wrapper .CodeMirror-scroll {
|
|
155
151
|
overflow-y: hidden !important;
|
|
156
152
|
overflow-x: auto !important;
|
|
157
153
|
}
|
|
158
154
|
|
|
159
|
-
.CodeMirror-activeline-background {
|
|
155
|
+
.ziko-notebook .input-wrapper .CodeMirror-activeline-background {
|
|
160
156
|
background: rgba(2, 132, 199, 0.05);
|
|
161
157
|
}
|
|
162
158
|
|
|
163
|
-
.cell-controls {
|
|
159
|
+
.ziko-notebook .cell-controls {
|
|
164
160
|
display: flex;
|
|
165
161
|
align-items: center;
|
|
166
162
|
gap: 4px;
|
|
@@ -169,19 +165,19 @@ body {
|
|
|
169
165
|
max-width: 120px;
|
|
170
166
|
}
|
|
171
167
|
|
|
172
|
-
/* ---
|
|
168
|
+
/* --- OUTPUT --- */
|
|
173
169
|
|
|
174
|
-
.output-wrapper {
|
|
170
|
+
.ziko-notebook .output-wrapper {
|
|
175
171
|
width: 100%;
|
|
176
172
|
padding: 4px 0;
|
|
177
173
|
}
|
|
178
174
|
|
|
179
|
-
.output-area {
|
|
175
|
+
.ziko-notebook .output-area {
|
|
180
176
|
font-size: 14px;
|
|
181
177
|
word-break: break-word;
|
|
182
178
|
}
|
|
183
179
|
|
|
184
|
-
.error-output {
|
|
180
|
+
.ziko-notebook .error-output {
|
|
185
181
|
color: #e11d48;
|
|
186
182
|
font-family: ui-monospace, SFMono-Regular, monospace;
|
|
187
183
|
white-space: pre-wrap;
|
|
@@ -192,7 +188,9 @@ body {
|
|
|
192
188
|
border: 1px solid #fecdd3;
|
|
193
189
|
}
|
|
194
190
|
|
|
195
|
-
|
|
191
|
+
/* --- MARKDOWN --- */
|
|
192
|
+
|
|
193
|
+
.ziko-notebook .markdown-rendered-cell {
|
|
196
194
|
grid-column: 1 / 3;
|
|
197
195
|
padding: 8px 12px;
|
|
198
196
|
cursor: pointer;
|
|
@@ -202,56 +200,56 @@ body {
|
|
|
202
200
|
transition: background 0.15s ease, border-color 0.15s ease;
|
|
203
201
|
}
|
|
204
202
|
|
|
205
|
-
.markdown-rendered-cell:hover {
|
|
203
|
+
.ziko-notebook .markdown-rendered-cell:hover {
|
|
206
204
|
background: #f8fafc;
|
|
207
205
|
border-color: #cbd5e1;
|
|
208
206
|
}
|
|
209
207
|
|
|
210
|
-
.cell.active .markdown-rendered-cell {
|
|
208
|
+
.ziko-notebook .cell.active .markdown-rendered-cell {
|
|
211
209
|
border-color: #94a3b8;
|
|
212
210
|
}
|
|
213
211
|
|
|
214
|
-
.markdown-body {
|
|
212
|
+
.ziko-notebook .markdown-body {
|
|
215
213
|
line-height: 1.6;
|
|
216
214
|
}
|
|
217
215
|
|
|
218
|
-
.markdown-body h1,
|
|
219
|
-
.markdown-body h2,
|
|
220
|
-
.markdown-body h3 {
|
|
216
|
+
.ziko-notebook .markdown-body h1,
|
|
217
|
+
.ziko-notebook .markdown-body h2,
|
|
218
|
+
.ziko-notebook .markdown-body h3 {
|
|
221
219
|
margin-top: 8px;
|
|
222
220
|
margin-bottom: 8px;
|
|
223
221
|
font-weight: 600;
|
|
224
222
|
}
|
|
225
223
|
|
|
226
|
-
.markdown-body h1 {
|
|
224
|
+
.ziko-notebook .markdown-body h1 {
|
|
227
225
|
font-size: 1.5em;
|
|
228
226
|
border-bottom: 1px solid var(--border-color);
|
|
229
227
|
padding-bottom: 4px;
|
|
230
228
|
}
|
|
231
229
|
|
|
232
|
-
.markdown-body h2 {
|
|
230
|
+
.ziko-notebook .markdown-body h2 {
|
|
233
231
|
font-size: 1.25em;
|
|
234
232
|
}
|
|
235
233
|
|
|
236
|
-
.markdown-body h3 {
|
|
234
|
+
.ziko-notebook .markdown-body h3 {
|
|
237
235
|
font-size: 1.1em;
|
|
238
236
|
}
|
|
239
237
|
|
|
240
|
-
.markdown-body p {
|
|
238
|
+
.ziko-notebook .markdown-body p {
|
|
241
239
|
margin-bottom: 8px;
|
|
242
240
|
}
|
|
243
241
|
|
|
244
|
-
.markdown-body p:last-child {
|
|
242
|
+
.ziko-notebook .markdown-body p:last-child {
|
|
245
243
|
margin-bottom: 0;
|
|
246
244
|
}
|
|
247
245
|
|
|
248
|
-
.markdown-body ul,
|
|
249
|
-
.markdown-body ol {
|
|
246
|
+
.ziko-notebook .markdown-body ul,
|
|
247
|
+
.ziko-notebook .markdown-body ol {
|
|
250
248
|
padding-left: 20px;
|
|
251
249
|
margin-bottom: 8px;
|
|
252
250
|
}
|
|
253
251
|
|
|
254
|
-
.markdown-body code {
|
|
252
|
+
.ziko-notebook .markdown-body code {
|
|
255
253
|
background: #f1f5f9;
|
|
256
254
|
padding: 2px 4px;
|
|
257
255
|
border-radius: 4px;
|
|
@@ -259,7 +257,7 @@ body {
|
|
|
259
257
|
font-size: 0.9em;
|
|
260
258
|
}
|
|
261
259
|
|
|
262
|
-
.markdown-body pre {
|
|
260
|
+
.ziko-notebook .markdown-body pre {
|
|
263
261
|
background: #1e293b;
|
|
264
262
|
color: #f8fafc;
|
|
265
263
|
padding: 10px;
|
|
@@ -268,22 +266,22 @@ body {
|
|
|
268
266
|
margin: 8px 0;
|
|
269
267
|
}
|
|
270
268
|
|
|
271
|
-
.markdown-body pre code {
|
|
269
|
+
.ziko-notebook .markdown-body pre code {
|
|
272
270
|
background: transparent;
|
|
273
271
|
color: inherit;
|
|
274
272
|
padding: 0;
|
|
275
273
|
}
|
|
276
274
|
|
|
277
|
-
.markdown-body blockquote {
|
|
275
|
+
.ziko-notebook .markdown-body blockquote {
|
|
278
276
|
border-left: 4px solid var(--primary);
|
|
279
277
|
padding-left: 10px;
|
|
280
278
|
color: #64748b;
|
|
281
279
|
margin: 8px 0;
|
|
282
280
|
}
|
|
283
281
|
|
|
284
|
-
/* --- BUTTONS
|
|
282
|
+
/* --- BUTTONS --- */
|
|
285
283
|
|
|
286
|
-
.btn {
|
|
284
|
+
.ziko-notebook .btn {
|
|
287
285
|
display: inline-flex;
|
|
288
286
|
align-items: center;
|
|
289
287
|
justify-content: center;
|
|
@@ -301,60 +299,60 @@ body {
|
|
|
301
299
|
transition: background 0.12s ease, border-color 0.12s ease;
|
|
302
300
|
}
|
|
303
301
|
|
|
304
|
-
.btn:hover {
|
|
302
|
+
.ziko-notebook .btn:hover {
|
|
305
303
|
background: #f1f5f9;
|
|
306
304
|
}
|
|
307
305
|
|
|
308
|
-
.btn:disabled {
|
|
306
|
+
.ziko-notebook .btn:disabled {
|
|
309
307
|
opacity: 0.5;
|
|
310
308
|
cursor: not-allowed;
|
|
311
309
|
}
|
|
312
310
|
|
|
313
|
-
.btn-icon {
|
|
311
|
+
.ziko-notebook .btn-icon {
|
|
314
312
|
padding: 6px;
|
|
315
313
|
border-radius: 4px;
|
|
316
314
|
}
|
|
317
315
|
|
|
318
|
-
.btn-primary {
|
|
316
|
+
.ziko-notebook .btn-primary {
|
|
319
317
|
background: var(--primary);
|
|
320
318
|
color: #ffffff;
|
|
321
319
|
border-color: var(--primary);
|
|
322
320
|
}
|
|
323
321
|
|
|
324
|
-
.btn-primary:hover {
|
|
322
|
+
.ziko-notebook .btn-primary:hover {
|
|
325
323
|
background: var(--primary-hover);
|
|
326
324
|
border-color: var(--primary-hover);
|
|
327
325
|
}
|
|
328
326
|
|
|
329
|
-
.btn-active {
|
|
327
|
+
.ziko-notebook .btn-active {
|
|
330
328
|
background: #e2e8f0;
|
|
331
329
|
border-color: #cbd5e1;
|
|
332
330
|
}
|
|
333
331
|
|
|
334
|
-
.icon {
|
|
332
|
+
.ziko-notebook .icon {
|
|
335
333
|
width: 14px;
|
|
336
334
|
height: 14px;
|
|
337
335
|
stroke-width: 2;
|
|
338
336
|
}
|
|
339
337
|
|
|
340
|
-
/* --- MOBILE
|
|
338
|
+
/* --- MOBILE --- */
|
|
341
339
|
|
|
342
340
|
@media (max-width: 640px) {
|
|
343
|
-
.header {
|
|
341
|
+
.ziko-notebook .header {
|
|
344
342
|
padding: 8px 12px;
|
|
345
343
|
}
|
|
346
344
|
|
|
347
|
-
.toolbar {
|
|
345
|
+
.ziko-notebook .toolbar {
|
|
348
346
|
width: 100%;
|
|
349
347
|
justify-content: flex-start;
|
|
350
348
|
}
|
|
351
349
|
|
|
352
|
-
.cell-input-grid {
|
|
350
|
+
.ziko-notebook .cell-input-grid {
|
|
353
351
|
grid-template-columns: 42px 1fr;
|
|
354
352
|
grid-template-rows: auto auto;
|
|
355
353
|
}
|
|
356
354
|
|
|
357
|
-
.cell-controls {
|
|
355
|
+
.ziko-notebook .cell-controls {
|
|
358
356
|
grid-column: 1 / -1;
|
|
359
357
|
justify-content: flex-end;
|
|
360
358
|
border-bottom: 1px solid #f1f5f9;
|
|
@@ -363,11 +361,11 @@ body {
|
|
|
363
361
|
max-width: 100%;
|
|
364
362
|
}
|
|
365
363
|
|
|
366
|
-
.cell-output-grid {
|
|
364
|
+
.ziko-notebook .cell-output-grid {
|
|
367
365
|
grid-template-columns: 42px 1fr;
|
|
368
366
|
}
|
|
369
367
|
|
|
370
|
-
.prompt {
|
|
368
|
+
.ziko-notebook .prompt {
|
|
371
369
|
font-size: 10px;
|
|
372
370
|
padding-top: 6px;
|
|
373
371
|
}
|
package/src/main.js
CHANGED
package/src/notebook.js
CHANGED
|
@@ -2,7 +2,9 @@ import { NotebookStore } from "./store.js";
|
|
|
2
2
|
import { Header, CellItem, MarkdownView } from "./components.js";
|
|
3
3
|
import { evaluateCodeAsync } from "./transform.js";
|
|
4
4
|
import { tags, UIElement } from "ziko/dom";
|
|
5
|
+
import { call_with_optional_props } from 'ziko/dom/internal-utils'
|
|
5
6
|
|
|
7
|
+
const { div } = tags
|
|
6
8
|
export class UINotebook extends UIElement{
|
|
7
9
|
constructor({
|
|
8
10
|
cells: initialCells = [],
|
|
@@ -11,9 +13,11 @@ export class UINotebook extends UIElement{
|
|
|
11
13
|
codeMirrorConfig = {},
|
|
12
14
|
codeMirrorPlugins = [],
|
|
13
15
|
minLines = 3,
|
|
14
|
-
maxCells = Infinity
|
|
16
|
+
maxCells = Infinity,
|
|
17
|
+
showHeader = true
|
|
15
18
|
} = {}) {
|
|
16
19
|
super({ element : 'div'})
|
|
20
|
+
this.setAttr({class : 'ziko-notebook'})
|
|
17
21
|
this.id = crypto.randomUUID ? crypto.randomUUID() : 'nb_' + Math.random().toString(36).substring(2, 9);
|
|
18
22
|
|
|
19
23
|
if (!window.__notebook_scope_map) {
|
|
@@ -28,7 +32,7 @@ export class UINotebook extends UIElement{
|
|
|
28
32
|
this.maxCells = maxCells;
|
|
29
33
|
|
|
30
34
|
const startingCells = maxCells !== Infinity ? initialCells.slice(0, maxCells) : initialCells;
|
|
31
|
-
|
|
35
|
+
let nextCellId = startingCells.length ? Math.max(...startingCells.map(c => c.id || 0)) + 1 : 1;
|
|
32
36
|
|
|
33
37
|
this.store = new NotebookStore({
|
|
34
38
|
cells: startingCells.map(cell => ({
|
|
@@ -58,7 +62,7 @@ export class UINotebook extends UIElement{
|
|
|
58
62
|
addCodeBelow: () => this.addCell("code", "", this.store.get('activeCellId'))
|
|
59
63
|
};
|
|
60
64
|
|
|
61
|
-
this.cellsContainer =
|
|
65
|
+
this.cellsContainer = div({ class: "cells-container" }).element;
|
|
62
66
|
this.header = Header({
|
|
63
67
|
store: this.store,
|
|
64
68
|
actions: {
|
|
@@ -71,9 +75,11 @@ export class UINotebook extends UIElement{
|
|
|
71
75
|
}
|
|
72
76
|
});
|
|
73
77
|
|
|
78
|
+
if(!showHeader) this.header.style.display = 'none'
|
|
79
|
+
|
|
74
80
|
this.append(
|
|
75
81
|
this.header,
|
|
76
|
-
|
|
82
|
+
div({ class: "notebook" },
|
|
77
83
|
this.cellsContainer)
|
|
78
84
|
)
|
|
79
85
|
|
|
@@ -120,7 +126,7 @@ export class UINotebook extends UIElement{
|
|
|
120
126
|
await evaluateCodeAsync(code, cellData._outputRef, app.importMap, scope);
|
|
121
127
|
} catch (err) {
|
|
122
128
|
hasError = true;
|
|
123
|
-
|
|
129
|
+
div({ class: "error-output" }, err.toString()).mount(cellData._outputRef)
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
const counter = this.store.get('executionCounter');
|
|
@@ -128,7 +134,7 @@ export class UINotebook extends UIElement{
|
|
|
128
134
|
cellData.execCount = counter;
|
|
129
135
|
cellData.hasDomOutput = cellData._outputRef.childNodes.length > 0 || hasError;
|
|
130
136
|
|
|
131
|
-
const container =
|
|
137
|
+
const container = div({ class: "output-area" }).element;
|
|
132
138
|
while (cellData._outputRef.firstChild) container.appendChild(cellData._outputRef.firstChild);
|
|
133
139
|
cellData.outputNode = container;
|
|
134
140
|
cellData._outputRef.appendChild(container);
|
|
@@ -341,4 +347,6 @@ export class UINotebook extends UIElement{
|
|
|
341
347
|
return exportedCell;
|
|
342
348
|
});
|
|
343
349
|
}
|
|
344
|
-
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export const Notebook = call_with_optional_props(UINotebook)
|
|
File without changes
|