roamjs-components 0.86.0-alpha → 0.86.0-alpha.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 +18 -10
- package/patches/@blueprintjs+core+3.50.4.patch +48 -0
- package/patches/@blueprintjs+select+3.18.6.patch +12 -0
- package/src/components/AutocompleteInput.tsx +248 -248
- package/src/components/BlockErrorBoundary.tsx +5 -1
- package/src/components/BlockInput.tsx +117 -117
- package/src/components/ComponentContainer.tsx +70 -69
- package/src/components/ConfigPage.tsx +320 -320
- package/src/components/ConfigPanels/BlocksPanel.tsx +100 -100
- package/src/components/ConfigPanels/MultiChildPanel.tsx +99 -99
- package/src/components/ConfigPanels/OauthPanel.tsx +127 -127
- package/src/components/ConfigPanels/useSingleChildValue.tsx +63 -63
- package/src/components/CursorMenu.tsx +1 -1
- package/src/components/ExternalLogin.tsx +190 -190
- package/src/components/FormDialog.tsx +503 -503
- package/src/components/MenuItemSelect.tsx +7 -2
- package/src/components/OauthSelect.tsx +40 -40
- package/src/components/PageInput.tsx +17 -17
- package/src/components.tsx +43 -0
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Popover,
|
|
3
|
-
PopoverPosition,
|
|
4
|
-
Menu,
|
|
5
|
-
MenuItem,
|
|
6
|
-
InputGroup,
|
|
7
|
-
} from "@blueprintjs/core";
|
|
8
|
-
import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
9
|
-
import getAllBlockUidsAndTexts from "../queries/getAllBlockUidsAndTexts";
|
|
10
|
-
import useArrowKeyDown from "../hooks/useArrowKeyDown";
|
|
11
|
-
|
|
12
|
-
const searchBlocksByString = (
|
|
13
|
-
q: string,
|
|
14
|
-
blocks: { text: string; uid: string }[]
|
|
15
|
-
) => {
|
|
16
|
-
const regex = new RegExp(q, "i");
|
|
17
|
-
return blocks.filter((a) => regex.test(a.text)).slice(0, 9);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const BlockInput = ({
|
|
21
|
-
value,
|
|
22
|
-
setValue,
|
|
23
|
-
onBlur,
|
|
24
|
-
onConfirm,
|
|
25
|
-
getAllBlocks = getAllBlockUidsAndTexts,
|
|
26
|
-
autoFocus,
|
|
27
|
-
}: {
|
|
28
|
-
value: string;
|
|
29
|
-
setValue: (q: string, uid?: string) => void;
|
|
30
|
-
onBlur?: (v: string) => void;
|
|
31
|
-
onConfirm?: () => void;
|
|
32
|
-
getAllBlocks?: () => { text: string; uid: string }[];
|
|
33
|
-
autoFocus?: boolean;
|
|
34
|
-
}): React.ReactElement => {
|
|
35
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
-
const open = useCallback(() => setIsOpen(true), [setIsOpen]);
|
|
37
|
-
const close = useCallback(() => setIsOpen(false), [setIsOpen]);
|
|
38
|
-
const allBlocks = useMemo(getAllBlocks, []);
|
|
39
|
-
const items = useMemo(
|
|
40
|
-
() => (value && isOpen ? searchBlocksByString(value, allBlocks) : []),
|
|
41
|
-
[value, allBlocks]
|
|
42
|
-
);
|
|
43
|
-
const menuRef = useRef<HTMLUListElement>(null);
|
|
44
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
45
|
-
const { activeIndex, onKeyDown } = useArrowKeyDown({
|
|
46
|
-
onEnter: (value) => {
|
|
47
|
-
if (isOpen) {
|
|
48
|
-
setValue(value.text, value.uid);
|
|
49
|
-
close();
|
|
50
|
-
} else if (onConfirm) {
|
|
51
|
-
onConfirm();
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
results: items,
|
|
55
|
-
menuRef,
|
|
56
|
-
});
|
|
57
|
-
return (
|
|
58
|
-
<Popover
|
|
59
|
-
portalClassName={"roamjs-block-input"}
|
|
60
|
-
targetClassName={"roamjs-block-input-target"}
|
|
61
|
-
captureDismiss={true}
|
|
62
|
-
isOpen={isOpen}
|
|
63
|
-
onOpened={open}
|
|
64
|
-
minimal={true}
|
|
65
|
-
autoFocus={false}
|
|
66
|
-
enforceFocus={false}
|
|
67
|
-
position={PopoverPosition.BOTTOM_LEFT}
|
|
68
|
-
modifiers={{
|
|
69
|
-
flip: { enabled: false },
|
|
70
|
-
preventOverflow: { enabled: false },
|
|
71
|
-
}}
|
|
72
|
-
content={
|
|
73
|
-
<Menu className={"max-h-64 overflow-auto max-w-md"} ulRef={menuRef}>
|
|
74
|
-
{items.map((t, i) => (
|
|
75
|
-
<MenuItem
|
|
76
|
-
text={t.text}
|
|
77
|
-
active={activeIndex === i}
|
|
78
|
-
key={t.uid}
|
|
79
|
-
multiline
|
|
80
|
-
onClick={() => {
|
|
81
|
-
setValue(t.text, t.uid);
|
|
82
|
-
close();
|
|
83
|
-
inputRef.current?.focus();
|
|
84
|
-
}}
|
|
85
|
-
/>
|
|
86
|
-
))}
|
|
87
|
-
</Menu>
|
|
88
|
-
}
|
|
89
|
-
target={
|
|
90
|
-
<InputGroup
|
|
91
|
-
value={value || ""}
|
|
92
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
93
|
-
setValue(e.target.value);
|
|
94
|
-
setIsOpen(!!e.target.value);
|
|
95
|
-
}}
|
|
96
|
-
placeholder={"Search for a block"}
|
|
97
|
-
onKeyDown={onKeyDown}
|
|
98
|
-
onBlur={(e) => {
|
|
99
|
-
if (
|
|
100
|
-
e.relatedTarget &&
|
|
101
|
-
!(e.relatedTarget as HTMLElement).closest?.(".roamjs-block-input")
|
|
102
|
-
) {
|
|
103
|
-
close();
|
|
104
|
-
}
|
|
105
|
-
if (onBlur) {
|
|
106
|
-
onBlur(e.target.value);
|
|
107
|
-
}
|
|
108
|
-
}}
|
|
109
|
-
inputRef={inputRef}
|
|
110
|
-
autoFocus={autoFocus}
|
|
111
|
-
/>
|
|
112
|
-
}
|
|
113
|
-
/>
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export default BlockInput;
|
|
1
|
+
import {
|
|
2
|
+
Popover,
|
|
3
|
+
PopoverPosition,
|
|
4
|
+
Menu,
|
|
5
|
+
MenuItem,
|
|
6
|
+
InputGroup,
|
|
7
|
+
} from "@blueprintjs/core";
|
|
8
|
+
import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
9
|
+
import getAllBlockUidsAndTexts from "../queries/getAllBlockUidsAndTexts";
|
|
10
|
+
import useArrowKeyDown from "../hooks/useArrowKeyDown";
|
|
11
|
+
|
|
12
|
+
const searchBlocksByString = (
|
|
13
|
+
q: string,
|
|
14
|
+
blocks: { text: string; uid: string }[]
|
|
15
|
+
) => {
|
|
16
|
+
const regex = new RegExp(q, "i");
|
|
17
|
+
return blocks.filter((a) => regex.test(a.text)).slice(0, 9);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const BlockInput = ({
|
|
21
|
+
value,
|
|
22
|
+
setValue,
|
|
23
|
+
onBlur,
|
|
24
|
+
onConfirm,
|
|
25
|
+
getAllBlocks = getAllBlockUidsAndTexts,
|
|
26
|
+
autoFocus,
|
|
27
|
+
}: {
|
|
28
|
+
value: string;
|
|
29
|
+
setValue: (q: string, uid?: string) => void;
|
|
30
|
+
onBlur?: (v: string) => void;
|
|
31
|
+
onConfirm?: () => void;
|
|
32
|
+
getAllBlocks?: () => { text: string; uid: string }[];
|
|
33
|
+
autoFocus?: boolean;
|
|
34
|
+
}): React.ReactElement => {
|
|
35
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
+
const open = useCallback(() => setIsOpen(true), [setIsOpen]);
|
|
37
|
+
const close = useCallback(() => setIsOpen(false), [setIsOpen]);
|
|
38
|
+
const allBlocks = useMemo(getAllBlocks, []);
|
|
39
|
+
const items = useMemo(
|
|
40
|
+
() => (value && isOpen ? searchBlocksByString(value, allBlocks) : []),
|
|
41
|
+
[value, allBlocks]
|
|
42
|
+
);
|
|
43
|
+
const menuRef = useRef<HTMLUListElement>(null);
|
|
44
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
45
|
+
const { activeIndex, onKeyDown } = useArrowKeyDown({
|
|
46
|
+
onEnter: (value) => {
|
|
47
|
+
if (isOpen) {
|
|
48
|
+
setValue(value.text, value.uid);
|
|
49
|
+
close();
|
|
50
|
+
} else if (onConfirm) {
|
|
51
|
+
onConfirm();
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
results: items,
|
|
55
|
+
menuRef,
|
|
56
|
+
});
|
|
57
|
+
return (
|
|
58
|
+
<Popover
|
|
59
|
+
portalClassName={"roamjs-block-input"}
|
|
60
|
+
targetClassName={"roamjs-block-input-target"}
|
|
61
|
+
captureDismiss={true}
|
|
62
|
+
isOpen={isOpen}
|
|
63
|
+
onOpened={open}
|
|
64
|
+
minimal={true}
|
|
65
|
+
autoFocus={false}
|
|
66
|
+
enforceFocus={false}
|
|
67
|
+
position={PopoverPosition.BOTTOM_LEFT}
|
|
68
|
+
modifiers={{
|
|
69
|
+
flip: { enabled: false },
|
|
70
|
+
preventOverflow: { enabled: false },
|
|
71
|
+
}}
|
|
72
|
+
content={
|
|
73
|
+
<Menu className={"max-h-64 overflow-auto max-w-md"} ulRef={menuRef}>
|
|
74
|
+
{items.map((t, i) => (
|
|
75
|
+
<MenuItem
|
|
76
|
+
text={t.text}
|
|
77
|
+
active={activeIndex === i}
|
|
78
|
+
key={t.uid}
|
|
79
|
+
multiline
|
|
80
|
+
onClick={() => {
|
|
81
|
+
setValue(t.text, t.uid);
|
|
82
|
+
close();
|
|
83
|
+
inputRef.current?.focus();
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
))}
|
|
87
|
+
</Menu>
|
|
88
|
+
}
|
|
89
|
+
target={
|
|
90
|
+
<InputGroup
|
|
91
|
+
value={value || ""}
|
|
92
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
93
|
+
setValue(e.target.value);
|
|
94
|
+
setIsOpen(!!e.target.value);
|
|
95
|
+
}}
|
|
96
|
+
placeholder={"Search for a block"}
|
|
97
|
+
onKeyDown={onKeyDown}
|
|
98
|
+
onBlur={(e) => {
|
|
99
|
+
if (
|
|
100
|
+
e.relatedTarget &&
|
|
101
|
+
!(e.relatedTarget as HTMLElement).closest?.(".roamjs-block-input")
|
|
102
|
+
) {
|
|
103
|
+
close();
|
|
104
|
+
}
|
|
105
|
+
if (onBlur) {
|
|
106
|
+
onBlur(e.target.value);
|
|
107
|
+
}
|
|
108
|
+
}}
|
|
109
|
+
inputRef={inputRef}
|
|
110
|
+
autoFocus={autoFocus}
|
|
111
|
+
/>
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export default BlockInput;
|
|
@@ -1,69 +1,70 @@
|
|
|
1
|
-
import { Button } from "@blueprintjs/core";
|
|
2
|
-
import React, { useCallback, useState } from "react";
|
|
3
|
-
import getUidsFromId from "../dom/getUidsFromId";
|
|
4
|
-
import getBlockUidFromTarget from "../dom/getBlockUidFromTarget";
|
|
5
|
-
import renderWithUnmount from "../util/renderWithUnmount";
|
|
6
|
-
import { OnloadArgs } from "../types/native";
|
|
7
|
-
|
|
8
|
-
const ComponentContainer: React.FunctionComponent<{
|
|
9
|
-
blockId?: string;
|
|
10
|
-
className?: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
import { Button } from "@blueprintjs/core";
|
|
2
|
+
import React, { useCallback, useState } from "react";
|
|
3
|
+
import getUidsFromId from "../dom/getUidsFromId";
|
|
4
|
+
import getBlockUidFromTarget from "../dom/getBlockUidFromTarget";
|
|
5
|
+
import renderWithUnmount from "../util/renderWithUnmount";
|
|
6
|
+
import { OnloadArgs } from "../types/native";
|
|
7
|
+
|
|
8
|
+
const ComponentContainer: React.FunctionComponent<{
|
|
9
|
+
blockId?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}> = ({ blockId, className, children }) => {
|
|
13
|
+
const [showIcons, setShowIcons] = useState(false);
|
|
14
|
+
const appear = useCallback(() => setShowIcons(true), [setShowIcons]);
|
|
15
|
+
const disappear = useCallback(() => setShowIcons(false), [setShowIcons]);
|
|
16
|
+
|
|
17
|
+
const { blockUid, windowId } = getUidsFromId(blockId);
|
|
18
|
+
return (
|
|
19
|
+
<div
|
|
20
|
+
className={className}
|
|
21
|
+
onMouseOver={appear}
|
|
22
|
+
onMouseLeave={disappear}
|
|
23
|
+
style={{ position: "relative", width: "fit-content", minWidth: 300 }}
|
|
24
|
+
>
|
|
25
|
+
{showIcons && (
|
|
26
|
+
<div className={"roamjs-edit-component absolute top-2 right-2 z-50"}>
|
|
27
|
+
{blockId && (
|
|
28
|
+
<Button
|
|
29
|
+
icon="edit"
|
|
30
|
+
minimal
|
|
31
|
+
onClick={() =>
|
|
32
|
+
window.roamAlphaAPI.ui.setBlockFocusAndSelection({
|
|
33
|
+
location: { "block-uid": blockUid, "window-id": windowId },
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
/>
|
|
37
|
+
)}
|
|
38
|
+
</div>
|
|
39
|
+
)}
|
|
40
|
+
{children}
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const createComponentRender =
|
|
46
|
+
(
|
|
47
|
+
Fc: (props: { blockUid: string }) => React.ReactElement,
|
|
48
|
+
className?: string
|
|
49
|
+
) =>
|
|
50
|
+
(b: HTMLButtonElement, args?: OnloadArgs): void => {
|
|
51
|
+
if (b.parentElement) {
|
|
52
|
+
b.parentElement.onmousedown = (e: MouseEvent) => e.stopPropagation();
|
|
53
|
+
const blockUid = getBlockUidFromTarget(b);
|
|
54
|
+
const possibleBlockId = b.closest(".roam-block")?.id;
|
|
55
|
+
const blockId = possibleBlockId?.endsWith?.(blockUid)
|
|
56
|
+
? possibleBlockId
|
|
57
|
+
: undefined;
|
|
58
|
+
if (blockUid) {
|
|
59
|
+
renderWithUnmount(
|
|
60
|
+
<ComponentContainer blockId={blockId} className={className}>
|
|
61
|
+
<Fc blockUid={blockUid} />
|
|
62
|
+
</ComponentContainer>,
|
|
63
|
+
b.parentElement,
|
|
64
|
+
args
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default ComponentContainer;
|