@sutech_jp/raas-react-client 0.1.29 → 0.1.30
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.
|
@@ -12,7 +12,7 @@ declare type Props = {
|
|
|
12
12
|
values?: BusinessData;
|
|
13
13
|
fileName?: string;
|
|
14
14
|
options?: ComponentOptions;
|
|
15
|
-
|
|
15
|
+
validate?: (property: string, rowIndex: number | undefined, value: ItemValue, values: BusinessData) => Promise<CustomValidationResult>;
|
|
16
16
|
onChange?: (property: string, rowIndex: number | undefined, value: ItemValue, values: BusinessData) => void;
|
|
17
17
|
onGenerate?: (logId: string) => void;
|
|
18
18
|
};
|
|
@@ -1,13 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
2
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
55
|
exports.ReportWebForm = void 0;
|
|
4
56
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
57
|
var react_1 = require("react");
|
|
6
58
|
var targetOrigin_1 = require("../util/targetOrigin");
|
|
7
59
|
var ReportWebForm = function (_a) {
|
|
8
|
-
var session = _a.session, _b = _a.width, width = _b === void 0 ? '100%' : _b, _c = _a.height, height = _c === void 0 ? '100%' : _c, customStyles = _a.customStyles, title = _a.title, layoutId = _a.layoutId, values = _a.values, fileName = _a.fileName, options = _a.options,
|
|
60
|
+
var session = _a.session, _b = _a.width, width = _b === void 0 ? '100%' : _b, _c = _a.height, height = _c === void 0 ? '100%' : _c, customStyles = _a.customStyles, title = _a.title, layoutId = _a.layoutId, values = _a.values, fileName = _a.fileName, options = _a.options, validate = _a.validate, onChange = _a.onChange, onGenerate = _a.onGenerate;
|
|
61
|
+
var _d = __read((0, react_1.useState)(false), 2), initialized = _d[0], setInitialized = _d[1];
|
|
62
|
+
var prevInitialized = (0, react_1.useRef)(false);
|
|
9
63
|
var iframe = (0, react_1.useRef)(null);
|
|
10
|
-
var sendMessage = (0, react_1.useCallback)(function (action, props) {
|
|
64
|
+
var sendMessage = (0, react_1.useCallback)(function (action, props, requestId) {
|
|
11
65
|
var _a;
|
|
12
66
|
var iframeWindow = (_a = iframe.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
|
|
13
67
|
if (!iframeWindow)
|
|
@@ -16,45 +70,82 @@ var ReportWebForm = function (_a) {
|
|
|
16
70
|
from: 'webformClient',
|
|
17
71
|
action: action,
|
|
18
72
|
props: props,
|
|
73
|
+
messageId: requestId,
|
|
19
74
|
}, (0, targetOrigin_1.getTargetOrigin)(session === null || session === void 0 ? void 0 : session.newUrl));
|
|
20
75
|
}, [session === null || session === void 0 ? void 0 : session.newUrl]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
if (action === 'onAuthorized') {
|
|
32
|
-
sendMessage('onShow', {
|
|
33
|
-
customStyles: customStyles,
|
|
34
|
-
title: title,
|
|
35
|
-
layoutId: layoutId,
|
|
36
|
-
values: values,
|
|
37
|
-
fileName: fileName,
|
|
38
|
-
options: options,
|
|
39
|
-
});
|
|
76
|
+
(0, react_1.useEffect)(function () {
|
|
77
|
+
// 前回の initialized の値を取得
|
|
78
|
+
var wasInitialized = prevInitialized.current;
|
|
79
|
+
// initialized が true になった直後は、データ更新メッセージを送信する必要がないため
|
|
80
|
+
// initialized に加えて、前回の initialized(wasInitialized) を確認し、
|
|
81
|
+
// 両方が true の場合のみデータ更新メッセージを送信する
|
|
82
|
+
if (initialized && wasInitialized) {
|
|
83
|
+
// データの更新があった場合は、データを送信する
|
|
84
|
+
sendMessage('onUpdateData', values);
|
|
40
85
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
86
|
+
// 現在の initialized の値を保存
|
|
87
|
+
prevInitialized.current = initialized;
|
|
88
|
+
}, [initialized, values, sendMessage]);
|
|
89
|
+
var handleMessage = (0, react_1.useCallback)(function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
+
var message, from, action, _a, property, rowIndex, value, values_1, result, _b, property, rowIndex, value, values_2, logId;
|
|
91
|
+
return __generator(this, function (_c) {
|
|
92
|
+
switch (_c.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
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)) {
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
message = e.data;
|
|
98
|
+
from = message === null || message === void 0 ? void 0 : message.from;
|
|
99
|
+
action = message === null || message === void 0 ? void 0 : message.action;
|
|
100
|
+
if (from !== 'webform') {
|
|
101
|
+
return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
if (!(action === 'onAuthorized')) return [3 /*break*/, 1];
|
|
104
|
+
sendMessage('onShow', {
|
|
105
|
+
customStyles: customStyles,
|
|
106
|
+
title: title,
|
|
107
|
+
layoutId: layoutId,
|
|
108
|
+
values: values,
|
|
109
|
+
fileName: fileName,
|
|
110
|
+
options: options,
|
|
111
|
+
});
|
|
112
|
+
// 初期化完了状態にする
|
|
113
|
+
setInitialized(true);
|
|
114
|
+
return [3 /*break*/, 4];
|
|
115
|
+
case 1:
|
|
116
|
+
if (!(action === 'onValidate')) return [3 /*break*/, 3];
|
|
117
|
+
if (!validate) {
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
}
|
|
120
|
+
_a = message.payload, property = _a.property, rowIndex = _a.rowIndex, value = _a.value, values_1 = _a.values;
|
|
121
|
+
return [4 /*yield*/, validate(property, rowIndex, value, values_1)
|
|
122
|
+
// バリデーション結果を送信
|
|
123
|
+
];
|
|
124
|
+
case 2:
|
|
125
|
+
result = _c.sent();
|
|
126
|
+
// バリデーション結果を送信
|
|
127
|
+
sendMessage('onValidated', result, message.messageId);
|
|
128
|
+
return [3 /*break*/, 4];
|
|
129
|
+
case 3:
|
|
130
|
+
if (action === 'onChange') {
|
|
131
|
+
if (!onChange) {
|
|
132
|
+
return [2 /*return*/];
|
|
133
|
+
}
|
|
134
|
+
_b = message.payload, property = _b.property, rowIndex = _b.rowIndex, value = _b.value, values_2 = _b.values;
|
|
135
|
+
onChange(property, rowIndex, value, values_2);
|
|
136
|
+
}
|
|
137
|
+
else if (action === 'onGenerate') {
|
|
138
|
+
if (!onGenerate) {
|
|
139
|
+
return [2 /*return*/];
|
|
140
|
+
}
|
|
141
|
+
logId = message.payload;
|
|
142
|
+
onGenerate(logId);
|
|
143
|
+
}
|
|
144
|
+
_c.label = 4;
|
|
145
|
+
case 4: return [2 /*return*/];
|
|
44
146
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
sendMessage('onValidated', result);
|
|
48
|
-
}
|
|
49
|
-
else if (action === 'onChange') {
|
|
50
|
-
var _b = message.payload, property = _b.property, rowIndex = _b.rowIndex, value = _b.value, values_2 = _b.values;
|
|
51
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(property, rowIndex, value, values_2);
|
|
52
|
-
}
|
|
53
|
-
else if (action === 'onGenerate') {
|
|
54
|
-
var logId = message.payload;
|
|
55
|
-
onGenerate === null || onGenerate === void 0 ? void 0 : onGenerate(logId);
|
|
56
|
-
}
|
|
57
|
-
}, [
|
|
147
|
+
});
|
|
148
|
+
}); }, [
|
|
58
149
|
customStyles,
|
|
59
150
|
fileName,
|
|
60
151
|
layoutId,
|
|
@@ -64,7 +155,7 @@ var ReportWebForm = function (_a) {
|
|
|
64
155
|
sendMessage,
|
|
65
156
|
session === null || session === void 0 ? void 0 : session.newUrl,
|
|
66
157
|
title,
|
|
67
|
-
|
|
158
|
+
validate,
|
|
68
159
|
values,
|
|
69
160
|
]);
|
|
70
161
|
(0, react_1.useEffect)(function () {
|