@teselagen/ui 0.9.6 → 0.9.7

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 (61) hide show
  1. package/DataTable/EditabelCell.d.ts +7 -0
  2. package/DataTable/ReactTable.d.ts +78 -0
  3. package/DataTable/defaultProps.d.ts +43 -0
  4. package/DataTable/index.d.ts +3 -3
  5. package/DataTable/utils/computePresets.d.ts +1 -0
  6. package/DataTable/utils/types/Entity.d.ts +9 -0
  7. package/DataTable/utils/types/Field.d.ts +4 -0
  8. package/DataTable/utils/types/OrderBy.d.ts +11 -0
  9. package/DataTable/utils/types/Schema.d.ts +4 -0
  10. package/DataTable/utils/useDeepEqualMemo.d.ts +1 -0
  11. package/DataTable/utils/useHotKeysWrapper.d.ts +29 -0
  12. package/DataTable/utils/useTableParams.d.ts +49 -0
  13. package/index.cjs.js +22410 -22287
  14. package/index.es.js +22462 -22339
  15. package/package.json +1 -2
  16. package/src/DataTable/Columns.jsx +945 -0
  17. package/src/DataTable/EditabelCell.js +44 -0
  18. package/src/DataTable/EditabelCell.jsx +44 -0
  19. package/src/DataTable/PagingTool.js +2 -2
  20. package/src/DataTable/ReactTable.js +738 -0
  21. package/src/DataTable/RenderCell.jsx +191 -0
  22. package/src/DataTable/defaultProps.js +45 -0
  23. package/src/DataTable/index.js +217 -1203
  24. package/src/DataTable/utils/computePresets.js +42 -0
  25. package/src/DataTable/utils/convertSchema.ts +79 -0
  26. package/src/DataTable/utils/formatPasteData.ts +34 -0
  27. package/src/DataTable/utils/getAllRows.ts +11 -0
  28. package/src/DataTable/utils/getCellCopyText.ts +7 -0
  29. package/src/DataTable/utils/getCellInfo.ts +46 -0
  30. package/src/DataTable/utils/getFieldPathToField.ts +10 -0
  31. package/src/DataTable/utils/getIdOrCodeOrIndex.ts +14 -0
  32. package/src/DataTable/utils/getLastSelectedEntity.ts +15 -0
  33. package/src/DataTable/utils/getNewEntToSelect.ts +32 -0
  34. package/src/DataTable/utils/initializeHasuraWhereAndFilter.ts +35 -0
  35. package/src/DataTable/utils/isBottomRightCornerOfRectangle.ts +27 -0
  36. package/src/DataTable/utils/isEntityClean.ts +15 -0
  37. package/src/DataTable/utils/primarySelectedValue.ts +1 -0
  38. package/src/DataTable/utils/removeCleanRows.ts +26 -0
  39. package/src/DataTable/utils/selection.ts +11 -0
  40. package/src/DataTable/utils/types/Entity.ts +13 -0
  41. package/src/DataTable/utils/types/Field.ts +4 -0
  42. package/src/DataTable/utils/types/OrderBy.ts +15 -0
  43. package/src/DataTable/utils/types/Schema.ts +5 -0
  44. package/src/DataTable/utils/useDeepEqualMemo.js +10 -0
  45. package/src/DataTable/utils/useHotKeysWrapper.js +395 -0
  46. package/src/DataTable/utils/useTableEntities.ts +60 -0
  47. package/src/DataTable/utils/useTableParams.js +361 -0
  48. package/src/DataTable/utils/utils.ts +39 -0
  49. package/src/DataTable/utils/withTableParams.js +1 -1
  50. package/src/Timeline/TimelineEvent.tsx +36 -0
  51. package/src/Timeline/index.tsx +21 -0
  52. package/src/utils/browserUtils.ts +3 -0
  53. package/src/utils/determineBlackOrWhiteTextColor.ts +11 -0
  54. package/src/utils/getTextFromEl.ts +45 -0
  55. package/src/utils/handlerHelpers.ts +32 -0
  56. package/src/utils/hooks/index.ts +1 -0
  57. package/src/utils/hooks/useDeepEqualMemo.ts +10 -0
  58. package/src/utils/hooks/useStableReference.ts +9 -0
  59. package/src/utils/hotkeyUtils.tsx +155 -0
  60. package/src/utils/isBeingCalledExcessively.ts +37 -0
  61. package/style.css +10537 -0
