@v-c/resize-observer 0.0.4 → 1.0.1
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.
- package/dist/SingleObserver/index.cjs +12 -9
- package/dist/SingleObserver/index.js +13 -10
- package/dist/index.cjs +2 -3
- package/dist/index.js +2 -3
- package/package.json +4 -3
- package/src/SingleObserver/index.tsx +31 -12
- package/src/index.tsx +2 -2
- package/vitest.config.ts +1 -1
|
@@ -4,13 +4,12 @@ const require_Collection = require("../Collection.cjs");
|
|
|
4
4
|
const require_observerUtil = require("../utils/observerUtil.cjs");
|
|
5
5
|
const require_DomWrapper = require("./DomWrapper.cjs");
|
|
6
6
|
let vue = require("vue");
|
|
7
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
7
8
|
let __v_c_util_dist_Dom_findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
8
9
|
__v_c_util_dist_Dom_findDOMNode = require_rolldown_runtime.__toESM(__v_c_util_dist_Dom_findDOMNode);
|
|
9
|
-
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
10
10
|
var SingleObserver = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
11
11
|
props: {
|
|
12
12
|
data: {
|
|
13
|
-
type: null,
|
|
14
13
|
required: false,
|
|
15
14
|
default: void 0
|
|
16
15
|
},
|
|
@@ -74,13 +73,17 @@ var SingleObserver = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
};
|
|
77
|
-
|
|
78
|
-
(0, vue.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
const disabled = (0, vue.computed)(() => props.disabled);
|
|
77
|
+
(0, vue.watch)([wrapperRef, disabled], (_n, _o, onCleanup) => {
|
|
78
|
+
if (disabled.value) return;
|
|
79
|
+
const currentElement = getDom();
|
|
80
|
+
if (currentElement) require_observerUtil.observe(currentElement, onInternalResize);
|
|
81
|
+
onCleanup(() => {
|
|
82
|
+
if (currentElement) require_observerUtil.unobserve(currentElement, onInternalResize);
|
|
83
|
+
});
|
|
84
|
+
}, {
|
|
85
|
+
immediate: true,
|
|
86
|
+
flush: "post"
|
|
84
87
|
});
|
|
85
88
|
expose({ getDom });
|
|
86
89
|
return () => {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { CollectionContext } from "../Collection.js";
|
|
2
2
|
import { observe, unobserve } from "../utils/observerUtil.js";
|
|
3
3
|
import DomWrapper_default from "./DomWrapper.js";
|
|
4
|
-
import { createVNode, defineComponent, inject, isVNode,
|
|
5
|
-
import findDOMNode from "@v-c/util/dist/Dom/findDOMNode";
|
|
4
|
+
import { computed, createVNode, defineComponent, inject, isVNode, shallowRef, watch } from "vue";
|
|
6
5
|
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
6
|
+
import findDOMNode from "@v-c/util/dist/Dom/findDOMNode";
|
|
7
7
|
var SingleObserver_default = /* @__PURE__ */ defineComponent({
|
|
8
8
|
props: {
|
|
9
9
|
data: {
|
|
10
|
-
type: null,
|
|
11
10
|
required: false,
|
|
12
11
|
default: void 0
|
|
13
12
|
},
|
|
@@ -71,13 +70,17 @@ var SingleObserver_default = /* @__PURE__ */ defineComponent({
|
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
72
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
const disabled = computed(() => props.disabled);
|
|
74
|
+
watch([wrapperRef, disabled], (_n, _o, onCleanup) => {
|
|
75
|
+
if (disabled.value) return;
|
|
76
|
+
const currentElement = getDom();
|
|
77
|
+
if (currentElement) observe(currentElement, onInternalResize);
|
|
78
|
+
onCleanup(() => {
|
|
79
|
+
if (currentElement) unobserve(currentElement, onInternalResize);
|
|
80
|
+
});
|
|
81
|
+
}, {
|
|
82
|
+
immediate: true,
|
|
83
|
+
flush: "post"
|
|
81
84
|
});
|
|
82
85
|
expose({ getDom });
|
|
83
86
|
return () => {
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ const require_observerUtil = require("./utils/observerUtil.cjs");
|
|
|
5
5
|
const require_index = require("./SingleObserver/index.cjs");
|
|
6
6
|
let vue = require("vue");
|
|
7
7
|
let __v_c_util = require("@v-c/util");
|
|
8
|
-
let
|
|
8
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
9
9
|
function _isSlot(s) {
|
|
10
10
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
11
11
|
}
|
|
@@ -13,7 +13,6 @@ var INTERNAL_PREFIX_KEY = "vc-observer-key";
|
|
|
13
13
|
var ResizeObserver = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
14
14
|
props: {
|
|
15
15
|
data: {
|
|
16
|
-
type: null,
|
|
17
16
|
required: false,
|
|
18
17
|
default: void 0
|
|
19
18
|
},
|
|
@@ -30,7 +29,7 @@ var ResizeObserver = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
30
29
|
},
|
|
31
30
|
setup(props, { slots }) {
|
|
32
31
|
return () => {
|
|
33
|
-
const childNodes = (0,
|
|
32
|
+
const childNodes = (0, __v_c_util_dist_props_util.filterEmpty)(slots.default?.() ?? []);
|
|
34
33
|
if (process.env.NODE_ENV !== "production") {
|
|
35
34
|
if (childNodes.length > 1) (0, __v_c_util.warning)(false, "Find more than one child node with `children` in ResizeObserver. Please use ResizeObserver.Collection instead.");
|
|
36
35
|
else if (childNodes.length === 0) (0, __v_c_util.warning)(false, "`children` of ResizeObserver is empty. Nothing is in observe.");
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { _rs } from "./utils/observerUtil.js";
|
|
|
3
3
|
import SingleObserver_default from "./SingleObserver/index.js";
|
|
4
4
|
import { createVNode, defineComponent, isVNode, mergeProps } from "vue";
|
|
5
5
|
import { warning } from "@v-c/util";
|
|
6
|
-
import {
|
|
6
|
+
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
7
7
|
function _isSlot(s) {
|
|
8
8
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
9
9
|
}
|
|
@@ -11,7 +11,6 @@ var INTERNAL_PREFIX_KEY = "vc-observer-key";
|
|
|
11
11
|
var ResizeObserver = /* @__PURE__ */ defineComponent({
|
|
12
12
|
props: {
|
|
13
13
|
data: {
|
|
14
|
-
type: null,
|
|
15
14
|
required: false,
|
|
16
15
|
default: void 0
|
|
17
16
|
},
|
|
@@ -28,7 +27,7 @@ var ResizeObserver = /* @__PURE__ */ defineComponent({
|
|
|
28
27
|
},
|
|
29
28
|
setup(props, { slots }) {
|
|
30
29
|
return () => {
|
|
31
|
-
const childNodes =
|
|
30
|
+
const childNodes = filterEmpty(slots.default?.() ?? []);
|
|
32
31
|
if (process.env.NODE_ENV !== "production") {
|
|
33
32
|
if (childNodes.length > 1) warning(false, "Find more than one child node with `children` in ResizeObserver. Please use ResizeObserver.Collection instead.");
|
|
34
33
|
else if (childNodes.length === 0) warning(false, "`children` of ResizeObserver is empty. Nothing is in observe.");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/resize-observer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"resize-observer-polyfill": "^1.5.1",
|
|
20
|
-
"@v-c/util": "
|
|
20
|
+
"@v-c/util": "^1.0.2"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "vite build",
|
|
24
24
|
"prepublish": "pnpm build",
|
|
25
|
-
"bump": "bumpp
|
|
25
|
+
"bump": "bumpp",
|
|
26
|
+
"bump:patch": "bumpp --release patch"
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { ResizeObserverProps, SizeInfo } from '../index.tsx'
|
|
2
2
|
import findDOMNode from '@v-c/util/dist/Dom/findDOMNode'
|
|
3
3
|
import { filterEmpty } from '@v-c/util/dist/props-util'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
computed,
|
|
6
|
+
createVNode,
|
|
7
|
+
defineComponent,
|
|
8
|
+
inject,
|
|
9
|
+
isVNode,
|
|
10
|
+
shallowRef,
|
|
11
|
+
watch,
|
|
12
|
+
} from 'vue'
|
|
5
13
|
import { CollectionContext } from '../Collection'
|
|
6
14
|
import { observe, unobserve } from '../utils/observerUtil.ts'
|
|
7
15
|
import DomWrapper from './DomWrapper'
|
|
@@ -76,17 +84,28 @@ const SingleObserver = defineComponent<ResizeObserverProps>({
|
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const disabled = computed(() => props.disabled)
|
|
88
|
+
// 记录上一个元素
|
|
89
|
+
watch(
|
|
90
|
+
[wrapperRef, disabled],
|
|
91
|
+
(_n, _o, onCleanup) => {
|
|
92
|
+
if (disabled.value) {
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
const currentElement = getDom() as HTMLElement
|
|
96
|
+
if (currentElement) {
|
|
97
|
+
observe(currentElement, onInternalResize as any)
|
|
98
|
+
}
|
|
99
|
+
onCleanup(() => {
|
|
100
|
+
if (currentElement)
|
|
101
|
+
unobserve(currentElement, onInternalResize as any)
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
immediate: true,
|
|
106
|
+
flush: 'post',
|
|
107
|
+
},
|
|
108
|
+
)
|
|
90
109
|
expose({
|
|
91
110
|
getDom,
|
|
92
111
|
})
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { warning } from '@v-c/util'
|
|
2
|
-
import {
|
|
2
|
+
import { filterEmpty } from '@v-c/util/dist/props-util'
|
|
3
3
|
import { defineComponent } from 'vue'
|
|
4
4
|
import { Collection } from './Collection.tsx'
|
|
5
5
|
import SingleObserver from './SingleObserver'
|
|
@@ -31,7 +31,7 @@ export interface ResizeObserverProps {
|
|
|
31
31
|
const ResizeObserver = defineComponent<ResizeObserverProps>({
|
|
32
32
|
setup(props, { slots }) {
|
|
33
33
|
return () => {
|
|
34
|
-
const childNodes =
|
|
34
|
+
const childNodes = filterEmpty(slots.default?.() ?? [])
|
|
35
35
|
if (process.env.NODE_ENV !== 'production') {
|
|
36
36
|
if (childNodes.length > 1) {
|
|
37
37
|
warning(
|
package/vitest.config.ts
CHANGED