@v-c/overflow 0.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.
@@ -0,0 +1,100 @@
1
+ import { Key, VueNode } from '@v-c/util/dist/type';
2
+ import { CSSProperties, PropType } from 'vue';
3
+ import { default as RawItem } from './RawItem';
4
+ export { OverflowContextProvider } from './context';
5
+ declare const RESPONSIVE: "responsive";
6
+ declare const INVALIDATE: "invalidate";
7
+ export interface OverflowProps<ItemType = any> {
8
+ prefixCls?: string;
9
+ class?: any;
10
+ style?: CSSProperties;
11
+ data?: ItemType[];
12
+ itemKey?: Key | ((item: ItemType) => Key);
13
+ /** Used for `responsive`. It will limit render node to avoid perf issue */
14
+ itemWidth?: number;
15
+ renderItem?: (item: ItemType, info: {
16
+ index: number;
17
+ }) => VueNode;
18
+ /** @private Do not use in your production. Render raw node that need wrap Item by developer self */
19
+ renderRawItem?: (item: ItemType, index: number) => VueNode;
20
+ maxCount?: number | typeof RESPONSIVE | typeof INVALIDATE;
21
+ renderRest?: VueNode | ((omittedItems: ItemType[]) => VueNode);
22
+ /** @private Do not use in your production. Render raw node that need wrap Item by developer self */
23
+ renderRawRest?: (omittedItems: ItemType[]) => VueNode;
24
+ prefix?: any;
25
+ suffix?: any;
26
+ component?: any;
27
+ itemComponent?: any;
28
+ /** @private This API may be refactor since not well design */
29
+ onVisibleChange?: (visibleCount: number) => void;
30
+ /** When set to `full`, ssr will render full items by default and remove at client side */
31
+ ssr?: 'full';
32
+ }
33
+ declare const OverflowImpl: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
34
+ readonly prefixCls: {
35
+ readonly type: StringConstructor;
36
+ readonly default: "vc-overflow";
37
+ };
38
+ readonly data: {
39
+ readonly type: PropType<any[]>;
40
+ readonly default: () => never[];
41
+ };
42
+ readonly renderItem: PropType<(item: any, info: {
43
+ index: number;
44
+ }) => VueNode>;
45
+ readonly renderRawItem: PropType<(item: any, index: number) => VueNode>;
46
+ readonly itemKey: PropType<Key | ((item: any) => Key)>;
47
+ readonly itemWidth: {
48
+ readonly type: NumberConstructor;
49
+ readonly default: 10;
50
+ };
51
+ readonly maxCount: PropType<number | typeof RESPONSIVE | typeof INVALIDATE>;
52
+ readonly renderRest: PropType<VueNode | ((omittedItems: any[]) => VueNode)>;
53
+ readonly renderRawRest: PropType<(omittedItems: any[]) => VueNode>;
54
+ readonly prefix: {};
55
+ readonly suffix: {};
56
+ readonly component: PropType<any>;
57
+ readonly itemComponent: PropType<any>;
58
+ readonly onVisibleChange: PropType<(visibleCount: number) => void>;
59
+ readonly ssr: PropType<"full">;
60
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "visibleChange"[], "visibleChange", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
61
+ readonly prefixCls: {
62
+ readonly type: StringConstructor;
63
+ readonly default: "vc-overflow";
64
+ };
65
+ readonly data: {
66
+ readonly type: PropType<any[]>;
67
+ readonly default: () => never[];
68
+ };
69
+ readonly renderItem: PropType<(item: any, info: {
70
+ index: number;
71
+ }) => VueNode>;
72
+ readonly renderRawItem: PropType<(item: any, index: number) => VueNode>;
73
+ readonly itemKey: PropType<Key | ((item: any) => Key)>;
74
+ readonly itemWidth: {
75
+ readonly type: NumberConstructor;
76
+ readonly default: 10;
77
+ };
78
+ readonly maxCount: PropType<number | typeof RESPONSIVE | typeof INVALIDATE>;
79
+ readonly renderRest: PropType<VueNode | ((omittedItems: any[]) => VueNode)>;
80
+ readonly renderRawRest: PropType<(omittedItems: any[]) => VueNode>;
81
+ readonly prefix: {};
82
+ readonly suffix: {};
83
+ readonly component: PropType<any>;
84
+ readonly itemComponent: PropType<any>;
85
+ readonly onVisibleChange: PropType<(visibleCount: number) => void>;
86
+ readonly ssr: PropType<"full">;
87
+ }>> & Readonly<{
88
+ onVisibleChange?: ((...args: any[]) => any) | undefined;
89
+ }>, {
90
+ readonly prefixCls: string;
91
+ readonly data: any[];
92
+ readonly itemWidth: number;
93
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
94
+ type OverflowComponent = typeof OverflowImpl & {
95
+ Item: typeof RawItem;
96
+ RESPONSIVE: typeof RESPONSIVE;
97
+ INVALIDATE: typeof INVALIDATE;
98
+ };
99
+ declare const Overflow: OverflowComponent;
100
+ export default Overflow;
@@ -0,0 +1,321 @@
1
+ import { defineComponent, computed, ref, watchEffect, createVNode, mergeProps, isVNode } from "vue";
2
+ import ResizeObserver from "@v-c/resize-observer";
3
+ import { classNames } from "@v-c/util";
4
+ import { OverflowContextProvider } from "./context.js";
5
+ import useEffectState, { useBatcher } from "./hooks/useEffectState.js";
6
+ import Item from "./Item.js";
7
+ import RawItem from "./RawItem.js";
8
+ function _isSlot(s) {
9
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
10
+ }
11
+ const RESPONSIVE = "responsive";
12
+ const INVALIDATE = "invalidate";
13
+ function defaultRenderRest(omittedItems) {
14
+ return `+ ${omittedItems.length} ...`;
15
+ }
16
+ const overflowProps = {
17
+ prefixCls: {
18
+ type: String,
19
+ default: "vc-overflow"
20
+ },
21
+ data: {
22
+ type: Array,
23
+ default: () => []
24
+ },
25
+ renderItem: Function,
26
+ renderRawItem: Function,
27
+ itemKey: [String, Number, Function],
28
+ itemWidth: {
29
+ type: Number,
30
+ default: 10
31
+ },
32
+ maxCount: [Number, String],
33
+ renderRest: [Function, Object],
34
+ renderRawRest: Function,
35
+ prefix: {},
36
+ suffix: {},
37
+ component: [String, Object, Function],
38
+ itemComponent: [String, Object, Function],
39
+ onVisibleChange: Function,
40
+ ssr: String
41
+ };
42
+ const OverflowImpl = /* @__PURE__ */ defineComponent({
43
+ name: "Overflow",
44
+ inheritAttrs: false,
45
+ props: overflowProps,
46
+ emits: ["visibleChange"],
47
+ setup(props, {
48
+ attrs,
49
+ slots,
50
+ emit
51
+ }) {
52
+ const notifyEffectUpdate = useBatcher();
53
+ const [containerWidth, setContainerWidth] = useEffectState(notifyEffectUpdate, null);
54
+ const mergedContainerWidth = computed(() => containerWidth.value || 0);
55
+ const [itemWidths, setItemWidths] = useEffectState(notifyEffectUpdate, /* @__PURE__ */ new Map());
56
+ const [prevRestWidth, setPrevRestWidth] = useEffectState(notifyEffectUpdate, 0);
57
+ const [restWidth, setRestWidth] = useEffectState(notifyEffectUpdate, 0);
58
+ const [prefixWidth, setPrefixWidth] = useEffectState(notifyEffectUpdate, 0);
59
+ const [suffixWidth, setSuffixWidth] = useEffectState(notifyEffectUpdate, 0);
60
+ const suffixFixedStart = ref(null);
61
+ const displayCount = ref(null);
62
+ const mergedDisplayCount = computed(() => {
63
+ if (displayCount.value === null && props.ssr === "full") {
64
+ return Number.MAX_SAFE_INTEGER;
65
+ }
66
+ return displayCount.value || 0;
67
+ });
68
+ const restReady = ref(false);
69
+ const itemPrefixCls = computed(() => `${props.prefixCls}-item`);
70
+ const mergedRestWidth = computed(() => Math.max(prevRestWidth.value, restWidth.value));
71
+ const data = computed(() => props.data ?? []);
72
+ const isResponsive = computed(() => props.maxCount === RESPONSIVE);
73
+ const shouldResponsive = computed(() => data.value.length && isResponsive.value);
74
+ const invalidate = computed(() => props.maxCount === INVALIDATE);
75
+ const showRest = computed(() => shouldResponsive.value || typeof props.maxCount === "number" && data.value.length > props.maxCount);
76
+ const mergedData = computed(() => {
77
+ let items = data.value;
78
+ if (shouldResponsive.value) {
79
+ if (containerWidth.value === null && props.ssr === "full") {
80
+ items = data.value;
81
+ } else {
82
+ const mergedItemWidth = props.itemWidth ?? 10;
83
+ const maxLen = Math.min(data.value.length, mergedContainerWidth.value / mergedItemWidth);
84
+ items = data.value.slice(0, Math.floor(maxLen));
85
+ }
86
+ } else if (typeof props.maxCount === "number") {
87
+ items = data.value.slice(0, props.maxCount);
88
+ }
89
+ return items;
90
+ });
91
+ const omittedItems = computed(() => {
92
+ if (shouldResponsive.value) {
93
+ return data.value.slice(mergedDisplayCount.value + 1);
94
+ }
95
+ return data.value.slice(mergedData.value.length);
96
+ });
97
+ const getKey = (item, index) => {
98
+ const {
99
+ itemKey
100
+ } = props;
101
+ if (typeof itemKey === "function") {
102
+ return itemKey(item);
103
+ }
104
+ if (itemKey != null) {
105
+ return item?.[itemKey] ?? index;
106
+ }
107
+ return index;
108
+ };
109
+ function updateDisplayCount(count, suffixFixedStartVal, notReady) {
110
+ if (displayCount.value === count && (suffixFixedStartVal === void 0 || suffixFixedStartVal === suffixFixedStart.value)) {
111
+ return;
112
+ }
113
+ displayCount.value = count;
114
+ if (!notReady) {
115
+ restReady.value = count < data.value.length - 1;
116
+ props.onVisibleChange?.(count);
117
+ emit("visibleChange", count);
118
+ }
119
+ if (suffixFixedStartVal !== void 0) {
120
+ suffixFixedStart.value = suffixFixedStartVal;
121
+ }
122
+ }
123
+ function onOverflowResize(_, element) {
124
+ setContainerWidth(element.clientWidth);
125
+ }
126
+ function registerSize(key, width) {
127
+ setItemWidths((origin) => {
128
+ const clone = new Map(origin || []);
129
+ if (width === null) {
130
+ clone.delete(key);
131
+ } else {
132
+ clone.set(key, width);
133
+ }
134
+ return clone;
135
+ });
136
+ }
137
+ function registerOverflowSize(_, width) {
138
+ setRestWidth(width ?? 0);
139
+ setPrevRestWidth(restWidth.value);
140
+ }
141
+ function registerPrefixSize(_, width) {
142
+ setPrefixWidth(width ?? 0);
143
+ }
144
+ function registerSuffixSize(_, width) {
145
+ setSuffixWidth(width ?? 0);
146
+ }
147
+ function getItemWidth(index) {
148
+ const key = getKey(mergedData.value[index], index);
149
+ return itemWidths.value?.get(key);
150
+ }
151
+ watchEffect(() => {
152
+ const container = mergedContainerWidth.value;
153
+ const rest = mergedRestWidth.value;
154
+ const list = mergedData.value;
155
+ if (container && typeof rest === "number" && list) {
156
+ let totalWidth = prefixWidth.value + suffixWidth.value;
157
+ const len = list.length;
158
+ const lastIndex = len - 1;
159
+ if (!len) {
160
+ updateDisplayCount(0, null);
161
+ return;
162
+ }
163
+ for (let i = 0; i < len; i += 1) {
164
+ let currentItemWidth = getItemWidth(i);
165
+ if (props.ssr === "full") {
166
+ currentItemWidth = currentItemWidth || 0;
167
+ }
168
+ if (currentItemWidth === void 0) {
169
+ updateDisplayCount(i - 1, void 0, true);
170
+ break;
171
+ }
172
+ totalWidth += currentItemWidth;
173
+ if (
174
+ // Only one means `totalWidth` is the final width
175
+ lastIndex === 0 && totalWidth <= container || i === lastIndex - 1 && totalWidth + (getItemWidth(lastIndex) || 0) <= container
176
+ ) {
177
+ updateDisplayCount(lastIndex, null);
178
+ break;
179
+ } else if (totalWidth + rest > container) {
180
+ updateDisplayCount(i - 1, totalWidth - currentItemWidth - suffixWidth.value + restWidth.value);
181
+ break;
182
+ }
183
+ }
184
+ if ((props.suffix ?? slots.suffix?.()) && getItemWidth(0) + suffixWidth.value > container) {
185
+ suffixFixedStart.value = null;
186
+ }
187
+ }
188
+ }, {
189
+ flush: "post"
190
+ });
191
+ return () => {
192
+ const {
193
+ prefixCls = "vc-overflow",
194
+ component: Component = "div",
195
+ itemComponent
196
+ } = props;
197
+ const renderItem = slots?.renderItem ?? props?.renderItem;
198
+ const renderRawItem = slots?.renderRawItem ?? props?.renderRawItem;
199
+ const renderRest = slots?.renderRest ?? props?.renderRest;
200
+ const renderRawRest = slots?.renderRawRest ?? props?.renderRawRest;
201
+ let prefix = slots?.prefix ?? props?.prefix;
202
+ let suffix = slots?.suffix ?? props?.suffix;
203
+ if (typeof prefix === "function") {
204
+ prefix = prefix();
205
+ }
206
+ if (typeof suffix === "function") {
207
+ suffix = suffix();
208
+ }
209
+ const displayRest = restReady.value && !!omittedItems.value.length;
210
+ let suffixStyle = {};
211
+ if (suffixFixedStart.value !== null && shouldResponsive.value) {
212
+ suffixStyle = {
213
+ position: "absolute",
214
+ left: `${suffixFixedStart.value}px`,
215
+ top: 0
216
+ };
217
+ }
218
+ const itemSharedProps = {
219
+ prefixCls: itemPrefixCls.value,
220
+ responsive: shouldResponsive.value,
221
+ component: itemComponent,
222
+ invalidate: invalidate.value
223
+ };
224
+ const internalRenderItemNode = (item, index) => {
225
+ const key = getKey(item, index);
226
+ if (renderRawItem) {
227
+ let _slot;
228
+ return createVNode(OverflowContextProvider, {
229
+ "key": key,
230
+ "value": {
231
+ ...itemSharedProps,
232
+ order: index,
233
+ item,
234
+ itemKey: key,
235
+ registerSize,
236
+ display: index <= mergedDisplayCount.value
237
+ }
238
+ }, _isSlot(_slot = renderRawItem(item, index)) ? _slot : {
239
+ default: () => [_slot]
240
+ });
241
+ }
242
+ return createVNode(Item, mergeProps(itemSharedProps, {
243
+ "order": index,
244
+ "key": key,
245
+ "item": item,
246
+ "renderItem": renderItem,
247
+ "itemKey": key,
248
+ "registerSize": registerSize,
249
+ "display": index <= mergedDisplayCount.value
250
+ }), null);
251
+ };
252
+ const restContextProps = {
253
+ order: displayRest ? mergedDisplayCount.value : Number.MAX_SAFE_INTEGER,
254
+ class: `${itemPrefixCls.value}-rest`,
255
+ registerSize: registerOverflowSize,
256
+ display: displayRest
257
+ };
258
+ const mergedRenderRestFn = renderRest ?? defaultRenderRest;
259
+ const restNode = () => {
260
+ if (renderRawRest) {
261
+ let _slot2;
262
+ return createVNode(OverflowContextProvider, {
263
+ "value": {
264
+ ...itemSharedProps,
265
+ ...restContextProps
266
+ }
267
+ }, _isSlot(_slot2 = renderRawRest(omittedItems.value)) ? _slot2 : {
268
+ default: () => [_slot2]
269
+ });
270
+ }
271
+ return createVNode(Item, mergeProps(itemSharedProps, restContextProps), {
272
+ default: () => typeof mergedRenderRestFn === "function" ? mergedRenderRestFn(omittedItems.value) : mergedRenderRestFn
273
+ });
274
+ };
275
+ const {
276
+ class: classAttr,
277
+ style: styleAttr,
278
+ ...restAttrs
279
+ } = attrs;
280
+ const overflowNode = createVNode(Component, mergeProps({
281
+ "class": classNames(!invalidate.value && prefixCls, classAttr),
282
+ "style": styleAttr
283
+ }, restAttrs), {
284
+ default: () => [prefix && createVNode(Item, mergeProps(itemSharedProps, {
285
+ "responsive": isResponsive.value,
286
+ "responsiveDisabled": !shouldResponsive.value,
287
+ "order": -1,
288
+ "class": `${itemPrefixCls.value}-prefix`,
289
+ "registerSize": registerPrefixSize,
290
+ "display": true
291
+ }), {
292
+ default: () => prefix
293
+ }), mergedData.value.map(internalRenderItemNode), showRest.value ? restNode() : null, suffix && createVNode(Item, mergeProps(itemSharedProps, {
294
+ "responsive": isResponsive.value,
295
+ "responsiveDisabled": !shouldResponsive.value,
296
+ "order": mergedDisplayCount.value,
297
+ "class": `${itemPrefixCls.value}-suffix`,
298
+ "registerSize": registerSuffixSize,
299
+ "display": true,
300
+ "style": suffixStyle
301
+ }), {
302
+ default: () => suffix
303
+ }), slots.default?.()]
304
+ });
305
+ return isResponsive.value ? createVNode(ResizeObserver, {
306
+ "onResize": onOverflowResize,
307
+ "disabled": !shouldResponsive.value
308
+ }, _isSlot(overflowNode) ? overflowNode : {
309
+ default: () => [overflowNode]
310
+ }) : overflowNode;
311
+ };
312
+ }
313
+ });
314
+ const Overflow = OverflowImpl;
315
+ Overflow.Item = RawItem;
316
+ Overflow.RESPONSIVE = RESPONSIVE;
317
+ Overflow.INVALIDATE = INVALIDATE;
318
+ export {
319
+ OverflowContextProvider,
320
+ Overflow as default
321
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const vue = require("vue");
4
+ const util = require("@v-c/util");
5
+ const context = require("./context.cjs");
6
+ const Item = require("./Item.cjs");
7
+ const RawItem = /* @__PURE__ */ vue.defineComponent({
8
+ name: "OverflowRawItem",
9
+ inheritAttrs: false,
10
+ props: {
11
+ component: {
12
+ type: [String, Object, Function],
13
+ default: "div"
14
+ }
15
+ },
16
+ setup(props, {
17
+ slots,
18
+ attrs
19
+ }) {
20
+ const context$1 = context.useInjectOverflowContext();
21
+ return () => {
22
+ if (!context$1?.value) {
23
+ const Component = props.component ?? "div";
24
+ return vue.createVNode(Component, attrs, {
25
+ default: () => [slots.default?.()]
26
+ });
27
+ }
28
+ const {
29
+ className: contextClassName,
30
+ ...restContext
31
+ } = context$1.value;
32
+ const {
33
+ class: classAttr,
34
+ ...restAttrs
35
+ } = attrs;
36
+ return vue.createVNode(context.OverflowContextProvider, {
37
+ "value": null
38
+ }, {
39
+ default: () => [vue.createVNode(Item.default, vue.mergeProps(restContext, restAttrs, {
40
+ "class": util.classNames(contextClassName, classAttr),
41
+ "component": props.component
42
+ }), slots)]
43
+ });
44
+ };
45
+ }
46
+ });
47
+ exports.default = RawItem;
@@ -0,0 +1,15 @@
1
+ import { PropType } from 'vue';
2
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
3
+ component: {
4
+ type: PropType<any>;
5
+ default: string;
6
+ };
7
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
8
+ component: {
9
+ type: PropType<any>;
10
+ default: string;
11
+ };
12
+ }>> & Readonly<{}>, {
13
+ component: any;
14
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
15
+ export default _default;
@@ -0,0 +1,47 @@
1
+ import { defineComponent, createVNode, mergeProps } from "vue";
2
+ import { classNames } from "@v-c/util";
3
+ import { useInjectOverflowContext, OverflowContextProvider } from "./context.js";
4
+ import Item from "./Item.js";
5
+ const RawItem = /* @__PURE__ */ defineComponent({
6
+ name: "OverflowRawItem",
7
+ inheritAttrs: false,
8
+ props: {
9
+ component: {
10
+ type: [String, Object, Function],
11
+ default: "div"
12
+ }
13
+ },
14
+ setup(props, {
15
+ slots,
16
+ attrs
17
+ }) {
18
+ const context = useInjectOverflowContext();
19
+ return () => {
20
+ if (!context?.value) {
21
+ const Component = props.component ?? "div";
22
+ return createVNode(Component, attrs, {
23
+ default: () => [slots.default?.()]
24
+ });
25
+ }
26
+ const {
27
+ className: contextClassName,
28
+ ...restContext
29
+ } = context.value;
30
+ const {
31
+ class: classAttr,
32
+ ...restAttrs
33
+ } = attrs;
34
+ return createVNode(OverflowContextProvider, {
35
+ "value": null
36
+ }, {
37
+ default: () => [createVNode(Item, mergeProps(restContext, restAttrs, {
38
+ "class": classNames(contextClassName, classAttr),
39
+ "component": props.component
40
+ }), slots)]
41
+ });
42
+ };
43
+ }
44
+ });
45
+ export {
46
+ RawItem as default
47
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ const OverflowContextKey = Symbol("OverflowContext");
5
+ const OverflowContextProvider = /* @__PURE__ */ vue.defineComponent({
6
+ name: "OverflowContextProvider",
7
+ inheritAttrs: false,
8
+ props: {
9
+ value: {
10
+ type: Object
11
+ }
12
+ },
13
+ setup(props, {
14
+ slots
15
+ }) {
16
+ vue.provide(OverflowContextKey, vue.computed(() => props.value));
17
+ return () => slots.default?.();
18
+ }
19
+ });
20
+ function useInjectOverflowContext() {
21
+ return vue.inject(OverflowContextKey, null);
22
+ }
23
+ exports.OverflowContextProvider = OverflowContextProvider;
24
+ exports.useInjectOverflowContext = useInjectOverflowContext;
@@ -0,0 +1,25 @@
1
+ import { Key } from '@v-c/util/dist/type';
2
+ import { ComputedRef, PropType } from 'vue';
3
+ export interface OverflowContextType {
4
+ prefixCls: string;
5
+ responsive: boolean;
6
+ order: number;
7
+ registerSize: (key: Key, width: number | null) => void;
8
+ display: boolean;
9
+ invalidate: boolean;
10
+ item?: any;
11
+ itemKey?: Key;
12
+ className?: string;
13
+ }
14
+ export declare const OverflowContextProvider: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
15
+ value: {
16
+ type: PropType<any>;
17
+ };
18
+ }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
19
+ [key: string]: any;
20
+ }>[] | undefined, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
21
+ value: {
22
+ type: PropType<any>;
23
+ };
24
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
25
+ export declare function useInjectOverflowContext(): ComputedRef<OverflowContextType | null> | null;
@@ -0,0 +1,24 @@
1
+ import { defineComponent, inject, provide, computed } from "vue";
2
+ const OverflowContextKey = Symbol("OverflowContext");
3
+ const OverflowContextProvider = /* @__PURE__ */ defineComponent({
4
+ name: "OverflowContextProvider",
5
+ inheritAttrs: false,
6
+ props: {
7
+ value: {
8
+ type: Object
9
+ }
10
+ },
11
+ setup(props, {
12
+ slots
13
+ }) {
14
+ provide(OverflowContextKey, computed(() => props.value));
15
+ return () => slots.default?.();
16
+ }
17
+ });
18
+ function useInjectOverflowContext() {
19
+ return inject(OverflowContextKey, null);
20
+ }
21
+ export {
22
+ OverflowContextProvider,
23
+ useInjectOverflowContext
24
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const raf = require("@v-c/util/dist/raf");
4
+ function channelUpdate(callback) {
5
+ if (typeof MessageChannel === "undefined") {
6
+ raf(callback);
7
+ } else {
8
+ const channel = new MessageChannel();
9
+ channel.port1.onmessage = () => callback();
10
+ channel.port2.postMessage(void 0);
11
+ }
12
+ }
13
+ exports.default = channelUpdate;
@@ -0,0 +1 @@
1
+ export default function channelUpdate(callback: VoidFunction): void;
@@ -0,0 +1,13 @@
1
+ import raf from "@v-c/util/dist/raf";
2
+ function channelUpdate(callback) {
3
+ if (typeof MessageChannel === "undefined") {
4
+ raf(callback);
5
+ } else {
6
+ const channel = new MessageChannel();
7
+ channel.port1.onmessage = () => callback();
8
+ channel.port2.postMessage(void 0);
9
+ }
10
+ }
11
+ export {
12
+ channelUpdate as default
13
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const useEvent = require("@v-c/util/dist/hooks/useEvent");
4
+ const vue = require("vue");
5
+ const channelUpdate = require("./channelUpdate.cjs");
6
+ function useBatcher() {
7
+ const updateFuncRef = vue.ref(null);
8
+ const notifyEffectUpdate = (callback) => {
9
+ if (!updateFuncRef.value) {
10
+ updateFuncRef.value = [];
11
+ channelUpdate.default(() => {
12
+ updateFuncRef.value.forEach((fn) => {
13
+ fn();
14
+ });
15
+ updateFuncRef.value = null;
16
+ });
17
+ }
18
+ updateFuncRef.value.push(callback);
19
+ };
20
+ return notifyEffectUpdate;
21
+ }
22
+ function useEffectState(notifyEffectUpdate, defaultValue) {
23
+ const stateValue = vue.ref(defaultValue);
24
+ const setEffectVal = useEvent((nextValue) => {
25
+ notifyEffectUpdate(() => {
26
+ if (typeof nextValue === "function") {
27
+ const updater = nextValue;
28
+ stateValue.value = updater(stateValue.value);
29
+ } else {
30
+ stateValue.value = nextValue;
31
+ }
32
+ });
33
+ });
34
+ return [stateValue, setEffectVal];
35
+ }
36
+ exports.default = useEffectState;
37
+ exports.useBatcher = useBatcher;