@jobber/hooks 2.9.2-CJS-to-ESM.18 → 2.9.2-CJS-to-ESM.24
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/dist/index.cjs +806 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/useAssert/index.cjs +53 -0
- package/dist/useAssert/index.cjs.map +1 -0
- package/dist/useAssert/index.js.map +1 -0
- package/dist/useBool/index.cjs +40 -0
- package/dist/useBool/index.cjs.map +1 -0
- package/dist/useBool/index.js.map +1 -0
- package/dist/useBreakpoints/index.cjs +138 -0
- package/dist/useBreakpoints/index.cjs.map +1 -0
- package/dist/useBreakpoints/index.js.map +1 -0
- package/dist/useCollectionQuery/index.cjs +389 -0
- package/dist/useCollectionQuery/index.cjs.map +1 -0
- package/dist/useCollectionQuery/index.js.map +1 -0
- package/dist/useCollectionQuery/useCollectionQuery.js +1 -2
- package/dist/useFocusTrap/index.cjs +84 -0
- package/dist/useFocusTrap/index.cjs.map +1 -0
- package/dist/useFocusTrap/index.js.map +1 -0
- package/dist/useInView/index.cjs +51 -0
- package/dist/useInView/index.cjs.map +1 -0
- package/dist/useInView/index.js.map +1 -0
- package/dist/useIsMounted/index.cjs +49 -0
- package/dist/useIsMounted/index.cjs.map +1 -0
- package/dist/useIsMounted/index.js.map +1 -0
- package/dist/useLiveAnnounce/index.cjs +64 -0
- package/dist/useLiveAnnounce/index.cjs.map +1 -0
- package/dist/useLiveAnnounce/index.js.map +1 -0
- package/dist/useOnKeyDown/index.cjs +62 -0
- package/dist/useOnKeyDown/index.cjs.map +1 -0
- package/dist/useOnKeyDown/index.js.map +1 -0
- package/dist/usePasswordStrength/index.cjs +62 -0
- package/dist/usePasswordStrength/index.cjs.map +1 -0
- package/dist/usePasswordStrength/index.js.map +1 -0
- package/dist/useRefocusOnActivator/index.cjs +49 -0
- package/dist/useRefocusOnActivator/index.cjs.map +1 -0
- package/dist/useRefocusOnActivator/index.js.map +1 -0
- package/dist/useResizeObserver/index.cjs +84 -0
- package/dist/useResizeObserver/index.cjs.map +1 -0
- package/dist/useResizeObserver/index.js.map +1 -0
- package/dist/useResizeObserver/useResizeObserver.js +1 -2
- package/dist/useSafeLayoutEffect/index.cjs +34 -0
- package/dist/useSafeLayoutEffect/index.cjs.map +1 -0
- package/dist/useSafeLayoutEffect/index.js.map +1 -0
- package/dist/useShowClear/index.cjs +52 -0
- package/dist/useShowClear/index.cjs.map +1 -0
- package/dist/useShowClear/index.js.map +1 -0
- package/package.json +22 -20
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
26
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
27
|
+
};
|
|
28
|
+
var __export = (target, all) => {
|
|
29
|
+
for (var name in all)
|
|
30
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
31
|
+
};
|
|
32
|
+
var __copyProps = (to, from, except, desc) => {
|
|
33
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
34
|
+
for (let key of __getOwnPropNames(from))
|
|
35
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
36
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
37
|
+
}
|
|
38
|
+
return to;
|
|
39
|
+
};
|
|
40
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
41
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
42
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
43
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
44
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
45
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
46
|
+
mod
|
|
47
|
+
));
|
|
48
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
49
|
+
|
|
50
|
+
// ../formatters/dist/global.js
|
|
51
|
+
var require_global = __commonJS({
|
|
52
|
+
"../formatters/dist/global.js"(exports2) {
|
|
53
|
+
"use strict";
|
|
54
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
55
|
+
exports2.global = void 0;
|
|
56
|
+
function getGlobal() {
|
|
57
|
+
if (typeof window !== "undefined") {
|
|
58
|
+
return window;
|
|
59
|
+
}
|
|
60
|
+
return global;
|
|
61
|
+
}
|
|
62
|
+
var glob = getGlobal();
|
|
63
|
+
exports2.global = glob;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// ../formatters/dist/config.js
|
|
68
|
+
var require_config = __commonJS({
|
|
69
|
+
"../formatters/dist/config.js"(exports2) {
|
|
70
|
+
"use strict";
|
|
71
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
72
|
+
exports2.config = void 0;
|
|
73
|
+
var global_1 = require_global();
|
|
74
|
+
var configOverrides = (global_1.global.ATLANTIS_ENV || {}).config || {};
|
|
75
|
+
exports2.config = Object.freeze(Object.assign({ defaultCurrency: "USD", errorNotifier(message, error) {
|
|
76
|
+
console.error(message, error);
|
|
77
|
+
} }, configOverrides));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// ../formatters/dist/currency.js
|
|
82
|
+
var require_currency = __commonJS({
|
|
83
|
+
"../formatters/dist/currency.js"(exports2) {
|
|
84
|
+
"use strict";
|
|
85
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
86
|
+
exports2.formatCurrency = void 0;
|
|
87
|
+
var config_1 = require_config();
|
|
88
|
+
function formatCurrency(amount, currency = config_1.config.defaultCurrency) {
|
|
89
|
+
return amount.toLocaleString("en", {
|
|
90
|
+
style: "currency",
|
|
91
|
+
currency
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports2.formatCurrency = formatCurrency;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ../formatters/dist/CurrencyType.js
|
|
99
|
+
var require_CurrencyType = __commonJS({
|
|
100
|
+
"../formatters/dist/CurrencyType.js"(exports2) {
|
|
101
|
+
"use strict";
|
|
102
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// ../formatters/dist/index.js
|
|
107
|
+
var require_dist = __commonJS({
|
|
108
|
+
"../formatters/dist/index.js"(exports2) {
|
|
109
|
+
"use strict";
|
|
110
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
111
|
+
if (k2 === void 0)
|
|
112
|
+
k2 = k;
|
|
113
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
114
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
115
|
+
desc = { enumerable: true, get: function() {
|
|
116
|
+
return m[k];
|
|
117
|
+
} };
|
|
118
|
+
}
|
|
119
|
+
Object.defineProperty(o, k2, desc);
|
|
120
|
+
} : function(o, m, k, k2) {
|
|
121
|
+
if (k2 === void 0)
|
|
122
|
+
k2 = k;
|
|
123
|
+
o[k2] = m[k];
|
|
124
|
+
});
|
|
125
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
126
|
+
for (var p in m)
|
|
127
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p))
|
|
128
|
+
__createBinding(exports3, m, p);
|
|
129
|
+
};
|
|
130
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
131
|
+
__exportStar(require_currency(), exports2);
|
|
132
|
+
__exportStar(require_CurrencyType(), exports2);
|
|
133
|
+
__exportStar(require_config(), exports2);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// src/index.ts
|
|
138
|
+
var src_exports = {};
|
|
139
|
+
__export(src_exports, {
|
|
140
|
+
BREAKPOINT_SIZES: () => BREAKPOINT_SIZES,
|
|
141
|
+
Breakpoints: () => Breakpoints,
|
|
142
|
+
mockViewportWidth: () => mockViewportWidth,
|
|
143
|
+
useAssert: () => useAssert,
|
|
144
|
+
useBool: () => useBool,
|
|
145
|
+
useBreakpoints: () => useBreakpoints,
|
|
146
|
+
useCollectionQuery: () => useCollectionQuery,
|
|
147
|
+
useFocusTrap: () => useFocusTrap,
|
|
148
|
+
useFormState: () => useFormState,
|
|
149
|
+
useInView: () => useInView,
|
|
150
|
+
useIsMounted: () => useIsMounted,
|
|
151
|
+
useLiveAnnounce: () => useLiveAnnounce,
|
|
152
|
+
useOnKeyDown: () => useOnKeyDown,
|
|
153
|
+
usePasswordStrength: () => usePasswordStrength,
|
|
154
|
+
useRefocusOnActivator: () => useRefocusOnActivator,
|
|
155
|
+
useResizeObserver: () => useResizeObserver,
|
|
156
|
+
useSafeLayoutEffect: () => useSafeLayoutEffect,
|
|
157
|
+
useShowClear: () => useShowClear
|
|
158
|
+
});
|
|
159
|
+
module.exports = __toCommonJS(src_exports);
|
|
160
|
+
|
|
161
|
+
// src/useAssert/useAssert.tsx
|
|
162
|
+
var import_process = __toESM(require("process"), 1);
|
|
163
|
+
function useAssert(shouldShow, message, options) {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
if (((_b = (_a = import_process.default) == null ? void 0 : _a.env) == null ? void 0 : _b.NODE_ENV) !== "production" && shouldShow) {
|
|
166
|
+
if (options == null ? void 0 : options.warn) {
|
|
167
|
+
console.warn(message);
|
|
168
|
+
} else {
|
|
169
|
+
throw new Error(message);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/useBool/useBool.ts
|
|
175
|
+
var import_react = require("react");
|
|
176
|
+
function useBool(initialState = false) {
|
|
177
|
+
const [state, setState] = (0, import_react.useState)(initialState);
|
|
178
|
+
const setTrue = (0, import_react.useCallback)(() => setState(true), []);
|
|
179
|
+
const setFalse = (0, import_react.useCallback)(() => setState(false), []);
|
|
180
|
+
const toggle = (0, import_react.useCallback)(() => setState((current) => !current), []);
|
|
181
|
+
return [state, setTrue, setFalse, toggle];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/useBreakpoints/useMediaQuery.ts
|
|
185
|
+
var import_react2 = require("react");
|
|
186
|
+
function useMediaQuery(CSSMediaQuery) {
|
|
187
|
+
const [matches, setMatches] = (0, import_react2.useState)(
|
|
188
|
+
window.matchMedia(CSSMediaQuery).matches
|
|
189
|
+
);
|
|
190
|
+
(0, import_react2.useEffect)(() => {
|
|
191
|
+
const media = window.matchMedia(CSSMediaQuery);
|
|
192
|
+
if (media.matches !== matches) {
|
|
193
|
+
setMatches(media.matches);
|
|
194
|
+
}
|
|
195
|
+
const listener = () => setMatches(media.matches);
|
|
196
|
+
media.addEventListener("change", listener);
|
|
197
|
+
return () => media.removeEventListener("change", listener);
|
|
198
|
+
}, [CSSMediaQuery]);
|
|
199
|
+
return matches;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/useBreakpoints/useBreakpoints.ts
|
|
203
|
+
var BREAKPOINT_SIZES = { sm: 490, md: 768, lg: 1080, xl: 1440 };
|
|
204
|
+
function useBreakpoints() {
|
|
205
|
+
const { sm, md, lg, xl } = BREAKPOINT_SIZES;
|
|
206
|
+
const extraSmallOnly = useMediaQuery(`(max-width: ${sm - 1}px)`);
|
|
207
|
+
const smallAndUp = useMediaQuery(`(min-width: ${sm}px)`);
|
|
208
|
+
const mediumAndUp = useMediaQuery(`(min-width: ${md}px)`);
|
|
209
|
+
const largeAndUp = useMediaQuery(`(min-width: ${lg}px)`);
|
|
210
|
+
const extraLargeAndUp = useMediaQuery(`(min-width: ${xl}px)`);
|
|
211
|
+
return {
|
|
212
|
+
smallAndUp,
|
|
213
|
+
mediumAndUp,
|
|
214
|
+
largeAndUp,
|
|
215
|
+
extraLargeAndUp,
|
|
216
|
+
extraSmallOnly,
|
|
217
|
+
smallOnly: smallAndUp && !mediumAndUp,
|
|
218
|
+
mediumOnly: mediumAndUp && !largeAndUp,
|
|
219
|
+
largeOnly: largeAndUp && !extraLargeAndUp
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/useBreakpoints/mockViewportWidth/mockViewportWidth.ts
|
|
224
|
+
var defaultMatchMedia = window.matchMedia;
|
|
225
|
+
var defaultResizeTo = window.resizeTo;
|
|
226
|
+
var defaultInnerWidth = window.innerWidth;
|
|
227
|
+
function mockViewportWidth() {
|
|
228
|
+
return { cleanup, setViewportWidth };
|
|
229
|
+
}
|
|
230
|
+
function setViewportWidth(newWidth) {
|
|
231
|
+
Object.defineProperty(window, "matchMedia", {
|
|
232
|
+
writable: true,
|
|
233
|
+
value: jest.fn().mockImplementation((query) => {
|
|
234
|
+
const matches = isQueryMatching(query);
|
|
235
|
+
const instance = {
|
|
236
|
+
matches,
|
|
237
|
+
media: query,
|
|
238
|
+
onchange: null,
|
|
239
|
+
addListener: jest.fn(),
|
|
240
|
+
// Deprecated but some packages use it
|
|
241
|
+
removeListener: jest.fn(),
|
|
242
|
+
// Deprecated but some packages use it
|
|
243
|
+
addEventListener: jest.fn(),
|
|
244
|
+
removeEventListener: jest.fn(),
|
|
245
|
+
dispatchEvent: jest.fn()
|
|
246
|
+
};
|
|
247
|
+
window.addEventListener("resize", () => {
|
|
248
|
+
if (matches != instance.matches) {
|
|
249
|
+
instance.matches = matches;
|
|
250
|
+
instance.dispatchEvent("change");
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return instance;
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
Object.defineProperty(window, "resizeTo", {
|
|
257
|
+
value: (width) => {
|
|
258
|
+
Object.defineProperty(window, "innerWidth", {
|
|
259
|
+
configurable: true,
|
|
260
|
+
writable: true,
|
|
261
|
+
value: width
|
|
262
|
+
});
|
|
263
|
+
window.dispatchEvent(new Event("resize"));
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
window.resizeTo(newWidth, window.innerHeight);
|
|
267
|
+
}
|
|
268
|
+
function cleanup() {
|
|
269
|
+
window.matchMedia = defaultMatchMedia;
|
|
270
|
+
window.resizeTo = defaultResizeTo;
|
|
271
|
+
window.innerWidth = defaultInnerWidth;
|
|
272
|
+
}
|
|
273
|
+
function isQueryMatching(query) {
|
|
274
|
+
const match = query.match(/(min-width|max-width):\s*(\d+)/);
|
|
275
|
+
if (!match)
|
|
276
|
+
return false;
|
|
277
|
+
const { innerWidth } = window;
|
|
278
|
+
const [, operator, value] = match;
|
|
279
|
+
const breakpoint = parseInt(value, 10);
|
|
280
|
+
switch (operator) {
|
|
281
|
+
case "max-width":
|
|
282
|
+
return innerWidth <= breakpoint;
|
|
283
|
+
case "min-width":
|
|
284
|
+
return innerWidth >= breakpoint;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/useCollectionQuery/useCollectionQuery.ts
|
|
289
|
+
var import_client = require("@apollo/client");
|
|
290
|
+
var import_lodash = require("lodash");
|
|
291
|
+
var import_react5 = require("react");
|
|
292
|
+
var import_formatters = __toESM(require_dist(), 1);
|
|
293
|
+
|
|
294
|
+
// src/useCollectionQuery/uniqueNodes.tsx
|
|
295
|
+
function uniqueNodes(nodes) {
|
|
296
|
+
const result = /* @__PURE__ */ new Map();
|
|
297
|
+
nodes.forEach((node) => {
|
|
298
|
+
result.set(`${node.__typename}-${node.id}`, node);
|
|
299
|
+
});
|
|
300
|
+
return Array.from(result.values());
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/useCollectionQuery/uniqueEdges.tsx
|
|
304
|
+
function createEdge(node) {
|
|
305
|
+
return {
|
|
306
|
+
node,
|
|
307
|
+
cursor: "",
|
|
308
|
+
__typename: `${node.__typename}Edge`
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function uniqueEdges(edges) {
|
|
312
|
+
const result = /* @__PURE__ */ new Map();
|
|
313
|
+
edges.forEach((edge) => {
|
|
314
|
+
result.set(
|
|
315
|
+
`${edge.__typename}-${edge.node.__typename}-${edge.node.id}`,
|
|
316
|
+
edge
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
return Array.from(result.values());
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/useIsMounted/useIsMounted.ts
|
|
323
|
+
var import_react4 = require("react");
|
|
324
|
+
|
|
325
|
+
// src/useSafeLayoutEffect/useSafeLayoutEffect.ts
|
|
326
|
+
var import_react3 = require("react");
|
|
327
|
+
var useSafeLayoutEffect = (globalThis == null ? void 0 : globalThis.document) ? import_react3.useLayoutEffect : import_react3.useEffect;
|
|
328
|
+
|
|
329
|
+
// src/useIsMounted/useIsMounted.ts
|
|
330
|
+
function useIsMounted() {
|
|
331
|
+
const isMounted = (0, import_react4.useRef)(false);
|
|
332
|
+
useSafeLayoutEffect(() => {
|
|
333
|
+
isMounted.current = true;
|
|
334
|
+
return () => {
|
|
335
|
+
isMounted.current = false;
|
|
336
|
+
};
|
|
337
|
+
}, []);
|
|
338
|
+
return isMounted;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/useCollectionQuery/useCollectionQuery.ts
|
|
342
|
+
function useCollectionQuery({
|
|
343
|
+
query,
|
|
344
|
+
queryOptions,
|
|
345
|
+
getCollectionByPath,
|
|
346
|
+
subscription
|
|
347
|
+
}) {
|
|
348
|
+
var _a, _b;
|
|
349
|
+
const { data, loading, refetch, error, fetchMore, subscribeToMore } = (0, import_client.useQuery)(query, queryOptions);
|
|
350
|
+
const isMounted = useIsMounted();
|
|
351
|
+
const [loadingRefresh, setLoadingRefresh] = (0, import_react5.useState)(false);
|
|
352
|
+
const [loadingNextPage, setLoadingNextPage] = (0, import_react5.useState)(false);
|
|
353
|
+
const [hookError, setHookError] = (0, import_react5.useState)();
|
|
354
|
+
const loadingInitialContent = loading && !loadingRefresh && !loadingNextPage;
|
|
355
|
+
const isSearching = !!((_a = queryOptions == null ? void 0 : queryOptions.variables) == null ? void 0 : _a.searchTerm);
|
|
356
|
+
const refresh = (0, import_react5.useCallback)(() => {
|
|
357
|
+
if (loadingInitialContent || loadingRefresh) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
setLoadingRefresh(true);
|
|
361
|
+
fetchMore({
|
|
362
|
+
// a workaround fix for the error described in this post
|
|
363
|
+
// https://github.com/apollographql/apollo-client/issues/7491#issuecomment-767985363
|
|
364
|
+
// These changes can be reverted once we can update to version 3.4
|
|
365
|
+
// (the current release candidate)
|
|
366
|
+
variables: {},
|
|
367
|
+
updateQuery: (prev, { fetchMoreResult }) => fetchMoreResult || prev
|
|
368
|
+
}).catch((err) => import_formatters.config.errorNotifier("Refetch Error", err)).finally(() => {
|
|
369
|
+
if (isMounted.current) {
|
|
370
|
+
setLoadingRefresh(false);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}, [
|
|
374
|
+
loadingInitialContent,
|
|
375
|
+
loadingRefresh,
|
|
376
|
+
setLoadingRefresh,
|
|
377
|
+
refetch,
|
|
378
|
+
isMounted
|
|
379
|
+
]);
|
|
380
|
+
const nextPage = (0, import_react5.useCallback)(() => {
|
|
381
|
+
var _a2;
|
|
382
|
+
if (loadingInitialContent || loadingRefresh || loadingNextPage) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const pageInfo = (_a2 = getCollectionByPath(data)) == null ? void 0 : _a2.pageInfo;
|
|
386
|
+
if (!pageInfo || !pageInfo.hasNextPage) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
setLoadingNextPage(true);
|
|
390
|
+
setHookError(void 0);
|
|
391
|
+
fetchMore({
|
|
392
|
+
variables: {
|
|
393
|
+
cursor: pageInfo.endCursor
|
|
394
|
+
},
|
|
395
|
+
updateQuery: (prev, { fetchMoreResult }) => fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath)
|
|
396
|
+
}).catch((err) => {
|
|
397
|
+
import_formatters.config.errorNotifier("FetchMore Error", err);
|
|
398
|
+
setHookError(err);
|
|
399
|
+
}).finally(() => {
|
|
400
|
+
if (isMounted.current) {
|
|
401
|
+
setLoadingNextPage(false);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}, [
|
|
405
|
+
data,
|
|
406
|
+
loadingInitialContent,
|
|
407
|
+
loadingRefresh,
|
|
408
|
+
fetchMore,
|
|
409
|
+
loadingNextPage,
|
|
410
|
+
setLoadingNextPage,
|
|
411
|
+
getCollectionByPath,
|
|
412
|
+
isMounted
|
|
413
|
+
]);
|
|
414
|
+
(0, import_react5.useEffect)(
|
|
415
|
+
() => {
|
|
416
|
+
if (subscription == void 0)
|
|
417
|
+
return;
|
|
418
|
+
const subscriptionOptions = subscription.options || {};
|
|
419
|
+
setHookError(void 0);
|
|
420
|
+
return subscribeToMore(__spreadProps(__spreadValues({}, subscriptionOptions), {
|
|
421
|
+
document: subscription.document,
|
|
422
|
+
updateQuery: (prev, { subscriptionData }) => subscribeToMoreHandler(
|
|
423
|
+
isSearching,
|
|
424
|
+
prev,
|
|
425
|
+
getCollectionByPath,
|
|
426
|
+
subscriptionData == null ? void 0 : subscriptionData.data,
|
|
427
|
+
subscription.getNodeByPath
|
|
428
|
+
),
|
|
429
|
+
onError: (err) => {
|
|
430
|
+
import_formatters.config.errorNotifier("Subscribe to More Error", err);
|
|
431
|
+
setHookError(err);
|
|
432
|
+
}
|
|
433
|
+
}));
|
|
434
|
+
},
|
|
435
|
+
// Disabling this linter so we can force this only run once. If we didn't
|
|
436
|
+
// do this we would need to ensure subscription, subscribeToMore, and getNodeByPath
|
|
437
|
+
// all use useCallback.
|
|
438
|
+
[(_b = queryOptions == null ? void 0 : queryOptions.variables) == null ? void 0 : _b.searchTerm]
|
|
439
|
+
);
|
|
440
|
+
const combinedError = error || hookError;
|
|
441
|
+
return {
|
|
442
|
+
data,
|
|
443
|
+
error: combinedError,
|
|
444
|
+
refresh,
|
|
445
|
+
loadingRefresh,
|
|
446
|
+
nextPage,
|
|
447
|
+
loadingNextPage,
|
|
448
|
+
loadingInitialContent
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath) {
|
|
452
|
+
const nextCollection = getCollectionByPath(fetchMoreResult);
|
|
453
|
+
const output = (0, import_lodash.cloneDeep)(prev);
|
|
454
|
+
const outputCollection = getCollectionByPath(output);
|
|
455
|
+
if (outputCollection === void 0 || nextCollection === void 0) {
|
|
456
|
+
return output;
|
|
457
|
+
}
|
|
458
|
+
if (outputCollection.nodes && nextCollection.nodes) {
|
|
459
|
+
outputCollection.nodes = getUpdatedNodes(
|
|
460
|
+
outputCollection.nodes,
|
|
461
|
+
nextCollection.nodes
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
if (outputCollection.edges && nextCollection.edges) {
|
|
465
|
+
outputCollection.edges = getUpdatedEdges(
|
|
466
|
+
outputCollection.edges,
|
|
467
|
+
nextCollection.edges
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
Object.assign(outputCollection, __spreadValues({
|
|
471
|
+
pageInfo: (0, import_lodash.cloneDeep)(nextCollection.pageInfo)
|
|
472
|
+
}, getTotalCount(nextCollection.totalCount)));
|
|
473
|
+
return output;
|
|
474
|
+
}
|
|
475
|
+
function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscriptionData, getNodeByPath) {
|
|
476
|
+
const node = getNodeByPath(subscriptionData);
|
|
477
|
+
const output = (0, import_lodash.cloneDeep)(prev);
|
|
478
|
+
const outputCollection = getCollectionByPath(output);
|
|
479
|
+
if (outputCollection == void 0 || node == void 0)
|
|
480
|
+
return output;
|
|
481
|
+
if (isAlreadyUpdated(outputCollection, node) || isSearching) {
|
|
482
|
+
return prev;
|
|
483
|
+
}
|
|
484
|
+
if (outputCollection.nodes) {
|
|
485
|
+
outputCollection.nodes = getUpdatedNodes(
|
|
486
|
+
outputCollection.nodes,
|
|
487
|
+
[node],
|
|
488
|
+
false
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
if (outputCollection.edges) {
|
|
492
|
+
outputCollection.edges = getUpdatedEdges(
|
|
493
|
+
outputCollection.edges,
|
|
494
|
+
[createEdge(node)],
|
|
495
|
+
false
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
Object.assign(outputCollection, __spreadValues({
|
|
499
|
+
pageInfo: (0, import_lodash.cloneDeep)(outputCollection.pageInfo)
|
|
500
|
+
}, getTotalCount(outputCollection.totalCount, 1)));
|
|
501
|
+
return output;
|
|
502
|
+
}
|
|
503
|
+
function getTotalCount(totalCount, additionalCount = 0) {
|
|
504
|
+
return totalCount !== void 0 ? { totalCount: totalCount + additionalCount } : {};
|
|
505
|
+
}
|
|
506
|
+
function isAlreadyUpdated(outputCollection, newNode) {
|
|
507
|
+
let edgesAlreadyUpdated = true;
|
|
508
|
+
let nodesAlreadyUpdated = true;
|
|
509
|
+
if (outputCollection.edges) {
|
|
510
|
+
edgesAlreadyUpdated = outputCollection.edges.some((edge) => {
|
|
511
|
+
return edge.node.id === newNode.id;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
if (outputCollection.nodes) {
|
|
515
|
+
nodesAlreadyUpdated = outputCollection.nodes.some((node) => {
|
|
516
|
+
return node.id === newNode.id;
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
return edgesAlreadyUpdated && nodesAlreadyUpdated;
|
|
520
|
+
}
|
|
521
|
+
function getUpdatedEdges(prevEdges, nextEdges, appendToEnd = true) {
|
|
522
|
+
const newEdges = appendToEnd ? [...prevEdges, ...nextEdges] : [...nextEdges, ...prevEdges];
|
|
523
|
+
return uniqueEdges(newEdges);
|
|
524
|
+
}
|
|
525
|
+
function getUpdatedNodes(prevNodes, nextNodes, appendToEnd = true) {
|
|
526
|
+
const newNodes = appendToEnd ? [...prevNodes, ...nextNodes] : [...nextNodes, ...prevNodes];
|
|
527
|
+
return uniqueNodes(newNodes);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// src/useFocusTrap/useFocusTrap.ts
|
|
531
|
+
var import_react6 = require("react");
|
|
532
|
+
function useFocusTrap(active) {
|
|
533
|
+
const ref = (0, import_react6.useRef)(null);
|
|
534
|
+
function handleKeyDown(event) {
|
|
535
|
+
if (!(active && ref.current) || event.key !== "Tab") {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const { firstElement, lastElement } = getElements(ref.current);
|
|
539
|
+
if (event.shiftKey) {
|
|
540
|
+
if (document.activeElement === firstElement) {
|
|
541
|
+
lastElement.focus();
|
|
542
|
+
event.preventDefault();
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
if (document.activeElement === lastElement) {
|
|
546
|
+
firstElement.focus();
|
|
547
|
+
event.preventDefault();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
(0, import_react6.useEffect)(() => {
|
|
552
|
+
if (active && ref.current) {
|
|
553
|
+
const { firstElement } = getElements(ref.current);
|
|
554
|
+
firstElement.focus();
|
|
555
|
+
ref.current.addEventListener("keydown", handleKeyDown);
|
|
556
|
+
}
|
|
557
|
+
return () => {
|
|
558
|
+
var _a;
|
|
559
|
+
(_a = ref.current) == null ? void 0 : _a.removeEventListener("keydown", handleKeyDown);
|
|
560
|
+
};
|
|
561
|
+
}, [active]);
|
|
562
|
+
return ref;
|
|
563
|
+
}
|
|
564
|
+
function getElements(ref) {
|
|
565
|
+
const focusables = [
|
|
566
|
+
"button",
|
|
567
|
+
"[href]",
|
|
568
|
+
"input",
|
|
569
|
+
"select",
|
|
570
|
+
"textarea",
|
|
571
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
572
|
+
];
|
|
573
|
+
const elements = [
|
|
574
|
+
...ref.querySelectorAll(focusables.join(", "))
|
|
575
|
+
];
|
|
576
|
+
if (ref.getAttribute("tabindex") === "0") {
|
|
577
|
+
elements.unshift(ref);
|
|
578
|
+
}
|
|
579
|
+
const firstElement = elements[0];
|
|
580
|
+
const lastElement = elements[elements.length - 1];
|
|
581
|
+
return { firstElement, lastElement };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/useFormState/useFormState.ts
|
|
585
|
+
var import_react7 = require("react");
|
|
586
|
+
function useFormState() {
|
|
587
|
+
const [formState, setFormState] = (0, import_react7.useState)({
|
|
588
|
+
isDirty: false,
|
|
589
|
+
isValid: false
|
|
590
|
+
});
|
|
591
|
+
return [formState, setFormState];
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/useInView/useInView.ts
|
|
595
|
+
var import_react8 = require("react");
|
|
596
|
+
function useInView() {
|
|
597
|
+
const ref = (0, import_react8.useRef)(null);
|
|
598
|
+
const [isInView, setIsInView] = (0, import_react8.useState)(false);
|
|
599
|
+
const handleIntersection = (0, import_react8.useCallback)(
|
|
600
|
+
(entries) => setIsInView(entries[0].isIntersecting),
|
|
601
|
+
[setIsInView]
|
|
602
|
+
);
|
|
603
|
+
(0, import_react8.useEffect)(() => {
|
|
604
|
+
if (!window.IntersectionObserver)
|
|
605
|
+
return;
|
|
606
|
+
const observer = new IntersectionObserver(handleIntersection);
|
|
607
|
+
ref.current && observer.observe(ref.current);
|
|
608
|
+
return () => {
|
|
609
|
+
ref.current && observer.unobserve(ref.current);
|
|
610
|
+
};
|
|
611
|
+
}, [handleIntersection, ref.current]);
|
|
612
|
+
return [ref, isInView];
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/useLiveAnnounce/useLiveAnnounce.tsx
|
|
616
|
+
var import_react9 = require("react");
|
|
617
|
+
function useLiveAnnounce() {
|
|
618
|
+
const [announcedMessage, setAnnouncedMessage] = (0, import_react9.useState)("");
|
|
619
|
+
(0, import_react9.useEffect)(() => {
|
|
620
|
+
let target;
|
|
621
|
+
if (announcedMessage) {
|
|
622
|
+
target = createAnnouncedElement();
|
|
623
|
+
setTimeout(() => target.append(announcedMessage), 100);
|
|
624
|
+
}
|
|
625
|
+
return () => target == null ? void 0 : target.remove();
|
|
626
|
+
}, [announcedMessage]);
|
|
627
|
+
return {
|
|
628
|
+
liveAnnounce: (message) => {
|
|
629
|
+
setAnnouncedMessage(message);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function createAnnouncedElement() {
|
|
634
|
+
const el = document.createElement("div");
|
|
635
|
+
el.style.position = "absolute";
|
|
636
|
+
el.style.width = "1px";
|
|
637
|
+
el.style.height = "1px";
|
|
638
|
+
el.style.overflow = "hidden";
|
|
639
|
+
el.style.clipPath = " inset(100%)";
|
|
640
|
+
el.style.whiteSpace = " nowrap";
|
|
641
|
+
el.style.top = "0";
|
|
642
|
+
el.setAttribute("role", "status");
|
|
643
|
+
el.setAttribute("aria-atomic", "true");
|
|
644
|
+
el.setAttribute("aria-live", "assertive");
|
|
645
|
+
document.body.appendChild(el);
|
|
646
|
+
return el;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/useOnKeyDown/useOnKeyDown.ts
|
|
650
|
+
var import_react10 = require("react");
|
|
651
|
+
function useOnKeyDown(callback, keys) {
|
|
652
|
+
(0, import_react10.useEffect)(() => {
|
|
653
|
+
window.addEventListener("keydown", handler);
|
|
654
|
+
return () => {
|
|
655
|
+
window.removeEventListener("keydown", handler);
|
|
656
|
+
};
|
|
657
|
+
}, [handler]);
|
|
658
|
+
function handler(event) {
|
|
659
|
+
const keyboardEvent = event;
|
|
660
|
+
if (typeof keys === "string" && keyboardEvent.key === keys) {
|
|
661
|
+
callback(event);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (Array.isArray(keys) && keys.some((item) => {
|
|
665
|
+
if (typeof item === "string")
|
|
666
|
+
return keyboardEvent.key === item;
|
|
667
|
+
return Object.keys(item).every(
|
|
668
|
+
(index) => keyboardEvent[index] === item[index]
|
|
669
|
+
);
|
|
670
|
+
})) {
|
|
671
|
+
callback(event);
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
if (!Array.isArray(keys) && typeof keys !== "string" && Object.keys(keys).every((index) => keyboardEvent[index] === keys[index])) {
|
|
675
|
+
callback(event);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/usePasswordStrength/usePasswordStrength.ts
|
|
682
|
+
var import_react11 = require("react");
|
|
683
|
+
var import_zxcvbn = __toESM(require("zxcvbn"), 1);
|
|
684
|
+
function usePasswordStrength(password, dictionary) {
|
|
685
|
+
const {
|
|
686
|
+
guesses,
|
|
687
|
+
score,
|
|
688
|
+
feedback: { warning, suggestions },
|
|
689
|
+
crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack }
|
|
690
|
+
} = (0, import_react11.useMemo)(
|
|
691
|
+
() => (0, import_zxcvbn.default)(password, dictionary),
|
|
692
|
+
[password, dictionary]
|
|
693
|
+
);
|
|
694
|
+
return {
|
|
695
|
+
guesses,
|
|
696
|
+
score,
|
|
697
|
+
warning,
|
|
698
|
+
suggestions,
|
|
699
|
+
timeToCrack
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// src/useRefocusOnActivator/useRefocusOnActivator.ts
|
|
704
|
+
var import_react12 = require("react");
|
|
705
|
+
function useRefocusOnActivator(active) {
|
|
706
|
+
(0, import_react12.useEffect)(() => {
|
|
707
|
+
let activator;
|
|
708
|
+
if (active && !activator) {
|
|
709
|
+
activator = document.activeElement;
|
|
710
|
+
}
|
|
711
|
+
return () => {
|
|
712
|
+
if (active) {
|
|
713
|
+
if (activator instanceof HTMLElement) {
|
|
714
|
+
activator.focus();
|
|
715
|
+
}
|
|
716
|
+
activator = void 0;
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
}, [active]);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/useResizeObserver/useResizeObserver.ts
|
|
723
|
+
var import_react13 = require("react");
|
|
724
|
+
var import_polyfilled = __toESM(require("use-resize-observer/polyfilled"), 1);
|
|
725
|
+
var import_lodash2 = require("lodash");
|
|
726
|
+
var Breakpoints = {
|
|
727
|
+
base: 640,
|
|
728
|
+
small: 500,
|
|
729
|
+
smaller: 265,
|
|
730
|
+
large: 750,
|
|
731
|
+
larger: 1024
|
|
732
|
+
};
|
|
733
|
+
var wait = 100;
|
|
734
|
+
function useResizeObserver({
|
|
735
|
+
widths = Breakpoints,
|
|
736
|
+
heights = Breakpoints
|
|
737
|
+
} = {}) {
|
|
738
|
+
const [exactSize, setSize] = (0, import_react13.useState)({
|
|
739
|
+
width: void 0,
|
|
740
|
+
height: void 0
|
|
741
|
+
});
|
|
742
|
+
const onResize = (0, import_react13.useMemo)(() => (0, import_lodash2.throttle)(setSize, wait), [wait]);
|
|
743
|
+
const { ref } = (0, import_polyfilled.default)({
|
|
744
|
+
onResize
|
|
745
|
+
});
|
|
746
|
+
const exactWidth = exactSize.width;
|
|
747
|
+
const exactHeight = exactSize.height;
|
|
748
|
+
const sizes = {
|
|
749
|
+
width: getSize(widths, exactSize.width),
|
|
750
|
+
height: getSize(heights, exactSize.height),
|
|
751
|
+
exactWidth,
|
|
752
|
+
exactHeight
|
|
753
|
+
};
|
|
754
|
+
return [ref, sizes];
|
|
755
|
+
}
|
|
756
|
+
function getSize(sizes, comparable) {
|
|
757
|
+
if (!comparable || !sizes) {
|
|
758
|
+
return void 0;
|
|
759
|
+
}
|
|
760
|
+
const sortedSizes = Object.values(sizes).sort((a, b) => a - b).reverse();
|
|
761
|
+
return sortedSizes.find((value) => value <= comparable) || sortedSizes[sortedSizes.length - 1];
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/useShowClear/useShowClear.ts
|
|
765
|
+
function useShowClear({
|
|
766
|
+
clearable,
|
|
767
|
+
multiline,
|
|
768
|
+
focused,
|
|
769
|
+
hasValue,
|
|
770
|
+
disabled = false
|
|
771
|
+
}) {
|
|
772
|
+
if (multiline && clearable !== "never") {
|
|
773
|
+
throw new Error("Multiline inputs can not be clearable");
|
|
774
|
+
}
|
|
775
|
+
if (!hasValue || clearable === "never" || disabled) {
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
switch (clearable) {
|
|
779
|
+
case "while-editing":
|
|
780
|
+
return focused;
|
|
781
|
+
case "always":
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
786
|
+
0 && (module.exports = {
|
|
787
|
+
BREAKPOINT_SIZES,
|
|
788
|
+
Breakpoints,
|
|
789
|
+
mockViewportWidth,
|
|
790
|
+
useAssert,
|
|
791
|
+
useBool,
|
|
792
|
+
useBreakpoints,
|
|
793
|
+
useCollectionQuery,
|
|
794
|
+
useFocusTrap,
|
|
795
|
+
useFormState,
|
|
796
|
+
useInView,
|
|
797
|
+
useIsMounted,
|
|
798
|
+
useLiveAnnounce,
|
|
799
|
+
useOnKeyDown,
|
|
800
|
+
usePasswordStrength,
|
|
801
|
+
useRefocusOnActivator,
|
|
802
|
+
useResizeObserver,
|
|
803
|
+
useSafeLayoutEffect,
|
|
804
|
+
useShowClear
|
|
805
|
+
});
|
|
806
|
+
//# sourceMappingURL=index.cjs.map
|