{"version":3,"file":"textFieldComponents.js","sources":["../../../Framework/FieldTypes/textFieldComponents.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, ref, watch } from \"vue\";\r\nimport { getFieldConfigurationProps, getFieldEditorProps } from \"./utils\";\r\nimport TextBox from \"@Obsidian/Controls/textBox.obs\";\r\nimport CheckBox from \"@Obsidian/Controls/checkBox.obs\";\r\nimport NumberBox from \"@Obsidian/Controls/numberBox.obs\";\r\nimport { asBoolean, asBooleanOrNull, asTrueFalseOrNull } from \"@Obsidian/Utility/booleanUtils\";\r\nimport { toNumberOrNull } from \"@Obsidian/Utility/numberUtils\";\r\n\r\n// We can't import the ConfigurationValueKey from textField.partial.ts\r\n// because it causes a recursive import back to this file by way of\r\n// the fieldType.ts import in textField.partial.ts.\r\nexport const enum ConfigurationValueKey {\r\n /** Contains \"True\" if the text field is designed for password entry. */\r\n IsPassword = \"ispassword\",\r\n\r\n /** The maximum number of characters allowed in the text entry field. */\r\n MaxCharacters = \"maxcharacters\",\r\n\r\n /** Contains \"True\" if the text field should show the character countdown. */\r\n ShowCountdown = \"showcountdown\"\r\n}\r\n\r\nexport const EditComponent = defineComponent({\r\n name: \"TextField.Edit\",\r\n\r\n components: {\r\n TextBox\r\n },\r\n\r\n props: getFieldEditorProps(),\r\n\r\n setup(props, { emit }) {\r\n // The internal value used by the text editor.\r\n const internalValue = ref(\"\");\r\n\r\n // Configuration attributes passed to the text editor.\r\n const configAttributes = computed((): Record => {\r\n const attributes: Record = {};\r\n\r\n const maxCharsConfig = props.configurationValues[ConfigurationValueKey.MaxCharacters];\r\n if (maxCharsConfig) {\r\n const maxCharsValue = Number(maxCharsConfig);\r\n\r\n if (maxCharsValue) {\r\n attributes.maxLength = maxCharsValue;\r\n }\r\n }\r\n\r\n const showCountDownConfig = props.configurationValues[ConfigurationValueKey.ShowCountdown];\r\n if (showCountDownConfig && showCountDownConfig) {\r\n const showCountDownValue = asBooleanOrNull(showCountDownConfig) || false;\r\n\r\n if (showCountDownValue) {\r\n attributes.showCountDown = showCountDownValue;\r\n }\r\n }\r\n\r\n return attributes;\r\n });\r\n\r\n // The type of text input field to use on the text editor.\r\n const textType = computed((): string => {\r\n const isPasswordConfig = props.configurationValues[ConfigurationValueKey.IsPassword];\r\n const isPassword = asBooleanOrNull(isPasswordConfig) ?? false;\r\n\r\n return isPassword ? \"password\" : \"\";\r\n\r\n });\r\n\r\n // Watch for changes from the parent component and update the text editor.\r\n watch(() => props.modelValue, () => {\r\n internalValue.value = props.modelValue;\r\n }, {\r\n immediate: true\r\n });\r\n\r\n // Watch for changes from the text editor and update the parent component.\r\n watch(internalValue, () => {\r\n emit(\"update:modelValue\", internalValue.value);\r\n });\r\n\r\n return {\r\n configAttributes,\r\n internalValue,\r\n textType\r\n };\r\n },\r\n\r\n template: `\r\n\r\n`\r\n});\r\n\r\nexport const ConfigurationComponent = defineComponent({\r\n name: \"TextField.Configuration\",\r\n\r\n components: {\r\n CheckBox,\r\n NumberBox\r\n },\r\n\r\n props: getFieldConfigurationProps(),\r\n\r\n emits: [\"update:modelValue\", \"updateConfiguration\", \"updateConfigurationValue\" ],\r\n\r\n setup(props, { emit }) {\r\n // Define the properties that will hold the current selections.\r\n const passwordField = ref(false);\r\n const maxCharacters = ref(null);\r\n const showCountdown = ref(false);\r\n\r\n /**\r\n * Update the modelValue property if any value of the dictionary has\r\n * actually changed. This helps prevent unwanted postbacks if the value\r\n * didn't really change - which can happen if multiple values get updated\r\n * at the same time.\r\n *\r\n * @returns true if a new modelValue was emitted to the parent component.\r\n */\r\n const maybeUpdateModelValue = (): boolean => {\r\n const newValue: Record = {};\r\n\r\n // Construct the new value that will be emitted if it is different\r\n // than the current value.\r\n newValue[ConfigurationValueKey.IsPassword] = asTrueFalseOrNull(passwordField.value) ?? \"False\";\r\n newValue[ConfigurationValueKey.MaxCharacters] = maxCharacters.value?.toString() ?? \"\";\r\n newValue[ConfigurationValueKey.ShowCountdown] = asTrueFalseOrNull(showCountdown.value) ?? \"False\";\r\n\r\n // Compare the new value and the old value.\r\n const anyValueChanged = newValue[ConfigurationValueKey.IsPassword] !== (props.modelValue[ConfigurationValueKey.IsPassword] ?? \"False\")\r\n || newValue[ConfigurationValueKey.MaxCharacters] !== (props.modelValue[ConfigurationValueKey.MaxCharacters] ?? \"\")\r\n || newValue[ConfigurationValueKey.ShowCountdown] !== (props.modelValue[ConfigurationValueKey.ShowCountdown] ?? \"False\");\r\n\r\n // If any value changed then emit the new model value.\r\n if (anyValueChanged) {\r\n emit(\"update:modelValue\", newValue);\r\n return true;\r\n }\r\n else {\r\n return false;\r\n }\r\n };\r\n\r\n /**\r\n * Emits the updateConfigurationValue if the value has actually changed.\r\n *\r\n * @param key The key that was possibly modified.\r\n * @param value The new value.\r\n */\r\n const maybeUpdateConfiguration = (key: string, value: string): void => {\r\n if (maybeUpdateModelValue()) {\r\n emit(\"updateConfigurationValue\", key, value);\r\n }\r\n };\r\n\r\n // Watch for changes coming in from the parent component and update our\r\n // data to match the new information.\r\n watch(() => [props.modelValue, props.configurationProperties], () => {\r\n passwordField.value = asBoolean(props.modelValue[ConfigurationValueKey.IsPassword]);\r\n maxCharacters.value = toNumberOrNull(props.modelValue[ConfigurationValueKey.MaxCharacters]);\r\n showCountdown.value = asBoolean(props.modelValue[ConfigurationValueKey.ShowCountdown]);\r\n }, {\r\n immediate: true\r\n });\r\n\r\n // Watch for changes in properties that require new configuration\r\n // properties to be retrieved from the server.\r\n // THIS IS JUST A PLACEHOLDER FOR COPYING TO NEW FIELDS THAT MIGHT NEED IT.\r\n // THIS FIELD DOES NOT NEED THIS\r\n watch([], () => {\r\n if (maybeUpdateModelValue()) {\r\n emit(\"updateConfiguration\");\r\n }\r\n });\r\n\r\n // Watch for changes in properties that only require a local UI update.\r\n watch(passwordField, () => maybeUpdateConfiguration(ConfigurationValueKey.IsPassword, asTrueFalseOrNull(passwordField.value) ?? \"False\"));\r\n watch(maxCharacters, () => maybeUpdateConfiguration(ConfigurationValueKey.MaxCharacters, maxCharacters.value?.toString() ?? \"\"));\r\n watch(showCountdown, () => maybeUpdateConfiguration(ConfigurationValueKey.ShowCountdown, asTrueFalseOrNull(showCountdown.value) ?? \"False\"));\r\n\r\n return {\r\n maxCharacters,\r\n passwordField,\r\n showCountdown\r\n };\r\n },\r\n\r\n template: `\r\n
\r\n \r\n \r\n \r\n
\r\n`\r\n});\r\n"],"names":["ConfigurationValueKey","EditComponent","defineComponent","name","components","TextBox","props","getFieldEditorProps","setup","_ref","emit","internalValue","ref","configAttributes","computed","attributes","maxCharsConfig","configurationValues","MaxCharacters","maxCharsValue","Number","maxLength","showCountDownConfig","ShowCountdown","showCountDownValue","asBooleanOrNull","showCountDown","textType","_asBooleanOrNull","isPasswordConfig","IsPassword","isPassword","watch","modelValue","value","immediate","template","ConfigurationComponent","CheckBox","NumberBox","getFieldConfigurationProps","emits","_ref2","passwordField","maxCharacters","showCountdown","maybeUpdateModelValue","_asTrueFalseOrNull","_maxCharacters$value$","_maxCharacters$value","_asTrueFalseOrNull2","_props$modelValue$Con","_props$modelValue$Con2","_props$modelValue$Con3","newValue","asTrueFalseOrNull","toString","anyValueChanged","maybeUpdateConfiguration","key","configurationProperties","asBoolean","toNumberOrNull","_asTrueFalseOrNull3","_maxCharacters$value$2","_maxCharacters$value2","_asTrueFalseOrNull4"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BkBA,gBAAAA,qBAAqB,8CAArBA,qBAAqB,EAAA;cAArBA,qBAAqB,CAAA,YAAA,CAAA,GAAA,YAAA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