@tsed/react-formio 1.10.6 → 1.10.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/react-formio",
3
- "version": "1.10.6",
3
+ "version": "1.10.10",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.modern.js",
6
6
  "source": "src/index.ts",
@@ -13,7 +13,7 @@
13
13
  "prettier": "prettier '{src,test}/**/*.{ts,tsx}' --write"
14
14
  },
15
15
  "dependencies": {
16
- "@tsed/redux-utils": "1.10.6",
16
+ "@tsed/redux-utils": "1.10.10",
17
17
  "eventemitter2": "^6.4.3",
18
18
  "prop-types": "^15.7.2"
19
19
  },
@@ -28,8 +28,9 @@
28
28
  "tooltip.js": "^1.3.3"
29
29
  },
30
30
  "devDependencies": {
31
- "@tsed/tailwind": "1.10.6",
32
- "@tsed/tailwind-formio": "1.10.6"
31
+ "@tsed/tailwind": "1.10.10",
32
+ "@tsed/tailwind-formio": "1.10.10",
33
+ "eslint-plugin-jsx-a11y": "^6.5.1"
33
34
  },
34
35
  "repository": "https://github.com/TypedProject/tsed-formio",
35
36
  "bugs": {
@@ -6,8 +6,8 @@ describe("Card", () => {
6
6
  it("should render the card component", () => {
7
7
  const { getByRole } = render(<Sandbox {...Sandbox.args} />);
8
8
 
9
- const title = getByRole("card-heading");
10
- const body = getByRole("card-body");
9
+ const title = getByRole("heading");
10
+ const body = getByRole("article");
11
11
 
12
12
  expect(title).toHaveTextContent("label");
13
13
  expect(body).toHaveTextContent("test");
@@ -14,11 +14,9 @@ export function Card({
14
14
  return (
15
15
  <div className={classnames("card", className)}>
16
16
  <div className={"card-header "}>
17
- <h4 className={"card-title"} role={"card-heading"}>
18
- {label}
19
- </h4>
17
+ <h4 className={"card-title"}>{label}</h4>
20
18
  </div>
21
- <div className={"card-body"} role={"card-body"}>
19
+ <div className={"card-body"} role={"article"}>
22
20
  {children}
23
21
  </div>
24
22
  </div>
@@ -95,6 +95,17 @@ export const useForm = (props: any): any => {
95
95
  }
96
96
  }, [src]);
97
97
 
98
+ useEffect(() => {
99
+ if (form) {
100
+ createWebForm(form, options);
101
+ }
102
+
103
+ return () => {
104
+ isLoaded.current = false;
105
+ instance.current && instance.current.destroy(true);
106
+ };
107
+ }, []);
108
+
98
109
  useEffect(() => {
99
110
  props.onSubmit && events.current.set("onSubmit", props.onSubmit);
100
111
  }, [props.onSubmit, events]);
@@ -1,3 +1,5 @@
1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
1
3
  import { ComponentSchema } from "formiojs";
2
4
  import AllComponents from "formiojs/components";
3
5
  import Components from "formiojs/components/Components";
@@ -32,7 +32,7 @@ export function FormsCell(
32
32
  </span>
33
33
 
34
34
  {(form.tags || []).map((tag, index) => (
35
- <span
35
+ <button
36
36
  key={index}
37
37
  className='badge badge-hover bg-secondary mr-1'
38
38
  onClick={stopPropagationWrapper(() => {
@@ -42,7 +42,7 @@ export function FormsCell(
42
42
  >
43
43
  <i className={classnames(iconClass(undefined, "tags"), "mr-1")} />
44
44
  {tag}
45
- </span>
45
+ </button>
46
46
  ))}
47
47
  </li>
48
48
  </ul>
@@ -16,7 +16,7 @@ describe("Modal", () => {
16
16
  expect(queryByTestId("modalBody")).toBeFalsy();
17
17
  expect(queryByTestId("modalFooter")).toBeFalsy();
18
18
 
19
- fireEvent.click(screen.getByRole("openModal"));
19
+ fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
20
20
 
21
21
  await waitFor(() => getByTestId("modalTitle"));
22
22
 
@@ -45,7 +45,7 @@ describe("Modal", () => {
45
45
  expect(queryByTestId("modalBody")).toBeFalsy();
46
46
  expect(queryByTestId("modalFooter")).toBeFalsy();
47
47
 
48
- fireEvent.click(getByRole("openModal"));
48
+ fireEvent.click(getByRole("button", { name: "Open modal" }));
49
49
 
50
50
  await waitFor(() => getByTestId("modalTitle"));
51
51
 
@@ -67,7 +67,7 @@ describe("Modal", () => {
67
67
  <WithFooter {...WithFooter.args} onSubmit={onSubmit} />
68
68
  );
69
69
 
70
- fireEvent.click(getByRole("openModal"));
70
+ fireEvent.click(getByRole("button", { name: "Open modal" }));
71
71
 
72
72
  await waitFor(() => getByTestId("modalTitle"));
73
73
 
@@ -1,3 +1,5 @@
1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
1
3
  import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
2
4
  import noop from "lodash";
3
5
 
@@ -61,7 +63,10 @@ export function Modal({
61
63
  }
62
64
 
63
65
  return (
64
- <div className={`formio-dialog formio-dialog-theme-default ${className}`}>
66
+ <div
67
+ role={"dialog"}
68
+ className={`formio-dialog formio-dialog-theme-default ${className}`}
69
+ >
65
70
  <div className='formio-dialog-overlay' onClick={onClickClose} />
66
71
  <div style={style} className={"formio-dialog-content"}>
67
72
  <div className={"formio-dialog-wrapper"}>
@@ -26,11 +26,7 @@ export const Sandbox = (args: ModalProps) => {
26
26
  return (
27
27
  <div>
28
28
  <div>
29
- <button
30
- role={"openModal"}
31
- className={"btn btn-primary"}
32
- onClick={modal.openModal}
33
- >
29
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
34
30
  Open modal
35
31
  </button>
36
32
  </div>
@@ -51,11 +47,7 @@ export const WithTitle = (args: ModalProps) => {
51
47
  return (
52
48
  <div>
53
49
  <div>
54
- <button
55
- role={"openModal"}
56
- className={"btn btn-primary"}
57
- onClick={modal.openModal}
58
- >
50
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
59
51
  Open modal
60
52
  </button>
61
53
  </div>
@@ -103,11 +95,7 @@ export const WithFooter = (args: ModalProps) => {
103
95
  return (
104
96
  <div>
105
97
  <div>
106
- <button
107
- className={"btn btn-primary"}
108
- role={"openModal"}
109
- onClick={modal.openModal}
110
- >
98
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
111
99
  Open modal
112
100
  </button>
113
101
  </div>
@@ -185,12 +173,8 @@ export const WithRemoveModal = (args: RemoveModalProps) => {
185
173
  return (
186
174
  <div>
187
175
  <div>
188
- <button
189
- className={"btn btn-primary"}
190
- role={"openModal"}
191
- onClick={modal.openModal}
192
- >
193
- Open
176
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
177
+ Open modal
194
178
  </button>
195
179
  </div>
196
180
  <RemoveModal
@@ -1,6 +1,6 @@
1
1
  import classnames from "classnames";
2
2
  import noop from "lodash/noop";
3
- import React, { useState } from "react";
3
+ import React, { PropsWithChildren, useState } from "react";
4
4
  import { iconClass } from "../../utils/iconClass";
5
5
  import { InputText } from "../input-text/inputText.component";
6
6
  import { Modal, ModalProps } from "./modal.component";
@@ -10,7 +10,7 @@ function RemoveModalFooter({
10
10
  valueToCompare,
11
11
  onSubmit,
12
12
  onClose,
13
- i18n = noop
13
+ i18n = (f: string) => f
14
14
  }: ModalProps) {
15
15
  return (
16
16
  <div className={"flex items-center justify-center bg-white p-2"}>
@@ -42,22 +42,29 @@ export interface RemoveModalProps extends ModalProps {
42
42
  valueToCompare: string;
43
43
  itemType?: string;
44
44
  i18n?: (f: string) => string;
45
+ maxWidth?: string;
45
46
  }
46
47
 
47
- export function RemoveModal(props: RemoveModalProps) {
48
+ export function RemoveModal({
49
+ maxWidth = "300px",
50
+ children,
51
+ ...props
52
+ }: PropsWithChildren<RemoveModalProps>) {
48
53
  const { i18n = noop } = props;
49
54
  const [value, setValue] = useState();
50
55
 
51
56
  return (
52
57
  <Modal
53
58
  {...props}
54
- style={{ maxWidth: "300px" }}
59
+ className={classnames(props.className, "formio-dialog-theme-remove")}
60
+ style={{ maxWidth }}
55
61
  title={`Drop ${props.itemType?.toLowerCase()}`}
56
62
  value={value}
57
63
  footer={RemoveModalFooter}
58
64
  >
59
65
  <div className={"px-4 pt-3 pb-5"}>
60
66
  <div className={"pb-1"}>
67
+ {children}
61
68
  {i18n("To drop")} <strong>{props.valueToCompare}</strong>,&nbsp;
62
69
  {i18n("type the")}&nbsp;
63
70
  <strong>&quot;{props.itemType?.toLowerCase()}&quot;</strong>&nbsp;
@@ -106,6 +106,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
106
106
  */
107
107
  // eslint-disable-next-line @typescript-eslint/no-empty-function
108
108
  attachReact(element?: any) {
109
+ // eslint-disable-next-line react/no-render-return-value
109
110
  return ReactDOM.render(this.renderReact(), element);
110
111
  }
111
112
 
@@ -1,6 +1,9 @@
1
1
  import React from "react";
2
2
 
3
- export function Cell({ value, render = (f: any) => f }: any): JSX.Element {
3
+ export function DefaultCell({
4
+ value,
5
+ render = (f: any) => f
6
+ }: any): JSX.Element {
4
7
  if (value === undefined) {
5
8
  return <></>;
6
9
  }
@@ -30,7 +30,7 @@ export function DefaultOperationButton(props: OperationButtonProps) {
30
30
  } = props;
31
31
 
32
32
  return (
33
- <span
33
+ <button
34
34
  className={classnames(
35
35
  className,
36
36
  ["btn", buttonOutline && "outline", buttonType]
@@ -48,6 +48,6 @@ export function DefaultOperationButton(props: OperationButtonProps) {
48
48
  {title && (
49
49
  <span className={icon && title ? "ml-1" : ""}>{i18n(title)}</span>
50
50
  )}
51
- </span>
51
+ </button>
52
52
  );
53
53
  }
@@ -1,6 +1,6 @@
1
1
  export * from "./utils/useOperations.hook";
2
- export * from "./components/cell.component";
3
2
  export * from "./components/defaultArrowSort.component";
3
+ export * from "./components/defaultCell.component";
4
4
  export * from "./components/defaultCellHeader.component";
5
5
  export * from "./components/defaultCellHeader.component";
6
6
  export * from "./components/defaultCellOperations.component";
@@ -215,10 +215,14 @@ export function Table<Data extends object = any>(
215
215
  /* style={{ marginBottom: disablePagination ? "-1px" : "0px" }} */
216
216
  >
217
217
  <thead>
218
- {tableInstance.headerGroups.map((headerGroup) => (
219
- <tr {...headerGroup.getHeaderGroupProps()}>
218
+ {tableInstance.headerGroups.map((headerGroup, i) => (
219
+ <tr
220
+ key={`tableInstance.headerGroups${i}`}
221
+ {...headerGroup.getHeaderGroupProps()}
222
+ >
220
223
  {headerGroup.headers.map((column) => (
221
224
  <th
225
+ key={`tableInstance.headers.column.${column.id}`}
222
226
  /* className='text-left py-2 align-top' */
223
227
  {...column.getHeaderProps()}
224
228
  >
@@ -230,20 +234,27 @@ export function Table<Data extends object = any>(
230
234
  </thead>
231
235
  {!isLoading ? (
232
236
  <tbody {...tableInstance.getTableBodyProps()}>
233
- {tableInstance.page.map((row, i) => {
237
+ {tableInstance.page.map((row) => {
234
238
  tableInstance.prepareRow(row);
235
239
  return (
236
240
  <tr
241
+ key={`tableInstance.page.${row.id}`}
237
242
  onClick={() => _onClick(row.original, "row")}
238
243
  {...row.getRowProps()}
239
244
  >
240
- {row.cells.map((cell) => {
245
+ {row.cells.map((cell, i) => {
241
246
  const { hidden, colspan } = cell.column as any;
242
247
  if (hidden) {
243
248
  return null;
244
249
  }
245
250
  return (
246
- <td colSpan={colspan} {...cell.getCellProps()}>
251
+ <td
252
+ key={`tableInstance.page.cells.${
253
+ cell.value || "value"
254
+ }.${i}`}
255
+ colSpan={colspan}
256
+ {...cell.getCellProps()}
257
+ >
247
258
  {cell.render("Cell")}
248
259
  </td>
249
260
  );
@@ -1,9 +1,9 @@
1
+ import React from "react";
1
2
  import { Components, ExtendedComponentSchema } from "formiojs";
2
3
  import FormioUtils from "formiojs/utils";
3
- import React from "react";
4
4
  import { Column } from "react-table";
5
5
  import { FormSchema } from "../../../interfaces";
6
- import { Cell } from "../components/cell.component";
6
+ import { DefaultCell } from "../components/defaultCell.component";
7
7
  import { SelectColumnFilter } from "../filters/selectColumnFilter.component";
8
8
 
9
9
  export function mapFormToColumns(form: FormSchema): Column[] {
@@ -19,7 +19,10 @@ export function mapFormToColumns(form: FormSchema): Column[] {
19
19
  Header: component.label || component.title || component.key,
20
20
  accessor: `data.${component.key}`,
21
21
  Cell: (props: any) => (
22
- <Cell {...props} render={(value: any) => cmp.asString(value)} />
22
+ <DefaultCell
23
+ {...props}
24
+ render={(value: any) => cmp.asString(value)}
25
+ />
23
26
  )
24
27
  };
25
28
 
@@ -87,7 +87,7 @@ Sandbox.args = {
87
87
  function AddButton({ onCreate }: any) {
88
88
  return (
89
89
  <div>
90
- <div onClick={onCreate}>+</div>
90
+ <button onClick={onCreate}>+</button>
91
91
  </div>
92
92
  );
93
93
  }
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function Cell({ value, render }: any): JSX.Element;