castle-web-cli 0.4.148 → 0.4.150

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.
Files changed (41) hide show
  1. package/dist/api.d.ts +14 -0
  2. package/dist/api.js +18 -0
  3. package/dist/castle-host/host.d.ts +17 -0
  4. package/dist/castle-host/host.js +58 -0
  5. package/dist/castleJson.d.ts +15 -0
  6. package/dist/castleJson.js +36 -0
  7. package/dist/devSessionChild.d.ts +1 -0
  8. package/dist/devSessionChild.js +129 -0
  9. package/dist/devSessionServer.d.ts +19 -0
  10. package/dist/devSessionServer.js +511 -0
  11. package/dist/index.js +8 -8
  12. package/dist/init.js +10 -2
  13. package/dist/list-decks.js +7 -6
  14. package/dist/preview.d.ts +1 -1
  15. package/dist/preview.js +4 -2
  16. package/dist/save-deck.js +63 -14
  17. package/dist/serve.js +269 -108
  18. package/dist/serveSecurity.d.ts +7 -1
  19. package/dist/serveSecurity.js +65 -16
  20. package/dist/serverBundle.d.ts +8 -0
  21. package/dist/serverBundle.js +82 -0
  22. package/dist/shell/assets/{index-CL9TuLXb.js → index-Dlhc3eZW.js} +42 -42
  23. package/dist/shell/assets/index-DwezawBs.css +1 -0
  24. package/dist/shell/index.html +2 -2
  25. package/kits/blank/castle.json +5 -2
  26. package/kits/physics-2d/behaviors/Collider.jsx +1 -2
  27. package/kits/physics-2d/behaviors/Joints.jsx +1 -1
  28. package/kits/physics-2d/castle.json +1 -1
  29. package/kits/physics-2d/editors/BlueprintLibrary.jsx +33 -3
  30. package/kits/physics-2d/editors/SceneEditor.jsx +319 -140
  31. package/kits/physics-2d/editors/SingleEditor.jsx +6 -0
  32. package/kits/physics-2d/engine/blueprint.js +106 -14
  33. package/kits/physics-2d/engine/scene.js +9 -2
  34. package/kits/physics-2d/engine/ui.jsx +30 -2
  35. package/kits/physics-2d/engine/ui.module.css +59 -0
  36. package/kits/physics-3d/castle.json +1 -1
  37. package/kits/physics-3d/engine3d/PxModelEditor.jsx +29 -13
  38. package/kits/physics-3d/engine3d/Scene3DEditor.jsx +26 -7
  39. package/kits/physics-3d/engine3d/editorChrome.jsx +26 -1
  40. package/package.json +1 -1
  41. package/dist/shell/assets/index-DN8HQBnW.css +0 -1
@@ -272,6 +272,12 @@ export function SingleEditor({ path, editor, editorModule }) {
272
272
  sprites={sprites}
273
273
  onChange={onChange}
274
274
  onChangeFile={onChangeFile}
275
+ readOnly={readOnly}
276
+ // `readOnly` answers for the open scene. The blueprint inspector edits a
277
+ // DIFFERENT file, whose answer can differ either way: an import's scene
278
+ // can show a blueprint of your own, and your scene can show one of
279
+ // theirs.
280
+ isWritable={isWritable}
275
281
  selectedActorIds={selectedActorIds}
276
282
  onSelectActorIds={setSelectedActorIds}
277
283
  multiSelectMode={multiSelectMode}
@@ -6,7 +6,7 @@
6
6
  // panel propagates to every scene that places it. Shared by the runtime
7
7
  // (`scene.js`, so play mode and `PlayOnly` resolve blueprints too) and the
8
8
  // editors (which also mint/fork/migrate/cascade-delete blueprint files).
9
- import { resolveDeckFile } from 'castle-web-sdk';
9
+ import { deckPrefixOf, IMPORTS_DIR, IMPORTS_PREFIX, resolveDeckFile } from 'castle-web-sdk';
10
10
  import { formatJson } from './files';
11
11
  import { DEFAULT_RESOLUTION, TRANSPARENT, serializeCompact } from './pxart';
12
12
  import { cardSize, dedupeActorId } from './scene';
@@ -29,6 +29,15 @@ export function isImportedPath(path) {
29
29
  return typeof path === 'string' && path.startsWith('imports/');
30
30
  }
31
31
 
32
+ // Which import owns a file, by the alias it was installed under:
33
+ // `imports/castle.physics-2d/blueprints/ball.scene` -> `castle.physics-2d`.
34
+ // Null for a file of this deck's own. For naming the source in the UI, so takes
35
+ // a whole-deck key rather than a ref.
36
+ export function importAliasOf(path) {
37
+ const prefix = deckPrefixOf(path ?? '');
38
+ return prefix ? prefix.slice(IMPORTS_DIR.length + 1, -1) : null;
39
+ }
40
+
32
41
  // Per-property inherit metadata for a behavior prop. Behaviors opt a prop out
33
42
  // of inheritance via `static propertyMeta = { propName: { inherit: false } }`
34
43
  // (see behaviors/Layout.jsx for x/y/rotation); anything absent defaults to
@@ -90,6 +99,40 @@ function resolveRefsIn(props, files, fromPath) {
90
99
  }
91
100
  }
