@teselagen/ui 0.7.33-beta.6 → 0.7.34

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 (114) 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 +14 -7
  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 +972 -837
  67. package/index.d.ts +0 -1
  68. package/index.es.js +972 -837
  69. package/index.js +1 -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/style.css +13 -0
  92. package/tagUtils.js +45 -0
  93. package/tgFormValues.js +35 -0
  94. package/tg_modalState.js +47 -0
  95. package/throwFormError.js +16 -0
  96. package/toastr.js +148 -0
  97. package/tryToMatchSchemas.js +264 -0
  98. package/typeToCommonType.js +6 -0
  99. package/useDeepEqualMemo.js +15 -0
  100. package/useDialog.js +63 -0
  101. package/useStableReference.js +9 -0
  102. package/useTableEntities.js +38 -0
  103. package/useTraceUpdate.js +19 -0
  104. package/utils.js +37 -0
  105. package/validateTableWideErrors.js +160 -0
  106. package/viewColumn.js +97 -0
  107. package/withField.js +20 -0
  108. package/withFields.js +11 -0
  109. package/withLocalStorage.js +11 -0
  110. package/withSelectTableRecords.js +43 -0
  111. package/withSelectedEntities.js +65 -0
  112. package/withStore.js +10 -0
  113. package/withTableParams.js +301 -0
  114. package/wrapDialog.js +116 -0
