@apple-pie/slice 0.1.3 → 0.1.4
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/README.md +47 -77
- package/dist/cjs/chunks/{Button-hg5kGC1P.js → Button-krf4dQeL.js} +4 -2
- package/dist/cjs/chunks/{FileList-BQgcnKPP.js → FileList-CkpMj-os.js} +1 -1
- package/dist/cjs/chunks/{ProgressIndicator-qjya_Yb5.js → ProgressIndicator-DVD-gD3T.js} +1 -1
- package/dist/cjs/chunks/{PromptInput-ZqHQUfXw.js → PromptInput-DULf5ock.js} +1 -1
- package/dist/cjs/chunks/SSEConnection-B_yE8cXz.js +140 -0
- package/dist/cjs/chunks/{TextArea-BhzVGfKA.js → TextArea-BJCjRUEG.js} +1 -1
- package/dist/cjs/chunks/{TextField-hIjxrOG9.js → TextField-CjT26H_6.js} +18 -16
- package/dist/cjs/chunks/{UploadArea-B4GA06LW.js → UploadArea-BE6but3t.js} +1 -1
- package/dist/cjs/chunks/WSConnection-DCBuJGmb.js +206 -0
- package/dist/cjs/chunks/{sseStore-Dg0WuXsI.js → sseStore-CIIeshjm.js} +3 -3
- package/dist/cjs/chunks/windowStore-CCxCOUqa.js +156 -0
- package/dist/cjs/components/Button/index.js +2 -2
- package/dist/cjs/components/FileList/index.js +2 -2
- package/dist/cjs/components/Progress/index.js +2 -2
- package/dist/cjs/components/PromptInput/index.js +4 -4
- package/dist/cjs/components/TextArea/index.js +3 -3
- package/dist/cjs/components/Textfield/index.js +3 -3
- package/dist/cjs/components/UploadArea/index.js +7 -8
- package/dist/cjs/hooks/useWindow.js +46 -11
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/stores/SSE.js +2 -2
- package/dist/cjs/stores/WS.js +62 -0
- package/dist/cjs/stores/window.js +14 -3
- package/dist/cjs/stores.js +15 -4
- package/dist/cjs/utils/index.js +2 -2
- package/dist/cjs/utils/objects/index.js +4 -138
- package/dist/esm/chunks/{Button-DJDS7Yad.mjs → Button-kXFJmcKv.mjs} +4 -2
- package/dist/esm/chunks/{FileList-CmlXqPXl.mjs → FileList-Bon537-t.mjs} +1 -1
- package/dist/esm/chunks/{PromptInput-DSHVUuEf.mjs → PromptInput-DXFAZspz.mjs} +3 -3
- package/dist/esm/chunks/SSEConnection-Dj9P0SWE.mjs +140 -0
- package/dist/esm/chunks/{TextArea-CyVBzMoN.mjs → TextArea-DBmM6aQm.mjs} +1 -1
- package/dist/esm/chunks/{TextField-CYI2vbvO.mjs → TextField-DyUTMegV.mjs} +18 -16
- package/dist/esm/chunks/{UploadArea-Kez3VD4d.mjs → UploadArea-tT5V8q23.mjs} +3 -3
- package/dist/esm/chunks/WSConnection-DlYSitff.mjs +206 -0
- package/dist/esm/chunks/{sseStore-m3IPyLwJ.mjs → sseStore-DdqmnAAf.mjs} +2 -2
- package/dist/esm/chunks/windowStore-BOTh1g37.mjs +148 -0
- package/dist/esm/components/Button/index.mjs +2 -2
- package/dist/esm/components/FileList/index.mjs +2 -2
- package/dist/esm/components/Progress/index.mjs +3 -3
- package/dist/esm/components/PromptInput/index.mjs +4 -4
- package/dist/esm/components/TextArea/index.mjs +3 -3
- package/dist/esm/components/Textfield/index.mjs +3 -3
- package/dist/esm/components/UploadArea/index.mjs +7 -7
- package/dist/esm/hooks/useWindow.mjs +47 -11
- package/dist/esm/index.mjs +7 -7
- package/dist/esm/stores/SSE.mjs +2 -2
- package/dist/esm/stores/WS.mjs +59 -0
- package/dist/esm/stores/window.mjs +3 -1
- package/dist/esm/stores.mjs +5 -5
- package/dist/esm/utils/index.mjs +3 -1
- package/dist/esm/utils/objects/index.mjs +4 -139
- package/dist/types/hooks/index.d.ts +1 -1
- package/dist/types/hooks/useWindow/useWindow.d.ts +19 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/stores/WS/_types.d.ts +17 -0
- package/dist/types/stores/WS/index.d.ts +2 -0
- package/dist/types/stores/WS/wsStore.d.ts +19 -0
- package/dist/types/stores/window/_types.d.ts +5 -0
- package/dist/types/stores/window/index.d.ts +3 -2
- package/dist/types/stores/window/windowStore.d.ts +8 -0
- package/dist/types/utils/index.d.ts +2 -2
- package/dist/types/utils/objects/WSConnection/WSConnection.d.ts +147 -0
- package/dist/types/utils/objects/index.d.ts +2 -0
- package/package.json +1 -1
- package/dist/cjs/chunks/windowStore-RaJswiHM.js +0 -70
- package/dist/esm/chunks/windowStore-CwW0i_le.mjs +0 -71
- package/dist/esm/chunks/{ProgressIndicator-h11R3FG1.mjs → ProgressIndicator-D2eairZl.mjs} +2 -2
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { a as __awaiter } from "./tslib.es6-c-7TIv71.mjs";
|
|
2
|
+
|
|
3
|
+
class WSConnection {
|
|
4
|
+
get connected() {
|
|
5
|
+
var _a;
|
|
6
|
+
return (null === (_a = this.socket) || void 0 === _a ? void 0 : _a.readyState) === WebSocket.OPEN;
|
|
7
|
+
}
|
|
8
|
+
get connection() {
|
|
9
|
+
return this.socket;
|
|
10
|
+
}
|
|
11
|
+
constructor(options) {
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13
|
+
if (this.socket = null, this.keepAliveTimer = null, this.reconnectIntervalTimer = null,
|
|
14
|
+
this.reconnectAttemptsCount = 0, this.manuallyClosed = !1,
|
|
15
|
+
/**
|
|
16
|
+
* Open handler
|
|
17
|
+
*/
|
|
18
|
+
this.onOpen = event => __awaiter(this, void 0, void 0, function*() {
|
|
19
|
+
var _a;
|
|
20
|
+
if (this.clearReconnectTimer(), this.reconnectAttemptsCount = 0, this.manuallyClosed = !1,
|
|
21
|
+
null === (_a = this.onOpenCallback) || void 0 === _a || _a.call(this, event), this.emitUnifiedMessage({
|
|
22
|
+
type: "open",
|
|
23
|
+
event: event
|
|
24
|
+
}), this.token) try {
|
|
25
|
+
const token = "string" == typeof this.token ? this.token : yield this.token();
|
|
26
|
+
if (!token) return void this.closeSocket({
|
|
27
|
+
code: 1e3,
|
|
28
|
+
reason: "Access token not provided"
|
|
29
|
+
});
|
|
30
|
+
this.send({
|
|
31
|
+
token: token
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const errorEvent = new ErrorEvent("token error", {
|
|
35
|
+
message: "Failed to resolve access token",
|
|
36
|
+
error: error
|
|
37
|
+
});
|
|
38
|
+
return this.emitErrorEvent(errorEvent), void this.closeSocket({
|
|
39
|
+
code: 1011,
|
|
40
|
+
reason: "Access token resolution failed"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
this.keepAlive && this.setKeepAlive();
|
|
44
|
+
}),
|
|
45
|
+
/**
|
|
46
|
+
* Message handler
|
|
47
|
+
*/
|
|
48
|
+
this.onMessage = event => {
|
|
49
|
+
const data = this.parseEventData(event.data);
|
|
50
|
+
void 0 !== data && (this.emitParsedMessage(data), this.emitUnifiedMessage({
|
|
51
|
+
type: "message",
|
|
52
|
+
data: data,
|
|
53
|
+
event: event
|
|
54
|
+
}));
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Close handler with the reconnection logic as needed
|
|
58
|
+
*/
|
|
59
|
+
this.onClose = event => {
|
|
60
|
+
var _a;
|
|
61
|
+
null === (_a = this.onCloseCallback) || void 0 === _a || _a.call(this, event), this.emitUnifiedMessage({
|
|
62
|
+
type: "close",
|
|
63
|
+
event: event
|
|
64
|
+
}), this.closeSocket(event), this.shouldReconnect(event) && this.reconnect();
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Error handler
|
|
68
|
+
*/
|
|
69
|
+
this.onError = event => {
|
|
70
|
+
const error = event instanceof ErrorEvent ? event : new ErrorEvent("websocket error", {
|
|
71
|
+
message: "WebSocket connection error"
|
|
72
|
+
});
|
|
73
|
+
this.emitErrorEvent(error);
|
|
74
|
+
}, this.url = options.url, this.autoReconnect = null === (_a = options.autoReconnect) || void 0 === _a || _a,
|
|
75
|
+
this.reconnectInterval = null !== (_b = options.reconnectInterval) && void 0 !== _b ? _b : 1e3,
|
|
76
|
+
this.reconnectAttempts = null !== (_c = options.reconnectAttempts) && void 0 !== _c ? _c : 5,
|
|
77
|
+
this.reconnectFalloff = null === (_d = options.reconnectFalloff) || void 0 === _d || _d,
|
|
78
|
+
this.keepAlive = null === (_e = options.keepAlive) || void 0 === _e || _e, this.keepAliveInterval = null !== (_f = options.keepAliveInterval) && void 0 !== _f ? _f : 3e4,
|
|
79
|
+
this.unifiedMessages = null !== (_g = options.unifiedMessages) && void 0 !== _g && _g,
|
|
80
|
+
this.token = null !== (_h = options.token) && void 0 !== _h ? _h : "", this.onMessageCallback = options.onMessageCallback,
|
|
81
|
+
this.onOpenCallback = options.onOpenCallback, this.onCloseCallback = options.onCloseCallback,
|
|
82
|
+
this.onErrorCallback = options.onErrorCallback, "undefined" == typeof WebSocket) throw new TypeError("WebSocket is not supported in this environment.");
|
|
83
|
+
this.connect();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gracefully handle sending messages
|
|
87
|
+
*/ send(message) {
|
|
88
|
+
var _a;
|
|
89
|
+
const data = "string" == typeof message ? message : JSON.stringify(message);
|
|
90
|
+
null === (_a = this.socket) || void 0 === _a || _a.send(data);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gracefully expose socket close
|
|
94
|
+
*/ close(closeEvent) {
|
|
95
|
+
this.manuallyClosed = !0, this.clearReconnectTimer(), this.reconnectAttemptsCount = 0,
|
|
96
|
+
this.closeSocket(closeEvent);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Emit the parsed message content for standard mode
|
|
100
|
+
*/ emitParsedMessage(data) {
|
|
101
|
+
if (this.unifiedMessages) return;
|
|
102
|
+
const callback = this.onMessageCallback;
|
|
103
|
+
null == callback || callback(data);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Emit a unified message if the unified flag is on
|
|
107
|
+
*/ emitUnifiedMessage(message) {
|
|
108
|
+
if (!this.unifiedMessages) return;
|
|
109
|
+
const callback = this.onMessageCallback;
|
|
110
|
+
null == callback || callback(message);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Emit error
|
|
114
|
+
*/ emitErrorEvent(error) {
|
|
115
|
+
var _a;
|
|
116
|
+
null === (_a = this.onErrorCallback) || void 0 === _a || _a.call(this, error), this.emitUnifiedMessage({
|
|
117
|
+
type: "error",
|
|
118
|
+
event: error
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Safe JSON parse message content
|
|
123
|
+
*/ parseEventData(rawData) {
|
|
124
|
+
if (rawData instanceof Blob || rawData instanceof ArrayBuffer || "string" == typeof rawData) {
|
|
125
|
+
if ("string" != typeof rawData) return rawData;
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(rawData);
|
|
128
|
+
} catch (_a) {
|
|
129
|
+
return rawData;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.emitErrorEvent(new ErrorEvent("parse error", {
|
|
133
|
+
message: "Unsupported websocket message data format"
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Attach socket listeners
|
|
138
|
+
*/ attachEventListeners() {
|
|
139
|
+
this.socket && (this.socket.addEventListener("open", this.onOpen), this.socket.addEventListener("message", this.onMessage),
|
|
140
|
+
this.socket.addEventListener("close", this.onClose), this.socket.addEventListener("error", this.onError));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* set keep alive pings
|
|
144
|
+
*/ setKeepAlive() {
|
|
145
|
+
this.socket && this.keepAlive && (this.keepAliveTimer && clearInterval(this.keepAliveTimer),
|
|
146
|
+
this.keepAliveTimer = setInterval(() => {
|
|
147
|
+
var _a;
|
|
148
|
+
(null === (_a = this.socket) || void 0 === _a ? void 0 : _a.readyState) === WebSocket.OPEN && this.socket.send("ping");
|
|
149
|
+
}, this.keepAliveInterval));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Clear keep alive pings
|
|
153
|
+
*/ clearKeepAliveTimer() {
|
|
154
|
+
this.keepAliveTimer && (clearInterval(this.keepAliveTimer), this.keepAliveTimer = null);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Clear reconnect timer
|
|
158
|
+
*/ clearReconnectTimer() {
|
|
159
|
+
this.reconnectIntervalTimer && (clearTimeout(this.reconnectIntervalTimer), this.reconnectIntervalTimer = null);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* detach all event listeners
|
|
163
|
+
*/ detachEventListeners() {
|
|
164
|
+
this.socket && (this.socket.removeEventListener("open", this.onOpen), this.socket.removeEventListener("message", this.onMessage),
|
|
165
|
+
this.socket.removeEventListener("close", this.onClose), this.socket.removeEventListener("error", this.onError));
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Connect the socket
|
|
169
|
+
*/ connect() {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
(null === (_a = this.socket) || void 0 === _a ? void 0 : _a.readyState) !== WebSocket.OPEN && (null === (_b = this.socket) || void 0 === _b ? void 0 : _b.readyState) !== WebSocket.CONNECTING && (this.socket = new WebSocket(this.url),
|
|
172
|
+
this.attachEventListeners());
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reconnect logic
|
|
176
|
+
*/ reconnect() {
|
|
177
|
+
if (!this.autoReconnect || this.manuallyClosed) return;
|
|
178
|
+
if (this.reconnectIntervalTimer) return;
|
|
179
|
+
const nextAttempt = this.reconnectAttemptsCount + 1;
|
|
180
|
+
if (nextAttempt > this.reconnectAttempts) return;
|
|
181
|
+
this.reconnectAttemptsCount = nextAttempt;
|
|
182
|
+
const delay = this.getReconnectDelay(nextAttempt);
|
|
183
|
+
this.reconnectIntervalTimer = setTimeout(() => {
|
|
184
|
+
this.reconnectIntervalTimer = null, this.manuallyClosed || this.connect();
|
|
185
|
+
}, delay);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Calculate reconnect delay with fall off
|
|
189
|
+
*/ getReconnectDelay(attempt) {
|
|
190
|
+
return this.reconnectFalloff ? this.reconnectInterval * Math.pow(2, attempt - 1) : this.reconnectInterval;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Determine if should reconnect based on the close event and props
|
|
194
|
+
*/ shouldReconnect(event) {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
return (null === (_a = this.socket) || void 0 === _a ? void 0 : _a.readyState) !== WebSocket.CONNECTING && (null === (_b = this.socket) || void 0 === _b ? void 0 : _b.readyState) !== WebSocket.OPEN && (this.autoReconnect && !this.manuallyClosed && !event.wasClean);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Internal close socket - does not reset retry logic
|
|
200
|
+
*/ closeSocket(closeEvent) {
|
|
201
|
+
this.socket && (this.clearKeepAliveTimer(), this.detachEventListeners(), this.socket.readyState !== WebSocket.CLOSED && this.socket.readyState !== WebSocket.CLOSING && this.socket.close(closeEvent.code || 1e3, closeEvent.reason || "Clean shutdown"),
|
|
202
|
+
this.socket = null, this.keepAliveTimer = null);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export { WSConnection as W };
|
|
@@ -2,7 +2,7 @@ import { create } from "zustand";
|
|
|
2
2
|
|
|
3
3
|
import "./tslib.es6-c-7TIv71.mjs";
|
|
4
4
|
|
|
5
|
-
import { SSEConnection } from "
|
|
5
|
+
import { S as SSEConnection } from "./SSEConnection-Dj9P0SWE.mjs";
|
|
6
6
|
|
|
7
7
|
const useSSEStore = create((set, get) => ({
|
|
8
8
|
connections: [],
|
|
@@ -47,7 +47,7 @@ const useSSEStore = create((set, get) => ({
|
|
|
47
47
|
function useMessage(type, connection) {
|
|
48
48
|
return useSSEStore(state => {
|
|
49
49
|
const sourceMessage = connection && !state.connections.some(c => c.name === connection) ? null : state.message;
|
|
50
|
-
return type ? sourceMessage
|
|
50
|
+
return type ? (null == sourceMessage ? void 0 : sourceMessage.type) !== type ? null : "open" === type || "error" === type || "close" === type ? "event" in sourceMessage ? sourceMessage.event : null : "data" in sourceMessage ? sourceMessage.data : null : sourceMessage;
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { a as __awaiter } from "./tslib.es6-c-7TIv71.mjs";
|
|
2
|
+
|
|
3
|
+
import { create } from "zustand";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Form factor names
|
|
7
|
+
*/ var FormFactor;
|
|
8
|
+
|
|
9
|
+
!function(FormFactor) {
|
|
10
|
+
FormFactor.Mobile = "mobile", FormFactor.Tablet = "tablet", FormFactor.Desktop = "desktop",
|
|
11
|
+
FormFactor.DesktopL = "desktopL", FormFactor.DesktopXL = "desktopXL";
|
|
12
|
+
}(FormFactor || (FormFactor = {}));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Use bootstrap breakpoints
|
|
16
|
+
*/
|
|
17
|
+
const bootstrapBreakPoints = {
|
|
18
|
+
[FormFactor.Mobile]: 576,
|
|
19
|
+
[FormFactor.Tablet]: 768,
|
|
20
|
+
[FormFactor.Desktop]: 992,
|
|
21
|
+
[FormFactor.DesktopL]: 1200,
|
|
22
|
+
[FormFactor.DesktopXL]: 1400
|
|
23
|
+
}, orderedBps = Object.entries(bootstrapBreakPoints).sort((a, b) => -b[1] - a[1]), getFormFactor = width => {
|
|
24
|
+
if (!width || width <= 0) return FormFactor.Mobile;
|
|
25
|
+
for (const [formFactor, breakpoint] of orderedBps) if (width >= breakpoint) return formFactor;
|
|
26
|
+
return FormFactor.Mobile;
|
|
27
|
+
}, isBrowser = "undefined" != typeof globalThis && "undefined" != typeof navigator, initialSize = processWindowSize(), useWindowStore = create((set, get) => ({
|
|
28
|
+
formFactor: initialSize.formFactor,
|
|
29
|
+
viewportWidth: initialSize.viewportWidth,
|
|
30
|
+
viewportHeight: initialSize.viewportHeight,
|
|
31
|
+
height: initialSize.height,
|
|
32
|
+
isElectron: checkElectron(),
|
|
33
|
+
isAppleDevice: checkAppleDevice(),
|
|
34
|
+
isTouchDevice: checkTouchDevice(),
|
|
35
|
+
dpr: getDpr(),
|
|
36
|
+
locationError: null,
|
|
37
|
+
location: null,
|
|
38
|
+
gettingLocation: !1,
|
|
39
|
+
actions: {
|
|
40
|
+
initialize: () => {
|
|
41
|
+
if (!isBrowser) return () => {};
|
|
42
|
+
const win = getViewportWindow();
|
|
43
|
+
return null == win || win.addEventListener("resize", handleResize), handleResize(),
|
|
44
|
+
() => null == win ? void 0 : win.removeEventListener("resize", handleResize);
|
|
45
|
+
},
|
|
46
|
+
getLocation: () => __awaiter(void 0, void 0, void 0, function*() {
|
|
47
|
+
if (!isBrowser || !("geolocation" in navigator)) {
|
|
48
|
+
const error = createLocationError("Geolocation is not supported in this browser.", 0);
|
|
49
|
+
throw set({
|
|
50
|
+
locationError: error,
|
|
51
|
+
gettingLocation: !1
|
|
52
|
+
}), error;
|
|
53
|
+
}
|
|
54
|
+
return set({
|
|
55
|
+
gettingLocation: !0,
|
|
56
|
+
locationError: null
|
|
57
|
+
}), yield new Promise((resolve, reject) => {
|
|
58
|
+
navigator.geolocation.getCurrentPosition(position => {
|
|
59
|
+
const location = {
|
|
60
|
+
latitude: position.coords.latitude,
|
|
61
|
+
longitude: position.coords.longitude,
|
|
62
|
+
accuracy: position.coords.accuracy,
|
|
63
|
+
altitude: position.coords.altitude,
|
|
64
|
+
altitudeAccuracy: position.coords.altitudeAccuracy,
|
|
65
|
+
heading: position.coords.heading,
|
|
66
|
+
speed: position.coords.speed,
|
|
67
|
+
timestamp: position.timestamp
|
|
68
|
+
};
|
|
69
|
+
set({
|
|
70
|
+
location: location,
|
|
71
|
+
gettingLocation: !1,
|
|
72
|
+
locationError: null
|
|
73
|
+
}), resolve(location);
|
|
74
|
+
}, err => {
|
|
75
|
+
const error = createLocationError(err.message, err.code);
|
|
76
|
+
set({
|
|
77
|
+
locationError: error,
|
|
78
|
+
gettingLocation: !1,
|
|
79
|
+
location: null
|
|
80
|
+
}), reject(error);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
function checkElectron() {
|
|
88
|
+
if (!isBrowser) return !1;
|
|
89
|
+
return navigator.userAgent.toLowerCase().includes("electron/");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function checkAppleDevice() {
|
|
93
|
+
return !!isBrowser && (navigator.platform.startsWith("Mac") || "iPhone" === navigator.platform);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function checkTouchDevice() {
|
|
97
|
+
return !!isBrowser && ("ontouchstart" in globalThis || navigator.maxTouchPoints > 0);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getDpr() {
|
|
101
|
+
var _a;
|
|
102
|
+
return isBrowser && null !== (_a = Math.min(Math.ceil(window.devicePixelRatio), 3)) && void 0 !== _a ? _a : 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function createLocationError(message, code) {
|
|
106
|
+
return new Error(message, {
|
|
107
|
+
cause: {
|
|
108
|
+
code: code
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function getViewportWindow() {
|
|
114
|
+
var _a;
|
|
115
|
+
return isBrowser ? null !== (_a = window.top) && void 0 !== _a ? _a : globalThis : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function handleResize() {
|
|
119
|
+
if (!isBrowser) return;
|
|
120
|
+
const {formFactor: formFactor, viewportWidth: viewportWidth, viewportHeight: viewportHeight, height: height} = processWindowSize();
|
|
121
|
+
useWindowStore.setState({
|
|
122
|
+
formFactor: formFactor,
|
|
123
|
+
viewportWidth: viewportWidth,
|
|
124
|
+
viewportHeight: viewportHeight,
|
|
125
|
+
height: height
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function processWindowSize(top = !0) {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
if (!isBrowser) return {
|
|
132
|
+
formFactor: FormFactor.Mobile,
|
|
133
|
+
viewportWidth: -1,
|
|
134
|
+
viewportHeight: -1,
|
|
135
|
+
height: "100vh"
|
|
136
|
+
};
|
|
137
|
+
const viewport = top ? getViewportWindow() : globalThis, touch = checkTouchDevice(), windowWidth = null !== (_a = null == viewport ? void 0 : viewport.innerWidth) && void 0 !== _a ? _a : -1, windowHeight = null !== (_b = null == viewport ? void 0 : viewport.innerHeight) && void 0 !== _b ? _b : -1;
|
|
138
|
+
return {
|
|
139
|
+
formFactor: getFormFactor(windowWidth),
|
|
140
|
+
viewportWidth: windowWidth,
|
|
141
|
+
viewportHeight: windowHeight,
|
|
142
|
+
height: viewport && touch ? `${windowHeight}px` : "100vh"
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const useFormFactor = () => useWindowStore(state => state.formFactor), useViewportWidth = () => useWindowStore(state => state.viewportWidth), useViewportHeight = () => useWindowStore(state => state.viewportHeight), useIsAppleDevice = () => useWindowStore(state => state.isAppleDevice), useIsTouchDevice = () => useWindowStore(state => state.isTouchDevice), useIsElectron = () => useWindowStore(state => state.isElectron), useDpr = () => useWindowStore(state => state.dpr), useLocation = () => useWindowStore(state => state.location), useLocationError = () => useWindowStore(state => state.locationError), useGettingLocation = () => useWindowStore(state => state.gettingLocation), useInitializeWindow = () => useWindowStore(state => state.actions.initialize), useGetLocation = () => useWindowStore(state => state.actions.getLocation), formFactor = () => useWindowStore.getState().formFactor, viewportWidth = () => useWindowStore.getState().viewportWidth, viewportHeight = () => useWindowStore.getState().viewportHeight, isAppleDevice = () => useWindowStore.getState().isAppleDevice, isTouchDevice = () => useWindowStore.getState().isTouchDevice, isElectron = () => useWindowStore.getState().isElectron, dpr = () => useWindowStore.getState().dpr, location = () => useWindowStore.getState().location, locationError = () => useWindowStore.getState().locationError, gettingLocation = () => useWindowStore.getState().gettingLocation;
|
|
147
|
+
|
|
148
|
+
export { FormFactor as F, isElectron as a, isTouchDevice as b, locationError as c, dpr as d, useFormFactor as e, formFactor as f, gettingLocation as g, useGetLocation as h, isAppleDevice as i, useGettingLocation as j, useInitializeWindow as k, location as l, useIsAppleDevice as m, useIsElectron as n, useIsTouchDevice as o, useLocation as p, useLocationError as q, useViewportHeight as r, useViewportWidth as s, useWindowStore as t, useDpr as u, viewportHeight as v, viewportWidth as w };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as Button } from "../../chunks/Button-
|
|
1
|
+
export { B as Button } from "../../chunks/Button-kXFJmcKv.mjs";
|
|
2
2
|
|
|
3
3
|
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
4
4
|
|
|
@@ -36,6 +36,6 @@ import "../../hooks/useWindow.mjs";
|
|
|
36
36
|
|
|
37
37
|
import "../../chunks/misc-cg9I7drO.mjs";
|
|
38
38
|
|
|
39
|
-
import "../../chunks/ProgressIndicator-
|
|
39
|
+
import "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
40
40
|
|
|
41
41
|
import "../../chunks/sharedTypes-tn9-uJvb.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FileList } from "../../chunks/FileList-
|
|
1
|
+
export { F as FileList } from "../../chunks/FileList-Bon537-t.mjs";
|
|
2
2
|
|
|
3
3
|
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
4
4
|
|
|
@@ -32,6 +32,6 @@ import "../../chunks/_types-CTmvSEX0.mjs";
|
|
|
32
32
|
|
|
33
33
|
import "../../chunks/style-inject.es-D0BjEaN8.mjs";
|
|
34
34
|
|
|
35
|
-
import "../../chunks/ProgressIndicator-
|
|
35
|
+
import "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
36
36
|
|
|
37
37
|
import "motion/react";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as DoneCheck, P as ProgressIndicator } from "../../chunks/ProgressIndicator-
|
|
1
|
+
export { D as DoneCheck, P as ProgressIndicator } from "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
2
2
|
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
|
|
@@ -22,10 +22,10 @@ import "../../hooks/useObserveTheme.mjs";
|
|
|
22
22
|
|
|
23
23
|
import "../../hooks/useWindow.mjs";
|
|
24
24
|
|
|
25
|
-
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
26
|
-
|
|
27
25
|
import "../../chunks/_types-CTmvSEX0.mjs";
|
|
28
26
|
|
|
27
|
+
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
28
|
+
|
|
29
29
|
import "../../chunks/misc-cg9I7drO.mjs";
|
|
30
30
|
|
|
31
31
|
import "../../chunks/style-inject.es-D0BjEaN8.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { P as PromptInput } from "../../chunks/PromptInput-
|
|
1
|
+
export { P as PromptInput } from "../../chunks/PromptInput-DXFAZspz.mjs";
|
|
2
2
|
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
|
|
@@ -22,7 +22,7 @@ import "../../hooks/useObserveTheme.mjs";
|
|
|
22
22
|
|
|
23
23
|
import "../../hooks/useWindow.mjs";
|
|
24
24
|
|
|
25
|
-
import "../../chunks/Button-
|
|
25
|
+
import "../../chunks/Button-kXFJmcKv.mjs";
|
|
26
26
|
|
|
27
27
|
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
28
28
|
|
|
@@ -38,10 +38,10 @@ import "../../chunks/_types-CTmvSEX0.mjs";
|
|
|
38
38
|
|
|
39
39
|
import "../../chunks/misc-cg9I7drO.mjs";
|
|
40
40
|
|
|
41
|
-
import "../../chunks/ProgressIndicator-
|
|
41
|
+
import "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
42
42
|
|
|
43
43
|
import "../../chunks/sharedTypes-tn9-uJvb.mjs";
|
|
44
44
|
|
|
45
|
-
import "../../chunks/FileList-
|
|
45
|
+
import "../../chunks/FileList-Bon537-t.mjs";
|
|
46
46
|
|
|
47
47
|
import "../../chunks/FileIcon-CC_k5dUW.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as TextArea } from "../../chunks/TextArea-
|
|
1
|
+
export { T as TextArea } from "../../chunks/TextArea-DBmM6aQm.mjs";
|
|
2
2
|
|
|
3
3
|
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ import "react/jsx-runtime";
|
|
|
6
6
|
|
|
7
7
|
import "react";
|
|
8
8
|
|
|
9
|
-
import "../../chunks/Button-
|
|
9
|
+
import "../../chunks/Button-kXFJmcKv.mjs";
|
|
10
10
|
|
|
11
11
|
import "motion/react";
|
|
12
12
|
|
|
@@ -38,6 +38,6 @@ import "../../hooks/useWindow.mjs";
|
|
|
38
38
|
|
|
39
39
|
import "../../chunks/misc-cg9I7drO.mjs";
|
|
40
40
|
|
|
41
|
-
import "../../chunks/ProgressIndicator-
|
|
41
|
+
import "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
42
42
|
|
|
43
43
|
import "../../chunks/sharedTypes-tn9-uJvb.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as TextField } from "../../chunks/TextField-
|
|
1
|
+
export { T as TextField } from "../../chunks/TextField-DyUTMegV.mjs";
|
|
2
2
|
|
|
3
3
|
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
4
4
|
|
|
@@ -26,7 +26,7 @@ import "../../hooks/useObserveTheme.mjs";
|
|
|
26
26
|
|
|
27
27
|
import "../../hooks/useWindow.mjs";
|
|
28
28
|
|
|
29
|
-
import "../../chunks/Button-
|
|
29
|
+
import "../../chunks/Button-kXFJmcKv.mjs";
|
|
30
30
|
|
|
31
31
|
import "../../chunks/Badge-DyICxZP2.mjs";
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ import "../../chunks/_types-CTmvSEX0.mjs";
|
|
|
38
38
|
|
|
39
39
|
import "../../chunks/misc-cg9I7drO.mjs";
|
|
40
40
|
|
|
41
|
-
import "../../chunks/ProgressIndicator-
|
|
41
|
+
import "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
42
42
|
|
|
43
43
|
import "../../chunks/sharedTypes-tn9-uJvb.mjs";
|
|
44
44
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { U as UploadArea, a as allTypes, b as audioTypes, d as documentTypes, i as imageTypes, t as textTypes, v as videoTypes } from "../../chunks/UploadArea-
|
|
1
|
+
export { U as UploadArea, a as allTypes, b as audioTypes, d as documentTypes, i as imageTypes, t as textTypes, v as videoTypes } from "../../chunks/UploadArea-tT5V8q23.mjs";
|
|
2
2
|
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
|
|
@@ -8,9 +8,7 @@ import "../../chunks/misc-cg9I7drO.mjs";
|
|
|
8
8
|
|
|
9
9
|
import "../../chunks/tslib.es6-c-7TIv71.mjs";
|
|
10
10
|
|
|
11
|
-
import "../../chunks/
|
|
12
|
-
|
|
13
|
-
import "../../chunks/FileIcon-CC_k5dUW.mjs";
|
|
11
|
+
import "../../chunks/_types-CTmvSEX0.mjs";
|
|
14
12
|
|
|
15
13
|
import "../../hooks/useTheme.mjs";
|
|
16
14
|
|
|
@@ -30,10 +28,12 @@ import "../../hooks/useObserveTheme.mjs";
|
|
|
30
28
|
|
|
31
29
|
import "../../hooks/useWindow.mjs";
|
|
32
30
|
|
|
33
|
-
import "../../chunks/_types-CTmvSEX0.mjs";
|
|
34
|
-
|
|
35
31
|
import "../../chunks/style-inject.es-D0BjEaN8.mjs";
|
|
36
32
|
|
|
37
|
-
import "../../chunks/ProgressIndicator-
|
|
33
|
+
import "../../chunks/ProgressIndicator-D2eairZl.mjs";
|
|
38
34
|
|
|
39
35
|
import "motion/react";
|
|
36
|
+
|
|
37
|
+
import "../../chunks/FileList-Bon537-t.mjs";
|
|
38
|
+
|
|
39
|
+
import "../../chunks/FileIcon-CC_k5dUW.mjs";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useState, useEffect, useCallback } from "react";
|
|
2
2
|
|
|
3
|
-
var _a, FormFactor;
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Form factor names
|
|
7
|
-
*/
|
|
5
|
+
*/ var FormFactor;
|
|
6
|
+
|
|
7
|
+
!function(FormFactor) {
|
|
8
8
|
FormFactor.Mobile = "mobile", FormFactor.Tablet = "tablet", FormFactor.Desktop = "desktop",
|
|
9
9
|
FormFactor.DesktopL = "desktopL", FormFactor.DesktopXL = "desktopXL";
|
|
10
10
|
}(FormFactor || (FormFactor = {}));
|
|
@@ -18,19 +18,50 @@ const bootstrapBreakPoints = {
|
|
|
18
18
|
[FormFactor.Desktop]: 992,
|
|
19
19
|
[FormFactor.DesktopL]: 1200,
|
|
20
20
|
[FormFactor.DesktopXL]: 1400
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const isElectron = navigator.userAgent.toLowerCase().includes("electron/"), isAppleDevice = navigator.platform.startsWith("Mac") || "iPhone" === navigator.platform, dpr = null !== (_a = Math.min(Math.ceil(window.devicePixelRatio), 3)) && void 0 !== _a ? _a : 1, isTouchDevice = "ontouchstart" in globalThis || navigator.maxTouchPoints > 0, orderedBps = Object.entries(bootstrapBreakPoints).sort((a, b) => -b[1] - a[1]);
|
|
21
|
+
}, isBrowser = "undefined" != typeof window && "undefined" != typeof navigator;
|
|
24
22
|
|
|
25
23
|
function useWindow(breakpoints = bootstrapBreakPoints, top = !0) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
()
|
|
24
|
+
const isElectron = !!isBrowser && navigator.userAgent.toLowerCase().includes("electron/"), isAppleDevice = !!isBrowser && (navigator.platform.startsWith("Mac") || "iPhone" === navigator.platform), isTouchDevice = !!isBrowser && ("ontouchstart" in globalThis || navigator.maxTouchPoints > 0), dpr = isBrowser && null !== (_a = Math.min(Math.ceil(window.devicePixelRatio), 3)) && void 0 !== _a ? _a : 1;
|
|
25
|
+
var _a;
|
|
26
|
+
const [viewportWidth, setViewportWidth] = useState(null), [viewportHeight, setViewportHeight] = useState(null), [height, setHeight] = useState("100vh"), [formFactor, setFormFactor] = useState(FormFactor.Desktop), [location, setLocation] = useState(null), [locationError, setLocationError] = useState(null), [gettingLocation, setGettingLocation] = useState(!1), geolocationSupported = "undefined" != typeof navigator && "geolocation" in navigator;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (isBrowser) return handleResize(), window.addEventListener("resize", handleResize, !1),
|
|
29
|
+
() => window.removeEventListener("resize", handleResize, !1);
|
|
30
|
+
}, []);
|
|
29
31
|
const getFormFactor = useCallback(width => {
|
|
30
32
|
if (!width || width <= 0) return FormFactor.Mobile;
|
|
33
|
+
const orderedBps = Object.entries(breakpoints).sort((a, b) => b[1] - a[1]);
|
|
31
34
|
for (const [formFactor, breakpoint] of orderedBps) if (width >= breakpoint) return formFactor;
|
|
32
35
|
return FormFactor.Mobile;
|
|
33
|
-
}, [])
|
|
36
|
+
}, [ breakpoints ]), requestGeolocation = useCallback(() => {
|
|
37
|
+
if (!geolocationSupported) {
|
|
38
|
+
const error = new Error("Geolocation is not supported in this browser.", {
|
|
39
|
+
cause: {
|
|
40
|
+
code: 0
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return void setLocationError(error);
|
|
44
|
+
}
|
|
45
|
+
setGettingLocation(!0), setLocationError(null), navigator.geolocation.getCurrentPosition(position => {
|
|
46
|
+
setLocation({
|
|
47
|
+
latitude: position.coords.latitude,
|
|
48
|
+
longitude: position.coords.longitude,
|
|
49
|
+
accuracy: position.coords.accuracy,
|
|
50
|
+
altitude: position.coords.altitude,
|
|
51
|
+
altitudeAccuracy: position.coords.altitudeAccuracy,
|
|
52
|
+
heading: position.coords.heading,
|
|
53
|
+
speed: position.coords.speed,
|
|
54
|
+
timestamp: position.timestamp
|
|
55
|
+
}), setGettingLocation(!1);
|
|
56
|
+
}, err => {
|
|
57
|
+
const error = new Error(err.message, {
|
|
58
|
+
cause: {
|
|
59
|
+
code: err.code
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
setLocationError(error), setGettingLocation(!1);
|
|
63
|
+
});
|
|
64
|
+
}, [ geolocationSupported ]);
|
|
34
65
|
function handleResize() {
|
|
35
66
|
var _a, _b, _c, _d;
|
|
36
67
|
const windowWidth = top && null !== (_b = null === (_a = window.top) || void 0 === _a ? void 0 : _a.innerWidth) && void 0 !== _b ? _b : window.innerWidth, windowHeight = top && null !== (_d = null === (_c = window.top) || void 0 === _c ? void 0 : _c.innerHeight) && void 0 !== _d ? _d : window.innerHeight;
|
|
@@ -45,7 +76,12 @@ function useWindow(breakpoints = bootstrapBreakPoints, top = !0) {
|
|
|
45
76
|
isElectron: isElectron,
|
|
46
77
|
isAppleDevice: isAppleDevice,
|
|
47
78
|
formFactor: formFactor,
|
|
48
|
-
dpr: dpr
|
|
79
|
+
dpr: dpr,
|
|
80
|
+
geolocationSupported: geolocationSupported,
|
|
81
|
+
location: location,
|
|
82
|
+
locationError: locationError,
|
|
83
|
+
gettingLocation: gettingLocation,
|
|
84
|
+
requestGeolocation: requestGeolocation
|
|
49
85
|
};
|
|
50
86
|
}
|
|
51
87
|
|
package/dist/esm/index.mjs
CHANGED
|
@@ -58,9 +58,9 @@ export { F as FlexDiv } from "./chunks/FlexDiv-LGEGGrT0.mjs";
|
|
|
58
58
|
|
|
59
59
|
export { P as Pager } from "./chunks/Pager-BX4TMwD_.mjs";
|
|
60
60
|
|
|
61
|
-
export { P as PromptInput } from "./chunks/PromptInput-
|
|
61
|
+
export { P as PromptInput } from "./chunks/PromptInput-DXFAZspz.mjs";
|
|
62
62
|
|
|
63
|
-
export { D as DoneCheck, P as ProgressIndicator } from "./chunks/ProgressIndicator-
|
|
63
|
+
export { D as DoneCheck, P as ProgressIndicator } from "./chunks/ProgressIndicator-D2eairZl.mjs";
|
|
64
64
|
|
|
65
65
|
export { R as RadioButton } from "./chunks/RadioButton-_lo_FJ8g.mjs";
|
|
66
66
|
|
|
@@ -74,9 +74,9 @@ export { S as Switch } from "./chunks/Switch-nWg2Ykea.mjs";
|
|
|
74
74
|
|
|
75
75
|
export { T as TabBar } from "./chunks/TabBar-CDDzA_m1.mjs";
|
|
76
76
|
|
|
77
|
-
export { T as TextArea } from "./chunks/TextArea-
|
|
77
|
+
export { T as TextArea } from "./chunks/TextArea-DBmM6aQm.mjs";
|
|
78
78
|
|
|
79
|
-
export { T as TextField } from "./chunks/TextField-
|
|
79
|
+
export { T as TextField } from "./chunks/TextField-DyUTMegV.mjs";
|
|
80
80
|
|
|
81
81
|
export { ThemeProvider } from "./providers/ThemeProvider.mjs";
|
|
82
82
|
|
|
@@ -84,7 +84,7 @@ export { T as Tip } from "./chunks/Tip-B-cDOFvV.mjs";
|
|
|
84
84
|
|
|
85
85
|
export { T as Toast, a as ToastType } from "./chunks/Toast-ovxR12_-.mjs";
|
|
86
86
|
|
|
87
|
-
export { B as Button } from "./chunks/Button-
|
|
87
|
+
export { B as Button } from "./chunks/Button-kXFJmcKv.mjs";
|
|
88
88
|
|
|
89
89
|
export { C as Chip } from "./chunks/Chip-ByaaWpFx.mjs";
|
|
90
90
|
|
|
@@ -98,7 +98,7 @@ export { C as Card } from "./chunks/Card-DjHdCav5.mjs";
|
|
|
98
98
|
|
|
99
99
|
export { L as Label } from "./chunks/Label-DOvquc82.mjs";
|
|
100
100
|
|
|
101
|
-
export { U as UploadArea, a as allTypes, b as audioTypes, d as documentTypes, i as imageTypes, t as textTypes, v as videoTypes } from "./chunks/UploadArea-
|
|
101
|
+
export { U as UploadArea, a as allTypes, b as audioTypes, d as documentTypes, i as imageTypes, t as textTypes, v as videoTypes } from "./chunks/UploadArea-tT5V8q23.mjs";
|
|
102
102
|
|
|
103
103
|
import "./theme/corners.mjs";
|
|
104
104
|
|
|
@@ -118,4 +118,4 @@ import "motion/react";
|
|
|
118
118
|
|
|
119
119
|
import "./chunks/colors-DR9fLI5X.mjs";
|
|
120
120
|
|
|
121
|
-
import "./chunks/FileList-
|
|
121
|
+
import "./chunks/FileList-Bon537-t.mjs";
|