92
101
 
102
+ // The inverse, for the write side. A resolved key is a fact about the whole
103
+ // deck; a stored ref is relative to the file holding it. So components moving
104
+ // INTO `toPath` have to be restated from there, or they name a different file
105
+ // -- or none -- the next time anything reads them.
106
+ //
107
+ // Same traversal and the same duck-typing guard as the read: only a string that
108
+ // names a real file is a ref. That guard bites harder here (a false positive
109
+ // persists rather than dirtying an object), but the two sides have to agree on
110
+ // what a ref is, and this is all either of them has to go on.
111
+ function reprojectRefsIn(props, files, toPath) {
112
+ for (const [key, value] of Object.entries(props ?? {})) {
113
+ if (typeof value === 'string' && value) {
114
+ if (files?.[value] === undefined) continue;
115
+ const ref = refFor(value, toPath);
116
+ if (ref !== value) props[key] = ref;
117
+ } else if (value && typeof value === 'object' && !Array.isArray(value)) {
118
+ reprojectRefsIn(value, files, toPath);
119
+ }
120
+ }
121
+ }
122
+
123
+ // A files-map key as a file at `toPath` has to write it: relative when the key
124
+ // is in that file's own deck, `@imports/...` when it is in another's. Left
125
+ // alone otherwise -- including a key already written relative, which is why
126
+ // this is safe on components that were never resolved.
127
+ function refFor(key, toPath) {
128
+ const prefix = deckPrefixOf(toPath);
129
+ if (prefix && key.startsWith(prefix)) return key.slice(prefix.length);
130
+ if (key.startsWith(`${IMPORTS_DIR}/`)) {
131
+ return `${IMPORTS_PREFIX}${key.slice(IMPORTS_DIR.length + 1)}`;
132
+ }
133
+ return key;
134
+ }
135
+
93
136
  // Resolve a blueprint's template from the LIVE files map -- the load-bearing
94
137
  // call for live propagation. Returns null when the file is missing, deleted,
95
138
  // or malformed (a dangling `blueprint` ref degrades to "no template" rather
@@ -292,7 +335,13 @@ export function setBlueprintTemplateComponents(files, blueprintPath, components)
292
335
  return null;
293
336
  }
294
337
  if (!data?.actors?.[0]) return null;
295
- data.actors[0].components = components;
338
+ // Callers hand back what they read, and reads resolve (`resolveTemplateRefs`).
339
+ // Storing that verbatim is only harmless for a blueprint of this deck's own,
340
+ // where resolving was the identity; inside an import it puts a whole-deck key
341
+ // where a ref belongs. Cloned first -- the caller's object is the caller's.
342
+ const next = structuredClone(components);
343
+ for (const props of Object.values(next ?? {})) reprojectRefsIn(props, files, blueprintPath);
344
+ data.actors[0].components = next;
296
345
  return formatJson(data);
297
346
  }
298
347
 
@@ -304,12 +353,21 @@ export function mintBlueprintFile(files, components) {
304
353
  const existing = listBlueprints(files);
305
354
  const name = mintBlueprintName(existing.map((blueprint) => blueprint.name));
306
355
  const path = mintBlueprintPath(existing.map((blueprint) => blueprint.path));
307
- return { path, name, text: formatBlueprintFileText(name, components) };
356
+ // The components may describe a file this one is not: new-blueprint-from-actor
357
+ // hands over an import's template, merged, and merging read it -- so its refs
358
+ // are whole-deck keys. Restate them from `path` before they are written, the
359
+ // same as any other write. Callers minting their own deck-root components pass
360
+ // through untouched, and so does a ref to a file being minted alongside this
361
+ // one, which is not in `files` to be recognised yet.
362
+ const next = structuredClone(components);
363
+ for (const props of Object.values(next ?? {})) reprojectRefsIn(props, files, path);
364
+ return { path, name, text: formatBlueprintFileText(name, next) };
308
365
  }
