@teselagen/ui 0.7.33-beta.1 → 0.7.33-beta.2
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/package.json +1 -1
- package/src/AdvancedOptions.js +33 -0
- package/src/AssignDefaultsModeContext.js +22 -0
- package/src/CellDragHandle.js +132 -0
- package/src/ColumnFilterMenu.js +62 -0
- package/src/Columns.js +979 -0
- package/src/DisabledLoadingComponent.js +15 -0
- package/src/DisplayOptions.js +199 -0
- package/src/DropdownButton.js +36 -0
- package/src/DropdownCell.js +61 -0
- package/src/EditableCell.js +44 -0
- package/src/FillWindow.css +6 -0
- package/src/FillWindow.js +69 -0
- package/src/FilterAndSortMenu.js +388 -0
- package/src/FormSeparator.js +9 -0
- package/src/LoadingDots.js +14 -0
- package/src/MatchHeaders.js +234 -0
- package/src/PagingTool.js +225 -0
- package/src/RenderCell.js +191 -0
- package/src/SearchBar.js +69 -0
- package/src/SimpleStepViz.js +22 -0
- package/src/SortableColumns.js +100 -0
- package/src/TableFormTrackerContext.js +10 -0
- package/src/Tag.js +112 -0
- package/src/ThComponent.js +44 -0
- package/src/TimelineEvent.js +31 -0
- package/src/UploadCsvWizard.css +4 -0
- package/src/UploadCsvWizard.js +719 -0
- package/src/Uploader.js +1278 -0
- package/src/adHoc.js +10 -0
- package/src/autoTooltip.js +201 -0
- package/src/basicHandleActionsWithFullState.js +14 -0
- package/src/browserUtils.js +3 -0
- package/src/combineReducersWithFullState.js +14 -0
- package/src/commandControls.js +82 -0
- package/src/commandUtils.js +112 -0
- package/src/constants.js +1 -0
- package/src/convertSchema.js +69 -0
- package/src/customIcons.js +361 -0
- package/src/dataTableEnhancer.js +41 -0
- package/src/defaultFormatters.js +32 -0
- package/src/defaultValidators.js +40 -0
- package/src/determineBlackOrWhiteTextColor.js +4 -0
- package/src/editCellHelper.js +44 -0
- package/src/filterLocalEntitiesToHasura.js +216 -0
- package/src/formatPasteData.js +16 -0
- package/src/getAllRows.js +11 -0
- package/src/getCellCopyText.js +7 -0
- package/src/getCellInfo.js +36 -0
- package/src/getCellVal.js +20 -0
- package/src/getDayjsFormatter.js +35 -0
- package/src/getFieldPathToField.js +7 -0
- package/src/getIdOrCodeOrIndex.js +9 -0
- package/src/getLastSelectedEntity.js +11 -0
- package/src/getNewEntToSelect.js +25 -0
- package/src/getNewName.js +31 -0
- package/src/getRowCopyText.js +28 -0
- package/src/getTableConfigFromStorage.js +5 -0
- package/src/getTextFromEl.js +28 -0
- package/src/getVals.js +8 -0
- package/src/handleCopyColumn.js +21 -0
- package/src/handleCopyHelper.js +15 -0
- package/src/handleCopyRows.js +23 -0
- package/src/handleCopyTable.js +16 -0
- package/src/handlerHelpers.js +24 -0
- package/src/hotkeyUtils.js +131 -0
- package/src/index.js +1 -0
- package/src/initializeHasuraWhereAndFilter.js +27 -0
- package/src/isBeingCalledExcessively.js +24 -0
- package/src/isBottomRightCornerOfRectangle.js +20 -0
- package/src/isEntityClean.js +15 -0
- package/src/isTruthy.js +12 -0
- package/src/isValueEmpty.js +3 -0
- package/src/itemUpload.js +84 -0
- package/src/menuUtils.js +433 -0
- package/src/popoverOverflowModifiers.js +11 -0
- package/src/primarySelectedValue.js +1 -0
- package/src/pureNoFunc.js +31 -0
- package/src/queryParams.js +336 -0
- package/src/removeCleanRows.js +22 -0
- package/src/renderOnDoc.js +32 -0
- package/src/rerenderOnWindowResize.js +26 -0
- package/src/rowClick.js +181 -0
- package/src/selection.js +8 -0
- package/src/showAppSpinner.js +12 -0
- package/src/showDialogOnDocBody.js +33 -0
- package/src/showProgressToast.js +22 -0
- package/src/simplifyHasuraWhere.js +80 -0
- package/src/sortify.js +73 -0
- package/src/style.css +29 -0
- package/src/tableQueryParamsToHasuraClauses.js +113 -0
- package/src/tagUtils.js +45 -0
- package/src/tgFormValues.js +35 -0
- package/src/tg_modalState.js +47 -0
- package/src/throwFormError.js +16 -0
- package/src/toastr.js +148 -0
- package/src/tryToMatchSchemas.js +264 -0
- package/src/typeToCommonType.js +6 -0
- package/src/useDeepEqualMemo.js +15 -0
- package/src/useDialog.js +63 -0
- package/src/useStableReference.js +9 -0
- package/src/useTableEntities.js +38 -0
- package/src/useTraceUpdate.js +19 -0
- package/src/utils.js +37 -0
- package/src/validateTableWideErrors.js +160 -0
- package/src/viewColumn.js +97 -0
- package/src/withField.js +20 -0
- package/src/withFields.js +11 -0
- package/src/withLocalStorage.js +11 -0
- package/src/withSelectTableRecords.js +43 -0
- package/src/withSelectedEntities.js +65 -0
- package/src/withStore.js +10 -0
- package/src/withTableParams.js +288 -0
- package/src/wrapDialog.js +116 -0
package/src/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
|
+
};
|
|
@@ -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,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/src/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;
|