{"version":3,"file":"utils.js","sources":["../../../Framework/FieldTypes/utils.ts"],"sourcesContent":["// \n// Copyright by the Spark Development Network\n//\n// Licensed under the Rock Community License (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.rockrms.com/license\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// \n//\n\nimport { Component, computed, defineComponent, PropType, ref, watch } from \"vue\";\nimport { binaryComparisonTypes, containsComparisonTypes, isCompareVisibleForComparisonFilter, isSingleComparisonType, stringComparisonTypes } from \"@Obsidian/Core/Reporting/comparisonType\";\nimport { getFilteredComparisonTypeOptions } from \"@Obsidian/Core/Reporting/comparisonTypeOptions\";\nimport { ComparisonValue } from \"@Obsidian/Types/Reporting/comparisonValue\";\nimport { ComparisonType } from \"@Obsidian/Enums/Reporting/comparisonType\";\nimport { FilterMode } from \"@Obsidian/Core/Reporting/filterMode\";\nimport DropDownList from \"@Obsidian/Controls/dropDownList.obs\";\nimport FieldFilterContainer from \"@Obsidian/Controls/fieldFilterContainer.obs\";\nimport { toNumberOrNull } from \"@Obsidian/Utility/numberUtils\";\nimport { DataEntryMode } from \"@Obsidian/Utility/fieldTypes\";\nimport { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\n\nexport type ConfigurationValues = Record;\n\n/**\n * The basic properties that all field editor components must support.\n */\ntype FieldEditorBaseProps = {\n modelValue: {\n type: PropType,\n required: true\n };\n\n configurationValues: {\n type: PropType;\n default: () => ConfigurationValues;\n };\n\n /**\n * This is used internally by the fieldTypeEditor to allow controls to make adjustments based\n * on how it's being used (e.g. to define a default value vs to edit a value)\n */\n dataEntryMode: {\n type: PropType;\n };\n};\n\n/**\n * The basic properties that all field configuration components must support.\n */\ntype FieldConfigurationBaseProps = {\n modelValue: {\n type: PropType>,\n required: true\n };\n\n configurationProperties: {\n type: PropType>,\n required: true\n };\n};\n\n/**\n * Get the standard properties that all field editor components must support.\n */\nexport function getFieldEditorProps(): FieldEditorBaseProps {\n return {\n modelValue: {\n type: String as PropType,\n required: true\n },\n\n configurationValues: {\n type: Object as PropType,\n default: () => ({})\n },\n\n dataEntryMode: {\n type: String as PropType\n }\n };\n}\n\n/**\n * The properties that all field filter components must support.\n */\ntype FieldFilterProps = {\n modelValue: {\n type: PropType,\n required: true\n },\n\n configurationValues: {\n type: PropType,\n required: true\n },\n\n filterMode: {\n type: PropType,\n required: true\n },\n\n required: {\n type: PropType,\n required: true\n }\n};\n\n/**\n * The properties that all field filter components must support.\n */\nexport const fieldFilterProps: FieldFilterProps = {\n modelValue: {\n type: Object as PropType,\n required: true\n },\n\n configurationValues: {\n type: Object as PropType,\n required: true\n },\n\n filterMode: {\n type: Number as PropType,\n required: true\n },\n\n required: {\n type: Boolean as PropType,\n required: true\n }\n};\n\n/**\n * Gets the standard field configuration properties that all field configuration\n * components must support.\n */\nexport function getFieldConfigurationProps(): FieldConfigurationBaseProps {\n return {\n modelValue: {\n type: Object as PropType>,\n required: true\n },\n configurationProperties: {\n type: Object as PropType>,\n required: true\n }\n };\n}\n\n/**\n * Allows callers to modify the names of the comparison type options. The values\n * and the array itself should not be modified.\n */\nexport type UpdateComparisonTypeNamesCallback = (comparisonTypeOptions: ListItemBag[]) => void;\n\n/**\n * Options that can be passed to the getStandardFilterComponent method which\n * will alter it's default behavior.\n */\nexport type StandardFilterComponentOptions = {\n updateComparisonTypeNames?: UpdateComparisonTypeNamesCallback;\n};\n\n/**\n * Gets a standard filter component that uses a constant string in place of the\n * comparison type picker. This component will always emit a ComparisonValue\n * with a null type.\n *\n * @param compareLabel The string to display in place of a comparison picker.\n * @param valueComponent The component that will handle editing the value.\n *\n * @returns A component that will handle editing a filter value.\n */\nexport function getStandardFilterComponent(compareLabel: string, valueComponent: Component, options?: StandardFilterComponentOptions): Component;\n\n/**\n * Gets a standard filter component that uses a picker to let the individual\n * select the comparison type to perform. If a single comparison type bit is\n * set then the picker will be hidden. If null is used for the comparison types\n * then no picker component will be shown and null will be emitted for the\n * type property.\n *\n * @param comparisonTypes One or more comparison types the user can select from.\n * @param valueComponent The component that will handle editing the value.\n *\n * @returns A component that will handle editing a filter value.\n */\nexport function getStandardFilterComponent(comparisonTypes: ComparisonType | null, valueComponent: Component, options?: StandardFilterComponentOptions): Component;\n\n/**\n * Gets a standard filter component that can be used by field types to generate\n * their filter component without having to write one from scratch.\n *\n * @param comparisonLabelOrTypes The comparison label or the comparison types that will be shown.\n * @param valueComponent The component that will handle value entry from the individual.\n *\n * @returns A component that will handle editing a filter value.\n */\nexport function getStandardFilterComponent(comparisonLabelOrTypes: ComparisonType | string | null, valueComponent: Component, options?: StandardFilterComponentOptions): Component {\n const comparisonTypes: ComparisonType | null = typeof comparisonLabelOrTypes === \"number\" ? comparisonLabelOrTypes : null;\n const compareLabel: string = typeof comparisonLabelOrTypes === \"string\" ? comparisonLabelOrTypes : \"\";\n\n let comparisonTypeOptions = comparisonTypes !== null ? getFilteredComparisonTypeOptions(comparisonTypes) : [];\n\n if (options?.updateComparisonTypeNames) {\n // Create a new array with new objects so we don't modify the core\n // set for every component on the page.\n comparisonTypeOptions = comparisonTypeOptions.map(o => {\n return {\n value: o.value,\n text: o.text\n };\n });\n\n options.updateComparisonTypeNames(comparisonTypeOptions);\n }\n\n return defineComponent({\n name: \"StandardFilterComponent\",\n\n components: {\n DropDownList,\n FieldFilterContainer,\n ValueComponent: valueComponent\n },\n\n props: fieldFilterProps,\n\n emits: [\n \"update:modelValue\"\n ],\n\n setup(props, { emit }) {\n /** The comparison type currently selected in the UI. */\n const internalComparisonType = ref(props.modelValue.comparisonType?.toString() ?? \"\");\n const comparisonType = ref(props.modelValue.comparisonType ?? null);\n\n /** The comparison value currently entered in the UI. */\n const internalComparisonValue = ref(props.modelValue.value);\n\n /** True if the compare component should be visible. */\n const hasCompareComponent = computed(() => {\n return comparisonTypes !== null\n && props.filterMode !== FilterMode.Simple\n && !isSingleComparisonType(comparisonTypes)\n && isCompareVisibleForComparisonFilter(comparisonTypes, props.filterMode);\n });\n\n /** True if the value component should be visible. */\n const hasValueComponent = computed((): boolean => {\n return internalComparisonType.value !== ComparisonType.IsBlank.toString()\n && internalComparisonType.value !== ComparisonType.IsNotBlank.toString();\n });\n\n /** True if the comparison type is optional. */\n const isTypeOptional = computed(() => !props.required);\n\n /**\n * Constructs the new value and emits it if it has changed from\n * the current modelValue.\n */\n const emitValueIfChanged = (): void => {\n let type: ComparisonType | null | undefined;\n\n // Determine the comparison type.\n if (compareLabel || comparisonTypes === null) {\n // No comparison type to be selected.\n type = null;\n }\n else if (isSingleComparisonType(comparisonTypes)) {\n // Only a single comparison type, so it is forced.\n type = comparisonTypes;\n }\n else {\n // If the filter mode is simple, then the comparison type is\n // not shown so we come up with a sane default.\n if (props.filterMode === FilterMode.Simple) {\n if (comparisonTypes === binaryComparisonTypes) {\n type = ComparisonType.EqualTo;\n }\n else if (comparisonTypes === stringComparisonTypes || comparisonTypes === containsComparisonTypes) {\n type = ComparisonType.Contains;\n }\n else {\n type = null;\n }\n }\n else {\n // Get the comparison type selected by the user if we are\n // in advanced mode.\n type = toNumberOrNull(internalComparisonType.value);\n }\n }\n\n comparisonType.value = type;\n\n // Construct the new value to be emitted.\n const newValue: ComparisonValue = {\n comparisonType: type,\n value: internalComparisonValue.value\n };\n\n // Check if it has changed from the original value.\n if (newValue.comparisonType !== props.modelValue.comparisonType || newValue.value !== props.modelValue.value) {\n emit(\"update:modelValue\", newValue);\n }\n };\n\n // Watch for changes in our modelValue and update our internal\n // values to match.\n watch(() => props.modelValue, () => {\n internalComparisonType.value = props.modelValue.comparisonType?.toString() ?? \"\";\n comparisonType.value = props.modelValue.comparisonType ?? null;\n internalComparisonValue.value = props.modelValue.value;\n });\n\n // Watch for changes in our internal values and update the modelValue.\n watch([internalComparisonType, internalComparisonValue], () => {\n emitValueIfChanged();\n });\n\n // This is primarily here to sync up state with default values.\n emitValueIfChanged();\n\n return {\n compareLabel,\n comparisonType,\n comparisonTypeOptions,\n hasCompareComponent,\n hasValueComponent,\n internalComparisonType,\n internalComparisonValue,\n isTypeOptional\n };\n },\n\n template: `\n\n \n\n \n\n`\n });\n}\n\n"],"names":["getFieldEditorProps","modelValue","type","String","required","configurationValues","Object","default","dataEntryMode","fieldFilterProps","filterMode","Number","Boolean","getFieldConfigurationProps","configurationProperties","getStandardFilterComponent","comparisonLabelOrTypes","valueComponent","options","comparisonTypes","compareLabel","comparisonTypeOptions","getFilteredComparisonTypeOptions","updateComparisonTypeNames","map","o","value","text","defineComponent","name","components","DropDownList","FieldFilterContainer","ValueComponent","props","emits","setup","_ref","_props$modelValue$com","_props$modelValue$com2","_props$modelValue$com3","emit","internalComparisonType","ref","comparisonType","toString","internalComparisonValue","hasCompareComponent","computed","FilterMode","Simple","isSingleComparisonType","isCompareVisibleForComparisonFilter","hasValueComponent","ComparisonType","IsBlank","IsNotBlank","isTypeOptional","emitValueIfChanged","binaryComparisonTypes","EqualTo","stringComparisonTypes","containsComparisonTypes","Contains","toNumberOrNull","newValue","watch","_props$modelValue$com4","_props$modelValue$com5","_props$modelValue$com6","template"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwEO,SAASA,mBAAmBA,GAAyB;cACxD,OAAO;YACHC,IAAAA,UAAU,EAAE;YACRC,MAAAA,IAAI,EAAEC,MAA0B;YAChCC,MAAAA,QAAQ,EAAE,IAAA;iBACb;YAEDC,IAAAA,mBAAmB,EAAE;YACjBH,MAAAA,IAAI,EAAEI,MAAuC;YAC7CC,MAAAA,OAAO,EAAEA,OAAO,EAAE,CAAA;iBACrB;YAEDC,IAAAA,aAAa,EAAE;YACXN,MAAAA,IAAI,EAAEC,MAAAA;YACV,KAAA;eACH,CAAA;YACL,CAAA;AA8BO,gBAAMM,gBAAkC,+BAAG;YAC9CR,EAAAA,UAAU,EAAE;YACRC,IAAAA,IAAI,E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