@zikojs/notebook 0.14.1 → 0.14.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zikojs/notebook",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "A lightweight, extensible JavaScript notebook component with Markdown, executable cells, persistent state, and pluggable runtimes.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
package/src/code-editor/index.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EditorView,
|
|
3
|
+
keymap,
|
|
4
|
+
lineNumbers,
|
|
5
|
+
highlightActiveLine,
|
|
6
|
+
} from "@codemirror/view";
|
|
2
7
|
import { EditorState, Compartment } from "@codemirror/state";
|
|
3
|
-
import {
|
|
4
|
-
|
|
8
|
+
import {
|
|
9
|
+
defaultKeymap,
|
|
10
|
+
history,
|
|
11
|
+
historyKeymap,
|
|
12
|
+
indentWithTab,
|
|
13
|
+
} from "@codemirror/commands";
|
|
14
|
+
import {
|
|
15
|
+
bracketMatching,
|
|
16
|
+
indentUnit,
|
|
17
|
+
syntaxHighlighting,
|
|
18
|
+
defaultHighlightStyle,
|
|
19
|
+
} from "@codemirror/language";
|
|
5
20
|
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
6
21
|
import { javascript } from "@codemirror/lang-javascript";
|
|
7
22
|
import { markdown } from "@codemirror/lang-markdown";
|
|
@@ -9,7 +24,6 @@ import { tags } from "ziko/dom";
|
|
|
9
24
|
|
|
10
25
|
const { div } = tags;
|
|
11
26
|
|
|
12
|
-
|
|
13
27
|
const getRuntimePlugin = (runtime, runtimePlugins = []) =>
|
|
14
28
|
runtimePlugins.find((plugin) => plugin?.name === runtime);
|
|
15
29
|
|
|
@@ -39,7 +53,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
39
53
|
const buildPluginKeymap = () => {
|
|
40
54
|
const bindings = [];
|
|
41
55
|
|
|
42
|
-
app.codeMirrorPlugins.forEach(plugin => {
|
|
56
|
+
app.codeMirrorPlugins.forEach((plugin) => {
|
|
43
57
|
if (plugin && typeof plugin === "object" && plugin.extraKeys) {
|
|
44
58
|
Object.entries(plugin.extraKeys).forEach(([key, run]) => {
|
|
45
59
|
bindings.push({
|
|
@@ -47,7 +61,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
47
61
|
run: () => {
|
|
48
62
|
run();
|
|
49
63
|
return true;
|
|
50
|
-
}
|
|
64
|
+
},
|
|
51
65
|
});
|
|
52
66
|
});
|
|
53
67
|
}
|
|
@@ -65,7 +79,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
65
79
|
run: () => {
|
|
66
80
|
actions.runCode(true);
|
|
67
81
|
return true;
|
|
68
|
-
}
|
|
82
|
+
},
|
|
69
83
|
},
|
|
70
84
|
{
|
|
71
85
|
key: "Ctrl-Enter",
|
|
@@ -73,7 +87,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
73
87
|
run: () => {
|
|
74
88
|
actions.runCode(false);
|
|
75
89
|
return true;
|
|
76
|
-
}
|
|
90
|
+
},
|
|
77
91
|
},
|
|
78
92
|
{
|
|
79
93
|
key: "Ctrl-Shift-d",
|
|
@@ -81,7 +95,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
81
95
|
run: () => {
|
|
82
96
|
app.notebookGlobalShortcuts.deleteActive();
|
|
83
97
|
return true;
|
|
84
|
-
}
|
|
98
|
+
},
|
|
85
99
|
},
|
|
86
100
|
{
|
|
87
101
|
key: "Ctrl-Shift-m",
|
|
@@ -89,7 +103,7 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
89
103
|
run: () => {
|
|
90
104
|
app.notebookGlobalShortcuts.addMdBelow();
|
|
91
105
|
return true;
|
|
92
|
-
}
|
|
106
|
+
},
|
|
93
107
|
},
|
|
94
108
|
{
|
|
95
109
|
key: "Ctrl-Shift-y",
|
|
@@ -97,14 +111,13 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
97
111
|
run: () => {
|
|
98
112
|
app.notebookGlobalShortcuts.addCodeBelow();
|
|
99
113
|
return true;
|
|
100
|
-
}
|
|
114
|
+
},
|
|
101
115
|
},
|
|
102
116
|
indentWithTab,
|
|
103
117
|
...buildPluginKeymap(),
|
|
104
118
|
...closeBracketsKeymap,
|
|
105
119
|
...defaultKeymap,
|
|
106
120
|
...historyKeymap,
|
|
107
|
-
|
|
108
121
|
]);
|
|
109
122
|
|
|
110
123
|
const extraExtensions = Array.isArray(app.codeMirrorConfig)
|
|
@@ -114,39 +127,38 @@ export function createCodeEditor(app, cellData, actions) {
|
|
|
114
127
|
const state = EditorState.create({
|
|
115
128
|
doc: cellData.code,
|
|
116
129
|
extensions: [
|
|
117
|
-
lineNumbers(),
|
|
130
|
+
// lineNumbers(),
|
|
118
131
|
highlightActiveLine(),
|
|
132
|
+
// EditorView.theme({
|
|
133
|
+
// "&": {
|
|
134
|
+
// fontFamily: '"Fira Code", SFMono-Regular, Consolas, monospace',
|
|
135
|
+
// fontSize: "13px",
|
|
136
|
+
// lineHeight: "17px",
|
|
137
|
+
// },
|
|
138
|
+
// ".cm-scroller, .cm-content, .cm-line, .cm-gutterElement": {
|
|
139
|
+
// lineHeight: "17px",
|
|
140
|
+
// },
|
|
141
|
+
// }),
|
|
119
142
|
|
|
120
143
|
history(),
|
|
121
144
|
bracketMatching(),
|
|
122
145
|
closeBrackets(),
|
|
123
|
-
|
|
124
146
|
syntaxHighlighting(defaultHighlightStyle),
|
|
125
|
-
|
|
126
147
|
shortcutKeymap,
|
|
127
|
-
|
|
128
148
|
EditorView.lineWrapping,
|
|
129
|
-
|
|
130
149
|
indentUnit.of(" "),
|
|
131
150
|
EditorState.tabSize.of(2),
|
|
132
|
-
|
|
133
151
|
languageCompartment.of(
|
|
134
|
-
|
|
135
|
-
),
|
|
152
|
+
languageFor(cellData.type, cellData.runtime, app.runtimePlugins),
|
|
153
|
+
),
|
|
136
154
|
|
|
137
|
-
themeCompartment.of(
|
|
138
|
-
themeFor(cellData.runtime, app.runtimePlugins)
|
|
139
|
-
),
|
|
155
|
+
themeCompartment.of(themeFor(cellData.runtime, app.runtimePlugins)),
|
|
140
156
|
|
|
141
|
-
readOnlyCompartment.of(
|
|
142
|
-
EditorState.readOnly.of(cellData.readonly)
|
|
143
|
-
),
|
|
157
|
+
readOnlyCompartment.of(EditorState.readOnly.of(cellData.readonly)),
|
|
144
158
|
|
|
145
|
-
editableCompartment.of(
|
|
146
|
-
EditorView.editable.of(!cellData.readonly)
|
|
147
|
-
),
|
|
159
|
+
editableCompartment.of(EditorView.editable.of(!cellData.readonly)),
|
|
148
160
|
|
|
149
|
-
EditorView.updateListener.of(update => {
|
|
161
|
+
EditorView.updateListener.of((update) => {
|
|
150
162
|
if (update.docChanged) {
|
|
151
163
|
cellData.code = update.state.doc.toString();
|
|
152
164
|
}
|
|
@@ -155,24 +167,23 @@ themeCompartment.of(
|
|
|
155
167
|
EditorView.domEventHandlers({
|
|
156
168
|
focus: () => {
|
|
157
169
|
actions.setActive();
|
|
158
|
-
}
|
|
170
|
+
},
|
|
159
171
|
}),
|
|
160
172
|
|
|
161
|
-
...extraExtensions
|
|
162
|
-
]
|
|
173
|
+
...extraExtensions,
|
|
174
|
+
],
|
|
163
175
|
});
|
|
164
176
|
|
|
165
177
|
view = new EditorView({
|
|
166
178
|
state,
|
|
167
|
-
parent: editorDom.element
|
|
179
|
+
parent: editorDom.element,
|
|
168
180
|
});
|
|
169
181
|
|
|
170
182
|
const lineHeight = view.defaultLineHeight || 19;
|
|
171
183
|
|
|
172
|
-
view.dom.style.minHeight =
|
|
173
|
-
`${Math.ceil(app.minLines * lineHeight + 8)}px`;
|
|
184
|
+
view.dom.style.minHeight = `${Math.ceil(app.minLines * lineHeight + 8)}px`;
|
|
174
185
|
|
|
175
|
-
app.codeMirrorPlugins.forEach(plugin => {
|
|
186
|
+
app.codeMirrorPlugins.forEach((plugin) => {
|
|
176
187
|
if (typeof plugin === "function") {
|
|
177
188
|
plugin(view);
|
|
178
189
|
}
|
|
@@ -182,10 +193,7 @@ themeCompartment.of(
|
|
|
182
193
|
return {
|
|
183
194
|
dom: editorDom.element,
|
|
184
195
|
|
|
185
|
-
getValue: () =>
|
|
186
|
-
view
|
|
187
|
-
? view.state.doc.toString()
|
|
188
|
-
: cellData.code,
|
|
196
|
+
getValue: () => (view ? view.state.doc.toString() : cellData.code),
|
|
189
197
|
|
|
190
198
|
sync: (isActive, isMarkdownView) => {
|
|
191
199
|
if (!isMarkdownView) {
|
|
@@ -195,21 +203,25 @@ themeCompartment.of(
|
|
|
195
203
|
view.dispatch({
|
|
196
204
|
effects: [
|
|
197
205
|
languageCompartment.reconfigure(
|
|
198
|
-
languageFor(
|
|
206
|
+
languageFor(
|
|
207
|
+
cellData.type,
|
|
208
|
+
cellData.runtime,
|
|
209
|
+
app.runtimePlugins,
|
|
210
|
+
),
|
|
199
211
|
),
|
|
200
212
|
|
|
201
213
|
themeCompartment.reconfigure(
|
|
202
|
-
themeFor(cellData.runtime, app.runtimePlugins)
|
|
214
|
+
themeFor(cellData.runtime, app.runtimePlugins),
|
|
203
215
|
),
|
|
204
216
|
|
|
205
217
|
readOnlyCompartment.reconfigure(
|
|
206
|
-
EditorState.readOnly.of(cellData.readonly)
|
|
218
|
+
EditorState.readOnly.of(cellData.readonly),
|
|
207
219
|
),
|
|
208
220
|
|
|
209
221
|
editableCompartment.reconfigure(
|
|
210
|
-
EditorView.editable.of(!cellData.readonly)
|
|
211
|
-
)
|
|
212
|
-
]
|
|
222
|
+
EditorView.editable.of(!cellData.readonly),
|
|
223
|
+
),
|
|
224
|
+
],
|
|
213
225
|
});
|
|
214
226
|
|
|
215
227
|
const currentValue = view.state.doc.toString();
|
|
@@ -219,8 +231,8 @@ themeCompartment.of(
|
|
|
219
231
|
changes: {
|
|
220
232
|
from: 0,
|
|
221
233
|
to: currentValue.length,
|
|
222
|
-
insert: cellData.code
|
|
223
|
-
}
|
|
234
|
+
insert: cellData.code,
|
|
235
|
+
},
|
|
224
236
|
});
|
|
225
237
|
}
|
|
226
238
|
}
|
|
@@ -232,6 +244,6 @@ themeCompartment.of(
|
|
|
232
244
|
view.destroy();
|
|
233
245
|
view = null;
|
|
234
246
|
}
|
|
235
|
-
}
|
|
247
|
+
},
|
|
236
248
|
};
|
|
237
|
-
}
|
|
249
|
+
}
|
|
@@ -46,16 +46,16 @@ export function CellItem({ cellData, app, store }) {
|
|
|
46
46
|
runtimePlugins: app.runtimePlugins
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const root = div({ class: "cell" },
|
|
49
|
+
const inputRow = div({ class: "cell-input-row" }, inPrompt, bodySlot);
|
|
50
|
+
const outputRow = div({ class: "cell-output-row" }, outPrompt, div({ class: "output-wrapper" }, outputRef));
|
|
51
|
+
const root = div({ class: "cell" }, inputRow, controlsEl, outputRow);
|
|
52
52
|
root.onClick(() => app.setActiveCell(cellData.id));
|
|
53
53
|
|
|
54
54
|
cellData._dom = root.element;
|
|
55
55
|
cellData._inPrompt = inPrompt.element;
|
|
56
56
|
cellData._outPrompt = outPrompt.element;
|
|
57
57
|
cellData._bodySlot = bodySlot.element;
|
|
58
|
-
cellData.
|
|
58
|
+
cellData._outputRow = outputRow.element;
|
|
59
59
|
cellData._setIn = setIn;
|
|
60
60
|
|
|
61
61
|
app._refreshCell(cellData);
|
package/src/index.css
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
border-left: 4px solid transparent;
|
|
33
33
|
border-radius: 6px;
|
|
34
34
|
padding: 8px;
|
|
35
|
-
gap:
|
|
35
|
+
gap: 2px;
|
|
36
36
|
background: #ffffff;
|
|
37
37
|
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
38
38
|
position: relative;
|
|
@@ -43,17 +43,15 @@
|
|
|
43
43
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
.ziko-notebook .cell-input-
|
|
47
|
-
display:
|
|
48
|
-
grid-template-columns: 56px 1fr auto;
|
|
46
|
+
.ziko-notebook .cell-input-row {
|
|
47
|
+
display: flex;
|
|
49
48
|
align-items: flex-start;
|
|
50
49
|
gap: 8px;
|
|
51
50
|
width: 100%;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
.ziko-notebook .cell-output-
|
|
55
|
-
display:
|
|
56
|
-
grid-template-columns: 56px 1fr;
|
|
53
|
+
.ziko-notebook .cell-output-row {
|
|
54
|
+
display: flex;
|
|
57
55
|
align-items: flex-start;
|
|
58
56
|
gap: 8px;
|
|
59
57
|
width: 100%;
|
|
@@ -81,7 +79,9 @@
|
|
|
81
79
|
border-radius: 4px;
|
|
82
80
|
background: var(--bg-editor);
|
|
83
81
|
overflow: hidden;
|
|
84
|
-
|
|
82
|
+
flex: 1 1 0;
|
|
83
|
+
min-width: 0;
|
|
84
|
+
width: auto;
|
|
85
85
|
transition: border-color 0.15s ease;
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -111,13 +111,10 @@
|
|
|
111
111
|
/* align-items: center; */
|
|
112
112
|
align-items: baseline;
|
|
113
113
|
justify-content: flex-end;
|
|
114
|
-
|
|
115
|
-
gap: 4px;
|
|
116
|
-
flex-shrink: 0;
|
|
114
|
+
gap: 2px;
|
|
117
115
|
flex-wrap: wrap;
|
|
118
|
-
|
|
119
|
-
padding
|
|
120
|
-
margin-bottom: 2px;
|
|
116
|
+
margin: 0;
|
|
117
|
+
padding: 0;
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
.ziko-notebook .cm-line{
|
|
@@ -127,7 +124,9 @@
|
|
|
127
124
|
/* --- OUTPUT --- */
|
|
128
125
|
|
|
129
126
|
.ziko-notebook .output-wrapper {
|
|
130
|
-
|
|
127
|
+
flex: 1 1 0;
|
|
128
|
+
min-width: 0;
|
|
129
|
+
width: auto;
|
|
131
130
|
padding: 4px 0;
|
|
132
131
|
}
|
|
133
132
|
|
|
@@ -151,17 +150,23 @@
|
|
|
151
150
|
align-items: baseline;
|
|
152
151
|
}
|
|
153
152
|
|
|
154
|
-
.ziko-notebook .cell-input-grid {
|
|
155
|
-
grid-template-columns: 42px 1fr;
|
|
156
|
-
grid-template-rows: auto auto;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.ziko-notebook .cell-output-grid {
|
|
160
|
-
grid-template-columns: 42px 1fr;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
153
|
.ziko-notebook .prompt {
|
|
164
154
|
font-size: 10px;
|
|
165
155
|
padding-top: 6px;
|
|
166
156
|
}
|
|
167
|
-
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
/* TEMP */
|
|
161
|
+
|
|
162
|
+
.ziko-notebook .cm-editor{
|
|
163
|
+
margin: 1px;
|
|
164
|
+
outline: none;
|
|
165
|
+
}
|
|
166
|
+
.ziko-notebook .cm-scroller{
|
|
167
|
+
margin: 1px;
|
|
168
|
+
outline: none;
|
|
169
|
+
}
|
|
170
|
+
.ziko-notebook .cm-line{
|
|
171
|
+
margin: 1px;
|
|
172
|
+
}
|
package/src/notebook.js
CHANGED
|
@@ -224,7 +224,7 @@ export class UINotebook extends UIElement {
|
|
|
224
224
|
_inPrompt: null,
|
|
225
225
|
_outPrompt: null,
|
|
226
226
|
_bodySlot: null,
|
|
227
|
-
|
|
227
|
+
_outputRow: null,
|
|
228
228
|
_outputRef: null,
|
|
229
229
|
};
|
|
230
230
|
});
|
|
@@ -484,8 +484,8 @@ export class UINotebook extends UIElement {
|
|
|
484
484
|
const showOutput =
|
|
485
485
|
cellData.type === "code" && cellData.hasDomOutput;
|
|
486
486
|
|
|
487
|
-
cellData.
|
|
488
|
-
showOutput ? "
|
|
487
|
+
cellData._outputRow.style.display =
|
|
488
|
+
showOutput ? "flex" : "none";
|
|
489
489
|
|
|
490
490
|
cellData._outPrompt.textContent = `Out ${countText}:`;
|
|
491
491
|
}
|
|
@@ -609,7 +609,7 @@ addCell(type = "code", initialCode = null, afterId = null, readonly = false) {
|
|
|
609
609
|
_inPrompt: null,
|
|
610
610
|
_outPrompt: null,
|
|
611
611
|
_bodySlot: null,
|
|
612
|
-
|
|
612
|
+
_outputRow: null,
|
|
613
613
|
_outputRef: null,
|
|
614
614
|
};
|
|
615
615
|
|