@teselagen/ui 0.8.6-beta.25 → 0.8.6-beta.26

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.8.6-beta.25",
3
+ "version": "0.8.6-beta.26",
4
4
  "main": "./src/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "@dnd-kit/sortable": "^8.0.0",
20
20
  "@teselagen/react-table": "6.10.18",
21
21
  "classnames": "^2.3.2",
22
- "color": "^3.2.1",
22
+ "color": "^5.0.0",
23
23
  "copy-to-clipboard": "^3.3.1",
24
24
  "dayjs": "^1.10.4",
25
25
  "dom-scroll-into-view": "^2.0.1",
@@ -30,7 +30,7 @@
30
30
  "lodash-es": "^4.17.21",
31
31
  "math-expression-evaluator": "^1.3.7",
32
32
  "mobx": "^6.10.2",
33
- "nanoid": "^4.0.0",
33
+ "nanoid": "^5.1.5",
34
34
  "papaparse": "5.3.2",
35
35
  "qs": "^6.9.6",
36
36
  "react": "^18.3.1",
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import dayjs from "dayjs";
3
+ import { Classes } from "@blueprintjs/core";
4
+ import classNames from "classnames";
5
+ import relativeTime from "dayjs/plugin/relativeTime";
6
+
7
+ dayjs.extend(relativeTime);
8
+
9
+ interface TimelineEventProps {
10
+ date: string | number | Date | dayjs.Dayjs;
11
+ children?: React.ReactNode;
12
+ }
13
+
14
+ function TimelineEvent({ date, children }: TimelineEventProps) {
15
+ return (
16
+ <div className="tg-timeline-event">
17
+ <div
18
+ style={{
19
+ display: "flex",
20
+ alignItems: "center"
21
+ }}
22
+ >
23
+ <div className="tg-timeline-circle" />
24
+ {children}
25
+ <div
26
+ style={{ marginLeft: 5 }}
27
+ className={classNames(Classes.TEXT_SMALL, Classes.TEXT_MUTED)}
28
+ >
29
+ ({dayjs(date).fromNow()})
30
+ </div>
31
+ </div>
32
+ </div>
33
+ );
34
+ }
35
+
36
+ export default TimelineEvent;
@@ -0,0 +1,21 @@
1
+ import React, { ReactNode, FC } from "react";
2
+ import "./style.css";
3
+
4
+ interface TimelineProps {
5
+ children: ReactNode;
6
+ }
7
+
8
+ const Timeline: FC<TimelineProps> = props => {
9
+ return (
10
+ <div className="tg-timeline">
11
+ {React.Children.count(props.children) > 1 && (
12
+ <div className="tg-timeline-line" />
13
+ )}
14
+ {props.children}
15
+ </div>
16
+ );
17
+ };
18
+
19
+ export { default as TimelineEvent } from "./TimelineEvent";
20
+
21
+ export default Timeline;
package/src/index.js CHANGED
@@ -35,7 +35,6 @@ export { default as PromptUnsavedChanges } from "./PromptUnsavedChanges";
35
35
  export { default as BlueprintError } from "./BlueprintError";
36
36
  export { default as DropdownButton } from "./DropdownButton";
37
37
  export { default as DialogFooter } from "./DialogFooter";
38
- export { default as adHoc } from "./utils/adHoc";
39
38
  export { default as IntentText } from "./IntentText";
40
39
  export { default as popoverOverflowModifiers } from "./utils/popoverOverflowModifiers";
41
40
  export * from "./utils/tgFormValues";
