@zappie/foundations 0.14.0 → 0.16.0
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/CHANGELOG.md +35 -0
- package/README.md +68 -0
- package/dist/account/index.js +1 -48
- package/dist/account/index.js.map +1 -1
- package/dist/account/zappie-account.js +1 -38
- package/dist/account/zappie-account.js.map +1 -1
- package/dist/attribution/powered-by-zappie.js +2 -0
- package/dist/attribution/powered-by-zappie.js.map +6 -0
- package/dist/branch-map/colors.js +1 -26
- package/dist/branch-map/colors.js.map +1 -1
- package/dist/branch-map/delivery-map.js +1 -59
- package/dist/branch-map/delivery-map.js.map +1 -1
- package/dist/branch-map/delivery-runtime.js +1 -117
- package/dist/branch-map/delivery-runtime.js.map +1 -1
- package/dist/branch-map/fit.js +1 -107
- package/dist/branch-map/fit.js.map +1 -1
- package/dist/branch-map/geometry.js +1 -11
- package/dist/branch-map/geometry.js.map +1 -1
- package/dist/branch-map/index.js +1 -94
- package/dist/branch-map/index.js.map +1 -1
- package/dist/branch-map/loader.js +1 -38
- package/dist/branch-map/loader.js.map +1 -1
- package/dist/branch-map/markers.js +1 -182
- package/dist/branch-map/markers.js.map +1 -1
- package/dist/branch-map/runtime.js +1 -294
- package/dist/branch-map/runtime.js.map +1 -1
- package/dist/branch-map/use-map-runtime.js +1 -52
- package/dist/branch-map/use-map-runtime.js.map +1 -1
- package/dist/branch-switch/index.js +1 -125
- package/dist/branch-switch/index.js.map +1 -1
- package/dist/cart/index.js +1 -170
- package/dist/cart/index.js.map +1 -1
- package/dist/checkout/attempt.js +1 -48
- package/dist/checkout/attempt.js.map +1 -1
- package/dist/checkout/contact.js +1 -35
- package/dist/checkout/contact.js.map +1 -1
- package/dist/checkout/index.js +1 -33
- package/dist/checkout/index.js.map +1 -1
- package/dist/checkout/markers.js +1 -25
- package/dist/checkout/markers.js.map +1 -1
- package/dist/checkout/offers.js +1 -12
- package/dist/checkout/offers.js.map +1 -1
- package/dist/checkout/pay-after-sign-in.js +1 -77
- package/dist/checkout/pay-after-sign-in.js.map +1 -1
- package/dist/checkout/sign-in.js +1 -25
- package/dist/checkout/sign-in.js.map +1 -1
- package/dist/checkout/status.js +1 -72
- package/dist/checkout/status.js.map +1 -1
- package/dist/checkout/timing.js +1 -38
- package/dist/checkout/timing.js.map +1 -1
- package/dist/checkout/use-checkout-flow.js +1 -598
- package/dist/checkout/use-checkout-flow.js.map +1 -1
- package/dist/deferred/index.js +1 -141
- package/dist/deferred/index.js.map +1 -1
- package/dist/fulfilment/address-picker.js +1 -165
- package/dist/fulfilment/address-picker.js.map +1 -1
- package/dist/fulfilment/branch-picker.js +1 -53
- package/dist/fulfilment/branch-picker.js.map +1 -1
- package/dist/fulfilment/schedule.js +1 -126
- package/dist/fulfilment/schedule.js.map +1 -1
- package/dist/fulfilment/switch.js +1 -53
- package/dist/fulfilment/switch.js.map +1 -1
- package/dist/fulfilment/window.js +1 -154
- package/dist/fulfilment/window.js.map +1 -1
- package/dist/index.d.ts +31 -110
- package/dist/index.js +1 -76
- package/dist/index.js.map +1 -1
- package/dist/internal/combobox.js +1 -130
- package/dist/internal/combobox.js.map +1 -1
- package/dist/internal/data-attrs.js +1 -7
- package/dist/internal/data-attrs.js.map +1 -1
- package/dist/internal/ids.js +1 -9
- package/dist/internal/ids.js.map +1 -1
- package/dist/internal/slot.js +1 -87
- package/dist/internal/slot.js.map +1 -1
- package/dist/internal/use-controllable-state.js +1 -28
- package/dist/internal/use-controllable-state.js.map +1 -1
- package/dist/item-form/index.js +1 -14
- package/dist/item-form/index.js.map +1 -1
- package/dist/item-form/option-group.js +1 -331
- package/dist/item-form/option-group.js.map +1 -1
- package/dist/item-form/options.js +1 -64
- package/dist/item-form/options.js.map +1 -1
- package/dist/item-form/quantity.js +1 -130
- package/dist/item-form/quantity.js.map +1 -1
- package/dist/item-form/root.js +1 -182
- package/dist/item-form/root.js.map +1 -1
- package/dist/item-sheet/index.d.ts +137 -0
- package/dist/item-sheet/index.js +2 -0
- package/dist/item-sheet/index.js.map +6 -0
- package/dist/loyalty/index.js +1 -278
- package/dist/loyalty/index.js.map +1 -1
- package/dist/media/image.js +1 -58
- package/dist/media/image.js.map +1 -1
- package/dist/money.js +1 -19
- package/dist/money.js.map +1 -1
- package/dist/next.js +1 -57
- package/dist/next.js.map +1 -1
- package/dist/order/index.js +1 -575
- package/dist/order/index.js.map +1 -1
- package/dist/order/model.js +1 -83
- package/dist/order/model.js.map +1 -1
- package/dist/order/use-customer-order.js +1 -55
- package/dist/order/use-customer-order.js.map +1 -1
- package/dist/otp/input.js +1 -109
- package/dist/otp/input.js.map +1 -1
- package/dist/overlay/drag-to-close.js +1 -50
- package/dist/overlay/drag-to-close.js.map +1 -1
- package/dist/overlay/drag.js +1 -209
- package/dist/overlay/drag.js.map +1 -1
- package/dist/overlay/engine.js +1 -184
- package/dist/overlay/engine.js.map +1 -1
- package/dist/overlay/history.js +1 -101
- package/dist/overlay/history.js.map +1 -1
- package/dist/overlay/load.js +1 -28
- package/dist/overlay/load.js.map +1 -1
- package/dist/overlay/react.js +1 -481
- package/dist/overlay/react.js.map +1 -1
- package/dist/payment/methods.js +1 -102
- package/dist/payment/methods.js.map +1 -1
- package/dist/phone/combobox.js +1 -295
- package/dist/phone/combobox.js.map +1 -1
- package/dist/phone/core.js +1 -162
- package/dist/phone/core.js.map +1 -1
- package/dist/phone/countries.js +1 -56
- package/dist/phone/countries.js.map +1 -1
- package/dist/phone/country-data.js +1 -272
- package/dist/phone/country-data.js.map +1 -1
- package/dist/phone/index.js +1 -42
- package/dist/phone/index.js.map +1 -1
- package/dist/phone/load.js +1 -12
- package/dist/phone/load.js.map +1 -1
- package/dist/phone/picker.js +1 -142
- package/dist/phone/picker.js.map +1 -1
- package/dist/phone/use-phone-field.js +1 -183
- package/dist/phone/use-phone-field.js.map +1 -1
- package/dist/react-CFPTPzAO.d.ts +120 -0
- package/dist/rich-text/banners.js +1 -8
- package/dist/rich-text/banners.js.map +1 -1
- package/dist/rich-text/browser.js +1 -23
- package/dist/rich-text/browser.js.map +1 -1
- package/dist/rich-text/core.js +1 -74
- package/dist/rich-text/core.js.map +1 -1
- package/dist/rich-text/index.js +1 -3
- package/dist/rich-text/index.js.map +1 -1
- package/dist/schedule/index.js +1 -36
- package/dist/schedule/index.js.map +1 -1
- package/dist/search/engine.js +1 -92
- package/dist/search/engine.js.map +1 -1
- package/dist/search/index.js +1 -174
- package/dist/search/index.js.map +1 -1
- package/dist/status/contact.js +1 -41
- package/dist/status/contact.js.map +1 -1
- package/dist/status/hours.js +1 -185
- package/dist/status/hours.js.map +1 -1
- package/dist/status/open-status.js +1 -47
- package/dist/status/open-status.js.map +1 -1
- package/dist/version.js +1 -5
- package/dist/version.js.map +1 -1
- package/package.json +14 -3
package/dist/order/model.js
CHANGED
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { money } from "@zappie/sdk";
|
|
3
|
-
var orderMoney = (value) => money(value.amount_minor, value.currency);
|
|
4
|
-
function orderTotals(order) {
|
|
5
|
-
const rows = [
|
|
6
|
-
{ kind: "subtotal", label: "Subtotal", amount: orderMoney(order.subtotal) }
|
|
7
|
-
];
|
|
8
|
-
let delivery = false;
|
|
9
|
-
for (const charge of order.charges) {
|
|
10
|
-
const isDelivery = charge.code === "delivery";
|
|
11
|
-
delivery || (delivery = isDelivery);
|
|
12
|
-
rows.push({
|
|
13
|
-
kind: isDelivery ? "delivery" : "charge",
|
|
14
|
-
label: charge.label,
|
|
15
|
-
amount: orderMoney(charge.amount),
|
|
16
|
-
...charge.waived ? { note: "waived" } : charge.included ? { note: "included" } : {}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
if (!delivery && order.delivery_fee.amount_minor > 0) {
|
|
20
|
-
rows.push({
|
|
21
|
-
kind: "delivery",
|
|
22
|
-
label: "Delivery",
|
|
23
|
-
amount: orderMoney(order.delivery_fee)
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
const discounts = order.discounts.length ? order.discounts : order.discount.amount_minor > 0 ? [{ label: "Discount", amount: order.discount }] : [];
|
|
27
|
-
for (const discount of discounts) {
|
|
28
|
-
rows.push({
|
|
29
|
-
kind: "discount",
|
|
30
|
-
label: discount.label,
|
|
31
|
-
amount: orderMoney({
|
|
32
|
-
...discount.amount,
|
|
33
|
-
amount_minor: -discount.amount.amount_minor
|
|
34
|
-
}),
|
|
35
|
-
..."promo_code" in discount && discount.promo_code ? { promoCode: discount.promo_code } : {}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
rows.push({ kind: "total", label: "Total", amount: orderMoney(order.total) });
|
|
39
|
-
if (order.amount_paid.amount_minor > 0) {
|
|
40
|
-
rows.push({
|
|
41
|
-
kind: "paid",
|
|
42
|
-
label: "Paid",
|
|
43
|
-
amount: orderMoney(order.amount_paid)
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (order.amount_due.amount_minor > 0) {
|
|
47
|
-
rows.push({
|
|
48
|
-
kind: "due",
|
|
49
|
-
label: "Amount due",
|
|
50
|
-
amount: orderMoney(order.amount_due)
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return rows;
|
|
54
|
-
}
|
|
55
|
-
var ended = /* @__PURE__ */ new Set(["completed", "cancelled", "rejected"]);
|
|
56
|
-
var orderEnded = (order) => ended.has(order.status);
|
|
57
|
-
function currentStep(order) {
|
|
58
|
-
const last = order.timeline.at(-1);
|
|
59
|
-
return last ? { title: last.title, description: last.description } : {
|
|
60
|
-
title: order.status.replaceAll("_", " ").replace(/^./, (first) => first.toUpperCase()),
|
|
61
|
-
description: ""
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function orderTime(iso, timeZone) {
|
|
65
|
-
const date = new Date(iso);
|
|
66
|
-
if (Number.isNaN(date.getTime())) {
|
|
67
|
-
return iso;
|
|
68
|
-
}
|
|
69
|
-
return new Intl.DateTimeFormat("en-GB", {
|
|
70
|
-
day: "numeric",
|
|
71
|
-
month: "short",
|
|
72
|
-
hour: "2-digit",
|
|
73
|
-
minute: "2-digit",
|
|
74
|
-
...timeZone ? { timeZone } : {}
|
|
75
|
-
}).format(date);
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
currentStep,
|
|
79
|
-
orderEnded,
|
|
80
|
-
orderMoney,
|
|
81
|
-
orderTime,
|
|
82
|
-
orderTotals
|
|
83
|
-
};
|
|
1
|
+
import{money}from"@zappie/sdk";var orderMoney=value=>money(value.amount_minor,value.currency);function orderTotals(order){const rows=[{kind:"subtotal",label:"Subtotal",amount:orderMoney(order.subtotal)}];let delivery=false;for(const charge of order.charges){const isDelivery=charge.code==="delivery";delivery||(delivery=isDelivery);rows.push({kind:isDelivery?"delivery":"charge",label:charge.label,amount:orderMoney(charge.amount),...charge.waived?{note:"waived"}:charge.included?{note:"included"}:{}})}if(!delivery&&order.delivery_fee.amount_minor>0){rows.push({kind:"delivery",label:"Delivery",amount:orderMoney(order.delivery_fee)})}const discounts=order.discounts.length?order.discounts:order.discount.amount_minor>0?[{label:"Discount",amount:order.discount}]:[];for(const discount of discounts){rows.push({kind:"discount",label:discount.label,amount:orderMoney({...discount.amount,amount_minor:-discount.amount.amount_minor}),..."promo_code"in discount&&discount.promo_code?{promoCode:discount.promo_code}:{}})}rows.push({kind:"total",label:"Total",amount:orderMoney(order.total)});if(order.amount_paid.amount_minor>0){rows.push({kind:"paid",label:"Paid",amount:orderMoney(order.amount_paid)})}if(order.amount_due.amount_minor>0){rows.push({kind:"due",label:"Amount due",amount:orderMoney(order.amount_due)})}return rows}var ended=new Set(["completed","cancelled","rejected"]);var orderEnded=order=>ended.has(order.status);function currentStep(order){const last=order.timeline.at(-1);return last?{title:last.title,description:last.description}:{title:order.status.replaceAll("_"," ").replace(/^./,first=>first.toUpperCase()),description:""}}function orderTime(iso,timeZone){const date=new Date(iso);if(Number.isNaN(date.getTime())){return iso}return new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit",...timeZone?{timeZone}:{}}).format(date)}export{currentStep,orderEnded,orderMoney,orderTime,orderTotals};
|
|
84
2
|
//# sourceMappingURL=model.js.map
|
package/dist/order/model.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/order/model.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAAA,OAAS,UAAwC,cAI1C,IAAM,WAAc,OACzB,MAAM,MAAM,aAAc,MAAM,QAAoB,EAuB/C,SAAS,YAAY,MAAuC,CACjE,MAAM,KAAwB,CAC5B,CAAE,KAAM,WAAY,MAAO,WAAY,OAAQ,WAAW,MAAM,QAAQ,CAAE,CAC5E,EACA,IAAI,SAAW,MACf,UAAW,UAAU,MAAM,QAAS,CAClC,MAAM,WAAa,OAAO,OAAS,WACnC,oBAAa,YACb,KAAK,KAAK,CACR,KAAM,WAAa,WAAa,SAChC,MAAO,OAAO,MACd,OAAQ,WAAW,OAAO,MAAM,EAChC,GAAI,OAAO,OACP,CAAE,KAAM,QAAkB,EAC1B,OAAO,SACL,CAAE,KAAM,UAAoB,EAC5B,CAAC,CACT,CAAC,CACH,CACA,GAAI,CAAC,UAAY,MAAM,aAAa,aAAe,EAAG,CACpD,KAAK,KAAK,CACR,KAAM,WACN,MAAO,WACP,OAAQ,WAAW,MAAM,YAAY,CACvC,CAAC,CACH,CACA,MAAM,UAAY,MAAM,UAAU,OAC9B,MAAM,UACN,MAAM,SAAS,aAAe,EAC5B,CAAC,CAAE,MAAO,WAAY,OAAQ,MAAM,QAAS,CAAC,EAC9C,CAAC,EACP,UAAW,YAAY,UAAW,CAChC,KAAK,KAAK,CACR,KAAM,WACN,MAAO,SAAS,MAChB,OAAQ,WAAW,CACjB,GAAG,SAAS,OACZ,aAAc,CAAC,SAAS,OAAO,YACjC,CAAC,EACD,GAAI,eAAgB,UAAY,SAAS,WACrC,CAAE,UAAW,SAAS,UAAW,EACjC,CAAC,CACP,CAAC,CACH,CACA,KAAK,KAAK,CAAE,KAAM,QAAS,MAAO,QAAS,OAAQ,WAAW,MAAM,KAAK,CAAE,CAAC,EAC5E,GAAI,MAAM,YAAY,aAAe,EAAG,CACtC,KAAK,KAAK,CACR,KAAM,OACN,MAAO,OACP,OAAQ,WAAW,MAAM,WAAW,CACtC,CAAC,CACH,CACA,GAAI,MAAM,WAAW,aAAe,EAAG,CACrC,KAAK,KAAK,CACR,KAAM,MACN,MAAO,aACP,OAAQ,WAAW,MAAM,UAAU,CACrC,CAAC,CACH,CACA,OAAO,IACT,CAEA,IAAM,MAAQ,IAAI,IAAI,CAAC,YAAa,YAAa,UAAU,CAAC,EAGrD,IAAM,WAAc,OAAyB,MAAM,IAAI,MAAM,MAAM,EAMnE,SAAS,YAAY,MAG1B,CACA,MAAM,KAAO,MAAM,SAAS,GAAG,EAAE,EACjC,OAAO,KACH,CAAE,MAAO,KAAK,MAAO,YAAa,KAAK,WAAY,EACnD,CACE,MAAO,MAAM,OACV,WAAW,IAAK,GAAG,EACnB,QAAQ,KAAO,OAAU,MAAM,YAAY,CAAC,EAC/C,YAAa,EACf,CACN,CAMO,SAAS,UAAU,IAAa,SAA2B,CAChE,MAAM,KAAO,IAAI,KAAK,GAAG,EACzB,GAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,EAAG,CAChC,OAAO,GACT,CACA,OAAO,IAAI,KAAK,eAAe,QAAS,CACtC,IAAK,UACL,MAAO,QACP,KAAM,UACN,OAAQ,UACR,GAAI,SAAW,CAAE,QAAS,EAAI,CAAC,CACjC,CAAC,EAAE,OAAO,IAAI,CAChB",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,56 +1,2 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/order/use-customer-order.ts
|
|
4
|
-
import { useCallback, useEffect, useState } from "react";
|
|
5
|
-
import { orderEnded } from "./model.js";
|
|
6
|
-
function useCustomerOrder(customer, orderId, options = {}) {
|
|
7
|
-
const initial = options.initialOrder?.id === orderId ? options.initialOrder : void 0;
|
|
8
|
-
const [state, setState] = useState({ id: orderId, order: initial, error: void 0 });
|
|
9
|
-
const [attempt, setAttempt] = useState(0);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
const abort = new AbortController();
|
|
12
|
-
const show = (order2) => {
|
|
13
|
-
if (!abort.signal.aborted) {
|
|
14
|
-
setState({ id: orderId, order: order2, error: void 0 });
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
let stop;
|
|
18
|
-
customer.order(orderId, abort.signal).then(
|
|
19
|
-
(order2) => {
|
|
20
|
-
show(order2);
|
|
21
|
-
if (!abort.signal.aborted && !orderEnded(order2)) {
|
|
22
|
-
stop = customer.watchOrder(orderId, {
|
|
23
|
-
signal: abort.signal,
|
|
24
|
-
onOrder: show
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
(error2) => {
|
|
29
|
-
if (!abort.signal.aborted) {
|
|
30
|
-
setState((last) => ({
|
|
31
|
-
id: orderId,
|
|
32
|
-
order: last.id === orderId ? last.order : void 0,
|
|
33
|
-
error: error2
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
return () => {
|
|
39
|
-
abort.abort();
|
|
40
|
-
stop?.();
|
|
41
|
-
};
|
|
42
|
-
}, [customer, orderId, attempt]);
|
|
43
|
-
const retry = useCallback(() => setAttempt((value) => value + 1), []);
|
|
44
|
-
const order = state.id === orderId ? state.order : initial;
|
|
45
|
-
const error = state.id === orderId ? state.error : void 0;
|
|
46
|
-
return {
|
|
47
|
-
order,
|
|
48
|
-
error,
|
|
49
|
-
status: error === void 0 ? order ? "ready" : "loading" : error.status === 404 ? "not_found" : "error",
|
|
50
|
-
retry
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export {
|
|
54
|
-
useCustomerOrder
|
|
55
|
-
};
|
|
1
|
+
"use client";import{useCallback,useEffect,useState}from"react";import{orderEnded}from"./model.js";function useCustomerOrder(customer,orderId,options={}){const initial=options.initialOrder?.id===orderId?options.initialOrder:void 0;const[state,setState]=useState({id:orderId,order:initial,error:void 0});const[attempt,setAttempt]=useState(0);useEffect(()=>{const abort=new AbortController;const show=order2=>{if(!abort.signal.aborted){setState({id:orderId,order:order2,error:void 0})}};let stop;customer.order(orderId,abort.signal).then(order2=>{show(order2);if(!abort.signal.aborted&&!orderEnded(order2)){stop=customer.watchOrder(orderId,{signal:abort.signal,onOrder:show})}},error2=>{if(!abort.signal.aborted){setState(last=>({id:orderId,order:last.id===orderId?last.order:void 0,error:error2}))}});return()=>{abort.abort();stop?.()}},[customer,orderId,attempt]);const retry=useCallback(()=>setAttempt(value=>value+1),[]);const order=state.id===orderId?state.order:initial;const error=state.id===orderId?state.error:void 0;return{order,error,status:error===void 0?order?"ready":"loading":error.status===404?"not_found":"error",retry}}export{useCustomerOrder};
|
|
56
2
|
//# sourceMappingURL=use-customer-order.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/order/use-customer-order.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "aAEA,OAAS,YAAa,UAAW,aAAgB,QACjD,OAAS,eAAkB,aAwBpB,SAAS,iBACd,SACA,QACA,QAA4C,CAAC,EACzB,CACpB,MAAM,QACJ,QAAQ,cAAc,KAAO,QAAU,QAAQ,aAAe,OAChE,KAAM,CAAC,MAAO,QAAQ,EAAI,SAIvB,CAAE,GAAI,QAAS,MAAO,QAAS,MAAO,MAAU,CAAC,EACpD,KAAM,CAAC,QAAS,UAAU,EAAI,SAAS,CAAC,EACxC,UAAU,IAAM,CACd,MAAM,MAAQ,IAAI,gBAClB,MAAM,KAAQA,QAAyB,CACrC,GAAI,CAAC,MAAM,OAAO,QAAS,CACzB,SAAS,CAAE,GAAI,QAAS,MAAAA,OAAO,MAAO,MAAU,CAAC,CACnD,CACF,EACA,IAAI,KACJ,SAAS,MAAM,QAAS,MAAM,MAAM,EAAE,KACnCA,QAAU,CACT,KAAKA,MAAK,EACV,GAAI,CAAC,MAAM,OAAO,SAAW,CAAC,WAAWA,MAAK,EAAG,CAC/C,KAAO,SAAS,WAAW,QAAS,CAClC,OAAQ,MAAM,OACd,QAAS,IACX,CAAC,CACH,CACF,EACCC,QAAmB,CAClB,GAAI,CAAC,MAAM,OAAO,QAAS,CACzB,SAAU,OAAU,CAClB,GAAI,QACJ,MAAO,KAAK,KAAO,QAAU,KAAK,MAAQ,OAC1C,MAAAA,MACF,EAAE,CACJ,CACF,CACF,EACA,MAAO,IAAM,CACX,MAAM,MAAM,EACZ,OAAO,CACT,CACF,EAAG,CAAC,SAAU,QAAS,OAAO,CAAC,EAC/B,MAAM,MAAQ,YAAY,IAAM,WAAY,OAAU,MAAQ,CAAC,EAAG,CAAC,CAAC,EACpE,MAAM,MAAQ,MAAM,KAAO,QAAU,MAAM,MAAQ,QACnD,MAAM,MAAQ,MAAM,KAAO,QAAU,MAAM,MAAQ,OACnD,MAAO,CACL,MACA,MACA,OACE,QAAU,OACN,MACE,QACA,UACD,MAA8B,SAAW,IACxC,YACA,QACR,KACF,CACF",
|
|
5
5
|
"names": ["order", "error"]
|
|
6
6
|
}
|
package/dist/otp/input.js
CHANGED
|
@@ -1,110 +1,2 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/otp/input.tsx
|
|
4
|
-
import {
|
|
5
|
-
forwardRef,
|
|
6
|
-
useEffect,
|
|
7
|
-
useRef
|
|
8
|
-
} from "react";
|
|
9
|
-
import { composeRefs, part } from "../internal/slot.js";
|
|
10
|
-
import { useControllableState } from "../internal/use-controllable-state.js";
|
|
11
|
-
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
function slotAttributes(index, length, value, disabled, update, focus) {
|
|
13
|
-
return {
|
|
14
|
-
type: "text",
|
|
15
|
-
inputMode: "numeric",
|
|
16
|
-
autoComplete: index === 0 ? "one-time-code" : "off",
|
|
17
|
-
"aria-label": `Digit ${index + 1} of ${length}`,
|
|
18
|
-
"data-otp-slot": index,
|
|
19
|
-
value: value[index] ?? "",
|
|
20
|
-
disabled,
|
|
21
|
-
onChange: (event) => update(index, event.target.value),
|
|
22
|
-
onPaste: (event) => {
|
|
23
|
-
event.preventDefault();
|
|
24
|
-
update(index, event.clipboardData.getData("text"));
|
|
25
|
-
},
|
|
26
|
-
onKeyDown: (event) => {
|
|
27
|
-
if (event.key === "Backspace") {
|
|
28
|
-
event.preventDefault();
|
|
29
|
-
const target = value[index] ? index : Math.max(0, index - 1);
|
|
30
|
-
update(target, "");
|
|
31
|
-
focus(target);
|
|
32
|
-
} else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
33
|
-
event.preventDefault();
|
|
34
|
-
focus(index + (event.key === "ArrowLeft" ? -1 : 1));
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
onFocus: (event) => event.currentTarget.select()
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
var Input = /* @__PURE__ */ forwardRef(function Input2({
|
|
41
|
-
length = 6,
|
|
42
|
-
value,
|
|
43
|
-
defaultValue = "",
|
|
44
|
-
onValueChange,
|
|
45
|
-
onComplete,
|
|
46
|
-
disabled = false,
|
|
47
|
-
...props
|
|
48
|
-
}, ref) {
|
|
49
|
-
if (!Number.isInteger(length) || length < 1 || length > 12) {
|
|
50
|
-
throw new RangeError("OTP length must be 1\u201312");
|
|
51
|
-
}
|
|
52
|
-
const [current, setValue] = useControllableState({
|
|
53
|
-
value,
|
|
54
|
-
defaultValue,
|
|
55
|
-
onChange: onValueChange
|
|
56
|
-
});
|
|
57
|
-
const element = useRef(null);
|
|
58
|
-
const previous = useRef("");
|
|
59
|
-
const callback = useRef(onComplete);
|
|
60
|
-
callback.current = onComplete;
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (current.length === length && /^\d+$/.test(current) && previous.current !== current) {
|
|
63
|
-
callback.current?.(current);
|
|
64
|
-
}
|
|
65
|
-
previous.current = current;
|
|
66
|
-
}, [current, length]);
|
|
67
|
-
const focus = (index) => element.current?.querySelector(
|
|
68
|
-
`[data-otp-slot="${Math.max(0, Math.min(length - 1, index))}"]`
|
|
69
|
-
)?.focus();
|
|
70
|
-
const update = (index, text) => {
|
|
71
|
-
if (disabled) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const digits = text.replace(/\D/g, "");
|
|
75
|
-
const start = digits.length >= length ? 0 : index;
|
|
76
|
-
const next = (current.slice(0, start) + digits + current.slice(start + Math.max(1, digits.length))).slice(0, length);
|
|
77
|
-
setValue(next);
|
|
78
|
-
if (digits) {
|
|
79
|
-
focus(start + digits.length);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const adopt = useRef(update);
|
|
83
|
-
adopt.current = update;
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
const typed = Array.from(
|
|
86
|
-
element.current?.querySelectorAll("[data-otp-slot]") ?? [],
|
|
87
|
-
(input) => input.value
|
|
88
|
-
).join("");
|
|
89
|
-
if (typed && typed !== current) {
|
|
90
|
-
adopt.current(0, typed);
|
|
91
|
-
}
|
|
92
|
-
}, []);
|
|
93
|
-
const getSlotProps = (index) => slotAttributes(index, length, current, disabled, update, focus);
|
|
94
|
-
const slots = Array.from({ length }, (_, index) => current[index] ?? "");
|
|
95
|
-
return part(
|
|
96
|
-
"div",
|
|
97
|
-
{
|
|
98
|
-
...props,
|
|
99
|
-
children: props.children ?? slots.map((_, index) => /* @__PURE__ */ jsx("input", { ...getSlotProps(index) }, index))
|
|
100
|
-
},
|
|
101
|
-
{ value: current, slots, getSlotProps },
|
|
102
|
-
{ role: "group", "data-disabled": disabled ? "" : void 0 },
|
|
103
|
-
composeRefs(ref, element)
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
var Otp = { Input };
|
|
107
|
-
export {
|
|
108
|
-
Otp
|
|
109
|
-
};
|
|
1
|
+
"use client";import{forwardRef,useEffect,useRef}from"react";import{composeRefs,part}from"../internal/slot.js";import{useControllableState}from"../internal/use-controllable-state.js";import{jsx}from"react/jsx-runtime";function slotAttributes(index,length,value,disabled,update,focus){return{type:"text",inputMode:"numeric",autoComplete:index===0?"one-time-code":"off","aria-label":`Digit ${index+1} of ${length}`,"data-otp-slot":index,value:value[index]??"",disabled,onChange:event=>update(index,event.target.value),onPaste:event=>{event.preventDefault();update(index,event.clipboardData.getData("text"))},onKeyDown:event=>{if(event.key==="Backspace"){event.preventDefault();const target=value[index]?index:Math.max(0,index-1);update(target,"");focus(target)}else if(event.key==="ArrowLeft"||event.key==="ArrowRight"){event.preventDefault();focus(index+(event.key==="ArrowLeft"?-1:1))}},onFocus:event=>event.currentTarget.select()}}var Input=/*@__PURE__ */forwardRef(function Input2({length=6,value,defaultValue="",onValueChange,onComplete,disabled=false,...props},ref){if(!Number.isInteger(length)||length<1||length>12){throw new RangeError("OTP length must be 1\u201312")}const[current,setValue]=useControllableState({value,defaultValue,onChange:onValueChange});const element=useRef(null);const previous=useRef("");const callback=useRef(onComplete);callback.current=onComplete;useEffect(()=>{if(current.length===length&&/^\d+$/.test(current)&&previous.current!==current){callback.current?.(current)}previous.current=current},[current,length]);const focus=index=>element.current?.querySelector(`[data-otp-slot="${Math.max(0,Math.min(length-1,index))}"]`)?.focus();const update=(index,text)=>{if(disabled){return}const digits=text.replace(/\D/g,"");const start=digits.length>=length?0:index;const next=(current.slice(0,start)+digits+current.slice(start+Math.max(1,digits.length))).slice(0,length);setValue(next);if(digits){focus(start+digits.length)}};const adopt=useRef(update);adopt.current=update;useEffect(()=>{const typed=Array.from(element.current?.querySelectorAll("[data-otp-slot]")??[],input=>input.value).join("");if(typed&&typed!==current){adopt.current(0,typed)}},[]);const getSlotProps=index=>slotAttributes(index,length,current,disabled,update,focus);const slots=Array.from({length},(_,index)=>current[index]??"");return part("div",{...props,children:props.children??slots.map((_,index)=>jsx("input",{...getSlotProps(index)},index))},{value:current,slots,getSlotProps},{role:"group","data-disabled":disabled?"":void 0},composeRefs(ref,element))});var Otp={Input};export{Otp};
|
|
110
2
|
//# sourceMappingURL=input.js.map
|
package/dist/otp/input.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/otp/input.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "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",
|
|
5
5
|
"names": ["Input"]
|
|
6
6
|
}
|
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/overlay/drag-to-close.ts
|
|
4
|
-
import { useEffect, useRef, useState } from "react";
|
|
5
|
-
var attach;
|
|
6
|
-
var gesture;
|
|
7
|
-
var loadGesture = () => gesture ?? (gesture = import("./drag.js").then(
|
|
8
|
-
(module) => attach = module.attachDragToClose,
|
|
9
|
-
(error) => {
|
|
10
|
-
gesture = void 0;
|
|
11
|
-
throw error;
|
|
12
|
-
}
|
|
13
|
-
));
|
|
14
|
-
function provideGesture(gestureAttach) {
|
|
15
|
-
attach = gestureAttach;
|
|
16
|
-
}
|
|
17
|
-
function useDragToClose(options) {
|
|
18
|
-
const [panel, setPanel] = useState(null);
|
|
19
|
-
const latest = useRef(options);
|
|
20
|
-
latest.current = options;
|
|
21
|
-
const enabled = options.enabled ?? true;
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (!enabled || !panel) {
|
|
24
|
-
return void 0;
|
|
25
|
-
}
|
|
26
|
-
const options2 = () => latest.current;
|
|
27
|
-
let detach = attach?.(panel, options2);
|
|
28
|
-
let live = true;
|
|
29
|
-
if (!detach) {
|
|
30
|
-
loadGesture().then(
|
|
31
|
-
(loaded) => {
|
|
32
|
-
if (live) {
|
|
33
|
-
detach = loaded(panel, options2);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
() => {
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return () => {
|
|
41
|
-
live = false;
|
|
42
|
-
detach?.();
|
|
43
|
-
};
|
|
44
|
-
}, [enabled, panel]);
|
|
45
|
-
return setPanel;
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
provideGesture,
|
|
49
|
-
useDragToClose
|
|
50
|
-
};
|
|
1
|
+
"use client";import{useEffect,useRef,useState}from"react";var attach;var gesture;var loadGesture=()=>gesture??(gesture=import("./drag.js").then(module=>attach=module.attachDragToClose,error=>{gesture=void 0;throw error}));function provideGesture(gestureAttach){attach=gestureAttach}function useDragToClose(options){const[panel,setPanel]=useState(null);const latest=useRef(options);latest.current=options;const enabled=options.enabled??true;useEffect(()=>{if(!enabled||!panel){return void 0}const options2=()=>latest.current;let detach=attach?.(panel,options2);let live=true;if(!detach){loadGesture().then(loaded=>{if(live){detach=loaded(panel,options2)}},()=>{})}return()=>{live=false;detach?.()}},[enabled,panel]);return setPanel}export{provideGesture,useDragToClose};
|
|
51
2
|
//# sourceMappingURL=drag-to-close.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/overlay/drag-to-close.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "aACA,OAAS,UAAW,OAAQ,aAAgB,QAkB5C,IAAI,OACJ,IAAI,QAEJ,IAAM,YAAc,IACjB,kBAAY,OAAO,WAAQ,EAAE,KAC3B,QAAY,OAAS,OAAO,kBAC5B,OAAmB,CAClB,QAAU,OACV,MAAM,KACR,CACF,GAEK,SAAS,eAAe,cAA6B,CAC1D,OAAS,aACX,CAyBO,SAAS,eACd,QAC0B,CAC1B,KAAM,CAAC,MAAO,QAAQ,EAAI,SAAmB,IAAI,EACjD,MAAM,OAAS,OAAO,OAAO,EAC7B,OAAO,QAAU,QACjB,MAAM,QAAU,QAAQ,SAAW,KACnC,UAAU,IAAM,CACd,GAAI,CAAC,SAAW,CAAC,MAAO,CACtB,OAAO,MACT,CACA,MAAMA,SAAU,IAAM,OAAO,QAC7B,IAAI,OAAS,SAAS,MAAOA,QAAO,EACpC,IAAI,KAAO,KACX,GAAI,CAAC,OAAQ,CACX,YAAY,EAAE,KACX,QAAW,CACV,GAAI,KAAM,CACR,OAAS,OAAO,MAAOA,QAAO,CAChC,CACF,EACA,IAAM,CAAC,CACT,CACF,CACA,MAAO,IAAM,CACX,KAAO,MACP,SAAS,CACX,CACF,EAAG,CAAC,QAAS,KAAK,CAAC,EACnB,OAAO,QACT",
|
|
5
5
|
"names": ["options"]
|
|
6
6
|
}
|
package/dist/overlay/drag.js
CHANGED
|
@@ -1,210 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var EASE = "cubic-bezier(0.32, 0.72, 0, 1)";
|
|
3
|
-
var SETTLE_MS = 500;
|
|
4
|
-
var CLOSE_FRACTION = 0.25;
|
|
5
|
-
var CLOSE_VELOCITY = 0.4;
|
|
6
|
-
var SLOP = 4;
|
|
7
|
-
var EDGE = 2;
|
|
8
|
-
var NO_DRAG = "input, textarea, select, [contenteditable], [data-no-drag]";
|
|
9
|
-
var PHONE = "(pointer: coarse), (max-width: 639.98px)";
|
|
10
|
-
var STILL = "(prefers-reduced-motion: reduce)";
|
|
11
|
-
var matches = (query) => window.matchMedia(query).matches;
|
|
12
|
-
var vertical = (side) => side === "down" || side === "up";
|
|
13
|
-
function dragDirection(panel, preferred) {
|
|
14
|
-
if (!matches(PHONE)) {
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
const box = panel.getBoundingClientRect();
|
|
18
|
-
const top = box.top <= EDGE;
|
|
19
|
-
const bottom = box.bottom >= window.innerHeight - EDGE;
|
|
20
|
-
const left = box.left <= EDGE;
|
|
21
|
-
const right = box.right >= window.innerWidth - EDGE;
|
|
22
|
-
if (preferred) {
|
|
23
|
-
const spans = vertical(preferred) ? top && bottom : left && right;
|
|
24
|
-
return spans ? void 0 : preferred;
|
|
25
|
-
}
|
|
26
|
-
return bottom && !top ? "down" : right && !left ? "right" : left && !right ? "left" : void 0;
|
|
27
|
-
}
|
|
28
|
-
function scrolls(target, panel, side) {
|
|
29
|
-
for (let node = target; node && node !== panel.parentElement; node = node.parentElement) {
|
|
30
|
-
const style = getComputedStyle(node);
|
|
31
|
-
if (vertical(side)) {
|
|
32
|
-
const room = node.scrollHeight - node.clientHeight;
|
|
33
|
-
if (/(auto|scroll)/.test(style.overflowY) && room > 0 && (side === "down" ? node.scrollTop > 0 : node.scrollTop < room - 1)) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
} else if (/(auto|scroll)/.test(style.overflowX) && node.scrollWidth > node.clientWidth) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
function attachDragToClose(panel, options) {
|
|
43
|
-
let side;
|
|
44
|
-
let start;
|
|
45
|
-
let dragging = false;
|
|
46
|
-
let still = false;
|
|
47
|
-
let offset = 0;
|
|
48
|
-
let settle;
|
|
49
|
-
const shade = () => options().backdrop?.(panel);
|
|
50
|
-
const paint = (distance, spring) => {
|
|
51
|
-
const sign = side === "up" || side === "left" ? -1 : 1;
|
|
52
|
-
const transition = spring ? `${SETTLE_MS}ms ${EASE}` : "none";
|
|
53
|
-
panel.style.transition = spring ? `translate ${transition}` : transition;
|
|
54
|
-
panel.style.translate = side && vertical(side) ? `0 ${sign * distance}px` : `${sign * distance}px 0`;
|
|
55
|
-
const backdrop = shade();
|
|
56
|
-
if (backdrop) {
|
|
57
|
-
backdrop.style.transition = spring ? `filter ${transition}` : transition;
|
|
58
|
-
backdrop.style.filter = `opacity(${Math.max(0, 1 - distance / extent())})`;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const rest = () => {
|
|
62
|
-
window.clearTimeout(settle);
|
|
63
|
-
panel.style.translate = panel.style.transition = "";
|
|
64
|
-
const backdrop = shade();
|
|
65
|
-
if (backdrop) {
|
|
66
|
-
backdrop.style.filter = backdrop.style.transition = "";
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const extent = () => (side && vertical(side) ? panel.offsetHeight : panel.offsetWidth) || 1;
|
|
70
|
-
const mark = () => {
|
|
71
|
-
const direction = dragDirection(panel, options().direction);
|
|
72
|
-
if (direction) {
|
|
73
|
-
panel.setAttribute("data-drag-to-close", direction);
|
|
74
|
-
} else {
|
|
75
|
-
panel.removeAttribute("data-drag-to-close");
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const begin = (x, y, target) => {
|
|
79
|
-
side = dragDirection(panel, options().direction);
|
|
80
|
-
still = matches(STILL);
|
|
81
|
-
dragging = false;
|
|
82
|
-
offset = 0;
|
|
83
|
-
start = side && target instanceof Element && !target.closest(NO_DRAG) ? { x, y, at: performance.now() } : void 0;
|
|
84
|
-
};
|
|
85
|
-
const move = (x, y, target) => {
|
|
86
|
-
if (!start || !side) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
const dx = x - start.x;
|
|
90
|
-
const dy = y - start.y;
|
|
91
|
-
const along = side === "down" ? dy : side === "up" ? -dy : side === "right" ? dx : -dx;
|
|
92
|
-
const across = vertical(side) ? dx : dy;
|
|
93
|
-
if (!dragging) {
|
|
94
|
-
if (Math.abs(along) < SLOP && Math.abs(across) < SLOP) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (along <= 0 || Math.abs(across) > Math.abs(along) || target instanceof Element && scrolls(target, panel, side)) {
|
|
98
|
-
start = void 0;
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
dragging = true;
|
|
102
|
-
window.clearTimeout(settle);
|
|
103
|
-
panel.setAttribute("data-swiping", "");
|
|
104
|
-
}
|
|
105
|
-
offset = Math.max(0, along);
|
|
106
|
-
if (!still) {
|
|
107
|
-
paint(offset, false);
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
};
|
|
111
|
-
const end = () => {
|
|
112
|
-
const began = start;
|
|
113
|
-
const dragged = dragging;
|
|
114
|
-
start = void 0;
|
|
115
|
-
dragging = false;
|
|
116
|
-
if (!began || !dragged) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
panel.removeAttribute("data-swiping");
|
|
120
|
-
const velocity = offset / Math.max(1, performance.now() - began.at);
|
|
121
|
-
if (offset > extent() * CLOSE_FRACTION || velocity > CLOSE_VELOCITY) {
|
|
122
|
-
options().onClose();
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
if (!still) {
|
|
126
|
-
paint(0, true);
|
|
127
|
-
settle = window.setTimeout(rest, SETTLE_MS);
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
130
|
-
};
|
|
131
|
-
const touch = (event) => event.touches.length === 1 ? event.touches[0] : void 0;
|
|
132
|
-
const onTouchStart = (event) => {
|
|
133
|
-
const point = touch(event);
|
|
134
|
-
if (point) {
|
|
135
|
-
begin(point.clientX, point.clientY, event.target);
|
|
136
|
-
} else {
|
|
137
|
-
start = void 0;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
const onTouchMove = (event) => {
|
|
141
|
-
const point = touch(event);
|
|
142
|
-
if (point && move(point.clientX, point.clientY, event.target) && event.cancelable) {
|
|
143
|
-
event.preventDefault();
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
const onTouchEnd = () => {
|
|
147
|
-
end();
|
|
148
|
-
};
|
|
149
|
-
const mouse = (event) => event.pointerType === "mouse";
|
|
150
|
-
const onPointerDown = (event) => {
|
|
151
|
-
if (mouse(event) && event.button === 0) {
|
|
152
|
-
begin(event.clientX, event.clientY, event.target);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const onPointerMove = (event) => {
|
|
156
|
-
if (mouse(event) && move(event.clientX, event.clientY, event.target)) {
|
|
157
|
-
event.preventDefault();
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const swallow = (event) => {
|
|
161
|
-
event.preventDefault();
|
|
162
|
-
event.stopPropagation();
|
|
163
|
-
};
|
|
164
|
-
const onPointerUp = (event) => {
|
|
165
|
-
if (mouse(event) && end()) {
|
|
166
|
-
window.addEventListener("click", swallow, { capture: true, once: true });
|
|
167
|
-
window.setTimeout(
|
|
168
|
-
() => window.removeEventListener("click", swallow, { capture: true })
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const phone = window.matchMedia(PHONE);
|
|
173
|
-
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(mark) : void 0;
|
|
174
|
-
rest();
|
|
175
|
-
mark();
|
|
176
|
-
observer?.observe(panel);
|
|
177
|
-
phone.addEventListener("change", mark);
|
|
178
|
-
window.addEventListener("resize", mark);
|
|
179
|
-
panel.addEventListener("animationend", mark);
|
|
180
|
-
panel.addEventListener("transitionend", mark);
|
|
181
|
-
panel.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
182
|
-
panel.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
183
|
-
panel.addEventListener("touchend", onTouchEnd);
|
|
184
|
-
panel.addEventListener("touchcancel", onTouchEnd);
|
|
185
|
-
panel.addEventListener("pointerdown", onPointerDown);
|
|
186
|
-
window.addEventListener("pointermove", onPointerMove);
|
|
187
|
-
window.addEventListener("pointerup", onPointerUp);
|
|
188
|
-
return () => {
|
|
189
|
-
window.clearTimeout(settle);
|
|
190
|
-
observer?.disconnect();
|
|
191
|
-
phone.removeEventListener("change", mark);
|
|
192
|
-
window.removeEventListener("resize", mark);
|
|
193
|
-
panel.removeEventListener("animationend", mark);
|
|
194
|
-
panel.removeEventListener("transitionend", mark);
|
|
195
|
-
panel.removeEventListener("touchstart", onTouchStart);
|
|
196
|
-
panel.removeEventListener("touchmove", onTouchMove);
|
|
197
|
-
panel.removeEventListener("touchend", onTouchEnd);
|
|
198
|
-
panel.removeEventListener("touchcancel", onTouchEnd);
|
|
199
|
-
panel.removeEventListener("pointerdown", onPointerDown);
|
|
200
|
-
window.removeEventListener("pointermove", onPointerMove);
|
|
201
|
-
window.removeEventListener("pointerup", onPointerUp);
|
|
202
|
-
panel.removeAttribute("data-drag-to-close");
|
|
203
|
-
panel.removeAttribute("data-swiping");
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
export {
|
|
207
|
-
attachDragToClose,
|
|
208
|
-
dragDirection
|
|
209
|
-
};
|
|
1
|
+
var EASE="cubic-bezier(0.32, 0.72, 0, 1)";var SETTLE_MS=500;var CLOSE_FRACTION=.25;var CLOSE_VELOCITY=.4;var SLOP=4;var EDGE=2;var NO_DRAG="input, textarea, select, [contenteditable], [data-no-drag]";var PHONE="(pointer: coarse), (max-width: 639.98px)";var STILL="(prefers-reduced-motion: reduce)";var matches=query=>window.matchMedia(query).matches;var vertical=side=>side==="down"||side==="up";function dragDirection(panel,preferred){if(!matches(PHONE)){return void 0}const box=panel.getBoundingClientRect();const top=box.top<=EDGE;const bottom=box.bottom>=window.innerHeight-EDGE;const left=box.left<=EDGE;const right=box.right>=window.innerWidth-EDGE;if(preferred){const spans=vertical(preferred)?top&&bottom:left&&right;return spans?void 0:preferred}return bottom&&!top?"down":right&&!left?"right":left&&!right?"left":void 0}function scrolls(target,panel,side){for(let node=target;node&&node!==panel.parentElement;node=node.parentElement){const style=getComputedStyle(node);if(vertical(side)){const room=node.scrollHeight-node.clientHeight;if(/(auto|scroll)/.test(style.overflowY)&&room>0&&(side==="down"?node.scrollTop>0:node.scrollTop<room-1)){return true}}else if(/(auto|scroll)/.test(style.overflowX)&&node.scrollWidth>node.clientWidth){return true}}return false}function attachDragToClose(panel,options){let side;let start;let dragging=false;let still=false;let offset=0;let settle;const shade=()=>options().backdrop?.(panel);const paint=(distance,spring)=>{const sign=side==="up"||side==="left"?-1:1;const transition=spring?`${SETTLE_MS}ms ${EASE}`:"none";panel.style.transition=spring?`translate ${transition}`:transition;panel.style.translate=side&&vertical(side)?`0 ${sign*distance}px`:`${sign*distance}px 0`;const backdrop=shade();if(backdrop){backdrop.style.transition=spring?`filter ${transition}`:transition;backdrop.style.filter=`opacity(${Math.max(0,1-distance/extent())})`}};const rest=()=>{window.clearTimeout(settle);panel.style.translate=panel.style.transition="";const backdrop=shade();if(backdrop){backdrop.style.filter=backdrop.style.transition=""}};const extent=()=>(side&&vertical(side)?panel.offsetHeight:panel.offsetWidth)||1;const mark=()=>{const direction=dragDirection(panel,options().direction);if(direction){panel.setAttribute("data-drag-to-close",direction)}else{panel.removeAttribute("data-drag-to-close")}};const begin=(x,y,target)=>{side=dragDirection(panel,options().direction);still=matches(STILL);dragging=false;offset=0;start=side&&target instanceof Element&&!target.closest(NO_DRAG)?{x,y,at:performance.now()}:void 0};const move=(x,y,target)=>{if(!start||!side){return false}const dx=x-start.x;const dy=y-start.y;const along=side==="down"?dy:side==="up"?-dy:side==="right"?dx:-dx;const across=vertical(side)?dx:dy;if(!dragging){if(Math.abs(along)<SLOP&&Math.abs(across)<SLOP){return false}if(along<=0||Math.abs(across)>Math.abs(along)||target instanceof Element&&scrolls(target,panel,side)){start=void 0;return false}dragging=true;window.clearTimeout(settle);panel.setAttribute("data-swiping","")}offset=Math.max(0,along);if(!still){paint(offset,false)}return true};const end=()=>{const began=start;const dragged=dragging;start=void 0;dragging=false;if(!began||!dragged){return false}panel.removeAttribute("data-swiping");const velocity=offset/Math.max(1,performance.now()-began.at);if(offset>extent()*CLOSE_FRACTION||velocity>CLOSE_VELOCITY){options().onClose();return true}if(!still){paint(0,true);settle=window.setTimeout(rest,SETTLE_MS)}return true};const touch=event=>event.touches.length===1?event.touches[0]:void 0;const onTouchStart=event=>{const point=touch(event);if(point){begin(point.clientX,point.clientY,event.target)}else{start=void 0}};const onTouchMove=event=>{const point=touch(event);if(point&&move(point.clientX,point.clientY,event.target)&&event.cancelable){event.preventDefault()}};const onTouchEnd=()=>{end()};const mouse=event=>event.pointerType==="mouse";const onPointerDown=event=>{if(mouse(event)&&event.button===0){begin(event.clientX,event.clientY,event.target)}};const onPointerMove=event=>{if(mouse(event)&&move(event.clientX,event.clientY,event.target)){event.preventDefault()}};const swallow=event=>{event.preventDefault();event.stopPropagation()};const onPointerUp=event=>{if(mouse(event)&&end()){window.addEventListener("click",swallow,{capture:true,once:true});window.setTimeout(()=>window.removeEventListener("click",swallow,{capture:true}))}};const phone=window.matchMedia(PHONE);const observer=typeof ResizeObserver==="function"?new ResizeObserver(mark):void 0;rest();mark();observer?.observe(panel);phone.addEventListener("change",mark);window.addEventListener("resize",mark);panel.addEventListener("animationend",mark);panel.addEventListener("transitionend",mark);panel.addEventListener("touchstart",onTouchStart,{passive:true});panel.addEventListener("touchmove",onTouchMove,{passive:false});panel.addEventListener("touchend",onTouchEnd);panel.addEventListener("touchcancel",onTouchEnd);panel.addEventListener("pointerdown",onPointerDown);window.addEventListener("pointermove",onPointerMove);window.addEventListener("pointerup",onPointerUp);return()=>{window.clearTimeout(settle);observer?.disconnect();phone.removeEventListener("change",mark);window.removeEventListener("resize",mark);panel.removeEventListener("animationend",mark);panel.removeEventListener("transitionend",mark);panel.removeEventListener("touchstart",onTouchStart);panel.removeEventListener("touchmove",onTouchMove);panel.removeEventListener("touchend",onTouchEnd);panel.removeEventListener("touchcancel",onTouchEnd);panel.removeEventListener("pointerdown",onPointerDown);window.removeEventListener("pointermove",onPointerMove);window.removeEventListener("pointerup",onPointerUp);panel.removeAttribute("data-drag-to-close");panel.removeAttribute("data-swiping")}}export{attachDragToClose,dragDirection};
|
|
210
2
|
//# sourceMappingURL=drag.js.map
|