@zylem/editor 0.6.7 → 0.6.9

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.
@@ -1,5 +1,7 @@
1
1
  import { Component } from 'solid-js';
2
2
  import { LucideProps } from 'lucide-solid';
3
+ import * as _zylem_bridge from '@zylem/bridge';
4
+ import { BridgeDebugTool } from '@zylem/bridge';
3
5
 
4
6
  type EditorLauncherMode = 'floating' | 'hidden';
5
7
 
@@ -68,6 +70,8 @@ declare class ZylemEditorElement extends HTMLElement {
68
70
  private _config;
69
71
  private _initialized;
70
72
  private controller;
73
+ /** Releases this element's bridge subscription (reference-counted). */
74
+ private releaseBridge;
71
75
  constructor();
72
76
  /**
73
77
  * Set configuration for the editor.
@@ -93,6 +97,7 @@ declare class ZylemEditorElement extends HTMLElement {
93
97
  */
94
98
  reinitialize(): void;
95
99
  disconnectedCallback(): void;
100
+ private teardown;
96
101
  }
97
102
  /**
98
103
  * Register the ZylemEditorElement as a custom element.
@@ -164,53 +169,11 @@ declare class EditorEventBusWrapper {
164
169
  */
165
170
  declare const editorEvents: EditorEventBusWrapper;
166
171
 
167
- /**
168
- * Editor Events Module
169
- *
170
- * Bidirectional window CustomEvents for communication between @zylem/editor and consuming apps.
171
- *
172
- * EDITOR_STATE_DISPATCH: Editor sends state changes → external apps listen
173
- * EDITOR_STATE_RECEIVE: External apps send updates → editor listens
174
- */
175
- /**
176
- * Payload structure for editor state events.
177
- * Matches the nested state structure for both directions.
178
- */
179
- interface EditorUpdatePayload {
180
- gameState?: {
181
- debugFlag?: boolean;
182
- [key: string]: unknown;
183
- };
184
- toolbarState?: {
185
- tool?: 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'none';
186
- paused?: boolean;
187
- };
188
- [key: string]: unknown;
189
- }
190
- /**
191
- * Event name constants
192
- */
193
- declare const EDITOR_STATE_DISPATCH = "editor-state-dispatch";
194
- declare const EDITOR_STATE_RECEIVE = "editor-state-receive";
195
- declare const EDITOR_UPDATE_EVENT = "editor-state-dispatch";
196
- /**
197
- * Dispatch state changes from the editor to external consumers.
198
- *
199
- * @param payload - The state update payload
200
- *
201
- * @example
202
- * ```ts
203
- * // From GameSection when debug checkbox changes
204
- * dispatchEditorUpdate({ gameState: { debugFlag: true } });
205
- * ```
206
- */
207
- declare function dispatchEditorUpdate(payload: EditorUpdatePayload): void;
208
-
209
172
  /**
210
173
  * Entities state for the entities section.
211
174
  * Manages debug state and entity selection/hover.
212
175
  */
