版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

useFocusTrap.iife.js 5.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
  2. if (VueDemi.install) {
  3. return VueDemi
  4. }
  5. if (!Vue) {
  6. console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
  7. return VueDemi
  8. }
  9. // Vue 2.7
  10. if (Vue.version.slice(0, 4) === '2.7.') {
  11. for (var key in Vue) {
  12. VueDemi[key] = Vue[key]
  13. }
  14. VueDemi.isVue2 = true
  15. VueDemi.isVue3 = false
  16. VueDemi.install = function () {}
  17. VueDemi.Vue = Vue
  18. VueDemi.Vue2 = Vue
  19. VueDemi.version = Vue.version
  20. VueDemi.warn = Vue.util.warn
  21. function createApp(rootComponent, rootProps) {
  22. var vm
  23. var provide = {}
  24. var app = {
  25. config: Vue.config,
  26. use: Vue.use.bind(Vue),
  27. mixin: Vue.mixin.bind(Vue),
  28. component: Vue.component.bind(Vue),
  29. provide: function (key, value) {
  30. provide[key] = value
  31. return this
  32. },
  33. directive: function (name, dir) {
  34. if (dir) {
  35. Vue.directive(name, dir)
  36. return app
  37. } else {
  38. return Vue.directive(name)
  39. }
  40. },
  41. mount: function (el, hydrating) {
  42. if (!vm) {
  43. vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
  44. vm.$mount(el, hydrating)
  45. return vm
  46. } else {
  47. return vm
  48. }
  49. },
  50. unmount: function () {
  51. if (vm) {
  52. vm.$destroy()
  53. vm = undefined
  54. }
  55. },
  56. }
  57. return app
  58. }
  59. VueDemi.createApp = createApp
  60. }
  61. // Vue 2.6.x
  62. else if (Vue.version.slice(0, 2) === '2.') {
  63. if (VueCompositionAPI) {
  64. for (var key in VueCompositionAPI) {
  65. VueDemi[key] = VueCompositionAPI[key]
  66. }
  67. VueDemi.isVue2 = true
  68. VueDemi.isVue3 = false
  69. VueDemi.install = function () {}
  70. VueDemi.Vue = Vue
  71. VueDemi.Vue2 = Vue
  72. VueDemi.version = Vue.version
  73. } else {
  74. console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
  75. }
  76. }
  77. // Vue 3
  78. else if (Vue.version.slice(0, 2) === '3.') {
  79. for (var key in Vue) {
  80. VueDemi[key] = Vue[key]
  81. }
  82. VueDemi.isVue2 = false
  83. VueDemi.isVue3 = true
  84. VueDemi.install = function () {}
  85. VueDemi.Vue = Vue
  86. VueDemi.Vue2 = undefined
  87. VueDemi.version = Vue.version
  88. VueDemi.set = function (target, key, val) {
  89. if (Array.isArray(target)) {
  90. target.length = Math.max(target.length, key)
  91. target.splice(key, 1, val)
  92. return val
  93. }
  94. target[key] = val
  95. return val
  96. }
  97. VueDemi.del = function (target, key) {
  98. if (Array.isArray(target)) {
  99. target.splice(key, 1)
  100. return
  101. }
  102. delete target[key]
  103. }
  104. } else {
  105. console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
  106. }
  107. return VueDemi
  108. })(
  109. (this.VueDemi = this.VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
  110. this.Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
  111. this.VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
  112. );
  113. ;
  114. ;(function (exports, core, vueDemi, focusTrap) {
  115. 'use strict';
  116. var __defProp = Object.defineProperty;
  117. var __defProps = Object.defineProperties;
  118. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  119. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  120. var __hasOwnProp = Object.prototype.hasOwnProperty;
  121. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  122. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  123. var __spreadValues = (a, b) => {
  124. for (var prop in b || (b = {}))
  125. if (__hasOwnProp.call(b, prop))
  126. __defNormalProp(a, prop, b[prop]);
  127. if (__getOwnPropSymbols)
  128. for (var prop of __getOwnPropSymbols(b)) {
  129. if (__propIsEnum.call(b, prop))
  130. __defNormalProp(a, prop, b[prop]);
  131. }
  132. return a;
  133. };
  134. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  135. var __objRest = (source, exclude) => {
  136. var target = {};
  137. for (var prop in source)
  138. if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
  139. target[prop] = source[prop];
  140. if (source != null && __getOwnPropSymbols)
  141. for (var prop of __getOwnPropSymbols(source)) {
  142. if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
  143. target[prop] = source[prop];
  144. }
  145. return target;
  146. };
  147. function useFocusTrap(target, options = {}) {
  148. let trap;
  149. const _a = options, { immediate } = _a, focusTrapOptions = __objRest(_a, ["immediate"]);
  150. const hasFocus = vueDemi.ref(false);
  151. const isPaused = vueDemi.ref(false);
  152. const activate = (opts) => trap && trap.activate(opts);
  153. const deactivate = (opts) => trap && trap.deactivate(opts);
  154. const pause = () => {
  155. if (trap) {
  156. trap.pause();
  157. isPaused.value = true;
  158. }
  159. };
  160. const unpause = () => {
  161. if (trap) {
  162. trap.unpause();
  163. isPaused.value = false;
  164. }
  165. };
  166. vueDemi.watch(() => core.unrefElement(target), (el) => {
  167. if (!el)
  168. return;
  169. trap = focusTrap.createFocusTrap(el, __spreadProps(__spreadValues({}, focusTrapOptions), {
  170. onActivate() {
  171. hasFocus.value = true;
  172. if (options.onActivate)
  173. options.onActivate();
  174. },
  175. onDeactivate() {
  176. hasFocus.value = false;
  177. if (options.onDeactivate)
  178. options.onDeactivate();
  179. }
  180. }));
  181. if (immediate)
  182. activate();
  183. }, { flush: "post" });
  184. core.tryOnScopeDispose(() => deactivate());
  185. return {
  186. hasFocus,
  187. isPaused,
  188. activate,
  189. deactivate,
  190. pause,
  191. unpause
  192. };
  193. }
  194. exports.useFocusTrap = useFocusTrap;
  195. })(this.VueUse = this.VueUse || {}, VueUse, VueDemi, focusTrap);