bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
738 lines (737 loc) • 24.5 kB
JavaScript
import { C as useVModel } from "./dist-B10a-gZ8.mjs";
import { S as hasTime, T as isBeforeOrSame, a as createContent, c as syncSegmentValues, d as useDateFormatter, g as areAllDaysBetweenValid, h as normalizeHourCycle, i as isSegmentNavigationKey, m as normalizeDateStep, n as getSegmentElements, o as initializeSegmentValues, t as useDateField, u as useLocale, v as getDefaultDate, w as isBefore } from "./useDateField-DmmXa0_5.mjs";
import { a as useDirection, c as createContext, n as usePrimitiveElement, r as Primitive, t as VisuallyHidden_default } from "./VisuallyHidden-Bbwok8oL.mjs";
import { r as isNullish, t as useKbd } from "./useKbd-IZRktImL.mjs";
import { computed, createBlock, createVNode, defineComponent, mergeProps, nextTick, onMounted, openBlock, ref, renderSlot, toHandlers, toRefs, unref, watch, withCtx, withKeys } from "vue";
//#region ../../node_modules/.pnpm/reka-ui@2.9.2_vue@3.5.31_typescript@5.9.3_/node_modules/reka-ui/dist/DateField/DateFieldRoot.js
var [injectDateFieldRootContext, provideDateFieldRootContext] = createContext("DateFieldRoot");
var DateFieldRoot_default = /* @__PURE__ */ defineComponent({
inheritAttrs: false,
__name: "DateFieldRoot",
props: {
defaultValue: {
type: null,
required: false,
default: void 0
},
defaultPlaceholder: {
type: null,
required: false
},
placeholder: {
type: null,
required: false,
default: void 0
},
modelValue: {
type: null,
required: false
},
hourCycle: {
type: null,
required: false
},
step: {
type: Object,
required: false
},
granularity: {
type: String,
required: false
},
hideTimeZone: {
type: Boolean,
required: false
},
maxValue: {
type: null,
required: false
},
minValue: {
type: null,
required: false
},
locale: {
type: String,
required: false
},
disabled: {
type: Boolean,
required: false,
default: false
},
readonly: {
type: Boolean,
required: false,
default: false
},
isDateUnavailable: {
type: Function,
required: false,
default: void 0
},
id: {
type: String,
required: false
},
dir: {
type: String,
required: false
},
asChild: {
type: Boolean,
required: false
},
as: {
type: null,
required: false
},
name: {
type: String,
required: false
},
required: {
type: Boolean,
required: false
}
},
emits: ["update:modelValue", "update:placeholder"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emits = __emit;
const { disabled, readonly, isDateUnavailable: propsIsDateUnavailable, granularity, defaultValue, dir: propDir, locale: propLocale } = toRefs(props);
const locale = useLocale(propLocale);
const dir = useDirection(propDir);
const formatter = useDateFormatter(locale.value, { hourCycle: normalizeHourCycle(props.hourCycle) });
const { primitiveElement, currentElement: parentElement } = usePrimitiveElement();
const segmentElements = ref(/* @__PURE__ */ new Set());
onMounted(() => {
getSegmentElements(parentElement.value).forEach((item) => segmentElements.value.add(item));
});
const modelValue = useVModel(props, "modelValue", emits, {
defaultValue: defaultValue.value,
passive: props.modelValue === void 0
});
const defaultDate = getDefaultDate({
defaultPlaceholder: props.placeholder,
granularity: granularity.value,
defaultValue: modelValue.value,
locale: props.locale
});
const placeholder = useVModel(props, "placeholder", emits, {
defaultValue: props.defaultPlaceholder ?? defaultDate.copy(),
passive: props.placeholder === void 0
});
const step = computed(() => normalizeDateStep(props));
const inferredGranularity = computed(() => {
if (props.granularity) return !hasTime(placeholder.value) ? "day" : props.granularity;
return hasTime(placeholder.value) ? "minute" : "day";
});
const isInvalid = computed(() => {
if (!modelValue.value) return false;
if (propsIsDateUnavailable.value?.(modelValue.value)) return true;
if (props.minValue && isBefore(modelValue.value, props.minValue)) return true;
if (props.maxValue && isBefore(props.maxValue, modelValue.value)) return true;
return false;
});
const initialSegments = initializeSegmentValues(inferredGranularity.value);
const segmentValues = ref(modelValue.value ? { ...syncSegmentValues({
value: modelValue.value,
formatter
}) } : { ...initialSegments });
const allSegmentContent = computed(() => createContent({
granularity: inferredGranularity.value,
dateRef: placeholder.value,
formatter,
hideTimeZone: props.hideTimeZone,
hourCycle: props.hourCycle,
segmentValues: segmentValues.value,
locale
}));
const segmentContents = computed(() => allSegmentContent.value.arr);
const editableSegmentContents = computed(() => segmentContents.value.filter(({ part }) => part !== "literal"));
watch(locale, (value) => {
if (formatter.getLocale() !== value) {
formatter.setLocale(value);
nextTick(() => {
segmentElements.value.clear();
getSegmentElements(parentElement.value).forEach((item) => segmentElements.value.add(item));
});
}
});
watch(modelValue, (_modelValue) => {
if (!isNullish(_modelValue) && placeholder.value.compare(_modelValue) !== 0) placeholder.value = _modelValue.copy();
});
watch([modelValue, locale], ([_modelValue]) => {
if (!isNullish(_modelValue)) segmentValues.value = { ...syncSegmentValues({
value: _modelValue,
formatter
}) };
else if (Object.values(segmentValues.value).every((value) => value !== null) && isNullish(_modelValue)) segmentValues.value = { ...initialSegments };
});
const currentFocusedElement = ref(null);
const currentSegmentIndex = computed(() => Array.from(segmentElements.value).findIndex((el) => el.getAttribute("data-reka-date-field-segment") === currentFocusedElement.value?.getAttribute("data-reka-date-field-segment")));
const nextFocusableSegment = computed(() => {
const sign = dir.value === "rtl" ? -1 : 1;
if (sign < 0 ? currentSegmentIndex.value < 0 : currentSegmentIndex.value > segmentElements.value.size - 1) return null;
return Array.from(segmentElements.value)[currentSegmentIndex.value + sign];
});
const prevFocusableSegment = computed(() => {
const sign = dir.value === "rtl" ? -1 : 1;
if (sign > 0 ? currentSegmentIndex.value < 0 : currentSegmentIndex.value > segmentElements.value.size - 1) return null;
return Array.from(segmentElements.value)[currentSegmentIndex.value - sign];
});
const kbd = useKbd();
function handleKeydown(e) {
if (!isSegmentNavigationKey(e.key)) return;
if (e.key === kbd.ARROW_LEFT) prevFocusableSegment.value?.focus();
if (e.key === kbd.ARROW_RIGHT) nextFocusableSegment.value?.focus();
}
function setFocusedElement(el) {
currentFocusedElement.value = el;
}
provideDateFieldRootContext({
isDateUnavailable: propsIsDateUnavailable.value,
locale,
modelValue,
placeholder,
disabled,
formatter,
hourCycle: props.hourCycle,
step,
readonly,
segmentValues,
isInvalid,
segmentContents: editableSegmentContents,
elements: segmentElements,
setFocusedElement,
focusNext() {
nextFocusableSegment.value?.focus();
}
});
__expose({ setFocusedElement });
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(Primitive), mergeProps(_ctx.$attrs, {
ref_key: "primitiveElement",
ref: primitiveElement,
role: "group",
"aria-disabled": unref(disabled) ? true : void 0,
"data-disabled": unref(disabled) ? "" : void 0,
"data-readonly": unref(readonly) ? "" : void 0,
"data-invalid": isInvalid.value ? "" : void 0,
dir: unref(dir),
onKeydown: withKeys(handleKeydown, ["left", "right"])
}), {
default: withCtx(() => [renderSlot(_ctx.$slots, "default", {
modelValue: unref(modelValue),
segments: segmentContents.value,
isInvalid: isInvalid.value
}), createVNode(unref(VisuallyHidden_default), {
id: _ctx.id,
as: "input",
type: "date",
feature: "focusable",
tabindex: "-1",
value: unref(modelValue) ? unref(modelValue).toString() : "",
name: _ctx.name,
disabled: unref(disabled),
required: _ctx.required,
max: _ctx.maxValue,
min: _ctx.minValue,
onFocus: _cache[0] || (_cache[0] = ($event) => Array.from(segmentElements.value)?.[0]?.focus())
}, null, 8, [
"id",
"value",
"name",
"disabled",
"required",
"max",
"min"
])]),
_: 3
}, 16, [
"aria-disabled",
"data-disabled",
"data-readonly",
"data-invalid",
"dir"
]);
};
}
});
//#endregion
//#region ../../node_modules/.pnpm/reka-ui@2.9.2_vue@3.5.31_typescript@5.9.3_/node_modules/reka-ui/dist/DateField/DateFieldInput.js
var DateFieldInput_default = /* @__PURE__ */ defineComponent({
__name: "DateFieldInput",
props: {
part: {
type: null,
required: true
},
asChild: {
type: Boolean,
required: false
},
as: {
type: null,
required: false
}
},
setup(__props) {
const props = __props;
const rootContext = injectDateFieldRootContext();
const hasLeftFocus = ref(true);
const { handleSegmentClick, handleSegmentKeydown, attributes } = useDateField({
hasLeftFocus,
lastKeyZero: ref(false),
placeholder: rootContext.placeholder,
hourCycle: rootContext.hourCycle,
step: rootContext.step,
segmentValues: rootContext.segmentValues,
formatter: rootContext.formatter,
part: props.part,
disabled: rootContext.disabled,
readonly: rootContext.readonly,
focusNext: rootContext.focusNext,
modelValue: rootContext.modelValue
});
const disabled = computed(() => rootContext.disabled.value);
const readonly = computed(() => rootContext.readonly.value);
const isInvalid = computed(() => rootContext.isInvalid.value);
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(Primitive), mergeProps({
as: _ctx.as,
"as-child": _ctx.asChild
}, unref(attributes), {
contenteditable: disabled.value || readonly.value ? false : _ctx.part !== "literal",
"data-reka-date-field-segment": _ctx.part,
"aria-disabled": disabled.value ? true : void 0,
"aria-readonly": readonly.value ? true : void 0,
"data-disabled": disabled.value ? "" : void 0,
"data-invalid": isInvalid.value ? "" : void 0,
"aria-invalid": isInvalid.value ? true : void 0
}, toHandlers(_ctx.part !== "literal" ? {
mousedown: unref(handleSegmentClick),
keydown: unref(handleSegmentKeydown),
focusout: () => {
hasLeftFocus.value = true;
},
focusin: (e) => {
unref(rootContext).setFocusedElement(e.target);
}
} : {})), {
default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
_: 3
}, 16, [
"as",
"as-child",
"contenteditable",
"data-reka-date-field-segment",
"aria-disabled",
"aria-readonly",
"data-disabled",
"data-invalid",
"aria-invalid"
]);
};
}
});
//#endregion
//#region ../../node_modules/.pnpm/reka-ui@2.9.2_vue@3.5.31_typescript@5.9.3_/node_modules/reka-ui/dist/DateRangeField/DateRangeFieldRoot.js
var [injectDateRangeFieldRootContext, provideDateRangeFieldRootContext] = createContext("DateRangeFieldRoot");
var DateRangeFieldRoot_default = /* @__PURE__ */ defineComponent({
inheritAttrs: false,
__name: "DateRangeFieldRoot",
props: {
defaultValue: {
type: Object,
required: false,
default: void 0
},
defaultPlaceholder: {
type: null,
required: false
},
placeholder: {
type: null,
required: false,
default: void 0
},
modelValue: {
type: [Object, null],
required: false
},
hourCycle: {
type: null,
required: false
},
step: {
type: Object,
required: false
},
granularity: {
type: String,
required: false
},
hideTimeZone: {
type: Boolean,
required: false
},
maxValue: {
type: null,
required: false
},
minValue: {
type: null,
required: false
},
locale: {
type: String,
required: false
},
disabled: {
type: Boolean,
required: false,
default: false
},
readonly: {
type: Boolean,
required: false,
default: false
},
isDateUnavailable: {
type: Function,
required: false,
default: void 0
},
id: {
type: String,
required: false
},
dir: {
type: String,
required: false
},
asChild: {
type: Boolean,
required: false
},
as: {
type: null,
required: false
},
name: {
type: String,
required: false
},
required: {
type: Boolean,
required: false
}
},
emits: ["update:modelValue", "update:placeholder"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emits = __emit;
const { disabled, readonly, isDateUnavailable: propsIsDateUnavailable, dir: propDir, locale: propLocale } = toRefs(props);
const locale = useLocale(propLocale);
const dir = useDirection(propDir);
const formatter = useDateFormatter(locale.value, { hourCycle: normalizeHourCycle(props.hourCycle) });
const { primitiveElement, currentElement: parentElement } = usePrimitiveElement();
const segmentElements = ref(/* @__PURE__ */ new Set());
onMounted(() => {
getSegmentElements(parentElement.value).forEach((item) => segmentElements.value.add(item));
});
const modelValue = useVModel(props, "modelValue", emits, {
defaultValue: props.defaultValue ?? {
start: void 0,
end: void 0
},
passive: props.modelValue === void 0
});
const defaultDate = getDefaultDate({
defaultPlaceholder: props.placeholder,
granularity: props.granularity,
defaultValue: modelValue.value?.start,
locale: props.locale
});
const placeholder = useVModel(props, "placeholder", emits, {
defaultValue: props.defaultPlaceholder ?? defaultDate.copy(),
passive: props.placeholder === void 0
});
const step = computed(() => normalizeDateStep(props));
const inferredGranularity = computed(() => {
if (props.granularity) return !hasTime(placeholder.value) ? "day" : props.granularity;
return hasTime(placeholder.value) ? "minute" : "day";
});
const isStartInvalid = computed(() => {
if (!modelValue.value?.start) return false;
if (propsIsDateUnavailable.value?.(modelValue.value.start)) return true;
if (props.minValue && isBefore(modelValue.value.start, props.minValue)) return true;
if (props.maxValue && isBefore(props.maxValue, modelValue.value.start)) return true;
return false;
});
const isEndInvalid = computed(() => {
if (!modelValue.value?.end) return false;
if (propsIsDateUnavailable.value?.(modelValue.value.end)) return true;
if (props.minValue && isBefore(modelValue.value.end, props.minValue)) return true;
if (props.maxValue && isBefore(props.maxValue, modelValue.value.end)) return true;
return false;
});
const isInvalid = computed(() => {
if (isStartInvalid.value || isEndInvalid.value) return true;
if (!modelValue.value?.start || !modelValue.value?.end) return false;
if (!isBeforeOrSame(modelValue.value.start, modelValue.value.end)) return true;
if (propsIsDateUnavailable.value !== void 0) {
if (!areAllDaysBetweenValid(modelValue.value.start, modelValue.value.end, propsIsDateUnavailable.value, void 0)) return true;
}
return false;
});
const initialSegments = initializeSegmentValues(inferredGranularity.value);
const startSegmentValues = ref(modelValue.value?.start ? { ...syncSegmentValues({
value: modelValue.value.start,
formatter
}) } : { ...initialSegments });
const endSegmentValues = ref(modelValue.value?.end ? { ...syncSegmentValues({
value: modelValue.value.end,
formatter
}) } : { ...initialSegments });
const startSegmentContent = computed(() => createContent({
granularity: inferredGranularity.value,
dateRef: placeholder.value,
formatter,
hideTimeZone: props.hideTimeZone,
hourCycle: props.hourCycle,
segmentValues: startSegmentValues.value,
locale
}));
const endSegmentContent = computed(() => createContent({
granularity: inferredGranularity.value,
dateRef: placeholder.value,
formatter,
hideTimeZone: props.hideTimeZone,
hourCycle: props.hourCycle,
segmentValues: endSegmentValues.value,
locale
}));
const segmentContents = computed(() => ({
start: startSegmentContent.value.arr,
end: endSegmentContent.value.arr
}));
const editableSegmentContents = computed(() => ({
start: segmentContents.value.start.filter(({ part }) => part !== "literal"),
end: segmentContents.value.end.filter(({ part }) => part !== "literal")
}));
const startValue = ref(modelValue.value?.start?.copy());
const endValue = ref(modelValue.value?.end?.copy());
watch([startValue, endValue], ([_startValue, _endValue]) => {
modelValue.value = {
start: _startValue?.copy(),
end: _endValue?.copy()
};
});
watch(modelValue, (_modelValue) => {
if (_modelValue?.start && startValue.value ? _modelValue.start.compare(startValue.value) !== 0 : _modelValue?.start !== startValue.value) startValue.value = _modelValue?.start?.copy();
if (_modelValue?.end && endValue.value ? _modelValue.end.compare(endValue.value) !== 0 : _modelValue?.end !== endValue.value) endValue.value = _modelValue?.end?.copy();
});
watch([startValue, locale], ([_startValue]) => {
if (_startValue !== void 0) startSegmentValues.value = { ...syncSegmentValues({
value: _startValue,
formatter
}) };
else if (Object.values(startSegmentValues.value).every((value) => value !== null) && _startValue === void 0) startSegmentValues.value = { ...initialSegments };
});
watch(locale, (value) => {
if (formatter.getLocale() !== value) {
formatter.setLocale(value);
nextTick(() => {
segmentElements.value.clear();
getSegmentElements(parentElement.value).forEach((item) => segmentElements.value.add(item));
});
}
});
watch(modelValue, (_modelValue) => {
if (_modelValue && _modelValue.start !== void 0 && placeholder.value.compare(_modelValue.start) !== 0) placeholder.value = _modelValue.start.copy();
});
watch([endValue, locale], ([_endValue]) => {
if (_endValue !== void 0) endSegmentValues.value = { ...syncSegmentValues({
value: _endValue,
formatter
}) };
else if (Object.values(endSegmentValues.value).every((value) => value !== null) && _endValue === void 0) endSegmentValues.value = { ...initialSegments };
});
const currentFocusedElement = ref(null);
const currentSegmentIndex = computed(() => Array.from(segmentElements.value).findIndex((el) => el.getAttribute("data-reka-date-field-segment") === currentFocusedElement.value?.getAttribute("data-reka-date-field-segment") && el.getAttribute("data-reka-date-range-field-segment-type") === currentFocusedElement.value?.getAttribute("data-reka-date-range-field-segment-type")));
const nextFocusableSegment = computed(() => {
const sign = dir.value === "rtl" ? -1 : 1;
if (sign < 0 ? currentSegmentIndex.value < 0 : currentSegmentIndex.value > segmentElements.value.size - 1) return null;
return Array.from(segmentElements.value)[currentSegmentIndex.value + sign];
});
const prevFocusableSegment = computed(() => {
const sign = dir.value === "rtl" ? -1 : 1;
if (sign > 0 ? currentSegmentIndex.value < 0 : currentSegmentIndex.value > segmentElements.value.size - 1) return null;
return Array.from(segmentElements.value)[currentSegmentIndex.value - sign];
});
const kbd = useKbd();
function handleKeydown(e) {
if (!isSegmentNavigationKey(e.key)) return;
if (e.key === kbd.ARROW_LEFT) prevFocusableSegment.value?.focus();
if (e.key === kbd.ARROW_RIGHT) nextFocusableSegment.value?.focus();
}
function setFocusedElement(el) {
currentFocusedElement.value = el;
}
provideDateRangeFieldRootContext({
isDateUnavailable: propsIsDateUnavailable.value,
locale,
startValue,
endValue,
placeholder,
disabled,
formatter,
hourCycle: props.hourCycle,
step,
readonly,
segmentValues: {
start: startSegmentValues,
end: endSegmentValues
},
isInvalid,
segmentContents: editableSegmentContents,
elements: segmentElements,
setFocusedElement,
focusNext() {
nextFocusableSegment.value?.focus();
}
});
__expose({ setFocusedElement });
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(Primitive), mergeProps(_ctx.$attrs, {
ref_key: "primitiveElement",
ref: primitiveElement,
role: "group",
"aria-disabled": unref(disabled) ? true : void 0,
"data-disabled": unref(disabled) ? "" : void 0,
"data-readonly": unref(readonly) ? "" : void 0,
"data-invalid": isInvalid.value ? "" : void 0,
dir: unref(dir),
onKeydown: withKeys(handleKeydown, ["left", "right"])
}), {
default: withCtx(() => [renderSlot(_ctx.$slots, "default", {
modelValue: unref(modelValue),
segments: segmentContents.value,
isInvalid: isInvalid.value
}), createVNode(unref(VisuallyHidden_default), {
id: _ctx.id,
as: "input",
feature: "focusable",
tabindex: "-1",
value: `${unref(modelValue)?.start?.toString()} - ${unref(modelValue)?.end?.toString()}`,
name: _ctx.name,
disabled: unref(disabled),
required: _ctx.required,
onFocus: _cache[0] || (_cache[0] = ($event) => Array.from(segmentElements.value)?.[0]?.focus())
}, null, 8, [
"id",
"value",
"name",
"disabled",
"required"
])]),
_: 3
}, 16, [
"aria-disabled",
"data-disabled",
"data-readonly",
"data-invalid",
"dir"
]);
};
}
});
//#endregion
//#region ../../node_modules/.pnpm/reka-ui@2.9.2_vue@3.5.31_typescript@5.9.3_/node_modules/reka-ui/dist/DateRangeField/DateRangeFieldInput.js
var DateRangeFieldInput_default = /* @__PURE__ */ defineComponent({
__name: "DateRangeFieldInput",
props: {
part: {
type: null,
required: true
},
type: {
type: String,
required: true
},
asChild: {
type: Boolean,
required: false
},
as: {
type: null,
required: false
}
},
setup(__props) {
const props = __props;
const rootContext = injectDateRangeFieldRootContext();
const hasLeftFocus = ref(true);
const { handleSegmentClick, handleSegmentKeydown, attributes } = useDateField({
hasLeftFocus,
lastKeyZero: ref(false),
placeholder: rootContext.placeholder,
hourCycle: rootContext.hourCycle,
step: rootContext.step,
segmentValues: rootContext.segmentValues[props.type],
formatter: rootContext.formatter,
part: props.part,
disabled: rootContext.disabled,
readonly: rootContext.readonly,
focusNext: rootContext.focusNext,
modelValue: props.type === "start" ? rootContext.startValue : rootContext.endValue
});
const disabled = computed(() => rootContext.disabled.value);
const readonly = computed(() => rootContext.readonly.value);
const isInvalid = computed(() => rootContext.isInvalid.value);
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(Primitive), mergeProps({
as: _ctx.as,
"as-child": _ctx.asChild
}, unref(attributes), {
contenteditable: disabled.value || readonly.value ? false : _ctx.part !== "literal",
"data-reka-date-field-segment": _ctx.part,
"aria-disabled": disabled.value ? true : void 0,
"aria-readonly": readonly.value ? true : void 0,
"data-disabled": disabled.value ? "" : void 0,
"data-reka-date-range-field-segment-type": _ctx.type,
"data-invalid": isInvalid.value ? "" : void 0,
"aria-invalid": isInvalid.value ? true : void 0
}, toHandlers(_ctx.part !== "literal" ? {
mousedown: unref(handleSegmentClick),
keydown: unref(handleSegmentKeydown),
focusout: () => {
hasLeftFocus.value = true;
},
focusin: (e) => {
unref(rootContext).setFocusedElement(e.target);
}
} : {})), {
default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
_: 3
}, 16, [
"as",
"as-child",
"contenteditable",
"data-reka-date-field-segment",
"aria-disabled",
"aria-readonly",
"data-disabled",
"data-reka-date-range-field-segment-type",
"data-invalid",
"aria-invalid"
]);
};
}
});
//#endregion
export { DateFieldRoot_default as i, DateRangeFieldRoot_default as n, DateFieldInput_default as r, DateRangeFieldInput_default as t };
//# sourceMappingURL=DateRangeFieldInput-DiVuhf4Y.mjs.map