@zylem/editor 0.6.9 → 0.7.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.
@@ -3,120 +3,6 @@ import { LucideProps } from 'lucide-solid';
3
3
  import * as _zylem_bridge from '@zylem/bridge';
4
4
  import { BridgeDebugTool } from '@zylem/bridge';
5
5
 
6
- type EditorLauncherMode = 'floating' | 'hidden';
7
-
8
- /**
9
- * Configuration options for the ZylemEditorElement
10
- */
11
- interface ZylemEditorConfig {
12
- /**
13
- * External debug state to sync with.
14
- * If provided, the editor will use this state instead of its internal state.
15
- */
16
- debugState?: any;
17
- /**
18
- * External game state to sync with.
19
- */
20
- gameState?: any;
21
- /**
22
- * External stage state to sync with.
23
- */
24
- stageState?: any;
25
- /**
26
- * Whether to include default styles.
27
- * @default true
28
- */
29
- includeStyles?: boolean;
30
- /**
31
- * Controls whether the internal floating launcher is rendered.
32
- * @default 'floating'
33
- */
34
- launcherMode?: EditorLauncherMode;
35
- }
36
- /**
37
- * ZylemEditorElement - A web component that wraps the Zylem Editor.
38
- *
39
- * This component is fully self-contained with bundled styles.
40
- * It can be imported and used in any project without additional CSS configuration.
41
- *
42
- * @example
43
- * ```html
44
- * <!-- Standalone usage -->
45
- * <zylem-editor></zylem-editor>
46
- * ```
47
- *
48
- * @example
49
- * ```js
50
- * // Configured usage
51
- * const editor = document.querySelector('zylem-editor');
52
- * editor.config = {
53
- * debugState: myGame.debugState,
54
- * gameState: myGame.gameState,
55
- * stageState: myGame.stageState,
56
- * };
57
- * ```
58
- *
59
- * @example
60
- * ```js
61
- * // Manual registration in another project
62
- * import { ZylemEditorElement } from '@zylem/editor';
63
- *
64
- * // Optionally customize before registering
65
- * customElements.define('my-editor', ZylemEditorElement);
66
- * ```
67
- */
68
- declare class ZylemEditorElement extends HTMLElement {
69
- private dispose;
70
- private _config;
71
- private _initialized;
72
- private controller;
73
- /** Releases this element's bridge subscription (reference-counted). */
74
- private releaseBridge;
75
- constructor();
76
- /**
77
- * Set configuration for the editor.
78
- * Must be set before the element is connected to the DOM, or call `reinitialize()` after.
79
- */
80
- set config(value: ZylemEditorConfig);
81
- get config(): ZylemEditorConfig;
82
- set launcherMode(value: EditorLauncherMode);
83
- get launcherMode(): EditorLauncherMode;
84
- /**
85
- * Observed attributes for the web component
86
- */
87
- static get observedAttributes(): string[];
88
- attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
89
- connectedCallback(): void;
90
- private initialize;
91
- openPanel(): void;
92
- closePanel(): void;
93
- togglePanel(): void;
94
- /**
95
- * Reinitialize the editor with new configuration.
96
- * Call this after changing the `config` property if the element is already connected.
97
- */
98
- reinitialize(): void;
99
- disconnectedCallback(): void;
100
- private teardown;
101
- }
102
- /**
103
- * Register the ZylemEditorElement as a custom element.
104
- * Call this function to use the default 'zylem-editor' tag name.
105
- *
106
- * @example
107
- * ```js
108
- * import { registerZylemEditor } from '@zylem/editor';
109
- * registerZylemEditor();
110
- * // Now you can use <zylem-editor> in your HTML
111
- * ```
112
- */
113
- declare function registerZylemEditor(tagName?: string): void;
114
-
115
- interface IconProps extends LucideProps {
116
- icon: Component<LucideProps>;
117
- }
118
- declare const Icon: Component<IconProps>;
119
-
120
6
  /**
121
7
  * Editor Event Bus
122
8
  *
@@ -259,6 +145,58 @@ interface StageStateInterface {
259
145
 
260
146
  declare const stageState: StageStateInterface;
261
147
 
148
+ /**
149
+ * Dock layout geometry.
150
+ *
151
+ * Docking used to be per-panel: each panel snapped itself to a viewport edge
152
+ * and sized itself from `window.innerWidth`. That cannot express two panels
153
+ * sharing a side, or a bottom strip that stops at a left-docked panel, so the
154
+ * dock state lives in one registry (persisted in the editor store) and every
155
+ * panel's rect comes from `computeDockLayout`.
156
+ *
157
+ * This module is deliberately free of Solid and `window` so the geometry can
158
+ * be unit tested directly.
159
+ */
160
+ type DockSide = 'left' | 'right' | 'top' | 'bottom';
161
+ /** `'main'` is the editor panel; any other id is a detached section id. */
162
+ type DockPanelId = string;
163
+ interface DockZoneState {
164
+ /** Occupants in slot order along the zone's long axis. */
165
+ panels: DockPanelId[];
166
+ /**
167
+ * Width for left/right, height for top/bottom.
168
+ * `0` means "not chosen yet"; the layout falls back to a viewport quarter.
169
+ */
170
+ thickness: number;
171
+ }
172
+ type DockRegistry = Record<DockSide, DockZoneState>;
173
+ interface Viewport {
174
+ width: number;
175
+ height: number;
176
+ }
177
+ interface DockRect {
178
+ x: number;
179
+ y: number;
180
+ width: number;
181
+ height: number;
182
+ }
183
+ declare const DOCK_SIDES: readonly DockSide[];
184
+ declare const findDockedSide: (registry: DockRegistry, panelId: DockPanelId) => DockSide | null;
185
+ interface DockLayoutOptions {
186
+ /** Smallest slot extent along a zone's long axis. */
187
+ minSlotExtent?: number;
188
+ }
189
+ /**
190
+ * Rect for every docked panel.
191
+ *
192
+ * Left and right zones take the full viewport height and win over top and
193
+ * bottom, which inset horizontally to the space between them. Panels sharing a
194
+ * zone split its long axis evenly.
195
+ */
196
+ declare const computeDockLayout: (registry: DockRegistry, viewport: Viewport, options?: DockLayoutOptions) => Record<DockPanelId, DockRect>;
197
+
198
+ /** Registry id of the main editor panel; detached sections use their panel id. */
199
+ declare const MAIN_PANEL_ID = "main";
262
200
  interface DetachedPanelState {
263
201
  position: {
264
202
  x: number;
@@ -269,6 +207,8 @@ interface DetachedPanelState {
269
207
  height: number;
270
208
  };
271
209
  }
210
+ /** First-run dock assignments a host can request; see `applyDefaultDocks`. */
211
+ type EditorDockDefaults = Partial<Record<DockSide, DockPanelId[]>>;
272
212
  declare const debugStore: {
273
213
  debug: boolean;
274
214
  tool: DebugTools;
@@ -279,6 +219,11 @@ declare const debugStore: {
279
219
  x: number;
280
220
  y: number;
281
221
  } | null;
222
+ /** Main panel's floating size; its docked size comes from the registry. */
223
+ panelSize: {
224
+ width: number;
225
+ height: number;
226
+ } | null;
282
227
  toggleButtonPosition: {
283
228
  x: number;
284
229
  y: number;
@@ -287,9 +232,143 @@ declare const debugStore: {
287
232
  detachedPanels: Record<string, DetachedPanelState>;
288
233
  openSections: string[];
289
234
  panelZOrder: string[];
235
+ docks: DockRegistry;
236
+ dockDefaultsApplied: boolean;
290
237
  draggingPanelId: string | null;
291
238
  dropTargetIndex: number | null;
292
239
  };
240
+ declare const dockPanelToSide: (panelId: DockPanelId, side: DockSide, index?: number) => void;
241
+ declare const undockPanelFromSides: (panelId: DockPanelId) => void;
242
+ declare const getDockedSide: (panelId: DockPanelId) => DockSide | null;
243
+
244
+ type EditorLauncherMode = 'floating' | 'hidden';
245
+
246
+ /**
247
+ * Configuration options for the ZylemEditorElement
248
+ */
249
+ interface ZylemEditorConfig {
250
+ /**
251
+ * External debug state to sync with.
252
+ * If provided, the editor will use this state instead of its internal state.
253
+ */
254
+ debugState?: any;
255
+ /**
256
+ * External game state to sync with.
257
+ */
258
+ gameState?: any;
259
+ /**
260
+ * External stage state to sync with.
261
+ */
262
+ stageState?: any;
263
+ /**
264
+ * Whether to include default styles.
265
+ * @default true
266
+ */
267
+ includeStyles?: boolean;
268
+ /**
269
+ * Controls whether the internal floating launcher is rendered.
270
+ * @default 'floating'
271
+ */
272
+ launcherMode?: EditorLauncherMode;
273
+ /**
274
+ * Dock layout to seed the first time the editor runs in this browser, keyed
275
+ * by viewport edge. Use `'main'` for the editor panel itself; any other id is
276
+ * a section (for example `'console'`), which gets detached from the accordion
277
+ * so it can hold a dock slot.
278
+ *
279
+ * Ignored once the user has a saved layout, so it sets a starting point
280
+ * rather than forcing one.
281
+ */
282
+ defaultDocks?: EditorDockDefaults;
283
+ }
284
+ /**
285
+ * ZylemEditorElement - A web component that wraps the Zylem Editor.
286
+ *
287
+ * This component is fully self-contained with bundled styles.
288
+ * It can be imported and used in any project without additional CSS configuration.
289
+ *
290
+ * @example
291
+ * ```html
292
+ * <!-- Standalone usage -->
293
+ * <zylem-editor></zylem-editor>
294
+ * ```
295
+ *
296
+ * @example
297
+ * ```js
298
+ * // Configured usage
299
+ * const editor = document.querySelector('zylem-editor');
300
+ * editor.config = {
301
+ * debugState: myGame.debugState,
302
+ * gameState: myGame.gameState,
303
+ * stageState: myGame.stageState,
304
+ * };
305
+ * ```
306
+ *
307
+ * @example
308
+ * ```js
309
+ * // Manual registration in another project
310
+ * import { ZylemEditorElement } from '@zylem/editor';
311
+ *
312
+ * // Optionally customize before registering
313
+ * customElements.define('my-editor', ZylemEditorElement);
314
+ * ```
315
+ */
316
+ declare class ZylemEditorElement extends HTMLElement {
317
+ private dispose;
318
+ private _config;
319
+ private _initialized;
320
+ private controller;
321
+ /** Releases this element's bridge subscription (reference-counted). */
322
+ private releaseBridge;
323
+ constructor();
324
+ /**
325
+ * Set configuration for the editor.
326
+ * Must be set before the element is connected to the DOM, or call `reinitialize()` after.
327
+ */
328
+ set config(value: ZylemEditorConfig);
329
+ get config(): ZylemEditorConfig;
330
+ set launcherMode(value: EditorLauncherMode);
331
+ get launcherMode(): EditorLauncherMode;
332
+ /**
333
+ * Observed attributes for the web component
334
+ */
335
+ static get observedAttributes(): string[];
336
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
337
+ connectedCallback(): void;
338
+ private initialize;
339
+ openPanel(): void;
340
+ closePanel(): void;
341
+ togglePanel(): void;
342
+ /**
343
+ * Dock a panel to a viewport edge, or pass `null` to float it again.
344
+ * Defaults to the main editor panel.
345
+ */
346
+ dockPanel(side: DockSide | null, panelId?: DockPanelId): void;
347
+ /**
348
+ * Reinitialize the editor with new configuration.
349
+ * Call this after changing the `config` property if the element is already connected.
350
+ */
351
+ reinitialize(): void;
352
+ disconnectedCallback(): void;
353
+ private teardown;
354
+ }
355
+ /**
356
+ * Register the ZylemEditorElement as a custom element.
357
+ * Call this function to use the default 'zylem-editor' tag name.
358
+ *
359
+ * @example
360
+ * ```js
361
+ * import { registerZylemEditor } from '@zylem/editor';
362
+ * registerZylemEditor();
363
+ * // Now you can use <zylem-editor> in your HTML
364
+ * ```
365
+ */
366
+ declare function registerZylemEditor(tagName?: string): void;
367
+
368
+ interface IconProps extends LucideProps {
369
+ icon: Component<LucideProps>;
370
+ }
371
+ declare const Icon: Component<IconProps>;
293
372
 
294
373
  declare const channel: _zylem_bridge.BridgeChannel;
295
374
  /**
@@ -401,6 +480,17 @@ interface MountZylemEditorOptions extends EditorStateBridgeOptions {
401
480
  * @default 'floating'
402
481
  */
403
482
  launcherMode?: EditorLauncherMode;
483
+ /**
484
+ * Dock layout to seed on first run, keyed by viewport edge. `'main'` is the
485
+ * editor panel; any other id is a section such as `'console'`. Ignored once
486
+ * the user has a saved layout.
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * mountZylemEditor({ defaultDocks: { left: ['main'], bottom: ['console'] } });
491
+ * ```
492
+ */
493
+ defaultDocks?: EditorDockDefaults;
404
494
  /**
405
495
  * Element the <zylem-editor> overlay is appended to.
406
496
  * @default document.body
@@ -409,6 +499,8 @@ interface MountZylemEditorOptions extends EditorStateBridgeOptions {
409
499
  }
410
500
  interface MountedZylemEditor extends EditorStateBridge {
411
501
  element: ZylemEditorElement;
502
+ /** Dock a panel to a viewport edge, or pass `null` to float it again. */
503
+ dockPanel(side: DockSide | null, panelId?: DockPanelId): void;
412
504
  }
413
505
  /**
414
506
  * Imperatively mount a <zylem-editor> overlay and attach the state bridge.
@@ -422,4 +514,4 @@ interface MountedZylemEditor extends EditorStateBridge {
422
514
  */
423
515
  declare function mountZylemEditor(options?: MountZylemEditorOptions): MountedZylemEditor;
424
516
 
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 };
517
+ export { DOCK_SIDES, type DockPanelId, type DockRect, type DockRegistry, type DockSide, type DockZoneState, type EditorDockDefaults, type EditorEvent, type EditorEventType, type EditorStateBridge, type EditorStateBridgeOptions, type EditorUpdatePayload, Icon, MAIN_PANEL_ID, type MountZylemEditorOptions, type MountedZylemEditor, type ZylemEditorConfig, ZylemEditorElement, attachEditorStateBridge, channel as bridgeChannel, computeDockLayout, connectEditorBridge, debugState, debugStore, disconnectEditorBridge, dispatchEditorUpdate, dispatchToEditor, dockPanelToSide, editorEvents, findDockedSide, gameState, getDockedSide, mountZylemEditor, registerZylemEditor, sendDebugEnabled, sendEntityFocus, sendEntitySelect, sendPlayback, sendStageVariable, sendTool, stageState, undockPanelFromSides };