@superblocksteam/vite-plugin-file-sync 2.0.3-next.100

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 (558) hide show
  1. package/LICENSE.txt +87 -0
  2. package/dist/ai-service/artifacts/bolt.d.ts +8 -0
  3. package/dist/ai-service/artifacts/bolt.d.ts.map +1 -0
  4. package/dist/ai-service/artifacts/bolt.js +34 -0
  5. package/dist/ai-service/artifacts/bolt.js.map +1 -0
  6. package/dist/ai-service/const.d.ts +8 -0
  7. package/dist/ai-service/const.d.ts.map +1 -0
  8. package/dist/ai-service/const.js +9 -0
  9. package/dist/ai-service/const.js.map +1 -0
  10. package/dist/ai-service/eval/template-renderer.d.ts +13 -0
  11. package/dist/ai-service/eval/template-renderer.d.ts.map +1 -0
  12. package/dist/ai-service/eval/template-renderer.js +66 -0
  13. package/dist/ai-service/eval/template-renderer.js.map +1 -0
  14. package/dist/ai-service/index.d.ts +18 -0
  15. package/dist/ai-service/index.d.ts.map +1 -0
  16. package/dist/ai-service/index.js +140 -0
  17. package/dist/ai-service/index.js.map +1 -0
  18. package/dist/ai-service/integrations/const.d.ts +41 -0
  19. package/dist/ai-service/integrations/const.d.ts.map +1 -0
  20. package/dist/ai-service/integrations/const.js +76 -0
  21. package/dist/ai-service/integrations/const.js.map +1 -0
  22. package/dist/ai-service/integrations/from-prompt-context.d.ts +4 -0
  23. package/dist/ai-service/integrations/from-prompt-context.d.ts.map +1 -0
  24. package/dist/ai-service/integrations/from-prompt-context.js +56 -0
  25. package/dist/ai-service/integrations/from-prompt-context.js.map +1 -0
  26. package/dist/ai-service/integrations/to-sdk-prompt.d.ts +3 -0
  27. package/dist/ai-service/integrations/to-sdk-prompt.d.ts.map +1 -0
  28. package/dist/ai-service/integrations/to-sdk-prompt.js +47 -0
  29. package/dist/ai-service/integrations/to-sdk-prompt.js.map +1 -0
  30. package/dist/ai-service/integrations/types.d.ts +31 -0
  31. package/dist/ai-service/integrations/types.d.ts.map +1 -0
  32. package/dist/ai-service/integrations/types.js +2 -0
  33. package/dist/ai-service/integrations/types.js.map +1 -0
  34. package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.d.ts +2 -0
  35. package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.d.ts.map +1 -0
  36. package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.js +386 -0
  37. package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.js.map +1 -0
  38. package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.d.ts +2 -0
  39. package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.d.ts.map +1 -0
  40. package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.js +219 -0
  41. package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.js.map +1 -0
  42. package/dist/ai-service/prompts/generated/index.d.ts +4 -0
  43. package/dist/ai-service/prompts/generated/index.d.ts.map +1 -0
  44. package/dist/ai-service/prompts/generated/index.js +6 -0
  45. package/dist/ai-service/prompts/generated/index.js.map +1 -0
  46. package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.d.ts +2 -0
  47. package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.d.ts.map +1 -0
  48. package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.js +6 -0
  49. package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.js.map +1 -0
  50. package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.d.ts +2 -0
  51. package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.d.ts.map +1 -0
  52. package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.js +6 -0
  53. package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.js.map +1 -0
  54. package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.d.ts +2 -0
  55. package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.d.ts.map +1 -0
  56. package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.js +6 -0
  57. package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.js.map +1 -0
  58. package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.d.ts +2 -0
  59. package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.d.ts.map +1 -0
  60. package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.js +6 -0
  61. package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.js.map +1 -0
  62. package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.d.ts +2 -0
  63. package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.d.ts.map +1 -0
  64. package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.js +6 -0
  65. package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.js.map +1 -0
  66. package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.d.ts +2 -0
  67. package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.d.ts.map +1 -0
  68. package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.js +6 -0
  69. package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.js.map +1 -0
  70. package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.d.ts +2 -0
  71. package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.d.ts.map +1 -0
  72. package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.js +6 -0
  73. package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.js.map +1 -0
  74. package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.d.ts +2 -0
  75. package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.d.ts.map +1 -0
  76. package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.js +6 -0
  77. package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.js.map +1 -0
  78. package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.d.ts +2 -0
  79. package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.d.ts.map +1 -0
  80. package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.js +6 -0
  81. package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.js.map +1 -0
  82. package/dist/ai-service/prompts/generated/library-components/SbKeyValuePropsDocs.d.ts +2 -0
  83. package/dist/ai-service/prompts/generated/library-components/SbKeyValuePropsDocs.d.ts.map +1 -0
  84. package/dist/ai-service/prompts/generated/library-components/SbKeyValuePropsDocs.js +6 -0
  85. package/dist/ai-service/prompts/generated/library-components/SbKeyValuePropsDocs.js.map +1 -0
  86. package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.d.ts +2 -0
  87. package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.d.ts.map +1 -0
  88. package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.js +6 -0
  89. package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.js.map +1 -0
  90. package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.d.ts +2 -0
  91. package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.d.ts.map +1 -0
  92. package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.js +6 -0
  93. package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.js.map +1 -0
  94. package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.d.ts +2 -0
  95. package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.d.ts.map +1 -0
  96. package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.js +6 -0
  97. package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.js.map +1 -0
  98. package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.d.ts +2 -0
  99. package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.d.ts.map +1 -0
  100. package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.js +6 -0
  101. package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.js.map +1 -0
  102. package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.d.ts +2 -0
  103. package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.d.ts.map +1 -0
  104. package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.js +6 -0
  105. package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.js.map +1 -0
  106. package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.d.ts +2 -0
  107. package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.d.ts.map +1 -0
  108. package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.js +6 -0
  109. package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.js.map +1 -0
  110. package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.d.ts +2 -0
  111. package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.d.ts.map +1 -0
  112. package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.js +6 -0
  113. package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.js.map +1 -0
  114. package/dist/ai-service/prompts/generated/library-components/index.d.ts +18 -0
  115. package/dist/ai-service/prompts/generated/library-components/index.d.ts.map +1 -0
  116. package/dist/ai-service/prompts/generated/library-components/index.js +20 -0
  117. package/dist/ai-service/prompts/generated/library-components/index.js.map +1 -0
  118. package/dist/ai-service/prompts/generated/library-typedefs/Dim.d.ts +2 -0
  119. package/dist/ai-service/prompts/generated/library-typedefs/Dim.d.ts.map +1 -0
  120. package/dist/ai-service/prompts/generated/library-typedefs/Dim.js +6 -0
  121. package/dist/ai-service/prompts/generated/library-typedefs/Dim.js.map +1 -0
  122. package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.d.ts +2 -0
  123. package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.d.ts.map +1 -0
  124. package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.js +6 -0
  125. package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.js.map +1 -0
  126. package/dist/ai-service/prompts/generated/library-typedefs/index.d.ts +3 -0
  127. package/dist/ai-service/prompts/generated/library-typedefs/index.d.ts.map +1 -0
  128. package/dist/ai-service/prompts/generated/library-typedefs/index.js +5 -0
  129. package/dist/ai-service/prompts/generated/library-typedefs/index.js.map +1 -0
  130. package/dist/ai-service/prompts/generated/subprompts/index.d.ts +11 -0
  131. package/dist/ai-service/prompts/generated/subprompts/index.d.ts.map +1 -0
  132. package/dist/ai-service/prompts/generated/subprompts/index.js +13 -0
  133. package/dist/ai-service/prompts/generated/subprompts/index.js.map +1 -0
  134. package/dist/ai-service/prompts/generated/subprompts/superblocks-api.d.ts +2 -0
  135. package/dist/ai-service/prompts/generated/subprompts/superblocks-api.d.ts.map +1 -0
  136. package/dist/ai-service/prompts/generated/subprompts/superblocks-api.js +6 -0
  137. package/dist/ai-service/prompts/generated/subprompts/superblocks-api.js.map +1 -0
  138. package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.d.ts +2 -0
  139. package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.d.ts.map +1 -0
  140. package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.js +6 -0
  141. package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.js.map +1 -0
  142. package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.d.ts +2 -0
  143. package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.d.ts.map +1 -0
  144. package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.js +6 -0
  145. package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.js.map +1 -0
  146. package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.d.ts +2 -0
  147. package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.d.ts.map +1 -0
  148. package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.js +6 -0
  149. package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.js.map +1 -0
  150. package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.d.ts +2 -0
  151. package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.d.ts.map +1 -0
  152. package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.js +6 -0
  153. package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.js.map +1 -0
  154. package/dist/ai-service/prompts/generated/subprompts/superblocks-page.d.ts +2 -0
  155. package/dist/ai-service/prompts/generated/subprompts/superblocks-page.d.ts.map +1 -0
  156. package/dist/ai-service/prompts/generated/subprompts/superblocks-page.js +6 -0
  157. package/dist/ai-service/prompts/generated/subprompts/superblocks-page.js.map +1 -0
  158. package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.d.ts +2 -0
  159. package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.d.ts.map +1 -0
  160. package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.js +6 -0
  161. package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.js.map +1 -0
  162. package/dist/ai-service/prompts/generated/subprompts/superblocks-state.d.ts +2 -0
  163. package/dist/ai-service/prompts/generated/subprompts/superblocks-state.d.ts.map +1 -0
  164. package/dist/ai-service/prompts/generated/subprompts/superblocks-state.js +6 -0
  165. package/dist/ai-service/prompts/generated/subprompts/superblocks-state.js.map +1 -0
  166. package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.d.ts +2 -0
  167. package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.d.ts.map +1 -0
  168. package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.js +6 -0
  169. package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.js.map +1 -0
  170. package/dist/ai-service/prompts/generated/subprompts/system.d.ts +2 -0
  171. package/dist/ai-service/prompts/generated/subprompts/system.d.ts.map +1 -0
  172. package/dist/ai-service/prompts/generated/subprompts/system.js +6 -0
  173. package/dist/ai-service/prompts/generated/subprompts/system.js.map +1 -0
  174. package/dist/ai-service/prompts/markdown-loader.d.ts +10 -0
  175. package/dist/ai-service/prompts/markdown-loader.d.ts.map +1 -0
  176. package/dist/ai-service/prompts/markdown-loader.js +65 -0
  177. package/dist/ai-service/prompts/markdown-loader.js.map +1 -0
  178. package/dist/ai-service/prompts/system.d.ts +2 -0
  179. package/dist/ai-service/prompts/system.d.ts.map +1 -0
  180. package/dist/ai-service/prompts/system.js +152 -0
  181. package/dist/ai-service/prompts/system.js.map +1 -0
  182. package/dist/ai-service/result-buffer/bolt.d.ts +15 -0
  183. package/dist/ai-service/result-buffer/bolt.d.ts.map +1 -0
  184. package/dist/ai-service/result-buffer/bolt.js +73 -0
  185. package/dist/ai-service/result-buffer/bolt.js.map +1 -0
  186. package/dist/ai-service/result-buffer/shared.d.ts +13 -0
  187. package/dist/ai-service/result-buffer/shared.d.ts.map +1 -0
  188. package/dist/ai-service/result-buffer/shared.js +7 -0
  189. package/dist/ai-service/result-buffer/shared.js.map +1 -0
  190. package/dist/ai-service/state-machine/clark-fsm.d.ts +158 -0
  191. package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -0
  192. package/dist/ai-service/state-machine/clark-fsm.js +62 -0
  193. package/dist/ai-service/state-machine/clark-fsm.js.map +1 -0
  194. package/dist/ai-service/state-machine/fsm.d.ts +42 -0
  195. package/dist/ai-service/state-machine/fsm.d.ts.map +1 -0
  196. package/dist/ai-service/state-machine/fsm.js +55 -0
  197. package/dist/ai-service/state-machine/fsm.js.map +1 -0
  198. package/dist/ai-service/state-machine/handlers/agent-planning.d.ts +3 -0
  199. package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -0
  200. package/dist/ai-service/state-machine/handlers/agent-planning.js +209 -0
  201. package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -0
  202. package/dist/ai-service/state-machine/handlers/awaiting-user.d.ts +3 -0
  203. package/dist/ai-service/state-machine/handlers/awaiting-user.d.ts.map +1 -0
  204. package/dist/ai-service/state-machine/handlers/awaiting-user.js +21 -0
  205. package/dist/ai-service/state-machine/handlers/awaiting-user.js.map +1 -0
  206. package/dist/ai-service/state-machine/handlers/idle.d.ts +3 -0
  207. package/dist/ai-service/state-machine/handlers/idle.d.ts.map +1 -0
  208. package/dist/ai-service/state-machine/handlers/idle.js +22 -0
  209. package/dist/ai-service/state-machine/handlers/idle.js.map +1 -0
  210. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts +3 -0
  211. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -0
  212. package/dist/ai-service/state-machine/handlers/llm-generating.js +123 -0
  213. package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -0
  214. package/dist/ai-service/state-machine/handlers/play-dead.d.ts +3 -0
  215. package/dist/ai-service/state-machine/handlers/play-dead.d.ts.map +1 -0
  216. package/dist/ai-service/state-machine/handlers/play-dead.js +11 -0
  217. package/dist/ai-service/state-machine/handlers/play-dead.js.map +1 -0
  218. package/dist/ai-service/state-machine/handlers/post-processing.d.ts +3 -0
  219. package/dist/ai-service/state-machine/handlers/post-processing.d.ts.map +1 -0
  220. package/dist/ai-service/state-machine/handlers/post-processing.js +50 -0
  221. package/dist/ai-service/state-machine/handlers/post-processing.js.map +1 -0
  222. package/dist/ai-service/state-machine/handlers/runtime-reviewing.d.ts +3 -0
  223. package/dist/ai-service/state-machine/handlers/runtime-reviewing.d.ts.map +1 -0
  224. package/dist/ai-service/state-machine/handlers/runtime-reviewing.js +37 -0
  225. package/dist/ai-service/state-machine/handlers/runtime-reviewing.js.map +1 -0
  226. package/dist/ai-service/state-machine/helpers/metadata.d.ts +6 -0
  227. package/dist/ai-service/state-machine/helpers/metadata.d.ts.map +1 -0
  228. package/dist/ai-service/state-machine/helpers/metadata.js +11 -0
  229. package/dist/ai-service/state-machine/helpers/metadata.js.map +1 -0
  230. package/dist/ai-service/state-machine/helpers/peer.d.ts +5 -0
  231. package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -0
  232. package/dist/ai-service/state-machine/helpers/peer.js +7 -0
  233. package/dist/ai-service/state-machine/helpers/peer.js.map +1 -0
  234. package/dist/ai-service/state-machine/helpers/transition.d.ts +13 -0
  235. package/dist/ai-service/state-machine/helpers/transition.d.ts.map +1 -0
  236. package/dist/ai-service/state-machine/helpers/transition.js +6 -0
  237. package/dist/ai-service/state-machine/helpers/transition.js.map +1 -0
  238. package/dist/ai-service/state-machine/mocks.d.ts +7 -0
  239. package/dist/ai-service/state-machine/mocks.d.ts.map +1 -0
  240. package/dist/ai-service/state-machine/mocks.js +63 -0
  241. package/dist/ai-service/state-machine/mocks.js.map +1 -0
  242. package/dist/ai-service/state-machine/test-util.d.ts +5 -0
  243. package/dist/ai-service/state-machine/test-util.d.ts.map +1 -0
  244. package/dist/ai-service/state-machine/test-util.js +29 -0
  245. package/dist/ai-service/state-machine/test-util.js.map +1 -0
  246. package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.d.ts +21 -0
  247. package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.d.ts.map +1 -0
  248. package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.js +47 -0
  249. package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.js.map +1 -0
  250. package/dist/ai-service/transform/api-builder/shared.d.ts +11 -0
  251. package/dist/ai-service/transform/api-builder/shared.d.ts.map +1 -0
  252. package/dist/ai-service/transform/api-builder/shared.js +53 -0
  253. package/dist/ai-service/transform/api-builder/shared.js.map +1 -0
  254. package/dist/ai-service/transform/api-builder/to-sdk-transformer.d.ts +27 -0
  255. package/dist/ai-service/transform/api-builder/to-sdk-transformer.d.ts.map +1 -0
  256. package/dist/ai-service/transform/api-builder/to-sdk-transformer.js +66 -0
  257. package/dist/ai-service/transform/api-builder/to-sdk-transformer.js.map +1 -0
  258. package/dist/ai-service/transform/api-builder/to-yaml-transformer.d.ts +23 -0
  259. package/dist/ai-service/transform/api-builder/to-yaml-transformer.d.ts.map +1 -0
  260. package/dist/ai-service/transform/api-builder/to-yaml-transformer.js +59 -0
  261. package/dist/ai-service/transform/api-builder/to-yaml-transformer.js.map +1 -0
  262. package/dist/ai-service/transform/remove-api-builder-imports/transformer.d.ts +19 -0
  263. package/dist/ai-service/transform/remove-api-builder-imports/transformer.d.ts.map +1 -0
  264. package/dist/ai-service/transform/remove-api-builder-imports/transformer.js +45 -0
  265. package/dist/ai-service/transform/remove-api-builder-imports/transformer.js.map +1 -0
  266. package/dist/ai-service/transform/shared.d.ts +20 -0
  267. package/dist/ai-service/transform/shared.d.ts.map +1 -0
  268. package/dist/ai-service/transform/shared.js +132 -0
  269. package/dist/ai-service/transform/shared.js.map +1 -0
  270. package/dist/ai-service/transform/workaround-missing-sbapi/transformer.d.ts +17 -0
  271. package/dist/ai-service/transform/workaround-missing-sbapi/transformer.d.ts.map +1 -0
  272. package/dist/ai-service/transform/workaround-missing-sbapi/transformer.js +33 -0
  273. package/dist/ai-service/transform/workaround-missing-sbapi/transformer.js.map +1 -0
  274. package/dist/ai-service/types.d.ts +65 -0
  275. package/dist/ai-service/types.d.ts.map +1 -0
  276. package/dist/ai-service/types.js +2 -0
  277. package/dist/ai-service/types.js.map +1 -0
  278. package/dist/binding-extraction/extract-control-block-identifiers.d.ts +4 -0
  279. package/dist/binding-extraction/extract-control-block-identifiers.d.ts.map +1 -0
  280. package/dist/binding-extraction/extract-control-block-identifiers.js +86 -0
  281. package/dist/binding-extraction/extract-control-block-identifiers.js.map +1 -0
  282. package/dist/binding-extraction/extract-embedded-identifiers.d.ts +16 -0
  283. package/dist/binding-extraction/extract-embedded-identifiers.d.ts.map +1 -0
  284. package/dist/binding-extraction/extract-embedded-identifiers.js +100 -0
  285. package/dist/binding-extraction/extract-embedded-identifiers.js.map +1 -0
  286. package/dist/binding-extraction/extract-identifiers.d.ts +8 -0
  287. package/dist/binding-extraction/extract-identifiers.d.ts.map +1 -0
  288. package/dist/binding-extraction/extract-identifiers.js +150 -0
  289. package/dist/binding-extraction/extract-identifiers.js.map +1 -0
  290. package/dist/binding-extraction/extract-js-identifiers.d.ts +19 -0
  291. package/dist/binding-extraction/extract-js-identifiers.d.ts.map +1 -0
  292. package/dist/binding-extraction/extract-js-identifiers.js +161 -0
  293. package/dist/binding-extraction/extract-js-identifiers.js.map +1 -0
  294. package/dist/binding-extraction/extract-py-identifiers.d.ts +4 -0
  295. package/dist/binding-extraction/extract-py-identifiers.d.ts.map +1 -0
  296. package/dist/binding-extraction/extract-py-identifiers.js +161 -0
  297. package/dist/binding-extraction/extract-py-identifiers.js.map +1 -0
  298. package/dist/binding-extraction/shared.d.ts +225 -0
  299. package/dist/binding-extraction/shared.d.ts.map +1 -0
  300. package/dist/binding-extraction/shared.js +43 -0
  301. package/dist/binding-extraction/shared.js.map +1 -0
  302. package/dist/binding-extraction/template-strings.d.ts +9 -0
  303. package/dist/binding-extraction/template-strings.d.ts.map +1 -0
  304. package/dist/binding-extraction/template-strings.js +45 -0
  305. package/dist/binding-extraction/template-strings.js.map +1 -0
  306. package/dist/codegen.d.ts +26 -0
  307. package/dist/codegen.d.ts.map +1 -0
  308. package/dist/codegen.js +222 -0
  309. package/dist/codegen.js.map +1 -0
  310. package/dist/components-manager.d.ts +38 -0
  311. package/dist/components-manager.d.ts.map +1 -0
  312. package/dist/components-manager.js +177 -0
  313. package/dist/components-manager.js.map +1 -0
  314. package/dist/custom-components.d.ts +6 -0
  315. package/dist/custom-components.d.ts.map +1 -0
  316. package/dist/custom-components.js +51 -0
  317. package/dist/custom-components.js.map +1 -0
  318. package/dist/draft-interface.d.ts +11 -0
  319. package/dist/draft-interface.d.ts.map +1 -0
  320. package/dist/draft-interface.js +2 -0
  321. package/dist/draft-interface.js.map +1 -0
  322. package/dist/errors/error-handler.d.ts +35 -0
  323. package/dist/errors/error-handler.d.ts.map +1 -0
  324. package/dist/errors/error-handler.js +65 -0
  325. package/dist/errors/error-handler.js.map +1 -0
  326. package/dist/errors/make-server-error.d.ts +5 -0
  327. package/dist/errors/make-server-error.d.ts.map +1 -0
  328. package/dist/errors/make-server-error.js +21 -0
  329. package/dist/errors/make-server-error.js.map +1 -0
  330. package/dist/file-sync-vite-plugin.d.ts +4 -0
  331. package/dist/file-sync-vite-plugin.d.ts.map +1 -0
  332. package/dist/file-sync-vite-plugin.js +624 -0
  333. package/dist/file-sync-vite-plugin.js.map +1 -0
  334. package/dist/file-system-helpers.d.ts +7 -0
  335. package/dist/file-system-helpers.d.ts.map +1 -0
  336. package/dist/file-system-helpers.js +12 -0
  337. package/dist/file-system-helpers.js.map +1 -0
  338. package/dist/file-system-manager.d.ts +132 -0
  339. package/dist/file-system-manager.d.ts.map +1 -0
  340. package/dist/file-system-manager.js +1176 -0
  341. package/dist/file-system-manager.js.map +1 -0
  342. package/dist/generate.d.ts +8 -0
  343. package/dist/generate.d.ts.map +1 -0
  344. package/dist/generate.js +7 -0
  345. package/dist/generate.js.map +1 -0
  346. package/dist/ids.d.ts +2 -0
  347. package/dist/ids.d.ts.map +1 -0
  348. package/dist/ids.js +21 -0
  349. package/dist/ids.js.map +1 -0
  350. package/dist/index.d.ts +6 -0
  351. package/dist/index.d.ts.map +1 -0
  352. package/dist/index.js +6 -0
  353. package/dist/index.js.map +1 -0
  354. package/dist/injected-index.d.ts +12 -0
  355. package/dist/injected-index.d.ts.map +1 -0
  356. package/dist/injected-index.js +38 -0
  357. package/dist/injected-index.js.map +1 -0
  358. package/dist/lock-service/index.d.ts +93 -0
  359. package/dist/lock-service/index.d.ts.map +1 -0
  360. package/dist/lock-service/index.js +267 -0
  361. package/dist/lock-service/index.js.map +1 -0
  362. package/dist/parsing/bindings.d.ts +4 -0
  363. package/dist/parsing/bindings.d.ts.map +1 -0
  364. package/dist/parsing/bindings.js +17 -0
  365. package/dist/parsing/bindings.js.map +1 -0
  366. package/dist/parsing/computed/to-code-computed.d.ts +2 -0
  367. package/dist/parsing/computed/to-code-computed.d.ts.map +1 -0
  368. package/dist/parsing/computed/to-code-computed.js +39 -0
  369. package/dist/parsing/computed/to-code-computed.js.map +1 -0
  370. package/dist/parsing/computed/to-value-computed.d.ts +4 -0
  371. package/dist/parsing/computed/to-value-computed.d.ts.map +1 -0
  372. package/dist/parsing/computed/to-value-computed.js +13 -0
  373. package/dist/parsing/computed/to-value-computed.js.map +1 -0
  374. package/dist/parsing/dim/to-code-dimensions.d.ts +3 -0
  375. package/dist/parsing/dim/to-code-dimensions.d.ts.map +1 -0
  376. package/dist/parsing/dim/to-code-dimensions.js +22 -0
  377. package/dist/parsing/dim/to-code-dimensions.js.map +1 -0
  378. package/dist/parsing/dim/to-value-dimensions.d.ts +4 -0
  379. package/dist/parsing/dim/to-value-dimensions.d.ts.map +1 -0
  380. package/dist/parsing/dim/to-value-dimensions.js +39 -0
  381. package/dist/parsing/dim/to-value-dimensions.js.map +1 -0
  382. package/dist/parsing/entity/index.d.ts +8 -0
  383. package/dist/parsing/entity/index.d.ts.map +1 -0
  384. package/dist/parsing/entity/index.js +8 -0
  385. package/dist/parsing/entity/index.js.map +1 -0
  386. package/dist/parsing/entity/to-code-entity.d.ts +3 -0
  387. package/dist/parsing/entity/to-code-entity.d.ts.map +1 -0
  388. package/dist/parsing/entity/to-code-entity.js +41 -0
  389. package/dist/parsing/entity/to-code-entity.js.map +1 -0
  390. package/dist/parsing/entity/to-value-entity.d.ts +8 -0
  391. package/dist/parsing/entity/to-value-entity.d.ts.map +1 -0
  392. package/dist/parsing/entity/to-value-entity.js +120 -0
  393. package/dist/parsing/entity/to-value-entity.js.map +1 -0
  394. package/dist/parsing/events/to-code-events.d.ts +3 -0
  395. package/dist/parsing/events/to-code-events.d.ts.map +1 -0
  396. package/dist/parsing/events/to-code-events.js +86 -0
  397. package/dist/parsing/events/to-code-events.js.map +1 -0
  398. package/dist/parsing/events/to-value-events.d.ts +5 -0
  399. package/dist/parsing/events/to-value-events.d.ts.map +1 -0
  400. package/dist/parsing/events/to-value-events.js +157 -0
  401. package/dist/parsing/events/to-value-events.js.map +1 -0
  402. package/dist/parsing/ids.d.ts +17 -0
  403. package/dist/parsing/ids.d.ts.map +1 -0
  404. package/dist/parsing/ids.js +121 -0
  405. package/dist/parsing/ids.js.map +1 -0
  406. package/dist/parsing/imports.d.ts +6 -0
  407. package/dist/parsing/imports.d.ts.map +1 -0
  408. package/dist/parsing/imports.js +27 -0
  409. package/dist/parsing/imports.js.map +1 -0
  410. package/dist/parsing/jsx-utils.d.ts +9 -0
  411. package/dist/parsing/jsx-utils.d.ts.map +1 -0
  412. package/dist/parsing/jsx-utils.js +42 -0
  413. package/dist/parsing/jsx-utils.js.map +1 -0
  414. package/dist/parsing/jsx.d.ts +23 -0
  415. package/dist/parsing/jsx.d.ts.map +1 -0
  416. package/dist/parsing/jsx.js +329 -0
  417. package/dist/parsing/jsx.js.map +1 -0
  418. package/dist/parsing/page.d.ts +9 -0
  419. package/dist/parsing/page.d.ts.map +1 -0
  420. package/dist/parsing/page.js +156 -0
  421. package/dist/parsing/page.js.map +1 -0
  422. package/dist/parsing/properties.d.ts +5 -0
  423. package/dist/parsing/properties.d.ts.map +1 -0
  424. package/dist/parsing/properties.js +89 -0
  425. package/dist/parsing/properties.js.map +1 -0
  426. package/dist/parsing/scope.d.ts +81 -0
  427. package/dist/parsing/scope.d.ts.map +1 -0
  428. package/dist/parsing/scope.js +575 -0
  429. package/dist/parsing/scope.js.map +1 -0
  430. package/dist/parsing/template/to-code-template.d.ts +2 -0
  431. package/dist/parsing/template/to-code-template.d.ts.map +1 -0
  432. package/dist/parsing/template/to-code-template.js +5 -0
  433. package/dist/parsing/template/to-code-template.js.map +1 -0
  434. package/dist/parsing/template/to-value-template.d.ts +4 -0
  435. package/dist/parsing/template/to-value-template.d.ts.map +1 -0
  436. package/dist/parsing/template/to-value-template.js +19 -0
  437. package/dist/parsing/template/to-value-template.js.map +1 -0
  438. package/dist/parsing/theme.d.ts +3 -0
  439. package/dist/parsing/theme.d.ts.map +1 -0
  440. package/dist/parsing/theme.js +87 -0
  441. package/dist/parsing/theme.js.map +1 -0
  442. package/dist/parsing/type-parsing-registry.d.ts +18 -0
  443. package/dist/parsing/type-parsing-registry.d.ts.map +1 -0
  444. package/dist/parsing/type-parsing-registry.js +31 -0
  445. package/dist/parsing/type-parsing-registry.js.map +1 -0
  446. package/dist/parsing/util.d.ts +31 -0
  447. package/dist/parsing/util.d.ts.map +1 -0
  448. package/dist/parsing/util.js +322 -0
  449. package/dist/parsing/util.js.map +1 -0
  450. package/dist/plugin-options.d.ts +25 -0
  451. package/dist/plugin-options.d.ts.map +1 -0
  452. package/dist/plugin-options.js +14 -0
  453. package/dist/plugin-options.js.map +1 -0
  454. package/dist/refactor/blocks.d.ts +10 -0
  455. package/dist/refactor/blocks.d.ts.map +1 -0
  456. package/dist/refactor/blocks.js +214 -0
  457. package/dist/refactor/blocks.js.map +1 -0
  458. package/dist/refactor/javascript.d.ts +15 -0
  459. package/dist/refactor/javascript.d.ts.map +1 -0
  460. package/dist/refactor/javascript.js +182 -0
  461. package/dist/refactor/javascript.js.map +1 -0
  462. package/dist/refactor-jsx.d.ts +28 -0
  463. package/dist/refactor-jsx.d.ts.map +1 -0
  464. package/dist/refactor-jsx.js +77 -0
  465. package/dist/refactor-jsx.js.map +1 -0
  466. package/dist/rename-manager.d.ts +27 -0
  467. package/dist/rename-manager.d.ts.map +1 -0
  468. package/dist/rename-manager.js +140 -0
  469. package/dist/rename-manager.js.map +1 -0
  470. package/dist/routing.d.ts +6 -0
  471. package/dist/routing.d.ts.map +1 -0
  472. package/dist/routing.js +76 -0
  473. package/dist/routing.js.map +1 -0
  474. package/dist/sb-scope-manager.d.ts +102 -0
  475. package/dist/sb-scope-manager.d.ts.map +1 -0
  476. package/dist/sb-scope-manager.js +501 -0
  477. package/dist/sb-scope-manager.js.map +1 -0
  478. package/dist/socket-manager.d.ts +40 -0
  479. package/dist/socket-manager.d.ts.map +1 -0
  480. package/dist/socket-manager.js +174 -0
  481. package/dist/socket-manager.js.map +1 -0
  482. package/dist/source-tracker.d.ts +190 -0
  483. package/dist/source-tracker.d.ts.map +1 -0
  484. package/dist/source-tracker.js +967 -0
  485. package/dist/source-tracker.js.map +1 -0
  486. package/dist/sync-service/download.d.ts +15 -0
  487. package/dist/sync-service/download.d.ts.map +1 -0
  488. package/dist/sync-service/download.js +116 -0
  489. package/dist/sync-service/download.js.map +1 -0
  490. package/dist/sync-service/draft-helpers.d.ts +68 -0
  491. package/dist/sync-service/draft-helpers.d.ts.map +1 -0
  492. package/dist/sync-service/draft-helpers.js +362 -0
  493. package/dist/sync-service/draft-helpers.js.map +1 -0
  494. package/dist/sync-service/hash-cache.d.ts +15 -0
  495. package/dist/sync-service/hash-cache.d.ts.map +1 -0
  496. package/dist/sync-service/hash-cache.js +58 -0
  497. package/dist/sync-service/hash-cache.js.map +1 -0
  498. package/dist/sync-service/hash-dir-tree.d.ts +10 -0
  499. package/dist/sync-service/hash-dir-tree.d.ts.map +1 -0
  500. package/dist/sync-service/hash-dir-tree.js +53 -0
  501. package/dist/sync-service/hash-dir-tree.js.map +1 -0
  502. package/dist/sync-service/index.d.ts +134 -0
  503. package/dist/sync-service/index.d.ts.map +1 -0
  504. package/dist/sync-service/index.js +323 -0
  505. package/dist/sync-service/index.js.map +1 -0
  506. package/dist/sync-service/list-dir.d.ts +29 -0
  507. package/dist/sync-service/list-dir.d.ts.map +1 -0
  508. package/dist/sync-service/list-dir.js +66 -0
  509. package/dist/sync-service/list-dir.js.map +1 -0
  510. package/dist/sync-service/server-rpc/client.d.ts +13 -0
  511. package/dist/sync-service/server-rpc/client.d.ts.map +1 -0
  512. package/dist/sync-service/server-rpc/client.js +62 -0
  513. package/dist/sync-service/server-rpc/client.js.map +1 -0
  514. package/dist/sync-service/server-rpc/handlers.d.ts +3 -0
  515. package/dist/sync-service/server-rpc/handlers.d.ts.map +1 -0
  516. package/dist/sync-service/server-rpc/handlers.js +18 -0
  517. package/dist/sync-service/server-rpc/handlers.js.map +1 -0
  518. package/dist/sync-service/snapshot/take-snapshot.d.ts +38 -0
  519. package/dist/sync-service/snapshot/take-snapshot.d.ts.map +1 -0
  520. package/dist/sync-service/snapshot/take-snapshot.js +232 -0
  521. package/dist/sync-service/snapshot/take-snapshot.js.map +1 -0
  522. package/dist/sync-service/snapshot/types.d.ts +24 -0
  523. package/dist/sync-service/snapshot/types.d.ts.map +1 -0
  524. package/dist/sync-service/snapshot/types.js +3 -0
  525. package/dist/sync-service/snapshot/types.js.map +1 -0
  526. package/dist/sync-service/snapshot/upload-snapshot.d.ts +5 -0
  527. package/dist/sync-service/snapshot/upload-snapshot.d.ts.map +1 -0
  528. package/dist/sync-service/snapshot/upload-snapshot.js +63 -0
  529. package/dist/sync-service/snapshot/upload-snapshot.js.map +1 -0
  530. package/dist/traverse.d.ts +6 -0
  531. package/dist/traverse.d.ts.map +1 -0
  532. package/dist/traverse.js +7 -0
  533. package/dist/traverse.js.map +1 -0
  534. package/dist/util/generation-number-sequence.d.ts +7 -0
  535. package/dist/util/generation-number-sequence.d.ts.map +1 -0
  536. package/dist/util/generation-number-sequence.js +13 -0
  537. package/dist/util/generation-number-sequence.js.map +1 -0
  538. package/dist/util/logger.d.ts +22 -0
  539. package/dist/util/logger.d.ts.map +1 -0
  540. package/dist/util/logger.js +64 -0
  541. package/dist/util/logger.js.map +1 -0
  542. package/dist/util/operation-queue.d.ts +17 -0
  543. package/dist/util/operation-queue.d.ts.map +1 -0
  544. package/dist/util/operation-queue.js +27 -0
  545. package/dist/util/operation-queue.js.map +1 -0
  546. package/dist/util/tracing.d.ts +4 -0
  547. package/dist/util/tracing.d.ts.map +1 -0
  548. package/dist/util/tracing.js +19 -0
  549. package/dist/util/tracing.js.map +1 -0
  550. package/dist/util/with-resolvers.d.ts +10 -0
  551. package/dist/util/with-resolvers.d.ts.map +1 -0
  552. package/dist/util/with-resolvers.js +14 -0
  553. package/dist/util/with-resolvers.js.map +1 -0
  554. package/dist/util.d.ts +26 -0
  555. package/dist/util.d.ts.map +1 -0
  556. package/dist/util.js +82 -0
  557. package/dist/util.js.map +1 -0
  558. package/package.json +126 -0
