@happyvertical/smrt-playground 0.40.64 → 0.40.66

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,6 +3,7 @@ import {
3
3
  ColorSchemeToggle,
4
4
  ThemeProvider,
5
5
  ThemeSwitcher,
6
+ tryGetThemeContext,
6
7
  } from '@happyvertical/smrt-ui/themes';
7
8
  import type { Component } from 'svelte';
8
9
  import { onMount } from 'svelte';
@@ -18,12 +19,18 @@ export interface Props {
18
19
  modules?: SmrtPlaygroundModule[];
19
20
  title?: string;
20
21
  subtitle?: string;
22
+ embedded?: boolean;
23
+ selectedEntryId?: string | null;
24
+ hideEntryList?: boolean;
21
25
  }
22
26
 
23
27
  let {
24
28
  modules = [],
25
29
  title = 's-m-r-t playground',
26
30
  subtitle = 'Shared package previews with app-local overrides',
31
+ embedded = false,
32
+ selectedEntryId: controlledSelectedEntryId = null,
33
+ hideEntryList = false,
27
34
  }: Props = $props();
28
35
 
29
36
  const foundationPackageName = '@happyvertical/smrt-ui';
@@ -38,6 +45,7 @@ let selectedModuleName = $state<string | null>(null);
38
45
  let selectedEntryId = $state<string | null>(null);
39
46
  let selectedMode = $state<SmrtPlaygroundMode>('mock');
40
47
  let isHydrated = $state(false);
48
+ const inheritedThemeContext = tryGetThemeContext();
41
49
 
