@makeswift/runtime 0.21.3 → 0.22.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.
Files changed (230) hide show
  1. package/dist/cjs/api/react.js +45 -0
  2. package/dist/cjs/api/react.js.map +1 -1
  3. package/dist/cjs/components/shared/Link/index.js +14 -69
  4. package/dist/cjs/components/shared/Link/index.js.map +1 -1
  5. package/dist/cjs/components/utils/responsive-style.js +2 -1
  6. package/dist/cjs/components/utils/responsive-style.js.map +1 -1
  7. package/dist/cjs/controls/link.js +46 -2
  8. package/dist/cjs/controls/link.js.map +1 -1
  9. package/dist/cjs/controls/rich-text/rich-text.js +12 -0
  10. package/dist/cjs/controls/rich-text/rich-text.js.map +1 -1
  11. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +12 -0
  12. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  13. package/dist/cjs/controls/slot.js +12 -0
  14. package/dist/cjs/controls/slot.js.map +1 -1
  15. package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
  16. package/dist/cjs/next/components/tests/controls/fixtures/rich-text-v2.js +203 -0
  17. package/dist/cjs/next/components/tests/controls/fixtures/rich-text-v2.js.map +1 -0
  18. package/dist/cjs/runtimes/react/components/ElementData.js +1 -1
  19. package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
  20. package/dist/cjs/runtimes/react/controls/control.js +11 -156
  21. package/dist/cjs/runtimes/react/controls/control.js.map +1 -1
  22. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js +1 -0
  23. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
  24. package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js +9 -3
  25. package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
  26. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +1 -0
  27. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
  28. package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +2 -2
  29. package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
  30. package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js +12 -9
  31. package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  32. package/dist/cjs/runtimes/react/controls/slot.js +5 -4
  33. package/dist/cjs/runtimes/react/controls/slot.js.map +1 -1
  34. package/dist/cjs/runtimes/react/controls/style.js +6 -47
  35. package/dist/cjs/runtimes/react/controls/style.js.map +1 -1
  36. package/dist/cjs/runtimes/react/controls/typography.js +49 -51
  37. package/dist/cjs/runtimes/react/controls/typography.js.map +1 -1
  38. package/dist/cjs/runtimes/react/controls.js +15 -111
  39. package/dist/cjs/runtimes/react/controls.js.map +1 -1
  40. package/dist/cjs/{utils/coalesce.js → runtimes/react/hooks/use-css-id.js} +13 -14
  41. package/dist/cjs/runtimes/react/hooks/use-css-id.js.map +1 -0
  42. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +85 -0
  43. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -0
  44. package/dist/cjs/runtimes/react/hooks/use-resolved-value.js +9 -2
  45. package/dist/cjs/runtimes/react/hooks/use-resolved-value.js.map +1 -1
  46. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +68 -0
  47. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -0
  48. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +115 -0
  49. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -0
  50. package/dist/cjs/runtimes/react/resolvable-record.js +67 -0
  51. package/dist/cjs/runtimes/react/resolvable-record.js.map +1 -0
  52. package/dist/cjs/runtimes/react/use-style.js +20 -4
  53. package/dist/cjs/runtimes/react/use-style.js.map +1 -1
  54. package/dist/cjs/slate/TypographyPlugin/index.js +2 -1
  55. package/dist/cjs/slate/TypographyPlugin/index.js.map +1 -1
  56. package/dist/cjs/slate/TypographyPlugin/normalizeTypographyDown.js +2 -12
  57. package/dist/cjs/slate/TypographyPlugin/normalizeTypographyDown.js.map +1 -1
  58. package/dist/cjs/slate/index.js.map +1 -1
  59. package/dist/cjs/state/modules/breakpoints.js +7 -87
  60. package/dist/cjs/state/modules/breakpoints.js.map +1 -1
  61. package/dist/esm/api/react.js +45 -0
  62. package/dist/esm/api/react.js.map +1 -1
  63. package/dist/esm/components/shared/Link/index.js +14 -69
  64. package/dist/esm/components/shared/Link/index.js.map +1 -1
  65. package/dist/esm/components/utils/responsive-style.js +2 -3
  66. package/dist/esm/components/utils/responsive-style.js.map +1 -1
  67. package/dist/esm/controls/link.js +37 -2
  68. package/dist/esm/controls/link.js.map +1 -1
  69. package/dist/esm/controls/rich-text/rich-text.js +16 -1
  70. package/dist/esm/controls/rich-text/rich-text.js.map +1 -1
  71. package/dist/esm/controls/rich-text-v2/rich-text-v2.js +14 -1
  72. package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  73. package/dist/esm/controls/slot.js +14 -1
  74. package/dist/esm/controls/slot.js.map +1 -1
  75. package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
  76. package/dist/esm/next/components/tests/controls/fixtures/rich-text-v2.js +179 -0
  77. package/dist/esm/next/components/tests/controls/fixtures/rich-text-v2.js.map +1 -0
  78. package/dist/esm/runtimes/react/components/ElementData.js +2 -2
  79. package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
  80. package/dist/esm/runtimes/react/controls/control.js +11 -175
  81. package/dist/esm/runtimes/react/controls/control.js.map +1 -1
  82. package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js +1 -0
  83. package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
  84. package/dist/esm/runtimes/react/controls/rich-text/rich-text.js +8 -2
  85. package/dist/esm/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
  86. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +1 -0
  87. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
  88. package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +1 -1
  89. package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
  90. package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js +14 -9
  91. package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  92. package/dist/esm/runtimes/react/controls/slot.js +4 -3
  93. package/dist/esm/runtimes/react/controls/slot.js.map +1 -1
  94. package/dist/esm/runtimes/react/controls/style.js +6 -37
  95. package/dist/esm/runtimes/react/controls/style.js.map +1 -1
  96. package/dist/esm/runtimes/react/controls/typography.js +49 -48
  97. package/dist/esm/runtimes/react/controls/typography.js.map +1 -1
  98. package/dist/esm/runtimes/react/controls.js +14 -129
  99. package/dist/esm/runtimes/react/controls.js.map +1 -1
  100. package/dist/esm/runtimes/react/hooks/use-css-id.js +8 -0
  101. package/dist/esm/runtimes/react/hooks/use-css-id.js.map +1 -0
  102. package/dist/esm/runtimes/react/hooks/use-resolved-props.js +53 -0
  103. package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -0
  104. package/dist/esm/runtimes/react/hooks/use-resolved-value.js +9 -2
  105. package/dist/esm/runtimes/react/hooks/use-resolved-value.js.map +1 -1
  106. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +34 -0
  107. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -0
  108. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +94 -0
  109. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -0
  110. package/dist/esm/runtimes/react/resolvable-record.js +43 -0
  111. package/dist/esm/runtimes/react/resolvable-record.js.map +1 -0
  112. package/dist/esm/runtimes/react/use-style.js +17 -3
  113. package/dist/esm/runtimes/react/use-style.js.map +1 -1
  114. package/dist/esm/slate/TypographyPlugin/index.js +2 -1
  115. package/dist/esm/slate/TypographyPlugin/index.js.map +1 -1
  116. package/dist/esm/slate/TypographyPlugin/normalizeTypographyDown.js +1 -1
  117. package/dist/esm/slate/TypographyPlugin/normalizeTypographyDown.js.map +1 -1
  118. package/dist/esm/slate/index.js.map +1 -1
  119. package/dist/esm/state/modules/breakpoints.js +9 -70
  120. package/dist/esm/state/modules/breakpoints.js.map +1 -1
  121. package/dist/types/api/react.d.ts +11 -1
  122. package/dist/types/api/react.d.ts.map +1 -1
  123. package/dist/types/components/builtin/Button/Button.d.ts +2 -2
  124. package/dist/types/components/shared/Link/index.d.ts.map +1 -1
  125. package/dist/types/components/utils/responsive-style.d.ts +1 -1
  126. package/dist/types/components/utils/responsive-style.d.ts.map +1 -1
  127. package/dist/types/controls/link.d.ts +16 -2
  128. package/dist/types/controls/link.d.ts.map +1 -1
  129. package/dist/types/controls/rich-text/rich-text.d.ts +2 -1
  130. package/dist/types/controls/rich-text/rich-text.d.ts.map +1 -1
  131. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +2 -1
  132. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  133. package/dist/types/controls/slot.d.ts +2 -1
  134. package/dist/types/controls/slot.d.ts.map +1 -1
  135. package/dist/types/locale.d.ts +1 -1
  136. package/dist/types/next/components/tests/controls/fixtures/rich-text-v2.d.ts +40 -0
  137. package/dist/types/next/components/tests/controls/fixtures/rich-text-v2.d.ts.map +1 -0
  138. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts +2 -0
  139. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts.map +1 -0
  140. package/dist/types/runtimes/react/controls/control.d.ts +1 -1
  141. package/dist/types/runtimes/react/controls/control.d.ts.map +1 -1
  142. package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts.map +1 -1
  143. package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts +1 -1
  144. package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts.map +1 -1
  145. package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
  146. package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +3 -3
  147. package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  148. package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +1 -1
  149. package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  150. package/dist/types/runtimes/react/controls/slot.d.ts +4 -1
  151. package/dist/types/runtimes/react/controls/slot.d.ts.map +1 -1
  152. package/dist/types/runtimes/react/controls/style.d.ts +4 -3
  153. package/dist/types/runtimes/react/controls/style.d.ts.map +1 -1
  154. package/dist/types/runtimes/react/controls/typography.d.ts +5 -6
  155. package/dist/types/runtimes/react/controls/typography.d.ts.map +1 -1
  156. package/dist/types/runtimes/react/controls.d.ts +1 -1
  157. package/dist/types/runtimes/react/controls.d.ts.map +1 -1
  158. package/dist/types/runtimes/react/hooks/use-css-id.d.ts +2 -0
  159. package/dist/types/runtimes/react/hooks/use-css-id.d.ts.map +1 -0
  160. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts +3 -0
  161. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -0
  162. package/dist/types/runtimes/react/hooks/use-resolved-value.d.ts +2 -2
  163. package/dist/types/runtimes/react/hooks/use-resolved-value.d.ts.map +1 -1
  164. package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts +3 -0
  165. package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -0
  166. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts +7 -0
  167. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -0
  168. package/dist/types/runtimes/react/resolvable-record.d.ts +3 -0
  169. package/dist/types/runtimes/react/resolvable-record.d.ts.map +1 -0
  170. package/dist/types/runtimes/react/use-style.d.ts +4 -0
  171. package/dist/types/runtimes/react/use-style.d.ts.map +1 -1
  172. package/dist/types/slate/BlockPlugin/index.d.ts +5 -5
  173. package/dist/types/slate/LinkPlugin/getValue.d.ts +1 -1
  174. package/dist/types/slate/LinkPlugin/index.d.ts +1 -1
  175. package/dist/types/slate/TypographyPlugin/index.d.ts.map +1 -1
  176. package/dist/types/slate/TypographyPlugin/normalizeTypographyDown.d.ts.map +1 -1
  177. package/dist/types/slate/index.d.ts +1 -0
  178. package/dist/types/slate/index.d.ts.map +1 -1
  179. package/dist/types/slate/test-helpers/slate-test-helper.d.ts +4 -4
  180. package/dist/types/slate/test-helpers/test-elements.d.ts +1 -1
  181. package/dist/types/state/modules/breakpoints.d.ts +2 -21
  182. package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
  183. package/package.json +4 -4
  184. package/dist/cjs/runtimes/react/controls/color.js +0 -58
  185. package/dist/cjs/runtimes/react/controls/color.js.map +0 -1
  186. package/dist/cjs/runtimes/react/controls/image.js +0 -53
  187. package/dist/cjs/runtimes/react/controls/image.js.map +0 -1
  188. package/dist/cjs/runtimes/react/controls/link.js +0 -110
  189. package/dist/cjs/runtimes/react/controls/link.js.map +0 -1
  190. package/dist/cjs/runtimes/react/controls/list.js +0 -58
  191. package/dist/cjs/runtimes/react/controls/list.js.map +0 -1
  192. package/dist/cjs/runtimes/react/controls/shape.js +0 -44
  193. package/dist/cjs/runtimes/react/controls/shape.js.map +0 -1
  194. package/dist/cjs/runtimes/react/controls/style-v2.js +0 -92
  195. package/dist/cjs/runtimes/react/controls/style-v2.js.map +0 -1
  196. package/dist/cjs/utils/coalesce.js.map +0 -1
  197. package/dist/cjs/utils/shallowMerge.js +0 -44
  198. package/dist/cjs/utils/shallowMerge.js.map +0 -1
  199. package/dist/esm/runtimes/react/controls/color.js +0 -24
  200. package/dist/esm/runtimes/react/controls/color.js.map +0 -1
  201. package/dist/esm/runtimes/react/controls/image.js +0 -29
  202. package/dist/esm/runtimes/react/controls/image.js.map +0 -1
  203. package/dist/esm/runtimes/react/controls/link.js +0 -76
  204. package/dist/esm/runtimes/react/controls/link.js.map +0 -1
  205. package/dist/esm/runtimes/react/controls/list.js +0 -34
  206. package/dist/esm/runtimes/react/controls/list.js.map +0 -1
  207. package/dist/esm/runtimes/react/controls/shape.js +0 -20
  208. package/dist/esm/runtimes/react/controls/shape.js.map +0 -1
  209. package/dist/esm/runtimes/react/controls/style-v2.js +0 -72
  210. package/dist/esm/runtimes/react/controls/style-v2.js.map +0 -1
  211. package/dist/esm/utils/coalesce.js +0 -13
  212. package/dist/esm/utils/coalesce.js.map +0 -1
  213. package/dist/esm/utils/shallowMerge.js +0 -14
  214. package/dist/esm/utils/shallowMerge.js.map +0 -1
  215. package/dist/types/runtimes/react/controls/color.d.ts +0 -4
  216. package/dist/types/runtimes/react/controls/color.d.ts.map +0 -1
  217. package/dist/types/runtimes/react/controls/image.d.ts +0 -4
  218. package/dist/types/runtimes/react/controls/image.d.ts.map +0 -1
  219. package/dist/types/runtimes/react/controls/link.d.ts +0 -4
  220. package/dist/types/runtimes/react/controls/link.d.ts.map +0 -1
  221. package/dist/types/runtimes/react/controls/list.d.ts +0 -12
  222. package/dist/types/runtimes/react/controls/list.d.ts.map +0 -1
  223. package/dist/types/runtimes/react/controls/shape.d.ts +0 -12
  224. package/dist/types/runtimes/react/controls/shape.d.ts.map +0 -1
  225. package/dist/types/runtimes/react/controls/style-v2.d.ts +0 -13
  226. package/dist/types/runtimes/react/controls/style-v2.d.ts.map +0 -1
  227. package/dist/types/utils/coalesce.d.ts +0 -3
  228. package/dist/types/utils/coalesce.d.ts.map +0 -1
  229. package/dist/types/utils/shallowMerge.d.ts +0 -2
  230. package/dist/types/utils/shallowMerge.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/controls/style.ts"],"sourcesContent":["import { CSSObject } from '@emotion/css'\nimport { useEffect, useId } from 'react'\n\nimport {\n Style,\n StyleDefinition,\n StyleControl,\n type DataType,\n type FontSizePropertyData,\n type WidthPropertyData,\n} from '@makeswift/controls'\n\nimport { useBorder, BorderSide } from '../../../components/hooks'\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\n\nimport { useStyle } from '../use-style'\nimport { BorderRadiusLonghandPropertyData } from '../../../css/border-radius'\nimport { lengthPercentageDataToString } from '../../../css/length-percentage'\nimport { marginPropertyDataToStyle } from '../../../css/margin'\nimport { paddingPropertyDataToStyle } from '../../../css/padding'\nimport { BoxModel, getBox } from '../../../box-model'\nimport deepEqual from '../../../utils/deepEqual'\n\nconst defaultMargin = {\n marginTop: 0,\n marginRight: 'auto',\n marginBottom: 0,\n marginLeft: 'auto',\n}\n\nconst defaultPadding = {\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n}\n\nfunction useStyleControlCssObject(\n style: DataType<StyleDefinition> | undefined,\n controlDefinition: StyleDefinition,\n): CSSObject {\n const { properties } = controlDefinition.config\n\n return {\n ...(properties.includes(Style.Width) && {\n maxWidth: '100%',\n }),\n ...useResponsiveStyle(\n [\n style?.width,\n style?.margin,\n style?.padding,\n useBorder(style?.border),\n style?.borderRadius,\n style?.textStyle,\n ] as const,\n ([width, margin, padding, border, borderRadius, textStyle]) => ({\n ...(properties.includes(Style.Width) && {\n width: widthToString(width) ?? '100%',\n }),\n ...(properties.includes(Style.Margin) &&\n marginPropertyDataToStyle(margin ?? defaultMargin, defaultMargin)),\n ...(properties.includes(Style.Padding) &&\n paddingPropertyDataToStyle(padding ?? defaultPadding, defaultPadding)),\n ...(properties.includes(Style.Border) && {\n borderTop: borderSideToString(border?.borderTop) ?? '0 solid black',\n borderRight: borderSideToString(border?.borderRight) ?? '0 solid black',\n borderBottom: borderSideToString(border?.borderBottom) ?? '0 solid black',\n borderLeft: borderSideToString(border?.borderLeft) ?? '0 solid black',\n }),\n ...(properties.includes(Style.BorderRadius) && {\n borderTopLeftRadius: borderRadiusToString(borderRadius?.borderTopLeftRadius) ?? 0,\n borderTopRightRadius: borderRadiusToString(borderRadius?.borderTopRightRadius) ?? 0,\n borderBottomRightRadius: borderRadiusToString(borderRadius?.borderBottomRightRadius) ?? 0,\n borderBottomLeftRadius: borderRadiusToString(borderRadius?.borderBottomLeftRadius) ?? 0,\n }),\n ...(properties.includes(Style.TextStyle) && {\n ...(textStyle?.fontFamily && { fontFamily: `\"${textStyle.fontFamily}\"` }),\n ...(textStyle?.letterSpacing && { letterSpacing: textStyle.letterSpacing }),\n ...(textStyle?.fontSize && { fontSize: fontSizeToString(textStyle.fontSize) }),\n ...(textStyle?.fontWeight && { fontWeight: textStyle.fontWeight }),\n textTransform: textStyle?.textTransform ?? [],\n fontStyle: textStyle?.fontStyle ?? [],\n }),\n }),\n ),\n }\n\n function widthToString(widthProperty: WidthPropertyData | undefined): string | null {\n if (widthProperty == null) return null\n\n return lengthPercentageDataToString(widthProperty)\n }\n\n function borderSideToString(borderSide: BorderSide | null | undefined): string | null {\n if (borderSide == null) return null\n\n const { width, color, style } = borderSide\n return `${width != null ? width : 0}px ${style} ${\n color != null ? colorToString(color) : 'black'\n }`\n }\n\n function borderRadiusToString(\n borderRadius: BorderRadiusLonghandPropertyData | null | undefined,\n ): string | null {\n if (borderRadius == null) return null\n\n return lengthPercentageDataToString(borderRadius)\n }\n\n function fontSizeToString(fontSize: NonNullable<FontSizePropertyData>) {\n return `${fontSize.value}${fontSize.unit}`\n }\n}\n\nexport type StyleControlFormattedValue = string\n\nexport function useFormattedStyle(\n styleControlData: DataType<StyleDefinition> | undefined,\n controlDefinition: StyleDefinition,\n control: StyleControl | null,\n): StyleControlFormattedValue {\n const style = useStyleControlCssObject(styleControlData, controlDefinition)\n // We're removing the colons because useId returns a string wrapped with colons, e.g. \":R3d5sm:\",\n // and we cannot use colons in a class name.\n const guid = useId().replaceAll(':', '')\n const styleClassName = useStyle(style)\n const classNames = `${styleClassName} ${guid}`\n\n useEffect(() => {\n let currentBoxModel: BoxModel | null = null\n\n const handleAnimationFrameRequest = () => {\n if (control == null) return\n\n const element = document.querySelector(`.${guid}`)\n\n const measuredBoxModel = element == null ? null : getBox(element)\n\n if (!deepEqual(currentBoxModel, measuredBoxModel)) {\n currentBoxModel = measuredBoxModel\n\n control.changeBoxModel(currentBoxModel)\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n\n control?.changeBoxModel(null)\n }\n }, [guid, control])\n\n return classNames\n}\n"],"mappings":"AACA,SAAS,WAAW,aAAa;AAEjC;AAAA,EACE;AAAA,OAMK;AAEP,SAAS,iBAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAEnC,SAAS,gBAAgB;AAEzB,SAAS,oCAAoC;AAC7C,SAAS,iCAAiC;AAC1C,SAAS,kCAAkC;AAC3C,SAAmB,cAAc;AACjC,OAAO,eAAe;AAEtB,MAAM,gBAAgB;AAAA,EACpB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AACd;AAEA,MAAM,iBAAiB;AAAA,EACrB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,eAAe;AAAA,EACf,aAAa;AACf;AAEA,SAAS,yBACP,OACA,mBACW;AACX,QAAM,EAAE,WAAW,IAAI,kBAAkB;AAEzC,SAAO;AAAA,IACL,GAAI,WAAW,SAAS,MAAM,KAAK,KAAK;AAAA,MACtC,UAAU;AAAA,IACZ;AAAA,IACA,GAAG;AAAA,MACD;AAAA,QACE,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,QACP,UAAU,OAAO,MAAM;AAAA,QACvB,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AAAA,MACA,CAAC,CAAC,OAAO,Q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es/react/controls/style.ts"],"sourcesContent":["import { CSSObject } from '@emotion/css'\nimport {\n Style,\n type StyleProperty,\n type ResolvedBorderSideData,\n type FontSizePropertyData,\n type WidthPropertyData,\n type ResolvedStyleData,\n} from '@makeswift/controls'\n\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { responsiveStyle } from '../../../components/utils/responsive-style'\n\nimport { BorderRadiusLonghandPropertyData } from '../../../css/border-radius'\nimport { lengthPercentageDataToString } from '../../../css/length-percentage'\nimport { marginPropertyDataToStyle } from '../../../css/margin'\nimport { paddingPropertyDataToStyle } from '../../../css/padding'\nimport { Breakpoints } from '../../../state/modules/breakpoints'\n\nconst defaultMargin = {\n marginTop: 0,\n marginRight: 'auto',\n marginBottom: 0,\n marginLeft: 'auto',\n}\n\nconst defaultPadding = {\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n}\n\nexport function styleV1Css(\n breakpoints: Breakpoints,\n style: ResolvedStyleData | undefined,\n properties: StyleProperty[],\n): CSSObject {\n return {\n ...(properties.includes(Style.Width) && {\n maxWidth: '100%',\n }),\n ...responsiveStyle(\n breakpoints,\n [\n style?.width,\n style?.margin,\n style?.padding,\n style?.border,\n style?.borderRadius,\n style?.textStyle,\n ] as const,\n ([width, margin, padding, border, borderRadius, textStyle]) => ({\n ...(properties.includes(Style.Width) && {\n width: widthToString(width) ?? '100%',\n }),\n ...(properties.includes(Style.Margin) &&\n marginPropertyDataToStyle(margin ?? defaultMargin, defaultMargin)),\n ...(properties.includes(Style.Padding) &&\n paddingPropertyDataToStyle(padding ?? defaultPadding, defaultPadding)),\n ...(properties.includes(Style.Border) && {\n borderTop: borderSideToString(border?.borderTop) ?? '0 solid black',\n borderRight: borderSideToString(border?.borderRight) ?? '0 solid black',\n borderBottom: borderSideToString(border?.borderBottom) ?? '0 solid black',\n borderLeft: borderSideToString(border?.borderLeft) ?? '0 solid black',\n }),\n ...(properties.includes(Style.BorderRadius) && {\n borderTopLeftRadius: borderRadiusToString(borderRadius?.borderTopLeftRadius) ?? 0,\n borderTopRightRadius: borderRadiusToString(borderRadius?.borderTopRightRadius) ?? 0,\n borderBottomRightRadius: borderRadiusToString(borderRadius?.borderBottomRightRadius) ?? 0,\n borderBottomLeftRadius: borderRadiusToString(borderRadius?.borderBottomLeftRadius) ?? 0,\n }),\n ...(properties.includes(Style.TextStyle) && {\n ...(textStyle?.fontFamily && { fontFamily: `\"${textStyle.fontFamily}\"` }),\n ...(textStyle?.letterSpacing && { letterSpacing: textStyle.letterSpacing }),\n ...(textStyle?.fontSize && { fontSize: fontSizeToString(textStyle.fontSize) }),\n ...(textStyle?.fontWeight && { fontWeight: textStyle.fontWeight }),\n textTransform: textStyle?.textTransform ?? [],\n fontStyle: textStyle?.fontStyle ?? [],\n }),\n }),\n ),\n }\n\n function widthToString(widthProperty: WidthPropertyData | undefined): string | null {\n if (widthProperty == null) return null\n\n return lengthPercentageDataToString(widthProperty)\n }\n\n function borderSideToString(\n borderSide: ResolvedBorderSideData | null | undefined,\n ): string | null {\n if (borderSide == null) return null\n\n const { width, color, style } = borderSide\n return `${width != null ? width : 0}px ${style} ${\n color != null ? colorToString(color) : 'black'\n }`\n }\n\n function borderRadiusToString(\n borderRadius: BorderRadiusLonghandPropertyData | null | undefined,\n ): string | null {\n if (borderRadius == null) return null\n\n return lengthPercentageDataToString(borderRadius)\n }\n\n function fontSizeToString(fontSize: NonNullable<FontSizePropertyData>) {\n return `${fontSize.value}${fontSize.unit}`\n }\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,OAMK;AAEP,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAGhC,SAAS,oCAAoC;AAC7C,SAAS,iCAAiC;AAC1C,SAAS,kCAAkC;AAG3C,MAAM,gBAAgB;AAAA,EACpB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AACd;AAEA,MAAM,iBAAiB;AAAA,EACrB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd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AA,UACvE,GAAI,WAAW,iBAAiB,EAAE,eAAe,UAAU,cAAc;AAAA,UACzE,GAAI,WAAW,YAAY,EAAE,UAAU,iBAAiB,UAAU,QAAQ,EAAE;AAAA,UAC5E,GAAI,WAAW,cAAc,EAAE,YAAY,UAAU,WAAW;AAAA,UAChE,eAAe,WAAW,iBAAiB,CAAC;AAAA,UAC5C,WAAW,WAAW,aAAa,CAAC;AAAA,QACtC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,WAAS,cAAc,eAA6D;AAClF,QAAI,iBAAiB;AAAM,aAAO;AAElC,WAAO,6BAA6B,aAAa;AAAA,EACnD;AAEA,WAAS,mBACP,YACe;AACf,QAAI,cAAc;AAAM,aAAO;AAE/B,UAAM,EAAE,OAAO,OAAO,OAAAA,OAAM,IAAI;AAChC,WAAO,GAAG,SAAS,OAAO,QAAQ,CAAC,MAAMA,MAAK,IAC5C,SAAS,OAAO,cAAc,KAAK,IAAI,OACzC;AAAA,EACF;AAEA,WAAS,qBACP,cACe;AACf,QAAI,gBAAgB;AAAM,aAAO;AAEjC,WAAO,6BAA6B,YAAY;AAAA,EAClD;AAEA,WAAS,iBAAiB,UAA6C;AACrE,WAAO,GAAG,SAAS,KAAK,GAAG,SAAS,IAAI;AAAA,EAC1C;AACF;","names":["style"]}
@@ -1,16 +1,19 @@
1
+ import {
2
+ findBreakpointOverride,
3
+ shallowMergeFallbacks
4
+ } from "@makeswift/controls";
1
5
  import { useSwatches, useTypography } from "../hooks/makeswift-api";
2
6
  import { colorToString } from "../../../components/utils/colorToString";
3
- import { useResponsiveStyle } from "../../../components/utils/responsive-style";
4
- import { findBreakpointOverride, shallowMergeFallbacks } from "../../../state/modules/breakpoints";
7
+ import { responsiveStyle } from "../../../components/utils/responsive-style";
5
8
  import { isNonNullable } from "../../../utils/isNonNullable";
6
9
  import { useStyle } from "../use-style";
7
10
  import { useBreakpoints } from "../hooks/use-breakpoints";
8
- function typographyFragementToTypographyControlData(typography) {
9
- if (typography == null)
11
+ function typographyFragementToTypographyControlData(fragment) {
12
+ if (fragment == null)
10
13
  return void 0;
11
14
  return {
12
- id: typography.id,
13
- style: typography.style.map(({ deviceId, value }) => ({
15
+ id: fragment.id,
16
+ style: fragment.style.map(({ deviceId, value }) => ({
14
17
  deviceId,
15
18
  value: {
16
19
  fontFamily: value.fontFamily ?? void 0,
@@ -52,13 +55,13 @@ const withColor = (swatches) => (deviceRawTypographyValue) => {
52
55
  };
53
56
  };
54
57
  const getDeviceId = ({ deviceId }) => deviceId;
55
- function useEnhancedTypography(value) {
56
- const typography = typographyFragementToTypographyControlData(useTypography(value?.id ?? null));
58
+ function useEnhancedTypography(data) {
59
+ const typography = typographyFragementToTypographyControlData(useTypography(data?.id ?? null));
57
60
  const source = typography?.style ?? [];
58
- const override = value?.style ?? [];
61
+ const override = data?.style ?? [];
59
62
  const breakpoints = useBreakpoints();
60
63
  const swatchIds = [
61
- ...getTypographyStyleSwatchIds(value?.style),
64
+ ...getTypographyStyleSwatchIds(data?.style),
62
65
  ...getTypographyStyleSwatchIds(typography?.style)
63
66
  ];
64
67
  const swatches = useSwatches(swatchIds).filter(isNonNullable);
@@ -94,50 +97,48 @@ function useEnhancedTypography(value) {
94
97
  return null;
95
98
  }).filter(isNonNullable);
96
99
  }
97
- function useTypographyClassName(value) {
98
- return useStyle(
99
- useResponsiveStyle(
100
- [value],
101
- ([value2]) => {
102
- if (value2 === void 0)
103
- return {};
104
- let styles = {};
105
- if (value2.color != null)
106
- styles.color = colorToString(value2.color);
107
- if (value2.fontFamily != null)
108
- styles.fontFamily = value2.fontFamily;
109
- if (value2.fontSize != null && value2.fontSize.value != null && value2.fontSize.unit != null)
110
- styles.fontSize = `${value2.fontSize.value}${value2.fontSize.unit}`;
111
- if (value2.fontWeight != null)
112
- styles.fontWeight = value2.fontWeight;
113
- if (value2.lineHeight != null)
114
- styles.lineHeight = value2.lineHeight;
115
- if (value2.letterSpacing != null)
116
- styles.letterSpacing = `${value2.letterSpacing / 10}em`;
117
- if (value2.uppercase != null)
118
- styles.textTransform = value2.uppercase === true ? "uppercase" : "initial";
119
- if (value2.underline != null || value2.strikethrough != null)
120
- styles.textDecoration = [
121
- Boolean(value2.underline) && "underline",
122
- Boolean(value2.strikethrough) && "line-through"
123
- ].filter(Boolean).join(" ");
124
- if (value2.italic != null)
125
- styles.fontStyle = value2.italic === true ? "italic" : "initial";
126
- return styles;
127
- },
128
- shallowMergeFallbacks
129
- )
100
+ function typographyToCssObject(value) {
101
+ let styles = {};
102
+ if (value.color != null)
103
+ styles.color = colorToString(value.color);
104
+ if (value.fontFamily != null)
105
+ styles.fontFamily = value.fontFamily;
106
+ if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)
107
+ styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`;
108
+ if (value.fontWeight != null)
109
+ styles.fontWeight = value.fontWeight;
110
+ if (value.lineHeight != null)
111
+ styles.lineHeight = value.lineHeight;
112
+ if (value.letterSpacing != null)
113
+ styles.letterSpacing = `${value.letterSpacing / 10}em`;
114
+ if (value.uppercase != null)
115
+ styles.textTransform = value.uppercase === true ? "uppercase" : "initial";
116
+ if (value.underline != null || value.strikethrough != null)
117
+ styles.textDecoration = [
118
+ Boolean(value.underline) && "underline",
119
+ Boolean(value.strikethrough) && "line-through"
120
+ ].filter(Boolean).join(" ");
121
+ if (value.italic != null)
122
+ styles.fontStyle = value.italic === true ? "italic" : "initial";
123
+ return styles;
124
+ }
125
+ function typographyCss(breakpoints, style) {
126
+ return responsiveStyle(
127
+ breakpoints,
128
+ [style],
129
+ ([value]) => value !== void 0 ? typographyToCssObject(value) : {},
130
+ shallowMergeFallbacks
130
131
  );
131
132
  }
132
- function useTypographyValue(data) {
133
- const enhancedTypography = useEnhancedTypography(data);
134
- return useTypographyClassName(enhancedTypography);
133
+ function useTypographyClassName(value) {
134
+ const breakpoints = useBreakpoints();
135
+ return useStyle(typographyCss(breakpoints, value));
135
136
  }
136
137
  export {
137
138
  useEnhancedTypography as default,
138
139
  getTypographyStyleSwatchIds,
140
+ typographyCss,
139
141
  typographyFragementToTypographyControlData,
140
- useTypographyClassName,
141
- useTypographyValue
142
+ useTypographyClassName
142
143
  };
143
144
  //# sourceMappingURL=typography.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/controls/typography.ts"],"sourcesContent":["import { CSSObject } from '@emotion/serialize'\nimport { unstable_TypographyDefinition, type DataType } from '@makeswift/controls'\n\nimport { useSwatches, useTypography } from '../hooks/makeswift-api'\nimport { Typography, Swatch } from '../../../api'\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { ColorValue } from '../../../components/utils/types'\nimport { DeviceOverride, ResponsiveValue } from '../../../prop-controllers'\nimport { findBreakpointOverride, shallowMergeFallbacks } from '../../../state/modules/breakpoints'\nimport { isNonNullable } from '../../../utils/isNonNullable'\nimport { useStyle } from '../use-style'\nimport { useBreakpoints } from '../hooks/use-breakpoints'\n\nexport function typographyFragementToTypographyControlData(\n typography: Typography | null,\n): DataType<unstable_TypographyDefinition> | undefined {\n if (typography == null) return undefined\n return {\n id: typography.id,\n style: typography.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\nexport type TypographyControlDataValue = Exclude<\n DataType<unstable_TypographyDefinition>,\n undefined\n>['style'][number]['value']\n\ntype EnhancedTypographyValue = Omit<TypographyControlDataValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function getTypographyStyleSwatchIds(\n style:\n | Exclude<DataType<unstable_TypographyDefinition>, undefined>['style']\n | Typography['style']\n | null\n | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<TypographyControlDataValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(\n value?: DataType<unstable_TypographyDefinition> | null,\n): EnhancedTypography {\n const typography = typographyFragementToTypographyControlData(useTypography(value?.id ?? null))\n const source = typography?.style ?? []\n const override = value?.style ?? []\n const breakpoints = useBreakpoints()\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(value?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findBreakpointOverride(breakpoints, enhancedSource, deviceId)?.value\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n enhancedOverride,\n deviceId,\n v => v,\n )?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n return useStyle(\n useResponsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n [value],\n ([value]) => {\n if (value === undefined) return {}\n\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n },\n shallowMergeFallbacks,\n ),\n )\n}\n\nexport type TypographyControlValue = string\n\nexport function useTypographyValue(\n data: DataType<unstable_TypographyDefinition> | undefined,\n): TypographyControlValue {\n // for each breakpoint fetch related resources and merge its value with its override\n const enhancedTypography = useEnhancedTypography(data)\n\n // for each breakpoint shallow merge back up through the breakpoints and create a className\n return useTypographyClassName(enhancedTypography)\n}\n"],"mappings":"AAGA,SAAS,aAAa,qBAAqB;AAE3C,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAGnC,SAAS,wBAAwB,6BAA6B;AAC9D,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAExB,SAAS,2CACd,YACqD;AACrD,MAAI,cAAc;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AM,cAAc;AAAM,iBAAO,aAAaA,OAAM;AACxD,YAAIA,OAAM,YAAY,QAAQA,OAAM,SAAS,SAAS,QAAQA,OAAM,SAAS,QAAQ;AACnF,iBAAO,WAAW,GAAGA,OAAM,SAAS,KAAK,GAAGA,OAAM,SAAS,IAAI;AACjE,YAAIA,OAAM,cAAc;AAAM,iBAAO,aAAaA,OAAM;AACxD,YAAIA,OAAM,cAAc;AAAM,iBAAO,aAAaA,OAAM;AACxD,YAAIA,OAAM,iBAAiB;AAAM,iBAAO,gBAAgB,GAAGA,OAAM,gBAAgB,EAAE;AACnF,YAAIA,OAAM,aAAa;AACrB,iBAAO,gBAAgBA,OAAM,cAAc,OAAO,cAAc;AAClE,YAAIA,OAAM,aAAa,QAAQA,OAAM,iBAAiB;AACpD,iBAAO,iBAAiB;AAAA,YACtB,QAAQA,OAAM,SAAS,KAAK;AAAA,YAC5B,QAAQA,OAAM,aAAa,KAAK;AAAA,UAClC,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AACb,YAAIA,OAAM,UAAU;AAAM,iBAAO,YAAYA,OAAM,WAAW,OAAO,WAAW;AAEhF,eAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAIO,SAAS,mBACd,MACwB;AAExB,QAAM,qBAAqB,sBAAsB,IAAI;AAGrD,SAAO,uBAAuB,kBAAkB;AAClD;","names":["value"]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/controls/typography.ts"],"sourcesContent":["import { CSSObject } from '@emotion/serialize'\nimport {\n unstable_TypographyDefinition,\n findBreakpointOverride,\n shallowMergeFallbacks,\n type DataType,\n type Breakpoints,\n type DeviceOverride,\n type ResponsiveValue,\n} from '@makeswift/controls'\n\nimport { useSwatches, useTypography } from '../hooks/makeswift-api'\nimport { Typography, Swatch } from '../../../api'\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { responsiveStyle } from '../../../components/utils/responsive-style'\nimport { ColorValue } from '../../../components/utils/types'\nimport { isNonNullable } from '../../../utils/isNonNullable'\nimport { useStyle } from '../use-style'\nimport { useBreakpoints } from '../hooks/use-breakpoints'\n\nexport function typographyFragementToTypographyControlData(\n fragment: Typography | null,\n): DataType<unstable_TypographyDefinition> | undefined {\n if (fragment == null) return undefined\n return {\n id: fragment.id,\n style: fragment.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\nexport type TypographyControlDataValue = Exclude<\n DataType<unstable_TypographyDefinition>,\n undefined\n>['style'][number]['value']\n\ntype EnhancedTypographyValue = Omit<TypographyControlDataValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function getTypographyStyleSwatchIds(\n style:\n | Exclude<DataType<unstable_TypographyDefinition>, undefined>['style']\n | Typography['style']\n | null\n | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<TypographyControlDataValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(\n data?: DataType<unstable_TypographyDefinition> | null,\n): EnhancedTypography {\n const typography = typographyFragementToTypographyControlData(useTypography(data?.id ?? null))\n const source = typography?.style ?? []\n const override = data?.style ?? []\n const breakpoints = useBreakpoints()\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(data?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findBreakpointOverride(breakpoints, enhancedSource, deviceId)?.value\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n enhancedOverride,\n deviceId,\n v => v,\n )?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nfunction typographyToCssObject(value: EnhancedTypographyValue): CSSObject {\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n}\n\nexport function typographyCss(breakpoints: Breakpoints, style: EnhancedTypography): CSSObject {\n return responsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n breakpoints,\n [style],\n ([value]) => (value !== undefined ? typographyToCssObject(value) : {}),\n shallowMergeFallbacks,\n )\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n const breakpoints = useBreakpoints()\n return useStyle(typographyCss(breakpoints, value))\n}\n"],"mappings":"AACA;AAAA,EAEE;AAAA,EACA;AAAA,OAKK;AAEP,SAAS,aAAa,qBAAqB;AAE3C,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAExB,SAAS,2CACd,UACqD;AACrD,MAAI,YAAY;AAAM,WAAO;AAC7B,SAAO;AAAA,IACL,IAAI,SAAS;AAAA,IACb,OAAO,SAAS,MAAM,IAAI,CAAC,EAAE,UAAU,MAAM,OAAO;AAAA,MAClD;AAAA,MACA,OAAO;AAAA,QACL,YAAY,MAAM,cAAc;AAAA,QAChC,YAAY,MAAM,cAAc;AAAA,QAChC,eAAe,MAAM,iBAAiB;AAAA,QACtC,YAAY,MAAM,cAAc;AAAA,QAChC,WAAW,MAAM,aAAa;AAAA,QAC9B,WAAW,MAAM,aAAa;AAAA,QAC9B,WAAW,MAAM,aAAa;AAAA,QAC9B,eAAe,MAAM,iBAAiB;AAAA,QACtC,QAAQ,MAAM,UAAU;AAAA,QACxB,UAAU,MAAM,YAAY;AAAA,QAC5B,OAAO,MAAM,SAAS;AAAA,MACxB;AAAA,IACF,EAAE;AAAA,EACJ;AACF;AAeO,SAAS,4BACd,OAKU;AACV,SACE,OACI,IAAI,cAAY,SAAS,KA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AsC;AAC5F,SAAO;AAAA,IAIL;AAAA,IACA,CAAC,KAAK;AAAA,IACN,CAAC,CAAC,KAAK,MAAO,UAAU,SAAY,sBAAsB,KAAK,IAAI,CAAC;AAAA,IACpE;AAAA,EACF;AACF;AAEO,SAAS,uBAAuB,OAAmC;AACxE,QAAM,cAAc,eAAe;AACnC,SAAO,SAAS,cAAc,aAAa,KAAK,CAAC;AACnD;","names":[]}
@@ -1,140 +1,25 @@
1
- import { jsx } from "react/jsx-runtime";
2
1
  import { useRef } from "react";
2
+ import { partitionRecord } from "../../utils/partition";
3
3
  import * as ReactPage from "../../state/react-page";
4
- import {
5
- CheckboxDefinition,
6
- NumberDefinition,
7
- RichTextV2Definition,
8
- ColorDefinition,
9
- ComboboxDefinition,
10
- IconRadioGroupDefinition,
11
- ImageDefinition,
12
- LinkDefinition,
13
- ListDefinition,
14
- RichTextV1Definition,
15
- SelectDefinition,
16
- ShapeDefinition,
17
- SlotDefinition,
18
- StyleDefinition,
19
- StyleV2Definition,
20
- TextAreaDefinition,
21
- TextInputDefinition,
22
- unstable_TypographyDefinition
23
- } from "../../controls";
24
4
  import { isLegacyDescriptor } from "../../prop-controllers/descriptors";
25
- import { useFormattedStyle } from "./controls/style";
26
- import { ControlValue } from "./controls/control";
27
- import { useSlot } from "./controls/slot";
28
- import { useRichText } from "./controls/rich-text/rich-text";
29
- import { useRichTextV2 } from "./controls/rich-text-v2";
30
5
  import { useStore } from "./hooks/use-store";
31
- import { useDocumentKey } from "./hooks/use-document-key";
32
- import { useSelector } from "./hooks/use-selector";
33
- import { RenderHook } from "./components";
34
6
  import { resolveLegacyDescriptorProp } from "./legacy-controls";
35
- function PropsValue({ element, children }) {
7
+ import { useResolvedProps } from "./hooks/use-resolved-props";
8
+ function useControlDefs(elementType) {
36
9
  const store = useStore();
37
- const propControllerDescriptorsRef = useRef(
38
- ReactPage.getComponentPropControllerDescriptors(store.getState(), element.type) ?? {}
10
+ const all = ReactPage.getComponentPropControllerDescriptors(store.getState(), elementType) ?? {};
11
+ return useRef(partitionRecord(all, isLegacyDescriptor)).current;
12
+ }
13
+ function ResolveProps({ element, children: renderComponent }) {
14
+ const [legacyDescriptors, definitions] = useControlDefs(element.type);
15
+ const resolvedProps = useResolvedProps(definitions, element.props, element.key);
16
+ const renderFn = Object.entries(legacyDescriptors).reduceRight(
17
+ (renderFn2, [propName, descriptor]) => (props) => resolveLegacyDescriptorProp(descriptor, propName, element.props[propName], props, renderFn2),
18
+ renderComponent
39
19
  );
40
- const props = element.props;
41
- const documentKey = useDocumentKey();
42
- const propControllers = useSelector((state) => {
43
- if (documentKey == null)
44
- return null;
45
- return ReactPage.getPropControllers(state, documentKey, element.key);
46
- });
47
- return Object.entries(propControllerDescriptorsRef.current).reduceRight(
48
- (renderFn, [propName, descriptor]) => (propsValue) => {
49
- if (isLegacyDescriptor(descriptor)) {
50
- return resolveLegacyDescriptorProp(
51
- descriptor,
52
- propName,
53
- props[propName],
54
- propsValue,
55
- renderFn
56
- );
57
- }
58
- switch (descriptor.controlType) {
59
- case CheckboxDefinition.type:
60
- case NumberDefinition.type:
61
- case TextInputDefinition.type:
62
- case TextAreaDefinition.type:
63
- case SelectDefinition.type:
64
- case ColorDefinition.type:
65
- case IconRadioGroupDefinition.type:
66
- case ImageDefinition.type:
67
- case ComboboxDefinition.type:
68
- case ShapeDefinition.type:
69
- case ListDefinition.type:
70
- case LinkDefinition.type:
71
- case StyleV2Definition.type:
72
- case unstable_TypographyDefinition.type:
73
- return /* @__PURE__ */ jsx(
74
- ControlValue,
75
- {
76
- definition: descriptor,
77
- data: props[propName],
78
- control: propControllers?.[propName],
79
- children: (value) => renderFn({ ...propsValue, [propName]: value })
80
- }
81
- );
82
- case StyleDefinition.type: {
83
- const control = propControllers?.[propName] ?? null;
84
- return /* @__PURE__ */ jsx(
85
- RenderHook,
86
- {
87
- hook: useFormattedStyle,
88
- parameters: [props[propName], descriptor, control],
89
- children: (value) => renderFn({ ...propsValue, [propName]: value })
90
- },
91
- descriptor.controlType
92
- );
93
- }
94
- case RichTextV1Definition.type: {
95
- const control = propControllers?.[propName] ?? null;
96
- return /* @__PURE__ */ jsx(
97
- RenderHook,
98
- {
99
- hook: useRichText,
100
- parameters: [props[propName], control],
101
- children: (value) => renderFn({ ...propsValue, [propName]: value })
102
- },
103
- descriptor.controlType
104
- );
105
- }
106
- case RichTextV2Definition.type: {
107
- const control = propControllers?.[propName] ?? null;
108
- return /* @__PURE__ */ jsx(
109
- RenderHook,
110
- {
111
- hook: useRichTextV2,
112
- parameters: [props[propName], descriptor, control],
113
- children: (value) => renderFn({ ...propsValue, [propName]: value })
114
- },
115
- descriptor.controlType
116
- );
117
- }
118
- case SlotDefinition.type: {
119
- const control = propControllers?.[propName] ?? null;
120
- return /* @__PURE__ */ jsx(
121
- RenderHook,
122
- {
123
- hook: useSlot,
124
- parameters: [props[propName], control],
125
- children: (value) => renderFn({ ...propsValue, [propName]: value })
126
- },
127
- descriptor.controlType
128
- );
129
- }
130
- }
131
- console.error(`Unknown control type: ${descriptor.controlType}`);
132
- return renderFn({ ...propsValue, [propName]: props[propName] });
133
- },
134
- children
135
- )({});
20
+ return renderFn(resolvedProps);
136
21
  }
137
22
  export {
138
- PropsValue
23
+ ResolveProps
139
24
  };
140
25
  //# sourceMappingURL=controls.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/controls.tsx"],"sourcesContent":["import { useRef } from 'react'\n\nimport * as ReactPage from '../../state/react-page'\n\nimport {\n CheckboxDefinition,\n NumberDefinition,\n RichTextV2Definition,\n RichTextV2Control,\n ColorDefinition,\n ComboboxDefinition,\n IconRadioGroupDefinition,\n ImageDefinition,\n LinkDefinition,\n ListDefinition,\n RichTextV1Definition,\n RichTextV1Control,\n SelectDefinition,\n ShapeDefinition,\n SlotDefinition,\n SlotControl,\n StyleDefinition,\n StyleControl,\n StyleV2Definition,\n TextAreaDefinition,\n TextInputDefinition,\n unstable_TypographyDefinition,\n} from '../../controls'\n\nimport { isLegacyDescriptor } from '../../prop-controllers/descriptors'\n\nimport { useFormattedStyle } from './controls/style'\nimport { ControlValue } from './controls/control'\nimport { useSlot } from './controls/slot'\nimport { useRichText } from './controls/rich-text/rich-text'\nimport { useRichTextV2 } from './controls/rich-text-v2'\n\nimport { useStore } from './hooks/use-store'\nimport { useDocumentKey } from './hooks/use-document-key'\nimport { useSelector } from './hooks/use-selector'\n\nimport { RenderHook } from './components'\nimport { resolveLegacyDescriptorProp } from './legacy-controls'\n\ntype PropsValueProps = {\n element: ReactPage.ElementData\n children(props: Record<string, unknown>): JSX.Element\n}\n\nexport function PropsValue({ element, children }: PropsValueProps): JSX.Element {\n const store = useStore()\n const propControllerDescriptorsRef = useRef(\n ReactPage.getComponentPropControllerDescriptors(store.getState(), element.type) ?? {},\n )\n const props = element.props as Record<string, any>\n const documentKey = useDocumentKey()\n\n const propControllers = useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, element.key)\n })\n\n return Object.entries(propControllerDescriptorsRef.current).reduceRight(\n (renderFn, [propName, descriptor]) =>\n propsValue => {\n if (isLegacyDescriptor(descriptor)) {\n return resolveLegacyDescriptorProp(\n descriptor,\n propName,\n props[propName],\n propsValue,\n renderFn,\n )\n }\n\n switch (descriptor.controlType) {\n case CheckboxDefinition.type:\n case NumberDefinition.type:\n case TextInputDefinition.type:\n case TextAreaDefinition.type:\n case SelectDefinition.type:\n case ColorDefinition.type:\n case IconRadioGroupDefinition.type:\n case ImageDefinition.type:\n case ComboboxDefinition.type:\n case ShapeDefinition.type:\n case ListDefinition.type:\n case LinkDefinition.type:\n case StyleV2Definition.type:\n case unstable_TypographyDefinition.type:\n return (\n <ControlValue\n definition={descriptor}\n data={props[propName]}\n control={propControllers?.[propName]}\n >\n {value => renderFn({ ...propsValue, [propName]: value })}\n </ControlValue>\n )\n\n case StyleDefinition.type: {\n const control = (propControllers?.[propName] ?? null) as StyleControl | null\n\n return (\n <RenderHook\n key={descriptor.controlType}\n hook={useFormattedStyle}\n parameters={[props[propName], descriptor as StyleDefinition, control]}\n >\n {value => renderFn({ ...propsValue, [propName]: value })}\n </RenderHook>\n )\n }\n\n case RichTextV1Definition.type: {\n const control = (propControllers?.[propName] ?? null) as RichTextV1Control | null\n\n return (\n <RenderHook\n key={descriptor.controlType}\n hook={useRichText}\n parameters={[props[propName], control]}\n >\n {value => renderFn({ ...propsValue, [propName]: value })}\n </RenderHook>\n )\n }\n\n case RichTextV2Definition.type: {\n const control = (propControllers?.[propName] ?? null) as RichTextV2Control | null\n\n return (\n <RenderHook\n key={descriptor.controlType}\n hook={useRichTextV2}\n parameters={[props[propName], descriptor as RichTextV2Definition, control]}\n >\n {value => renderFn({ ...propsValue, [propName]: value })}\n </RenderHook>\n )\n }\n\n case SlotDefinition.type: {\n const control = (propControllers?.[propName] ?? null) as SlotControl | null\n\n return (\n <RenderHook\n key={descriptor.controlType}\n hook={useSlot}\n parameters={[props[propName], control]}\n >\n {value => renderFn({ ...propsValue, [propName]: value })}\n </RenderHook>\n )\n }\n }\n\n console.error(`Unknown control type: ${descriptor.controlType}`)\n return renderFn({ ...propsValue, [propName]: props[propName] })\n },\n children,\n )({})\n}\n"],"mappings":"AA4Fc;AA5Fd,SAAS,cAAc;AAEvB,YAAY,eAAe;AAE3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AAEnC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAE9B,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAE5B,SAAS,kBAAkB;AAC3B,SAAS,mCAA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/D,aAAO,SAAS,EAAE,GAAG,YAAY,CAAC,QAAQ,GAAG,MAAM,QAAQ,EAAE,CAAC;AAAA,IAChE;AAAA,IACF;AAAA,EACF,EAAE,CAAC,CAAC;AACN;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/controls.tsx"],"sourcesContent":["import { useRef } from 'react'\n\nimport { ControlDefinition } from '@makeswift/controls'\n\nimport { partitionRecord } from '../../utils/partition'\n\nimport * as ReactPage from '../../state/react-page'\nimport { isLegacyDescriptor, LegacyDescriptor } from '../../prop-controllers/descriptors'\n\nimport { useStore } from './hooks/use-store'\n\nimport { resolveLegacyDescriptorProp } from './legacy-controls'\nimport { useResolvedProps } from './hooks/use-resolved-props'\n\ntype PropsValueProps = {\n element: ReactPage.ElementData\n children(props: Record<string, unknown>): JSX.Element\n}\n\nfunction useControlDefs(\n elementType: string,\n): readonly [Record<string, LegacyDescriptor>, Record<string, ControlDefinition>] {\n const store = useStore()\n const all = ReactPage.getComponentPropControllerDescriptors(store.getState(), elementType) ?? {}\n return useRef(partitionRecord(all, isLegacyDescriptor)).current\n}\n\nexport function ResolveProps({ element, children: renderComponent }: PropsValueProps): JSX.Element {\n const [legacyDescriptors, definitions] = useControlDefs(element.type)\n\n const resolvedProps = useResolvedProps(definitions, element.props, element.key)\n\n const renderFn = Object.entries(legacyDescriptors).reduceRight(\n (renderFn, [propName, descriptor]) =>\n props =>\n resolveLegacyDescriptorProp(descriptor, propName, element.props[propName], props, renderFn),\n renderComponent,\n )\n\n return renderFn(resolvedProps)\n}\n"],"mappings":"AAAA,SAAS,cAAc;AAIvB,SAAS,uBAAuB;AAEhC,YAAY,eAAe;AAC3B,SAAS,0BAA4C;AAErD,SAAS,gBAAgB;AAEzB,SAAS,mCAAmC;AAC5C,SAAS,wBAAwB;AAOjC,SAAS,eACP,aACgF;AAChF,QAAM,QAAQ,SAAS;AACvB,QAAM,MAAM,UAAU,sCAAsC,MAAM,SAAS,GAAG,WAAW,KAAK,CAAC;AAC/F,SAAO,OAAO,gBAAgB,KAAK,kBAAkB,CAAC,EAAE;AAC1D;AAEO,SAAS,aAAa,EAAE,SAAS,UAAU,gBAAgB,GAAiC;AACjG,QAAM,CAAC,mBAAmB,WAAW,IAAI,eAAe,QAAQ,IAAI;AAEpE,QAAM,gBAAgB,iBAAiB,aAAa,QAAQ,OAAO,QAAQ,GAAG;AAE9E,QAAM,WAAW,OAAO,QAAQ,iBAAiB,EAAE;AAAA,IACjD,CAACA,WAAU,CAAC,UAAU,UAAU,MAC9B,WACE,4BAA4B,YAAY,UAAU,QAAQ,MAAM,QAAQ,GAAG,OAAOA,SAAQ;AAAA,IAC9F;AAAA,EACF;AAEA,SAAO,SAAS,aAAa;AAC/B;","names":["renderFn"]}
@@ -0,0 +1,8 @@
1
+ import { useId } from "react";
2
+ function useCssId() {
3
+ return useId().replaceAll(":", "");
4
+ }
5
+ export {
6
+ useCssId
7
+ };
8
+ //# sourceMappingURL=use-css-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-css-id.ts"],"sourcesContent":["import { useId } from 'react'\n\nexport function useCssId(): string {\n return useId().replaceAll(':', '') // CSS class names prohibit colons\n}\n"],"mappings":"AAAA,SAAS,aAAa;AAEf,SAAS,WAAmB;AACjC,SAAO,MAAM,EAAE,WAAW,KAAK,EAAE;AACnC;","names":[]}
@@ -0,0 +1,53 @@
1
+ import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from "react";
2
+ import {
3
+ mapValues
4
+ } from "@makeswift/controls";
5
+ import * as ReactPage from "../../../state/react-page";
6
+ import { useResourceResolver } from "./use-resource-resolver";
7
+ import { useDocumentKey } from "./use-document-key";
8
+ import { useSelector } from "./use-selector";
9
+ import { useStylesheetFactory } from "./use-stylesheet-factory";
10
+ import { resolvableRecord } from "../resolvable-record";
11
+ function useControlInstances(elementKey) {
12
+ const documentKey = useDocumentKey();
13
+ return useSelector((state) => {
14
+ if (documentKey == null)
15
+ return null;
16
+ return ReactPage.getPropControllers(state, documentKey, elementKey);
17
+ });
18
+ }
19
+ function useResolvedProps(propDefs, elementData, elementKey) {
20
+ const stylesheetFactory = useStylesheetFactory();
21
+ const resourceResolver = useResourceResolver();
22
+ const controls = useControlInstances(elementKey);
23
+ const cache = useRef({}).current;
24
+ const resolveProp = useCallback(
25
+ (def, propName) => {
26
+ const data = elementData[propName];
27
+ const control = controls?.[propName];
28
+ if (cache[propName] != null && data === cache[propName].data && control === cache[propName].control) {
29
+ return cache[propName].resolvedValue;
30
+ }
31
+ const resolvedValue = def.resolveValue(
32
+ data,
33
+ resourceResolver,
34
+ stylesheetFactory.get(propName),
35
+ control
36
+ );
37
+ cache[propName] = { data, control, resolvedValue };
38
+ return resolvedValue;
39
+ },
40
+ [controls, elementData, resourceResolver, stylesheetFactory]
41
+ );
42
+ const resolvables = useMemo(() => mapValues(propDefs, resolveProp), [propDefs, resolveProp]);
43
+ const props = useMemo(() => resolvableRecord(resolvables), [resolvables]);
44
+ stylesheetFactory.useDefinedStyles();
45
+ useEffect(() => {
46
+ props.triggerResolve();
47
+ }, []);
48
+ return useSyncExternalStore(props.subscribe, props.readStable, props.readStable);
49
+ }
50
+ export {
51
+ useResolvedProps
52
+ };
53
+ //# sourceMappingURL=use-resolved-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-key'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport { resolvableRecord } from '../resolvable-record'\n\nfunction useControlInstances(elementKey: string): Record<string, ControlInstance> | null {\n const documentKey = useDocumentKey()\n\n return useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, elementKey)\n })\n}\n\ntype CacheItem = {\n data: Data\n control: ControlInstance | undefined\n resolvedValue: Resolvable<unknown>\n}\n\nexport function useResolvedProps(\n propDefs: Record<string, ControlDefinition>,\n elementData: Record<string, Data>,\n elementKey: string,\n): Record<string, unknown> {\n const stylesheetFactory = useStylesheetFactory()\n const resourceResolver = useResourceResolver()\n const controls = useControlInstances(elementKey)\n\n const cache = useRef<Record<string, CacheItem>>({}).current\n const resolveProp = useCallback(\n (def: ControlDefinition, propName: string) => {\n const data = elementData[propName]\n const control = controls?.[propName]\n\n if (\n cache[propName] != null &&\n data === cache[propName].data &&\n control === cache[propName].control\n ) {\n return cache[propName].resolvedValue\n }\n\n const resolvedValue = def.resolveValue(\n data,\n resourceResolver,\n stylesheetFactory.get(propName),\n control,\n )\n\n cache[propName] = { data, control, resolvedValue }\n return resolvedValue\n },\n [controls, elementData, resourceResolver, stylesheetFactory],\n )\n\n const resolvables = useMemo(() => mapValues(propDefs, resolveProp), [propDefs, resolveProp])\n const props = useMemo(() => resolvableRecord(resolvables), [resolvables])\n\n stylesheetFactory.useDefinedStyles()\n\n useEffect(() => {\n props.triggerResolve()\n }, [])\n\n return useSyncExternalStore(props.subscribe, props.readStable, props.readStable)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,QAAQ,sBAAsB,mBAAmB;AAC9E;AAAA,EAGE;AAAA,OAGK;AAEP,YAAY,eAAe;AAC3B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAE5B,SAAS,4BAA4B;AAErC,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,YAA4D;AACvF,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY,WAAS;AAC1B,QAAI,eAAe;AAAM,aAAO;AAEhC,WAAO,UAAU,mBAAmB,OAAO,aAAa,UAAU;AAAA,EACpE,CAAC;AACH;AAQO,SAAS,iBACd,UACA,aACA,YACyB;AACzB,QAAM,oBAAoB,qBAAqB;AAC/C,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,WAAW,oBAAoB,UAAU;AAE/C,QAAM,QAAQ,OAAkC,CAAC,CAAC,EAAE;AACpD,QAAM,cAAc;AAAA,IAClB,CAAC,KAAwB,aAAqB;AAC5C,YAAM,OAAO,YAAY,QAAQ;AACjC,YAAM,UAAU,WAAW,QAAQ;AAEnC,UACE,MAAM,QAAQ,KAAK,QACnB,SAAS,MAAM,QAAQ,EAAE,QACzB,YAAY,MAAM,QAAQ,EAAE,SAC5B;AACA,eAAO,MAAM,QAAQ,EAAE;AAAA,MACzB;AAEA,YAAM,gBAAgB,IAAI;AAAA,QACxB;AAAA,QACA;AAAA,QACA,kBAAkB,IAAI,QAAQ;AAAA,QAC9B;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,EAAE,MAAM,SAAS,cAAc;AACjD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU,aAAa,kBAAkB,iBAAiB;AAAA,EAC7D;AAEA,QAAM,cAAc,QAAQ,MAAM,UAAU,UAAU,WAAW,GAAG,CAAC,UAAU,WAAW,CAAC;AAC3F,QAAM,QAAQ,QAAQ,MAAM,iBAAiB,WAAW,GAAG,CAAC,WAAW,CAAC;AAExE,oBAAkB,iBAAiB;AAEnC,YAAU,MAAM;AACd,UAAM,eAAe;AAAA,EACvB,GAAG,CAAC,CAAC;AAEL,SAAO,qBAAqB,MAAM,WAAW,MAAM,YAAY,MAAM,UAAU;AACjF;","names":[]}
@@ -1,5 +1,12 @@
1
- function useResolvedValue(data, definition) {
2
- return definition.resolveValue(data).readStableValue();
1
+ import { useMemo, useEffect, useSyncExternalStore } from "react";
2
+ import { useResourceResolver } from "./use-resource-resolver";
3
+ function useResolvedValue(data, resolver) {
4
+ const resourceResolver = useResourceResolver();
5
+ const resolvable = useMemo(() => resolver(data, resourceResolver), [data, resourceResolver]);
6
+ useEffect(() => {
7
+ resolvable.triggerResolve();
8
+ }, []);
9
+ return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable);
3
10
  }
4
11
  export {
5
12
  useResolvedValue
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-value.ts"],"sourcesContent":["import { ControlDefinition, type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nexport function useResolvedValue(\n data: DataType<ControlDefinition> | undefined,\n definition: ControlDefinition,\n): ResolvedValueType<ControlDefinition> {\n return definition.resolveValue(data).readStableValue()\n}\n"],"mappings":"AAEO,SAAS,iBACd,MACA,YACsC;AACtC,SAAO,WAAW,aAAa,IAAI,EAAE,gBAAgB;AACvD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-value.ts"],"sourcesContent":["import { useMemo, useEffect, useSyncExternalStore } from 'react'\nimport { Resolvable, ResourceResolver } from '@makeswift/controls'\n\nimport { useResourceResolver } from './use-resource-resolver'\n\nexport function useResolvedValue<D, T>(\n data: D,\n resolver: (data: D, resourceResolver: ResourceResolver) => Resolvable<T>,\n): T {\n const resourceResolver = useResourceResolver()\n const resolvable = useMemo(() => resolver(data, resourceResolver), [data, resourceResolver])\n\n useEffect(() => {\n resolvable.triggerResolve()\n }, [])\n\n return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,4BAA4B;AAGzD,SAAS,2BAA2B;AAE7B,SAAS,iBACd,MACA,UACG;AACH,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,aAAa,QAAQ,MAAM,SAAS,MAAM,gBAAgB,GAAG,CAAC,MAAM,gBAAgB,CAAC;AAE3F,YAAU,MAAM;AACd,eAAW,eAAe;AAAA,EAC5B,GAAG,CAAC,CAAC;AAEL,SAAO,qBAAqB,WAAW,WAAW,WAAW,YAAY,WAAW,UAAU;AAChG;","names":[]}
@@ -0,0 +1,34 @@
1
+ import { useMemo } from "react";
2
+ import * as ReactPage from "../../../state/react-page";
3
+ import { useStore } from "./use-store";
4
+ import { useDocumentKey } from "./use-document-key";
5
+ import { useMakeswiftHostApiClient } from "../../../next/context/makeswift-host-api-client";
6
+ function useResourceResolver() {
7
+ const store = useStore();
8
+ const client = useMakeswiftHostApiClient();
9
+ const documentKey = useDocumentKey();
10
+ return useMemo(() => {
11
+ return {
12
+ resolveSwatch: (swatchId) => client.resolveSwatch(swatchId),
13
+ resolveFile: (fileId) => client.resolveFile(fileId),
14
+ resolveTypography: (typographyId) => client.resolveTypography(typographyId),
15
+ resolvePagePathnameSlice: (pageId) => client.resolvePagePathnameSlice(pageId),
16
+ resolveElementId: (elementKey) => {
17
+ const read = () => documentKey == null ? null : ReactPage.getElementId(store.getState(), documentKey, elementKey);
18
+ let lastValue = null;
19
+ return {
20
+ name: `element-id:${documentKey}:${elementKey}`,
21
+ readStable: () => lastValue = read(),
22
+ subscribe: (onUpdate) => store.subscribe(() => {
23
+ if (read() !== lastValue)
24
+ onUpdate();
25
+ })
26
+ };
27
+ }
28
+ };
29
+ }, [client, store, documentKey]);
30
+ }
31
+ export {
32
+ useResourceResolver
33
+ };
34
+ //# sourceMappingURL=use-resource-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useStore } from './use-store'\nimport { useDocumentKey } from './use-document-key'\nimport { useMakeswiftHostApiClient } from '../../../next/context/makeswift-host-api-client'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const client = useMakeswiftHostApiClient()\n const documentKey = useDocumentKey()\n\n return useMemo<ResourceResolver>(() => {\n return {\n resolveSwatch: swatchId => client.resolveSwatch(swatchId),\n resolveFile: fileId => client.resolveFile(fileId),\n resolveTypography: typographyId => client.resolveTypography(typographyId),\n resolvePagePathnameSlice: pageId => client.resolvePagePathnameSlice(pageId),\n resolveElementId: elementKey => {\n const read = () =>\n documentKey == null\n ? null\n : ReactPage.getElementId(store.getState(), documentKey, elementKey)\n\n let lastValue: string | null = null\n return {\n name: `element-id:${documentKey}:${elementKey}`,\n readStable: () => (lastValue = read()),\n subscribe: (onUpdate: () => void) =>\n store.subscribe(() => {\n if (read() !== lastValue) onUpdate()\n }),\n }\n },\n }\n }, [client, store, documentKey])\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,YAAY,eAAe;AAC3B,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,iCAAiC;AAEnC,SAAS,sBAAwC;AACtD,QAAM,QAAQ,SAAS;AACvB,QAAM,SAAS,0BAA0B;AACzC,QAAM,cAAc,eAAe;AAEnC,SAAO,QAA0B,MAAM;AACrC,WAAO;AAAA,MACL,eAAe,cAAY,OAAO,cAAc,QAAQ;AAAA,MACxD,aAAa,YAAU,OAAO,YAAY,MAAM;AAAA,MAChD,mBAAmB,kBAAgB,OAAO,kBAAkB,YAAY;AAAA,MACxE,0BAA0B,YAAU,OAAO,yBAAyB,MAAM;AAAA,MAC1E,kBAAkB,gBAAc;AAC9B,cAAM,OAAO,MACX,eAAe,OACX,OACA,UAAU,aAAa,MAAM,SAAS,GAAG,aAAa,UAAU;AAEtE,YAAI,YAA2B;AAC/B,eAAO;AAAA,UACL,MAAM,cAAc,WAAW,IAAI,UAAU;AAAA,UAC7C,YAAY,MAAO,YAAY,KAAK;AAAA,UACpC,WAAW,CAAC,aACV,MAAM,UAAU,MAAM;AACpB,gBAAI,KAAK,MAAM;AAAW,uBAAS;AAAA,UACrC,CAAC;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,WAAW,CAAC;AACjC;","names":[]}