@kardalum/plugin-sdk 0.0.0-stage → 0.15.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 (312) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/LICENSE +202 -0
  3. package/README.md +70 -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 +99 -0
  15. package/dist/capabilities.js +363 -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 +93 -0
  40. package/dist/license-verdict-keys.d.ts +18 -0
  41. package/dist/license-verdict-keys.js +22 -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 +408 -0
  47. package/dist/manifest-schema.js +774 -0
  48. package/dist/manifest.d.ts +546 -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 +438 -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 +75 -0
  55. package/dist/plugin-context.js +70 -0
  56. package/dist/plugin-screen-context.d.ts +40 -0
  57. package/dist/plugin-screen-context.js +16 -0
  58. package/dist/register-built-ins.d.ts +1 -0
  59. package/dist/register-built-ins.js +41 -0
  60. package/dist/registry.d.ts +4 -0
  61. package/dist/registry.js +17 -0
  62. package/dist/rendition-eligibility.d.ts +24 -0
  63. package/dist/rendition-eligibility.js +40 -0
  64. package/dist/richtext/block-panel.d.ts +27 -0
  65. package/dist/richtext/block-panel.js +232 -0
  66. package/dist/richtext/extensions.d.ts +19 -0
  67. package/dist/richtext/extensions.js +56 -0
  68. package/dist/richtext/insert-menu.d.ts +24 -0
  69. package/dist/richtext/insert-menu.js +142 -0
  70. package/dist/richtext/kardalum-block.d.ts +33 -0
  71. package/dist/richtext/kardalum-block.js +282 -0
  72. package/dist/richtext/style-listbox.d.ts +10 -0
  73. package/dist/richtext/style-listbox.js +69 -0
  74. package/dist/richtext/text-style-class.d.ts +18 -0
  75. package/dist/richtext/text-style-class.js +36 -0
  76. package/dist/simple-storage-value-provider.d.ts +9 -0
  77. package/dist/simple-storage-value-provider.js +96 -0
  78. package/dist/structured-storage-types.d.ts +61 -0
  79. package/dist/structured-storage-types.js +11 -0
  80. package/dist/tailwind.d.ts +1 -0
  81. package/dist/tailwind.js +5 -0
  82. package/dist/tokens/system-dark.css +75 -0
  83. package/dist/tokens/tokens.css +239 -0
  84. package/dist/tokens/tokens.json +212 -0
  85. package/dist/tokens.d.ts +1 -0
  86. package/dist/tokens.js +11 -0
  87. package/dist/ui-entry.d.ts +5 -0
  88. package/dist/ui-entry.js +42 -0
  89. package/dist/views/content-list-preview.d.ts +1 -0
  90. package/dist/views/content-list-preview.js +14 -0
  91. package/dist/views/content-list-settings-view.d.ts +1 -0
  92. package/dist/views/content-list-settings-view.js +97 -0
  93. package/dist/views/content-list-view.d.ts +19 -0
  94. package/dist/views/content-list-view.js +248 -0
  95. package/dist/views/crop-view.d.ts +55 -0
  96. package/dist/views/crop-view.js +161 -0
  97. package/dist/views/date-range-view.d.ts +6 -0
  98. package/dist/views/date-range-view.js +55 -0
  99. package/dist/views/file-upload-view.d.ts +43 -0
  100. package/dist/views/file-upload-view.js +104 -0
  101. package/dist/views/html-code-editor.d.ts +10 -0
  102. package/dist/views/html-code-editor.js +101 -0
  103. package/dist/views/html-view.d.ts +3 -0
  104. package/dist/views/html-view.js +53 -0
  105. package/dist/views/image-view.d.ts +3 -0
  106. package/dist/views/image-view.js +387 -0
  107. package/dist/views/rich-text-view.d.ts +2 -0
  108. package/dist/views/rich-text-view.js +429 -0
  109. package/node_modules/@kardalum/api-schemas/LICENSE +202 -0
  110. package/node_modules/@kardalum/api-schemas/README.md +56 -0
  111. package/node_modules/@kardalum/api-schemas/dist/action.schema.d.ts +30 -0
  112. package/node_modules/@kardalum/api-schemas/dist/action.schema.js +88 -0
  113. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +5 -0
  114. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +6 -0
  115. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +75 -0
  116. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +36 -0
  117. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +89 -0
  118. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +60 -0
  119. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +24 -0
  120. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +47 -0
  121. package/node_modules/@kardalum/api-schemas/dist/auth.schema.d.ts +38 -0
  122. package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +38 -0
  123. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +537 -0
  124. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +353 -0
  125. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +158 -0
  126. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +139 -0
  127. package/node_modules/@kardalum/api-schemas/dist/content-path.d.ts +125 -0
  128. package/node_modules/@kardalum/api-schemas/dist/content-path.js +256 -0
  129. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +20 -0
  130. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +23 -0
  131. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +151 -0
  132. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +82 -0
  133. package/node_modules/@kardalum/api-schemas/dist/content-version.schema.d.ts +18 -0
  134. package/node_modules/@kardalum/api-schemas/dist/content-version.schema.js +22 -0
  135. package/node_modules/@kardalum/api-schemas/dist/content.schema.d.ts +17 -0
  136. package/node_modules/@kardalum/api-schemas/dist/content.schema.js +20 -0
  137. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +302 -0
  138. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +97 -0
  139. package/node_modules/@kardalum/api-schemas/dist/culture-direction.d.ts +1 -0
  140. package/node_modules/@kardalum/api-schemas/dist/culture-direction.js +9 -0
  141. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +36 -0
  142. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +32 -0
  143. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +9 -0
  144. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +32 -0
  145. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +296 -0
  146. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +138 -0
  147. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.d.ts +121 -0
  148. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +147 -0
  149. package/node_modules/@kardalum/api-schemas/dist/health.schema.d.ts +6 -0
  150. package/node_modules/@kardalum/api-schemas/dist/health.schema.js +5 -0
  151. package/node_modules/@kardalum/api-schemas/dist/html-entities.d.ts +4 -0
  152. package/node_modules/@kardalum/api-schemas/dist/html-entities.js +250 -0
  153. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +102 -0
  154. package/node_modules/@kardalum/api-schemas/dist/index.js +58 -0
  155. package/node_modules/@kardalum/api-schemas/dist/licensing.schema.d.ts +15 -0
  156. package/node_modules/@kardalum/api-schemas/dist/licensing.schema.js +14 -0
  157. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +381 -0
  158. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +197 -0
  159. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +167 -0
  160. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +214 -0
  161. package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.d.ts +77 -0
  162. package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.js +53 -0
  163. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +75 -0
  164. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +117 -0
  165. package/node_modules/@kardalum/api-schemas/dist/media-reference.d.ts +27 -0
  166. package/node_modules/@kardalum/api-schemas/dist/media-reference.js +279 -0
  167. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.d.ts +74 -0
  168. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +157 -0
  169. package/node_modules/@kardalum/api-schemas/dist/media.schema.d.ts +80 -0
  170. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +156 -0
  171. package/node_modules/@kardalum/api-schemas/dist/nav.schema.d.ts +23 -0
  172. package/node_modules/@kardalum/api-schemas/dist/nav.schema.js +55 -0
  173. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.d.ts +846 -0
  174. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +356 -0
  175. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +20 -0
  176. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +27 -0
  177. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +169 -0
  178. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +80 -0
  179. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.d.ts +65 -0
  180. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +889 -0
  181. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +89 -0
  182. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +134 -0
  183. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +31 -0
  184. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +38 -0
  185. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +369 -0
  186. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +393 -0
  187. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +22 -0
  188. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +87 -0
  189. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +31 -0
  190. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +25 -0
  191. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.d.ts +15 -0
  192. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +24 -0
  193. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +306 -0
  194. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +328 -0
  195. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +79 -0
  196. package/node_modules/@kardalum/api-schemas/dist/render-editing.js +50 -0
  197. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.d.ts +9 -0
  198. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +13 -0
  199. package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.d.ts +2 -0
  200. package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.js +16 -0
  201. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +90 -0
  202. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +69 -0
  203. package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.d.ts +17 -0
  204. package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.js +27 -0
  205. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +108 -0
  206. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +93 -0
  207. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +243 -0
  208. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +296 -0
  209. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +43 -0
  210. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +25 -0
  211. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +30 -0
  212. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +19 -0
  213. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +112 -0
  214. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +74 -0
  215. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +41 -0
  216. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +39 -0
  217. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +21 -0
  218. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +14 -0
  219. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +89 -0
  220. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +68 -0
  221. package/node_modules/@kardalum/api-schemas/package.json +35 -0
  222. package/node_modules/@kardalum/design-tokens/LICENSE +202 -0
  223. package/node_modules/@kardalum/design-tokens/README.md +29 -0
  224. package/node_modules/@kardalum/design-tokens/dist/build-css.d.ts +32 -0
  225. package/node_modules/@kardalum/design-tokens/dist/build-css.js +88 -0
  226. package/node_modules/@kardalum/design-tokens/dist/generate.d.ts +1 -0
  227. package/node_modules/@kardalum/design-tokens/dist/generate.js +18 -0
  228. package/node_modules/@kardalum/design-tokens/dist/index.d.ts +6 -0
  229. package/node_modules/@kardalum/design-tokens/dist/index.js +4 -0
  230. package/node_modules/@kardalum/design-tokens/dist/system-dark.css +75 -0
  231. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +33 -0
  232. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +54 -0
  233. package/node_modules/@kardalum/design-tokens/dist/theme-css.d.ts +12 -0
  234. package/node_modules/@kardalum/design-tokens/dist/theme-css.js +42 -0
  235. package/node_modules/@kardalum/design-tokens/dist/theme-types.d.ts +43 -0
  236. package/node_modules/@kardalum/design-tokens/dist/theme-types.js +1 -0
  237. package/node_modules/@kardalum/design-tokens/dist/themes/dark.d.ts +13 -0
  238. package/node_modules/@kardalum/design-tokens/dist/themes/dark.js +120 -0
  239. package/node_modules/@kardalum/design-tokens/dist/themes/index.d.ts +5 -0
  240. package/node_modules/@kardalum/design-tokens/dist/themes/index.js +4 -0
  241. package/node_modules/@kardalum/design-tokens/dist/themes/light.d.ts +9 -0
  242. package/node_modules/@kardalum/design-tokens/dist/themes/light.js +13 -0
  243. package/node_modules/@kardalum/design-tokens/dist/tokens.css +239 -0
  244. package/node_modules/@kardalum/design-tokens/dist/tokens.d.ts +25 -0
  245. package/node_modules/@kardalum/design-tokens/dist/tokens.js +276 -0
  246. package/node_modules/@kardalum/design-tokens/dist/tokens.json +212 -0
  247. package/node_modules/@kardalum/design-tokens/dist/types.d.ts +91 -0
  248. package/node_modules/@kardalum/design-tokens/dist/types.js +5 -0
  249. package/node_modules/@kardalum/design-tokens/package.json +42 -0
  250. package/node_modules/@kardalum/plugin-package/LICENSE +202 -0
  251. package/node_modules/@kardalum/plugin-package/README.md +71 -0
  252. package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +50 -0
  253. package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +659 -0
  254. package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +19 -0
  255. package/node_modules/@kardalum/plugin-package/dist/envelope.js +104 -0
  256. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +37 -0
  257. package/node_modules/@kardalum/plugin-package/dist/extract.js +199 -0
  258. package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +17 -0
  259. package/node_modules/@kardalum/plugin-package/dist/hash.js +69 -0
  260. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +11 -0
  261. package/node_modules/@kardalum/plugin-package/dist/index.js +7 -0
  262. package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +185 -0
  263. package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +236 -0
  264. package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +50 -0
  265. package/node_modules/@kardalum/plugin-package/dist/package-contract.js +115 -0
  266. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +1 -0
  267. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +17 -0
  268. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +45 -0
  269. package/node_modules/@kardalum/plugin-package/dist/types.js +1 -0
  270. package/node_modules/@kardalum/plugin-package/package.json +49 -0
  271. package/node_modules/@kardalum/ui/LICENSE +202 -0
  272. package/node_modules/@kardalum/ui/README.md +35 -0
  273. package/node_modules/@kardalum/ui/dist/components/alert-dialog.d.ts +14 -0
  274. package/node_modules/@kardalum/ui/dist/components/alert-dialog.js +38 -0
  275. package/node_modules/@kardalum/ui/dist/components/badge.d.ts +9 -0
  276. package/node_modules/@kardalum/ui/dist/components/badge.js +30 -0
  277. package/node_modules/@kardalum/ui/dist/components/button.d.ts +11 -0
  278. package/node_modules/@kardalum/ui/dist/components/button.js +37 -0
  279. package/node_modules/@kardalum/ui/dist/components/checkbox.d.ts +5 -0
  280. package/node_modules/@kardalum/ui/dist/components/checkbox.js +7 -0
  281. package/node_modules/@kardalum/ui/dist/components/dialog.d.ts +17 -0
  282. package/node_modules/@kardalum/ui/dist/components/dialog.js +48 -0
  283. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.d.ts +18 -0
  284. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +53 -0
  285. package/node_modules/@kardalum/ui/dist/components/empty-state.d.ts +30 -0
  286. package/node_modules/@kardalum/ui/dist/components/empty-state.js +9 -0
  287. package/node_modules/@kardalum/ui/dist/components/input.d.ts +4 -0
  288. package/node_modules/@kardalum/ui/dist/components/input.js +6 -0
  289. package/node_modules/@kardalum/ui/dist/components/panel.d.ts +5 -0
  290. package/node_modules/@kardalum/ui/dist/components/panel.js +6 -0
  291. package/node_modules/@kardalum/ui/dist/components/property-field.d.ts +19 -0
  292. package/node_modules/@kardalum/ui/dist/components/property-field.js +86 -0
  293. package/node_modules/@kardalum/ui/dist/components/sheet.d.ts +17 -0
  294. package/node_modules/@kardalum/ui/dist/components/sheet.js +55 -0
  295. package/node_modules/@kardalum/ui/dist/components/skeleton.d.ts +3 -0
  296. package/node_modules/@kardalum/ui/dist/components/skeleton.js +9 -0
  297. package/node_modules/@kardalum/ui/dist/components/switch.d.ts +5 -0
  298. package/node_modules/@kardalum/ui/dist/components/switch.js +7 -0
  299. package/node_modules/@kardalum/ui/dist/components/tab-strip.d.ts +34 -0
  300. package/node_modules/@kardalum/ui/dist/components/tab-strip.js +72 -0
  301. package/node_modules/@kardalum/ui/dist/components/toast.d.ts +18 -0
  302. package/node_modules/@kardalum/ui/dist/components/toast.js +42 -0
  303. package/node_modules/@kardalum/ui/dist/components/toaster.d.ts +12 -0
  304. package/node_modules/@kardalum/ui/dist/components/toaster.js +11 -0
  305. package/node_modules/@kardalum/ui/dist/components/use-toast.d.ts +17 -0
  306. package/node_modules/@kardalum/ui/dist/components/use-toast.js +62 -0
  307. package/node_modules/@kardalum/ui/dist/index.d.ts +18 -0
  308. package/node_modules/@kardalum/ui/dist/index.js +18 -0
  309. package/node_modules/@kardalum/ui/dist/lib/cn.d.ts +2 -0
  310. package/node_modules/@kardalum/ui/dist/lib/cn.js +5 -0
  311. package/node_modules/@kardalum/ui/package.json +63 -0
  312. package/package.json +146 -4
