roamjs-components 0.62.5 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/backend/putRoamJSUser.d.ts +1 -1
  2. package/backend/putRoamJSUser.js +5 -8
  3. package/backend/putRoamJSUser.js.map +1 -1
  4. package/components/ConfigPage.d.ts +3 -68
  5. package/components/ConfigPage.js +11 -391
  6. package/components/ConfigPage.js.map +1 -1
  7. package/components/ConfigPanels/BlockPanel.d.ts +3 -0
  8. package/components/ConfigPanels/BlockPanel.js +43 -0
  9. package/components/ConfigPanels/BlockPanel.js.map +1 -0
  10. package/components/ConfigPanels/BlocksPanel.d.ts +3 -0
  11. package/components/ConfigPanels/BlocksPanel.js +61 -0
  12. package/components/ConfigPanels/BlocksPanel.js.map +1 -0
  13. package/components/ConfigPanels/CustomPanel.d.ts +3 -0
  14. package/components/ConfigPanels/CustomPanel.js +25 -0
  15. package/components/ConfigPanels/CustomPanel.js.map +1 -0
  16. package/components/ConfigPanels/FlagPanel.d.ts +3 -0
  17. package/components/ConfigPanels/FlagPanel.js +32 -0
  18. package/components/ConfigPanels/FlagPanel.js.map +1 -0
  19. package/components/ConfigPanels/MultiChildPanel.d.ts +13 -0
  20. package/components/ConfigPanels/MultiChildPanel.js +58 -0
  21. package/components/ConfigPanels/MultiChildPanel.js.map +1 -0
  22. package/components/ConfigPanels/MultiTextPanel.d.ts +3 -0
  23. package/components/ConfigPanels/MultiTextPanel.js +12 -0
  24. package/components/ConfigPanels/MultiTextPanel.js.map +1 -0
  25. package/components/ConfigPanels/NumberPanel.d.ts +3 -0
  26. package/components/ConfigPanels/NumberPanel.js +26 -0
  27. package/components/ConfigPanels/NumberPanel.js.map +1 -0
  28. package/components/ConfigPanels/OauthPanel.d.ts +3 -0
  29. package/components/ConfigPanels/OauthPanel.js +82 -0
  30. package/components/ConfigPanels/OauthPanel.js.map +1 -0
  31. package/components/ConfigPanels/PagesPanel.d.ts +3 -0
  32. package/components/ConfigPanels/PagesPanel.js +12 -0
  33. package/components/ConfigPanels/PagesPanel.js.map +1 -0
  34. package/components/ConfigPanels/SelectPanel.d.ts +3 -0
  35. package/components/ConfigPanels/SelectPanel.js +28 -0
  36. package/components/ConfigPanels/SelectPanel.js.map +1 -0
  37. package/components/ConfigPanels/TextPanel.d.ts +3 -0
  38. package/components/ConfigPanels/TextPanel.js +26 -0
  39. package/components/ConfigPanels/TextPanel.js.map +1 -0
  40. package/components/ConfigPanels/TimePanel.d.ts +3 -0
  41. package/components/ConfigPanels/TimePanel.js +35 -0
  42. package/components/ConfigPanels/TimePanel.js.map +1 -0
  43. package/components/ConfigPanels/getBrandColors.d.ts +7 -0
  44. package/components/ConfigPanels/getBrandColors.js +29 -0
  45. package/components/ConfigPanels/getBrandColors.js.map +1 -0
  46. package/components/ConfigPanels/types.d.ts +76 -0
  47. package/components/ConfigPanels/types.js +3 -0
  48. package/components/ConfigPanels/types.js.map +1 -0
  49. package/components/ConfigPanels/useSingleChildValue.d.ts +13 -0
  50. package/components/ConfigPanels/useSingleChildValue.js +44 -0
  51. package/components/ConfigPanels/useSingleChildValue.js.map +1 -0
  52. package/components/ExternalLogin.js +10 -1
  53. package/components/ExternalLogin.js.map +1 -1
  54. package/date/constants.d.ts +1 -0
  55. package/date/constants.js +15 -1
  56. package/date/constants.js.map +1 -1
  57. package/date/parseRoamDate.js +5 -3
  58. package/date/parseRoamDate.js.map +1 -1
  59. package/date/parseRoamDateUid.js +4 -3
  60. package/date/parseRoamDateUid.js.map +1 -1
  61. package/date/toRoamDate.js +10 -3
  62. package/date/toRoamDate.js.map +1 -1
  63. package/date/toRoamDateUid.js +6 -3
  64. package/date/toRoamDateUid.js.map +1 -1
  65. package/package.json +6 -4
