@webstudio-is/react-sdk 0.50.0 → 0.52.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 (364) hide show
  1. package/lib/app/custom-components/image.js +2 -4
  2. package/lib/app/custom-components/shared/remix-link.js +7 -23
  3. package/lib/cjs/app/custom-components/{image.cjs → image.js} +1 -3
  4. package/lib/cjs/app/custom-components/shared/{remix-link.cjs → remix-link.js} +6 -22
  5. package/lib/cjs/components/__generated__/{link.props.cjs → link.props.js} +6 -6
  6. package/lib/cjs/components/{blockquote.cjs → blockquote.js} +2 -1
  7. package/lib/cjs/components/{blockquote.ws.cjs → blockquote.ws.js} +57 -35
  8. package/lib/cjs/components/{body.cjs → body.js} +2 -1
  9. package/lib/cjs/components/{body.ws.cjs → body.ws.js} +30 -46
  10. package/lib/cjs/components/{bold.cjs → bold.js} +2 -1
  11. package/lib/cjs/components/{bold.ws.cjs → bold.ws.js} +6 -1
  12. package/lib/cjs/components/{box.ws.cjs → box.ws.js} +11 -4
  13. package/lib/cjs/components/{button.cjs → button.js} +2 -1
  14. package/lib/cjs/components/{button.ws.cjs → button.ws.js} +6 -1
  15. package/lib/cjs/components/{code.cjs → code.js} +1 -0
  16. package/lib/cjs/components/{code.ws.cjs → code.ws.js} +31 -25
  17. package/lib/cjs/components/{form.cjs → form.js} +2 -1
  18. package/lib/cjs/components/{form.ws.cjs → form.ws.js} +8 -8
  19. package/lib/cjs/components/{heading.ws.cjs → heading.ws.js} +11 -1
  20. package/lib/cjs/components/{image.cjs → image.js} +2 -1
  21. package/lib/cjs/components/{image.ws.cjs → image.ws.js} +15 -11
  22. package/lib/cjs/components/{input.cjs → input.js} +2 -1
  23. package/lib/cjs/components/{input.ws.cjs → input.ws.js} +6 -1
  24. package/lib/cjs/components/{italic.cjs → italic.js} +2 -1
  25. package/lib/cjs/components/{italic.ws.cjs → italic.ws.js} +8 -4
  26. package/lib/cjs/components/{link-block.cjs → link-block.js} +3 -1
  27. package/lib/cjs/components/{link-block.ws.cjs → link-block.ws.js} +13 -9
  28. package/lib/cjs/components/{link.cjs → link.js} +15 -6
  29. package/lib/cjs/components/{link.ws.cjs → link.ws.js} +21 -10
  30. package/lib/cjs/components/{list-item.cjs → list-item.js} +2 -1
  31. package/lib/cjs/components/{list-item.ws.cjs → list-item.ws.js} +6 -1
  32. package/lib/cjs/components/{list.ws.cjs → list.ws.js} +29 -10
  33. package/lib/cjs/components/{paragraph.cjs → paragraph.js} +2 -1
  34. package/lib/cjs/components/{paragraph.ws.cjs → paragraph.ws.js} +6 -1
  35. package/lib/cjs/components/{rich-text-link.ws.cjs → rich-text-link.ws.js} +5 -2
  36. package/lib/cjs/components/{separator.cjs → separator.js} +2 -1
  37. package/lib/cjs/components/{separator.ws.cjs → separator.ws.js} +27 -11
  38. package/lib/cjs/components/{span.cjs → span.js} +2 -1
  39. package/lib/cjs/components/{span.ws.cjs → span.ws.js} +6 -1
  40. package/lib/cjs/components/{subscript.cjs → subscript.js} +2 -1
  41. package/lib/cjs/components/{subscript.ws.cjs → subscript.ws.js} +6 -1
  42. package/lib/cjs/components/{superscript.cjs → superscript.js} +2 -1
  43. package/lib/cjs/components/{superscript.ws.cjs → superscript.ws.js} +6 -1
  44. package/lib/cjs/components/{text-block.cjs → text-block.js} +2 -1
  45. package/lib/cjs/components/{text-block.ws.cjs → text-block.ws.js} +9 -5
  46. package/lib/cjs/{context.cjs → context.js} +2 -1
  47. package/lib/cjs/css/css.js +64 -0
  48. package/lib/cjs/css/global-rules.js +37 -0
  49. package/lib/cjs/css/{index.cjs → index.js} +3 -1
  50. package/lib/cjs/css/normalize-type-check.js +26 -0
  51. package/lib/cjs/css/normalize.js +358 -0
  52. package/lib/cjs/css/presets.js +61 -0
  53. package/lib/cjs/css/style-rules.js +62 -0
  54. package/lib/cjs/package.json +1 -0
  55. package/lib/cjs/{props.cjs → props.js} +43 -2
  56. package/lib/cjs/pubsub/{create.cjs → create.js} +6 -35
  57. package/lib/cjs/pubsub/raf-queue.js +45 -0
  58. package/lib/cjs/tree/{create-elements-tree.cjs → create-elements-tree.js} +8 -1
  59. package/lib/cjs/tree/{root.cjs → root.js} +1 -0
  60. package/lib/cjs/tree/{webstudio-component.cjs → webstudio-component.js} +1 -0
  61. package/lib/components/__generated__/link-block.props.js +5 -5
  62. package/lib/components/__generated__/link.props.js +6 -6
  63. package/lib/components/__generated__/rich-text-link.props.js +5 -5
  64. package/lib/components/blockquote.js +2 -1
  65. package/lib/components/blockquote.ws.js +57 -35
  66. package/lib/components/body.js +2 -1
  67. package/lib/components/body.ws.js +30 -46
  68. package/lib/components/bold.js +2 -1
  69. package/lib/components/bold.ws.js +7 -2
  70. package/lib/components/box.ws.js +22 -4
  71. package/lib/components/button.js +2 -1
  72. package/lib/components/button.ws.js +7 -2
  73. package/lib/components/code.js +1 -0
  74. package/lib/components/code.ws.js +31 -25
  75. package/lib/components/form.js +2 -1
  76. package/lib/components/form.ws.js +8 -8
  77. package/lib/components/heading.ws.js +11 -1
  78. package/lib/components/image.js +2 -1
  79. package/lib/components/image.ws.js +15 -11
  80. package/lib/components/input.js +2 -1
  81. package/lib/components/input.ws.js +7 -2
  82. package/lib/components/italic.js +2 -1
  83. package/lib/components/italic.ws.js +9 -5
  84. package/lib/components/link-block.js +3 -1
  85. package/lib/components/link-block.ws.js +13 -9
  86. package/lib/components/link.js +15 -6
  87. package/lib/components/link.ws.js +22 -11
  88. package/lib/components/list-item.js +2 -1
  89. package/lib/components/list-item.ws.js +6 -1
  90. package/lib/components/list.ws.js +29 -10
  91. package/lib/components/paragraph.js +2 -1
  92. package/lib/components/paragraph.ws.js +6 -1
  93. package/lib/components/rich-text-link.ws.js +6 -3
  94. package/lib/components/separator.js +2 -1
  95. package/lib/components/separator.ws.js +27 -11
  96. package/lib/components/span.js +2 -1
  97. package/lib/components/span.ws.js +7 -2
  98. package/lib/components/subscript.js +2 -1
  99. package/lib/components/subscript.ws.js +6 -1
  100. package/lib/components/superscript.js +2 -1
  101. package/lib/components/superscript.ws.js +6 -1
  102. package/lib/components/text-block.js +2 -1
  103. package/lib/components/text-block.ws.js +10 -6
  104. package/lib/context.js +2 -1
  105. package/lib/css/css.js +44 -0
  106. package/lib/css/get-browser-style.js +3 -1
  107. package/lib/css/global-rules.js +20 -0
  108. package/lib/css/index.js +3 -1
  109. package/lib/css/normalize-type-check.js +3 -0
  110. package/lib/css/normalize.js +338 -0
  111. package/lib/css/presets.js +41 -0
  112. package/lib/css/style-rules.js +42 -0
  113. package/lib/props.js +43 -2
  114. package/lib/pubsub/create.js +6 -25
  115. package/lib/pubsub/raf-queue.js +25 -0
  116. package/lib/tree/create-elements-tree.js +8 -1
  117. package/lib/tree/root.js +1 -0
  118. package/lib/tree/webstudio-component.js +1 -0
  119. package/lib/types/app/custom-components/image.d.ts +6 -0
  120. package/lib/types/app/custom-components/index.d.ts +26 -0
  121. package/lib/types/app/custom-components/link-block.d.ts +6 -0
  122. package/lib/types/app/custom-components/link.d.ts +6 -0
  123. package/lib/types/app/custom-components/rich-text-link.d.ts +6 -0
  124. package/lib/types/app/custom-components/shared/remix-link.d.ts +10 -0
  125. package/lib/types/app/handle-request.server.d.ts +2 -0
  126. package/lib/types/app/index.d.ts +3 -0
  127. package/lib/types/app/params.d.ts +5 -0
  128. package/lib/types/app/root.d.ts +8 -0
  129. package/lib/types/components/__generated__/blockquote.props.d.ts +2 -0
  130. package/lib/types/components/__generated__/body.props.d.ts +2 -0
  131. package/lib/types/components/__generated__/bold.props.d.ts +2 -0
  132. package/lib/types/components/__generated__/box.props.d.ts +2 -0
  133. package/lib/types/components/__generated__/button.props.d.ts +2 -0
  134. package/lib/types/components/__generated__/code.props.d.ts +2 -0
  135. package/lib/types/components/__generated__/form.props.d.ts +2 -0
  136. package/lib/types/components/__generated__/fragment.props.d.ts +2 -0
  137. package/lib/types/components/__generated__/heading.props.d.ts +2 -0
  138. package/lib/types/components/__generated__/image.props.d.ts +2 -0
  139. package/lib/types/components/__generated__/input.props.d.ts +2 -0
  140. package/lib/types/components/__generated__/italic.props.d.ts +2 -0
  141. package/lib/types/components/__generated__/link-block.props.d.ts +2 -0
  142. package/lib/types/components/__generated__/link.props.d.ts +2 -0
  143. package/lib/types/components/__generated__/list-item.props.d.ts +2 -0
  144. package/lib/types/components/__generated__/list.props.d.ts +2 -0
  145. package/lib/types/components/__generated__/paragraph.props.d.ts +2 -0
  146. package/lib/types/components/__generated__/rich-text-link.props.d.ts +2 -0
  147. package/lib/types/components/__generated__/separator.props.d.ts +2 -0
  148. package/lib/types/components/__generated__/slot.props.d.ts +2 -0
  149. package/lib/types/components/__generated__/span.props.d.ts +2 -0
  150. package/lib/types/components/__generated__/subscript.props.d.ts +2 -0
  151. package/lib/types/components/__generated__/superscript.props.d.ts +2 -0
  152. package/lib/types/components/__generated__/text-block.props.d.ts +2 -0
  153. package/lib/types/components/blockquote.d.ts +3 -0
  154. package/lib/types/components/blockquote.stories.d.ts +5 -0
  155. package/lib/types/components/blockquote.ws.d.ts +3 -0
  156. package/lib/types/components/body.d.ts +3 -0
  157. package/lib/types/components/body.stories.d.ts +6 -0
  158. package/lib/types/components/body.ws.d.ts +3 -0
  159. package/lib/types/components/bold.d.ts +3 -0
  160. package/lib/types/components/bold.stories.d.ts +5 -0
  161. package/lib/types/components/bold.ws.d.ts +3 -0
  162. package/lib/types/components/box.d.ts +7 -0
  163. package/lib/types/components/box.stories.d.ts +9 -0
  164. package/lib/types/components/box.ws.d.ts +3 -0
  165. package/lib/types/components/button.d.ts +7 -0
  166. package/lib/types/components/button.stories.d.ts +9 -0
  167. package/lib/types/components/button.ws.d.ts +3 -0
  168. package/lib/types/components/code.d.ts +9 -0
  169. package/lib/types/components/code.stories.d.ts +11 -0
  170. package/lib/types/components/code.ws.d.ts +3 -0
  171. package/lib/types/components/component-meta.d.ts +605 -0
  172. package/lib/types/components/components-utils.d.ts +34 -0
  173. package/lib/types/components/components.d.ts +31 -0
  174. package/lib/types/components/form.d.ts +3 -0
  175. package/lib/types/components/form.stories.d.ts +5 -0
  176. package/lib/types/components/form.ws.d.ts +3 -0
  177. package/lib/types/components/fragment.d.ts +6 -0
  178. package/lib/types/components/fragment.ws.d.ts +3 -0
  179. package/lib/types/components/heading.d.ts +7 -0
  180. package/lib/types/components/heading.stories.d.ts +9 -0
  181. package/lib/types/components/heading.ws.d.ts +3 -0
  182. package/lib/types/components/image.d.ts +3 -0
  183. package/lib/types/components/image.stories.d.ts +5 -0
  184. package/lib/types/components/image.ws.d.ts +3 -0
  185. package/lib/types/components/index.d.ts +17 -0
  186. package/lib/types/components/input.d.ts +3 -0
  187. package/lib/types/components/input.stories.d.ts +5 -0
  188. package/lib/types/components/input.ws.d.ts +3 -0
  189. package/lib/types/components/italic.d.ts +3 -0
  190. package/lib/types/components/italic.stories.d.ts +5 -0
  191. package/lib/types/components/italic.ws.d.ts +3 -0
  192. package/lib/types/components/link-block.d.ts +3 -0
  193. package/lib/types/components/link-block.stories.d.ts +13 -0
  194. package/lib/types/components/link-block.ws.d.ts +3 -0
  195. package/lib/types/components/link.d.ts +9 -0
  196. package/lib/types/components/link.stories.d.ts +13 -0
  197. package/lib/types/components/link.ws.d.ts +3 -0
  198. package/lib/types/components/list-item.d.ts +3 -0
  199. package/lib/types/components/list-item.stories.d.ts +5 -0
  200. package/lib/types/components/list-item.ws.d.ts +3 -0
  201. package/lib/types/components/list.d.ts +9 -0
  202. package/lib/types/components/list.stories.d.ts +9 -0
  203. package/lib/types/components/list.ws.d.ts +3 -0
  204. package/lib/types/components/paragraph.d.ts +3 -0
  205. package/lib/types/components/paragraph.stories.d.ts +5 -0
  206. package/lib/types/components/paragraph.ws.d.ts +3 -0
  207. package/lib/types/components/rich-text-link.d.ts +2 -0
  208. package/lib/types/components/rich-text-link.stories.d.ts +13 -0
  209. package/lib/types/components/rich-text-link.ws.d.ts +3 -0
  210. package/lib/types/components/separator.d.ts +3 -0
  211. package/lib/types/components/separator.stories.d.ts +5 -0
  212. package/lib/types/components/separator.ws.d.ts +3 -0
  213. package/lib/types/components/slot.d.ts +6 -0
  214. package/lib/types/components/slot.stories.d.ts +9 -0
  215. package/lib/types/components/slot.ws.d.ts +3 -0
  216. package/lib/types/components/span.d.ts +3 -0
  217. package/lib/types/components/span.stories.d.ts +5 -0
  218. package/lib/types/components/span.ws.d.ts +3 -0
  219. package/lib/types/components/subscript.d.ts +3 -0
  220. package/lib/types/components/subscript.stories.d.ts +5 -0
  221. package/lib/types/components/subscript.ws.d.ts +3 -0
  222. package/lib/types/components/superscript.d.ts +3 -0
  223. package/lib/types/components/superscript.stories.d.ts +5 -0
  224. package/lib/types/components/superscript.ws.d.ts +3 -0
  225. package/lib/types/components/text-block.d.ts +3 -0
  226. package/lib/types/components/text-block.stories.d.ts +5 -0
  227. package/lib/types/components/text-block.ws.d.ts +3 -0
  228. package/lib/types/context.d.ts +9 -0
  229. package/lib/types/css/css.d.ts +10 -0
  230. package/lib/types/css/get-browser-style.d.ts +2 -0
  231. package/lib/types/css/global-rules.d.ts +44 -0
  232. package/lib/types/css/index.d.ts +4 -0
  233. package/lib/types/css/normalize-type-check.d.ts +1 -0
  234. package/lib/types/css/normalize.d.ts +2429 -0
  235. package/lib/types/css/presets.d.ts +38 -0
  236. package/lib/types/css/style-rules.d.ts +248 -0
  237. package/lib/types/css/style-rules.test.d.ts +1 -0
  238. package/lib/types/index.d.ts +9 -0
  239. package/lib/types/props.d.ts +97 -0
  240. package/lib/types/props.test.d.ts +1 -0
  241. package/lib/types/pubsub/create.d.ts +28 -0
  242. package/lib/types/pubsub/index.d.ts +1 -0
  243. package/lib/types/pubsub/raf-queue.d.ts +1 -0
  244. package/lib/types/tree/create-elements-tree.d.ts +16 -0
  245. package/lib/types/tree/index.d.ts +3 -0
  246. package/lib/types/tree/root.d.ts +25 -0
  247. package/lib/types/tree/session-storage-polyfill.d.ts +2 -0
  248. package/lib/types/tree/webstudio-component.d.ts +15 -0
  249. package/package.json +20 -19
  250. package/src/app/custom-components/image.tsx +4 -7
  251. package/src/app/custom-components/shared/remix-link.tsx +12 -48
  252. package/src/components/__generated__/link-block.props.ts +5 -5
  253. package/src/components/__generated__/link.props.ts +6 -6
  254. package/src/components/__generated__/rich-text-link.props.ts +5 -5
  255. package/src/components/blockquote.tsx +1 -1
  256. package/src/components/blockquote.ws.tsx +63 -36
  257. package/src/components/body.tsx +1 -1
  258. package/src/components/body.ws.tsx +39 -47
  259. package/src/components/bold.tsx +1 -1
  260. package/src/components/bold.ws.tsx +10 -2
  261. package/src/components/box.ws.ts +28 -5
  262. package/src/components/button.tsx +1 -1
  263. package/src/components/button.ws.tsx +10 -2
  264. package/src/components/code.tsx +1 -1
  265. package/src/components/code.ws.tsx +36 -28
  266. package/src/components/component-meta.ts +4 -1
  267. package/src/components/form.tsx +1 -1
  268. package/src/components/form.ws.tsx +11 -9
  269. package/src/components/heading.ws.tsx +16 -0
  270. package/src/components/image.tsx +1 -1
  271. package/src/components/image.ws.tsx +19 -12
  272. package/src/components/input.tsx +1 -1
  273. package/src/components/input.ws.tsx +10 -2
  274. package/src/components/italic.tsx +1 -1
  275. package/src/components/italic.ws.tsx +12 -6
  276. package/src/components/link-block.tsx +1 -0
  277. package/src/components/link-block.ws.tsx +16 -10
  278. package/src/components/link.tsx +14 -6
  279. package/src/components/link.ws.tsx +25 -12
  280. package/src/components/list-item.tsx +1 -1
  281. package/src/components/list-item.ws.tsx +8 -0
  282. package/src/components/list.tsx +2 -0
  283. package/src/components/list.ws.tsx +32 -11
  284. package/src/components/paragraph.tsx +1 -1
  285. package/src/components/paragraph.ws.tsx +8 -0
  286. package/src/components/rich-text-link.ws.tsx +6 -3
  287. package/src/components/separator.tsx +1 -1
  288. package/src/components/separator.ws.tsx +33 -12
  289. package/src/components/span.tsx +1 -1
  290. package/src/components/span.ws.tsx +10 -2
  291. package/src/components/subscript.tsx +1 -1
  292. package/src/components/subscript.ws.tsx +8 -0
  293. package/src/components/superscript.tsx +1 -1
  294. package/src/components/superscript.ws.tsx +8 -0
  295. package/src/components/text-block.tsx +1 -1
  296. package/src/components/text-block.ws.tsx +14 -7
  297. package/src/context.tsx +4 -1
  298. package/src/css/css.ts +57 -0
  299. package/src/css/get-browser-style.ts +6 -1
  300. package/src/css/global-rules.ts +29 -0
  301. package/src/css/index.ts +3 -1
  302. package/src/css/normalize-type-check.ts +13 -0
  303. package/src/css/normalize.ts +519 -0
  304. package/src/css/presets.ts +42 -0
  305. package/src/css/style-rules.test.ts +147 -0
  306. package/src/css/style-rules.ts +66 -0
  307. package/src/props.test.ts +95 -0
  308. package/src/props.ts +59 -5
  309. package/src/pubsub/create.ts +7 -38
  310. package/src/pubsub/raf-queue.ts +31 -0
  311. package/src/tree/create-elements-tree.tsx +7 -2
  312. package/src/tree/root.ts +2 -0
  313. package/src/tree/webstudio-component.tsx +1 -0
  314. package/lib/cjs/css/categories.cjs +0 -250
  315. package/lib/css/categories.js +0 -230
  316. package/src/css/categories.ts +0 -254
  317. package/lib/cjs/app/custom-components/{index.cjs → index.js} +0 -0
  318. package/lib/cjs/app/custom-components/{link-block.cjs → link-block.js} +0 -0
  319. package/lib/cjs/app/custom-components/{link.cjs → link.js} +0 -0
  320. package/lib/cjs/app/custom-components/{rich-text-link.cjs → rich-text-link.js} +0 -0
  321. package/lib/cjs/app/{handle-request.server.cjs → handle-request.server.js} +0 -0
  322. package/lib/cjs/app/{index.cjs → index.js} +0 -0
  323. package/lib/cjs/app/{params.cjs → params.js} +0 -0
  324. package/lib/cjs/app/{root.cjs → root.js} +0 -0
  325. package/lib/cjs/components/__generated__/{blockquote.props.cjs → blockquote.props.js} +0 -0
  326. package/lib/cjs/components/__generated__/{body.props.cjs → body.props.js} +0 -0
  327. package/lib/cjs/components/__generated__/{bold.props.cjs → bold.props.js} +0 -0
  328. package/lib/cjs/components/__generated__/{box.props.cjs → box.props.js} +0 -0
  329. package/lib/cjs/components/__generated__/{button.props.cjs → button.props.js} +0 -0
  330. package/lib/cjs/components/__generated__/{code.props.cjs → code.props.js} +0 -0
  331. package/lib/cjs/components/__generated__/{form.props.cjs → form.props.js} +0 -0
  332. package/lib/cjs/components/__generated__/{fragment.props.cjs → fragment.props.js} +0 -0
  333. package/lib/cjs/components/__generated__/{heading.props.cjs → heading.props.js} +0 -0
  334. package/lib/cjs/components/__generated__/{image.props.cjs → image.props.js} +0 -0
  335. package/lib/cjs/components/__generated__/{input.props.cjs → input.props.js} +0 -0
  336. package/lib/cjs/components/__generated__/{italic.props.cjs → italic.props.js} +0 -0
  337. package/lib/cjs/components/__generated__/{link-block.props.cjs → link-block.props.js} +5 -5
  338. package/lib/cjs/components/__generated__/{list-item.props.cjs → list-item.props.js} +0 -0
  339. package/lib/cjs/components/__generated__/{list.props.cjs → list.props.js} +0 -0
  340. package/lib/cjs/components/__generated__/{paragraph.props.cjs → paragraph.props.js} +0 -0
  341. package/lib/cjs/components/__generated__/{rich-text-link.props.cjs → rich-text-link.props.js} +5 -5
  342. /package/lib/cjs/components/__generated__/{separator.props.cjs → separator.props.js} +0 -0
  343. /package/lib/cjs/components/__generated__/{slot.props.cjs → slot.props.js} +0 -0
  344. /package/lib/cjs/components/__generated__/{span.props.cjs → span.props.js} +0 -0
  345. /package/lib/cjs/components/__generated__/{subscript.props.cjs → subscript.props.js} +0 -0
  346. /package/lib/cjs/components/__generated__/{superscript.props.cjs → superscript.props.js} +0 -0
  347. /package/lib/cjs/components/__generated__/{text-block.props.cjs → text-block.props.js} +0 -0
  348. /package/lib/cjs/components/{box.cjs → box.js} +0 -0
  349. /package/lib/cjs/components/{component-meta.cjs → component-meta.js} +0 -0
  350. /package/lib/cjs/components/{components-utils.cjs → components-utils.js} +0 -0
  351. /package/lib/cjs/components/{components.cjs → components.js} +0 -0
  352. /package/lib/cjs/components/{fragment.cjs → fragment.js} +0 -0
  353. /package/lib/cjs/components/{fragment.ws.cjs → fragment.ws.js} +0 -0
  354. /package/lib/cjs/components/{heading.cjs → heading.js} +0 -0
  355. /package/lib/cjs/components/{index.cjs → index.js} +0 -0
  356. /package/lib/cjs/components/{list.cjs → list.js} +0 -0
  357. /package/lib/cjs/components/{rich-text-link.cjs → rich-text-link.js} +0 -0
  358. /package/lib/cjs/components/{slot.cjs → slot.js} +0 -0
  359. /package/lib/cjs/components/{slot.ws.cjs → slot.ws.js} +0 -0
  360. /package/lib/cjs/css/{get-browser-style.cjs → get-browser-style.js} +0 -0
  361. /package/lib/cjs/{index.cjs → index.js} +0 -0
  362. /package/lib/cjs/pubsub/{index.cjs → index.js} +0 -0
  363. /package/lib/cjs/tree/{index.cjs → index.js} +0 -0
  364. /package/lib/cjs/tree/{session-storage-polyfill.cjs → session-storage-polyfill.js} +0 -0
