@sutech_jp/datatraveler-react-client 0.0.28 → 0.1.22

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,21 +1,103 @@
1
- import { ReactElement } from 'react';
2
- import { Binder, DataTravelerResult, Mapper, ImportType, UseReportType, Session } from './types';
1
+ import { VFC } from 'react';
2
+ import { Binder, DataTravelerResult, Mapper, ImportType, UseReportType, Session, MasterType, MasterSyncedStatus, ExtensionSchemaDef, WorkMemoDef, MapperDef } from './types';
3
3
  import { ThemeOptions } from './types/theme';
4
- declare type Props<D> = {
4
+ /**
5
+ * データトラベラーコンポーネントのプロパティ
6
+ */
7
+ declare type Props = {
8
+ /** Raasを組み込むアプリケーション名 */
5
9
  application: string;
10
+ /** 帳票のスキーマ名 */
6
11
  schema: string;
12
+ /**
13
+ * セッション情報
14
+ * バックエンドに用意したcreateSession APIにて発行したSessionオブジェクトを渡す
15
+ */
7
16
  session: Session | undefined;
17
+ /** @ignore */
8
18
  googleToken?: string;
19
+ /**
20
+ * 帳票発行ボタン押下後に実行されるコールバック関数
21
+ * resultに含まれるdataImportLogIdを保存する処理を実装する想定の関数
22
+ */
9
23
  onImport: (result: DataTravelerResult) => void;
24
+ /**
25
+ * コンポーネント初期化完了時に実行されるコールバック関数
26
+ */
27
+ onInitialized?: () => void;
28
+ /**
29
+ * キャンセルボタン押下時に実行されるコールバック関数
30
+ * 任意の画面への遷移処理を実装する想定の関数
31
+ */
10
32
  onCancel?: () => void;
33
+ /**
34
+ * 操作中状態の変化時に実行されるコールバック関数
35
+ *
36
+ * CSVをアップロードするとoperating=trueとして実行され、帳票作成が開始されるとoperating=falseとして実行される。
37
+ * 操作中の画面遷移やブラウザリロード時に確認ダイアログを表示するのに利用する想定。
38
+ */
39
+ onChangeOperating?: (operating: boolean) => void;
40
+ /** @ignore */
11
41
  importType?: ImportType;
12
- currentData?: D[];
42
+ /** @ignore */
43
+ currentData?: Record<string, any>[];
44
+ /**
45
+ * マスタの同期方法
46
+ *
47
+ * { type: 'direct' } : コンポーネントの引数で直接渡す方式
48
+ * { type: 'sync' } : バックエンドを経由し同期する方式
49
+ *
50
+ * { partners : { type : 'sync'} } のように指定する
51
+ */
52
+ masterType?: MasterType;
53
+ /**
54
+ * マスタの同期ステータス
55
+ * 同期方法がsyncの場合に、同期ステータスを指定する
56
+ */
57
+ masterSyncedStatus?: MasterSyncedStatus;
58
+ /**
59
+ * マッピング形式のマスタ
60
+ * 取引先マスタのようなマッピング形式のマスタを指定する
61
+ */
13
62
  mapper?: Mapper;
63
+ /**
64
+ * バインド形式のマスタ
65
+ * 自社情報マスタのようなバインド形式のマスタを指定する
66
+ */
14
67
  binder?: Binder;
68
+ /**
69
+ * マッピング形式の定義
70
+ * マッピング形式の定義を指定する
71
+ */
72
+ mapperDefs?: Array<MapperDef>;
73
+ /**
74
+ * バインド形式の定義
75
+ * バインド形式の定義を指定する
76
+ */
77
+ binderDefs?: Array<MapperDef>;
78
+ /** コンポーネントの幅 */
15
79
  width?: number;
80
+ /** コンポーネントの高さ */
16
81
  height?: number;
82
+ /** カスタムスタイル */
17
83
  customStyles?: ThemeOptions;
84
+ /**
85
+ * 帳票発行機能の利用方法
86
+ *
87
+ * データトラベラーコンポーネントは本来データの変換を主軸としてコンポーネントだが、
88
+ * 本引数を指定することで帳票発行機能とシームレスに連携し、帳票発行まで行うことができるようになる。
89
+ */
18
90
  report?: UseReportType;
91
+ /** @ignore 拡張スキーマの定義(オプション) */
92
+ extensionSchemaDef?: ExtensionSchemaDef;
93
+ /** 作業メモの定義 */
94
+ workMemoDef?: WorkMemoDef;
19
95
  };
20
- export declare const DataTravelerImport: <D>({ application, schema, session, googleToken, importType, currentData, mapper, binder, width, height, customStyles, report, onImport, onCancel, }: Props<D>) => ReactElement;
96
+ /**
97
+ * データトラベラーコンポーネント
98
+ *
99
+ * CSVインポート画面用のコンポーネントです。
100
+ * 本コンポーネントにより、CSVアップロード〜帳票発行までの一連の画面を組み込むことが可能となります。
101
+ */
102
+ export declare const DataTravelerImport: VFC<Props>;
21
103
  export {};
@@ -1,12 +1,35 @@
1
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
+ };
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
3
19
  exports.DataTravelerImport = void 0;
