react-iframe-bridge 0.7.1 → 0.9.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.
- package/lib/components/ErrorPage.d.ts +1 -1
- package/lib/components/LoadingFull.d.ts +1 -2
- package/lib/components/Spinner.d.ts +1 -2
- package/lib/components/home/Home.d.ts +14 -2
- package/lib/components/home/Home.js +15 -2
- package/lib/components/home/HomeContext.d.ts +4 -3
- package/lib/components/home/HomeContext.js +7 -6
- package/lib/components/home/HomeHeader.d.ts +1 -2
- package/lib/components/home/HomeHeader.js +2 -2
- package/lib/components/home/HomeIframe.d.ts +5 -2
- package/lib/components/home/HomeIframe.js +5 -5
- package/lib/components/home/HomeNoSample.d.ts +1 -2
- package/lib/components/home/HomeSamples.d.ts +1 -2
- package/lib/components/home/HomeSelector.d.ts +1 -2
- package/lib/contexts/iframeBridge.d.ts +2 -2
- package/lib/contexts/iframeBridge.js +2 -3
- package/lib/contexts/roc.d.ts +1 -1
- package/lib/hooks/useRocQuery.d.ts +3 -3
- package/lib/types/db.d.ts +2 -2
- package/lib/types/util.d.ts +1 -1
- package/lib-cjs/components/ErrorPage.d.ts +1 -1
- package/lib-cjs/components/LoadingFull.d.ts +1 -2
- package/lib-cjs/components/Spinner.d.ts +1 -2
- package/lib-cjs/components/home/Home.d.ts +14 -2
- package/lib-cjs/components/home/Home.js +14 -1
- package/lib-cjs/components/home/HomeContext.d.ts +4 -3
- package/lib-cjs/components/home/HomeContext.js +7 -6
- package/lib-cjs/components/home/HomeHeader.d.ts +1 -2
- package/lib-cjs/components/home/HomeHeader.js +2 -2
- package/lib-cjs/components/home/HomeIframe.d.ts +5 -2
- package/lib-cjs/components/home/HomeIframe.js +4 -4
- package/lib-cjs/components/home/HomeNoSample.d.ts +1 -2
- package/lib-cjs/components/home/HomeSamples.d.ts +1 -2
- package/lib-cjs/components/home/HomeSelector.d.ts +1 -2
- package/lib-cjs/contexts/iframeBridge.d.ts +2 -2
- package/lib-cjs/contexts/iframeBridge.js +1 -2
- package/lib-cjs/contexts/roc.d.ts +1 -1
- package/lib-cjs/hooks/useRocQuery.d.ts +3 -3
- package/lib-cjs/types/db.d.ts +2 -2
- package/lib-cjs/types/util.d.ts +1 -1
- package/lib-cjs/utils/localStorage.js +0 -2
- package/package.json +12 -11
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function LoadingFull(): JSX.Element;
|
|
1
|
+
export default function LoadingFull(): 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,5 +9,18 @@ export interface HomeProps {
|
|
|
10
9
|
* @default 'eln'
|
|
11
10
|
*/
|
|
12
11
|
database?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Base url loaded by the iframe
|
|
14
|
+
*/
|
|
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;
|
|
13
25
|
}
|
|
14
|
-
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 {
|
|
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
|
-
|
|
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
|
}
|
|
@@ -3,17 +3,18 @@ import { ActionType } from '../../types/util';
|
|
|
3
3
|
interface HomeContextType {
|
|
4
4
|
rocUrl: string;
|
|
5
5
|
database: string;
|
|
6
|
-
|
|
6
|
+
iframePath: string;
|
|
7
7
|
iframeMode: 'closed' | 'sample' | 'no-sample';
|
|
8
8
|
selectedSample: string | null;
|
|
9
9
|
}
|
|
10
|
-
|
|
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 {};
|
|
@@ -5,11 +5,11 @@ 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
|
-
|
|
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.
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
2
|
-
export default function HomeHeader(): JSX.Element;
|
|
1
|
+
export default function HomeHeader(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useHomeContext, useHomeDispatchContext } from './HomeContext';
|
|
3
3
|
export default function HomeHeader() {
|
|
4
|
-
const { rocUrl, database,
|
|
4
|
+
const { rocUrl, database, iframePath } = useHomeContext();
|
|
5
5
|
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:
|
|
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: iframePath, type: "text", className: "flex-1 form-input", onChange: (event) => {
|
|
7
7
|
dispatch({ type: 'SET_IFRAME_PAGE', payload: event.target.value });
|
|
8
8
|
} })] }));
|
|
9
9
|
}
|
|
@@ -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
|
-
|
|
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
|
-
export default function HomeIframe() {
|
|
8
|
-
const {
|
|
6
|
+
export default function HomeIframe(props) {
|
|
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() {
|
|
|
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:
|
|
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
|
-
|
|
2
|
-
export default function HomeNoSample(): JSX.Element;
|
|
1
|
+
export default function HomeNoSample(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function HomeSamples(): JSX.Element;
|
|
1
|
+
export default function HomeSamples(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -16,7 +16,7 @@ interface IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserI
|
|
|
16
16
|
hasSample: false;
|
|
17
17
|
sample: null;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
type IframeBridgeReadyContextType<PublicUserInfo = unknown, PrivateUserInfo = unknown> = IframeBridgeReadyContextTypeWithSample<PublicUserInfo, PrivateUserInfo> | IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserInfo>;
|
|
20
20
|
interface IframeDataMessage {
|
|
21
21
|
couchDB: {
|
|
22
22
|
url: string;
|
|
@@ -28,5 +28,5 @@ export declare function IframeBridgeProvider(props: {
|
|
|
28
28
|
children: ReactNode;
|
|
29
29
|
requireSample?: boolean;
|
|
30
30
|
allowStandalone?: boolean;
|
|
31
|
-
}): JSX.Element;
|
|
31
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
32
32
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
3
|
-
|
|
4
|
-
import { ready, onMessage } from 'iframe-bridge/iframe';
|
|
3
|
+
import { onMessage, ready } from 'iframe-bridge/iframe';
|
|
5
4
|
import { produce } from 'immer';
|
|
6
5
|
import { createContext, useContext, useEffect, useReducer, } from 'react';
|
|
7
6
|
import { Roc } from 'rest-on-couch-client';
|
|
@@ -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
|
|
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);
|
package/lib/contexts/roc.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IQueryResult } from 'rest-on-couch-client';
|
|
2
|
-
export
|
|
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
|
-
|
|
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
|
|
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:
|
|
58
|
+
nmr: SampleEntrySpectraNmr[];
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
export interface SampleEntrySpectraNmr {
|
package/lib/types/util.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function LoadingFull(): JSX.Element;
|
|
1
|
+
export default function LoadingFull(): 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,5 +9,18 @@ export interface HomeProps {
|
|
|
10
9
|
* @default 'eln'
|
|
11
10
|
*/
|
|
12
11
|
database?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Base url loaded by the iframe
|
|
14
|
+
*/
|
|
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;
|
|
13
25
|
}
|
|
14
|
-
export declare function Home(props: HomeProps): JSX.Element;
|
|
26
|
+
export declare function Home(props: HomeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,12 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Home = void 0;
|
|
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
|
-
|
|
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 }) }));
|
|
15
17
|
}
|
|
16
18
|
exports.Home = Home;
|
|
19
|
+
function HomeInternal(props) {
|
|
20
|
+
const homeDispatch = (0, HomeContext_1.useHomeDispatchContext)();
|
|
21
|
+
(0, react_1.useEffect)(() => {
|
|
22
|
+
if (props.noSampleSelection) {
|
|
23
|
+
homeDispatch({
|
|
24
|
+
type: 'OPEN_NO_SAMPLE',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}, [props.noSampleSelection, homeDispatch]);
|
|
28
|
+
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 })] })] }));
|
|
29
|
+
}
|
|
@@ -3,17 +3,18 @@ import { ActionType } from '../../types/util';
|
|
|
3
3
|
interface HomeContextType {
|
|
4
4
|
rocUrl: string;
|
|
5
5
|
database: string;
|
|
6
|
-
|
|
6
|
+
iframePath: string;
|
|
7
7
|
iframeMode: 'closed' | 'sample' | 'no-sample';
|
|
8
8
|
selectedSample: string | null;
|
|
9
9
|
}
|
|
10
|
-
|
|
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 {};
|
|
@@ -8,11 +8,11 @@ const roc_1 = require("../../contexts/roc");
|
|
|
8
8
|
const localStorage_1 = require("../../hooks/localStorage");
|
|
9
9
|
const localStorage_2 = require("../../utils/localStorage");
|
|
10
10
|
function getInitialHomeContext(config = {}) {
|
|
11
|
-
const { rocUrl = 'http://localhost:3000/api/fake-roc', database = 'eln' } = config;
|
|
11
|
+
const { rocUrl = 'http://localhost:3000/api/fake-roc', database = 'eln', defaultPath = '/dev/base-page', } = config;
|
|
12
12
|
return {
|
|
13
13
|
rocUrl,
|
|
14
14
|
database,
|
|
15
|
-
|
|
15
|
+
iframePath: (0, localStorage_2.getItem)('dev-home-iframe-path') || defaultPath,
|
|
16
16
|
iframeMode: 'closed',
|
|
17
17
|
selectedSample: null,
|
|
18
18
|
};
|
|
@@ -28,7 +28,7 @@ const homeReducer = (0, immer_1.produce)((state, action) => {
|
|
|
28
28
|
state.selectedSample = action.payload;
|
|
29
29
|
break;
|
|
30
30
|
case 'SET_IFRAME_PAGE':
|
|
31
|
-
state.
|
|
31
|
+
state.iframePath = action.payload;
|
|
32
32
|
break;
|
|
33
33
|
default:
|
|
34
34
|
throw new Error('unreachable');
|
|
@@ -39,9 +39,10 @@ const homeDispatchContext = (0, react_1.createContext)(() => {
|
|
|
39
39
|
// noop
|
|
40
40
|
});
|
|
41
41
|
function HomeContextProvider(props) {
|
|
42
|
-
const
|
|
43
|
-
(0,
|
|
44
|
-
|
|
42
|
+
const { children, ...initial } = props;
|
|
43
|
+
const [homeState, dispatch] = (0, react_1.useReducer)(homeReducer, initial, getInitialHomeContext);
|
|
44
|
+
(0, localStorage_1.useSaveToLocalStorage)('dev-home-iframe-path', homeState.iframePath);
|
|
45
|
+
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
46
|
}
|
|
46
47
|
exports.HomeContextProvider = HomeContextProvider;
|
|
47
48
|
function useHomeContext() {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function HomeHeader(): JSX.Element;
|
|
1
|
+
export default function HomeHeader(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
const HomeContext_1 = require("./HomeContext");
|
|
5
5
|
function HomeHeader() {
|
|
6
|
-
const { rocUrl, database,
|
|
6
|
+
const { rocUrl, database, iframePath } = (0, HomeContext_1.useHomeContext)();
|
|
7
7
|
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:
|
|
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: iframePath, type: "text", className: "flex-1 form-input", onChange: (event) => {
|
|
9
9
|
dispatch({ type: 'SET_IFRAME_PAGE', payload: event.target.value });
|
|
10
10
|
} })] }));
|
|
11
11
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
5
|
-
/* eslint-disable import/no-unresolved */
|
|
6
5
|
const main_1 = require("iframe-bridge/main");
|
|
7
6
|
const react_1 = require("react");
|
|
8
7
|
const HomeContext_1 = require("./HomeContext");
|
|
9
|
-
function HomeIframe() {
|
|
10
|
-
const {
|
|
8
|
+
function HomeIframe(props) {
|
|
9
|
+
const { baseUrl } = props;
|
|
10
|
+
const { database, iframePath, rocUrl, selectedSample, iframeMode } = (0, HomeContext_1.useHomeContext)();
|
|
11
11
|
const [windowId, setWindowId] = (0, react_1.useState)();
|
|
12
12
|
(0, react_1.useEffect)(() => {
|
|
13
13
|
(0, main_1.registerHandler)('admin', (message) => {
|
|
@@ -32,6 +32,6 @@ function HomeIframe() {
|
|
|
32
32
|
uuid: selectedSample,
|
|
33
33
|
}, windowId);
|
|
34
34
|
}, [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:
|
|
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: `${baseUrl || ''}${iframePath}`, className: "w-full h-full" }, selectedSample)) : ((0, jsx_runtime_1.jsx)("div", { children: "Please select something" })) }));
|
|
36
36
|
}
|
|
37
37
|
exports.default = HomeIframe;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function HomeNoSample(): JSX.Element;
|
|
1
|
+
export default function HomeNoSample(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function HomeSamples(): JSX.Element;
|
|
1
|
+
export default function HomeSamples(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -16,7 +16,7 @@ interface IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserI
|
|
|
16
16
|
hasSample: false;
|
|
17
17
|
sample: null;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
type IframeBridgeReadyContextType<PublicUserInfo = unknown, PrivateUserInfo = unknown> = IframeBridgeReadyContextTypeWithSample<PublicUserInfo, PrivateUserInfo> | IframeBridgeReadyContextTypeWithoutSample<PublicUserInfo, PrivateUserInfo>;
|
|
20
20
|
interface IframeDataMessage {
|
|
21
21
|
couchDB: {
|
|
22
22
|
url: string;
|
|
@@ -28,5 +28,5 @@ export declare function IframeBridgeProvider(props: {
|
|
|
28
28
|
children: ReactNode;
|
|
29
29
|
requireSample?: boolean;
|
|
30
30
|
allowStandalone?: boolean;
|
|
31
|
-
}): JSX.Element;
|
|
31
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
32
32
|
export {};
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.IframeBridgeProvider = exports.useIframeBridgeSample = exports.useIframeBridgeContext = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
9
|
-
/* eslint-disable import/no-unresolved */
|
|
10
9
|
const iframe_1 = require("iframe-bridge/iframe");
|
|
11
10
|
const immer_1 = require("immer");
|
|
12
11
|
const react_1 = require("react");
|
|
@@ -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
|
|
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);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IQueryResult } from 'rest-on-couch-client';
|
|
2
|
-
export
|
|
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
|
-
|
|
8
|
+
type RocQueryHookResult<T> = RocQueryState<T>;
|
|
9
9
|
interface RocQueryHookOptions {
|
|
10
10
|
mine?: boolean;
|
|
11
11
|
}
|
package/lib-cjs/types/db.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface TocEntry {
|
|
|
27
27
|
names: string[];
|
|
28
28
|
reference: string;
|
|
29
29
|
}
|
|
30
|
-
export
|
|
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:
|
|
58
|
+
nmr: SampleEntrySpectraNmr[];
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
export interface SampleEntrySpectraNmr {
|
package/lib-cjs/types/util.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.9.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": "^
|
|
31
|
+
"clsx": "^2.1.1",
|
|
32
32
|
"iframe-bridge": "^2.0.0",
|
|
33
|
-
"immer": "^
|
|
34
|
-
"rest-on-couch-client": "^5.1
|
|
33
|
+
"immer": "^10.1.1",
|
|
34
|
+
"rest-on-couch-client": "^5.3.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/react": "^
|
|
38
|
-
"@types/react-dom": "^
|
|
39
|
-
"
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"prettier": "^
|
|
42
|
-
"react": "^
|
|
43
|
-
"react-dom": "^
|
|
37
|
+
"@types/react": "^18.3.1",
|
|
38
|
+
"@types/react-dom": "^18.3.0",
|
|
39
|
+
"eslint": "^8.57.0",
|
|
40
|
+
"eslint-config-zakodium": "^9.0.1",
|
|
41
|
+
"prettier": "^3.2.5",
|
|
42
|
+
"react": "^18.3.1",
|
|
43
|
+
"react-dom": "^18.3.1",
|
|
44
|
+
"typescript": "^5.4.5"
|
|
44
45
|
}
|
|
45
46
|
}
|