@@ -23,7 +23,7 @@ export declare const awsPutRoamJSUser: (event: {
23
23
  };
24
24
  } | {
25
25
  statusCode: number;
26
- body: any;
26
+ body: string;
27
27
  headers: {
28
28
  "Access-Control-Allow-Origin": string;
29
29
  "Access-Control-Allow-Methods": string;
@@ -42,14 +42,11 @@ const awsPutRoamJSUser = (event, data) => putRoamJSUser({
42
42
  body: JSON.stringify(data),
43
43
  headers: headers_1.default,
44
44
  }))
45
- .catch((e) => {
46
- var _a;
47
- return ({
48
- statusCode: 401,
49
- body: (_a = e.response) === null || _a === void 0 ? void 0 : _a.data,
50
- headers: headers_1.default,
51
- });
52
- });
45
+ .catch((e) => ({
46
+ statusCode: 401,
47
+ body: e.message,
48
+ headers: headers_1.default,
49
+ }));
53
50
  exports.awsPutRoamJSUser = awsPutRoamJSUser;
54
51
  exports.default = putRoamJSUser;
55
52
  //# sourceMappingURL=putRoamJSUser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"putRoamJSUser.js","sourceRoot":"","sources":["../src/backend/putRoamJSUser.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,gEAAgC;AAEhC,MAAM,aAAa,GAAG,CAAC,EACrB,KAAK,EACL,IAAI,EACJ,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,EAAE,EACnD,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,EAChC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,GAO7C,EAAE,EAAE,CACH,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACpD,MAAM,GAAG,GAAG,eAAK;SACd,OAAO,CACN,gCAAgC,EAChC;QACE,MAAM,EAAE,KAAK;QACb,OAAO,kBACL,aAAa,EAAE,UAAU,MAAM,CAAC,IAAI,CAClC,GAAG,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CACjD,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EACtB,gBAAgB,EAAE,KAAK,EACvB,oBAAoB,EAAE,WAAW,IAC9B,CAAC,GAAG;YACL,CAAC,CAAC;gBACE,cAAc,EAAE,MAAM;aACvB;YACH,CAAC,CAAC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EAAP,iBAAO;CACR,CAAC,CAAC,CAAC;AAjBK,QAAA,gBAAgB,oBAiBrB;AAER,kBAAe,aAAa,CAAC"}
@@ -1,71 +1,6 @@
1
1
  import React from "react";
2
- import type { InputTextNode } from "../types";
3
- import { ExternalLoginOptions } from "./ExternalLogin";
4
- declare type TextField = {
5
- type: "text";
6
- defaultValue?: string;
7
- };
8
- declare type TimeField = {
9
- type: "time";
10
- defaultValue?: Date;
11
- };
12
- declare type NumberField = {
13
- type: "number";
14
- defaultValue?: number;
15
- };
16
- declare type FlagField = {
17
- type: "flag";
18
- defaultValue?: boolean;
19
- options?: {
20
- onChange?: (f: boolean) => void;
21
- };
22
- };
23
- declare type MultiTextField = {
24
- type: "multitext";
25
- defaultValue?: string[];
26
- };
27
- declare type PagesField = {
28
- type: "pages";
29
- defaultValue?: string[];
30
- };
31
- declare type OauthField = {
32
- type: "oauth";
33
- defaultValue?: [];
34
- options: ExternalLoginOptions;
35
- };
36
- declare type SelectField = {
37
- type: "select";
38
- defaultValue?: string;
39
- options: {
40
- items: string[] | (() => string[]);
41
- };
42
- };
43
- declare type BlockField = {
44
- type: "block";
45
- defaultValue?: InputTextNode;
46
- };
47
- declare type BlocksField = {
48
- type: "blocks";
49
- defaultValue?: InputTextNode[];
50
- };
51
- declare type CustomField = {
52
- type: "custom";
53
- defaultValue?: InputTextNode[];
54
- options: {
55
- component: React.FC<{
56
- parentUid: string;
57
- uid: string;
58
- defaultValue: InputTextNode[];
59
- title: string;
60
- }>;
61
- };
62
- };
63
- declare type ArrayField = PagesField | MultiTextField | CustomField | BlocksField;
64
- declare type UnionField = ArrayField | TextField | TimeField | NumberField | OauthField | FlagField | SelectField | BlockField;
65
- declare type Field<T extends UnionField> = T & {
66
- title: string;
67
- description: string;
68
- };
2
+ import type { Field, UnionField } from "./ConfigPanels/types";
3
+ import { Brand } from "./ConfigPanels/getBrandColors";
69
4
  declare type ConfigTab = {
70
5
  id: string;
71
6
  toggleable?: boolean | "premium";
@@ -77,7 +12,7 @@ declare type ConfigTab = {
77
12
  declare type Config = {
78
13
  tabs: ConfigTab[];
79
14
  versioning?: boolean;
80
- brand?: string;
15
+ brand?: Brand;
81
16
  };
82
17
  declare const ConfigPage: ({ id, config, pageUid, }: {
83
18
  id: string;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createConfigObserver = exports.render = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@blueprintjs/core");
6
- const datetime_1 = require("@blueprintjs/datetime");
7
6
  const react_1 = tslib_1.__importStar(require("react"));
8
7
  const react_dom_1 = tslib_1.__importDefault(require("react-dom"));
9
8
  const addOldRoamJSDependency_1 = tslib_1.__importDefault(require("../dom/addOldRoamJSDependency"));
@@ -12,363 +11,13 @@ const createBlock_1 = tslib_1.__importDefault(require("../writes/createBlock"));
12
11
  const createPage_1 = tslib_1.__importDefault(require("../writes/createPage"));
13
12
  const deleteBlock_1 = tslib_1.__importDefault(require("../writes/deleteBlock"));
14
13
  const getBasicTreeByParentUid_1 = tslib_1.__importDefault(require("../queries/getBasicTreeByParentUid"));
15
- const getFirstChildUidByBlockUid_1 = tslib_1.__importDefault(require("../queries/getFirstChildUidByBlockUid"));
16
14
  const getPageUidByPageTitle_1 = tslib_1.__importDefault(require("../queries/getPageUidByPageTitle"));
17
15
  const getShallowTreeByParentUid_1 = tslib_1.__importDefault(require("../queries/getShallowTreeByParentUid"));
18
- const getTextByBlockUid_1 = tslib_1.__importDefault(require("../queries/getTextByBlockUid"));
19
16
  const localStorageGet_1 = tslib_1.__importDefault(require("../util/localStorageGet"));
20
- const localStorageRemove_1 = tslib_1.__importDefault(require("../util/localStorageRemove"));
21
- const localStorageSet_1 = tslib_1.__importDefault(require("../util/localStorageSet"));
22
- const startOfDay_1 = tslib_1.__importDefault(require("date-fns/startOfDay"));
23
- const Description_1 = tslib_1.__importDefault(require("./Description"));
24
- const ExternalLogin_1 = tslib_1.__importDefault(require("./ExternalLogin"));
25
17
  const idToTitle_1 = tslib_1.__importDefault(require("../util/idToTitle"));
26
- const MenuItemSelect_1 = tslib_1.__importDefault(require("./MenuItemSelect"));
27
- const PageInput_1 = tslib_1.__importDefault(require("./PageInput"));
28
- const format_1 = tslib_1.__importDefault(require("date-fns/format"));
29
- const color_1 = tslib_1.__importDefault(require("color"));
30
18
  const TokenDialog_1 = require("./TokenDialog");
31
19
  const apiGet_1 = tslib_1.__importDefault(require("../util/apiGet"));
32
20
  const apiPost_1 = tslib_1.__importDefault(require("../util/apiPost"));
33
- const useSingleChildValue = ({ defaultValue, uid: initialUid, title, parentUid, order, transform, toStr, }) => {
34
- const [uid, setUid] = (0, react_1.useState)(initialUid);
35
- const [valueUid, setValueUid] = (0, react_1.useState)(uid && (0, getFirstChildUidByBlockUid_1.default)(uid));
36
- const [value, setValue] = (0, react_1.useState)((valueUid && transform((0, getTextByBlockUid_1.default)(valueUid))) || defaultValue);
37
- const onChange = (0, react_1.useCallback)((v) => {
38
- setValue(v);
39
- if (valueUid) {
40
- window.roamAlphaAPI.updateBlock({
41
- block: { string: toStr(v), uid: valueUid },
42
- });
43
- }
44
- else if (uid) {
45
- const newValueUid = window.roamAlphaAPI.util.generateUID();
46
- window.roamAlphaAPI.createBlock({
47
- block: { string: toStr(v), uid: newValueUid },
48
- location: { order: 0, "parent-uid": uid },
49
- });
50
- setValueUid(newValueUid);
51
- }
52
- else {
53
- const newUid = window.roamAlphaAPI.util.generateUID();
54
- window.roamAlphaAPI.createBlock({
55
- block: { string: title, uid: newUid },
56
- location: { order, "parent-uid": parentUid },
57
- });
58
- setTimeout(() => setUid(newUid));
59
- const newValueUid = window.roamAlphaAPI.util.generateUID();
60
- window.roamAlphaAPI.createBlock({
61
- block: { string: toStr(v), uid: newValueUid },
62
- location: { order: 0, "parent-uid": newUid },
63
- });
64
- setValueUid(newValueUid);
65
- }
66
- }, [setValue, setValueUid, title, parentUid, order, uid, valueUid, setUid]);
67
- return { value, onChange };
68
- };
69
- const MultiChildPanel = ({ uid: initialUid, title, description, order, parentUid, InputComponent, }) => {
70
- const [uid, setUid] = (0, react_1.useState)(initialUid);
71
- const [texts, setTexts] = (0, react_1.useState)(() => uid ? (0, getShallowTreeByParentUid_1.default)(uid) : []);
72
- const [value, setValue] = (0, react_1.useState)("");
73
- return (react_1.default.createElement(react_1.default.Fragment, null,
74
- react_1.default.createElement(core_1.Label, null,
75
- (0, idToTitle_1.default)(title),
76
- react_1.default.createElement(Description_1.default, { description: description }),
77
- react_1.default.createElement("div", { style: { display: "flex" } },
78
- react_1.default.createElement(InputComponent, { value: value, setValue: setValue }),
79
- react_1.default.createElement(core_1.Button, { icon: "plus", minimal: true, disabled: !value, onClick: () => {
80
- const valueUid = window.roamAlphaAPI.util.generateUID();
81
- if (uid) {
82
- window.roamAlphaAPI.createBlock({
83
- location: { "parent-uid": uid, order: texts.length },
84
- block: { string: value, uid: valueUid },
85
- });
86
- }
87
- else {
88
- const newUid = window.roamAlphaAPI.util.generateUID();
89
- window.roamAlphaAPI.createBlock({
90
- block: { string: title, uid: newUid },
91
- location: { order, "parent-uid": parentUid },
92
- });
93
- setTimeout(() => setUid(newUid));
94
- window.roamAlphaAPI.createBlock({
95
- block: { string: value, uid: valueUid },
96
- location: { order: 0, "parent-uid": newUid },
97
- });
98
- }
99
- setTexts([...texts, { text: value, uid: valueUid }]);
100
- setValue("");
101
- } }))),
102
- texts.map((p) => (react_1.default.createElement("div", { key: p.uid, style: {
103
- display: "flex",
104
- alignItems: "center",
105
- justifyContent: "space-between",
106
- } },
107
- react_1.default.createElement("span", { style: {
108
- textOverflow: "ellipsis",
109
- whiteSpace: "nowrap",
110
- overflow: "hidden",
111
- } }, p.text),
112
- react_1.default.createElement(core_1.Button, { icon: "trash", minimal: true, onClick: () => {
113
- window.roamAlphaAPI.deleteBlock({ block: { uid: p.uid } });
114
- setTexts(texts.filter((f) => f.uid !== p.uid));
115
- } }))))));
116
- };
117
- const TextPanel = ({ title, uid, parentUid, order, description, defaultValue = "", }) => {
118
- const { value, onChange } = useSingleChildValue({
119
- defaultValue,
120
- title,
121
- uid,
122
- parentUid,
123
- order,
124
- transform: (s) => s,
125
- toStr: (s) => s,
126
- });
127
- return (react_1.default.createElement(core_1.Label, null,
128
- (0, idToTitle_1.default)(title),
129
- react_1.default.createElement(Description_1.default, { description: description }),
130
- react_1.default.createElement(core_1.InputGroup, { value: value, onChange: (e) => onChange(e.target.value) })));
131
- };
132
- const TimePanel = ({ title, uid, parentUid, order, description, defaultValue = (0, startOfDay_1.default)(new Date()), }) => {
133
- const { value, onChange } = useSingleChildValue({
134
- defaultValue,
135
- title,
136
- uid,
137
- parentUid,
138
- order,
139
- transform: (s) => {
140
- const d = new Date();
141
- const [hours, minutes] = s.split(":");
142
- d.setHours(Number(hours));
143
- d.setMinutes(Number(minutes));
144
- return d;
145
- },
146
- toStr: (v) => (0, format_1.default)(v, "HH:mm"),
147
- });
148
- return (react_1.default.createElement(core_1.Label, null,
149
- (0, idToTitle_1.default)(title),
150
- react_1.default.createElement(Description_1.default, { description: description }),
151
- react_1.default.createElement(datetime_1.TimePicker, { value: value, onChange: onChange, showArrowButtons: true })));
152
- };
153
- const NumberPanel = ({ title, uid, parentUid, order, description, defaultValue = 0, }) => {
154
- const { value, onChange } = useSingleChildValue({
155
- defaultValue,
156
- title,
157
- uid,
158
- parentUid,
159
- order,
160
- transform: parseInt,
161
- toStr: (v) => `${v}`,
162
- });
163
- return (react_1.default.createElement(core_1.Label, null,
164
- (0, idToTitle_1.default)(title),
165
- react_1.default.createElement(Description_1.default, { description: description }),
166
- react_1.default.createElement(core_1.NumericInput, { value: value, onValueChange: onChange })));
167
- };
168
- const SelectPanel = ({ title, uid, parentUid, order, description, defaultValue = "", options: { items }, }) => {
169
- const optionItems = (0, react_1.useMemo)(() => (typeof items === "function" ? items() : items), [items]);
170
- const { value, onChange } = useSingleChildValue({
171
- defaultValue: defaultValue || optionItems[0],
172
- title,
173
- uid,
174
- parentUid,
175
- order,
176
- transform: (s) => s,
177
- toStr: (s) => s,
178
- });
179
- return (react_1.default.createElement(core_1.Label, null,
180
- (0, idToTitle_1.default)(title),
181
- react_1.default.createElement(Description_1.default, { description: description }),
182
- react_1.default.createElement(MenuItemSelect_1.default, { activeItem: value, onItemSelect: (e) => onChange(e), items: optionItems })));
183
- };
184
- const FlagPanel = ({ title, uid: initialUid, parentUid, order, description, options = {}, }) => {
185
- const [uid, setUid] = (0, react_1.useState)(initialUid);
186
- return (react_1.default.createElement(core_1.Checkbox, { checked: !!uid, onChange: (e) => {
187
- var _a;
188
- const { checked } = e.target;
189
- if (checked) {
190
- const newUid = window.roamAlphaAPI.util.generateUID();
191
- window.roamAlphaAPI.createBlock({
192
- block: { string: title, uid: newUid },
193
- location: { order, "parent-uid": parentUid },
194
- });
195
- setTimeout(() => setUid(newUid), 1);
196
- }
197
- else {
198
- window.roamAlphaAPI.deleteBlock({ block: { uid } });
199
- setUid("");
200
- }
201
- (_a = options.onChange) === null || _a === void 0 ? void 0 : _a.call(options, checked);
202
- }, labelElement: react_1.default.createElement(react_1.default.Fragment, null,
203
- (0, idToTitle_1.default)(title),
204
- react_1.default.createElement(Description_1.default, { description: description })) }));
205
- };
206
- const MultiTextPanel = (props) => {
207
- 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) })) })));
208
- };
209
- const PagesPanel = (props) => {
210
- return (react_1.default.createElement(MultiChildPanel, Object.assign({}, props, { InputComponent: (inputProps) => (react_1.default.createElement(PageInput_1.default, Object.assign({ extra: ["{all}"] }, inputProps))) })));
211
- };
212
- const OauthPanel = ({ uid, parentUid, options }) => {
213
- const key = `oauth-${options.service}`;
214
- const [useLocal, setUseLocal] = (0, react_1.useState)(!!(0, localStorageGet_1.default)(key));
215
- const [accounts, setAccounts] = (0, react_1.useState)(() => useLocal
216
- ? JSON.parse((0, localStorageGet_1.default)(key))
217
- : uid
218
- ? (0, getBasicTreeByParentUid_1.default)(uid).map((v) => {
219
- var _a, _b;
220
- return ({
221
- text: ((_a = v.children[0]) === null || _a === void 0 ? void 0 : _a.text) ? v.text : "Default Account",
222
- uid: v.uid,
223
- data: ((_b = v.children[0]) === null || _b === void 0 ? void 0 : _b.text) || v.text,
224
- });
225
- })
226
- : []);
227
- const onCheck = (0, react_1.useCallback)((e) => {
228
- const checked = e.target.checked;
229
- setUseLocal(checked);
230
- if (checked) {
231
- if (uid) {
232
- (0, getShallowTreeByParentUid_1.default)(uid).forEach(({ uid: u }) => (0, deleteBlock_1.default)(u));
233
- }
234
- (0, localStorageSet_1.default)(key, JSON.stringify(accounts));
235
- }
236
- else {
237
- (0, localStorageRemove_1.default)(key);
238
- if (uid) {
239
- accounts.forEach(({ text, uid: u, data }, order) => {
240
- window.roamAlphaAPI.createBlock({
241
- location: { "parent-uid": uid, order },
242
- block: { string: text, uid: u },
243
- });
244
- window.roamAlphaAPI.createBlock({
245
- location: { "parent-uid": u, order: 0 },
246
- block: { string: data },
247
- });
248
- });
249
- }
250
- }
251
- }, [setUseLocal, accounts, uid, key]);
252
- return (react_1.default.createElement(react_1.default.Fragment, null,
253
- react_1.default.createElement(core_1.Checkbox, { labelElement: react_1.default.createElement(react_1.default.Fragment, null,
254
- "Store Locally",
255
- 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 }),
256
- react_1.default.createElement(ExternalLogin_1.default, Object.assign({ useLocal: useLocal, onSuccess: (acc) => setAccounts([...accounts, acc]), parentUid: parentUid, loggedIn: !!accounts.length }, options)),
257
- !!accounts.length && (react_1.default.createElement(react_1.default.Fragment, null,
258
- react_1.default.createElement("h5", { style: { marginTop: 8 } }, "Accounts"),
259
- react_1.default.createElement("hr", null),
260
- react_1.default.createElement("ul", { style: { marginTop: 8, padding: 0 } }, accounts.map((act) => (react_1.default.createElement("li", { key: act.uid, style: {
261
- display: "flex",
262
- justifyContent: "space-between",
263
- alignItems: "center",
264
- marginTop: 8,
265
- } },
266
- react_1.default.createElement("span", { style: { minWidth: 192 } }, act.text),
267
- react_1.default.createElement(core_1.Button, { text: "Log Out", onClick: () => {
268
- if (useLocal) {
269
- const accts = JSON.parse((0, localStorageGet_1.default)(key));
270
- (0, localStorageSet_1.default)(key, JSON.stringify(accts.filter((a) => act.uid !== a.uid)));
271
- }
272
- else {
273
- (0, deleteBlock_1.default)(act.uid);
274
- }
275
- setAccounts(accounts.filter((a) => act.uid !== a.uid));
276
- } })))))))));
277
- };
278
- const BlockPanel = ({ uid: initialUid, parentUid, title, defaultValue, description, }) => {
279
- const containerRef = (0, react_1.useRef)(null);
280
- (0, react_1.useEffect)(() => {
281
- if (containerRef.current) {
282
- const el = containerRef.current;
283
- (initialUid
284
- ? Promise.resolve(initialUid)
285
- : (0, createBlock_1.default)({ node: { text: title, children: [] }, parentUid }))
286
- .then((formatUid) => (0, getFirstChildUidByBlockUid_1.default)(formatUid) ||
287
- (0, createBlock_1.default)({
288
- node: defaultValue || { text: " " },
289
- parentUid: formatUid,
290
- }))
291
- .then((uid) => {
292
- window.roamAlphaAPI.ui.components.renderBlock({
293
- uid,
294
- el,
295
- });
296
- });
297
- }
298
- }, [containerRef, defaultValue]);
299
- return (react_1.default.createElement(react_1.default.Fragment, null,
300
- react_1.default.createElement(core_1.Label, null,
301
- (0, idToTitle_1.default)(title),
302
- react_1.default.createElement(Description_1.default, { description: description })),
303
- react_1.default.createElement("div", { ref: containerRef, style: {
304
- border: "1px solid #33333333",
305
- padding: "8px 0",
306
- borderRadius: 4,
307
- } })));
308
- };
309
- const BlocksPanel = ({ uid: initialUid, parentUid, title, defaultValue, description, }) => {
310
- const containerRef = (0, react_1.useRef)(null);
311
- (0, react_1.useEffect)(() => {
312
- if (containerRef.current) {
313
- const el = containerRef.current;
314
- (initialUid
315
- ? Promise.resolve(initialUid)
316
- : (0, createBlock_1.default)({ node: { text: title, children: [] }, parentUid }))
317
- .then((formatUid) => (0, getFirstChildUidByBlockUid_1.default)(formatUid)
318
- ? formatUid
319
- : ((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length)
320
- ? Promise.all(defaultValue.map((node, order) => (0, createBlock_1.default)({
321
- node,
322
- parentUid: formatUid,
323
- order,
324
- })))
325
- : (0, createBlock_1.default)({
326
- node: { text: " " },
327
- parentUid: formatUid,
328
- })).then(() => formatUid))
329
- .then((uid) => {
330
- window.roamAlphaAPI.ui.components.renderBlock({
331
- uid,
332
- el,
333
- });
334
- });
335
- }
336
- }, [containerRef, defaultValue]);
337
- return (react_1.default.createElement(react_1.default.Fragment, null,
338
- react_1.default.createElement(core_1.Label, null,
339
- (0, idToTitle_1.default)(title),
340
- react_1.default.createElement(Description_1.default, { description: description })),
341
- react_1.default.createElement("style", null, `.roamjs-config-blocks > div > .rm-block-main {
342
- display: none;
343
- }
344
-
345
- .roamjs-config-blocks > div > .rm-block-children > .rm-multibar {
346
- display: none;
347
- }
348
-
349
- .roamjs-config-blocks > div > .rm-block-children {
350
- margin-left: -4px;
351
- }`),
352
- react_1.default.createElement("div", { ref: containerRef, style: {
353
- border: "1px solid #33333333",
354
- padding: "8px 0",
355
- borderRadius: 4,
356
- }, className: "roamjs-config-blocks" })));
357
- };
358
- const CustomPanel = ({ description, title, uid: inputUid, options: { component: Component }, parentUid, defaultValue = [], order, }) => {
359
- const uid = (0, react_1.useMemo)(() => {
360
- if (inputUid)
361
- return inputUid;
362
- const newUid = window.roamAlphaAPI.util.generateUID();
363
- (0, createBlock_1.default)({ node: { text: title, uid: newUid }, parentUid, order });
364
- return newUid;
365
- }, [inputUid]);
366
- return (react_1.default.createElement(react_1.default.Fragment, null,
367
- react_1.default.createElement(core_1.Label, null,
368
- (0, idToTitle_1.default)(title),
369
- react_1.default.createElement(Description_1.default, { description: description })),
370
- react_1.default.createElement(Component, { uid: uid, parentUid: parentUid, title: title, defaultValue: defaultValue })));
371
- };
372
21
  const ToggleablePanel = ({ enabled, setEnabled, pageUid, order, id, extensionId, setUid, uid, toggleable, onEnable, onDisable, }) => {
373
22
  const uidRef = (0, react_1.useRef)(uid);
374
23
  const isPremium = (0, react_1.useMemo)(() => toggleable !== true, [toggleable]);
@@ -541,29 +190,6 @@ const ToggleablePanel = ({ enabled, setEnabled, pageUid, order, id, extensionId,
541
190
  ? `By clicking submit below, you will unsubscribe from the premium features of the RoamJS Extension: ${(0, idToTitle_1.default)(extensionId)}`
542
191
  : `By clicking submit below, you will subscribe to the premium features of the RoamJS Extension: ${(0, idToTitle_1.default)(extensionId)}.\n\nA window may appear for checkout if this is your first premium extension.`)));
543
192
  };