@@ -0,0 +1,155 @@
1
+ import React, { useMemo } from "react";
2
+ import { useHotkeys } from "@blueprintjs/core";
3
+ import { startCase } from "lodash-es";
4
+
5
+ type Out = {
6
+ combo: string;
7
+ label: string;
8
+ [key: string]: unknown;
9
+ global?: boolean;
10
+ };
11
+ type Hotkeys = {
12
+ [key: string]: string | [string, string, object] | Out;
13
+ };
14
+
15
+ // This has been mostly superseded by blueprint's KeyCombo component, but may
16
+ // still be useful for cases where we need plain text
17
+ export function comboToLabel(
18
+ def: string | { combo: string },
19
+ useSymbols = true
20
+ ) {
21
+ const combo = typeof def === "string" ? def : def.combo;
22
+
23
+ if (useSymbols) {
24
+ let parts = combo.replace("++", "+plus").split("+");
25
+ parts = parts.map(p =>
26
+ p in symbols ? symbols[p as keyof typeof symbols] : startCase(p) || p
27
+ );
28
+ return parts.join("");
29
+ } else {
30
+ return combo
31
+ .split("+")
32
+ .map(p => startCase(p) || p)
33
+ .join(" + ")
34
+ .replace("Meta", isMac ? "Cmd" : "Ctrl")
35
+ .replace("Mod", isMac ? "Cmd" : "Ctrl")
36
+ .replace("Alt", isMac ? "Option" : "Alt");
37
+ }
38
+ }
39
+
40
+ // HOF to get hotkey combos by id
41
+ export const hotkeysById =
42
+ (hotkeys: Hotkeys, mode = "raw") =>
43
+ (id: string) => {
44
+ const def = getHotkeyProps(hotkeys[id]);
45
+ return (
46
+ def &&
47
+ (mode === "raw" ? def.combo : comboToLabel(def.combo, mode === "symbols"))
48
+ );
49
+ };
50
+
51
+ // Translate shorthand array if needed
52
+ export const getHotkeyProps = (
53
+ def: string | [string, string, object] | Out,
54
+ id?: string
55
+ ) => {
56
+ let out: Out;
57
+ if (typeof def === "string") {
58
+ out = { combo: def, label: def };
59
+ } else if (def instanceof Array) {
60
+ out = { combo: def[0], label: def[1], ...(def[2] || {}) };
61
+ } else {
62
+ out = def;
63
+ }
64
+ out.label = out.label || startCase(id);
65
+ return out;
66
+ };
67
+
68
+ /*
69
+ * HOC to add hotkey support to components. Use this instead of blueprint's one.
70
+ *
71
+ * Arguments:
72
+ * - hotkeySpec: either a named hotkey section previously registered, or an
73
+ * object mapping command ids to hotkey definitions, where each hotkey can
74
+ * be either:
75
+ * - a string consisting in the key combo (e.g. 'ctrl+shift+x')
76
+ * - an array holding the combo, label, and an object with any other props
77
+ * - an object holding all props
78
+ * - handlers: an object mapping command ids to handler functions
79
+ * - options: an object that may specify the follownig options:
80
+ * - functional: boolean indicating if the wrapped component will be a
81
+ * functional stateless component instead of a class-based one
82
+ *
83
+ * Returns a function that can be invoked with a component class, or a
84
+ * stateless component function (if specified in the options) and returns
85
+ * the decorated class. It may also be invoked without arguments to generate a
86
+ * dummy ad-hoc component with no output.
87
+ *
88
+ */
89
+ export const withHotkeys = (
90
+ hotkeys: Hotkeys,
91
+ handlers: { [key: string]: (e: KeyboardEvent) => void }
92
+ ) => {
93
+ return ({ children }: { children?: React.ReactElement } = {}) => {
94
+ const memoedHotkeys = useMemo(
95
+ () =>
96
+ Object.keys(hotkeys).map(id => {
97
+ const { ...props } = getHotkeyProps(hotkeys[id], id);
98
+ return {
99
+ key: id,
100
+ global: props.global !== false,
101
+ onKeyDown: function (e: KeyboardEvent) {
102
+ return handlers[id](e);
103
+ },
104
+ ...props
105
+ };
106
+ }),
107
+ []
108
+ );
109
+
110
+ const { handleKeyDown, handleKeyUp } = useHotkeys(memoedHotkeys);
111
+ const newProps = {
112
+ tabIndex: 0,
113
+ onKeyDown: handleKeyDown,
114
+ onKeyUp: handleKeyUp
115
+ };
116
+ return children ? ( //tnr: if children are passed, we'll clone them with the new props
117
+ React.cloneElement(children, newProps)
118
+ ) : (
119
+ //if not, then we'll return a div that can be used
120
+ <div className="hotkeyHandler" {...newProps} />
121
+ );
122
+ };
123
+ };
124
+
125
+ const isMac = navigator.userAgent.includes("Mac OS X");
126
+
127
+ const cmd = "⌘";
128
+ const meta = "⌘";
129
+ const ctrl = "⌃";
130
+
131
+ // TODO maybe avoid using symbols by default when not on Mac?
132
+ // Anyway, alternative 'Key + Key' description is provided as well
133
+ const symbols = {
134
+ cmd,
135
+ meta,
136
+ ctrl,
137
+ alt: "⌥",
138
+ shift: "⇧",
139
+ esc: "␛", //'⎋',
140
+ enter: "⏎",
141
+ backspace: "⌫",
142
+ plus: "+",
143
+ tab: "⇥",
144
+ space: "␣",
145
+ capslock: "⇪",
146
+ pageup: "⇞",
147
+ pagedown: "⇟",
148
+ home: "↖",
149
+ end: "↘",
150
+ left: "←",
151
+ right: "→",
152
+ up: "↑",
153
+ down: "↓",
154
+ mod: isMac ? cmd : ctrl
155
+ } as const;
@@ -0,0 +1,37 @@
1
+ const keyCount: { [key: string]: number | null } = {};
2
+ const timeout: { [key: string]: NodeJS.Timeout | null } = {};
3
+
4
+ // if this function is hit more than 20 times in a row in 2 seconds with the same uniqName then throw an error
5
+ export const isBeingCalledExcessively = ({
6
+ uniqName
7
+ }: {
8
+ uniqName: string;
9
+ }) => {
10
+ if (process.env["NODE_ENV"] !== "development") {
11
+ return;
12
+ }
13
+ if (!uniqName) {
14
+ throw new Error("uniqName is required");
15
+ }
16
+ // Initialize the count if it doesn't exist
17
+ keyCount[uniqName] = keyCount[uniqName] || 0;
18
+ (keyCount[uniqName] as number)++;
19
+
20
+ // Only set the timeout if it doesn't exist already to ensure it runs exactly once every 2 seconds
21
+ if (!timeout[uniqName]) {
22
+ timeout[uniqName] = setTimeout(() => {
23
+ keyCount[uniqName] = 0;
24
+ timeout[uniqName] = null;
25
+ }, 2000);
26
+ }
27
+
28
+ if ((keyCount[uniqName] as number) > 20) {
29
+ keyCount[uniqName] = 0;
30
+ // Also clear the timeout when throwing an error
31
+ if (timeout[uniqName]) {
32
+ clearTimeout(timeout[uniqName]);
33
+ timeout[uniqName] = null;
34
+ }
35
+ throw new Error(`isBeingCalledExcessively: ${uniqName}`);
36
+ }
37
+ };