@kissflow/lowcode-client-sdk 1.0.12 → 1.0.13
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 +28 -12
- package/dist/global.types.d.ts +40 -39
- package/dist/index.d.ts +105 -67
- package/dist/kfsdk.es.js +227 -160
- package/dist/kfsdk.umd.js +1 -1
- package/dist/kfworkersdk.es.js +253 -119
- package/dist/lowcode.d.ts +131 -94
- package/package.json +4 -12
package/dist/kfsdk.es.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
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
1
|
var __accessCheck = (obj, member, msg) => {
|
|
18
2
|
if (!member.has(obj))
|
|
19
3
|
throw TypeError("Cannot " + msg);
|
|
@@ -36,7 +20,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
36
20
|
__accessCheck(obj, member, "access private method");
|
|
37
21
|
return method;
|
|
38
22
|
};
|
|
39
|
-
var _listeners,
|
|
23
|
+
var _listeners, _registerComponentAPIs, registerComponentAPIs_fn;
|
|
40
24
|
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
41
25
|
byte &= 63;
|
|
42
26
|
if (byte < 36) {
|
|
@@ -52,7 +36,6 @@ let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce(
|
|
|
52
36
|
}, "");
|
|
53
37
|
const LISTENER_CMDS = {
|
|
54
38
|
API: "API",
|
|
55
|
-
PARAMS: "PARAMS",
|
|
56
39
|
GET_CONTEXT: "GET_CONTEXT",
|
|
57
40
|
RETURN: "RETURN",
|
|
58
41
|
GET_FORM_FIELD: "GET_FORM_FIELD",
|
|
@@ -84,11 +67,23 @@ const LISTENER_CMDS = {
|
|
|
84
67
|
GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
|
|
85
68
|
GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
|
|
86
69
|
CLOSE_POPUP: "CLOSE_POPUP",
|
|
87
|
-
|
|
70
|
+
COMPONENT_GET: "COMPONENT_GET",
|
|
88
71
|
COMPONENT_REFRESH: "COMPONENT_REFRESH",
|
|
89
72
|
COMPONENT_SHOW: "COMPONENT_SHOW",
|
|
90
73
|
COMPONENT_HIDE: "COMPONENT_HIDE",
|
|
91
|
-
|
|
74
|
+
COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
|
|
75
|
+
CC_INITIALIZE: "CC_INITIALIZE",
|
|
76
|
+
CC_WATCH_PARAMS: "CC_WATCH_PARAMS",
|
|
77
|
+
WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
|
|
78
|
+
WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
|
|
79
|
+
WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
|
|
80
|
+
WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
|
|
81
|
+
WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
|
|
82
|
+
WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN"
|
|
83
|
+
};
|
|
84
|
+
const EVENT_TYPES = {
|
|
85
|
+
COMPONENT_ON_MOUNT: "componentOnMount",
|
|
86
|
+
CC_ON_PARAMS_CHANGE: "onCustomComponentParamsChange"
|
|
92
87
|
};
|
|
93
88
|
const DEFAULTS = {
|
|
94
89
|
POPUP_ID: "ACTIVE_POP_UP"
|
|
@@ -96,30 +91,87 @@ const DEFAULTS = {
|
|
|
96
91
|
function generateId(prefix = "lcncsdk") {
|
|
97
92
|
return `${prefix}-${nanoid()}`;
|
|
98
93
|
}
|
|
94
|
+
const globalInstances = {};
|
|
99
95
|
function postMessage(args) {
|
|
100
|
-
if (
|
|
101
|
-
|
|
96
|
+
if (globalThis.parent && globalThis.parent !== globalThis) {
|
|
97
|
+
globalThis.parent.postMessage(args, "*");
|
|
102
98
|
} else {
|
|
103
|
-
|
|
99
|
+
globalThis.postMessage(args);
|
|
104
100
|
}
|
|
105
101
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
function onMessage(event) {
|
|
103
|
+
if (event.origin !== globalThis.location.origin) {
|
|
104
|
+
const data = event.data;
|
|
105
|
+
if (data == null ? void 0 : data.isEvent) {
|
|
106
|
+
const { target, eventParams, eventName, eventConfig = {} } = data;
|
|
107
|
+
let targetInstance = globalInstances[target];
|
|
108
|
+
targetInstance._dispatchEvent(eventName, eventParams);
|
|
109
|
+
if (eventConfig.once) {
|
|
110
|
+
targetInstance._removeEventListener(eventName);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let { _req: req, resp } = data;
|
|
115
|
+
if (req == null ? void 0 : req._id) {
|
|
116
|
+
let targetInstance = globalInstances[req._id];
|
|
117
|
+
targetInstance._dispatchMessageEvents(req, resp);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
globalThis.addEventListener("message", onMessage);
|
|
122
|
+
class EventBase {
|
|
123
|
+
constructor() {
|
|
112
124
|
__privateAdd(this, _listeners, void 0);
|
|
113
|
-
__privateAdd(this, _eventListeners, void 0);
|
|
114
125
|
__privateSet(this, _listeners, {});
|
|
115
|
-
__privateSet(this, _eventListeners, {});
|
|
116
|
-
self.addEventListener("message", __privateMethod(this, _onMessage, onMessage_fn).bind(this), false);
|
|
117
126
|
}
|
|
127
|
+
_addEventListener(eventName, callBack) {
|
|
128
|
+
var _a;
|
|
129
|
+
__privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
|
|
130
|
+
__privateGet(this, _listeners)[eventName].push(callBack);
|
|
131
|
+
}
|
|
132
|
+
_removeEventListener(eventName, callBack) {
|
|
133
|
+
if (callBack) {
|
|
134
|
+
let index2 = __privateGet(this, _listeners)[eventName].findIndex(callBack);
|
|
135
|
+
index2 > -1 && __privateGet(this, _listeners)[eventName].splice(index2, 1);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
|
|
139
|
+
}
|
|
140
|
+
_dispatchEvent(eventName, eventParams) {
|
|
141
|
+
if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
|
|
142
|
+
__privateGet(this, _listeners)[eventName].forEach(
|
|
143
|
+
(callBack) => callBack(eventParams)
|
|
144
|
+
);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
_dispatchMessageEvents(req, resp) {
|
|
150
|
+
let target = req._id;
|
|
151
|
+
if (Array.isArray(__privateGet(this, _listeners)[target])) {
|
|
152
|
+
__privateGet(this, _listeners)[target].forEach((listener) => {
|
|
153
|
+
try {
|
|
154
|
+
if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
|
|
155
|
+
listener(Object.values(resp)[0]);
|
|
156
|
+
} else {
|
|
157
|
+
listener(resp);
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error("Message callback error: ", err);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
this._removeEventListener(target);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
_listeners = new WeakMap();
|
|
168
|
+
class BaseSDK extends EventBase {
|
|
118
169
|
_postMessageAsync(command, args, hasCallBack, callBack) {
|
|
119
170
|
return new Promise((resolve, reject) => {
|
|
120
171
|
const _id = generateId(command.toLowerCase());
|
|
121
|
-
postMessage(
|
|
122
|
-
|
|
172
|
+
postMessage({ _id, command, ...args });
|
|
173
|
+
globalInstances[_id] = this;
|
|
174
|
+
this._addEventListener(_id, async (data) => {
|
|
123
175
|
if (data == null ? void 0 : data.errorMessage) {
|
|
124
176
|
reject(data);
|
|
125
177
|
} else {
|
|
@@ -131,114 +183,35 @@ class BaseSDK {
|
|
|
131
183
|
});
|
|
132
184
|
});
|
|
133
185
|
}
|
|
134
|
-
_postMessage(command,
|
|
186
|
+
_postMessage(command, args, callBack) {
|
|
135
187
|
const _id = generateId(command.toLowerCase());
|
|
136
|
-
postMessage(
|
|
137
|
-
|
|
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
|
+
postMessage({ _id, command, ...args });
|
|
189
|
+
if (callBack) {
|
|
190
|
+
this._addEventListener(args.eventName, callBack);
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
|
-
};
|
|
191
|
-
class Client extends BaseSDK {
|
|
192
|
-
showInfo(message) {
|
|
193
|
-
return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
|
|
194
|
-
}
|
|
195
|
-
showConfirm(args) {
|
|
196
|
-
return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
|
|
197
|
-
data: {
|
|
198
|
-
title: args.title,
|
|
199
|
-
content: args.content,
|
|
200
|
-
okText: args.okText || "Ok",
|
|
201
|
-
cancelText: args.cancelText || "Cancel"
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
redirect(url) {
|
|
206
|
-
return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
class Formatter extends BaseSDK {
|
|
210
|
-
toDate(date) {
|
|
211
|
-
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
|
|
212
|
-
date
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
toDateTime(date) {
|
|
216
|
-
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
|
|
217
|
-
date
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
toNumber(value) {
|
|
221
|
-
return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
|
|
222
|
-
value
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
toCurrency(value, currencyCode) {
|
|
226
|
-
return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
|
|
227
|
-
value,
|
|
228
|
-
currencyCode
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
toBoolean(value) {
|
|
232
|
-
return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
|
|
233
|
-
value
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
193
|
}
|
|
237
194
|
class Component extends BaseSDK {
|
|
238
195
|
constructor(props) {
|
|
239
|
-
super(
|
|
196
|
+
super();
|
|
197
|
+
__privateAdd(this, _registerComponentAPIs);
|
|
240
198
|
this._id = props.componentId;
|
|
241
199
|
this.type = "Component";
|
|
200
|
+
globalInstances[this._id] = this;
|
|
201
|
+
__privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
|
|
202
|
+
}
|
|
203
|
+
onMount(callback) {
|
|
204
|
+
this._postMessage(
|
|
205
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
206
|
+
{
|
|
207
|
+
id: this._id,
|
|
208
|
+
eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
|
|
209
|
+
eventConfig: {
|
|
210
|
+
once: true
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
callback
|
|
214
|
+
);
|
|
242
215
|
}
|
|
243
216
|
refresh() {
|
|
244
217
|
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
|
|
@@ -256,18 +229,53 @@ class Component extends BaseSDK {
|
|
|
256
229
|
});
|
|
257
230
|
}
|
|
258
231
|
}
|
|
232
|
+
_registerComponentAPIs = new WeakSet();
|
|
233
|
+
registerComponentAPIs_fn = function(componentAPIs) {
|
|
234
|
+
componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
|
|
235
|
+
this[Api.name] = (...args) => {
|
|
236
|
+
if (Api.type === "method") {
|
|
237
|
+
return this._postMessageAsync(`COMPONENT_${Api.name}`, {
|
|
238
|
+
id: this._id,
|
|
239
|
+
parameters: args
|
|
240
|
+
});
|
|
241
|
+
} else if (Api.type === "event") {
|
|
242
|
+
this._postMessage(
|
|
243
|
+
LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
|
|
244
|
+
{
|
|
245
|
+
id: this._id,
|
|
246
|
+
eventName: Api.name,
|
|
247
|
+
eventConfig: args[1]
|
|
248
|
+
},
|
|
249
|
+
args[0]
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
};
|
|
259
255
|
class CustomComponent extends BaseSDK {
|
|
260
|
-
constructor() {
|
|
261
|
-
super(
|
|
256
|
+
constructor(id) {
|
|
257
|
+
super();
|
|
258
|
+
this._id = id;
|
|
262
259
|
this.type = "CustomComponent";
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
260
|
+
globalInstances[this._id] = this;
|
|
261
|
+
}
|
|
262
|
+
watchParams(callBack) {
|
|
263
|
+
this._postMessage(
|
|
264
|
+
LISTENER_CMDS.CC_WATCH_PARAMS,
|
|
265
|
+
{
|
|
266
|
+
id: this._id,
|
|
267
|
+
eventName: EVENT_TYPES.CC_ON_PARAMS_CHANGE,
|
|
268
|
+
eventConfig: {
|
|
269
|
+
once: false
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
callBack
|
|
273
|
+
);
|
|
266
274
|
}
|
|
267
275
|
}
|
|
268
276
|
class Popup extends BaseSDK {
|
|
269
277
|
constructor(props) {
|
|
270
|
-
super(
|
|
278
|
+
super();
|
|
271
279
|
this.type = "Popup";
|
|
272
280
|
this._id = props.popupId || DEFAULTS.POPUP_ID;
|
|
273
281
|
}
|
|
@@ -286,14 +294,19 @@ class Popup extends BaseSDK {
|
|
|
286
294
|
return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
|
|
287
295
|
}
|
|
288
296
|
getComponent(componentId) {
|
|
289
|
-
return this._postMessageAsync(
|
|
290
|
-
|
|
291
|
-
|
|
297
|
+
return this._postMessageAsync(
|
|
298
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
299
|
+
{ componentId },
|
|
300
|
+
true,
|
|
301
|
+
(data) => {
|
|
302
|
+
return new Component(data);
|
|
303
|
+
}
|
|
304
|
+
);
|
|
292
305
|
}
|
|
293
306
|
}
|
|
294
307
|
class Page extends BaseSDK {
|
|
295
308
|
constructor(props) {
|
|
296
|
-
super(
|
|
309
|
+
super();
|
|
297
310
|
this.type = "Page";
|
|
298
311
|
this.popup = new Popup({});
|
|
299
312
|
this._id = props.pageId;
|
|
@@ -326,14 +339,17 @@ class Page extends BaseSDK {
|
|
|
326
339
|
});
|
|
327
340
|
}
|
|
328
341
|
getComponent(componentId) {
|
|
329
|
-
return this._postMessageAsync(
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
return this._postMessageAsync(
|
|
343
|
+
LISTENER_CMDS.COMPONENT_GET,
|
|
344
|
+
{ componentId },
|
|
345
|
+
true,
|
|
346
|
+
(data) => new Component(data)
|
|
347
|
+
);
|
|
332
348
|
}
|
|
333
349
|
}
|
|
334
350
|
class Application extends BaseSDK {
|
|
335
351
|
constructor(props) {
|
|
336
|
-
super(
|
|
352
|
+
super();
|
|
337
353
|
this._id = props.appId;
|
|
338
354
|
this.page = new Page(props);
|
|
339
355
|
}
|
|
@@ -355,25 +371,76 @@ class Application extends BaseSDK {
|
|
|
355
371
|
});
|
|
356
372
|
}
|
|
357
373
|
}
|
|
374
|
+
class Client extends BaseSDK {
|
|
375
|
+
showInfo(message) {
|
|
376
|
+
return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
|
|
377
|
+
}
|
|
378
|
+
showConfirm(args) {
|
|
379
|
+
return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
|
|
380
|
+
data: {
|
|
381
|
+
title: args.title,
|
|
382
|
+
content: args.content,
|
|
383
|
+
okText: args.okText || "Ok",
|
|
384
|
+
cancelText: args.cancelText || "Cancel"
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
redirect(url) {
|
|
389
|
+
return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
class Formatter extends BaseSDK {
|
|
393
|
+
toDate(date) {
|
|
394
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
|
|
395
|
+
date
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
toDateTime(date) {
|
|
399
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
|
|
400
|
+
date
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
toNumber(value) {
|
|
404
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
|
|
405
|
+
value
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
toCurrency(value, currencyCode) {
|
|
409
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
|
|
410
|
+
value,
|
|
411
|
+
currencyCode
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
toBoolean(value) {
|
|
415
|
+
return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
|
|
416
|
+
value
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
358
420
|
class CustomComponentSDK extends BaseSDK {
|
|
359
421
|
constructor() {
|
|
360
|
-
super(
|
|
422
|
+
super();
|
|
361
423
|
}
|
|
362
424
|
api(url, args = {}) {
|
|
363
425
|
return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
|
|
364
426
|
}
|
|
365
427
|
initialize() {
|
|
366
|
-
return this._postMessageAsync(
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
428
|
+
return this._postMessageAsync(
|
|
429
|
+
LISTENER_CMDS.CC_INITIALIZE,
|
|
430
|
+
{},
|
|
431
|
+
true,
|
|
432
|
+
(data) => {
|
|
433
|
+
this.app = new Application(data);
|
|
434
|
+
this.page = new Page(data);
|
|
435
|
+
this.context = new CustomComponent(data.componentId);
|
|
436
|
+
this.client = new Client();
|
|
437
|
+
this.formatter = new Formatter();
|
|
438
|
+
this.user = data.user;
|
|
439
|
+
this.account = data.account;
|
|
440
|
+
this.env = data.envDetails;
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
);
|
|
377
444
|
}
|
|
378
445
|
initialise() {
|
|
379
446
|
return this.initialize();
|
package/dist/kfsdk.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=(E,t,i)=>{if(!t.has(E))throw TypeError("Cannot "+i)};var o=(E,t,i)=>(c(E,t,"read from private field"),i?i.call(E):t.get(E)),p=(E,t,i)=>{if(t.has(E))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(E):t.set(E,i)},g=(E,t,i,a)=>(c(E,t,"write to private field"),a?a.call(E,i):t.set(E,i),i);var l=(E,t,i)=>(c(E,t,"access private method"),i);(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 A,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",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"},i={COMPONENT_ON_MOUNT:"componentOnMount",CC_ON_PARAMS_CHANGE:"onCustomComponentParamsChange"},a={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:R,eventName:h,eventConfig:N={}}=e;let T=P[r];T._dispatchEvent(h,R),N.once&&T._removeEventListener(h);return}let{_req:s,resp:_}=e;s!=null&&s._id&&P[s._id]._dispatchMessageEvents(s,_)}}globalThis.addEventListener("message",d);class S{constructor(){p(this,A,void 0);g(this,A,{})}_addEventListener(e,s){var _;o(this,A)[e]=((_=o(this,A))==null?void 0:_[e])||[],o(this,A)[e].push(s)}_removeEventListener(e,s){if(s){let _=o(this,A)[e].findIndex(s);_>-1&&o(this,A)[e].splice(_,1);return}Reflect.deleteProperty(o(this,A),e)}_dispatchEvent(e,s){return Array.isArray(o(this,A)[e])?(o(this,A)[e].forEach(_=>_(s)),!0):!1}_dispatchMessageEvents(e,s){let _=e._id;Array.isArray(o(this,A)[_])&&(o(this,A)[_].forEach(r=>{try{s&&Object.keys(s).length===1&&e.command!==t.API?r(Object.values(s)[0]):r(s)}catch(R){console.error("Message callback error: ",R)}}),this._removeEventListener(_))}}A=new WeakMap;class O extends S{_postMessageAsync(e,s,_,r){return new Promise((R,h)=>{const N=u(e.toLowerCase());C({_id:N,command:e,...s}),P[N]=this,this._addEventListener(N,async T=>{T!=null&&T.errorMessage?h(T):(_&&r&&(T=await r(T)),R(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,l(this,M,L).call(this,s.componentMethods)}onMount(s){this._postMessage(t.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:i.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:i.CC_ON_PARAMS_CHANGE,eventConfig:{once:!1}},e)}}class f extends O{constructor(e){super(),this.type="Popup",this._id=e.popupId||a.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 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})}}class W 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 F 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 m 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 W,this.formatter=new F,this.user=e.user,this.account=e.account,this.env=e.envDetails,this))}initialise(){return this.initialize()}}var B=new m;return B});
|