@streamscloud/kit 0.38.2 → 0.39.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.
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">import { slideHorizontally, transitionDuration } from '../../core/transitions';
2
2
  import PagePanel from './cmp.page-panel.svelte';
3
3
  import { untrack } from 'svelte';
4
- const { panelState, children, sidebarLeft, sidebarRight, sidebarLeftIsValid = true, sidebarRightIsValid = true, title, actionsLeft, actionsCenter, actionsRight, balanceHeaderCenter = false } = $props();
4
+ const { panelState, children, sidebarLeft, sidebarRight, sidebarLeftIsValid = true, sidebarRightIsValid = true, title, actionsLeft, actionsCenter, actionsRight, balanceHeaderCenter = false, toggle } = $props();
5
5
  let leftPanel = $state(null);
6
6
  let rightPanel = $state(null);
7
7
  $effect(() => {
@@ -31,21 +31,13 @@ $effect(() => {
31
31
  const collapseButtons = $derived([leftPanel?.id, rightPanel?.id].filter((id) => id !== null && id !== undefined));
32
32
  const leftCollapsed = $derived(leftPanel?.entry.collapsed ?? false);
33
33
  const rightCollapsed = $derived(rightPanel?.entry.collapsed ?? false);
34
- export function toggleLeft() {
35
- leftPanel?.entry.toggleCollapsed();
36
- }
37
- export function toggleRight() {
38
- rightPanel?.entry.toggleCollapsed();
39
- }
40
- /** Collapses both sidebars, or expands both when they are already all collapsed. */
41
- export function toggleBoth() {
42
- const entries = [leftPanel?.entry, rightPanel?.entry].filter((entry) => !!entry);
43
- if (entries.length === 0) {
44
- return;
45
- }
46
- const allCollapsed = entries.every((entry) => entry.collapsed);
47
- entries.forEach((entry) => entry.setCollapsed(!allCollapsed));
48
- }
34
+ $effect(() => {
35
+ const attached = toggle;
36
+ attached?.attach(leftPanel?.entry ?? null, rightPanel?.entry ?? null);
37
+ return () => {
38
+ attached?.attach(null, null);
39
+ };
40
+ });
49
41
  $effect(() => {
50
42
  if (leftPanel) {
51
43
  leftPanel.entry.isValid = sidebarLeftIsValid;
@@ -101,8 +93,9 @@ PagePanelSidebars — a `PagePanel` whose body has collapsible left / right side
101
93
  fictional left/right panels in the shared `PanelState` so the standard collapse buttons in the
102
94
  header can target them. Sidebars slide horizontally on collapse / expand.
103
95
 
104
- Exposes imperative `toggleLeft()` / `toggleRight()` / `toggleBoth()` via `bind:this` for external
105
- collapse controls (e.g. a top-bar button), so callers don't reach into `PanelState` by id.
96
+ Pass a `SidebarsToggle` instance as `toggle` to drive an external "collapse both" control (e.g. a
97
+ top-bar button) without `bind:this` or a local collapsed flag — read `toggleBoth` / `allCollapsed`
98
+ off that same instance.
106
99
 
107
100
  ### CSS Custom Properties
108
101
  | Property | Description | Default |
@@ -1,4 +1,4 @@
1
- import type { PanelState } from './panel-state.svelte';
1
+ import type { PanelState, SidebarsToggle } from './panel-state.svelte';
2
2
  import type { Snippet } from 'svelte';
3
3
  type Props = {
4
4
  /** The shared `PanelState` instance the inner panel + sidebars register with. */
@@ -14,24 +14,23 @@ type Props = {
14
14
  actionsRight?: Snippet;
15
15
  /** Lay the inner panel header out as a 3-column grid so `actionsCenter` is centered against the panel width. @default false */
16
16
  balanceHeaderCenter?: boolean;
17
+ /** Shared collapse target for an external "collapse both sidebars" control (e.g. `PageLayout`'s `editorControls.panelsToggle`). */
18
+ toggle?: SidebarsToggle;
17
19
  };
18
20
  /**
19
21
  * PagePanelSidebars — a `PagePanel` whose body has collapsible left / right sidebars. Registers
20
22
  * fictional left/right panels in the shared `PanelState` so the standard collapse buttons in the
21
23
  * header can target them. Sidebars slide horizontally on collapse / expand.
22
24
  *
23
- * Exposes imperative `toggleLeft()` / `toggleRight()` / `toggleBoth()` via `bind:this` for external
24
- * collapse controls (e.g. a top-bar button), so callers don't reach into `PanelState` by id.
25
+ * Pass a `SidebarsToggle` instance as `toggle` to drive an external "collapse both" control (e.g. a
26
+ * top-bar button) without `bind:this` or a local collapsed flag — read `toggleBoth` / `allCollapsed`
27
+ * off that same instance.
25
28
  *
26
29
  * ### CSS Custom Properties
27
30
  * | Property | Description | Default |
28
31
  * |---|---|---|
29
32
  * | `--sc-kit--page-panel-sidebars--border-color` | Sidebar divider color | `--sc-kit--color--border` |
30
33
  */
31
- declare const Cmp: import("svelte").Component<Props, {
32
- toggleLeft: () => void;
33
- toggleRight: () => void;
34
- toggleBoth: () => void;
35
- }, "">;
34
+ declare const Cmp: import("svelte").Component<Props, {}, "">;
36
35
  type Cmp = ReturnType<typeof Cmp>;
37
36
  export default Cmp;
@@ -4,5 +4,5 @@ export { default as PagePanelSidebars } from './cmp.page-panel-sidebars.svelte';
4
4
  export { default as PagePanels } from './cmp.page-panels.svelte';
5
5
  export { default as PanelCollapseButton } from './cmp.panel-collapse-button.svelte';
6
6
  export { default as PanelContent } from './cmp.panel-content.svelte';
7
- export { PanelEntry, PanelState } from './panel-state.svelte';
7
+ export { PanelEntry, PanelState, SidebarsToggle } from './panel-state.svelte';
8
8
  export type { EditorControls, PageLayoutAction, PanelBorder, PanelResizingSettings } from './types';
@@ -4,4 +4,4 @@ export { default as PagePanelSidebars } from './cmp.page-panel-sidebars.svelte';
4
4
  export { default as PagePanels } from './cmp.page-panels.svelte';
5
5
  export { default as PanelCollapseButton } from './cmp.panel-collapse-button.svelte';
6
6
  export { default as PanelContent } from './cmp.panel-content.svelte';
7
- export { PanelEntry, PanelState } from './panel-state.svelte';
7
+ export { PanelEntry, PanelState, SidebarsToggle } from './panel-state.svelte';
@@ -47,4 +47,37 @@ export declare class PanelState {
47
47
  get: (id: string) => PanelEntry | null;
48
48
  unregister: (id: string, entry: PanelEntry) => void;
49
49
  }
50
+ /**
51
+ * Shared collapse target for a `PagePanelSidebars`'s left/right sidebar pair. Create one instance
52
+ * and pass it to `PagePanelSidebars`'s `toggle` prop, then read `toggleBoth` / `allCollapsed` from
53
+ * this instance wherever the external control lives (e.g. `PageLayout`'s `editorControls`) — no
54
+ * `bind:this` or extra local state needed on the consumer side.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const panels = new PanelState();
59
+ * const sidebarsToggle = new SidebarsToggle();
60
+ * ```
61
+ * ```svelte
62
+ * <PageLayout editorControls={{ panelsToggle: { active: sidebarsToggle.allCollapsed, onClick: sidebarsToggle.toggleBoth }, close: {...} }}>
63
+ * <PagePanels>
64
+ * <PagePanelSidebars panelState={panels} toggle={sidebarsToggle}>...</PagePanelSidebars>
65
+ * </PagePanels>
66
+ * </PageLayout>
67
+ * ```
68
+ */
69
+ export declare class SidebarsToggle {
70
+ private _left;
71
+ private _right;
72
+ /**
73
+ * True when every attached sidebar is currently collapsed.
74
+ * @remarks False both when there are no sidebars attached and before `PagePanelSidebars` mounts —
75
+ * an external toggle button reads this as "not active" in either case.
76
+ */
77
+ get allCollapsed(): boolean;
78
+ /** Wired automatically by the paired `PagePanelSidebars`'s `toggle` prop. Not for direct use. */
79
+ attach(left: PanelEntry | null, right: PanelEntry | null): void;
80
+ /** Collapses both sidebars, or expands both when they are already all collapsed. */
81
+ toggleBoth: () => void;
82
+ }
50
83
  export {};
@@ -59,3 +59,49 @@ export class PanelState {
59
59
  }
60
60
  };
61
61
  }
62
+ /**
63
+ * Shared collapse target for a `PagePanelSidebars`'s left/right sidebar pair. Create one instance
64
+ * and pass it to `PagePanelSidebars`'s `toggle` prop, then read `toggleBoth` / `allCollapsed` from
65
+ * this instance wherever the external control lives (e.g. `PageLayout`'s `editorControls`) — no
66
+ * `bind:this` or extra local state needed on the consumer side.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const panels = new PanelState();
71
+ * const sidebarsToggle = new SidebarsToggle();
72
+ * ```
73
+ * ```svelte
74
+ * <PageLayout editorControls={{ panelsToggle: { active: sidebarsToggle.allCollapsed, onClick: sidebarsToggle.toggleBoth }, close: {...} }}>
75
+ * <PagePanels>
76
+ * <PagePanelSidebars panelState={panels} toggle={sidebarsToggle}>...</PagePanelSidebars>
77
+ * </PagePanels>
78
+ * </PageLayout>
79
+ * ```
80
+ */
81
+ export class SidebarsToggle {
82
+ _left = $state(null);
83
+ _right = $state(null);
84
+ /**
85
+ * True when every attached sidebar is currently collapsed.
86
+ * @remarks False both when there are no sidebars attached and before `PagePanelSidebars` mounts —
87
+ * an external toggle button reads this as "not active" in either case.
88
+ */
89
+ get allCollapsed() {
90
+ const entries = [this._left, this._right].filter((entry) => !!entry);
91
+ return entries.length > 0 && entries.every((entry) => entry.collapsed);
92
+ }
93
+ /** Wired automatically by the paired `PagePanelSidebars`'s `toggle` prop. Not for direct use. */
94
+ attach(left, right) {
95
+ this._left = left;
96
+ this._right = right;
97
+ }
98
+ /** Collapses both sidebars, or expands both when they are already all collapsed. */
99
+ toggleBoth = () => {
100
+ const entries = [this._left, this._right].filter((entry) => !!entry);
101
+ if (entries.length === 0) {
102
+ return;
103
+ }
104
+ const collapsed = entries.every((entry) => entry.collapsed);
105
+ entries.forEach((entry) => entry.setCollapsed(!collapsed));
106
+ };
107
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.38.2",
3
+ "version": "0.39.0",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",