datocms-react-ui 3.1.0-next.6 → 4.0.0-next.7

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 (222) hide show
  1. package/README.md +2 -1
  2. package/dist/DateInput.d.ts +2 -0
  3. package/dist/DateInput.js +2 -0
  4. package/dist/DateTimeInput.d.ts +2 -0
  5. package/dist/DateTimeInput.js +2 -0
  6. package/dist/DateTimeRangeInput.d.ts +2 -0
  7. package/dist/DateTimeRangeInput.js +2 -0
  8. package/dist/FilterBuilder.d.ts +2 -0
  9. package/dist/FilterBuilder.js +2 -0
  10. package/dist/RecordRow.d.ts +2 -0
  11. package/dist/RecordRow.js +2 -0
  12. package/dist/UploadCard.js +2 -2
  13. package/dist/UploadPreview.d.ts +2 -2
  14. package/dist/UploadPreview.js +1 -1
  15. package/dist/UserRow.d.ts +2 -0
  16. package/dist/UserRow.js +2 -0
  17. package/dist/react-ui/src/Canvas.d.ts +7 -1
  18. package/dist/react-ui/src/Canvas.js +26 -4
  19. package/dist/react-ui/src/ctxAnswer.js +21 -0
  20. package/dist/react-ui/src/ctxDateSettings.js +7 -5
  21. package/dist/react-ui/src/ctxRecordPresentation.js +34 -0
  22. package/dist/react-ui/src/ctxUploads.js +23 -0
  23. package/dist/styles.css +592 -11
  24. package/dist/ui-public/icons/index.js +79 -81
  25. package/dist/ui-public/locales/en.js +43 -5
  26. package/dist/ui-public/src/Message.d.ts +3 -4
  27. package/dist/ui-public/src/UiTextKey.d.ts +1 -1
  28. package/dist/ui-public/src/actions/Actions/ActionTooltip.js +1 -1
  29. package/dist/ui-public/src/actions/Actions/registry.d.ts +2 -2
  30. package/dist/ui-public/src/actions/Actions/registry.js +2 -2
  31. package/dist/ui-public/src/actions/Button.d.ts +10 -10
  32. package/dist/ui-public/src/actions/Button.js +1 -1
  33. package/dist/ui-public/src/actions/Dropdown/Menu.d.ts +2 -2
  34. package/dist/ui-public/src/actions/Dropdown/Option.d.ts +7 -7
  35. package/dist/ui-public/src/actions/Dropdown/index.d.ts +1 -1
  36. package/dist/ui-public/src/actions/Dropdown/triggers/ButtonTrigger.d.ts +5 -5
  37. package/dist/ui-public/src/actions/Dropdown/triggers/DropdownTriggerButton.d.ts +2 -2
  38. package/dist/ui-public/src/actions/Dropdown/triggers/IconTrigger.d.ts +6 -6
  39. package/dist/ui-public/src/actions/Dropdown/triggers/IconTrigger.js +1 -1
  40. package/dist/ui-public/src/actions/EditorToolbar/Button.d.ts +1 -1
  41. package/dist/ui-public/src/actions/MultipleSelectionActionBar.d.ts +1 -1
  42. package/dist/ui-public/src/actions/SplitButton/Caret.js +2 -2
  43. package/dist/ui-public/src/actions/SplitButton/Halves.js +1 -1
  44. package/dist/ui-public/src/actions/SplitButton/index.d.ts +3 -3
  45. package/dist/ui-public/src/actions/disabledReason.d.ts +4 -4
  46. package/dist/ui-public/src/content/Avatar.d.ts +3 -3
  47. package/dist/ui-public/src/content/Avatar.js +2 -2
  48. package/dist/ui-public/src/content/CodeSnippet.d.ts +1 -1
  49. package/dist/ui-public/src/content/CopyableValue.d.ts +1 -1
  50. package/dist/ui-public/src/content/EnvironmentPill.d.ts +1 -1
  51. package/dist/ui-public/src/content/EnvironmentPill.js +1 -1
  52. package/dist/ui-public/src/content/IconAvatar.d.ts +1 -1
  53. package/dist/ui-public/src/content/ItemStatus.d.ts +1 -1
  54. package/dist/ui-public/src/content/Pill.d.ts +1 -1
  55. package/dist/ui-public/src/content/SmartDate.d.ts +1 -1
  56. package/dist/ui-public/src/content/UploadPreview/asset.js +200 -0
  57. package/dist/ui-public/src/content/UploadPreview/audio.js +120 -0
  58. package/dist/ui-public/src/content/{UploadPreview.d.ts → UploadPreview/box.d.ts} +10 -10
  59. package/dist/ui-public/src/content/{UploadPreview.js → UploadPreview/box.js} +7 -7
  60. package/dist/ui-public/src/content/{uploadPreviewFit.d.ts → UploadPreview/fit.d.ts} +2 -2
  61. package/dist/ui-public/src/content/{uploadPreviewFit.js → UploadPreview/fit.js} +3 -3
  62. package/dist/ui-public/src/content/UploadPreview/index.d.ts +61 -0
  63. package/dist/ui-public/src/content/UploadPreview/index.js +36 -0
  64. package/dist/ui-public/src/content/UploadPreview/presentation.js +63 -0
  65. package/dist/ui-public/src/content/UploadPreview/thumbhash.js +91 -0
  66. package/dist/ui-public/src/content/UploadPreview/upload.d.ts +104 -0
  67. package/dist/ui-public/src/content/UploadPreview/upload.js +112 -0
  68. package/dist/ui-public/src/content/UsageMeter.d.ts +1 -1
  69. package/dist/ui-public/src/content/ValidityTriangles.d.ts +1 -1
  70. package/dist/ui-public/src/feedback/BlankSlate.d.ts +5 -5
  71. package/dist/ui-public/src/feedback/Callout.d.ts +5 -5
  72. package/dist/ui-public/src/feedback/Callout.js +1 -1
  73. package/dist/ui-public/src/feedback/ProgressBar.d.ts +4 -4
  74. package/dist/ui-public/src/feedback/Spinner.d.ts +6 -6
  75. package/dist/ui-public/src/feedback/Spinner.js +1 -1
  76. package/dist/ui-public/src/form/DateInput.d.ts +13 -0
  77. package/dist/ui-public/src/form/DateInput.js +16 -0
  78. package/dist/ui-public/src/form/DateTimeInput/Base.d.ts +89 -0
  79. package/dist/ui-public/src/form/DateTimeInput/Base.js +330 -0
  80. package/dist/ui-public/src/form/DateTimeInput/CalendarGrid.d.ts +29 -0
  81. package/dist/ui-public/src/form/DateTimeInput/CalendarGrid.js +195 -0
  82. package/dist/ui-public/src/form/DateTimeInput/dateText.js +38 -0
  83. package/dist/ui-public/src/form/DateTimeInput/index.d.ts +10 -0
  84. package/dist/ui-public/src/form/DateTimeInput/index.js +18 -0
  85. package/dist/ui-public/src/form/DateTimeInput/value.js +31 -0
  86. package/dist/ui-public/src/form/DateTimeRangeInput/Panel.js +167 -0
  87. package/dist/ui-public/src/form/DateTimeRangeInput/index.d.ts +123 -0
  88. package/dist/ui-public/src/form/DateTimeRangeInput/index.js +186 -0
  89. package/dist/ui-public/src/form/DateTimeRangeInput/rangeLabel.js +46 -0
  90. package/dist/ui-public/src/form/FieldHint.d.ts +2 -2
  91. package/dist/ui-public/src/form/FieldWrapper.d.ts +9 -9
  92. package/dist/ui-public/src/form/FieldWrapper.js +3 -3
  93. package/dist/ui-public/src/form/FilterBuilder/Editor.js +123 -0
  94. package/dist/ui-public/src/form/FilterBuilder/index.d.ts +9 -0
  95. package/dist/ui-public/src/form/FilterBuilder/index.js +294 -0
  96. package/dist/ui-public/src/form/FilterBuilder/types.d.ts +188 -0
  97. package/dist/ui-public/src/form/FilterBuilder/values.js +86 -0
  98. package/dist/ui-public/src/form/InputGroup.d.ts +2 -2
  99. package/dist/ui-public/src/form/InputGroup.js +1 -1
  100. package/dist/ui-public/src/form/KeyValueList.d.ts +1 -1
  101. package/dist/ui-public/src/form/Label.d.ts +2 -2
  102. package/dist/ui-public/src/form/RadioGroupInput.d.ts +2 -2
  103. package/dist/ui-public/src/form/RadioGroupInput.js +1 -1
  104. package/dist/ui-public/src/form/SelectInput/SelectMenu.d.ts +2 -2
  105. package/dist/ui-public/src/form/SelectInput/index.d.ts +3 -3
  106. package/dist/ui-public/src/form/SwitchInput.d.ts +2 -2
  107. package/dist/ui-public/src/form/SwitchList.d.ts +1 -1
  108. package/dist/ui-public/src/form/SwitchList.js +1 -1
  109. package/dist/ui-public/src/form/TableList.d.ts +2 -2
  110. package/dist/ui-public/src/form/TextareaInput.js +1 -1
  111. package/dist/ui-public/src/form/inputProps.d.ts +6 -6
  112. package/dist/ui-public/src/hooks/useAsyncSelectOptions.d.ts +1 -1
  113. package/dist/ui-public/src/hooks/useSmartRowClick.d.ts +1 -1
  114. package/dist/ui-public/src/hooks/useSmartRowClick.js +1 -1
  115. package/dist/ui-public/src/layout/Page/PageGroup.d.ts +2 -2
  116. package/dist/ui-public/src/layout/Page/PageGroup.js +1 -1
  117. package/dist/ui-public/src/layout/Pane/FormHeader.d.ts +1 -1
  118. package/dist/ui-public/src/layout/Pane/FormHeader.js +1 -1
  119. package/dist/ui-public/src/layout/Pane/ListFilter.d.ts +1 -1
  120. package/dist/ui-public/src/layout/Pane/ListPresets.d.ts +1 -1
  121. package/dist/ui-public/src/layout/Pane/PaneHeader.d.ts +1 -1
  122. package/dist/ui-public/src/layout/Pane/index.d.ts +2 -2
  123. package/dist/ui-public/src/layout/SidebarPanel.d.ts +1 -1
  124. package/dist/ui-public/src/layout/SplitPane/Rail.js +1 -1
  125. package/dist/ui-public/src/layout/SplitPane/index.d.ts +6 -6
  126. package/dist/ui-public/src/layout/Toolbar/AddNewButton.d.ts +2 -2
  127. package/dist/ui-public/src/layout/Toolbar/Help.d.ts +3 -3
  128. package/dist/ui-public/src/layout/Toolbar/Help.js +2 -2
  129. package/dist/ui-public/src/layout/Toolbar/Note.d.ts +1 -1
  130. package/dist/ui-public/src/layout/Toolbar/Note.js +1 -1
  131. package/dist/ui-public/src/layout/Toolbar/Pagination.d.ts +1 -1
  132. package/dist/ui-public/src/layout/Toolbar/Pagination.js +1 -1
  133. package/dist/ui-public/src/layout/Toolbar/PresetsTitle.d.ts +3 -3
  134. package/dist/ui-public/src/layout/Toolbar/PresetsTitle.js +2 -2
  135. package/dist/ui-public/src/layout/Toolbar/PrimaryButton.d.ts +3 -3
  136. package/dist/ui-public/src/layout/Toolbar/Root.d.ts +1 -1
  137. package/dist/ui-public/src/layout/Toolbar/Root.js +4 -1
  138. package/dist/ui-public/src/layout/Toolbar/ToolbarTitleTrigger.js +1 -1
  139. package/dist/ui-public/src/lists/CardList.d.ts +3 -3
  140. package/dist/ui-public/src/lists/EmptySlot.d.ts +1 -1
  141. package/dist/ui-public/src/lists/InfoList/User.d.ts +1 -1
  142. package/dist/ui-public/src/lists/InfoList/Value.d.ts +1 -1
  143. package/dist/ui-public/src/lists/InfoList/Value.js +1 -1
  144. package/dist/ui-public/src/lists/InfoList/index.d.ts +3 -3
  145. package/dist/ui-public/src/lists/InfoList/index.js +1 -1
  146. package/dist/ui-public/src/lists/MediaCard.d.ts +7 -7
  147. package/dist/ui-public/src/lists/RecordRow/Image.d.ts +24 -0
  148. package/dist/ui-public/src/lists/RecordRow/Image.js +22 -0
  149. package/dist/ui-public/src/lists/RecordRow/List.d.ts +26 -0
  150. package/dist/ui-public/src/lists/RecordRow/List.js +30 -0
  151. package/dist/ui-public/src/lists/RecordRow/context.js +31 -0
  152. package/dist/ui-public/src/lists/RecordRow/index.d.ts +94 -0
  153. package/dist/ui-public/src/lists/RecordRow/index.js +122 -0
  154. package/dist/ui-public/src/lists/RecordRow/presentation.js +73 -0
  155. package/dist/ui-public/src/lists/RecordRow/types.d.ts +58 -0
  156. package/dist/ui-public/src/lists/RowList.d.ts +5 -5
  157. package/dist/ui-public/src/lists/SettingsList.d.ts +3 -3
  158. package/dist/ui-public/src/lists/SettingsList.js +2 -2
  159. package/dist/ui-public/src/lists/Table/Row.d.ts +5 -5
  160. package/dist/ui-public/src/lists/Table/Table.d.ts +3 -3
  161. package/dist/ui-public/src/lists/Table/TreeToggle.d.ts +2 -2
  162. package/dist/ui-public/src/lists/Table/TreeToggle.js +1 -1
  163. package/dist/ui-public/src/lists/Table/cells/LinkCell.d.ts +1 -1
  164. package/dist/ui-public/src/lists/TreeRow/Action.d.ts +1 -1
  165. package/dist/ui-public/src/lists/TreeRow/Action.js +1 -1
  166. package/dist/ui-public/src/lists/TreeRow/Link.d.ts +1 -1
  167. package/dist/ui-public/src/lists/TreeRow/Link.js +1 -1
  168. package/dist/ui-public/src/lists/UploadCard.d.ts +66 -3
  169. package/dist/ui-public/src/lists/UploadCard.js +116 -7
  170. package/dist/ui-public/src/lists/UserRow.d.ts +122 -0
  171. package/dist/ui-public/src/lists/UserRow.js +104 -0
  172. package/dist/ui-public/src/lists/dnd/DragHandle.d.ts +2 -2
  173. package/dist/ui-public/src/lists/dnd/SortableList.d.ts +1 -1
  174. package/dist/ui-public/src/lists/dnd/dropTargetClassName.d.ts +1 -1
  175. package/dist/ui-public/src/lists/dnd/tree/SortableTree.d.ts +2 -2
  176. package/dist/ui-public/src/navigation/Chevron.d.ts +4 -4
  177. package/dist/ui-public/src/navigation/Chevron.js +1 -1
  178. package/dist/ui-public/src/navigation/Link.d.ts +5 -5
  179. package/dist/ui-public/src/navigation/Link.js +1 -1
  180. package/dist/ui-public/src/navigation/NavList.d.ts +1 -1
  181. package/dist/ui-public/src/navigation/NavList.js +1 -1
  182. package/dist/ui-public/src/navigation/NavigationProvider.d.ts +1 -1
  183. package/dist/ui-public/src/navigation/SegmentedControl.d.ts +2 -2
  184. package/dist/ui-public/src/navigation/SettingsMenu.d.ts +8 -8
  185. package/dist/ui-public/src/navigation/SettingsMenu.js +1 -1
  186. package/dist/ui-public/src/navigation/SidebarTree/SidebarTreeNode.d.ts +4 -4
  187. package/dist/ui-public/src/overlays/FullscreenModal/TitleContext.d.ts +1 -1
  188. package/dist/ui-public/src/overlays/FullscreenModal/TitleContext.js +1 -1
  189. package/dist/ui-public/src/overlays/NewZIndex.d.ts +1 -1
  190. package/dist/ui-public/src/overlays/NewZIndex.js +1 -1
  191. package/dist/ui-public/src/overlays/Popover.d.ts +1 -1
  192. package/dist/ui-public/src/overlays/PortalWrapper.js +1 -1
  193. package/dist/ui-public/src/overlays/useModalClose.js +3 -3
  194. package/dist/ui-public/src/patterns/ListDetail/FloatingDetail.js +2 -2
  195. package/dist/ui-public/src/patterns/ListDetail/Page.d.ts +8 -9
  196. package/dist/ui-public/src/patterns/ListDetail/Page.js +4 -5
  197. package/dist/ui-public/src/patterns/ListDetail/Panel.d.ts +2 -2
  198. package/dist/ui-public/src/patterns/ListDetail/Panel.js +1 -1
  199. package/dist/ui-public/src/patterns/ListDetail/Split.d.ts +9 -10
  200. package/dist/ui-public/src/patterns/ListDetail/Split.js +5 -5
  201. package/dist/ui-public/src/patterns/ListFormPage.d.ts +3 -3
  202. package/dist/ui-public/src/patterns/ListFormPage.js +1 -1
  203. package/dist/ui-public/src/semantic/Heading.d.ts +1 -1
  204. package/dist/ui-public/src/semantic/Heading.js +1 -1
  205. package/dist/ui-public/src/semantic/Image.js +1 -1
  206. package/dist/ui-public/src/semantic/Nav.d.ts +3 -3
  207. package/dist/ui-public/src/semantic/Nav.js +3 -3
  208. package/dist/ui-public/src/semantic/RawButton.d.ts +3 -3
  209. package/dist/ui-public/src/semantic/RawButton.js +1 -1
  210. package/dist/ui-public/src/semantic/Search.d.ts +1 -1
  211. package/dist/ui-public/src/semantic/Search.js +1 -1
  212. package/dist/ui-public/src/utils/format.d.ts +21 -0
  213. package/dist/ui-public/src/utils/format.js +20 -0
  214. package/dist/ui-public/src/utils/formatDate.d.ts +10 -2
  215. package/dist/ui-public/src/utils/formatDate.js +4 -4
  216. package/dist/ui-public/src/utils/tickBatcher.js +44 -0
  217. package/dist/ui-public/src/utils/timezones.js +277 -0
  218. package/dist/ui-public/src/utils/weekStartForLocale.js +25 -0
  219. package/dist/utils/format.d.ts +1 -0
  220. package/dist/utils/format.js +2 -0
  221. package/package.json +2 -2
  222. package/dist/ui-public/icons/lucide/receipt.js +0 -26