213
- type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'none';
176
+ type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'add' | 'none';
214
177
  interface DebugState {
215
178
  paused: boolean;
216
179
  tool: DebugTools;
@@ -256,10 +219,20 @@ interface Vector3Like {
256
219
  interface BaseEntityInterface {
257
220
  uuid: string;
258
221
  name: string;
259
- type?: string;
260
- position?: Vector3Like;
261
- rotation?: Vector3Like;
262
- scale?: Vector3Like;
222
+ type?: string | undefined;
223
+ position?: Vector3Like | undefined;
224
+ rotation?: Vector3Like | undefined;
225
+ scale?: Vector3Like | undefined;
226
+ /**
227
+ * World-space AABB size for thumbnail rulers. Preview images themselves
228
+ * live in the thumbnail side-channel store, keyed by uuid, so entity state
229
+ * stays small enough to diff cheaply.
230
+ */
231
+ bounds?: {
232
+ width: number;
233
+ height: number;
234
+ depth: number;
235
+ } | undefined;
263
236
  }
264
237
  interface StageConfigState {
265
238
  id: string;
@@ -318,36 +291,93 @@ declare const debugStore: {
318
291
  dropTargetIndex: number | null;
319
292
  };
320
293
 
294
+ declare const channel: _zylem_bridge.BridgeChannel;
295
+ /**
296
+ * Subscribe the editor stores to game→editor bridge messages and hydrate
297
+ * from the channel's retained state.
298
+ *
299
+ * Reference-counted: the game gates expensive editor-only work (thumbnails,
300
+ * entity summaries) on these subscriptions existing, so the last editor to
301
+ * unmount must actually release them, while any editor still mounted must
302
+ * keep them alive.
303
+ *
304
+ * @returns A release function; safe to call more than once.
305
+ */
306
+ declare function connectEditorBridge(): () => void;
307
+ /** Tear down all bridge subscriptions, ignoring the reference count. */
308
+ declare function disconnectEditorBridge(): void;
309
+ /** Toggle the game's debug mode. */
310
+ declare function sendDebugEnabled(enabled: boolean): void;
311
+ /** Switch the active editor tool in the game. */
312
+ declare function sendTool(tool: BridgeDebugTool): void;
313
+ /** Pause or resume the game loop. */
314
+ declare function sendPlayback(paused: boolean): void;
315
+ /** Select an entity in the game (null clears the selection). */
316
+ declare function sendEntitySelect(uuid: string | null): void;
317
+ /** Focus/frame the game debug camera on an entity. */
318
+ declare function sendEntityFocus(uuid: string): void;
319
+ /** Write a stage variable in the running game. */
320
+ declare function sendStageVariable(key: string, value: unknown): void;
321
+
321
322
  /**
322
323
  * Editor Host Helpers
323
324
  *
324
325
  * Reusable wiring for apps that embed the <zylem-editor> overlay next to a
325
- * running Zylem game. Consolidates the mount + state-bridge boilerplate that
326
- * was previously duplicated across consuming apps (examples, creator preview).
326
+ * running Zylem game. These helpers are thin wrappers over the shared
327
+ * `@zylem/bridge` channel: the game applies editor commands itself (via its
328
+ * bridge adapter), so hosts only need this module to mount the overlay,
329
+ * mirror editor commands into their own stores, or push state into the
330
+ * editor UI.
327
331
  */
328
332
 
333
+ /**
334
+ * Nested state payload used by host-facing helpers.
335
+ * Mirrors the historical `editor-state-dispatch` window-event shape so
336
+ * existing hosts keep working; internally everything rides the bridge.
337
+ */
338
+ interface EditorUpdatePayload {
339
+ gameState?: {
340
+ debugFlag?: boolean;
341
+ [key: string]: unknown;
342
+ };
343
+ toolbarState?: {
344
+ tool?: BridgeDebugTool;
345
+ paused?: boolean;
346
+ };
347
+ [key: string]: unknown;
348
+ }
329
349
  interface EditorStateBridgeOptions {
330
350
  /**
331
- * Called after each editor state dispatch has been applied to the
332
- * game-lib debug state, so hosts can mirror the payload into their own
333
- * stores (e.g. a SolidJS store).
351
+ * Called after each editor command has been sent to the game, so hosts
352
+ * can mirror the payload into their own stores (e.g. a SolidJS store).
334
353
  */
335
354
  onStateDispatch?: (payload: EditorUpdatePayload) => void;
336
355
  }
337
356
  interface EditorStateBridge {
338
357
  /** Push external app state back into the editor UI. */
339
358
  dispatchToEditor(payload: EditorUpdatePayload): void;
340
- /** Remove the window listener installed by the bridge. */
359
+ /** Remove the bridge subscriptions installed by this helper. */
341
360
  dispose(): void;
342
361
  }
343
362
  /**
344
- * Dispatch a state update payload to the editor (EDITOR_STATE_RECEIVE).
345
- * Safe to call in non-browser environments (no-op).
363
+ * Push a state update payload into the editor UI (stores + game command).
364
+ * Safe to call in non-browser environments (no-op side effects only).
346
365
  */
347
366
  declare function dispatchToEditor(payload: EditorUpdatePayload): void;
348
367
  /**
349
- * Listen for editor state dispatches (EDITOR_STATE_DISPATCH) and sync them
350
- * into the game-lib debug state: debug flag, active tool, and pause state.
368
+ * Observe editor→game commands on the shared bridge.
369
+ *
370
+ * The game side applies commands itself; this helper exists so external
371
+ * hosts can mirror editor actions (debug toggle, tool, pause) into their own
372
+ * state via `onStateDispatch`.
373
+ *
374
+ * This deliberately does **not** open the editor's game→editor store
375
+ * subscriptions. Those are owned by `<zylem-editor>` for the duration it is
376
+ * mounted, and the game gates expensive work (thumbnail renders, entity
377
+ * summaries) on them being present. A long-lived host helper holding one open
378
+ * would keep that work running forever, even with no editor on screen. Hosts
379
+ * that render editor components without the custom element should call
380
+ * `connectEditorBridge()` directly and release it themselves.
351
381
  *
352
382
  * @example
353
383
  * ```ts
@@ -357,6 +387,14 @@ declare function dispatchToEditor(payload: EditorUpdatePayload): void;
357
387
  * ```
358
388
  */
359
389
  declare function attachEditorStateBridge(options?: EditorStateBridgeOptions): EditorStateBridge;
390
+ /**
391
+ * Send an editor state payload as bridge commands to the running game.
392
+ *
393
+ * @deprecated Use the typed bridge commands (`sendDebugEnabled`, `sendTool`,
394
+ * `sendPlayback`) instead. Kept for hosts migrating off the old
395
+ * window-CustomEvent API.
396
+ */
397
+ declare function dispatchEditorUpdate(payload: EditorUpdatePayload): void;
360
398
  interface MountZylemEditorOptions extends EditorStateBridgeOptions {
361
399
  /**
362
400
  * Controls the editor's floating launcher button.
@@ -384,4 +422,4 @@ interface MountedZylemEditor extends EditorStateBridge {
384
422
  */
385
423
  declare function mountZylemEditor(options?: MountZylemEditorOptions): MountedZylemEditor;
386
424
 
387
- export { EDITOR_STATE_DISPATCH, EDITOR_STATE_RECEIVE, EDITOR_UPDATE_EVENT, type EditorEvent, type EditorEventType, type EditorStateBridge, type EditorStateBridgeOptions, type EditorUpdatePayload, Icon, type MountZylemEditorOptions, type MountedZylemEditor, type ZylemEditorConfig, ZylemEditorElement, attachEditorStateBridge, debugState, debugStore, dispatchEditorUpdate, dispatchToEditor, editorEvents, gameState, mountZylemEditor, registerZylemEditor, stageState };
425
+ export { type EditorEvent, type EditorEventType, type EditorStateBridge, type EditorStateBridgeOptions, type EditorUpdatePayload, Icon, type MountZylemEditorOptions, type MountedZylemEditor, type ZylemEditorConfig, ZylemEditorElement, attachEditorStateBridge, channel as bridgeChannel, connectEditorBridge, debugState, debugStore, disconnectEditorBridge, dispatchEditorUpdate, dispatchToEditor, editorEvents, gameState, mountZylemEditor, registerZylemEditor, sendDebugEnabled, sendEntityFocus, sendEntitySelect, sendPlayback, sendStageVariable, sendTool, stageState };