@v-c/image 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
+ import { useMergedState } from "./util/dist/hooks/useMergedState.js";
2
+ import { pickAttrs } from "./util/dist/pickAttrs.js";
3
+ import { getAttrStyleAndClass, getStylePxValue } from "./util/dist/props-util/index.js";
1
4
  import { COMMON_PROPS } from "./common.js";
2
5
  import { usePreviewGroupContext } from "./context.js";
3
- import { useMergedState } from "../../util/dist/hooks/useMergedState.js";
4
- import { pickAttrs } from "../../util/dist/pickAttrs.js";
5
- import { getAttrStyleAndClass, getStylePxValue } from "../../util/dist/props-util/index.js";
6
6
  import useRegisterImage from "./hooks/useRegisterImage.js";
7
7
  import useStatus from "./hooks/useStatus.js";
8
8
  import Preview_default from "./Preview/index.js";
@@ -1,9 +1,9 @@
1
1
  import { usePreviewGroupContext } from "../context.js";
2
2
  import useStatus from "../hooks/useStatus.js";
3
- import { canUseDom } from "../../../util/dist/Dom/canUseDom.js";
4
- import { useLockFocus } from "../../../util/dist/Dom/focus.js";
5
- import { KeyCodeStr } from "../../../util/dist/KeyCode.js";
6
- import { getTransitionProps } from "../../../util/dist/utils/transition.js";
3
+ import { canUseDom } from "../util/dist/Dom/canUseDom.js";
4
+ import { useLockFocus } from "../util/dist/Dom/focus.js";
5
+ import { KeyCodeStr } from "../util/dist/KeyCode.js";
6
+ import { getTransitionProps } from "../util/dist/utils/transition.js";
7
7
  import useImageTransform from "../hooks/useImageTransform.js";
8
8
  import { BASE_SCALE_RATIO } from "../previewConfig.js";
9
9
  import useMouseEvent from "../hooks/useMouseEvent.js";
@@ -1,5 +1,5 @@
1
+ import { useMergedState } from "./util/dist/hooks/useMergedState.js";
1
2
  import { usePreviewGroupProvider } from "./context.js";
2
- import { useMergedState } from "../../util/dist/hooks/useMergedState.js";
3
3
  import Preview_default from "./Preview/index.js";
4
4
  import usePreviewItems from "./hooks/usePreviewItems.js";
5
5
  import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, toRef, watch } from "vue";
@@ -1,6 +1,6 @@
1
1
  import { getClientSize } from "../util.js";
2
- import { isEqual_default } from "../../../util/dist/isEqual.js";
3
- import { raf_default } from "../../../util/dist/raf.js";
2
+ import { isEqual_default } from "../util/dist/isEqual.js";
3
+ import { raf_default } from "../util/dist/raf.js";
4
4
  import { ref, shallowRef } from "vue";