@@ -6,8 +6,8 @@ export type BoxSize = {
6
6
  /** The space around the asset, in px */
7
7
  export type UploadPreviewPadding = [vertical: number, horizontal: number];
8
8
  /**
9
- * The space around the asset when the caller gives no padding. Only an image
10
- * can have no space around it: when the caller gives zero padding, an icon
9
+ * The space around the asset when you give no padding. Only an image
10
+ * can have no space around it: when you give zero padding, an icon
11
11
  * gets this space, because an icon without space touches the edges of the
12
12
  * box.
13
13
  */
@@ -1,7 +1,7 @@
1
- //#region ../ui-public/src/content/uploadPreviewFit.ts
1
+ //#region ../ui-public/src/content/UploadPreview/fit.ts
2
2
  /**
3
- * The space around the asset when the caller gives no padding. Only an image
4
- * can have no space around it: when the caller gives zero padding, an icon
3
+ * The space around the asset when you give no padding. Only an image
4
+ * can have no space around it: when you give zero padding, an icon
5
5
  * gets this space, because an icon without space touches the edges of the
6
6
  * box.
7
7
  */
@@ -0,0 +1,61 @@
1
+ import React, { type ReactNode } from 'react';
2
+ import { type UploadPreviewBoxProps } from './box.js';
3
+ import type { BoxSize, UploadPreviewPadding } from './fit.js';
4
+ import type { UploadFieldValue, UploadPreviewUpload } from './upload.js';
5
+ export type { UploadPreviewImageProps, UploadPreviewProgressProps, } from './box.js';
6
+ export type { BoxSize, UploadPreviewPadding } from './fit.js';
7
+ export type { UploadFieldValue, UploadPreviewUpload } from './upload.js';
8
+ /**
9
+ * Mode "box": you draw the asset in the box, with `UploadPreview.Image`, an
10
+ * icon or a progress bar.
11
+ */
12
+ export type UploadPreviewBoxModeProps = UploadPreviewBoxProps & {
13
+ upload?: never;
14
+ fieldValue?: never;
15
+ };
16
+ /**
17
+ * Mode "upload": the preview draws an asset of the Media Area, as DatoCMS
18
+ * draws it.
19
+ */
20
+ export type UploadPreviewUploadModeProps = {
21
+ /**
22
+ * The asset as `ctx` gives it, or its ID. An ID loads through the
23
+ * provider of the host: `Canvas` mounts it. While the asset loads, the box
24
+ * is empty. An asset that does not exist, or `null`, shows a blank file
25
+ * icon.
26
+ */
27
+ upload: string | UploadPreviewUpload | null;
28
+ /**
29
+ * The size of the box in px. The box gets this size. Without it, the CSS
30
+ * of the parent gives the size of the box, and the preview measures it.
31
+ */
32
+ box?: BoxSize;
33
+ /**
34
+ * The space (vertical, horizontal) in px between the box and the asset.
35
+ * An icon always gets space: with `[0, 0]`, an icon gets `[10, 10]`.
36
+ * @default [10, 10]
37
+ */
38
+ padding?: UploadPreviewPadding;
39
+ /** The box has no background, so it shows the background of the parent. */
40
+ transparent?: boolean;
41
+ /** The box is a link. */
42
+ link?: {
43
+ href: string;
44
+ target?: string;
45
+ };
46
+ /**
47
+ * The value of the field that holds the asset, as in `UploadCard`. The
48
+ * preview reads its `poster_time`, the frame of a video. When it is not
49
+ * set, the frame is the default of the asset.
50
+ */
51
+ fieldValue?: UploadFieldValue;
52
+ /** More content in the box, over the asset */
53
+ children?: ReactNode;
54
+ fixedSize?: never;
55
+ };
56
+ export type UploadPreviewProps = UploadPreviewBoxModeProps | UploadPreviewUploadModeProps;
57
+ declare const _default: React.ForwardRefExoticComponent<UploadPreviewProps & React.RefAttributes<HTMLElement>> & {
58
+ Image: ({ src, width, height, upscale, icon, alt, }: import("./box.js").UploadPreviewImageProps) => React.JSX.Element | null;
59
+ Progress: ({ percent, label }: import("./box.js").UploadPreviewProgressProps) => React.JSX.Element;
60
+ };
61
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { useLoadedUpload } from "./presentation.js";
2
+ import box_default from "./box.js";
3
+ import { UploadAssetPreview } from "./asset.js";
4
+ import { forwardRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ //#region ../ui-public/src/content/UploadPreview/index.tsx
7
+ var UploadModePreview = forwardRef(function UploadModePreview({ upload, fieldValue, ...props }, ref) {
8
+ const loaded = useLoadedUpload(upload);
9
+ return /* @__PURE__ */ jsx(UploadAssetPreview, {
10
+ ...props,
11
+ ref,
12
+ upload: loaded,
13
+ posterTime: fieldValue?.poster_time ?? void 0
14
+ });
15
+ });
16
+ /**
17
+ * The preview of an asset in a box: the asset is in the center, with space
18
+ * around it. With `upload`, the preview draws an asset of the Media Area.
19
+ * Without it, you draw the asset in the box.
20
+ */
21
+ var UploadPreview = forwardRef(function UploadPreview(props, ref) {
22
+ if (props.upload !== void 0) return /* @__PURE__ */ jsx(UploadModePreview, {
23
+ ...props,
24
+ ref
25
+ });
26
+ return /* @__PURE__ */ jsx(box_default, {
27
+ ...props,
28
+ ref
29
+ });
30
+ });
31
+ var UploadPreview_default = Object.assign(UploadPreview, {
32
+ Image: box_default.Image,
33
+ Progress: box_default.Progress
34
+ });
35
+ //#endregion
36
+ export { UploadPreview_default as default };
@@ -0,0 +1,63 @@
1
+ import { createTickBatcher } from "../../utils/tickBatcher.js";
2
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region ../ui-public/src/content/UploadPreview/presentation.tsx
5
+ var UploadPresentationContext = createContext({
6
+ request: async () => null,
7
+ mainLocale: void 0
8
+ });
9
+ /**
10
+ * Gives the loader of assets to the `UploadPreview`s and `UploadCard`s with
11
+ * an asset ID. The previews of one render ask for their assets in the same
12
+ * tick: the provider sends them in one call to the loader. It keeps no
13
+ * cache. A failed call gives null to its previews.
14
+ */
15
+ function UploadPresentationProvider({ load, mainLocale, children }) {
16
+ const request = useMemo(() => {
17
+ const batch = createTickBatcher({
18
+ groupKey: () => "",
19
+ fallback: null,
20
+ load: async (_group, uploadIds) => load ? load(uploadIds) : uploadIds.map(() => null)
21
+ });
22
+ return (uploadId) => batch(null, uploadId);
23
+ }, [load]);
24
+ const value = useMemo(() => ({
25
+ request,
26
+ mainLocale
27
+ }), [request, mainLocale]);
28
+ return /* @__PURE__ */ jsx(UploadPresentationContext.Provider, {
29
+ value,
30
+ children
31
+ });
32
+ }
33
+ /**
34
+ * The asset from the loader of the provider, or the asset itself when it is
35
+ * not an ID. It is undefined while it loads, and null when the asset does not
36
+ * exist or the loader failed.
37
+ */
38
+ function useLoadedUpload(upload) {
39
+ const { request } = useContext(UploadPresentationContext);
40
+ const id = typeof upload === "string" ? upload : null;
41
+ const [state, setState] = useState(null);
42
+ useEffect(() => {
43
+ if (id === null) return;
44
+ let active = true;
45
+ request(id).then((value) => {
46
+ if (active) setState({
47
+ id,
48
+ value
49
+ });
50
+ });
51
+ return () => {
52
+ active = false;
53
+ };
54
+ }, [request, id]);
55
+ if (typeof upload !== "string") return upload;
56
+ return state?.id === upload ? state.value : void 0;
57
+ }
58
+ /** The main locale of the project, from the provider */
59
+ function useUploadMainLocale() {
60
+ return useContext(UploadPresentationContext).mainLocale;
61
+ }
62
+ //#endregion
63
+ export { UploadPresentationProvider, useLoadedUpload, useUploadMainLocale };
@@ -0,0 +1,91 @@
1
+ import { useEffect, useMemo, useRef } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ //#region ../ui-public/src/content/UploadPreview/thumbhash.tsx
4
+ function thumbHashToApproximateAspectRatio(hash) {
5
+ const header = hash[3];
6
+ const hasAlpha = hash[2] & 128;
7
+ const isLandscape = hash[4] & 128;
8
+ return (isLandscape ? hasAlpha ? 5 : 7 : header & 7) / (isLandscape ? header & 7 : hasAlpha ? 5 : 7);
9
+ }
10
+ function thumbHashToRGBA(hash) {
11
+ const { PI, min, max, cos, round } = Math;
12
+ const header24 = hash[0] | hash[1] << 8 | hash[2] << 16;
13
+ const header16 = hash[3] | hash[4] << 8;
14
+ const l_dc = (header24 & 63) / 63;
15
+ const p_dc = (header24 >> 6 & 63) / 31.5 - 1;
16
+ const q_dc = (header24 >> 12 & 63) / 31.5 - 1;
17
+ const l_scale = (header24 >> 18 & 31) / 31;
18
+ const hasAlpha = header24 >> 23;
19
+ const p_scale = (header16 >> 3 & 63) / 63;
20
+ const q_scale = (header16 >> 9 & 63) / 63;
21
+ const isLandscape = header16 >> 15;
22
+ const lx = max(3, isLandscape ? hasAlpha ? 5 : 7 : header16 & 7);
23
+ const ly = max(3, isLandscape ? header16 & 7 : hasAlpha ? 5 : 7);
24
+ const a_dc = hasAlpha ? (hash[5] & 15) / 15 : 1;
25
+ const a_scale = (hash[5] >> 4) / 15;
26
+ const ac_start = hasAlpha ? 6 : 5;
27
+ let ac_index = 0;
28
+ const decodeChannel = (nx, ny, scale) => {
29
+ const ac = [];
30
+ for (let cy = 0; cy < ny; cy++) for (let cx = cy ? 0 : 1; cx * ny < nx * (ny - cy); cx++) ac.push(((hash[ac_start + (ac_index >> 1)] >> ((ac_index++ & 1) << 2) & 15) / 7.5 - 1) * scale);
31
+ return ac;
32
+ };
33
+ const l_ac = decodeChannel(lx, ly, l_scale);
34
+ const p_ac = decodeChannel(3, 3, p_scale * 1.25);
35
+ const q_ac = decodeChannel(3, 3, q_scale * 1.25);
36
+ const a_ac = hasAlpha ? decodeChannel(5, 5, a_scale) : [];
37
+ const ratio = thumbHashToApproximateAspectRatio(hash);
38
+ const w = round(ratio > 1 ? 32 : 32 * ratio);
39
+ const h = round(ratio > 1 ? 32 / ratio : 32);
40
+ const rgba = new Uint8ClampedArray(w * h * 4);
41
+ const fx = [];
42
+ const fy = [];
43
+ for (let y = 0, i = 0; y < h; y++) for (let x = 0; x < w; x++, i += 4) {
44
+ let l = l_dc;
45
+ let p = p_dc;
46
+ let q = q_dc;
47
+ let a = a_dc;
48
+ for (let cx = 0, n = max(lx, hasAlpha ? 5 : 3); cx < n; cx++) fx[cx] = cos(PI / w * (x + .5) * cx);
49
+ for (let cy = 0, n = max(ly, hasAlpha ? 5 : 3); cy < n; cy++) fy[cy] = cos(PI / h * (y + .5) * cy);
50
+ for (let cy = 0, j = 0; cy < ly; cy++) for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx * ly < lx * (ly - cy); cx++, j++) l += l_ac[j] * fx[cx] * fy2;
51
+ for (let cy = 0, j = 0; cy < 3; cy++) for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx < 3 - cy; cx++, j++) {
52
+ const f = fx[cx] * fy2;
53
+ p += p_ac[j] * f;
54
+ q += q_ac[j] * f;
55
+ }
56
+ if (hasAlpha) for (let cy = 0, j = 0; cy < 5; cy++) for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx < 5 - cy; cx++, j++) a += a_ac[j] * fx[cx] * fy2;
57
+ const b = l - 2 / 3 * p;
58
+ const r = (3 * l - b + q) / 2;
59
+ const g = r - q;
60
+ rgba[i] = max(0, 255 * min(1, r));
61
+ rgba[i + 1] = max(0, 255 * min(1, g));
62
+ rgba[i + 2] = max(0, 255 * min(1, b));
63
+ rgba[i + 3] = max(0, 255 * min(1, a));
64
+ }
65
+ return {
66
+ w,
67
+ h,
68
+ rgba
69
+ };
70
+ }
71
+ function decodeThumbhash(thumbhash) {
72
+ return thumbHashToRGBA(new Uint8ClampedArray(atob(thumbhash).split("").map((x) => x.charCodeAt(0))));
73
+ }
74
+ /** The blurred picture of a thumbhash, while the real image loads */
75
+ function ThumbhashCanvas({ thumbhash, style }) {
76
+ const canvasRef = useRef(null);
77
+ const result = useMemo(() => decodeThumbhash(thumbhash), [thumbhash]);
78
+ useEffect(() => {
79
+ const context = canvasRef.current?.getContext("2d");
80
+ if (!context) return;
81
+ context.putImageData(new ImageData(result.rgba, result.w, result.h), 0, 0);
82
+ }, [result]);
83
+ return /* @__PURE__ */ jsx("canvas", {
84
+ ref: canvasRef,
85
+ style,
86
+ width: result.w,
87
+ height: result.h
88
+ });
89
+ }
90
+ //#endregion
91
+ export { ThumbhashCanvas };
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The metadata of an asset in one locale. An older plugin SDK gives
3
+ * `default_field_metadata` keyed by locale (`{ en: { alt, title } }`); the
4
+ * API and the newer SDKs give it keyed by field (`{ alt: { en } }`). The
5
+ * helpers read the two shapes.
6
+ */
7
+ type LocaleMetadata = {
8
+ alt?: string | null;
9
+ title?: string | null;
10
+ poster_time?: number | null;
11
+ };
12
+ type FieldKeyedMetadata = {
13
+ alt: {
14
+ [locale: string]: string | null;
15
+ };
16
+ title: {
17
+ [locale: string]: string | null;
18
+ };
19
+ poster_time?: number | null;
20
+ };
21
+ type LocaleKeyedMetadata = {
22
+ [locale: string]: LocaleMetadata;
23
+ };
24
+ /**
25
+ * An asset of the Media Area as the API and `ctx` give it (for example
26
+ * `ctx.selectUpload()` or `ctx.loadUploads()`). The preview reads only these
27
+ * fields.
28
+ */
29
+ export type UploadPreviewUpload = {
30
+ id?: string;
31
+ attributes: {
32
+ /** The full URL of the file */
33
+ url: string;
34
+ filename?: string;
35
+ format: string | null;
36
+ size: number;
37
+ width: number | null;
38
+ height: number | null;
39
+ mime_type: string | null;
40
+ md5?: string | null;
41
+ thumbhash?: string | null;
42
+ mux_playback_id?: string | null;
43
+ default_field_metadata?: FieldKeyedMetadata | LocaleKeyedMetadata;
44
+ };
45
+ meta?: {
46
+ antivirus?: {
47
+ status?: string | null;
48
+ } | null;
49
+ };
50
+ };
51
+ type Attributes = UploadPreviewUpload['attributes'];
52
+ /**
53
+ * The metadata of an asset in the value of a file or gallery field. Each
54
+ * value is null when the field uses the default of the asset.
55
+ */
56
+ export type UploadFieldValue = {
57
+ alt?: string | null;
58
+ title?: string | null;
59
+ /** The frame of a video, in seconds */
60
+ poster_time?: number | null;
61
+ };
62
+ /**
63
+ * The default alternate text and title of an asset, from the Media Area. Each
64
+ * value is the one of the first locale of `locales` that is not null, as the
65
+ * gallery field of DatoCMS reads it: an empty text does not fall back.
66
+ */
67
+ export declare function uploadDefaultMetadata(upload: UploadPreviewUpload, locales: string[]): {
68
+ alt: string | null;
69
+ title: string | null;
70
+ };
71
+ /**
72
+ * The default frame of a video, in seconds, from the Media Area. Null for the
73
+ * default frame of the video service.
74
+ */
75
+ export declare function uploadDefaultPosterTime(upload: UploadPreviewUpload): number | null;
76
+ /** The image service of DatoCMS transforms (crops, resizes) this format */
77
+ export declare function formatSupportsTransformations(format: string | null): boolean;
78
+ /** The browser shows a file of this format in an image */
79
+ export declare function formatShownByBrowser(format: string | null): boolean;
80
+ export type UploadPreviewKind =
81
+ /** A file that the image service resizes */
82
+ 'image'
83
+ /** A small file that the browser shows as it is (an SVG) */
84
+ | 'file-image'
85
+ /** A video with its frame */
86
+ | 'video'
87
+ /** A video that the video service still encodes */
88
+ | 'video-encoding' | 'audio'
89
+ /** Any other file: the icon of its format */
90
+ | 'file';
91
+ /** What the preview of an asset shows */
92
+ export declare function uploadPreviewKind(attributes: Attributes): UploadPreviewKind;
93
+ /**
94
+ * The URL of the file, with a parameter that changes when the file changes:
95
+ * the browser does not show an old copy from its cache. A change of the
96
+ * metadata does not change it.
97
+ */
98
+ export declare function uploadFileUrl(attributes: Attributes, params?: Record<string, string | number>): string;
99
+ /**
100
+ * The URL of a frame of a video, at this width in image pixels. Without
101
+ * `posterTime`, the frame is the one of the video service.
102
+ */
103
+ export declare function videoFrameUrl(muxPlaybackId: string, width: number, posterTime: number | null): string;
104
+ export {};
@@ -0,0 +1,112 @@
1
+ //#region ../ui-public/src/content/UploadPreview/upload.ts
2
+ function isFieldKeyed(metadata) {
3
+ return typeof metadata.alt === "object" && metadata.alt !== null && !("alt" in metadata.alt) && !("title" in metadata.alt);
4
+ }
5
+ /**
6
+ * The default alternate text and title of an asset, from the Media Area. Each
7
+ * value is the one of the first locale of `locales` that is not null, as the
8
+ * gallery field of DatoCMS reads it: an empty text does not fall back.
9
+ */
10
+ function uploadDefaultMetadata(upload, locales) {
11
+ const metadata = upload.attributes.default_field_metadata;
12
+ function first(field) {
13
+ if (!metadata) return null;
14
+ for (const locale of locales) {
15
+ const value = isFieldKeyed(metadata) ? metadata[field][locale] : metadata[locale]?.[field];
16
+ if (value != null) return value;
17
+ }
18
+ return null;
19
+ }
20
+ return {
21
+ alt: first("alt"),
22
+ title: first("title")
23
+ };
24
+ }
25
+ /**
26
+ * The default frame of a video, in seconds, from the Media Area. Null for the
27
+ * default frame of the video service.
28
+ */
29
+ function uploadDefaultPosterTime(upload) {
30
+ const metadata = upload.attributes.default_field_metadata;
31
+ if (!metadata) return null;
32
+ if (isFieldKeyed(metadata)) return metadata.poster_time ?? null;
33
+ return Object.values(metadata)[0]?.poster_time ?? null;
34
+ }
35
+ var formatsWithTransformations = /* @__PURE__ */ new Set([
36
+ "ai",
37
+ "avif",
38
+ "bmp",
39
+ "gif",
40
+ "heic",
41
+ "ico",
42
+ "icns",
43
+ "jpg",
44
+ "jpeg",
45
+ "pct",
46
+ "png",
47
+ "psd",
48
+ "tif",
49
+ "tiff",
50
+ "webp"
51
+ ]);
52
+ var formatsShownByBrowser = /* @__PURE__ */ new Set([
53
+ "bmp",
54
+ "gif",
55
+ "jpeg",
56
+ "jpg",
57
+ "png",
58
+ "svg",
59
+ "webp"
60
+ ]);
61
+ var AVIF_PROBE = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAA1HbWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAANbwAAACIAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAMv2lwcnAA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/t3/Af8mP0p/br+S/7c/23//wAAABNjb2xybmNseAABAA0ABoAAAAAYaXBtYQAAAAAAAAABAAEFAQKDBAUAAAAqbWRhdBIACggYAAaICGg0IDIUE8ADDDDEAgkAA1C2y8ymNlTjVUA=";
62
+ var probeStarted = false;
63
+ function probeBrowserFormats() {
64
+ if (probeStarted || typeof Image === "undefined") return;
65
+ probeStarted = true;
66
+ const image = new Image();
67
+ image.onload = () => {
68
+ if (image.width === 1) formatsShownByBrowser.add("avif");
69
+ };
70
+ image.src = AVIF_PROBE;
71
+ }
72
+ /** The image service of DatoCMS transforms (crops, resizes) this format */
73
+ function formatSupportsTransformations(format) {
74
+ return !!format && formatsWithTransformations.has(format.toLowerCase());
75
+ }
76
+ /** The browser shows a file of this format in an image */
77
+ function formatShownByBrowser(format) {
78
+ probeBrowserFormats();
79
+ return !!format && formatsShownByBrowser.has(format.toLowerCase());
80
+ }
81
+ var MAX_SIZE_OF_FILE_SHOWN_AS_IT_IS = 35e4;
82
+ /** What the preview of an asset shows */
83
+ function uploadPreviewKind(attributes) {
84
+ const { format, width, height, size } = attributes;
85
+ if (attributes.mime_type?.startsWith("audio")) return "audio";
86
+ if (attributes.mux_playback_id && width && height) return "video";
87
+ if (attributes.mux_playback_id && !format) return "video-encoding";
88
+ if (!width || !height) return "file";
89
+ if (formatSupportsTransformations(format)) return "image";
90
+ if (formatShownByBrowser(format) && size && size < MAX_SIZE_OF_FILE_SHOWN_AS_IT_IS) return "file-image";
91
+ return "file";
92
+ }
93
+ /**
94
+ * The URL of the file, with a parameter that changes when the file changes:
95
+ * the browser does not show an old copy from its cache. A change of the
96
+ * metadata does not change it.
97
+ */
98
+ function uploadFileUrl(attributes, params = {}) {
99
+ const url = new URL(attributes.url);
100
+ if (attributes.md5) url.searchParams.set("ts", attributes.md5.substring(0, 8));
101
+ for (const [key, value] of Object.entries(params)) url.searchParams.set(key, String(value));
102
+ return url.toString();
103
+ }
104
+ /**
105
+ * The URL of a frame of a video, at this width in image pixels. Without
106
+ * `posterTime`, the frame is the one of the video service.
107
+ */
108
+ function videoFrameUrl(muxPlaybackId, width, posterTime) {
109
+ return `https://image.mux.com/${muxPlaybackId}/thumbnail.jpg?width=${width}${posterTime != null ? `&time=${posterTime}` : ""}`;
110
+ }
111
+ //#endregion
112
+ export { formatShownByBrowser, formatSupportsTransformations, uploadDefaultMetadata, uploadDefaultPosterTime, uploadFileUrl, uploadPreviewKind, videoFrameUrl };
@@ -19,7 +19,7 @@ export type UsageMeterProps = {
19
19
  * @default false
20
20
  */
21
21
  blocked?: boolean;
22
- /** Only for the size and the place of the meter, not for its look */
22
+ /** Only for the size and the position of the meter, not for its look */
23
23
  className?: string;
24
24
  };
