@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
package/dist/kfsdk.es.js
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
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;
|
|
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 index2 = __privateGet(this, _listeners)[eventName].findIndex(callBack);
|
|
138
|
+
index2 > -1 && __privateGet(this, _listeners)[eventName].splice(index2, 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 Component extends BaseSDK {
|
|
198
|
+
constructor(props) {
|
|
199
|
+
super();
|
|
200
|
+
__privateAdd(this, _registerComponentAPIs);
|
|
201
|
+
this._id = props.componentId;
|
|
202
|
+
this.type = "Component";
|
|
203
|
+
globalInstances[this._id] = this;
|
|
204
|
+
__privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
|
|
205
|
+
}
|
|
206
|
+
onMount(callback) {
|
|
207
|
+
this._postMessage(
|
|
208
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
209
|
+
{
|
|
210
|
+
id: this._id,
|
|
211
|
+
eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
|
|
212
|
+
eventConfig: {
|
|
213
|
+
once: true
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
callback
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
refresh() {
|
|
220
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
|
|
221
|
+
id: this._id
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
show() {
|
|
225
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_SHOW, {
|
|
226
|
+
id: this._id
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
hide() {
|
|
230
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_HIDE, {
|
|
231
|
+
id: this._id
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
_registerComponentAPIs = new WeakSet();
|
|
236
|
+
registerComponentAPIs_fn = function(componentAPIs) {
|
|
237
|
+
componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
|
|
238
|
+
this[Api.name] = (...args) => {
|
|
239
|
+
if (Api.type === "method") {
|
|
240
|
+
return this._postMessageAsync(`COMPONENT_${Api.name}`, {
|
|
241
|
+
id: this._id,
|
|
242
|
+
parameters: args
|
|
243
|
+
});
|
|
244
|
+
} else if (Api.type === "event") {
|
|
245
|
+
this._postMessage(
|
|
246
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
247
|
+
{
|
|
248
|
+
id: this._id,
|
|
249
|
+
eventName: Api.name,
|
|
250
|
+
eventConfig: args[1]
|
|
251
|
+
},
|
|
252
|
+
args[0]
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
class CustomComponent extends BaseSDK {
|
|
259
|
+
constructor(id) {
|
|
260
|
+
super();
|
|
261
|
+
this._id = id;
|
|
262
|
+
this.type = "CustomComponent";
|
|
263
|
+
globalInstances[this._id] = this;
|
|
264
|
+
}
|
|
265
|
+
watchParams(callBack) {
|
|
266
|
+
this._postMessage(
|
|
267
|
+
LISTENER_CMDS.CC_WATCH_PARAMS,
|
|
268
|
+
{
|
|
269
|
+
id: this._id,
|
|
270
|
+
eventName: EVENT_TYPES.CC_ON_PARAMS_CHANGE,
|
|
271
|
+
eventConfig: {
|
|
272
|
+
once: false
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
callBack
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
class Popup extends BaseSDK {
|
|
280
|
+
constructor(props) {
|
|
281
|
+
super();
|
|
282
|
+
this.type = "Popup";
|
|
283
|
+
this._id = props.popupId || DEFAULTS.POPUP_ID;
|
|
284
|
+
}
|
|
285
|
+
getParameter(key) {
|
|
286
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_POPUP_PARAMS, {
|
|
287
|
+
key,
|
|
288
|
+
popupId: this._id
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
getAllParameters() {
|
|
292
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_POPUP_PARAMS, {
|
|
293
|
+
popupId: this._id
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
close() {
|
|
297
|
+
return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
|
|
298
|
+
}
|
|
299
|
+
getComponent(componentId) {
|
|
300
|
+
return this._postMessageAsync(
|
|
301
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
302
|
+
{ componentId },
|
|
303
|
+
true,
|
|
304
|
+
(data) => {
|
|
305
|
+
return new Component(data);
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
class Page extends BaseSDK {
|
|
311
|
+
constructor(props) {
|
|
312
|
+
super();
|
|
313
|
+
this.type = "Page";
|
|
314
|
+
this.popup = new Popup({});
|
|
315
|
+
this._id = props.pageId;
|
|
316
|
+
}
|
|
317
|
+
getParameter(key) {
|
|
318
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
|
|
319
|
+
key
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
getAllParameters() {
|
|
323
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_PAGE_PARAMS, {
|
|
324
|
+
pageId: this._id
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
getVariable(key) {
|
|
328
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_VARIABLE, {
|
|
329
|
+
key
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
setVariable(key, value) {
|
|
333
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_PAGE_VARIABLE, {
|
|
334
|
+
key,
|
|
335
|
+
value
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
openPopup(popupId, popupParams) {
|
|
339
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_POPUP, {
|
|
340
|
+
popupId,
|
|
341
|
+
popupParams
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
getComponent(componentId) {
|
|
345
|
+
return this._postMessageAsync(
|
|
346
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
347
|
+
{ componentId },
|
|
348
|
+
true,
|
|
349
|
+
(data) => new Component(data)
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
class DecisionTable extends BaseSDK {
|
|
354
|
+
constructor(flowId) {
|
|
355
|
+
super();
|
|
356
|
+
this.flowId = flowId;
|
|
357
|
+
}
|
|
358
|
+
evaluate(payload) {
|
|
359
|
+
return this._postMessageAsync(LISTENER_CMDS.DECISION_TABLE_EXECUTE, {
|
|
360
|
+
flowId: this.flowId,
|
|
361
|
+
payload
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
class Dataform extends BaseSDK {
|
|
366
|
+
constructor(flowId) {
|
|
367
|
+
super();
|
|
368
|
+
this._id = flowId;
|
|
369
|
+
}
|
|
370
|
+
importCSV(defaultValues) {
|
|
371
|
+
return this._postMessageAsync(LISTENER_CMDS.DATAFORM_IMPORT_CSV, {
|
|
372
|
+
flowId: this._id,
|
|
373
|
+
defaultValues
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
class Application extends BaseSDK {
|
|
378
|
+
constructor(props) {
|
|
379
|
+
super();
|
|
380
|
+
this._id = props.appId;
|
|
381
|
+
this.page = new Page(props);
|
|
382
|
+
}
|
|
383
|
+
getVariable(key) {
|
|
384
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
|
|
385
|
+
key
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
setVariable(key, value) {
|
|
389
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_APP_VARIABLE, {
|
|
390
|
+
key,
|
|
391
|
+
value
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
openPage(pageId, pageParams) {
|
|
395
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_PAGE, {
|
|
396
|
+
pageId,
|
|
397
|
+
pageParams
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
getDecisionTable(flowId) {
|
|
401
|
+
return new DecisionTable(flowId);
|
|
402
|
+
}
|
|
403
|
+
getDataform(flowId) {
|
|
404
|
+
return new Dataform(flowId);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
class Client extends BaseSDK {
|
|
408
|
+
showInfo(message) {
|
|
409
|
+
return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
|
|
410
|
+
}
|
|
411
|
+
showConfirm(args) {
|
|
412
|
+
return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
|
|
413
|
+
data: {
|
|
414
|
+
title: args.title,
|
|
415
|
+
content: args.content,
|
|
416
|
+
okText: args.okText || "Ok",
|
|
417
|
+
cancelText: args.cancelText || "Cancel"
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
redirect(url) {
|
|
422
|
+
return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
class Formatter extends BaseSDK {
|
|
426
|
+
toDate(date) {
|
|
427
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
|
|
428
|
+
date
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
toDateTime(date) {
|
|
432
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
|
|
433
|
+
date
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
toNumber(value) {
|
|
437
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
|
|
438
|
+
value
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
toCurrency(value, currencyCode) {
|
|
442
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
|
|
443
|
+
value,
|
|
444
|
+
currencyCode
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
toBoolean(value) {
|
|
448
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
|
|
449
|
+
value
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
class CustomComponentSDK extends BaseSDK {
|
|
454
|
+
constructor() {
|
|
455
|
+
super();
|
|
456
|
+
}
|
|
457
|
+
api(url, args = {}) {
|
|
458
|
+
return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
|
|
459
|
+
}
|
|
460
|
+
initialize() {
|
|
461
|
+
return this._postMessageAsync(
|
|
462
|
+
LISTENER_CMDS.CC_INITIALIZE,
|
|
463
|
+
{},
|
|
464
|
+
true,
|
|
465
|
+
(data) => {
|
|
466
|
+
this.app = new Application(data);
|
|
467
|
+
this.page = new Page(data);
|
|
468
|
+
this.context = new CustomComponent(data.componentId);
|
|
469
|
+
this.client = new Client();
|
|
470
|
+
this.formatter = new Formatter();
|
|
471
|
+
this.user = data.user;
|
|
472
|
+
this.account = data.account;
|
|
473
|
+
this.env = data.envDetails;
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
initialise() {
|
|
479
|
+
return this.initialize();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
var index = new CustomComponentSDK();
|
|
483
|
+
export { index as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var h=(E,t,A)=>{if(!t.has(E))throw TypeError("Cannot "+A)};var o=(E,t,A)=>(h(E,t,"read from private field"),A?A.call(E):t.get(E)),p=(E,t,A)=>{if(t.has(E))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(E):t.set(E,A)},l=(E,t,A,N)=>(h(E,t,"write to private field"),N?N.call(E,A):t.set(E,A),A);var g=(E,t,A)=>(h(E,t,"access private method"),A);(function(E,t){typeof exports=="object"&&typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(t):(E=typeof globalThis!="undefined"?globalThis:E||self,E.kf=t())})(this,function(){var i,M,L;"use strict";let E=(n=21)=>crypto.getRandomValues(new Uint8Array(n)).reduce((e,s)=>(s&=63,s<36?e+=s.toString(36):s<62?e+=(s-26).toString(36).toUpperCase():s>62?e+="-":e+="_",e),"");const t={API:"API",GET_CONTEXT:"GET_CONTEXT",RETURN:"RETURN",GET_FORM_FIELD:"GET_FORM_FIELD",UPDATE_FORM:"UPDATE_FORM",GET_TABLE:"GET_TABLE",GET_TABLE_ROW:"GET_TABLE_ROW",ADD_TABLE_ROW:"ADD_TABLE_ROW",ADD_TABLE_ROWS:"ADD_TABLE_ROWS",DELETE_TABLE_ROW:"DELETE_TABLE_ROW",TO_JSON:"TO_JSON",GET_TABLE_ROWS:"GET_TABLE_ROWS",MESSAGE:"MESSAGE",CONFIRM:"CONFIRM",ALERT:"ALERT",REDIRECT:"REDIRECT",OPEN_PAGE:"OPEN_PAGE",FORMAT_DATE:"FORMAT_DATE",FORMAT_DATE_TIME:"FORMAT_DATE_TIME",FORMAT_NUMBER:"FORMAT_NUMBER",FORMAT_CURRENCY:"FORMAT_CURRENCY",FORMAT_BOOLEAN:"FORMAT_BOOLEAN",GET_APP_VARIABLE:"GET_APP_VARIABLE",SET_APP_VARIABLE:"SET_APP_VARIABLE",GET_PAGE_VARIABLE:"GET_PAGE_VARIABLE",SET_PAGE_VARIABLE:"SET_PAGE_VARIABLE",GET_PAGE_PARAMS:"GET_PAGE_PARAMS",GET_ALL_PAGE_PARAMS:"GET_ALL_PAGE_PARAMS",PAGE_ON_CLOSE:"PAGE_ON_CLOSE",OPEN_POPUP:"OPEN_POPUP",GET_POPUP_PARAMS:"GET_POPUP_PARAMS",GET_ALL_POPUP_PARAMS:"GET_ALL_POPUP_PARAMS",CLOSE_POPUP:"CLOSE_POPUP",COMPONENT_GET:"COMPONENT_GET",COMPONENT_REFRESH:"COMPONENT_REFRESH",COMPONENT_SHOW:"COMPONENT_SHOW",COMPONENT_HIDE:"COMPONENT_HIDE",COMPONENT_ADD_EVENT_LISTENER:"COMPONENT_ADD_EVENT_LISTENER",CC_INITIALIZE:"CC_INITIALIZE",CC_WATCH_PARAMS:"CC_WATCH_PARAMS",WINDOW_NDEF_READER_NEW:"WINDOW_NDEF_READER_NEW",WINDOW_NDEF_READER_SCAN:"WINDOW_NDEF_READER_SCAN",WINDOW_NDEF_READER_WRITE:"WINDOW_NDEF_READER_WRITE",WINDOW_NDEF_READER_ADD_EVENT_LISTENER:"WINDOW_NDEF_READER_ADD_EVENT_LISTENER",WINDOW_NDEF_READER_MAKE_READONLY:"WINDOW_NDEF_READER_MAKE_READONLY",WINDOW_NDEF_READER_ABORT_SCAN:"WINDOW_NDEF_READER_ABORT_SCAN",DECISION_TABLE_EXECUTE:"DECISION_TABLE_EXECUTE",DATAFORM_IMPORT_CSV:"DATAFORM_IMPORT_CSV"},A={COMPONENT_ON_MOUNT:"componentOnMount",CC_ON_PARAMS_CHANGE:"onCustomComponentParamsChange"},N={POPUP_ID:"ACTIVE_POP_UP"};function u(n="lcncsdk"){return`${n}-${E()}`}const P={};function C(n){globalThis.parent&&globalThis.parent!==globalThis?globalThis.parent.postMessage(n,"*"):globalThis.postMessage(n)}function d(n){if(n.origin!==globalThis.location.origin){const e=n.data;if(e!=null&&e.isEvent){const{target:r,eventParams:a,eventName:c,eventConfig:R={}}=e;let O=P[r];O._dispatchEvent(c,a),R.once&&O._removeEventListener(c);return}let{_req:s,resp:_}=e;s!=null&&s._id&&P[s._id]._dispatchMessageEvents(s,_)}}globalThis.addEventListener("message",d);class S{constructor(){p(this,i,void 0);l(this,i,{})}_addEventListener(e,s){var _;o(this,i)[e]=((_=o(this,i))==null?void 0:_[e])||[],o(this,i)[e].push(s)}_removeEventListener(e,s){if(s){let _=o(this,i)[e].findIndex(s);_>-1&&o(this,i)[e].splice(_,1);return}Reflect.deleteProperty(o(this,i),e)}_dispatchEvent(e,s){return Array.isArray(o(this,i)[e])?(o(this,i)[e].forEach(_=>_(s)),!0):!1}_dispatchMessageEvents(e,s){let _=e._id;Array.isArray(o(this,i)[_])&&(o(this,i)[_].forEach(r=>{try{s&&Object.keys(s).length===1&&e.command!==t.API?r(Object.values(s)[0]):r(s)}catch(a){console.error("Message callback error: ",a)}}),this._removeEventListener(_))}}i=new WeakMap;class T extends S{_postMessageAsync(e,s,_,r){return new Promise((a,c)=>{const R=u(e.toLowerCase());C({_id:R,command:e,...s}),P[R]=this,this._addEventListener(R,async O=>{O!=null&&O.errorMessage?c(O):(_&&r&&(O=await r(O)),a(O))})})}_postMessage(e,s,_){const r=u(e.toLowerCase());C({_id:r,command:e,...s}),_&&this._addEventListener(s.eventName,_)}}class D extends T{constructor(s){super();p(this,M);this._id=s.componentId,this.type="Component",P[this._id]=this,g(this,M,L).call(this,s.componentMethods)}onMount(s){this._postMessage(t.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:A.COMPONENT_ON_MOUNT,eventConfig:{once:!0}},s)}refresh(){return this._postMessageAsync(t.COMPONENT_REFRESH,{id:this._id})}show(){return this._postMessageAsync(t.COMPONENT_SHOW,{id:this._id})}hide(){return this._postMessageAsync(t.COMPONENT_HIDE,{id:this._id})}}M=new WeakSet,L=function(s){s==null||s.forEach(_=>{this[_.name]=(...r)=>{if(_.type==="method")return this._postMessageAsync(`COMPONENT_${_.name}`,{id:this._id,parameters:r});_.type==="event"&&this._postMessage(t.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:_.name,eventConfig:r[1]},r[0])}})};class G extends T{constructor(e){super(),this._id=e,this.type="CustomComponent",P[this._id]=this}watchParams(e){this._postMessage(t.CC_WATCH_PARAMS,{id:this._id,eventName:A.CC_ON_PARAMS_CHANGE,eventConfig:{once:!1}},e)}}class f extends T{constructor(e){super(),this.type="Popup",this._id=e.popupId||N.POPUP_ID}getParameter(e){return this._postMessageAsync(t.GET_POPUP_PARAMS,{key:e,popupId:this._id})}getAllParameters(){return this._postMessageAsync(t.GET_ALL_POPUP_PARAMS,{popupId:this._id})}close(){return this._postMessageAsync(t.CLOSE_POPUP,{})}getComponent(e){return this._postMessageAsync(t.COMPONENT_GET,{componentId:e},!0,s=>new D(s))}}class I extends T{constructor(e){super(),this.type="Page",this.popup=new f({}),this._id=e.pageId}getParameter(e){return this._postMessageAsync(t.GET_PAGE_PARAMS,{key:e})}getAllParameters(){return this._postMessageAsync(t.GET_ALL_PAGE_PARAMS,{pageId:this._id})}getVariable(e){return this._postMessageAsync(t.GET_PAGE_VARIABLE,{key:e})}setVariable(e,s){return this._postMessageAsync(t.SET_PAGE_VARIABLE,{key:e,value:s})}openPopup(e,s){return this._postMessageAsync(t.OPEN_POPUP,{popupId:e,popupParams:s})}getComponent(e){return this._postMessageAsync(t.COMPONENT_GET,{componentId:e},!0,s=>new D(s))}}class y extends T{constructor(e){super(),this.flowId=e}evaluate(e){return this._postMessageAsync(t.DECISION_TABLE_EXECUTE,{flowId:this.flowId,payload:e})}}class F extends T{constructor(e){super(),this._id=e}importCSV(e){return this._postMessageAsync(t.DATAFORM_IMPORT_CSV,{flowId:this._id,defaultValues:e})}}class W extends T{constructor(e){super(),this._id=e.appId,this.page=new I(e)}getVariable(e){return this._postMessageAsync(t.GET_APP_VARIABLE,{key:e})}setVariable(e,s){return this._postMessageAsync(t.SET_APP_VARIABLE,{key:e,value:s})}openPage(e,s){return this._postMessageAsync(t.OPEN_PAGE,{pageId:e,pageParams:s})}getDecisionTable(e){return new y(e)}getDataform(e){return new F(e)}}class m extends T{showInfo(e){return super._postMessageAsync(t.MESSAGE,{message:e})}showConfirm(e){return super._postMessageAsync(t.CONFIRM,{data:{title:e.title,content:e.content,okText:e.okText||"Ok",cancelText:e.cancelText||"Cancel"}})}redirect(e){return super._postMessageAsync(t.REDIRECT,{url:e})}}class B extends T{toDate(e){return this._postMessageAsync(t.FORMAT_DATE,{date:e})}toDateTime(e){return this._postMessageAsync(t.FORMAT_DATE_TIME,{date:e})}toNumber(e){return this._postMessageAsync(t.FORMAT_NUMBER,{value:e})}toCurrency(e,s){return this._postMessageAsync(t.FORMAT_CURRENCY,{value:e,currencyCode:s})}toBoolean(e){return this._postMessageAsync(t.FORMAT_BOOLEAN,{value:e})}}class U extends T{constructor(){super()}api(e,s={}){return this._postMessageAsync(t.API,{url:e,args:s})}initialize(){return this._postMessageAsync(t.CC_INITIALIZE,{},!0,e=>(this.app=new W(e),this.page=new I(e),this.context=new G(e.componentId),this.client=new m,this.formatter=new B,this.user=e.user,this.account=e.account,this.env=e.envDetails,this))}initialise(){return this.initialize()}}var V=new U;return V});
|