@r2digisolutions/components 0.21.11 → 0.21.14

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.
@@ -6,8 +6,9 @@
6
6
  import IconButton from '../../atoms/IconButton/IconButton.svelte';
7
7
  import Badge from '../../atoms/Badge/Badge.svelte';
8
8
  import {
9
- AppChrome,
10
9
  getAppChrome,
10
+ getAppChromeEpoch,
11
+ getSharedAppChrome,
11
12
  setAppChrome,
12
13
  type AppShellContextual
13
14
  } from './app-chrome.svelte.js';
@@ -77,16 +78,7 @@
77
78
  children
78
79
  }: AppShellProps = $props();
79
80
 
80
- const chrome = (() => {
81
- try {
82
- return getAppChrome();
83
- } catch {
84
- const created = new AppChrome();
85
- setAppChrome(created);
86
- return created;
87
- }
88
- })();
89
-
81
+ // Resolve via singleton inside deriveds so HMR / duplicate graphs stay aligned.
90
82
  const propContextual = $derived.by((): AppShellContextual | null => {
91
83
  if (contextualGroups.length === 0) return null;
92
84
  return {
@@ -98,11 +90,20 @@
98
90
  };
99
91
  });
100
92
 
101
- const resolvedContextual = $derived(chrome.source?.() ?? propContextual);
93
+ const resolvedContextual = $derived.by(() => {
94
+ const chrome = getSharedAppChrome();
95
+ try {
96
+ getAppChrome();
97
+ } catch {
98
+ setAppChrome(chrome);
99
+ }
100
+ void getAppChromeEpoch();
101
+ return chrome.source?.() ?? propContextual;
102
+ });
102
103
  const contextualKey = $derived(
103
104
  resolvedContextual
104
- ? `${resolvedContextual.parentHref ?? ''}:${resolvedContextual.brand ?? ''}:${resolvedContextual.description ?? ''}`
105
- : ''
105
+ ? `${getAppChromeEpoch()}:${resolvedContextual.parentHref ?? ''}:${resolvedContextual.brand ?? ''}:${resolvedContextual.groups?.map((g) => g.id).join(',') ?? ''}`
106
+ : `none:${getAppChromeEpoch()}`
106
107
  );
107
108
  const showRail = $derived(rail.length > 0 || railFooter.length > 0);
108
109
  let mobileOpen = $state(false);
@@ -11,10 +11,20 @@ export interface AppShellContextual {
11
11
  header?: Snippet;
12
12
  onchange?: (id: string) => void;
13
13
  }
14
+ export type AppChromeClear = () => void;
15
+ export declare function getAppChromeEpoch(): number;
14
16
  export declare class AppChrome {
17
+ #private;
15
18
  /** Live reader so nested layouts stay reactive when `[id]` is reused. */
16
19
  source: (() => AppShellContextual | null) | null;
17
20
  get contextual(): AppShellContextual | null;
18
- setContextual(nav: AppShellContextual | (() => AppShellContextual | null) | null): void;
21
+ /**
22
+ * Register contextual sidebar. Returns a disposer that only clears if this
23
+ * registration is still active (safe across layout navigation races).
24
+ */
25
+ setContextual(nav: AppShellContextual | (() => AppShellContextual | null) | null): AppChromeClear;
19
26
  }
20
- export declare const getAppChrome: () => AppChrome, setAppChrome: (context: AppChrome) => AppChrome;
27
+ export declare function getSharedAppChrome(): AppChrome;
28
+ export declare function getAppChrome(): AppChrome;
29
+ /** Sets Svelte context and keeps `globalThis` in sync for duplicate module graphs. */
30
+ export declare function setAppChrome(chrome: AppChrome): void;
@@ -1,16 +1,71 @@
1
1
  import { createContext } from 'svelte';