@@ -0,0 +1,147 @@
1
+ import { test, expect } from "@jest/globals";
2
+ import type {
3
+ Styles,
4
+ StyleSourceSelections,
5
+ } from "@webstudio-is/project-build";
6
+ import { getStyleRules } from "./style-rules";
7
+
8
+ test("compute styles from different style sources", () => {
9
+ const styles: Styles = new Map([
10
+ [
11
+ "styleSource1:a:width",
12
+ {
13
+ breakpointId: "a",
14
+ styleSourceId: "styleSource1",
15
+ property: "width",
16
+ value: { type: "unit", value: 10, unit: "px" },
17
+ },
18
+ ],
19
+ [
20
+ "styleSource2:a:display",
21
+ {
22
+ breakpointId: "a",
23
+ styleSourceId: "styleSource2",
24
+ property: "display",
25
+ value: { type: "keyword", value: "block" },
26
+ },
27
+ ],
28
+ [
29
+ "styleSource4:a:color",
30
+ {
31
+ breakpointId: "a",
32
+ styleSourceId: "styleSource4",
33
+ property: "color",
34
+ value: { type: "keyword", value: "green" },
35
+ },
36
+ ],
37
+ [
38
+ "styleSource4:a:width",
39
+ {
40
+ breakpointId: "a",
41
+ styleSourceId: "styleSource4",
42
+ property: "width",
43
+ value: { type: "keyword", value: "min-content" },
44
+ },
45
+ ],
46
+ [
47
+ "styleSource3:a:color",
48
+ {
49
+ breakpointId: "a",
50
+ styleSourceId: "styleSource3",
51
+ property: "color",
52
+ value: { type: "keyword", value: "red" },
53
+ },
54
+ ],
55
+ [
56
+ "styleSource5:b:color",
57
+ {
58
+ breakpointId: "b",
59
+ styleSourceId: "styleSource5",
60
+ property: "color",
61
+ value: { type: "keyword", value: "orange" },
62
+ },
63
+ ],
64
+ [
65
+ "styleSource6:a:color",
66
+ {
67
+ breakpointId: "a",
68
+ styleSourceId: "styleSource6",
69
+ property: "color",
70
+ value: { type: "keyword", value: "blue" },
71
+ },
72
+ ],
73
+ ]);
74
+ const styleSourceSelections: StyleSourceSelections = new Map([
75
+ [
76
+ "instance1",
77
+ {
78
+ instanceId: "instance1",
79
+ values: ["styleSource1"],
80
+ },
81
+ ],
82
+ [
83
+ "instance2",
84
+ {
85
+ instanceId: "instance2",
86
+ values: ["styleSource4", "styleSource5", "styleSource3"],
87
+ },
88
+ ],
89
+ [
90
+ "instance3",
91
+ {
92
+ instanceId: "instance3",
93
+ values: ["styleSource6"],
94
+ },
95
+ ],
96
+ ]);
97
+
98
+ expect(getStyleRules(styles, styleSourceSelections)).toMatchInlineSnapshot(`
99
+ [
100
+ {
101
+ "breakpointId": "a",
102
+ "instanceId": "instance1",
103
+ "style": {
104
+ "width": {
105
+ "type": "unit",
106
+ "unit": "px",
107
+ "value": 10,
108
+ },
109
+ },
110
+ },
111
+ {
112
+ "breakpointId": "a",
113
+ "instanceId": "instance2",
114
+ "style": {
115
+ "color": {
116
+ "type": "keyword",
117
+ "value": "red",
118
+ },
119
+ "width": {
120
+ "type": "keyword",
121
+ "value": "min-content",
122
+ },
123
+ },
124
+ },
125
+ {
126
+ "breakpointId": "b",
127
+ "instanceId": "instance2",
128
+ "style": {
129
+ "color": {
130
+ "type": "keyword",
131
+ "value": "orange",
132
+ },
133
+ },
134
+ },
135
+ {
136
+ "breakpointId": "a",
137
+ "instanceId": "instance3",
138
+ "style": {
139
+ "color": {
140
+ "type": "keyword",
141
+ "value": "blue",
142
+ },
143
+ },
144
+ },
145
+ ]
146
+ `);
147
+ });
@@ -0,0 +1,66 @@
1
+ import type { Style } from "@webstudio-is/css-data";
2
+ import type {
3
+ Breakpoint,
4
+ StyleDecl,
5
+ Styles,
6
+ StyleSource,
7
+ StyleSourceSelections,
8
+ } from "@webstudio-is/project-build";
9
+
10
+ type StyleRule = {
11
+ instanceId: string;
12
+ breakpointId: string;
13
+ style: Style;
14
+ };
15
+
16
+ /**
17
+ * Merge styles from different style sources
18
+ * and group by instance and breakpoint
19
+ */
20
+ export const getStyleRules = (
21
+ styles: Styles,
22
+ styleSourceSelections: StyleSourceSelections
23
+ ) => {
24
+ if (styles === undefined || styleSourceSelections === undefined) {
25
+ return [];
26
+ }
27
+ const stylesByStyleSourceId = new Map<StyleSource["id"], StyleDecl[]>();
28
+ for (const styleDecl of styles.values()) {
29
+ const { styleSourceId } = styleDecl;
30
+ let styleSourceStyles = stylesByStyleSourceId.get(styleSourceId);
31
+ // instance can be undefined when style is from other tree
32
+ if (styleSourceStyles === undefined) {
33
+ styleSourceStyles = [];
34
+ stylesByStyleSourceId.set(styleSourceId, styleSourceStyles);
35
+ }
36
+ styleSourceStyles.push(styleDecl);
37
+ }
38
+
39
+ const styleRules: StyleRule[] = [];
40
+ for (const { instanceId, values } of styleSourceSelections.values()) {
41
+ const styleRuleByBreakpointId = new Map<Breakpoint["id"], StyleRule>();
42
+
43
+ for (const styleSourceId of values) {
44
+ const styleSourceStyles = stylesByStyleSourceId.get(styleSourceId);
45
+ // instance can be undefined when style is from other tree
46
+ if (styleSourceStyles === undefined) {
47
+ continue;
48
+ }
49
+ for (const { breakpointId, property, value } of styleSourceStyles) {
50
+ let styleRule = styleRuleByBreakpointId.get(breakpointId);
51
+ if (styleRule === undefined) {
52
+ styleRule = {
53
+ instanceId,
54
+ breakpointId,
55
+ style: {},
56
+ };
57
+ styleRuleByBreakpointId.set(breakpointId, styleRule);
58
+ }
59
+ styleRule.style[property] = value;
60
+ }
61
+ }
62
+ styleRules.push(...styleRuleByBreakpointId.values());
63
+ }
64
+
65
+ return styleRules;
66
+ };
@@ -0,0 +1,95 @@
1
+ import { describe, test, expect } from "@jest/globals";
2
+ import { resolveUrlProp, type Pages, type PropsByInstanceId } from "./props";
3
+ import type { Page, Prop } from "@webstudio-is/project-build";
4
+
5
+ const unique = () => Math.random().toString();
6
+
7
+ describe("resolveUrlProp", () => {
8
+ const instanceId = unique();
9
+
10
+ const page1: Page = {
11
+ id: unique(),
12
+ path: `/${unique()}`,
13
+ name: "",
14
+ title: "",
15
+ meta: {},
16
+ rootInstanceId: "0",
17
+ };
18
+
19
+ const page2: Page = {
20
+ id: unique(),
21
+ path: `/${unique()}`,
22
+ name: "",
23
+ title: "",
24
+ meta: {},
25
+ rootInstanceId: "0",
26
+ };
27
+
28
+ const pageByIdProp: Prop = {
29
+ type: "page",
30
+ id: unique(),
31
+ instanceId,
32
+ name: unique(),
33
+ value: page1.id,
34
+ };
35
+
36
+ const pageByPathProp: Prop = {
37
+ type: "string",
38
+ id: unique(),
39
+ instanceId,
40
+ name: unique(),
41
+ value: page2.path,
42
+ };
43
+
44
+ const arbitraryUrlProp: Prop = {
45
+ type: "string",
46
+ id: unique(),
47
+ instanceId,
48
+ name: unique(),
49
+ value: unique(),
50
+ };
51
+
52
+ const propsByInstanceId: PropsByInstanceId = new Map([
53
+ [instanceId, [pageByIdProp, pageByPathProp, arbitraryUrlProp]],
54
+ ]);
55
+
56
+ const pages: Pages = new Map([
57
+ [page1.id, page1],
58
+ [page2.id, page2],
59
+ ]);
60
+
61
+ test("if instanceId is unknown returns undefined", () => {
62
+ expect(
63
+ resolveUrlProp("unknown", pageByIdProp.name, propsByInstanceId, pages)
64
+ ).toBeUndefined();
65
+ });
66
+
67
+ test("if prop name is unknown returns undefined", () => {
68
+ expect(
69
+ resolveUrlProp(instanceId, "unknown", propsByInstanceId, pages)
70
+ ).toBeUndefined();
71
+ });
72
+
73
+ test("page by id", () => {
74
+ expect(
75
+ resolveUrlProp(instanceId, pageByIdProp.name, propsByInstanceId, pages)
76
+ ).toBe(page1);
77
+ });
78
+
79
+ test("page by path", () => {
80
+ expect(
81
+ resolveUrlProp(instanceId, pageByPathProp.name, propsByInstanceId, pages)
82
+ ).toBe(page2);
83
+ });
84
+
85
+ test("arbitrary url", () => {
86
+ expect(
87
+ resolveUrlProp(
88
+ instanceId,
89
+ arbitraryUrlProp.name,
90
+ propsByInstanceId,
91
+ pages
92
+ )
93
+ ).toBe(arbitraryUrlProp.value);
94
+ });
95
+ });
package/src/props.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { useContext, useMemo } from "react";
2
2
  import { computed } from "nanostores";
