@bridgebrew/design-system 0.0.0-stage → 0.1.9

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.
@@ -0,0 +1,201 @@
1
+ // The pieces every story page is made of, all kit: a `Group` (a Section framing its samples in an outline Card) and a
2
+ // `Sample` (a captioned item), laid out by the plugin's CSS only. Plus the fake server the search stories ask.
3
+ import * as React from 'react';
4
+ import { Button, Card, CodeBlock, Collapsible, CollapsiblePanel, CollapsibleTrigger, Icon, ScreenLink, ScrollArea, Section, Tabs, TabsList, TabsTrigger, type CodeToken } from '@bridge/ui';
5
+ import { tokensOf } from '../highlight.ts';
6
+
7
+ /** How a frame places its samples: in wrapping rows, a grid of equal cells (narrow, or `columns`: wide), a column,
8
+ * one full-width child, or one child edge to edge (`bleed`: a layout, as on a screen). */
9
+ type Layout = 'row' | 'grid' | 'columns' | 'stack' | 'fill' | 'bleed';
10
+
11
+ export function Group({ title, description, layout = 'row', code, actions, children }: {
12
+ title: string; description?: React.ReactNode; layout?: Layout; children: React.ReactNode;
13
+ /** At the group's header end (a button). */
14
+ actions?: React.ReactNode;
15
+ /** The React that draws the sample, under it in a "Code" disclosure (closed), as Storybook's "Show code". */
16
+ code?: string;
17
+ }) {
18
+ return (
19
+ <Section title={title} description={description} actions={actions}>
20
+ <Card variant="outline" size="lg" className={`ds-frame ds-layout-${layout}`}>{children}</Card>
21
+ {code !== undefined && (
22
+ <Collapsible className="ds-code">
23
+ <CollapsibleTrigger>Code</CollapsibleTrigger>
24
+ <CollapsiblePanel><Code code={code} /></CollapsiblePanel>
25
+ </Collapsible>
26
+ )}
27
+ </Section>
28
+ );
29
+ }
30
+
31
+ /** A sample's code, coloured once Shiki has cut it (plain until then). */
32
+ export function Code({ code, language = 'tsx' }: { code: string; language?: string }) {
33
+ const [tokens, setTokens] = React.useState<CodeToken[][]>();
34
+ React.useEffect(() => {
35
+ let live = true;
36
+ tokensOf(code, language)
37
+ .then((next) => live && setTokens(next))
38
+ .catch(() => live && setTokens(undefined));
39
+ return () => {
40
+ live = false;
41
+ };
42
+ }, [code, language]);
43
+ return <CodeBlock language={language} code={code} tokens={tokens} />;
44
+ }
45
+
46
+ export type Device = 'desktop' | 'mobile';
47
+
48
+ /** A layout's page: Desktop and Mobile tabs, each frame then drawn as that device's screen (`Screen`). */
49
+ export function Devices({ children }: { children: (device: Device) => React.ReactNode }) {
50
+ const [device, setDevice] = React.useState<Device>('desktop');
51
+ return (
52
+ <>
53
+ <Tabs value={device} onValueChange={(value) => setDevice(value === 'mobile' ? 'mobile' : 'desktop')}>
54
+ <TabsList>
55
+ <TabsTrigger value="desktop">Desktop</TabsTrigger>
56
+ <TabsTrigger value="mobile">Mobile</TabsTrigger>
57
+ </TabsList>
58
+ </Tabs>
59
+ {children(device)}
60
+ </>
61
+ );
62
+ }
63
+
64
+ /** A device's screen in its ratio: desktop a 1080p screen (16:9) across the frame, mobile an iPhone 15 (393 × 852). */
65
+ export function Screen({ device, children }: { device: Device; children: React.ReactNode }) {
66
+ if (device === 'desktop') return <DesktopScreen>{children}</DesktopScreen>;
67
+ // A phone: its glass rounded inside the frame, the status bar's and the home indicator's room kept free.
68
+ return <div className="ds-screen ds-screen-mobile"><div className="ds-screen-glass">{children}</div></div>;
69
+ }
70
+
71
+ /** The narrowest a desktop screen is drawn: a narrower frame (a phone) shows it shrunk, not rearranged as a phone's. */
72
+ const desktopWidth = 1024;
73
+
74
+ /** A desktop's screen: drawn at its frame's width, or at `desktopWidth` scaled down to fit a narrower frame. */
75
+ function DesktopScreen({ children }: { children: React.ReactNode }) {
76
+ const frame = React.useRef<HTMLDivElement>(null);
77
+ const [scale, setScale] = React.useState(1);
78
+ React.useLayoutEffect(() => {
79
+ const element = frame.current;
80
+ if (!element || typeof ResizeObserver === 'undefined') return;
81
+ const observer = new ResizeObserver(([entry]) => entry && setScale(Math.min(1, entry.contentRect.width / desktopWidth)));
82
+ observer.observe(element);
83
+ return () => observer.disconnect();
84
+ }, []);
85
+ return (
86
+ <div ref={frame} className="ds-screen ds-screen-desktop">
87
+ <div className="ds-screen-scaled" style={{ width: `${100 / scale}%`, height: `${100 / scale}%`, transform: `scale(${scale})` }}>{children}</div>
88
+ </div>
89
+ );
90
+ }
91
+
92
+ /** A sample made for a wider screen (a table's columns, a desktop's shell): drawn at its width, scrolling sideways in a
93
+ * narrower frame (a phone) rather than squeezed. */
94
+ export function Wide({ children }: { children: React.ReactNode }) {
95
+ return <ScrollArea orientation="horizontal"><div className="ds-min-wide">{children}</div></ScrollArea>;
96
+ }
97
+
98
+ /** The Template screen's own path, without an item (`/<workspace>[/<node>…]/design-system/template`), from this page's,
99
+ * whichever screen and item it shows. */
100
+ const templateScreenPath = () => {
101
+ const path = location.pathname;
102
+ const at = path.lastIndexOf('/design-system');
103
+ return `${at >= 0 ? path.slice(0, at) : ''}/design-system/template`;
104
+ };
105
+
106
+ /** The Template screen on a phone, open on `template` (its story id): a frame named `bridge-phone`, which Bridge shows in
107
+ * its phone shell (header, Back, the text size), the screen's phone form inside. */
108
+ export function PhonePreview({ title, template }: { title: string; template: string }) {
109
+ return <Screen device="mobile"><iframe name="bridge-phone" title={title} src={`${templateScreenPath()}/${template}`} className="ds-phone-frame" /></Screen>;
110
+ }
111
+
112
+ /** A phone's way through a layout: one phone per step (each pane alone), an arrow between, a caption under each;
113
+ * scrolling sideways when the steps do not fit (a phone). */
114
+ export function PhoneFlow({ steps }: { steps: { label: string; screen: React.ReactNode }[] }) {
115
+ return (
116
+ <ScrollArea orientation="horizontal"><div className="ds-flow">
117
+ {steps.map((step, i) => (
118
+ <React.Fragment key={step.label}>
119
+ {i > 0 && <span className="ds-flow-arrow" aria-hidden>→</span>}
120
+ <div className="ds-flow-step"><Screen device="mobile">{step.screen}</Screen><span>{step.label}</span></div>
121
+ </React.Fragment>
122
+ ))}
123
+ </div></ScrollArea>
124
+ );
125
+ }
126
+
127
+ /** One captioned item of a frame (a variant, a size, a state). */
128
+ export function Sample({ title, description, children, wide }: {
129
+ title: string; description?: React.ReactNode; children?: React.ReactNode; wide?: boolean;
130
+ }) {
131
+ return (
132
+ <Section size="sm" title={title} description={description} className={wide ? 'ds-sample ds-wide' : 'ds-sample'}>
133
+ {children !== undefined && <div className="ds-sample-body">{children}</div>}
134
+ </Section>
135
+ );
136
+ }
137
+
138
+ /** Lower case, without accents. */
139
+ const fold = (text: string) => text.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
140
+
141
+ /** A pretend server search over `all`: each text gets its matches after `delay` ms (the empty text at once, the first
142
+ * `take`); while one is on its way the list is empty and `loading`. Only the latest answer lands. */
143
+ export function useFakeSearch<T>(all: readonly T[], toText: (item: T) => string, { delay = 400, take = 20 } = {}) {
144
+ const first = React.useMemo(() => all.slice(0, take), [all, take]);
145
+ const [state, setState] = React.useState<{ items: readonly T[]; loading: boolean }>({ items: first, loading: false });
146
+ const asks = React.useRef(0);
147
+ const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
148
+ React.useEffect(() => () => clearTimeout(timer.current), []);
149
+ const ask = React.useCallback((text: string) => {
150
+ const mine = ++asks.current;
151
+ clearTimeout(timer.current);
152
+ const query = fold(text.trim());
153
+ if (query === '') return setState({ items: first, loading: false });
154
+ setState({ items: [], loading: true });
155
+ timer.current = setTimeout(() => {
156
+ if (mine !== asks.current) return;
157
+ setState({ items: all.filter((each) => fold(toText(each)).includes(query)).slice(0, take), loading: false });
158
+ }, delay);
159
+ }, [all, first, toText, delay, take]);
160
+ return { ...state, ask };
161
+ }
162
+
163
+ /** Re-renders on a theme change (the shell sets `<html data-theme>`, or the system's scheme flips). */
164
+ export function useTheme() {
165
+ const read = () => `${document.documentElement.dataset.theme ?? ''}/${matchMedia('(prefers-color-scheme: dark)').matches}`;
166
+ return React.useSyncExternalStore((changed) => {
167
+ const observer = new MutationObserver(changed);
168
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
169
+ const scheme = matchMedia('(prefers-color-scheme: dark)');
170
+ scheme.addEventListener('change', changed);
171
+ return () => { observer.disconnect(); scheme.removeEventListener('change', changed); };
172
+ }, read);
173
+ }
174
+
175
+ /** Sample people and organizations, for lists, pickers and tables. */
176
+ export const people = [
177
+ 'Ada Lindqvist', 'Bruno Okafor', 'Chloé Martin', 'Dmitri Volkov', 'Elif Şahin', 'Farah Haddad', 'Gustavo Reyes',
178
+ 'Hana Kobayashi', 'Ines Duarte', 'Jonas Becker', 'Kirra Walsh', 'Luca Romano', 'Maya Patel', 'Nils Eriksson',
179
+ 'Olivia Brennan', 'Priya Raman', 'Quentin Moreau', 'Rosa Jiménez', 'Sven Larsen', 'Tomás Ortega', 'Uma Nair',
180
+ 'Victor Hugo Lemaire', 'Wen Li', 'Yusuf Demir', 'Zoé Laurent',
181
+ ] as const;
182
+
183
+ export const organizations = [
184
+ 'Northwind', 'Windmill Labs', 'Bluewind Energy', 'Southwind Freight', 'Acme', 'Tessera', 'Globex', 'Initech',
185
+ 'Umbrella Health', 'Stark Industries', 'Wayne Enterprises', 'Hooli', 'Pied Piper', 'Vandelay Imports', 'Soylent',
186
+ 'Cyberdyne', 'Massive Dynamic', 'Oscorp', 'Wonka Industries', 'Monarch Solutions', 'Gringotts', 'Aperture Science',
187
+ 'Black Mesa', 'Tyrell Corporation', 'Weyland-Yutani', 'Nakatomi Trading', 'Duff Brewing', 'Kwik-E-Mart',
188
+ ] as const;
189
+
190
+ /** The Template screen's item for `template` alone, as a real screen (no row open): `<template>/~`. */
191
+ export const fullscreenItem = (template: string) => `${template}/~`;
192
+
193
+ /** Opens a template alone, as a real screen of Bridge (its breadcrumb, Back returns here); ⌘-click, in a window beside. */
194
+ export function FullscreenLink({ template }: { template: string }) {
195
+ return (
196
+ <Button variant="outline" size="sm" render={<ScreenLink to={{ item: fullscreenItem(template) }} />}>
197
+ <Icon name="maximize-2" size={14} />
198
+ Fullscreen
199
+ </Button>
200
+ );
201
+ }
package/stories.ts ADDED
@@ -0,0 +1,149 @@
1
+ // The storyboard's registry: each story's id (the screen's item, `/<workspace>/<node>/design-system/<id>`), title,
2
+ // layer and one-line description, in list order, grouped by the kit's layers (research-070). Bridge's sidebar shows
3
+ // Design system, a home, with one screen per layer under it: Foundations, Core, Layout, Composite, Template and Shell
4
+ // (`screens`). A component's id is its folder in the kit (`packages/ui/src/components/<layer>/<id>/`,
5
+ // or its `*.meta.yaml` name), and its layer that folder's: `model.test.ts` checks both, so a new kit component without a
6
+ // story fails the tests. The stories themselves (React) are in
7
+ // `stories/<topic>.tsx` (action, input, overlay…), keyed by these ids (the typecheck checks each id has one). Plain data, run by `node --test`.
8
+
9
+ export const layers = [
10
+ { id: 'foundations', title: 'Foundations', icon: 'palette' },
11
+ { id: 'core', title: 'Core', icon: 'box' },
12
+ { id: 'layout', title: 'Layout', icon: 'dashboard' },
13
+ { id: 'composite', title: 'Composite', icon: 'puzzle' },
14
+ { id: 'template', title: 'Template', icon: 'files' },
15
+ { id: 'shell', title: 'Shell', icon: 'app-window' },
16
+ ] as const;
17
+
18
+ export type Layer = (typeof layers)[number]['id'];
19
+
20
+ export interface Story {
21
+ id: string;
22
+ title: string;
23
+ layer: Layer;
24
+ description: string;
25
+ /** Not a kit component (Foundations). */
26
+ foundation?: true;
27
+ }
28
+
29
+ export const stories = [
30
+ { id: 'colors', title: 'Colors', layer: 'foundations', foundation: true, description: 'The semantic colour tokens of the current theme, read live from the page.' },
31
+ { id: 'typography', title: 'Typography', layer: 'foundations', foundation: true, description: 'The type scale, weights and font stacks the kit uses.' },
32
+ { id: 'sizes', title: 'Sizes and radii', layer: 'foundations', foundation: true, description: 'Control heights, corner radii and shadows.' },
33
+ { id: 'icons', title: 'Icons', layer: 'foundations', foundation: true, description: 'Every name the Icon component knows, for manifests and plugins.' },
34
+
35
+ { id: 'button', title: 'Button', layer: 'core', description: 'Triggers an action: five variants, text and icon-only sizes.' },
36
+ { id: 'checkbox', title: 'Checkbox', layer: 'core', description: 'A boolean choice, with an indeterminate state for a partial selection.' },
37
+ { id: 'editable-field', title: 'Editable field', layer: 'core', description: 'A value edited in place, with its save state: saving, saved, failed, conflict.' },
38
+ { id: 'combobox', title: 'Combobox', layer: 'core', description: 'A typed single-value picker for forms, over a local list or a server search.' },
39
+ { id: 'colour-picker', title: 'Colour picker', layer: 'core', description: "A colour among the theme's first, then more of them, then any." },
40
+ { id: 'field', title: 'Field', layer: 'core', description: 'Wires a label, a description and an error to a form control.' },
41
+ { id: 'input', title: 'Input', layer: 'core', description: 'Single-line text: inline for detail cards, outline for forms.' },
42
+ { id: 'pick-menu', title: 'Pick menu', layer: 'core', description: 'A keyboard-first menu opened from any anchor: search, number keys, Create.' },
43
+ { id: 'segment-group', title: 'Segment group', layer: 'core', description: 'A compact switch between a few exclusive options.' },
44
+ { id: 'select', title: 'Select', layer: 'core', description: 'Picks one value from a short list in a form.' },
45
+ { id: 'slider', title: 'Slider', layer: 'core', description: 'One number on a range, dragged or keyed.' },
46
+ { id: 'textarea', title: 'Textarea', layer: 'core', description: 'Multi-line text that grows with its content.' },
47
+ { id: 'tag-menu', title: 'Tag menu', layer: 'core', description: "A record's tags: the known ones with counts, checked, and Create for a new one." },
48
+ { id: 'drop-zone', title: 'Drop zone', layer: 'core', description: 'A place to drop files, with an overlay while dragging and a file picker.' },
49
+ { id: 'toggle', title: 'Toggle', layer: 'core', description: 'An on/off switch that applies at once.' },
50
+ { id: 'toggle-group', title: 'Toggle group', layer: 'core', description: 'A row of toggle buttons in one track, any number pressed.' },
51
+ { id: 'avatar', title: 'Avatar', layer: 'core', description: 'Initials for a person or an organization, tinted from the name.' },
52
+ { id: 'badge', title: 'Badge', layer: 'core', description: 'A small count or status pill.' },
53
+ { id: 'kbd', title: 'Kbd', layer: 'core', description: 'A key as a small cap, plain or inside a primary button.' },
54
+ { id: 'icon', title: 'Icon', layer: 'core', description: 'A named, decorative glyph in the current text colour.' },
55
+ { id: 'label', title: 'Label', layer: 'core', description: 'A coloured category chip with a dot.' },
56
+ { id: 'status-icon', title: 'Status icon', layer: 'core', description: 'A workflow state as a small circle.' },
57
+ { id: 'tag-pill', title: 'Tag pill', layer: 'core', description: "A tag as a round pill with a dot coloured from its name, a list, a filter chip." },
58
+ { id: 'thumbnail', title: 'Thumbnail', layer: 'core', description: 'A square tile of a media or file grid, its name below.' },
59
+ { id: 'table', title: 'Table', layer: 'core', description: 'Grid rows with headers, groups and collapsible sections.' },
60
+ { id: 'breadcrumb', title: 'Breadcrumb', layer: 'core', description: 'Where the page sits, each ancestor a way back.' },
61
+ { id: 'bullets', title: 'Bullets', layer: 'core', description: 'Dots saying which of a few items shows, a click going to one.' },
62
+ { id: 'screen-link', title: 'Screen link', layer: 'core', description: "A link to a screen whose clicks follow Bridge's rule: here, beside, a new desk." },
63
+ { id: 'tabs', title: 'Tabs', layer: 'core', description: 'Switches between views of the same content.' },
64
+ { id: 'dialog', title: 'Dialog', layer: 'core', description: 'A modal window for a focused task.' },
65
+ { id: 'dropdown-menu', title: 'Dropdown menu', layer: 'core', description: 'Actions in a menu, from a button or a right-click.' },
66
+ { id: 'popover', title: 'Popover', layer: 'core', description: 'A floating panel tied to its trigger, for a picker, a filter or a small form.' },
67
+ { id: 'tooltip', title: 'Tooltip', layer: 'core', description: 'Names an icon-only control on hover and focus.' },
68
+ { id: 'toast', title: 'Toast', layer: 'core', description: 'A short notice in the corner, fading on its own.' },
69
+ { id: 'empty-state', title: 'Empty state', layer: 'core', description: 'A pane with nothing to show: an icon, a title, words and actions.' },
70
+ { id: 'progress', title: 'Progress', layer: 'core', description: 'A progress bar: a share done, or indeterminate while the length is unknown.' },
71
+ { id: 'skeleton', title: 'Skeleton', layer: 'core', description: "Pulsing placeholders, and a list's and a record page's loading shapes." },
72
+ { id: 'card', title: 'Card', layer: 'core', description: 'A surface that groups related content.' },
73
+ { id: 'cluster', title: 'Cluster', layer: 'core', description: 'Things side by side on a line, wrapping when they must.' },
74
+ { id: 'detail', title: 'Detail', layer: 'core', description: "A record's page: a header with its title block, its rows and a hint." },
75
+ { id: 'resizable', title: 'Resizable', layer: 'core', description: 'Panels split by a draggable handle.' },
76
+ { id: 'scroll-area', title: 'Scroll area', layer: 'core', description: 'Scrolling with a thin overlay scrollbar.' },
77
+ { id: 'main-content', title: 'Main content', layer: 'core', description: "A main pane's content: its margins and its centred column, read, wide or full." },
78
+ { id: 'pane', title: 'Pane', layer: 'core', description: "A list's column: a toolbar, a scrolling body, a footer and a last-line note." },
79
+ { id: 'section', title: 'Section', layer: 'core', description: 'A titled block at three scales: a page, a section, a caption.' },
80
+ { id: 'split-view', title: 'Split view', layer: 'core', description: 'MultiPane split into columns or rows, resizable or fixed, nestable for a grid.' },
81
+ { id: 'collapsible', title: 'Collapsible', layer: 'core', description: 'A trigger that shows or hides a panel, closed at first.' },
82
+ { id: 'code-block', title: 'Code block', layer: 'core', description: 'Code to read and copy, long lines scrolling sideways.' },
83
+ { id: 'sortable', title: 'Sortable', layer: 'core', description: 'Reorders items by drag, in a list or across a board.' },
84
+
85
+ { id: 'single-pane', title: 'Single pane', layer: 'layout', description: 'One pane that scrolls: a centred column to read, or the whole width.' },
86
+ { id: 'multi-pane', title: 'Multi pane', layer: 'layout', description: 'Two or three panes, nav | main | aside; when room runs out they leave from the right.' },
87
+
88
+ { id: 'image-field', title: 'Image field', layer: 'composite', description: 'One image in a form: upload, preview, replace or remove it.' },
89
+ { id: 'picker', title: 'Picker', layer: 'composite', description: 'A Linear-style property menu for detail cards, keyboard-first.' },
90
+ { id: 'prompt-field', title: 'Prompt field', layer: 'composite', description: 'A message and its Send: Enter sends, Shift+Enter a new line.' },
91
+ { id: 'tag-input', title: 'Tag input', layer: 'composite', description: 'Free-form tags as chips: Enter or a comma adds, Backspace removes.' },
92
+ { id: 'list', title: 'List', layer: 'composite', description: 'Rows to browse and select, with groups and keyboard navigation.' },
93
+ { id: 'properties', title: 'Properties', layer: 'composite', description: 'Label and value rows for a detail card, edited in place.' },
94
+ { id: 'command', title: 'Command', layer: 'composite', description: "A screen's commands: their keys, the key hints and the ⌘K menu." },
95
+ { id: 'snooze-menu', title: 'Snooze menu', layer: 'composite', description: 'Puts an item away until a preset or chosen time.' },
96
+ { id: 'wizard', title: 'Wizard', layer: 'composite', description: 'A dialog in steps, where a first choice decides the next.' },
97
+ { id: 'draft-bar', title: 'Draft bar', layer: 'composite', description: 'Under a record not created yet: kept, or what stops Create, then Cancel and Create.' },
98
+
99
+ { id: 'address-book-template', title: 'Address book', layer: 'template', description: 'Sample people: MultiPane, a searchable list, a record.' },
100
+ { id: 'mail-template', title: 'Mail', layer: 'template', description: 'Sample mails: MultiPane, an inbox grouped by day (sender, subject, the text\'s start; unread, a dot), the mail open, its actions.' },
101
+
102
+ { id: 'sidebar', title: 'Sidebar', layer: 'shell', description: 'The app navigation: items, sections, groups, a tree and a resize handle.' },
103
+ { id: 'app-shell', title: 'App shell', layer: 'shell', description: 'The page frame: a header, a sidebar and the main area.' },
104
+ ] as const satisfies readonly Story[];
105
+
106
+ export type StoryId = (typeof stories)[number]['id'];
107
+
108
+ /** Lower case, without accents: what search compares. */
109
+ export const fold = (text: string) => text.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
110
+
111
+ /** The screens in Bridge's sidebar (research-070): Design system, the home (an introduction and the sections, no story),
112
+ * then one child screen per layer, each listing its layer's stories. */
113
+ export const screens = {
114
+ 'design-system': [],
115
+ foundations: ['foundations'],
116
+ core: ['core'],
117
+ layout: ['layout'],
118
+ composite: ['composite'],
119
+ template: ['template'],
120
+ shell: ['shell'],
121
+ } as const satisfies Record<string, readonly Layer[]>;
122
+
123
+ export type ScreenId = keyof typeof screens;
124
+
125
+ /** Screen `screen`'s stories, in list order; the home, or an unknown screen, none. */
126
+ export const storiesOf = (screen: string): readonly Story[] => {
127
+ const own: readonly Layer[] = screens[screen as ScreenId] ?? [];
128
+ return stories.filter((story) => own.includes(story.layer));
129
+ };
130
+
131
+ /** The screen showing a story: its layer's. */
132
+ export const screenOf = (story: Story): ScreenId => story.layer;
133
+
134
+ /** Screen `screen`'s stories whose title, id or layer matches `query` (inside words, any case or accent), in list order. */
135
+ export const search = (query: string, screen: string): readonly Story[] => {
136
+ const words = fold(query).split(/\s+/).filter(Boolean);
137
+ const own = storiesOf(screen);
138
+ if (words.length === 0) return own;
139
+ return own.filter((story) => {
140
+ const text = fold(`${story.title} ${story.id} ${layers.find((each) => each.id === story.layer)!.title}`);
141
+ return words.every((word) => text.includes(word));
142
+ });
143
+ };
144
+
145
+ /** The story an item names on screen `screen`; an unknown item, one of another screen, or none, gives its first story. */
146
+ export const storyOf = (item: string | undefined, screen: string): Story => {
147
+ const own = storiesOf(screen);
148
+ return own.find((story) => story.id === item) ?? own[0] ?? stories[0];
149
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2024",
4
+ "lib": ["ES2024", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "jsx": "react-jsx",
8
+ "strict": true,
9
+ "noEmit": true,
10
+ "allowImportingTsExtensions": true,
11
+ "erasableSyntaxOnly": true,
12
+ "verbatimModuleSyntax": true,
13
+ "noUncheckedIndexedAccess": true,
14
+ "exactOptionalPropertyTypes": false,
15
+ "skipLibCheck": true,
16
+ "noUncheckedSideEffectImports": false,
17
+ "types": ["node"]
18
+ },
19
+ "include": ["*.ts", "*.tsx", "stories/*.tsx"]
20
+ }