@univerjs/design 0.20.1 → 0.21.0
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/lib/cjs/index.js +4212 -25
- package/lib/cjs/locale/ca-ES.js +54 -1
- package/lib/cjs/locale/en-US.js +69 -1
- package/lib/cjs/locale/es-ES.js +54 -1
- package/lib/cjs/locale/fa-IR.js +54 -1
- package/lib/cjs/locale/fr-FR.js +54 -1
- package/lib/cjs/locale/ja-JP.js +54 -1
- package/lib/cjs/locale/ko-KR.js +54 -1
- package/lib/cjs/locale/ru-RU.js +54 -1
- package/lib/cjs/locale/sk-SK.js +54 -1
- package/lib/cjs/locale/vi-VN.js +54 -1
- package/lib/cjs/locale/zh-CN.js +54 -1
- package/lib/cjs/locale/zh-TW.js +54 -1
- package/lib/es/index.js +4146 -25
- package/lib/es/locale/ca-ES.js +53 -1
- package/lib/es/locale/en-US.js +68 -1
- package/lib/es/locale/es-ES.js +53 -1
- package/lib/es/locale/fa-IR.js +53 -1
- package/lib/es/locale/fr-FR.js +53 -1
- package/lib/es/locale/ja-JP.js +53 -1
- package/lib/es/locale/ko-KR.js +53 -1
- package/lib/es/locale/ru-RU.js +53 -1
- package/lib/es/locale/sk-SK.js +53 -1
- package/lib/es/locale/vi-VN.js +53 -1
- package/lib/es/locale/zh-CN.js +53 -1
- package/lib/es/locale/zh-TW.js +53 -1
- package/lib/index.js +4146 -25
- package/lib/locale/ca-ES.js +53 -1
- package/lib/locale/en-US.js +68 -1
- package/lib/locale/es-ES.js +53 -1
- package/lib/locale/fa-IR.js +53 -1
- package/lib/locale/fr-FR.js +53 -1
- package/lib/locale/ja-JP.js +53 -1
- package/lib/locale/ko-KR.js +53 -1
- package/lib/locale/ru-RU.js +53 -1
- package/lib/locale/sk-SK.js +53 -1
- package/lib/locale/vi-VN.js +53 -1
- package/lib/locale/zh-CN.js +53 -1
- package/lib/locale/zh-TW.js +53 -1
- package/lib/umd/index.js +23 -23
- package/package.json +4 -4
package/lib/es/index.js
CHANGED
|
@@ -1,84 +1,4205 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CalendarIcon, CheckMarkIcon, ClockIcon, CloseIcon, DeleteIcon, DownIcon, DropdownIcon, ErrorIcon, InfoIcon, LoadingMultiIcon, MoreDownIcon, MoreLeftIcon, MoreRightIcon, MoreUpIcon, OneToOneIcon, SuccessIcon, WarningIcon, ZoomInIcon, ZoomOutIcon } from "@univerjs/icons";
|
|
2
|
+
import { Children, cloneElement, createContext, forwardRef, isValidElement, memo, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { clsx as clsx$1 } from "clsx";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { cva } from "class-variance-authority";
|
|
7
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
8
|
+
import { Close, Content, Description, Overlay, Portal, Root, Title } from "@radix-ui/react-dialog";
|
|
9
|
+
import { Content as Content$1, Portal as Portal$1, Root as Root$1, Trigger } from "@radix-ui/react-popover";
|
|
10
|
+
import { createPortal } from "react-dom";
|
|
11
|
+
import { CheckboxItem, Content as Content$2, Item, ItemIndicator, Portal as Portal$2, RadioGroup as RadioGroup$1, RadioItem, Root as Root$2, Separator as Separator$1, Sub, SubContent, SubTrigger, Trigger as Trigger$1 } from "@radix-ui/react-dropdown-menu";
|
|
12
|
+
import { Content as Content$3, Portal as Portal$3, Root as Root$3, Trigger as Trigger$2 } from "@radix-ui/react-hover-card";
|
|
13
|
+
import { Toaster as Toaster$1, toast, toast as toast$1 } from "sonner";
|
|
14
|
+
import { CSSTransition } from "react-transition-group";
|
|
15
|
+
import { Root as Root$4 } from "@radix-ui/react-separator";
|
|
16
|
+
import { createRoot } from "react-dom/client";
|
|
17
|
+
|
|
18
|
+
//#region src/helper/clsx.ts
|
|
19
|
+
function clsx(...inputs) {
|
|
20
|
+
return twMerge(clsx$1(inputs));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/components/accordion/Accordion.tsx
|
|
25
|
+
function Accordion(props) {
|
|
26
|
+
const { className, items } = props;
|
|
27
|
+
const [openIndex, setOpenIndex] = useState(null);
|
|
28
|
+
const toggleItem = (index) => {
|
|
29
|
+
setOpenIndex(openIndex === index ? null : index);
|
|
30
|
+
};
|
|
31
|
+
return /* @__PURE__ */ jsx("div", {
|
|
32
|
+
"data-u-comp": "accordion",
|
|
33
|
+
className: clsx("univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200 dark:!univer-divide-gray-600", className),
|
|
34
|
+
children: items.map((item, index) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("button", {
|
|
35
|
+
className: "univer-box-border univer-flex univer-w-full univer-cursor-pointer univer-items-center univer-gap-1.5 univer-border-none univer-bg-transparent univer-p-4 univer-text-left univer-text-gray-700 hover:univer-text-gray-900 focus:univer-outline-none dark:!univer-text-gray-200 dark:hover:!univer-text-white",
|
|
36
|
+
type: "button",
|
|
37
|
+
onClick: () => toggleItem(index),
|
|
38
|
+
children: [/* @__PURE__ */ jsx(DownIcon, { className: clsx("univer-size-2.5 univer-flex-shrink-0 univer-transition-transform", {
|
|
39
|
+
"-univer-rotate-90": openIndex !== index,
|
|
40
|
+
"univer-rotate-0": openIndex === index
|
|
41
|
+
}) }), /* @__PURE__ */ jsx("span", {
|
|
42
|
+
className: "univer-font-medium",
|
|
43
|
+
children: item.label
|
|
44
|
+
})]
|
|
45
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
46
|
+
className: clsx("univer-overflow-hidden univer-transition-[max-height,opacity] univer-duration-500 univer-ease-in-out", {
|
|
47
|
+
"univer-max-h-screen": openIndex === index,
|
|
48
|
+
"univer-max-h-0": openIndex !== index
|
|
49
|
+
}),
|
|
50
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
51
|
+
className: "univer-box-border univer-px-4 univer-py-1.5",
|
|
52
|
+
children: item.children
|
|
53
|
+
})
|
|
54
|
+
})] }, index))
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/components/avatar/Avatar.tsx
|
|
60
|
+
const avatarVariants = cva(`
|
|
2
61
|
univer-relative univer-inline-block univer-overflow-hidden univer-whitespace-nowrap univer-bg-gray-200
|
|
3
62
|
univer-text-center univer-align-middle univer-text-white
|
|
4
|
-
`,
|
|
63
|
+
`, {
|
|
64
|
+
variants: {
|
|
65
|
+
shape: {
|
|
66
|
+
circle: "univer-rounded-full",
|
|
67
|
+
square: "univer-rounded"
|
|
68
|
+
},
|
|
69
|
+
size: {
|
|
70
|
+
middle: "univer-size-9 univer-leading-9",
|
|
71
|
+
small: "univer-size-7 univer-leading-7"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
defaultVariants: {
|
|
75
|
+
shape: "circle",
|
|
76
|
+
size: "middle"
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Avatar Component
|
|
81
|
+
*/
|
|
82
|
+
function Avatar(props) {
|
|
83
|
+
const { children, className, style, title, alt, shape = "circle", size = "middle", src, fit = "fill", onError, onLoad } = props;
|
|
84
|
+
const sizeStyle = typeof size === "number" ? {
|
|
85
|
+
width: `${size}px`,
|
|
86
|
+
height: `${size}px`,
|
|
87
|
+
lineHeight: `${size}px`
|
|
88
|
+
} : {};
|
|
89
|
+
const fitStyle = { objectFit: fit };
|
|
90
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
91
|
+
className: clsx(avatarVariants({
|
|
92
|
+
shape,
|
|
93
|
+
size: typeof size === "number" ? "middle" : size
|
|
94
|
+
}), { "univer-bg-transparent": src }, className),
|
|
95
|
+
style: {
|
|
96
|
+
...sizeStyle,
|
|
97
|
+
...style,
|
|
98
|
+
...src && fitStyle
|
|
99
|
+
},
|
|
100
|
+
children: [src && /* @__PURE__ */ jsx("img", {
|
|
101
|
+
className: "univer-block univer-size-full",
|
|
102
|
+
src,
|
|
103
|
+
title,
|
|
104
|
+
alt,
|
|
105
|
+
onError,
|
|
106
|
+
onLoad
|
|
107
|
+
}), children]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/components/badge/Badge.tsx
|
|
113
|
+
function Badge(props) {
|
|
114
|
+
const { className, children, closable = false, onClose } = props;
|
|
115
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
116
|
+
"data-u-comp": "badge",
|
|
117
|
+
className: clsx("univer-box-border univer-inline-flex univer-items-center univer-gap-1 univer-truncate univer-rounded-md univer-border univer-border-solid univer-border-gray-100 univer-bg-gray-100 univer-px-2.5 univer-py-0.5 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-border-gray-500 dark:!univer-bg-gray-700 dark:!univer-text-gray-300", className),
|
|
118
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
119
|
+
className: "univer-flex-1 univer-truncate",
|
|
120
|
+
children
|
|
121
|
+
}), closable && /* @__PURE__ */ jsx("button", {
|
|
122
|
+
className: "univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-p-0 univer-outline-none univer-transition-opacity hover:univer-opacity-70",
|
|
123
|
+
type: "button",
|
|
124
|
+
"aria-label": "Close badge",
|
|
125
|
+
onClick: onClose,
|
|
126
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { className: "univer-text-current" })
|
|
127
|
+
})]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/components/button/Button.tsx
|
|
133
|
+
const buttonVariants = cva(`
|
|
5
134
|
univer-box-border univer-inline-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
6
135
|
univer-justify-center univer-gap-2 univer-whitespace-nowrap univer-rounded-md univer-border univer-border-solid
|
|
7
136
|
univer-text-sm univer-font-medium univer-transition-colors
|
|
8
137
|
disabled:univer-pointer-events-none disabled:univer-cursor-not-allowed disabled:univer-opacity-50
|
|
9
138
|
[&_svg]:univer-pointer-events-none [&_svg]:univer-size-4 [&_svg]:univer-shrink-0
|
|
10
|
-
`,{
|
|
139
|
+
`, {
|
|
140
|
+
variants: {
|
|
141
|
+
variant: {
|
|
142
|
+
default: `
|
|
11
143
|
univer-border-gray-200 univer-bg-white univer-text-gray-700
|
|
12
144
|
hover:univer-bg-gray-100
|
|
13
145
|
active:univer-bg-gray-200
|
|
14
146
|
dark:!univer-border-gray-600 dark:!univer-bg-gray-700 dark:!univer-text-white
|
|
15
147
|
dark:hover:!univer-bg-gray-600
|
|
16
148
|
dark:active:!univer-bg-gray-700
|
|
17
|
-
`,
|
|
149
|
+
`,
|
|
150
|
+
primary: `
|
|
18
151
|
univer-border-primary-600 univer-bg-primary-600 univer-text-white
|
|
19
152
|
hover:univer-bg-primary-500
|
|
20
153
|
active:univer-bg-primary-700
|
|
21
|
-
`,
|
|
154
|
+
`,
|
|
155
|
+
danger: `
|
|
22
156
|
univer-border-red-500 univer-bg-red-500 univer-text-white
|
|
23
157
|
hover:univer-border-red-400 hover:univer-bg-red-400
|
|
24
158
|
active:univer-border-red-600 active:univer-bg-red-600
|
|
25
|
-
`,
|
|
159
|
+
`,
|
|
160
|
+
text: `
|
|
26
161
|
univer-border-transparent univer-bg-transparent univer-text-gray-900
|
|
27
162
|
hover:univer-bg-gray-100
|
|
28
163
|
active:univer-bg-gray-200
|
|
29
164
|
dark:!univer-text-white
|
|
30
165
|
dark:hover:!univer-bg-gray-700
|
|
31
166
|
dark:active:!univer-bg-gray-600
|
|
32
|
-
`,
|
|
167
|
+
`,
|
|
168
|
+
link: `
|
|
33
169
|
univer-underline-current univer-border-transparent univer-bg-transparent univer-text-primary-600
|
|
34
170
|
univer-underline-offset-4
|
|
35
171
|
hover:univer-text-primary-500 hover:univer-underline
|
|
36
172
|
active:univer-text-primary-700
|
|
37
|
-
`,
|
|
173
|
+
`,
|
|
174
|
+
ghost: `
|
|
38
175
|
univer-border-transparent univer-bg-transparent univer-text-gray-900
|
|
39
176
|
hover:univer-bg-gray-100
|
|
40
177
|
active:univer-bg-gray-200
|
|
41
178
|
dark:!univer-text-white
|
|
42
179
|
dark:hover:!univer-bg-gray-700
|
|
43
180
|
dark:active:!univer-bg-gray-600
|
|
44
|
-
`},size:{small:`univer-h-6 univer-rounded-md univer-px-1.5 univer-text-xs`,middle:`univer-h-8 univer-rounded-lg univer-px-2 univer-text-sm`,large:`univer-h-10 univer-rounded-lg univer-px-3 univer-text-sm`}},defaultVariants:{variant:`default`,size:`middle`}}),G=S(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>I(r?z:`button`,{className:W(Fe({variant:t,size:n,className:e})),ref:a,"data-u-comp":`button`,...i}));G.displayName=`Button`;const Ie=({className:e,orientation:t=`horizontal`,children:n})=>{let r=y.count(n),i=t===`horizontal`,a=t===`vertical`;return I(`div`,{className:W(`univer-grid`,{"univer-grid-flow-row":a,"univer-w-fit":a},e),children:y.map(n,(e,t)=>{let n=t===0,o=t===r-1;return b(e,{className:W({"!univer-rounded-l-none":i&&!n,"!univer-rounded-r-none":i&&!o,"!univer-border-l-0":i&&!n,"!univer-rounded-t-none":a&&!n,"!univer-rounded-b-none":a&&!o,"!univer-border-t-0":a&&!n},e.props.className)})})})};function Le(){return typeof window<`u`&&typeof document<`u`}const K=x({mountContainer:Le()?document.body:null});function Re(e){let{children:t,locale:n,mountContainer:r}=e,i=A(()=>({locale:n,mountContainer:r}),[n,r]);return I(K.Provider,{value:i,children:t})}const q=`univer-scrollbar-thin univer-scrollbar-track-gray-50 univer-scrollbar-thumb-gray-300 dark:!univer-scrollbar-track-gray-900 dark:!univer-scrollbar-thumb-gray-700`,J=`univer-border-gray-200 dark:!univer-border-gray-600 univer-border-solid`,Y=W(J,`univer-border`),ze=W(J,`univer-border-l univer-border-b univer-border-t-0 univer-border-r-0`),Be=W(J,`univer-border-l univer-border-b-0 univer-border-t-0 univer-border-r-0`),Ve=W(J,`univer-border-b-0 univer-border-t-0 rtl:univer-border-l-0 rtl:univer-border-r`),He=W(J,`univer-border-l-0 univer-border-b-0 univer-border-t univer-border-r-0`),Ue=W(J,`univer-border-l-0 univer-border-b univer-border-t-0 univer-border-r-0`),We=W(J,`univer-border-l-0 univer-border-b-0 univer-border-t-0 univer-border-r`),Ge=`univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-y univer-divide-x-0 univer-divide-solid`,Ke=`univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-x univer-divide-y-0 univer-divide-solid`;function X(e,t=2){return String(e).padStart(t,`0`)}function qe(e,t){let n=e==null?new Date:e;if(Number.isNaN(n.getTime()))return`Invalid Date`;let r={YYYY:String(n.getFullYear()),MM:X(n.getMonth()+1),DD:X(n.getDate()),HH:X(n.getHours()),mm:X(n.getMinutes()),ss:X(n.getSeconds())};return t.replace(/YYYY|MM|DD|HH|mm|ss/g,e=>{var t;return(t=r[e])==null?e:t})}function Je(e){let{className:t,value:r,onValueChange:i}=e;function a(e){let[t,n,a]=e.target.value.split(`:`).map(Number),o=new Date(r==null?Date.now():r);o.setHours(t,n,a,0),i==null||i(o)}return L(`div`,{"data-u-comp":`time-input`,className:`univer-relative univer-mx-auto univer-mt-1 univer-w-fit`,children:[I(n,{className:`univer-absolute univer-left-2 univer-top-1/2 -univer-translate-y-1/2 univer-text-gray-600 dark:!univer-text-gray-400`}),I(`input`,{className:W(`univer-block univer-h-7 univer-w-fit univer-appearance-none univer-rounded-md univer-bg-transparent univer-pl-6 univer-pr-2 univer-text-center univer-text-gray-800 univer-shadow univer-outline-none univer-transition-all univer-duration-200 focus:univer-border-primary-600 dark:!univer-text-white dark:focus:!univer-border-primary-500 [&::-webkit-calendar-picker-indicator]:univer-hidden [&::-webkit-calendar-picker-indicator]:univer-appearance-none`,Y,t),type:`time`,step:`1`,value:qe(r,`HH:mm:ss`),onChange:a})]})}function Ye(e,t){return new Date(e,t+1,0).getDate()}function Xe(e,t){return new Date(e,t,1).getDay()}function Ze(e){let{className:t,...n}=e;return I(`button`,{className:W(`univer-size-7 univer-rounded-md univer-border-none univer-bg-transparent univer-p-1 univer-transition-all hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600`,t),type:`button`,...n})}function Qe(e){let{className:t,max:n,min:r,showTime:i=!1,value:a,onValueChange:o}=e,{locale:s}=E(K),{year:c,weekDays:l,months:u}=s==null?void 0:s.Calendar,d=new Date,[p,m]=M((a==null?d:a).getFullYear()),[h,g]=M((a==null?d:a).getMonth());function _(){g(e=>e===0?(m(e=>e-1),11):e-1)}function v(){g(e=>e===11?(m(e=>e+1),0):e+1)}let y=Ye(p,h),b=Xe(p,h),x=A(()=>{let e=[];for(let t=0;t<b;t++)e.push(null);for(let t=1;t<=y;t++)e.push(t);return e},[y,b]);function S(e){return e&&p===(a==null?void 0:a.getFullYear())&&h===(a==null?void 0:a.getMonth())&&e===(a==null?void 0:a.getDate())}function C(e){return e&&p===d.getFullYear()&&h===d.getMonth()&&e===d.getDate()}function w(e){var t,i,o;if(!e)return!1;let s=(t=a==null?void 0:a.getHours())==null?d.getHours():t,c=(i=a==null?void 0:a.getMinutes())==null?d.getMinutes():i,l=(o=a==null?void 0:a.getSeconds())==null?d.getSeconds():o,u=new Date(p,h,e,s,c,l);return!!(r&&u<r||n&&u>n)}function T(e){var t,n,r;if(w(e))return;let i=(t=a==null?void 0:a.getHours())==null?d.getHours():t,s=(n=a==null?void 0:a.getMinutes())==null?d.getMinutes():n,c=(r=a==null?void 0:a.getSeconds())==null?d.getSeconds():r;o==null||o(new Date(p,h,e,i,s,c))}function D(e){var t;let n=e.getHours(),r=e.getMinutes(),i=e.getSeconds(),s=new Date(p,h,(t=a==null?void 0:a.getDate())==null?d.getDate():t,n,r,i);o==null||o(s)}return L(`div`,{"data-u-comp":`calendar`,className:W(`univer-mx-auto univer-max-w-xs univer-select-none univer-rounded univer-bg-white univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-white`,t),children:[L(`nav`,{className:`univer-mb-4 univer-flex univer-items-center univer-justify-between`,children:[I(Ze,{className:`univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200`,"aria-label":`Previous Month`,onClick:_,children:I(f,{className:`univer-rotate-180`})}),L(`span`,{className:`univer-flex univer-gap-0.5 univer-text-sm univer-font-medium`,children:[I(`span`,{children:p}),I(`span`,{children:c}),I(`span`,{children:u[h]})]}),I(Ze,{className:`univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200`,"aria-label":`Next Month`,onClick:v,children:I(f,{})})]}),I(`div`,{className:`univer-mb-1 univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center univer-text-sm univer-text-gray-500 dark:!univer-text-gray-200`,children:l.map(e=>I(`div`,{children:e},e))}),I(`div`,{className:`univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center`,children:x.map((e,t)=>e?I(Ze,{className:W({"!univer-bg-primary-600 univer-font-bold univer-text-white":!C(e)&&S(e),"dark:!univer-text-white":!C(e)&&!S(e),"!univer-bg-primary-600 univer-text-white":C(e)&&S(e),"univer-font-semibold univer-text-primary-600 dark:!univer-text-primary-500":C(e)&&!S(e),"univer-cursor-not-allowed univer-opacity-40":w(e),"univer-hover:bg-primary-100 univer-cursor-pointer univer-text-gray-800":!S(e)&&!w(e)}),onClick:()=>T(e),disabled:w(e),children:e},t):I(`div`,{},t))}),i&&I(Je,{value:a,onValueChange:D})]})}function $e({emptyText:e}){return I(`section`,{className:`univer-h-8 univer-px-2 univer-pr-32 univer-text-sm/8 univer-text-gray-600 dark:!univer-text-gray-200`,children:e})}function et(e){let{value:n,options:r=[],onChange:i,contentClassName:a,wrapperClassName:o}=e,{locale:s}=E(K),c=A(()=>{let e=[r];return n.forEach((t,n)=>{let r=e[n].find(e=>e.value===t);r!=null&&r.children&&e.push(r.children)}),e},[n]);function l(e,t){if(t===n[e])return;if(n[e+1]){let r=n.slice(0,e+1);r[e]=t,i(r);return}let r=[...n];r[e]=t,i(r)}return L(`section`,{"data-u-comp":`cascader-list`,className:W(`univer-overflow-auto-y univer-grid univer-h-full univer-max-h-80 univer-grid-flow-col univer-rounded univer-py-2 univer-text-gray-900 dark:!univer-text-white [&>ul:not(:last-child)]:univer-border-0 [&>ul:not(:last-child)]:univer-border-r [&>ul:not(:last-child)]:univer-border-solid [&>ul:not(:last-child)]:univer-border-r-gray-200`,Y,q,o),children:[c.map((e,r)=>e.length?I(`ul`,{className:W(`univer-m-0 univer-h-full univer-max-h-full univer-list-none univer-overflow-auto univer-px-2`,q,a),children:e.map(e=>I(`li`,{children:L(`a`,{className:W(`univer-relative univer-block univer-h-8 univer-cursor-pointer univer-rounded univer-text-sm/8`,{"univer-px-7":r>0,"univer-px-1.5":r===0,"univer-bg-gray-200 dark:!univer-bg-gray-600":e.value===n[r]}),onClick:()=>l(r,e.value),children:[r>0&&I(`span`,{className:`univer-absolute univer-left-2 univer-flex univer-h-full univer-items-center`,children:e.value===n[r]&&I(t,{className:`univer-text-primary-600`})}),I(`span`,{children:e.label})]})},e.value))},r):I($e,{emptyText:s==null?void 0:s.CascaderList.empty},r)),n.length<=0&&I($e,{emptyText:s==null?void 0:s.CascaderList.empty})]})}function tt(e){let{children:t,className:n,style:r,value:i,disabled:a,direction:o=`horizontal`,onChange:s}=e,c=e=>{i.includes(e)?s(i.filter(t=>t!==e)):s([...i,e])};return I(`div`,{className:W(`univer-flex univer-gap-2`,{"univer-flex-col":o===`vertical`},n),style:r,children:y.map(t,(e,t)=>C(e)?b(e,{key:t,children:e.props.children,checked:e.props.value?i.includes(e.props.value):!1,disabled:a==null?e.props.disabled:a,onChange:c}):e)})}function nt(e){let{children:n,className:r,style:i,checked:a=!1,indeterminate:o=!1,value:s,disabled:c=!1,onChange:l,contentClassName:u}=e,d=j(null);function f(e){if(e.stopPropagation(),!(!l||c))if(s!==void 0)l==null||l(s);else{var t,n;let e=(t=d==null||(n=d.current)==null?void 0:n.checked)==null?!1:t;l==null||l(e)}}return L(`label`,{"data-u-comp":`checkbox`,className:W(`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm`,{"univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white":!c,"univer-text-gray-400":c},r),style:i,children:[L(`span`,{className:`univer-relative univer-block`,children:[I(`input`,{ref:d,className:`univer-absolute univer-size-0 univer-opacity-0`,type:`checkbox`,checked:a,disabled:c,onChange:f}),L(`span`,{className:W(`univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded univer-border univer-border-solid univer-transition-colors`,{"univer-opacity-50":c,"univer-border-primary-600 univer-bg-primary-600":a||o,"univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600":!a&&!o}),children:[a&&I(t,{className:`univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-3 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-text-white`}),o&&!a&&I(`span`,{className:`univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-h-0.5 univer-w-2.5 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded univer-bg-white`})]})]}),I(`span`,{className:W(`univer-select-none`,u),children:n})]})}const rt=ne,it=te,at=S(({className:e,...t},n)=>I(H,{ref:n,className:W(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 univer-fixed univer-inset-0 univer-z-[1080] univer-bg-[rgba(0,0,0,0.8)]`,e),...t}));at.displayName=H.displayName;const ot=S(({className:e,children:t,closable:n=!0,onClickClose:i,...a},o)=>L(it,{children:[I(at,{}),L(B,{ref:o,className:W(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=open]:univer-slide-in-from-left-1/2 data-[state=open]:univer-slide-in-from-top-[48%] data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[state=closed]:univer-slide-out-to-left-1/2 data-[state=closed]:univer-slide-out-to-top-[48%] univer-fixed univer-left-1/2 univer-top-1/2 univer-z-[1080] univer-box-border univer-grid univer-w-full univer-max-w-lg -univer-translate-x-1/2 -univer-translate-y-1/2 univer-gap-4 univer-bg-white univer-p-4 univer-text-gray-500 univer-shadow-md univer-duration-200 sm:!univer-rounded-lg dark:!univer-bg-gray-700 dark:!univer-text-gray-400`,Y,e),...a,children:[t,n&&L(ee,{className:`univer-absolute univer-right-4 univer-top-4 univer-size-6 univer-cursor-pointer univer-rounded-sm univer-border-none univer-bg-transparent univer-p-0 univer-transition-opacity hover:univer-opacity-100 disabled:univer-pointer-events-none`,onClick:i,children:[I(r,{className:`univer-size-4 univer-text-gray-400`}),I(`span`,{className:`univer-sr-only`,children:`Close`})]})]})]}));ot.displayName=B.displayName;const st=({className:e,...t})=>I(`div`,{className:W(`univer-flex univer-flex-col univer-space-y-1.5 univer-text-center sm:!univer-text-left`,e),...t});st.displayName=`DialogHeader`;const ct=({className:e,...t})=>I(`div`,{className:W(`univer-flex univer-flex-col-reverse sm:!univer-flex-row sm:!univer-justify-end sm:!univer-space-x-2`,e),...t});ct.displayName=`DialogFooter`;const lt=S(({className:e,...t},n)=>I(re,{ref:n,className:W(`univer-my-0 univer-text-lg univer-font-semibold univer-leading-none univer-tracking-tight univer-text-gray-900 dark:!univer-text-white`,e),...t}));lt.displayName=re.displayName;const ut=S(({className:e,...t},n)=>I(V,{ref:n,className:W(`univer-text-sm univer-text-gray-500`,e),...t}));ut.displayName=V.displayName;function dt(e={}){let t=T(()=>{let{innerWidth:e,innerHeight:t}=window;return{x:Math.max(0,(e-0)/2),y:Math.max(0,(t-0)/2)}},[]),{defaultPosition:n=t(),enabled:r=!1}=e,[i,a]=M(n),[o,s]=M(!1),c=j(null),l=j({x:0,y:0}),u=j({x:0,y:0}),d=j(!1);D(()=>{if(!c.current||d.current||e.defaultPosition)return;let{width:t,height:n}=c.current.getBoundingClientRect(),{innerWidth:r,innerHeight:i}=window,o=Math.max(0,(r-t)/2),s=Math.max(0,(i-n)/2);a({x:o,y:s}),l.current={x:o,y:s},d.current=!0},[e.defaultPosition]);let f=T((e,t)=>{if(!c.current)return{x:e,y:t};let n=c.current.getBoundingClientRect(),{clientWidth:r,clientHeight:i}=document.documentElement,a=l.current.x+(e-u.current.x),o=l.current.y+(t-u.current.y);return a<0&&(a=0),o<0&&(o=0),a+n.width>r&&(a=r-n.width),o+n.height>i&&(o=i-n.height),{x:a,y:o}},[]),p=T(e=>{r&&(e.preventDefault(),e.stopPropagation(),l.current={...i},u.current={x:e.clientX,y:e.clientY},s(!0),document.body.style.userSelect=`none`)},[r,i]),m=T(e=>{o&&(e.preventDefault(),e.stopPropagation(),a(f(e.clientX,e.clientY)))},[o,f]),h=T(()=>{s(!1),document.body.style.userSelect=``},[]);return D(()=>{if(r)return document.addEventListener(`mousemove`,m),document.addEventListener(`mouseup`,h),()=>{document.removeEventListener(`mousemove`,m),document.removeEventListener(`mouseup`,h)}},[r,m,h]),{position:i,isDragging:o,elementRef:c,setElementRef:t=>{if(c.current=t,t&&!d.current&&!e.defaultPosition){let{width:e,height:n}=t.getBoundingClientRect(),{innerWidth:r,innerHeight:i}=window,o=Math.max(0,(r-e)/2),s=Math.max(0,(i-n)/2);a({x:o,y:s}),l.current={x:o,y:s},d.current=!0}},handleMouseDown:p}}function ft(e){var t,n,r,i;let{className:a,children:o,style:s,open:c=!1,title:l,width:u,draggable:d=!1,defaultPosition:f,footer:p,mask:m=!0,keyboard:h=!0,closable:g=!0,maskClosable:_=!0,showOk:v,showCancel:y,onOpenChange:b,onClose:x,onOk:S,onCancel:C}=e,{locale:w}=E(K),{position:D,isDragging:O,setElementRef:k,handleMouseDown:A}=dt({defaultPosition:f,enabled:d}),j=p==null?v||y?L(`div`,{className:`univer-flex univer-justify-end univer-gap-2`,children:[y&&I(G,{onClick:C,children:(t=w==null||(n=w.Confirm)==null?void 0:n.cancel)==null?`Cancel`:t}),v&&I(G,{variant:`primary`,onClick:S,children:(r=w==null||(i=w.Confirm)==null?void 0:i.confirm)==null?`OK`:r})]}):null:p,M=T(e=>{e&&d&&k(e)},[d,k]),N=T(e=>{!m&&!e||(b==null||b(e),e||x==null||x())},[x,b]);function P(){b==null||b(!1),x==null||x()}return I(rt,{open:c,onOpenChange:N,modal:m!==!1,children:L(ot,{ref:M,className:W(a,{"!univer-animate-none":d}),style:{...s,width:u?typeof u==`number`?`${u}px`:u:void 0,maxWidth:u?`initial`:void 0,...d?{position:`absolute`,margin:0,left:0,top:0,transform:`translate(${D.x}px, ${D.y}px)`,transition:O?`none`:void 0,cursor:O?`grabbing`:void 0}:{}},closable:g,onClickClose:P,onEscapeKeyDown:e=>{h&&P(),e.preventDefault()},onPointerDownOutside:e=>{_&&P(),e.preventDefault()},children:[L(st,{className:W({"!univer-hidden":!l}),"data-drag-handle":d?`true`:void 0,style:{cursor:d?`grab`:void 0,userSelect:d?`none`:void 0,touchAction:d?`none`:void 0},onMouseDown:d?A:void 0,children:[I(lt,{children:l}),I(ut,{className:`univer-hidden`})]}),o,j&&I(ct,{children:j})]})})}const Z=(e,t,n)=>{t/=100,n/=100;let r=n*t,i=r*(1-Math.abs(e/60%2-1)),a=n-r,o=0,s=0,c=0;return e>=0&&e<60?(o=r,s=i,c=0):e>=60&&e<120?(o=i,s=r,c=0):e>=120&&e<180?(o=0,s=r,c=i):e>=180&&e<240?(o=0,s=i,c=r):e>=240&&e<300?(o=i,s=0,c=r):e>=300&&e<360&&(o=r,s=0,c=i),[Math.round((o+a)*255),Math.round((s+a)*255),Math.round((c+a)*255)]},pt=(e,t,n)=>{let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`},mt=(e,t,n)=>{e/=255,t/=255,n/=255;let r=Math.max(e,t,n),i=r-Math.min(e,t,n),a=0,o=0,s=r;return r!==0&&(o=i/r),i!==0&&(r===e?a=(t-n)/i+(t<n?6:0):r===t?a=(n-e)/i+2:r===n&&(a=(e-t)/i+4),a*=60),[a,o*100,s*100]},ht=e=>{e.length===4&&(e=`#${e.slice(1).split(``).map(e=>e+e).join(``)}`);let[t,n,r]=e.match(/\w\w/g).map(e=>Number.parseInt(e,16));return mt(t,n,r)},gt=(e,t,n)=>{let[r,i,a]=Z(e,t,n);return pt(r,i,a)},_t=(e,t,n,r)=>{let[i,a,o]=Z(e,t,n);return`rgba(${i}, ${a}, ${o}, ${r})`},vt=e=>{let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)/);if(!t)throw Error(`Invalid RGBA string`);return[Number.parseInt(t[1],10),Number.parseInt(t[2],10),Number.parseInt(t[3],10),t[4]?Number.parseFloat(t[4]):1]};function yt({hsv:e,alpha:t,onChange:n,onChanged:r}){let[i,a]=M(!1),o=j(null),s=j(null),c=T(e=>{var t,r;let i=o.current;if(!i)return;let a=(t=(r=s.current)==null?void 0:r.clientWidth)==null?0:t,c=i.getBoundingClientRect(),l=c.width-a;if(l<=0){n(0);return}let u=Math.max(0,Math.min(e-c.left,l));n(Math.round(u/l*100)/100)},[n]),l=T(e=>{i&&c(e.clientX)},[i,c]),u=T(()=>{a(!1),r==null||r(t)},[t]);D(()=>(i&&(window.addEventListener(`pointermove`,l),window.addEventListener(`pointerup`,u),window.addEventListener(`mouseup`,u)),()=>{window.removeEventListener(`pointermove`,l),window.removeEventListener(`pointerup`,u),window.removeEventListener(`mouseup`,u)}),[i,l,u]);let d=()=>{var e,n,r,i;let a=Math.min(Math.max(t*100,0),100),c=(e=(n=s.current)==null?void 0:n.clientWidth)==null?0:e,l=(r=(i=o.current)==null?void 0:i.clientWidth)==null?0:r,u=l>0?c/l*100:0;return`${a/100*(100-u)}%`},f=Z(...e);return L(`div`,{className:`univer-relative univer-w-full univer-select-none`,children:[I(`div`,{className:`univer-absolute univer-inset-0 univer-rounded-full`,style:{backgroundImage:`linear-gradient(45deg, #E3E5EA 25%, transparent 25%), linear-gradient(-45deg, #E3E5EA 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #E3E5EA 75%), linear-gradient(-45deg, transparent 75%, #E3E5EA 75%)`,backgroundPosition:`0 0, 0 4px, 4px -4px, -4px 0`,backgroundSize:`8px 8px`}}),I(`div`,{ref:o,className:`univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner`,style:{background:`linear-gradient(to right, transparent, rgb(${f.join(`,`)}))`},onPointerDown:e=>{a(!0),c(e.clientX)},children:I(`div`,{ref:s,className:`univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform`,style:{left:d(),transform:`translateY(-50%)`,transition:i?`none`:`all 0.1s ease-out`}})})]})}function bt({hsv:e,onChange:t}){let[n,r]=M(``),i=A(()=>gt(e[0],e[1],e[2]),[e]);D(()=>{r(i.replace(/^#/,``))},[i]);let a=e=>/^[0-9A-Fa-f]{6}$/.test(e);return L(F,{children:[I(`input`,{className:W(`univer-w-full univer-px-2 !univer-pl-4 univer-uppercase focus:univer-border-primary-500 focus:univer-outline-none dark:!univer-text-white`,Y),value:n,onChange:e=>{let n=e.target.value.trim();if(!(n.length>6)&&!(n!==``&&!/^[0-9A-Fa-f]*$/.test(n))&&(r(n),a(n))){let e=ht(n);e&&t&&t(...e)}},onBlur:()=>{a(n)||r(i.replace(/^#/,``))},maxLength:6,spellCheck:!1}),I(`span`,{className:`univer-absolute univer-left-1.5 univer-top-1/2 -univer-translate-y-1/2 univer-text-sm univer-text-gray-400`,children:`#`})]})}function xt({hsv:e,alpha:t,format:n,onChange:r}){let[i,a]=M({r:0,g:0,b:0,a:1});D(()=>{let[n,r,i]=Z(e[0],e[1],e[2]);a({r:Math.round(n),g:Math.round(r),b:Math.round(i),a:t==null?1:t})},[e,t]);let o=(t,n)=>{if(t===`a`){if(n!==``&&!/^\d*\.?\d*$/.test(n))return;let t=n===``?0:Number.parseFloat(n);if(t>1)return;a({...i,a:t}),r&&r(e[0],e[1],e[2],t);return}if(n!==``&&!/^\d*$/.test(n))return;let o=n===``?0:Number.parseInt(n,10);if(o>255)return;let s={...i,[t]:o};a(s),r&&r(...mt(s.r,s.g,s.b),i.a)},s=()=>{let[n,r,i]=Z(e[0],e[1],e[2]);a({r:Math.round(n),g:Math.round(r),b:Math.round(i),a:t==null?1:t})};return L(`div`,{className:`univer-flex univer-items-center univer-gap-2 [&>input]:univer-w-11 [&>input]:univer-border-gray-200 [&>input]:focus:univer-border-primary-500 dark:[&>input]:!univer-border-gray-600 dark:[&>input]:!univer-text-white`,children:[I(`input`,{value:i.r,onChange:e=>o(`r`,e.target.value),onBlur:s,maxLength:3}),I(`input`,{value:i.g,onChange:e=>o(`g`,e.target.value),onBlur:s,maxLength:3}),I(`input`,{value:i.b,onChange:e=>o(`b`,e.target.value),onBlur:s,maxLength:3}),n===`rgba`&&I(`input`,{value:i.a,onChange:e=>o(`a`,e.target.value),onBlur:s,maxLength:4})]})}function St({hsv:e,alpha:t,format:n,onChange:r}){return I(`div`,{className:`dark:![&_input]:univer-border-gray-600 dark:![&_input]:univer-text-white univer-flex univer-gap-2 [&_input]:univer-box-border [&_input]:univer-flex [&_input]:univer-h-7 [&_input]:univer-items-center [&_input]:univer-rounded [&_input]:univer-border [&_input]:univer-border-solid [&_input]:univer-border-gray-200 [&_input]:univer-bg-transparent [&_input]:univer-px-1.5 [&_input]:univer-text-sm [&_input]:univer-text-gray-700 [&_input]:univer-outline-none`,children:L(`div`,{className:`univer-relative univer-flex univer-flex-1 univer-gap-2`,children:[I(bt,{hsv:e,onChange:r}),I(xt,{hsv:e,alpha:t,format:n,onChange:r})]})})}const Ct=[[`#FFFFFF`,`#E1EFFE`,`#FDE8E8`,`#FEECDC`,`#FFF4B9`,`#DEF7EC`,`#D5F5F6`,`#EDEBFE`,`#FCE8F3`],[`#CDD0D8`,`#A4CAFE`,`#F8B4B4`,`#FDBA8C`,`#FAC815`,`#84E1BC`,`#7EDCE2`,`#CABFFD`,`#F8B4D9`],[`#979DAC`,`#3F83F8`,`#F05252`,`#FF5A1F`,`#D49D0F`,`#0DA471`,`#0694A2`,`#9061F9`,`#E74694`],[`#414657`,`#1A56DB`,`#C81E1E`,`#B43403`,`#9A6D15`,`#046C4E`,`#036672`,`#6C2BD9`,`#BF125D`],[`#000000`,`#233876`,`#771D1D`,`#8A2C0D`,`#634312`,`#014737`,`#014451`,`#4A1D96`,`#751A3D`]];function wt({hsv:e,onChange:t}){let n=T(e=>{let[n,r,i]=ht(e);t(n,r,i)},[t]),r=gt(e[0],e[1],e[2]);return I(`div`,{"data-u-comp":`color-picker-presets`,className:`univer-grid univer-content-center univer-gap-2`,children:Ct.map((e,t)=>I(`div`,{className:`univer-grid univer-grid-flow-col univer-items-center univer-justify-between univer-gap-2`,children:e.map((e,i)=>I(`button`,{type:`button`,className:W(`univer-box-border univer-size-5 univer-cursor-pointer univer-rounded-full univer-border univer-border-solid univer-border-transparent univer-bg-gray-300 univer-transition-shadow`,{"univer-ring-2 univer-ring-offset-2 univer-ring-offset-white dark:!univer-ring-primary-600 dark:!univer-ring-offset-gray-600":e.toUpperCase()===r.toUpperCase(),"!univer-border-gray-200":t===0&&i===0}),style:{backgroundColor:e},onClick:()=>n(e)},i))},t))})}function Tt({hsv:e,onChange:t,onChanged:n}){let r=j(null),i=j(null),[a,o]=M(!1);D(()=>{let t=r.current;if(!t)return;let n=t.getContext(`2d`);if(!n)return;let i=n.createLinearGradient(0,0,t.width,0);i.addColorStop(0,`hsl(${e[0]}, 0%, 50%)`),i.addColorStop(1,`hsl(${e[0]}, 100%, 50%)`),n.fillStyle=i,n.fillRect(0,0,t.width,t.height);let a=n.createLinearGradient(0,0,0,t.height);a.addColorStop(0,`rgba(255, 255, 255, 0)`),a.addColorStop(1,`rgba(0, 0, 0, 1)`),n.fillStyle=a,n.fillRect(0,0,t.width,t.height)},[e]);let s=n=>{n.stopPropagation();let i=r.current;if(!i)return;let a=i.getBoundingClientRect(),o=Math.max(0,Math.min(n.clientX-a.left,a.width)),s=Math.max(0,Math.min(n.clientY-a.top,a.height)),c=o/a.width*100,l=100-s/a.height*100;t(e[0],c,l)},c=T(()=>{o(!1)},[e]);function l(){n==null||n(e[0],e[1],e[2])}D(()=>{var e;return(e=i.current)==null||e.addEventListener(`mouseup`,l),window.addEventListener(`pointerup`,c),window.addEventListener(`mouseup`,c),()=>{var e;(e=i.current)==null||e.removeEventListener(`mouseup`,l),window.removeEventListener(`pointerup`,c),window.removeEventListener(`mouseup`,c)}},[e]);let u=()=>{var t,n,r,o;let s=(t=(n=i.current)==null?void 0:n.clientWidth)==null?0:t,c=(r=(o=i.current)==null?void 0:o.clientHeight)==null?0:r;return{transform:`translate(${e[1]/100*s-8}px, ${(100-e[2])/100*c-8}px)`,transition:a?`none`:`transform 0.1s ease-out`}};return D(()=>{let e=()=>{o(!1)};return window.addEventListener(`pointerup`,e),window.addEventListener(`mouseup`,e),()=>{window.removeEventListener(`pointerup`,e),window.removeEventListener(`mouseup`,e)}},[]),L(`div`,{"data-u-comp":`color-picker-spectrum`,ref:i,className:`univer-relative univer-overflow-hidden`,children:[I(`canvas`,{ref:r,className:`univer-size-full univer-cursor-crosshair univer-rounded`,onPointerDown:e=>{o(!0),s(e)},onPointerMove:e=>a&&s(e)}),I(`div`,{className:`univer-pointer-events-none univer-absolute univer-left-0 univer-top-0 univer-size-4 univer-rounded-full univer-border-2 univer-border-white univer-shadow-md univer-ring-2 univer-ring-white univer-will-change-transform`,style:u()})]})}function Et({hsv:e,onChange:t,onChanged:n}){let[r,i]=M(!1),a=j(null),o=j(null),s=T(n=>{var r,i;let s=a.current;if(!s)return;let c=(r=(i=o.current)==null?void 0:i.clientWidth)==null?0:r,l=s.getBoundingClientRect(),u=l.width-c;if(u<=0){t(0,e[1],e[2]);return}let d=Math.max(0,Math.min(n-l.left,u));t(Math.round(d/u*360),e[1],e[2])},[e,t]),c=T(e=>{e.stopPropagation(),r&&s(e.clientX)},[r,s]),l=T(()=>{i(!1),n==null||n(e[0],e[1],e[2])},[e,n]);D(()=>(r&&(window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l),window.addEventListener(`mouseup`,l)),()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),window.removeEventListener(`mouseup`,l)}),[r,c,l]);let u=()=>{var t,n,r,i;let s=Math.min(Math.max(e[0],0),360),c=(t=(n=o.current)==null?void 0:n.clientWidth)==null?0:t,l=(r=(i=a.current)==null?void 0:i.clientWidth)==null?0:r,u=l>0?c/l*100:0;return`${s/360*(100-u)}%`};return I(`div`,{"data-u-comp":`color-picker-hue-slider`,className:`univer-relative univer-w-full univer-select-none`,children:I(`div`,{ref:a,className:`univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner`,style:{background:`linear-gradient(to right,
|
|
181
|
+
`
|
|
182
|
+
},
|
|
183
|
+
size: {
|
|
184
|
+
small: "univer-h-6 univer-rounded-md univer-px-1.5 univer-text-xs",
|
|
185
|
+
middle: "univer-h-8 univer-rounded-lg univer-px-2 univer-text-sm",
|
|
186
|
+
large: "univer-h-10 univer-rounded-lg univer-px-3 univer-text-sm"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
defaultVariants: {
|
|
190
|
+
variant: "default",
|
|
191
|
+
size: "middle"
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const Button = forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
195
|
+
return /* @__PURE__ */ jsx(asChild ? Slot : "button", {
|
|
196
|
+
className: clsx(buttonVariants({
|
|
197
|
+
variant,
|
|
198
|
+
size,
|
|
199
|
+
className
|
|
200
|
+
})),
|
|
201
|
+
ref,
|
|
202
|
+
"data-u-comp": "button",
|
|
203
|
+
...props
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
Button.displayName = "Button";
|
|
207
|
+
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/components/button/ButtonGroup.tsx
|
|
210
|
+
const ButtonGroup = ({ className, orientation = "horizontal", children }) => {
|
|
211
|
+
const totalButtons = Children.count(children);
|
|
212
|
+
const isHorizontal = orientation === "horizontal";
|
|
213
|
+
const isVertical = orientation === "vertical";
|
|
214
|
+
return /* @__PURE__ */ jsx("div", {
|
|
215
|
+
className: clsx("univer-grid", {
|
|
216
|
+
"univer-grid-flow-row": isVertical,
|
|
217
|
+
"univer-w-fit": isVertical
|
|
218
|
+
}, className),
|
|
219
|
+
children: Children.map(children, (child, index) => {
|
|
220
|
+
const isFirst = index === 0;
|
|
221
|
+
const isLast = index === totalButtons - 1;
|
|
222
|
+
return cloneElement(child, { className: clsx({
|
|
223
|
+
"!univer-rounded-l-none": isHorizontal && !isFirst,
|
|
224
|
+
"!univer-rounded-r-none": isHorizontal && !isLast,
|
|
225
|
+
"!univer-border-l-0": isHorizontal && !isFirst,
|
|
226
|
+
"!univer-rounded-t-none": isVertical && !isFirst,
|
|
227
|
+
"!univer-rounded-b-none": isVertical && !isLast,
|
|
228
|
+
"!univer-border-t-0": isVertical && !isFirst
|
|
229
|
+
}, child.props.className) });
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/helper/is-browser.ts
|
|
236
|
+
/**
|
|
237
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
238
|
+
*
|
|
239
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
240
|
+
* you may not use this file except in compliance with the License.
|
|
241
|
+
* You may obtain a copy of the License at
|
|
242
|
+
*
|
|
243
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
244
|
+
*
|
|
245
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
246
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
247
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
248
|
+
* See the License for the specific language governing permissions and
|
|
249
|
+
* limitations under the License.
|
|
250
|
+
*/
|
|
251
|
+
function isBrowser() {
|
|
252
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/components/config-provider/ConfigProvider.tsx
|
|
257
|
+
const ConfigContext = createContext({ mountContainer: isBrowser() ? document.body : null });
|
|
258
|
+
function ConfigProvider(props) {
|
|
259
|
+
const { children, locale, mountContainer } = props;
|
|
260
|
+
const value = useMemo(() => {
|
|
261
|
+
return {
|
|
262
|
+
locale,
|
|
263
|
+
mountContainer
|
|
264
|
+
};
|
|
265
|
+
}, [locale, mountContainer]);
|
|
266
|
+
return /* @__PURE__ */ jsx(ConfigContext.Provider, {
|
|
267
|
+
value,
|
|
268
|
+
children
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/helper/class-utilities.ts
|
|
274
|
+
/**
|
|
275
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
276
|
+
*
|
|
277
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
278
|
+
* you may not use this file except in compliance with the License.
|
|
279
|
+
* You may obtain a copy of the License at
|
|
280
|
+
*
|
|
281
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
282
|
+
*
|
|
283
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
284
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
285
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
286
|
+
* See the License for the specific language governing permissions and
|
|
287
|
+
* limitations under the License.
|
|
288
|
+
*/
|
|
289
|
+
const scrollbarClassName = "univer-scrollbar-thin univer-scrollbar-track-gray-50 univer-scrollbar-thumb-gray-300 dark:!univer-scrollbar-track-gray-900 dark:!univer-scrollbar-thumb-gray-700";
|
|
290
|
+
const borderBasicClassName = "univer-border-gray-200 dark:!univer-border-gray-600 univer-border-solid";
|
|
291
|
+
const borderClassName = clsx(borderBasicClassName, "univer-border");
|
|
292
|
+
const borderLeftBottomClassName = clsx(borderBasicClassName, "univer-border-l univer-border-b univer-border-t-0 univer-border-r-0");
|
|
293
|
+
const borderLeftClassName = clsx(borderBasicClassName, "univer-border-l univer-border-b-0 univer-border-t-0 univer-border-r-0");
|
|
294
|
+
const borderLeftRTLClassName = clsx(borderBasicClassName, "univer-border-b-0 univer-border-t-0 rtl:univer-border-l-0 rtl:univer-border-r");
|
|
295
|
+
const borderTopClassName = clsx(borderBasicClassName, "univer-border-l-0 univer-border-b-0 univer-border-t univer-border-r-0");
|
|
296
|
+
const borderBottomClassName = clsx(borderBasicClassName, "univer-border-l-0 univer-border-b univer-border-t-0 univer-border-r-0");
|
|
297
|
+
const borderRightClassName = clsx(borderBasicClassName, "univer-border-l-0 univer-border-b-0 univer-border-t-0 univer-border-r");
|
|
298
|
+
const divideYClassName = "univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-y univer-divide-x-0 univer-divide-solid";
|
|
299
|
+
const divideXClassName = "univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-x univer-divide-y-0 univer-divide-solid";
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/helper/date.ts
|
|
303
|
+
/**
|
|
304
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
305
|
+
*
|
|
306
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
307
|
+
* you may not use this file except in compliance with the License.
|
|
308
|
+
* You may obtain a copy of the License at
|
|
309
|
+
*
|
|
310
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
311
|
+
*
|
|
312
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
313
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
314
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
315
|
+
* See the License for the specific language governing permissions and
|
|
316
|
+
* limitations under the License.
|
|
317
|
+
*/
|
|
318
|
+
function pad(value, length = 2) {
|
|
319
|
+
return String(value).padStart(length, "0");
|
|
320
|
+
}
|
|
321
|
+
function formatDateWithPattern(value, pattern) {
|
|
322
|
+
const date = value !== null && value !== void 0 ? value : /* @__PURE__ */ new Date();
|
|
323
|
+
if (Number.isNaN(date.getTime())) return "Invalid Date";
|
|
324
|
+
const tokenMap = {
|
|
325
|
+
YYYY: String(date.getFullYear()),
|
|
326
|
+
MM: pad(date.getMonth() + 1),
|
|
327
|
+
DD: pad(date.getDate()),
|
|
328
|
+
HH: pad(date.getHours()),
|
|
329
|
+
mm: pad(date.getMinutes()),
|
|
330
|
+
ss: pad(date.getSeconds())
|
|
331
|
+
};
|
|
332
|
+
return pattern.replace(/YYYY|MM|DD|HH|mm|ss/g, (token) => {
|
|
333
|
+
var _tokenMap$token;
|
|
334
|
+
return (_tokenMap$token = tokenMap[token]) !== null && _tokenMap$token !== void 0 ? _tokenMap$token : token;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/components/time-input/TimeInput.tsx
|
|
340
|
+
function TimeInput(props) {
|
|
341
|
+
const { className, value, onValueChange } = props;
|
|
342
|
+
function handleChangeTime(event) {
|
|
343
|
+
const [hours, minutes, seconds] = event.target.value.split(":").map(Number);
|
|
344
|
+
const newValue = new Date(value !== null && value !== void 0 ? value : Date.now());
|
|
345
|
+
newValue.setHours(hours, minutes, seconds, 0);
|
|
346
|
+
onValueChange === null || onValueChange === void 0 || onValueChange(newValue);
|
|
347
|
+
}
|
|
348
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
349
|
+
"data-u-comp": "time-input",
|
|
350
|
+
className: "univer-relative univer-mx-auto univer-mt-1 univer-w-fit",
|
|
351
|
+
children: [/* @__PURE__ */ jsx(ClockIcon, { className: "univer-absolute univer-left-2 univer-top-1/2 -univer-translate-y-1/2 univer-text-gray-600 dark:!univer-text-gray-400" }), /* @__PURE__ */ jsx("input", {
|
|
352
|
+
className: clsx("univer-block univer-h-7 univer-w-fit univer-appearance-none univer-rounded-md univer-bg-transparent univer-pl-6 univer-pr-2 univer-text-center univer-text-gray-800 univer-shadow univer-outline-none univer-transition-all univer-duration-200 focus:univer-border-primary-600 dark:!univer-text-white dark:focus:!univer-border-primary-500 [&::-webkit-calendar-picker-indicator]:univer-hidden [&::-webkit-calendar-picker-indicator]:univer-appearance-none", borderClassName, className),
|
|
353
|
+
type: "time",
|
|
354
|
+
step: "1",
|
|
355
|
+
value: formatDateWithPattern(value, "HH:mm:ss"),
|
|
356
|
+
onChange: handleChangeTime
|
|
357
|
+
})]
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/components/calendar/Calendar.tsx
|
|
363
|
+
function getDaysInMonth(year, month) {
|
|
364
|
+
return new Date(year, month + 1, 0).getDate();
|
|
365
|
+
}
|
|
366
|
+
function getFirstDayOfWeek(year, month) {
|
|
367
|
+
return new Date(year, month, 1).getDay();
|
|
368
|
+
}
|
|
369
|
+
function DayButton(props) {
|
|
370
|
+
const { className, ...restProps } = props;
|
|
371
|
+
return /* @__PURE__ */ jsx("button", {
|
|
372
|
+
className: clsx("univer-size-7 univer-rounded-md univer-border-none univer-bg-transparent univer-p-1 univer-transition-all hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600", className),
|
|
373
|
+
type: "button",
|
|
374
|
+
...restProps
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function Calendar(props) {
|
|
378
|
+
const { className, max, min, showTime = false, value, onValueChange } = props;
|
|
379
|
+
const { locale } = useContext(ConfigContext);
|
|
380
|
+
const { year, weekDays, months } = locale === null || locale === void 0 ? void 0 : locale.Calendar;
|
|
381
|
+
const today = /* @__PURE__ */ new Date();
|
|
382
|
+
const [currentYear, setCurrentYear] = useState((value !== null && value !== void 0 ? value : today).getFullYear());
|
|
383
|
+
const [currentMonth, setCurrentMonth] = useState((value !== null && value !== void 0 ? value : today).getMonth());
|
|
384
|
+
function prevMonth() {
|
|
385
|
+
setCurrentMonth((prev) => {
|
|
386
|
+
if (prev === 0) {
|
|
387
|
+
setCurrentYear((y) => y - 1);
|
|
388
|
+
return 11;
|
|
389
|
+
}
|
|
390
|
+
return prev - 1;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function nextMonth() {
|
|
394
|
+
setCurrentMonth((prev) => {
|
|
395
|
+
if (prev === 11) {
|
|
396
|
+
setCurrentYear((y) => y + 1);
|
|
397
|
+
return 0;
|
|
398
|
+
}
|
|
399
|
+
return prev + 1;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
const daysInMonth = getDaysInMonth(currentYear, currentMonth);
|
|
403
|
+
const firstDay = getFirstDayOfWeek(currentYear, currentMonth);
|
|
404
|
+
const days = useMemo(() => {
|
|
405
|
+
const daysArray = [];
|
|
406
|
+
for (let i = 0; i < firstDay; i++) daysArray.push(null);
|
|
407
|
+
for (let d = 1; d <= daysInMonth; d++) daysArray.push(d);
|
|
408
|
+
return daysArray;
|
|
409
|
+
}, [daysInMonth, firstDay]);
|
|
410
|
+
function isSelected(day) {
|
|
411
|
+
return day && currentYear === (value === null || value === void 0 ? void 0 : value.getFullYear()) && currentMonth === (value === null || value === void 0 ? void 0 : value.getMonth()) && day === (value === null || value === void 0 ? void 0 : value.getDate());
|
|
412
|
+
}
|
|
413
|
+
function isToday(day) {
|
|
414
|
+
return day && currentYear === today.getFullYear() && currentMonth === today.getMonth() && day === today.getDate();
|
|
415
|
+
}
|
|
416
|
+
function isDisabled(day) {
|
|
417
|
+
var _value$getHours, _value$getMinutes, _value$getSeconds;
|
|
418
|
+
if (!day) return false;
|
|
419
|
+
const hours = (_value$getHours = value === null || value === void 0 ? void 0 : value.getHours()) !== null && _value$getHours !== void 0 ? _value$getHours : today.getHours();
|
|
420
|
+
const minutes = (_value$getMinutes = value === null || value === void 0 ? void 0 : value.getMinutes()) !== null && _value$getMinutes !== void 0 ? _value$getMinutes : today.getMinutes();
|
|
421
|
+
const seconds = (_value$getSeconds = value === null || value === void 0 ? void 0 : value.getSeconds()) !== null && _value$getSeconds !== void 0 ? _value$getSeconds : today.getSeconds();
|
|
422
|
+
const d = new Date(currentYear, currentMonth, day, hours, minutes, seconds);
|
|
423
|
+
if (min && d < min) return true;
|
|
424
|
+
if (max && d > max) return true;
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
function handleChangeDate(day) {
|
|
428
|
+
var _value$getHours2, _value$getMinutes2, _value$getSeconds2;
|
|
429
|
+
if (isDisabled(day)) return;
|
|
430
|
+
const hours = (_value$getHours2 = value === null || value === void 0 ? void 0 : value.getHours()) !== null && _value$getHours2 !== void 0 ? _value$getHours2 : today.getHours();
|
|
431
|
+
const minutes = (_value$getMinutes2 = value === null || value === void 0 ? void 0 : value.getMinutes()) !== null && _value$getMinutes2 !== void 0 ? _value$getMinutes2 : today.getMinutes();
|
|
432
|
+
const seconds = (_value$getSeconds2 = value === null || value === void 0 ? void 0 : value.getSeconds()) !== null && _value$getSeconds2 !== void 0 ? _value$getSeconds2 : today.getSeconds();
|
|
433
|
+
const selectedDate = new Date(currentYear, currentMonth, day, hours, minutes, seconds);
|
|
434
|
+
onValueChange === null || onValueChange === void 0 || onValueChange(selectedDate);
|
|
435
|
+
}
|
|
436
|
+
function handleChangeTime(time) {
|
|
437
|
+
var _value$getDate;
|
|
438
|
+
const hours = time.getHours();
|
|
439
|
+
const minutes = time.getMinutes();
|
|
440
|
+
const seconds = time.getSeconds();
|
|
441
|
+
const updatedDate = new Date(currentYear, currentMonth, (_value$getDate = value === null || value === void 0 ? void 0 : value.getDate()) !== null && _value$getDate !== void 0 ? _value$getDate : today.getDate(), hours, minutes, seconds);
|
|
442
|
+
onValueChange === null || onValueChange === void 0 || onValueChange(updatedDate);
|
|
443
|
+
}
|
|
444
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
445
|
+
"data-u-comp": "calendar",
|
|
446
|
+
className: clsx("univer-mx-auto univer-max-w-xs univer-select-none univer-rounded univer-bg-white univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-white", className),
|
|
447
|
+
children: [
|
|
448
|
+
/* @__PURE__ */ jsxs("nav", {
|
|
449
|
+
className: "univer-mb-4 univer-flex univer-items-center univer-justify-between",
|
|
450
|
+
children: [
|
|
451
|
+
/* @__PURE__ */ jsx(DayButton, {
|
|
452
|
+
className: "univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200",
|
|
453
|
+
"aria-label": "Previous Month",
|
|
454
|
+
onClick: prevMonth,
|
|
455
|
+
children: /* @__PURE__ */ jsx(MoreRightIcon, { className: "univer-rotate-180" })
|
|
456
|
+
}),
|
|
457
|
+
/* @__PURE__ */ jsxs("span", {
|
|
458
|
+
className: "univer-flex univer-gap-0.5 univer-text-sm univer-font-medium",
|
|
459
|
+
children: [
|
|
460
|
+
/* @__PURE__ */ jsx("span", { children: currentYear }),
|
|
461
|
+
/* @__PURE__ */ jsx("span", { children: year }),
|
|
462
|
+
/* @__PURE__ */ jsx("span", { children: months[currentMonth] })
|
|
463
|
+
]
|
|
464
|
+
}),
|
|
465
|
+
/* @__PURE__ */ jsx(DayButton, {
|
|
466
|
+
className: "univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200",
|
|
467
|
+
"aria-label": "Next Month",
|
|
468
|
+
onClick: nextMonth,
|
|
469
|
+
children: /* @__PURE__ */ jsx(MoreRightIcon, {})
|
|
470
|
+
})
|
|
471
|
+
]
|
|
472
|
+
}),
|
|
473
|
+
/* @__PURE__ */ jsx("div", {
|
|
474
|
+
className: "univer-mb-1 univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center univer-text-sm univer-text-gray-500 dark:!univer-text-gray-200",
|
|
475
|
+
children: weekDays.map((wd) => /* @__PURE__ */ jsx("div", { children: wd }, wd))
|
|
476
|
+
}),
|
|
477
|
+
/* @__PURE__ */ jsx("div", {
|
|
478
|
+
className: "univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center",
|
|
479
|
+
children: days.map((day, idx) => day ? /* @__PURE__ */ jsx(DayButton, {
|
|
480
|
+
className: clsx({
|
|
481
|
+
"!univer-bg-primary-600 univer-font-bold univer-text-white": !isToday(day) && isSelected(day),
|
|
482
|
+
"dark:!univer-text-white": !isToday(day) && !isSelected(day),
|
|
483
|
+
"!univer-bg-primary-600 univer-text-white": isToday(day) && isSelected(day),
|
|
484
|
+
"univer-font-semibold univer-text-primary-600 dark:!univer-text-primary-500": isToday(day) && !isSelected(day),
|
|
485
|
+
"univer-cursor-not-allowed univer-opacity-40": isDisabled(day),
|
|
486
|
+
"univer-hover:bg-primary-100 univer-cursor-pointer univer-text-gray-800": !isSelected(day) && !isDisabled(day)
|
|
487
|
+
}),
|
|
488
|
+
onClick: () => handleChangeDate(day),
|
|
489
|
+
disabled: isDisabled(day),
|
|
490
|
+
children: day
|
|
491
|
+
}, idx) : /* @__PURE__ */ jsx("div", {}, idx))
|
|
492
|
+
}),
|
|
493
|
+
showTime && /* @__PURE__ */ jsx(TimeInput, {
|
|
494
|
+
value,
|
|
495
|
+
onValueChange: handleChangeTime
|
|
496
|
+
})
|
|
497
|
+
]
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/components/cascader-list/CascaderList.tsx
|
|
503
|
+
/**
|
|
504
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
505
|
+
*
|
|
506
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
507
|
+
* you may not use this file except in compliance with the License.
|
|
508
|
+
* You may obtain a copy of the License at
|
|
509
|
+
*
|
|
510
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
511
|
+
*
|
|
512
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
513
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
514
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
515
|
+
* See the License for the specific language governing permissions and
|
|
516
|
+
* limitations under the License.
|
|
517
|
+
*/
|
|
518
|
+
function Empty({ emptyText }) {
|
|
519
|
+
return /* @__PURE__ */ jsx("section", {
|
|
520
|
+
className: "univer-h-8 univer-px-2 univer-pr-32 univer-text-sm/8 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
521
|
+
children: emptyText
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
function CascaderList(props) {
|
|
525
|
+
const { value, options = [], onChange, contentClassName, wrapperClassName } = props;
|
|
526
|
+
const { locale } = useContext(ConfigContext);
|
|
527
|
+
const activeOptions = useMemo(() => {
|
|
528
|
+
const activeOptions = [options];
|
|
529
|
+
value.forEach((item, index) => {
|
|
530
|
+
const option = activeOptions[index].find((option) => option.value === item);
|
|
531
|
+
if (option === null || option === void 0 ? void 0 : option.children) activeOptions.push(option.children);
|
|
532
|
+
});
|
|
533
|
+
return activeOptions;
|
|
534
|
+
}, [value]);
|
|
535
|
+
function handleChange(index, v) {
|
|
536
|
+
if (v === value[index]) return;
|
|
537
|
+
if (value[index + 1]) {
|
|
538
|
+
const newValue = value.slice(0, index + 1);
|
|
539
|
+
newValue[index] = v;
|
|
540
|
+
onChange(newValue);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
const newValue = [...value];
|
|
544
|
+
newValue[index] = v;
|
|
545
|
+
onChange(newValue);
|
|
546
|
+
}
|
|
547
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
548
|
+
"data-u-comp": "cascader-list",
|
|
549
|
+
className: clsx("univer-overflow-auto-y univer-grid univer-h-full univer-max-h-80 univer-grid-flow-col univer-rounded univer-py-2 univer-text-gray-900 dark:!univer-text-white [&>ul:not(:last-child)]:univer-border-0 [&>ul:not(:last-child)]:univer-border-r [&>ul:not(:last-child)]:univer-border-solid [&>ul:not(:last-child)]:univer-border-r-gray-200", borderClassName, scrollbarClassName, wrapperClassName),
|
|
550
|
+
children: [activeOptions.map((options, index) => options.length ? /* @__PURE__ */ jsx("ul", {
|
|
551
|
+
className: clsx("univer-m-0 univer-h-full univer-max-h-full univer-list-none univer-overflow-auto univer-px-2", scrollbarClassName, contentClassName),
|
|
552
|
+
children: options.map((option) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("a", {
|
|
553
|
+
className: clsx("univer-relative univer-block univer-h-8 univer-cursor-pointer univer-rounded univer-text-sm/8", {
|
|
554
|
+
"univer-px-7": index > 0,
|
|
555
|
+
"univer-px-1.5": index === 0,
|
|
556
|
+
"univer-bg-gray-200 dark:!univer-bg-gray-600": option.value === value[index]
|
|
557
|
+
}),
|
|
558
|
+
onClick: () => handleChange(index, option.value),
|
|
559
|
+
children: [index > 0 && /* @__PURE__ */ jsx("span", {
|
|
560
|
+
className: "univer-absolute univer-left-2 univer-flex univer-h-full univer-items-center",
|
|
561
|
+
children: option.value === value[index] && /* @__PURE__ */ jsx(CheckMarkIcon, { className: "univer-text-primary-600" })
|
|
562
|
+
}), /* @__PURE__ */ jsx("span", { children: option.label })]
|
|
563
|
+
}) }, option.value))
|
|
564
|
+
}, index) : /* @__PURE__ */ jsx(Empty, { emptyText: locale === null || locale === void 0 ? void 0 : locale.CascaderList.empty }, index)), value.length <= 0 && /* @__PURE__ */ jsx(Empty, { emptyText: locale === null || locale === void 0 ? void 0 : locale.CascaderList.empty })]
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/components/checkbox-group/CheckboxGroup.tsx
|
|
570
|
+
/**
|
|
571
|
+
* CheckboxGroup Component
|
|
572
|
+
*/
|
|
573
|
+
function CheckboxGroup(props) {
|
|
574
|
+
const { children, className, style, value, disabled, direction = "horizontal", onChange } = props;
|
|
575
|
+
const handleChange = (item) => {
|
|
576
|
+
if (value.includes(item)) onChange(value.filter((i) => i !== item));
|
|
577
|
+
else onChange([...value, item]);
|
|
578
|
+
};
|
|
579
|
+
return /* @__PURE__ */ jsx("div", {
|
|
580
|
+
className: clsx("univer-flex univer-gap-2", { "univer-flex-col": direction === "vertical" }, className),
|
|
581
|
+
style,
|
|
582
|
+
children: Children.map(children, (child, index) => {
|
|
583
|
+
if (isValidElement(child)) return cloneElement(child, {
|
|
584
|
+
key: index,
|
|
585
|
+
children: child.props.children,
|
|
586
|
+
checked: child.props.value ? value.includes(child.props.value) : false,
|
|
587
|
+
disabled: disabled !== null && disabled !== void 0 ? disabled : child.props.disabled,
|
|
588
|
+
onChange: handleChange
|
|
589
|
+
});
|
|
590
|
+
return child;
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region src/components/checkbox/Checkbox.tsx
|
|
597
|
+
/**
|
|
598
|
+
* Checkbox Component
|
|
599
|
+
*/
|
|
600
|
+
function Checkbox(props) {
|
|
601
|
+
const { children, className, style, checked = false, indeterminate = false, value, disabled = false, onChange, contentClassName } = props;
|
|
602
|
+
const inputRef = useRef(null);
|
|
603
|
+
function handleChange(e) {
|
|
604
|
+
e.stopPropagation();
|
|
605
|
+
if (!onChange || disabled) return;
|
|
606
|
+
if (typeof value !== "undefined") onChange === null || onChange === void 0 || onChange(value);
|
|
607
|
+
else {
|
|
608
|
+
var _inputRef$current$che, _inputRef$current;
|
|
609
|
+
const checked = (_inputRef$current$che = inputRef === null || inputRef === void 0 || (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.checked) !== null && _inputRef$current$che !== void 0 ? _inputRef$current$che : false;
|
|
610
|
+
onChange === null || onChange === void 0 || onChange(checked);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
614
|
+
"data-u-comp": "checkbox",
|
|
615
|
+
className: clsx("univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm", {
|
|
616
|
+
"univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white": !disabled,
|
|
617
|
+
"univer-text-gray-400": disabled
|
|
618
|
+
}, className),
|
|
619
|
+
style,
|
|
620
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
621
|
+
className: "univer-relative univer-block",
|
|
622
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
623
|
+
ref: inputRef,
|
|
624
|
+
className: "univer-absolute univer-size-0 univer-opacity-0",
|
|
625
|
+
type: "checkbox",
|
|
626
|
+
checked,
|
|
627
|
+
disabled,
|
|
628
|
+
onChange: handleChange
|
|
629
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
630
|
+
className: clsx("univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded univer-border univer-border-solid univer-transition-colors", {
|
|
631
|
+
"univer-opacity-50": disabled,
|
|
632
|
+
"univer-border-primary-600 univer-bg-primary-600": checked || indeterminate,
|
|
633
|
+
"univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600": !checked && !indeterminate
|
|
634
|
+
}),
|
|
635
|
+
children: [checked && /* @__PURE__ */ jsx(CheckMarkIcon, { className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-3 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-text-white" }), indeterminate && !checked && /* @__PURE__ */ jsx("span", { className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-h-0.5 univer-w-2.5 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded univer-bg-white" })]
|
|
636
|
+
})]
|
|
637
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
638
|
+
className: clsx("univer-select-none", contentClassName),
|
|
639
|
+
children
|
|
640
|
+
})]
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/components/dialog/DialogPrimitive.tsx
|
|
646
|
+
const Dialog$1 = Root;
|
|
647
|
+
const DialogPortal = Portal;
|
|
648
|
+
const DialogOverlay = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Overlay, {
|
|
649
|
+
ref,
|
|
650
|
+
className: clsx("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 univer-fixed univer-inset-0 univer-z-[1080] univer-bg-[rgba(0,0,0,0.8)]", className),
|
|
651
|
+
...props
|
|
652
|
+
}));
|
|
653
|
+
DialogOverlay.displayName = Overlay.displayName;
|
|
654
|
+
const DialogContent = forwardRef(({ className, children, closable = true, onClickClose, ...props }, ref) => /* @__PURE__ */ jsxs(DialogPortal, { children: [/* @__PURE__ */ jsx(DialogOverlay, {}), /* @__PURE__ */ jsxs(Content, {
|
|
655
|
+
ref,
|
|
656
|
+
className: clsx("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=open]:univer-slide-in-from-left-1/2 data-[state=open]:univer-slide-in-from-top-[48%] data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[state=closed]:univer-slide-out-to-left-1/2 data-[state=closed]:univer-slide-out-to-top-[48%] univer-fixed univer-left-1/2 univer-top-1/2 univer-z-[1080] univer-box-border univer-grid univer-w-full univer-max-w-lg -univer-translate-x-1/2 -univer-translate-y-1/2 univer-gap-4 univer-bg-white univer-p-4 univer-text-gray-500 univer-shadow-md univer-duration-200 sm:!univer-rounded-lg dark:!univer-bg-gray-700 dark:!univer-text-gray-400", borderClassName, className),
|
|
657
|
+
...props,
|
|
658
|
+
children: [children, closable && /* @__PURE__ */ jsxs(Close, {
|
|
659
|
+
className: "univer-absolute univer-right-4 univer-top-4 univer-size-6 univer-cursor-pointer univer-rounded-sm univer-border-none univer-bg-transparent univer-p-0 univer-transition-opacity hover:univer-opacity-100 disabled:univer-pointer-events-none",
|
|
660
|
+
onClick: onClickClose,
|
|
661
|
+
children: [/* @__PURE__ */ jsx(CloseIcon, { className: "univer-size-4 univer-text-gray-400" }), /* @__PURE__ */ jsx("span", {
|
|
662
|
+
className: "univer-sr-only",
|
|
663
|
+
children: "Close"
|
|
664
|
+
})]
|
|
665
|
+
})]
|
|
666
|
+
})] }));
|
|
667
|
+
DialogContent.displayName = Content.displayName;
|
|
668
|
+
const DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
669
|
+
className: clsx("univer-flex univer-flex-col univer-space-y-1.5 univer-text-center sm:!univer-text-left", className),
|
|
670
|
+
...props
|
|
671
|
+
});
|
|
672
|
+
DialogHeader.displayName = "DialogHeader";
|
|
673
|
+
const DialogFooter = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
674
|
+
className: clsx("univer-flex univer-flex-col-reverse sm:!univer-flex-row sm:!univer-justify-end sm:!univer-space-x-2", className),
|
|
675
|
+
...props
|
|
676
|
+
});
|
|
677
|
+
DialogFooter.displayName = "DialogFooter";
|
|
678
|
+
const DialogTitle = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Title, {
|
|
679
|
+
ref,
|
|
680
|
+
className: clsx("univer-my-0 univer-text-lg univer-font-semibold univer-leading-none univer-tracking-tight univer-text-gray-900 dark:!univer-text-white", className),
|
|
681
|
+
...props
|
|
682
|
+
}));
|
|
683
|
+
DialogTitle.displayName = Title.displayName;
|
|
684
|
+
const DialogDescription = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Description, {
|
|
685
|
+
ref,
|
|
686
|
+
className: clsx("univer-text-sm univer-text-gray-500", className),
|
|
687
|
+
...props
|
|
688
|
+
}));
|
|
689
|
+
DialogDescription.displayName = Description.displayName;
|
|
690
|
+
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/components/dialog/Dialog.tsx
|
|
693
|
+
function useDraggable(options = {}) {
|
|
694
|
+
const getCenteredPosition = useCallback(() => {
|
|
695
|
+
const { innerWidth, innerHeight } = window;
|
|
696
|
+
return {
|
|
697
|
+
x: Math.max(0, (innerWidth - 0) / 2),
|
|
698
|
+
y: Math.max(0, (innerHeight - 0) / 2)
|
|
699
|
+
};
|
|
700
|
+
}, []);
|
|
701
|
+
const { defaultPosition = getCenteredPosition(), enabled = false } = options;
|
|
702
|
+
const [position, setPosition] = useState(defaultPosition);
|
|
703
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
704
|
+
const elementRef = useRef(null);
|
|
705
|
+
const startPosRef = useRef({
|
|
706
|
+
x: 0,
|
|
707
|
+
y: 0
|
|
708
|
+
});
|
|
709
|
+
const startClientRef = useRef({
|
|
710
|
+
x: 0,
|
|
711
|
+
y: 0
|
|
712
|
+
});
|
|
713
|
+
const initializedRef = useRef(false);
|
|
714
|
+
useEffect(() => {
|
|
715
|
+
if (!elementRef.current || initializedRef.current || options.defaultPosition) return;
|
|
716
|
+
const { width, height } = elementRef.current.getBoundingClientRect();
|
|
717
|
+
const { innerWidth, innerHeight } = window;
|
|
718
|
+
const centeredX = Math.max(0, (innerWidth - width) / 2);
|
|
719
|
+
const centeredY = Math.max(0, (innerHeight - height) / 2);
|
|
720
|
+
setPosition({
|
|
721
|
+
x: centeredX,
|
|
722
|
+
y: centeredY
|
|
723
|
+
});
|
|
724
|
+
startPosRef.current = {
|
|
725
|
+
x: centeredX,
|
|
726
|
+
y: centeredY
|
|
727
|
+
};
|
|
728
|
+
initializedRef.current = true;
|
|
729
|
+
}, [options.defaultPosition]);
|
|
730
|
+
const calculateBounds = useCallback((clientX, clientY) => {
|
|
731
|
+
if (!elementRef.current) return {
|
|
732
|
+
x: clientX,
|
|
733
|
+
y: clientY
|
|
734
|
+
};
|
|
735
|
+
const rect = elementRef.current.getBoundingClientRect();
|
|
736
|
+
const { clientWidth, clientHeight } = document.documentElement;
|
|
737
|
+
let newX = startPosRef.current.x + (clientX - startClientRef.current.x);
|
|
738
|
+
let newY = startPosRef.current.y + (clientY - startClientRef.current.y);
|
|
739
|
+
if (newX < 0) newX = 0;
|
|
740
|
+
if (newY < 0) newY = 0;
|
|
741
|
+
if (newX + rect.width > clientWidth) newX = clientWidth - rect.width;
|
|
742
|
+
if (newY + rect.height > clientHeight) newY = clientHeight - rect.height;
|
|
743
|
+
return {
|
|
744
|
+
x: newX,
|
|
745
|
+
y: newY
|
|
746
|
+
};
|
|
747
|
+
}, []);
|
|
748
|
+
const startDrag = useCallback((e) => {
|
|
749
|
+
if (!enabled) return;
|
|
750
|
+
e.preventDefault();
|
|
751
|
+
e.stopPropagation();
|
|
752
|
+
startPosRef.current = { ...position };
|
|
753
|
+
startClientRef.current = {
|
|
754
|
+
x: e.clientX,
|
|
755
|
+
y: e.clientY
|
|
756
|
+
};
|
|
757
|
+
setIsDragging(true);
|
|
758
|
+
document.body.style.userSelect = "none";
|
|
759
|
+
}, [enabled, position]);
|
|
760
|
+
const onDrag = useCallback((e) => {
|
|
761
|
+
if (!isDragging) return;
|
|
762
|
+
e.preventDefault();
|
|
763
|
+
e.stopPropagation();
|
|
764
|
+
setPosition(calculateBounds(e.clientX, e.clientY));
|
|
765
|
+
}, [isDragging, calculateBounds]);
|
|
766
|
+
const endDrag = useCallback(() => {
|
|
767
|
+
setIsDragging(false);
|
|
768
|
+
document.body.style.userSelect = "";
|
|
769
|
+
}, []);
|
|
770
|
+
useEffect(() => {
|
|
771
|
+
if (enabled) {
|
|
772
|
+
document.addEventListener("mousemove", onDrag);
|
|
773
|
+
document.addEventListener("mouseup", endDrag);
|
|
774
|
+
return () => {
|
|
775
|
+
document.removeEventListener("mousemove", onDrag);
|
|
776
|
+
document.removeEventListener("mouseup", endDrag);
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}, [
|
|
780
|
+
enabled,
|
|
781
|
+
onDrag,
|
|
782
|
+
endDrag
|
|
783
|
+
]);
|
|
784
|
+
return {
|
|
785
|
+
position,
|
|
786
|
+
isDragging,
|
|
787
|
+
elementRef,
|
|
788
|
+
setElementRef: (el) => {
|
|
789
|
+
elementRef.current = el;
|
|
790
|
+
if (el && !initializedRef.current && !options.defaultPosition) {
|
|
791
|
+
const { width, height } = el.getBoundingClientRect();
|
|
792
|
+
const { innerWidth, innerHeight } = window;
|
|
793
|
+
const centeredX = Math.max(0, (innerWidth - width) / 2);
|
|
794
|
+
const centeredY = Math.max(0, (innerHeight - height) / 2);
|
|
795
|
+
setPosition({
|
|
796
|
+
x: centeredX,
|
|
797
|
+
y: centeredY
|
|
798
|
+
});
|
|
799
|
+
startPosRef.current = {
|
|
800
|
+
x: centeredX,
|
|
801
|
+
y: centeredY
|
|
802
|
+
};
|
|
803
|
+
initializedRef.current = true;
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
handleMouseDown: startDrag
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
function Dialog(props) {
|
|
810
|
+
var _locale$Confirm$cance, _locale$Confirm, _locale$Confirm$confi, _locale$Confirm2;
|
|
811
|
+
const { className, children, style, open = false, title, width, draggable = false, defaultPosition, footer: propFooter, mask = true, keyboard = true, closable = true, maskClosable = true, showOk, showCancel, onOpenChange, onClose, onOk, onCancel } = props;
|
|
812
|
+
const { locale } = useContext(ConfigContext);
|
|
813
|
+
const { position, isDragging, setElementRef, handleMouseDown } = useDraggable({
|
|
814
|
+
defaultPosition,
|
|
815
|
+
enabled: draggable
|
|
816
|
+
});
|
|
817
|
+
const footer = propFooter !== null && propFooter !== void 0 ? propFooter : showOk || showCancel ? /* @__PURE__ */ jsxs("div", {
|
|
818
|
+
className: "univer-flex univer-justify-end univer-gap-2",
|
|
819
|
+
children: [showCancel && /* @__PURE__ */ jsx(Button, {
|
|
820
|
+
onClick: onCancel,
|
|
821
|
+
children: (_locale$Confirm$cance = locale === null || locale === void 0 || (_locale$Confirm = locale.Confirm) === null || _locale$Confirm === void 0 ? void 0 : _locale$Confirm.cancel) !== null && _locale$Confirm$cance !== void 0 ? _locale$Confirm$cance : "Cancel"
|
|
822
|
+
}), showOk && /* @__PURE__ */ jsx(Button, {
|
|
823
|
+
variant: "primary",
|
|
824
|
+
onClick: onOk,
|
|
825
|
+
children: (_locale$Confirm$confi = locale === null || locale === void 0 || (_locale$Confirm2 = locale.Confirm) === null || _locale$Confirm2 === void 0 ? void 0 : _locale$Confirm2.confirm) !== null && _locale$Confirm$confi !== void 0 ? _locale$Confirm$confi : "OK"
|
|
826
|
+
})]
|
|
827
|
+
}) : null;
|
|
828
|
+
const handleContentRef = useCallback((node) => {
|
|
829
|
+
if (node && draggable) setElementRef(node);
|
|
830
|
+
}, [draggable, setElementRef]);
|
|
831
|
+
const handleOpenChange = useCallback((isOpen) => {
|
|
832
|
+
if (!mask && !isOpen) return;
|
|
833
|
+
onOpenChange === null || onOpenChange === void 0 || onOpenChange(isOpen);
|
|
834
|
+
if (!isOpen) onClose === null || onClose === void 0 || onClose();
|
|
835
|
+
}, [onClose, onOpenChange]);
|
|
836
|
+
function handleClickClose() {
|
|
837
|
+
onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
|
|
838
|
+
onClose === null || onClose === void 0 || onClose();
|
|
839
|
+
}
|
|
840
|
+
return /* @__PURE__ */ jsx(Dialog$1, {
|
|
841
|
+
open,
|
|
842
|
+
onOpenChange: handleOpenChange,
|
|
843
|
+
modal: mask !== false,
|
|
844
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
845
|
+
ref: handleContentRef,
|
|
846
|
+
className: clsx(className, { "!univer-animate-none": draggable }),
|
|
847
|
+
style: {
|
|
848
|
+
...style,
|
|
849
|
+
width: width ? typeof width === "number" ? `${width}px` : width : void 0,
|
|
850
|
+
maxWidth: width ? "initial" : void 0,
|
|
851
|
+
...draggable ? {
|
|
852
|
+
position: "absolute",
|
|
853
|
+
margin: 0,
|
|
854
|
+
left: 0,
|
|
855
|
+
top: 0,
|
|
856
|
+
transform: `translate(${position.x}px, ${position.y}px)`,
|
|
857
|
+
transition: isDragging ? "none" : void 0,
|
|
858
|
+
cursor: isDragging ? "grabbing" : void 0
|
|
859
|
+
} : {}
|
|
860
|
+
},
|
|
861
|
+
closable,
|
|
862
|
+
onClickClose: handleClickClose,
|
|
863
|
+
onEscapeKeyDown: (e) => {
|
|
864
|
+
if (keyboard) handleClickClose();
|
|
865
|
+
e.preventDefault();
|
|
866
|
+
},
|
|
867
|
+
onPointerDownOutside: (e) => {
|
|
868
|
+
if (maskClosable) handleClickClose();
|
|
869
|
+
e.preventDefault();
|
|
870
|
+
},
|
|
871
|
+
children: [
|
|
872
|
+
/* @__PURE__ */ jsxs(DialogHeader, {
|
|
873
|
+
className: clsx({ "!univer-hidden": !title }),
|
|
874
|
+
"data-drag-handle": draggable ? "true" : void 0,
|
|
875
|
+
style: {
|
|
876
|
+
cursor: draggable ? "grab" : void 0,
|
|
877
|
+
userSelect: draggable ? "none" : void 0,
|
|
878
|
+
touchAction: draggable ? "none" : void 0
|
|
879
|
+
},
|
|
880
|
+
onMouseDown: draggable ? handleMouseDown : void 0,
|
|
881
|
+
children: [/* @__PURE__ */ jsx(DialogTitle, { children: title }), /* @__PURE__ */ jsx(DialogDescription, { className: "univer-hidden" })]
|
|
882
|
+
}),
|
|
883
|
+
children,
|
|
884
|
+
footer && /* @__PURE__ */ jsx(DialogFooter, { children: footer })
|
|
885
|
+
]
|
|
886
|
+
})
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
//#endregion
|
|
891
|
+
//#region src/components/color-picker/color-conversion.ts
|
|
892
|
+
/**
|
|
893
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
894
|
+
*
|
|
895
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
896
|
+
* you may not use this file except in compliance with the License.
|
|
897
|
+
* You may obtain a copy of the License at
|
|
898
|
+
*
|
|
899
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
900
|
+
*
|
|
901
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
902
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
903
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
904
|
+
* See the License for the specific language governing permissions and
|
|
905
|
+
* limitations under the License.
|
|
906
|
+
*/
|
|
907
|
+
const hsvToRgb = (h, s, v) => {
|
|
908
|
+
s = s / 100;
|
|
909
|
+
v = v / 100;
|
|
910
|
+
const c = v * s;
|
|
911
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
912
|
+
const m = v - c;
|
|
913
|
+
let r = 0;
|
|
914
|
+
let g = 0;
|
|
915
|
+
let b = 0;
|
|
916
|
+
if (h >= 0 && h < 60) {
|
|
917
|
+
r = c;
|
|
918
|
+
g = x;
|
|
919
|
+
b = 0;
|
|
920
|
+
} else if (h >= 60 && h < 120) {
|
|
921
|
+
r = x;
|
|
922
|
+
g = c;
|
|
923
|
+
b = 0;
|
|
924
|
+
} else if (h >= 120 && h < 180) {
|
|
925
|
+
r = 0;
|
|
926
|
+
g = c;
|
|
927
|
+
b = x;
|
|
928
|
+
} else if (h >= 180 && h < 240) {
|
|
929
|
+
r = 0;
|
|
930
|
+
g = x;
|
|
931
|
+
b = c;
|
|
932
|
+
} else if (h >= 240 && h < 300) {
|
|
933
|
+
r = x;
|
|
934
|
+
g = 0;
|
|
935
|
+
b = c;
|
|
936
|
+
} else if (h >= 300 && h < 360) {
|
|
937
|
+
r = c;
|
|
938
|
+
g = 0;
|
|
939
|
+
b = x;
|
|
940
|
+
}
|
|
941
|
+
return [
|
|
942
|
+
Math.round((r + m) * 255),
|
|
943
|
+
Math.round((g + m) * 255),
|
|
944
|
+
Math.round((b + m) * 255)
|
|
945
|
+
];
|
|
946
|
+
};
|
|
947
|
+
const rgbToHex = (r, g, b) => {
|
|
948
|
+
const toHex = (n) => n.toString(16).padStart(2, "0");
|
|
949
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
950
|
+
};
|
|
951
|
+
const rgbToHsv = (r, g, b) => {
|
|
952
|
+
r /= 255;
|
|
953
|
+
g /= 255;
|
|
954
|
+
b /= 255;
|
|
955
|
+
const max = Math.max(r, g, b);
|
|
956
|
+
const d = max - Math.min(r, g, b);
|
|
957
|
+
let h = 0;
|
|
958
|
+
let s = 0;
|
|
959
|
+
const v = max;
|
|
960
|
+
if (max !== 0) s = d / max;
|
|
961
|
+
if (d !== 0) {
|
|
962
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
963
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
964
|
+
else if (max === b) h = (r - g) / d + 4;
|
|
965
|
+
h *= 60;
|
|
966
|
+
}
|
|
967
|
+
return [
|
|
968
|
+
h,
|
|
969
|
+
s * 100,
|
|
970
|
+
v * 100
|
|
971
|
+
];
|
|
972
|
+
};
|
|
973
|
+
const hexToHsv = (hex) => {
|
|
974
|
+
if (hex.length === 4) hex = `#${hex.slice(1).split("").map((i) => i + i).join("")}`;
|
|
975
|
+
const [r, g, b] = hex.match(/\w\w/g).map((x) => Number.parseInt(x, 16));
|
|
976
|
+
return rgbToHsv(r, g, b);
|
|
977
|
+
};
|
|
978
|
+
const hsvToHex = (h, s, v) => {
|
|
979
|
+
const [r, g, b] = hsvToRgb(h, s, v);
|
|
980
|
+
return rgbToHex(r, g, b);
|
|
981
|
+
};
|
|
982
|
+
const hsvToRgba = (h, s, v, a) => {
|
|
983
|
+
const [r, g, b] = hsvToRgb(h, s, v);
|
|
984
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
985
|
+
};
|
|
986
|
+
const parseRgba = (rgba) => {
|
|
987
|
+
const match = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)/);
|
|
988
|
+
if (!match) throw new Error("Invalid RGBA string");
|
|
989
|
+
return [
|
|
990
|
+
Number.parseInt(match[1], 10),
|
|
991
|
+
Number.parseInt(match[2], 10),
|
|
992
|
+
Number.parseInt(match[3], 10),
|
|
993
|
+
match[4] ? Number.parseFloat(match[4]) : 1
|
|
994
|
+
];
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
//#endregion
|
|
998
|
+
//#region src/components/color-picker/AlphaSlider.tsx
|
|
999
|
+
/**
|
|
1000
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1001
|
+
*
|
|
1002
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1003
|
+
* you may not use this file except in compliance with the License.
|
|
1004
|
+
* You may obtain a copy of the License at
|
|
1005
|
+
*
|
|
1006
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1007
|
+
*
|
|
1008
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1009
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1010
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1011
|
+
* See the License for the specific language governing permissions and
|
|
1012
|
+
* limitations under the License.
|
|
1013
|
+
*/
|
|
1014
|
+
function AlphaSlider({ hsv, alpha, onChange, onChanged }) {
|
|
1015
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
1016
|
+
const sliderRef = useRef(null);
|
|
1017
|
+
const thumbRef = useRef(null);
|
|
1018
|
+
const calculateAlpha = useCallback((clientX) => {
|
|
1019
|
+
var _thumbRef$current$cli, _thumbRef$current;
|
|
1020
|
+
const slider = sliderRef.current;
|
|
1021
|
+
if (!slider) return;
|
|
1022
|
+
const thumbSize = (_thumbRef$current$cli = (_thumbRef$current = thumbRef.current) === null || _thumbRef$current === void 0 ? void 0 : _thumbRef$current.clientWidth) !== null && _thumbRef$current$cli !== void 0 ? _thumbRef$current$cli : 0;
|
|
1023
|
+
const rect = slider.getBoundingClientRect();
|
|
1024
|
+
const maxX = rect.width - thumbSize;
|
|
1025
|
+
if (maxX <= 0) {
|
|
1026
|
+
onChange(0);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
const x = Math.max(0, Math.min(clientX - rect.left, maxX));
|
|
1030
|
+
onChange(Math.round(x / maxX * 100) / 100);
|
|
1031
|
+
}, [onChange]);
|
|
1032
|
+
const handlePointerMove = useCallback((e) => {
|
|
1033
|
+
if (!isDragging) return;
|
|
1034
|
+
calculateAlpha(e.clientX);
|
|
1035
|
+
}, [isDragging, calculateAlpha]);
|
|
1036
|
+
const handlePointerUp = useCallback(() => {
|
|
1037
|
+
setIsDragging(false);
|
|
1038
|
+
onChanged === null || onChanged === void 0 || onChanged(alpha);
|
|
1039
|
+
}, [alpha]);
|
|
1040
|
+
useEffect(() => {
|
|
1041
|
+
if (isDragging) {
|
|
1042
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
1043
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
1044
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
1045
|
+
}
|
|
1046
|
+
return () => {
|
|
1047
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
1048
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
1049
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
1050
|
+
};
|
|
1051
|
+
}, [
|
|
1052
|
+
isDragging,
|
|
1053
|
+
handlePointerMove,
|
|
1054
|
+
handlePointerUp
|
|
1055
|
+
]);
|
|
1056
|
+
const getThumbPosition = () => {
|
|
1057
|
+
var _thumbRef$current$cli2, _thumbRef$current2, _sliderRef$current$cl, _sliderRef$current;
|
|
1058
|
+
const safeAlpha = Math.min(Math.max(alpha * 100, 0), 100);
|
|
1059
|
+
const thumbSize = (_thumbRef$current$cli2 = (_thumbRef$current2 = thumbRef.current) === null || _thumbRef$current2 === void 0 ? void 0 : _thumbRef$current2.clientWidth) !== null && _thumbRef$current$cli2 !== void 0 ? _thumbRef$current$cli2 : 0;
|
|
1060
|
+
const sliderWidth = (_sliderRef$current$cl = (_sliderRef$current = sliderRef.current) === null || _sliderRef$current === void 0 ? void 0 : _sliderRef$current.clientWidth) !== null && _sliderRef$current$cl !== void 0 ? _sliderRef$current$cl : 0;
|
|
1061
|
+
const thumbOffsetPercent = sliderWidth > 0 ? thumbSize / sliderWidth * 100 : 0;
|
|
1062
|
+
return `${safeAlpha / 100 * (100 - thumbOffsetPercent)}%`;
|
|
1063
|
+
};
|
|
1064
|
+
const color = hsvToRgb(...hsv);
|
|
1065
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1066
|
+
className: "univer-relative univer-w-full univer-select-none",
|
|
1067
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1068
|
+
className: "univer-absolute univer-inset-0 univer-rounded-full",
|
|
1069
|
+
style: {
|
|
1070
|
+
backgroundImage: "linear-gradient(45deg, #E3E5EA 25%, transparent 25%), linear-gradient(-45deg, #E3E5EA 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #E3E5EA 75%), linear-gradient(-45deg, transparent 75%, #E3E5EA 75%)",
|
|
1071
|
+
backgroundPosition: "0 0, 0 4px, 4px -4px, -4px 0",
|
|
1072
|
+
backgroundSize: "8px 8px"
|
|
1073
|
+
}
|
|
1074
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1075
|
+
ref: sliderRef,
|
|
1076
|
+
className: "univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner",
|
|
1077
|
+
style: { background: `linear-gradient(to right, transparent, rgb(${color.join(",")}))` },
|
|
1078
|
+
onPointerDown: (e) => {
|
|
1079
|
+
setIsDragging(true);
|
|
1080
|
+
calculateAlpha(e.clientX);
|
|
1081
|
+
},
|
|
1082
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1083
|
+
ref: thumbRef,
|
|
1084
|
+
className: "univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform",
|
|
1085
|
+
style: {
|
|
1086
|
+
left: getThumbPosition(),
|
|
1087
|
+
transform: "translateY(-50%)",
|
|
1088
|
+
transition: isDragging ? "none" : "all 0.1s ease-out"
|
|
1089
|
+
}
|
|
1090
|
+
})
|
|
1091
|
+
})]
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/components/color-picker/ColorInput.tsx
|
|
1097
|
+
function HexInput({ hsv, onChange }) {
|
|
1098
|
+
const [inputValue, setInputValue] = useState("");
|
|
1099
|
+
const hexValue = useMemo(() => hsvToHex(hsv[0], hsv[1], hsv[2]), [hsv]);
|
|
1100
|
+
useEffect(() => {
|
|
1101
|
+
setInputValue(hexValue.replace(/^#/, ""));
|
|
1102
|
+
}, [hexValue]);
|
|
1103
|
+
const isValidHex = (hex) => {
|
|
1104
|
+
return /^[0-9A-Fa-f]{6}$/.test(hex);
|
|
1105
|
+
};
|
|
1106
|
+
const handleChange = (e) => {
|
|
1107
|
+
const newValue = e.target.value.trim();
|
|
1108
|
+
if (newValue.length > 6) return;
|
|
1109
|
+
if (newValue !== "" && !/^[0-9A-Fa-f]*$/.test(newValue)) return;
|
|
1110
|
+
setInputValue(newValue);
|
|
1111
|
+
if (isValidHex(newValue)) {
|
|
1112
|
+
const hsvValue = hexToHsv(newValue);
|
|
1113
|
+
if (hsvValue && onChange) onChange(...hsvValue);
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
const handleBlur = () => {
|
|
1117
|
+
if (!isValidHex(inputValue)) setInputValue(hexValue.replace(/^#/, ""));
|
|
1118
|
+
};
|
|
1119
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
1120
|
+
className: clsx("univer-w-full univer-px-2 !univer-pl-4 univer-uppercase focus:univer-border-primary-500 focus:univer-outline-none dark:!univer-text-white", borderClassName),
|
|
1121
|
+
value: inputValue,
|
|
1122
|
+
onChange: handleChange,
|
|
1123
|
+
onBlur: handleBlur,
|
|
1124
|
+
maxLength: 6,
|
|
1125
|
+
spellCheck: false
|
|
1126
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1127
|
+
className: "univer-absolute univer-left-1.5 univer-top-1/2 -univer-translate-y-1/2 univer-text-sm univer-text-gray-400",
|
|
1128
|
+
children: "#"
|
|
1129
|
+
})] });
|
|
1130
|
+
}
|
|
1131
|
+
function RgbInput({ hsv, alpha, format, onChange }) {
|
|
1132
|
+
const [localValues, setLocalValues] = useState({
|
|
1133
|
+
r: 0,
|
|
1134
|
+
g: 0,
|
|
1135
|
+
b: 0,
|
|
1136
|
+
a: 1
|
|
1137
|
+
});
|
|
1138
|
+
useEffect(() => {
|
|
1139
|
+
const [r, g, b] = hsvToRgb(hsv[0], hsv[1], hsv[2]);
|
|
1140
|
+
setLocalValues({
|
|
1141
|
+
r: Math.round(r),
|
|
1142
|
+
g: Math.round(g),
|
|
1143
|
+
b: Math.round(b),
|
|
1144
|
+
a: alpha !== null && alpha !== void 0 ? alpha : 1
|
|
1145
|
+
});
|
|
1146
|
+
}, [hsv, alpha]);
|
|
1147
|
+
const handleChange = (color, value) => {
|
|
1148
|
+
if (color === "a") {
|
|
1149
|
+
if (value !== "" && !/^\d*\.?\d*$/.test(value)) return;
|
|
1150
|
+
const numValue = value === "" ? 0 : Number.parseFloat(value);
|
|
1151
|
+
if (numValue > 1) return;
|
|
1152
|
+
setLocalValues({
|
|
1153
|
+
...localValues,
|
|
1154
|
+
a: numValue
|
|
1155
|
+
});
|
|
1156
|
+
if (onChange) onChange(hsv[0], hsv[1], hsv[2], numValue);
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
if (value !== "" && !/^\d*$/.test(value)) return;
|
|
1160
|
+
const numValue = value === "" ? 0 : Number.parseInt(value, 10);
|
|
1161
|
+
if (numValue > 255) return;
|
|
1162
|
+
const newValues = {
|
|
1163
|
+
...localValues,
|
|
1164
|
+
[color]: numValue
|
|
1165
|
+
};
|
|
1166
|
+
setLocalValues(newValues);
|
|
1167
|
+
if (onChange) onChange(...rgbToHsv(newValues.r, newValues.g, newValues.b), localValues.a);
|
|
1168
|
+
};
|
|
1169
|
+
const handleBlur = () => {
|
|
1170
|
+
const [r, g, b] = hsvToRgb(hsv[0], hsv[1], hsv[2]);
|
|
1171
|
+
setLocalValues({
|
|
1172
|
+
r: Math.round(r),
|
|
1173
|
+
g: Math.round(g),
|
|
1174
|
+
b: Math.round(b),
|
|
1175
|
+
a: alpha !== null && alpha !== void 0 ? alpha : 1
|
|
1176
|
+
});
|
|
1177
|
+
};
|
|
1178
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1179
|
+
className: "univer-flex univer-items-center univer-gap-2 [&>input]:univer-w-11 [&>input]:univer-border-gray-200 [&>input]:focus:univer-border-primary-500 dark:[&>input]:!univer-border-gray-600 dark:[&>input]:!univer-text-white",
|
|
1180
|
+
children: [
|
|
1181
|
+
/* @__PURE__ */ jsx("input", {
|
|
1182
|
+
value: localValues.r,
|
|
1183
|
+
onChange: (e) => handleChange("r", e.target.value),
|
|
1184
|
+
onBlur: handleBlur,
|
|
1185
|
+
maxLength: 3
|
|
1186
|
+
}),
|
|
1187
|
+
/* @__PURE__ */ jsx("input", {
|
|
1188
|
+
value: localValues.g,
|
|
1189
|
+
onChange: (e) => handleChange("g", e.target.value),
|
|
1190
|
+
onBlur: handleBlur,
|
|
1191
|
+
maxLength: 3
|
|
1192
|
+
}),
|
|
1193
|
+
/* @__PURE__ */ jsx("input", {
|
|
1194
|
+
value: localValues.b,
|
|
1195
|
+
onChange: (e) => handleChange("b", e.target.value),
|
|
1196
|
+
onBlur: handleBlur,
|
|
1197
|
+
maxLength: 3
|
|
1198
|
+
}),
|
|
1199
|
+
format === "rgba" && /* @__PURE__ */ jsx("input", {
|
|
1200
|
+
value: localValues.a,
|
|
1201
|
+
onChange: (e) => handleChange("a", e.target.value),
|
|
1202
|
+
onBlur: handleBlur,
|
|
1203
|
+
maxLength: 4
|
|
1204
|
+
})
|
|
1205
|
+
]
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
function ColorInput({ hsv, alpha, format, onChange }) {
|
|
1209
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1210
|
+
className: "dark:![&_input]:univer-border-gray-600 dark:![&_input]:univer-text-white univer-flex univer-gap-2 [&_input]:univer-box-border [&_input]:univer-flex [&_input]:univer-h-7 [&_input]:univer-items-center [&_input]:univer-rounded [&_input]:univer-border [&_input]:univer-border-solid [&_input]:univer-border-gray-200 [&_input]:univer-bg-transparent [&_input]:univer-px-1.5 [&_input]:univer-text-sm [&_input]:univer-text-gray-700 [&_input]:univer-outline-none",
|
|
1211
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1212
|
+
className: "univer-relative univer-flex univer-flex-1 univer-gap-2",
|
|
1213
|
+
children: [/* @__PURE__ */ jsx(HexInput, {
|
|
1214
|
+
hsv,
|
|
1215
|
+
onChange
|
|
1216
|
+
}), /* @__PURE__ */ jsx(RgbInput, {
|
|
1217
|
+
hsv,
|
|
1218
|
+
alpha,
|
|
1219
|
+
format,
|
|
1220
|
+
onChange
|
|
1221
|
+
})]
|
|
1222
|
+
})
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
//#endregion
|
|
1227
|
+
//#region src/components/color-picker/presets.ts
|
|
1228
|
+
/**
|
|
1229
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1230
|
+
*
|
|
1231
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1232
|
+
* you may not use this file except in compliance with the License.
|
|
1233
|
+
* You may obtain a copy of the License at
|
|
1234
|
+
*
|
|
1235
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1236
|
+
*
|
|
1237
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1238
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1239
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1240
|
+
* See the License for the specific language governing permissions and
|
|
1241
|
+
* limitations under the License.
|
|
1242
|
+
*/
|
|
1243
|
+
const colorPresets = [
|
|
1244
|
+
[
|
|
1245
|
+
"#FFFFFF",
|
|
1246
|
+
"#E1EFFE",
|
|
1247
|
+
"#FDE8E8",
|
|
1248
|
+
"#FEECDC",
|
|
1249
|
+
"#FFF4B9",
|
|
1250
|
+
"#DEF7EC",
|
|
1251
|
+
"#D5F5F6",
|
|
1252
|
+
"#EDEBFE",
|
|
1253
|
+
"#FCE8F3"
|
|
1254
|
+
],
|
|
1255
|
+
[
|
|
1256
|
+
"#CDD0D8",
|
|
1257
|
+
"#A4CAFE",
|
|
1258
|
+
"#F8B4B4",
|
|
1259
|
+
"#FDBA8C",
|
|
1260
|
+
"#FAC815",
|
|
1261
|
+
"#84E1BC",
|
|
1262
|
+
"#7EDCE2",
|
|
1263
|
+
"#CABFFD",
|
|
1264
|
+
"#F8B4D9"
|
|
1265
|
+
],
|
|
1266
|
+
[
|
|
1267
|
+
"#979DAC",
|
|
1268
|
+
"#3F83F8",
|
|
1269
|
+
"#F05252",
|
|
1270
|
+
"#FF5A1F",
|
|
1271
|
+
"#D49D0F",
|
|
1272
|
+
"#0DA471",
|
|
1273
|
+
"#0694A2",
|
|
1274
|
+
"#9061F9",
|
|
1275
|
+
"#E74694"
|
|
1276
|
+
],
|
|
1277
|
+
[
|
|
1278
|
+
"#414657",
|
|
1279
|
+
"#1A56DB",
|
|
1280
|
+
"#C81E1E",
|
|
1281
|
+
"#B43403",
|
|
1282
|
+
"#9A6D15",
|
|
1283
|
+
"#046C4E",
|
|
1284
|
+
"#036672",
|
|
1285
|
+
"#6C2BD9",
|
|
1286
|
+
"#BF125D"
|
|
1287
|
+
],
|
|
1288
|
+
[
|
|
1289
|
+
"#000000",
|
|
1290
|
+
"#233876",
|
|
1291
|
+
"#771D1D",
|
|
1292
|
+
"#8A2C0D",
|
|
1293
|
+
"#634312",
|
|
1294
|
+
"#014737",
|
|
1295
|
+
"#014451",
|
|
1296
|
+
"#4A1D96",
|
|
1297
|
+
"#751A3D"
|
|
1298
|
+
]
|
|
1299
|
+
];
|
|
1300
|
+
|
|
1301
|
+
//#endregion
|
|
1302
|
+
//#region src/components/color-picker/ColorPresets.tsx
|
|
1303
|
+
/**
|
|
1304
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1305
|
+
*
|
|
1306
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1307
|
+
* you may not use this file except in compliance with the License.
|
|
1308
|
+
* You may obtain a copy of the License at
|
|
1309
|
+
*
|
|
1310
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1311
|
+
*
|
|
1312
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1313
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1314
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1315
|
+
* See the License for the specific language governing permissions and
|
|
1316
|
+
* limitations under the License.
|
|
1317
|
+
*/
|
|
1318
|
+
function ColorPresets({ hsv, onChange }) {
|
|
1319
|
+
const handleSelectPreset = useCallback((color) => {
|
|
1320
|
+
const [h, s, v] = hexToHsv(color);
|
|
1321
|
+
onChange(h, s, v);
|
|
1322
|
+
}, [onChange]);
|
|
1323
|
+
const currentColor = hsvToHex(hsv[0], hsv[1], hsv[2]);
|
|
1324
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1325
|
+
"data-u-comp": "color-picker-presets",
|
|
1326
|
+
className: "univer-grid univer-content-center univer-gap-2",
|
|
1327
|
+
children: colorPresets.map((row, i) => /* @__PURE__ */ jsx("div", {
|
|
1328
|
+
className: "univer-grid univer-grid-flow-col univer-items-center univer-justify-between univer-gap-2",
|
|
1329
|
+
children: row.map((color, j) => /* @__PURE__ */ jsx("button", {
|
|
1330
|
+
type: "button",
|
|
1331
|
+
className: clsx("univer-box-border univer-size-5 univer-cursor-pointer univer-rounded-full univer-border univer-border-solid univer-border-transparent univer-bg-gray-300 univer-transition-shadow", {
|
|
1332
|
+
"univer-ring-2 univer-ring-offset-2 univer-ring-offset-white dark:!univer-ring-primary-600 dark:!univer-ring-offset-gray-600": color.toUpperCase() === currentColor.toUpperCase(),
|
|
1333
|
+
"!univer-border-gray-200": i === 0 && j === 0
|
|
1334
|
+
}),
|
|
1335
|
+
style: { backgroundColor: color },
|
|
1336
|
+
onClick: () => handleSelectPreset(color)
|
|
1337
|
+
}, j))
|
|
1338
|
+
}, i))
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
//#endregion
|
|
1343
|
+
//#region src/components/color-picker/ColorSpectrum.tsx
|
|
1344
|
+
function ColorSpectrum({ hsv, onChange, onChanged }) {
|
|
1345
|
+
const canvasRef = useRef(null);
|
|
1346
|
+
const containerRef = useRef(null);
|
|
1347
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
1348
|
+
useEffect(() => {
|
|
1349
|
+
const canvas = canvasRef.current;
|
|
1350
|
+
if (!canvas) return;
|
|
1351
|
+
const ctx = canvas.getContext("2d");
|
|
1352
|
+
if (!ctx) return;
|
|
1353
|
+
const gradientS = ctx.createLinearGradient(0, 0, canvas.width, 0);
|
|
1354
|
+
gradientS.addColorStop(0, `hsl(${hsv[0]}, 0%, 50%)`);
|
|
1355
|
+
gradientS.addColorStop(1, `hsl(${hsv[0]}, 100%, 50%)`);
|
|
1356
|
+
ctx.fillStyle = gradientS;
|
|
1357
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
1358
|
+
const gradientV = ctx.createLinearGradient(0, 0, 0, canvas.height);
|
|
1359
|
+
gradientV.addColorStop(0, "rgba(255, 255, 255, 0)");
|
|
1360
|
+
gradientV.addColorStop(1, "rgba(0, 0, 0, 1)");
|
|
1361
|
+
ctx.fillStyle = gradientV;
|
|
1362
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
1363
|
+
}, [hsv]);
|
|
1364
|
+
const handlePointerEvent = (e) => {
|
|
1365
|
+
e.stopPropagation();
|
|
1366
|
+
const canvas = canvasRef.current;
|
|
1367
|
+
if (!canvas) return;
|
|
1368
|
+
const rect = canvas.getBoundingClientRect();
|
|
1369
|
+
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
|
|
1370
|
+
const y = Math.max(0, Math.min(e.clientY - rect.top, rect.height));
|
|
1371
|
+
const s = x / rect.width * 100;
|
|
1372
|
+
const v = 100 - y / rect.height * 100;
|
|
1373
|
+
onChange(hsv[0], s, v);
|
|
1374
|
+
};
|
|
1375
|
+
const handlePointerUp = useCallback(() => {
|
|
1376
|
+
setIsDragging(false);
|
|
1377
|
+
}, [hsv]);
|
|
1378
|
+
function handleChange() {
|
|
1379
|
+
onChanged === null || onChanged === void 0 || onChanged(hsv[0], hsv[1], hsv[2]);
|
|
1380
|
+
}
|
|
1381
|
+
useEffect(() => {
|
|
1382
|
+
var _containerRef$current;
|
|
1383
|
+
(_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 || _containerRef$current.addEventListener("mouseup", handleChange);
|
|
1384
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
1385
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
1386
|
+
return () => {
|
|
1387
|
+
var _containerRef$current2;
|
|
1388
|
+
(_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 || _containerRef$current2.removeEventListener("mouseup", handleChange);
|
|
1389
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
1390
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
1391
|
+
};
|
|
1392
|
+
}, [hsv]);
|
|
1393
|
+
const getIndicatorStyles = () => {
|
|
1394
|
+
var _containerRef$current3, _containerRef$current4, _containerRef$current5, _containerRef$current6;
|
|
1395
|
+
const halfIndicatorSize = 16 / 2;
|
|
1396
|
+
const w = (_containerRef$current3 = (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.clientWidth) !== null && _containerRef$current3 !== void 0 ? _containerRef$current3 : 0;
|
|
1397
|
+
const h = (_containerRef$current5 = (_containerRef$current6 = containerRef.current) === null || _containerRef$current6 === void 0 ? void 0 : _containerRef$current6.clientHeight) !== null && _containerRef$current5 !== void 0 ? _containerRef$current5 : 0;
|
|
1398
|
+
return {
|
|
1399
|
+
transform: `translate(${hsv[1] / 100 * w - halfIndicatorSize}px, ${(100 - hsv[2]) / 100 * h - halfIndicatorSize}px)`,
|
|
1400
|
+
transition: isDragging ? "none" : "transform 0.1s ease-out"
|
|
1401
|
+
};
|
|
1402
|
+
};
|
|
1403
|
+
useEffect(() => {
|
|
1404
|
+
const handlePointerUp = () => {
|
|
1405
|
+
setIsDragging(false);
|
|
1406
|
+
};
|
|
1407
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
1408
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
1409
|
+
return () => {
|
|
1410
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
1411
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
1412
|
+
};
|
|
1413
|
+
}, []);
|
|
1414
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1415
|
+
"data-u-comp": "color-picker-spectrum",
|
|
1416
|
+
ref: containerRef,
|
|
1417
|
+
className: "univer-relative univer-overflow-hidden",
|
|
1418
|
+
children: [/* @__PURE__ */ jsx("canvas", {
|
|
1419
|
+
ref: canvasRef,
|
|
1420
|
+
className: "univer-size-full univer-cursor-crosshair univer-rounded",
|
|
1421
|
+
onPointerDown: (e) => {
|
|
1422
|
+
setIsDragging(true);
|
|
1423
|
+
handlePointerEvent(e);
|
|
1424
|
+
},
|
|
1425
|
+
onPointerMove: (e) => isDragging && handlePointerEvent(e)
|
|
1426
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1427
|
+
className: "univer-pointer-events-none univer-absolute univer-left-0 univer-top-0 univer-size-4 univer-rounded-full univer-border-2 univer-border-white univer-shadow-md univer-ring-2 univer-ring-white univer-will-change-transform",
|
|
1428
|
+
style: getIndicatorStyles()
|
|
1429
|
+
})]
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
//#endregion
|
|
1434
|
+
//#region src/components/color-picker/HueSlider.tsx
|
|
1435
|
+
/**
|
|
1436
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1437
|
+
*
|
|
1438
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1439
|
+
* you may not use this file except in compliance with the License.
|
|
1440
|
+
* You may obtain a copy of the License at
|
|
1441
|
+
*
|
|
1442
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1443
|
+
*
|
|
1444
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1445
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1446
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1447
|
+
* See the License for the specific language governing permissions and
|
|
1448
|
+
* limitations under the License.
|
|
1449
|
+
*/
|
|
1450
|
+
function HueSlider({ hsv, onChange, onChanged }) {
|
|
1451
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
1452
|
+
const sliderRef = useRef(null);
|
|
1453
|
+
const thumbRef = useRef(null);
|
|
1454
|
+
const calculateHue = useCallback((clientX) => {
|
|
1455
|
+
var _thumbRef$current$cli, _thumbRef$current;
|
|
1456
|
+
const slider = sliderRef.current;
|
|
1457
|
+
if (!slider) return;
|
|
1458
|
+
const thumbSize = (_thumbRef$current$cli = (_thumbRef$current = thumbRef.current) === null || _thumbRef$current === void 0 ? void 0 : _thumbRef$current.clientWidth) !== null && _thumbRef$current$cli !== void 0 ? _thumbRef$current$cli : 0;
|
|
1459
|
+
const rect = slider.getBoundingClientRect();
|
|
1460
|
+
const maxX = rect.width - thumbSize;
|
|
1461
|
+
if (maxX <= 0) {
|
|
1462
|
+
onChange(0, hsv[1], hsv[2]);
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
const x = Math.max(0, Math.min(clientX - rect.left, maxX));
|
|
1466
|
+
onChange(Math.round(x / maxX * 360), hsv[1], hsv[2]);
|
|
1467
|
+
}, [hsv, onChange]);
|
|
1468
|
+
const handlePointerMove = useCallback((e) => {
|
|
1469
|
+
e.stopPropagation();
|
|
1470
|
+
if (!isDragging) return;
|
|
1471
|
+
calculateHue(e.clientX);
|
|
1472
|
+
}, [isDragging, calculateHue]);
|
|
1473
|
+
const handlePointerUp = useCallback(() => {
|
|
1474
|
+
setIsDragging(false);
|
|
1475
|
+
onChanged === null || onChanged === void 0 || onChanged(hsv[0], hsv[1], hsv[2]);
|
|
1476
|
+
}, [hsv, onChanged]);
|
|
1477
|
+
useEffect(() => {
|
|
1478
|
+
if (isDragging) {
|
|
1479
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
1480
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
1481
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
1482
|
+
}
|
|
1483
|
+
return () => {
|
|
1484
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
1485
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
1486
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
1487
|
+
};
|
|
1488
|
+
}, [
|
|
1489
|
+
isDragging,
|
|
1490
|
+
handlePointerMove,
|
|
1491
|
+
handlePointerUp
|
|
1492
|
+
]);
|
|
1493
|
+
const getThumbPosition = () => {
|
|
1494
|
+
var _thumbRef$current$cli2, _thumbRef$current2, _sliderRef$current$cl, _sliderRef$current;
|
|
1495
|
+
const safeHue = Math.min(Math.max(hsv[0], 0), 360);
|
|
1496
|
+
const thumbSize = (_thumbRef$current$cli2 = (_thumbRef$current2 = thumbRef.current) === null || _thumbRef$current2 === void 0 ? void 0 : _thumbRef$current2.clientWidth) !== null && _thumbRef$current$cli2 !== void 0 ? _thumbRef$current$cli2 : 0;
|
|
1497
|
+
const sliderWidth = (_sliderRef$current$cl = (_sliderRef$current = sliderRef.current) === null || _sliderRef$current === void 0 ? void 0 : _sliderRef$current.clientWidth) !== null && _sliderRef$current$cl !== void 0 ? _sliderRef$current$cl : 0;
|
|
1498
|
+
const thumbOffsetPercent = sliderWidth > 0 ? thumbSize / sliderWidth * 100 : 0;
|
|
1499
|
+
return `${safeHue / 360 * (100 - thumbOffsetPercent)}%`;
|
|
1500
|
+
};
|
|
1501
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1502
|
+
"data-u-comp": "color-picker-hue-slider",
|
|
1503
|
+
className: "univer-relative univer-w-full univer-select-none",
|
|
1504
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1505
|
+
ref: sliderRef,
|
|
1506
|
+
className: "univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner",
|
|
1507
|
+
style: { background: `linear-gradient(to right,
|
|
45
1508
|
hsl(0, 100%, 50%),
|
|
46
1509
|
hsl(60, 100%, 50%),
|
|
47
1510
|
hsl(120, 100%, 50%),
|
|
48
1511
|
hsl(180, 100%, 50%),
|
|
49
1512
|
hsl(240, 100%, 50%),
|
|
50
1513
|
hsl(300, 100%, 50%),
|
|
51
|
-
hsl(360, 100%, 50%))`
|
|
1514
|
+
hsl(360, 100%, 50%))` },
|
|
1515
|
+
onPointerDown: (e) => {
|
|
1516
|
+
setIsDragging(true);
|
|
1517
|
+
calculateHue(e.clientX);
|
|
1518
|
+
},
|
|
1519
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1520
|
+
ref: thumbRef,
|
|
1521
|
+
className: "univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform",
|
|
1522
|
+
style: {
|
|
1523
|
+
left: getThumbPosition(),
|
|
1524
|
+
transform: "translateY(-50%)",
|
|
1525
|
+
transition: isDragging ? "none" : "all 0.1s ease-out"
|
|
1526
|
+
}
|
|
1527
|
+
})
|
|
1528
|
+
})
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
//#endregion
|
|
1533
|
+
//#region src/components/color-picker/ColorPicker.tsx
|
|
1534
|
+
/**
|
|
1535
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1536
|
+
*
|
|
1537
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1538
|
+
* you may not use this file except in compliance with the License.
|
|
1539
|
+
* You may obtain a copy of the License at
|
|
1540
|
+
*
|
|
1541
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1542
|
+
*
|
|
1543
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1544
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1545
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1546
|
+
* See the License for the specific language governing permissions and
|
|
1547
|
+
* limitations under the License.
|
|
1548
|
+
*/
|
|
1549
|
+
const MemoizedColorSpectrum = memo(ColorSpectrum);
|
|
1550
|
+
const MemoizedHueSlider = memo(HueSlider);
|
|
1551
|
+
const MemoizedAlphaSlider = memo(AlphaSlider);
|
|
1552
|
+
const MemoizedColorInput = memo(ColorInput);
|
|
1553
|
+
const MemoizedColorPresets = memo(ColorPresets);
|
|
1554
|
+
function ColorPicker({ format = "hex", value, onChange }) {
|
|
1555
|
+
if (!isBrowser) return null;
|
|
1556
|
+
const { locale } = useContext(ConfigContext);
|
|
1557
|
+
const [hsv, setHsv] = useState([
|
|
1558
|
+
0,
|
|
1559
|
+
100,
|
|
1560
|
+
100
|
|
1561
|
+
]);
|
|
1562
|
+
const [alpha, setAlpha] = useState(1);
|
|
1563
|
+
const [visible, setVisible] = useState(false);
|
|
1564
|
+
const getRgb = useCallback((h, s, v) => {
|
|
1565
|
+
return hsvToRgb(h, s, v);
|
|
1566
|
+
}, []);
|
|
1567
|
+
useEffect(() => {
|
|
1568
|
+
try {
|
|
1569
|
+
const actualValue = value || (format === "hex" ? "#000000" : "rgba(0, 0, 0, 1)");
|
|
1570
|
+
if (format === "hex") {
|
|
1571
|
+
const [h, s, v] = hexToHsv(actualValue);
|
|
1572
|
+
setHsv([
|
|
1573
|
+
h,
|
|
1574
|
+
s,
|
|
1575
|
+
v
|
|
1576
|
+
]);
|
|
1577
|
+
setAlpha(1);
|
|
1578
|
+
} else if (format === "rgba") {
|
|
1579
|
+
const [r, g, b, a] = parseRgba(actualValue);
|
|
1580
|
+
const [h, s, v] = rgbToHsv(r, g, b);
|
|
1581
|
+
setHsv([
|
|
1582
|
+
h,
|
|
1583
|
+
s,
|
|
1584
|
+
v
|
|
1585
|
+
]);
|
|
1586
|
+
setAlpha(a);
|
|
1587
|
+
}
|
|
1588
|
+
} catch (error) {
|
|
1589
|
+
console.error("Invalid value:", error);
|
|
1590
|
+
}
|
|
1591
|
+
}, [value, format]);
|
|
1592
|
+
function handleColorChange(h, s, v) {
|
|
1593
|
+
setHsv([
|
|
1594
|
+
h,
|
|
1595
|
+
s,
|
|
1596
|
+
v
|
|
1597
|
+
]);
|
|
1598
|
+
}
|
|
1599
|
+
function handleAlphaChange(a) {
|
|
1600
|
+
setAlpha(a);
|
|
1601
|
+
}
|
|
1602
|
+
function handleColorChanged(h, s, v, a = alpha) {
|
|
1603
|
+
if (format === "hex") {
|
|
1604
|
+
const [r, g, b] = getRgb(h, s, v);
|
|
1605
|
+
const hex = rgbToHex(r, g, b);
|
|
1606
|
+
onChange === null || onChange === void 0 || onChange(hex);
|
|
1607
|
+
} else if (format === "rgba") {
|
|
1608
|
+
const [r, g, b] = getRgb(h, s, v);
|
|
1609
|
+
onChange === null || onChange === void 0 || onChange(`rgba(${r}, ${g}, ${b}, ${a})`);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
function handleConfirmCustomColor() {
|
|
1613
|
+
const [h, s, v] = hsv;
|
|
1614
|
+
if (format === "hex") {
|
|
1615
|
+
const hex = hsvToHex(h, s, v);
|
|
1616
|
+
onChange === null || onChange === void 0 || onChange(hex);
|
|
1617
|
+
} else if (format === "rgba") {
|
|
1618
|
+
const [r, g, b] = getRgb(h, s, v);
|
|
1619
|
+
onChange === null || onChange === void 0 || onChange(`rgba(${r}, ${g}, ${b}, ${alpha})`);
|
|
1620
|
+
}
|
|
1621
|
+
setVisible(false);
|
|
1622
|
+
}
|
|
1623
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1624
|
+
"data-u-comp": "color-picker",
|
|
1625
|
+
className: "univer-cursor-default univer-space-y-2 univer-rounded-lg",
|
|
1626
|
+
onClick: (e) => e.stopPropagation(),
|
|
1627
|
+
children: [
|
|
1628
|
+
/* @__PURE__ */ jsx(MemoizedColorPresets, {
|
|
1629
|
+
hsv,
|
|
1630
|
+
onChange: (h, s, v) => {
|
|
1631
|
+
handleColorChange(h, s, v);
|
|
1632
|
+
handleAlphaChange(1);
|
|
1633
|
+
handleColorChanged(h, s, v, 1);
|
|
1634
|
+
}
|
|
1635
|
+
}),
|
|
1636
|
+
/* @__PURE__ */ jsx("div", {
|
|
1637
|
+
className: "univer-flex univer-h-7 univer-items-center",
|
|
1638
|
+
children: /* @__PURE__ */ jsx("a", {
|
|
1639
|
+
className: "univer-cursor-pointer univer-gap-2 univer-text-sm univer-text-gray-900 univer-transition-opacity hover:univer-opacity-80 dark:!univer-text-white",
|
|
1640
|
+
onClick: () => setVisible(true),
|
|
1641
|
+
children: locale === null || locale === void 0 ? void 0 : locale.ColorPicker.more
|
|
1642
|
+
})
|
|
1643
|
+
}),
|
|
1644
|
+
/* @__PURE__ */ jsx(Dialog, {
|
|
1645
|
+
className: "!univer-w-fit !univer-p-2.5",
|
|
1646
|
+
closable: false,
|
|
1647
|
+
maskClosable: false,
|
|
1648
|
+
open: visible,
|
|
1649
|
+
onOpenChange: setVisible,
|
|
1650
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1651
|
+
className: "univer-grid univer-w-64 univer-gap-2",
|
|
1652
|
+
children: [
|
|
1653
|
+
/* @__PURE__ */ jsx(MemoizedColorSpectrum, {
|
|
1654
|
+
hsv,
|
|
1655
|
+
onChange: handleColorChange
|
|
1656
|
+
}),
|
|
1657
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1658
|
+
className: "univer-flex univer-items-center univer-gap-2",
|
|
1659
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1660
|
+
className: "univer-size-6 univer-flex-shrink-0 univer-rounded-sm",
|
|
1661
|
+
style: { backgroundColor: format === "hex" ? hsvToHex(...hsv) : hsvToRgba(...hsv, alpha) }
|
|
1662
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1663
|
+
className: "univer-flex-1 univer-space-y-2",
|
|
1664
|
+
children: [/* @__PURE__ */ jsx(MemoizedHueSlider, {
|
|
1665
|
+
hsv,
|
|
1666
|
+
onChange: handleColorChange
|
|
1667
|
+
}), format === "rgba" && /* @__PURE__ */ jsx(MemoizedAlphaSlider, {
|
|
1668
|
+
hsv,
|
|
1669
|
+
alpha,
|
|
1670
|
+
onChange: handleAlphaChange
|
|
1671
|
+
})]
|
|
1672
|
+
})]
|
|
1673
|
+
}),
|
|
1674
|
+
/* @__PURE__ */ jsx(MemoizedColorInput, {
|
|
1675
|
+
hsv,
|
|
1676
|
+
alpha,
|
|
1677
|
+
format,
|
|
1678
|
+
onChange: (h, s, v, a) => {
|
|
1679
|
+
handleColorChange(h, s, v);
|
|
1680
|
+
if (a !== void 0) handleAlphaChange(a);
|
|
1681
|
+
}
|
|
1682
|
+
}),
|
|
1683
|
+
/* @__PURE__ */ jsxs("footer", {
|
|
1684
|
+
className: "univer-flex univer-items-center univer-justify-end univer-gap-2",
|
|
1685
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1686
|
+
onClick: () => setVisible(false),
|
|
1687
|
+
children: locale === null || locale === void 0 ? void 0 : locale.ColorPicker.cancel
|
|
1688
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1689
|
+
variant: "primary",
|
|
1690
|
+
onClick: handleConfirmCustomColor,
|
|
1691
|
+
children: locale === null || locale === void 0 ? void 0 : locale.ColorPicker.confirm
|
|
1692
|
+
})]
|
|
1693
|
+
})
|
|
1694
|
+
]
|
|
1695
|
+
})
|
|
1696
|
+
})
|
|
1697
|
+
]
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
//#endregion
|
|
1702
|
+
//#region src/components/confirm/Confirm.tsx
|
|
1703
|
+
function Footer(props) {
|
|
1704
|
+
const { locale, cancelText, confirmText, onClose, onConfirm, closable = true } = props;
|
|
1705
|
+
return /* @__PURE__ */ jsxs("footer", {
|
|
1706
|
+
className: "univer-flex univer-items-center univer-justify-end univer-gap-2",
|
|
1707
|
+
children: [closable && /* @__PURE__ */ jsx(Button, {
|
|
1708
|
+
onClick: onClose,
|
|
1709
|
+
children: cancelText !== null && cancelText !== void 0 ? cancelText : locale === null || locale === void 0 ? void 0 : locale.Confirm.cancel
|
|
1710
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1711
|
+
variant: "primary",
|
|
1712
|
+
onClick: onConfirm,
|
|
1713
|
+
children: confirmText !== null && confirmText !== void 0 ? confirmText : locale === null || locale === void 0 ? void 0 : locale.Confirm.confirm
|
|
1714
|
+
})]
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
function Confirm(props) {
|
|
1718
|
+
const { children, visible = false, title, cancelText, confirmText, width, onClose, onConfirm, closable = true } = props;
|
|
1719
|
+
const { locale } = useContext(ConfigContext);
|
|
1720
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
1721
|
+
open: visible,
|
|
1722
|
+
title,
|
|
1723
|
+
maskClosable: false,
|
|
1724
|
+
footer: /* @__PURE__ */ jsx(Footer, {
|
|
1725
|
+
locale,
|
|
1726
|
+
cancelText,
|
|
1727
|
+
confirmText,
|
|
1728
|
+
onClose,
|
|
1729
|
+
onConfirm,
|
|
1730
|
+
closable
|
|
1731
|
+
}),
|
|
1732
|
+
onClose,
|
|
1733
|
+
width,
|
|
1734
|
+
closable,
|
|
1735
|
+
children
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
//#endregion
|
|
1740
|
+
//#region src/components/dropdown/PopoverPrimitive.tsx
|
|
1741
|
+
function PopoverPrimitive({ ...props }) {
|
|
1742
|
+
return /* @__PURE__ */ jsx(Root$1, {
|
|
1743
|
+
"data-slot": "popover",
|
|
1744
|
+
...props
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
function PopoverTrigger({ ...props }) {
|
|
1748
|
+
return /* @__PURE__ */ jsx(Trigger, {
|
|
1749
|
+
"data-slot": "popover-trigger",
|
|
1750
|
+
...props
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
function PopoverContent({ className, align = "center", sideOffset = 4, ...props }) {
|
|
1754
|
+
return /* @__PURE__ */ jsx(Portal$1, { children: /* @__PURE__ */ jsx(Content$1, {
|
|
1755
|
+
"data-slot": "popover-content",
|
|
1756
|
+
align,
|
|
1757
|
+
sideOffset,
|
|
1758
|
+
className: clsx("univer-outline-hidden data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-900 dark:!univer-text-white dark:focus-visible:!univer-border-gray-600", borderClassName, scrollbarClassName, className),
|
|
1759
|
+
...props
|
|
1760
|
+
}) });
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
//#endregion
|
|
1764
|
+
//#region src/components/dropdown/Dropdown.tsx
|
|
1765
|
+
function Dropdown(props) {
|
|
1766
|
+
const { children, overlay, disabled, open: controlledOpen, onOpenChange: controlledOnOpenChange, ...restProps } = props;
|
|
1767
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
1768
|
+
const isControlled = controlledOpen !== void 0;
|
|
1769
|
+
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
1770
|
+
function handleChangeOpen(newOpen) {
|
|
1771
|
+
if (disabled) return;
|
|
1772
|
+
if (!isControlled) setUncontrolledOpen(newOpen);
|
|
1773
|
+
controlledOnOpenChange === null || controlledOnOpenChange === void 0 || controlledOnOpenChange(newOpen);
|
|
1774
|
+
}
|
|
1775
|
+
return /* @__PURE__ */ jsxs(PopoverPrimitive, {
|
|
1776
|
+
open,
|
|
1777
|
+
onOpenChange: handleChangeOpen,
|
|
1778
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
1779
|
+
asChild: true,
|
|
1780
|
+
children
|
|
1781
|
+
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
1782
|
+
...restProps,
|
|
1783
|
+
children: overlay
|
|
1784
|
+
})]
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
//#endregion
|
|
1789
|
+
//#region src/components/date-picker/DatePicker.tsx
|
|
1790
|
+
/**
|
|
1791
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1792
|
+
*
|
|
1793
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1794
|
+
* you may not use this file except in compliance with the License.
|
|
1795
|
+
* You may obtain a copy of the License at
|
|
1796
|
+
*
|
|
1797
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1798
|
+
*
|
|
1799
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1800
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1801
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1802
|
+
* See the License for the specific language governing permissions and
|
|
1803
|
+
* limitations under the License.
|
|
1804
|
+
*/
|
|
1805
|
+
function DatePicker(props) {
|
|
1806
|
+
const { value, onValueChange, className } = props;
|
|
1807
|
+
const [open, setOpen] = useState(false);
|
|
1808
|
+
function handleValueChange(date) {
|
|
1809
|
+
onValueChange === null || onValueChange === void 0 || onValueChange(date);
|
|
1810
|
+
setOpen(false);
|
|
1811
|
+
}
|
|
1812
|
+
return /* @__PURE__ */ jsx(Dropdown, {
|
|
1813
|
+
align: "start",
|
|
1814
|
+
overlay: /* @__PURE__ */ jsx("div", {
|
|
1815
|
+
className: "univer-p-2",
|
|
1816
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
1817
|
+
value,
|
|
1818
|
+
onValueChange: handleValueChange
|
|
1819
|
+
})
|
|
1820
|
+
}),
|
|
1821
|
+
open,
|
|
1822
|
+
onOpenChange: setOpen,
|
|
1823
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
1824
|
+
className: clsx("univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all hover:univer-border-primary-600 dark:!univer-text-white", borderClassName, className),
|
|
1825
|
+
type: "button",
|
|
1826
|
+
children: [formatDateWithPattern(value, "YYYY-MM-DD"), /* @__PURE__ */ jsx(CalendarIcon, { className: "univer-text-gray-600 dark:!univer-text-gray-400" })]
|
|
1827
|
+
})
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
//#endregion
|
|
1832
|
+
//#region src/components/date-range-picker/DateRangePicker.tsx
|
|
1833
|
+
/**
|
|
1834
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1835
|
+
*
|
|
1836
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1837
|
+
* you may not use this file except in compliance with the License.
|
|
1838
|
+
* You may obtain a copy of the License at
|
|
1839
|
+
*
|
|
1840
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1841
|
+
*
|
|
1842
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1843
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1844
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1845
|
+
* See the License for the specific language governing permissions and
|
|
1846
|
+
* limitations under the License.
|
|
1847
|
+
*/
|
|
1848
|
+
function DateRangePicker(props) {
|
|
1849
|
+
const { value = [/* @__PURE__ */ new Date(), /* @__PURE__ */ new Date()], onValueChange, className } = props;
|
|
1850
|
+
const [open, setOpen] = useState(false);
|
|
1851
|
+
function handleValueChange(date) {
|
|
1852
|
+
let [start, end] = date;
|
|
1853
|
+
if (start > end) [start, end] = [end, start];
|
|
1854
|
+
onValueChange === null || onValueChange === void 0 || onValueChange([start, end]);
|
|
1855
|
+
setOpen(false);
|
|
1856
|
+
}
|
|
1857
|
+
return /* @__PURE__ */ jsx(Dropdown, {
|
|
1858
|
+
align: "start",
|
|
1859
|
+
overlay: /* @__PURE__ */ jsxs("div", {
|
|
1860
|
+
className: "univer-grid univer-grid-cols-2 univer-gap-2 univer-p-2",
|
|
1861
|
+
children: [/* @__PURE__ */ jsx(Calendar, {
|
|
1862
|
+
value: value[0],
|
|
1863
|
+
max: value[1],
|
|
1864
|
+
onValueChange: (date) => {
|
|
1865
|
+
handleValueChange([date, value[1]]);
|
|
1866
|
+
}
|
|
1867
|
+
}), /* @__PURE__ */ jsx(Calendar, {
|
|
1868
|
+
value: value[1],
|
|
1869
|
+
min: value[0],
|
|
1870
|
+
onValueChange: (date) => {
|
|
1871
|
+
handleValueChange([value[0], date]);
|
|
1872
|
+
}
|
|
1873
|
+
})]
|
|
1874
|
+
}),
|
|
1875
|
+
open,
|
|
1876
|
+
onOpenChange: setOpen,
|
|
1877
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
1878
|
+
className: clsx("univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all hover:univer-border-primary-600 dark:!univer-text-white", borderClassName, className),
|
|
1879
|
+
type: "button",
|
|
1880
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1881
|
+
className: "univer-flex univer-gap-1",
|
|
1882
|
+
children: [
|
|
1883
|
+
/* @__PURE__ */ jsx("span", { children: formatDateWithPattern(value[0], "YYYY-MM-DD") }),
|
|
1884
|
+
/* @__PURE__ */ jsx("span", { children: "-" }),
|
|
1885
|
+
/* @__PURE__ */ jsx("span", { children: formatDateWithPattern(value[1], "YYYY-MM-DD") })
|
|
1886
|
+
]
|
|
1887
|
+
}), /* @__PURE__ */ jsx(CalendarIcon, { className: "univer-text-gray-600 dark:!univer-text-gray-400" })]
|
|
1888
|
+
})
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
//#endregion
|
|
1893
|
+
//#region src/components/draggable-list/DraggableList.tsx
|
|
1894
|
+
function moveItemByIndex(list, fromIndex, toIndex) {
|
|
1895
|
+
if (fromIndex === toIndex || fromIndex < 0 || toIndex < 0 || fromIndex >= list.length || toIndex >= list.length) return list;
|
|
1896
|
+
const next = [...list];
|
|
1897
|
+
const [item] = next.splice(fromIndex, 1);
|
|
1898
|
+
next.splice(toIndex, 0, item);
|
|
1899
|
+
return next;
|
|
1900
|
+
}
|
|
1901
|
+
function DraggableList(props) {
|
|
1902
|
+
const { list, onListChange, idKey, itemRender, className, style, draggableHandle, rowHeight, margin = [0, 0], onDragStart, onDragStop, ...restProps } = props;
|
|
1903
|
+
const [displayList, setDisplayList] = useState(list);
|
|
1904
|
+
const displayListRef = useRef(list);
|
|
1905
|
+
const [draggingId, setDraggingId] = useState(null);
|
|
1906
|
+
const [dragOverId, setDragOverId] = useState(null);
|
|
1907
|
+
const [ghostElement, setGhostElement] = useState(null);
|
|
1908
|
+
const [ghostPosition, setGhostPosition] = useState(null);
|
|
1909
|
+
const [canUsePortal, setCanUsePortal] = useState(false);
|
|
1910
|
+
const pointerIdRef = useRef(null);
|
|
1911
|
+
const dragPointerOffsetRef = useRef({
|
|
1912
|
+
x: 0,
|
|
1913
|
+
y: 0
|
|
1914
|
+
});
|
|
1915
|
+
const dragItemSizeRef = useRef({
|
|
1916
|
+
width: 0,
|
|
1917
|
+
height: 0
|
|
1918
|
+
});
|
|
1919
|
+
const ghostContainerRef = useRef(null);
|
|
1920
|
+
const pressedHandleIdRef = useRef(null);
|
|
1921
|
+
const dragSourceIdRef = useRef(null);
|
|
1922
|
+
const dragStartIndexRef = useRef(-1);
|
|
1923
|
+
useEffect(() => {
|
|
1924
|
+
if (!draggingId) {
|
|
1925
|
+
setDisplayList(list);
|
|
1926
|
+
displayListRef.current = list;
|
|
1927
|
+
}
|
|
1928
|
+
}, [draggingId, list]);
|
|
1929
|
+
useEffect(() => {
|
|
1930
|
+
setCanUsePortal(typeof document !== "undefined");
|
|
1931
|
+
}, []);
|
|
1932
|
+
useEffect(() => {
|
|
1933
|
+
const container = ghostContainerRef.current;
|
|
1934
|
+
if (!container) return;
|
|
1935
|
+
container.replaceChildren();
|
|
1936
|
+
if (ghostElement) container.appendChild(ghostElement);
|
|
1937
|
+
}, [ghostElement]);
|
|
1938
|
+
useEffect(() => {
|
|
1939
|
+
if (!draggingId) return;
|
|
1940
|
+
const handlePointerMove = (evt) => {
|
|
1941
|
+
const sourceId = dragSourceIdRef.current;
|
|
1942
|
+
if (!sourceId || pointerIdRef.current !== evt.pointerId) return;
|
|
1943
|
+
setGhostPosition({
|
|
1944
|
+
x: evt.clientX - dragPointerOffsetRef.current.x,
|
|
1945
|
+
y: evt.clientY - dragPointerOffsetRef.current.y
|
|
1946
|
+
});
|
|
1947
|
+
const element = document.elementFromPoint(evt.clientX, evt.clientY);
|
|
1948
|
+
const itemElement = element === null || element === void 0 ? void 0 : element.closest("[data-draggable-list-item-id]");
|
|
1949
|
+
const targetId = itemElement === null || itemElement === void 0 ? void 0 : itemElement.dataset.draggableListItemId;
|
|
1950
|
+
if (!targetId || targetId === sourceId) return;
|
|
1951
|
+
setDragOverId(targetId);
|
|
1952
|
+
setDisplayList((prev) => {
|
|
1953
|
+
const fromIndex = prev.findIndex((it) => getItemId(it) === sourceId);
|
|
1954
|
+
const toIndex = prev.findIndex((it) => getItemId(it) === targetId);
|
|
1955
|
+
if (fromIndex < 0 || toIndex < 0 || fromIndex === toIndex) return prev;
|
|
1956
|
+
const next = moveItemByIndex(prev, fromIndex, toIndex);
|
|
1957
|
+
displayListRef.current = next;
|
|
1958
|
+
return next;
|
|
1959
|
+
});
|
|
1960
|
+
};
|
|
1961
|
+
const handlePointerUp = (evt) => {
|
|
1962
|
+
if (pointerIdRef.current !== evt.pointerId) return;
|
|
1963
|
+
const sourceId = dragSourceIdRef.current;
|
|
1964
|
+
const startIndex = dragStartIndexRef.current;
|
|
1965
|
+
const currentList = displayListRef.current;
|
|
1966
|
+
if (sourceId) {
|
|
1967
|
+
const finalIndex = currentList.findIndex((it) => getItemId(it) === sourceId);
|
|
1968
|
+
onDragStop === null || onDragStop === void 0 || onDragStop(void 0, { y: startIndex }, { y: finalIndex });
|
|
1969
|
+
if (startIndex >= 0) onListChange([...currentList]);
|
|
1970
|
+
}
|
|
1971
|
+
pointerIdRef.current = null;
|
|
1972
|
+
pressedHandleIdRef.current = null;
|
|
1973
|
+
dragSourceIdRef.current = null;
|
|
1974
|
+
dragStartIndexRef.current = -1;
|
|
1975
|
+
setDragOverId(null);
|
|
1976
|
+
setGhostElement(null);
|
|
1977
|
+
setGhostPosition(null);
|
|
1978
|
+
setDraggingId(null);
|
|
1979
|
+
};
|
|
1980
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
1981
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
1982
|
+
window.addEventListener("pointercancel", handlePointerUp);
|
|
1983
|
+
return () => {
|
|
1984
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
1985
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
1986
|
+
window.removeEventListener("pointercancel", handlePointerUp);
|
|
1987
|
+
};
|
|
1988
|
+
}, [
|
|
1989
|
+
draggingId,
|
|
1990
|
+
onDragStop,
|
|
1991
|
+
onListChange
|
|
1992
|
+
]);
|
|
1993
|
+
const gapStyle = useMemo(() => {
|
|
1994
|
+
const [horizontal, vertical] = margin;
|
|
1995
|
+
return {
|
|
1996
|
+
rowGap: `${vertical}px`,
|
|
1997
|
+
paddingLeft: horizontal ? `${horizontal}px` : void 0,
|
|
1998
|
+
paddingRight: horizontal ? `${horizontal}px` : void 0,
|
|
1999
|
+
...style
|
|
2000
|
+
};
|
|
2001
|
+
}, [margin, style]);
|
|
2002
|
+
const getItemId = (item) => String(item[idKey]);
|
|
2003
|
+
const draggingItem = draggingId ? displayList.find((item) => getItemId(item) === draggingId) : null;
|
|
2004
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
2005
|
+
...restProps,
|
|
2006
|
+
className: clsx("univer-flex univer-flex-col", draggingId && "univer-cursor-grabbing univer-select-none", className),
|
|
2007
|
+
style: gapStyle,
|
|
2008
|
+
children: displayList.map((item, index) => {
|
|
2009
|
+
const itemId = getItemId(item);
|
|
2010
|
+
const isDraggingItem = draggingId === itemId;
|
|
2011
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2012
|
+
"data-draggable-list-item-id": itemId,
|
|
2013
|
+
className: clsx("univer-relative univer-transition-all univer-duration-150", isDraggingItem && "univer-opacity-0", dragOverId === itemId && !isDraggingItem && `
|
|
52
2014
|
univer-bg-primary-50/60
|
|
53
2015
|
dark:!univer-bg-primary-900/20
|
|
54
2016
|
univer-rounded univer-border univer-border-primary-200
|
|
55
2017
|
dark:!univer-border-primary-700
|
|
56
|
-
`),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
2018
|
+
`),
|
|
2019
|
+
onPointerDownCapture: (e) => {
|
|
2020
|
+
if (pointerIdRef.current !== null) return;
|
|
2021
|
+
if (!draggableHandle) pressedHandleIdRef.current = itemId;
|
|
2022
|
+
else pressedHandleIdRef.current = !!e.target.closest(draggableHandle) ? itemId : null;
|
|
2023
|
+
if (pressedHandleIdRef.current !== itemId) return;
|
|
2024
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2025
|
+
dragPointerOffsetRef.current = {
|
|
2026
|
+
x: e.clientX - rect.left,
|
|
2027
|
+
y: e.clientY - rect.top
|
|
2028
|
+
};
|
|
2029
|
+
dragItemSizeRef.current = {
|
|
2030
|
+
width: rect.width,
|
|
2031
|
+
height: rect.height
|
|
2032
|
+
};
|
|
2033
|
+
setGhostPosition({
|
|
2034
|
+
x: rect.left,
|
|
2035
|
+
y: rect.top
|
|
2036
|
+
});
|
|
2037
|
+
setGhostElement(e.currentTarget.cloneNode(true));
|
|
2038
|
+
pointerIdRef.current = e.pointerId;
|
|
2039
|
+
dragSourceIdRef.current = itemId;
|
|
2040
|
+
dragStartIndexRef.current = index;
|
|
2041
|
+
setDraggingId(itemId);
|
|
2042
|
+
displayListRef.current = displayList;
|
|
2043
|
+
onDragStart === null || onDragStart === void 0 || onDragStart(void 0, { y: index });
|
|
2044
|
+
e.preventDefault();
|
|
2045
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
2046
|
+
},
|
|
2047
|
+
style: {
|
|
2048
|
+
...rowHeight ? { minHeight: `${rowHeight}px` } : void 0,
|
|
2049
|
+
cursor: draggingId ? "grabbing" : void 0
|
|
2050
|
+
},
|
|
2051
|
+
children: [isDraggingItem && /* @__PURE__ */ jsx("div", { className: "\n univer-bg-primary-50/50 univer-absolute univer-inset-0 univer-rounded\n univer-border univer-border-dashed univer-border-primary-300\n " }), itemRender(item, index)]
|
|
2052
|
+
}, itemId);
|
|
2053
|
+
})
|
|
2054
|
+
}), canUsePortal && draggingItem && ghostPosition && createPortal(/* @__PURE__ */ jsx("div", {
|
|
2055
|
+
className: clsx("univer-pointer-events-none univer-fixed univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-800"),
|
|
2056
|
+
style: {
|
|
2057
|
+
zIndex: 2147483647,
|
|
2058
|
+
left: `${ghostPosition.x}px`,
|
|
2059
|
+
top: `${ghostPosition.y}px`,
|
|
2060
|
+
width: `${dragItemSizeRef.current.width}px`,
|
|
2061
|
+
height: `${dragItemSizeRef.current.height}px`,
|
|
2062
|
+
opacity: .95
|
|
2063
|
+
},
|
|
2064
|
+
children: ghostElement ? /* @__PURE__ */ jsx("div", { ref: ghostContainerRef }) : itemRender(draggingItem, displayList.findIndex((item) => getItemId(item) === getItemId(draggingItem)))
|
|
2065
|
+
}), document.body)] });
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
//#endregion
|
|
2069
|
+
//#region src/components/dropdown-menu/DropdownMenuPrimitive.tsx
|
|
2070
|
+
function DropdownMenuPrimitive({ ...props }) {
|
|
2071
|
+
return /* @__PURE__ */ jsx(Root$2, {
|
|
2072
|
+
"data-slot": "dropdown-menu",
|
|
2073
|
+
...props
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
function DropdownMenuPortal({ ...props }) {
|
|
2077
|
+
return /* @__PURE__ */ jsx(Portal$2, {
|
|
2078
|
+
"data-slot": "dropdown-menu-portal",
|
|
2079
|
+
...props
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
function DropdownMenuTrigger({ ...props }) {
|
|
2083
|
+
return /* @__PURE__ */ jsx(Trigger$1, {
|
|
2084
|
+
"data-slot": "dropdown-menu-trigger",
|
|
2085
|
+
...props
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
function DropdownMenuSub({ ...props }) {
|
|
2089
|
+
return /* @__PURE__ */ jsx(Sub, {
|
|
2090
|
+
"data-slot": "dropdown-menu-sub",
|
|
2091
|
+
...props
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
function DropdownMenuRadioGroup({ ...props }) {
|
|
2095
|
+
return /* @__PURE__ */ jsx(RadioGroup$1, {
|
|
2096
|
+
"data-slot": "dropdown-menu-radio-group",
|
|
2097
|
+
...props
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
|
|
2101
|
+
return /* @__PURE__ */ jsxs(SubTrigger, {
|
|
2102
|
+
"data-slot": "dropdown-menu-sub-trigger",
|
|
2103
|
+
"data-inset": inset,
|
|
2104
|
+
className: clsx("univer-flex univer-cursor-default univer-select-none univer-items-center univer-justify-between univer-gap-2 univer-rounded univer-px-2 univer-py-1.5 univer-text-sm univer-outline-none data-[state=open]:univer-bg-gray-100 focus:univer-bg-gray-100 dark:data-[state=open]:!univer-bg-gray-600 dark:focus:!univer-bg-gray-600 [&_svg]:univer-pointer-events-none [&_svg]:univer-size-4 [&_svg]:univer-shrink-0", className),
|
|
2105
|
+
...props,
|
|
2106
|
+
children: [children, /* @__PURE__ */ jsx(MoreRightIcon, { className: "ml-auto" })]
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
function DropdownMenuSubContent({ className, ...props }) {
|
|
2110
|
+
return /* @__PURE__ */ jsx(SubContent, {
|
|
2111
|
+
"data-slot": "dropdown-menu-sub-content",
|
|
2112
|
+
className: clsx("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-box-border univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-p-1.5 univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName, scrollbarClassName, className),
|
|
2113
|
+
...props
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
|
|
2117
|
+
return /* @__PURE__ */ jsx(Portal$2, { children: /* @__PURE__ */ jsx(Content$2, {
|
|
2118
|
+
"data-slot": "dropdown-menu-content",
|
|
2119
|
+
sideOffset,
|
|
2120
|
+
className: clsx("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-box-border univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-p-1.5 univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName, scrollbarClassName, className),
|
|
2121
|
+
...props
|
|
2122
|
+
}) });
|
|
2123
|
+
}
|
|
2124
|
+
function DropdownMenuItem({ className, inset, variant = "default", ...props }) {
|
|
2125
|
+
return /* @__PURE__ */ jsx(Item, {
|
|
2126
|
+
"data-slot": "dropdown-menu-item",
|
|
2127
|
+
"data-inset": inset,
|
|
2128
|
+
"data-variant": variant,
|
|
2129
|
+
className: clsx("univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-gap-2 univer-rounded univer-px-2 univer-py-1.5 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600 [&>svg]:univer-size-4 [&>svg]:univer-shrink-0", className),
|
|
2130
|
+
...props
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
function DropdownMenuCheckboxItem({ className, children, hideIndicator, checked, ...props }) {
|
|
2134
|
+
return /* @__PURE__ */ jsxs(CheckboxItem, {
|
|
2135
|
+
"data-slot": "dropdown-menu-checkbox-item",
|
|
2136
|
+
className: clsx("univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-rounded univer-py-1.5 univer-pr-2 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600", {
|
|
2137
|
+
"univer-pl-8": !hideIndicator,
|
|
2138
|
+
"univer-pl-2": hideIndicator
|
|
2139
|
+
}, className),
|
|
2140
|
+
checked,
|
|
2141
|
+
...props,
|
|
2142
|
+
children: [!hideIndicator && /* @__PURE__ */ jsx("span", {
|
|
2143
|
+
className: "univer-absolute univer-left-2 univer-flex univer-size-3.5 univer-items-center univer-justify-center",
|
|
2144
|
+
children: /* @__PURE__ */ jsx(ItemIndicator, { children: /* @__PURE__ */ jsx(CheckMarkIcon, { className: "univer-block univer-size-4 univer-fill-current univer-text-primary-600" }) })
|
|
2145
|
+
}), children]
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
function DropdownMenuRadioItem({ className, children, hideIndicator, ...props }) {
|
|
2149
|
+
return /* @__PURE__ */ jsxs(RadioItem, {
|
|
2150
|
+
"data-slot": "dropdown-menu-radio-item",
|
|
2151
|
+
className: clsx("univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-rounded univer-py-1.5 univer-pr-2 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600", {
|
|
2152
|
+
"univer-pl-8": !hideIndicator,
|
|
2153
|
+
"univer-pl-2": hideIndicator
|
|
2154
|
+
}, className),
|
|
2155
|
+
...props,
|
|
2156
|
+
children: [!hideIndicator && /* @__PURE__ */ jsx("span", {
|
|
2157
|
+
className: "univer-absolute univer-left-2 univer-flex univer-size-3.5 univer-items-center univer-justify-center",
|
|
2158
|
+
children: /* @__PURE__ */ jsx(ItemIndicator, { children: /* @__PURE__ */ jsx(CheckMarkIcon, { className: "univer-block univer-size-4 univer-fill-current univer-text-primary-600" }) })
|
|
2159
|
+
}), children]
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
function DropdownMenuSeparator({ className, ...props }) {
|
|
2163
|
+
return /* @__PURE__ */ jsx(Separator$1, {
|
|
2164
|
+
className: clsx("-univer-mx-1 univer-my-1 univer-h-px univer-bg-gray-200 dark:!univer-bg-gray-600", className),
|
|
2165
|
+
...props
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
//#endregion
|
|
2170
|
+
//#region src/components/dropdown-menu/DropdownMenu.tsx
|
|
2171
|
+
function DropdownMenu(props) {
|
|
2172
|
+
const { children, items, disabled, open: controlledOpen, onOpenChange: controlledOnOpenChange, ...restProps } = props;
|
|
2173
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
2174
|
+
const isControlled = controlledOpen !== void 0;
|
|
2175
|
+
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
2176
|
+
function handleChangeOpen(newOpen) {
|
|
2177
|
+
if (disabled) return;
|
|
2178
|
+
if (!isControlled) setUncontrolledOpen(newOpen);
|
|
2179
|
+
controlledOnOpenChange === null || controlledOnOpenChange === void 0 || controlledOnOpenChange(newOpen);
|
|
2180
|
+
}
|
|
2181
|
+
function renderMenuItem(item, index) {
|
|
2182
|
+
const { className, type } = item;
|
|
2183
|
+
if (type === "separator") return /* @__PURE__ */ jsx(DropdownMenuSeparator, { className }, index);
|
|
2184
|
+
else if (type === "radio") return /* @__PURE__ */ jsx(DropdownMenuRadioGroup, {
|
|
2185
|
+
className,
|
|
2186
|
+
value: item.value,
|
|
2187
|
+
onValueChange: item.onSelect,
|
|
2188
|
+
children: item.options.map((option, index) => {
|
|
2189
|
+
if ("type" in option) {
|
|
2190
|
+
if (option.type === "separator") return /* @__PURE__ */ jsx(DropdownMenuSeparator, { className: option.className }, index);
|
|
2191
|
+
} else {
|
|
2192
|
+
if (option.value === void 0) throw new Error("[DropdownMenu]: `value` is required");
|
|
2193
|
+
return /* @__PURE__ */ jsx(DropdownMenuRadioItem, {
|
|
2194
|
+
value: option.value,
|
|
2195
|
+
disabled: option.disabled,
|
|
2196
|
+
hideIndicator: item.hideIndicator,
|
|
2197
|
+
children: option.label
|
|
2198
|
+
}, option.value);
|
|
2199
|
+
}
|
|
2200
|
+
return null;
|
|
2201
|
+
})
|
|
2202
|
+
}, index);
|
|
2203
|
+
else if (type === "checkbox") return /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
|
|
2204
|
+
className,
|
|
2205
|
+
disabled: item.disabled,
|
|
2206
|
+
checked: item.checked,
|
|
2207
|
+
onSelect: () => {
|
|
2208
|
+
var _item$onSelect;
|
|
2209
|
+
(_item$onSelect = item.onSelect) === null || _item$onSelect === void 0 || _item$onSelect.call(item, item.value);
|
|
2210
|
+
},
|
|
2211
|
+
children: item.label
|
|
2212
|
+
}, index);
|
|
2213
|
+
else if (type === "item") return /* @__PURE__ */ jsx(DropdownMenuItem, {
|
|
2214
|
+
className,
|
|
2215
|
+
disabled: item.disabled,
|
|
2216
|
+
onSelect: () => {
|
|
2217
|
+
var _item$onSelect2;
|
|
2218
|
+
(_item$onSelect2 = item.onSelect) === null || _item$onSelect2 === void 0 || _item$onSelect2.call(item, item);
|
|
2219
|
+
},
|
|
2220
|
+
children: item.children
|
|
2221
|
+
}, index);
|
|
2222
|
+
else if (type === "subItem") {
|
|
2223
|
+
var _item$options;
|
|
2224
|
+
return /* @__PURE__ */ jsxs(DropdownMenuSub, { children: [/* @__PURE__ */ jsx(DropdownMenuSubTrigger, { children: item.children }), /* @__PURE__ */ jsx(DropdownMenuPortal, { children: /* @__PURE__ */ jsx(DropdownMenuSubContent, {
|
|
2225
|
+
sideOffset: 12,
|
|
2226
|
+
children: (_item$options = item.options) === null || _item$options === void 0 ? void 0 : _item$options.map((subItem, subIndex) => renderMenuItem(subItem, subIndex))
|
|
2227
|
+
}) })] }, index);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
return /* @__PURE__ */ jsxs(DropdownMenuPrimitive, {
|
|
2231
|
+
modal: false,
|
|
2232
|
+
open,
|
|
2233
|
+
onOpenChange: handleChangeOpen,
|
|
2234
|
+
children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
|
|
2235
|
+
asChild: true,
|
|
2236
|
+
children
|
|
2237
|
+
}), /* @__PURE__ */ jsx(DropdownMenuContent, {
|
|
2238
|
+
className: "univer-text-sm",
|
|
2239
|
+
collisionPadding: {
|
|
2240
|
+
top: 12,
|
|
2241
|
+
bottom: 12
|
|
2242
|
+
},
|
|
2243
|
+
onWheel: (e) => e.stopPropagation(),
|
|
2244
|
+
...restProps,
|
|
2245
|
+
children: items.map((item, index) => renderMenuItem(item, index))
|
|
2246
|
+
})]
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
//#endregion
|
|
2251
|
+
//#region src/components/form-layout/FormLayout.tsx
|
|
2252
|
+
const FormLayoutContext = createContext(false);
|
|
2253
|
+
const FormLayout = (props) => {
|
|
2254
|
+
const { label, desc, children, style, className, error, contentStyle, collapsable = false, defaultCollapsed = false } = props;
|
|
2255
|
+
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
|
2256
|
+
return /* @__PURE__ */ jsx(FormLayoutContext.Provider, {
|
|
2257
|
+
value: true,
|
|
2258
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2259
|
+
"data-u-comp": "form-layout",
|
|
2260
|
+
className: clsx("univer-mb-3 univer-flex univer-flex-col", className),
|
|
2261
|
+
style,
|
|
2262
|
+
children: [label && /* @__PURE__ */ jsxs("div", {
|
|
2263
|
+
className: clsx("univer-mb-2 univer-flex univer-min-h-3.5 univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white", { "univer-cursor-pointer": collapsable }),
|
|
2264
|
+
onClick: () => setCollapsed(!collapsed),
|
|
2265
|
+
children: [label, collapsable && /* @__PURE__ */ jsx(MoreUpIcon, { className: clsx("univer-ml-1 univer-transition-transform", { "univer-rotate-180": collapsed }) })]
|
|
2266
|
+
}), collapsed && collapsable ? null : /* @__PURE__ */ jsxs(Fragment, { children: [desc && /* @__PURE__ */ jsx("div", {
|
|
2267
|
+
className: "univer-mt-1 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2268
|
+
children: desc
|
|
2269
|
+
}), children ? /* @__PURE__ */ jsxs("div", {
|
|
2270
|
+
className: clsx("last:univer-mb-0 [&_[data-u-comp=input]]:univer-w-full [&_[data-u-comp=select]]:univer-w-full", {
|
|
2271
|
+
"[&_[data-u-comp=input]]:univer-border-red-500": error,
|
|
2272
|
+
"[&_[data-u-comp=select]]:univer-border-red-500": error
|
|
2273
|
+
}),
|
|
2274
|
+
style: contentStyle,
|
|
2275
|
+
children: [children, error ? /* @__PURE__ */ jsx("div", {
|
|
2276
|
+
className: "univer-mt-1 univer-text-xs univer-text-red-500",
|
|
2277
|
+
children: error
|
|
2278
|
+
}) : null]
|
|
2279
|
+
}) : null] })]
|
|
2280
|
+
})
|
|
2281
|
+
});
|
|
2282
|
+
};
|
|
2283
|
+
/**
|
|
2284
|
+
* A dual columns layout component for the form.
|
|
2285
|
+
* @param props props of the component
|
|
2286
|
+
*/
|
|
2287
|
+
const FormDualColumnLayout = (props) => {
|
|
2288
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2289
|
+
className: "univer-flex univer-justify-between [&_[data-u-comp=form-layout]]:univer-max-w-[calc(50%-8px)] [&_[data-u-comp=form-layout]]:univer-shrink [&_[data-u-comp=form-layout]]:univer-grow",
|
|
2290
|
+
children: props.children
|
|
2291
|
+
});
|
|
2292
|
+
};
|
|
2293
|
+
|
|
2294
|
+
//#endregion
|
|
2295
|
+
//#region src/components/pager/Pager.tsx
|
|
2296
|
+
/**
|
|
2297
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2298
|
+
*
|
|
2299
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2300
|
+
* you may not use this file except in compliance with the License.
|
|
2301
|
+
* You may obtain a copy of the License at
|
|
2302
|
+
*
|
|
2303
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2304
|
+
*
|
|
2305
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2306
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2307
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2308
|
+
* See the License for the specific language governing permissions and
|
|
2309
|
+
* limitations under the License.
|
|
2310
|
+
*/
|
|
2311
|
+
function Pager(props) {
|
|
2312
|
+
const { className, value: current = 0, total: count = 0, loop, text: propText, onChange } = props;
|
|
2313
|
+
const text = useMemo(() => propText !== null && propText !== void 0 ? propText : `${current}/${count}`, [
|
|
2314
|
+
current,
|
|
2315
|
+
count,
|
|
2316
|
+
propText
|
|
2317
|
+
]);
|
|
2318
|
+
const hasValue = count > 0;
|
|
2319
|
+
const onClickLeftArrow = () => {
|
|
2320
|
+
if (current === 1) {
|
|
2321
|
+
if (loop) onChange === null || onChange === void 0 || onChange(count);
|
|
2322
|
+
} else onChange === null || onChange === void 0 || onChange(current - 1);
|
|
2323
|
+
};
|
|
2324
|
+
const onClickRightArrow = () => {
|
|
2325
|
+
if (current === count) {
|
|
2326
|
+
if (loop) onChange === null || onChange === void 0 || onChange(1);
|
|
2327
|
+
} else onChange === null || onChange === void 0 || onChange(current + 1);
|
|
2328
|
+
};
|
|
2329
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2330
|
+
"data-u-comp": "pager",
|
|
2331
|
+
className: clsx("univer-flex univer-flex-shrink-0 univer-items-center univer-text-sm univer-text-gray-700 dark:!univer-text-gray-400", className),
|
|
2332
|
+
children: hasValue ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2333
|
+
/* @__PURE__ */ jsx("button", {
|
|
2334
|
+
"data-u-comp": "pager-left-arrow",
|
|
2335
|
+
className: "univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded univer-border-none univer-bg-transparent univer-p-0 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600",
|
|
2336
|
+
type: "button",
|
|
2337
|
+
role: "button",
|
|
2338
|
+
onClick: onClickLeftArrow,
|
|
2339
|
+
children: /* @__PURE__ */ jsx(MoreLeftIcon, {})
|
|
2340
|
+
}),
|
|
2341
|
+
/* @__PURE__ */ jsx("span", {
|
|
2342
|
+
className: "univer-mx-1",
|
|
2343
|
+
children: text
|
|
2344
|
+
}),
|
|
2345
|
+
/* @__PURE__ */ jsx("button", {
|
|
2346
|
+
"data-u-comp": "pager-right-arrow",
|
|
2347
|
+
className: "univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded univer-border-none univer-bg-transparent univer-p-0 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600",
|
|
2348
|
+
type: "button",
|
|
2349
|
+
role: "button",
|
|
2350
|
+
onClick: onClickRightArrow,
|
|
2351
|
+
children: /* @__PURE__ */ jsx(MoreRightIcon, {})
|
|
2352
|
+
})
|
|
2353
|
+
] }) : /* @__PURE__ */ jsx("div", {
|
|
2354
|
+
className: "univer-mx-1",
|
|
2355
|
+
children: text
|
|
2356
|
+
})
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
//#endregion
|
|
2361
|
+
//#region src/components/gallery/Gallery.tsx
|
|
2362
|
+
/**
|
|
2363
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2364
|
+
*
|
|
2365
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2366
|
+
* you may not use this file except in compliance with the License.
|
|
2367
|
+
* You may obtain a copy of the License at
|
|
2368
|
+
*
|
|
2369
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2370
|
+
*
|
|
2371
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2372
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2373
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2374
|
+
* See the License for the specific language governing permissions and
|
|
2375
|
+
* limitations under the License.
|
|
2376
|
+
*/
|
|
2377
|
+
const buttonClassName = `
|
|
60
2378
|
univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-border-none
|
|
61
2379
|
univer-bg-transparent univer-p-0 univer-text-current
|
|
62
2380
|
hover:univer-text-white
|
|
63
|
-
`;
|
|
2381
|
+
`;
|
|
2382
|
+
function Gallery(props) {
|
|
2383
|
+
const { className, images, open, onOpenChange } = props;
|
|
2384
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
2385
|
+
const [activeImageIndex, setActiveImageIndex] = useState(0);
|
|
2386
|
+
const [zoomLevel, setZoomLevel] = useState(1);
|
|
2387
|
+
const dialogRef = useRef(null);
|
|
2388
|
+
const activeImage = useMemo(() => images[activeImageIndex], [activeImageIndex, images]);
|
|
2389
|
+
useEffect(() => {
|
|
2390
|
+
if (open && dialogRef.current) dialogRef.current.focus();
|
|
2391
|
+
}, [open]);
|
|
2392
|
+
useEffect(() => {
|
|
2393
|
+
if (!open) return;
|
|
2394
|
+
const handler = (e) => {
|
|
2395
|
+
if (e.key === "Escape") onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
|
|
2396
|
+
};
|
|
2397
|
+
window.addEventListener("keydown", handler);
|
|
2398
|
+
return () => window.removeEventListener("keydown", handler);
|
|
2399
|
+
}, [open, onOpenChange]);
|
|
2400
|
+
useEffect(() => {
|
|
2401
|
+
if (open) setIsVisible(true);
|
|
2402
|
+
else {
|
|
2403
|
+
const timer = setTimeout(() => {
|
|
2404
|
+
setIsVisible(false);
|
|
2405
|
+
}, 150);
|
|
2406
|
+
return () => clearTimeout(timer);
|
|
2407
|
+
}
|
|
2408
|
+
}, [open]);
|
|
2409
|
+
useEffect(() => {
|
|
2410
|
+
if (!open) return;
|
|
2411
|
+
const handleWheel = (e) => {
|
|
2412
|
+
e.preventDefault();
|
|
2413
|
+
const step = -e.deltaY * .001;
|
|
2414
|
+
setZoomLevel((prev) => Math.min(Math.max(.5, prev + step), 2));
|
|
2415
|
+
};
|
|
2416
|
+
window.addEventListener("wheel", handleWheel, { passive: false });
|
|
2417
|
+
return () => {
|
|
2418
|
+
window.removeEventListener("wheel", handleWheel);
|
|
2419
|
+
};
|
|
2420
|
+
}, [open]);
|
|
2421
|
+
if (!open && !isVisible) return null;
|
|
2422
|
+
function handleToggleZoom(ratio) {
|
|
2423
|
+
if (ratio === "reset") {
|
|
2424
|
+
setZoomLevel(1);
|
|
2425
|
+
return;
|
|
2426
|
+
}
|
|
2427
|
+
const newZoomLevel = zoomLevel + ratio;
|
|
2428
|
+
if (newZoomLevel < .5) return;
|
|
2429
|
+
if (newZoomLevel > 2) return;
|
|
2430
|
+
setZoomLevel(newZoomLevel);
|
|
2431
|
+
}
|
|
2432
|
+
return createPortal(/* @__PURE__ */ jsxs("div", {
|
|
2433
|
+
"data-u-comp": "gallery",
|
|
2434
|
+
role: "dialog",
|
|
2435
|
+
"aria-modal": "true",
|
|
2436
|
+
"aria-label": "Image gallery",
|
|
2437
|
+
tabIndex: -1,
|
|
2438
|
+
ref: dialogRef,
|
|
2439
|
+
className: clsx("univer-absolute univer-inset-0 univer-z-[1080] univer-flex univer-size-full univer-select-none univer-items-center univer-justify-center", {
|
|
2440
|
+
"univer-animate-in univer-fade-in": open,
|
|
2441
|
+
"univer-animate-out univer-fade-out": !open
|
|
2442
|
+
}, className),
|
|
2443
|
+
children: [
|
|
2444
|
+
/* @__PURE__ */ jsx("div", {
|
|
2445
|
+
className: "univer-absolute univer-inset-0 univer-size-full univer-bg-gray-900 univer-opacity-80",
|
|
2446
|
+
"aria-hidden": "true",
|
|
2447
|
+
onClick: () => onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false)
|
|
2448
|
+
}),
|
|
2449
|
+
/* @__PURE__ */ jsx("div", {
|
|
2450
|
+
className: "univer-relative",
|
|
2451
|
+
children: activeImage && /* @__PURE__ */ jsx("img", {
|
|
2452
|
+
className: "univer-max-h-[40vh] univer-max-w-[60vw] univer-transition-transform univer-duration-300 univer-ease-out",
|
|
2453
|
+
style: { transform: `scale(${zoomLevel})` },
|
|
2454
|
+
src: activeImage,
|
|
2455
|
+
alt: `Image ${activeImageIndex + 1} of ${images.length}`,
|
|
2456
|
+
draggable: false
|
|
2457
|
+
})
|
|
2458
|
+
}),
|
|
2459
|
+
/* @__PURE__ */ jsxs("footer", {
|
|
2460
|
+
className: "univer-absolute univer-bottom-6 univer-left-1/2 univer-flex -univer-translate-x-1/2 univer-items-center univer-gap-3 univer-rounded-full univer-bg-gray-800 univer-px-6 univer-py-3 univer-text-gray-400",
|
|
2461
|
+
children: [
|
|
2462
|
+
/* @__PURE__ */ jsx(Pager, {
|
|
2463
|
+
className: "!univer-text-gray-400 [&_[data-u-comp=pager-left-arrow]:hover]:!univer-bg-gray-600 [&_[data-u-comp=pager-right-arrow]:hover]:!univer-bg-gray-600",
|
|
2464
|
+
value: activeImageIndex + 1,
|
|
2465
|
+
total: images.length,
|
|
2466
|
+
onChange: (value) => setActiveImageIndex(value - 1)
|
|
2467
|
+
}),
|
|
2468
|
+
/* @__PURE__ */ jsx("button", {
|
|
2469
|
+
type: "button",
|
|
2470
|
+
"aria-label": "Zoom in",
|
|
2471
|
+
className: buttonClassName,
|
|
2472
|
+
onClick: () => handleToggleZoom(.25),
|
|
2473
|
+
children: /* @__PURE__ */ jsx(ZoomInIcon, { "aria-hidden": "true" })
|
|
2474
|
+
}),
|
|
2475
|
+
/* @__PURE__ */ jsx("button", {
|
|
2476
|
+
type: "button",
|
|
2477
|
+
"aria-label": "Zoom out",
|
|
2478
|
+
className: buttonClassName,
|
|
2479
|
+
onClick: () => handleToggleZoom(-.25),
|
|
2480
|
+
children: /* @__PURE__ */ jsx(ZoomOutIcon, { "aria-hidden": "true" })
|
|
2481
|
+
}),
|
|
2482
|
+
/* @__PURE__ */ jsx("button", {
|
|
2483
|
+
type: "button",
|
|
2484
|
+
"aria-label": "Reset zoom",
|
|
2485
|
+
className: buttonClassName,
|
|
2486
|
+
onClick: () => handleToggleZoom("reset"),
|
|
2487
|
+
children: /* @__PURE__ */ jsx(OneToOneIcon, { "aria-hidden": "true" })
|
|
2488
|
+
})
|
|
2489
|
+
]
|
|
2490
|
+
})
|
|
2491
|
+
]
|
|
2492
|
+
}), document.body);
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
//#endregion
|
|
2496
|
+
//#region src/components/input/Input.tsx
|
|
2497
|
+
const inputVariants = cva(`
|
|
64
2498
|
univer-box-border univer-w-full univer-rounded-md univer-bg-white univer-transition-colors univer-duration-200
|
|
65
2499
|
placeholder:univer-text-gray-400
|
|
66
2500
|
focus:univer-border-primary-600 focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-50
|
|
67
2501
|
dark:!univer-bg-gray-700 dark:!univer-text-white
|
|
68
2502
|
dark:focus:!univer-ring-primary-900
|
|
69
|
-
`,
|
|
2503
|
+
`, {
|
|
2504
|
+
variants: { size: {
|
|
2505
|
+
mini: "univer-h-7 univer-px-1.5 univer-text-sm",
|
|
2506
|
+
small: "univer-h-8 univer-px-2 univer-text-sm",
|
|
2507
|
+
middle: "univer-h-10 univer-px-3 univer-text-base",
|
|
2508
|
+
large: "univer-h-12 univer-px-4 univer-text-lg"
|
|
2509
|
+
} },
|
|
2510
|
+
defaultVariants: { size: "small" }
|
|
2511
|
+
});
|
|
2512
|
+
const Input = forwardRef(({ autoFocus = false, className, style, type = "text", placeholder, value, size = "small", allowClear = false, disabled = false, onClick, onKeyDown, onChange, onFocus, onBlur, slot, inputClass, inputStyle, ...props }, ref) => {
|
|
2513
|
+
const handleClear = (e) => {
|
|
2514
|
+
e.stopPropagation();
|
|
2515
|
+
onChange === null || onChange === void 0 || onChange("");
|
|
2516
|
+
};
|
|
2517
|
+
const handleChange = (e) => {
|
|
2518
|
+
onChange === null || onChange === void 0 || onChange(e.target.value);
|
|
2519
|
+
};
|
|
2520
|
+
const hasSlotContent = useMemo(() => {
|
|
2521
|
+
return allowClear && value && !disabled || slot;
|
|
2522
|
+
}, [
|
|
2523
|
+
allowClear,
|
|
2524
|
+
disabled,
|
|
2525
|
+
slot,
|
|
2526
|
+
value
|
|
2527
|
+
]);
|
|
2528
|
+
const [paddingRight, setPaddingRight] = useState(0);
|
|
2529
|
+
const slotRef = useRef(null);
|
|
2530
|
+
useEffect(() => {
|
|
2531
|
+
let observer = null;
|
|
2532
|
+
if (slot && slotRef.current) {
|
|
2533
|
+
observer = new MutationObserver(() => {
|
|
2534
|
+
if (slotRef.current) setPaddingRight(slotRef.current.offsetWidth + 8);
|
|
2535
|
+
});
|
|
2536
|
+
observer.observe(slotRef.current, {
|
|
2537
|
+
childList: true,
|
|
2538
|
+
subtree: true
|
|
2539
|
+
});
|
|
2540
|
+
setPaddingRight(slotRef.current.offsetWidth + 8);
|
|
2541
|
+
}
|
|
2542
|
+
return () => observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
2543
|
+
}, [slotRef.current]);
|
|
2544
|
+
useEffect(() => {
|
|
2545
|
+
if (allowClear && !(slot && slotRef.current)) setPaddingRight(26);
|
|
2546
|
+
}, []);
|
|
2547
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2548
|
+
"data-u-comp": "input",
|
|
2549
|
+
className: clsx("univer-relative univer-inline-flex univer-w-full univer-items-center univer-rounded-md", disabled && "univer-cursor-not-allowed", className),
|
|
2550
|
+
style,
|
|
2551
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
2552
|
+
ref,
|
|
2553
|
+
type,
|
|
2554
|
+
className: clsx(inputVariants({ size }), borderClassName, disabled && `
|
|
70
2555
|
univer-cursor-not-allowed univer-bg-gray-50 univer-text-gray-400
|
|
71
2556
|
dark:!univer-text-gray-500
|
|
72
|
-
`,c&&!h&&`univer-pr-8`,g),placeholder:a,value:o,disabled:l,autoFocus:e,onClick:u,onKeyDown:d,onChange:x,onFocus:p,onBlur:m,style:{..._,paddingRight:C},...v}),S&&L(`div`,{className:`univer-absolute univer-right-2 univer-flex univer-items-center univer-gap-1 univer-rounded-full`,ref:T,children:[h,c&&o&&!l&&I(`button`,{type:`button`,onClick:b,className:`univer-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded-full univer-border-none univer-bg-transparent univer-p-1 univer-text-gray-400 univer-transition-colors univer-duration-200 hover:univer-text-gray-500 focus:univer-outline-none`,children:I(r,{className:`univer-size-3`})})]})]})}),dn=S(({value:e,defaultValue:t,size:n=`small`,min:r=-(2**53-1),max:i=2**53-1,step:a=1,precision:o,formatter:s,parser:c,controls:l=!0,className:u,inputClassName:d,controlsClassName:f,disabled:p,onChange:m,onKeyDown:h,onPressEnter:g,onFocus:_,onBlur:v,allowEmpty:y=!1},b)=>{let[x,S]=M(e===void 0?t===void 0?null:t:e),C=j(x),[w,T]=M(N(x)),E=j(null),O=j(null),k=j(null),A=e=>{b&&(typeof b==`function`?b(e):b.current=e),E.current=e};D(()=>{e!==void 0&&e!==x&&(S(e),C.current=e,T(N(e)))},[e]),D(()=>{x!==null&&(C.current=x)},[x]),D(()=>()=>{O.current&&clearTimeout(O.current),k.current&&clearInterval(k.current)},[]);function N(e){if(e==null)return``;let t=e;return o!==void 0&&(t=Number(e).toFixed(o)),s?s(t):String(t)}function P(e){if(!e)return null;let t=e;c&&(t=c(e));try{let e=t.replace(/[^\d.-]/g,``).split(`.`),n=e[0],a=e.length>1?e.slice(1).join(``):``,s=n+(a?`.${a}`:``),c=Number(s);if(Number.isNaN(c))return null;let l;if(o!==void 0){let e=10**o,t=Math.round(c*e)/e;l=t.toString().includes(`e`)?Number.parseFloat(t.toFixed(o)):t}else l=c.toString().includes(`e`)?Number.parseFloat(c.toFixed(16).replace(/\.?0+$/,``)):c;return i!==void 0&&l>i&&(l=i),r!==void 0&&l<r&&(l=r),l}catch{return null}}function F(e){if(T(e),y&&e===``){S(null),m==null||m(null);return}let t=P(e);S(t),m==null||m(t)}function R(e){if(x===null){if(w===``&&y)m&&m(null);else{let e=C.current;S(e),T(N(e)),m&&m(e)}v==null||v(e);return}let t=x;i!==void 0&&t>i&&(t=i),r!==void 0&&t<r&&(t=r),t===x?T(N(x)):(S(t),T(N(t)),m==null||m(t)),v==null||v(e)}function z(e){if(p)return;let t=e?a:-a,n;n=x===null?C.current===null?r>0?r:0:C.current:x;let o=n+t;i!==void 0&&o>i&&(o=i),r!==void 0&&o<r&&(o=r),o!==n&&(S(o),C.current=o,T(N(o)),m==null||m(o))}function ee(e){p||(h==null||h(e),e.key===`ArrowUp`?(e.preventDefault(),z(!0)):e.key===`ArrowDown`?(e.preventDefault(),z(!1)):e.key===`Enter`&&(g==null||g(e)))}function B(e){var t;p||(z(e),(t=E.current)==null||t.focus())}let V=p||i!==void 0&&x!==null&&x>=i,H=p||r!==void 0&&x!==null&&x<=r;return I(`div`,{className:W(`univer-inline-block`,u),children:L(`div`,{className:`univer-relative univer-w-full`,children:[I(un,{ref:A,className:W(`univer-box-border`,d),size:n,value:w,disabled:p,onChange:F,onFocus:_,onBlur:R,onKeyDown:ee}),l&&L(`div`,{className:W(`univer-absolute univer-right-px univer-top-px univer-flex univer-h-[calc(100%-2px)] univer-flex-col univer-overflow-hidden univer-rounded-r-md before:univer-absolute before:univer-top-1/2 before:univer-block before:univer-h-px before:univer-w-full before:-univer-translate-y-1/2 before:univer-bg-gray-200 before:univer-content-[""] rtl:univer-left-px rtl:univer-right-auto rtl:univer-rounded-l-md rtl:univer-rounded-r-none dark:before:!univer-bg-gray-600`,Be,Ve,f),children:[I(`span`,{className:W(`univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,V&&`univer-cursor-not-allowed univer-opacity-60`),role:`button`,"aria-label":`increment`,"aria-disabled":V,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>{V||B(!0)},children:`+`}),I(`span`,{className:W(`univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,H&&`univer-cursor-not-allowed univer-opacity-60`),role:`button`,"aria-label":`decrement`,"aria-disabled":H,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>{H||B(!1)},children:`-`})]})]})})});function fn({items:e,value:t,defaultValue:n,onChange:r,className:i=``}){let[a,o]=M(t===void 0?n||e[0].value:t),[s,c]=M({}),l=j(new Map),u=j(null);D(()=>{t!==void 0&&t!==a&&o(t)},[t]);let d=(e,t)=>{let n=l.current.get(e),r=t?l.current.get(t):null;if(n&&u.current){let e=u.current.getBoundingClientRect(),t=n.getBoundingClientRect(),i=t.left-e.left-4;if(r){let n=r.getBoundingClientRect().left-e.left-4;c({"--slide-from":`${n}px`,"--slide-to":`${i}px`,width:`${t.width}px`,transform:`translateX(${i}px)`})}else c({width:`${t.width}px`,transform:`translateX(${i}px)`})}};D(()=>{d(a)},[a]);let f=e=>{let t=a;o(e),r==null||r(e),d(e,t)};return L(`div`,{"data-u-comp":`segmented`,ref:u,className:W(`univer-relative univer-box-border univer-flex univer-gap-4 univer-rounded-lg univer-bg-gray-100 univer-p-1 dark:!univer-bg-gray-800`,i),children:[I(`div`,{className:`univer-animate-univer-slide univer-absolute univer-h-6 univer-rounded-md univer-bg-white univer-shadow-sm univer-transition-all univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-gray-400`,style:s}),e.map(e=>I(`button`,{ref:t=>{t&&l.current.set(e.value,t)},className:W(`univer-relative univer-box-border univer-flex-1 univer-cursor-pointer univer-border-none univer-bg-transparent univer-px-3 univer-py-1 univer-text-xs univer-font-medium univer-transition-colors`,{"univer-text-gray-900 dark:!univer-text-white":a===e.value,"univer-text-gray-500 hover:univer-text-gray-900 dark:hover:!univer-text-white":a!==e.value}),type:`button`,onClick:()=>f(e.value),children:e.label},String(e.value)))]})}function pn(e){let{children:t,className:n,asChild:r=!0,title:i,placement:a=`bottom`,showIfEllipsis:o=!1,visible:s,onVisibleChange:c}=e,[l,u]=M(!1),d=s!==void 0,f=d?s:l,p=j(null),m=j(null),h=j(null),[g,_]=M(null),[v,y]=M(a);function b(e){return Math.abs(e.scrollWidth-e.clientWidth)>1}function x(){d?c==null||c(!0):u(!0)}function S(){d?c==null||c(!1):u(!1)}k(()=>{if(!f)return;let e=p.current,t=m.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=window.innerWidth,o=window.innerHeight,s=[a,`bottom`,`top`,`right`,`left`],c=a,l=0,u=0,d=e=>{let t=0,i=0;return e===`bottom`?(t=n.bottom+8,i=n.left+n.width/2-r.width/2):e===`top`?(t=n.top-r.height-8,i=n.left+n.width/2-r.width/2):e===`left`?(t=n.top+n.height/2-r.height/2,i=n.left-r.width-8):(t=n.top+n.height/2-r.height/2,i=n.right+8),{t,l:i}};for(let e of s){let{t,l:n}=d(e),a=n>=0&&n+r.width<=i,s=t>=0&&t+r.height<=o;if(a&&s){c=e,l=t,u=n;break}}if(!l&&!u){let e=d(a);l=Math.min(Math.max(0,e.t),o-r.height),u=Math.min(Math.max(0,e.l),i-r.width)}y(c),_({top:Math.round(l+window.scrollY),left:Math.round(u+window.scrollX)})},[f,a]),D(()=>{if(!f)return;let e=()=>{if(!p.current||!m.current)return;let e=p.current.getBoundingClientRect(),t=m.current.getBoundingClientRect(),n=0,r=0;v===`bottom`?(n=e.bottom+8,r=e.left+e.width/2-t.width/2):v===`top`?(n=e.top-t.height-8,r=e.left+e.width/2-t.width/2):v===`left`?(n=e.top+e.height/2-t.height/2,r=e.left-t.width-8):(n=e.top+e.height/2-t.height/2,r=e.right+8),_({top:Math.round(n+window.scrollY),left:Math.round(r+window.scrollX)})};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[f,v]);let C={ref:e=>p.current=e,onMouseEnter:()=>{o&&p.current&&!b(p.current)||x()},onMouseLeave:()=>S(),onFocus:()=>x(),onBlur:()=>S()},w=r?I(`span`,{...C,className:`univer-inline-block univer-max-w-full univer-truncate`,children:t}):I(`button`,{type:`button`,...C,children:t}),T=null;if(typeof document<`u`&&f&&i&&document.body){var E,O;T=ce(L(`div`,{ref:m,role:`tooltip`,className:W(`univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900`,n),style:{top:(E=g==null?void 0:g.top)==null?-9999:E,left:(O=g==null?void 0:g.left)==null?-9999:O},onMouseEnter:()=>x(),onMouseLeave:()=>S(),children:[I(`div`,{className:`univer-break-words`,children:i}),I(`div`,{ref:h,className:`univer-absolute univer-size-2.5 univer-rotate-45 univer-rounded-sm univer-bg-gray-700 dark:!univer-bg-gray-100`,style:{...v===`bottom`&&{top:-5,left:`50%`,transform:`translateX(-50%) rotate(45deg)`},...v===`top`&&{bottom:-5,left:`50%`,transform:`translateX(-50%) rotate(45deg)`},...v===`left`&&{right:-5,top:`50%`,transform:`translateY(-50%) rotate(45deg)`},...v===`right`&&{left:-5,top:`50%`,transform:`translateY(-50%) rotate(45deg)`}}})]}),document.body)}return L(F,{children:[w,T]})}const mn={type:`linear`,stops:[{color:`#ffffff`,offset:0},{color:`#000000`,offset:100}],angle:90};function hn(e){var t,n;let{className:r,value:a=mn,onChange:o}=e,{locale:s}=E(K),[c,l]=M(0),u=j(null),d=A(()=>[...a.stops].sort((e,t)=>e.offset-t.offset),[a.stops]),f=e=>{o==null||o({...a,type:e})},p=e=>{o==null||o({...a,angle:e==null?0:e})},m=e=>{let t=[...a.stops];t[c]={...t[c],color:e},o==null||o({...a,stops:t})},h=e=>{if(e===null)return;let t=[...a.stops];t[c]={...t[c],offset:e},o==null||o({...a,stops:t})},g=e=>{if(!u.current)return;let t=u.current.getBoundingClientRect(),n=Math.round((e.clientX-t.left)/t.width*100),r={color:([...d].reverse().find(e=>e.offset<=n)||d[0]).color,offset:n},i=[...a.stops,r];o==null||o({...a,stops:i}),l(i.length-1)},_=()=>{if(a.stops.length<=2)return;let e=a.stops.filter((e,t)=>t!==c);o==null||o({...a,stops:e}),l(0)},v=A(()=>`linear-gradient(to right, ${d.map(e=>`${e.color} ${e.offset}%`).join(`, `)})`,[d]),y=A(()=>{let e=d.map(e=>`${e.color} ${e.offset}%`).join(`, `);switch(a.type){case`linear`:return`linear-gradient(${a.angle}deg, ${e})`;case`radial`:return`radial-gradient(circle, ${e})`;case`angular`:return`conic-gradient(from ${a.angle}deg, ${e})`;case`diamond`:return`radial-gradient(circle, ${e})`;default:return`linear-gradient(${a.angle}deg, ${e})`}},[a,d]);return L(`div`,{className:W(`univer-flex univer-w-64 univer-flex-col univer-gap-4 univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-bg-gray-800`,r),children:[I(fn,{items:[{label:s==null?void 0:s.GradientColorPicker.linear,value:`linear`},{label:s==null?void 0:s.GradientColorPicker.radial,value:`radial`},{label:s==null?void 0:s.GradientColorPicker.angular,value:`angular`},{label:s==null?void 0:s.GradientColorPicker.diamond,value:`diamond`}],value:a.type,onChange:e=>f(e)}),I(`div`,{className:`univer-h-32 univer-w-full univer-rounded-md univer-border univer-border-gray-200 dark:!univer-border-gray-600`,style:{background:y}}),L(`div`,{className:`univer-relative univer-mt-4 univer-h-6`,children:[I(`div`,{ref:u,className:`univer-absolute univer-inset-x-0 univer-top-1/2 univer-h-2 -univer-translate-y-1/2 univer-cursor-crosshair univer-rounded-full`,style:{background:v},onClick:g}),a.stops.map((e,t)=>I(`div`,{className:W(`univer-absolute univer-top-1/2 univer-size-4 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-cursor-pointer univer-rounded-full univer-border-2 univer-border-white univer-shadow-md`,c===t?`univer-z-10 univer-ring-2 univer-ring-primary-500`:`univer-z-0`),style:{left:`${e.offset}%`,backgroundColor:e.color},onClick:e=>{e.stopPropagation(),l(t)},onPointerDown:n=>{let r=n.clientX,i=e.offset,s=e=>{if(!u.current)return;let n=u.current.getBoundingClientRect(),s=(e.clientX-r)/n.width*100,c=Math.max(0,Math.min(100,Math.round(i+s))),l=[...a.stops];l[t]={...l[t],offset:c},o==null||o({...a,stops:l})},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c)};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c)}},t))]}),L(`div`,{className:`univer-flex univer-items-end univer-gap-2`,children:[L(`div`,{className:`univer-flex-1`,children:[I(`div`,{className:`univer-mb-1 univer-text-xs univer-text-gray-500`,children:s==null?void 0:s.GradientColorPicker.offset}),I(dn,{value:(t=a.stops[c])==null?void 0:t.offset,min:0,max:100,onChange:h})]}),(a.type===`linear`||a.type===`angular`)&&L(`div`,{className:`univer-flex-1`,children:[I(`div`,{className:`univer-mb-1 univer-text-xs univer-text-gray-500`,children:s==null?void 0:s.GradientColorPicker.angle}),I(dn,{value:a.angle,min:0,max:360,onChange:p})]}),I(`div`,{className:`univer-flex univer-gap-1`,children:I(pn,{title:s==null?void 0:s.GradientColorPicker.delete,children:I(G,{variant:`danger`,onClick:_,disabled:a.stops.length<=2,children:I(i,{})})})})]}),I(`div`,{className:`univer-border-t univer-border-gray-100 univer-pt-4 dark:!univer-border-gray-700`,children:I(Mt,{value:(n=a.stops[c])==null?void 0:n.color,onChange:m})})]})}const gn=we,_n=Ce,vn=Te,yn=S(({className:e,align:t=`center`,sideOffset:n=4,...r},i)=>I(Se,{ref:i,align:t,sideOffset:n,className:W(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-w-64 univer-origin-[--radix-hover-card-content-transform-origin] univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900 dark:!univer-text-white`,Y,e),...r}));yn.displayName=Se.displayName;function bn(e){let{children:t,overlay:n,disabled:r,openDelay:i=200,open:a,onOpenChange:o,...s}=e,[c,l]=M(!1),u=a!==void 0,d=u?a:c;function f(e){r||(u||l(e),o==null||o(e))}return L(gn,{open:d,onOpenChange:f,openDelay:i,children:[I(vn,{asChild:!0,children:t}),I(_n,{children:I(yn,{...s,children:n})})]})}function xn(e){let{keyboard:t,className:n}=e,r=t.split(`+`);return I(`span`,{className:W(`univer-inline-block univer-h-6 univer-select-none univer-whitespace-nowrap univer-rounded-md univer-bg-gray-50 univer-px-2 univer-font-mono univer-text-xs/6 univer-font-medium univer-text-gray-700 dark:!univer-bg-gray-700 dark:!univer-text-white`,Y,n),children:r.map((e,t)=>L(F,{children:[I(`kbd`,{className:`univer-inline-block univer-h-full`,children:e}),t<r.length-1&&I(`span`,{className:`univer-inline-block univer-h-full univer-px-1`,children:`+`})]},t))})}let Q=function(e){return e.Success=`success`,e.Info=`info`,e.Warning=`warning`,e.Error=`error`,e.Loading=`loading`,e}({});const Sn=`univer-message-toaster`,Cn=3e3,$=new Set,wn=I(l,{className:`univer-animate-spin univer-text-violet-500`});let Tn=0;const En={[Q.Success]:I(h,{className:`univer-text-green-500`}),[Q.Info]:I(c,{className:`univer-text-sky-500 dark:!univer-text-sky-400`}),[Q.Warning]:I(g,{className:`univer-text-amber-500`}),[Q.Error]:I(s,{className:`univer-text-red-500`}),[Q.Loading]:wn},Dn={[Q.Success]:`[&_[data-icon]]:univer-text-green-500`,[Q.Info]:`[&_[data-icon]]:univer-text-sky-500`,[Q.Warning]:`[&_[data-icon]]:univer-text-amber-500`,[Q.Error]:`[&_[data-icon]]:univer-text-red-500`,[Q.Loading]:`[&_[data-icon]]:univer-text-violet-500`},On=e=>{switch(e){case Q.Success:return U.success;case Q.Warning:return U.warning;case Q.Error:return U.error;case Q.Loading:return U.loading;case Q.Info:default:return U.info}},kn=()=>{let e=`univer-message-${Tn}`;return Tn+=1,e},An=({className:e,...t})=>I(Ee,{id:Sn,position:`top-center`,visibleToasts:4,closeButton:!1,expand:!1,icons:{loading:wn},offset:{top:16},className:W(`[&_[data-sonner-toast]]:univer-bg-white/95 dark:[&_[data-sonner-toast]]:!univer-bg-gray-800/95 [&_[data-sonner-toast]]:univer-rounded-2xl [&_[data-sonner-toast]]:univer-border [&_[data-sonner-toast]]:univer-border-solid [&_[data-sonner-toast]]:univer-border-gray-200 [&_[data-sonner-toast]]:univer-shadow-[0_16px_40px_-20px_rgba(15,23,42,0.55)] [&_[data-sonner-toast]]:univer-backdrop-blur-sm dark:[&_[data-sonner-toast]]:!univer-border-gray-600`,e),toastOptions:{duration:Cn,classNames:{toast:`
|
|
2557
|
+
`, allowClear && !slot && "univer-pr-8", inputClass),
|
|
2558
|
+
placeholder,
|
|
2559
|
+
value,
|
|
2560
|
+
disabled,
|
|
2561
|
+
autoFocus,
|
|
2562
|
+
onClick,
|
|
2563
|
+
onKeyDown,
|
|
2564
|
+
onChange: handleChange,
|
|
2565
|
+
onFocus,
|
|
2566
|
+
onBlur,
|
|
2567
|
+
style: {
|
|
2568
|
+
...inputStyle,
|
|
2569
|
+
paddingRight
|
|
2570
|
+
},
|
|
2571
|
+
...props
|
|
2572
|
+
}), hasSlotContent && /* @__PURE__ */ jsxs("div", {
|
|
2573
|
+
className: "univer-absolute univer-right-2 univer-flex univer-items-center univer-gap-1 univer-rounded-full",
|
|
2574
|
+
ref: slotRef,
|
|
2575
|
+
children: [slot, allowClear && value && !disabled && /* @__PURE__ */ jsx("button", {
|
|
2576
|
+
type: "button",
|
|
2577
|
+
onClick: handleClear,
|
|
2578
|
+
className: "univer-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded-full univer-border-none univer-bg-transparent univer-p-1 univer-text-gray-400 univer-transition-colors univer-duration-200 hover:univer-text-gray-500 focus:univer-outline-none",
|
|
2579
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { className: "univer-size-3" })
|
|
2580
|
+
})]
|
|
2581
|
+
})]
|
|
2582
|
+
});
|
|
2583
|
+
});
|
|
2584
|
+
|
|
2585
|
+
//#endregion
|
|
2586
|
+
//#region src/components/input-number/InputNumber.tsx
|
|
2587
|
+
const InputNumber = forwardRef(({ value, defaultValue, size = "small", min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, precision, formatter, parser, controls = true, className, inputClassName, controlsClassName, disabled, onChange, onKeyDown, onPressEnter, onFocus, onBlur, allowEmpty = false }, ref) => {
|
|
2588
|
+
const [internalValue, setInternalValue] = useState(value !== void 0 ? value : defaultValue !== void 0 ? defaultValue : null);
|
|
2589
|
+
const lastValidValueRef = useRef(internalValue);
|
|
2590
|
+
const [inputValue, setInputValue] = useState(formatValue(internalValue));
|
|
2591
|
+
const inputRef = useRef(null);
|
|
2592
|
+
const longPressTimerRef = useRef(null);
|
|
2593
|
+
const longPressIntervalRef = useRef(null);
|
|
2594
|
+
const mergedRef = (node) => {
|
|
2595
|
+
if (ref) if (typeof ref === "function") ref(node);
|
|
2596
|
+
else ref.current = node;
|
|
2597
|
+
inputRef.current = node;
|
|
2598
|
+
};
|
|
2599
|
+
useEffect(() => {
|
|
2600
|
+
if (value !== void 0 && value !== internalValue) {
|
|
2601
|
+
setInternalValue(value);
|
|
2602
|
+
lastValidValueRef.current = value;
|
|
2603
|
+
setInputValue(formatValue(value));
|
|
2604
|
+
}
|
|
2605
|
+
}, [value]);
|
|
2606
|
+
useEffect(() => {
|
|
2607
|
+
if (internalValue !== null) lastValidValueRef.current = internalValue;
|
|
2608
|
+
}, [internalValue]);
|
|
2609
|
+
useEffect(() => {
|
|
2610
|
+
return () => {
|
|
2611
|
+
if (longPressTimerRef.current) clearTimeout(longPressTimerRef.current);
|
|
2612
|
+
if (longPressIntervalRef.current) clearInterval(longPressIntervalRef.current);
|
|
2613
|
+
};
|
|
2614
|
+
}, []);
|
|
2615
|
+
function formatValue(val) {
|
|
2616
|
+
if (val === null || val === void 0) return "";
|
|
2617
|
+
let formattedValue = val;
|
|
2618
|
+
if (precision !== void 0) formattedValue = Number(val).toFixed(precision);
|
|
2619
|
+
if (formatter) return formatter(formattedValue);
|
|
2620
|
+
return String(formattedValue);
|
|
2621
|
+
}
|
|
2622
|
+
function parseValue(val) {
|
|
2623
|
+
if (!val) return null;
|
|
2624
|
+
let parsedValue = val;
|
|
2625
|
+
if (parser) parsedValue = parser(val);
|
|
2626
|
+
try {
|
|
2627
|
+
const parts = parsedValue.replace(/[^\d.-]/g, "").split(".");
|
|
2628
|
+
const firstPart = parts[0];
|
|
2629
|
+
const secondPart = parts.length > 1 ? parts.slice(1).join("") : "";
|
|
2630
|
+
const normalizedValue = firstPart + (secondPart ? `.${secondPart}` : "");
|
|
2631
|
+
const num = Number(normalizedValue);
|
|
2632
|
+
if (Number.isNaN(num)) return null;
|
|
2633
|
+
let result;
|
|
2634
|
+
if (precision !== void 0) {
|
|
2635
|
+
const factor = 10 ** precision;
|
|
2636
|
+
const roundedNum = Math.round(num * factor) / factor;
|
|
2637
|
+
if (roundedNum.toString().includes("e")) result = Number.parseFloat(roundedNum.toFixed(precision));
|
|
2638
|
+
else result = roundedNum;
|
|
2639
|
+
} else if (num.toString().includes("e")) result = Number.parseFloat(num.toFixed(16).replace(/\.?0+$/, ""));
|
|
2640
|
+
else result = num;
|
|
2641
|
+
if (max !== void 0 && result > max) result = max;
|
|
2642
|
+
if (min !== void 0 && result < min) result = min;
|
|
2643
|
+
return result;
|
|
2644
|
+
} catch (e) {
|
|
2645
|
+
return null;
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
function handleInputChange(value) {
|
|
2649
|
+
setInputValue(value);
|
|
2650
|
+
if (allowEmpty && value === "") {
|
|
2651
|
+
setInternalValue(null);
|
|
2652
|
+
onChange === null || onChange === void 0 || onChange(null);
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
const parsedValue = parseValue(value);
|
|
2656
|
+
setInternalValue(parsedValue);
|
|
2657
|
+
onChange === null || onChange === void 0 || onChange(parsedValue);
|
|
2658
|
+
}
|
|
2659
|
+
function handleBlur(e) {
|
|
2660
|
+
if (internalValue === null) {
|
|
2661
|
+
if (inputValue === "" && allowEmpty) {
|
|
2662
|
+
if (onChange) onChange(null);
|
|
2663
|
+
} else {
|
|
2664
|
+
const valueToRestore = lastValidValueRef.current;
|
|
2665
|
+
setInternalValue(valueToRestore);
|
|
2666
|
+
setInputValue(formatValue(valueToRestore));
|
|
2667
|
+
if (onChange) onChange(valueToRestore);
|
|
2668
|
+
}
|
|
2669
|
+
onBlur === null || onBlur === void 0 || onBlur(e);
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
let valueInRange = internalValue;
|
|
2673
|
+
if (max !== void 0 && valueInRange > max) valueInRange = max;
|
|
2674
|
+
if (min !== void 0 && valueInRange < min) valueInRange = min;
|
|
2675
|
+
if (valueInRange !== internalValue) {
|
|
2676
|
+
setInternalValue(valueInRange);
|
|
2677
|
+
setInputValue(formatValue(valueInRange));
|
|
2678
|
+
onChange === null || onChange === void 0 || onChange(valueInRange);
|
|
2679
|
+
} else setInputValue(formatValue(internalValue));
|
|
2680
|
+
onBlur === null || onBlur === void 0 || onBlur(e);
|
|
2681
|
+
}
|
|
2682
|
+
function handleStep(isUp) {
|
|
2683
|
+
if (disabled) return;
|
|
2684
|
+
const stepValue = isUp ? step : -step;
|
|
2685
|
+
let currentValue;
|
|
2686
|
+
if (internalValue !== null) currentValue = internalValue;
|
|
2687
|
+
else if (lastValidValueRef.current !== null) currentValue = lastValidValueRef.current;
|
|
2688
|
+
else currentValue = min > 0 ? min : 0;
|
|
2689
|
+
let newValue = currentValue + stepValue;
|
|
2690
|
+
if (max !== void 0 && newValue > max) newValue = max;
|
|
2691
|
+
if (min !== void 0 && newValue < min) newValue = min;
|
|
2692
|
+
if (newValue === currentValue) return;
|
|
2693
|
+
setInternalValue(newValue);
|
|
2694
|
+
lastValidValueRef.current = newValue;
|
|
2695
|
+
setInputValue(formatValue(newValue));
|
|
2696
|
+
onChange === null || onChange === void 0 || onChange(newValue);
|
|
2697
|
+
}
|
|
2698
|
+
function handleKeyDown(e) {
|
|
2699
|
+
if (disabled) return;
|
|
2700
|
+
onKeyDown === null || onKeyDown === void 0 || onKeyDown(e);
|
|
2701
|
+
if (e.key === "ArrowUp") {
|
|
2702
|
+
e.preventDefault();
|
|
2703
|
+
handleStep(true);
|
|
2704
|
+
} else if (e.key === "ArrowDown") {
|
|
2705
|
+
e.preventDefault();
|
|
2706
|
+
handleStep(false);
|
|
2707
|
+
} else if (e.key === "Enter") onPressEnter === null || onPressEnter === void 0 || onPressEnter(e);
|
|
2708
|
+
}
|
|
2709
|
+
function handleClick(isUp) {
|
|
2710
|
+
var _inputRef$current;
|
|
2711
|
+
if (disabled) return;
|
|
2712
|
+
handleStep(isUp);
|
|
2713
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
2714
|
+
}
|
|
2715
|
+
const incrementDisabled = disabled || max !== void 0 && internalValue !== null && internalValue >= max;
|
|
2716
|
+
const decrementDisabled = disabled || min !== void 0 && internalValue !== null && internalValue <= min;
|
|
2717
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2718
|
+
className: clsx("univer-inline-block", className),
|
|
2719
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2720
|
+
className: "univer-relative univer-w-full",
|
|
2721
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
2722
|
+
ref: mergedRef,
|
|
2723
|
+
className: clsx("univer-box-border", inputClassName),
|
|
2724
|
+
size,
|
|
2725
|
+
value: inputValue,
|
|
2726
|
+
disabled,
|
|
2727
|
+
onChange: handleInputChange,
|
|
2728
|
+
onFocus,
|
|
2729
|
+
onBlur: handleBlur,
|
|
2730
|
+
onKeyDown: handleKeyDown
|
|
2731
|
+
}), controls && /* @__PURE__ */ jsxs("div", {
|
|
2732
|
+
className: clsx("univer-absolute univer-right-px univer-top-px univer-flex univer-h-[calc(100%-2px)] univer-flex-col univer-overflow-hidden univer-rounded-r-md before:univer-absolute before:univer-top-1/2 before:univer-block before:univer-h-px before:univer-w-full before:-univer-translate-y-1/2 before:univer-bg-gray-200 before:univer-content-[\"\"] rtl:univer-left-px rtl:univer-right-auto rtl:univer-rounded-l-md rtl:univer-rounded-r-none dark:before:!univer-bg-gray-600", borderLeftClassName, borderLeftRTLClassName, controlsClassName),
|
|
2733
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2734
|
+
className: clsx("univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600", incrementDisabled && "univer-cursor-not-allowed univer-opacity-60"),
|
|
2735
|
+
role: "button",
|
|
2736
|
+
"aria-label": "increment",
|
|
2737
|
+
"aria-disabled": incrementDisabled,
|
|
2738
|
+
tabIndex: -1,
|
|
2739
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2740
|
+
onClick: () => {
|
|
2741
|
+
if (incrementDisabled) return;
|
|
2742
|
+
handleClick(true);
|
|
2743
|
+
},
|
|
2744
|
+
children: "+"
|
|
2745
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2746
|
+
className: clsx("univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600", decrementDisabled && "univer-cursor-not-allowed univer-opacity-60"),
|
|
2747
|
+
role: "button",
|
|
2748
|
+
"aria-label": "decrement",
|
|
2749
|
+
"aria-disabled": decrementDisabled,
|
|
2750
|
+
tabIndex: -1,
|
|
2751
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2752
|
+
onClick: () => {
|
|
2753
|
+
if (decrementDisabled) return;
|
|
2754
|
+
handleClick(false);
|
|
2755
|
+
},
|
|
2756
|
+
children: "-"
|
|
2757
|
+
})]
|
|
2758
|
+
})]
|
|
2759
|
+
})
|
|
2760
|
+
});
|
|
2761
|
+
});
|
|
2762
|
+
|
|
2763
|
+
//#endregion
|
|
2764
|
+
//#region src/components/segmented/Segmented.tsx
|
|
2765
|
+
function Segmented({ items, value, defaultValue, onChange, className = "" }) {
|
|
2766
|
+
const [selectedItem, setSelectedItem] = useState(value !== void 0 ? value : defaultValue || items[0].value);
|
|
2767
|
+
const [slideStyle, setSlideStyle] = useState({});
|
|
2768
|
+
const itemRefs = useRef(/* @__PURE__ */ new Map());
|
|
2769
|
+
const containerRef = useRef(null);
|
|
2770
|
+
useEffect(() => {
|
|
2771
|
+
if (value !== void 0 && value !== selectedItem) setSelectedItem(value);
|
|
2772
|
+
}, [value]);
|
|
2773
|
+
const updateSliderPosition = (newValue, oldValue) => {
|
|
2774
|
+
const newItemElement = itemRefs.current.get(newValue);
|
|
2775
|
+
const oldItemElement = oldValue ? itemRefs.current.get(oldValue) : null;
|
|
2776
|
+
if (newItemElement && containerRef.current) {
|
|
2777
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
2778
|
+
const newRect = newItemElement.getBoundingClientRect();
|
|
2779
|
+
const newLeft = newRect.left - containerRect.left - 4;
|
|
2780
|
+
if (oldItemElement) setSlideStyle({
|
|
2781
|
+
"--slide-from": `${oldItemElement.getBoundingClientRect().left - containerRect.left - 4}px`,
|
|
2782
|
+
"--slide-to": `${newLeft}px`,
|
|
2783
|
+
width: `${newRect.width}px`,
|
|
2784
|
+
transform: `translateX(${newLeft}px)`
|
|
2785
|
+
});
|
|
2786
|
+
else setSlideStyle({
|
|
2787
|
+
width: `${newRect.width}px`,
|
|
2788
|
+
transform: `translateX(${newLeft}px)`
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
};
|
|
2792
|
+
useEffect(() => {
|
|
2793
|
+
updateSliderPosition(selectedItem);
|
|
2794
|
+
}, [selectedItem]);
|
|
2795
|
+
const handleClick = (itemValue) => {
|
|
2796
|
+
const oldValue = selectedItem;
|
|
2797
|
+
setSelectedItem(itemValue);
|
|
2798
|
+
onChange === null || onChange === void 0 || onChange(itemValue);
|
|
2799
|
+
updateSliderPosition(itemValue, oldValue);
|
|
2800
|
+
};
|
|
2801
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2802
|
+
"data-u-comp": "segmented",
|
|
2803
|
+
ref: containerRef,
|
|
2804
|
+
className: clsx("univer-relative univer-box-border univer-flex univer-gap-4 univer-rounded-lg univer-bg-gray-100 univer-p-1 dark:!univer-bg-gray-800", className),
|
|
2805
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2806
|
+
className: "univer-animate-univer-slide univer-absolute univer-h-6 univer-rounded-md univer-bg-white univer-shadow-sm univer-transition-all univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-gray-400",
|
|
2807
|
+
style: slideStyle
|
|
2808
|
+
}), items.map((item) => /* @__PURE__ */ jsx("button", {
|
|
2809
|
+
ref: (el) => {
|
|
2810
|
+
if (el) itemRefs.current.set(item.value, el);
|
|
2811
|
+
},
|
|
2812
|
+
className: clsx("univer-relative univer-box-border univer-flex-1 univer-cursor-pointer univer-border-none univer-bg-transparent univer-px-3 univer-py-1 univer-text-xs univer-font-medium univer-transition-colors", {
|
|
2813
|
+
"univer-text-gray-900 dark:!univer-text-white": selectedItem === item.value,
|
|
2814
|
+
"univer-text-gray-500 hover:univer-text-gray-900 dark:hover:!univer-text-white": selectedItem !== item.value
|
|
2815
|
+
}),
|
|
2816
|
+
type: "button",
|
|
2817
|
+
onClick: () => handleClick(item.value),
|
|
2818
|
+
children: item.label
|
|
2819
|
+
}, String(item.value)))]
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
//#endregion
|
|
2824
|
+
//#region src/components/tooltip/Tooltip.tsx
|
|
2825
|
+
function Tooltip(props) {
|
|
2826
|
+
const { children, className, asChild = true, title, placement = "bottom", showIfEllipsis = false, visible: controlledVisible, onVisibleChange } = props;
|
|
2827
|
+
const [uncontrolledVisible, setUncontrolledVisible] = useState(false);
|
|
2828
|
+
const isControlled = controlledVisible !== void 0;
|
|
2829
|
+
const visible = isControlled ? controlledVisible : uncontrolledVisible;
|
|
2830
|
+
const triggerRef = useRef(null);
|
|
2831
|
+
const tooltipRef = useRef(null);
|
|
2832
|
+
const arrowRef = useRef(null);
|
|
2833
|
+
const [coords, setCoords] = useState(null);
|
|
2834
|
+
const [currentPlacement, setCurrentPlacement] = useState(placement);
|
|
2835
|
+
function isContentOverflowing(element) {
|
|
2836
|
+
return Math.abs(element.scrollWidth - element.clientWidth) > 1;
|
|
2837
|
+
}
|
|
2838
|
+
function showTooltip() {
|
|
2839
|
+
if (isControlled) onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(true);
|
|
2840
|
+
else setUncontrolledVisible(true);
|
|
2841
|
+
}
|
|
2842
|
+
function hideTooltip() {
|
|
2843
|
+
if (isControlled) onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(false);
|
|
2844
|
+
else setUncontrolledVisible(false);
|
|
2845
|
+
}
|
|
2846
|
+
useLayoutEffect(() => {
|
|
2847
|
+
if (!visible) return;
|
|
2848
|
+
const trigger = triggerRef.current;
|
|
2849
|
+
const tip = tooltipRef.current;
|
|
2850
|
+
if (!trigger || !tip) return;
|
|
2851
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
2852
|
+
const tipRect = tip.getBoundingClientRect();
|
|
2853
|
+
const offset = 8;
|
|
2854
|
+
const viewportWidth = window.innerWidth;
|
|
2855
|
+
const viewportHeight = window.innerHeight;
|
|
2856
|
+
const placements = [
|
|
2857
|
+
placement,
|
|
2858
|
+
"bottom",
|
|
2859
|
+
"top",
|
|
2860
|
+
"right",
|
|
2861
|
+
"left"
|
|
2862
|
+
];
|
|
2863
|
+
let chosen = placement;
|
|
2864
|
+
let top = 0;
|
|
2865
|
+
let left = 0;
|
|
2866
|
+
const computeFor = (p) => {
|
|
2867
|
+
let t = 0;
|
|
2868
|
+
let l = 0;
|
|
2869
|
+
if (p === "bottom") {
|
|
2870
|
+
t = triggerRect.bottom + offset;
|
|
2871
|
+
l = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
|
|
2872
|
+
} else if (p === "top") {
|
|
2873
|
+
t = triggerRect.top - tipRect.height - offset;
|
|
2874
|
+
l = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
|
|
2875
|
+
} else if (p === "left") {
|
|
2876
|
+
t = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
|
|
2877
|
+
l = triggerRect.left - tipRect.width - offset;
|
|
2878
|
+
} else {
|
|
2879
|
+
t = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
|
|
2880
|
+
l = triggerRect.right + offset;
|
|
2881
|
+
}
|
|
2882
|
+
return {
|
|
2883
|
+
t,
|
|
2884
|
+
l
|
|
2885
|
+
};
|
|
2886
|
+
};
|
|
2887
|
+
for (const p of placements) {
|
|
2888
|
+
const { t, l } = computeFor(p);
|
|
2889
|
+
const fitsHorizontally = l >= 0 && l + tipRect.width <= viewportWidth;
|
|
2890
|
+
const fitsVertically = t >= 0 && t + tipRect.height <= viewportHeight;
|
|
2891
|
+
if (fitsHorizontally && fitsVertically) {
|
|
2892
|
+
chosen = p;
|
|
2893
|
+
top = t;
|
|
2894
|
+
left = l;
|
|
2895
|
+
break;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
if (!top && !left) {
|
|
2899
|
+
const c = computeFor(placement);
|
|
2900
|
+
top = Math.min(Math.max(0, c.t), viewportHeight - tipRect.height);
|
|
2901
|
+
left = Math.min(Math.max(0, c.l), viewportWidth - tipRect.width);
|
|
2902
|
+
}
|
|
2903
|
+
setCurrentPlacement(chosen);
|
|
2904
|
+
setCoords({
|
|
2905
|
+
top: Math.round(top + window.scrollY),
|
|
2906
|
+
left: Math.round(left + window.scrollX)
|
|
2907
|
+
});
|
|
2908
|
+
}, [visible, placement]);
|
|
2909
|
+
useEffect(() => {
|
|
2910
|
+
if (!visible) return;
|
|
2911
|
+
const handler = () => {
|
|
2912
|
+
if (!triggerRef.current || !tooltipRef.current) return;
|
|
2913
|
+
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
2914
|
+
const tipRect = tooltipRef.current.getBoundingClientRect();
|
|
2915
|
+
const offset = 8;
|
|
2916
|
+
let top = 0;
|
|
2917
|
+
let left = 0;
|
|
2918
|
+
if (currentPlacement === "bottom") {
|
|
2919
|
+
top = triggerRect.bottom + offset;
|
|
2920
|
+
left = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
|
|
2921
|
+
} else if (currentPlacement === "top") {
|
|
2922
|
+
top = triggerRect.top - tipRect.height - offset;
|
|
2923
|
+
left = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
|
|
2924
|
+
} else if (currentPlacement === "left") {
|
|
2925
|
+
top = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
|
|
2926
|
+
left = triggerRect.left - tipRect.width - offset;
|
|
2927
|
+
} else {
|
|
2928
|
+
top = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
|
|
2929
|
+
left = triggerRect.right + offset;
|
|
2930
|
+
}
|
|
2931
|
+
setCoords({
|
|
2932
|
+
top: Math.round(top + window.scrollY),
|
|
2933
|
+
left: Math.round(left + window.scrollX)
|
|
2934
|
+
});
|
|
2935
|
+
};
|
|
2936
|
+
window.addEventListener("scroll", handler, true);
|
|
2937
|
+
window.addEventListener("resize", handler);
|
|
2938
|
+
return () => {
|
|
2939
|
+
window.removeEventListener("scroll", handler, true);
|
|
2940
|
+
window.removeEventListener("resize", handler);
|
|
2941
|
+
};
|
|
2942
|
+
}, [visible, currentPlacement]);
|
|
2943
|
+
const commonProps = {
|
|
2944
|
+
ref: (node) => triggerRef.current = node,
|
|
2945
|
+
onMouseEnter: () => {
|
|
2946
|
+
if (showIfEllipsis && triggerRef.current) {
|
|
2947
|
+
if (!isContentOverflowing(triggerRef.current)) return;
|
|
2948
|
+
}
|
|
2949
|
+
showTooltip();
|
|
2950
|
+
},
|
|
2951
|
+
onMouseLeave: () => hideTooltip(),
|
|
2952
|
+
onFocus: () => showTooltip(),
|
|
2953
|
+
onBlur: () => hideTooltip()
|
|
2954
|
+
};
|
|
2955
|
+
const triggerElement = asChild ? /* @__PURE__ */ jsx("span", {
|
|
2956
|
+
...commonProps,
|
|
2957
|
+
className: "univer-inline-block univer-max-w-full univer-truncate",
|
|
2958
|
+
children
|
|
2959
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
2960
|
+
type: "button",
|
|
2961
|
+
...commonProps,
|
|
2962
|
+
children
|
|
2963
|
+
});
|
|
2964
|
+
let tooltipNode = null;
|
|
2965
|
+
if (typeof document !== "undefined" && visible && title && document.body) {
|
|
2966
|
+
var _coords$top, _coords$left;
|
|
2967
|
+
tooltipNode = createPortal(/* @__PURE__ */ jsxs("div", {
|
|
2968
|
+
ref: tooltipRef,
|
|
2969
|
+
role: "tooltip",
|
|
2970
|
+
className: clsx("univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900", className),
|
|
2971
|
+
style: {
|
|
2972
|
+
top: (_coords$top = coords === null || coords === void 0 ? void 0 : coords.top) !== null && _coords$top !== void 0 ? _coords$top : -9999,
|
|
2973
|
+
left: (_coords$left = coords === null || coords === void 0 ? void 0 : coords.left) !== null && _coords$left !== void 0 ? _coords$left : -9999
|
|
2974
|
+
},
|
|
2975
|
+
onMouseEnter: () => showTooltip(),
|
|
2976
|
+
onMouseLeave: () => hideTooltip(),
|
|
2977
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2978
|
+
className: "univer-break-words",
|
|
2979
|
+
children: title
|
|
2980
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2981
|
+
ref: arrowRef,
|
|
2982
|
+
className: "univer-absolute univer-size-2.5 univer-rotate-45 univer-rounded-sm univer-bg-gray-700 dark:!univer-bg-gray-100",
|
|
2983
|
+
style: {
|
|
2984
|
+
...currentPlacement === "bottom" && {
|
|
2985
|
+
top: -5,
|
|
2986
|
+
left: "50%",
|
|
2987
|
+
transform: "translateX(-50%) rotate(45deg)"
|
|
2988
|
+
},
|
|
2989
|
+
...currentPlacement === "top" && {
|
|
2990
|
+
bottom: -5,
|
|
2991
|
+
left: "50%",
|
|
2992
|
+
transform: "translateX(-50%) rotate(45deg)"
|
|
2993
|
+
},
|
|
2994
|
+
...currentPlacement === "left" && {
|
|
2995
|
+
right: -5,
|
|
2996
|
+
top: "50%",
|
|
2997
|
+
transform: "translateY(-50%) rotate(45deg)"
|
|
2998
|
+
},
|
|
2999
|
+
...currentPlacement === "right" && {
|
|
3000
|
+
left: -5,
|
|
3001
|
+
top: "50%",
|
|
3002
|
+
transform: "translateY(-50%) rotate(45deg)"
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
})]
|
|
3006
|
+
}), document.body);
|
|
3007
|
+
}
|
|
3008
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [triggerElement, tooltipNode] });
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
//#endregion
|
|
3012
|
+
//#region src/components/gradient-color-picker/GradientColorPicker.tsx
|
|
3013
|
+
/**
|
|
3014
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3015
|
+
*
|
|
3016
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3017
|
+
* you may not use this file except in compliance with the License.
|
|
3018
|
+
* You may obtain a copy of the License at
|
|
3019
|
+
*
|
|
3020
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3021
|
+
*
|
|
3022
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3023
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3024
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3025
|
+
* See the License for the specific language governing permissions and
|
|
3026
|
+
* limitations under the License.
|
|
3027
|
+
*/
|
|
3028
|
+
const DEFAULT_VALUE = {
|
|
3029
|
+
type: "linear",
|
|
3030
|
+
stops: [{
|
|
3031
|
+
color: "#ffffff",
|
|
3032
|
+
offset: 0
|
|
3033
|
+
}, {
|
|
3034
|
+
color: "#000000",
|
|
3035
|
+
offset: 100
|
|
3036
|
+
}],
|
|
3037
|
+
angle: 90
|
|
3038
|
+
};
|
|
3039
|
+
function GradientColorPicker(props) {
|
|
3040
|
+
var _value$stops$selected, _value$stops$selected2;
|
|
3041
|
+
const { className, value = DEFAULT_VALUE, onChange } = props;
|
|
3042
|
+
const { locale } = useContext(ConfigContext);
|
|
3043
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
3044
|
+
const barRef = useRef(null);
|
|
3045
|
+
const stops = useMemo(() => {
|
|
3046
|
+
return [...value.stops].sort((a, b) => a.offset - b.offset);
|
|
3047
|
+
}, [value.stops]);
|
|
3048
|
+
const handleTypeChange = (type) => {
|
|
3049
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3050
|
+
...value,
|
|
3051
|
+
type
|
|
3052
|
+
});
|
|
3053
|
+
};
|
|
3054
|
+
const handleAngleChange = (angle) => {
|
|
3055
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3056
|
+
...value,
|
|
3057
|
+
angle: angle !== null && angle !== void 0 ? angle : 0
|
|
3058
|
+
});
|
|
3059
|
+
};
|
|
3060
|
+
const handleStopColorChange = (color) => {
|
|
3061
|
+
const newStops = [...value.stops];
|
|
3062
|
+
newStops[selectedIndex] = {
|
|
3063
|
+
...newStops[selectedIndex],
|
|
3064
|
+
color
|
|
3065
|
+
};
|
|
3066
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3067
|
+
...value,
|
|
3068
|
+
stops: newStops
|
|
3069
|
+
});
|
|
3070
|
+
};
|
|
3071
|
+
const handleStopOffsetChange = (offset) => {
|
|
3072
|
+
if (offset === null) return;
|
|
3073
|
+
const newStops = [...value.stops];
|
|
3074
|
+
newStops[selectedIndex] = {
|
|
3075
|
+
...newStops[selectedIndex],
|
|
3076
|
+
offset
|
|
3077
|
+
};
|
|
3078
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3079
|
+
...value,
|
|
3080
|
+
stops: newStops
|
|
3081
|
+
});
|
|
3082
|
+
};
|
|
3083
|
+
const handleAddStop = (e) => {
|
|
3084
|
+
if (!barRef.current) return;
|
|
3085
|
+
const rect = barRef.current.getBoundingClientRect();
|
|
3086
|
+
const offset = Math.round((e.clientX - rect.left) / rect.width * 100);
|
|
3087
|
+
const newStop = {
|
|
3088
|
+
color: ([...stops].reverse().find((s) => s.offset <= offset) || stops[0]).color,
|
|
3089
|
+
offset
|
|
3090
|
+
};
|
|
3091
|
+
const newStops = [...value.stops, newStop];
|
|
3092
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3093
|
+
...value,
|
|
3094
|
+
stops: newStops
|
|
3095
|
+
});
|
|
3096
|
+
setSelectedIndex(newStops.length - 1);
|
|
3097
|
+
};
|
|
3098
|
+
const handleRemoveStop = () => {
|
|
3099
|
+
if (value.stops.length <= 2) return;
|
|
3100
|
+
const newStops = value.stops.filter((_, i) => i !== selectedIndex);
|
|
3101
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3102
|
+
...value,
|
|
3103
|
+
stops: newStops
|
|
3104
|
+
});
|
|
3105
|
+
setSelectedIndex(0);
|
|
3106
|
+
};
|
|
3107
|
+
const gradientPreview = useMemo(() => {
|
|
3108
|
+
return `linear-gradient(to right, ${stops.map((s) => `${s.color} ${s.offset}%`).join(", ")})`;
|
|
3109
|
+
}, [stops]);
|
|
3110
|
+
const mainPreview = useMemo(() => {
|
|
3111
|
+
const stopsStr = stops.map((s) => `${s.color} ${s.offset}%`).join(", ");
|
|
3112
|
+
switch (value.type) {
|
|
3113
|
+
case "linear": return `linear-gradient(${value.angle}deg, ${stopsStr})`;
|
|
3114
|
+
case "radial": return `radial-gradient(circle, ${stopsStr})`;
|
|
3115
|
+
case "angular": return `conic-gradient(from ${value.angle}deg, ${stopsStr})`;
|
|
3116
|
+
case "diamond": return `radial-gradient(circle, ${stopsStr})`;
|
|
3117
|
+
default: return `linear-gradient(${value.angle}deg, ${stopsStr})`;
|
|
3118
|
+
}
|
|
3119
|
+
}, [value, stops]);
|
|
3120
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3121
|
+
className: clsx("univer-flex univer-w-64 univer-flex-col univer-gap-4 univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-bg-gray-800", className),
|
|
3122
|
+
children: [
|
|
3123
|
+
/* @__PURE__ */ jsx(Segmented, {
|
|
3124
|
+
items: [
|
|
3125
|
+
{
|
|
3126
|
+
label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.linear,
|
|
3127
|
+
value: "linear"
|
|
3128
|
+
},
|
|
3129
|
+
{
|
|
3130
|
+
label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.radial,
|
|
3131
|
+
value: "radial"
|
|
3132
|
+
},
|
|
3133
|
+
{
|
|
3134
|
+
label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.angular,
|
|
3135
|
+
value: "angular"
|
|
3136
|
+
},
|
|
3137
|
+
{
|
|
3138
|
+
label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.diamond,
|
|
3139
|
+
value: "diamond"
|
|
3140
|
+
}
|
|
3141
|
+
],
|
|
3142
|
+
value: value.type,
|
|
3143
|
+
onChange: (v) => handleTypeChange(v)
|
|
3144
|
+
}),
|
|
3145
|
+
/* @__PURE__ */ jsx("div", {
|
|
3146
|
+
className: "univer-h-32 univer-w-full univer-rounded-md univer-border univer-border-gray-200 dark:!univer-border-gray-600",
|
|
3147
|
+
style: { background: mainPreview }
|
|
3148
|
+
}),
|
|
3149
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3150
|
+
className: "univer-relative univer-mt-4 univer-h-6",
|
|
3151
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
3152
|
+
ref: barRef,
|
|
3153
|
+
className: "univer-absolute univer-inset-x-0 univer-top-1/2 univer-h-2 -univer-translate-y-1/2 univer-cursor-crosshair univer-rounded-full",
|
|
3154
|
+
style: { background: gradientPreview },
|
|
3155
|
+
onClick: handleAddStop
|
|
3156
|
+
}), value.stops.map((stop, index) => /* @__PURE__ */ jsx("div", {
|
|
3157
|
+
className: clsx("univer-absolute univer-top-1/2 univer-size-4 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-cursor-pointer univer-rounded-full univer-border-2 univer-border-white univer-shadow-md", selectedIndex === index ? "univer-z-10 univer-ring-2 univer-ring-primary-500" : "univer-z-0"),
|
|
3158
|
+
style: {
|
|
3159
|
+
left: `${stop.offset}%`,
|
|
3160
|
+
backgroundColor: stop.color
|
|
3161
|
+
},
|
|
3162
|
+
onClick: (e) => {
|
|
3163
|
+
e.stopPropagation();
|
|
3164
|
+
setSelectedIndex(index);
|
|
3165
|
+
},
|
|
3166
|
+
onPointerDown: (e) => {
|
|
3167
|
+
const startX = e.clientX;
|
|
3168
|
+
const startOffset = stop.offset;
|
|
3169
|
+
const handlePointerMove = (moveEvent) => {
|
|
3170
|
+
if (!barRef.current) return;
|
|
3171
|
+
const rect = barRef.current.getBoundingClientRect();
|
|
3172
|
+
const deltaOffset = (moveEvent.clientX - startX) / rect.width * 100;
|
|
3173
|
+
const newOffset = Math.max(0, Math.min(100, Math.round(startOffset + deltaOffset)));
|
|
3174
|
+
const newStops = [...value.stops];
|
|
3175
|
+
newStops[index] = {
|
|
3176
|
+
...newStops[index],
|
|
3177
|
+
offset: newOffset
|
|
3178
|
+
};
|
|
3179
|
+
onChange === null || onChange === void 0 || onChange({
|
|
3180
|
+
...value,
|
|
3181
|
+
stops: newStops
|
|
3182
|
+
});
|
|
3183
|
+
};
|
|
3184
|
+
const handlePointerUp = () => {
|
|
3185
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
3186
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
3187
|
+
};
|
|
3188
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
3189
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
3190
|
+
}
|
|
3191
|
+
}, index))]
|
|
3192
|
+
}),
|
|
3193
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3194
|
+
className: "univer-flex univer-items-end univer-gap-2",
|
|
3195
|
+
children: [
|
|
3196
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3197
|
+
className: "univer-flex-1",
|
|
3198
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
3199
|
+
className: "univer-mb-1 univer-text-xs univer-text-gray-500",
|
|
3200
|
+
children: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.offset
|
|
3201
|
+
}), /* @__PURE__ */ jsx(InputNumber, {
|
|
3202
|
+
value: (_value$stops$selected = value.stops[selectedIndex]) === null || _value$stops$selected === void 0 ? void 0 : _value$stops$selected.offset,
|
|
3203
|
+
min: 0,
|
|
3204
|
+
max: 100,
|
|
3205
|
+
onChange: handleStopOffsetChange
|
|
3206
|
+
})]
|
|
3207
|
+
}),
|
|
3208
|
+
(value.type === "linear" || value.type === "angular") && /* @__PURE__ */ jsxs("div", {
|
|
3209
|
+
className: "univer-flex-1",
|
|
3210
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
3211
|
+
className: "univer-mb-1 univer-text-xs univer-text-gray-500",
|
|
3212
|
+
children: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.angle
|
|
3213
|
+
}), /* @__PURE__ */ jsx(InputNumber, {
|
|
3214
|
+
value: value.angle,
|
|
3215
|
+
min: 0,
|
|
3216
|
+
max: 360,
|
|
3217
|
+
onChange: handleAngleChange
|
|
3218
|
+
})]
|
|
3219
|
+
}),
|
|
3220
|
+
/* @__PURE__ */ jsx("div", {
|
|
3221
|
+
className: "univer-flex univer-gap-1",
|
|
3222
|
+
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
3223
|
+
title: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.delete,
|
|
3224
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
3225
|
+
variant: "danger",
|
|
3226
|
+
onClick: handleRemoveStop,
|
|
3227
|
+
disabled: value.stops.length <= 2,
|
|
3228
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
3229
|
+
})
|
|
3230
|
+
})
|
|
3231
|
+
})
|
|
3232
|
+
]
|
|
3233
|
+
}),
|
|
3234
|
+
/* @__PURE__ */ jsx("div", {
|
|
3235
|
+
className: "univer-border-t univer-border-gray-100 univer-pt-4 dark:!univer-border-gray-700",
|
|
3236
|
+
children: /* @__PURE__ */ jsx(ColorPicker, {
|
|
3237
|
+
value: (_value$stops$selected2 = value.stops[selectedIndex]) === null || _value$stops$selected2 === void 0 ? void 0 : _value$stops$selected2.color,
|
|
3238
|
+
onChange: handleStopColorChange
|
|
3239
|
+
})
|
|
3240
|
+
})
|
|
3241
|
+
]
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
//#endregion
|
|
3246
|
+
//#region src/components/hover-card/HoverCardPrimitive.tsx
|
|
3247
|
+
const HoverCardPrimitive = Root$3;
|
|
3248
|
+
const HoverCardPortal = Portal$3;
|
|
3249
|
+
const HoverCardTrigger = Trigger$2;
|
|
3250
|
+
const HoverCardContent = forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(Content$3, {
|
|
3251
|
+
ref,
|
|
3252
|
+
align,
|
|
3253
|
+
sideOffset,
|
|
3254
|
+
className: clsx("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-w-64 univer-origin-[--radix-hover-card-content-transform-origin] univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900 dark:!univer-text-white", borderClassName, className),
|
|
3255
|
+
...props
|
|
3256
|
+
}));
|
|
3257
|
+
HoverCardContent.displayName = Content$3.displayName;
|
|
3258
|
+
|
|
3259
|
+
//#endregion
|
|
3260
|
+
//#region src/components/hover-card/HoverCard.tsx
|
|
3261
|
+
function HoverCard(props) {
|
|
3262
|
+
const { children, overlay, disabled, openDelay = 200, open: controlledOpen, onOpenChange: controlledOnOpenChange, ...restProps } = props;
|
|
3263
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
3264
|
+
const isControlled = controlledOpen !== void 0;
|
|
3265
|
+
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
3266
|
+
function handleChangeOpen(newOpen) {
|
|
3267
|
+
if (disabled) return;
|
|
3268
|
+
if (!isControlled) setUncontrolledOpen(newOpen);
|
|
3269
|
+
controlledOnOpenChange === null || controlledOnOpenChange === void 0 || controlledOnOpenChange(newOpen);
|
|
3270
|
+
}
|
|
3271
|
+
return /* @__PURE__ */ jsxs(HoverCardPrimitive, {
|
|
3272
|
+
open,
|
|
3273
|
+
onOpenChange: handleChangeOpen,
|
|
3274
|
+
openDelay,
|
|
3275
|
+
children: [/* @__PURE__ */ jsx(HoverCardTrigger, {
|
|
3276
|
+
asChild: true,
|
|
3277
|
+
children
|
|
3278
|
+
}), /* @__PURE__ */ jsx(HoverCardPortal, { children: /* @__PURE__ */ jsx(HoverCardContent, {
|
|
3279
|
+
...restProps,
|
|
3280
|
+
children: overlay
|
|
3281
|
+
}) })]
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
//#endregion
|
|
3286
|
+
//#region src/components/kbd/Kbd.tsx
|
|
3287
|
+
/**
|
|
3288
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3289
|
+
*
|
|
3290
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3291
|
+
* you may not use this file except in compliance with the License.
|
|
3292
|
+
* You may obtain a copy of the License at
|
|
3293
|
+
*
|
|
3294
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3295
|
+
*
|
|
3296
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3297
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3298
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3299
|
+
* See the License for the specific language governing permissions and
|
|
3300
|
+
* limitations under the License.
|
|
3301
|
+
*/
|
|
3302
|
+
function KBD(props) {
|
|
3303
|
+
const { keyboard, className } = props;
|
|
3304
|
+
const keys = keyboard.split("+");
|
|
3305
|
+
return /* @__PURE__ */ jsx("span", {
|
|
3306
|
+
className: clsx("univer-inline-block univer-h-6 univer-select-none univer-whitespace-nowrap univer-rounded-md univer-bg-gray-50 univer-px-2 univer-font-mono univer-text-xs/6 univer-font-medium univer-text-gray-700 dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName, className),
|
|
3307
|
+
children: keys.map((text, index) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("kbd", {
|
|
3308
|
+
className: "univer-inline-block univer-h-full",
|
|
3309
|
+
children: text
|
|
3310
|
+
}), index < keys.length - 1 && /* @__PURE__ */ jsx("span", {
|
|
3311
|
+
className: "univer-inline-block univer-h-full univer-px-1",
|
|
3312
|
+
children: "+"
|
|
3313
|
+
})] }, index))
|
|
3314
|
+
});
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
//#endregion
|
|
3318
|
+
//#region src/components/message/Message.tsx
|
|
3319
|
+
let MessageType = /* @__PURE__ */ function(MessageType) {
|
|
3320
|
+
MessageType["Success"] = "success";
|
|
3321
|
+
MessageType["Info"] = "info";
|
|
3322
|
+
MessageType["Warning"] = "warning";
|
|
3323
|
+
MessageType["Error"] = "error";
|
|
3324
|
+
MessageType["Loading"] = "loading";
|
|
3325
|
+
return MessageType;
|
|
3326
|
+
}({});
|
|
3327
|
+
const MESSAGE_TOASTER_ID = "univer-message-toaster";
|
|
3328
|
+
const DEFAULT_MESSAGE_DURATION = 3e3;
|
|
3329
|
+
const activeMessageIds = /* @__PURE__ */ new Set();
|
|
3330
|
+
const loadingIcon = /* @__PURE__ */ jsx(LoadingMultiIcon, { className: "univer-animate-spin univer-text-violet-500" });
|
|
3331
|
+
let messageCount = 0;
|
|
3332
|
+
const iconMap = {
|
|
3333
|
+
[MessageType.Success]: /* @__PURE__ */ jsx(SuccessIcon, { className: "univer-text-green-500" }),
|
|
3334
|
+
[MessageType.Info]: /* @__PURE__ */ jsx(InfoIcon, { className: "univer-text-sky-500 dark:!univer-text-sky-400" }),
|
|
3335
|
+
[MessageType.Warning]: /* @__PURE__ */ jsx(WarningIcon, { className: "univer-text-amber-500" }),
|
|
3336
|
+
[MessageType.Error]: /* @__PURE__ */ jsx(ErrorIcon, { className: "univer-text-red-500" }),
|
|
3337
|
+
[MessageType.Loading]: loadingIcon
|
|
3338
|
+
};
|
|
3339
|
+
const typeClassMap = {
|
|
3340
|
+
[MessageType.Success]: "[&_[data-icon]]:univer-text-green-500",
|
|
3341
|
+
[MessageType.Info]: "[&_[data-icon]]:univer-text-sky-500",
|
|
3342
|
+
[MessageType.Warning]: "[&_[data-icon]]:univer-text-amber-500",
|
|
3343
|
+
[MessageType.Error]: "[&_[data-icon]]:univer-text-red-500",
|
|
3344
|
+
[MessageType.Loading]: "[&_[data-icon]]:univer-text-violet-500"
|
|
3345
|
+
};
|
|
3346
|
+
const resolveToastMethod = (type) => {
|
|
3347
|
+
switch (type) {
|
|
3348
|
+
case MessageType.Success: return toast$1.success;
|
|
3349
|
+
case MessageType.Warning: return toast$1.warning;
|
|
3350
|
+
case MessageType.Error: return toast$1.error;
|
|
3351
|
+
case MessageType.Loading: return toast$1.loading;
|
|
3352
|
+
case MessageType.Info:
|
|
3353
|
+
default: return toast$1.info;
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3356
|
+
const createMessageId = () => {
|
|
3357
|
+
const id = `univer-message-${messageCount}`;
|
|
3358
|
+
messageCount += 1;
|
|
3359
|
+
return id;
|
|
3360
|
+
};
|
|
3361
|
+
const Messager = ({ className, ...props }) => /* @__PURE__ */ jsx(Toaster$1, {
|
|
3362
|
+
id: MESSAGE_TOASTER_ID,
|
|
3363
|
+
position: "top-center",
|
|
3364
|
+
visibleToasts: 4,
|
|
3365
|
+
closeButton: false,
|
|
3366
|
+
expand: false,
|
|
3367
|
+
icons: { loading: loadingIcon },
|
|
3368
|
+
offset: { top: 16 },
|
|
3369
|
+
className: clsx("[&_[data-sonner-toast]]:univer-bg-white/95 dark:[&_[data-sonner-toast]]:!univer-bg-gray-800/95 [&_[data-sonner-toast]]:univer-rounded-2xl [&_[data-sonner-toast]]:univer-border [&_[data-sonner-toast]]:univer-border-solid [&_[data-sonner-toast]]:univer-border-gray-200 [&_[data-sonner-toast]]:univer-shadow-[0_16px_40px_-20px_rgba(15,23,42,0.55)] [&_[data-sonner-toast]]:univer-backdrop-blur-sm dark:[&_[data-sonner-toast]]:!univer-border-gray-600", className),
|
|
3370
|
+
toastOptions: {
|
|
3371
|
+
duration: DEFAULT_MESSAGE_DURATION,
|
|
3372
|
+
classNames: {
|
|
3373
|
+
toast: `
|
|
73
3374
|
univer-group univer-min-h-0 univer-min-w-[320px] univer-max-w-[520px] univer-px-3.5 univer-py-3
|
|
74
3375
|
univer-font-sans univer-transition-all univer-duration-300
|
|
75
|
-
`,
|
|
3376
|
+
`,
|
|
3377
|
+
title: `
|
|
76
3378
|
univer-m-0 univer-font-sans univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-700
|
|
77
3379
|
dark:!univer-text-gray-100
|
|
78
|
-
`,content:`univer-gap-2.5`,icon:`[&>svg]:univer-block [&>svg]:univer-size-4`,success:Dn[Q.Success],info:Dn[Q.Info],warning:Dn[Q.Warning],error:Dn[Q.Error],loading:Dn[Q.Loading]}},...t}),jn=({content:e,duration:t,id:n,onClose:r,type:i=Q.Info})=>{let a=n==null?kn():n,o=On(i),s=!1,c=()=>{s||(s=!0,$.delete(a),r==null||r())};return o(e,{id:a,toasterId:Sn,duration:t==null?Cn:t,icon:i===Q.Loading?void 0:En[i],onDismiss:c,onAutoClose:c}),$.add(a),a},Mn=e=>{if(e!==void 0){U.dismiss(e),$.delete(e);return}$.forEach(e=>{U.dismiss(e)}),$.clear()},Nn=[-9999,-9999];function Pn(e){let{children:t,visible:n=!1,offset:r=[0,0],overflowVisible:i=!1,placementY:a=`below`}=e,o=j(null),[s,c]=M(Nn),{mountContainer:l}=E(K),u=()=>{let e=o.current;if(!e)return null;let[t,n]=r,{clientWidth:i,clientHeight:s}=e,{innerWidth:c,innerHeight:l}=window,u=Math.max(0,c-i-2),d=Math.max(0,l-s-2),f=Math.min(Math.max(t,0),u),p=a===`above`?n-s:n;return[f,Math.min(Math.max(p,0),d)]};k(()=>{if(!n){c(Nn);return}let e=u();e&&c(e)},[r,a,n]),D(()=>{if(!n)return;let e=()=>{let e=u();e&&c(e)};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[r,a,n]);function d(e){e.preventDefault()}return ce(I(Oe,{in:n,nodeRef:o,timeout:500,classNames:{enter:`univer-popup-enter`,enterActive:`univer-popup-enter-active`,enterDone:`univer-popup-enter-done`,exitActive:`univer-popup-exit`,exitDone:`univer-popup-exit-active`},children:I(`section`,{ref:o,className:`univer-popup`,style:{left:s[0]+2,top:s[1]+2,overflow:i?`visible`:void 0},onContextMenu:d,children:t})}),l)}function Fn(e){let{children:t,className:n,style:r,value:i,disabled:a=!1,direction:o=`horizontal`,onChange:s}=e,c=e=>{s(e)};return I(`div`,{className:W(`univer-flex univer-gap-2`,{"univer-flex-col":o===`vertical`},n),style:r,children:y.map(t,(e,t)=>C(e)?b(e,{key:t,children:e.props.children,value:e.props.value,checked:i===e.props.value,disabled:a==null?e.props.disabled:a,onChange:c}):e)})}function In(e){let{children:t,checked:n,value:r,disabled:i=!1,onChange:a}=e,o=j(null);function s(e){if(e.stopPropagation(),!(!a||i))if(r!==void 0)a&&a(r);else{let e=o.current.checked;a&&a(e)}}return L(`label`,{"data-u-comp":`radio`,className:W(`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm`,{"univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white":!i,"univer-text-gray-400":i}),children:[L(`span`,{className:`univer-relative univer-block`,children:[I(`input`,{ref:o,className:`univer-absolute univer-size-0 univer-opacity-0`,type:`radio`,checked:n,disabled:i,onChange:s}),I(`span`,{className:W(`univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded-full univer-border univer-border-solid univer-transition-colors`,{"univer-opacity-50":i,"univer-border-primary-600 univer-bg-primary-600 dark:!univer-bg-primary-600":n,"univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600":!n}),children:n&&I(`span`,{className:`univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-2 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded-full univer-bg-white`})})]}),I(`span`,{children:t})]})}function Ln(e){let{value:n,options:r=[],hideCheckMark:i=!1,onChange:a,multiple:o,className:s,optionClassName:c}=e,l=Array.isArray(n)?n:[n];function u(e){let t=l.indexOf(e);a(o?t>-1?l.filter(t=>t===e):[...l,e]:t>-1?void 0:e)}return I(`ul`,{className:W(`univer-m-0 univer-grid univer-max-h-80 univer-list-none univer-gap-1 univer-overflow-y-auto univer-rounded univer-p-1.5`,Y,q,s),children:r.map((e,n)=>{let r=l.indexOf(e.value)>-1;return I(`li`,{children:L(`a`,{className:W(`univer-relative univer-block univer-cursor-pointer univer-select-none univer-rounded univer-py-1.5 univer-pl-8 univer-pr-2 univer-text-sm univer-text-gray-900 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,c,{"univer-bg-gray-200 dark:!univer-bg-gray-500":r}),onClick:()=>u(e.value),children:[!i&&r&&I(t,{className:`univer-absolute univer-left-0 univer-top-1/2 -univer-translate-y-1/2 univer-pl-2 univer-text-primary-600`}),I(`span`,{style:{color:e.color},children:e.label})]})},n)})})}const Rn=W(`univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-white`,Y);function zn(e){let{className:t,value:n,disabled:r=!1,options:i=[],borderless:a=!1,onChange:o}=e,[s,c]=M(!1);function l(e){c(e)}let d=A(()=>{let e=[];for(let t of i)t.options?(t.options.forEach(t=>{e.push({label:t.label,value:t.value,disabled:t.disabled})}),e.push({type:`separator`})):e.push({label:t.label,value:t.value,disabled:t.disabled});return[{type:`radio`,value:n,hideIndicator:!0,options:e,onSelect:e=>{o(e)}}]},[i]),f=A(()=>{let e=null;for(let t of i)if(t.options){for(let r of t.options)if(r.value===n){e=r.label;break}}else if(t.value===n){e=t.label;break}return e||n},[i,n]);return I(tn,{className:`max-h univer-w-[--radix-popper-anchor-width] univer-min-w-36`,align:`start`,open:s,items:d,disabled:r,onOpenChange:l,children:L(`div`,{"data-u-comp":`select`,className:W(Rn,{"univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900":s&&!a,"univer-border-transparent univer-bg-transparent hover:univer-border-transparent":a,"univer-cursor-not-allowed":r,"hover:univer-border-primary-600":!r&&!a,"univer-cursor-pointer":!r&&!s},t),children:[I(`div`,{className:`univer-flex-1 univer-truncate univer-text-sm univer-text-gray-500 dark:!univer-text-white`,children:f}),I(u,{className:`univer-flex-shrink-0 dark:!univer-text-white`})]})})}function Bn(e){let{className:t,value:n=[],disabled:r=!1,options:i=[],borderless:a=!1,onChange:o}=e,[s,c]=M(!1);function l(e){c(e)}let d=A(()=>i.map(e=>({type:`checkbox`,value:e.value,label:e.label,disabled:e.disabled,checked:n.includes(e.value),onSelect:e=>{o(n.includes(e)?n.filter(t=>t!==e):[...n,e])}})),[i]);function f(e){o(n.filter(t=>t!==e))}let p=A(()=>i.filter(e=>n.includes(e.value)).map((e,t)=>I(Pe,{className:`univer-max-w-32`,closable:!0,onClose:()=>f(e.value),children:e.label},t)),[i,n]);return I(tn,{className:`univer-w-[--radix-popper-anchor-width] univer-min-w-36`,align:`start`,open:s,items:d,disabled:r,onOpenChange:l,children:L(`div`,{"data-u-comp":`multiple-select`,className:W(Rn,{"univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900":s&&!a,"univer-border-transparent univer-bg-transparent hover:univer-border-transparent":a,"univer-cursor-not-allowed":r,"hover:univer-border-primary-600":!r&&!a,"univer-cursor-pointer":!r&&!s},t),children:[I(`div`,{className:`univer-box-border univer-flex univer-w-[calc(100%-16px)] univer-gap-2 univer-pr-2`,children:p}),I(u,{className:`univer-flex-shrink-0 dark:!univer-text-white`})]})})}function Vn({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return I(ke,{"data-u-comp":`separator`,"data-slot":`separator-root`,decorative:n,orientation:t,className:W(`univer-shrink-0 univer-bg-gray-200 data-[orientation=horizontal]:univer-h-px data-[orientation=vertical]:univer-h-full data-[orientation=horizontal]:univer-w-full data-[orientation=vertical]:univer-w-px dark:!univer-bg-gray-600`,e),...r})}const Hn=e=>{let{defaultChecked:t=!1,onChange:n}=e,[r,i]=M(t);return D(()=>{i(t)},[t]),I(`div`,{className:`univer-h-4`,children:L(`label`,{className:`univer-relative univer-inline-block univer-h-4 univer-w-7`,children:[I(`input`,{className:`univer-size-0 univer-opacity-0`,type:`checkbox`,checked:r,onChange:()=>{i(!r),n==null||n(!r)}}),I(`span`,{className:W(`univer-absolute univer-inset-0 univer-cursor-pointer univer-rounded-2xl univer-transition-colors univer-duration-200`,{"univer-bg-primary-600":r,"univer-bg-gray-200 dark:!univer-bg-gray-600":!r}),children:I(`span`,{className:W(`univer-absolute univer-bottom-0.5 univer-left-0.5 univer-size-3 univer-rounded-full univer-bg-white univer-transition-transform univer-duration-200`,{"univer-translate-x-3":r})})})]})})},Un=S((e,t)=>{let n=j(null),r=j({width:0,height:0}),{className:i,onResize:a,onValueChange:o,...s}=e;O(t,()=>n.current,[]),k(()=>{let e=n.current;if(e&&a){let t=new ResizeObserver(e=>{let{width:t,height:n}=e[0].target.getBoundingClientRect();t===0||n===0||(r.current.width!==t||r.current.height!==n)&&(r.current={width:t,height:n},a(t,n))});return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}},[a]);function c(e){let t=e.target.value;o==null||o(t)}return I(`textarea`,{ref:n,"data-u-comp":`textarea`,"data-slot":`textarea`,className:W(`univer-box-border univer-flex univer-w-full univer-resize univer-rounded-md univer-bg-transparent univer-p-2 univer-text-base univer-text-gray-900 univer-outline-none univer-transition-[color,box-shadow] placeholder:univer-text-gray-200 disabled:univer-cursor-not-allowed disabled:univer-opacity-50 dark:!univer-text-white`,Y,q,i),onChange:c,...s})});function Wn({visibleToasts:e,...t}){return I(Ee,{className:`dark:![&_[data-description]]:univer-text-gray-200 [&_[data-description]]:univer-text-sm [&_[data-description]]:univer-text-gray-600 [&_[data-icon]>svg]:univer-relative [&_[data-icon]>svg]:univer-top-1 [&_[data-icon]]:univer-self-baseline [&_[data-sonner-toast]]:univer-shadow-md [&_[data-title]]:univer-text-sm [&_[data-title]]:univer-text-gray-900`,toastOptions:{classNames:{content:`univer-leading-normal`,success:`[&_[data-icon]]:univer-text-green-500`,info:`[&_[data-icon]]:univer-text-primary-600`,error:`[&_[data-icon]]:univer-text-red-500`,warning:`[&_[data-icon]]:univer-text-yellow-500`}},visibleToasts:e==null?5:e,...t})}function Gn(e){let{data:t,itemKey:n,children:r,height:i,itemHeight:a,overscan:o=2,className:s,style:c}=e,[l,u]=M(0);if(!i||!a||a<=0)return I(`div`,{className:s,style:c,children:t.map((e,t)=>{let i=typeof n==`function`?n(e):e[n];return I(`div`,{children:r(e,t)},i)})});let d=Math.max(0,Math.floor(l/a)-o),f=Math.ceil(i/a)+o*2,p=Math.min(t.length,d+f),m=d*a,h=t.length*a,g=t.slice(d,p);return I(`div`,{className:s,style:{...c,height:i,overflowY:`auto`},onScroll:e=>u(e.currentTarget.scrollTop),children:I(`div`,{style:{height:h,position:`relative`},children:I(`div`,{style:{transform:`translateY(${m}px)`},children:g.map((e,t)=>{let i=typeof n==`function`?n(e):e[n];return I(`div`,{children:r(e,d+t)},i)})})})})}const Kn=(e,t)=>{let n=[],r=e=>{var i;if(n.push(e.key),t===e.key||(i=e.children)!=null&&i.length&&e.children.some(r))return!0;n.pop()};return e.some(r),n},qn=(e,t)=>{let n=t==null?new Map:t,r=e;return{findNodePathFromTreeWithCache:e=>{let t=n.get(e);if(t)return t;let i=Kn(r,e);return i.map((e,t,n)=>{let r=[];for(let e=0;e<=t;e++)r.push(n[e]);return r}).reverse().forEach(e=>{let t=e[e.length-1];n.set(t,e)}),i},reset:e=>{n.clear(),e&&(r=e)}}},Jn=(e,t)=>t.length?t.reduce((e,t)=>{let n=e.find(e=>e.key===t);return(n==null?void 0:n.children)||[]},e):e,Yn=(e,t)=>{let n=t.slice(0),r=n.pop();return Jn(e,n).find(e=>e.key===r)},Xn=(e,t,n)=>{let r=new Set(t),i=n[n.length-1],a=Jn(e,n);if(r.has(i)){if(a.length){let e=t=>{r.delete(t.key),t.children&&t.children.forEach(t=>e(t))};a.forEach(e)}n.map((e,t,n)=>{let r=[];for(let e=0;e<=t;e++)r.push(n[e]);return r}).reverse().some(t=>{let n=Jn(e,t),i=t[t.length-1];if(n.every(e=>!r.has(e.key)))r.delete(i);else return!0;return!1})}else{let e=t=>{r.add(t.key),t.children&&t.children.forEach(t=>e(t))};n.forEach(e=>r.add(e)),a.length&&a.forEach(e)}return[...r]},Zn=(e,t)=>{let n=t.children||[],r=t=>{var n;return(n=t.children)!=null&&n.length?!!t.children.every(r):e.has(t.key)};return n.length?n.some(e=>!r(e)):!1},Qn=(e,t)=>{let n=[],r=qn(e);return t.forEach(t=>{let i=Yn(e,r.findNodePathFromTreeWithCache(t));if(i){var a;(a=i.children)!=null&&a.length||n.push(i)}}),n};let $n=function(e){return e[e.ONLY_LEAF_NODE=0]=`ONLY_LEAF_NODE`,e[e.ALL=1]=`ALL`,e}({});function er(e,t,n=1){let r=[];return e.forEach(e=>{r.push({...e,level:n}),e.children&&t.has(e.key)&&r.push(...er(e.children,t,n+1))}),r}function tr(e){let{data:t=[],defaultCache:n,style:r,defaultExpandAll:i=!1,selectionMode:a=$n.ALL,valueGroup:s=[],onChange:c,onExpend:l,height:u=200,itemHeight:d=32,attachRender:f}=e,[p,m]=M({}),h=A(()=>new Set,[]),g=A(()=>qn(t,n),[t,n]),_=A(()=>{let e=new Set;return s.forEach(t=>{g.findNodePathFromTreeWithCache(t).forEach(t=>e.add(t))}),e},[s,g]);D(()=>{function e(t){var n;h.add(t.key),(n=t.children)==null||n.forEach(e)}i&&t.forEach(e),m({})},[i,t]);let v=A(()=>er(t,h),[t,p,h]);function y(e){var t;(t=e.children)!=null&&t.length&&(h.has(e.key)?h.delete(e.key):h.add(e.key),m({})),!(a===$n.ONLY_LEAF_NODE&&e.children)&&(l==null||l(e.key))}function b(t){let{title:n,key:r,level:i=0}=t,a=e.treeNodeClassName,s=h.has(r),l=_.has(r),u=Zn(_,t);return I(`div`,{className:W(`univer-relative univer-text-[13px]`,a),style:{paddingLeft:`${i*20}px`},children:L(`div`,{className:`univer-relative univer-my-1 univer-flex univer-w-full univer-items-center`,children:[t.children&&t.children.length>0&&I(`span`,{className:W(`univer-absolute univer-left-[-16px] univer-top-1/2 univer-flex univer--translate-y-1/2 univer-items-center univer-justify-center univer-text-[8px]`,{"univer-rotate-[-90deg]":!s}),onClick:e=>{e.stopPropagation(),y(t)},children:I(o,{})}),I(nt,{checked:l&&!u,indeterminate:l&&u,onChange:()=>{c==null||c(t)}}),I(`div`,{className:`
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
3380
|
+
`,
|
|
3381
|
+
content: "univer-gap-2.5",
|
|
3382
|
+
icon: "[&>svg]:univer-block [&>svg]:univer-size-4",
|
|
3383
|
+
success: typeClassMap[MessageType.Success],
|
|
3384
|
+
info: typeClassMap[MessageType.Info],
|
|
3385
|
+
warning: typeClassMap[MessageType.Warning],
|
|
3386
|
+
error: typeClassMap[MessageType.Error],
|
|
3387
|
+
loading: typeClassMap[MessageType.Loading]
|
|
3388
|
+
}
|
|
3389
|
+
},
|
|
3390
|
+
...props
|
|
3391
|
+
});
|
|
3392
|
+
const message = ({ content, duration, id, onClose, type = MessageType.Info }) => {
|
|
3393
|
+
const messageId = id !== null && id !== void 0 ? id : createMessageId();
|
|
3394
|
+
const method = resolveToastMethod(type);
|
|
3395
|
+
let closed = false;
|
|
3396
|
+
const handleClose = () => {
|
|
3397
|
+
if (closed) return;
|
|
3398
|
+
closed = true;
|
|
3399
|
+
activeMessageIds.delete(messageId);
|
|
3400
|
+
onClose === null || onClose === void 0 || onClose();
|
|
3401
|
+
};
|
|
3402
|
+
method(content, {
|
|
3403
|
+
id: messageId,
|
|
3404
|
+
toasterId: MESSAGE_TOASTER_ID,
|
|
3405
|
+
duration: duration !== null && duration !== void 0 ? duration : DEFAULT_MESSAGE_DURATION,
|
|
3406
|
+
icon: type === MessageType.Loading ? void 0 : iconMap[type],
|
|
3407
|
+
onDismiss: handleClose,
|
|
3408
|
+
onAutoClose: handleClose
|
|
3409
|
+
});
|
|
3410
|
+
activeMessageIds.add(messageId);
|
|
3411
|
+
return messageId;
|
|
3412
|
+
};
|
|
3413
|
+
const removeMessage = (id) => {
|
|
3414
|
+
if (typeof id !== "undefined") {
|
|
3415
|
+
toast$1.dismiss(id);
|
|
3416
|
+
activeMessageIds.delete(id);
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
activeMessageIds.forEach((messageId) => {
|
|
3420
|
+
toast$1.dismiss(messageId);
|
|
3421
|
+
});
|
|
3422
|
+
activeMessageIds.clear();
|
|
3423
|
+
};
|
|
3424
|
+
|
|
3425
|
+
//#endregion
|
|
3426
|
+
//#region src/components/popup/Popup.tsx
|
|
3427
|
+
const POPUP_POINTER_OFFSET = 2;
|
|
3428
|
+
const HIDDEN_POPUP_OFFSET = [-9999, -9999];
|
|
3429
|
+
function Popup(props) {
|
|
3430
|
+
const { children, visible = false, offset = [0, 0], overflowVisible = false, placementY = "below" } = props;
|
|
3431
|
+
const nodeRef = useRef(null);
|
|
3432
|
+
const [realOffset, setRealOffset] = useState(HIDDEN_POPUP_OFFSET);
|
|
3433
|
+
const { mountContainer } = useContext(ConfigContext);
|
|
3434
|
+
const calculateOffset = () => {
|
|
3435
|
+
const element = nodeRef.current;
|
|
3436
|
+
if (!element) return null;
|
|
3437
|
+
const [left, top] = offset;
|
|
3438
|
+
const { clientWidth, clientHeight } = element;
|
|
3439
|
+
const { innerWidth, innerHeight } = window;
|
|
3440
|
+
const maxX = Math.max(0, innerWidth - clientWidth - POPUP_POINTER_OFFSET);
|
|
3441
|
+
const maxY = Math.max(0, innerHeight - clientHeight - POPUP_POINTER_OFFSET);
|
|
3442
|
+
const x = Math.min(Math.max(left, 0), maxX);
|
|
3443
|
+
const topWithPlacement = placementY === "above" ? top - clientHeight : top;
|
|
3444
|
+
return [x, Math.min(Math.max(topWithPlacement, 0), maxY)];
|
|
3445
|
+
};
|
|
3446
|
+
useLayoutEffect(() => {
|
|
3447
|
+
if (!visible) {
|
|
3448
|
+
setRealOffset(HIDDEN_POPUP_OFFSET);
|
|
3449
|
+
return;
|
|
3450
|
+
}
|
|
3451
|
+
const nextOffset = calculateOffset();
|
|
3452
|
+
if (nextOffset) setRealOffset(nextOffset);
|
|
3453
|
+
}, [
|
|
3454
|
+
offset,
|
|
3455
|
+
placementY,
|
|
3456
|
+
visible
|
|
3457
|
+
]);
|
|
3458
|
+
useEffect(() => {
|
|
3459
|
+
if (!visible) return;
|
|
3460
|
+
const handleResize = () => {
|
|
3461
|
+
const nextOffset = calculateOffset();
|
|
3462
|
+
if (nextOffset) setRealOffset(nextOffset);
|
|
3463
|
+
};
|
|
3464
|
+
window.addEventListener("resize", handleResize);
|
|
3465
|
+
return () => {
|
|
3466
|
+
window.removeEventListener("resize", handleResize);
|
|
3467
|
+
};
|
|
3468
|
+
}, [
|
|
3469
|
+
offset,
|
|
3470
|
+
placementY,
|
|
3471
|
+
visible
|
|
3472
|
+
]);
|
|
3473
|
+
function preventDefault(event) {
|
|
3474
|
+
event.preventDefault();
|
|
3475
|
+
}
|
|
3476
|
+
return createPortal(/* @__PURE__ */ jsx(CSSTransition, {
|
|
3477
|
+
in: visible,
|
|
3478
|
+
nodeRef,
|
|
3479
|
+
timeout: 500,
|
|
3480
|
+
classNames: {
|
|
3481
|
+
enter: "univer-popup-enter",
|
|
3482
|
+
enterActive: "univer-popup-enter-active",
|
|
3483
|
+
enterDone: "univer-popup-enter-done",
|
|
3484
|
+
exitActive: "univer-popup-exit",
|
|
3485
|
+
exitDone: "univer-popup-exit-active"
|
|
3486
|
+
},
|
|
3487
|
+
children: /* @__PURE__ */ jsx("section", {
|
|
3488
|
+
ref: nodeRef,
|
|
3489
|
+
className: "univer-popup",
|
|
3490
|
+
style: {
|
|
3491
|
+
left: realOffset[0] + POPUP_POINTER_OFFSET,
|
|
3492
|
+
top: realOffset[1] + POPUP_POINTER_OFFSET,
|
|
3493
|
+
overflow: overflowVisible ? "visible" : void 0
|
|
3494
|
+
},
|
|
3495
|
+
onContextMenu: preventDefault,
|
|
3496
|
+
children
|
|
3497
|
+
})
|
|
3498
|
+
}), mountContainer);
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
//#endregion
|
|
3502
|
+
//#region src/components/radio-group/RadioGroup.tsx
|
|
3503
|
+
/**
|
|
3504
|
+
* RadioGroup Component
|
|
3505
|
+
*/
|
|
3506
|
+
function RadioGroup(props) {
|
|
3507
|
+
const { children, className, style, value, disabled = false, direction = "horizontal", onChange } = props;
|
|
3508
|
+
const handleChange = (value) => {
|
|
3509
|
+
onChange(value);
|
|
3510
|
+
};
|
|
3511
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3512
|
+
className: clsx("univer-flex univer-gap-2", { "univer-flex-col": direction === "vertical" }, className),
|
|
3513
|
+
style,
|
|
3514
|
+
children: Children.map(children, (child, index) => {
|
|
3515
|
+
if (isValidElement(child)) return cloneElement(child, {
|
|
3516
|
+
key: index,
|
|
3517
|
+
children: child.props.children,
|
|
3518
|
+
value: child.props.value,
|
|
3519
|
+
checked: value === child.props.value,
|
|
3520
|
+
disabled: disabled !== null && disabled !== void 0 ? disabled : child.props.disabled,
|
|
3521
|
+
onChange: handleChange
|
|
3522
|
+
});
|
|
3523
|
+
return child;
|
|
3524
|
+
})
|
|
3525
|
+
});
|
|
3526
|
+
}
|
|
3527
|
+
|
|
3528
|
+
//#endregion
|
|
3529
|
+
//#region src/components/radio/Radio.tsx
|
|
3530
|
+
/**
|
|
3531
|
+
* Radio Component
|
|
3532
|
+
*/
|
|
3533
|
+
function Radio(props) {
|
|
3534
|
+
const { children, checked, value, disabled = false, onChange } = props;
|
|
3535
|
+
const inputRef = useRef(null);
|
|
3536
|
+
function handleChange(e) {
|
|
3537
|
+
e.stopPropagation();
|
|
3538
|
+
if (!onChange || disabled) return;
|
|
3539
|
+
if (typeof value !== "undefined") onChange && onChange(value);
|
|
3540
|
+
else {
|
|
3541
|
+
const checked = inputRef.current.checked;
|
|
3542
|
+
onChange && onChange(checked);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
3546
|
+
"data-u-comp": "radio",
|
|
3547
|
+
className: clsx("univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm", {
|
|
3548
|
+
"univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white": !disabled,
|
|
3549
|
+
"univer-text-gray-400": disabled
|
|
3550
|
+
}),
|
|
3551
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
3552
|
+
className: "univer-relative univer-block",
|
|
3553
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
3554
|
+
ref: inputRef,
|
|
3555
|
+
className: "univer-absolute univer-size-0 univer-opacity-0",
|
|
3556
|
+
type: "radio",
|
|
3557
|
+
checked,
|
|
3558
|
+
disabled,
|
|
3559
|
+
onChange: handleChange
|
|
3560
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
3561
|
+
className: clsx("univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded-full univer-border univer-border-solid univer-transition-colors", {
|
|
3562
|
+
"univer-opacity-50": disabled,
|
|
3563
|
+
"univer-border-primary-600 univer-bg-primary-600 dark:!univer-bg-primary-600": checked,
|
|
3564
|
+
"univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600": !checked
|
|
3565
|
+
}),
|
|
3566
|
+
children: checked && /* @__PURE__ */ jsx("span", { className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-2 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded-full univer-bg-white" })
|
|
3567
|
+
})]
|
|
3568
|
+
}), /* @__PURE__ */ jsx("span", { children })]
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
//#endregion
|
|
3573
|
+
//#region src/components/select-list/SelectList.tsx
|
|
3574
|
+
/**
|
|
3575
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3576
|
+
*
|
|
3577
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3578
|
+
* you may not use this file except in compliance with the License.
|
|
3579
|
+
* You may obtain a copy of the License at
|
|
3580
|
+
*
|
|
3581
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3582
|
+
*
|
|
3583
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3584
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3585
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3586
|
+
* See the License for the specific language governing permissions and
|
|
3587
|
+
* limitations under the License.
|
|
3588
|
+
*/
|
|
3589
|
+
function SelectList(props) {
|
|
3590
|
+
const { value: _value, options = [], hideCheckMark = false, onChange, multiple, className, optionClassName } = props;
|
|
3591
|
+
const value = Array.isArray(_value) ? _value : [_value];
|
|
3592
|
+
function handleSelect(newValue) {
|
|
3593
|
+
const index = value.indexOf(newValue);
|
|
3594
|
+
if (!multiple) if (index > -1) onChange(void 0);
|
|
3595
|
+
else onChange(newValue);
|
|
3596
|
+
else if (index > -1) onChange(value.filter((i) => i === newValue));
|
|
3597
|
+
else onChange([...value, newValue]);
|
|
3598
|
+
}
|
|
3599
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
3600
|
+
className: clsx("univer-m-0 univer-grid univer-max-h-80 univer-list-none univer-gap-1 univer-overflow-y-auto univer-rounded univer-p-1.5", borderClassName, scrollbarClassName, className),
|
|
3601
|
+
children: options.map((option, index) => {
|
|
3602
|
+
const checked = value.indexOf(option.value) > -1;
|
|
3603
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("a", {
|
|
3604
|
+
className: clsx("univer-relative univer-block univer-cursor-pointer univer-select-none univer-rounded univer-py-1.5 univer-pl-8 univer-pr-2 univer-text-sm univer-text-gray-900 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600", optionClassName, { "univer-bg-gray-200 dark:!univer-bg-gray-500": checked }),
|
|
3605
|
+
onClick: () => handleSelect(option.value),
|
|
3606
|
+
children: [!hideCheckMark && checked && /* @__PURE__ */ jsx(CheckMarkIcon, { className: "univer-absolute univer-left-0 univer-top-1/2 -univer-translate-y-1/2 univer-pl-2 univer-text-primary-600" }), /* @__PURE__ */ jsx("span", {
|
|
3607
|
+
style: { color: option.color },
|
|
3608
|
+
children: option.label
|
|
3609
|
+
})]
|
|
3610
|
+
}) }, index);
|
|
3611
|
+
})
|
|
3612
|
+
});
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
//#endregion
|
|
3616
|
+
//#region src/components/select/Select.tsx
|
|
3617
|
+
const selectClassName = clsx("univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName);
|
|
3618
|
+
function Select(props) {
|
|
3619
|
+
const { className, value, disabled = false, options = [], borderless = false, onChange } = props;
|
|
3620
|
+
const [open, setOpen] = useState(false);
|
|
3621
|
+
function handleOpenChange(open) {
|
|
3622
|
+
setOpen(open);
|
|
3623
|
+
}
|
|
3624
|
+
const items = useMemo(() => {
|
|
3625
|
+
const selectOptions = [];
|
|
3626
|
+
for (const option of options) if (option.options) {
|
|
3627
|
+
option.options.forEach((opt) => {
|
|
3628
|
+
selectOptions.push({
|
|
3629
|
+
label: opt.label,
|
|
3630
|
+
value: opt.value,
|
|
3631
|
+
disabled: opt.disabled
|
|
3632
|
+
});
|
|
3633
|
+
});
|
|
3634
|
+
selectOptions.push({ type: "separator" });
|
|
3635
|
+
} else selectOptions.push({
|
|
3636
|
+
label: option.label,
|
|
3637
|
+
value: option.value,
|
|
3638
|
+
disabled: option.disabled
|
|
3639
|
+
});
|
|
3640
|
+
return [{
|
|
3641
|
+
type: "radio",
|
|
3642
|
+
value,
|
|
3643
|
+
hideIndicator: true,
|
|
3644
|
+
options: selectOptions,
|
|
3645
|
+
onSelect: (item) => {
|
|
3646
|
+
onChange(item);
|
|
3647
|
+
}
|
|
3648
|
+
}];
|
|
3649
|
+
}, [options]);
|
|
3650
|
+
const displayValue = useMemo(() => {
|
|
3651
|
+
let label = null;
|
|
3652
|
+
for (const option of options) if (option.options) {
|
|
3653
|
+
for (const opt of option.options) if (opt.value === value) {
|
|
3654
|
+
label = opt.label;
|
|
3655
|
+
break;
|
|
3656
|
+
}
|
|
3657
|
+
} else if (option.value === value) {
|
|
3658
|
+
label = option.label;
|
|
3659
|
+
break;
|
|
3660
|
+
}
|
|
3661
|
+
return label || value;
|
|
3662
|
+
}, [options, value]);
|
|
3663
|
+
return /* @__PURE__ */ jsx(DropdownMenu, {
|
|
3664
|
+
className: "max-h univer-w-[--radix-popper-anchor-width] univer-min-w-36",
|
|
3665
|
+
align: "start",
|
|
3666
|
+
open,
|
|
3667
|
+
items,
|
|
3668
|
+
disabled,
|
|
3669
|
+
onOpenChange: handleOpenChange,
|
|
3670
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
3671
|
+
"data-u-comp": "select",
|
|
3672
|
+
className: clsx(selectClassName, {
|
|
3673
|
+
"univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900": open && !borderless,
|
|
3674
|
+
"univer-border-transparent univer-bg-transparent hover:univer-border-transparent": borderless,
|
|
3675
|
+
"univer-cursor-not-allowed": disabled,
|
|
3676
|
+
"hover:univer-border-primary-600": !disabled && !borderless,
|
|
3677
|
+
"univer-cursor-pointer": !disabled && !open
|
|
3678
|
+
}, className),
|
|
3679
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
3680
|
+
className: "univer-flex-1 univer-truncate univer-text-sm univer-text-gray-500 dark:!univer-text-white",
|
|
3681
|
+
children: displayValue
|
|
3682
|
+
}), /* @__PURE__ */ jsx(MoreDownIcon, { className: "univer-flex-shrink-0 dark:!univer-text-white" })]
|
|
3683
|
+
})
|
|
3684
|
+
});
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
//#endregion
|
|
3688
|
+
//#region src/components/select/MultipleSelect.tsx
|
|
3689
|
+
function MultipleSelect(props) {
|
|
3690
|
+
const { className, value = [], disabled = false, options = [], borderless = false, onChange } = props;
|
|
3691
|
+
const [open, setOpen] = useState(false);
|
|
3692
|
+
function handleOpenChange(open) {
|
|
3693
|
+
setOpen(open);
|
|
3694
|
+
}
|
|
3695
|
+
const items = useMemo(() => {
|
|
3696
|
+
return options.map((option) => {
|
|
3697
|
+
return {
|
|
3698
|
+
type: "checkbox",
|
|
3699
|
+
value: option.value,
|
|
3700
|
+
label: option.label,
|
|
3701
|
+
disabled: option.disabled,
|
|
3702
|
+
checked: value.includes(option.value),
|
|
3703
|
+
onSelect: (item) => {
|
|
3704
|
+
onChange(value.includes(item) ? value.filter((v) => v !== item) : [...value, item]);
|
|
3705
|
+
}
|
|
3706
|
+
};
|
|
3707
|
+
});
|
|
3708
|
+
}, [options]);
|
|
3709
|
+
function handleClose(item) {
|
|
3710
|
+
onChange(value.filter((v) => v !== item));
|
|
3711
|
+
}
|
|
3712
|
+
const displayValue = useMemo(() => {
|
|
3713
|
+
return options.filter((option) => value.includes(option.value)).map((option, index) => /* @__PURE__ */ jsx(Badge, {
|
|
3714
|
+
className: "univer-max-w-32",
|
|
3715
|
+
closable: true,
|
|
3716
|
+
onClose: () => handleClose(option.value),
|
|
3717
|
+
children: option.label
|
|
3718
|
+
}, index));
|
|
3719
|
+
}, [options, value]);
|
|
3720
|
+
return /* @__PURE__ */ jsx(DropdownMenu, {
|
|
3721
|
+
className: "univer-w-[--radix-popper-anchor-width] univer-min-w-36",
|
|
3722
|
+
align: "start",
|
|
3723
|
+
open,
|
|
3724
|
+
items,
|
|
3725
|
+
disabled,
|
|
3726
|
+
onOpenChange: handleOpenChange,
|
|
3727
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
3728
|
+
"data-u-comp": "multiple-select",
|
|
3729
|
+
className: clsx(selectClassName, {
|
|
3730
|
+
"univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900": open && !borderless,
|
|
3731
|
+
"univer-border-transparent univer-bg-transparent hover:univer-border-transparent": borderless,
|
|
3732
|
+
"univer-cursor-not-allowed": disabled,
|
|
3733
|
+
"hover:univer-border-primary-600": !disabled && !borderless,
|
|
3734
|
+
"univer-cursor-pointer": !disabled && !open
|
|
3735
|
+
}, className),
|
|
3736
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
3737
|
+
className: "univer-box-border univer-flex univer-w-[calc(100%-16px)] univer-gap-2 univer-pr-2",
|
|
3738
|
+
children: displayValue
|
|
3739
|
+
}), /* @__PURE__ */ jsx(MoreDownIcon, { className: "univer-flex-shrink-0 dark:!univer-text-white" })]
|
|
3740
|
+
})
|
|
3741
|
+
});
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
//#endregion
|
|
3745
|
+
//#region src/components/separator/Separator.tsx
|
|
3746
|
+
function Separator({ className, orientation = "horizontal", decorative = true, ...props }) {
|
|
3747
|
+
return /* @__PURE__ */ jsx(Root$4, {
|
|
3748
|
+
"data-u-comp": "separator",
|
|
3749
|
+
"data-slot": "separator-root",
|
|
3750
|
+
decorative,
|
|
3751
|
+
orientation,
|
|
3752
|
+
className: clsx("univer-shrink-0 univer-bg-gray-200 data-[orientation=horizontal]:univer-h-px data-[orientation=vertical]:univer-h-full data-[orientation=horizontal]:univer-w-full data-[orientation=vertical]:univer-w-px dark:!univer-bg-gray-600", className),
|
|
3753
|
+
...props
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
//#endregion
|
|
3758
|
+
//#region src/components/switch/Switch.tsx
|
|
3759
|
+
/**
|
|
3760
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3761
|
+
*
|
|
3762
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3763
|
+
* you may not use this file except in compliance with the License.
|
|
3764
|
+
* You may obtain a copy of the License at
|
|
3765
|
+
*
|
|
3766
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3767
|
+
*
|
|
3768
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3769
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3770
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3771
|
+
* See the License for the specific language governing permissions and
|
|
3772
|
+
* limitations under the License.
|
|
3773
|
+
*/
|
|
3774
|
+
const Switch = (props) => {
|
|
3775
|
+
const { defaultChecked = false, onChange } = props;
|
|
3776
|
+
const [checked, setChecked] = useState(defaultChecked);
|
|
3777
|
+
const handleChange = () => {
|
|
3778
|
+
setChecked(!checked);
|
|
3779
|
+
onChange === null || onChange === void 0 || onChange(!checked);
|
|
3780
|
+
};
|
|
3781
|
+
useEffect(() => {
|
|
3782
|
+
setChecked(defaultChecked);
|
|
3783
|
+
}, [defaultChecked]);
|
|
3784
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3785
|
+
className: "univer-h-4",
|
|
3786
|
+
children: /* @__PURE__ */ jsxs("label", {
|
|
3787
|
+
className: "univer-relative univer-inline-block univer-h-4 univer-w-7",
|
|
3788
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
3789
|
+
className: "univer-size-0 univer-opacity-0",
|
|
3790
|
+
type: "checkbox",
|
|
3791
|
+
checked,
|
|
3792
|
+
onChange: handleChange
|
|
3793
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
3794
|
+
className: clsx("univer-absolute univer-inset-0 univer-cursor-pointer univer-rounded-2xl univer-transition-colors univer-duration-200", {
|
|
3795
|
+
"univer-bg-primary-600": checked,
|
|
3796
|
+
"univer-bg-gray-200 dark:!univer-bg-gray-600": !checked
|
|
3797
|
+
}),
|
|
3798
|
+
children: /* @__PURE__ */ jsx("span", { className: clsx("univer-absolute univer-bottom-0.5 univer-left-0.5 univer-size-3 univer-rounded-full univer-bg-white univer-transition-transform univer-duration-200", { "univer-translate-x-3": checked }) })
|
|
3799
|
+
})]
|
|
3800
|
+
})
|
|
3801
|
+
});
|
|
3802
|
+
};
|
|
3803
|
+
|
|
3804
|
+
//#endregion
|
|
3805
|
+
//#region src/components/textarea/Textarea.tsx
|
|
3806
|
+
const Textarea = forwardRef((props, ref) => {
|
|
3807
|
+
const textareaRef = useRef(null);
|
|
3808
|
+
const lastSizeRef = useRef({
|
|
3809
|
+
width: 0,
|
|
3810
|
+
height: 0
|
|
3811
|
+
});
|
|
3812
|
+
const { className, onResize, onValueChange, ...restProps } = props;
|
|
3813
|
+
useImperativeHandle(ref, () => textareaRef.current, []);
|
|
3814
|
+
useLayoutEffect(() => {
|
|
3815
|
+
const textarea = textareaRef.current;
|
|
3816
|
+
if (textarea && onResize) {
|
|
3817
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
3818
|
+
const { width, height } = entries[0].target.getBoundingClientRect();
|
|
3819
|
+
if (width === 0 || height === 0) return;
|
|
3820
|
+
if (lastSizeRef.current.width !== width || lastSizeRef.current.height !== height) {
|
|
3821
|
+
lastSizeRef.current = {
|
|
3822
|
+
width,
|
|
3823
|
+
height
|
|
3824
|
+
};
|
|
3825
|
+
onResize(width, height);
|
|
3826
|
+
}
|
|
3827
|
+
});
|
|
3828
|
+
resizeObserver.observe(textarea);
|
|
3829
|
+
return () => {
|
|
3830
|
+
resizeObserver.unobserve(textarea);
|
|
3831
|
+
resizeObserver.disconnect();
|
|
3832
|
+
};
|
|
3833
|
+
}
|
|
3834
|
+
}, [onResize]);
|
|
3835
|
+
function handleChange(event) {
|
|
3836
|
+
const value = event.target.value;
|
|
3837
|
+
onValueChange === null || onValueChange === void 0 || onValueChange(value);
|
|
3838
|
+
}
|
|
3839
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
3840
|
+
ref: textareaRef,
|
|
3841
|
+
"data-u-comp": "textarea",
|
|
3842
|
+
"data-slot": "textarea",
|
|
3843
|
+
className: clsx("univer-box-border univer-flex univer-w-full univer-resize univer-rounded-md univer-bg-transparent univer-p-2 univer-text-base univer-text-gray-900 univer-outline-none univer-transition-[color,box-shadow] placeholder:univer-text-gray-200 disabled:univer-cursor-not-allowed disabled:univer-opacity-50 dark:!univer-text-white", borderClassName, scrollbarClassName, className),
|
|
3844
|
+
onChange: handleChange,
|
|
3845
|
+
...restProps
|
|
3846
|
+
});
|
|
3847
|
+
});
|
|
3848
|
+
|
|
3849
|
+
//#endregion
|
|
3850
|
+
//#region src/components/toaster/Toaster.tsx
|
|
3851
|
+
function Toaster({ visibleToasts, ...props }) {
|
|
3852
|
+
return /* @__PURE__ */ jsx(Toaster$1, {
|
|
3853
|
+
className: "dark:![&_[data-description]]:univer-text-gray-200 [&_[data-description]]:univer-text-sm [&_[data-description]]:univer-text-gray-600 [&_[data-icon]>svg]:univer-relative [&_[data-icon]>svg]:univer-top-1 [&_[data-icon]]:univer-self-baseline [&_[data-sonner-toast]]:univer-shadow-md [&_[data-title]]:univer-text-sm [&_[data-title]]:univer-text-gray-900",
|
|
3854
|
+
toastOptions: { classNames: {
|
|
3855
|
+
content: "univer-leading-normal",
|
|
3856
|
+
success: "[&_[data-icon]]:univer-text-green-500",
|
|
3857
|
+
info: "[&_[data-icon]]:univer-text-primary-600",
|
|
3858
|
+
error: "[&_[data-icon]]:univer-text-red-500",
|
|
3859
|
+
warning: "[&_[data-icon]]:univer-text-yellow-500"
|
|
3860
|
+
} },
|
|
3861
|
+
visibleToasts: visibleToasts !== null && visibleToasts !== void 0 ? visibleToasts : 5,
|
|
3862
|
+
...props
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
//#endregion
|
|
3867
|
+
//#region src/components/virtual-list/VirtualList.tsx
|
|
3868
|
+
function VirtualList(props) {
|
|
3869
|
+
const { data, itemKey, children, height, itemHeight, overscan = 2, className, style } = props;
|
|
3870
|
+
const [scrollTop, setScrollTop] = useState(0);
|
|
3871
|
+
if (!height || !itemHeight || itemHeight <= 0) return /* @__PURE__ */ jsx("div", {
|
|
3872
|
+
className,
|
|
3873
|
+
style,
|
|
3874
|
+
children: data.map((item, index) => {
|
|
3875
|
+
const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
|
|
3876
|
+
return /* @__PURE__ */ jsx("div", { children: children(item, index) }, key);
|
|
3877
|
+
})
|
|
3878
|
+
});
|
|
3879
|
+
const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);
|
|
3880
|
+
const visibleCount = Math.ceil(height / itemHeight) + overscan * 2;
|
|
3881
|
+
const end = Math.min(data.length, start + visibleCount);
|
|
3882
|
+
const offsetY = start * itemHeight;
|
|
3883
|
+
const totalHeight = data.length * itemHeight;
|
|
3884
|
+
const visibleItems = data.slice(start, end);
|
|
3885
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3886
|
+
className,
|
|
3887
|
+
style: {
|
|
3888
|
+
...style,
|
|
3889
|
+
height,
|
|
3890
|
+
overflowY: "auto"
|
|
3891
|
+
},
|
|
3892
|
+
onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
|
|
3893
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
3894
|
+
style: {
|
|
3895
|
+
height: totalHeight,
|
|
3896
|
+
position: "relative"
|
|
3897
|
+
},
|
|
3898
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
3899
|
+
style: { transform: `translateY(${offsetY}px)` },
|
|
3900
|
+
children: visibleItems.map((item, index) => {
|
|
3901
|
+
const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
|
|
3902
|
+
return /* @__PURE__ */ jsx("div", { children: children(item, start + index) }, key);
|
|
3903
|
+
})
|
|
3904
|
+
})
|
|
3905
|
+
})
|
|
3906
|
+
});
|
|
3907
|
+
}
|
|
3908
|
+
|
|
3909
|
+
//#endregion
|
|
3910
|
+
//#region src/components/tree/util.ts
|
|
3911
|
+
const findNodePathFromTree = (tree, key) => {
|
|
3912
|
+
const result = [];
|
|
3913
|
+
const recursive = (node) => {
|
|
3914
|
+
var _node$children;
|
|
3915
|
+
result.push(node.key);
|
|
3916
|
+
if (key === node.key) return true;
|
|
3917
|
+
if ((_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) {
|
|
3918
|
+
if (node.children.some(recursive)) return true;
|
|
3919
|
+
}
|
|
3920
|
+
result.pop();
|
|
3921
|
+
};
|
|
3922
|
+
tree.some(recursive);
|
|
3923
|
+
return result;
|
|
3924
|
+
};
|
|
3925
|
+
const createCacheWithFindNodePathFromTree = (tree, defaultCache) => {
|
|
3926
|
+
const cache = defaultCache !== null && defaultCache !== void 0 ? defaultCache : /* @__PURE__ */ new Map();
|
|
3927
|
+
let cacheTree = tree;
|
|
3928
|
+
return {
|
|
3929
|
+
findNodePathFromTreeWithCache: (key) => {
|
|
3930
|
+
const cacheValue = cache.get(key);
|
|
3931
|
+
if (cacheValue) return cacheValue;
|
|
3932
|
+
const path = findNodePathFromTree(cacheTree, key);
|
|
3933
|
+
path.map((k, index, arr) => {
|
|
3934
|
+
const result = [];
|
|
3935
|
+
for (let i = 0; i <= index; i++) result.push(arr[i]);
|
|
3936
|
+
return result;
|
|
3937
|
+
}).reverse().forEach((list) => {
|
|
3938
|
+
const key = list[list.length - 1];
|
|
3939
|
+
cache.set(key, list);
|
|
3940
|
+
});
|
|
3941
|
+
return path;
|
|
3942
|
+
},
|
|
3943
|
+
reset: (newTree) => {
|
|
3944
|
+
cache.clear();
|
|
3945
|
+
if (newTree) cacheTree = newTree;
|
|
3946
|
+
}
|
|
3947
|
+
};
|
|
3948
|
+
};
|
|
3949
|
+
const findSubTreeFromPath = (tree, path) => {
|
|
3950
|
+
if (!path.length) return tree;
|
|
3951
|
+
return path.reduce((list, key) => {
|
|
3952
|
+
const item = list.find((node) => node.key === key);
|
|
3953
|
+
return (item === null || item === void 0 ? void 0 : item.children) || [];
|
|
3954
|
+
}, tree);
|
|
3955
|
+
};
|
|
3956
|
+
const findNodeFromPath = (tree, _path) => {
|
|
3957
|
+
const path = _path.slice(0);
|
|
3958
|
+
const key = path.pop();
|
|
3959
|
+
return findSubTreeFromPath(tree, path).find((node) => node.key === key);
|
|
3960
|
+
};
|
|
3961
|
+
const mergeTreeSelected = (treeData, treeSelected, path) => {
|
|
3962
|
+
const set = new Set(treeSelected);
|
|
3963
|
+
const key = path[path.length - 1];
|
|
3964
|
+
const subTree = findSubTreeFromPath(treeData, path);
|
|
3965
|
+
if (!set.has(key)) {
|
|
3966
|
+
const addRecursive = (node) => {
|
|
3967
|
+
set.add(node.key);
|
|
3968
|
+
if (node.children) node.children.forEach((n) => addRecursive(n));
|
|
3969
|
+
};
|
|
3970
|
+
path.forEach((k) => set.add(k));
|
|
3971
|
+
if (subTree.length) subTree.forEach(addRecursive);
|
|
3972
|
+
} else {
|
|
3973
|
+
if (subTree.length) {
|
|
3974
|
+
const deleteRecursive = (node) => {
|
|
3975
|
+
set.delete(node.key);
|
|
3976
|
+
if (node.children) node.children.forEach((n) => deleteRecursive(n));
|
|
3977
|
+
};
|
|
3978
|
+
subTree.forEach(deleteRecursive);
|
|
3979
|
+
}
|
|
3980
|
+
path.map((k, index, arr) => {
|
|
3981
|
+
const result = [];
|
|
3982
|
+
for (let i = 0; i <= index; i++) result.push(arr[i]);
|
|
3983
|
+
return result;
|
|
3984
|
+
}).reverse().some((path) => {
|
|
3985
|
+
const list = findSubTreeFromPath(treeData, path);
|
|
3986
|
+
const key = path[path.length - 1];
|
|
3987
|
+
if (list.every((e) => !set.has(e.key))) set.delete(key);
|
|
3988
|
+
else return true;
|
|
3989
|
+
return false;
|
|
3990
|
+
});
|
|
3991
|
+
}
|
|
3992
|
+
return [...set];
|
|
3993
|
+
};
|
|
3994
|
+
const isIntermediated = (treeSelected, node) => {
|
|
3995
|
+
const list = node.children || [];
|
|
3996
|
+
const checkIsSelected = (node) => {
|
|
3997
|
+
var _node$children2;
|
|
3998
|
+
if ((_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.length) {
|
|
3999
|
+
if (node.children.every(checkIsSelected)) return true;
|
|
4000
|
+
return false;
|
|
4001
|
+
}
|
|
4002
|
+
return treeSelected.has(node.key);
|
|
4003
|
+
};
|
|
4004
|
+
if (list.length) return list.some((node) => !checkIsSelected(node));
|
|
4005
|
+
return false;
|
|
4006
|
+
};
|
|
4007
|
+
const filterLeafNode = (tree, keyList) => {
|
|
4008
|
+
const result = [];
|
|
4009
|
+
const find = createCacheWithFindNodePathFromTree(tree);
|
|
4010
|
+
keyList.forEach((key) => {
|
|
4011
|
+
const node = findNodeFromPath(tree, find.findNodePathFromTreeWithCache(key));
|
|
4012
|
+
if (node) {
|
|
4013
|
+
var _node$children3;
|
|
4014
|
+
if (!((_node$children3 = node.children) === null || _node$children3 === void 0 ? void 0 : _node$children3.length)) result.push(node);
|
|
4015
|
+
}
|
|
4016
|
+
});
|
|
4017
|
+
return result;
|
|
4018
|
+
};
|
|
4019
|
+
|
|
4020
|
+
//#endregion
|
|
4021
|
+
//#region src/components/tree/Tree.tsx
|
|
4022
|
+
let TreeSelectionMode = /* @__PURE__ */ function(TreeSelectionMode) {
|
|
4023
|
+
TreeSelectionMode[TreeSelectionMode["ONLY_LEAF_NODE"] = 0] = "ONLY_LEAF_NODE";
|
|
4024
|
+
TreeSelectionMode[TreeSelectionMode["ALL"] = 1] = "ALL";
|
|
4025
|
+
return TreeSelectionMode;
|
|
4026
|
+
}({});
|
|
4027
|
+
function flattenTree(items, expandedKeys, level = 1) {
|
|
4028
|
+
const flatItems = [];
|
|
4029
|
+
items.forEach((item) => {
|
|
4030
|
+
flatItems.push({
|
|
4031
|
+
...item,
|
|
4032
|
+
level
|
|
4033
|
+
});
|
|
4034
|
+
if (item.children && expandedKeys.has(item.key)) flatItems.push(...flattenTree(item.children, expandedKeys, level + 1));
|
|
4035
|
+
});
|
|
4036
|
+
return flatItems;
|
|
4037
|
+
}
|
|
4038
|
+
/**
|
|
4039
|
+
* Tree Component
|
|
4040
|
+
*/
|
|
4041
|
+
function Tree(props) {
|
|
4042
|
+
const { data = [], defaultCache, style, defaultExpandAll = false, selectionMode = TreeSelectionMode.ALL, valueGroup = [], onChange, onExpend, height = 200, itemHeight = 32, attachRender } = props;
|
|
4043
|
+
const [update, forceUpdate] = useState({});
|
|
4044
|
+
const expandKeySet = useMemo(() => {
|
|
4045
|
+
return /* @__PURE__ */ new Set();
|
|
4046
|
+
}, []);
|
|
4047
|
+
const findNode = useMemo(() => createCacheWithFindNodePathFromTree(data, defaultCache), [data, defaultCache]);
|
|
4048
|
+
const selectedNodeKeySet = useMemo(() => {
|
|
4049
|
+
const set = /* @__PURE__ */ new Set();
|
|
4050
|
+
valueGroup.forEach((key) => {
|
|
4051
|
+
findNode.findNodePathFromTreeWithCache(key).forEach((k) => set.add(k));
|
|
4052
|
+
});
|
|
4053
|
+
return set;
|
|
4054
|
+
}, [valueGroup, findNode]);
|
|
4055
|
+
useEffect(() => {
|
|
4056
|
+
function walkData(item) {
|
|
4057
|
+
var _item$children;
|
|
4058
|
+
expandKeySet.add(item.key);
|
|
4059
|
+
(_item$children = item.children) === null || _item$children === void 0 || _item$children.forEach(walkData);
|
|
4060
|
+
}
|
|
4061
|
+
if (defaultExpandAll) data.forEach(walkData);
|
|
4062
|
+
forceUpdate({});
|
|
4063
|
+
}, [defaultExpandAll, data]);
|
|
4064
|
+
const flatData = useMemo(() => flattenTree(data, expandKeySet), [
|
|
4065
|
+
data,
|
|
4066
|
+
update,
|
|
4067
|
+
expandKeySet
|
|
4068
|
+
]);
|
|
4069
|
+
function handleExpendItem(treeItem) {
|
|
4070
|
+
var _treeItem$children;
|
|
4071
|
+
if ((_treeItem$children = treeItem.children) === null || _treeItem$children === void 0 ? void 0 : _treeItem$children.length) {
|
|
4072
|
+
if (expandKeySet.has(treeItem.key)) expandKeySet.delete(treeItem.key);
|
|
4073
|
+
else expandKeySet.add(treeItem.key);
|
|
4074
|
+
forceUpdate({});
|
|
4075
|
+
}
|
|
4076
|
+
if (selectionMode === TreeSelectionMode.ONLY_LEAF_NODE) {
|
|
4077
|
+
if (treeItem.children) return;
|
|
4078
|
+
}
|
|
4079
|
+
onExpend === null || onExpend === void 0 || onExpend(treeItem.key);
|
|
4080
|
+
}
|
|
4081
|
+
function renderTreeItem(treeItem) {
|
|
4082
|
+
const { title, key, level = 0 } = treeItem;
|
|
4083
|
+
const treeNodeClassName = props.treeNodeClassName;
|
|
4084
|
+
const expended = expandKeySet.has(key);
|
|
4085
|
+
const selected = selectedNodeKeySet.has(key);
|
|
4086
|
+
const intermediated = isIntermediated(selectedNodeKeySet, treeItem);
|
|
4087
|
+
return /* @__PURE__ */ jsx("div", {
|
|
4088
|
+
className: clsx("univer-relative univer-text-[13px]", treeNodeClassName),
|
|
4089
|
+
style: { paddingLeft: `${level * 20}px` },
|
|
4090
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
4091
|
+
className: "univer-relative univer-my-1 univer-flex univer-w-full univer-items-center",
|
|
4092
|
+
children: [
|
|
4093
|
+
treeItem.children && treeItem.children.length > 0 && /* @__PURE__ */ jsx("span", {
|
|
4094
|
+
className: clsx("univer-absolute univer-left-[-16px] univer-top-1/2 univer-flex univer--translate-y-1/2 univer-items-center univer-justify-center univer-text-[8px]", { "univer-rotate-[-90deg]": !expended }),
|
|
4095
|
+
onClick: (e) => {
|
|
4096
|
+
e.stopPropagation();
|
|
4097
|
+
handleExpendItem(treeItem);
|
|
4098
|
+
},
|
|
4099
|
+
children: /* @__PURE__ */ jsx(DropdownIcon, {})
|
|
4100
|
+
}),
|
|
4101
|
+
/* @__PURE__ */ jsx(Checkbox, {
|
|
4102
|
+
checked: selected && !intermediated,
|
|
4103
|
+
indeterminate: selected && intermediated,
|
|
4104
|
+
onChange: () => {
|
|
4105
|
+
onChange === null || onChange === void 0 || onChange(treeItem);
|
|
4106
|
+
}
|
|
4107
|
+
}),
|
|
4108
|
+
/* @__PURE__ */ jsx("div", {
|
|
4109
|
+
className: "\n univer-mx-1 univer-flex univer-h-full univer-shrink univer-items-center univer-overflow-hidden\n univer-text-ellipsis univer-whitespace-nowrap\n ",
|
|
4110
|
+
onClick: (e) => {
|
|
4111
|
+
e.stopPropagation();
|
|
4112
|
+
handleExpendItem(treeItem);
|
|
4113
|
+
},
|
|
4114
|
+
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
4115
|
+
className: "univer-block",
|
|
4116
|
+
showIfEllipsis: true,
|
|
4117
|
+
placement: "top",
|
|
4118
|
+
title,
|
|
4119
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
4120
|
+
className: "univer-block",
|
|
4121
|
+
children: title
|
|
4122
|
+
})
|
|
4123
|
+
})
|
|
4124
|
+
}),
|
|
4125
|
+
attachRender && attachRender(treeItem)
|
|
4126
|
+
]
|
|
4127
|
+
})
|
|
4128
|
+
}, key);
|
|
4129
|
+
}
|
|
4130
|
+
return /* @__PURE__ */ jsx("section", {
|
|
4131
|
+
className: "\n univer-relative univer-select-none univer-text-gray-900\n dark:!univer-text-white\n ",
|
|
4132
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
4133
|
+
className: "univer-m-0 univer-h-full univer-list-none univer-p-0",
|
|
4134
|
+
style,
|
|
4135
|
+
children: /* @__PURE__ */ jsx(VirtualList, {
|
|
4136
|
+
data: flatData,
|
|
4137
|
+
itemKey: (item) => item.key,
|
|
4138
|
+
height,
|
|
4139
|
+
itemHeight,
|
|
4140
|
+
children: (item) => renderTreeItem(item)
|
|
4141
|
+
})
|
|
4142
|
+
})
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
//#endregion
|
|
4147
|
+
//#region src/helper/react-dom.ts
|
|
4148
|
+
const rootMap = /* @__PURE__ */ new WeakMap();
|
|
4149
|
+
function render(node, container) {
|
|
4150
|
+
let root = rootMap.get(container);
|
|
4151
|
+
if (!root) {
|
|
4152
|
+
root = createRoot(container);
|
|
4153
|
+
rootMap.set(container, root);
|
|
4154
|
+
}
|
|
4155
|
+
root.render(node);
|
|
4156
|
+
}
|
|
4157
|
+
function unmount(container) {
|
|
4158
|
+
const root = rootMap.get(container);
|
|
4159
|
+
if (root) {
|
|
4160
|
+
root.unmount();
|
|
4161
|
+
rootMap.delete(container);
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4164
|
+
|
|
4165
|
+
//#endregion
|
|
4166
|
+
//#region src/helper/resize-observer.ts
|
|
4167
|
+
/**
|
|
4168
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
4169
|
+
*
|
|
4170
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4171
|
+
* you may not use this file except in compliance with the License.
|
|
4172
|
+
* You may obtain a copy of the License at
|
|
4173
|
+
*
|
|
4174
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4175
|
+
*
|
|
4176
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4177
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4178
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4179
|
+
* See the License for the specific language governing permissions and
|
|
4180
|
+
* limitations under the License.
|
|
4181
|
+
*/
|
|
4182
|
+
/**
|
|
4183
|
+
* All elements are observed by a single ResizeObserver is got greater performance than each element observed by separate ResizeObserver
|
|
4184
|
+
* See issue https://github.com/WICG/resize-observer/issues/59#issuecomment-408098151
|
|
4185
|
+
*/
|
|
4186
|
+
const _resizeObserverCallbacks = /* @__PURE__ */ new Set();
|
|
4187
|
+
let _resizeObserver;
|
|
4188
|
+
function resizeObserverCtor(callback) {
|
|
4189
|
+
if (!_resizeObserver) _resizeObserver = new ResizeObserver((...args) => {
|
|
4190
|
+
_resizeObserverCallbacks.forEach((callback) => callback(...args));
|
|
4191
|
+
});
|
|
4192
|
+
return {
|
|
4193
|
+
observe(target, options) {
|
|
4194
|
+
_resizeObserverCallbacks.add(callback);
|
|
4195
|
+
_resizeObserver.observe(target, options);
|
|
4196
|
+
},
|
|
4197
|
+
unobserve(target) {
|
|
4198
|
+
_resizeObserverCallbacks.delete(callback);
|
|
4199
|
+
_resizeObserver.unobserve(target);
|
|
4200
|
+
}
|
|
4201
|
+
};
|
|
4202
|
+
}
|
|
4203
|
+
|
|
4204
|
+
//#endregion
|
|
4205
|
+
export { Accordion, Avatar, Badge, Button, ButtonGroup, Calendar, CascaderList, Checkbox, CheckboxGroup, ColorPicker, ConfigContext, ConfigProvider, Confirm, DatePicker, DateRangePicker, Dialog, DraggableList, Dropdown, DropdownMenu, FormDualColumnLayout, FormLayout, Gallery, GradientColorPicker, HoverCard, Input, InputNumber, KBD, MessageType, Messager, MultipleSelect, Pager, Popup, Radio, RadioGroup, Segmented, Select, SelectList, Separator, Switch, Textarea, TimeInput, Toaster, Tooltip, Tree, TreeSelectionMode, borderBottomClassName, borderClassName, borderLeftBottomClassName, borderLeftClassName, borderRightClassName, borderTopClassName, clsx, divideXClassName, divideYClassName, filterLeafNode, findNodePathFromTree, findSubTreeFromPath, isBrowser, mergeTreeSelected, message, removeMessage, render, resizeObserverCtor, scrollbarClassName, toast, unmount };
|