@plures/praxis 1.1.0 → 1.1.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.
- package/LICENSE +21 -21
- package/core/codegen/ts-generator.ts +15 -15
- package/dist/node/cli/index.cjs +3 -2282
- package/dist/node/cli/index.js +1 -1
- package/dist/node/{verify-YBZ7W24H.js → verify-QRYKRIDU.js} +3 -2282
- package/docs/REACTIVE_REDESIGN.md +132 -132
- package/docs/SVELTE_INTEGRATION_STRATEGY.md +68 -68
- package/package.json +132 -132
- package/src/components/TerminalNode.svelte +457 -457
- package/src/core/reactive-engine.svelte.ts +65 -65
- package/src/core/reactive-engine.ts +67 -67
- package/src/core/schema/loader.common.ts +150 -150
- package/src/examples/advanced-todo/App.svelte +506 -506
- package/src/index.browser.ts +204 -204
|
@@ -1,457 +1,457 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* TerminalNode.svelte
|
|
4
|
-
*
|
|
5
|
-
* Svelte component for terminal nodes in Praxis/RuneBook.
|
|
6
|
-
* Provides a terminal interface with command execution, history, and canvas integration.
|
|
7
|
-
*/
|
|
8
|
-
import { onDestroy } from 'svelte';
|
|
9
|
-
import type { TerminalAdapter } from '../runtime/terminal-adapter.js';
|
|
10
|
-
import type { TerminalExecutionResult } from '../runtime/terminal-adapter.js';
|
|
11
|
-
|
|
12
|
-
// Props
|
|
13
|
-
export let adapter: TerminalAdapter;
|
|
14
|
-
export let x: number = 0;
|
|
15
|
-
export let y: number = 0;
|
|
16
|
-
export let width: number = 600;
|
|
17
|
-
export let height: number = 400;
|
|
18
|
-
export let draggable: boolean = true;
|
|
19
|
-
export let resizable: boolean = true;
|
|
20
|
-
export let showContextMenu: boolean = false;
|
|
21
|
-
|
|
22
|
-
// Local state
|
|
23
|
-
let currentCommand = '';
|
|
24
|
-
let isDragging = false;
|
|
25
|
-
let isResizing = false;
|
|
26
|
-
let dragStartX = 0;
|
|
27
|
-
let dragStartY = 0;
|
|
28
|
-
let resizeStartX = 0;
|
|
29
|
-
let resizeStartY = 0;
|
|
30
|
-
let resizeStartWidth = 0;
|
|
31
|
-
let resizeStartHeight = 0;
|
|
32
|
-
let terminalOutput: TerminalExecutionResult[] = [];
|
|
33
|
-
let contextMenuX = 0;
|
|
34
|
-
let contextMenuY = 0;
|
|
35
|
-
let outputContainer: HTMLDivElement;
|
|
36
|
-
|
|
37
|
-
// Get state from adapter
|
|
38
|
-
$: state = adapter.getState();
|
|
39
|
-
$: inputMode = state.inputMode;
|
|
40
|
-
$: history = state.history;
|
|
41
|
-
$: lastOutput = state.lastOutput;
|
|
42
|
-
|
|
43
|
-
// Execute command
|
|
44
|
-
async function executeCommand() {
|
|
45
|
-
if (!currentCommand.trim()) return;
|
|
46
|
-
|
|
47
|
-
const result = await adapter.executeCommand(currentCommand);
|
|
48
|
-
terminalOutput = [...terminalOutput, result];
|
|
49
|
-
currentCommand = '';
|
|
50
|
-
|
|
51
|
-
// Auto-scroll to bottom after DOM update
|
|
52
|
-
if (outputContainer) {
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
outputContainer.scrollTop = outputContainer.scrollHeight;
|
|
55
|
-
}, 0);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Handle keyboard shortcuts
|
|
60
|
-
function handleKeyDown(event: KeyboardEvent) {
|
|
61
|
-
if (event.key === 'Enter' && !event.shiftKey) {
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
executeCommand();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Drag handling
|
|
68
|
-
function startDrag(event: MouseEvent) {
|
|
69
|
-
if (!draggable) return;
|
|
70
|
-
isDragging = true;
|
|
71
|
-
dragStartX = event.clientX - x;
|
|
72
|
-
dragStartY = event.clientY - y;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function handleDrag(event: MouseEvent) {
|
|
76
|
-
if (!isDragging) return;
|
|
77
|
-
x = event.clientX - dragStartX;
|
|
78
|
-
y = event.clientY - dragStartY;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function stopDrag() {
|
|
82
|
-
isDragging = false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Resize handling
|
|
86
|
-
function startResize(event: MouseEvent) {
|
|
87
|
-
if (!resizable) return;
|
|
88
|
-
event.stopPropagation();
|
|
89
|
-
isResizing = true;
|
|
90
|
-
resizeStartX = event.clientX;
|
|
91
|
-
resizeStartY = event.clientY;
|
|
92
|
-
resizeStartWidth = width;
|
|
93
|
-
resizeStartHeight = height;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function handleResize(event: MouseEvent) {
|
|
97
|
-
if (!isResizing) return;
|
|
98
|
-
const deltaX = event.clientX - resizeStartX;
|
|
99
|
-
const deltaY = event.clientY - resizeStartY;
|
|
100
|
-
width = Math.max(300, resizeStartWidth + deltaX);
|
|
101
|
-
height = Math.max(200, resizeStartHeight + deltaY);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function stopResize() {
|
|
105
|
-
isResizing = false;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Context menu handling
|
|
109
|
-
function handleContextMenu(event: MouseEvent) {
|
|
110
|
-
event.preventDefault();
|
|
111
|
-
contextMenuX = event.clientX;
|
|
112
|
-
contextMenuY = event.clientY;
|
|
113
|
-
showContextMenu = true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function closeContextMenu() {
|
|
117
|
-
showContextMenu = false;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function clearTerminal() {
|
|
121
|
-
terminalOutput = [];
|
|
122
|
-
adapter.clearHistory();
|
|
123
|
-
closeContextMenu();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function copyLastOutput() {
|
|
127
|
-
if (lastOutput) {
|
|
128
|
-
navigator.clipboard.writeText(lastOutput);
|
|
129
|
-
}
|
|
130
|
-
closeContextMenu();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Global mouse event listeners with proper cleanup
|
|
134
|
-
let mouseMoveHandler: ((e: MouseEvent) => void) | null = null;
|
|
135
|
-
let mouseUpHandler: (() => void) | null = null;
|
|
136
|
-
|
|
137
|
-
$: {
|
|
138
|
-
// Remove old listeners if they exist
|
|
139
|
-
if (mouseMoveHandler) {
|
|
140
|
-
window.removeEventListener('mousemove', mouseMoveHandler);
|
|
141
|
-
}
|
|
142
|
-
if (mouseUpHandler) {
|
|
143
|
-
window.removeEventListener('mouseup', mouseUpHandler);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Add new listeners if dragging or resizing
|
|
147
|
-
if (isDragging) {
|
|
148
|
-
mouseMoveHandler = handleDrag;
|
|
149
|
-
mouseUpHandler = stopDrag;
|
|
150
|
-
window.addEventListener('mousemove', mouseMoveHandler);
|
|
151
|
-
window.addEventListener('mouseup', mouseUpHandler);
|
|
152
|
-
} else if (isResizing) {
|
|
153
|
-
mouseMoveHandler = handleResize;
|
|
154
|
-
mouseUpHandler = stopResize;
|
|
155
|
-
window.addEventListener('mousemove', mouseMoveHandler);
|
|
156
|
-
window.addEventListener('mouseup', mouseUpHandler);
|
|
157
|
-
} else {
|
|
158
|
-
mouseMoveHandler = null;
|
|
159
|
-
mouseUpHandler = null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Cleanup event listeners on component destroy
|
|
164
|
-
onDestroy(() => {
|
|
165
|
-
if (mouseMoveHandler) {
|
|
166
|
-
window.removeEventListener('mousemove', mouseMoveHandler);
|
|
167
|
-
}
|
|
168
|
-
if (mouseUpHandler) {
|
|
169
|
-
window.removeEventListener('mouseup', mouseUpHandler);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Click outside to close context menu
|
|
174
|
-
function handleDocumentClick() {
|
|
175
|
-
if (showContextMenu) {
|
|
176
|
-
closeContextMenu();
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
</script>
|
|
180
|
-
|
|
181
|
-
<svelte:window on:click={handleDocumentClick} />
|
|
182
|
-
|
|
183
|
-
<div
|
|
184
|
-
class="terminal-node"
|
|
185
|
-
style="left: {x}px; top: {y}px; width: {width}px; height: {height}px;"
|
|
186
|
-
on:contextmenu={handleContextMenu}
|
|
187
|
-
role="application"
|
|
188
|
-
aria-label="Terminal Node"
|
|
189
|
-
>
|
|
190
|
-
<!-- Title bar -->
|
|
191
|
-
<div
|
|
192
|
-
class="terminal-header"
|
|
193
|
-
on:mousedown={startDrag}
|
|
194
|
-
role="banner"
|
|
195
|
-
>
|
|
196
|
-
<span class="terminal-title">Terminal: {state.nodeId}</span>
|
|
197
|
-
<span class="terminal-mode">Mode: {inputMode}</span>
|
|
198
|
-
</div>
|
|
199
|
-
|
|
200
|
-
<!-- Output area -->
|
|
201
|
-
<div class="terminal-output" bind:this={outputContainer}>
|
|
202
|
-
{#if terminalOutput.length === 0}
|
|
203
|
-
<div class="terminal-empty">No output yet. Enter a command below.</div>
|
|
204
|
-
{:else}
|
|
205
|
-
{#each terminalOutput as result}
|
|
206
|
-
<div class="terminal-result">
|
|
207
|
-
<div class="terminal-command">$ {result.command}</div>
|
|
208
|
-
<div class="terminal-result-output">{result.output}</div>
|
|
209
|
-
{#if result.error}
|
|
210
|
-
<div class="terminal-error">Error: {result.error}</div>
|
|
211
|
-
{/if}
|
|
212
|
-
</div>
|
|
213
|
-
{/each}
|
|
214
|
-
{/if}
|
|
215
|
-
</div>
|
|
216
|
-
|
|
217
|
-
<!-- Input area -->
|
|
218
|
-
<div class="terminal-input-area">
|
|
219
|
-
<span class="terminal-prompt">$</span>
|
|
220
|
-
{#if inputMode === 'text'}
|
|
221
|
-
<input
|
|
222
|
-
type="text"
|
|
223
|
-
class="terminal-input"
|
|
224
|
-
bind:value={currentCommand}
|
|
225
|
-
on:keydown={handleKeyDown}
|
|
226
|
-
placeholder="Enter command..."
|
|
227
|
-
aria-label="Terminal input"
|
|
228
|
-
/>
|
|
229
|
-
{:else if inputMode === 'widget'}
|
|
230
|
-
<textarea
|
|
231
|
-
class="terminal-input terminal-input-widget"
|
|
232
|
-
bind:value={currentCommand}
|
|
233
|
-
on:keydown={handleKeyDown}
|
|
234
|
-
placeholder="Enter command..."
|
|
235
|
-
rows="1"
|
|
236
|
-
aria-label="Terminal input widget"
|
|
237
|
-
/>
|
|
238
|
-
{/if}
|
|
239
|
-
<button class="terminal-submit" on:click={executeCommand}>Run</button>
|
|
240
|
-
</div>
|
|
241
|
-
|
|
242
|
-
<!-- Resize handle -->
|
|
243
|
-
{#if resizable}
|
|
244
|
-
<div
|
|
245
|
-
class="terminal-resize-handle"
|
|
246
|
-
on:mousedown={startResize}
|
|
247
|
-
role="button"
|
|
248
|
-
tabindex="0"
|
|
249
|
-
aria-label="Resize terminal"
|
|
250
|
-
/>
|
|
251
|
-
{/if}
|
|
252
|
-
|
|
253
|
-
<!-- Context menu -->
|
|
254
|
-
{#if showContextMenu}
|
|
255
|
-
<div
|
|
256
|
-
class="terminal-context-menu"
|
|
257
|
-
style="left: {contextMenuX}px; top: {contextMenuY}px;"
|
|
258
|
-
role="menu"
|
|
259
|
-
>
|
|
260
|
-
<button class="context-menu-item" on:click={clearTerminal}>Clear Terminal</button>
|
|
261
|
-
<button class="context-menu-item" on:click={copyLastOutput} disabled={!lastOutput}>
|
|
262
|
-
Copy Last Output
|
|
263
|
-
</button>
|
|
264
|
-
<button class="context-menu-item" on:click={closeContextMenu}>Close Menu</button>
|
|
265
|
-
</div>
|
|
266
|
-
{/if}
|
|
267
|
-
</div>
|
|
268
|
-
|
|
269
|
-
<style>
|
|
270
|
-
.terminal-node {
|
|
271
|
-
position: absolute;
|
|
272
|
-
display: flex;
|
|
273
|
-
flex-direction: column;
|
|
274
|
-
background: #1e1e1e;
|
|
275
|
-
border: 1px solid #3c3c3c;
|
|
276
|
-
border-radius: 8px;
|
|
277
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
278
|
-
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
279
|
-
color: #d4d4d4;
|
|
280
|
-
overflow: hidden;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
.terminal-header {
|
|
284
|
-
display: flex;
|
|
285
|
-
justify-content: space-between;
|
|
286
|
-
align-items: center;
|
|
287
|
-
padding: 8px 12px;
|
|
288
|
-
background: #2d2d2d;
|
|
289
|
-
border-bottom: 1px solid #3c3c3c;
|
|
290
|
-
cursor: move;
|
|
291
|
-
user-select: none;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
.terminal-title {
|
|
295
|
-
font-weight: 600;
|
|
296
|
-
font-size: 14px;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
.terminal-mode {
|
|
300
|
-
font-size: 12px;
|
|
301
|
-
color: #858585;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
.terminal-output {
|
|
305
|
-
flex: 1;
|
|
306
|
-
padding: 12px;
|
|
307
|
-
overflow-y: auto;
|
|
308
|
-
background: #1e1e1e;
|
|
309
|
-
font-size: 13px;
|
|
310
|
-
line-height: 1.6;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
.terminal-empty {
|
|
314
|
-
color: #858585;
|
|
315
|
-
font-style: italic;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
.terminal-result {
|
|
319
|
-
margin-bottom: 16px;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
.terminal-command {
|
|
323
|
-
color: #4ec9b0;
|
|
324
|
-
font-weight: 600;
|
|
325
|
-
margin-bottom: 4px;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
.terminal-result-output {
|
|
329
|
-
color: #d4d4d4;
|
|
330
|
-
white-space: pre-wrap;
|
|
331
|
-
word-break: break-word;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
.terminal-error {
|
|
335
|
-
color: #f48771;
|
|
336
|
-
margin-top: 4px;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
.terminal-input-area {
|
|
340
|
-
display: flex;
|
|
341
|
-
align-items: center;
|
|
342
|
-
gap: 8px;
|
|
343
|
-
padding: 8px 12px;
|
|
344
|
-
background: #2d2d2d;
|
|
345
|
-
border-top: 1px solid #3c3c3c;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
.terminal-prompt {
|
|
349
|
-
color: #4ec9b0;
|
|
350
|
-
font-weight: 600;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
.terminal-input {
|
|
354
|
-
flex: 1;
|
|
355
|
-
padding: 6px 8px;
|
|
356
|
-
background: #3c3c3c;
|
|
357
|
-
border: 1px solid #515151;
|
|
358
|
-
border-radius: 4px;
|
|
359
|
-
color: #d4d4d4;
|
|
360
|
-
font-family: inherit;
|
|
361
|
-
font-size: 13px;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
.terminal-input:focus {
|
|
365
|
-
outline: none;
|
|
366
|
-
border-color: #007acc;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
.terminal-input-widget {
|
|
370
|
-
resize: vertical;
|
|
371
|
-
min-height: 28px;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
.terminal-submit {
|
|
375
|
-
padding: 6px 16px;
|
|
376
|
-
background: #007acc;
|
|
377
|
-
border: none;
|
|
378
|
-
border-radius: 4px;
|
|
379
|
-
color: white;
|
|
380
|
-
font-size: 13px;
|
|
381
|
-
font-weight: 600;
|
|
382
|
-
cursor: pointer;
|
|
383
|
-
transition: background 0.2s;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
.terminal-submit:hover {
|
|
387
|
-
background: #005a9e;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
.terminal-submit:active {
|
|
391
|
-
background: #004578;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
.terminal-resize-handle {
|
|
395
|
-
position: absolute;
|
|
396
|
-
bottom: 0;
|
|
397
|
-
right: 0;
|
|
398
|
-
width: 16px;
|
|
399
|
-
height: 16px;
|
|
400
|
-
cursor: nwse-resize;
|
|
401
|
-
background: linear-gradient(135deg, transparent 50%, #515151 50%);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
.terminal-resize-handle:hover {
|
|
405
|
-
background: linear-gradient(135deg, transparent 50%, #007acc 50%);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
.terminal-context-menu {
|
|
409
|
-
position: fixed;
|
|
410
|
-
background: #2d2d2d;
|
|
411
|
-
border: 1px solid #515151;
|
|
412
|
-
border-radius: 4px;
|
|
413
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
|
|
414
|
-
padding: 4px 0;
|
|
415
|
-
z-index: 1000;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
.context-menu-item {
|
|
419
|
-
display: block;
|
|
420
|
-
width: 100%;
|
|
421
|
-
padding: 8px 16px;
|
|
422
|
-
background: transparent;
|
|
423
|
-
border: none;
|
|
424
|
-
color: #d4d4d4;
|
|
425
|
-
font-size: 13px;
|
|
426
|
-
text-align: left;
|
|
427
|
-
cursor: pointer;
|
|
428
|
-
transition: background 0.2s;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
.context-menu-item:hover:not(:disabled) {
|
|
432
|
-
background: #3c3c3c;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
.context-menu-item:disabled {
|
|
436
|
-
color: #858585;
|
|
437
|
-
cursor: not-allowed;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/* Scrollbar styling */
|
|
441
|
-
.terminal-output::-webkit-scrollbar {
|
|
442
|
-
width: 8px;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
.terminal-output::-webkit-scrollbar-track {
|
|
446
|
-
background: #1e1e1e;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
.terminal-output::-webkit-scrollbar-thumb {
|
|
450
|
-
background: #515151;
|
|
451
|
-
border-radius: 4px;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
.terminal-output::-webkit-scrollbar-thumb:hover {
|
|
455
|
-
background: #686868;
|
|
456
|
-
}
|
|
457
|
-
</style>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* TerminalNode.svelte
|
|
4
|
+
*
|
|
5
|
+
* Svelte component for terminal nodes in Praxis/RuneBook.
|
|
6
|
+
* Provides a terminal interface with command execution, history, and canvas integration.
|
|
7
|
+
*/
|
|
8
|
+
import { onDestroy } from 'svelte';
|
|
9
|
+
import type { TerminalAdapter } from '../runtime/terminal-adapter.js';
|
|
10
|
+
import type { TerminalExecutionResult } from '../runtime/terminal-adapter.js';
|
|
11
|
+
|
|
12
|
+
// Props
|
|
13
|
+
export let adapter: TerminalAdapter;
|
|
14
|
+
export let x: number = 0;
|
|
15
|
+
export let y: number = 0;
|
|
16
|
+
export let width: number = 600;
|
|
17
|
+
export let height: number = 400;
|
|
18
|
+
export let draggable: boolean = true;
|
|
19
|
+
export let resizable: boolean = true;
|
|
20
|
+
export let showContextMenu: boolean = false;
|
|
21
|
+
|
|
22
|
+
// Local state
|
|
23
|
+
let currentCommand = '';
|
|
24
|
+
let isDragging = false;
|
|
25
|
+
let isResizing = false;
|
|
26
|
+
let dragStartX = 0;
|
|
27
|
+
let dragStartY = 0;
|
|
28
|
+
let resizeStartX = 0;
|
|
29
|
+
let resizeStartY = 0;
|
|
30
|
+
let resizeStartWidth = 0;
|
|
31
|
+
let resizeStartHeight = 0;
|
|
32
|
+
let terminalOutput: TerminalExecutionResult[] = [];
|
|
33
|
+
let contextMenuX = 0;
|
|
34
|
+
let contextMenuY = 0;
|
|
35
|
+
let outputContainer: HTMLDivElement;
|
|
36
|
+
|
|
37
|
+
// Get state from adapter
|
|
38
|
+
$: state = adapter.getState();
|
|
39
|
+
$: inputMode = state.inputMode;
|
|
40
|
+
$: history = state.history;
|
|
41
|
+
$: lastOutput = state.lastOutput;
|
|
42
|
+
|
|
43
|
+
// Execute command
|
|
44
|
+
async function executeCommand() {
|
|
45
|
+
if (!currentCommand.trim()) return;
|
|
46
|
+
|
|
47
|
+
const result = await adapter.executeCommand(currentCommand);
|
|
48
|
+
terminalOutput = [...terminalOutput, result];
|
|
49
|
+
currentCommand = '';
|
|
50
|
+
|
|
51
|
+
// Auto-scroll to bottom after DOM update
|
|
52
|
+
if (outputContainer) {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
outputContainer.scrollTop = outputContainer.scrollHeight;
|
|
55
|
+
}, 0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Handle keyboard shortcuts
|
|
60
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
61
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
executeCommand();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Drag handling
|
|
68
|
+
function startDrag(event: MouseEvent) {
|
|
69
|
+
if (!draggable) return;
|
|
70
|
+
isDragging = true;
|
|
71
|
+
dragStartX = event.clientX - x;
|
|
72
|
+
dragStartY = event.clientY - y;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function handleDrag(event: MouseEvent) {
|
|
76
|
+
if (!isDragging) return;
|
|
77
|
+
x = event.clientX - dragStartX;
|
|
78
|
+
y = event.clientY - dragStartY;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function stopDrag() {
|
|
82
|
+
isDragging = false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Resize handling
|
|
86
|
+
function startResize(event: MouseEvent) {
|
|
87
|
+
if (!resizable) return;
|
|
88
|
+
event.stopPropagation();
|
|
89
|
+
isResizing = true;
|
|
90
|
+
resizeStartX = event.clientX;
|
|
91
|
+
resizeStartY = event.clientY;
|
|
92
|
+
resizeStartWidth = width;
|
|
93
|
+
resizeStartHeight = height;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function handleResize(event: MouseEvent) {
|
|
97
|
+
if (!isResizing) return;
|
|
98
|
+
const deltaX = event.clientX - resizeStartX;
|
|
99
|
+
const deltaY = event.clientY - resizeStartY;
|
|
100
|
+
width = Math.max(300, resizeStartWidth + deltaX);
|
|
101
|
+
height = Math.max(200, resizeStartHeight + deltaY);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function stopResize() {
|
|
105
|
+
isResizing = false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Context menu handling
|
|
109
|
+
function handleContextMenu(event: MouseEvent) {
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
contextMenuX = event.clientX;
|
|
112
|
+
contextMenuY = event.clientY;
|
|
113
|
+
showContextMenu = true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function closeContextMenu() {
|
|
117
|
+
showContextMenu = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function clearTerminal() {
|
|
121
|
+
terminalOutput = [];
|
|
122
|
+
adapter.clearHistory();
|
|
123
|
+
closeContextMenu();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function copyLastOutput() {
|
|
127
|
+
if (lastOutput) {
|
|
128
|
+
navigator.clipboard.writeText(lastOutput);
|
|
129
|
+
}
|
|
130
|
+
closeContextMenu();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Global mouse event listeners with proper cleanup
|
|
134
|
+
let mouseMoveHandler: ((e: MouseEvent) => void) | null = null;
|
|
135
|
+
let mouseUpHandler: (() => void) | null = null;
|
|
136
|
+
|
|
137
|
+
$: {
|
|
138
|
+
// Remove old listeners if they exist
|
|
139
|
+
if (mouseMoveHandler) {
|
|
140
|
+
window.removeEventListener('mousemove', mouseMoveHandler);
|
|
141
|
+
}
|
|
142
|
+
if (mouseUpHandler) {
|
|
143
|
+
window.removeEventListener('mouseup', mouseUpHandler);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Add new listeners if dragging or resizing
|
|
147
|
+
if (isDragging) {
|
|
148
|
+
mouseMoveHandler = handleDrag;
|
|
149
|
+
mouseUpHandler = stopDrag;
|
|
150
|
+
window.addEventListener('mousemove', mouseMoveHandler);
|
|
151
|
+
window.addEventListener('mouseup', mouseUpHandler);
|
|
152
|
+
} else if (isResizing) {
|
|
153
|
+
mouseMoveHandler = handleResize;
|
|
154
|
+
mouseUpHandler = stopResize;
|
|
155
|
+
window.addEventListener('mousemove', mouseMoveHandler);
|
|
156
|
+
window.addEventListener('mouseup', mouseUpHandler);
|
|
157
|
+
} else {
|
|
158
|
+
mouseMoveHandler = null;
|
|
159
|
+
mouseUpHandler = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Cleanup event listeners on component destroy
|
|
164
|
+
onDestroy(() => {
|
|
165
|
+
if (mouseMoveHandler) {
|
|
166
|
+
window.removeEventListener('mousemove', mouseMoveHandler);
|
|
167
|
+
}
|
|
168
|
+
if (mouseUpHandler) {
|
|
169
|
+
window.removeEventListener('mouseup', mouseUpHandler);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Click outside to close context menu
|
|
174
|
+
function handleDocumentClick() {
|
|
175
|
+
if (showContextMenu) {
|
|
176
|
+
closeContextMenu();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
</script>
|
|
180
|
+
|
|
181
|
+
<svelte:window on:click={handleDocumentClick} />
|
|
182
|
+
|
|
183
|
+
<div
|
|
184
|
+
class="terminal-node"
|
|
185
|
+
style="left: {x}px; top: {y}px; width: {width}px; height: {height}px;"
|
|
186
|
+
on:contextmenu={handleContextMenu}
|
|
187
|
+
role="application"
|
|
188
|
+
aria-label="Terminal Node"
|
|
189
|
+
>
|
|
190
|
+
<!-- Title bar -->
|
|
191
|
+
<div
|
|
192
|
+
class="terminal-header"
|
|
193
|
+
on:mousedown={startDrag}
|
|
194
|
+
role="banner"
|
|
195
|
+
>
|
|
196
|
+
<span class="terminal-title">Terminal: {state.nodeId}</span>
|
|
197
|
+
<span class="terminal-mode">Mode: {inputMode}</span>
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
<!-- Output area -->
|
|
201
|
+
<div class="terminal-output" bind:this={outputContainer}>
|
|
202
|
+
{#if terminalOutput.length === 0}
|
|
203
|
+
<div class="terminal-empty">No output yet. Enter a command below.</div>
|
|
204
|
+
{:else}
|
|
205
|
+
{#each terminalOutput as result}
|
|
206
|
+
<div class="terminal-result">
|
|
207
|
+
<div class="terminal-command">$ {result.command}</div>
|
|
208
|
+
<div class="terminal-result-output">{result.output}</div>
|
|
209
|
+
{#if result.error}
|
|
210
|
+
<div class="terminal-error">Error: {result.error}</div>
|
|
211
|
+
{/if}
|
|
212
|
+
</div>
|
|
213
|
+
{/each}
|
|
214
|
+
{/if}
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<!-- Input area -->
|
|
218
|
+
<div class="terminal-input-area">
|
|
219
|
+
<span class="terminal-prompt">$</span>
|
|
220
|
+
{#if inputMode === 'text'}
|
|
221
|
+
<input
|
|
222
|
+
type="text"
|
|
223
|
+
class="terminal-input"
|
|
224
|
+
bind:value={currentCommand}
|
|
225
|
+
on:keydown={handleKeyDown}
|
|
226
|
+
placeholder="Enter command..."
|
|
227
|
+
aria-label="Terminal input"
|
|
228
|
+
/>
|
|
229
|
+
{:else if inputMode === 'widget'}
|
|
230
|
+
<textarea
|
|
231
|
+
class="terminal-input terminal-input-widget"
|
|
232
|
+
bind:value={currentCommand}
|
|
233
|
+
on:keydown={handleKeyDown}
|
|
234
|
+
placeholder="Enter command..."
|
|
235
|
+
rows="1"
|
|
236
|
+
aria-label="Terminal input widget"
|
|
237
|
+
/>
|
|
238
|
+
{/if}
|
|
239
|
+
<button class="terminal-submit" on:click={executeCommand}>Run</button>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
<!-- Resize handle -->
|
|
243
|
+
{#if resizable}
|
|
244
|
+
<div
|
|
245
|
+
class="terminal-resize-handle"
|
|
246
|
+
on:mousedown={startResize}
|
|
247
|
+
role="button"
|
|
248
|
+
tabindex="0"
|
|
249
|
+
aria-label="Resize terminal"
|
|
250
|
+
/>
|
|
251
|
+
{/if}
|
|
252
|
+
|
|
253
|
+
<!-- Context menu -->
|
|
254
|
+
{#if showContextMenu}
|
|
255
|
+
<div
|
|
256
|
+
class="terminal-context-menu"
|
|
257
|
+
style="left: {contextMenuX}px; top: {contextMenuY}px;"
|
|
258
|
+
role="menu"
|
|
259
|
+
>
|
|
260
|
+
<button class="context-menu-item" on:click={clearTerminal}>Clear Terminal</button>
|
|
261
|
+
<button class="context-menu-item" on:click={copyLastOutput} disabled={!lastOutput}>
|
|
262
|
+
Copy Last Output
|
|
263
|
+
</button>
|
|
264
|
+
<button class="context-menu-item" on:click={closeContextMenu}>Close Menu</button>
|
|
265
|
+
</div>
|
|
266
|
+
{/if}
|
|
267
|
+
</div>
|
|
268
|
+
|
|
269
|
+
<style>
|
|
270
|
+
.terminal-node {
|
|
271
|
+
position: absolute;
|
|
272
|
+
display: flex;
|
|
273
|
+
flex-direction: column;
|
|
274
|
+
background: #1e1e1e;
|
|
275
|
+
border: 1px solid #3c3c3c;
|
|
276
|
+
border-radius: 8px;
|
|
277
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
278
|
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
279
|
+
color: #d4d4d4;
|
|
280
|
+
overflow: hidden;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.terminal-header {
|
|
284
|
+
display: flex;
|
|
285
|
+
justify-content: space-between;
|
|
286
|
+
align-items: center;
|
|
287
|
+
padding: 8px 12px;
|
|
288
|
+
background: #2d2d2d;
|
|
289
|
+
border-bottom: 1px solid #3c3c3c;
|
|
290
|
+
cursor: move;
|
|
291
|
+
user-select: none;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.terminal-title {
|
|
295
|
+
font-weight: 600;
|
|
296
|
+
font-size: 14px;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.terminal-mode {
|
|
300
|
+
font-size: 12px;
|
|
301
|
+
color: #858585;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.terminal-output {
|
|
305
|
+
flex: 1;
|
|
306
|
+
padding: 12px;
|
|
307
|
+
overflow-y: auto;
|
|
308
|
+
background: #1e1e1e;
|
|
309
|
+
font-size: 13px;
|
|
310
|
+
line-height: 1.6;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.terminal-empty {
|
|
314
|
+
color: #858585;
|
|
315
|
+
font-style: italic;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.terminal-result {
|
|
319
|
+
margin-bottom: 16px;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.terminal-command {
|
|
323
|
+
color: #4ec9b0;
|
|
324
|
+
font-weight: 600;
|
|
325
|
+
margin-bottom: 4px;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.terminal-result-output {
|
|
329
|
+
color: #d4d4d4;
|
|
330
|
+
white-space: pre-wrap;
|
|
331
|
+
word-break: break-word;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.terminal-error {
|
|
335
|
+
color: #f48771;
|
|
336
|
+
margin-top: 4px;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.terminal-input-area {
|
|
340
|
+
display: flex;
|
|
341
|
+
align-items: center;
|
|
342
|
+
gap: 8px;
|
|
343
|
+
padding: 8px 12px;
|
|
344
|
+
background: #2d2d2d;
|
|
345
|
+
border-top: 1px solid #3c3c3c;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.terminal-prompt {
|
|
349
|
+
color: #4ec9b0;
|
|
350
|
+
font-weight: 600;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.terminal-input {
|
|
354
|
+
flex: 1;
|
|
355
|
+
padding: 6px 8px;
|
|
356
|
+
background: #3c3c3c;
|
|
357
|
+
border: 1px solid #515151;
|
|
358
|
+
border-radius: 4px;
|
|
359
|
+
color: #d4d4d4;
|
|
360
|
+
font-family: inherit;
|
|
361
|
+
font-size: 13px;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.terminal-input:focus {
|
|
365
|
+
outline: none;
|
|
366
|
+
border-color: #007acc;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.terminal-input-widget {
|
|
370
|
+
resize: vertical;
|
|
371
|
+
min-height: 28px;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.terminal-submit {
|
|
375
|
+
padding: 6px 16px;
|
|
376
|
+
background: #007acc;
|
|
377
|
+
border: none;
|
|
378
|
+
border-radius: 4px;
|
|
379
|
+
color: white;
|
|
380
|
+
font-size: 13px;
|
|
381
|
+
font-weight: 600;
|
|
382
|
+
cursor: pointer;
|
|
383
|
+
transition: background 0.2s;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.terminal-submit:hover {
|
|
387
|
+
background: #005a9e;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.terminal-submit:active {
|
|
391
|
+
background: #004578;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.terminal-resize-handle {
|
|
395
|
+
position: absolute;
|
|
396
|
+
bottom: 0;
|
|
397
|
+
right: 0;
|
|
398
|
+
width: 16px;
|
|
399
|
+
height: 16px;
|
|
400
|
+
cursor: nwse-resize;
|
|
401
|
+
background: linear-gradient(135deg, transparent 50%, #515151 50%);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.terminal-resize-handle:hover {
|
|
405
|
+
background: linear-gradient(135deg, transparent 50%, #007acc 50%);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.terminal-context-menu {
|
|
409
|
+
position: fixed;
|
|
410
|
+
background: #2d2d2d;
|
|
411
|
+
border: 1px solid #515151;
|
|
412
|
+
border-radius: 4px;
|
|
413
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
|
|
414
|
+
padding: 4px 0;
|
|
415
|
+
z-index: 1000;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
.context-menu-item {
|
|
419
|
+
display: block;
|
|
420
|
+
width: 100%;
|
|
421
|
+
padding: 8px 16px;
|
|
422
|
+
background: transparent;
|
|
423
|
+
border: none;
|
|
424
|
+
color: #d4d4d4;
|
|
425
|
+
font-size: 13px;
|
|
426
|
+
text-align: left;
|
|
427
|
+
cursor: pointer;
|
|
428
|
+
transition: background 0.2s;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.context-menu-item:hover:not(:disabled) {
|
|
432
|
+
background: #3c3c3c;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.context-menu-item:disabled {
|
|
436
|
+
color: #858585;
|
|
437
|
+
cursor: not-allowed;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/* Scrollbar styling */
|
|
441
|
+
.terminal-output::-webkit-scrollbar {
|
|
442
|
+
width: 8px;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.terminal-output::-webkit-scrollbar-track {
|
|
446
|
+
background: #1e1e1e;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
.terminal-output::-webkit-scrollbar-thumb {
|
|
450
|
+
background: #515151;
|
|
451
|
+
border-radius: 4px;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.terminal-output::-webkit-scrollbar-thumb:hover {
|
|
455
|
+
background: #686868;
|
|
456
|
+
}
|
|
457
|
+
</style>
|