@sutech_jp/datatraveler-react-client 0.0.10 → 0.0.11

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.
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { DataImportDef, DataImportParseMaps } from './types';
2
+ import { DataImportDef, Mapper } from './types';
3
3
  export declare type DataImportResult<D> = {
4
4
  insert: D[];
5
5
  update: D[];
@@ -12,7 +12,7 @@ declare type Props<D> = {
12
12
  onImport: (result: DataImportResult<D>) => void;
13
13
  onCancel?: () => void;
14
14
  currentData?: D[];
15
- maps?: DataImportParseMaps;
15
+ maps?: Mapper;
16
16
  width?: number;
17
17
  height?: number;
18
18
  };
@@ -0,0 +1,20 @@
1
+ import { ReactElement } from 'react';
2
+ import { EntitySchema, Mapper } from './types';
3
+ declare type DataImportResult<D> = {
4
+ insert: D[];
5
+ update: D[];
6
+ dataImportLogId: string;
7
+ };
8
+ declare type Props<D> = {
9
+ url: string;
10
+ entitySchemas: EntitySchema[];
11
+ googleToken?: string;
12
+ onImport: (result: DataImportResult<D>) => void;
13
+ onCancel?: () => void;
14
+ currentData?: D[];
15
+ maps?: Mapper;
16
+ width?: number;
17
+ height?: number;
18
+ };
19
+ export declare const DataTravelerImportNew: <D>({ url, entitySchemas, googleToken, currentData, maps, width, height, onImport, onCancel, }: Props<D>) => ReactElement;
20
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataTravelerImportNew = void 0;
4
+ var jsx_runtime_1 = require("react/jsx-runtime");
5
+ var react_1 = require("react");
6
+ var DataTravelerImportNew = function (_a) {
7
+ var url = _a.url, entitySchemas = _a.entitySchemas, googleToken = _a.googleToken, _b = _a.currentData, currentData = _b === void 0 ? [] : _b, _c = _a.maps, maps = _c === void 0 ? {} : _c, width = _a.width, height = _a.height, onImport = _a.onImport, onCancel = _a.onCancel;
8
+ var iframe = (0, react_1.useRef)(null);
9
+ var handleMessage = (0, react_1.useCallback)(function (e) {
10
+ var _a;
11
+ var message = e.data;
12
+ var from = message === null || message === void 0 ? void 0 : message.from;
13
+ var action = message === null || message === void 0 ? void 0 : message.action;
14
+ var payload = message === null || message === void 0 ? void 0 : message.payload;
15
+ if (from !== 'dataTraveler') {
16
+ return;
17
+ }
18
+ if (action === 'onAuthorized') {
19
+ var iframeWindow = (_a = iframe.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
20
+ if (!iframeWindow)
21
+ return;
22
+ iframeWindow.postMessage({
23
+ from: 'dataTravelerClient',
24
+ action: 'onShow',
25
+ entitySchemas: entitySchemas,
26
+ currentData: currentData,
27
+ maps: maps,
28
+ useCancel: !!onCancel,
29
+ googleToken: googleToken,
30
+ size: {
31
+ width: width,
32
+ height: height,
33
+ },
34
+ }, '*');
35
+ }
36
+ else if (action === 'onImport') {
37
+ onImport(payload);
38
+ }
39
+ else if (action === 'onCancel') {
40
+ onCancel && onCancel();
41
+ }
42
+ }, [entitySchemas, currentData, maps, onCancel, googleToken, width, height, onImport]);
43
+ (0, react_1.useEffect)(function () {
44
+ window.addEventListener('message', handleMessage);
45
+ return function () { return window.removeEventListener('message', handleMessage); };
46
+ }, [handleMessage]);
47
+ return ((0, jsx_runtime_1.jsx)("iframe", { ref: iframe, id: "datatraveler", name: "datatraveler", frameBorder: '0', src: url, style: {
48
+ width: width !== undefined ? "".concat(width, "px") : '100vw',
49
+ height: height !== undefined ? "".concat(height, "px") : '100vh',
50
+ } }));
51
+ };
52
+ exports.DataTravelerImportNew = DataTravelerImportNew;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './DataTravelerImport';
2
+ export * from './DataTravelerImportNew';
2
3
  export * from './types';
package/dist/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./DataTravelerImport"), exports);
18
+ __exportStar(require("./DataTravelerImportNew"), exports);
18
19
  __exportStar(require("./types"), exports);
package/dist/types.d.ts CHANGED
@@ -33,4 +33,38 @@ export declare type RecordMessage<LVL extends 'error' | 'warning' | 'info'> = {
33
33
  level: LVL;
34
34
  message: string;
35
35
  };
36
- export declare type DataImportParseMaps = Record<string, Record<string, number>>;
36
+ export declare type EntitySchema = {
37
+ property: string;
38
+ } & (TextEntitySchema | NumberEntitySchema | DateEntitySchema | ArrayEntitySchema | ObjectEntitySchema | OriginalEntitySchema);
39
+ declare type ValueEntitySchema<T> = {
40
+ key?: boolean;
41
+ mapping?: {
42
+ name: string;
43
+ };
44
+ default?: T;
45
+ notNull?: boolean;
46
+ allow?: T[];
47
+ ignoreUpdate?: T[];
48
+ };
49
+ declare type TextEntitySchema = {
50
+ type: 'text';
51
+ } & ValueEntitySchema<string>;
52
+ declare type NumberEntitySchema = {
53
+ type: 'number';
54
+ } & ValueEntitySchema<number>;
55
+ declare type DateEntitySchema = {
56
+ type: 'date';
57
+ } & ValueEntitySchema<Date>;
58
+ declare type ArrayEntitySchema = {
59
+ type: 'array';
60
+ children: EntitySchema[];
61
+ };
62
+ declare type ObjectEntitySchema = {
63
+ type: 'object';
64
+ children: EntitySchema[];
65
+ };
66
+ declare type OriginalEntitySchema = {
67
+ type: 'original';
68
+ };
69
+ export declare type Mapper = Record<string, Record<string, string | number>>;
70
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sutech_jp/datatraveler-react-client",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "react client for data traveler produced by SuTech",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",