monaco-json-studio-base 0.0.0-stage → 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KeshavSoft
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/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # monaco-json-studio-base
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared base engine, region builders (`header/`, `body/`, `footer/`), and browser Monaco runtime for `monaco-json-studio-single`, `monaco-json-studio-double`, and `monaco-json-studio-triple`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install monaco-json-studio-base
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { generateStudio } from 'monaco-json-studio-base';
15
+ ```
@@ -0,0 +1,33 @@
1
+ :root {
2
+ color-scheme: dark;
3
+ --bg-page: #0f1117;
4
+ --bg-header: #181a20;
5
+ --bg-pane: #1e1e1e;
6
+ --bg-region: #14161d;
7
+ --bg-footer: #12141a;
8
+ --border-color: #2b2f3a;
9
+ --border-subtle: #232733;
10
+ --text-primary: #f3f4f6;
11
+ --text-secondary: #9ca3af;
12
+ --text-muted: #6b7280;
13
+ --accent-blue: #38bdf8;
14
+ --accent-blue-bg: rgba(56, 189, 248, 0.12);
15
+ --accent-blue-border: rgba(56, 189, 248, 0.35);
16
+ --accent-green: #34d399;
17
+ --accent-green-bg: rgba(52, 211, 153, 0.12);
18
+ --accent-green-border: rgba(52, 211, 153, 0.35);
19
+ --accent-amber: #fbbf24;
20
+ --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
21
+ --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
22
+ }
23
+
24
+ * { box-sizing: border-box; }
25
+ html, body { width: 100%; height: 100%; margin: 0; }
26
+ body {
27
+ overflow: hidden;
28
+ background: var(--bg-page);
29
+ color: var(--text-primary);
30
+ font-family: var(--font-sans);
31
+ -webkit-font-smoothing: antialiased;
32
+ }
33
+ button, input { font: inherit; }
@@ -0,0 +1,29 @@
1
+ .studio-workspace {
2
+ display: grid;
3
+ flex: 1 1 auto;
4
+ min-height: 0;
5
+ width: 100%;
6
+ gap: 1px;
7
+ overflow: hidden;
8
+ background: var(--border-color);
9
+ }
10
+ .studio-workspace[data-panes="1"] { grid-template-columns: minmax(0, 1fr); }
11
+ .studio-workspace[data-panes="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
12
+ .studio-workspace[data-panes="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
13
+
14
+ .studio-pane {
15
+ display: flex;
16
+ flex-direction: column;
17
+ min-width: 0;
18
+ min-height: 0;
19
+ overflow: hidden;
20
+ background: var(--bg-pane);
21
+ }
22
+
23
+ .pane-body {
24
+ flex: 1 1 auto;
25
+ min-width: 0;
26
+ min-height: 0;
27
+ overflow: hidden;
28
+ position: relative;
29
+ }
@@ -0,0 +1,74 @@
1
+ .pane-region { flex: 0 0 auto; }
2
+ .pane-header {
3
+ height: 36px;
4
+ display: flex;
5
+ align-items: center;
6
+ justify-content: space-between;
7
+ gap: 8px;
8
+ padding: 0 10px;
9
+ background: var(--bg-region);
10
+ border-bottom: 1px solid var(--border-color);
11
+ user-select: none;
12
+ }
13
+ .pane-header__left, .pane-header__right { display: flex; align-items: center; gap: 8px; min-width: 0; }
14
+ .pane-label {
15
+ overflow: hidden;
16
+ color: var(--accent-blue);
17
+ font-size: 11px;
18
+ font-weight: 700;
19
+ letter-spacing: .04em;
20
+ text-overflow: ellipsis;
21
+ text-transform: uppercase;
22
+ white-space: nowrap;
23
+ }
24
+ .pane-header--title { justify-content: flex-start; }
25
+ .btn-pane-file {
26
+ display: inline-flex;
27
+ align-items: center;
28
+ gap: 5px;
29
+ padding: 3px 8px;
30
+ border: 1px solid var(--border-color);
31
+ border-radius: 4px;
32
+ background: #20242f;
33
+ color: var(--text-primary);
34
+ cursor: pointer;
35
+ font-size: 11px;
36
+ font-weight: 600;
37
+ white-space: nowrap;
38
+ }
39
+ .btn-pane-file:hover { border-color: var(--accent-blue-border); background: #2a303f; }
40
+ .btn-pane-file i { color: var(--accent-blue); }
41
+ .pane-select {
42
+ max-width: 220px;
43
+ height: 26px;
44
+ padding: 2px 26px 2px 8px;
45
+ border: 1px solid var(--border-color);
46
+ border-radius: 4px;
47
+ background: #20242f;
48
+ color: var(--text-primary);
49
+ font: 11px var(--font-mono);
50
+ }
51
+ .pane-select:focus { outline: 1px solid var(--accent-blue); outline-offset: 1px; }
52
+ .pane-file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
53
+ .pane-file-pill {
54
+ max-width: 42vw;
55
+ overflow: hidden;
56
+ text-overflow: ellipsis;
57
+ background: rgba(255, 255, 255, .04);
58
+ }
59
+ .pane-file-pill i { color: var(--accent-amber); }
60
+ .pane-file-name { overflow: hidden; color: var(--text-primary); font: 11px var(--font-mono); text-overflow: ellipsis; }
61
+
62
+ .pane-body--monaco { flex: 1 1 auto; }
63
+ .pane-footer {
64
+ min-height: 24px;
65
+ display: flex;
66
+ align-items: center;
67
+ padding: 0 10px;
68
+ border-top: 1px solid var(--border-subtle);
69
+ background: var(--bg-footer);
70
+ color: var(--text-secondary);
71
+ font: 10px var(--font-mono);
72
+ }
73
+ .pane-footer--cursor { color: var(--accent-blue); }
74
+ .pane-footer--note { color: var(--text-muted); }
@@ -0,0 +1,56 @@
1
+ .studio-app {
2
+ display: flex;
3
+ flex-direction: column;
4
+ width: 100vw;
5
+ height: 100vh;
6
+ overflow: hidden;
7
+ }
8
+
9
+ .studio-header {
10
+ height: 44px;
11
+ flex: 0 0 44px;
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: space-between;
15
+ padding: 0 14px;
16
+ background: var(--bg-header);
17
+ border-bottom: 1px solid var(--border-color);
18
+ }
19
+ .header-left, .header-right, .brand-link {
20
+ display: flex;
21
+ align-items: center;
22
+ gap: 10px;
23
+ }
24
+ .brand-link { color: var(--text-primary); text-decoration: none; font-size: 13px; font-weight: 700; }
25
+ .brand-icon { color: var(--accent-blue); font-size: 17px; }
26
+ .version-pill, .pane-file-pill {
27
+ display: inline-flex;
28
+ align-items: center;
29
+ gap: 6px;
30
+ border: 1px solid var(--border-subtle);
31
+ border-radius: 5px;
32
+ padding: 3px 8px;
33
+ color: var(--text-secondary);
34
+ font-size: 11px;
35
+ white-space: nowrap;
36
+ }
37
+ .version-pill { color: var(--accent-blue); border-color: var(--accent-blue-border); background: var(--accent-blue-bg); }
38
+ .header-divider { width: 1px; height: 18px; background: var(--border-color); }
39
+ .status-pill { display: inline-flex; align-items: center; gap: 5px; color: var(--accent-green); font-size: 11px; }
40
+ .status-pill.hidden { display: none; }
41
+ .status-pill.error { color: #f87171; }
42
+
43
+ .studio-footer {
44
+ height: 24px;
45
+ flex: 0 0 24px;
46
+ display: flex;
47
+ align-items: center;
48
+ justify-content: space-between;
49
+ padding: 0 12px;
50
+ background: var(--bg-footer);
51
+ border-top: 1px solid var(--border-color);
52
+ color: var(--text-secondary);
53
+ font: 11px var(--font-mono);
54
+ }
55
+ .footer-left, .footer-right, .footer-brand { display: flex; align-items: center; gap: 10px; }
56
+ .footer-brand { color: var(--accent-blue); }
@@ -0,0 +1,45 @@
1
+ import { pretty } from '../dom.js';
2
+
3
+ const DEFAULT_OPTIONS = {
4
+ theme: 'vs-dark',
5
+ automaticLayout: true,
6
+ tabSize: 2,
7
+ fontSize: 13,
8
+ lineNumbers: 'on',
9
+ minimap: { enabled: false },
10
+ scrollBeyondLastLine: false,
11
+ cursorBlinking: 'smooth',
12
+ renderLineHighlight: 'all',
13
+ padding: { top: 10 }
14
+ };
15
+
16
+ export function loadMonaco() {
17
+ if (window.monaco) return Promise.resolve(window.monaco);
18
+ if (typeof window.require !== 'function') {
19
+ return Promise.reject(new Error('Monaco loader is unavailable.'));
20
+ }
21
+ window.require.config({
22
+ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs' }
23
+ });
24
+ return new Promise((resolve, reject) => {
25
+ window.require(['vs/editor/editor.main'], () => resolve(window.monaco), reject);
26
+ });
27
+ }
28
+
29
+ export async function loadInitialValue(fileName) {
30
+ try {
31
+ const response = await fetch(`./data/${encodeURIComponent(fileName)}`);
32
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
33
+ return pretty(await response.text());
34
+ } catch {
35
+ return pretty({ message: `Default content for ${fileName}` });
36
+ }
37
+ }
38
+
39
+ export function mountMonacoEditor(monaco, container, { language = 'json', value = '{}' }) {
40
+ return monaco.editor.create(container, {
41
+ ...DEFAULT_OPTIONS,
42
+ language,
43
+ value
44
+ });
45
+ }
@@ -0,0 +1,21 @@
1
+ export const byId = (id) => document.getElementById(id);
2
+
3
+ export function pretty(value) {
4
+ if (typeof value === 'string') {
5
+ try {
6
+ return JSON.stringify(JSON.parse(value), null, 2);
7
+ } catch {
8
+ return value;
9
+ }
10
+ }
11
+ return JSON.stringify(value, null, 2);
12
+ }
13
+
14
+ export function setStatus(message, isError = false) {
15
+ const pill = byId('statusPill');
16
+ const text = byId('statusText');
17
+ if (!pill || !text) return;
18
+ text.textContent = message;
19
+ pill.classList.remove('hidden', 'success', 'error');
20
+ pill.classList.add(isError ? 'error' : 'success');
21
+ }
@@ -0,0 +1,17 @@
1
+ import { byId } from '../dom.js';
2
+
3
+ export function updateCursor(editor, pane) {
4
+ const position = editor.getPosition();
5
+ if (!position) return;
6
+
7
+ const globalCursor = byId('cursorPos');
8
+ if (globalCursor) {
9
+ globalCursor.textContent = `${pane.label} | Ln ${position.lineNumber}, Col ${position.column}`;
10
+ }
11
+ if (pane.footerType === 'cursor') {
12
+ const paneCursor = byId(`paneCursor${pane.paneNumber}`);
13
+ if (paneCursor) {
14
+ paneCursor.textContent = `Ln ${position.lineNumber}, Col ${position.column}`;
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,58 @@
1
+ import { paneConfigs, state } from '../state.js';
2
+ import { byId, pretty, setStatus } from '../dom.js';
3
+ import { loadInitialValue } from '../body/monaco.js';
4
+
5
+ function getPaneContext(matchElement) {
6
+ const paneEl = matchElement.closest('[data-pane-key]');
7
+ const paneKey = paneEl?.dataset.paneKey;
8
+ const pane = paneConfigs.find((item) => item.key === paneKey);
9
+ const editor = pane ? state.editors[pane.paneNumber - 1] : null;
10
+ return { pane, editor };
11
+ }
12
+
13
+ export const actions = {
14
+ openFilePicker: (_event, matchElement) => {
15
+ const { pane } = getPaneContext(matchElement);
16
+ if (!pane) return;
17
+ const input = byId(`fileInput${pane.paneNumber}`);
18
+ if (!input) return;
19
+ input.value = '';
20
+ input.click();
21
+ },
22
+
23
+ loadSelectedFile: (_event, matchElement) => {
24
+ const { pane, editor } = getPaneContext(matchElement);
25
+ if (!pane || !editor) return;
26
+
27
+ const file = matchElement.files?.[0];
28
+ if (!file) return;
29
+
30
+ const fileName = byId(`fileName${pane.paneNumber}`);
31
+ const reader = new FileReader();
32
+ reader.onload = () => {
33
+ const value = pretty(String(reader.result ?? ''));
34
+ editor.setValue(value);
35
+ if (fileName) fileName.textContent = file.name;
36
+ state.contents[pane.paneNumber - 1] = value;
37
+ setStatus(`Loaded: ${file.name}`);
38
+ };
39
+ reader.readAsText(file);
40
+ },
41
+
42
+ selectPaneDataset: async (_event, matchElement) => {
43
+ const { pane, editor } = getPaneContext(matchElement);
44
+ if (!pane || !editor) return;
45
+
46
+ const option = pane.selectOptions.find((item) => item.value === matchElement.value);
47
+ if (!option) return;
48
+
49
+ const fileName = byId(`fileName${pane.paneNumber}`);
50
+ const value = await loadInitialValue(option.fileName);
51
+ editor.setValue(value);
52
+ if (fileName) fileName.textContent = option.fileName;
53
+ state.contents[pane.paneNumber - 1] = value;
54
+ setStatus(`Loaded: ${option.label}`);
55
+ }
56
+ };
57
+
58
+ export default actions;
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "event": "click",
4
+ "selector": ".btn-pane-file",
5
+ "action": "openFilePicker"
6
+ },
7
+ {
8
+ "event": "change",
9
+ "selector": ".pane-file-input",
10
+ "action": "loadSelectedFile"
11
+ },
12
+ {
13
+ "event": "change",
14
+ "selector": ".pane-select",
15
+ "action": "selectPaneDataset"
16
+ }
17
+ ]
@@ -0,0 +1,49 @@
1
+ import { bindEvents } from 'https://keshavsoft.github.io/dom-primitive-bindings/dist/v7/min.js';
2
+ import bindings from './header/bindings.json' with { type: 'json' };
3
+ import actions from './header/actions.js';
4
+ import { paneConfigs, state } from './state.js';
5
+ import { byId, setStatus } from './dom.js';
6
+ import { loadMonaco, loadInitialValue, mountMonacoEditor } from './body/monaco.js';
7
+ import { updateCursor } from './footer/cursor.js';
8
+
9
+ async function initPane(monaco, pane) {
10
+ if (pane.bodyType !== 'monaco') return;
11
+ const container = byId(`editor${pane.paneNumber}`);
12
+ if (!container) return;
13
+
14
+ const initialValue = await loadInitialValue(pane.fileName);
15
+ const editor = mountMonacoEditor(monaco, container, {
16
+ language: pane.language,
17
+ value: initialValue
18
+ });
19
+
20
+ state.editors[pane.paneNumber - 1] = editor;
21
+ state.contents[pane.paneNumber - 1] = initialValue;
22
+
23
+ const update = () => updateCursor(editor, pane);
24
+ editor.onDidFocusEditorText(update);
25
+ editor.onDidChangeCursorPosition(update);
26
+ editor.onDidChangeModelContent(() => {
27
+ state.contents[pane.paneNumber - 1] = editor.getValue();
28
+ });
29
+ }
30
+
31
+ async function start() {
32
+ let monaco;
33
+ try {
34
+ monaco = await loadMonaco();
35
+ } catch (error) {
36
+ console.error('Failed to load Monaco:', error);
37
+ setStatus('Monaco unavailable', true);
38
+ return;
39
+ }
40
+
41
+ await Promise.all(paneConfigs.map((pane) => initPane(monaco, pane)));
42
+
43
+ const app = document.querySelector('.studio-app');
44
+ bindEvents(app, bindings, actions);
45
+
46
+ setStatus('Ready ✓');
47
+ }
48
+
49
+ start();
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "monaco-json-studio-base",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Shared base editor and generator primitives for Monaco JSON Studio layouts.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/keshavsoft/monaco-json-studio-base.git"
11
+ },
12
+ "type": "module",
13
+ "main": "./src/index.js",
14
+ "exports": {
15
+ ".": "./src/index.js"
16
+ },
17
+ "files": [
18
+ "src",
19
+ "assets",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "scripts": {
24
+ "test": "node --check src/index.js && node --check src/v1/index.js"
25
+ },
26
+ "keywords": [
27
+ "monaco",
28
+ "monaco-editor",
29
+ "json-studio",
30
+ "keshavsoft"
31
+ ],
32
+ "author": "KeshavSoft",
33
+ "license": "MIT"
34
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './v1/index.js';
2
+ export { default } from './v1/index.js';
@@ -0,0 +1,25 @@
1
+ export const BODY_TYPES = ['monaco'];
2
+
3
+ export function normalizeBody(rawBody = 'monaco', paneKey, paneNumber, header) {
4
+ const body = typeof rawBody === 'string' ? { type: rawBody } : (rawBody ?? { type: 'monaco' });
5
+ const type = body.type ?? 'monaco';
6
+ if (!BODY_TYPES.includes(type)) {
7
+ throw new TypeError(`body.type must be one of: ${BODY_TYPES.join(', ')}`);
8
+ }
9
+
10
+ const selectedOption = header.selectedOption;
11
+ const fileName = body.fileName ?? selectedOption?.fileName ?? `${paneKey}.json`;
12
+ const content = body.content ?? (selectedOption ? JSON.parse(selectedOption.contentText) : {});
13
+
14
+ return {
15
+ type,
16
+ language: body.language ?? 'json',
17
+ editorId: `editor${paneNumber}`,
18
+ fileName,
19
+ contentText: JSON.stringify(content, null, 2)
20
+ };
21
+ }
22
+
23
+ export function renderPaneBody(pane) {
24
+ return `<div id="${pane.body.editorId}" class="pane-region pane-body pane-body--${pane.body.type}" data-region="body" data-type="${pane.body.type}" data-language="${pane.body.language}"></div>`;
25
+ }
@@ -0,0 +1,32 @@
1
+ export const FOOTER_TYPES = ['cursor', 'note', 'none'];
2
+
3
+ function escapeHtml(text) {
4
+ return String(text)
5
+ .replaceAll('&', '&amp;')
6
+ .replaceAll('<', '&lt;')
7
+ .replaceAll('>', '&gt;')
8
+ .replaceAll('"', '&quot;');
9
+ }
10
+
11
+ export function normalizeFooter(rawFooter = 'none', paneNumber) {
12
+ const footer = typeof rawFooter === 'string' ? { type: rawFooter } : (rawFooter ?? { type: 'none' });
13
+ const type = footer.type ?? 'none';
14
+ if (!FOOTER_TYPES.includes(type)) {
15
+ throw new TypeError(`footer.type must be one of: ${FOOTER_TYPES.join(', ')}`);
16
+ }
17
+
18
+ return {
19
+ type,
20
+ cursorId: `paneCursor${paneNumber}`,
21
+ text: type === 'note' ? (footer.text || 'Monaco JSON Studio') : ''
22
+ };
23
+ }
24
+
25
+ export function renderPaneFooter(pane) {
26
+ const { footer } = pane;
27
+ if (footer.type === 'none') return '';
28
+ if (footer.type === 'cursor') {
29
+ return `<footer id="${footer.cursorId}" class="pane-region pane-footer pane-footer--cursor" data-region="footer" data-type="cursor">Ln 1, Col 1</footer>`;
30
+ }
31
+ return `<footer class="pane-region pane-footer pane-footer--note" data-region="footer" data-type="note">${escapeHtml(footer.text)}</footer>`;
32
+ }
@@ -0,0 +1,176 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { normalizeHeader, renderHeaderControls, renderPaneHeader } from './header/index.js';
5
+ import { normalizeBody, renderPaneBody } from './body/index.js';
6
+ import { normalizeFooter, renderPaneFooter } from './footer/index.js';
7
+
8
+ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
9
+ const assetsDir = path.resolve(moduleDir, '..', '..', 'assets', 'v1');
10
+
11
+ export function resolveUniqueDir(baseOutputDir) {
12
+ const resolvedBase = path.resolve(process.cwd(), baseOutputDir);
13
+ if (!fs.existsSync(resolvedBase)) return resolvedBase;
14
+
15
+ let counter = 1;
16
+ while (fs.existsSync(`${resolvedBase}-${counter}`)) {
17
+ counter += 1;
18
+ }
19
+ return `${resolvedBase}-${counter}`;
20
+ }
21
+
22
+ function copyTree(sourceDir, targetDir) {
23
+ fs.mkdirSync(targetDir, { recursive: true });
24
+ for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) {
25
+ const srcPath = path.join(sourceDir, entry.name);
26
+ const dstPath = path.join(targetDir, entry.name);
27
+ if (entry.isDirectory()) {
28
+ copyTree(srcPath, dstPath);
29
+ } else {
30
+ fs.copyFileSync(srcPath, dstPath);
31
+ }
32
+ }
33
+ }
34
+
35
+ function normalizePanes(rawPanes) {
36
+ if (!Array.isArray(rawPanes) || rawPanes.length < 1 || rawPanes.length > 3) {
37
+ throw new TypeError('panes must be an array with 1 to 3 items.');
38
+ }
39
+
40
+ return rawPanes.map((rawPane, index) => {
41
+ const paneNumber = index + 1;
42
+ const key = rawPane.key ?? `pane${paneNumber}`;
43
+ const label = rawPane.label ?? `Pane ${paneNumber}`;
44
+ const header = normalizeHeader(rawPane.header, key, paneNumber);
45
+ const body = normalizeBody(rawPane.body, key, paneNumber, header);
46
+ const footer = normalizeFooter(rawPane.footer, paneNumber);
47
+
48
+ const dataFiles = header.type === 'select'
49
+ ? header.options.map((opt) => ({ fileName: opt.fileName, contentText: opt.contentText }))
50
+ : [{ fileName: body.fileName, contentText: body.contentText }];
51
+
52
+ return { paneNumber, key, label, header, body, footer, dataFiles };
53
+ });
54
+ }
55
+
56
+ function buildHtml({ title, badge, panes }) {
57
+ const paneCount = panes.length;
58
+ const countLabel = `${paneCount} ${paneCount === 1 ? 'Pane' : 'Panes'} Active`;
59
+
60
+ const studioBarPanes = panes.filter((pane) => pane.header.placement === 'studio' && pane.header.type !== 'none');
61
+ const studioControlsHtml = studioBarPanes.map((pane) => `
62
+ <span class="header-divider" aria-hidden="true"></span>
63
+ <div class="header-left" data-pane-key="${pane.key}">
64
+ ${renderHeaderControls(pane)}
65
+ </div>`).join('');
66
+
67
+ const panesHtml = panes.map((pane) => `
68
+ <section class="studio-pane" id="pane${pane.paneNumber}" data-pane-key="${pane.key}">
69
+ ${renderPaneHeader(pane)}
70
+ ${renderPaneBody(pane)}
71
+ ${renderPaneFooter(pane)}
72
+ </section>`).join('\n');
73
+
74
+ return `<!doctype html>
75
+ <html lang="en">
76
+ <head>
77
+ <meta charset="utf-8">
78
+ <meta name="viewport" content="width=device-width, initial-scale=1">
79
+ <title>${title}</title>
80
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
81
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.min.css">
82
+ <link rel="stylesheet" href="./css/base.css">
83
+ <link rel="stylesheet" href="./css/studio.css">
84
+ <link rel="stylesheet" href="./css/pane-layout.css">
85
+ <link rel="stylesheet" href="./css/pane-regions.css">
86
+ </head>
87
+ <body>
88
+ <div class="studio-app">
89
+ <header class="studio-header">
90
+ <div class="header-left">
91
+ <a href="#" class="brand-link" title="${title}">
92
+ <i class="bi bi-cpu-fill brand-icon" aria-hidden="true"></i>
93
+ <span>${title}</span>
94
+ <span class="version-pill">${badge}</span>
95
+ </a>${studioControlsHtml}
96
+ </div>
97
+ <div class="header-right">
98
+ <span id="statusPill" class="status-pill success">
99
+ <i class="bi bi-check2" aria-hidden="true"></i>
100
+ <span id="statusText">Ready ✓</span>
101
+ </span>
102
+ <span class="header-divider" aria-hidden="true"></span>
103
+ <span class="pane-file-pill">
104
+ <i class="bi bi-layout-split" aria-hidden="true"></i>
105
+ <span>${countLabel}</span>
106
+ </span>
107
+ </div>
108
+ </header>
109
+ <main class="studio-workspace" data-panes="${paneCount}">
110
+ ${panesHtml}
111
+ </main>
112
+ <footer class="studio-footer">
113
+ <div class="footer-left">
114
+ <span class="footer-brand">
115
+ <i class="bi bi-braces-asterisk" aria-hidden="true"></i>
116
+ <span>${title}</span>
117
+ </span>
118
+ <span aria-hidden="true">|</span>
119
+ <span id="layoutMeta">${countLabel}</span>
120
+ </div>
121
+ <div class="footer-right">
122
+ <span id="cursorPos">Focus an editor to see the cursor position</span>
123
+ </div>
124
+ </footer>
125
+ </div>
126
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/loader.min.js"></script>
127
+ <script type="module" src="./js/index.js"></script>
128
+ </body>
129
+ </html>
130
+ `;
131
+ }
132
+
133
+ export function generateStudio(rawConfig) {
134
+ const title = rawConfig.title ?? 'Monaco Studio';
135
+ const badge = rawConfig.badge ?? 'base';
136
+ const panes = normalizePanes(rawConfig.panes);
137
+ const targetDir = rawConfig.uniqueDir === false
138
+ ? path.resolve(process.cwd(), rawConfig.outputDir ?? './monaco-studio')
139
+ : resolveUniqueDir(rawConfig.outputDir ?? './monaco-studio');
140
+
141
+ const cssDir = path.join(targetDir, 'css');
142
+ const dataDir = path.join(targetDir, 'data');
143
+ const jsDir = path.join(targetDir, 'js');
144
+ [cssDir, dataDir, jsDir].forEach((dir) => fs.mkdirSync(dir, { recursive: true }));
145
+
146
+ fs.writeFileSync(path.join(targetDir, 'index.html'), buildHtml({ title, badge, panes }), 'utf8');
147
+ copyTree(path.join(assetsDir, 'css'), cssDir);
148
+ copyTree(path.join(assetsDir, 'js'), jsDir);
149
+
150
+ panes.forEach((pane) => {
151
+ pane.dataFiles.forEach((dataFile) => {
152
+ fs.writeFileSync(path.join(dataDir, dataFile.fileName), `${dataFile.contentText}\n`, 'utf8');
153
+ });
154
+ });
155
+
156
+ const paneConfigs = panes.map((pane) => ({
157
+ paneNumber: pane.paneNumber,
158
+ key: pane.key,
159
+ label: pane.label,
160
+ fileName: pane.body.fileName,
161
+ headerType: pane.header.type,
162
+ selectOptions: pane.header.options ?? [],
163
+ bodyType: pane.body.type,
164
+ language: pane.body.language,
165
+ footerType: pane.footer.type
166
+ }));
167
+
168
+ const stateModule = [
169
+ `export const paneConfigs = ${JSON.stringify(paneConfigs, null, 2)};`,
170
+ 'export const state = { editors: [], contents: [] };',
171
+ ''
172
+ ].join('\n');
173
+ fs.writeFileSync(path.join(jsDir, 'state.js'), stateModule, 'utf8');
174
+
175
+ return targetDir;
176
+ }
@@ -0,0 +1,104 @@
1
+ export const HEADER_TYPES = ['file-picker', 'title', 'select', 'none'];
2
+
3
+ function escapeHtml(text) {
4
+ return String(text)
5
+ .replaceAll('&', '&amp;')
6
+ .replaceAll('<', '&lt;')
7
+ .replaceAll('>', '&gt;')
8
+ .replaceAll('"', '&quot;');
9
+ }
10
+
11
+ export function normalizeHeader(rawHeader = 'title', paneKey, paneNumber) {
12
+ const header = typeof rawHeader === 'string' ? { type: rawHeader } : (rawHeader ?? { type: 'title' });
13
+ const type = header.type ?? 'title';
14
+ if (!HEADER_TYPES.includes(type)) {
15
+ throw new TypeError(`header.type must be one of: ${HEADER_TYPES.join(', ')}`);
16
+ }
17
+
18
+ const base = {
19
+ type,
20
+ placement: header.placement === 'studio' ? 'studio' : 'pane',
21
+ fileBtnId: `openFileBtn${paneNumber}`,
22
+ fileInputId: `fileInput${paneNumber}`,
23
+ fileNameId: `fileName${paneNumber}`,
24
+ selectId: `paneSelect${paneNumber}`
25
+ };
26
+
27
+ if (type !== 'select') return base;
28
+
29
+ const options = (header.options && header.options.length > 0 ? header.options : [
30
+ { label: 'Sample A', value: 'sampleA', content: { sample: 'A' } },
31
+ { label: 'Sample B', value: 'sampleB', content: { sample: 'B' } }
32
+ ]).map((opt) => ({
33
+ label: opt.label,
34
+ value: opt.value,
35
+ fileName: opt.fileName ?? `${paneKey}-${opt.value}.json`,
36
+ contentText: JSON.stringify(opt.content ?? {}, null, 2),
37
+ selected: false
38
+ }));
39
+
40
+ const selectedValue = header.selected ?? options[0].value;
41
+ options.forEach((opt) => {
42
+ opt.selected = opt.value === selectedValue;
43
+ });
44
+
45
+ return {
46
+ ...base,
47
+ options,
48
+ selectedOption: options.find((opt) => opt.selected) ?? options[0]
49
+ };
50
+ }
51
+
52
+ export function renderHeaderControls(pane) {
53
+ const { header, label, body } = pane;
54
+ if (header.type === 'file-picker') {
55
+ return `
56
+ <button id="${header.fileBtnId}" type="button" class="btn-pane-file" title="Choose a file for ${escapeHtml(label)}">
57
+ <i class="bi bi-folder2-open" aria-hidden="true"></i>
58
+ <span>Select File</span>
59
+ </button>
60
+ <input type="file" id="${header.fileInputId}" class="pane-file-input" accept=".json,.js,.txt,application/json">
61
+ <span class="pane-file-pill">
62
+ <i class="bi bi-filetype-json" aria-hidden="true"></i>
63
+ <span id="${header.fileNameId}" class="pane-file-name">${escapeHtml(body.fileName)}</span>
64
+ </span>`;
65
+ }
66
+
67
+ if (header.type === 'select') {
68
+ const optionsHtml = (header.options ?? []).map((opt) =>
69
+ `<option value="${escapeHtml(opt.value)}"${opt.selected ? ' selected' : ''}>${escapeHtml(opt.label)}</option>`
70
+ ).join('');
71
+ return `
72
+ <select id="${header.selectId}" class="pane-select" aria-label="${escapeHtml(label)}">${optionsHtml}</select>
73
+ <span class="pane-file-pill">
74
+ <i class="bi bi-filetype-json" aria-hidden="true"></i>
75
+ <span id="${header.fileNameId}" class="pane-file-name">${escapeHtml(body.fileName)}</span>
76
+ </span>`;
77
+ }
78
+
79
+ return '';
80
+ }
81
+
82
+ export function renderPaneHeader(pane) {
83
+ const { header, label, body } = pane;
84
+ if (header.type === 'none' || header.placement === 'studio') return '';
85
+
86
+ if (header.type === 'title') {
87
+ return `<header class="pane-region pane-header pane-header--title" data-region="header" data-type="title">
88
+ <span class="pane-label">${escapeHtml(label)}</span>
89
+ </header>`;
90
+ }
91
+
92
+ return `<header class="pane-region pane-header pane-header--${header.type}" data-region="header" data-type="${header.type}">
93
+ <div class="pane-header__left">
94
+ <span class="pane-label">${escapeHtml(label)}</span>
95
+ ${renderHeaderControls(pane).split('<span class="pane-file-pill">')[0]}
96
+ </div>
97
+ <div class="pane-header__right">
98
+ <span class="pane-file-pill">
99
+ <i class="bi bi-filetype-json" aria-hidden="true"></i>
100
+ <span id="${header.fileNameId}" class="pane-file-name">${escapeHtml(body.fileName)}</span>
101
+ </span>
102
+ </div>
103
+ </header>`;
104
+ }
@@ -0,0 +1,8 @@
1
+ import { generateStudio, resolveUniqueDir } from './generateStudio.js';
2
+
3
+ export { generateStudio, resolveUniqueDir } from './generateStudio.js';
4
+ export { HEADER_TYPES } from './header/index.js';
5
+ export { BODY_TYPES } from './body/index.js';
6
+ export { FOOTER_TYPES } from './footer/index.js';
7
+
8
+ export default { generateStudio, resolveUniqueDir };