25
25
  /** The usage against a limit, with the part over the limit in color */
@@ -18,7 +18,7 @@ export type ItemValidityTrianglesProps = {
18
18
  currentValid?: boolean | null | undefined;
19
19
  /**
20
20
  * True when the model has a draft mode. Without it, the current version
21
- * is the published version, thus the current triangle does not show.
21
+ * is the published version, so the current triangle does not show.
22
22
  */
23
23
  draftModeActive: boolean | null | undefined;
24
24
  };
@@ -10,20 +10,20 @@ export type BlankSlateDocsLink = {
10
10
  href: string;
11
11
  };
12
12
  /**
13
- * While the content loads: a spinner shows in the place of the icon. The
14
- * title then tells what loads. Without a title, the spinner tells that the
13
+ * While the content loads, a spinner shows instead of the icon. The
14
+ * title then says what loads. Without a title, the spinner says that the
15
15
  * content loads.
16
16
  */
17
17
  type Loading = {
18
- /** Shows a spinner in the place of the icon */
18
+ /** Shows a spinner instead of the icon */
19
19
  loading: true;
20
20
  /** What loads, for example "Loading the invoices" */
21
21
  title?: Message;
22
- /** The spinner takes the place of the icon */
22
+ /** The spinner replaces the icon */
23
23
  icon?: never;
24
24
  error?: never;
25
25
  };
