@kissflow/lowcode-client-sdk 1.0.6 → 1.0.7
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 +190 -66
- package/dist/kfsdk.es.js +379 -0
- package/dist/kfsdk.umd.js +1 -0
- package/dist/kfworkersdk.es.js +470 -0
- package/package.json +23 -9
- package/SDK_IN_INTEGRATION.md +0 -78
- package/custom.build.js +0 -103
- package/dist/app.js +0 -48
- package/dist/base.js +0 -170
- package/dist/client.js +0 -44
- package/dist/component.js +0 -45
- package/dist/constants.js +0 -48
- package/dist/form.js +0 -126
- package/dist/formatter.js +0 -54
- package/dist/global.types.d.ts +0 -81
- package/dist/index.d.ts +0 -176
- package/dist/index.html +0 -23
- package/dist/index.js +0 -7
- package/dist/kflowcode.sdk.js +0 -896
- package/dist/kflowcode.sdk.js.map +0 -1
- package/dist/kflowcode.sdk.module.js +0 -896
- package/dist/kflowcode.sdk.module.js.map +0 -1
- package/dist/lowcode.sdk.js +0 -58
- package/dist/page.js +0 -63
- package/dist/sdk.types.js +0 -2
- package/id +0 -55
- package/index.html +0 -23
- package/src/app.ts +0 -31
- package/src/base.ts +0 -108
- package/src/client.ts +0 -28
- package/src/component.ts +0 -25
- package/src/constants.ts +0 -53
- package/src/form.ts +0 -131
- package/src/formatter.ts +0 -35
- package/src/index.ts +0 -7
- package/src/lowcode.sdk.ts +0 -51
- package/src/page.ts +0 -43
- package/src/sdk.types.ts +0 -11
- 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 -62
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __accessCheck = (obj, member, msg) => {
|
|
18
|
+
if (!member.has(obj))
|
|
19
|
+
throw TypeError("Cannot " + msg);
|
|
20
|
+
};
|
|
21
|
+
var __privateGet = (obj, member, getter) => {
|
|
22
|
+
__accessCheck(obj, member, "read from private field");
|
|
23
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
24
|
+
};
|
|
25
|
+
var __privateAdd = (obj, member, value) => {
|
|
26
|
+
if (member.has(obj))
|
|
27
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
28
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
29
|
+
};
|
|
30
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
31
|
+
__accessCheck(obj, member, "write to private field");
|
|
32
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
var __privateMethod = (obj, member, method) => {
|
|
36
|
+
__accessCheck(obj, member, "access private method");
|
|
37
|
+
return method;
|
|
38
|
+
};
|
|
39
|
+
var _listeners, _eventListeners, _addListener, addListener_fn, _appendEventListeners, appendEventListeners_fn, _checkEvents, checkEvents_fn, _onMessage, onMessage_fn;
|
|
40
|
+
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
41
|
+
byte &= 63;
|
|
42
|
+
if (byte < 36) {
|
|
43
|
+
id += byte.toString(36);
|
|
44
|
+
} else if (byte < 62) {
|
|
45
|
+
id += (byte - 26).toString(36).toUpperCase();
|
|
46
|
+
} else if (byte > 62) {
|
|
47
|
+
id += "-";
|
|
48
|
+
} else {
|
|
49
|
+
id += "_";
|
|
50
|
+
}
|
|
51
|
+
return id;
|
|
52
|
+
}, "");
|
|
53
|
+
const LISTENER_CMDS = {
|
|
54
|
+
API: "API",
|
|
55
|
+
PARAMS: "PARAMS",
|
|
56
|
+
GET_CONTEXT: "GET_CONTEXT",
|
|
57
|
+
RETURN: "RETURN",
|
|
58
|
+
GET_FORM_FIELD: "GET_FORM_FIELD",
|
|
59
|
+
UPDATE_FORM: "UPDATE_FORM",
|
|
60
|
+
GET_TABLE: "GET_TABLE",
|
|
61
|
+
GET_TABLE_ROW: "GET_TABLE_ROW",
|
|
62
|
+
ADD_TABLE_ROW: "ADD_TABLE_ROW",
|
|
63
|
+
DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
|
|
64
|
+
TO_JSON: "TO_JSON",
|
|
65
|
+
GET_TABLE_ROWS: "GET_TABLE_ROWS",
|
|
66
|
+
MESSAGE: "MESSAGE",
|
|
67
|
+
CONFIRM: "CONFIRM",
|
|
68
|
+
ALERT: "ALERT",
|
|
69
|
+
REDIRECT: "REDIRECT",
|
|
70
|
+
OPEN_PAGE: "OPEN_PAGE",
|
|
71
|
+
FORMAT_DATE: "FORMAT_DATE",
|
|
72
|
+
FORMAT_DATE_TIME: "FORMAT_DATE_TIME",
|
|
73
|
+
FORMAT_NUMBER: "FORMAT_NUMBER",
|
|
74
|
+
FORMAT_CURRENCY: "FORMAT_CURRENCY",
|
|
75
|
+
FORMAT_BOOLEAN: "FORMAT_BOOLEAN",
|
|
76
|
+
GET_APP_VARIABLE: "GET_APP_VARIABLE",
|
|
77
|
+
SET_APP_VARIABLE: "SET_APP_VARIABLE",
|
|
78
|
+
GET_PAGE_VARIABLE: "GET_PAGE_VARIABLE",
|
|
79
|
+
SET_PAGE_VARIABLE: "SET_PAGE_VARIABLE",
|
|
80
|
+
GET_PAGE_PARAMS: "GET_PAGE_PARAMS",
|
|
81
|
+
GET_ALL_PAGE_PARAMS: "GET_ALL_PAGE_PARAMS",
|
|
82
|
+
PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
|
|
83
|
+
OPEN_POPUP: "OPEN_POPUP",
|
|
84
|
+
GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
|
|
85
|
+
GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
|
|
86
|
+
CLOSE_POPUP: "CLOSE_POPUP",
|
|
87
|
+
GET_COMPONENT: "GET_COMPONENT",
|
|
88
|
+
COMPONENT_REFRESH: "COMPONENT_REFRESH",
|
|
89
|
+
COMPONENT_SHOW: "COMPONENT_SHOW",
|
|
90
|
+
COMPONENT_HIDE: "COMPONENT_HIDE",
|
|
91
|
+
INITIALIZE_CUST_COMP: "INITIALIZE_CUST_COMP"
|
|
92
|
+
};
|
|
93
|
+
const DEFAULTS = {
|
|
94
|
+
POPUP_ID: "ACTIVE_POP_UP"
|
|
95
|
+
};
|
|
96
|
+
function generateId(prefix = "lcncsdk") {
|
|
97
|
+
return `${prefix}-${nanoid()}`;
|
|
98
|
+
}
|
|
99
|
+
function postMessage(args) {
|
|
100
|
+
if (self.parent && self.parent !== self) {
|
|
101
|
+
self.parent.postMessage(args, "*");
|
|
102
|
+
} else {
|
|
103
|
+
self.postMessage(args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class BaseSDK {
|
|
107
|
+
constructor(props) {
|
|
108
|
+
__privateAdd(this, _addListener);
|
|
109
|
+
__privateAdd(this, _appendEventListeners);
|
|
110
|
+
__privateAdd(this, _checkEvents);
|
|
111
|
+
__privateAdd(this, _onMessage);
|
|
112
|
+
__privateAdd(this, _listeners, void 0);
|
|
113
|
+
__privateAdd(this, _eventListeners, void 0);
|
|
114
|
+
__privateSet(this, _listeners, {});
|
|
115
|
+
__privateSet(this, _eventListeners, {});
|
|
116
|
+
self.addEventListener("message", __privateMethod(this, _onMessage, onMessage_fn).bind(this), false);
|
|
117
|
+
}
|
|
118
|
+
_postMessageAsync(command, args, hasCallBack, callBack) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const _id = generateId(command.toLowerCase());
|
|
121
|
+
postMessage(__spreadValues({ _id, command }, args));
|
|
122
|
+
__privateMethod(this, _addListener, addListener_fn).call(this, _id, async (data) => {
|
|
123
|
+
if (data.errorMessage) {
|
|
124
|
+
reject(data);
|
|
125
|
+
} else {
|
|
126
|
+
if (hasCallBack && callBack) {
|
|
127
|
+
data = await callBack(data);
|
|
128
|
+
}
|
|
129
|
+
resolve(data);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
_postMessage(command, func, args = {}) {
|
|
135
|
+
const _id = generateId(command.toLowerCase());
|
|
136
|
+
postMessage(__spreadValues({ _id, command }, args));
|
|
137
|
+
__privateMethod(this, _addListener, addListener_fn).call(this, _id, (data) => func(data));
|
|
138
|
+
}
|
|
139
|
+
_registerEventListener(_id, eventType, callback) {
|
|
140
|
+
__privateMethod(this, _appendEventListeners, appendEventListeners_fn).call(this, _id, eventType, callback);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
_listeners = new WeakMap();
|
|
144
|
+
_eventListeners = new WeakMap();
|
|
145
|
+
_addListener = new WeakSet();
|
|
146
|
+
addListener_fn = function(_id, callback) {
|
|
147
|
+
__privateGet(this, _listeners)[_id] = __privateGet(this, _listeners)[_id] || [];
|
|
148
|
+
__privateGet(this, _listeners)[_id].push(callback);
|
|
149
|
+
};
|
|
150
|
+
_appendEventListeners = new WeakSet();
|
|
151
|
+
appendEventListeners_fn = function(_id, eventType, callback) {
|
|
152
|
+
if (!__privateGet(this, _eventListeners)[_id]) {
|
|
153
|
+
__privateGet(this, _eventListeners)[_id] = {};
|
|
154
|
+
}
|
|
155
|
+
__privateGet(this, _eventListeners)[_id][eventType] = callback;
|
|
156
|
+
};
|
|
157
|
+
_checkEvents = new WeakSet();
|
|
158
|
+
checkEvents_fn = function(data) {
|
|
159
|
+
const { _id, eventType, eventParams } = data;
|
|
160
|
+
if (!_id || !eventType)
|
|
161
|
+
return;
|
|
162
|
+
const eventListener = __privateGet(this, _eventListeners)[_id] || {};
|
|
163
|
+
if (eventListener[eventType]) {
|
|
164
|
+
eventListener[eventType](eventParams || {});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
_onMessage = new WeakSet();
|
|
168
|
+
onMessage_fn = function(event) {
|
|
169
|
+
if (event.origin !== self.location.origin) {
|
|
170
|
+
const data = event.data;
|
|
171
|
+
if (data.isEvent) {
|
|
172
|
+
return __privateMethod(this, _checkEvents, checkEvents_fn).call(this, data);
|
|
173
|
+
}
|
|
174
|
+
const _req = (data == null ? void 0 : data._req) || {};
|
|
175
|
+
let listeners = __privateGet(this, _listeners)[_req == null ? void 0 : _req._id] || [];
|
|
176
|
+
if (listeners) {
|
|
177
|
+
listeners.forEach((listener) => {
|
|
178
|
+
try {
|
|
179
|
+
if (data.resp && Object.keys(data.resp).length === 1 && _req.command !== LISTENER_CMDS.API) {
|
|
180
|
+
listener(Object.values(data.resp)[0]);
|
|
181
|
+
} else {
|
|
182
|
+
listener(data.resp);
|
|
183
|
+
}
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.error("Message callback error: ", err);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
class Form extends BaseSDK {
|
|
192
|
+
constructor(instanceId) {
|
|
193
|
+
super({});
|
|
194
|
+
this.type = "Form";
|
|
195
|
+
this.instanceId = instanceId;
|
|
196
|
+
}
|
|
197
|
+
toJSON() {
|
|
198
|
+
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
199
|
+
instanceId: this.instanceId
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
getField(fieldId) {
|
|
203
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
|
|
204
|
+
instanceId: this.instanceId,
|
|
205
|
+
fieldId
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
updateField(args) {
|
|
209
|
+
return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
|
|
210
|
+
data: args
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
getTable(tableId) {
|
|
214
|
+
return new Table(this.instanceId, tableId);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
class Table extends BaseSDK {
|
|
218
|
+
constructor(instanceId, tableId) {
|
|
219
|
+
super({});
|
|
220
|
+
this.tableId = tableId;
|
|
221
|
+
this.instanceId = instanceId;
|
|
222
|
+
}
|
|
223
|
+
toJSON() {
|
|
224
|
+
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
225
|
+
tableId: this.tableId
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
getRows() {
|
|
229
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_TABLE_ROWS, { tableId: this.tableId }, true, (data) => {
|
|
230
|
+
return data.map((row) => new TableForm(this.instanceId, this.tableId, row.id));
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
getRow(rowId) {
|
|
234
|
+
return new TableForm(this.instanceId, this.tableId, rowId);
|
|
235
|
+
}
|
|
236
|
+
addRow(rowObject) {
|
|
237
|
+
return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROW, {
|
|
238
|
+
tableId: this.tableId,
|
|
239
|
+
rowObject
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
deleteRow(rowId) {
|
|
243
|
+
return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
|
|
244
|
+
tableId: this.tableId,
|
|
245
|
+
rowId
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
class TableForm extends BaseSDK {
|
|
250
|
+
constructor(instanceId, tableId, rowId) {
|
|
251
|
+
super({});
|
|
252
|
+
this.instanceId = instanceId;
|
|
253
|
+
this.type = "TabelForm";
|
|
254
|
+
this.tableId = tableId;
|
|
255
|
+
this.rowId = rowId;
|
|
256
|
+
}
|
|
257
|
+
getParent() {
|
|
258
|
+
return new Form(this.instanceId);
|
|
259
|
+
}
|
|
260
|
+
toJSON() {
|
|
261
|
+
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
262
|
+
tableId: this.tableId,
|
|
263
|
+
rowId: this.rowId
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
getField(fieldId) {
|
|
267
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
|
|
268
|
+
instanceId: this.instanceId,
|
|
269
|
+
tableId: this.tableId,
|
|
270
|
+
rowId: this.rowId,
|
|
271
|
+
fieldId
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
updateField(args) {
|
|
275
|
+
return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
|
|
276
|
+
instanceId: this.instanceId,
|
|
277
|
+
tableId: this.tableId,
|
|
278
|
+
rowId: this.rowId,
|
|
279
|
+
data: args
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
class Client extends BaseSDK {
|
|
284
|
+
showInfo(message) {
|
|
285
|
+
return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
|
|
286
|
+
}
|
|
287
|
+
showConfirm(args) {
|
|
288
|
+
return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
|
|
289
|
+
data: {
|
|
290
|
+
title: args.title,
|
|
291
|
+
content: args.content,
|
|
292
|
+
okText: args.okText || "Ok",
|
|
293
|
+
cancelText: args.cancelText || "Cancel"
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
redirect(url) {
|
|
298
|
+
return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
class Formatter extends BaseSDK {
|
|
302
|
+
toDate(date) {
|
|
303
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
|
|
304
|
+
date
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
toDateTime(date) {
|
|
308
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
|
|
309
|
+
date
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
toNumber(value) {
|
|
313
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
|
|
314
|
+
value
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
toCurrency(value, currencyCode) {
|
|
318
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
|
|
319
|
+
value,
|
|
320
|
+
currencyCode
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
toBoolean(value) {
|
|
324
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
|
|
325
|
+
value
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
class Component extends BaseSDK {
|
|
330
|
+
constructor(props) {
|
|
331
|
+
super({});
|
|
332
|
+
this._id = props.componentId;
|
|
333
|
+
this.type = "Component";
|
|
334
|
+
}
|
|
335
|
+
refresh() {
|
|
336
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
|
|
337
|
+
id: this._id
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
show() {
|
|
341
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_SHOW, {
|
|
342
|
+
id: this._id
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
hide() {
|
|
346
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_HIDE, {
|
|
347
|
+
id: this._id
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
class Popup extends BaseSDK {
|
|
352
|
+
constructor(props) {
|
|
353
|
+
super({});
|
|
354
|
+
this.type = "Popup";
|
|
355
|
+
this._id = props.popupId || DEFAULTS.POPUP_ID;
|
|
356
|
+
}
|
|
357
|
+
getParameter(key) {
|
|
358
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_POPUP_PARAMS, {
|
|
359
|
+
key,
|
|
360
|
+
popupId: this._id
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
getAllParameters() {
|
|
364
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_POPUP_PARAMS, {
|
|
365
|
+
popupId: this._id
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
close() {
|
|
369
|
+
return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
|
|
370
|
+
}
|
|
371
|
+
getComponent(componentId) {
|
|
372
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_COMPONENT, { componentId }, true, (data) => {
|
|
373
|
+
return new Component(data);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
class Page extends BaseSDK {
|
|
378
|
+
constructor(props) {
|
|
379
|
+
super({});
|
|
380
|
+
this.type = "Page";
|
|
381
|
+
this.popup = new Popup({});
|
|
382
|
+
this._id = props.pageId;
|
|
383
|
+
}
|
|
384
|
+
getParameter(key) {
|
|
385
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
|
|
386
|
+
key
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
getAllParameters() {
|
|
390
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_PAGE_PARAMS, {
|
|
391
|
+
pageId: this._id
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
getVariable(key) {
|
|
395
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_VARIABLE, {
|
|
396
|
+
key
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
setVariable(key, value) {
|
|
400
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_PAGE_VARIABLE, {
|
|
401
|
+
key,
|
|
402
|
+
value
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
openPopup(popupId, popupParams) {
|
|
406
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_POPUP, {
|
|
407
|
+
popupId,
|
|
408
|
+
popupParams
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
getComponent(componentId) {
|
|
412
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_COMPONENT, { componentId }, true, (data) => {
|
|
413
|
+
return new Component(data);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
class Application extends BaseSDK {
|
|
418
|
+
constructor(props) {
|
|
419
|
+
super({});
|
|
420
|
+
this._id = props.appId;
|
|
421
|
+
this.page = new Page(props);
|
|
422
|
+
}
|
|
423
|
+
getVariable(key) {
|
|
424
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
|
|
425
|
+
key
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
setVariable(key, value) {
|
|
429
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_APP_VARIABLE, {
|
|
430
|
+
key,
|
|
431
|
+
value
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
openPage(pageId, pageParams) {
|
|
435
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_PAGE, {
|
|
436
|
+
pageId,
|
|
437
|
+
pageParams
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
class LowcodeSDK extends BaseSDK {
|
|
442
|
+
constructor(props) {
|
|
443
|
+
super({});
|
|
444
|
+
if (props.tableId && props.tableRowId) {
|
|
445
|
+
this.context = new TableForm(props.formInstanceId, props.tableId, props.tableRowId);
|
|
446
|
+
} else if (props.formInstanceId) {
|
|
447
|
+
this.context = new Form(props.formInstanceId);
|
|
448
|
+
} else if (props.popupId) {
|
|
449
|
+
this.context = new Popup(props);
|
|
450
|
+
} else if (props.pageId && !props.componentId) {
|
|
451
|
+
this.context = new Page(props);
|
|
452
|
+
} else if (props.componentId) {
|
|
453
|
+
this.context = new Component(props);
|
|
454
|
+
}
|
|
455
|
+
this.client = new Client({});
|
|
456
|
+
this.formatter = new Formatter({});
|
|
457
|
+
if (props.appId) {
|
|
458
|
+
this.app = new Application(props);
|
|
459
|
+
}
|
|
460
|
+
this.user = props.user;
|
|
461
|
+
this.account = props.account;
|
|
462
|
+
}
|
|
463
|
+
api(url, args = {}) {
|
|
464
|
+
return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function initSDK(config) {
|
|
468
|
+
return new LowcodeSDK(config);
|
|
469
|
+
}
|
|
470
|
+
export { initSDK as default };
|
package/package.json
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kissflow/lowcode-client-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "JavaScript SDK for developing over the Kissflow lowcode platform",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
5
|
"types": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/kfsdk.umd.js",
|
|
10
|
+
"module": "./dist/kfsdk.es.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/kfsdk.es.js",
|
|
14
|
+
"require": "./dist/kfsdk.umd.js"
|
|
15
|
+
},
|
|
16
|
+
"./lowcode": {
|
|
17
|
+
"import": "./dist/kfworkersdk.es.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
7
20
|
"scripts": {
|
|
8
|
-
"start": "
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"prepare": "npm run build",
|
|
14
|
-
"serve": "webpack serve"
|
|
21
|
+
"start": "vite serve",
|
|
22
|
+
"customBuild": "node custom.build.mjs",
|
|
23
|
+
"build": "pnpm run customBuild",
|
|
24
|
+
"prepare": "vite build",
|
|
25
|
+
"serve": "http-server -p 8080"
|
|
15
26
|
},
|
|
16
27
|
"repository": {
|
|
17
28
|
"type": "git",
|
|
@@ -29,11 +40,14 @@
|
|
|
29
40
|
"http-server": "^0.12.3",
|
|
30
41
|
"ts-loader": "^9.2.5",
|
|
31
42
|
"typescript": "^4.3.5",
|
|
43
|
+
"vite": "^2.9.8",
|
|
32
44
|
"webpack": "^5.52.1",
|
|
33
45
|
"webpack-cli": "^4.8.0",
|
|
34
46
|
"webpack-dev-server": "^3.11.2"
|
|
35
47
|
},
|
|
36
48
|
"dependencies": {
|
|
49
|
+
"@lingui/cli": "^3.13.3",
|
|
50
|
+
"@lingui/react": "^2",
|
|
37
51
|
"nanoid": "^3.1.30",
|
|
38
52
|
"ts-file-parser": "0.0.21"
|
|
39
53
|
}
|
package/SDK_IN_INTEGRATION.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# _Kissflow Low-code JavaScript SDK_
|
|
2
|
-
|
|
3
|
-
The JavaScript Software Development Kit (SDK) for Kissflow Low-code includes all the supported functions and code snippets that you can incorporate into your application while integrating with other services.
|
|
4
|
-
|
|
5
|
-
### 1) Get context
|
|
6
|
-
This function retrieves your account and application's context information, such as the **account ID** and **application ID**.
|
|
7
|
-
```js
|
|
8
|
-
kf.getContext().then((ctx) => {...})
|
|
9
|
-
// or
|
|
10
|
-
let ctx = kf.getContext()
|
|
11
|
-
/*
|
|
12
|
-
fetches contextual information, such as:
|
|
13
|
-
ctx = {
|
|
14
|
-
app: {_id },
|
|
15
|
-
account: { _id }
|
|
16
|
-
}
|
|
17
|
-
*/
|
|
18
|
-
```
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
### 2) Get API via Kissflow Low-code SDK
|
|
22
|
-
|
|
23
|
-
This function lets you retrieve any external or Kissflow APIs. To access an internal Kissflow API, use an absolute URL, **(i.e., https://{your_sub_domain}.kissflow.com/user/2/{account_id})**. The Access key secret must be passed in the header. Refer **[Access keys](https://helpdocs.kissflow.com/user-settings/api-keys#access_keys)** to know how to locate your Kissflow API key and secret. Refer the developer guide to know more about our **[APIs](https://developers.kissflow.com)**.
|
|
24
|
-
> Note: The API call timeout for this method is 10 seconds.
|
|
25
|
-
```js
|
|
26
|
-
kf.api(url, config).then((res) => {...})
|
|
27
|
-
// or
|
|
28
|
-
let resp = await kf.api(url, config)
|
|
29
|
-
```
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
### 3) Formatter functions
|
|
33
|
-
##### Convert to Kissflow date format
|
|
34
|
-
This function lets you transform your date into Kissflow's date format. This conversion is based on the date format specified in your Kissflow account format settings.
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
kf.formatter.toDate("08-24-2021").then((res) => {...})
|
|
38
|
-
// or
|
|
39
|
-
let value = kf.formatter.toDate("08-24-2021");
|
|
40
|
-
```
|
|
41
|
-
##### Convert to Kissflow DateTime format
|
|
42
|
-
This function lets you transform your date and time into Kissflow's DateTime format. This conversion is based on the time zone and date format specified in your Kissflow account format settings.
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
kf.formatter.toDateTime("2021-08-26T14:30").then((res) => {...})
|
|
46
|
-
// or
|
|
47
|
-
let value = kf.formatter.toDateTime("2021-08-26T14:30");
|
|
48
|
-
```
|
|
49
|
-
##### Convert to Kissflow number format
|
|
50
|
-
This function lets you transform your number into Kissflow's number format.
|
|
51
|
-
```js
|
|
52
|
-
kf.formatter.toNumber("1,00,000.500000").then((res) => {...})
|
|
53
|
-
// or
|
|
54
|
-
let value = kf.formatter.toNumber("1,00,000.500000");
|
|
55
|
-
```
|
|
56
|
-
##### Convert to Kissflow currency format
|
|
57
|
-
This function lets you transform your current values into Kissflow's currency format.
|
|
58
|
-
```js
|
|
59
|
-
kf.formatter.toCurrency("1,00,000.500000", "USD").then((res) => {...})
|
|
60
|
-
// or
|
|
61
|
-
let value = kf.formatter.toCurrency("1,00,000.500000", "USD");
|
|
62
|
-
```
|
|
63
|
-
##### Convert to boolean
|
|
64
|
-
This function converts your value to a boolean value.
|
|
65
|
-
```js
|
|
66
|
-
kf.formatter.toBoolean("yes").then((res) => {...})
|
|
67
|
-
// or
|
|
68
|
-
let value = kf.formatter.toBoolean("yes");
|
|
69
|
-
```
|
|
70
|
-
##### Other supported boolean values
|
|
71
|
-
```js
|
|
72
|
-
let value = kf.formatter.toBoolean("1");
|
|
73
|
-
let value = kf.formatter.toBoolean("true");
|
|
74
|
-
let value = kf.formatter.toBoolean("no");
|
|
75
|
-
let value = kf.formatter.toBoolean("0");
|
|
76
|
-
let value = kf.formatter.toBoolean("false");
|
|
77
|
-
```
|
|
78
|
-
---
|
package/custom.build.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const tsFileStruct = require("ts-file-parser");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
let classMappings = {
|
|
4
|
-
Page: { name: "Page" },
|
|
5
|
-
Application: { name: "Application" },
|
|
6
|
-
Client: { name: "Client" },
|
|
7
|
-
Component: { name: "Component" },
|
|
8
|
-
Form: { name: "Form" },
|
|
9
|
-
Table: { name: "Table" },
|
|
10
|
-
TableForm: { name: "TableForm" },
|
|
11
|
-
Formatter: { name: "Formatter" },
|
|
12
|
-
LowcodeSDK: { name: "kf", staticDeclarations: true }
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const exec = require("child_process").exec;
|
|
16
|
-
runCommand("webpack", () => {
|
|
17
|
-
runCommand("tsc", () => {
|
|
18
|
-
runCommand("tsc -p tsconfig.types.json", transfromTypings);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
function runCommand(command, callBack = null) {
|
|
23
|
-
const execCmd = exec(command, () => {
|
|
24
|
-
callBack && callBack();
|
|
25
|
-
});
|
|
26
|
-
execCmd.stdout.on("data", (data) => {
|
|
27
|
-
console.log(data);
|
|
28
|
-
});
|
|
29
|
-
execCmd.stderr.on("data", (data) => {
|
|
30
|
-
console.error(data);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function transfromTypings() {
|
|
35
|
-
const filePath = "./dist/index.d.ts";
|
|
36
|
-
let srcFile = fs.readFileSync(filePath).toString();
|
|
37
|
-
let srcCode = tsFileStruct.parseStruct(srcFile, {}, filePath);
|
|
38
|
-
|
|
39
|
-
let allClasses = srcCode.classes;
|
|
40
|
-
let func = "";
|
|
41
|
-
let toWrite = ``;
|
|
42
|
-
|
|
43
|
-
for (let i = 0; i < allClasses.length; i++) {
|
|
44
|
-
if (Object.keys(classMappings).includes(allClasses[i].name)) {
|
|
45
|
-
let _class = allClasses[i];
|
|
46
|
-
toWrite += `\ndeclare class ${
|
|
47
|
-
classMappings[_class.name].name
|
|
48
|
-
} { \n`;
|
|
49
|
-
|
|
50
|
-
// fields on Class
|
|
51
|
-
for (let i = 0; i < _class.fields.length; i++) {
|
|
52
|
-
// if (_class.fields[i].type.modulePath) {
|
|
53
|
-
let className = "";
|
|
54
|
-
if (!_class.fields[i].type) {
|
|
55
|
-
continue;
|
|
56
|
-
} else if (_class.fields[i].type.options) {
|
|
57
|
-
// TODO: currently we add only the first typechecking
|
|
58
|
-
className = _class.fields[i].type.options[0].typeName;
|
|
59
|
-
|
|
60
|
-
// TODO: need to handle when there are multiple type
|
|
61
|
-
// let options = _class.fields[i].type.options
|
|
62
|
-
// for (let j = 0; j < options.length; j++) {
|
|
63
|
-
// className += options[j].typeName;
|
|
64
|
-
// if (j < options.length - 1) {
|
|
65
|
-
// className += " | ";
|
|
66
|
-
// }
|
|
67
|
-
// }
|
|
68
|
-
} else {
|
|
69
|
-
className = _class.fields[i].type.typeName;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let fieldName = _class.fields[i].name;
|
|
73
|
-
// console.log(_class.fields[i]);
|
|
74
|
-
toWrite += `\t${
|
|
75
|
-
classMappings[_class.name].staticDeclarations
|
|
76
|
-
? "static "
|
|
77
|
-
: ""
|
|
78
|
-
}${fieldName}: ${className} \n`;
|
|
79
|
-
// }
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//methods of Class
|
|
83
|
-
for (j = 0; j < _class.methods.length; j++) {
|
|
84
|
-
func = _class.methods[j].text.trim().split("\n\t").join(" ");
|
|
85
|
-
toWrite += `\t${func} \n`;
|
|
86
|
-
// if (
|
|
87
|
-
// typeof _class.methods[j].returnType === "object" &&
|
|
88
|
-
// method.returnType.modulePath
|
|
89
|
-
// ) {
|
|
90
|
-
// childClasses.push(method.returnType.typeName);
|
|
91
|
-
// }
|
|
92
|
-
}
|
|
93
|
-
toWrite += `}`;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
let typesFile = fs.readFileSync("./src/sdk.types.ts").toString();
|
|
98
|
-
toWrite += `\n` + typesFile.replace(/export/gi, "declare");
|
|
99
|
-
|
|
100
|
-
fs.writeFile("./dist/global.types.d.ts", toWrite, function (err) {
|
|
101
|
-
if (err) return console.log(err);
|
|
102
|
-
});
|
|
103
|
-
}
|