2
+ const GLOBAL_KEY = '__r2_app_chrome__';
3
+ const EPOCH_KEY = '__r2_app_chrome_epoch__';
4
+ function epochBox() {
5
+ const g = globalThis;
6
+ if (!g[EPOCH_KEY])
7
+ g[EPOCH_KEY] = { value: 0 };
8
+ return g[EPOCH_KEY];
9
+ }
10
+ /** Reactive epoch — always read via this so AppShell tracks updates across module copies. */
11
+ let chromeEpoch = $state(0);
12
+ export function getAppChromeEpoch() {
13
+ // Prefer module signal; sync from global so duplicate graphs still move.
14
+ const box = epochBox();
15
+ if (box.value !== chromeEpoch)
16
+ chromeEpoch = box.value;
17
+ return chromeEpoch;
18
+ }
19
+ function bumpEpoch() {
20
+ const box = epochBox();
21
+ box.value += 1;
22
+ chromeEpoch = box.value;
23
+ }
2
24
  export class AppChrome {
3
25
  /** Live reader so nested layouts stay reactive when `[id]` is reused. */
4
26
  source = $state.raw(null);
27
+ /** Identity of the active source — cleanup no-ops if another layout already replaced it. */
28
+ #owner = null;
5
29
  get contextual() {
6
30
  return this.source?.() ?? null;
7
31
  }
32
+ /**
33
+ * Register contextual sidebar. Returns a disposer that only clears if this
34
+ * registration is still active (safe across layout navigation races).
35
+ */
8
36
  setContextual(nav) {
9
37
  if (nav === null) {
10
38
  this.source = null;
11
- return;
39
+ this.#owner = null;
40
+ bumpEpoch();
41
+ return () => { };
12
42
  }
13
- this.source = typeof nav === 'function' ? nav : () => nav;
43
+ const reader = typeof nav === 'function' ? nav : () => nav;
44
+ this.source = reader;
45
+ this.#owner = reader;
46
+ bumpEpoch();
47
+ return () => {
48
+ if (this.#owner !== reader)
49
+ return;
50
+ this.source = null;
51
+ this.#owner = null;
52
+ bumpEpoch();
53
+ };
14
54
  }
15
55
  }
16
- export const [getAppChrome, setAppChrome] = createContext();
56
+ export function getSharedAppChrome() {
57
+ const g = globalThis;
58
+ if (!g[GLOBAL_KEY])
59
+ g[GLOBAL_KEY] = new AppChrome();
60
+ return g[GLOBAL_KEY];
61
+ }
62
+ const [getAppChromeContext, setAppChromeContext] = createContext();
63
+ export function getAppChrome() {
64
+ return getAppChromeContext();
65
+ }
66
+ /** Sets Svelte context and keeps `globalThis` in sync for duplicate module graphs. */
67
+ export function setAppChrome(chrome) {
68
+ const g = globalThis;
69
+ g[GLOBAL_KEY] = chrome;
70
+ setAppChromeContext(chrome);
71
+ }
@@ -3,6 +3,7 @@ declare const meta: {
3
3
  title: string;
4
4
  component: import("svelte").Component<{
5
5
  collapsed?: boolean;
6
+ wizard?: boolean;
6
7
  }, {}, "">;
7
8
  tags: string[];
8
9
  argTypes: {
@@ -18,3 +19,4 @@ export default meta;
18
19
  type Story = StoryObj<typeof meta>;
19
20
  export declare const Default: Story;
20
21
  export declare const Collapsed: Story;
22
+ export declare const WizardStepper: Story;
@@ -11,3 +11,4 @@ const meta = {
11
11
  export default meta;
12
12
  export const Default = {};
13
13
  export const Collapsed = { args: { collapsed: true } };
14
+ export const WizardStepper = { args: { wizard: true } };
@@ -15,6 +15,10 @@
15
15
  href?: string;
16
16
  icon?: SidebarIcon;
17
17
  disabled?: boolean;
18
+ /** Completed step (wizard). Kept for a11y; no check glyph in the UI. */
19
+ done?: boolean;
20
+ /** Optional short hint (e.g. warning). */
21
+ hint?: string;
18
22
  }
19
23
 
20
24
  export interface SidebarGroup {
@@ -55,10 +59,11 @@
55
59
  }
56
60
 
57
61
  function itemClass(item: SidebarItem) {
62
+ const active = value === item.id;
58
63
  return [
59
- 'relative flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-sm transition-colors',
64
+ 'relative flex w-full items-center justify-start gap-2 rounded-lg px-2.5 py-2 text-left text-sm transition-colors',
60
65
  'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/30',
61
- value === item.id
66
+ active
62
67
  ? 'bg-surface-overlay font-medium text-primary'
63
68
  : 'text-secondary hover:bg-surface-overlay hover:text-primary',
64
69
  item.disabled && 'pointer-events-none cursor-not-allowed opacity-40',
@@ -70,9 +75,11 @@
70
75
  {#snippet itemGlyph(item: SidebarItem)}
71
76
  {#if item.icon}
72
77
  <item.icon class="h-4 w-4 shrink-0" strokeWidth={1.75} />
78
+ {:else if !collapsed}
79
+ <!-- No letter tile / check — labels stay flush left like the primary nav -->
73
80
  {:else}
74
81
  <span
75
- class="h-6 w-6 rounded-md bg-surface-overlay font-semibold flex shrink-0 items-center justify-center text-[11px]"
82
+ class="bg-surface-overlay h-6 w-6 rounded-md font-semibold flex shrink-0 items-center justify-center text-[11px]"
76
83
  >
77
84
  {item.label.slice(0, 1)}
78
85
  </span>
@@ -91,7 +98,10 @@
91
98
  <RailMark active={value === item.id} side="right" length="short" inset="sm" />
92
99
  {@render itemGlyph(item)}
93
100
  {#if !collapsed}
94
- <span class="truncate">{item.label}</span>
101
+ <span class="min-w-0 flex-1 truncate text-left">{item.label}</span>
102
+ {#if item.hint}
103
+ <span class="text-amber-600 dark:text-amber-400 shrink-0 text-[10px]">{item.hint}</span>
104
+ {/if}
95
105
  {/if}
96
106
  </a>
97
107
  {:else}
@@ -100,13 +110,17 @@
100
110
  disabled={item.disabled}
101
111
  title={collapsed ? item.label : undefined}
102
112
  aria-current={value === item.id ? 'page' : undefined}
113
+ aria-checked={item.done ? 'true' : undefined}
103
114
  class={itemClass(item)}
104
115
  onclick={() => select(item.id, item.disabled)}
105
116
  >
106
117
  <RailMark active={value === item.id} side="right" length="short" inset="sm" />
107
118
  {@render itemGlyph(item)}
108
119
  {#if !collapsed}
109
- <span class="truncate">{item.label}</span>
120
+ <span class="min-w-0 flex-1 truncate text-left">{item.label}</span>
121
+ {#if item.hint}
122
+ <span class="text-amber-600 dark:text-amber-400 shrink-0 text-[10px]">{item.hint}</span>
123
+ {/if}
110
124
  {/if}
111
125
  </button>
112
126
  {/if}
@@ -10,6 +10,10 @@ export interface SidebarItem {
10
10
  href?: string;
11
11
  icon?: SidebarIcon;
12
12
  disabled?: boolean;
13
+ /** Completed step (wizard). Kept for a11y; no check glyph in the UI. */
14
+ done?: boolean;
15
+ /** Optional short hint (e.g. warning). */
16
+ hint?: string;
13
17
  }
14
18
  export interface SidebarGroup {
15
19
  id: string;
@@ -4,9 +4,10 @@
4
4
 
5
5
  let props = $props<{
6
6
  collapsed?: boolean;
7
+ wizard?: boolean;
7
8
  }>();
8
9
 
9
- const groups: SidebarGroup[] = [
10
+ const defaultGroups: SidebarGroup[] = [
10
11
  {
11
12
  id: 'main',
12
13
  label: 'Workspace',
@@ -26,7 +27,30 @@
26
27
  }
27
28
  ];
28
29
 
29
- let value = $state('projects');
30
+ const wizardGroups: SidebarGroup[] = [
31
+ {
32
+ id: 'business',
33
+ label: 'Onboarding',
34
+ items: [{ id: 'business', label: 'Empresa', done: true }]
35
+ },
36
+ {
37
+ id: 'campaign',
38
+ label: 'Crea tu campaña',
39
+ items: [
40
+ { id: 'themes', label: 'Temas de búsqueda', done: true },
41
+ { id: 'ads', label: 'Crear anuncios' },
42
+ { id: 'bidding', label: 'Estrategia de puja' },
43
+ { id: 'budget', label: 'Presupuesto' }
44
+ ]
45
+ },
46
+ {
47
+ id: 'payment',
48
+ items: [{ id: 'payment', label: 'Detalles del pago' }]
49
+ }
50
+ ];
51
+
52
+ const groups = $derived(props.wizard ? wizardGroups : defaultGroups);
53
+ let value = $state(props.wizard ? 'ads' : 'projects');
30
54
  let collapsed = $state(props.collapsed ?? false);
31
55
  </script>
32
56
 
@@ -1,5 +1,6 @@
1
1
  type $$ComponentProps = {
2
2
  collapsed?: boolean;
3
+ wizard?: boolean;
3
4
  };
4
5
  declare const SidebarStory: import("svelte").Component<$$ComponentProps, {}, "">;
5
6
  type SidebarStory = ReturnType<typeof SidebarStory>;
package/dist/index.d.ts CHANGED
@@ -671,7 +671,7 @@ export type { BottomNavItem, BottomNavIcon } from './components/organisms/Bottom
671
671
  export { default as CommandPalette } from './components/organisms/CommandPalette/CommandPalette.svelte';
672
672
  export type { CommandItem, CommandIcon } from './components/organisms/CommandPalette/CommandPalette.svelte';
673
673
  export { default as AppShell } from './components/organisms/AppShell/AppShell.svelte';
674
- export { getAppChrome, setAppChrome, AppChrome } from './components/organisms/AppShell/app-chrome.svelte.js';
674
+ export { getAppChrome, getSharedAppChrome, setAppChrome, AppChrome } from './components/organisms/AppShell/app-chrome.svelte.js';
675
675
  export type { AppShellContextual } from './components/organisms/AppShell/app-chrome.svelte.js';
676
676
  export { default as EditorShell } from './components/organisms/EditorShell/EditorShell.svelte';
677
677
  export { default as BlueprintEditor } from './components/organisms/BlueprintEditor/BlueprintEditor.svelte';
package/dist/index.js CHANGED
@@ -463,7 +463,7 @@ export { default as Navbar } from './components/organisms/Navbar/Navbar.svelte';
463
463
  export { default as BottomNav } from './components/organisms/BottomNav/BottomNav.svelte';
464
464
  export { default as CommandPalette } from './components/organisms/CommandPalette/CommandPalette.svelte';
465
465
  export { default as AppShell } from './components/organisms/AppShell/AppShell.svelte';
466
- export { getAppChrome, setAppChrome, AppChrome } from './components/organisms/AppShell/app-chrome.svelte.js';
466
+ export { getAppChrome, getSharedAppChrome, setAppChrome, AppChrome } from './components/organisms/AppShell/app-chrome.svelte.js';
467
467
  export { default as EditorShell } from './components/organisms/EditorShell/EditorShell.svelte';
468
468
  export { default as BlueprintEditor } from './components/organisms/BlueprintEditor/BlueprintEditor.svelte';
469
469
  export { default as CanvasEditor } from './components/organisms/CanvasEditor/CanvasEditor.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.21.11",
3
+ "version": "0.21.14",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",