@cratis/components 4.41.5 → 4.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compat-manifest.json +11 -11
- package/dist/esm/Chat/Kit/AnchoredOverlay.d.ts +4 -3
- package/dist/esm/Chat/Kit/AnchoredOverlay.d.ts.map +1 -1
- package/dist/esm/Chat/Kit/AnchoredOverlay.js +15 -47
- package/dist/esm/Chat/Kit/AnchoredOverlay.js.map +1 -1
- package/dist/esm/Chat/Kit/OverlayPlacement.d.ts +7 -0
- package/dist/esm/Chat/Kit/OverlayPlacement.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/OverlayPlacement.js +4 -0
- package/dist/esm/Chat/Kit/OverlayPlacement.js.map +1 -0
- package/dist/esm/Chat/Kit/OverlayPlacementOptions.d.ts +3 -0
- package/dist/esm/Chat/Kit/OverlayPlacementOptions.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/OverlayPlacementOptions.js +4 -0
- package/dist/esm/Chat/Kit/OverlayPlacementOptions.js.map +1 -0
- package/dist/esm/Chat/Kit/overlayGeometry.d.ts +5 -0
- package/dist/esm/Chat/Kit/overlayGeometry.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/overlayGeometry.js +47 -0
- package/dist/esm/Chat/Kit/overlayGeometry.js.map +1 -0
- package/dist/esm/Chat/Kit/readAnchorTheme.d.ts +3 -0
- package/dist/esm/Chat/Kit/readAnchorTheme.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/readAnchorTheme.js +12 -0
- package/dist/esm/Chat/Kit/readAnchorTheme.js.map +1 -0
- package/dist/esm/Chat/Kit/useOverlayLayer.d.ts +2 -0
- package/dist/esm/Chat/Kit/useOverlayLayer.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/useOverlayLayer.js +12 -0
- package/dist/esm/Chat/Kit/useOverlayLayer.js.map +1 -0
- package/dist/esm/Chat/Kit/useOverlayPlacement.d.ts +4 -0
- package/dist/esm/Chat/Kit/useOverlayPlacement.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/useOverlayPlacement.js +44 -0
- package/dist/esm/Chat/Kit/useOverlayPlacement.js.map +1 -0
- package/dist/esm/Chat/Kit/useOverlayTarget.d.ts +2 -0
- package/dist/esm/Chat/Kit/useOverlayTarget.d.ts.map +1 -0
- package/dist/esm/Chat/Kit/useOverlayTarget.js +12 -0
- package/dist/esm/Chat/Kit/useOverlayTarget.js.map +1 -0
- package/dist/esm/Chat/Kit/useReactionPickerFocus.d.ts.map +1 -1
- package/dist/esm/Chat/Kit/useReactionPickerFocus.js +15 -10
- package/dist/esm/Chat/Kit/useReactionPickerFocus.js.map +1 -1
- package/dist/esm/DataPage/DataPage.d.ts +13 -7
- package/dist/esm/DataPage/DataPage.d.ts.map +1 -1
- package/dist/esm/DataPage/DataPage.js +6 -12
- package/dist/esm/DataPage/DataPage.js.map +1 -1
- package/dist/esm/DataPage/DataPageSelection.d.ts +19 -0
- package/dist/esm/DataPage/DataPageSelection.d.ts.map +1 -0
- package/dist/esm/DataPage/DataPageSelection.js +4 -0
- package/dist/esm/DataPage/DataPageSelection.js.map +1 -0
- package/dist/esm/DataPage/adaptMenuItem.d.ts +5 -0
- package/dist/esm/DataPage/adaptMenuItem.d.ts.map +1 -0
- package/dist/esm/DataPage/adaptMenuItem.js +22 -0
- package/dist/esm/DataPage/adaptMenuItem.js.map +1 -0
- package/dist/esm/DataPage/index.d.ts +1 -0
- package/dist/esm/DataPage/index.d.ts.map +1 -1
- package/dist/esm/Filter/measurePanelPlacement.d.ts +2 -11
- package/dist/esm/Filter/measurePanelPlacement.d.ts.map +1 -1
- package/dist/esm/Filter/measurePanelPlacement.js +3 -17
- package/dist/esm/Filter/measurePanelPlacement.js.map +1 -1
- package/dist/esm/Filter/usePanelPosition.js +2 -1
- package/dist/esm/Filter/usePanelPosition.js.map +1 -1
- package/dist/esm/renderer/fixedProbe.d.ts +11 -0
- package/dist/esm/renderer/fixedProbe.d.ts.map +1 -0
- package/dist/esm/renderer/fixedProbe.js +19 -0
- package/dist/esm/renderer/fixedProbe.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataPage.d.ts","sourceRoot":"","sources":["../../../DataPage/DataPage.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,SAAS,EAAW,MAAM,OAAO,CAAC;AAEpE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAY,MAAM,qBAAqB,CAAC;AAEzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAA6B,CAAC;AAElE,OAAO,KAAK,EACR,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,iCAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gDAA6C,CAAC;AACjG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAoC,CAAC;AAE/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"DataPage.d.ts","sourceRoot":"","sources":["../../../DataPage/DataPage.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,SAAS,EAAW,MAAM,OAAO,CAAC;AAEpE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAY,MAAM,qBAAqB,CAAC;AAEzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAA6B,CAAC;AAElE,OAAO,KAAK,EACR,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,iCAA8B,CAAC;AACtC,OAA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tE,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAExD;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,4EAA4E;IAC5E,SAAS,CAAC,EAAE,WAAW,CAAC;IAExB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;0BA+GG,MAAM,SACA,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,GAChC,SAAS,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,GAClC,mBAAmB,CAAC,SAAS,EAAE,UAAU,CAAC,GAC1C,mBAAmB,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,EAClD,SAAS,SAAS,MAAM,EACxB,UAAU,SAAS,MAAM,EAEzB,KAAK,EAAE,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC;;;;;;AA+DvD,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -7,6 +7,7 @@ import { DataTableForObservableQuery } from '../DataTables/DataTableForObservabl
|
|
|
7
7
|
import { DataTableForQuery } from '../DataTables/DataTableForQuery.js';
|
|
8
8
|
import { Allotment } from 'allotment';
|
|
9
9
|
import { DataPageLayout } from './DataPageLayout.js';
|
|
10
|
+
import { adaptMenuItem } from './adaptMenuItem.js';
|
|
10
11
|
|
|
11
12
|
const MenuItem = (_props) => {
|
|
12
13
|
return null;
|
|
@@ -16,25 +17,18 @@ const tableRegionStyle = { flexGrow: 1, flexBasis: 0, minHeight: 0 };
|
|
|
16
17
|
const pageStyle = { minHeight: '20rem' };
|
|
17
18
|
const MenuItems = ({ children }) => {
|
|
18
19
|
const context = useDataPageContext();
|
|
19
|
-
const
|
|
20
|
-
? context.selectedItems
|
|
21
|
-
:
|
|
20
|
+
const selection = useMemo(() => context.selectionMode === 'multiple'
|
|
21
|
+
? Object.freeze({ selectionMode: 'multiple', selectedItems: Object.freeze([...context.selectedItems]) })
|
|
22
|
+
: Object.freeze({ selectionMode: 'single', selectedItem: context.selectedItem }), [context.selectionMode, context.selectedItem, context.selectedItems]);
|
|
22
23
|
const items = useMemo(() => {
|
|
23
24
|
const menuItems = [];
|
|
24
25
|
React.Children.forEach(children, (child) => {
|
|
25
26
|
if (React.isValidElement(child) && child.type === MenuItem) {
|
|
26
|
-
|
|
27
|
-
menuItems.push({
|
|
28
|
-
label: child.props.label,
|
|
29
|
-
command: child.props.command,
|
|
30
|
-
icon: Icon ? jsx(Icon, { className: 'cratis:mr-2' }) : undefined,
|
|
31
|
-
disabled: (child.props.disabled ?? false) ||
|
|
32
|
-
(isDisabled && (child.props.disableOnUnselected ?? false)),
|
|
33
|
-
});
|
|
27
|
+
menuItems.push(adaptMenuItem(child.props, selection));
|
|
34
28
|
}
|
|
35
29
|
});
|
|
36
30
|
return menuItems;
|
|
37
|
-
}, [children,
|
|
31
|
+
}, [children, selection]);
|
|
38
32
|
return (jsx("div", { className: 'cratis-data-page-actions cratis:px-4 cratis:py-2', style: actionsStyle, children: jsx(ActionMenubar, { "aria-label": context.actionsAriaLabel ?? 'Actions', model: items, className: context.menubarClassName, pt: context.menubarPt, ptOptions: context.menubarPtOptions, unstyled: context.menubarUnstyled }) }));
|
|
39
33
|
};
|
|
40
34
|
const Columns = ({ children }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataPage.js","sources":["../../../DataPage/DataPage.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { type CSSProperties, type ReactNode, useMemo } from 'react';\nimport { Page } from '../Common/Page';\nimport React from 'react';\nimport { ActionMenubar, type ActionMenuItem } from '../Common/ActionMenubar';\nimport type { ButtonParts } from '../Common/Button';\nimport { type IObservableQueryFor, type IQueryFor, QueryFor } from '@cratis/arc/queries';\nimport { DataTableForObservableQuery } from '../DataTables/DataTableForObservableQuery';\nimport type { DataTableParts } from '../DataTables/DataTableCore';\nimport { DataTableForQuery } from '../DataTables/DataTableForQuery';\nimport type {\n TablePaginatorParts,\n TablePaginatorProps,\n} from '../DataTables/TablePaginator';\nimport type { DataTableFilterMeta } from '../DataTables/DataTableFilterMeta';\nimport type { DataTableSelectionChangeEvent } from '../DataTables/DataTableSelectionChangeEvent';\nimport type { DataTableServerQuery } from '../DataTables/DataTableServerQuery';\nimport { Allotment } from 'allotment';\nimport type { Constructor } from '@cratis/fundamentals';\nimport { DataPageLayout } from './DataPageLayout';\n\n// Allotment ships its layout as a stylesheet rather than inline styles, and a pane only becomes\n// the absolutely positioned, full-height box the split view assumes once that stylesheet is on\n// the page. It used to be pulled in here with a bare `import 'allotment/dist/style.css'`, but a\n// CSS import inside the JS graph is precisely what stops the published ESM from loading in Node\n// (Cratis/Components#118). The rules now ship inside this package's own `./styles` entry point,\n// which the build concatenates from every component stylesheet plus this third-party one — so a\n// consumer still gets a working split view, from the single stylesheet they already import.\n\n/**\n * Props for {@link MenuItem} — a single action in a {@link DataPage}'s\n * action bar.\n */\nexport interface MenuItemProps {\n /** Icon component rendered before the label (e.g. a react-icons icon). */\n icon?: React.ComponentType<{ className?: string }>;\n /** The visible label. */\n label?: string;\n /** Invoked when the item is activated. */\n command?: () => void;\n /** When true, the item is greyed out regardless of selection. */\n disabled?: boolean;\n /**\n * When true, the menu item is disabled while no row is selected in the\n * surrounding {@link DataPage}. Use it for context-sensitive actions like\n * \"Edit\" or \"Delete\" that require a selection.\n */\n disableOnUnselected?: boolean;\n}\n\n/**\n * Declarative menu item for use inside `<DataPage.MenuItems>`. Renders nothing\n * directly; the surrounding {@link MenuItems} component reads its props and\n * forwards them to the action menubar.\n */\nexport const MenuItem = (_props: MenuItemProps) => {\n return null;\n};\n\n/**\n * Props for {@link MenuItems}.\n */\nexport interface MenuItemsProps {\n /** One or more `<DataPage.MenuItem>` elements. */\n children: ReactNode;\n}\n\n/**\n * Props for {@link Columns}.\n */\nexport interface ColumnsProps {\n /** Cratis-owned `<Column>` markers describing each visible column. */\n children: ReactNode;\n}\n\n/**\n * The action bar is an intrinsically sized item in the page's layout column —\n * it takes the height its menubar needs and never gives any of it up, so the\n * table region below it is the only part that has to adapt to the space left.\n */\nconst actionsStyle: CSSProperties = { flexShrink: 0 };\n\n/**\n * The table region takes every pixel the action bar leaves and no more.\n * `minHeight: 0` is the load-bearing half: without it the region's automatic\n * minimum keeps it at content height, the column grows past the page, and the\n * table's paginator ends up below the clipped edge.\n */\nconst tableRegionStyle: CSSProperties = { flexGrow: 1, flexBasis: 0, minHeight: 0 };\n\n/**\n * The floor a `DataPage` falls back to when its ancestors give it no height at\n * all. A page that renders as an empty sliver is indistinguishable from a\n * broken one, so a contract-violating consumer gets a small but usable page\n * instead of nothing.\n */\nconst pageStyle: CSSProperties = { minHeight: '20rem' };\n\n/**\n * Renders an action menubar at the top of a {@link DataPage}, populated from\n * `<DataPage.MenuItem>` children. Each menu item's `disableOnUnselected` flag\n * is automatically honored against the current row selection.\n *\n * Use as `<DataPage.MenuItems>` inside a `<DataPage>`.\n */\nexport const MenuItems = ({ children }: MenuItemsProps) => {\n const context = useDataPageContext();\n const isDisabled =\n context.selectionMode === 'multiple'\n ? context.selectedItems.length === 0\n : !context.selectedItem;\n\n const items = useMemo(() => {\n const menuItems: ActionMenuItem[] = [];\n React.Children.forEach(children, (child) => {\n if (React.isValidElement<MenuItemProps>(child) && child.type === MenuItem) {\n const Icon = child.props.icon;\n menuItems.push({\n label: child.props.label,\n command: child.props.command,\n icon: Icon ? <Icon className='cratis:mr-2' /> : undefined,\n disabled:\n (child.props.disabled ?? false) ||\n (isDisabled && (child.props.disableOnUnselected ?? false)),\n });\n }\n });\n\n return menuItems;\n }, [children, isDisabled]);\n\n return (\n <div\n className='cratis-data-page-actions cratis:px-4 cratis:py-2'\n style={actionsStyle}\n >\n <ActionMenubar\n aria-label={context.actionsAriaLabel ?? 'Actions'}\n model={items}\n className={context.menubarClassName}\n pt={context.menubarPt}\n ptOptions={context.menubarPtOptions}\n unstyled={context.menubarUnstyled}\n />\n </div>\n );\n};\n\n/**\n * Renders the data table at the body of a {@link DataPage}. Automatically\n * selects between {@link DataTableForQuery} (snapshot query) and\n * {@link DataTableForObservableQuery} (real-time observable) based on the\n * `query` type provided to the surrounding `<DataPage>`.\n *\n * Use as `<DataPage.Columns>` inside a `<DataPage>`, with Cratis-owned `<Column>`\n * children defining the table columns.\n */\nexport const Columns = ({ children }: ColumnsProps) => {\n const context = useDataPageContext();\n const isSnapshotQuery = context.query.prototype instanceof QueryFor;\n // SAFETY: The runtime prototype check above narrows a constructor shape that\n // TypeScript cannot discriminate after the generic DataPage context is erased.\n const snapshotQuery = context.query as Constructor<\n IQueryFor<object, object> | IQueryFor<object[], object>\n >;\n const observableQuery = context.query as Constructor<\n IObservableQueryFor<object, object> | IObservableQueryFor<object[], object>\n >;\n\n return (\n <div className='cratis-data-page-table' style={tableRegionStyle}>\n {isSnapshotQuery ? (\n <DataTableForQuery\n {...context}\n query={snapshotQuery}\n selection={context.selectedItem}\n onSelectionChange={context.onSelectionChanged}\n className={context.tableClassName}\n pt={context.tablePt}\n ptOptions={context.tablePtOptions}\n unstyled={context.tableUnstyled}\n >\n {children}\n </DataTableForQuery>\n ) : (\n <DataTableForObservableQuery\n {...context}\n query={observableQuery}\n selection={context.selectedItem}\n onSelectionChange={context.onSelectionChanged}\n className={context.tableClassName}\n pt={context.tablePt}\n ptOptions={context.tablePtOptions}\n unstyled={context.tableUnstyled}\n >\n {children}\n </DataTableForObservableQuery>\n )}\n </div>\n );\n};\n\n/**\n * Props passed to the optional details component rendered on the right pane\n * of a {@link DataPage} when a row is selected.\n *\n * @typeParam TDataType - The type of the selected item.\n */\nexport interface IDetailsComponentProps<TDataType> {\n /** The currently-selected row. */\n item: TDataType;\n\n /**\n * The caller's {@link DataPageProps.onRefresh} callback, forwarded unchanged\n * to the details component. Invoking it does not make DataPage refetch.\n */\n onRefresh?: () => void;\n}\n\ninterface IDataPageContext extends DataPageProps<\n IQueryFor<object, object> | IObservableQueryFor<object, object>,\n object,\n object\n> {\n selectedItem: object | null | undefined;\n onSelectionChanged: (event: DataTableSelectionChangeEvent<object>) => void;\n selectedItems: object[];\n onSelectedItemsChange: (items: object[]) => void;\n}\n\nconst DataPageContext = React.createContext<IDataPageContext | null>(null);\n\nfunction useDataPageContext(): IDataPageContext {\n const context = React.useContext(DataPageContext);\n if (!context) {\n throw new Error('useDataPageContext must be used within a DataPage component');\n }\n return context;\n}\n\n/**\n * Props for {@link DataPage}.\n *\n * @typeParam TQuery - The query class — either a snapshot `IQueryFor` or a real-time `IObservableQueryFor`.\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type, or `object` if the query takes none.\n */\nexport interface DataPageProps<\n TQuery extends\n | IQueryFor<TDataType, TArguments>\n | IQueryFor<TDataType[], TArguments>\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n> {\n /**\n * The title of the page\n */\n title: string;\n\n /** Whether the page content is a main landmark. Defaults to true; set false inside an existing main. */\n landmark?: boolean;\n\n /**\n * Children to render, for this it means menu items and columns. Use <DataPage.MenuItems> and <DataPage.Columns> for this.\n */\n children: ReactNode;\n\n /**\n * Component to render when the selection changes\n */\n detailsComponent?: React.FC<IDetailsComponentProps<TDataType>>;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /**\n * The message to show instead of {@link emptyMessage} when a search or column filter is active\n * and no rows are shown. Defaults to a localizable message that says only the loaded page was\n * searched, or, with `serverQuery`, a neutral \"No rows match the search.\".\n */\n filteredEmptyMessage?: ReactNode;\n\n /** Notified of every change to the search text, as typed. */\n onGlobalFilterChange?: (globalFilter: string) => void;\n\n /** Message shown while loading without rows. */\n loadingMessage?: ReactNode;\n /** Message shown when the query fails. */\n failureMessage?: ReactNode;\n /** Message shown when access is denied. */\n unauthorizedMessage?: ReactNode;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes, including replacement or removal of its query row.\n * With a controlled selection, the consumer must accept the new value. Without a callback,\n * the controlled value and its details remain unchanged even if the query row disappears.\n */\n onSelectionChange?(event: DataTableSelectionChangeEvent<TDataType>): void;\n\n /**\n * The row selection mode. Defaults to `'single'`. Use `'multiple'` for a page whose actions\n * operate on a set of rows - it adds per-row checkboxes and a select-all header checkbox, and\n * reports through {@link onSelectedItemsChange}.\n */\n selectionMode?: 'single' | 'multiple';\n\n /**\n * The currently selected rows, for `selectionMode='multiple'`. Leave undefined to let the page\n * own the selection.\n */\n selectedItems?: TDataType[];\n\n /**\n * Callback for when a multiple selection changes, with the full selected set.\n */\n onSelectedItemsChange?(items: TDataType[]): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /** Placeholder for the loaded-page search input. */\n globalSearchPlaceholder?: string;\n\n /** Accessible name for the loaded-page search input. */\n globalSearchAriaLabel?: string;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n\n /**\n * @deprecated Filtering is always applied to the currently loaded page.\n * This compatibility prop no longer toggles behavior and does not change\n * server-reported pagination totals. Retained for source compatibility only.\n */\n clientFiltering?: boolean;\n\n /**\n * Opts the page's table into server mode: the query sorts, filters and searches the complete\n * result before paging, and the table renders the rows as returned. Leave undefined to sort,\n * filter and search the loaded page. See {@link DataTableServerQuery}.\n */\n serverQuery?: DataTableServerQuery<TArguments>;\n\n /** Optional callback forwarded to the details component as `onRefresh`; DataPage does not invoke it or refetch when it is called. */\n onRefresh?(): void;\n\n /**\n * Extra CSS class name forwarded to the inner DataTable root.\n */\n tableClassName?: string;\n\n /** Cratis-owned per-part attributes applied to the inner table. */\n tablePt?: DataTableParts;\n\n /**\n * @deprecated Cratis table parts always merge. Remove this renderer-era option.\n */\n tablePtOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `tablePt` and CSS instead.\n */\n tableUnstyled?: boolean;\n\n /** Shows numbered page buttons in the query table paginator. Defaults to false. */\n pageLinks?: TablePaginatorProps['pageLinks'];\n\n /** Extra CSS class name forwarded to the query table paginator. */\n paginatorClassName?: string;\n\n /** Cratis-owned attributes applied to the query table paginator. */\n paginatorPt?: TablePaginatorParts;\n\n /**\n * @deprecated Cratis paginator parts always merge. Remove this renderer-era option.\n */\n paginatorPtOptions?: object;\n\n /** Accessible paginator labels. Override any value to localize it. */\n paginatorAriaLabels?: TablePaginatorProps['ariaLabels'];\n\n /**\n * Extra CSS class name forwarded to the action menubar root.\n */\n menubarClassName?: string;\n\n /** Cratis-owned part attributes applied to the action menubar's buttons. */\n menubarPt?: ButtonParts;\n\n /**\n * @deprecated Cratis menubar parts always merge. Remove this renderer-era option.\n */\n menubarPtOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `menubarPt` and CSS instead.\n */\n menubarUnstyled?: boolean;\n\n /**\n * Accessible name for the action menubar (toolbar). Override to localize.\n * Defaults to `'Actions'`.\n */\n actionsAriaLabel?: string;\n}\n\n/**\n * A page primitive that combines an action menubar, a query-backed data\n * table, and an optional details pane into one layout. Designed as the\n * default rendering for \"list view\" pages in an Arc app.\n *\n * ## What `TQuery` is\n *\n * `TQuery` is the auto-generated TypeScript class produced by the Arc proxy\n * generator from a C# read model query. Two flavors are accepted and\n * **selected automatically at runtime** based on the class hierarchy:\n *\n * - **`IQueryFor<TDataType, TArguments>`** — a snapshot query. Re-fetched\n * when `queryArguments` change or when the page is mounted. Rendered\n * through {@link DataTableForQuery} internally.\n * - **`IObservableQueryFor<TDataType, TArguments>`** — a real-time\n * subscription. Connects to the backend over WebSocket and re-renders\n * automatically whenever the underlying read model changes server-side.\n * Rendered through {@link DataTableForObservableQuery} internally.\n *\n * You don't pick which inner table to use — `DataPage` inspects the\n * prototype chain (`context.query.prototype instanceof QueryFor`) and\n * mounts the correct one.\n *\n * ## Declarative composition\n *\n * Three children build up the page:\n *\n * - **`<DataPage.MenuItems>`** wraps `<DataPage.MenuItem>` elements that\n * become the action `Menubar` at the top. Each item declares its `icon`,\n * `label`, and `command` (an `onClick` handler). Items can be marked\n * `disableOnUnselected` so they automatically grey out until the user\n * picks a row — useful for Edit / Delete actions that need a target.\n *\n * - **`<DataPage.Columns>`** wraps Cratis-owned `<Column>` markers that\n * describe the visible columns. The columns themselves are\n * Cratis-owned — the documented `ColumnProps` surface is\n * supported here (sorting, filtering, custom body templates, …).\n *\n * - **`detailsComponent`** (optional) is a React component rendered in a\n * right-hand pane via Allotment when a row is selected. It receives the\n * selected item as `item` and the caller's `onRefresh` callback, if\n * supplied. DataPage does not refetch when the details component invokes it.\n *\n * ## Selection lifecycle\n *\n * `DataPage` keeps the current selection in local state and threads it to\n * the inner table, the menubar (`disableOnUnselected` items follow it),\n * and the optional details pane. The `onSelectionChange` prop is invoked\n * after every change if the consumer also needs to react to it.\n *\n * ```tsx\n * <DataPage<AllAuthors, Author, never>\n * title=\"Authors\"\n * query={AllAuthors} // proxy from C#\n * detailsComponent={AuthorDetails}>\n * <DataPage.MenuItems>\n * <DataPage.MenuItem icon={FaPlus} label=\"Add\" command={onAdd} />\n * <DataPage.MenuItem icon={FaPencil} label=\"Edit\" command={onEdit}\n * disableOnUnselected />\n * <DataPage.MenuItem icon={FaTrash} label=\"Delete\" command={onDelete}\n * disableOnUnselected />\n * </DataPage.MenuItems>\n * <DataPage.Columns>\n * <Column field=\"name\" header=\"Name\" sortable />\n * <Column field=\"email\" header=\"Email\" />\n * </DataPage.Columns>\n * </DataPage>\n * ```\n *\n * ## Height — `DataPage` needs a bounded ancestor\n *\n * `DataPage` fills the height it is given and divides it between the action\n * bar and the table region, so the table's paginator always sits at the\n * bottom of the page rather than below its edge. It cannot invent that height:\n * every element from the page root down sizes as a percentage of its parent,\n * so **some ancestor has to have a definite height**.\n *\n * ```tsx\n * // ✅ the router outlet, a sized container, or a flex child with min-height\n * <div style={{ height: '100vh' }}>\n * <DataPage … />\n * </div>\n *\n * // ❌ nothing above resolves to a height — the table grows to its content\n * <div>\n * <DataPage … />\n * </div>\n * ```\n *\n * Without one, the page falls back to a small fixed height so it stays\n * usable instead of collapsing to nothing.\n *\n * ## Styling\n *\n * The inner DataTable and action toolbar each have their own per-slot props:\n * `tablePt` / `tableUnstyled` / `tableClassName` for the table;\n * `paginatorPt` / `paginatorClassName` / `paginatorAriaLabels` for paging;\n * `menubarPt` / `menubarPtOptions` / `menubarUnstyled` / `menubarClassName` for\n * the action toolbar's stable button parts (the action bar is implemented as\n * a button toolbar, so `menubarPt` targets the stable Cratis button parts). See the\n * [pass-through cheat sheet](../../Documentation/Styling/pass-through.md) for\n * the full slot reference.\n *\n * @typeParam TQuery - The query class (proxy generated from a C# read model query).\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n * @param props - {@link DataPageProps}.\n */\nconst DataPage = <\n TQuery extends\n | IQueryFor<TDataType, TArguments>\n | IQueryFor<TDataType[], TArguments>\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n>(\n props: DataPageProps<TQuery, TDataType, TArguments>,\n) => {\n const [internalSelection, setInternalSelection] = React.useState<\n TDataType | null | undefined\n >(props.selection);\n const selectedItem =\n props.selection === undefined ? internalSelection : props.selection;\n\n const selectionChanged = (event: DataTableSelectionChangeEvent<TDataType>) => {\n if (props.selection === undefined) setInternalSelection(event.value);\n props.onSelectionChange?.(event);\n };\n\n const [internalSelectedItems, setInternalSelectedItems] = React.useState<TDataType[]>(\n props.selectedItems ?? [],\n );\n const selectedItems = props.selectedItems ?? internalSelectedItems;\n\n const selectedItemsChanged = (items: TDataType[]) => {\n if (props.selectedItems === undefined) setInternalSelectedItems(items);\n props.onSelectedItemsChange?.(items);\n };\n\n // SAFETY: React context cannot retain this component's generic parameters. The\n // provider and every consumer are nested in the same DataPage invocation, so the\n // erased object-level context never crosses between differently typed pages.\n const context = {\n ...props,\n selectedItem,\n onSelectionChanged: selectionChanged,\n selectedItems,\n onSelectedItemsChange: selectedItemsChanged,\n } as unknown as IDataPageContext;\n\n return (\n <DataPageContext.Provider value={context}>\n <Page title={props.title} landmark={props.landmark} panel={true} style={pageStyle} data-cratis-component='DataPage'>\n {props.detailsComponent ? (\n <Allotment className='cratis:h-full' proportionalLayout={false}>\n <Allotment.Pane>\n <DataPageLayout>{props.children}</DataPageLayout>\n </Allotment.Pane>\n {selectedItem && (\n <Allotment.Pane preferredSize='450px'>\n <props.detailsComponent\n item={selectedItem}\n onRefresh={props.onRefresh}\n />\n </Allotment.Pane>\n )}\n </Allotment>\n ) : (\n <DataPageLayout>{props.children}</DataPageLayout>\n )}\n </Page>\n </DataPageContext.Provider>\n );\n};\n\nDataPage.MenuItem = MenuItem;\nDataPage.MenuItems = MenuItems;\nDataPage.Columns = Columns;\n\nexport { DataPage };\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;AAyDO,MAAM,QAAQ,GAAG,CAAC,MAAqB,KAAI;AAC9C,IAAA,OAAO,IAAI;AACf;AAuBA,MAAM,YAAY,GAAkB,EAAE,UAAU,EAAE,CAAC,EAAE;AAQrD,MAAM,gBAAgB,GAAkB,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;AAQnF,MAAM,SAAS,GAAkB,EAAE,SAAS,EAAE,OAAO,EAAE;MAS1C,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAkB,KAAI;AACtD,IAAA,MAAM,OAAO,GAAG,kBAAkB,EAAE;AACpC,IAAA,MAAM,UAAU,GACZ,OAAO,CAAC,aAAa,KAAK;AACtB,UAAE,OAAO,CAAC,aAAa,CAAC,MAAM,KA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AAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAA,uBAAA,EAAwB,UAAU,YAC9G,KAAK,CAAC,gBAAgB,IACnBC,IAAA,CAAC,SAAS,EAAA,EAAC,SAAS,EAAC,eAAe,EAAC,kBAAkB,EAAE,KAAK,EAAA,QAAA,EAAA,CAC1DD,GAAA,CAAC,SAAS,CAAC,IAAI,EAAA,EAAA,QAAA,EACXA,GAAA,CAAC,cAAc,EAAA,EAAA,QAAA,EAAE,KAAK,CAAC,QAAQ,EAAA,CAAkB,EAAA,CACpC,EAChB,YAAY,KACTA,IAAC,SAAS,CAAC,IAAI,EAAA,EAAC,aAAa,EAAC,OAAO,EAAA,QAAA,EACjCA,GAAA,CAAC,KAAK,CAAC,gBAAgB,EAAA,EACnB,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,KAAK,CAAC,SAAS,EAAA,CAC5B,EAAA,CACW,CACpB,CAAA,EAAA,CACO,KAEZA,GAAA,CAAC,cAAc,EAAA,EAAA,QAAA,EAAE,KAAK,CAAC,QAAQ,EAAA,CAAkB,CACpD,EAAA,CACE,EAAA,CACgB;AAEnC;AAEA,QAAQ,CAAC,QAAQ,GAAG,QAAQ;AAC5B,QAAQ,CAAC,SAAS,GAAG,SAAS;AAC9B,QAAQ,CAAC,OAAO,GAAG,OAAO;;"}
|
|
1
|
+
{"version":3,"file":"DataPage.js","sources":["../../../DataPage/DataPage.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { type CSSProperties, type ReactNode, useMemo } from 'react';\nimport { Page } from '../Common/Page';\nimport React from 'react';\nimport { ActionMenubar, type ActionMenuItem } from '../Common/ActionMenubar';\nimport type { ButtonParts } from '../Common/Button';\nimport { type IObservableQueryFor, type IQueryFor, QueryFor } from '@cratis/arc/queries';\nimport { DataTableForObservableQuery } from '../DataTables/DataTableForObservableQuery';\nimport type { DataTableParts } from '../DataTables/DataTableCore';\nimport { DataTableForQuery } from '../DataTables/DataTableForQuery';\nimport type {\n TablePaginatorParts,\n TablePaginatorProps,\n} from '../DataTables/TablePaginator';\nimport type { DataTableFilterMeta } from '../DataTables/DataTableFilterMeta';\nimport type { DataTableSelectionChangeEvent } from '../DataTables/DataTableSelectionChangeEvent';\nimport type { DataTableServerQuery } from '../DataTables/DataTableServerQuery';\nimport { Allotment } from 'allotment';\nimport type { Constructor } from '@cratis/fundamentals';\nimport { DataPageLayout } from './DataPageLayout';\nimport type { DataPageSelection } from './DataPageSelection';\nimport { adaptMenuItem } from './adaptMenuItem';\n\n// Allotment ships its layout as a stylesheet rather than inline styles, and a pane only becomes\n// the absolutely positioned, full-height box the split view assumes once that stylesheet is on\n// the page. It used to be pulled in here with a bare `import 'allotment/dist/style.css'`, but a\n// CSS import inside the JS graph is precisely what stops the published ESM from loading in Node\n// (Cratis/Components#118). The rules now ship inside this package's own `./styles` entry point,\n// which the build concatenates from every component stylesheet plus this third-party one — so a\n// consumer still gets a working split view, from the single stylesheet they already import.\n\n/**\n * Props for {@link MenuItem} — a single action in a {@link DataPage}'s\n * action bar.\n *\n * @typeParam TDataType - The surrounding page's row type. JSX does not infer it from the parent.\n */\nexport interface MenuItemProps<TDataType extends object = object> {\n /** Icon component rendered before the label (e.g. a react-icons icon). */\n icon?: React.ComponentType<{ className?: string }>;\n /** The visible label. */\n label?: string;\n /** Invoked with the immutable, committed selection when the enabled item is activated. */\n command?: (selection: DataPageSelection<TDataType>) => void;\n /** A boolean or selection predicate; when true, the item cannot dispatch its command. */\n disabled?: boolean | ((selection: DataPageSelection<TDataType>) => boolean);\n /**\n * When true, the menu item is disabled while no row is selected in the\n * surrounding {@link DataPage}. Use it for context-sensitive actions like\n * \"Edit\" or \"Delete\" that require a selection.\n */\n disableOnUnselected?: boolean;\n}\n\n/**\n * Declarative menu item for use inside `<DataPage.MenuItems>`. Renders nothing\n * directly; the surrounding {@link MenuItems} component reads its props and\n * forwards them to the action menubar. Supply the page's row type explicitly\n * as `<DataPage.MenuItem<Person>>` for typed row access in callbacks.\n *\n * @typeParam TDataType - The surrounding page's row type, not inferred from its JSX parent.\n */\nexport const MenuItem = <TDataType extends object = object,>(_props: MenuItemProps<TDataType>) => {\n return null;\n};\n\n/**\n * Props for {@link MenuItems}.\n */\nexport interface MenuItemsProps {\n /** One or more `<DataPage.MenuItem>` elements. */\n children: ReactNode;\n}\n\n/**\n * Props for {@link Columns}.\n */\nexport interface ColumnsProps {\n /** Cratis-owned `<Column>` markers describing each visible column. */\n children: ReactNode;\n}\n\n/**\n * The action bar is an intrinsically sized item in the page's layout column —\n * it takes the height its menubar needs and never gives any of it up, so the\n * table region below it is the only part that has to adapt to the space left.\n */\nconst actionsStyle: CSSProperties = { flexShrink: 0 };\n\n/**\n * The table region takes every pixel the action bar leaves and no more.\n * `minHeight: 0` is the load-bearing half: without it the region's automatic\n * minimum keeps it at content height, the column grows past the page, and the\n * table's paginator ends up below the clipped edge.\n */\nconst tableRegionStyle: CSSProperties = { flexGrow: 1, flexBasis: 0, minHeight: 0 };\n\n/**\n * The floor a `DataPage` falls back to when its ancestors give it no height at\n * all. A page that renders as an empty sliver is indistinguishable from a\n * broken one, so a contract-violating consumer gets a small but usable page\n * instead of nothing.\n */\nconst pageStyle: CSSProperties = { minHeight: '20rem' };\n\n/**\n * Renders an action menubar at the top of a {@link DataPage}, populated from\n * `<DataPage.MenuItem>` children. Each menu item's `disableOnUnselected` flag\n * is automatically honored against the current row selection.\n *\n * Use as `<DataPage.MenuItems>` inside a `<DataPage>`.\n */\nexport const MenuItems = ({ children }: MenuItemsProps) => {\n const context = useDataPageContext();\n const selection = useMemo<DataPageSelection>(() => context.selectionMode === 'multiple'\n ? Object.freeze({ selectionMode: 'multiple', selectedItems: Object.freeze([...context.selectedItems]) })\n : Object.freeze({ selectionMode: 'single', selectedItem: context.selectedItem }),\n [context.selectionMode, context.selectedItem, context.selectedItems]);\n\n const items = useMemo(() => {\n const menuItems: ActionMenuItem[] = [];\n React.Children.forEach(children, (child) => {\n // SAFETY: Marker generics are erased by React children. Consumers explicitly\n // supply this page's row type on MenuItem; the private context never escapes.\n if (React.isValidElement<MenuItemProps>(child) && child.type === MenuItem) {\n menuItems.push(adaptMenuItem(child.props, selection));\n }\n });\n\n return menuItems;\n }, [children, selection]);\n\n return (\n <div\n className='cratis-data-page-actions cratis:px-4 cratis:py-2'\n style={actionsStyle}\n >\n <ActionMenubar\n aria-label={context.actionsAriaLabel ?? 'Actions'}\n model={items}\n className={context.menubarClassName}\n pt={context.menubarPt}\n ptOptions={context.menubarPtOptions}\n unstyled={context.menubarUnstyled}\n />\n </div>\n );\n};\n\n/**\n * Renders the data table at the body of a {@link DataPage}. Automatically\n * selects between {@link DataTableForQuery} (snapshot query) and\n * {@link DataTableForObservableQuery} (real-time observable) based on the\n * `query` type provided to the surrounding `<DataPage>`.\n *\n * Use as `<DataPage.Columns>` inside a `<DataPage>`, with Cratis-owned `<Column>`\n * children defining the table columns.\n */\nexport const Columns = ({ children }: ColumnsProps) => {\n const context = useDataPageContext();\n const isSnapshotQuery = context.query.prototype instanceof QueryFor;\n // SAFETY: The runtime prototype check above narrows a constructor shape that\n // TypeScript cannot discriminate after the generic DataPage context is erased.\n const snapshotQuery = context.query as Constructor<\n IQueryFor<object, object> | IQueryFor<object[], object>\n >;\n const observableQuery = context.query as Constructor<\n IObservableQueryFor<object, object> | IObservableQueryFor<object[], object>\n >;\n\n return (\n <div className='cratis-data-page-table' style={tableRegionStyle}>\n {isSnapshotQuery ? (\n <DataTableForQuery\n {...context}\n query={snapshotQuery}\n selection={context.selectedItem}\n onSelectionChange={context.onSelectionChanged}\n className={context.tableClassName}\n pt={context.tablePt}\n ptOptions={context.tablePtOptions}\n unstyled={context.tableUnstyled}\n >\n {children}\n </DataTableForQuery>\n ) : (\n <DataTableForObservableQuery\n {...context}\n query={observableQuery}\n selection={context.selectedItem}\n onSelectionChange={context.onSelectionChanged}\n className={context.tableClassName}\n pt={context.tablePt}\n ptOptions={context.tablePtOptions}\n unstyled={context.tableUnstyled}\n >\n {children}\n </DataTableForObservableQuery>\n )}\n </div>\n );\n};\n\n/**\n * Props passed to the optional details component rendered on the right pane\n * of a {@link DataPage} when a row is selected.\n *\n * @typeParam TDataType - The type of the selected item.\n */\nexport interface IDetailsComponentProps<TDataType> {\n /** The currently-selected row. */\n item: TDataType;\n\n /**\n * The caller's {@link DataPageProps.onRefresh} callback, forwarded unchanged\n * to the details component. Invoking it does not make DataPage refetch.\n */\n onRefresh?: () => void;\n}\n\ninterface IDataPageContext extends DataPageProps<\n IQueryFor<object, object> | IObservableQueryFor<object, object>,\n object,\n object\n> {\n selectedItem: object | null | undefined;\n onSelectionChanged: (event: DataTableSelectionChangeEvent<object>) => void;\n selectedItems: object[];\n onSelectedItemsChange: (items: object[]) => void;\n}\n\nconst DataPageContext = React.createContext<IDataPageContext | null>(null);\n\nfunction useDataPageContext(): IDataPageContext {\n const context = React.useContext(DataPageContext);\n if (!context) {\n throw new Error('useDataPageContext must be used within a DataPage component');\n }\n return context;\n}\n\n/**\n * Props for {@link DataPage}.\n *\n * @typeParam TQuery - The query class — either a snapshot `IQueryFor` or a real-time `IObservableQueryFor`.\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type, or `object` if the query takes none.\n */\nexport interface DataPageProps<\n TQuery extends\n | IQueryFor<TDataType, TArguments>\n | IQueryFor<TDataType[], TArguments>\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n> {\n /**\n * The title of the page\n */\n title: string;\n\n /** Whether the page content is a main landmark. Defaults to true; set false inside an existing main. */\n landmark?: boolean;\n\n /**\n * Children to render, for this it means menu items and columns. Use <DataPage.MenuItems> and <DataPage.Columns> for this.\n */\n children: ReactNode;\n\n /**\n * Component to render when the selection changes\n */\n detailsComponent?: React.FC<IDetailsComponentProps<TDataType>>;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /**\n * The message to show instead of {@link emptyMessage} when a search or column filter is active\n * and no rows are shown. Defaults to a localizable message that says only the loaded page was\n * searched, or, with `serverQuery`, a neutral \"No rows match the search.\".\n */\n filteredEmptyMessage?: ReactNode;\n\n /** Notified of every change to the search text, as typed. */\n onGlobalFilterChange?: (globalFilter: string) => void;\n\n /** Message shown while loading without rows. */\n loadingMessage?: ReactNode;\n /** Message shown when the query fails. */\n failureMessage?: ReactNode;\n /** Message shown when access is denied. */\n unauthorizedMessage?: ReactNode;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes, including replacement or removal of its query row.\n * With a controlled selection, the consumer must accept the new value. Without a callback,\n * the controlled value and its details remain unchanged even if the query row disappears.\n */\n onSelectionChange?(event: DataTableSelectionChangeEvent<TDataType>): void;\n\n /**\n * The row selection mode. Defaults to `'single'`. Use `'multiple'` for a page whose actions\n * operate on a set of rows - it adds per-row checkboxes and a select-all header checkbox, and\n * reports through {@link onSelectedItemsChange}.\n */\n selectionMode?: 'single' | 'multiple';\n\n /**\n * The currently selected rows, for `selectionMode='multiple'`. Leave undefined to let the page\n * own the selection.\n */\n selectedItems?: TDataType[];\n\n /**\n * Callback for when a multiple selection changes, with the full selected set.\n */\n onSelectedItemsChange?(items: TDataType[]): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /** Placeholder for the loaded-page search input. */\n globalSearchPlaceholder?: string;\n\n /** Accessible name for the loaded-page search input. */\n globalSearchAriaLabel?: string;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n\n /**\n * @deprecated Filtering is always applied to the currently loaded page.\n * This compatibility prop no longer toggles behavior and does not change\n * server-reported pagination totals. Retained for source compatibility only.\n */\n clientFiltering?: boolean;\n\n /**\n * Opts the page's table into server mode: the query sorts, filters and searches the complete\n * result before paging, and the table renders the rows as returned. Leave undefined to sort,\n * filter and search the loaded page. See {@link DataTableServerQuery}.\n */\n serverQuery?: DataTableServerQuery<TArguments>;\n\n /** Optional callback forwarded to the details component as `onRefresh`; DataPage does not invoke it or refetch when it is called. */\n onRefresh?(): void;\n\n /**\n * Extra CSS class name forwarded to the inner DataTable root.\n */\n tableClassName?: string;\n\n /** Cratis-owned per-part attributes applied to the inner table. */\n tablePt?: DataTableParts;\n\n /**\n * @deprecated Cratis table parts always merge. Remove this renderer-era option.\n */\n tablePtOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `tablePt` and CSS instead.\n */\n tableUnstyled?: boolean;\n\n /** Shows numbered page buttons in the query table paginator. Defaults to false. */\n pageLinks?: TablePaginatorProps['pageLinks'];\n\n /** Extra CSS class name forwarded to the query table paginator. */\n paginatorClassName?: string;\n\n /** Cratis-owned attributes applied to the query table paginator. */\n paginatorPt?: TablePaginatorParts;\n\n /**\n * @deprecated Cratis paginator parts always merge. Remove this renderer-era option.\n */\n paginatorPtOptions?: object;\n\n /** Accessible paginator labels. Override any value to localize it. */\n paginatorAriaLabels?: TablePaginatorProps['ariaLabels'];\n\n /**\n * Extra CSS class name forwarded to the action menubar root.\n */\n menubarClassName?: string;\n\n /** Cratis-owned part attributes applied to the action menubar's buttons. */\n menubarPt?: ButtonParts;\n\n /**\n * @deprecated Cratis menubar parts always merge. Remove this renderer-era option.\n */\n menubarPtOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `menubarPt` and CSS instead.\n */\n menubarUnstyled?: boolean;\n\n /**\n * Accessible name for the action menubar (toolbar). Override to localize.\n * Defaults to `'Actions'`.\n */\n actionsAriaLabel?: string;\n}\n\n/**\n * A page primitive that combines an action menubar, a query-backed data\n * table, and an optional details pane into one layout. Designed as the\n * default rendering for \"list view\" pages in an Arc app.\n *\n * ## What `TQuery` is\n *\n * `TQuery` is the auto-generated TypeScript class produced by the Arc proxy\n * generator from a C# read model query. Two flavors are accepted and\n * **selected automatically at runtime** based on the class hierarchy:\n *\n * - **`IQueryFor<TDataType, TArguments>`** — a snapshot query. Re-fetched\n * when `queryArguments` change or when the page is mounted. Rendered\n * through {@link DataTableForQuery} internally.\n * - **`IObservableQueryFor<TDataType, TArguments>`** — a real-time\n * subscription. Connects to the backend over WebSocket and re-renders\n * automatically whenever the underlying read model changes server-side.\n * Rendered through {@link DataTableForObservableQuery} internally.\n *\n * You don't pick which inner table to use — `DataPage` inspects the\n * prototype chain (`context.query.prototype instanceof QueryFor`) and\n * mounts the correct one.\n *\n * ## Declarative composition\n *\n * Three children build up the page:\n *\n * - **`<DataPage.MenuItems>`** wraps `<DataPage.MenuItem>` elements that\n * become the action `Menubar` at the top. Each item declares its `icon`,\n * `label`, and `command` (an `onClick` handler). Items can be marked\n * `disableOnUnselected` so they automatically grey out until the user\n * picks a row — useful for Edit / Delete actions that need a target.\n *\n * - **`<DataPage.Columns>`** wraps Cratis-owned `<Column>` markers that\n * describe the visible columns. The columns themselves are\n * Cratis-owned — the documented `ColumnProps` surface is\n * supported here (sorting, filtering, custom body templates, …).\n *\n * - **`detailsComponent`** (optional) is a React component rendered in a\n * right-hand pane via Allotment when a row is selected. It receives the\n * selected item as `item` and the caller's `onRefresh` callback, if\n * supplied. DataPage does not refetch when the details component invokes it.\n *\n * ## Selection lifecycle\n *\n * `DataPage` keeps the current selection in local state and threads it to\n * the inner table, the menubar (`disableOnUnselected` items follow it),\n * and the optional details pane. The `onSelectionChange` prop is invoked\n * after every change if the consumer also needs to react to it.\n *\n * ```tsx\n * <DataPage<AllAuthors, Author, never>\n * title=\"Authors\"\n * query={AllAuthors} // proxy from C#\n * detailsComponent={AuthorDetails}>\n * <DataPage.MenuItems>\n * <DataPage.MenuItem icon={FaPlus} label=\"Add\" command={onAdd} />\n * <DataPage.MenuItem icon={FaPencil} label=\"Edit\" command={onEdit}\n * disableOnUnselected />\n * <DataPage.MenuItem icon={FaTrash} label=\"Delete\" command={onDelete}\n * disableOnUnselected />\n * </DataPage.MenuItems>\n * <DataPage.Columns>\n * <Column field=\"name\" header=\"Name\" sortable />\n * <Column field=\"email\" header=\"Email\" />\n * </DataPage.Columns>\n * </DataPage>\n * ```\n *\n * ## Height — `DataPage` needs a bounded ancestor\n *\n * `DataPage` fills the height it is given and divides it between the action\n * bar and the table region, so the table's paginator always sits at the\n * bottom of the page rather than below its edge. It cannot invent that height:\n * every element from the page root down sizes as a percentage of its parent,\n * so **some ancestor has to have a definite height**.\n *\n * ```tsx\n * // ✅ the router outlet, a sized container, or a flex child with min-height\n * <div style={{ height: '100vh' }}>\n * <DataPage … />\n * </div>\n *\n * // ❌ nothing above resolves to a height — the table grows to its content\n * <div>\n * <DataPage … />\n * </div>\n * ```\n *\n * Without one, the page falls back to a small fixed height so it stays\n * usable instead of collapsing to nothing.\n *\n * ## Styling\n *\n * The inner DataTable and action toolbar each have their own per-slot props:\n * `tablePt` / `tableUnstyled` / `tableClassName` for the table;\n * `paginatorPt` / `paginatorClassName` / `paginatorAriaLabels` for paging;\n * `menubarPt` / `menubarPtOptions` / `menubarUnstyled` / `menubarClassName` for\n * the action toolbar's stable button parts (the action bar is implemented as\n * a button toolbar, so `menubarPt` targets the stable Cratis button parts). See the\n * [pass-through cheat sheet](../../Documentation/Styling/pass-through.md) for\n * the full slot reference.\n *\n * @typeParam TQuery - The query class (proxy generated from a C# read model query).\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n * @param props - {@link DataPageProps}.\n */\nconst DataPage = <\n TQuery extends\n | IQueryFor<TDataType, TArguments>\n | IQueryFor<TDataType[], TArguments>\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n>(\n props: DataPageProps<TQuery, TDataType, TArguments>,\n) => {\n const [internalSelection, setInternalSelection] = React.useState<\n TDataType | null | undefined\n >(props.selection);\n const selectedItem =\n props.selection === undefined ? internalSelection : props.selection;\n\n const selectionChanged = (event: DataTableSelectionChangeEvent<TDataType>) => {\n if (props.selection === undefined) setInternalSelection(event.value);\n props.onSelectionChange?.(event);\n };\n\n const [internalSelectedItems, setInternalSelectedItems] = React.useState<TDataType[]>(\n props.selectedItems ?? [],\n );\n const selectedItems = props.selectedItems ?? internalSelectedItems;\n\n const selectedItemsChanged = (items: TDataType[]) => {\n if (props.selectedItems === undefined) setInternalSelectedItems(items);\n props.onSelectedItemsChange?.(items);\n };\n\n // SAFETY: React context cannot retain this component's generic parameters. The\n // provider and every consumer are nested in the same DataPage invocation, so the\n // erased object-level context never crosses between differently typed pages.\n const context = {\n ...props,\n selectedItem,\n onSelectionChanged: selectionChanged,\n selectedItems,\n onSelectedItemsChange: selectedItemsChanged,\n } as unknown as IDataPageContext;\n\n return (\n <DataPageContext.Provider value={context}>\n <Page title={props.title} landmark={props.landmark} panel={true} style={pageStyle} data-cratis-component='DataPage'>\n {props.detailsComponent ? (\n <Allotment className='cratis:h-full' proportionalLayout={false}>\n <Allotment.Pane>\n <DataPageLayout>{props.children}</DataPageLayout>\n </Allotment.Pane>\n {selectedItem && (\n <Allotment.Pane preferredSize='450px'>\n <props.detailsComponent\n item={selectedItem}\n onRefresh={props.onRefresh}\n />\n </Allotment.Pane>\n )}\n </Allotment>\n ) : (\n <DataPageLayout>{props.children}</DataPageLayout>\n )}\n </Page>\n </DataPageContext.Provider>\n );\n};\n\nDataPage.MenuItem = MenuItem;\nDataPage.MenuItems = MenuItems;\nDataPage.Columns = Columns;\n\nexport { DataPage };\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;AAgEO,MAAM,QAAQ,GAAG,CAAqC,MAAgC,KAAI;AAC7F,IAAA,OAAO,IAAI;AACf;AAuBA,MAAM,YAAY,GAAkB,EAAE,UAAU,EAAE,C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menu action is rendered.
|
|
3
|
+
* The container and multiple-selection array are immutable; application row
|
|
4
|
+
* objects are not deep-frozen. Narrow `selectionMode` before accessing the row(s).
|
|
5
|
+
*
|
|
6
|
+
* @typeParam TDataType - The page's row type, supplied explicitly on `DataPage.MenuItem`.
|
|
7
|
+
*/
|
|
8
|
+
export type DataPageSelection<TDataType extends object = object> = {
|
|
9
|
+
/** A page that selects one row at a time. */
|
|
10
|
+
readonly selectionMode: 'single';
|
|
11
|
+
/** The selected row, or null/undefined when nothing is selected. */
|
|
12
|
+
readonly selectedItem: TDataType | null | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
/** A page that selects multiple rows. */
|
|
15
|
+
readonly selectionMode: 'multiple';
|
|
16
|
+
/** The selected rows at render time, copied independently of the page's array. */
|
|
17
|
+
readonly selectedItems: readonly TDataType[];
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=DataPageSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataPageSelection.d.ts","sourceRoot":"","sources":["../../../DataPage/DataPageSelection.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,IACzD;IACE,6CAA6C;IAC7C,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC;IACjC,oEAAoE;IACpE,QAAQ,CAAC,YAAY,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;CACvD,GACC;IACE,yCAAyC;IACzC,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACnC,kFAAkF;IAClF,QAAQ,CAAC,aAAa,EAAE,SAAS,SAAS,EAAE,CAAC;CAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataPageSelection.js","sourceRoot":"","sources":["../../../DataPage/DataPageSelection.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG","sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * The selection committed by a {@link DataPage} when a menu action is rendered.\n * The container and multiple-selection array are immutable; application row\n * objects are not deep-frozen. Narrow `selectionMode` before accessing the row(s).\n *\n * @typeParam TDataType - The page's row type, supplied explicitly on `DataPage.MenuItem`.\n */\nexport type DataPageSelection<TDataType extends object = object> =\n | {\n /** A page that selects one row at a time. */\n readonly selectionMode: 'single';\n /** The selected row, or null/undefined when nothing is selected. */\n readonly selectedItem: TDataType | null | undefined;\n }\n | {\n /** A page that selects multiple rows. */\n readonly selectionMode: 'multiple';\n /** The selected rows at render time, copied independently of the page's array. */\n readonly selectedItems: readonly TDataType[];\n };\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ActionMenuItem } from '../Common/ActionMenubar.js';
|
|
2
|
+
import type { MenuItemProps } from './DataPage.js';
|
|
3
|
+
import type { DataPageSelection } from './DataPageSelection.js';
|
|
4
|
+
export declare function adaptMenuItem(props: MenuItemProps, selection: DataPageSelection): ActionMenuItem;
|
|
5
|
+
//# sourceMappingURL=adaptMenuItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptMenuItem.d.ts","sourceRoot":"","sources":["../../../DataPage/adaptMenuItem.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAY,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAqB,CAAC;AAE7D,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,iBAAiB,GAAG,cAAc,CAgBhG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
function adaptMenuItem(props, selection) {
|
|
4
|
+
const Icon = props.icon;
|
|
5
|
+
const unselected = selection.selectionMode === 'multiple'
|
|
6
|
+
? selection.selectedItems.length === 0
|
|
7
|
+
: !selection.selectedItem;
|
|
8
|
+
const disabled = (typeof props.disabled === 'function' ? props.disabled(selection) : props.disabled ?? false)
|
|
9
|
+
|| (unselected && (props.disableOnUnselected ?? false));
|
|
10
|
+
return {
|
|
11
|
+
label: props.label,
|
|
12
|
+
icon: Icon ? jsx(Icon, { className: 'cratis:mr-2' }) : undefined,
|
|
13
|
+
disabled,
|
|
14
|
+
command: () => {
|
|
15
|
+
if (!disabled)
|
|
16
|
+
props.command?.(selection);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { adaptMenuItem };
|
|
22
|
+
//# sourceMappingURL=adaptMenuItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptMenuItem.js","sources":["../../../DataPage/adaptMenuItem.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { ActionMenuItem } from '../Common/ActionMenubar';\nimport type { MenuItemProps } from './DataPage';\nimport type { DataPageSelection } from './DataPageSelection';\n\nexport function adaptMenuItem(props: MenuItemProps, selection: DataPageSelection): ActionMenuItem {\n const Icon = props.icon;\n const unselected = selection.selectionMode === 'multiple'\n ? selection.selectedItems.length === 0\n : !selection.selectedItem;\n const disabled = (typeof props.disabled === 'function' ? props.disabled(selection) : props.disabled ?? false)\n || (unselected && (props.disableOnUnselected ?? false));\n\n return {\n label: props.label,\n icon: Icon ? <Icon className='cratis:mr-2' /> : undefined,\n disabled,\n command: () => {\n if (!disabled) props.command?.(selection);\n },\n };\n}\n"],"names":["_jsx"],"mappings":";;AAOM,SAAU,aAAa,CAAC,KAAoB,EAAE,SAA4B,EAAA;AAC5E,IAAA,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI;AACvB,IAAA,MAAM,UAAU,GAAG,SAAS,CAAC,aAAa,KAAK;AAC3C,UAAE,SAAS,CAAC,aAAa,CAAC,MAAM,KAAK;AACrC,UAAE,CAAC,SAAS,CAAC,YAAY;IAC7B,MAAM,QAAQ,GAAG,CAAC,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK;YACpG,UAAU,KAAK,KAAK,CAAC,mBAAmB,IAAI,KAAK,CAAC,CAAC;IAE3D,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,KAAK;AAClB,QAAA,IAAI,EAAE,IAAI,GAAGA,GAAA,CAAC,IAAI,EAAA,EAAC,SAAS,EAAC,aAAa,EAAA,CAAG,GAAG,SAAS;QACzD,QAAQ;QACR,OAAO,EAAE,MAAK;AACV,YAAA,IAAI,CAAC,QAAQ;AAAE,gBAAA,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC;QAC7C,CAAC;KACJ;AACL;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../DataPage/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAY,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../DataPage/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAY,CAAC;AAC3B,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAqB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAsB,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
+
import { measureProbe, probeStyle } from '../renderer/fixedProbe.js';
|
|
1
2
|
import { type DropdownPosition } from './utils.js';
|
|
3
|
+
export { measureProbe, probeStyle };
|
|
2
4
|
/** Fixed-position panel placement, optionally with a clamped CSS width. */
|
|
3
5
|
export type PanelPosition = DropdownPosition & {
|
|
4
6
|
width?: number;
|
|
5
7
|
};
|
|
6
|
-
/** Edges of a fixed-position probe's containing block. */
|
|
7
|
-
interface ProbeEdges {
|
|
8
|
-
origin: DOMRect;
|
|
9
|
-
bottom: number;
|
|
10
|
-
right: number;
|
|
11
|
-
}
|
|
12
8
|
/** The probes (and the elements they sit in) the panel placement is measured against. */
|
|
13
9
|
export interface PlacementTargets {
|
|
14
10
|
probe: HTMLDivElement;
|
|
@@ -18,14 +14,9 @@ export interface PlacementTargets {
|
|
|
18
14
|
panel: HTMLDivElement;
|
|
19
15
|
anchor: HTMLButtonElement;
|
|
20
16
|
}
|
|
21
|
-
/** Inline style that makes an element a fixed, invisible, 1px probe. */
|
|
22
|
-
export declare const probeStyle = "position:fixed;left:0;top:0;width:1px;height:1px;margin:0;padding:0;border:0;visibility:hidden;pointer-events:none";
|
|
23
|
-
/** Measures the origin, bottom and right edges of a fixed probe's containing block. */
|
|
24
|
-
export declare function measureProbe(element: HTMLDivElement): ProbeEdges;
|
|
25
17
|
/**
|
|
26
18
|
* Computes where the fixed-position panel belongs so it stays attached to its anchor
|
|
27
19
|
* and clamped inside the viewport (or the modal that clips it).
|
|
28
20
|
*/
|
|
29
21
|
export declare function measurePanelPlacement(targets: PlacementTargets): PanelPosition;
|
|
30
|
-
export {};
|
|
31
22
|
//# sourceMappingURL=measurePanelPlacement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measurePanelPlacement.d.ts","sourceRoot":"","sources":["../../../Filter/measurePanelPlacement.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,KAAK,gBAAgB,EAAE,MAAM,YAAS,CAAC;AAEzE,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,
|
|
1
|
+
{"version":3,"file":"measurePanelPlacement.d.ts","sourceRoot":"","sources":["../../../Filter/measurePanelPlacement.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAmB,MAAM,2BAAwB,CAAC;AACnF,OAAO,EAA2B,KAAK,gBAAgB,EAAE,MAAM,YAAS,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAEpC,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,yFAAyF;AACzF,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,eAAe,EAAE,WAAW,CAAC;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,iBAAiB,CAAC;CAC7B;AAqHD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAoC9E"}
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
+
import { measureProbe } from '../renderer/fixedProbe.js';
|
|
2
|
+
export { probeStyle } from '../renderer/fixedProbe.js';
|
|
1
3
|
import { resolveDropdownPosition } from './utils.js';
|
|
2
4
|
|
|
3
|
-
const probeStyle = 'position:fixed;left:0;top:0;width:1px;height:1px;margin:0;padding:0;border:0;visibility:hidden;pointer-events:none';
|
|
4
5
|
const edgeTolerance = 0.5;
|
|
5
6
|
const viewportGutter = 32;
|
|
6
|
-
function measureProbe(element) {
|
|
7
|
-
element.style.top = '0';
|
|
8
|
-
element.style.bottom = 'auto';
|
|
9
|
-
const origin = element.getBoundingClientRect();
|
|
10
|
-
element.style.top = 'auto';
|
|
11
|
-
element.style.bottom = '0';
|
|
12
|
-
const bottom = element.getBoundingClientRect().bottom;
|
|
13
|
-
element.style.bottom = 'auto';
|
|
14
|
-
element.style.left = 'auto';
|
|
15
|
-
element.style.right = '0';
|
|
16
|
-
const right = element.getBoundingClientRect().right;
|
|
17
|
-
element.style.left = '0';
|
|
18
|
-
element.style.right = 'auto';
|
|
19
|
-
return { origin, bottom, right };
|
|
20
|
-
}
|
|
21
7
|
function readViewport() {
|
|
22
8
|
const viewportElement = document.compatMode === 'BackCompat' ? document.body : document.documentElement;
|
|
23
9
|
return {
|
|
@@ -128,5 +114,5 @@ function measurePanelPlacement(targets) {
|
|
|
128
114
|
};
|
|
129
115
|
}
|
|
130
116
|
|
|
131
|
-
export { measurePanelPlacement, measureProbe
|
|
117
|
+
export { measurePanelPlacement, measureProbe };
|
|
132
118
|
//# sourceMappingURL=measurePanelPlacement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measurePanelPlacement.js","sources":["../../../Filter/measurePanelPlacement.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { resolveDropdownPosition, type DropdownPosition } from './utils';\n\n/** Fixed-position panel placement, optionally with a clamped CSS width. */\nexport type PanelPosition = DropdownPosition & { width?: number };\n\n/** Edges of a fixed-position probe's containing block. */\ninterface ProbeEdges {\n origin: DOMRect;\n bottom: number;\n right: number;\n}\n\n/** The probes (and the elements they sit in) the panel placement is measured against. */\nexport interface PlacementTargets {\n probe: HTMLDivElement;\n rootProbe: HTMLDivElement | null;\n modalRoot: HTMLElement | null | undefined;\n portalContainer: HTMLElement;\n panel: HTMLDivElement;\n anchor: HTMLButtonElement;\n}\n\n/** Inline style that makes an element a fixed, invisible, 1px probe. */\nexport const probeStyle = 'position:fixed;left:0;top:0;width:1px;height:1px;margin:0;padding:0;border:0;visibility:hidden;pointer-events:none';\n\nconst edgeTolerance = 0.5;\nconst viewportGutter = 32;\n\n/** Measures the origin, bottom and right edges of a fixed probe's containing block. */\nexport function measureProbe(element: HTMLDivElement): ProbeEdges {\n element.style.top = '0';\n element.style.bottom = 'auto';\n const origin = element.getBoundingClientRect();\n element.style.top = 'auto';\n element.style.bottom = '0';\n const bottom = element.getBoundingClientRect().bottom;\n element.style.bottom = 'auto';\n element.style.left = 'auto';\n element.style.right = '0';\n const right = element.getBoundingClientRect().right;\n element.style.left = '0';\n element.style.right = 'auto';\n return { origin, bottom, right };\n}\n\n/** Layoutless renderers report zero; browser layout uses the scrollbar-free viewport. */\nfunction readViewport(): { width: number; height: number } {\n // In quirks mode the viewport's client size is reported on the body, not the root.\n const viewportElement = document.compatMode === 'BackCompat' ? document.body : document.documentElement;\n return {\n width: viewportElement.clientWidth || window.innerWidth,\n height: viewportElement.clientHeight || window.innerHeight,\n };\n}\n\n/** Properties whose non-\"none\" value makes an element the containing block of fixed descendants. */\nconst fixedContainingProperties = ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter'] as const;\n\nconst containLayoutPattern = /\\b(?:layout|paint|strict|content)\\b/u;\nconst containerTypePattern = /^(?:size|inline-size)$/u;\nconst willChangePattern = /\\b(?:transform|translate|scale|rotate|perspective|filter|backdrop-filter|contain|container-type)\\b/u;\n\nfunction hasBackdropFilter(rootStyle: CSSStyleDeclaration): boolean {\n return rootStyle.getPropertyValue('backdrop-filter') !== 'none' &&\n rootStyle.getPropertyValue('backdrop-filter') !== '';\n}\n\nfunction hasFixedContainingStyle(rootStyle: CSSStyleDeclaration): boolean {\n if (fixedContainingProperties.some(property => rootStyle[property] !== 'none')) return true;\n if (hasBackdropFilter(rootStyle)) return true;\n return containLayoutPattern.test(rootStyle.contain) ||\n containerTypePattern.test(rootStyle.getPropertyValue('container-type')) ||\n willChangePattern.test(rootStyle.willChange);\n}\n\n/**\n * A fixed probe spans its containing block, not the Dialog's overflow box.\n * Compare all four edges to the root's padding box: a side dialog can share\n * the positioner's top-left origin without sharing its containing block.\n * Comparing to innerWidth/innerHeight instead would mistake classic scrollbars\n * (excluded from the layout viewport) for a transformed containing block.\n */\nfunction edgesMatchPaddingBox(\n rootEdges: ProbeEdges,\n rootRect: DOMRect,\n rootStyle: CSSStyleDeclaration,\n scaleX: number,\n scaleY: number,\n): boolean {\n // Lazy checks: each edge is read only when the previous edges matched.\n const edgeChecks: Array<() => boolean> = [\n () => Math.abs(rootEdges.origin.left - (rootRect.left + parseFloat(rootStyle.borderLeftWidth) * scaleX)) <= edgeTolerance,\n () => Math.abs(rootEdges.origin.top - (rootRect.top + parseFloat(rootStyle.borderTopWidth) * scaleY)) <= edgeTolerance,\n () => Math.abs(rootEdges.right - (rootRect.right - parseFloat(rootStyle.borderRightWidth) * scaleX)) <= edgeTolerance,\n () => Math.abs(rootEdges.bottom - (rootRect.bottom - parseFloat(rootStyle.borderBottomWidth) * scaleY)) <= edgeTolerance,\n ];\n return edgeChecks.every(check => check());\n}\n\nfunction edgesDiffer(probeEdges: ProbeEdges, rootEdges: ProbeEdges): boolean {\n // Lazy checks: each edge is read only when the previous edges did not differ.\n const edgeChecks: Array<() => boolean> = [\n () => Math.abs(probeEdges.origin.left - rootEdges.origin.left) > edgeTolerance,\n () => Math.abs(probeEdges.origin.top - rootEdges.origin.top) > edgeTolerance,\n () => Math.abs(probeEdges.right - rootEdges.right) > edgeTolerance,\n () => Math.abs(probeEdges.bottom - rootEdges.bottom) > edgeTolerance,\n ];\n return edgeChecks.some(check => check());\n}\n\n/** Layoutless environments cannot supply a modal clip rect. */\nfunction hasLayout(rect: DOMRect): boolean {\n return rect.right > rect.left && rect.bottom > rect.top;\n}\n\n/** The modal's rect when the modal or the portal's descendant block owns the fixed containing block. */\nfunction resolveModalClip(\n targets: PlacementTargets,\n edges: ProbeEdges,\n): DOMRect | null {\n const { modalRoot, portalContainer, rootProbe } = targets;\n if (!modalRoot || !modalRoot.contains(portalContainer)) return null;\n const rootRect = modalRoot.getBoundingClientRect();\n const rootEdges = rootProbe ? measureProbe(rootProbe) : edges;\n const rootStyle = getComputedStyle(modalRoot);\n const rootScaleX = rootEdges.origin.width;\n const rootScaleY = rootEdges.origin.height;\n // Axis-aligned bounding rects lose the padding origin under rotation/skew.\n // The root's own containing-block properties cover those cases; the probe\n // comparison below still handles nested portal containers geometrically.\n const rootOwnsBlock = hasFixedContainingStyle(rootStyle) ||\n edgesMatchPaddingBox(rootEdges, rootRect, rootStyle, rootScaleX, rootScaleY);\n // Evaluated even when the root owns the block, as the probe edges are always compared.\n const descendantOwnsBlock = rootProbe !== null && edgesDiffer(edges, rootEdges);\n const ownsBlock = rootOwnsBlock || descendantOwnsBlock;\n return ownsBlock && hasLayout(rootRect) ? rootRect : null;\n}\n\n/** The viewport rectangle, narrowed to the modal clip when there is one. */\nfunction resolveBounds(viewport: { width: number; height: number }, clip: DOMRect | null) {\n return {\n left: Math.max(0, clip?.left ?? 0),\n top: Math.max(0, clip?.top ?? 0),\n right: Math.min(viewport.width, clip?.right ?? viewport.width),\n bottom: Math.min(viewport.height, clip?.bottom ?? viewport.height),\n };\n}\n\n/** Measures the CSS width without a previous resize's inline clamp applied. */\nfunction measureCssWidth(panel: HTMLDivElement): number {\n const previousWidth = panel.style.width;\n if (previousWidth) panel.style.width = '';\n const cssWidth = panel.offsetWidth;\n if (previousWidth) panel.style.width = previousWidth;\n return cssWidth;\n}\n\n/**\n * Computes where the fixed-position panel belongs so it stays attached to its anchor\n * and clamped inside the viewport (or the modal that clips it).\n */\nexport function measurePanelPlacement(targets: PlacementTargets): PanelPosition {\n const { probe, panel, anchor: anchorElement } = targets;\n // The probe stays mounted while open, but its origin must be read on every\n // update: scrolling a transformed ancestor changes its viewport coordinates.\n const edges = measureProbe(probe);\n const { origin, bottom: containingBlockBottom } = edges;\n\n // offsetWidth is in local CSS pixels; the probe's rect supplies the viewport scale.\n // Preserve the viewport gutter even when a containing block scales the dropdown.\n const scaleX = origin.width || 1;\n const scaleY = origin.height || 1;\n const viewport = readViewport();\n const clip = resolveModalClip(targets, edges);\n const bounds = resolveBounds(viewport, clip);\n const visible = {\n width: Math.max(0, bounds.right - bounds.left),\n height: Math.max(0, bounds.bottom - bounds.top),\n };\n const cssWidth = measureCssWidth(panel);\n const width = cssWidth * scaleX > visible.width - viewportGutter\n ? Math.max(0, (visible.width - viewportGutter) / scaleX)\n : undefined;\n const anchor = anchorElement.getBoundingClientRect();\n const viewportPosition = resolveDropdownPosition({\n left: anchor.left - bounds.left,\n top: anchor.top - bounds.top,\n bottom: anchor.bottom - bounds.top,\n }, visible, (width ?? cssWidth) * scaleX);\n return {\n left: (bounds.left + viewportPosition.left - origin.left) / scaleX,\n top: viewportPosition.top === undefined ? undefined : (bounds.top + viewportPosition.top - origin.top) / scaleY,\n bottom: viewportPosition.bottom === undefined ? undefined\n : (containingBlockBottom - (bounds.bottom - viewportPosition.bottom)) / scaleY,\n maxHeight: viewportPosition.maxHeight / scaleY,\n width,\n };\n}\n"],"names":[],"mappings":";;AA0BO,MAAM,UAAU,GAAG;AAE1B,MAAM,aAAa,GAAG,GAAG;AACzB,MAAM,cAAc,GAAG,EAAE;AAGnB,SAAU,YAAY,CAAC,OAAuB,EAAA;AAChD,IAAA,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG;AACvB,IAAA,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM;AAC7B,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE;AAC9C,IAAA,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM;AAC1B,IAAA,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,MAAM;AACrD,IAAA,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM;AAC7B,IAAA,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM;AAC3B,IAAA,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAK;AACnD,IAAA,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG;AACxB,IAAA,OAAO,CAAC,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EAAE,gBAAgB,CAAC,GAAG,KAAK,SAAS,GAAG,SAAS,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,gBAAgB,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,MAAM;QAC/G,MAAM,EAAE,gBAAgB,CAAC,MAAM,KAAK,SAAS,GAAG;AAC5C,cAAE,CAAC,qBAAqB,IAAI,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,MAAM;AAClF,QAAA,SAAS,EAAE,gBAAgB,CAAC,SAAS,GAAG,MAAM;QAC9C,KAAK;KACR;AACL;;"}
|
|
1
|
+
{"version":3,"file":"measurePanelPlacement.js","sources":["../../../Filter/measurePanelPlacement.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { measureProbe, probeStyle, type ProbeEdges } from '../renderer/fixedProbe';\nimport { resolveDropdownPosition, type DropdownPosition } from './utils';\n\nexport { measureProbe, probeStyle };\n\n/** Fixed-position panel placement, optionally with a clamped CSS width. */\nexport type PanelPosition = DropdownPosition & { width?: number };\n\n/** The probes (and the elements they sit in) the panel placement is measured against. */\nexport interface PlacementTargets {\n probe: HTMLDivElement;\n rootProbe: HTMLDivElement | null;\n modalRoot: HTMLElement | null | undefined;\n portalContainer: HTMLElement;\n panel: HTMLDivElement;\n anchor: HTMLButtonElement;\n}\n\nconst edgeTolerance = 0.5;\nconst viewportGutter = 32;\n\n/** Layoutless renderers report zero; browser layout uses the scrollbar-free viewport. */\nfunction readViewport(): { width: number; height: number } {\n // In quirks mode the viewport's client size is reported on the body, not the root.\n const viewportElement = document.compatMode === 'BackCompat' ? document.body : document.documentElement;\n return {\n width: viewportElement.clientWidth || window.innerWidth,\n height: viewportElement.clientHeight || window.innerHeight,\n };\n}\n\n/** Properties whose non-\"none\" value makes an element the containing block of fixed descendants. */\nconst fixedContainingProperties = ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter'] as const;\n\nconst containLayoutPattern = /\\b(?:layout|paint|strict|content)\\b/u;\nconst containerTypePattern = /^(?:size|inline-size)$/u;\nconst willChangePattern = /\\b(?:transform|translate|scale|rotate|perspective|filter|backdrop-filter|contain|container-type)\\b/u;\n\nfunction hasBackdropFilter(rootStyle: CSSStyleDeclaration): boolean {\n return rootStyle.getPropertyValue('backdrop-filter') !== 'none' &&\n rootStyle.getPropertyValue('backdrop-filter') !== '';\n}\n\nfunction hasFixedContainingStyle(rootStyle: CSSStyleDeclaration): boolean {\n if (fixedContainingProperties.some(property => rootStyle[property] !== 'none')) return true;\n if (hasBackdropFilter(rootStyle)) return true;\n return containLayoutPattern.test(rootStyle.contain) ||\n containerTypePattern.test(rootStyle.getPropertyValue('container-type')) ||\n willChangePattern.test(rootStyle.willChange);\n}\n\n/**\n * A fixed probe spans its containing block, not the Dialog's overflow box.\n * Compare all four edges to the root's padding box: a side dialog can share\n * the positioner's top-left origin without sharing its containing block.\n * Comparing to innerWidth/innerHeight instead would mistake classic scrollbars\n * (excluded from the layout viewport) for a transformed containing block.\n */\nfunction edgesMatchPaddingBox(\n rootEdges: ProbeEdges,\n rootRect: DOMRect,\n rootStyle: CSSStyleDeclaration,\n scaleX: number,\n scaleY: number,\n): boolean {\n // Lazy checks: each edge is read only when the previous edges matched.\n const edgeChecks: Array<() => boolean> = [\n () => Math.abs(rootEdges.origin.left - (rootRect.left + parseFloat(rootStyle.borderLeftWidth) * scaleX)) <= edgeTolerance,\n () => Math.abs(rootEdges.origin.top - (rootRect.top + parseFloat(rootStyle.borderTopWidth) * scaleY)) <= edgeTolerance,\n () => Math.abs(rootEdges.right - (rootRect.right - parseFloat(rootStyle.borderRightWidth) * scaleX)) <= edgeTolerance,\n () => Math.abs(rootEdges.bottom - (rootRect.bottom - parseFloat(rootStyle.borderBottomWidth) * scaleY)) <= edgeTolerance,\n ];\n return edgeChecks.every(check => check());\n}\n\nfunction edgesDiffer(probeEdges: ProbeEdges, rootEdges: ProbeEdges): boolean {\n // Lazy checks: each edge is read only when the previous edges did not differ.\n const edgeChecks: Array<() => boolean> = [\n () => Math.abs(probeEdges.origin.left - rootEdges.origin.left) > edgeTolerance,\n () => Math.abs(probeEdges.origin.top - rootEdges.origin.top) > edgeTolerance,\n () => Math.abs(probeEdges.right - rootEdges.right) > edgeTolerance,\n () => Math.abs(probeEdges.bottom - rootEdges.bottom) > edgeTolerance,\n ];\n return edgeChecks.some(check => check());\n}\n\n/** Layoutless environments cannot supply a modal clip rect. */\nfunction hasLayout(rect: DOMRect): boolean {\n return rect.right > rect.left && rect.bottom > rect.top;\n}\n\n/** The modal's rect when the modal or the portal's descendant block owns the fixed containing block. */\nfunction resolveModalClip(\n targets: PlacementTargets,\n edges: ProbeEdges,\n): DOMRect | null {\n const { modalRoot, portalContainer, rootProbe } = targets;\n if (!modalRoot || !modalRoot.contains(portalContainer)) return null;\n const rootRect = modalRoot.getBoundingClientRect();\n const rootEdges = rootProbe ? measureProbe(rootProbe) : edges;\n const rootStyle = getComputedStyle(modalRoot);\n const rootScaleX = rootEdges.origin.width;\n const rootScaleY = rootEdges.origin.height;\n // Axis-aligned bounding rects lose the padding origin under rotation/skew.\n // The root's own containing-block properties cover those cases; the probe\n // comparison below still handles nested portal containers geometrically.\n const rootOwnsBlock = hasFixedContainingStyle(rootStyle) ||\n edgesMatchPaddingBox(rootEdges, rootRect, rootStyle, rootScaleX, rootScaleY);\n // Evaluated even when the root owns the block, as the probe edges are always compared.\n const descendantOwnsBlock = rootProbe !== null && edgesDiffer(edges, rootEdges);\n const ownsBlock = rootOwnsBlock || descendantOwnsBlock;\n return ownsBlock && hasLayout(rootRect) ? rootRect : null;\n}\n\n/** The viewport rectangle, narrowed to the modal clip when there is one. */\nfunction resolveBounds(viewport: { width: number; height: number }, clip: DOMRect | null) {\n return {\n left: Math.max(0, clip?.left ?? 0),\n top: Math.max(0, clip?.top ?? 0),\n right: Math.min(viewport.width, clip?.right ?? viewport.width),\n bottom: Math.min(viewport.height, clip?.bottom ?? viewport.height),\n };\n}\n\n/** Measures the CSS width without a previous resize's inline clamp applied. */\nfunction measureCssWidth(panel: HTMLDivElement): number {\n const previousWidth = panel.style.width;\n if (previousWidth) panel.style.width = '';\n const cssWidth = panel.offsetWidth;\n if (previousWidth) panel.style.width = previousWidth;\n return cssWidth;\n}\n\n/**\n * Computes where the fixed-position panel belongs so it stays attached to its anchor\n * and clamped inside the viewport (or the modal that clips it).\n */\nexport function measurePanelPlacement(targets: PlacementTargets): PanelPosition {\n const { probe, panel, anchor: anchorElement } = targets;\n // The probe stays mounted while open, but its origin must be read on every\n // update: scrolling a transformed ancestor changes its viewport coordinates.\n const edges = measureProbe(probe);\n const { origin, bottom: containingBlockBottom } = edges;\n\n // offsetWidth is in local CSS pixels; the probe's rect supplies the viewport scale.\n // Preserve the viewport gutter even when a containing block scales the dropdown.\n const scaleX = origin.width || 1;\n const scaleY = origin.height || 1;\n const viewport = readViewport();\n const clip = resolveModalClip(targets, edges);\n const bounds = resolveBounds(viewport, clip);\n const visible = {\n width: Math.max(0, bounds.right - bounds.left),\n height: Math.max(0, bounds.bottom - bounds.top),\n };\n const cssWidth = measureCssWidth(panel);\n const width = cssWidth * scaleX > visible.width - viewportGutter\n ? Math.max(0, (visible.width - viewportGutter) / scaleX)\n : undefined;\n const anchor = anchorElement.getBoundingClientRect();\n const viewportPosition = resolveDropdownPosition({\n left: anchor.left - bounds.left,\n top: anchor.top - bounds.top,\n bottom: anchor.bottom - bounds.top,\n }, visible, (width ?? cssWidth) * scaleX);\n return {\n left: (bounds.left + viewportPosition.left - origin.left) / scaleX,\n top: viewportPosition.top === undefined ? undefined : (bounds.top + viewportPosition.top - origin.top) / scaleY,\n bottom: viewportPosition.bottom === undefined ? undefined\n : (containingBlockBottom - (bounds.bottom - viewportPosition.bottom)) / scaleY,\n maxHeight: viewportPosition.maxHeight / scaleY,\n width,\n };\n}\n"],"names":[],"mappings":";;;;AAqBA,MAAM,aAAa,GAAG,GAAG;AACzB,MAAM,cA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GAAG,gBAAgB,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,MAAM;QAC/G,MAAM,EAAE,gBAAgB,CAAC,MAAM,KAAK,SAAS,GAAG;AAC5C,cAAE,CAAC,qBAAqB,IAAI,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,MAAM;AAClF,QAAA,SAAS,EAAE,gBAAgB,CAAC,SAAS,GAAG,MAAM;QAC9C,KAAK;KACR;AACL;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useLayoutEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { measurePanelPlacement } from './measurePanelPlacement.js';
|
|
3
|
+
import { probeStyle } from '../renderer/fixedProbe.js';
|
|
3
4
|
|
|
4
5
|
const motionEvents = ['animationend', 'animationcancel', 'transitionend'];
|
|
5
6
|
function usePanelPosition({ isOpen, portalContainer, modalRoot, anchorRef, panelRef, resolvedAnchor, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePanelPosition.js","sources":["../../../Filter/usePanelPosition.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useLayoutEffect, useState } from 'react';\nimport type { RefObject } from 'react';\nimport {\n measurePanelPlacement,\n probeStyle,\n type PanelPosition,\n} from './measurePanelPlacement';\n\nconst motionEvents = ['animationend', 'animationcancel', 'transitionend'] as const;\n\n/** What the panel position tracks. */\nexport interface UsePanelPositionOptions {\n isOpen: boolean;\n portalContainer: HTMLElement | null;\n modalRoot: HTMLElement | null | undefined;\n anchorRef: RefObject<HTMLButtonElement | null>;\n panelRef: RefObject<HTMLDivElement | null>;\n /** The resolved anchor element; re-runs the effect when the anchor changes. */\n resolvedAnchor: HTMLButtonElement | null | undefined;\n}\n\n/**\n * Keeps the fixed-position portal attached to its anchor and clamped inside the viewport.\n * A transform (or other fixed containing-block property) on the portal container OR any\n * ancestor changes the meaning of CSS left/top/bottom. A fixed probe in the portal sees\n * exactly the same containing block as the panel, without guessing which ancestor owns it.\n * Capture-phase scroll observation also covers nested scrolling containers.\n *\n * @param options - What the position tracks.\n * @returns The current fixed-position placement of the panel.\n */\nexport function usePanelPosition({\n isOpen,\n portalContainer,\n modalRoot,\n anchorRef,\n panelRef,\n resolvedAnchor,\n}: UsePanelPositionOptions): PanelPosition {\n const [position, setPosition] = useState<PanelPosition>({\n top: 0,\n left: 0,\n maxHeight: 0,\n });\n\n useLayoutEffect(() => {\n if (!isOpen || !portalContainer) return;\n\n const probe = document.createElement('div');\n probe.style.cssText = probeStyle;\n portalContainer.appendChild(probe);\n // A portal inside (rather than directly on) the root can have a different fixed\n // containing block. A second probe distinguishes that descendant block from one\n // owned by the positioner outside the root.\n const rootProbe = modalRoot && modalRoot.contains(portalContainer) && portalContainer !== modalRoot\n ? document.createElement('div') : null;\n if (rootProbe && modalRoot) {\n rootProbe.style.cssText = probeStyle;\n modalRoot.appendChild(rootProbe);\n }\n\n const updatePosition = () => {\n const anchor = anchorRef.current;\n const panel = panelRef.current;\n if (!anchor || !panel) return;\n\n const nextPosition = measurePanelPlacement({\n probe,\n rootProbe,\n modalRoot,\n portalContainer,\n panel,\n anchor,\n });\n setPosition((previous) => previous.left === nextPosition.left &&\n previous.top === nextPosition.top && previous.bottom === nextPosition.bottom &&\n previous.maxHeight === nextPosition.maxHeight && previous.width === nextPosition.width\n ? previous : nextPosition);\n };\n\n // A Dialog's entry motion may change the fixed-position containing block.\n // Measure again when its root or positioner stops moving.\n let animationFrame: number | undefined;\n const schedulePosition = () => {\n if (animationFrame !== undefined) return;\n animationFrame = requestAnimationFrame(() => {\n animationFrame = undefined;\n updatePosition();\n });\n };\n const handleScroll = (event: Event) => {\n if (event.target instanceof Node && panelRef.current?.contains(event.target)) return;\n schedulePosition();\n };\n // Consumers may replace the Dialog's entry animation or animate its positioner.\n // Ignore events bubbling from controls inside the dialog; one frame is enough for\n // any number of animations or transitions ending in the same rendering frame.\n const positioner = modalRoot?.parentElement?.matches('[data-cratis-part=\"positioner\"]')\n ? modalRoot.parentElement : null;\n const handleModalMotionEnd = (event: Event) => {\n if (event.target === modalRoot || event.target === positioner) schedulePosition();\n };\n\n updatePosition();\n window.addEventListener('resize', schedulePosition);\n window.addEventListener('scroll', handleScroll, true);\n for (const eventName of motionEvents) {\n modalRoot?.addEventListener(eventName, handleModalMotionEnd);\n positioner?.addEventListener(eventName, handleModalMotionEnd);\n }\n\n return () => {\n if (animationFrame !== undefined) cancelAnimationFrame(animationFrame);\n window.removeEventListener('resize', schedulePosition);\n window.removeEventListener('scroll', handleScroll, true);\n for (const eventName of motionEvents) {\n modalRoot?.removeEventListener(eventName, handleModalMotionEnd);\n positioner?.removeEventListener(eventName, handleModalMotionEnd);\n }\n probe.remove();\n rootProbe?.remove();\n };\n }, [anchorRef, panelRef, isOpen, modalRoot, portalContainer, resolvedAnchor]);\n\n return position;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePanelPosition.js","sources":["../../../Filter/usePanelPosition.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useLayoutEffect, useState } from 'react';\nimport type { RefObject } from 'react';\nimport {\n measurePanelPlacement,\n probeStyle,\n type PanelPosition,\n} from './measurePanelPlacement';\n\nconst motionEvents = ['animationend', 'animationcancel', 'transitionend'] as const;\n\n/** What the panel position tracks. */\nexport interface UsePanelPositionOptions {\n isOpen: boolean;\n portalContainer: HTMLElement | null;\n modalRoot: HTMLElement | null | undefined;\n anchorRef: RefObject<HTMLButtonElement | null>;\n panelRef: RefObject<HTMLDivElement | null>;\n /** The resolved anchor element; re-runs the effect when the anchor changes. */\n resolvedAnchor: HTMLButtonElement | null | undefined;\n}\n\n/**\n * Keeps the fixed-position portal attached to its anchor and clamped inside the viewport.\n * A transform (or other fixed containing-block property) on the portal container OR any\n * ancestor changes the meaning of CSS left/top/bottom. A fixed probe in the portal sees\n * exactly the same containing block as the panel, without guessing which ancestor owns it.\n * Capture-phase scroll observation also covers nested scrolling containers.\n *\n * @param options - What the position tracks.\n * @returns The current fixed-position placement of the panel.\n */\nexport function usePanelPosition({\n isOpen,\n portalContainer,\n modalRoot,\n anchorRef,\n panelRef,\n resolvedAnchor,\n}: UsePanelPositionOptions): PanelPosition {\n const [position, setPosition] = useState<PanelPosition>({\n top: 0,\n left: 0,\n maxHeight: 0,\n });\n\n useLayoutEffect(() => {\n if (!isOpen || !portalContainer) return;\n\n const probe = document.createElement('div');\n probe.style.cssText = probeStyle;\n portalContainer.appendChild(probe);\n // A portal inside (rather than directly on) the root can have a different fixed\n // containing block. A second probe distinguishes that descendant block from one\n // owned by the positioner outside the root.\n const rootProbe = modalRoot && modalRoot.contains(portalContainer) && portalContainer !== modalRoot\n ? document.createElement('div') : null;\n if (rootProbe && modalRoot) {\n rootProbe.style.cssText = probeStyle;\n modalRoot.appendChild(rootProbe);\n }\n\n const updatePosition = () => {\n const anchor = anchorRef.current;\n const panel = panelRef.current;\n if (!anchor || !panel) return;\n\n const nextPosition = measurePanelPlacement({\n probe,\n rootProbe,\n modalRoot,\n portalContainer,\n panel,\n anchor,\n });\n setPosition((previous) => previous.left === nextPosition.left &&\n previous.top === nextPosition.top && previous.bottom === nextPosition.bottom &&\n previous.maxHeight === nextPosition.maxHeight && previous.width === nextPosition.width\n ? previous : nextPosition);\n };\n\n // A Dialog's entry motion may change the fixed-position containing block.\n // Measure again when its root or positioner stops moving.\n let animationFrame: number | undefined;\n const schedulePosition = () => {\n if (animationFrame !== undefined) return;\n animationFrame = requestAnimationFrame(() => {\n animationFrame = undefined;\n updatePosition();\n });\n };\n const handleScroll = (event: Event) => {\n if (event.target instanceof Node && panelRef.current?.contains(event.target)) return;\n schedulePosition();\n };\n // Consumers may replace the Dialog's entry animation or animate its positioner.\n // Ignore events bubbling from controls inside the dialog; one frame is enough for\n // any number of animations or transitions ending in the same rendering frame.\n const positioner = modalRoot?.parentElement?.matches('[data-cratis-part=\"positioner\"]')\n ? modalRoot.parentElement : null;\n const handleModalMotionEnd = (event: Event) => {\n if (event.target === modalRoot || event.target === positioner) schedulePosition();\n };\n\n updatePosition();\n window.addEventListener('resize', schedulePosition);\n window.addEventListener('scroll', handleScroll, true);\n for (const eventName of motionEvents) {\n modalRoot?.addEventListener(eventName, handleModalMotionEnd);\n positioner?.addEventListener(eventName, handleModalMotionEnd);\n }\n\n return () => {\n if (animationFrame !== undefined) cancelAnimationFrame(animationFrame);\n window.removeEventListener('resize', schedulePosition);\n window.removeEventListener('scroll', handleScroll, true);\n for (const eventName of motionEvents) {\n modalRoot?.removeEventListener(eventName, handleModalMotionEnd);\n positioner?.removeEventListener(eventName, handleModalMotionEnd);\n }\n probe.remove();\n rootProbe?.remove();\n };\n }, [anchorRef, panelRef, isOpen, modalRoot, portalContainer, resolvedAnchor]);\n\n return position;\n}\n"],"names":[],"mappings":";;;;AAWA,MAAM,YAAY,GAAG,CAAC,cAAc,EAAE,iBAAiB,EAAE,eAAe,CAAU;AAuB5E,SAAU,gBAAgB,CAAC,EAC7B,MAAM,EACN,eAAe,EACf,SAAS,EACT,SAAS,EACT,QAAQ,EACR,cAAc,GACQ,EAAA;AACtB,IAAA,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAgB;AACpD,QAAA,GAAG,EAAE,CAAC;AACN,QAAA,IAAI,EAAE,CAAC;AACP,QAAA,SAAS,EAAE,CAAC;AACf,KAAA,CAAC;IAEF,eAAe,CAAC,MAAK;AACjB,QAAA,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe;YAAE;QAEjC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AAC3C,QAAA,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,UAAU;AAChC,QAAA,eAAe,CAAC,WAAW,CAAC,KAAK,CAAC;AAIlC,QAAA,MAAM,SAAS,GAAG,SAAS,IAAI,SAAS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B,QAAA,CAAC;AACL,IAAA,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,CAAC,CAAC;AAE7E,IAAA,OAAO,QAAQ;AACnB;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Edges of a fixed-position probe's containing block. */
|
|
2
|
+
export interface ProbeEdges {
|
|
3
|
+
origin: DOMRect;
|
|
4
|
+
bottom: number;
|
|
5
|
+
right: number;
|
|
6
|
+
}
|
|
7
|
+
/** Inline style that makes an element a fixed, invisible, 1px probe. */
|
|
8
|
+
export declare const probeStyle = "position:fixed;left:0;top:0;width:1px;height:1px;margin:0;padding:0;border:0;visibility:hidden;pointer-events:none";
|
|
9
|
+
/** Measures the origin, bottom and right edges of a fixed probe's containing block. */
|
|
10
|
+
export declare function measureProbe(element: HTMLDivElement): ProbeEdges;
|
|
11
|
+
//# sourceMappingURL=fixedProbe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixedProbe.d.ts","sourceRoot":"","sources":["../../../renderer/fixedProbe.ts"],"names":[],"mappings":"AAGA,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,wEAAwE;AACxE,eAAO,MAAM,UAAU,uHAAuH,CAAC;AAE/I,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,UAAU,CAchE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const probeStyle = 'position:fixed;left:0;top:0;width:1px;height:1px;margin:0;padding:0;border:0;visibility:hidden;pointer-events:none';
|
|
2
|
+
function measureProbe(element) {
|
|
3
|
+
element.style.top = '0';
|
|
4
|
+
element.style.bottom = 'auto';
|
|
5
|
+
const origin = element.getBoundingClientRect();
|
|
6
|
+
element.style.top = 'auto';
|
|
7
|
+
element.style.bottom = '0';
|
|
8
|
+
const bottom = element.getBoundingClientRect().bottom;
|
|
9
|
+
element.style.bottom = 'auto';
|
|
10
|
+
element.style.left = 'auto';
|
|
11
|
+
element.style.right = '0';
|
|
12
|
+
const right = element.getBoundingClientRect().right;
|
|
13
|
+
element.style.left = '0';
|
|
14
|
+
element.style.right = 'auto';
|
|
15
|
+
return { origin, bottom, right };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { measureProbe, probeStyle };
|
|
19
|
+
//# sourceMappingURL=fixedProbe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixedProbe.js","sources":["../../../renderer/fixedProbe.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/** Edges of a fixed-position probe's containing block. */\nexport interface ProbeEdges {\n origin: DOMRect;\n bottom: number;\n right: number;\n}\n\n/** Inline style that makes an element a fixed, invisible, 1px probe. */\nexport const probeStyle = 'position:fixed;left:0;top:0;width:1px;height:1px;margin:0;padding:0;border:0;visibility:hidden;pointer-events:none';\n\n/** Measures the origin, bottom and right edges of a fixed probe's containing block. */\nexport function measureProbe(element: HTMLDivElement): ProbeEdges {\n element.style.top = '0';\n element.style.bottom = 'auto';\n const origin = element.getBoundingClientRect();\n element.style.top = 'auto';\n element.style.bottom = '0';\n const bottom = element.getBoundingClientRect().bottom;\n element.style.bottom = 'auto';\n element.style.left = 'auto';\n element.style.right = '0';\n const right = element.getBoundingClientRect().right;\n element.style.left = '0';\n element.style.right = 'auto';\n return { origin, bottom, right };\n}\n"],"names":[],"mappings":"AAWO,MAAM,UAAU,GAAG;AAGpB,SAAU,YAAY,CAAC,OAAuB,EAAA;AAChD,IAAA,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG;AACvB,IAAA,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM;AAC7B,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE;AAC9C,IAAA,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM;AAC1B,IAAA,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,MAAM;AACrD,IAAA,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM;AAC7B,IAAA,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM;AAC3B,IAAA,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAK;AACnD,IAAA,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG;AACxB,IAAA,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM;AAC5B,IAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;AACpC;;"}
|
package/package.json
CHANGED