@aloudata/aloudata-design 3.0.0-beta.17 → 3.0.0-beta.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloudata/aloudata-design",
3
- "version": "3.0.0-beta.17",
3
+ "version": "3.0.0-beta.18",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
@@ -79,6 +79,7 @@
79
79
  "immer": "^10.0.3",
80
80
  "memoize-one": "^6.0.0",
81
81
  "rc-field-form": "^2.7.1",
82
+ "rc-overflow": "^1.3.2",
82
83
  "rc-picker": "^4.11.3",
83
84
  "rc-tree": "^5.13.1",
84
85
  "rc-upload": "^4.8.1",
@@ -1,14 +0,0 @@
1
- import { default as React } from 'react';
2
- interface SimpleOverflowProps<T> {
3
- data: T[];
4
- renderItem: (item: T, index: number) => React.ReactNode;
5
- renderRest?: (omittedItems: T[]) => React.ReactNode;
6
- suffix?: React.ReactNode;
7
- itemKey?: string | ((item: T) => string);
8
- maxCount?: 'responsive' | number;
9
- className?: string;
10
- prefixCls?: string;
11
- onVisibleChange?: (visibleCount: number) => void;
12
- }
13
- export default function SimpleOverflow<T>(props: SimpleOverflowProps<T>): import("react/jsx-runtime").JSX.Element;
14
- export {};
@@ -1,67 +0,0 @@
1
- import { cn } from "../lib/utils.js";
2
- import { useEffect, useRef, useState } from "react";
3
- import { jsx, jsxs } from "react/jsx-runtime";
4
- //#region src/_utils/SimpleOverflow.tsx
5
- function SimpleOverflow(props) {
6
- const { data, renderItem, renderRest, suffix, itemKey, className, prefixCls, onVisibleChange } = props;
7
- const containerRef = useRef(null);
8
- const [visibleCount, setVisibleCount] = useState(data.length);
9
- useEffect(() => {
10
- const container = containerRef.current;
11
- if (!container) return;
12
- const measure = () => {
13
- if (!container.offsetWidth) return;
14
- const overflowItems = [];
15
- for (const child of Array.from(container.children)) if (child.dataset.overflowItem === "true") overflowItems.push(child);
16
- if (overflowItems.length === 0) return;
17
- const savedDisplays = overflowItems.map((el) => el.style.display);
18
- overflowItems.forEach((el) => {
19
- el.style.display = "";
20
- });
21
- container.offsetHeight;
22
- const containerRect = container.getBoundingClientRect();
23
- const allFit = container.scrollWidth <= container.clientWidth + 1;
24
- let newCount;
25
- if (allFit) newCount = data.length;
26
- else {
27
- let count = 0;
28
- for (const el of overflowItems) if (el.getBoundingClientRect().right <= containerRect.right - 40) count++;
29
- else break;
30
- newCount = Math.min(count, data.length);
31
- }
32
- overflowItems.forEach((el, i) => {
33
- el.style.display = savedDisplays[i];
34
- });
35
- setVisibleCount(newCount);
36
- onVisibleChange?.(newCount === 0 ? -1 : newCount);
37
- };
38
- measure();
39
- const ro = new window.ResizeObserver(measure);
40
- ro.observe(container);
41
- return () => ro.disconnect();
42
- }, [data.length, onVisibleChange]);
43
- const getKey = (item, index) => {
44
- if (typeof itemKey === "function") return itemKey(item);
45
- if (typeof itemKey === "string") return item[itemKey];
46
- return String(index);
47
- };
48
- const omittedItems = data.slice(visibleCount);
49
- return /* @__PURE__ */ jsxs("div", {
50
- ref: containerRef,
51
- className: cn(prefixCls, "tw-flex tw-flex-nowrap tw-items-center tw-overflow-hidden", className),
52
- children: [
53
- data.map((item, index) => /* @__PURE__ */ jsx("div", {
54
- "data-overflow-item": "true",
55
- className: prefixCls ? `${prefixCls}-item` : void 0,
56
- style: { display: index < visibleCount ? void 0 : "none" },
57
- children: renderItem(item, index)
58
- }, getKey(item, index))),
59
- omittedItems.length > 0 && renderRest?.(omittedItems),
60
- suffix
61
- ]
62
- });
63
- }
64
- //#endregion
65
- export { SimpleOverflow as default };
66
-
67
- //# sourceMappingURL=SimpleOverflow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SimpleOverflow.js","names":[],"sources":["../../src/_utils/SimpleOverflow.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { cn } from '../lib/utils';\n\ninterface SimpleOverflowProps<T> {\n data: T[];\n renderItem: (item: T, index: number) => React.ReactNode;\n renderRest?: (omittedItems: T[]) => React.ReactNode;\n suffix?: React.ReactNode;\n itemKey?: string | ((item: T) => string);\n maxCount?: 'responsive' | number;\n className?: string;\n prefixCls?: string;\n onVisibleChange?: (visibleCount: number) => void;\n}\n\nexport default function SimpleOverflow<T>(props: SimpleOverflowProps<T>) {\n const {\n data,\n renderItem,\n renderRest,\n suffix,\n itemKey,\n className,\n prefixCls,\n onVisibleChange,\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [visibleCount, setVisibleCount] = useState(data.length);\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n const measure = () => {\n // 容器隐藏时跳过测量(-1 降级路径会把容器置 display:none):\n // 0 尺寸会被误判为 allFit,与 -1 状态互相翻转形成 setState 死循环\n if (!container.offsetWidth) return;\n const overflowItems: HTMLElement[] = [];\n for (const child of Array.from(container.children)) {\n if ((child as HTMLElement).dataset.overflowItem === 'true') {\n overflowItems.push(child as HTMLElement);\n }\n }\n if (overflowItems.length === 0) return;\n\n // Temporarily show all items so we can measure their natural positions\n const savedDisplays = overflowItems.map((el) => el.style.display);\n overflowItems.forEach((el) => {\n el.style.display = '';\n });\n // Force synchronous reflow\n void container.offsetHeight;\n\n const containerRect = container.getBoundingClientRect();\n // 容器无横向溢出 → 全部显示,不做 +N 预留。\n // width:auto 的 Select 容器恰好包住内容(右侧余量 0),按固定预留量判定会把\n // 放得下的 tag 误判为放不下,导致被 overflow:hidden 裁掉右侧\n const allFit = container.scrollWidth <= container.clientWidth + 1;\n let newCount: number;\n if (allFit) {\n newCount = data.length;\n } else {\n let count = 0;\n for (const el of overflowItems) {\n const rect = el.getBoundingClientRect();\n // 40px 预留给 \"+N\" 计数节点\n if (rect.right <= containerRect.right - 40) {\n count++;\n } else {\n break;\n }\n }\n newCount = Math.min(count, data.length);\n }\n\n // Restore display values before React re-renders\n overflowItems.forEach((el, i) => {\n el.style.display = savedDisplays[i];\n });\n\n setVisibleCount(newCount);\n // 一个都放不下时上报 -1,触发消费方(MultipleSelector)的\n // overflow-item-first 降级路径:首个 tag 可收缩 + 文本省略,保住关闭按钮\n onVisibleChange?.(newCount === 0 ? -1 : newCount);\n };\n\n measure();\n const ro = new window.ResizeObserver(measure);\n ro.observe(container);\n return () => ro.disconnect();\n }, [data.length, onVisibleChange]);\n\n const getKey = (item: T, index: number) => {\n if (typeof itemKey === 'function') return itemKey(item);\n if (typeof itemKey === 'string')\n return (item as Record<string, string>)[itemKey];\n return String(index);\n };\n\n const omittedItems = data.slice(visibleCount);\n\n return (\n <div\n ref={containerRef}\n className={cn(\n prefixCls,\n 'tw-flex tw-flex-nowrap tw-items-center tw-overflow-hidden',\n className,\n )}\n >\n {data.map((item, index) => (\n <div\n key={getKey(item, index)}\n data-overflow-item=\"true\"\n className={prefixCls ? `${prefixCls}-item` : undefined}\n style={{\n display: index < visibleCount ? undefined : 'none',\n }}\n >\n {renderItem(item, index)}\n </div>\n ))}\n {omittedItems.length > 0 && renderRest?.(omittedItems)}\n {suffix}\n </div>\n );\n}\n"],"mappings":";;;;AAeA,SAAwB,eAAkB,OAA+B;CACvE,MAAM,EACJ,MACA,YACA,YACA,QACA,SACA,WACA,WACA,oBACE;CAEJ,MAAM,eAAe,OAAuB,KAAK;CACjD,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK,OAAO;AAE7D,iBAAgB;EACd,MAAM,YAAY,aAAa;AAC/B,MAAI,CAAC,UAAW;EAEhB,MAAM,gBAAgB;AAGpB,OAAI,CAAC,UAAU,YAAa;GAC5B,MAAM,gBAA+B,EAAE;AACvC,QAAK,MAAM,SAAS,MAAM,KAAK,UAAU,SAAS,CAChD,KAAK,MAAsB,QAAQ,iBAAiB,OAClD,eAAc,KAAK,MAAqB;AAG5C,OAAI,cAAc,WAAW,EAAG;GAGhC,MAAM,gBAAgB,cAAc,KAAK,OAAO,GAAG,MAAM,QAAQ;AACjE,iBAAc,SAAS,OAAO;AAC5B,OAAG,M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