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