@tsed/react-formio 2.2.3 → 2.3.1

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 +1,2 @@
1
+ /// <reference types="react" />
1
2
  export declare function DefaultCell({ value, render }: any): JSX.Element;
@@ -1,3 +1,11 @@
1
1
  import React from "react";
2
2
  import { FilterProps } from "react-table";
3
- export declare function SelectColumnFilter<D extends Record<string, unknown> = {}>({ column }: FilterProps<D>): React.JSX.Element;
3
+ export declare function useSelectColumnFilter<D extends Record<string, unknown> = {}>(props: FilterProps<D>): {
4
+ value: any;
5
+ onChange: (_: string, value: any) => void;
6
+ choices: {
7
+ value: string;
8
+ label: string;
9
+ }[];
10
+ };
11
+ export declare function SelectColumnFilter<D extends Record<string, unknown> = {}>(props: FilterProps<D>): React.JSX.Element;
@@ -1,10 +1,24 @@
1
1
  import React, { PropsWithChildren } from "react";
2
- import { CellProps, FilterProps, Renderer, TableOptions } from "react-table";
2
+ import { Cell, CellProps, Column, FilterProps, Renderer, TableOptions } from "react-table";
3
3
  import { OnClickOperation, Operation, QueryOptions } from "../../../interfaces";
4
4
  import { Pagination as DefaultPagination } from "../../pagination/pagination.component";
5
5
  import { DefaultCellHeaderProps } from "../components/defaultCellHeader.component";
6
6
  import { DefaultRow, DefaultRowProps } from "../components/defaultRow.component";
7
+ export interface ExtraColumnProps {
8
+ colspan?: number;
9
+ hidden?: boolean;
10
+ className?: string;
11
+ style?: React.CSSProperties;
12
+ }
13
+ export type ExtendedColumn<Data extends object = any> = Column<Data> & ExtraColumnProps;
14
+ export type ExtendedCell<Data extends object = any> = Cell<Data, any> & {
15
+ column: ExtraColumnProps;
16
+ };
7
17
  export interface TableProps<Data extends object = any> extends TableOptions<Data>, Partial<QueryOptions> {
18
+ /**
19
+ * extended columns interface
20
+ */
21
+ columns: ReadonlyArray<ExtendedColumn<Data>>;
8
22
  className?: string;
9
23
  /**
10
24
  * Call the listener when a filter / pagination / sort change.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ /// <reference types="react" />
2
3
  import { DefaultRowProps } from "../components/defaultRow.component";
3
4
  export declare function useDndRow<Data extends object = {}>({ onDrag, onDrop, index, ...props }: DefaultRowProps<Data>): {
4
5
  opacity: number;
@@ -24,7 +24,7 @@ export declare const Sandbox: {
24
24
  modified: string;
25
25
  form: string;
26
26
  }[];
27
- columns: import("react-table").Column<{}>[];
27
+ columns: import(".").ExtendedColumn<any>[];
28
28
  operations: ({
29
29
  title: string;
30
30
  action: string;
@@ -49,7 +49,7 @@ export declare const TableWithDragNDrop: {
49
49
  args: {
50
50
  enableDragNDrop: boolean;
51
51
  data: never[];
52
- columns: import("react-table").Column<{}>[];
52
+ columns: import(".").ExtendedColumn<any>[];
53
53
  operations: ({
54
54
  title: string;
55
55
  action: string;
@@ -1,3 +1,3 @@
1
- import { Column } from "react-table";
2
1
  import { FormSchema } from "../../../interfaces";
3
- export declare function mapFormToColumns(form: FormSchema): Column[];
2
+ import { ExtendedColumn } from "../hooks/useCustomTable.hook";
3
+ export declare function mapFormToColumns(form: FormSchema): ExtendedColumn[];
package/dist/index.js CHANGED
@@ -521,7 +521,10 @@ function DefaultCells(_ref) {
521
521
  }
522
522
  return /*#__PURE__*/React__default["default"].createElement("td", _extends({
523
523
  colSpan: colspan
524
- }, cell.getCellProps(), {
524
+ }, cell.getCellProps({
525
+ className: cell.column.className,
526
+ style: cell.column.style
527
+ }), {
525
528
  key: "tableInstance.page.cells." + (cell.value || "value") + "." + i
526
529
  }), cell.render("Cell"));
527
530
  }));