3
3
  import { useStore } from "@nanostores/react";
4
- import type { Instance, Prop, Props } from "@webstudio-is/project-build";
5
- import type { Asset } from "@webstudio-is/asset-uploader";
4
+ import type { Instance, Page, Prop, Props } from "@webstudio-is/project-build";
6
5
  import { ReactSdkContext } from "./context";
6
+ import { idAttribute } from "./tree/webstudio-component";
7
7
 
8
8
  export type PropsByInstanceId = Map<Instance["id"], Prop[]>;
9
9
 
10
- export type Assets = Map<Asset["id"], Asset>;
10
+ export type Pages = Map<Page["id"], Page>;
11
11
 
12
12
  export const getPropsByInstanceId = (props: Props) => {
13
13
  const propsByInstanceId: PropsByInstanceId = new Map();
@@ -39,7 +39,7 @@ export const useInstanceProps = (instanceId: Instance["id"]) => {
39
39
  return instancePropsObject;
40
40
  };
41
41
 
42
- // this utility is be used for image component in both builder and preview
42
+ // this utility is used for image component in both builder and preview
43
43
  // so need to optimize rerenders with computed
44
44
  export const usePropAsset = (instanceId: Instance["id"], name: string) => {
45
45
  const { propsByInstanceIdStore, assetsStore } = useContext(ReactSdkContext);
@@ -49,7 +49,7 @@ export const usePropAsset = (instanceId: Instance["id"], name: string) => {
49
49
  (propsByInstanceId, assets) => {
50
50
  const instanceProps = propsByInstanceId.get(instanceId);
51
51
  if (instanceProps === undefined) {
52
- return undefined;
52
+ return;
53
53
  }
54
54
  for (const prop of instanceProps) {
55
55
  if (prop.type === "asset" && prop.name === name) {
@@ -63,3 +63,57 @@ export const usePropAsset = (instanceId: Instance["id"], name: string) => {
63
63
  const asset = useStore(assetStore);
64
64
  return asset;
65
65
  };
66
+
67
+ export const resolveUrlProp = (
68
+ instanceId: Instance["id"],
69
+ name: string,
70
+ propsByInstanceId: PropsByInstanceId,
71
+ pages: Pages
72
+ ): Page | string | undefined => {
73
+ const instanceProps = propsByInstanceId.get(instanceId);
74
+ if (instanceProps === undefined) {
75
+ return;
76
+ }
77
+ for (const prop of instanceProps) {
78
+ if (prop.name !== name) {
79
+ continue;
80
+ }
81
+
82
+ if (prop.type === "page") {
83
+ return pages.get(prop.value);
84
+ }
85
+
86
+ if (prop.type === "string") {
87
+ for (const page of pages.values()) {
88
+ if (page.path === prop.value) {
89
+ return page;
90
+ }
91
+ }
92
+ return prop.value;
93
+ }
94
+
95
+ return;
96
+ }
97
+ };
98
+
99
+ // this utility is used for link component in both builder and preview
100
+ // so need to optimize rerenders with computed
101
+ export const usePropUrl = (instanceId: Instance["id"], name: string) => {
102
+ const { propsByInstanceIdStore, pagesStore } = useContext(ReactSdkContext);
103
+ const pageStore = useMemo(
104
+ () =>
105
+ computed(
106
+ [propsByInstanceIdStore, pagesStore],
107
+ (propsByInstanceId, pages) =>
108
+ resolveUrlProp(instanceId, name, propsByInstanceId, pages)
109
+ ),
110
+ [propsByInstanceIdStore, pagesStore, instanceId, name]
111
+ );
112
+ return useStore(pageStore);
113
+ };
114
+
115
+ export const getInstanceIdFromComponentProps = (
116
+ props: Record<string, unknown>
117
+ ) => {
118
+ return props[idAttribute] as string;
119
+ };
@@ -1,5 +1,6 @@
1
- import mitt from "mitt";
1
+ import { createNanoEvents } from "nanoevents";
2
2
  import { useCallback, useEffect, useRef } from "react";
3
+ import { batchUpdate } from "./raf-queue";
3
4
 
4
5
  export const createPubsub = <PublishMap>() => {
5
6
  type Action<Type extends keyof PublishMap> =
@@ -7,9 +8,8 @@ export const createPubsub = <PublishMap>() => {
7
8
  ? { type: Type; payload?: PublishMap[Type] }
8
9
  : { type: Type; payload: PublishMap[Type] };
9
10
 
10
- // `mitt` has a somewhat annoying overload for `*` type that makes it hard to wrap in a generic context
11
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- const emitter = mitt<Record<any, any>>();
12
+ const emitter = createNanoEvents<Record<any, any>>();
13
13
 
14
14
  if (typeof window === "object") {
15
15
  window.addEventListener(
@@ -19,7 +19,8 @@ export const createPubsub = <PublishMap>() => {
19
19
  // we could potentially maintain a list of valid event types at runtime
20
20
  // at the very least we could add a brand property or something to our events
21
21
  if (typeof event.data?.type === "string") {
22
- emitter.emit(event.data.type, event.data.payload);
22
+ // Execute all updates within a single batch to improve performance
23
+ batchUpdate(() => emitter.emit(event.data.type, event.data.payload));
23
24
  }
24
25
  },
25
26
  false
@@ -62,47 +63,15 @@ export const createPubsub = <PublishMap>() => {
62
63
  onAction: (payload: PublishMap[Type]) => void
63
64
  ) {
64
65
  useEffect(() => {
65
- emitter.on(type, onAction);
66
- return () => {
67
- emitter.off(type, onAction);
68
- };
66
+ return emitter.on(type, onAction);
69
67
  }, [type, onAction]);
70
68
  },
71
69
 
72
- useSubscribeAll(
73
- onAction: <Type extends keyof PublishMap>(
74
- type: Type,
75
- payload: PublishMap[Type]
76
- ) => void
77
- ) {
78
- useEffect(() => {
79
- emitter.on("*", onAction);
80
- return () => {
81
- emitter.off("*", onAction);
82
- };
83
- }, [onAction]);
84
- },
85
-
86
70
  subscribe<Type extends keyof PublishMap>(
87
71
  type: Type,
88
72
  onAction: (payload: PublishMap[Type]) => void
89
73
  ) {
90
- emitter.on(type, onAction);
91
- return () => {
92
- emitter.off(type, onAction);
93
- };
94
- },
95
-
96
- subscribeAll(
97
- onAction: <Type extends keyof PublishMap>(
98
- type: Type,
99
- payload: PublishMap[Type]
100
- ) => void
101
- ) {
102
- emitter.on("*", onAction);
103
- return () => {
104
- emitter.off("*", onAction);
105
- };
74
+ return emitter.on(type, onAction);
106
75
  },
107
76
  };
108
77
  };
@@ -0,0 +1,31 @@
1
+ import { unstable_batchedUpdates as batchedUpdates } from "react-dom";
2
+
3
+ type Task = () => void;
4
+
5
+ let handle: ReturnType<typeof requestAnimationFrame> | undefined;
6
+ let updateQueue: Task[] = [];
7
+
8
+ const processUpdates = (updates: Task[]) => {
9
+ // Prior to React v18, updates not called within React event handlers would not be batched
10
+ // To ensure all updates are batched into a single React update, we wrap them in a batchedUpdates callback
11
+ batchedUpdates(() => {
12
+ for (const update of updates) {
13
+ update();
14
+ }
15
+ });
16
+ };
17
+
18
+ export const batchUpdate = (update: () => void) => {
19
+ updateQueue.push(update);
20
+
21
+ if (handle !== undefined) {
22
+ return;
23
+ }
24
+
25
+ handle = requestAnimationFrame(() => {
26
+ const updates = updateQueue;
27
+ updateQueue = [];
28
+ handle = undefined;
29
+ processUpdates(updates);
30
+ });
31
+ };
@@ -1,10 +1,11 @@
1
1
  import { type ComponentProps, Fragment } from "react";
2
2
  import type { ReadableAtom } from "nanostores";
3
3
  import { Scripts, ScrollRestoration } from "@remix-run/react";
4
+ import type { Assets } from "@webstudio-is/asset-uploader";
4
5
  import type { Instance } from "@webstudio-is/project-build";
5
6
  import type { GetComponent } from "../components/components-utils";
6
7
  import { ReactSdkContext } from "../context";
7
- import type { Assets, PropsByInstanceId } from "../props";
8
+ import type { Pages, PropsByInstanceId } from "../props";
8
9
  import type { WebstudioComponent } from "./webstudio-component";
9
10
  import { SessionStoragePolyfill } from "./session-storage-polyfill";
10
11
 
@@ -15,6 +16,7 @@ export const createElementsTree = ({
15
16
  instance,
16
17
  propsByInstanceIdStore,
17
18
  assetsStore,
19
+ pagesStore,
18
20
  Component,
19
21
  getComponent,
20
22
  }: {
@@ -22,6 +24,7 @@ export const createElementsTree = ({
22
24
  instance: Instance;
23
25
  propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
24
26
  assetsStore: ReadableAtom<Assets>;
27
+ pagesStore: ReadableAtom<Pages>;
25
28
  Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
26
29
  getComponent: GetComponent;
27
30
  }) => {
@@ -47,7 +50,9 @@ export const createElementsTree = ({
47
50
  getComponent,
48
51
  });
49
52
  return (
50
- <ReactSdkContext.Provider value={{ propsByInstanceIdStore, assetsStore }}>
53
+ <ReactSdkContext.Provider
54
+ value={{ propsByInstanceIdStore, assetsStore, pagesStore }}
55
+ >
51
56
  {root}
52
57
  </ReactSdkContext.Provider>
53
58
  );
package/src/tree/root.ts CHANGED
@@ -18,6 +18,7 @@ import type { GetComponent } from "../components/components-utils";
18
18
 
19
19
  export type Data = {
20
20
  page: Page;
21
+ pages: Array<Page>;
21
22
  build: Build;
22
23
  assets: Array<Asset>;
23
24
  params?: Params;
@@ -86,6 +87,7 @@ export const InstanceRoot = ({
86
87
  getPropsByInstanceId(new Map(data.build.props))
87
88
  ),
88
89
  assetsStore: atom(new Map(data.assets.map((asset) => [asset.id, asset]))),
90
+ pagesStore: atom(new Map(data.pages.map((page) => [page.id, page]))),
89
91
  Component: Component ?? WebstudioComponent,
90
92
  getComponent,
91
93
  });
@@ -35,6 +35,7 @@ type WebstudioComponentProps = {
35
35
 
36
36
  export const WebstudioComponent = ({
37
37
  instance,
38
+ instanceSelector,
38
39
  children,
39
40
  getComponent,
40
41
  ...rest