@pandacss/studio 0.0.0-dev-20231020132218 → 0.0.0-dev-20231020173315

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/studio",
3
- "version": "0.0.0-dev-20231020132218",
3
+ "version": "0.0.0-dev-20231020173315",
4
4
  "description": "The automated token documentation for Panda CSS",
5
5
  "main": "dist/studio.js",
6
6
  "module": "dist/studio.mjs",
@@ -33,12 +33,12 @@
33
33
  "react": "18.2.0",
34
34
  "react-dom": "18.2.0",
35
35
  "vite": "4.4.11",
36
- "@pandacss/config": "0.0.0-dev-20231020132218",
37
- "@pandacss/logger": "0.0.0-dev-20231020132218",
38
- "@pandacss/node": "0.0.0-dev-20231020132218",
39
- "@pandacss/shared": "0.0.0-dev-20231020132218",
40
- "@pandacss/token-dictionary": "0.0.0-dev-20231020132218",
41
- "@pandacss/types": "0.0.0-dev-20231020132218"
36
+ "@pandacss/config": "0.0.0-dev-20231020173315",
37
+ "@pandacss/logger": "0.0.0-dev-20231020173315",
38
+ "@pandacss/node": "0.0.0-dev-20231020173315",
39
+ "@pandacss/shared": "0.0.0-dev-20231020173315",
40
+ "@pandacss/token-dictionary": "0.0.0-dev-20231020173315",
41
+ "@pandacss/types": "0.0.0-dev-20231020173315"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/react": "18.2.22",
@@ -1,8 +1,16 @@
1
- import { compact, splitProps } from '../helpers.mjs';
1
+ import { compact, mergeProps, splitProps, uniq } from '../helpers.mjs';
2
2
  import { css, mergeCss } from './css.mjs';
3
3
 
4
+ const defaults = (conf) => ({
5
+ base: {},
6
+ variants: {},
7
+ defaultVariants: {},
8
+ compoundVariants: [],
9
+ ...conf,
10
+ })
11
+
4
12
  export function cva(config) {
5
- const { base = {}, variants = {}, defaultVariants = {}, compoundVariants = [] } = config
13
+ const { base, variants, defaultVariants, compoundVariants } = defaults(config)
6
14
 
7
15
  function resolve(props = {}) {
8
16
  const computedVariants = { ...defaultVariants, ...compact(props) }
@@ -16,6 +24,19 @@ export function cva(config) {
16
24
  return mergeCss(variantCss, compoundVariantCss)
17
25
  }
18
26
 
27
+ function merge(cvaConfig) {
28
+ const override = defaults(cvaConfig)
29
+ const variantKeys = uniq(override.variantKeys, Object.keys(variants))
30
+ return cva({
31
+ base: mergeCss(base, override.base),
32
+ variants: Object.fromEntries(
33
+ variantKeys.map((key) => [key, mergeCss(variants[key], override.variants[key])]),
34
+ ),
35
+ defaultVariants: mergeProps(defaultVariants, override.defaultVariants),
36
+ compoundVariants: [...compoundVariants, ...override.compoundVariants],
37
+ })
38
+ }
39
+
19
40
  function cvaFn(props) {
20
41
  return css(resolve(props))
21
42
  }
@@ -34,6 +55,7 @@ export function cva(config) {
34
55
  variantKeys,
35
56
  raw: resolve,
36
57
  config,
58
+ merge,
37
59
  splitVariantProps,
38
60
  })
39
61
  }