26
- /** The content is ready: the blank slate tells why there is nothing to show */
26
+ /** The content is ready: the blank slate says why there is nothing to show */
27
27
  type Loaded = {
28
28
  loading?: false;
29
29
  /**
@@ -2,10 +2,10 @@ import React, { ReactNode } from 'react';
2
2
  import { type Message } from '../Message.js';
3
3
  export type CalloutProps = {
4
4
  /**
5
- * "neutral" gives information. "warning" tells about a problem or a risk
5
+ * "neutral" gives information. "warning" says that there is a problem or a risk
6
6
  * with the current data, for example a token that shows only once.
7
- * "danger" tells about an error, for example the error of a form.
8
- * "success" tells that the current data is in a good state, for example
7
+ * "danger" says that there is an error, for example the error of a form.
8
+ * "success" says that the current data is in a good state, for example
9
9
  * a usage that is within the limits.
10
10
  *
11
11
  * When a "warning" or "danger" callout appears, screen readers read it
@@ -18,13 +18,13 @@ export type CalloutProps = {
18
18
  icon?: ReactNode;
19
19
  /** A short line in bold above the text, for example "Some invoices are due" */
20
20
  title?: Message;
21
- /** Only for the place of the callout (margin), not for its look */
21
+ /** Only for the position of the callout (margin), not for its look */
22
22
  className?: string;
23
23
  /** The message. A next step is a link in the text. */
24
24
  children?: ReactNode;
25
25
  };