@@ -0,0 +1,3 @@
1
+ export const isSafari = /^((?!chrome|android).)*safari/i.test(
2
+ navigator.userAgent
3
+ );
@@ -0,0 +1,11 @@
1
+ /* Copyright (C) 2018 TeselaGen Biotechnology, Inc. */
2
+ import Color from "color";
3
+
4
+ export default function determineBlackOrWhiteTextColor(c: string) {
5
+ try {
6
+ return Color(c).isLight() ? "#000000" : "#FFFFFF";
7
+ } catch (e) {
8
+ console.error("Error in color parsing:", e);
9
+ return "#000000"; // Fallback to black if color parsing fails
10
+ }
11
+ }
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+
3
+ type Node = React.ReactElement<{ children?: Node[] | Node }> | string | number;
4
+
5
+ const isReactElement = (
6
+ el: Node
7
+ ): el is React.ReactElement<{ children?: Node[] | Node }> => {
8
+ if (el) {
9
+ const newEl = el as React.ReactElement<{ children?: Node[] | Node }>;
10
+ if (newEl.props && newEl.props.children) {
11
+ return true;
12
+ }
13
+ }
14
+ return false;
15
+ };
16
+
17
+ export default function getTextFromEl<T extends Node>(
18
+ el: T,
19
+ options: { lowerCase?: boolean } = {}
20
+ ): string {
21
+ const { lowerCase } = options;
22
+ if (React.isValidElement<{ children?: Node[] | Node }>(el)) {
23
+ return el && el.props && el.props.children
24
+ ? (Array.isArray(el.props.children)
25
+ ? el.props.children
26
+ : [el.props.children]
27
+ ).reduce((acc: string, child) => {
28
+ if (isReactElement(child)) {
29
+ acc += getTextFromEl(child);
30
+ } else if (typeof child === "string") {
31
+ if (lowerCase) {
32
+ acc += child.toLowerCase();
33
+ } else {
34
+ acc += child;
35
+ }
36
+ } else if (typeof child === "number") {
37
+ acc += child + "";
38
+ }
39
+ return acc;
40
+ }, "")
41
+ : "";
42
+ } else {
43
+ return el as string;
44
+ }
45
+ }
@@ -0,0 +1,32 @@
1
+ export const onEnterHelper = (
2
+ callback: (event: React.KeyboardEvent<Element>) => void
3
+ ) => ({
4
+ onKeyDown: (event: React.KeyboardEvent<Element>) => {
5
+ if (event.key === "Enter") {
6
+ callback(event);
7
+ }
8
+ }
9
+ });
10
+
11
+ export const onBlurHelper = (
12
+ callback: (event: React.FocusEvent<Element>) => void
13
+ ) => ({
14
+ onBlur: (event: React.FocusEvent<Element>) => {
15
+ callback(event);
16
+ }
17
+ });
18
+
19
+ export const onEnterOrBlurHelper = (
20
+ callback: (
21
+ event: React.KeyboardEvent<Element> | React.FocusEvent<Element>
22
+ ) => void
23
+ ) => ({
24
+ onKeyDown: function (event: React.KeyboardEvent<Element>) {
25
+ if (event.key === "Enter") {
26
+ callback(event);
27
+ }
28
+ },
29
+ onBlur: function (event: React.FocusEvent<Element>) {
30
+ callback(event);
31
+ }
32
+ });
@@ -0,0 +1 @@
1
+ export { useDeepEqualMemo } from "./useDeepEqualMemo";
@@ -0,0 +1,10 @@
1
+ import { isEqual } from "lodash-es";
2
+ import { useRef } from "react";
3
+
4
+ export const useDeepEqualMemo = (value: unknown) => {
5
+ const ref = useRef<unknown>();
6
+ if (!isEqual(value, ref.current)) {
7
+ ref.current = value;
8
+ }
9
+ return ref.current;
10
+ };
@@ -0,0 +1,9 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ export const useStableReference = (value: unknown) => {
4
+ const ref = useRef<unknown>();
5
+ useEffect(() => {
6
+ ref.current = value;
7
+ }, [value]);
8
+ return ref;
9
+ };
@@ -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
+ };
@@ -1 +1 @@
1
- export const isSafari: boolean;
1
+ export declare const isSafari: boolean;
@@ -1 +1 @@
1
- export default function determineBlackOrWhiteTextColor(c: any): "#000000" | "#FFFFFF";
1
+ export default function determineBlackOrWhiteTextColor(c: string): "#000000" | "#FFFFFF";
@@ -1 +1,8 @@
1
- export default function getTextFromEl(el: any, options?: {}): any;
1
+ import { default as React } from '../../../../node_modules/react';
2
+ type Node = React.ReactElement<{
3
+ children?: Node[] | Node;
4
+ }> | string | number;
5
+ export default function getTextFromEl<T extends Node>(el: T, options?: {
6
+ lowerCase?: boolean;
7
+ }): string;
8
+ export {};
@@ -1,10 +1,10 @@
1
- export function onEnterHelper(callback: any): {
2
- onKeyDown: (event: any) => void;
1
+ export declare const onEnterHelper: (callback: (event: React.KeyboardEvent<Element>) => void) => {
2
+ onKeyDown: (event: React.KeyboardEvent<Element>) => void;
3
3
  };
4
- export function onBlurHelper(callback: any): {
5
- onBlur: (event: any) => void;
4
+ export declare const onBlurHelper: (callback: (event: React.FocusEvent<Element>) => void) => {
5
+ onBlur: (event: React.FocusEvent<Element>) => void;
6
6
  };
7
- export function onEnterOrBlurHelper(callback: any): {
8
- onKeyDown: (event: any) => void;
9
- onBlur: (event: any) => void;
7
+ export declare const onEnterOrBlurHelper: (callback: (event: React.KeyboardEvent<Element> | React.FocusEvent<Element>) => void) => {
8
+ onKeyDown: (event: React.KeyboardEvent<Element>) => void;
9
+ onBlur: (event: React.FocusEvent<Element>) => void;
10
10
  };
@@ -1,2 +1 @@
1
- export function useDeepEqualMemo(value: any): undefined;
2
- export function useDeepEqualEffect(effect: any, deps: any): void;
1
+ export declare const useDeepEqualMemo: (value: unknown) => unknown;
@@ -1 +1 @@
1
- export function useStableReference(value: any): import('../../../../../node_modules/react').MutableRefObject<undefined>;
1
+ export declare const useStableReference: (value: unknown) => import('../../../../../node_modules/react').MutableRefObject<unknown>;
@@ -1,4 +1,21 @@
1
- export function comboToLabel(def: any, useSymbols?: boolean): any;
2
- export function hotkeysById(hotkeys: any, mode?: string): (id: any) => any;
3
- export function getHotkeyProps(def: any, id: any): any;
4
- export function withHotkeys(hotkeys: any, handlers: any): ({ children }?: {}) => import("react/jsx-runtime").JSX.Element;
1
+ import { default as React } from '../../../../node_modules/react';
2
+ type Out = {
3
+ combo: string;
4
+ label: string;
5
+ [key: string]: unknown;
6
+ global?: boolean;
7
+ };
8
+ type Hotkeys = {
9
+ [key: string]: string | [string, string, object] | Out;
10
+ };
11
+ export declare function comboToLabel(def: string | {
12
+ combo: string;
13
+ }, useSymbols?: boolean): string;
14
+ export declare const hotkeysById: (hotkeys: Hotkeys, mode?: string) => (id: string) => string;
15
+ export declare const getHotkeyProps: (def: string | [string, string, object] | Out, id?: string) => Out;
16
+ export declare const withHotkeys: (hotkeys: Hotkeys, handlers: {
17
+ [key: string]: (e: KeyboardEvent) => void;
18
+ }) => ({ children }?: {
19
+ children?: React.ReactElement;
20
+ }) => import("react/jsx-runtime").JSX.Element;
21
+ export {};
@@ -1,3 +1,3 @@
1
- export function isBeingCalledExcessively({ uniqName }: {
2
- uniqName: any;
3
- }): void;
1
+ export declare const isBeingCalledExcessively: ({ uniqName }: {
2
+ uniqName: string;
3
+ }) => void;