42
50
  onMount(() => {
43
51
  isHydrated = true;
@@ -125,7 +133,14 @@ const foundationGroups = $derived.by(() => {
125
133
  });
126
134
 
127
135
  $effect(() => {
128
- const firstModule = orderedModules[0] ?? null;
136
+ const controlledModule = controlledSelectedEntryId
137
+ ? (orderedModules.find((module) =>
138
+ module.entries.some(
139
+ (entry) => entry.qualifiedId === controlledSelectedEntryId,
140
+ ),
141
+ ) ?? null)
142
+ : null;
143
+ const firstModule = controlledModule ?? orderedModules[0] ?? null;
129
144
  if (!firstModule) {
130
145
  selectedModuleName = null;
131
146
  selectedEntryId = null;
@@ -133,28 +148,32 @@ $effect(() => {
133
148
  }
134
149
 
135
150
  const activeModule =
151
+ controlledModule ??
136
152
  orderedModules.find(
137
153
  (module) => module.packageName === selectedModuleName,
138
- ) ?? firstModule;
154
+ ) ??
155
+ firstModule;
139
156
 
140
157
  if (activeModule.packageName !== selectedModuleName) {
141
158
  selectedModuleName = activeModule.packageName;
142
159
  selectedEntryId =
143
- activeModule.packageName === foundationPackageName
160
+ controlledSelectedEntryId ??
161
+ (activeModule.packageName === foundationPackageName || hideEntryList
144
162
  ? (activeModule.entries[0]?.qualifiedId ?? null)
145
- : null;
163
+ : null);
146
164
  selectedMode = activeModule.entries[0]?.availableModes[0] ?? 'mock';
147
165
  return;
148
166
  }
149
167
 
150
- if (selectedEntryId === null) {
168
+ const requestedEntryId = controlledSelectedEntryId ?? selectedEntryId;
169
+ if (requestedEntryId === null && !hideEntryList) {
151
170
  return;
152
171
  }
153
172
 
154
173
  const activeEntry =
155
174
  activeModule.entries.find(
156
- (entry) => entry.qualifiedId === selectedEntryId,
157
- ) ?? null;
175
+ (entry) => entry.qualifiedId === requestedEntryId,
176
+ ) ?? (hideEntryList ? (activeModule.entries[0] ?? null) : null);
158
177
 
159
178
  if (!activeEntry) {
160
179
  selectedEntryId = null;
@@ -174,8 +193,9 @@ const selectedModule = $derived(
174
193
  );
175
194
  const selectedEntry = $derived(
176
195
  selectedModule?.entries.find(
177
- (entry) => entry.qualifiedId === selectedEntryId,
178
- ) ?? null,
196
+ (entry) =>
197
+ entry.qualifiedId === (controlledSelectedEntryId ?? selectedEntryId),
198
+ ) ?? (hideEntryList ? (selectedModule?.entries[0] ?? null) : null),
179
199
  );
180
200
  const selectedModeConfig = $derived(
181
201
  selectedEntry ? (selectedEntry.modes[selectedMode] ?? null) : null,
@@ -297,8 +317,13 @@ function selectEntry(entry: ResolvedSmrtPlaygroundEntry) {
297
317
  </button>
298
318
  {/snippet}
299
319
 
300
- <ThemeProvider colorScheme="system" persist={true}>
301
- <div class="playground-shell" data-hydrated={isHydrated ? 'true' : 'false'}>
320
+ {#snippet playgroundShell()}
321
+ <div
322
+ class="playground-shell"
323
+ class:playground-shell--embedded={embedded}
324
+ data-hydrated={isHydrated ? 'true' : 'false'}
325
+ >
326
+ {#if !embedded}
302
327
  <aside class="catalog-nav">
303
328
  <header class="brand">
304
329
  <span class="brand__mark" aria-hidden="true">S</span>
@@ -377,6 +402,7 @@ function selectEntry(entry: ResolvedSmrtPlaygroundEntry) {
377
402
  <ColorSchemeToggle />
378
403
  </footer>
379
404
  </aside>
405
+ {/if}
380
406
 
381
407
  <main class="workspace">
382
408
  {#if selectedModule}
@@ -471,7 +497,15 @@ function selectEntry(entry: ResolvedSmrtPlaygroundEntry) {
471
497
  {/if}
472
498
  </main>
473
499
  </div>
474
- </ThemeProvider>
500
+ {/snippet}
501
+
502
+ {#if inheritedThemeContext}
503
+ {@render playgroundShell()}
504
+ {:else}
505
+ <ThemeProvider colorScheme="system" persist={true}>
506
+ {@render playgroundShell()}
507
+ </ThemeProvider>
508
+ {/if}
475
509
 
476
510
  <style>
477
511
  :global(body) {
@@ -492,6 +526,11 @@ function selectEntry(entry: ResolvedSmrtPlaygroundEntry) {
492
526
  font-family: var(--smrt-font-family);
493
527
  }
494
528
 
529
+ .playground-shell--embedded {
530
+ grid-template-columns: 1fr;
531
+ min-height: 0;
532
+ }
533
+
495
534
  button,
496
535
  input {
497
536
  font: inherit;
@@ -701,6 +740,10 @@ function selectEntry(entry: ResolvedSmrtPlaygroundEntry) {
701
740
  padding: 1.25rem clamp(1.25rem, 3vw, 3rem) 3rem;
702
741
  }
703
742
 
743
+ .playground-shell--embedded .workspace {
744
+ padding: 0;
745
+ }
746
+
704
747
  .workspace-header {
705
748
  display: flex;
706
749
  min-height: 2.75rem;
@@ -4,6 +4,9 @@ export interface Props {
4
4
  modules?: SmrtPlaygroundModule[];
5
5
  title?: string;
6
6
  subtitle?: string;
7
+ embedded?: boolean;
8
+ selectedEntryId?: string | null;
9
+ hideEntryList?: boolean;
7
10
  }
8
11
  declare const PlaygroundHost: Component<Props, {}, "">;
9
12
  type PlaygroundHost = ReturnType<typeof PlaygroundHost>;
@@ -1 +1 @@
1
- {"version":3,"file":"PlaygroundHost.svelte.d.ts","sourceRoot":"","sources":["../../src/svelte/PlaygroundHost.svelte.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,KAAK,EAIV,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,KAAK;IACpB,OAAO,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA0bD,QAAA,MAAM,cAAc,0BAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"PlaygroundHost.svelte.d.ts","sourceRoot":"","sources":["../../src/svelte/PlaygroundHost.svelte.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,KAAK,EAIV,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,KAAK;IACpB,OAAO,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAodD,QAAA,MAAM,cAAc,0BAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-playground",
3
- "version": "0.40.64",
3
+ "version": "0.40.66",
4
4
  "description": "Shared playground discovery, runtime, and host components for SMRT UI packages",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "fast-glob": "3.3.3",
31
31
  "tsx": "^4.23.0",
32
- "@happyvertical/smrt-ui": "0.40.64"
32
+ "@happyvertical/smrt-ui": "0.40.66"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "svelte": "^5.56.4",