{"version":3,"file":"numberBox.js","sources":["../../../Framework/Controls/numberBox.ts"],"sourcesContent":["// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport { computed, defineComponent, PropType, ref, watch } from \"vue\";\r\nimport { normalizeRules, rulesPropType, ValidationRule } from \"@Obsidian/ValidationRules\";\r\nimport { asFormattedString, toNumberOrNull } from \"@Obsidian/Utility/numberUtils\";\r\nimport RockFormField from \"./rockFormField\";\r\n\r\nexport default defineComponent({\r\n name: \"NumberBox\",\r\n\r\n components: {\r\n RockFormField\r\n },\r\n\r\n props: {\r\n modelValue: {\r\n type: Number as PropType,\r\n default: null\r\n },\r\n placeholder: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n /** The minimum allowed value to be entered. */\r\n minimumValue: {\r\n type: Number as PropType\r\n },\r\n maximumValue: {\r\n type: Number as PropType\r\n },\r\n /** The number of decimal places allowed. */\r\n decimalCount: {\r\n type: Number as PropType,\r\n default: null\r\n },\r\n inputClasses: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n inputGroupClasses: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n rules: rulesPropType\r\n },\r\n\r\n emits: {\r\n \"update:modelValue\": (_value: number | null) => true\r\n },\r\n\r\n setup(props, ctx) {\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 !!ctx.slots.inputGroupPrepend || !!ctx.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 ctx.emit(\"update:modelValue\", internalNumberValue.value);\r\n });\r\n\r\n return {\r\n computedRules,\r\n controlContainerClass,\r\n internalStep,\r\n internalValue\r\n };\r\n },\r\n\r\n template: `\r\n\r\n \r\n`\r\n});\r\n"],"names":["defineComponent","name","components","RockFormField","props","modelValue","type","Number","default","placeholder","String","minimumValue","maximumValue","decimalCount","inputClasses","inputGroupClasses","rules","rulesPropType","emits","_value","setup","ctx","_props$decimalCount","internalValue","ref","asFormattedString","undefined","useGrouping","internalNumberValue","computed","toNumberOrNull","value","internalStep","Math","pow","toString","isInputGroup","slots","inputGroupPrepend","inputGroupAppend","controlContainerClass","concat","computedRules","normalizeRules","push","watch","_props$decimalCount2","emit","template"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,+CAAeA,eAAe,CAAC;YAC3BC,EAAAA,IAAI,EAAE,WAAW;YAEjBC,EAAAA,UAAU,EAAE;YACRC,IAAAA,aAAAA;eACH;YAEDC,EAAAA,KAAK,EAAE;YACHC,IAAAA,UAAU,EAAE;YACRC,MAAAA,I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