26
26
  /**
27
- * A message about the current data. For the text that tells what a page is
27
+ * A message about the current data. For the text that says what a page is
28
28
  * for, use Toolbar.Help. A callout has no buttons: a next step is a link in
29
29
  * the text, and a link only opens a page. An action that fixes the problem
30
30
  * goes in the row of the value, or in a Page.Group with a tone (a callout in
@@ -5,7 +5,7 @@ import classNames from "classnames";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  //#region ../ui-public/src/feedback/Callout.tsx
7
7
  /**
8
- * A message about the current data. For the text that tells what a page is
8
+ * A message about the current data. For the text that says what a page is
9
9
  * for, use Toolbar.Help. A callout has no buttons: a next step is a link in
10
10
  * the text, and a link only opens a page. An action that fixes the problem
11
11
  * goes in the row of the value, or in a Page.Group with a tone (a callout in
@@ -14,14 +14,14 @@ export type ProgressBarProps = {
14
14
  ariaLabel: TextMessage;
15
15
  /**
16
16
  * "inline" is a 4px bar as wide as its parent. "edge" is a 2px bar on the
17
- * bottom edge of the nearest positioned parent, thus it does not cover the
18
- * content: use it on a card or a row.
17
+ * bottom edge of the nearest positioned parent, so it does not cover the
18
+ * content. Use it on a card or a row.
19
19
  * @default "inline"
20
20
  */