package/adHoc.js ADDED
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { compose } from "recompose";
3
+
4
+ //adHoc allows you to add dynamic HOCs to a component
5
+ export default func => WrappedComponent => props => {
6
+ const calledFunc = func(props);
7
+ const composeArgs = Array.isArray(calledFunc) ? calledFunc : [calledFunc];
8
+ const ComposedAndWrapped = compose(...composeArgs)(WrappedComponent);
9
+ return <ComposedAndWrapped {...props} />;
10
+ };
package/autoTooltip.js ADDED
@@ -0,0 +1,201 @@
1
+ import tippy, { followCursor } from "tippy.js";
2
+ import "tippy.js/dist/tippy.css";
3
+
4
+ let isDragging = false;
5
+ let canSetDragging = false;
6
+ document.addEventListener("mousedown", () => {
7
+ canSetDragging = true;
8
+ isDragging = false;
9
+ });
10
+ document.addEventListener("mousemove", () => {
11
+ if (canSetDragging) {
12
+ isDragging = true;
13
+ }
14
+ });
15
+ document.addEventListener("mouseup", () => {
16
+ canSetDragging = false;
17
+ isDragging = false;
18
+ });
19
+
20
+ let tippys = [];
21
+ let recentlyHidden = false;
22
+ let clearMe;
23
+ (function () {
24
+ let lastMouseOverElement = null;
25
+ document.addEventListener("mouseover", function (event) {
26
+ const element = event.target;
27
+
28
+ if (element instanceof Element && element !== lastMouseOverElement) {
29
+ lastMouseOverElement = element;
30
+
31
+ const id = "tippyEllipsizedEl";
32
+ // eslint-disable-next-line no-inner-declarations
33
+ function clearOldTippys(maybeInst) {
34
+ //clear old tippys
35
+ tippys = tippys.filter(t => {
36
+ const areeq = maybeInst?.reference?.isEqualNode(t.reference);
37
+ if (!areeq) {
38
+ t.destroy();
39
+ return false;
40
+ }
41
+ return true;
42
+ });
43
+ }
44
+ let innerRun = false;
45
+ const inner = (
46
+ content,
47
+ el,
48
+ { dataTitle, dataAvoid, dataAvoidBackup }
49
+ ) => {
50
+ innerRun = true;
51
+ document.querySelectorAll(`.${id}`).forEach(elem => {
52
+ elem.classList.remove(id);
53
+ });
54
+
55
+ el.classList.add(id);
56
+ const inst = tippy(`.${id}`, {
57
+ theme: "teselagen",
58
+ plugins: [followCursor],
59
+ content,
60
+ delay:
61
+ dataTitle && !recentlyHidden
62
+ ? [1300, 1300]
63
+ : dataTitle
64
+ ? [150, 150]
65
+ : [0, 0],
66
+ allowHTML: true,
67
+ ...(dataTitle && {
68
+ followCursor: dataTitle ? "initial" : false
69
+ }),
70
+ onHidden() {
71
+ recentlyHidden = true;
72
+ clearMe && clearTimeout(clearMe);
73
+ clearMe = setTimeout(() => {
74
+ if (tippys.length === 0) recentlyHidden = false;
75
+ }, 700);
76
+ },
77
+ ...(dataAvoid && {
78
+ popperOptions: {
79
+ modifiers: [
80
+ {
81
+ name: "myModifier",
82
+ enabled: true,
83
+ phase: "beforeWrite",
84
+ requires: ["computeStyles"],
85
+ requiresIfExists: ["offset"],
86
+ fn({ state }) {
87
+ // console.log(`state:`, state);
88
+ // state.styles.popper.bottom = 20 + "px";
89
+ const customBoundary =
90
+ document.querySelector(dataAvoid) ||
91
+ document.querySelector(dataAvoidBackup);
92
+
93
+ if (!customBoundary) return;
94
+ const a = customBoundary.getBoundingClientRect();
95
+ // console.log(
96
+ // `state.rects.reference.y:`,
97
+ // state.rects.reference.y
98
+ // );
99
+ // console.log(`a.top:`, a.top);
100
+
101
+ if (a.top < state.rects.reference.y) {
102
+ const b = Math.abs(
103
+ Math.abs(a.top - state.rects.reference.y) - 10
104
+ );
105
+ state.styles.popper.bottom = b + "px";
106
+ }
107
+
108
+ // const overflow = detectOverflow(state, {
109
+ // boundary: customBoundary,
110
+ // altBoundary: true
111
+ // });
112
+ // console.log(`overflow:`, overflow);
113
+ // if (overflow.bottom > 0) {
114
+ // const a = Math.abs(overflow.bottom);
115
+ // state.styles.popper.bottom = a + "px";
116
+ // }
117
+ }
118
+ }
119
+ ]
120
+ }
121
+ })
122
+ });
123
+
124
+ if (dataTitle) {
125
+ inst[0]?.popper?.classList.add("isDataTitle");
126
+ }
127
+ clearOldTippys(...inst);
128
+
129
+ if (!dataTitle) {
130
+ inst.forEach(i => {
131
+ i.show();
132
+ });
133
+ }
134
+
135
+ tippys = [...tippys, ...inst];
136
+ if (content === el.getAttribute("title")) {
137
+ el.removeAttribute("title");
138
+ }
139
+ };
140
+ const levels = 6;
141
+ let dataTip;
142
+ let dataTipStop;
143
+ let el = element;
144
+ for (let index = 0; index < levels; index++) {
145
+ if (!el) continue;
146
+
147
+ const style = window.getComputedStyle(el);
148
+ const whiteSpace = style.getPropertyValue("white-space");
149
+ const textOverflow = style.getPropertyValue("text-overflow");
150
+ const dataTitle = el.getAttribute("data-title");
151
+ const dataAvoid = el.getAttribute("data-avoid");
152
+ const dataAvoidBackup = el.getAttribute("data-avoid-backup");
153
+ dataTip = el.getAttribute("data-tip") || dataTitle;
154
+ const isEllipsized =
155
+ whiteSpace === "nowrap" && textOverflow === "ellipsis";
156
+
157
+ const opts = {
158
+ dataTitle,
159
+ dataAvoid,
160
+ dataAvoidBackup
161
+ };
162
+ if (
163
+ dataTip &&
164
+ !document.body.classList.contains("drag-active") &&
165
+ !isDragging
166
+ ) {
167
+ if (dataTipStop) break;
168
+
169
+ inner(dataTip, el, opts);
170
+ break;
171
+ } else if (
172
+ isEllipsized &&
173
+ el.offsetWidth < el.scrollWidth - 4 && //the -4 is adding a teeny bit of tolerance to fix issues with the column headers getting tooltips even when fully visible
174
+ !el.classList.contains("no-data-tip") &&
175
+ !parentIncludesNoChildDataTip(el, 0) &&
176
+ !document.body.classList.contains("drag-active") &&
177
+ el.textContent &&
178
+ el.textContent?.trim?.().length !== 0
179
+ ) {
180
+ inner(el.textContent, el, opts);
181
+ break;
182
+ } else if (isEllipsized && el.offsetWidth >= el.scrollWidth) {
183
+ // break; //tnr: i don't think we need this..
184
+ }
185
+ el = el.parentElement;
186
+ }
187
+
188
+ if (!innerRun) {
189
+ clearOldTippys();
190
+ }
191
+ }
192
+ });
193
+ })();
194
+
195
+ function parentIncludesNoChildDataTip(el, count) {
196
+ if (count > 4) return false;
197
+ if (!el) return false;
198
+ // if attr data-no-child-data-tip is preset on the element, then we don't want to show a tooltip on any of its children
199
+ if (el.getAttribute("data-no-child-data-tip")) return true;
200
+ return parentIncludesNoChildDataTip(el.parentElement, count + 1);
201
+ }
@@ -0,0 +1,14 @@
1
+ export default function basicHandleActionsWithFullState(
2
+ handlers,
3
+ defaultState
4
+ ) {
5
+ return (state = defaultState, action, fullState) => {
6
+ const { type } = action;
7
+ const handler = handlers[type];
8
+ if (handler) {
9
+ return handler(state, action, fullState);
10
+ } else {
11
+ return state;
12
+ }
13
+ };
14
+ }
@@ -0,0 +1,3 @@
1
+ export const isSafari = /^((?!chrome|android).)*safari/i.test(
2
+ navigator.userAgent
3
+ );
@@ -0,0 +1,14 @@
1
+ export default function combineReducers(reducers = {}) {
2
+ const reducerKeys = Object.keys(reducers);
3
+ return function combination(state = {}, action, fullState) {
4
+ let hasChanged = false;
5
+ const nextState = {};
6
+ fullState = fullState || state;
7
+ for (let i = 0; i < reducerKeys.length; i++) {
8
+ const key = reducerKeys[i];
9
+ nextState[key] = reducers[key](state[key], action, fullState);
10
+ hasChanged = hasChanged || nextState[key] !== state[key];
11
+ }
12
+ return hasChanged ? nextState : state;
13
+ };
14
+ }
@@ -0,0 +1,82 @@
1
+ import React from "react";
2
+ import { Tooltip, Checkbox, Button, Switch } from "@blueprintjs/core";
3
+
4
+ export const withCommand =
5
+ mappings =>
6
+ WrappedComponent =>
7
+ ({ cmd, cmdOptions = {}, ...props }) => {
8
+ const mappedProps = {};
9
+ Object.keys(mappings).forEach(k => {
10
+ mappedProps[k] =
11
+ mappings[k] === "execute"
12
+ ? event => cmd.execute({ event })
13
+ : typeof mappings[k] === "function"
14
+ ? mappings[k](cmd, props)
15
+ : cmd[mappings[k]];
16
+ });
17
+
18
+ let out = <WrappedComponent {...mappedProps} {...props} />;
19
+ const tooltip =
20
+ cmd.tooltip || (typeof cmd.isDisabled === "string" && cmd.isDisabled);
21
+ if (tooltip && !cmdOptions.ignoreTooltip) {
22
+ out = <Tooltip content={tooltip}>{out}</Tooltip>;
23
+ }
24
+
25
+ return cmd.isHidden && !cmdOptions.ignoreHidden ? null : out;
26
+ };
27
+
28
+ export const CmdCheckbox = withCommand({
29
+ onChange: "execute",
30
+ label: (cmd, props) =>
31
+ props.name ||
32
+ (props.prefix && (
33
+ <React.Fragment>
34
+ {props.prefix}
35
+ {cmd.name}
36
+ </React.Fragment>
37
+ )) ||
38
+ cmd.name,
39
+ disabled: "isDisabled",
40
+ checked: "isActive"
41
+ })(Checkbox);
42
+
43
+ export const CmdSwitch = withCommand({
44
+ onChange: "execute",
45
+ label: (cmd, props) =>
46
+ props.name ||
47
+ (props.prefix && (
48
+ <React.Fragment>
49
+ {props.prefix}
50
+ {cmd.name}
51
+ </React.Fragment>
52
+ )) ||
53
+ cmd.name,
54
+ disabled: "isDisabled",
55
+ checked: "isActive"
56
+ })(Switch);
57
+
58
+ const Div = ({ onChange, children }) => {
59
+ return <div onClick={onChange}>{children}</div>;
60
+ };
61
+
62
+ export const CmdDiv = withCommand({
63
+ onChange: "execute",
64
+ children: (cmd, props) =>
65
+ props.name ||
66
+ (props.prefix && (
67
+ <React.Fragment>
68
+ {props.prefix}
69
+ {cmd.name}
70
+ </React.Fragment>
71
+ )) ||
72
+ cmd.name,
73
+ disabled: "isDisabled",
74
+ checked: "isActive"
75
+ })(Div);
76
+
77
+ export const CmdButton = withCommand({
78
+ onClick: "execute",
79
+ text: cmd => (cmd.isActive === false && cmd.inactiveName) || cmd.name,
80
+ icon: "icon",
81
+ disabled: "isDisabled"
82
+ })(Button);
@@ -0,0 +1,112 @@
1
+ import { startCase } from "lodash-es";
2
+
3
+ // Generic factory function to create command objects.
4
+ // TODO add documentation
5
+ export function genericCommandFactory(config) {
6
+ const out = {};
7
+ // eslint-disable-next-line no-unused-vars
8
+ for (const cmdId in config.commandDefs) {
9
+ const def = config.commandDefs[cmdId];
10
+ const command = { id: cmdId };
11
+ command.execute = (...execArgs) => {
12
+ config.handleReturn(
13
+ cmdId,
14
+ def.handler &&
15
+ def.handler.apply(command, config.getArguments(cmdId, execArgs))
16
+ );
17
+ };
18
+
19
+ const properties = [
20
+ "icon",
21
+ "name",
22
+ "component",
23
+ "shortName",
24
+ "description",
25
+ "hotkey",
26
+ "hotkeyProps",
27
+ "isDisabled",
28
+ "submenu",
29
+ "isActive",
30
+ "isHidden",
31
+ "tooltip",
32
+ "inactiveIcon",
33
+ "inactiveName"
34
+ ];
35
+
36
+ properties.forEach(prop => {
37
+ if (def[prop] !== undefined) {
38
+ if (typeof def[prop] === "function") {
39
+ Object.defineProperty(command, prop, {
40
+ get: () => {
41
+ return def[prop].apply(command, config.getArguments(cmdId, []));
42
+ }
43
+ });
44
+ } else {
45
+ command[prop] = def[prop];
46
+ }
47
+ }
48
+ });
49
+
50
+ // If no name was specified in the definition, let's try to give some
51
+ // auto-generated names
52
+ if (!def.name) {
53
+ command.name = startCase(cmdId);
54
+ if (def.toggle && cmdId.startsWith("toggle")) {
55
+ command.name = startCase(cmdId.replace("toggle", def.toggle[0] || ""));
56
+ command.inactiveName = startCase(
57
+ cmdId.replace("toggle", def.toggle[1] || "")
58
+ );
59
+ command.shortName = startCase(cmdId.replace("toggle", ""));
60
+ }
61
+ }
62
+
63
+ out[cmdId] = command;
64
+ }
65
+
66
+ return out;
67
+ }
68
+
69
+ // Extract hotkey props from the given commands or command defs, returning
70
+ // a mapping of command ids to hotkey prop objects
71
+ export function getCommandHotkeys(commandsOrDefs) {
72
+ const hotkeyDefs = {};
73
+ Object.keys(commandsOrDefs).forEach(cmdId => {
74
+ if (commandsOrDefs[cmdId].hotkey) {
75
+ hotkeyDefs[cmdId] = {
76
+ combo: commandsOrDefs[cmdId].hotkey,
77
+ label: commandsOrDefs[cmdId].name || startCase(cmdId),
78
+ ...commandsOrDefs[cmdId].hotkeyProps
79
+ };
80
+ }
81
+ });
82
+
83
+ return hotkeyDefs;
84
+ }
85
+
86
+ // Extract handler functions from the given commands, returning a mapping of
87
+ // command ids to handlers (directly - no checks added).
88
+ export function getCommandHandlers(commands) {
89
+ const handlers = {};
90
+ Object.keys(commands).forEach(cmdId => {
91
+ handlers[cmdId] = commands[cmdId].execute;
92
+ });
93
+
94
+ return handlers;
95
+ }
96
+
97
+ // Get hotkey handler functions for the given commands, returning a mapping of
98
+ // command ids to hotkey handlers.
99
+ export function getCommandHotkeyHandlers(commands) {
100
+ const handlers = {};
101
+ Object.keys(commands).forEach(cmdId => {
102
+ if (commands[cmdId].hotkey) {
103
+ handlers[cmdId] = event => {
104
+ if (!commands[cmdId].isDisabled && !commands[cmdId].isHidden) {
105
+ commands[cmdId].execute({ event, viaHotkey: true });
106
+ }
107
+ };
108
+ }
109
+ });
110
+
111
+ return handlers;
112
+ }
package/constants.js ADDED
@@ -0,0 +1 @@
1
+ export const SAFE_UPSERT_PAGE_SIZE = 50;
@@ -0,0 +1,69 @@
1
+ import { camelCase } from "lodash-es";
2
+ import { startCase, keyBy, map } from "lodash-es";
3
+
4
+ function convertSchema(schema) {
5
+ let schemaToUse = schema;
6
+ if (!schemaToUse.fields && Array.isArray(schema)) {
7
+ schemaToUse = {
8
+ fields: schema
9
+ };
10
+ }
11
+ schemaToUse = {
12
+ ...schemaToUse
13
+ };
14
+ schemaToUse.fields = schemaToUse.fields.map((field, i) => {
15
+ let fieldToUse = field;
16
+ if (typeof field === "string") {
17
+ fieldToUse = {
18
+ displayName: startCase(camelCase(field)),
19
+ path: field,
20
+ type: "string"
21
+ };
22
+ } else if (!field.type) {
23
+ fieldToUse = {
24
+ ...field,
25
+ type: "string"
26
+ };
27
+ }
28
+ if (!fieldToUse.displayName) {
29
+ fieldToUse = {
30
+ ...fieldToUse,
31
+ displayName: startCase(camelCase(fieldToUse.path))
32
+ };
33
+ }
34
+ // paths are needed for column resizing
35
+ if (!fieldToUse.path) {
36
+ fieldToUse = {
37
+ ...fieldToUse,
38
+ filterDisabled: true,
39
+ sortDisabled: true,
40
+ path: "fake-path" + i
41
+ };
42
+ }
43
+ return fieldToUse;
44
+ });
45
+ return schemaToUse;
46
+ }
47
+
48
+ export function mergeSchemas(_originalSchema, _overrideSchema) {
49
+ const originalSchema = convertSchema(_originalSchema);
50
+ const overrideSchema = convertSchema(_overrideSchema);
51
+
52
+ const overridesByKey = keyBy(overrideSchema.fields, "path");
53
+ return {
54
+ ...originalSchema,
55
+ ...overrideSchema,
56
+ fields: originalSchema.fields
57
+ .map(f => {
58
+ const override = overridesByKey[f.path];
59
+ if (override) {
60
+ delete overridesByKey[f.path];
61
+ return override;
62
+ }
63
+ return f;
64
+ })
65
+ .concat(map(overridesByKey))
66
+ };
67
+ }
68
+
69
+ export default convertSchema;