UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

511 lines (510 loc) 17.3 kB
import { C as useVModel } from "./dist-B10a-gZ8.mjs"; import { t as useDefaults } from "./useDefaults-BKgBaqOV.mjs"; import { t as useId$1 } from "./useId-BKZFSYm8.mjs"; import { B as $14e0f24ef4ac5c92$export$d0bdf45af03a6ea3, F as $14e0f24ef4ac5c92$export$91b62ebf2ba703ee, a as createContent, d as useDateFormatter, h as normalizeHourCycle, i as isSegmentNavigationKey, j as $11d87f3f76e88657$export$b21e0b124e224484, k as $35ea8db9cb2ccb90$export$680ea196effce5f, l as syncTimeSegmentValues, m as normalizeDateStep, r as getTimeFieldSegmentElements, s as initializeTimeSegmentValues, t as useDateField, u as useLocale, w as isBefore, y as getDefaultTime, z as $14e0f24ef4ac5c92$export$aa8b41735afcabd2 } 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 { Fragment, computed, createBlock, createElementBlock, createTextVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, normalizeClass, onMounted, openBlock, ref, renderList, renderSlot, toDisplayString, toHandlers, toRefs, unref, useModel, 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/TimeField/TimeFieldRoot.js var [injectTimeFieldRootContext, provideTimeFieldRootContext] = createContext("TimeFieldRoot"); function convertValue(value, date = $14e0f24ef4ac5c92$export$d0bdf45af03a6ea3($14e0f24ef4ac5c92$export$aa8b41735afcabd2())) { if (value && "day" in value) return value; return $11d87f3f76e88657$export$b21e0b124e224484(date, value); } var TimeFieldRoot_default = /* @__PURE__ */ defineComponent({ inheritAttrs: false, __name: "TimeFieldRoot", props: { defaultValue: { type: Object, required: false, default: void 0 }, defaultPlaceholder: { type: Object, required: false }, placeholder: { type: Object, required: false, default: void 0 }, modelValue: { type: [Object, null], required: false }, hourCycle: { type: null, required: false }, step: { type: Object, required: false }, stepSnapping: { type: Boolean, required: false, default: false }, granularity: { type: String, required: false }, hideTimeZone: { type: Boolean, required: false }, maxValue: { type: Object, required: false }, minValue: { type: Object, required: false }, locale: { type: String, required: false }, disabled: { type: Boolean, required: false, default: false }, readonly: { type: Boolean, required: false, default: false }, 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, granularity, defaultValue, minValue, maxValue, stepSnapping, 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()); const step = computed(() => normalizeDateStep(props)); const convertedMinValue = computed(() => minValue.value ? convertValue(minValue.value) : void 0); const convertedMaxValue = computed(() => maxValue.value ? convertValue(maxValue.value) : void 0); onMounted(() => { getTimeFieldSegmentElements(parentElement.value).forEach((item) => segmentElements.value.add(item)); }); const modelValue = useVModel(props, "modelValue", emits, { defaultValue: defaultValue.value, passive: props.modelValue === void 0 }); const convertedModelValue = computed({ get() { if (isNullish(modelValue.value)) return modelValue.value; return convertValue(modelValue.value); }, set(newValue) { if (newValue) modelValue.value = modelValue.value && "day" in modelValue.value ? newValue : new $35ea8db9cb2ccb90$export$680ea196effce5f(newValue.hour, newValue.minute, newValue.second, modelValue.value?.millisecond); else modelValue.value = newValue; return newValue; } }); const defaultDate = getDefaultTime({ defaultPlaceholder: props.placeholder, defaultValue: modelValue.value }); const placeholder = useVModel(props, "placeholder", emits, { defaultValue: props.defaultPlaceholder ?? defaultDate.copy(), passive: props.placeholder === void 0 }); const convertedPlaceholder = computed({ get() { return convertValue(placeholder.value); }, set(newValue) { if (newValue) placeholder.value = "day" in placeholder.value ? newValue.copy() : new $35ea8db9cb2ccb90$export$680ea196effce5f(newValue.hour, newValue.minute, newValue.second, placeholder.value?.millisecond); return newValue; } }); const inferredGranularity = computed(() => { if (granularity.value) return granularity.value; return "minute"; }); const isInvalid = computed(() => { if (!modelValue.value) return false; if (convertedMinValue.value && isBefore(convertedModelValue.value, convertedMinValue.value)) return true; if (convertedMaxValue.value && isBefore(convertedMaxValue.value, convertedModelValue.value)) return true; return false; }); const initialSegments = initializeTimeSegmentValues(inferredGranularity.value); const segmentValues = ref(modelValue.value ? { ...syncTimeSegmentValues({ value: convertedModelValue.value, formatter }) } : { ...initialSegments }); const allSegmentContent = computed(() => createContent({ granularity: inferredGranularity.value, dateRef: convertedPlaceholder.value, formatter, hideTimeZone: props.hideTimeZone, hourCycle: props.hourCycle, segmentValues: segmentValues.value, locale, isTimeValue: true })); const segmentContents = computed(() => { const contents = allSegmentContent.value.arr; if (props.hourCycle === 12) return contents.map((segment) => { if (segment.part === "hour" && "hour" in segmentValues.value) { const hour = segmentValues.value.hour; if (hour !== null) { const displayHour = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour; return { ...segment, value: displayHour.toString() }; } } return segment; }); return contents; }); const editableSegmentContents = computed(() => segmentContents.value.filter(({ part }) => part !== "literal")); watch(locale, (value) => { if (formatter.getLocale() !== value) { formatter.setLocale(value); nextTick(() => { segmentElements.value.clear(); getTimeFieldSegmentElements(parentElement.value).forEach((item) => segmentElements.value.add(item)); }); } }); watch(convertedModelValue, (_modelValue) => { if (!isNullish(_modelValue) && (!$14e0f24ef4ac5c92$export$91b62ebf2ba703ee(convertedPlaceholder.value, _modelValue) || convertedPlaceholder.value.compare(_modelValue) !== 0)) placeholder.value = _modelValue.copy(); }); watch([convertedModelValue, locale], ([_modelValue]) => { if (!isNullish(_modelValue)) segmentValues.value = { ...syncTimeSegmentValues({ 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-time-field-segment") === currentFocusedElement.value?.getAttribute("data-reka-time-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; } provideTimeFieldRootContext({ locale, modelValue: convertedModelValue, placeholder: convertedPlaceholder, disabled, formatter, hourCycle: props.hourCycle, step, stepSnapping, 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", feature: "focusable", tabindex: "-1", value: unref(modelValue) ? unref(modelValue).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/TimeField/TimeFieldInput.js var TimeFieldInput_default = /* @__PURE__ */ defineComponent({ __name: "TimeFieldInput", props: { part: { type: null, required: true }, asChild: { type: Boolean, required: false }, as: { type: null, required: false } }, setup(__props) { const props = __props; const rootContext = injectTimeFieldRootContext(); const hasLeftFocus = ref(true); const { handleSegmentClick, handleSegmentKeydown, handleSegmentFocusOut, attributes } = useDateField({ hasLeftFocus, lastKeyZero: ref(false), placeholder: rootContext.placeholder, hourCycle: rootContext.hourCycle, step: rootContext.step, stepSnapping: rootContext.stepSnapping, 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-time-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; unref(handleSegmentFocusOut)(); }, focusin: (e) => { unref(rootContext).setFocusedElement(e.target); } } : {})), { default: withCtx(() => [renderSlot(_ctx.$slots, "default")]), _: 3 }, 16, [ "as", "as-child", "contenteditable", "data-reka-time-field-segment", "aria-disabled", "aria-readonly", "data-disabled", "data-invalid", "aria-invalid" ]); }; } }); //#endregion //#region src/components/BTimeField/BTimeField.vue var BTimeField_default = /* @__PURE__ */ defineComponent({ __name: "BTimeField", props: /* @__PURE__ */ mergeModels({ defaultPlaceholder: { default: void 0 }, defaultValue: { default: void 0 }, dir: { default: void 0 }, disabled: { type: Boolean, default: false }, granularity: { default: void 0 }, hideTimeZone: { type: Boolean, default: void 0 }, hourCycle: { default: void 0 }, id: { default: void 0 }, locale: { default: void 0 }, maxValue: { default: void 0 }, minValue: { default: void 0 }, name: { default: void 0 }, readonly: { type: Boolean, default: false }, required: { type: Boolean, default: false }, size: { default: void 0 }, state: { type: [Boolean, null], default: null }, step: { default: void 0 }, stepSnapping: { type: Boolean, default: false } }, { "modelValue": { default: null }, "modelModifiers": {}, "placeholder": {}, "placeholderModifiers": {} }), emits: ["update:modelValue", "update:placeholder"], setup(__props) { const props = useDefaults(__props, "BTimeField"); const modelValue = useModel(__props, "modelValue"); const placeholderModel = useModel(__props, "placeholder"); const computedId = useId$1(() => props.id, "time-field"); const computedRootClasses = computed(() => ({ "disabled": props.disabled, "readonly": props.readonly, "is-valid": props.state === true, "is-invalid": props.state === false, [`form-control-${props.size}`]: props.size !== void 0 })); return (_ctx, _cache) => { return openBlock(), createBlock(unref(TimeFieldRoot_default), { id: unref(computedId), modelValue: modelValue.value, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event), placeholder: placeholderModel.value, "onUpdate:placeholder": _cache[1] || (_cache[1] = ($event) => placeholderModel.value = $event), "default-value": unref(props).defaultValue, "default-placeholder": unref(props).defaultPlaceholder, "hour-cycle": unref(props).hourCycle, step: unref(props).step, "step-snapping": unref(props).stepSnapping, granularity: unref(props).granularity, "hide-time-zone": unref(props).hideTimeZone, "max-value": unref(props).maxValue, "min-value": unref(props).minValue, locale: unref(props).locale, disabled: unref(props).disabled, readonly: unref(props).readonly, name: unref(props).name, required: unref(props).required, dir: unref(props).dir, class: normalizeClass([computedRootClasses.value, "b-time-field form-control d-inline-flex align-items-center gap-0"]) }, { default: withCtx(({ segments, isInvalid, modelValue: currentValue }) => [renderSlot(_ctx.$slots, "default", { modelValue: currentValue, segments, isInvalid }, () => [(openBlock(true), createElementBlock(Fragment, null, renderList(segments, ({ part, value }) => { return openBlock(), createElementBlock(Fragment, { key: part }, [part === "literal" ? (openBlock(), createBlock(unref(TimeFieldInput_default), { key: 0, part, class: "b-time-field-literal" }, { default: withCtx(() => [createTextVNode(toDisplayString(value), 1)]), _: 2 }, 1032, ["part"])) : (openBlock(), createBlock(unref(TimeFieldInput_default), { key: 1, part, class: "b-time-field-segment" }, { default: withCtx(() => [createTextVNode(toDisplayString(value), 1)]), _: 2 }, 1032, ["part"]))], 64); }), 128))])]), _: 3 }, 8, [ "id", "modelValue", "placeholder", "default-value", "default-placeholder", "hour-cycle", "step", "step-snapping", "granularity", "hide-time-zone", "max-value", "min-value", "locale", "disabled", "readonly", "name", "required", "dir", "class" ]); }; } }); //#endregion export { BTimeField_default as t }; //# sourceMappingURL=BTimeField-DSWZeGYP.mjs.map