@headless-adminapp/fluent 0.0.17-alpha.57 → 0.0.17-alpha.59
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.
|
@@ -13,6 +13,7 @@ const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
|
13
13
|
const hooks_4 = require("@headless-adminapp/app/recordset/hooks");
|
|
14
14
|
const hooks_5 = require("@headless-adminapp/app/route/hooks");
|
|
15
15
|
const utils_1 = require("@headless-adminapp/app/utils");
|
|
16
|
+
const phone_1 = require("@headless-adminapp/app/utils/phone");
|
|
16
17
|
const app_1 = require("@headless-adminapp/core/experience/app");
|
|
17
18
|
const react_table_1 = require("@tanstack/react-table");
|
|
18
19
|
const react_1 = require("react");
|
|
@@ -264,6 +265,7 @@ function renderCellContent({ info, column, schema, schemaStore, locale, routeRes
|
|
|
264
265
|
currencyDisplay: currency.currencyDisplay,
|
|
265
266
|
currencySign: currency.currencySign,
|
|
266
267
|
locale: locale.locale,
|
|
268
|
+
region: locale.region,
|
|
267
269
|
}) ?? '';
|
|
268
270
|
if (column.plainText) {
|
|
269
271
|
return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize() }, column.id));
|
|
@@ -311,6 +313,18 @@ function renderCellContent({ info, column, schema, schemaStore, locale, routeRes
|
|
|
311
313
|
case 'choice':
|
|
312
314
|
return ((0, jsx_runtime_1.jsx)(TableCellChoice_1.TableCellChoice, { column: column, schema: schema, record: info.row.original, value: value, attribute: attribute, formattedValue: formattedValue, width: info.column.getSize() }));
|
|
313
315
|
}
|
|
316
|
+
if (attribute.type === 'string' && attribute.format === 'phone') {
|
|
317
|
+
const parsedNumber = (0, phone_1.parsePhoneNumber)(value, locale.region);
|
|
318
|
+
if (parsedNumber.isValid && parsedNumber.uri) {
|
|
319
|
+
return ((0, jsx_runtime_1.jsx)(TableCellLink_1.TableCellLink, { value: formattedValue, width: info.column.getSize(), href: parsedNumber.uri }, column.id));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (attribute.type === 'string' &&
|
|
323
|
+
attribute.format === 'email' &&
|
|
324
|
+
value &&
|
|
325
|
+
typeof value === 'string') {
|
|
326
|
+
return ((0, jsx_runtime_1.jsx)(TableCellLink_1.TableCellLink, { value: formattedValue, width: info.column.getSize(), href: `mailto:${value}` }, column.id));
|
|
327
|
+
}
|
|
314
328
|
return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize() }, column.id));
|
|
315
329
|
}
|
|
316
330
|
function renderPrimaryAttribute({ info, column, schema, routeResolver, openRecord, value, }) {
|
|
@@ -15,12 +15,22 @@ interface PromptDialogProps<SA extends SchemaAttributes = SchemaAttributes> {
|
|
|
15
15
|
onDismiss?: PromptDialogOptions<SA>['onDismiss'];
|
|
16
16
|
}
|
|
17
17
|
export declare function PromptDialog(props: PromptDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
-
export declare const formValidator: (<A extends SchemaAttributes = SchemaAttributes>(attributes
|
|
18
|
+
export declare const formValidator: (<A extends SchemaAttributes = SchemaAttributes>({ attributes, language, strings, region, }: {
|
|
19
|
+
attributes: A;
|
|
20
|
+
language: string;
|
|
21
|
+
strings: FormValidationStringSet;
|
|
22
|
+
region: string;
|
|
23
|
+
}) => (values: Record<string, any>, context: any, options: any) => Promise<import("react-hook-form").ResolverResult<{
|
|
19
24
|
[x: string]: any;
|
|
20
25
|
[x: number]: any;
|
|
21
26
|
[x: symbol]: any;
|
|
22
27
|
}>>) & import("lodash").MemoizedFunction;
|
|
23
|
-
export declare const generateValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>(attributes
|
|
28
|
+
export declare const generateValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>({ attributes, language, strings, region, }: {
|
|
29
|
+
attributes: A;
|
|
30
|
+
language: string;
|
|
31
|
+
strings: FormValidationStringSet;
|
|
32
|
+
region: string;
|
|
33
|
+
}) => yup.ObjectSchema<{
|
|
24
34
|
[x: string]: any;
|
|
25
35
|
}, yup.AnyObject, {
|
|
26
36
|
[x: string]: any;
|
|
@@ -37,13 +37,18 @@ const yup = __importStar(require("yup"));
|
|
|
37
37
|
const SectionControl_1 = require("../DataForm/SectionControl");
|
|
38
38
|
const StandardControl_1 = require("../PageEntityForm/StandardControl");
|
|
39
39
|
function PromptDialog(props) {
|
|
40
|
-
const { language } = (0, locale_1.useLocale)();
|
|
40
|
+
const { language, region } = (0, locale_1.useLocale)();
|
|
41
41
|
const formValidationStrings = (0, form_1.useFormValidationStrings)();
|
|
42
42
|
const form = (0, react_hook_form_1.useForm)({
|
|
43
43
|
mode: 'all',
|
|
44
44
|
defaultValues: props.defaultValues,
|
|
45
45
|
shouldUnregister: false,
|
|
46
|
-
resolver: (0, exports.formValidator)(
|
|
46
|
+
resolver: (0, exports.formValidator)({
|
|
47
|
+
attributes: props.attributes,
|
|
48
|
+
language,
|
|
49
|
+
strings: formValidationStrings,
|
|
50
|
+
region,
|
|
51
|
+
}),
|
|
47
52
|
});
|
|
48
53
|
return ((0, jsx_runtime_1.jsx)(react_components_1.Dialog, { open: props.open, onOpenChange: () => {
|
|
49
54
|
props.onDismiss?.();
|
|
@@ -70,24 +75,29 @@ function PromptDialog(props) {
|
|
|
70
75
|
})();
|
|
71
76
|
}, children: props.confirmText ?? 'Confirm' })] })] }) }) }));
|
|
72
77
|
}
|
|
73
|
-
exports.formValidator = (0, lodash_1.memoize)(function formValidator(attributes, language, strings) {
|
|
78
|
+
exports.formValidator = (0, lodash_1.memoize)(function formValidator({ attributes, language, strings, region, }) {
|
|
74
79
|
return async (values, context, options) => {
|
|
75
|
-
const validator = (0, exports.generateValidationSchema)(
|
|
80
|
+
const validator = (0, exports.generateValidationSchema)({
|
|
81
|
+
attributes,
|
|
82
|
+
language,
|
|
83
|
+
strings,
|
|
84
|
+
region,
|
|
85
|
+
});
|
|
76
86
|
const resolver = (0, yup_1.yupResolver)(validator);
|
|
77
87
|
const result = await resolver(values, context, options);
|
|
78
88
|
return result;
|
|
79
89
|
};
|
|
80
|
-
}, (
|
|
81
|
-
exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValidationSchema(attributes, language, strings) {
|
|
90
|
+
}, (options) => JSON.stringify(options));
|
|
91
|
+
exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValidationSchema({ attributes, language, strings, region, }) {
|
|
82
92
|
const columns = Object.keys(attributes);
|
|
83
93
|
return yup.object().shape({
|
|
84
94
|
...columns.reduce((acc, column) => {
|
|
85
95
|
const attribute = attributes[column];
|
|
86
|
-
const validationSchema = (0, utils_1.generateAttributeValidationSchema)(attribute, language, strings);
|
|
96
|
+
const validationSchema = (0, utils_1.generateAttributeValidationSchema)(attribute, language, strings, region);
|
|
87
97
|
return {
|
|
88
98
|
...acc,
|
|
89
99
|
[column]: validationSchema,
|
|
90
100
|
};
|
|
91
101
|
}, {}),
|
|
92
102
|
});
|
|
93
|
-
}, (
|
|
103
|
+
}, (options) => JSON.stringify(options));
|
|
@@ -2,4 +2,4 @@ import { ControlProps } from './types';
|
|
|
2
2
|
export interface TelephoneControlProps extends ControlProps<string> {
|
|
3
3
|
autoComplete?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function TelephoneControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, readOnly, autoComplete, }: TelephoneControlProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function TelephoneControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, readOnly, autoComplete, }: Readonly<TelephoneControlProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,14 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TelephoneControl = TelephoneControl;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
7
|
+
const phone_1 = require("@headless-adminapp/app/utils/phone");
|
|
6
8
|
const icons_1 = require("@headless-adminapp/icons");
|
|
9
|
+
const react_1 = require("react");
|
|
7
10
|
function TelephoneControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, readOnly, autoComplete, }) {
|
|
8
|
-
|
|
11
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)('');
|
|
12
|
+
const { region } = (0, locale_1.useLocale)();
|
|
13
|
+
const number = (0, react_1.useMemo)(() => {
|
|
14
|
+
if (!value) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return (0, phone_1.parsePhoneNumber)(value, region);
|
|
18
|
+
}, [value, region]);
|
|
19
|
+
(0, react_1.useEffect)(() => {
|
|
20
|
+
setInternalValue(number?.formattedInternationalValue ?? '');
|
|
21
|
+
}, [number]);
|
|
22
|
+
const handleChange = () => {
|
|
23
|
+
const parsedPhoneNumber = (0, phone_1.parsePhoneNumber)(internalValue, region);
|
|
24
|
+
setInternalValue(parsedPhoneNumber.formattedInternationalValue);
|
|
25
|
+
onChange?.(parsedPhoneNumber.rawValue);
|
|
26
|
+
};
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { type: "tel", placeholder: placeholder, id: id, appearance: "filled-darker", name: name, value: internalValue, onChange: (e) => setInternalValue?.(e.target.value), onBlur: () => {
|
|
28
|
+
handleChange();
|
|
29
|
+
onBlur?.();
|
|
30
|
+
}, onFocus: () => onFocus?.(),
|
|
9
31
|
// invalid={error}
|
|
10
32
|
readOnly: disabled || readOnly, autoComplete: autoComplete, style: {
|
|
11
33
|
width: '100%',
|
|
12
34
|
paddingRight: react_components_1.tokens.spacingHorizontalXS,
|
|
13
35
|
},
|
|
14
36
|
// size="sm"
|
|
15
|
-
contentAfter: !!
|
|
37
|
+
contentAfter: !!number?.uri ? ((0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "transparent", size: "small", onClick: () => window.open(number.uri, '_blank'), title: number.uri, icon: (0, jsx_runtime_1.jsx)(icons_1.Icons.Phone, {}) })) : undefined }));
|
|
16
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/fluent",
|
|
3
|
-
"version": "0.0.17-alpha.
|
|
3
|
+
"version": "0.0.17-alpha.59",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"uuid": "11.0.3",
|
|
43
43
|
"yup": "^1.4.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "813d07729a10a5613b46f012ba4b24bcaab384dc"
|
|
46
46
|
}
|