react-iframe-bridge 0.3.0 → 0.4.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.js +1 -1
- package/lib/components/LoadingFull.js +1 -1
- package/lib/components/Spinner.js +1 -1
- package/lib/components/home/Home.js +1 -1
- package/lib/components/home/HomeContext.js +1 -1
- package/lib/components/home/HomeHeader.js +2 -2
- package/lib/components/home/HomeIframe.js +3 -1
- package/lib/components/home/HomeSamples.js +3 -3
- package/lib/components/home/HomeSelector.js +1 -1
- package/lib/contexts/iframeBridge.d.ts +3 -3
- package/lib/contexts/iframeBridge.js +4 -2
- package/lib/contexts/roc.js +1 -1
- package/lib/types/db.d.ts +2 -1
- package/lib-cjs/components/ErrorPage.js +1 -1
- package/lib-cjs/components/LoadingFull.js +1 -1
- package/lib-cjs/components/Spinner.js +1 -1
- package/lib-cjs/components/home/Home.js +1 -1
- package/lib-cjs/components/home/HomeContext.js +9 -9
- package/lib-cjs/components/home/HomeHeader.js +4 -4
- package/lib-cjs/components/home/HomeIframe.js +9 -7
- package/lib-cjs/components/home/HomeNoSample.js +3 -3
- package/lib-cjs/components/home/HomeSamples.js +6 -6
- package/lib-cjs/components/home/HomeSelector.js +1 -1
- package/lib-cjs/contexts/iframeBridge.d.ts +3 -3
- package/lib-cjs/contexts/iframeBridge.js +15 -13
- package/lib-cjs/contexts/roc.js +4 -4
- package/lib-cjs/hooks/localStorage.js +6 -6
- package/lib-cjs/hooks/useRocQuery.js +3 -3
- package/lib-cjs/types/db.d.ts +2 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
export default function ErrorPage(props) {
|
|
3
|
-
return (_jsx("div",
|
|
3
|
+
return (_jsx("div", { className: "max-w-2xl m-auto md:max-w-4xl", children: _jsx("div", { className: "flex justify-between px-2 pt-4", children: _jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "text-5xl font-bold sm:mt-16 text-primary-900", children: props.title }, void 0), _jsx("h2", { className: "mt-16 text-lg sm:mt-8", children: props.subtitle }, void 0), _jsx("div", { className: "mt-4", children: props.children }, void 0)] }, void 0) }, void 0) }, void 0));
|
|
4
4
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import Spinner from './Spinner';
|
|
3
3
|
export default function LoadingFull() {
|
|
4
|
-
return (_jsx("div",
|
|
4
|
+
return (_jsx("div", { className: "flex items-center justify-center w-full h-full", children: _jsx(Spinner, { className: "w-10 h-10 text-alternative-500" }, void 0) }, void 0));
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
export default function Spinner(props) {
|
|
4
|
-
return (_jsxs("svg",
|
|
4
|
+
return (_jsxs("svg", { className: clsx('animate-spin', props.className), xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }, void 0), _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" }, void 0)] }, void 0));
|
|
5
5
|
}
|
|
@@ -5,5 +5,5 @@ import HomeIframe from './HomeIframe';
|
|
|
5
5
|
import HomeNoSample from './HomeNoSample';
|
|
6
6
|
import HomeSamples from './HomeSamples';
|
|
7
7
|
export function Home(props) {
|
|
8
|
-
return (_jsx(HomeContextProvider,
|
|
8
|
+
return (_jsx(HomeContextProvider, { rocUrl: props.rocUrl, database: props.database, children: _jsxs("div", { className: "flex flex-col w-screen h-screen", children: [_jsx(HomeHeader, {}, void 0), _jsxs("div", { className: "flex flex-row flex-1 mt-2 border-t border-neutral-300 ", children: [_jsxs("div", { className: "flex flex-col w-48 px-2 pt-4 space-y-3 border-r h-100 border-neutral-300", children: [_jsx(HomeNoSample, {}, void 0), _jsx(HomeSamples, {}, void 0)] }, void 0), _jsx(HomeIframe, {}, void 0)] }, void 0)] }, void 0) }, void 0));
|
|
9
9
|
}
|
|
@@ -38,7 +38,7 @@ const homeDispatchContext = createContext(() => {
|
|
|
38
38
|
export function HomeContextProvider(props) {
|
|
39
39
|
const [homeState, dispatch] = useReducer(homeReducer, props, getInitialHomeContext);
|
|
40
40
|
useSaveToLocalStorage('dev-home-iframePage', homeState.iframePage);
|
|
41
|
-
return (_jsx(homeContext.Provider,
|
|
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 }, void 0) }, void 0) }, void 0));
|
|
42
42
|
}
|
|
43
43
|
export function useHomeContext() {
|
|
44
44
|
return useContext(homeContext);
|
|
@@ -3,7 +3,7 @@ import { useHomeContext, useHomeDispatchContext } from './HomeContext';
|
|
|
3
3
|
export default function HomeHeader() {
|
|
4
4
|
const { rocUrl, database, iframePage } = useHomeContext();
|
|
5
5
|
const dispatch = useHomeDispatchContext();
|
|
6
|
-
return (_jsxs("header",
|
|
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 }, void 0), _jsx("input", { name: "database", type: "text", className: "form-input", value: database, readOnly: true }, void 0), _jsx("input", { name: "iframe-page", value: iframePage, type: "text", className: "flex-1 form-input", onChange: (event) => {
|
|
7
7
|
dispatch({ type: 'SET_IFRAME_PAGE', payload: event.target.value });
|
|
8
|
-
} }, void 0)] }
|
|
8
|
+
} }, void 0)] }, void 0));
|
|
9
9
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
3
|
+
/* eslint-disable import/no-unresolved */
|
|
2
4
|
import { registerHandler, postMessage } from 'iframe-bridge/main';
|
|
3
5
|
import { useEffect, useState } from 'react';
|
|
4
6
|
import { useHomeContext } from './HomeContext';
|
|
@@ -28,5 +30,5 @@ export default function HomeIframe() {
|
|
|
28
30
|
uuid: selectedSample,
|
|
29
31
|
}, windowId);
|
|
30
32
|
}, [windowId, database, rocUrl, selectedSample]);
|
|
31
|
-
return (_jsx("div",
|
|
33
|
+
return (_jsx("div", { className: "flex items-center justify-center flex-1", children: iframeMode !== 'closed' ? (_jsx("iframe", { allowFullScreen: true, src: `http://localhost:3000${iframePage}`, className: "w-full h-full" }, selectedSample)) : (_jsx("div", { children: "Please select something" }, void 0)) }, void 0));
|
|
32
34
|
}
|
|
@@ -8,7 +8,7 @@ export default function HomeSamples() {
|
|
|
8
8
|
if (error) {
|
|
9
9
|
throw error;
|
|
10
10
|
}
|
|
11
|
-
return (_jsxs(_Fragment, { children: [_jsx("h1",
|
|
11
|
+
return (_jsxs(_Fragment, { children: [_jsx("h1", { className: "mb-4 text-lg font-bold text-center", children: "Sample TOC" }, void 0), _jsx("div", { className: "flex-1", children: loading || !result ? _jsx(Loading, {}, void 0) : _jsx(SampleToc, { samples: result }, void 0) }, void 0)] }, void 0));
|
|
12
12
|
}
|
|
13
13
|
function SampleToc(props) {
|
|
14
14
|
const { selectedSample } = useHomeContext();
|
|
@@ -16,8 +16,8 @@ function SampleToc(props) {
|
|
|
16
16
|
function selectSample(id) {
|
|
17
17
|
dispatch({ type: 'SELECT_SAMPLE', payload: id });
|
|
18
18
|
}
|
|
19
|
-
return (_jsx("div",
|
|
19
|
+
return (_jsx("div", { className: "space-y-2", children: props.samples.map((sample) => (_jsx(HomeSelector, { selected: sample.id === selectedSample, text: sample.value.reference, onClick: () => selectSample(sample.id) }, sample.id))) }, void 0));
|
|
20
20
|
}
|
|
21
21
|
function Loading() {
|
|
22
|
-
return (_jsx("div",
|
|
22
|
+
return (_jsx("div", { className: "flex justify-center mt-8", children: _jsx(Spinner, { className: "w-8 h-8 text-alternative-500" }, void 0) }, void 0));
|
|
23
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
export default function HomeSelector(props) {
|
|
4
|
-
return (_jsx("div",
|
|
4
|
+
return (_jsx("div", { className: clsx('p-1 border rounded cursor-pointer border-neutral-400', props.selected && 'bg-primary-50 shadow-inner'), onClick: props.onClick, children: props.text }, void 0));
|
|
5
5
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Roc, RocDocument } from 'rest-on-couch-client';
|
|
3
|
-
import { SampleEntryContent } from '../types/db';
|
|
3
|
+
import { SampleEntryContent, SampleEntryId } from '../types/db';
|
|
4
4
|
export declare function useIframeBridgeContext(): IframeBridgeReadyContextType;
|
|
5
|
-
export declare function useIframeBridgeSample(): RocDocument<SampleEntryContent>;
|
|
5
|
+
export declare function useIframeBridgeSample(): RocDocument<SampleEntryContent, SampleEntryId>;
|
|
6
6
|
interface IframeBridgeReadyContextTypeBase {
|
|
7
7
|
state: 'ready';
|
|
8
8
|
data: IframeDataMessage;
|
|
@@ -10,7 +10,7 @@ interface IframeBridgeReadyContextTypeBase {
|
|
|
10
10
|
}
|
|
11
11
|
interface IframeBridgeReadyContextTypeWithSample extends IframeBridgeReadyContextTypeBase {
|
|
12
12
|
hasSample: true;
|
|
13
|
-
sample: RocDocument<SampleEntryContent>;
|
|
13
|
+
sample: RocDocument<SampleEntryContent, SampleEntryId>;
|
|
14
14
|
}
|
|
15
15
|
interface IframeBridgeReadyContextTypeWithoutSample extends IframeBridgeReadyContextTypeBase {
|
|
16
16
|
hasSample: false;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
3
|
+
/* eslint-disable import/no-unresolved */
|
|
2
4
|
import { ready, onMessage } from 'iframe-bridge/iframe';
|
|
3
5
|
import { produce } from 'immer';
|
|
4
6
|
import { createContext, useContext, useEffect, useReducer, } from 'react';
|
|
@@ -110,10 +112,10 @@ export function IframeBridgeProvider(props) {
|
|
|
110
112
|
return (_jsx(ErrorPage, { title: "Invalid access", subtitle: "This page cannot be accessed without iframe-bridge." }, void 0));
|
|
111
113
|
}
|
|
112
114
|
if (state.state !== 'ready') {
|
|
113
|
-
return (_jsx("div",
|
|
115
|
+
return (_jsx("div", { className: "w-screen h-screen", children: _jsx(LoadingFull, {}, void 0) }, void 0));
|
|
114
116
|
}
|
|
115
117
|
if (!state.hasSample && props.requireSample) {
|
|
116
118
|
return (_jsx(ErrorPage, { title: "Invalid access", subtitle: "This page must be accessed with a sample." }, void 0));
|
|
117
119
|
}
|
|
118
|
-
return (_jsx(iframeBridgeContext.Provider,
|
|
120
|
+
return (_jsx(iframeBridgeContext.Provider, { value: state, children: props.children }, void 0));
|
|
119
121
|
}
|
package/lib/contexts/roc.js
CHANGED
|
@@ -12,5 +12,5 @@ export function useRoc() {
|
|
|
12
12
|
export function RocProvider(props) {
|
|
13
13
|
const { url, database, children } = props;
|
|
14
14
|
const roc = useMemo(() => new Roc({ url, database }), [url, database]);
|
|
15
|
-
return _jsx(rocContext.Provider,
|
|
15
|
+
return _jsx(rocContext.Provider, { value: roc, children: children }, void 0);
|
|
16
16
|
}
|
package/lib/types/db.d.ts
CHANGED
|
@@ -27,11 +27,12 @@ export interface TocEntry {
|
|
|
27
27
|
names: string[];
|
|
28
28
|
reference: string;
|
|
29
29
|
}
|
|
30
|
+
export declare type SampleEntryId = [string, string];
|
|
30
31
|
export interface SampleEntry {
|
|
31
32
|
_id: string;
|
|
32
33
|
_rev: string;
|
|
33
34
|
$type: 'entry';
|
|
34
|
-
$id:
|
|
35
|
+
$id: SampleEntryId;
|
|
35
36
|
$kind: 'sample';
|
|
36
37
|
$owners: string[];
|
|
37
38
|
$content: SampleEntryContent;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
function ErrorPage(props) {
|
|
5
|
-
return (jsx_runtime_1.jsx("div",
|
|
5
|
+
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 }, void 0), (0, jsx_runtime_1.jsx)("h2", { className: "mt-16 text-lg sm:mt-8", children: props.subtitle }, void 0), (0, jsx_runtime_1.jsx)("div", { className: "mt-4", children: props.children }, void 0)] }, void 0) }, void 0) }, void 0));
|
|
6
6
|
}
|
|
7
7
|
exports.default = ErrorPage;
|
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
7
|
const Spinner_1 = __importDefault(require("./Spinner"));
|
|
8
8
|
function LoadingFull() {
|
|
9
|
-
return (jsx_runtime_1.jsx("div",
|
|
9
|
+
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" }, void 0) }, void 0));
|
|
10
10
|
}
|
|
11
11
|
exports.default = LoadingFull;
|
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
7
|
const clsx_1 = __importDefault(require("clsx"));
|
|
8
8
|
function Spinner(props) {
|
|
9
|
-
return (jsx_runtime_1.jsxs("svg",
|
|
9
|
+
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" }, void 0), (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" }, void 0)] }, void 0));
|
|
10
10
|
}
|
|
11
11
|
exports.default = Spinner;
|
|
@@ -11,6 +11,6 @@ const HomeIframe_1 = __importDefault(require("./HomeIframe"));
|
|
|
11
11
|
const HomeNoSample_1 = __importDefault(require("./HomeNoSample"));
|
|
12
12
|
const HomeSamples_1 = __importDefault(require("./HomeSamples"));
|
|
13
13
|
function Home(props) {
|
|
14
|
-
return (jsx_runtime_1.jsx(HomeContext_1.HomeContextProvider,
|
|
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, {}, void 0), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-row flex-1 mt-2 border-t border-neutral-300 ", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col w-48 px-2 pt-4 space-y-3 border-r h-100 border-neutral-300", children: [(0, jsx_runtime_1.jsx)(HomeNoSample_1.default, {}, void 0), (0, jsx_runtime_1.jsx)(HomeSamples_1.default, {}, void 0)] }, void 0), (0, jsx_runtime_1.jsx)(HomeIframe_1.default, {}, void 0)] }, void 0)] }, void 0) }, void 0));
|
|
15
15
|
}
|
|
16
16
|
exports.Home = Home;
|
|
@@ -12,12 +12,12 @@ function getInitialHomeContext(config = {}) {
|
|
|
12
12
|
return {
|
|
13
13
|
rocUrl,
|
|
14
14
|
database,
|
|
15
|
-
iframePage: localStorage_2.getItem('dev-home-iframePage') || '/dev/base-page',
|
|
15
|
+
iframePage: (0, localStorage_2.getItem)('dev-home-iframePage') || '/dev/base-page',
|
|
16
16
|
iframeMode: 'closed',
|
|
17
17
|
selectedSample: null,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
const homeReducer = immer_1.produce((state, action) => {
|
|
20
|
+
const homeReducer = (0, immer_1.produce)((state, action) => {
|
|
21
21
|
switch (action.type) {
|
|
22
22
|
case 'OPEN_NO_SAMPLE':
|
|
23
23
|
state.iframeMode = 'no-sample';
|
|
@@ -34,21 +34,21 @@ const homeReducer = immer_1.produce((state, action) => {
|
|
|
34
34
|
throw new Error('unreachable');
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
const homeContext = react_1.createContext(getInitialHomeContext());
|
|
38
|
-
const homeDispatchContext = react_1.createContext(() => {
|
|
37
|
+
const homeContext = (0, react_1.createContext)(getInitialHomeContext());
|
|
38
|
+
const homeDispatchContext = (0, react_1.createContext)(() => {
|
|
39
39
|
// noop
|
|
40
40
|
});
|
|
41
41
|
function HomeContextProvider(props) {
|
|
42
|
-
const [homeState, dispatch] = react_1.useReducer(homeReducer, props, getInitialHomeContext);
|
|
43
|
-
localStorage_1.useSaveToLocalStorage('dev-home-iframePage', homeState.iframePage);
|
|
44
|
-
return (jsx_runtime_1.jsx(homeContext.Provider,
|
|
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 }, void 0) }, void 0) }, void 0));
|
|
45
45
|
}
|
|
46
46
|
exports.HomeContextProvider = HomeContextProvider;
|
|
47
47
|
function useHomeContext() {
|
|
48
|
-
return react_1.useContext(homeContext);
|
|
48
|
+
return (0, react_1.useContext)(homeContext);
|
|
49
49
|
}
|
|
50
50
|
exports.useHomeContext = useHomeContext;
|
|
51
51
|
function useHomeDispatchContext() {
|
|
52
|
-
return react_1.useContext(homeDispatchContext);
|
|
52
|
+
return (0, react_1.useContext)(homeDispatchContext);
|
|
53
53
|
}
|
|
54
54
|
exports.useHomeDispatchContext = useHomeDispatchContext;
|
|
@@ -3,10 +3,10 @@ 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, iframePage } = HomeContext_1.useHomeContext();
|
|
7
|
-
const dispatch = HomeContext_1.useHomeDispatchContext();
|
|
8
|
-
return (jsx_runtime_1.jsxs("header",
|
|
6
|
+
const { rocUrl, database, iframePage } = (0, HomeContext_1.useHomeContext)();
|
|
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 }, void 0), (0, jsx_runtime_1.jsx)("input", { name: "database", type: "text", className: "form-input", value: database, readOnly: true }, void 0), (0, jsx_runtime_1.jsx)("input", { name: "iframe-page", value: iframePage, type: "text", className: "flex-1 form-input", onChange: (event) => {
|
|
9
9
|
dispatch({ type: 'SET_IFRAME_PAGE', payload: event.target.value });
|
|
10
|
-
} }, void 0)] }
|
|
10
|
+
} }, void 0)] }, void 0));
|
|
11
11
|
}
|
|
12
12
|
exports.default = HomeHeader;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
5
|
+
/* eslint-disable import/no-unresolved */
|
|
4
6
|
const main_1 = require("iframe-bridge/main");
|
|
5
7
|
const react_1 = require("react");
|
|
6
8
|
const HomeContext_1 = require("./HomeContext");
|
|
7
9
|
function HomeIframe() {
|
|
8
|
-
const { database, iframePage, rocUrl, selectedSample, iframeMode } = HomeContext_1.useHomeContext();
|
|
9
|
-
const [windowId, setWindowId] = react_1.useState();
|
|
10
|
-
react_1.useEffect(() => {
|
|
11
|
-
main_1.registerHandler('admin', (message) => {
|
|
10
|
+
const { database, iframePage, rocUrl, selectedSample, iframeMode } = (0, HomeContext_1.useHomeContext)();
|
|
11
|
+
const [windowId, setWindowId] = (0, react_1.useState)();
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
(0, main_1.registerHandler)('admin', (message) => {
|
|
12
14
|
switch (message.type) {
|
|
13
15
|
case 'admin.connect': {
|
|
14
16
|
setWindowId(message.windowID);
|
|
@@ -19,10 +21,10 @@ function HomeIframe() {
|
|
|
19
21
|
}
|
|
20
22
|
});
|
|
21
23
|
}, []);
|
|
22
|
-
react_1.useEffect(() => {
|
|
24
|
+
(0, react_1.useEffect)(() => {
|
|
23
25
|
if (windowId === undefined)
|
|
24
26
|
return;
|
|
25
|
-
main_1.postMessage('tab.data', {
|
|
27
|
+
(0, main_1.postMessage)('tab.data', {
|
|
26
28
|
couchDB: {
|
|
27
29
|
url: rocUrl,
|
|
28
30
|
database,
|
|
@@ -30,6 +32,6 @@ function HomeIframe() {
|
|
|
30
32
|
uuid: selectedSample,
|
|
31
33
|
}, windowId);
|
|
32
34
|
}, [windowId, database, rocUrl, selectedSample]);
|
|
33
|
-
return (jsx_runtime_1.jsx("div",
|
|
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: `http://localhost:3000${iframePage}`, className: "w-full h-full" }, selectedSample)) : ((0, jsx_runtime_1.jsx)("div", { children: "Please select something" }, void 0)) }, void 0));
|
|
34
36
|
}
|
|
35
37
|
exports.default = HomeIframe;
|
|
@@ -7,8 +7,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
7
|
const HomeContext_1 = require("./HomeContext");
|
|
8
8
|
const HomeSelector_1 = __importDefault(require("./HomeSelector"));
|
|
9
9
|
function HomeNoSample() {
|
|
10
|
-
const { iframeMode } = HomeContext_1.useHomeContext();
|
|
11
|
-
const dispatch = HomeContext_1.useHomeDispatchContext();
|
|
12
|
-
return (jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx(HomeSelector_1.default, { onClick: () => dispatch({ type: 'OPEN_NO_SAMPLE' }), selected: iframeMode === 'no-sample', text: "No sample" }, void 0) }, void 0));
|
|
10
|
+
const { iframeMode } = (0, HomeContext_1.useHomeContext)();
|
|
11
|
+
const dispatch = (0, HomeContext_1.useHomeDispatchContext)();
|
|
12
|
+
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" }, void 0) }, void 0));
|
|
13
13
|
}
|
|
14
14
|
exports.default = HomeNoSample;
|
|
@@ -9,21 +9,21 @@ const Spinner_1 = __importDefault(require("../Spinner"));
|
|
|
9
9
|
const HomeContext_1 = require("./HomeContext");
|
|
10
10
|
const HomeSelector_1 = __importDefault(require("./HomeSelector"));
|
|
11
11
|
function HomeSamples() {
|
|
12
|
-
const { loading, error, result } = useRocQuery_1.useRocQuery('sample_toc');
|
|
12
|
+
const { loading, error, result } = (0, useRocQuery_1.useRocQuery)('sample_toc');
|
|
13
13
|
if (error) {
|
|
14
14
|
throw error;
|
|
15
15
|
}
|
|
16
|
-
return (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [jsx_runtime_1.jsx("h1",
|
|
16
|
+
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" }, void 0), (0, jsx_runtime_1.jsx)("div", { className: "flex-1", children: loading || !result ? (0, jsx_runtime_1.jsx)(Loading, {}, void 0) : (0, jsx_runtime_1.jsx)(SampleToc, { samples: result }, void 0) }, void 0)] }, void 0));
|
|
17
17
|
}
|
|
18
18
|
exports.default = HomeSamples;
|
|
19
19
|
function SampleToc(props) {
|
|
20
|
-
const { selectedSample } = HomeContext_1.useHomeContext();
|
|
21
|
-
const dispatch = HomeContext_1.useHomeDispatchContext();
|
|
20
|
+
const { selectedSample } = (0, HomeContext_1.useHomeContext)();
|
|
21
|
+
const dispatch = (0, HomeContext_1.useHomeDispatchContext)();
|
|
22
22
|
function selectSample(id) {
|
|
23
23
|
dispatch({ type: 'SELECT_SAMPLE', payload: id });
|
|
24
24
|
}
|
|
25
|
-
return (jsx_runtime_1.jsx("div",
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "space-y-2", children: props.samples.map((sample) => ((0, jsx_runtime_1.jsx)(HomeSelector_1.default, { selected: sample.id === selectedSample, text: sample.value.reference, onClick: () => selectSample(sample.id) }, sample.id))) }, void 0));
|
|
26
26
|
}
|
|
27
27
|
function Loading() {
|
|
28
|
-
return (jsx_runtime_1.jsx("div",
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "flex justify-center mt-8", children: (0, jsx_runtime_1.jsx)(Spinner_1.default, { className: "w-8 h-8 text-alternative-500" }, void 0) }, void 0));
|
|
29
29
|
}
|
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
7
|
const clsx_1 = __importDefault(require("clsx"));
|
|
8
8
|
function HomeSelector(props) {
|
|
9
|
-
return (jsx_runtime_1.jsx("div",
|
|
9
|
+
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 }, void 0));
|
|
10
10
|
}
|
|
11
11
|
exports.default = HomeSelector;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Roc, RocDocument } from 'rest-on-couch-client';
|
|
3
|
-
import { SampleEntryContent } from '../types/db';
|
|
3
|
+
import { SampleEntryContent, SampleEntryId } from '../types/db';
|
|
4
4
|
export declare function useIframeBridgeContext(): IframeBridgeReadyContextType;
|
|
5
|
-
export declare function useIframeBridgeSample(): RocDocument<SampleEntryContent>;
|
|
5
|
+
export declare function useIframeBridgeSample(): RocDocument<SampleEntryContent, SampleEntryId>;
|
|
6
6
|
interface IframeBridgeReadyContextTypeBase {
|
|
7
7
|
state: 'ready';
|
|
8
8
|
data: IframeDataMessage;
|
|
@@ -10,7 +10,7 @@ interface IframeBridgeReadyContextTypeBase {
|
|
|
10
10
|
}
|
|
11
11
|
interface IframeBridgeReadyContextTypeWithSample extends IframeBridgeReadyContextTypeBase {
|
|
12
12
|
hasSample: true;
|
|
13
|
-
sample: RocDocument<SampleEntryContent>;
|
|
13
|
+
sample: RocDocument<SampleEntryContent, SampleEntryId>;
|
|
14
14
|
}
|
|
15
15
|
interface IframeBridgeReadyContextTypeWithoutSample extends IframeBridgeReadyContextTypeBase {
|
|
16
16
|
hasSample: false;
|
|
@@ -5,15 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
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
|
+
// https://github.com/import-js/eslint-plugin-import/issues/1810
|
|
9
|
+
/* eslint-disable import/no-unresolved */
|
|
8
10
|
const iframe_1 = require("iframe-bridge/iframe");
|
|
9
11
|
const immer_1 = require("immer");
|
|
10
12
|
const react_1 = require("react");
|
|
11
13
|
const rest_on_couch_client_1 = require("rest-on-couch-client");
|
|
12
14
|
const ErrorPage_1 = __importDefault(require("../components/ErrorPage"));
|
|
13
15
|
const LoadingFull_1 = __importDefault(require("../components/LoadingFull"));
|
|
14
|
-
const iframeBridgeContext = react_1.createContext(null);
|
|
16
|
+
const iframeBridgeContext = (0, react_1.createContext)(null);
|
|
15
17
|
function useIframeBridgeContext() {
|
|
16
|
-
const context = react_1.useContext(iframeBridgeContext);
|
|
18
|
+
const context = (0, react_1.useContext)(iframeBridgeContext);
|
|
17
19
|
if (!context) {
|
|
18
20
|
throw new Error('Iframe bridge context is not ready');
|
|
19
21
|
}
|
|
@@ -28,7 +30,7 @@ function useIframeBridgeSample() {
|
|
|
28
30
|
return context.sample;
|
|
29
31
|
}
|
|
30
32
|
exports.useIframeBridgeSample = useIframeBridgeSample;
|
|
31
|
-
const iframeBridgeReducer = immer_1.produce((state, action) => {
|
|
33
|
+
const iframeBridgeReducer = (0, immer_1.produce)((state, action) => {
|
|
32
34
|
switch (action.type) {
|
|
33
35
|
case 'RECEIVE_DATA': {
|
|
34
36
|
state.data = action.payload;
|
|
@@ -64,9 +66,9 @@ const initialState = {
|
|
|
64
66
|
sample: null,
|
|
65
67
|
};
|
|
66
68
|
function IframeBridgeProvider(props) {
|
|
67
|
-
const [state, dispatch] = react_1.useReducer(iframeBridgeReducer, initialState);
|
|
68
|
-
react_1.useEffect(() => {
|
|
69
|
-
iframe_1.onMessage((message) => {
|
|
69
|
+
const [state, dispatch] = (0, react_1.useReducer)(iframeBridgeReducer, initialState);
|
|
70
|
+
(0, react_1.useEffect)(() => {
|
|
71
|
+
(0, iframe_1.onMessage)((message) => {
|
|
70
72
|
switch (message.type) {
|
|
71
73
|
case 'tab.data': {
|
|
72
74
|
dispatch({ type: 'RECEIVE_DATA', payload: message.message });
|
|
@@ -83,9 +85,9 @@ function IframeBridgeProvider(props) {
|
|
|
83
85
|
throw new Error('unreachable');
|
|
84
86
|
}
|
|
85
87
|
});
|
|
86
|
-
iframe_1.ready();
|
|
88
|
+
(0, iframe_1.ready)();
|
|
87
89
|
}, []);
|
|
88
|
-
react_1.useEffect(() => {
|
|
90
|
+
(0, react_1.useEffect)(() => {
|
|
89
91
|
if (!props.allowStandalone && state.state === 'initial') {
|
|
90
92
|
const timeout = setTimeout(() => {
|
|
91
93
|
dispatch({ type: 'STANDALONE_TIMEOUT' });
|
|
@@ -93,7 +95,7 @@ function IframeBridgeProvider(props) {
|
|
|
93
95
|
return () => clearTimeout(timeout);
|
|
94
96
|
}
|
|
95
97
|
}, [props.allowStandalone, state.state]);
|
|
96
|
-
react_1.useEffect(() => {
|
|
98
|
+
(0, react_1.useEffect)(() => {
|
|
97
99
|
if (!state.roc || !state.data || !state.data.uuid)
|
|
98
100
|
return;
|
|
99
101
|
let cancelled = false;
|
|
@@ -115,14 +117,14 @@ function IframeBridgeProvider(props) {
|
|
|
115
117
|
};
|
|
116
118
|
}, [state.roc, state.data]);
|
|
117
119
|
if (state.state === 'standalone-error') {
|
|
118
|
-
return (jsx_runtime_1.jsx(ErrorPage_1.default, { title: "Invalid access", subtitle: "This page cannot be accessed without iframe-bridge." }, void 0));
|
|
120
|
+
return ((0, jsx_runtime_1.jsx)(ErrorPage_1.default, { title: "Invalid access", subtitle: "This page cannot be accessed without iframe-bridge." }, void 0));
|
|
119
121
|
}
|
|
120
122
|
if (state.state !== 'ready') {
|
|
121
|
-
return (jsx_runtime_1.jsx("div",
|
|
123
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "w-screen h-screen", children: (0, jsx_runtime_1.jsx)(LoadingFull_1.default, {}, void 0) }, void 0));
|
|
122
124
|
}
|
|
123
125
|
if (!state.hasSample && props.requireSample) {
|
|
124
|
-
return (jsx_runtime_1.jsx(ErrorPage_1.default, { title: "Invalid access", subtitle: "This page must be accessed with a sample." }, void 0));
|
|
126
|
+
return ((0, jsx_runtime_1.jsx)(ErrorPage_1.default, { title: "Invalid access", subtitle: "This page must be accessed with a sample." }, void 0));
|
|
125
127
|
}
|
|
126
|
-
return (jsx_runtime_1.jsx(iframeBridgeContext.Provider,
|
|
128
|
+
return ((0, jsx_runtime_1.jsx)(iframeBridgeContext.Provider, { value: state, children: props.children }, void 0));
|
|
127
129
|
}
|
|
128
130
|
exports.IframeBridgeProvider = IframeBridgeProvider;
|
package/lib-cjs/contexts/roc.js
CHANGED
|
@@ -4,9 +4,9 @@ exports.RocProvider = exports.useRoc = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const rest_on_couch_client_1 = require("rest-on-couch-client");
|
|
7
|
-
const rocContext = react_1.createContext(null);
|
|
7
|
+
const rocContext = (0, react_1.createContext)(null);
|
|
8
8
|
function useRoc() {
|
|
9
|
-
const roc = react_1.useContext(rocContext);
|
|
9
|
+
const roc = (0, react_1.useContext)(rocContext);
|
|
10
10
|
if (!roc) {
|
|
11
11
|
throw new Error('missing roc');
|
|
12
12
|
}
|
|
@@ -15,7 +15,7 @@ function useRoc() {
|
|
|
15
15
|
exports.useRoc = useRoc;
|
|
16
16
|
function RocProvider(props) {
|
|
17
17
|
const { url, database, children } = props;
|
|
18
|
-
const roc = react_1.useMemo(() => new rest_on_couch_client_1.Roc({ url, database }), [url, database]);
|
|
19
|
-
return jsx_runtime_1.jsx(rocContext.Provider,
|
|
18
|
+
const roc = (0, react_1.useMemo)(() => new rest_on_couch_client_1.Roc({ url, database }), [url, database]);
|
|
19
|
+
return (0, jsx_runtime_1.jsx)(rocContext.Provider, { value: roc, children: children }, void 0);
|
|
20
20
|
}
|
|
21
21
|
exports.RocProvider = RocProvider;
|
|
@@ -10,18 +10,18 @@ const localStorage_1 = require("../utils/localStorage");
|
|
|
10
10
|
* @param initialValue Value to use if the storage is empty.
|
|
11
11
|
*/
|
|
12
12
|
function useLocalStorage(key, initialValue) {
|
|
13
|
-
const [storedValue, setStoredValue] = react_1.useState(() => {
|
|
13
|
+
const [storedValue, setStoredValue] = (0, react_1.useState)(() => {
|
|
14
14
|
// Get from local storage by key.
|
|
15
|
-
const item = localStorage_1.getItem(key);
|
|
15
|
+
const item = (0, localStorage_1.getItem)(key);
|
|
16
16
|
// Parse stored json or if none return initialValue.
|
|
17
17
|
return item ? item : initialValue;
|
|
18
18
|
});
|
|
19
19
|
// Return a wrapped version of useState's setter function that persists the new value to localStorage.
|
|
20
|
-
const setValue = react_1.useCallback((value) => {
|
|
20
|
+
const setValue = (0, react_1.useCallback)((value) => {
|
|
21
21
|
// Save state.
|
|
22
22
|
setStoredValue(value);
|
|
23
23
|
// Save to local storage.
|
|
24
|
-
localStorage_1.setItem(key, value);
|
|
24
|
+
(0, localStorage_1.setItem)(key, value);
|
|
25
25
|
}, [key]);
|
|
26
26
|
return [storedValue, setValue];
|
|
27
27
|
}
|
|
@@ -32,8 +32,8 @@ exports.useLocalStorage = useLocalStorage;
|
|
|
32
32
|
* @param value Value to save.
|
|
33
33
|
*/
|
|
34
34
|
function useSaveToLocalStorage(key, value) {
|
|
35
|
-
react_1.useEffect(() => {
|
|
36
|
-
localStorage_1.setItem(key, value);
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
(0, localStorage_1.setItem)(key, value);
|
|
37
37
|
}, [key, value]);
|
|
38
38
|
}
|
|
39
39
|
exports.useSaveToLocalStorage = useSaveToLocalStorage;
|
|
@@ -25,13 +25,13 @@ function rocQueryReducer(state, action) {
|
|
|
25
25
|
}
|
|
26
26
|
function useRocQuery(viewName, options = {}) {
|
|
27
27
|
const { mine = false } = options;
|
|
28
|
-
const roc = roc_1.useRoc();
|
|
29
|
-
const [state, dispatch] = react_1.useReducer(rocQueryReducer, {
|
|
28
|
+
const roc = (0, roc_1.useRoc)();
|
|
29
|
+
const [state, dispatch] = (0, react_1.useReducer)(rocQueryReducer, {
|
|
30
30
|
loading: true,
|
|
31
31
|
error: null,
|
|
32
32
|
result: null,
|
|
33
33
|
});
|
|
34
|
-
react_1.useEffect(() => {
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
35
|
dispatch({ type: 'LOAD' });
|
|
36
36
|
const query = roc.getQuery(viewName, { mine });
|
|
37
37
|
query
|
package/lib-cjs/types/db.d.ts
CHANGED
|
@@ -27,11 +27,12 @@ export interface TocEntry {
|
|
|
27
27
|
names: string[];
|
|
28
28
|
reference: string;
|
|
29
29
|
}
|
|
30
|
+
export declare type SampleEntryId = [string, string];
|
|
30
31
|
export interface SampleEntry {
|
|
31
32
|
_id: string;
|
|
32
33
|
_rev: string;
|
|
33
34
|
$type: 'entry';
|
|
34
|
-
$id:
|
|
35
|
+
$id: SampleEntryId;
|
|
35
36
|
$kind: 'sample';
|
|
36
37
|
$owners: string[];
|
|
37
38
|
$content: SampleEntryContent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-iframe-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"clsx": "^1.1.1",
|
|
32
32
|
"iframe-bridge": "^2.0.0",
|
|
33
33
|
"immer": "^9.0.5",
|
|
34
|
-
"rest-on-couch-client": "^
|
|
34
|
+
"rest-on-couch-client": "^4.2.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "^17.0.16",
|