@conloca/cms-spa 0.1.14 → 0.1.16

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 (438) hide show
  1. package/dist/App-Bk1LNxbS.mjs +10851 -0
  2. package/dist/App-Bk1LNxbS.mjs.map +1 -0
  3. package/dist/App.d.ts +35 -0
  4. package/dist/App.d.ts.map +1 -0
  5. package/dist/App.js +52 -0
  6. package/dist/CmsSpaApp.d.ts +13 -0
  7. package/dist/CmsSpaApp.d.ts.map +1 -0
  8. package/dist/CmsSpaApp.js +33 -0
  9. package/dist/cn-dlASUkDY.mjs +10 -0
  10. package/dist/cn-dlASUkDY.mjs.map +1 -0
  11. package/dist/components/CMSDashboard.d.ts +2 -0
  12. package/dist/components/CMSDashboard.d.ts.map +1 -0
  13. package/dist/components/CMSDashboard.js +20 -0
  14. package/dist/components/CMSLayout.d.ts +2 -0
  15. package/dist/components/CMSLayout.d.ts.map +1 -0
  16. package/dist/components/CMSLayout.js +15 -0
  17. package/dist/components/ConlocaLogo.d.ts +2 -0
  18. package/dist/components/ConlocaLogo.d.ts.map +1 -0
  19. package/dist/components/ConlocaLogo.js +4 -0
  20. package/dist/components/GitStatusPanel.d.ts +25 -0
  21. package/dist/components/GitStatusPanel.d.ts.map +1 -0
  22. package/dist/components/GitStatusPanel.js +77 -0
  23. package/dist/components/MobileTopBar.d.ts +6 -0
  24. package/dist/components/MobileTopBar.d.ts.map +1 -0
  25. package/dist/components/MobileTopBar.js +6 -0
  26. package/dist/components/Sidebar.d.ts +8 -0
  27. package/dist/components/Sidebar.d.ts.map +1 -0
  28. package/dist/components/Sidebar.js +40 -0
  29. package/dist/components/UserAvatar.d.ts +2 -0
  30. package/dist/components/UserAvatar.d.ts.map +1 -0
  31. package/dist/components/UserAvatar.js +14 -0
  32. package/dist/components/cards/DataEntryCard.d.ts +14 -0
  33. package/dist/components/cards/DataEntryCard.d.ts.map +1 -0
  34. package/dist/components/cards/DataEntryCard.js +32 -0
  35. package/dist/components/cards/SectionCard.d.ts +15 -0
  36. package/dist/components/cards/SectionCard.d.ts.map +1 -0
  37. package/dist/components/cards/SectionCard.js +10 -0
  38. package/dist/components/cards/index.d.ts +2 -0
  39. package/dist/components/cards/index.d.ts.map +1 -0
  40. package/dist/components/cards/index.js +1 -0
  41. package/dist/components/dashboard/RecentActivity.d.ts +2 -0
  42. package/dist/components/dashboard/RecentActivity.d.ts.map +1 -0
  43. package/dist/components/dashboard/RecentActivity.js +58 -0
  44. package/dist/components/dialog.d.ts +53 -0
  45. package/dist/components/dialog.d.ts.map +1 -0
  46. package/dist/components/dialog.js +56 -0
  47. package/dist/components/dialogs/BlockPropertiesDialog.d.ts +12 -0
  48. package/dist/components/dialogs/BlockPropertiesDialog.d.ts.map +1 -0
  49. package/dist/components/dialogs/BlockPropertiesDialog.js +42 -0
  50. package/dist/components/dialogs/ConflictDialog.d.ts +10 -0
  51. package/dist/components/dialogs/ConflictDialog.d.ts.map +1 -0
  52. package/dist/components/dialogs/ConflictDialog.js +29 -0
  53. package/dist/components/dialogs/CreateDataDialog.d.ts +9 -0
  54. package/dist/components/dialogs/CreateDataDialog.d.ts.map +1 -0
  55. package/dist/components/dialogs/CreateDataDialog.js +20 -0
  56. package/dist/components/dialogs/CreateFolderDialog.d.ts +9 -0
  57. package/dist/components/dialogs/CreateFolderDialog.d.ts.map +1 -0
  58. package/dist/components/dialogs/CreateFolderDialog.js +33 -0
  59. package/dist/components/dialogs/CreatePageDialog.d.ts +10 -0
  60. package/dist/components/dialogs/CreatePageDialog.d.ts.map +1 -0
  61. package/dist/components/dialogs/CreatePageDialog.js +155 -0
  62. package/dist/components/dialogs/DataPropertiesDialog.d.ts +10 -0
  63. package/dist/components/dialogs/DataPropertiesDialog.d.ts.map +1 -0
  64. package/dist/components/dialogs/DataPropertiesDialog.js +38 -0
  65. package/dist/components/dialogs/DeleteConfirmDialog.d.ts +12 -0
  66. package/dist/components/dialogs/DeleteConfirmDialog.d.ts.map +1 -0
  67. package/dist/components/dialogs/DeleteConfirmDialog.js +7 -0
  68. package/dist/components/dialogs/ErrorModal.d.ts +14 -0
  69. package/dist/components/dialogs/ErrorModal.d.ts.map +1 -0
  70. package/dist/components/dialogs/ErrorModal.js +38 -0
  71. package/dist/components/dialogs/MoveFolderDialog.d.ts +11 -0
  72. package/dist/components/dialogs/MoveFolderDialog.d.ts.map +1 -0
  73. package/dist/components/dialogs/MoveFolderDialog.js +45 -0
  74. package/dist/components/dialogs/PageMetadataDialog.d.ts +10 -0
  75. package/dist/components/dialogs/PageMetadataDialog.d.ts.map +1 -0
  76. package/dist/components/dialogs/PageMetadataDialog.js +85 -0
  77. package/dist/components/dialogs/UnsavedChangesDialog.d.ts +8 -0
  78. package/dist/components/dialogs/UnsavedChangesDialog.d.ts.map +1 -0
  79. package/dist/components/dialogs/UnsavedChangesDialog.js +6 -0
  80. package/dist/components/dialogs/index.d.ts +9 -0
  81. package/dist/components/dialogs/index.d.ts.map +1 -0
  82. package/dist/components/dialogs/index.js +8 -0
  83. package/dist/components/editor/BlockEditor.d.ts +8 -0
  84. package/dist/components/editor/BlockEditor.d.ts.map +1 -0
  85. package/dist/components/editor/BlockEditor.js +262 -0
  86. package/dist/components/editor/BlockWrappers.d.ts +15 -0
  87. package/dist/components/editor/BlockWrappers.d.ts.map +1 -0
  88. package/dist/components/editor/BlockWrappers.js +29 -0
  89. package/dist/components/editor/CMSMDXEditor.d.ts +13 -0
  90. package/dist/components/editor/CMSMDXEditor.d.ts.map +1 -0
  91. package/dist/components/editor/CMSMDXEditor.js +123 -0
  92. package/dist/components/editor/ContentDiff.d.ts +10 -0
  93. package/dist/components/editor/ContentDiff.d.ts.map +1 -0
  94. package/dist/components/editor/ContentDiff.js +51 -0
  95. package/dist/components/editor/CreateBlockDialog.d.ts +26 -0
  96. package/dist/components/editor/CreateBlockDialog.d.ts.map +1 -0
  97. package/dist/components/editor/CreateBlockDialog.js +131 -0
  98. package/dist/components/editor/DrawerItemOverride.d.ts +8 -0
  99. package/dist/components/editor/DrawerItemOverride.d.ts.map +1 -0
  100. package/dist/components/editor/DrawerItemOverride.js +41 -0
  101. package/dist/components/editor/EditorChromeToggles.d.ts +16 -0
  102. package/dist/components/editor/EditorChromeToggles.d.ts.map +1 -0
  103. package/dist/components/editor/EditorChromeToggles.js +16 -0
  104. package/dist/components/editor/GenericBlock.d.ts +3 -0
  105. package/dist/components/editor/GenericBlock.d.ts.map +1 -0
  106. package/dist/components/editor/GenericBlock.js +1067 -0
  107. package/dist/components/editor/ImagePickerDialog.d.ts +6 -0
  108. package/dist/components/editor/ImagePickerDialog.d.ts.map +1 -0
  109. package/dist/components/editor/ImagePickerDialog.js +24 -0
  110. package/dist/components/editor/JsxPropsPanel.d.ts +16 -0
  111. package/dist/components/editor/JsxPropsPanel.d.ts.map +1 -0
  112. package/dist/components/editor/JsxPropsPanel.js +145 -0
  113. package/dist/components/editor/LocaleSelector.d.ts +9 -0
  114. package/dist/components/editor/LocaleSelector.d.ts.map +1 -0
  115. package/dist/components/editor/LocaleSelector.js +13 -0
  116. package/dist/components/editor/MDXLivePreview.d.ts +14 -0
  117. package/dist/components/editor/MDXLivePreview.d.ts.map +1 -0
  118. package/dist/components/editor/MDXLivePreview.js +103 -0
  119. package/dist/components/editor/MdxPageEditor.d.ts +10 -0
  120. package/dist/components/editor/MdxPageEditor.d.ts.map +1 -0
  121. package/dist/components/editor/MdxPageEditor.js +297 -0
  122. package/dist/components/editor/PageEditor.d.ts +18 -0
  123. package/dist/components/editor/PageEditor.d.ts.map +1 -0
  124. package/dist/components/editor/PageEditor.js +288 -0
  125. package/dist/components/editor/PageEditorHeaderActions.d.ts +16 -0
  126. package/dist/components/editor/PageEditorHeaderActions.d.ts.map +1 -0
  127. package/dist/components/editor/PageEditorHeaderActions.js +19 -0
  128. package/dist/components/editor/PageEditorWrapper.d.ts +7 -0
  129. package/dist/components/editor/PageEditorWrapper.d.ts.map +1 -0
  130. package/dist/components/editor/PageEditorWrapper.js +319 -0
  131. package/dist/components/editor/SearchableSelect.d.ts +34 -0
  132. package/dist/components/editor/SearchableSelect.d.ts.map +1 -0
  133. package/dist/components/editor/SearchableSelect.js +116 -0
  134. package/dist/components/editor/host-wrapper-plugin.d.ts +51 -0
  135. package/dist/components/editor/host-wrapper-plugin.d.ts.map +1 -0
  136. package/dist/components/editor/host-wrapper-plugin.js +37 -0
  137. package/dist/components/editor/index.d.ts +9 -0
  138. package/dist/components/editor/index.d.ts.map +1 -0
  139. package/dist/components/editor/index.js +7 -0
  140. package/dist/components/editor/insert-menu/InsertMdxComponentButton.d.ts +15 -0
  141. package/dist/components/editor/insert-menu/InsertMdxComponentButton.d.ts.map +1 -0
  142. package/dist/components/editor/insert-menu/InsertMdxComponentButton.js +90 -0
  143. package/dist/components/editor/insert-menu/SlashMenuPlugin.d.ts +12 -0
  144. package/dist/components/editor/insert-menu/SlashMenuPlugin.d.ts.map +1 -0
  145. package/dist/components/editor/insert-menu/SlashMenuPlugin.js +106 -0
  146. package/dist/components/editor/insert-menu/insert-payload.d.ts +76 -0
  147. package/dist/components/editor/insert-menu/insert-payload.d.ts.map +1 -0
  148. package/dist/components/editor/insert-menu/insert-payload.js +94 -0
  149. package/dist/components/editor/insert-menu/mdx-components-plugin.d.ts +8 -0
  150. package/dist/components/editor/insert-menu/mdx-components-plugin.d.ts.map +1 -0
  151. package/dist/components/editor/insert-menu/mdx-components-plugin.js +13 -0
  152. package/dist/components/editors/DataEditor.d.ts +19 -0
  153. package/dist/components/editors/DataEditor.d.ts.map +1 -0
  154. package/dist/components/editors/DataEditor.js +139 -0
  155. package/dist/components/fields/ContentBlockSelectorField.d.ts +14 -0
  156. package/dist/components/fields/ContentBlockSelectorField.d.ts.map +1 -0
  157. package/dist/components/fields/ContentBlockSelectorField.js +105 -0
  158. package/dist/components/fields/ImageField.d.ts +16 -0
  159. package/dist/components/fields/ImageField.d.ts.map +1 -0
  160. package/dist/components/fields/ImageField.js +39 -0
  161. package/dist/components/fields/MDXEditField.d.ts +17 -0
  162. package/dist/components/fields/MDXEditField.d.ts.map +1 -0
  163. package/dist/components/fields/MDXEditField.js +28 -0
  164. package/dist/components/forms/ChipArrayField.d.ts +12 -0
  165. package/dist/components/forms/ChipArrayField.d.ts.map +1 -0
  166. package/dist/components/forms/ChipArrayField.js +40 -0
  167. package/dist/components/forms/HintForm.d.ts +22 -0
  168. package/dist/components/forms/HintForm.d.ts.map +1 -0
  169. package/dist/components/forms/HintForm.js +162 -0
  170. package/dist/components/forms/SchemaForm.d.ts +15 -0
  171. package/dist/components/forms/SchemaForm.d.ts.map +1 -0
  172. package/dist/components/forms/SchemaForm.js +106 -0
  173. package/dist/components/index.d.ts +8 -0
  174. package/dist/components/index.d.ts.map +1 -0
  175. package/dist/components/index.js +13 -0
  176. package/dist/components/media/AssetCard.d.ts +14 -0
  177. package/dist/components/media/AssetCard.d.ts.map +1 -0
  178. package/dist/components/media/AssetCard.js +31 -0
  179. package/dist/components/media/AssetDetailSidebar.d.ts +11 -0
  180. package/dist/components/media/AssetDetailSidebar.d.ts.map +1 -0
  181. package/dist/components/media/AssetDetailSidebar.js +101 -0
  182. package/dist/components/media/BulkActionBar.d.ts +9 -0
  183. package/dist/components/media/BulkActionBar.d.ts.map +1 -0
  184. package/dist/components/media/BulkActionBar.js +8 -0
  185. package/dist/components/media/FolderNav.d.ts +7 -0
  186. package/dist/components/media/FolderNav.d.ts.map +1 -0
  187. package/dist/components/media/FolderNav.js +12 -0
  188. package/dist/components/media/FolderTreeSidebar.d.ts +9 -0
  189. package/dist/components/media/FolderTreeSidebar.d.ts.map +1 -0
  190. package/dist/components/media/FolderTreeSidebar.js +41 -0
  191. package/dist/components/media/ImagePicker.d.ts +14 -0
  192. package/dist/components/media/ImagePicker.d.ts.map +1 -0
  193. package/dist/components/media/ImagePicker.js +45 -0
  194. package/dist/components/media/MediaLibrary.d.ts +35 -0
  195. package/dist/components/media/MediaLibrary.d.ts.map +1 -0
  196. package/dist/components/media/MediaLibrary.js +100 -0
  197. package/dist/components/media/MediaToolbar.d.ts +21 -0
  198. package/dist/components/media/MediaToolbar.d.ts.map +1 -0
  199. package/dist/components/media/MediaToolbar.js +6 -0
  200. package/dist/components/media/UploadModal.d.ts +9 -0
  201. package/dist/components/media/UploadModal.d.ts.map +1 -0
  202. package/dist/components/media/UploadModal.js +42 -0
  203. package/dist/components/media/UploadZone.d.ts +8 -0
  204. package/dist/components/media/UploadZone.d.ts.map +1 -0
  205. package/dist/components/media/UploadZone.js +22 -0
  206. package/dist/components/media/index.d.ts +11 -0
  207. package/dist/components/media/index.d.ts.map +1 -0
  208. package/dist/components/media/index.js +10 -0
  209. package/dist/components/pages/BlockList.d.ts +2 -0
  210. package/dist/components/pages/BlockList.d.ts.map +1 -0
  211. package/dist/components/pages/BlockList.js +280 -0
  212. package/dist/components/pages/DataList.d.ts +7 -0
  213. package/dist/components/pages/DataList.d.ts.map +1 -0
  214. package/dist/components/pages/DataList.js +244 -0
  215. package/dist/components/pages/MediaPage.d.ts +8 -0
  216. package/dist/components/pages/MediaPage.d.ts.map +1 -0
  217. package/dist/components/pages/MediaPage.js +107 -0
  218. package/dist/components/pages/PageList.d.ts +7 -0
  219. package/dist/components/pages/PageList.d.ts.map +1 -0
  220. package/dist/components/pages/PageList.js +308 -0
  221. package/dist/components/pages/index.d.ts +3 -0
  222. package/dist/components/pages/index.d.ts.map +1 -0
  223. package/dist/components/pages/index.js +2 -0
  224. package/dist/components/puck/MDXContent.d.ts +10 -0
  225. package/dist/components/puck/MDXContent.d.ts.map +1 -0
  226. package/dist/components/puck/MDXContent.js +80 -0
  227. package/dist/components/puck/index.d.ts +2 -0
  228. package/dist/components/puck/index.d.ts.map +1 -0
  229. package/dist/components/puck/index.js +1 -0
  230. package/dist/components/toast.d.ts +44 -0
  231. package/dist/components/toast.d.ts.map +1 -0
  232. package/dist/components/toast.js +7 -0
  233. package/dist/components/ui/Banner.d.ts +76 -0
  234. package/dist/components/ui/Banner.d.ts.map +1 -0
  235. package/dist/components/ui/Banner.js +49 -0
  236. package/dist/components/ui/Button.d.ts +25 -0
  237. package/dist/components/ui/Button.d.ts.map +1 -0
  238. package/dist/components/ui/Button.js +33 -0
  239. package/dist/components/ui/Card.d.ts +72 -0
  240. package/dist/components/ui/Card.d.ts.map +1 -0
  241. package/dist/components/ui/Card.js +49 -0
  242. package/dist/components/ui/FieldError.d.ts +24 -0
  243. package/dist/components/ui/FieldError.d.ts.map +1 -0
  244. package/dist/components/ui/FieldError.js +17 -0
  245. package/dist/components/ui/IconButton.d.ts +13 -0
  246. package/dist/components/ui/IconButton.d.ts.map +1 -0
  247. package/dist/components/ui/IconButton.js +10 -0
  248. package/dist/components/ui/Input.d.ts +37 -0
  249. package/dist/components/ui/Input.d.ts.map +1 -0
  250. package/dist/components/ui/Input.js +9 -0
  251. package/dist/components/ui/SaveIndicator.d.ts +8 -0
  252. package/dist/components/ui/SaveIndicator.d.ts.map +1 -0
  253. package/dist/components/ui/SaveIndicator.js +32 -0
  254. package/dist/components/ui/Select.d.ts +8 -0
  255. package/dist/components/ui/Select.d.ts.map +1 -0
  256. package/dist/components/ui/Select.js +9 -0
  257. package/dist/components/ui/Separator.d.ts +7 -0
  258. package/dist/components/ui/Separator.d.ts.map +1 -0
  259. package/dist/components/ui/Separator.js +8 -0
  260. package/dist/components/ui/Textarea.d.ts +8 -0
  261. package/dist/components/ui/Textarea.d.ts.map +1 -0
  262. package/dist/components/ui/Textarea.js +5 -0
  263. package/dist/components/ui/Tooltip.d.ts +9 -0
  264. package/dist/components/ui/Tooltip.d.ts.map +1 -0
  265. package/dist/components/ui/Tooltip.js +7 -0
  266. package/dist/components/ui/index.d.ts +14 -0
  267. package/dist/components/ui/index.d.ts.map +1 -0
  268. package/dist/components/ui/index.js +17 -0
  269. package/dist/data-schemas.d.mts +0 -1
  270. package/dist/data-schemas.d.mts.map +1 -1
  271. package/dist/data-schemas.d.ts +22 -0
  272. package/dist/data-schemas.d.ts.map +1 -0
  273. package/dist/data-schemas.js +51 -0
  274. package/dist/data-schemas.mjs +3 -4
  275. package/dist/data-schemas.mjs.map +1 -1
  276. package/dist/dev-entry.d.ts +2 -0
  277. package/dist/dev-entry.d.ts.map +1 -0
  278. package/dist/dev-entry.js +19 -0
  279. package/dist/dialog.d.mts +56 -0
  280. package/dist/dialog.d.mts.map +1 -0
  281. package/dist/dialog.mjs +67 -0
  282. package/dist/dialog.mjs.map +1 -0
  283. package/dist/hooks/index.d.ts +10 -0
  284. package/dist/hooks/index.d.ts.map +1 -0
  285. package/dist/hooks/index.js +7 -0
  286. package/dist/hooks/useCanvasTheme.d.ts +12 -0
  287. package/dist/hooks/useCanvasTheme.d.ts.map +1 -0
  288. package/dist/hooks/useCanvasTheme.js +33 -0
  289. package/dist/hooks/useClickOutside.d.ts +7 -0
  290. package/dist/hooks/useClickOutside.d.ts.map +1 -0
  291. package/dist/hooks/useClickOutside.js +18 -0
  292. package/dist/hooks/useDialogState.d.ts +23 -0
  293. package/dist/hooks/useDialogState.d.ts.map +1 -0
  294. package/dist/hooks/useDialogState.js +31 -0
  295. package/dist/hooks/useEditorPref.d.ts +2 -0
  296. package/dist/hooks/useEditorPref.d.ts.map +1 -0
  297. package/dist/hooks/useEditorPref.js +49 -0
  298. package/dist/hooks/useErrorModal.d.ts +15 -0
  299. package/dist/hooks/useErrorModal.d.ts.map +1 -0
  300. package/dist/hooks/useErrorModal.js +35 -0
  301. package/dist/hooks/useSiteBaseUrl.d.ts +10 -0
  302. package/dist/hooks/useSiteBaseUrl.d.ts.map +1 -0
  303. package/dist/hooks/useSiteBaseUrl.js +14 -0
  304. package/dist/hooks/useTheme.d.ts +13 -0
  305. package/dist/hooks/useTheme.d.ts.map +1 -0
  306. package/dist/hooks/useTheme.js +69 -0
  307. package/dist/hooks/useUnsavedChangesGuard.d.ts +16 -0
  308. package/dist/hooks/useUnsavedChangesGuard.d.ts.map +1 -0
  309. package/dist/hooks/useUnsavedChangesGuard.js +29 -0
  310. package/dist/hooks/useUpload.d.ts +10 -0
  311. package/dist/hooks/useUpload.d.ts.map +1 -0
  312. package/dist/hooks/useUpload.js +42 -0
  313. package/dist/hooks/useUploadFlow.d.ts +42 -0
  314. package/dist/hooks/useUploadFlow.d.ts.map +1 -0
  315. package/dist/hooks/useUploadFlow.js +148 -0
  316. package/dist/host-style-probe.d.ts +22 -0
  317. package/dist/host-style-probe.d.ts.map +1 -0
  318. package/dist/host-style-probe.js +508 -0
  319. package/dist/index.d.mts +165 -48
  320. package/dist/index.d.mts.map +1 -1
  321. package/dist/index.d.ts +10 -0
  322. package/dist/index.d.ts.map +1 -0
  323. package/dist/index.js +12 -0
  324. package/dist/index.mjs +36 -2
  325. package/dist/index.mjs.map +1 -0
  326. package/dist/lib/utils.d.ts +13 -0
  327. package/dist/lib/utils.d.ts.map +1 -0
  328. package/dist/lib/utils.js +47 -0
  329. package/dist/main-spa-781YUplS.mjs +46 -0
  330. package/dist/main-spa-781YUplS.mjs.map +1 -0
  331. package/dist/main-spa.d.ts +8 -0
  332. package/dist/main-spa.d.ts.map +1 -0
  333. package/dist/main-spa.js +61 -0
  334. package/dist/main.d.mts +1 -1
  335. package/dist/main.d.ts +2 -0
  336. package/dist/main.d.ts.map +1 -0
  337. package/dist/main.js +13 -0
  338. package/dist/main.mjs +11 -4998
  339. package/dist/main.mjs.map +1 -1
  340. package/dist/mdx-components.d.mts +207 -0
  341. package/dist/mdx-components.d.mts.map +1 -0
  342. package/dist/mdx-components.d.ts +204 -0
  343. package/dist/mdx-components.d.ts.map +1 -0
  344. package/dist/mdx-components.js +217 -0
  345. package/dist/mdx-components.mjs +208 -0
  346. package/dist/mdx-components.mjs.map +1 -0
  347. package/dist/media/AssetScopePill.d.ts +30 -0
  348. package/dist/media/AssetScopePill.d.ts.map +1 -0
  349. package/dist/media/AssetScopePill.js +30 -0
  350. package/dist/media/MediaIssueBadge.d.ts +33 -0
  351. package/dist/media/MediaIssueBadge.d.ts.map +1 -0
  352. package/dist/media/MediaIssueBadge.js +54 -0
  353. package/dist/media/types.d.ts +101 -0
  354. package/dist/media/types.d.ts.map +1 -0
  355. package/dist/media/types.js +1 -0
  356. package/dist/media/use-asset-scope.d.ts +25 -0
  357. package/dist/media/use-asset-scope.d.ts.map +1 -0
  358. package/dist/media/use-asset-scope.js +54 -0
  359. package/dist/media/use-media-issue.d.ts +24 -0
  360. package/dist/media/use-media-issue.d.ts.map +1 -0
  361. package/dist/media/use-media-issue.js +49 -0
  362. package/dist/mock-puck-config.d.mts +23 -0
  363. package/dist/mock-puck-config.d.mts.map +1 -0
  364. package/dist/mock-puck-config.d.ts +21 -0
  365. package/dist/mock-puck-config.d.ts.map +1 -0
  366. package/dist/mock-puck-config.js +73 -0
  367. package/dist/mock-puck-config.mjs +125 -0
  368. package/dist/mock-puck-config.mjs.map +1 -0
  369. package/dist/page-schemas.d.mts +139 -6
  370. package/dist/page-schemas.d.mts.map +1 -1
  371. package/dist/page-schemas.d.ts +156 -0
  372. package/dist/page-schemas.d.ts.map +1 -0
  373. package/dist/page-schemas.js +118 -0
  374. package/dist/page-schemas.mjs +74 -6
  375. package/dist/page-schemas.mjs.map +1 -1
  376. package/dist/puck-config.d.mts +9 -1
  377. package/dist/puck-config.d.mts.map +1 -1
  378. package/dist/puck-config.d.ts +31 -0
  379. package/dist/puck-config.d.ts.map +1 -0
  380. package/dist/puck-config.js +50 -0
  381. package/dist/puck-config.mjs +3 -4
  382. package/dist/puck-config.mjs.map +1 -1
  383. package/dist/selected-block.d.ts +61 -0
  384. package/dist/selected-block.d.ts.map +1 -0
  385. package/dist/selected-block.js +64 -0
  386. package/dist/site-styles.d.mts +123 -0
  387. package/dist/site-styles.d.mts.map +1 -0
  388. package/dist/site-styles.d.ts +121 -0
  389. package/dist/site-styles.d.ts.map +1 -0
  390. package/dist/site-styles.js +253 -0
  391. package/dist/site-styles.mjs +234 -0
  392. package/dist/site-styles.mjs.map +1 -0
  393. package/dist/spa/main.css +5497 -4371
  394. package/dist/toast.d.mts +7 -0
  395. package/dist/toast.d.mts.map +1 -0
  396. package/dist/toast.mjs +16 -0
  397. package/dist/toast.mjs.map +1 -0
  398. package/dist/types.d.ts +57 -0
  399. package/dist/types.d.ts.map +1 -0
  400. package/dist/types.js +1 -0
  401. package/dist/ui-CIacC6Mv.mjs +318 -0
  402. package/dist/ui-CIacC6Mv.mjs.map +1 -0
  403. package/dist/ui-config.d.ts +70 -0
  404. package/dist/ui-config.d.ts.map +1 -0
  405. package/dist/ui-config.js +44 -0
  406. package/dist/ui.d.mts +290 -0
  407. package/dist/ui.d.mts.map +1 -0
  408. package/dist/ui.mjs +2 -0
  409. package/dist/utils/asset-url.d.ts +3 -0
  410. package/dist/utils/asset-url.d.ts.map +1 -0
  411. package/dist/utils/asset-url.js +7 -0
  412. package/dist/utils/cn.d.ts +3 -0
  413. package/dist/utils/cn.d.ts.map +1 -0
  414. package/dist/utils/cn.js +5 -0
  415. package/dist/utils/format-date.d.ts +15 -0
  416. package/dist/utils/format-date.d.ts.map +1 -0
  417. package/dist/utils/format-date.js +37 -0
  418. package/dist/utils/mdast-to-html.d.ts +55 -0
  419. package/dist/utils/mdast-to-html.d.ts.map +1 -0
  420. package/dist/utils/mdast-to-html.js +206 -0
  421. package/dist/utils/mdast-tree.d.ts +104 -0
  422. package/dist/utils/mdast-tree.d.ts.map +1 -0
  423. package/dist/utils/mdast-tree.js +285 -0
  424. package/dist/utils/pageMetadata.d.ts +67 -0
  425. package/dist/utils/pageMetadata.d.ts.map +1 -0
  426. package/dist/utils/pageMetadata.js +161 -0
  427. package/dist/utils/slugify.d.ts +12 -0
  428. package/dist/utils/slugify.d.ts.map +1 -0
  429. package/dist/utils/slugify.js +17 -0
  430. package/dist/utils/zodIntrospect.d.ts +24 -0
  431. package/dist/utils/zodIntrospect.d.ts.map +1 -0
  432. package/dist/utils/zodIntrospect.js +88 -0
  433. package/package.json +153 -35
  434. package/styles/styles.css.d.ts +2 -0
  435. package/styles/tailwind-theme.css +126 -0
  436. package/styles/tailwind-theme.css.d.ts +2 -0
  437. package/dist/puck-CvjeYQRH.mjs +0 -1533
  438. package/dist/puck-CvjeYQRH.mjs.map +0 -1
