roamjs-components 0.53.2 → 0.53.5
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/LICENSE +21 -21
- package/README.md +154 -154
- package/backend/emailCatch.d.ts +4 -4
- package/backend/emailCatch.js +11 -11
- package/backend/emailError.d.ts +4 -4
- package/backend/emailError.js +56 -56
- package/backend/getRoamJSUser.d.ts +11 -11
- package/backend/getRoamJSUser.js +30 -30
- package/backend/headers.d.ts +5 -5
- package/backend/headers.js +7 -7
- package/backend/index.d.ts +6 -6
- package/backend/index.js +20 -20
- package/backend/meterRoamJSUser.d.ts +4 -4
- package/backend/meterRoamJSUser.js +14 -14
- package/backend/putRoamJSUser.d.ts +10 -10
- package/backend/putRoamJSUser.js +25 -25
- package/components/BlockErrorBoundary.d.ts +15 -15
- package/components/BlockErrorBoundary.js +27 -27
- package/components/BlockInput.d.ts +12 -12
- package/components/BlockInput.js +53 -53
- package/components/ComponentContainer.d.ts +9 -9
- package/components/ComponentContainer.js +46 -46
- package/components/ConfigPage.d.ts +99 -99
- package/components/ConfigPage.js +751 -751
- package/components/CursorMenu.d.ts +21 -21
- package/components/CursorMenu.js +181 -181
- package/components/Description.d.ts +5 -5
- package/components/Description.js +16 -16
- package/components/ExternalLogin.d.ts +18 -18
- package/components/ExternalLogin.js +131 -131
- package/components/Filter.d.ts +14 -14
- package/components/Filter.js +147 -147
- package/components/Loading.d.ts +4 -4
- package/components/Loading.js +33 -33
- package/components/MenuItemSelect.d.ts +10 -10
- package/components/MenuItemSelect.js +13 -13
- package/components/OauthSelect.d.ts +5 -5
- package/components/OauthSelect.js +25 -25
- package/components/PageInput.d.ts +10 -10
- package/components/PageInput.js +69 -69
- package/components/ServiceComponents.d.ts +49 -49
- package/components/ServiceComponents.js +277 -277
- package/components/SimpleAlert.d.ts +12 -12
- package/components/SimpleAlert.js +38 -38
- package/components/Toast.d.ts +10 -10
- package/components/Toast.js +41 -41
- package/components/TokenDialog.d.ts +11 -11
- package/components/TokenDialog.js +100 -100
- package/components/index.d.ts +15 -15
- package/components/index.js +60 -60
- package/date/constants.d.ts +2 -2
- package/date/constants.js +5 -5
- package/date/index.d.ts +5 -5
- package/date/index.js +13 -13
- package/date/parseRoamDate.d.ts +2 -2
- package/date/parseRoamDate.js +6 -6
- package/date/parseRoamDateUid.d.ts +2 -2
- package/date/parseRoamDateUid.js +6 -6
- package/date/toRoamDate.d.ts +2 -2
- package/date/toRoamDate.js +6 -6
- package/date/toRoamDateUid.d.ts +2 -2
- package/date/toRoamDateUid.js +6 -6
- package/dom/addBlockCommand.d.ts +5 -5
- package/dom/addBlockCommand.js +53 -53
- package/dom/addOldRoamJSDependency.d.ts +2 -2
- package/dom/addOldRoamJSDependency.js +10 -10
- package/dom/addRoamJSDependency.d.ts +2 -2
- package/dom/addRoamJSDependency.js +8 -8
- package/dom/addScriptAsDependency.d.ts +6 -6
- package/dom/addScriptAsDependency.js +16 -16
- package/dom/addStyle.d.ts +2 -2
- package/dom/addStyle.js +14 -14
- package/dom/constants.d.ts +1 -1
- package/dom/constants.js +4 -4
- package/dom/createBlockObserver.d.ts +7 -7
- package/dom/createBlockObserver.js +43 -43
- package/dom/createButtonObserver.d.ts +6 -6
- package/dom/createButtonObserver.js +21 -21
- package/dom/createDivObserver.d.ts +2 -2
- package/dom/createDivObserver.js +8 -8
- package/dom/createHTMLObserver.d.ts +8 -8
- package/dom/createHTMLObserver.js +24 -24
- package/dom/createHashtagObserver.d.ts +5 -5
- package/dom/createHashtagObserver.js +16 -16
- package/dom/createIconButton.d.ts +2 -2
- package/dom/createIconButton.js +12 -12
- package/dom/createObserver.d.ts +2 -2
- package/dom/createObserver.js +6 -6
- package/dom/createOverlayObserver.d.ts +2 -2
- package/dom/createOverlayObserver.js +6 -6
- package/dom/createPageObserver.d.ts +2 -2
- package/dom/createPageObserver.js +34 -34
- package/dom/createPageTitleObserver.d.ts +6 -6
- package/dom/createPageTitleObserver.js +29 -29
- package/dom/genericError.d.ts +4 -4
- package/dom/genericError.js +16 -16
- package/dom/getActiveUids.d.ts +3 -3
- package/dom/getActiveUids.js +6 -6
- package/dom/getBlockUidFromTarget.d.ts +2 -2
- package/dom/getBlockUidFromTarget.js +33 -33
- package/dom/getCurrentPageUid.d.ts +2 -2
- package/dom/getCurrentPageUid.js +6 -6
- package/dom/getDomRefs.d.ts +2 -2
- package/dom/getDomRefs.js +12 -12
- package/dom/getDropUidOffset.d.ts +5 -5
- package/dom/getDropUidOffset.js +27 -27
- package/dom/getMutatedNodes.d.ts +7 -7
- package/dom/getMutatedNodes.js +11 -11
- package/dom/getPageTitleByHtmlElement.d.ts +2 -2
- package/dom/getPageTitleByHtmlElement.js +12 -12
- package/dom/getPageTitleValueByHtmlElement.d.ts +2 -2
- package/dom/getPageTitleValueByHtmlElement.js +27 -27
- package/dom/getReferenceBlockUid.d.ts +2 -2
- package/dom/getReferenceBlockUid.js +18 -18
- package/dom/getRoamUrl.d.ts +2 -2
- package/dom/getRoamUrl.js +4 -4
- package/dom/getRoamUrlByPage.d.ts +2 -2
- package/dom/getRoamUrlByPage.js +10 -10
- package/dom/getUids.d.ts +3 -3
- package/dom/getUids.js +8 -8
- package/dom/getUidsFromButton.d.ts +3 -3
- package/dom/getUidsFromButton.js +9 -9
- package/dom/getUidsFromId.d.ts +5 -5
- package/dom/getUidsFromId.js +15 -15
- package/dom/index.d.ts +31 -31
- package/dom/index.js +65 -65
- package/dom/openBlock.d.ts +2 -2
- package/dom/openBlock.js +6 -6
- package/dom/openBlockElement.d.ts +2 -2
- package/dom/openBlockElement.js +16 -16
- package/dom/parseRoamBlocksToHtml.d.ts +9 -9
- package/dom/parseRoamBlocksToHtml.js +75 -75
- package/dom/resolveRefs.d.ts +2 -2
- package/dom/resolveRefs.js +24 -24
- package/events/index.d.ts +1 -1
- package/events/index.js +8 -8
- package/events/watchOnce.d.ts +3 -3
- package/events/watchOnce.js +11 -11
- package/hooks/index.d.ts +3 -3
- package/hooks/index.js +12 -12
- package/hooks/useArrowKeyDown.d.ts +8 -8
- package/hooks/useArrowKeyDown.js +31 -31
- package/hooks/useRoamJSTokenWarning.d.ts +2 -2
- package/hooks/useRoamJSTokenWarning.js +11 -11
- package/hooks/useSubTree.d.ts +3 -3
- package/hooks/useSubTree.js +11 -11
- package/index.d.ts +11 -11
- package/index.js +14 -14
- package/marked/index.d.ts +14 -14
- package/marked/index.js +518 -518
- package/package.json +86 -86
- package/queries/getAllBlockUids.d.ts +2 -2
- package/queries/getAllBlockUids.js +6 -6
- package/queries/getAllBlockUidsAndTexts.d.ts +5 -5
- package/queries/getAllBlockUidsAndTexts.js +6 -6
- package/queries/getAllPageNames.d.ts +2 -2
- package/queries/getAllPageNames.js +6 -6
- package/queries/getAttributeValueByBlockAndName.d.ts +5 -5
- package/queries/getAttributeValueByBlockAndName.js +11 -11
- package/queries/getBasicTreeByParentUid.d.ts +3 -3
- package/queries/getBasicTreeByParentUid.js +13 -13
- package/queries/getBlockUidAndTextIncludingText.d.ts +5 -5
- package/queries/getBlockUidAndTextIncludingText.js +6 -6
- package/queries/getBlockUidByTextOnPage.d.ts +5 -5
- package/queries/getBlockUidByTextOnPage.js +7 -7
- package/queries/getBlockUidsAndTextsReferencingPage.d.ts +5 -5
- package/queries/getBlockUidsAndTextsReferencingPage.js +11 -11
- package/queries/getBlockUidsByPageTitle.d.ts +2 -2
- package/queries/getBlockUidsByPageTitle.js +8 -8
- package/queries/getBlockUidsReferencingBlock.d.ts +2 -2
- package/queries/getBlockUidsReferencingBlock.js +6 -6
- package/queries/getBlockUidsReferencingPage.d.ts +2 -2
- package/queries/getBlockUidsReferencingPage.js +8 -8
- package/queries/getBlockUidsWithParentUid.d.ts +2 -2
- package/queries/getBlockUidsWithParentUid.js +6 -6
- package/queries/getChildrenLengthByPageUid.d.ts +2 -2
- package/queries/getChildrenLengthByPageUid.js +4 -4
- package/queries/getCreateTimeByBlockUid.d.ts +2 -2
- package/queries/getCreateTimeByBlockUid.js +7 -7
- package/queries/getCurrentUser.d.ts +2 -2
- package/queries/getCurrentUser.js +11 -11
- package/queries/getCurrentUserDisplayName.d.ts +2 -2
- package/queries/getCurrentUserDisplayName.js +13 -13
- package/queries/getCurrentUserEmail.d.ts +2 -2
- package/queries/getCurrentUserEmail.js +13 -13
- package/queries/getCurrentUserUid.d.ts +2 -2
- package/queries/getCurrentUserUid.js +13 -13
- package/queries/getDisplayNameByEmail.d.ts +2 -2
- package/queries/getDisplayNameByEmail.js +7 -7
- package/queries/getDisplayNameByUid.d.ts +2 -2
- package/queries/getDisplayNameByUid.js +7 -7
- package/queries/getEditTimeByBlockUid.d.ts +2 -2
- package/queries/getEditTimeByBlockUid.js +7 -7
- package/queries/getEditedUserEmailByBlockUid.d.ts +2 -2
- package/queries/getEditedUserEmailByBlockUid.js +7 -7
- package/queries/getFirstChildTextByBlockUid.d.ts +2 -2
- package/queries/getFirstChildTextByBlockUid.js +7 -7
- package/queries/getFirstChildUidByBlockUid.d.ts +2 -2
- package/queries/getFirstChildUidByBlockUid.js +5 -5
- package/queries/getFullTreeByParentUid.d.ts +3 -3
- package/queries/getFullTreeByParentUid.js +26 -26
- package/queries/getLinkedPageTitlesUnderUid.d.ts +2 -2
- package/queries/getLinkedPageTitlesUnderUid.js +6 -6
- package/queries/getNthChildUidByBlockUid.d.ts +5 -5
- package/queries/getNthChildUidByBlockUid.js +7 -7
- package/queries/getOrderByBlockUid.d.ts +2 -2
- package/queries/getOrderByBlockUid.js +7 -7
- package/queries/getPageTitleByBlockUid.d.ts +2 -2
- package/queries/getPageTitleByBlockUid.js +7 -7
- package/queries/getPageTitleByPageUid.d.ts +2 -2
- package/queries/getPageTitleByPageUid.js +9 -9
- package/queries/getPageTitleReferencesByPageTitle.d.ts +2 -2
- package/queries/getPageTitleReferencesByPageTitle.js +8 -8
- package/queries/getPageTitlesAndBlockUidsReferencingPage.d.ts +5 -5
- package/queries/getPageTitlesAndBlockUidsReferencingPage.js +8 -8
- package/queries/getPageTitlesAndUidsDirectlyReferencingPage.d.ts +5 -5
- package/queries/getPageTitlesAndUidsDirectlyReferencingPage.js +8 -8
- package/queries/getPageTitlesReferencingBlockUid.d.ts +2 -2
- package/queries/getPageTitlesReferencingBlockUid.js +6 -6
- package/queries/getPageTitlesStartingWithPrefix.d.ts +2 -2
- package/queries/getPageTitlesStartingWithPrefix.js +6 -6
- package/queries/getPageUidByPageTitle.d.ts +2 -2
- package/queries/getPageUidByPageTitle.js +9 -9
- package/queries/getPageViewType.d.ts +3 -3
- package/queries/getPageViewType.js +9 -9
- package/queries/getParentTextByBlockUid.d.ts +2 -2
- package/queries/getParentTextByBlockUid.js +7 -7
- package/queries/getParentTextByBlockUidAndTag.d.ts +5 -5
- package/queries/getParentTextByBlockUidAndTag.js +7 -7
- package/queries/getParentUidByBlockUid.d.ts +2 -2
- package/queries/getParentUidByBlockUid.js +7 -7
- package/queries/getParentUidsOfBlockUid.d.ts +2 -2
- package/queries/getParentUidsOfBlockUid.js +6 -6
- package/queries/getSettingsByEmail.d.ts +3 -3
- package/queries/getSettingsByEmail.js +7 -7
- package/queries/getShallowTreeByParentUid.d.ts +5 -5
- package/queries/getShallowTreeByParentUid.js +10 -10
- package/queries/getTextByBlockUid.d.ts +2 -2
- package/queries/getTextByBlockUid.js +7 -7
- package/queries/index.d.ts +45 -45
- package/queries/index.js +96 -96
- package/queries/isTagOnPage.d.ts +5 -5
- package/queries/isTagOnPage.js +9 -9
- package/queries/normalizePageTitle.d.ts +2 -2
- package/queries/normalizePageTitle.js +4 -4
- package/types/index.d.ts +461 -459
- package/types/index.js +2 -2
- package/types/query-builder.d.ts +16 -16
- package/types/query-builder.js +2 -2
- package/util/addInputSetting.d.ts +7 -7
- package/util/addInputSetting.js +25 -25
- package/util/apiDelete.d.ts +2 -2
- package/util/apiDelete.js +9 -9
- package/util/apiGet.d.ts +2 -2
- package/util/apiGet.js +9 -9
- package/util/apiPost.d.ts +2 -2
- package/util/apiPost.js +9 -9
- package/util/apiPut.d.ts +2 -2
- package/util/apiPut.js +9 -9
- package/util/createOverlayRender.d.ts +6 -6
- package/util/createOverlayRender.js +18 -18
- package/util/createTagRegex.d.ts +2 -2
- package/util/createTagRegex.js +4 -4
- package/util/extractRef.d.ts +2 -2
- package/util/extractRef.js +8 -8
- package/util/extractTag.d.ts +2 -2
- package/util/extractTag.js +12 -12
- package/util/getAuthorizationHeader.d.ts +2 -2
- package/util/getAuthorizationHeader.js +12 -12
- package/util/getGraph.d.ts +2 -2
- package/util/getGraph.js +8 -8
- package/util/getLocalStorageKey.d.ts +2 -2
- package/util/getLocalStorageKey.js +6 -6
- package/util/getOauth.d.ts +2 -2
- package/util/getOauth.js +50 -50
- package/util/getOauthAccounts.d.ts +2 -2
- package/util/getOauthAccounts.js +21 -21
- package/util/getRenderRoot.d.ts +2 -2
- package/util/getRenderRoot.js +11 -11
- package/util/getSettingIntFromTree.d.ts +7 -7
- package/util/getSettingIntFromTree.js +11 -11
- package/util/getSettingValueFromTree.d.ts +7 -7
- package/util/getSettingValueFromTree.js +13 -13
- package/util/getSettingValuesFromTree.d.ts +7 -7
- package/util/getSettingValuesFromTree.js +12 -12
- package/util/getSubTree.d.ts +8 -8
- package/util/getSubTree.js +19 -19
- package/util/getToken.d.ts +2 -2
- package/util/getToken.js +9 -9
- package/util/getTokenFromTree.d.ts +2 -2
- package/util/getTokenFromTree.js +5 -5
- package/util/idToTitle.d.ts +2 -2
- package/util/idToTitle.js +8 -8
- package/util/index.d.ts +23 -23
- package/util/index.js +52 -52
- package/util/isControl.d.ts +2 -2
- package/util/isControl.js +6 -6
- package/util/localStorageGet.d.ts +2 -2
- package/util/localStorageGet.js +8 -8
- package/util/localStorageRemove.d.ts +2 -2
- package/util/localStorageRemove.js +6 -6
- package/util/localStorageSet.d.ts +2 -2
- package/util/localStorageSet.js +8 -8
- package/util/registerSmartBlocksCommand.d.ts +8 -8
- package/util/registerSmartBlocksCommand.js +24 -24
- package/util/runExtension.d.ts +4 -4
- package/util/runExtension.js +40 -40
- package/util/setInputSetting.d.ts +7 -7
- package/util/setInputSetting.js +33 -33
- package/util/setInputSettings.d.ts +7 -7
- package/util/setInputSettings.js +28 -28
- package/util/toConfigPageName.d.ts +2 -2
- package/util/toConfigPageName.js +4 -4
- package/util/toFlexRegex.d.ts +2 -2
- package/util/toFlexRegex.js +4 -4
- package/writes/clearBlockById.d.ts +2 -2
- package/writes/clearBlockById.js +11 -11
- package/writes/clearBlockByUid.d.ts +2 -2
- package/writes/clearBlockByUid.js +9 -9
- package/writes/createBlock.d.ts +9 -9
- package/writes/createBlock.js +61 -61
- package/writes/createPage.d.ts +7 -7
- package/writes/createPage.js +18 -18
- package/writes/deleteBlock.d.ts +2 -2
- package/writes/deleteBlock.js +6 -6
- package/writes/index.d.ts +8 -8
- package/writes/index.js +22 -22
- package/writes/openBlockInSidebar.d.ts +2 -2
- package/writes/openBlockInSidebar.js +13 -13
- package/writes/updateActiveBlock.d.ts +2 -2
- package/writes/updateActiveBlock.js +11 -11
- package/writes/updateBlock.d.ts +5 -5
- package/writes/updateBlock.js +17 -17
package/components/ConfigPage.js
CHANGED
|
@@ -1,335 +1,335 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConfigObserver = exports.render = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const core_1 = require("@blueprintjs/core");
|
|
6
|
-
const datetime_1 = require("@blueprintjs/datetime");
|
|
7
|
-
const react_1 = (0, tslib_1.__importStar)(require("react"));
|
|
8
|
-
const react_dom_1 = (0, tslib_1.__importDefault)(require("react-dom"));
|
|
9
|
-
const dom_1 = require("../dom");
|
|
10
|
-
const writes_1 = require("../writes");
|
|
11
|
-
const queries_1 = require("../queries");
|
|
12
|
-
const localStorageGet_1 = (0, tslib_1.__importDefault)(require("../util/localStorageGet"));
|
|
13
|
-
const localStorageRemove_1 = (0, tslib_1.__importDefault)(require("../util/localStorageRemove"));
|
|
14
|
-
const localStorageSet_1 = (0, tslib_1.__importDefault)(require("../util/localStorageSet"));
|
|
15
|
-
const startOfDay_1 = (0, tslib_1.__importDefault)(require("date-fns/startOfDay"));
|
|
16
|
-
const Description_1 = (0, tslib_1.__importDefault)(require("./Description"));
|
|
17
|
-
const ExternalLogin_1 = (0, tslib_1.__importDefault)(require("./ExternalLogin"));
|
|
18
|
-
const idToTitle_1 = (0, tslib_1.__importDefault)(require("../util/idToTitle"));
|
|
19
|
-
const MenuItemSelect_1 = (0, tslib_1.__importDefault)(require("./MenuItemSelect"));
|
|
20
|
-
const PageInput_1 = (0, tslib_1.__importDefault)(require("./PageInput"));
|
|
21
|
-
const format_1 = (0, tslib_1.__importDefault)(require("date-fns/format"));
|
|
22
|
-
const axios_1 = (0, tslib_1.__importDefault)(require("axios"));
|
|
23
|
-
const color_1 = (0, tslib_1.__importDefault)(require("color"));
|
|
24
|
-
const getAuthorizationHeader_1 = (0, tslib_1.__importDefault)(require("../util/getAuthorizationHeader"));
|
|
25
|
-
const TokenDialog_1 = require("./TokenDialog");
|
|
26
|
-
const useSingleChildValue = ({ defaultValue, uid: initialUid, title, parentUid, order, transform, toStr, }) => {
|
|
27
|
-
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
28
|
-
const [valueUid, setValueUid] = (0, react_1.useState)(uid && (0, queries_1.getFirstChildUidByBlockUid)(uid));
|
|
29
|
-
const [value, setValue] = (0, react_1.useState)((valueUid && transform((0, queries_1.getTextByBlockUid)(valueUid))) || defaultValue);
|
|
30
|
-
const onChange = (0, react_1.useCallback)((v) => {
|
|
31
|
-
setValue(v);
|
|
32
|
-
if (valueUid) {
|
|
33
|
-
window.roamAlphaAPI.updateBlock({
|
|
34
|
-
block: { string: toStr(v), uid: valueUid },
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
else if (uid) {
|
|
38
|
-
const newValueUid = window.roamAlphaAPI.util.generateUID();
|
|
39
|
-
window.roamAlphaAPI.createBlock({
|
|
40
|
-
block: { string: toStr(v), uid: newValueUid },
|
|
41
|
-
location: { order: 0, "parent-uid": uid },
|
|
42
|
-
});
|
|
43
|
-
setValueUid(newValueUid);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
47
|
-
window.roamAlphaAPI.createBlock({
|
|
48
|
-
block: { string: title, uid: newUid },
|
|
49
|
-
location: { order, "parent-uid": parentUid },
|
|
50
|
-
});
|
|
51
|
-
setTimeout(() => setUid(newUid));
|
|
52
|
-
const newValueUid = window.roamAlphaAPI.util.generateUID();
|
|
53
|
-
window.roamAlphaAPI.createBlock({
|
|
54
|
-
block: { string: toStr(v), uid: newValueUid },
|
|
55
|
-
location: { order: 0, "parent-uid": newUid },
|
|
56
|
-
});
|
|
57
|
-
setValueUid(newValueUid);
|
|
58
|
-
}
|
|
59
|
-
}, [setValue, setValueUid, title, parentUid, order, uid, valueUid, setUid]);
|
|
60
|
-
return { value, onChange };
|
|
61
|
-
};
|
|
62
|
-
const MultiChildPanel = ({ uid: initialUid, title, description, order, parentUid, InputComponent, }) => {
|
|
63
|
-
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
64
|
-
const [texts, setTexts] = (0, react_1.useState)(() => uid ? (0, queries_1.getShallowTreeByParentUid)(uid) : []);
|
|
65
|
-
const [value, setValue] = (0, react_1.useState)("");
|
|
66
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
67
|
-
react_1.default.createElement(core_1.Label, null,
|
|
68
|
-
(0, idToTitle_1.default)(title),
|
|
69
|
-
react_1.default.createElement(Description_1.default, { description: description }),
|
|
70
|
-
react_1.default.createElement("div", { style: { display: "flex" } },
|
|
71
|
-
react_1.default.createElement(InputComponent, { value: value, setValue: setValue }),
|
|
72
|
-
react_1.default.createElement(core_1.Button, { icon: "plus", minimal: true, disabled: !value, onClick: () => {
|
|
73
|
-
const valueUid = window.roamAlphaAPI.util.generateUID();
|
|
74
|
-
if (uid) {
|
|
75
|
-
window.roamAlphaAPI.createBlock({
|
|
76
|
-
location: { "parent-uid": uid, order: texts.length },
|
|
77
|
-
block: { string: value, uid: valueUid },
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
82
|
-
window.roamAlphaAPI.createBlock({
|
|
83
|
-
block: { string: title, uid: newUid },
|
|
84
|
-
location: { order, "parent-uid": parentUid },
|
|
85
|
-
});
|
|
86
|
-
setTimeout(() => setUid(newUid));
|
|
87
|
-
window.roamAlphaAPI.createBlock({
|
|
88
|
-
block: { string: value, uid: valueUid },
|
|
89
|
-
location: { order: 0, "parent-uid": newUid },
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
setTexts([...texts, { text: value, uid: valueUid }]);
|
|
93
|
-
setValue("");
|
|
94
|
-
} }))),
|
|
95
|
-
texts.map((p) => (react_1.default.createElement("div", { key: p.uid, style: {
|
|
96
|
-
display: "flex",
|
|
97
|
-
alignItems: "center",
|
|
98
|
-
justifyContent: "space-between",
|
|
99
|
-
} },
|
|
100
|
-
react_1.default.createElement("span", { style: {
|
|
101
|
-
textOverflow: "ellipsis",
|
|
102
|
-
whiteSpace: "nowrap",
|
|
103
|
-
overflow: "hidden",
|
|
104
|
-
} }, p.text),
|
|
105
|
-
react_1.default.createElement(core_1.Button, { icon: "trash", minimal: true, onClick: () => {
|
|
106
|
-
window.roamAlphaAPI.deleteBlock({ block: { uid: p.uid } });
|
|
107
|
-
setTexts(texts.filter((f) => f.uid !== p.uid));
|
|
108
|
-
} }))))));
|
|
109
|
-
};
|
|
110
|
-
const TextPanel = ({ title, uid, parentUid, order, description, defaultValue = "", }) => {
|
|
111
|
-
const { value, onChange } = useSingleChildValue({
|
|
112
|
-
defaultValue,
|
|
113
|
-
title,
|
|
114
|
-
uid,
|
|
115
|
-
parentUid,
|
|
116
|
-
order,
|
|
117
|
-
transform: (s) => s,
|
|
118
|
-
toStr: (s) => s,
|
|
119
|
-
});
|
|
120
|
-
return (react_1.default.createElement(core_1.Label, null,
|
|
121
|
-
(0, idToTitle_1.default)(title),
|
|
122
|
-
react_1.default.createElement(Description_1.default, { description: description }),
|
|
123
|
-
react_1.default.createElement(core_1.InputGroup, { value: value, onChange: (e) => onChange(e.target.value) })));
|
|
124
|
-
};
|
|
125
|
-
const TimePanel = ({ title, uid, parentUid, order, description, defaultValue = (0, startOfDay_1.default)(new Date()), }) => {
|
|
126
|
-
const { value, onChange } = useSingleChildValue({
|
|
127
|
-
defaultValue,
|
|
128
|
-
title,
|
|
129
|
-
uid,
|
|
130
|
-
parentUid,
|
|
131
|
-
order,
|
|
132
|
-
transform: (s) => {
|
|
133
|
-
const d = new Date();
|
|
134
|
-
const [hours, minutes] = s.split(":");
|
|
135
|
-
d.setHours(Number(hours));
|
|
136
|
-
d.setMinutes(Number(minutes));
|
|
137
|
-
return d;
|
|
138
|
-
},
|
|
139
|
-
toStr: (v) => (0, format_1.default)(v, "HH:mm"),
|
|
140
|
-
});
|
|
141
|
-
return (react_1.default.createElement(core_1.Label, null,
|
|
142
|
-
(0, idToTitle_1.default)(title),
|
|
143
|
-
react_1.default.createElement(Description_1.default, { description: description }),
|
|
144
|
-
react_1.default.createElement(datetime_1.TimePicker, { value: value, onChange: onChange, showArrowButtons: true })));
|
|
145
|
-
};
|
|
146
|
-
const NumberPanel = ({ title, uid, parentUid, order, description, defaultValue = 0, }) => {
|
|
147
|
-
const { value, onChange } = useSingleChildValue({
|
|
148
|
-
defaultValue,
|
|
149
|
-
title,
|
|
150
|
-
uid,
|
|
151
|
-
parentUid,
|
|
152
|
-
order,
|
|
153
|
-
transform: parseInt,
|
|
154
|
-
toStr: (v) => `${v}`,
|
|
155
|
-
});
|
|
156
|
-
return (react_1.default.createElement(core_1.Label, null,
|
|
157
|
-
(0, idToTitle_1.default)(title),
|
|
158
|
-
react_1.default.createElement(Description_1.default, { description: description }),
|
|
159
|
-
react_1.default.createElement(core_1.NumericInput, { value: value, onValueChange: onChange })));
|
|
160
|
-
};
|
|
161
|
-
const SelectPanel = ({ title, uid, parentUid, order, description, defaultValue = "", options: { items }, }) => {
|
|
162
|
-
const { value, onChange } = useSingleChildValue({
|
|
163
|
-
defaultValue: defaultValue || items[0],
|
|
164
|
-
title,
|
|
165
|
-
uid,
|
|
166
|
-
parentUid,
|
|
167
|
-
order,
|
|
168
|
-
transform: (s) => s,
|
|
169
|
-
toStr: (s) => s,
|
|
170
|
-
});
|
|
171
|
-
return (react_1.default.createElement(core_1.Label, null,
|
|
172
|
-
(0, idToTitle_1.default)(title),
|
|
173
|
-
react_1.default.createElement(Description_1.default, { description: description }),
|
|
174
|
-
react_1.default.createElement(MenuItemSelect_1.default, { activeItem: value, onItemSelect: (e) => onChange(e), items: items })));
|
|
175
|
-
};
|
|
176
|
-
const FlagPanel = ({ title, uid: initialUid, parentUid, order, description, options = {}, }) => {
|
|
177
|
-
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
178
|
-
return (react_1.default.createElement(core_1.Checkbox, { checked: !!uid, onChange: (e) => {
|
|
179
|
-
var _a;
|
|
180
|
-
const { checked } = e.target;
|
|
181
|
-
if (checked) {
|
|
182
|
-
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
183
|
-
window.roamAlphaAPI.createBlock({
|
|
184
|
-
block: { string: title, uid: newUid },
|
|
185
|
-
location: { order, "parent-uid": parentUid },
|
|
186
|
-
});
|
|
187
|
-
setTimeout(() => setUid(newUid), 1);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
window.roamAlphaAPI.deleteBlock({ block: { uid } });
|
|
191
|
-
setUid("");
|
|
192
|
-
}
|
|
193
|
-
(_a = options.onChange) === null || _a === void 0 ? void 0 : _a.call(options, checked);
|
|
194
|
-
}, labelElement: react_1.default.createElement(react_1.default.Fragment, null,
|
|
195
|
-
(0, idToTitle_1.default)(title),
|
|
196
|
-
react_1.default.createElement(Description_1.default, { description: description })) }));
|
|
197
|
-
};
|
|
198
|
-
const MultiTextPanel = (props) => {
|
|
199
|
-
return (react_1.default.createElement(MultiChildPanel, Object.assign({}, props, { InputComponent: ({ value, setValue }) => (react_1.default.createElement(core_1.InputGroup, { value: value, onChange: (e) => setValue(e.target.value) })) })));
|
|
200
|
-
};
|
|
201
|
-
const PagesPanel = (props) => {
|
|
202
|
-
return (react_1.default.createElement(MultiChildPanel, Object.assign({}, props, { InputComponent: (inputProps) => (react_1.default.createElement(PageInput_1.default, Object.assign({ extra: ["{all}"] }, inputProps))) })));
|
|
203
|
-
};
|
|
204
|
-
const OauthPanel = ({ uid, parentUid, options }) => {
|
|
205
|
-
const key = `oauth-${options.service}`;
|
|
206
|
-
const [useLocal, setUseLocal] = (0, react_1.useState)(!!(0, localStorageGet_1.default)(key));
|
|
207
|
-
const [accounts, setAccounts] = (0, react_1.useState)(() => useLocal
|
|
208
|
-
? JSON.parse((0, localStorageGet_1.default)(key))
|
|
209
|
-
: uid
|
|
210
|
-
? (0, queries_1.getBasicTreeByParentUid)(uid).map((v) => {
|
|
211
|
-
var _a, _b;
|
|
212
|
-
return ({
|
|
213
|
-
text: ((_a = v.children[0]) === null || _a === void 0 ? void 0 : _a.text) ? v.text : "Default Account",
|
|
214
|
-
uid: v.uid,
|
|
215
|
-
data: ((_b = v.children[0]) === null || _b === void 0 ? void 0 : _b.text) || v.text,
|
|
216
|
-
});
|
|
217
|
-
})
|
|
218
|
-
: []);
|
|
219
|
-
const onCheck = (0, react_1.useCallback)((e) => {
|
|
220
|
-
const checked = e.target.checked;
|
|
221
|
-
setUseLocal(checked);
|
|
222
|
-
if (checked) {
|
|
223
|
-
if (uid) {
|
|
224
|
-
(0, queries_1.getShallowTreeByParentUid)(uid).forEach(({ uid: u }) => (0, writes_1.deleteBlock)(u));
|
|
225
|
-
}
|
|
226
|
-
(0, localStorageSet_1.default)(key, JSON.stringify(accounts));
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
(0, localStorageRemove_1.default)(key);
|
|
230
|
-
if (uid) {
|
|
231
|
-
accounts.forEach(({ text, uid: u, data }, order) => {
|
|
232
|
-
window.roamAlphaAPI.createBlock({
|
|
233
|
-
location: { "parent-uid": uid, order },
|
|
234
|
-
block: { string: text, uid: u },
|
|
235
|
-
});
|
|
236
|
-
window.roamAlphaAPI.createBlock({
|
|
237
|
-
location: { "parent-uid": u, order: 0 },
|
|
238
|
-
block: { string: data },
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}, [setUseLocal, accounts, uid, key]);
|
|
244
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
245
|
-
react_1.default.createElement(core_1.Checkbox, { labelElement: react_1.default.createElement(react_1.default.Fragment, null,
|
|
246
|
-
"Store Locally",
|
|
247
|
-
react_1.default.createElement(Description_1.default, { description: "If checked, sensitive authentication data will be stored locally on your machine and will require re-logging in per device. If unchecked, sensitive authentication data will be stored in your Roam Graph." })), checked: useLocal, onChange: onCheck }),
|
|
248
|
-
react_1.default.createElement(ExternalLogin_1.default, Object.assign({ useLocal: useLocal, onSuccess: (acc) => setAccounts([...accounts, acc]), parentUid: parentUid, loggedIn: !!accounts.length }, options)),
|
|
249
|
-
!!accounts.length && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
250
|
-
react_1.default.createElement("h5", { style: { marginTop: 8 } }, "Accounts"),
|
|
251
|
-
react_1.default.createElement("hr", null),
|
|
252
|
-
react_1.default.createElement("ul", { style: { marginTop: 8, padding: 0 } }, accounts.map((act) => (react_1.default.createElement("li", { key: act.uid, style: {
|
|
253
|
-
display: "flex",
|
|
254
|
-
justifyContent: "space-between",
|
|
255
|
-
alignItems: "center",
|
|
256
|
-
marginTop: 8,
|
|
257
|
-
} },
|
|
258
|
-
react_1.default.createElement("span", { style: { minWidth: 192 } }, act.text),
|
|
259
|
-
react_1.default.createElement(core_1.Button, { text: "Log Out", onClick: () => {
|
|
260
|
-
if (useLocal) {
|
|
261
|
-
const accts = JSON.parse((0, localStorageGet_1.default)(key));
|
|
262
|
-
(0, localStorageSet_1.default)(key, JSON.stringify(accts.filter((a) => act.uid !== a.uid)));
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
(0, writes_1.deleteBlock)(act.uid);
|
|
266
|
-
}
|
|
267
|
-
setAccounts(accounts.filter((a) => act.uid !== a.uid));
|
|
268
|
-
} })))))))));
|
|
269
|
-
};
|
|
270
|
-
const BlockPanel = ({ uid: initialUid, parentUid, title, defaultValue, description, }) => {
|
|
271
|
-
const containerRef = (0, react_1.useRef)(null);
|
|
272
|
-
(0, react_1.useEffect)(() => {
|
|
273
|
-
if (containerRef.current) {
|
|
274
|
-
const el = containerRef.current;
|
|
275
|
-
(initialUid
|
|
276
|
-
? Promise.resolve(initialUid)
|
|
277
|
-
: (0, writes_1.createBlock)({ node: { text: title, children: [] }, parentUid }))
|
|
278
|
-
.then((formatUid) => (0, queries_1.getFirstChildUidByBlockUid)(formatUid) ||
|
|
279
|
-
(0, writes_1.createBlock)({
|
|
280
|
-
node: defaultValue || { text: " " },
|
|
281
|
-
parentUid: formatUid,
|
|
282
|
-
}))
|
|
283
|
-
.then((uid) => {
|
|
284
|
-
window.roamAlphaAPI.ui.components.renderBlock({
|
|
285
|
-
uid,
|
|
286
|
-
el,
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}, [containerRef, defaultValue]);
|
|
291
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
292
|
-
react_1.default.createElement(core_1.Label, null,
|
|
293
|
-
(0, idToTitle_1.default)(title),
|
|
294
|
-
react_1.default.createElement(Description_1.default, { description: description })),
|
|
295
|
-
react_1.default.createElement("div", { ref: containerRef, style: {
|
|
296
|
-
border: "1px solid #33333333",
|
|
297
|
-
padding: "8px 0",
|
|
298
|
-
borderRadius: 4,
|
|
299
|
-
} })));
|
|
300
|
-
};
|
|
301
|
-
const BlocksPanel = ({ uid: initialUid, parentUid, title, defaultValue, description, }) => {
|
|
302
|
-
const containerRef = (0, react_1.useRef)(null);
|
|
303
|
-
(0, react_1.useEffect)(() => {
|
|
304
|
-
if (containerRef.current) {
|
|
305
|
-
const el = containerRef.current;
|
|
306
|
-
(initialUid
|
|
307
|
-
? Promise.resolve(initialUid)
|
|
308
|
-
: (0, writes_1.createBlock)({ node: { text: title, children: [] }, parentUid }))
|
|
309
|
-
.then((formatUid) => (0, queries_1.getFirstChildUidByBlockUid)(formatUid)
|
|
310
|
-
? formatUid
|
|
311
|
-
: ((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length)
|
|
312
|
-
? Promise.all(defaultValue.map((node, order) => (0, writes_1.createBlock)({
|
|
313
|
-
node,
|
|
314
|
-
parentUid: formatUid,
|
|
315
|
-
order,
|
|
316
|
-
})))
|
|
317
|
-
: (0, writes_1.createBlock)({
|
|
318
|
-
node: { text: " " },
|
|
319
|
-
parentUid: formatUid,
|
|
320
|
-
})).then(() => formatUid))
|
|
321
|
-
.then((uid) => {
|
|
322
|
-
window.roamAlphaAPI.ui.components.renderBlock({
|
|
323
|
-
uid,
|
|
324
|
-
el,
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}, [containerRef, defaultValue]);
|
|
329
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
330
|
-
react_1.default.createElement(core_1.Label, null,
|
|
331
|
-
(0, idToTitle_1.default)(title),
|
|
332
|
-
react_1.default.createElement(Description_1.default, { description: description })),
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfigObserver = exports.render = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@blueprintjs/core");
|
|
6
|
+
const datetime_1 = require("@blueprintjs/datetime");
|
|
7
|
+
const react_1 = (0, tslib_1.__importStar)(require("react"));
|
|
8
|
+
const react_dom_1 = (0, tslib_1.__importDefault)(require("react-dom"));
|
|
9
|
+
const dom_1 = require("../dom");
|
|
10
|
+
const writes_1 = require("../writes");
|
|
11
|
+
const queries_1 = require("../queries");
|
|
12
|
+
const localStorageGet_1 = (0, tslib_1.__importDefault)(require("../util/localStorageGet"));
|
|
13
|
+
const localStorageRemove_1 = (0, tslib_1.__importDefault)(require("../util/localStorageRemove"));
|
|
14
|
+
const localStorageSet_1 = (0, tslib_1.__importDefault)(require("../util/localStorageSet"));
|
|
15
|
+
const startOfDay_1 = (0, tslib_1.__importDefault)(require("date-fns/startOfDay"));
|
|
16
|
+
const Description_1 = (0, tslib_1.__importDefault)(require("./Description"));
|
|
17
|
+
const ExternalLogin_1 = (0, tslib_1.__importDefault)(require("./ExternalLogin"));
|
|
18
|
+
const idToTitle_1 = (0, tslib_1.__importDefault)(require("../util/idToTitle"));
|
|
19
|
+
const MenuItemSelect_1 = (0, tslib_1.__importDefault)(require("./MenuItemSelect"));
|
|
20
|
+
const PageInput_1 = (0, tslib_1.__importDefault)(require("./PageInput"));
|
|
21
|
+
const format_1 = (0, tslib_1.__importDefault)(require("date-fns/format"));
|
|
22
|
+
const axios_1 = (0, tslib_1.__importDefault)(require("axios"));
|
|
23
|
+
const color_1 = (0, tslib_1.__importDefault)(require("color"));
|
|
24
|
+
const getAuthorizationHeader_1 = (0, tslib_1.__importDefault)(require("../util/getAuthorizationHeader"));
|
|
25
|
+
const TokenDialog_1 = require("./TokenDialog");
|
|
26
|
+
const useSingleChildValue = ({ defaultValue, uid: initialUid, title, parentUid, order, transform, toStr, }) => {
|
|
27
|
+
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
28
|
+
const [valueUid, setValueUid] = (0, react_1.useState)(uid && (0, queries_1.getFirstChildUidByBlockUid)(uid));
|
|
29
|
+
const [value, setValue] = (0, react_1.useState)((valueUid && transform((0, queries_1.getTextByBlockUid)(valueUid))) || defaultValue);
|
|
30
|
+
const onChange = (0, react_1.useCallback)((v) => {
|
|
31
|
+
setValue(v);
|
|
32
|
+
if (valueUid) {
|
|
33
|
+
window.roamAlphaAPI.updateBlock({
|
|
34
|
+
block: { string: toStr(v), uid: valueUid },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else if (uid) {
|
|
38
|
+
const newValueUid = window.roamAlphaAPI.util.generateUID();
|
|
39
|
+
window.roamAlphaAPI.createBlock({
|
|
40
|
+
block: { string: toStr(v), uid: newValueUid },
|
|
41
|
+
location: { order: 0, "parent-uid": uid },
|
|
42
|
+
});
|
|
43
|
+
setValueUid(newValueUid);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
47
|
+
window.roamAlphaAPI.createBlock({
|
|
48
|
+
block: { string: title, uid: newUid },
|
|
49
|
+
location: { order, "parent-uid": parentUid },
|
|
50
|
+
});
|
|
51
|
+
setTimeout(() => setUid(newUid));
|
|
52
|
+
const newValueUid = window.roamAlphaAPI.util.generateUID();
|
|
53
|
+
window.roamAlphaAPI.createBlock({
|
|
54
|
+
block: { string: toStr(v), uid: newValueUid },
|
|
55
|
+
location: { order: 0, "parent-uid": newUid },
|
|
56
|
+
});
|
|
57
|
+
setValueUid(newValueUid);
|
|
58
|
+
}
|
|
59
|
+
}, [setValue, setValueUid, title, parentUid, order, uid, valueUid, setUid]);
|
|
60
|
+
return { value, onChange };
|
|
61
|
+
};
|
|
62
|
+
const MultiChildPanel = ({ uid: initialUid, title, description, order, parentUid, InputComponent, }) => {
|
|
63
|
+
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
64
|
+
const [texts, setTexts] = (0, react_1.useState)(() => uid ? (0, queries_1.getShallowTreeByParentUid)(uid) : []);
|
|
65
|
+
const [value, setValue] = (0, react_1.useState)("");
|
|
66
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
67
|
+
react_1.default.createElement(core_1.Label, null,
|
|
68
|
+
(0, idToTitle_1.default)(title),
|
|
69
|
+
react_1.default.createElement(Description_1.default, { description: description }),
|
|
70
|
+
react_1.default.createElement("div", { style: { display: "flex" } },
|
|
71
|
+
react_1.default.createElement(InputComponent, { value: value, setValue: setValue }),
|
|
72
|
+
react_1.default.createElement(core_1.Button, { icon: "plus", minimal: true, disabled: !value, onClick: () => {
|
|
73
|
+
const valueUid = window.roamAlphaAPI.util.generateUID();
|
|
74
|
+
if (uid) {
|
|
75
|
+
window.roamAlphaAPI.createBlock({
|
|
76
|
+
location: { "parent-uid": uid, order: texts.length },
|
|
77
|
+
block: { string: value, uid: valueUid },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
82
|
+
window.roamAlphaAPI.createBlock({
|
|
83
|
+
block: { string: title, uid: newUid },
|
|
84
|
+
location: { order, "parent-uid": parentUid },
|
|
85
|
+
});
|
|
86
|
+
setTimeout(() => setUid(newUid));
|
|
87
|
+
window.roamAlphaAPI.createBlock({
|
|
88
|
+
block: { string: value, uid: valueUid },
|
|
89
|
+
location: { order: 0, "parent-uid": newUid },
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
setTexts([...texts, { text: value, uid: valueUid }]);
|
|
93
|
+
setValue("");
|
|
94
|
+
} }))),
|
|
95
|
+
texts.map((p) => (react_1.default.createElement("div", { key: p.uid, style: {
|
|
96
|
+
display: "flex",
|
|
97
|
+
alignItems: "center",
|
|
98
|
+
justifyContent: "space-between",
|
|
99
|
+
} },
|
|
100
|
+
react_1.default.createElement("span", { style: {
|
|
101
|
+
textOverflow: "ellipsis",
|
|
102
|
+
whiteSpace: "nowrap",
|
|
103
|
+
overflow: "hidden",
|
|
104
|
+
} }, p.text),
|
|
105
|
+
react_1.default.createElement(core_1.Button, { icon: "trash", minimal: true, onClick: () => {
|
|
106
|
+
window.roamAlphaAPI.deleteBlock({ block: { uid: p.uid } });
|
|
107
|
+
setTexts(texts.filter((f) => f.uid !== p.uid));
|
|
108
|
+
} }))))));
|
|
109
|
+
};
|
|
110
|
+
const TextPanel = ({ title, uid, parentUid, order, description, defaultValue = "", }) => {
|
|
111
|
+
const { value, onChange } = useSingleChildValue({
|
|
112
|
+
defaultValue,
|
|
113
|
+
title,
|
|
114
|
+
uid,
|
|
115
|
+
parentUid,
|
|
116
|
+
order,
|
|
117
|
+
transform: (s) => s,
|
|
118
|
+
toStr: (s) => s,
|
|
119
|
+
});
|
|
120
|
+
return (react_1.default.createElement(core_1.Label, null,
|
|
121
|
+
(0, idToTitle_1.default)(title),
|
|
122
|
+
react_1.default.createElement(Description_1.default, { description: description }),
|
|
123
|
+
react_1.default.createElement(core_1.InputGroup, { value: value, onChange: (e) => onChange(e.target.value) })));
|
|
124
|
+
};
|
|
125
|
+
const TimePanel = ({ title, uid, parentUid, order, description, defaultValue = (0, startOfDay_1.default)(new Date()), }) => {
|
|
126
|
+
const { value, onChange } = useSingleChildValue({
|
|
127
|
+
defaultValue,
|
|
128
|
+
title,
|
|
129
|
+
uid,
|
|
130
|
+
parentUid,
|
|
131
|
+
order,
|
|
132
|
+
transform: (s) => {
|
|
133
|
+
const d = new Date();
|
|
134
|
+
const [hours, minutes] = s.split(":");
|
|
135
|
+
d.setHours(Number(hours));
|
|
136
|
+
d.setMinutes(Number(minutes));
|
|
137
|
+
return d;
|
|
138
|
+
},
|
|
139
|
+
toStr: (v) => (0, format_1.default)(v, "HH:mm"),
|
|
140
|
+
});
|
|
141
|
+
return (react_1.default.createElement(core_1.Label, null,
|
|
142
|
+
(0, idToTitle_1.default)(title),
|
|
143
|
+
react_1.default.createElement(Description_1.default, { description: description }),
|
|
144
|
+
react_1.default.createElement(datetime_1.TimePicker, { value: value, onChange: onChange, showArrowButtons: true })));
|
|
145
|
+
};
|
|
146
|
+
const NumberPanel = ({ title, uid, parentUid, order, description, defaultValue = 0, }) => {
|
|
147
|
+
const { value, onChange } = useSingleChildValue({
|
|
148
|
+
defaultValue,
|
|
149
|
+
title,
|
|
150
|
+
uid,
|
|
151
|
+
parentUid,
|
|
152
|
+
order,
|
|
153
|
+
transform: parseInt,
|
|
154
|
+
toStr: (v) => `${v}`,
|
|
155
|
+
});
|
|
156
|
+
return (react_1.default.createElement(core_1.Label, null,
|
|
157
|
+
(0, idToTitle_1.default)(title),
|
|
158
|
+
react_1.default.createElement(Description_1.default, { description: description }),
|
|
159
|
+
react_1.default.createElement(core_1.NumericInput, { value: value, onValueChange: onChange })));
|
|
160
|
+
};
|
|
161
|
+
const SelectPanel = ({ title, uid, parentUid, order, description, defaultValue = "", options: { items }, }) => {
|
|
162
|
+
const { value, onChange } = useSingleChildValue({
|
|
163
|
+
defaultValue: defaultValue || items[0],
|
|
164
|
+
title,
|
|
165
|
+
uid,
|
|
166
|
+
parentUid,
|
|
167
|
+
order,
|
|
168
|
+
transform: (s) => s,
|
|
169
|
+
toStr: (s) => s,
|
|
170
|
+
});
|
|
171
|
+
return (react_1.default.createElement(core_1.Label, null,
|
|
172
|
+
(0, idToTitle_1.default)(title),
|
|
173
|
+
react_1.default.createElement(Description_1.default, { description: description }),
|
|
174
|
+
react_1.default.createElement(MenuItemSelect_1.default, { activeItem: value, onItemSelect: (e) => onChange(e), items: items })));
|
|
175
|
+
};
|
|
176
|
+
const FlagPanel = ({ title, uid: initialUid, parentUid, order, description, options = {}, }) => {
|
|
177
|
+
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
178
|
+
return (react_1.default.createElement(core_1.Checkbox, { checked: !!uid, onChange: (e) => {
|
|
179
|
+
var _a;
|
|
180
|
+
const { checked } = e.target;
|
|
181
|
+
if (checked) {
|
|
182
|
+
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
183
|
+
window.roamAlphaAPI.createBlock({
|
|
184
|
+
block: { string: title, uid: newUid },
|
|
185
|
+
location: { order, "parent-uid": parentUid },
|
|
186
|
+
});
|
|
187
|
+
setTimeout(() => setUid(newUid), 1);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
window.roamAlphaAPI.deleteBlock({ block: { uid } });
|
|
191
|
+
setUid("");
|
|
192
|
+
}
|
|
193
|
+
(_a = options.onChange) === null || _a === void 0 ? void 0 : _a.call(options, checked);
|
|
194
|
+
}, labelElement: react_1.default.createElement(react_1.default.Fragment, null,
|
|
195
|
+
(0, idToTitle_1.default)(title),
|
|
196
|
+
react_1.default.createElement(Description_1.default, { description: description })) }));
|
|
197
|
+
};
|
|
198
|
+
const MultiTextPanel = (props) => {
|
|
199
|
+
return (react_1.default.createElement(MultiChildPanel, Object.assign({}, props, { InputComponent: ({ value, setValue }) => (react_1.default.createElement(core_1.InputGroup, { value: value, onChange: (e) => setValue(e.target.value) })) })));
|
|
200
|
+
};
|
|
201
|
+
const PagesPanel = (props) => {
|
|
202
|
+
return (react_1.default.createElement(MultiChildPanel, Object.assign({}, props, { InputComponent: (inputProps) => (react_1.default.createElement(PageInput_1.default, Object.assign({ extra: ["{all}"] }, inputProps))) })));
|
|
203
|
+
};
|
|
204
|
+
const OauthPanel = ({ uid, parentUid, options }) => {
|
|
205
|
+
const key = `oauth-${options.service}`;
|
|
206
|
+
const [useLocal, setUseLocal] = (0, react_1.useState)(!!(0, localStorageGet_1.default)(key));
|
|
207
|
+
const [accounts, setAccounts] = (0, react_1.useState)(() => useLocal
|
|
208
|
+
? JSON.parse((0, localStorageGet_1.default)(key))
|
|
209
|
+
: uid
|
|
210
|
+
? (0, queries_1.getBasicTreeByParentUid)(uid).map((v) => {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
return ({
|
|
213
|
+
text: ((_a = v.children[0]) === null || _a === void 0 ? void 0 : _a.text) ? v.text : "Default Account",
|
|
214
|
+
uid: v.uid,
|
|
215
|
+
data: ((_b = v.children[0]) === null || _b === void 0 ? void 0 : _b.text) || v.text,
|
|
216
|
+
});
|
|
217
|
+
})
|
|
218
|
+
: []);
|
|
219
|
+
const onCheck = (0, react_1.useCallback)((e) => {
|
|
220
|
+
const checked = e.target.checked;
|
|
221
|
+
setUseLocal(checked);
|
|
222
|
+
if (checked) {
|
|
223
|
+
if (uid) {
|
|
224
|
+
(0, queries_1.getShallowTreeByParentUid)(uid).forEach(({ uid: u }) => (0, writes_1.deleteBlock)(u));
|
|
225
|
+
}
|
|
226
|
+
(0, localStorageSet_1.default)(key, JSON.stringify(accounts));
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
(0, localStorageRemove_1.default)(key);
|
|
230
|
+
if (uid) {
|
|
231
|
+
accounts.forEach(({ text, uid: u, data }, order) => {
|
|
232
|
+
window.roamAlphaAPI.createBlock({
|
|
233
|
+
location: { "parent-uid": uid, order },
|
|
234
|
+
block: { string: text, uid: u },
|
|
235
|
+
});
|
|
236
|
+
window.roamAlphaAPI.createBlock({
|
|
237
|
+
location: { "parent-uid": u, order: 0 },
|
|
238
|
+
block: { string: data },
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}, [setUseLocal, accounts, uid, key]);
|
|
244
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
245
|
+
react_1.default.createElement(core_1.Checkbox, { labelElement: react_1.default.createElement(react_1.default.Fragment, null,
|
|
246
|
+
"Store Locally",
|
|
247
|
+
react_1.default.createElement(Description_1.default, { description: "If checked, sensitive authentication data will be stored locally on your machine and will require re-logging in per device. If unchecked, sensitive authentication data will be stored in your Roam Graph." })), checked: useLocal, onChange: onCheck }),
|
|
248
|
+
react_1.default.createElement(ExternalLogin_1.default, Object.assign({ useLocal: useLocal, onSuccess: (acc) => setAccounts([...accounts, acc]), parentUid: parentUid, loggedIn: !!accounts.length }, options)),
|
|
249
|
+
!!accounts.length && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
250
|
+
react_1.default.createElement("h5", { style: { marginTop: 8 } }, "Accounts"),
|
|
251
|
+
react_1.default.createElement("hr", null),
|
|
252
|
+
react_1.default.createElement("ul", { style: { marginTop: 8, padding: 0 } }, accounts.map((act) => (react_1.default.createElement("li", { key: act.uid, style: {
|
|
253
|
+
display: "flex",
|
|
254
|
+
justifyContent: "space-between",
|
|
255
|
+
alignItems: "center",
|
|
256
|
+
marginTop: 8,
|
|
257
|
+
} },
|
|
258
|
+
react_1.default.createElement("span", { style: { minWidth: 192 } }, act.text),
|
|
259
|
+
react_1.default.createElement(core_1.Button, { text: "Log Out", onClick: () => {
|
|
260
|
+
if (useLocal) {
|
|
261
|
+
const accts = JSON.parse((0, localStorageGet_1.default)(key));
|
|
262
|
+
(0, localStorageSet_1.default)(key, JSON.stringify(accts.filter((a) => act.uid !== a.uid)));
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
(0, writes_1.deleteBlock)(act.uid);
|
|
266
|
+
}
|
|
267
|
+
setAccounts(accounts.filter((a) => act.uid !== a.uid));
|
|
268
|
+
} })))))))));
|
|
269
|
+
};
|
|
270
|
+
const BlockPanel = ({ uid: initialUid, parentUid, title, defaultValue, description, }) => {
|
|
271
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
272
|
+
(0, react_1.useEffect)(() => {
|
|
273
|
+
if (containerRef.current) {
|
|
274
|
+
const el = containerRef.current;
|
|
275
|
+
(initialUid
|
|
276
|
+
? Promise.resolve(initialUid)
|
|
277
|
+
: (0, writes_1.createBlock)({ node: { text: title, children: [] }, parentUid }))
|
|
278
|
+
.then((formatUid) => (0, queries_1.getFirstChildUidByBlockUid)(formatUid) ||
|
|
279
|
+
(0, writes_1.createBlock)({
|
|
280
|
+
node: defaultValue || { text: " " },
|
|
281
|
+
parentUid: formatUid,
|
|
282
|
+
}))
|
|
283
|
+
.then((uid) => {
|
|
284
|
+
window.roamAlphaAPI.ui.components.renderBlock({
|
|
285
|
+
uid,
|
|
286
|
+
el,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}, [containerRef, defaultValue]);
|
|
291
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
292
|
+
react_1.default.createElement(core_1.Label, null,
|
|
293
|
+
(0, idToTitle_1.default)(title),
|
|
294
|
+
react_1.default.createElement(Description_1.default, { description: description })),
|
|
295
|
+
react_1.default.createElement("div", { ref: containerRef, style: {
|
|
296
|
+
border: "1px solid #33333333",
|
|
297
|
+
padding: "8px 0",
|
|
298
|
+
borderRadius: 4,
|
|
299
|
+
} })));
|
|
300
|
+
};
|
|
301
|
+
const BlocksPanel = ({ uid: initialUid, parentUid, title, defaultValue, description, }) => {
|
|
302
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
303
|
+
(0, react_1.useEffect)(() => {
|
|
304
|
+
if (containerRef.current) {
|
|
305
|
+
const el = containerRef.current;
|
|
306
|
+
(initialUid
|
|
307
|
+
? Promise.resolve(initialUid)
|
|
308
|
+
: (0, writes_1.createBlock)({ node: { text: title, children: [] }, parentUid }))
|
|
309
|
+
.then((formatUid) => (0, queries_1.getFirstChildUidByBlockUid)(formatUid)
|
|
310
|
+
? formatUid
|
|
311
|
+
: ((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length)
|
|
312
|
+
? Promise.all(defaultValue.map((node, order) => (0, writes_1.createBlock)({
|
|
313
|
+
node,
|
|
314
|
+
parentUid: formatUid,
|
|
315
|
+
order,
|
|
316
|
+
})))
|
|
317
|
+
: (0, writes_1.createBlock)({
|
|
318
|
+
node: { text: " " },
|
|
319
|
+
parentUid: formatUid,
|
|
320
|
+
})).then(() => formatUid))
|
|
321
|
+
.then((uid) => {
|
|
322
|
+
window.roamAlphaAPI.ui.components.renderBlock({
|
|
323
|
+
uid,
|
|
324
|
+
el,
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}, [containerRef, defaultValue]);
|
|
329
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
330
|
+
react_1.default.createElement(core_1.Label, null,
|
|
331
|
+
(0, idToTitle_1.default)(title),
|
|
332
|
+
react_1.default.createElement(Description_1.default, { description: description })),
|
|
333
333
|
react_1.default.createElement("style", null, `.roamjs-config-blocks > div > .rm-block-main {
|
|
334
334
|
display: none;
|
|
335
335
|
}
|
|
@@ -340,309 +340,309 @@ const BlocksPanel = ({ uid: initialUid, parentUid, title, defaultValue, descript
|
|
|
340
340
|
|
|
341
341
|
.roamjs-config-blocks > div > .rm-block-children {
|
|
342
342
|
margin-left: -4px;
|
|
343
|
-
}`),
|
|
344
|
-
react_1.default.createElement("div", { ref: containerRef, style: {
|
|
345
|
-
border: "1px solid #33333333",
|
|
346
|
-
padding: "8px 0",
|
|
347
|
-
borderRadius: 4,
|
|
348
|
-
}, className: "roamjs-config-blocks" })));
|
|
349
|
-
};
|
|
350
|
-
const CustomPanel = ({ description, title, uid: inputUid, options: { component: Component }, parentUid, defaultValue = [], order, }) => {
|
|
351
|
-
const uid = (0, react_1.useMemo)(() => {
|
|
352
|
-
if (inputUid)
|
|
353
|
-
return inputUid;
|
|
354
|
-
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
355
|
-
(0, writes_1.createBlock)({ node: { text: title, uid: newUid }, parentUid, order });
|
|
356
|
-
return newUid;
|
|
357
|
-
}, [inputUid]);
|
|
358
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
359
|
-
react_1.default.createElement(core_1.Label, null,
|
|
360
|
-
(0, idToTitle_1.default)(title),
|
|
361
|
-
react_1.default.createElement(Description_1.default, { description: description })),
|
|
362
|
-
react_1.default.createElement(Component, { uid: uid, parentUid: parentUid, title: title, defaultValue: defaultValue })));
|
|
363
|
-
};
|
|
364
|
-
const ToggleablePanel = ({ enabled, setEnabled, pageUid, order, id, extensionId, setUid, uid, toggleable, onEnable, onDisable, }) => {
|
|
365
|
-
const uidRef = (0, react_1.useRef)(uid);
|
|
366
|
-
const isPremium = (0, react_1.useMemo)(() => toggleable !== true, [toggleable]);
|
|
367
|
-
const dev = (0, react_1.useMemo)(() => ["dev", "ngrok", "localhost"].some((s) => (process.env.API_URL || "").includes(s))
|
|
368
|
-
? "&dev=true"
|
|
369
|
-
: "", []);
|
|
370
|
-
const [pricingMessage, setPricingMessage] = (0, react_1.useState)("");
|
|
371
|
-
const [productDescription, setProductDescription] = (0, react_1.useState)("");
|
|
372
|
-
const [error, setError] = (0, react_1.useState)("");
|
|
373
|
-
const [loading, setLoading] = (0, react_1.useState)(isPremium);
|
|
374
|
-
const [alertLoading, setAlertLoading] = (0, react_1.useState)(false);
|
|
375
|
-
const enableCallback = (0, react_1.useCallback)((checked, uid) => {
|
|
376
|
-
setEnabled(checked);
|
|
377
|
-
if (checked) {
|
|
378
|
-
(0, writes_1.createBlock)({
|
|
379
|
-
parentUid: pageUid,
|
|
380
|
-
order,
|
|
381
|
-
node: { text: id },
|
|
382
|
-
})
|
|
383
|
-
.then((newUid) => {
|
|
384
|
-
setUid(newUid);
|
|
385
|
-
uidRef.current = newUid;
|
|
386
|
-
})
|
|
387
|
-
.then(() => onEnable === null || onEnable === void 0 ? void 0 : onEnable());
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
(0, writes_1.deleteBlock)(uid)
|
|
391
|
-
.then(() => {
|
|
392
|
-
setUid("");
|
|
393
|
-
uidRef.current = "";
|
|
394
|
-
})
|
|
395
|
-
.then(() => onDisable === null || onDisable === void 0 ? void 0 : onDisable());
|
|
396
|
-
}
|
|
397
|
-
}, [setUid, setEnabled, id, pageUid, order, onEnable, onDisable]);
|
|
398
|
-
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
399
|
-
const intervalListener = (0, react_1.useRef)(0);
|
|
400
|
-
const catchError = (0, react_1.useCallback)((e) => { var _a, _b, _c; return setError(((_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || ((_c = e.response) === null || _c === void 0 ? void 0 : _c.data) || e.message); }, [setError]);
|
|
401
|
-
(0, react_1.useEffect)(() => {
|
|
402
|
-
if (isPremium) {
|
|
403
|
-
axios_1.default
|
|
404
|
-
.get(`https://lambda.roamjs.com/price?extensionId=${extensionId}${dev}`)
|
|
405
|
-
.then((r) => {
|
|
406
|
-
setPricingMessage(`$${r.data.price / 100}${r.data.perUse ? " per use" : ""}${r.data.isMonthly ? " per month" : " per year"}`);
|
|
407
|
-
setProductDescription(r.data.description || "No extension specific description found.");
|
|
408
|
-
})
|
|
409
|
-
.catch(catchError);
|
|
410
|
-
}
|
|
411
|
-
}, [isPremium, setPricingMessage, setProductDescription, dev]);
|
|
412
|
-
const checkSubscription = (0, react_1.useCallback)((token) => {
|
|
413
|
-
setLoading(true);
|
|
414
|
-
setError("");
|
|
415
|
-
setEnabled(false);
|
|
416
|
-
(token
|
|
417
|
-
? axios_1.default
|
|
418
|
-
.get(`https://lambda.roamjs.com/check?extensionId=${extensionId}${dev}`, {
|
|
419
|
-
headers: { Authorization: (0, getAuthorizationHeader_1.default)() },
|
|
420
|
-
})
|
|
421
|
-
.then((r) => {
|
|
422
|
-
if (!r.data.success && uidRef.current) {
|
|
423
|
-
enableCallback(false, uidRef.current);
|
|
424
|
-
}
|
|
425
|
-
else if (r.data.success && !uidRef.current) {
|
|
426
|
-
enableCallback(true, uidRef.current);
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
setEnabled(r.data.success);
|
|
430
|
-
}
|
|
431
|
-
})
|
|
432
|
-
: Promise.reject(new Error(`Must set a RoamJS token in order to use these features. To set your RoamJS token, open the Roam command palette and enter "Set RoamJS Token"`)))
|
|
433
|
-
.catch((e) => {
|
|
434
|
-
if (uidRef.current)
|
|
435
|
-
enableCallback(false, uidRef.current);
|
|
436
|
-
catchError(e);
|
|
437
|
-
})
|
|
438
|
-
.finally(() => setLoading(false));
|
|
439
|
-
}, [catchError, extensionId, dev, uidRef, enableCallback, setLoading, setError]);
|
|
440
|
-
const containerRef = (0, react_1.useRef)(null);
|
|
441
|
-
(0, react_1.useEffect)(() => {
|
|
442
|
-
var _a;
|
|
443
|
-
if (isPremium) {
|
|
444
|
-
(0, TokenDialog_1.checkRoamJSTokenWarning)().then(checkSubscription);
|
|
445
|
-
if (containerRef.current)
|
|
446
|
-
(_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener("roamjs:token:set", ((e) => checkSubscription(e.detail)));
|
|
447
|
-
}
|
|
448
|
-
return () => clearTimeout(intervalListener.current);
|
|
449
|
-
}, [isPremium, checkSubscription]);
|
|
450
|
-
return (react_1.default.createElement("div", { id: "roamjs-toggleable-container", ref: containerRef },
|
|
451
|
-
loading ? (react_1.default.createElement("div", { style: {
|
|
452
|
-
whiteSpace: "pre-wrap",
|
|
453
|
-
display: "flex",
|
|
454
|
-
justifyContent: "space-between",
|
|
455
|
-
} },
|
|
456
|
-
react_1.default.createElement("span", { style: { opacity: 0.75 } },
|
|
457
|
-
"Checking to see if you are subscribed to RoamJS",
|
|
458
|
-
" ",
|
|
459
|
-
(0, idToTitle_1.default)(extensionId),
|
|
460
|
-
"..."),
|
|
461
|
-
react_1.default.createElement(core_1.Spinner, { size: 16 }))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
462
|
-
react_1.default.createElement(core_1.Switch, { labelElement: "Enabled", checked: enabled, onChange: (e) => isPremium
|
|
463
|
-
? setIsOpen(true)
|
|
464
|
-
: enableCallback(e.target.checked, uid) }),
|
|
465
|
-
react_1.default.createElement("p", { style: { whiteSpace: "pre-wrap" } }, isPremium &&
|
|
466
|
-
(enabled
|
|
467
|
-
? `You have sucessfully subscribed!\n\nConfigure this feature with the tabs on the left.`
|
|
468
|
-
: `This is a premium feature and will require a paid subscription to enable.\n\n${productDescription}`)))),
|
|
469
|
-
react_1.default.createElement("p", { style: { color: "red" } }, error),
|
|
470
|
-
react_1.default.createElement(core_1.Alert, { isOpen: isOpen, onConfirm: () => {
|
|
471
|
-
setAlertLoading(true);
|
|
472
|
-
setError("");
|
|
473
|
-
if (enabled) {
|
|
474
|
-
axios_1.default
|
|
475
|
-
.post(`https://lambda.roamjs.com/unsubscribe`, {
|
|
476
|
-
extensionId,
|
|
477
|
-
dev: !!dev,
|
|
478
|
-
}, { headers: { Authorization: (0, getAuthorizationHeader_1.default)() } })
|
|
479
|
-
.then(() => {
|
|
480
|
-
enableCallback(false, uid);
|
|
481
|
-
})
|
|
482
|
-
.catch(catchError)
|
|
483
|
-
.finally(() => {
|
|
484
|
-
setAlertLoading(false);
|
|
485
|
-
setIsOpen(false);
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
axios_1.default
|
|
490
|
-
.post(`https://lambda.roamjs.com/subscribe`, {
|
|
491
|
-
extensionId,
|
|
492
|
-
dev: !!dev,
|
|
493
|
-
}, { headers: { Authorization: (0, getAuthorizationHeader_1.default)() } })
|
|
494
|
-
.then((r) => {
|
|
495
|
-
if (r.data.url) {
|
|
496
|
-
const width = 600;
|
|
497
|
-
const height = 525;
|
|
498
|
-
const left = window.screenX + (window.innerWidth - width) / 2;
|
|
499
|
-
const top = window.screenY + (window.innerHeight - height) / 2;
|
|
500
|
-
window.open(r.data.url, `roamjs:roamjs:stripe`, `left=${left},top=${top},width=${width},height=${height},status=1`);
|
|
501
|
-
const authInterval = () => {
|
|
502
|
-
axios_1.default
|
|
503
|
-
.get(`https://lambda.roamjs.com/check?extensionId=${extensionId}${dev}`, { headers: { Authorization: (0, getAuthorizationHeader_1.default)() } })
|
|
504
|
-
.then((r) => {
|
|
505
|
-
if (r.data.success) {
|
|
506
|
-
enableCallback(true, uid);
|
|
507
|
-
setAlertLoading(false);
|
|
508
|
-
setIsOpen(false);
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
intervalListener.current = window.setTimeout(authInterval, 2000);
|
|
512
|
-
}
|
|
513
|
-
})
|
|
514
|
-
.catch((e) => {
|
|
515
|
-
catchError(e);
|
|
516
|
-
setAlertLoading(false);
|
|
517
|
-
setIsOpen(false);
|
|
518
|
-
});
|
|
519
|
-
};
|
|
520
|
-
authInterval();
|
|
521
|
-
}
|
|
522
|
-
else if (r.data.success) {
|
|
523
|
-
enableCallback(true, uid);
|
|
524
|
-
setAlertLoading(false);
|
|
525
|
-
setIsOpen(false);
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
setError("Something went wrong with the subscription. Please contact support@roamjs.com for help!");
|
|
529
|
-
setAlertLoading(false);
|
|
530
|
-
setIsOpen(false);
|
|
531
|
-
}
|
|
532
|
-
})
|
|
533
|
-
.catch(catchError)
|
|
534
|
-
.finally(() => {
|
|
535
|
-
setAlertLoading(false);
|
|
536
|
-
setIsOpen(false);
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
}, confirmButtonText: "Submit", cancelButtonText: "Cancel", intent: core_1.Intent.PRIMARY, loading: alertLoading, onCancel: () => setIsOpen(false) }, enabled
|
|
540
|
-
? `By clicking submit below, you will unsubscribe from the premium features of the RoamJS Extension: ${(0, idToTitle_1.default)(extensionId)}`
|
|
541
|
-
: `By clicking submit below, you will subscribe to the premium features of the RoamJS Extension: ${(0, idToTitle_1.default)(extensionId)} for ${pricingMessage}. A window may appear for checkout if this is your first premium extension`)));
|
|
542
|
-
};
|
|
543
|
-
const Panels = {
|
|
544
|
-
text: TextPanel,
|
|
545
|
-
time: TimePanel,
|
|
546
|
-
number: NumberPanel,
|
|
547
|
-
flag: FlagPanel,
|
|
548
|
-
pages: PagesPanel,
|
|
549
|
-
oauth: OauthPanel,
|
|
550
|
-
multitext: MultiTextPanel,
|
|
551
|
-
select: SelectPanel,
|
|
552
|
-
block: BlockPanel,
|
|
553
|
-
blocks: BlocksPanel,
|
|
554
|
-
custom: CustomPanel,
|
|
555
|
-
};
|
|
556
|
-
const tryColor = (s) => {
|
|
557
|
-
if (!s)
|
|
558
|
-
return undefined;
|
|
559
|
-
try {
|
|
560
|
-
return (0, color_1.default)(s);
|
|
561
|
-
}
|
|
562
|
-
catch (e) {
|
|
563
|
-
return undefined;
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
const FieldTabs = ({ id, fields, uid: initialUid, pageUid, order, toggleable, extensionId, onEnable, onDisable, }) => {
|
|
567
|
-
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
568
|
-
const parentUid = (0, react_1.useMemo)(() => {
|
|
569
|
-
if (/home/i.test(id)) {
|
|
570
|
-
return pageUid;
|
|
571
|
-
}
|
|
572
|
-
if (uid) {
|
|
573
|
-
return uid;
|
|
574
|
-
}
|
|
575
|
-
if (toggleable) {
|
|
576
|
-
return "";
|
|
577
|
-
}
|
|
578
|
-
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
579
|
-
(0, writes_1.createBlock)({
|
|
580
|
-
parentUid: pageUid,
|
|
581
|
-
order,
|
|
582
|
-
node: { text: id, uid: newUid },
|
|
583
|
-
});
|
|
584
|
-
return newUid;
|
|
585
|
-
}, [pageUid, uid, id, toggleable]);
|
|
586
|
-
const childUids = Object.fromEntries((0, queries_1.getShallowTreeByParentUid)(parentUid).map(({ text, uid }) => [
|
|
587
|
-
text.toLowerCase().trim(),
|
|
588
|
-
uid,
|
|
589
|
-
]));
|
|
590
|
-
const [enabled, setEnabled] = (0, react_1.useState)(!toggleable || !!parentUid);
|
|
591
|
-
const [selectedTabId, setSelectedTabId] = (0, react_1.useState)(enabled && fields.length && typeof toggleable !== "string"
|
|
592
|
-
? fields[0].title
|
|
593
|
-
: "enabled");
|
|
594
|
-
const onTabsChange = (0, react_1.useCallback)((tabId) => setSelectedTabId(tabId), [setSelectedTabId]);
|
|
595
|
-
return (react_1.default.createElement(core_1.Tabs, { vertical: true, id: `${id}-field-tabs`, onChange: onTabsChange, selectedTabId: selectedTabId, renderActiveTabPanelOnly: true },
|
|
596
|
-
toggleable && (react_1.default.createElement(core_1.Tab, { id: "enabled", title: "enabled", panel: selectedTabId === "enabled" ? (react_1.default.createElement(ToggleablePanel, { id: id, uid: uid, pageUid: pageUid, extensionId: extensionId, enabled: enabled, order: order, toggleable: toggleable, setUid: setUid, setEnabled: setEnabled, onEnable: onEnable, onDisable: onDisable })) : undefined })),
|
|
597
|
-
fields.map((field, i) => {
|
|
598
|
-
const { type, title, defaultValue } = field;
|
|
599
|
-
const Panel = Panels[type];
|
|
600
|
-
return (react_1.default.createElement(core_1.Tab, { id: title, key: title, title: (0, idToTitle_1.default)(title), disabled: !enabled, panel: react_1.default.createElement(Panel, Object.assign({}, field, {
|
|
601
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
602
|
-
// @ts-ignore 4.3.0
|
|
603
|
-
defaultValue: defaultValue, order: i, parentUid: parentUid, uid: childUids[title.toLowerCase()] })) }));
|
|
604
|
-
})));
|
|
605
|
-
};
|
|
606
|
-
const ConfigPage = ({ id, config, pageUid, }) => {
|
|
607
|
-
var _a;
|
|
608
|
-
const userTabs = config.tabs.filter((t) => t.fields.length || t.toggleable);
|
|
609
|
-
const [selectedTabId, setSelectedTabId] = (0, react_1.useState)((_a = userTabs[0]) === null || _a === void 0 ? void 0 : _a.id);
|
|
610
|
-
const onTabsChange = (0, react_1.useCallback)((tabId) => setSelectedTabId(tabId), [setSelectedTabId]);
|
|
611
|
-
const tree = (0, queries_1.getBasicTreeByParentUid)(pageUid);
|
|
612
|
-
const [currentVersion, setCurrentVersion] = (0, react_1.useState)("");
|
|
613
|
-
const [experimentalMode, setExperimentalMode] = (0, react_1.useState)(!!(0, localStorageGet_1.default)("experimental"));
|
|
614
|
-
const titleRef = (0, react_1.useRef)(null);
|
|
615
|
-
(0, react_1.useEffect)(() => {
|
|
616
|
-
var _a, _b, _c;
|
|
617
|
-
if (config.versioning) {
|
|
618
|
-
(0, dom_1.addOldRoamJSDependency)("versioning");
|
|
619
|
-
const scriptVersionMatch = (_b = (_a = window.roamjs) === null || _a === void 0 ? void 0 : _a.version) === null || _b === void 0 ? void 0 : _b[id];
|
|
620
|
-
if (scriptVersionMatch) {
|
|
621
|
-
setCurrentVersion(scriptVersionMatch);
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
setCurrentVersion("Version Not Found");
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
if (userTabs.some((t) => t.development)) {
|
|
628
|
-
(_c = titleRef.current) === null || _c === void 0 ? void 0 : _c.addEventListener("keydown", (e) => {
|
|
629
|
-
if (e.ctrlKey &&
|
|
630
|
-
e.metaKey &&
|
|
631
|
-
e.shiftKey &&
|
|
632
|
-
e.altKey &&
|
|
633
|
-
e.key === "KeyM") {
|
|
634
|
-
const newVal = !(0, localStorageGet_1.default)("experimental");
|
|
635
|
-
setExperimentalMode(newVal);
|
|
636
|
-
if (newVal)
|
|
637
|
-
(0, localStorageSet_1.default)("experimental", "true");
|
|
638
|
-
else
|
|
639
|
-
(0, localStorageRemove_1.default)("experimental");
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
}, [config.versioning, id, setCurrentVersion, userTabs, titleRef]);
|
|
644
|
-
const brandColor = tryColor(config.brand);
|
|
645
|
-
return (react_1.default.createElement(core_1.Card, { style: { color: "#202B33" }, className: "roamjs-config-panel" },
|
|
343
|
+
}`),
|
|
344
|
+
react_1.default.createElement("div", { ref: containerRef, style: {
|
|
345
|
+
border: "1px solid #33333333",
|
|
346
|
+
padding: "8px 0",
|
|
347
|
+
borderRadius: 4,
|
|
348
|
+
}, className: "roamjs-config-blocks" })));
|
|
349
|
+
};
|
|
350
|
+
const CustomPanel = ({ description, title, uid: inputUid, options: { component: Component }, parentUid, defaultValue = [], order, }) => {
|
|
351
|
+
const uid = (0, react_1.useMemo)(() => {
|
|
352
|
+
if (inputUid)
|
|
353
|
+
return inputUid;
|
|
354
|
+
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
355
|
+
(0, writes_1.createBlock)({ node: { text: title, uid: newUid }, parentUid, order });
|
|
356
|
+
return newUid;
|
|
357
|
+
}, [inputUid]);
|
|
358
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
359
|
+
react_1.default.createElement(core_1.Label, null,
|
|
360
|
+
(0, idToTitle_1.default)(title),
|
|
361
|
+
react_1.default.createElement(Description_1.default, { description: description })),
|
|
362
|
+
react_1.default.createElement(Component, { uid: uid, parentUid: parentUid, title: title, defaultValue: defaultValue })));
|
|
363
|
+
};
|
|
364
|
+
const ToggleablePanel = ({ enabled, setEnabled, pageUid, order, id, extensionId, setUid, uid, toggleable, onEnable, onDisable, }) => {
|
|
365
|
+
const uidRef = (0, react_1.useRef)(uid);
|
|
366
|
+
const isPremium = (0, react_1.useMemo)(() => toggleable !== true, [toggleable]);
|
|
367
|
+
const dev = (0, react_1.useMemo)(() => ["dev", "ngrok", "localhost"].some((s) => (process.env.API_URL || "").includes(s))
|
|
368
|
+
? "&dev=true"
|
|
369
|
+
: "", []);
|
|
370
|
+
const [pricingMessage, setPricingMessage] = (0, react_1.useState)("");
|
|
371
|
+
const [productDescription, setProductDescription] = (0, react_1.useState)("");
|
|
372
|
+
const [error, setError] = (0, react_1.useState)("");
|
|
373
|
+
const [loading, setLoading] = (0, react_1.useState)(isPremium);
|
|
374
|
+
const [alertLoading, setAlertLoading] = (0, react_1.useState)(false);
|
|
375
|
+
const enableCallback = (0, react_1.useCallback)((checked, uid) => {
|
|
376
|
+
setEnabled(checked);
|
|
377
|
+
if (checked) {
|
|
378
|
+
(0, writes_1.createBlock)({
|
|
379
|
+
parentUid: pageUid,
|
|
380
|
+
order,
|
|
381
|
+
node: { text: id },
|
|
382
|
+
})
|
|
383
|
+
.then((newUid) => {
|
|
384
|
+
setUid(newUid);
|
|
385
|
+
uidRef.current = newUid;
|
|
386
|
+
})
|
|
387
|
+
.then(() => onEnable === null || onEnable === void 0 ? void 0 : onEnable());
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
(0, writes_1.deleteBlock)(uid)
|
|
391
|
+
.then(() => {
|
|
392
|
+
setUid("");
|
|
393
|
+
uidRef.current = "";
|
|
394
|
+
})
|
|
395
|
+
.then(() => onDisable === null || onDisable === void 0 ? void 0 : onDisable());
|
|
396
|
+
}
|
|
397
|
+
}, [setUid, setEnabled, id, pageUid, order, onEnable, onDisable]);
|
|
398
|
+
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
399
|
+
const intervalListener = (0, react_1.useRef)(0);
|
|
400
|
+
const catchError = (0, react_1.useCallback)((e) => { var _a, _b, _c; return setError(((_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || ((_c = e.response) === null || _c === void 0 ? void 0 : _c.data) || e.message); }, [setError]);
|
|
401
|
+
(0, react_1.useEffect)(() => {
|
|
402
|
+
if (isPremium) {
|
|
403
|
+
axios_1.default
|
|
404
|
+
.get(`https://lambda.roamjs.com/price?extensionId=${extensionId}${dev}`)
|
|
405
|
+
.then((r) => {
|
|
406
|
+
setPricingMessage(`$${r.data.price / 100}${r.data.perUse ? " per use" : ""}${r.data.isMonthly ? " per month" : " per year"}`);
|
|
407
|
+
setProductDescription(r.data.description || "No extension specific description found.");
|
|
408
|
+
})
|
|
409
|
+
.catch(catchError);
|
|
410
|
+
}
|
|
411
|
+
}, [isPremium, setPricingMessage, setProductDescription, dev]);
|
|
412
|
+
const checkSubscription = (0, react_1.useCallback)((token) => {
|
|
413
|
+
setLoading(true);
|
|
414
|
+
setError("");
|
|
415
|
+
setEnabled(false);
|
|
416
|
+
(token
|
|
417
|
+
? axios_1.default
|
|
418
|
+
.get(`https://lambda.roamjs.com/check?extensionId=${extensionId}${dev}`, {
|
|
419
|
+
headers: { Authorization: (0, getAuthorizationHeader_1.default)() },
|
|
420
|
+
})
|
|
421
|
+
.then((r) => {
|
|
422
|
+
if (!r.data.success && uidRef.current) {
|
|
423
|
+
enableCallback(false, uidRef.current);
|
|
424
|
+
}
|
|
425
|
+
else if (r.data.success && !uidRef.current) {
|
|
426
|
+
enableCallback(true, uidRef.current);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
setEnabled(r.data.success);
|
|
430
|
+
}
|
|
431
|
+
})
|
|
432
|
+
: Promise.reject(new Error(`Must set a RoamJS token in order to use these features. To set your RoamJS token, open the Roam command palette and enter "Set RoamJS Token"`)))
|
|
433
|
+
.catch((e) => {
|
|
434
|
+
if (uidRef.current)
|
|
435
|
+
enableCallback(false, uidRef.current);
|
|
436
|
+
catchError(e);
|
|
437
|
+
})
|
|
438
|
+
.finally(() => setLoading(false));
|
|
439
|
+
}, [catchError, extensionId, dev, uidRef, enableCallback, setLoading, setError]);
|
|
440
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
441
|
+
(0, react_1.useEffect)(() => {
|
|
442
|
+
var _a;
|
|
443
|
+
if (isPremium) {
|
|
444
|
+
(0, TokenDialog_1.checkRoamJSTokenWarning)().then(checkSubscription);
|
|
445
|
+
if (containerRef.current)
|
|
446
|
+
(_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener("roamjs:token:set", ((e) => checkSubscription(e.detail)));
|
|
447
|
+
}
|
|
448
|
+
return () => clearTimeout(intervalListener.current);
|
|
449
|
+
}, [isPremium, checkSubscription]);
|
|
450
|
+
return (react_1.default.createElement("div", { id: "roamjs-toggleable-container", ref: containerRef },
|
|
451
|
+
loading ? (react_1.default.createElement("div", { style: {
|
|
452
|
+
whiteSpace: "pre-wrap",
|
|
453
|
+
display: "flex",
|
|
454
|
+
justifyContent: "space-between",
|
|
455
|
+
} },
|
|
456
|
+
react_1.default.createElement("span", { style: { opacity: 0.75 } },
|
|
457
|
+
"Checking to see if you are subscribed to RoamJS",
|
|
458
|
+
" ",
|
|
459
|
+
(0, idToTitle_1.default)(extensionId),
|
|
460
|
+
"..."),
|
|
461
|
+
react_1.default.createElement(core_1.Spinner, { size: 16 }))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
462
|
+
react_1.default.createElement(core_1.Switch, { labelElement: "Enabled", checked: enabled, onChange: (e) => isPremium
|
|
463
|
+
? setIsOpen(true)
|
|
464
|
+
: enableCallback(e.target.checked, uid) }),
|
|
465
|
+
react_1.default.createElement("p", { style: { whiteSpace: "pre-wrap" } }, isPremium &&
|
|
466
|
+
(enabled
|
|
467
|
+
? `You have sucessfully subscribed!\n\nConfigure this feature with the tabs on the left.`
|
|
468
|
+
: `This is a premium feature and will require a paid subscription to enable.\n\n${productDescription}`)))),
|
|
469
|
+
react_1.default.createElement("p", { style: { color: "red" } }, error),
|
|
470
|
+
react_1.default.createElement(core_1.Alert, { isOpen: isOpen, onConfirm: () => {
|
|
471
|
+
setAlertLoading(true);
|
|
472
|
+
setError("");
|
|
473
|
+
if (enabled) {
|
|
474
|
+
axios_1.default
|
|
475
|
+
.post(`https://lambda.roamjs.com/unsubscribe`, {
|
|
476
|
+
extensionId,
|
|
477
|
+
dev: !!dev,
|
|
478
|
+
}, { headers: { Authorization: (0, getAuthorizationHeader_1.default)() } })
|
|
479
|
+
.then(() => {
|
|
480
|
+
enableCallback(false, uid);
|
|
481
|
+
})
|
|
482
|
+
.catch(catchError)
|
|
483
|
+
.finally(() => {
|
|
484
|
+
setAlertLoading(false);
|
|
485
|
+
setIsOpen(false);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
axios_1.default
|
|
490
|
+
.post(`https://lambda.roamjs.com/subscribe`, {
|
|
491
|
+
extensionId,
|
|
492
|
+
dev: !!dev,
|
|
493
|
+
}, { headers: { Authorization: (0, getAuthorizationHeader_1.default)() } })
|
|
494
|
+
.then((r) => {
|
|
495
|
+
if (r.data.url) {
|
|
496
|
+
const width = 600;
|
|
497
|
+
const height = 525;
|
|
498
|
+
const left = window.screenX + (window.innerWidth - width) / 2;
|
|
499
|
+
const top = window.screenY + (window.innerHeight - height) / 2;
|
|
500
|
+
window.open(r.data.url, `roamjs:roamjs:stripe`, `left=${left},top=${top},width=${width},height=${height},status=1`);
|
|
501
|
+
const authInterval = () => {
|
|
502
|
+
axios_1.default
|
|
503
|
+
.get(`https://lambda.roamjs.com/check?extensionId=${extensionId}${dev}`, { headers: { Authorization: (0, getAuthorizationHeader_1.default)() } })
|
|
504
|
+
.then((r) => {
|
|
505
|
+
if (r.data.success) {
|
|
506
|
+
enableCallback(true, uid);
|
|
507
|
+
setAlertLoading(false);
|
|
508
|
+
setIsOpen(false);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
intervalListener.current = window.setTimeout(authInterval, 2000);
|
|
512
|
+
}
|
|
513
|
+
})
|
|
514
|
+
.catch((e) => {
|
|
515
|
+
catchError(e);
|
|
516
|
+
setAlertLoading(false);
|
|
517
|
+
setIsOpen(false);
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
authInterval();
|
|
521
|
+
}
|
|
522
|
+
else if (r.data.success) {
|
|
523
|
+
enableCallback(true, uid);
|
|
524
|
+
setAlertLoading(false);
|
|
525
|
+
setIsOpen(false);
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
setError("Something went wrong with the subscription. Please contact support@roamjs.com for help!");
|
|
529
|
+
setAlertLoading(false);
|
|
530
|
+
setIsOpen(false);
|
|
531
|
+
}
|
|
532
|
+
})
|
|
533
|
+
.catch(catchError)
|
|
534
|
+
.finally(() => {
|
|
535
|
+
setAlertLoading(false);
|
|
536
|
+
setIsOpen(false);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}, confirmButtonText: "Submit", cancelButtonText: "Cancel", intent: core_1.Intent.PRIMARY, loading: alertLoading, onCancel: () => setIsOpen(false) }, enabled
|
|
540
|
+
? `By clicking submit below, you will unsubscribe from the premium features of the RoamJS Extension: ${(0, idToTitle_1.default)(extensionId)}`
|
|
541
|
+
: `By clicking submit below, you will subscribe to the premium features of the RoamJS Extension: ${(0, idToTitle_1.default)(extensionId)} for ${pricingMessage}. A window may appear for checkout if this is your first premium extension`)));
|
|
542
|
+
};
|
|
543
|
+
const Panels = {
|
|
544
|
+
text: TextPanel,
|
|
545
|
+
time: TimePanel,
|
|
546
|
+
number: NumberPanel,
|
|
547
|
+
flag: FlagPanel,
|
|
548
|
+
pages: PagesPanel,
|
|
549
|
+
oauth: OauthPanel,
|
|
550
|
+
multitext: MultiTextPanel,
|
|
551
|
+
select: SelectPanel,
|
|
552
|
+
block: BlockPanel,
|
|
553
|
+
blocks: BlocksPanel,
|
|
554
|
+
custom: CustomPanel,
|
|
555
|
+
};
|
|
556
|
+
const tryColor = (s) => {
|
|
557
|
+
if (!s)
|
|
558
|
+
return undefined;
|
|
559
|
+
try {
|
|
560
|
+
return (0, color_1.default)(s);
|
|
561
|
+
}
|
|
562
|
+
catch (e) {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
const FieldTabs = ({ id, fields, uid: initialUid, pageUid, order, toggleable, extensionId, onEnable, onDisable, }) => {
|
|
567
|
+
const [uid, setUid] = (0, react_1.useState)(initialUid);
|
|
568
|
+
const parentUid = (0, react_1.useMemo)(() => {
|
|
569
|
+
if (/home/i.test(id)) {
|
|
570
|
+
return pageUid;
|
|
571
|
+
}
|
|
572
|
+
if (uid) {
|
|
573
|
+
return uid;
|
|
574
|
+
}
|
|
575
|
+
if (toggleable) {
|
|
576
|
+
return "";
|
|
577
|
+
}
|
|
578
|
+
const newUid = window.roamAlphaAPI.util.generateUID();
|
|
579
|
+
(0, writes_1.createBlock)({
|
|
580
|
+
parentUid: pageUid,
|
|
581
|
+
order,
|
|
582
|
+
node: { text: id, uid: newUid },
|
|
583
|
+
});
|
|
584
|
+
return newUid;
|
|
585
|
+
}, [pageUid, uid, id, toggleable]);
|
|
586
|
+
const childUids = Object.fromEntries((0, queries_1.getShallowTreeByParentUid)(parentUid).map(({ text, uid }) => [
|
|
587
|
+
text.toLowerCase().trim(),
|
|
588
|
+
uid,
|
|
589
|
+
]));
|
|
590
|
+
const [enabled, setEnabled] = (0, react_1.useState)(!toggleable || !!parentUid);
|
|
591
|
+
const [selectedTabId, setSelectedTabId] = (0, react_1.useState)(enabled && fields.length && typeof toggleable !== "string"
|
|
592
|
+
? fields[0].title
|
|
593
|
+
: "enabled");
|
|
594
|
+
const onTabsChange = (0, react_1.useCallback)((tabId) => setSelectedTabId(tabId), [setSelectedTabId]);
|
|
595
|
+
return (react_1.default.createElement(core_1.Tabs, { vertical: true, id: `${id}-field-tabs`, onChange: onTabsChange, selectedTabId: selectedTabId, renderActiveTabPanelOnly: true },
|
|
596
|
+
toggleable && (react_1.default.createElement(core_1.Tab, { id: "enabled", title: "enabled", panel: selectedTabId === "enabled" ? (react_1.default.createElement(ToggleablePanel, { id: id, uid: uid, pageUid: pageUid, extensionId: extensionId, enabled: enabled, order: order, toggleable: toggleable, setUid: setUid, setEnabled: setEnabled, onEnable: onEnable, onDisable: onDisable })) : undefined })),
|
|
597
|
+
fields.map((field, i) => {
|
|
598
|
+
const { type, title, defaultValue } = field;
|
|
599
|
+
const Panel = Panels[type];
|
|
600
|
+
return (react_1.default.createElement(core_1.Tab, { id: title, key: title, title: (0, idToTitle_1.default)(title), disabled: !enabled, panel: react_1.default.createElement(Panel, Object.assign({}, field, {
|
|
601
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
602
|
+
// @ts-ignore 4.3.0
|
|
603
|
+
defaultValue: defaultValue, order: i, parentUid: parentUid, uid: childUids[title.toLowerCase()] })) }));
|
|
604
|
+
})));
|
|
605
|
+
};
|
|
606
|
+
const ConfigPage = ({ id, config, pageUid, }) => {
|
|
607
|
+
var _a;
|
|
608
|
+
const userTabs = config.tabs.filter((t) => t.fields.length || t.toggleable);
|
|
609
|
+
const [selectedTabId, setSelectedTabId] = (0, react_1.useState)((_a = userTabs[0]) === null || _a === void 0 ? void 0 : _a.id);
|
|
610
|
+
const onTabsChange = (0, react_1.useCallback)((tabId) => setSelectedTabId(tabId), [setSelectedTabId]);
|
|
611
|
+
const tree = (0, queries_1.getBasicTreeByParentUid)(pageUid);
|
|
612
|
+
const [currentVersion, setCurrentVersion] = (0, react_1.useState)("");
|
|
613
|
+
const [experimentalMode, setExperimentalMode] = (0, react_1.useState)(!!(0, localStorageGet_1.default)("experimental"));
|
|
614
|
+
const titleRef = (0, react_1.useRef)(null);
|
|
615
|
+
(0, react_1.useEffect)(() => {
|
|
616
|
+
var _a, _b, _c;
|
|
617
|
+
if (config.versioning) {
|
|
618
|
+
(0, dom_1.addOldRoamJSDependency)("versioning");
|
|
619
|
+
const scriptVersionMatch = (_b = (_a = window.roamjs) === null || _a === void 0 ? void 0 : _a.version) === null || _b === void 0 ? void 0 : _b[id];
|
|
620
|
+
if (scriptVersionMatch) {
|
|
621
|
+
setCurrentVersion(scriptVersionMatch);
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
setCurrentVersion("Version Not Found");
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (userTabs.some((t) => t.development)) {
|
|
628
|
+
(_c = titleRef.current) === null || _c === void 0 ? void 0 : _c.addEventListener("keydown", (e) => {
|
|
629
|
+
if (e.ctrlKey &&
|
|
630
|
+
e.metaKey &&
|
|
631
|
+
e.shiftKey &&
|
|
632
|
+
e.altKey &&
|
|
633
|
+
e.key === "KeyM") {
|
|
634
|
+
const newVal = !(0, localStorageGet_1.default)("experimental");
|
|
635
|
+
setExperimentalMode(newVal);
|
|
636
|
+
if (newVal)
|
|
637
|
+
(0, localStorageSet_1.default)("experimental", "true");
|
|
638
|
+
else
|
|
639
|
+
(0, localStorageRemove_1.default)("experimental");
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
}, [config.versioning, id, setCurrentVersion, userTabs, titleRef]);
|
|
644
|
+
const brandColor = tryColor(config.brand);
|
|
645
|
+
return (react_1.default.createElement(core_1.Card, { style: { color: "#202B33" }, className: "roamjs-config-panel" },
|
|
646
646
|
react_1.default.createElement("style", null, `.roamjs-config-panel .bp3-tab-panel {
|
|
647
647
|
width: 100%;
|
|
648
648
|
position: relative;
|
|
@@ -650,7 +650,7 @@ const ConfigPage = ({ id, config, pageUid, }) => {
|
|
|
650
650
|
.roamjs-external-login {
|
|
651
651
|
margin-bottom: 16px;
|
|
652
652
|
}
|
|
653
|
-
${brandColor &&
|
|
653
|
+
${brandColor &&
|
|
654
654
|
`div.bp3-tab[aria-selected="true"], div.bp3-tab:not([aria-disabled="true"]):hover {
|
|
655
655
|
color: ${brandColor.toString()};
|
|
656
656
|
}
|
|
@@ -660,124 +660,124 @@ ${brandColor &&
|
|
|
660
660
|
}
|
|
661
661
|
|
|
662
662
|
.bp3-tabs.bp3-vertical>.bp3-tab-list .bp3-tab-indicator-wrapper div.bp3-tab-indicator {
|
|
663
|
-
background-color: ${brandColor
|
|
664
|
-
.alpha(0.2)
|
|
665
|
-
.lightness(brandColor.lightness() + 5)
|
|
663
|
+
background-color: ${brandColor
|
|
664
|
+
.alpha(0.2)
|
|
665
|
+
.lightness(brandColor.lightness() + 5)
|
|
666
666
|
.toString()};
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
.bp3-control input:checked ~ span.bp3-control-indicator {
|
|
670
|
-
background-color: ${brandColor
|
|
671
|
-
.lightness(brandColor.lightness() + 5)
|
|
670
|
+
background-color: ${brandColor
|
|
671
|
+
.lightness(brandColor.lightness() + 5)
|
|
672
672
|
.toString()}
|
|
673
|
-
}`}`),
|
|
674
|
-
react_1.default.createElement("div", { style: { display: "flex", justifyContent: "space-between" }, ref: titleRef, tabIndex: -1 },
|
|
675
|
-
react_1.default.createElement("h4", { style: { padding: 4 } },
|
|
676
|
-
(0, idToTitle_1.default)(id),
|
|
677
|
-
" Configuration"),
|
|
678
|
-
currentVersion && (react_1.default.createElement("span", null,
|
|
679
|
-
react_1.default.createElement("span", { style: { color: "#cccccc", fontSize: 8 } },
|
|
680
|
-
"v",
|
|
681
|
-
currentVersion),
|
|
682
|
-
react_1.default.createElement(core_1.Button, { icon: "git-branch", minimal: true, onClick: () => {
|
|
683
|
-
var _a, _b;
|
|
684
|
-
return ((_a = window.roamjs) === null || _a === void 0 ? void 0 : _a.extension.versioning) &&
|
|
685
|
-
((_b = window.roamjs) === null || _b === void 0 ? void 0 : _b.extension.versioning.switch({
|
|
686
|
-
id,
|
|
687
|
-
currentVersion,
|
|
688
|
-
}));
|
|
689
|
-
}, style: { marginLeft: 4 } })))),
|
|
690
|
-
react_1.default.createElement("style", null, `.roamjs-config-tabs {\npadding: 4px;\n}`),
|
|
691
|
-
react_1.default.createElement(core_1.Tabs, { id: `${id}-config-tabs`, onChange: onTabsChange, selectedTabId: selectedTabId, renderActiveTabPanelOnly: true, className: "roamjs-config-tabs" }, userTabs.map(({ id: tabId, fields, toggleable, development = false, onEnable, onDisable, }, i) => {
|
|
692
|
-
var _a;
|
|
693
|
-
return (react_1.default.createElement(core_1.Tab, { id: tabId, key: tabId, title: (0, idToTitle_1.default)(tabId), disabled: development && !experimentalMode, panel: react_1.default.createElement(FieldTabs, { id: tabId, extensionId: id, fields: fields, uid: ((_a = tree.find((t) => new RegExp(tabId, "i").test(t.text))) === null || _a === void 0 ? void 0 : _a.uid) || "", pageUid: pageUid, order: i, toggleable: toggleable, onEnable: onEnable, onDisable: onDisable }) }));
|
|
694
|
-
}))));
|
|
695
|
-
};
|
|
696
|
-
const fieldsToChildren = (t) => t.fields
|
|
697
|
-
.filter((f) => !!f.defaultValue)
|
|
698
|
-
.map((f) => {
|
|
699
|
-
var _a;
|
|
700
|
-
return ({
|
|
701
|
-
text: f.title,
|
|
702
|
-
children: f.type === "flag"
|
|
703
|
-
? []
|
|
704
|
-
: f.type === "custom"
|
|
705
|
-
? f.defaultValue || []
|
|
706
|
-
: f.type === "pages" || f.type === "multitext"
|
|
707
|
-
? (_a = f.defaultValue) === null || _a === void 0 ? void 0 : _a.map((v) => ({ text: v }))
|
|
708
|
-
: f.type === "block"
|
|
709
|
-
? f.defaultValue
|
|
710
|
-
? [f.defaultValue]
|
|
711
|
-
: []
|
|
712
|
-
: [{ text: `${f.defaultValue}` }],
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
const createConfigPage = ({ title, config, }) => {
|
|
716
|
-
const homeTab = config.tabs.find((t) => /home/i.test(t.id));
|
|
717
|
-
const rawTree = [
|
|
718
|
-
...(homeTab ? fieldsToChildren(homeTab) : []),
|
|
719
|
-
...config.tabs
|
|
720
|
-
.filter((t) => !/home/i.test(t.id) && !t.toggleable && !t.development)
|
|
721
|
-
.map((t) => ({
|
|
722
|
-
text: t.id,
|
|
723
|
-
children: fieldsToChildren(t),
|
|
724
|
-
})),
|
|
725
|
-
];
|
|
726
|
-
return (0, writes_1.createPage)({
|
|
727
|
-
title,
|
|
728
|
-
tree: rawTree.length ? rawTree : [{ text: " " }],
|
|
729
|
-
});
|
|
730
|
-
};
|
|
731
|
-
const render = ({ h, title, pageUid = (0, queries_1.getPageUidByPageTitle)(title), config, }) => {
|
|
732
|
-
var _a, _b;
|
|
733
|
-
const uid = (0, queries_1.getPageUidByPageTitle)(title);
|
|
734
|
-
const attribute = `data-roamjs-${uid}`;
|
|
735
|
-
const containerParent = (_a = h.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
736
|
-
if (containerParent && !containerParent.hasAttribute(attribute)) {
|
|
737
|
-
containerParent.setAttribute(attribute, "true");
|
|
738
|
-
const parent = document.createElement("div");
|
|
739
|
-
const configPageId = title.split("/").slice(-1)[0];
|
|
740
|
-
parent.id = `${configPageId}-config`;
|
|
741
|
-
containerParent.insertBefore(parent, ((_b = h.parentElement) === null || _b === void 0 ? void 0 : _b.nextElementSibling) || null);
|
|
742
|
-
react_dom_1.default.render(react_1.default.createElement(ConfigPage, { id: configPageId, config: config, pageUid: pageUid }), parent);
|
|
743
|
-
}
|
|
744
|
-
};
|
|
745
|
-
exports.render = render;
|
|
746
|
-
const createConfigObserver = ({ title, config, }) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
747
|
-
const pageUid = (0, queries_1.getPageUidByPageTitle)(title) ||
|
|
748
|
-
(yield createConfigPage({
|
|
749
|
-
title,
|
|
750
|
-
config,
|
|
751
|
-
}));
|
|
752
|
-
if (config.tabs.length) {
|
|
753
|
-
if (config.tabs.some((t) => t.toggleable === "premium"))
|
|
754
|
-
(0, TokenDialog_1.addTokenDialogCommand)({
|
|
755
|
-
onEnter: (token) => {
|
|
756
|
-
const toggleablePanel = document.getElementById("roamjs-toggleable-container");
|
|
757
|
-
if (toggleablePanel)
|
|
758
|
-
toggleablePanel.dispatchEvent(new CustomEvent("roamjs:token:set", { detail: token }));
|
|
759
|
-
},
|
|
760
|
-
});
|
|
761
|
-
(0, dom_1.createHTMLObserver)({
|
|
762
|
-
className: "rm-title-display",
|
|
763
|
-
tag: "H1",
|
|
764
|
-
callback: (d) => {
|
|
765
|
-
const h = d;
|
|
766
|
-
if (h.innerText === title) {
|
|
767
|
-
(0, exports.render)({
|
|
768
|
-
pageUid,
|
|
769
|
-
config,
|
|
770
|
-
title,
|
|
771
|
-
h,
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
},
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
return {
|
|
778
|
-
pageUid,
|
|
779
|
-
};
|
|
780
|
-
});
|
|
781
|
-
exports.createConfigObserver = createConfigObserver;
|
|
782
|
-
exports.default = ConfigPage;
|
|
673
|
+
}`}`),
|
|
674
|
+
react_1.default.createElement("div", { style: { display: "flex", justifyContent: "space-between" }, ref: titleRef, tabIndex: -1 },
|
|
675
|
+
react_1.default.createElement("h4", { style: { padding: 4 } },
|
|
676
|
+
(0, idToTitle_1.default)(id),
|
|
677
|
+
" Configuration"),
|
|
678
|
+
currentVersion && (react_1.default.createElement("span", null,
|
|
679
|
+
react_1.default.createElement("span", { style: { color: "#cccccc", fontSize: 8 } },
|
|
680
|
+
"v",
|
|
681
|
+
currentVersion),
|
|
682
|
+
react_1.default.createElement(core_1.Button, { icon: "git-branch", minimal: true, onClick: () => {
|
|
683
|
+
var _a, _b;
|
|
684
|
+
return ((_a = window.roamjs) === null || _a === void 0 ? void 0 : _a.extension.versioning) &&
|
|
685
|
+
((_b = window.roamjs) === null || _b === void 0 ? void 0 : _b.extension.versioning.switch({
|
|
686
|
+
id,
|
|
687
|
+
currentVersion,
|
|
688
|
+
}));
|
|
689
|
+
}, style: { marginLeft: 4 } })))),
|
|
690
|
+
react_1.default.createElement("style", null, `.roamjs-config-tabs {\npadding: 4px;\n}`),
|
|
691
|
+
react_1.default.createElement(core_1.Tabs, { id: `${id}-config-tabs`, onChange: onTabsChange, selectedTabId: selectedTabId, renderActiveTabPanelOnly: true, className: "roamjs-config-tabs" }, userTabs.map(({ id: tabId, fields, toggleable, development = false, onEnable, onDisable, }, i) => {
|
|
692
|
+
var _a;
|
|
693
|
+
return (react_1.default.createElement(core_1.Tab, { id: tabId, key: tabId, title: (0, idToTitle_1.default)(tabId), disabled: development && !experimentalMode, panel: react_1.default.createElement(FieldTabs, { id: tabId, extensionId: id, fields: fields, uid: ((_a = tree.find((t) => new RegExp(tabId, "i").test(t.text))) === null || _a === void 0 ? void 0 : _a.uid) || "", pageUid: pageUid, order: i, toggleable: toggleable, onEnable: onEnable, onDisable: onDisable }) }));
|
|
694
|
+
}))));
|
|
695
|
+
};
|
|
696
|
+
const fieldsToChildren = (t) => t.fields
|
|
697
|
+
.filter((f) => !!f.defaultValue)
|
|
698
|
+
.map((f) => {
|
|
699
|
+
var _a;
|
|
700
|
+
return ({
|
|
701
|
+
text: f.title,
|
|
702
|
+
children: f.type === "flag"
|
|
703
|
+
? []
|
|
704
|
+
: f.type === "custom"
|
|
705
|
+
? f.defaultValue || []
|
|
706
|
+
: f.type === "pages" || f.type === "multitext"
|
|
707
|
+
? (_a = f.defaultValue) === null || _a === void 0 ? void 0 : _a.map((v) => ({ text: v }))
|
|
708
|
+
: f.type === "block"
|
|
709
|
+
? f.defaultValue
|
|
710
|
+
? [f.defaultValue]
|
|
711
|
+
: []
|
|
712
|
+
: [{ text: `${f.defaultValue}` }],
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
const createConfigPage = ({ title, config, }) => {
|
|
716
|
+
const homeTab = config.tabs.find((t) => /home/i.test(t.id));
|
|
717
|
+
const rawTree = [
|
|
718
|
+
...(homeTab ? fieldsToChildren(homeTab) : []),
|
|
719
|
+
...config.tabs
|
|
720
|
+
.filter((t) => !/home/i.test(t.id) && !t.toggleable && !t.development)
|
|
721
|
+
.map((t) => ({
|
|
722
|
+
text: t.id,
|
|
723
|
+
children: fieldsToChildren(t),
|
|
724
|
+
})),
|
|
725
|
+
];
|
|
726
|
+
return (0, writes_1.createPage)({
|
|
727
|
+
title,
|
|
728
|
+
tree: rawTree.length ? rawTree : [{ text: " " }],
|
|
729
|
+
});
|
|
730
|
+
};
|
|
731
|
+
const render = ({ h, title, pageUid = (0, queries_1.getPageUidByPageTitle)(title), config, }) => {
|
|
732
|
+
var _a, _b;
|
|
733
|
+
const uid = (0, queries_1.getPageUidByPageTitle)(title);
|
|
734
|
+
const attribute = `data-roamjs-${uid}`;
|
|
735
|
+
const containerParent = (_a = h.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
736
|
+
if (containerParent && !containerParent.hasAttribute(attribute)) {
|
|
737
|
+
containerParent.setAttribute(attribute, "true");
|
|
738
|
+
const parent = document.createElement("div");
|
|
739
|
+
const configPageId = title.split("/").slice(-1)[0];
|
|
740
|
+
parent.id = `${configPageId}-config`;
|
|
741
|
+
containerParent.insertBefore(parent, ((_b = h.parentElement) === null || _b === void 0 ? void 0 : _b.nextElementSibling) || null);
|
|
742
|
+
react_dom_1.default.render(react_1.default.createElement(ConfigPage, { id: configPageId, config: config, pageUid: pageUid }), parent);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
exports.render = render;
|
|
746
|
+
const createConfigObserver = ({ title, config, }) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
747
|
+
const pageUid = (0, queries_1.getPageUidByPageTitle)(title) ||
|
|
748
|
+
(yield createConfigPage({
|
|
749
|
+
title,
|
|
750
|
+
config,
|
|
751
|
+
}));
|
|
752
|
+
if (config.tabs.length) {
|
|
753
|
+
if (config.tabs.some((t) => t.toggleable === "premium"))
|
|
754
|
+
(0, TokenDialog_1.addTokenDialogCommand)({
|
|
755
|
+
onEnter: (token) => {
|
|
756
|
+
const toggleablePanel = document.getElementById("roamjs-toggleable-container");
|
|
757
|
+
if (toggleablePanel)
|
|
758
|
+
toggleablePanel.dispatchEvent(new CustomEvent("roamjs:token:set", { detail: token }));
|
|
759
|
+
},
|
|
760
|
+
});
|
|
761
|
+
(0, dom_1.createHTMLObserver)({
|
|
762
|
+
className: "rm-title-display",
|
|
763
|
+
tag: "H1",
|
|
764
|
+
callback: (d) => {
|
|
765
|
+
const h = d;
|
|
766
|
+
if (h.innerText === title) {
|
|
767
|
+
(0, exports.render)({
|
|
768
|
+
pageUid,
|
|
769
|
+
config,
|
|
770
|
+
title,
|
|
771
|
+
h,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
pageUid,
|
|
779
|
+
};
|
|
780
|
+
});
|
|
781
|
+
exports.createConfigObserver = createConfigObserver;
|
|
782
|
+
exports.default = ConfigPage;
|
|
783
783
|
//# sourceMappingURL=ConfigPage.js.map
|