@teselagen/ui 0.7.33-beta.5 → 0.7.33

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.
Files changed (119) hide show
  1. package/AdvancedOptions.js +33 -0
  2. package/AssignDefaultsModeContext.js +22 -0
  3. package/CellDragHandle.js +132 -0
  4. package/ColumnFilterMenu.js +62 -0
  5. package/Columns.js +979 -0
  6. package/DataTable/utils/queryParams.d.ts +18 -9
  7. package/DisabledLoadingComponent.js +15 -0
  8. package/DisplayOptions.js +199 -0
  9. package/DropdownButton.js +36 -0
  10. package/DropdownCell.js +61 -0
  11. package/EditableCell.js +44 -0
  12. package/FillWindow.css +6 -0
  13. package/FillWindow.js +69 -0
  14. package/FilterAndSortMenu.js +391 -0
  15. package/FormSeparator.js +9 -0
  16. package/LoadingDots.js +14 -0
  17. package/MatchHeaders.js +234 -0
  18. package/PagingTool.js +225 -0
  19. package/RenderCell.js +191 -0
  20. package/SearchBar.js +69 -0
  21. package/SimpleStepViz.js +22 -0
  22. package/SortableColumns.js +100 -0
  23. package/TableFormTrackerContext.js +10 -0
  24. package/Tag.js +112 -0
  25. package/ThComponent.js +44 -0
  26. package/TimelineEvent.js +31 -0
  27. package/UploadCsvWizard.css +4 -0
  28. package/UploadCsvWizard.js +719 -0
  29. package/Uploader.js +1278 -0
  30. package/adHoc.js +10 -0
  31. package/autoTooltip.js +201 -0
  32. package/basicHandleActionsWithFullState.js +14 -0
  33. package/browserUtils.js +3 -0
  34. package/combineReducersWithFullState.js +14 -0
  35. package/commandControls.js +82 -0
  36. package/commandUtils.js +112 -0
  37. package/constants.js +1 -0
  38. package/convertSchema.js +69 -0
  39. package/customIcons.js +361 -0
  40. package/dataTableEnhancer.js +41 -0
  41. package/defaultFormatters.js +32 -0
  42. package/defaultValidators.js +40 -0
  43. package/determineBlackOrWhiteTextColor.js +4 -0
  44. package/editCellHelper.js +44 -0
  45. package/formatPasteData.js +16 -0
  46. package/getAllRows.js +11 -0
  47. package/getCellCopyText.js +7 -0
  48. package/getCellInfo.js +36 -0
  49. package/getCellVal.js +20 -0
  50. package/getDayjsFormatter.js +35 -0
  51. package/getFieldPathToField.js +7 -0
  52. package/getIdOrCodeOrIndex.js +9 -0
  53. package/getLastSelectedEntity.js +11 -0
  54. package/getNewEntToSelect.js +25 -0
  55. package/getNewName.js +31 -0
  56. package/getRowCopyText.js +28 -0
  57. package/getTableConfigFromStorage.js +5 -0
  58. package/getTextFromEl.js +28 -0
  59. package/getVals.js +8 -0
  60. package/handleCopyColumn.js +21 -0
  61. package/handleCopyHelper.js +15 -0
  62. package/handleCopyRows.js +23 -0
  63. package/handleCopyTable.js +16 -0
  64. package/handlerHelpers.js +24 -0
  65. package/hotkeyUtils.js +131 -0
  66. package/index.cjs.js +970 -826
  67. package/index.d.ts +0 -1
  68. package/index.es.js +970 -826
  69. package/index.js +196 -0
  70. package/isBeingCalledExcessively.js +31 -0
  71. package/isBottomRightCornerOfRectangle.js +20 -0
  72. package/isEntityClean.js +15 -0
  73. package/isTruthy.js +12 -0
  74. package/isValueEmpty.js +3 -0
  75. package/itemUpload.js +84 -0
  76. package/menuUtils.js +433 -0
  77. package/package.json +1 -2
  78. package/popoverOverflowModifiers.js +11 -0
  79. package/primarySelectedValue.js +1 -0
  80. package/pureNoFunc.js +31 -0
  81. package/queryParams.js +1058 -0
  82. package/removeCleanRows.js +22 -0
  83. package/renderOnDoc.js +32 -0
  84. package/rerenderOnWindowResize.js +26 -0
  85. package/rowClick.js +181 -0
  86. package/selection.js +8 -0
  87. package/showAppSpinner.js +12 -0
  88. package/showDialogOnDocBody.js +33 -0
  89. package/showProgressToast.js +22 -0
  90. package/sortify.js +73 -0
  91. package/src/DataTable/index.js +1 -1
  92. package/src/DataTable/utils/filterLocalEntitiesToHasura.js +14 -0
  93. package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +49 -0
  94. package/src/DataTable/utils/queryParams.js +12 -9
  95. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +146 -143
  96. package/style.css +29 -0
  97. package/tagUtils.js +45 -0
  98. package/tgFormValues.js +35 -0
  99. package/tg_modalState.js +47 -0
  100. package/throwFormError.js +16 -0
  101. package/toastr.js +148 -0
  102. package/tryToMatchSchemas.js +264 -0
  103. package/typeToCommonType.js +6 -0
  104. package/useDeepEqualMemo.js +15 -0
  105. package/useDialog.js +63 -0
  106. package/useStableReference.js +9 -0
  107. package/useTableEntities.js +38 -0
  108. package/useTraceUpdate.js +19 -0
  109. package/utils.js +37 -0
  110. package/validateTableWideErrors.js +160 -0
  111. package/viewColumn.js +97 -0
  112. package/withField.js +20 -0
  113. package/withFields.js +11 -0
  114. package/withLocalStorage.js +11 -0
  115. package/withSelectTableRecords.js +43 -0
  116. package/withSelectedEntities.js +65 -0
  117. package/withStore.js +10 -0
  118. package/withTableParams.js +301 -0
  119. package/wrapDialog.js +116 -0
