@tsed/react-formio 2.3.1 → 2.3.3
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/coverage.json +4 -4
- package/dist/components/actions-table/actionsTable.stories.d.ts +8 -53
- package/dist/components/form-access/formAccess.component.d.ts +2 -13
- package/dist/components/form-access/formAccess.stories.d.ts +3 -44
- package/dist/components/form-control/formControl.component.d.ts +3 -11
- package/dist/components/react-component/reactComponent.component.d.ts +1 -1
- package/dist/components/select/select.component.d.ts +5 -18
- package/dist/components/table/components/defaultCellOperations.component.d.ts +12 -1
- package/dist/components/table/components/defaultOperationButton.component.d.ts +4 -4
- package/dist/components/table/hooks/useOperations.hook.d.ts +2 -2
- package/dist/index.js +1184 -1334
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +300 -316
- package/dist/index.modern.js.map +1 -1
- package/package.json +13 -9
- package/src/components/__fixtures__/form-actions.json +240 -0
- package/src/components/actions-table/__fixtures__/data.json +12 -0
- package/src/components/actions-table/actionsTable.component.spec.tsx +44 -13
- package/src/components/actions-table/actionsTable.component.tsx +2 -1
- package/src/components/actions-table/actionsTable.stories.tsx +71 -289
- package/src/components/form/form.stories.tsx +1 -2
- package/src/components/form-access/formAccess.component.tsx +2 -13
- package/src/components/form-access/formAccess.stories.tsx +55 -49
- package/src/components/form-action/formAction.component.tsx +1 -0
- package/src/components/form-control/formControl.component.tsx +3 -10
- package/src/components/form-edit/formEdit.reducer.ts +0 -1
- package/src/components/form-settings/formSettings.component.spec.tsx +4 -4
- package/src/components/pagination/pagination.component.spec.tsx +0 -2
- package/src/components/react-component/reactComponent.component.tsx +5 -5
- package/src/components/select/select.component.tsx +10 -23
- package/src/components/table/components/defaultCellOperations.component.tsx +17 -4
- package/src/components/table/components/defaultOperationButton.component.tsx +11 -4
- package/src/components/table/components/defaultRow.component.tsx +1 -0
- package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
- package/src/components/table/hooks/useOperations.hook.tsx +3 -3
- package/src/react-table.d.ts +2 -0
- package/dist/package.json +0 -3
|
@@ -15,7 +15,6 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
15
15
|
* @param options - Any options passed into the renderer.
|
|
16
16
|
* @param data - The submission data where this component's data exists.
|
|
17
17
|
*/
|
|
18
|
-
// eslint-disable-next-line no-useless-constructor,import/no-anonymous-default-export
|
|
19
18
|
constructor(component: ComponentSchema, options: any, data: Submission<Data>) {
|
|
20
19
|
super(component, options, data);
|
|
21
20
|
}
|
|
@@ -105,18 +104,19 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
105
104
|
*
|
|
106
105
|
* @param element
|
|
107
106
|
*/
|
|
108
|
-
|
|
107
|
+
|
|
109
108
|
attachReact(element?: any) {
|
|
110
|
-
// eslint-disable-next-line react/no-render-return-value
|
|
109
|
+
// eslint-disable-next-line react/no-render-return-value,react/no-deprecated
|
|
111
110
|
return ReactDOM.render(this.renderReact(), element);
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
* Override this function.
|
|
116
115
|
*/
|
|
117
|
-
|
|
116
|
+
|
|
118
117
|
detachReact(element?: any) {
|
|
119
118
|
if (element) {
|
|
119
|
+
// eslint-disable-next-line react/no-deprecated
|
|
120
120
|
ReactDOM.unmountComponentAtNode(element);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -127,7 +127,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
127
127
|
* @param value
|
|
128
128
|
* @param flags
|
|
129
129
|
*/
|
|
130
|
-
setValue(value: any
|
|
130
|
+
setValue(value: any) {
|
|
131
131
|
if (this.reactInstance) {
|
|
132
132
|
this.reactInstance.setState({
|
|
133
133
|
value: value
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import Choices from "@formio/choices.js";
|
|
2
2
|
import classnames from "classnames";
|
|
3
|
-
import
|
|
4
|
-
import React, { ReactElement, useEffect, useRef } from "react";
|
|
3
|
+
import React, { HTMLAttributes, ReactElement, useEffect, useRef } from "react";
|
|
5
4
|
|
|
6
5
|
import { getEventValue } from "../../utils/getEventValue";
|
|
7
6
|
import { FormControl, FormControlProps } from "../form-control/formControl.component";
|
|
8
7
|
|
|
9
|
-
export interface SelectProps<
|
|
10
|
-
value?: any;
|
|
8
|
+
export interface SelectProps<Data = any> extends FormControlProps, Omit<HTMLAttributes<HTMLSelectElement>, "onChange" | "prefix"> {
|
|
11
9
|
size?: string;
|
|
12
|
-
onChange?: (name: string, value: any) => void;
|
|
13
10
|
placeholder?: string;
|
|
14
|
-
choices: { label: string; value:
|
|
11
|
+
choices: { label: string; value: Data }[];
|
|
15
12
|
layout?: "html5" | "choicesjs";
|
|
13
|
+
disabled?: boolean;
|
|
16
14
|
multiple?: boolean;
|
|
17
|
-
|
|
18
|
-
[key: string]: any;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
export function Select<
|
|
17
|
+
export function Select<Data = any>({
|
|
22
18
|
name,
|
|
23
19
|
label,
|
|
24
20
|
size,
|
|
@@ -33,14 +29,14 @@ export function Select<T = any>({
|
|
|
33
29
|
multiple,
|
|
34
30
|
layout,
|
|
35
31
|
...props
|
|
36
|
-
}: SelectProps<
|
|
37
|
-
const ref = useRef<
|
|
32
|
+
}: SelectProps<Data>): ReactElement {
|
|
33
|
+
const ref = useRef<HTMLSelectElement>(null);
|
|
38
34
|
|
|
39
35
|
useEffect(() => {
|
|
40
36
|
let instance: any;
|
|
41
37
|
|
|
42
38
|
if (layout === "choicesjs") {
|
|
43
|
-
instance = new Choices(ref.current, {
|
|
39
|
+
instance = new Choices(ref.current as unknown as HTMLInputElement, {
|
|
44
40
|
removeItemButton: true,
|
|
45
41
|
placeholderValue: placeholder
|
|
46
42
|
});
|
|
@@ -64,11 +60,11 @@ export function Select<T = any>({
|
|
|
64
60
|
|
|
65
61
|
return (
|
|
66
62
|
<FormControl name={name} label={label} required={required} description={description} prefix={prefix} suffix={suffix} shadow={false}>
|
|
67
|
-
{
|
|
63
|
+
{}
|
|
68
64
|
<select
|
|
69
65
|
ref={ref}
|
|
70
|
-
{...props}
|
|
71
66
|
data-testid={`select_${name}`}
|
|
67
|
+
{...props}
|
|
72
68
|
className={classnames("form-control", size && `form-control-${size}`)}
|
|
73
69
|
name={name}
|
|
74
70
|
id={name}
|
|
@@ -90,12 +86,3 @@ export function Select<T = any>({
|
|
|
90
86
|
</FormControl>
|
|
91
87
|
);
|
|
92
88
|
}
|
|
93
|
-
|
|
94
|
-
Select.propTypes = {
|
|
95
|
-
label: PropTypes.string,
|
|
96
|
-
name: PropTypes.string.isRequired,
|
|
97
|
-
value: PropTypes.any,
|
|
98
|
-
required: PropTypes.bool,
|
|
99
|
-
onChange: PropTypes.func,
|
|
100
|
-
choices: PropTypes.array.isRequired
|
|
101
|
-
};
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import { DefaultOperationButton } from "./defaultOperationButton.component";
|
|
3
|
+
import { DefaultOperationButton, OperationButtonProps } from "./defaultOperationButton.component";
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export interface DefaultCellOperationsProps {
|
|
6
|
+
operations: (OperationButtonProps & {
|
|
7
|
+
OperationButton: typeof DefaultOperationButton;
|
|
8
|
+
permissionsResolver?(data: unknown, ctx: any): boolean;
|
|
9
|
+
})[];
|
|
10
|
+
row: any;
|
|
11
|
+
|
|
12
|
+
onClick: (data: any, action: string) => void;
|
|
13
|
+
ctx: any;
|
|
14
|
+
i18n: (i18n: string) => string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function DefaultCellOperations({ operations, row, onClick, ctx, i18n }: DefaultCellOperationsProps) {
|
|
6
18
|
const data = row.original;
|
|
7
19
|
|
|
8
20
|
return (
|
|
9
21
|
<div className='btn-group'>
|
|
10
22
|
{operations
|
|
11
|
-
.filter(({ permissionsResolver }
|
|
12
|
-
.map(({ OperationButton = DefaultOperationButton, ...operation }:
|
|
23
|
+
.filter(({ permissionsResolver }) => !permissionsResolver || permissionsResolver(data, ctx))
|
|
24
|
+
.map(({ OperationButton = DefaultOperationButton, ...operation }, index: number) => {
|
|
13
25
|
return (
|
|
14
26
|
<OperationButton
|
|
15
27
|
key={operation.action}
|
|
16
28
|
{...operation}
|
|
29
|
+
data-testid={`operation-${index}-${operation.action}`}
|
|
17
30
|
onClick={(action: string) => onClick(data, action)}
|
|
18
31
|
data={data}
|
|
19
32
|
i18n={i18n}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import classnames from "classnames";
|
|
2
|
-
import
|
|
2
|
+
import { HTMLAttributes } from "react";
|
|
3
3
|
|
|
4
4
|
import { iconClass } from "../../../utils/iconClass";
|
|
5
5
|
import { stopPropagationWrapper } from "../../../utils/stopPropagationWrapper";
|
|
6
6
|
|
|
7
|
-
export interface OperationButtonProps {
|
|
8
|
-
className?: string;
|
|
7
|
+
export interface OperationButtonProps extends Omit<HTMLAttributes<HTMLButtonElement>, "onClick"> {
|
|
9
8
|
buttonType?: string;
|
|
10
9
|
buttonSize?: string;
|
|
11
10
|
buttonOutline?: boolean;
|
|
@@ -15,6 +14,7 @@ export interface OperationButtonProps {
|
|
|
15
14
|
icon?: string;
|
|
16
15
|
title?: string;
|
|
17
16
|
i18n?: (i18n: string) => string;
|
|
17
|
+
ctx?: any;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function DefaultOperationButton(props: OperationButtonProps) {
|
|
@@ -27,11 +27,18 @@ export function DefaultOperationButton(props: OperationButtonProps) {
|
|
|
27
27
|
action,
|
|
28
28
|
icon = "",
|
|
29
29
|
title = "",
|
|
30
|
-
i18n = (f: string) => f
|
|
30
|
+
i18n = (f: string) => f,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
|
+
data,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
ctx,
|
|
35
|
+
...otherProps
|
|
31
36
|
} = props;
|
|
32
37
|
|
|
33
38
|
return (
|
|
34
39
|
<button
|
|
40
|
+
{...otherProps}
|
|
41
|
+
aria-label={"Operation button: " + (title || action)}
|
|
35
42
|
className={classnames(className, ["btn", buttonOutline && "outline", buttonType].filter(Boolean).join("-"), `btn-${buttonSize}`)}
|
|
36
43
|
onClick={stopPropagationWrapper(() => onClick(action))}
|
|
37
44
|
>
|
|
@@ -21,6 +21,7 @@ export function DefaultDndRow<Data extends object = {}>(props: DefaultRowProps<D
|
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<tr ref={dropRef} style={{ opacity }}>
|
|
24
|
+
{/* eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role */}
|
|
24
25
|
<td ref={dragRef} role='cell' style={{ cursor: isDragging ? "grabbing" : "grab" }} className='align-middle'>
|
|
25
26
|
<div className='flex items-center justify-center'>
|
|
26
27
|
<i className={classnames(iconClass(undefined, "dots-vertical-rounded"))} />
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { type ComponentType, type FunctionComponent } from "react";
|
|
2
2
|
import { Hooks } from "react-table";
|
|
3
3
|
|
|
4
4
|
import { Operation } from "../../../interfaces";
|
|
5
5
|
import { DefaultCellOperations } from "../components/defaultCellOperations.component";
|
|
6
6
|
|
|
7
7
|
export type UseOperationsHookProps = {
|
|
8
|
-
CellOperations?:
|
|
8
|
+
CellOperations?: FunctionComponent | ComponentType<{}>;
|
|
9
9
|
operations: Operation[];
|
|
10
10
|
onClick?: (data: any, event: string) => void;
|
|
11
11
|
i18n?: (f: string) => string;
|
|
@@ -14,7 +14,7 @@ export type UseOperationsHookProps = {
|
|
|
14
14
|
|
|
15
15
|
export function useOperations<D extends object = {}>({
|
|
16
16
|
operations,
|
|
17
|
-
CellOperations = DefaultCellOperations,
|
|
17
|
+
CellOperations = DefaultCellOperations as FunctionComponent,
|
|
18
18
|
onClick,
|
|
19
19
|
i18n = (f: string) => f,
|
|
20
20
|
ctx
|
package/src/react-table.d.ts
CHANGED
|
@@ -45,10 +45,12 @@ import {
|
|
|
45
45
|
} from "react-table";
|
|
46
46
|
|
|
47
47
|
declare module "react-table" {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
49
|
export interface UseFlexLayoutInstanceProps<D extends Record<string, unknown>> {
|
|
49
50
|
totalColumnsMinWidth: number;
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
54
|
export interface UseFlexLayoutColumnProps<D extends Record<string, unknown>> {
|
|
53
55
|
totalMinWidth: number;
|
|
54
56
|
}
|
package/dist/package.json
DELETED