@deviceinsight/ng-ui-components 7.5.0 → 7.10.0

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/dist/index.cjs CHANGED
@@ -339,15 +339,15 @@ _ValidatedTextInput.defaultProps = {
339
339
  let ValidatedTextInput = _ValidatedTextInput;
340
340
  function ColorTextInput({ value, pattern, onChange, placeholder, style }) {
341
341
  const [text, setText] = React.useState(value);
342
+ React.useEffect(() => {
343
+ setText(value);
344
+ }, [value]);
342
345
  function handleChange(value2, valid) {
343
346
  setText(value2);
344
347
  if (valid) {
345
348
  onChange(value2);
346
349
  }
347
350
  }
348
- React.useEffect(() => {
349
- setText(value);
350
- }, [value]);
351
351
  return /* @__PURE__ */ jsxRuntime.jsx(
352
352
  ValidatedTextInput,
353
353
  {
@@ -1522,6 +1522,125 @@ function Pagination({ onChangePage, page, totalPages, onChangeSize, size }) {
1522
1522
  ) })
1523
1523
  ] }) });
1524
1524
  }
1525
+ function getSortedOptions(options, compareOptions) {
1526
+ if (!compareOptions) {
1527
+ return lodash.orderBy(options, "label", "asc");
1528
+ }
1529
+ if (options.every((option) => !option.options)) {
1530
+ const singleOptions = options;
1531
+ return [...singleOptions].sort(compareOptions);
1532
+ }
1533
+ if (options.every((option) => option.options)) {
1534
+ const groupOptions = options;
1535
+ return groupOptions.map((option) => ({ ...option, options: [...option.options].sort(compareOptions) }));
1536
+ }
1537
+ throw new Error("Mixing groups with single options not allowed");
1538
+ }
1539
+ class SelectWithSearch extends React.Component {
1540
+ constructor() {
1541
+ super(...arguments);
1542
+ this.state = {
1543
+ options: [],
1544
+ inputValue: null
1545
+ };
1546
+ this.selectRef = React.createRef();
1547
+ this.portalRoot = null;
1548
+ this.updateOptions = () => {
1549
+ const { options, specialOptions, compareOptions } = this.props;
1550
+ const sortedOptions = getSortedOptions(options, compareOptions);
1551
+ if (specialOptions) {
1552
+ this.setState({
1553
+ // @ts-ignore
1554
+ options: [...sortedOptions, ...specialOptions]
1555
+ });
1556
+ } else {
1557
+ this.setState({
1558
+ options: sortedOptions
1559
+ });
1560
+ }
1561
+ };
1562
+ this.filterOption = (option, inputValue) => {
1563
+ return option.label.toString().toLowerCase().startsWith(inputValue.toLowerCase());
1564
+ };
1565
+ this.getContainerClasses = () => {
1566
+ const { specialOptions } = this.props;
1567
+ if (specialOptions) {
1568
+ return ["select-search-container", "special"];
1569
+ }
1570
+ return ["select-search-container"];
1571
+ };
1572
+ }
1573
+ componentDidMount() {
1574
+ this.updateOptions();
1575
+ if (this.props["data-testid"] && this.selectRef && this.selectRef.current) {
1576
+ this.selectRef.current.controlRef.setAttribute("data-testid", this.props["data-testid"]);
1577
+ }
1578
+ if (this.props.menuPortalTarget) {
1579
+ this.portalRoot = document.createElement("div");
1580
+ const classes = this.getContainerClasses();
1581
+ this.portalRoot.classList.add(...classes);
1582
+ this.props.menuPortalTarget.appendChild(this.portalRoot);
1583
+ }
1584
+ }
1585
+ componentDidUpdate(prevProps) {
1586
+ if (!lodash.isEqual(prevProps.options, this.props.options) || prevProps.freeForm !== this.props.freeForm) {
1587
+ this.updateOptions();
1588
+ }
1589
+ }
1590
+ componentWillUnmount() {
1591
+ if (this.props.menuPortalTarget && this.portalRoot) {
1592
+ this.props.menuPortalTarget.removeChild(this.portalRoot);
1593
+ }
1594
+ }
1595
+ render() {
1596
+ const { noResultsMessage, placeholder, value, onChange, clearable, loading, disabled } = this.props;
1597
+ const { options } = this.state;
1598
+ return /* @__PURE__ */ jsxRuntime.jsx(
1599
+ Select,
1600
+ {
1601
+ ref: this.selectRef,
1602
+ joinValues: true,
1603
+ name: "form-field-name",
1604
+ className: this.getContainerClasses().join(" "),
1605
+ classNamePrefix: "select-search",
1606
+ isClearable: clearable,
1607
+ noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
1608
+ options,
1609
+ value: value || null,
1610
+ onChange,
1611
+ onInputChange: (newValue) => {
1612
+ if (this.props.freeForm && newValue) {
1613
+ this.setState({ inputValue: newValue });
1614
+ }
1615
+ },
1616
+ placeholder,
1617
+ filterOption: this.filterOption,
1618
+ isLoading: loading,
1619
+ menuPortalTarget: this.portalRoot,
1620
+ isDisabled: disabled,
1621
+ onBlur: () => {
1622
+ if (this.props.freeForm && this.state.inputValue !== null) {
1623
+ this.setState({ options: this.props.options });
1624
+ this.setState({ inputValue: this.state.inputValue }, () => {
1625
+ const newItem = {
1626
+ type: "item",
1627
+ value: this.state.inputValue,
1628
+ label: this.state.inputValue
1629
+ };
1630
+ this.setState(
1631
+ (prevState) => ({
1632
+ options: [newItem, ...prevState.options]
1633
+ })
1634
+ );
1635
+ this.state.inputValue = null;
1636
+ onChange(newItem);
1637
+ });
1638
+ }
1639
+ }
1640
+ }
1641
+ );
1642
+ }
1643
+ }
1525
1644
  const getInitialValueFromColumnDef = (columnDef) => {
1526
1645
  return columnDef.filterable?.initialValue ?? "";
1527
1646
  };
