@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.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.
Files changed (89) hide show
  1. package/AGENTS.md +16 -0
  2. package/README.md +96 -0
  3. package/dist/chunk-AYQZO2FV.js +1496 -0
  4. package/dist/chunk-QDTU2FRN.js +1682 -0
  5. package/dist/client/index.d.ts +3 -3
  6. package/dist/client/index.js +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +2 -8
  9. package/dist/server/index.d.ts +2512 -608
  10. package/dist/server/index.js +1 -7
  11. package/dist/shop-guide-header-art-pea-v2-OME4MKBW.jpg +0 -0
  12. package/dist/shopping-guide-OQ2SSHXL.css +2593 -0
  13. package/package.json +25 -16
  14. package/skills/shopping-guide/SKILL.md +127 -24
  15. package/src/client/assets/shop-guide-header-art-pea-v2.jpg +0 -0
  16. package/src/client/assets/shop-guide-header-art.png +0 -0
  17. package/src/client/assets.d.ts +10 -0
  18. package/src/client/cards/category-list/index.tsx +113 -0
  19. package/src/client/cards/human-guide-list/index.tsx +72 -0
  20. package/src/client/cards/index.ts +14 -0
  21. package/src/client/cards/location-handoff/index.tsx +52 -0
  22. package/src/client/cards/mall-directory/index.tsx +77 -0
  23. package/src/client/cards/nearby-mall-list/index.tsx +40 -0
  24. package/src/client/cards/product-comparison/index.tsx +100 -0
  25. package/src/client/cards/product-detail/index.tsx +97 -0
  26. package/src/client/cards/product-list/index.tsx +223 -0
  27. package/src/client/cards/recommend-merchants/index.tsx +147 -0
  28. package/src/client/cards/shop-detail/index.tsx +133 -0
  29. package/src/client/cards/shop-list/index.tsx +216 -0
  30. package/src/client/cards/view.ts +147 -0
  31. package/src/client/categories.ts +38 -0
  32. package/src/client/components/ImageWithFallback.tsx +34 -0
  33. package/src/client/components/MerchantRow.tsx +78 -0
  34. package/src/client/components/ShopDetailSheet.tsx +383 -0
  35. package/src/client/components/ShopGuideHeader.tsx +24 -0
  36. package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
  37. package/src/client/components/ShopListSheet.tsx +293 -0
  38. package/src/client/index.ts +8 -6
  39. package/src/client/styles/shopping-guide.css +2593 -0
  40. package/src/client/types/css.d.ts +2 -0
  41. package/src/server/cards/category-list/meta.ts +0 -2
  42. package/src/server/cards/human-guide-list/meta.ts +0 -2
  43. package/src/server/cards/index.ts +10 -10
  44. package/src/server/cards/location-handoff/meta.ts +0 -2
  45. package/src/server/cards/mall-directory/meta.ts +0 -2
  46. package/src/server/cards/nearby-mall-list/meta.ts +1 -3
  47. package/src/server/cards/product-comparison/meta.ts +0 -2
  48. package/src/server/cards/product-detail/meta.ts +0 -2
  49. package/src/server/cards/product-list/meta.ts +0 -2
  50. package/src/server/cards/recommend-merchants/meta.ts +37 -0
  51. package/src/server/cards/recommend-merchants/samples.ts +189 -0
  52. package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
  53. package/src/server/cards/shop-detail/samples.ts +72 -0
  54. package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
  55. package/src/server/cards/shop-list/samples.ts +154 -0
  56. package/src/server/domain/value-objects.ts +1 -2
  57. package/src/server/handler.ts +63 -0
  58. package/src/server/index.ts +161 -101
  59. package/src/server/ports/index.ts +120 -91
  60. package/src/server/ports/local-adapters.ts +5 -55
  61. package/src/server/projections/index.ts +159 -41
  62. package/src/server/tools/index.ts +590 -315
  63. package/tbox.module.json +137 -0
  64. package/tests/cards-render.test.tsx +830 -0
  65. package/tests/floor-pretool.test.ts +275 -0
  66. package/tests/handler.test.ts +259 -0
  67. package/tests/merchant-list-limit.test.ts +53 -0
  68. package/tests/ports-resolve.test.ts +112 -0
  69. package/tests/samples.test.ts +71 -0
  70. package/tests/shopping-guide.test.ts +402 -234
  71. package/tests/skill.test.ts +86 -0
  72. package/tests/view.test.ts +42 -0
  73. package/tsup.config.ts +9 -1
  74. package/dist/chunk-AGBLC6XI.js +0 -1294
  75. package/dist/chunk-U4WDS5PQ.js +0 -173
  76. package/skills/shopping-guide/references/comparison-format.md +0 -5
  77. package/skills/shopping-guide/references/faq-answers.md +0 -5
  78. package/skills/shopping-guide/references/floor-directory.md +0 -4
  79. package/skills/shopping-guide/references/intent-patterns.md +0 -5
  80. package/skills/shopping-guide/references/location-format.md +0 -5
  81. package/skills/shopping-guide/references/policy-lookup.md +0 -5
  82. package/skills/shopping-guide/references/product-search-tips.md +0 -6
  83. package/skills/shopping-guide/references/recommendation-style.md +0 -5
  84. package/src/client/cards/index.tsx +0 -267
  85. package/src/server/cards/customer-service-faq/meta.ts +0 -18
  86. package/src/server/integrations/joycity/adapter.ts +0 -226
  87. package/src/server/integrations/joycity/auth-strategy.ts +0 -38
  88. package/src/server/integrations/joycity/gateway.ts +0 -128
  89. package/tbox.component.json +0 -48
