UNPKG

@nextcloud/vue

Version:
1 lines 1.5 kB
{"version":3,"file":"useTrapStackControl-B6cEicto.mjs","sources":["../../src/composables/useTrapStackControl.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { MaybeRefOrGetter, Ref } from 'vue'\n\nimport { onUnmounted, toValue, watch } from 'vue'\nimport { createTrapStackController } from '../utils/focusTrap.ts'\n\n/**\n * Control global focus trap stack when focus trap is managed manually\n *\n * @param shouldPause - Whether focus trap should be paused\n * @param options - Additional options\n * @param options.disabled - Whether the controller should be disabled\n */\nexport function useTrapStackControl(shouldPause: Ref<boolean> | (() => boolean), options: { disabled?: MaybeRefOrGetter<boolean> } = {}) {\n\tconst trapStackController = createTrapStackController()\n\n\twatch(shouldPause, () => {\n\t\tif (toValue(options.disabled)) {\n\t\t\treturn\n\t\t}\n\n\t\tif (toValue(shouldPause)) {\n\t\t\ttrapStackController.pause()\n\t\t} else {\n\t\t\ttrapStackController.unpause()\n\t\t}\n\t})\n\n\tonUnmounted(() => {\n\t\ttrapStackController.unpause()\n\t})\n}\n"],"names":[],"mappings":";;AAiBO,SAAS,oBAAoB,aAA6C,UAAoD,IAAI;AACxI,QAAM,sBAAsB,0BAAA;AAE5B,QAAM,aAAa,MAAM;AACxB,QAAI,QAAQ,QAAQ,QAAQ,GAAG;AAC9B;AAAA,IACD;AAEA,QAAI,QAAQ,WAAW,GAAG;AACzB,0BAAoB,MAAA;AAAA,IACrB,OAAO;AACN,0BAAoB,QAAA;AAAA,IACrB;AAAA,EACD,CAAC;AAED,cAAY,MAAM;AACjB,wBAAoB,QAAA;AAAA,EACrB,CAAC;AACF;"}