544
- const Panels = {
545
- text: TextPanel,
546
- time: TimePanel,
547
- number: NumberPanel,
548
- flag: FlagPanel,
549
- pages: PagesPanel,
550
- oauth: OauthPanel,
551
- multitext: MultiTextPanel,
552
- select: SelectPanel,
553
- block: BlockPanel,
554
- blocks: BlocksPanel,
555
- custom: CustomPanel,
556
- };
557
- const tryColor = (s) => {
558
- if (!s)
559
- return undefined;
560
- try {
561
- return (0, color_1.default)(s);
562
- }
563
- catch (e) {
564
- return undefined;
565
- }
566
- };
567
193
  const FieldTabs = ({ id, fields, uid: initialUid, pageUid, order, toggleable, extensionId, onEnable, onDisable, }) => {
568
194
  const [uid, setUid] = (0, react_1.useState)(initialUid);
569
195
  const parentUid = (0, react_1.useMemo)(() => {
@@ -596,8 +222,7 @@ const FieldTabs = ({ id, fields, uid: initialUid, pageUid, order, toggleable, ex
596
222
  return (react_1.default.createElement(core_1.Tabs, { vertical: true, id: `${id}-field-tabs`, onChange: onTabsChange, selectedTabId: selectedTabId, renderActiveTabPanelOnly: true },
597
223
  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 })),
598
224
  fields.map((field, i) => {
599
- const { type, title, defaultValue } = field;
600
- const Panel = Panels[type];
225
+ const { Panel, title, defaultValue } = field;
601
226
  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, {
602
227
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
603
228
  // @ts-ignore 4.3.0
@@ -626,7 +251,6 @@ const ConfigPage = ({ id, config, pageUid, }) => {
626
251
  }
627
252
  }
628
253
  }, [config.versioning, id, setCurrentVersion, userTabs, titleRef]);
629
- const brandColor = tryColor(config.brand);
630
254
  return (react_1.default.createElement(core_1.Card, { style: { color: "#202B33" }, className: "roamjs-config-panel" },
631
255
  react_1.default.createElement("style", null, `.roamjs-config-panel .bp3-tab-panel {
632
256
  width: 100%;
@@ -635,26 +259,21 @@ const ConfigPage = ({ id, config, pageUid, }) => {
635
259
  .roamjs-external-login {
636
260
  margin-bottom: 16px;
637
261
  }
638
- ${brandColor &&
262
+ ${config.brand &&
639
263
  `div.bp3-tab[aria-selected="true"], div.bp3-tab:not([aria-disabled="true"]):hover {
640
- color: ${brandColor.toString()};
264
+ color: ${config.brand.base};
641
265
  }
642
266
 
643
267
  .bp3-tab-indicator-wrapper div.bp3-tab-indicator, .bp3-control:hover input:checked ~ span.bp3-control-indicator {
644
- background-color: ${brandColor.toString()};
268
+ background-color: ${config.brand.base};
645
269
  }
646
270
 
647
271
  .bp3-tabs.bp3-vertical>.bp3-tab-list .bp3-tab-indicator-wrapper div.bp3-tab-indicator {
648
- background-color: ${brandColor
649
- .alpha(0.2)
650
- .lightness(brandColor.lightness() + 5)
651
- .toString()};
272
+ background-color: ${config.brand.faded};
652
273
  }
653
274
 
654
275
  .bp3-control input:checked ~ span.bp3-control-indicator {
655
- background-color: ${brandColor
656
- .lightness(brandColor.lightness() + 5)
657
- .toString()}
276
+ background-color: ${config.brand.bright}
658
277
  }`}`),
659
278
  react_1.default.createElement("div", { style: { display: "flex", justifyContent: "space-between" }, ref: titleRef, tabIndex: -1 },
660
279
  react_1.default.createElement("h4", { style: { padding: 4 } },
@@ -678,19 +297,20 @@ ${brandColor &&
678
297
  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 }) }));
679
298
  }))));
680
299
  };
300
+ // TODO: better nested type discrimination here
681
301
  const fieldsToChildren = (t) => t.fields
682
302
  .filter((f) => !!f.defaultValue)
683
303
  .map((f) => {
684
304
  var _a;
685
305
  return ({
686
306
  text: f.title,
687
- children: f.type === "flag"
307
+ children: f.Panel.type === "flag"
688
308
  ? []
689
- : f.type === "custom"
309
+ : f.Panel.type === "custom"
690
310
  ? f.defaultValue || []
691
- : f.type === "pages" || f.type === "multitext"
311
+ : f.Panel.type === "pages" || f.Panel.type === "multitext"
692
312
  ? (_a = f.defaultValue) === null || _a === void 0 ? void 0 : _a.map((v) => ({ text: v }))
693
- : f.type === "block"
313
+ : f.Panel.type === "block"
694
314
  ? f.defaultValue
695
315
  ? [f.defaultValue]
696
316
  : []