4
20
  var jsx_runtime_1 = require("react/jsx-runtime");
5
21
  var react_1 = require("react");
6
22
  var targetOrigin_1 = require("./util/targetOrigin");
23
+ /**
24
+ * データトラベラーコンポーネント
25
+ *
26
+ * CSVインポート画面用のコンポーネントです。
27
+ * 本コンポーネントにより、CSVアップロード〜帳票発行までの一連の画面を組み込むことが可能となります。
28
+ */
7
29
  var DataTravelerImport = function (_a) {
8
- var application = _a.application, schema = _a.schema, session = _a.session, googleToken = _a.googleToken, _b = _a.importType, importType = _b === void 0 ? googleToken ? 'gss' : 'csv' : _b, _c = _a.currentData, currentData = _c === void 0 ? [] : _c, _d = _a.mapper, mapper = _d === void 0 ? {} : _d, _e = _a.binder, binder = _e === void 0 ? {} : _e, width = _a.width, height = _a.height, customStyles = _a.customStyles, report = _a.report, onImport = _a.onImport, onCancel = _a.onCancel;
30
+ var application = _a.application, schema = _a.schema, session = _a.session, googleToken = _a.googleToken, _b = _a.importType, importType = _b === void 0 ? googleToken ? 'gss' : 'csv' : _b, _c = _a.currentData, currentData = _c === void 0 ? [] : _c, masterType = _a.masterType, masterSyncedStatus = _a.masterSyncedStatus, _d = _a.mapper, mapper = _d === void 0 ? {} : _d, _e = _a.binder, binder = _e === void 0 ? {} : _e, mapperDefs = _a.mapperDefs, binderDefs = _a.binderDefs, width = _a.width, height = _a.height, customStyles = _a.customStyles, report = _a.report, extensionSchemaDef = _a.extensionSchemaDef, workMemoDef = _a.workMemoDef, onImport = _a.onImport, onInitialized = _a.onInitialized, onCancel = _a.onCancel, onChangeOperating = _a.onChangeOperating;
9
31
  var iframe = (0, react_1.useRef)(null);
32
+ var _f = __read((0, react_1.useState)('initializing'), 2), iframeState = _f[0], setIframeState = _f[1];
10
33
  var handleMessage = (0, react_1.useCallback)(function (e) {
11
34
  var _a;
12
35
  if ((0, targetOrigin_1.getTargetOrigin)(session === null || session === void 0 ? void 0 : session.newUrl) !== '*' && e.origin !== (0, targetOrigin_1.getTargetOrigin)(session === null || session === void 0 ? void 0 : session.newUrl)) {
@@ -19,7 +42,12 @@ var DataTravelerImport = function (_a) {
19
42
  if (from !== 'dataTraveler') {
20
43
  return;
21
44
  }
22
- if (action === 'onAuthorized') {
45
+ if (action === 'onInitialized') {
46
+ setIframeState('initialized');
47
+ onInitialized && onInitialized();
48
+ }
49
+ else if (action === 'onAuthorized') {
50
+ setIframeState('prepared');
23
51
  var iframeWindow = (_a = iframe.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
24
52
  if (!iframeWindow)
25
53
  return;
@@ -30,9 +58,14 @@ var DataTravelerImport = function (_a) {
30
58
  application: application,
31
59
  schema: schema,
32
60
  currentData: currentData,
61
+ masterType: masterType,
62
+ masterSyncedStatus: masterSyncedStatus,
33
63
  mapper: mapper,
34
64
  binder: binder,
65
+ mapperDefs: mapperDefs,
66
+ binderDefs: binderDefs,
35
67
  useCancel: !!onCancel,
68
+ useChangeOperating: !!onChangeOperating,
36
69
  googleToken: googleToken,
37
70
  size: {
38
71
  width: width,
@@ -40,6 +73,8 @@ var DataTravelerImport = function (_a) {
40
73
  },
41
74
  customStyles: customStyles,
42
75
  report: report,
76
+ extensionSchemaDef: extensionSchemaDef,
77
+ workMemoDef: workMemoDef,
43
78
  }, (0, targetOrigin_1.getTargetOrigin)(session === null || session === void 0 ? void 0 : session.newUrl));
44
79
  }
45
80
  else if (action === 'onImport') {
@@ -48,22 +83,53 @@ var DataTravelerImport = function (_a) {
48
83
  else if (action === 'onCancel') {
49
84
  onCancel && onCancel();
50
85
  }
86
+ else if (action === 'onChangeOperating') {
87
+ onChangeOperating && onChangeOperating(message.operating);
88
+ }
51
89
  }, [
52
90
  importType,
53
91
  application,
54
92
  schema,
55
93
  currentData,
94
+ masterType,
95
+ masterSyncedStatus,
56
96
  mapper,
57
97
  binder,
58
- onCancel,
98
+ mapperDefs,
99
+ binderDefs,
59
100
  googleToken,
60
101
  width,
61
102
  height,
62
103
  customStyles,
63
104
  report,
105
+ extensionSchemaDef,
106
+ workMemoDef,
64
107
  session,
65
108
  onImport,
109
+ onInitialized,
110
+ onCancel,
111
+ onChangeOperating,
66
112
  ]);
113
+ (0, react_1.useEffect)(function () {
114
+ var _a;
115
+ if (masterSyncedStatus === undefined)
116
+ return;
117
+ if (iframeState === 'initializing')
118
+ return;
119
+ if (iframeState === 'initialized')
120
+ return;
121
+ if (masterSyncedStatus) {
122
+ console.log('postMessage#onMasterSynced');
123
+ var iframeWindow = (_a = iframe.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
124
+ if (!iframeWindow)
125
+ return;
126
+ iframeWindow.postMessage({
127
+ from: 'dataTravelerClient',
128
+ action: 'onMasterSynced',
129
+ masterSyncedStatus: masterSyncedStatus,
130
+ }, (0, targetOrigin_1.getTargetOrigin)(session === null || session === void 0 ? void 0 : session.newUrl));
131
+ }
132
+ }, [masterSyncedStatus, iframeState, session]);
67
133
  (0, react_1.useEffect)(function () {
68
134
  window.addEventListener('message', handleMessage);
69
135
  return function () { return window.removeEventListener('message', handleMessage); };
@@ -72,6 +138,7 @@ var DataTravelerImport = function (_a) {
72
138
  width: width !== undefined ? "".concat(width, "px") : '100%',
73
139
  height: height !== undefined ? "".concat(height, "px") : '100%',
74
140
  border: 0,
141
+ display: iframeState === 'initializing' ? 'none' : undefined,
75
142
  } }));
76
143
  };
77
144
  exports.DataTravelerImport = DataTravelerImport;
@@ -1,5 +1,24 @@
1
1
  export declare type Mapper = Record<string, Record<string, any>[]>;
2
2
  export declare type Binder = Record<string, Record<string, any>>;
3
+ export declare type MapperDef = {
4
+ name: string;
5
+ caption: string;
6
+ values: MapperValue[];
7
+ checkDuplication?: boolean;
8
+ };
9
+ declare type MapperValue = {
10
+ caption: string;
11
+ path: string;
12
+ matcher?: boolean;
13
+ };
14
+ export declare type MasterType = Record<string, MasterTypeDirect | MasterTypeSync>;
15
+ declare type MasterTypeDirect = {
16
+ type: 'direct';
17
+ };
18
+ declare type MasterTypeSync = {
19
+ type: 'sync';
20
+ };
21
+ export declare type MasterSyncedStatus = 'ongoing' | 'error' | 'finished';
3
22
  export declare type DataTravelerResult = {
4
23
  dataImportLogId: string;
5
24
  };
@@ -17,3 +36,21 @@ export declare type Session = {
17
36
  url: string;
18
37
  newUrl: string;
19
38
  };
39
+ export declare type ExtensionSchemaDef = {
40
+ container?: {
41
+ property: string;
42
+ caption: string;
43
+ };
44
+ properties: {
45
+ type: 'text' | 'number' | 'date' | 'datetime' | 'boolean';
46
+ property: string;
47
+ caption: string;
48
+ notNull?: boolean;
49
+ }[];
50
+ };
51
+ export declare type WorkMemoDef = {
52
+ use: boolean;
53
+ caption?: string;
54
+ description?: string;
55
+ };
56
+ export { ThemeOptions, PaletteOptions, TypographyOptions, ColorOptions, Grayscale, TypographyVariants } from './theme';
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@sutech_jp/datatraveler-react-client",
3
- "version": "0.0.28",
3
+ "version": "0.1.22",
4
4
  "description": "react client for data traveler produced by SuTech",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/",
8
9
  "access": "public"
9
10
  },
10
11
  "author": "sutech",
@@ -13,17 +14,17 @@
13
14
  "test": "jest",
14
15
  "watch": "tsc -w",
15
16
  "build": "rimraf dist&&tsc",
16
- "prepublishOnly": "npm run build&&npm version patch",
17
+ "prepublishOnly": "npm run build",
17
18
  "lint:fix": "eslint --fix \"./{src,test}/**/*.{tsx,ts,js}\" --ignore-path .gitignore",
18
19
  "format": "prettier --write \"./{src,test}/**/*.{tsx,ts,js}\" --ignore-path .gitignore",
19
- "precommit": "npm run format && npm run lint:fix"
20
+ "precommit": "npm run format && npm run lint:fix",
21
+ "doc": "npx typedoc src/index.ts --out dist/docs --name \"Raas : datatraveler-react-client\" --customFooterHtml \"©Copyright 2024 SuTech Co., Ltd. All Rights Reserved\" --plugin typedoc-plugin-missing-exports --excludeExternals --placeInternalsInOwningModule --sort kind --sort source-order --includeVersion"
20
22
  },
21
23
  "husky": {
22
24
  "hooks": {
23
25
  "pre-commit": "npm run precommit"
24
26
  }
25
27
  },
26
- "dependencies": {},
27
28
  "devDependencies": {
28
29
  "@testing-library/dom": "^8.11.1",
29
30
  "@testing-library/jest-dom": "^5.15.1",
@@ -46,6 +47,8 @@
46
47
  "prettier": "^2.2.1",
47
48
  "rimraf": "^3.0.2",
48
49
  "ts-jest": "^27.0.7",
50
+ "typedoc": "^0.26.10",
51
+ "typedoc-plugin-missing-exports": "^3.0.0",
49
52
  "typescript": "^4.4.3"
50
53
  },
51
54
  "peerDependencies": {