{"version":3,"file":"rockButton.obs.js","sources":["../../../Framework/Controls/rockButton.obs"],"sourcesContent":["<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License -->\r\n<template>\r\n    <button :class=\"cssClass\" :disabled=\"isButtonDisabled\" @click=\"onButtonClick\" :type=\"type\" :data-shortcut-key=\"shortcutKey\">\r\n        <template v-if=\"isButtonLoading\">\r\n            {{ loadingText }}\r\n        </template>\r\n        <slot v-else />\r\n    </button>\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\n    import { computed, PropType, ref } from \"vue\";\r\n    import { isPromise } from \"@Obsidian/Utility/promiseUtils\";\r\n    import { LiteralUnion } from \"@Obsidian/Types/Utility/support\";\r\n    import { BtnType } from \"@Obsidian/Enums/Controls/btnType\";\r\n    import { BtnSize } from \"@Obsidian/Enums/Controls/btnSize\";\r\n\r\n    const props = defineProps({\r\n        isLoading: {\r\n            type: Boolean as PropType<boolean>,\r\n            default: false\r\n        },\r\n        loadingText: {\r\n            type: String as PropType<string>,\r\n            default: \"Loading...\"\r\n        },\r\n        type: {\r\n            type: String as PropType<\"button\" | \"submit\" | \"reset\">,\r\n            default: \"button\"\r\n        },\r\n        disabled: {\r\n            type: Boolean as PropType<boolean>,\r\n            default: false\r\n        },\r\n        btnType: {\r\n            type: String as PropType<LiteralUnion<BtnType>>,\r\n            default: BtnType.Default\r\n        },\r\n        btnSize: {\r\n            type: String as PropType<BtnSize>,\r\n            default: BtnSize.Default\r\n        },\r\n        autoLoading: {\r\n            type: Boolean as PropType<boolean>,\r\n            default: false\r\n        },\r\n\r\n        /**\r\n         * Automatically disables the button when it is in a loading state or\r\n         * the click handler is processing. This can prevent duplicate clicks.\r\n         */\r\n        autoDisable: {\r\n            type: Boolean as PropType<boolean>,\r\n            default: false\r\n        },\r\n\r\n        onClick: {\r\n            type: Function as PropType<((event: MouseEvent) => void | PromiseLike<void>)>,\r\n            required: false\r\n        },\r\n\r\n        /** Change button proportions to make it a square. Used for buttons with only an icon. */\r\n        isSquare: {\r\n            type: Boolean as PropType<boolean>,\r\n            default: false\r\n        },\r\n\r\n        shortcutKey: {\r\n            type: String as PropType<string>,\r\n            default: \"\"\r\n        }\r\n    });\r\n\r\n    const isProcessing = ref(false);\r\n\r\n    const isButtonDisabled = computed((): boolean => {\r\n        return props.disabled || (props.autoDisable && isProcessing.value) || props.isLoading;\r\n    });\r\n\r\n    const isButtonLoading = computed((): boolean => {\r\n        return props.isLoading || (props.autoLoading && isProcessing.value);\r\n    });\r\n\r\n    const typeClass = computed((): string => {\r\n        return `btn-${props.btnType}`;\r\n    });\r\n\r\n    const sizeClass = computed((): string => {\r\n        if (!props.btnSize) {\r\n            return \"\";\r\n        }\r\n\r\n        return `btn-${props.btnSize}`;\r\n    });\r\n\r\n    const cssClass = computed((): string => {\r\n        return `btn ${typeClass.value} ${sizeClass.value} ${props.isSquare ? \"btn-square\" : \"\"}`;\r\n    });\r\n\r\n    const onButtonClick = async (event: MouseEvent): Promise<void> => {\r\n        if (isButtonDisabled.value || isButtonLoading.value) {\r\n            return;\r\n        }\r\n\r\n        isProcessing.value = true;\r\n\r\n        try {\r\n            const clickHandler = props.onClick;\r\n\r\n            if (clickHandler) {\r\n                const result = clickHandler(event);\r\n\r\n                if (isPromise(result)) {\r\n                    await result;\r\n                }\r\n            }\r\n        }\r\n        finally {\r\n            isProcessing.value = false;\r\n        }\r\n    };\r\n</script>\r\n"],"names":["isProcessing","ref","isButtonDisabled","computed","props","disabled","autoDisable","value","isLoading","isButtonLoading","autoLoading","typeClass","concat","btnType","sizeClass","btnSize","cssClass","isSquare","onButtonClick","_ref","_asyncToGenerator","event","clickHandler","onClick","result","isPromise","_x","apply","arguments"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAyEI,IAAA,IAAMA,YAAY,GAAGC,GAAG,CAAC,KAAK,CAAC,CAAA;M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