@velastack/cms 0.1.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 (327) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +644 -0
  3. package/dist/cms.d.ts +6 -0
  4. package/dist/cms.js +30 -0
  5. package/dist/components/admin-bar/admin-bar-internal.svelte +1697 -0
  6. package/dist/components/admin-bar/admin-bar-internal.svelte.d.ts +12 -0
  7. package/dist/components/admin-bar/admin-bar.css +5 -0
  8. package/dist/components/admin-bar/admin-bar.svelte +355 -0
  9. package/dist/components/admin-bar/admin-bar.svelte.d.ts +7 -0
  10. package/dist/components/admin-bar/click-outside.d.ts +8 -0
  11. package/dist/components/admin-bar/click-outside.js +17 -0
  12. package/dist/components/admin-bar/css-root.svelte +23 -0
  13. package/dist/components/admin-bar/css-root.svelte.d.ts +19 -0
  14. package/dist/components/admin-bar/delete-page-dialog.svelte +326 -0
  15. package/dist/components/admin-bar/delete-page-dialog.svelte.d.ts +32 -0
  16. package/dist/components/admin-bar/history-panel.svelte +264 -0
  17. package/dist/components/admin-bar/history-panel.svelte.d.ts +8 -0
  18. package/dist/components/admin-bar/icons/bold.svelte +13 -0
  19. package/dist/components/admin-bar/icons/bold.svelte.d.ts +3 -0
  20. package/dist/components/admin-bar/icons/check.svelte +11 -0
  21. package/dist/components/admin-bar/icons/check.svelte.d.ts +3 -0
  22. package/dist/components/admin-bar/icons/chevron-down.svelte +11 -0
  23. package/dist/components/admin-bar/icons/chevron-down.svelte.d.ts +3 -0
  24. package/dist/components/admin-bar/icons/chevron-right.svelte +11 -0
  25. package/dist/components/admin-bar/icons/chevron-right.svelte.d.ts +3 -0
  26. package/dist/components/admin-bar/icons/chevron-up.svelte +11 -0
  27. package/dist/components/admin-bar/icons/chevron-up.svelte.d.ts +3 -0
  28. package/dist/components/admin-bar/icons/code.svelte +14 -0
  29. package/dist/components/admin-bar/icons/code.svelte.d.ts +3 -0
  30. package/dist/components/admin-bar/icons/external-link.svelte +15 -0
  31. package/dist/components/admin-bar/icons/external-link.svelte.d.ts +3 -0
  32. package/dist/components/admin-bar/icons/file.svelte +19 -0
  33. package/dist/components/admin-bar/icons/file.svelte.d.ts +3 -0
  34. package/dist/components/admin-bar/icons/heading-2.svelte +16 -0
  35. package/dist/components/admin-bar/icons/heading-2.svelte.d.ts +3 -0
  36. package/dist/components/admin-bar/icons/heading-3.svelte +17 -0
  37. package/dist/components/admin-bar/icons/heading-3.svelte.d.ts +3 -0
  38. package/dist/components/admin-bar/icons/icon.svelte +41 -0
  39. package/dist/components/admin-bar/icons/icon.svelte.d.ts +21 -0
  40. package/dist/components/admin-bar/icons/images.svelte +16 -0
  41. package/dist/components/admin-bar/icons/images.svelte.d.ts +3 -0
  42. package/dist/components/admin-bar/icons/italic.svelte +15 -0
  43. package/dist/components/admin-bar/icons/italic.svelte.d.ts +3 -0
  44. package/dist/components/admin-bar/icons/link-2-off.svelte +16 -0
  45. package/dist/components/admin-bar/icons/link-2-off.svelte.d.ts +3 -0
  46. package/dist/components/admin-bar/icons/link.svelte +14 -0
  47. package/dist/components/admin-bar/icons/link.svelte.d.ts +3 -0
  48. package/dist/components/admin-bar/icons/list-ordered.svelte +18 -0
  49. package/dist/components/admin-bar/icons/list-ordered.svelte.d.ts +3 -0
  50. package/dist/components/admin-bar/icons/list.svelte +18 -0
  51. package/dist/components/admin-bar/icons/list.svelte.d.ts +3 -0
  52. package/dist/components/admin-bar/icons/loader-circle.svelte +11 -0
  53. package/dist/components/admin-bar/icons/loader-circle.svelte.d.ts +3 -0
  54. package/dist/components/admin-bar/icons/minus.svelte +11 -0
  55. package/dist/components/admin-bar/icons/minus.svelte.d.ts +3 -0
  56. package/dist/components/admin-bar/icons/quote.svelte +24 -0
  57. package/dist/components/admin-bar/icons/quote.svelte.d.ts +3 -0
  58. package/dist/components/admin-bar/icons/search.svelte +14 -0
  59. package/dist/components/admin-bar/icons/search.svelte.d.ts +3 -0
  60. package/dist/components/admin-bar/icons/trash-2.svelte +17 -0
  61. package/dist/components/admin-bar/icons/trash-2.svelte.d.ts +3 -0
  62. package/dist/components/admin-bar/icons/triangle-alert.svelte +15 -0
  63. package/dist/components/admin-bar/icons/triangle-alert.svelte.d.ts +3 -0
  64. package/dist/components/admin-bar/icons/types.d.ts +7 -0
  65. package/dist/components/admin-bar/icons/types.js +1 -0
  66. package/dist/components/admin-bar/icons/undo-2.svelte +14 -0
  67. package/dist/components/admin-bar/icons/undo-2.svelte.d.ts +3 -0
  68. package/dist/components/admin-bar/icons/upload.svelte +15 -0
  69. package/dist/components/admin-bar/icons/upload.svelte.d.ts +3 -0
  70. package/dist/components/admin-bar/icons/x.svelte +14 -0
  71. package/dist/components/admin-bar/icons/x.svelte.d.ts +3 -0
  72. package/dist/components/admin-bar/keyboard-shortcuts-dialog.svelte +96 -0
  73. package/dist/components/admin-bar/keyboard-shortcuts-dialog.svelte.d.ts +7 -0
  74. package/dist/components/admin-bar/locales-panel.svelte +137 -0
  75. package/dist/components/admin-bar/locales-panel.svelte.d.ts +9 -0
  76. package/dist/components/admin-bar/media-panel.svelte +282 -0
  77. package/dist/components/admin-bar/media-panel.svelte.d.ts +7 -0
  78. package/dist/components/admin-bar/new-page-chooser-dialog.svelte +56 -0
  79. package/dist/components/admin-bar/new-page-chooser-dialog.svelte.d.ts +10 -0
  80. package/dist/components/admin-bar/new-page-dialog.svelte +126 -0
  81. package/dist/components/admin-bar/new-page-dialog.svelte.d.ts +14 -0
  82. package/dist/components/admin-bar/page-config.d.ts +61 -0
  83. package/dist/components/admin-bar/page-config.js +24 -0
  84. package/dist/components/admin-bar/pages-panel.svelte +639 -0
  85. package/dist/components/admin-bar/pages-panel.svelte.d.ts +13 -0
  86. package/dist/components/admin-bar/panel-footer.svelte +21 -0
  87. package/dist/components/admin-bar/panel-footer.svelte.d.ts +8 -0
  88. package/dist/components/admin-bar/panel-header.svelte +29 -0
  89. package/dist/components/admin-bar/panel-header.svelte.d.ts +10 -0
  90. package/dist/components/admin-bar/panel.svelte +41 -0
  91. package/dist/components/admin-bar/panel.svelte.d.ts +10 -0
  92. package/dist/components/admin-bar/publish-dialog.svelte +387 -0
  93. package/dist/components/admin-bar/publish-dialog.svelte.d.ts +16 -0
  94. package/dist/components/admin-bar/resolve-route.d.ts +20 -0
  95. package/dist/components/admin-bar/resolve-route.js +50 -0
  96. package/dist/components/admin-bar/seo-panel.svelte +387 -0
  97. package/dist/components/admin-bar/seo-panel.svelte.d.ts +7 -0
  98. package/dist/components/admin-bar/share-preview-link-dialog.svelte +97 -0
  99. package/dist/components/admin-bar/share-preview-link-dialog.svelte.d.ts +9 -0
  100. package/dist/components/admin-bar/site-settings-panel.svelte +225 -0
  101. package/dist/components/admin-bar/site-settings-panel.svelte.d.ts +7 -0
  102. package/dist/components/admin-bar/status-pill.svelte +49 -0
  103. package/dist/components/admin-bar/status-pill.svelte.d.ts +11 -0
  104. package/dist/components/admin-bar/theme.svelte.d.ts +16 -0
  105. package/dist/components/admin-bar/theme.svelte.js +39 -0
  106. package/dist/components/admin-bar/ui/badge/badge.svelte +57 -0
  107. package/dist/components/admin-bar/ui/badge/badge.svelte.d.ts +16 -0
  108. package/dist/components/admin-bar/ui/badge/index.d.ts +4 -0
  109. package/dist/components/admin-bar/ui/badge/index.js +4 -0
  110. package/dist/components/admin-bar/ui/button/button.svelte +73 -0
  111. package/dist/components/admin-bar/ui/button/button.svelte.d.ts +16 -0
  112. package/dist/components/admin-bar/ui/button/index.d.ts +4 -0
  113. package/dist/components/admin-bar/ui/button/index.js +4 -0
  114. package/dist/components/admin-bar/ui/collapsible/collapsible-content.svelte +7 -0
  115. package/dist/components/admin-bar/ui/collapsible/collapsible-content.svelte.d.ts +4 -0
  116. package/dist/components/admin-bar/ui/collapsible/collapsible-trigger.svelte +7 -0
  117. package/dist/components/admin-bar/ui/collapsible/collapsible-trigger.svelte.d.ts +4 -0
  118. package/dist/components/admin-bar/ui/collapsible/collapsible.svelte +7 -0
  119. package/dist/components/admin-bar/ui/collapsible/collapsible.svelte.d.ts +4 -0
  120. package/dist/components/admin-bar/ui/collapsible/index.d.ts +4 -0
  121. package/dist/components/admin-bar/ui/collapsible/index.js +6 -0
  122. package/dist/components/admin-bar/ui/dialog/dialog-close.svelte +7 -0
  123. package/dist/components/admin-bar/ui/dialog/dialog-close.svelte.d.ts +4 -0
  124. package/dist/components/admin-bar/ui/dialog/dialog-content.svelte +46 -0
  125. package/dist/components/admin-bar/ui/dialog/dialog-content.svelte.d.ts +11 -0
  126. package/dist/components/admin-bar/ui/dialog/dialog-description.svelte +17 -0
  127. package/dist/components/admin-bar/ui/dialog/dialog-description.svelte.d.ts +4 -0
  128. package/dist/components/admin-bar/ui/dialog/dialog-footer.svelte +23 -0
  129. package/dist/components/admin-bar/ui/dialog/dialog-footer.svelte.d.ts +5 -0
  130. package/dist/components/admin-bar/ui/dialog/dialog-header.svelte +20 -0
  131. package/dist/components/admin-bar/ui/dialog/dialog-header.svelte.d.ts +5 -0
  132. package/dist/components/admin-bar/ui/dialog/dialog-overlay.svelte +20 -0
  133. package/dist/components/admin-bar/ui/dialog/dialog-overlay.svelte.d.ts +4 -0
  134. package/dist/components/admin-bar/ui/dialog/dialog-portal.svelte +7 -0
  135. package/dist/components/admin-bar/ui/dialog/dialog-portal.svelte.d.ts +3 -0
  136. package/dist/components/admin-bar/ui/dialog/dialog-title.svelte +17 -0
  137. package/dist/components/admin-bar/ui/dialog/dialog-title.svelte.d.ts +4 -0
  138. package/dist/components/admin-bar/ui/dialog/dialog-trigger.svelte +7 -0
  139. package/dist/components/admin-bar/ui/dialog/dialog-trigger.svelte.d.ts +4 -0
  140. package/dist/components/admin-bar/ui/dialog/dialog.svelte +7 -0
  141. package/dist/components/admin-bar/ui/dialog/dialog.svelte.d.ts +3 -0
  142. package/dist/components/admin-bar/ui/dialog/index.d.ts +11 -0
  143. package/dist/components/admin-bar/ui/dialog/index.js +13 -0
  144. package/dist/components/admin-bar/ui/input/index.d.ts +3 -0
  145. package/dist/components/admin-bar/ui/input/index.js +3 -0
  146. package/dist/components/admin-bar/ui/input/input.svelte +24 -0
  147. package/dist/components/admin-bar/ui/input/input.svelte.d.ts +5 -0
  148. package/dist/components/admin-bar/ui/kbd/index.d.ts +4 -0
  149. package/dist/components/admin-bar/ui/kbd/index.js +6 -0
  150. package/dist/components/admin-bar/ui/kbd/kbd-group.svelte +20 -0
  151. package/dist/components/admin-bar/ui/kbd/kbd-group.svelte.d.ts +5 -0
  152. package/dist/components/admin-bar/ui/kbd/kbd-shortcut.svelte +52 -0
  153. package/dist/components/admin-bar/ui/kbd/kbd-shortcut.svelte.d.ts +8 -0
  154. package/dist/components/admin-bar/ui/kbd/kbd.svelte +27 -0
  155. package/dist/components/admin-bar/ui/kbd/kbd.svelte.d.ts +5 -0
  156. package/dist/components/admin-bar/ui/label/index.d.ts +3 -0
  157. package/dist/components/admin-bar/ui/label/index.js +3 -0
  158. package/dist/components/admin-bar/ui/label/label.svelte +20 -0
  159. package/dist/components/admin-bar/ui/label/label.svelte.d.ts +4 -0
  160. package/dist/components/admin-bar/ui/menubar/index.d.ts +18 -0
  161. package/dist/components/admin-bar/ui/menubar/index.js +20 -0
  162. package/dist/components/admin-bar/ui/menubar/menubar-checkbox-item.svelte +46 -0
  163. package/dist/components/admin-bar/ui/menubar/menubar-checkbox-item.svelte.d.ts +10 -0
  164. package/dist/components/admin-bar/ui/menubar/menubar-content.svelte +28 -0
  165. package/dist/components/admin-bar/ui/menubar/menubar-content.svelte.d.ts +4 -0
  166. package/dist/components/admin-bar/ui/menubar/menubar-group-heading.svelte +25 -0
  167. package/dist/components/admin-bar/ui/menubar/menubar-group-heading.svelte.d.ts +8 -0
  168. package/dist/components/admin-bar/ui/menubar/menubar-group.svelte +12 -0
  169. package/dist/components/admin-bar/ui/menubar/menubar-group.svelte.d.ts +7 -0
  170. package/dist/components/admin-bar/ui/menubar/menubar-item.svelte +27 -0
  171. package/dist/components/admin-bar/ui/menubar/menubar-item.svelte.d.ts +8 -0
  172. package/dist/components/admin-bar/ui/menubar/menubar-label.svelte +25 -0
  173. package/dist/components/admin-bar/ui/menubar/menubar-label.svelte.d.ts +8 -0
  174. package/dist/components/admin-bar/ui/menubar/menubar-menu.svelte +7 -0
  175. package/dist/components/admin-bar/ui/menubar/menubar-menu.svelte.d.ts +3 -0
  176. package/dist/components/admin-bar/ui/menubar/menubar-portal.svelte +7 -0
  177. package/dist/components/admin-bar/ui/menubar/menubar-portal.svelte.d.ts +3 -0
  178. package/dist/components/admin-bar/ui/menubar/menubar-radio-group.svelte +11 -0
  179. package/dist/components/admin-bar/ui/menubar/menubar-radio-group.svelte.d.ts +4 -0
  180. package/dist/components/admin-bar/ui/menubar/menubar-radio-item.svelte +37 -0
  181. package/dist/components/admin-bar/ui/menubar/menubar-radio-item.svelte.d.ts +8 -0
  182. package/dist/components/admin-bar/ui/menubar/menubar-separator.svelte +17 -0
  183. package/dist/components/admin-bar/ui/menubar/menubar-separator.svelte.d.ts +4 -0
  184. package/dist/components/admin-bar/ui/menubar/menubar-shortcut.svelte +23 -0
  185. package/dist/components/admin-bar/ui/menubar/menubar-shortcut.svelte.d.ts +5 -0
  186. package/dist/components/admin-bar/ui/menubar/menubar-sub-content.svelte +20 -0
  187. package/dist/components/admin-bar/ui/menubar/menubar-sub-content.svelte.d.ts +4 -0
  188. package/dist/components/admin-bar/ui/menubar/menubar-sub-trigger.svelte +29 -0
  189. package/dist/components/admin-bar/ui/menubar/menubar-sub-trigger.svelte.d.ts +8 -0
  190. package/dist/components/admin-bar/ui/menubar/menubar-sub.svelte +7 -0
  191. package/dist/components/admin-bar/ui/menubar/menubar-sub.svelte.d.ts +4 -0
  192. package/dist/components/admin-bar/ui/menubar/menubar-trigger.svelte +20 -0
  193. package/dist/components/admin-bar/ui/menubar/menubar-trigger.svelte.d.ts +4 -0
  194. package/dist/components/admin-bar/ui/menubar/menubar.svelte +20 -0
  195. package/dist/components/admin-bar/ui/menubar/menubar.svelte.d.ts +4 -0
  196. package/dist/components/admin-bar/ui/select/index.d.ts +12 -0
  197. package/dist/components/admin-bar/ui/select/index.js +14 -0
  198. package/dist/components/admin-bar/ui/select/select-content.svelte +45 -0
  199. package/dist/components/admin-bar/ui/select/select-content.svelte.d.ts +11 -0
  200. package/dist/components/admin-bar/ui/select/select-group-heading.svelte +21 -0
  201. package/dist/components/admin-bar/ui/select/select-group-heading.svelte.d.ts +10 -0
  202. package/dist/components/admin-bar/ui/select/select-group.svelte +17 -0
  203. package/dist/components/admin-bar/ui/select/select-group.svelte.d.ts +4 -0
  204. package/dist/components/admin-bar/ui/select/select-item.svelte +40 -0
  205. package/dist/components/admin-bar/ui/select/select-item.svelte.d.ts +5 -0
  206. package/dist/components/admin-bar/ui/select/select-label.svelte +20 -0
  207. package/dist/components/admin-bar/ui/select/select-label.svelte.d.ts +6 -0
  208. package/dist/components/admin-bar/ui/select/select-portal.svelte +7 -0
  209. package/dist/components/admin-bar/ui/select/select-portal.svelte.d.ts +3 -0
  210. package/dist/components/admin-bar/ui/select/select-scroll-down-button.svelte +23 -0
  211. package/dist/components/admin-bar/ui/select/select-scroll-down-button.svelte.d.ts +5 -0
  212. package/dist/components/admin-bar/ui/select/select-scroll-up-button.svelte +23 -0
  213. package/dist/components/admin-bar/ui/select/select-scroll-up-button.svelte.d.ts +5 -0
  214. package/dist/components/admin-bar/ui/select/select-separator.svelte +21 -0
  215. package/dist/components/admin-bar/ui/select/select-separator.svelte.d.ts +4 -0
  216. package/dist/components/admin-bar/ui/select/select-trigger.svelte +31 -0
  217. package/dist/components/admin-bar/ui/select/select-trigger.svelte.d.ts +8 -0
  218. package/dist/components/admin-bar/ui/select/select.svelte +11 -0
  219. package/dist/components/admin-bar/ui/select/select.svelte.d.ts +3 -0
  220. package/dist/components/admin-bar/ui/separator/index.d.ts +2 -0
  221. package/dist/components/admin-bar/ui/separator/index.js +4 -0
  222. package/dist/components/admin-bar/ui/separator/separator.svelte +21 -0
  223. package/dist/components/admin-bar/ui/separator/separator.svelte.d.ts +4 -0
  224. package/dist/components/admin-bar/ui/textarea/index.d.ts +3 -0
  225. package/dist/components/admin-bar/ui/textarea/index.js +3 -0
  226. package/dist/components/admin-bar/ui/textarea/textarea.svelte +21 -0
  227. package/dist/components/admin-bar/ui/textarea/textarea.svelte.d.ts +5 -0
  228. package/dist/components/admin-bar/user-avatar.svelte +29 -0
  229. package/dist/components/admin-bar/user-avatar.svelte.d.ts +7 -0
  230. package/dist/components/admin-bar/utils.d.ts +10 -0
  231. package/dist/components/admin-bar/utils.js +46 -0
  232. package/dist/components/admin-bar/variants.d.ts +20 -0
  233. package/dist/components/admin-bar/variants.js +14 -0
  234. package/dist/components/cms/cms-boolean.svelte +102 -0
  235. package/dist/components/cms/cms-boolean.svelte.d.ts +10 -0
  236. package/dist/components/cms/cms-date-time-editable.svelte +66 -0
  237. package/dist/components/cms/cms-date-time-editable.svelte.d.ts +11 -0
  238. package/dist/components/cms/cms-date-time.svelte +67 -0
  239. package/dist/components/cms/cms-date-time.svelte.d.ts +19 -0
  240. package/dist/components/cms/cms-entries.svelte +24 -0
  241. package/dist/components/cms/cms-entries.svelte.d.ts +31 -0
  242. package/dist/components/cms/cms-image-editable.svelte +439 -0
  243. package/dist/components/cms/cms-image-editable.svelte.d.ts +11 -0
  244. package/dist/components/cms/cms-image.svelte +78 -0
  245. package/dist/components/cms/cms-image.svelte.d.ts +18 -0
  246. package/dist/components/cms/cms-link-editable.svelte +429 -0
  247. package/dist/components/cms/cms-link-editable.svelte.d.ts +13 -0
  248. package/dist/components/cms/cms-link.svelte +92 -0
  249. package/dist/components/cms/cms-link.svelte.d.ts +25 -0
  250. package/dist/components/cms/cms-markdown-editable.svelte +74 -0
  251. package/dist/components/cms/cms-markdown-editable.svelte.d.ts +9 -0
  252. package/dist/components/cms/cms-markdown.svelte +56 -0
  253. package/dist/components/cms/cms-markdown.svelte.d.ts +10 -0
  254. package/dist/components/cms/cms-media-picker.svelte +150 -0
  255. package/dist/components/cms/cms-media-picker.svelte.d.ts +8 -0
  256. package/dist/components/cms/cms-number-editable.svelte +77 -0
  257. package/dist/components/cms/cms-number-editable.svelte.d.ts +13 -0
  258. package/dist/components/cms/cms-number.svelte +63 -0
  259. package/dist/components/cms/cms-number.svelte.d.ts +16 -0
  260. package/dist/components/cms/cms-repeater-editable.svelte +137 -0
  261. package/dist/components/cms/cms-repeater-editable.svelte.d.ts +31 -0
  262. package/dist/components/cms/cms-repeater.svelte +55 -0
  263. package/dist/components/cms/cms-repeater.svelte.d.ts +30 -0
  264. package/dist/components/cms/cms-rich-text-editable.svelte +101 -0
  265. package/dist/components/cms/cms-rich-text-editable.svelte.d.ts +9 -0
  266. package/dist/components/cms/cms-rich-text-toolbar.svelte +246 -0
  267. package/dist/components/cms/cms-rich-text-toolbar.svelte.d.ts +9 -0
  268. package/dist/components/cms/cms-rich-text.svelte +74 -0
  269. package/dist/components/cms/cms-rich-text.svelte.d.ts +10 -0
  270. package/dist/components/cms/cms-store.svelte.d.ts +294 -0
  271. package/dist/components/cms/cms-store.svelte.js +625 -0
  272. package/dist/components/cms/cms-text.svelte +131 -0
  273. package/dist/components/cms/cms-text.svelte.d.ts +11 -0
  274. package/dist/components/cms/index.d.ts +13 -0
  275. package/dist/components/cms/index.js +11 -0
  276. package/dist/components/cms/install-scope.svelte.d.ts +7 -0
  277. package/dist/components/cms/install-scope.svelte.js +33 -0
  278. package/dist/components/cms/locale-merge.d.ts +41 -0
  279. package/dist/components/cms/locale-merge.js +77 -0
  280. package/dist/components/cms/overlay-sync.d.ts +82 -0
  281. package/dist/components/cms/overlay-sync.js +76 -0
  282. package/dist/components/cms/path.d.ts +30 -0
  283. package/dist/components/cms/path.js +156 -0
  284. package/dist/components/cms/scope.d.ts +120 -0
  285. package/dist/components/cms/scope.js +23 -0
  286. package/dist/index.d.ts +27 -0
  287. package/dist/index.js +28 -0
  288. package/dist/srv/README.md +341 -0
  289. package/dist/srv/api-adapter.d.ts +20 -0
  290. package/dist/srv/api-adapter.js +178 -0
  291. package/dist/srv/cms.d.ts +62 -0
  292. package/dist/srv/cms.js +35 -0
  293. package/dist/srv/index.d.ts +5 -0
  294. package/dist/srv/index.js +4 -0
  295. package/dist/srv/load-cms.d.ts +105 -0
  296. package/dist/srv/load-cms.js +227 -0
  297. package/dist/srv/mock-adapter.d.ts +96 -0
  298. package/dist/srv/mock-adapter.js +171 -0
  299. package/dist/srv/types.d.ts +114 -0
  300. package/dist/srv/types.js +1 -0
  301. package/package.json +116 -0
  302. package/plugin/README.md +137 -0
  303. package/plugin/dist/adapter.d.ts +35 -0
  304. package/plugin/dist/adapter.js +346 -0
  305. package/plugin/dist/adapter.js.map +1 -0
  306. package/plugin/dist/build-state.d.ts +10 -0
  307. package/plugin/dist/build-state.js +26 -0
  308. package/plugin/dist/build-state.js.map +1 -0
  309. package/plugin/dist/fallback-shim.js +194 -0
  310. package/plugin/dist/index.d.ts +56 -0
  311. package/plugin/dist/index.js +396 -0
  312. package/plugin/dist/index.js.map +1 -0
  313. package/plugin/dist/manifest.d.ts +76 -0
  314. package/plugin/dist/manifest.js +367 -0
  315. package/plugin/dist/manifest.js.map +1 -0
  316. package/plugin/dist/media.d.ts +36 -0
  317. package/plugin/dist/media.js +153 -0
  318. package/plugin/dist/media.js.map +1 -0
  319. package/plugin/dist/parse-svelte.d.ts +35 -0
  320. package/plugin/dist/parse-svelte.js +120 -0
  321. package/plugin/dist/parse-svelte.js.map +1 -0
  322. package/plugin/dist/route-tree.d.ts +27 -0
  323. package/plugin/dist/route-tree.js +69 -0
  324. package/plugin/dist/route-tree.js.map +1 -0
  325. package/plugin/dist/transforms.d.ts +42 -0
  326. package/plugin/dist/transforms.js +95 -0
  327. package/plugin/dist/transforms.js.map +1 -0
