@keshavsoft/monaco-json-studio 0.0.0-stage → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,171 @@
1
+ {
2
+ "tagName": "header",
3
+ "attributes": {
4
+ "class": "studio-header"
5
+ },
6
+ "children": [
7
+ {
8
+ "tagName": "div",
9
+ "attributes": {
10
+ "class": "header-left"
11
+ },
12
+ "children": [
13
+ {
14
+ "tagName": "a",
15
+ "attributes": {
16
+ "href": "../../index.html",
17
+ "class": "brand-link",
18
+ "title": "Back to Docs"
19
+ },
20
+ "children": [
21
+ {
22
+ "tagName": "i",
23
+ "attributes": {
24
+ "class": "bi bi-boxes brand-icon"
25
+ }
26
+ },
27
+ {
28
+ "tagName": "span",
29
+ "textContent": "JSON-Driven Monaco Assembler"
30
+ },
31
+ {
32
+ "tagName": "span",
33
+ "attributes": {
34
+ "class": "version-pill"
35
+ },
36
+ "textContent": "v1"
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ "tagName": "div",
42
+ "attributes": {
43
+ "class": "header-divider"
44
+ }
45
+ },
46
+ {
47
+ "tagName": "div",
48
+ "attributes": {
49
+ "class": "layout-switcher"
50
+ },
51
+ "children": [
52
+ {
53
+ "tagName": "span",
54
+ "attributes": {
55
+ "class": "layout-switcher-label"
56
+ },
57
+ "textContent": "Panes:"
58
+ },
59
+ {
60
+ "tagName": "button",
61
+ "attributes": {
62
+ "type": "button",
63
+ "class": "btn-layout-mode",
64
+ "data-panes": "1",
65
+ "title": "Single Pane (100%)"
66
+ },
67
+ "textContent": "1"
68
+ },
69
+ {
70
+ "tagName": "button",
71
+ "attributes": {
72
+ "type": "button",
73
+ "class": "btn-layout-mode active",
74
+ "data-panes": "2",
75
+ "title": "Double Pane (50/50)"
76
+ },
77
+ "textContent": "2"
78
+ },
79
+ {
80
+ "tagName": "button",
81
+ "attributes": {
82
+ "type": "button",
83
+ "class": "btn-layout-mode",
84
+ "data-panes": "3",
85
+ "title": "Triple Pane (33/33/33)"
86
+ },
87
+ "textContent": "3"
88
+ }
89
+ ]
90
+ }
91
+ ]
92
+ },
93
+ {
94
+ "tagName": "div",
95
+ "attributes": {
96
+ "class": "header-right"
97
+ },
98
+ "children": [
99
+ {
100
+ "tagName": "button",
101
+ "attributes": {
102
+ "id": "btnExportProject",
103
+ "type": "button",
104
+ "class": "btn-export",
105
+ "title": "Export Physical Static HTML & Project Files for Clients"
106
+ },
107
+ "children": [
108
+ {
109
+ "tagName": "i",
110
+ "attributes": {
111
+ "class": "bi bi-download"
112
+ }
113
+ },
114
+ {
115
+ "tagName": "span",
116
+ "textContent": "Export Physical Project"
117
+ }
118
+ ]
119
+ },
120
+ {
121
+ "tagName": "span",
122
+ "attributes": {
123
+ "id": "statusPill",
124
+ "class": "status-pill success hidden"
125
+ },
126
+ "children": [
127
+ {
128
+ "tagName": "i",
129
+ "attributes": {
130
+ "class": "bi bi-check2"
131
+ }
132
+ },
133
+ {
134
+ "tagName": "span",
135
+ "attributes": {
136
+ "id": "statusText"
137
+ },
138
+ "textContent": "Assembled ✓"
139
+ }
140
+ ]
141
+ },
142
+ {
143
+ "tagName": "div",
144
+ "attributes": {
145
+ "class": "header-divider"
146
+ }
147
+ },
148
+ {
149
+ "tagName": "a",
150
+ "attributes": {
151
+ "href": "../../index.html",
152
+ "class": "docs-link",
153
+ "title": "Documentation Hub"
154
+ },
155
+ "children": [
156
+ {
157
+ "tagName": "i",
158
+ "attributes": {
159
+ "class": "bi bi-arrow-left"
160
+ }
161
+ },
162
+ {
163
+ "tagName": "span",
164
+ "textContent": "Docs"
165
+ }
166
+ ]
167
+ }
168
+ ]
169
+ }
170
+ ]
171
+ }
@@ -0,0 +1,99 @@
1
+ {
2
+ "tagName": "section",
3
+ "attributes": {
4
+ "class": "studio-pane",
5
+ "id": "{{paneId}}"
6
+ },
7
+ "children": [
8
+ {
9
+ "tagName": "div",
10
+ "attributes": {
11
+ "class": "pane-header"
12
+ },
13
+ "children": [
14
+ {
15
+ "tagName": "div",
16
+ "attributes": {
17
+ "class": "pane-header-left"
18
+ },
19
+ "children": [
20
+ {
21
+ "tagName": "span",
22
+ "attributes": {
23
+ "class": "pane-badge"
24
+ },
25
+ "textContent": "{{badgeText}}"
26
+ },
27
+ {
28
+ "tagName": "button",
29
+ "attributes": {
30
+ "id": "{{fileBtnId}}",
31
+ "type": "button",
32
+ "class": "btn-pane-file",
33
+ "title": "Open JSON file for {{badgeText}}"
34
+ },
35
+ "children": [
36
+ {
37
+ "tagName": "i",
38
+ "attributes": {
39
+ "class": "bi bi-folder2-open"
40
+ }
41
+ },
42
+ {
43
+ "tagName": "span",
44
+ "textContent": "Select File"
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ "tagName": "input",
50
+ "attributes": {
51
+ "type": "file",
52
+ "id": "{{fileInputId}}",
53
+ "style": "display: none;",
54
+ "accept": ".json,.js,.txt,application/json"
55
+ }
56
+ }
57
+ ]
58
+ },
59
+ {
60
+ "tagName": "div",
61
+ "attributes": {
62
+ "class": "pane-header-right"
63
+ },
64
+ "children": [
65
+ {
66
+ "tagName": "span",
67
+ "attributes": {
68
+ "class": "pane-file-pill"
69
+ },
70
+ "children": [
71
+ {
72
+ "tagName": "i",
73
+ "attributes": {
74
+ "class": "bi bi-filetype-json"
75
+ }
76
+ },
77
+ {
78
+ "tagName": "span",
79
+ "attributes": {
80
+ "id": "{{fileNameId}}",
81
+ "class": "pane-file-name"
82
+ },
83
+ "textContent": "{{defaultFileName}}"
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ }
89
+ ]
90
+ },
91
+ {
92
+ "tagName": "div",
93
+ "attributes": {
94
+ "id": "{{editorId}}",
95
+ "class": "editor-pane-body"
96
+ }
97
+ }
98
+ ]
99
+ }
@@ -0,0 +1,111 @@
1
+ import { $, state, pretty, loadInitialData, setStatus } from './state.js';
2
+
3
+ async function initMonaco() {
4
+ return new Promise((resolve, reject) => {
5
+ if (window.monaco) {
6
+ return resolve(window.monaco);
7
+ }
8
+ require.config({
9
+ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs' }
10
+ });
11
+ require(['vs/editor/editor.main'], () => resolve(window.monaco), reject);
12
+ });
13
+ }
14
+
15
+ function wirePane({ editor, fileBtnId, fileInputId, fileNameId, index }) {
16
+ const fileBtn = $(fileBtnId);
17
+ const fileInput = $(fileInputId);
18
+ const fileNameEl = $(fileNameId);
19
+
20
+ if (!fileBtn || !fileInput) return;
21
+
22
+ fileBtn.addEventListener('click', () => {
23
+ fileInput.value = '';
24
+ fileInput.click();
25
+ });
26
+
27
+ fileInput.addEventListener('change', (e) => {
28
+ const file = e.target.files?.[0];
29
+ if (!file) return;
30
+
31
+ const reader = new FileReader();
32
+ reader.onload = (ev) => {
33
+ const text = ev.target.result;
34
+ const formatted = pretty(text);
35
+ editor.setValue(formatted);
36
+
37
+ if (fileNameEl) fileNameEl.textContent = file.name;
38
+ state.fileNames[index] = file.name;
39
+ state.contents[index] = formatted;
40
+
41
+ setStatus(`Loaded: ${file.name}`);
42
+ };
43
+ reader.readAsText(file);
44
+ });
45
+ }
46
+
47
+ async function start() {
48
+ try {
49
+ const monaco = await initMonaco();
50
+
51
+ const editorConfig = {
52
+ language: 'json',
53
+ theme: 'vs-dark',
54
+ automaticLayout: true,
55
+ tabSize: 2,
56
+ fontSize: 13,
57
+ lineNumbers: 'on',
58
+ minimap: { enabled: false },
59
+ scrollBeyondLastLine: false,
60
+ cursorBlinking: 'smooth',
61
+ renderLineHighlight: 'all',
62
+ padding: { top: 10 }
63
+ };
64
+
65
+ for (let i = 0; i < state.paneCount; i++) {
66
+ const num = i + 1;
67
+ const container = $(`editor${num}`);
68
+ if (!container) continue;
69
+
70
+ const initialText = await loadInitialData(state.fileNames[i]);
71
+ state.contents[i] = initialText;
72
+
73
+ const ed = monaco.editor.create(container, {
74
+ ...editorConfig,
75
+ value: initialText
76
+ });
77
+ state.editors[i] = ed;
78
+
79
+ wirePane({
80
+ editor: ed,
81
+ fileBtnId: `openFileBtn${num}`,
82
+ fileInputId: `fileInput${num}`,
83
+ fileNameId: `fileName${num}`,
84
+ index: i
85
+ });
86
+
87
+ ed.onDidChangeModelContent(() => {
88
+ state.contents[i] = ed.getValue();
89
+ });
90
+
91
+ const updateCursor = () => {
92
+ const pos = ed.getPosition();
93
+ const el = $('cursorPos');
94
+ if (el && pos) el.textContent = `Editor ${num} | Ln ${pos.lineNumber}, Col ${pos.column}`;
95
+ };
96
+
97
+ ed.onDidFocusEditorText(updateCursor);
98
+ ed.onDidChangeCursorPosition(updateCursor);
99
+ }
100
+
101
+ setStatus('Ready ✓');
102
+ } catch (err) {
103
+ console.error('Failed to initialize Monaco studio:', err);
104
+ }
105
+ }
106
+
107
+ if (document.readyState === 'loading') {
108
+ document.addEventListener('DOMContentLoaded', start);
109
+ } else {
110
+ start();
111
+ }
@@ -0,0 +1,45 @@
1
+ export const $ = (id) => document.getElementById(id);
2
+
3
+ export const state = {
4
+ paneCount: 2,
5
+ editors: [],
6
+ fileNames: ['instructions.json', 'data.json'],
7
+ contents: []
8
+ };
9
+
10
+ export const pretty = (v) => {
11
+ if (typeof v === 'string') {
12
+ try {
13
+ return JSON.stringify(JSON.parse(v), null, 2);
14
+ } catch {
15
+ return v;
16
+ }
17
+ }
18
+ return JSON.stringify(v, null, 2);
19
+ };
20
+
21
+ export async function loadInitialData(filename) {
22
+ try {
23
+ const res = await fetch(`./data/${filename}`);
24
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
25
+ const data = await res.json();
26
+ return pretty(data);
27
+ } catch (err) {
28
+ console.warn('Fallback loading', filename, err);
29
+ return pretty({ "status": "ready", "file": filename });
30
+ }
31
+ }
32
+
33
+ export function setStatus(text) {
34
+ const pill = $('statusPill');
35
+ const textEl = $('statusText');
36
+ if (!pill || !textEl) return;
37
+
38
+ textEl.textContent = text;
39
+ pill.classList.remove('hidden');
40
+
41
+ clearTimeout(setStatus._timer);
42
+ setStatus._timer = setTimeout(() => {
43
+ pill.classList.add('hidden');
44
+ }, 3000);
45
+ }
package/bin/index.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import path from 'path';
3
+ import { generateStudio } from '../src/index.js';
4
+
5
+ const args = process.argv.slice(2);
6
+
7
+ function printHelp() {
8
+ console.log(`
9
+ ========================================================================
10
+ 🚀 @keshavsoft/monaco-json-studio (v2)
11
+ Zero-dependency Physical Static Monaco Studio Generator
12
+ ========================================================================
13
+
14
+ Usage:
15
+ npx @keshavsoft / monaco - json - studio < panes > [targetDir][options]
16
+
17
+ Arguments:
18
+ <panes> Required. Number of Monaco editor panes (1, 2, or 3):
19
+ 1 → Single Full-Width Monaco Studio (100% width)
20
+ 2 → Dual Split Monaco Studio (50/50 split)
21
+ 3 → Triple Split Monaco Studio (33/33/33 split)
22
+
23
+ [targetDir] Optional. Destination directory path:
24
+ - Pass a folder name (e.g., ./my-studio)
25
+ - Pass '.' to scaffold directly into current folder
26
+ (Default: ./monaco-studio)
27
+
28
+ Options:
29
+ --title=<title> Custom branding title for studio header
30
+ -h, --help Display this guide
31
+
32
+ Examples:
33
+ npx @keshavsoft/monaco-json-studio 1 ./single-viewer
34
+ npx @keshavsoft/monaco-json-studio 2 ./dual-studio --title="API Data Studio"
35
+ npx @keshavsoft/monaco-json-studio 3 .
36
+ ========================================================================
37
+ `);
38
+ }
39
+
40
+ // 1. If no arguments provided or help requested, show guide
41
+ if (args.length === 0 || args.includes('-h') || args.includes('--help')) {
42
+ printHelp();
43
+ process.exit(0);
44
+ }
45
+
46
+ // 2. Parse arguments
47
+ let panes = null;
48
+ let targetDir = './monaco-studio';
49
+ let title = 'Monaco Studio';
50
+
51
+ for (let i = 0; i < args.length; i++) {
52
+ const arg = args[i];
53
+ if (arg.startsWith('--panes=')) {
54
+ panes = parseInt(arg.split('=')[1], 10);
55
+ } else if (arg.startsWith('--target=')) {
56
+ targetDir = arg.split('=')[1];
57
+ } else if (arg.startsWith('--title=')) {
58
+ title = arg.split('=')[1];
59
+ } else if (!arg.startsWith('-')) {
60
+ if (panes === null && !isNaN(parseInt(arg, 10))) {
61
+ panes = parseInt(arg, 10);
62
+ } else if (targetDir === './monaco-studio') {
63
+ targetDir = arg;
64
+ }
65
+ }
66
+ }
67
+
68
+ // 3. Validate pane count (strictly 1, 2, or 3)
69
+ if (panes === null || isNaN(panes) || panes < 1 || panes > 3) {
70
+ console.error(`\n❌ Error: Invalid pane count "${panes}". Must be 1, 2, or 3.`);
71
+ printHelp();
72
+ process.exit(1);
73
+ }
74
+
75
+ const resolvedTarget = path.resolve(process.cwd(), targetDir);
76
+
77
+ console.log(`\n======================================================`);
78
+ console.log(` 🚀 @keshavsoft/monaco-json-studio (v2)`);
79
+ console.log(` Mode: ${panes} Pane${panes > 1 ? 's' : ''} (100% Static HTML)`);
80
+ console.log(` Target: ${resolvedTarget}`);
81
+ console.log(`======================================================\n`);
82
+
83
+ try {
84
+ const result = generateStudio({
85
+ inPanes: panes,
86
+ inTargetDir: resolvedTarget,
87
+ inTitle: title
88
+ });
89
+
90
+ console.log(`✓ Generated 100% STATIC index.html with ${panes} panes baked in`);
91
+ console.log(`✓ Copied modular CSS (base.css, header.css, workspace.css, footer.css)`);
92
+ console.log(`✓ Copied ${panes} sample data files`);
93
+ console.log(`✓ Generated static JS controller (zero runtime assemble/fetch dependencies)`);
94
+
95
+ console.log(`\n🎉 Success! Scaffolded physical studio at:`);
96
+ console.log(` ${result.targetDir}\n`);
97
+ } catch (err) {
98
+ console.error(`❌ Error generating studio:`, err.message);
99
+ process.exit(1);
100
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
- {
2
- "name": "@keshavsoft/monaco-json-studio",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
1
+ {
2
+ "name": "@keshavsoft/monaco-json-studio",
3
+ "version": "1.2.1",
4
+ "description": "Zero-dependency physical and static Monaco JSON Studio scaffold generator and specification assembler.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/keshavsoft/monaco-json-studio.git"
11
+ },
12
+ "homepage": "https://keshavsoft.github.io/monaco-json-studio/",
13
+ "type": "module",
14
+ "main": "src/index.js",
15
+ "module": "./src/index.js",
16
+ "bin": {
17
+ "monaco-json-studio": "./bin/index.js",
18
+ "create-monaco-studio": "./bin/index.js"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "import": "./src/index.js",
23
+ "default": "./src/index.js"
24
+ },
25
+ "./v1": "./src/v1/index.js",
26
+ "./v2": "./src/v2/index.js",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "src",
31
+ "bin",
32
+ "assets",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "test": "node bin/index.js 2 ./test-output"
38
+ },
39
+ "keywords": [
40
+ "monaco",
41
+ "monaco-editor",
42
+ "json-visualizer",
43
+ "static-generator",
44
+ "scaffold",
45
+ "json-studio",
46
+ "declarative-ui",
47
+ "keshavsoft"
48
+ ],
49
+ "author": "KeshavSoft",
50
+ "license": "MIT"
6
51
  }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './v2/index.js';
2
+ export { default } from './v2/index.js';
@@ -0,0 +1,87 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ const assetsDir = path.resolve(__dirname, '..', '..', '..', 'assets');
8
+
9
+ function interpolateSpec({ inSpec, inVars }) {
10
+ const localSpec = inSpec;
11
+ const localVars = inVars;
12
+
13
+ if (typeof localSpec === 'string') {
14
+ let result = localSpec;
15
+ for (const [key, val] of Object.entries(localVars)) {
16
+ result = result.replaceAll(`{{${key}}}`, String(val));
17
+ }
18
+ return result;
19
+ }
20
+ if (Array.isArray(localSpec)) {
21
+ return localSpec.map((item) => interpolateSpec({ inSpec: item, inVars: localVars }));
22
+ }
23
+ if (localSpec !== null && typeof localSpec === 'object') {
24
+ const out = {};
25
+ for (const [k, v] of Object.entries(localSpec)) {
26
+ out[k] = interpolateSpec({ inSpec: v, inVars: localVars });
27
+ }
28
+ return out;
29
+ }
30
+ return localSpec;
31
+ }
32
+
33
+ /**
34
+ * Assembles atomic component specifications into a unified Studio specification tree.
35
+ * Follows strict inArgs convention.
36
+ *
37
+ * @param {Object} inArgs
38
+ * @param {number} [inArgs.inPanes=2] - Number of panes (1, 2, or 3)
39
+ * @param {Array<string>} [inArgs.inFiles] - Optional custom file names for each pane
40
+ * @returns {Object} Complete assembled specification tree
41
+ */
42
+ const assembleSpec = ({ inPanes = 2, inFiles } = {}) => {
43
+ const localPanes = Math.max(1, Math.min(3, parseInt(inPanes, 10) || 2));
44
+ const defaultFiles = ['instructions.json', 'data.json', 'columns.json'];
45
+ const localFiles = inFiles || defaultFiles.slice(0, localPanes);
46
+
47
+ const specsDir = path.join(assetsDir, 'specs');
48
+ const headerSpec = JSON.parse(fs.readFileSync(path.join(specsDir, 'header.spec.json'), 'utf-8'));
49
+ const paneTemplate = JSON.parse(fs.readFileSync(path.join(specsDir, 'pane.spec.json'), 'utf-8'));
50
+ const footerSpec = JSON.parse(fs.readFileSync(path.join(specsDir, 'footer.spec.json'), 'utf-8'));
51
+
52
+ const assembledPanes = [];
53
+ for (let i = 0; i < localPanes; i++) {
54
+ const vars = {
55
+ paneId: `pane${i + 1}`,
56
+ badgeText: `Editor ${i + 1}`,
57
+ fileBtnId: `openFileBtn${i + 1}`,
58
+ fileInputId: `fileInput${i + 1}`,
59
+ fileNameId: `fileName${i + 1}`,
60
+ defaultFileName: localFiles[i] || `file${i + 1}.json`,
61
+ editorId: `editor${i + 1}`
62
+ };
63
+ assembledPanes.push(interpolateSpec({ inSpec: paneTemplate, inVars: vars }));
64
+ }
65
+
66
+ return {
67
+ tagName: 'div',
68
+ attributes: {
69
+ class: 'studio-app'
70
+ },
71
+ children: [
72
+ headerSpec,
73
+ {
74
+ tagName: 'main',
75
+ attributes: {
76
+ class: 'studio-workspace',
77
+ 'data-panes': String(localPanes)
78
+ },
79
+ children: assembledPanes
80
+ },
81
+ footerSpec
82
+ ]
83
+ };
84
+ };
85
+
86
+ export { assembleSpec };
87
+ export default assembleSpec;