@@ -0,0 +1,438 @@
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 { usePluginApi } from "../plugin-context.js";
7
+ import { isRenditionIneligible } from "../rendition-eligibility.js";
8
+ import { uploadFailureMessage } from "./upload-error.js";
9
+ // GET /api/media page size for the picker's grid (S197 Task 2). Additional
10
+ // pages are fetched on demand via the "Load more" button below, following
11
+ // MediaListQuerySchema's cursor contract (media-api.schema.ts) rather than
12
+ // assuming a library's whole image set fits on one page.
13
+ const PAGE_LIMIT = 50;
14
+ // What the picker offers when the caller names nothing. Rich text has no
15
+ // accepted-types setting of its own and has always shown images only, so
16
+ // this is that behaviour written down rather than a new default.
17
+ const DEFAULT_ACCEPTED_TYPES = ["image/*"];
18
+ // The word the breadcrumb already uses for the library root, reused by the
19
+ // upload affordance so both name the same place the same way.
20
+ const ROOT_LABEL = "Root";
21
+ // --- Type filtering (S234d Task 6) ----------------------------------------
22
+ // The spec's sentence is that the picker offers items whose media type's
23
+ // file upload accepts the field's accepted types. An item's STORED media
24
+ // type is the outcome of exactly that upload, and it is already on the
25
+ // row, so the question is answered per item from the listing the picker
26
+ // already has rather than by loading every media document type and its
27
+ // file upload's settings first. It is also the tighter of the two
28
+ // readings: a media type that accepts both jpg and pdf cannot slip a PDF
29
+ // into an image field this way, which is the example the spec gives.
30
+ /** A stored media type reduced to its base form. It is whatever the
31
+ * uploading client sent, so `IMAGE/PNG` and `image/png; charset=binary`
32
+ * both have to answer as `image/png`. */
33
+ function baseMimeType(mimeType) {
34
+ const semicolon = mimeType.indexOf(";");
35
+ return (semicolon === -1 ? mimeType : mimeType.slice(0, semicolon)).trim().toLowerCase();
36
+ }
37
+ /** The extension a filename carries, without the dot, lowercased. Empty
38
+ * for a name with no extension (a leading dot is not one: `.gitignore` is
39
+ * a whole name). */
40
+ function fileExtension(filename) {
41
+ const dot = filename.lastIndexOf(".");
42
+ return dot <= 0 ? "" : filename.slice(dot + 1).trim().toLowerCase();
43
+ }
44
+ /** One accept token against one item, in the vocabulary of the HTML
45
+ * accept attribute, which is the vocabulary an image field's
46
+ * `acceptedTypes` is written in (image-view.tsx feeds it straight to an
47
+ * `accept`) and a superset of the bare extensions a file upload's
48
+ * settings store ("jpg"). */
49
+ function matchesAcceptToken(item, token) {
50
+ const wanted = token.trim().toLowerCase();
51
+ if (wanted === "")
52
+ return false;
53
+ if (wanted === "*" || wanted === "*/*")
54
+ return true;
55
+ if (wanted.includes("/")) {
56
+ const mimeType = baseMimeType(item.mimeType);
57
+ // "image/*" matches on the "image/" prefix; anything else is exact.
58
+ if (wanted.endsWith("/*"))
59
+ return mimeType.startsWith(wanted.slice(0, -1));
60
+ return mimeType === wanted;
61
+ }
62
+ const extension = fileExtension(item.filename);
63
+ return extension !== "" && extension === (wanted.startsWith(".") ? wanted.slice(1) : wanted);
64
+ }
65
+ function fieldAccepts(item, acceptedTypes) {
66
+ const tokens = acceptedTypes && acceptedTypes.length > 0 ? acceptedTypes : DEFAULT_ACCEPTED_TYPES;
67
+ return tokens.some((token) => matchesAcceptToken(item, token));
68
+ }
69
+ /** The same tokens as an `accept` attribute value, so the OS file dialog
70
+ * offers what this picker would have offered. A bare extension gains the
71
+ * dot the attribute wants. */
72
+ function acceptAttribute(acceptedTypes) {
73
+ const tokens = acceptedTypes && acceptedTypes.length > 0 ? acceptedTypes : DEFAULT_ACCEPTED_TYPES;
74
+ return tokens
75
+ .map((token) => token.trim())
76
+ .filter((token) => token !== "")
77
+ .map((token) => (token.includes("/") || token.startsWith(".") ? token : `.${token}`))
78
+ .join(",");
79
+ }
80
+ function groupFoldersByParent(folders) {
81
+ const map = new Map();
82
+ for (const folder of folders) {
83
+ const key = folder.parentId ?? "root";
84
+ const bucket = map.get(key);
85
+ if (bucket)
86
+ bucket.push(folder);
87
+ else
88
+ map.set(key, [folder]);
89
+ }
90
+ for (const bucket of map.values())
91
+ bucket.sort((a, b) => a.name.localeCompare(b.name));
92
+ return map;
93
+ }
94
+ function childFoldersOf(byParent, parentId) {
95
+ return byParent.get(parentId ?? "root") ?? [];
96
+ }
97
+ // The ancestor chain from the library root down to (and including)
98
+ // `folderId`, which is the breadcrumb's data. Stops rather than looping
99
+ // if it ever revisits a folder (a malformed cycle in the data can't hang
100
+ // this).
101
+ function folderPath(folderId, byId) {
102
+ const path = [];
103
+ const visited = new Set();
104
+ let current = folderId ? (byId.get(folderId) ?? null) : null;
105
+ while (current && !visited.has(current.id)) {
106
+ visited.add(current.id);
107
+ path.unshift(current);
108
+ current = current.parentId ? (byId.get(current.parentId) ?? null) : null;
109
+ }
110
+ return path;
111
+ }
112
+ // The one media picker, serving two callers (S234d Task 6, approved mockup
113
+ // screen 4): rich text's "Image" toolbar command, and a page's image
114
+ // field. It lived under richtext/ until this session, when the second
115
+ // caller arrived; nothing about the drawer is specific to either.
116
+ //
117
+ // A right-side drawer over the media library. Folders of the currently
118
+ // open location (Root to start) drill in one level at a time via a
119
+ // breadcrumb, then a grid of that folder's items to pick from, plus an
120
+ // upload control at the bottom naming the folder it would upload into.
121
+ // Always rendered open; the caller mounts this component only while the
122
+ // picker should be showing and supplies onClose for every way Radix's
123
+ // Dialog can close itself (Escape, overlay click, Close), the same
124
+ // controlled-open pattern as IconPickerDialog
125
+ // (apps/admin-ui/src/icons/icon-picker-dialog.tsx).
126
+ //
127
+ // downloadUrl is resolved fresh from each GET /api/media response, never
128
+ // cached across renders: a private item's URL carries a short-lived
129
+ // token, so a stale one would go dead (image-view.tsx's useMediaPreview
130
+ // :21-24 doctrine, mirrored here for the same reason).
131
+ //
132
+ // WHAT A PICK DOES depends on `collectAlt`. With it true (rich text),
133
+ // selection is two-step, the same "arm then confirm" shape as
134
+ // IconPickerDialog: clicking (or Enter-ing) a grid item arms it as
135
+ // `pending` (highlighted via aria-selected, nothing inserted yet), and an
136
+ // Alt text input appears with Insert/Cancel. Only Insert calls onPick,
137
+ // carrying whatever alt text was typed, empty allowed, because a
138
+ // decorative image is a legitimate choice. A fresh upload flows into the
139
+ // same confirm step, so alt text is always authored before an image lands
140
+ // in the document, never defaulted to a filename. With it false (an image
141
+ // field), there is nothing to confirm: the field stores one media id and
142
+ // has nowhere to put alt text, so a pick commits and the drawer closes.
143
+ //
144
+ // WHERE FOCUS GOES when it closes is the same on both paths, and this
145
+ // component decides it rather than leaving it to Radix: back to the
146
+ // control that opened the drawer, which outlives it. See the
147
+ // onCloseAutoFocus handler below for why Radix alone would drop the user
148
+ // on <body>. It matters most on the no-alt path, where the thing that was
149
+ // focused at the moment of closing is the tile, and the tile is about to
150
+ // stop existing. The one focus move made inside the drawer is INTO the
151
+ // alt input when a selection is armed, which is a step that keeps the
152
+ // drawer open.
153
+ //
154
+ // Cancel discards the pending selection AND closes the whole picker,
155
+ // matching IconPickerDialog's Cancel. Drilling into a different folder
156
+ // before confirming also discards a pending selection: the user's
157
+ // attention has moved on.
158
+ export function MediaPicker({ onPick, onClose, collectAlt, acceptedTypes, rendition }) {
159
+ const fetchApi = usePluginApi();
160
+ const [folders, setFolders] = useState([]);
161
+ const [currentFolderId, setCurrentFolderId] = useState(null);
162
+ // As the server sent them. The accepted-types filter is applied on the
163
+ // way to the grid rather than here, so the empty state can tell "this
164
+ // folder is empty" apart from "this folder holds nothing this field
165
+ // accepts", which are different problems with different fixes.
166
+ const [rawItems, setRawItems] = useState([]);
167
+ const [nextCursor, setNextCursor] = useState(null);
168
+ const [loading, setLoading] = useState(true);
169
+ const [loadingMore, setLoadingMore] = useState(false);
170
+ const [error, setError] = useState(null);
171
+ const [uploading, setUploading] = useState(false);
172
+ const [activeIndex, setActiveIndex] = useState(0);
173
+ const [pending, setPending] = useState(null);
174
+ const [altText, setAltText] = useState("");
175
+ // Whatever was focused when this drawer mounted, captured during the
176
+ // FIRST RENDER: by the time an effect could run, the drawer has already
177
+ // moved focus into itself. See onCloseAutoFocus below for what it is
178
+ // for. A state initializer rather than a ref so it is read once.
179
+ const [opener] = useState(() => typeof document === "undefined" ? null : document.activeElement);
180
+ // The shape the requested name encodes, which is what the sentences
181
+ // below show a person: "3x4" is a filename suffix, "3:4" is a ratio,
182
+ // and the two are the same fact (S234d Task 7b). The NAME is still what
183
+ // goes to the server on every listing request. Empty only when nothing
184
+ // was asked for, and every use of it below sits behind that check.
185
+ const requestedShape = rendition === undefined ? "" : renditionShape(rendition);
186
+ const optionRefs = useRef([]);
187
+ const altInputRef = useRef(null);
188
+ const uploadInputRef = useRef(null);
189
+ const items = useMemo(() => rawItems.filter((item) => fieldAccepts(item, acceptedTypes)), [rawItems, acceptedTypes]);
190
+ const foldersById = useMemo(() => new Map(folders.map((folder) => [folder.id, folder])), [folders]);
191
+ const foldersByParent = useMemo(() => groupFoldersByParent(folders), [folders]);
192
+ const visibleFolders = useMemo(() => childFoldersOf(foldersByParent, currentFolderId), [foldersByParent, currentFolderId]);
193
+ const breadcrumbPath = useMemo(() => folderPath(currentFolderId, foldersById), [currentFolderId, foldersById]);
194
+ const currentFolderName = breadcrumbPath.at(-1)?.name ?? ROOT_LABEL;
195
+ // The whole folder tree loads once. A failed folder fetch surfaces
196
+ // through the SAME error banner the image list uses (review fix:
197
+ // silently-empty folders are indistinguishable from "no subfolders
198
+ // exist", against this picker's own verbatim-error convention). One
199
+ // banner, whichever fetch failed most recently.
200
+ useEffect(() => {
201
+ let cancelled = false;
202
+ fetchApi("/api/media/folders")
203
+ .then(async (response) => {
204
+ if (!response.ok)
205
+ throw new Error(`Failed to load media folders (${response.status})`);
206
+ const body = (await response.json());
207
+ if (!cancelled)
208
+ setFolders(body.folders);
209
+ })
210
+ .catch((err) => {
211
+ if (!cancelled)
212
+ setError(err instanceof Error ? err.message : String(err));
213
+ });
214
+ return () => {
215
+ cancelled = true;
216
+ };
217
+ }, [fetchApi]);
218
+ // `rendition` rides along as a query parameter, once per page, and the
219
+ // server answers it on every item through `hasRendition` (S234d Task 3).
220
+ // It is the whole fallback marking: nothing is asked per tile, and
221
+ // nothing is asked again when a tile is armed.
222
+ const listUrl = useCallback((folderId, cursor) => {
223
+ const params = new URLSearchParams();
224
+ params.set("limit", String(PAGE_LIMIT));
225
+ params.set("folderId", folderId ?? "root");
226
+ if (cursor)
227
+ params.set("cursor", cursor);
228
+ if (rendition)
229
+ params.set("rendition", rendition);
230
+ return `/api/media?${params.toString()}`;
231
+ }, [rendition]);
232
+ // A generation counter, bumped on every call. It guards against a stale
233
+ // response (e.g. two rapid folder switches) overwriting the newer one,
234
+ // regardless of resolution order. Same idiom as media-section.tsx's own
235
+ // loadRequestIdRef.
236
+ const loadRequestIdRef = useRef(0);
237
+ const loadFirstPage = useCallback((folderId) => {
238
+ const requestId = ++loadRequestIdRef.current;
239
+ setLoading(true);
240
+ setError(null);
241
+ fetchApi(listUrl(folderId, null))
242
+ .then(async (response) => {
243
+ if (!response.ok)
244
+ throw new Error(`Failed to load media (${response.status})`);
245
+ const body = (await response.json());
246
+ if (requestId !== loadRequestIdRef.current)
247
+ return;
248
+ setRawItems(body.items);
249
+ setNextCursor(body.nextCursor);
250
+ })
251
+ .catch((err) => {
252
+ if (requestId !== loadRequestIdRef.current)
253
+ return;
254
+ setError(err instanceof Error ? err.message : String(err));
255
+ })
256
+ .finally(() => {
257
+ if (requestId === loadRequestIdRef.current)
258
+ setLoading(false);
259
+ });
260
+ }, [fetchApi, listUrl]);
261
+ useEffect(() => {
262
+ loadFirstPage(currentFolderId);
263
+ }, [currentFolderId, loadFirstPage]);
264
+ // Focus follows the armed selection into the confirm step (spec: "Enter
265
+ // on a focused option selects; focus moves to the alt input"). It fires
266
+ // for both a grid pick and a completed upload, since both go through
267
+ // setPending. Only ever reached when `collectAlt` is true: nothing is
268
+ // armed otherwise.
269
+ useEffect(() => {
270
+ if (pending)
271
+ altInputRef.current?.focus();
272
+ }, [pending]);
273
+ function openFolder(folderId) {
274
+ setCurrentFolderId(folderId);
275
+ setActiveIndex(0);
276
+ // A different folder is a different confirm scope, so discard whatever
277
+ // was armed rather than let it silently survive the navigation (see
278
+ // this component's own doc comment for the reasoning, same as Cancel).
279
+ setPending(null);
280
+ setAltText("");
281
+ }
282
+ async function loadMore() {
283
+ if (!nextCursor || loadingMore)
284
+ return;
285
+ setLoadingMore(true);
286
+ setError(null);
287
+ try {
288
+ const response = await fetchApi(listUrl(currentFolderId, nextCursor));
289
+ if (!response.ok)
290
+ throw new Error(`Failed to load media (${response.status})`);
291
+ const body = (await response.json());
292
+ setRawItems((current) => [...current, ...body.items]);
293
+ setNextCursor(body.nextCursor);
294
+ }
295
+ catch (err) {
296
+ setError(err instanceof Error ? err.message : String(err));
297
+ }
298
+ finally {
299
+ setLoadingMore(false);
300
+ }
301
+ }
302
+ // The one place a pick is decided. With no alt text to collect there is
303
+ // nothing to confirm, so the item commits and the drawer closes in the
304
+ // same gesture; otherwise it is armed and the confirm step takes over.
305
+ function selectItem(item) {
306
+ if (!collectAlt) {
307
+ onPick({ id: item.id, downloadUrl: item.downloadUrl });
308
+ onClose();
309
+ return;
310
+ }
311
+ setPending(item);
312
+ setAltText("");
313
+ }
314
+ // No Content-Type header: the browser sets the multipart boundary
315
+ // itself. folderId targets the currently open folder; the server
316
+ // requires the folderId form field to be appended BEFORE the file field
317
+ // (@fastify/multipart's request.file() stops reading parts once it finds
318
+ // the file part; see routes/media.ts's extractUploadFolderId doc
319
+ // comment, and media-api.ts's uploadMedia for the admin's own copy of
320
+ // this same rule), so the append order below is load-bearing, not
321
+ // stylistic.
322
+ async function handleUpload(event) {
323
+ const file = event.target.files?.[0];
324
+ event.target.value = ""; // lets the same file be re-selected later
325
+ if (!file)
326
+ return;
327
+ setUploading(true);
328
+ setError(null);
329
+ try {
330
+ const formData = new FormData();
331
+ if (currentFolderId)
332
+ formData.append("folderId", currentFolderId);
333
+ formData.append("file", file);
334
+ const response = await fetchApi("/api/media", { method: "POST", body: formData });
335
+ // The server's own sentence, not a status code (S234d Task 8).
336
+ // This drawer has no size check of its own and cannot usefully have
337
+ // one: the ceiling belongs to the media document type the file will
338
+ // land on, which nothing here knows until the server has resolved
339
+ // it. Relaying what it said is this surface's whole part in that
340
+ // rule.
341
+ if (!response.ok)
342
+ throw new Error(await uploadFailureMessage(response));
343
+ const media = (await response.json());
344
+ // A fresh upload goes through the same door as an existing item: it
345
+ // still needs alt text authored where alt text is collected, and it
346
+ // still commits at once where it is not.
347
+ selectItem(media);
348
+ }
349
+ catch (err) {
350
+ setError(err instanceof Error ? err.message : String(err));
351
+ }
352
+ finally {
353
+ setUploading(false);
354
+ }
355
+ }
356
+ function focusIndex(index) {
357
+ setActiveIndex(index);
358
+ optionRefs.current[index]?.focus();
359
+ }
360
+ // Roving tabindex over the grid (WAI-ARIA listbox pattern, same shape as
361
+ // IconPickerDialog's grid): arrows/Home/End move focus only, Enter/Space
362
+ // picks the focused item (see selectItem).
363
+ function handleGridKeyDown(event) {
364
+ if (items.length === 0)
365
+ return;
366
+ let next = activeIndex;
367
+ switch (event.key) {
368
+ case "ArrowRight":
369
+ case "ArrowDown":
370
+ next = Math.min(activeIndex + 1, items.length - 1);
371
+ break;
372
+ case "ArrowLeft":
373
+ case "ArrowUp":
374
+ next = Math.max(activeIndex - 1, 0);
375
+ break;
376
+ case "Home":
377
+ next = 0;
378
+ break;
379
+ case "End":
380
+ next = items.length - 1;
381
+ break;
382
+ case "Enter":
383
+ case " ": {
384
+ event.preventDefault();
385
+ // Read rather than asserted: `items` is filtered by what the
386
+ // field accepts, so it can be shorter than the index a previous
387
+ // listing left behind.
388
+ const focused = items[activeIndex];
389
+ if (focused)
390
+ selectItem(focused);
391
+ return;
392
+ }
393
+ default:
394
+ return;
395
+ }
396
+ event.preventDefault();
397
+ focusIndex(next);
398
+ }
399
+ const emptyBecauseFiltered = !loading && rawItems.length > 0 && items.length === 0;
400
+ return (_jsx(Sheet, { open: true, onOpenChange: (next) => {
401
+ if (!next)
402
+ onClose();
403
+ }, children: _jsxs(SheetContent, { onCloseAutoFocus: (event) => {
404
+ // Radix's MODAL Dialog does not restore focus to whatever had it
405
+ // before: it prevents the browser's restore and focuses its own
406
+ // <Dialog.Trigger> instead. This drawer has no Trigger, because
407
+ // the caller mounts it only while it should be open, so leaving
408
+ // Radix to it drops the user on <body> (WCAG 2.4.3). The control
409
+ // that opened the drawer is the right place, and unlike the tile
410
+ // that was just clicked it is still there, so this restores to
411
+ // it explicitly. If it has gone since (a caller that opened this
412
+ // from something that unmounted), there is nothing here to
413
+ // reach, and Radix's own behaviour stands.
414
+ if (opener?.isConnected) {
415
+ event.preventDefault();
416
+ opener.focus();
417
+ }
418
+ }, 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) => {
419
+ const isCurrent = index === breadcrumbPath.length - 1;
420
+ 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));
421
+ })] }) }), _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) => {
422
+ const selected = pending?.id === item.id;
423
+ // `hasRendition` is only set when the listing was asked
424
+ // about a crop, so absent means nothing was asked and
425
+ // there is nothing to mark.
426
+ const fallsBack = Boolean(rendition) && item.hasRendition === false;
427
+ const title = !fallsBack
428
+ ? item.filename
429
+ : isRenditionIneligible(item.mimeType)
430
+ ? `${item.filename}: this format is never cut, so this field shows the full image.`
431
+ : `${item.filename}: no ${requestedShape} crop yet, so this field shows the full image.`;
432
+ return (_jsxs("button", { type: "button", ref: (el) => {
433
+ optionRefs.current[index] = el;
434
+ }, 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
435
+ ? "border-primary-600 bg-primary-100"
436
+ : "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));
437
+ }) })), !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" })) })] })] }) }));
438
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The sentence a failed `POST /api/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/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
+ }
@@ -0,0 +1,75 @@
1
+ import { type ReactNode } from "react";
2
+ interface PluginValueProviderProps {
3
+ value: unknown;
4
+ onChange: (value: unknown) => void;
5
+ children: ReactNode;
6
+ }
7
+ export declare function PluginValueProvider({ value, onChange, children }: PluginValueProviderProps): import("react").JSX.Element;
8
+ export declare function usePluginValue<T = unknown>(): {
9
+ value: T;
10
+ onChange: (value: T) => void;
11
+ };
12
+ interface PluginSettingsProviderProps {
13
+ settings: Record<string, unknown>;
14
+ onSettingsChange?: (settings: Record<string, unknown>) => void;
15
+ children: ReactNode;
16
+ }
17
+ export declare function PluginSettingsProvider({ settings, onSettingsChange, children }: PluginSettingsProviderProps): import("react").JSX.Element;
18
+ export declare function usePluginSettings<T extends Record<string, unknown> = Record<string, unknown>>(): T;
19
+ export declare function usePluginSettingsValue<T extends Record<string, unknown> = Record<string, unknown>>(): {
20
+ value: T;
21
+ onChange: (value: T) => void;
22
+ };
23
+ export type PluginFetch = (input: string, init?: RequestInit) => Promise<Response>;
24
+ interface PluginApiProviderProps {
25
+ fetch: PluginFetch;
26
+ children: ReactNode;
27
+ }
28
+ export declare function PluginApiProvider({ fetch, children }: PluginApiProviderProps): import("react").JSX.Element;
29
+ export declare function usePluginApi(): PluginFetch;
30
+ /** A page document type, as far as a view needs to know it (S232). */
31
+ export interface ContentHostDocumentType {
32
+ id: string;
33
+ name: string;
34
+ fields: Array<{
35
+ id: string;
36
+ name: string;
37
+ }>;
38
+ }
39
+ /**
40
+ * The page a view is being rendered on, and the two navigations a view
41
+ * may ask the host to perform (S232). The Content List table is the first
42
+ * consumer: it lists the children of `nodeId` and hands the editor back to
43
+ * the host when a row is opened or a new child is wanted.
44
+ */
45
+ export interface ContentHostPage {
46
+ nodeId: string;
47
+ openContent(id: string): void;
48
+ createChild(parentId: string): void;
49
+ }
50
+ /**
51
+ * What a view learns about where it is being rendered (S232).
52
+ *
53
+ * `page` is the discriminant, and the two branches are the two real
54
+ * situations: there is a page open, in which case its id and both
55
+ * navigations are there together, or there is none at all and the host
56
+ * exists only to carry `documentTypes` (the Data Types editor hosts the
57
+ * Content List SETTINGS view that way, so its column picker can name real
58
+ * fields while no content is open). A view checks `page` once instead of
59
+ * an id and two callbacks separately, and no state can spell "a page with
60
+ * no way to open a row".
61
+ */
62
+ export type ContentHost = {
63
+ page: null;
64
+ documentTypes?: ContentHostDocumentType[];
65
+ } | {
66
+ page: ContentHostPage;
67
+ documentTypes?: ContentHostDocumentType[];
68
+ };
69
+ interface ContentHostProviderProps {
70
+ host: ContentHost;
71
+ children: ReactNode;
72
+ }
73
+ export declare function ContentHostProvider({ host, children }: ContentHostProviderProps): import("react").JSX.Element;
74
+ export declare function useContentHost(): ContentHost | null;
75
+ export {};
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ const PluginValueContext = createContext(null);
4
+ export function PluginValueProvider({ value, onChange, children }) {
5
+ return _jsx(PluginValueContext.Provider, { value: { value, onChange }, children: children });
6
+ }
7
+ // A view calling this outside a host-rendered PluginValueProvider is a
8
+ // real bug (the host forgot to wrap it) — throw loudly, don't hand back
9
+ // a silently-undefined value/no-op onChange.
10
+ export function usePluginValue() {
11
+ const ctx = useContext(PluginValueContext);
12
+ if (!ctx) {
13
+ throw new Error("usePluginValue must be called from a view rendered inside a PluginValueProvider");
14
+ }
15
+ return ctx;
16
+ }
17
+ const PluginSettingsContext = createContext(null);
18
+ export function PluginSettingsProvider({ settings, onSettingsChange, children }) {
19
+ return (_jsx(PluginSettingsContext.Provider, { value: { settings, onSettingsChange }, children: children }));
20
+ }
21
+ // Returns settings directly (not {settings, onChange}) — this is the
22
+ // READ-ONLY path used by input/readOnly/preview views (Session 69). For a
23
+ // settings-EDITING view (the "settings" DataTypePluginViews slot), use
24
+ // usePluginSettingsValue() below instead.
25
+ export function usePluginSettings() {
26
+ const ctx = useContext(PluginSettingsContext);
27
+ if (!ctx) {
28
+ throw new Error("usePluginSettings must be called from a view rendered inside a PluginSettingsProvider");
29
+ }
30
+ return ctx.settings;
31
+ }
32
+ // Mirrors usePluginValue()'s {value, onChange} shape, for settings-EDITING
33
+ // views only (Session 69) — the host (e.g. the Data Types editor) must
34
+ // supply onSettingsChange via PluginSettingsProvider, or this throws:
35
+ // a settings view rendered in a read-only context is a host bug, same
36
+ // "throw loudly" philosophy as usePluginValue().
37
+ export function usePluginSettingsValue() {
38
+ const ctx = useContext(PluginSettingsContext);
39
+ if (!ctx) {
40
+ throw new Error("usePluginSettingsValue must be called from a view rendered inside a PluginSettingsProvider");
41
+ }
42
+ if (!ctx.onSettingsChange) {
43
+ throw new Error("usePluginSettingsValue must be called from a settings view rendered inside a PluginSettingsProvider " +
44
+ "that supplies onSettingsChange (read-only contexts should use usePluginSettings() instead)");
45
+ }
46
+ return { value: ctx.settings, onChange: ctx.onSettingsChange };
47
+ }
48
+ const PluginApiContext = createContext(null);
49
+ export function PluginApiProvider({ fetch, children }) {
50
+ return _jsx(PluginApiContext.Provider, { value: fetch, children: children });
51
+ }
52
+ export function usePluginApi() {
53
+ const ctx = useContext(PluginApiContext);
54
+ if (!ctx) {
55
+ throw new Error("usePluginApi must be called from a view rendered inside a PluginApiProvider");
56
+ }
57
+ return ctx;
58
+ }
59
+ const ContentHostContext = createContext(null);
60
+ export function ContentHostProvider({ host, children }) {
61
+ return _jsx(ContentHostContext.Provider, { value: host, children: children });
62
+ }
63
+ // Returns null instead of throwing, unlike usePluginValue/usePluginApi:
64
+ // a view legitimately renders where there is no page at all (the document
65
+ // type builder's field preview, the Data Types settings screen), and the
66
+ // view is expected to say so rather than crash. "No host" is a real state
67
+ // here, not a host wiring bug.
68
+ export function useContentHost() {
69
+ return useContext(ContentHostContext);
70
+ }