castle-web-cli 0.4.140 → 0.4.141
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/dist/agent.js +45 -4
- package/dist/init.js +1 -1
- package/dist/serve.js +10 -0
- package/dist/shell/assets/index-BiZuc7mo.js +441 -0
- package/dist/shell/index.html +1 -1
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/SingleEditor.jsx +101 -42
- package/kits/physics-3d/castle.json +1 -1
- package/kits/physics-3d/engine3d/editorChrome.jsx +48 -20
- package/kits/physics-3d/package-lock.json +1 -1
- package/package.json +1 -1
- package/dist/shell/assets/index-DDJUiBek.js +0 -441
package/dist/shell/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<link rel="icon" type="image/png" sizes="32x32" href="/__castle/ide/favicon-32x32.png" />
|
|
11
11
|
<link rel="icon" type="image/png" sizes="16x16" href="/__castle/ide/favicon-16x16.png" />
|
|
12
12
|
<link rel="icon" href="/__castle/ide/favicon.ico" sizes="any" />
|
|
13
|
-
<script type="module" crossorigin src="/__castle/ide/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/__castle/ide/assets/index-BiZuc7mo.js"></script>
|
|
14
14
|
<link rel="stylesheet" crossorigin href="/__castle/ide/assets/index-CAN0bnXn.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// The shell only routes the kit's RICH file types here (scene / pxart / style);
|
|
5
5
|
// file browsing and the code/text editor are now builtin shell panels.
|
|
6
6
|
|
|
7
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
7
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
8
8
|
import {
|
|
9
9
|
isImportedFile,
|
|
10
10
|
onBeforeRestart,
|
|
@@ -12,6 +12,16 @@ import {
|
|
|
12
12
|
takeReloadState,
|
|
13
13
|
writeFile,
|
|
14
14
|
} from 'castle-web-sdk';
|
|
15
|
+
import * as castleSdk from 'castle-web-sdk';
|
|
16
|
+
|
|
17
|
+
// A kit is published independently of the SDK, and a deck that takes a kit
|
|
18
|
+
// update keeps whatever SDK it already installed -- so the kit cannot assume the
|
|
19
|
+
// newest one. On an older SDK these two are simply absent, and the editor should
|
|
20
|
+
// lose its pending-save indicator rather than fail to load at all. `writeFile`
|
|
21
|
+
// is always there; on an old SDK it is the one-shot version, which is how this
|
|
22
|
+
// editor behaved before the queue existed.
|
|
23
|
+
const onSaveState = castleSdk.onSaveState ?? (() => () => undefined);
|
|
24
|
+
const hasPendingSave = castleSdk.hasPendingSave ?? (() => false);
|
|
15
25
|
import { getFileKind } from '../engine/files';
|
|
16
26
|
import { hasEditorModule, loadEditorModule } from './editorRegistry';
|
|
17
27
|
import { useLiveDeckFiles } from '../engine/liveReload';
|
|
@@ -23,63 +33,111 @@ import { PxArtEditor } from './PxArtEditor';
|
|
|
23
33
|
import { SceneEditor } from './SceneEditor';
|
|
24
34
|
import { StyleEditor } from './StyleEditor';
|
|
25
35
|
|
|
26
|
-
//
|
|
27
|
-
//
|
|
36
|
+
// Debounce per path on top of the SDK's save queue: this decides WHEN a change
|
|
37
|
+
// is worth writing (a drag shouldn't write every frame), the queue decides that
|
|
38
|
+
// it gets written at all -- it holds the newest text per path, retries, and
|
|
39
|
+
// flushes when the dev-server socket comes back. So a save that fails while the
|
|
40
|
+
// connection is down is no longer lost, it is late.
|
|
28
41
|
//
|
|
29
42
|
// `isWritable` decides what may be saved. Not `isImportedFile` directly: a file
|
|
30
43
|
// this deck has forked is under `imports/` and writable, and only the caller
|
|
31
44
|
// knows which those are.
|
|
32
45
|
function useFileSaver(isWritable) {
|
|
33
46
|
const timers = useRef({});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
// Text still waiting out its debounce, so it can be flushed early. Once
|
|
48
|
+
// handed to the queue a path leaves here and `hasPendingSave` tracks it.
|
|
49
|
+
const debounced = useRef({});
|
|
50
|
+
const [saveState, setSaveState] = useState({ pending: [], error: null });
|
|
51
|
+
|
|
52
|
+
const commitNow = useCallback((path) => {
|
|
53
|
+
const text = debounced.current[path];
|
|
54
|
+
if (text === undefined) return Promise.resolve();
|
|
55
|
+
delete debounced.current[path];
|
|
56
|
+
if (timers.current[path]) {
|
|
57
|
+
window.clearTimeout(timers.current[path]);
|
|
58
|
+
delete timers.current[path];
|
|
59
|
+
}
|
|
60
|
+
// Rejection here is the first attempt failing, not the save being dropped:
|
|
61
|
+
// the queue keeps it and retries. `saveState` is what says so on screen.
|
|
62
|
+
return writeFile(path, text).catch(() => undefined);
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
const flushAll = useCallback(
|
|
66
|
+
() => Promise.all(Object.keys(debounced.current).map(commitNow)).then(() => undefined),
|
|
67
|
+
[commitNow]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
function schedule(path, text) {
|
|
37
71
|
// Someone else's deck, and not forked here. The serve refuses these writes
|
|
38
72
|
// anyway; skip the request so a missed UI lock doesn't look like a save that
|
|
39
|
-
// failed.
|
|
40
|
-
if (!isWritable(path)) return Promise.resolve();
|
|
41
|
-
return writeFile(path, text)
|
|
42
|
-
.then(() => {
|
|
43
|
-
if (versions.current[path] === version && pending.current[path] === text) {
|
|
44
|
-
delete pending.current[path];
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
.catch((error) => {
|
|
48
|
-
if (versions.current[path] !== version) return;
|
|
49
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
50
|
-
console.error(`Failed to save ${path}: ${message}`);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function schedule(path, text) {
|
|
73
|
+
// failed. Guarding here is enough: nothing reaches the queue unscheduled.
|
|
54
74
|
if (!isWritable(path)) return;
|
|
55
|
-
|
|
56
|
-
versions.current[path] = version;
|
|
57
|
-
pending.current[path] = text;
|
|
75
|
+
debounced.current[path] = text;
|
|
58
76
|
if (timers.current[path]) window.clearTimeout(timers.current[path]);
|
|
59
77
|
// Short-ish debounce: writes now drive the live play/panel updates, so a
|
|
60
78
|
// drag should reflect soon after the user pauses.
|
|
61
79
|
timers.current[path] = window.setTimeout(() => {
|
|
62
80
|
delete timers.current[path];
|
|
63
|
-
void
|
|
81
|
+
void commitNow(path);
|
|
64
82
|
}, 800);
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
|
|
85
|
+
useEffect(() => onSaveState(setSaveState), []);
|
|
86
|
+
useEffect(() => onBeforeRestart(flushAll), [flushAll]);
|
|
87
|
+
// Leaving the tab -- switching apps, locking the phone -- is the case the
|
|
88
|
+
// debounce was never written for: up to 800ms of work sitting in a timer that
|
|
89
|
+
// is about to be frozen, in front of a connection that is about to drop. Hand
|
|
90
|
+
// it to the queue on the way out, while there is still a socket to write it.
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const onHidden = () => {
|
|
93
|
+
if (document.visibilityState === 'hidden') void flushAll();
|
|
94
|
+
};
|
|
95
|
+
const onPageHide = () => void flushAll();
|
|
96
|
+
document.addEventListener('visibilitychange', onHidden);
|
|
97
|
+
window.addEventListener('pagehide', onPageHide);
|
|
98
|
+
return () => {
|
|
99
|
+
document.removeEventListener('visibilitychange', onHidden);
|
|
100
|
+
window.removeEventListener('pagehide', onPageHide);
|
|
101
|
+
};
|
|
102
|
+
}, [flushAll]);
|
|
103
|
+
|
|
104
|
+
// Live-reload's echo skip: a path is "ours" from the keystroke until the serve
|
|
105
|
+
// has the text, which now spans the debounce AND however long the queue takes
|
|
106
|
+
// to land it. Without the second half, a retry that outlives one fs event
|
|
107
|
+
// would let a stale on-disk version overwrite what is on screen.
|
|
79
108
|
function hasPending(path) {
|
|
80
|
-
return
|
|
109
|
+
return debounced.current[path] !== undefined || hasPendingSave(path);
|
|
81
110
|
}
|
|
82
|
-
return { schedule, hasPending };
|
|
111
|
+
return { schedule, hasPending, saveState };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Shown only once a save has actually failed and is being retried -- a "saving"
|
|
115
|
+
// flicker on every drag would be noise, but silently showing edited-but-unsaved
|
|
116
|
+
// work as if it were saved is the bug this whole path exists to fix.
|
|
117
|
+
function UnsavedNotice({ saveState }) {
|
|
118
|
+
if (!saveState.error || saveState.pending.length === 0) return null;
|
|
119
|
+
const count = saveState.pending.length;
|
|
120
|
+
return (
|
|
121
|
+
<div
|
|
122
|
+
title={saveState.error}
|
|
123
|
+
style={{
|
|
124
|
+
position: 'absolute',
|
|
125
|
+
bottom: 12,
|
|
126
|
+
left: '50%',
|
|
127
|
+
transform: 'translateX(-50%)',
|
|
128
|
+
zIndex: 20,
|
|
129
|
+
padding: '6px 12px',
|
|
130
|
+
borderRadius: 999,
|
|
131
|
+
background: 'rgba(20, 20, 20, 0.92)',
|
|
132
|
+
border: '1px solid rgba(255, 190, 80, 0.5)',
|
|
133
|
+
color: '#ffd9a0',
|
|
134
|
+
fontSize: 12,
|
|
135
|
+
pointerEvents: 'none',
|
|
136
|
+
whiteSpace: 'nowrap',
|
|
137
|
+
}}>
|
|
138
|
+
{count === 1 ? '1 change not saved yet' : `${count} changes not saved yet`} — retrying…
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
83
141
|
}
|
|
84
142
|
|
|
85
143
|
// A file type whose declaring deck named an editor module: load that module and
|
|
@@ -151,7 +209,7 @@ export function SingleEditor({ path, editor, editorModule }) {
|
|
|
151
209
|
const forkedPaths = useForkedPaths();
|
|
152
210
|
const isWritable = (p) => !isImportedFile(p) || forkedPaths.has(p);
|
|
153
211
|
const readOnly = !isWritable(path);
|
|
154
|
-
const { schedule, hasPending } = useFileSaver(isWritable);
|
|
212
|
+
const { schedule, hasPending, saveState } = useFileSaver(isWritable);
|
|
155
213
|
// Live deck files; our own in-flight (debounced, unsaved) edits win over the
|
|
156
214
|
// fs echo of a stale write, so a drag in progress isn't clobbered.
|
|
157
215
|
const { files, setFiles, hydrated } = useLiveDeckFiles({ shouldSkipPath: hasPending, ensurePath: path });
|
|
@@ -229,8 +287,9 @@ export function SingleEditor({ path, editor, editorModule }) {
|
|
|
229
287
|
// No `else`: code/text files are handled by the builtin shell code editor, so
|
|
230
288
|
// the shell never routes them here. `body` stays null for any other kind.
|
|
231
289
|
return (
|
|
232
|
-
<div className={styles.panelBare}>
|
|
290
|
+
<div className={styles.panelBare} style={{ position: 'relative' }}>
|
|
233
291
|
<MainEditor>{body}</MainEditor>
|
|
292
|
+
<UnsavedNotice saveState={saveState} />
|
|
234
293
|
</div>
|
|
235
294
|
);
|
|
236
295
|
}
|
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
// design system by construction.
|
|
5
5
|
import React, { forwardRef, useEffect, useRef } from 'react';
|
|
6
6
|
import { onBeforeRestart, writeFile } from 'castle-web-sdk';
|
|
7
|
+
import * as castleSdk from 'castle-web-sdk';
|
|
8
|
+
|
|
9
|
+
// See the note in physics-2d's SingleEditor: a deck can take a kit update while
|
|
10
|
+
// keeping an older SDK, so anything newer than `writeFile` degrades instead of
|
|
11
|
+
// breaking the import.
|
|
12
|
+
const flushSaves = castleSdk.flushSaves ?? (() => Promise.resolve());
|
|
13
|
+
const hasPendingSave = castleSdk.hasPendingSave ?? (() => false);
|
|
7
14
|
import { Button, Icon, IconButton } from '@imports/castle.physics-2d/engine/ui';
|
|
8
15
|
|
|
9
16
|
// Custom glyphs for concepts the kit's icon set doesn't cover, drawn to match
|
|
@@ -71,33 +78,54 @@ const MODE_STYLE = {
|
|
|
71
78
|
zIndex: 5,
|
|
72
79
|
};
|
|
73
80
|
|
|
74
|
-
//
|
|
75
|
-
//
|
|
81
|
+
// Debounce per path on top of the SDK's save queue -- the same split as the
|
|
82
|
+
// imported kit's SingleEditor. This decides WHEN a change is worth writing; the
|
|
83
|
+
// queue decides that it gets written at all, holding the newest text per path,
|
|
84
|
+
// retrying, and surviving a reload.
|
|
76
85
|
export function useFileSaver3D() {
|
|
77
86
|
const pending = useRef({});
|
|
78
87
|
const timers = useRef({});
|
|
88
|
+
function commit(path) {
|
|
89
|
+
const value = pending.current[path];
|
|
90
|
+
if (value === undefined) return Promise.resolve();
|
|
91
|
+
delete pending.current[path];
|
|
92
|
+
if (timers.current[path]) {
|
|
93
|
+
window.clearTimeout(timers.current[path]);
|
|
94
|
+
delete timers.current[path];
|
|
95
|
+
}
|
|
96
|
+
// A rejection is the first attempt failing, not the write being dropped --
|
|
97
|
+
// the queue keeps it and retries.
|
|
98
|
+
return writeFile(path, value).catch(() => undefined);
|
|
99
|
+
}
|
|
79
100
|
function schedule(path, text) {
|
|
80
101
|
pending.current[path] = text;
|
|
81
102
|
if (timers.current[path]) window.clearTimeout(timers.current[path]);
|
|
82
|
-
timers.current[path] = window.setTimeout(() =>
|
|
83
|
-
delete timers.current[path];
|
|
84
|
-
const value = pending.current[path];
|
|
85
|
-
delete pending.current[path];
|
|
86
|
-
void writeFile(path, value).catch((error) => console.error(`save failed: ${error}`));
|
|
87
|
-
}, 500);
|
|
103
|
+
timers.current[path] = window.setTimeout(() => void commit(path), 500);
|
|
88
104
|
}
|
|
89
|
-
|
|
90
|
-
() =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
const flushAll = () =>
|
|
106
|
+
Promise.all(Object.keys(pending.current).map(commit)).then(() => flushSaves());
|
|
107
|
+
useEffect(() => onBeforeRestart(flushAll), []);
|
|
108
|
+
// Leaving the tab is the case a debounce was never written for: work sitting
|
|
109
|
+
// in a timer that is about to be frozen, over a connection about to drop.
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const onHidden = () => {
|
|
112
|
+
if (document.visibilityState === 'hidden') void flushAll();
|
|
113
|
+
};
|
|
114
|
+
const onPageHide = () => void flushAll();
|
|
115
|
+
document.addEventListener('visibilitychange', onHidden);
|
|
116
|
+
window.addEventListener('pagehide', onPageHide);
|
|
117
|
+
return () => {
|
|
118
|
+
document.removeEventListener('visibilitychange', onHidden);
|
|
119
|
+
window.removeEventListener('pagehide', onPageHide);
|
|
120
|
+
};
|
|
121
|
+
}, []);
|
|
122
|
+
// A path is "ours" from the keystroke until the serve has the text, which
|
|
123
|
+
// spans the debounce AND however long the queue takes to land it -- otherwise
|
|
124
|
+
// a retry outliving one fs event lets a stale on-disk version win.
|
|
125
|
+
return {
|
|
126
|
+
schedule,
|
|
127
|
+
hasPending: (path) => pending.current[path] !== undefined || hasPendingSave(path),
|
|
128
|
+
};
|
|
101
129
|
}
|
|
102
130
|
|
|
103
131
|
export function isEditableTarget(target) {
|