@conloca/cms-spa 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (483) hide show
  1. package/dist/spa/main.css +262 -21
  2. package/dist/ts/.build-inputs.json +99 -57
  3. package/dist/ts/CmsSpaApp.d.ts +4 -6
  4. package/dist/ts/CmsSpaApp.d.ts.map +1 -1
  5. package/dist/ts/CmsSpaApp.js +19 -8
  6. package/dist/ts/CmsSpaApp.js.map +1 -1
  7. package/dist/ts/components/conflicts/EditorNoticeStrip.d.ts +44 -0
  8. package/dist/ts/components/conflicts/EditorNoticeStrip.d.ts.map +1 -0
  9. package/dist/ts/components/conflicts/EditorNoticeStrip.js +55 -0
  10. package/dist/ts/components/conflicts/EditorNoticeStrip.js.map +1 -0
  11. package/dist/ts/components/conflicts/FieldConflictList.d.ts +20 -0
  12. package/dist/ts/components/conflicts/FieldConflictList.d.ts.map +1 -0
  13. package/dist/ts/components/conflicts/FieldConflictList.js +14 -0
  14. package/dist/ts/components/conflicts/FieldConflictList.js.map +1 -0
  15. package/dist/ts/components/conflicts/FieldConflictPicker.d.ts +28 -0
  16. package/dist/ts/components/conflicts/FieldConflictPicker.d.ts.map +1 -0
  17. package/dist/ts/components/conflicts/FieldConflictPicker.js +52 -0
  18. package/dist/ts/components/conflicts/FieldConflictPicker.js.map +1 -0
  19. package/dist/ts/components/conflicts/OverwriteNotice.d.ts +11 -0
  20. package/dist/ts/components/conflicts/OverwriteNotice.d.ts.map +1 -0
  21. package/dist/ts/components/conflicts/OverwriteNotice.js +8 -0
  22. package/dist/ts/components/conflicts/OverwriteNotice.js.map +1 -0
  23. package/dist/ts/components/conflicts/PageDraftMenu.d.ts +11 -0
  24. package/dist/ts/components/conflicts/PageDraftMenu.d.ts.map +1 -0
  25. package/dist/ts/components/conflicts/PageDraftMenu.js +20 -0
  26. package/dist/ts/components/conflicts/PageDraftMenu.js.map +1 -0
  27. package/dist/ts/components/conflicts/PeerAvatars.d.ts +9 -0
  28. package/dist/ts/components/conflicts/PeerAvatars.d.ts.map +1 -0
  29. package/dist/ts/components/conflicts/PeerAvatars.js +29 -0
  30. package/dist/ts/components/conflicts/PeerAvatars.js.map +1 -0
  31. package/dist/ts/components/conflicts/PuckConflicts.d.ts +13 -0
  32. package/dist/ts/components/conflicts/PuckConflicts.d.ts.map +1 -0
  33. package/dist/ts/components/conflicts/PuckConflicts.js +59 -0
  34. package/dist/ts/components/conflicts/PuckConflicts.js.map +1 -0
  35. package/dist/ts/components/conflicts/RecentVersionsDialog.d.ts +15 -0
  36. package/dist/ts/components/conflicts/RecentVersionsDialog.d.ts.map +1 -0
  37. package/dist/ts/components/conflicts/RecentVersionsDialog.js +94 -0
  38. package/dist/ts/components/conflicts/RecentVersionsDialog.js.map +1 -0
  39. package/dist/ts/components/conflicts/conflict-label.d.ts +12 -0
  40. package/dist/ts/components/conflicts/conflict-label.d.ts.map +1 -0
  41. package/dist/ts/components/conflicts/conflict-label.js +120 -0
  42. package/dist/ts/components/conflicts/conflict-label.js.map +1 -0
  43. package/dist/ts/components/conflicts/use-page-conflicts.d.ts +26 -0
  44. package/dist/ts/components/conflicts/use-page-conflicts.d.ts.map +1 -0
  45. package/dist/ts/components/conflicts/use-page-conflicts.js +93 -0
  46. package/dist/ts/components/conflicts/use-page-conflicts.js.map +1 -0
  47. package/dist/ts/components/conflicts/version-copy.d.ts +7 -0
  48. package/dist/ts/components/conflicts/version-copy.d.ts.map +1 -0
  49. package/dist/ts/components/conflicts/version-copy.js +31 -0
  50. package/dist/ts/components/conflicts/version-copy.js.map +1 -0
  51. package/dist/ts/components/dashboard/RecentActivity.d.ts.map +1 -1
  52. package/dist/ts/components/dashboard/RecentActivity.js +2 -1
  53. package/dist/ts/components/dashboard/RecentActivity.js.map +1 -1
  54. package/dist/ts/components/dialogs/CreatePageDialog.js +1 -1
  55. package/dist/ts/components/dialogs/CreatePageDialog.js.map +1 -1
  56. package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts +2 -1
  57. package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts.map +1 -1
  58. package/dist/ts/components/dialogs/DataPropertiesDialog.js +15 -3
  59. package/dist/ts/components/dialogs/DataPropertiesDialog.js.map +1 -1
  60. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +2 -1
  61. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
  62. package/dist/ts/components/dialogs/FragmentPropertiesDialog.js +16 -3
  63. package/dist/ts/components/dialogs/FragmentPropertiesDialog.js.map +1 -1
  64. package/dist/ts/components/dialogs/PageMetadataDialog.d.ts +9 -2
  65. package/dist/ts/components/dialogs/PageMetadataDialog.d.ts.map +1 -1
  66. package/dist/ts/components/dialogs/PageMetadataDialog.js +63 -16
  67. package/dist/ts/components/dialogs/PageMetadataDialog.js.map +1 -1
  68. package/dist/ts/components/dialogs/UnsavedChangesDialog.d.ts +16 -1
  69. package/dist/ts/components/dialogs/UnsavedChangesDialog.d.ts.map +1 -1
  70. package/dist/ts/components/dialogs/UnsavedChangesDialog.js +90 -2
  71. package/dist/ts/components/dialogs/UnsavedChangesDialog.js.map +1 -1
  72. package/dist/ts/components/dialogs/unsaved-guard.d.ts +9 -0
  73. package/dist/ts/components/dialogs/unsaved-guard.d.ts.map +1 -0
  74. package/dist/ts/components/dialogs/unsaved-guard.js +14 -0
  75. package/dist/ts/components/dialogs/unsaved-guard.js.map +1 -0
  76. package/dist/ts/components/editor/CMSMDXEditor.d.ts +6 -1
  77. package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
  78. package/dist/ts/components/editor/CMSMDXEditor.js +32 -15
  79. package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
  80. package/dist/ts/components/editor/EditorFrame.d.ts +22 -0
  81. package/dist/ts/components/editor/EditorFrame.d.ts.map +1 -0
  82. package/dist/ts/components/editor/EditorFrame.js +72 -0
  83. package/dist/ts/components/editor/EditorFrame.js.map +1 -0
  84. package/dist/ts/components/editor/FragmentBlockTypeSelect.d.ts +10 -0
  85. package/dist/ts/components/editor/FragmentBlockTypeSelect.d.ts.map +1 -0
  86. package/dist/ts/components/editor/FragmentBlockTypeSelect.js +187 -0
  87. package/dist/ts/components/editor/FragmentBlockTypeSelect.js.map +1 -0
  88. package/dist/ts/components/editor/FragmentComponentBlock.d.ts +7 -0
  89. package/dist/ts/components/editor/FragmentComponentBlock.d.ts.map +1 -0
  90. package/dist/ts/components/editor/FragmentComponentBlock.js +180 -0
  91. package/dist/ts/components/editor/FragmentComponentBlock.js.map +1 -0
  92. package/dist/ts/components/editor/FragmentEditor.d.ts +3 -1
  93. package/dist/ts/components/editor/FragmentEditor.d.ts.map +1 -1
  94. package/dist/ts/components/editor/FragmentEditor.js +545 -130
  95. package/dist/ts/components/editor/FragmentEditor.js.map +1 -1
  96. package/dist/ts/components/editor/FragmentEditorHeaderActions.d.ts +20 -0
  97. package/dist/ts/components/editor/FragmentEditorHeaderActions.d.ts.map +1 -0
  98. package/dist/ts/components/editor/FragmentEditorHeaderActions.js +49 -0
  99. package/dist/ts/components/editor/FragmentEditorHeaderActions.js.map +1 -0
  100. package/dist/ts/components/editor/GenericBlock.d.ts.map +1 -1
  101. package/dist/ts/components/editor/GenericBlock.js +109 -12
  102. package/dist/ts/components/editor/GenericBlock.js.map +1 -1
  103. package/dist/ts/components/editor/InlinePreviewFrame.d.ts +19 -0
  104. package/dist/ts/components/editor/InlinePreviewFrame.d.ts.map +1 -0
  105. package/dist/ts/components/editor/InlinePreviewFrame.js +65 -0
  106. package/dist/ts/components/editor/InlinePreviewFrame.js.map +1 -0
  107. package/dist/ts/components/editor/JsxPropsPanel.d.ts.map +1 -1
  108. package/dist/ts/components/editor/JsxPropsPanel.js +62 -2
  109. package/dist/ts/components/editor/JsxPropsPanel.js.map +1 -1
  110. package/dist/ts/components/editor/LocaleSelector.d.ts +2 -1
  111. package/dist/ts/components/editor/LocaleSelector.d.ts.map +1 -1
  112. package/dist/ts/components/editor/LocaleSelector.js +2 -2
  113. package/dist/ts/components/editor/LocaleSelector.js.map +1 -1
  114. package/dist/ts/components/editor/MDXLivePreview.d.ts +2 -0
  115. package/dist/ts/components/editor/MDXLivePreview.d.ts.map +1 -1
  116. package/dist/ts/components/editor/MDXLivePreview.js +30 -38
  117. package/dist/ts/components/editor/MDXLivePreview.js.map +1 -1
  118. package/dist/ts/components/editor/MdxPageEditor.d.ts +7 -2
  119. package/dist/ts/components/editor/MdxPageEditor.d.ts.map +1 -1
  120. package/dist/ts/components/editor/MdxPageEditor.js +136 -10
  121. package/dist/ts/components/editor/MdxPageEditor.js.map +1 -1
  122. package/dist/ts/components/editor/PageEditor.d.ts +4 -1
  123. package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
  124. package/dist/ts/components/editor/PageEditor.js +78 -100
  125. package/dist/ts/components/editor/PageEditor.js.map +1 -1
  126. package/dist/ts/components/editor/PageEditorHeaderActions.d.ts +15 -4
  127. package/dist/ts/components/editor/PageEditorHeaderActions.d.ts.map +1 -1
  128. package/dist/ts/components/editor/PageEditorHeaderActions.js +13 -7
  129. package/dist/ts/components/editor/PageEditorHeaderActions.js.map +1 -1
  130. package/dist/ts/components/editor/PageEditorWrapper.d.ts +8 -2
  131. package/dist/ts/components/editor/PageEditorWrapper.d.ts.map +1 -1
  132. package/dist/ts/components/editor/PageEditorWrapper.js +99 -41
  133. package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
  134. package/dist/ts/components/editor/body-sync-plugin.d.ts +2 -0
  135. package/dist/ts/components/editor/body-sync-plugin.d.ts.map +1 -0
  136. package/dist/ts/components/editor/body-sync-plugin.js +32 -0
  137. package/dist/ts/components/editor/body-sync-plugin.js.map +1 -0
  138. package/dist/ts/components/editor/draft-media-config.d.ts +6 -0
  139. package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -1
  140. package/dist/ts/components/editor/draft-media-config.js +21 -0
  141. package/dist/ts/components/editor/draft-media-config.js.map +1 -1
  142. package/dist/ts/components/editor/fragment-save-check.d.ts +7 -0
  143. package/dist/ts/components/editor/fragment-save-check.d.ts.map +1 -0
  144. package/dist/ts/components/editor/fragment-save-check.js +13 -0
  145. package/dist/ts/components/editor/fragment-save-check.js.map +1 -0
  146. package/dist/ts/components/editor/fragment-save-lifetime.d.ts +18 -0
  147. package/dist/ts/components/editor/fragment-save-lifetime.d.ts.map +1 -0
  148. package/dist/ts/components/editor/fragment-save-lifetime.js +115 -0
  149. package/dist/ts/components/editor/fragment-save-lifetime.js.map +1 -0
  150. package/dist/ts/components/editor/host-wrapper-plugin.d.ts.map +1 -1
  151. package/dist/ts/components/editor/host-wrapper-plugin.js +20 -7
  152. package/dist/ts/components/editor/host-wrapper-plugin.js.map +1 -1
  153. package/dist/ts/components/editor/index.d.ts +0 -1
  154. package/dist/ts/components/editor/index.d.ts.map +1 -1
  155. package/dist/ts/components/editor/index.js +0 -1
  156. package/dist/ts/components/editor/index.js.map +1 -1
  157. package/dist/ts/components/editor/insert-menu/InsertMdxComponentButton.d.ts.map +1 -1
  158. package/dist/ts/components/editor/insert-menu/InsertMdxComponentButton.js +6 -11
  159. package/dist/ts/components/editor/insert-menu/InsertMdxComponentButton.js.map +1 -1
  160. package/dist/ts/components/editor/insert-menu/SlashMenuPlugin.d.ts.map +1 -1
  161. package/dist/ts/components/editor/insert-menu/SlashMenuPlugin.js +66 -12
  162. package/dist/ts/components/editor/insert-menu/SlashMenuPlugin.js.map +1 -1
  163. package/dist/ts/components/editor/insert-menu/insert-payload.d.ts +16 -21
  164. package/dist/ts/components/editor/insert-menu/insert-payload.d.ts.map +1 -1
  165. package/dist/ts/components/editor/insert-menu/insert-payload.js +75 -22
  166. package/dist/ts/components/editor/insert-menu/insert-payload.js.map +1 -1
  167. package/dist/ts/components/editor/insert-menu/mdx-components-plugin.d.ts +3 -1
  168. package/dist/ts/components/editor/insert-menu/mdx-components-plugin.d.ts.map +1 -1
  169. package/dist/ts/components/editor/insert-menu/mdx-components-plugin.js +5 -3
  170. package/dist/ts/components/editor/insert-menu/mdx-components-plugin.js.map +1 -1
  171. package/dist/ts/components/editor/jsx-layout-plugin.d.ts +25 -0
  172. package/dist/ts/components/editor/jsx-layout-plugin.d.ts.map +1 -0
  173. package/dist/ts/components/editor/jsx-layout-plugin.js +77 -0
  174. package/dist/ts/components/editor/jsx-layout-plugin.js.map +1 -0
  175. package/dist/ts/components/editor/offered-mdx-components.d.ts +11 -0
  176. package/dist/ts/components/editor/offered-mdx-components.d.ts.map +1 -0
  177. package/dist/ts/components/editor/offered-mdx-components.js +27 -0
  178. package/dist/ts/components/editor/offered-mdx-components.js.map +1 -0
  179. package/dist/ts/components/editor/page-setting-targets.d.ts.map +1 -1
  180. package/dist/ts/components/editor/page-setting-targets.js +2 -1
  181. package/dist/ts/components/editor/page-setting-targets.js.map +1 -1
  182. package/dist/ts/components/editor/preview-availability.d.ts +16 -1
  183. package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
  184. package/dist/ts/components/editor/preview-availability.js +16 -1
  185. package/dist/ts/components/editor/preview-availability.js.map +1 -1
  186. package/dist/ts/components/editor/prop-field-hint.d.ts +13 -0
  187. package/dist/ts/components/editor/prop-field-hint.d.ts.map +1 -0
  188. package/dist/ts/components/editor/prop-field-hint.js +70 -0
  189. package/dist/ts/components/editor/prop-field-hint.js.map +1 -0
  190. package/dist/ts/components/editor/soft-break-plugin.d.ts +21 -0
  191. package/dist/ts/components/editor/soft-break-plugin.d.ts.map +1 -0
  192. package/dist/ts/components/editor/soft-break-plugin.js +52 -0
  193. package/dist/ts/components/editor/soft-break-plugin.js.map +1 -0
  194. package/dist/ts/components/editor/use-live-page-settings.d.ts +13 -0
  195. package/dist/ts/components/editor/use-live-page-settings.d.ts.map +1 -0
  196. package/dist/ts/components/editor/use-live-page-settings.js +76 -0
  197. package/dist/ts/components/editor/use-live-page-settings.js.map +1 -0
  198. package/dist/ts/components/editor/usePagePreview.d.ts +32 -0
  199. package/dist/ts/components/editor/usePagePreview.d.ts.map +1 -0
  200. package/dist/ts/components/editor/usePagePreview.js +252 -0
  201. package/dist/ts/components/editor/usePagePreview.js.map +1 -0
  202. package/dist/ts/components/editors/DataEditor.d.ts +6 -3
  203. package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
  204. package/dist/ts/components/editors/DataEditor.js +153 -19
  205. package/dist/ts/components/editors/DataEditor.js.map +1 -1
  206. package/dist/ts/components/fields/MDXEditField.d.ts +1 -1
  207. package/dist/ts/components/fields/MDXEditField.js +2 -2
  208. package/dist/ts/components/fields/MDXEditField.js.map +1 -1
  209. package/dist/ts/components/forms/SchemaForm.d.ts.map +1 -1
  210. package/dist/ts/components/forms/SchemaForm.js +1 -9
  211. package/dist/ts/components/forms/SchemaForm.js.map +1 -1
  212. package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
  213. package/dist/ts/components/media/AssetDetailSidebar.js +43 -5
  214. package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
  215. package/dist/ts/components/pages/DataList.d.ts.map +1 -1
  216. package/dist/ts/components/pages/DataList.js +16 -4
  217. package/dist/ts/components/pages/DataList.js.map +1 -1
  218. package/dist/ts/components/pages/FragmentList.d.ts.map +1 -1
  219. package/dist/ts/components/pages/FragmentList.js +10 -0
  220. package/dist/ts/components/pages/FragmentList.js.map +1 -1
  221. package/dist/ts/components/pages/PageList.d.ts.map +1 -1
  222. package/dist/ts/components/pages/PageList.js +54 -118
  223. package/dist/ts/components/pages/PageList.js.map +1 -1
  224. package/dist/ts/components/pages/PageRow.d.ts +21 -0
  225. package/dist/ts/components/pages/PageRow.d.ts.map +1 -0
  226. package/dist/ts/components/pages/PageRow.js +70 -0
  227. package/dist/ts/components/pages/PageRow.js.map +1 -0
  228. package/dist/ts/components/pages/PageTable.d.ts +21 -0
  229. package/dist/ts/components/pages/PageTable.d.ts.map +1 -0
  230. package/dist/ts/components/pages/PageTable.js +12 -0
  231. package/dist/ts/components/pages/PageTable.js.map +1 -0
  232. package/dist/ts/components/pages/page-list-model.d.ts +20 -0
  233. package/dist/ts/components/pages/page-list-model.d.ts.map +1 -0
  234. package/dist/ts/components/pages/page-list-model.js +78 -0
  235. package/dist/ts/components/pages/page-list-model.js.map +1 -0
  236. package/dist/ts/components/puck/MDXContent.d.ts +3 -3
  237. package/dist/ts/components/puck/MDXContent.d.ts.map +1 -1
  238. package/dist/ts/components/puck/MDXContent.js +24 -72
  239. package/dist/ts/components/puck/MDXContent.js.map +1 -1
  240. package/dist/ts/components/puck/csp-frame-harness.d.ts +14 -0
  241. package/dist/ts/components/puck/csp-frame-harness.d.ts.map +1 -0
  242. package/dist/ts/components/puck/csp-frame-harness.js +85 -0
  243. package/dist/ts/components/puck/csp-frame-harness.js.map +1 -0
  244. package/dist/ts/components/puck/use-fragment-render.d.ts +9 -0
  245. package/dist/ts/components/puck/use-fragment-render.d.ts.map +1 -0
  246. package/dist/ts/components/puck/use-fragment-render.js +70 -0
  247. package/dist/ts/components/puck/use-fragment-render.js.map +1 -0
  248. package/dist/ts/components/sandbox/ContentSandbox.d.ts +3 -5
  249. package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
  250. package/dist/ts/components/sandbox/ContentSandbox.js +6 -8
  251. package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
  252. package/dist/ts/components/sandbox/frame-runtime.d.ts +1 -1
  253. package/dist/ts/components/sandbox/frame-runtime.d.ts.map +1 -1
  254. package/dist/ts/components/sandbox/frame-runtime.js +1 -1
  255. package/dist/ts/components/sandbox/frame-runtime.js.map +1 -1
  256. package/dist/ts/components/toast.d.ts +8 -4
  257. package/dist/ts/components/toast.d.ts.map +1 -1
  258. package/dist/ts/components/toast.js +6 -1
  259. package/dist/ts/components/toast.js.map +1 -1
  260. package/dist/ts/components/ui/Card.d.ts +3 -5
  261. package/dist/ts/components/ui/Card.d.ts.map +1 -1
  262. package/dist/ts/components/ui/Card.js +3 -5
  263. package/dist/ts/components/ui/Card.js.map +1 -1
  264. package/dist/ts/components/ui/Select.d.ts.map +1 -1
  265. package/dist/ts/components/ui/Select.js +12 -3
  266. package/dist/ts/components/ui/Select.js.map +1 -1
  267. package/dist/ts/draft-tools.d.ts +76 -0
  268. package/dist/ts/draft-tools.d.ts.map +1 -0
  269. package/dist/ts/draft-tools.js +2 -0
  270. package/dist/ts/draft-tools.js.map +1 -0
  271. package/dist/ts/frame/channel.d.ts +1 -1
  272. package/dist/ts/frame/channel.d.ts.map +1 -1
  273. package/dist/ts/frame/channel.js +3 -0
  274. package/dist/ts/frame/channel.js.map +1 -1
  275. package/dist/ts/frame/editor-frame.d.ts.map +1 -1
  276. package/dist/ts/frame/editor-frame.js +188 -30
  277. package/dist/ts/frame/editor-frame.js.map +1 -1
  278. package/dist/ts/frame/protocol.d.ts +73 -4
  279. package/dist/ts/frame/protocol.d.ts.map +1 -1
  280. package/dist/ts/frame/protocol.js +54 -16
  281. package/dist/ts/frame/protocol.js.map +1 -1
  282. package/dist/ts/hooks/useUnsavedChangesGuard.d.ts +5 -3
  283. package/dist/ts/hooks/useUnsavedChangesGuard.d.ts.map +1 -1
  284. package/dist/ts/hooks/useUnsavedChangesGuard.js +17 -7
  285. package/dist/ts/hooks/useUnsavedChangesGuard.js.map +1 -1
  286. package/dist/ts/host-style-probe.d.ts.map +1 -1
  287. package/dist/ts/host-style-probe.js +160 -40
  288. package/dist/ts/host-style-probe.js.map +1 -1
  289. package/dist/ts/index.d.ts +13 -0
  290. package/dist/ts/index.d.ts.map +1 -1
  291. package/dist/ts/index.js +14 -0
  292. package/dist/ts/index.js.map +1 -1
  293. package/dist/ts/live/data-binding.d.ts +67 -0
  294. package/dist/ts/live/data-binding.d.ts.map +1 -0
  295. package/dist/ts/live/data-binding.js +215 -0
  296. package/dist/ts/live/data-binding.js.map +1 -0
  297. package/dist/ts/live/doc-channel.d.ts +74 -0
  298. package/dist/ts/live/doc-channel.d.ts.map +1 -0
  299. package/dist/ts/live/doc-channel.js +293 -0
  300. package/dist/ts/live/doc-channel.js.map +1 -0
  301. package/dist/ts/live/held-fragment-edits.d.ts +15 -0
  302. package/dist/ts/live/held-fragment-edits.d.ts.map +1 -0
  303. package/dist/ts/live/held-fragment-edits.js +47 -0
  304. package/dist/ts/live/held-fragment-edits.js.map +1 -0
  305. package/dist/ts/live/markdown-binding.d.ts +54 -0
  306. package/dist/ts/live/markdown-binding.d.ts.map +1 -0
  307. package/dist/ts/live/markdown-binding.js +618 -0
  308. package/dist/ts/live/markdown-binding.js.map +1 -0
  309. package/dist/ts/live/markdown-live-plugin.d.ts +42 -0
  310. package/dist/ts/live/markdown-live-plugin.d.ts.map +1 -0
  311. package/dist/ts/live/markdown-live-plugin.js +918 -0
  312. package/dist/ts/live/markdown-live-plugin.js.map +1 -0
  313. package/dist/ts/live/messages.d.ts +142 -0
  314. package/dist/ts/live/messages.d.ts.map +1 -0
  315. package/dist/ts/live/messages.js +266 -0
  316. package/dist/ts/live/messages.js.map +1 -0
  317. package/dist/ts/live/puck-binding.d.ts +88 -0
  318. package/dist/ts/live/puck-binding.d.ts.map +1 -0
  319. package/dist/ts/live/puck-binding.js +467 -0
  320. package/dist/ts/live/puck-binding.js.map +1 -0
  321. package/dist/ts/live/undo.d.ts +29 -0
  322. package/dist/ts/live/undo.d.ts.map +1 -0
  323. package/dist/ts/live/undo.js +104 -0
  324. package/dist/ts/live/undo.js.map +1 -0
  325. package/dist/ts/live/use-live.d.ts +77 -0
  326. package/dist/ts/live/use-live.d.ts.map +1 -0
  327. package/dist/ts/live/use-live.js +207 -0
  328. package/dist/ts/live/use-live.js.map +1 -0
  329. package/dist/ts/mdx-components-define.d.ts +52 -15
  330. package/dist/ts/mdx-components-define.d.ts.map +1 -1
  331. package/dist/ts/mdx-components-define.js +136 -0
  332. package/dist/ts/mdx-components-define.js.map +1 -1
  333. package/dist/ts/mdx-components.d.ts +11 -19
  334. package/dist/ts/mdx-components.d.ts.map +1 -1
  335. package/dist/ts/mdx-components.js +23 -32
  336. package/dist/ts/mdx-components.js.map +1 -1
  337. package/dist/ts/media/AssetScopePill.d.ts.map +1 -1
  338. package/dist/ts/media/AssetScopePill.js +2 -1
  339. package/dist/ts/media/AssetScopePill.js.map +1 -1
  340. package/dist/ts/merge-default-props.d.ts.map +1 -1
  341. package/dist/ts/merge-default-props.js +3 -0
  342. package/dist/ts/merge-default-props.js.map +1 -1
  343. package/dist/ts/selected-block.d.ts +27 -2
  344. package/dist/ts/selected-block.d.ts.map +1 -1
  345. package/dist/ts/selected-block.js +43 -1
  346. package/dist/ts/selected-block.js.map +1 -1
  347. package/dist/ts/site-render.d.ts +60 -0
  348. package/dist/ts/site-render.d.ts.map +1 -0
  349. package/dist/ts/site-render.js +87 -0
  350. package/dist/ts/site-render.js.map +1 -0
  351. package/dist/ts/types.d.ts +3 -0
  352. package/dist/ts/types.d.ts.map +1 -1
  353. package/dist/ts/ui-config.d.ts +29 -13
  354. package/dist/ts/ui-config.d.ts.map +1 -1
  355. package/dist/ts/ui-config.js +14 -3
  356. package/dist/ts/ui-config.js.map +1 -1
  357. package/dist/ts/utils/apply-clash.d.ts +44 -0
  358. package/dist/ts/utils/apply-clash.d.ts.map +1 -0
  359. package/dist/ts/utils/apply-clash.js +102 -0
  360. package/dist/ts/utils/apply-clash.js.map +1 -0
  361. package/dist/ts/utils/mdast-tree.d.ts +5 -7
  362. package/dist/ts/utils/mdast-tree.d.ts.map +1 -1
  363. package/dist/ts/utils/mdast-tree.js +8 -13
  364. package/dist/ts/utils/mdast-tree.js.map +1 -1
  365. package/dist/ts/utils/pageMetadata.d.ts +6 -2
  366. package/dist/ts/utils/pageMetadata.d.ts.map +1 -1
  367. package/dist/ts/utils/pageMetadata.js +25 -7
  368. package/dist/ts/utils/pageMetadata.js.map +1 -1
  369. package/dist/ts/utils/schema-fields.d.ts +2 -0
  370. package/dist/ts/utils/schema-fields.d.ts.map +1 -1
  371. package/dist/ts/utils/schema-fields.js +8 -0
  372. package/dist/ts/utils/schema-fields.js.map +1 -1
  373. package/dist/ts/write-access.d.ts +2 -0
  374. package/dist/ts/write-access.d.ts.map +1 -1
  375. package/dist/ts/write-access.js +9 -4
  376. package/dist/ts/write-access.js.map +1 -1
  377. package/package.json +18 -7
  378. package/src/CmsSpaApp.tsx +20 -11
  379. package/src/components/conflicts/EditorNoticeStrip.tsx +135 -0
  380. package/src/components/conflicts/FieldConflictList.tsx +59 -0
  381. package/src/components/conflicts/FieldConflictPicker.tsx +158 -0
  382. package/src/components/conflicts/OverwriteNotice.tsx +30 -0
  383. package/src/components/conflicts/PageDraftMenu.tsx +51 -0
  384. package/src/components/conflicts/PeerAvatars.tsx +51 -0
  385. package/src/components/conflicts/PuckConflicts.tsx +92 -0
  386. package/src/components/conflicts/RecentVersionsDialog.tsx +154 -0
  387. package/src/components/conflicts/conflict-label.ts +124 -0
  388. package/src/components/conflicts/use-page-conflicts.ts +112 -0
  389. package/src/components/conflicts/version-copy.ts +33 -0
  390. package/src/components/dashboard/RecentActivity.tsx +3 -2
  391. package/src/components/dialogs/CreatePageDialog.tsx +1 -1
  392. package/src/components/dialogs/DataPropertiesDialog.tsx +22 -4
  393. package/src/components/dialogs/FragmentPropertiesDialog.tsx +23 -4
  394. package/src/components/dialogs/PageMetadataDialog.tsx +157 -65
  395. package/src/components/dialogs/UnsavedChangesDialog.tsx +171 -21
  396. package/src/components/dialogs/unsaved-guard.ts +15 -0
  397. package/src/components/editor/CMSMDXEditor.tsx +238 -198
  398. package/src/components/editor/EditorFrame.tsx +116 -0
  399. package/src/components/editor/FragmentBlockTypeSelect.tsx +245 -0
  400. package/src/components/editor/FragmentComponentBlock.tsx +257 -0
  401. package/src/components/editor/FragmentEditor.tsx +899 -213
  402. package/src/components/editor/FragmentEditorHeaderActions.tsx +77 -0
  403. package/src/components/editor/GenericBlock.tsx +127 -16
  404. package/src/components/editor/InlinePreviewFrame.tsx +78 -0
  405. package/src/components/editor/JsxPropsPanel.tsx +90 -6
  406. package/src/components/editor/LocaleSelector.tsx +4 -2
  407. package/src/components/editor/MDXLivePreview.tsx +44 -46
  408. package/src/components/editor/MdxPageEditor.tsx +247 -7
  409. package/src/components/editor/PageEditor.tsx +154 -121
  410. package/src/components/editor/PageEditorHeaderActions.tsx +65 -27
  411. package/src/components/editor/PageEditorWrapper.tsx +122 -45
  412. package/src/components/editor/body-sync-plugin.ts +44 -0
  413. package/src/components/editor/draft-media-config.ts +22 -0
  414. package/src/components/editor/fragment-save-check.ts +26 -0
  415. package/src/components/editor/fragment-save-lifetime.ts +142 -0
  416. package/src/components/editor/host-wrapper-plugin.ts +28 -7
  417. package/src/components/editor/index.ts +0 -1
  418. package/src/components/editor/insert-menu/InsertMdxComponentButton.tsx +7 -11
  419. package/src/components/editor/insert-menu/SlashMenuPlugin.tsx +95 -18
  420. package/src/components/editor/insert-menu/insert-payload.ts +79 -30
  421. package/src/components/editor/insert-menu/mdx-components-plugin.ts +5 -3
  422. package/src/components/editor/jsx-layout-plugin.ts +103 -0
  423. package/src/components/editor/offered-mdx-components.ts +35 -0
  424. package/src/components/editor/page-setting-targets.tsx +2 -0
  425. package/src/components/editor/preview-availability.ts +21 -1
  426. package/src/components/editor/prop-field-hint.ts +75 -0
  427. package/src/components/editor/soft-break-plugin.ts +55 -0
  428. package/src/components/editor/use-live-page-settings.ts +80 -0
  429. package/src/components/editor/usePagePreview.ts +291 -0
  430. package/src/components/editors/DataEditor.tsx +257 -22
  431. package/src/components/fields/MDXEditField.tsx +2 -2
  432. package/src/components/forms/SchemaForm.tsx +1 -10
  433. package/src/components/media/AssetDetailSidebar.tsx +47 -6
  434. package/src/components/pages/DataList.tsx +14 -4
  435. package/src/components/pages/FragmentList.tsx +8 -0
  436. package/src/components/pages/PageList.tsx +90 -337
  437. package/src/components/pages/PageRow.tsx +290 -0
  438. package/src/components/pages/PageTable.tsx +71 -0
  439. package/src/components/pages/page-list-model.ts +98 -0
  440. package/src/components/puck/MDXContent.tsx +37 -113
  441. package/src/components/puck/csp-frame-harness.tsx +99 -0
  442. package/src/components/puck/use-fragment-render.ts +82 -0
  443. package/src/components/sandbox/ContentSandbox.tsx +6 -11
  444. package/src/components/sandbox/frame-runtime.ts +0 -2
  445. package/src/components/toast.tsx +23 -5
  446. package/src/components/ui/Card.tsx +3 -5
  447. package/src/components/ui/Select.tsx +14 -6
  448. package/src/draft-tools.ts +77 -0
  449. package/src/frame/channel.ts +3 -1
  450. package/src/frame/editor-frame.ts +210 -30
  451. package/src/frame/protocol.ts +98 -15
  452. package/src/hooks/useUnsavedChangesGuard.ts +17 -6
  453. package/src/host-style-probe.ts +157 -37
  454. package/src/index.ts +90 -0
  455. package/src/live/data-binding.ts +252 -0
  456. package/src/live/doc-channel.ts +343 -0
  457. package/src/live/held-fragment-edits.ts +47 -0
  458. package/src/live/markdown-binding.ts +630 -0
  459. package/src/live/markdown-live-plugin.tsx +1037 -0
  460. package/src/live/messages.ts +370 -0
  461. package/src/live/puck-binding.tsx +579 -0
  462. package/src/live/undo.ts +112 -0
  463. package/src/live/use-live.ts +264 -0
  464. package/src/main.css +184 -4
  465. package/src/mdx-components-define.ts +170 -24
  466. package/src/mdx-components.ts +29 -30
  467. package/src/media/AssetScopePill.tsx +2 -1
  468. package/src/merge-default-props.ts +4 -0
  469. package/src/selected-block.ts +55 -3
  470. package/src/site-render.ts +146 -0
  471. package/src/types.ts +3 -0
  472. package/src/ui-config.ts +51 -15
  473. package/src/utils/apply-clash.ts +113 -0
  474. package/src/utils/mdast-tree.ts +8 -12
  475. package/src/utils/pageMetadata.ts +25 -7
  476. package/src/utils/schema-fields.ts +9 -0
  477. package/src/write-access.ts +10 -4
  478. package/styles/tailwind-theme.css +11 -0
  479. package/dist/ts/components/editor/ContentDiff.d.ts +0 -10
  480. package/dist/ts/components/editor/ContentDiff.d.ts.map +0 -1
  481. package/dist/ts/components/editor/ContentDiff.js +0 -52
  482. package/dist/ts/components/editor/ContentDiff.js.map +0 -1
  483. package/src/components/editor/ContentDiff.tsx +0 -251