@@ -0,0 +1,293 @@
1
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { MagnifyingGlass, X } from '@phosphor-icons/react';
4
+ import { MerchantRow } from './MerchantRow';
5
+ import { resolveCategoryTabs, type MerchantCategoryTab } from '../categories';
6
+ import type { ActionDraft } from '@tbox.cn/app-contracts-mall';
7
+
8
+ export interface ShopListSheetMerchant {
9
+ readonly merchantId: string;
10
+ readonly name: string;
11
+ readonly logoUrl?: string;
12
+ readonly coverUrl?: string;
13
+ readonly brand?: string;
14
+ readonly businessCategories: readonly string[];
15
+ readonly location: {
16
+ readonly buildingName?: string;
17
+ readonly floorName?: string;
18
+ readonly unitName?: string;
19
+ readonly displayText: string;
20
+ };
21
+ readonly status: { readonly code: 'enabled' | 'disabled' | 'unknown'; readonly label: string; readonly observedAt?: string };
22
+ readonly description?: string;
23
+ readonly contactInfo?: readonly { readonly channel: string; readonly value: string }[];
24
+ readonly services?: readonly string[];
25
+ readonly rating?: string;
26
+ readonly avgSpend?: string;
27
+ readonly operatingStatus?: string;
28
+ readonly itemActions?: readonly ActionDraft[];
29
+ }
30
+
31
+ function normalizeSearchText(value: string) {
32
+ return value.trim().toLocaleLowerCase();
33
+ }
34
+
35
+ function floorOrder(a: string, b: string) {
36
+ const parse = (value: string) => {
37
+ const normalized = value.trim().toUpperCase();
38
+ const basement = normalized.match(/^B(\d+)$/);
39
+ if (basement) return -Number(basement[1]);
40
+ const aboveGround = normalized.match(/^(?:L|F)?(\d+)F?$/);
41
+ if (aboveGround) return Number(aboveGround[1]);
42
+ return Number.POSITIVE_INFINITY;
43
+ };
44
+ const numeric = parse(a) - parse(b);
45
+ return Number.isNaN(numeric) || numeric === 0
46
+ ? a.localeCompare(b, 'zh-CN', { numeric: true })
47
+ : numeric;
48
+ }
49
+
50
+ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
51
+ readonly open: boolean;
52
+ readonly items: readonly T[];
53
+ readonly categoryTabs: readonly MerchantCategoryTab[];
54
+ readonly activeTabCode: string;
55
+ readonly isHistory: boolean;
56
+ readonly onSelect: (merchant: T) => void;
57
+ readonly onClose: () => void;
58
+ }) {
59
+ const { open, items, categoryTabs, activeTabCode, onSelect, onClose } = props;
60
+ const [query, setQuery] = useState('');
61
+ const [sheetTabCode, setSheetTabCode] = useState('');
62
+ const [activeFloor, setActiveFloor] = useState('');
63
+ const [closing, setClosing] = useState(false);
64
+ const panelRef = useRef<HTMLElement>(null);
65
+ const bodyRef = useRef<HTMLDivElement>(null);
66
+ const closeButtonRef = useRef<HTMLButtonElement>(null);
67
+ const closingRef = useRef(false);
68
+ const closeTimerRef = useRef<number>();
69
+ const onCloseRef = useRef(onClose);
70
+ onCloseRef.current = onClose;
71
+ const titleId = useId();
72
+ const searchId = useId();
73
+
74
+ const finishClose = useCallback(() => {
75
+ if (!closingRef.current) return;
76
+ window.clearTimeout(closeTimerRef.current);
77
+ closingRef.current = false;
78
+ setClosing(false);
79
+ onCloseRef.current();
80
+ }, []);
81
+
82
+ const requestClose = useCallback(() => {
83
+ if (closingRef.current) return;
84
+ closingRef.current = true;
85
+ setClosing(true);
86
+ const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false;
87
+ closeTimerRef.current = window.setTimeout(finishClose, reducedMotion ? 1 : 200);
88
+ }, [finishClose]);
89
+
90
+ const allCategories = useMemo(() => resolveCategoryTabs(categoryTabs, items), [categoryTabs, items]);
91
+
92
+ const activeCategory = allCategories.find((tab) => tab.code === sheetTabCode)?.name;
93
+ /** 业态 + 关键词命中的集合;楼层轨的清单与显示与否都以它为准。 */
94
+ const matchedItems = useMemo(() => {
95
+ const normalizedQuery = normalizeSearchText(query);
96
+ return items.filter((item) => {
97
+ if (activeCategory && !item.businessCategories.includes(activeCategory)) return false;
98
+ if (!normalizedQuery) return true;
99
+ return normalizeSearchText([
100
+ item.name,
101
+ item.brand,
102
+ ...item.businessCategories,
103
+ item.location.displayText,
104
+ ].filter(Boolean).join(' ')).includes(normalizedQuery);
105
+ });
106
+ }, [activeCategory, items, query]);
107
+
108
+ /*
109
+ * 楼层轨是**筛选**不是大纲:点一层只留那一层的门店,不再滚动定位。因此列表不按楼层排序,
110
+ * 保持搜索/业态给出的原有顺序。
111
+ *
112
+ * 楼层清单必须从**未按楼层筛选**的 matchedItems 算——若从最终结果算,选中某层后清单会
113
+ * 塌成一项、`showFloorRail` 随即为假,整条轨消失,用户再也退不回全部。
114
+ *
115
+ * 降序排列(高层在上):商场的楼层图与电梯面板都是这个方向,升序会与人的空间直觉相反。
116
+ */
117
+ const floorNames = useMemo(() => [...new Set(
118
+ matchedItems.map((item) => item.location.floorName?.trim()).filter((floor): floor is string => Boolean(floor)),
119
+ )].sort((a, b) => floorOrder(b, a)), [matchedItems]);
120
+ const showFloorRail = floorNames.length >= 2 && matchedItems.length >= 5;
121
+
122
+ const filteredItems = useMemo(
123
+ () => (activeFloor ? matchedItems.filter((item) => item.location.floorName?.trim() === activeFloor) : matchedItems),
124
+ [activeFloor, matchedItems],
125
+ );
126
+
127
+ // 筛选变化后重置滚动到顶部(2026-09-04 实证:快速滑动深处切业态,列表变短而 scrollTop
128
+ // 停在原位——视口落在内容之外呈"白屏",再点一次触发渲染/滚动钳制才恢复)。
129
+ // 搜索输入逐字符重置同语义(结果变化从头部看起)。
130
+ useEffect(() => {
131
+ bodyRef.current?.scrollTo({ top: 0 });
132
+ }, [sheetTabCode, activeFloor, query]);
133
+
134
+ // 楼层集合变了(换业态、改搜索词)而当前选中层已不在其中时退回「全部」,
135
+ // 不擅自替用户选另一层。
136
+ useEffect(() => {
137
+ setActiveFloor((current) => (current && floorNames.includes(current) ? current : ''));
138
+ }, [floorNames]);
139
+
140
+ useEffect(() => {
141
+ if (!open) return;
142
+ setQuery('');
143
+ setSheetTabCode(allCategories.some((tab) => tab.code === activeTabCode) ? activeTabCode : '');
144
+ closingRef.current = false;
145
+ setClosing(false);
146
+ const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
147
+ const previousOverflow = document.body.style.overflow;
148
+ document.body.style.overflow = 'hidden';
149
+ closeButtonRef.current?.focus();
150
+
151
+ const onKeyDown = (event: KeyboardEvent) => {
152
+ if (event.key === 'Escape') {
153
+ event.preventDefault();
154
+ requestClose();
155
+ return;
156
+ }
157
+ if (event.key !== 'Tab') return;
158
+ const focusable = panelRef.current?.querySelectorAll<HTMLElement>(
159
+ 'button:not(:disabled), input:not(:disabled), a[href], [tabindex]:not([tabindex="-1"])',
160
+ );
161
+ if (!focusable || focusable.length === 0) return;
162
+ const first = focusable[0];
163
+ const last = focusable[focusable.length - 1];
164
+ if (event.shiftKey && document.activeElement === first) {
165
+ event.preventDefault();
166
+ last.focus();
167
+ } else if (!event.shiftKey && document.activeElement === last) {
168
+ event.preventDefault();
169
+ first.focus();
170
+ }
171
+ };
172
+ document.addEventListener('keydown', onKeyDown);
173
+ return () => {
174
+ document.removeEventListener('keydown', onKeyDown);
175
+ document.body.style.overflow = previousOverflow;
176
+ previousFocus?.focus();
177
+ };
178
+ }, [activeTabCode, allCategories, open, requestClose]);
179
+
180
+ useEffect(() => () => window.clearTimeout(closeTimerRef.current), []);
181
+
182
+ if (!open || typeof document === 'undefined') return null;
183
+
184
+ return createPortal(
185
+ <div
186
+ className={`sg-store-list-sheet${closing ? ' sg-store-list-sheet--closing' : ''}`}
187
+ role="presentation"
188
+ onAnimationEnd={(event) => {
189
+ if (closing && event.target === event.currentTarget) finishClose();
190
+ }}
191
+ >
192
+ <div className="sg-store-list-sheet__mask" aria-hidden="true" onClick={requestClose} />
193
+ <section ref={panelRef} className="sg-store-list-sheet__panel" role="dialog" aria-modal="true" aria-labelledby={titleId}>
194
+ <header className="sg-store-list-sheet__header">
195
+ <h2 id={titleId}>门店导览</h2>
196
+ <button ref={closeButtonRef} type="button" className="sg-store-list-sheet__close" aria-label="关闭门店列表" onClick={requestClose}>
197
+ <X size={20} weight="bold" />
198
+ </button>
199
+ </header>
200
+
201
+ <div className="sg-store-list-sheet__search">
202
+ <label className="sg-visually-hidden" htmlFor={searchId}>搜索门店</label>
203
+ <MagnifyingGlass size={18} aria-hidden="true" />
204
+ <input
205
+ id={searchId}
206
+ type="search"
207
+ value={query}
208
+ placeholder="请输入要搜索的店铺名"
209
+ onChange={(event) => setQuery(event.target.value)}
210
+ />
211
+ {query && (
212
+ <button type="button" aria-label="清空门店搜索" onClick={() => setQuery('')}>
213
+ <X size={14} weight="bold" />
214
+ </button>
215
+ )}
216
+ </div>
217
+
218
+ <div className="sg-store-list-sheet__content">
219
+ <nav className="sg-store-list-sheet__categories" aria-label="按门店业态筛选">
220
+ <button
221
+ type="button"
222
+ className={!sheetTabCode ? 'is-active' : undefined}
223
+ aria-pressed={!sheetTabCode}
224
+ onClick={() => setSheetTabCode('')}
225
+ >
226
+ 全部
227
+ </button>
228
+ {allCategories.map((tab) => {
229
+ const isActive = sheetTabCode === tab.code;
230
+ return (
231
+ <button
232
+ key={tab.code}
233
+ type="button"
234
+ className={isActive ? 'is-active' : undefined}
235
+ aria-pressed={isActive}
236
+ onClick={() => setSheetTabCode(tab.code)}
237
+ >
238
+ {tab.name}
239
+ </button>
240
+ );
241
+ })}
242
+ </nav>
243
+
244
+ <div ref={bodyRef} className="sg-store-list-sheet__body">
245
+ <p className="sg-store-list-sheet__count" aria-live="polite">当前显示 {filteredItems.length} 家门店</p>
246
+ {filteredItems.length === 0 ? (
247
+ <div className="sg-store-list-sheet__empty">暂时没有符合条件的门店</div>
248
+ ) : (
249
+ <ul className="sg-store-list-sheet__list">
250
+ {filteredItems.map((item) => (
251
+ <li key={item.merchantId}>
252
+ <MerchantRow
253
+ merchant={item}
254
+ className="sg-store-list-sheet__item"
255
+ onSelect={() => onSelect(item)}
256
+ />
257
+ </li>
258
+ ))}
259
+ </ul>
260
+ )}
261
+ </div>
262
+
263
+ {showFloorRail && (
264
+ <nav className="sg-store-list-sheet__floors" aria-label="按楼层筛选">
265
+ {/* 显式的「全」而非再点一次取消:这条轨是窄条,选中态之外没有别的地方能提示
266
+ 「还能退回全部」,靠隐式 toggle 会把人卡在某一层里。 */}
267
+ <button
268
+ type="button"
269
+ className={!activeFloor ? 'is-active' : undefined}
270
+ aria-pressed={!activeFloor}
271
+ onClick={() => setActiveFloor('')}
272
+ >
273
+ 全
274
+ </button>
275
+ {floorNames.map((floor) => (
276
+ <button
277
+ key={floor}
278
+ type="button"
279
+ className={activeFloor === floor ? 'is-active' : undefined}
280
+ aria-pressed={activeFloor === floor}
281
+ onClick={() => setActiveFloor(floor)}
282
+ >
283
+ {floor}
284
+ </button>
285
+ ))}
286
+ </nav>
287
+ )}
288
+ </div>
289
+ </section>
290
+ </div>,
291
+ document.body,
292
+ );
293
+ }
@@ -1,34 +1,36 @@
1
1
  /**
2
2
  * module-shopping-guide 客户端入口(与服务端 serverModule 对称)。
3
3
  */
