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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQAumujy5kXaOKurr6zgTP2krHrFVXi2kj8seRYrlvq2GssUjReh5MiVpQbLFQNy9HsmcasqpBNVsXytWTw0ZDjA=

ActionToolbar

import { ActionToolbar, MenuBuilder, useMenuBuilder } from '@dxos/react-ui-menu';
Terminal window
npm install @dxos/react-ui-menu @effect/atom-react

ActionToolbar draws a list of actions as a toolbar. When the row is too narrow, it moves actions into an overflow menu.

An action is a label, an icon and the function it runs. You build the list with MenuBuilder and useMenuBuilder. Because the list is data, other code can add to it. This is how PLEX plugins add buttons to each other’s toolbars.

The actions live in an atom.

Wrap your app in RegistryProvider from @effect/atom-react. This is best practice, because your app then controls the registry that the toolbar reads. Without a provider, the toolbar reads the library’s default registry.

Add the package’s strings from @dxos/react-ui-menu/translations to the resourceExtensions of Theme.Provider.

Prop Type Effect
...menu MenuActions Sets the actions, from useMenuBuilder
onAction ActionExecutor The user ran an action. onAction runs it in place of the action’s own function
attendableId string Dims the toolbar while this surface lacks the user’s attention
alwaysActive boolean Keeps the toolbar from dimming
customActions Atom<ActionGraphProps> Sets actions another component adds to this toolbar
bounds HTMLElement | null Sets the box whose width the toolbar may fill. Its own frame by default

useMenuBuilder takes a function that builds the actions, and the values that function depends on.

  • Give an action iconOnly to show only its icon, with the label as its tooltip.
  • Give it placement: { zone: 'end' } to put it at the far end of the row.

Pass alwaysActive when the toolbar does not belong to a surface that tracks the user’s attention.

Example (Building a toolbar of three actions)

