mig-schema-table 1.0.7 → 1.0.8

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,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { camelTextToTitleText } from "../../../inc/string";
3
+ import { uncamel } from "../../../inc/string";
4
4
  const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters, setSortAsc, setSortColumn, sortAsc, style, }) => {
5
5
  const thDivProps = {
6
6
  style,
@@ -39,6 +39,6 @@ const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters,
39
39
  thDivProps.className += ` text-${(config === null || config === void 0 ? void 0 : config.align) || "end"}`;
40
40
  }
41
41
  }
42
- return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (config === null || config === void 0 ? void 0 : config.sortable) === false, onClick: onSortButtonClick }, { children: [(config === null || config === void 0 ? void 0 : config.title) || camelTextToTitleText(name), sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: (config === null || config === void 0 ? void 0 : config.title) || camelTextToTitleText(name) }))), (config === null || config === void 0 ? void 0 : config.isFilterable) ? (_jsx("button", Object.assign({ onClick: onFilterButtonClick }, { children: _jsx("svg", Object.assign({ viewBox: "0 0 36 36", xmlns: "http://www.w3.org/2000/svg", height: 16, width: 16, style: { display: "block" } }, { children: _jsx("polygon", { fill: "#231F20", points: "14,30 22,25 22,17 35.999,0 17.988,0 0,0 14,17 " }) })) }))) : null] })));
42
+ return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (config === null || config === void 0 ? void 0 : config.sortable) === false, onClick: onSortButtonClick }, { children: [(config === null || config === void 0 ? void 0 : config.title) || uncamel(name), sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: (config === null || config === void 0 ? void 0 : config.title) || uncamel(name) }))), (config === null || config === void 0 ? void 0 : config.isFilterable) ? (_jsx("button", Object.assign({ onClick: onFilterButtonClick }, { children: _jsx("svg", Object.assign({ viewBox: "0 0 36 36", xmlns: "http://www.w3.org/2000/svg", height: 16, width: 16, style: { display: "block" } }, { children: _jsx("polygon", { fill: "#231F20", points: "14,30 22,25 22,17 35.999,0 17.988,0 0,0 14,17 " }) })) }))) : null] })));
43
43
  };
44
44
  export default React.memo(Th);
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { VariableSizeList, VariableSizeGrid } from "react-window";
4
4
  import { localeFormat } from "../../inc/date";
5
- import { camelTextToTitleText } from "../../inc/string";
5
+ import { uncamel } from "../../inc/string";
6
6
  import Th from "./Th";
7
7
  export default function SchemaTableComponent(props) {
8
8
  const { config, data, defaultSortColumn, defaultSortAsc = false, Heading = VariableSizeList, isSearchable, isSortable, onRowClick, getRowClassName, getRowSelected, rowHeight = 36, schema, style, customElement, tableTitle, searchPlaceholder } = props;
@@ -81,7 +81,7 @@ export default function SchemaTableComponent(props) {
81
81
  return prev;
82
82
  }
83
83
  if (schema.enum) {
84
- prev[propName] = camelTextToTitleText(rawValue);
84
+ prev[propName] = uncamel(rawValue);
85
85
  return prev;
86
86
  }
87
87
  // fallthrough
@@ -1 +1 @@
1
- export declare const camelTextToTitleText: (keyName: string) => string;
1
+ export declare function uncamel(camel: string): string;
@@ -1,4 +1,17 @@
1
- export const camelTextToTitleText = (keyName) => {
2
- const titleText = keyName.replace(/([A-Z])/g, " $1");
3
- return titleText.charAt(0).toUpperCase() + titleText.slice(1);
4
- };
1
+ import { upperFirst } from "lodash";
2
+ function isUpperCase(letter) {
3
+ return !!letter.match(/[A-Z]/);
4
+ }
5
+ export function uncamel(camel) {
6
+ return upperFirst(camel.replaceAll(/[A-Z]/g, (letter, position) => {
7
+ const prevLetter = camel[position - 1];
8
+ const prevIsUppercase = prevLetter ? isUpperCase(prevLetter) : false;
9
+ const nextLetter = camel[position + 1];
10
+ const nextIsUppercase = nextLetter ? isUpperCase(nextLetter) : false;
11
+ if (position === 0 ||
12
+ (prevIsUppercase && (!nextLetter || nextIsUppercase))) {
13
+ return letter;
14
+ }
15
+ return ` ${nextIsUppercase ? letter : letter.toLowerCase()}`;
16
+ }));
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "build/index.js",
5
5
  "files": [
6
6
  "build/"