react-iframe-bridge 0.8.0 → 1.0.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 (58) hide show
  1. package/README.md +4 -7
  2. package/lib/components/ErrorPage.d.ts +2 -2
  3. package/lib/components/Input.d.ts +10 -0
  4. package/lib/components/Input.js +5 -0
  5. package/lib/components/LoadingFull.d.ts +1 -2
  6. package/lib/components/Spinner.d.ts +1 -2
  7. package/lib/components/home/Home.d.ts +13 -2
  8. package/lib/components/home/Home.js +15 -2
  9. package/lib/components/home/HomeContext.d.ts +6 -5
  10. package/lib/components/home/HomeContext.js +8 -7
  11. package/lib/components/home/HomeHeader.d.ts +1 -2
  12. package/lib/components/home/HomeHeader.js +3 -2
  13. package/lib/components/home/HomeIframe.d.ts +4 -3
  14. package/lib/components/home/HomeIframe.js +4 -4
  15. package/lib/components/home/HomeNoSample.d.ts +1 -2
  16. package/lib/components/home/HomeSamples.d.ts +1 -2
  17. package/lib/components/home/HomeSelector.d.ts +1 -2
  18. package/lib/contexts/iframeBridge.d.ts +6 -5
  19. package/lib/contexts/iframeBridge.js +3 -4
  20. package/lib/contexts/roc.d.ts +2 -2
  21. package/lib/hooks/localStorage.d.ts +1 -1
  22. package/lib/hooks/useRocQuery.d.ts +4 -4
  23. package/lib/types/db.d.ts +2 -2
  24. package/lib/types/util.d.ts +1 -1
  25. package/lib-cjs/components/ErrorPage.d.ts +2 -2
  26. package/lib-cjs/components/ErrorPage.js +1 -1
  27. package/lib-cjs/components/Input.d.ts +10 -0
  28. package/lib-cjs/components/Input.js +11 -0
  29. package/lib-cjs/components/LoadingFull.d.ts +1 -2
  30. package/lib-cjs/components/LoadingFull.js +1 -1
  31. package/lib-cjs/components/Spinner.d.ts +1 -2
  32. package/lib-cjs/components/Spinner.js +1 -1
  33. package/lib-cjs/components/home/Home.d.ts +13 -2
  34. package/lib-cjs/components/home/Home.js +15 -3
  35. package/lib-cjs/components/home/HomeContext.d.ts +6 -5
  36. package/lib-cjs/components/home/HomeContext.js +10 -10
  37. package/lib-cjs/components/home/HomeHeader.d.ts +1 -2
  38. package/lib-cjs/components/home/HomeHeader.js +7 -3
  39. package/lib-cjs/components/home/HomeIframe.d.ts +4 -3
  40. package/lib-cjs/components/home/HomeIframe.js +4 -4
  41. package/lib-cjs/components/home/HomeNoSample.d.ts +1 -2
  42. package/lib-cjs/components/home/HomeNoSample.js +1 -1
  43. package/lib-cjs/components/home/HomeSamples.d.ts +1 -2
  44. package/lib-cjs/components/home/HomeSamples.js +1 -1
  45. package/lib-cjs/components/home/HomeSelector.d.ts +1 -2
  46. package/lib-cjs/components/home/HomeSelector.js +1 -1
  47. package/lib-cjs/contexts/iframeBridge.d.ts +6 -5
  48. package/lib-cjs/contexts/iframeBridge.js +4 -6
  49. package/lib-cjs/contexts/roc.d.ts +2 -2
  50. package/lib-cjs/contexts/roc.js +2 -3
  51. package/lib-cjs/hooks/localStorage.d.ts +1 -1
  52. package/lib-cjs/hooks/localStorage.js +2 -3
  53. package/lib-cjs/hooks/useRocQuery.d.ts +4 -4
  54. package/lib-cjs/hooks/useRocQuery.js +1 -2
  55. package/lib-cjs/types/db.d.ts +2 -2
  56. package/lib-cjs/types/util.d.ts +1 -1
  57. package/lib-cjs/utils/localStorage.js +0 -2
  58. package/package.json +12 -11
package/README.md CHANGED
@@ -10,12 +10,9 @@ Install the package:
10
10
  npm i react-iframe-bridge
11
11
  ```
12
12
 
13
- Add the package's files to TailwindCSS' purge configuration:
13
+ Add the package's files to TailwindCSS configuration:
14
14
 
15
- ```javascript
16
- module.exports = {
17
- purge: {
18
- './node_modules/react-iframe-bridge/lib/**/*.js',
19
- },
20
- };
15
+ ```css
16
+ @import 'tailwindcss';
17
+ @source '../node_modules/react-iframe-bridge/lib';
21
18
  ```
@@ -1,8 +1,8 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
  interface ErrorPageProps {
3
3
  title: string;
4
4
  subtitle: string;
5
5
  children?: ReactNode;
6
6
  }
7
- export default function ErrorPage(props: ErrorPageProps): JSX.Element;
7
+ export default function ErrorPage(props: ErrorPageProps): import("react/jsx-runtime").JSX.Element;
8
8
  export {};
@@ -0,0 +1,10 @@
1
+ import type { ChangeEvent } from 'react';
2
+ interface InputProps {
3
+ name: string;
4
+ className?: string;
5
+ value: string;
6
+ readOnly?: boolean;
7
+ onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
8
+ }
9
+ export default function Input(props: InputProps): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import clsx from 'clsx';
3
+ export default function Input(props) {
4
+ return (_jsx("input", { name: props.name, type: "text", className: clsx('appearance-none border border-neutral-600 bg-white px-3 py-2 text-base leading-none', props.className), value: props.value, readOnly: props.readOnly, onChange: props.onChange }));
5
+ }
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function LoadingFull(): JSX.Element;
1
+ export default function LoadingFull(): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
1
  export interface SpinnerProps {
3
2
  className?: string;
4
3
  }
