{"version":3,"file":"textBox.obs.js","sources":["../../../Framework/Controls/textBox.obs"],"sourcesContent":["<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License -->\r\n<template>\r\n <RockFormField v-model=\"internalValue\"\r\n name=\"textbox\"\r\n v-bind=\"fieldProps\"\r\n :rules=\"augmentedRules\"\r\n :formGroupClasses=\"'rock-text-box ' + formGroupClasses\">\r\n <template #pre>\r\n <em v-if=\"showCountDown\" class=\"pull-right badge\" :class=\"countdownClass\">\r\n {{ charsRemaining }}\r\n </em>\r\n </template>\r\n <template #default=\"{ uniqueId, field }\">\r\n <div class=\"control-wrapper\">\r\n <slot name=\"prepend\" :isInputGroupSupported=\"true\" />\r\n <div :class=\"controlContainerClass\">\r\n <slot name=\"inputGroupPrepend\" :isInputGroupSupported=\"true\" />\r\n\r\n <textarea v-if=\"isTextarea\"\r\n :value=\"internalValue\"\r\n :rows=\"rows\"\r\n cols=\"20\"\r\n :maxlength=\"maxLength\"\r\n :id=\"uniqueId\"\r\n class=\"form-control\"\r\n v-bind=\"field\"\r\n @input=\"onInput\"\r\n @change=\"onChange\"></textarea>\r\n\r\n <input v-else :value=\"internalValue\"\r\n :id=\"uniqueId\"\r\n :type=\"type\"\r\n :class=\"formControlClass\"\r\n v-bind=\"field\"\r\n :maxlength=\"maxLength\"\r\n :placeholder=\"placeholder\"\r\n @input=\"onInput\"\r\n @change=\"onChange\" />\r\n <slot name=\"inputGroupAppend\" :isInputGroupSupported=\"true\" />\r\n </div>\r\n <slot name=\"append\" :isInputGroupSupported=\"true\" />\r\n </div>\r\n </template>\r\n </RockFormField>\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\n import { computed, ref, useSlots, watch } from \"vue\";\r\n import { PropType } from \"vue\";\r\n import RockFormField from \"./rockFormField.obs\";\r\n import { standardRockFormFieldProps, useStandardRockFormFieldProps } from \"@Obsidian/Utility/component\";\r\n import type { ValidationRule } from \"@Obsidian/Types/validationRules\";\r\n import { normalizeRules } from \"@Obsidian/ValidationRules\";\r\n\r\n const props = defineProps({\r\n modelValue: {\r\n type: String as PropType<string>,\r\n required: true\r\n },\r\n /** Internal use to track what modifier flags were applied to modelValue. */\r\n modelModifiers: {\r\n type: Object as PropType<Record<string, boolean>>,\r\n default: () => ({})\r\n },\r\n type: {\r\n type: String as PropType<string>,\r\n default: \"text\"\r\n },\r\n maxLength: {\r\n type: Number as PropType<number>,\r\n default: 524288\r\n },\r\n showCountDown: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n placeholder: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n inputClasses: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n rows: {\r\n type: Number as PropType<number>,\r\n default: 3\r\n },\r\n textMode: {\r\n type: String as PropType<string>,\r\n default: \"\"\r\n },\r\n size: {\r\n type: String as PropType<\"small\" | \"medium\" | \"large\">,\r\n default: \"medium\"\r\n },\r\n allowHtml: {\r\n type: Boolean as PropType<boolean>,\r\n default: false\r\n },\r\n ...standardRockFormFieldProps\r\n });\r\n\r\n const emit = defineEmits<{\r\n (e: \"update:modelValue\", value: string): void;\r\n }>();\r\n\r\n const slots = useSlots();\r\n\r\n const internalValue = ref(props.modelValue);\r\n const fieldProps = useStandardRockFormFieldProps(props);\r\n\r\n const isTextarea = computed((): boolean => {\r\n return props.textMode?.toLowerCase() === \"multiline\";\r\n });\r\n\r\n const charsRemaining = computed((): number => {\r\n return props.maxLength - internalValue.value.length;\r\n });\r\n\r\n const countdownClass = computed((): string => {\r\n if (charsRemaining.value >= 10) {\r\n return \"badge-default\";\r\n }\r\n\r\n if (charsRemaining.value >= 0) {\r\n return \"badge-warning\";\r\n }\r\n\r\n return \"badge-danger\";\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((): Record<string, boolean> => {\r\n return {\r\n \"input-group col-xs-12\": isInputGroup.value,\r\n \"input-group-sm\": isInputGroup.value && props.size == \"small\",\r\n \"input-group-lg\": isInputGroup.value && props.size == \"large\"\r\n };\r\n });\r\n\r\n const formControlClass = computed((): Record<string, boolean> => {\r\n return {\r\n \"form-control\": true,\r\n [props.inputClasses]: true,\r\n \"input-sm\": props.size == \"small\",\r\n \"input-lg\": props.size == \"large\"\r\n };\r\n });\r\n\r\n const augmentedRules = computed((): ValidationRule[] => {\r\n const rules = normalizeRules(props.rules);\r\n\r\n if (!props.allowHtml) {\r\n rules.push(\"nohtml\");\r\n }\r\n\r\n return rules;\r\n });\r\n\r\n /**\r\n * Event handler for the input field having any modification to the value\r\n * happen. This is basically called on every key press.\r\n *\r\n * @param e The object that describes the event.\r\n */\r\n function onInput(e: Event): void {\r\n if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {\r\n internalValue.value = e.target.value;\r\n }\r\n\r\n // Lazy models do not get every single key press.\r\n if (!props.modelModifiers.lazy) {\r\n emit(\"update:modelValue\", internalValue.value);\r\n }\r\n }\r\n\r\n /**\r\n * Event handler for the input field when the changed value is \"committed\".\r\n * This is basically called when the focus leaves the input field.\r\n *\r\n * @param e The object that describes the event.\r\n */\r\n function onChange(e: Event): void {\r\n if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {\r\n internalValue.value = e.target.value;\r\n }\r\n\r\n // Only send the update if we didn't send it in the onInput handler.\r\n if (props.modelModifiers.lazy) {\r\n emit(\"update:modelValue\", internalValue.value);\r\n }\r\n }\r\n\r\n watch(() => props.modelValue, () => {\r\n internalValue.value = props.modelValue;\r\n });\r\n</script>\r\n"],"names":["slots","useSlots","internalValue","ref","props","modelValue","fieldProps","useStandardRockFormFieldProps","isTextarea","computed","_props$textMode","textMode","toLowerCase","charsRemaining","maxLength","value","length","countdownClass","isInputGroup","inputGroupPrepend","inputGroupAppend","controlContainerClass","size","formControlClass","inputClasses","augmentedRules","rules","normalizeRules","allowHtml","push","onInput","e","target","HTMLInputElement","HTMLTextAreaElement","modelModifi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