@@ -49,8 +49,9 @@ function toHash(value) {
49
49
 
50
50
  // src/merge-props.ts
51
51
  function mergeProps(...sources) {
52
+ const __sources = sources.filter(Boolean);
52
53
  const result = {};
53
- for (const source of sources) {
54
+ for (const source of __sources) {
54
55
  for (const [key, value] of Object.entries(source)) {
55
56
  if (isObject(value)) {
56
57
  result[key] = mergeProps(result[key] || {}, value);
@@ -250,6 +251,9 @@ function splitProps(props, ...keys) {
250
251
  const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
251
252
  return keys.map(fn).concat(split(dKeys));
252
253
  }
254
+
255
+ // src/uniq.ts
256
+ var uniq = (...items) => items.filter(Boolean).reduce((acc, item) => Array.from(/* @__PURE__ */ new Set([...acc, ...item])), []);
253
257
  export {
254
258
  compact,
255
259
  createCss,
@@ -265,6 +269,7 @@ export {
265
269
  mergeProps,
266
270
  splitProps,
267
271
  toHash,
272
+ uniq,
268
273
  walkObject,
269
274
  withoutSpace
270
275
  };
@@ -0,0 +1,22 @@
1
+ import { isCssProperty } from './is-valid-prop.mjs';
2
+
3
+ export const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
4
+
5
+ export const composeShouldForwardProps = (tag, shouldForwardProp) =>
6
+ tag.__shouldForwardProps__ && shouldForwardProp
7
+ ? (propName) => tag.__shouldForwardProps__(propName) && shouldForwardProp(propName)
8
+ : shouldForwardProp
9
+
10
+ export const composeCvaFn = (cvaA, cvaB) => {
11
+ if (cvaA && !cvaB) return cvaA
12
+ if (!cvaA && cvaB) return cvaB
13
+ if ((cvaA.__cva__ && cvaB.__cva__) || (cvaA.__recipe__ && cvaB.__recipe__)) return cvaA.merge(cvaB.config)
14
+ const error = new TypeError('Cannot merge cva with recipe. Please use either cva or recipe.')
15
+ TypeError.captureStackTrace?.(error)
16
+ throw error
17
+ }
18
+
19
+ export const getDisplayName = (Component) => {
20
+ if (typeof Component === 'string') return Component
21
+ return Component?.displayName || Component?.name || 'Component'
22
+ }
@@ -1,10 +1,9 @@
1
1
  import { createElement, forwardRef, useMemo } from 'react'
2
2
  import { css, cx, cva } from '../css/index.mjs';
3
+ import { defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName } from './factory-helper.mjs';
3
4
  import { splitProps, normalizeHTMLProps } from '../helpers.mjs';
4
5
  import { isCssProperty } from './is-valid-prop.mjs';
5
6
 
6
- const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
7
-
8
7
  function styledFn(Dynamic, configOrCva = {}, options = {}) {
9
8
  const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
10
9
 
@@ -17,23 +16,26 @@ function styledFn(Dynamic, configOrCva = {}, options = {}) {
17
16
  )
18
17
 
19
18
  const PandaComponent = /* @__PURE__ */ forwardRef(function PandaComponent(props, ref) {
20
- const { as: Element = Dynamic, children, ...restProps } = props
19
+ const { as: Element = Dynamic.__base__ || Dynamic, children, ...restProps } = props
20
+
21
+ const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
22
+ const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
21
23
 
22
24
  const combinedProps = useMemo(() => Object.assign({}, defaultProps, restProps), [restProps])
23
25
 
24
26
  const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
25
- return splitProps(combinedProps, shouldForwardProp, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
27
+ return splitProps(combinedProps, __shouldForwardProps__, __cvaFn__.variantKeys, isCssProperty, normalizeHTMLProps.keys)
26
28
  }, [combinedProps])
27
29
 
28
30
  function recipeClass() {
29
31
  const { css: cssStyles, ...propStyles } = styleProps
30
- const compoundVariantStyles = cvaFn.__getCompoundVariantCss__?.(variantProps);
31
- return cx(cvaFn(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.className)
32
+ const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps)
33
+ return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.className)
32
34
  }
33
35
 
34
36
  function cvaClass() {
35
37
  const { css: cssStyles, ...propStyles } = styleProps
36
- const cvaStyles = cvaFn.raw(variantProps)
38
+ const cvaStyles = __cvaFn__.raw(variantProps)
37
39
  return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.className)
38
40
  }
39
41
 
@@ -49,8 +51,13 @@ function styledFn(Dynamic, configOrCva = {}, options = {}) {
49
51
  })
50
52
  })
51
53
 
52
- const name = (typeof Dynamic === 'string' ? Dynamic : Dynamic.displayName || Dynamic.name) || 'Component'
54
+ const name = getDisplayName(Dynamic)
55
+
53
56
  PandaComponent.displayName = `panda.${name}`
57
+ PandaComponent.__cva__ = cvaFn
58
+ PandaComponent.__base__ = Dynamic
59
+ PandaComponent.__shouldForwardProps__ = shouldForwardProp
60
+
54
61
  return PandaComponent
55
62
  }
56
63
 
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable */
2
2
  import type { ComponentPropsWithoutRef, ElementType, ElementRef, Ref } from 'react'
3
- import type { Assign, DistributiveOmit, JsxHTMLProps, JsxStyleProps } from './system-types';
4
3
  import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe';
4
+ import type { Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty } from './system-types';
5
5
 
6
- type Dict = Record<string, unknown>
6
+ interface Dict {
7
+ [k: string]: unknown
8
+ }
7
9
 
8
10
  export type ComponentProps<T extends ElementType> = DistributiveOmit<ComponentPropsWithoutRef<T>, 'ref'> & {
9
11
  ref?: Ref<ElementRef<T>>
@@ -14,7 +16,9 @@ export interface PandaComponent<T extends ElementType, P extends Dict = {}> {
14
16
  displayName?: string
15
17
  }
16
18
 
17
- interface RecipeFn { __type: any }
19
+ interface RecipeFn {
20
+ __type: any
21
+ }
18
22
 
19
23
  interface JsxFactoryOptions<TProps extends Dict> {
20
24
  dataAttr?: boolean
@@ -24,17 +28,25 @@ interface JsxFactoryOptions<TProps extends Dict> {
24
28
 
25
29
  export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
26
30
 
27
- interface JsxFactory {
31
+ export type JsxElement<T extends ElementType, P> = T extends PandaComponent<infer A, infer B>
32
+ ? PandaComponent<A, Pretty<DistributiveUnion<P, B>>>
33
+ : PandaComponent<T, P>
34
+
35
+ export interface JsxFactory {
28
36
  <T extends ElementType>(component: T): PandaComponent<T, {}>
29
- <T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): PandaComponent<
37
+ <T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
30
38
  T,
31
39
  RecipeSelection<P>
32
40
  >
33
- <T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): PandaComponent<T, P['__type']>
41
+ <T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): JsxElement<T, P['__type']>
34
42
  }
35
43
 
36
- type JsxElements = { [K in keyof JSX.IntrinsicElements]: PandaComponent<K, {}> }
44
+ export type JsxElements = {
45
+ [K in keyof JSX.IntrinsicElements]: PandaComponent<K, {}>
46
+ }
37
47
 
38
48
  export type Panda = JsxFactory & JsxElements
39
49
 
40
- export type HTMLPandaProps<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
50
+ export type HTMLPandaProps<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
51
+
52
+ export type PandaVariantProps<T extends PandaComponent<any, any>> = T extends PandaComponent<any, infer Props> ? Props : never
@@ -6,6 +6,18 @@ import type { SystemProperties, CssVarProperties } from './style-props';
6
6
  type String = string & {}
7
7
  type Number = number & {}
8
8
 
9
+ export type Pretty<T> = { [K in keyof T]: T[K] } & {}
10
+
11
+ export type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never
12
+
13
+ export type DistributiveUnion<T, U> = {
14
+ [K in keyof T]: K extends keyof U ? U[K] | T[K] : T[K]
15
+ } & DistributiveOmit<U, keyof T>
16
+
17
+ export type Assign<T, U> = {
18
+ [K in keyof T]: K extends keyof U ? U[K] : T[K]
19
+ } & U
20
+
9
21
  /* -----------------------------------------------------------------------------
10
22
  * Native css properties
11
23
  * -----------------------------------------------------------------------------*/
@@ -62,12 +74,6 @@ type StyleProps = SystemProperties & MinimalNested<SystemStyleObject>
62
74
 
63
75
  export type JsxStyleProps = StyleProps & WithCss
64
76
 
65
- export type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never
66
-
67
- export type Assign<T, U> = {
68
- [K in keyof T]: K extends keyof U ? U[K] : T[K]
69
- } & U
70
-
71
77
  export interface PatchedHTMLProps {
72
78
  htmlWidth?: string | number
73
79
  htmlHeight?: string | number