5
- export default function Spinner(props: SpinnerProps): JSX.Element;
4
+ export default function Spinner(props: SpinnerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export interface HomeProps {
3
2
  /**
4
3
  * URL of the rest-on-couch instance.
@@ -10,6 +9,18 @@ export interface HomeProps {
10
9
  * @default 'eln'
11
10
  */
12
11
  database?: string;
12
+ /**
13
+ * Base url loaded by the iframe
14
+ */
13
15
  baseUrl?: string;
16
+ /**
17
+ * Default path the iframe should load, if no path is found in local storage
18
+ */
19
+ defaultPath?: string;
20
+ /**
21
+ * Opt out of selecting a sample / selecting no sample before loading the iframe.
22
+ * The sample selection UI will be hidden and the iframe will automatically load without a selected sample.
23
+ */
24
+ noSampleSelection?: boolean;
14
25
  }
15
- export declare function Home(props: HomeProps): JSX.Element;
26
+ export declare function Home(props: HomeProps): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,22 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { HomeContextProvider } from './HomeContext';
2
+ import { useEffect } from 'react';
3
+ import { HomeContextProvider, useHomeDispatchContext } from './HomeContext';
3
4
  import HomeHeader from './HomeHeader';
4
5
  import HomeIframe from './HomeIframe';
5
6
  import HomeNoSample from './HomeNoSample';
6
7
  import HomeSamples from './HomeSamples';
7
8
  export function Home(props) {
8
- return (_jsx(HomeContextProvider, { rocUrl: props.rocUrl, database: props.database, children: _jsxs("div", { className: "flex flex-col w-screen h-screen", children: [_jsx(HomeHeader, {}), _jsxs("div", { className: "flex flex-row flex-1 mt-2 border-t border-neutral-300 min-h-0", children: [_jsxs("div", { className: "flex flex-col w-48 px-2 pt-4 space-y-3 border-r border-neutral-300 overflow-auto", children: [_jsx(HomeNoSample, {}), _jsx(HomeSamples, {})] }), _jsx(HomeIframe, { baseUrl: props.baseUrl })] })] }) }));
9
+ const { baseUrl, noSampleSelection, rocUrl, database, defaultPath } = props;
10
+ return (_jsx(HomeContextProvider, { rocUrl: rocUrl, database: database, defaultPath: defaultPath, children: _jsx(HomeInternal, { noSampleSelection: noSampleSelection, baseUrl: baseUrl }) }));
11
+ }
12
+ function HomeInternal(props) {
13
+ const homeDispatch = useHomeDispatchContext();
14
+ useEffect(() => {
15
+ if (props.noSampleSelection) {
16
+ homeDispatch({
17
+ type: 'OPEN_NO_SAMPLE',
18
+ });
19
+ }
20
+ }, [props.noSampleSelection, homeDispatch]);
21
+ return (_jsxs("div", { className: "flex flex-col w-screen h-screen", children: [_jsx(HomeHeader, {}), _jsxs("div", { className: "flex flex-row flex-1 mt-2 border-t border-neutral-300 min-h-0", children: [!props.noSampleSelection && (_jsxs("div", { className: "flex flex-col w-48 px-2 pt-4 space-y-3 border-r border-neutral-300 overflow-auto", children: [_jsx(HomeNoSample, {}), _jsx(HomeSamples, {})] })), _jsx(HomeIframe, { baseUrl: props.baseUrl })] })] }));
9
22
  }
@@ -1,19 +1,20 @@
1
- import { Dispatch, ReactNode } from 'react';
2
- import { ActionType } from '../../types/util';
1
+ import type { Dispatch, ReactNode } from 'react';
2
+ import type { ActionType } from '../../types/util';
3
3
  interface HomeContextType {
4
4
  rocUrl: string;
5
5
  database: string;
6
- iframePage: string;
6
+ iframePath: string;
7
7
  iframeMode: 'closed' | 'sample' | 'no-sample';
8
8
  selectedSample: string | null;
9
9
  }
10
- declare type HomeContextAction = ActionType<'SELECT_SAMPLE', string> | ActionType<'OPEN_NO_SAMPLE'> | ActionType<'SET_IFRAME_PAGE', string>;
10
+ type HomeContextAction = ActionType<'SELECT_SAMPLE', string> | ActionType<'OPEN_NO_SAMPLE'> | ActionType<'SET_IFRAME_PAGE', string>;
11
11
  interface HomeContextProviderProps {
12
12
  children: ReactNode;
13
13
  rocUrl?: string;
14
14
  database?: string;
15
+ defaultPath?: string;
15
16
  }
16
- export declare function HomeContextProvider(props: HomeContextProviderProps): JSX.Element;
17
+ export declare function HomeContextProvider(props: HomeContextProviderProps): import("react/jsx-runtime").JSX.Element;
17
18
  export declare function useHomeContext(): HomeContextType;
18
19
  export declare function useHomeDispatchContext(): Dispatch<HomeContextAction>;
19
20
  export {};
@@ -1,15 +1,15 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { produce } from 'immer';
3
- import { createContext, useContext, useReducer, } from 'react';
3
+ import { createContext, useContext, useReducer } from 'react';
4
4
  import { RocProvider } from '../../contexts/roc';
5
5
  import { useSaveToLocalStorage } from '../../hooks/localStorage';
6
6
  import { getItem } from '../../utils/localStorage';
7
7
  function getInitialHomeContext(config = {}) {
8
- const { rocUrl = 'http://localhost:3000/api/fake-roc', database = 'eln' } = config;
8
+ const { rocUrl = 'http://localhost:3000/api/fake-roc', database = 'eln', defaultPath = '/dev/base-page', } = config;
9
9
  return {
10
10
  rocUrl,
11
11
  database,
12
- iframePage: getItem('dev-home-iframePage') || '/dev/base-page',
12
+ iframePath: getItem('dev-home-iframe-path') || defaultPath,
13
13
  iframeMode: 'closed',
14
14
  selectedSample: null,
15
15
  };
@@ -25,7 +25,7 @@ const homeReducer = produce((state, action) => {
25
25
  state.selectedSample = action.payload;
26
26
  break;
27
27
  case 'SET_IFRAME_PAGE':
28
- state.iframePage = action.payload;
28
+ state.iframePath = action.payload;
29
29
  break;
30
30
  default:
31
31
  throw new Error('unreachable');
@@ -36,9 +36,10 @@ const homeDispatchContext = createContext(() => {
36
36
  // noop
37
37
  });
38
38
  export function HomeContextProvider(props) {
39
- const [homeState, dispatch] = useReducer(homeReducer, props, getInitialHomeContext);
40
- useSaveToLocalStorage('dev-home-iframePage', homeState.iframePage);
41
- return (_jsx(homeContext.Provider, { value: homeState, children: _jsx(homeDispatchContext.Provider, { value: dispatch, children: _jsx(RocProvider, { url: homeState.rocUrl, database: homeState.database, children: props.children }) }) }));
39
+ const { children, ...initial } = props;
40
+ const [homeState, dispatch] = useReducer(homeReducer, initial, getInitialHomeContext);
41
+ useSaveToLocalStorage('dev-home-iframe-path', homeState.iframePath);
42
+ return (_jsx(homeContext.Provider, { value: homeState, children: _jsx(homeDispatchContext.Provider, { value: dispatch, children: _jsx(RocProvider, { url: homeState.rocUrl, database: homeState.database, children: children }) }) }));
42
43
  }
43
44
  export function useHomeContext() {
44
45
  return useContext(homeContext);
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function HomeHeader(): JSX.Element;
1
+ export default function HomeHeader(): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Input from '../Input';
2
3
  import { useHomeContext, useHomeDispatchContext } from './HomeContext';
3
4
  export default function HomeHeader() {
4
- const { rocUrl, database, iframePage } = useHomeContext();
5
+ const { rocUrl, database, iframePath } = useHomeContext();
5
6
  const dispatch = useHomeDispatchContext();
6
- return (_jsxs("header", { className: "flex flex-row p-2 space-x-4", children: [_jsx("input", { name: "rocUrl", type: "text", className: "flex-1 form-input", value: rocUrl, readOnly: true }), _jsx("input", { name: "database", type: "text", className: "form-input", value: database, readOnly: true }), _jsx("input", { name: "iframe-page", value: iframePage, type: "text", className: "flex-1 form-input", onChange: (event) => {
7
+ return (_jsxs("header", { className: "flex flex-row p-2 space-x-4", children: [_jsx(Input, { name: "rocUrl", className: "flex-1", value: rocUrl, readOnly: true }), _jsx(Input, { name: "database", value: database, readOnly: true }), _jsx(Input, { name: "iframe-page", value: iframePath, className: "flex-1", onChange: (event) => {
7
8
  dispatch({ type: 'SET_IFRAME_PAGE', payload: event.target.value });
8
9
  } })] }));
9
10
  }
@@ -1,4 +1,5 @@
1
- /// <reference types="react" />
2
- export default function HomeIframe(props: {
1
+ interface HomeIframeProps {
3
2
  baseUrl?: string;
4
- }): JSX.Element;
3
+ }
4
+ export default function HomeIframe(props: HomeIframeProps): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // https://github.com/import-js/eslint-plugin-import/issues/1810
3
- /* eslint-disable import/no-unresolved */
4
- import { registerHandler, postMessage } from 'iframe-bridge/main';
3
+ import { postMessage, registerHandler } from 'iframe-bridge/main';
5
4
  import { useEffect, useState } from 'react';
6
5
  import { useHomeContext } from './HomeContext';
7
6
  export default function HomeIframe(props) {
8
- const { database, iframePage, rocUrl, selectedSample, iframeMode } = useHomeContext();
7
+ const { baseUrl } = props;
8
+ const { database, iframePath, rocUrl, selectedSample, iframeMode } = useHomeContext();
9
9
  const [windowId, setWindowId] = useState();
10
10
  useEffect(() => {
11
11
  registerHandler('admin', (message) => {
@@ -30,5 +30,5 @@ export default function HomeIframe(props) {
30
30
  uuid: selectedSample,
31
31
  }, windowId);
32
32
  }, [windowId, database, rocUrl, selectedSample]);
33
- return (_jsx("div", { className: "flex items-center justify-center flex-1", children: iframeMode !== 'closed' ? (_jsx("iframe", { allowFullScreen: true, src: `${props.baseUrl || ''}${iframePage}`, className: "w-full h-full" }, selectedSample)) : (_jsx("div", { children: "Please select something" })) }));
33
+ return (_jsx("div", { className: "flex items-center justify-center flex-1", children: iframeMode !== 'closed' ? (_jsx("iframe", { allowFullScreen: true, src: `${baseUrl || ''}${iframePath}`, className: "w-full h-full" }, selectedSample)) : (_jsx("div", { children: "Please select something" })) }));
34
34
  }
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function HomeNoSample(): JSX.Element;
1
+ export default function HomeNoSample(): import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function HomeSamples(): JSX.Element;
1
+ export default function HomeSamples(): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
1
  export default function HomeSelector(props: {
3
2
  selected: boolean;
4
3
  onClick: () => void;
5
4
  text: string;
6
- }): JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
- import { ReactNode } from 'react';
2
- import { Roc, RocDocument } from 'rest-on-couch-client';
3
- import { SampleEntryContent, SampleEntryId } from '../types/db';
1
+ import type { ReactNode } from 'react';
2
+ import type { RocDocument } from 'rest-on-couch-client';
3
+ import { Roc } from 'rest-on-couch-client';
4
+ import type { SampleEntryContent, SampleEntryId } from '../types/db';
4
5
  export declare function useIframeBridgeContext<PublicUserInfo = unknown, PrivateUserInfo = unknown>(): IframeBridgeReadyContextType<PublicUserInfo, PrivateUserInfo>;
5
6
  export declare function useIframeBridgeSample(): RocDocument<SampleEntryContent, SampleEntryId>;
6
7
  interface IframeBridgeReadyContextTypeBase<PublicUserInfo, PrivateUserInfo> {
@@ -16,7 +17,7 @@ interface IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserI
16
17
  hasSample: false;
17
18
  sample: null;
18
19
  }
19
- declare type IframeBridgeReadyContextType<PublicUserInfo = unknown, PrivateUserInfo = unknown> = IframeBridgeReadyContextTypeWithSample<PublicUserInfo, PrivateUserInfo> | IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserInfo>;
20
+ type IframeBridgeReadyContextType<PublicUserInfo = unknown, PrivateUserInfo = unknown> = IframeBridgeReadyContextTypeWithSample<PublicUserInfo, PrivateUserInfo> | IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserInfo>;
20
21
  interface IframeDataMessage {
21
22
  couchDB: {
22
23
  url: string;
@@ -28,5 +29,5 @@ export declare function IframeBridgeProvider(props: {
28
29
  children: ReactNode;
29
30
  requireSample?: boolean;
30
31
  allowStandalone?: boolean;
31
- }): JSX.Element;
32
+ }): import("react/jsx-runtime").JSX.Element;
32
33
  export {};
@@ -1,9 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // https://github.com/import-js/eslint-plugin-import/issues/1810
3
- /* eslint-disable import/no-unresolved */
4
- import { ready, onMessage } from 'iframe-bridge/iframe';
3
+ import { onMessage, ready } from 'iframe-bridge/iframe';
5
4
  import { produce } from 'immer';
6
- import { createContext, useContext, useEffect, useReducer, } from 'react';
5
+ import { createContext, useContext, useEffect, useReducer } from 'react';
7
6
  import { Roc } from 'rest-on-couch-client';
8
7
  import ErrorPage from '../components/ErrorPage';
9
8
  import LoadingFull from '../components/LoadingFull';
@@ -90,7 +89,7 @@ export function IframeBridgeProvider(props) {
90
89
  }
91
90
  }, [props.allowStandalone, state.state]);
92
91
  useEffect(() => {
93
- if (!state.roc || !state.data || !state.data.uuid)
92
+ if (!state.roc || !state.data?.uuid)
94
93
  return;
95
94
  let cancelled = false;
96
95
  const document = state.roc.getDocument(state.data.uuid);
@@ -1,8 +1,8 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
  import { Roc } from 'rest-on-couch-client';
3
3
  export declare function useRoc<PublicUserInfo = unknown, PrivateUserInfo = unknown>(): Roc<PublicUserInfo, PrivateUserInfo>;
4
4
  export declare function RocProvider(props: {
5
5
  children: ReactNode;
6
6
  url: string;
7
7
  database: string;
8
- }): JSX.Element;
8
+ }): import("react/jsx-runtime").JSX.Element;
@@ -10,4 +10,4 @@ export declare function useLocalStorage<ValueType>(key: string, initialValue: Va
10
10
  * @param key localStorage key. Will be appended to the `react-iframe-bridge-` prefix.
11
11
  * @param value Value to save.
12
12
  */
13
- export declare function useSaveToLocalStorage<ValueType>(key: string, value: ValueType): void;
13
+ export declare function useSaveToLocalStorage(key: string, value: unknown): void;
@@ -1,11 +1,11 @@
1
- import { IQueryResult } from 'rest-on-couch-client';
2
- export declare type RocQueryResult<T> = IQueryResult<[string, string], T>;
1
+ import type { IQueryResult } from 'rest-on-couch-client';
2
+ export type RocQueryResult<T> = IQueryResult<[string, string], T>;
3
3
  interface RocQueryState<T = unknown> {
4
4
  loading: boolean;
5
5
  error: null | Error;
6
- result: null | RocQueryResult<T>[];
6
+ result: null | Array<RocQueryResult<T>>;
7
7
  }
8
- declare type RocQueryHookResult<T> = RocQueryState<T>;
8
+ type RocQueryHookResult<T> = RocQueryState<T>;
9
9
  interface RocQueryHookOptions {
10
10
  mine?: boolean;
11
11
  }
package/lib/types/db.d.ts CHANGED
@@ -27,7 +27,7 @@ export interface TocEntry {
27
27
  names: string[];
28
28
  reference: string;
29
29
  }
30
- export declare type SampleEntryId = [string, string];
30
+ export type SampleEntryId = [string, string];
31
31
  export interface SampleEntry {
32
32
  _id: string;
33
33
  _rev: string;
@@ -55,7 +55,7 @@ export interface SampleEntryContent {
55
55
  }>;
56
56
  };
57
57
  spectra: {
58
- nmr: Array<SampleEntrySpectraNmr>;
58
+ nmr: SampleEntrySpectraNmr[];
59
59
  };
60
60
  }
61
61
  export interface SampleEntrySpectraNmr {
@@ -1,4 +1,4 @@
1
- export declare type ActionType<Action, Payload = void> = Payload extends void ? {
1
+ export type ActionType<Action, Payload = void> = Payload extends void ? {
2
2
  type: Action;
3
3
  } : {
4
4
  type: Action;
@@ -1,8 +1,8 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
  interface ErrorPageProps {
3
3
  title: string;
4
4
  subtitle: string;
5
5
  children?: ReactNode;
6
6
  }
7
- export default function ErrorPage(props: ErrorPageProps): JSX.Element;
7
+ export default function ErrorPage(props: ErrorPageProps): import("react/jsx-runtime").JSX.Element;
8
8
  export {};
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = ErrorPage;
3
4
  const jsx_runtime_1 = require("react/jsx-runtime");
4
5
  function ErrorPage(props) {
5
6
  return ((0, jsx_runtime_1.jsx)("div", { className: "max-w-2xl m-auto md:max-w-4xl", children: (0, jsx_runtime_1.jsx)("div", { className: "flex justify-between px-2 pt-4", children: (0, jsx_runtime_1.jsxs)("div", { className: "min-w-0", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-5xl font-bold sm:mt-16 text-primary-900", children: props.title }), (0, jsx_runtime_1.jsx)("h2", { className: "mt-16 text-lg sm:mt-8", children: props.subtitle }), (0, jsx_runtime_1.jsx)("div", { className: "mt-4", children: props.children })] }) }) }));
6
7
  }
7
- exports.default = ErrorPage;
@@ -0,0 +1,10 @@
1
+ import type { ChangeEvent } from 'react';
2
+ interface InputProps {
3
+ name: string;
4
+ className?: string;
5
+ value: string;
6
+ readOnly?: boolean;
7
+ onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
8
+ }
9
+ export default function Input(props: InputProps): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = Input;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const clsx_1 = __importDefault(require("clsx"));
9
+ function Input(props) {
10
+ return ((0, jsx_runtime_1.jsx)("input", { name: props.name, type: "text", className: (0, clsx_1.default)('appearance-none border border-neutral-600 bg-white px-3 py-2 text-base leading-none', props.className), value: props.value, readOnly: props.readOnly, onChange: props.onChange }));
11
+ }
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function LoadingFull(): JSX.Element;
1
+ export default function LoadingFull(): import("react/jsx-runtime").JSX.Element;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = LoadingFull;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
8
  const Spinner_1 = __importDefault(require("./Spinner"));
8
9
  function LoadingFull() {
9
10
  return ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-center w-full h-full", children: (0, jsx_runtime_1.jsx)(Spinner_1.default, { className: "w-10 h-10 text-alternative-500" }) }));
10
11
  }
11
- exports.default = LoadingFull;
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
1
  export interface SpinnerProps {
3
2
  className?: string;
4
3
  }
5
- export default function Spinner(props: SpinnerProps): JSX.Element;
4
+ export default function Spinner(props: SpinnerProps): import("react/jsx-runtime").JSX.Element;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = Spinner;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
8
  const clsx_1 = __importDefault(require("clsx"));
8
9
  function Spinner(props) {
9
10
  return ((0, jsx_runtime_1.jsxs)("svg", { className: (0, clsx_1.default)('animate-spin', props.className), xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), (0, jsx_runtime_1.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }));
10
11
  }
11
- exports.default = Spinner;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export interface HomeProps {
3
2
  /**
4
3
  * URL of the rest-on-couch instance.
@@ -10,6 +9,18 @@ export interface HomeProps {
10
9
  * @default 'eln'
11
10
  */
12
11
  database?: string;
12
+ /**
13
+ * Base url loaded by the iframe
14
+ */
13
15
  baseUrl?: string;
16
+ /**
17
+ * Default path the iframe should load, if no path is found in local storage
18
+ */
19
+ defaultPath?: string;
20
+ /**
21
+ * Opt out of selecting a sample / selecting no sample before loading the iframe.
22
+ * The sample selection UI will be hidden and the iframe will automatically load without a selected sample.
23
+ */
24
+ noSampleSelection?: boolean;
14
25
  }
15
- export declare function Home(props: HomeProps): JSX.Element;
26
+ export declare function Home(props: HomeProps): import("react/jsx-runtime").JSX.Element;
@@ -3,14 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Home = void 0;
6
+ exports.Home = Home;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("react");
8
9
  const HomeContext_1 = require("./HomeContext");
9
10
  const HomeHeader_1 = __importDefault(require("./HomeHeader"));
10
11
  const HomeIframe_1 = __importDefault(require("./HomeIframe"));
11
12
  const HomeNoSample_1 = __importDefault(require("./HomeNoSample"));
12
13
  const HomeSamples_1 = __importDefault(require("./HomeSamples"));
13
14
  function Home(props) {
14
- return ((0, jsx_runtime_1.jsx)(HomeContext_1.HomeContextProvider, { rocUrl: props.rocUrl, database: props.database, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col w-screen h-screen", children: [(0, jsx_runtime_1.jsx)(HomeHeader_1.default, {}), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-row flex-1 mt-2 border-t border-neutral-300 min-h-0", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col w-48 px-2 pt-4 space-y-3 border-r border-neutral-300 overflow-auto", children: [(0, jsx_runtime_1.jsx)(HomeNoSample_1.default, {}), (0, jsx_runtime_1.jsx)(HomeSamples_1.default, {})] }), (0, jsx_runtime_1.jsx)(HomeIframe_1.default, { baseUrl: props.baseUrl })] })] }) }));
15
+ const { baseUrl, noSampleSelection, rocUrl, database, defaultPath } = props;
16
+ return ((0, jsx_runtime_1.jsx)(HomeContext_1.HomeContextProvider, { rocUrl: rocUrl, database: database, defaultPath: defaultPath, children: (0, jsx_runtime_1.jsx)(HomeInternal, { noSampleSelection: noSampleSelection, baseUrl: baseUrl }) }));
17
+ }
18
+ function HomeInternal(props) {
19
+ const homeDispatch = (0, HomeContext_1.useHomeDispatchContext)();
20
+ (0, react_1.useEffect)(() => {
21
+ if (props.noSampleSelection) {
22
+ homeDispatch({
23
+ type: 'OPEN_NO_SAMPLE',
24
+ });
25
+ }
26
+ }, [props.noSampleSelection, homeDispatch]);
27
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col w-screen h-screen", children: [(0, jsx_runtime_1.jsx)(HomeHeader_1.default, {}), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-row flex-1 mt-2 border-t border-neutral-300 min-h-0", children: [!props.noSampleSelection && ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col w-48 px-2 pt-4 space-y-3 border-r border-neutral-300 overflow-auto", children: [(0, jsx_runtime_1.jsx)(HomeNoSample_1.default, {}), (0, jsx_runtime_1.jsx)(HomeSamples_1.default, {})] })), (0, jsx_runtime_1.jsx)(HomeIframe_1.default, { baseUrl: props.baseUrl })] })] }));
15
28
  }
16
- exports.Home = Home;
@@ -1,19 +1,20 @@
1
- import { Dispatch, ReactNode } from 'react';
2
- import { ActionType } from '../../types/util';
1
+ import type { Dispatch, ReactNode } from 'react';
2
+ import type { ActionType } from '../../types/util';
3
3
  interface HomeContextType {
4
4
  rocUrl: string;
5
5
  database: string;
6
- iframePage: string;
6
+ iframePath: string;
7
7
  iframeMode: 'closed' | 'sample' | 'no-sample';
8
8
  selectedSample: string | null;
9
9
  }
10
- declare type HomeContextAction = ActionType<'SELECT_SAMPLE', string> | ActionType<'OPEN_NO_SAMPLE'> | ActionType<'SET_IFRAME_PAGE', string>;
10
+ type HomeContextAction = ActionType<'SELECT_SAMPLE', string> | ActionType<'OPEN_NO_SAMPLE'> | ActionType<'SET_IFRAME_PAGE', string>;
11
11
  interface HomeContextProviderProps {
12
12
  children: ReactNode;
13
13
  rocUrl?: string;
14
14
  database?: string;
15
+ defaultPath?: string;
15
16
  }
16
- export declare function HomeContextProvider(props: HomeContextProviderProps): JSX.Element;
17
+ export declare function HomeContextProvider(props: HomeContextProviderProps): import("react/jsx-runtime").JSX.Element;
17
18
  export declare function useHomeContext(): HomeContextType;
18
19
  export declare function useHomeDispatchContext(): Dispatch<HomeContextAction>;
19
20
  export {};
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useHomeDispatchContext = exports.useHomeContext = exports.HomeContextProvider = void 0;
3
+ exports.HomeContextProvider = HomeContextProvider;
4
+ exports.useHomeContext = useHomeContext;
5
+ exports.useHomeDispatchContext = useHomeDispatchContext;
4
6
  const jsx_runtime_1 = require("react/jsx-runtime");
5
7
  const immer_1 = require("immer");
6
8
  const react_1 = require("react");
@@ -8,11 +10,11 @@ const roc_1 = require("../../contexts/roc");
8
10
  const localStorage_1 = require("../../hooks/localStorage");
9
11
  const localStorage_2 = require("../../utils/localStorage");
10
12
  function getInitialHomeContext(config = {}) {
11
- const { rocUrl = 'http://localhost:3000/api/fake-roc', database = 'eln' } = config;
13
+ const { rocUrl = 'http://localhost:3000/api/fake-roc', database = 'eln', defaultPath = '/dev/base-page', } = config;
12
14
  return {
13
15
  rocUrl,
14
16
  database,
15
- iframePage: (0, localStorage_2.getItem)('dev-home-iframePage') || '/dev/base-page',
17
+ iframePath: (0, localStorage_2.getItem)('dev-home-iframe-path') || defaultPath,
16
18
  iframeMode: 'closed',
17
19
  selectedSample: null,
18
20
  };
@@ -28,7 +30,7 @@ const homeReducer = (0, immer_1.produce)((state, action) => {
28
30
  state.selectedSample = action.payload;
29
31
  break;
30
32
  case 'SET_IFRAME_PAGE':
31
- state.iframePage = action.payload;
33
+ state.iframePath = action.payload;
32
34
  break;
33
35
  default:
34
36
  throw new Error('unreachable');
@@ -39,16 +41,14 @@ const homeDispatchContext = (0, react_1.createContext)(() => {
39
41
  // noop
40
42
  });
41
43
  function HomeContextProvider(props) {
42
- const [homeState, dispatch] = (0, react_1.useReducer)(homeReducer, props, getInitialHomeContext);
43
- (0, localStorage_1.useSaveToLocalStorage)('dev-home-iframePage', homeState.iframePage);
44
- return ((0, jsx_runtime_1.jsx)(homeContext.Provider, { value: homeState, children: (0, jsx_runtime_1.jsx)(homeDispatchContext.Provider, { value: dispatch, children: (0, jsx_runtime_1.jsx)(roc_1.RocProvider, { url: homeState.rocUrl, database: homeState.database, children: props.children }) }) }));
44
+ const { children, ...initial } = props;
45
+ const [homeState, dispatch] = (0, react_1.useReducer)(homeReducer, initial, getInitialHomeContext);
46
+ (0, localStorage_1.useSaveToLocalStorage)('dev-home-iframe-path', homeState.iframePath);
47
+ return ((0, jsx_runtime_1.jsx)(homeContext.Provider, { value: homeState, children: (0, jsx_runtime_1.jsx)(homeDispatchContext.Provider, { value: dispatch, children: (0, jsx_runtime_1.jsx)(roc_1.RocProvider, { url: homeState.rocUrl, database: homeState.database, children: children }) }) }));
45
48
  }
46
- exports.HomeContextProvider = HomeContextProvider;
47
49
  function useHomeContext() {
48
50
  return (0, react_1.useContext)(homeContext);
49
51
  }
50
- exports.useHomeContext = useHomeContext;
51
52
  function useHomeDispatchContext() {
52
53
  return (0, react_1.useContext)(homeDispatchContext);
53
54
  }
54
- exports.useHomeDispatchContext = useHomeDispatchContext;
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function HomeHeader(): JSX.Element;
1
+ export default function HomeHeader(): import("react/jsx-runtime").JSX.Element;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = HomeHeader;
3
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const Input_1 = __importDefault(require("../Input"));
4
9
  const HomeContext_1 = require("./HomeContext");
5
10
  function HomeHeader() {
6
- const { rocUrl, database, iframePage } = (0, HomeContext_1.useHomeContext)();
11
+ const { rocUrl, database, iframePath } = (0, HomeContext_1.useHomeContext)();
7
12
  const dispatch = (0, HomeContext_1.useHomeDispatchContext)();
8
- return ((0, jsx_runtime_1.jsxs)("header", { className: "flex flex-row p-2 space-x-4", children: [(0, jsx_runtime_1.jsx)("input", { name: "rocUrl", type: "text", className: "flex-1 form-input", value: rocUrl, readOnly: true }), (0, jsx_runtime_1.jsx)("input", { name: "database", type: "text", className: "form-input", value: database, readOnly: true }), (0, jsx_runtime_1.jsx)("input", { name: "iframe-page", value: iframePage, type: "text", className: "flex-1 form-input", onChange: (event) => {
13
+ return ((0, jsx_runtime_1.jsxs)("header", { className: "flex flex-row p-2 space-x-4", children: [(0, jsx_runtime_1.jsx)(Input_1.default, { name: "rocUrl", className: "flex-1", value: rocUrl, readOnly: true }), (0, jsx_runtime_1.jsx)(Input_1.default, { name: "database", value: database, readOnly: true }), (0, jsx_runtime_1.jsx)(Input_1.default, { name: "iframe-page", value: iframePath, className: "flex-1", onChange: (event) => {
9
14
  dispatch({ type: 'SET_IFRAME_PAGE', payload: event.target.value });
10
15
  } })] }));
11
16
  }
12
- exports.default = HomeHeader;
@@ -1,4 +1,5 @@
1
- /// <reference types="react" />
2
- export default function HomeIframe(props: {
1
+ interface HomeIframeProps {
3
2
  baseUrl?: string;
4
- }): JSX.Element;
3
+ }
4
+ export default function HomeIframe(props: HomeIframeProps): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = HomeIframe;
3
4
  const jsx_runtime_1 = require("react/jsx-runtime");
4
5
  // https://github.com/import-js/eslint-plugin-import/issues/1810
5
- /* eslint-disable import/no-unresolved */
6
6
  const main_1 = require("iframe-bridge/main");
7
7
  const react_1 = require("react");
8
8
  const HomeContext_1 = require("./HomeContext");
9
9
  function HomeIframe(props) {
10
- const { database, iframePage, rocUrl, selectedSample, iframeMode } = (0, HomeContext_1.useHomeContext)();
10
+ const { baseUrl } = props;
11
+ const { database, iframePath, rocUrl, selectedSample, iframeMode } = (0, HomeContext_1.useHomeContext)();
11
12
  const [windowId, setWindowId] = (0, react_1.useState)();
12
13
  (0, react_1.useEffect)(() => {
13
14
  (0, main_1.registerHandler)('admin', (message) => {
@@ -32,6 +33,5 @@ function HomeIframe(props) {
32
33
  uuid: selectedSample,
33
34
  }, windowId);
34
35
  }, [windowId, database, rocUrl, selectedSample]);
35
- return ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-center flex-1", children: iframeMode !== 'closed' ? ((0, jsx_runtime_1.jsx)("iframe", { allowFullScreen: true, src: `${props.baseUrl || ''}${iframePage}`, className: "w-full h-full" }, selectedSample)) : ((0, jsx_runtime_1.jsx)("div", { children: "Please select something" })) }));
36
+ return ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-center flex-1", children: iframeMode !== 'closed' ? ((0, jsx_runtime_1.jsx)("iframe", { allowFullScreen: true, src: `${baseUrl || ''}${iframePath}`, className: "w-full h-full" }, selectedSample)) : ((0, jsx_runtime_1.jsx)("div", { children: "Please select something" })) }));
36
37
  }
37
- exports.default = HomeIframe;
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function HomeNoSample(): JSX.Element;
1
+ export default function HomeNoSample(): import("react/jsx-runtime").JSX.Element;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = HomeNoSample;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
8
  const HomeContext_1 = require("./HomeContext");
8
9
  const HomeSelector_1 = __importDefault(require("./HomeSelector"));
@@ -11,4 +12,3 @@ function HomeNoSample() {
11
12
  const dispatch = (0, HomeContext_1.useHomeDispatchContext)();
12
13
  return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(HomeSelector_1.default, { onClick: () => dispatch({ type: 'OPEN_NO_SAMPLE' }), selected: iframeMode === 'no-sample', text: "No sample" }) }));
13
14
  }
14
- exports.default = HomeNoSample;
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export default function HomeSamples(): JSX.Element;
1
+ export default function HomeSamples(): import("react/jsx-runtime").JSX.Element;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = HomeSamples;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
8
  const useRocQuery_1 = require("../../hooks/useRocQuery");
8
9
  const Spinner_1 = __importDefault(require("../Spinner"));
@@ -15,7 +16,6 @@ function HomeSamples() {
15
16
  }
16
17
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h1", { className: "mb-4 text-lg font-bold text-center", children: "Sample TOC" }), (0, jsx_runtime_1.jsx)("div", { className: "flex-1", children: loading || !result ? (0, jsx_runtime_1.jsx)(Loading, {}) : (0, jsx_runtime_1.jsx)(SampleToc, { samples: result }) })] }));
17
18
  }
18
- exports.default = HomeSamples;
19
19
  function SampleToc(props) {
20
20
  const { selectedSample } = (0, HomeContext_1.useHomeContext)();
21
21
  const dispatch = (0, HomeContext_1.useHomeDispatchContext)();
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
1
  export default function HomeSelector(props: {
3
2
  selected: boolean;
4
3
  onClick: () => void;
5
4
  text: string;
6
- }): JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = HomeSelector;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
8
  const clsx_1 = __importDefault(require("clsx"));
8
9
  function HomeSelector(props) {
9
10
  return ((0, jsx_runtime_1.jsx)("div", { className: (0, clsx_1.default)('p-1 border rounded cursor-pointer border-neutral-400', props.selected && 'bg-primary-50 shadow-inner'), onClick: props.onClick, children: props.text }));
10
11
  }
11
- exports.default = HomeSelector;
@@ -1,6 +1,7 @@
1
- import { ReactNode } from 'react';
2
- import { Roc, RocDocument } from 'rest-on-couch-client';
3
- import { SampleEntryContent, SampleEntryId } from '../types/db';
1
+ import type { ReactNode } from 'react';
2
+ import type { RocDocument } from 'rest-on-couch-client';
3
+ import { Roc } from 'rest-on-couch-client';
4
+ import type { SampleEntryContent, SampleEntryId } from '../types/db';
4
5
  export declare function useIframeBridgeContext<PublicUserInfo = unknown, PrivateUserInfo = unknown>(): IframeBridgeReadyContextType<PublicUserInfo, PrivateUserInfo>;
5
6
  export declare function useIframeBridgeSample(): RocDocument<SampleEntryContent, SampleEntryId>;
6
7
  interface IframeBridgeReadyContextTypeBase<PublicUserInfo, PrivateUserInfo> {
@@ -16,7 +17,7 @@ interface IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserI
16
17
  hasSample: false;
17
18
  sample: null;
18
19
  }
19
- declare type IframeBridgeReadyContextType<PublicUserInfo = unknown, PrivateUserInfo = unknown> = IframeBridgeReadyContextTypeWithSample<PublicUserInfo, PrivateUserInfo> | IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserInfo>;
20
+ type IframeBridgeReadyContextType<PublicUserInfo = unknown, PrivateUserInfo = unknown> = IframeBridgeReadyContextTypeWithSample<PublicUserInfo, PrivateUserInfo> | IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserInfo>;
20
21
  interface IframeDataMessage {
21
22
  couchDB: {
22
23
  url: string;
@@ -28,5 +29,5 @@ export declare function IframeBridgeProvider(props: {
28
29
  children: ReactNode;
29
30
  requireSample?: boolean;
30
31
  allowStandalone?: boolean;
31
- }): JSX.Element;
32
+ }): import("react/jsx-runtime").JSX.Element;
32
33
  export {};
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.IframeBridgeProvider = exports.useIframeBridgeSample = exports.useIframeBridgeContext = void 0;
6
+ exports.useIframeBridgeContext = useIframeBridgeContext;
7
+ exports.useIframeBridgeSample = useIframeBridgeSample;
8
+ exports.IframeBridgeProvider = IframeBridgeProvider;
7
9
  const jsx_runtime_1 = require("react/jsx-runtime");
8
10
  // https://github.com/import-js/eslint-plugin-import/issues/1810
9
- /* eslint-disable import/no-unresolved */
10
11
  const iframe_1 = require("iframe-bridge/iframe");
11
12
  const immer_1 = require("immer");
12
13
  const react_1 = require("react");
@@ -23,7 +24,6 @@ function useIframeBridgeContext() {
23
24
  }
24
25
  return context;
25
26
  }
26
- exports.useIframeBridgeContext = useIframeBridgeContext;
27
27
  function useIframeBridgeSample() {
28
28
  const context = useIframeBridgeContext();
29
29
  if (!context.sample) {
@@ -31,7 +31,6 @@ function useIframeBridgeSample() {
31
31
  }
32
32
  return context.sample;
33
33
  }
34
- exports.useIframeBridgeSample = useIframeBridgeSample;
35
34
  const iframeBridgeReducer = (0, immer_1.produce)((state, action) => {
36
35
  switch (action.type) {
37
36
  case 'RECEIVE_DATA': {
@@ -98,7 +97,7 @@ function IframeBridgeProvider(props) {
98
97
  }
99
98
  }, [props.allowStandalone, state.state]);
100
99
  (0, react_1.useEffect)(() => {
101
- if (!state.roc || !state.data || !state.data.uuid)
100
+ if (!state.roc || !state.data?.uuid)
102
101
  return;
103
102
  let cancelled = false;
104
103
  const document = state.roc.getDocument(state.data.uuid);
@@ -129,4 +128,3 @@ function IframeBridgeProvider(props) {
129
128
  }
130
129
  return ((0, jsx_runtime_1.jsx)(iframeBridgeContext.Provider, { value: state, children: props.children }));
131
130
  }
132
- exports.IframeBridgeProvider = IframeBridgeProvider;
@@ -1,8 +1,8 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
  import { Roc } from 'rest-on-couch-client';
3
3
  export declare function useRoc<PublicUserInfo = unknown, PrivateUserInfo = unknown>(): Roc<PublicUserInfo, PrivateUserInfo>;
4
4
  export declare function RocProvider(props: {
5
5
  children: ReactNode;
6
6
  url: string;
7
7
  database: string;
8
- }): JSX.Element;
8
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RocProvider = exports.useRoc = void 0;
3
+ exports.useRoc = useRoc;
4
+ exports.RocProvider = RocProvider;
4
5
  const jsx_runtime_1 = require("react/jsx-runtime");
5
6
  const react_1 = require("react");
6
7
  const rest_on_couch_client_1 = require("rest-on-couch-client");
@@ -12,10 +13,8 @@ function useRoc() {
12
13
  }
13
14
  return roc;
14
15
  }
15
- exports.useRoc = useRoc;
16
16
  function RocProvider(props) {
17
17
  const { url, database, children } = props;
18
18
  const roc = (0, react_1.useMemo)(() => new rest_on_couch_client_1.Roc({ url, database }), [url, database]);
19
19
  return (0, jsx_runtime_1.jsx)(rocContext.Provider, { value: roc, children: children });
20
20
  }
21
- exports.RocProvider = RocProvider;
@@ -10,4 +10,4 @@ export declare function useLocalStorage<ValueType>(key: string, initialValue: Va
10
10
  * @param key localStorage key. Will be appended to the `react-iframe-bridge-` prefix.
11
11
  * @param value Value to save.
12
12
  */
13
- export declare function useSaveToLocalStorage<ValueType>(key: string, value: ValueType): void;
13
+ export declare function useSaveToLocalStorage(key: string, value: unknown): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSaveToLocalStorage = exports.useLocalStorage = void 0;
3
+ exports.useLocalStorage = useLocalStorage;
4
+ exports.useSaveToLocalStorage = useSaveToLocalStorage;
4
5
  const react_1 = require("react");
5
6
  const localStorage_1 = require("../utils/localStorage");
6
7
  /**
@@ -25,7 +26,6 @@ function useLocalStorage(key, initialValue) {
25
26
  }, [key]);
26
27
  return [storedValue, setValue];
27
28
  }
28
- exports.useLocalStorage = useLocalStorage;
29
29
  /**
30
30
  * Save the provided value to `localStorage` everytime it changes.
31
31
  * @param key localStorage key. Will be appended to the `react-iframe-bridge-` prefix.
@@ -36,4 +36,3 @@ function useSaveToLocalStorage(key, value) {
36
36
  (0, localStorage_1.setItem)(key, value);
37
37
  }, [key, value]);
38
38
  }
39
- exports.useSaveToLocalStorage = useSaveToLocalStorage;
@@ -1,11 +1,11 @@
1
- import { IQueryResult } from 'rest-on-couch-client';
2
- export declare type RocQueryResult<T> = IQueryResult<[string, string], T>;
1
+ import type { IQueryResult } from 'rest-on-couch-client';
2
+ export type RocQueryResult<T> = IQueryResult<[string, string], T>;
3
3
  interface RocQueryState<T = unknown> {
4
4
  loading: boolean;
5
5
  error: null | Error;
6
- result: null | RocQueryResult<T>[];
6
+ result: null | Array<RocQueryResult<T>>;
7
7
  }
8
- declare type RocQueryHookResult<T> = RocQueryState<T>;
8
+ type RocQueryHookResult<T> = RocQueryState<T>;
9
9
  interface RocQueryHookOptions {
10
10
  mine?: boolean;
11
11
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRocQuery = void 0;
3
+ exports.useRocQuery = useRocQuery;
4
4
  const react_1 = require("react");
5
5
  const roc_1 = require("../contexts/roc");
6
6
  function rocQueryReducer(state, action) {
@@ -43,4 +43,3 @@ function useRocQuery(viewName, options = {}) {
43
43
  }, [roc, viewName, mine]);
44
44
  return state;
45
45
  }
46
- exports.useRocQuery = useRocQuery;
@@ -27,7 +27,7 @@ export interface TocEntry {
27
27
  names: string[];
28
28
  reference: string;
29
29
  }
30
- export declare type SampleEntryId = [string, string];
30
+ export type SampleEntryId = [string, string];
31
31
  export interface SampleEntry {
32
32
  _id: string;
33
33
  _rev: string;
@@ -55,7 +55,7 @@ export interface SampleEntryContent {
55
55
  }>;
56
56
  };
57
57
  spectra: {
58
- nmr: Array<SampleEntrySpectraNmr>;
58
+ nmr: SampleEntrySpectraNmr[];
59
59
  };
60
60
  }
61
61
  export interface SampleEntrySpectraNmr {
@@ -1,4 +1,4 @@
1
- export declare type ActionType<Action, Payload = void> = Payload extends void ? {
1
+ export type ActionType<Action, Payload = void> = Payload extends void ? {
2
2
  type: Action;
3
3
  } : {
4
4
  type: Action;
@@ -14,9 +14,7 @@ function prefixKey(key) {
14
14
  return `react-iframe-bridge-${key}`;
15
15
  }
16
16
  let getItem;
17
- exports.getItem = getItem;
18
17
  let setItem;
19
- exports.setItem = setItem;
20
18
  if (typeof localStorage !== 'undefined') {
21
19
  exports.getItem = getItem = function getItem(key) {
22
20
  const value = localStorage.getItem(prefixKey(key));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-iframe-bridge",
3
- "version": "0.8.0",
3
+ "version": "1.0.0",
4
4
  "description": "React hooks and components to work with iframe-bridge.",
5
5
  "main": "lib-cjs/index.js",
6
6
  "module": "lib/index.js",
@@ -28,18 +28,19 @@
28
28
  },
29
29
  "homepage": "https://github.com/zakodium-oss/react-iframe-bridge#readme",
30
30
  "dependencies": {
31
- "clsx": "^1.1.1",
31
+ "clsx": "^2.1.1",
32
32
  "iframe-bridge": "^2.0.0",
33
- "immer": "^9.0.5",
34
- "rest-on-couch-client": "^5.1.0"
33
+ "immer": "^10.1.1",
34
+ "rest-on-couch-client": "^5.3.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/react": "^17.0.16",
38
- "@types/react-dom": "^17.0.9",
39
- "@zakodium/eslint-config": "^5.1.1",
40
- "eslint": "^8.14.0",
41
- "prettier": "^2.3.2",
42
- "react": "^17.0.2",
43
- "react-dom": "^17.0.2"
37
+ "@types/react": "^18.3.1",
38
+ "@types/react-dom": "^18.3.0",
39
+ "eslint": "^9.27.0",
40
+ "eslint-config-zakodium": "^15.0.1",
41
+ "prettier": "^3.5.3",
42
+ "react": "^18.3.1",
43
+ "react-dom": "^18.3.1",
44
+ "typescript": "^5.8.3"
44
45
  }
45
46
  }