@kirill.konshin/utils 0.0.19 → 0.0.20
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/.ctirc +19 -10
- package/.storybook/main.ts +1 -20
- package/.storybook/preview.ts +1 -16
- package/.turbo/turbo-build.log +9 -66
- package/CHANGELOG.md +21 -0
- package/README.md +6 -0
- package/dist/bootstrap/index.d.ts +1 -12
- package/dist/bootstrap/index.d.ts.map +1 -1
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -9
- package/dist/core/index.d.ts.map +1 -1
- package/dist/electron/index.d.ts +1 -2
- package/dist/electron/index.d.ts.map +1 -1
- package/dist/electron-builder/index.d.ts +1 -2
- package/dist/electron-builder/index.d.ts.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/mui/index.d.ts +1 -4
- package/dist/mui/index.d.ts.map +1 -1
- package/dist/next/index.d.ts +1 -5
- package/dist/next/index.d.ts.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/react/index.d.ts +1 -5
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react-native/index.d.ts +1 -3
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/tailwind/index.d.ts +1 -2
- package/dist/tailwind/index.d.ts.map +1 -1
- package/dist/worker/index.d.ts +2 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/package.json +41 -99
- package/src/bootstrap/index.ts +2 -12
- package/src/browser/index.ts +2 -0
- package/src/core/index.ts +2 -9
- package/src/electron/index.ts +2 -2
- package/src/electron-builder/index.ts +2 -2
- package/src/index.ts +12 -0
- package/src/mui/index.ts +2 -4
- package/src/next/index.ts +2 -5
- package/src/node/index.ts +2 -0
- package/src/react/index.ts +2 -5
- package/src/react-native/index.ts +2 -3
- package/src/tailwind/index.ts +2 -2
- package/src/worker/index.ts +2 -0
- package/tsconfig.json +2 -15
- package/vite.config.ts +2 -56
- package/.turbo/turbo-test.log +0 -171
- package/builders/.swcrc +0 -18
- package/builders/build.config.ts +0 -11
- package/builders/bun.build.js +0 -23
- package/builders/package.json +0 -209
- package/builders/perf.mjs +0 -63
- package/builders/rollup.config.mjs +0 -50
- package/builders/rslib.config.ts +0 -26
- package/builders/tsconfig.json +0 -21
- package/builders/tsup.config.ts +0 -20
- package/builders/turbo.json +0 -24
- package/builders/vite.config.ts +0 -37
- package/demo/worker-demo.ts +0 -73
- package/dist/bootstrap/adaptiveContainer.d.ts +0 -4
- package/dist/bootstrap/adaptiveContainer.d.ts.map +0 -1
- package/dist/bootstrap/adaptiveContainer.js +0 -11
- package/dist/bootstrap/adaptiveContainer.js.map +0 -1
- package/dist/bootstrap/controls.d.ts +0 -38
- package/dist/bootstrap/controls.d.ts.map +0 -1
- package/dist/bootstrap/controls.js +0 -78
- package/dist/bootstrap/controls.js.map +0 -1
- package/dist/bootstrap/controls.stories.d.ts +0 -9
- package/dist/bootstrap/controls.stories.d.ts.map +0 -1
- package/dist/bootstrap/error.d.ts +0 -9
- package/dist/bootstrap/error.d.ts.map +0 -1
- package/dist/bootstrap/error.js +0 -27
- package/dist/bootstrap/error.js.map +0 -1
- package/dist/bootstrap/error.stories.d.ts +0 -8
- package/dist/bootstrap/error.stories.d.ts.map +0 -1
- package/dist/bootstrap/field.d.ts +0 -11
- package/dist/bootstrap/field.d.ts.map +0 -1
- package/dist/bootstrap/field.js +0 -29
- package/dist/bootstrap/field.js.map +0 -1
- package/dist/bootstrap/field.stories.d.ts +0 -8
- package/dist/bootstrap/field.stories.d.ts.map +0 -1
- package/dist/bootstrap/footer.d.ts +0 -10
- package/dist/bootstrap/footer.d.ts.map +0 -1
- package/dist/bootstrap/footer.js +0 -45
- package/dist/bootstrap/footer.js.map +0 -1
- package/dist/bootstrap/globalLoading.d.ts +0 -6
- package/dist/bootstrap/globalLoading.d.ts.map +0 -1
- package/dist/bootstrap/globalLoading.js +0 -10
- package/dist/bootstrap/globalLoading.js.map +0 -1
- package/dist/bootstrap/globalLoading.stories.d.ts +0 -7
- package/dist/bootstrap/globalLoading.stories.d.ts.map +0 -1
- package/dist/bootstrap/index.js +0 -35
- package/dist/bootstrap/loading.d.ts +0 -10
- package/dist/bootstrap/loading.d.ts.map +0 -1
- package/dist/bootstrap/loading.js +0 -19
- package/dist/bootstrap/loading.js.map +0 -1
- package/dist/bootstrap/loading.stories.d.ts +0 -9
- package/dist/bootstrap/loading.stories.d.ts.map +0 -1
- package/dist/bootstrap/responsiveHelper.d.ts +0 -8
- package/dist/bootstrap/responsiveHelper.d.ts.map +0 -1
- package/dist/bootstrap/responsiveHelper.js +0 -46
- package/dist/bootstrap/responsiveHelper.js.map +0 -1
- package/dist/bootstrap/screen.d.ts +0 -22
- package/dist/bootstrap/screen.d.ts.map +0 -1
- package/dist/bootstrap/screen.js +0 -80
- package/dist/bootstrap/screen.js.map +0 -1
- package/dist/bootstrap/screen.stories.d.ts +0 -14
- package/dist/bootstrap/screen.stories.d.ts.map +0 -1
- package/dist/bootstrap/toaster.d.ts +0 -11
- package/dist/bootstrap/toaster.d.ts.map +0 -1
- package/dist/bootstrap/toaster.js +0 -34
- package/dist/bootstrap/toaster.js.map +0 -1
- package/dist/bootstrap/toaster.stories.d.ts +0 -8
- package/dist/bootstrap/toaster.stories.d.ts.map +0 -1
- package/dist/bootstrap/useModal.d.ts +0 -23
- package/dist/bootstrap/useModal.d.ts.map +0 -1
- package/dist/bootstrap/useModal.js +0 -50
- package/dist/bootstrap/useModal.js.map +0 -1
- package/dist/bootstrap/useModal.stories.d.ts +0 -9
- package/dist/bootstrap/useModal.stories.d.ts.map +0 -1
- package/dist/bootstrap/useWrappedForm.d.ts +0 -14
- package/dist/bootstrap/useWrappedForm.d.ts.map +0 -1
- package/dist/bootstrap/useWrappedForm.js +0 -32
- package/dist/bootstrap/useWrappedForm.js.map +0 -1
- package/dist/core/cache.d.ts +0 -120
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/cache.js +0 -107
- package/dist/core/cache.js.map +0 -1
- package/dist/core/cache.test.d.ts +0 -2
- package/dist/core/cache.test.d.ts.map +0 -1
- package/dist/core/errors.d.ts +0 -2
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/errors.js +0 -15
- package/dist/core/errors.js.map +0 -1
- package/dist/core/files.d.ts +0 -4
- package/dist/core/files.d.ts.map +0 -1
- package/dist/core/files.js +0 -31
- package/dist/core/files.js.map +0 -1
- package/dist/core/index.js +0 -35
- package/dist/core/index.js.map +0 -1
- package/dist/core/ls.d.ts +0 -6
- package/dist/core/ls.d.ts.map +0 -1
- package/dist/core/ls.js +0 -12
- package/dist/core/ls.js.map +0 -1
- package/dist/core/measure.d.ts +0 -35
- package/dist/core/measure.d.ts.map +0 -1
- package/dist/core/measure.js +0 -60
- package/dist/core/measure.js.map +0 -1
- package/dist/core/mutex.d.ts +0 -6
- package/dist/core/mutex.d.ts.map +0 -1
- package/dist/core/mutex.js +0 -26
- package/dist/core/mutex.js.map +0 -1
- package/dist/core/worker.d.ts +0 -98
- package/dist/core/worker.d.ts.map +0 -1
- package/dist/core/worker.js +0 -240
- package/dist/core/worker.js.map +0 -1
- package/dist/core/worker.test.d.ts +0 -2
- package/dist/core/worker.test.d.ts.map +0 -1
- package/dist/core/workerUtils.d.ts +0 -3
- package/dist/core/workerUtils.d.ts.map +0 -1
- package/dist/core/workerUtils.js +0 -31
- package/dist/core/workerUtils.js.map +0 -1
- package/dist/core/wrpc.d.ts +0 -45
- package/dist/core/wrpc.d.ts.map +0 -1
- package/dist/core/wrpc.fixture.d.ts +0 -26
- package/dist/core/wrpc.fixture.d.ts.map +0 -1
- package/dist/core/wrpc.js +0 -242
- package/dist/core/wrpc.js.map +0 -1
- package/dist/core/wrpc.test.d.ts +0 -1
- package/dist/core/wrpc.test.d.ts.map +0 -1
- package/dist/electron/createWindow.d.ts +0 -23
- package/dist/electron/createWindow.d.ts.map +0 -1
- package/dist/electron/createWindow.js +0 -160
- package/dist/electron/createWindow.js.map +0 -1
- package/dist/electron/index.js +0 -9
- package/dist/electron/index.js.map +0 -1
- package/dist/electron/updater.d.ts +0 -2
- package/dist/electron/updater.d.ts.map +0 -1
- package/dist/electron/updater.js +0 -47
- package/dist/electron/updater.js.map +0 -1
- package/dist/electron-builder/builder.d.ts +0 -8
- package/dist/electron-builder/builder.d.ts.map +0 -1
- package/dist/electron-builder/builder.js +0 -130
- package/dist/electron-builder/builder.js.map +0 -1
- package/dist/electron-builder/images.d.ts +0 -7
- package/dist/electron-builder/images.d.ts.map +0 -1
- package/dist/electron-builder/images.js +0 -25
- package/dist/electron-builder/images.js.map +0 -1
- package/dist/electron-builder/index.js +0 -7
- package/dist/electron-builder/index.js.map +0 -1
- package/dist/mui/formControlFieldset.d.ts +0 -5
- package/dist/mui/formControlFieldset.d.ts.map +0 -1
- package/dist/mui/formControlFieldset.js +0 -28
- package/dist/mui/formControlFieldset.js.map +0 -1
- package/dist/mui/formControlFieldset.stories.d.ts +0 -7
- package/dist/mui/formControlFieldset.stories.d.ts.map +0 -1
- package/dist/mui/formLabelLegend.d.ts +0 -4
- package/dist/mui/formLabelLegend.d.ts.map +0 -1
- package/dist/mui/formLabelLegend.js +0 -12
- package/dist/mui/formLabelLegend.js.map +0 -1
- package/dist/mui/genericControl.d.ts +0 -7
- package/dist/mui/genericControl.d.ts.map +0 -1
- package/dist/mui/genericControl.js +0 -21
- package/dist/mui/genericControl.js.map +0 -1
- package/dist/mui/index.js +0 -11
- package/dist/mui/index.js.map +0 -1
- package/dist/mui/readOnly.d.ts +0 -6
- package/dist/mui/readOnly.d.ts.map +0 -1
- package/dist/mui/readOnly.js +0 -7
- package/dist/mui/readOnly.js.map +0 -1
- package/dist/next/appLink.d.ts +0 -8
- package/dist/next/appLink.d.ts.map +0 -1
- package/dist/next/appLink.js +0 -34
- package/dist/next/appLink.js.map +0 -1
- package/dist/next/index.js +0 -15
- package/dist/next/index.js.map +0 -1
- package/dist/next/measure.d.ts +0 -15
- package/dist/next/measure.d.ts.map +0 -1
- package/dist/next/measure.js +0 -9
- package/dist/next/measure.js.map +0 -1
- package/dist/next/noSSR.d.ts +0 -29
- package/dist/next/noSSR.d.ts.map +0 -1
- package/dist/next/noSSR.js +0 -13
- package/dist/next/noSSR.js.map +0 -1
- package/dist/next/redirect.d.ts +0 -6
- package/dist/next/redirect.d.ts.map +0 -1
- package/dist/next/useIsInner.d.ts +0 -3
- package/dist/next/useIsInner.d.ts.map +0 -1
- package/dist/next/useIsInner.js +0 -15
- package/dist/next/useIsInner.js.map +0 -1
- package/dist/react/apiCall.d.ts +0 -6
- package/dist/react/apiCall.d.ts.map +0 -1
- package/dist/react/apiCall.js +0 -24
- package/dist/react/apiCall.js.map +0 -1
- package/dist/react/form/client.d.ts +0 -7
- package/dist/react/form/client.d.ts.map +0 -1
- package/dist/react/form/client.js +0 -46
- package/dist/react/form/client.js.map +0 -1
- package/dist/react/form/form.d.ts +0 -59
- package/dist/react/form/form.d.ts.map +0 -1
- package/dist/react/form/form.js +0 -89
- package/dist/react/form/form.js.map +0 -1
- package/dist/react/form/index.d.ts +0 -3
- package/dist/react/form/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -26
- package/dist/react/index.js.map +0 -1
- package/dist/react/keyboard.d.ts +0 -10
- package/dist/react/keyboard.d.ts.map +0 -1
- package/dist/react/keyboard.js +0 -38
- package/dist/react/keyboard.js.map +0 -1
- package/dist/react/useFetch.d.ts +0 -2
- package/dist/react/useFetch.d.ts.map +0 -1
- package/dist/react/useFetch.js +0 -20
- package/dist/react/useFetch.js.map +0 -1
- package/dist/react/useFetcher.d.ts +0 -10
- package/dist/react/useFetcher.d.ts.map +0 -1
- package/dist/react/useFetcher.js +0 -43
- package/dist/react/useFetcher.js.map +0 -1
- package/dist/react-native/index.js +0 -9
- package/dist/react-native/index.js.map +0 -1
- package/dist/react-native/share.d.ts +0 -9
- package/dist/react-native/share.d.ts.map +0 -1
- package/dist/react-native/share.js +0 -23
- package/dist/react-native/share.js.map +0 -1
- package/dist/react-native/update.d.ts +0 -3
- package/dist/react-native/update.d.ts.map +0 -1
- package/dist/react-native/update.js +0 -40
- package/dist/react-native/update.js.map +0 -1
- package/dist/react-native/useAppState.d.ts +0 -2
- package/dist/react-native/useAppState.d.ts.map +0 -1
- package/dist/react-native/useAppState.js +0 -18
- package/dist/react-native/useAppState.js.map +0 -1
- package/dist/tailwind/fullpage.d.ts +0 -3
- package/dist/tailwind/fullpage.d.ts.map +0 -1
- package/dist/tailwind/fullpage.js +0 -14
- package/dist/tailwind/fullpage.js.map +0 -1
- package/dist/tailwind/index.js +0 -7
- package/dist/tailwind/index.js.map +0 -1
- package/dist/tailwind/responsiveHelper.d.ts +0 -3
- package/dist/tailwind/responsiveHelper.d.ts.map +0 -1
- package/dist/tailwind/responsiveHelper.js +0 -16
- package/dist/tailwind/responsiveHelper.js.map +0 -1
- package/src/bootstrap/adaptiveContainer.tsx +0 -12
- package/src/bootstrap/controls.stories.tsx +0 -62
- package/src/bootstrap/controls.tsx +0 -119
- package/src/bootstrap/error.stories.tsx +0 -34
- package/src/bootstrap/error.tsx +0 -37
- package/src/bootstrap/field.stories.tsx +0 -42
- package/src/bootstrap/field.tsx +0 -37
- package/src/bootstrap/footer.tsx +0 -61
- package/src/bootstrap/globalLoading.stories.tsx +0 -25
- package/src/bootstrap/globalLoading.tsx +0 -19
- package/src/bootstrap/loading.stories.tsx +0 -35
- package/src/bootstrap/loading.tsx +0 -24
- package/src/bootstrap/main.scss +0 -86
- package/src/bootstrap/responsiveHelper.tsx +0 -55
- package/src/bootstrap/screen.stories.tsx +0 -160
- package/src/bootstrap/screen.tsx +0 -146
- package/src/bootstrap/toaster.stories.tsx +0 -32
- package/src/bootstrap/toaster.tsx +0 -40
- package/src/bootstrap/useModal.stories.tsx +0 -51
- package/src/bootstrap/useModal.tsx +0 -93
- package/src/bootstrap/useWrappedForm.ts +0 -42
- package/src/core/README.md +0 -91
- package/src/core/cache.test.ts +0 -121
- package/src/core/cache.ts +0 -246
- package/src/core/errors.ts +0 -17
- package/src/core/files.ts +0 -29
- package/src/core/ls.ts +0 -15
- package/src/core/measure.ts +0 -109
- package/src/core/mutex.ts +0 -22
- package/src/core/worker.test.ts +0 -197
- package/src/core/worker.ts +0 -347
- package/src/core/workerUtils.ts +0 -32
- package/src/core/wrpc.fixture.ts +0 -106
- package/src/core/wrpc.test.ts +0 -225
- package/src/core/wrpc.ts +0 -377
- package/src/electron/README.md +0 -13
- package/src/electron/createWindow.ts +0 -234
- package/src/electron/updater.ts +0 -54
- package/src/electron-builder/builder.ts +0 -150
- package/src/electron-builder/images.ts +0 -33
- package/src/mui/README.md +0 -3
- package/src/mui/formControlFieldset.stories.tsx +0 -71
- package/src/mui/formControlFieldset.tsx +0 -26
- package/src/mui/formLabelLegend.tsx +0 -11
- package/src/mui/genericControl.tsx +0 -20
- package/src/mui/readOnly.tsx +0 -6
- package/src/next/appLink.tsx +0 -40
- package/src/next/measure.ts +0 -24
- package/src/next/noSSR.tsx +0 -36
- package/src/next/redirect.tsx +0 -13
- package/src/next/useIsInner.ts +0 -13
- package/src/react/apiCall.ts +0 -25
- package/src/react/form/client.tsx +0 -73
- package/src/react/form/form.tsx +0 -178
- package/src/react/form/index.ts +0 -2
- package/src/react/keyboard.tsx +0 -54
- package/src/react/useFetch.ts +0 -29
- package/src/react/useFetcher.ts +0 -54
- package/src/react-native/share.ts +0 -31
- package/src/react-native/update.tsx +0 -40
- package/src/react-native/useAppState.ts +0 -18
- package/src/tailwind/README.md +0 -8
- package/src/tailwind/fullpage.tsx +0 -11
- package/src/tailwind/responsiveHelper.tsx +0 -16
- package/src-todo/auth0.tsx +0 -177
- package/vite.exports.ts +0 -121
- /package/dist/{bootstrap/index.js.map → index.js.map} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { MaybeTypeOf, Validation } from './form';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export declare function createClient<S extends z.ZodObject<any>>(schema: S): {
|
|
4
|
-
useValidation: (actionFn: (data: FormData) => Promise<Validation<S>>, initialData?: MaybeTypeOf<S>) => [state: Validation<S>, dispatch: (payload: FormData) => void, isPending: boolean];
|
|
5
|
-
useValidationTransition: (actionFn: (data: FormData) => Promise<Validation<S>>, initialData?: MaybeTypeOf<S>) => [Validation<S>, (formData: FormData) => Promise<Validation<S>>, boolean];
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/react/form/client.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAU,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EACnD,MAAM,EAAE,CAAC,GACV;IACC,aAAa,EAAE,CACX,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACpD,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAC3B,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACvF,uBAAuB,EAAE,CACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACpD,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAC3B,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;CACjF,CAqDA"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useActionState, useTransition, useState, useCallback } from "react";
|
|
3
|
-
import { create } from "./form.js";
|
|
4
|
-
const FORM_DEBUG = process.env.NEXT_PUBLIC_FORM_DEBUG === "true";
|
|
5
|
-
function createClient(schema) {
|
|
6
|
-
const { validate } = create(schema);
|
|
7
|
-
function useValidationCallback(actionFn) {
|
|
8
|
-
return useCallback(
|
|
9
|
-
async (formData) => {
|
|
10
|
-
const clientRes = validate(formData);
|
|
11
|
-
console.log("Client validation", FORM_DEBUG ? "ignored" : "active", clientRes);
|
|
12
|
-
if (!clientRes.success && !FORM_DEBUG) return clientRes;
|
|
13
|
-
const serverRes = await actionFn(formData);
|
|
14
|
-
console.log("Server validation", serverRes);
|
|
15
|
-
return serverRes;
|
|
16
|
-
},
|
|
17
|
-
[actionFn]
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
function useValidation(actionFn, initialData = {}) {
|
|
21
|
-
const cb = useValidationCallback(actionFn);
|
|
22
|
-
return useActionState(async (_, data) => cb(data), {
|
|
23
|
-
success: false,
|
|
24
|
-
data: initialData
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function useValidationTransition(actionFn, initialData = {}) {
|
|
28
|
-
const [isPending, startTransition] = useTransition();
|
|
29
|
-
const [state, setState] = useState({ success: false, data: initialData });
|
|
30
|
-
const cb = useValidationCallback(actionFn);
|
|
31
|
-
const wrappedCb = useCallback(
|
|
32
|
-
(formData) => {
|
|
33
|
-
const promise = cb(formData);
|
|
34
|
-
startTransition(() => promise.then(setState));
|
|
35
|
-
return promise;
|
|
36
|
-
},
|
|
37
|
-
[cb, startTransition]
|
|
38
|
-
);
|
|
39
|
-
return [state, wrappedCb, isPending];
|
|
40
|
-
}
|
|
41
|
-
return { useValidation, useValidationTransition };
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
createClient
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/react/form/client.tsx"],"sourcesContent":["'use client';\n\nimport { useActionState, useCallback, useState, useTransition } from 'react';\nimport { create, MaybeTypeOf, Validation } from './form';\nimport { z } from 'zod';\n\nconst FORM_DEBUG = process.env.NEXT_PUBLIC_FORM_DEBUG === 'true';\n\nexport function createClient<S extends z.ZodObject<any>>(\n schema: S,\n): {\n useValidation: (\n actionFn: (data: FormData) => Promise<Validation<S>>,\n initialData?: MaybeTypeOf<S>,\n ) => [state: Validation<S>, dispatch: (payload: FormData) => void, isPending: boolean];\n useValidationTransition: (\n actionFn: (data: FormData) => Promise<Validation<S>>,\n initialData?: MaybeTypeOf<S>,\n ) => [Validation<S>, (formData: FormData) => Promise<Validation<S>>, boolean];\n} {\n const { validate } = create(schema);\n\n function useValidationCallback(\n actionFn: (data: FormData) => Promise<Validation<S>>,\n ): (formData: FormData) => Promise<Validation<S>> {\n return useCallback(\n async (formData: FormData) => {\n const clientRes = validate(formData);\n console.log('Client validation', FORM_DEBUG ? 'ignored' : 'active', clientRes);\n if (!clientRes.success && !FORM_DEBUG) return clientRes;\n\n const serverRes = await actionFn(formData);\n console.log('Server validation', serverRes);\n return serverRes;\n },\n [actionFn],\n );\n }\n\n function useValidation(\n actionFn: (data: FormData) => Promise<Validation<S>>,\n initialData: MaybeTypeOf<S> = {} as MaybeTypeOf<S>,\n ): [state: Validation<S>, dispatch: (payload: FormData) => void, isPending: boolean] {\n const cb = useValidationCallback(actionFn);\n\n return useActionState<Validation<S>, FormData>(async (_, data) => cb(data), {\n success: false,\n data: initialData,\n });\n }\n\n function useValidationTransition(\n actionFn: (data: FormData) => Promise<Validation<S>>,\n initialData: MaybeTypeOf<S> = {} as MaybeTypeOf<S>,\n ): [Validation<S>, (formData: FormData) => Promise<Validation<S>>, boolean] {\n const [isPending, startTransition] = useTransition();\n const [state, setState] = useState<Validation<S>>({ success: false, data: initialData });\n const cb = useValidationCallback(actionFn);\n\n const wrappedCb = useCallback(\n (formData: FormData) => {\n const promise = cb(formData);\n startTransition(() => promise.then(setState));\n return promise;\n },\n [cb, startTransition],\n );\n\n return [state, wrappedCb, isPending];\n }\n\n return { useValidation, useValidationTransition };\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,aAAa,QAAQ,IAAI,2BAA2B;AAEnD,SAAS,aACZ,QAUF;AACE,QAAM,EAAE,SAAA,IAAa,OAAO,MAAM;AAElC,WAAS,sBACL,UAC8C;AACvC,WAAA;AAAA,MACH,OAAO,aAAuB;AACpB,cAAA,YAAY,SAAS,QAAQ;AACnC,gBAAQ,IAAI,qBAAqB,aAAa,YAAY,UAAU,SAAS;AAC7E,YAAI,CAAC,UAAU,WAAW,CAAC,WAAmB,QAAA;AAExC,cAAA,YAAY,MAAM,SAAS,QAAQ;AACjC,gBAAA,IAAI,qBAAqB,SAAS;AACnC,eAAA;AAAA,MACX;AAAA,MACA,CAAC,QAAQ;AAAA,IACb;AAAA,EAAA;AAGJ,WAAS,cACL,UACA,cAA8B,IACmD;AAC3E,UAAA,KAAK,sBAAsB,QAAQ;AAEzC,WAAO,eAAwC,OAAO,GAAG,SAAS,GAAG,IAAI,GAAG;AAAA,MACxE,SAAS;AAAA,MACT,MAAM;AAAA,IAAA,CACT;AAAA,EAAA;AAGL,WAAS,wBACL,UACA,cAA8B,IAC0C;AACxE,UAAM,CAAC,WAAW,eAAe,IAAI,cAAc;AAC7C,UAAA,CAAC,OAAO,QAAQ,IAAI,SAAwB,EAAE,SAAS,OAAO,MAAM,aAAa;AACjF,UAAA,KAAK,sBAAsB,QAAQ;AAEzC,UAAM,YAAY;AAAA,MACd,CAAC,aAAuB;AACd,cAAA,UAAU,GAAG,QAAQ;AAC3B,wBAAgB,MAAM,QAAQ,KAAK,QAAQ,CAAC;AACrC,eAAA;AAAA,MACX;AAAA,MACA,CAAC,IAAI,eAAe;AAAA,IACxB;AAEO,WAAA,CAAC,OAAO,WAAW,SAAS;AAAA,EAAA;AAGhC,SAAA,EAAE,eAAe,wBAAwB;AACpD;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { typeToFlattenedError, z, SafeParseReturnType, TypeOf } from 'zod';
|
|
2
|
-
import { Context, FC } from 'react';
|
|
3
|
-
export declare const stringRequired: () => z.ZodString;
|
|
4
|
-
export declare const maxLength: (schema: z.ZodString) => number;
|
|
5
|
-
export declare const minLength: (schema: z.ZodString) => number;
|
|
6
|
-
export declare const isRequired: (schema: z.ZodString) => boolean;
|
|
7
|
-
export type ZodObject = z.ZodObject<any> | z.ZodEffects<z.ZodObject<any>>;
|
|
8
|
-
export type MaybeTypeOf<S extends ZodObject> = Partial<TypeOf<S>>;
|
|
9
|
-
export type SafeTypeOf<S extends ZodObject> = SafeParseReturnType<TypeOf<S>, TypeOf<S>>['data'];
|
|
10
|
-
export type Errors<S extends ZodObject> = typeToFlattenedError<TypeOf<S>>['fieldErrors'];
|
|
11
|
-
export type Validation<S extends ZodObject> = {
|
|
12
|
-
success: true;
|
|
13
|
-
data: SafeTypeOf<S>;
|
|
14
|
-
errors?: never;
|
|
15
|
-
} | {
|
|
16
|
-
success: false;
|
|
17
|
-
data?: MaybeTypeOf<S>;
|
|
18
|
-
errors?: Errors<S>;
|
|
19
|
-
};
|
|
20
|
-
export declare const FormContext: Context<{
|
|
21
|
-
schema: ZodObject;
|
|
22
|
-
}>;
|
|
23
|
-
export interface FormProps<S extends ZodObject> {
|
|
24
|
-
schema: S;
|
|
25
|
-
children: any;
|
|
26
|
-
}
|
|
27
|
-
export declare const Form: FC<FormProps<any>>;
|
|
28
|
-
export declare function create<S extends ZodObject>(schema: S): {
|
|
29
|
-
register: (name: keyof TypeOf<S>, data?: MaybeTypeOf<S>, errors?: Errors<S>, mui?: boolean) => {
|
|
30
|
-
label?: any;
|
|
31
|
-
helperText?: string;
|
|
32
|
-
error?: boolean;
|
|
33
|
-
name: keyof z.TypeOf<S>;
|
|
34
|
-
id: keyof z.TypeOf<S>;
|
|
35
|
-
required: boolean;
|
|
36
|
-
maxLength: number;
|
|
37
|
-
type: string;
|
|
38
|
-
defaultValue?: Partial<z.TypeOf<S>>[keyof z.TypeOf<S>];
|
|
39
|
-
};
|
|
40
|
-
validate: (formData: FormData) => Validation<S>;
|
|
41
|
-
validationError: (data: MaybeTypeOf<S>, errors: Errors<S>) => Validation<S>;
|
|
42
|
-
};
|
|
43
|
-
interface FieldProps<S extends ZodObject> {
|
|
44
|
-
children?: any;
|
|
45
|
-
name: keyof TypeOf<S>;
|
|
46
|
-
errors?: Validation<S>['errors'];
|
|
47
|
-
hint?: string;
|
|
48
|
-
className?: string;
|
|
49
|
-
labelProps?: any;
|
|
50
|
-
[key: string]: any;
|
|
51
|
-
}
|
|
52
|
-
export declare const Field: FC<FieldProps<any>>;
|
|
53
|
-
export interface HintProps {
|
|
54
|
-
children: any;
|
|
55
|
-
error?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export declare const Hint: FC<HintProps>;
|
|
58
|
-
export {};
|
|
59
|
-
//# sourceMappingURL=form.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/react/form/form.tsx"],"names":[],"mappings":"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"}
|
package/dist/react/form/form.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { createContext, memo, useMemo, useContext } from "react";
|
|
4
|
-
import clsx from "clsx";
|
|
5
|
-
const nonEmpty = "This field cannot be empty";
|
|
6
|
-
const stringRequired = () => z.string({ required_error: nonEmpty }).min(1, nonEmpty);
|
|
7
|
-
const maxLength = (schema) => schema.maxLength || 0;
|
|
8
|
-
const minLength = (schema) => schema.minLength || 0;
|
|
9
|
-
const isRequired = (schema) => minLength(schema) > 0;
|
|
10
|
-
const FormContext = createContext(null);
|
|
11
|
-
const Form = memo(function Form2({ schema, children }) {
|
|
12
|
-
const value = useMemo(() => ({ schema }), [schema]);
|
|
13
|
-
return /* @__PURE__ */ jsx(FormContext.Provider, { value, children });
|
|
14
|
-
});
|
|
15
|
-
const getShape = (schema) => schema.shape || schema.sourceType().shape;
|
|
16
|
-
function create(schema) {
|
|
17
|
-
if (!getShape(schema)) {
|
|
18
|
-
throw new Error("Invalid schema: only z.object() or z.object().refine() are supported");
|
|
19
|
-
}
|
|
20
|
-
function register(name, data, errors, mui = false) {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const field = getShape(schema)[name];
|
|
23
|
-
return {
|
|
24
|
-
name,
|
|
25
|
-
id: name,
|
|
26
|
-
required: isRequired(field),
|
|
27
|
-
maxLength: maxLength(field),
|
|
28
|
-
type: field.isEmail ? "email" : name.includes("password") ? "password" : "text",
|
|
29
|
-
defaultValue: data == null ? void 0 : data[name],
|
|
30
|
-
...mui ? {
|
|
31
|
-
label: field.description,
|
|
32
|
-
helperText: (_a = errors == null ? void 0 : errors[name]) == null ? void 0 : _a.join(", "),
|
|
33
|
-
error: !!((_b = errors == null ? void 0 : errors[name]) == null ? void 0 : _b.length)
|
|
34
|
-
} : {}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function validationError(data, errors) {
|
|
38
|
-
return {
|
|
39
|
-
success: false,
|
|
40
|
-
data,
|
|
41
|
-
// data is undefined if there are errors
|
|
42
|
-
errors
|
|
43
|
-
// Next.js will butcher error object, so we provide something more primitive
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function validate(formData) {
|
|
47
|
-
const rawData = Object.fromEntries(formData);
|
|
48
|
-
const { error, data } = schema.safeParse(rawData);
|
|
49
|
-
if (error) {
|
|
50
|
-
return validationError(rawData, error.flatten().fieldErrors);
|
|
51
|
-
}
|
|
52
|
-
return { success: true, data };
|
|
53
|
-
}
|
|
54
|
-
return { register, validate, validationError };
|
|
55
|
-
}
|
|
56
|
-
const Field = memo(function Field2({
|
|
57
|
-
children,
|
|
58
|
-
name,
|
|
59
|
-
errors,
|
|
60
|
-
hint,
|
|
61
|
-
className,
|
|
62
|
-
labelProps,
|
|
63
|
-
...props
|
|
64
|
-
}) {
|
|
65
|
-
var _a;
|
|
66
|
-
const { schema } = useContext(FormContext);
|
|
67
|
-
const { description } = getShape(schema)[name];
|
|
68
|
-
return /* @__PURE__ */ jsxs("div", { ...props, className: clsx("form-row", className), children: [
|
|
69
|
-
description && /* @__PURE__ */ jsx("label", { ...labelProps, htmlFor: name, children: description }),
|
|
70
|
-
children,
|
|
71
|
-
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
72
|
-
(_a = errors == null ? void 0 : errors[name]) == null ? void 0 : _a.map((e) => /* @__PURE__ */ jsx(Hint, { error: true, children: e }, e))
|
|
73
|
-
] });
|
|
74
|
-
});
|
|
75
|
-
const Hint = memo(function Hint2({ children, error }) {
|
|
76
|
-
return /* @__PURE__ */ jsx("div", { className: `hint ${error ? "hint-error" : ""}`, children });
|
|
77
|
-
});
|
|
78
|
-
export {
|
|
79
|
-
Field,
|
|
80
|
-
Form,
|
|
81
|
-
FormContext,
|
|
82
|
-
Hint,
|
|
83
|
-
create,
|
|
84
|
-
isRequired,
|
|
85
|
-
maxLength,
|
|
86
|
-
minLength,
|
|
87
|
-
stringRequired
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=form.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","sources":["../../../src/react/form/form.tsx"],"sourcesContent":["import { typeToFlattenedError, z, SafeParseReturnType, TypeOf } from 'zod';\nimport { Context, createContext, useContext, useMemo, JSX, FC, memo } from 'react';\nimport clsx from 'clsx';\n\nconst nonEmpty = 'This field cannot be empty';\n\nexport const stringRequired = (): z.ZodString => z.string({ required_error: nonEmpty }).min(1, nonEmpty);\nexport const maxLength = (schema: z.ZodString): number => schema.maxLength || 0;\nexport const minLength = (schema: z.ZodString): number => schema.minLength || 0;\nexport const isRequired = (schema: z.ZodString): boolean => minLength(schema) > 0;\n\nexport type ZodObject = z.ZodObject<any> | z.ZodEffects<z.ZodObject<any>>; // z.ZodType<any, any, any>\nexport type MaybeTypeOf<S extends ZodObject> = Partial<TypeOf<S>>;\nexport type SafeTypeOf<S extends ZodObject> = SafeParseReturnType<TypeOf<S>, TypeOf<S>>['data'];\nexport type Errors<S extends ZodObject> = typeToFlattenedError<TypeOf<S>>['fieldErrors'];\nexport type Validation<S extends ZodObject> =\n | {\n success: true; // this is true only if form was validated successfully\n data: SafeTypeOf<S>;\n errors?: never;\n }\n | {\n success: false;\n data?: MaybeTypeOf<S>;\n errors?: Errors<S>;\n };\n\nexport const FormContext: Context<{\n schema: ZodObject;\n}> = createContext(null as never);\n\nexport interface FormProps<S extends ZodObject> {\n schema: S;\n children: any;\n}\n\nexport const Form: FC<FormProps<any>> = memo(function Form({ schema, children }) {\n const value = useMemo(() => ({ schema }), [schema]);\n return <FormContext.Provider value={value}>{children}</FormContext.Provider>;\n});\n\nconst getShape = <S extends ZodObject>(schema: S) =>\n (schema as z.ZodObject<any>).shape || (schema as z.ZodEffects<z.ZodObject<any>>).sourceType().shape;\n\nexport function create<S extends ZodObject>(\n schema: S,\n): {\n register: (\n name: keyof TypeOf<S>,\n data?: MaybeTypeOf<S>,\n errors?: Errors<S>,\n mui?: boolean,\n ) => {\n label?: any;\n helperText?: string;\n error?: boolean;\n name: keyof z.TypeOf<S>;\n id: keyof z.TypeOf<S>;\n required: boolean;\n maxLength: number;\n type: string;\n defaultValue?: Partial<z.TypeOf<S>>[keyof z.TypeOf<S>];\n };\n validate: (formData: FormData) => Validation<S>;\n validationError: (data: MaybeTypeOf<S>, errors: Errors<S>) => Validation<S>;\n} {\n if (!getShape(schema)) {\n throw new Error('Invalid schema: only z.object() or z.object().refine() are supported');\n }\n\n function register(\n name: keyof TypeOf<S>,\n data?: MaybeTypeOf<S>,\n errors?: Errors<S>,\n mui: boolean = false,\n ): {\n label?: any;\n helperText?: string;\n error?: boolean;\n name: keyof z.TypeOf<S>;\n id: keyof z.TypeOf<S>;\n required: boolean;\n maxLength: number;\n type: string;\n defaultValue?: Partial<z.TypeOf<S>>[keyof z.TypeOf<S>];\n } {\n const field = getShape(schema)[name];\n return {\n name,\n id: name,\n required: isRequired(field),\n maxLength: maxLength(field),\n type: field.isEmail ? 'email' : (name as string).includes('password') ? 'password' : 'text',\n defaultValue: data?.[name],\n ...(mui\n ? {\n label: field.description,\n helperText: errors?.[name]?.join(', '),\n error: !!errors?.[name]?.length,\n }\n : {}),\n };\n }\n\n function validationError(data: MaybeTypeOf<S>, errors: Errors<S>): Validation<S> {\n return {\n success: false,\n data, // data is undefined if there are errors\n errors, // Next.js will butcher error object, so we provide something more primitive\n };\n }\n\n function validate(formData: FormData): Validation<S> {\n const rawData = Object.fromEntries(formData) as TypeOf<S>;\n const { error, data } = schema.safeParse(rawData);\n\n // console.log('Validate result', { error, data, rawData });\n\n if (error) {\n // data is undefined if there are errors\n // Next.js will butcher error object, so we provide something more primitive\n return validationError(rawData, error.flatten().fieldErrors as any);\n }\n\n return { success: true, data };\n }\n\n return { register, validate, validationError };\n}\n\ninterface FieldProps<S extends ZodObject> {\n children?: any;\n name: keyof TypeOf<S>;\n errors?: Validation<S>['errors'];\n hint?: string;\n className?: string;\n labelProps?: any;\n [key: string]: any;\n}\n\nexport const Field: FC<FieldProps<any>> = memo(function Field({\n children,\n name,\n errors,\n hint,\n className,\n labelProps,\n ...props\n}) {\n const { schema } = useContext(FormContext);\n const { description } = getShape(schema)[name];\n\n return (\n <div {...props} className={clsx('form-row', className)}>\n {description && (\n <label {...labelProps} htmlFor={name}>\n {description}\n </label>\n )}\n {children}\n {hint && <Hint>{hint}</Hint>}\n {errors?.[name]?.map((e: string) => (\n <Hint error key={e}>\n {e}\n </Hint>\n ))}\n </div>\n );\n});\n\nexport interface HintProps {\n children: any;\n error?: boolean;\n}\n\nexport const Hint: FC<HintProps> = memo(function Hint({ children, error }) {\n return <div className={`hint ${error ? 'hint-error' : ''}`}>{children}</div>;\n});\n"],"names":["Form","Field","Hint"],"mappings":";;;;AAIA,MAAM,WAAW;AAEJ,MAAA,iBAAiB,MAAmB,EAAE,OAAO,EAAE,gBAAgB,UAAU,EAAE,IAAI,GAAG,QAAQ;AAChG,MAAM,YAAY,CAAC,WAAgC,OAAO,aAAa;AACvE,MAAM,YAAY,CAAC,WAAgC,OAAO,aAAa;AACvE,MAAM,aAAa,CAAC,WAAiC,UAAU,MAAM,IAAI;AAkBnE,MAAA,cAER,cAAc,IAAa;AAOzB,MAAM,OAA2B,KAAK,SAASA,MAAK,EAAE,QAAQ,YAAY;AACvE,QAAA,QAAQ,QAAQ,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;AAClD,SAAQ,oBAAA,YAAY,UAAZ,EAAqB,OAAe,SAAS,CAAA;AACzD,CAAC;AAED,MAAM,WAAW,CAAsB,WAClC,OAA4B,SAAU,OAA0C,aAAa;AAE3F,SAAS,OACZ,QAoBF;AACM,MAAA,CAAC,SAAS,MAAM,GAAG;AACb,UAAA,IAAI,MAAM,sEAAsE;AAAA,EAAA;AAG1F,WAAS,SACL,MACA,MACA,QACA,MAAe,OAWjB;;AACE,UAAM,QAAQ,SAAS,MAAM,EAAE,IAAI;AAC5B,WAAA;AAAA,MACH;AAAA,MACA,IAAI;AAAA,MACJ,UAAU,WAAW,KAAK;AAAA,MAC1B,WAAW,UAAU,KAAK;AAAA,MAC1B,MAAM,MAAM,UAAU,UAAW,KAAgB,SAAS,UAAU,IAAI,aAAa;AAAA,MACrF,cAAc,6BAAO;AAAA,MACrB,GAAI,MACE;AAAA,QACI,OAAO,MAAM;AAAA,QACb,aAAY,sCAAS,UAAT,mBAAgB,KAAK;AAAA,QACjC,OAAO,CAAC,GAAC,sCAAS,UAAT,mBAAgB;AAAA,MAAA,IAE7B,CAAA;AAAA,IACV;AAAA,EAAA;AAGK,WAAA,gBAAgB,MAAsB,QAAkC;AACtE,WAAA;AAAA,MACH,SAAS;AAAA,MACT;AAAA;AAAA,MACA;AAAA;AAAA,IACJ;AAAA,EAAA;AAGJ,WAAS,SAAS,UAAmC;AAC3C,UAAA,UAAU,OAAO,YAAY,QAAQ;AAC3C,UAAM,EAAE,OAAO,KAAA,IAAS,OAAO,UAAU,OAAO;AAIhD,QAAI,OAAO;AAGP,aAAO,gBAAgB,SAAS,MAAM,QAAA,EAAU,WAAkB;AAAA,IAAA;AAG/D,WAAA,EAAE,SAAS,MAAM,KAAK;AAAA,EAAA;AAG1B,SAAA,EAAE,UAAU,UAAU,gBAAgB;AACjD;AAYa,MAAA,QAA6B,KAAK,SAASC,OAAM;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACP,GAAG;;AACC,QAAM,EAAE,OAAA,IAAW,WAAW,WAAW;AACzC,QAAM,EAAE,YAAY,IAAI,SAAS,MAAM,EAAE,IAAI;AAGzC,SAAA,qBAAC,SAAK,GAAG,OAAO,WAAW,KAAK,YAAY,SAAS,GAChD,UAAA;AAAA,IAAA,mCACI,SAAO,EAAA,GAAG,YAAY,SAAS,MAC3B,UACL,aAAA;AAAA,IAEH;AAAA,IACA,QAAS,oBAAA,MAAA,EAAM,UAAK,KAAA,CAAA;AAAA,KACpB,sCAAS,UAAT,mBAAgB,IAAI,CAAC,MACjB,oBAAA,MAAA,EAAK,OAAK,MACN,UADY,EAAA,GAAA,CAEjB;AAAA,EACH,GACL;AAER,CAAC;AAOM,MAAM,OAAsB,KAAK,SAASC,MAAK,EAAE,UAAU,SAAS;AAChE,SAAA,oBAAC,SAAI,WAAW,QAAQ,QAAQ,eAAe,EAAE,IAAK,SAAS,CAAA;AAC1E,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/form/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
package/dist/react/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createClient } from "./form/client.js";
|
|
2
|
-
import { Field, Form, FormContext, Hint, create, isRequired, maxLength, minLength, stringRequired } from "./form/form.js";
|
|
3
|
-
import { apiCall, jsonContentType } from "./apiCall.js";
|
|
4
|
-
import { HotkeysContext, HotkeysProvider, useHotkeys } from "./keyboard.js";
|
|
5
|
-
import { useFetch } from "./useFetch.js";
|
|
6
|
-
import { useFetcher } from "./useFetcher.js";
|
|
7
|
-
export {
|
|
8
|
-
Field,
|
|
9
|
-
Form,
|
|
10
|
-
FormContext,
|
|
11
|
-
Hint,
|
|
12
|
-
HotkeysContext,
|
|
13
|
-
HotkeysProvider,
|
|
14
|
-
apiCall,
|
|
15
|
-
create,
|
|
16
|
-
createClient,
|
|
17
|
-
isRequired,
|
|
18
|
-
jsonContentType,
|
|
19
|
-
maxLength,
|
|
20
|
-
minLength,
|
|
21
|
-
stringRequired,
|
|
22
|
-
useFetch,
|
|
23
|
-
useFetcher,
|
|
24
|
-
useHotkeys
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
package/dist/react/keyboard.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, FC, Context } from 'react';
|
|
2
|
-
export type Hotkeys = Record<KeyboardEvent['code'], (e: KeyboardEvent) => void>;
|
|
3
|
-
export type HotkeyContextType = {
|
|
4
|
-
enabled: boolean;
|
|
5
|
-
setEnabled: Dispatch<SetStateAction<boolean>>;
|
|
6
|
-
};
|
|
7
|
-
export declare const HotkeysContext: Context<HotkeyContextType>;
|
|
8
|
-
export declare const HotkeysProvider: FC<any>;
|
|
9
|
-
export declare const useHotkeys: (hotkeys: Hotkeys) => void;
|
|
10
|
-
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/react/keyboard.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA+C,QAAQ,EAAE,cAAc,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAMvH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC,CAAC;AAEhF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,iBAAiB,CAGrC,CAAC;AAElB,eAAO,MAAM,eAAe,EAAE,EAAE,CAAC,GAAG,CAMnC,CAAC;AAEF,eAAO,MAAM,UAAU,YAAa,OAAO,KAAG,IAyB7C,CAAC"}
|
package/dist/react/keyboard.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useState, useMemo, useContext, useEffect } from "react";
|
|
4
|
-
const isCtrlOrMeta = (e) => e.metaKey || e.ctrlKey;
|
|
5
|
-
const EVENT = "keydown";
|
|
6
|
-
const HotkeysContext = createContext(null);
|
|
7
|
-
const HotkeysProvider = ({ children }) => {
|
|
8
|
-
const [enabled, setEnabled] = useState(true);
|
|
9
|
-
const control = useMemo(() => ({ enabled, setEnabled }), [enabled, setEnabled]);
|
|
10
|
-
return /* @__PURE__ */ jsx(HotkeysContext.Provider, { value: control, children });
|
|
11
|
-
};
|
|
12
|
-
const useHotkeys = (hotkeys) => {
|
|
13
|
-
const { enabled } = useContext(HotkeysContext);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (typeof document === "undefined" || !enabled) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const listeners = (e) => {
|
|
19
|
-
if (!isCtrlOrMeta(e)) return;
|
|
20
|
-
for (const [code, callback] of Object.entries(hotkeys)) {
|
|
21
|
-
if (e.code === code) {
|
|
22
|
-
callback(e);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
window.addEventListener(EVENT, listeners, true);
|
|
28
|
-
return () => {
|
|
29
|
-
window.removeEventListener(EVENT, listeners);
|
|
30
|
-
};
|
|
31
|
-
}, [hotkeys, enabled]);
|
|
32
|
-
};
|
|
33
|
-
export {
|
|
34
|
-
HotkeysContext,
|
|
35
|
-
HotkeysProvider,
|
|
36
|
-
useHotkeys
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=keyboard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.js","sources":["../../src/react/keyboard.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, createContext, useMemo, useState, Dispatch, SetStateAction, useContext, FC, Context } from 'react';\n\nconst isCtrlOrMeta = (e: KeyboardEvent) => e.metaKey || e.ctrlKey;\n\nconst EVENT = 'keydown';\n\nexport type Hotkeys = Record<KeyboardEvent['code'], (e: KeyboardEvent) => void>;\n\nexport type HotkeyContextType = {\n enabled: boolean;\n setEnabled: Dispatch<SetStateAction<boolean>>;\n};\n\nexport const HotkeysContext: Context<HotkeyContextType> = createContext<{\n enabled: boolean;\n setEnabled: Dispatch<SetStateAction<boolean>>;\n}>(null as never);\n\nexport const HotkeysProvider: FC<any> = ({ children }) => {\n const [enabled, setEnabled] = useState(true);\n\n const control = useMemo(() => ({ enabled, setEnabled }), [enabled, setEnabled]);\n\n return <HotkeysContext.Provider value={control}>{children}</HotkeysContext.Provider>;\n};\n\nexport const useHotkeys = (hotkeys: Hotkeys): void => {\n const { enabled } = useContext(HotkeysContext);\n\n useEffect(() => {\n if (typeof document === 'undefined' || !enabled) {\n return;\n }\n\n const listeners = (e: KeyboardEvent) => {\n if (!isCtrlOrMeta(e)) return;\n\n for (const [code, callback] of Object.entries(hotkeys)) {\n if (e.code === code) {\n callback(e);\n return;\n }\n }\n };\n\n window.addEventListener(EVENT, listeners, true);\n\n return () => {\n window.removeEventListener(EVENT, listeners);\n };\n }, [hotkeys, enabled]);\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,eAAe,CAAC,MAAqB,EAAE,WAAW,EAAE;AAE1D,MAAM,QAAQ;AASD,MAAA,iBAA6C,cAGvD,IAAa;AAET,MAAM,kBAA2B,CAAC,EAAE,eAAe;AACtD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAErC,QAAA,UAAU,QAAQ,OAAO,EAAE,SAAS,eAAe,CAAC,SAAS,UAAU,CAAC;AAE9E,6BAAQ,eAAe,UAAf,EAAwB,OAAO,SAAU,UAAS;AAC9D;AAEa,MAAA,aAAa,CAAC,YAA2B;AAClD,QAAM,EAAE,QAAA,IAAY,WAAW,cAAc;AAE7C,YAAU,MAAM;AACZ,QAAI,OAAO,aAAa,eAAe,CAAC,SAAS;AAC7C;AAAA,IAAA;AAGE,UAAA,YAAY,CAAC,MAAqB;AAChC,UAAA,CAAC,aAAa,CAAC,EAAG;AAEtB,iBAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,OAAO,GAAG;AAChD,YAAA,EAAE,SAAS,MAAM;AACjB,mBAAS,CAAC;AACV;AAAA,QAAA;AAAA,MACJ;AAAA,IAER;AAEO,WAAA,iBAAiB,OAAO,WAAW,IAAI;AAE9C,WAAO,MAAM;AACF,aAAA,oBAAoB,OAAO,SAAS;AAAA,IAC/C;AAAA,EAAA,GACD,CAAC,SAAS,OAAO,CAAC;AACzB;"}
|
package/dist/react/useFetch.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetch.d.ts","sourceRoot":"","sources":["../../src/react/useFetch.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,CAAC,EACtB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,YAAY,GAAE,CAAC,GAAG,IAAW,GAC9B,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,GAAG,SAAS,CAAC,CAkBnD"}
|
package/dist/react/useFetch.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useTransition, useState, useCallback } from "react";
|
|
3
|
-
function useFetch(fn, defaultValue = null) {
|
|
4
|
-
const [isPending, startTransition] = useTransition();
|
|
5
|
-
const [data, setData] = useState(defaultValue);
|
|
6
|
-
const [error, setError] = useState();
|
|
7
|
-
const actionFn = useCallback(
|
|
8
|
-
(...args) => {
|
|
9
|
-
const promise = fn(...args);
|
|
10
|
-
startTransition(() => promise.then(setData).catch(setError));
|
|
11
|
-
return promise;
|
|
12
|
-
},
|
|
13
|
-
[fn]
|
|
14
|
-
);
|
|
15
|
-
return [data, actionFn, isPending, error];
|
|
16
|
-
}
|
|
17
|
-
export {
|
|
18
|
-
useFetch
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=useFetch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetch.js","sources":["../../src/react/useFetch.ts"],"sourcesContent":["'use client';\n\nimport { useCallback, useState, useTransition } from 'react';\n\n//TODO useFetch https://use-http.com\n//TODO SWR?\n//TODO Tanstack Query?\nexport function useFetch<R>(\n fn: (...args: any[]) => Promise<R>,\n defaultValue: R | null = null,\n): [R | null, typeof fn, boolean, Error | undefined] {\n // An async function was passed to useActionState, but it was dispatched outside of an action context.\n // This is likely not what you intended. Either pass the dispatch function to an `action` prop, or dispatch manually inside `startTransition`\n const [isPending, startTransition] = useTransition();\n const [data, setData] = useState<R | null>(defaultValue);\n const [error, setError] = useState<Error>();\n\n const actionFn = useCallback(\n (...args: Parameters<typeof fn>) => {\n const promise = fn(...args);\n // https://react.dev/reference/react/useTransition#react-doesnt-treat-my-state-update-after-await-as-a-transition\n startTransition(() => promise.then(setData).catch(setError)); //FIXME sub-chain...\n return promise;\n },\n [fn],\n );\n\n return [data, actionFn, isPending, error];\n}\n"],"names":[],"mappings":";;AAOgB,SAAA,SACZ,IACA,eAAyB,MACwB;AAGjD,QAAM,CAAC,WAAW,eAAe,IAAI,cAAc;AACnD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAmB,YAAY;AACvD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAgB;AAE1C,QAAM,WAAW;AAAA,IACb,IAAI,SAAgC;AAC1B,YAAA,UAAU,GAAG,GAAG,IAAI;AAE1B,sBAAgB,MAAM,QAAQ,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACpD,aAAA;AAAA,IACX;AAAA,IACA,CAAC,EAAE;AAAA,EACP;AAEA,SAAO,CAAC,MAAM,UAAU,WAAW,KAAK;AAC5C;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function useFetcher<T = any>(cb: any, { fetchOnMount, onError }?: {
|
|
2
|
-
fetchOnMount?: boolean;
|
|
3
|
-
onError?: (e: Error) => void;
|
|
4
|
-
}): {
|
|
5
|
-
loading: boolean;
|
|
6
|
-
error: Error | null;
|
|
7
|
-
data: T | null;
|
|
8
|
-
trigger: (...args: any[]) => Promise<any>;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=useFetcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetcher.d.ts","sourceRoot":"","sources":["../../src/react/useFetcher.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,CAAC,GAAG,GAAG,EAC9B,EAAE,EAAE,GAAG,EAEP,EAAE,YAAoB,EAAE,OAAO,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAA;CAAO,GACjG;IACC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7C,CA0CA"}
|
package/dist/react/useFetcher.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { useState, useRef, useCallback, useEffect } from "react";
|
|
2
|
-
function useFetcher(cb, { fetchOnMount = false, onError } = {}) {
|
|
3
|
-
const [loading, setLoading] = useState(fetchOnMount);
|
|
4
|
-
const [error, setError] = useState(null);
|
|
5
|
-
const [data, setData] = useState(null);
|
|
6
|
-
const isMounted = useRef(false);
|
|
7
|
-
const trigger = useCallback(
|
|
8
|
-
async (...args) => {
|
|
9
|
-
try {
|
|
10
|
-
setLoading(true);
|
|
11
|
-
setError(null);
|
|
12
|
-
const res = await cb(args);
|
|
13
|
-
if (!isMounted.current) return;
|
|
14
|
-
setData(res);
|
|
15
|
-
return res;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.error("Fetch failed", e);
|
|
18
|
-
if (!isMounted.current) return;
|
|
19
|
-
setError(e);
|
|
20
|
-
onError == null ? void 0 : onError(e);
|
|
21
|
-
} finally {
|
|
22
|
-
if (isMounted.current) setLoading(false);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
[cb, onError]
|
|
26
|
-
);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (fetchOnMount) {
|
|
29
|
-
trigger().catch((e) => console.error("Fetch on mount failed", e));
|
|
30
|
-
}
|
|
31
|
-
}, [fetchOnMount, cb, trigger]);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
isMounted.current = true;
|
|
34
|
-
return () => {
|
|
35
|
-
isMounted.current = false;
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
return { loading, error, data, trigger };
|
|
39
|
-
}
|
|
40
|
-
export {
|
|
41
|
-
useFetcher
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=useFetcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetcher.js","sources":["../../src/react/useFetcher.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport function useFetcher<T = any>(\n cb: any,\n\n { fetchOnMount = false, onError }: { fetchOnMount?: boolean; onError?: (e: Error) => void } = {},\n): {\n loading: boolean;\n error: Error | null;\n data: T | null;\n trigger: (...args: any[]) => Promise<any>;\n} {\n const [loading, setLoading] = useState(fetchOnMount);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<T | null>(null);\n\n const isMounted = useRef(false);\n\n const trigger = useCallback(\n async (...args: any[]): Promise<any> => {\n try {\n setLoading(true);\n setError(null);\n const res = await cb(args);\n if (!isMounted.current) return;\n setData(res);\n return res;\n } catch (e) {\n console.error('Fetch failed', e);\n if (!isMounted.current) return;\n setError(e);\n (onError as any)?.(e);\n } finally {\n if (isMounted.current) setLoading(false);\n }\n },\n [cb, onError],\n );\n\n useEffect(() => {\n if (fetchOnMount) {\n trigger().catch((e) => console.error('Fetch on mount failed', e)); // catch actually will never happen\n }\n }, [fetchOnMount, cb, trigger]);\n\n useEffect(() => {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n });\n\n return { loading, error, data, trigger };\n}\n"],"names":[],"mappings":";AAEgB,SAAA,WACZ,IAEA,EAAE,eAAe,OAAO,QAAQ,IAA8D,IAMhG;AACE,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,YAAY;AACnD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAmB,IAAI;AAEzC,QAAA,YAAY,OAAO,KAAK;AAE9B,QAAM,UAAU;AAAA,IACZ,UAAU,SAA8B;AAChC,UAAA;AACA,mBAAW,IAAI;AACf,iBAAS,IAAI;AACP,cAAA,MAAM,MAAM,GAAG,IAAI;AACrB,YAAA,CAAC,UAAU,QAAS;AACxB,gBAAQ,GAAG;AACJ,eAAA;AAAA,eACF,GAAG;AACA,gBAAA,MAAM,gBAAgB,CAAC;AAC3B,YAAA,CAAC,UAAU,QAAS;AACxB,iBAAS,CAAC;AACT,2CAAkB;AAAA,MAAC,UACtB;AACM,YAAA,UAAU,QAAS,YAAW,KAAK;AAAA,MAAA;AAAA,IAE/C;AAAA,IACA,CAAC,IAAI,OAAO;AAAA,EAChB;AAEA,YAAU,MAAM;AACZ,QAAI,cAAc;AACN,cAAA,EAAE,MAAM,CAAC,MAAM,QAAQ,MAAM,yBAAyB,CAAC,CAAC;AAAA,IAAA;AAAA,EAErE,GAAA,CAAC,cAAc,IAAI,OAAO,CAAC;AAE9B,YAAU,MAAM;AACZ,cAAU,UAAU;AACpB,WAAO,MAAM;AACT,gBAAU,UAAU;AAAA,IACxB;AAAA,EAAA,CACH;AAED,SAAO,EAAE,SAAS,OAAO,MAAM,QAAQ;AAC3C;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data:text/plain;base64,W29iamV
|
|
3
|
-
* @see https://stackoverflow.com/questions/69738812/problem-to-generate-pdf-from-a-blob-in-an-expo-app-using-filesystem
|
|
4
|
-
* @param base64
|
|
5
|
-
* @param fileName
|
|
6
|
-
* @returns {Promise<void>}
|
|
7
|
-
*/
|
|
8
|
-
export declare const shareDialog: (base64: string, fileName: string) => Promise<void>;
|
|
9
|
-
//# sourceMappingURL=share.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../../src/react-native/share.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,WAAkB,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC,IAAI,CAoBhF,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as FileSystem from "expo-file-system";
|
|
2
|
-
import * as Sharing from "expo-sharing";
|
|
3
|
-
const shareDialog = async (base64, fileName) => {
|
|
4
|
-
const path = `${FileSystem.documentDirectory}/${fileName}`;
|
|
5
|
-
try {
|
|
6
|
-
if (!await Sharing.isAvailableAsync()) throw new Error("Sharing is not available");
|
|
7
|
-
const [header, buffer] = base64.split(",");
|
|
8
|
-
const [, mimeTypeStr] = header.split(":");
|
|
9
|
-
const [mimeType] = mimeTypeStr.split(";");
|
|
10
|
-
await FileSystem.writeAsStringAsync(`${path}`, buffer, {
|
|
11
|
-
encoding: FileSystem.EncodingType.Base64
|
|
12
|
-
});
|
|
13
|
-
await Sharing.shareAsync(path, { mimeType, UTI: fileName, dialogTitle: "Save or share document" });
|
|
14
|
-
} catch (error) {
|
|
15
|
-
alert("Sharing failed: " + error.message);
|
|
16
|
-
} finally {
|
|
17
|
-
await FileSystem.deleteAsync(path);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
shareDialog
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=share.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"share.js","sources":["../../src/react-native/share.ts"],"sourcesContent":["import * as FileSystem from 'expo-file-system';\nimport * as Sharing from 'expo-sharing';\n\n/**\n * data:text/plain;base64,W29iamV\n * @see https://stackoverflow.com/questions/69738812/problem-to-generate-pdf-from-a-blob-in-an-expo-app-using-filesystem\n * @param base64\n * @param fileName\n * @returns {Promise<void>}\n */\nexport const shareDialog = async (base64: string, fileName: string): Promise<void> => {\n const path = `${FileSystem.documentDirectory}/${fileName}`;\n\n try {\n if (!(await Sharing.isAvailableAsync())) throw new Error('Sharing is not available');\n\n const [header, buffer] = base64.split(',');\n const [, mimeTypeStr] = header.split(':');\n const [mimeType] = mimeTypeStr.split(';');\n\n await FileSystem.writeAsStringAsync(`${path}`, buffer, {\n encoding: FileSystem.EncodingType.Base64,\n });\n\n await Sharing.shareAsync(path, { mimeType, UTI: fileName, dialogTitle: 'Save or share document' });\n } catch (error) {\n alert('Sharing failed: ' + error.message);\n } finally {\n await FileSystem.deleteAsync(path);\n }\n};\n"],"names":[],"mappings":";;AAUa,MAAA,cAAc,OAAO,QAAgB,aAAoC;AAClF,QAAM,OAAO,GAAG,WAAW,iBAAiB,IAAI,QAAQ;AAEpD,MAAA;AACI,QAAA,CAAE,MAAM,QAAQ,mBAA2B,OAAA,IAAI,MAAM,0BAA0B;AAEnF,UAAM,CAAC,QAAQ,MAAM,IAAI,OAAO,MAAM,GAAG;AACzC,UAAM,CAAG,EAAA,WAAW,IAAI,OAAO,MAAM,GAAG;AACxC,UAAM,CAAC,QAAQ,IAAI,YAAY,MAAM,GAAG;AAExC,UAAM,WAAW,mBAAmB,GAAG,IAAI,IAAI,QAAQ;AAAA,MACnD,UAAU,WAAW,aAAa;AAAA,IAAA,CACrC;AAEK,UAAA,QAAQ,WAAW,MAAM,EAAE,UAAU,KAAK,UAAU,aAAa,0BAA0B;AAAA,WAC5F,OAAO;AACN,UAAA,qBAAqB,MAAM,OAAO;AAAA,EAAA,UAC1C;AACQ,UAAA,WAAW,YAAY,IAAI;AAAA,EAAA;AAEzC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/react-native/update.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAGhD,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,GAAG,CAmC1B,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsxs } from "react/jsx-runtime";
|
|
2
|
-
import * as Updates from "expo-updates";
|
|
3
|
-
import { useState, useEffect } from "react";
|
|
4
|
-
import { Text } from "react-native";
|
|
5
|
-
const Update = function Update2({ children }) {
|
|
6
|
-
const [updating, setUpdating] = useState(true);
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
(async () => {
|
|
9
|
-
try {
|
|
10
|
-
if (__DEV__) {
|
|
11
|
-
setUpdating(false);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const update = await Updates.checkForUpdateAsync();
|
|
15
|
-
if (!update.isAvailable) {
|
|
16
|
-
setUpdating(false);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
await Updates.fetchUpdateAsync();
|
|
20
|
-
alert("Update is available. App will reload.");
|
|
21
|
-
await Updates.reloadAsync();
|
|
22
|
-
} catch (error) {
|
|
23
|
-
alert(`Error fetching latest Expo update: ${error}`);
|
|
24
|
-
setUpdating(false);
|
|
25
|
-
}
|
|
26
|
-
})();
|
|
27
|
-
});
|
|
28
|
-
if (updating) {
|
|
29
|
-
return /* @__PURE__ */ jsxs(Text, { children: [
|
|
30
|
-
"Checking for updates (",
|
|
31
|
-
Updates.channel,
|
|
32
|
-
")..."
|
|
33
|
-
] });
|
|
34
|
-
}
|
|
35
|
-
return children;
|
|
36
|
-
};
|
|
37
|
-
export {
|
|
38
|
-
Update
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sources":["../../src/react-native/update.tsx"],"sourcesContent":["import * as Updates from 'expo-updates';\nimport { FC, useEffect, useState } from 'react';\nimport { Text } from 'react-native';\n\nexport const Update: FC<any> = function Update({ children }) {\n //FIXME useUpdates https://blog.expo.dev/feature-preview-updates-js-api-for-expo-updates-3b92beb40dab\n const [updating, setUpdating] = useState(true);\n\n useEffect(() => {\n (async () => {\n try {\n if (__DEV__) {\n setUpdating(false);\n return;\n }\n\n const update = await Updates.checkForUpdateAsync();\n\n if (!update.isAvailable) {\n setUpdating(false);\n return;\n }\n\n await Updates.fetchUpdateAsync();\n alert('Update is available. App will reload.');\n await Updates.reloadAsync();\n } catch (error) {\n // You can also add an alert() to see the error message in case of an error when fetching updates.\n alert(`Error fetching latest Expo update: ${error}`);\n setUpdating(false);\n }\n })();\n });\n\n if (updating) {\n return <Text>Checking for updates ({Updates.channel})...</Text>;\n }\n\n return children;\n};\n"],"names":["Update"],"mappings":";;;;AAIO,MAAM,SAAkB,SAASA,QAAO,EAAE,YAAY;AAEzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,IAAI;AAE7C,YAAU,MAAM;AACZ,KAAC,YAAY;AACL,UAAA;AACA,YAAI,SAAS;AACT,sBAAY,KAAK;AACjB;AAAA,QAAA;AAGE,cAAA,SAAS,MAAM,QAAQ,oBAAoB;AAE7C,YAAA,CAAC,OAAO,aAAa;AACrB,sBAAY,KAAK;AACjB;AAAA,QAAA;AAGJ,cAAM,QAAQ,iBAAiB;AAC/B,cAAM,uCAAuC;AAC7C,cAAM,QAAQ,YAAY;AAAA,eACrB,OAAO;AAEN,cAAA,sCAAsC,KAAK,EAAE;AACnD,oBAAY,KAAK;AAAA,MAAA;AAAA,IACrB,GACD;AAAA,EAAA,CACN;AAED,MAAI,UAAU;AACV,gCAAQ,MAAK,EAAA,UAAA;AAAA,MAAA;AAAA,MAAuB,QAAQ;AAAA,MAAQ;AAAA,IAAA,GAAI;AAAA,EAAA;AAGrD,SAAA;AACX;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAppState.d.ts","sourceRoot":"","sources":["../../src/react-native/useAppState.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,IAAI,QAAQ,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAc5F"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
2
|
-
import { AppState } from "react-native";
|
|
3
|
-
function useAppState() {
|
|
4
|
-
const [appState, setAppState] = useState(AppState.currentState);
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
const subscription = AppState.addEventListener("change", (nextAppState) => {
|
|
7
|
-
setAppState(nextAppState);
|
|
8
|
-
});
|
|
9
|
-
return () => {
|
|
10
|
-
subscription.remove();
|
|
11
|
-
};
|
|
12
|
-
}, []);
|
|
13
|
-
return appState;
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
useAppState
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=useAppState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAppState.js","sources":["../../src/react-native/useAppState.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { AppState } from 'react-native';\n\nexport function useAppState(): 'active' | 'background' | 'inactive' | 'unknown' | 'extension' {\n const [appState, setAppState] = useState(AppState.currentState);\n\n useEffect(() => {\n const subscription = AppState.addEventListener('change', (nextAppState) => {\n setAppState(nextAppState);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return appState;\n}\n"],"names":[],"mappings":";;AAGO,SAAS,cAA8E;AAC1F,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,SAAS,YAAY;AAE9D,YAAU,MAAM;AACZ,UAAM,eAAe,SAAS,iBAAiB,UAAU,CAAC,iBAAiB;AACvE,kBAAY,YAAY;AAAA,IAAA,CAC3B;AAED,WAAO,MAAM;AACT,mBAAa,OAAO;AAAA,IACxB;AAAA,EACJ,GAAG,EAAE;AAEE,SAAA;AACX;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fullpage.d.ts","sourceRoot":"","sources":["../../src/tailwind/fullpage.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAElC,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,GAAG,CAQ5B,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
const Fullpage = ({ divRef = null, className = "", children, ...props }) => /* @__PURE__ */ jsx(
|
|
3
|
-
"div",
|
|
4
|
-
{
|
|
5
|
-
ref: divRef,
|
|
6
|
-
...props,
|
|
7
|
-
className: `container h-screen flex flex-col justify-center items-center ${className}`,
|
|
8
|
-
children
|
|
9
|
-
}
|
|
10
|
-
);
|
|
11
|
-
export {
|
|
12
|
-
Fullpage
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=fullpage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fullpage.js","sources":["../../src/tailwind/fullpage.tsx"],"sourcesContent":["import React, { FC } from 'react';\n\nexport const Fullpage: FC<any> = ({ divRef = null, className = '', children, ...props }) => (\n <div\n ref={divRef}\n {...props}\n className={`container h-screen flex flex-col justify-center items-center ${className}`}\n >\n {children}\n </div>\n);\n"],"names":[],"mappings":";AAEa,MAAA,WAAoB,CAAC,EAAE,SAAS,MAAM,YAAY,IAAI,UAAU,GAAG,MAAA,MAC5E;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,KAAK;AAAA,IACJ,GAAG;AAAA,IACJ,WAAW,gEAAgE,SAAS;AAAA,IAEnF;AAAA,EAAA;AACL;"}
|