@kardalum/plugin-sdk 0.0.0-stage → 0.16.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 (332) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/LICENSE +202 -0
  3. package/README.md +80 -2
  4. package/dist/admin-section-registry.d.ts +34 -0
  5. package/dist/admin-section-registry.js +49 -0
  6. package/dist/built-in-serializers.d.ts +3 -0
  7. package/dist/built-in-serializers.js +18 -0
  8. package/dist/built-in-settings-schemas.d.ts +14 -0
  9. package/dist/built-in-settings-schemas.js +225 -0
  10. package/dist/built-in-value-schemas.d.ts +4 -0
  11. package/dist/built-in-value-schemas.js +47 -0
  12. package/dist/built-ins.d.ts +1 -0
  13. package/dist/built-ins.js +257 -0
  14. package/dist/capabilities.d.ts +29 -0
  15. package/dist/capabilities.js +67 -0
  16. package/dist/data-type-plugin.d.ts +28 -0
  17. package/dist/data-type-plugin.js +1 -0
  18. package/dist/datatype-validation.d.ts +26 -0
  19. package/dist/datatype-validation.js +110 -0
  20. package/dist/datatypes-entry.d.ts +4 -0
  21. package/dist/datatypes-entry.js +18 -0
  22. package/dist/define-plugin.d.ts +25 -0
  23. package/dist/define-plugin.js +51 -0
  24. package/dist/entitlement-entry.d.ts +5 -0
  25. package/dist/entitlement-entry.js +24 -0
  26. package/dist/entitlement-gate.d.ts +36 -0
  27. package/dist/entitlement-gate.js +201 -0
  28. package/dist/entitlement-types.d.ts +39 -0
  29. package/dist/entitlement-types.js +1 -0
  30. package/dist/entitlement.d.ts +57 -0
  31. package/dist/entitlement.js +170 -0
  32. package/dist/host-entry.d.ts +1 -0
  33. package/dist/host-entry.js +11 -0
  34. package/dist/icon-name.d.ts +1 -0
  35. package/dist/icon-name.js +1 -0
  36. package/dist/icons.d.ts +2 -0
  37. package/dist/icons.js +10 -0
  38. package/dist/index.d.ts +28 -0
  39. package/dist/index.js +94 -0
  40. package/dist/license-verdict-keys.d.ts +18 -0
  41. package/dist/license-verdict-keys.js +26 -0
  42. package/dist/local-host.d.ts +3 -0
  43. package/dist/local-host.js +38 -0
  44. package/dist/manifest-entry.d.ts +8 -0
  45. package/dist/manifest-entry.js +13 -0
  46. package/dist/manifest-schema.d.ts +476 -0
  47. package/dist/manifest-schema.js +823 -0
  48. package/dist/manifest.d.ts +611 -0
  49. package/dist/manifest.js +86 -0
  50. package/dist/media/media-picker.d.ts +39 -0
  51. package/dist/media/media-picker.js +447 -0
  52. package/dist/media/upload-error.d.ts +12 -0
  53. package/dist/media/upload-error.js +30 -0
  54. package/dist/plugin-context.d.ts +82 -0
  55. package/dist/plugin-context.js +77 -0
  56. package/dist/plugin-screen-context.d.ts +71 -0
  57. package/dist/plugin-screen-context.js +41 -0
  58. package/dist/read-all-pages.d.ts +23 -0
  59. package/dist/read-all-pages.js +30 -0
  60. package/dist/register-built-ins.d.ts +1 -0
  61. package/dist/register-built-ins.js +41 -0
  62. package/dist/registry.d.ts +4 -0
  63. package/dist/registry.js +17 -0
  64. package/dist/rendition-eligibility.d.ts +24 -0
  65. package/dist/rendition-eligibility.js +40 -0
  66. package/dist/richtext/block-panel.d.ts +27 -0
  67. package/dist/richtext/block-panel.js +232 -0
  68. package/dist/richtext/extensions.d.ts +19 -0
  69. package/dist/richtext/extensions.js +56 -0
  70. package/dist/richtext/insert-menu.d.ts +24 -0
  71. package/dist/richtext/insert-menu.js +142 -0
  72. package/dist/richtext/kardalum-block.d.ts +33 -0
  73. package/dist/richtext/kardalum-block.js +282 -0
  74. package/dist/richtext/style-listbox.d.ts +10 -0
  75. package/dist/richtext/style-listbox.js +69 -0
  76. package/dist/richtext/text-style-class.d.ts +18 -0
  77. package/dist/richtext/text-style-class.js +36 -0
  78. package/dist/simple-storage-value-provider.d.ts +9 -0
  79. package/dist/simple-storage-value-provider.js +96 -0
  80. package/dist/structured-storage-types.d.ts +61 -0
  81. package/dist/structured-storage-types.js +11 -0
  82. package/dist/tailwind.d.ts +1 -0
  83. package/dist/tailwind.js +5 -0
  84. package/dist/tokens/system-dark.css +75 -0
  85. package/dist/tokens/tokens.css +239 -0
  86. package/dist/tokens/tokens.json +212 -0
  87. package/dist/tokens.d.ts +1 -0
  88. package/dist/tokens.js +11 -0
  89. package/dist/ui-entry.d.ts +5 -0
  90. package/dist/ui-entry.js +42 -0
  91. package/dist/views/content-list-preview.d.ts +1 -0
  92. package/dist/views/content-list-preview.js +14 -0
  93. package/dist/views/content-list-settings-view.d.ts +1 -0
  94. package/dist/views/content-list-settings-view.js +97 -0
  95. package/dist/views/content-list-view.d.ts +19 -0
  96. package/dist/views/content-list-view.js +248 -0
  97. package/dist/views/crop-view.d.ts +55 -0
  98. package/dist/views/crop-view.js +161 -0
  99. package/dist/views/date-range-view.d.ts +6 -0
  100. package/dist/views/date-range-view.js +55 -0
  101. package/dist/views/file-upload-view.d.ts +43 -0
  102. package/dist/views/file-upload-view.js +104 -0
  103. package/dist/views/html-code-editor.d.ts +10 -0
  104. package/dist/views/html-code-editor.js +101 -0
  105. package/dist/views/html-view.d.ts +3 -0
  106. package/dist/views/html-view.js +53 -0
  107. package/dist/views/image-view.d.ts +3 -0
  108. package/dist/views/image-view.js +372 -0
  109. package/dist/views/rich-text-view.d.ts +2 -0
  110. package/dist/views/rich-text-view.js +429 -0
  111. package/node_modules/@kardalum/api-schemas/LICENSE +202 -0
  112. package/node_modules/@kardalum/api-schemas/README.md +56 -0
  113. package/node_modules/@kardalum/api-schemas/dist/action.schema.d.ts +30 -0
  114. package/node_modules/@kardalum/api-schemas/dist/action.schema.js +88 -0
  115. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +17 -0
  116. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +25 -0
  117. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +93 -0
  118. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +88 -0
  119. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +89 -0
  120. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +60 -0
  121. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +24 -0
  122. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +47 -0
  123. package/node_modules/@kardalum/api-schemas/dist/auth.schema.d.ts +38 -0
  124. package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +38 -0
  125. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +542 -0
  126. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +357 -0
  127. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +158 -0
  128. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +139 -0
  129. package/node_modules/@kardalum/api-schemas/dist/content-path.d.ts +125 -0
  130. package/node_modules/@kardalum/api-schemas/dist/content-path.js +260 -0
  131. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +20 -0
  132. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +23 -0
  133. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +152 -0
  134. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +82 -0
  135. package/node_modules/@kardalum/api-schemas/dist/content-version.schema.d.ts +18 -0
  136. package/node_modules/@kardalum/api-schemas/dist/content-version.schema.js +22 -0
  137. package/node_modules/@kardalum/api-schemas/dist/content.schema.d.ts +17 -0
  138. package/node_modules/@kardalum/api-schemas/dist/content.schema.js +20 -0
  139. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +352 -0
  140. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +133 -0
  141. package/node_modules/@kardalum/api-schemas/dist/culture-direction.d.ts +1 -0
  142. package/node_modules/@kardalum/api-schemas/dist/culture-direction.js +9 -0
  143. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +37 -0
  144. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +32 -0
  145. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +9 -0
  146. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +32 -0
  147. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +298 -0
  148. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +138 -0
  149. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.d.ts +121 -0
  150. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +147 -0
  151. package/node_modules/@kardalum/api-schemas/dist/health.schema.d.ts +6 -0
  152. package/node_modules/@kardalum/api-schemas/dist/health.schema.js +5 -0
  153. package/node_modules/@kardalum/api-schemas/dist/html-entities.d.ts +4 -0
  154. package/node_modules/@kardalum/api-schemas/dist/html-entities.js +250 -0
  155. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +113 -0
  156. package/node_modules/@kardalum/api-schemas/dist/index.js +64 -0
  157. package/node_modules/@kardalum/api-schemas/dist/licensing.schema.d.ts +15 -0
  158. package/node_modules/@kardalum/api-schemas/dist/licensing.schema.js +14 -0
  159. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.d.ts +73 -0
  160. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.js +104 -0
  161. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +682 -0
  162. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +269 -0
  163. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +177 -0
  164. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +222 -0
  165. package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.d.ts +77 -0
  166. package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.js +53 -0
  167. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +75 -0
  168. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +117 -0
  169. package/node_modules/@kardalum/api-schemas/dist/media-reference.d.ts +27 -0
  170. package/node_modules/@kardalum/api-schemas/dist/media-reference.js +279 -0
  171. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.d.ts +74 -0
  172. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +157 -0
  173. package/node_modules/@kardalum/api-schemas/dist/media.schema.d.ts +80 -0
  174. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +156 -0
  175. package/node_modules/@kardalum/api-schemas/dist/nav.schema.d.ts +23 -0
  176. package/node_modules/@kardalum/api-schemas/dist/nav.schema.js +55 -0
  177. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.d.ts +846 -0
  178. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +356 -0
  179. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +20 -0
  180. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +27 -0
  181. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +249 -0
  182. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +84 -0
  183. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.d.ts +65 -0
  184. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +889 -0
  185. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +172 -0
  186. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +196 -0
  187. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +31 -0
  188. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +38 -0
  189. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +69 -0
  190. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +59 -0
  191. package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +585 -0
  192. package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +536 -0
  193. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +75 -0
  194. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +213 -0
  195. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +391 -0
  196. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +413 -0
  197. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +29 -0
  198. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +100 -0
  199. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +44 -0
  200. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +162 -0
  201. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +31 -0
  202. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +25 -0
  203. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.d.ts +15 -0
  204. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +24 -0
  205. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +314 -0
  206. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +338 -0
  207. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +79 -0
  208. package/node_modules/@kardalum/api-schemas/dist/render-editing.js +50 -0
  209. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.d.ts +9 -0
  210. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +13 -0
  211. package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.d.ts +2 -0
  212. package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.js +16 -0
  213. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +96 -0
  214. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +75 -0
  215. package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.d.ts +17 -0
  216. package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.js +27 -0
  217. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +35 -0
  218. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +79 -0
  219. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +138 -0
  220. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +105 -0
  221. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +243 -0
  222. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +296 -0
  223. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +47 -0
  224. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +27 -0
  225. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +30 -0
  226. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +19 -0
  227. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +112 -0
  228. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +74 -0
  229. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +41 -0
  230. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +39 -0
  231. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +21 -0
  232. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +14 -0
  233. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +97 -0
  234. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +73 -0
  235. package/node_modules/@kardalum/api-schemas/package.json +35 -0
  236. package/node_modules/@kardalum/design-tokens/LICENSE +202 -0
  237. package/node_modules/@kardalum/design-tokens/README.md +29 -0
  238. package/node_modules/@kardalum/design-tokens/dist/build-css.d.ts +32 -0
  239. package/node_modules/@kardalum/design-tokens/dist/build-css.js +88 -0
  240. package/node_modules/@kardalum/design-tokens/dist/generate.d.ts +1 -0
  241. package/node_modules/@kardalum/design-tokens/dist/generate.js +18 -0
  242. package/node_modules/@kardalum/design-tokens/dist/index.d.ts +6 -0
  243. package/node_modules/@kardalum/design-tokens/dist/index.js +4 -0
  244. package/node_modules/@kardalum/design-tokens/dist/system-dark.css +75 -0
  245. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +33 -0
  246. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +54 -0
  247. package/node_modules/@kardalum/design-tokens/dist/theme-css.d.ts +12 -0
  248. package/node_modules/@kardalum/design-tokens/dist/theme-css.js +42 -0
  249. package/node_modules/@kardalum/design-tokens/dist/theme-types.d.ts +43 -0
  250. package/node_modules/@kardalum/design-tokens/dist/theme-types.js +1 -0
  251. package/node_modules/@kardalum/design-tokens/dist/themes/dark.d.ts +13 -0
  252. package/node_modules/@kardalum/design-tokens/dist/themes/dark.js +120 -0
  253. package/node_modules/@kardalum/design-tokens/dist/themes/index.d.ts +5 -0
  254. package/node_modules/@kardalum/design-tokens/dist/themes/index.js +4 -0
  255. package/node_modules/@kardalum/design-tokens/dist/themes/light.d.ts +9 -0
  256. package/node_modules/@kardalum/design-tokens/dist/themes/light.js +13 -0
  257. package/node_modules/@kardalum/design-tokens/dist/tokens.css +239 -0
  258. package/node_modules/@kardalum/design-tokens/dist/tokens.d.ts +25 -0
  259. package/node_modules/@kardalum/design-tokens/dist/tokens.js +276 -0
  260. package/node_modules/@kardalum/design-tokens/dist/tokens.json +212 -0
  261. package/node_modules/@kardalum/design-tokens/dist/types.d.ts +91 -0
  262. package/node_modules/@kardalum/design-tokens/dist/types.js +5 -0
  263. package/node_modules/@kardalum/design-tokens/package.json +42 -0
  264. package/node_modules/@kardalum/plugin-package/LICENSE +202 -0
  265. package/node_modules/@kardalum/plugin-package/README.md +71 -0
  266. package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +111 -0
  267. package/node_modules/@kardalum/plugin-package/dist/build-reference.js +61 -0
  268. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
  269. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +351 -0
  270. package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +50 -0
  271. package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +659 -0
  272. package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +19 -0
  273. package/node_modules/@kardalum/plugin-package/dist/envelope.js +104 -0
  274. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +37 -0
  275. package/node_modules/@kardalum/plugin-package/dist/extract.js +199 -0
  276. package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +17 -0
  277. package/node_modules/@kardalum/plugin-package/dist/hash.js +69 -0
  278. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +13 -0
  279. package/node_modules/@kardalum/plugin-package/dist/index.js +8 -0
  280. package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +185 -0
  281. package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +236 -0
  282. package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +50 -0
  283. package/node_modules/@kardalum/plugin-package/dist/package-contract.js +115 -0
  284. package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +2 -0
  285. package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +6 -0
  286. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +20 -0
  287. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +57 -0
  288. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +43 -0
  289. package/node_modules/@kardalum/plugin-package/dist/types.js +15 -0
  290. package/node_modules/@kardalum/plugin-package/package.json +54 -0
  291. package/node_modules/@kardalum/ui/LICENSE +202 -0
  292. package/node_modules/@kardalum/ui/README.md +35 -0
  293. package/node_modules/@kardalum/ui/dist/components/alert-dialog.d.ts +14 -0
  294. package/node_modules/@kardalum/ui/dist/components/alert-dialog.js +38 -0
  295. package/node_modules/@kardalum/ui/dist/components/badge.d.ts +9 -0
  296. package/node_modules/@kardalum/ui/dist/components/badge.js +30 -0
  297. package/node_modules/@kardalum/ui/dist/components/button.d.ts +11 -0
  298. package/node_modules/@kardalum/ui/dist/components/button.js +37 -0
  299. package/node_modules/@kardalum/ui/dist/components/checkbox.d.ts +5 -0
  300. package/node_modules/@kardalum/ui/dist/components/checkbox.js +7 -0
  301. package/node_modules/@kardalum/ui/dist/components/dialog.d.ts +17 -0
  302. package/node_modules/@kardalum/ui/dist/components/dialog.js +48 -0
  303. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.d.ts +18 -0
  304. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +53 -0
  305. package/node_modules/@kardalum/ui/dist/components/empty-state.d.ts +30 -0
  306. package/node_modules/@kardalum/ui/dist/components/empty-state.js +9 -0
  307. package/node_modules/@kardalum/ui/dist/components/input.d.ts +4 -0
  308. package/node_modules/@kardalum/ui/dist/components/input.js +6 -0
  309. package/node_modules/@kardalum/ui/dist/components/panel.d.ts +5 -0
  310. package/node_modules/@kardalum/ui/dist/components/panel.js +6 -0
  311. package/node_modules/@kardalum/ui/dist/components/property-field.d.ts +19 -0
  312. package/node_modules/@kardalum/ui/dist/components/property-field.js +89 -0
  313. package/node_modules/@kardalum/ui/dist/components/sheet.d.ts +17 -0
  314. package/node_modules/@kardalum/ui/dist/components/sheet.js +55 -0
  315. package/node_modules/@kardalum/ui/dist/components/skeleton.d.ts +3 -0
  316. package/node_modules/@kardalum/ui/dist/components/skeleton.js +9 -0
  317. package/node_modules/@kardalum/ui/dist/components/switch.d.ts +5 -0
  318. package/node_modules/@kardalum/ui/dist/components/switch.js +7 -0
  319. package/node_modules/@kardalum/ui/dist/components/tab-strip.d.ts +34 -0
  320. package/node_modules/@kardalum/ui/dist/components/tab-strip.js +72 -0
  321. package/node_modules/@kardalum/ui/dist/components/toast.d.ts +18 -0
  322. package/node_modules/@kardalum/ui/dist/components/toast.js +42 -0
  323. package/node_modules/@kardalum/ui/dist/components/toaster.d.ts +12 -0
  324. package/node_modules/@kardalum/ui/dist/components/toaster.js +11 -0
  325. package/node_modules/@kardalum/ui/dist/components/use-toast.d.ts +17 -0
  326. package/node_modules/@kardalum/ui/dist/components/use-toast.js +62 -0
  327. package/node_modules/@kardalum/ui/dist/index.d.ts +18 -0
  328. package/node_modules/@kardalum/ui/dist/index.js +18 -0
  329. package/node_modules/@kardalum/ui/dist/lib/cn.d.ts +2 -0
  330. package/node_modules/@kardalum/ui/dist/lib/cn.js +5 -0
  331. package/node_modules/@kardalum/ui/package.json +63 -0
  332. package/package.json +146 -4
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The text of a slot's label for a locale: the locale as given, else its
3
+ * primary subtag (`de-AT` reads `de`), else `en`, which every label carries.
4
+ * Locale codes compare case-insensitively, since BCP 47 tags are
5
+ * case-insensitive and a label written `pt-BR` must answer `pt-br`.
6
+ */
7
+ export function slotLabel(label, locale) {
8
+ const wanted = locale.toLowerCase();
9
+ const primary = wanted.split("-")[0] ?? "";
10
+ let primaryText;
11
+ for (const [code, text] of Object.entries(label)) {
12
+ const lower = code.toLowerCase();
13
+ if (lower === wanted)
14
+ return text;
15
+ if (primaryText === undefined && primary !== "" && lower === primary)
16
+ primaryText = text;
17
+ }
18
+ return primaryText ?? label.en;
19
+ }
20
+ /**
21
+ * The contributions that put code in the browser, and so the ones that
22
+ * make a plugin ship a client bundle (S267 section 5, implemented by
23
+ * S268 Task 3). `dataTypes`, `adminSections`, `railEntries` (S280),
24
+ * `dashboardWidgets` and `settingsPages` carry React views; `contentTreeActions` and
25
+ * `editorToolbar` carry client callbacks (`onSelect`, `onClick`), which
26
+ * is just as much browser code even though neither has a `view` key.
27
+ *
28
+ * Everything else is absent on purpose: `apiRoutes`, `hooks`,
29
+ * `scheduledTasks`, `mediaProcessors` and `serializers` run on the
30
+ * server, and `documentTypes`, `themeTokens`, `templates`, `assets`,
31
+ * `bundledPlugins`, `bundledTemplate` and `exposedServices` are data the
32
+ * host consumes rather than code the browser runs.
33
+ *
34
+ * This replaces the type-keyed CLIENT_BUNDLE_TYPES. It is more correct
35
+ * than that list was, not merely equivalent: a plugin listed as
36
+ * `section` with no views had to ship a remoteEntry.js it did not have.
37
+ */
38
+ export const VIEW_BEARING_CONTRIBUTIONS = [
39
+ "dataTypes",
40
+ "adminSections",
41
+ "railEntries",
42
+ "dashboardWidgets",
43
+ "settingsPages",
44
+ "contentTreeActions",
45
+ "editorToolbar",
46
+ ];
47
+ /**
48
+ * Whether a manifest's declared contributions require a client bundle:
49
+ * whether a built artifact must contain a `remoteEntry.js`, and whether
50
+ * the Module Federation build runs at all.
51
+ *
52
+ * Accepts both a live `PluginContributions` and the redacted, JSON-safe
53
+ * summary kardalum plugin writes into a package's `manifest.json` (which
54
+ * keeps every contribution key and every array's length, dropping only
55
+ * the function-valued fields inside each entry), so both sides of an
56
+ * install answer this identically.
57
+ *
58
+ * An empty array declares nothing and therefore buys no bundle.
59
+ *
60
+ * NAMED `declaresClientBundle`, not `hasClientBundle`, on purpose. The
61
+ * S144 predicate of that name took a `type` string and answered `true`
62
+ * for `"datatype"`; this one takes an object and answers `false` for the
63
+ * same argument, silently, because a string is not an object. All three
64
+ * things a `false` decides are quiet (skip the federation build, stop
65
+ * requiring a remoteEntry.js, hand out `remoteUrl: ""`), so a caller left
66
+ * on the old shape produced a package that reported "Built" and shipped
67
+ * nothing, which is how this bit during S268 Task 3 itself: a stale
68
+ * `kardalum/dist/plugin/build.js` passed a string and the gap surfaced only
69
+ * as a downstream server test. Under the new name that same stale caller
70
+ * fails at module load with "does not provide an export named
71
+ * 'hasClientBundle'", before it can decide anything. The old name is
72
+ * gone rather than aliased: a name that outlives its meaning is how these
73
+ * get recombined later. A caller passing a string to THIS name is a
74
+ * compile error against the signature below.
75
+ */
76
+ export function declaresClientBundle(contributions) {
77
+ if (contributions === null || typeof contributions !== "object")
78
+ return false;
79
+ const declared = contributions;
80
+ return VIEW_BEARING_CONTRIBUTIONS.some((key) => {
81
+ const value = declared[key];
82
+ if (value === null || value === undefined)
83
+ return false;
84
+ return Array.isArray(value) ? value.length > 0 : true;
85
+ });
86
+ }
@@ -0,0 +1,39 @@
1
+ export interface MediaPickerItem {
2
+ id: string;
3
+ downloadUrl: string;
4
+ alt?: string;
5
+ }
6
+ export interface MediaPickerProps {
7
+ onPick: (item: MediaPickerItem) => void;
8
+ onClose: () => void;
9
+ /**
10
+ * Whether a pick is followed by an alt-text step. TRUE for rich text,
11
+ * where the alt lives on the inserted node and is authored before the
12
+ * image lands in the document. FALSE for an image field, which stores
13
+ * one media id and has nowhere to put alt text, so a pick commits and
14
+ * closes at once.
15
+ *
16
+ * Required, not defaulted: a caller that has not decided is a caller
17
+ * that has not thought about where its alt text is going to live.
18
+ */
19
+ collectAlt: boolean;
20
+ /**
21
+ * What the calling field accepts, in the same spellings its settings
22
+ * allow (`image/*`, `image/png`, `.jpg`, `jpg`). Absent or empty means
23
+ * images, which is what rich text has always shown.
24
+ */
25
+ acceptedTypes?: string[];
26
+ /**
27
+ * The rendition NAME the calling field asks its picture for ("3x4",
28
+ * "thumb"), as `renditionName` in @kardalum/api-schemas produces one
29
+ * and as ImageSettingsSchema stores it. Absent means the field asks for
30
+ * no particular crop.
31
+ *
32
+ * It is not a filter. Items without that crop are still offered, and
33
+ * marked as falling back to their full image: hiding a perfectly good
34
+ * photo would leave an editor hunting for an upload that is right
35
+ * there.
36
+ */
37
+ rendition?: string;
38
+ }
39
+ export declare function MediaPicker({ onPick, onClose, collectAlt, acceptedTypes, rendition }: MediaPickerProps): import("react").JSX.Element;
@@ -0,0 +1,447 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import { ChevronRight, Folder as FolderIcon } from "lucide-react";
4
+ import { renditionShape, } from "@kardalum/api-schemas";
5
+ import { Button, cn, Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, } from "@kardalum/ui";
6
+ import { MANAGE_API, usePluginApi } from "../plugin-context.js";
7
+ import { readAllPages } from "../read-all-pages.js";
8
+ import { isRenditionIneligible } from "../rendition-eligibility.js";
9
+ import { uploadFailureMessage } from "./upload-error.js";
10
+ // GET /api/manage/v1/media page size for the picker's grid (S197 Task 2). Additional
11
+ // pages are fetched on demand via the "Load more" button below, following
12
+ // MediaListQuerySchema's cursor contract (media-api.schema.ts) rather than
13
+ // assuming a library's whole image set fits on one page.
14
+ const PAGE_LIMIT = 50;
15
+ // The folder list is paged by the server (S300b): read it to its end, 200 folders a page, at most 50 pages.
16
+ const FOLDER_PAGE_LIMIT = 200;
17
+ const FOLDER_PAGE_CAP = 50;
18
+ // What the picker offers when the caller names nothing. Rich text has no
19
+ // accepted-types setting of its own and has always shown images only, so
20
+ // this is that behaviour written down rather than a new default.
21
+ const DEFAULT_ACCEPTED_TYPES = ["image/*"];
22
+ // The word the breadcrumb already uses for the library root, reused by the
23
+ // upload affordance so both name the same place the same way.
24
+ const ROOT_LABEL = "Root";
25
+ // --- Type filtering (S234d Task 6) ----------------------------------------
26
+ // The spec's sentence is that the picker offers items whose media type's
27
+ // file upload accepts the field's accepted types. An item's STORED media
28
+ // type is the outcome of exactly that upload, and it is already on the
29
+ // row, so the question is answered per item from the listing the picker
30
+ // already has rather than by loading every media document type and its
31
+ // file upload's settings first. It is also the tighter of the two
32
+ // readings: a media type that accepts both jpg and pdf cannot slip a PDF
33
+ // into an image field this way, which is the example the spec gives.
34
+ /** A stored media type reduced to its base form. It is whatever the
35
+ * uploading client sent, so `IMAGE/PNG` and `image/png; charset=binary`
36
+ * both have to answer as `image/png`. */
37
+ function baseMimeType(mimeType) {
38
+ const semicolon = mimeType.indexOf(";");
39
+ return (semicolon === -1 ? mimeType : mimeType.slice(0, semicolon)).trim().toLowerCase();
40
+ }
41
+ /** The extension a filename carries, without the dot, lowercased. Empty
42
+ * for a name with no extension (a leading dot is not one: `.gitignore` is
43
+ * a whole name). */
44
+ function fileExtension(filename) {
45
+ const dot = filename.lastIndexOf(".");
46
+ return dot <= 0 ? "" : filename.slice(dot + 1).trim().toLowerCase();
47
+ }
48
+ /** One accept token against one item, in the vocabulary of the HTML
49
+ * accept attribute, which is the vocabulary an image field's
50
+ * `acceptedTypes` is written in (image-view.tsx feeds it straight to an
51
+ * `accept`) and a superset of the bare extensions a file upload's
52
+ * settings store ("jpg"). */
53
+ function matchesAcceptToken(item, token) {
54
+ const wanted = token.trim().toLowerCase();
55
+ if (wanted === "")
56
+ return false;
57
+ if (wanted === "*" || wanted === "*/*")
58
+ return true;
59
+ if (wanted.includes("/")) {
60
+ const mimeType = baseMimeType(item.mimeType);
61
+ // "image/*" matches on the "image/" prefix; anything else is exact.
62
+ if (wanted.endsWith("/*"))
63
+ return mimeType.startsWith(wanted.slice(0, -1));
64
+ return mimeType === wanted;
65
+ }
66
+ const extension = fileExtension(item.filename);
67
+ return extension !== "" && extension === (wanted.startsWith(".") ? wanted.slice(1) : wanted);
68
+ }
69
+ function fieldAccepts(item, acceptedTypes) {
70
+ const tokens = acceptedTypes && acceptedTypes.length > 0 ? acceptedTypes : DEFAULT_ACCEPTED_TYPES;
71
+ return tokens.some((token) => matchesAcceptToken(item, token));
72
+ }
73
+ /** The same tokens as an `accept` attribute value, so the OS file dialog
74
+ * offers what this picker would have offered. A bare extension gains the
75
+ * dot the attribute wants. */
76
+ function acceptAttribute(acceptedTypes) {
77
+ const tokens = acceptedTypes && acceptedTypes.length > 0 ? acceptedTypes : DEFAULT_ACCEPTED_TYPES;
78
+ return tokens
79
+ .map((token) => token.trim())
80
+ .filter((token) => token !== "")
81
+ .map((token) => (token.includes("/") || token.startsWith(".") ? token : `.${token}`))
82
+ .join(",");
83
+ }
84
+ function groupFoldersByParent(folders) {
85
+ const map = new Map();
86
+ for (const folder of folders) {
87
+ const key = folder.parentId ?? "root";
88
+ const bucket = map.get(key);
89
+ if (bucket)
90
+ bucket.push(folder);
91
+ else
92
+ map.set(key, [folder]);
93
+ }
94
+ for (const bucket of map.values())
95
+ bucket.sort((a, b) => a.name.localeCompare(b.name));
96
+ return map;
97
+ }
98
+ function childFoldersOf(byParent, parentId) {
99
+ return byParent.get(parentId ?? "root") ?? [];
100
+ }
101
+ // The ancestor chain from the library root down to (and including)
102
+ // `folderId`, which is the breadcrumb's data. Stops rather than looping
103
+ // if it ever revisits a folder (a malformed cycle in the data can't hang
104
+ // this).
105
+ function folderPath(folderId, byId) {
106
+ const path = [];
107
+ const visited = new Set();
108
+ let current = folderId ? (byId.get(folderId) ?? null) : null;
109
+ while (current && !visited.has(current.id)) {
110
+ visited.add(current.id);
111
+ path.unshift(current);
112
+ current = current.parentId ? (byId.get(current.parentId) ?? null) : null;
113
+ }
114
+ return path;
115
+ }
116
+ // The one media picker, serving two callers (S234d Task 6, approved mockup
117
+ // screen 4): rich text's "Image" toolbar command, and a page's image
118
+ // field. It lived under richtext/ until this session, when the second
119
+ // caller arrived; nothing about the drawer is specific to either.
120
+ //
121
+ // A right-side drawer over the media library. Folders of the currently
122
+ // open location (Root to start) drill in one level at a time via a
123
+ // breadcrumb, then a grid of that folder's items to pick from, plus an
124
+ // upload control at the bottom naming the folder it would upload into.
125
+ // Always rendered open; the caller mounts this component only while the
126
+ // picker should be showing and supplies onClose for every way Radix's
127
+ // Dialog can close itself (Escape, overlay click, Close), the same
128
+ // controlled-open pattern as IconPickerDialog
129
+ // (apps/admin-ui/src/icons/icon-picker-dialog.tsx).
130
+ //
131
+ // downloadUrl is resolved fresh from each GET /api/manage/v1/media response, never
132
+ // cached across renders: a private item's URL carries a short-lived
133
+ // token, so a stale one would go dead (image-view.tsx's useMediaPreview
134
+ // :21-24 doctrine, mirrored here for the same reason).
135
+ //
136
+ // WHAT A PICK DOES depends on `collectAlt`. With it true (rich text),
137
+ // selection is two-step, the same "arm then confirm" shape as
138
+ // IconPickerDialog: clicking (or Enter-ing) a grid item arms it as
139
+ // `pending` (highlighted via aria-selected, nothing inserted yet), and an
140
+ // Alt text input appears with Insert/Cancel. Only Insert calls onPick,
141
+ // carrying whatever alt text was typed, empty allowed, because a
142
+ // decorative image is a legitimate choice. A fresh upload flows into the
143
+ // same confirm step, so alt text is always authored before an image lands
144
+ // in the document, never defaulted to a filename. With it false (an image
145
+ // field), there is nothing to confirm: the field stores one media id and
146
+ // has nowhere to put alt text, so a pick commits and the drawer closes.
147
+ //
148
+ // WHERE FOCUS GOES when it closes is the same on both paths, and this
149
+ // component decides it rather than leaving it to Radix: back to the
150
+ // control that opened the drawer, which outlives it. See the
151
+ // onCloseAutoFocus handler below for why Radix alone would drop the user
152
+ // on <body>. It matters most on the no-alt path, where the thing that was
153
+ // focused at the moment of closing is the tile, and the tile is about to
154
+ // stop existing. The one focus move made inside the drawer is INTO the
155
+ // alt input when a selection is armed, which is a step that keeps the
156
+ // drawer open.
157
+ //
158
+ // Cancel discards the pending selection AND closes the whole picker,
159
+ // matching IconPickerDialog's Cancel. Drilling into a different folder
160
+ // before confirming also discards a pending selection: the user's
161
+ // attention has moved on.
162
+ export function MediaPicker({ onPick, onClose, collectAlt, acceptedTypes, rendition }) {
163
+ const fetchApi = usePluginApi();
164
+ const [folders, setFolders] = useState([]);
165
+ const [currentFolderId, setCurrentFolderId] = useState(null);
166
+ // As the server sent them. The accepted-types filter is applied on the
167
+ // way to the grid rather than here, so the empty state can tell "this
168
+ // folder is empty" apart from "this folder holds nothing this field
169
+ // accepts", which are different problems with different fixes.
170
+ const [rawItems, setRawItems] = useState([]);
171
+ const [nextCursor, setNextCursor] = useState(null);
172
+ const [loading, setLoading] = useState(true);
173
+ const [loadingMore, setLoadingMore] = useState(false);
174
+ const [error, setError] = useState(null);
175
+ const [uploading, setUploading] = useState(false);
176
+ const [activeIndex, setActiveIndex] = useState(0);
177
+ const [pending, setPending] = useState(null);
178
+ const [altText, setAltText] = useState("");
179
+ // Whatever was focused when this drawer mounted, captured during the
180
+ // FIRST RENDER: by the time an effect could run, the drawer has already
181
+ // moved focus into itself. See onCloseAutoFocus below for what it is
182
+ // for. A state initializer rather than a ref so it is read once.
183
+ const [opener] = useState(() => typeof document === "undefined" ? null : document.activeElement);
184
+ // The shape the requested name encodes, which is what the sentences
185
+ // below show a person: "3x4" is a filename suffix, "3:4" is a ratio,
186
+ // and the two are the same fact (S234d Task 7b). The NAME is still what
187
+ // goes to the server on every listing request. Empty only when nothing
188
+ // was asked for, and every use of it below sits behind that check.
189
+ const requestedShape = rendition === undefined ? "" : renditionShape(rendition);
190
+ const optionRefs = useRef([]);
191
+ const altInputRef = useRef(null);
192
+ const uploadInputRef = useRef(null);
193
+ const items = useMemo(() => rawItems.filter((item) => fieldAccepts(item, acceptedTypes)), [rawItems, acceptedTypes]);
194
+ const foldersById = useMemo(() => new Map(folders.map((folder) => [folder.id, folder])), [folders]);
195
+ const foldersByParent = useMemo(() => groupFoldersByParent(folders), [folders]);
196
+ const visibleFolders = useMemo(() => childFoldersOf(foldersByParent, currentFolderId), [foldersByParent, currentFolderId]);
197
+ const breadcrumbPath = useMemo(() => folderPath(currentFolderId, foldersById), [currentFolderId, foldersById]);
198
+ const currentFolderName = breadcrumbPath.at(-1)?.name ?? ROOT_LABEL;
199
+ // The whole folder tree loads once. A failed folder fetch surfaces
200
+ // through the SAME error banner the image list uses (review fix:
201
+ // silently-empty folders are indistinguishable from "no subfolders
202
+ // exist", against this picker's own verbatim-error convention). One
203
+ // banner, whichever fetch failed most recently.
204
+ useEffect(() => {
205
+ let cancelled = false;
206
+ readAllPages(fetchApi, `${MANAGE_API}/media/folders`, "media folders", {
207
+ itemKey: "folders",
208
+ limit: FOLDER_PAGE_LIMIT,
209
+ cap: FOLDER_PAGE_CAP,
210
+ })
211
+ .then(({ items, complete }) => {
212
+ if (cancelled)
213
+ return;
214
+ setFolders(items);
215
+ // A tree that was not read to its end is a subset of the folders: say so through the banner the list uses.
216
+ if (!complete)
217
+ setError(`Only the first ${FOLDER_PAGE_CAP * FOLDER_PAGE_LIMIT} media folders could be read`);
218
+ })
219
+ .catch((err) => {
220
+ if (!cancelled)
221
+ setError(err instanceof Error ? err.message : String(err));
222
+ });
223
+ return () => {
224
+ cancelled = true;
225
+ };
226
+ }, [fetchApi]);
227
+ // `rendition` rides along as a query parameter, once per page, and the
228
+ // server answers it on every item through `hasRendition` (S234d Task 3).
229
+ // It is the whole fallback marking: nothing is asked per tile, and
230
+ // nothing is asked again when a tile is armed.
231
+ const listUrl = useCallback((folderId, cursor) => {
232
+ const params = new URLSearchParams();
233
+ params.set("limit", String(PAGE_LIMIT));
234
+ params.set("folderId", folderId ?? "root");
235
+ if (cursor)
236
+ params.set("cursor", cursor);
237
+ if (rendition)
238
+ params.set("rendition", rendition);
239
+ return `${MANAGE_API}/media?${params.toString()}`;
240
+ }, [rendition]);
241
+ // A generation counter, bumped on every call. It guards against a stale
242
+ // response (e.g. two rapid folder switches) overwriting the newer one,
243
+ // regardless of resolution order. Same idiom as media-section.tsx's own
244
+ // loadRequestIdRef.
245
+ const loadRequestIdRef = useRef(0);
246
+ const loadFirstPage = useCallback((folderId) => {
247
+ const requestId = ++loadRequestIdRef.current;
248
+ setLoading(true);
249
+ setError(null);
250
+ fetchApi(listUrl(folderId, null))
251
+ .then(async (response) => {
252
+ if (!response.ok)
253
+ throw new Error(`Failed to load media (${response.status})`);
254
+ const body = (await response.json());
255
+ if (requestId !== loadRequestIdRef.current)
256
+ return;
257
+ setRawItems(body.items);
258
+ setNextCursor(body.nextCursor);
259
+ })
260
+ .catch((err) => {
261
+ if (requestId !== loadRequestIdRef.current)
262
+ return;
263
+ setError(err instanceof Error ? err.message : String(err));
264
+ })
265
+ .finally(() => {
266
+ if (requestId === loadRequestIdRef.current)
267
+ setLoading(false);
268
+ });
269
+ }, [fetchApi, listUrl]);
270
+ useEffect(() => {
271
+ loadFirstPage(currentFolderId);
272
+ }, [currentFolderId, loadFirstPage]);
273
+ // Focus follows the armed selection into the confirm step (spec: "Enter
274
+ // on a focused option selects; focus moves to the alt input"). It fires
275
+ // for both a grid pick and a completed upload, since both go through
276
+ // setPending. Only ever reached when `collectAlt` is true: nothing is
277
+ // armed otherwise.
278
+ useEffect(() => {
279
+ if (pending)
280
+ altInputRef.current?.focus();
281
+ }, [pending]);
282
+ function openFolder(folderId) {
283
+ setCurrentFolderId(folderId);
284
+ setActiveIndex(0);
285
+ // A different folder is a different confirm scope, so discard whatever
286
+ // was armed rather than let it silently survive the navigation (see
287
+ // this component's own doc comment for the reasoning, same as Cancel).
288
+ setPending(null);
289
+ setAltText("");
290
+ }
291
+ async function loadMore() {
292
+ if (!nextCursor || loadingMore)
293
+ return;
294
+ setLoadingMore(true);
295
+ setError(null);
296
+ try {
297
+ const response = await fetchApi(listUrl(currentFolderId, nextCursor));
298
+ if (!response.ok)
299
+ throw new Error(`Failed to load media (${response.status})`);
300
+ const body = (await response.json());
301
+ setRawItems((current) => [...current, ...body.items]);
302
+ setNextCursor(body.nextCursor);
303
+ }
304
+ catch (err) {
305
+ setError(err instanceof Error ? err.message : String(err));
306
+ }
307
+ finally {
308
+ setLoadingMore(false);
309
+ }
310
+ }
311
+ // The one place a pick is decided. With no alt text to collect there is
312
+ // nothing to confirm, so the item commits and the drawer closes in the
313
+ // same gesture; otherwise it is armed and the confirm step takes over.
314
+ function selectItem(item) {
315
+ if (!collectAlt) {
316
+ onPick({ id: item.id, downloadUrl: item.downloadUrl });
317
+ onClose();
318
+ return;
319
+ }
320
+ setPending(item);
321
+ setAltText("");
322
+ }
323
+ // No Content-Type header: the browser sets the multipart boundary
324
+ // itself. folderId targets the currently open folder; the server
325
+ // requires the folderId form field to be appended BEFORE the file field
326
+ // (@fastify/multipart's request.file() stops reading parts once it finds
327
+ // the file part; see routes/media.ts's extractUploadFolderId doc
328
+ // comment, and media-api.ts's uploadMedia for the admin's own copy of
329
+ // this same rule), so the append order below is load-bearing, not
330
+ // stylistic.
331
+ async function handleUpload(event) {
332
+ const file = event.target.files?.[0];
333
+ event.target.value = ""; // lets the same file be re-selected later
334
+ if (!file)
335
+ return;
336
+ setUploading(true);
337
+ setError(null);
338
+ try {
339
+ const formData = new FormData();
340
+ if (currentFolderId)
341
+ formData.append("folderId", currentFolderId);
342
+ formData.append("file", file);
343
+ const response = await fetchApi(`${MANAGE_API}/media`, { method: "POST", body: formData });
344
+ // The server's own sentence, not a status code (S234d Task 8).
345
+ // This drawer has no size check of its own and cannot usefully have
346
+ // one: the ceiling belongs to the media document type the file will
347
+ // land on, which nothing here knows until the server has resolved
348
+ // it. Relaying what it said is this surface's whole part in that
349
+ // rule.
350
+ if (!response.ok)
351
+ throw new Error(await uploadFailureMessage(response));
352
+ const media = (await response.json());
353
+ // A fresh upload goes through the same door as an existing item: it
354
+ // still needs alt text authored where alt text is collected, and it
355
+ // still commits at once where it is not.
356
+ selectItem(media);
357
+ }
358
+ catch (err) {
359
+ setError(err instanceof Error ? err.message : String(err));
360
+ }
361
+ finally {
362
+ setUploading(false);
363
+ }
364
+ }
365
+ function focusIndex(index) {
366
+ setActiveIndex(index);
367
+ optionRefs.current[index]?.focus();
368
+ }
369
+ // Roving tabindex over the grid (WAI-ARIA listbox pattern, same shape as
370
+ // IconPickerDialog's grid): arrows/Home/End move focus only, Enter/Space
371
+ // picks the focused item (see selectItem).
372
+ function handleGridKeyDown(event) {
373
+ if (items.length === 0)
374
+ return;
375
+ let next = activeIndex;
376
+ switch (event.key) {
377
+ case "ArrowRight":
378
+ case "ArrowDown":
379
+ next = Math.min(activeIndex + 1, items.length - 1);
380
+ break;
381
+ case "ArrowLeft":
382
+ case "ArrowUp":
383
+ next = Math.max(activeIndex - 1, 0);
384
+ break;
385
+ case "Home":
386
+ next = 0;
387
+ break;
388
+ case "End":
389
+ next = items.length - 1;
390
+ break;
391
+ case "Enter":
392
+ case " ": {
393
+ event.preventDefault();
394
+ // Read rather than asserted: `items` is filtered by what the
395
+ // field accepts, so it can be shorter than the index a previous
396
+ // listing left behind.
397
+ const focused = items[activeIndex];
398
+ if (focused)
399
+ selectItem(focused);
400
+ return;
401
+ }
402
+ default:
403
+ return;
404
+ }
405
+ event.preventDefault();
406
+ focusIndex(next);
407
+ }
408
+ const emptyBecauseFiltered = !loading && rawItems.length > 0 && items.length === 0;
409
+ return (_jsx(Sheet, { open: true, onOpenChange: (next) => {
410
+ if (!next)
411
+ onClose();
412
+ }, children: _jsxs(SheetContent, { onCloseAutoFocus: (event) => {
413
+ // Radix's MODAL Dialog does not restore focus to whatever had it
414
+ // before: it prevents the browser's restore and focuses its own
415
+ // <Dialog.Trigger> instead. This drawer has no Trigger, because
416
+ // the caller mounts it only while it should be open, so leaving
417
+ // Radix to it drops the user on <body> (WCAG 2.4.3). The control
418
+ // that opened the drawer is the right place, and unlike the tile
419
+ // that was just clicked it is still there, so this restores to
420
+ // it explicitly. If it has gone since (a caller that opened this
421
+ // from something that unmounted), there is nothing here to
422
+ // reach, and Radix's own behaviour stands.
423
+ if (opener?.isConnected) {
424
+ event.preventDefault();
425
+ opener.focus();
426
+ }
427
+ }, children: [_jsxs(SheetHeader, { className: "flex-col items-start gap-1", children: [_jsx(SheetTitle, { children: "Choose an image" }), _jsxs(SheetDescription, { children: ["Showing images from your library.", rendition ? (_jsxs(_Fragment, { children: [" ", "This field asks for a ", _jsx("strong", { className: "font-medium text-text-primary", children: requestedShape }), " crop."] })) : null] })] }), _jsx("nav", { "aria-label": "Folder location", className: "shrink-0 border-b border-border-default px-4 py-2", children: _jsxs("ol", { className: "flex flex-wrap items-center gap-1 text-sm text-text-tertiary", children: [_jsx("li", { children: currentFolderId === null ? (_jsx("span", { "aria-current": "page", className: "font-medium text-text-primary", children: ROOT_LABEL })) : (_jsx("button", { type: "button", onClick: () => openFolder(null), className: "rounded-md px-1 hover:text-primary-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600", children: ROOT_LABEL })) }), breadcrumbPath.map((folder, index) => {
428
+ const isCurrent = index === breadcrumbPath.length - 1;
429
+ return (_jsxs("li", { className: "flex min-w-0 items-center gap-1", children: [_jsx(ChevronRight, { "aria-hidden": "true", className: "size-3 shrink-0 rtl:rotate-180" }), isCurrent ? (_jsx("span", { "aria-current": "page", className: "truncate font-medium text-text-primary", children: folder.name })) : (_jsx("button", { type: "button", onClick: () => openFolder(folder.id), className: "truncate rounded-md px-1 hover:text-primary-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600", children: folder.name }))] }, folder.id));
430
+ })] }) }), _jsxs("div", { className: "flex flex-1 flex-col gap-4 overflow-y-auto p-4", children: [error && _jsx("p", { className: "text-sm text-danger-600", children: error }), visibleFolders.length > 0 && (_jsx("ul", { "aria-label": "Folders", className: "flex flex-wrap gap-2", children: visibleFolders.map((folder) => (_jsx("li", { className: "min-w-0", children: _jsxs("button", { type: "button", onClick: () => openFolder(folder.id), className: "flex max-w-full items-center gap-2 rounded-full border border-border-default bg-background-elevated px-3 py-1 text-xs text-text-secondary hover:bg-background-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600", children: [_jsx(FolderIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-text-tertiary" }), _jsx("span", { className: "truncate", children: folder.name })] }) }, folder.id))) })), loading && _jsx("p", { className: "text-sm text-text-secondary", children: "Loading\u2026" }), emptyBecauseFiltered && (_jsx("p", { className: "text-sm text-text-secondary", children: "Nothing here is a kind this field accepts." })), !loading && rawItems.length === 0 && visibleFolders.length === 0 && (_jsx("p", { className: "text-sm text-text-secondary", children: currentFolderId === null ? "No images in the media library yet." : "No images in this folder yet." })), !loading && items.length > 0 && (_jsx("div", { role: "listbox", "aria-label": "Media library", onKeyDown: handleGridKeyDown, className: "grid grid-cols-3 gap-3", children: items.map((item, index) => {
431
+ const selected = pending?.id === item.id;
432
+ // `hasRendition` is only set when the listing was asked
433
+ // about a crop, so absent means nothing was asked and
434
+ // there is nothing to mark.
435
+ const fallsBack = Boolean(rendition) && item.hasRendition === false;
436
+ const title = !fallsBack
437
+ ? item.filename
438
+ : isRenditionIneligible(item.mimeType)
439
+ ? `${item.filename}: this format is never cut, so this field shows the full image.`
440
+ : `${item.filename}: no ${requestedShape} crop yet, so this field shows the full image.`;
441
+ return (_jsxs("button", { type: "button", ref: (el) => {
442
+ optionRefs.current[index] = el;
443
+ }, role: "option", "aria-selected": selected, title: title, tabIndex: index === activeIndex ? 0 : -1, onFocus: () => setActiveIndex(index), onClick: () => selectItem(item), className: cn("flex flex-col overflow-hidden rounded-md border text-start focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600", selected
444
+ ? "border-primary-600 bg-primary-100"
445
+ : "border-border-subtle hover:bg-background-elevated"), children: [_jsx("span", { className: "block aspect-square overflow-hidden bg-background-subtle", children: _jsx("img", { src: item.downloadUrl, alt: "", className: "h-full w-full object-cover" }) }), _jsxs("span", { className: "block min-w-0 px-2 py-1", children: [_jsx("span", { className: "block truncate font-mono text-xs text-text-tertiary", children: item.filename }), fallsBack && (_jsx("span", { className: "mt-1 inline-block rounded-sm bg-warning-100 px-1 text-xs text-warning-800", children: "full image" }))] })] }, item.id));
446
+ }) })), !loading && nextCursor && (_jsx("div", { className: "flex justify-center", children: _jsx(Button, { type: "button", variant: "outline", size: "sm", disabled: loadingMore, onClick: () => void loadMore(), children: loadingMore ? "Loading…" : "Load more" }) }))] }), pending && (_jsxs("div", { className: "flex shrink-0 items-center gap-3 border-t border-border-default px-4 py-3", children: [_jsx("img", { src: pending.downloadUrl, alt: "", className: "h-12 w-12 shrink-0 rounded-md border border-border-subtle object-cover" }), _jsxs("div", { className: "flex-1", children: [_jsx("label", { htmlFor: "media-picker-alt", className: "mb-1 block text-xs font-medium text-text-secondary", children: "Alt text" }), _jsx("input", { id: "media-picker-alt", ref: altInputRef, type: "text", value: altText, onChange: (event) => setAltText(event.target.value), placeholder: "Describe this image for screen readers (optional)", className: "w-full rounded-md border border-border-default bg-background-elevated px-2 py-1 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600" })] })] })), _jsxs(SheetFooter, { className: "items-center justify-start", children: [_jsxs("p", { className: "text-sm text-text-tertiary", children: ["Or", " ", _jsx("button", { type: "button", disabled: uploading, onClick: () => uploadInputRef.current?.click(), className: "rounded-md text-primary-600 underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600", children: uploading ? `uploading into ${currentFolderName}…` : `upload into ${currentFolderName}` })] }), _jsx("input", { id: "media-picker-upload", ref: uploadInputRef, type: "file", className: "hidden", accept: acceptAttribute(acceptedTypes), "aria-label": `Upload into ${currentFolderName}`, disabled: uploading, onChange: (event) => void handleUpload(event) }), _jsx("span", { className: "ms-auto flex gap-2", children: pending ? (_jsxs(_Fragment, { children: [_jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "button", onClick: () => onPick({ id: pending.id, downloadUrl: pending.downloadUrl, alt: altText }), children: "Insert" })] })) : (_jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Close" })) })] })] }) }));
447
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The sentence a failed `POST /api/manage/v1/media` should show. The server's own
3
+ * message when there is one (every refusal on that route answers with
4
+ * `ApiErrorSchema`, which is `{ message }`), and the status otherwise:
5
+ * a failure with nothing to say still has to say something, and the
6
+ * status is then the only thing there is.
7
+ *
8
+ * Never throws. A body that is not JSON at all, which is what a proxy's
9
+ * own error page or a dropped connection looks like from here, is a
10
+ * missing message rather than a second failure on top of the first.
11
+ */
12
+ export declare function uploadFailureMessage(response: Response): Promise<string>;
@@ -0,0 +1,30 @@
1
+ // S234d Task 8: what a failed upload says to the person who started it.
2
+ //
3
+ // Both of this package's upload affordances, an image field's own Upload
4
+ // button and the picker drawer's, used to throw `Upload failed (413)` and
5
+ // drop whatever the server had said. That became a real loss the moment
6
+ // the server started refusing files by SIZE: the refusal names the limit
7
+ // and the actual size precisely so a person knows by how much they are
8
+ // over, and a bare status code answers neither question.
9
+ //
10
+ // Shared rather than written twice, because the two affordances sit on the
11
+ // same field (the drawer is opened by Choose, a few lines from Upload) and
12
+ // a person meeting two different sentences for one refusal would have no
13
+ // way to tell they are the same rule.
14
+ /**
15
+ * The sentence a failed `POST /api/manage/v1/media` should show. The server's own
16
+ * message when there is one (every refusal on that route answers with
17
+ * `ApiErrorSchema`, which is `{ message }`), and the status otherwise:
18
+ * a failure with nothing to say still has to say something, and the
19
+ * status is then the only thing there is.
20
+ *
21
+ * Never throws. A body that is not JSON at all, which is what a proxy's
22
+ * own error page or a dropped connection looks like from here, is a
23
+ * missing message rather than a second failure on top of the first.
24
+ */
25
+ export async function uploadFailureMessage(response) {
26
+ const body = (await response.json().catch(() => null));
27
+ if (body && typeof body.message === "string" && body.message.length > 0)
28
+ return body.message;
29
+ return `Upload failed (${response.status})`;
30
+ }