@gjsify/storybook-core 0.38.1 → 0.40.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.
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";const e=[`Overview`,`Presentation`,`Boxed Lists`,`Controls`,`Buttons`,`Layout`,`View Switching`,`Navigation`,`Feedback`];function orderCategories(t){let n=new Map(e.map((e,t)=>[e,t])),r=[...t].filter(e=>n.has(e));r.sort((e,t)=>n.get(e)-n.get(t));let i=t.filter(e=>!n.has(e));return[...r,...i]}export{e as STORYBOOK_CATEGORY_ORDER,orderCategories};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{StoryRegistry as e}from"./registry.js";var StorybookController=class{constructor(t,n){this._registry=new e,this._activeStory=null,this._unsubArgs=null,this._view=t,this._buildControls=n}mount(e,t=!0){this._registry.registerStories(e);let n=this._registry.createStoryInstances();if(this._view.renderSidebar(this._groupByCategory(n),e=>this.select(e)),t){let e=this._firstStory();e&&this.select(e)}}select(e){this._view.setPreviewTitle(`${e.meta.title} — ${e.story}`),this._view.showPreview(e),this._view.markSelected(e.meta.title),this._wireControls(e),this._activeStory=e}_wireControls(e){this._unsubArgs&&=(this._unsubArgs(),null);let t=this._buildControls(e),n=t.map(e=>e.refresh);this._view.renderControls(t),this._unsubArgs=e.onArgsChanged(e=>{for(let t of n)t(e)})}_groupByCategory(e){let t=new Map;for(let n of e)for(let e of n.instances??[]){let n=e.meta.title.split(`/`),r=n[0],i=n.length>1?n[1]:e.meta.title;t.has(r)||t.set(r,[]),t.get(r).push({instance:e,name:i||`Unnamed`})}return[...t].map(([e,t])=>({category:e,stories:t}))}get activeStory(){return this._activeStory}listStories(){return this._registry.getStories().flatMap(e=>(e.instances??[]).map(e=>({title:e.meta.title,story:e.story,category:e.meta.title.split(`/`)[0],controls:e.meta.controls??[]})))}openStoryByTitle(e){let t=this._findByTitle(e);return t?(this.select(t),!0):!1}getCurrentStory(){let e=this._activeStory;return e?{title:e.meta.title,story:e.story,args:e.args}:null}setActiveArg(e,t){let n=this._activeStory;return n?(n.setArg(e,t),!0):!1}_findByTitle(e){for(let t of this._registry.getStories())for(let n of t.instances??[])if(n.meta.title===e)return n;return null}_firstStory(){for(let e of this._registry.getStories()){let t=(e.instances??[])[0];if(t)return t}return null}};export{StorybookController};
1
+ import"./_virtual/_rolldown/runtime.js";import{orderCategories as e}from"./category-order.js";import{StoryRegistry as t}from"./registry.js";var StorybookController=class{constructor(e,n){this._registry=new t,this._activeStory=null,this._unsubArgs=null,this._view=e,this._buildControls=n}mount(e,t=!0){this._registry.registerStories(e);let n=this._registry.createStoryInstances(),r=this._groupByCategory(n);if(this._view.renderSidebar(r,e=>this.select(e)),t){let e=r[0]?.stories[0]?.instance??null;e&&this.select(e)}}select(e){this._view.setPreviewTitle(`${e.meta.title} — ${e.story}`),this._view.showPreview(e),this._view.markSelected(e.meta.title),this._wireControls(e),this._activeStory=e}_wireControls(e){this._unsubArgs&&=(this._unsubArgs(),null);let t=this._buildControls(e),n=t.map(e=>e.refresh);this._view.renderControls(t),this._unsubArgs=e.onArgsChanged(e=>{for(let t of n)t(e)})}_groupByCategory(t){let n=new Map;for(let e of t)for(let t of e.instances??[]){let e=t.meta.title.split(`/`),r=e[0],i=e.length>1?e[1]:t.meta.title;n.has(r)||n.set(r,[]),n.get(r).push({instance:t,name:i||`Unnamed`})}return e([...n.keys()]).map(e=>({category:e,stories:n.get(e)}))}get activeStory(){return this._activeStory}listStories(){return this._registry.getStories().flatMap(e=>(e.instances??[]).map(e=>({title:e.meta.title,story:e.story,category:e.meta.title.split(`/`)[0],controls:e.meta.controls??[]})))}openStoryByTitle(e){let t=this._findByTitle(e);return t?(this.select(t),!0):!1}getCurrentStory(){let e=this._activeStory;return e?{title:e.meta.title,story:e.story,args:e.args}:null}setActiveArg(e,t){let n=this._activeStory;return n?(n.setArg(e,t),!0):!1}_findByTitle(e){for(let t of this._registry.getStories())for(let n of t.instances??[])if(n.meta.title===e)return n;return null}};export{StorybookController};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{StoryRegistry as e}from"./registry.js";import{StorybookController as t}from"./controller.js";import{bindControl as n}from"./controls.js";import{buildStorybookDevtoolsExtension as r}from"./devtools.js";import{collectStoryModules as i}from"./discover.js";import{StoryViewBase as a}from"./story-view-base.js";import{STORYBOOK_COLOR_SCHEMES as o,StorybookSettings as s}from"./settings.js";export*from"@gjsify/stories";export{o as STORYBOOK_COLOR_SCHEMES,e as StoryRegistry,a as StoryViewBase,t as StorybookController,s as StorybookSettings,n as bindControl,r as buildStorybookDevtoolsExtension,i as collectStoryModules};
1
+ import{STORYBOOK_CATEGORY_ORDER as e,orderCategories as t}from"./category-order.js";import{StoryRegistry as n}from"./registry.js";import{StorybookController as r}from"./controller.js";import{bindControl as i}from"./controls.js";import{buildStorybookDevtoolsExtension as a}from"./devtools.js";import{collectStoryModules as o}from"./discover.js";import{StoryViewBase as s}from"./story-view-base.js";import{STORYBOOK_COLOR_SCHEMES as c,StorybookSettings as l}from"./settings.js";export*from"@gjsify/stories";export{e as STORYBOOK_CATEGORY_ORDER,c as STORYBOOK_COLOR_SCHEMES,n as StoryRegistry,s as StoryViewBase,r as StorybookController,l as StorybookSettings,i as bindControl,a as buildStorybookDevtoolsExtension,o as collectStoryModules,t as orderCategories};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The category order every storybook renders its sidebar in.
3
+ *
4
+ * A category NOT listed here still renders — it sorts after every listed one,
5
+ * keeping discovery order among its peers — because a storybook that drops a
6
+ * story on an unrecognised prefix would hide work rather than surface it. The
7
+ * build gate is what makes the omission visible.
8
+ */
9
+ export declare const STORYBOOK_CATEGORY_ORDER: readonly string[];
10
+ /**
11
+ * Order `categories` by {@link STORYBOOK_CATEGORY_ORDER}, appending unlisted ones
12
+ * in the order they arrived.
13
+ *
14
+ * Stable by construction: it partitions rather than sorts, so two unlisted
15
+ * categories keep their discovery order instead of depending on a comparator's
16
+ * tie-breaking.
17
+ */
18
+ export declare function orderCategories(categories: readonly string[]): string[];
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -65,7 +65,7 @@ export declare class StorybookController<TInstance extends StoryInstanceLike> {
65
65
  constructor(view: StorybookView<TInstance>, buildControls: (instance: TInstance) => Array<ControlRow<unknown>>);
66
66
  /**
67
67
  * Register + instantiate `modules`, render the sidebar, and (when
68
- * `openFirst`) select the first story.
68
+ * `openFirst`) select the story the sidebar lists first.
69
69
  */
70
70
  mount(modules: StoryModuleLike<TInstance, new () => TInstance>[], openFirst?: boolean): void;
71
71
  /** Select + show a story instance, wiring its controls. */
@@ -87,5 +87,4 @@ export declare class StorybookController<TInstance extends StoryInstanceLike> {
87
87
  /** Set one arg on the active story — drives the same path as the controls. */
88
88
  setActiveArg(name: string, value: StoryArgValue): boolean;
89
89
  private _findByTitle;
90
- private _firstStory;
91
90
  }
@@ -2,6 +2,7 @@ export * from './story-view-base.js';
2
2
  export * from './registry.js';
3
3
  export * from './controls.js';
4
4
  export * from './controller.js';
5
+ export * from './category-order.js';
5
6
  export * from './discover.js';
6
7
  export * from './devtools.js';
7
8
  export * from './settings.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/storybook-core",
3
- "version": "0.38.1",
3
+ "version": "0.40.0",
4
4
  "description": "Renderer-agnostic storybook logic (story base, registry, control binding, controller, discovery, devtools) shared by the GTK, browser and NativeScript storybook renderers",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -40,12 +40,12 @@
40
40
  "stories"
41
41
  ],
42
42
  "dependencies": {
43
- "@gjsify/adwaita-core": "^0.38.1",
44
- "@gjsify/stories": "^0.38.1"
43
+ "@gjsify/adwaita-core": "^0.40.0",
44
+ "@gjsify/stories": "^0.40.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@gjsify/cli": "^0.38.1",
48
- "@gjsify/unit": "^0.38.1",
47
+ "@gjsify/cli": "^0.40.0",
48
+ "@gjsify/unit": "^0.40.0",
49
49
  "@types/node": "^25.9.2",
50
50
  "typescript": "^6.0.3"
51
51
  },