@@ -0,0 +1,967 @@
1
+ import path from "node:path";
2
+ import { parse } from "@babel/parser";
3
+ import t from "@babel/types";
4
+ import { isPropertyInfo, Property, splitJSPath, splitJSPathAdvanced, } from "@superblocksteam/library-shared";
5
+ import { SbEntityType, } from "@superblocksteam/library-shared/types";
6
+ import { format } from "prettier";
7
+ import { generateJSXAttribute, generateJSXElement, writeNestedProperty, } from "./codegen.js";
8
+ import { ComponentsManager } from "./components-manager.js";
9
+ import { SCOPE_FILE } from "./file-system-helpers.js";
10
+ import { generate } from "./generate.js";
11
+ import { generatePredictableId } from "./ids.js";
12
+ import { generateElementId, getSbElementId, supplementElementIds, } from "./parsing/ids.js";
13
+ import { REQUIRED_IMPORTS_BY_PROPERTY_TYPE } from "./parsing/imports.js";
14
+ import { getDescriptiveName, getJSXAttributeName, getJSXAttributeType, getVariableReferences, isNamedComponent, } from "./parsing/jsx.js";
15
+ import { updateThemeAst } from "./parsing/theme.js";
16
+ import { getTagName, addImport, extractImportsFromAst, getImportPath, } from "./parsing/util.js";
17
+ import { RenameManager } from "./rename-manager.js";
18
+ import { SbScopeManager } from "./sb-scope-manager.js";
19
+ import { getErrorMeta, getLogger } from "./util/logger.js";
20
+ const GLOBAL_FUNCTION_NAMES = new Set([
21
+ "copyToClipboard",
22
+ "navigateTo",
23
+ "setQueryParams",
24
+ "download",
25
+ "showAlert",
26
+ "logoutIntegrations",
27
+ ]);
28
+ const ATTRIBUTE_TYPES_WITH_STATE_ACCESS = ["COMPUTED", "TEMPLATE"];
29
+ // File Explanation:
30
+ // This file is responsible for tracking the source code of the application.
31
+ // It parses the source code of the application and stores the ASTs of the files.
32
+ // It also tracks the location of JSX elements in the source code.
33
+ // This information is used by the source code editor to provide features like drag and drop and property editing.
34
+ export class SourceTracker {
35
+ renameManager = new RenameManager();
36
+ sbScopeManager;
37
+ elementToLocation = {};
38
+ elementToFilePath = {};
39
+ scopeIdToFilePath = {};
40
+ sbScopeNamesToFilePath = {};
41
+ newlyAddedCount = 0;
42
+ fileToMeta = {};
43
+ changedFiles = new Set();
44
+ constructor() {
45
+ this.sbScopeManager = new SbScopeManager(this);
46
+ }
47
+ getCurrentFiles() {
48
+ return this.fileToMeta;
49
+ }
50
+ /**
51
+ * Retrieves and clears the changes made to files, returning them as a record of file
52
+ * names and their corresponding code.
53
+ * @returns A Record<string, string> object containing the file names as keys and their corresponding code as values.
54
+ */
55
+ getAndFlushChanges = async () => {
56
+ const files = Array.from(this.changedFiles);
57
+ this.changedFiles.clear();
58
+ return await Promise.all(files.map(async (file) => {
59
+ const meta = this.fileToMeta[file];
60
+ if (!meta)
61
+ throw new Error("No meta found for file " + file);
62
+ const code = generate(meta.ast).code;
63
+ const formattedCode = await format(code, {
64
+ parser: "typescript",
65
+ });
66
+ return { fileName: file, source: formattedCode, kind: "ts" };
67
+ }));
68
+ };
69
+ getElementToFilePath(el) {
70
+ if (el === undefined)
71
+ return this.elementToFilePath;
72
+ return this.elementToFilePath[el];
73
+ }
74
+ getElementToLocation(el) {
75
+ if (el === undefined)
76
+ return this.elementToLocation;
77
+ return this.elementToLocation[el];
78
+ }
79
+ setElementToLocation(el, path) {
80
+ this.elementToLocation[el] = path;
81
+ }
82
+ setElementToFilePath(el, filePath) {
83
+ this.elementToFilePath[el] = filePath;
84
+ }
85
+ deleteElementToLocation(el) {
86
+ delete this.elementToLocation[el];
87
+ }
88
+ deleteElementToFilePath(el) {
89
+ delete this.elementToFilePath[el];
90
+ }
91
+ getScopeDefinitionForPage(pageName) {
92
+ const { scopeDefinition } = this.sbScopeManager.getScopeDefinitionAndFilePathByNameOrId({
93
+ identifier: pageName,
94
+ type: "name",
95
+ });
96
+ return scopeDefinition;
97
+ }
98
+ parseJsxFromEntrypoint({ files, }) {
99
+ const parsedAsts = {};
100
+ for (const { fileName, code } of files) {
101
+ const isTsx = fileName.endsWith(".tsx");
102
+ const isTs = fileName.endsWith(".ts");
103
+ if (isTsx || isTs) {
104
+ try {
105
+ parsedAsts[fileName] = parse(code, {
106
+ sourceType: "module",
107
+ sourceFilename: fileName,
108
+ plugins: [["typescript", {}], "jsx"],
109
+ });
110
+ }
111
+ catch (e) {
112
+ getLogger().error(`Error parsing entry point: ${path.relative(process.cwd(), fileName)}`, getErrorMeta(e));
113
+ }
114
+ }
115
+ }
116
+ return parsedAsts;
117
+ }
118
+ initializeSourceTracker = ({ files }) => {
119
+ const fileContents = Object.entries(files).map(([fileName, code]) => ({
120
+ fileName,
121
+ code,
122
+ }));
123
+ const parsedAsts = this.parseJsxFromEntrypoint({
124
+ // entryPointFilePath: rootDir + "/pages/page1/_index.tsx",
125
+ files: fileContents,
126
+ });
127
+ this.fileToMeta = Object.fromEntries(Object.entries(parsedAsts).map(([file, ast]) => [
128
+ file,
129
+ {
130
+ code: fileContents.find((f) => f.fileName === file).code,
131
+ ast,
132
+ imports: extractImportsFromAst(ast),
133
+ },
134
+ ]));
135
+ this.sbScopeManager.parseScopes(this.fileToMeta);
136
+ Object.entries(parsedAsts).forEach(([file, ast]) => {
137
+ // scope files are handled by the sbScopeManager
138
+ if (!file.endsWith(SCOPE_FILE)) {
139
+ const { idMap } = supplementElementIds({
140
+ fileName: file,
141
+ ast,
142
+ shouldModifyAst: false,
143
+ });
144
+ idMap.forEach((path, id) => {
145
+ this.elementToLocation[id] = path;
146
+ this.elementToFilePath[id] = file;
147
+ });
148
+ }
149
+ });
150
+ };
151
+ handleNonVisualChangeByDeletingIds = async (fileName, fileContents) => {
152
+ const extension = path.extname(fileName);
153
+ if (extension !== ".ts" && extension !== ".tsx")
154
+ return;
155
+ try {
156
+ const astMap = this.parseJsxFromEntrypoint({
157
+ files: [{ fileName, code: fileContents }],
158
+ });
159
+ const ast = astMap[fileName];
160
+ if (!ast) {
161
+ throw new Error("Failed to parse file " + fileName);
162
+ }
163
+ this.fileToMeta[fileName] = {
164
+ ast: ast,
165
+ code: fileContents,
166
+ imports: extractImportsFromAst(ast),
167
+ };
168
+ // delete all existing elements from the ast cache
169
+ Object.entries(this.elementToLocation)
170
+ .filter(([id]) => {
171
+ const filePath = this.getElementToFilePath(id);
172
+ if (!filePath)
173
+ return false;
174
+ return filePath.startsWith(fileName);
175
+ })
176
+ .forEach(([key]) => {
177
+ delete this.elementToLocation[key];
178
+ delete this.elementToFilePath[key];
179
+ });
180
+ const changedFiles = this.sbScopeManager.resetScope(fileName);
181
+ // scope file is handled by the sbScopeManager
182
+ if (!fileName.endsWith(SCOPE_FILE)) {
183
+ const { idMap } = supplementElementIds({
184
+ fileName,
185
+ ast,
186
+ shouldModifyAst: false,
187
+ });
188
+ idMap.forEach((path, id) => {
189
+ this.elementToLocation[id] = path;
190
+ this.elementToFilePath[id] = fileName;
191
+ });
192
+ }
193
+ changedFiles.forEach((file) => {
194
+ if (file !== fileName) {
195
+ this.changedFiles.add(file);
196
+ }
197
+ });
198
+ // Mark the file as changed
199
+ this.changedFiles.add(fileName);
200
+ }
201
+ catch (e) {
202
+ getLogger().error("Non-visual change parsing error", getErrorMeta(e));
203
+ return;
204
+ }
205
+ };
206
+ removeFile = async (fileName) => {
207
+ delete this.fileToMeta[fileName];
208
+ // Clean up element mappings
209
+ Object.entries(this.elementToFilePath).forEach(([id, path]) => {
210
+ if (path === fileName) {
211
+ delete this.elementToLocation[id];
212
+ delete this.elementToFilePath[id];
213
+ }
214
+ });
215
+ // Clean up sb scope mappings
216
+ Object.entries(this.sbScopeNamesToFilePath).forEach(([scopeName, info]) => {
217
+ if (info.filePath === fileName) {
218
+ delete this.sbScopeNamesToFilePath[scopeName];
219
+ }
220
+ });
221
+ // Clean up scope ID mappings
222
+ Object.entries(this.scopeIdToFilePath).forEach(([scopeId, path]) => {
223
+ if (path === fileName) {
224
+ delete this.scopeIdToFilePath[scopeId];
225
+ }
226
+ });
227
+ };
228
+ moveElement = async ({ from, to, }) => {
229
+ let fromAstPath = this.getElementToLocation(from.source.id);
230
+ // if not jsxElement, then its a self closing element? (not sure if always) so get parent element
231
+ if (!fromAstPath.isJSXElement()) {
232
+ if (fromAstPath.parentPath == null ||
233
+ !fromAstPath.parentPath.isJSXElement()) {
234
+ throw new Error("UNEXPECTED D&D ELEMENT " + fromAstPath.toString());
235
+ }
236
+ fromAstPath = fromAstPath.parentPath;
237
+ }
238
+ let toAstPath = this.getElementToLocation(to.source.id);
239
+ // if not jsxElement, then its a self closing element? (not sure if always) so get parent element
240
+ if (!toAstPath.isJSXElement()) {
241
+ if (toAstPath.parentPath == null ||
242
+ !toAstPath.parentPath.isJSXElement()) {
243
+ throw new Error("UNEXPECTED D&D ELEMENT " + toAstPath.toString());
244
+ }
245
+ toAstPath = toAstPath.parentPath;
246
+ }
247
+ if (fromAstPath.node == null ||
248
+ fromAstPath.node == null ||
249
+ toAstPath.node == null ||
250
+ toAstPath.node == null) {
251
+ throw new Error("From/to AST nodes are missing");
252
+ }
253
+ const fromFilepath = this.getElementToFilePath(from.source.id);
254
+ if (!fromFilepath) {
255
+ getLogger().error(`Filepath not found for element ${from.source.id} ${fromAstPath}`);
256
+ throw new Error("Filepath not found for element " + from.source.id);
257
+ }
258
+ const toFilePath = this.getElementToFilePath(to.source.id);
259
+ if (!toFilePath) {
260
+ throw new Error("Filepath not found for element " + to.source.id);
261
+ }
262
+ const fromFileAst = this.fileToMeta[fromFilepath]?.ast;
263
+ if (!fromFileAst) {
264
+ throw new Error("File not found in source tracker " + fromFilepath);
265
+ }
266
+ try {
267
+ const toElement = toAstPath;
268
+ const fromNode = fromAstPath.node;
269
+ const { index = -1 } = to.source;
270
+ this.transformSelfClosingTagToRegularTag(toElement);
271
+ // Get the JSXElement children of the toElement
272
+ const elementChildren = toElement
273
+ .get("children")
274
+ .filter((child) => child.isJSXElement());
275
+ if (elementChildren[index] === fromAstPath) {
276
+ return;
277
+ }
278
+ // First remove the original node
279
+ // We need to do this first incase the parent element is the same
280
+ fromAstPath.remove();
281
+ let newAstPath = null;
282
+ if (index === 0) {
283
+ const [insertedPath] = toElement.unshiftContainer("children", fromNode);
284
+ newAstPath = insertedPath;
285
+ }
286
+ else if (index < 0 || index >= elementChildren.length) {
287
+ const [insertedPath] = toElement.pushContainer("children", fromNode);
288
+ newAstPath = insertedPath;
289
+ }
290
+ else {
291
+ const child = elementChildren[index];
292
+ if (!child)
293
+ throw new Error("Child not found");
294
+ const [insertedPath] = child.insertBefore(fromNode);
295
+ newAstPath = insertedPath;
296
+ }
297
+ // We store JSXOpeningElement paths in the elementToLocation map
298
+ const newOpeningElement = newAstPath.get("openingElement");
299
+ if (Array.isArray(newOpeningElement)) {
300
+ throw new Error("Expected single opening element path");
301
+ }
302
+ this.elementToLocation[from.source.id] = newOpeningElement;
303
+ this.changedFiles.add(fromFilepath);
304
+ }
305
+ catch (e) {
306
+ getLogger().error("Error updating source tracker during move", getErrorMeta(e));
307
+ throw new Error("Error updating source tracker during move" + e.message);
308
+ }
309
+ };
310
+ addApi = async ({ pageName, apiName, }) => {
311
+ const { scopeDefinition, filePath: scopeFilePath } = this.sbScopeManager.getScopeDefinitionAndFilePathByNameOrId({
312
+ identifier: pageName,
313
+ type: "name",
314
+ });
315
+ if (!scopeDefinition || !scopeFilePath) {
316
+ throw new Error("Scope not found for page " + pageName);
317
+ }
318
+ const changedFiles = this.sbScopeManager.addScopeEntity(scopeDefinition.id, {
319
+ type: SbEntityType.API,
320
+ name: apiName,
321
+ attributes: {},
322
+ });
323
+ changedFiles.forEach((file) => {
324
+ this.changedFiles.add(file);
325
+ });
326
+ return scopeDefinition.id;
327
+ };
328
+ deleteApi = async ({ pageName, apiName, }) => {
329
+ const { scopeDefinition, filePath: scopeFilePath } = this.sbScopeManager.getScopeDefinitionAndFilePathByNameOrId({
330
+ identifier: pageName,
331
+ type: "name",
332
+ });
333
+ if (!scopeDefinition || !scopeFilePath) {
334
+ throw new Error("Scope not found for page " + pageName);
335
+ }
336
+ const entityId = scopeDefinition.scopeNameToEntityId[apiName];
337
+ if (!entityId) {
338
+ throw new Error("Entity ID not found for API " + apiName);
339
+ }
340
+ const { changedFiles } = this.sbScopeManager.deleteScopeEntity(entityId);
341
+ changedFiles.forEach((file) => {
342
+ this.changedFiles.add(file);
343
+ });
344
+ return scopeDefinition.id;
345
+ };
346
+ addEntity = async ({ scopeId, entity, }) => {
347
+ const changedFiles = this.sbScopeManager.addScopeEntity(scopeId, entity);
348
+ changedFiles.forEach((file) => {
349
+ this.changedFiles.add(file);
350
+ });
351
+ };
352
+ updateEntity = async (payload) => {
353
+ const changedFile = this.sbScopeManager.updateScopeEntity(payload);
354
+ this.changedFiles.add(changedFile);
355
+ };
356
+ deleteEntity = async ({ entityId }) => {
357
+ const { changedFiles, deletedEntitiesNames } = this.sbScopeManager.deleteScopeEntity(entityId);
358
+ changedFiles.forEach((file) => {
359
+ this.changedFiles.add(file);
360
+ });
361
+ return deletedEntitiesNames[0];
362
+ };
363
+ renameEntity = async ({ entityId, oldName, newName, scopeName, }) => {
364
+ const { changedFiles, scopeFile } = this.sbScopeManager.renameScopeEntity({
365
+ entityId,
366
+ newName,
367
+ oldName,
368
+ });
369
+ if (changedFiles.length === 0) {
370
+ console.warn("No changed files found for entity", entityId);
371
+ return;
372
+ }
373
+ changedFiles.forEach((file) => {
374
+ this.changedFiles.add(file);
375
+ });
376
+ if (!scopeFile) {
377
+ console.error("Could not find scope file for entity", entityId);
378
+ return;
379
+ }
380
+ this.changedFiles.add(scopeFile);
381
+ // For now, just look in the same folder as the scope file for renames
382
+ // in the future, we may need to look in other folders
383
+ const scopeFolder = path.dirname(scopeFile);
384
+ for (const filePath of Object.keys(this.fileToMeta)) {
385
+ if (filePath.startsWith(scopeFolder) && filePath.endsWith(".tsx")) {
386
+ this.renameIdentifier({
387
+ oldName,
388
+ newName,
389
+ filePath,
390
+ parentBinding: scopeName,
391
+ });
392
+ }
393
+ }
394
+ };
395
+ // THEMING
396
+ updateTheme = async ({ themeFilePath, theme, }) => {
397
+ const ast = this.getCurrentFiles()[themeFilePath]?.ast;
398
+ if (!ast) {
399
+ throw new Error("File not found in source tracker " + path);
400
+ }
401
+ updateThemeAst(ast, theme);
402
+ try {
403
+ this.changedFiles.add(themeFilePath);
404
+ }
405
+ catch (e) {
406
+ getLogger().error("Error generating updated theme file", getErrorMeta(e));
407
+ throw e;
408
+ }
409
+ };
410
+ addElement = async ({ parentElement, tagName, properties, children, id, scopeName, }) => {
411
+ const logger = getLogger();
412
+ const parentOpeningElementPath = this.getElementToLocation(parentElement.source.id);
413
+ const parentFilepath = this.getElementToFilePath(parentElement.source.id);
414
+ if (!parentOpeningElementPath || !parentFilepath) {
415
+ logger.error(`Element not found in source tracker ${parentElement.source.id} ${parentOpeningElementPath?.toString()}`);
416
+ throw new Error("Element not found in source tracker " + parentElement.source.id);
417
+ }
418
+ if (!parentOpeningElementPath.isJSXOpeningElement()) {
419
+ logger.error(`Parent element is not a JSX element ${parentOpeningElementPath.type} ${parentOpeningElementPath.toString()}`);
420
+ throw new Error("Parent element is not a JSX element");
421
+ }
422
+ const parentJSXElementPath = parentOpeningElementPath.parentPath;
423
+ if (!parentJSXElementPath?.isJSXElement()) {
424
+ logger.error(`Parent element is not a JSX element ${String(parentJSXElementPath)}`);
425
+ throw new Error("Parent element is not a JSX element");
426
+ }
427
+ try {
428
+ const childName = properties.name;
429
+ if (childName && scopeName) {
430
+ const { scopeDefinition, filePath: scopeFilePath } = this.sbScopeManager.getScopeDefinitionAndFilePathByNameOrId({
431
+ identifier: scopeName,
432
+ type: "name",
433
+ });
434
+ if (!scopeDefinition || !scopeFilePath) {
435
+ console.log("No scope creation found for " + scopeName + " will not add a bind");
436
+ }
437
+ else {
438
+ const { name: scopeExportName } = scopeDefinition;
439
+ if (scopeFilePath !== parentFilepath) {
440
+ // check if exportName is already imported into parentFilePath
441
+ const parentFileImports = this.fileToMeta[parentFilepath]?.imports;
442
+ if (!parentFileImports || !parentFileImports[scopeExportName]) {
443
+ // add the import
444
+ addImport({
445
+ importPath: getImportPath(parentFilepath, scopeFilePath),
446
+ importName: scopeExportName,
447
+ path: parentOpeningElementPath,
448
+ onAdd: () => {
449
+ this.fileToMeta[parentFilepath].imports[scopeExportName] =
450
+ true;
451
+ },
452
+ });
453
+ }
454
+ }
455
+ const childNameValue = childName.value;
456
+ const changedFiles = this.sbScopeManager.addScopeComponent(scopeName, childNameValue);
457
+ changedFiles.forEach((file) => {
458
+ this.changedFiles.add(file);
459
+ });
460
+ // if the scope file path is in the same page directory as this file, then we should destructure it
461
+ if (path.dirname(scopeFilePath) === path.dirname(parentFilepath)) {
462
+ this.sbScopeManager.addScopeDestructuringForComponent({
463
+ elementLocation: parentJSXElementPath,
464
+ scopeName,
465
+ componentFilePath: parentFilepath,
466
+ });
467
+ properties.bind = Property.Expression(`${childNameValue}`);
468
+ }
469
+ else {
470
+ properties.bind = Property.Expression(`${scopeExportName}.${childNameValue}`);
471
+ }
472
+ delete properties.name;
473
+ }
474
+ }
475
+ const newElement = generateJSXElement({
476
+ id,
477
+ tagName,
478
+ properties,
479
+ children,
480
+ });
481
+ this.transformSelfClosingTagToRegularTag(parentJSXElementPath);
482
+ const { index = -1 } = parentElement.source;
483
+ const elementChildren = parentJSXElementPath
484
+ .get("children")
485
+ .filter((child) => child.isJSXElement());
486
+ let results = null;
487
+ if (index === 0) {
488
+ results = parentJSXElementPath.unshiftContainer("children", newElement);
489
+ }
490
+ else if (index < 0 || index >= elementChildren.length) {
491
+ results = parentJSXElementPath.pushContainer("children", newElement);
492
+ }
493
+ else {
494
+ const child = elementChildren[index];
495
+ if (!child)
496
+ throw new Error("Child element not found");
497
+ results = child.insertBefore(newElement);
498
+ }
499
+ if (!Array.isArray(results)) {
500
+ throw new Error("Failed to add element to parent");
501
+ }
502
+ // You can traverse subpaths like this: https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md#paths-in-visitors
503
+ let sourceId;
504
+ results[0]?.traverse({
505
+ JSXOpeningElement: (path) => {
506
+ if (path.node.name.type !== "JSXIdentifier")
507
+ return;
508
+ const tagName = getTagName(path.node.name);
509
+ if (!tagName)
510
+ return;
511
+ this.newlyAddedCount++;
512
+ const id = getSbElementId(path.node) ??
513
+ `SB-${generatePredictableId(parentFilepath + this.newlyAddedCount)}`;
514
+ path.node.extra ??= {};
515
+ path.node.extra.sbElementId = id;
516
+ this.elementToLocation[id] = path;
517
+ this.elementToFilePath[id] = parentFilepath;
518
+ sourceId = id;
519
+ },
520
+ });
521
+ const manager = ComponentsManager.getInstance();
522
+ if (manager.isCustomComponent(tagName)) {
523
+ const importPath = manager.getComponentImportPath(tagName, process.cwd());
524
+ if (importPath) {
525
+ addImport({
526
+ path: parentOpeningElementPath,
527
+ importName: tagName,
528
+ importPath,
529
+ isDefaultImport: true,
530
+ onAdd: () => {
531
+ this.fileToMeta[parentFilepath].imports[tagName] = true;
532
+ },
533
+ });
534
+ }
535
+ }
536
+ else {
537
+ addImport({
538
+ path: parentOpeningElementPath,
539
+ importName: tagName,
540
+ importPath: "@superblocksteam/library",
541
+ onAdd: () => {
542
+ this.fileToMeta[parentFilepath].imports[tagName] = true;
543
+ },
544
+ });
545
+ }
546
+ // We need to add the imports for the properties that are used in the new element
547
+ const requiredImports = this.getAddElementImports({
548
+ properties,
549
+ children,
550
+ });
551
+ requiredImports.forEach((importName) => {
552
+ addImport({
553
+ path: parentOpeningElementPath,
554
+ importName,
555
+ importPath: "@superblocksteam/library",
556
+ onAdd: () => {
557
+ this.fileToMeta[parentFilepath].imports[importName] = true;
558
+ },
559
+ });
560
+ });
561
+ this.changedFiles.add(parentFilepath);
562
+ return sourceId;
563
+ }
564
+ catch (e) {
565
+ getLogger().error("Error updating source tracker during add", getErrorMeta(e));
566
+ throw new Error("Error updating source tracker during add" + e.message);
567
+ }
568
+ };
569
+ deleteElement = async ({ source, scopeName, }) => {
570
+ const logger = getLogger();
571
+ let openingTag = this.getElementToLocation(source.id);
572
+ if (!openingTag) {
573
+ logger.error(`Element not found in source tracker ${source.id}`);
574
+ return;
575
+ }
576
+ if (openingTag.isJSXOpeningElement()) {
577
+ const parent = openingTag.parentPath;
578
+ if (parent?.isJSXElement()) {
579
+ openingTag = parent;
580
+ }
581
+ else {
582
+ logger.error(`JSXOpeningElement does not have a JSXElement parent ${source.id}`);
583
+ return;
584
+ }
585
+ }
586
+ else if (!openingTag.isJSXElement()) {
587
+ logger.error(`Cannot delete a non-JSX element ${source.id}`);
588
+ return;
589
+ }
590
+ const componentName = getDescriptiveName(openingTag.node);
591
+ const children = [];
592
+ openingTag.traverse({
593
+ JSXElement: (path) => {
594
+ const sbElementId = getSbElementId(path.get("openingElement").node);
595
+ const name = getDescriptiveName(path.node);
596
+ if (sbElementId) {
597
+ children.push({ id: sbElementId, name });
598
+ }
599
+ },
600
+ });
601
+ const fileName = this.getElementToFilePath(source.id);
602
+ this.deleteSectionIfOnlyChild(openingTag);
603
+ // First delete the parent and remove it from the AST
604
+ delete this.elementToLocation[source.id];
605
+ delete this.elementToFilePath[source.id];
606
+ openingTag.remove();
607
+ if (scopeName && componentName) {
608
+ const changedFiles = this.sbScopeManager.deleteScopeComponent(scopeName, componentName);
609
+ changedFiles.forEach((file) => {
610
+ this.changedFiles.add(file);
611
+ });
612
+ }
613
+ // Then remove all traces of the children
614
+ children.forEach(({ id, name: childComponentName }) => {
615
+ if (childComponentName && scopeName) {
616
+ const changedFiles = this.sbScopeManager.deleteScopeComponent(scopeName, childComponentName);
617
+ changedFiles.forEach((file) => {
618
+ this.changedFiles.add(file);
619
+ });
620
+ }
621
+ delete this.elementToLocation[id];
622
+ delete this.elementToFilePath[id];
623
+ });
624
+ this.changedFiles.add(fileName);
625
+ };
626
+ // If we're deleting the only SbColumn in an SbSection, remove the SbSection
627
+ deleteSectionIfOnlyChild = (openingTag) => {
628
+ const parentElement = openingTag.parentPath;
629
+ if (!parentElement)
630
+ return false;
631
+ const isSbColumn = getTagName(openingTag.node.openingElement.name) ===
632
+ "SbColumn";
633
+ const isOnlyChild = parentElement.isJSXElement() &&
634
+ parentElement.get("children").filter((child) => child.isJSXElement())
635
+ .length === 1;
636
+ const isParentSbSection = parentElement.isJSXElement() &&
637
+ getTagName(parentElement.node.openingElement.name) ===
638
+ "SbSection";
639
+ if (isSbColumn && isOnlyChild && isParentSbSection) {
640
+ const sectionId = getSbElementId(parentElement.get("openingElement").node);
641
+ if (sectionId) {
642
+ delete this.elementToLocation[sectionId];
643
+ delete this.elementToFilePath[sectionId];
644
+ parentElement.remove();
645
+ }
646
+ }
647
+ };
648
+ /**
649
+ * Set's a deeply nested property on a JSX attribute. For example, if you have an attribute that is
650
+ * an object like:
651
+ * ```
652
+ * columns={{
653
+ * name: {
654
+ * accessor: "name",
655
+ * },
656
+ * }}
657
+ * ```
658
+ * And you want to update the `accessor` property, you can use this function to do so, passing a property path like
659
+ * `columns.name.accessor`, rather than the entire columns object.
660
+ */
661
+ setNestedAttribute = ({ openingTag, property, value, type, }) => {
662
+ const [parent, ...paths] = splitJSPathAdvanced(property, []);
663
+ let parentAttr = openingTag
664
+ .get("attributes")
665
+ .find((attr) => attr.isJSXAttribute() && attr.node.name.name === parent);
666
+ if (!parentAttr && parent) {
667
+ const newAttr = openingTag.pushContainer("attributes", [
668
+ t.jsxAttribute(t.jsxIdentifier(parent), t.jSXExpressionContainer(t.objectExpression([]))),
669
+ ]);
670
+ parentAttr = newAttr[0];
671
+ }
672
+ // why does this return an array of node paths, its super annoying
673
+ const expressionContainer = parentAttr?.get("value");
674
+ if (!expressionContainer ||
675
+ !expressionContainer.isJSXExpressionContainer()) {
676
+ throw new Error("Parent attribute value is not a JSXExpressionContainer");
677
+ }
678
+ const currentNode = expressionContainer.get("expression");
679
+ writeNestedProperty({
680
+ node: currentNode,
681
+ paths,
682
+ value,
683
+ type,
684
+ });
685
+ };
686
+ setAttribute = (openingTag, property, value, type) => {
687
+ const paths = splitJSPath(property);
688
+ if (Array.isArray(paths) && paths.length > 1) {
689
+ // Sometimes we want to set a nested attribute, like `columns.name.accessor`
690
+ this.setNestedAttribute({ openingTag, property, value, type });
691
+ return;
692
+ }
693
+ let attr = openingTag
694
+ .get("attributes")
695
+ .find((attr) => attr.isJSXAttribute() && attr.node.name.name === property);
696
+ if (!attr) {
697
+ attr = openingTag.pushContainer("attributes", [
698
+ t.jsxAttribute(t.jsxIdentifier(property), t.stringLiteral("")),
699
+ ])[0];
700
+ }
701
+ // TODO: move to proper prop typing for custom components, but for now we just try to coerce
702
+ // values 🤷
703
+ if (getTagName(openingTag.node.name) === "SbCustom") {
704
+ const expressionType = getJSXAttributeType(attr.node);
705
+ switch (expressionType) {
706
+ case "string":
707
+ value = value.toString();
708
+ break;
709
+ case "number":
710
+ value = Number(value);
711
+ break;
712
+ case "boolean":
713
+ value = Boolean(value);
714
+ break;
715
+ }
716
+ }
717
+ // We currently delete attributes that are undefined or set to an empty string
718
+ if (value === undefined || (typeof value === "string" && value === "")) {
719
+ attr.remove();
720
+ return;
721
+ }
722
+ const attrName = getJSXAttributeName(attr.node);
723
+ if (attrName === null) {
724
+ throw new Error("Attribute name not found");
725
+ }
726
+ const attrValue = attr.get("value");
727
+ const jsxAttribute = generateJSXAttribute(property, Property.Any(value, type));
728
+ if (jsxAttribute.value) {
729
+ attrValue.replaceWith(jsxAttribute.value);
730
+ }
731
+ return jsxAttribute;
732
+ };
733
+ deleteAttribute = (openingTag, property) => {
734
+ const attr = openingTag
735
+ .get("attributes")
736
+ .find((attr) => attr.isJSXAttribute() && attr.node.name.name === property);
737
+ attr?.remove();
738
+ };
739
+ transformSelfClosingTagToRegularTag = (element) => {
740
+ const openingElement = element.get("openingElement");
741
+ if (openingElement.node.selfClosing) {
742
+ openingElement.node.selfClosing = false;
743
+ element.node.closingElement = t.jsxClosingElement(t.jsxIdentifier(getTagName(openingElement.node.name) ?? ""));
744
+ }
745
+ };
746
+ setProperty = async ({ source, property, value, type, }) => {
747
+ await this.setProperties({
748
+ source,
749
+ changes: { [property]: { value, type } },
750
+ });
751
+ };
752
+ setProperties = async ({ source, changes, }) => {
753
+ const logger = getLogger();
754
+ if (Object.keys(changes).length === 0)
755
+ return;
756
+ try {
757
+ let openingTag = this.getElementToLocation(source.id);
758
+ if (openingTag?.isJSXElement()) {
759
+ openingTag = openingTag.get("openingElement");
760
+ }
761
+ const fileName = this.getElementToFilePath(source.id);
762
+ if (!fileName) {
763
+ logger.error(`Filepath not found for element ${source.id} ${openingTag}`);
764
+ throw new Error(`Filepath not found for element ${source.id}`);
765
+ }
766
+ const currentFile = this.fileToMeta[fileName];
767
+ if (!currentFile || !openingTag) {
768
+ throw new Error(`Element ${source.id} not found in source tracker`);
769
+ }
770
+ if (!openingTag.isJSXOpeningElement()) {
771
+ throw new Error(`Element ${source.id} is not a JSXOpeningElement`);
772
+ }
773
+ // Iterate over the changes and set each attribute using the helper
774
+ for (const [key, { value, type }] of Object.entries(changes)) {
775
+ // TODO(code-mode): should we use property definitions to ensure writes are valid?
776
+ // For now we will just add the attribute to the element and write the update
777
+ const processedValue = value;
778
+ const jsxAttribute = this.setAttribute(openingTag, key, processedValue, type);
779
+ if (type in REQUIRED_IMPORTS_BY_PROPERTY_TYPE) {
780
+ const requiredImports = REQUIRED_IMPORTS_BY_PROPERTY_TYPE[type];
781
+ if (requiredImports) {
782
+ for (const { importName, importPath } of requiredImports) {
783
+ if (!this.fileToMeta[fileName].imports[importName]) {
784
+ addImport({
785
+ importPath,
786
+ importName,
787
+ path: openingTag,
788
+ onAdd: () => {
789
+ this.fileToMeta[fileName].imports[importName] = true;
790
+ },
791
+ });
792
+ }
793
+ }
794
+ }
795
+ }
796
+ if (type === "EVENT" && jsxAttribute) {
797
+ const referencedGlobalFunctions = getVariableReferences(jsxAttribute, GLOBAL_FUNCTION_NAMES);
798
+ referencedGlobalFunctions.forEach((funcName) => {
799
+ if (!this.fileToMeta[fileName].imports[funcName]) {
800
+ addImport({
801
+ importPath: "@superblocksteam/library",
802
+ importName: funcName,
803
+ path: openingTag,
804
+ onAdd: () => {
805
+ this.fileToMeta[fileName].imports[funcName] = true;
806
+ },
807
+ });
808
+ }
809
+ });
810
+ }
811
+ if (ATTRIBUTE_TYPES_WITH_STATE_ACCESS.includes(type) && jsxAttribute) {
812
+ const elementLocation = this.getElementToLocation(source.id);
813
+ const scopeImports = this.sbScopeManager.getAndUpdateScopeImportsForCodeSnippet({
814
+ jsxAttribute,
815
+ codeFilePath: fileName,
816
+ elementLocation,
817
+ existingImports: this.fileToMeta[fileName].imports,
818
+ });
819
+ scopeImports.forEach(({ importPath, importName }) => {
820
+ addImport({
821
+ importPath,
822
+ importName,
823
+ path: openingTag,
824
+ onAdd: () => {
825
+ this.fileToMeta[fileName].imports[importName] = true;
826
+ },
827
+ });
828
+ });
829
+ }
830
+ }
831
+ this.changedFiles.add(fileName);
832
+ }
833
+ catch (e) {
834
+ logger.error("Error setting property", getErrorMeta(e));
835
+ }
836
+ };
837
+ deleteProperties = async ({ source, properties, }) => {
838
+ const logger = getLogger();
839
+ try {
840
+ let openingTag = this.elementToLocation[source.id];
841
+ if (openingTag?.isJSXElement()) {
842
+ openingTag = openingTag.get("openingElement");
843
+ }
844
+ const fileName = this.getElementToFilePath(source.id);
845
+ if (!fileName) {
846
+ logger.error(`Filepath not found for element ${source.id} ${openingTag}`);
847
+ throw new Error(`Filepath not found for element ${source.id}`);
848
+ }
849
+ const currentFile = this.fileToMeta[fileName];
850
+ if (!currentFile || !openingTag) {
851
+ throw new Error(`Element ${source.id} not found in source tracker`);
852
+ }
853
+ if (!openingTag.isJSXOpeningElement()) {
854
+ throw new Error(`Element ${source.id} is not a JSXOpeningElement`);
855
+ }
856
+ for (const property of properties) {
857
+ this.deleteAttribute(openingTag, property);
858
+ }
859
+ this.changedFiles.add(fileName);
860
+ }
861
+ catch (e) {
862
+ logger.error("Error deleting properties", getErrorMeta(e));
863
+ }
864
+ };
865
+ renameComponent = async ({ widgetSourceId, newName, oldName, scopeName, }) => {
866
+ const filePath = this.getElementToFilePath(widgetSourceId);
867
+ const currentFile = this.fileToMeta[filePath];
868
+ if (!currentFile || !currentFile.ast) {
869
+ throw new Error(`File not found for element ${filePath}`);
870
+ }
871
+ let widgetNode = this.getElementToLocation(widgetSourceId);
872
+ if (!widgetNode) {
873
+ throw new Error(`Widget ${widgetSourceId} not found`);
874
+ }
875
+ if (widgetNode?.isJSXElement()) {
876
+ widgetNode = widgetNode.get("openingElement");
877
+ }
878
+ const hasNameAttribute = isNamedComponent(widgetNode.node);
879
+ if (scopeName) {
880
+ const changedFiles = this.sbScopeManager.renameScopeComponent({
881
+ oldName: hasNameAttribute ? oldName : undefined,
882
+ newName,
883
+ scopeName,
884
+ });
885
+ changedFiles.forEach((file) => {
886
+ this.changedFiles.add(file);
887
+ });
888
+ }
889
+ await this.renameManager.renameComponent({
890
+ widgetNode: widgetNode,
891
+ newName,
892
+ ast: currentFile.ast,
893
+ });
894
+ this.changedFiles.add(filePath);
895
+ };
896
+ renameIdentifier = ({ oldName, newName, filePath, parentBinding, }) => {
897
+ const currentFile = this.fileToMeta[filePath];
898
+ if (!currentFile || !currentFile.ast) {
899
+ throw new Error(`File not found for element ${filePath}`);
900
+ }
901
+ this.renameManager.renameIdentifierInAST({
902
+ oldName,
903
+ newName,
904
+ ast: currentFile.ast,
905
+ parentBinding,
906
+ });
907
+ this.changedFiles.add(filePath);
908
+ };
909
+ /**
910
+ * Change the name of the page element within a page file. Note: this does not actually
911
+ * rename the page file, but only the name of the page element, you have to perform the
912
+ * file system operation separately.
913
+ */
914
+ renamePage = async ({ newName, filePath, }) => {
915
+ const currentFile = this.fileToMeta[filePath];
916
+ if (!currentFile || !currentFile.ast) {
917
+ throw new Error(`File not found for element ${filePath}`);
918
+ }
919
+ const widgetSourceId = generateElementId(filePath, ["SbPage"], 0);
920
+ const pageElement = this.getElementToLocation(widgetSourceId);
921
+ if (!pageElement) {
922
+ throw new Error(`Page element not found for ${widgetSourceId}`);
923
+ }
924
+ const attributes = pageElement.get("attributes");
925
+ const attribute = attributes?.find((attr) => attr.isJSXAttribute() && attr.node.name.name === "name");
926
+ attribute?.replaceWith(t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(newName)));
927
+ this.changedFiles.add(filePath);
928
+ };
929
+ getAddElementImports = ({ properties, children, }) => {
930
+ const getPropertyImports = (properties) => {
931
+ return Object.values(properties)
932
+ .flatMap((property) => {
933
+ if (property.type === "EVENT") {
934
+ return "SbEventFlow";
935
+ }
936
+ if (property.type === "DIMENSION") {
937
+ return "Dim";
938
+ }
939
+ if (property.type === "BINDING") {
940
+ return "SB";
941
+ }
942
+ if (property.type === "STATIC" &&
943
+ typeof property.value === "object" &&
944
+ property.value != null) {
945
+ // Object.entries works on arrays as well, so we dont need to special case them for just finding property values
946
+ const staticProperties = Object.fromEntries(Object.entries(property.value).filter(([_, value]) => isPropertyInfo(value)));
947
+ return getPropertyImports(staticProperties);
948
+ }
949
+ return null;
950
+ })
951
+ .filter(Boolean);
952
+ };
953
+ const getComponentImports = (children) => {
954
+ return children.flatMap((child) => {
955
+ return [
956
+ child.tagName,
957
+ ...getPropertyImports(child.properties),
958
+ ...getComponentImports(child.children),
959
+ ];
960
+ });
961
+ };
962
+ const requiredPropertyImports = getPropertyImports(properties);
963
+ const requiredComponentImports = getComponentImports(children);
964
+ return Array.from(new Set([...requiredPropertyImports, ...requiredComponentImports]));
965
+ };
966
+ }
967
+ //# sourceMappingURL=source-tracker.js.map