@taskon/widget-react 0.0.1-beta.1

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.
Files changed (48) hide show
  1. package/README.md +1065 -0
  2. package/dist/CommunityTaskList.css +4893 -0
  3. package/dist/EligibilityInfo.css +2337 -0
  4. package/dist/LeaderboardWidget.css +815 -0
  5. package/dist/PageBuilder.css +54 -0
  6. package/dist/Quest.css +4214 -0
  7. package/dist/TaskOnProvider.css +163 -0
  8. package/dist/TipPopover.css +210 -0
  9. package/dist/UserCenterWidget.css +297 -0
  10. package/dist/UserCenterWidget2.css +3519 -0
  11. package/dist/WidgetShell.css +182 -0
  12. package/dist/chunks/CommunityTaskList-DoPGZsw1.js +6813 -0
  13. package/dist/chunks/EligibilityInfo-C7GZ2G5u.js +22228 -0
  14. package/dist/chunks/LeaderboardWidget-CmYfDeHV.js +1068 -0
  15. package/dist/chunks/PageBuilder-Tmhf2GTS.js +150 -0
  16. package/dist/chunks/Quest-DKFZ-pPU.js +8839 -0
  17. package/dist/chunks/TaskOnProvider-BD6Vp2x8.js +1435 -0
  18. package/dist/chunks/ThemeProvider-wnSXrNQb.js +1118 -0
  19. package/dist/chunks/TipPopover-BrW8jo71.js +2926 -0
  20. package/dist/chunks/UserCenterWidget-BE329iS7.js +3546 -0
  21. package/dist/chunks/UserCenterWidget-BVw_IEEd.js +3989 -0
  22. package/dist/chunks/WidgetShell-D_5OjvNZ.js +1517 -0
  23. package/dist/chunks/common-ja-DWhTaFHb.js +23 -0
  24. package/dist/chunks/common-ko-80ezXsMG.js +23 -0
  25. package/dist/chunks/dynamic-import-helper-DxEFwm31.js +537 -0
  26. package/dist/chunks/index-CwMvO_wZ.js +777 -0
  27. package/dist/chunks/leaderboardwidget-ja-Bj6gz6y1.js +119 -0
  28. package/dist/chunks/leaderboardwidget-ko-f1cLO9ic.js +119 -0
  29. package/dist/chunks/useToast-B-wyO5zL.js +93 -0
  30. package/dist/chunks/useWidgetLocale-JDelxtt8.js +74 -0
  31. package/dist/chunks/usercenter-ja-uu-XfVF9.js +332 -0
  32. package/dist/chunks/usercenter-ko-DYgUOVzd.js +332 -0
  33. package/dist/community-task.d.ts +451 -0
  34. package/dist/community-task.js +9 -0
  35. package/dist/core.d.ts +803 -0
  36. package/dist/core.js +22 -0
  37. package/dist/dynamic-import-helper.css +389 -0
  38. package/dist/index.d.ts +1660 -0
  39. package/dist/index.js +41 -0
  40. package/dist/leaderboard.d.ts +547 -0
  41. package/dist/leaderboard.js +18 -0
  42. package/dist/page-builder.d.ts +20 -0
  43. package/dist/page-builder.js +4 -0
  44. package/dist/quest.d.ts +400 -0
  45. package/dist/quest.js +8 -0
  46. package/dist/user-center.d.ts +1780 -0
  47. package/dist/user-center.js +713 -0
  48. package/package.json +105 -0
