notations 1.0.2 → 1.0.4

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.
Files changed (68) hide show
  1. package/dist/notations.umd.js +3933 -12155
  2. package/dist/notations.umd.min.js +2 -3
  3. package/dist/notations.umd.min.js.map +1 -1
  4. package/lib/cjs/parser.js +1 -1
  5. package/lib/cjs/parser.js.map +1 -1
  6. package/lib/cjs/web/components/DockViewPlayground.d.ts +51 -0
  7. package/lib/cjs/web/components/DockViewPlayground.js +364 -0
  8. package/lib/cjs/web/components/DockViewPlayground.js.map +1 -0
  9. package/lib/cjs/web/components/NotationBlock.d.ts +35 -0
  10. package/lib/cjs/web/components/NotationBlock.js +219 -0
  11. package/lib/cjs/web/components/NotationBlock.js.map +1 -0
  12. package/lib/cjs/web/components/NotebookCell.d.ts +41 -0
  13. package/lib/cjs/web/components/NotebookCell.js +269 -0
  14. package/lib/cjs/web/components/NotebookCell.js.map +1 -0
  15. package/lib/cjs/web/components/NotebookView.d.ts +37 -0
  16. package/lib/cjs/web/components/NotebookView.js +379 -0
  17. package/lib/cjs/web/components/NotebookView.js.map +1 -0
  18. package/lib/cjs/web/components/SideBySideEditor.d.ts +47 -0
  19. package/lib/cjs/web/components/SideBySideEditor.js +171 -0
  20. package/lib/cjs/web/components/SideBySideEditor.js.map +1 -0
  21. package/lib/cjs/web/dockview.d.ts +2 -0
  22. package/lib/cjs/web/dockview.js +11 -0
  23. package/lib/cjs/web/dockview.js.map +1 -0
  24. package/lib/cjs/web/index.d.ts +8 -0
  25. package/lib/cjs/web/index.js +34 -0
  26. package/lib/cjs/web/index.js.map +1 -0
  27. package/lib/cjs/web/types/notebook.d.ts +64 -0
  28. package/lib/cjs/web/types/notebook.js +56 -0
  29. package/lib/cjs/web/types/notebook.js.map +1 -0
  30. package/lib/cjs/web/utils/cellFactory.d.ts +16 -0
  31. package/lib/cjs/web/utils/cellFactory.js +137 -0
  32. package/lib/cjs/web/utils/cellFactory.js.map +1 -0
  33. package/lib/cjs/web/utils/sourceSerializer.d.ts +19 -0
  34. package/lib/cjs/web/utils/sourceSerializer.js +162 -0
  35. package/lib/cjs/web/utils/sourceSerializer.js.map +1 -0
  36. package/lib/esm/parser.js +1 -1
  37. package/lib/esm/parser.js.map +1 -1
  38. package/lib/esm/web/components/DockViewPlayground.d.ts +51 -0
  39. package/lib/esm/web/components/DockViewPlayground.js +358 -0
  40. package/lib/esm/web/components/DockViewPlayground.js.map +1 -0
  41. package/lib/esm/web/components/NotationBlock.d.ts +35 -0
  42. package/lib/esm/web/components/NotationBlock.js +216 -0
  43. package/lib/esm/web/components/NotationBlock.js.map +1 -0
  44. package/lib/esm/web/components/NotebookCell.d.ts +41 -0
  45. package/lib/esm/web/components/NotebookCell.js +266 -0
  46. package/lib/esm/web/components/NotebookCell.js.map +1 -0
  47. package/lib/esm/web/components/NotebookView.d.ts +37 -0
  48. package/lib/esm/web/components/NotebookView.js +376 -0
  49. package/lib/esm/web/components/NotebookView.js.map +1 -0
  50. package/lib/esm/web/components/SideBySideEditor.d.ts +47 -0
  51. package/lib/esm/web/components/SideBySideEditor.js +168 -0
  52. package/lib/esm/web/components/SideBySideEditor.js.map +1 -0
  53. package/lib/esm/web/dockview.d.ts +2 -0
  54. package/lib/esm/web/dockview.js +3 -0
  55. package/lib/esm/web/dockview.js.map +1 -0
  56. package/lib/esm/web/index.d.ts +8 -0
  57. package/lib/esm/web/index.js +9 -0
  58. package/lib/esm/web/index.js.map +1 -0
  59. package/lib/esm/web/types/notebook.d.ts +64 -0
  60. package/lib/esm/web/types/notebook.js +50 -0
  61. package/lib/esm/web/types/notebook.js.map +1 -0
  62. package/lib/esm/web/utils/cellFactory.d.ts +16 -0
  63. package/lib/esm/web/utils/cellFactory.js +127 -0
  64. package/lib/esm/web/utils/cellFactory.js.map +1 -0
  65. package/lib/esm/web/utils/sourceSerializer.d.ts +19 -0
  66. package/lib/esm/web/utils/sourceSerializer.js +154 -0
  67. package/lib/esm/web/utils/sourceSerializer.js.map +1 -0
  68. package/package.json +41 -1
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const block_1 = require("../../block");
4
+ const notebook_1 = require("../types/notebook");
5
+ class NotebookCell {
6
+ constructor(cell, config = {}) {
7
+ this.childCells = [];
8
+ this.editTextarea = null;
9
+ this.cell = cell;
10
+ this.config = config;
11
+ this.element = document.createElement("div");
12
+ this.element.className = this.buildRootClassName();
13
+ this.element.dataset.cellId = cell.state.id;
14
+ this.element.dataset.depth = String(cell.state.depth);
15
+ this.render();
16
+ }
17
+ buildRootClassName() {
18
+ var _a;
19
+ const classes = [
20
+ "notebook-cell",
21
+ `notebook-cell-${this.cell.state.type}`,
22
+ `notebook-cell-depth-${this.cell.state.depth}`,
23
+ ];
24
+ if (this.cell.state.isEditing) {
25
+ classes.push("notebook-cell-editing");
26
+ }
27
+ if (this.cell.state.hasError) {
28
+ classes.push("notebook-cell-error");
29
+ }
30
+ if (!this.cell.state.isExpanded && this.cell.children.length > 0) {
31
+ classes.push("notebook-cell-collapsed");
32
+ }
33
+ if ((_a = this.config.cssClasses) === null || _a === void 0 ? void 0 : _a.cell) {
34
+ classes.push(this.config.cssClasses.cell);
35
+ }
36
+ return classes.join(" ");
37
+ }
38
+ render() {
39
+ this.element.innerHTML = "";
40
+ this.renderHeader();
41
+ if (this.cell.state.hasError && this.cell.state.errorMessage) {
42
+ this.renderError();
43
+ }
44
+ this.renderContent();
45
+ if (this.cell.state.isExpanded && this.cell.children.length > 0) {
46
+ this.renderChildren();
47
+ }
48
+ }
49
+ renderHeader() {
50
+ var _a;
51
+ const header = document.createElement("div");
52
+ header.className = "notebook-cell-header";
53
+ if ((_a = this.config.cssClasses) === null || _a === void 0 ? void 0 : _a.cellHeader) {
54
+ header.className += " " + this.config.cssClasses.cellHeader;
55
+ }
56
+ const leftSide = document.createElement("div");
57
+ leftSide.className = "notebook-cell-header-left";
58
+ const badge = this.createBadge();
59
+ leftSide.appendChild(badge);
60
+ if ((0, block_1.isBlock)(this.cell.blockItem)) {
61
+ const block = this.cell.blockItem;
62
+ if (block.name) {
63
+ const nameSpan = document.createElement("span");
64
+ nameSpan.className = "notebook-cell-name";
65
+ nameSpan.textContent = block.name;
66
+ leftSide.appendChild(nameSpan);
67
+ }
68
+ }
69
+ if (this.cell.children.length > 0) {
70
+ const expandBtn = document.createElement("button");
71
+ expandBtn.className = "notebook-btn notebook-expand-btn";
72
+ expandBtn.innerHTML = this.cell.state.isExpanded
73
+ ? '<svg width="12" height="12" viewBox="0 0 12 12"><path d="M2 4l4 4 4-4" stroke="currentColor" fill="none"/></svg>'
74
+ : '<svg width="12" height="12" viewBox="0 0 12 12"><path d="M4 2l4 4-4 4" stroke="currentColor" fill="none"/></svg>';
75
+ expandBtn.title = this.cell.state.isExpanded ? "Collapse" : "Expand";
76
+ expandBtn.addEventListener("click", () => this.handleToggleExpanded());
77
+ leftSide.appendChild(expandBtn);
78
+ const countSpan = document.createElement("span");
79
+ countSpan.className = "notebook-cell-child-count";
80
+ countSpan.textContent = `(${this.cell.children.length})`;
81
+ leftSide.appendChild(countSpan);
82
+ }
83
+ header.appendChild(leftSide);
84
+ const controls = this.createControls();
85
+ header.appendChild(controls);
86
+ this.element.appendChild(header);
87
+ }
88
+ createBadge() {
89
+ const badgeInfo = (0, notebook_1.getCellTypeBadge)(this.cell.state.type);
90
+ const badge = document.createElement("span");
91
+ badge.className = `notebook-cell-badge ${badgeInfo.cssClass}`;
92
+ badge.textContent = badgeInfo.label;
93
+ return badge;
94
+ }
95
+ createControls() {
96
+ var _a;
97
+ const controls = document.createElement("div");
98
+ controls.className = "notebook-cell-controls";
99
+ if ((_a = this.config.cssClasses) === null || _a === void 0 ? void 0 : _a.cellControls) {
100
+ controls.className += " " + this.config.cssClasses.cellControls;
101
+ }
102
+ if (this.config.showMoveButtons && !this.cell.state.isEditing) {
103
+ const moveUpBtn = document.createElement("button");
104
+ moveUpBtn.className = "notebook-btn notebook-move-btn";
105
+ moveUpBtn.innerHTML = "↑";
106
+ moveUpBtn.title = "Move up";
107
+ moveUpBtn.addEventListener("click", () => { var _a, _b; return (_b = (_a = this.config).onMoveUp) === null || _b === void 0 ? void 0 : _b.call(_a, this.cell.state.id); });
108
+ controls.appendChild(moveUpBtn);
109
+ const moveDownBtn = document.createElement("button");
110
+ moveDownBtn.className = "notebook-btn notebook-move-btn";
111
+ moveDownBtn.innerHTML = "↓";
112
+ moveDownBtn.title = "Move down";
113
+ moveDownBtn.addEventListener("click", () => { var _a, _b; return (_b = (_a = this.config).onMoveDown) === null || _b === void 0 ? void 0 : _b.call(_a, this.cell.state.id); });
114
+ controls.appendChild(moveDownBtn);
115
+ }
116
+ const editBtn = document.createElement("button");
117
+ editBtn.className = "notebook-btn notebook-edit-btn";
118
+ if (this.cell.state.isEditing) {
119
+ editBtn.textContent = "Cancel";
120
+ editBtn.addEventListener("click", () => this.handleCancelEdit());
121
+ }
122
+ else {
123
+ editBtn.textContent = "Edit";
124
+ editBtn.addEventListener("click", () => this.handleStartEdit());
125
+ }
126
+ controls.appendChild(editBtn);
127
+ if (this.config.showDeleteButton && !this.cell.state.isEditing) {
128
+ const deleteBtn = document.createElement("button");
129
+ deleteBtn.className = "notebook-btn notebook-delete-btn";
130
+ deleteBtn.textContent = "Delete";
131
+ deleteBtn.addEventListener("click", () => this.handleDelete());
132
+ controls.appendChild(deleteBtn);
133
+ }
134
+ return controls;
135
+ }
136
+ renderError() {
137
+ var _a;
138
+ const errorDiv = document.createElement("div");
139
+ errorDiv.className = "notebook-cell-error-message";
140
+ if ((_a = this.config.cssClasses) === null || _a === void 0 ? void 0 : _a.errorMessage) {
141
+ errorDiv.className += " " + this.config.cssClasses.errorMessage;
142
+ }
143
+ errorDiv.textContent = this.cell.state.errorMessage || "Error";
144
+ this.element.appendChild(errorDiv);
145
+ }
146
+ renderContent() {
147
+ var _a;
148
+ const content = document.createElement("div");
149
+ content.className = "notebook-cell-content";
150
+ if ((_a = this.config.cssClasses) === null || _a === void 0 ? void 0 : _a.cellContent) {
151
+ content.className += " " + this.config.cssClasses.cellContent;
152
+ }
153
+ if (this.cell.state.isEditing) {
154
+ this.renderEditMode(content);
155
+ }
156
+ else {
157
+ this.renderPreviewMode(content);
158
+ }
159
+ this.element.appendChild(content);
160
+ }
161
+ renderPreviewMode(container) {
162
+ if ((0, block_1.isRawBlock)(this.cell.blockItem)) {
163
+ const rawBlock = this.cell.blockItem;
164
+ const contentDiv = document.createElement("div");
165
+ contentDiv.className = "notebook-rawblock-content";
166
+ if (this.config.markdownParser && rawBlock.contentType === "md") {
167
+ contentDiv.innerHTML = this.config.markdownParser(rawBlock.content);
168
+ }
169
+ else {
170
+ contentDiv.textContent = rawBlock.content;
171
+ }
172
+ container.appendChild(contentDiv);
173
+ }
174
+ else {
175
+ const preview = document.createElement("div");
176
+ preview.className = "notebook-notation-preview";
177
+ if ((0, block_1.isLine)(this.cell.blockItem)) {
178
+ preview.textContent = "[Line content]";
179
+ }
180
+ else if ((0, block_1.isBlock)(this.cell.blockItem)) {
181
+ const block = this.cell.blockItem;
182
+ const itemCount = block.blockItems.length;
183
+ preview.textContent = `[${block.blockType}: ${itemCount} item${itemCount !== 1 ? "s" : ""}]`;
184
+ }
185
+ container.appendChild(preview);
186
+ }
187
+ }
188
+ renderEditMode(container) {
189
+ var _a;
190
+ this.editTextarea = document.createElement("textarea");
191
+ this.editTextarea.className = "notebook-edit-textarea";
192
+ if ((_a = this.config.cssClasses) === null || _a === void 0 ? void 0 : _a.editTextarea) {
193
+ this.editTextarea.className += " " + this.config.cssClasses.editTextarea;
194
+ }
195
+ this.editTextarea.value = this.cell.source;
196
+ this.editTextarea.rows = Math.max(3, this.cell.source.split("\n").length + 1);
197
+ container.appendChild(this.editTextarea);
198
+ const actions = document.createElement("div");
199
+ actions.className = "notebook-edit-actions";
200
+ const applyBtn = document.createElement("button");
201
+ applyBtn.className = "notebook-btn notebook-apply-btn";
202
+ applyBtn.textContent = "Apply";
203
+ applyBtn.addEventListener("click", () => this.handleApplyEdit());
204
+ actions.appendChild(applyBtn);
205
+ const cancelBtn = document.createElement("button");
206
+ cancelBtn.className = "notebook-btn notebook-cancel-btn";
207
+ cancelBtn.textContent = "Cancel";
208
+ cancelBtn.addEventListener("click", () => this.handleCancelEdit());
209
+ actions.appendChild(cancelBtn);
210
+ container.appendChild(actions);
211
+ setTimeout(() => { var _a; return (_a = this.editTextarea) === null || _a === void 0 ? void 0 : _a.focus(); }, 0);
212
+ }
213
+ renderChildren() {
214
+ const childrenContainer = document.createElement("div");
215
+ childrenContainer.className = "notebook-cell-children";
216
+ this.element.appendChild(childrenContainer);
217
+ this.childCells = [];
218
+ for (const childModel of this.cell.children) {
219
+ if (this.config.createChildCell) {
220
+ const childCell = this.config.createChildCell(childModel, childrenContainer);
221
+ this.childCells.push(childCell);
222
+ }
223
+ else {
224
+ const childCell = new NotebookCell(childModel, this.config);
225
+ childrenContainer.appendChild(childCell.element);
226
+ this.childCells.push(childCell);
227
+ }
228
+ }
229
+ }
230
+ handleStartEdit() {
231
+ var _a, _b;
232
+ (_b = (_a = this.config).onStartEdit) === null || _b === void 0 ? void 0 : _b.call(_a, this.cell.state.id);
233
+ }
234
+ handleApplyEdit() {
235
+ var _a, _b, _c;
236
+ const newSource = ((_a = this.editTextarea) === null || _a === void 0 ? void 0 : _a.value) || "";
237
+ (_c = (_b = this.config).onApplyEdit) === null || _c === void 0 ? void 0 : _c.call(_b, this.cell.state.id, newSource);
238
+ }
239
+ handleCancelEdit() {
240
+ var _a, _b;
241
+ (_b = (_a = this.config).onCancelEdit) === null || _b === void 0 ? void 0 : _b.call(_a, this.cell.state.id);
242
+ }
243
+ handleDelete() {
244
+ var _a, _b;
245
+ (_b = (_a = this.config).onDelete) === null || _b === void 0 ? void 0 : _b.call(_a, this.cell.state.id);
246
+ }
247
+ handleToggleExpanded() {
248
+ var _a, _b;
249
+ (_b = (_a = this.config).onToggleExpanded) === null || _b === void 0 ? void 0 : _b.call(_a, this.cell.state.id);
250
+ }
251
+ getEditSource() {
252
+ var _a;
253
+ return ((_a = this.editTextarea) === null || _a === void 0 ? void 0 : _a.value) || this.cell.source;
254
+ }
255
+ update(newCell) {
256
+ this.cell = newCell;
257
+ this.element.className = this.buildRootClassName();
258
+ this.render();
259
+ }
260
+ destroy() {
261
+ for (const child of this.childCells) {
262
+ child.destroy();
263
+ }
264
+ this.childCells = [];
265
+ this.element.remove();
266
+ }
267
+ }
268
+ exports.default = NotebookCell;
269
+ //# sourceMappingURL=NotebookCell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotebookCell.js","sourceRoot":"","sources":["../../../../src/web/components/NotebookCell.ts"],"names":[],"mappings":";;AAOA,uCAA2E;AAC3E,gDAAmG;AAqDnG,MAAqB,YAAY;IAsB/B,YAAY,IAAe,EAAE,SAA6B,EAAE;QAXpD,eAAU,GAAmB,EAAE,CAAC;QAGhC,iBAAY,GAA+B,IAAI,CAAC;QAStD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAGrB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACnD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAGtD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAKO,kBAAkB;;QACxB,MAAM,OAAO,GAAG;YACd,eAAe;YACf,iBAAiB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACvC,uBAAuB,IAAI,CAAC,IAAI,CAAC,KAAK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I,CAAC,MAAM,EAAC,YAAY,mDAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAEO,YAAY;;QAClB,MAAA,MAAA,IAAI,CAAC,MAAM,EAAC,QAAQ,mDAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAEO,oBAAoB;;QAC1B,MAAA,MAAA,IAAI,CAAC,MAAM,EAAC,gBAAgB,mDAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IASD,aAAa;;QACX,OAAO,CAAA,MAAA,IAAI,CAAC,YAAY,0CAAE,KAAK,KAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACtD,CAAC;IAKD,MAAM,CAAC,OAAkB;QAEtB,IAA4B,CAAC,IAAI,GAAG,OAAO,CAAC;QAG7C,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAGnD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAKD,OAAO;QAEL,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpC,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QAGrB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;CACF;AAvYD,+BAuYC","sourcesContent":["/**\n * NotebookCell - Individual cell component for notebook-style editing.\n *\n * A cell represents a single BlockItem (Block, Line, or RawBlock) with\n * preview/edit modes, controls, and optional nested children.\n */\n\nimport { isBlock, isLine, isRawBlock, Block, RawBlock } from \"../../block\";\nimport { CellModel, CellTypeBadge, getCellTypeBadge, NotebookCssClasses } from \"../types/notebook\";\n\n/**\n * Configuration for NotebookCell.\n */\nexport interface NotebookCellConfig {\n /** CSS classes for cell elements */\n cssClasses?: NotebookCssClasses;\n\n /** Markdown parser for RawBlock content */\n markdownParser?: (content: string) => string;\n\n /** Whether to show delete button */\n showDeleteButton?: boolean;\n\n /** Whether to show move buttons (for reordering) */\n showMoveButtons?: boolean;\n\n /** Callback when edit is started */\n onStartEdit?: (cellId: string) => void;\n\n /** Callback when edit is applied */\n onApplyEdit?: (cellId: string, newSource: string) => void;\n\n /** Callback when edit is cancelled */\n onCancelEdit?: (cellId: string) => void;\n\n /** Callback when cell is deleted */\n onDelete?: (cellId: string) => void;\n\n /** Callback when cell is moved up */\n onMoveUp?: (cellId: string) => void;\n\n /** Callback when cell is moved down */\n onMoveDown?: (cellId: string) => void;\n\n /** Callback when expand/collapse is toggled */\n onToggleExpanded?: (cellId: string) => void;\n\n /** Factory to create child cells (for nesting) */\n createChildCell?: (cell: CellModel, parent: HTMLElement) => NotebookCell;\n}\n\n/**\n * NotebookCell renders a single cell with header, content, and controls.\n *\n * Features:\n * - Type badge showing block type\n * - Preview mode showing rendered content\n * - Edit mode with textarea\n * - Controls for edit, delete, move\n * - Support for nested children\n */\nexport default class NotebookCell {\n /** The root element for this cell */\n readonly element: HTMLDivElement;\n\n /** The cell model */\n readonly cell: CellModel;\n\n /** Configuration */\n readonly config: NotebookCellConfig;\n\n /** Child cell instances (for nested blocks) */\n private childCells: NotebookCell[] = [];\n\n /** Reference to textarea in edit mode */\n private editTextarea: HTMLTextAreaElement | null = null;\n\n /**\n * Creates a new NotebookCell.\n *\n * @param cell The cell model to render\n * @param config Configuration options\n */\n constructor(cell: CellModel, config: NotebookCellConfig = {}) {\n this.cell = cell;\n this.config = config;\n\n // Create root element\n this.element = document.createElement(\"div\");\n this.element.className = this.buildRootClassName();\n this.element.dataset.cellId = cell.state.id;\n this.element.dataset.depth = String(cell.state.depth);\n\n // Render content\n this.render();\n }\n\n /**\n * Builds the root element class name.\n */\n private buildRootClassName(): string {\n const classes = [\n \"notebook-cell\",\n `notebook-cell-${this.cell.state.type}`,\n `notebook-cell-depth-${this.cell.state.depth}`,\n ];\n\n if (this.cell.state.isEditing) {\n classes.push(\"notebook-cell-editing\");\n }\n if (this.cell.state.hasError) {\n classes.push(\"notebook-cell-error\");\n }\n if (!this.cell.state.isExpanded && this.cell.children.length > 0) {\n classes.push(\"notebook-cell-collapsed\");\n }\n\n if (this.config.cssClasses?.cell) {\n classes.push(this.config.cssClasses.cell);\n }\n\n return classes.join(\" \");\n }\n\n /**\n * Renders the cell content.\n */\n private render(): void {\n this.element.innerHTML = \"\";\n\n // Render header\n this.renderHeader();\n\n // Render error message if any\n if (this.cell.state.hasError && this.cell.state.errorMessage) {\n this.renderError();\n }\n\n // Render content (preview or edit mode)\n this.renderContent();\n\n // Render children if expanded\n if (this.cell.state.isExpanded && this.cell.children.length > 0) {\n this.renderChildren();\n }\n }\n\n /**\n * Renders the cell header.\n */\n private renderHeader(): void {\n const header = document.createElement(\"div\");\n header.className = \"notebook-cell-header\";\n if (this.config.cssClasses?.cellHeader) {\n header.className += \" \" + this.config.cssClasses.cellHeader;\n }\n\n // Left side: badge, name, expand/collapse\n const leftSide = document.createElement(\"div\");\n leftSide.className = \"notebook-cell-header-left\";\n\n // Type badge\n const badge = this.createBadge();\n leftSide.appendChild(badge);\n\n // Name (if block has one)\n if (isBlock(this.cell.blockItem)) {\n const block = this.cell.blockItem as Block;\n if (block.name) {\n const nameSpan = document.createElement(\"span\");\n nameSpan.className = \"notebook-cell-name\";\n nameSpan.textContent = block.name;\n leftSide.appendChild(nameSpan);\n }\n }\n\n // Expand/collapse toggle for cells with children\n if (this.cell.children.length > 0) {\n const expandBtn = document.createElement(\"button\");\n expandBtn.className = \"notebook-btn notebook-expand-btn\";\n expandBtn.innerHTML = this.cell.state.isExpanded\n ? '<svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\"><path d=\"M2 4l4 4 4-4\" stroke=\"currentColor\" fill=\"none\"/></svg>'\n : '<svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\"><path d=\"M4 2l4 4-4 4\" stroke=\"currentColor\" fill=\"none\"/></svg>';\n expandBtn.title = this.cell.state.isExpanded ? \"Collapse\" : \"Expand\";\n expandBtn.addEventListener(\"click\", () => this.handleToggleExpanded());\n leftSide.appendChild(expandBtn);\n\n // Child count\n const countSpan = document.createElement(\"span\");\n countSpan.className = \"notebook-cell-child-count\";\n countSpan.textContent = `(${this.cell.children.length})`;\n leftSide.appendChild(countSpan);\n }\n\n header.appendChild(leftSide);\n\n // Right side: controls\n const controls = this.createControls();\n header.appendChild(controls);\n\n this.element.appendChild(header);\n }\n\n /**\n * Creates the type badge element.\n */\n private createBadge(): HTMLSpanElement {\n const badgeInfo = getCellTypeBadge(this.cell.state.type);\n const badge = document.createElement(\"span\");\n badge.className = `notebook-cell-badge ${badgeInfo.cssClass}`;\n badge.textContent = badgeInfo.label;\n return badge;\n }\n\n /**\n * Creates the controls container.\n */\n private createControls(): HTMLDivElement {\n const controls = document.createElement(\"div\");\n controls.className = \"notebook-cell-controls\";\n if (this.config.cssClasses?.cellControls) {\n controls.className += \" \" + this.config.cssClasses.cellControls;\n }\n\n // Move buttons (if enabled and not in edit mode)\n if (this.config.showMoveButtons && !this.cell.state.isEditing) {\n const moveUpBtn = document.createElement(\"button\");\n moveUpBtn.className = \"notebook-btn notebook-move-btn\";\n moveUpBtn.innerHTML = \"↑\";\n moveUpBtn.title = \"Move up\";\n moveUpBtn.addEventListener(\"click\", () => this.config.onMoveUp?.(this.cell.state.id));\n controls.appendChild(moveUpBtn);\n\n const moveDownBtn = document.createElement(\"button\");\n moveDownBtn.className = \"notebook-btn notebook-move-btn\";\n moveDownBtn.innerHTML = \"↓\";\n moveDownBtn.title = \"Move down\";\n moveDownBtn.addEventListener(\"click\", () => this.config.onMoveDown?.(this.cell.state.id));\n controls.appendChild(moveDownBtn);\n }\n\n // Edit/Cancel button\n const editBtn = document.createElement(\"button\");\n editBtn.className = \"notebook-btn notebook-edit-btn\";\n if (this.cell.state.isEditing) {\n editBtn.textContent = \"Cancel\";\n editBtn.addEventListener(\"click\", () => this.handleCancelEdit());\n } else {\n editBtn.textContent = \"Edit\";\n editBtn.addEventListener(\"click\", () => this.handleStartEdit());\n }\n controls.appendChild(editBtn);\n\n // Delete button (if enabled and not in edit mode)\n if (this.config.showDeleteButton && !this.cell.state.isEditing) {\n const deleteBtn = document.createElement(\"button\");\n deleteBtn.className = \"notebook-btn notebook-delete-btn\";\n deleteBtn.textContent = \"Delete\";\n deleteBtn.addEventListener(\"click\", () => this.handleDelete());\n controls.appendChild(deleteBtn);\n }\n\n return controls;\n }\n\n /**\n * Renders the error message.\n */\n private renderError(): void {\n const errorDiv = document.createElement(\"div\");\n errorDiv.className = \"notebook-cell-error-message\";\n if (this.config.cssClasses?.errorMessage) {\n errorDiv.className += \" \" + this.config.cssClasses.errorMessage;\n }\n errorDiv.textContent = this.cell.state.errorMessage || \"Error\";\n this.element.appendChild(errorDiv);\n }\n\n /**\n * Renders the cell content (preview or edit mode).\n */\n private renderContent(): void {\n const content = document.createElement(\"div\");\n content.className = \"notebook-cell-content\";\n if (this.config.cssClasses?.cellContent) {\n content.className += \" \" + this.config.cssClasses.cellContent;\n }\n\n if (this.cell.state.isEditing) {\n this.renderEditMode(content);\n } else {\n this.renderPreviewMode(content);\n }\n\n this.element.appendChild(content);\n }\n\n /**\n * Renders preview mode content.\n */\n private renderPreviewMode(container: HTMLElement): void {\n if (isRawBlock(this.cell.blockItem)) {\n const rawBlock = this.cell.blockItem as RawBlock;\n const contentDiv = document.createElement(\"div\");\n contentDiv.className = \"notebook-rawblock-content\";\n\n if (this.config.markdownParser && rawBlock.contentType === \"md\") {\n contentDiv.innerHTML = this.config.markdownParser(rawBlock.content);\n } else {\n contentDiv.textContent = rawBlock.content;\n }\n container.appendChild(contentDiv);\n } else {\n // For Line and Block, show a placeholder or summary\n const preview = document.createElement(\"div\");\n preview.className = \"notebook-notation-preview\";\n\n if (isLine(this.cell.blockItem)) {\n preview.textContent = \"[Line content]\";\n } else if (isBlock(this.cell.blockItem)) {\n const block = this.cell.blockItem as Block;\n const itemCount = block.blockItems.length;\n preview.textContent = `[${block.blockType}: ${itemCount} item${itemCount !== 1 ? \"s\" : \"\"}]`;\n }\n container.appendChild(preview);\n }\n }\n\n /**\n * Renders edit mode content.\n */\n private renderEditMode(container: HTMLElement): void {\n // Textarea for editing\n this.editTextarea = document.createElement(\"textarea\");\n this.editTextarea.className = \"notebook-edit-textarea\";\n if (this.config.cssClasses?.editTextarea) {\n this.editTextarea.className += \" \" + this.config.cssClasses.editTextarea;\n }\n this.editTextarea.value = this.cell.source;\n this.editTextarea.rows = Math.max(3, this.cell.source.split(\"\\n\").length + 1);\n container.appendChild(this.editTextarea);\n\n // Action buttons\n const actions = document.createElement(\"div\");\n actions.className = \"notebook-edit-actions\";\n\n const applyBtn = document.createElement(\"button\");\n applyBtn.className = \"notebook-btn notebook-apply-btn\";\n applyBtn.textContent = \"Apply\";\n applyBtn.addEventListener(\"click\", () => this.handleApplyEdit());\n actions.appendChild(applyBtn);\n\n const cancelBtn = document.createElement(\"button\");\n cancelBtn.className = \"notebook-btn notebook-cancel-btn\";\n cancelBtn.textContent = \"Cancel\";\n cancelBtn.addEventListener(\"click\", () => this.handleCancelEdit());\n actions.appendChild(cancelBtn);\n\n container.appendChild(actions);\n\n // Focus textarea\n setTimeout(() => this.editTextarea?.focus(), 0);\n }\n\n /**\n * Renders child cells.\n */\n private renderChildren(): void {\n const childrenContainer = document.createElement(\"div\");\n childrenContainer.className = \"notebook-cell-children\";\n this.element.appendChild(childrenContainer);\n\n // Clear existing child cells\n this.childCells = [];\n\n // Create child cells\n for (const childModel of this.cell.children) {\n if (this.config.createChildCell) {\n const childCell = this.config.createChildCell(childModel, childrenContainer);\n this.childCells.push(childCell);\n } else {\n // Default: create NotebookCell with same config\n const childCell = new NotebookCell(childModel, this.config);\n childrenContainer.appendChild(childCell.element);\n this.childCells.push(childCell);\n }\n }\n }\n\n // ============================================\n // Event handlers\n // ============================================\n\n private handleStartEdit(): void {\n this.config.onStartEdit?.(this.cell.state.id);\n }\n\n private handleApplyEdit(): void {\n const newSource = this.editTextarea?.value || \"\";\n this.config.onApplyEdit?.(this.cell.state.id, newSource);\n }\n\n private handleCancelEdit(): void {\n this.config.onCancelEdit?.(this.cell.state.id);\n }\n\n private handleDelete(): void {\n this.config.onDelete?.(this.cell.state.id);\n }\n\n private handleToggleExpanded(): void {\n this.config.onToggleExpanded?.(this.cell.state.id);\n }\n\n // ============================================\n // Public methods\n // ============================================\n\n /**\n * Gets the current source text from the edit textarea.\n */\n getEditSource(): string {\n return this.editTextarea?.value || this.cell.source;\n }\n\n /**\n * Updates the cell with a new model and re-renders.\n */\n update(newCell: CellModel): void {\n // Update reference (cast away readonly for internal update)\n (this as { cell: CellModel }).cell = newCell;\n\n // Update class name\n this.element.className = this.buildRootClassName();\n\n // Re-render\n this.render();\n }\n\n /**\n * Destroys the cell and cleans up resources.\n */\n destroy(): void {\n // Destroy child cells\n for (const child of this.childCells) {\n child.destroy();\n }\n this.childCells = [];\n\n // Remove element\n this.element.remove();\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { GridLayoutGroup } from "../../grids";
2
+ import { Notation } from "../../notation";
3
+ import { NotebookConfig, CellModel, CellOperations } from "../types/notebook";
4
+ export default class NotebookView implements CellOperations {
5
+ readonly rootElement: HTMLDivElement;
6
+ readonly config: NotebookConfig;
7
+ readonly gridLayoutGroup: GridLayoutGroup;
8
+ private notation;
9
+ private notationSource;
10
+ private cells;
11
+ private cellElements;
12
+ private cellNotationViews;
13
+ private layoutChangeUnsubscribe;
14
+ constructor(container: HTMLElement, config?: Partial<NotebookConfig>);
15
+ loadNotation(source: string): void;
16
+ getNotation(): Notation | null;
17
+ getCells(): CellModel[];
18
+ getVisibleCells(): CellModel[];
19
+ getCell(cellId: string): CellModel | null;
20
+ private render;
21
+ private renderCell;
22
+ private renderCellHeader;
23
+ private renderCellPreviewMode;
24
+ private renderCellEditMode;
25
+ private renderAddCellButton;
26
+ private handleLayoutChange;
27
+ startEdit(cellId: string): void;
28
+ applyEdit(cellId: string, newSource: string): void;
29
+ cancelEdit(cellId: string): void;
30
+ deleteCell(cellId: string): void;
31
+ moveCell(cellId: string, targetIndex: number): void;
32
+ insertCell(index: number, source: string): CellModel;
33
+ toggleExpanded(cellId: string): void;
34
+ private replaceCellInTree;
35
+ private rerenderCell;
36
+ destroy(): void;
37
+ }