{"version":3,"file":"testing.mjs","names":["Container","Theme.Provider","Container"],"sources":["../../src/testing/decorators/withLayout.tsx","../../src/testing/decorators/withLayoutVariants.tsx","../../src/testing/decorators/withRegistry.tsx","../../src/testing/decorators/withTheme.tsx","../../src/testing/Loading.tsx","../../src/testing/ThrowError.tsx","../../src/testing/stories.tsx"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react-vite';\nimport React, { type FC, type PropsWithChildren, memo } from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ClassNameValue } from '@dxos/ui-types';\n\nimport type * as Util from '../../util/Util.ts';\n\nexport type ContainerProps = Util.ThemedClassName<PropsWithChildren>;\n\nexport type ContainerType = 'default' | 'fullscreen' | 'centered' | 'column';\n\nexport type WithLayoutProps =\n  | FC<ContainerProps>\n  | {\n      classNames?: ClassNameValue;\n      layout?: ContainerType;\n      scroll?: boolean;\n    };\n\n/**\n * Adds layout container.\n */\nexport const withLayout =\n  (props: WithLayoutProps = {}): Decorator =>\n  (Story) => {\n    // Prevent re-rendering of the story.\n    const MemoizedStory = memo(Story);\n    if (typeof props === 'function') {\n      const Container = props;\n      return (\n        <Container>\n          <MemoizedStory />\n        </Container>\n      );\n    } else {\n      const { layout = 'default', classNames, scroll } = props;\n      const Container = layouts[layout] ?? layouts.fullscreen;\n      return (\n        <Container classNames={mx(scroll ? 'overflow-y-auto' : 'overflow-hidden', classNames)}>\n          <MemoizedStory />\n        </Container>\n      );\n    }\n  };\n\nconst layouts: Record<ContainerType, FC<ContainerProps>> = {\n  default: ({ classNames, children }: ContainerProps) => <div className={mx('p-4', classNames)}>{children}</div>,\n\n  fullscreen: ({ classNames, children }: ContainerProps) => (\n    <div className={mx('fixed inset-0 flex overflow-hidden bg-black', classNames)}>{children}</div>\n  ),\n\n  centered: ({ classNames, children }: ContainerProps) => (\n    <div className={mx('fixed inset-0 grid overflow-hidden place-items-center dx-deck-surface')}>\n      <div className={mx('flex flex-col dx-base-surface', classNames)}>{children}</div>\n    </div>\n  ),\n\n  column: ({ classNames, children }: ContainerProps) => (\n    <div className='fixed inset-0 flex overflow-hidden justify-center dx-deck-surface'>\n      <div className={mx('flex flex-col w-[40rem] dx-base-surface', classNames)}>{children}</div>\n    </div>\n  ),\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react-vite';\nimport React, { type ComponentType, type PropsWithChildren } from 'react';\n\nimport { mx, surfaceShadow } from '@dxos/ui-theme';\nimport { type Density, type Elevation, type ThemedClassName } from '@dxos/ui-types';\n\ntype Config = ThemedClassName<{\n  elevations?: { elevation: Elevation; surface?: string }[];\n  densities?: Density[];\n}>;\n\nconst Container = ({ children, elevation, surface }: PropsWithChildren<{ elevation: Elevation; surface?: string }>) => (\n  <div className={mx('p-4 rounded-sm', surface, surfaceShadow({ elevation }))}>{children}</div>\n);\n\nconst Panel = ({ Story, classNames, elevations, densities }: ThemedClassName<{ Story: ComponentType } & Config>) => {\n  return (\n    <div className={mx('flex flex-col h-full p-8 gap-8', classNames)}>\n      {elevations?.map(({ elevation, surface }) =>\n        densities?.map((density) => (\n          <Container key={`${elevation}--${density}`} surface={surface} elevation={elevation}>\n            <Story />\n          </Container>\n        )),\n      )}\n    </div>\n  );\n};\n\nexport const withLayoutVariants = ({\n  classNames,\n  densities = ['md'],\n  elevations = [\n    {\n      elevation: 'dialog',\n      surface: 'dx-modal-surface',\n    },\n    {\n      elevation: 'positioned',\n      surface: 'dx-card-surface',\n    },\n    {\n      elevation: 'base',\n      surface: 'dx-base-surface',\n    },\n  ],\n}: Config = {}): Decorator => {\n  return (Story) => <Panel Story={Story} classNames={classNames} elevations={elevations} densities={densities} />;\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { RegistryContext } from '@effect/atom-react/RegistryContext';\nimport { type Decorator } from '@storybook/react-vite';\nimport React, { memo, useMemo } from 'react';\n\nimport * as AtomEx from '@dxos/effect/AtomEx';\n\n/**\n * Adds Effect Atom registry context for storybook.\n */\nexport const withRegistry: Decorator = (Story) => {\n  const registry = useMemo(() => AtomEx.makeRegistry(), []);\n\n  // Prevent re-rendering of the story.\n  const MemoizedStory = memo(Story);\n\n  return (\n    <RegistryContext.Provider value={registry}>\n      <MemoizedStory />\n    </RegistryContext.Provider>\n  );\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react-vite';\nimport React from 'react';\n\nimport { type ThemeMode } from '@dxos/ui-types';\n\nimport * as Theme from '../../providers/ThemeProvider/Theme.tsx';\nimport { defaultTx } from '../../theme/defaultTheme.ts';\n\n/**\n * Adds theme decorator.\n */\nexport const withTheme =\n  ({ tx = defaultTx, platform }: Partial<Theme.ThemeContextValue> = {}): Decorator =>\n  (Story, context) => {\n    const {\n      globals: { theme },\n      parameters: { translations },\n    } = context;\n\n    return (\n      <Theme.Provider\n        tx={tx}\n        themeMode={(theme as ThemeMode) || 'dark'}\n        resourceExtensions={translations}\n        platform={platform}\n      >\n        <Story />\n      </Theme.Provider>\n    );\n  };\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { captureOwnerStack, useEffect, useState } from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { safeStringify } from '@dxos/util';\n\nimport { ErrorStack } from '../components/ErrorFallback/ErrorFallback.tsx';\nimport { parseCaptureOwnerStack } from '../components/ErrorFallback/parse-stack.ts';\n\nexport type LoadingProps = { data?: any };\n\n/**\n * Storybook loading component.\n */\nexport const Loading = ({ data }: LoadingProps) => {\n  const [visible, setVisible] = useState(false);\n  // React exports `captureOwnerStack` only from its development build; a production Storybook has none.\n  const ownerFrames = parseCaptureOwnerStack(typeof captureOwnerStack === 'function' ? captureOwnerStack() : null);\n\n  useEffect(() => {\n    const t = setTimeout(() => setVisible(true), 1000);\n    return () => clearTimeout(t);\n  }, []);\n\n  return (\n    <div className='grid p-2'>\n      <div\n        className={mx(\n          'flex flex-col w-full p-2 border-2 border-teal-500 rounded-md',\n          'opacity-0 transition delay-1000 duration-1000',\n          'overflow-auto',\n          visible && 'opacity-100',\n        )}\n      >\n        <h2 className='uppercase capitalize text-xs'>Loading State</h2>\n        <pre className='text-sm text-fg-muted'>{safeStringify(data, undefined, 2)}</pre>\n\n        <h3 className='uppercase capitalize text-xs mt-2'>Owner stack</h3>\n        {ownerFrames && ownerFrames.length > 0 ? (\n          <ErrorStack frames={ownerFrames} />\n        ) : (\n          <p className='text-xs text-fg-subtle'>No owner stack (production build or unsupported context).</p>\n        )}\n      </div>\n    </div>\n  );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nexport type ThrowErrorProps = {\n  error?: () => Error;\n  delay?: number;\n};\n\n/**\n * Use this to debug the error boundary.\n */\nexport const ThrowError = ({ delay = 1_000, ...props }: ThrowErrorProps) => {\n  const [error, setError] = useState<Error>();\n  useEffect(() => {\n    if (delay < 0) {\n      return;\n    }\n\n    const t = setTimeout(() => {\n      setError(generator({ delay, ...props }));\n    }, delay);\n    return () => clearTimeout(t);\n  }, [delay, generator]);\n\n  if (error) {\n    throw error;\n  }\n\n  return null;\n};\n\nconst generator = ({ error, delay }: ThrowErrorProps) => {\n  return error?.() ?? new Error(`Error generated after ${delay}ms`);\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { type ComponentType, type ReactElement } from 'react';\n\nimport { Container, type Gutter } from '../components/Container/Container.tsx';\nimport { type Size, SIZES } from '../sizes.ts';\n\n/**\n * Args every sized story takes: `size` is a properties-panel control (portalled parts inherit it from their trigger's\n * row, DESIGN.md follow-up 57); `allSizes` renders every size at once, which the play tests use to assert geometry per\n * size.\n */\nexport type SizeArgs = {\n  size?: Size;\n  allSizes?: boolean;\n};\n\n/** The `size` control for a story's properties panel; `allSizes` is hidden because only tests set it. */\nexport const SIZE_ARG_TYPES = {\n  size: { control: 'select', options: SIZES },\n  allSizes: { table: { disable: true } },\n} as const;\n\n/**\n * A storybook decorator, typed structurally so this published entry does not depend on storybook: storybook passes the\n * story (rendered with overridden args) and the story context.\n */\ntype SizesDecorator = (\n  Story: ComponentType<{ args?: Record<string, unknown> }>,\n  context: { args: Record<string, unknown>; parameters?: { sizes?: { gutter?: Gutter } } },\n) => ReactElement;\n\nexport type WithSizesOptions = {\n  sizes?: Size[];\n};\n\n/**\n * Renders the story at its `size` arg (default `md`), or once per size when `allSizes` is set, each in its own row: a\n * `level='base'` rail-gutter Container at that size (a story's `parameters.sizes.gutter` overrides the gutter), `data-testid='size-<size>'`, with the size passed as the `size` arg.\n * The rows share a full-width frame, the pane (the query container of decision 5), so its width is set by an outer\n * decorator (e.g. `withLayout({ classNames: 'p-0 w-[32rem]' })`).\n */\nexport const withSizes =\n  ({ sizes = SIZES }: WithSizesOptions = {}): SizesDecorator =>\n  (Story, context) => {\n    const selected = SIZES.find((size) => size === context.args.size) ?? 'md';\n    const shown = context.args.allSizes === true ? sizes : [selected];\n    return (\n      <div className='dx-scope @container flex flex-col w-full' data-size='md'>\n        {shown.map((size) => (\n          <Container\n            key={size}\n            size={size}\n            gutter={context.parameters?.sizes?.gutter ?? 'rail'}\n            level='base'\n            data-testid={`size-${size}`}\n          >\n            <Story args={{ ...context.args, size }} />\n          </Container>\n        ))}\n      </div>\n    );\n  };\n"],"mappings":";;;;;;;;;;;;;;AA2BA,IAAa,cACV,QAAyB,CAAC,OAC1B,UAAU;CAET,MAAM,gBAAgB,KAAK,KAAK;CAChC,IAAI,OAAO,UAAU,YAEnB,OACE,oBAACA,OAAD,EAAA,UACE,oBAAC,eAAD,CAAgB,CAAA,EACP,CAAA;MAER;EACL,MAAM,EAAE,SAAS,WAAW,YAAY,WAAW;EACnD,MAAM,YAAY,QAAQ,WAAW,QAAQ;EAC7C,OACE,oBAAC,WAAD;GAAW,YAAY,GAAG,SAAS,oBAAoB,mBAAmB,UAAU;GAClF,UAAA,oBAAC,eAAD,CAAgB,CAAA;EACP,CAAA;CAEf;AACF;AAEF,IAAM,UAAqD;CACzD,UAAU,EAAE,YAAY,eAA+B,oBA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