@@ -0,0 +1,150 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect, useMemo, useRef } from "react";
3
+ import { DEFAULT_PAGE_BUILDER_CONFIG, createPageBuilderApi, parsePageBuilderConfig, SectionLayoutType, WidgetTypeEnum, SECTION_LAYOUT_RATIOS } from "@taskon/core";
4
+ import { Q as QuestWidget } from "./Quest-DKFZ-pPU.js";
5
+ import { a as CommunityTaskList } from "./CommunityTaskList-DoPGZsw1.js";
6
+ import { L as LeaderboardWidget } from "./LeaderboardWidget-CmYfDeHV.js";
7
+ import { U as UserCenterWidget } from "./UserCenterWidget-BVw_IEEd.js";
8
+ import { b as useTaskOnContext } from "./ThemeProvider-wnSXrNQb.js";
9
+ import '../PageBuilder.css';function usePageBuilderConfig(pageId, localConfig) {
10
+ const { client } = useTaskOnContext();
11
+ const [config, setConfig] = useState(
12
+ localConfig ?? null
13
+ );
14
+ const [pageInfo, setPageInfo] = useState(null);
15
+ const [isLoading, setIsLoading] = useState(false);
16
+ const [error, setError] = useState(null);
17
+ useEffect(() => {
18
+ if (localConfig) {
19
+ setConfig(localConfig ?? { ...DEFAULT_PAGE_BUILDER_CONFIG });
20
+ setPageInfo(null);
21
+ setIsLoading(false);
22
+ setError(null);
23
+ return;
24
+ }
25
+ if (!pageId || !client) {
26
+ setConfig(null);
27
+ setPageInfo(null);
28
+ setIsLoading(false);
29
+ setError(null);
30
+ return;
31
+ }
32
+ let cancelled = false;
33
+ setIsLoading(true);
34
+ setError(null);
35
+ const api = createPageBuilderApi(client);
36
+ api.getPageBuilder(pageId).then((info) => {
37
+ if (!cancelled) {
38
+ setPageInfo(info);
39
+ setConfig(parsePageBuilderConfig(info.config_json));
40
+ }
41
+ }).catch((err) => {
42
+ if (!cancelled) {
43
+ console.warn("[TaskOn] Failed to load page builder config:", err);
44
+ setError(
45
+ err instanceof Error ? err.message : "Failed to load page builder config"
46
+ );
47
+ }
48
+ }).finally(() => {
49
+ if (!cancelled) {
50
+ setIsLoading(false);
51
+ }
52
+ });
53
+ return () => {
54
+ cancelled = true;
55
+ };
56
+ }, [pageId, client, localConfig]);
57
+ return { config, pageInfo, isLoading, error };
58
+ }
59
+ const ROOT_CLASS = "taskon-page-builder";
60
+ function normalizeConfig(config) {
61
+ if (!config || !Array.isArray(config.sections)) return null;
62
+ return {
63
+ version: typeof config.version === "number" ? config.version : 1,
64
+ sections: Array.isArray(config.sections) ? config.sections : []
65
+ };
66
+ }
67
+ function getSlotFlex(section, index) {
68
+ const ratios = SECTION_LAYOUT_RATIOS[section.layout] ?? [1];
69
+ return ratios[index] ?? 1;
70
+ }
71
+ function renderWidget(slot) {
72
+ if (!slot.widgetId || !slot.widgetType) return null;
73
+ switch (slot.widgetType) {
74
+ case WidgetTypeEnum.Quest:
75
+ return /* @__PURE__ */ jsx(QuestWidget, { widgetId: slot.widgetId });
76
+ case WidgetTypeEnum.Tasks:
77
+ return /* @__PURE__ */ jsx(CommunityTaskList, { widgetId: slot.widgetId });
78
+ case WidgetTypeEnum.Leaderboard:
79
+ return /* @__PURE__ */ jsx(LeaderboardWidget, { widgetId: slot.widgetId });
80
+ case WidgetTypeEnum.UserCenter:
81
+ return /* @__PURE__ */ jsx(UserCenterWidget, { widgetId: slot.widgetId });
82
+ default:
83
+ console.warn("[TaskOn] Unknown widgetType in PageBuilder:", slot.widgetType);
84
+ return null;
85
+ }
86
+ }
87
+ function PageBuilder(props) {
88
+ const { pageId, config: localConfig, className, style } = props;
89
+ const { config, isLoading, error } = usePageBuilderConfig(
90
+ pageId,
91
+ localConfig
92
+ );
93
+ const resolvedConfig = useMemo(
94
+ () => normalizeConfig(config ?? localConfig),
95
+ [config, localConfig]
96
+ );
97
+ const errorMessage = error ?? (!resolvedConfig && !pageId && !localConfig ? "Page ID or config is required." : null);
98
+ const hasTrackedRef = useRef(false);
99
+ useEffect(() => {
100
+ if (hasTrackedRef.current) return;
101
+ if (!resolvedConfig) return;
102
+ hasTrackedRef.current = true;
103
+ }, [resolvedConfig]);
104
+ if (errorMessage) {
105
+ return /* @__PURE__ */ jsx("div", { className: `${ROOT_CLASS} ${className ?? ""}`, style, children: /* @__PURE__ */ jsx("div", { className: `${ROOT_CLASS}-error`, children: errorMessage }) });
106
+ }
107
+ if (isLoading) {
108
+ return /* @__PURE__ */ jsx("div", { className: `${ROOT_CLASS} ${className ?? ""}`, style, children: /* @__PURE__ */ jsx("div", { className: `${ROOT_CLASS}-loading`, children: "Loading page..." }) });
109
+ }
110
+ if (!resolvedConfig) {
111
+ return /* @__PURE__ */ jsx("div", { className: `${ROOT_CLASS} ${className ?? ""}`, style });
112
+ }
113
+ return /* @__PURE__ */ jsx("div", { className: `${ROOT_CLASS} ${className ?? ""}`, style, children: resolvedConfig.sections.map((section) => {
114
+ const isTwoColumn = section.layout !== SectionLayoutType.SingleColumn;
115
+ const sectionClass = [
116
+ `${ROOT_CLASS}-section`,
117
+ section.mobileStackOrder === "right-first" && isTwoColumn ? `${ROOT_CLASS}-section--stack-right-first` : ""
118
+ ].filter(Boolean).join(" ");
119
+ return /* @__PURE__ */ jsx(
120
+ "div",
121
+ {
122
+ className: sectionClass,
123
+ "data-layout": section.layout,
124
+ children: section.slots.map((slot, index) => {
125
+ const widgetNode = renderWidget(slot);
126
+ const isEmpty = !widgetNode;
127
+ return /* @__PURE__ */ jsx(
128
+ "div",
129
+ {
130
+ className: `${ROOT_CLASS}-slot ${isEmpty ? `${ROOT_CLASS}-slot--empty` : ""}`,
131
+ style: { flex: getSlotFlex(section, index) },
132
+ children: widgetNode ?? /* @__PURE__ */ jsx(
133
+ "div",
134
+ {
135
+ className: `${ROOT_CLASS}-slot-placeholder`,
136
+ "aria-hidden": "true"
137
+ }
138
+ )
139
+ },
140
+ slot.id
141
+ );
142
+ })
143
+ },
144
+ section.id
145
+ );
146
+ }) });
147
+ }
148
+ export {
149
+ PageBuilder as P
150
+ };