309
366
 
310
367
  // Split a resolved component's props into { inherited, overridden } by each
311
- // prop's propertyMeta. Used by migration and fork to decide what belongs in a
312
- // new blueprint template vs. what must stay an explicit instance value.
368
+ // prop's propertyMeta. Used by migration and by new-blueprint-from-actor to
369
+ // decide what belongs in a new blueprint template vs. what must stay an
370
+ // explicit instance value.
313
371
  function splitByInherit(Behavior, props) {
314
372
  const inherited = {};
315
373
  const overridden = {};
@@ -587,7 +645,11 @@ export function placeBlueprintInstance(sceneData, files, blueprintPath, position
587
645
  // Reparent the instance to the new blueprint, keeping only its non-inherited
588
646
  // prop values (Layout position et al) as instance overrides -- everything
589
647
  // else now matches the new template exactly, so no override is needed for it.
590
- export function forkActorToBlueprint(files, behaviors, sceneData, actorId) {
648
+ //
649
+ // Additive and local: a NEW file, and only the one actor follows it. Not to be
650
+ // confused with forking, which is a file operation on somebody else's file --
651
+ // same path, this deck's bytes, and every instance in the deck follows.
652
+ export function newBlueprintFromActor(files, behaviors, sceneData, actorId) {
591
653
  const next = structuredClone(sceneData);
592
654
  const actor = next.actors?.find((candidate) => candidate.id === actorId);
593
655
  if (!actor) return null;
@@ -633,13 +695,38 @@ function parseSceneFiles(files) {
633
695
  return out;
634
696
  }
635
697
 
636
- // Every `scenes/*.scene` file's actor count referencing a blueprint, for the
637
- // delete-confirm dialog and the library's per-blueprint badge.
638
- export function countBlueprintInstances(files, blueprintPath) {
698
+ // Whether an actor is an instance of the blueprint at whole-deck key
699
+ // `blueprintPath`. An actor's `blueprint` is a ref as WRITTEN in the scene at
700
+ // `fromPath`, so the two are not comparable as strings: an instance of an
701
+ // import's blueprint placed in this deck says `@imports/<alias>/...` and matches
702
+ // no key at all, and an actor in the import's OWN scene says a bare
703
+ // `blueprints/ball.scene` that matches this deck's same-named blueprint instead.
704
+ export function actorUsesBlueprint(actor, blueprintPath, fromPath) {
705
+ if (!actor?.blueprint || !blueprintPath) return false;
706
+ return resolveDeckFile(actor.blueprint, fromPath) === blueprintPath;
707
+ }
708
+
709
+ // How many placed actors reference a blueprint. The deck's own `scenes/` by
710
+ // default, which is what the delete-confirm needs: it promises how many actors
711
+ // a delete removes, and the cascade only rewrites this deck's files.
712
+ //
713
+ // `alsoScenePath` adds one more scene to the scan, for the inspector's badge.
714
+ // The open scene can belong to an import, and a badge reading "0 actors" over a
715
+ // scene visibly full of them is just wrong -- even though none of those actors
716
+ // is this deck's to delete.
717
+ export function countBlueprintInstances(files, blueprintPath, alsoScenePath) {
718
+ const scenes = parseSceneFiles(files);
719
+ if (alsoScenePath && !scenes.some((scene) => scene.path === alsoScenePath)) {
720
+ try {
721
+ scenes.push({ path: alsoScenePath, data: JSON.parse(files?.[alsoScenePath] ?? '') });
722
+ } catch {
723
+ // Mid-edit invalid JSON just doesn't count, as in `parseSceneFiles`.
724
+ }
725
+ }
639
726
  let count = 0;
640
- for (const { data } of parseSceneFiles(files)) {
727
+ for (const { path, data } of scenes) {
641
728
  for (const actor of data?.actors ?? []) {
642
- if (actor?.blueprint === blueprintPath) count += 1;
729
+ if (actorUsesBlueprint(actor, blueprintPath, path)) count += 1;
643
730
  }
644
731
  }
645
732
  return count;
@@ -655,7 +742,7 @@ export function cascadeDeleteBlueprint(files, blueprintPath) {
655
742
  const writes = [];
656
743
  for (const { path, data } of parseSceneFiles(files)) {
657
744
  const actors = data.actors ?? [];
658
- const filtered = actors.filter((actor) => actor?.blueprint !== blueprintPath);
745
+ const filtered = actors.filter((actor) => !actorUsesBlueprint(actor, blueprintPath, path));
659
746
  if (filtered.length !== actors.length) {
660
747
  writes.push({ path, text: formatJson({ ...data, actors: filtered }) });
661
748
  }
@@ -738,9 +825,14 @@ export function renameBlueprintCascade(files, blueprintPath, nextName) {
738
825
  const writes = [{ path: nextPath, text: formatBlueprintFileText(name, components) }];
739
826
  for (const { path, data } of parseSceneFiles(files)) {
740
827
  const actors = data.actors ?? [];
741
- if (!actors.some((actor) => actor?.blueprint === blueprintPath)) continue;
828
+ if (!actors.some((actor) => actorUsesBlueprint(actor, blueprintPath, path))) continue;
829
+ // `nextPath` is a whole-deck key and an actor's `blueprint` is a ref, so it
830
+ // has to be restated from the scene that will hold it -- the same as any
831
+ // other ref being written (`reprojectRefsIn`).
742
832
  const rewritten = actors.map((actor) =>
743
- actor?.blueprint === blueprintPath ? { ...actor, blueprint: nextPath } : actor
833
+ actorUsesBlueprint(actor, blueprintPath, path)
834
+ ? { ...actor, blueprint: refFor(nextPath, path) }
835
+ : actor
744
836
  );
745
837
  writes.push({ path, text: formatJson({ ...data, actors: rewritten }) });
746
838
  }
@@ -1,6 +1,6 @@
1
1
  import { resolveDeckFile } from 'castle-web-sdk';
2
2
  import { initialFiles, parseJsonFile } from './files';
3
- import { getBlueprintTemplate, mergeComponents } from './blueprint';
3
+ import { actorUsesBlueprint, getBlueprintTemplate, mergeComponents } from './blueprint';
4
4
  import { getColliderRect, intersects, spriteIsEmpty } from './collider';
5
5
  import { systemInstallers } from './systemRegistry';
6
6
 
@@ -156,6 +156,13 @@ export class SceneRuntime {
156
156
  return this.actors.get(actorId);
157
157
  }
158
158
 
159
+ // `actorUsesBlueprint` against this scene's own path. Behaviors get the scene
160
+ // handed to `draw`, so this is how they answer "is the hotbar's selection mine"
161
+ // without having to know where the scene lives.
162
+ usesBlueprint(actor, blueprintPath) {
163
+ return actorUsesBlueprint(actor, blueprintPath, this.scenePath);
164
+ }
165
+
159
166
  getActors() {
160
167
  return [...this.actors.values()].sort((a, b) => {
161
168
  const az = getLayout(a)?.z ?? 0;
@@ -417,7 +424,7 @@ export class SceneRuntime {
417
424
  // Per-actor transform: Layout's `rotation` (degrees) rotates every draw
418
425
  // behavior of the actor about its center.
419
426
  ctx.save();
420
- if (dimBlueprintPath && actor.blueprint !== dimBlueprintPath) {
427
+ if (dimBlueprintPath && !this.usesBlueprint(actor, dimBlueprintPath)) {
421
428
  ctx.globalAlpha = 0.2;
422
429
  }
423
430
  applyLayoutRotation(ctx, getLayout(actor));
@@ -231,6 +231,13 @@ const icons = {
231
231
  clone: faClone,
232
232
  code: faCode,
233
233
  // FA5 has no faCodeFork (that's the FA6 name); faCodeBranch is the fork glyph.
234
+ //
235
+ // Reserved for forking a FILE -- taking this deck's own version of one an
236
+ // import owns -- which is what it means in the shell's file tree and editor
237
+ // banner too. Nothing in this kit draws it since the actor action became
238
+ // `clone`; kept because a deck or a kit pinned to an older physics-2d may
239
+ // still ask for it by name, and an unused entry costs less than a missing
240
+ // glyph on somebody else's screen.
234
241
  'code-fork': faCodeBranch,
235
242
  'dot-circle': faDotCircle,
236
243
  'draw-polygon': faDrawPolygon,
@@ -316,6 +323,10 @@ export function BehaviorPanel({
316
323
  enabled = true,
317
324
  onToggleEnabled = null,
318
325
  dragging = false,
326
+ // The inspected file can't be written. Only the panel's BODY is blocked: the
327
+ // header's collapse and drag, and the View source link, read rather than
328
+ // write, and are most of what a file you can't edit is still good for.
329
+ readOnly = false,
319
330
  children,
320
331
  }) {
321
332
  const value = React.useMemo(
@@ -329,8 +340,20 @@ export function BehaviorPanel({
329
340
  enabled,
330
341
  onToggleEnabled,
331
342
  dragging,
343
+ readOnly,
332
344
  }),
333
- [summary, collapsed, onToggle, handleProps, onViewSource, onRemove, enabled, onToggleEnabled, dragging]
345
+ [
346
+ summary,
347
+ collapsed,
348
+ onToggle,
349
+ handleProps,
350
+ onViewSource,
351
+ onRemove,
352
+ enabled,
353
+ onToggleEnabled,
354
+ dragging,
355
+ readOnly,
356
+ ]
334
357
  );
335
358
  return <BehaviorPanelContext.Provider value={value}>{children}</BehaviorPanelContext.Provider>;
336
359
  }
@@ -431,7 +454,12 @@ export function Panel({ title, action, children, overridden = false }) {
431
454
  </div>
432
455
  )}
433
456
  {collapsed ? null : (
434
- <div className={cx(styles.panelBody, behavior?.enabled === false && styles.panelBodyOff)}>
457
+ <div
458
+ className={cx(
459
+ styles.panelBody,
460
+ behavior?.enabled === false && styles.panelBodyOff,
461
+ behavior?.readOnly && styles.inspectorFieldsLocked
462
+ )}>
435
463
  {children}
436
464
  </div>
437
465
  )}
@@ -1045,6 +1045,65 @@
1045
1045
  background: var(--castle-inspector-input-bg);
1046
1046
  }
1047
1047
 
1048
+ /* An import's blueprint: still selectable so the name can be read and copied,
1049
+ but the hover and focus borders would offer an edit that won't be taken. */
1050
+ .blueprintNameInputLocked,
1051
+ .blueprintNameInputLocked:hover,
1052
+ .blueprintNameInputLocked:focus {
1053
+ border-color: transparent;
1054
+ background: transparent;
1055
+ color: var(--castle-text-dim);
1056
+ cursor: default;
1057
+ }
1058
+
1059
+ /* Whose blueprint this is, above the inspector when the hotbar's selection
1060
+ belongs to an import. The shell's editor banner describes the OPEN file, so
1061
+ it says nothing about a blueprint selected inside a scene; this fills that
1062
+ gap and uses the same wording. The column is narrow, so the text ellipsizes
1063
+ and the full path is on the title attribute. */
1064
+ .blueprintProvenance {
1065
+ display: flex;
1066
+ align-items: center;
1067
+ gap: 6px;
1068
+ padding: 8px;
1069
+ border-bottom: 1px solid var(--castle-inspector-divider);
1070
+ background: var(--castle-inspector-bg);
1071
+ color: var(--castle-text-dim);
1072
+ font-size: 12px;
1073
+ }
1074
+
1075
+ .blueprintProvenanceChip {
1076
+ flex: 0 0 auto;
1077
+ padding: 2px 8px;
1078
+ border: 1px solid var(--castle-inspector-divider);
1079
+ border-radius: 999px;
1080
+ background: var(--castle-workspace-bg);
1081
+ letter-spacing: 0.02em;
1082
+ line-height: 1.4;
1083
+ }
1084
+
1085
+ /* A forked blueprint is editable, so its chip should not read like the locked
1086
+ one -- same distinction the shell's banner makes. */
1087
+ .blueprintProvenanceForked {
1088
+ color: var(--castle-inspector-text);
1089
+ }
1090
+
1091
+ .blueprintProvenanceText {
1092
+ min-width: 0;
1093
+ overflow: hidden;
1094
+ text-overflow: ellipsis;
1095
+ white-space: nowrap;
1096
+ }
1097
+
1098
+ /* A behavior panel's fields when the inspected file can't be written -- an
1099
+ import's blueprint. Just the fields: the panel header keeps View source and
1100
+ its collapse toggle, which read rather than write. Same treatment the pxart
1101
+ editor gives its read-only panels (.drawingReadOnly). */
1102
+ .inspectorFieldsLocked {
1103
+ opacity: 0.45;
1104
+ pointer-events: none;
1105
+ }
1106
+
1048
1107
  .stageWrap {
1049
1108
  grid-column: 1;
1050
1109
  grid-row: 2;
@@ -72,5 +72,5 @@
72
72
  "autoUpdateWhenImported": true,
73
73
  "deckId": "JH0SclbPVP0y",
74
74
  "cardId": "eXfAaUdbSU5A",
75
- "publishedVersion": "2026-08-27T18:04:56.551Z"
75
+ "publishedVersion": "2026-08-27T19:43:40.084Z"
76
76
  }
@@ -30,6 +30,7 @@ import {
30
30
  HotbarButton,
31
31
  StageCanvas,
32
32
  StageControls,
33
+ isViewerOnly,
33
34
  useEditorShortcuts,
34
35
  useFileSaver3D,
35
36
  } from './editorChrome';
@@ -234,9 +235,11 @@ export function PxModelEditor({ path }) {
234
235
  });
235
236
  };
236
237
 
238
+ const readOnly = isViewerOnly();
237
239
  useEditorShortcuts({
238
240
  history,
239
241
  setMode,
242
+ readOnly,
240
243
  onDuplicate: meshEdit ? undefined : duplicatePart,
241
244
  onDelete: meshEdit ? undefined : deletePart,
242
245
  onEscape: () => (meshEdit ? exitMeshEdit() : setSelectedPartId(null)),
@@ -276,6 +279,21 @@ export function PxModelEditor({ path }) {
276
279
  );
277
280
  }
278
281
 
282
+ // Hoisted so the hotbar markup reads flat (and jscpd stops seeing the two
283
+ // editors' identical scaffolding as one clone).
284
+ const addPartButtons = readOnly
285
+ ? null
286
+ : KIND_OPTIONS.map((option) => (
287
+ <HotbarButton
288
+ key={option.value}
289
+ icon={option.icon}
290
+ glyph={option.glyph}
291
+ label={option.label}
292
+ title={`Add a ${option.label.toLowerCase()} part`}
293
+ onClick={() => addPart(option.value)}
294
+ />
295
+ ));
296
+
279
297
  return (
280
298
  <div className={styles.panelBare}>
281
299
  <MainEditor>
@@ -283,21 +301,12 @@ export function PxModelEditor({ path }) {
283
301
  <div className={styles.sceneWorkspace}>
284
302
  <div className={styles.sceneTools}>
285
303
  <div className={styles.bpHotbar}>
286
- {KIND_OPTIONS.map((option) => (
287
- <HotbarButton
288
- key={option.value}
289
- icon={option.icon}
290
- glyph={option.glyph}
291
- label={option.label}
292
- title={`Add a ${option.label.toLowerCase()} part`}
293
- onClick={() => addPart(option.value)}
294
- />
295
- ))}
304
+ {addPartButtons}
296
305
  <span style={{ width: 10 }} />
297
- {selectedPart?.kind === 'box' && !meshEdit ? (
306
+ {selectedPart?.kind === 'box' && !meshEdit && !readOnly ? (
298
307
  <HotbarButton icon="object-group" label="To mesh" onClick={convertToMesh} />
299
308
  ) : null}
300
- {selectedPart?.kind === 'mesh' && !meshEdit ? (
309
+ {selectedPart?.kind === 'mesh' && !meshEdit && !readOnly ? (
301
310
  <HotbarButton icon="pencil" label="Edit mesh" onClick={enterMeshEdit} />
302
311
  ) : null}
303
312
  {meshEdit ? (
@@ -345,12 +354,14 @@ export function PxModelEditor({ path }) {
345
354
  history={history}
346
355
  mode={mode}
347
356
  setMode={setMode}
357
+ readOnly={readOnly}
348
358
  onDuplicate={duplicatePart}
349
359
  onDelete={deletePart}
350
360
  actionsDisabled={!selectedPartId}
351
361
  />
352
362
  </div>
353
363
  <ModelInspectorPane
364
+ readOnly={readOnly}
354
365
  model={model}
355
366
  selectedPartId={selectedPartId}
356
367
  onSelectPart={setSelectedPartId}
@@ -571,6 +582,7 @@ function ModelInspectorPane({
571
582
  onSelectPart,
572
583
  commitModel,
573
584
  setSelectedPartId,
585
+ readOnly = false,
574
586
  }) {
575
587
  const sheet = useMobileSheet({
576
588
  open: true,
@@ -591,7 +603,11 @@ function ModelInspectorPane({
591
603
  <div {...sheet.grabProps}>
592
604
  <SheetGrabHandle />
593
605
  </div>
594
- <div className={cx(styles.sheetBody, styles.inspectorBody)}>
606
+ <div
607
+ className={cx(styles.sheetBody, styles.inspectorBody)}
608
+ // The shared ui primitives have no disabled mode yet; the saver already
609
+ // refuses writes, this keeps the controls from looking live.
610
+ style={readOnly ? { pointerEvents: 'none', opacity: 0.75 } : undefined}>
595
611
  <Panel title="Model">
596
612
  <TextField
597
613
  label="Name"
@@ -59,11 +59,20 @@ import {
59
59
  initialBehaviorProps,
60
60
  } from './editor3dInspector';
61
61
  import { THUMB_PREFIX, thumbArtFor, withThumbRef } from './thumbnails';
62
- import { StageCanvas, StageControls, useEditorShortcuts, useFileSaver3D } from './editorChrome';
62
+ import {
63
+ StageCanvas,
64
+ StageControls,
65
+ isViewerOnly,
66
+ useEditorShortcuts,
67
+ useFileSaver3D,
68
+ } from './editorChrome';
63
69
 
64
70
  export function Scene3DEditor({ path }) {
65
71
  const stashKey = `scene3d-editor:${path}`;
66
72
  const [stash] = useState(() => takeReloadState(stashKey));
73
+ // The saver is already guarded; this flag is for the affordances, so the
74
+ // editor doesn't LOOK writable while nothing saves.
75
+ const readOnly = isViewerOnly();
67
76
  const saver = useFileSaver3D();
68
77
  const { files, setFiles, dataVersion, hydrated } = useLiveDeckFiles3D({
69
78
  shouldSkipPath: saver.hasPending,
@@ -133,7 +142,7 @@ export function Scene3DEditor({ path }) {
133
142
  onSelectActorIds([hits[next]]);
134
143
  },
135
144
  onCommitTransforms: (changes) => {
136
- if (!sceneData) return;
145
+ if (readOnly || !sceneData) return;
137
146
  const next = structuredClone(sceneData);
138
147
  for (const change of changes) {
139
148
  const actor = next.actors?.find((candidate) => candidate.id === change.id);
@@ -201,6 +210,7 @@ export function Scene3DEditor({ path }) {
201
210
  useEditorShortcuts({
202
211
  history,
203
212
  setMode,
213
+ readOnly,
204
214
  onDuplicate: actions.duplicateSelection,
205
215
  onDelete: actions.deleteSelection,
206
216
  onEscape: () => onSelectActorIds([]),
@@ -332,9 +342,9 @@ export function Scene3DEditor({ path }) {
332
342
  selectedBlueprintPath={selectedBlueprintPath}
333
343
  instanceBlueprintPath={rawSelectedActor?.blueprint ?? null}
334
344
  onSelectBlueprint={onSelectBlueprint}
335
- onAddActor={onAddActor}
336
- dragPlace={dragPlace}
337
- onDeleteBlueprint={onDeleteBlueprint}
345
+ onAddActor={readOnly ? undefined : onAddActor}
346
+ dragPlace={readOnly ? undefined : dragPlace}
347
+ onDeleteBlueprint={readOnly ? undefined : onDeleteBlueprint}
338
348
  />
339
349
  )}
340
350
  </div>
@@ -344,12 +354,14 @@ export function Scene3DEditor({ path }) {
344
354
  history={history}
345
355
  mode={mode}
346
356
  setMode={setMode}
357
+ readOnly={readOnly}
347
358
  onDuplicate={isBlueprintFile ? undefined : actions.duplicateSelection}
348
359
  onDelete={isBlueprintFile ? undefined : actions.deleteSelection}
349
360
  actionsDisabled={selectedActorIds.length === 0}
350
361
  />
351
362
  </div>
352
363
  <InspectorPane
364
+ readOnly={readOnly}
353
365
  hotbarBlueprint={
354
366
  hotbarBlueprint ? withThumbRef(hotbarBlueprint, selectedBlueprintPath) : null
355
367
  }
@@ -549,6 +561,7 @@ function InspectorPane(props) {
549
561
  storageKey: 'scene3d-inspector',
550
562
  });
551
563
  const {
564
+ readOnly,
552
565
  hotbarBlueprint,
553
566
  selectedBlueprintPath,
554
567
  blueprintActions,
@@ -596,7 +609,7 @@ function InspectorPane(props) {
596
609
  blueprintTemplate={selectedBlueprintTemplate}
597
610
  sprites={sprites}
598
611
  files={files}
599
- showAddBehavior={isBlueprintFile}
612
+ showAddBehavior={isBlueprintFile && !readOnly}
600
613
  onSetComponent={actions.updateComponent}
601
614
  onAddBehavior={actions.addBehavior}
602
615
  onRemoveBehavior={actions.removeBehavior}
@@ -623,7 +636,13 @@ function InspectorPane(props) {
623
636
  <div {...inspectorSheet.grabProps}>
624
637
  <SheetGrabHandle />
625
638
  </div>
626
- <div className={cx(styles.sheetBody, styles.inspectorBody)}>{body}</div>
639
+ <div
640
+ className={cx(styles.sheetBody, styles.inspectorBody)}
641
+ // The shared ui primitives have no disabled mode yet; the saver already
642
+ // refuses writes, this keeps the controls from looking live.
643
+ style={readOnly ? { pointerEvents: 'none', opacity: 0.75 } : undefined}>
644
+ {body}
645
+ </div>
627
646
  </aside>
628
647
  );
629
648
  }
@@ -82,6 +82,10 @@ const MODE_STYLE = {
82
82
  // imported kit's SingleEditor. This decides WHEN a change is worth writing; the
83
83
  // queue decides that it gets written at all, holding the newest text per path,
84
84
  // retrying, and surviving a reload.
85
+ // Same flag the imported kit's SingleEditor reads: the host page (view source)
86
+ // says the whole deck is read-only.
87
+ export const isViewerOnly = () => typeof window !== 'undefined' && window.__castleReadOnly === true;
88
+
85
89
  export function useFileSaver3D() {
86
90
  const pending = useRef({});
87
91
  const timers = useRef({});
@@ -98,6 +102,10 @@ export function useFileSaver3D() {
98
102
  return writeFile(path, value).catch(() => undefined);
99
103
  }
100
104
  function schedule(path, text) {
105
+ // A read-only host refuses these writes anyway; skip the request so a
106
+ // missed UI lock doesn't look like a save that failed. Guarding here is
107
+ // enough: nothing reaches the queue unscheduled.
108
+ if (isViewerOnly()) return;
101
109
  pending.current[path] = text;
102
110
  if (timers.current[path]) window.clearTimeout(timers.current[path]);
103
111
  timers.current[path] = window.setTimeout(() => void commit(path), 500);
@@ -147,6 +155,11 @@ export function useEditorShortcuts(handlers) {
147
155
  const onKeyDown = (event) => {
148
156
  if (isEditableTarget(event.target)) return;
149
157
  const h = latest.current;
158
+ if (h.readOnly) {
159
+ if (event.key === 'Escape') h.onEscape?.();
160
+ else if (event.key === '1') h.setMode('select');
161
+ return;
162
+ }
150
163
  const meta = event.metaKey || event.ctrlKey;
151
164
  if (meta && event.key.toLowerCase() === 'z') {
152
165
  event.preventDefault();
@@ -189,7 +202,15 @@ export const StageCanvas = forwardRef(function StageCanvas(props, ref) {
189
202
 
190
203
  // Undo/redo top-left; select/move/rotate (plus duplicate/delete when handlers
191
204
  // are given) down the right edge.
192
- export function StageControls({ history, mode, setMode, onDuplicate, onDelete, actionsDisabled }) {
205
+ export function StageControls({
206
+ history,
207
+ mode,
208
+ setMode,
209
+ onDuplicate,
210
+ onDelete,
211
+ actionsDisabled,
212
+ readOnly = false,
213
+ }) {
193
214
  const modeButton = (value, icon, label) => (
194
215
  <IconButton
195
216
  icon={icon}
@@ -199,6 +220,10 @@ export function StageControls({ history, mode, setMode, onDuplicate, onDelete, a
199
220
  onClick={() => setMode(value)}
200
221
  />
201
222
  );
223
+ // Selection stays (inspecting needs it); everything that mutates goes.
224
+ if (readOnly) {
225
+ return <div style={MODE_STYLE}>{modeButton('select', 'marquee', 'Select (1)')}</div>;
226
+ }
202
227
  return (
203
228
  <>
204
229
  <div style={UNDO_STYLE}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.148",
3
+ "version": "0.4.150",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "castle-web": "./dist/index.js"