@@ -1306,24 +1309,24 @@ function Form(props) {
1306
1309
  Form.propTypes = {
1307
1310
  name: PropTypes__default["default"].string,
1308
1311
  className: PropTypes__default["default"].string,
1309
- /**
1310
- *
1312
+ /**
1313
+ *
1311
1314
  */
1312
1315
  src: PropTypes__default["default"].string,
1313
- /**
1314
- * url to fetch form
1316
+ /**
1317
+ * url to fetch form
1315
1318
  */
1316
1319
  url: PropTypes__default["default"].string,
1317
- /**
1318
- * Raw form object
1320
+ /**
1321
+ * Raw form object
1319
1322
  */
1320
1323
  form: PropTypes__default["default"].object,
1321
- /**
1322
- * Data submission
1324
+ /**
1325
+ * Data submission
1323
1326
  */
1324
1327
  submission: PropTypes__default["default"].object,
1325
- /**
1326
- * Configuration option
1328
+ /**
1329
+ * Configuration option
1327
1330
  */
1328
1331
  options: PropTypes__default["default"].shape({
1329
1332
  readOnly: PropTypes__default["default"].bool,
@@ -2520,35 +2523,55 @@ function FormSettings(props) {
2520
2523
  }, i18n("Save settings")));
2521
2524
  }
2522
2525
 
2523
- function SelectColumnFilter(_ref) {
2524
- var column = _ref.column;
2526
+ function useSelectColumnFilter(props) {
2527
+ var column = props.column;
2525
2528
  var id = column.id,
2526
- preFilteredRows = column.preFilteredRows,
2527
- filterValue = column.filterValue,
2528
- setFilter = column.setFilter;
2529
+ preFilteredRows = column.preFilteredRows;
2529
2530
  var customChoices = column.choices;
2530
- var choices = customChoices || [].concat(new Set(preFilteredRows.map(function (row) {
2531
- return row.values[id];
2532
- }))).filter(function (value) {
2533
- return value;
2534
- }).map(function (value) {
2535
- return {
2536
- label: value,
2537
- value: value
2538
- };
2539
- });
2540
- return /*#__PURE__*/React__default["default"].createElement(Select, {
2541
- key: "filter-" + column.id,
2542
- name: "filter-" + column.id,
2543
- size: "sm",
2531
+ var filterValue = column.filterValue,
2532
+ setFilter = column.setFilter;
2533
+ var choices = function () {
2534
+ if (customChoices) {
2535
+ if (typeof customChoices === "function") {
2536
+ return customChoices(props);
2537
+ }
2538
+ return customChoices;
2539
+ }
2540
+ return [].concat(new Set(preFilteredRows.map(function (row) {
2541
+ return row.values[id];
2542
+ }))).filter(function (value) {
2543
+ return value;
2544
+ }).map(function (value) {
2545
+ return {
2546
+ label: value,
2547
+ value: value
2548
+ };
2549
+ });
2550
+ }();
2551
+ var onChange = function onChange(_, value) {
2552
+ setFilter(value || undefined);
2553
+ };
2554
+ return {
2544
2555
  value: filterValue,
2556
+ onChange: onChange,
2545
2557
  choices: [{
2546
2558
  value: "",
2547
2559
  label: "All"
2548
- }].concat(choices),
2549
- onChange: function onChange(name, value) {
2550
- setFilter(value || undefined);
2551
- }
2560
+ }].concat(choices)
2561
+ };
2562
+ }
2563
+ function SelectColumnFilter(props) {
2564
+ var _useSelectColumnFilte = useSelectColumnFilter(props),
2565
+ value = _useSelectColumnFilte.value,
2566
+ choices = _useSelectColumnFilte.choices,
2567
+ onChange = _useSelectColumnFilte.onChange;
2568
+ return /*#__PURE__*/React__default["default"].createElement(Select, {
2569
+ key: "filter-" + props.column.id,
2570
+ name: "filter-" + props.column.id,
2571
+ size: "sm",
2572
+ value: value,
2573
+ choices: choices,
2574
+ onChange: onChange
2552
2575
  });
2553
2576
  }
2554
2577
 
@@ -7334,12 +7357,12 @@ function RemoveModal(_ref2) {
7334
7357
 
7335
7358
  var ReactComponent = /*#__PURE__*/function (_Components$component) {
7336
7359
  _inheritsLoose(ReactComponent, _Components$component);
7337
- /**
7338
- * This is the first phase of component building where the component is instantiated.
7339
- *
7340
- * @param component - The component definition created from the settings form.
7341
- * @param options - Any options passed into the renderer.
7342
- * @param data - The submission data where this component's data exists.
7360
+ /**
7361
+ * This is the first phase of component building where the component is instantiated.
7362
+ *
7363
+ * @param component - The component definition created from the settings form.
7364
+ * @param options - Any options passed into the renderer.
7365
+ * @param data - The submission data where this component's data exists.
7343
7366
  */
7344
7367
  // eslint-disable-next-line no-useless-constructor,import/no-anonymous-default-export
7345
7368
  function ReactComponent(component, options, data) {
@@ -7348,11 +7371,11 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7348
7371
  _this.reactInstance = void 0;
7349
7372
  _this.shouldSetValue = void 0;
7350
7373
  _this.dataForSetting = void 0;
7351
- /**
7352
- * The user has changed the value in the component and the value needs to be updated on the main submission object and other components notified of a change event.
7353
- *
7354
- * @param value
7355
- * @param flags
7374
+ /**
7375
+ * The user has changed the value in the component and the value needs to be updated on the main submission object and other components notified of a change event.
7376
+ *
7377
+ * @param value
7378
+ * @param flags
7356
7379
  */
7357
7380
  _this.updateValue = function (value, flags) {
7358
7381
  flags = flags || {};
@@ -7365,37 +7388,37 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7365
7388
  return _this;
7366
7389
  }
7367
7390
  var _proto = ReactComponent.prototype;
7368
- /**
7369
- * This method is called any time the component needs to be rebuilt. It is most frequently used to listen to other
7370
- * components using the this.on() function.
7391
+ /**
7392
+ * This method is called any time the component needs to be rebuilt. It is most frequently used to listen to other
7393
+ * components using the this.on() function.
7371
7394
  */
7372
7395
  _proto.init = function init() {
7373
7396
  return _Components$component.prototype.init.call(this);
7374
7397
  }
7375
- /**
7376
- * This method is called before the component is going to be destroyed, which is when the component instance is
7377
- * destroyed. This is different from detach which is when the component instance still exists but the dom instance is
7378
- * removed.
7398
+ /**
7399
+ * This method is called before the component is going to be destroyed, which is when the component instance is
7400
+ * destroyed. This is different from detach which is when the component instance still exists but the dom instance is
7401
+ * removed.
7379
7402
  */;
7380
7403
  _proto.destroy = function destroy() {
7381
7404
  return _Components$component.prototype.destroy.call(this);
7382
7405
  }
7383
- /**
7384
- * The second phase of component building where the component is rendered as an HTML string.
7385
- *
7386
- * @returns {string} - The return is the full string of the component
7406
+ /**
7407
+ * The second phase of component building where the component is rendered as an HTML string.
7408
+ *
7409
+ * @returns {string} - The return is the full string of the component
7387
7410
  */;
7388
7411
  _proto.render = function render() {
7389
7412
  // For react components, we simply render as a div which will become the react instance.
7390
7413
  // By calling super.render(string) it will wrap the component with the needed wrappers to make it a full component.
7391
7414
  return _Components$component.prototype.render.call(this, "<div ref=\"react-" + this.id + "\"></div>");
7392
7415
  }
7393
- /**
7394
- * The third phase of component building where the component has been attached to the DOM as 'element' and is ready
7395
- * to have its javascript events attached.
7396
- *
7397
- * @param element
7398
- * @returns {Promise<void>} - Return a promise that resolves when the attach is complete.
7416
+ /**
7417
+ * The third phase of component building where the component has been attached to the DOM as 'element' and is ready
7418
+ * to have its javascript events attached.
7419
+ *
7420
+ * @param element
7421
+ * @returns {Promise<void>} - Return a promise that resolves when the attach is complete.
7399
7422
  */;
7400
7423
  _proto.attach = function attach(element) {
7401
7424
  try {
@@ -7419,9 +7442,9 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7419
7442
  return Promise.reject(e);
7420
7443
  }
7421
7444
  }
7422
- /**
7423
- * The fourth phase of component building where the component is being removed from the page. This could be a redraw
7424
- * or it is being removed from the form.
7445
+ /**
7446
+ * The fourth phase of component building where the component is being removed from the page. This could be a redraw
7447
+ * or it is being removed from the form.
7425
7448
  */
7426
7449
  ;
7427
7450
  _proto.detach = function detach() {
@@ -7432,16 +7455,16 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7432
7455
  }
7433
7456
  _Components$component.prototype.detach.call(this);
7434
7457
  }
7435
- /**
7436
- * Override this function to render a react component.
7458
+ /**
7459
+ * Override this function to render a react component.
7437
7460
  */;
7438
7461
  _proto.renderReact = function renderReact() {
7439
7462
  return null;
7440
7463
  }
7441
- /**
7442
- * Override this function to insert your custom component.
7443
- *
7444
- * @param element
7464
+ /**
7465
+ * Override this function to insert your custom component.
7466
+ *
7467
+ * @param element
7445
7468
  */
7446
7469
  // eslint-disable-next-line @typescript-eslint/no-empty-function
7447
7470
  ;
@@ -7449,8 +7472,8 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7449
7472
  // eslint-disable-next-line react/no-render-return-value
7450
7473
  return ReactDOM__default["default"].render(this.renderReact(), element);
7451
7474
  }
7452
- /**
7453
- * Override this function.
7475
+ /**
7476
+ * Override this function.
7454
7477
  */
7455
7478
  // eslint-disable-next-line @typescript-eslint/no-empty-function
7456
7479
  ;
@@ -7459,11 +7482,11 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7459
7482
  ReactDOM__default["default"].unmountComponentAtNode(element);
7460
7483
  }
7461
7484
  }
7462
- /**
7463
- * Something external has set a value and our component needs to be updated to reflect that. For example, loading a submission.
7464
- *
7465
- * @param value
7466
- * @param flags
7485
+ /**
7486
+ * Something external has set a value and our component needs to be updated to reflect that. For example, loading a submission.
7487
+ *
7488
+ * @param value
7489
+ * @param flags
7467
7490
  */;
7468
7491
  _proto.setValue = function setValue(value, flags) {
7469
7492
  if (this.reactInstance) {
@@ -7477,10 +7500,10 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7477
7500
  }
7478
7501
  return false;
7479
7502
  };
7480
- /**
7481
- * Get the current value of the component. Should return the value set in the react component.
7482
- *
7483
- * @returns {*}
7503
+ /**
7504
+ * Get the current value of the component. Should return the value set in the react component.
7505
+ *
7506
+ * @returns {*}
7484
7507
  */
7485
7508
  _proto.getValue = function getValue() {
7486
7509
  if (this.reactInstance) {
@@ -7488,13 +7511,13 @@ var ReactComponent = /*#__PURE__*/function (_Components$component) {
7488
7511
  }
7489
7512
  return this.defaultValue;
7490
7513
  }
7491
- /**
7492
- * Override normal validation check to insert custom validation in react component.
7493
- *
7494
- * @param data
7495
- * @param dirty
7496
- * @param rowData
7497
- * @returns {boolean}
7514
+ /**
7515
+ * Override normal validation check to insert custom validation in react component.
7516
+ *
7517
+ * @param data
7518
+ * @param dirty
7519
+ * @param rowData
7520
+ * @returns {boolean}
7498
7521
  */;
7499
7522
  _proto.checkValidity = function checkValidity(data, dirty, rowData) {
7500
7523
  var valid = _Components$component.prototype.checkValidity.call(this, data, dirty, rowData);
@@ -7545,6 +7568,7 @@ function mapFormToColumns(form) {
7545
7568
  var column = {
7546
7569
  Header: component.label || component.title || component.key,
7547
7570
  accessor: "data." + component.key,
7571
+ className: "text-center",
7548
7572
  Cell: function Cell(props) {
7549
7573
  return /*#__PURE__*/React__default["default"].createElement(DefaultCell, _extends({}, props, {
7550
7574
  render: function render(value) {
@@ -7776,5 +7800,6 @@ exports.useForm = useForm;
7776
7800
  exports.useFormEdit = useFormEdit;
7777
7801
  exports.useModal = useModal;
7778
7802
  exports.useOperations = useOperations;
7803
+ exports.useSelectColumnFilter = useSelectColumnFilter;
7779
7804
  exports.useTooltip = useTooltip;
7780
7805
  //# sourceMappingURL=index.js.map