@@ -0,0 +1,178 @@
1
+ import { building } from '$app/environment';
2
+ import { buildConfig } from 'virtual:vela-cms/build-config';
3
+ /**
4
+ * The Vite plugin generates `virtual:vela-cms/build-config` with the
5
+ * project's resolved `{ uploadsBase, mediaPrefix }` (or `null` when the
6
+ * customer hasn't passed `cms({ endpoint })`). Inlining the value via a
7
+ * virtual module is the only way it survives into SvelteKit's prerender
8
+ * worker thread, which doesn't share `globalThis` with the plugin process.
9
+ */
10
+ const getBuildMediaConfig = () => {
11
+ if (!building)
12
+ return null;
13
+ return buildConfig.media;
14
+ };
15
+ const RELATIVE_UPLOADS_RE = /^\/uploads\/([^/?#]+)$/;
16
+ /**
17
+ * Deep-clone `value` and replace every `/uploads/<file>` (relative) and
18
+ * `<uploadsBase>/<file>` (absolute) string with `<mediaPrefix>/<file>`. Pure;
19
+ * cycle-safe via a WeakMap. Mirrors the helper in `plugin/src/media.ts` —
20
+ * deliberately duplicated to keep the runtime adapter free of plugin imports.
21
+ */
22
+ const rewriteMediaUrls = (value, uploadsBase, mediaPrefix) => {
23
+ const seen = new WeakMap();
24
+ const prefix = `${uploadsBase}/`;
25
+ const normalizedPrefix = mediaPrefix.replace(/\/$/, '');
26
+ const walk = (v) => {
27
+ if (typeof v === 'string') {
28
+ const m = RELATIVE_UPLOADS_RE.exec(v);
29
+ if (m)
30
+ return `${normalizedPrefix}/${m[1]}`;
31
+ if (v.startsWith(prefix)) {
32
+ const rest = v.slice(prefix.length).split(/[?#]/)[0];
33
+ if (rest && !rest.includes('/'))
34
+ return `${normalizedPrefix}/${rest}`;
35
+ }
36
+ return v;
37
+ }
38
+ if (!v || typeof v !== 'object')
39
+ return v;
40
+ const cached = seen.get(v);
41
+ if (cached !== undefined)
42
+ return cached;
43
+ if (Array.isArray(v)) {
44
+ const arr = [];
45
+ seen.set(v, arr);
46
+ for (const x of v)
47
+ arr.push(walk(x));
48
+ return arr;
49
+ }
50
+ const obj = {};
51
+ seen.set(v, obj);
52
+ for (const k of Object.keys(v)) {
53
+ obj[k] = walk(v[k]);
54
+ }
55
+ return obj;
56
+ };
57
+ return walk(value);
58
+ };
59
+ /**
60
+ * HTTP-backed adapter that talks to a remote @velastack/cms backend.
61
+ *
62
+ * Mirrors the in-memory mock's wire shape (one GET `/docs` per scope query;
63
+ * GET `/pages` for entry enumeration) so the same backend powers both the
64
+ * in-process mock and this adapter while the migration is in flight. Forwards
65
+ * `previewKey` as `?preview=…` so the backend overlays pending release edits
66
+ * when present. Uses the request-scoped `context.fetch` so SvelteKit can
67
+ * forward cookies during SSR.
68
+ */
69
+ export const apiAdapter = (options) => {
70
+ const endpoint = options.endpoint.replace(/\/$/, '');
71
+ return {
72
+ endpoint,
73
+ async fetchDocs(queries, context) {
74
+ const out = {};
75
+ const mediaConfig = getBuildMediaConfig();
76
+ const extraSuffix = context.versionKey
77
+ ? `&version=${encodeURIComponent(context.versionKey)}`
78
+ : context.previewKey
79
+ ? `&preview=${encodeURIComponent(context.previewKey)}`
80
+ : '';
81
+ await Promise.all(queries.map(async (q) => {
82
+ const qs = new URLSearchParams({
83
+ kind: q.kind,
84
+ routeId: q.routeId,
85
+ params: JSON.stringify(q.params),
86
+ locale: q.locale
87
+ }).toString();
88
+ const res = await context.fetch(`${endpoint}/docs?${qs}${extraSuffix}`, {
89
+ credentials: 'include'
90
+ });
91
+ if (res.status === 404)
92
+ return;
93
+ if (!res.ok) {
94
+ throw new Error(`apiAdapter.fetchDocs ${q.scopeId}: ${res.status}`);
95
+ }
96
+ const body = (await res.json());
97
+ if ('kind' in body) {
98
+ out[q.scopeId] = body;
99
+ }
100
+ else {
101
+ const contents = mediaConfig
102
+ ? rewriteMediaUrls(body.contents, mediaConfig.uploadsBase, mediaConfig.mediaPrefix)
103
+ : body.contents;
104
+ out[q.scopeId] = { contents };
105
+ }
106
+ }));
107
+ return out;
108
+ },
109
+ async fetchSite(context) {
110
+ const qs = new URLSearchParams();
111
+ if (context.versionKey)
112
+ qs.set('version', context.versionKey);
113
+ else if (context.previewKey)
114
+ qs.set('preview', context.previewKey);
115
+ const suffix = qs.toString() ? `?${qs}` : '';
116
+ const res = await context.fetch(`${endpoint}/site${suffix}`, {
117
+ credentials: 'include'
118
+ });
119
+ if (res.status === 404)
120
+ return {};
121
+ if (!res.ok)
122
+ throw new Error(`apiAdapter.fetchSite: ${res.status}`);
123
+ const body = (await res.json());
124
+ const mediaConfig = getBuildMediaConfig();
125
+ const contents = mediaConfig
126
+ ? rewriteMediaUrls(body.contents, mediaConfig.uploadsBase, mediaConfig.mediaPrefix)
127
+ : body.contents;
128
+ return contents ?? {};
129
+ },
130
+ async fetchEntries(routeId, context) {
131
+ // Without `previewKey`: `/pages` is read-public; the backend returns
132
+ // published entries only when no `cms_session` cookie is present.
133
+ // For prerender we don't pass a cookie — we get published-only by
134
+ // construction. We still filter `isDraft` / `isDeletePending` /
135
+ // `gone` as a defensive belt-and-suspenders. Tombstoned entries
136
+ // with `redirectTo` are kept so prerender visits the URL and
137
+ // SvelteKit emits the redirect file.
138
+ //
139
+ // With `previewKey`: forward as `?preview=…` so the backend overlays
140
+ // the matching open release, and skip the filter so the editor sees
141
+ // staged additions/deletions.
142
+ //
143
+ // With `versionKey`: forward as `?version=…`; the backend returns
144
+ // the entry list as it was at that release's publish time. No drafts,
145
+ // no pending deletes — past releases are immutable.
146
+ const qs = new URLSearchParams({ locale: context.locale });
147
+ if (context.versionKey)
148
+ qs.set('version', context.versionKey);
149
+ else if (context.previewKey)
150
+ qs.set('preview', context.previewKey);
151
+ const res = await context.fetch(`${endpoint}/pages?${qs}`, {
152
+ credentials: 'include'
153
+ });
154
+ if (!res.ok)
155
+ throw new Error(`apiAdapter.fetchEntries: ${res.status}`);
156
+ const body = (await res.json());
157
+ const route = body.routes.find((r) => r.routeId === routeId);
158
+ if (!route)
159
+ return [];
160
+ const entries = context.versionKey || context.previewKey
161
+ ? route.entries
162
+ : route.entries.filter((e) => !e.isDraft && !e.isDeletePending && !e.gone);
163
+ const mediaConfig = getBuildMediaConfig();
164
+ return entries.map((e) => {
165
+ const metadata = e.metadata ?? {};
166
+ const rewritten = mediaConfig
167
+ ? rewriteMediaUrls(metadata, mediaConfig.uploadsBase, mediaConfig.mediaPrefix)
168
+ : metadata;
169
+ return {
170
+ params: e.params,
171
+ metadata: rewritten,
172
+ ...(e.redirectTo ? { redirectTo: e.redirectTo } : {}),
173
+ ...(e.gone ? { gone: true } : {})
174
+ };
175
+ });
176
+ }
177
+ };
178
+ };
@@ -0,0 +1,62 @@
1
+ import type { ServerLoadEvent } from '@sveltejs/kit';
2
+ import type { RouteId, RouteParams } from '$app/types';
3
+ import { type LoadCmsResult } from './load-cms.js';
4
+ import type { CmsAdapter, CmsEntry, SiteSchema } from './types.js';
5
+ export type CreateCmsOptions = {
6
+ /** Adapter that talks to the backing store. */
7
+ adapter: CmsAdapter;
8
+ /** BCP-47 supported locales, e.g. `'en'` or `'es-MX'`. */
9
+ locales: string[];
10
+ /**
11
+ * Project-wide site settings schema. Top-level keys become groups in the
12
+ * Site Settings panel; each group's `fields` keys become path segments in
13
+ * the stored tree (`branding.name`, `social.twitter`). Omit the option for
14
+ * projects that don't expose any editable site settings — the panel won't
15
+ * render any sections and the data layer keeps an empty tree.
16
+ */
17
+ site?: SiteSchema;
18
+ };
19
+ export type Cms = {
20
+ /**
21
+ * Resolve the CMS payload for the current SvelteKit request. Mirrors
22
+ * {@link loadCms} but with the adapter and locale already bound.
23
+ */
24
+ load: (event: ServerLoadEvent, { locale }: {
25
+ locale: string;
26
+ }) => Promise<LoadCmsResult>;
27
+ /**
28
+ * Enumerate every publishable entry the adapter has at one route.
29
+ * Resolves to `{ params, metadata }[]` — `params` for SvelteKit's
30
+ * prerender `entries()` export, `metadata` (lifted from each doc's
31
+ * reserved `_metadata` field) for index/listing pages that need a title
32
+ * or description per entry.
33
+ *
34
+ * Generic in the route id: pass a literal route (e.g.
35
+ * `'/(marketing)/rooms/[slug]' satisfies RouteId`) and `params` is typed
36
+ * as that route's `RouteParams` (e.g. `{ slug: string }`). When called
37
+ * with no `routeId`, the @velastack/cms Vite plugin substitutes the importing
38
+ * `+page.{ts,server.ts}`'s route id at build time; the static type then
39
+ * widens to the union of all routes, so prefer passing the route id
40
+ * explicitly when you need typed `params`.
41
+ */
42
+ generateEntries: {
43
+ (): Promise<CmsEntry<RouteParams<RouteId>>[]>;
44
+ <R extends RouteId>(routeId: R): Promise<CmsEntry<RouteParams<R>>[]>;
45
+ };
46
+ };
47
+ /**
48
+ * Bind a {@link CmsAdapter} + locale into a small object of helpers used by
49
+ * SvelteKit route files. The returned `load` and `generateEntries` close
50
+ * over the adapter, so call sites never re-pass it.
51
+ *
52
+ * Typical usage:
53
+ *
54
+ * ```ts
55
+ * // $lib/cms.ts
56
+ * import { createCms, mockAdapter } from '@velastack/cms/server';
57
+ * export const { load: loadCms, generateEntries } = createCms({
58
+ * adapter: mockAdapter({ layoutDocs, pageDocs }),
59
+ * });
60
+ * ```
61
+ */
62
+ export declare const createCms: (options: CreateCmsOptions) => Cms;
@@ -0,0 +1,35 @@
1
+ import { loadCms } from './load-cms.js';
2
+ /**
3
+ * Bind a {@link CmsAdapter} + locale into a small object of helpers used by
4
+ * SvelteKit route files. The returned `load` and `generateEntries` close
5
+ * over the adapter, so call sites never re-pass it.
6
+ *
7
+ * Typical usage:
8
+ *
9
+ * ```ts
10
+ * // $lib/cms.ts
11
+ * import { createCms, mockAdapter } from '@velastack/cms/server';
12
+ * export const { load: loadCms, generateEntries } = createCms({
13
+ * adapter: mockAdapter({ layoutDocs, pageDocs }),
14
+ * });
15
+ * ```
16
+ */
17
+ export const createCms = (options) => {
18
+ const { adapter, locales, site } = options;
19
+ const defaultLocale = locales[0];
20
+ const siteSchema = site ?? {};
21
+ return {
22
+ load: (event, { locale }) => loadCms(event, { adapter, locale, locales, siteSchema }),
23
+ generateEntries: (async (routeId) => {
24
+ if (!routeId) {
25
+ throw new Error('generateEntries: routeId not injected. Did the @velastack/cms Vite plugin run?');
26
+ }
27
+ const entries = await adapter.fetchEntries(routeId, {
28
+ fetch,
29
+ locale: defaultLocale,
30
+ locales
31
+ });
32
+ return entries;
33
+ })
34
+ };
35
+ };
@@ -0,0 +1,5 @@
1
+ export { loadCms, type LoadCmsOptions, type LoadCmsResult } from './load-cms.ts';
2
+ export { createCms, type CreateCmsOptions, type Cms } from './cms.ts';
3
+ export { mockAdapter, type MockAdapterOptions, type PageEntry, type ReleaseItemSnapshot, type ReleaseSnapshot } from './mock-adapter.ts';
4
+ export { apiAdapter, type ApiAdapterOptions } from './api-adapter.ts';
5
+ export type { CmsAdapter, CmsAdapterContext, CmsAdapterDoc, CmsAdapterResolution, CmsAdapterTombstone, CmsEntry, CmsScopeQuery } from './types.ts';
@@ -0,0 +1,4 @@
1
+ export { loadCms } from "./load-cms.js";
2
+ export { createCms } from "./cms.js";
3
+ export { mockAdapter } from "./mock-adapter.js";
4
+ export { apiAdapter } from "./api-adapter.js";
@@ -0,0 +1,105 @@
1
+ import type { ServerLoadEvent } from '@sveltejs/kit';
2
+ import type { CmsManifest, CmsPayload, SiteSchema } from '../components/cms/scope.ts';
3
+ import type { CmsAdapter } from './types.ts';
4
+ export type LoadCmsOptions = {
5
+ /** BCP-47 locale for the request, e.g. `'en'` or `'es-MX'`. */
6
+ locale: string;
7
+ /**
8
+ * BCP-47 supported locales. First entry is the default locale used for
9
+ * read-time fallback when a value is missing in the requested `locale`.
10
+ */
11
+ locales: string[];
12
+ /** Adapter that talks to the backing store. See {@link CmsAdapter}. */
13
+ adapter: CmsAdapter;
14
+ /**
15
+ * Project-wide site settings schema, from `createCms({ site })`. Empty
16
+ * when the customer didn't pass one. Carried on the payload so the admin
17
+ * panel can render its inputs.
18
+ */
19
+ siteSchema?: SiteSchema;
20
+ };
21
+ /**
22
+ * Result of {@link loadCms}. `cms` is the payload components consume;
23
+ * the three flags are mutually exclusive resolutions for the page-kind scope:
24
+ *
25
+ * - `redirectTo` — set to a target URL when the page was replaced with a
26
+ * permanent redirect; the caller should `redirect(308, redirectTo)`.
27
+ * - `gone` — `true` when the page was deliberately permanently removed; the
28
+ * caller should `error(410, …)`.
29
+ * - `notFound` — `true` when the page-kind scope had owned params and the
30
+ * adapter returned no doc and no tombstone; the caller should
31
+ * `error(404, …)`.
32
+ *
33
+ * Resolution priority (handled in `resolveCmsPayload`): `redirectTo` →
34
+ * `gone` → `notFound` → render. Consumers should branch in that order.
35
+ */
36
+ export type LoadCmsResult = {
37
+ cms: CmsPayload;
38
+ notFound: boolean;
39
+ gone: boolean;
40
+ redirectTo: string | null;
41
+ };
42
+ /**
43
+ * Pure inputs to {@link resolveCmsPayload}: everything {@link loadCms} reads
44
+ * from the SvelteKit `event` plus the build-time manifest, separated so tests
45
+ * can drive the resolver with a hand-built manifest and synthetic params.
46
+ */
47
+ export type ResolveCmsPayloadArgs = {
48
+ manifest: CmsManifest;
49
+ routeId: string | null;
50
+ params: Record<string, string>;
51
+ previewKey: string | null;
52
+ versionKey?: string | null;
53
+ locale: string;
54
+ locales: string[];
55
+ adapter: CmsAdapter;
56
+ fetch: typeof fetch;
57
+ siteSchema?: SiteSchema;
58
+ };
59
+ /**
60
+ * Pure resolver: build per-scope queries from the manifest, ask the adapter
61
+ * for documents, and shape a {@link CmsPayload}. The page-kind doc owns a
62
+ * `metadata` branch on its tree; `payload.metadata` aliases that branch for
63
+ * `definePageMetaTags(...)`. No SvelteKit dependency — used directly by tests.
64
+ */
65
+ export declare const resolveCmsPayload: (args: ResolveCmsPayloadArgs) => Promise<LoadCmsResult>;
66
+ /**
67
+ * Resolve the CMS payload for the current SvelteKit request.
68
+ *
69
+ * Reads the route's scope chain from the build-time manifest, builds one
70
+ * query per scope with its `routeId` and bound owned `params` separately,
71
+ * asks `adapter.fetchDocs` for every scope's document, and shapes the result
72
+ * into a {@link CmsPayload} (keyed by `scopeId`) that the runtime CMS
73
+ * components consume via `getContext(CMS_SCOPE)` + `page.data.cms`.
74
+ *
75
+ * When `?preview=KEY` is present in the URL, the key is forwarded to the
76
+ * adapter as `context.previewKey`. Adapters that support release previews
77
+ * (e.g. `mockAdapter`) overlay any pending edits in the matching open
78
+ * release on top of the published content for each requested scope. Without
79
+ * a preview key, only published content is returned.
80
+ *
81
+ * The page-kind doc owns a `metadata` branch on its tree; `payload.metadata`
82
+ * aliases it for `definePageMetaTags(...)`. The doc itself is unchanged —
83
+ * components addressing `metadata.title` etc. read straight through.
84
+ *
85
+ * Wire it into your root `+layout.server.ts`:
86
+ *
87
+ * ```ts
88
+ * import { error, redirect } from '@sveltejs/kit';
89
+ * import { loadCms, mockAdapter } from '@velastack/cms/server';
90
+ *
91
+ * const adapter = mockAdapter({ layoutDocs: {}, pageDocs: {} });
92
+ *
93
+ * export const load = async (event) => {
94
+ * const { cms, notFound, gone, redirectTo } = await loadCms(event, {
95
+ * locale: 'en',
96
+ * adapter
97
+ * });
98
+ * if (redirectTo) redirect(308, redirectTo);
99
+ * if (gone) error(410, 'Gone');
100
+ * if (notFound) error(404, 'Not found');
101
+ * return { cms };
102
+ * };
103
+ * ```
104
+ */
105
+ export declare const loadCms: (event: ServerLoadEvent, options: LoadCmsOptions) => Promise<LoadCmsResult>;
@@ -0,0 +1,227 @@
1
+ import { cmsManifest } from 'virtual:vela-cms/manifest';
2
+ import { mergeLocaleDocs, mergeLocaleEntries } from "../components/cms/locale-merge.js";
3
+ import { browser, building } from '$app/environment';
4
+ const builtManifest = cmsManifest;
5
+ const DEFAULT_ENDPOINT = '/api/cms';
6
+ const emptyPayload = (locale, locales, endpoint, site) => ({
7
+ locale,
8
+ locales,
9
+ docs: {},
10
+ scopes: {},
11
+ metadata: {},
12
+ entries: {},
13
+ endpoint,
14
+ page: null,
15
+ site
16
+ });
17
+ const isTombstone = (r) => !!r && 'kind' in r;
18
+ /**
19
+ * Pure resolver: build per-scope queries from the manifest, ask the adapter
20
+ * for documents, and shape a {@link CmsPayload}. The page-kind doc owns a
21
+ * `metadata` branch on its tree; `payload.metadata` aliases that branch for
22
+ * `definePageMetaTags(...)`. No SvelteKit dependency — used directly by tests.
23
+ */
24
+ export const resolveCmsPayload = async (args) => {
25
+ const { manifest, routeId, params, previewKey, locale, locales, adapter, fetch } = args;
26
+ const versionKey = args.versionKey ?? null;
27
+ const endpoint = adapter.endpoint ?? DEFAULT_ENDPOINT;
28
+ const defaultLocale = locales[0] ?? locale;
29
+ const needsFallback = locale !== defaultLocale;
30
+ const siteSchema = args.siteSchema ?? {};
31
+ const sitePayload = async () => {
32
+ const tree = adapter.fetchSite
33
+ ? await Promise.resolve(adapter.fetchSite({ fetch, previewKey, versionKey, locale, locales }))
34
+ : {};
35
+ return { schema: siteSchema, tree: tree ?? {} };
36
+ };
37
+ if (!routeId)
38
+ return {
39
+ cms: emptyPayload(locale, locales, endpoint, await sitePayload()),
40
+ notFound: false,
41
+ gone: false,
42
+ redirectTo: null
43
+ };
44
+ const route = manifest.routes[routeId];
45
+ if (!route)
46
+ return {
47
+ cms: emptyPayload(locale, locales, endpoint, await sitePayload()),
48
+ notFound: false,
49
+ gone: false,
50
+ redirectTo: null
51
+ };
52
+ const buildQueries = (forLocale) => route.scopes.map((scope) => {
53
+ const scopeParams = {};
54
+ for (const p of scope.ownedParams) {
55
+ if (params[p] !== undefined)
56
+ scopeParams[p] = params[p];
57
+ }
58
+ return {
59
+ scopeId: scope.scopeId,
60
+ kind: scope.kind,
61
+ routeId: scope.routeId,
62
+ params: scopeParams,
63
+ fields: scope.fields,
64
+ locale: forLocale
65
+ };
66
+ });
67
+ const queries = buildQueries(locale);
68
+ const fallbackQueries = needsFallback ? buildQueries(defaultLocale) : null;
69
+ const ctx = (forLocale) => ({
70
+ fetch,
71
+ previewKey,
72
+ versionKey,
73
+ locale: forLocale,
74
+ locales
75
+ });
76
+ const entriesRouteIds = route.entriesRouteIds ?? [];
77
+ const noDocs = {};
78
+ const [rawDocs, fallbackDocs, entriesPairs, fallbackEntriesPairs, siteTree] = await Promise.all([
79
+ Promise.resolve(adapter.fetchDocs(queries, ctx(locale))),
80
+ fallbackQueries
81
+ ? Promise.resolve(adapter.fetchDocs(fallbackQueries, ctx(defaultLocale)))
82
+ : Promise.resolve(noDocs),
83
+ Promise.all(entriesRouteIds.map(async (rid) => [
84
+ rid,
85
+ await adapter.fetchEntries(rid, ctx(locale))
86
+ ])),
87
+ needsFallback
88
+ ? Promise.all(entriesRouteIds.map(async (rid) => [
89
+ rid,
90
+ await adapter.fetchEntries(rid, ctx(defaultLocale))
91
+ ]))
92
+ : Promise.resolve([]),
93
+ adapter.fetchSite
94
+ ? Promise.resolve(adapter.fetchSite({ fetch, previewKey, versionKey, locale, locales }))
95
+ : Promise.resolve({})
96
+ ]);
97
+ const site = { schema: siteSchema, tree: siteTree ?? {} };
98
+ // Adapter `fetchEntries` returns tombstones (redirect / gone) so the
99
+ // prerender path can visit redirected URLs. The consumer-facing payload
100
+ // drops them — `<CmsEntries>` lists shouldn't display deleted pages.
101
+ const isListable = (e) => !e.redirectTo && !e.gone;
102
+ const requestedEntries = Object.fromEntries(entriesPairs);
103
+ const fallbackEntries = needsFallback ? Object.fromEntries(fallbackEntriesPairs) : null;
104
+ const mergedEntries = mergeLocaleEntries(requestedEntries, fallbackEntries);
105
+ const entries = {};
106
+ for (const [rid, list] of Object.entries(mergedEntries)) {
107
+ entries[rid] = list.filter(isListable);
108
+ }
109
+ const pageQuery = queries.find((q) => q.kind === 'page');
110
+ // Page-kind scope can resolve to a tombstone (gone / redirect). Priority:
111
+ // requested-locale tombstone wins outright; otherwise requested-locale doc
112
+ // uses normal merge; otherwise default-locale tombstone applies; otherwise
113
+ // default-locale doc; otherwise notFound (when params are owned).
114
+ if (pageQuery) {
115
+ const requested = rawDocs[pageQuery.scopeId];
116
+ const fallback = fallbackDocs[pageQuery.scopeId];
117
+ let tombstone = null;
118
+ if (isTombstone(requested))
119
+ tombstone = requested;
120
+ else if (!requested && isTombstone(fallback))
121
+ tombstone = fallback;
122
+ if (tombstone) {
123
+ return {
124
+ cms: emptyPayload(locale, locales, endpoint, site),
125
+ notFound: false,
126
+ gone: tombstone.kind === 'gone',
127
+ redirectTo: tombstone.kind === 'redirect' ? tombstone.to : null
128
+ };
129
+ }
130
+ }
131
+ let pagePointer = null;
132
+ const requestedTrees = {};
133
+ const fallbackTrees = {};
134
+ for (const [scopeId, r] of Object.entries(rawDocs)) {
135
+ requestedTrees[scopeId] = isTombstone(r) ? undefined : r?.contents;
136
+ }
137
+ for (const [scopeId, f] of Object.entries(fallbackDocs)) {
138
+ fallbackTrees[scopeId] = isTombstone(f) ? undefined : f?.contents;
139
+ }
140
+ const docs = mergeLocaleDocs(requestedTrees, needsFallback ? fallbackTrees : null);
141
+ let metadata = {};
142
+ if (pageQuery) {
143
+ pagePointer = {
144
+ scopeId: pageQuery.scopeId,
145
+ routeId: pageQuery.routeId,
146
+ params: pageQuery.params
147
+ };
148
+ const pageDoc = docs[pageQuery.scopeId];
149
+ const meta = pageDoc?.metadata;
150
+ if (meta && typeof meta === 'object' && !Array.isArray(meta)) {
151
+ metadata = meta;
152
+ }
153
+ }
154
+ const scopes = {};
155
+ for (const q of queries) {
156
+ const { locale: _omit, ...entry } = q;
157
+ scopes[q.scopeId] = entry;
158
+ }
159
+ const pageScopeMissing = !!pageQuery &&
160
+ Object.keys(pageQuery.params).length > 0 &&
161
+ !(pageQuery.scopeId in rawDocs) &&
162
+ !(pageQuery.scopeId in fallbackDocs);
163
+ return {
164
+ cms: { locale, locales, docs, scopes, metadata, entries, endpoint, page: pagePointer, site },
165
+ notFound: pageScopeMissing,
166
+ gone: false,
167
+ redirectTo: null
168
+ };
169
+ };
170
+ /**
171
+ * Resolve the CMS payload for the current SvelteKit request.
172
+ *
173
+ * Reads the route's scope chain from the build-time manifest, builds one
174
+ * query per scope with its `routeId` and bound owned `params` separately,
175
+ * asks `adapter.fetchDocs` for every scope's document, and shapes the result
176
+ * into a {@link CmsPayload} (keyed by `scopeId`) that the runtime CMS
177
+ * components consume via `getContext(CMS_SCOPE)` + `page.data.cms`.
178
+ *
179
+ * When `?preview=KEY` is present in the URL, the key is forwarded to the
180
+ * adapter as `context.previewKey`. Adapters that support release previews
181
+ * (e.g. `mockAdapter`) overlay any pending edits in the matching open
182
+ * release on top of the published content for each requested scope. Without
183
+ * a preview key, only published content is returned.
184
+ *
185
+ * The page-kind doc owns a `metadata` branch on its tree; `payload.metadata`
186
+ * aliases it for `definePageMetaTags(...)`. The doc itself is unchanged —
187
+ * components addressing `metadata.title` etc. read straight through.
188
+ *
189
+ * Wire it into your root `+layout.server.ts`:
190
+ *
191
+ * ```ts
192
+ * import { error, redirect } from '@sveltejs/kit';
193
+ * import { loadCms, mockAdapter } from '@velastack/cms/server';
194
+ *
195
+ * const adapter = mockAdapter({ layoutDocs: {}, pageDocs: {} });
196
+ *
197
+ * export const load = async (event) => {
198
+ * const { cms, notFound, gone, redirectTo } = await loadCms(event, {
199
+ * locale: 'en',
200
+ * adapter
201
+ * });
202
+ * if (redirectTo) redirect(308, redirectTo);
203
+ * if (gone) error(410, 'Gone');
204
+ * if (notFound) error(404, 'Not found');
205
+ * return { cms };
206
+ * };
207
+ * ```
208
+ */
209
+ export const loadCms = (event, options) => {
210
+ if (browser) {
211
+ throw new Error('[@velastack/cms] loadCms() is server-only — call it from `+layout.server.ts` ' +
212
+ 'or `+page.server.ts`, not from a `+page.svelte` or universal `+page.ts`. ' +
213
+ "For browser-side preview/editing, use `cmsStore` from '@velastack/cms'.");
214
+ }
215
+ return resolveCmsPayload({
216
+ manifest: builtManifest,
217
+ routeId: event.route.id,
218
+ params: event.params,
219
+ previewKey: building ? null : event.url.searchParams.get('preview'),
220
+ versionKey: building ? null : event.url.searchParams.get('version'),
221
+ locale: options.locale,
222
+ locales: options.locales,
223
+ adapter: options.adapter,
224
+ fetch: event.fetch,
225
+ siteSchema: options.siteSchema
226
+ });
227
+ };