{"version":3,"file":"datePickerBase.obs.js","sources":["../../../Framework/Controls/datePickerBase.obs"],"sourcesContent":["<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License -->\r\n<template>\r\n <div class=\"input-group input-width-md js-date-picker date\">\r\n <input ref=\"inputEl\" type=\"text\" :id=\"computedId\" class=\"form-control\" v-model.lazy=\"internalValue\" :disabled=\"disabled\" />\r\n <span class=\"input-group-addon\">\r\n <i class=\"fa fa-calendar\"></i>\r\n </span>\r\n </div>\r\n</template>\r\n\r\n<script lang=\"ts\">\r\n declare global {\r\n /* eslint-disable @typescript-eslint/naming-convention */\r\n interface Window {\r\n Rock: {\r\n controls: {\r\n datePicker: {\r\n initialize: (args: Record<string, unknown>) => void\r\n }\r\n }\r\n }\r\n }\r\n /* eslint-enable @typescript-eslint/naming-convention */\r\n }\r\n</script>\r\n\r\n<script setup lang=\"ts\">\r\n import { computed, onMounted, PropType, watch, ref, nextTick } from \"vue\";\r\n import { newGuid } from \"@Obsidian/Utility/guid\";\r\n import { DateTime } from \"luxon\";\r\n\r\n type DatePickerActions = {\r\n onSetLocalDate: ((localDate: Date) => void) | null;\r\n };\r\n\r\n const props = defineProps({\r\n modelValue: {\r\n type: String as PropType<string | null>,\r\n default: null\r\n },\r\n\r\n id: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n\r\n disabled: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n\r\n /** Whether to parse the entered value and reformat it to match the set format */\r\n disableForceParse: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n\r\n /** If set to true, only clicking on the calendar icon will open the calendar widget */\r\n disableShowOnFocus: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n\r\n /** Whether or not to highlight the current day on the calendar */\r\n disableHighlightToday: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n\r\n /** Whether or not the user should be able to select dates in the future */\r\n disallowFutureDateSelection: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n\r\n /** Whether or not the user should be able to select dates in the past */\r\n disallowPastDateSelection: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n\r\n /** Which view do we open the calendar widget on? 0 = Month, 1 = Year, 2 = Decade */\r\n startView: {\r\n type: Number as PropType<0 | 1 | 2>,\r\n default: 0\r\n },\r\n\r\n /**\r\n * The container to attach the popup to, if not specified it will\r\n * default to the document body.\r\n */\r\n container: {\r\n type: HTMLElement as PropType<HTMLElement | null>,\r\n required: false\r\n },\r\n\r\n /**\r\n * The horizontal orientation of the popup. Left will attempt to keep\r\n * the left edge aligned with the control and right will attempt to\r\n * keep the right edge aligned with the control.\r\n */\r\n horizontalOrientation: {\r\n type: String as PropType<\"left\" | \"right\">,\r\n required: false\r\n }\r\n });\r\n\r\n const emit = defineEmits<{\r\n (e: \"update:modelValue\", val: string | null): void\r\n }>();\r\n\r\n /** Actions to which the datepicker can handle. */\r\n const actions: DatePickerActions = {\r\n onSetLocalDate: null\r\n };\r\n\r\n // #region Values\r\n\r\n const internalValue = ref<string | null>(null);\r\n const defaultId = `datepicker-${newGuid()}`;\r\n const inputEl = ref<HTMLInputElement | null>(null);\r\n\r\n // #endregion\r\n\r\n // #region Computed Values\r\n\r\n const computedId = computed(() => {\r\n return props.id || defaultId;\r\n });\r\n\r\n const asRockDateOrNull = computed(() => {\r\n const match = /^(\\d+)\\/(\\d+)\\/(\\d+)/.exec(internalValue.value ?? \"\");\r\n\r\n if (match !== null) {\r\n return `${match[3]}-${match[1]}-${match[2]}`;\r\n }\r\n else {\r\n return null;\r\n }\r\n });\r\n\r\n const dateLimiterOptions = computed(() => {\r\n const options: Record<string, Date> = {};\r\n if (props.disallowFutureDateSelection) {\r\n options.endDate = new Date();\r\n }\r\n if (props.disallowPastDateSelection) {\r\n options.startDate = new Date();\r\n }\r\n\r\n return options;\r\n });\r\n\r\n // #endregion\r\n\r\n // #region Functions\r\n\r\n function initializePopup(): void {\r\n const input = inputEl.value;\r\n\r\n if (!input) {\r\n return;\r\n }\r\n\r\n window.Rock.controls.datePicker.initialize({\r\n ...(dateLimiterOptions.value),\r\n id: input.id,\r\n startView: props.startView,\r\n showOnFocus: !props.disableShowOnFocus,\r\n format: \"mm/dd/yyyy\",\r\n todayHighlight: !props.disableHighlightToday,\r\n forceParse: !props.disableForceParse,\r\n onChangeScript: () => {\r\n internalValue.value = input.value;\r\n },\r\n container: props.container ?? \"body\",\r\n orientation: props.horizontalOrientation || \"auto\",\r\n actions\r\n });\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Watchers\r\n\r\n watch(() => props.modelValue, () => {\r\n if (!props.modelValue) {\r\n internalValue.value = null;\r\n\r\n return;\r\n }\r\n\r\n const match = /^(\\d+)-(\\d+)-(\\d+)/.exec(props.modelValue);\r\n\r\n if (match !== null) {\r\n internalValue.value = `${match[2]}/${match[3]}/${match[1]}`;\r\n }\r\n else {\r\n internalValue.value = null;\r\n }\r\n\r\n // Update the underlying datepicker when the props.modelValue changes.\r\n if (internalValue.value && actions.onSetLocalDate) {\r\n const localDate = DateTime.fromFormat(internalValue.value, \"MM/dd/yyyy\").toJSDate();\r\n actions.onSetLocalDate(localDate);\r\n }\r\n }, { immediate: true });\r\n\r\n watch(asRockDateOrNull, () => {\r\n emit(\"update:modelValue\", asRockDateOrNull.value);\r\n });\r\n\r\n // #endregion\r\n\r\n // #region Lifecycle\r\n\r\n onMounted(() => {\r\n // Bit of a back to make sure all our props are set correctly.\r\n nextTick(() => {\r\n initializePopup();\r\n });\r\n });\r\n\r\n // #endregion\r\n</script>\r\n"],"names":["actions","onSetLocalDate","internalValue","ref","defaultId","concat","newGuid","inputEl","computedId","computed","props","id","asRockDateOrNull","_internalValue$value","match","exec","value","dateLimiterOptions","options","disallowFutureDateSelection","endDate","Date","disallowPastDateSelection","startDate","initializePopup","_props$container","input","window","Rock","controls","datePicker","initialize","_objectSpread","startView","showOnFocus","disableShowOnFocus","format","todayHighlight","disableHighlightToday","forceParse","disableForceParse","onChangeScript","container","orientation","horizontalOrientation","watch","modelValue","localDate","DateTime","fromFormat","toJSDate","immediate","emit","onMounted","nextTick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAgHI,IAAA,IAAMA,OAA0B,GAAG;MAC/BC,MAAAA,cAAc,EAAE,IAAA;WACnB,CAAA;MAID,IAAA,IAAMC,aAAa,GAAGC,GAAG,CAAgB,IAAI,CAAC,CAAA;MAC9C,IAAA,IAAMC,SAAS,GAAAC,aAAAA,CAAAA,MAAA,CAAiBC,OAAO,EAAE,CAAE,CAAA;MAC3C,IAAA,IAAMC,OAAO,GAAGJ,GAAG,CAA0B,IAAI,CAAC,CAAA;MAMlD,IAAA,IAAMK,UAAU,GAAGC,QAAQ,CAAC,MAAM;MAC9B,MAAA,OAAOC,KAAK,CAACC,EAAE,IAAIP,SAAS,CAAA;MAChC,KAAC,CAAC,CAAA;MAEF,IAAA,IAAMQ,gBAAgB,GAAGH,QAAQ,CAAC,MAAM;MAAA,MAAA,IAAAI,oBAAA,CAAA;MACpC,MAAA,IAAMC,KAAK,GAAG,sBAAsB,CAACC,IAAI,EAAAF,oBAAA,GAACX,aAAa,CAACc,KAAK,MAAAH,IAAAA,IAAAA,oBAAA,cAAAA,oBAAA,GAAI,EAAE,CAAC,CAAA;YAEpE,IAAIC,KAAK,KAAK,IAAI,EAAE;MAChB,QAAA,OAAA,EAAA,CAAAT,MAAA,CAAUS,KAAK,CAAC,CAAC,CAAC,OAAAT,MAAA,CAAIS,KAAK,CAAC,CAAC,CAAC,EAAAT,GAAAA,CAAAA,CAAAA,MAAA,CAAIS,KAAK,CAAC,CAAC,CAAC,CAAA,CAAA;MAC9C,OAAC,MACI;MACD,QAAA,OAAO,IAAI,CAAA;MACf,OAAA;MACJ,KAAC,CAAC,CA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