11import type { Spec } from '@devframes/json-render'
22import type { Meta , StoryObj } from '@storybook/vue3-vite'
3- import { h } from 'vue'
3+ import { h , onMounted , onUnmounted , useTemplateRef } from 'vue'
44import { baseRegistry } from './registry'
55import { JsonRenderView } from './renderer'
6+ import jsonRenderDockRenderer from './renderer-module'
67
78// A no-op RPC — stories don't dispatch real actions.
89const rpc = { call : async ( ) => undefined }
@@ -20,7 +21,7 @@ const meta: Meta = {
2021}
2122export default meta
2223
23- export const Gallery = story ( {
24+ const gallerySpec : Spec = {
2425 root : 'root' ,
2526 elements : {
2627 root : { type : 'Stack' , props : { gap : 12 } , children : [ 'title' , 'row' , 'card' , 'progress' , 'table' , 'tree' ] } ,
@@ -35,7 +36,9 @@ export const Gallery = story({
3536 table : { type : 'DataTable' , props : { rows : [ { id : 1 , name : 'a' } , { id : 2 , name : 'b' } ] } , children : [ ] } ,
3637 tree : { type : 'Tree' , props : { data : { a : 1 , b : [ true , 'x' ] } } , children : [ ] } ,
3738 } ,
38- } )
39+ }
40+
41+ export const Gallery = story ( gallerySpec )
3942
4043export const Controls = story ( {
4144 root : 'root' ,
@@ -103,3 +106,42 @@ export const SubsetRegistry: StoryObj = story(
103106 } ,
104107 { registry : subsetRegistry } ,
105108)
109+
110+ const dockRendererContext = {
111+ rpc : { call : rpc . call , connectionMeta : undefined } ,
112+ } as unknown as Parameters < typeof jsonRenderDockRenderer > [ 0 ] [ 'context' ]
113+
114+ /** Mounts the shipped dock renderer so the story exercises its shadow root and adopted stylesheet. */
115+ export const InShadowRoot : StoryObj = {
116+ render : ( ) => ( {
117+ setup ( ) {
118+ const host = useTemplateRef < HTMLDivElement > ( 'host' )
119+ let dispose : ( ( ) => void ) | undefined
120+ let mountToken = 0
121+ onMounted ( async ( ) => {
122+ const token = ++ mountToken
123+ const instance = await jsonRenderDockRenderer ( {
124+ entry : {
125+ id : 'story' ,
126+ title : 'Story' ,
127+ icon : 'ph:cube-duotone' ,
128+ type : 'json-render' ,
129+ view : { spec : gallerySpec } ,
130+ } ,
131+ container : host . value ! ,
132+ context : dockRendererContext ,
133+ } )
134+ if ( token !== mountToken ) {
135+ instance . dispose ?.( )
136+ return
137+ }
138+ dispose = instance . dispose
139+ } )
140+ onUnmounted ( ( ) => {
141+ mountToken ++
142+ dispose ?.( )
143+ } )
144+ return ( ) => h ( 'div' , { ref : 'host' , class : 'w-full h-80 rounded-lg bg-grid' } )
145+ } ,
146+ } ) ,
147+ }
0 commit comments