roamjs-components 0.73.5 → 0.73.8

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.
@@ -28,7 +28,7 @@ declare type Props<T> = {
28
28
  }>;
29
29
  };
30
30
  declare const FormDialog: <T extends Record<string, unknown>>({ title, content, isOpen, onClose, onSubmit, fields, }: RoamOverlayProps<Props<T>>) => JSX.Element;
31
- export declare const render: (props: Props<Record<string, unknown>>) => () => void;
31
+ export declare const render: (props: Props<Record<string, unknown>>) => void | (() => void);
32
32
  export declare const prompt: ({ defaultAnswer, question, title, }: {
33
33
  title: string;
34
34
  question: string;
@@ -7,5 +7,5 @@ export declare const ID = "roamjs-progress-dialog-root";
7
7
  declare const ProgressDialog: ({ onClose, ...props }: {
8
8
  onClose: () => void;
9
9
  } & Props) => JSX.Element;
10
- export declare const render: (props: Props) => () => void;
10
+ export declare const render: (props: Props) => void | (() => void);
11
11
  export default ProgressDialog;
@@ -11,5 +11,5 @@ declare type Props = {
11
11
  declare const SimpleAlert: (Markdown: typeof Marked) => ({ onClose, content, onConfirm, onCancel, externalLink, confirmText, dontShowAgain, }: Props & {
12
12
  onClose: () => void;
13
13
  }) => React.ReactElement;
14
- export declare const render: (props: Props) => Promise<() => void>;
14
+ export declare const render: (props: Props) => Promise<void | (() => void)>;
15
15
  export default SimpleAlert;
@@ -5,7 +5,7 @@ declare type Props = {
5
5
  declare const TokenDialog: ({ onClose, onEnter }: {
6
6
  onClose: () => void;
7
7
  } & Props) => JSX.Element;
8
- export declare const render: (props: Props) => () => void;
8
+ export declare const render: (props: Props) => void | (() => void);
9
9
  export declare const addTokenDialogCommand: (props?: Props) => void;
10
10
  export declare const checkRoamJSTokenWarning: () => Promise<string>;
11
11
  export default TokenDialog;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "roamjs-components",
3
3
  "description": "Description for roamjs-components",
4
- "version": "0.73.5",
4
+ "version": "0.73.8",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { RoamOverlayProps } from "./renderOverlay";
3
- declare const createOverlayRender: <T extends Record<string, unknown>>(id: string, Overlay: (props: RoamOverlayProps<T>) => React.ReactElement) => (props: T) => () => void;
3
+ declare const createOverlayRender: <T extends Record<string, unknown>>(id: string, Overlay: (props: RoamOverlayProps<T>) => React.ReactElement) => (props: T) => void | (() => void);
4
4
  export default createOverlayRender;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // @DEPRECATED
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  const getRenderRoot = (id) => {
4
5
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"getRenderRoot.js","sourceRoot":"","sources":["../src/util/getRenderRoot.ts"],"names":[],"mappings":";;AAAA,MAAM,aAAa,GAAG,CAAC,EAAU,EAAkB,EAAE;;IACnD,MAAM,MAAM,GAAG,UAAU,EAAE,OAAO,CAAC;IACnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAmB,CAAC;IACnE,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;KACjB;IACD,MAAM,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC;IACpB,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,aAAa,0CAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"getRenderRoot.js","sourceRoot":"","sources":["../src/util/getRenderRoot.ts"],"names":[],"mappings":";AAAA,cAAc;;AAEd,MAAM,aAAa,GAAG,CAAC,EAAU,EAAkB,EAAE;;IACnD,MAAM,MAAM,GAAG,UAAU,EAAE,OAAO,CAAC;IACnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAmB,CAAC;IACnE,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;KACjB;IACD,MAAM,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC;IACpB,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,aAAa,0CAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
@@ -3,9 +3,11 @@ export declare type RoamOverlayProps<T extends Record<string, unknown> = Record<
3
3
  onClose: () => void;
4
4
  isOpen: boolean;
5
5
  } & T;
6
- declare const renderOverlay: <T extends Record<string, unknown>>({ id, Overlay, props, }?: {
6
+ declare const renderOverlay: <T extends Record<string, unknown>>({ id, Overlay, props, path, before, }?: {
7
7
  id?: string | undefined;
8
8
  Overlay?: ((props: RoamOverlayProps<T>) => React.ReactElement) | undefined;
9
9
  props?: T | undefined;
10
- }) => () => void;
10
+ path?: string | HTMLElement | null | undefined;
11
+ before?: number | HTMLElement | null | undefined;
12
+ }) => (() => void) | void;
11
13
  export default renderOverlay;
@@ -5,26 +5,36 @@ const nanoid_1 = tslib_1.__importDefault(require("nanoid"));
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const react_dom_1 = tslib_1.__importDefault(require("react-dom"));
7
7
  const dispatchToRegistry_1 = tslib_1.__importDefault(require("./dispatchToRegistry"));
8
- const getRenderRoot_1 = tslib_1.__importDefault(require("./getRenderRoot"));
9
8
  const removeFromRegistry_1 = tslib_1.__importDefault(require("./removeFromRegistry"));
10
- const renderOverlay = ({ id = (0, nanoid_1.default)(), Overlay = (props) => react_1.default.createElement("div", props), props = {}, } = {}) => {
11
- const parent = (0, getRenderRoot_1.default)(id);
12
- const onClose = () => {
13
- if (typeof props.onClose === "function")
14
- props.onClose();
15
- react_dom_1.default.unmountComponentAtNode(parent);
16
- parent.remove();
17
- (0, removeFromRegistry_1.default)({
18
- reactRoots: [parent],
19
- });
20
- };
21
- if (!parent.hasAttribute("data-existing")) {
9
+ const renderOverlay = ({ id = (0, nanoid_1.default)(), Overlay = (props) => react_1.default.createElement("div", props), props = {}, path = "body", before, } = {}) => {
10
+ const parent = document.createElement("div");
11
+ parent.id = id;
12
+ const pathElement = typeof path === "string" ? document.querySelector(path) : path;
13
+ if (pathElement && !pathElement.querySelector(`#${id}`)) {
14
+ if (typeof before === "number") {
15
+ pathElement.insertBefore(parent, pathElement.children[before]);
16
+ }
17
+ else if (typeof before === "object") {
18
+ pathElement.insertBefore(parent, before);
19
+ }
20
+ else {
21
+ pathElement.appendChild(parent);
22
+ }
23
+ const onClose = () => {
24
+ if (typeof props.onClose === "function")
25
+ props.onClose();
26
+ react_dom_1.default.unmountComponentAtNode(parent);
27
+ parent.remove();
28
+ (0, removeFromRegistry_1.default)({
29
+ reactRoots: [parent],
30
+ });
31
+ };
22
32
  react_dom_1.default.render(react_1.default.createElement(Overlay, Object.assign(Object.assign({}, props), { isOpen: true, onClose })), parent);
23
33
  (0, dispatchToRegistry_1.default)({
24
34
  reactRoots: [parent],
25
35
  });
36
+ return onClose;
26
37
  }
27
- return onClose;
28
38
  };
29
39
  exports.default = renderOverlay;
30
40
  //# sourceMappingURL=renderOverlay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderOverlay.js","sourceRoot":"","sources":["../src/util/renderOverlay.ts"],"names":[],"mappings":";;;AAAA,4DAA4B;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