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' ] } ,
@@ -37,7 +38,9 @@ export const Gallery = story({
3738 table : { type : 'DataTable' , props : { rows : [ { id : 1 , name : 'a' } , { id : 2 , name : 'b' } ] } , children : [ ] } ,
3839 tree : { type : 'Tree' , props : { data : { a : 1 , b : [ true , 'x' ] } } , children : [ ] } ,
3940 } ,
40- } )
41+ }
42+
43+ export const Gallery = story ( gallerySpec )
4144
4245export const Controls = story ( {
4346 root : 'root' ,
@@ -119,3 +122,42 @@ export const SubsetRegistry: StoryObj = story(
119122 } ,
120123 { registry : subsetRegistry } ,
121124)
125+
126+ const dockRendererContext = {
127+ rpc : { call : rpc . call , connectionMeta : undefined } ,
128+ } as unknown as Parameters < typeof jsonRenderDockRenderer > [ 0 ] [ 'context' ]
129+
130+ /** Mounts the shipped dock renderer so the story exercises its shadow root and adopted stylesheet. */
131+ export const InShadowRoot : StoryObj = {
132+ render : ( ) => ( {
133+ setup ( ) {
134+ const host = useTemplateRef < HTMLDivElement > ( 'host' )
135+ let dispose : ( ( ) => void ) | undefined
136+ let mountToken = 0
137+ onMounted ( async ( ) => {
138+ const token = ++ mountToken
139+ const instance = await jsonRenderDockRenderer ( {
140+ entry : {
141+ id : 'story' ,
142+ title : 'Story' ,
143+ icon : 'ph:cube-duotone' ,
144+ type : 'json-render' ,
145+ view : { spec : gallerySpec } ,
146+ } ,
147+ container : host . value ! ,
148+ context : dockRendererContext ,
149+ } )
150+ if ( token !== mountToken ) {
151+ instance . dispose ?.( )
152+ return
153+ }
154+ dispose = instance . dispose
155+ } )
156+ onUnmounted ( ( ) => {
157+ mountToken ++
158+ dispose ?.( )
159+ } )
160+ return ( ) => h ( 'div' , { ref : 'host' , class : 'w-full h-80 rounded-lg bg-grid' } )
161+ } ,
162+ } ) ,
163+ }
0 commit comments