@plexui/vue 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/DateInput/DateInput.js +43 -25
- package/dist/es/components/DateInput/DateInput.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +129 -10
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Sidebar/useSidebarContext.js +21 -18
- package/dist/es/components/Sidebar/useSidebarContext.js.map +1 -1
- package/dist/es/lib/dateInputText.js +201 -0
- package/dist/es/lib/dateInputText.js.map +1 -0
- package/dist/es/lib/phoneDrawer.js +234 -0
- package/dist/es/lib/phoneDrawer.js.map +1 -0
- package/dist/types/components/Sidebar/Sidebar.d.ts +16 -2
- package/dist/types/components/Sidebar/useSidebarContext.d.ts +25 -0
- package/dist/types/lib/dateInputText.d.ts +54 -0
- package/dist/types/lib/phoneDrawer.d.ts +51 -0
- package/package.json +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { maskitoDateOptionsGenerator, maskitoDateTimeOptionsGenerator,
|
|
1
|
+
import { maskitoDateOptionsGenerator, maskitoDateTimeOptionsGenerator, } from "@maskito/kit";
|
|
2
2
|
import { maskito as vMaskito } from "@maskito/vue";
|
|
3
3
|
import { DateTime } from "luxon";
|
|
4
4
|
import { computed, defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref, watch, withDirectives, } from "vue";
|
|
5
|
+
import { dateInputValueKey, dateInputZone, formatDateInput, keepTypedValue, maskDate, parseDateInput, } from "../../lib/dateInputText.js";
|
|
5
6
|
import { Input } from "../Input/index.js";
|
|
6
7
|
// Vue port of packages/ui/src/components/DateInput/DateInput.tsx: an Input
|
|
7
8
|
// with a Maskito date (or date + time) mask, same options as React.
|
|
@@ -22,6 +23,9 @@ import { Input } from "../Input/index.js";
|
|
|
22
23
|
// read the same way here, from the event bubbling through Input's container.
|
|
23
24
|
// Input's `update:value` only keeps its controlled value in step, so Input
|
|
24
25
|
// does not put the previous text back.
|
|
26
|
+
// - The text is made from the value's own fields in its own zone and read
|
|
27
|
+
// back into that zone (lib/dateInputText, shared with React), never through
|
|
28
|
+
// the browser's local Date.
|
|
25
29
|
const DateInputComponent = defineComponent({
|
|
26
30
|
name: "DateInput",
|
|
27
31
|
inheritAttrs: false,
|
|
@@ -53,14 +57,24 @@ const DateInputComponent = defineComponent({
|
|
|
53
57
|
},
|
|
54
58
|
setup(props, { attrs, slots, emit, expose }) {
|
|
55
59
|
const hasTime = computed(() => !!props.timeMode);
|
|
56
|
-
// React memoizes on the dates' milliseconds, not on the DateTime objects
|
|
60
|
+
// React memoizes on the dates' milliseconds and the value's zone, not on the DateTime objects
|
|
61
|
+
const zone = computed(() => dateInputZone(props.value));
|
|
57
62
|
const minMs = computed(() => props.min?.toMillis());
|
|
58
63
|
const maxMs = computed(() => props.max?.toMillis());
|
|
64
|
+
const textFormat = computed(() => ({
|
|
65
|
+
mode: props.mode,
|
|
66
|
+
separator: props.separator,
|
|
67
|
+
timeMode: props.timeMode,
|
|
68
|
+
dateTimeSeparator: props.dateTimeSeparator,
|
|
69
|
+
min: minMs.value,
|
|
70
|
+
max: maxMs.value,
|
|
71
|
+
zone: zone.value,
|
|
72
|
+
}));
|
|
59
73
|
const dateParams = computed(() => ({
|
|
60
74
|
mode: props.mode,
|
|
61
75
|
separator: props.separator,
|
|
62
|
-
...(minMs.value !== undefined ? { min:
|
|
63
|
-
...(maxMs.value !== undefined ? { max:
|
|
76
|
+
...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),
|
|
77
|
+
...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),
|
|
64
78
|
}));
|
|
65
79
|
const dateTimeParams = computed(() => ({
|
|
66
80
|
dateMode: props.mode,
|
|
@@ -68,32 +82,36 @@ const DateInputComponent = defineComponent({
|
|
|
68
82
|
timeMode: props.timeMode ?? "HH:MM",
|
|
69
83
|
dateTimeSeparator: props.dateTimeSeparator,
|
|
70
84
|
...(props.timeStep ? { timeStep: props.timeStep } : undefined),
|
|
71
|
-
...(minMs.value !== undefined ? { min:
|
|
72
|
-
...(maxMs.value !== undefined ? { max:
|
|
85
|
+
...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),
|
|
86
|
+
...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),
|
|
73
87
|
}));
|
|
74
|
-
// Like React's memo, new options whenever either set of params changes
|
|
88
|
+
// Like React's memo, new options whenever either set of params changes. The mask shows a complete text as the
|
|
89
|
+
// value reads it (lib/dateInputText)
|
|
75
90
|
const maskOptions = computed(() => {
|
|
76
91
|
const date = dateParams.value;
|
|
77
92
|
const dateTime = dateTimeParams.value;
|
|
78
|
-
|
|
93
|
+
const format = textFormat.value;
|
|
94
|
+
return keepTypedValue(hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date), format);
|
|
79
95
|
});
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
const format = (date) => formatDateInput(date, textFormat.value);
|
|
97
|
+
const parse = (str) => parseDateInput(str, textFormat.value);
|
|
98
|
+
// The first render, on the server too, already shows the value. A new
|
|
99
|
+
// value or format shows it again before the next render, as React does
|
|
100
|
+
// during its render
|
|
101
|
+
const inputValue = ref(format(props.value));
|
|
102
|
+
const syncKey = computed(() => [
|
|
103
|
+
dateInputValueKey(props.value),
|
|
104
|
+
props.mode,
|
|
105
|
+
props.separator,
|
|
106
|
+
props.timeMode,
|
|
107
|
+
props.dateTimeSeparator,
|
|
108
|
+
props.timeStep,
|
|
109
|
+
minMs.value,
|
|
110
|
+
maxMs.value,
|
|
111
|
+
].join("|"));
|
|
112
|
+
watch(syncKey, () => {
|
|
92
113
|
inputValue.value = format(props.value);
|
|
93
|
-
};
|
|
94
|
-
const valueMsKey = computed(() => props.value?.toMillis() ?? null);
|
|
95
|
-
watch([valueMsKey, hasTime, dateParams, dateTimeParams], syncInputValue);
|
|
96
|
-
onMounted(syncInputValue);
|
|
114
|
+
});
|
|
97
115
|
const change = (value) => {
|
|
98
116
|
emit("update:value", value);
|
|
99
117
|
emit("change", value);
|
|
@@ -111,7 +129,7 @@ const DateInputComponent = defineComponent({
|
|
|
111
129
|
}
|
|
112
130
|
const parsed = parse(str);
|
|
113
131
|
if (parsed) {
|
|
114
|
-
change(
|
|
132
|
+
change(parsed);
|
|
115
133
|
}
|
|
116
134
|
};
|
|
117
135
|
// Text that is not a complete date never reaches `change`, so leaving the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../../../src/components/DateInput/DateInput.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,GAKzB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EACL,QAAQ,EACR,eAAe,EACf,CAAC,EACD,UAAU,EACV,eAAe,EACf,SAAS,EACT,GAAG,EACH,KAAK,EACL,cAAc,GAEf,MAAM,KAAK,CAAA;AACZ,OAAO,EAAE,KAAK,EAAmB,MAAM,mBAAmB,CAAA;AAE1D,2EAA2E;AAC3E,oEAAoE;AACpE,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,+EAA+E;AAC/E,2EAA2E;AAC3E,oDAAoD;AACpD,+DAA+D;AAC/D,0EAA0E;AAC1E,2EAA2E;AAC3E,qCAAqC;AACrC,6EAA6E;AAC7E,gDAAgD;AAChD,6EAA6E;AAC7E,8EAA8E;AAC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,\n maskitoDateTimeOptionsGenerator,\n maskitoParseDate,\n maskitoParseDateTime,\n maskitoStringifyDate,\n maskitoStringifyDateTime,\n type MaskitoDateMode,\n type MaskitoDateParams,\n type MaskitoDateTimeParams,\n type MaskitoTimeMode,\n} from \"@maskito/kit\"\nimport { maskito as vMaskito } from \"@maskito/vue\"\nimport { DateTime } from \"luxon\"\nimport {\n computed,\n defineComponent,\n h,\n mergeProps,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n withDirectives,\n type PropType,\n} from \"vue\"\nimport { Input, type InputProps } from \"../Input/index.js\"\n\n// Vue port of packages/ui/src/components/DateInput/DateInput.tsx: an Input\n// with a Maskito date (or date + time) mask, same options as React.\n//\n// - `value` + `update:value` (`v-model:value`) and `change` mirror React's\n// `value` + `onChange`: both fire with a Luxon DateTime once a complete\n// valid date is typed, and with `null` when the field is emptied or cleared.\n// What is typed in between stays in the field without an event until the\n// field loses focus, which shows the value again.\n// - Every other attribute, listener and the `startAdornment` /\n// `endAdornment` slots go to Input, like React's `...inputProps`. React\n// sets `onInput` and `onClear` itself, so `@input` and `@clear` given to\n// DateInput are dropped, as there.\n// - The mask is `@maskito/vue`'s directive on Input's container; its default\n// element predicate picks the <input> inside.\n// - React reads the typed text in a listener React delegates to the root, so\n// it runs after Maskito's own `input` listeners on the <input>. The text is\n// read the same way here, from the event bubbling through Input's container.\n// Input's `update:value` only keeps its controlled value in step, so Input\n// does not put the previous text back.\n\nconst DateInputComponent = defineComponent({\n name: \"DateInput\",\n inheritAttrs: false,\n props: {\n /** Selected date (Luxon DateTime). Bind `v-model:value`. */\n value: { type: [Object, null] as PropType<DateTime | null>, required: true as const },\n /** Date format: `dd/mm/yyyy`, `mm/dd/yyyy`, `yyyy/mm/dd`, ... @default \"dd/mm/yyyy\" */\n mode: { type: String as PropType<MaskitoDateMode>, default: \"dd/mm/yyyy\" },\n /** Character between date parts. @default \".\" */\n separator: { type: String, default: \".\" },\n /** Enables time input: `HH:MM`, `HH:MM:SS`, ... */\n timeMode: String as PropType<MaskitoTimeMode>,\n /** Separator between the date and time parts. @default \", \" */\n dateTimeSeparator: { type: String, default: \", \" },\n /** Arrow-key increment step for time segments. @default 0 */\n timeStep: { type: Number, default: 0 },\n /** Earliest allowed date */\n min: Object as PropType<DateTime>,\n /** Latest allowed date */\n max: Object as PropType<DateTime>,\n /** Shows the clear button while the input has a value. @default false */\n clearable: { type: Boolean, default: false },\n /** Generated from the format when not set */\n placeholder: String,\n },\n emits: {\n \"update:value\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n \"change\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n },\n setup(props, { attrs, slots, emit, expose }) {\n const hasTime = computed(() => !!props.timeMode)\n // React memoizes on the dates' milliseconds, not on the DateTime objects\n const minMs = computed(() => props.min?.toMillis())\n const maxMs = computed(() => props.max?.toMillis())\n\n const dateParams = computed<MaskitoDateParams>(() => ({\n mode: props.mode,\n separator: props.separator,\n ...(minMs.value !== undefined ? { min: new Date(minMs.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: new Date(maxMs.value) } : undefined),\n }))\n\n const dateTimeParams = computed<MaskitoDateTimeParams>(() => ({\n dateMode: props.mode,\n dateSeparator: props.separator,\n timeMode: props.timeMode ?? \"HH:MM\",\n dateTimeSeparator: props.dateTimeSeparator,\n ...(props.timeStep ? { timeStep: props.timeStep } : undefined),\n ...(minMs.value !== undefined ? { min: new Date(minMs.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: new Date(maxMs.value) } : undefined),\n }))\n\n // Like React's memo, new options whenever either set of params changes\n const maskOptions = computed(() => {\n const date = dateParams.value\n const dateTime = dateTimeParams.value\n return hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date)\n })\n\n const inputValue = ref(\"\")\n\n const format = (date: DateTime | null) => {\n if (!date) return \"\"\n return hasTime.value\n ? maskitoStringifyDateTime(date.toJSDate(), dateTimeParams.value)\n : maskitoStringifyDate(date.toJSDate(), dateParams.value)\n }\n\n const parse = (str: string) =>\n hasTime.value ? maskitoParseDateTime(str, dateTimeParams.value) : maskitoParseDate(str, dateParams.value)\n\n // React formats the value in an effect: the first render (and the server\n // markup) has an empty field, without the clear button\n const syncInputValue = () => {\n inputValue.value = format(props.value)\n }\n const valueMsKey = computed(() => props.value?.toMillis() ?? null)\n watch([valueMsKey, hasTime, dateParams, dateTimeParams], syncInputValue)\n onMounted(syncInputValue)\n\n const change = (value: DateTime | null) => {\n emit(\"update:value\", value)\n emit(\"change\", value)\n }\n\n const inputComponent = ref<{ $el: HTMLElement; input: HTMLInputElement | null; focus: () => void } | null>(null)\n\n const handleInput = (evt: Event) => {\n const input = inputComponent.value?.input\n if (!input || evt.target !== input) return\n const str = input.value\n inputValue.value = str\n\n if (!str) {\n change(null)\n return\n }\n\n const parsed = parse(str)\n\n if (parsed) {\n change(DateTime.fromJSDate(parsed))\n }\n }\n\n // Text that is not a complete date never reaches `change`, so leaving the\n // field shows the value again instead of a date the value does not hold\n const handleBlur = () => {\n if (inputValue.value && !parse(inputValue.value)) {\n inputValue.value = format(props.value)\n }\n }\n\n const handleClear = () => {\n inputValue.value = \"\"\n change(null)\n }\n\n let container: HTMLElement | null = null\n onMounted(() => {\n container = inputComponent.value?.$el ?? null\n container?.addEventListener(\"input\", handleInput)\n })\n onBeforeUnmount(() => {\n container?.removeEventListener(\"input\", handleInput)\n container = null\n })\n\n const defaultPlaceholder = computed(() => {\n const datePart = props.mode.replace(/\\//g, props.separator).toUpperCase()\n if (!hasTime.value) return datePart\n return `${datePart}${props.dateTimeSeparator}${props.timeMode}`\n })\n\n expose({\n focus: () => inputComponent.value?.focus(),\n input: computed(() => inputComponent.value?.input ?? null),\n })\n\n return () => {\n const { inputMode, inputmode, ...inputProps } = attrs\n delete inputProps.onInput\n delete inputProps.onClear\n return withDirectives(\n h(\n Input,\n // mergeProps keeps the caller's `@blur` and runs it first, as React does\n mergeProps(inputProps, {\n // Accept both native and JSX spelling, without duplicate DOM attributes.\n \"inputmode\": inputMode ?? inputmode ?? (props.timeMode?.includes(\"AA\") ? \"text\" : \"numeric\"),\n \"ref\": inputComponent,\n \"value\": inputValue.value,\n \"onUpdate:value\": (str: string) => {\n inputValue.value = str\n },\n \"onBlur\": handleBlur,\n \"placeholder\": props.placeholder ?? defaultPlaceholder.value,\n \"onClear\": props.clearable ? handleClear : undefined,\n }),\n {\n ...(slots.startAdornment ? { startAdornment: slots.startAdornment } : {}),\n ...(slots.endAdornment ? { endAdornment: slots.endAdornment } : {}),\n },\n ),\n [[vMaskito, maskOptions.value]],\n )\n }\n },\n})\n\ntype DateInputOwnProps = InstanceType<typeof DateInputComponent>[\"$props\"]\n\n/** DateInput props plus the Input props and attributes that fall through to it. */\nexport type DateInputProps = DateInputOwnProps &\n Omit<InputProps, keyof DateInputOwnProps | \"defaultValue\" | \"onUpdate:value\" | \"onInput\" | \"onClear\" | \"type\">\n\n/** Masked text input for typing dates (Luxon DateTime values). */\nexport const DateInput = DateInputComponent as typeof DateInputComponent & { new (): { $props: DateInputProps } }\n"]}
|
|
1
|
+
{"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../../../src/components/DateInput/DateInput.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAKhC,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EACL,QAAQ,EACR,eAAe,EACf,CAAC,EACD,UAAU,EACV,eAAe,EACf,SAAS,EACT,GAAG,EACH,KAAK,EACL,cAAc,GAEf,MAAM,KAAK,CAAA;AACZ,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,QAAQ,EACR,cAAc,GAEf,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,KAAK,EAAmB,MAAM,mBAAmB,CAAA;AAE1D,2EAA2E;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AE,UAAU;gBACpB,aAAa,EAAE,KAAK,CAAC,WAAW,IAAI,kBAAkB,CAAC,KAAK;gBAC5D,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;aACrD,CAAC,EACF;gBACE,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzE,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpE,CACF,EACD,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAChC,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAQF,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAwF,CAAA","sourcesContent":["import {\n maskitoDateOptionsGenerator,\n maskitoDateTimeOptionsGenerator,\n type MaskitoDateMode,\n type MaskitoDateParams,\n type MaskitoDateTimeParams,\n type MaskitoTimeMode,\n} from \"@maskito/kit\"\nimport { maskito as vMaskito } from \"@maskito/vue\"\nimport { DateTime } from \"luxon\"\nimport {\n computed,\n defineComponent,\n h,\n mergeProps,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n withDirectives,\n type PropType,\n} from \"vue\"\nimport {\n dateInputValueKey,\n dateInputZone,\n formatDateInput,\n keepTypedValue,\n maskDate,\n parseDateInput,\n type DateInputFormat,\n} from \"../../lib/dateInputText.js\"\nimport { Input, type InputProps } from \"../Input/index.js\"\n\n// Vue port of packages/ui/src/components/DateInput/DateInput.tsx: an Input\n// with a Maskito date (or date + time) mask, same options as React.\n//\n// - `value` + `update:value` (`v-model:value`) and `change` mirror React's\n// `value` + `onChange`: both fire with a Luxon DateTime once a complete\n// valid date is typed, and with `null` when the field is emptied or cleared.\n// What is typed in between stays in the field without an event until the\n// field loses focus, which shows the value again.\n// - Every other attribute, listener and the `startAdornment` /\n// `endAdornment` slots go to Input, like React's `...inputProps`. React\n// sets `onInput` and `onClear` itself, so `@input` and `@clear` given to\n// DateInput are dropped, as there.\n// - The mask is `@maskito/vue`'s directive on Input's container; its default\n// element predicate picks the <input> inside.\n// - React reads the typed text in a listener React delegates to the root, so\n// it runs after Maskito's own `input` listeners on the <input>. The text is\n// read the same way here, from the event bubbling through Input's container.\n// Input's `update:value` only keeps its controlled value in step, so Input\n// does not put the previous text back.\n// - The text is made from the value's own fields in its own zone and read\n// back into that zone (lib/dateInputText, shared with React), never through\n// the browser's local Date.\n\nconst DateInputComponent = defineComponent({\n name: \"DateInput\",\n inheritAttrs: false,\n props: {\n /** Selected date (Luxon DateTime). Bind `v-model:value`. */\n value: { type: [Object, null] as PropType<DateTime | null>, required: true as const },\n /** Date format: `dd/mm/yyyy`, `mm/dd/yyyy`, `yyyy/mm/dd`, ... @default \"dd/mm/yyyy\" */\n mode: { type: String as PropType<MaskitoDateMode>, default: \"dd/mm/yyyy\" },\n /** Character between date parts. @default \".\" */\n separator: { type: String, default: \".\" },\n /** Enables time input: `HH:MM`, `HH:MM:SS`, ... */\n timeMode: String as PropType<MaskitoTimeMode>,\n /** Separator between the date and time parts. @default \", \" */\n dateTimeSeparator: { type: String, default: \", \" },\n /** Arrow-key increment step for time segments. @default 0 */\n timeStep: { type: Number, default: 0 },\n /** Earliest allowed date */\n min: Object as PropType<DateTime>,\n /** Latest allowed date */\n max: Object as PropType<DateTime>,\n /** Shows the clear button while the input has a value. @default false */\n clearable: { type: Boolean, default: false },\n /** Generated from the format when not set */\n placeholder: String,\n },\n emits: {\n \"update:value\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n \"change\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n },\n setup(props, { attrs, slots, emit, expose }) {\n const hasTime = computed(() => !!props.timeMode)\n // React memoizes on the dates' milliseconds and the value's zone, not on the DateTime objects\n const zone = computed(() => dateInputZone(props.value))\n const minMs = computed(() => props.min?.toMillis())\n const maxMs = computed(() => props.max?.toMillis())\n\n const textFormat = computed<DateInputFormat>(() => ({\n mode: props.mode,\n separator: props.separator,\n timeMode: props.timeMode,\n dateTimeSeparator: props.dateTimeSeparator,\n min: minMs.value,\n max: maxMs.value,\n zone: zone.value,\n }))\n\n const dateParams = computed<MaskitoDateParams>(() => ({\n mode: props.mode,\n separator: props.separator,\n ...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),\n }))\n\n const dateTimeParams = computed<MaskitoDateTimeParams>(() => ({\n dateMode: props.mode,\n dateSeparator: props.separator,\n timeMode: props.timeMode ?? \"HH:MM\",\n dateTimeSeparator: props.dateTimeSeparator,\n ...(props.timeStep ? { timeStep: props.timeStep } : undefined),\n ...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),\n }))\n\n // Like React's memo, new options whenever either set of params changes. The mask shows a complete text as the\n // value reads it (lib/dateInputText)\n const maskOptions = computed(() => {\n const date = dateParams.value\n const dateTime = dateTimeParams.value\n const format = textFormat.value\n return keepTypedValue(\n hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date),\n format,\n )\n })\n\n const format = (date: DateTime | null) => formatDateInput(date, textFormat.value)\n const parse = (str: string) => parseDateInput(str, textFormat.value)\n\n // The first render, on the server too, already shows the value. A new\n // value or format shows it again before the next render, as React does\n // during its render\n const inputValue = ref(format(props.value))\n const syncKey = computed(() =>\n [\n dateInputValueKey(props.value),\n props.mode,\n props.separator,\n props.timeMode,\n props.dateTimeSeparator,\n props.timeStep,\n minMs.value,\n maxMs.value,\n ].join(\"|\"),\n )\n watch(syncKey, () => {\n inputValue.value = format(props.value)\n })\n\n const change = (value: DateTime | null) => {\n emit(\"update:value\", value)\n emit(\"change\", value)\n }\n\n const inputComponent = ref<{ $el: HTMLElement; input: HTMLInputElement | null; focus: () => void } | null>(null)\n\n const handleInput = (evt: Event) => {\n const input = inputComponent.value?.input\n if (!input || evt.target !== input) return\n const str = input.value\n inputValue.value = str\n\n if (!str) {\n change(null)\n return\n }\n\n const parsed = parse(str)\n\n if (parsed) {\n change(parsed)\n }\n }\n\n // Text that is not a complete date never reaches `change`, so leaving the\n // field shows the value again instead of a date the value does not hold\n const handleBlur = () => {\n if (inputValue.value && !parse(inputValue.value)) {\n inputValue.value = format(props.value)\n }\n }\n\n const handleClear = () => {\n inputValue.value = \"\"\n change(null)\n }\n\n let container: HTMLElement | null = null\n onMounted(() => {\n container = inputComponent.value?.$el ?? null\n container?.addEventListener(\"input\", handleInput)\n })\n onBeforeUnmount(() => {\n container?.removeEventListener(\"input\", handleInput)\n container = null\n })\n\n const defaultPlaceholder = computed(() => {\n const datePart = props.mode.replace(/\\//g, props.separator).toUpperCase()\n if (!hasTime.value) return datePart\n return `${datePart}${props.dateTimeSeparator}${props.timeMode}`\n })\n\n expose({\n focus: () => inputComponent.value?.focus(),\n input: computed(() => inputComponent.value?.input ?? null),\n })\n\n return () => {\n const { inputMode, inputmode, ...inputProps } = attrs\n delete inputProps.onInput\n delete inputProps.onClear\n return withDirectives(\n h(\n Input,\n // mergeProps keeps the caller's `@blur` and runs it first, as React does\n mergeProps(inputProps, {\n // Accept both native and JSX spelling, without duplicate DOM attributes.\n \"inputmode\": inputMode ?? inputmode ?? (props.timeMode?.includes(\"AA\") ? \"text\" : \"numeric\"),\n \"ref\": inputComponent,\n \"value\": inputValue.value,\n \"onUpdate:value\": (str: string) => {\n inputValue.value = str\n },\n \"onBlur\": handleBlur,\n \"placeholder\": props.placeholder ?? defaultPlaceholder.value,\n \"onClear\": props.clearable ? handleClear : undefined,\n }),\n {\n ...(slots.startAdornment ? { startAdornment: slots.startAdornment } : {}),\n ...(slots.endAdornment ? { endAdornment: slots.endAdornment } : {}),\n },\n ),\n [[vMaskito, maskOptions.value]],\n )\n }\n },\n})\n\ntype DateInputOwnProps = InstanceType<typeof DateInputComponent>[\"$props\"]\n\n/** DateInput props plus the Input props and attributes that fall through to it. */\nexport type DateInputProps = DateInputOwnProps &\n Omit<InputProps, keyof DateInputOwnProps | \"defaultValue\" | \"onUpdate:value\" | \"onInput\" | \"onClear\" | \"type\">\n\n/** Masked text input for typing dates (Luxon DateTime values). */\nexport const DateInput = DateInputComponent as typeof DateInputComponent & { new (): { $props: DateInputProps } }\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { computed, defineComponent, Fragment, h, inject, onBeforeUnmount, onMounted, provide, ref, Text, } from "vue";
|
|
1
|
+
import { computed, defineComponent, Fragment, h, inject, onBeforeUnmount, onMounted, onUnmounted, provide, ref, Text, watch, } from "vue";
|
|
2
|
+
import { attachDrawerSwipe, closeOnUnhandledEscape, drawerInitialFocus, returnDrawerFocus, loopDrawerFocus, } from "../../lib/phoneDrawer.js";
|
|
2
3
|
import { Button } from "../Button/index.js";
|
|
3
4
|
import { ChevronRightMd, Disclosure, Search as SearchIcon, Sidebar as SidebarIcon, SidebarMenuMobile, X } from "../Icon/index.js";
|
|
4
5
|
import { Input } from "../Input/index.js";
|
|
@@ -216,8 +217,10 @@ export const SidebarMenuItem = SidebarMenuItemComponent;
|
|
|
216
217
|
// =============================================
|
|
217
218
|
// Shared by every row of the rail: moving to the next one shows its label at once.
|
|
218
219
|
let railLeftAt = 0;
|
|
219
|
-
// Rows inside the mobile drawer end with a disclosure chevron (see the drawer list in the styles)
|
|
220
|
+
// Rows inside the mobile drawer end with a disclosure chevron (see the drawer list in the styles), unless the drawer
|
|
221
|
+
// leaves it out (`:disclosure="false"`).
|
|
220
222
|
const sidebarDrawerKey = Symbol("SidebarDrawer");
|
|
223
|
+
const notInDrawer = computed(() => false);
|
|
221
224
|
/** The chevron of a drawer row that leads to another page. */
|
|
222
225
|
const menuDisclosure = () => h("span", { "class": s.MenuDisclosure, "aria-hidden": "true" }, [h(Disclosure)]);
|
|
223
226
|
const SidebarMenuButtonComponent = defineComponent({
|
|
@@ -236,7 +239,7 @@ const SidebarMenuButtonComponent = defineComponent({
|
|
|
236
239
|
},
|
|
237
240
|
setup(props, { attrs, slots }) {
|
|
238
241
|
const sidebar = useSidebar();
|
|
239
|
-
const
|
|
242
|
+
const drawerRows = inject(sidebarDrawerKey, notInDrawer);
|
|
240
243
|
const openDelay = ref();
|
|
241
244
|
return () => {
|
|
242
245
|
const { className, rest } = cleanAttrs(attrs);
|
|
@@ -256,7 +259,7 @@ const SidebarMenuButtonComponent = defineComponent({
|
|
|
256
259
|
});
|
|
257
260
|
}
|
|
258
261
|
const content = slots.default?.();
|
|
259
|
-
const wrap = (children) => h("span", { class: s.MenuButtonInner },
|
|
262
|
+
const wrap = (children) => h("span", { class: s.MenuButtonInner }, drawerRows.value ? [children, menuDisclosure()] : children);
|
|
260
263
|
let button;
|
|
261
264
|
if (props.asChild) {
|
|
262
265
|
// With asChild the child element is the button, so the inner wrapper
|
|
@@ -387,7 +390,7 @@ const SidebarMenuSubButtonComponent = defineComponent({
|
|
|
387
390
|
indent: { type: Number, default: 0 },
|
|
388
391
|
},
|
|
389
392
|
setup(props, { attrs, slots }) {
|
|
390
|
-
const
|
|
393
|
+
const drawerRows = inject(sidebarDrawerKey, notInDrawer);
|
|
391
394
|
return () => {
|
|
392
395
|
const { className, rest } = cleanAttrs(attrs);
|
|
393
396
|
const ownProps = {
|
|
@@ -397,7 +400,7 @@ const SidebarMenuSubButtonComponent = defineComponent({
|
|
|
397
400
|
...rest,
|
|
398
401
|
};
|
|
399
402
|
const content = slots.default?.();
|
|
400
|
-
if (!
|
|
403
|
+
if (!drawerRows.value)
|
|
401
404
|
return props.asChild ? renderAsChild(content, ownProps) : h("button", ownProps, content);
|
|
402
405
|
// In the drawer the disclosure follows the content, inside the child element with asChild
|
|
403
406
|
if (props.asChild) {
|
|
@@ -474,8 +477,21 @@ export const SidebarCardTitleLink = defineComponent({
|
|
|
474
477
|
});
|
|
475
478
|
export const SidebarCardContent = part("SidebarCardContent", "div", s.CardContent);
|
|
476
479
|
export const SidebarCardFooter = part("SidebarCardFooter", "div", s.CardFooter);
|
|
477
|
-
/**
|
|
478
|
-
|
|
480
|
+
/**
|
|
481
|
+
* Main content area next to the sidebar, a `<main>`. Behind the open phone drawer it takes no focus or touch
|
|
482
|
+
* (`inert`); an `inert` of your own wins.
|
|
483
|
+
*/
|
|
484
|
+
export const SidebarInset = defineComponent({
|
|
485
|
+
name: "SidebarInset",
|
|
486
|
+
inheritAttrs: false,
|
|
487
|
+
setup(_props, { attrs, slots }) {
|
|
488
|
+
const sidebar = useSidebar();
|
|
489
|
+
return () => {
|
|
490
|
+
const { className, rest } = cleanAttrs(attrs);
|
|
491
|
+
return h("main", { inert: sidebar.isMobile && sidebar.openMobile ? "" : undefined, ...rest, class: [s.Inset, className] }, slots.default?.());
|
|
492
|
+
};
|
|
493
|
+
},
|
|
494
|
+
});
|
|
479
495
|
/** Wrapper for the sidebar and the main content. */
|
|
480
496
|
export const SidebarLayout = part("SidebarLayout", "div", s.SidebarLayout);
|
|
481
497
|
/**
|
|
@@ -525,6 +541,8 @@ export const SidebarMobileMenuButton = defineComponent({
|
|
|
525
541
|
return h("button", {
|
|
526
542
|
"type": "button",
|
|
527
543
|
"data-expanded": sidebar.openMobile ? "" : undefined,
|
|
544
|
+
// Where focus goes when a drawer closes and what opened it can no longer take it (lib/phoneDrawer)
|
|
545
|
+
"data-sidebar-mobile-menu-button": "",
|
|
528
546
|
"class": [s.MobileMenuButton, className],
|
|
529
547
|
// The caller's listener runs first and can cancel the toggle
|
|
530
548
|
"onClick": composeEventHandlers(onClick, () => sidebar.setOpenMobile(!sidebar.openMobile)),
|
|
@@ -542,19 +560,104 @@ export const SidebarMobileMenuButton = defineComponent({
|
|
|
542
560
|
// =============================================
|
|
543
561
|
// Mobile Sidebar
|
|
544
562
|
// =============================================
|
|
563
|
+
/**
|
|
564
|
+
* The phone drawer: a modal dialog while it is open. Focus moves into it and Tab goes round its controls, the page
|
|
565
|
+
* behind is inert (SidebarInset), Escape inside it closes it after any layer over it has taken its own, and focus
|
|
566
|
+
* goes back to the control that opened it. A swipe in from the edge it slides from opens it and a swipe back closes
|
|
567
|
+
* it (lib/phoneDrawer).
|
|
568
|
+
*/
|
|
569
|
+
/** Runs `run` once `element` has left the page: a leaving `<Transition>` keeps it there for its animation */
|
|
570
|
+
const whenDetached = (element, run) => {
|
|
571
|
+
if (!element.isConnected)
|
|
572
|
+
return run();
|
|
573
|
+
const observer = new MutationObserver(() => {
|
|
574
|
+
if (element.isConnected)
|
|
575
|
+
return;
|
|
576
|
+
observer.disconnect();
|
|
577
|
+
run();
|
|
578
|
+
});
|
|
579
|
+
observer.observe(element.ownerDocument, { childList: true, subtree: true });
|
|
580
|
+
};
|
|
545
581
|
const SidebarMobileComponent = defineComponent({
|
|
546
582
|
name: "SidebarMobile",
|
|
547
583
|
inheritAttrs: false,
|
|
548
584
|
props: {
|
|
549
585
|
/** When true, drawer is positioned absolute instead of fixed (for contained demos) */
|
|
550
586
|
contained: { type: Boolean, default: undefined },
|
|
587
|
+
/** Rows that lead to another page end with a disclosure chevron, as in an iOS list. `false` leaves it out. @default true */
|
|
588
|
+
disclosure: { type: Boolean, default: true },
|
|
551
589
|
},
|
|
552
590
|
setup(props, { attrs, slots }) {
|
|
553
591
|
const sidebar = useSidebar();
|
|
554
|
-
provide(sidebarDrawerKey,
|
|
592
|
+
provide(sidebarDrawerKey, computed(() => props.disclosure));
|
|
593
|
+
const drawer = ref();
|
|
594
|
+
const setDrawer = (el) => {
|
|
595
|
+
drawer.value = el instanceof HTMLElement ? el : el?.$el;
|
|
596
|
+
};
|
|
597
|
+
let detachSwipe;
|
|
598
|
+
// Vue runs a watcher's cleanup on unmount while the drawer is still on the page, where React runs it once the
|
|
599
|
+
// drawer has left: focus goes back once the drawer has left (after unmount, or after a leaving <Transition>), so a
|
|
600
|
+
// menu button that leaves with the drawer is not picked
|
|
601
|
+
let unmounting = false;
|
|
602
|
+
let restoreAfterUnmount;
|
|
603
|
+
onMounted(() => {
|
|
604
|
+
// Focus moves in on open and back to what opened the drawer on close, or to a menu button when that can no longer
|
|
605
|
+
// take it (from mount, as React's effect). A drawer that is not contained shows only at phone width, so going
|
|
606
|
+
// back to it from a wide window moves focus in again.
|
|
607
|
+
watch(() => sidebar.openMobile && (sidebar.isMobile || Boolean(props.contained)), (open, _, onCleanup) => {
|
|
608
|
+
const el = drawer.value;
|
|
609
|
+
if (!open || !el)
|
|
610
|
+
return;
|
|
611
|
+
const trigger = document.activeElement;
|
|
612
|
+
// Taken now: after unmount the drawer has left the page, with no provider around it
|
|
613
|
+
const root = el.closest("[data-mobile-menu]");
|
|
614
|
+
if (!el.contains(document.activeElement))
|
|
615
|
+
drawerInitialFocus(el).focus({ preventScroll: true });
|
|
616
|
+
onCleanup(() => {
|
|
617
|
+
const restore = () => {
|
|
618
|
+
const active = document.activeElement;
|
|
619
|
+
const lost = !active || active === document.body || el.contains(active);
|
|
620
|
+
if (lost)
|
|
621
|
+
returnDrawerFocus(trigger, el, root);
|
|
622
|
+
};
|
|
623
|
+
if (unmounting)
|
|
624
|
+
restoreAfterUnmount = () => whenDetached(el, restore);
|
|
625
|
+
else
|
|
626
|
+
restore();
|
|
627
|
+
});
|
|
628
|
+
}, { flush: "post", immediate: true });
|
|
629
|
+
const el = drawer.value;
|
|
630
|
+
const root = el?.closest("[data-mobile-menu]");
|
|
631
|
+
if (!el || !root)
|
|
632
|
+
return;
|
|
633
|
+
detachSwipe = attachDrawerSwipe({
|
|
634
|
+
root,
|
|
635
|
+
drawer: el,
|
|
636
|
+
isOpen: () => sidebar.openMobile,
|
|
637
|
+
setOpen: (open) => sidebar.setOpenMobile(open),
|
|
638
|
+
enabled: () => sidebar.isMobile,
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
onBeforeUnmount(() => {
|
|
642
|
+
unmounting = true;
|
|
643
|
+
detachSwipe?.();
|
|
644
|
+
});
|
|
645
|
+
onUnmounted(() => {
|
|
646
|
+
restoreAfterUnmount?.();
|
|
647
|
+
restoreAfterUnmount = undefined;
|
|
648
|
+
});
|
|
649
|
+
const onDrawerKeydown = (event) => {
|
|
650
|
+
const el = drawer.value;
|
|
651
|
+
if (!sidebar.openMobile || !el)
|
|
652
|
+
return;
|
|
653
|
+
loopDrawerFocus(event, el);
|
|
654
|
+
closeOnUnhandledEscape(event, el, () => sidebar.setOpenMobile(false));
|
|
655
|
+
};
|
|
555
656
|
return () => {
|
|
556
657
|
const { className, rest } = cleanAttrs(attrs);
|
|
658
|
+
const { onKeydown: userKeydown, ...drawerAttrs } = rest;
|
|
557
659
|
const contained = props.contained && s.contained;
|
|
660
|
+
const open = sidebar.openMobile;
|
|
558
661
|
return [
|
|
559
662
|
// Backdrop
|
|
560
663
|
h("div", {
|
|
@@ -563,7 +666,23 @@ const SidebarMobileComponent = defineComponent({
|
|
|
563
666
|
"aria-hidden": "true",
|
|
564
667
|
}),
|
|
565
668
|
// Drawer
|
|
566
|
-
h("div", {
|
|
669
|
+
h("div", {
|
|
670
|
+
"ref": setDrawer,
|
|
671
|
+
"role": "dialog",
|
|
672
|
+
"aria-modal": open ? "true" : undefined,
|
|
673
|
+
"aria-label": "Menu",
|
|
674
|
+
"tabindex": -1,
|
|
675
|
+
"inert": open ? undefined : "",
|
|
676
|
+
...drawerAttrs,
|
|
677
|
+
"class": [s.MobileSidebar, contained, className],
|
|
678
|
+
// Your handler runs first and can keep the drawer open with preventDefault(), as onKeyDown in React
|
|
679
|
+
"onKeydown": (event) => {
|
|
680
|
+
for (const handler of [userKeydown].flat())
|
|
681
|
+
if (typeof handler === "function")
|
|
682
|
+
handler(event);
|
|
683
|
+
onDrawerKeydown(event);
|
|
684
|
+
},
|
|
685
|
+
}, slots.default?.()),
|
|
567
686
|
];
|
|
568
687
|
};
|
|
569
688
|
},
|