dou-ui 0.1.0-alpha.12 → 0.1.0-alpha.13
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/components/button/button.js.map +1 -1
- package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js +29 -17
- package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input2.js.map +1 -1
- package/dist/components/check-tag/check-tag.vue_vue_type_script_setup_true_lang.js +8 -5
- package/dist/components/check-tag/check-tag.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/check-tag/check-tag2.js.map +1 -1
- package/dist/components/command/command-dialog.js.map +1 -1
- package/dist/components/command/command-dialog.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/components/command/command-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/command/command.js.map +1 -1
- package/dist/components/command/command.vue_vue_type_script_setup_true_lang.js +65 -12
- package/dist/components/command/command.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/command/command2.js.map +1 -1
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +6 -4
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-actions.js +3 -13
- package/dist/components/menu/menu-actions.js.map +1 -1
- package/dist/components/status-dot/status-dot.vue_vue_type_script_lang.js +3 -11
- package/dist/components/status-dot/status-dot.vue_vue_type_script_lang.js.map +1 -1
- package/dist/components/status-dot/status-dot2.js.map +1 -1
- package/dist/components/tag/tag.js.map +1 -1
- package/dist/components/tag/tag.vue_vue_type_script_setup_true_lang.js +9 -6
- package/dist/components/tag/tag.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/composables/use-grouped-window.js +4 -1
- package/dist/composables/use-grouped-window.js.map +1 -1
- package/dist/composables/use-measured-sizes.js +6 -5
- package/dist/composables/use-measured-sizes.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/command/command-dialog.vue.d.ts +1 -0
- package/dist/types/components/command/command.d.ts +7 -1
- package/dist/types/components/command/index.d.ts +3 -0
- package/dist/types/composables/use-grouped-window.d.ts +1 -0
- package/dist/types/composables/use-measured-sizes.d.ts +6 -0
- package/dist/types/utils/slot.d.ts +19 -0
- package/dist/utils/slot.js +36 -0
- package/dist/utils/slot.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { useLocale } from "../config-provider/use-config.js";
|
|
3
3
|
import { useFormSize } from "../form/use-form-item.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SlotNodes, filled } from "../../utils/slot.js";
|
|
5
|
+
import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, renderSlot, unref, useAttrs, useSlots, useTemplateRef } from "vue";
|
|
5
6
|
import { CloseIcon } from "@dou-ui/icons";
|
|
6
7
|
// src/components/tag/tag.vue?vue&type=script&setup=true&lang.ts
|
|
7
8
|
var _hoisted_1 = ["title"];
|
|
@@ -51,10 +52,12 @@ var tag_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompon
|
|
|
51
52
|
]);
|
|
52
53
|
return (_ctx, _cache) => {
|
|
53
54
|
return openBlock(), createElementBlock("span", { class: normalizeClass(classes.value) }, [
|
|
54
|
-
|
|
55
|
-
key: 0,
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList([unref(filled)(slots.leading)], (leading) => {
|
|
56
|
+
return openBlock(), createElementBlock(Fragment, { key: 0 }, [leading ? (openBlock(), createElementBlock("span", {
|
|
57
|
+
key: 0,
|
|
58
|
+
class: normalizeClass(unref(ns).e("icon"))
|
|
59
|
+
}, [createVNode(unref(SlotNodes), { nodes: leading }, null, 8, ["nodes"])], 2)) : createCommentVNode("", true)], 64);
|
|
60
|
+
}), 128)),
|
|
58
61
|
createElementVNode("span", {
|
|
59
62
|
ref: "label",
|
|
60
63
|
class: normalizeClass(unref(ns).e("label")),
|
|
@@ -62,7 +65,7 @@ var tag_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompon
|
|
|
62
65
|
onPointerenter: onLabelEnter
|
|
63
66
|
}, [renderSlot(_ctx.$slots, "default")], 42, _hoisted_1),
|
|
64
67
|
__props.closable ? (openBlock(), createElementBlock("button", {
|
|
65
|
-
key:
|
|
68
|
+
key: 0,
|
|
66
69
|
type: "button",
|
|
67
70
|
class: normalizeClass(unref(ns).e("close")),
|
|
68
71
|
"aria-label": __props.closeLabel ?? unref(t)("tag.remove"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","
|
|
1
|
+
{"version":3,"file":"tag.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_Fragment","_renderList","_unref","_createVNode","_createCommentVNode","_createElementVNode","_renderSlot"],"sources":["../../../src/components/tag/tag.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon } from '@dou-ui/icons'\nimport { computed, ref, useAttrs, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { SlotNodes, filled } from '../../utils/slot'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormSize } from '../form/use-form-item'\nimport type { TagEmits, TagProps, TagSlots } from './tag'\n\ndefineOptions({ name: 'DouTag' })\n\nconst props = withDefaults(defineProps<TagProps>(), {\n variant: 'soft',\n tone: 'neutral',\n closable: false,\n round: false,\n})\nconst emit = defineEmits<TagEmits>()\nconst slots = defineSlots<TagSlots>()\n\nconst ns = useNamespace('tag')\nconst { t } = useLocale()\nconst size = useFormSize(() => props.size)\n\n// A label cut short by the ellipsis shows the whole text on hover. Measured\n// only when the pointer arrives, so a page of tags costs nothing until then.\n// A `title` given to the tag is the user's own and always wins.\nconst attrs = useAttrs()\nconst labelRef = useTemplateRef<HTMLElement>('label')\nconst labelTitle = ref<string>()\nfunction onLabelEnter() {\n const el = labelRef.value\n if (!el || attrs.title != null) {\n labelTitle.value = undefined\n return\n }\n labelTitle.value =\n el.scrollWidth > el.clientWidth ? el.textContent?.trim() || undefined : undefined\n}\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('round', props.round),\n])\n</script>\n\n<template>\n <span :class=\"classes\">\n <!-- rendered once: a leading slot that renders nothing leaves no icon -->\n <template v-for=\"leading in [filled(slots.leading)]\" :key=\"0\">\n <span v-if=\"leading\" :class=\"ns.e('icon')\"><SlotNodes :nodes=\"leading\" /></span>\n </template>\n <span ref=\"label\" :class=\"ns.e('label')\" :title=\"labelTitle\" @pointerenter=\"onLabelEnter\">\n <slot />\n </span>\n <button\n v-if=\"closable\"\n type=\"button\"\n :class=\"ns.e('close')\"\n :aria-label=\"closeLabel ?? t('tag.remove')\"\n @click=\"emit('close', $event)\"\n >\n <CloseIcon />\n </button>\n </span>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWA,MAAM,QAAQ;EAMd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,KAAK;EAC7B,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,OAAO,kBAAkB,MAAM,IAAI;EAKzC,MAAM,QAAQ,SAAS;EACvB,MAAM,WAAW,eAA4B,OAAO;EACpD,MAAM,aAAa,IAAY;EAC/B,SAAS,eAAe;GACtB,MAAM,KAAK,SAAS;GACpB,IAAI,CAAC,MAAM,MAAM,SAAS,MAAM;IAC9B,WAAW,QAAQ,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|
|
|
113
113
|
observed?.removeEventListener("scroll", onScroll);
|
|
114
114
|
observer?.disconnect();
|
|
115
115
|
});
|
|
116
|
+
/** Where an item starts in the scrolled content. */
|
|
117
|
+
const startOf = (group, index) => (starts.value[group] ?? 0) + (offsets.value[group]?.start(index) ?? 0);
|
|
116
118
|
return {
|
|
117
119
|
enabled,
|
|
118
120
|
windows,
|
|
119
121
|
scrollToItem,
|
|
120
|
-
measure
|
|
122
|
+
measure,
|
|
123
|
+
startOf
|
|
121
124
|
};
|
|
122
125
|
}
|
|
123
126
|
export { GROUP_START, useGroupedWindow };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-grouped-window.js","names":[],"sources":["../../src/composables/use-grouped-window.ts"],"sourcesContent":["import { computed, onBeforeUnmount, onMounted, onUpdated, ref, watch } from 'vue'\nimport { createOffsets } from '../components/virtual-list/virtual-list'\nimport { shouldVirtualize } from '../utils/virtual'\n\nexport interface UseGroupedWindowOptions {\n /** The element that scrolls. */\n container: () => HTMLElement | null | undefined\n /** How many items each group holds, in order. */\n sizes: () => number[]\n /** The height of an item in px. */\n itemSize: (group: number, index: number) => number\n /** `virtual` as asked for; left undefined, it turns on for long lists. */\n virtual: () => boolean | undefined\n /** Extra items rendered above and below the viewport. */\n overscan?: number\n}\n\nexport interface GroupWindow {\n /** The first item to render. */\n from: number\n /** One past the last item to render. */\n to: number\n /** The height of a spacer standing in for the items before `from`. */\n before: number\n /** The height of a spacer standing in for the items from `to` on. */\n after: number\n}\n\n/** The attribute that marks where a group's items begin, on its leading spacer. */\nexport const GROUP_START = 'data-dou-group-start'\n\n/**\n * Render only the items in view of a list split into groups, such as\n * options under group labels. Items keep their place in the page between\n * two spacers, so labels, separators and padding stay as they are; where\n * each group's items begin is measured from a marker on its leading spacer.\n */\nexport function useGroupedWindow(options: UseGroupedWindowOptions) {\n const overscan = options.overscan ?? 4\n const scrollTop = ref(0)\n const viewport = ref(0)\n const measuredStarts = ref<number[]>([])\n\n const total = computed(() => options.sizes().reduce((sum, count) => sum + count, 0))\n const enabled = computed(() => shouldVirtualize(options.virtual(), total.value))\n const offsets = computed(() =>\n options.sizes().map((count, group) => createOffsets(count, (i) => options.itemSize(group, i))),\n )\n // Until measured, groups are assumed to follow each other with no gap.\n const starts = computed(() => {\n let estimate = 0\n return offsets.value.map((offset, group) => {\n const start = measuredStarts.value[group] ?? estimate\n estimate = start + offset.total\n return start\n })\n })\n\n function windowOf(group: number): GroupWindow {\n const count = options.sizes()[group] ?? 0\n if (!enabled.value) return { from: 0, to: count, before: 0, after: 0 }\n const offset = offsets.value[group]!\n const top = scrollTop.value - starts.value[group]!\n const height = Math.max(viewport.value, 1)\n let from: number\n let to: number\n if (!count || top + height <= 0) from = to = 0\n else if (top >= offset.total) from = to = count\n else {\n from = Math.max(0, offset.find(Math.max(0, top)) - overscan)\n to = Math.min(count, offset.find(top + height - 1) + 1 + overscan)\n }\n return { from, to, before: offset.start(from), after: offset.total - offset.start(to) }\n }\n const windows = computed(() => options.sizes().map((_, group) => windowOf(group)))\n\n function measure() {\n const el = options.container()\n if (!el || !enabled.value) return\n viewport.value = el.clientHeight\n const base = el.getBoundingClientRect().top - el.scrollTop\n const markers = el.querySelectorAll(`[${GROUP_START}]`)\n const next = Array.from(markers, (marker) =>\n Math.round(marker.getBoundingClientRect().top - base),\n )\n const current = measuredStarts.value\n if (next.length !== current.length || next.some((value, at) => value !== current[at])) {\n measuredStarts.value = next\n }\n }\n\n function onScroll() {\n const el = options.container()\n if (el && enabled.value) scrollTop.value = el.scrollTop\n }\n\n /** Scroll as little as needed to show an item, whether or not it is rendered. */\n function scrollToItem(group: number, index: number) {\n const el = options.container()\n const offset = offsets.value[group]\n if (!el || !offset) return\n const top = starts.value[group]! + offset.start(index)\n const bottom = starts.value[group]! + offset.start(index + 1)\n let target = el.scrollTop\n if (top < target) target = top\n else if (bottom > target + el.clientHeight) target = bottom - el.clientHeight\n if (target !== el.scrollTop) {\n el.scrollTop = Math.max(0, target)\n scrollTop.value = el.scrollTop\n }\n }\n\n let observed: HTMLElement | null | undefined\n let observer: ResizeObserver | undefined\n function bind() {\n const el = options.container()\n if (el === observed) return\n observed?.removeEventListener('scroll', onScroll)\n observer?.disconnect()\n observed = el\n if (!el) return\n el.addEventListener('scroll', onScroll, { passive: true })\n scrollTop.value = el.scrollTop\n if (typeof ResizeObserver !== 'undefined') {\n observer = new ResizeObserver(measure)\n observer.observe(el)\n }\n }\n onMounted(() => {\n bind()\n measure()\n })\n onUpdated(() => {\n bind()\n measure()\n })\n watch(enabled, (on) => {\n if (on) onScroll()\n })\n onBeforeUnmount(() => {\n observed?.removeEventListener('scroll', onScroll)\n observer?.disconnect()\n })\n\n return { enabled, windows, scrollToItem, measure }\n}\n"],"mappings":";;;;;AA6BA,IAAa,cAAc;;;;;;;AAQ3B,SAAgB,iBAAiB,SAAkC;CACjE,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,YAAY,IAAI,CAAC;CACvB,MAAM,WAAW,IAAI,CAAC;CACtB,MAAM,iBAAiB,IAAc,CAAC,CAAC;CAEvC,MAAM,QAAQ,eAAe,QAAQ,MAAM,CAAC,CAAC,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC;CACnF,MAAM,UAAU,eAAe,iBAAiB,QAAQ,QAAQ,GAAG,MAAM,KAAK,CAAC;CAC/E,MAAM,UAAU,eACd,QAAQ,MAAM,CAAC,CAAC,KAAK,OAAO,UAAU,cAAc,QAAQ,MAAM,QAAQ,SAAS,OAAO,CAAC,CAAC,CAAC,CAC/F;CAEA,MAAM,SAAS,eAAe;EAC5B,IAAI,WAAW;EACf,OAAO,QAAQ,MAAM,KAAK,QAAQ,UAAU;GAC1C,MAAM,QAAQ,eAAe,MAAM,UAAU;GAC7C,WAAW,QAAQ,OAAO;GAC1B,OAAO;EACT,CAAC;CACH,CAAC;CAED,SAAS,SAAS,OAA4B;EAC5C,MAAM,QAAQ,QAAQ,MAAM,CAAC,CAAC,UAAU;EACxC,IAAI,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AQ,OAAO,UAAU,QAAQ,GAAG;CAChD;;CAGA,SAAS,aAAa,OAAe,OAAe;EAClD,MAAM,KAAK,QAAQ,UAAU;EAC7B,MAAM,SAAS,QAAQ,MAAM;EAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ;EACpB,MAAM,MAAM,OAAO,MAAM,SAAU,OAAO,MAAM,KAAK;EACrD,MAAM,SAAS,OAAO,MAAM,SAAU,OAAO,MAAM,QAAQ,CAAC;EAC5D,IAAI,SAAS,GAAG;EAChB,IAAI,MAAM,QAAQ,SAAS;OACtB,IAAI,SAAS,SAAS,GAAG,cAAc,SAAS,SAAS,GAAG;EACjE,IAAI,WAAW,GAAG,WAAW;GAC3B,GAAG,YAAY,KAAK,IAAI,GAAG,MAAM;GACjC,UAAU,QAAQ,GAAG;EACvB;CACF;CAEA,IAAI;CACJ,IAAI;CACJ,SAAS,OAAO;EACd,MAAM,KAAK,QAAQ,UAAU;EAC7B,IAAI,OAAO,UAAU;EACrB,UAAU,oBAAoB,UAAU,QAAQ;EAChD,UAAU,WAAW;EACrB,WAAW;EACX,IAAI,CAAC,IAAI;EACT,GAAG,iBAAiB,UAAU,UAAU,EAAE,SAAS,KAAK,CAAC;EACzD,UAAU,QAAQ,GAAG;EACrB,IAAI,OAAO,mBAAmB,aAAa;GACzC,WAAW,IAAI,eAAe,OAAO;GACrC,SAAS,QAAQ,EAAE;EACrB;CACF;CACA,gBAAgB;EACd,KAAK;EACL,QAAQ;CACV,CAAC;CACD,gBAAgB;EACd,KAAK;EACL,QAAQ;CACV,CAAC;CACD,MAAM,UAAU,OAAO;EACrB,IAAI,IAAI,SAAS;CACnB,CAAC;CACD,sBAAsB;EACpB,UAAU,oBAAoB,UAAU,QAAQ;EAChD,UAAU,WAAW;CACvB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-grouped-window.js","names":[],"sources":["../../src/composables/use-grouped-window.ts"],"sourcesContent":["import { computed, onBeforeUnmount, onMounted, onUpdated, ref, watch } from 'vue'\nimport { createOffsets } from '../components/virtual-list/virtual-list'\nimport { shouldVirtualize } from '../utils/virtual'\n\nexport interface UseGroupedWindowOptions {\n /** The element that scrolls. */\n container: () => HTMLElement | null | undefined\n /** How many items each group holds, in order. */\n sizes: () => number[]\n /** The height of an item in px. */\n itemSize: (group: number, index: number) => number\n /** `virtual` as asked for; left undefined, it turns on for long lists. */\n virtual: () => boolean | undefined\n /** Extra items rendered above and below the viewport. */\n overscan?: number\n}\n\nexport interface GroupWindow {\n /** The first item to render. */\n from: number\n /** One past the last item to render. */\n to: number\n /** The height of a spacer standing in for the items before `from`. */\n before: number\n /** The height of a spacer standing in for the items from `to` on. */\n after: number\n}\n\n/** The attribute that marks where a group's items begin, on its leading spacer. */\nexport const GROUP_START = 'data-dou-group-start'\n\n/**\n * Render only the items in view of a list split into groups, such as\n * options under group labels. Items keep their place in the page between\n * two spacers, so labels, separators and padding stay as they are; where\n * each group's items begin is measured from a marker on its leading spacer.\n */\nexport function useGroupedWindow(options: UseGroupedWindowOptions) {\n const overscan = options.overscan ?? 4\n const scrollTop = ref(0)\n const viewport = ref(0)\n const measuredStarts = ref<number[]>([])\n\n const total = computed(() => options.sizes().reduce((sum, count) => sum + count, 0))\n const enabled = computed(() => shouldVirtualize(options.virtual(), total.value))\n const offsets = computed(() =>\n options.sizes().map((count, group) => createOffsets(count, (i) => options.itemSize(group, i))),\n )\n // Until measured, groups are assumed to follow each other with no gap.\n const starts = computed(() => {\n let estimate = 0\n return offsets.value.map((offset, group) => {\n const start = measuredStarts.value[group] ?? estimate\n estimate = start + offset.total\n return start\n })\n })\n\n function windowOf(group: number): GroupWindow {\n const count = options.sizes()[group] ?? 0\n if (!enabled.value) return { from: 0, to: count, before: 0, after: 0 }\n const offset = offsets.value[group]!\n const top = scrollTop.value - starts.value[group]!\n const height = Math.max(viewport.value, 1)\n let from: number\n let to: number\n if (!count || top + height <= 0) from = to = 0\n else if (top >= offset.total) from = to = count\n else {\n from = Math.max(0, offset.find(Math.max(0, top)) - overscan)\n to = Math.min(count, offset.find(top + height - 1) + 1 + overscan)\n }\n return { from, to, before: offset.start(from), after: offset.total - offset.start(to) }\n }\n const windows = computed(() => options.sizes().map((_, group) => windowOf(group)))\n\n function measure() {\n const el = options.container()\n if (!el || !enabled.value) return\n viewport.value = el.clientHeight\n const base = el.getBoundingClientRect().top - el.scrollTop\n const markers = el.querySelectorAll(`[${GROUP_START}]`)\n const next = Array.from(markers, (marker) =>\n Math.round(marker.getBoundingClientRect().top - base),\n )\n const current = measuredStarts.value\n if (next.length !== current.length || next.some((value, at) => value !== current[at])) {\n measuredStarts.value = next\n }\n }\n\n function onScroll() {\n const el = options.container()\n if (el && enabled.value) scrollTop.value = el.scrollTop\n }\n\n /** Scroll as little as needed to show an item, whether or not it is rendered. */\n function scrollToItem(group: number, index: number) {\n const el = options.container()\n const offset = offsets.value[group]\n if (!el || !offset) return\n const top = starts.value[group]! + offset.start(index)\n const bottom = starts.value[group]! + offset.start(index + 1)\n let target = el.scrollTop\n if (top < target) target = top\n else if (bottom > target + el.clientHeight) target = bottom - el.clientHeight\n if (target !== el.scrollTop) {\n el.scrollTop = Math.max(0, target)\n scrollTop.value = el.scrollTop\n }\n }\n\n let observed: HTMLElement | null | undefined\n let observer: ResizeObserver | undefined\n function bind() {\n const el = options.container()\n if (el === observed) return\n observed?.removeEventListener('scroll', onScroll)\n observer?.disconnect()\n observed = el\n if (!el) return\n el.addEventListener('scroll', onScroll, { passive: true })\n scrollTop.value = el.scrollTop\n if (typeof ResizeObserver !== 'undefined') {\n observer = new ResizeObserver(measure)\n observer.observe(el)\n }\n }\n onMounted(() => {\n bind()\n measure()\n })\n onUpdated(() => {\n bind()\n measure()\n })\n watch(enabled, (on) => {\n if (on) onScroll()\n })\n onBeforeUnmount(() => {\n observed?.removeEventListener('scroll', onScroll)\n observer?.disconnect()\n })\n\n /** Where an item starts in the scrolled content. */\n const startOf = (group: number, index: number) =>\n (starts.value[group] ?? 0) + (offsets.value[group]?.start(index) ?? 0)\n\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W;GAC3B,GAAG,YAAY,KAAK,IAAI,GAAG,MAAM;GACjC,UAAU,QAAQ,GAAG;EACvB;CACF;CAEA,IAAI;CACJ,IAAI;CACJ,SAAS,OAAO;EACd,MAAM,KAAK,QAAQ,UAAU;EAC7B,IAAI,OAAO,UAAU;EACrB,UAAU,oBAAoB,UAAU,QAAQ;EAChD,UAAU,WAAW;EACrB,WAAW;EACX,IAAI,CAAC,IAAI;EACT,GAAG,iBAAiB,UAAU,UAAU,EAAE,SAAS,KAAK,CAAC;EACzD,UAAU,QAAQ,GAAG;EACrB,IAAI,OAAO,mBAAmB,aAAa;GACzC,WAAW,IAAI,eAAe,OAAO;GACrC,SAAS,QAAQ,EAAE;EACrB;CACF;CACA,gBAAgB;EACd,KAAK;EACL,QAAQ;CACV,CAAC;CACD,gBAAgB;EACd,KAAK;EACL,QAAQ;CACV,CAAC;CACD,MAAM,UAAU,OAAO;EACrB,IAAI,IAAI,SAAS;CACnB,CAAC;CACD,sBAAsB;EACpB,UAAU,oBAAoB,UAAU,QAAQ;EAChD,UAAU,WAAW;CACvB,CAAC;;CAGD,MAAM,WAAW,OAAe,WAC7B,OAAO,MAAM,UAAU,MAAM,QAAQ,MAAM,MAAM,EAAE,MAAM,KAAK,KAAK;CAEtE,OAAO;EAAE;EAAS;EAAS;EAAc;EAAS;CAAQ;AAC5D"}
|
|
@@ -15,11 +15,12 @@ function useMeasuredSizes(options) {
|
|
|
15
15
|
const known = /* @__PURE__ */ new Map();
|
|
16
16
|
const touch = useTouchScroll();
|
|
17
17
|
const version = shallowRef(0);
|
|
18
|
-
const sizeOf = (index) =>
|
|
19
|
-
const offsets = computed(() => {
|
|
18
|
+
const sizeOf = (index) => {
|
|
20
19
|
version.value;
|
|
21
|
-
return
|
|
22
|
-
}
|
|
20
|
+
return known.get(options.keyOf(index)) ?? options.estimate(index);
|
|
21
|
+
};
|
|
22
|
+
const offsets = computed(() => createOffsets(options.count(), sizeOf));
|
|
23
|
+
const startOf = (index) => options.start?.(index) ?? offsets.value.start(index);
|
|
23
24
|
const tracked = /* @__PURE__ */ new Map();
|
|
24
25
|
const byKey = /* @__PURE__ */ new Map();
|
|
25
26
|
const heightOf = (key) => {
|
|
@@ -42,7 +43,7 @@ function useMeasuredSizes(options) {
|
|
|
42
43
|
if (size === before && known.has(key)) continue;
|
|
43
44
|
known.set(key, size);
|
|
44
45
|
changed = true;
|
|
45
|
-
if (
|
|
46
|
+
if (startOf(index) < top) shift += size - before;
|
|
46
47
|
}
|
|
47
48
|
if (!changed) return;
|
|
48
49
|
version.value++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-measured-sizes.js","names":[],"sources":["../../src/composables/use-measured-sizes.ts"],"sourcesContent":["import { computed, onBeforeUnmount, shallowRef } from 'vue'\nimport { createOffsets } from '../components/virtual-list/virtual-list'\nimport { scrollPositionOf } from '../utils/scroll'\nimport { useTouchScroll } from './use-touch-scroll'\n\nexport interface UseMeasuredSizesOptions<K> {\n /** How many items there are. */\n count: () => number\n /** A key that follows an item as the list changes. */\n keyOf: (index: number) => K\n /** The height to assume for an item not measured yet. */\n estimate: (index: number) => number\n /** The element that scrolls, kept steady while items above the view change height. */\n container: () => HTMLElement | null | undefined\n}\n\n/**\n * Item offsets for a list whose items are measured once rendered.\n *\n * Unmeasured items count at their estimate. Rendered items are watched for\n * size changes; when one above the top of the view changes, the scroll\n * position moves by the same amount, so what the reader sees stays put;\n * a move iOS drops during a touch scroll is made once the scroll is over.\n */\nexport function useMeasuredSizes<K>(options: UseMeasuredSizesOptions<K>) {\n const known = new Map<K, number>()\n const touch = useTouchScroll()\n // Bumped when a measurement changes; reading it ties offsets to it.\n const version = shallowRef(0)\n\n const sizeOf = (index: number) => known.get(options.keyOf(index)) ?? options.estimate(index)\n const offsets = computed(() =>
|
|
1
|
+
{"version":3,"file":"use-measured-sizes.js","names":[],"sources":["../../src/composables/use-measured-sizes.ts"],"sourcesContent":["import { computed, onBeforeUnmount, shallowRef } from 'vue'\nimport { createOffsets } from '../components/virtual-list/virtual-list'\nimport { scrollPositionOf } from '../utils/scroll'\nimport { useTouchScroll } from './use-touch-scroll'\n\nexport interface UseMeasuredSizesOptions<K> {\n /** How many items there are. */\n count: () => number\n /** A key that follows an item as the list changes. */\n keyOf: (index: number) => K\n /** The height to assume for an item not measured yet. */\n estimate: (index: number) => number\n /** The element that scrolls, kept steady while items above the view change height. */\n container: () => HTMLElement | null | undefined\n /**\n * Where an item starts in the scrolled content, when items don't simply\n * follow each other from the top, e.g. under group labels. Defaults to\n * the sum of the sizes before it.\n */\n start?: (index: number) => number\n}\n\n/**\n * Item offsets for a list whose items are measured once rendered.\n *\n * Unmeasured items count at their estimate. Rendered items are watched for\n * size changes; when one above the top of the view changes, the scroll\n * position moves by the same amount, so what the reader sees stays put;\n * a move iOS drops during a touch scroll is made once the scroll is over.\n */\nexport function useMeasuredSizes<K>(options: UseMeasuredSizesOptions<K>) {\n const known = new Map<K, number>()\n const touch = useTouchScroll()\n // Bumped when a measurement changes; reading it ties offsets to it.\n const version = shallowRef(0)\n\n const sizeOf = (index: number) => {\n void version.value\n return known.get(options.keyOf(index)) ?? options.estimate(index)\n }\n const offsets = computed(() => createOffsets(options.count(), sizeOf))\n const startOf = (index: number) => options.start?.(index) ?? offsets.value.start(index)\n\n // An item can span several elements, e.g. a table row and its detail row.\n const tracked = new Map<Element, { key: K; index: number }>()\n const byKey = new Map<K, Set<Element>>()\n const heightOf = (key: K) => {\n let size = 0\n for (const element of byKey.get(key) ?? []) size += (element as HTMLElement).offsetHeight\n return size\n }\n\n /** Record new heights for `keys`, keeping the view steady above the top. */\n function update(items: Iterable<{ key: K; index: number }>) {\n let shift = 0\n let changed = false\n const el = options.container()\n const top = el ? scrollPositionOf(el).top : 0\n const seen = new Set<K>()\n for (const { key, index } of items) {\n if (seen.has(key)) continue\n seen.add(key)\n const size = heightOf(key)\n const before = sizeOf(index)\n if (size === before && known.has(key)) continue\n known.set(key, size)\n changed = true\n if (startOf(index) < top) shift += size - before\n }\n if (!changed) return\n version.value++\n if (el && shift) touch.shiftScroll(el, shift)\n }\n\n const observer =\n typeof ResizeObserver === 'undefined'\n ? undefined\n : new ResizeObserver((entries) =>\n update(entries.flatMap((entry) => tracked.get(entry.target) ?? [])),\n )\n\n /** Watch an item's element; call it from a function ref on every render. */\n function track(element: Element | null, key: K, index: number) {\n if (!element) return\n const item = tracked.get(element)\n if (item) {\n if (item.key !== key) {\n byKey.get(item.key)?.delete(element)\n item.key = key\n add(element, key)\n }\n item.index = index\n return\n }\n tracked.set(element, { key, index })\n add(element, key)\n observer?.observe(element)\n }\n function add(element: Element, key: K) {\n let set = byKey.get(key)\n if (!set) byKey.set(key, (set = new Set()))\n set.add(element)\n }\n /** Stop watching elements that left the page, and re-measure what they belonged to. */\n function prune() {\n const touched: { key: K; index: number }[] = []\n for (const [element, item] of tracked) {\n if (element.isConnected) continue\n observer?.unobserve(element)\n tracked.delete(element)\n const set = byKey.get(item.key)\n set?.delete(element)\n // Only re-measure an item still on the page, e.g. a row whose detail closed.\n if (set?.size) touched.push(item)\n else byKey.delete(item.key)\n }\n if (touched.length) update(touched)\n }\n onBeforeUnmount(() => observer?.disconnect())\n\n return { offsets, sizeOf, track, prune }\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,iBAAoB,SAAqC;CACvE,MAAM,wBAAQ,IAAI,IAAe;CACjC,MAAM,QAAQ,eAAe;CAE7B,MAAM,UAAU,WAAW,CAAC;CAE5B,MAAM,UAAU,UAAkB;EAChC,QAAa;EACb,OAAO,MAAM,IAAI,QAAQ,MAAM,KAAK,CAAC,KAAK,QAAQ,SAAS,KAAK;CAClE;CACA,MAAM,UAAU,eAAe,cAAc,QAAQ,MAAM,GAAG,MAAM,CAAC;CACrE,MAAM,WAAW,UAAkB,QAAQ,QAAQ,KAAK,KAAK,QAAQ,MAAM,MAAM,KAAK;CAGtF,MAAM,0BAAU,IAAI,IAAwC;CAC5D,MAAM,wBAAQ,IAAI,IAAqB;CACv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