@@ -0,0 +1,1067 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { NestedLexicalEditor, useLexicalNodeRemove, useMdastNodeUpdater, useNestedEditorContext, } from '@mdxeditor/editor';
3
+ import { $getNodeByKey } from 'lexical';
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
+ import { createPortal } from 'react-dom';
6
+ import { containsMarkdownMarkers, isJsxDescriptor, useMdxComponents, writeAttribute, } from '../../mdx-components';
7
+ import { getSelectedBlock, setSelectedBlock, useSelectedBlock } from '../../selected-block';
8
+ import { bodyNeedsStaticHtml, isHtmlTag, mdastToHtml } from '../../utils/mdast-to-html';
9
+ import { effectiveChildren, getMdastAtPath, getNamedSlotName, readAttrs, removeMdastNodeAtPath, replaceMdastAtPath, replaceMdastNodeAtPath, slotIdToPath, stripBodyFields, } from '../../utils/mdast-tree';
10
+ const SLOT_TAG = 'conloca-slot';
11
+ const RENDER_ENDPOINT = '/__cms/api/render';
12
+ /**
13
+ * Find string-prop values inside the SSR'd preview and make their rendering
14
+ * element directly editable. The author types in place; on blur the new
15
+ * value flows back through `onPropChange`, which routes through the same
16
+ * mdast updater the side panel uses — so a LinkCard's `description` can
17
+ * be edited inline OR in the side panel, both update the same source.
18
+ *
19
+ * Resolution is a conservative text-match heuristic: only leaf elements
20
+ * (no element children) whose `textContent.trim()` equals the prop value
21
+ * qualify, AND the match must be unique. If two elements happen to render
22
+ * the same string, or the value is too short to disambiguate (<3 chars),
23
+ * the prop falls back to side-panel-only editing. This avoids accidentally
24
+ * binding the wrong element when a value like "tip" coincides with body
25
+ * text or a CSS class.
26
+ *
27
+ * Commits land on blur (or Enter), not on keystroke — committing per-key
28
+ * would refire the render endpoint on every character and lose focus
29
+ * each time the new HTML replaces the wrapper.
30
+ *
31
+ * No registry opt-in for now; the uniqueness + length guards make the
32
+ * heuristic safe enough that "automatically inline-editable for components
33
+ * where it makes sense" matches the zero-config goal of the broader
34
+ * registry work.
35
+ */
36
+ function wireInlinePropEditors(wrap, attrs, onPropChange) {
37
+ for (const [propName, rawValue] of Object.entries(attrs)) {
38
+ if (typeof rawValue !== 'string')
39
+ continue;
40
+ const value = rawValue.trim();
41
+ if (value.length < 3)
42
+ continue;
43
+ // Skip markdown-bearing values. A `plaintext-only` contenteditable
44
+ // strips `**bold**` / inline code / link syntax on commit, so we
45
+ // route these props through the side panel instead. The author sees
46
+ // the raw string there and decides whether to keep the formatting.
47
+ // Conservative detection (see `containsMarkdownMarkers`) — false
48
+ // positive cost is "edit via panel" which is fine; false negative
49
+ // cost is silent formatting loss, which isn't.
50
+ if (containsMarkdownMarkers(value))
51
+ continue;
52
+ // Two parallel walks, combined for uniqueness. The element walk
53
+ // catches "value lives in a leaf span" cases (LinkCard's
54
+ // `<span class="description">`); the text-node walk catches "value
55
+ // is a text node sibling of an icon" cases (Aside's title sits
56
+ // inside `<p class="starlight-aside__title">` right next to an SVG).
57
+ // Total matches across both walks must equal 1 — otherwise we can't
58
+ // unambiguously bind the prop to a single rendering location and
59
+ // fall back to side-panel-only editing.
60
+ const elementMatches = [];
61
+ for (const el of Array.from(wrap.querySelectorAll('*'))) {
62
+ // Leaf-only — skip elements with element children, otherwise we'd
63
+ // turn an entire `<a class="sl-link-card">` into a contenteditable.
64
+ if (el.children.length > 0)
65
+ continue;
66
+ // Skip already-wired editors so re-renders don't double-bind.
67
+ if (el.hasAttribute('data-conloca-prop'))
68
+ continue;
69
+ if ((el.textContent ?? '').trim() === value)
70
+ elementMatches.push(el);
71
+ }
72
+ const textMatches = [];
73
+ const walker = wrap.ownerDocument.createTreeWalker(wrap, NodeFilter.SHOW_TEXT);
74
+ let textNode = walker.nextNode();
75
+ while (textNode) {
76
+ const t = textNode;
77
+ if (!t.parentElement)
78
+ continue;
79
+ // Don't double-count: a text node that is the sole content of a
80
+ // leaf element is already caught by the element walk above.
81
+ const parentIsLeaf = t.parentElement.children.length === 0;
82
+ if (parentIsLeaf)
83
+ continue;
84
+ // Skip text inside an already-wired inline editor.
85
+ if (t.parentElement.closest('[data-conloca-prop]'))
86
+ continue;
87
+ if ((t.nodeValue ?? '').trim() === value)
88
+ textMatches.push(t);
89
+ textNode = walker.nextNode();
90
+ }
91
+ if (elementMatches.length + textMatches.length !== 1)
92
+ continue;
93
+ // Resolve the actual target element. For text-node matches we wrap
94
+ // the value in a fresh span so we have something to attach
95
+ // contenteditable to. Surrounding whitespace stays as plain text
96
+ // nodes either side of the span, so the icon→text spacing the host
97
+ // designed for is preserved.
98
+ let target;
99
+ if (elementMatches.length === 1) {
100
+ target = elementMatches[0];
101
+ }
102
+ else {
103
+ const t = textMatches[0];
104
+ const original = t.nodeValue ?? '';
105
+ const idx = original.indexOf(value);
106
+ const before = idx > 0 ? original.slice(0, idx) : '';
107
+ const after = idx + value.length < original.length ? original.slice(idx + value.length) : '';
108
+ const span = wrap.ownerDocument.createElement('span');
109
+ span.textContent = value;
110
+ const parent = t.parentNode;
111
+ if (before)
112
+ parent.insertBefore(wrap.ownerDocument.createTextNode(before), t);
113
+ parent.insertBefore(span, t);
114
+ if (after)
115
+ parent.insertBefore(wrap.ownerDocument.createTextNode(after), t);
116
+ parent.removeChild(t);
117
+ target = span;
118
+ }
119
+ bindInlinePropEditor(target, propName, onPropChange);
120
+ }
121
+ }
122
+ /**
123
+ * Attach the inline-prop event listeners to a target element. Pulled
124
+ * out of `wireInlinePropEditors` so both the selector-driven path
125
+ * (defaults like Aside's auto-derived "Note" title) and the text-match
126
+ * path (explicit prop values that render as visible text) share the
127
+ * same wiring code — contenteditable attribute, focus override against
128
+ * stretched-link anchors, Enter/Escape semantics, and the blur commit
129
+ * that flows back through `onPropChange`.
130
+ */
131
+ function bindInlinePropEditor(target, propName, onPropChange) {
132
+ // `plaintext-only` keeps the contenteditable from accepting rich
133
+ // formatting (bold, italic, pasted markup). String props are flat
134
+ // text — bolding inside one would silently lose the styling on
135
+ // save anyway, so the affordance shouldn't suggest otherwise.
136
+ target.setAttribute('contenteditable', 'plaintext-only');
137
+ target.setAttribute('data-conloca-prop', propName);
138
+ target.setAttribute('spellcheck', 'true');
139
+ // Small visual cue so the author can tell which inline regions
140
+ // accept editing. Faint outline-color on hover, no layout shift.
141
+ target.classList.add('conloca-inline-prop');
142
+ let committed = (target.textContent ?? '').trim();
143
+ const commit = () => {
144
+ const next = (target.textContent ?? '').trim();
145
+ if (next !== committed) {
146
+ committed = next;
147
+ onPropChange(propName, next);
148
+ }
149
+ };
150
+ target.addEventListener('blur', commit);
151
+ target.addEventListener('keydown', (e) => {
152
+ // Enter commits (string props are single-line); Escape reverts.
153
+ if (e.key === 'Enter') {
154
+ e.preventDefault();
155
+ target.blur();
156
+ }
157
+ else if (e.key === 'Escape') {
158
+ e.preventDefault();
159
+ target.textContent = committed;
160
+ target.blur();
161
+ }
162
+ });
163
+ // Anchor-parent focus override. When the inline-editable element sits
164
+ // inside a clickable anchor (Starlight's `<LinkCard>` wraps title +
165
+ // description in a single `<a>`), the browser's default mousedown
166
+ // focuses the anchor, not our contenteditable child. Override by
167
+ // calling preventDefault() to stop the anchor's default focus, then
168
+ // explicitly focus the contenteditable and place the caret at the
169
+ // click point. `stopPropagation` is intentionally NOT used — the
170
+ // parent block's mousedownCapture still needs to fire so the side
171
+ // panel updates with this block's props.
172
+ target.addEventListener('mousedown', (e) => {
173
+ e.preventDefault();
174
+ target.focus();
175
+ // `caretPositionFromPoint` is the spec API; WebKit/older Chromium
176
+ // ship `caretRangeFromPoint` instead. Try both, fall back to the
177
+ // end of the text if neither works.
178
+ const doc = target.ownerDocument;
179
+ let range = null;
180
+ const cp = doc.caretPositionFromPoint;
181
+ if (cp) {
182
+ const pos = cp.call(doc, e.clientX, e.clientY);
183
+ if (pos) {
184
+ range = doc.createRange();
185
+ range.setStart(pos.offsetNode, pos.offset);
186
+ range.collapse(true);
187
+ }
188
+ }
189
+ else if (doc.caretRangeFromPoint) {
190
+ range = doc.caretRangeFromPoint(e.clientX, e.clientY);
191
+ }
192
+ if (!range) {
193
+ range = doc.createRange();
194
+ range.selectNodeContents(target);
195
+ range.collapse(false);
196
+ }
197
+ const sel = doc.defaultView?.getSelection();
198
+ if (sel) {
199
+ sel.removeAllRanges();
200
+ sel.addRange(range);
201
+ }
202
+ });
203
+ }
204
+ /**
205
+ * Activate the tab the author clicked on inside an SSR'd `<starlight-tabs>`
206
+ * preview. Mirrors what `<starlight-tabs>`'s connectedCallback does at
207
+ * runtime on the published page — toggling `aria-selected` on the trigger
208
+ * and the `hidden` attribute on the matching panel — but runs purely off
209
+ * the DOM we already SSR'd, so the editor doesn't need to load the host's
210
+ * tab script.
211
+ *
212
+ * Starlight's tab markup ([starlight-tabs] > [role=tablist] > a[role=tab]
213
+ * with `href="#tab-panel-N"`, and `<section role="tabpanel" id="...">`
214
+ * siblings of the tablist) is stable enough that this resolves by
215
+ * traversing roles + the href hash. If Starlight ever ships a different
216
+ * variant the resolution falls back to no-op, which is the same as the
217
+ * pre-fix behaviour.
218
+ */
219
+ function activateTabInPlace(tab) {
220
+ const tablist = tab.closest('[role="tablist"]');
221
+ // The panels live as siblings of the tablist inside the same custom
222
+ // element (or inside a generic ancestor if Starlight changes shape).
223
+ const tabsRoot = tab.closest('starlight-tabs') ?? tablist?.parentElement ?? null;
224
+ if (!tablist || !tabsRoot)
225
+ return;
226
+ // Deselect every trigger in this tablist; tabindex=-1 keeps keyboard
227
+ // focus order matching Starlight's runtime behaviour.
228
+ for (const t of tablist.querySelectorAll('[role="tab"]')) {
229
+ t.setAttribute('aria-selected', 'false');
230
+ t.setAttribute('tabindex', '-1');
231
+ }
232
+ tab.setAttribute('aria-selected', 'true');
233
+ tab.setAttribute('tabindex', '0');
234
+ // Resolve target panel via the trigger's `href="#id"`. Falls back to
235
+ // positional match if href is missing — covers future Starlight shapes
236
+ // that wire via aria-controls or index.
237
+ const href = tab.getAttribute('href') || '';
238
+ const targetId = href.startsWith('#') ? href.slice(1) : '';
239
+ const panels = Array.from(tabsRoot.querySelectorAll('[role="tabpanel"]'));
240
+ let activeIndex = -1;
241
+ if (targetId) {
242
+ activeIndex = panels.findIndex((p) => p.id === targetId);
243
+ }
244
+ if (activeIndex < 0) {
245
+ const triggers = Array.from(tablist.querySelectorAll('[role="tab"]'));
246
+ activeIndex = triggers.indexOf(tab);
247
+ }
248
+ panels.forEach((p, i) => {
249
+ if (i === activeIndex)
250
+ p.removeAttribute('hidden');
251
+ else
252
+ p.setAttribute('hidden', '');
253
+ });
254
+ }
255
+ /**
256
+ * In-memory cache of rendered HTML keyed by the full tree shape +
257
+ * document index. Same edit state reuses cached HTML without a server
258
+ * roundtrip. Cleared on page reload.
259
+ */
260
+ const renderCache = new Map();
261
+ function cacheKey(req) {
262
+ return `${req.documentIndex}::${req.inline ? 'inline::' : ''}${stableStringify(stripBodyFields(req.tree))}`;
263
+ }
264
+ function stableStringify(obj) {
265
+ // Stable across key order so attribute reordering doesn't bust the cache.
266
+ // For nested objects/arrays (children trees) JSON.stringify already
267
+ // preserves array order which is what we want.
268
+ const sort = (v) => {
269
+ if (Array.isArray(v))
270
+ return v.map(sort);
271
+ if (v && typeof v === 'object') {
272
+ const keys = Object.keys(v).sort();
273
+ return Object.fromEntries(keys.map((k) => [k, sort(v[k])]));
274
+ }
275
+ return v;
276
+ };
277
+ return JSON.stringify(sort(obj));
278
+ }
279
+ async function fetchRendered(req) {
280
+ const key = cacheKey(req);
281
+ const cached = renderCache.get(key);
282
+ if (cached !== undefined)
283
+ return cached;
284
+ const res = await fetch(RENDER_ENDPOINT, {
285
+ method: 'POST',
286
+ headers: { 'content-type': 'application/json' },
287
+ body: JSON.stringify(req),
288
+ });
289
+ if (!res.ok)
290
+ throw new Error(`Render endpoint returned ${res.status}: ${await res.text()}`);
291
+ const html = await res.text();
292
+ renderCache.set(key, html);
293
+ return html;
294
+ }
295
+ /**
296
+ * Given a child slot element inside a container's SSR'd preview,
297
+ * return the DOM subtree that belongs to ONLY this child. Used to
298
+ * bound the inline-prop scan so we don't accidentally match a
299
+ * sibling child's title.
300
+ *
301
+ * Heuristic: walk up from the slot. Each ancestor is a candidate.
302
+ * We keep walking as long as the parent of the ancestor contains
303
+ * exactly one slot-with-data-slot-id descendant (this slot). The
304
+ * moment we'd step into an ancestor whose subtree contains MORE
305
+ * than one slot — that's the boundary between children — we stop
306
+ * and return the last single-slot ancestor.
307
+ *
308
+ * For Starlight CardGrid the result is the `<article class="card">`
309
+ * for each child. For a future framework that wraps each child
310
+ * differently the same logic applies — we don't care about the
311
+ * specific class names.
312
+ *
313
+ * Returns `null` if the slot isn't actually inside a container with
314
+ * sibling slots (eg edge cases where the framework only emits one
315
+ * child). The caller falls back to wiring against the whole wrapper.
316
+ */
317
+ function findChildRegion(slot) {
318
+ let region = slot;
319
+ let parent = slot.parentElement;
320
+ while (parent) {
321
+ const slotCount = parent.querySelectorAll(`${SLOT_TAG}[data-slot-id]`).length;
322
+ if (slotCount > 1) {
323
+ // Parent encloses more than one child — region is the current
324
+ // node (before stepping into the multi-child container).
325
+ return region === slot ? null : region;
326
+ }
327
+ region = parent;
328
+ parent = parent.parentElement;
329
+ }
330
+ return region === slot ? null : region;
331
+ }
332
+ /**
333
+ * Find the first mdast `list` node inside a component's effective
334
+ * children. Returns both the list and the path that `getMdastAtPath`
335
+ * would walk to reach it. `null` when no list is present at the top
336
+ * level — eg a regular Aside body where children are paragraphs.
337
+ *
338
+ * Handles two common shapes:
339
+ * 1. `{ name: 'Steps', children: [list] }` — path: `[0]`
340
+ * 2. `{ name: 'Steps', children: [{paragraph, children:[list]}] }`
341
+ * — `effectiveChildren` unwraps the single-paragraph wrapper, so
342
+ * the list is still reached at path `[0]`.
343
+ *
344
+ * Restricted to "first child is a list" because that's the strict-
345
+ * slot list pattern (Steps, FileTree). A Card body that happens to
346
+ * contain a list as a non-leading child stays in the regular slot
347
+ * path — those have a real `<conloca-slot>` from the server already.
348
+ */
349
+ function findTopLevelList(node) {
350
+ const effective = effectiveChildren(node);
351
+ if (effective.length === 0)
352
+ return null;
353
+ const first = effective[0];
354
+ if (first?.type !== 'list' || !Array.isArray(first.children))
355
+ return null;
356
+ return { list: first, path: [0] };
357
+ }
358
+ /**
359
+ * Wire each `<li>` of the first ordered/unordered list in the
360
+ * rendered preview as a contenteditable, with on-blur commit that
361
+ * rewrites the corresponding mdast `listItem`. Used for strict-slot
362
+ * list components (Starlight `<Steps>`, `<FileTree>`) where the
363
+ * framework rejects `<conloca-slot>` children — we can't portal a
364
+ * Lexical editor into them, so we edit the rendered HTML in place.
365
+ *
366
+ * Trade-off vs the portal path: this loses any inline formatting on
367
+ * commit (the blur handler reads `textContent` and rewrites the item
368
+ * as plain text). The rendered output keeps whatever formatting the
369
+ * framework SSR'd (bold survives across renders that don't touch the
370
+ * item), but typing in a step replaces its content with plaintext.
371
+ * For step descriptions and file-tree labels that's usually fine; for
372
+ * heavily-formatted lists the user has to edit through markdown.
373
+ *
374
+ * DOM mutation safety: we DO NOT replace the li's children or inject
375
+ * anything React might reconcile against. Just set `contenteditable`
376
+ * on the existing element and attach listeners. The next render's
377
+ * `wrap.innerHTML = html` wipes the contenteditable cleanly.
378
+ */
379
+ function wireListItemEditors(wrap, node, updater, pendingFocusIndexRef) {
380
+ const found = findTopLevelList(node);
381
+ if (!found)
382
+ return;
383
+ const domList = wrap.querySelector('ol, ul');
384
+ if (!domList)
385
+ return;
386
+ const domItems = Array.from(domList.children).filter((c) => c.tagName === 'LI');
387
+ if (domItems.length !== found.list.children.length)
388
+ return;
389
+ // Default-deny tree-shaped lists. A flat plaintext editor over an
390
+ // `<li>` that contains a nested `<ul>`/`<ol>` would collapse the
391
+ // sub-tree into a single text node on commit. FileTree is the
392
+ // canonical case, but the same trap applies to any nav-menu /
393
+ // outline / nested-list component. The side panel still works;
394
+ // authors who need to restructure the tree edit the raw MDX.
395
+ // Future: a proper tree-aware editor can ship as a follow-up that
396
+ // handles recursive wiring, path-scoped writes, and add/remove
397
+ // affordances for sub-items.
398
+ if (domItems.some((li) => li.querySelector('ul, ol') !== null))
399
+ return;
400
+ const listOrdered = found.list.ordered ?? false;
401
+ /**
402
+ * Shared helper that writes a new list of items back through the
403
+ * mdast updater, preserving the paragraph-wrap shape if any. All
404
+ * commit / insert / remove paths funnel through this so the
405
+ * write-side logic stays in one place.
406
+ */
407
+ const writeListChildren = (newListChildren) => {
408
+ const newList = { type: 'list', ordered: listOrdered, children: newListChildren };
409
+ const originalKids = (node.children ?? []);
410
+ const isWrapped = originalKids.length === 1 && originalKids[0]?.type === 'paragraph';
411
+ const newChildren = isWrapped ? [{ ...originalKids[0], children: [newList] }] : [newList];
412
+ updater({ children: newChildren });
413
+ };
414
+ const buildListItem = (text) => ({
415
+ type: 'listItem',
416
+ children: [{ type: 'paragraph', children: [{ type: 'text', value: text }] }],
417
+ });
418
+ for (let i = 0; i < domItems.length; i++) {
419
+ const li = domItems[i];
420
+ // Skip already-wired editors so re-renders don't double-bind.
421
+ if (li.hasAttribute('data-conloca-listitem'))
422
+ continue;
423
+ li.setAttribute('data-conloca-listitem', String(i));
424
+ li.setAttribute('contenteditable', 'plaintext-only');
425
+ li.classList.add('conloca-listitem');
426
+ let committed = (li.textContent ?? '').trim();
427
+ const itemIndex = i;
428
+ const commit = () => {
429
+ const next = (li.textContent ?? '').trim();
430
+ if (next === committed)
431
+ return;
432
+ committed = next;
433
+ // Build a fresh listItem with a single paragraph of plain text.
434
+ // Future enhancement: parse inline markdown so `**bold**` round-
435
+ // trips correctly. For now, plaintext-only matches the editing
436
+ // affordance authors see (no formatting toolbar in the li).
437
+ const newListChildren = found.list.children.map((it, idx) => (idx === itemIndex ? buildListItem(next) : it));
438
+ writeListChildren(newListChildren);
439
+ };
440
+ /**
441
+ * Insert an empty list item BELOW this one and ask the next
442
+ * render to focus the new li. The render cycle is:
443
+ * 1. writeListChildren → mdast updates → React re-renders
444
+ * 2. html-injection effect runs `wrap.innerHTML = html`
445
+ * 3. wireListItemEditors runs again; it sees the pending
446
+ * focus index and focuses that li.
447
+ * The ref decouples the focus request from the render — we
448
+ * can't focus the new li synchronously because it doesn't
449
+ * exist in the DOM yet.
450
+ */
451
+ const insertItemBelow = () => {
452
+ // Commit current text first so we don't lose any unsaved
453
+ // typing in this li. `commit` is a no-op if nothing changed.
454
+ const currentText = (li.textContent ?? '').trim();
455
+ const updatedCurrent = buildListItem(currentText);
456
+ const newListChildren = [
457
+ ...found.list.children.slice(0, itemIndex),
458
+ updatedCurrent,
459
+ buildListItem(''),
460
+ ...found.list.children.slice(itemIndex + 1),
461
+ ];
462
+ pendingFocusIndexRef.current = itemIndex + 1;
463
+ writeListChildren(newListChildren);
464
+ };
465
+ /**
466
+ * Remove this list item from the list. Used when the author
467
+ * presses Backspace at the start of an already-empty step. If
468
+ * removing would leave the list empty we leave one empty item
469
+ * — Starlight's `<Steps>` rejects an empty `<ol>` and the
470
+ * author probably wants to keep editing.
471
+ */
472
+ const removeSelf = () => {
473
+ if (found.list.children.length <= 1)
474
+ return;
475
+ const newListChildren = found.list.children.filter((_, idx) => idx !== itemIndex);
476
+ // Focus the previous item after re-render (or the new first
477
+ // item if we removed the head).
478
+ pendingFocusIndexRef.current = Math.max(0, itemIndex - 1);
479
+ writeListChildren(newListChildren);
480
+ };
481
+ li.addEventListener('blur', commit);
482
+ li.addEventListener('keydown', (e) => {
483
+ if (e.key === 'Enter' && !e.shiftKey) {
484
+ // Enter splits the list: commit current text, append a new
485
+ // empty item below, focus it. Standard list-editor pattern
486
+ // (Notion, Bear, native markdown editors).
487
+ e.preventDefault();
488
+ insertItemBelow();
489
+ }
490
+ else if (e.key === 'Backspace') {
491
+ // Backspace at the start of an empty item removes the item.
492
+ // Anywhere else: default delete-character behaviour.
493
+ const text = (li.textContent ?? '').trim();
494
+ if (text.length === 0) {
495
+ e.preventDefault();
496
+ removeSelf();
497
+ }
498
+ }
499
+ else if (e.key === 'Escape') {
500
+ e.preventDefault();
501
+ li.textContent = committed;
502
+ li.blur();
503
+ }
504
+ });
505
+ }
506
+ // After every re-wire pass, honor any pending focus request from
507
+ // the previous render's keyboard handler. This is what makes Enter
508
+ // / Backspace feel responsive — the new li appears AND gets the
509
+ // caret in one perceived action.
510
+ if (pendingFocusIndexRef.current !== null) {
511
+ const targetIdx = pendingFocusIndexRef.current;
512
+ pendingFocusIndexRef.current = null;
513
+ const target = domItems[targetIdx];
514
+ if (target) {
515
+ // Defer to next microtask so any in-flight focus management
516
+ // (Lexical refocus after the discrete update) settles first.
517
+ Promise.resolve().then(() => {
518
+ target.focus();
519
+ // Place caret at start for the freshly-inserted empty item.
520
+ const range = target.ownerDocument.createRange();
521
+ range.selectNodeContents(target);
522
+ range.collapse(true);
523
+ const sel = target.ownerDocument.defaultView?.getSelection();
524
+ if (sel) {
525
+ sel.removeAllRanges();
526
+ sel.addRange(range);
527
+ }
528
+ });
529
+ }
530
+ }
531
+ }
532
+ /**
533
+ * Walk the mdast subtree starting at `node` and build the render-tree
534
+ * payload. Children that are JSX elements (flow OR text — MDX parses
535
+ * inline-written JSX as text variants) with a registered descriptor
536
+ * are recursed into; anything else terminates the recursion and the
537
+ * parent ends up with a single body slot like a leaf would.
538
+ *
539
+ * `isRoot=true` means this is the top-level node the caller will
540
+ * portal a Lexical editor into. We skip the static text fallback on
541
+ * the root so the portal isn't stacked on top of duplicate text —
542
+ * the editor itself owns the body content for the root. Nested
543
+ * leaves (children inside a container) DO get the fallback, since
544
+ * they aren't being portaled into yet (Phase 3).
545
+ */
546
+ function buildRenderTree(node, descriptors, slotIdPrefix, isRoot = false) {
547
+ const name = node.name ?? '';
548
+ const desc = descriptors.find((d) => 'name' in d && d.name === name);
549
+ const jsxDesc = desc && isJsxDescriptor(desc) ? desc : null;
550
+ const source = jsxDesc?.import?.from;
551
+ if (!source)
552
+ return null;
553
+ const allKids = effectiveChildren(node);
554
+ // Extract `<Fragment slot="name">…</Fragment>` children into a
555
+ // namedSlots map and continue body processing with the remaining
556
+ // (default-slot) children only. This is the Astro convention for
557
+ // multi-slot components like `<Layout>` or `<Hero>`.
558
+ const namedSlots = {};
559
+ const kids = [];
560
+ for (const child of allKids) {
561
+ const slot = getNamedSlotName(child);
562
+ if (slot) {
563
+ const inner = child.children;
564
+ namedSlots[slot] = mdastToHtml({ children: Array.isArray(inner) ? inner : [] });
565
+ }
566
+ else {
567
+ kids.push(child);
568
+ }
569
+ }
570
+ const children = [];
571
+ let hasJsxChildren = false;
572
+ for (let i = 0; i < kids.length; i++) {
573
+ const child = kids[i];
574
+ if (child?.type === 'mdxJsxFlowElement' || child?.type === 'mdxJsxTextElement') {
575
+ const childTree = buildRenderTree(child, descriptors, `${slotIdPrefix}.${i}`);
576
+ if (childTree) {
577
+ children.push(childTree);
578
+ hasJsxChildren = true;
579
+ }
580
+ }
581
+ }
582
+ // If the body is a markdown list (Steps/FileTree), render it as
583
+ // raw HTML — those components' Astro implementations validate the
584
+ // slot tag name and reject `<conloca-slot>`. `bodyHtml` makes the
585
+ // server emit our rendered list directly as the slot content with
586
+ // no wrapper.
587
+ const bodyHtml = !hasJsxChildren && bodyNeedsStaticHtml(kids) ? mdastToHtml({ children: kids }) : undefined;
588
+ // Previously, nested leaves shipped a static-text `body` fallback
589
+ // inside their slot so authored text was visible even without an
590
+ // inline editor — back when only the root slot got a Lexical
591
+ // portal. Every container child now gets its own `ContainerSlotEditor`
592
+ // portaled in (see `GenericBlock`), so the slot's owner is always
593
+ // an editor. Emitting `body` here would render the same text twice:
594
+ // once as static text from the SSR'd slot, once via the portaled
595
+ // editor's contentEditable. Always omit.
596
+ const body = undefined;
597
+ return {
598
+ component: name,
599
+ source,
600
+ defaultExport: jsxDesc?.import?.default ?? false,
601
+ props: readAttrs(node),
602
+ slotId: slotIdPrefix,
603
+ ...(hasJsxChildren ? { children } : {}),
604
+ ...(body ? { body } : {}),
605
+ ...(bodyHtml ? { bodyHtml } : {}),
606
+ ...(Object.keys(namedSlots).length > 0 ? { namedSlots } : {}),
607
+ };
608
+ }
609
+ /**
610
+ * True when every non-trivial child of `node` is itself a JSX element
611
+ * (flow or text variant). This is the "container" case (CardGrid with
612
+ * Cards inside, Tabs with TabItems). Text-bearing or mixed children
613
+ * fall through to leaf rendering with one body slot.
614
+ */
615
+ function isPureContainer(node) {
616
+ const allKids = effectiveChildren(node);
617
+ if (allKids.length === 0)
618
+ return false;
619
+ // Ignore named-slot Fragments — they're passed as separate slots,
620
+ // not part of the default-body container detection.
621
+ const kids = allKids.filter((k) => getNamedSlotName(k) == null);
622
+ if (kids.length === 0)
623
+ return false;
624
+ let sawJsx = false;
625
+ for (const child of kids) {
626
+ const c = child;
627
+ if (!c || typeof c !== 'object')
628
+ continue;
629
+ if (c.type === 'mdxJsxFlowElement' || c.type === 'mdxJsxTextElement') {
630
+ sawJsx = true;
631
+ continue;
632
+ }
633
+ // Permit pure-whitespace text nodes between block JSX.
634
+ if (c.type === 'text' && typeof c.value === 'string' && c.value.trim() === '')
635
+ continue;
636
+ return false;
637
+ }
638
+ return sawJsx;
639
+ }
640
+ /**
641
+ * One nested editor scoped to a single child inside a container's
642
+ * render-tree. The parent's MDXEditor `JsxNode` owns the WHOLE mdast
643
+ * subtree (CardGrid + its Cards + grandchildren) as one opaque blob;
644
+ * we can't give each child its own Lexical node within the library's
645
+ * data model. Instead, this component sits inside the parent's JsxEditor
646
+ * context (via `<NestedLexicalEditor>`) and uses `getContent` /
647
+ * `getUpdatedMdastNode` to read and write a SPECIFIC child by mdast
648
+ * path. The same `effectiveChildren` unwrap that buildRenderTree did
649
+ * on read is mirrored in the write helper so the original tree shape
650
+ * round-trips on save.
651
+ *
652
+ * Concurrency caveat: when two `ContainerSlotEditor` instances inside
653
+ * the same parent both fire `getUpdatedMdastNode`, each sees the
654
+ * parent snapshot captured by `useMdastNodeUpdater` at its render
655
+ * time. MDXEditor's `discrete: true` update path makes the parent
656
+ * commit synchronously between blurs and React re-renders before
657
+ * the next blur could fire, so blur-driven prose edits are safe. The
658
+ * race exists only for non-blur updates (codemirror's
659
+ * `NESTED_EDITOR_UPDATED_COMMAND` while still focused) — vanishingly
660
+ * rare in container-child editing today.
661
+ */
662
+ function ContainerSlotEditor({ path }) {
663
+ return (_jsx(NestedLexicalEditor, { getContent: (parent) => {
664
+ const target = getMdastAtPath(parent, path);
665
+ return target?.children ?? [];
666
+ }, getUpdatedMdastNode: (parent, newChildren) => replaceMdastAtPath(parent, path, newChildren) }));
667
+ }
668
+ export function GenericBlock({ mdastNode }) {
669
+ const updater = useMdastNodeUpdater();
670
+ const removeNode = useLexicalNodeRemove();
671
+ const descriptors = useMdxComponents();
672
+ const { parentEditor, lexicalNode } = useNestedEditorContext();
673
+ const node = mdastNode;
674
+ const attrs = readAttrs(node);
675
+ const name = node.name ?? '';
676
+ const found = descriptors.find((d) => 'name' in d && d.name === name);
677
+ const descriptor = found && isJsxDescriptor(found) ? found : null;
678
+ const source = descriptor?.import?.from;
679
+ // Inline (text-kind) components — `<Icon>`, anything rendered as
680
+ // `mdxJsxTextElement` — sit inside a paragraph's text flow and must
681
+ // NOT carry block wrappers. The phantom-sibling / `sl-markdown-content`
682
+ // path only makes sense for root-level flow blocks (Card colour
683
+ // cycle, CSS-grid placement); for inline elements it would force a
684
+ // line break and stack hidden siblings around the glyph.
685
+ const isInline = descriptor?.kind === 'text';
686
+ // This block's 1-based position among Lexical's root-level children.
687
+ // Passed to the render endpoint so it can prepend phantom siblings and
688
+ // restore the same `:nth-child(N)` position the live page would have.
689
+ // Subscribes to the parent editor so the index updates when the user
690
+ // adds, deletes, or reorders blocks above this one. Inline components
691
+ // skip this entirely — they aren't root children.
692
+ const [documentIndex, setDocumentIndex] = useState(1);
693
+ useEffect(() => {
694
+ if (isInline)
695
+ return;
696
+ const computeIndex = () => {
697
+ parentEditor.getEditorState().read(() => {
698
+ const me = $getNodeByKey(lexicalNode.getKey());
699
+ // Walk up to the root-level child (a JSX block lives inside a
700
+ // Lexical paragraph; the paragraph is the root's direct child).
701
+ let cursor = me;
702
+ while (cursor && cursor.getParent() && cursor.getParent()?.getParent() !== null) {
703
+ cursor = cursor.getParent();
704
+ }
705
+ const root = cursor?.getParent();
706
+ if (root && cursor) {
707
+ const idx = root.getChildren().indexOf(cursor);
708
+ if (idx >= 0)
709
+ setDocumentIndex(idx + 1);
710
+ }
711
+ });
712
+ };
713
+ computeIndex();
714
+ return parentEditor.registerUpdateListener(computeIndex);
715
+ }, [parentEditor, lexicalNode, isInline]);
716
+ // Container mode: when all of this node's children are themselves
717
+ // JSX flow elements with known descriptors, we render the whole
718
+ // subtree in one server call so the children emerge as real DOM
719
+ // siblings of their parent (vs. each child rendering in its own
720
+ // wrapper). This fixes CSS grid layout and positional CSS for
721
+ // components like CardGrid and Tabs whose children must be direct
722
+ // DOM children of the container.
723
+ const containerMode = isPureContainer(node);
724
+ // Build the full render-tree payload. For leaves this is one node
725
+ // with a `<conloca-slot>` body slot. For containers it recurses
726
+ // into children. `tree` is null when we lack an import source for
727
+ // the root component — the fallback wrapper handles that path.
728
+ const tree = useMemo(() => buildRenderTree(node, descriptors, 'root', true),
729
+ // mdast attrs/children are regenerated on every render but
730
+ // structurally stable, so we use stableStringify in cacheKey to
731
+ // dedupe identical requests. Recomputing the tree per render is
732
+ // cheap.
733
+ // biome-ignore lint/correctness/useExhaustiveDependencies: descriptors identity changes every render
734
+ [node, descriptors]);
735
+ const propsJson = useMemo(() => stableStringify(attrs), [attrs]);
736
+ // biome-ignore lint/correctness/useExhaustiveDependencies: propsJson is the stable attrs signal
737
+ const renderReq = useMemo(() => (tree ? { tree, documentIndex, ...(isInline ? { inline: true } : {}) } : null), [tree, documentIndex, propsJson, isInline]);
738
+ const [html, setHtml] = useState(() => renderReq ? (renderCache.get(cacheKey(renderReq)) ?? null) : null);
739
+ const [error, setError] = useState(null);
740
+ const wrapperRef = useRef(null);
741
+ const [slotEl, setSlotEl] = useState(null);
742
+ /** Container-mode slots: slot-id → element. Each entry portals a
743
+ * `<ContainerSlotEditor>` into that element so every child's body
744
+ * is inline-editable, even when N children share one SSR'd wrapper. */
745
+ const [containerSlots, setContainerSlots] = useState(() => new Map());
746
+ /** Index of a list item that should receive focus after the next
747
+ * render commits. Set by the Enter / Backspace handlers in
748
+ * `wireListItemEditors`; consumed by the same function on the
749
+ * next re-wire pass. Lives at component level (not effect-local)
750
+ * so it survives across render cycles. */
751
+ const pendingListItemFocusRef = useRef(null);
752
+ // Fetch (or serve from cache) the rendered HTML on prop changes.
753
+ useEffect(() => {
754
+ if (!renderReq)
755
+ return;
756
+ let cancelled = false;
757
+ setError(null);
758
+ fetchRendered(renderReq)
759
+ .then((next) => {
760
+ if (!cancelled)
761
+ setHtml(next);
762
+ })
763
+ .catch((err) => {
764
+ if (cancelled)
765
+ return;
766
+ setError(err instanceof Error ? err.message : String(err));
767
+ console.warn('[Conloca] GenericBlock render failed:', err);
768
+ });
769
+ return () => {
770
+ cancelled = true;
771
+ };
772
+ }, [renderReq]);
773
+ // Imperatively swap the wrapper's inner HTML when the rendered
774
+ // string changes, then locate every body slot in the SSR'd markup.
775
+ //
776
+ // Leaf mode: one `<conloca-slot>` at the root, portaled with a
777
+ // single `<NestedLexicalEditor>` for the component's body.
778
+ //
779
+ // Container mode: each child JSX node also emits a slot (carrying
780
+ // its `data-slot-id` from the buildRenderTree path). Each gets its
781
+ // own portaled `<ContainerSlotEditor>` scoped to that child's mdast
782
+ // subtree via path resolution — so editing the body of a Card
783
+ // inside a CardGrid works the same as editing the body of a
784
+ // root-level Aside.
785
+ // biome-ignore lint/correctness/useExhaustiveDependencies: attrs/onPropChange deliberately omitted — see comment in effect
786
+ useEffect(() => {
787
+ const wrap = wrapperRef.current;
788
+ if (!wrap || html == null)
789
+ return;
790
+ wrap.innerHTML = html;
791
+ // After replacing the preview HTML, scan for string-prop values that
792
+ // appear exactly once as a leaf element's textContent and wire those
793
+ // elements as contenteditable. Authors edit eg LinkCard's `description`
794
+ // in place; the blur handler commits via `onPropChange`. Runs after
795
+ // every prop change because the new HTML wipes prior contenteditable
796
+ // attributes — re-wiring keeps inline editing alive across re-renders.
797
+ wireInlinePropEditors(wrap, attrs, onPropChange);
798
+ if (containerMode) {
799
+ // Multiple slots — discover them all and key by slot-id so the
800
+ // path resolution in `ContainerSlotEditor` can find the right
801
+ // mdast subtree to edit.
802
+ const next = new Map();
803
+ const slotEls = wrap.querySelectorAll(`${SLOT_TAG}[data-slot-id]`);
804
+ for (const el of Array.from(slotEls)) {
805
+ const slotId = el.getAttribute('data-slot-id');
806
+ if (slotId)
807
+ next.set(slotId, el);
808
+ }
809
+ setContainerSlots(next);
810
+ setSlotEl(null);
811
+ // Per-child inline-prop wiring. The container's own
812
+ // `wireInlinePropEditors` call above only matches against the
813
+ // container's props (eg CardGrid's `stagger`) — child Cards'
814
+ // `title` and `icon` values are skipped because the matcher
815
+ // doesn't know they belong to a child. For each child slot
816
+ // we find the enclosing region (the DOM subtree the framework
817
+ // rendered for that one child), then run the matcher against
818
+ // the child's own attrs with a child-scoped `onPropChange` that
819
+ // routes through `replaceMdastNodeAtPath`. This is what lets
820
+ // the author click "First card" inside a CardGrid and edit it.
821
+ for (const [slotId, slotEl] of next) {
822
+ const childPath = slotIdToPath(slotId);
823
+ const childNode = getMdastAtPath(node, childPath);
824
+ if (!childNode)
825
+ continue;
826
+ const region = findChildRegion(slotEl);
827
+ if (!region)
828
+ continue;
829
+ // Tag the child's enclosing region with its path so the
830
+ // wrapper-level mousedown/focus handler (`handleSelect`) can
831
+ // resolve which child a click landed in. The slot-id walk
832
+ // alone isn't enough — clicks on a child's title or icon
833
+ // (which sit OUTSIDE the slot) wouldn't find a slot ancestor
834
+ // via `closest`. This attribute IS a child ancestor in those
835
+ // cases, so `closest('[data-conloca-child-path]')` lands on
836
+ // the right region.
837
+ region.setAttribute('data-conloca-child-path', slotId);
838
+ const childAttrs = readAttrs(childNode);
839
+ const childOnPropChange = (propName, value) => {
840
+ const newChild = {
841
+ ...childNode,
842
+ attributes: writeAttribute(childNode.attributes, propName, value),
843
+ };
844
+ const nextRoot = replaceMdastNodeAtPath(node, childPath, newChild);
845
+ updater({ children: nextRoot.children });
846
+ };
847
+ wireInlinePropEditors(region, childAttrs, childOnPropChange);
848
+ }
849
+ }
850
+ else {
851
+ // Not a JSX container (so `containerMode` is false). But the
852
+ // mdast might still be a list-based strict-slot component (Steps,
853
+ // FileTree, anything else whose framework component validates
854
+ // its slot as a real `<ol>` / `<ul>` and rejects `<conloca-slot>`
855
+ // children). For those, we wire each `<li>` as a contenteditable
856
+ // with on-blur commit — no DOM mutation, no portal collision
857
+ // with React. Trade-off: plaintext-only commits (loses bold/
858
+ // italic on edit). Future enhancement: parse inline markdown
859
+ // back from contenteditable text so formatting round-trips.
860
+ wireListItemEditors(wrap, node, updater, pendingListItemFocusRef);
861
+ setContainerSlots(new Map());
862
+ setSlotEl(wrap.querySelector(SLOT_TAG));
863
+ }
864
+ // `attrs` and `onPropChange` are NOT in deps on purpose. They get a
865
+ // fresh identity on every render (new object from `readAttrs`, new
866
+ // callback closure), so listing them would re-run this effect for
867
+ // every parent render — including selection-change re-renders that
868
+ // don't actually touch the preview HTML. That would re-set
869
+ // `innerHTML` mid-typing and trash the contenteditable's focus.
870
+ // The effect already runs whenever `html` changes, and `html` only
871
+ // updates after `propsJson` changes (via the renderReq fetch path),
872
+ // so the closure captures the right `attrs`/`onPropChange` for the
873
+ // commit that triggered the new render.
874
+ }, [html, containerMode]);
875
+ const slot = (_jsx(NestedLexicalEditor, { getContent: (n) => n.children, getUpdatedMdastNode: (n, children) => ({ ...n, children: children }) }));
876
+ const onPropChange = useCallback((propName, next) => {
877
+ // Route through the type-aware writer so booleans become JSX
878
+ // shorthand (`<CardGrid stagger />`), numbers become expressions
879
+ // (`<Box columns={3} />`), and strings stay as string literals.
880
+ // The inline-prop editor in the preview still calls this with
881
+ // string values — `writeAttribute` handles those identically to
882
+ // `writeStringAttribute` (the previous narrow writer).
883
+ updater({ attributes: writeAttribute(node.attributes, propName, next) });
884
+ }, [updater, node.attributes]);
885
+ // Publish to the side-panel registry whenever this block is the
886
+ // currently-selected one, or its props change while still selected.
887
+ // The panel reads `descriptor`/`attrs` to render the form and calls
888
+ // back through `onPropChange`/`removeNode` (closed over the block's
889
+ // own updater hooks) so updates flow on the same path inline editing
890
+ // used.
891
+ // Stable per-block identity. `useLexicalNodeRemove` returns a fresh
892
+ // closure on each render so we can't key off `removeNode`. The Lexical
893
+ // node `getKey()` is stable for the block's whole lifetime and unique
894
+ // across siblings — exactly what the side-panel registry and the
895
+ // `is-selected` className need to identify the active block.
896
+ const blockKey = lexicalNode.getKey();
897
+ // biome-ignore lint/correctness/useExhaustiveDependencies: selection republish uses blockKey/propsJson signal
898
+ useEffect(() => {
899
+ if (!descriptor)
900
+ return;
901
+ const current = getSelectedBlock();
902
+ if (!current)
903
+ return;
904
+ if (current.key === blockKey) {
905
+ // Container/leaf itself is selected — republish with current attrs.
906
+ setSelectedBlock({ key: blockKey, name, descriptor, attrs, onPropChange, onRemove: removeNode });
907
+ return;
908
+ }
909
+ // A child of this container might be the selection. Child keys are
910
+ // `${containerKey}:${dotPath}` — strip our prefix to find which
911
+ // child path the panel is showing. Re-resolve that child from the
912
+ // current mdast so panel inputs reflect prop edits done elsewhere
913
+ // (inline editor commits, programmatic updates).
914
+ if (containerMode && current.key.startsWith(`${blockKey}:`)) {
915
+ const dotPath = current.key.slice(blockKey.length + 1);
916
+ const childPath = dotPath ? dotPath.split('.').map((s) => Number.parseInt(s, 10)) : [];
917
+ const childNode = getMdastAtPath(node, childPath);
918
+ if (!childNode || childNode.name !== current.name)
919
+ return;
920
+ const childDescriptor = descriptors.find((d) => d.name === childNode.name);
921
+ if (!childDescriptor || !isJsxDescriptor(childDescriptor))
922
+ return;
923
+ const childAttrs = readAttrs(childNode);
924
+ const childOnPropChange = (propName, value) => {
925
+ const newChild = {
926
+ ...childNode,
927
+ attributes: writeAttribute(childNode.attributes, propName, value),
928
+ };
929
+ const next = replaceMdastNodeAtPath(node, childPath, newChild);
930
+ updater({ children: next.children });
931
+ };
932
+ const childOnRemove = () => {
933
+ const next = removeMdastNodeAtPath(node, childPath);
934
+ updater({ children: next.children });
935
+ };
936
+ setSelectedBlock({
937
+ key: current.key,
938
+ name: childNode.name,
939
+ descriptor: childDescriptor,
940
+ attrs: childAttrs,
941
+ onPropChange: childOnPropChange,
942
+ onRemove: childOnRemove,
943
+ });
944
+ }
945
+ // Deps are intentionally narrow. `propsJson` is the content the panel
946
+ // reads; `descriptor`/`name`/`blockKey` define identity. `onPropChange`
947
+ // and `removeNode` are FRESH closures on every render (Lexical's
948
+ // updater hooks rebuild them), so including them would trigger a
949
+ // re-publish → useSelectedBlock fires → all blocks re-render →
950
+ // closure identities change → re-publish → infinite loop. We capture
951
+ // the latest closures via the `attrs`/`propsJson` change signal
952
+ // instead, which is the moment the panel actually needs an update.
953
+ }, [propsJson, descriptor, name, blockKey, containerMode]);
954
+ const handleSelect = useCallback((e) => {
955
+ if (!descriptor)
956
+ return;
957
+ // Container resolution: when the click/focus landed inside a
958
+ // child slot (eg a Card inside a CardGrid), publish the CHILD's
959
+ // descriptor + attrs to the panel instead of the container's.
960
+ // The same wrapper handler covers both cases — we walk from the
961
+ // event target to find the nearest `data-slot-id` ancestor; if
962
+ // one exists, the user clicked into a child, otherwise the click
963
+ // hit container-level chrome and the container itself is the
964
+ // selection.
965
+ if (containerMode && e) {
966
+ const target = e.target;
967
+ // Prefer the child-region marker stamped by the html-injection
968
+ // effect — covers clicks anywhere inside a child (title, icon,
969
+ // body). The slot-id fallback covers the case where the
970
+ // region marker is missing (eg edge cases where the region
971
+ // walker couldn't find a bounded subtree).
972
+ const regionEl = target?.closest('[data-conloca-child-path]');
973
+ const slotEl = regionEl ?? target?.closest('[data-slot-id]');
974
+ if (slotEl) {
975
+ const slotId = slotEl.getAttribute('data-conloca-child-path') ?? slotEl.getAttribute('data-slot-id') ?? '';
976
+ const childPath = slotIdToPath(slotId);
977
+ const childNode = getMdastAtPath(node, childPath);
978
+ if (childNode && childNode.name) {
979
+ const childDescriptor = descriptors.find((d) => d.name === childNode.name);
980
+ if (childDescriptor && isJsxDescriptor(childDescriptor)) {
981
+ const childAttrs = readAttrs(childNode);
982
+ const childKey = `${blockKey}:${childPath.join('.')}`;
983
+ const childOnPropChange = (propName, value) => {
984
+ const newChild = {
985
+ ...childNode,
986
+ attributes: writeAttribute(childNode.attributes, propName, value),
987
+ };
988
+ const next = replaceMdastNodeAtPath(node, childPath, newChild);
989
+ updater({ children: next.children });
990
+ };
991
+ const childOnRemove = () => {
992
+ const next = removeMdastNodeAtPath(node, childPath);
993
+ updater({ children: next.children });
994
+ };
995
+ setSelectedBlock({
996
+ key: childKey,
997
+ name: childNode.name,
998
+ descriptor: childDescriptor,
999
+ attrs: childAttrs,
1000
+ onPropChange: childOnPropChange,
1001
+ onRemove: childOnRemove,
1002
+ });
1003
+ return;
1004
+ }
1005
+ }
1006
+ }
1007
+ }
1008
+ setSelectedBlock({ key: blockKey, name, descriptor, attrs, onPropChange, onRemove: removeNode });
1009
+ }, [blockKey, descriptor, name, attrs, onPropChange, removeNode, containerMode, node, descriptors, updater]);
1010
+ // SSR'd component previews ship with real interactive anchors — Starlight
1011
+ // `<LinkCard>`s navigate, `<Tabs>` triggers are `<a role="tab" href="#...">`,
1012
+ // any `<a>` inside a `<Card>` body, etc. In a live page Starlight's custom
1013
+ // elements (`<starlight-tabs>`) wire click → tab-panel toggle, and link
1014
+ // anchors navigate. In the editor neither of those is desirable: the JS
1015
+ // that runs `<starlight-tabs>`'s connectedCallback isn't loaded under
1016
+ // /__cms, and navigation yanks the author away from what they're editing.
1017
+ //
1018
+ // So intercept anchor clicks in capture phase and handle the two cases:
1019
+ // 1. `[role="tab"]` → switch tabs in place (manual ARIA toggle that
1020
+ // mirrors what `<starlight-tabs>` would do at runtime). The author
1021
+ // can now click "npm" to see and edit the npm tab body.
1022
+ // 2. Any other `<a>` → swallow. Selection still fires from the
1023
+ // `mousedown` handler so the block becomes selected as if it were a
1024
+ // static surface.
1025
+ //
1026
+ // `auxclick` (middle-click) gets the anchor swallow too — without it
1027
+ // middle-click on a LinkCard would still "open in new tab" and escape
1028
+ // the editor.
1029
+ const handleAnchorClickInPreview = useCallback((e) => {
1030
+ const target = e.target;
1031
+ const tab = target?.closest('[role="tab"]');
1032
+ if (tab) {
1033
+ e.preventDefault();
1034
+ e.stopPropagation();
1035
+ activateTabInPlace(tab);
1036
+ return;
1037
+ }
1038
+ if (target?.closest('a')) {
1039
+ e.preventDefault();
1040
+ e.stopPropagation();
1041
+ }
1042
+ }, []);
1043
+ // Per-block "am I selected" subscription. Compares the registry's
1044
+ // current key with this block's stable key; safe across re-renders.
1045
+ // The CSS hook is the `is-selected` class on the wrapper, which paints
1046
+ // the accent outline; the side panel keys off the same registry.
1047
+ const selected = useSelectedBlock();
1048
+ const isSelected = selected?.key === blockKey;
1049
+ // Raw HTML in MDX (`<div class="x">`, `<details>`, etc.) lands here
1050
+ // with a lowercase tag name and no registered component descriptor.
1051
+ // Render the whole subtree client-side as HTML — no SSR roundtrip,
1052
+ // no labelled fallback. Static (not inline-editable) for now.
1053
+ if (!source && isHtmlTag(name)) {
1054
+ const rawHtml = mdastToHtml(node);
1055
+ return (_jsx("div", { className: `conloca-generic-block conloca-generic-block--html${isSelected ? ' is-selected' : ''}`, onMouseDownCapture: handleSelect, onFocusCapture: handleSelect, onClickCapture: handleAnchorClickInPreview, onAuxClickCapture: handleAnchorClickInPreview,
1056
+ // eslint-disable-next-line react/no-danger
1057
+ dangerouslySetInnerHTML: { __html: rawHtml } }));
1058
+ }
1059
+ // Text-kind components are inline glyphs (Icon, raw-HTML inline tags).
1060
+ // Wrapping them in a `<div>` would force a line break inside the
1061
+ // paragraph that contains them. Use `<span>` wrappers and a class
1062
+ // modifier so CSS can drop block-level styling for this path.
1063
+ if (isInline) {
1064
+ return (_jsx("span", { className: `conloca-generic-block conloca-generic-block--inline${isSelected ? ' is-selected' : ''}`, onMouseDownCapture: handleSelect, onFocusCapture: handleSelect, onClickCapture: handleAnchorClickInPreview, onAuxClickCapture: handleAnchorClickInPreview, children: source && !error ? (_jsxs(_Fragment, { children: [_jsx("span", { ref: wrapperRef, className: "conloca-generic-block__rendered" }), slotEl && createPortal(slot, slotEl)] })) : (_jsxs("span", { className: "conloca-generic-block__fallback", "data-mdx-block": name, children: [_jsx("span", { className: "conloca-generic-block__fallback-label", children: name }), _jsx("span", { className: "conloca-generic-block__fallback-body", children: slot })] })) }));
1065
+ }
1066
+ return (_jsx("div", { className: `conloca-generic-block${isSelected ? ' is-selected' : ''}`, onMouseDownCapture: handleSelect, onFocusCapture: handleSelect, onClickCapture: handleAnchorClickInPreview, onAuxClickCapture: handleAnchorClickInPreview, children: source && !error ? (_jsxs(_Fragment, { children: [_jsx("div", { ref: wrapperRef, className: "conloca-generic-block__rendered" }), slotEl && createPortal(slot, slotEl), Array.from(containerSlots).map(([slotId, el]) => createPortal(_jsx(ContainerSlotEditor, { path: slotIdToPath(slotId) }, slotId), el))] })) : (_jsxs("div", { className: "conloca-generic-block__fallback", "data-mdx-block": name, children: [_jsx("span", { className: "conloca-generic-block__fallback-label", children: name }), _jsx("div", { className: "conloca-generic-block__fallback-body", children: slot })] })) }));
1067
+ }