camox 0.43.0 → 0.45.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 (412) hide show
  1. package/bin/camox.mjs +9 -1
  2. package/dist/components/AuthGate.js +0 -6
  3. package/dist/components/DeviceSelector.js +96 -0
  4. package/dist/components/PlatformLabel.js +20 -24
  5. package/dist/core/components/lexical/HighlightNode.js +1 -1
  6. package/dist/core/components/lexical/InlineContentEditable.js +15 -19
  7. package/dist/core/components/lexical/InlineLexicalEditor.js +54 -74
  8. package/dist/core/components/lexical/InlineStylesPlugin.js +57 -41
  9. package/dist/core/components/lexical/MaxLengthPlugin.js +59 -0
  10. package/dist/core/components/lexical/SelectionBroadcaster.js +55 -56
  11. package/dist/core/components/lexical/SidebarLexicalEditor.js +327 -234
  12. package/dist/core/components/lexical/SummaryToggleGuard.js +42 -0
  13. package/dist/core/components/lexical/TextLinkPopover.js +169 -180
  14. package/dist/core/createApp.d.ts +254 -299
  15. package/dist/core/createApp.js +123 -29
  16. package/dist/core/createBlock.d.ts +5 -5
  17. package/dist/core/createBlock.js +399 -152
  18. package/dist/core/createCollection.d.ts +55 -0
  19. package/dist/core/createCollection.js +93 -0
  20. package/dist/core/createLayout.d.ts +197 -61
  21. package/dist/core/createLayout.js +114 -56
  22. package/dist/core/defineDocument.d.ts +3 -5
  23. package/dist/core/derivedRoutes.js +49 -1
  24. package/dist/core/dom.d.ts +13 -4
  25. package/dist/core/dom.js +44 -1
  26. package/dist/core/editing/BlockEditingRuntime.d.ts +16 -0
  27. package/dist/core/editing/BlockEditingRuntime.js +6 -15
  28. package/dist/core/editing/CompleteBlockEditingRuntime.js +28 -23
  29. package/dist/core/editing/createEditableBlock.d.ts +820 -565
  30. package/dist/core/editing/createEditableBlock.js +2153 -971
  31. package/dist/core/editing/referenceWrites.js +51 -0
  32. package/dist/core/editing/useLatestRecord.js +90 -0
  33. package/dist/core/hooks/useArtifactHost.js +139 -0
  34. package/dist/core/hooks/useFieldSelection.js +43 -18
  35. package/dist/core/hooks/useIsEditable.js +12 -10
  36. package/dist/core/hooks/useOverlayMessage.js +15 -19
  37. package/dist/core/lib/artifact.d.ts +21 -0
  38. package/dist/core/lib/artifact.js +154 -0
  39. package/dist/core/lib/artifactColors.js +123 -0
  40. package/dist/core/lib/artifactData.d.ts +1 -0
  41. package/dist/core/lib/artifactData.js +131 -0
  42. package/dist/core/lib/artifactHost.js +205 -0
  43. package/dist/core/lib/artifactRuntime.js +36 -0
  44. package/dist/core/lib/artifactTheme.js +57 -0
  45. package/dist/core/lib/contentType.d.ts +304 -103
  46. package/dist/core/lib/contentType.js +207 -168
  47. package/dist/core/lib/fieldTypes.js +4 -0
  48. package/dist/core/lib/iconTypes.d.ts +13 -0
  49. package/dist/core/lib/icons.d.ts +6 -0
  50. package/dist/core/lib/icons.js +126 -0
  51. package/dist/core/lib/imagePlaceholder.js +177 -0
  52. package/dist/core/lib/imageTransform.js +1 -1
  53. package/dist/core/lib/lexicalReact.d.ts +3 -1
  54. package/dist/core/lib/lexicalState.js +7 -7
  55. package/dist/core/lib/modifierFormats.js +1 -1
  56. package/dist/core/lib/previewPaused.js +9 -0
  57. package/dist/core/lib/recordScope.js +316 -0
  58. package/dist/core/lib/reference.d.ts +81 -0
  59. package/dist/core/lib/reference.js +29 -0
  60. package/dist/core/lib/textLinks.js +7 -5
  61. package/dist/core/lib/textStyles.d.ts +6 -8
  62. package/dist/core/lib/textStyles.js +5 -5
  63. package/dist/core/notFound.d.ts +7 -0
  64. package/dist/core/notFound.js +11 -0
  65. package/dist/core/pageDestinations.js +6 -3
  66. package/dist/core/recordItem.js +34 -0
  67. package/dist/core/requestContext.d.ts +26 -0
  68. package/dist/core/requestContext.js +20 -0
  69. package/dist/features/canvas/CamoxCanvas.js +1734 -0
  70. package/dist/features/canvas/CanvasBlockFrame.js +353 -0
  71. package/dist/features/canvas/CanvasBlockHeader.js +55 -0
  72. package/dist/features/canvas/CanvasLoadingScreen.js +35 -0
  73. package/dist/features/canvas/CanvasOverlays.js +254 -0
  74. package/dist/features/canvas/CanvasPageEdge.js +87 -0
  75. package/dist/features/canvas/CanvasPageFrame.js +335 -0
  76. package/dist/features/canvas/CanvasPageHeader.js +125 -0
  77. package/dist/features/canvas/CanvasPreviewPageSlot.js +103 -0
  78. package/dist/features/canvas/CanvasShelfMarker.js +255 -0
  79. package/dist/features/canvas/DerivedPagePathInput.js +238 -0
  80. package/dist/features/canvas/canvasCamera.js +229 -0
  81. package/dist/features/canvas/canvasFlight.js +104 -0
  82. package/dist/features/canvas/canvasFrameCapture.js +364 -0
  83. package/dist/features/canvas/canvasFrameDocument.js +317 -0
  84. package/dist/features/canvas/canvasFrameMode.js +53 -0
  85. package/dist/features/canvas/canvasInsertionSeams.js +44 -0
  86. package/dist/features/canvas/canvasItems.js +120 -0
  87. package/dist/features/canvas/canvasOverlayGeometry.js +240 -0
  88. package/dist/features/canvas/canvasPages.js +79 -0
  89. package/dist/features/canvas/canvasScreenSpace.js +26 -0
  90. package/dist/features/canvas/canvasSelection.js +18 -0
  91. package/dist/features/canvas/canvasStore.js +149 -0
  92. package/dist/features/canvas/canvasThumbnails.js +304 -0
  93. package/dist/features/canvas/canvasZoom.js +10 -0
  94. package/dist/features/canvas/sidebar/CanvasInspector.js +202 -0
  95. package/dist/features/canvas/sidebar/CanvasNavigator.js +226 -0
  96. package/dist/features/canvas/sidebar/CanvasSidebar.js +60 -0
  97. package/dist/features/canvas/sidebar/CanvasSidebarFrame.js +48 -0
  98. package/dist/features/canvas/sidebar/CanvasSidebarSkeleton.js +39 -0
  99. package/dist/features/canvas/sidebar/CatalogBlockInspector.js +189 -0
  100. package/dist/features/canvas/sidebar/CuratedPageInspector.js +69 -0
  101. package/dist/features/canvas/sidebar/DerivedPageInspector.js +37 -0
  102. package/dist/features/canvas/sidebar/LayoutPageBlocks.js +78 -0
  103. package/dist/features/canvas/sidebar/LayoutPageOverview.js +71 -0
  104. package/dist/features/canvas/sidebar/PageInspector.js +157 -0
  105. package/dist/features/canvas/sidebar/PageInspectorSkeleton.js +90 -0
  106. package/dist/features/canvas/sidebar/PageOverview.js +27 -0
  107. package/dist/features/canvas/sidebar/SingletonPageInspector.js +31 -0
  108. package/dist/features/canvas/useCanvasCamera.js +803 -0
  109. package/dist/features/canvas/useCanvasFrame.js +149 -0
  110. package/dist/features/canvas/useCanvasFrameInput.js +97 -0
  111. package/dist/features/canvas/useCanvasNearness.js +57 -0
  112. package/dist/features/canvas/useDiscoveredPreviewPaths.js +62 -0
  113. package/dist/features/content/CamoxContent.d.ts +2 -5
  114. package/dist/features/content/CamoxContent.js +174 -271
  115. package/dist/features/content/CollectionItemSheetContext.js +106 -0
  116. package/dist/features/content/ContentAssets.js +315 -0
  117. package/dist/features/content/ContentCollection.js +663 -0
  118. package/dist/features/content/collection-form.js +58 -0
  119. package/dist/features/content/components/AssetCard.js +101 -69
  120. package/dist/features/content/components/AssetCardSkeleton.js +4 -8
  121. package/dist/features/content/components/ContentSidebar.js +129 -18
  122. package/dist/features/content/components/ContentSidebarGroup.js +37 -0
  123. package/dist/features/content/components/DeleteCollectionItemButton.js +202 -0
  124. package/dist/features/content/components/MissingFromLocale.js +282 -0
  125. package/dist/features/content/components/UploadDropZone.js +27 -31
  126. package/dist/features/content/components/UploadProgressDrawer.js +90 -98
  127. package/dist/features/navigation/navigation.d.ts +66 -20
  128. package/dist/features/navigation/navigation.js +257 -90
  129. package/dist/features/og/defaultFonts.js +8 -8
  130. package/dist/features/og/geist-variable-ttf-base64.js +1 -1
  131. package/dist/features/og/imageResponse.d.ts +8 -0
  132. package/dist/features/og/imageResponse.js +26 -0
  133. package/dist/features/page/CuratedPageContent.js +167 -0
  134. package/dist/features/page/DerivedPageContent.js +26 -30
  135. package/dist/features/page/SharedLayoutContent.js +25 -27
  136. package/dist/features/preview/CamoxPreview.d.ts +23 -61
  137. package/dist/features/preview/CamoxPreview.js +811 -507
  138. package/dist/features/preview/EditablePageContent.js +1 -1
  139. package/dist/features/preview/EditablePageExperience.js +16 -22
  140. package/dist/features/preview/components/AddBlockDialog.js +270 -0
  141. package/dist/features/preview/components/AssetFieldEditor.js +173 -154
  142. package/dist/features/preview/components/AssetLightbox.js +194 -136
  143. package/dist/features/preview/components/AssetPickerModal.js +153 -170
  144. package/dist/features/preview/components/BlockActionsPopover.js +150 -149
  145. package/dist/features/preview/components/BlockErrorBoundary.js +8 -12
  146. package/dist/features/preview/components/BlockThumbnail.js +176 -100
  147. package/dist/features/preview/components/CanvasPreview.js +243 -0
  148. package/dist/features/preview/components/CreatePageModal.js +128 -137
  149. package/dist/features/preview/components/DebouncedFieldEditor.js +29 -33
  150. package/dist/features/preview/components/DerivedLayoutDialog.js +46 -29
  151. package/dist/features/preview/components/DrillRow.js +150 -0
  152. package/dist/features/preview/components/FieldOverlayStyles.js +33 -10
  153. package/dist/features/preview/components/FieldToolbar.js +166 -116
  154. package/dist/features/preview/components/Frame.js +108 -20
  155. package/dist/features/preview/components/IconFieldEditor.js +227 -0
  156. package/dist/features/preview/components/ItemFieldsEditor.js +238 -205
  157. package/dist/features/preview/components/LinkFieldEditor.js +135 -139
  158. package/dist/features/preview/components/Metadata.js +22 -30
  159. package/dist/features/preview/components/MobilePreviewDrawer.js +89 -108
  160. package/dist/features/preview/components/MultipleAssetFieldEditor.js +334 -246
  161. package/dist/features/preview/components/OverlayTracker.js +10 -42
  162. package/dist/features/preview/components/Overlays.js +81 -69
  163. package/dist/features/preview/components/PageInfo.js +1748 -0
  164. package/dist/features/preview/components/PageInfoSkeleton.js +51 -0
  165. package/dist/features/preview/components/PageLocationFieldset.js +112 -116
  166. package/dist/features/preview/components/PageNavigatorHeader.js +24 -0
  167. package/dist/features/preview/components/PageNicknameField.js +22 -26
  168. package/dist/features/preview/components/PagePicker.js +145 -147
  169. package/dist/features/preview/components/PageTree.js +525 -532
  170. package/dist/features/preview/components/PreviewActivation.js +28 -32
  171. package/dist/features/preview/components/PreviewPanel.js +620 -319
  172. package/dist/features/preview/components/PreviewToolbar.js +111 -340
  173. package/dist/features/preview/components/RecordCard.js +80 -0
  174. package/dist/features/preview/components/RecordCombobox.js +178 -0
  175. package/dist/features/preview/components/ReferenceFieldEditor.js +149 -0
  176. package/dist/features/preview/components/ReferenceListFieldEditor.js +432 -0
  177. package/dist/features/preview/components/RemovedBlockPlaceholder.js +95 -0
  178. package/dist/features/preview/components/RepeatableItemsList.js +125 -138
  179. package/dist/features/preview/components/SelectionEditor.js +993 -0
  180. package/dist/features/preview/components/ShikiMarkdown.js +14 -18
  181. package/dist/features/preview/components/SidebarSection.js +52 -64
  182. package/dist/features/preview/components/StudioEditingFallback.js +56 -0
  183. package/dist/features/preview/components/UnlinkAssetButton.js +104 -107
  184. package/dist/features/preview/components/blockGridNavigation.js +15 -0
  185. package/dist/features/preview/components/contentFieldSchema.js +8 -0
  186. package/dist/features/preview/components/useFieldWriter.js +200 -0
  187. package/dist/features/preview/components/useRecordView.js +383 -0
  188. package/dist/features/preview/components/useRepeatableItemActions.js +35 -37
  189. package/dist/features/preview/components/useUpdateBlockPosition.js +37 -37
  190. package/dist/features/preview/editingFrame.js +197 -0
  191. package/dist/features/preview/overlayHighlights.js +27 -0
  192. package/dist/features/preview/overlayMessages.js +72 -1
  193. package/dist/features/preview/pageRecord.js +189 -0
  194. package/dist/features/preview/previewConstants.js +6 -2
  195. package/dist/features/preview/previewPageFrame.js +95 -0
  196. package/dist/features/preview/previewPreparation.js +7 -0
  197. package/dist/features/preview/previewSelection.js +33 -59
  198. package/dist/features/preview/previewStore.js +225 -123
  199. package/dist/features/preview/referencePickerFocus.js +29 -0
  200. package/dist/features/preview/repeatableItemTargets.js +56 -0
  201. package/dist/features/preview/selectionReveal.js +21 -0
  202. package/dist/features/preview/usePreviewViewportActions.js +114 -0
  203. package/dist/features/preview/viewportContinuity.js +109 -0
  204. package/dist/features/provider/AuthenticatedCamoxProvider.js +69 -44
  205. package/dist/features/provider/CamoxProvider.d.ts +3 -6
  206. package/dist/features/provider/CamoxProvider.js +38 -50
  207. package/dist/features/provider/CoreCamoxProvider.js +71 -23
  208. package/dist/features/provider/LocalhostPreviewProvider.js +73 -73
  209. package/dist/features/provider/PreviewSignInPage.js +54 -0
  210. package/dist/features/provider/components/CamoxAppContext.js +11 -11
  211. package/dist/features/provider/components/CommandPalette.js +87 -143
  212. package/dist/features/provider/useAdminShortcuts.js +7 -11
  213. package/dist/features/routes/pageRuntime.d.ts +44 -4
  214. package/dist/features/routes/pageRuntime.js +244 -137
  215. package/dist/features/runtime/RuntimeChrome.js +117 -115
  216. package/dist/features/runtime/alternates.js +64 -0
  217. package/dist/features/runtime/analytics.d.ts +7 -0
  218. package/dist/features/runtime/analytics.js +66 -0
  219. package/dist/features/runtime/artifactSources.js +87 -0
  220. package/dist/features/runtime/editingFallback.js +20 -0
  221. package/dist/features/runtime/linkPrefetch.js +97 -0
  222. package/dist/features/runtime/livePages.js +62 -0
  223. package/dist/features/runtime/llmsTxt.js +40 -0
  224. package/dist/features/runtime/loopbackFetch.js +18 -0
  225. package/dist/features/runtime/navigationAccessibility.js +51 -0
  226. package/dist/features/runtime/navigationTarget.js +23 -2
  227. package/dist/features/runtime/pageApp.js +216 -141
  228. package/dist/features/runtime/pageBlockTypes.js +20 -0
  229. package/dist/features/runtime/pageClient.d.ts +2 -4
  230. package/dist/features/runtime/pageClient.js +18 -3
  231. package/dist/features/runtime/pageNavigation.js +254 -32
  232. package/dist/features/runtime/pageServer.d.ts +2 -4
  233. package/dist/features/runtime/pageServer.js +8 -1
  234. package/dist/features/runtime/pageViewport.js +7 -0
  235. package/dist/features/runtime/runtime.d.ts +60 -23
  236. package/dist/features/runtime/runtime.js +779 -166
  237. package/dist/features/runtime/runtimeChromeLoader.js +58 -0
  238. package/dist/features/runtime/runtimeRoutes.d.ts +19 -0
  239. package/dist/features/runtime/runtimeRoutes.js +25 -0
  240. package/dist/features/runtime/scrollRestoration.js +133 -0
  241. package/dist/features/runtime/studioApp.d.ts +4 -3
  242. package/dist/features/runtime/studioApp.js +5 -9
  243. package/dist/features/runtime/studioClient.d.ts +2 -4
  244. package/dist/features/runtime/studioClient.js +12 -3
  245. package/dist/features/runtime/studioServer.d.ts +2 -4
  246. package/dist/features/runtime/studioServer.js +6 -1
  247. package/dist/features/runtime/worker.d.ts +6 -0
  248. package/dist/features/runtime/worker.js +23 -0
  249. package/dist/features/runtime/workerRequest.js +44 -0
  250. package/dist/features/studio/CamoxStudio.d.ts +2 -6
  251. package/dist/features/studio/CamoxStudio.js +34 -49
  252. package/dist/features/studio/FollowAgentProvider.js +338 -0
  253. package/dist/features/studio/components/ChatSidebar.js +356 -0
  254. package/dist/features/studio/components/DraftsControl.js +676 -0
  255. package/dist/features/studio/components/FaviconDialog.js +318 -0
  256. package/dist/features/studio/components/LocalePicker.js +785 -0
  257. package/dist/features/studio/components/Navbar.js +123 -103
  258. package/dist/features/studio/components/ProjectMenu.js +239 -260
  259. package/dist/features/studio/components/RenameDraftDialog.js +206 -0
  260. package/dist/features/studio/components/ReviewDraftSheet.js +1472 -0
  261. package/dist/features/studio/components/ThreadComposer.js +157 -0
  262. package/dist/features/studio/components/ThreadMarkdown.js +113 -0
  263. package/dist/features/studio/components/ThreadMessages.js +270 -0
  264. package/dist/features/studio/components/UserButton.js +34 -23
  265. package/dist/features/studio/draftLabel.js +33 -0
  266. package/dist/features/studio/draftNotice.js +13 -0
  267. package/dist/features/studio/followAgent.js +250 -0
  268. package/dist/features/studio/followAgentContext.js +7 -0
  269. package/dist/features/studio/localeOptions.js +118 -0
  270. package/dist/features/studio/localeSwitch.js +19 -0
  271. package/dist/features/studio/routes.js +48 -1
  272. package/dist/features/studio/studioStore.js +64 -1
  273. package/dist/features/studio/useTheme.js +24 -27
  274. package/dist/features/vite/artifactRuntimeMinification.js +36 -0
  275. package/dist/features/vite/auth.js +1 -50
  276. package/dist/features/vite/blockBoilerplate.js +6 -5
  277. package/dist/features/vite/blockChunks.js +31 -0
  278. package/dist/features/vite/bundlerLogs.js +17 -0
  279. package/dist/features/vite/definitionsSync.js +158 -226
  280. package/dist/features/vite/devAuthentication.js +4 -16
  281. package/dist/features/vite/devSignIn.js +87 -0
  282. package/dist/features/vite/iconGeneration.js +16 -0
  283. package/dist/features/vite/layoutGeneration.js +11 -1
  284. package/dist/features/vite/publishSeededContent.js +30 -0
  285. package/dist/features/vite/routeGeneration.js +6 -7
  286. package/dist/features/vite/runtimeDev.js +80 -99
  287. package/dist/features/vite/vite.d.ts +53 -31
  288. package/dist/features/vite/vite.js +230 -116
  289. package/dist/features/vite/workerBuild.js +39 -0
  290. package/dist/hooks/use-debounced-field.js +116 -47
  291. package/dist/hooks/use-file-upload.js +114 -67
  292. package/dist/hooks/use-marquee-selection.js +32 -36
  293. package/dist/hooks/use-page-destinations.js +69 -37
  294. package/dist/lib/api-client-server.d.ts +5 -0
  295. package/dist/lib/api-client-server.js +10 -4
  296. package/dist/lib/api-client.d.ts +6 -0
  297. package/dist/lib/api-client.js +51 -16
  298. package/dist/lib/api-socket.js +17 -0
  299. package/dist/lib/auth-page-styles.js +39 -0
  300. package/dist/lib/auth.js +139 -60
  301. package/dist/lib/collection-cache.js +23 -0
  302. package/dist/lib/draft-scope.d.ts +4 -0
  303. package/dist/lib/draft-scope.js +222 -0
  304. package/dist/lib/html.js +12 -0
  305. package/dist/lib/link-pages.js +154 -0
  306. package/dist/lib/locale-path.d.ts +22 -0
  307. package/dist/lib/locale-path.js +57 -0
  308. package/dist/lib/normalized-data.js +252 -152
  309. package/dist/lib/preview-handoff.js +13 -0
  310. package/dist/lib/queries.d.ts +11 -0
  311. package/dist/lib/queries.js +71 -131
  312. package/dist/lib/studio-reads.d.ts +14 -0
  313. package/dist/lib/studio-reads.js +574 -0
  314. package/dist/lib/use-project-room.js +50 -47
  315. package/dist/lib/use-thread.js +310 -0
  316. package/dist/lib/utils.js +25 -29
  317. package/dist/lib/view-locale-context.js +22 -0
  318. package/dist/lib/view-locale.js +46 -0
  319. package/dist/package.js +5 -0
  320. package/dist/studio-overlays.css +41 -147
  321. package/dist/studio.css +2 -2
  322. package/package.json +70 -72
  323. package/skills/camox/SKILL.md +16 -5
  324. package/skills/camox/references/artifacts.md +179 -0
  325. package/skills/camox/references/block-definitions.md +98 -55
  326. package/skills/camox/references/cli-common.md +18 -6
  327. package/skills/camox/references/cli-content.md +92 -58
  328. package/skills/camox/references/cli-publishing.md +26 -0
  329. package/skills/camox/references/dom-integrations.md +27 -0
  330. package/skills/camox/references/field-styling.md +7 -7
  331. package/skills/camox/references/layout-definitions.md +16 -14
  332. package/skills/camox/references/localization.md +56 -0
  333. package/skills/camox/references/routed-layouts.md +133 -15
  334. package/skills/camox-expand/SKILL.md +69 -0
  335. package/skills/camox-expand/references/jobs.md +39 -0
  336. package/skills/camoxify/SKILL.md +38 -2
  337. package/dist/core/components/AddBlockControlBar.js +0 -78
  338. package/dist/core/hooks/useRequireDraftSource.js +0 -23
  339. package/dist/features/metadata/sitemap.d.ts +0 -8
  340. package/dist/features/metadata/sitemap.js +0 -17
  341. package/dist/features/og/imageResponse.node.d.ts +0 -12
  342. package/dist/features/og/imageResponse.node.js +0 -49
  343. package/dist/features/og/imageResponse.workerd.d.ts +0 -12
  344. package/dist/features/og/imageResponse.workerd.js +0 -40
  345. package/dist/features/page/PublishedPageContent.js +0 -205
  346. package/dist/features/page/PublishedPageExperience.js +0 -23
  347. package/dist/features/preview/DerivedPreview.js +0 -134
  348. package/dist/features/preview/commentsEnabled.js +0 -8
  349. package/dist/features/preview/components/AddBlockSidebar.js +0 -381
  350. package/dist/features/preview/components/AttachedComments.js +0 -194
  351. package/dist/features/preview/components/CommentHeader.js +0 -122
  352. package/dist/features/preview/components/CommentSidebar.js +0 -29
  353. package/dist/features/preview/components/CommentTargetQuote.js +0 -166
  354. package/dist/features/preview/components/DerivedLayoutSidebar.d.ts +0 -5
  355. package/dist/features/preview/components/DerivedLayoutSidebar.js +0 -179
  356. package/dist/features/preview/components/DerivedPageInfoSidebar.js +0 -69
  357. package/dist/features/preview/components/LeftSidebar.js +0 -68
  358. package/dist/features/preview/components/PageEditorSidebar.js +0 -563
  359. package/dist/features/preview/components/PageInfoSidebar.js +0 -1551
  360. package/dist/features/preview/components/PageNavigatorSidebar.js +0 -78
  361. package/dist/features/preview/components/PageStatusBadge.js +0 -97
  362. package/dist/features/preview/components/PeekedBlock.js +0 -217
  363. package/dist/features/preview/components/PreviewComments.js +0 -56
  364. package/dist/features/preview/components/PreviewToolbarSpacer.js +0 -43
  365. package/dist/features/preview/components/PublicationRow.js +0 -422
  366. package/dist/features/preview/components/PublishDialog.js +0 -194
  367. package/dist/features/preview/components/RightSidebar.js +0 -59
  368. package/dist/features/preview/previewCommentsStore.js +0 -115
  369. package/dist/features/preview/publication.js +0 -81
  370. package/dist/features/runtime/SharedChromeContext.js +0 -7
  371. package/dist/features/studio/components/EnvironmentMenu.js +0 -413
  372. package/dist/features/vite/appGeneration.js +0 -89
  373. package/dist/lib/view-queries.js +0 -28
  374. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/Matches.d.ts +0 -114
  375. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/RouterProvider.d.ts +0 -25
  376. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/config.d.ts +0 -1
  377. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/defer.d.ts +0 -1
  378. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/fileRoute.d.ts +0 -20
  379. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/global.d.ts +0 -8
  380. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/hash-scroll.d.ts +0 -1
  381. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/index.d.ts +0 -18
  382. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/link.d.ts +0 -161
  383. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/load-matches.d.ts +0 -6
  384. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/location.d.ts +0 -54
  385. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/lru-cache.d.ts +0 -8
  386. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/manifest.d.ts +0 -32
  387. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/new-process-route-tree.d.ts +0 -115
  388. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/not-found.d.ts +0 -1
  389. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/redirect.d.ts +0 -49
  390. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/rewrite.d.ts +0 -1
  391. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/root.d.ts +0 -6
  392. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/route.d.ts +0 -343
  393. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/routeInfo.d.ts +0 -48
  394. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/router.d.ts +0 -695
  395. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/scroll-restoration.d.ts +0 -1
  396. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/searchMiddleware.d.ts +0 -1
  397. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/searchParams.d.ts +0 -5
  398. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/ssr/serializer/RawStream.d.ts +0 -38
  399. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/ssr/serializer/seroval-plugins.d.ts +0 -1
  400. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/ssr/serializer/transformer.d.ts +0 -65
  401. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/stores.d.ts +0 -69
  402. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/structuralSharing.d.ts +0 -1
  403. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/typePrimitives.d.ts +0 -1
  404. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useLoaderData.d.ts +0 -1
  405. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useLoaderDeps.d.ts +0 -1
  406. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useNavigate.d.ts +0 -10
  407. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useParams.d.ts +0 -1
  408. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useRouteContext.d.ts +0 -1
  409. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useSearch.d.ts +0 -1
  410. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/utils.d.ts +0 -28
  411. package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/validators.d.ts +0 -49
  412. package/skills/camox/references/cli-environments.md +0 -37
