@tbox.cn/app-module-shopping-guide 0.9.12 → 1.0.0-alpha.10
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/AGENTS.md +3 -3
- package/dist/chunk-MBJPTP72.js +1692 -0
- package/dist/client/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/server/index.d.ts +696 -696
- package/package.json +12 -9
- package/src/client/cards/category-list/index.tsx +17 -17
- package/src/client/cards/human-guide-list/index.tsx +17 -14
- package/src/client/cards/location-handoff/index.tsx +10 -10
- package/src/client/cards/mall-directory/index.tsx +14 -14
- package/src/client/cards/nearby-mall-list/index.tsx +29 -11
- package/src/client/cards/product-comparison/index.tsx +29 -18
- package/src/client/cards/product-detail/index.tsx +41 -25
- package/src/client/cards/product-list/index.tsx +74 -54
- package/src/client/cards/recommend-merchants/index.tsx +19 -9
- package/src/client/cards/shop-detail/index.tsx +13 -9
- package/src/client/cards/shop-list/index.tsx +19 -9
- package/src/client/components/ImageWithFallback.tsx +1 -1
- package/src/client/components/MerchantRow.tsx +23 -13
- package/src/client/components/ShopDetailSheet.tsx +94 -131
- package/src/client/components/ShopGuideHeader.tsx +6 -6
- package/src/client/components/ShopGuideSectionLabel.tsx +1 -1
- package/src/client/components/ShopListSheet.tsx +58 -96
- package/src/client/index.ts +0 -2
- package/tbox.module.json +0 -1
- package/tests/cards-render.test.tsx +40 -7
- package/tsup.config.ts +0 -5
- package/dist/chunk-PAYDOSCV.js +0 -1676
- package/dist/shopping-guide-62BDCPW5.css +0 -2600
- package/src/client/styles/shopping-guide.css +0 -2600
- package/src/client/types/css.d.ts +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
1
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
2
|
import { MagnifyingGlass, X } from '@phosphor-icons/react';
|
|
3
|
+
import { Overlay } from '@tbox.cn/app-agent-ui-kit/overlay';
|
|
4
4
|
import { MerchantRow } from './MerchantRow';
|
|
5
5
|
import { resolveCategoryTabs, type MerchantCategoryTab } from '../categories';
|
|
6
6
|
import type { ActionDraft } from '@tbox.cn/app-contracts-mall';
|
|
@@ -47,6 +47,20 @@ function floorOrder(a: string, b: string) {
|
|
|
47
47
|
: numeric;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const SHEET_ROOT_CLASS = 'sg-store-list-sheet group text-foreground group-data-[state=closed]:animate-[sg-shop-sheet-out_180ms_ease-in_both] motion-reduce:animate-none';
|
|
51
|
+
const SHEET_PANEL_CLASS =
|
|
52
|
+
'sg-store-list-sheet__panel flex h-[86vh] max-h-[86vh] w-[min(100%,375px)] flex-col overflow-hidden rounded-t-[18px] bg-white shadow-[0_-8px_24px_rgba(24,31,27,0.18)] animate-[sg-shop-sheet-in_240ms_cubic-bezier(0.22,0.72,0.24,1)_both] group-data-[state=closed]:animate-[sg-shop-sheet-down_180ms_ease-in_both] motion-reduce:animate-none';
|
|
53
|
+
/** 业态按钮:选中态(is-active)与默认态各一串完整字面量,避免拼接。 */
|
|
54
|
+
const CATEGORY_BUTTON_CLASS =
|
|
55
|
+
'relative min-h-[46px] shrink-0 border-0 bg-transparent px-[9px] py-[7px] text-center text-sm leading-4.5 text-[#4f5551] [font-family:inherit] focus-visible:z-[1] focus-visible:outline-[1.5px] focus-visible:outline-offset-[-1.5px] focus-visible:outline-[rgba(45,98,69,0.2)] max-[700px]:px-[5px] max-[700px]:text-xs';
|
|
56
|
+
const CATEGORY_BUTTON_ACTIVE_CLASS =
|
|
57
|
+
'is-active relative min-h-[46px] shrink-0 border-0 bg-white px-[9px] py-[7px] text-center text-sm leading-4.5 font-bold text-[#273c2d] [font-family:inherit] before:absolute before:top-[13px] before:bottom-[13px] before:left-0 before:w-[3px] before:rounded-r-[3px] before:bg-[#6c8753] focus-visible:z-[1] focus-visible:outline-[1.5px] focus-visible:outline-offset-[-1.5px] focus-visible:outline-[rgba(45,98,69,0.2)] max-[700px]:px-[5px] max-[700px]:text-xs';
|
|
58
|
+
/** 楼层按钮:同上,两态各一串。 */
|
|
59
|
+
const FLOOR_BUTTON_CLASS =
|
|
60
|
+
'min-h-[23px] border-0 bg-transparent px-[3px] text-xs text-[#7c827e] [font-family:inherit] focus-visible:z-[1] focus-visible:outline-[1.5px] focus-visible:outline-offset-[-1.5px] focus-visible:outline-[rgba(45,98,69,0.2)]';
|
|
61
|
+
const FLOOR_BUTTON_ACTIVE_CLASS =
|
|
62
|
+
'is-active min-h-[23px] border-0 bg-[#30372f] px-[3px] text-xs text-white [font-family:inherit] focus-visible:z-[1] focus-visible:outline-[1.5px] focus-visible:outline-offset-[-1.5px] focus-visible:outline-[rgba(45,98,69,0.2)]';
|
|
63
|
+
|
|
50
64
|
export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
51
65
|
readonly open: boolean;
|
|
52
66
|
readonly items: readonly T[];
|
|
@@ -60,33 +74,11 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
60
74
|
const [query, setQuery] = useState('');
|
|
61
75
|
const [sheetTabCode, setSheetTabCode] = useState('');
|
|
62
76
|
const [activeFloor, setActiveFloor] = useState('');
|
|
63
|
-
const [closing, setClosing] = useState(false);
|
|
64
|
-
const panelRef = useRef<HTMLElement>(null);
|
|
65
77
|
const bodyRef = useRef<HTMLDivElement>(null);
|
|
66
78
|
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
79
|
const titleId = useId();
|
|
72
80
|
const searchId = useId();
|
|
73
81
|
|
|
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
82
|
const allCategories = useMemo(() => resolveCategoryTabs(categoryTabs, items), [categoryTabs, items]);
|
|
91
83
|
|
|
92
84
|
const activeCategory = allCategories.find((tab) => tab.code === sheetTabCode)?.name;
|
|
@@ -137,69 +129,40 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
137
129
|
setActiveFloor((current) => (current && floorNames.includes(current) ? current : ''));
|
|
138
130
|
}, [floorNames]);
|
|
139
131
|
|
|
132
|
+
// 只在「打开」这一刻复位筛选项:依赖里带上 allCategories 会让 effect 每次渲染都重跑。
|
|
133
|
+
const wasOpenRef = useRef(false);
|
|
140
134
|
useEffect(() => {
|
|
141
|
-
if (!open)
|
|
135
|
+
if (!open) {
|
|
136
|
+
wasOpenRef.current = false;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (wasOpenRef.current) return;
|
|
140
|
+
wasOpenRef.current = true;
|
|
142
141
|
setQuery('');
|
|
143
142
|
setSheetTabCode(allCategories.some((tab) => tab.code === activeTabCode) ? activeTabCode : '');
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
}}
|
|
143
|
+
}, [activeTabCode, allCategories, open]);
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<Overlay
|
|
147
|
+
open={open}
|
|
148
|
+
onDismiss={onClose}
|
|
149
|
+
placement="bottom"
|
|
150
|
+
labelledBy={titleId}
|
|
151
|
+
initialFocus={closeButtonRef}
|
|
152
|
+
exitMs={220}
|
|
153
|
+
rootClassName={SHEET_ROOT_CLASS}
|
|
154
|
+
maskClassName="bg-[rgba(18,21,19,0.52)] backdrop-blur-[2px]"
|
|
155
|
+
panelClassName={SHEET_PANEL_CLASS}
|
|
191
156
|
>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<h2 id={titleId}>门店导览</h2>
|
|
196
|
-
<button ref={closeButtonRef} type="button" className="sg-store-list-sheet__close" aria-label="关闭门店列表" onClick={requestClose}>
|
|
157
|
+
<header className="sg-store-list-sheet__header flex min-h-[52px] shrink-0 items-center pt-[9px] pr-3 pb-[5px] pl-[18px]">
|
|
158
|
+
<h2 id={titleId} className="flex min-w-0 flex-1 items-center justify-center gap-[5px] pl-7 text-lg leading-6">门店导览</h2>
|
|
159
|
+
<button ref={closeButtonRef} type="button" className="sg-store-list-sheet__close flex size-7 shrink-0 items-center justify-center rounded-full border-0 bg-transparent p-0 text-[#343936] focus-visible:outline-[1.5px] focus-visible:outline-offset-[1px] focus-visible:outline-[rgba(9,107,250,0.28)]" aria-label="关闭门店列表" onClick={onClose}>
|
|
197
160
|
<X size={20} weight="bold" />
|
|
198
161
|
</button>
|
|
199
162
|
</header>
|
|
200
163
|
|
|
201
|
-
<div className="sg-store-list-sheet__search">
|
|
202
|
-
<label className="sg-visually-hidden" htmlFor={searchId}>搜索门店</label>
|
|
164
|
+
<div className="sg-store-list-sheet__search mx-[15px] mt-[2px] mb-[9px] flex min-h-[38px] shrink-0 items-center gap-[7px] rounded-[9px] bg-[#f2f3f2] px-[11px] text-[#777d79] focus-within:shadow-[0_0_0_1.5px_rgba(45,98,69,0.16)]">
|
|
165
|
+
<label className="sg-visually-hidden sr-only" htmlFor={searchId}>搜索门店</label>
|
|
203
166
|
<MagnifyingGlass size={18} aria-hidden="true" />
|
|
204
167
|
<input
|
|
205
168
|
id={searchId}
|
|
@@ -207,19 +170,20 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
207
170
|
value={query}
|
|
208
171
|
placeholder="请输入要搜索的店铺名"
|
|
209
172
|
onChange={(event) => setQuery(event.target.value)}
|
|
173
|
+
className="h-[34px] min-w-0 flex-1 appearance-none rounded-none border-0 bg-transparent p-0 text-sm text-[#242724] [font-family:inherit] outline-none placeholder:text-[#a7aba8] [&::-webkit-search-cancel-button]:hidden"
|
|
210
174
|
/>
|
|
211
175
|
{query && (
|
|
212
|
-
<button type="button" aria-label="清空门店搜索" onClick={() => setQuery('')}>
|
|
176
|
+
<button type="button" className="flex size-6 shrink-0 items-center justify-center rounded-full border-0 bg-[#dadeda] p-0 text-[#5f6561]" aria-label="清空门店搜索" onClick={() => setQuery('')}>
|
|
213
177
|
<X size={14} weight="bold" />
|
|
214
178
|
</button>
|
|
215
179
|
)}
|
|
216
180
|
</div>
|
|
217
181
|
|
|
218
|
-
<div className="sg-store-list-sheet__content">
|
|
219
|
-
<nav className="sg-store-list-sheet__categories" aria-label="按门店业态筛选">
|
|
182
|
+
<div className="sg-store-list-sheet__content relative grid min-h-0 flex-1 grid-cols-[82px_minmax(0,1fr)] overflow-hidden border-t-[0.5px] border-[#f0f1ef] max-[700px]:grid-cols-[74px_minmax(0,1fr)]">
|
|
183
|
+
<nav className="sg-store-list-sheet__categories flex min-h-0 flex-col overflow-y-auto bg-[#f5f6f7] pt-[7px] pb-[calc(22px_+_env(safe-area-inset-bottom))] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden" aria-label="按门店业态筛选">
|
|
220
184
|
<button
|
|
221
185
|
type="button"
|
|
222
|
-
className={!sheetTabCode ?
|
|
186
|
+
className={!sheetTabCode ? CATEGORY_BUTTON_ACTIVE_CLASS : CATEGORY_BUTTON_CLASS}
|
|
223
187
|
aria-pressed={!sheetTabCode}
|
|
224
188
|
onClick={() => setSheetTabCode('')}
|
|
225
189
|
>
|
|
@@ -231,7 +195,7 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
231
195
|
<button
|
|
232
196
|
key={tab.code}
|
|
233
197
|
type="button"
|
|
234
|
-
className={isActive ?
|
|
198
|
+
className={isActive ? CATEGORY_BUTTON_ACTIVE_CLASS : CATEGORY_BUTTON_CLASS}
|
|
235
199
|
aria-pressed={isActive}
|
|
236
200
|
onClick={() => setSheetTabCode(tab.code)}
|
|
237
201
|
>
|
|
@@ -241,17 +205,17 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
241
205
|
})}
|
|
242
206
|
</nav>
|
|
243
207
|
|
|
244
|
-
<div ref={bodyRef} className="sg-store-list-sheet__body">
|
|
245
|
-
<p className="sg-store-list-sheet__count" aria-live="polite">当前显示 {filteredItems.length} 家门店</p>
|
|
208
|
+
<div ref={bodyRef} className="sg-store-list-sheet__body min-h-0 min-w-0 flex-1 overflow-y-auto bg-[#f7f8f6] px-3 pb-[calc(27px_+_env(safe-area-inset-bottom))] [scroll-padding-top:30px] [&::-webkit-scrollbar]:hidden max-[700px]:px-[9px]">
|
|
209
|
+
<p className="sg-store-list-sheet__count sticky top-0 z-[2] -mx-px bg-[rgba(247,248,246,0.96)] px-px pt-[9px] pb-[5px] text-xs leading-[15px] text-[#939894]" aria-live="polite">当前显示 {filteredItems.length} 家门店</p>
|
|
246
210
|
{filteredItems.length === 0 ? (
|
|
247
|
-
<div className="sg-store-list-sheet__empty">暂时没有符合条件的门店</div>
|
|
211
|
+
<div className="sg-store-list-sheet__empty px-2.5 py-16 text-center text-sm text-secondary-foreground">暂时没有符合条件的门店</div>
|
|
248
212
|
) : (
|
|
249
|
-
<ul className="sg-store-list-sheet__list">
|
|
213
|
+
<ul className="sg-store-list-sheet__list m-0 flex list-none flex-col gap-2 p-0">
|
|
250
214
|
{filteredItems.map((item) => (
|
|
251
|
-
<li key={item.merchantId}>
|
|
215
|
+
<li key={item.merchantId} className="border-0 [scroll-margin-top:32px]">
|
|
252
216
|
<MerchantRow
|
|
253
217
|
merchant={item}
|
|
254
|
-
className="sg-store-list-sheet__item"
|
|
218
|
+
className="sg-store-list-sheet__item min-h-[86px] items-center rounded-[9px] bg-white p-[9px] shadow-[0_2px_8px_rgba(34,42,37,0.05)] focus-visible:rounded-[8px] focus-visible:outline-offset-[1.5px] disabled:cursor-default disabled:opacity-72"
|
|
255
219
|
onSelect={() => onSelect(item)}
|
|
256
220
|
/>
|
|
257
221
|
</li>
|
|
@@ -261,12 +225,12 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
261
225
|
</div>
|
|
262
226
|
|
|
263
227
|
{showFloorRail && (
|
|
264
|
-
<nav className="sg-store-list-sheet__floors" aria-label="按楼层筛选">
|
|
228
|
+
<nav className="sg-store-list-sheet__floors absolute right-1 bottom-[calc(30px_+_env(safe-area-inset-bottom))] z-[3] flex w-[35px] flex-col overflow-hidden rounded-[15px] border-[0.5px] border-[#eceeeb] bg-[rgba(255,255,255,0.95)] py-1 shadow-[0_3px_10px_rgba(29,36,31,0.12)]" aria-label="按楼层筛选">
|
|
265
229
|
{/* 显式的「全」而非再点一次取消:这条轨是窄条,选中态之外没有别的地方能提示
|
|
266
230
|
「还能退回全部」,靠隐式 toggle 会把人卡在某一层里。 */}
|
|
267
231
|
<button
|
|
268
232
|
type="button"
|
|
269
|
-
className={!activeFloor ?
|
|
233
|
+
className={!activeFloor ? FLOOR_BUTTON_ACTIVE_CLASS : FLOOR_BUTTON_CLASS}
|
|
270
234
|
aria-pressed={!activeFloor}
|
|
271
235
|
onClick={() => setActiveFloor('')}
|
|
272
236
|
>
|
|
@@ -276,7 +240,7 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
276
240
|
<button
|
|
277
241
|
key={floor}
|
|
278
242
|
type="button"
|
|
279
|
-
className={activeFloor === floor ?
|
|
243
|
+
className={activeFloor === floor ? FLOOR_BUTTON_ACTIVE_CLASS : FLOOR_BUTTON_CLASS}
|
|
280
244
|
aria-pressed={activeFloor === floor}
|
|
281
245
|
onClick={() => setActiveFloor(floor)}
|
|
282
246
|
>
|
|
@@ -286,8 +250,6 @@ export function ShopListSheet<T extends ShopListSheetMerchant>(props: {
|
|
|
286
250
|
</nav>
|
|
287
251
|
)}
|
|
288
252
|
</div>
|
|
289
|
-
|
|
290
|
-
</div>,
|
|
291
|
-
document.body,
|
|
253
|
+
</Overlay>
|
|
292
254
|
);
|
|
293
255
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* module-shopping-guide 客户端入口(与服务端 serverModule 对称)。
|
|
3
3
|
*/
|
|
4
|
-
import './styles/shopping-guide.css'; // 0.4.0 模块自持 CSS(副作用 import,首行保证先行加载)
|
|
5
|
-
|
|
6
4
|
import type { CardComponent } from '@tbox.cn/app-contracts';
|
|
7
5
|
import type { ClientContext, ClientModule } from '@tbox.cn/app-agent-sdk-client';
|
|
8
6
|
import {
|
package/tbox.module.json
CHANGED
|
@@ -318,14 +318,14 @@ describe('门店导览无权益内容', () => {
|
|
|
318
318
|
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(1);
|
|
319
319
|
const listSheet = document.body.querySelector('.sg-store-list-sheet') as HTMLElement;
|
|
320
320
|
act(() => (document.body.querySelector('[aria-label="关闭门店列表"]') as HTMLButtonElement).click());
|
|
321
|
-
expect(listSheet.
|
|
321
|
+
expect(listSheet.getAttribute('data-state')).toBe('closed');
|
|
322
322
|
act(() => listSheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
323
323
|
// 浮层里的选择不回写卡内:卡内仍停在「全部」,其余品类 tab 均未选中。
|
|
324
324
|
const cardTabs = Array.from(host.querySelectorAll('.sg-rm-tab'));
|
|
325
325
|
expect(cardTabs[0].getAttribute('aria-pressed')).toBe('true');
|
|
326
326
|
expect(cardTabs.slice(1).every((tab) => tab.getAttribute('aria-pressed') === 'false')).toBe(true);
|
|
327
327
|
act(() => (host.querySelector('.sg-rm-view-all') as HTMLButtonElement).click());
|
|
328
|
-
expect(document.body.querySelector('.sg-store-list-sheet')?.
|
|
328
|
+
expect(document.body.querySelector('.sg-store-list-sheet')?.getAttribute('data-state')).toBe('open');
|
|
329
329
|
expect(document.body.querySelector('.sg-store-list-sheet__categories button[aria-pressed="true"]')?.textContent).toBe('全部');
|
|
330
330
|
});
|
|
331
331
|
|
|
@@ -606,6 +606,38 @@ describe('门店导览无权益内容', () => {
|
|
|
606
606
|
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('当前门店详情');
|
|
607
607
|
});
|
|
608
608
|
|
|
609
|
+
it('关闭后退场动画期间保留最后一份详情快照,且迟到响应不会把弹层顶开', async () => {
|
|
610
|
+
let resolveRequest!: (value: unknown) => void;
|
|
611
|
+
const pending = new Promise<unknown>((resolve) => { resolveRequest = resolve; });
|
|
612
|
+
vi.mocked(httpGet).mockReturnValueOnce(pending as never);
|
|
613
|
+
const { host } = render(
|
|
614
|
+
<ShopDetailCard
|
|
615
|
+
data={{ ...merchant, mallId: 'mall-1', miniAppId: 'mini-1', coverUrls: [merchant.coverUrl], evidence: [] } as never}
|
|
616
|
+
cardId="detail-close-snapshot"
|
|
617
|
+
isHistory={false}
|
|
618
|
+
/>,
|
|
619
|
+
);
|
|
620
|
+
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
621
|
+
const sheet = document.body.querySelector('.sg-shop-sheet') as HTMLElement;
|
|
622
|
+
expect(sheet.getAttribute('data-state')).toBe('open');
|
|
623
|
+
|
|
624
|
+
act(() => (document.body.querySelector('[aria-label="关闭门店详情"]') as HTMLButtonElement).click());
|
|
625
|
+
// 父组件已清 data,但快照让面板在退场期间仍有内容
|
|
626
|
+
expect(sheet.getAttribute('data-state')).toBe('closed');
|
|
627
|
+
expect(sheet.textContent).toContain('营业中');
|
|
628
|
+
|
|
629
|
+
// 迟到响应:父组件已 abort(controller 置空),不得把弹层重新顶开
|
|
630
|
+
await act(async () => {
|
|
631
|
+
resolveRequest({ data: { data: { ...merchant, name: '迟到的旧详情', coverUrls: [merchant.coverUrl] } } });
|
|
632
|
+
await pending;
|
|
633
|
+
});
|
|
634
|
+
expect(sheet.getAttribute('data-state')).toBe('closed');
|
|
635
|
+
expect(sheet.textContent).not.toContain('迟到的旧详情');
|
|
636
|
+
|
|
637
|
+
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
638
|
+
expect(document.body.querySelector('.sg-shop-sheet')).toBeNull();
|
|
639
|
+
});
|
|
640
|
+
|
|
609
641
|
it('历史 shop-list 保留只读门店详情和列表浏览', () => {
|
|
610
642
|
const items = Array.from({ length: 4 }, (_, index) => ({
|
|
611
643
|
...merchant,
|
|
@@ -666,14 +698,15 @@ describe('门店导览无权益内容', () => {
|
|
|
666
698
|
|
|
667
699
|
act(() => closeButton.click());
|
|
668
700
|
const sheet = document.body.querySelector('.sg-shop-sheet') as HTMLElement;
|
|
669
|
-
expect(sheet.
|
|
670
|
-
|
|
671
|
-
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
701
|
+
expect(sheet.getAttribute('data-state')).toBe('closed');
|
|
702
|
+
// 退出动画期间面板已失去对话框语义,但仍挂载到动画结束
|
|
672
703
|
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
|
|
704
|
+
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
705
|
+
expect(document.body.querySelector('.sg-shop-sheet')).toBeNull();
|
|
673
706
|
expect(document.body.style.overflow).toBe('');
|
|
674
707
|
|
|
675
708
|
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
676
|
-
expect(document.body.querySelector('.sg-shop-sheet')?.
|
|
709
|
+
expect(document.body.querySelector('.sg-shop-sheet')?.getAttribute('data-state')).toBe('open');
|
|
677
710
|
});
|
|
678
711
|
|
|
679
712
|
it('门店优惠免费 redirect 与付费抢购复用 openLink,历史卡也保持可点击', () => {
|
|
@@ -822,7 +855,7 @@ describe('门店导览无权益内容', () => {
|
|
|
822
855
|
|
|
823
856
|
act(() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })));
|
|
824
857
|
const sheet = document.body.querySelector('.sg-shop-sheet') as HTMLElement;
|
|
825
|
-
expect(sheet.
|
|
858
|
+
expect(sheet.getAttribute('data-state')).toBe('closed');
|
|
826
859
|
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
827
860
|
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
|
|
828
861
|
expect(document.activeElement).toBe(trigger);
|
package/tsup.config.ts
CHANGED
|
@@ -27,11 +27,6 @@ export default defineConfig({
|
|
|
27
27
|
'express',
|
|
28
28
|
'@phosphor-icons/react',
|
|
29
29
|
],
|
|
30
|
-
// 0.3.2/0.4.0 D1:模块自持 CSS 出货链。
|
|
31
|
-
// 顶层 loader 写法(实测:esbuildOptions 内设 loader 被 tsup 覆盖失效——CSS 提取断链静默丢失)。
|
|
32
|
-
loader: {
|
|
33
|
-
'.css': 'copy',
|
|
34
|
-
},
|
|
35
30
|
esbuildOptions(options) {
|
|
36
31
|
options.jsx = 'automatic';
|
|
37
32
|
},
|