@molecule/app-ide-default 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Browser `localStorage` adapter for workspace-layout persistence.
3
+ *
4
+ * The provider stays storage-agnostic (it accepts an injectable
5
+ * {@link StorageAdapter} and defaults to in-memory). This helper supplies the
6
+ * concrete browser implementation used to pre-wire the exported singleton so a
7
+ * resized layout survives a page reload out of the box, while remaining `null`
8
+ * (in-memory, no persistence) anywhere `localStorage` is missing or blocked
9
+ * (SSR, Node test runners, privacy modes that throw on access).
10
+ *
11
+ * @module
12
+ */
13
+ import type { StorageAdapter } from './types.js';
14
+ /**
15
+ * Returns a {@link StorageAdapter} backed by the browser's `localStorage`, or
16
+ * `null` when no usable `localStorage` exists. A `null` result means
17
+ * "persistence unavailable — fall back to in-memory".
18
+ * @returns A `localStorage`-backed adapter, or `null` if unavailable.
19
+ */
20
+ export declare function getBrowserStorage(): StorageAdapter | null;
21
+ //# sourceMappingURL=browser-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-storage.d.ts","sourceRoot":"","sources":["../src/browser-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAmBzD"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Browser `localStorage` adapter for workspace-layout persistence.
3
+ *
4
+ * The provider stays storage-agnostic (it accepts an injectable
5
+ * {@link StorageAdapter} and defaults to in-memory). This helper supplies the
6
+ * concrete browser implementation used to pre-wire the exported singleton so a
7
+ * resized layout survives a page reload out of the box, while remaining `null`
8
+ * (in-memory, no persistence) anywhere `localStorage` is missing or blocked
9
+ * (SSR, Node test runners, privacy modes that throw on access).
10
+ *
11
+ * @module
12
+ */
13
+ /**
14
+ * Returns a {@link StorageAdapter} backed by the browser's `localStorage`, or
15
+ * `null` when no usable `localStorage` exists. A `null` result means
16
+ * "persistence unavailable — fall back to in-memory".
17
+ * @returns A `localStorage`-backed adapter, or `null` if unavailable.
18
+ */
19
+ export function getBrowserStorage() {
20
+ try {
21
+ const ls = globalThis.localStorage;
22
+ if (!ls)
23
+ return null;
24
+ // Some environments expose the object but throw on first use (private mode,
25
+ // disabled storage). Probe with a throwaway key before trusting it.
26
+ const probeKey = '__molecule_workspace_probe__';
27
+ ls.setItem(probeKey, probeKey);
28
+ ls.removeItem(probeKey);
29
+ return {
30
+ getItem: (key) => ls.getItem(key),
31
+ setItem: (key, value) => ls.setItem(key, value),
32
+ removeItem: (key) => ls.removeItem(key),
33
+ };
34
+ }
35
+ catch (_error) {
36
+ // localStorage is absent or access is blocked. Layout persistence across
37
+ // reloads is an enhancement, not a requirement, so fall back to in-memory.
38
+ return null;
39
+ }
40
+ }
41
+ //# sourceMappingURL=browser-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-storage.js","sourceRoot":"","sources":["../src/browser-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,UAAU,CAAC,YAAmC,CAAA;QACzD,IAAI,CAAC,EAAE;YAAE,OAAO,IAAI,CAAA;QACpB,4EAA4E;QAC5E,oEAAoE;QACpE,MAAM,QAAQ,GAAG,8BAA8B,CAAA;QAC/C,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAC9B,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACvB,OAAO;YACL,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;YACzC,OAAO,EAAE,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC;YAC/D,UAAU,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;SAChD,CAAA;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,yEAAyE;QACzE,2EAA2E;QAC3E,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Default IDE workspace provider for molecule.dev — panel layout state
3
+ * (chat / editor / preview), sizes, collapse/active state, with optional
4
+ * persistence through an injectable storage adapter.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { setProvider } from '@molecule/app-ide'
9
+ * import { provider } from '@molecule/app-ide-default'
10
+ *
11
+ * setProvider(provider) // once, at app startup (bonds.ts)
12
+ * ```
13
+ *
14
+ * @remarks
15
+ * - **A persisted layout SHADOWS default-layout changes.** The `provider`
16
+ * singleton saves to `localStorage` key `'molecule-workspace-layout'`; once a
17
+ * user has a saved layout, changes to `defaultLayout` (or the built-in
18
+ * default) have no visible effect until `resetLayout()` runs or the key is
19
+ * cleared. If "my layout change doesn't show up", this is why.
20
+ * - Default layout: `chat` (left, 25%) / `editor` (center, 50%) / `preview`
21
+ * (right, 25%). `PanelId` accepts custom strings — extend the layout rather
22
+ * than building a parallel one.
23
+ * - State-only: pair with `@molecule/app-ide-react` (or your own renderer
24
+ * reading `getLayout()` + `subscribe()`).
25
+ * - Need different persistence (custom adapter, key, or none)? Build your own
26
+ * instance with `createProvider({...})` instead of the singleton.
27
+ *
28
+ * @module
29
+ */
30
+ export * from './browser-storage.js';
31
+ export * from './provider.js';
32
+ export * from './types.js';
33
+ /**
34
+ * Pre-instantiated provider singleton. Persists the layout to the browser's
35
+ * `localStorage` when available, so a panel resize survives a page reload;
36
+ * falls back to a non-persistent in-memory provider where storage is missing
37
+ * or blocked (SSR, tests). Consumers wanting different behavior (a custom
38
+ * storage adapter, key, or opting out) should call {@link createProvider}.
39
+ */
40
+ export declare const provider: import("./provider.js").DefaultWorkspaceProvider;
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAO1B;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,kDAED,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Default IDE workspace provider for molecule.dev — panel layout state
3
+ * (chat / editor / preview), sizes, collapse/active state, with optional
4
+ * persistence through an injectable storage adapter.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { setProvider } from '@molecule/app-ide'
9
+ * import { provider } from '@molecule/app-ide-default'
10
+ *
11
+ * setProvider(provider) // once, at app startup (bonds.ts)
12
+ * ```
13
+ *
14
+ * @remarks
15
+ * - **A persisted layout SHADOWS default-layout changes.** The `provider`
16
+ * singleton saves to `localStorage` key `'molecule-workspace-layout'`; once a
17
+ * user has a saved layout, changes to `defaultLayout` (or the built-in
18
+ * default) have no visible effect until `resetLayout()` runs or the key is
19
+ * cleared. If "my layout change doesn't show up", this is why.
20
+ * - Default layout: `chat` (left, 25%) / `editor` (center, 50%) / `preview`
21
+ * (right, 25%). `PanelId` accepts custom strings — extend the layout rather
22
+ * than building a parallel one.
23
+ * - State-only: pair with `@molecule/app-ide-react` (or your own renderer
24
+ * reading `getLayout()` + `subscribe()`).
25
+ * - Need different persistence (custom adapter, key, or none)? Build your own
26
+ * instance with `createProvider({...})` instead of the singleton.
27
+ *
28
+ * @module
29
+ */
30
+ export * from './browser-storage.js';
31
+ export * from './provider.js';
32
+ export * from './types.js';
33
+ import { getBrowserStorage } from './browser-storage.js';
34
+ import { createProvider } from './provider.js';
35
+ const browserStorage = getBrowserStorage();
36
+ /**
37
+ * Pre-instantiated provider singleton. Persists the layout to the browser's
38
+ * `localStorage` when available, so a panel resize survives a page reload;
39
+ * falls back to a non-persistent in-memory provider where storage is missing
40
+ * or blocked (SSR, tests). Consumers wanting different behavior (a custom
41
+ * storage adapter, key, or opting out) should call {@link createProvider}.
42
+ */
43
+ export const provider = browserStorage
44
+ ? createProvider({ persistLayout: true, storage: browserStorage })
45
+ : createProvider();
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc;IACpC,CAAC,CAAC,cAAc,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAClE,CAAC,CAAC,cAAc,EAAE,CAAA"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Default workspace provider implementation.
3
+ *
4
+ * Manages panel layout, sizes, visibility, and collapse state.
5
+ * Optionally persists layout via an injectable storage adapter.
6
+ *
7
+ * @module
8
+ */
9
+ import type { PanelId, WorkspaceLayout, WorkspaceProvider, WorkspaceState } from '@molecule/app-ide';
10
+ import type { DefaultWorkspaceConfig } from './types.js';
11
+ /**
12
+ * Default implementation of `WorkspaceProvider`. Manages panel layout (chat, editor, preview),
13
+ * sizes, visibility, collapse state, and optional persistence via a storage adapter.
14
+ */
15
+ export declare class DefaultWorkspaceProvider implements WorkspaceProvider {
16
+ readonly name = "default";
17
+ private state;
18
+ private defaultLayout;
19
+ private persistLayout;
20
+ private storageKey;
21
+ private storage;
22
+ private subscribers;
23
+ constructor(config?: DefaultWorkspaceConfig);
24
+ /**
25
+ * Returns the current workspace layout with panel positions and sizes.
26
+ * @returns The current workspace layout.
27
+ */
28
+ getLayout(): WorkspaceLayout;
29
+ /**
30
+ * Replaces the workspace layout, persists it, and notifies subscribers.
31
+ * @param layout - The new workspace layout.
32
+ */
33
+ setLayout(layout: WorkspaceLayout): void;
34
+ /**
35
+ * Toggles a panel's collapsed state.
36
+ * @param panelId - The ID of the panel to toggle.
37
+ */
38
+ togglePanel(panelId: PanelId): void;
39
+ /**
40
+ * Resizes a panel to the given size percentage within its position group.
41
+ * @param panelId - The ID of the panel to resize.
42
+ * @param size - The new size as a percentage.
43
+ */
44
+ resizePanel(panelId: PanelId, size: number): void;
45
+ /**
46
+ * Sets the given panel as the active (focused) panel.
47
+ * @param panelId - The ID of the panel to activate.
48
+ */
49
+ setActivePanel(panelId: PanelId): void;
50
+ /**
51
+ * Subscribes to workspace state changes.
52
+ * @param callback - Called with the new state whenever layout, panels, or active panel changes.
53
+ * @returns An unsubscribe function.
54
+ */
55
+ subscribe(callback: (state: WorkspaceState) => void): () => void;
56
+ /** Resets the workspace to the default layout, clears collapsed panels, and persists. */
57
+ resetLayout(): void;
58
+ /** Notifies all subscribers of the current workspace state. */
59
+ private notify;
60
+ /** Persists the current layout to the storage adapter if persistence is enabled. */
61
+ private persist;
62
+ /**
63
+ * Loads a previously persisted layout from the storage adapter.
64
+ * @returns The saved layout, or `null` if none exists or persistence is disabled.
65
+ */
66
+ private loadPersistedLayout;
67
+ }
68
+ /**
69
+ * Creates a `DefaultWorkspaceProvider` with optional layout configuration and persistence.
70
+ * @param config - Workspace configuration (default layout, persistence options, storage adapter).
71
+ * @returns A `DefaultWorkspaceProvider` that manages panel layout state.
72
+ */
73
+ export declare function createProvider(config?: DefaultWorkspaceConfig): DefaultWorkspaceProvider;
74
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEpG,OAAO,KAAK,EAAE,sBAAsB,EAAkB,MAAM,YAAY,CAAA;AAyBxE;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IAChE,QAAQ,CAAC,IAAI,aAAY;IACzB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,WAAW,CAAkD;gBAEzD,MAAM,GAAE,sBAA2B;IAgB/C;;;OAGG;IACH,SAAS,IAAI,eAAe;IAI5B;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAMxC;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAWnC;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAsBjD;;;OAGG;IACH,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKtC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,MAAM,IAAI;IAKhE,yFAAyF;IACzF,WAAW,IAAI,IAAI;IAWnB,+DAA+D;IAC/D,OAAO,CAAC,MAAM;IAMd,oFAAoF;IACpF,OAAO,CAAC,OAAO;IAaf;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAY5B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,wBAAwB,CAExF"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Default workspace provider implementation.
3
+ *
4
+ * Manages panel layout, sizes, visibility, and collapse state.
5
+ * Optionally persists layout via an injectable storage adapter.
6
+ *
7
+ * @module
8
+ */
9
+ const DEFAULT_LAYOUT = {
10
+ panels: [
11
+ {
12
+ id: 'chat',
13
+ position: 'left',
14
+ defaultSize: 25,
15
+ resizable: true,
16
+ collapsible: true,
17
+ visible: true,
18
+ },
19
+ { id: 'editor', position: 'center', defaultSize: 50, resizable: true, visible: true },
20
+ {
21
+ id: 'preview',
22
+ position: 'right',
23
+ defaultSize: 25,
24
+ resizable: true,
25
+ collapsible: true,
26
+ visible: true,
27
+ },
28
+ ],
29
+ sizes: { left: [25], center: [50], right: [25], bottom: [] },
30
+ };
31
+ /**
32
+ * Default implementation of `WorkspaceProvider`. Manages panel layout (chat, editor, preview),
33
+ * sizes, visibility, collapse state, and optional persistence via a storage adapter.
34
+ */
35
+ export class DefaultWorkspaceProvider {
36
+ name = 'default';
37
+ state;
38
+ defaultLayout;
39
+ persistLayout;
40
+ storageKey;
41
+ storage;
42
+ subscribers = new Set();
43
+ constructor(config = {}) {
44
+ this.defaultLayout = config.defaultLayout ?? DEFAULT_LAYOUT;
45
+ this.persistLayout = config.persistLayout ?? false;
46
+ this.storageKey = config.storageKey ?? 'molecule-workspace-layout';
47
+ this.storage = config.storage ?? null;
48
+ const savedLayout = this.loadPersistedLayout();
49
+ this.state = {
50
+ layout: savedLayout ?? { ...this.defaultLayout },
51
+ activePanel: null,
52
+ collapsedPanels: new Set(),
53
+ isFullscreen: false,
54
+ };
55
+ }
56
+ /**
57
+ * Returns the current workspace layout with panel positions and sizes.
58
+ * @returns The current workspace layout.
59
+ */
60
+ getLayout() {
61
+ return this.state.layout;
62
+ }
63
+ /**
64
+ * Replaces the workspace layout, persists it, and notifies subscribers.
65
+ * @param layout - The new workspace layout.
66
+ */
67
+ setLayout(layout) {
68
+ this.state = { ...this.state, layout };
69
+ this.persist();
70
+ this.notify();
71
+ }
72
+ /**
73
+ * Toggles a panel's collapsed state.
74
+ * @param panelId - The ID of the panel to toggle.
75
+ */
76
+ togglePanel(panelId) {
77
+ const collapsed = new Set(this.state.collapsedPanels);
78
+ if (collapsed.has(panelId)) {
79
+ collapsed.delete(panelId);
80
+ }
81
+ else {
82
+ collapsed.add(panelId);
83
+ }
84
+ this.state = { ...this.state, collapsedPanels: collapsed };
85
+ this.notify();
86
+ }
87
+ /**
88
+ * Resizes a panel to the given size percentage within its position group.
89
+ * @param panelId - The ID of the panel to resize.
90
+ * @param size - The new size as a percentage.
91
+ */
92
+ resizePanel(panelId, size) {
93
+ const panel = this.state.layout.panels.find((p) => p.id === panelId);
94
+ if (!panel)
95
+ return;
96
+ const position = panel.position;
97
+ const positionPanels = this.state.layout.panels.filter((p) => p.position === position);
98
+ const panelIndex = positionPanels.findIndex((p) => p.id === panelId);
99
+ if (panelIndex === -1)
100
+ return;
101
+ const sizes = { ...this.state.layout.sizes };
102
+ const positionSizes = [...(sizes[position] ?? [])];
103
+ positionSizes[panelIndex] = size;
104
+ sizes[position] = positionSizes;
105
+ this.state = {
106
+ ...this.state,
107
+ layout: { ...this.state.layout, sizes },
108
+ };
109
+ this.persist();
110
+ this.notify();
111
+ }
112
+ /**
113
+ * Sets the given panel as the active (focused) panel.
114
+ * @param panelId - The ID of the panel to activate.
115
+ */
116
+ setActivePanel(panelId) {
117
+ this.state = { ...this.state, activePanel: panelId };
118
+ this.notify();
119
+ }
120
+ /**
121
+ * Subscribes to workspace state changes.
122
+ * @param callback - Called with the new state whenever layout, panels, or active panel changes.
123
+ * @returns An unsubscribe function.
124
+ */
125
+ subscribe(callback) {
126
+ this.subscribers.add(callback);
127
+ return () => this.subscribers.delete(callback);
128
+ }
129
+ /** Resets the workspace to the default layout, clears collapsed panels, and persists. */
130
+ resetLayout() {
131
+ this.state = {
132
+ layout: { ...this.defaultLayout },
133
+ activePanel: null,
134
+ collapsedPanels: new Set(),
135
+ isFullscreen: false,
136
+ };
137
+ this.persist();
138
+ this.notify();
139
+ }
140
+ /** Notifies all subscribers of the current workspace state. */
141
+ notify() {
142
+ for (const cb of this.subscribers) {
143
+ cb(this.state);
144
+ }
145
+ }
146
+ /** Persists the current layout to the storage adapter if persistence is enabled. */
147
+ persist() {
148
+ if (!this.persistLayout || !this.storage)
149
+ return;
150
+ try {
151
+ const serializable = {
152
+ layout: this.state.layout,
153
+ collapsedPanels: [...this.state.collapsedPanels],
154
+ };
155
+ this.storage.setItem(this.storageKey, JSON.stringify(serializable));
156
+ }
157
+ catch (_error) {
158
+ // storage may be unavailable (quota exceeded, security restrictions) — persistence is best-effort
159
+ }
160
+ }
161
+ /**
162
+ * Loads a previously persisted layout from the storage adapter.
163
+ * @returns The saved layout, or `null` if none exists or persistence is disabled.
164
+ */
165
+ loadPersistedLayout() {
166
+ if (!this.persistLayout || !this.storage)
167
+ return null;
168
+ try {
169
+ const saved = this.storage.getItem(this.storageKey);
170
+ if (!saved)
171
+ return null;
172
+ const parsed = JSON.parse(saved);
173
+ return parsed.layout ?? null;
174
+ }
175
+ catch (_error) {
176
+ // corrupted or unreadable saved data — fall back to the default layout
177
+ return null;
178
+ }
179
+ }
180
+ }
181
+ /**
182
+ * Creates a `DefaultWorkspaceProvider` with optional layout configuration and persistence.
183
+ * @param config - Workspace configuration (default layout, persistence options, storage adapter).
184
+ * @returns A `DefaultWorkspaceProvider` that manages panel layout state.
185
+ */
186
+ export function createProvider(config) {
187
+ return new DefaultWorkspaceProvider(config);
188
+ }
189
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":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AAC,KAAK,CAAC,KAAK,CAAiC,CAAA;YAChE,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,CAAA;QAC9B,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,uEAAuE;YACvE,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAA+B;IAC5D,OAAO,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAA;AAC7C,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Default workspace provider configuration.
3
+ *
4
+ * @module
5
+ */
6
+ import type { WorkspaceLayout } from '@molecule/app-ide';
7
+ /**
8
+ * Adapter interface for storage.
9
+ */
10
+ export interface StorageAdapter {
11
+ getItem(key: string): string | null;
12
+ setItem(key: string, value: string): void;
13
+ removeItem(key: string): void;
14
+ }
15
+ /**
16
+ * Configuration for default workspace.
17
+ */
18
+ export interface DefaultWorkspaceConfig {
19
+ /** Default panel layout. */
20
+ defaultLayout?: WorkspaceLayout;
21
+ /** Persist layout using the provided storage adapter. */
22
+ persistLayout?: boolean;
23
+ /** Key for storage persistence. */
24
+ storageKey?: string;
25
+ /** Storage adapter for persistence. Required when persistLayout is true. */
26
+ storage?: StorageAdapter;
27
+ }
28
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACnC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACzC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,4BAA4B;IAC5B,aAAa,CAAC,EAAE,eAAe,CAAA;IAC/B,yDAAyD;IACzD,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Default workspace provider configuration.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@molecule/app-ide-default",
3
+ "version": "1.0.0",
4
+ "description": "Default workspace layout provider with panel management",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "ide",
25
+ "workspace",
26
+ "panels"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "devDependencies": {
30
+ "@molecule/app-ide": "1.0.0",
31
+ "@types/node": "26.1.2",
32
+ "typescript": "6.0.3",
33
+ "vitest": "4.1.10"
34
+ },
35
+ "peerDependencies": {
36
+ "@molecule/app-ide": "^1.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@molecule/app-ide": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/molecule-dev/molecule.git",
46
+ "directory": "packages/app/bonds/ide/default"
47
+ },
48
+ "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/bonds/ide/default",
49
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }