@kissflow/lowcode-client-sdk 1.0.1 → 1.0.2-1.beta.1
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/README.md +392 -95
- package/dist/index.d.ts +263 -76
- package/dist/kf.lowcodeworkersdk.es.js +665 -0
- package/dist/kf.nocodeworkersdk.es.js +455 -0
- package/dist/kfsdk.es.js +483 -0
- package/dist/kfsdk.umd.js +1 -0
- package/dist/lowcode.d.ts +319 -0
- package/dist/lowcode.types.d.ts +106 -0
- package/dist/nocode.d.ts +316 -0
- package/dist/nocode.types.d.ts +65 -0
- package/dist/snippets.json +193 -0
- package/dist/worker.js +40 -0
- package/package.json +44 -39
- package/custom.build.js +0 -79
- package/dist/app.js +0 -48
- package/dist/base.js +0 -171
- package/dist/client.js +0 -44
- package/dist/component.js +0 -35
- package/dist/constants.js +0 -40
- package/dist/form.js +0 -44
- package/dist/formatter.js +0 -54
- package/dist/global.types.d.ts +0 -54
- package/dist/index.html +0 -23
- package/dist/index.js +0 -7
- package/dist/kflowcode.sdk.js +0 -822
- package/dist/kflowcode.sdk.js.map +0 -1
- package/dist/kflowcode.sdk.module.js +0 -808
- package/dist/kflowcode.sdk.module.js.map +0 -1
- package/dist/lowcode.sdk.js +0 -56
- package/dist/page.js +0 -62
- package/id +0 -55
- package/index.html +0 -23
- package/src/app.ts +0 -31
- package/src/base.ts +0 -109
- package/src/client.ts +0 -28
- package/src/component.ts +0 -15
- package/src/constants.ts +0 -45
- package/src/form.ts +0 -21
- package/src/formatter.ts +0 -35
- package/src/index.ts +0 -7
- package/src/lowcode.sdk.ts +0 -41
- package/src/page.ts +0 -51
- package/test/lcnc-handler.js +0 -45
- package/test/mock/api.js +0 -16
- package/test/mock/id.js +0 -55
- package/tsconfig.json +0 -7
- package/tsconfig.types.json +0 -18
- package/webpack.config.js +0 -63
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2
|
+
if (!member.has(obj))
|
|
3
|
+
throw TypeError("Cannot " + msg);
|
|
4
|
+
};
|
|
5
|
+
var __privateGet = (obj, member, getter) => {
|
|
6
|
+
__accessCheck(obj, member, "read from private field");
|
|
7
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
+
};
|
|
9
|
+
var __privateAdd = (obj, member, value) => {
|
|
10
|
+
if (member.has(obj))
|
|
11
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
+
};
|
|
14
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
+
__accessCheck(obj, member, "write to private field");
|
|
16
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
var __privateMethod = (obj, member, method) => {
|
|
20
|
+
__accessCheck(obj, member, "access private method");
|
|
21
|
+
return method;
|
|
22
|
+
};
|
|
23
|
+
var _listeners, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
|
|
24
|
+
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
25
|
+
byte &= 63;
|
|
26
|
+
if (byte < 36) {
|
|
27
|
+
id += byte.toString(36);
|
|
28
|
+
} else if (byte < 62) {
|
|
29
|
+
id += (byte - 26).toString(36).toUpperCase();
|
|
30
|
+
} else if (byte > 62) {
|
|
31
|
+
id += "-";
|
|
32
|
+
} else {
|
|
33
|
+
id += "_";
|
|
34
|
+
}
|
|
35
|
+
return id;
|
|
36
|
+
}, "");
|
|
37
|
+
const LISTENER_CMDS = {
|
|
38
|
+
API: "API",
|
|
39
|
+
GET_CONTEXT: "GET_CONTEXT",
|
|
40
|
+
RETURN: "RETURN",
|
|
41
|
+
GET_FORM_FIELD: "GET_FORM_FIELD",
|
|
42
|
+
UPDATE_FORM: "UPDATE_FORM",
|
|
43
|
+
GET_TABLE: "GET_TABLE",
|
|
44
|
+
GET_TABLE_ROW: "GET_TABLE_ROW",
|
|
45
|
+
ADD_TABLE_ROW: "ADD_TABLE_ROW",
|
|
46
|
+
ADD_TABLE_ROWS: "ADD_TABLE_ROWS",
|
|
47
|
+
DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
|
|
48
|
+
TO_JSON: "TO_JSON",
|
|
49
|
+
GET_TABLE_ROWS: "GET_TABLE_ROWS",
|
|
50
|
+
MESSAGE: "MESSAGE",
|
|
51
|
+
CONFIRM: "CONFIRM",
|
|
52
|
+
ALERT: "ALERT",
|
|
53
|
+
REDIRECT: "REDIRECT",
|
|
54
|
+
OPEN_PAGE: "OPEN_PAGE",
|
|
55
|
+
FORMAT_DATE: "FORMAT_DATE",
|
|
56
|
+
FORMAT_DATE_TIME: "FORMAT_DATE_TIME",
|
|
57
|
+
FORMAT_NUMBER: "FORMAT_NUMBER",
|
|
58
|
+
FORMAT_CURRENCY: "FORMAT_CURRENCY",
|
|
59
|
+
FORMAT_BOOLEAN: "FORMAT_BOOLEAN",
|
|
60
|
+
GET_APP_VARIABLE: "GET_APP_VARIABLE",
|
|
61
|
+
SET_APP_VARIABLE: "SET_APP_VARIABLE",
|
|
62
|
+
GET_PAGE_VARIABLE: "GET_PAGE_VARIABLE",
|
|
63
|
+
SET_PAGE_VARIABLE: "SET_PAGE_VARIABLE",
|
|
64
|
+
GET_PAGE_PARAMS: "GET_PAGE_PARAMS",
|
|
65
|
+
GET_ALL_PAGE_PARAMS: "GET_ALL_PAGE_PARAMS",
|
|
66
|
+
PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
|
|
67
|
+
OPEN_POPUP: "OPEN_POPUP",
|
|
68
|
+
GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
|
|
69
|
+
GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
|
|
70
|
+
CLOSE_POPUP: "CLOSE_POPUP",
|
|
71
|
+
COMPONENT_GET: "COMPONENT_GET",
|
|
72
|
+
COMPONENT_REFRESH: "COMPONENT_REFRESH",
|
|
73
|
+
COMPONENT_SHOW: "COMPONENT_SHOW",
|
|
74
|
+
COMPONENT_HIDE: "COMPONENT_HIDE",
|
|
75
|
+
COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
|
|
76
|
+
CC_INITIALIZE: "CC_INITIALIZE",
|
|
77
|
+
CC_WATCH_PARAMS: "CC_WATCH_PARAMS",
|
|
78
|
+
WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
|
|
79
|
+
WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
|
|
80
|
+
WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
|
|
81
|
+
WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
|
|
82
|
+
WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
|
|
83
|
+
WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN",
|
|
84
|
+
DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
|
|
85
|
+
DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV"
|
|
86
|
+
};
|
|
87
|
+
const EVENT_TYPES = {
|
|
88
|
+
COMPONENT_ON_MOUNT: "componentOnMount",
|
|
89
|
+
CC_ON_PARAMS_CHANGE: "onCustomComponentParamsChange"
|
|
90
|
+
};
|
|
91
|
+
const DEFAULTS = {
|
|
92
|
+
POPUP_ID: "ACTIVE_POP_UP"
|
|
93
|
+
};
|
|
94
|
+
function generateId(prefix = "lcncsdk") {
|
|
95
|
+
return `${prefix}-${nanoid()}`;
|
|
96
|
+
}
|
|
97
|
+
const globalInstances = {};
|
|
98
|
+
function postMessage(args) {
|
|
99
|
+
if (globalThis.parent && globalThis.parent !== globalThis) {
|
|
100
|
+
globalThis.parent.postMessage(args, "*");
|
|
101
|
+
} else {
|
|
102
|
+
globalThis.postMessage(args);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function onMessage(event) {
|
|
106
|
+
if (event.origin !== globalThis.location.origin) {
|
|
107
|
+
const data = event.data;
|
|
108
|
+
if (data == null ? void 0 : data.isEvent) {
|
|
109
|
+
const { target, eventParams, eventName, eventConfig = {} } = data;
|
|
110
|
+
let targetInstance = globalInstances[target];
|
|
111
|
+
targetInstance._dispatchEvent(eventName, eventParams);
|
|
112
|
+
if (eventConfig.once) {
|
|
113
|
+
targetInstance._removeEventListener(eventName);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let { _req: req, resp } = data;
|
|
118
|
+
if (req == null ? void 0 : req._id) {
|
|
119
|
+
let targetInstance = globalInstances[req._id];
|
|
120
|
+
targetInstance._dispatchMessageEvents(req, resp);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
globalThis.addEventListener("message", onMessage);
|
|
125
|
+
class EventBase {
|
|
126
|
+
constructor() {
|
|
127
|
+
__privateAdd(this, _listeners, void 0);
|
|
128
|
+
__privateSet(this, _listeners, {});
|
|
129
|
+
}
|
|
130
|
+
_addEventListener(eventName, callBack) {
|
|
131
|
+
var _a;
|
|
132
|
+
__privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
|
|
133
|
+
__privateGet(this, _listeners)[eventName].push(callBack);
|
|
134
|
+
}
|
|
135
|
+
_removeEventListener(eventName, callBack) {
|
|
136
|
+
if (callBack) {
|
|
137
|
+
let index = __privateGet(this, _listeners)[eventName].findIndex(callBack);
|
|
138
|
+
index > -1 && __privateGet(this, _listeners)[eventName].splice(index, 1);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
|
|
142
|
+
}
|
|
143
|
+
_dispatchEvent(eventName, eventParams) {
|
|
144
|
+
if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
|
|
145
|
+
__privateGet(this, _listeners)[eventName].forEach(
|
|
146
|
+
(callBack) => callBack(eventParams)
|
|
147
|
+
);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
_dispatchMessageEvents(req, resp) {
|
|
153
|
+
let target = req._id;
|
|
154
|
+
if (Array.isArray(__privateGet(this, _listeners)[target])) {
|
|
155
|
+
__privateGet(this, _listeners)[target].forEach((listener) => {
|
|
156
|
+
try {
|
|
157
|
+
if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
|
|
158
|
+
listener(Object.values(resp)[0]);
|
|
159
|
+
} else {
|
|
160
|
+
listener(resp);
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
console.error("Message callback error: ", err);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
this._removeEventListener(target);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
_listeners = new WeakMap();
|
|
171
|
+
class BaseSDK extends EventBase {
|
|
172
|
+
_postMessageAsync(command, args, hasCallBack, callBack) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
const _id = generateId(command.toLowerCase());
|
|
175
|
+
postMessage({ _id, command, ...args });
|
|
176
|
+
globalInstances[_id] = this;
|
|
177
|
+
this._addEventListener(_id, async (data) => {
|
|
178
|
+
if (data == null ? void 0 : data.errorMessage) {
|
|
179
|
+
reject(data);
|
|
180
|
+
} else {
|
|
181
|
+
if (hasCallBack && callBack) {
|
|
182
|
+
data = await callBack(data);
|
|
183
|
+
}
|
|
184
|
+
resolve(data);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
_postMessage(command, args, callBack) {
|
|
190
|
+
const _id = generateId(command.toLowerCase());
|
|
191
|
+
postMessage({ _id, command, ...args });
|
|
192
|
+
if (callBack) {
|
|
193
|
+
this._addEventListener(args.eventName, callBack);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
class Form extends BaseSDK {
|
|
198
|
+
constructor(instanceId) {
|
|
199
|
+
super();
|
|
200
|
+
this.type = "Form";
|
|
201
|
+
this.instanceId = instanceId;
|
|
202
|
+
}
|
|
203
|
+
toJSON() {
|
|
204
|
+
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
205
|
+
instanceId: this.instanceId
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
getField(fieldId) {
|
|
209
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
|
|
210
|
+
instanceId: this.instanceId,
|
|
211
|
+
fieldId
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
updateField(args) {
|
|
215
|
+
return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
|
|
216
|
+
data: args
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
getTable(tableId) {
|
|
220
|
+
return new Table(this.instanceId, tableId);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
class Table extends BaseSDK {
|
|
224
|
+
constructor(instanceId, tableId) {
|
|
225
|
+
super();
|
|
226
|
+
this.tableId = tableId;
|
|
227
|
+
this.instanceId = instanceId;
|
|
228
|
+
}
|
|
229
|
+
toJSON() {
|
|
230
|
+
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
231
|
+
tableId: this.tableId
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
getRows() {
|
|
235
|
+
return this._postMessageAsync(
|
|
236
|
+
LISTENER_CMDS.GET_TABLE_ROWS,
|
|
237
|
+
{ tableId: this.tableId },
|
|
238
|
+
true,
|
|
239
|
+
(data) => {
|
|
240
|
+
return data.map(
|
|
241
|
+
(row) => new TableForm(this.instanceId, this.tableId, row.id)
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
getRow(rowId) {
|
|
247
|
+
return new TableForm(this.instanceId, this.tableId, rowId);
|
|
248
|
+
}
|
|
249
|
+
addRow(rowObject) {
|
|
250
|
+
return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROW, {
|
|
251
|
+
tableId: this.tableId,
|
|
252
|
+
rowObject
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
addRows(rows) {
|
|
256
|
+
return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROWS, {
|
|
257
|
+
tableId: this.tableId,
|
|
258
|
+
rows
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
deleteRow(rowId) {
|
|
262
|
+
return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
|
|
263
|
+
tableId: this.tableId,
|
|
264
|
+
rows: [rowId]
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
deleteRows(rows) {
|
|
268
|
+
return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
|
|
269
|
+
tableId: this.tableId,
|
|
270
|
+
rows
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
class TableForm extends BaseSDK {
|
|
275
|
+
constructor(instanceId, tableId, rowId) {
|
|
276
|
+
super();
|
|
277
|
+
this.instanceId = instanceId;
|
|
278
|
+
this.type = "TabelForm";
|
|
279
|
+
this.tableId = tableId;
|
|
280
|
+
this.rowId = rowId;
|
|
281
|
+
}
|
|
282
|
+
getParent() {
|
|
283
|
+
return new Form(this.instanceId);
|
|
284
|
+
}
|
|
285
|
+
toJSON() {
|
|
286
|
+
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
287
|
+
tableId: this.tableId,
|
|
288
|
+
rowId: this.rowId
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
getField(fieldId) {
|
|
292
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
|
|
293
|
+
instanceId: this.instanceId,
|
|
294
|
+
tableId: this.tableId,
|
|
295
|
+
rowId: this.rowId,
|
|
296
|
+
fieldId
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
updateField(args) {
|
|
300
|
+
return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
|
|
301
|
+
instanceId: this.instanceId,
|
|
302
|
+
tableId: this.tableId,
|
|
303
|
+
rowId: this.rowId,
|
|
304
|
+
data: args
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
class Client extends BaseSDK {
|
|
309
|
+
showInfo(message) {
|
|
310
|
+
return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
|
|
311
|
+
}
|
|
312
|
+
showConfirm(args) {
|
|
313
|
+
return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
|
|
314
|
+
data: {
|
|
315
|
+
title: args.title,
|
|
316
|
+
content: args.content,
|
|
317
|
+
okText: args.okText || "Ok",
|
|
318
|
+
cancelText: args.cancelText || "Cancel"
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
redirect(url) {
|
|
323
|
+
return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
class Formatter extends BaseSDK {
|
|
327
|
+
toDate(date) {
|
|
328
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
|
|
329
|
+
date
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
toDateTime(date) {
|
|
333
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
|
|
334
|
+
date
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
toNumber(value) {
|
|
338
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
|
|
339
|
+
value
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
toCurrency(value, currencyCode) {
|
|
343
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
|
|
344
|
+
value,
|
|
345
|
+
currencyCode
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
toBoolean(value) {
|
|
349
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
|
|
350
|
+
value
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
class Component extends BaseSDK {
|
|
355
|
+
constructor(props) {
|
|
356
|
+
super();
|
|
357
|
+
__privateAdd(this, _registerComponentAPIs);
|
|
358
|
+
this._id = props.componentId;
|
|
359
|
+
this.type = "Component";
|
|
360
|
+
globalInstances[this._id] = this;
|
|
361
|
+
__privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
|
|
362
|
+
}
|
|
363
|
+
onMount(callback) {
|
|
364
|
+
this._postMessage(
|
|
365
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
366
|
+
{
|
|
367
|
+
id: this._id,
|
|
368
|
+
eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
|
|
369
|
+
eventConfig: {
|
|
370
|
+
once: true
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
callback
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
refresh() {
|
|
377
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
|
|
378
|
+
id: this._id
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
show() {
|
|
382
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_SHOW, {
|
|
383
|
+
id: this._id
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
hide() {
|
|
387
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_HIDE, {
|
|
388
|
+
id: this._id
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
_registerComponentAPIs = new WeakSet();
|
|
393
|
+
registerComponentAPIs_fn = function(componentAPIs) {
|
|
394
|
+
componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
|
|
395
|
+
this[Api.name] = (...args) => {
|
|
396
|
+
if (Api.type === "method") {
|
|
397
|
+
return this._postMessageAsync(`COMPONENT_${Api.name}`, {
|
|
398
|
+
id: this._id,
|
|
399
|
+
parameters: args
|
|
400
|
+
});
|
|
401
|
+
} else if (Api.type === "event") {
|
|
402
|
+
this._postMessage(
|
|
403
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
404
|
+
{
|
|
405
|
+
id: this._id,
|
|
406
|
+
eventName: Api.name,
|
|
407
|
+
eventConfig: args[1]
|
|
408
|
+
},
|
|
409
|
+
args[0]
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
class Popup extends BaseSDK {
|
|
416
|
+
constructor(props) {
|
|
417
|
+
super();
|
|
418
|
+
this.type = "Popup";
|
|
419
|
+
this._id = props.popupId || DEFAULTS.POPUP_ID;
|
|
420
|
+
}
|
|
421
|
+
getParameter(key) {
|
|
422
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_POPUP_PARAMS, {
|
|
423
|
+
key,
|
|
424
|
+
popupId: this._id
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
getAllParameters() {
|
|
428
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_POPUP_PARAMS, {
|
|
429
|
+
popupId: this._id
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
close() {
|
|
433
|
+
return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
|
|
434
|
+
}
|
|
435
|
+
getComponent(componentId) {
|
|
436
|
+
return this._postMessageAsync(
|
|
437
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
438
|
+
{ componentId },
|
|
439
|
+
true,
|
|
440
|
+
(data) => {
|
|
441
|
+
return new Component(data);
|
|
442
|
+
}
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
class Page extends BaseSDK {
|
|
447
|
+
constructor(props) {
|
|
448
|
+
super();
|
|
449
|
+
this.type = "Page";
|
|
450
|
+
this.popup = new Popup({});
|
|
451
|
+
this._id = props.pageId;
|
|
452
|
+
}
|
|
453
|
+
getParameter(key) {
|
|
454
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
|
|
455
|
+
key
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
getAllParameters() {
|
|
459
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_PAGE_PARAMS, {
|
|
460
|
+
pageId: this._id
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
getVariable(key) {
|
|
464
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_VARIABLE, {
|
|
465
|
+
key
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
setVariable(key, value) {
|
|
469
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_PAGE_VARIABLE, {
|
|
470
|
+
key,
|
|
471
|
+
value
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
openPopup(popupId, popupParams) {
|
|
475
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_POPUP, {
|
|
476
|
+
popupId,
|
|
477
|
+
popupParams
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
getComponent(componentId) {
|
|
481
|
+
return this._postMessageAsync(
|
|
482
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
483
|
+
{ componentId },
|
|
484
|
+
true,
|
|
485
|
+
(data) => new Component(data)
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
class DecisionTable extends BaseSDK {
|
|
490
|
+
constructor(flowId) {
|
|
491
|
+
super();
|
|
492
|
+
this.flowId = flowId;
|
|
493
|
+
}
|
|
494
|
+
evaluate(payload) {
|
|
495
|
+
return this._postMessageAsync(LISTENER_CMDS.DECISION_TABLE_EXECUTE, {
|
|
496
|
+
flowId: this.flowId,
|
|
497
|
+
payload
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
class Dataform extends BaseSDK {
|
|
502
|
+
constructor(flowId) {
|
|
503
|
+
super();
|
|
504
|
+
this._id = flowId;
|
|
505
|
+
}
|
|
506
|
+
importCSV(defaultValues) {
|
|
507
|
+
return this._postMessageAsync(LISTENER_CMDS.DATAFORM_IMPORT_CSV, {
|
|
508
|
+
flowId: this._id,
|
|
509
|
+
defaultValues
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
class Application extends BaseSDK {
|
|
514
|
+
constructor(props) {
|
|
515
|
+
super();
|
|
516
|
+
this._id = props.appId;
|
|
517
|
+
this.page = new Page(props);
|
|
518
|
+
}
|
|
519
|
+
getVariable(key) {
|
|
520
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
|
|
521
|
+
key
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
setVariable(key, value) {
|
|
525
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_APP_VARIABLE, {
|
|
526
|
+
key,
|
|
527
|
+
value
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
openPage(pageId, pageParams) {
|
|
531
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_PAGE, {
|
|
532
|
+
pageId,
|
|
533
|
+
pageParams
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
getDecisionTable(flowId) {
|
|
537
|
+
return new DecisionTable(flowId);
|
|
538
|
+
}
|
|
539
|
+
getDataform(flowId) {
|
|
540
|
+
return new Dataform(flowId);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
class NDEFReader extends BaseSDK {
|
|
544
|
+
constructor() {
|
|
545
|
+
super();
|
|
546
|
+
this.id = generateId(LISTENER_CMDS.WINDOW_NDEF_READER_NEW);
|
|
547
|
+
globalInstances[this.id] = this;
|
|
548
|
+
this._postMessage(
|
|
549
|
+
LISTENER_CMDS.WINDOW_NDEF_READER_NEW,
|
|
550
|
+
{
|
|
551
|
+
id: this.id,
|
|
552
|
+
operation: "new"
|
|
553
|
+
},
|
|
554
|
+
(data) => {
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
scan() {
|
|
559
|
+
return new Promise((resolve, reject) => {
|
|
560
|
+
this._postMessage(
|
|
561
|
+
LISTENER_CMDS.WINDOW_NDEF_READER_SCAN,
|
|
562
|
+
{ id: this.id, operation: "scan" },
|
|
563
|
+
({ data, err }) => {
|
|
564
|
+
console.log("scan data from main window ", data);
|
|
565
|
+
resolve(data);
|
|
566
|
+
}
|
|
567
|
+
);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
write(data) {
|
|
571
|
+
return new Promise((resolve, reject) => {
|
|
572
|
+
this._postMessage(
|
|
573
|
+
LISTENER_CMDS.WINDOW_NDEF_READER_WRITE,
|
|
574
|
+
{ id: this.id, operation: "write", data },
|
|
575
|
+
({ data: data2, err }) => {
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
addEventListener(eventName, cb) {
|
|
581
|
+
this._postMessage(
|
|
582
|
+
LISTENER_CMDS.WINDOW_NDEF_READER_ADD_EVENT_LISTENER,
|
|
583
|
+
{
|
|
584
|
+
id: this.id,
|
|
585
|
+
operation: "addEventListener",
|
|
586
|
+
eventName
|
|
587
|
+
},
|
|
588
|
+
() => {
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
makeReadOnly() {
|
|
593
|
+
return new Promise((resolve, reject) => {
|
|
594
|
+
this._postMessage(
|
|
595
|
+
LISTENER_CMDS.WINDOW_NDEF_READER_MAKE_READONLY,
|
|
596
|
+
{ id: this.id, operation: "makeReadOnly" },
|
|
597
|
+
({ data, err }) => {
|
|
598
|
+
}
|
|
599
|
+
);
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
abortScan() {
|
|
603
|
+
return new Promise((resolve, reject) => {
|
|
604
|
+
this._postMessage(
|
|
605
|
+
LISTENER_CMDS.WINDOW_NDEF_READER_ABORT_SCAN,
|
|
606
|
+
{ id: this.id, operation: "abortScan" },
|
|
607
|
+
({ data, err }) => {
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const window = {
|
|
614
|
+
NDEFReader
|
|
615
|
+
};
|
|
616
|
+
class LowcodeSDK extends BaseSDK {
|
|
617
|
+
constructor(props) {
|
|
618
|
+
super();
|
|
619
|
+
__privateAdd(this, _csrfToken, void 0);
|
|
620
|
+
if (props.tableId && props.tableRowId) {
|
|
621
|
+
this.context = new TableForm(
|
|
622
|
+
props.formInstanceId,
|
|
623
|
+
props.tableId,
|
|
624
|
+
props.tableRowId
|
|
625
|
+
);
|
|
626
|
+
} else if (props.formInstanceId) {
|
|
627
|
+
this.context = new Form(props.formInstanceId);
|
|
628
|
+
} else if (props.popupId) {
|
|
629
|
+
this.context = new Popup(props);
|
|
630
|
+
} else if (props.pageId && !props.componentId) {
|
|
631
|
+
this.context = new Page(props);
|
|
632
|
+
} else if (props.componentId) {
|
|
633
|
+
this.context = new Component(props);
|
|
634
|
+
}
|
|
635
|
+
this.client = new Client();
|
|
636
|
+
this.formatter = new Formatter();
|
|
637
|
+
if (props.appId) {
|
|
638
|
+
this.app = new Application(props);
|
|
639
|
+
}
|
|
640
|
+
this.user = props.user;
|
|
641
|
+
this.env = props.envDetails;
|
|
642
|
+
this.account = props.account;
|
|
643
|
+
__privateSet(this, _csrfToken, props.csrfToken);
|
|
644
|
+
}
|
|
645
|
+
async api(url, args) {
|
|
646
|
+
const response = await globalThis.fetch(url, {
|
|
647
|
+
...args,
|
|
648
|
+
headers: {
|
|
649
|
+
...(args == null ? void 0 : args.headers) || {},
|
|
650
|
+
"X-Csrf-Token": __privateGet(this, _csrfToken)
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
const contentType = response.headers.get("content-type");
|
|
654
|
+
if (contentType && contentType.includes("application/json")) {
|
|
655
|
+
return await response.json();
|
|
656
|
+
} else {
|
|
657
|
+
return response;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
_csrfToken = new WeakMap();
|
|
662
|
+
function initSDK(config) {
|
|
663
|
+
return new LowcodeSDK(config);
|
|
664
|
+
}
|
|
665
|
+
export { initSDK as default, window };
|