@superblocksteam/vite-plugin-file-sync 1.99.99-next.2

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