4
+ import './styles/shopping-guide.css'; // 0.4.0 D1:模块自持 CSS(副作用 import,首行保证先行加载)
5
+
4
6
  import type { CardComponent } from '@tbox.cn/app-contracts';
5
7
  import type { ClientContext, ClientModule } from '@tbox.cn/app-sdk/client';
6
8
  import {
7
9
  ProductListCard,
8
10
  ProductDetailCard,
9
- MerchantListCard,
10
- MerchantDetailCard,
11
+ ShopListCard,
12
+ ShopDetailCard,
11
13
  CategoryListCard,
12
14
  ProductComparisonCard,
13
15
  MallDirectoryCard,
14
16
  NearbyMallListCard,
15
- CustomerServiceFaqCard,
16
17
  HumanGuideListCard,
17
18
  LocationHandoffCard,
19
+ RecommendMerchantsCard,
18
20
  } from './cards';
19
21
 
20
22
  const cards = {
21
23
  'product-list': ProductListCard as CardComponent,
22
24
  'product-detail': ProductDetailCard as CardComponent,
23
- 'merchant-list': MerchantListCard as CardComponent,
24
- 'merchant-detail': MerchantDetailCard as CardComponent,
25
+ 'shop-list': ShopListCard as CardComponent,
26
+ 'shop-detail': ShopDetailCard as CardComponent,
25
27
  'category-list': CategoryListCard as CardComponent,
26
28
  'product-comparison': ProductComparisonCard as CardComponent,
27
29
  'mall-directory': MallDirectoryCard as CardComponent,
28
30
  'nearby-mall-list': NearbyMallListCard as CardComponent,
29
- 'customer-service-faq': CustomerServiceFaqCard as CardComponent,
30
31
  'human-guide-list': HumanGuideListCard as CardComponent,
31
32
  'location-handoff': LocationHandoffCard as CardComponent,
33
+ 'recommend-merchants': RecommendMerchantsCard as CardComponent,
32
34
  } as const;
33
35
 
34
36
  export const clientModule = {