@@ -0,0 +1,222 @@
1
+ import { UNNAMED_DEFAULT_LOCALE, localeHeaders } from "./locale-path.js";
2
+ import { getApiClient } from "./api-client.js";
3
+ import { c } from "react/compiler-runtime";
4
+ import * as React from "react";
5
+ import { generateUuidv7 } from "@camox/api-contract/ids";
6
+ import { DEVELOPMENT_DRAFT, DRAFT_CREATE_HEADER, DRAFT_HEADER, DRAFT_SEARCH_PARAM } from "@camox/api-contract/drafts";
7
+ import { LIVE_KEY_SCOPE, scopeOfKey } from "@camox/api-contract/query-keys";
8
+
9
+ //#region src/lib/draft-scope.ts
10
+ /** The draft a URL names, if any. */
11
+ function draftNamedBy(href) {
12
+ return new URL(href, "http://camox.local").searchParams.get(DRAFT_SEARCH_PARAM) || null;
13
+ }
14
+ /** The URL without the draft param. */
15
+ function withoutDraft(href) {
16
+ const url = new URL(href);
17
+ url.searchParams.delete(DRAFT_SEARCH_PARAM);
18
+ return url.href;
19
+ }
20
+ function buildIsDevelopmentMode() {
21
+ return typeof __CAMOX_DEVELOPMENT_DRAFT__ !== "undefined" && __CAMOX_DEVELOPMENT_DRAFT__;
22
+ }
23
+ function createDraftScope({ queryClient, browser, developmentMode = buildIsDevelopmentMode(), loadDevelopmentDraftId = async (projectId) => (await getApiClient().drafts.get({ projectId }))?.id }) {
24
+ let current = developmentMode ? DEVELOPMENT_DRAFT : null;
25
+ let locale = UNNAMED_DEFAULT_LOCALE;
26
+ let pending = null;
27
+ let developmentDraftId;
28
+ let adoptedRender = false;
29
+ const listeners = /* @__PURE__ */ new Set();
30
+ const noticeListeners = /* @__PURE__ */ new Set();
31
+ const pendingNotices = [];
32
+ const draftOfRender = (rendered) => {
33
+ if (!developmentMode) return rendered.draftId ?? null;
34
+ return rendered.refusedDraft ? null : DEVELOPMENT_DRAFT;
35
+ };
36
+ const notify = (move) => {
37
+ for (const listener of listeners) listener({
38
+ draftId: current,
39
+ move
40
+ });
41
+ };
42
+ const report = (notice) => {
43
+ if (noticeListeners.size === 0) return void pendingNotices.push(notice);
44
+ for (const listener of noticeListeners) listener(notice);
45
+ };
46
+ const replaceUrl = (draftId) => {
47
+ if (!browser) return;
48
+ const url = new URL(browser.location.href);
49
+ if (draftId === url.searchParams.get(DRAFT_SEARCH_PARAM)) return;
50
+ if (draftId) url.searchParams.set(DRAFT_SEARCH_PARAM, draftId);
51
+ else url.searchParams.delete(DRAFT_SEARCH_PARAM);
52
+ browser.history.replaceState(browser.history.state, "", url.pathname + url.search + url.hash);
53
+ };
54
+ const enterStartedDraft = (draftId) => {
55
+ pending = null;
56
+ current = draftId;
57
+ replaceUrl(draftId);
58
+ for (const query of queryClient.getQueryCache().findAll({ queryKey: ["camox"] })) {
59
+ if (scopeOfKey(query.queryKey) !== LIVE_KEY_SCOPE || query.state.data === void 0) continue;
60
+ queryClient.setQueryData([...query.queryKey.slice(0, -1), draftId], query.state.data);
61
+ }
62
+ queryClient.invalidateQueries({
63
+ queryKey: ["camox"],
64
+ predicate: (query) => scopeOfKey(query.queryKey) !== LIVE_KEY_SCOPE
65
+ });
66
+ notify("started");
67
+ };
68
+ const headersFor = (contentWrite) => {
69
+ const noop = () => {};
70
+ const inLocale = localeHeaders(locale);
71
+ if (current) return {
72
+ headers: {
73
+ [DRAFT_HEADER]: current,
74
+ ...inLocale
75
+ },
76
+ settle: noop
77
+ };
78
+ if (!contentWrite || developmentMode) return {
79
+ headers: inLocale,
80
+ settle: noop
81
+ };
82
+ pending ??= {
83
+ id: generateUuidv7(),
84
+ inFlight: 0
85
+ };
86
+ const started = pending;
87
+ started.inFlight += 1;
88
+ return {
89
+ headers: {
90
+ [DRAFT_HEADER]: started.id,
91
+ [DRAFT_CREATE_HEADER]: "1",
92
+ ...inLocale
93
+ },
94
+ settle: (ok) => {
95
+ if (pending !== started) return;
96
+ started.inFlight -= 1;
97
+ if (ok) return enterStartedDraft(started.id);
98
+ if (started.inFlight === 0) pending = null;
99
+ }
100
+ };
101
+ };
102
+ return {
103
+ current: () => current,
104
+ locale: () => locale,
105
+ developmentMode,
106
+ subscribe(listener) {
107
+ listeners.add(listener);
108
+ return () => listeners.delete(listener);
109
+ },
110
+ requestHeaders: headersFor,
111
+ enterStarted(draftId) {
112
+ if (current !== null) return false;
113
+ enterStartedDraft(draftId);
114
+ return true;
115
+ },
116
+ hrefFor(to, { from, draft } = {}) {
117
+ if (developmentMode) return to;
118
+ const base = new URL(from ?? browser?.location.href ?? "http://camox.local");
119
+ const target = new URL(to, base);
120
+ if (target.origin !== base.origin) return to;
121
+ if (draft === void 0 && target.searchParams.has(DRAFT_SEARCH_PARAM)) return to;
122
+ const next = draft === void 0 ? current : draft;
123
+ if (next) target.searchParams.set(DRAFT_SEARCH_PARAM, next);
124
+ else target.searchParams.delete(DRAFT_SEARCH_PARAM);
125
+ if (target.href === new URL(to, base).href) return to;
126
+ return /^[a-z][a-z\d+.-]*:/i.test(to) || to.startsWith("//") ? target.href : `${target.pathname}${target.search}${target.hash}`;
127
+ },
128
+ adopt(rendered) {
129
+ if (rendered.locale) locale = rendered.locale;
130
+ if (rendered.refusedDraft) {
131
+ replaceUrl(null);
132
+ if (rendered.refusedDraft.notice) report(rendered.refusedDraft.notice);
133
+ }
134
+ const next = draftOfRender(rendered);
135
+ if (next !== null) pending = null;
136
+ const firstRender = !adoptedRender;
137
+ adoptedRender = true;
138
+ if (next === current) return;
139
+ current = next;
140
+ if (!firstRender) {
141
+ const entered = next ?? LIVE_KEY_SCOPE;
142
+ queryClient.invalidateQueries({
143
+ queryKey: ["camox"],
144
+ predicate: (query) => scopeOfKey(query.queryKey) === entered,
145
+ refetchType: "none"
146
+ });
147
+ }
148
+ notify("adopted");
149
+ },
150
+ leave(ended, { notice = false } = {}) {
151
+ queryClient.invalidateQueries({ queryKey: ["camox"] });
152
+ if (developmentMode) return false;
153
+ pending = null;
154
+ current = null;
155
+ replaceUrl(null);
156
+ if (notice && ended) report({
157
+ reason: "ended",
158
+ ...ended
159
+ });
160
+ notify("left");
161
+ return true;
162
+ },
163
+ onNotice(listener) {
164
+ noticeListeners.add(listener);
165
+ for (const notice of pendingNotices.splice(0)) listener(notice);
166
+ return () => noticeListeners.delete(listener);
167
+ },
168
+ async keyScopeOfDraft(draftId, projectId) {
169
+ if (current !== DEVELOPMENT_DRAFT) return draftId;
170
+ developmentDraftId ??= loadDevelopmentDraftId(projectId).catch(() => {
171
+ developmentDraftId = void 0;
172
+ });
173
+ return draftId === await developmentDraftId ? DEVELOPMENT_DRAFT : draftId;
174
+ }
175
+ };
176
+ }
177
+ const DraftScopeContext = React.createContext(null);
178
+ /**
179
+ * The draft scope the studio is in, for handlers and effects. Render code reads the draft it
180
+ * views from `useCurrentDraftId`: the scope object never changes, so a memoized render reading
181
+ * `current()` from it would keep showing the draft of its first render.
182
+ */
183
+ function useDraftScope() {
184
+ const scope = React.useContext(DraftScopeContext);
185
+ if (!scope) throw new Error("useDraftScope must be used inside a DraftScopeContext provider");
186
+ return scope;
187
+ }
188
+ const noScope = () => null;
189
+ const noSubscription = () => () => {};
190
+ /** The draft the studio is in, or null for Live. The caller re-renders after every move. */
191
+ function useCurrentDraftId() {
192
+ const scope = useDraftScope();
193
+ return React.useSyncExternalStore(scope.subscribe, scope.current, scope.current);
194
+ }
195
+ /** The draft scope and the draft it views, outside the studio too, where there is none. */
196
+ function useOptionalDraftScope() {
197
+ const $ = c(3);
198
+ const scope = React.useContext(DraftScopeContext);
199
+ const current = scope?.current ?? noScope;
200
+ const draftId = React.useSyncExternalStore(scope?.subscribe ?? noSubscription, current, current);
201
+ let t0;
202
+ if ($[0] !== draftId || $[1] !== scope) {
203
+ t0 = {
204
+ scope,
205
+ draftId
206
+ };
207
+ $[0] = draftId;
208
+ $[1] = scope;
209
+ $[2] = t0;
210
+ } else t0 = $[2];
211
+ return t0;
212
+ }
213
+ /**
214
+ * Follows the draft a browser URL names, for a studio mounted in a host application, whose
215
+ * navigation renders nothing the scope could adopt.
216
+ */
217
+ function followUrl(scope, href) {
218
+ scope.adopt({ draftId: draftNamedBy(href) ?? void 0 });
219
+ }
220
+
221
+ //#endregion
222
+ export { DraftScopeContext, createDraftScope, draftNamedBy, followUrl, useCurrentDraftId, useDraftScope, useOptionalDraftScope, withoutDraft };
@@ -0,0 +1,12 @@
1
+ //#region src/lib/html.ts
2
+ /** `value`, safe inside a double-quoted HTML attribute. */
3
+ function escapeAttribute(value) {
4
+ return value.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;");
5
+ }
6
+ /** `value` as JSON that can't close the `<script>` element it's written into. */
7
+ function serializeJsonForHtml(value) {
8
+ return JSON.stringify(value).replaceAll("<", "\\u003c");
9
+ }
10
+
11
+ //#endregion
12
+ export { escapeAttribute, serializeJsonForHtml };
@@ -0,0 +1,154 @@
1
+ import { UNNAMED_DEFAULT_LOCALE, localizedPath } from "./locale-path.js";
2
+ import { useViewLocale } from "./view-locale-context.js";
3
+ import { reads, useReadQuery } from "./studio-reads.js";
4
+ import { c } from "react/compiler-runtime";
5
+
6
+ //#region src/lib/link-pages.ts
7
+ /**
8
+ * The locale whose pages links fall back to from `locale`: the default locale, or none in the
9
+ * default locale itself. Its tag is never read: reads name the default locale by none.
10
+ */
11
+ function linkFallbackLocale(locale) {
12
+ return locale.isDefault ? null : UNNAMED_DEFAULT_LOCALE;
13
+ }
14
+ /**
15
+ * The pages a link can lead to from a locale, given its pages and its fallback locale's: its own,
16
+ * then the fallback's pages it has no localization of.
17
+ */
18
+ function linkablePages(pages, fallbackPages) {
19
+ const own = new Set(pages.map((page) => page.id));
20
+ return [...pages.map((page) => ({
21
+ page,
22
+ own: true
23
+ })), ...(fallbackPages ?? []).filter((page) => !own.has(page.id)).map((page) => ({
24
+ page,
25
+ own: false
26
+ }))];
27
+ }
28
+ /**
29
+ * The pages links lead to in `locale`, at their paths: its own pages under its prefix, then the
30
+ * default locale's pages it misses. Undefined until the locale's pages load.
31
+ */
32
+ function linkPagesIn(locale, pages, fallbackPages) {
33
+ if (!pages) return void 0;
34
+ return linkablePages(pages, fallbackPages).map(({ page, own }) => ({
35
+ id: page.id,
36
+ fullPath: own ? localizedPath(page.fullPath, locale) : page.fullPath
37
+ }));
38
+ }
39
+ /**
40
+ * Selects the page list as is. Selected values keep their identity while their content does, so
41
+ * fields don't re-render when a frame hydrates an equal list.
42
+ */
43
+ const samePageList = (pages) => pages;
44
+ /** Selects only that a read loaded, so fields don't re-render as its value changes. */
45
+ const isLoaded = () => true;
46
+ /**
47
+ * The pages a link can lead to in the locale viewed (see `linkablePages`), undefined until they
48
+ * load. A site render seeds them, so by default the project they wait for is read from the cache
49
+ * only: an anonymous visitor may not read the project, so fetching it would fail. The studio's
50
+ * editors fetch it with `fetchProject`.
51
+ */
52
+ function useLinkablePages(projectUuid, t0) {
53
+ const $ = c(21);
54
+ let t1;
55
+ if ($[0] !== t0) {
56
+ t1 = t0 === void 0 ? {} : t0;
57
+ $[0] = t0;
58
+ $[1] = t1;
59
+ } else t1 = $[1];
60
+ const { fetchProject: t2 } = t1;
61
+ const fetchProject = t2 === void 0 ? false : t2;
62
+ const { locale } = useViewLocale();
63
+ let t3;
64
+ if ($[2] !== locale) {
65
+ t3 = linkFallbackLocale(locale);
66
+ $[2] = locale;
67
+ $[3] = t3;
68
+ } else t3 = $[3];
69
+ const fallback = t3;
70
+ let t4;
71
+ if ($[4] !== projectUuid) {
72
+ t4 = reads.project({ projectUuid });
73
+ $[4] = projectUuid;
74
+ $[5] = t4;
75
+ } else t4 = $[5];
76
+ let t5;
77
+ if ($[6] !== fetchProject) {
78
+ t5 = {
79
+ enabled: fetchProject,
80
+ select: isLoaded
81
+ };
82
+ $[6] = fetchProject;
83
+ $[7] = t5;
84
+ } else t5 = $[7];
85
+ const { data: projectLoaded } = useReadQuery(t4, t5);
86
+ let t6;
87
+ if ($[8] !== projectUuid) {
88
+ t6 = reads.pageList({ projectUuid });
89
+ $[8] = projectUuid;
90
+ $[9] = t6;
91
+ } else t6 = $[9];
92
+ const t7 = !!projectLoaded;
93
+ let t8;
94
+ if ($[10] !== t7) {
95
+ t8 = {
96
+ enabled: t7,
97
+ select: samePageList
98
+ };
99
+ $[10] = t7;
100
+ $[11] = t8;
101
+ } else t8 = $[11];
102
+ const { data: pages } = useReadQuery(t6, t8);
103
+ let t9;
104
+ if ($[12] !== projectUuid) {
105
+ t9 = reads.pageList({ projectUuid });
106
+ $[12] = projectUuid;
107
+ $[13] = t9;
108
+ } else t9 = $[13];
109
+ const t10 = !!projectLoaded && fallback !== null;
110
+ const t11 = fallback ?? void 0;
111
+ let t12;
112
+ if ($[14] !== t10 || $[15] !== t11) {
113
+ t12 = {
114
+ enabled: t10,
115
+ locale: t11,
116
+ select: samePageList
117
+ };
118
+ $[14] = t10;
119
+ $[15] = t11;
120
+ $[16] = t12;
121
+ } else t12 = $[16];
122
+ const { data: fallbackPages } = useReadQuery(t9, t12);
123
+ const t13 = fallback ? fallbackPages : void 0;
124
+ let t14;
125
+ if ($[17] !== locale || $[18] !== pages || $[19] !== t13) {
126
+ t14 = {
127
+ locale,
128
+ pages,
129
+ fallbackPages: t13
130
+ };
131
+ $[17] = locale;
132
+ $[18] = pages;
133
+ $[19] = t13;
134
+ $[20] = t14;
135
+ } else t14 = $[20];
136
+ return t14;
137
+ }
138
+ /** The pages links lead to in the locale viewed, at their paths (see `linkPagesIn`). */
139
+ function useLinkPages(projectUuid, options) {
140
+ const $ = c(4);
141
+ const { locale, pages, fallbackPages } = useLinkablePages(projectUuid, options);
142
+ let t0;
143
+ if ($[0] !== fallbackPages || $[1] !== locale || $[2] !== pages) {
144
+ t0 = linkPagesIn(locale, pages, fallbackPages);
145
+ $[0] = fallbackPages;
146
+ $[1] = locale;
147
+ $[2] = pages;
148
+ $[3] = t0;
149
+ } else t0 = $[3];
150
+ return t0;
151
+ }
152
+
153
+ //#endregion
154
+ export { linkFallbackLocale, linkPagesIn, linkablePages, useLinkPages, useLinkablePages };
@@ -0,0 +1,22 @@
1
+ //#region src/lib/locale-path.d.ts
2
+ /**
3
+ * The URL names the locale: a non-default locale's paths sit under its prefix (`/de/preise`), the
4
+ * default locale's have none. The studio's routes follow the same rule (`/de/camox/content`).
5
+ * Pure, so the runtime and the browser share it.
6
+ */
7
+ /** A locale of a project, as `locales.list` returns it. */
8
+ export type LocaleView = {
9
+ tag: string;
10
+ isDefault: boolean;
11
+ };
12
+ /**
13
+ * Where a page sits in one locale it exists in: the locale's tag and the page's path there, under
14
+ * the locale's prefix. The runtime finds them for `hreflang` links and the sitemap; the
15
+ * alternates hook turns each into an `Alternate` a switcher links to.
16
+ */
17
+ export interface AlternatePath {
18
+ locale: string;
19
+ /** The page's runtime path, with its locale's prefix and without the runtime base path. */
20
+ path: string;
21
+ }
22
+ //#endregion
@@ -0,0 +1,57 @@
1
+ import { LOCALE_HEADER } from "@camox/api-contract/drafts";
2
+
3
+ //#region src/lib/locale-path.ts
4
+ /**
5
+ * The URL names the locale: a non-default locale's paths sit under its prefix (`/de/preise`), the
6
+ * default locale's have none. The studio's routes follow the same rule (`/de/camox/content`).
7
+ * Pure, so the runtime and the browser share it.
8
+ */
9
+ /**
10
+ * The default locale where nothing says its tag yet: before a render shows a locale, outside the
11
+ * page runtime, or without an API to read the project's locales from.
12
+ */
13
+ const UNNAMED_DEFAULT_LOCALE = {
14
+ tag: "und",
15
+ isDefault: true
16
+ };
17
+ /**
18
+ * The headers naming `locale` in a request (`LOCALE_HEADER`). The default locale is the API's own
19
+ * default, so only another locale is named.
20
+ */
21
+ function localeHeaders(locale) {
22
+ return locale && !locale.isDefault ? { [LOCALE_HEADER]: locale.tag } : {};
23
+ }
24
+ /** A locale's URL prefix: its tag in lowercase. The default locale has none. */
25
+ function localePrefix(locale) {
26
+ return locale.isDefault ? "" : `/${locale.tag.toLowerCase()}`;
27
+ }
28
+ /**
29
+ * The locale a runtime path names, and the path after its prefix, without search or hash. A first
30
+ * segment that isn't a non-default locale's prefix leaves the path the default locale's. A
31
+ * locale's home is `/de`; `/de/` names it too.
32
+ */
33
+ function parseLocalePath(pathname, locales) {
34
+ const path = pathname.replace(/[?#].*$/s, "") || "/";
35
+ const end = path.indexOf("/", 1);
36
+ const segment = end === -1 ? path.slice(1) : path.slice(1, end);
37
+ const named = locales.find((locale) => !locale.isDefault && localePrefix(locale) === `/${segment}`);
38
+ if (named) return {
39
+ locale: named,
40
+ path: end === -1 ? "/" : path.slice(end)
41
+ };
42
+ const fallback = locales.find((locale) => locale.isDefault);
43
+ if (!fallback) throw new Error("A project's locales include its default locale.");
44
+ return {
45
+ locale: fallback,
46
+ path
47
+ };
48
+ }
49
+ /** A locale-relative path under its locale's prefix, keeping its search and hash: `/` is `/de`. */
50
+ function localizedPath(path, locale) {
51
+ const prefix = localePrefix(locale);
52
+ if (!prefix) return path;
53
+ return path === "/" || /^\/[?#]/.test(path) ? `${prefix}${path.slice(1)}` : `${prefix}${path}`;
54
+ }
55
+
56
+ //#endregion
57
+ export { UNNAMED_DEFAULT_LOCALE, localeHeaders, localePrefix, localizedPath, parseLocalePath };