@sutech_jp/datatraveler-react-client 0.0.4

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.
@@ -0,0 +1,16 @@
1
+ import { ReactElement } from 'react';
2
+ export declare type DataImportResult<D> = {
3
+ insert: D[];
4
+ update: D[];
5
+ dataImportLogId: string;
6
+ };
7
+ declare type Props<D> = {
8
+ url: string;
9
+ googleToken?: string;
10
+ onImport: (result: DataImportResult<D>) => void;
11
+ onCancel?: () => void;
12
+ currentData?: D[];
13
+ maps?: Record<string, Record<string, number>>;
14
+ };
15
+ export declare const DataTravelerImport: <D>({ url, googleToken, currentData, maps, onImport, onCancel, }: Props<D>) => ReactElement;
16
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.DataTravelerImport = void 0;
20
+ var jsx_runtime_1 = require("react/jsx-runtime");
21
+ var react_1 = require("react");
22
+ var DataTravelerImport = function (_a) {
23
+ var url = _a.url, googleToken = _a.googleToken, _b = _a.currentData, currentData = _b === void 0 ? [] : _b, _c = _a.maps, maps = _c === void 0 ? {} : _c, onImport = _a.onImport, onCancel = _a.onCancel;
24
+ var iframe = (0, react_1.useRef)(null);
25
+ var _d = __read((0, react_1.useState)(), 2), width = _d[0], setWidth = _d[1];
26
+ var _e = __read((0, react_1.useState)(), 2), height = _e[0], setHeight = _e[1];
27
+ var handleMessage = (0, react_1.useCallback)(function (e) {
28
+ var _a;
29
+ var message = e.data;
30
+ var from = message === null || message === void 0 ? void 0 : message.from;
31
+ var action = message === null || message === void 0 ? void 0 : message.action;
32
+ var payload = message === null || message === void 0 ? void 0 : message.payload;
33
+ if (from !== 'dataTraveler') {
34
+ return;
35
+ }
36
+ if (action === 'onAuthorized') {
37
+ var iframeWindow = (_a = iframe.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
38
+ if (!iframeWindow)
39
+ return;
40
+ iframeWindow.postMessage({
41
+ from: 'dataTravelerClient',
42
+ action: 'onShow',
43
+ currentData: currentData,
44
+ maps: maps,
45
+ useCancel: !!onCancel,
46
+ googleToken: googleToken,
47
+ }, '*');
48
+ }
49
+ else if (action === 'onImport') {
50
+ onImport(payload);
51
+ }
52
+ else if (action === 'onCancel') {
53
+ onCancel && onCancel();
54
+ }
55
+ else if (action === 'onPageChange') {
56
+ setWidth(message === null || message === void 0 ? void 0 : message.width);
57
+ setHeight(message === null || message === void 0 ? void 0 : message.height);
58
+ }
59
+ }, [googleToken, currentData, maps, onImport, onCancel]);
60
+ (0, react_1.useEffect)(function () {
61
+ window.addEventListener('message', handleMessage);
62
+ return function () { return window.removeEventListener('message', handleMessage); };
63
+ }, [handleMessage]);
64
+ return ((0, jsx_runtime_1.jsx)("iframe", { ref: iframe, id: "datatraveler", name: "datatraveler", frameBorder: '0', src: url, style: {
65
+ width: width || '800px',
66
+ height: height || '300px',
67
+ } }));
68
+ };
69
+ exports.DataTravelerImport = DataTravelerImport;
@@ -0,0 +1 @@
1
+ export * from './DataTravelerImport';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./DataTravelerImport"), exports);
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@sutech_jp/datatraveler-react-client",
3
+ "version": "0.0.4",
4
+ "description": "react client for data traveler produced by SuTech",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "author": "sutech",
11
+ "license": "ISC",
12
+ "scripts": {
13
+ "test": "jest",
14
+ "watch": "tsc -w",
15
+ "build": "rimraf dist&&tsc",
16
+ "prepublishOnly": "npm run build&&npm version patch",
17
+ "lint:fix": "eslint --fix \"./{src,test}/**/*.{tsx,ts,js}\" --ignore-path .gitignore",
18
+ "format": "prettier --write \"./{src,test}/**/*.{tsx,ts,js}\" --ignore-path .gitignore",
19
+ "precommit": "npm run format && npm run lint:fix"
20
+ },
21
+ "husky": {
22
+ "hooks": {
23
+ "pre-commit": "npm run precommit"
24
+ }
25
+ },
26
+ "dependencies": {},
27
+ "devDependencies": {
28
+ "@testing-library/dom": "^8.11.1",
29
+ "@testing-library/jest-dom": "^5.15.1",
30
+ "@testing-library/react": "^12.1.2",
31
+ "@testing-library/user-event": "^13.5.0",
32
+ "@types/jest": "^27.4.0",
33
+ "@types/node": "^16.9.4",
34
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
35
+ "@typescript-eslint/parser": "^4.31.2",
36
+ "eslint": "^7.32.0",
37
+ "eslint-config-prettier": "^8.3.0",
38
+ "eslint-plugin-import": "^2.24.2",
39
+ "eslint-plugin-jest-dom": "^3.9.2",
40
+ "eslint-plugin-prettier": "^4.0.0",
41
+ "eslint-plugin-react": "^7.26.1",
42
+ "eslint-plugin-react-hooks": "^4.2.0",
43
+ "eslint-plugin-testing-library": "^5.0.1",
44
+ "husky": "^4.3.8",
45
+ "jest": "^27.5.1",
46
+ "prettier": "^2.2.1",
47
+ "rimraf": "^3.0.2",
48
+ "ts-jest": "^27.0.7",
49
+ "typescript": "^4.4.3"
50
+ },
51
+ "peerDependencies": {
52
+ "@types/react": "^17.0.0 || ^18.0.0",
53
+ "react": "^17.0.0 || ^18.0.0",
54
+ "react-dom": "^17.0.0 || ^18.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "@types/react": {
58
+ "optional": true
59
+ }
60
+ }
61
+ }