{"version":3,"file":"numberBox.obs.js","sources":["../../../Framework/Controls/numberBox.obs"],"sourcesContent":["<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License -->\r\n<template>\r\n <RockFormField\r\n :modelValue=\"internalValue\"\r\n formGroupClasses=\"rock-number-box\"\r\n name=\"numberbox\"\r\n :rules=\"computedRules\">\r\n <template #default=\"{ uniqueId, field }\">\r\n <div class=\"control-wrapper\">\r\n <slot name=\"prepend\" />\r\n <div :class=\"controlContainerClass\">\r\n <slot name=\"inputGroupPrepend\" :isInputGroupSupported=\"true\" />\r\n <input\r\n v-model=\"internalValue\"\r\n :id=\"uniqueId\"\r\n type=\"number\"\r\n class=\"form-control\"\r\n :class=\"inputClasses\"\r\n v-bind=\"field\"\r\n :placeholder=\"placeholder\"\r\n :step=\"internalStep\"\r\n :min=\"minimumValue\"\r\n :max=\"maximumValue\" />\r\n <slot name=\"inputGroupAppend\" :isInputGroupSupported=\"true\" />\r\n </div>\r\n <slot name=\"append\" />\r\n </div>\r\n </template>\r\n </RockFormField>\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\n import { computed, PropType, ref, useSlots, watch } from \"vue\";\r\n import { normalizeRules, rulesPropType, ValidationRule } from \"@Obsidian/ValidationRules\";\r\n import { asFormattedString, toNumberOrNull } from \"@Obsidian/Utility/numberUtils\";\r\n import RockFormField from \"./rockFormField.obs\";\r\n\r\n const props = defineProps({\r\n modelValue: {\r\n type: Number as PropType<number | null>,\r\n default: null\r\n },\r\n placeholder: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n /** The minimum allowed value to be entered. */\r\n minimumValue: {\r\n type: Number as PropType<number | null>\r\n },\r\n maximumValue: {\r\n type: Number as PropType<number | null>\r\n },\r\n /** The number of decimal places allowed. */\r\n decimalCount: {\r\n type: Number as PropType<number | null>,\r\n default: null\r\n },\r\n inputClasses: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n inputGroupClasses: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n rules: rulesPropType\r\n });\r\n\r\n const emit = defineEmits<{\r\n (e: \"update:modelValue\", value: number | null): void;\r\n }>();\r\n\r\n const slots = useSlots();\r\n const internalValue = ref(asFormattedString(props.modelValue, props.decimalCount ?? undefined, { useGrouping: false }));\r\n\r\n const internalNumberValue = computed((): number | null => {\r\n return toNumberOrNull(internalValue.value);\r\n });\r\n\r\n const internalStep = computed((): string => {\r\n return props.decimalCount === null ? \"any\" : (1 / Math.pow(10, props.decimalCount)).toString();\r\n });\r\n\r\n const isInputGroup = computed((): boolean => {\r\n return !!slots.inputGroupPrepend || !!slots.inputGroupAppend;\r\n });\r\n\r\n const controlContainerClass = computed((): string => {\r\n return isInputGroup.value ? `input-group ${props.inputGroupClasses}` : \"\";\r\n });\r\n\r\n const computedRules = computed((): ValidationRule[] => {\r\n const rules = normalizeRules(props.rules);\r\n\r\n if (props.maximumValue !== null && props.maximumValue !== undefined) {\r\n rules.push(`lte:${props.maximumValue}`);\r\n }\r\n\r\n if (props.minimumValue !== null && props.minimumValue !== undefined) {\r\n rules.push(`gte:${props.minimumValue}`);\r\n }\r\n\r\n return rules;\r\n });\r\n\r\n watch(() => props.modelValue, () => {\r\n if (props.modelValue !== internalNumberValue.value) {\r\n internalValue.value = asFormattedString(props.modelValue, props.decimalCount ?? undefined, { useGrouping: false });\r\n }\r\n });\r\n\r\n watch(internalNumberValue, () => {\r\n emit(\"update:modelValue\", internalNumberValue.value);\r\n });\r\n</script>\r\n"],"names":["slots","useSlots","internalValue","ref","asFormattedString","props","modelValue","_props$decimalCount","decimalCount","undefined","useGrouping","internalNumberValue","computed","toNumberOrNull","value","internalStep","Math","pow","toString","isInputGroup","inputGroupPrepend","inputGroupAppend","controlContainerClass","concat","inputGroupClasses","computedRules","rules","normalizeRules","maximumValue","push","minimumValue","watch","_props$decimalCount2","emit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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