@taskon/widget-react 0.0.1-beta.5 → 0.0.1-beta.7
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/README.md +61 -47
- package/dist/CommunityTaskList.css +9 -1
- package/dist/EligibilityInfo.css +48 -75
- package/dist/LeaderboardWidget.css +73 -71
- package/dist/PageBuilder.css +5 -0
- package/dist/Quest.css +18 -14
- package/dist/TaskOnProvider.css +289 -0
- package/dist/ThemeProvider.css +227 -0
- package/dist/UserCenterWidget.css +6 -6
- package/dist/UserCenterWidget2.css +1388 -1621
- package/dist/{dynamic-import-helper.css → WidgetShell.css} +0 -227
- package/dist/chunks/{CommunityTaskList-CrMvOB8w.js → CommunityTaskList-D0uVD8wD.js} +393 -208
- package/dist/chunks/{EligibilityInfo-Beww12QX.js → EligibilityInfo-Cf6hx9-a.js} +459 -679
- package/dist/chunks/{LeaderboardWidget-DwuSpVl0.js → LeaderboardWidget-DyoiiNS6.js} +274 -252
- package/dist/chunks/{PageBuilder-DsX6Tv0N.js → PageBuilder-DoAFPm6-.js} +5 -5
- package/dist/chunks/{Quest-CuD2LElS.js → Quest-ySZlYd4u.js} +74 -57
- package/dist/chunks/TaskOnProvider-CxtFIs3n.js +2072 -0
- package/dist/chunks/{dynamic-import-helper-WmIF58Sb.js → ThemeProvider-CulHkqqY.js} +1282 -555
- package/dist/chunks/UserCenterWidget-BJsc_GSZ.js +3246 -0
- package/dist/chunks/{UserCenterWidget-CvU6K4AC.js → UserCenterWidget-STq8kpV4.js} +1174 -1386
- package/dist/chunks/WidgetShell-8xn-Jivw.js +659 -0
- package/dist/chunks/communitytask-es-CBNnS4o2.js +521 -0
- package/dist/chunks/communitytask-ja-GRf9cbdx.js +521 -0
- package/dist/chunks/communitytask-ko-Bf24PQKI.js +521 -0
- package/dist/chunks/{communitytask-ru-DhySaZL8.js → communitytask-ru-CZm2CPoV.js} +211 -1
- package/dist/chunks/leaderboardwidget-es-vKjrjQaz.js +146 -0
- package/dist/chunks/leaderboardwidget-ja-Q6u0HxKG.js +146 -0
- package/dist/chunks/leaderboardwidget-ko-CG6SWgxf.js +146 -0
- package/dist/chunks/leaderboardwidget-ru-DCcHcJGz.js +146 -0
- package/dist/chunks/{quest-es-D-b5xcme.js → quest-es-Dyyy0zaw.js} +8 -93
- package/dist/chunks/{quest-ja-Dxd2vqBF.js → quest-ja-Depog33y.js} +8 -93
- package/dist/chunks/{quest-ko-CSmRWgK_.js → quest-ko-BMu3uRQJ.js} +8 -93
- package/dist/chunks/{quest-ru-CkEKv1_F.js → quest-ru-xne814Rw.js} +8 -93
- package/dist/chunks/useIsMobile-D6Ybur-6.js +30 -0
- package/dist/chunks/useToast-BGJhd3BX.js +93 -0
- package/dist/chunks/usercenter-es-Dz3Wp2vV.js +512 -0
- package/dist/chunks/usercenter-ja-CKE4DJC6.js +512 -0
- package/dist/chunks/usercenter-ko-Dtpkn2qb.js +512 -0
- package/dist/chunks/usercenter-ru-DnBGee45.js +512 -0
- package/dist/community-task.d.ts +0 -390
- package/dist/community-task.js +2 -7
- package/dist/core.d.ts +38 -20
- package/dist/core.js +9 -10
- package/dist/index.d.ts +86 -709
- package/dist/index.js +22 -28
- package/dist/leaderboard.d.ts +0 -498
- package/dist/leaderboard.js +2 -16
- package/dist/page-builder.js +1 -1
- package/dist/quest.d.ts +0 -971
- package/dist/quest.js +2 -7
- package/dist/user-center.d.ts +0 -1610
- package/dist/user-center.js +2 -494
- package/package.json +2 -2
- package/dist/chunks/TaskOnProvider-xUeP2Nro.js +0 -1243
- package/dist/chunks/ThemeProvider-Bt4UZ33y.js +0 -1334
- package/dist/chunks/UserCenterWidget-CB0hnj-L.js +0 -3230
- package/dist/chunks/communitytask-es-1zawvXEX.js +0 -311
- package/dist/chunks/communitytask-ja-CmW6nP-L.js +0 -311
- package/dist/chunks/communitytask-ko-BD0hzQSi.js +0 -311
- package/dist/chunks/createLocaleLoader-BameiEhU.js +0 -65
- package/dist/chunks/leaderboardwidget-ja-Bj6gz6y1.js +0 -119
- package/dist/chunks/leaderboardwidget-ko-f1cLO9ic.js +0 -119
- package/dist/chunks/useToast-CaRkylKe.js +0 -304
- package/dist/chunks/usercenter-ja-B2465c1O.js +0 -326
- package/dist/chunks/usercenter-ko-xAEYxqLg.js +0 -326
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useState, useMemo, useCallback, useEffect, forwardRef } from "react";
|
|
3
|
+
import { createWidgetApi, parseWidgetConfig } from "@taskon/core";
|
|
4
|
+
import { h as useTaskOnContext, j as composeRefs, T as ThemeProvider } from "./ThemeProvider-CulHkqqY.js";
|
|
5
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
6
|
+
import '../WidgetShell.css';function cloudThemeToReactTheme(cloud) {
|
|
7
|
+
const isDual = cloud.colorMode.type === "dual";
|
|
8
|
+
const modeStrategy = isDual ? cloud.colorMode.dualVariant : "auto";
|
|
9
|
+
let mode;
|
|
10
|
+
if (cloud.colorMode.type === "dual") {
|
|
11
|
+
mode = cloud.colorMode.dualVariant === "auto" ? "auto" : "light";
|
|
12
|
+
} else {
|
|
13
|
+
mode = cloud.colorMode.type;
|
|
14
|
+
}
|
|
15
|
+
const mapColorToSeed = (color) => ({
|
|
16
|
+
colorPrimary: color.primaryColor,
|
|
17
|
+
colorSecondary: color.secondaryColor,
|
|
18
|
+
colorSuccess: color.successColor,
|
|
19
|
+
colorWarning: color.warningColor,
|
|
20
|
+
colorError: color.errorColor,
|
|
21
|
+
colorLink: color.linkColor,
|
|
22
|
+
colorTextOnPrimary: color.textInPrimaryButton,
|
|
23
|
+
colorText: color.textColor,
|
|
24
|
+
colorBgBase: color.backgroundColor
|
|
25
|
+
});
|
|
26
|
+
const mapSpacingToSeed = () => {
|
|
27
|
+
const base = Math.max(1, Number(cloud.spacing.sizeBaseStep) || 1);
|
|
28
|
+
const unit = Math.max(1, Number(cloud.spacing.sizeChangeUnit) || 1);
|
|
29
|
+
return {
|
|
30
|
+
spacingBaseStep: base,
|
|
31
|
+
spacingChangeUnit: unit
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
mode,
|
|
36
|
+
modeStrategy,
|
|
37
|
+
// Global seed (shape and spacing values applied regardless of mode)
|
|
38
|
+
seed: {
|
|
39
|
+
borderRadius: cloud.shape.borderRadius,
|
|
40
|
+
fontSize: cloud.shape.fontSize,
|
|
41
|
+
...mapSpacingToSeed()
|
|
42
|
+
},
|
|
43
|
+
// Per-mode color overrides
|
|
44
|
+
light: {
|
|
45
|
+
seed: mapColorToSeed(cloud.light)
|
|
46
|
+
},
|
|
47
|
+
dark: {
|
|
48
|
+
seed: mapColorToSeed(cloud.dark)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function usePagination(options) {
|
|
53
|
+
const { total, pageSize, initialPage = 0, mode = "pagination" } = options;
|
|
54
|
+
const [page, setPage] = useState(initialPage);
|
|
55
|
+
const totalPages = useMemo(() => {
|
|
56
|
+
return Math.max(1, Math.ceil(total / pageSize));
|
|
57
|
+
}, [total, pageSize]);
|
|
58
|
+
const safePage = useMemo(() => {
|
|
59
|
+
return Math.min(page, totalPages - 1);
|
|
60
|
+
}, [page, totalPages]);
|
|
61
|
+
if (safePage !== page) {
|
|
62
|
+
setPage(safePage);
|
|
63
|
+
}
|
|
64
|
+
const hasPrevious = safePage > 0;
|
|
65
|
+
const hasNext = safePage < totalPages - 1;
|
|
66
|
+
const goToPage = useCallback(
|
|
67
|
+
(targetPage) => {
|
|
68
|
+
const validPage = Math.max(0, Math.min(targetPage, totalPages - 1));
|
|
69
|
+
setPage(validPage);
|
|
70
|
+
},
|
|
71
|
+
[totalPages]
|
|
72
|
+
);
|
|
73
|
+
const goToPrevious = useCallback(() => {
|
|
74
|
+
if (hasPrevious) {
|
|
75
|
+
setPage((p) => p - 1);
|
|
76
|
+
}
|
|
77
|
+
}, [hasPrevious]);
|
|
78
|
+
const goToNext = useCallback(() => {
|
|
79
|
+
if (hasNext) {
|
|
80
|
+
setPage((p) => p + 1);
|
|
81
|
+
}
|
|
82
|
+
}, [hasNext]);
|
|
83
|
+
const reset = useCallback(() => {
|
|
84
|
+
setPage(0);
|
|
85
|
+
}, []);
|
|
86
|
+
const startIndex = safePage * pageSize + 1;
|
|
87
|
+
const endIndex = Math.min((safePage + 1) * pageSize, total);
|
|
88
|
+
const hasMore = useMemo(() => {
|
|
89
|
+
if (mode === "infinite") {
|
|
90
|
+
return safePage < totalPages - 1;
|
|
91
|
+
}
|
|
92
|
+
return hasNext;
|
|
93
|
+
}, [mode, safePage, totalPages, hasNext]);
|
|
94
|
+
const loadedCount = useMemo(() => {
|
|
95
|
+
if (mode === "infinite") {
|
|
96
|
+
return Math.min((safePage + 1) * pageSize, total);
|
|
97
|
+
}
|
|
98
|
+
return endIndex - startIndex + 1;
|
|
99
|
+
}, [mode, safePage, pageSize, total, startIndex, endIndex]);
|
|
100
|
+
const loadMore = useCallback(() => {
|
|
101
|
+
if (mode === "infinite" && hasMore) {
|
|
102
|
+
setPage((p) => p + 1);
|
|
103
|
+
}
|
|
104
|
+
}, [mode, hasMore]);
|
|
105
|
+
return {
|
|
106
|
+
page: safePage,
|
|
107
|
+
totalPages,
|
|
108
|
+
hasPrevious,
|
|
109
|
+
hasNext,
|
|
110
|
+
goToPage,
|
|
111
|
+
goToPrevious,
|
|
112
|
+
goToNext,
|
|
113
|
+
reset,
|
|
114
|
+
startIndex,
|
|
115
|
+
endIndex,
|
|
116
|
+
// Infinite 模式专用
|
|
117
|
+
loadMore,
|
|
118
|
+
hasMore,
|
|
119
|
+
loadedCount
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function useWidgetConfig(widgetId) {
|
|
123
|
+
const { client } = useTaskOnContext();
|
|
124
|
+
const [config, setConfig] = useState(null);
|
|
125
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
126
|
+
const [error, setError] = useState(null);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (!widgetId || !client) {
|
|
129
|
+
setConfig(null);
|
|
130
|
+
setIsLoading(false);
|
|
131
|
+
setError(null);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let cancelled = false;
|
|
135
|
+
setIsLoading(true);
|
|
136
|
+
setError(null);
|
|
137
|
+
const api = createWidgetApi(client);
|
|
138
|
+
api.getWidgetInfo(widgetId).then((info) => {
|
|
139
|
+
if (!cancelled) {
|
|
140
|
+
setConfig(parseWidgetConfig(info));
|
|
141
|
+
}
|
|
142
|
+
}).catch((err) => {
|
|
143
|
+
if (!cancelled) {
|
|
144
|
+
console.warn("[TaskOn] Failed to load widget config:", err);
|
|
145
|
+
setError(
|
|
146
|
+
err instanceof Error ? err.message : "Failed to load widget config"
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}).finally(() => {
|
|
150
|
+
if (!cancelled) {
|
|
151
|
+
setIsLoading(false);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return () => {
|
|
155
|
+
cancelled = true;
|
|
156
|
+
};
|
|
157
|
+
}, [widgetId, client]);
|
|
158
|
+
return { config, isLoading, error };
|
|
159
|
+
}
|
|
160
|
+
function useResolvedWidgetConfig(widgetId) {
|
|
161
|
+
const { config, isLoading, error } = useWidgetConfig(widgetId);
|
|
162
|
+
const cloudTheme = useMemo(() => {
|
|
163
|
+
if (!(config == null ? void 0 : config.theme)) return void 0;
|
|
164
|
+
return cloudThemeToReactTheme(config.theme);
|
|
165
|
+
}, [config == null ? void 0 : config.theme]);
|
|
166
|
+
return {
|
|
167
|
+
functionConfig: (config == null ? void 0 : config.functionConfig) ?? null,
|
|
168
|
+
cloudTheme,
|
|
169
|
+
isConfigLoading: isLoading,
|
|
170
|
+
configError: error
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
var REACT_LAZY_TYPE = Symbol.for("react.lazy");
|
|
174
|
+
var use = React[" use ".trim().toString()];
|
|
175
|
+
function isPromiseLike(value) {
|
|
176
|
+
return typeof value === "object" && value !== null && "then" in value;
|
|
177
|
+
}
|
|
178
|
+
function isLazyComponent(element) {
|
|
179
|
+
return element != null && typeof element === "object" && "$$typeof" in element && element.$$typeof === REACT_LAZY_TYPE && "_payload" in element && isPromiseLike(element._payload);
|
|
180
|
+
}
|
|
181
|
+
// @__NO_SIDE_EFFECTS__
|
|
182
|
+
function createSlot(ownerName) {
|
|
183
|
+
const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
|
|
184
|
+
const Slot2 = React.forwardRef((props, forwardedRef) => {
|
|
185
|
+
let { children, ...slotProps } = props;
|
|
186
|
+
if (isLazyComponent(children) && typeof use === "function") {
|
|
187
|
+
children = use(children._payload);
|
|
188
|
+
}
|
|
189
|
+
const childrenArray = React.Children.toArray(children);
|
|
190
|
+
const slottable = childrenArray.find(isSlottable);
|
|
191
|
+
if (slottable) {
|
|
192
|
+
const newElement = slottable.props.children;
|
|
193
|
+
const newChildren = childrenArray.map((child) => {
|
|
194
|
+
if (child === slottable) {
|
|
195
|
+
if (React.Children.count(newElement) > 1) return React.Children.only(null);
|
|
196
|
+
return React.isValidElement(newElement) ? newElement.props.children : null;
|
|
197
|
+
} else {
|
|
198
|
+
return child;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
|
|
202
|
+
}
|
|
203
|
+
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
|
|
204
|
+
});
|
|
205
|
+
Slot2.displayName = `${ownerName}.Slot`;
|
|
206
|
+
return Slot2;
|
|
207
|
+
}
|
|
208
|
+
var Slot = /* @__PURE__ */ createSlot("Slot");
|
|
209
|
+
// @__NO_SIDE_EFFECTS__
|
|
210
|
+
function createSlotClone(ownerName) {
|
|
211
|
+
const SlotClone = React.forwardRef((props, forwardedRef) => {
|
|
212
|
+
let { children, ...slotProps } = props;
|
|
213
|
+
if (isLazyComponent(children) && typeof use === "function") {
|
|
214
|
+
children = use(children._payload);
|
|
215
|
+
}
|
|
216
|
+
if (React.isValidElement(children)) {
|
|
217
|
+
const childrenRef = getElementRef(children);
|
|
218
|
+
const props2 = mergeProps(slotProps, children.props);
|
|
219
|
+
if (children.type !== React.Fragment) {
|
|
220
|
+
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
|
|
221
|
+
}
|
|
222
|
+
return React.cloneElement(children, props2);
|
|
223
|
+
}
|
|
224
|
+
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
|
|
225
|
+
});
|
|
226
|
+
SlotClone.displayName = `${ownerName}.SlotClone`;
|
|
227
|
+
return SlotClone;
|
|
228
|
+
}
|
|
229
|
+
var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
|
|
230
|
+
function isSlottable(child) {
|
|
231
|
+
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
|
|
232
|
+
}
|
|
233
|
+
function mergeProps(slotProps, childProps) {
|
|
234
|
+
const overrideProps = { ...childProps };
|
|
235
|
+
for (const propName in childProps) {
|
|
236
|
+
const slotPropValue = slotProps[propName];
|
|
237
|
+
const childPropValue = childProps[propName];
|
|
238
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
239
|
+
if (isHandler) {
|
|
240
|
+
if (slotPropValue && childPropValue) {
|
|
241
|
+
overrideProps[propName] = (...args) => {
|
|
242
|
+
const result = childPropValue(...args);
|
|
243
|
+
slotPropValue(...args);
|
|
244
|
+
return result;
|
|
245
|
+
};
|
|
246
|
+
} else if (slotPropValue) {
|
|
247
|
+
overrideProps[propName] = slotPropValue;
|
|
248
|
+
}
|
|
249
|
+
} else if (propName === "style") {
|
|
250
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
251
|
+
} else if (propName === "className") {
|
|
252
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { ...slotProps, ...overrideProps };
|
|
256
|
+
}
|
|
257
|
+
function getElementRef(element) {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
let getter = (_a = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a.get;
|
|
260
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
261
|
+
if (mayWarn) {
|
|
262
|
+
return element.ref;
|
|
263
|
+
}
|
|
264
|
+
getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
|
|
265
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
266
|
+
if (mayWarn) {
|
|
267
|
+
return element.props.ref;
|
|
268
|
+
}
|
|
269
|
+
return element.props.ref || element.ref;
|
|
270
|
+
}
|
|
271
|
+
const Button = forwardRef(
|
|
272
|
+
({
|
|
273
|
+
size = "medium",
|
|
274
|
+
variant = "primary",
|
|
275
|
+
loading = false,
|
|
276
|
+
iconPosition,
|
|
277
|
+
leftIcon,
|
|
278
|
+
rightIcon,
|
|
279
|
+
asChild = false,
|
|
280
|
+
disabled,
|
|
281
|
+
className = "",
|
|
282
|
+
style,
|
|
283
|
+
children,
|
|
284
|
+
...props
|
|
285
|
+
}, ref) => {
|
|
286
|
+
const Comp = asChild ? Slot : "button";
|
|
287
|
+
const actualIconPosition = iconPosition || (leftIcon ? "left" : rightIcon ? "right" : void 0);
|
|
288
|
+
const isIconOnly = actualIconPosition === "only" || !children && (leftIcon || rightIcon);
|
|
289
|
+
const baseStyles = {
|
|
290
|
+
display: "inline-flex",
|
|
291
|
+
alignItems: "center",
|
|
292
|
+
justifyContent: "center",
|
|
293
|
+
gap: "var(--taskon-spacing-xs)",
|
|
294
|
+
fontFamily: "inherit",
|
|
295
|
+
fontWeight: 500,
|
|
296
|
+
lineHeight: 1.5,
|
|
297
|
+
border: "none",
|
|
298
|
+
outline: "none",
|
|
299
|
+
cursor: disabled || loading ? "not-allowed" : "pointer",
|
|
300
|
+
transition: "all 0.2s ease-in-out",
|
|
301
|
+
position: "relative",
|
|
302
|
+
userSelect: "none",
|
|
303
|
+
whiteSpace: "nowrap",
|
|
304
|
+
opacity: disabled ? 0.5 : 1,
|
|
305
|
+
...style
|
|
306
|
+
};
|
|
307
|
+
const sizeStyles = {
|
|
308
|
+
small: {
|
|
309
|
+
fontSize: "var(--taskon-font-size-sm)",
|
|
310
|
+
padding: isIconOnly ? "var(--taskon-spacing-xs)" : "var(--taskon-spacing-xs) var(--taskon-spacing-sm)",
|
|
311
|
+
borderRadius: "var(--taskon-border-radius-sm)",
|
|
312
|
+
minWidth: isIconOnly ? "24px" : "64px",
|
|
313
|
+
height: "24px"
|
|
314
|
+
},
|
|
315
|
+
medium: {
|
|
316
|
+
fontSize: "var(--taskon-font-size)",
|
|
317
|
+
padding: isIconOnly ? "var(--taskon-spacing-xs)" : "var(--taskon-spacing-xs) var(--taskon-spacing-md)",
|
|
318
|
+
borderRadius: "var(--taskon-border-radius)",
|
|
319
|
+
minWidth: isIconOnly ? "32px" : "80px",
|
|
320
|
+
height: "32px"
|
|
321
|
+
},
|
|
322
|
+
large: {
|
|
323
|
+
fontSize: "var(--taskon-font-size-lg)",
|
|
324
|
+
padding: isIconOnly ? "var(--taskon-spacing-sm)" : "var(--taskon-spacing-sm) var(--taskon-spacing-lg)",
|
|
325
|
+
borderRadius: "var(--taskon-border-radius)",
|
|
326
|
+
minWidth: isIconOnly ? "40px" : "96px",
|
|
327
|
+
height: "40px"
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const variantStyles = {
|
|
331
|
+
primary: {
|
|
332
|
+
backgroundColor: "var(--taskon-color-primary)",
|
|
333
|
+
color: "var(--taskon-color-text-on-primary)"
|
|
334
|
+
},
|
|
335
|
+
secondary: {
|
|
336
|
+
backgroundColor: "var(--taskon-color-secondary)",
|
|
337
|
+
color: "var(--taskon-color-text-on-primary)"
|
|
338
|
+
},
|
|
339
|
+
outline: {
|
|
340
|
+
backgroundColor: "transparent",
|
|
341
|
+
color: "var(--taskon-color-text)",
|
|
342
|
+
border: "1px solid var(--taskon-color-border)"
|
|
343
|
+
},
|
|
344
|
+
ghost: {
|
|
345
|
+
backgroundColor: "transparent",
|
|
346
|
+
color: "var(--taskon-color-text)"
|
|
347
|
+
},
|
|
348
|
+
danger: {
|
|
349
|
+
backgroundColor: "var(--taskon-color-error)",
|
|
350
|
+
color: "var(--taskon-color-text-on-primary)"
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const hoverStyles = {
|
|
354
|
+
primary: "hover:bg-[var(--taskon-color-primary-hover)] active:bg-[var(--taskon-color-primary-active)]",
|
|
355
|
+
secondary: "hover:opacity-90 active:opacity-80",
|
|
356
|
+
outline: "hover:bg-[var(--taskon-color-bg-surface-strong)] active:bg-[var(--taskon-color-bg-surface-strong)]",
|
|
357
|
+
ghost: "hover:bg-[var(--taskon-color-bg-surface-strong)] active:bg-[var(--taskon-color-bg-surface-strong)]",
|
|
358
|
+
danger: "hover:opacity-90 active:opacity-80"
|
|
359
|
+
};
|
|
360
|
+
const mergedStyle = {
|
|
361
|
+
...baseStyles,
|
|
362
|
+
...sizeStyles[size],
|
|
363
|
+
...variantStyles[variant]
|
|
364
|
+
};
|
|
365
|
+
const mergedClassName = `${className} ${hoverStyles[variant]}`.trim();
|
|
366
|
+
const renderLoadingIndicator = () => {
|
|
367
|
+
if (!loading) return null;
|
|
368
|
+
return /* @__PURE__ */ jsx(
|
|
369
|
+
"span",
|
|
370
|
+
{
|
|
371
|
+
style: {
|
|
372
|
+
display: "inline-block",
|
|
373
|
+
width: "1em",
|
|
374
|
+
height: "1em",
|
|
375
|
+
border: "2px solid currentColor",
|
|
376
|
+
borderTopColor: "transparent",
|
|
377
|
+
borderRadius: "50%",
|
|
378
|
+
animation: "taskon-button-spin 0.6s linear infinite"
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
);
|
|
382
|
+
};
|
|
383
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
384
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
385
|
+
@keyframes taskon-button-spin {
|
|
386
|
+
from {
|
|
387
|
+
transform: rotate(0deg);
|
|
388
|
+
}
|
|
389
|
+
to {
|
|
390
|
+
transform: rotate(360deg);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
` }),
|
|
394
|
+
/* @__PURE__ */ jsxs(
|
|
395
|
+
Comp,
|
|
396
|
+
{
|
|
397
|
+
ref,
|
|
398
|
+
disabled: disabled || loading,
|
|
399
|
+
className: mergedClassName,
|
|
400
|
+
style: mergedStyle,
|
|
401
|
+
...props,
|
|
402
|
+
children: [
|
|
403
|
+
loading && renderLoadingIndicator(),
|
|
404
|
+
!loading && leftIcon && actualIconPosition === "left" && /* @__PURE__ */ jsx("span", { style: { display: "inline-flex" }, children: leftIcon }),
|
|
405
|
+
!isIconOnly && children,
|
|
406
|
+
!loading && rightIcon && actualIconPosition === "right" && /* @__PURE__ */ jsx("span", { style: { display: "inline-flex" }, children: rightIcon })
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
] });
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
Button.displayName = "Button";
|
|
414
|
+
const defaultPaginationMessages = {
|
|
415
|
+
previous: "Previous",
|
|
416
|
+
next: "Next",
|
|
417
|
+
page: "Page",
|
|
418
|
+
of: "of",
|
|
419
|
+
showing: "Showing {start}-{end} of {total}"
|
|
420
|
+
};
|
|
421
|
+
function ChevronLeftIcon() {
|
|
422
|
+
return /* @__PURE__ */ jsx(
|
|
423
|
+
"svg",
|
|
424
|
+
{
|
|
425
|
+
className: "taskon-pagination-icon",
|
|
426
|
+
viewBox: "0 0 24 24",
|
|
427
|
+
fill: "none",
|
|
428
|
+
stroke: "currentColor",
|
|
429
|
+
strokeWidth: "2",
|
|
430
|
+
strokeLinecap: "round",
|
|
431
|
+
strokeLinejoin: "round",
|
|
432
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "15 18 9 12 15 6" })
|
|
433
|
+
}
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
function ChevronRightIcon() {
|
|
437
|
+
return /* @__PURE__ */ jsx(
|
|
438
|
+
"svg",
|
|
439
|
+
{
|
|
440
|
+
className: "taskon-pagination-icon",
|
|
441
|
+
viewBox: "0 0 24 24",
|
|
442
|
+
fill: "none",
|
|
443
|
+
stroke: "currentColor",
|
|
444
|
+
strokeWidth: "2",
|
|
445
|
+
strokeLinecap: "round",
|
|
446
|
+
strokeLinejoin: "round",
|
|
447
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "9 18 15 12 9 6" })
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
function Pagination({
|
|
452
|
+
page,
|
|
453
|
+
totalPages,
|
|
454
|
+
hasPrevious,
|
|
455
|
+
hasNext,
|
|
456
|
+
onPrevious,
|
|
457
|
+
onNext,
|
|
458
|
+
messages = defaultPaginationMessages,
|
|
459
|
+
className = "",
|
|
460
|
+
showRange,
|
|
461
|
+
showArrows = true,
|
|
462
|
+
showButtonText = false,
|
|
463
|
+
// 默认不显示按钮文字,只显示箭头图标
|
|
464
|
+
size = "medium"
|
|
465
|
+
}) {
|
|
466
|
+
if (totalPages <= 1) {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
const rangeText = showRange && messages.showing ? messages.showing.replace("{start}", String(showRange.start)).replace("{end}", String(showRange.end)).replace("{total}", String(showRange.total)) : null;
|
|
470
|
+
return /* @__PURE__ */ jsxs("div", { className: `taskon-pagination taskon-pagination--${size} ${className}`, children: [
|
|
471
|
+
rangeText && /* @__PURE__ */ jsx("span", { className: "taskon-pagination-range", children: rangeText }),
|
|
472
|
+
/* @__PURE__ */ jsxs("div", { className: "taskon-pagination-controls", children: [
|
|
473
|
+
/* @__PURE__ */ jsx(
|
|
474
|
+
Button,
|
|
475
|
+
{
|
|
476
|
+
variant: "ghost",
|
|
477
|
+
size,
|
|
478
|
+
disabled: !hasPrevious,
|
|
479
|
+
onClick: onPrevious,
|
|
480
|
+
"aria-label": messages.previous,
|
|
481
|
+
leftIcon: showArrows ? /* @__PURE__ */ jsx(ChevronLeftIcon, {}) : void 0,
|
|
482
|
+
className: "taskon-pagination-btn taskon-pagination-btn--prev",
|
|
483
|
+
children: showButtonText && messages.previous
|
|
484
|
+
}
|
|
485
|
+
),
|
|
486
|
+
/* @__PURE__ */ jsxs("span", { className: "taskon-pagination-info", children: [
|
|
487
|
+
/* @__PURE__ */ jsx("span", { className: "taskon-pagination-info-current", children: page + 1 }),
|
|
488
|
+
/* @__PURE__ */ jsx("span", { className: "taskon-pagination-info-separator", children: " / " }),
|
|
489
|
+
/* @__PURE__ */ jsx("span", { className: "taskon-pagination-info-total", children: totalPages })
|
|
490
|
+
] }),
|
|
491
|
+
/* @__PURE__ */ jsx(
|
|
492
|
+
Button,
|
|
493
|
+
{
|
|
494
|
+
variant: "ghost",
|
|
495
|
+
size,
|
|
496
|
+
disabled: !hasNext,
|
|
497
|
+
onClick: onNext,
|
|
498
|
+
"aria-label": messages.next,
|
|
499
|
+
rightIcon: showArrows ? /* @__PURE__ */ jsx(ChevronRightIcon, {}) : void 0,
|
|
500
|
+
className: "taskon-pagination-btn taskon-pagination-btn--next",
|
|
501
|
+
children: showButtonText && messages.next
|
|
502
|
+
}
|
|
503
|
+
)
|
|
504
|
+
] })
|
|
505
|
+
] });
|
|
506
|
+
}
|
|
507
|
+
function Table({
|
|
508
|
+
columns,
|
|
509
|
+
data,
|
|
510
|
+
rowConfig,
|
|
511
|
+
loading = false,
|
|
512
|
+
loadingText = "Loading...",
|
|
513
|
+
empty,
|
|
514
|
+
striped = false,
|
|
515
|
+
compact = false,
|
|
516
|
+
borderless = false,
|
|
517
|
+
className = "",
|
|
518
|
+
style
|
|
519
|
+
}) {
|
|
520
|
+
const tableClassName = [
|
|
521
|
+
"taskon-table",
|
|
522
|
+
striped && "taskon-table--striped",
|
|
523
|
+
compact && "taskon-table--compact",
|
|
524
|
+
borderless && "taskon-table--borderless"
|
|
525
|
+
].filter(Boolean).join(" ");
|
|
526
|
+
const getRowKey = (rowConfig == null ? void 0 : rowConfig.getRowKey) || ((_, index) => index);
|
|
527
|
+
const getColumnStyle = (column) => {
|
|
528
|
+
const style2 = {};
|
|
529
|
+
if (column.width) {
|
|
530
|
+
style2.width = typeof column.width === "number" ? `${column.width}px` : column.width;
|
|
531
|
+
}
|
|
532
|
+
if (column.minWidth) {
|
|
533
|
+
style2.minWidth = typeof column.minWidth === "number" ? `${column.minWidth}px` : column.minWidth;
|
|
534
|
+
}
|
|
535
|
+
return style2;
|
|
536
|
+
};
|
|
537
|
+
const getAlignClassName = (align) => {
|
|
538
|
+
if (!align || align === "left") return "";
|
|
539
|
+
return `taskon-table__header--${align}`;
|
|
540
|
+
};
|
|
541
|
+
const getCellAlignClassName = (align) => {
|
|
542
|
+
if (!align || align === "left") return "";
|
|
543
|
+
return `taskon-table__cell--${align}`;
|
|
544
|
+
};
|
|
545
|
+
const renderHeader = () => /* @__PURE__ */ jsx("thead", { className: "taskon-table__head", children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx(
|
|
546
|
+
"th",
|
|
547
|
+
{
|
|
548
|
+
className: `taskon-table__header ${getAlignClassName(column.align)} ${column.headerClassName || ""}`,
|
|
549
|
+
style: getColumnStyle(column),
|
|
550
|
+
children: column.title
|
|
551
|
+
},
|
|
552
|
+
column.key
|
|
553
|
+
)) }) });
|
|
554
|
+
const renderLoading = () => /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsxs("td", { colSpan: columns.length, className: "taskon-table__loading", children: [
|
|
555
|
+
/* @__PURE__ */ jsx("div", { className: "taskon-table__loading-spinner" }),
|
|
556
|
+
/* @__PURE__ */ jsx("div", { style: { marginTop: 8 }, children: loadingText })
|
|
557
|
+
] }) });
|
|
558
|
+
const renderEmpty = () => /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columns.length, className: "taskon-table__empty", children: /* @__PURE__ */ jsxs("div", { className: "taskon-table__empty-content", children: [
|
|
559
|
+
(empty == null ? void 0 : empty.icon) && /* @__PURE__ */ jsx("div", { className: "taskon-table__empty-icon", children: empty.icon }),
|
|
560
|
+
(empty == null ? void 0 : empty.title) && /* @__PURE__ */ jsx("p", { className: "taskon-table__empty-title", children: empty.title }),
|
|
561
|
+
(empty == null ? void 0 : empty.description) && /* @__PURE__ */ jsx("p", { className: "taskon-table__empty-desc", children: empty.description }),
|
|
562
|
+
!(empty == null ? void 0 : empty.title) && !(empty == null ? void 0 : empty.description) && /* @__PURE__ */ jsx("p", { className: "taskon-table__empty-title", children: "No data" })
|
|
563
|
+
] }) }) });
|
|
564
|
+
const renderRows = () => data.map((row, rowIndex) => {
|
|
565
|
+
var _a, _b, _c;
|
|
566
|
+
const rowKey = getRowKey(row, rowIndex);
|
|
567
|
+
const isHighlighted = ((_a = rowConfig == null ? void 0 : rowConfig.isHighlighted) == null ? void 0 : _a.call(rowConfig, row, rowIndex)) || false;
|
|
568
|
+
const isDisabled = ((_b = rowConfig == null ? void 0 : rowConfig.isDisabled) == null ? void 0 : _b.call(rowConfig, row, rowIndex)) || false;
|
|
569
|
+
const isClickable = !!(rowConfig == null ? void 0 : rowConfig.onRowClick);
|
|
570
|
+
const customRowClassName = ((_c = rowConfig == null ? void 0 : rowConfig.rowClassName) == null ? void 0 : _c.call(rowConfig, row, rowIndex)) || "";
|
|
571
|
+
const rowClassName = [
|
|
572
|
+
"taskon-table__row",
|
|
573
|
+
isHighlighted && "taskon-table__row--highlighted",
|
|
574
|
+
isDisabled && "taskon-table__row--disabled",
|
|
575
|
+
isClickable && "taskon-table__row--clickable",
|
|
576
|
+
customRowClassName
|
|
577
|
+
].filter(Boolean).join(" ");
|
|
578
|
+
const handleRowClick = () => {
|
|
579
|
+
var _a2;
|
|
580
|
+
if (isClickable && !isDisabled) {
|
|
581
|
+
(_a2 = rowConfig == null ? void 0 : rowConfig.onRowClick) == null ? void 0 : _a2.call(rowConfig, row, rowIndex);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
return /* @__PURE__ */ jsx("tr", { className: rowClassName, onClick: handleRowClick, children: columns.map((column) => {
|
|
585
|
+
const value = row[column.key];
|
|
586
|
+
const cellContent = column.render ? column.render(value, row, rowIndex) : value;
|
|
587
|
+
const cellClassName = [
|
|
588
|
+
"taskon-table__cell",
|
|
589
|
+
getCellAlignClassName(column.align),
|
|
590
|
+
column.ellipsis && "taskon-table__cell--ellipsis",
|
|
591
|
+
column.cellClassName
|
|
592
|
+
].filter(Boolean).join(" ");
|
|
593
|
+
return /* @__PURE__ */ jsx("td", { className: cellClassName, style: getColumnStyle(column), children: cellContent }, column.key);
|
|
594
|
+
}) }, rowKey);
|
|
595
|
+
});
|
|
596
|
+
const renderBody = () => {
|
|
597
|
+
if (!data || data.length === 0) {
|
|
598
|
+
if (loading) {
|
|
599
|
+
return renderLoading();
|
|
600
|
+
}
|
|
601
|
+
return renderEmpty();
|
|
602
|
+
}
|
|
603
|
+
return renderRows();
|
|
604
|
+
};
|
|
605
|
+
return /* @__PURE__ */ jsxs("div", { className: `taskon-table-container ${className}`, style, children: [
|
|
606
|
+
/* @__PURE__ */ jsxs("table", { className: tableClassName, children: [
|
|
607
|
+
renderHeader(),
|
|
608
|
+
/* @__PURE__ */ jsx("tbody", { className: "taskon-table__body", children: renderBody() })
|
|
609
|
+
] }),
|
|
610
|
+
loading && data && data.length > 0 && /* @__PURE__ */ jsx("div", { className: "taskon-table__loading-overlay", children: /* @__PURE__ */ jsx("div", { className: "taskon-table__loading-spinner" }) })
|
|
611
|
+
] });
|
|
612
|
+
}
|
|
613
|
+
function WidgetShell({
|
|
614
|
+
widgetId,
|
|
615
|
+
isConfigLoading,
|
|
616
|
+
cloudTheme,
|
|
617
|
+
themeMode,
|
|
618
|
+
className,
|
|
619
|
+
errorMessage,
|
|
620
|
+
children
|
|
621
|
+
}) {
|
|
622
|
+
const resolvedCloudTheme = useMemo(() => {
|
|
623
|
+
if (!cloudTheme) return void 0;
|
|
624
|
+
if (!themeMode) return cloudTheme;
|
|
625
|
+
return {
|
|
626
|
+
...cloudTheme,
|
|
627
|
+
mode: themeMode
|
|
628
|
+
};
|
|
629
|
+
}, [cloudTheme, themeMode]);
|
|
630
|
+
if (widgetId && isConfigLoading) {
|
|
631
|
+
return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsxs("div", { className: `${className}-loading`, children: [
|
|
632
|
+
/* @__PURE__ */ jsx("div", { className: `${className}-loading-spinner` }),
|
|
633
|
+
/* @__PURE__ */ jsx("span", { children: "Loading config..." })
|
|
634
|
+
] }) });
|
|
635
|
+
}
|
|
636
|
+
if (errorMessage) {
|
|
637
|
+
return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx("div", { className: `${className}-error`, children: /* @__PURE__ */ jsx(
|
|
638
|
+
"span",
|
|
639
|
+
{
|
|
640
|
+
className: `${className}-error-message`,
|
|
641
|
+
style: { overflowWrap: "anywhere", wordBreak: "break-word" },
|
|
642
|
+
children: errorMessage
|
|
643
|
+
}
|
|
644
|
+
) }) });
|
|
645
|
+
}
|
|
646
|
+
if (resolvedCloudTheme) {
|
|
647
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme: resolvedCloudTheme, children });
|
|
648
|
+
}
|
|
649
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
650
|
+
}
|
|
651
|
+
export {
|
|
652
|
+
Button as B,
|
|
653
|
+
Pagination as P,
|
|
654
|
+
Table as T,
|
|
655
|
+
WidgetShell as W,
|
|
656
|
+
usePagination as a,
|
|
657
|
+
cloudThemeToReactTheme as c,
|
|
658
|
+
useResolvedWidgetConfig as u
|
|
659
|
+
};
|