@kissflow/lowcode-client-sdk 1.0.0 → 1.0.2-0.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 +398 -102
- package/dist/index.d.ts +252 -76
- package/dist/kf.lowcodeworkersdk.es.js +649 -0
- package/dist/kf.nocodeworkersdk.es.js +454 -0
- package/dist/kfsdk.es.js +467 -0
- package/dist/kfsdk.umd.js +1 -0
- package/dist/lowcode.d.ts +308 -0
- package/dist/lowcode.types.d.ts +105 -0
- package/dist/nocode.d.ts +305 -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 -77
- package/dist/global.types.d.ts +0 -54
- package/dist/index.html +0 -23
- package/dist/kflowcode.sdk.js +0 -663
- package/dist/kflowcode.sdk.js.map +0 -1
- package/dist/kflowcode.sdk.module.js +0 -643
- package/dist/kflowcode.sdk.module.js.map +0 -1
- package/dist/lcnc.sdk.js +0 -662
- package/dist/lcnc.sdk.js.map +0 -1
- 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 -18
- package/webpack.config.js +0 -63
package/dist/kfsdk.es.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
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
|
+
};
|
|
86
|
+
const EVENT_TYPES = {
|
|
87
|
+
COMPONENT_ON_MOUNT: "componentOnMount",
|
|
88
|
+
CC_ON_PARAMS_CHANGE: "onCustomComponentParamsChange"
|
|
89
|
+
};
|
|
90
|
+
const DEFAULTS = {
|
|
91
|
+
POPUP_ID: "ACTIVE_POP_UP"
|
|
92
|
+
};
|
|
93
|
+
function generateId(prefix = "lcncsdk") {
|
|
94
|
+
return `${prefix}-${nanoid()}`;
|
|
95
|
+
}
|
|
96
|
+
const globalInstances = {};
|
|
97
|
+
function postMessage(args) {
|
|
98
|
+
if (globalThis.parent && globalThis.parent !== globalThis) {
|
|
99
|
+
globalThis.parent.postMessage(args, "*");
|
|
100
|
+
} else {
|
|
101
|
+
globalThis.postMessage(args);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function onMessage(event) {
|
|
105
|
+
if (event.origin !== globalThis.location.origin) {
|
|
106
|
+
const data = event.data;
|
|
107
|
+
if (data == null ? void 0 : data.isEvent) {
|
|
108
|
+
const { target, eventParams, eventName, eventConfig = {} } = data;
|
|
109
|
+
let targetInstance = globalInstances[target];
|
|
110
|
+
targetInstance._dispatchEvent(eventName, eventParams);
|
|
111
|
+
if (eventConfig.once) {
|
|
112
|
+
targetInstance._removeEventListener(eventName);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let { _req: req, resp } = data;
|
|
117
|
+
if (req == null ? void 0 : req._id) {
|
|
118
|
+
let targetInstance = globalInstances[req._id];
|
|
119
|
+
targetInstance._dispatchMessageEvents(req, resp);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
globalThis.addEventListener("message", onMessage);
|
|
124
|
+
class EventBase {
|
|
125
|
+
constructor() {
|
|
126
|
+
__privateAdd(this, _listeners, void 0);
|
|
127
|
+
__privateSet(this, _listeners, {});
|
|
128
|
+
}
|
|
129
|
+
_addEventListener(eventName, callBack) {
|
|
130
|
+
var _a;
|
|
131
|
+
__privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
|
|
132
|
+
__privateGet(this, _listeners)[eventName].push(callBack);
|
|
133
|
+
}
|
|
134
|
+
_removeEventListener(eventName, callBack) {
|
|
135
|
+
if (callBack) {
|
|
136
|
+
let index2 = __privateGet(this, _listeners)[eventName].findIndex(callBack);
|
|
137
|
+
index2 > -1 && __privateGet(this, _listeners)[eventName].splice(index2, 1);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
|
|
141
|
+
}
|
|
142
|
+
_dispatchEvent(eventName, eventParams) {
|
|
143
|
+
if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
|
|
144
|
+
__privateGet(this, _listeners)[eventName].forEach(
|
|
145
|
+
(callBack) => callBack(eventParams)
|
|
146
|
+
);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
_dispatchMessageEvents(req, resp) {
|
|
152
|
+
let target = req._id;
|
|
153
|
+
if (Array.isArray(__privateGet(this, _listeners)[target])) {
|
|
154
|
+
__privateGet(this, _listeners)[target].forEach((listener) => {
|
|
155
|
+
try {
|
|
156
|
+
if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
|
|
157
|
+
listener(Object.values(resp)[0]);
|
|
158
|
+
} else {
|
|
159
|
+
listener(resp);
|
|
160
|
+
}
|
|
161
|
+
} catch (err) {
|
|
162
|
+
console.error("Message callback error: ", err);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
this._removeEventListener(target);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_listeners = new WeakMap();
|
|
170
|
+
class BaseSDK extends EventBase {
|
|
171
|
+
_postMessageAsync(command, args, hasCallBack, callBack) {
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
const _id = generateId(command.toLowerCase());
|
|
174
|
+
postMessage({ _id, command, ...args });
|
|
175
|
+
globalInstances[_id] = this;
|
|
176
|
+
this._addEventListener(_id, async (data) => {
|
|
177
|
+
if (data == null ? void 0 : data.errorMessage) {
|
|
178
|
+
reject(data);
|
|
179
|
+
} else {
|
|
180
|
+
if (hasCallBack && callBack) {
|
|
181
|
+
data = await callBack(data);
|
|
182
|
+
}
|
|
183
|
+
resolve(data);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
_postMessage(command, args, callBack) {
|
|
189
|
+
const _id = generateId(command.toLowerCase());
|
|
190
|
+
postMessage({ _id, command, ...args });
|
|
191
|
+
if (callBack) {
|
|
192
|
+
this._addEventListener(args.eventName, callBack);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
class Component extends BaseSDK {
|
|
197
|
+
constructor(props) {
|
|
198
|
+
super();
|
|
199
|
+
__privateAdd(this, _registerComponentAPIs);
|
|
200
|
+
this._id = props.componentId;
|
|
201
|
+
this.type = "Component";
|
|
202
|
+
globalInstances[this._id] = this;
|
|
203
|
+
__privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
|
|
204
|
+
}
|
|
205
|
+
onMount(callback) {
|
|
206
|
+
this._postMessage(
|
|
207
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
208
|
+
{
|
|
209
|
+
id: this._id,
|
|
210
|
+
eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
|
|
211
|
+
eventConfig: {
|
|
212
|
+
once: true
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
callback
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
refresh() {
|
|
219
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
|
|
220
|
+
id: this._id
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
show() {
|
|
224
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_SHOW, {
|
|
225
|
+
id: this._id
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
hide() {
|
|
229
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_HIDE, {
|
|
230
|
+
id: this._id
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
_registerComponentAPIs = new WeakSet();
|
|
235
|
+
registerComponentAPIs_fn = function(componentAPIs) {
|
|
236
|
+
componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
|
|
237
|
+
this[Api.name] = (...args) => {
|
|
238
|
+
if (Api.type === "method") {
|
|
239
|
+
return this._postMessageAsync(`COMPONENT_${Api.name}`, {
|
|
240
|
+
id: this._id,
|
|
241
|
+
parameters: args
|
|
242
|
+
});
|
|
243
|
+
} else if (Api.type === "event") {
|
|
244
|
+
this._postMessage(
|
|
245
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
246
|
+
{
|
|
247
|
+
id: this._id,
|
|
248
|
+
eventName: Api.name,
|
|
249
|
+
eventConfig: args[1]
|
|
250
|
+
},
|
|
251
|
+
args[0]
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
class CustomComponent extends BaseSDK {
|
|
258
|
+
constructor(id) {
|
|
259
|
+
super();
|
|
260
|
+
this._id = id;
|
|
261
|
+
this.type = "CustomComponent";
|
|
262
|
+
globalInstances[this._id] = this;
|
|
263
|
+
}
|
|
264
|
+
watchParams(callBack) {
|
|
265
|
+
this._postMessage(
|
|
266
|
+
LISTENER_CMDS.CC_WATCH_PARAMS,
|
|
267
|
+
{
|
|
268
|
+
id: this._id,
|
|
269
|
+
eventName: EVENT_TYPES.CC_ON_PARAMS_CHANGE,
|
|
270
|
+
eventConfig: {
|
|
271
|
+
once: false
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
callBack
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
class Popup extends BaseSDK {
|
|
279
|
+
constructor(props) {
|
|
280
|
+
super();
|
|
281
|
+
this.type = "Popup";
|
|
282
|
+
this._id = props.popupId || DEFAULTS.POPUP_ID;
|
|
283
|
+
}
|
|
284
|
+
getParameter(key) {
|
|
285
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_POPUP_PARAMS, {
|
|
286
|
+
key,
|
|
287
|
+
popupId: this._id
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
getAllParameters() {
|
|
291
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_POPUP_PARAMS, {
|
|
292
|
+
popupId: this._id
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
close() {
|
|
296
|
+
return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
|
|
297
|
+
}
|
|
298
|
+
getComponent(componentId) {
|
|
299
|
+
return this._postMessageAsync(
|
|
300
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
301
|
+
{ componentId },
|
|
302
|
+
true,
|
|
303
|
+
(data) => {
|
|
304
|
+
return new Component(data);
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
class Page extends BaseSDK {
|
|
310
|
+
constructor(props) {
|
|
311
|
+
super();
|
|
312
|
+
this.type = "Page";
|
|
313
|
+
this.popup = new Popup({});
|
|
314
|
+
this._id = props.pageId;
|
|
315
|
+
}
|
|
316
|
+
getParameter(key) {
|
|
317
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
|
|
318
|
+
key
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
getAllParameters() {
|
|
322
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_ALL_PAGE_PARAMS, {
|
|
323
|
+
pageId: this._id
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
getVariable(key) {
|
|
327
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_VARIABLE, {
|
|
328
|
+
key
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
setVariable(key, value) {
|
|
332
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_PAGE_VARIABLE, {
|
|
333
|
+
key,
|
|
334
|
+
value
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
openPopup(popupId, popupParams) {
|
|
338
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_POPUP, {
|
|
339
|
+
popupId,
|
|
340
|
+
popupParams
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
getComponent(componentId) {
|
|
344
|
+
return this._postMessageAsync(
|
|
345
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
346
|
+
{ componentId },
|
|
347
|
+
true,
|
|
348
|
+
(data) => new Component(data)
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
class DecisionTable extends BaseSDK {
|
|
353
|
+
constructor(flowId) {
|
|
354
|
+
super();
|
|
355
|
+
this.flowId = flowId;
|
|
356
|
+
}
|
|
357
|
+
evaluate(payload) {
|
|
358
|
+
return this._postMessageAsync(LISTENER_CMDS.DECISION_TABLE_EXECUTE, {
|
|
359
|
+
flowId: this.flowId,
|
|
360
|
+
payload
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
class Application extends BaseSDK {
|
|
365
|
+
constructor(props) {
|
|
366
|
+
super();
|
|
367
|
+
this._id = props.appId;
|
|
368
|
+
this.page = new Page(props);
|
|
369
|
+
}
|
|
370
|
+
getVariable(key) {
|
|
371
|
+
return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
|
|
372
|
+
key
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
setVariable(key, value) {
|
|
376
|
+
return this._postMessageAsync(LISTENER_CMDS.SET_APP_VARIABLE, {
|
|
377
|
+
key,
|
|
378
|
+
value
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
openPage(pageId, pageParams) {
|
|
382
|
+
return this._postMessageAsync(LISTENER_CMDS.OPEN_PAGE, {
|
|
383
|
+
pageId,
|
|
384
|
+
pageParams
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
getDecisionTable(flowId) {
|
|
388
|
+
return new DecisionTable(flowId);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
class Client extends BaseSDK {
|
|
392
|
+
showInfo(message) {
|
|
393
|
+
return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
|
|
394
|
+
}
|
|
395
|
+
showConfirm(args) {
|
|
396
|
+
return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
|
|
397
|
+
data: {
|
|
398
|
+
title: args.title,
|
|
399
|
+
content: args.content,
|
|
400
|
+
okText: args.okText || "Ok",
|
|
401
|
+
cancelText: args.cancelText || "Cancel"
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
redirect(url) {
|
|
406
|
+
return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
class Formatter extends BaseSDK {
|
|
410
|
+
toDate(date) {
|
|
411
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
|
|
412
|
+
date
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
toDateTime(date) {
|
|
416
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
|
|
417
|
+
date
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
toNumber(value) {
|
|
421
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
|
|
422
|
+
value
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
toCurrency(value, currencyCode) {
|
|
426
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
|
|
427
|
+
value,
|
|
428
|
+
currencyCode
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
toBoolean(value) {
|
|
432
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
|
|
433
|
+
value
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
class CustomComponentSDK extends BaseSDK {
|
|
438
|
+
constructor() {
|
|
439
|
+
super();
|
|
440
|
+
}
|
|
441
|
+
api(url, args = {}) {
|
|
442
|
+
return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
|
|
443
|
+
}
|
|
444
|
+
initialize() {
|
|
445
|
+
return this._postMessageAsync(
|
|
446
|
+
LISTENER_CMDS.CC_INITIALIZE,
|
|
447
|
+
{},
|
|
448
|
+
true,
|
|
449
|
+
(data) => {
|
|
450
|
+
this.app = new Application(data);
|
|
451
|
+
this.page = new Page(data);
|
|
452
|
+
this.context = new CustomComponent(data.componentId);
|
|
453
|
+
this.client = new Client();
|
|
454
|
+
this.formatter = new Formatter();
|
|
455
|
+
this.user = data.user;
|
|
456
|
+
this.account = data.account;
|
|
457
|
+
this.env = data.envDetails;
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
initialise() {
|
|
463
|
+
return this.initialize();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
var index = new CustomComponentSDK();
|
|
467
|
+
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,R)=>(h(E,t,"write to private field"),R?R.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"},A={COMPONENT_ON_MOUNT:"componentOnMount",CC_ON_PARAMS_CHANGE:"onCustomComponentParamsChange"},R={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:N={}}=e;let T=P[r];T._dispatchEvent(c,a),N.once&&T._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 O extends S{_postMessageAsync(e,s,_,r){return new Promise((a,c)=>{const N=u(e.toLowerCase());C({_id:N,command:e,...s}),P[N]=this,this._addEventListener(N,async T=>{T!=null&&T.errorMessage?c(T):(_&&r&&(T=await r(T)),a(T))})})}_postMessage(e,s,_){const r=u(e.toLowerCase());C({_id:r,command:e,...s}),_&&this._addEventListener(s.eventName,_)}}class D extends O{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 O{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 O{constructor(e){super(),this.type="Popup",this._id=e.popupId||R.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 O{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 W extends O{constructor(e){super(),this.flowId=e}evaluate(e){return this._postMessageAsync(t.DECISION_TABLE_EXECUTE,{flowId:this.flowId,payload:e})}}class y extends O{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 W(e)}}class F extends O{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 m extends O{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 B extends O{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 y(e),this.page=new I(e),this.context=new G(e.componentId),this.client=new F,this.formatter=new m,this.user=e.user,this.account=e.account,this.env=e.envDetails,this))}initialise(){return this.initialize()}}var U=new B;return U});
|