{"version":3,"file":"checkBoxList.js","sources":["../../../Framework/Controls/checkBoxList.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\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { computed, defineComponent, PropType, ref, watch } from \"vue\";\r\nimport { updateRefValue } from \"@Obsidian/Utility/component\";\r\nimport { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\r\nimport RockFormField from \"./rockFormField\";\r\nimport { defaultControlCompareValue } from \"@Obsidian/Utility/stringUtils\";\r\n\r\nexport default defineComponent({\r\n name: \"CheckBoxList\",\r\n\r\n components: {\r\n RockFormField\r\n },\r\n\r\n props: {\r\n modelValue: {\r\n type: Array as PropType,\r\n default: []\r\n },\r\n\r\n disabled: {\r\n type: Boolean as PropType,\r\n required: false,\r\n default: false\r\n },\r\n\r\n items: {\r\n type: Array as PropType>,\r\n required: true\r\n },\r\n\r\n repeatColumns: {\r\n type: Number as PropType,\r\n default: 0\r\n },\r\n\r\n horizontal: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n\r\n compareValue: {\r\n type: Function as PropType<((value: string, itemValue: string) => boolean)>,\r\n default: defaultControlCompareValue\r\n }\r\n },\r\n\r\n emits: {\r\n \"update:modelValue\": (_value: string[]) => true\r\n },\r\n\r\n setup(props, { emit }) {\r\n const internalValue = ref([...props.modelValue]);\r\n\r\n const valueForItem = (item: ListItemBag): string => item.value ?? \"\";\r\n const textForItem = (item: ListItemBag): string => item.text ?? \"\";\r\n\r\n const uniqueIdForItem = (uniqueId: Guid, item: ListItemBag): string => `${uniqueId}-${(item.value ?? \"\").replace(\" \", \"-\")}`;\r\n\r\n const containerClasses = computed(() => {\r\n const classes: string[] = [];\r\n\r\n if (props.horizontal) {\r\n classes.push(\"rockcheckboxlist-horizontal\");\r\n\r\n if (props.repeatColumns > 0) {\r\n classes.push(`in-columns in-columns-${props.repeatColumns}`);\r\n }\r\n }\r\n else {\r\n classes.push(\"rockcheckboxlist-vertical input-group\");\r\n }\r\n\r\n return classes.join(\" \");\r\n });\r\n\r\n const syncInternalValue = (): void => {\r\n let value = [...props.modelValue];\r\n\r\n // Ensure they are all valid values and make sure they are the\r\n // correct matching value from the item rather than what was\r\n // originally provided.\r\n value = props.items\r\n .filter(o => value.some(v => props.compareValue(v, o.value ?? \"\")))\r\n .map(o => o.value ?? \"\");\r\n\r\n updateRefValue(internalValue, value);\r\n };\r\n\r\n watch([() => props.modelValue, () => props.items], () => {\r\n syncInternalValue();\r\n });\r\n\r\n watch(internalValue, () => {\r\n emit(\"update:modelValue\", internalValue.value);\r\n });\r\n\r\n syncInternalValue();\r\n\r\n return {\r\n containerClasses,\r\n internalValue,\r\n textForItem,\r\n uniqueIdForItem,\r\n valueForItem\r\n };\r\n },\r\n\r\n template: `\r\n\r\n \r\n