{"version":3,"file":"useModelMigration-EhAWvqDD.mjs","sources":["../../src/composables/useModelMigration.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport Vue, { getCurrentInstance, computed } from 'vue'\n\n/**\n * Create model proxy to new v9 model (modelValue + update:modelValue) with a fallback to old model\n * @param {string} oldModelName - Name of model prop in nextcloud-vue v8\n * @param {string} oldModelEvent - Event name of model event in nextcloud-vue v8\n * @param {boolean} required - If the prop is required\n * @return {import('vue').WritableComputedRef} - model proxy\n */\nexport function useModelMigration(oldModelName, oldModelEvent, required = false) {\n\tconst vm = getCurrentInstance()!.proxy\n\n\tif (required && vm.$props[oldModelName] === undefined && vm.$props.modelValue === undefined) {\n\t\tVue.util.warn(`Missing required prop: \"modelValue\" or old \"${oldModelName}\"`)\n\t}\n\n\tconst model = computed({\n\t\tget() {\n\t\t\tif (vm.$props[oldModelName] !== undefined) {\n\t\t\t\treturn vm.$props[oldModelName]\n\t\t\t}\n\t\t\treturn vm.$props.modelValue\n\t\t},\n\n\t\tset(value) {\n\t\t\t// New nextcloud-vue v9 event\n\t\t\tvm.$emit('update:modelValue', value)\n\t\t\t// Vue 2 fallback for kebab-case event names in templates (recommended by Vue 3 style guide)\n\t\t\tvm.$emit('update:model-value', value)\n\t\t\t// Old nextcloud-vue v8 event\n\t\t\tvm.$emit(oldModelEvent, value)\n\t\t},\n\t})\n\n\treturn model\n}\n"],"names":[],"mappings":";AAcO,SAAS,kBAAkB,cAAc,eAAe,WAAW,OAAO;AAC1E,QAAA,KAAK,mBAAsB,EAAA;AAE7B,MAAA,YAAY,GAAG,OAAO,YAAY,MAAM,UAAa,GAAG,OAAO,eAAe,QAAW;AAC5F,QAAI,KAAK,KAAK,+CAA+C,YAAY,GAAG;AAAA,EAC7E;AAEA,QAAM,QAAQ,SAAS;AAAA,IACtB,MAAM;AACL,UAAI,GAAG,OAAO,YAAY,MAAM,QAAW;AACnC,eAAA,GAAG,OAAO,YAAY;AAAA,MAC9B;AACA,aAAO,GAAG,OAAO;AAAA,IAClB;AAAA,IAEA,IAAI,OAAO;AAEP,SAAA,MAAM,qBAAqB,KAAK;AAEhC,SAAA,MAAM,sBAAsB,KAAK;AAEjC,SAAA,MAAM,eAAe,KAAK;AAAA,IAC9B;AAAA,EAAA,CACA;AAEM,SAAA;AACR;"}