@@ -0,0 +1,579 @@
1
+ /**
2
+ * Binds a Puck editor to its page's replica: the user's changes go into the doc keyed by block id, and changes made
3
+ * elsewhere (a teammate, a restore, undo) come back into Puck without entering its history.
4
+ */
5
+
6
+ import { mergeContent } from '@conloca/content-api/merge';
7
+ import { applyContentDiff, applyItemChanges, type ItemIds, readItemIds, serializeDoc } from '@conloca/content-api/ydoc';
8
+ import {
9
+ type ComponentConfig,
10
+ type Config,
11
+ createUsePuck,
12
+ type Data,
13
+ type DefaultComponentProps,
14
+ useGetPuck,
15
+ } from '@puckeditor/core';
16
+ import { createContext, type ReactNode, useContext, useEffect, useMemo } from 'react';
17
+ import type * as Y from 'yjs';
18
+ import { type FrameLiveDoc, HELD_WRITE_FAILED, LOCAL_ORIGIN, useDocChannel } from './doc-channel.js';
19
+ import type { PresencePeer } from './messages.js';
20
+ import { createListUndo, interceptUndoKeys } from './undo.js';
21
+ import { usePresencePeers } from './use-live.js';
22
+
23
+ export function readPuckData(doc: Y.Doc): Data {
24
+ return serializeDoc(doc).puckData;
25
+ }
26
+
27
+ const asFile = (puckData: Data) => ({ type: 'puck', content: { puckData } });
28
+
29
+ /**
30
+ * Writes what changed from `shadow` (what Puck was showing, with `shadowIds`, the ids of its list items) to `data` (what
31
+ * it shows now) into the doc, over whatever the doc holds that Puck has not been shown yet, so a remote change is never
32
+ * reverted. Lists change item by item, by the ids the view showed; the rest is merged against the doc. Unchanged data
33
+ * writes nothing. Returns the ids of `data`'s items, the next write's `shadowIds`. `beforeWrite` gets the `a:` arrays
34
+ * the write touches, before it writes (undo scope). A throw writes nothing: `applyItemChanges` parses all of `data`
35
+ * (a non-JSON value) and checks the doc's kind and shape before its first write, and what follows merges only JSON
36
+ * it read back into a doc of that kind.
37
+ */
38
+ export function writePuckChange(
39
+ doc: Y.Doc,
40
+ shadow: Data,
41
+ shadowIds: ItemIds,
42
+ data: Data,
43
+ beforeWrite?: (names: string[]) => void,
44
+ ): { ok: true; ids: ItemIds } | { ok: false; error: string } {
45
+ try {
46
+ let ids = shadowIds;
47
+ doc.transact(() => {
48
+ const written = applyItemChanges(
49
+ doc,
50
+ { puckData: shadow },
51
+ shadowIds,
52
+ { puckData: data },
53
+ LOCAL_ORIGIN,
54
+ beforeWrite,
55
+ );
56
+ ids = written.ids;
57
+ const merged = mergeContent({
58
+ kind: 'vxjson',
59
+ base: asFile(shadow),
60
+ ours: { type: 'puck', content: written.rest },
61
+ theirs: asFile(readPuckData(doc)),
62
+ }).value;
63
+ const content = typeof merged === 'object' && merged !== null && !Array.isArray(merged) ? merged.content : null;
64
+ const puckData =
65
+ typeof content === 'object' && content !== null && !Array.isArray(content) ? content.puckData : null;
66
+ // Never reached for an object merge; a null would throw after the item write, a partial write.
67
+ if (typeof puckData !== 'object' || puckData === null || Array.isArray(puckData))
68
+ throw new Error('merge lost the data');
69
+ applyContentDiff(doc, { puckData }, LOCAL_ORIGIN);
70
+ }, LOCAL_ORIGIN);
71
+ return { ok: true, ids };
72
+ } catch (error) {
73
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
74
+ }
75
+ }
76
+
77
+ /** One editor mount's binding to its replica. */
78
+ export interface PuckBinding {
79
+ readonly live: FrameLiveDoc;
80
+ /** This user's undo over the page's blocks and root. */
81
+ readonly undo: Y.UndoManager;
82
+ /** Marks the editor mounted; the returned release lets go of the doc once no mount is left (see `ListUndo.retain`). */
83
+ retain(): () => void;
84
+ /** The last data handed to Puck or received from it: what Puck shows. */
85
+ readonly shadow: Data;
86
+ /** Puck's onChange. A write that throws holds the replica; from then on the view keeps every change unwritten. */
87
+ change(data: Data): void;
88
+ /** The data to show after a change Puck did not make, or null while held (the view stays as the user left it). */
89
+ reseed(): Data | null;
90
+ /**
91
+ * A field change starts resolveData (trigger `replace`) for block `id` (root: `''`) with the props Puck built at the
92
+ * keystroke. Called then, synchronously, so the binding knows which props the user changed; the returned function
93
+ * takes what resolveData answered, or null when it threw (Puck then hands nothing over).
94
+ */
95
+ fieldResolveStarted(id: string, props: Props, parentId?: string): (resolved: Props | null) => void;
96
+ /** How many field changes the binding still waits on Puck to hand over. */
97
+ fieldResolvesWaiting(): number;
98
+ }
99
+
100
+ export type Props = DefaultComponentProps;
101
+
102
+ /** The view of each held replica: its unwritten changes, which a remount must show again (the doc lacks them). */
103
+ const heldViews = new WeakMap<FrameLiveDoc, Data>();
104
+
105
+ /** An empty transaction under this origin makes the bridge re-seed Puck without writing anything. */
106
+ const RESHOW_ORIGIN = Symbol('live-puck-reshow');
107
+
108
+ /** The root's id among block ids; Puck itself calls it `root`. */
109
+ const ROOT_ID = '';
110
+
111
+ type Block = Data['content'][number];
112
+
113
+ /** A slot's value: a non-empty list of blocks. */
114
+ function isBlockList(value: Props[string]): value is Block[] {
115
+ return (
116
+ Array.isArray(value) &&
117
+ value.length > 0 &&
118
+ value.every((item) => typeof item?.type === 'string' && typeof item?.props?.id === 'string')
119
+ );
120
+ }
121
+
122
+ type MapProps = (id: string, props: Props) => Props;
123
+
124
+ /** `props` after `map`, then each block in its slots the same way, at every depth. */
125
+ function mapSlots(props: Props, map: MapProps): Props {
126
+ let out: Props | null = null;
127
+ for (const [key, value] of Object.entries(props)) {
128
+ if (!isBlockList(value)) continue;
129
+ const next = value.map((block) => mapBlock(block, map));
130
+ if (!next.some((block, i) => block !== value[i])) continue;
131
+ out ??= { ...props };
132
+ out[key] = next;
133
+ }
134
+ return out ?? props;
135
+ }
136
+
137
+ function mapBlock(block: Block, map: MapProps): Block {
138
+ const props = mapSlots(map(String(block.props.id), block.props), map);
139
+ return props === block.props ? block : { ...block, props };
140
+ }
141
+
142
+ /** `data` with `map` applied to the root's props and every block's, slot blocks included (the parent first). */
143
+ function mapData(data: Data, map: MapProps): Data {
144
+ const rootProps = data.root?.props ?? {};
145
+ const root = mapSlots(map(ROOT_ID, rootProps), map);
146
+ const content = data.content.map((block) => mapBlock(block, map));
147
+ return { ...data, root: { ...data.root, props: root }, content };
148
+ }
149
+
150
+ /** Every block's props by id, the root's under `ROOT_ID`, slot blocks included. */
151
+ function propsById(data: Data): Map<string, Props> {
152
+ const byId = new Map<string, Props>();
153
+ mapData(data, (id, props) => {
154
+ byId.set(id, props);
155
+ return props;
156
+ });
157
+ return byId;
158
+ }
159
+
160
+ const same = (a: Props[string], b: Props[string]) => JSON.stringify(a) === JSON.stringify(b);
161
+
162
+ function sameProps(a: Props, b: Props): boolean {
163
+ return [...new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => same(a[key], b[key]));
164
+ }
165
+
166
+ /** The keys whose values differ between `a` and `b`. */
167
+ function differing(a: Props, b: Props): string[] {
168
+ return [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((key) => !same(a[key], b[key]));
169
+ }
170
+
171
+ /** A field change whose resolveData ran: the props the user changed, those resolveData derived, and the block Puck will hand over. */
172
+ interface FieldResolve {
173
+ id: string;
174
+ /** What the keystroke wrote: the block's props then, the props Puck built, and the keys the user set. */
175
+ wrote: { before: Props; props: Props; keys: string[] };
176
+ /** Set once resolveData answered: the block's props Puck's `replace` carries, and the props resolveData changed. */
177
+ settled: { props: Props; derived: string[] } | null;
178
+ }
179
+
180
+ type SettledResolve = FieldResolve & { settled: NonNullable<FieldResolve['settled']> };
181
+
182
+ /** Block `id` among the slot children of `props`, at any depth. */
183
+ function childProps(props: Props, id: string): Props | undefined {
184
+ for (const value of Object.values(props)) {
185
+ if (!isBlockList(value)) continue;
186
+ for (const block of value) {
187
+ if (block.props.id === id) return block.props;
188
+ const inner = childProps(block.props, id);
189
+ if (inner) return inner;
190
+ }
191
+ }
192
+ return undefined;
193
+ }
194
+
195
+ /**
196
+ * The block a field change's `replace` hands over, as it is to be written: what Puck shows now (the doc, re-seeded)
197
+ * plus the props resolveData derived. Puck builds that `replace` from the block as it was at the keystroke, so every
198
+ * other prop it carries is a stale copy, and a change re-seeded meanwhile (a teammate's) must not be written back
199
+ * over. The props the user set are not written again: they went into the doc at the keystroke, and a teammate may have
200
+ * changed them since.
201
+ */
202
+ function narrowed(shown: Props, resolve: SettledResolve): Props {
203
+ const props: Props = { ...shown };
204
+ for (const key of resolve.settled.derived) {
205
+ if (key in resolve.settled.props) props[key] = resolve.settled.props[key];
206
+ else Reflect.deleteProperty(props, key);
207
+ }
208
+ return props;
209
+ }
210
+
211
+ /** `next` with each block's and root's props Puck was shown kept under the doc's: resolved props the doc never stored. */
212
+ function keepShownProps(next: Data, shown: Data): Data {
213
+ const before = propsById(shown);
214
+ return mapData(next, (id, props) => ({ ...before.get(id), ...props }));
215
+ }
216
+
217
+ /**
218
+ * `data` with root in the shape Puck 0.23 holds it from its first state (`root.props || root`, without the id `root`
219
+ * that it and resolveAllData give root), so that reshape writes nothing.
220
+ */
221
+ function withPuckRoot(data: Data): Data {
222
+ const props = { ...(data.root.props ?? data.root) };
223
+ Reflect.deleteProperty(props, 'id');
224
+ return { ...data, root: { ...data.root, props } };
225
+ }
226
+
227
+ /**
228
+ * `shown` is what Puck was handed on load; `prepare` gives a re-seed the load's shape (default props). Resolved props
229
+ * the doc never stored stay from what Puck showed, under the doc's values.
230
+ *
231
+ * A field change's entry lives until Puck hands its block over (that and every older settled entry of the block go),
232
+ * its block leaves the doc, or its resolveData throws: never on a timer, since Puck hands the block over only once
233
+ * every slot child it resolves again has answered, however long their fetches take.
234
+ */
235
+ export function createPuckBinding(
236
+ live: FrameLiveDoc,
237
+ shown: Data = readPuckData(live.doc),
238
+ prepare: (data: Data) => Data = (data) => data,
239
+ ): PuckBinding {
240
+ const shape = (data: Data) => withPuckRoot(prepare(data));
241
+ let shadow = heldViews.get(live) ?? withPuckRoot(shown);
242
+ /** The ids of `shadow`'s list items; lists the doc does not hold (resolved defaults) have none. */
243
+ let shadowIds = readItemIds(live.doc);
244
+ /**
245
+ * What waiting field changes wrote, with its ids, while Puck has handed nothing over since: the next keystroke's write
246
+ * base (`shadow` stays what Puck shows). Without it a second keystroke re-inserts the item the first one inserted.
247
+ */
248
+ let typed: { data: Data; ids: ItemIds } | null = null;
249
+ /** Field changes waiting on resolveData, or settled and waiting for Puck to hand their block over. */
250
+ let resolves: FieldResolve[] = [];
251
+ const keep = (kept: (resolve: FieldResolve) => boolean) => {
252
+ resolves = resolves.filter(kept);
253
+ };
254
+ /** `data` with each settled field change's `replace` narrowed (and consumed); null when none was handed over. */
255
+ const narrowFieldChanges = (data: Data): Data | null => {
256
+ const showing = propsById(shadow);
257
+ let changed = false;
258
+ const seen = new Set<string>();
259
+ const next = mapData(data, (id, props) => {
260
+ seen.add(id);
261
+ const resolve = resolves.find(
262
+ (candidate): candidate is SettledResolve =>
263
+ candidate.id === id && candidate.settled !== null && sameProps(candidate.settled.props, props),
264
+ );
265
+ const current = showing.get(id);
266
+ if (!resolve || !current) return props;
267
+ const at = resolves.indexOf(resolve);
268
+ // Older settled entries of the block go with it. Older pending ones stay: an older resolve that answers after
269
+ // this handover still brings a late replace, built from its own keystroke, and only its entry narrows it (an
270
+ // unmatched one would revert the teammate's values and the user's newer edit). Correctness over a tighter bound:
271
+ // only a resolveData that never answers keeps its entry for good, and Puck's own pending promise holds that call
272
+ // in memory anyway.
273
+ keep((other) => resolves.indexOf(other) > at || other.id !== id || other.settled === null);
274
+ const out = narrowed(current, resolve);
275
+ // A re-seed is needed only when Puck shows something other than what is written.
276
+ if (!sameProps(out, props)) changed = true;
277
+ return out;
278
+ });
279
+ // A block that is gone never comes back as a replace: its waiting changes go with it.
280
+ keep((resolve) => seen.has(resolve.id));
281
+ return changed ? next : null;
282
+ };
283
+ // Block props live in the doc-level `blocks` map: scoping `puck` alone would not undo them.
284
+ const listUndo = createListUndo(live.doc, ['puck', 'blocks']);
285
+ /** Writes `data` over what Puck showed (`before`, with its ids); returns `data`'s ids, or null when it held. */
286
+ const write = (before: Data, beforeIds: ItemIds, data: Data): ItemIds | null => {
287
+ if (live.held) return null;
288
+ const written = writePuckChange(live.doc, before, beforeIds, data, (names) => listUndo.track(names));
289
+ if (written.ok) return written.ids;
290
+ console.error('[live] could not write a Puck change', written.error);
291
+ live.hold(HELD_WRITE_FAILED);
292
+ return null;
293
+ };
294
+ return {
295
+ live,
296
+ get undo() {
297
+ return listUndo.undo;
298
+ },
299
+ retain: () => listUndo.retain(),
300
+ get shadow() {
301
+ return shadow;
302
+ },
303
+ change(handed) {
304
+ const fixed = narrowFieldChanges(handed);
305
+ const wasTyped = typed !== null;
306
+ typed = null;
307
+ const before = shadow;
308
+ // What Puck shows, stale copies of a late replace included: a change built on it before the re-seed lands
309
+ // differs from it only in what the user did.
310
+ shadow = handed;
311
+ const ids = write(before, shadowIds, fixed ?? handed);
312
+ if (ids) {
313
+ shadowIds = ids;
314
+ // Another block's change lacks the keystrokes a waiting resolve wrote; the doc holds them, so it is the next
315
+ // keystroke's base (as a re-seed's), or that keystroke inserts again what they inserted.
316
+ if (wasTyped && resolves.length > 0)
317
+ typed = { data: shape(keepShownProps(readPuckData(live.doc), handed)), ids: readItemIds(live.doc) };
318
+ // Puck still shows the stale copies: a re-seed shows it the doc again.
319
+ if (fixed) live.doc.transact(() => {}, RESHOW_ORIGIN);
320
+ return;
321
+ }
322
+ heldViews.set(live, handed);
323
+ },
324
+ reseed() {
325
+ if (live.held) return null;
326
+ const next = shape(keepShownProps(readPuckData(live.doc), shadow));
327
+ shadow = next;
328
+ typed = null;
329
+ shadowIds = readItemIds(live.doc);
330
+ return shadow;
331
+ },
332
+ fieldResolveStarted(id, props, parentId) {
333
+ // Puck resolves a slot child again during its parent's update, with the child as the parent held it at the
334
+ // keystroke: not the user's change, and the parent's late replace takes the children from what Puck shows.
335
+ const parent =
336
+ parentId === undefined ? undefined : resolves.find((other) => other.id === parentId && other.settled);
337
+ const held = parent?.settled ? childProps(parent.settled.props, id) : undefined;
338
+ if (held && sameProps(held, props)) return () => {};
339
+ const before = propsById(shadow).get(id) ?? {};
340
+ const keys = differing(props, before);
341
+ // Written now, over what Puck showed at the keystroke (and the keystrokes before it Puck has not handed over):
342
+ // whatever its delayed replace carries, the edit is in.
343
+ const base = typed ?? { data: shadow, ids: shadowIds };
344
+ const data = mapData(base.data, (block, own) => (block === id ? props : own));
345
+ const ids = write(base.data, base.ids, data);
346
+ if (ids) typed = { data, ids };
347
+ const resolve: FieldResolve = { id, wrote: { before, props, keys }, settled: null };
348
+ // Kept until Puck hands its block over, its resolveData throws, or its block goes: a late replace that finds no
349
+ // entry would write its stale copies back.
350
+ resolves = [...resolves, resolve];
351
+ return (resolved) => {
352
+ if (resolved === null) {
353
+ keep((other) => other !== resolve);
354
+ takeBack(resolve);
355
+ return;
356
+ }
357
+ const settledProps = { ...props, ...resolved };
358
+ resolve.settled = { props: settledProps, derived: differing(settledProps, props) };
359
+ };
360
+ },
361
+ fieldResolvesWaiting: () => resolves.length,
362
+ };
363
+
364
+ /**
365
+ * Puck applies nothing when resolveData throws (the field shows the typing until it loses focus): take back what
366
+ * the keystroke wrote, where no one changed it since.
367
+ */
368
+ function takeBack(resolve: FieldResolve): void {
369
+ const { before, props, keys } = resolve.wrote;
370
+ const doc = readPuckData(live.doc);
371
+ const now = propsById(doc).get(resolve.id);
372
+ if (!now) return;
373
+ const restored: Props = { ...now };
374
+ for (const key of keys) {
375
+ if (!same(now[key], props[key])) continue;
376
+ if (key in before) restored[key] = before[key];
377
+ else Reflect.deleteProperty(restored, key);
378
+ }
379
+ write(
380
+ doc,
381
+ readItemIds(live.doc),
382
+ mapData(doc, (block, own) => (block === resolve.id ? restored : own)),
383
+ );
384
+ }
385
+ }
386
+
387
+ /**
388
+ * `config` with every resolveData reporting the field changes that run it (trigger `replace`) to the binding, at the
389
+ * keystroke and once it answers; every other trigger (load, insert, move, force) is passed through untouched.
390
+ */
391
+ export function trackFieldResolves(
392
+ config: Config,
393
+ binding: () => Pick<PuckBinding, 'fieldResolveStarted'> | null,
394
+ ): Config {
395
+ // Synchronous with the keystroke: Puck calls resolveData before its first await (resolveComponentData).
396
+ const started = (props: Props | undefined, trigger: string, parent: { props?: Props } | null | undefined) => {
397
+ if (trigger !== 'replace') return undefined;
398
+ const parentId = typeof parent?.props?.id === 'string' ? parent.props.id : undefined;
399
+ const id = typeof props?.id === 'string' ? props.id : ROOT_ID;
400
+ return binding()?.fieldResolveStarted(id, props ?? {}, parentId);
401
+ };
402
+ const track = (resolveData: ResolveData | undefined): ResolveData | undefined =>
403
+ resolveData &&
404
+ (async (data, params) => {
405
+ const settle = started(data.props, params.trigger, params.parent);
406
+ try {
407
+ const result = await resolveData(data, params);
408
+ settle?.(result.props ?? {});
409
+ return result;
410
+ } catch (error) {
411
+ settle?.(null);
412
+ throw error;
413
+ }
414
+ });
415
+ const trackRoot = (resolveData: RootResolveData | undefined): RootResolveData | undefined =>
416
+ resolveData &&
417
+ (async (data: Parameters<RootResolveData>[0], params: Parameters<RootResolveData>[1]) => {
418
+ const settle = started(data.props, params.trigger, params.parent);
419
+ try {
420
+ const result = await resolveData(data, params);
421
+ settle?.(result.props ?? {});
422
+ return result;
423
+ } catch (error) {
424
+ settle?.(null);
425
+ throw error;
426
+ }
427
+ });
428
+ const { root } = config;
429
+ return {
430
+ ...config,
431
+ ...(root ? { root: { ...root, resolveData: trackRoot(root.resolveData) } } : {}),
432
+ components: Object.fromEntries(
433
+ Object.entries(config.components).map(([name, component]) => [
434
+ name,
435
+ { ...component, resolveData: track(component.resolveData) },
436
+ ]),
437
+ ),
438
+ };
439
+ }
440
+
441
+ type ResolveData = NonNullable<ComponentConfig['resolveData']>;
442
+ type RootResolveData = NonNullable<NonNullable<Config['root']>['resolveData']>;
443
+
444
+ const PuckBindingContext = createContext<PuckBinding | null>(null);
445
+
446
+ /** Puck's overrides are module-stable, so the parts inside <Puck> read the binding from here. */
447
+ export function PuckBindingProvider({ binding, children }: { binding: PuckBinding | null; children: ReactNode }) {
448
+ return <PuckBindingContext.Provider value={binding}>{children}</PuckBindingContext.Provider>;
449
+ }
450
+
451
+ const usePuck = createUsePuck();
452
+
453
+ /**
454
+ * Inside <Puck>: shows each change Puck did not make (a teammate's, a restore, undo) once per frame, outside Puck's
455
+ * history; reports the selected block to teammates; routes the undo keys of the editor window to this user's undo.
456
+ */
457
+ export function PuckLiveBridge(): null {
458
+ const binding = useContext(PuckBindingContext);
459
+ const channel = useDocChannel();
460
+ const dispatch = usePuck((state) => state.dispatch);
461
+ const getPuck = useGetPuck();
462
+ const selected = usePuck((state) => state.selectedItem?.props.id ?? null);
463
+
464
+ useEffect(() => {
465
+ if (binding) channel?.setSelection(binding.live.docKey, typeof selected === 'string' ? selected : null);
466
+ }, [binding, channel, selected]);
467
+
468
+ useEffect(() => {
469
+ if (!binding) return undefined;
470
+ let frame = 0;
471
+ let refocus = 0;
472
+ const onTransaction = (transaction: Y.Transaction) => {
473
+ if (transaction.origin === LOCAL_ORIGIN || frame !== 0) return;
474
+ frame = requestAnimationFrame(() => {
475
+ frame = 0;
476
+ const data = binding.reseed();
477
+ if (!data) return;
478
+ const { field } = getPuck().appState.ui;
479
+ dispatch({ type: 'setData', data: () => data, recordHistory: false });
480
+ if (!field.focus) return;
481
+ // Puck keeps a focused field's own value (it syncs only while its store says unfocused): unfocus it there for
482
+ // one render so it shows the change, then focus it again; the input keeps DOM focus and caret throughout.
483
+ dispatch({ type: 'setUi', ui: { field: { ...field, focus: null } } });
484
+ refocus = requestAnimationFrame(() => dispatch({ type: 'setUi', ui: { field } }));
485
+ });
486
+ };
487
+ binding.live.doc.on('afterTransaction', onTransaction);
488
+ const stopKeys = interceptUndoKeys([window], binding.undo);
489
+ return () => {
490
+ binding.live.doc.off('afterTransaction', onTransaction);
491
+ cancelAnimationFrame(frame);
492
+ cancelAnimationFrame(refocus);
493
+ stopKeys();
494
+ };
495
+ }, [binding, dispatch, getPuck]);
496
+ return null;
497
+ }
498
+
499
+ /** Routes the canvas iframe's undo keys to this user's undo; re-runs when Puck replaces the iframe. */
500
+ export function useCanvasUndoKeys(canvas: Document | undefined): void {
501
+ const binding = useContext(PuckBindingContext);
502
+ useEffect(() => {
503
+ const view = canvas?.defaultView;
504
+ if (!binding || !view) return undefined;
505
+ return interceptUndoKeys([view], binding.undo);
506
+ }, [binding, canvas]);
507
+ }
508
+
509
+ /** The peers selecting each block of `docKey`, by block id. */
510
+ export function usePeerOutlines(docKey: string): Record<string, PresencePeer[]> {
511
+ const peers = usePresencePeers(docKey);
512
+ return useMemo(() => {
513
+ const byBlock: Record<string, PresencePeer[]> = {};
514
+ for (const peer of peers) {
515
+ const { blockId } = peer.selection;
516
+ if (blockId !== null) byBlock[blockId] = [...(byBlock[blockId] ?? []), peer];
517
+ }
518
+ return byBlock;
519
+ }, [peers]);
520
+ }
521
+
522
+ /** A stable colour per user, so each teammate's outline reads the same everywhere. */
523
+ function peerColour(userId: string): string {
524
+ let hash = 0;
525
+ for (const char of userId) hash = (hash * 31 + char.charCodeAt(0)) % 360;
526
+ return `hsl(${hash} 70% 45%)`;
527
+ }
528
+
529
+ const NO_DOC = '';
530
+
531
+ /** Puck's `componentOverlay`: outlines a block a teammate has selected, with their name. */
532
+ export function PeerOutline({ children, componentId }: { children: ReactNode; componentId: string }) {
533
+ const binding = useContext(PuckBindingContext);
534
+ const peer = usePeerOutlines(binding?.live.docKey ?? NO_DOC)[componentId]?.[0];
535
+ if (!peer) return <>{children}</>;
536
+ const colour = peerColour(peer.user.id);
537
+ return (
538
+ <>
539
+ {children}
540
+ <div
541
+ aria-hidden="true"
542
+ data-peer-outline={peer.user.id}
543
+ style={{ position: 'absolute', inset: 0, outline: `2px solid ${colour}`, pointerEvents: 'none' }}
544
+ >
545
+ <span
546
+ style={{
547
+ position: 'absolute',
548
+ top: 0,
549
+ right: 0,
550
+ background: colour,
551
+ color: 'white',
552
+ fontSize: '11px',
553
+ padding: '0 4px',
554
+ }}
555
+ >
556
+ {peer.user.name}
557
+ </span>
558
+ </div>
559
+ </>
560
+ );
561
+ }
562
+
563
+ /** Above the canvas while the replica is held: the editor is read-only, and the user's view can be copied out. */
564
+ export function PuckHeldNotice({ binding }: { binding: PuckBinding }) {
565
+ const channel = useDocChannel();
566
+ if (!binding.live.held) return null;
567
+ return (
568
+ <div role="alert" className="flex items-center gap-3 px-4 py-2 bg-yellow-11 text-yellow-02 text-sm">
569
+ <span>{channel?.held() ?? HELD_WRITE_FAILED}</span>
570
+ <button
571
+ type="button"
572
+ className="px-3 py-1 border border-line rounded"
573
+ onClick={() => void navigator.clipboard.writeText(JSON.stringify({ puckData: binding.shadow }, null, 2))}
574
+ >
575
+ Copy changes
576
+ </button>
577
+ </div>
578
+ );
579
+ }
@@ -0,0 +1,112 @@
1
+ /** Per-user undo over a shared doc: only this user's edits and restores, never a teammate's. */
2
+
3
+ import * as Y from 'yjs';
4
+ import { EDIT_ORIGIN, LOCAL_ORIGIN } from './doc-channel.js';
5
+
6
+ /** One typing burst within this window is one undo step. */
7
+ const CAPTURE_MS = 500;
8
+
9
+ /** The shared types an undo manager tracks, as Yjs types them. */
10
+ export type UndoScope = ConstructorParameters<typeof Y.UndoManager>[0];
11
+
12
+ export function createLocalUndo(scope: UndoScope): Y.UndoManager {
13
+ return new Y.UndoManager(scope, { trackedOrigins: new Set([LOCAL_ORIGIN, EDIT_ORIGIN]), captureTimeout: CAPTURE_MS });
14
+ }
15
+
16
+ /** This user's undo over a page's maps (`roots`), its list items and the arrays of its lists of primitives. */
17
+ export interface ListUndo {
18
+ undo: Y.UndoManager;
19
+ /** Adds the `a:` arrays a local write is about to create, before it writes (`applyItemChanges`'s `beforeWrite`). */
20
+ track(names: string[]): void;
21
+ /**
22
+ * Marks one mounted user (an effect); call the returned release on unmount. Once the last user releases it and none
23
+ * comes back within the commit (StrictMode remounts at once), the undo lets go of the doc: its handlers and manager.
24
+ */
25
+ retain(): () => void;
26
+ }
27
+
28
+ /**
29
+ * Local undo over the maps `roots`, `items` and the `a:` root array of every list of primitives: those present now,
30
+ * those a local write names through `track`, and those a remote transaction created (added once it ends). Without them,
31
+ * an item or primitive edit is not undoable, and Undo of a flip or a removal empties a list of primitives. `lists` is
32
+ * never in scope: only the server prunes it.
33
+ */
34
+ export function createListUndo(doc: Y.Doc, roots: string[]): ListUndo {
35
+ const arrays = () => [...doc.share.keys()].filter((name) => name.startsWith('a:'));
36
+ /**
37
+ * Attached at first use, not at creation: StrictMode builds a memoized binding twice and drops one unused, which
38
+ * then holds nothing on the doc.
39
+ */
40
+ let attached: { undo: Y.UndoManager; scoped: Set<string>; onTransaction: () => void } | null = null;
41
+ let released = false;
42
+ const attach = () => {
43
+ if (attached) return attached;
44
+ const scoped = new Set(arrays());
45
+ const undo = createLocalUndo([
46
+ ...roots.map((name) => doc.getMap(name)),
47
+ doc.getMap('items'),
48
+ ...[...scoped].map((name) => doc.getArray(name)),
49
+ ]);
50
+ let known = doc.share.size;
51
+ const onTransaction = () => {
52
+ // Only a transaction that added a root type can have created an array.
53
+ if (doc.share.size === known) return;
54
+ known = doc.share.size;
55
+ track(arrays());
56
+ };
57
+ doc.on('afterTransaction', onTransaction);
58
+ attached = { undo, scoped, onTransaction };
59
+ return attached;
60
+ };
61
+ const track = (names: string[]) => {
62
+ const { undo, scoped } = attach();
63
+ for (const name of names) {
64
+ if (scoped.has(name)) continue;
65
+ scoped.add(name);
66
+ undo.addToScope(doc.getArray(name));
67
+ }
68
+ };
69
+ let users = 0;
70
+ const retain = () => {
71
+ attach();
72
+ users += 1;
73
+ return () => {
74
+ users -= 1;
75
+ queueMicrotask(() => {
76
+ if (users > 0 || released || !attached) return;
77
+ released = true;
78
+ doc.off('afterTransaction', attached.onTransaction);
79
+ attached.undo.destroy();
80
+ });
81
+ };
82
+ };
83
+ return {
84
+ get undo() {
85
+ return attach().undo;
86
+ },
87
+ track,
88
+ retain,
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Routes mod+Z, mod+Shift+Z and mod+Y on each window to `undo`, in the capture phase so the editor's own history never
94
+ * sees them; a key inside an element marked `data-native-undo` is left to it. Returns the function that stops it.
95
+ */
96
+ export function interceptUndoKeys(targets: Window[], undo: Y.UndoManager): () => void {
97
+ const onKey = (event: KeyboardEvent) => {
98
+ if (!(event.metaKey || event.ctrlKey) || event.altKey) return;
99
+ const key = event.key.toLowerCase();
100
+ const redo = key === 'y' || (key === 'z' && event.shiftKey);
101
+ if (key !== 'z' && key !== 'y') return;
102
+ if (event.target instanceof Element && event.target.closest('[data-native-undo]')) return;
103
+ event.preventDefault();
104
+ event.stopPropagation();
105
+ if (redo) undo.redo();
106
+ else undo.undo();
107
+ };
108
+ for (const target of targets) target.addEventListener('keydown', onKey, true);
109
+ return () => {
110
+ for (const target of targets) target.removeEventListener('keydown', onKey, true);
111
+ };
112
+ }