5
5
  var initialTransform = {
6
6
  x: 0,
@@ -1,5 +1,5 @@
1
+ import { canUseDom } from "../util/dist/Dom/canUseDom.js";
1
2
  import getFixScaleEleTransPosition from "../getFixScaleEleTransPosition.js";
2
- import { canUseDom } from "../../../util/dist/Dom/canUseDom.js";
3
3
  import { BASE_SCALE_RATIO, WHEEL_MAX_SCALE_RATIO } from "../previewConfig.js";
4
4
  import { shallowRef, watch } from "vue";
5
5
  import { warning } from "@v-c/util";
@@ -1,5 +1,5 @@
1
+ import { canUseDom } from "../util/dist/Dom/canUseDom.js";
1
2
  import getFixScaleEleTransPosition from "../getFixScaleEleTransPosition.js";
2
- import { canUseDom } from "../../../util/dist/Dom/canUseDom.js";
3
3
  import { shallowRef, watchEffect } from "vue";
4
4
  function getDistance(a, b) {
5
5
  const x = a.x - b.x;
@@ -0,0 +1,20 @@
1
+ import { canUseDom } from "./canUseDom.js";
2
+ import { unref } from "vue";
3
+ function isDOM(node) {
4
+ return node instanceof HTMLElement || node instanceof SVGElement;
5
+ }
6
+ function getDOM(elementRef) {
7
+ const unrefElementRef = unref(elementRef);
8
+ if (!canUseDom()) return unrefElementRef;
9
+ const dom = findDOMNode(unrefElementRef) || (unrefElementRef && typeof unrefElementRef === "object" ? findDOMNode(unrefElementRef.nativeElement) : null);
10
+ if (dom && (dom.nodeType === 3 || dom.nodeType === 8) && dom.nextElementSibling) return dom.nextElementSibling;
11
+ return dom;
12
+ }
13
+ function findDOMNode(_node) {
14
+ const node = unref(_node);
15
+ if (!canUseDom()) return node;
16
+ if (isDOM(node)) return node;
17
+ else if (node && "$el" in node) return node.$el;
18
+ return null;
19
+ }
20
+ export { getDOM };
@@ -1,3 +1,5 @@
1
+ import { useId_default } from "../hooks/useId.js";
2
+ import { getDOM } from "./findDOMNode.js";
1
3
  import { isVisible_default } from "./isVisible.js";
2
4
  import { watch } from "vue";
3
5
  function focusable(node, includePositive = false) {
@@ -28,9 +30,31 @@ function getFocusNodeList(node, includePositive = false) {
28
30
  }
29
31
  var lastFocusElement = null;
30
32
  var focusElements = [];
33
+ var idToElementMap = /* @__PURE__ */ new Map();
34
+ var ignoredElementMap = /* @__PURE__ */ new Map();
35
+ var allowedElementMap = /* @__PURE__ */ new Map();
31
36
  function getLastElement() {
32
37
  return focusElements[focusElements.length - 1];
33
38
  }
39
+ function getLastLockId() {
40
+ const lastElement = getLastElement();
41
+ if (!lastElement) return void 0;
42
+ for (const [id, ele] of idToElementMap.entries()) if (ele === lastElement) return id;
43
+ }
44
+ function isIgnoredElement(element) {
45
+ const lockId = getLastLockId();
46
+ if (!lockId || !element) return false;
47
+ const ignoredEle = ignoredElementMap.get(lockId);
48
+ return !!ignoredEle && (ignoredEle === element || ignoredEle.contains(element));
49
+ }
50
+ function isAllowedElement(element) {
51
+ const lockId = getLastLockId();
52
+ if (!lockId || !element) return false;
53
+ const allowedElements = allowedElementMap.get(lockId);
54
+ if (!allowedElements?.size) return false;
55
+ for (const allowedElement of allowedElements) if (allowedElement === element || allowedElement.contains(element)) return true;
56
+ return false;
57
+ }
34
58
  function hasFocus(element) {
35
59
  const { activeElement } = document;
36
60
  return element === activeElement || element.contains(activeElement);
@@ -38,9 +62,10 @@ function hasFocus(element) {
38
62
  function syncFocus() {
39
63
  const lastElement = getLastElement();
40
64
  const { activeElement } = document;
65
+ if (isIgnoredElement(activeElement) || isAllowedElement(activeElement)) return;
41
66
  if (lastElement && !hasFocus(lastElement)) {
42
67
  const focusableList = getFocusNodeList(lastElement);
43
- (focusableList.includes(lastFocusElement) ? lastFocusElement : focusableList[0])?.focus();
68
+ (focusableList.includes(lastFocusElement) ? lastFocusElement : focusableList[0])?.focus({ preventScroll: true });
44
69
  } else lastFocusElement = activeElement;
45
70
  }
46
71
  function onWindowKeyDown(e) {
@@ -52,8 +77,9 @@ function onWindowKeyDown(e) {
52
77
  else if (!e.shiftKey && activeElement === last) lastFocusElement = focusableList[0];
53
78
  }
54
79
  }
55
- function lockFocus(element) {
80
+ function lockFocus(element, id) {
56
81
  if (element) {
82
+ idToElementMap.set(id, element);
57
83
  focusElements = focusElements.filter((ele) => ele !== element);
58
84
  focusElements.push(element);
59
85
  window.addEventListener("focusin", syncFocus);
@@ -63,6 +89,9 @@ function lockFocus(element) {
63
89
  return () => {
64
90
  lastFocusElement = null;
65
91
  focusElements = focusElements.filter((ele) => ele !== element);
92
+ idToElementMap.delete(id);
93
+ ignoredElementMap.delete(id);
94
+ allowedElementMap.delete(id);
66
95
  if (focusElements.length === 0) {
67
96
  window.removeEventListener("focusin", syncFocus);
68
97
  window.removeEventListener("keydown", onWindowKeyDown, true);
@@ -70,11 +99,31 @@ function lockFocus(element) {
70
99
  };
71
100
  }
72
101
  function useLockFocus(lock, getElement) {
73
- watch(lock, (_, _o, onCleanup) => {
74
- if (lock.value) {
75
- const element = getElement();
76
- if (element) onCleanup(lockFocus(element));
77
- }
102
+ const id = useId_default();
103
+ watch([lock, () => getElement()], ([nextLock, element], _o, onCleanup) => {
104
+ element = getDOM(element);
105
+ if (nextLock && element) onCleanup(lockFocus(element, id));
106
+ }, {
107
+ flush: "post",
108
+ immediate: true
78
109
  });
110
+ const ignoreElement = (ele) => {
111
+ if (ele) ignoredElementMap.set(id, ele);
112
+ };
113
+ const registerAllowedElement = (ele) => {
114
+ if (!ele) return () => {};
115
+ let allowedElements = allowedElementMap.get(id);
116
+ if (!allowedElements) {
117
+ allowedElements = /* @__PURE__ */ new Set();
118
+ allowedElementMap.set(id, allowedElements);
119
+ }
120
+ allowedElements.add(ele);
121
+ return () => {
122
+ const nextAllowedElements = allowedElementMap.get(id);
123
+ nextAllowedElements?.delete(ele);
124
+ if (!nextAllowedElements?.size) allowedElementMap.delete(id);
125
+ };
126
+ };
127
+ return [ignoreElement, registerAllowedElement];
79
128
  }
80
129
  export { useLockFocus };
@@ -0,0 +1,12 @@
1
+ import { useId } from "vue";
2
+ function getUseId() {
3
+ return useId;
4
+ }
5
+ var useOriginalId = getUseId();
6
+ function useId_default(id) {
7
+ const vueId = useOriginalId();
8
+ if (id) return id;
9
+ if (process.env.NODE_ENV === "test") return "test-id";
10
+ return vueId;
11
+ }
12
+ export { useId_default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/image",
3
3
  "type": "module",
4
- "version": "1.0.8",
4
+ "version": "1.0.9",
5
5
  "description": "image component",
6
6
  "author": "",
7
7
  "license": "MIT",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes