@graphcommerce/react-hook-form 2.102.1

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.
@@ -0,0 +1,41 @@
1
+ import {
2
+ DocumentNode,
3
+ LazyQueryHookOptions,
4
+ LazyQueryResult,
5
+ QueryLazyOptions,
6
+ TypedDocumentNode,
7
+ useLazyQuery,
8
+ } from '@apollo/client'
9
+ import { useEffect, useRef } from 'react'
10
+ import { Promisable } from 'type-fest'
11
+
12
+ export type LazyQueryTuple<Q, V> = [
13
+ (options?: QueryLazyOptions<V>) => Promisable<LazyQueryResult<Q, V>>,
14
+ LazyQueryResult<Q, V>,
15
+ ]
16
+
17
+ /**
18
+ * Same API as useLazyQuery, except:
19
+ * - The execute method is a promise that will return the eventual result
20
+ */
21
+ export function useLazyQueryPromise<Q, V>(
22
+ query: DocumentNode | TypedDocumentNode<Q, V>,
23
+ options?: LazyQueryHookOptions<Q, V>,
24
+ ): LazyQueryTuple<Q, V> {
25
+ const [execute, result] = useLazyQuery<Q, V>(query, options)
26
+ const ref = useRef<(value: Promisable<LazyQueryResult<Q, V>>) => void>()
27
+
28
+ useEffect(() => {
29
+ if (!result.called || result.loading || !ref.current) return
30
+ ref.current(result)
31
+ ref.current = undefined
32
+ }, [result])
33
+
34
+ const queryLazily = (executeOptions?: QueryLazyOptions<V>) => {
35
+ execute(executeOptions)
36
+ return new Promise<LazyQueryResult<Q, V>>((resolve) => {
37
+ ref.current = resolve
38
+ })
39
+ }
40
+ return [queryLazily, result]
41
+ }
@@ -0,0 +1,4 @@
1
+ export const emailPattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
2
+ export const phonePattern = /^\s*(?:\+?(\d{1,3}))?([-. (]*(\d{3})[-. )]*)?((\d{3})[-. ]*(\d{2,4})(?:[-.x ]*(\d+))?)\s*$/
3
+
4
+ export const houseNumberPattern = /^\d+([-\\/]\d+)*$/
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "exclude": ["**/node_modules", "**/.*/"],
3
+ "include": ["**/*.ts", "**/*.tsx"],
4
+ "extends": "@graphcommerce/typescript-config-pwa/nextjs.json"
5
+ }