@@ -0,0 +1,35 @@
1
+ import dayjs from "dayjs";
2
+ import LocalizedFormat from "dayjs/plugin/localizedFormat";
3
+ import localeData from "dayjs/plugin/localeData";
4
+
5
+ dayjs.extend(localeData);
6
+ dayjs.extend(LocalizedFormat);
7
+ const userLocale = Intl.DateTimeFormat().resolvedOptions().locale;
8
+
9
+ if (userLocale) {
10
+ const requireLocale = (newLocale, skipCall) => {
11
+ if (dayjs.locale() !== newLocale) {
12
+ try {
13
+ require(`dayjs/locale/${newLocale}.js`);
14
+ dayjs.locale(newLocale);
15
+ } catch (error) {
16
+ // error
17
+ if (!skipCall && newLocale.includes("-")) {
18
+ requireLocale(newLocale.split("-")[0], true);
19
+ }
20
+ }
21
+ }
22
+ };
23
+ const localeToUse = userLocale.toLowerCase();
24
+ requireLocale(localeToUse);
25
+ }
26
+
27
+ export default function getDayjsFormatter(format) {
28
+ return {
29
+ formatDate: date => dayjs(date).format(format),
30
+ parseDate: str => dayjs(str, format).toDate(),
31
+ placeholder: format?.toLowerCase().includes("l")
32
+ ? dayjs.Ls[dayjs.locale()]?.formats[format.toUpperCase()]
33
+ : format
34
+ };
35
+ }
@@ -0,0 +1,7 @@
1
+ export const getFieldPathToField = schema => {
2
+ const fieldPathToField = {};
3
+ schema.fields.forEach(f => {
4
+ fieldPathToField[f.path] = f;
5
+ });
6
+ return fieldPathToField;
7
+ };
@@ -0,0 +1,9 @@
1
+ export const getIdOrCodeOrIndex = (record, rowIndex) => {
2
+ if (record.id || record.id === 0) {
3
+ return record.id;
4
+ } else if (record.code) {
5
+ return record.code;
6
+ } else {
7
+ return rowIndex;
8
+ }
9
+ };
@@ -0,0 +1,11 @@
1
+ export const getLastSelectedEntity = idMap => {
2
+ let lastSelectedEnt;
3
+ let latestTime;
4
+ Object.values(idMap).forEach(({ time, entity }) => {
5
+ if (!latestTime || time > latestTime) {
6
+ lastSelectedEnt = entity;
7
+ latestTime = time;
8
+ }
9
+ });
10
+ return lastSelectedEnt;
11
+ };
@@ -0,0 +1,25 @@
1
+ export const getNewEntToSelect = ({
2
+ type,
3
+ lastSelectedIndex,
4
+ entities,
5
+ isEntityDisabled
6
+ }) => {
7
+ let newIndexToSelect;
8
+ if (type === "up") {
9
+ newIndexToSelect = lastSelectedIndex - 1;
10
+ } else {
11
+ newIndexToSelect = lastSelectedIndex + 1;
12
+ }
13
+ const newEntToSelect = entities[newIndexToSelect];
14
+ if (!newEntToSelect) return;
15
+ if (isEntityDisabled && isEntityDisabled(newEntToSelect)) {
16
+ return getNewEntToSelect({
17
+ type,
18
+ lastSelectedIndex: newIndexToSelect,
19
+ entities,
20
+ isEntityDisabled
21
+ });
22
+ } else {
23
+ return newEntToSelect;
24
+ }
25
+ };
package/getNewName.js ADDED
@@ -0,0 +1,31 @@
1
+ export function getNewName(list, targetName) {
2
+ const usedNumbers = [];
3
+
4
+ for (let i = 0; i < list.length; i++) {
5
+ const currentName = list[i].name;
6
+ const baseName = currentName.replace(/\(\d+\)\.csv$/, ".csv");
7
+
8
+ if (baseName === targetName) {
9
+ const match = currentName.match(/\((\d+)\)\.csv$/);
10
+ if (match) {
11
+ usedNumbers[parseInt(match[1])] = true;
12
+ } else {
13
+ usedNumbers[0] = true;
14
+ }
15
+ }
16
+ }
17
+
18
+ let newName = targetName;
19
+ for (let i = 0; i <= usedNumbers.length; i++) {
20
+ if (!usedNumbers[i]) {
21
+ if (i === 0) {
22
+ newName = targetName;
23
+ } else {
24
+ newName = targetName.replace(".csv", `(${i}).csv`);
25
+ }
26
+ break;
27
+ }
28
+ }
29
+
30
+ return newName;
31
+ }
@@ -0,0 +1,28 @@
1
+ import { getCellCopyText } from "./getCellCopyText";
2
+ import { flatMap } from "lodash-es";
3
+
4
+ export const getRowCopyText = (rowEl, { specificColumn } = {}) => {
5
+ //takes in a row element
6
+ if (!rowEl) return [];
7
+ const textContent = [];
8
+ const jsonText = [];
9
+
10
+ for (const cellEl of rowEl.children) {
11
+ const cellChild = cellEl.querySelector(`[data-copy-text]`);
12
+ if (!cellChild) {
13
+ if (specificColumn) continue; //strip it
14
+ continue; //just leave it blank
15
+ }
16
+ if (
17
+ specificColumn &&
18
+ cellChild.getAttribute("data-test") !== specificColumn
19
+ ) {
20
+ continue;
21
+ }
22
+ const [t, j] = getCellCopyText(cellChild);
23
+ textContent.push(t);
24
+ jsonText.push(j);
25
+ }
26
+
27
+ return [flatMap(textContent).join("\t"), jsonText];
28
+ };
@@ -0,0 +1,5 @@
1
+ export default function getTableConfigFromStorage(formName) {
2
+ let tableConfig = window.localStorage.getItem(formName);
3
+ tableConfig = tableConfig && JSON.parse(tableConfig);
4
+ return tableConfig;
5
+ }
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+
3
+ export default function getTextFromEl(el, options = {}) {
4
+ const { lowerCase } = options;
5
+ if (React.isValidElement(el)) {
6
+ return el && el.props && el.props.children
7
+ ? (el.props.children.reduce
8
+ ? el.props.children
9
+ : [el.props.children]
10
+ ).reduce((acc, child) => {
11
+ if (child && child.props && child.props.children) {
12
+ acc += getTextFromEl(child);
13
+ } else if (typeof child === "string") {
14
+ if (lowerCase) {
15
+ acc += child.toLowerCase();
16
+ } else {
17
+ acc += child;
18
+ }
19
+ } else if (typeof child === "number") {
20
+ acc += child + "";
21
+ }
22
+ return acc;
23
+ }, "")
24
+ : "";
25
+ } else {
26
+ return el;
27
+ }
28
+ }
package/getVals.js ADDED
@@ -0,0 +1,8 @@
1
+ import { isFunction } from "lodash-es";
2
+
3
+ export function getVals(values) {
4
+ if (isFunction(values)) {
5
+ return values();
6
+ }
7
+ return values;
8
+ }
@@ -0,0 +1,21 @@
1
+ import { getAllRows } from "./getAllRows";
2
+ import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
3
+ import { handleCopyRows } from "./handleCopyRows";
4
+
5
+ export const handleCopyColumn = (e, cellWrapper, selectedRecords) => {
6
+ const specificColumn = cellWrapper.getAttribute("data-test");
7
+ let rowElsToCopy = getAllRows(e);
8
+ if (!rowElsToCopy) return;
9
+ if (selectedRecords) {
10
+ const ids = selectedRecords.map(e => getIdOrCodeOrIndex(e)?.toString());
11
+ rowElsToCopy = Array.from(rowElsToCopy).filter(rowEl => {
12
+ const id = rowEl.closest(".rt-tr-group")?.getAttribute("data-test-id");
13
+ return id !== undefined && ids.includes(id);
14
+ });
15
+ }
16
+ if (!rowElsToCopy) return;
17
+ handleCopyRows(rowElsToCopy, {
18
+ specificColumn,
19
+ onFinishMsg: "Column Copied"
20
+ });
21
+ };
@@ -0,0 +1,15 @@
1
+ import copy from "copy-to-clipboard";
2
+
3
+ export const handleCopyHelper = (stringToCopy, jsonToCopy, message) => {
4
+ !window.Cypress &&
5
+ copy(stringToCopy, {
6
+ onCopy: clipboardData => {
7
+ clipboardData.setData("application/json", JSON.stringify(jsonToCopy));
8
+ },
9
+ // keep this so that pasting into spreadsheets works.
10
+ format: "text/plain"
11
+ });
12
+ if (message) {
13
+ window.toastr.success(message);
14
+ }
15
+ };
@@ -0,0 +1,23 @@
1
+ import download from "downloadjs";
2
+ import { getRowCopyText } from "./getRowCopyText";
3
+ import { handleCopyHelper } from "./handleCopyHelper";
4
+
5
+ export const handleCopyRows = (
6
+ rowElsToCopy,
7
+ { specificColumn, onFinishMsg, isDownload } = {}
8
+ ) => {
9
+ let textToCopy = [];
10
+ const jsonToCopy = [];
11
+ rowElsToCopy.forEach(rowEl => {
12
+ const [t, j] = getRowCopyText(rowEl, { specificColumn });
13
+ textToCopy.push(t);
14
+ jsonToCopy.push(j);
15
+ });
16
+ textToCopy = textToCopy.filter(text => text).join("\n");
17
+ if (!textToCopy) return window.toastr.warning("No text to copy");
18
+ if (isDownload) {
19
+ download(textToCopy.replaceAll("\t", ","), "tableData.csv", "text/csv");
20
+ } else {
21
+ handleCopyHelper(textToCopy, jsonToCopy, onFinishMsg || "Row Copied");
22
+ }
23
+ };
@@ -0,0 +1,16 @@
1
+ import { getAllRows } from "./getAllRows";
2
+ import { handleCopyRows } from "./handleCopyRows";
3
+
4
+ export const handleCopyTable = (e, opts) => {
5
+ try {
6
+ const allRowEls = getAllRows(e);
7
+ if (!allRowEls) return;
8
+ handleCopyRows(allRowEls, {
9
+ ...opts,
10
+ onFinishMsg: "Table Copied"
11
+ });
12
+ } catch (error) {
13
+ console.error(`error:`, error);
14
+ window.toastr.error("Error copying rows.");
15
+ }
16
+ };
@@ -0,0 +1,24 @@
1
+ export const onEnterHelper = callback => ({
2
+ onKeyDown: event => {
3
+ if (event.key === "Enter") {
4
+ callback(event);
5
+ }
6
+ }
7
+ });
8
+
9
+ export const onBlurHelper = callback => ({
10
+ onBlur: event => {
11
+ callback(event);
12
+ }
13
+ });
14
+
15
+ export const onEnterOrBlurHelper = callback => ({
16
+ onKeyDown: function (event) {
17
+ if (event.key === "Enter") {
18
+ callback(event);
19
+ }
20
+ },
21
+ onBlur: function (event) {
22
+ callback(event);
23
+ }
24
+ });
package/hotkeyUtils.js ADDED
@@ -0,0 +1,131 @@
1
+ import React, { useMemo } from "react";
2
+ import { useHotkeys } from "@blueprintjs/core";
3
+ import { startCase } from "lodash-es";
4
+
5
+ // This has been mostly superseded by blueprint's KeyCombo component, but may
6
+ // still be useful for cases where we need plain text
7
+ export function comboToLabel(def, useSymbols = true) {
8
+ const combo = typeof def === "string" ? def : def.combo;
9
+
10
+ if (useSymbols) {
11
+ let parts = combo.replace("++", "+plus").split("+");
12
+ parts = parts.map(p => symbols[p] || startCase(p) || p);
13
+ return parts.join("");
14
+ } else {
15
+ return combo
16
+ .split("+")
17
+ .map(p => startCase(p) || p)
18
+ .join(" + ")
19
+ .replace("Meta", isMac ? "Cmd" : "Ctrl")
20
+ .replace("Mod", isMac ? "Cmd" : "Ctrl")
21
+ .replace("Alt", isMac ? "Option" : "Alt");
22
+ }
23
+ }
24
+
25
+ // HOF to get hotkey combos by id
26
+ export const hotkeysById =
27
+ (hotkeys, mode = "raw") =>
28
+ id => {
29
+ const def = getHotkeyProps(hotkeys[id]);
30
+ return (
31
+ def &&
32
+ (mode === "raw" ? def.combo : comboToLabel(def.combo, mode === "symbols"))
33
+ );
34
+ };
35
+
36
+ // Translate shorthand array if needed
37
+ export const getHotkeyProps = (def, id) => {
38
+ let out;
39
+ if (typeof def === "string") {
40
+ out = { combo: def };
41
+ } else if (def instanceof Array) {
42
+ out = { combo: def[0], label: def[1], ...(def[2] || {}) };
43
+ } else {
44
+ out = def;
45
+ }
46
+ out.label = out.label || startCase(id);
47
+ return out;
48
+ };
49
+
50
+ /*
51
+ * HOC to add hotkey support to components. Use this instead of blueprint's one.
52
+ *
53
+ * Arguments:
54
+ * - hotkeySpec: either a named hotkey section previously registered, or an
55
+ * object mapping command ids to hotkey definitions, where each hotkey can
56
+ * be either:
57
+ * - a string consisting in the key combo (e.g. 'ctrl+shift+x')
58
+ * - an array holding the combo, label, and an object with any other props
59
+ * - an object holding all props
60
+ * - handlers: an object mapping command ids to handler functions
61
+ * - options: an object that may specify the follownig options:
62
+ * - functional: boolean indicating if the wrapped component will be a
63
+ * functional stateless component instead of a class-based one
64
+ *
65
+ * Returns a function that can be invoked with a component class, or a
66
+ * stateless component function (if specified in the options) and returns
67
+ * the decorated class. It may also be invoked without arguments to generate a
68
+ * dummy ad-hoc component with no output.
69
+ *
70
+ */
71
+ export const withHotkeys = (hotkeys, handlers) => {
72
+ return ({ children } = {}) => {
73
+ const memoedHotkeys = useMemo(
74
+ () =>
75
+ Object.keys(hotkeys).map(id => {
76
+ const { ...props } = getHotkeyProps(hotkeys[id], id);
77
+ return {
78
+ key: id,
79
+ global: props.global !== false,
80
+ onKeyDown: function (e) {
81
+ return handlers[id](e);
82
+ },
83
+ ...props
84
+ };
85
+ }),
86
+ []
87
+ );
88
+
89
+ const { handleKeyDown, handleKeyUp } = useHotkeys(memoedHotkeys);
90
+ const newProps = {
91
+ tabIndex: 0,
92
+ onKeyDown: handleKeyDown,
93
+ onKeyUp: handleKeyUp
94
+ };
95
+ return children ? ( //tnr: if children are passed, we'll clone them with the new props
96
+ React.cloneElement(children, newProps)
97
+ ) : (
98
+ //if not, then we'll return a div that can be used
99
+ <div className="hotkeyHandler" {...newProps}></div>
100
+ );
101
+ };
102
+ };
103
+
104
+ const isMac = navigator.userAgent.includes("Mac OS X");
105
+
106
+ // TODO maybe avoid using symbols by default when not on Mac?
107
+ // Anyway, alternative 'Key + Key' description is provided as well
108
+ const symbols = {
109
+ cmd: "⌘",
110
+ meta: "⌘",
111
+ ctrl: "⌃",
112
+ alt: "⌥",
113
+ shift: "⇧",
114
+ esc: "␛", //'⎋',
115
+ enter: "⏎",
116
+ backspace: "⌫",
117
+ plus: "+",
118
+ tab: "⇥",
119
+ space: "␣",
120
+ capslock: "⇪",
121
+ pageup: "⇞",
122
+ pagedown: "⇟",
123
+ home: "↖",
124
+ end: "↘",
125
+ left: "←",
126
+ right: "→",
127
+ up: "↑",
128
+ down: "↓"
129
+ };
130
+
131
+ symbols.mod = symbols[isMac ? "meta" : "ctrl"];