@headless-adminapp/fluent 0.0.17-alpha.18 → 0.0.17-alpha.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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FormValidationStringSet } from '@headless-adminapp/app/form';
|
|
1
2
|
import { PromptDialogOptions } from '@headless-adminapp/core/experience/dialog';
|
|
2
3
|
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
4
|
import * as yup from 'yup';
|
|
@@ -14,12 +15,12 @@ interface PromptDialogProps<SA extends SchemaAttributes = SchemaAttributes> {
|
|
|
14
15
|
onDismiss?: PromptDialogOptions<SA>['onDismiss'];
|
|
15
16
|
}
|
|
16
17
|
export declare function PromptDialog(props: PromptDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
-
export declare const formValidator: (<A extends SchemaAttributes = SchemaAttributes>(attributes: A) => (values: Record<string, any>, context: any, options: any) => Promise<import("react-hook-form").ResolverResult<{
|
|
18
|
+
export declare const formValidator: (<A extends SchemaAttributes = SchemaAttributes>(attributes: A, language: string, strings: FormValidationStringSet) => (values: Record<string, any>, context: any, options: any) => Promise<import("react-hook-form").ResolverResult<{
|
|
18
19
|
[x: string]: any;
|
|
19
20
|
[x: number]: any;
|
|
20
21
|
[x: symbol]: any;
|
|
21
22
|
}>>) & import("lodash").MemoizedFunction;
|
|
22
|
-
export declare const generateValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>(attributes: A) => yup.ObjectSchema<{
|
|
23
|
+
export declare const generateValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>(attributes: A, language: string, strings: FormValidationStringSet) => yup.ObjectSchema<{
|
|
23
24
|
[x: string]: any;
|
|
24
25
|
}, yup.AnyObject, {
|
|
25
26
|
[x: string]: any;
|
|
@@ -37,6 +37,8 @@ exports.PromptDialog = PromptDialog;
|
|
|
37
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
38
|
const react_components_1 = require("@fluentui/react-components");
|
|
39
39
|
const utils_1 = require("@headless-adminapp/app/dataform/utils");
|
|
40
|
+
const form_1 = require("@headless-adminapp/app/form");
|
|
41
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
40
42
|
const yup_1 = require("@hookform/resolvers/yup");
|
|
41
43
|
const lodash_1 = require("lodash");
|
|
42
44
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -45,11 +47,13 @@ const SectionControl_1 = require("../DataForm/SectionControl");
|
|
|
45
47
|
const StandardControl_1 = require("../PageEntityForm/StandardControl");
|
|
46
48
|
function PromptDialog(props) {
|
|
47
49
|
var _a, _b;
|
|
50
|
+
const { language } = (0, locale_1.useLocale)();
|
|
51
|
+
const formValidationStrings = (0, form_1.useFormValidationStrings)();
|
|
48
52
|
const form = (0, react_hook_form_1.useForm)({
|
|
49
53
|
mode: 'all',
|
|
50
54
|
defaultValues: props.defaultValues,
|
|
51
55
|
shouldUnregister: false,
|
|
52
|
-
resolver: (0, exports.formValidator)(props.attributes),
|
|
56
|
+
resolver: (0, exports.formValidator)(props.attributes, language, formValidationStrings),
|
|
53
57
|
});
|
|
54
58
|
return ((0, jsx_runtime_1.jsx)(react_components_1.Dialog, { open: props.open, onOpenChange: () => {
|
|
55
59
|
var _a;
|
|
@@ -80,19 +84,19 @@ function PromptDialog(props) {
|
|
|
80
84
|
}))();
|
|
81
85
|
}), children: (_b = props.confirmText) !== null && _b !== void 0 ? _b : 'Confirm' })] })] }) }) }));
|
|
82
86
|
}
|
|
83
|
-
exports.formValidator = (0, lodash_1.memoize)(function formValidator(attributes) {
|
|
87
|
+
exports.formValidator = (0, lodash_1.memoize)(function formValidator(attributes, language, strings) {
|
|
84
88
|
return (values, context, options) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const validator = (0, exports.generateValidationSchema)(attributes);
|
|
89
|
+
const validator = (0, exports.generateValidationSchema)(attributes, language, strings);
|
|
86
90
|
const resolver = (0, yup_1.yupResolver)(validator);
|
|
87
91
|
const result = yield resolver(values, context, options);
|
|
88
92
|
return result;
|
|
89
93
|
});
|
|
90
94
|
}, (attributes) => JSON.stringify({ attributes }));
|
|
91
|
-
exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValidationSchema(attributes) {
|
|
95
|
+
exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValidationSchema(attributes, language, strings) {
|
|
92
96
|
const columns = Object.keys(attributes);
|
|
93
97
|
return yup.object().shape(Object.assign({}, columns.reduce((acc, column) => {
|
|
94
98
|
const attribute = attributes[column];
|
|
95
|
-
const validationSchema = (0, utils_1.generateAttributeValidationSchema)(attribute,
|
|
99
|
+
const validationSchema = (0, utils_1.generateAttributeValidationSchema)(attribute, language, strings);
|
|
96
100
|
return Object.assign(Object.assign({}, acc), { [column]: validationSchema });
|
|
97
101
|
}, {})));
|
|
98
102
|
}, (attributes) => JSON.stringify({ attributes }));
|
|
@@ -9,6 +9,7 @@ const hooks_1 = require("@headless-adminapp/app/metadata/hooks");
|
|
|
9
9
|
const transport_1 = require("@headless-adminapp/app/transport");
|
|
10
10
|
const react_1 = require("react");
|
|
11
11
|
const componentStore_1 = require("../componentStore");
|
|
12
|
+
const AttachmentsControl_1 = require("../form/controls/AttachmentsControl");
|
|
12
13
|
const CurrencyControl_1 = require("../form/controls/CurrencyControl");
|
|
13
14
|
const DateControl_1 = require("../form/controls/DateControl");
|
|
14
15
|
const DateRangeControl_1 = require("../form/controls/DateRangeControl");
|
|
@@ -24,7 +25,7 @@ const TelephoneControl_1 = require("../form/controls/TelephoneControl");
|
|
|
24
25
|
const TextAreaControl_1 = require("../form/controls/TextAreaControl");
|
|
25
26
|
const TextControl_1 = require("../form/controls/TextControl");
|
|
26
27
|
const StandardControl = (props) => {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
28
29
|
const { attribute, label: _label, isError,
|
|
29
30
|
// errorMessage,
|
|
30
31
|
name, value, onBlur, onChange,
|
|
@@ -142,6 +143,10 @@ const StandardControl = (props) => {
|
|
|
142
143
|
const Control = (_r = componentStore_1.componentStore.getComponent('Form.MultiSelectControl')) !== null && _r !== void 0 ? _r : MultiSelectControl_1.default;
|
|
143
144
|
return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, options: attribute.options, placeholder: placeholder, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly }));
|
|
144
145
|
}
|
|
146
|
+
case 'attachments': {
|
|
147
|
+
const Control = (_s = componentStore_1.componentStore.getComponent('Form.AttachmentsControl')) !== null && _s !== void 0 ? _s : AttachmentsControl_1.AttachmentsControl;
|
|
148
|
+
return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, placeholder: placeholder, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly }));
|
|
149
|
+
}
|
|
145
150
|
// case 'attachment': {
|
|
146
151
|
// return (
|
|
147
152
|
// <FormControl
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileObject } from '@headless-adminapp/core/attributes/AttachmentAttribute';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { ControlProps } from './types';
|
|
4
|
+
export declare function fileToObject(file: File): Promise<FileObject>;
|
|
5
|
+
export declare function dataUrlToFile(dataUrl: string, name: string): File;
|
|
6
|
+
export interface AttachmentsControlProps extends ControlProps<FileObject[]> {
|
|
7
|
+
}
|
|
8
|
+
export declare const AttachmentsControl: FC<AttachmentsControlProps>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AttachmentsControl = void 0;
|
|
13
|
+
exports.fileToObject = fileToObject;
|
|
14
|
+
exports.dataUrlToFile = dataUrlToFile;
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
17
|
+
const icons_1 = require("@headless-adminapp/icons");
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
function fileToObject(file) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const reader = new FileReader();
|
|
22
|
+
reader.onload = () => {
|
|
23
|
+
resolve({
|
|
24
|
+
name: file.name,
|
|
25
|
+
type: file.type,
|
|
26
|
+
size: file.size,
|
|
27
|
+
url: reader.result,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
reader.onerror = (error) => {
|
|
31
|
+
reject(error);
|
|
32
|
+
};
|
|
33
|
+
reader.readAsDataURL(file);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function dataUrlToFile(dataUrl, name) {
|
|
37
|
+
const byteString = atob(dataUrl.split(',')[1]);
|
|
38
|
+
const mimeString = dataUrl.split(',')[0].split(':')[1].split(';')[0];
|
|
39
|
+
const ab = new ArrayBuffer(byteString.length);
|
|
40
|
+
const ia = new Uint8Array(ab);
|
|
41
|
+
for (let i = 0; i < byteString.length; i++) {
|
|
42
|
+
ia[i] = byteString.charCodeAt(i);
|
|
43
|
+
}
|
|
44
|
+
return new File([ab], name, { type: mimeString });
|
|
45
|
+
}
|
|
46
|
+
const AttachmentsControl = ({ onChange, id, onBlur, onFocus, disabled, readOnly, value, }) => {
|
|
47
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
48
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsxs)(react_components_1.TagPicker, { appearance: "filled-darker", disabled: disabled, open: false, children: [(0, jsx_runtime_1.jsx)(react_components_1.TagPickerControl, { onFocus: onFocus, onBlur: onBlur, id: id, style: { paddingBlock: react_components_1.tokens.spacingVerticalXXS }, expandIcon: null, children: (0, jsx_runtime_1.jsxs)(react_components_1.TagGroup, { style: {
|
|
49
|
+
flexWrap: 'wrap',
|
|
50
|
+
columnGap: react_components_1.tokens.spacingHorizontalXS,
|
|
51
|
+
gap: react_components_1.tokens.spacingHorizontalXS,
|
|
52
|
+
}, children: [value === null || value === void 0 ? void 0 : value.map((file, index) => ((0, jsx_runtime_1.jsx)(react_components_1.Tag, { as: "span", appearance: "brand", size: "small", shape: "rounded",
|
|
53
|
+
// value={option}
|
|
54
|
+
dismissible: true, dismissIcon: (0, jsx_runtime_1.jsx)("div", { style: { display: 'flex', cursor: 'pointer' }, onClick: () => {
|
|
55
|
+
if (readOnly)
|
|
56
|
+
return;
|
|
57
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value === null || value === void 0 ? void 0 : value.filter((_, i) => i !== index));
|
|
58
|
+
}, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Close, { size: 16 }) }), children: (0, jsx_runtime_1.jsx)(react_components_1.Link, { href: file.url, target: "_blank", onClick: (event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
window.open(file.url, '_blank');
|
|
62
|
+
}, children: (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { overflow: 'hidden', textOverflow: 'ellipsis' }, children: file.name }) }) }, index))), (0, jsx_runtime_1.jsx)(react_components_1.Button, { size: "small", icon: (0, jsx_runtime_1.jsx)(icons_1.Icons.Add, { size: 16 }), appearance: "outline", onClick: () => {
|
|
63
|
+
var _a;
|
|
64
|
+
if (readOnly)
|
|
65
|
+
return;
|
|
66
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
67
|
+
}, children: "Add" })] }) }), (0, jsx_runtime_1.jsx)(react_components_1.TagPickerList, {})] }), (0, jsx_runtime_1.jsx)("input", { ref: inputRef, type: "file", multiple: true, style: { display: 'none' }, onChange: (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const files = event.target.files;
|
|
69
|
+
if (files === null || files === void 0 ? void 0 : files.length) {
|
|
70
|
+
const fileObjects = yield Promise.all(Array.from(files).map((file) => fileToObject(file)));
|
|
71
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([...(value !== null && value !== void 0 ? value : []), ...fileObjects]);
|
|
72
|
+
}
|
|
73
|
+
}) })] }));
|
|
74
|
+
};
|
|
75
|
+
exports.AttachmentsControl = AttachmentsControl;
|
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.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"react-hook-form": "7.52.2",
|
|
45
45
|
"yup": "^1.4.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "bcc1bcddef884731f72e5e4fedb0d78ad64afbd0"
|
|
48
48
|
}
|