@owlmeans/client-panel 0.1.0 → 0.1.2
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/LICENSE +1 -1
- package/build/components/context.d.ts.map +1 -1
- package/build/components/form/action.d.ts +4 -0
- package/build/components/form/action.d.ts.map +1 -0
- package/build/components/form/action.js +36 -0
- package/build/components/form/action.js.map +1 -0
- package/build/components/form/component.d.ts +4 -0
- package/build/components/form/component.d.ts.map +1 -0
- package/build/components/form/component.js +44 -0
- package/build/components/form/component.js.map +1 -0
- package/build/components/form/context.d.ts.map +1 -1
- package/build/components/form/helper.d.ts +1 -1
- package/build/components/form/helper.d.ts.map +1 -1
- package/build/components/form/helper.js.map +1 -1
- package/build/components/form/index.d.ts +4 -1
- package/build/components/form/index.d.ts.map +1 -1
- package/build/components/form/index.js +3 -1
- package/build/components/form/index.js.map +1 -1
- package/build/components/form/input/controller.d.ts +4 -0
- package/build/components/form/input/controller.d.ts.map +1 -0
- package/build/components/form/input/controller.js +33 -0
- package/build/components/form/input/controller.js.map +1 -0
- package/build/components/form/input/index.d.ts +3 -0
- package/build/components/form/input/index.d.ts.map +1 -0
- package/build/components/form/input/index.js +2 -0
- package/build/components/form/input/index.js.map +1 -0
- package/build/components/form/input/types.d.ts +24 -0
- package/build/components/form/input/types.d.ts.map +1 -0
- package/build/components/form/input/types.js +2 -0
- package/build/components/form/input/types.js.map +1 -0
- package/build/components/form/types.d.ts +20 -1
- package/build/components/form/types.d.ts.map +1 -1
- package/build/components/index.d.ts +1 -0
- package/build/components/index.d.ts.map +1 -1
- package/build/components/index.js +1 -0
- package/build/components/index.js.map +1 -1
- package/build/components/layout/helper.d.ts +1 -1
- package/build/components/layout/helper.d.ts.map +1 -1
- package/build/components/layout/helper.js +1 -2
- package/build/components/layout/helper.js.map +1 -1
- package/build/components/status.d.ts +7 -0
- package/build/components/status.d.ts.map +1 -0
- package/build/components/status.js +18 -0
- package/build/components/status.js.map +1 -0
- package/build/components/types.d.ts +7 -0
- package/build/components/types.d.ts.map +1 -1
- package/build/helper/form.d.ts.map +1 -1
- package/package.json +17 -16
- package/src/components/form/action.tsx +46 -0
- package/src/components/form/component.tsx +63 -0
- package/src/components/form/helper.ts +1 -1
- package/src/components/form/index.ts +5 -2
- package/src/components/form/input/controller.tsx +34 -0
- package/src/components/form/input/index.ts +3 -0
- package/src/components/form/input/types.ts +28 -0
- package/src/components/form/types.ts +22 -1
- package/src/components/index.ts +1 -0
- package/src/components/layout/helper.ts +2 -3
- package/src/components/status.ts +23 -0
- package/src/components/types.ts +8 -0
- package/tsconfig.tsbuildinfo +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 OwlMeans Common — Fullstack typescript framework
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/components/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,SAAS,EAA6B,MAAM,uBAAuB,CAAA;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAIhD,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,aAAa,CAK1C,CAAA;AAED,eAAO,MAAM,cAAc,qBAAsD,CAAA;AAEjF,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/components/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,SAAS,EAA6B,MAAM,uBAAuB,CAAA;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAIhD,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,aAAa,CAK1C,CAAA;AAED,eAAO,MAAM,cAAc,qBAAsD,CAAA;AAEjF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,WAAW,SAAS,CAAC,MAAM,CAAC,0DAUvE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,QAAQ,cAAc,uBAajE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/components/form/action.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAI/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAmC1C,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import { useClientFormContext, useFormI18n } from "./context.js";
|
|
4
|
+
import { useContext } from "@owlmeans/client";
|
|
5
|
+
// import { usePanelHelper } from "../context.js"
|
|
6
|
+
// import { useCommonI18n, useI18nApp, useI18nLib } from "@owlmeans/client-i18n"
|
|
7
|
+
import { useI18nApp, useI18nLib } from "@owlmeans/client-i18n";
|
|
8
|
+
export const ActionCtrl = ({ render, label, i18n, size, onClick, submit }) => {
|
|
9
|
+
const form = useFormContext();
|
|
10
|
+
const client = useClientFormContext();
|
|
11
|
+
const context = useContext();
|
|
12
|
+
// const panel = usePanelHelper()
|
|
13
|
+
/*const t = useCommonI18n(
|
|
14
|
+
i18n?.resource ?? panel.resource ?? context.cfg.service,
|
|
15
|
+
i18n?.ns ?? panel.ns,
|
|
16
|
+
i18n?.prefix ?? panel.prefix
|
|
17
|
+
)*/
|
|
18
|
+
const t = useFormI18n();
|
|
19
|
+
const appT = useI18nApp(context.cfg.service, 'buttons');
|
|
20
|
+
const libT = useI18nLib('client-panel', 'buttons');
|
|
21
|
+
label = useMemo(() => i18n?.suppress ? label : t(label ?? 'submit', {
|
|
22
|
+
defaultValue: appT(label ?? 'submit', { defaultValue: libT(label ?? 'submit') })
|
|
23
|
+
}), [i18n?.suppress, label]);
|
|
24
|
+
size = size ?? 'medium';
|
|
25
|
+
const progressSize = size === 'large'
|
|
26
|
+
? 20
|
|
27
|
+
: size === 'medium' ? 16 : 14;
|
|
28
|
+
submit = onClick != null ? undefined : (submit ?? client.onSubmit);
|
|
29
|
+
const action = onClick ?? submit != null
|
|
30
|
+
? form.handleSubmit(async (data) => submit?.(data, client.formRef?.current?.update))
|
|
31
|
+
: undefined;
|
|
32
|
+
const update = client.formRef?.current?.update;
|
|
33
|
+
const loading = client.loader.opened === true;
|
|
34
|
+
return render({ form, client, label, size, progressSize, action, update, loading, t });
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../../src/components/form/action.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,iDAAiD;AACjD,gFAAgF;AAChF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAE9D,MAAM,CAAC,MAAM,UAAU,GAAwB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,O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AM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAClF,CAAC,CAAC,SAAS,CAAA;IAEb,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAO,CAAA;IAE/C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,IAAI,CAAA;IAE7C,OAAO,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;AACxF,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/components/form/component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAe3C,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,SAAS,CA6CpC,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import Ajv from "ajv";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { schemaToFormDefault } from "../../helper/form.js";
|
|
6
|
+
import { FormProvider, useForm } from 'react-hook-form';
|
|
7
|
+
import { ajvResolver } from '@hookform/resolvers/ajv';
|
|
8
|
+
import { FormContext } from "./context.js";
|
|
9
|
+
import { useToggle } from "@owlmeans/client";
|
|
10
|
+
import formatsPlugin from 'ajv-formats';
|
|
11
|
+
import { ResilientError } from "@owlmeans/error";
|
|
12
|
+
const ajv = new Ajv({ coerceTypes: true });
|
|
13
|
+
formatsPlugin(ajv);
|
|
14
|
+
export const ClientForm = (props) => {
|
|
15
|
+
const { defaults, children, formRef, validation, name } = props;
|
|
16
|
+
const _defaults = useMemo(() => defaults ?? (validation != null ? schemaToFormDefault(validation) : undefined), [name, defaults != null, validation != null]);
|
|
17
|
+
const loader = useToggle(false);
|
|
18
|
+
const form = useForm({
|
|
19
|
+
mode: 'all',
|
|
20
|
+
defaultValues: _defaults,
|
|
21
|
+
resolver: validation
|
|
22
|
+
? ajvResolver(validation, { formats: ajv.formats, coerceTypes: true })
|
|
23
|
+
: undefined,
|
|
24
|
+
delayError: 300
|
|
25
|
+
});
|
|
26
|
+
const update = useCallback(((data) => {
|
|
27
|
+
const fields = validation != null
|
|
28
|
+
? Object.keys(validation.properties)
|
|
29
|
+
: Object.keys(data);
|
|
30
|
+
fields.forEach(key => {
|
|
31
|
+
form.setValue(key, data[key]);
|
|
32
|
+
});
|
|
33
|
+
}), [name]);
|
|
34
|
+
const setError = useCallback((error, target = 'root') => {
|
|
35
|
+
form.setError(target, {
|
|
36
|
+
message: ResilientError.ensure(error instanceof Error ? error : `${error}`).marshal().message
|
|
37
|
+
});
|
|
38
|
+
}, [name]);
|
|
39
|
+
if (formRef != null) {
|
|
40
|
+
formRef.current = { form, update, loader, error: setError };
|
|
41
|
+
}
|
|
42
|
+
return _jsx(FormProvider, { ...form, children: _jsx(FormContext, { ...props, loader: loader, children: children }) });
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/components/form/component.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGnC,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,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W,EAAE,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,CACa,CAAA;AAEzE,eAAO,MAAM,oBAAoB,oBAAoD,CAAA;AAErF,eAAO,MAAM,WAAW,6DASvB,CAAA;AAED,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/components/form/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAGlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAI9C,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,CACa,CAAA;AAEzE,eAAO,MAAM,oBAAoB,oBAAoD,CAAA;AAErF,eAAO,MAAM,WAAW,6DASvB,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,QAAQ,UAAU,uBAa5D,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FieldValues } from 'react-hook-form';
|
|
2
2
|
import type { FormRef } from './types.js';
|
|
3
|
-
export declare const useFormRef: <T extends FieldValues = FieldValues>() => import("react").
|
|
3
|
+
export declare const useFormRef: <T extends FieldValues = FieldValues>() => import("react").RefObject<FormRef<T> | null>;
|
|
4
4
|
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/form/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,WAAW,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/form/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,WAAW,GAAG,WAAW,mDAE7D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/components/form/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAI9B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAwC,EAAE;IAClE,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/components/form/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAI9B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAwC,EAAE;IAClE,OAAO,MAAM,CAAa,IAAI,CAAC,CAAA;AACjC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/form/index.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/form/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/form/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/form/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/components/form/input/controller.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKtD,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,oBAAoB,CA2B9C,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useFormContext, Controller } from 'react-hook-form';
|
|
3
|
+
import { useClientFormContext, useFormError, useFormI18n } from "../context.js";
|
|
4
|
+
export const InputCtrl = (props) => {
|
|
5
|
+
let { name, label, placeholder, hint, def, render, ...other } = props;
|
|
6
|
+
const { control } = useFormContext();
|
|
7
|
+
const t = useFormI18n();
|
|
8
|
+
const key = name;
|
|
9
|
+
if (typeof label === 'boolean' && label) {
|
|
10
|
+
label = t(`${key}.label`);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
label = undefined;
|
|
14
|
+
}
|
|
15
|
+
if (typeof placeholder === 'boolean' && placeholder) {
|
|
16
|
+
placeholder = t(`${key}.placeholder`);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
placeholder = undefined;
|
|
20
|
+
}
|
|
21
|
+
if (typeof hint === 'boolean' && hint) {
|
|
22
|
+
hint = t(`${key}.hint`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
hint = undefined;
|
|
26
|
+
}
|
|
27
|
+
return _jsx(Controller, { control: control, name: name, defaultValue: def, render: ({ field, fieldState }) => {
|
|
28
|
+
const form = useClientFormContext();
|
|
29
|
+
const error = useFormError(name, fieldState.error);
|
|
30
|
+
return render({ ...other, ...form, field, fieldState, label, placeholder, hint, error, t });
|
|
31
|
+
} });
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/components/form/input/controller.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE/E,MAAM,CAAC,MAAM,SAAS,GAA6B,CAAC,KAAK,EAAE,EAAE;IAC3D,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,EAAC,GAAG,KAAK,CAAA;IACpE,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,CAAC,GAAG,WAAW,EAAE,CAAA;IACvB,MAAM,GAAG,GAAG,IAAI,CAAA;IAChB,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC;QACxC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAA;IAC3B,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,SAAS,CAAA;IACnB,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,SAAS,IAAI,WAAW,EAAE,CAAC;QACpD,WAAW,GAAG,CAAC,CAAC,GAAG,GAAG,cAAc,CAAC,CAAA;IACvC,CAAC;SAAM,CAAC;QACN,WAAW,GAAG,SAAS,CAAA;IACzB,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,EAAE,CAAC;QACtC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,OAAO,CAAC,CAAA;IACzB,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,KAAC,UAAU,IAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE;YACpG,MAAM,IAAI,GAAG,oBAAoB,EAAE,CAAA;YACnC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;YAElD,OAAO,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;QAC7F,CAAC,GAAI,CAAA;AACP,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/form/input/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/form/input/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HTMLInputTypeAttribute, ReactElement } from 'react';
|
|
2
|
+
import type { FormFieldProps, TFormContext } from '../types.js';
|
|
3
|
+
import type { ControllerFieldState, ControllerRenderProps, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { TFunction } from "i18next";
|
|
5
|
+
export interface InputControllerProps extends FormFieldProps {
|
|
6
|
+
name: string;
|
|
7
|
+
label?: string | boolean;
|
|
8
|
+
placeholder?: string | boolean;
|
|
9
|
+
hint?: string | boolean;
|
|
10
|
+
type?: HTMLInputTypeAttribute;
|
|
11
|
+
disableAutocomplete?: boolean;
|
|
12
|
+
render: InputControllerRenderer;
|
|
13
|
+
}
|
|
14
|
+
export interface InputControllerRenderer<T extends FieldValues = FieldValues> {
|
|
15
|
+
(args: InputControllerRendererArgs<T>): ReactElement;
|
|
16
|
+
}
|
|
17
|
+
export interface InputControllerRendererArgs<T extends FieldValues = FieldValues> extends TFormContext, Omit<InputControllerProps, "name" | "render"> {
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
field: ControllerRenderProps<T>;
|
|
20
|
+
fieldState: ControllerFieldState;
|
|
21
|
+
t: TFunction;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/form/input/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB,IAAI,CAAC,EAAE,sBAAsB,CAAA;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,MAAM,EAAE,uBAAuB,CAAA;CAChC;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC1E,CAAC,IAAI,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,YAAY,CAAA;CACrD;AAED,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,CAC9E,SAAQ,YAAY,EACpB,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAC/B,UAAU,EAAE,oBAAoB,CAAA;IAChC,CAAC,EAAE,SAAS,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/form/input/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AnySchema } from 'ajv';
|
|
2
|
-
import type { PropsWithChildren, MutableRefObject } from 'react';
|
|
2
|
+
import type { PropsWithChildren, ReactNode, MutableRefObject } from 'react';
|
|
3
3
|
import type { UseFormReturn, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { I18nProps } from '@owlmeans/client-i18n';
|
|
5
5
|
import type { Toggleable } from '@owlmeans/client';
|
|
6
6
|
import type { BlockScaling } from '../consts.js';
|
|
7
|
+
import type { TFunction } from 'i18next';
|
|
7
8
|
export interface FormProps extends PropsWithChildren<I18nProps> {
|
|
8
9
|
name?: string;
|
|
9
10
|
formRef?: MutableRefObject<FormRef<any> | null>;
|
|
@@ -30,4 +31,22 @@ export interface FormFieldProps {
|
|
|
30
31
|
name: string;
|
|
31
32
|
def?: any;
|
|
32
33
|
}
|
|
34
|
+
export interface FormActionProps<T extends FieldValues = FieldValues> extends I18nProps {
|
|
35
|
+
label?: string;
|
|
36
|
+
size?: 'small' | 'medium' | 'large';
|
|
37
|
+
render: (args: FormActionRenderArgs<T>) => ReactNode;
|
|
38
|
+
onClick?: () => void;
|
|
39
|
+
submit?: FormOnSubmit<T>;
|
|
40
|
+
}
|
|
41
|
+
export interface FormActionRenderArgs<T extends FieldValues = FieldValues> {
|
|
42
|
+
label: string;
|
|
43
|
+
size: 'small' | 'medium' | 'large';
|
|
44
|
+
progressSize: number;
|
|
45
|
+
form: UseFormReturn<T>;
|
|
46
|
+
client: TFormContext;
|
|
47
|
+
action?: () => void;
|
|
48
|
+
loading: boolean;
|
|
49
|
+
t: TFunction;
|
|
50
|
+
update: (data: T) => void;
|
|
51
|
+
}
|
|
33
52
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/form/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/form/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,WAAW,SAAU,SAAQ,iBAAiB,CAAC,SAAS,CAAC;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CA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Y,CAAC,CAAC,CAAC,CAAA;CACzB;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IAClC,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IACtB,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,CAAC,EAAE,SAAS,CAAA;IACZ,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClientModule } from '@owlmeans/client-module';
|
|
2
2
|
import type { AbstractRequest } from '@owlmeans/module';
|
|
3
|
-
export declare const usePanelLayout: <T = {}, R extends AbstractRequest = AbstractRequest
|
|
3
|
+
export declare const usePanelLayout: <T = {}, R extends AbstractRequest = AbstractRequest>() => ClientModule<T, R>;
|
|
4
4
|
export declare const useLayoutTitle: (name?: string, alias?: string) => string;
|
|
5
5
|
export declare const prepareLayoutTitle: (title: string) => string;
|
|
6
6
|
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/layout/helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/layout/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAOvD,eAAO,MAAM,cAAc,GAAI,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,OAAK,YAAY,CAAC,CAAC,EAAE,CAAC,CAKvG,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,MAM9D,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,WAA0C,CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { useLocation } from 'react-router';
|
|
2
1
|
import { useContext } from '@owlmeans/client';
|
|
3
2
|
import { usePanelI18n } from '../context.js';
|
|
4
3
|
import { useMemo } from 'react';
|
|
5
4
|
export const usePanelLayout = () => {
|
|
6
5
|
const context = useContext();
|
|
7
|
-
const location = useLocation();
|
|
6
|
+
const location = context.router().useLocation();
|
|
8
7
|
return context.module(location.state.alias);
|
|
9
8
|
};
|
|
10
9
|
export const useLayoutTitle = (name, alias) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/components/layout/helper.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/components/layout/helper.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,MAAM,CAAC,MAAM,cAAc,GAAG,GAA4E,EAAE;IAC1G,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAA0B,OAAO,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAA;IAEtE,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAa,EAAE,KAAc,EAAU,EAAE;IACtE,MAAM,MAAM,GAAG,cAAc,EAAE,CAAA;IAC/B,MAAM,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAC5B,KAAK,GAAG,KAAK,IAAI,MAAM,CAAC,KAAK,CAAA;IAE7B,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;AACxE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/components/status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAM/C,eAAO,MAAM,gBAAgB,GAAI,6CAA6C,aAAa;;;;CAe1F,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { usePanelI18n } from "./context";
|
|
3
|
+
import { ResilientError } from "@owlmeans/error";
|
|
4
|
+
const prepareMessage = (msg) => msg.replace(/\:/g, '.');
|
|
5
|
+
export const useStatusMessage = ({ variant, name, ok, i18n, message, error }) => {
|
|
6
|
+
ok = ok !== false;
|
|
7
|
+
variant = useMemo(() => variant ?? (ok ? 'success' : 'error'), [ok, variant]);
|
|
8
|
+
const t = usePanelI18n(name ?? variant, i18n);
|
|
9
|
+
message = useMemo(() => {
|
|
10
|
+
const resilient = error != null ? ResilientError.ensure(error) : null;
|
|
11
|
+
return message != null ? t(message) : resilient != null ? t([
|
|
12
|
+
`${resilient.type}.${prepareMessage(resilient.message)}`,
|
|
13
|
+
prepareMessage(resilient.message)
|
|
14
|
+
]) : t(variant);
|
|
15
|
+
}, [message, error?.name, ok, variant]);
|
|
16
|
+
return { message, variant, ok };
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/components/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,C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{
|
|
5
5
|
loader?: Toggleable;
|
|
6
6
|
}
|
|
7
|
+
export interface StatusOptions extends I18nProps {
|
|
8
|
+
name?: string;
|
|
9
|
+
ok?: boolean;
|
|
10
|
+
variant?: string;
|
|
11
|
+
error?: Error;
|
|
12
|
+
message?: string;
|
|
13
|
+
}
|
|
7
14
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE9C,MAAM,WAAW,aAAc,SAAQ,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzE,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE9C,MAAM,WAAW,aAAc,SAAQ,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzE,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB;AAED,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/helper/form.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,KAAK,CAAA;AAEpD,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/helper/form.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,KAAK,CAAA;AAEpD,eAAO,MAAM,mBAAmB,GAAI,QAAQ,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAGzE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/client-panel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"build": "tsc -b",
|
|
@@ -34,21 +35,22 @@
|
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@owlmeans/client
|
|
39
|
-
"@owlmeans/client-
|
|
40
|
-
"@owlmeans/client-
|
|
41
|
-
"@owlmeans/
|
|
42
|
-
"@owlmeans/
|
|
38
|
+
"@hookform/resolvers": "^3.9.0",
|
|
39
|
+
"@owlmeans/client": "^0.1.2",
|
|
40
|
+
"@owlmeans/client-i18n": "^0.1.2",
|
|
41
|
+
"@owlmeans/client-module": "^0.1.2",
|
|
42
|
+
"@owlmeans/client-route": "^0.1.2",
|
|
43
|
+
"@owlmeans/error": "^0.1.2",
|
|
44
|
+
"@owlmeans/module": "^0.1.2"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"@owlmeans/auth": "*",
|
|
46
48
|
"@owlmeans/client-auth": "*",
|
|
47
49
|
"@owlmeans/i18n": "*",
|
|
50
|
+
"@owlmeans/router": "*",
|
|
48
51
|
"ajv": "*",
|
|
49
52
|
"react": "*",
|
|
50
|
-
"react-hook-form": "*"
|
|
51
|
-
"react-router": "*"
|
|
53
|
+
"react-hook-form": "*"
|
|
52
54
|
},
|
|
53
55
|
"peerDependenciesMeta": {
|
|
54
56
|
"@owlmeans/auth": {
|
|
@@ -59,16 +61,15 @@
|
|
|
59
61
|
}
|
|
60
62
|
},
|
|
61
63
|
"devDependencies": {
|
|
62
|
-
"@owlmeans/auth": "^0.1.
|
|
63
|
-
"@owlmeans/client-auth": "^0.1.
|
|
64
|
-
"@types/react": "^
|
|
65
|
-
"nodemon": "^3.1.
|
|
64
|
+
"@owlmeans/auth": "^0.1.2",
|
|
65
|
+
"@owlmeans/client-auth": "^0.1.2",
|
|
66
|
+
"@types/react": "^19.2.7",
|
|
67
|
+
"nodemon": "^3.1.11",
|
|
66
68
|
"npm-check": "^6.0.1",
|
|
67
69
|
"react-hook-form": "^7.53.0",
|
|
68
|
-
"typescript": "^5.
|
|
70
|
+
"typescript": "^5.8.3"
|
|
69
71
|
},
|
|
70
|
-
"private": false,
|
|
71
72
|
"publishConfig": {
|
|
72
73
|
"access": "public"
|
|
73
74
|
}
|
|
74
|
-
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FC } from "react"
|
|
2
|
+
import { useMemo } from "react"
|
|
3
|
+
import { useFormContext } from "react-hook-form"
|
|
4
|
+
import { useClientFormContext, useFormI18n } from "./context.js"
|
|
5
|
+
import type { FormActionProps } from "./types.js"
|
|
6
|
+
import { useContext } from "@owlmeans/client"
|
|
7
|
+
// import { usePanelHelper } from "../context.js"
|
|
8
|
+
// import { useCommonI18n, useI18nApp, useI18nLib } from "@owlmeans/client-i18n"
|
|
9
|
+
import { useI18nApp, useI18nLib } from "@owlmeans/client-i18n"
|
|
10
|
+
|
|
11
|
+
export const ActionCtrl: FC<FormActionProps> = ({ render, label, i18n, size, onClick, submit }) => {
|
|
12
|
+
const form = useFormContext()
|
|
13
|
+
const client = useClientFormContext()
|
|
14
|
+
|
|
15
|
+
const context = useContext()
|
|
16
|
+
// const panel = usePanelHelper()
|
|
17
|
+
/*const t = useCommonI18n(
|
|
18
|
+
i18n?.resource ?? panel.resource ?? context.cfg.service,
|
|
19
|
+
i18n?.ns ?? panel.ns,
|
|
20
|
+
i18n?.prefix ?? panel.prefix
|
|
21
|
+
)*/
|
|
22
|
+
const t = useFormI18n()
|
|
23
|
+
const appT = useI18nApp(context.cfg.service, 'buttons')
|
|
24
|
+
const libT = useI18nLib('client-panel', 'buttons')
|
|
25
|
+
|
|
26
|
+
label = useMemo(() => i18n?.suppress ? label : t(label ?? 'submit', {
|
|
27
|
+
defaultValue: appT(label ?? 'submit', { defaultValue: libT(label ?? 'submit') })
|
|
28
|
+
}), [i18n?.suppress, label])!
|
|
29
|
+
|
|
30
|
+
size = size ?? 'medium'
|
|
31
|
+
const progressSize = size === 'large'
|
|
32
|
+
? 20
|
|
33
|
+
: size === 'medium' ? 16 : 14
|
|
34
|
+
|
|
35
|
+
submit = onClick != null ? undefined : (submit ?? client.onSubmit)
|
|
36
|
+
|
|
37
|
+
const action = onClick ?? submit != null
|
|
38
|
+
? form.handleSubmit(async data => submit?.(data, client.formRef?.current?.update))
|
|
39
|
+
: undefined
|
|
40
|
+
|
|
41
|
+
const update = client.formRef?.current?.update!
|
|
42
|
+
|
|
43
|
+
const loading = client.loader.opened === true
|
|
44
|
+
|
|
45
|
+
return render({ form, client, label, size, progressSize, action, update, loading, t })
|
|
46
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { FC } from "react"
|
|
2
|
+
import { useCallback } from "react"
|
|
3
|
+
import type { FormProps } from "./types.js"
|
|
4
|
+
import type { JSONSchemaType } from "ajv"
|
|
5
|
+
import Ajv from "ajv"
|
|
6
|
+
import { useMemo } from "react"
|
|
7
|
+
import { schemaToFormDefault } from "../../helper/form.js"
|
|
8
|
+
import { FormProvider, useForm } from 'react-hook-form'
|
|
9
|
+
import { ajvResolver } from '@hookform/resolvers/ajv'
|
|
10
|
+
import { FormContext } from "./context.js"
|
|
11
|
+
import { useToggle } from "@owlmeans/client"
|
|
12
|
+
import formatsPlugin from 'ajv-formats'
|
|
13
|
+
import { ResilientError } from "@owlmeans/error"
|
|
14
|
+
|
|
15
|
+
const ajv = new Ajv({ coerceTypes: true })
|
|
16
|
+
formatsPlugin(ajv)
|
|
17
|
+
|
|
18
|
+
export const ClientForm: FC<FormProps> = (props) => {
|
|
19
|
+
const { defaults, children, formRef, validation, name } = props
|
|
20
|
+
|
|
21
|
+
const _defaults = useMemo(
|
|
22
|
+
() => defaults ?? (validation != null ? schemaToFormDefault(validation) : undefined),
|
|
23
|
+
[name, defaults != null, validation != null]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const loader = useToggle(false)
|
|
27
|
+
|
|
28
|
+
const form = useForm({
|
|
29
|
+
mode: 'all',
|
|
30
|
+
defaultValues: _defaults,
|
|
31
|
+
resolver: validation
|
|
32
|
+
? ajvResolver(validation as JSONSchemaType<unknown>, { formats: ajv.formats, coerceTypes: true })
|
|
33
|
+
: undefined,
|
|
34
|
+
delayError: 300
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const update = useCallback(((data: Record<string, any>) => {
|
|
38
|
+
const fields = validation != null
|
|
39
|
+
? Object.keys((validation as JSONSchemaType<any>).properties)
|
|
40
|
+
: Object.keys(data)
|
|
41
|
+
fields.forEach(key => {
|
|
42
|
+
form.setValue(key, data[key])
|
|
43
|
+
})
|
|
44
|
+
}) as <T>(data: T) => void, [name])
|
|
45
|
+
|
|
46
|
+
const setError = useCallback((error: unknown, target: string = 'root') => {
|
|
47
|
+
form.setError(target, {
|
|
48
|
+
message: ResilientError.ensure(
|
|
49
|
+
error instanceof Error ? error : `${error}`
|
|
50
|
+
).marshal().message
|
|
51
|
+
})
|
|
52
|
+
}, [name])
|
|
53
|
+
|
|
54
|
+
if (formRef != null) {
|
|
55
|
+
formRef.current = { form, update, loader, error: setError }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return <FormProvider {...form}>
|
|
59
|
+
<FormContext {...props} loader={loader}>
|
|
60
|
+
{children}
|
|
61
|
+
</FormContext>
|
|
62
|
+
</FormProvider>
|
|
63
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FC } from "react"
|
|
2
|
+
import type { InputControllerProps } from "./types.js"
|
|
3
|
+
import { useFormContext, Controller } from 'react-hook-form'
|
|
4
|
+
import { } from "react"
|
|
5
|
+
import { useClientFormContext, useFormError, useFormI18n } from "../context.js"
|
|
6
|
+
|
|
7
|
+
export const InputCtrl: FC<InputControllerProps> = (props) => {
|
|
8
|
+
let { name, label, placeholder, hint, def, render, ...other} = props
|
|
9
|
+
const { control } = useFormContext()
|
|
10
|
+
const t = useFormI18n()
|
|
11
|
+
const key = name
|
|
12
|
+
if (typeof label === 'boolean' && label) {
|
|
13
|
+
label = t(`${key}.label`)
|
|
14
|
+
} else {
|
|
15
|
+
label = undefined
|
|
16
|
+
}
|
|
17
|
+
if (typeof placeholder === 'boolean' && placeholder) {
|
|
18
|
+
placeholder = t(`${key}.placeholder`)
|
|
19
|
+
} else {
|
|
20
|
+
placeholder = undefined
|
|
21
|
+
}
|
|
22
|
+
if (typeof hint === 'boolean' && hint) {
|
|
23
|
+
hint = t(`${key}.hint`)
|
|
24
|
+
} else {
|
|
25
|
+
hint = undefined
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return <Controller control={control} name={name} defaultValue={def} render={({ field, fieldState }) => {
|
|
29
|
+
const form = useClientFormContext()
|
|
30
|
+
const error = useFormError(name, fieldState.error)
|
|
31
|
+
|
|
32
|
+
return render({ ...other, ...form, field, fieldState, label, placeholder, hint, error, t })
|
|
33
|
+
}} />
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HTMLInputTypeAttribute, ReactElement } from 'react'
|
|
2
|
+
import type { FormFieldProps, TFormContext } from '../types.js'
|
|
3
|
+
import type { ControllerFieldState, ControllerRenderProps, FieldValues } from 'react-hook-form'
|
|
4
|
+
import type { TFunction } from "i18next"
|
|
5
|
+
|
|
6
|
+
export interface InputControllerProps extends FormFieldProps {
|
|
7
|
+
name: string
|
|
8
|
+
label?: string | boolean
|
|
9
|
+
placeholder?: string | boolean
|
|
10
|
+
hint?: string | boolean
|
|
11
|
+
type?: HTMLInputTypeAttribute
|
|
12
|
+
disableAutocomplete?: boolean
|
|
13
|
+
render: InputControllerRenderer
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface InputControllerRenderer<T extends FieldValues = FieldValues> {
|
|
17
|
+
(args: InputControllerRendererArgs<T>): ReactElement
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface InputControllerRendererArgs<T extends FieldValues = FieldValues>
|
|
21
|
+
extends TFormContext,
|
|
22
|
+
Omit<InputControllerProps, "name" | "render"> {
|
|
23
|
+
placeholder?: string
|
|
24
|
+
field: ControllerRenderProps<T>
|
|
25
|
+
fieldState: ControllerFieldState
|
|
26
|
+
t: TFunction
|
|
27
|
+
error?: string
|
|
28
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AnySchema } from 'ajv'
|
|
2
|
-
import type { PropsWithChildren, MutableRefObject } from 'react'
|
|
2
|
+
import type { PropsWithChildren, ReactNode, MutableRefObject } from 'react'
|
|
3
3
|
import type { UseFormReturn, FieldValues } from 'react-hook-form'
|
|
4
4
|
import type { I18nProps } from '@owlmeans/client-i18n'
|
|
5
5
|
import type { Toggleable } from '@owlmeans/client'
|
|
6
6
|
import type { BlockScaling } from '../consts.js'
|
|
7
|
+
import type { TFunction } from 'i18next'
|
|
7
8
|
|
|
8
9
|
export interface FormProps extends PropsWithChildren<I18nProps> {
|
|
9
10
|
name?: string
|
|
@@ -35,3 +36,23 @@ export interface FormFieldProps {
|
|
|
35
36
|
name: string
|
|
36
37
|
def?: any
|
|
37
38
|
}
|
|
39
|
+
|
|
40
|
+
export interface FormActionProps<T extends FieldValues = FieldValues> extends I18nProps {
|
|
41
|
+
label?: string
|
|
42
|
+
size?: 'small' | 'medium' | 'large'
|
|
43
|
+
render: (args: FormActionRenderArgs<T>) => ReactNode
|
|
44
|
+
onClick?: () => void
|
|
45
|
+
submit?: FormOnSubmit<T>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface FormActionRenderArgs<T extends FieldValues = FieldValues> {
|
|
49
|
+
label: string
|
|
50
|
+
size: 'small' | 'medium' | 'large'
|
|
51
|
+
progressSize: number
|
|
52
|
+
form: UseFormReturn<T>
|
|
53
|
+
client: TFormContext
|
|
54
|
+
action?: () => void
|
|
55
|
+
loading: boolean
|
|
56
|
+
t: TFunction
|
|
57
|
+
update: (data: T) => void
|
|
58
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import type { ClientRoute } from '@owlmeans/client-route'
|
|
2
|
-
import type { Location } from 'react-router'
|
|
3
2
|
import type { ClientModule } from '@owlmeans/client-module'
|
|
4
3
|
import type { AbstractRequest } from '@owlmeans/module'
|
|
4
|
+
import type { Location } from '@owlmeans/router'
|
|
5
5
|
|
|
6
|
-
import { useLocation } from 'react-router'
|
|
7
6
|
import { useContext } from '@owlmeans/client'
|
|
8
7
|
import { usePanelI18n } from '../context.js'
|
|
9
8
|
import { useMemo } from 'react'
|
|
10
9
|
|
|
11
10
|
export const usePanelLayout = <T = {}, R extends AbstractRequest = AbstractRequest>(): ClientModule<T, R> => {
|
|
12
11
|
const context = useContext()
|
|
13
|
-
const location: Location<ClientRoute> = useLocation()
|
|
12
|
+
const location: Location<ClientRoute> = context.router().useLocation()
|
|
14
13
|
|
|
15
14
|
return context.module(location.state.alias)
|
|
16
15
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useMemo } from "react"
|
|
2
|
+
import type { StatusOptions } from "./types.js"
|
|
3
|
+
import { usePanelI18n } from "./context"
|
|
4
|
+
import { ResilientError } from "@owlmeans/error"
|
|
5
|
+
|
|
6
|
+
const prepareMessage = (msg: string) => msg.replace(/\:/g, '.')
|
|
7
|
+
|
|
8
|
+
export const useStatusMessage = ({ variant, name, ok, i18n, message, error }: StatusOptions) => {
|
|
9
|
+
ok = ok !== false
|
|
10
|
+
variant = useMemo(() => variant ?? (ok ? 'success' : 'error'), [ok, variant])
|
|
11
|
+
const t = usePanelI18n(name ?? variant, i18n)
|
|
12
|
+
message = useMemo(() => {
|
|
13
|
+
const resilient = error != null ? ResilientError.ensure(error) : null
|
|
14
|
+
return message != null ? t(message) : resilient != null ? t(
|
|
15
|
+
[
|
|
16
|
+
`${resilient.type}.${prepareMessage(resilient.message)}`,
|
|
17
|
+
prepareMessage(resilient.message)
|
|
18
|
+
],
|
|
19
|
+
) : t(variant)
|
|
20
|
+
}, [message, error?.name, ok, variant])
|
|
21
|
+
|
|
22
|
+
return { message, variant, ok }
|
|
23
|
+
}
|
package/src/components/types.ts
CHANGED
|
@@ -5,3 +5,11 @@ import type { PropsWithChildren } from 'react'
|
|
|
5
5
|
export interface TPanelContext extends PropsWithChildren<I18nProps["i18n"]> {
|
|
6
6
|
loader?: Toggleable
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export interface StatusOptions extends I18nProps {
|
|
10
|
+
name?: string
|
|
11
|
+
ok?: boolean
|
|
12
|
+
variant?: string
|
|
13
|
+
error?: Error
|
|
14
|
+
message?: string
|
|
15
|
+
}
|
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/auth/i18n.ts","./src/auth/index.ts","./src/auth/plugins/consts.ts","./src/auth/plugins/exports.ts","./src/auth/plugins/types.ts","./src/components/consts.ts","./src/components/context.tsx","./src/components/index.ts","./src/components/types.ts","./src/components/form/context.tsx","./src/components/form/helper.ts","./src/components/form/index.ts","./src/components/form/types.ts","./src/components/layout/helper.ts","./src/components/layout/index.ts","./src/helper/form.ts","./src/helper/index.ts"],"version":"5.6.3"}
|