@delmaredigital/payload-experiments 0.4.0-rc.6 → 0.4.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/blocks/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +8 -4
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +7 -6
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +91 -37
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/PageWizard.js +1 -0
- package/dist/admin/surface/newTest/newTest.css +1 -1
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +3 -2
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +21 -7
- package/dist/blocks/placementLocale.js +218 -67
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- package/dist/endpoints/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +206 -0
- package/dist/endpoints/index.js +7 -0
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +6 -1
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/index.d.ts +1 -1
- package/dist/goals/fairness.js +38 -31
- package/dist/hooks/blockRemovalRule.d.ts +2 -2
- package/dist/hooks/blockRemovalRule.js +16 -14
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +33 -23
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +5 -1
- package/dist/puck/ExperimentPicker.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +135 -104
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- package/dist/puck/editor/VersionBuilder.d.ts +18 -1
- package/dist/puck/editor/VersionBuilder.js +217 -39
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +8 -1
- package/dist/puck/editor/copy.js +9 -1
- package/dist/puck/editor/editor.chrome.css +117 -3
- package/dist/puck/editor/editor.css +130 -8
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/localPlacements.d.ts +1 -0
- package/dist/puck/editor/localPlacements.js +12 -0
- package/dist/puck/editor/placementsCache.d.ts +18 -12
- package/dist/puck/editor/placementsCache.js +52 -47
- package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
- package/dist/puck/editor/usePlacementNotice.js +4 -3
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +2 -3
- package/dist/puck/visibility.js +11 -7
- package/dist/server/recordContentChange.js +34 -19
- package/dist/server/resolveExperimentData.js +2 -2
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/api.d.ts +6 -3
- package/dist/testSurface/api.js +10 -6
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/common.d.ts +4 -0
- package/dist/testSurface/copy/common.js +8 -4
- package/dist/testSurface/copy/languages.d.ts +11 -0
- package/dist/testSurface/copy/languages.js +7 -0
- package/dist/testSurface/copy/readiness.d.ts +1 -1
- package/dist/testSurface/copy/readiness.js +1 -1
- package/dist/testSurface/copy/testPage.d.ts +21 -0
- package/dist/testSurface/copy/testPage.js +21 -0
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/surface/contracts.d.ts +2 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
- package/dist/testSurface/surface/editorPlacement.js +18 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
- package/dist/testSurface/surface/results/useResults.d.ts +4 -1
- package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
- package/dist/testSurface/surface/test/DeleteTest.js +171 -0
- package/dist/testSurface/surface/test/TestSurface.js +29 -9
- package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
- package/dist/testSurface/surface/useTestDocument.js +20 -4
- package/dist/testSurface/useApi.d.ts +4 -1
- package/dist/transitions/checkStart.d.ts +4 -1
- package/dist/transitions/checkStart.js +117 -14
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/makeContent.js +5 -4
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +33 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/placementInteractions.js +7 -4
- package/dist/transitions/placements.d.ts +26 -1
- package/dist/transitions/placements.js +219 -56
- package/dist/transitions/preflightData.d.ts +2 -1
- package/dist/transitions/preflightData.js +66 -3
- package/dist/transitions/start.js +4 -1
- package/dist/types/endpoints.d.ts +35 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +9 -9
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/ui.css +13 -5
- package/package.json +3 -2
package/dist/ui/Button.js
CHANGED
|
@@ -12,7 +12,7 @@ export function Button({ variant = 'secondary', size = 'md', disabled, busy, cla
|
|
|
12
12
|
href: blocked ? undefined : href,
|
|
13
13
|
role: blocked ? 'link' : undefined,
|
|
14
14
|
"aria-disabled": blocked || undefined,
|
|
15
|
-
"aria-busy": busy || undefined,
|
|
15
|
+
"aria-busy": busy || props['aria-busy'] || undefined,
|
|
16
16
|
tabIndex: blocked ? -1 : rest.tabIndex,
|
|
17
17
|
onClick: (event)=>{
|
|
18
18
|
if (blocked) event.preventDefault();
|
|
@@ -26,7 +26,7 @@ export function Button({ variant = 'secondary', size = 'md', disabled, busy, cla
|
|
|
26
26
|
type: props.type ?? 'button',
|
|
27
27
|
className: classes,
|
|
28
28
|
disabled: blocked,
|
|
29
|
-
"aria-busy": busy || undefined,
|
|
29
|
+
"aria-busy": busy || props['aria-busy'] || undefined,
|
|
30
30
|
children: children
|
|
31
31
|
});
|
|
32
32
|
}
|
package/dist/ui/Inputs.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { InputHTMLAttributes,
|
|
1
|
+
import type { InputHTMLAttributes, TextareaHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { SelectControlProps } from './SelectControl.js';
|
|
2
3
|
import './ui.css';
|
|
3
4
|
export interface FieldProps {
|
|
4
5
|
id: string;
|
|
@@ -12,8 +13,8 @@ export declare function NumberInput(props: TextInputProps): import("react").JSX.
|
|
|
12
13
|
export declare function SearchInput(props: TextInputProps): import("react").JSX.Element;
|
|
13
14
|
export type SelectProps = FieldProps & {
|
|
14
15
|
labelAction?: ReactNode;
|
|
15
|
-
} & Omit<
|
|
16
|
-
export declare function Select({ label, labelAction, help, error,
|
|
16
|
+
} & Omit<SelectControlProps, 'id'>;
|
|
17
|
+
export declare function Select({ label, labelAction, help, error, ...props }: SelectProps): import("react").JSX.Element;
|
|
17
18
|
export declare function Toggle({ label, help, error, className, ...props }: Omit<TextInputProps, 'type'>): import("react").JSX.Element;
|
|
18
19
|
export type TextareaProps = FieldProps & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'id'>;
|
|
19
20
|
export declare function Textarea({ label, help, error, className, ...props }: TextareaProps): import("react").JSX.Element;
|
package/dist/ui/Inputs.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { SelectControl } from './SelectControl.js';
|
|
3
4
|
import './ui.css';
|
|
4
5
|
function described(props, extra) {
|
|
5
6
|
return [
|
|
@@ -16,12 +17,14 @@ function Field({ id, label, labelAction, help, error, children }) {
|
|
|
16
17
|
className: "xp-ui-field-label",
|
|
17
18
|
children: [
|
|
18
19
|
/*#__PURE__*/ _jsx("label", {
|
|
20
|
+
id: `${id}-label`,
|
|
19
21
|
htmlFor: id,
|
|
20
22
|
children: label
|
|
21
23
|
}),
|
|
22
24
|
labelAction
|
|
23
25
|
]
|
|
24
26
|
}) : /*#__PURE__*/ _jsx("label", {
|
|
27
|
+
id: `${id}-label`,
|
|
25
28
|
htmlFor: id,
|
|
26
29
|
children: label
|
|
27
30
|
}),
|
|
@@ -70,7 +73,7 @@ export function SearchInput(props) {
|
|
|
70
73
|
type: "search"
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
|
-
export function Select({ label, labelAction, help, error,
|
|
76
|
+
export function Select({ label, labelAction, help, error, ...props }) {
|
|
74
77
|
const field = {
|
|
75
78
|
id: props.id,
|
|
76
79
|
label,
|
|
@@ -80,14 +83,11 @@ export function Select({ label, labelAction, help, error, className = '', ...pro
|
|
|
80
83
|
return /*#__PURE__*/ _jsx(Field, {
|
|
81
84
|
...field,
|
|
82
85
|
labelAction: labelAction,
|
|
83
|
-
children: /*#__PURE__*/ _jsx(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"aria-invalid": Boolean(error) || undefined,
|
|
89
|
-
"aria-describedby": described(field, props['aria-describedby'])
|
|
90
|
-
})
|
|
86
|
+
children: /*#__PURE__*/ _jsx(SelectControl, {
|
|
87
|
+
...props,
|
|
88
|
+
"aria-labelledby": props['aria-labelledby'] ?? (props['aria-label'] ? undefined : `${props.id}-label`),
|
|
89
|
+
"aria-invalid": Boolean(error) || props['aria-invalid'] || undefined,
|
|
90
|
+
"aria-describedby": described(field, props['aria-describedby'])
|
|
91
91
|
})
|
|
92
92
|
});
|
|
93
93
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
group?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SelectChange {
|
|
9
|
+
target: {
|
|
10
|
+
value: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
};
|
|
13
|
+
currentTarget: {
|
|
14
|
+
value: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface SelectControlProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'value' | 'defaultValue' | 'children'> {
|
|
19
|
+
id: string;
|
|
20
|
+
value?: string | number | readonly string[];
|
|
21
|
+
defaultValue?: string | number | readonly string[];
|
|
22
|
+
options?: readonly SelectOption[];
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
onChange?: (event: SelectChange) => void;
|
|
25
|
+
name?: string;
|
|
26
|
+
form?: string;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Select-only combobox: DOM focus stays on the button while active-descendant
|
|
30
|
+
* focus explores the list. The manual popover lives in the trigger's document
|
|
31
|
+
* and inherits its theme; the browser's top layer escapes scroll/iframe drawers.
|
|
32
|
+
*/
|
|
33
|
+
export declare function SelectControl({ id, value, defaultValue, options: supplied, children, onChange, name, form, required, disabled, className, onKeyDown, onBlur, ...props }: SelectControlProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Children, isValidElement, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { INPUT_COPY } from '../testSurface/copy/common.js';
|
|
6
|
+
function optionText(children) {
|
|
7
|
+
return Children.toArray(children).map((child)=>/*#__PURE__*/ isValidElement(child) ? optionText(child.props.children) : String(child)).join('');
|
|
8
|
+
}
|
|
9
|
+
/** Keep existing option/optgroup callers while giving new callers a plain options API. */ function childOptions(children, group, disabled = false) {
|
|
10
|
+
return Children.toArray(children).flatMap((child)=>{
|
|
11
|
+
if (!/*#__PURE__*/ isValidElement(child)) return [];
|
|
12
|
+
const p = child.props;
|
|
13
|
+
if (child.type === 'option') return [
|
|
14
|
+
{
|
|
15
|
+
value: String(p.value ?? optionText(p.children)),
|
|
16
|
+
label: p.label ?? optionText(p.children),
|
|
17
|
+
disabled: disabled || p.disabled,
|
|
18
|
+
group
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
return childOptions(p.children, child.type === 'optgroup' ? p.label : group, disabled || Boolean(p.disabled));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** Select-only combobox: DOM focus stays on the button while active-descendant
|
|
25
|
+
* focus explores the list. The manual popover lives in the trigger's document
|
|
26
|
+
* and inherits its theme; the browser's top layer escapes scroll/iframe drawers.
|
|
27
|
+
*/ export function SelectControl({ id, value, defaultValue, options: supplied, children, onChange, name, form, required, disabled, className = '', onKeyDown, onBlur, ...props }) {
|
|
28
|
+
const options = useMemo(()=>supplied ?? childOptions(children), [
|
|
29
|
+
supplied,
|
|
30
|
+
children
|
|
31
|
+
]);
|
|
32
|
+
// Derive the native-select default until a value has actually been chosen;
|
|
33
|
+
// asynchronously loaded options then supply the first value too.
|
|
34
|
+
const [local, setLocal] = useState(defaultValue === undefined ? undefined : String(defaultValue));
|
|
35
|
+
const selected = String(value ?? local ?? options[0]?.value ?? '');
|
|
36
|
+
const [open, setOpen] = useState(false);
|
|
37
|
+
const [requiredInvalid, setRequiredInvalid] = useState(false);
|
|
38
|
+
const missingRequired = requiredInvalid && required && !selected;
|
|
39
|
+
const [active, setActive] = useState(-1);
|
|
40
|
+
const trigger = useRef(null);
|
|
41
|
+
const popup = useRef(null);
|
|
42
|
+
const [portalHost, setPortalHost] = useState(null);
|
|
43
|
+
const keyboardActive = useRef(false);
|
|
44
|
+
const typed = useRef({
|
|
45
|
+
text: '',
|
|
46
|
+
at: 0
|
|
47
|
+
});
|
|
48
|
+
const enabled = options.flatMap((option, index)=>option.disabled ? [] : [
|
|
49
|
+
index
|
|
50
|
+
]);
|
|
51
|
+
const groups = [];
|
|
52
|
+
options.forEach((option, index)=>{
|
|
53
|
+
const last = groups.at(-1);
|
|
54
|
+
if (last && last.label === option.group) last.options.push(option);
|
|
55
|
+
else groups.push({
|
|
56
|
+
label: option.group,
|
|
57
|
+
start: index,
|
|
58
|
+
options: [
|
|
59
|
+
option
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
const selectedIndex = options.findIndex((option)=>option.value === selected);
|
|
64
|
+
const current = enabled.includes(active) ? active : enabled.includes(selectedIndex) ? selectedIndex : enabled[0] ?? -1;
|
|
65
|
+
const listId = `${id}-listbox`;
|
|
66
|
+
const optionId = (index)=>`${id}-option-${index}`;
|
|
67
|
+
function begin(index = enabled.includes(selectedIndex) ? selectedIndex : enabled[0] ?? -1, keyboard = false) {
|
|
68
|
+
if (disabled) return;
|
|
69
|
+
keyboardActive.current = keyboard;
|
|
70
|
+
typed.current = {
|
|
71
|
+
text: '',
|
|
72
|
+
at: 0
|
|
73
|
+
};
|
|
74
|
+
setActive(index);
|
|
75
|
+
setOpen(true);
|
|
76
|
+
}
|
|
77
|
+
function commit(index = current) {
|
|
78
|
+
if (disabled || !options[index] || options[index].disabled) {
|
|
79
|
+
setOpen(false);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const next = options[index].value;
|
|
83
|
+
setLocal(next);
|
|
84
|
+
if (next) setRequiredInvalid(false);
|
|
85
|
+
const target = {
|
|
86
|
+
value: next,
|
|
87
|
+
name
|
|
88
|
+
};
|
|
89
|
+
if (next !== selected) onChange?.({
|
|
90
|
+
target,
|
|
91
|
+
currentTarget: target
|
|
92
|
+
});
|
|
93
|
+
setOpen(false);
|
|
94
|
+
}
|
|
95
|
+
function leave() {
|
|
96
|
+
if (keyboardActive.current) commit();
|
|
97
|
+
else setOpen(false);
|
|
98
|
+
}
|
|
99
|
+
useLayoutEffect(()=>{
|
|
100
|
+
const node = trigger.current, menu = popup.current;
|
|
101
|
+
if (!open || !node || !menu || disabled) return;
|
|
102
|
+
const win = node.ownerDocument.defaultView;
|
|
103
|
+
if (!win) return;
|
|
104
|
+
const topLayer = typeof menu.showPopover === 'function';
|
|
105
|
+
// Without popovers, escape transformed/scrolling content through a portal.
|
|
106
|
+
// Keep it in the nearest native modal: a body portal would be inert and
|
|
107
|
+
// painted below that modal. Our Dialog/Drawer root has no transform.
|
|
108
|
+
const host = topLayer ? null : node.closest('dialog[open]') ?? node.ownerDocument.body;
|
|
109
|
+
if (host !== portalHost) {
|
|
110
|
+
setPortalHost(host);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let style = win.getComputedStyle(node);
|
|
114
|
+
const copied = new Set();
|
|
115
|
+
const clearTheme = ()=>{
|
|
116
|
+
for (const property of copied)menu.style.removeProperty(property);
|
|
117
|
+
copied.clear();
|
|
118
|
+
menu.style.removeProperty('direction');
|
|
119
|
+
};
|
|
120
|
+
const copyTheme = ()=>{
|
|
121
|
+
style = win.getComputedStyle(node);
|
|
122
|
+
clearTheme();
|
|
123
|
+
// Portals lose inherited tokens. Refresh from the control whenever an
|
|
124
|
+
// ancestor changes theme; remove tokens absent from the new theme too.
|
|
125
|
+
for (const property of Array.from(style))if (property.startsWith('--xp-')) {
|
|
126
|
+
menu.style.setProperty(property, style.getPropertyValue(property));
|
|
127
|
+
copied.add(property);
|
|
128
|
+
}
|
|
129
|
+
menu.style.direction = style.direction;
|
|
130
|
+
};
|
|
131
|
+
if (host) {
|
|
132
|
+
copyTheme();
|
|
133
|
+
menu.style.display = 'block';
|
|
134
|
+
}
|
|
135
|
+
const position = ()=>{
|
|
136
|
+
const rect = node.getBoundingClientRect();
|
|
137
|
+
const viewport = win.visualViewport;
|
|
138
|
+
const left = viewport?.offsetLeft ?? 0, top = viewport?.offsetTop ?? 0;
|
|
139
|
+
const width = viewport?.width ?? win.innerWidth, height = viewport?.height ?? win.innerHeight;
|
|
140
|
+
let clipTop = top, clipBottom = top + height, clipLeft = left, clipRight = left + width;
|
|
141
|
+
for(let parent = node.parentElement; parent && parent !== node.ownerDocument.body; parent = parent.parentElement){
|
|
142
|
+
const css = win.getComputedStyle(parent);
|
|
143
|
+
const bounds = parent.getBoundingClientRect();
|
|
144
|
+
if (/(auto|scroll|hidden|clip)/.test(`${css.overflow} ${css.overflowY}`)) {
|
|
145
|
+
clipTop = Math.max(clipTop, bounds.top);
|
|
146
|
+
clipBottom = Math.min(clipBottom, bounds.bottom);
|
|
147
|
+
}
|
|
148
|
+
if (/(auto|scroll|hidden|clip)/.test(`${css.overflow} ${css.overflowX}`)) {
|
|
149
|
+
clipLeft = Math.max(clipLeft, bounds.left);
|
|
150
|
+
clipRight = Math.min(clipRight, bounds.right);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if ((rect.width || rect.height) && (rect.bottom <= clipTop || rect.top >= clipBottom || rect.right <= clipLeft || rect.left >= clipRight)) {
|
|
154
|
+
setOpen(false);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const minLeft = left + 8, maxRight = left + width - 8;
|
|
158
|
+
const limit = Math.max(0, maxRight - minLeft);
|
|
159
|
+
menu.style.width = 'max-content';
|
|
160
|
+
menu.style.maxWidth = `${limit}px`;
|
|
161
|
+
const menuStyle = win.getComputedStyle(menu);
|
|
162
|
+
const borders = (parseFloat(menuStyle.borderLeftWidth) || 0) + (parseFloat(menuStyle.borderRightWidth) || 0);
|
|
163
|
+
const menuWidth = Math.min(Math.max(rect.width, menu.scrollWidth + borders), limit);
|
|
164
|
+
const below = Math.max(0, top + height - rect.bottom - 8);
|
|
165
|
+
const above = Math.max(0, rect.top - top - 8);
|
|
166
|
+
const menuHeight = Math.min(menu.scrollHeight || 280, 280);
|
|
167
|
+
const flip = below < menuHeight && above > below;
|
|
168
|
+
const rtl = style.direction === 'rtl';
|
|
169
|
+
let x = rtl ? rect.right - menuWidth : rect.left;
|
|
170
|
+
// Prefer logical start, then logical end, then clamp to the viewport.
|
|
171
|
+
if (x < minLeft || x + menuWidth > maxRight) x = rtl ? rect.left : rect.right - menuWidth;
|
|
172
|
+
x = Math.max(minLeft, Math.min(x, maxRight - menuWidth));
|
|
173
|
+
const available = flip ? above : below;
|
|
174
|
+
Object.assign(menu.style, {
|
|
175
|
+
width: `${menuWidth}px`,
|
|
176
|
+
left: `${x}px`,
|
|
177
|
+
top: `${flip ? rect.top - Math.min(menuHeight, available) - 4 : rect.bottom + 4}px`,
|
|
178
|
+
bottom: 'auto',
|
|
179
|
+
maxHeight: `${Math.min(280, available)}px`
|
|
180
|
+
});
|
|
181
|
+
menu.dataset.placement = flip ? 'top' : 'bottom';
|
|
182
|
+
};
|
|
183
|
+
if (topLayer) menu.showPopover();
|
|
184
|
+
position();
|
|
185
|
+
const Resize = win.ResizeObserver;
|
|
186
|
+
const observer = Resize ? new Resize(position) : undefined;
|
|
187
|
+
observer?.observe(node);
|
|
188
|
+
const scroll = (event)=>{
|
|
189
|
+
const target = event.target;
|
|
190
|
+
if (target && 'nodeType' in target && menu.contains(target)) return;
|
|
191
|
+
position();
|
|
192
|
+
};
|
|
193
|
+
const theme = host ? new win.MutationObserver(()=>{
|
|
194
|
+
copyTheme();
|
|
195
|
+
position();
|
|
196
|
+
}) : undefined;
|
|
197
|
+
for(let ancestor = node; theme && ancestor; ancestor = ancestor.parentElement){
|
|
198
|
+
theme.observe(ancestor, {
|
|
199
|
+
attributes: true,
|
|
200
|
+
attributeFilter: [
|
|
201
|
+
'data-theme',
|
|
202
|
+
'class',
|
|
203
|
+
'style',
|
|
204
|
+
'dir'
|
|
205
|
+
]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
win.addEventListener('resize', position);
|
|
209
|
+
win.addEventListener('scroll', scroll, true);
|
|
210
|
+
win.visualViewport?.addEventListener('resize', position);
|
|
211
|
+
win.visualViewport?.addEventListener('scroll', position);
|
|
212
|
+
return ()=>{
|
|
213
|
+
if (topLayer) menu.hidePopover?.();
|
|
214
|
+
observer?.disconnect();
|
|
215
|
+
theme?.disconnect();
|
|
216
|
+
clearTheme();
|
|
217
|
+
win.removeEventListener('resize', position);
|
|
218
|
+
win.removeEventListener('scroll', scroll, true);
|
|
219
|
+
win.visualViewport?.removeEventListener('resize', position);
|
|
220
|
+
win.visualViewport?.removeEventListener('scroll', position);
|
|
221
|
+
};
|
|
222
|
+
}, [
|
|
223
|
+
open,
|
|
224
|
+
disabled,
|
|
225
|
+
options,
|
|
226
|
+
portalHost
|
|
227
|
+
]);
|
|
228
|
+
useLayoutEffect(()=>{
|
|
229
|
+
const menu = popup.current;
|
|
230
|
+
const option = menu?.querySelector(`[data-index="${current}"]`);
|
|
231
|
+
if (!open || !menu || !option) return;
|
|
232
|
+
// Scroll only the popup, without moving the drawer or the page behind it.
|
|
233
|
+
const top = option.offsetTop, bottom = top + option.offsetHeight;
|
|
234
|
+
if (top < menu.scrollTop) menu.scrollTop = top;
|
|
235
|
+
else if (bottom > menu.scrollTop + menu.clientHeight) menu.scrollTop = bottom - menu.clientHeight;
|
|
236
|
+
}, [
|
|
237
|
+
open,
|
|
238
|
+
current,
|
|
239
|
+
portalHost
|
|
240
|
+
]);
|
|
241
|
+
useEffect(()=>{
|
|
242
|
+
if (!open) return;
|
|
243
|
+
const doc = trigger.current?.ownerDocument;
|
|
244
|
+
const outside = (event)=>{
|
|
245
|
+
const target = event.target;
|
|
246
|
+
if (!trigger.current?.contains(target) && !popup.current?.contains(target)) leave();
|
|
247
|
+
};
|
|
248
|
+
doc?.addEventListener('pointerdown', outside, true);
|
|
249
|
+
return ()=>doc?.removeEventListener('pointerdown', outside, true);
|
|
250
|
+
});
|
|
251
|
+
useEffect(()=>{
|
|
252
|
+
const node = trigger.current;
|
|
253
|
+
if (!node) return;
|
|
254
|
+
// A button is labelable: suppress label activation's synthetic click, while
|
|
255
|
+
// retaining native label association and the expected focus behavior.
|
|
256
|
+
const labelClick = (event)=>{
|
|
257
|
+
const target = event.target;
|
|
258
|
+
const label = target?.closest?.('label');
|
|
259
|
+
if (label?.control === node && !node.contains(target)) {
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
node.focus();
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
node.ownerDocument.addEventListener('click', labelClick, true);
|
|
265
|
+
return ()=>node.ownerDocument.removeEventListener('click', labelClick, true);
|
|
266
|
+
}, [
|
|
267
|
+
id
|
|
268
|
+
]);
|
|
269
|
+
useEffect(()=>{
|
|
270
|
+
if (!open) return;
|
|
271
|
+
const dialog = trigger.current?.closest('dialog');
|
|
272
|
+
// Native cancel is also guarded for browser-generated dialog dismissal.
|
|
273
|
+
const cancel = (event)=>{
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
event.stopImmediatePropagation();
|
|
276
|
+
setOpen(false);
|
|
277
|
+
};
|
|
278
|
+
dialog?.addEventListener('cancel', cancel, true);
|
|
279
|
+
return ()=>dialog?.removeEventListener('cancel', cancel, true);
|
|
280
|
+
}, [
|
|
281
|
+
open
|
|
282
|
+
]);
|
|
283
|
+
useEffect(()=>{
|
|
284
|
+
if (disabled) setOpen(false);
|
|
285
|
+
}, [
|
|
286
|
+
disabled
|
|
287
|
+
]);
|
|
288
|
+
function typeAhead(key) {
|
|
289
|
+
keyboardActive.current = true;
|
|
290
|
+
const now = Date.now();
|
|
291
|
+
const text = !open || now - typed.current.at > 700 ? key : typed.current.text + key;
|
|
292
|
+
typed.current = {
|
|
293
|
+
text,
|
|
294
|
+
at: now
|
|
295
|
+
};
|
|
296
|
+
const repeated = [
|
|
297
|
+
...text
|
|
298
|
+
].every((letter)=>letter === text[0]);
|
|
299
|
+
const search = (repeated ? key : text).toLocaleLowerCase('en-US');
|
|
300
|
+
const start = repeated ? (open ? current : selectedIndex) + 1 : Math.max(0, current);
|
|
301
|
+
const order = [
|
|
302
|
+
...enabled.filter((index)=>index >= start),
|
|
303
|
+
...enabled.filter((index)=>index < start)
|
|
304
|
+
];
|
|
305
|
+
const match = order.find((index)=>options[index].label.toLocaleLowerCase('en-US').startsWith(search));
|
|
306
|
+
setOpen(true);
|
|
307
|
+
if (match !== undefined) setActive(match);
|
|
308
|
+
}
|
|
309
|
+
const menu = /*#__PURE__*/ _jsx("div", {
|
|
310
|
+
ref: popup,
|
|
311
|
+
hidden: !open || disabled,
|
|
312
|
+
style: {
|
|
313
|
+
position: 'fixed',
|
|
314
|
+
inset: 'auto',
|
|
315
|
+
right: 'auto',
|
|
316
|
+
bottom: 'auto',
|
|
317
|
+
margin: 0,
|
|
318
|
+
background: 'var(--xp-surface, Canvas)',
|
|
319
|
+
color: 'var(--xp-text, CanvasText)',
|
|
320
|
+
overflow: 'auto',
|
|
321
|
+
boxSizing: 'border-box',
|
|
322
|
+
zIndex: 2147483647,
|
|
323
|
+
...!open || disabled ? {
|
|
324
|
+
display: 'none'
|
|
325
|
+
} : {}
|
|
326
|
+
},
|
|
327
|
+
id: listId,
|
|
328
|
+
role: "listbox",
|
|
329
|
+
"aria-label": props['aria-label'],
|
|
330
|
+
"aria-labelledby": props['aria-labelledby'] ?? (props['aria-label'] ? undefined : `${id}-label`),
|
|
331
|
+
popover: portalHost ? undefined : 'manual',
|
|
332
|
+
className: "xp-ui-combobox-popup",
|
|
333
|
+
onPointerDown: (event)=>{
|
|
334
|
+
event.preventDefault();
|
|
335
|
+
event.stopPropagation();
|
|
336
|
+
},
|
|
337
|
+
children: groups.map((group)=>/*#__PURE__*/ _jsxs("div", {
|
|
338
|
+
role: group.label ? 'group' : undefined,
|
|
339
|
+
"aria-labelledby": group.label ? `${id}-group-${group.start}` : undefined,
|
|
340
|
+
children: [
|
|
341
|
+
group.label ? /*#__PURE__*/ _jsx("div", {
|
|
342
|
+
id: `${id}-group-${group.start}`,
|
|
343
|
+
className: "xp-ui-combobox-group",
|
|
344
|
+
children: group.label
|
|
345
|
+
}) : null,
|
|
346
|
+
group.options.map((option, offset)=>{
|
|
347
|
+
const index = group.start + offset;
|
|
348
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
349
|
+
role: "option",
|
|
350
|
+
id: optionId(index),
|
|
351
|
+
"data-index": index,
|
|
352
|
+
"data-value": option.value,
|
|
353
|
+
"aria-selected": selectedIndex === index,
|
|
354
|
+
"data-active": current === index,
|
|
355
|
+
style: {
|
|
356
|
+
backgroundColor: current === index ? 'var(--xp-surface-3, Highlight)' : undefined,
|
|
357
|
+
color: option.disabled ? 'var(--xp-text-3, GrayText)' : current === index ? 'var(--xp-text, HighlightText)' : undefined,
|
|
358
|
+
fontWeight: selectedIndex === index ? 600 : undefined
|
|
359
|
+
},
|
|
360
|
+
"aria-disabled": option.disabled || undefined,
|
|
361
|
+
className: "xp-ui-combobox-option",
|
|
362
|
+
onPointerMove: ()=>{
|
|
363
|
+
if (!option.disabled) {
|
|
364
|
+
keyboardActive.current = false;
|
|
365
|
+
setActive(index);
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
onClick: ()=>{
|
|
369
|
+
if (!option.disabled) {
|
|
370
|
+
commit(index);
|
|
371
|
+
trigger.current?.focus();
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
children: option.label
|
|
375
|
+
}, option.value);
|
|
376
|
+
})
|
|
377
|
+
]
|
|
378
|
+
}, group.start))
|
|
379
|
+
});
|
|
380
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
381
|
+
className: "xp-ui-combobox-wrap",
|
|
382
|
+
children: [
|
|
383
|
+
/*#__PURE__*/ _jsxs("button", {
|
|
384
|
+
...props,
|
|
385
|
+
id: id,
|
|
386
|
+
ref: trigger,
|
|
387
|
+
value: selected,
|
|
388
|
+
type: "button",
|
|
389
|
+
role: "combobox",
|
|
390
|
+
disabled: disabled,
|
|
391
|
+
"aria-expanded": open && !disabled,
|
|
392
|
+
"aria-haspopup": "listbox",
|
|
393
|
+
"aria-controls": listId,
|
|
394
|
+
"aria-activedescendant": open && current >= 0 ? optionId(current) : undefined,
|
|
395
|
+
"aria-required": required || undefined,
|
|
396
|
+
"aria-invalid": props['aria-invalid'] || missingRequired || undefined,
|
|
397
|
+
"aria-describedby": [
|
|
398
|
+
props['aria-describedby'],
|
|
399
|
+
missingRequired ? `${id}-required-error` : undefined
|
|
400
|
+
].filter(Boolean).join(' ') || undefined,
|
|
401
|
+
className: `xp-ui-input xp-ui-combobox ${className}`,
|
|
402
|
+
onClick: ()=>open ? setOpen(false) : begin(),
|
|
403
|
+
onBlur: (event)=>{
|
|
404
|
+
if (open) leave();
|
|
405
|
+
onBlur?.(event);
|
|
406
|
+
},
|
|
407
|
+
onKeyDown: (event)=>{
|
|
408
|
+
onKeyDown?.(event);
|
|
409
|
+
if (event.defaultPrevented || disabled || event.nativeEvent.isComposing) return;
|
|
410
|
+
const key = event.key;
|
|
411
|
+
if (key === 'Tab') {
|
|
412
|
+
if (open) leave();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (key === 'Escape') {
|
|
416
|
+
if (open) {
|
|
417
|
+
event.preventDefault();
|
|
418
|
+
event.stopPropagation();
|
|
419
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
420
|
+
setOpen(false);
|
|
421
|
+
}
|
|
422
|
+
;
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (open && key === ' ' && typed.current.text && Date.now() - typed.current.at <= 700) {
|
|
426
|
+
event.preventDefault();
|
|
427
|
+
typeAhead(key);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (key === 'Enter' || key === ' ') {
|
|
431
|
+
event.preventDefault();
|
|
432
|
+
open ? commit() : begin(undefined, true);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if ([
|
|
436
|
+
'ArrowDown',
|
|
437
|
+
'ArrowUp',
|
|
438
|
+
'Home',
|
|
439
|
+
'End',
|
|
440
|
+
'PageDown',
|
|
441
|
+
'PageUp'
|
|
442
|
+
].includes(key)) {
|
|
443
|
+
event.preventDefault();
|
|
444
|
+
keyboardActive.current = true;
|
|
445
|
+
if (open && event.altKey && key === 'ArrowUp') {
|
|
446
|
+
commit();
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (key === 'Home' || !open && key === 'ArrowUp') begin(enabled[0] ?? -1, true);
|
|
450
|
+
else if (key === 'End') begin(enabled.at(-1) ?? -1, true);
|
|
451
|
+
else if (!open) begin(undefined, true);
|
|
452
|
+
else {
|
|
453
|
+
const offset = key === 'ArrowUp' ? -1 : key === 'PageUp' ? -10 : key === 'PageDown' ? 10 : 1;
|
|
454
|
+
setActive(enabled[Math.max(0, Math.min(enabled.length - 1, enabled.indexOf(current) + offset))] ?? -1);
|
|
455
|
+
}
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (key.length === 1 && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
459
|
+
event.preventDefault();
|
|
460
|
+
typeAhead(key);
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
children: [
|
|
464
|
+
/*#__PURE__*/ _jsx("span", {
|
|
465
|
+
children: options[selectedIndex]?.label ?? ''
|
|
466
|
+
}),
|
|
467
|
+
/*#__PURE__*/ _jsx("span", {
|
|
468
|
+
className: "xp-ui-combobox-chevron",
|
|
469
|
+
"aria-hidden": "true"
|
|
470
|
+
})
|
|
471
|
+
]
|
|
472
|
+
}),
|
|
473
|
+
/*#__PURE__*/ _jsx("input", {
|
|
474
|
+
type: "hidden",
|
|
475
|
+
name: name,
|
|
476
|
+
form: form,
|
|
477
|
+
value: selected,
|
|
478
|
+
disabled: disabled
|
|
479
|
+
}),
|
|
480
|
+
required ? /*#__PURE__*/ _jsx("input", {
|
|
481
|
+
className: "xp-ui-combobox-validation",
|
|
482
|
+
"aria-hidden": "true",
|
|
483
|
+
tabIndex: -1,
|
|
484
|
+
value: selected,
|
|
485
|
+
required: true,
|
|
486
|
+
disabled: disabled,
|
|
487
|
+
form: form,
|
|
488
|
+
onChange: ()=>{},
|
|
489
|
+
onInvalid: (event)=>{
|
|
490
|
+
event.preventDefault();
|
|
491
|
+
setRequiredInvalid(true);
|
|
492
|
+
trigger.current?.focus();
|
|
493
|
+
}
|
|
494
|
+
}) : null,
|
|
495
|
+
missingRequired ? /*#__PURE__*/ _jsx("p", {
|
|
496
|
+
className: "xp-ui-error",
|
|
497
|
+
id: `${id}-required-error`,
|
|
498
|
+
role: "alert",
|
|
499
|
+
children: INPUT_COPY.selectRequired
|
|
500
|
+
}) : null,
|
|
501
|
+
portalHost ? /*#__PURE__*/ createPortal(menu, portalHost) : menu
|
|
502
|
+
]
|
|
503
|
+
});
|
|
504
|
+
}
|
package/dist/ui/ui.css
CHANGED
|
@@ -21,11 +21,19 @@
|
|
|
21
21
|
.xp-ui-input::placeholder { color: var(--xp-text-3); }
|
|
22
22
|
.xp-ui-input:hover { border-color: var(--xp-text-3); }
|
|
23
23
|
.xp-ui-input[aria-invalid='true'] { border-color: var(--xp-error); }
|
|
24
|
-
.xp-ui-input--number { text-align:
|
|
25
|
-
/* The
|
|
26
|
-
.xp-ui-
|
|
27
|
-
.xp-ui-
|
|
28
|
-
.xp-ui-
|
|
24
|
+
.xp-ui-input--number { text-align: end; font-variant-numeric: tabular-nums; }
|
|
25
|
+
/* The open menu inherits the control's tokens, even in a dialog or canvas iframe. */
|
|
26
|
+
.xp-ui-combobox-wrap { display: block; position: relative; min-width: 0; max-width: 100%; }
|
|
27
|
+
.xp-ui-combobox { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-2); cursor: pointer; text-align: start; }
|
|
28
|
+
.xp-ui-combobox > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
29
|
+
.xp-ui-combobox-chevron { flex: 0 0 auto; width: 7px; height: 7px; margin-inline-end: 4px; border-right: 2px solid var(--xp-text-2); border-bottom: 2px solid var(--xp-text-2); transform: translateY(-2px) rotate(45deg); }
|
|
30
|
+
.xp-ui-combobox-popup { box-sizing: border-box; position: fixed; inset: auto; margin: 0; padding: var(--xp-space-1); overflow: auto; overscroll-behavior: contain; border: 1px solid var(--xp-border-strong); border-radius: var(--xp-radius-control); background: var(--xp-surface); color: var(--xp-text); font: var(--xp-text-body); z-index: 2147483647; }
|
|
31
|
+
.xp-ui-combobox-popup:popover-open { display: block; }
|
|
32
|
+
.xp-ui-combobox-option { padding: var(--xp-space-2); border-radius: var(--xp-space-1); cursor: pointer; overflow-wrap: anywhere; }
|
|
33
|
+
.xp-ui-combobox-option[data-active='true'] { background: var(--xp-surface-3); outline: 1px solid var(--xp-border-strong); outline-offset: -1px; }
|
|
34
|
+
.xp-ui-combobox-option[aria-disabled='true'] { color: var(--xp-text-3); cursor: not-allowed; }
|
|
35
|
+
.xp-ui-combobox-group { padding: var(--xp-space-2); color: var(--xp-text-2); font: var(--xp-text-small); }
|
|
36
|
+
.xp-ui-combobox-validation { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
|
|
29
37
|
.xp-ui-help { margin: 0; color: var(--xp-text-2); font: var(--xp-text-small); }
|
|
30
38
|
.xp-ui-error { margin: 0; color: var(--xp-error); font: var(--xp-text-small); }
|
|
31
39
|
.xp-ui-toggle { appearance: none; display: inline-block; width: 32px; height: 20px; margin: 0; padding: 2px; border-radius: 20px; border: 1px solid var(--xp-border-strong); background: var(--xp-surface-3); cursor: pointer; transition: background-color var(--xp-motion); }
|