@luxfi/core 5.2.14 → 5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/commerce/ui/conf.ts +13 -13
- package/commerce/ui/context.tsx +126 -126
- package/commerce/ui/store.ts +304 -304
- package/components/access-code-input.tsx +71 -71
- package/components/auth/auth-listener.tsx +29 -29
- package/components/auth/auth-token/clear-auth-token.tsx +12 -12
- package/components/auth/auth-token/set-auth-token.tsx +16 -16
- package/components/auth/common-auth-domains.ts +16 -16
- package/components/auth/login-panel.tsx +107 -107
- package/components/back-button.tsx +42 -42
- package/components/chat-widget.tsx +85 -85
- package/components/commerce/add-widget.tsx +20 -20
- package/components/commerce/bag-button.tsx +98 -98
- package/components/commerce/buy-button.tsx +34 -34
- package/components/commerce/checkout-button.tsx +129 -129
- package/components/commerce/checkout-panel/dt-bag-carousel.tsx +36 -36
- package/components/commerce/checkout-panel/dt-checkout-panel.tsx +84 -84
- package/components/commerce/checkout-panel/index.tsx +129 -129
- package/components/commerce/checkout-panel/links-row.tsx +21 -21
- package/components/commerce/checkout-panel/mb-checkout-panel.tsx +54 -54
- package/components/commerce/checkout-panel/steps-indicator.tsx +39 -39
- package/components/commerce/checkout-panel/thank-you.tsx +18 -18
- package/components/commerce/checkout-widget/const.ts +13 -13
- package/components/commerce/checkout-widget/index.tsx +192 -192
- package/components/commerce/checkout-widget/obs-string-set.ts +48 -48
- package/components/commerce/checkout-widget/use-anim-clx-set.ts +58 -58
- package/components/commerce/desktop-bag-popup.tsx +78 -78
- package/components/commerce/desktop-nav-menu.tsx +130 -130
- package/components/commerce/drawer/index.tsx +99 -99
- package/components/commerce/drawer/micro.tsx +144 -144
- package/components/commerce/drawer/shell.tsx +85 -85
- package/components/commerce/mobile-bag-drawer.tsx +51 -51
- package/components/commerce/mobile-login-button.tsx +107 -101
- package/components/commerce/mobile-menu-toggle-button.tsx +35 -35
- package/components/commerce/mobile-nav-menu-ai.tsx +51 -48
- package/components/commerce/mobile-nav-menu-item.tsx +49 -49
- package/components/commerce/mobile-nav-menu.tsx +101 -101
- package/components/contact-dialog/contact-form.tsx +113 -113
- package/components/contact-dialog/disclaimer.tsx +13 -13
- package/components/contact-dialog/index.tsx +64 -64
- package/components/copyright.tsx +21 -17
- package/components/drawer-margin.tsx +25 -25
- package/components/footer.tsx +77 -77
- package/components/header/desktop.tsx +51 -50
- package/components/header/index.tsx +50 -52
- package/components/header/mobile.tsx +163 -163
- package/components/header/theme-toggle.tsx +26 -26
- package/components/icons/24k-gold-card.tsx +43 -43
- package/components/icons/ai-chat-act.tsx +47 -47
- package/components/icons/ai-chat.tsx +29 -29
- package/components/icons/anodized-titanium.tsx +45 -45
- package/components/icons/avatar.tsx +11 -11
- package/components/icons/bag-icon.tsx +10 -10
- package/components/icons/blog-act.tsx +14 -14
- package/components/icons/blog.tsx +20 -20
- package/components/icons/bridge-act.tsx +18 -18
- package/components/icons/bridge.tsx +68 -68
- package/components/icons/changelog-act.tsx +15 -15
- package/components/icons/changelog.tsx +21 -21
- package/components/icons/chrome.tsx +45 -45
- package/components/icons/coins-act.tsx +29 -29
- package/components/icons/coins.tsx +20 -20
- package/components/icons/compare-cards-act.tsx +30 -30
- package/components/icons/compare-cards.tsx +21 -21
- package/components/icons/credit-act.tsx +29 -29
- package/components/icons/credit.tsx +20 -20
- package/components/icons/customer-support-act.tsx +27 -27
- package/components/icons/customer-support.tsx +21 -21
- package/components/icons/customers-act.tsx +65 -65
- package/components/icons/customers.tsx +33 -33
- package/components/icons/developer-docs-act.tsx +26 -26
- package/components/icons/developer-docs.tsx +20 -20
- package/components/icons/exchange-act.tsx +27 -27
- package/components/icons/exchange.tsx +21 -21
- package/components/icons/explorer-act.tsx +27 -27
- package/components/icons/explorer.tsx +22 -22
- package/components/icons/faqs-act.tsx +27 -27
- package/components/icons/faqs.tsx +21 -21
- package/components/icons/github.tsx +14 -14
- package/components/icons/guides-act.tsx +26 -26
- package/components/icons/guides.tsx +21 -21
- package/components/icons/gun-metal.tsx +44 -44
- package/components/icons/index.tsx +43 -43
- package/components/icons/integrations-act.tsx +41 -41
- package/components/icons/integrations.tsx +25 -25
- package/components/icons/irradescent.tsx +41 -41
- package/components/icons/launch-subnet.tsx +21 -21
- package/components/icons/launchsubnet-act.tsx +29 -29
- package/components/icons/left-arrow.tsx +11 -11
- package/components/icons/lux-finance-act.tsx +34 -34
- package/components/icons/lux-finance.tsx +23 -23
- package/components/icons/lux-logo.tsx +10 -10
- package/components/icons/lux-pass-act.tsx +41 -41
- package/components/icons/lux-pass.tsx +25 -25
- package/components/icons/lux-quests-act.tsx +15 -15
- package/components/icons/lux-quests.tsx +21 -21
- package/components/icons/market-act.tsx +39 -39
- package/components/icons/market.tsx +24 -24
- package/components/icons/mirrored-titanium.tsx +46 -46
- package/components/icons/more-benefits-act.tsx +29 -29
- package/components/icons/more-benefits.tsx +21 -21
- package/components/icons/open-source-act.tsx +41 -41
- package/components/icons/open-source.tsx +26 -26
- package/components/icons/right-arrow.tsx +10 -10
- package/components/icons/safe-act.tsx +77 -77
- package/components/icons/safe.tsx +37 -37
- package/components/icons/search.tsx +12 -12
- package/components/icons/secure-delivery.tsx +13 -13
- package/components/icons/shop-act.tsx +29 -29
- package/components/icons/shop.tsx +20 -20
- package/components/icons/social-icon.tsx +35 -35
- package/components/icons/social-svg.css +3 -3
- package/components/icons/sterling-silver-card.tsx +44 -44
- package/components/icons/templates-act.tsx +29 -29
- package/components/icons/templates.tsx +21 -21
- package/components/icons/validators-act.tsx +42 -42
- package/components/icons/validators.tsx +41 -41
- package/components/icons/view-all-card-act.tsx +28 -28
- package/components/icons/view-all-card.tsx +20 -20
- package/components/icons/wallet-act.tsx +29 -29
- package/components/icons/wallet.tsx +20 -20
- package/components/icons/warpcast.tsx +58 -58
- package/components/icons/youtube-logo.tsx +59 -59
- package/components/index.ts +27 -27
- package/components/logo.tsx +89 -89
- package/components/main.tsx +27 -27
- package/components/mini-chart/index.tsx +7 -7
- package/components/mini-chart/mini-chart-props.ts +43 -43
- package/components/mini-chart/mini-chart.tsx +85 -85
- package/components/mini-chart/wrapper.tsx +23 -23
- package/components/not-found/index.tsx +28 -28
- package/components/not-found/not-found-content.mdx +5 -5
- package/components/scripts.tsx +24 -24
- package/components/tooltip.tsx +31 -31
- package/environment.d.ts +5 -5
- package/next/analytics/fpixel.ts +15 -15
- package/next/analytics/google-analytics.ts +13 -13
- package/next/analytics/index.ts +3 -3
- package/next/analytics/pixel-analytics.tsx +54 -54
- package/next/font/get-app-router-font-classes.ts +12 -12
- package/next/font/load-and-return-lux-next-fonts-on-import.ts +68 -68
- package/next/font/next-font-desc.ts +27 -27
- package/next/font/pages-router-font-vars.tsx +18 -18
- package/next/head-metadata/from-next/metadata-types.ts +158 -158
- package/next/head-metadata/from-next/opengraph-types.ts +267 -267
- package/next/head-metadata/from-next/twitter-types.ts +92 -92
- package/next/head-metadata/index.tsx +208 -208
- package/next/middleware/determine-device-mw.ts +16 -16
- package/package.json +79 -79
- package/root-layout/WHY_THIS_IS_SEPARATE.txt +1 -1
- package/root-layout/index.tsx +112 -112
- package/server-actions/firebase-app.ts +14 -14
- package/server-actions/index.ts +5 -5
- package/server-actions/store-contact.ts +51 -51
- package/site-def/footer/community.tsx +67 -67
- package/site-def/footer/company.ts +37 -37
- package/site-def/footer/ecosystem.ts +37 -37
- package/site-def/footer/index.tsx +26 -26
- package/site-def/footer/legal.ts +28 -28
- package/site-def/footer/network.ts +45 -45
- package/site-def/footer/svg/warpcast-logo.svg +11 -11
- package/site-def/index.ts +2 -2
- package/site-def/main-nav.tsx +458 -458
- package/style/cart-animation.css +29 -29
- package/style/checkout-animation.css +23 -23
- package/style/drawer-handle-overrides.css +160 -160
- package/style/lux-colors.css +85 -85
- package/style/lux-global.css +50 -47
- package/tailwind/fontFamily.tailwind.lux.ts +18 -18
- package/tailwind/index.ts +2 -2
- package/tailwind/lux-tw-fonts.ts +39 -39
- package/tailwind/tailwind.config.lux-preset.ts +10 -10
- package/tsconfig.json +15 -15
- package/types/chatbot-config.ts +6 -6
- package/types/chatbot-suggested-question.ts +7 -7
- package/types/contact-info.ts +10 -10
- package/types/index.ts +4 -4
- package/types/site-def.ts +43 -43
package/commerce/ui/store.ts
CHANGED
@@ -1,305 +1,305 @@
|
|
1
|
-
import {
|
2
|
-
action,
|
3
|
-
autorun,
|
4
|
-
computed,
|
5
|
-
makeObservable,
|
6
|
-
observable,
|
7
|
-
reaction,
|
8
|
-
type IReactionDisposer,
|
9
|
-
} from 'mobx'
|
10
|
-
|
11
|
-
import type { CommerceService, LineItem, ObsLineItemRef } from '@hanzo/commerce/types'
|
12
|
-
|
13
|
-
const LOG = false ////////////////////
|
14
|
-
|
15
|
-
const log = (s: string) => {
|
16
|
-
if (LOG) {
|
17
|
-
console.log('COMMERCE_UI ' + s)
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
type SnapPoint = number | string
|
22
|
-
|
23
|
-
type SnapPoints = {
|
24
|
-
full: SnapPoint
|
25
|
-
micro: SnapPoint
|
26
|
-
}
|
27
|
-
|
28
|
-
type SnapPointsConfig = {
|
29
|
-
mb: SnapPoints
|
30
|
-
dt: SnapPoints
|
31
|
-
}
|
32
|
-
|
33
|
-
type DrawerState = 'closed' | 'micro' | 'full'
|
34
|
-
|
35
|
-
interface RecentActivity extends ObsLineItemRef {
|
36
|
-
quantityChanged(sku: string, val: number, prevVal: number): void
|
37
|
-
}
|
38
|
-
|
39
|
-
interface SelectAndBuy {
|
40
|
-
showVariants: (skuPath: string) => void
|
41
|
-
hideVariants: () => void
|
42
|
-
get currentSkuPath(): string | undefined
|
43
|
-
}
|
44
|
-
|
45
|
-
interface CommerceDrawer {
|
46
|
-
|
47
|
-
get open(): boolean
|
48
|
-
get state(): DrawerState
|
49
|
-
get closedByUser(): boolean
|
50
|
-
setClosedByUser(b: boolean): void
|
51
|
-
get modal(): boolean
|
52
|
-
get points(): SnapPoint[]
|
53
|
-
get activePoint(): SnapPoint | null
|
54
|
-
// Called by UI Gesture
|
55
|
-
onActivePointChanged: (p: SnapPoint | null) => void
|
56
|
-
get showCheckout(): boolean
|
57
|
-
get showAdded(): boolean
|
58
|
-
get showBuy(): boolean
|
59
|
-
|
60
|
-
get microHeight(): SnapPoint
|
61
|
-
get isMobile(): boolean
|
62
|
-
get snapPointPx(): number
|
63
|
-
}
|
64
|
-
|
65
|
-
class CommerceUIStore implements
|
66
|
-
RecentActivity,
|
67
|
-
SelectAndBuy,
|
68
|
-
CommerceDrawer
|
69
|
-
{
|
70
|
-
_vHeight: number = 0
|
71
|
-
|
72
|
-
_currentSkuPath: string | undefined = undefined
|
73
|
-
_closedByUser: boolean = false
|
74
|
-
_checkingOut: boolean | undefined = undefined
|
75
|
-
_ignoreStateChange: boolean = false
|
76
|
-
_activePoint: SnapPoint | null = null
|
77
|
-
|
78
|
-
_activeItem: LineItem | undefined = undefined
|
79
|
-
_reactionDisposers: IReactionDisposer[] = []
|
80
|
-
_service: CommerceService
|
81
|
-
_pointsConfig: SnapPointsConfig
|
82
|
-
_points: SnapPoints // points to either this._pointsConfig.md or this._pointsConfig.dt
|
83
|
-
|
84
|
-
constructor(s: CommerceService, conf: SnapPointsConfig) {
|
85
|
-
this._service = s
|
86
|
-
this._pointsConfig = conf
|
87
|
-
this._points = this._pointsConfig.dt
|
88
|
-
|
89
|
-
makeObservable(this, {
|
90
|
-
_currentSkuPath: observable,
|
91
|
-
_activeItem: observable.ref,
|
92
|
-
_closedByUser: observable,
|
93
|
-
_checkingOut: observable,
|
94
|
-
_activePoint: observable,
|
95
|
-
_points: observable.ref,
|
96
|
-
_vHeight: observable,
|
97
|
-
|
98
|
-
showVariants: action,
|
99
|
-
hideVariants: action,
|
100
|
-
quantityChanged: action,
|
101
|
-
setClosedByUser: action,
|
102
|
-
setCheckingOut: action,
|
103
|
-
setActivePoint: action,
|
104
|
-
setMobile: action,
|
105
|
-
setViewportHeight: action,
|
106
|
-
clearActiveItem: action,
|
107
|
-
|
108
|
-
activePoint: computed,
|
109
|
-
checkingOut: computed,
|
110
|
-
closedByUser: computed,
|
111
|
-
currentSkuPath: computed,
|
112
|
-
item: computed,
|
113
|
-
microHeight: computed,
|
114
|
-
modal: computed,
|
115
|
-
points: computed,
|
116
|
-
showAdded: computed,
|
117
|
-
showBuy: computed,
|
118
|
-
showCheckout: computed,
|
119
|
-
snapPointPx: computed,
|
120
|
-
state: computed,
|
121
|
-
open: computed
|
122
|
-
})
|
123
|
-
}
|
124
|
-
|
125
|
-
initialize = (): void => {
|
126
|
-
|
127
|
-
this._reactionDisposers.push(reaction(
|
128
|
-
() => ( this.state ),
|
129
|
-
(s) => {
|
130
|
-
if (this.ignoreStateChange) {
|
131
|
-
log(`STATE CHANGE to "${s}" (IGNORED)`) // ===========
|
132
|
-
this.setIgnoreStateChange(false)
|
133
|
-
return
|
134
|
-
}
|
135
|
-
else {
|
136
|
-
log(`STATE CHANGE to "${s}" (UI REACTED)`) // ===========
|
137
|
-
this._syncUIToState(s)
|
138
|
-
}
|
139
|
-
}
|
140
|
-
))
|
141
|
-
this._reactionDisposers.push(autorun(() => {
|
142
|
-
log('AUTORUN: OPEN: ' + this.open)
|
143
|
-
log('AUTORUN:' + // ===============
|
144
|
-
'[showCheckout: ' + this.showCheckout +
|
145
|
-
'], [showAdded: ' + this.showAdded +
|
146
|
-
'], [showBuy: ' + this.showBuy +
|
147
|
-
'], [closedByUser: ' + this._closedByUser +
|
148
|
-
'], [checkingOut: ' + this._checkingOut + ']'
|
149
|
-
) // ===========
|
150
|
-
}))
|
151
|
-
}
|
152
|
-
|
153
|
-
reset = () => {
|
154
|
-
this.hideVariants()
|
155
|
-
this.setClosedByUser(false)
|
156
|
-
this.clearActiveItem()
|
157
|
-
// DO NOT reset _checkingOut!
|
158
|
-
}
|
159
|
-
|
160
|
-
onActivePointChanged = (pt: SnapPoint | null): void => {
|
161
|
-
log("ON onActivePointChanged: " + pt) // ===========
|
162
|
-
if (pt === this._points.micro && this.activePoint === this._points.full) {
|
163
|
-
this.setIgnoreStateChange(true)
|
164
|
-
this.hideVariants()
|
165
|
-
}
|
166
|
-
else if (pt === this._points.full && this.activePoint === this._points.micro) {
|
167
|
-
this.setIgnoreStateChange(true)
|
168
|
-
this.showVariants(this.item?.sku ?? '')
|
169
|
-
}
|
170
|
-
this.setActivePoint(pt)
|
171
|
-
}
|
172
|
-
|
173
|
-
showVariants = (skuPath: string): void => {
|
174
|
-
this._service.setCurrentItem(undefined)
|
175
|
-
this._currentSkuPath = skuPath
|
176
|
-
this._closedByUser = false
|
177
|
-
}
|
178
|
-
|
179
|
-
hideVariants = (): void => { this._currentSkuPath = undefined }
|
180
|
-
|
181
|
-
get currentSkuPath(): string | undefined { return this._currentSkuPath }
|
182
|
-
|
183
|
-
quantityChanged = (sku: string, val: number, oldVal: number): void => {
|
184
|
-
|
185
|
-
if (val === 0) {
|
186
|
-
if (this._activeItem?.sku === sku) {
|
187
|
-
this._activeItem = undefined
|
188
|
-
}
|
189
|
-
// otherwise ignore
|
190
|
-
}
|
191
|
-
else {
|
192
|
-
if (!this._activeItem || this._activeItem.sku !== sku) {
|
193
|
-
this._activeItem = this._service.getItemBySku(sku)
|
194
|
-
}
|
195
|
-
}
|
196
|
-
}
|
197
|
-
|
198
|
-
get item(): LineItem | undefined { return this._activeItem }
|
199
|
-
clearActiveItem = (): void => { this._activeItem = undefined }
|
200
|
-
|
201
|
-
get closedByUser(): boolean { return this._closedByUser }
|
202
|
-
setClosedByUser = (b: boolean): void => { this._closedByUser = b}
|
203
|
-
|
204
|
-
get ignoreStateChange(): boolean { return this._ignoreStateChange }
|
205
|
-
setIgnoreStateChange = (b: boolean): void => { this._ignoreStateChange = b}
|
206
|
-
|
207
|
-
get checkingOut(): boolean | undefined { return this._checkingOut }
|
208
|
-
setCheckingOut = (b: boolean): void => { this._checkingOut = b }
|
209
|
-
|
210
|
-
get activePoint(): SnapPoint | null { return this._activePoint }
|
211
|
-
setActivePoint = (pt: SnapPoint | null): void => { this._activePoint = pt}
|
212
|
-
|
213
|
-
get points(): SnapPoint[] {
|
214
|
-
if (this.showBuy && !(this.showAdded || this.showCheckout)) {
|
215
|
-
return [this._points.full]
|
216
|
-
}
|
217
|
-
else if (!this.showBuy && !this.showAdded && this.showCheckout) {
|
218
|
-
return [this._points.micro]
|
219
|
-
}
|
220
|
-
return [this._points.micro, this._points.full]
|
221
|
-
}
|
222
|
-
|
223
|
-
_syncUIToState = (s: DrawerState) => {
|
224
|
-
log("_syncUIToState: " + s) // ===========
|
225
|
-
if (s === 'micro') {
|
226
|
-
this.setActivePoint(this.points[0])
|
227
|
-
}
|
228
|
-
else if (s === 'full') {
|
229
|
-
this.setActivePoint(this.points[this.points.length - 1])
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
get open(): boolean {
|
234
|
-
|
235
|
-
log('open():' + // ===============
|
236
|
-
' showCheckout: ' + this.showCheckout +
|
237
|
-
' showAdded: ' + this.showAdded +
|
238
|
-
' showBuy: ' + this.showBuy
|
239
|
-
) // ===========
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
return (
|
244
|
-
this._checkingOut !== undefined
|
245
|
-
&&
|
246
|
-
!this._checkingOut
|
247
|
-
&&
|
248
|
-
!this.closedByUser
|
249
|
-
&&
|
250
|
-
(this.showCheckout || this.showAdded || this.showBuy)
|
251
|
-
)
|
252
|
-
}
|
253
|
-
|
254
|
-
get state(): DrawerState {
|
255
|
-
if (!this.closedByUser && !this._checkingOut) {
|
256
|
-
if (this.showBuy) {
|
257
|
-
return 'full'
|
258
|
-
}
|
259
|
-
else if (this.showAdded || this.showCheckout) {
|
260
|
-
return 'micro'
|
261
|
-
}
|
262
|
-
}
|
263
|
-
return 'closed'
|
264
|
-
}
|
265
|
-
|
266
|
-
get showBuy(): boolean {return !!this.currentSkuPath}
|
267
|
-
get showAdded(): boolean { return !!this.item}
|
268
|
-
get showCheckout(): boolean { return !this._service.cartEmpty}
|
269
|
-
get modal(): boolean { return this.state !== 'micro'}
|
270
|
-
|
271
|
-
get microHeight(): SnapPoint {
|
272
|
-
return this._points.micro
|
273
|
-
}
|
274
|
-
|
275
|
-
get isMobile(): boolean { return this._pointsConfig.mb === this._points }
|
276
|
-
setMobile = (b: boolean): void => {
|
277
|
-
log("setMobile: " + b) // ===========
|
278
|
-
this._points = b ? this._pointsConfig.mb : this._pointsConfig.dt
|
279
|
-
}
|
280
|
-
|
281
|
-
setViewportHeight = (v: number) => {this._vHeight = v}
|
282
|
-
get snapPointPx(): number {
|
283
|
-
if (!this._activePoint || this._vHeight === 0) return 0
|
284
|
-
|
285
|
-
if (typeof this._activePoint === 'string') {
|
286
|
-
return parseInt(this._activePoint)
|
287
|
-
}
|
288
|
-
|
289
|
-
return this._vHeight * this._activePoint as number
|
290
|
-
}
|
291
|
-
|
292
|
-
dispose = () => {
|
293
|
-
this._reactionDisposers.forEach((d) => {d()})
|
294
|
-
}
|
295
|
-
}
|
296
|
-
|
297
|
-
export {
|
298
|
-
CommerceUIStore,
|
299
|
-
type CommerceDrawer,
|
300
|
-
type RecentActivity,
|
301
|
-
type SelectAndBuy,
|
302
|
-
type SnapPointsConfig,
|
303
|
-
type SnapPoints,
|
304
|
-
type SnapPoint
|
1
|
+
import {
|
2
|
+
action,
|
3
|
+
autorun,
|
4
|
+
computed,
|
5
|
+
makeObservable,
|
6
|
+
observable,
|
7
|
+
reaction,
|
8
|
+
type IReactionDisposer,
|
9
|
+
} from 'mobx'
|
10
|
+
|
11
|
+
import type { CommerceService, LineItem, ObsLineItemRef } from '@hanzo/commerce/types'
|
12
|
+
|
13
|
+
const LOG = false ////////////////////
|
14
|
+
|
15
|
+
const log = (s: string) => {
|
16
|
+
if (LOG) {
|
17
|
+
console.log('COMMERCE_UI ' + s)
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
type SnapPoint = number | string
|
22
|
+
|
23
|
+
type SnapPoints = {
|
24
|
+
full: SnapPoint
|
25
|
+
micro: SnapPoint
|
26
|
+
}
|
27
|
+
|
28
|
+
type SnapPointsConfig = {
|
29
|
+
mb: SnapPoints
|
30
|
+
dt: SnapPoints
|
31
|
+
}
|
32
|
+
|
33
|
+
type DrawerState = 'closed' | 'micro' | 'full'
|
34
|
+
|
35
|
+
interface RecentActivity extends ObsLineItemRef {
|
36
|
+
quantityChanged(sku: string, val: number, prevVal: number): void
|
37
|
+
}
|
38
|
+
|
39
|
+
interface SelectAndBuy {
|
40
|
+
showVariants: (skuPath: string) => void
|
41
|
+
hideVariants: () => void
|
42
|
+
get currentSkuPath(): string | undefined
|
43
|
+
}
|
44
|
+
|
45
|
+
interface CommerceDrawer {
|
46
|
+
|
47
|
+
get open(): boolean
|
48
|
+
get state(): DrawerState
|
49
|
+
get closedByUser(): boolean
|
50
|
+
setClosedByUser(b: boolean): void
|
51
|
+
get modal(): boolean
|
52
|
+
get points(): SnapPoint[]
|
53
|
+
get activePoint(): SnapPoint | null
|
54
|
+
// Called by UI Gesture
|
55
|
+
onActivePointChanged: (p: SnapPoint | null) => void
|
56
|
+
get showCheckout(): boolean
|
57
|
+
get showAdded(): boolean
|
58
|
+
get showBuy(): boolean
|
59
|
+
|
60
|
+
get microHeight(): SnapPoint
|
61
|
+
get isMobile(): boolean
|
62
|
+
get snapPointPx(): number
|
63
|
+
}
|
64
|
+
|
65
|
+
class CommerceUIStore implements
|
66
|
+
RecentActivity,
|
67
|
+
SelectAndBuy,
|
68
|
+
CommerceDrawer
|
69
|
+
{
|
70
|
+
_vHeight: number = 0
|
71
|
+
|
72
|
+
_currentSkuPath: string | undefined = undefined
|
73
|
+
_closedByUser: boolean = false
|
74
|
+
_checkingOut: boolean | undefined = undefined
|
75
|
+
_ignoreStateChange: boolean = false
|
76
|
+
_activePoint: SnapPoint | null = null
|
77
|
+
|
78
|
+
_activeItem: LineItem | undefined = undefined
|
79
|
+
_reactionDisposers: IReactionDisposer[] = []
|
80
|
+
_service: CommerceService
|
81
|
+
_pointsConfig: SnapPointsConfig
|
82
|
+
_points: SnapPoints // points to either this._pointsConfig.md or this._pointsConfig.dt
|
83
|
+
|
84
|
+
constructor(s: CommerceService, conf: SnapPointsConfig) {
|
85
|
+
this._service = s
|
86
|
+
this._pointsConfig = conf
|
87
|
+
this._points = this._pointsConfig.dt
|
88
|
+
|
89
|
+
makeObservable(this, {
|
90
|
+
_currentSkuPath: observable,
|
91
|
+
_activeItem: observable.ref,
|
92
|
+
_closedByUser: observable,
|
93
|
+
_checkingOut: observable,
|
94
|
+
_activePoint: observable,
|
95
|
+
_points: observable.ref,
|
96
|
+
_vHeight: observable,
|
97
|
+
|
98
|
+
showVariants: action,
|
99
|
+
hideVariants: action,
|
100
|
+
quantityChanged: action,
|
101
|
+
setClosedByUser: action,
|
102
|
+
setCheckingOut: action,
|
103
|
+
setActivePoint: action,
|
104
|
+
setMobile: action,
|
105
|
+
setViewportHeight: action,
|
106
|
+
clearActiveItem: action,
|
107
|
+
|
108
|
+
activePoint: computed,
|
109
|
+
checkingOut: computed,
|
110
|
+
closedByUser: computed,
|
111
|
+
currentSkuPath: computed,
|
112
|
+
item: computed,
|
113
|
+
microHeight: computed,
|
114
|
+
modal: computed,
|
115
|
+
points: computed,
|
116
|
+
showAdded: computed,
|
117
|
+
showBuy: computed,
|
118
|
+
showCheckout: computed,
|
119
|
+
snapPointPx: computed,
|
120
|
+
state: computed,
|
121
|
+
open: computed
|
122
|
+
})
|
123
|
+
}
|
124
|
+
|
125
|
+
initialize = (): void => {
|
126
|
+
|
127
|
+
this._reactionDisposers.push(reaction(
|
128
|
+
() => ( this.state ),
|
129
|
+
(s) => {
|
130
|
+
if (this.ignoreStateChange) {
|
131
|
+
log(`STATE CHANGE to "${s}" (IGNORED)`) // ===========
|
132
|
+
this.setIgnoreStateChange(false)
|
133
|
+
return
|
134
|
+
}
|
135
|
+
else {
|
136
|
+
log(`STATE CHANGE to "${s}" (UI REACTED)`) // ===========
|
137
|
+
this._syncUIToState(s)
|
138
|
+
}
|
139
|
+
}
|
140
|
+
))
|
141
|
+
this._reactionDisposers.push(autorun(() => {
|
142
|
+
log('AUTORUN: OPEN: ' + this.open)
|
143
|
+
log('AUTORUN:' + // ===============
|
144
|
+
'[showCheckout: ' + this.showCheckout +
|
145
|
+
'], [showAdded: ' + this.showAdded +
|
146
|
+
'], [showBuy: ' + this.showBuy +
|
147
|
+
'], [closedByUser: ' + this._closedByUser +
|
148
|
+
'], [checkingOut: ' + this._checkingOut + ']'
|
149
|
+
) // ===========
|
150
|
+
}))
|
151
|
+
}
|
152
|
+
|
153
|
+
reset = () => {
|
154
|
+
this.hideVariants()
|
155
|
+
this.setClosedByUser(false)
|
156
|
+
this.clearActiveItem()
|
157
|
+
// DO NOT reset _checkingOut!
|
158
|
+
}
|
159
|
+
|
160
|
+
onActivePointChanged = (pt: SnapPoint | null): void => {
|
161
|
+
log("ON onActivePointChanged: " + pt) // ===========
|
162
|
+
if (pt === this._points.micro && this.activePoint === this._points.full) {
|
163
|
+
this.setIgnoreStateChange(true)
|
164
|
+
this.hideVariants()
|
165
|
+
}
|
166
|
+
else if (pt === this._points.full && this.activePoint === this._points.micro) {
|
167
|
+
this.setIgnoreStateChange(true)
|
168
|
+
this.showVariants(this.item?.sku ?? '')
|
169
|
+
}
|
170
|
+
this.setActivePoint(pt)
|
171
|
+
}
|
172
|
+
|
173
|
+
showVariants = (skuPath: string): void => {
|
174
|
+
this._service.setCurrentItem(undefined)
|
175
|
+
this._currentSkuPath = skuPath
|
176
|
+
this._closedByUser = false
|
177
|
+
}
|
178
|
+
|
179
|
+
hideVariants = (): void => { this._currentSkuPath = undefined }
|
180
|
+
|
181
|
+
get currentSkuPath(): string | undefined { return this._currentSkuPath }
|
182
|
+
|
183
|
+
quantityChanged = (sku: string, val: number, oldVal: number): void => {
|
184
|
+
|
185
|
+
if (val === 0) {
|
186
|
+
if (this._activeItem?.sku === sku) {
|
187
|
+
this._activeItem = undefined
|
188
|
+
}
|
189
|
+
// otherwise ignore
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
if (!this._activeItem || this._activeItem.sku !== sku) {
|
193
|
+
this._activeItem = this._service.getItemBySku(sku)
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
get item(): LineItem | undefined { return this._activeItem }
|
199
|
+
clearActiveItem = (): void => { this._activeItem = undefined }
|
200
|
+
|
201
|
+
get closedByUser(): boolean { return this._closedByUser }
|
202
|
+
setClosedByUser = (b: boolean): void => { this._closedByUser = b}
|
203
|
+
|
204
|
+
get ignoreStateChange(): boolean { return this._ignoreStateChange }
|
205
|
+
setIgnoreStateChange = (b: boolean): void => { this._ignoreStateChange = b}
|
206
|
+
|
207
|
+
get checkingOut(): boolean | undefined { return this._checkingOut }
|
208
|
+
setCheckingOut = (b: boolean): void => { this._checkingOut = b }
|
209
|
+
|
210
|
+
get activePoint(): SnapPoint | null { return this._activePoint }
|
211
|
+
setActivePoint = (pt: SnapPoint | null): void => { this._activePoint = pt}
|
212
|
+
|
213
|
+
get points(): SnapPoint[] {
|
214
|
+
if (this.showBuy && !(this.showAdded || this.showCheckout)) {
|
215
|
+
return [this._points.full]
|
216
|
+
}
|
217
|
+
else if (!this.showBuy && !this.showAdded && this.showCheckout) {
|
218
|
+
return [this._points.micro]
|
219
|
+
}
|
220
|
+
return [this._points.micro, this._points.full]
|
221
|
+
}
|
222
|
+
|
223
|
+
_syncUIToState = (s: DrawerState) => {
|
224
|
+
log("_syncUIToState: " + s) // ===========
|
225
|
+
if (s === 'micro') {
|
226
|
+
this.setActivePoint(this.points[0])
|
227
|
+
}
|
228
|
+
else if (s === 'full') {
|
229
|
+
this.setActivePoint(this.points[this.points.length - 1])
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
get open(): boolean {
|
234
|
+
|
235
|
+
log('open():' + // ===============
|
236
|
+
' showCheckout: ' + this.showCheckout +
|
237
|
+
' showAdded: ' + this.showAdded +
|
238
|
+
' showBuy: ' + this.showBuy
|
239
|
+
) // ===========
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
return (
|
244
|
+
this._checkingOut !== undefined
|
245
|
+
&&
|
246
|
+
!this._checkingOut
|
247
|
+
&&
|
248
|
+
!this.closedByUser
|
249
|
+
&&
|
250
|
+
(this.showCheckout || this.showAdded || this.showBuy)
|
251
|
+
)
|
252
|
+
}
|
253
|
+
|
254
|
+
get state(): DrawerState {
|
255
|
+
if (!this.closedByUser && !this._checkingOut) {
|
256
|
+
if (this.showBuy) {
|
257
|
+
return 'full'
|
258
|
+
}
|
259
|
+
else if (this.showAdded || this.showCheckout) {
|
260
|
+
return 'micro'
|
261
|
+
}
|
262
|
+
}
|
263
|
+
return 'closed'
|
264
|
+
}
|
265
|
+
|
266
|
+
get showBuy(): boolean {return !!this.currentSkuPath}
|
267
|
+
get showAdded(): boolean { return !!this.item}
|
268
|
+
get showCheckout(): boolean { return !this._service.cartEmpty}
|
269
|
+
get modal(): boolean { return this.state !== 'micro'}
|
270
|
+
|
271
|
+
get microHeight(): SnapPoint {
|
272
|
+
return this._points.micro
|
273
|
+
}
|
274
|
+
|
275
|
+
get isMobile(): boolean { return this._pointsConfig.mb === this._points }
|
276
|
+
setMobile = (b: boolean): void => {
|
277
|
+
log("setMobile: " + b) // ===========
|
278
|
+
this._points = b ? this._pointsConfig.mb : this._pointsConfig.dt
|
279
|
+
}
|
280
|
+
|
281
|
+
setViewportHeight = (v: number) => {this._vHeight = v}
|
282
|
+
get snapPointPx(): number {
|
283
|
+
if (!this._activePoint || this._vHeight === 0) return 0
|
284
|
+
|
285
|
+
if (typeof this._activePoint === 'string') {
|
286
|
+
return parseInt(this._activePoint)
|
287
|
+
}
|
288
|
+
|
289
|
+
return this._vHeight * this._activePoint as number
|
290
|
+
}
|
291
|
+
|
292
|
+
dispose = () => {
|
293
|
+
this._reactionDisposers.forEach((d) => {d()})
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
export {
|
298
|
+
CommerceUIStore,
|
299
|
+
type CommerceDrawer,
|
300
|
+
type RecentActivity,
|
301
|
+
type SelectAndBuy,
|
302
|
+
type SnapPointsConfig,
|
303
|
+
type SnapPoints,
|
304
|
+
type SnapPoint
|
305
305
|
}
|