frontile 0.18.0-beta.5 → 0.18.1
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/declarations/components/buttons/chip.d.ts +1 -1
- package/declarations/components/buttons/chip.d.ts.map +1 -1
- package/declarations/components/collections/dropdown/menu-context.d.ts +10 -0
- package/declarations/components/collections/dropdown/menu-context.d.ts.map +1 -1
- package/declarations/components/collections/dropdown/sub.d.ts +34 -0
- package/declarations/components/collections/dropdown/sub.d.ts.map +1 -1
- package/declarations/components/forms/autocomplete.d.ts +12 -12
- package/declarations/components/forms/date-input/clipboard.d.ts +34 -0
- package/declarations/components/forms/date-input/clipboard.d.ts.map +1 -0
- package/declarations/components/forms/date-input/date-input.d.ts +91 -0
- package/declarations/components/forms/date-input/date-input.d.ts.map +1 -0
- package/declarations/components/forms/date-input/segment-group.d.ts +130 -0
- package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -0
- package/declarations/components/forms/date-input/segments.d.ts +137 -0
- package/declarations/components/forms/date-input/segments.d.ts.map +1 -0
- package/declarations/components/forms/date-input/types.d.ts +134 -0
- package/declarations/components/forms/date-input/types.d.ts.map +1 -0
- package/declarations/components/forms/date-input.d.ts +6 -0
- package/declarations/components/forms/date-input.d.ts.map +1 -0
- package/declarations/components/forms/date-picker/date-picker.d.ts +248 -15
- package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/end-content.d.ts +33 -3
- package/declarations/components/forms/date-picker/end-content.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/types.d.ts +30 -1
- package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
- package/declarations/components/forms/field.d.ts +3 -0
- package/declarations/components/forms/field.d.ts.map +1 -1
- package/declarations/components/forms/index.d.ts +1 -0
- package/declarations/components/forms/index.d.ts.map +1 -1
- package/declarations/components/forms/input.d.ts +11 -11
- package/declarations/components/forms/native-select.d.ts +8 -8
- package/declarations/components/forms/select/select.d.ts +16 -16
- package/declarations/components/forms/textarea.d.ts +7 -7
- package/declarations/components/utilities/avatar.d.ts +35 -2
- package/declarations/components/utilities/avatar.d.ts.map +1 -1
- package/declarations/test-support.d.ts +30 -0
- package/declarations/test-support.d.ts.map +1 -1
- package/dist/components/buttons/chip.js.map +1 -1
- package/dist/components/collections/dropdown/menu-context.js.map +1 -1
- package/dist/components/collections/dropdown/sub.js +76 -11
- package/dist/components/collections/dropdown/sub.js.map +1 -1
- package/dist/components/forms/date-input/clipboard.js +162 -0
- package/dist/components/forms/date-input/clipboard.js.map +1 -0
- package/dist/components/forms/date-input/date-input.js +194 -0
- package/dist/components/forms/date-input/date-input.js.map +1 -0
- package/dist/components/forms/date-input/segment-group.js +271 -0
- package/dist/components/forms/date-input/segment-group.js.map +1 -0
- package/dist/components/forms/date-input/segments.js +379 -0
- package/dist/components/forms/date-input/segments.js.map +1 -0
- package/dist/components/forms/date-input/types.js +2 -0
- package/dist/components/forms/date-input/types.js.map +1 -0
- package/dist/components/forms/date-input.js +4 -0
- package/dist/components/forms/date-input.js.map +1 -0
- package/dist/components/forms/date-picker/date-picker.js +301 -14
- package/dist/components/forms/date-picker/date-picker.js.map +1 -1
- package/dist/components/forms/date-picker/end-content.js +17 -4
- package/dist/components/forms/date-picker/end-content.js.map +1 -1
- package/dist/components/forms/field.js +4 -1
- package/dist/components/forms/field.js.map +1 -1
- package/dist/components/forms/index.js +3 -0
- package/dist/components/forms/index.js.map +1 -1
- package/dist/components/utilities/avatar.js +30 -5
- package/dist/components/utilities/avatar.js.map +1 -1
- package/dist/forms.js +3 -0
- package/dist/forms.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/test-support.js +480 -1
- package/dist/test-support.js.map +1 -1
- package/package.json +3 -3
|
@@ -15,9 +15,25 @@ interface AvatarSignature {
|
|
|
15
15
|
*/
|
|
16
16
|
shape?: AvatarVariants['shape'];
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* How the image fills the avatar. `cover` crops the image to fill the
|
|
19
|
+
* avatar, which suits photos. `contain` shows the whole image, inset from
|
|
20
|
+
* the edge, which suits logos and wordmarks.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue 'cover'
|
|
23
|
+
*/
|
|
24
|
+
fit?: AvatarVariants['fit'];
|
|
25
|
+
/**
|
|
26
|
+
* Draws a faint hairline just inside the avatar's edge. Pass `false` to
|
|
27
|
+
* remove it.
|
|
20
28
|
*
|
|
29
|
+
* @defaultValue true
|
|
30
|
+
*/
|
|
31
|
+
isBordered?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* URL of the image to be displayed in the avatar.
|
|
34
|
+
* If provided, the image will be used instead of initials. If the image
|
|
35
|
+
* fails to load, the avatar falls back to the initials, or to an empty
|
|
36
|
+
* plate when there is no name.
|
|
21
37
|
*/
|
|
22
38
|
src?: string | null;
|
|
23
39
|
/**
|
|
@@ -56,38 +72,55 @@ interface AvatarSignature {
|
|
|
56
72
|
Element: HTMLSpanElement;
|
|
57
73
|
}
|
|
58
74
|
declare class Avatar extends Component<AvatarSignature> {
|
|
75
|
+
failedSrc?: string | null;
|
|
59
76
|
get classes(): {
|
|
60
77
|
base: (slotProps?: ({
|
|
61
78
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
62
79
|
shape?: "circle" | "square" | undefined;
|
|
80
|
+
isBordered?: boolean | undefined;
|
|
81
|
+
fit?: "cover" | "contain" | undefined;
|
|
63
82
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
64
83
|
img: (slotProps?: ({
|
|
65
84
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
66
85
|
shape?: "circle" | "square" | undefined;
|
|
86
|
+
isBordered?: boolean | undefined;
|
|
87
|
+
fit?: "cover" | "contain" | undefined;
|
|
67
88
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
68
89
|
name: (slotProps?: ({
|
|
69
90
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
70
91
|
shape?: "circle" | "square" | undefined;
|
|
92
|
+
isBordered?: boolean | undefined;
|
|
93
|
+
fit?: "cover" | "contain" | undefined;
|
|
71
94
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
72
95
|
} & {
|
|
73
96
|
base: (slotProps?: ({
|
|
74
97
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
75
98
|
shape?: "circle" | "square" | undefined;
|
|
99
|
+
isBordered?: boolean | undefined;
|
|
100
|
+
fit?: "cover" | "contain" | undefined;
|
|
76
101
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
77
102
|
img: (slotProps?: ({
|
|
78
103
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
79
104
|
shape?: "circle" | "square" | undefined;
|
|
105
|
+
isBordered?: boolean | undefined;
|
|
106
|
+
fit?: "cover" | "contain" | undefined;
|
|
80
107
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
81
108
|
name: (slotProps?: ({
|
|
82
109
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
83
110
|
shape?: "circle" | "square" | undefined;
|
|
111
|
+
isBordered?: boolean | undefined;
|
|
112
|
+
fit?: "cover" | "contain" | undefined;
|
|
84
113
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
85
114
|
} & {
|
|
86
115
|
base: (slotProps?: ({
|
|
87
116
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
88
117
|
shape?: "circle" | "square" | undefined;
|
|
118
|
+
isBordered?: boolean | undefined;
|
|
119
|
+
fit?: "cover" | "contain" | undefined;
|
|
89
120
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
90
121
|
};
|
|
122
|
+
get hasImage(): boolean;
|
|
123
|
+
handleImageError(): void;
|
|
91
124
|
get initials(): string;
|
|
92
125
|
get shouldShowInitials(): boolean;
|
|
93
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../../src/components/utilities/avatar.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../../src/components/utilities/avatar.gts"],"names":[],"mappings":"AAyLA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAI3C,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AAEzB,UAAU,eAAe;IACvB,IAAI,EAAE;QACJ;;;;WAIG;QACH,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;QAE9B;;;;WAIG;QACH,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;QAEhC;;;;;;WAMG;QACH,GAAG,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;QAE5B;;;;;WAKG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;QAErB;;;;;WAKG;QACH,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAEpB;;;;WAIG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd;;;;WAIG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB;;;;WAIG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;QAElB;;;;;WAKG;QACH,GAAG,CAAC,EAAE,MAAM,CAAC;QAEb;;WAEG;QACH,OAAO,CAAC,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;KACvC,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED,cAAM,MAAO,SAAQ,SAAS,CAAC,eAAe,CAAC;IAGpC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC,IAAI,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAQV;IAED,IAAI,QAAQ,YAGX;IAGD,gBAAgB;IAIhB,IAAI,QAAQ,WAmBX;IAED,IAAI,kBAAkB,YAOrB;CA4DF;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,eAAe,MAAM,CAAC"}
|
|
@@ -23,4 +23,34 @@ export { setPrefersReducedMotion } from './utils/prefers-reduced-motion';
|
|
|
23
23
|
* that legitimately belongs to `root`.
|
|
24
24
|
*/
|
|
25
25
|
export declare function ownParts(root: Element, part: string): Element[];
|
|
26
|
+
/**
|
|
27
|
+
* Types a date into a segmented `DateInput` or `DatePicker`.
|
|
28
|
+
*
|
|
29
|
+
* `fillIn` cannot do this and, worse, does not fail when you try. The segments
|
|
30
|
+
* are `contenteditable`, so `fillIn` writes their text and fires `input`
|
|
31
|
+
* without complaint -- but the component renders from its own segments and
|
|
32
|
+
* listens only to `beforeinput`/`keydown`, so nothing reaches the value. The
|
|
33
|
+
* result is a test that reads green, whose `assert.dom(...).hasText('01')`
|
|
34
|
+
* even passes, while the component's value stayed `null` and the form would
|
|
35
|
+
* submit empty.
|
|
36
|
+
*
|
|
37
|
+
* This types the digits segment by segment the way a person does, so the value
|
|
38
|
+
* composes through the same commit path as real input.
|
|
39
|
+
*
|
|
40
|
+
* ```js
|
|
41
|
+
* await fillDate('[data-test-due]', '2026-01-20');
|
|
42
|
+
* await fillDate('[data-test-due]', new Date(2026, 0, 20));
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* For `@mode="range"` use {@link fillDateRange}.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fillDate(selector: string, value: Date | string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Types both ends of a range into a segmented `DatePicker @mode="range"`.
|
|
50
|
+
*
|
|
51
|
+
* ```js
|
|
52
|
+
* await fillDateRange('[data-test-trip]', '2026-01-20', '2026-01-25');
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function fillDateRange(selector: string, start: Date | string, end: Date | string): Promise<void>;
|
|
26
56
|
//# sourceMappingURL=test-support.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-support.d.ts","sourceRoot":"","sources":["../src/test-support.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"test-support.d.ts","sourceRoot":"","sources":["../src/test-support.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC,CAEf;AAkDD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CAS/D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,IAAI,GAAG,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,IAAI,GAAG,MAAM,EACpB,GAAG,EAAE,IAAI,GAAG,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chip.js","sources":["../../../src/components/buttons/chip.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { useStyles } from '@frontile/theme';\nimport { CloseButton } from './close-button';\nimport { renamedArgValue } from '../../-private/deprecated-args';\n\ninterface ChipSignature {\n Args: {\n /**\n * The chip variant.\n *\n * @defaultValue 'solid'\n */\n variant?: 'solid' | 'outline' | 'soft';\n\n /**\n * @deprecated Use `variant`. `default` is now `solid`, `outlined` is\n * `outline`, and `faded` is `soft`.\n */\n appearance?: 'default' | 'outlined' | 'faded';\n\n /**\n * The color of the chip.\n */\n color?:\n | 'neutral'\n | 'primary'\n | 'secondary'\n | 'tertiary'\n | 'success'\n | 'warning'\n | 'danger';\n\n /**\n * @deprecated Use `color`. `default` is now `neutral`.\n */\n intent?:\n | 'default'\n | 'primary'\n | 'secondary'\n | 'tertiary'\n | 'success'\n | 'warning'\n | 'danger';\n\n /**\n * The size of the chip\n *\n * @defaultValue 'md'\n */\n size?: 'sm' | 'md' | 'lg';\n\n /**\n * The border radius of the chip\n *\n * @defaultValue 'full'\n */\n radius?: 'none' | 'sm' | 'lg' | 'full';\n\n /**\n * Adds a dot before the content, colored by `@color`. On the `solid`\n * variant the dot takes the chip's text color, since the chip's\n * background is already the chip's color.\n *\n * @defaultValue false\n */\n withDot?: boolean;\n\n /**\n * Function to be called when clicking on the close button.\n * If you pass this argument, the close button will be visible.\n */\n onClose?: () => void;\n\n /**\n * The accessible name of the close button. Every close button would\n * otherwise be announced as just \"Close\", which does not say *what* is\n * being removed — worth setting when several chips sit together.\n *\n * @defaultValue 'Close'\n */\n closeButtonTitle?: string;\n\n /**\n * `tabindex` for the close button.\n *\n * Set to `-1` when chips sit inside another control (a multi-select field,\n * say) and the close button should stay a pointer affordance: every chip\n * would otherwise cost a Tab stop before the control itself is reached.\n * Whoever does this owes keyboard users another way to remove a chip.\n *\n * @defaultValue undefined (the close button is a normal tab stop)\n */\n closeButtonTabIndex?: number | string;\n\n /**\n * Dims the chip and disables its close button, if any.\n *\n * @defaultValue false\n */\n isDisabled?: boolean;\n\n /**\n * Custom class name, it will override the default ones using Tailwind Merge library.\n */\n class?: string;\n };\n Blocks: {\n default: [];\n };\n Element: HTMLDivElement;\n}\n\nclass Chip extends Component<ChipSignature> {\n get classNames() {\n const { chip } = useStyles();\n\n const { base, content, dot, closeButton } = chip({\n color:\n renamedArgValue(\n this.args.color,\n this.args.intent,\n { default: 'neutral' } as const,\n {\n component: 'Chip',\n from: 'intent',\n to: 'color',\n id: 'frontile.chip.intent'\n }\n ) || 'neutral',\n size: this.args.size,\n variant:\n renamedArgValue(\n this.args.variant,\n this.args.appearance,\n { default: 'solid', outlined: 'outline', faded: 'soft' } as const,\n {\n component: 'Chip',\n from: 'appearance',\n to: 'variant',\n id: 'frontile.chip.appearance'\n }\n ) || 'solid',\n radius: this.args.radius,\n isDisabled: this.args.isDisabled\n });\n\n return {\n base: base({ class: this.args.class }),\n content: content(),\n dot: dot(),\n closeButton: closeButton()\n };\n }\n\n <template>\n <div\n class={{this.classNames.base}}\n data-component=\"chip\"\n data-part=\"base\"\n ...attributes\n >\n {{#if @withDot}}\n <span class={{this.classNames.dot}} data-part=\"dot\"></span>\n {{/if}}\n <span class={{this.classNames.content}} data-part=\"content\">\n {{yield}}\n </span>\n {{#if @onClose}}\n <CloseButton\n @class={{this.classNames.closeButton}}\n @title={{@closeButtonTitle}}\n @onPress={{@onClose}}\n tabindex={{@closeButtonTabIndex}}\n disabled={{@isDisabled}}\n data-part=\"close-button\"\n />\n {{/if}}\n </div>\n </template>\n}\n\nexport { Chip, type ChipSignature };\nexport default Chip;\n"],"names":["Chip","Component","classNames","chip","useStyles","base","content","dot","closeButton","color","renamedArgValue","args","intent","default","component","from","to","id","size","variant","appearance","outlined","faded","radius","isDisabled","class","setComponentTemplate","precompileTemplate","strictMode","scope","CloseButton"],"mappings":";;;;;;;AAgHA,MAAMA,aAAaC,SAAA,CAAU;EAC3B,IAAIC,UAAAA,GAAa;IACf,MAAM;AAAEC,MAAAA;KAAM,GAAGC,SAAA,EAAA;IAEjB,MAAM;MAAEC,IAAI;MAAEC,OAAO;MAAEC,GAAG;AAAEC,MAAAA;KAAa,GAAGL,IAAA,CAAK;AAC/CM,MAAAA,KAAA,EACEC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
+
{"version":3,"file":"chip.js","sources":["../../../src/components/buttons/chip.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { useStyles } from '@frontile/theme';\nimport { CloseButton } from './close-button';\nimport { renamedArgValue } from '../../-private/deprecated-args';\n\ninterface ChipSignature {\n Args: {\n /**\n * The chip variant.\n *\n * @defaultValue 'solid'\n */\n variant?: 'solid' | 'outline' | 'soft';\n\n /**\n * @deprecated Use `variant`. `default` is now `solid`, `outlined` is\n * `outline`, and `faded` is `soft`.\n */\n appearance?: 'default' | 'outlined' | 'faded';\n\n /**\n * The color of the chip.\n */\n color?:\n | 'neutral'\n | 'primary'\n | 'secondary'\n | 'tertiary'\n | 'success'\n | 'warning'\n | 'danger';\n\n /**\n * @deprecated Use `color`. `default` is now `neutral`.\n */\n intent?:\n | 'default'\n | 'primary'\n | 'secondary'\n | 'tertiary'\n | 'success'\n | 'warning'\n | 'danger';\n\n /**\n * The size of the chip\n *\n * @defaultValue 'md'\n */\n size?: 'xs' | 'sm' | 'md' | 'lg';\n\n /**\n * The border radius of the chip\n *\n * @defaultValue 'full'\n */\n radius?: 'none' | 'sm' | 'lg' | 'full';\n\n /**\n * Adds a dot before the content, colored by `@color`. On the `solid`\n * variant the dot takes the chip's text color, since the chip's\n * background is already the chip's color.\n *\n * @defaultValue false\n */\n withDot?: boolean;\n\n /**\n * Function to be called when clicking on the close button.\n * If you pass this argument, the close button will be visible.\n */\n onClose?: () => void;\n\n /**\n * The accessible name of the close button. Every close button would\n * otherwise be announced as just \"Close\", which does not say *what* is\n * being removed — worth setting when several chips sit together.\n *\n * @defaultValue 'Close'\n */\n closeButtonTitle?: string;\n\n /**\n * `tabindex` for the close button.\n *\n * Set to `-1` when chips sit inside another control (a multi-select field,\n * say) and the close button should stay a pointer affordance: every chip\n * would otherwise cost a Tab stop before the control itself is reached.\n * Whoever does this owes keyboard users another way to remove a chip.\n *\n * @defaultValue undefined (the close button is a normal tab stop)\n */\n closeButtonTabIndex?: number | string;\n\n /**\n * Dims the chip and disables its close button, if any.\n *\n * @defaultValue false\n */\n isDisabled?: boolean;\n\n /**\n * Custom class name, it will override the default ones using Tailwind Merge library.\n */\n class?: string;\n };\n Blocks: {\n default: [];\n };\n Element: HTMLDivElement;\n}\n\nclass Chip extends Component<ChipSignature> {\n get classNames() {\n const { chip } = useStyles();\n\n const { base, content, dot, closeButton } = chip({\n color:\n renamedArgValue(\n this.args.color,\n this.args.intent,\n { default: 'neutral' } as const,\n {\n component: 'Chip',\n from: 'intent',\n to: 'color',\n id: 'frontile.chip.intent'\n }\n ) || 'neutral',\n size: this.args.size,\n variant:\n renamedArgValue(\n this.args.variant,\n this.args.appearance,\n { default: 'solid', outlined: 'outline', faded: 'soft' } as const,\n {\n component: 'Chip',\n from: 'appearance',\n to: 'variant',\n id: 'frontile.chip.appearance'\n }\n ) || 'solid',\n radius: this.args.radius,\n isDisabled: this.args.isDisabled\n });\n\n return {\n base: base({ class: this.args.class }),\n content: content(),\n dot: dot(),\n closeButton: closeButton()\n };\n }\n\n <template>\n <div\n class={{this.classNames.base}}\n data-component=\"chip\"\n data-part=\"base\"\n ...attributes\n >\n {{#if @withDot}}\n <span class={{this.classNames.dot}} data-part=\"dot\"></span>\n {{/if}}\n <span class={{this.classNames.content}} data-part=\"content\">\n {{yield}}\n </span>\n {{#if @onClose}}\n <CloseButton\n @class={{this.classNames.closeButton}}\n @title={{@closeButtonTitle}}\n @onPress={{@onClose}}\n tabindex={{@closeButtonTabIndex}}\n disabled={{@isDisabled}}\n data-part=\"close-button\"\n />\n {{/if}}\n </div>\n </template>\n}\n\nexport { Chip, type ChipSignature };\nexport default Chip;\n"],"names":["Chip","Component","classNames","chip","useStyles","base","content","dot","closeButton","color","renamedArgValue","args","intent","default","component","from","to","id","size","variant","appearance","outlined","faded","radius","isDisabled","class","setComponentTemplate","precompileTemplate","strictMode","scope","CloseButton"],"mappings":";;;;;;;AAgHA,MAAMA,aAAaC,SAAA,CAAU;EAC3B,IAAIC,UAAAA,GAAa;IAC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AAA,CAAA,ygBAAA,EAwBA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-context.js","sources":["../../../../src/components/collections/dropdown/menu-context.ts"],"sourcesContent":["import type { SelectionMode } from '../../../utils/listManager';\nimport type { ListboxItemSignature } from '../listbox/item';\n\n/**\n * How a submenu was asked to open.\n *\n * It decides whether the submenu highlights its first item: a keyboard user\n * who pressed ArrowRight expects to be somewhere, while a pointer user\n * hovering a row does not expect a selection to move. The `Listbox` at each\n * level is constructed fresh on open, so the source is read once, at mount,\n * as `autoActivateMode`.\n */\ntype OpenSource = 'pointer' | 'keyboard';\n\n/**\n * What a level needs in order to drive a submenu it does not itself render.\n *\n * A level's ArrowRight handler has to open the submenu belonging to whichever\n * item is currently active. The item knows nothing about the submenu, and the\n * `Sub` renders inside the level's own block -- so each `Sub` registers a\n * handle under its trigger's key, and the level looks it up.\n */\ninterface SubHandle {\n open: (source: OpenSource) => void;\n close: () => void;\n}\n\ninterface MenuContext extends MenuSelectionContext {\n /** 0 for the root menu, 1 for a submenu, and so on. */\n depth: number;\n\n /**\n * Close the whole chain. Choosing a leaf three levels down dismisses the\n * entire dropdown, not just the level the leaf sits in.\n */\n closeRoot: () => void;\n\n /**\n * Close just this level, leaving its parent open -- what ArrowLeft does.\n * On the root this is the same thing as `closeRoot`.\n */\n closeSelf: () => void;\n\n /** The submenus registered at this level, keyed by their trigger's key. */\n subs: Map<string, SubHandle>;\n registerSub: (key: string, handle: SubHandle) => void;\n unregisterSub: (key: string) => void;\n\n // Appearance and timing are the root's for the whole chain: a submenu that\n // styled itself would make one menu look like two, so these are declared\n // once on the root and never overridden below it.\n variant?: ListboxItemSignature['Args']['variant'];\n color?: ListboxItemSignature['Args']['color'];\n shortcutVariant?: ListboxItemSignature['Args']['shortcutVariant'];\n disableTransitions?: boolean;\n transitionDuration?: number;\n}\n\n/**\n * The parts of a context a level may declare for itself.\n *\n * Declared once on the root and inherited by every depth -- so `@onAction` and\n * `@selectedKeys` written at the top apply to a leaf at any level -- but a\n * submenu may override any of them for its own level and the levels below,\n * which is what lets a navigation menu hold a multi-select submenu.\n *\n * Split out from `MenuContext` so the overridable set is a type rather than a\n * list repeated in prose and in a literal: `OVERRIDABLE_KEYS` below is indexed\n * by this interface, so an eighth setting added here fails to compile until it\n * is spelled there too, instead of silently being non-overridable.\n */\ninterface MenuSelectionContext {\n selectionMode?: SelectionMode;\n selectedKeys?: string[];\n disabledKeys?: string[];\n allowEmpty?: boolean;\n onAction?: (key: string) => void;\n onSelectionChange?: (keys: string[]) => void;\n closeOnItemSelect?: boolean;\n}\n\nconst OVERRIDABLE_KEYS: Record<keyof MenuSelectionContext, true> = {\n selectionMode: true,\n selectedKeys: true,\n disabledKeys: true,\n allowEmpty: true,\n onAction: true,\n onSelectionChange: true,\n closeOnItemSelect: true\n};\n\ninterface RootMenuContextArgs extends Omit<\n MenuContext,\n 'depth' | 'closeRoot' | 'closeSelf' | 'registerSub' | 'unregisterSub'\n> {\n /** The root popover's close, used for both `closeRoot` and `closeSelf`. */\n close: () => void;\n}\n\n/**\n * `subs` is passed in rather than created here, and deliberately so: the\n * caller is a Glimmer component whose getter rebuilds this object on every\n * render, and a map created here would drop every `Sub` that had already\n * registered. The component owns one stable map for the life of the level.\n */\nfunction bindSubRegistry(\n subs: Map<string, SubHandle>\n): Pick<MenuContext, 'registerSub' | 'unregisterSub'> {\n return {\n registerSub: (key, handle) => subs.set(key, handle),\n unregisterSub: (key) => subs.delete(key)\n };\n}\n\nfunction createRootMenuContext(args: RootMenuContextArgs): MenuContext {\n const { close, subs, ...shared } = args;\n\n return {\n ...shared,\n depth: 0,\n subs,\n closeRoot: close,\n closeSelf: close,\n ...bindSubRegistry(subs)\n };\n}\n\nfunction createChildMenuContext(\n parent: MenuContext,\n options: { closeSelf: () => void; subs: Map<string, SubHandle> }\n): MenuContext {\n const { closeSelf, subs } = options;\n\n return {\n ...parent,\n depth: parent.depth + 1,\n subs,\n closeSelf,\n ...bindSubRegistry(subs)\n };\n}\n\n/**\n * Layers a level's own declarations over the context it inherited.\n *\n * Only settings actually written on this level count: reading them\n * unconditionally would overwrite inherited values with `undefined` and\n * silently break inheritance, which is the default and by far the common case.\n * That case also allocates nothing and hands back the parent's own object, so\n * a level that declares nothing is indistinguishable downstream from one that\n * never had the chance to.\n */\nfunction createOverriddenMenuContext(\n parent: MenuContext,\n own: MenuSelectionContext\n): MenuContext {\n let overrides: Partial<MenuSelectionContext> | undefined;\n\n for (const key of Object.keys(\n OVERRIDABLE_KEYS\n ) as (keyof MenuSelectionContext)[]) {\n const value = own[key];\n\n if (value !== undefined) {\n overrides ??= {};\n // Correlating the key with its own value type is beyond what TS narrows\n // across an index like this; the `Record` above is what actually keeps\n // the key set honest.\n overrides[key] = value as never;\n }\n }\n\n return overrides ? { ...parent, ...overrides } : parent;\n}\n\nexport {\n createRootMenuContext,\n createChildMenuContext,\n createOverriddenMenuContext,\n type MenuContext,\n type MenuSelectionContext,\n type RootMenuContextArgs,\n type SubHandle,\n type OpenSource\n};\n"],"names":["OVERRIDABLE_KEYS","selectionMode","selectedKeys","disabledKeys","allowEmpty","onAction","onSelectionChange","closeOnItemSelect","bindSubRegistry","subs","registerSub","key","handle","set","unregisterSub","delete","createRootMenuContext","args","close","shared","depth","closeRoot","closeSelf","createChildMenuContext","parent","options","createOverriddenMenuContext","own","overrides","Object","keys","value","undefined"],"mappings":"
|
|
1
|
+
{"version":3,"file":"menu-context.js","sources":["../../../../src/components/collections/dropdown/menu-context.ts"],"sourcesContent":["import type { SelectionMode } from '../../../utils/listManager';\nimport type { Point } from '../../../utils/safe-area';\nimport type { ListboxItemSignature } from '../listbox/item';\n\n/**\n * How a submenu was asked to open.\n *\n * It decides whether the submenu highlights its first item: a keyboard user\n * who pressed ArrowRight expects to be somewhere, while a pointer user\n * hovering a row does not expect a selection to move. The `Listbox` at each\n * level is constructed fresh on open, so the source is read once, at mount,\n * as `autoActivateMode`.\n */\ntype OpenSource = 'pointer' | 'keyboard';\n\n/**\n * What a level needs in order to drive a submenu it does not itself render.\n *\n * A level's ArrowRight handler has to open the submenu belonging to whichever\n * item is currently active. The item knows nothing about the submenu, and the\n * `Sub` renders inside the level's own block -- so each `Sub` registers a\n * handle under its trigger's key, and the level looks it up.\n */\ninterface SubHandle {\n open: (source: OpenSource) => void;\n close: () => void;\n\n /**\n * Whether this submenu is open and the pointer is somewhere that should\n * keep it that way -- its own safe area, or one of its own descendants'.\n *\n * A level asks this of its children before closing itself. A third level\n * sits outside the second level's safe area entirely, so without it the\n * whole chain unwinds the moment the pointer goes deeper than one level.\n */\n isPointSafe: (point: Point) => boolean;\n}\n\ninterface MenuContext extends MenuSelectionContext {\n /** 0 for the root menu, 1 for a submenu, and so on. */\n depth: number;\n\n /**\n * Close the whole chain. Choosing a leaf three levels down dismisses the\n * entire dropdown, not just the level the leaf sits in.\n */\n closeRoot: () => void;\n\n /**\n * Close just this level, leaving its parent open -- what ArrowLeft does.\n * On the root this is the same thing as `closeRoot`.\n */\n closeSelf: () => void;\n\n /** The submenus registered at this level, keyed by their trigger's key. */\n subs: Map<string, SubHandle>;\n registerSub: (key: string, handle: SubHandle) => void;\n unregisterSub: (key: string) => void;\n\n // Appearance and timing are the root's for the whole chain: a submenu that\n // styled itself would make one menu look like two, so these are declared\n // once on the root and never overridden below it.\n variant?: ListboxItemSignature['Args']['variant'];\n color?: ListboxItemSignature['Args']['color'];\n shortcutVariant?: ListboxItemSignature['Args']['shortcutVariant'];\n disableTransitions?: boolean;\n transitionDuration?: number;\n}\n\n/**\n * The parts of a context a level may declare for itself.\n *\n * Declared once on the root and inherited by every depth -- so `@onAction` and\n * `@selectedKeys` written at the top apply to a leaf at any level -- but a\n * submenu may override any of them for its own level and the levels below,\n * which is what lets a navigation menu hold a multi-select submenu.\n *\n * Split out from `MenuContext` so the overridable set is a type rather than a\n * list repeated in prose and in a literal: `OVERRIDABLE_KEYS` below is indexed\n * by this interface, so an eighth setting added here fails to compile until it\n * is spelled there too, instead of silently being non-overridable.\n */\ninterface MenuSelectionContext {\n selectionMode?: SelectionMode;\n selectedKeys?: string[];\n disabledKeys?: string[];\n allowEmpty?: boolean;\n onAction?: (key: string) => void;\n onSelectionChange?: (keys: string[]) => void;\n closeOnItemSelect?: boolean;\n}\n\nconst OVERRIDABLE_KEYS: Record<keyof MenuSelectionContext, true> = {\n selectionMode: true,\n selectedKeys: true,\n disabledKeys: true,\n allowEmpty: true,\n onAction: true,\n onSelectionChange: true,\n closeOnItemSelect: true\n};\n\ninterface RootMenuContextArgs extends Omit<\n MenuContext,\n 'depth' | 'closeRoot' | 'closeSelf' | 'registerSub' | 'unregisterSub'\n> {\n /** The root popover's close, used for both `closeRoot` and `closeSelf`. */\n close: () => void;\n}\n\n/**\n * `subs` is passed in rather than created here, and deliberately so: the\n * caller is a Glimmer component whose getter rebuilds this object on every\n * render, and a map created here would drop every `Sub` that had already\n * registered. The component owns one stable map for the life of the level.\n */\nfunction bindSubRegistry(\n subs: Map<string, SubHandle>\n): Pick<MenuContext, 'registerSub' | 'unregisterSub'> {\n return {\n registerSub: (key, handle) => subs.set(key, handle),\n unregisterSub: (key) => subs.delete(key)\n };\n}\n\nfunction createRootMenuContext(args: RootMenuContextArgs): MenuContext {\n const { close, subs, ...shared } = args;\n\n return {\n ...shared,\n depth: 0,\n subs,\n closeRoot: close,\n closeSelf: close,\n ...bindSubRegistry(subs)\n };\n}\n\nfunction createChildMenuContext(\n parent: MenuContext,\n options: { closeSelf: () => void; subs: Map<string, SubHandle> }\n): MenuContext {\n const { closeSelf, subs } = options;\n\n return {\n ...parent,\n depth: parent.depth + 1,\n subs,\n closeSelf,\n ...bindSubRegistry(subs)\n };\n}\n\n/**\n * Layers a level's own declarations over the context it inherited.\n *\n * Only settings actually written on this level count: reading them\n * unconditionally would overwrite inherited values with `undefined` and\n * silently break inheritance, which is the default and by far the common case.\n * That case also allocates nothing and hands back the parent's own object, so\n * a level that declares nothing is indistinguishable downstream from one that\n * never had the chance to.\n */\nfunction createOverriddenMenuContext(\n parent: MenuContext,\n own: MenuSelectionContext\n): MenuContext {\n let overrides: Partial<MenuSelectionContext> | undefined;\n\n for (const key of Object.keys(\n OVERRIDABLE_KEYS\n ) as (keyof MenuSelectionContext)[]) {\n const value = own[key];\n\n if (value !== undefined) {\n overrides ??= {};\n // Correlating the key with its own value type is beyond what TS narrows\n // across an index like this; the `Record` above is what actually keeps\n // the key set honest.\n overrides[key] = value as never;\n }\n }\n\n return overrides ? { ...parent, ...overrides } : parent;\n}\n\nexport {\n createRootMenuContext,\n createChildMenuContext,\n createOverriddenMenuContext,\n type MenuContext,\n type MenuSelectionContext,\n type RootMenuContextArgs,\n type SubHandle,\n type OpenSource\n};\n"],"names":["OVERRIDABLE_KEYS","selectionMode","selectedKeys","disabledKeys","allowEmpty","onAction","onSelectionChange","closeOnItemSelect","bindSubRegistry","subs","registerSub","key","handle","set","unregisterSub","delete","createRootMenuContext","args","close","shared","depth","closeRoot","closeSelf","createChildMenuContext","parent","options","createOverriddenMenuContext","own","overrides","Object","keys","value","undefined"],"mappings":"AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA+CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,MAAMA,gBAA0D,GAAG;AACjEC,EAAAA,aAAa,EAAE,IAAI;AACnBC,EAAAA,YAAY,EAAE,IAAI;AAClBC,EAAAA,YAAY,EAAE,IAAI;AAClBC,EAAAA,UAAU,EAAE,IAAI;AAChBC,EAAAA,QAAQ,EAAE,IAAI;AACdC,EAAAA,iBAAiB,EAAE,IAAI;AACvBC,EAAAA,iBAAiB,EAAE;AACrB,CAAC;AAUD;AACA;AACA;AACA;AACA;AACA;AACA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B,KAAc;AACjC,IAAA;AACF,EAAA;AAEA,EAAA,OAAOH,SAAS,GAAG;AAAE,IAAA,GAAGJ,MAAM;IAAE,GAAGI;AAAU,GAAC,GAAGJ,MAAM;AACzD;;"}
|
|
@@ -86,19 +86,43 @@ class Sub extends Component {
|
|
|
86
86
|
this.args.parentContext.unregisterSub(this.triggerKey);
|
|
87
87
|
this.stopTracking();
|
|
88
88
|
cancel(this.#openTimer);
|
|
89
|
-
|
|
89
|
+
this.cancelClose();
|
|
90
90
|
}
|
|
91
91
|
handle = {
|
|
92
92
|
open: source => this.open(source),
|
|
93
|
-
close: () => this.close()
|
|
93
|
+
close: () => this.close(),
|
|
94
|
+
isPointSafe: point => this.isPointSafe(point)
|
|
94
95
|
};
|
|
95
96
|
open = (source = 'pointer') => {
|
|
97
|
+
this.closeSiblings();
|
|
96
98
|
this.openSource = source;
|
|
97
99
|
this.isOpen = true;
|
|
98
100
|
this.startTracking();
|
|
99
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* Close every other submenu at this level.
|
|
104
|
+
*
|
|
105
|
+
* Two sub-triggers next to each other would otherwise both stay on screen:
|
|
106
|
+
* the abandoned level's own close is on a timer, and the pointer moving
|
|
107
|
+
* toward the new one keeps re-arming it. A level's siblings are exactly the
|
|
108
|
+
* other entries in the parent's registry, so closing them as this one opens
|
|
109
|
+
* makes the two states mutually exclusive in a single render -- there is no
|
|
110
|
+
* frame in which both are painted.
|
|
111
|
+
*/
|
|
112
|
+
closeSiblings = () => {
|
|
113
|
+
for (const [key, handle] of this.args.parentContext.subs) {
|
|
114
|
+
if (key !== this.triggerKey) {
|
|
115
|
+
handle.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
100
119
|
close = () => {
|
|
101
120
|
this.stopTracking();
|
|
121
|
+
// Not just bookkeeping: a close that arrives from elsewhere -- a sibling
|
|
122
|
+
// opening, ArrowLeft -- while a timer is pending would otherwise leave
|
|
123
|
+
// that timer to fire later and close a level the pointer had meanwhile
|
|
124
|
+
// brought back.
|
|
125
|
+
this.cancelClose();
|
|
102
126
|
if (this.isDestroyed || this.isDestroying) {
|
|
103
127
|
return;
|
|
104
128
|
}
|
|
@@ -129,22 +153,50 @@ class Sub extends Component {
|
|
|
129
153
|
* is outside the safe area, so moving onto one closes the submenu.
|
|
130
154
|
*/
|
|
131
155
|
trackPointer = event => {
|
|
132
|
-
|
|
133
|
-
|
|
156
|
+
// Nothing to measure against yet -- neither close nor cancel, just wait
|
|
157
|
+
// for the next move.
|
|
158
|
+
if (!this.#triggerEl || !document.getElementById(this.submenuId)) {
|
|
134
159
|
return;
|
|
135
160
|
}
|
|
136
|
-
|
|
137
|
-
const content = submenu.getBoundingClientRect();
|
|
138
|
-
const point = {
|
|
161
|
+
if (this.isPointSafe({
|
|
139
162
|
x: event.clientX,
|
|
140
163
|
y: event.clientY
|
|
141
|
-
}
|
|
142
|
-
if (isPointInSafeArea(point, trigger, content)) {
|
|
164
|
+
})) {
|
|
143
165
|
this.cancelClose();
|
|
144
166
|
} else {
|
|
145
167
|
this.scheduleClose();
|
|
146
168
|
}
|
|
147
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Whether the pointer is somewhere that should keep this level open.
|
|
172
|
+
*
|
|
173
|
+
* Its own safe area, or -- recursively -- any open descendant's. A third
|
|
174
|
+
* level opens to the right of the second, well outside the polygon that
|
|
175
|
+
* runs from *this* trigger to *this* content, so a level that only
|
|
176
|
+
* consulted its own area would close the instant the pointer went deeper,
|
|
177
|
+
* taking every level below it along. Asking the children means the chain
|
|
178
|
+
* survives exactly as long as the pointer is still somewhere in it.
|
|
179
|
+
*/
|
|
180
|
+
isPointSafe = point => {
|
|
181
|
+
if (!this.isOpen) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const submenu = document.getElementById(this.submenuId);
|
|
185
|
+
if (!this.#triggerEl || !submenu) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const trigger = this.#triggerEl.getBoundingClientRect();
|
|
189
|
+
const content = submenu.getBoundingClientRect();
|
|
190
|
+
if (isPointInSafeArea(point, trigger, content)) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
for (const handle of this.#childSubs.values()) {
|
|
194
|
+
if (handle.isPointSafe(point)) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
};
|
|
148
200
|
startTracking = () => {
|
|
149
201
|
if (this.#isTracking) {
|
|
150
202
|
return;
|
|
@@ -164,9 +216,22 @@ class Sub extends Component {
|
|
|
164
216
|
cancel(this.#openTimer);
|
|
165
217
|
this.#openTimer = later(this, () => this.open('pointer'), SUBMENU_OPEN_DELAY);
|
|
166
218
|
};
|
|
219
|
+
/**
|
|
220
|
+
* Arm the close, but never re-arm one already pending.
|
|
221
|
+
*
|
|
222
|
+
* This runs from every `pointermove` that lands outside the safe area, so
|
|
223
|
+
* cancelling and re-scheduling here would let a pointer that simply keeps
|
|
224
|
+
* moving -- across a sibling row, into a sibling's submenu, anywhere on the
|
|
225
|
+
* page -- push the close out indefinitely and strand the level open. Once
|
|
226
|
+
* the pointer has left, the countdown is from that moment and nothing
|
|
227
|
+
* outside the safe area extends it; only `cancelClose` (the pointer coming
|
|
228
|
+
* back inside) stops it.
|
|
229
|
+
*/
|
|
167
230
|
scheduleClose = () => {
|
|
168
231
|
cancel(this.#openTimer);
|
|
169
|
-
|
|
232
|
+
if (this.#closeTimer) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
170
235
|
this.#closeTimer = later(this, this.close, SUBMENU_CLOSE_DELAY);
|
|
171
236
|
};
|
|
172
237
|
cancelClose = () => {
|
|
@@ -181,7 +246,7 @@ class Sub extends Component {
|
|
|
181
246
|
el.removeEventListener('pointerenter', this.scheduleOpen);
|
|
182
247
|
el.removeEventListener('pointerleave', this.scheduleClose);
|
|
183
248
|
cancel(this.#openTimer);
|
|
184
|
-
|
|
249
|
+
this.cancelClose();
|
|
185
250
|
this.stopTracking();
|
|
186
251
|
if (this.#triggerEl === el) {
|
|
187
252
|
this.#triggerEl = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sub.js","sources":["../../../../src/components/collections/dropdown/sub.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { guidFor } from '@ember/object/internals';\nimport { assert } from '@ember/debug';\nimport { hash } from '@ember/helper';\nimport { cancel, later } from '@ember/runloop';\nimport { modifier } from 'ember-modifier';\nimport { Popover, type PopoverSignature } from '../../overlays/popover';\nimport { createChildMenuContext } from './menu-context';\nimport type { MenuContext, OpenSource, SubHandle } from './menu-context';\nimport type { ListboxItem } from '../listbox/item';\nimport type Owner from '@ember/owner';\nimport type { Timer } from '@ember/runloop';\nimport type { WithBoundArgs } from '@glint/template';\nimport type { ModifierLike } from '@glint/template';\nimport type { Menu } from './dropdown';\nimport { isPointInSafeArea, type Rect } from '../../../utils/safe-area';\n\n/**\n * Long enough that dragging the pointer across a row on its way somewhere else\n * does not flash a submenu open, short enough to feel immediate when the\n * pointer settles.\n */\nconst SUBMENU_OPEN_DELAY = 100;\n\n/**\n * The pointer has to cross a gap to reach the submenu, so leaving the trigger\n * cannot close it instantly. The safe-area check below decides *where* the\n * pointer is allowed to go; this is how long it has to get there.\n */\nconst SUBMENU_CLOSE_DELAY = 300;\n\n/**\n * The raw, unbound `Menu` component, handed in rather than imported.\n *\n * `Menu` yields `Sub`, and a `Sub` renders a `Menu` for its own level. Passing\n * it in keeps the *runtime* import running one way -- `dropdown.gts` imports\n * `sub.gts` and nothing goes back at runtime, so there is no import cycle to\n * reason about there. This is a TYPE-only import of `Menu` from `dropdown.gts`\n * (see the `import type` above): it disappears entirely once compiled, so it\n * creates no runtime dependency and no cycle. A loose `ComponentLike<...>`\n * shape was tried first and rejected by Glint -- currying `Sub`'s own named\n * args onto a `ComponentLike` signature produced an \"excessively deep type\n * instantiation\" error, because Glint could not resolve the curried result\n * back to a concrete `Blocks` shape. Naming the real `Menu` type here (still\n * without a runtime import) keeps that resolution concrete.\n */\ntype MenuComponent = typeof Menu;\n\n/**\n * The bound-args shape `Sub` produces for its own `s.Menu` -- `Content`,\n * `context`, `depth`, `menuId`, `openSource` and `close` are all curried\n * by `Sub` itself (see the template below), so a consumer only ever supplies\n * the public args (`@selectionMode`, `@onAction`, and so on).\n */\ntype BoundMenuComponent = WithBoundArgs<\n typeof Menu,\n 'context' | 'depth' | 'menuId' | 'openSource' | 'close' | 'Content'\n>;\n\ninterface SubArgs extends Pick<\n PopoverSignature['Args'],\n | 'placement'\n | 'flipOptions'\n | 'middleware'\n | 'shiftOptions'\n | 'offsetOptions'\n | 'strategy'\n> {\n /**\n * @internal\n *\n * Named `item` rather than `Item`: Ember's template compiler treats any\n * named arg whose first letter is not lowercase (`@Item`, `@Menu`, ...) as\n * reserved and refuses to reference it inside a template -- so every named\n * arg here and on `SubTrigger` below is lowercase even though the values\n * yielded to consumers (`Trigger`, `Menu`, `Sub`) stay capitalized block\n * params, which are not subject to that rule.\n */\n item: WithBoundArgs<typeof ListboxItem, 'manager'>;\n\n /**\n * @internal\n *\n * The raw, unbound `Menu` -- `Sub` curries `Content`/`context`/`depth`/\n * `menuId`/`openSource`/`close` onto it itself (see `BoundMenuComponent`\n * above and the template below).\n */\n menu: MenuComponent;\n\n /**\n * @internal\n */\n parentContext: MenuContext;\n}\n\nexport interface SubSignature {\n Args: SubArgs;\n Blocks: {\n default: [\n {\n Trigger: WithBoundArgs<\n typeof SubTrigger,\n | 'item'\n | 'anchor'\n | 'onTriggerClick'\n | 'isOpen'\n | 'submenuId'\n | 'key'\n | 'hoverTrigger'\n >;\n Menu: BoundMenuComponent;\n isOpen: boolean;\n }\n ];\n };\n}\n\nclass Sub extends Component<SubSignature> {\n /**\n * The key the trigger registers under.\n *\n * Generated rather than asked for: a sub-trigger never selects, so its key\n * never reaches `onAction` or `selectedKeys`, and making consumers invent\n * one would be asking for a value nothing observes.\n */\n triggerKey = `${guidFor(this)}-sub-trigger`;\n\n /** The id of this submenu's `role=\"menu\"` element, for `aria-controls`. */\n submenuId = `${guidFor(this)}-submenu`;\n\n /**\n * The registry this level's own children write into. One map for the life of\n * the component -- see `createRootMenuContext` for why it cannot be built in\n * the getter.\n */\n #childSubs = new Map<string, SubHandle>();\n\n /**\n * The popover is driven in controlled mode.\n *\n * The parent level has to be able to open this submenu from its own\n * ArrowRight handler, through the registered `SubHandle` -- so the open\n * state has to live somewhere reachable from outside the Popover's block,\n * which the yielded `open`/`close` are not.\n */\n @tracked isOpen = false;\n\n /**\n * Not tracked: it is read once, when the freshly mounted `Listbox`\n * constructs its `ListManager`, and never rendered.\n */\n openSource: OpenSource = 'pointer';\n\n constructor(owner: Owner, args: SubArgs) {\n super(owner, args);\n this.args.parentContext.registerSub(this.triggerKey, this.handle);\n }\n\n willDestroy(): void {\n super.willDestroy();\n this.args.parentContext.unregisterSub(this.triggerKey);\n this.stopTracking();\n cancel(this.#openTimer);\n cancel(this.#closeTimer);\n }\n\n handle: SubHandle = {\n open: (source: OpenSource) => this.open(source),\n close: () => this.close()\n };\n\n open = (source: OpenSource = 'pointer') => {\n this.openSource = source;\n this.isOpen = true;\n this.startTracking();\n };\n\n close = () => {\n this.stopTracking();\n\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n this.isOpen = false;\n };\n\n #openTimer?: Timer;\n #closeTimer?: Timer;\n\n /**\n * The trigger element, captured by `hoverTrigger`, so the safe area can be\n * measured without querying for it.\n */\n #triggerEl?: HTMLElement;\n\n /**\n * Whether the pointer is currently being tracked against the safe area.\n * Guards against installing the document listener twice.\n */\n #isTracking = false;\n\n /**\n * Keeps the submenu open while the pointer is heading for it.\n *\n * The pointer has to cross a gap to reach a submenu, and it crosses it\n * diagonally -- so `pointerleave` on the trigger cannot mean \"close\". While\n * the submenu is open, every pointer move is tested against the safe area:\n * inside it, the pending close is cancelled; outside it, the pointer has\n * clearly gone elsewhere and the submenu closes.\n *\n * This also handles hovering a sibling row with no extra wiring: a sibling\n * is outside the safe area, so moving onto one closes the submenu.\n */\n trackPointer = (event: PointerEvent) => {\n const submenu = document.getElementById(this.submenuId);\n if (!this.#triggerEl || !submenu) {\n return;\n }\n\n const trigger: Rect = this.#triggerEl.getBoundingClientRect();\n const content: Rect = submenu.getBoundingClientRect();\n const point = { x: event.clientX, y: event.clientY };\n\n if (isPointInSafeArea(point, trigger, content)) {\n this.cancelClose();\n } else {\n this.scheduleClose();\n }\n };\n\n startTracking = () => {\n if (this.#isTracking) {\n return;\n }\n this.#isTracking = true;\n document.addEventListener('pointermove', this.trackPointer);\n };\n\n stopTracking = () => {\n if (!this.#isTracking) {\n return;\n }\n this.#isTracking = false;\n document.removeEventListener('pointermove', this.trackPointer);\n };\n\n scheduleOpen = () => {\n this.cancelClose();\n cancel(this.#openTimer);\n this.#openTimer = later(\n this,\n () => this.open('pointer'),\n SUBMENU_OPEN_DELAY\n );\n };\n\n scheduleClose = () => {\n cancel(this.#openTimer);\n cancel(this.#closeTimer);\n this.#closeTimer = later(this, this.close, SUBMENU_CLOSE_DELAY);\n };\n\n cancelClose = () => {\n cancel(this.#closeTimer);\n this.#closeTimer = undefined;\n };\n\n hoverTrigger = modifier((el: HTMLElement) => {\n this.#triggerEl = el;\n el.addEventListener('pointerenter', this.scheduleOpen);\n el.addEventListener('pointerleave', this.scheduleClose);\n\n return () => {\n el.removeEventListener('pointerenter', this.scheduleOpen);\n el.removeEventListener('pointerleave', this.scheduleClose);\n cancel(this.#openTimer);\n cancel(this.#closeTimer);\n this.stopTracking();\n if (this.#triggerEl === el) {\n this.#triggerEl = undefined;\n }\n };\n });\n\n onTriggerClick = () => {\n if (this.isOpen) {\n this.close();\n } else {\n this.open('pointer');\n }\n };\n\n setOpen = (isOpen: boolean) => {\n this.isOpen = isOpen;\n };\n\n get childContext(): MenuContext {\n return createChildMenuContext(this.args.parentContext, {\n closeSelf: this.close,\n subs: this.#childSubs\n });\n }\n\n get depth(): number {\n return this.args.parentContext.depth + 1;\n }\n\n <template>\n <Popover\n @isOpen={{this.isOpen}}\n @onOpenChange={{this.setOpen}}\n @placement={{if @placement @placement \"right-start\"}}\n @flipOptions={{@flipOptions}}\n @middleware={{@middleware}}\n @shiftOptions={{@shiftOptions}}\n @offsetOptions={{@offsetOptions}}\n @strategy={{@strategy}}\n as |p|\n >\n {{yield\n (hash\n Trigger=(component\n SubTrigger\n item=@item\n anchor=p.anchor\n onTriggerClick=this.onTriggerClick\n isOpen=this.isOpen\n submenuId=this.submenuId\n key=this.triggerKey\n hoverTrigger=this.hoverTrigger\n )\n Menu=(component\n @menu\n Content=p.Content\n context=this.childContext\n depth=this.depth\n menuId=this.submenuId\n openSource=this.openSource\n close=this.close\n )\n isOpen=this.isOpen\n )\n }}\n </Popover>\n </template>\n}\n\ninterface SubTriggerArgs {\n /**\n * @internal\n */\n item: WithBoundArgs<typeof ListboxItem, 'manager'>;\n\n /**\n * @internal\n */\n anchor: ModifierLike<{ Element: HTMLElement }>;\n\n /**\n * @internal\n */\n onTriggerClick: () => void;\n\n /**\n * @internal\n */\n isOpen: boolean;\n\n /**\n * @internal\n */\n submenuId: string;\n\n /**\n * The key this row registers under. Generated by `Sub` when omitted; accept\n * an override so a test or a consumer can address the row by `data-key`.\n */\n key?: string;\n\n /**\n * @internal\n */\n hoverTrigger: ModifierLike<{ Element: HTMLElement }>;\n}\n\nexport interface SubTriggerSignature {\n Args: SubTriggerArgs;\n Element: HTMLLIElement;\n Blocks: { default: [] };\n}\n\n/**\n * The row that opens a submenu.\n *\n * It renders the parent level's own bound `item`, so it registers with that\n * level's `ListManager` and takes part in arrow navigation, type-ahead and the\n * roving tab stop exactly like any other row -- while `@hasSubmenu` keeps it\n * from ever selecting.\n */\nclass SubTrigger extends Component<SubTriggerSignature> {\n /**\n * `Sub` always binds a generated `key` by default (see `Sub`'s\n * `Trigger=(component SubTrigger ... key=this.triggerKey)`), so this is\n * never actually missing -- but `@key` on `SubTriggerArgs` stays optional so\n * a consumer-supplied override can win, and `ListboxItem.key` needs a plain\n * `string`, not `string | undefined`.\n */\n get key(): string {\n assert(\n `Sub's item did not receive a @key -- Sub always binds a generated key by default`,\n this.args.key\n );\n\n return this.args.key;\n }\n\n <template>\n <@item\n @key={{this.key}}\n @hasSubmenu={{true}}\n @isSubmenuOpen={{@isOpen}}\n @submenuId={{@submenuId}}\n @onClick={{@onTriggerClick}}\n {{@anchor}}\n {{@hoverTrigger}}\n data-test-id=\"dropdown-submenu-trigger\"\n ...attributes\n >\n {{yield}}\n </@item>\n </template>\n}\n\nexport { Sub, SubTrigger };\n"],"names":["SUBMENU_OPEN_DELAY","SUBMENU_CLOSE_DELAY","Sub","Component","triggerKey","guidFor","submenuId","Map","g","prototype","tracked","i","openSource","constructor","owner","args","parentContext","registerSub","handle","willDestroy","unregisterSub","stopTracking","cancel","open","source","close","isOpen","startTracking","isDestroyed","isDestroying","trackPointer","event","submenu","document","getElementById","trigger","getBoundingClientRect","content","point","x","clientX","y","clientY","isPointInSafeArea","cancelClose","scheduleClose","addEventListener","removeEventListener","scheduleOpen","later","undefined","hoverTrigger","modifier","el","onTriggerClick","setOpen","childContext","createChildMenuContext","closeSelf","subs","depth","setComponentTemplate","precompileTemplate","strictMode","scope","Popover","hash","SubTrigger","key","assert"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAMA,kBAAA,GAAqB,GAAA;AAE3B;;;;AAIC;AACD,MAAMC,mBAAA,GAAsB,GAAA;AAE5B;;;;;;;;;;;;;;AAcC;AAGD;;;;;AAKC;;AAgED,MAAMC,YAAYC,SAAA,CAAU;AAC1B;;;;;;AAMC;AACDC,EAAAA,aAAa,CAAA,EAAGC,OAAA,CAAQ,IAAI,CAAA,CAAA,YAAA,CAAe;AAE3C;AACAC,EAAAA,YAAY,CAAA,EAAGD,OAAA,CAAQ,IAAI,CAAA,CAAA,QAAA,CAAW;AAEtC;;;;AAIC;AACD,EAAA,UAAU,GAAG,IAAIE,GAAA,EAAY;AAE7B;;;;;;;AAOC;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3,"file":"sub.js","sources":["../../../../src/components/collections/dropdown/sub.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { guidFor } from '@ember/object/internals';\nimport { assert } from '@ember/debug';\nimport { hash } from '@ember/helper';\nimport { cancel, later } from '@ember/runloop';\nimport { modifier } from 'ember-modifier';\nimport { Popover, type PopoverSignature } from '../../overlays/popover';\nimport { createChildMenuContext } from './menu-context';\nimport type { MenuContext, OpenSource, SubHandle } from './menu-context';\nimport type { ListboxItem } from '../listbox/item';\nimport type Owner from '@ember/owner';\nimport type { Timer } from '@ember/runloop';\nimport type { WithBoundArgs } from '@glint/template';\nimport type { ModifierLike } from '@glint/template';\nimport type { Menu } from './dropdown';\nimport {\n isPointInSafeArea,\n type Point,\n type Rect\n} from '../../../utils/safe-area';\n\n/**\n * Long enough that dragging the pointer across a row on its way somewhere else\n * does not flash a submenu open, short enough to feel immediate when the\n * pointer settles.\n */\nconst SUBMENU_OPEN_DELAY = 100;\n\n/**\n * The pointer has to cross a gap to reach the submenu, so leaving the trigger\n * cannot close it instantly. The safe-area check below decides *where* the\n * pointer is allowed to go; this is how long it has to get there.\n */\nconst SUBMENU_CLOSE_DELAY = 300;\n\n/**\n * The raw, unbound `Menu` component, handed in rather than imported.\n *\n * `Menu` yields `Sub`, and a `Sub` renders a `Menu` for its own level. Passing\n * it in keeps the *runtime* import running one way -- `dropdown.gts` imports\n * `sub.gts` and nothing goes back at runtime, so there is no import cycle to\n * reason about there. This is a TYPE-only import of `Menu` from `dropdown.gts`\n * (see the `import type` above): it disappears entirely once compiled, so it\n * creates no runtime dependency and no cycle. A loose `ComponentLike<...>`\n * shape was tried first and rejected by Glint -- currying `Sub`'s own named\n * args onto a `ComponentLike` signature produced an \"excessively deep type\n * instantiation\" error, because Glint could not resolve the curried result\n * back to a concrete `Blocks` shape. Naming the real `Menu` type here (still\n * without a runtime import) keeps that resolution concrete.\n */\ntype MenuComponent = typeof Menu;\n\n/**\n * The bound-args shape `Sub` produces for its own `s.Menu` -- `Content`,\n * `context`, `depth`, `menuId`, `openSource` and `close` are all curried\n * by `Sub` itself (see the template below), so a consumer only ever supplies\n * the public args (`@selectionMode`, `@onAction`, and so on).\n */\ntype BoundMenuComponent = WithBoundArgs<\n typeof Menu,\n 'context' | 'depth' | 'menuId' | 'openSource' | 'close' | 'Content'\n>;\n\ninterface SubArgs extends Pick<\n PopoverSignature['Args'],\n | 'placement'\n | 'flipOptions'\n | 'middleware'\n | 'shiftOptions'\n | 'offsetOptions'\n | 'strategy'\n> {\n /**\n * @internal\n *\n * Named `item` rather than `Item`: Ember's template compiler treats any\n * named arg whose first letter is not lowercase (`@Item`, `@Menu`, ...) as\n * reserved and refuses to reference it inside a template -- so every named\n * arg here and on `SubTrigger` below is lowercase even though the values\n * yielded to consumers (`Trigger`, `Menu`, `Sub`) stay capitalized block\n * params, which are not subject to that rule.\n */\n item: WithBoundArgs<typeof ListboxItem, 'manager'>;\n\n /**\n * @internal\n *\n * The raw, unbound `Menu` -- `Sub` curries `Content`/`context`/`depth`/\n * `menuId`/`openSource`/`close` onto it itself (see `BoundMenuComponent`\n * above and the template below).\n */\n menu: MenuComponent;\n\n /**\n * @internal\n */\n parentContext: MenuContext;\n}\n\nexport interface SubSignature {\n Args: SubArgs;\n Blocks: {\n default: [\n {\n Trigger: WithBoundArgs<\n typeof SubTrigger,\n | 'item'\n | 'anchor'\n | 'onTriggerClick'\n | 'isOpen'\n | 'submenuId'\n | 'key'\n | 'hoverTrigger'\n >;\n Menu: BoundMenuComponent;\n isOpen: boolean;\n }\n ];\n };\n}\n\nclass Sub extends Component<SubSignature> {\n /**\n * The key the trigger registers under.\n *\n * Generated rather than asked for: a sub-trigger never selects, so its key\n * never reaches `onAction` or `selectedKeys`, and making consumers invent\n * one would be asking for a value nothing observes.\n */\n triggerKey = `${guidFor(this)}-sub-trigger`;\n\n /** The id of this submenu's `role=\"menu\"` element, for `aria-controls`. */\n submenuId = `${guidFor(this)}-submenu`;\n\n /**\n * The registry this level's own children write into. One map for the life of\n * the component -- see `createRootMenuContext` for why it cannot be built in\n * the getter.\n */\n #childSubs = new Map<string, SubHandle>();\n\n /**\n * The popover is driven in controlled mode.\n *\n * The parent level has to be able to open this submenu from its own\n * ArrowRight handler, through the registered `SubHandle` -- so the open\n * state has to live somewhere reachable from outside the Popover's block,\n * which the yielded `open`/`close` are not.\n */\n @tracked isOpen = false;\n\n /**\n * Not tracked: it is read once, when the freshly mounted `Listbox`\n * constructs its `ListManager`, and never rendered.\n */\n openSource: OpenSource = 'pointer';\n\n constructor(owner: Owner, args: SubArgs) {\n super(owner, args);\n this.args.parentContext.registerSub(this.triggerKey, this.handle);\n }\n\n willDestroy(): void {\n super.willDestroy();\n this.args.parentContext.unregisterSub(this.triggerKey);\n this.stopTracking();\n cancel(this.#openTimer);\n this.cancelClose();\n }\n\n handle: SubHandle = {\n open: (source: OpenSource) => this.open(source),\n close: () => this.close(),\n isPointSafe: (point: Point) => this.isPointSafe(point)\n };\n\n open = (source: OpenSource = 'pointer') => {\n this.closeSiblings();\n this.openSource = source;\n this.isOpen = true;\n this.startTracking();\n };\n\n /**\n * Close every other submenu at this level.\n *\n * Two sub-triggers next to each other would otherwise both stay on screen:\n * the abandoned level's own close is on a timer, and the pointer moving\n * toward the new one keeps re-arming it. A level's siblings are exactly the\n * other entries in the parent's registry, so closing them as this one opens\n * makes the two states mutually exclusive in a single render -- there is no\n * frame in which both are painted.\n */\n closeSiblings = () => {\n for (const [key, handle] of this.args.parentContext.subs) {\n if (key !== this.triggerKey) {\n handle.close();\n }\n }\n };\n\n close = () => {\n this.stopTracking();\n // Not just bookkeeping: a close that arrives from elsewhere -- a sibling\n // opening, ArrowLeft -- while a timer is pending would otherwise leave\n // that timer to fire later and close a level the pointer had meanwhile\n // brought back.\n this.cancelClose();\n\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n this.isOpen = false;\n };\n\n #openTimer?: Timer;\n #closeTimer?: Timer;\n\n /**\n * The trigger element, captured by `hoverTrigger`, so the safe area can be\n * measured without querying for it.\n */\n #triggerEl?: HTMLElement;\n\n /**\n * Whether the pointer is currently being tracked against the safe area.\n * Guards against installing the document listener twice.\n */\n #isTracking = false;\n\n /**\n * Keeps the submenu open while the pointer is heading for it.\n *\n * The pointer has to cross a gap to reach a submenu, and it crosses it\n * diagonally -- so `pointerleave` on the trigger cannot mean \"close\". While\n * the submenu is open, every pointer move is tested against the safe area:\n * inside it, the pending close is cancelled; outside it, the pointer has\n * clearly gone elsewhere and the submenu closes.\n *\n * This also handles hovering a sibling row with no extra wiring: a sibling\n * is outside the safe area, so moving onto one closes the submenu.\n */\n trackPointer = (event: PointerEvent) => {\n // Nothing to measure against yet -- neither close nor cancel, just wait\n // for the next move.\n if (!this.#triggerEl || !document.getElementById(this.submenuId)) {\n return;\n }\n\n if (this.isPointSafe({ x: event.clientX, y: event.clientY })) {\n this.cancelClose();\n } else {\n this.scheduleClose();\n }\n };\n\n /**\n * Whether the pointer is somewhere that should keep this level open.\n *\n * Its own safe area, or -- recursively -- any open descendant's. A third\n * level opens to the right of the second, well outside the polygon that\n * runs from *this* trigger to *this* content, so a level that only\n * consulted its own area would close the instant the pointer went deeper,\n * taking every level below it along. Asking the children means the chain\n * survives exactly as long as the pointer is still somewhere in it.\n */\n isPointSafe = (point: Point): boolean => {\n if (!this.isOpen) {\n return false;\n }\n\n const submenu = document.getElementById(this.submenuId);\n if (!this.#triggerEl || !submenu) {\n return false;\n }\n\n const trigger: Rect = this.#triggerEl.getBoundingClientRect();\n const content: Rect = submenu.getBoundingClientRect();\n\n if (isPointInSafeArea(point, trigger, content)) {\n return true;\n }\n\n for (const handle of this.#childSubs.values()) {\n if (handle.isPointSafe(point)) {\n return true;\n }\n }\n\n return false;\n };\n\n startTracking = () => {\n if (this.#isTracking) {\n return;\n }\n this.#isTracking = true;\n document.addEventListener('pointermove', this.trackPointer);\n };\n\n stopTracking = () => {\n if (!this.#isTracking) {\n return;\n }\n this.#isTracking = false;\n document.removeEventListener('pointermove', this.trackPointer);\n };\n\n scheduleOpen = () => {\n this.cancelClose();\n cancel(this.#openTimer);\n this.#openTimer = later(\n this,\n () => this.open('pointer'),\n SUBMENU_OPEN_DELAY\n );\n };\n\n /**\n * Arm the close, but never re-arm one already pending.\n *\n * This runs from every `pointermove` that lands outside the safe area, so\n * cancelling and re-scheduling here would let a pointer that simply keeps\n * moving -- across a sibling row, into a sibling's submenu, anywhere on the\n * page -- push the close out indefinitely and strand the level open. Once\n * the pointer has left, the countdown is from that moment and nothing\n * outside the safe area extends it; only `cancelClose` (the pointer coming\n * back inside) stops it.\n */\n scheduleClose = () => {\n cancel(this.#openTimer);\n\n if (this.#closeTimer) {\n return;\n }\n\n this.#closeTimer = later(this, this.close, SUBMENU_CLOSE_DELAY);\n };\n\n cancelClose = () => {\n cancel(this.#closeTimer);\n this.#closeTimer = undefined;\n };\n\n hoverTrigger = modifier((el: HTMLElement) => {\n this.#triggerEl = el;\n el.addEventListener('pointerenter', this.scheduleOpen);\n el.addEventListener('pointerleave', this.scheduleClose);\n\n return () => {\n el.removeEventListener('pointerenter', this.scheduleOpen);\n el.removeEventListener('pointerleave', this.scheduleClose);\n cancel(this.#openTimer);\n this.cancelClose();\n this.stopTracking();\n if (this.#triggerEl === el) {\n this.#triggerEl = undefined;\n }\n };\n });\n\n onTriggerClick = () => {\n if (this.isOpen) {\n this.close();\n } else {\n this.open('pointer');\n }\n };\n\n setOpen = (isOpen: boolean) => {\n this.isOpen = isOpen;\n };\n\n get childContext(): MenuContext {\n return createChildMenuContext(this.args.parentContext, {\n closeSelf: this.close,\n subs: this.#childSubs\n });\n }\n\n get depth(): number {\n return this.args.parentContext.depth + 1;\n }\n\n <template>\n <Popover\n @isOpen={{this.isOpen}}\n @onOpenChange={{this.setOpen}}\n @placement={{if @placement @placement \"right-start\"}}\n @flipOptions={{@flipOptions}}\n @middleware={{@middleware}}\n @shiftOptions={{@shiftOptions}}\n @offsetOptions={{@offsetOptions}}\n @strategy={{@strategy}}\n as |p|\n >\n {{yield\n (hash\n Trigger=(component\n SubTrigger\n item=@item\n anchor=p.anchor\n onTriggerClick=this.onTriggerClick\n isOpen=this.isOpen\n submenuId=this.submenuId\n key=this.triggerKey\n hoverTrigger=this.hoverTrigger\n )\n Menu=(component\n @menu\n Content=p.Content\n context=this.childContext\n depth=this.depth\n menuId=this.submenuId\n openSource=this.openSource\n close=this.close\n )\n isOpen=this.isOpen\n )\n }}\n </Popover>\n </template>\n}\n\ninterface SubTriggerArgs {\n /**\n * @internal\n */\n item: WithBoundArgs<typeof ListboxItem, 'manager'>;\n\n /**\n * @internal\n */\n anchor: ModifierLike<{ Element: HTMLElement }>;\n\n /**\n * @internal\n */\n onTriggerClick: () => void;\n\n /**\n * @internal\n */\n isOpen: boolean;\n\n /**\n * @internal\n */\n submenuId: string;\n\n /**\n * The key this row registers under. Generated by `Sub` when omitted; accept\n * an override so a test or a consumer can address the row by `data-key`.\n */\n key?: string;\n\n /**\n * @internal\n */\n hoverTrigger: ModifierLike<{ Element: HTMLElement }>;\n}\n\nexport interface SubTriggerSignature {\n Args: SubTriggerArgs;\n Element: HTMLLIElement;\n Blocks: { default: [] };\n}\n\n/**\n * The row that opens a submenu.\n *\n * It renders the parent level's own bound `item`, so it registers with that\n * level's `ListManager` and takes part in arrow navigation, type-ahead and the\n * roving tab stop exactly like any other row -- while `@hasSubmenu` keeps it\n * from ever selecting.\n */\nclass SubTrigger extends Component<SubTriggerSignature> {\n /**\n * `Sub` always binds a generated `key` by default (see `Sub`'s\n * `Trigger=(component SubTrigger ... key=this.triggerKey)`), so this is\n * never actually missing -- but `@key` on `SubTriggerArgs` stays optional so\n * a consumer-supplied override can win, and `ListboxItem.key` needs a plain\n * `string`, not `string | undefined`.\n */\n get key(): string {\n assert(\n `Sub's item did not receive a @key -- Sub always binds a generated key by default`,\n this.args.key\n );\n\n return this.args.key;\n }\n\n <template>\n <@item\n @key={{this.key}}\n @hasSubmenu={{true}}\n @isSubmenuOpen={{@isOpen}}\n @submenuId={{@submenuId}}\n @onClick={{@onTriggerClick}}\n {{@anchor}}\n {{@hoverTrigger}}\n data-test-id=\"dropdown-submenu-trigger\"\n ...attributes\n >\n {{yield}}\n </@item>\n </template>\n}\n\nexport { Sub, SubTrigger };\n"],"names":["SUBMENU_OPEN_DELAY","SUBMENU_CLOSE_DELAY","Sub","Component","triggerKey","guidFor","submenuId","Map","g","prototype","tracked","i","openSource","constructor","owner","args","parentContext","registerSub","handle","willDestroy","unregisterSub","stopTracking","cancel","cancelClose","open","source","close","isPointSafe","point","closeSiblings","isOpen","startTracking","key","subs","isDestroyed","isDestroying","trackPointer","event","document","getElementById","x","clientX","y","clientY","scheduleClose","submenu","trigger","getBoundingClientRect","content","isPointInSafeArea","values","addEventListener","removeEventListener","scheduleOpen","later","undefined","hoverTrigger","modifier","el","onTriggerClick","setOpen","childContext","createChildMenuContext","closeSelf","depth","setComponentTemplate","precompileTemplate","strictMode","scope","Popover","hash","SubTrigger","assert"],"mappings":";;;;;;;;;;;;;;AA2BA,MAAMA,kBAAA,GAAqB,GAAA;AAE3B;;;;AAIC;AACD,MAAMC,mBAAA,GAAsB,GAAA;AAE5B;;;;;;;;;;;;;;AAcC;AAGD;;;;;AAKC;;AAgED,MAAMC,YAAYC,SAAA,CAAU;AAC1B;;;;;;AAMC;AACDC,EAAAA,aAAa,CAAA,EAAGC,OAAA,CAAQ,IAAI,CAAA,CAAA,YAAA,CAAe;AAE3C;AACAC,EAAAA,YAAY,CAAA,EAAGD,OAAA,CAAQ,IAAI,CAAA,CAAA,QAAA,CAAW;AAEtC;;;;AAIC;AACD,EAAA,UAAU,GAAG,IAAIE,GAAA,EAAY;AAE7B;;;;;;;AAOC;AAPD,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAQCC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAiB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,OAAA,IAAAC,2BA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C/C,IAAI,CAACC,aAAa,EAAE;MACrD+C,SAAA,EAAW,IAAI,CAACrC,KAAK;MACrBO,IAAA,EAAM,IAAI,CAAC;AACb,KAAA,CAAA;AACF,EAAA;EAEA,IAAI+B,KAAAA,GAAgB;IAClB,OAAO,IAAI,CAACjD,IAAI,CAACC,aAAa,CAACgD,KAAK,GAAG,CAAA;AACzC,EAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,0pBAAA,EAqCA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,OAAA;QAAAC,IAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;AA8CA;;;;;;;;AAQA,MAAMA,mBAAmBpE,SAAA,CAAU;AACjC;;;;;;;EAOA,IAAI6B,GAAAA,GAAc;IAChBwC,MAAA,CACE,kFAAkF,EAClF,IAAI,CAACzD,IAAI,CAACiB,GAAG,CAAA;AAGf,IAAA,OAAO,IAAI,CAACjB,IAAI,CAACiB,GAAG;AACtB,EAAA;AAEA,EAAA;IAAAiC,oBAAA,CAAAC,kBAAA,CAAA,+OAAA,EAcA;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { isSegment, displaySegment, resolveTwoDigitYear, withValue } from './segments.js';
|
|
2
|
+
|
|
3
|
+
const ISO_DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
4
|
+
|
|
5
|
+
/** The digits destined for each segment, keyed by type. */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Writes digit strings onto the segments they name.
|
|
9
|
+
*
|
|
10
|
+
* Digits stay *strings* all the way in, because a year's leading zeros carry
|
|
11
|
+
* meaning: `0045` is the year 45, while `45` runs through the sliding window.
|
|
12
|
+
* Passing numbers here would erase that distinction and make a pasted `0045`
|
|
13
|
+
* resolve differently from a typed one.
|
|
14
|
+
*
|
|
15
|
+
* A segment no key names is left untouched, which is what lets a partial paste
|
|
16
|
+
* fill what it can. Out of bounds refuses the *whole* paste rather than
|
|
17
|
+
* clamping: clamping would turn a paste of `99/99/2026` into a plausible
|
|
18
|
+
* looking date the user never meant. The day is the exception by design -- its
|
|
19
|
+
* bound is 31 and the real length of the month is applied later, by `toDate`,
|
|
20
|
+
* so a pasted 31st of February shortens to the 28th exactly as a typed one
|
|
21
|
+
* does.
|
|
22
|
+
*/
|
|
23
|
+
function fill(parts, digits) {
|
|
24
|
+
let filled = 0;
|
|
25
|
+
const next = [];
|
|
26
|
+
for (const part of parts) {
|
|
27
|
+
if (!isSegment(part)) {
|
|
28
|
+
next.push(part);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const raw = digits[part.type];
|
|
32
|
+
if (raw === undefined) {
|
|
33
|
+
next.push(part);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const value = part.type === 'year' ? resolveTwoDigitYear(raw) : Number(raw);
|
|
37
|
+
if (Number.isNaN(value) || value < part.min || value > part.max) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
filled++;
|
|
41
|
+
// A paste is a finished answer for every segment it fills.
|
|
42
|
+
next.push(withValue(part, value));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Nothing landed anywhere -- treat that as a refusal rather than quietly
|
|
46
|
+
// handing back an untouched field.
|
|
47
|
+
return filled === 0 ? null : next;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Maps digit groups onto the segments in their rendered order. */
|
|
51
|
+
function byPosition(segments, groups) {
|
|
52
|
+
if (groups.length === 0 || groups.length > segments.length) return null;
|
|
53
|
+
const digits = {};
|
|
54
|
+
groups.forEach((group, i) => {
|
|
55
|
+
const segment = segments[i];
|
|
56
|
+
if (segment) digits[segment.type] = group;
|
|
57
|
+
});
|
|
58
|
+
return digits;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Reads pasted text into the segments, trying each strategy in turn and
|
|
63
|
+
* stopping at the first that works.
|
|
64
|
+
*
|
|
65
|
+
* Every strategy lands in `fill`, so all three share one bounds policy. There
|
|
66
|
+
* is deliberately no `new Date(text)` fallback: it parses differently in every
|
|
67
|
+
* engine, and a date field that silently guesses wrong is worse than one that
|
|
68
|
+
* declines.
|
|
69
|
+
*/
|
|
70
|
+
function parsePasted(text, parts) {
|
|
71
|
+
const trimmed = text.trim();
|
|
72
|
+
if (trimmed === '') return null;
|
|
73
|
+
|
|
74
|
+
// 1. ISO, which is unambiguous and so outranks the locale's own order.
|
|
75
|
+
const iso = ISO_DAY.exec(trimmed);
|
|
76
|
+
if (iso) {
|
|
77
|
+
const [, year, month, day] = iso;
|
|
78
|
+
return fill(parts, {
|
|
79
|
+
year,
|
|
80
|
+
month,
|
|
81
|
+
day
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const segments = parts.filter(isSegment);
|
|
85
|
+
|
|
86
|
+
// 2. A bare digit run, split by each segment's width. Checked before the
|
|
87
|
+
// separated form, because an unseparated run also splits into a single
|
|
88
|
+
// "group" and would otherwise be read as one enormous month.
|
|
89
|
+
if (/^\d+$/.test(trimmed)) {
|
|
90
|
+
const widths = [];
|
|
91
|
+
let at = 0;
|
|
92
|
+
for (const segment of segments) {
|
|
93
|
+
if (at >= trimmed.length) break;
|
|
94
|
+
widths.push(trimmed.slice(at, at + segment.width));
|
|
95
|
+
at += segment.width;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// It has to end on a segment boundary, otherwise there is no telling
|
|
99
|
+
// where the last number was meant to stop.
|
|
100
|
+
if (at !== trimmed.length) return null;
|
|
101
|
+
const digits = byPosition(segments, widths);
|
|
102
|
+
return digits ? fill(parts, digits) : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 3. Separated numbers, mapped positionally onto the locale's order. Fewer
|
|
106
|
+
// groups than segments is a partial date and fills a prefix of them.
|
|
107
|
+
const groups = trimmed.split(/\D+/).filter(Boolean);
|
|
108
|
+
const digits = byPosition(segments, groups);
|
|
109
|
+
if (digits) return fill(parts, digits);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The field as it reads on screen, literals included. Copying the display
|
|
115
|
+
* rather than an ISO string means the text round-trips through `parsePasted`
|
|
116
|
+
* and still reads naturally when pasted into a document.
|
|
117
|
+
*
|
|
118
|
+
* Delegates each segment to `displaySegment`, the same function the group
|
|
119
|
+
* renders from, so a mid-entry year (buffer `26`, uncommitted) copies as
|
|
120
|
+
* `26` rather than being padded to `0026` -- padding would claim digits the
|
|
121
|
+
* user never typed and would contradict what is on screen.
|
|
122
|
+
*/
|
|
123
|
+
function formatForClipboard(parts) {
|
|
124
|
+
return parts.map(part => isSegment(part) ? displaySegment(part) : part.text).join('');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* What separates the two halves of a pasted range.
|
|
129
|
+
*
|
|
130
|
+
* An en or em dash needs no surrounding space, because neither ever appears
|
|
131
|
+
* inside a date. A plain hyphen does: it is the ISO separator, so splitting on
|
|
132
|
+
* an unspaced one would tear `2026-01-20` into pieces. The same reasoning
|
|
133
|
+
* applies to the words -- `\s+` on both sides keeps "to" from matching inside
|
|
134
|
+
* "total".
|
|
135
|
+
*/
|
|
136
|
+
const RANGE_SEPARATOR = /\s*[\u2013\u2014]\s*|\s+(?:-|to|until|through)\s+/i;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Splits pasted text into the two dates of a range, or returns `null` when it
|
|
140
|
+
* does not read as two.
|
|
141
|
+
*
|
|
142
|
+
* Only the shape is decided here; neither half is parsed. The caller runs each
|
|
143
|
+
* through {@link parsePasted} and keeps the result only when both halves are
|
|
144
|
+
* dates -- so text that merely contains a dash falls through to the ordinary
|
|
145
|
+
* single-date handling rather than being consumed.
|
|
146
|
+
*/
|
|
147
|
+
function splitRange(text) {
|
|
148
|
+
const trimmed = text.trim();
|
|
149
|
+
const match = RANGE_SEPARATOR.exec(trimmed);
|
|
150
|
+
if (!match) return null;
|
|
151
|
+
const start = trimmed.slice(0, match.index).trim();
|
|
152
|
+
const end = trimmed.slice(match.index + match[0].length).trim();
|
|
153
|
+
if (start === '' || end === '') return null;
|
|
154
|
+
|
|
155
|
+
// Three halves is not a range, and guessing which two were meant would be
|
|
156
|
+
// exactly the silent wrong guess this module declines to make elsewhere.
|
|
157
|
+
if (RANGE_SEPARATOR.test(end)) return null;
|
|
158
|
+
return [start, end];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { formatForClipboard, parsePasted, splitRange };
|
|
162
|
+
//# sourceMappingURL=clipboard.js.map
|