@taskon/widget-react 0.0.1 → 0.0.2
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 +118 -64
- package/dist/CommunityTaskList.css +2694 -2951
- package/dist/EligibilityInfo.css +2221 -1332
- package/dist/LeaderboardWidget.css +403 -198
- package/dist/PageBuilder.css +57 -0
- package/dist/Quest.css +1347 -1477
- package/dist/TaskOnProvider.css +337 -29
- package/dist/ThemeProvider.css +228 -0
- package/dist/UserCenterWidget.css +168 -0
- package/dist/UserCenterWidget2.css +4917 -0
- package/dist/WidgetShell.css +417 -130
- package/dist/chunks/{CommunityTaskList-CrH6r4Av.js → CommunityTaskList-2nFy6l6m.js} +2612 -2074
- package/dist/chunks/{EligibilityInfo-DesW9-k9.js → EligibilityInfo-CKTl_cdU.js} +2714 -4077
- package/dist/chunks/{LeaderboardWidget-BSGpHKTk.js → LeaderboardWidget-DyoiiNS6.js} +288 -349
- package/dist/chunks/PageBuilder-DHM3Il6f.js +150 -0
- package/dist/chunks/{Quest-uSIVq78I.js → Quest-Dqx4OCat.js} +1380 -726
- package/dist/chunks/TaskOnProvider-CxtFIs3n.js +2072 -0
- package/dist/chunks/{WidgetShell-NlOgn1x5.js → ThemeProvider-CulHkqqY.js} +1397 -103
- package/dist/chunks/UserCenterWidget-SE5hqpnZ.js +8335 -0
- package/dist/chunks/UserCenterWidget-XL6LZRZM.js +3259 -0
- package/dist/chunks/{Table-CWGf2FKV.js → WidgetShell-8xn-Jivw.js} +237 -27
- 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-CZm2CPoV.js +521 -0
- 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-Dyyy0zaw.js +863 -0
- package/dist/chunks/quest-ja-Depog33y.js +863 -0
- package/dist/chunks/quest-ko-BMu3uRQJ.js +863 -0
- package/dist/chunks/quest-ru-xne814Rw.js +863 -0
- package/dist/chunks/taskwidget-es-Do9b3Mqw.js +245 -0
- package/dist/chunks/taskwidget-ja-CqSu-yWA.js +245 -0
- package/dist/chunks/taskwidget-ko-EHgXFV4B.js +245 -0
- package/dist/chunks/taskwidget-ru-CMbLQDK4.js +245 -0
- package/dist/chunks/useIsMobile-D6Ybur-6.js +30 -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 +29 -388
- package/dist/community-task.js +2 -7
- package/dist/core.d.ts +95 -28
- package/dist/core.js +11 -12
- package/dist/index.d.ts +260 -602
- package/dist/index.js +28 -7361
- package/dist/leaderboard.d.ts +5 -496
- package/dist/leaderboard.js +2 -15
- package/dist/page-builder.d.ts +20 -0
- package/dist/page-builder.js +4 -0
- package/dist/quest.d.ts +20 -292
- package/dist/quest.js +2 -5
- package/dist/user-center.d.ts +56 -0
- package/dist/user-center.js +4 -0
- package/package.json +22 -3
- package/dist/Table.css +0 -389
- package/dist/chunks/TaskOnProvider-QMwxGL44.js +0 -1435
- package/dist/chunks/ThemeProvider-Cs8IUVQj.js +0 -1118
- package/dist/chunks/leaderboardwidget-ja-Bj6gz6y1.js +0 -119
- package/dist/chunks/leaderboardwidget-ko-f1cLO9ic.js +0 -119
- package/dist/chunks/useWidgetLocale-BVcopbZS.js +0 -74
- package/dist/chunks/usercenter-ja-DBj_dtuz.js +0 -329
- package/dist/chunks/usercenter-ko-DYTkHAld.js +0 -329
- package/dist/index.css +0 -3662
|
@@ -1,8 +1,176 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
1
|
import * as React from "react";
|
|
3
|
-
import { forwardRef } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
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");
|
|
6
174
|
var use = React[" use ".trim().toString()];
|
|
7
175
|
function isPromiseLike(value) {
|
|
8
176
|
return typeof value === "object" && value !== null && "then" in value;
|
|
@@ -122,7 +290,7 @@ const Button = forwardRef(
|
|
|
122
290
|
display: "inline-flex",
|
|
123
291
|
alignItems: "center",
|
|
124
292
|
justifyContent: "center",
|
|
125
|
-
gap: "var(--taskon-spacing-xs
|
|
293
|
+
gap: "var(--taskon-spacing-xs)",
|
|
126
294
|
fontFamily: "inherit",
|
|
127
295
|
fontWeight: 500,
|
|
128
296
|
lineHeight: 1.5,
|
|
@@ -138,55 +306,55 @@ const Button = forwardRef(
|
|
|
138
306
|
};
|
|
139
307
|
const sizeStyles = {
|
|
140
308
|
small: {
|
|
141
|
-
fontSize: "var(--taskon-font-size-sm
|
|
142
|
-
padding: isIconOnly ? "var(--taskon-spacing-xs
|
|
143
|
-
borderRadius: "var(--taskon-border-radius-sm
|
|
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)",
|
|
144
312
|
minWidth: isIconOnly ? "24px" : "64px",
|
|
145
313
|
height: "24px"
|
|
146
314
|
},
|
|
147
315
|
medium: {
|
|
148
|
-
fontSize: "var(--taskon-font-size
|
|
149
|
-
padding: isIconOnly ? "var(--taskon-spacing-xs
|
|
150
|
-
borderRadius: "var(--taskon-border-radius
|
|
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)",
|
|
151
319
|
minWidth: isIconOnly ? "32px" : "80px",
|
|
152
320
|
height: "32px"
|
|
153
321
|
},
|
|
154
322
|
large: {
|
|
155
|
-
fontSize: "var(--taskon-font-size-lg
|
|
156
|
-
padding: isIconOnly ? "var(--taskon-spacing-sm
|
|
157
|
-
borderRadius: "var(--taskon-border-radius
|
|
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)",
|
|
158
326
|
minWidth: isIconOnly ? "40px" : "96px",
|
|
159
327
|
height: "40px"
|
|
160
328
|
}
|
|
161
329
|
};
|
|
162
330
|
const variantStyles = {
|
|
163
331
|
primary: {
|
|
164
|
-
backgroundColor: "var(--taskon-color-primary
|
|
165
|
-
color: "
|
|
332
|
+
backgroundColor: "var(--taskon-color-primary)",
|
|
333
|
+
color: "var(--taskon-color-text-on-primary)"
|
|
166
334
|
},
|
|
167
335
|
secondary: {
|
|
168
|
-
backgroundColor: "var(--taskon-color-secondary
|
|
169
|
-
color: "
|
|
336
|
+
backgroundColor: "var(--taskon-color-secondary)",
|
|
337
|
+
color: "var(--taskon-color-text-on-primary)"
|
|
170
338
|
},
|
|
171
339
|
outline: {
|
|
172
340
|
backgroundColor: "transparent",
|
|
173
|
-
color: "var(--taskon-color-text
|
|
174
|
-
border: "1px solid var(--taskon-color-border
|
|
341
|
+
color: "var(--taskon-color-text)",
|
|
342
|
+
border: "1px solid var(--taskon-color-border)"
|
|
175
343
|
},
|
|
176
344
|
ghost: {
|
|
177
345
|
backgroundColor: "transparent",
|
|
178
|
-
color: "var(--taskon-color-text
|
|
346
|
+
color: "var(--taskon-color-text)"
|
|
179
347
|
},
|
|
180
348
|
danger: {
|
|
181
|
-
backgroundColor: "var(--taskon-color-error
|
|
182
|
-
color: "
|
|
349
|
+
backgroundColor: "var(--taskon-color-error)",
|
|
350
|
+
color: "var(--taskon-color-text-on-primary)"
|
|
183
351
|
}
|
|
184
352
|
};
|
|
185
353
|
const hoverStyles = {
|
|
186
|
-
primary: "hover:bg-[var(--taskon-color-primary-hover
|
|
354
|
+
primary: "hover:bg-[var(--taskon-color-primary-hover)] active:bg-[var(--taskon-color-primary-active)]",
|
|
187
355
|
secondary: "hover:opacity-90 active:opacity-80",
|
|
188
|
-
outline: "hover:bg-[var(--taskon-color-bg-
|
|
189
|
-
ghost: "hover:bg-[var(--taskon-color-bg-
|
|
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)]",
|
|
190
358
|
danger: "hover:opacity-90 active:opacity-80"
|
|
191
359
|
};
|
|
192
360
|
const mergedStyle = {
|
|
@@ -442,8 +610,50 @@ function Table({
|
|
|
442
610
|
loading && data && data.length > 0 && /* @__PURE__ */ jsx("div", { className: "taskon-table__loading-overlay", children: /* @__PURE__ */ jsx("div", { className: "taskon-table__loading-spinner" }) })
|
|
443
611
|
] });
|
|
444
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
|
+
}
|
|
445
651
|
export {
|
|
446
652
|
Button as B,
|
|
447
653
|
Pagination as P,
|
|
448
|
-
Table as T
|
|
654
|
+
Table as T,
|
|
655
|
+
WidgetShell as W,
|
|
656
|
+
usePagination as a,
|
|
657
|
+
cloudThemeToReactTheme as c,
|
|
658
|
+
useResolvedWidgetConfig as u
|
|
449
659
|
};
|