@reladraw/studio 0.0.0-stage → 0.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.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ // src/start/preload.ts
4
+ var import_electron = require("electron");
5
+ import_electron.contextBridge.exposeInMainWorld("reladrawStudio", {
6
+ platform: process.platform,
7
+ recent: () => import_electron.ipcRenderer.invoke("studio:recent"),
8
+ open: (paths) => import_electron.ipcRenderer.invoke("studio:open", paths),
9
+ choose: (kind) => import_electron.ipcRenderer.invoke("studio:choose", kind),
10
+ playground: () => import_electron.ipcRenderer.invoke("studio:playground"),
11
+ start: () => import_electron.ipcRenderer.invoke("studio:start"),
12
+ /** Goes to another page of the same server in this tab, asking first about unsaved edits, as leaving does. */
13
+ go: (url) => import_electron.ipcRenderer.invoke("studio:go", String(url)),
14
+ /** What to update, studio or the reladraw beside it: a list of { key, title, detail, command }. */
15
+ update: () => import_electron.ipcRenderer.invoke("studio:update"),
16
+ /** Called with the new list when a check finds a newer studio while the page is open. */
17
+ onUpdate: (found) => {
18
+ import_electron.ipcRenderer.on("studio:update-found", (_event, notices) => found(notices));
19
+ },
20
+ /** True the first time any page asks to show the card for this notice. */
21
+ updateCard: (key) => import_electron.ipcRenderer.invoke("studio:update-card", String(key)),
22
+ copy: (text) => import_electron.ipcRenderer.invoke("studio:copy", String(text)),
23
+ /** The page says whether it has unsaved edits, for the dot on its tab, and which files leaving it would lose them in. */
24
+ unsaved: (mark, losing) => import_electron.ipcRenderer.send("studio:unsaved", mark === true, Array.isArray(losing) ? losing.filter((one) => typeof one === "string") : [])
25
+ });
@@ -0,0 +1,189 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'">
6
+ <title>reladraw studio</title>
7
+ <style>
8
+ :root {
9
+ --bg: #121212; --bar: #121212; --line: #2a2d35; --text: #d8dae0; --dim: #8a8f9c;
10
+ --button: #1a1c22; --button-line: #3a3e48; --accent: #7aa2f7; --chosen: #1d2230; --problem: #2a1414; --fresh: #e0b04a;
11
+ }
12
+ @media (prefers-color-scheme: light) {
13
+ :root {
14
+ --bg: #fafafa; --bar: #fafafa; --line: #dcdfe5; --text: #1d2026; --dim: #6a707c;
15
+ --button: #ffffff; --button-line: #c8ccd4; --accent: #3864d6; --chosen: #e4ebfb; --problem: #fbe6e6; --fresh: #a86a00;
16
+ }
17
+ }
18
+ * { box-sizing: border-box; }
19
+ html, body { height: 100%; }
20
+ /* The same scroll bars as the diagram window: a thin thumb on no track. */
21
+ ::-webkit-scrollbar { width: 10px; height: 10px; }
22
+ ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
23
+ ::-webkit-scrollbar-button { display: none; }
24
+ ::-webkit-scrollbar-thumb {
25
+ border: 3px solid transparent; border-radius: 5px; background-clip: padding-box;
26
+ background-color: color-mix(in srgb, var(--text) 16%, transparent);
27
+ }
28
+ :hover::-webkit-scrollbar-thumb { background-color: color-mix(in srgb, var(--text) 28%, transparent); }
29
+ ::-webkit-scrollbar-thumb:hover, ::-webkit-scrollbar-thumb:active {
30
+ border-width: 2px; background-color: color-mix(in srgb, var(--text) 42%, transparent);
31
+ }
32
+ body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, sans-serif; display: flex; flex-direction: column; }
33
+ header { display: flex; align-items: baseline; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--bar); }
34
+ header b { font-size: 16px; }
35
+ header span { color: var(--dim); font-size: 12px; }
36
+ main { flex: 1; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(220px, 1fr); gap: 40px; padding: 40px 56px; max-width: 1100px; width: 100%; margin: 0 auto; align-content: start; }
37
+ @media (max-width: 700px) { main { grid-template-columns: 1fr; padding: 24px 16px; gap: 28px; } }
38
+ h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 0 0 10px; font-weight: 600; }
39
+ ol { list-style: none; margin: 0; padding: 0; }
40
+ li button { all: unset; box-sizing: border-box; width: 100%; display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
41
+ li button.chosen { background: var(--chosen); }
42
+ li .path { color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
43
+ li .names { min-width: 0; }
44
+ li .when { color: var(--dim); font-size: 12px; white-space: nowrap; }
45
+ .empty { color: var(--dim); padding: 8px 10px; }
46
+ .hint { color: var(--dim); font-size: 12px; margin-top: 12px; padding: 0 10px; }
47
+ .actions button { display: flex; justify-content: space-between; width: 100%; margin-bottom: 10px; padding: 9px 12px; border-radius: 7px; border: 1px solid var(--button-line); background: var(--button); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
48
+ .actions button:first-of-type { border-color: var(--accent); }
49
+ .actions .key { color: var(--dim); font-size: 12px; }
50
+ /* Amber, for something waiting on you: unlike the buttons above it, and unlike blue, which is what Enter presses. */
51
+ #updates:not(:empty) { margin-top: 18px; }
52
+ .update { margin-bottom: 10px; padding: 9px 12px; border-radius: 7px; border: 1px solid color-mix(in srgb, var(--fresh) 45%, transparent);
53
+ border-left: 3px solid var(--fresh); background: color-mix(in srgb, var(--fresh) 10%, var(--bg)); font-size: 13px; }
54
+ .update b { color: var(--fresh); }
55
+ .update .cmd { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 4px; }
56
+ .update code { font: 12px ui-monospace, monospace; color: var(--dim); }
57
+ .update .copy { all: unset; color: var(--accent); font-size: 12px; cursor: pointer; }
58
+ #problem { display: none; margin: 0 0 16px; padding: 10px 12px; border-radius: 6px; background: var(--problem); border-left: 3px solid #e06c6c; grid-column: 1 / -1; }
59
+ </style>
60
+ </head>
61
+ <body>
62
+ <header><b>reladraw studio</b><span>no file open</span></header>
63
+ <main>
64
+ <div id="problem"></div>
65
+ <section>
66
+ <h2>Recent</h2>
67
+ <ol id="recent"></ol>
68
+ <div class="hint" id="hint">Enter opens the highlighted one; ↑ ↓ move.</div>
69
+ </section>
70
+ <section class="actions">
71
+ <h2>Start</h2>
72
+ <button id="open-file">Open file…<span class="key" data-key="O"></span></button>
73
+ <button id="open-folder">Open folder…<span class="key" data-key="Shift O"></span></button>
74
+ <button id="new">New diagram…<span class="key" data-key="N"></span></button>
75
+ <button id="playground">Playground<span class="key" data-key="Shift P"></span></button>
76
+ <div id="updates"></div>
77
+ </section>
78
+ </main>
79
+ <script>
80
+ const studio = window.reladrawStudio;
81
+ const mac = studio.platform === 'darwin';
82
+ for (const key of document.querySelectorAll('[data-key]')) key.textContent = (mac ? '⌘ ' : 'Ctrl ') + key.dataset.key;
83
+
84
+ const list = document.getElementById('recent');
85
+ const problem = document.getElementById('problem');
86
+ let entries = [];
87
+ let chosen = 0;
88
+
89
+ function when(at) {
90
+ const then = new Date(at);
91
+ const days = Math.round((new Date().setHours(0, 0, 0, 0) - new Date(then).setHours(0, 0, 0, 0)) / 86400000);
92
+ if (days <= 0) return 'today';
93
+ if (days === 1) return 'yesterday';
94
+ return then.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
95
+ }
96
+
97
+ function draw() {
98
+ list.replaceChildren();
99
+ document.getElementById('hint').style.display = entries.length ? '' : 'none';
100
+ if (!entries.length) {
101
+ const none = document.createElement('li');
102
+ none.className = 'empty';
103
+ none.textContent = 'Nothing yet. What you open is listed here.';
104
+ list.append(none);
105
+ return;
106
+ }
107
+ entries.forEach((entry, i) => {
108
+ const item = document.createElement('li');
109
+ const button = document.createElement('button');
110
+ if (i === chosen) button.className = 'chosen';
111
+ const names = document.createElement('span');
112
+ names.className = 'names';
113
+ names.append(entry.name);
114
+ const path = document.createElement('div');
115
+ path.className = 'path';
116
+ path.textContent = entry.where;
117
+ names.append(path);
118
+ const at = document.createElement('span');
119
+ at.className = 'when';
120
+ at.textContent = when(entry.at);
121
+ button.append(names, at);
122
+ button.addEventListener('click', () => go(studio.open(entry.paths)));
123
+ button.addEventListener('mouseenter', () => { chosen = i; mark(); });
124
+ item.append(button);
125
+ list.append(item);
126
+ });
127
+ }
128
+
129
+ function mark() {
130
+ list.querySelectorAll('li button').forEach((button, i) => button.classList.toggle('chosen', i === chosen));
131
+ }
132
+
133
+ async function go(promise) {
134
+ const result = await promise;
135
+ if (result && result.problem) {
136
+ problem.textContent = result.problem;
137
+ problem.style.display = 'block';
138
+ }
139
+ }
140
+
141
+ document.getElementById('open-file').addEventListener('click', () => go(studio.choose('file')));
142
+ document.getElementById('open-folder').addEventListener('click', () => go(studio.choose('folder')));
143
+ document.getElementById('new').addEventListener('click', () => go(studio.choose('new')));
144
+ document.getElementById('playground').addEventListener('click', () => go(studio.playground()));
145
+
146
+ document.addEventListener('keydown', (event) => {
147
+ const mod = mac ? event.metaKey : event.ctrlKey;
148
+ const key = event.key.toLowerCase();
149
+ if (mod && key === 'o') { event.preventDefault(); go(studio.choose(event.shiftKey ? 'folder' : 'file')); return; }
150
+ if (mod && key === 'n' && !event.shiftKey) { event.preventDefault(); go(studio.choose('new')); return; }
151
+ if (mod && event.shiftKey && key === 'p') { event.preventDefault(); go(studio.playground()); return; }
152
+ if (mod || event.altKey || !entries.length) return;
153
+ if (event.key === 'ArrowDown') { event.preventDefault(); chosen = Math.min(entries.length - 1, chosen + 1); mark(); }
154
+ else if (event.key === 'ArrowUp') { event.preventDefault(); chosen = Math.max(0, chosen - 1); mark(); }
155
+ else if (event.key === 'Enter') { event.preventDefault(); go(studio.open(entries[chosen].paths)); }
156
+ });
157
+
158
+ studio.recent().then((found) => { entries = found; chosen = 0; draw(); });
159
+
160
+ // What to update, studio or the reladraw beside it: a line under the buttons
161
+ // for each, for as long as it holds.
162
+ const updates = document.getElementById('updates');
163
+ function showUpdates(notices) {
164
+ updates.replaceChildren();
165
+ for (const notice of notices || []) {
166
+ const line = document.createElement('div');
167
+ line.className = 'update';
168
+ const title = document.createElement('b');
169
+ title.textContent = `${notice.title}.`;
170
+ const cmd = document.createElement('div');
171
+ cmd.className = 'cmd';
172
+ const code = document.createElement('code');
173
+ code.textContent = notice.command;
174
+ const copy = document.createElement('button');
175
+ copy.className = 'copy';
176
+ copy.type = 'button';
177
+ copy.textContent = 'Copy';
178
+ copy.onclick = () => studio.copy(notice.command).then(() => { copy.textContent = 'Copied'; });
179
+ cmd.append(code, copy);
180
+ const detail = notice.detail.charAt(0).toUpperCase() + notice.detail.slice(1);
181
+ line.append(title, ` ${detail}.`, cmd);
182
+ updates.append(line);
183
+ }
184
+ }
185
+ studio.update().then(showUpdates);
186
+ studio.onUpdate(showUpdates);
187
+ </script>
188
+ </body>
189
+ </html>
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/tabs/preload.ts
17
+ var preload_exports = {};
18
+ module.exports = __toCommonJS(preload_exports);
19
+ var import_electron = require("electron");
20
+ import_electron.contextBridge.exposeInMainWorld("reladrawTabs", {
21
+ platform: process.platform,
22
+ onState: (draw) => import_electron.ipcRenderer.on("tabs:state", (_event, state) => draw(state)),
23
+ select: (index) => import_electron.ipcRenderer.send("tabs:select", index),
24
+ close: (index) => import_electron.ipcRenderer.send("tabs:close", index),
25
+ add: () => import_electron.ipcRenderer.send("tabs:add")
26
+ });
@@ -0,0 +1,69 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'">
6
+ <title>tabs</title>
7
+ <style>
8
+ /* The strip of tabs above a window's page, shown while two or more are open. */
9
+ :root { --bg: #0a0a0a; --tab: #121212; --text: #d8dae0; --dim: #8a8f9c; --hover: #17181c; --dot: #e8c872; --line: #2a2d35; }
10
+ @media (prefers-color-scheme: light) {
11
+ :root { --bg: #e9eaee; --tab: #fafafa; --text: #1d2026; --dim: #6a707c; --hover: #f2f3f6; --dot: #b8860b; --line: #dcdfe5; }
12
+ }
13
+ * { box-sizing: border-box; }
14
+ html, body { height: 100%; margin: 0; overflow: hidden; }
15
+ body { background: var(--bg); color: var(--dim); font: 13px/1 system-ui, sans-serif; display: flex; align-items: flex-end; padding: 0 6px; gap: 2px; user-select: none; }
16
+ .tab { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 6px 0 12px; border-radius: 6px 6px 0 0; max-width: 240px; min-width: 0; flex: 0 1 auto; cursor: default; }
17
+ .tab:hover { background: var(--hover); }
18
+ .tab.on { background: var(--tab); color: var(--text); }
19
+ .tab .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
20
+ /* The close mark, or the unsaved dot in its place until the pointer is over the tab. */
21
+ .tab .end { all: unset; flex: none; width: 18px; height: 18px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--dim); }
22
+ .tab .end:hover { background: var(--line); color: var(--text); }
23
+ .tab .end.dot { color: var(--dot); font-size: 10px; }
24
+ .tab:hover .end.dot { color: var(--dim); font-size: 12px; }
25
+ .tab:hover .end.dot::before { content: '×'; }
26
+ .tab:hover .end.dot span { display: none; }
27
+ .add { all: unset; flex: none; width: 26px; height: 26px; margin-bottom: 1px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--dim); }
28
+ .add:hover { background: var(--hover); color: var(--text); }
29
+ </style>
30
+ </head>
31
+ <body>
32
+ <script>
33
+ const tabs = window.reladrawTabs;
34
+ const mac = tabs.platform === 'darwin';
35
+ const key = (k) => (mac ? '⌘' : 'Ctrl+') + k;
36
+
37
+ tabs.onState((state) => {
38
+ document.body.replaceChildren();
39
+ state.tabs.forEach((tab, i) => {
40
+ const button = document.createElement('button');
41
+ button.className = 'tab' + (i === state.active ? ' on' : '');
42
+ button.title = tab.title + (tab.unsaved ? ' (not saved)' : '');
43
+ const name = document.createElement('span');
44
+ name.className = 'name';
45
+ name.textContent = tab.title;
46
+ const end = document.createElement('span');
47
+ end.className = 'end' + (tab.unsaved ? ' dot' : '');
48
+ end.title = 'Close (' + key('W') + ')';
49
+ if (tab.unsaved) { const dot = document.createElement('span'); dot.textContent = '●'; end.append(dot); } else end.textContent = '×';
50
+ // Pressing the × must not pick the tab first: the strip would redraw under
51
+ // the pointer, and the click would land on nothing.
52
+ end.addEventListener('mousedown', (event) => event.stopPropagation());
53
+ end.addEventListener('click', (event) => { event.stopPropagation(); tabs.close(i); });
54
+ button.append(name, end);
55
+ button.addEventListener('mousedown', (event) => { if (event.button === 0) tabs.select(i); });
56
+ // A middle click closes a tab, as in a browser.
57
+ button.addEventListener('auxclick', (event) => { if (event.button === 1) tabs.close(i); });
58
+ document.body.append(button);
59
+ });
60
+ const add = document.createElement('button');
61
+ add.className = 'add';
62
+ add.textContent = '+';
63
+ add.title = 'New tab (' + key('T') + ')';
64
+ add.addEventListener('click', () => tabs.add());
65
+ document.body.append(add);
66
+ });
67
+ </script>
68
+ </body>
69
+ </html>