import {
function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
} from 'react';
import {
const ActionToolbar: React.ForwardRefExoticComponent<Omit<ActionToolbarProps, "className"> & {
classNames?: ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>

A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮, TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as custom items (MenuBuilder.custom), labels as text items.

ActionToolbar
,
const MenuBuilder: Readonly<{
make: () => MenuBuilder;
extend: (groupId: string, cb: ActionGroupBuilderFn) => ActionGraphProps;
}>

Top-level builder that creates the root group and produces the final action graph.

MenuBuilder
,
const useMenuBuilder: (build: (get: AtomContext) => ActionGraphProps, deps: React.DependencyList, options?: MenuActionsOptions) => MenuActions

Convenience wrapper around useMenuActions that creates the backing atom inline. Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when the action graph is composed from local state (e.g. a toolbar driven by component state).

Read reactive state via get inside the builder; deps should hold only stable references.

useMenuBuilder
} from '@dxos/react-ui-menu';
import * as
import Typography
Typography
from '@dxos/react-ui/Typography';
/** A toolbar built from actions: each action is a label, an icon and the function it runs. */
export const
const FormatToolbar: () => React.JSX.Element

A toolbar built from actions: each action is a label, an icon and the function it runs.

FormatToolbar
= () => {
const [
const last: string | undefined
last
,
const setLast: React.Dispatch<React.SetStateAction<string | undefined>>
setLast
] =
useState<string>(): [string | undefined, React.Dispatch<React.SetStateAction<string | undefined>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
<string>();
const
const menu: MenuActions
menu
=
function useMenuBuilder(build: (get: AtomContext) => ActionGraphProps, deps: React.DependencyList, options?: MenuActionsOptions): MenuActions

Convenience wrapper around useMenuActions that creates the backing atom inline. Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when the action graph is composed from local state (e.g. a toolbar driven by component state).

Read reactive state via get inside the builder; deps should hold only stable references.

useMenuBuilder
(
() =>
const MenuBuilder: Readonly<{
make: () => MenuBuilder;
extend: (groupId: string, cb: ActionGroupBuilderFn) => ActionGraphProps;
}>

Top-level builder that creates the root group and produces the final action graph.

MenuBuilder
.
make: () => MenuBuilder
make
()
.
ActionGroupBuilder.action<{
label: string;
icon: string;
iconOnly: true;
}>(id: string, props: {
label: string;
icon: string;
iconOnly: true;
} & MenuItemChrome & {
variant?: "action" | "primary" | "toggle" | "switch" | "custom" | "text";
value?: string;
checked?: boolean;
indent?: number;
render?: (props: CustomRenderProps) => React.ReactNode;
} & {
presentation?: Partial<Record<string, Partial<MenuActionChrome>>>;
}, invoke: () => void): MenuBuilder

Add an action node as a child of the current group.

action
(
'bold',
{
label: string & Label
label
: 'Bold',
icon: string
icon
: 'ph--text-b--regular',
iconOnly: true
iconOnly
: true },
() =>
const setLast: (value: React.SetStateAction<string | undefined>) => void
setLast
('Bold'),
)
.
ActionGroupBuilder.action<{
label: string;
icon: string;
iconOnly: true;
}>(id: string, props: {
label: string;
icon: string;
iconOnly: true;
} & MenuItemChrome & {
variant?: "action" | "primary" | "toggle" | "switch" | "custom" | "text";
value?: string;
checked?: boolean;
indent?: number;
render?: (props: CustomRenderProps) => React.ReactNode;
} & {
presentation?: Partial<Record<string, Partial<MenuActionChrome>>>;
}, invoke: () => void): MenuBuilder

Add an action node as a child of the current group.

action
(
'italic',
{
label: string & Label
label
: 'Italic',
icon: string
icon
: 'ph--text-italic--regular',
iconOnly: true
iconOnly
: true },
() =>
const setLast: (value: React.SetStateAction<string | undefined>) => void
setLast
('Italic'),
)
.
ActionGroupBuilder.separator(variant?: "gap" | "line"): MenuBuilder

Add a separator.

separator
('line')
.
ActionGroupBuilder.action<{
label: string;
icon: string;
placement: {
zone: "end";
};
}>(id: string, props: {
label: string;
icon: string;
placement: {
zone: "end";
};
} & MenuItemChrome & {
variant?: "action" | "primary" | "toggle" | "switch" | "custom" | "text";
value?: string;
checked?: boolean;
indent?: number;
render?: (props: CustomRenderProps) => React.ReactNode;
} & {
presentation?: Partial<Record<string, Partial<MenuActionChrome>>>;
}, invoke: () => void): MenuBuilder

Add an action node as a child of the current group.

action
(
'share',
{
label: string & Label
label
: 'Share',
icon: string
icon
: 'ph--share-network--regular',
placement: {
zone: "end";
} & ToolbarPlacement

Toolbar layout; ignored when the item renders in a menu.

placement
: {
zone: "end"

Left or right of its row (default start).

zone
: 'end' },
},
() =>
const setLast: (value: React.SetStateAction<string | undefined>) => void
setLast
('Share'),
)
.
MenuBuilder.build(): ActionGraphProps

Return the assembled action graph.

build
(),
[],
);
return (
<>
<
const ActionToolbar: React.ForwardRefExoticComponent<Omit<ActionToolbarProps, "className"> & {
classNames?: ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>

A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮, TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as custom items (MenuBuilder.custom), labels as text items.

ActionToolbar
{...
const menu: MenuActions
menu
}
alwaysActive?: boolean | undefined
alwaysActive
/>
<
import Typography
Typography
.
const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {
asChild?: boolean;
}, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLParagraphElement>>
export Text

Text whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a <p>; asChild puts the metrics on a heading or other text element instead.

Text
tone?: Typography.TextTone | undefined

Emphasis below the default (DESIGN.md "Text emphasis"): description for secondary content, subdued for interface text.

tone
='muted'>
{
const last: string | undefined
last
? `Ran ${
const last: string
last
}` : 'Nothing run yet'}
</
import Typography
Typography
.
const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {
asChild?: boolean;
}, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLParagraphElement>>
export Text

Text whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a <p>; asChild puts the metrics on a heading or other text element instead.

Text
>
</>
);
};

iconOnly leaves Bold and Italic as icons, and placement puts Share at the far end of the row. Each action’s function records its name in state, and the text under the toolbar shows the last one run.

A switch shows whether something is on. Pass the state as checked, and list it in the dependencies, so useMenuBuilder rebuilds the actions when the state changes.

Example (Showing word wrap as a switch)

import {
function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
} from 'react';
import {
const ActionToolbar: React.ForwardRefExoticComponent<Omit<ActionToolbarProps, "className"> & {
classNames?: ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>

A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮, TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as custom items (MenuBuilder.custom), labels as text items.

ActionToolbar
,
const MenuBuilder: Readonly<{
make: () => MenuBuilder;
extend: (groupId: string, cb: ActionGroupBuilderFn) => ActionGraphProps;
}>

Top-level builder that creates the root group and produces the final action graph.

MenuBuilder
,
const useMenuBuilder: (build: (get: AtomContext) => ActionGraphProps, deps: React.DependencyList, options?: MenuActionsOptions) => MenuActions

Convenience wrapper around useMenuActions that creates the backing atom inline. Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when the action graph is composed from local state (e.g. a toolbar driven by component state).

Read reactive state via get inside the builder; deps should hold only stable references.

useMenuBuilder
} from '@dxos/react-ui-menu';
/** A switch shows its state in the toolbar; the deps rebuild the actions when the state changes. */
export const
const ViewToolbar: () => React.JSX.Element

A switch shows its state in the toolbar; the deps rebuild the actions when the state changes.

ViewToolbar
= () => {
const [
const wrap: boolean
wrap
,
const setWrap: React.Dispatch<React.SetStateAction<boolean>>
setWrap
] =
useState<boolean>(initialState: boolean | (() => boolean)): [boolean, React.Dispatch<React.SetStateAction<boolean>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
(false);
const
const menu: MenuActions
menu
=
function useMenuBuilder(build: (get: AtomContext) => ActionGraphProps, deps: React.DependencyList, options?: MenuActionsOptions): MenuActions

Convenience wrapper around useMenuActions that creates the backing atom inline. Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when the action graph is composed from local state (e.g. a toolbar driven by component state).

Read reactive state via get inside the builder; deps should hold only stable references.

useMenuBuilder
(
() =>
const MenuBuilder: Readonly<{
make: () => MenuBuilder;
extend: (groupId: string, cb: ActionGroupBuilderFn) => ActionGraphProps;
}>

Top-level builder that creates the root group and produces the final action graph.

MenuBuilder
.
make: () => MenuBuilder
make
()
.
ActionGroupBuilder.switch(id: string, props: Omit<MenuActionProperties, "variant"> & {
checked: boolean;
}, invoke: () => void): MenuBuilder

Add a switch action rendered as a labeled Field.Switch.

switch
('wrap', {
label: Label
label
: 'Word wrap',
checked: boolean
checked
:
const wrap: boolean
wrap
}, () =>
const setWrap: (value: React.SetStateAction<boolean>) => void
setWrap
((
wrap: boolean
wrap
) => !
wrap: boolean
wrap
),
)
.
MenuBuilder.build(): ActionGraphProps

Return the assembled action graph.

build
(),
[
const wrap: boolean
wrap
],
);
return <
const ActionToolbar: React.ForwardRefExoticComponent<Omit<ActionToolbarProps, "className"> & {
classNames?: ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>

A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮, TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as custom items (MenuBuilder.custom), labels as text items.

ActionToolbar
{...
const menu: MenuActions
menu
}
alwaysActive?: boolean | undefined
alwaysActive
/>;
};

wrap is both the switch’s checked value and the one dependency, and the switch’s function flips it.

In a PLEX plugin, other plugins add actions to an object’s node in App Graph. graphActions reads those actions from the graph, so you can add them to your toolbar.

  • Pass the surface’s attendableId, so the toolbar is active while its surface has the user’s attention.
  • Pass onAction to run a graph action. useActionRunner from @dxos/plugin-graph gives you one.

Example (Adding other plugins’ actions to a toolbar)

import * as
import Hooks
Hooks
from '@dxos/app-toolkit/Hooks';
import { type
type ActionExecutor = (action: MenuAction, params: InvokeProps) => void
ActionExecutor
,
const ActionToolbar: React.ForwardRefExoticComponent<Omit<ActionToolbarProps, "className"> & {
classNames?: ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>

A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮, TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as custom items (MenuBuilder.custom), labels as text items.

ActionToolbar
,
const MenuBuilder: Readonly<{
make: () => MenuBuilder;
extend: (groupId: string, cb: ActionGroupBuilderFn) => ActionGraphProps;
}>

Top-level builder that creates the root group and produces the final action graph.

MenuBuilder
,
const graphActions: (graph: ReadableGraph | undefined, get: AtomContext, nodeId: string | undefined, options?: GraphMenuOptions) => ActionGraphProps

Read a node's contributed actions from the app-graph as menu ActionGraphProps, for splicing into a hand-built toolbar via MenuBuilder.subgraph(graphActions(graph, get, nodeId)). Reactive: reads the graph's action atoms through get, so contributed actions appear/disappear as extensions update.

@idiom ― org.dxos.react-ui-menu.graphActionsToolbar applies: Splicing a node's app-graph-contributed toolbar actions into a hand-built object toolbar instead-of: Reading graph.actions(nodeId) and filtering/wiring nodes/edges by hand in every toolbar uses: graphActions, MenuBuilder , useMenuBuilder related: org.dxos.react-ui-menu.toolbarMenu

graphActions
,
const isToolbarAction: (action: ActionLike) => boolean

Filter for

graphActions

: keeps only actions a producer opted into the toolbar.

isToolbarAction
,
const useMenuBuilder: (build: (get: AtomContext) => ActionGraphProps, deps: React.DependencyList, options?: MenuActionsOptions) => MenuActions

Convenience wrapper around useMenuActions that creates the backing atom inline. Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when the action graph is composed from local state (e.g. a toolbar driven by component state).

Read reactive state via get inside the builder; deps should hold only stable references.

useMenuBuilder
} from '@dxos/react-ui-menu';
/**
* In a plugin, the toolbar also shows the actions other plugins add to the object's node in App Graph.
* `onAction` runs a graph action. Get one from `useActionRunner` in `@dxos/plugin-graph`.
*/
export const
const ObjectToolbar: ({ attendableId, onAction, }: {
attendableId: string;
onAction: ActionExecutor;
}) => React.JSX.Element

In a plugin, the toolbar also shows the actions other plugins add to the object's node in App Graph. onAction runs a graph action. Get one from useActionRunner in @dxos/plugin-graph.

ObjectToolbar
= ({
attendableId: string
attendableId
,
onAction: ActionExecutor
onAction
,
}: {
attendableId: string
attendableId
: string;
onAction: ActionExecutor
onAction
:
type ActionExecutor = (action: MenuAction, params: InvokeProps) => void
ActionExecutor
;
}) => {
const {
const graph: ExpandableGraph
graph
} =
import Hooks
Hooks
.
const useAppGraph: () => AppGraph

Hook to get the current app graph.

useAppGraph
();
const
const menu: MenuActions
menu
=
function useMenuBuilder(build: (get: AtomContext) => ActionGraphProps, deps: React.DependencyList, options?: MenuActionsOptions): MenuActions

Convenience wrapper around useMenuActions that creates the backing atom inline. Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when the action graph is composed from local state (e.g. a toolbar driven by component state).

Read reactive state via get inside the builder; deps should hold only stable references.

useMenuBuilder
(
(
get: AtomContext
get
) =>
const MenuBuilder: Readonly<{
make: () => MenuBuilder;
extend: (groupId: string, cb: ActionGroupBuilderFn) => ActionGraphProps;
}>

Top-level builder that creates the root group and produces the final action graph.

MenuBuilder
.
make: () => MenuBuilder
make
()
.
ActionGroupBuilder.action<{
label: string;
icon: string;
}>(id: string, props: {
label: string;
icon: string;
} & MenuItemChrome & {
variant?: "action" | "primary" | "toggle" | "switch" | "custom" | "text";
value?: string;
checked?: boolean;
indent?: number;
render?: (props: CustomRenderProps) => React.ReactNode;
} & {
presentation?: Partial<Record<string, Partial<MenuActionChrome>>>;
}, invoke: () => void): MenuBuilder

Add an action node as a child of the current group.

action
(
'refresh',
{
label: string & Label
label
: 'Refresh',
icon: string
icon
: 'ph--arrow-clockwise--regular' },
() => {},
)
.
ActionGroupBuilder.subgraph(subgraphOrCb: ActionGraphProps | ActionGroupBuilderFn | false | null | undefined): MenuBuilder

Merge pre-built nodes and edges, or build a subgraph via callback scoped to the current group. Falsy values are ignored.

subgraph
(
function graphActions(graph: ReadableGraph | undefined, get: AtomContext, nodeId: string | undefined, options?: GraphMenuOptions): ActionGraphProps

Read a node's contributed actions from the app-graph as menu ActionGraphProps, for splicing into a hand-built toolbar via MenuBuilder.subgraph(graphActions(graph, get, nodeId)). Reactive: reads the graph's action atoms through get, so contributed actions appear/disappear as extensions update.

@idiom ― org.dxos.react-ui-menu.graphActionsToolbar applies: Splicing a node's app-graph-contributed toolbar actions into a hand-built object toolbar instead-of: Reading graph.actions(nodeId) and filtering/wiring nodes/edges by hand in every toolbar uses: graphActions, MenuBuilder , useMenuBuilder related: org.dxos.react-ui-menu.toolbarMenu

graphActions
(
const graph: ExpandableGraph
graph
,
get: AtomContext
get
,
attendableId: string
attendableId
, {
filter?: ((action: ActionLike) => boolean) | undefined

Keep only the actions the predicate accepts (e.g. by disposition).

filter
:
const isToolbarAction: (action: ActionLike) => boolean

Filter for

graphActions

: keeps only actions a producer opted into the toolbar.

isToolbarAction
}),
)
.
MenuBuilder.build(): ActionGraphProps

Return the assembled action graph.

build
(),
[
const graph: ExpandableGraph
graph
,
attendableId: string
attendableId
],
);
return (
<
const ActionToolbar: React.ForwardRefExoticComponent<Omit<ActionToolbarProps, "className"> & {
classNames?: ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>

A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮, TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as custom items (MenuBuilder.custom), labels as text items.

ActionToolbar
{...
const menu: MenuActions
menu
}
attendableId?: string | undefined

The toolbar is dimmed (still operable) while this attendable lacks attention, unless alwaysActive.

attendableId
={
attendableId: string
attendableId
}
onAction?: ActionExecutor | undefined
onAction
={
onAction: ActionExecutor
onAction
} />
);
};

ObjectToolbar has one action of its own, Refresh. subgraph adds the actions that graphActions reads from the graph, and isToolbarAction keeps the ones marked for the toolbar.