datocms-react-ui 3.1.0-next.6 → 3.1.0-next.9
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.
- package/README.md +3 -2
- package/dist/DateInput.d.ts +2 -0
- package/dist/DateInput.js +2 -0
- package/dist/DateTimeInput.d.ts +2 -0
- package/dist/DateTimeInput.js +2 -0
- package/dist/DateTimeRangeInput.d.ts +2 -0
- package/dist/DateTimeRangeInput.js +2 -0
- package/dist/FieldTypeAvatar.d.ts +2 -0
- package/dist/FieldTypeAvatar.js +2 -0
- package/dist/FieldTypeName.d.ts +2 -0
- package/dist/FieldTypeName.js +2 -0
- package/dist/FilterBuilder.d.ts +2 -0
- package/dist/FilterBuilder.js +2 -0
- package/dist/RecordRow.d.ts +2 -0
- package/dist/RecordRow.js +2 -0
- package/dist/UploadCard.js +2 -2
- package/dist/UploadPreview.d.ts +2 -2
- package/dist/UploadPreview.js +1 -1
- package/dist/UserRow.d.ts +2 -0
- package/dist/UserRow.js +2 -0
- package/dist/react-ui/src/Canvas.d.ts +7 -1
- package/dist/react-ui/src/Canvas.js +26 -4
- package/dist/react-ui/src/ctxAnswer.js +21 -0
- package/dist/react-ui/src/ctxDateSettings.js +7 -5
- package/dist/react-ui/src/ctxRecordPresentation.js +34 -0
- package/dist/react-ui/src/ctxUploads.js +23 -0
- package/dist/styles.css +634 -45
- package/dist/ui-public/icons/index.js +285 -280
- package/dist/ui-public/icons/lucide/braces.js +22 -0
- package/dist/ui-public/icons/lucide/hash.js +47 -0
- package/dist/ui-public/icons/lucide/letter-text.js +28 -0
- package/dist/ui-public/icons/lucide/rows-3.js +32 -0
- package/dist/ui-public/icons/lucide/toggle-right.js +32 -0
- package/dist/ui-public/locales/en.js +74 -5
- package/dist/ui-public/src/Message.d.ts +3 -4
- package/dist/ui-public/src/UiTextKey.d.ts +1 -1
- package/dist/ui-public/src/actions/Actions/ActionTooltip.js +1 -1
- package/dist/ui-public/src/actions/Actions/registry.d.ts +2 -2
- package/dist/ui-public/src/actions/Actions/registry.js +2 -2
- package/dist/ui-public/src/actions/Button.d.ts +10 -10
- package/dist/ui-public/src/actions/Button.js +1 -1
- package/dist/ui-public/src/actions/Dropdown/Menu.d.ts +2 -2
- package/dist/ui-public/src/actions/Dropdown/Option.d.ts +7 -7
- package/dist/ui-public/src/actions/Dropdown/index.d.ts +1 -1
- package/dist/ui-public/src/actions/Dropdown/triggers/ButtonTrigger.d.ts +5 -5
- package/dist/ui-public/src/actions/Dropdown/triggers/DropdownTriggerButton.d.ts +2 -2
- package/dist/ui-public/src/actions/Dropdown/triggers/IconTrigger.d.ts +6 -6
- package/dist/ui-public/src/actions/Dropdown/triggers/IconTrigger.js +1 -1
- package/dist/ui-public/src/actions/EditorToolbar/Button.d.ts +1 -1
- package/dist/ui-public/src/actions/MultipleSelectionActionBar.d.ts +1 -1
- package/dist/ui-public/src/actions/SplitButton/Caret.js +2 -2
- package/dist/ui-public/src/actions/SplitButton/Halves.js +1 -1
- package/dist/ui-public/src/actions/SplitButton/index.d.ts +3 -3
- package/dist/ui-public/src/actions/disabledReason.d.ts +4 -4
- package/dist/ui-public/src/content/Avatar.d.ts +3 -3
- package/dist/ui-public/src/content/Avatar.js +2 -2
- package/dist/ui-public/src/content/CodeSnippet.d.ts +1 -1
- package/dist/ui-public/src/content/CopyableValue.d.ts +1 -1
- package/dist/ui-public/src/content/EnvironmentPill.d.ts +1 -1
- package/dist/ui-public/src/content/EnvironmentPill.js +1 -1
- package/dist/ui-public/src/content/FieldTypeAvatar.d.ts +22 -0
- package/dist/ui-public/src/content/FieldTypeAvatar.js +35 -0
- package/dist/ui-public/src/content/FieldTypeName.d.ts +19 -0
- package/dist/ui-public/src/content/FieldTypeName.js +25 -0
- package/dist/ui-public/src/content/IconAvatar.d.ts +3 -2
- package/dist/ui-public/src/content/ItemStatus.d.ts +1 -1
- package/dist/ui-public/src/content/Pill.d.ts +1 -1
- package/dist/ui-public/src/content/SmartDate.d.ts +1 -1
- package/dist/ui-public/src/content/UploadPreview/asset.js +200 -0
- package/dist/ui-public/src/content/UploadPreview/audio.js +120 -0
- package/dist/ui-public/src/content/{UploadPreview.d.ts → UploadPreview/box.d.ts} +10 -10
- package/dist/ui-public/src/content/{UploadPreview.js → UploadPreview/box.js} +7 -7
- package/dist/ui-public/src/content/{uploadPreviewFit.d.ts → UploadPreview/fit.d.ts} +2 -2
- package/dist/ui-public/src/content/{uploadPreviewFit.js → UploadPreview/fit.js} +3 -3
- package/dist/ui-public/src/content/UploadPreview/index.d.ts +61 -0
- package/dist/ui-public/src/content/UploadPreview/index.js +36 -0
- package/dist/ui-public/src/content/UploadPreview/presentation.js +63 -0
- package/dist/ui-public/src/content/UploadPreview/thumbhash.js +91 -0
- package/dist/ui-public/src/content/UploadPreview/upload.d.ts +104 -0
- package/dist/ui-public/src/content/UploadPreview/upload.js +112 -0
- package/dist/ui-public/src/content/UsageMeter.d.ts +1 -1
- package/dist/ui-public/src/content/ValidityTriangles.d.ts +1 -1
- package/dist/ui-public/src/feedback/BlankSlate.d.ts +5 -5
- package/dist/ui-public/src/feedback/Callout.d.ts +5 -5
- package/dist/ui-public/src/feedback/Callout.js +1 -1
- package/dist/ui-public/src/feedback/ProgressBar.d.ts +4 -4
- package/dist/ui-public/src/feedback/Spinner.d.ts +6 -6
- package/dist/ui-public/src/feedback/Spinner.js +1 -1
- package/dist/ui-public/src/form/DateInput.d.ts +13 -0
- package/dist/ui-public/src/form/DateInput.js +16 -0
- package/dist/ui-public/src/form/DateTimeInput/Base.d.ts +89 -0
- package/dist/ui-public/src/form/DateTimeInput/Base.js +330 -0
- package/dist/ui-public/src/form/DateTimeInput/CalendarGrid.d.ts +29 -0
- package/dist/ui-public/src/form/DateTimeInput/CalendarGrid.js +195 -0
- package/dist/ui-public/src/form/DateTimeInput/dateText.js +38 -0
- package/dist/ui-public/src/form/DateTimeInput/index.d.ts +10 -0
- package/dist/ui-public/src/form/DateTimeInput/index.js +18 -0
- package/dist/ui-public/src/form/DateTimeInput/value.js +31 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/Panel.js +167 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/index.d.ts +123 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/index.js +186 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/rangeLabel.js +46 -0
- package/dist/ui-public/src/form/FieldHint.d.ts +2 -2
- package/dist/ui-public/src/form/FieldWrapper.d.ts +9 -9
- package/dist/ui-public/src/form/FieldWrapper.js +3 -3
- package/dist/ui-public/src/form/FilterBuilder/Editor.js +123 -0
- package/dist/ui-public/src/form/FilterBuilder/index.d.ts +9 -0
- package/dist/ui-public/src/form/FilterBuilder/index.js +294 -0
- package/dist/ui-public/src/form/FilterBuilder/types.d.ts +188 -0
- package/dist/ui-public/src/form/FilterBuilder/values.js +86 -0
- package/dist/ui-public/src/form/InputGroup.d.ts +2 -2
- package/dist/ui-public/src/form/InputGroup.js +1 -1
- package/dist/ui-public/src/form/KeyValueList.d.ts +1 -1
- package/dist/ui-public/src/form/Label.d.ts +2 -2
- package/dist/ui-public/src/form/RadioGroupInput.d.ts +2 -2
- package/dist/ui-public/src/form/RadioGroupInput.js +1 -1
- package/dist/ui-public/src/form/SelectInput/SelectMenu.d.ts +2 -2
- package/dist/ui-public/src/form/SelectInput/index.d.ts +3 -3
- package/dist/ui-public/src/form/SwitchInput.d.ts +2 -2
- package/dist/ui-public/src/form/SwitchList.d.ts +1 -1
- package/dist/ui-public/src/form/SwitchList.js +1 -1
- package/dist/ui-public/src/form/TableList.d.ts +2 -2
- package/dist/ui-public/src/form/TextareaInput.js +1 -1
- package/dist/ui-public/src/form/inputProps.d.ts +6 -6
- package/dist/ui-public/src/hooks/useAsyncSelectOptions.d.ts +1 -1
- package/dist/ui-public/src/hooks/useSmartRowClick.d.ts +1 -1
- package/dist/ui-public/src/hooks/useSmartRowClick.js +1 -1
- package/dist/ui-public/src/layout/Page/PageGroup.d.ts +2 -2
- package/dist/ui-public/src/layout/Page/PageGroup.js +1 -1
- package/dist/ui-public/src/layout/Pane/FormHeader.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/FormHeader.js +1 -1
- package/dist/ui-public/src/layout/Pane/ListFilter.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/ListPresets.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/PaneHeader.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/index.d.ts +8 -8
- package/dist/ui-public/src/layout/Pane/index.js +17 -8
- package/dist/ui-public/src/layout/SidebarPanel.d.ts +1 -1
- package/dist/ui-public/src/layout/SplitPane/Rail.js +1 -1
- package/dist/ui-public/src/layout/SplitPane/index.d.ts +6 -6
- package/dist/ui-public/src/layout/SplitPane/index.js +16 -2
- package/dist/ui-public/src/layout/Toolbar/AddNewButton.d.ts +2 -2
- package/dist/ui-public/src/layout/Toolbar/Help.d.ts +3 -3
- package/dist/ui-public/src/layout/Toolbar/Help.js +2 -2
- package/dist/ui-public/src/layout/Toolbar/Note.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/Note.js +1 -1
- package/dist/ui-public/src/layout/Toolbar/Pagination.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/Pagination.js +1 -1
- package/dist/ui-public/src/layout/Toolbar/PresetsTitle.d.ts +3 -3
- package/dist/ui-public/src/layout/Toolbar/PresetsTitle.js +2 -2
- package/dist/ui-public/src/layout/Toolbar/PrimaryButton.d.ts +3 -3
- package/dist/ui-public/src/layout/Toolbar/Root.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/Root.js +4 -1
- package/dist/ui-public/src/layout/Toolbar/ToolbarTitleTrigger.js +1 -1
- package/dist/ui-public/src/lists/CardList.d.ts +3 -3
- package/dist/ui-public/src/lists/EmptySlot.d.ts +1 -1
- package/dist/ui-public/src/lists/InfoList/User.d.ts +1 -1
- package/dist/ui-public/src/lists/InfoList/Value.d.ts +1 -1
- package/dist/ui-public/src/lists/InfoList/Value.js +1 -1
- package/dist/ui-public/src/lists/InfoList/index.d.ts +3 -3
- package/dist/ui-public/src/lists/InfoList/index.js +1 -1
- package/dist/ui-public/src/lists/MediaCard.d.ts +7 -7
- package/dist/ui-public/src/lists/RecordRow/Image.d.ts +24 -0
- package/dist/ui-public/src/lists/RecordRow/Image.js +22 -0
- package/dist/ui-public/src/lists/RecordRow/List.d.ts +26 -0
- package/dist/ui-public/src/lists/RecordRow/List.js +30 -0
- package/dist/ui-public/src/lists/RecordRow/context.js +31 -0
- package/dist/ui-public/src/lists/RecordRow/index.d.ts +94 -0
- package/dist/ui-public/src/lists/RecordRow/index.js +122 -0
- package/dist/ui-public/src/lists/RecordRow/presentation.js +73 -0
- package/dist/ui-public/src/lists/RecordRow/types.d.ts +58 -0
- package/dist/ui-public/src/lists/RowList.d.ts +5 -5
- package/dist/ui-public/src/lists/SettingsList.d.ts +3 -3
- package/dist/ui-public/src/lists/SettingsList.js +2 -2
- package/dist/ui-public/src/lists/Table/Row.d.ts +5 -5
- package/dist/ui-public/src/lists/Table/Table.d.ts +3 -3
- package/dist/ui-public/src/lists/Table/TreeToggle.d.ts +2 -2
- package/dist/ui-public/src/lists/Table/TreeToggle.js +5 -4
- package/dist/ui-public/src/lists/Table/cells/LinkCell.d.ts +1 -1
- package/dist/ui-public/src/lists/TreeRow/Action.d.ts +1 -1
- package/dist/ui-public/src/lists/TreeRow/Action.js +1 -1
- package/dist/ui-public/src/lists/TreeRow/Link.d.ts +1 -1
- package/dist/ui-public/src/lists/TreeRow/Link.js +1 -1
- package/dist/ui-public/src/lists/UploadCard.d.ts +66 -3
- package/dist/ui-public/src/lists/UploadCard.js +116 -7
- package/dist/ui-public/src/lists/UserRow.d.ts +122 -0
- package/dist/ui-public/src/lists/UserRow.js +104 -0
- package/dist/ui-public/src/lists/dnd/DragHandle.d.ts +2 -2
- package/dist/ui-public/src/lists/dnd/SortableList.d.ts +1 -1
- package/dist/ui-public/src/lists/dnd/dropTargetClassName.d.ts +1 -1
- package/dist/ui-public/src/lists/dnd/tree/SortableTree.d.ts +2 -2
- package/dist/ui-public/src/navigation/Chevron.d.ts +4 -4
- package/dist/ui-public/src/navigation/Chevron.js +1 -1
- package/dist/ui-public/src/navigation/Link.d.ts +5 -5
- package/dist/ui-public/src/navigation/Link.js +1 -1
- package/dist/ui-public/src/navigation/NavList.d.ts +1 -1
- package/dist/ui-public/src/navigation/NavList.js +1 -1
- package/dist/ui-public/src/navigation/NavigationProvider.d.ts +1 -1
- package/dist/ui-public/src/navigation/SegmentedControl.d.ts +2 -2
- package/dist/ui-public/src/navigation/SettingsMenu.d.ts +8 -8
- package/dist/ui-public/src/navigation/SettingsMenu.js +1 -1
- package/dist/ui-public/src/navigation/SidebarTree/SidebarTreeNode.d.ts +4 -4
- package/dist/ui-public/src/overlays/FullscreenModal/TitleContext.d.ts +1 -1
- package/dist/ui-public/src/overlays/FullscreenModal/TitleContext.js +1 -1
- package/dist/ui-public/src/overlays/NewZIndex.d.ts +1 -1
- package/dist/ui-public/src/overlays/NewZIndex.js +1 -1
- package/dist/ui-public/src/overlays/Popover.d.ts +1 -1
- package/dist/ui-public/src/overlays/PortalWrapper.js +1 -1
- package/dist/ui-public/src/overlays/useModalClose.js +3 -3
- package/dist/ui-public/src/patterns/ListDetail/FloatingDetail.js +2 -2
- package/dist/ui-public/src/patterns/ListDetail/Page.d.ts +8 -9
- package/dist/ui-public/src/patterns/ListDetail/Page.js +4 -5
- package/dist/ui-public/src/patterns/ListDetail/Panel.d.ts +2 -2
- package/dist/ui-public/src/patterns/ListDetail/Panel.js +1 -1
- package/dist/ui-public/src/patterns/ListDetail/Split.d.ts +9 -10
- package/dist/ui-public/src/patterns/ListDetail/Split.js +5 -5
- package/dist/ui-public/src/patterns/ListFormPage.d.ts +3 -3
- package/dist/ui-public/src/patterns/ListFormPage.js +1 -1
- package/dist/ui-public/src/semantic/Heading.d.ts +1 -1
- package/dist/ui-public/src/semantic/Heading.js +1 -1
- package/dist/ui-public/src/semantic/Image.js +1 -1
- package/dist/ui-public/src/semantic/Nav.d.ts +3 -3
- package/dist/ui-public/src/semantic/Nav.js +3 -3
- package/dist/ui-public/src/semantic/RawButton.d.ts +3 -3
- package/dist/ui-public/src/semantic/RawButton.js +1 -1
- package/dist/ui-public/src/semantic/Search.d.ts +1 -1
- package/dist/ui-public/src/semantic/Search.js +1 -1
- package/dist/ui-public/src/utils/fieldTypes.d.ts +29 -0
- package/dist/ui-public/src/utils/fieldTypes.js +94 -0
- package/dist/ui-public/src/utils/format.d.ts +21 -0
- package/dist/ui-public/src/utils/format.js +20 -0
- package/dist/ui-public/src/utils/formatDate.d.ts +10 -2
- package/dist/ui-public/src/utils/formatDate.js +4 -4
- package/dist/ui-public/src/utils/tickBatcher.js +44 -0
- package/dist/ui-public/src/utils/timezones.js +277 -0
- package/dist/ui-public/src/utils/weekStartForLocale.js +25 -0
- package/dist/utils/fieldTypes.d.ts +1 -0
- package/dist/utils/fieldTypes.js +2 -0
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.js +2 -0
- package/package.json +2 -2
- package/dist/ui-public/icons/custom/fieldgroup-boolean.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-color.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-datetime.js +0 -49
- package/dist/ui-public/icons/custom/fieldgroup-json.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-location.js +0 -19
- package/dist/ui-public/icons/custom/fieldgroup-media.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-number.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-reference.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-rich_text.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-seo.js +0 -22
- package/dist/ui-public/icons/custom/fieldgroup-structured_text.js +0 -61
- package/dist/ui-public/icons/lucide/receipt.js +0 -26
|
@@ -7,7 +7,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
/**
|
|
8
8
|
* The title of a toolbar that opens a menu. Use it only for a menu that
|
|
9
9
|
* switches the view of the same list (see Toolbar.PresetsTitle), never for actions
|
|
10
|
-
* on the thing that the title names. The chevron always shows,
|
|
10
|
+
* on the thing that the title names. The chevron always shows, so the
|
|
11
11
|
* user sees that the title opens a menu.
|
|
12
12
|
*/
|
|
13
13
|
function ToolbarTitleTrigger({ onTrigger, label, open }) {
|
|
@@ -26,7 +26,7 @@ export type CardListProps = {
|
|
|
26
26
|
/** The button that adds an item, in the footer of the card */
|
|
27
27
|
add?: ActionOrMenu;
|
|
28
28
|
/**
|
|
29
|
-
* Shows
|
|
29
|
+
* Shows instead of the card when the card has no items (for example an
|
|
30
30
|
* EmptySlot with the button that adds the first item)
|
|
31
31
|
*/
|
|
32
32
|
empty?: ReactNode;
|
|
@@ -66,7 +66,7 @@ export type CardListRow = {
|
|
|
66
66
|
/**
|
|
67
67
|
* The actions of the item (an icon button, a menu, a "Change" button).
|
|
68
68
|
* They go in a column with the width of a micro icon button at least,
|
|
69
|
-
*
|
|
69
|
+
* so the icon actions of all the items align.
|
|
70
70
|
*/
|
|
71
71
|
actions?: ReactNode;
|
|
72
72
|
};
|
|
@@ -99,7 +99,7 @@ type ItemWithoutRow = {
|
|
|
99
99
|
expandable?: never;
|
|
100
100
|
};
|
|
101
101
|
/**
|
|
102
|
-
* The other props go to the `li`,
|
|
102
|
+
* The other props go to the `li`, so the item can be the trigger of a
|
|
103
103
|
* Tooltip for the whole row
|
|
104
104
|
*/
|
|
105
105
|
type ItemElementProps = Omit<React.HTMLAttributes<HTMLLIElement>, 'children' | 'className'>;
|
|
@@ -3,7 +3,7 @@ import { type Message } from '../Message.js';
|
|
|
3
3
|
import { type ActionOrMenu } from './ActionOrMenu.js';
|
|
4
4
|
type EmptySlotAction =
|
|
5
5
|
/**
|
|
6
|
-
* The actions show
|
|
6
|
+
* The actions show instead of the message when the pointer is on the
|
|
7
7
|
* slot, when an action has the focus or when its menu is open. On a touch
|
|
8
8
|
* device, they always show.
|
|
9
9
|
*/
|
|
@@ -7,7 +7,7 @@ export type InfoListUserProps = {
|
|
|
7
7
|
user: InfoListUserData;
|
|
8
8
|
/**
|
|
9
9
|
* A text about the user, for example the type of the user. It goes in a
|
|
10
|
-
* tooltip
|
|
10
|
+
* tooltip on the left, so the text does not wrap in a narrow column.
|
|
11
11
|
* Without it, there is no tooltip.
|
|
12
12
|
*/
|
|
13
13
|
tooltip?: Message;
|
|
@@ -14,7 +14,7 @@ export type InfoListValueTriggerProps = {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* A value in a row of an InfoList, that the user cannot change. It has the
|
|
17
|
-
* same look as `InfoList.Value.Trigger`,
|
|
17
|
+
* same look as `InfoList.Value.Trigger`, so the values of the rows align.
|
|
18
18
|
*/
|
|
19
19
|
declare function Value({ label }: InfoListValueProps): React.JSX.Element;
|
|
20
20
|
/**
|
|
@@ -6,7 +6,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
//#region ../ui-public/src/lists/InfoList/Value.tsx
|
|
7
7
|
/**
|
|
8
8
|
* A value in a row of an InfoList, that the user cannot change. It has the
|
|
9
|
-
* same look as `InfoList.Value.Trigger`,
|
|
9
|
+
* same look as `InfoList.Value.Trigger`, so the values of the rows align.
|
|
10
10
|
*/
|
|
11
11
|
function Value({ label }) {
|
|
12
12
|
const { tc } = useTranslation();
|
|
@@ -9,15 +9,15 @@ export type InfoListProps = {
|
|
|
9
9
|
};
|
|
10
10
|
declare function BaseInfoList({ className, children }: InfoListProps): React.JSX.Element;
|
|
11
11
|
export type InfoListRowProps = {
|
|
12
|
-
/** The name of the fact,
|
|
12
|
+
/** The name of the fact, on the left */
|
|
13
13
|
title: Message;
|
|
14
14
|
/**
|
|
15
|
-
* The value,
|
|
15
|
+
* The value, on the right. A short note about the value goes under it, in
|
|
16
16
|
* the value.
|
|
17
17
|
*/
|
|
18
18
|
children: ReactNode;
|
|
19
19
|
};
|
|
20
|
-
/** A line with a title
|
|
20
|
+
/** A line with a title on the left and its value on the right. */
|
|
21
21
|
declare function Row({ title, children }: InfoListRowProps): React.JSX.Element;
|
|
22
22
|
export type InfoListGroupProps = {
|
|
23
23
|
/**
|
|
@@ -16,7 +16,7 @@ function BaseInfoList({ className, children }) {
|
|
|
16
16
|
children
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
/** A line with a title
|
|
19
|
+
/** A line with a title on the left and its value on the right. */
|
|
20
20
|
function Row({ title, children }) {
|
|
21
21
|
const { tc } = useTranslation();
|
|
22
22
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -5,7 +5,7 @@ import { SvgIcon } from '../utils/types.js';
|
|
|
5
5
|
export type MediaCardAction = {
|
|
6
6
|
/**
|
|
7
7
|
* The key of the action. Give it when the label changes, for example
|
|
8
|
-
* "Play" and "Pause".
|
|
8
|
+
* "Play" and "Pause". So the button keeps the keyboard focus.
|
|
9
9
|
*/
|
|
10
10
|
id?: string;
|
|
11
11
|
/** The text of the button or of the menu option. */
|
|
@@ -38,7 +38,7 @@ export type MediaCardOption = MediaCardOptionBase & ({
|
|
|
38
38
|
action?: never;
|
|
39
39
|
} | {
|
|
40
40
|
/**
|
|
41
|
-
* The id of an action of the registry (`
|
|
41
|
+
* The id of an action of the registry (`Actions`). The option
|
|
42
42
|
* runs it and shows its keys.
|
|
43
43
|
*/
|
|
44
44
|
action: string;
|
|
@@ -60,10 +60,10 @@ export type MediaCardCaption = {
|
|
|
60
60
|
*/
|
|
61
61
|
muted?: boolean;
|
|
62
62
|
};
|
|
63
|
-
/** A click on the media opens a page of
|
|
63
|
+
/** A click on the media opens a page of DatoCMS. */
|
|
64
64
|
type LinkCard = {
|
|
65
65
|
/**
|
|
66
|
-
* The page that the card opens. The media is a link,
|
|
66
|
+
* The page that the card opens. The media is a link, so the user can
|
|
67
67
|
* open the page in a new tab.
|
|
68
68
|
*/
|
|
69
69
|
to: string;
|
|
@@ -121,11 +121,11 @@ export type MediaCardSelection = {
|
|
|
121
121
|
*/
|
|
122
122
|
onSelect?: () => void;
|
|
123
123
|
};
|
|
124
|
-
/** The caption has a checkbox,
|
|
124
|
+
/** The caption has a checkbox, so it has no `captionAction`. */
|
|
125
125
|
type CheckboxCaption = {
|
|
126
126
|
selection: MediaCardSelection & {
|
|
127
127
|
/**
|
|
128
|
-
* The checkbox
|
|
128
|
+
* The checkbox on the right of the caption. Its name is the caption.
|
|
129
129
|
* "hover" shows it when the pointer is on the card, when the card has
|
|
130
130
|
* the focus, when the card is selected and on a touch screen. "always"
|
|
131
131
|
* shows it in all cases, for example when the user has selected a card.
|
|
@@ -139,7 +139,7 @@ type PlainCaption = {
|
|
|
139
139
|
selection?: MediaCardSelection & {
|
|
140
140
|
checkbox?: never;
|
|
141
141
|
};
|
|
142
|
-
/** An action
|
|
142
|
+
/** An action on the right of the caption, for example the cross that cancels an upload. */
|
|
143
143
|
captionAction?: React.ReactNode;
|
|
144
144
|
};
|
|
145
145
|
export type MediaCardProps = MediaCardBaseProps & (LinkCard | ClickCard | StaticCard) & (CheckboxCaption | PlainCaption);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The image of a record. "image" is a picture to show in the square, cut to
|
|
4
|
+
* fill it. "file" is a file that is not a picture: the square shows the icon
|
|
5
|
+
* of its extension.
|
|
6
|
+
*/
|
|
7
|
+
export type RecordRowImage = {
|
|
8
|
+
type: 'image';
|
|
9
|
+
url: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'file';
|
|
12
|
+
extension: string;
|
|
13
|
+
};
|
|
14
|
+
export type RecordRowImageProps = {
|
|
15
|
+
/** The image of the record. Without it, the square is a muted placeholder. */
|
|
16
|
+
image: RecordRowImage | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The image of a record in a square that its container sizes. The image of
|
|
20
|
+
* a `RecordRow`, also alone in a cell or a chip.
|
|
21
|
+
*/
|
|
22
|
+
declare function Image({ image }: RecordRowImageProps): React.JSX.Element;
|
|
23
|
+
declare const _default: React.MemoExoticComponent<typeof Image>;
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import FileTypeIcon from "../../content/FileTypeIcon.js";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region ../ui-public/src/lists/RecordRow/Image.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The image of a record in a square that its container sizes. The image of
|
|
8
|
+
* a `RecordRow`, also alone in a cell or a chip.
|
|
9
|
+
*/
|
|
10
|
+
function Image({ image }) {
|
|
11
|
+
if (image?.type === "file") return /* @__PURE__ */ jsx(FileTypeIcon, {
|
|
12
|
+
extension: image.extension,
|
|
13
|
+
className: "RecordRow__image"
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsx("div", {
|
|
16
|
+
className: classNames("RecordRow__image", { "RecordRow__image--placeholder": !image }),
|
|
17
|
+
style: image ? { backgroundImage: `url(${image.url})` } : void 0
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
var Image_default = React.memo(Image);
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Image_default as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
export type RecordRowListProps = {
|
|
3
|
+
/**
|
|
4
|
+
* The rows show the model above the title. Give false when all the
|
|
5
|
+
* records have the same model.
|
|
6
|
+
* @default true
|
|
7
|
+
*/
|
|
8
|
+
showModel?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* All the rows show the image slot from the start, before a row with an
|
|
11
|
+
* image loads. Use it when a model of the rows has an image, in a list
|
|
12
|
+
* with many records of the same models.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
reserveImageSlot?: boolean;
|
|
16
|
+
/** The rows */
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Put it around the rows of records of a list that are one above the other.
|
|
21
|
+
* It renders no element: it gives the rows the same settings, so that they
|
|
22
|
+
* look the same. When one row has an image, all the rows show the image
|
|
23
|
+
* slot, so that the titles align.
|
|
24
|
+
*/
|
|
25
|
+
declare function List({ showModel, reserveImageSlot, children, }: RecordRowListProps): React.JSX.Element;
|
|
26
|
+
export default List;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RecordRowListContext } from "./context.js";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region ../ui-public/src/lists/RecordRow/List.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Put it around the rows of records of a list that are one above the other.
|
|
7
|
+
* It renders no element: it gives the rows the same settings, so that they
|
|
8
|
+
* look the same. When one row has an image, all the rows show the image
|
|
9
|
+
* slot, so that the titles align.
|
|
10
|
+
*/
|
|
11
|
+
function List({ showModel = true, reserveImageSlot = false, children }) {
|
|
12
|
+
const [imageSlot, setImageSlot] = useState(reserveImageSlot);
|
|
13
|
+
const previousReserve = useRef(reserveImageSlot);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (previousReserve.current === reserveImageSlot) return;
|
|
16
|
+
previousReserve.current = reserveImageSlot;
|
|
17
|
+
setImageSlot(reserveImageSlot);
|
|
18
|
+
}, [reserveImageSlot]);
|
|
19
|
+
const value = useMemo(() => ({
|
|
20
|
+
showModel,
|
|
21
|
+
imageSlot,
|
|
22
|
+
showImageSlot: () => setImageSlot(true)
|
|
23
|
+
}), [showModel, imageSlot]);
|
|
24
|
+
return /* @__PURE__ */ jsx(RecordRowListContext.Provider, {
|
|
25
|
+
value,
|
|
26
|
+
children
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { List as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect } from "react";
|
|
2
|
+
//#region ../ui-public/src/lists/RecordRow/context.tsx
|
|
3
|
+
var RecordRowListContext = createContext({
|
|
4
|
+
showModel: true,
|
|
5
|
+
imageSlot: false,
|
|
6
|
+
showImageSlot: () => {}
|
|
7
|
+
});
|
|
8
|
+
/** False when the `RecordRow.List` around hides the model of its rows */
|
|
9
|
+
function useRecordRowsShowModel() {
|
|
10
|
+
return useContext(RecordRowListContext).showModel;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Tells if a row of a `RecordRow.List` shows the image slot. A row with an
|
|
14
|
+
* image shows it, and makes all the rows of the list show it, so that the
|
|
15
|
+
* titles align. A `standalone` record (a chip) shows the slot only when it
|
|
16
|
+
* has an image, and does not change the rows.
|
|
17
|
+
*/
|
|
18
|
+
function useRecordRowImageSlot(hasImage, standalone = false) {
|
|
19
|
+
const { imageSlot, showImageSlot } = useContext(RecordRowListContext);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!standalone && hasImage && !imageSlot) showImageSlot();
|
|
22
|
+
}, [
|
|
23
|
+
standalone,
|
|
24
|
+
hasImage,
|
|
25
|
+
imageSlot,
|
|
26
|
+
showImageSlot
|
|
27
|
+
]);
|
|
28
|
+
return hasImage || !standalone && imageSlot;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { RecordRowListContext, useRecordRowImageSlot, useRecordRowsShowModel };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type RecordRowImage } from './Image.js';
|
|
3
|
+
import List from './List.js';
|
|
4
|
+
import type { RecordRowItem, RecordRowModel, RecordRowPresentation } from './types.js';
|
|
5
|
+
export type { RecordRowImageProps } from './Image.js';
|
|
6
|
+
export type { RecordRowListProps } from './List.js';
|
|
7
|
+
export type { RecordRowImage, RecordRowItem, RecordRowModel, RecordRowPresentation, };
|
|
8
|
+
type Content =
|
|
9
|
+
/** The data of the record, already resolved */
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* The data of the record, for example a result of
|
|
13
|
+
* `ctx.loadItemPresentationInfo`
|
|
14
|
+
*/
|
|
15
|
+
presentation: RecordRowPresentation;
|
|
16
|
+
/**
|
|
17
|
+
* The model of the record. The row shows its name above the title,
|
|
18
|
+
* and the status only when it has the draft mode. Without it, the row
|
|
19
|
+
* reads the model of `presentation.itemTypeId` from the host.
|
|
20
|
+
*/
|
|
21
|
+
model?: RecordRowModel | null;
|
|
22
|
+
item?: never;
|
|
23
|
+
preferredLocale?: never;
|
|
24
|
+
}
|
|
25
|
+
/** The record: the row loads its data from the host */
|
|
26
|
+
| {
|
|
27
|
+
/**
|
|
28
|
+
* The ID of the record, or the record. The row loads its presentation
|
|
29
|
+
* once, and again when `item` changes: it does not show the changes
|
|
30
|
+
* that somebody makes to the record later. While it loads, it shows a
|
|
31
|
+
* placeholder in place of the title, and the model and the status of
|
|
32
|
+
* a full record.
|
|
33
|
+
*/
|
|
34
|
+
item: string | RecordRowItem;
|
|
35
|
+
/** The locale of the title and of the image */
|
|
36
|
+
preferredLocale?: string;
|
|
37
|
+
presentation?: never;
|
|
38
|
+
model?: never;
|
|
39
|
+
};
|
|
40
|
+
type Layout = {
|
|
41
|
+
/**
|
|
42
|
+
* "row" shows the model above the title: a row of a list, an option
|
|
43
|
+
* of a menu.
|
|
44
|
+
*/
|
|
45
|
+
layout: 'row';
|
|
46
|
+
/**
|
|
47
|
+
* More lines below the title, small and in the subtle ink. For example
|
|
48
|
+
* the parents of the record, or the users that edit it.
|
|
49
|
+
*/
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
} | {
|
|
52
|
+
/**
|
|
53
|
+
* "inline" shows one line: a chip, the value of a select, a record in
|
|
54
|
+
* a text. It has no model and no lines below the title.
|
|
55
|
+
*/
|
|
56
|
+
layout: 'inline';
|
|
57
|
+
children?: never;
|
|
58
|
+
};
|
|
59
|
+
type Common = {
|
|
60
|
+
/**
|
|
61
|
+
* Shows the ID of the record. For example when the ID matches the text of
|
|
62
|
+
* a search.
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
showId?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The title shows on up to three lines, not on one line. Only for a list
|
|
68
|
+
* of records that is wide enough.
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
multilineTitle?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The row ignores the `RecordRow.List` around it (for example a chip of a
|
|
74
|
+
* select, when the list is the options of the menu). It shows an image
|
|
75
|
+
* only when it has one, and does not change the rows.
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
standalone?: boolean;
|
|
79
|
+
};
|
|
80
|
+
export type RecordRowProps = Content & Layout & Common;
|
|
81
|
+
/**
|
|
82
|
+
* A record in a row: the image, the model, the title, the validity
|
|
83
|
+
* triangles and the status, always in the same order and with the same
|
|
84
|
+
* sizes. It shows only the content: its container gives the surface, the
|
|
85
|
+
* hover and the click.
|
|
86
|
+
*/
|
|
87
|
+
declare function RecordRow(props: RecordRowProps): React.JSX.Element;
|
|
88
|
+
declare const _default: React.NamedExoticComponent<RecordRowProps> & {
|
|
89
|
+
readonly type: typeof RecordRow;
|
|
90
|
+
} & {
|
|
91
|
+
Image: React.MemoExoticComponent<({ image }: import("./Image.js").RecordRowImageProps) => React.JSX.Element>;
|
|
92
|
+
List: typeof List;
|
|
93
|
+
};
|
|
94
|
+
export default _default;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useTranslation } from "../../i18n.js";
|
|
2
|
+
import { useLoadedRecordPresentation, useRecordPresentationModel } from "./presentation.js";
|
|
3
|
+
import { ItemValidityTriangles } from "../../content/ValidityTriangles.js";
|
|
4
|
+
import EntityRow_default from "../EntityRow.js";
|
|
5
|
+
import IdText from "../../content/IdText.js";
|
|
6
|
+
import ItemStatus_default from "../../content/ItemStatus.js";
|
|
7
|
+
import { useRecordRowImageSlot, useRecordRowsShowModel } from "./context.js";
|
|
8
|
+
import Image_default from "./Image.js";
|
|
9
|
+
import List from "./List.js";
|
|
10
|
+
import React, { useMemo } from "react";
|
|
11
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
//#region ../ui-public/src/lists/RecordRow/index.tsx
|
|
13
|
+
var imageSizes = {
|
|
14
|
+
inline: 20,
|
|
15
|
+
row: 32
|
|
16
|
+
};
|
|
17
|
+
function PresentedRecordRow({ presentation, model: givenModel, layout, showId = false, multilineTitle, standalone, children }) {
|
|
18
|
+
const { t, tc } = useTranslation();
|
|
19
|
+
const modelOf = useRecordPresentationModel();
|
|
20
|
+
const { id, image, title, status, itemTypeId } = presentation;
|
|
21
|
+
const model = givenModel !== void 0 ? givenModel : itemTypeId ? modelOf(itemTypeId) : null;
|
|
22
|
+
const showImage = useRecordRowImageSlot(Boolean(image), standalone);
|
|
23
|
+
const showModel = useRecordRowsShowModel() && Boolean(model);
|
|
24
|
+
const idShown = showId && Boolean(id);
|
|
25
|
+
const common = {
|
|
26
|
+
multilineTitle,
|
|
27
|
+
image: showImage && /* @__PURE__ */ jsx(Image_default, { image }),
|
|
28
|
+
title,
|
|
29
|
+
afterTitle: /* @__PURE__ */ jsx(ItemValidityTriangles, {
|
|
30
|
+
currentValid: presentation.currentVersionValid,
|
|
31
|
+
publishedValid: presentation.publishedVersionValid,
|
|
32
|
+
draftModeActive: model?.draftModeActive
|
|
33
|
+
}),
|
|
34
|
+
trailing: model?.draftModeActive && status ? /* @__PURE__ */ jsx(ItemStatus_default, { status }) : void 0
|
|
35
|
+
};
|
|
36
|
+
if (layout === "inline") return /* @__PURE__ */ jsx(EntityRow_default, {
|
|
37
|
+
layout: "inline",
|
|
38
|
+
...common,
|
|
39
|
+
aside: idShown && id ? /* @__PURE__ */ jsx(IdText, {
|
|
40
|
+
id,
|
|
41
|
+
labeled: true
|
|
42
|
+
}) : void 0
|
|
43
|
+
});
|
|
44
|
+
return /* @__PURE__ */ jsx(EntityRow_default, {
|
|
45
|
+
layout: "row",
|
|
46
|
+
...common,
|
|
47
|
+
kicker: showModel || idShown ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
48
|
+
showModel && model && tc(model.name),
|
|
49
|
+
showModel && idShown && " ",
|
|
50
|
+
idShown && id && /* @__PURE__ */ jsxs(Fragment$1, { children: [!showModel && `${t("idText.label")} `, /* @__PURE__ */ jsx(IdText, {
|
|
51
|
+
id,
|
|
52
|
+
labeled: showModel
|
|
53
|
+
})] })
|
|
54
|
+
] }) : void 0,
|
|
55
|
+
children
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function LoadingTitle() {
|
|
59
|
+
const { t } = useTranslation();
|
|
60
|
+
return /* @__PURE__ */ jsx("span", {
|
|
61
|
+
className: "RecordRow__loading",
|
|
62
|
+
"aria-busy": "true",
|
|
63
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "visually-hidden",
|
|
65
|
+
children: t("recordRow.loading")
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function LoadedRecordRow({ item, preferredLocale, ...rest }) {
|
|
70
|
+
const { t } = useTranslation();
|
|
71
|
+
const size = imageSizes[rest.layout];
|
|
72
|
+
const options = useMemo(() => ({
|
|
73
|
+
preferredLocale,
|
|
74
|
+
preferredImageSize: {
|
|
75
|
+
width: size,
|
|
76
|
+
height: size
|
|
77
|
+
}
|
|
78
|
+
}), [preferredLocale, size]);
|
|
79
|
+
const loaded = useLoadedRecordPresentation(item, options);
|
|
80
|
+
const fullItem = typeof item === "string" ? null : item;
|
|
81
|
+
const id = typeof item === "string" ? item : item.id;
|
|
82
|
+
const presentation = loaded ? {
|
|
83
|
+
...loaded,
|
|
84
|
+
id
|
|
85
|
+
} : {
|
|
86
|
+
id,
|
|
87
|
+
title: loaded === null ? t("recordRow.fallbackTitle", { id }) : /* @__PURE__ */ jsx(LoadingTitle, {}),
|
|
88
|
+
image: null,
|
|
89
|
+
itemTypeId: fullItem?.relationships.item_type.data.id,
|
|
90
|
+
status: fullItem ? fullItem.meta.status ?? "published" : void 0,
|
|
91
|
+
currentVersionValid: fullItem?.meta.is_current_version_valid ?? void 0,
|
|
92
|
+
publishedVersionValid: fullItem?.meta.is_published_version_valid ?? void 0
|
|
93
|
+
};
|
|
94
|
+
return /* @__PURE__ */ jsx(PresentedRecordRow, {
|
|
95
|
+
...rest,
|
|
96
|
+
presentation
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A record in a row: the image, the model, the title, the validity
|
|
101
|
+
* triangles and the status, always in the same order and with the same
|
|
102
|
+
* sizes. It shows only the content: its container gives the surface, the
|
|
103
|
+
* hover and the click.
|
|
104
|
+
*/
|
|
105
|
+
function RecordRow(props) {
|
|
106
|
+
if (props.item !== void 0) return /* @__PURE__ */ jsx(LoadedRecordRow, {
|
|
107
|
+
...props,
|
|
108
|
+
item: props.item
|
|
109
|
+
});
|
|
110
|
+
const { presentation, model, ...rest } = props;
|
|
111
|
+
return /* @__PURE__ */ jsx(PresentedRecordRow, {
|
|
112
|
+
...rest,
|
|
113
|
+
presentation,
|
|
114
|
+
model
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
var RecordRow_default = Object.assign(React.memo(RecordRow), {
|
|
118
|
+
Image: Image_default,
|
|
119
|
+
List
|
|
120
|
+
});
|
|
121
|
+
//#endregion
|
|
122
|
+
export { RecordRow_default as default };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createTickBatcher } from "../../utils/tickBatcher.js";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region ../ui-public/src/lists/RecordRow/presentation.tsx
|
|
5
|
+
var RecordPresentationContext = createContext({
|
|
6
|
+
request: async () => null,
|
|
7
|
+
model: () => null
|
|
8
|
+
});
|
|
9
|
+
function optionsKey(options) {
|
|
10
|
+
return JSON.stringify([
|
|
11
|
+
options.preferredLocale ?? null,
|
|
12
|
+
options.preferredImageSize?.width ?? null,
|
|
13
|
+
options.preferredImageSize?.height ?? null
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gives the loader of the presentation of records to the `RecordRow`s with
|
|
18
|
+
* `item`. The rows of one render ask for their records in the same tick:
|
|
19
|
+
* the provider sends them in one call to the loader, one call for each set
|
|
20
|
+
* of options. It keeps no cache, so a row that renders again with a new
|
|
21
|
+
* record asks again. A failed call gives null to its rows.
|
|
22
|
+
*/
|
|
23
|
+
function RecordPresentationProvider({ load, model, children }) {
|
|
24
|
+
const value = useMemo(() => ({
|
|
25
|
+
model,
|
|
26
|
+
request: createTickBatcher({
|
|
27
|
+
groupKey: optionsKey,
|
|
28
|
+
fallback: null,
|
|
29
|
+
load: async (options, itemsOrIds) => load ? load(itemsOrIds, options) : itemsOrIds.map(() => null)
|
|
30
|
+
})
|
|
31
|
+
}), [load, model]);
|
|
32
|
+
return /* @__PURE__ */ jsx(RecordPresentationContext.Provider, {
|
|
33
|
+
value,
|
|
34
|
+
children
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function useRecordPresentationModel() {
|
|
38
|
+
return useContext(RecordPresentationContext).model;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The presentation of a record from the loader of the provider. It is
|
|
42
|
+
* undefined while it loads, and null when the record does not exist or the
|
|
43
|
+
* loader failed. It loads again when the record changes, not when the record
|
|
44
|
+
* changes on the server.
|
|
45
|
+
*/
|
|
46
|
+
function useLoadedRecordPresentation(itemOrId, options) {
|
|
47
|
+
const { request } = useContext(RecordPresentationContext);
|
|
48
|
+
const [state, setState] = useState(null);
|
|
49
|
+
const key = `${typeof itemOrId === "string" ? itemOrId : JSON.stringify(itemOrId)}|${optionsKey(options)}`;
|
|
50
|
+
const latest = useRef({
|
|
51
|
+
itemOrId,
|
|
52
|
+
options
|
|
53
|
+
});
|
|
54
|
+
latest.current = {
|
|
55
|
+
itemOrId,
|
|
56
|
+
options
|
|
57
|
+
};
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
let active = true;
|
|
60
|
+
request(latest.current.options, latest.current.itemOrId).then((value) => {
|
|
61
|
+
if (active) setState({
|
|
62
|
+
key,
|
|
63
|
+
value
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
active = false;
|
|
68
|
+
};
|
|
69
|
+
}, [request, key]);
|
|
70
|
+
return state?.key === key ? state.value : void 0;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { RecordPresentationProvider, useLoadedRecordPresentation, useRecordPresentationModel };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Message } from '../../Message.js';
|
|
2
|
+
import type { RecordRowImage } from './Image.js';
|
|
3
|
+
/**
|
|
4
|
+
* The data of a record that the row shows. A result of
|
|
5
|
+
* `ctx.loadItemPresentationInfo` is a `RecordRowPresentation`.
|
|
6
|
+
*/
|
|
7
|
+
export type RecordRowPresentation = {
|
|
8
|
+
/**
|
|
9
|
+
* The ID of the record. A block that is not saved yet has no ID. The row
|
|
10
|
+
* shows it only with `showId`.
|
|
11
|
+
*/
|
|
12
|
+
id?: string;
|
|
13
|
+
/** The title of the record */
|
|
14
|
+
title: Message;
|
|
15
|
+
/** The image of the record, or null when the record has no image */
|
|
16
|
+
image: RecordRowImage | null;
|
|
17
|
+
/**
|
|
18
|
+
* The ID of the model of the record. Without `model`, the row reads the
|
|
19
|
+
* model from the host with this ID.
|
|
20
|
+
*/
|
|
21
|
+
itemTypeId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The publishing status of the record. The row shows it only when the
|
|
24
|
+
* model has the draft mode: without it, a record is published every time
|
|
25
|
+
* that it is saved, and the status says nothing.
|
|
26
|
+
*/
|
|
27
|
+
status?: 'draft' | 'updated' | 'published';
|
|
28
|
+
/** False when the current version of the record does not pass the validations */
|
|
29
|
+
currentVersionValid?: boolean;
|
|
30
|
+
/** False when the published version of the record does not pass the validations */
|
|
31
|
+
publishedVersionValid?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/** The model of the record */
|
|
34
|
+
export type RecordRowModel = {
|
|
35
|
+
/** The name of the model, with its emoji */
|
|
36
|
+
name: Message;
|
|
37
|
+
/** True when the model has the draft mode */
|
|
38
|
+
draftModeActive: boolean;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A record as the API gives it. The row reads only these fields, for the
|
|
42
|
+
* model, the status and the validity while the presentation loads.
|
|
43
|
+
*/
|
|
44
|
+
export type RecordRowItem = {
|
|
45
|
+
id: string;
|
|
46
|
+
relationships: {
|
|
47
|
+
item_type: {
|
|
48
|
+
data: {
|
|
49
|
+
id: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
meta: {
|
|
54
|
+
status?: 'draft' | 'updated' | 'published' | null;
|
|
55
|
+
is_current_version_valid?: boolean | null;
|
|
56
|
+
is_published_version_valid?: boolean | null;
|
|
57
|
+
};
|
|
58
|
+
};
|