@@ -1642,125 +1761,6 @@ function extendColumnDefsWithCheckboxes(columnDefs, onSelectChange, onSelectAllC
1642
1761
  function getClassName(tableName, columnName) {
1643
1762
  return `${tableName || "unnamedTable"}-${columnName}`;
1644
1763
  }
1645
- function getSortedOptions(options, compareOptions) {
1646
- if (!compareOptions) {
1647
- return lodash.orderBy(options, "label", "asc");
1648
- }
1649
- if (options.every((option) => !option.options)) {
1650
- const singleOptions = options;
1651
- return [...singleOptions].sort(compareOptions);
1652
- }
1653
- if (options.every((option) => option.options)) {
1654
- const groupOptions = options;
1655
- return groupOptions.map((option) => ({ ...option, options: [...option.options].sort(compareOptions) }));
1656
- }
1657
- throw new Error("Mixing groups with single options not allowed");
1658
- }
1659
- class SelectWithSearch extends React.Component {
1660
- constructor() {
1661
- super(...arguments);
1662
- this.state = {
1663
- options: [],
1664
- inputValue: null
1665
- };
1666
- this.selectRef = React.createRef();
1667
- this.portalRoot = null;
1668
- this.updateOptions = () => {
1669
- const { options, specialOptions, compareOptions } = this.props;
1670
- const sortedOptions = getSortedOptions(options, compareOptions);
1671
- if (specialOptions) {
1672
- this.setState({
1673
- // @ts-ignore
1674
- options: [...sortedOptions, ...specialOptions]
1675
- });
1676
- } else {
1677
- this.setState({
1678
- options: sortedOptions
1679
- });
1680
- }
1681
- };
1682
- this.filterOption = (option, inputValue) => {
1683
- return option.label.toString().toLowerCase().startsWith(inputValue.toLowerCase());
1684
- };
1685
- this.getContainerClasses = () => {
1686
- const { specialOptions } = this.props;
1687
- if (specialOptions) {
1688
- return ["select-search-container", "special"];
1689
- }
1690
- return ["select-search-container"];
1691
- };
1692
- }
1693
- componentDidMount() {
1694
- this.updateOptions();
1695
- if (this.props["data-testid"] && this.selectRef && this.selectRef.current) {
1696
- this.selectRef.current.controlRef.setAttribute("data-testid", this.props["data-testid"]);
1697
- }
1698
- if (this.props.menuPortalTarget) {
1699
- this.portalRoot = document.createElement("div");
1700
- const classes = this.getContainerClasses();
1701
- this.portalRoot.classList.add(...classes);
1702
- this.props.menuPortalTarget.appendChild(this.portalRoot);
1703
- }
1704
- }
1705
- componentDidUpdate(prevProps) {
1706
- if (!lodash.isEqual(prevProps.options, this.props.options) || prevProps.freeForm !== this.props.freeForm) {
1707
- this.updateOptions();
1708
- }
1709
- }
1710
- componentWillUnmount() {
1711
- if (this.props.menuPortalTarget && this.portalRoot) {
1712
- this.props.menuPortalTarget.removeChild(this.portalRoot);
1713
- }
1714
- }
1715
- render() {
1716
- const { noResultsMessage, placeholder, value, onChange, clearable, loading, disabled } = this.props;
1717
- const { options } = this.state;
1718
- return /* @__PURE__ */ jsxRuntime.jsx(
1719
- Select,
1720
- {
1721
- ref: this.selectRef,
1722
- joinValues: true,
1723
- name: "form-field-name",
1724
- className: this.getContainerClasses().join(" "),
1725
- classNamePrefix: "select-search",
1726
- isClearable: clearable,
1727
- noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
1728
- options,
1729
- value: value || null,
1730
- onChange,
1731
- onInputChange: (newValue) => {
1732
- if (this.props.freeForm && newValue) {
1733
- this.setState({ inputValue: newValue });
1734
- }
1735
- },
1736
- placeholder,
1737
- filterOption: this.filterOption,
1738
- isLoading: loading,
1739
- menuPortalTarget: this.portalRoot,
1740
- isDisabled: disabled,
1741
- onBlur: () => {
1742
- if (this.props.freeForm && this.state.inputValue !== null) {
1743
- this.setState({ options: this.props.options });
1744
- this.setState({ inputValue: this.state.inputValue }, () => {
1745
- const newItem = {
1746
- type: "item",
1747
- value: this.state.inputValue,
1748
- label: this.state.inputValue
1749
- };
1750
- this.setState(
1751
- (prevState) => ({
1752
- options: [newItem, ...prevState.options]
1753
- })
1754
- );
1755
- this.state.inputValue = null;
1756
- onChange(newItem);
1757
- });
1758
- }
1759
- }
1760
- }
1761
- );
1762
- }
1763
- }
1764
1764
  const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
1765
1765
  const { t } = useTranslation();
1766
1766
  const [state, setState] = React.useState({});
@@ -1857,7 +1857,15 @@ const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
1857
1857
  );
1858
1858
  }
1859
1859
  };
1860
- return /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsxRuntime.jsx("td", { style: { textAlign: columnDef.align || "left" }, children: getFilterByColumnDef(columnDef) }, columnDef.name)) });
1860
+ return /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsxRuntime.jsx(
1861
+ "td",
1862
+ {
1863
+ className: getClassName(tableName, columnDef.name),
1864
+ style: { textAlign: columnDef.align || "left" },
1865
+ children: getFilterByColumnDef(columnDef)
1866
+ },
1867
+ columnDef.name
1868
+ )) });
1861
1869
  };
1862
1870
  const toggleSortDirection = (direction) => direction === "ASC" ? "DESC" : "ASC";
1863
1871
  class ReactableTableHeader extends React.Component {