21
21
  placement?: 'inline' | 'edge';
22
22
  /**
23
- * Only for the place of the bar (width, margin), not for its look. The bar
24
- * is as wide as its parent: the caller knows the width that fits its
23
+ * Only for the position of the bar (width, margin), not for its look. The bar
24
+ * is as wide as its parent. You know the width that fits your
25
25
  * layout, for example a maximum width in a table column.
26
26
  */
27
27
  className?: string;
@@ -9,17 +9,17 @@ export type SpinnerProps = {
9
9
  */
10
10
  inline?: boolean;
11
11
  /**
12
- * The text that a screen reader tells: the spinner is a status. Give
13
- * `false` when a visible text or `aria-busy` already tells that the
14
- * content loads: then the spinner is only a decoration.
12
+ * The text that a screen reader says. The spinner is a status. Give
13
+ * `false` when a visible text or `aria-busy` already says that the
14
+ * content loads. Then the spinner is only a decoration.
15
15
  * @default "Loading"
16
16
  */
17
17
  label?: TextMessage | false;
18
- /** Only for the place of the spinner (margin, z-index), not for its look */
18
+ /** Only for the position of the spinner (margin, z-index), not for its look */
19
19
  className?: string;
20
20
  };
21
21
  /**
22
- * A spinner that tells that something loads. It has two sizes: 32px to load
22
+ * A spinner that shows that something loads. It has two sizes: 32px to load
23
23
  * an area, 16px (an icon) in a line of text or in a control. The box is the
24
24
  * size of the spinner.
25
25
  */
@@ -50,7 +50,7 @@ export type SpinnerOverlayProps = {
50
50
  veil?: boolean;
51
51
  /** See the label of Spinner */
52
52
  label?: TextMessage | false;
53
- /** Only for the place of the overlay (z-index), not for its look */
53
+ /** Only for the position of the overlay (z-index), not for its look */
54
54
  className?: string;
55
55
  };
56
56
  /**
@@ -3,7 +3,7 @@ import "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  //#region ../ui-public/src/feedback/Spinner.tsx
5
5
  /**
6
- * A spinner that tells that something loads. It has two sizes: 32px to load
6
+ * A spinner that shows that something loads. It has two sizes: 32px to load
7
7
  * an area, 16px (an icon) in a line of text or in a control. The box is the
8
8
  * size of the spinner.
9
9
  */