@kissflow/lowcode-client-sdk 1.0.9 → 1.0.12-beta
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 +105 -62
- package/dist/kfsdk.es.js +176 -127
- package/dist/kfsdk.umd.js +1 -1
- package/dist/kfworkersdk.es.js +198 -87
- package/dist/lowcode.d.ts +137 -93
- package/package.json +52 -53
package/dist/kfsdk.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var w=Object.defineProperty;var l=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var L=(_,s,E)=>s in _?w(_,s,{enumerable:!0,configurable:!0,writable:!0,value:E}):_[s]=E,h=(_,s)=>{for(var E in s||(s={}))x.call(s,E)&&L(_,E,s[E]);if(l)for(var E of l(s))b.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)},S=(_,s,E,a)=>(p(_,s,"write to private field"),a?a.call(_,E):s.set(_,E),E);var d=(_,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",PARAMS:"PARAMS",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",INITIALIZE_CUST_COMP:"INITIALIZE_CUST_COMP",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"},a={POPUP_ID:"ACTIVE_POP_UP"};function D(i="lcncsdk"){return`${i}-${_()}`}const N={};function I(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:P,eventName:c,eventConfig:R={}}=e;let T=N[r];T._dispatchEvent(c,P),R.once&&T._removeEventListener(c);return}let{_req:t,resp:n}=e;t!=null&&t._id&&N[t._id]._dispatchMessageEvents(t,n)}}globalThis.addEventListener("message",f);class y{constructor(){u(this,A,void 0);S(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(P){console.error("Message callback error: ",P)}}),this._removeEventListener(n))}}A=new WeakMap;class O extends y{_postMessageAsync(e,t,n,r){return new Promise((P,c)=>{const R=D(e.toLowerCase());I(h({_id:R,command:e},t)),N[R]=this,this._addEventListener(R,async T=>{T!=null&&T.errorMessage?c(T):(n&&r&&(T=await r(T)),P(T))})})}_postMessage(e,t,n){const r=D(e.toLowerCase());I(h({_id:r,command:e},t)),n&&this._addEventListener(t.eventName,n)}}class g extends O{constructor(t){super();u(this,M);this._id=t.componentId,this.type="Component",N[this._id]=this,d(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 F extends O{constructor(){super(),this.type="CustomComponent"}watchParams(e){this._postMessage(s.PARAMS,e)}}class W 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 g(t))}}class C extends O{constructor(e){super(),this.type="Page",this.popup=new W({}),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 g(t))}}class U extends O{constructor(e){super(),this._id=e.appId,this.page=new C(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 m 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 B 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.INITIALIZE_CUST_COMP,{},!0,e=>(this.app=new U(e),this.page=new C(e),this.context=new F,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 V;return v});
|
package/dist/kfworkersdk.es.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
var __accessCheck = (obj, member, msg) => {
|
|
18
21
|
if (!member.has(obj))
|
|
19
22
|
throw TypeError("Cannot " + msg);
|
|
@@ -36,7 +39,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
36
39
|
__accessCheck(obj, member, "access private method");
|
|
37
40
|
return method;
|
|
38
41
|
};
|
|
39
|
-
var _listeners,
|
|
42
|
+
var _listeners, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
|
|
40
43
|
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
41
44
|
byte &= 63;
|
|
42
45
|
if (byte < 36) {
|
|
@@ -84,11 +87,21 @@ const LISTENER_CMDS = {
|
|
|
84
87
|
GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
|
|
85
88
|
GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
|
|
86
89
|
CLOSE_POPUP: "CLOSE_POPUP",
|
|
87
|
-
|
|
90
|
+
COMPONENT_GET: "COMPONENT_GET",
|
|
88
91
|
COMPONENT_REFRESH: "COMPONENT_REFRESH",
|
|
89
92
|
COMPONENT_SHOW: "COMPONENT_SHOW",
|
|
90
93
|
COMPONENT_HIDE: "COMPONENT_HIDE",
|
|
91
|
-
|
|
94
|
+
COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
|
|
95
|
+
INITIALIZE_CUST_COMP: "INITIALIZE_CUST_COMP",
|
|
96
|
+
WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
|
|
97
|
+
WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
|
|
98
|
+
WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
|
|
99
|
+
WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
|
|
100
|
+
WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
|
|
101
|
+
WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN"
|
|
102
|
+
};
|
|
103
|
+
const EVENT_TYPES = {
|
|
104
|
+
COMPONENT_ON_MOUNT: "componentOnMount"
|
|
92
105
|
};
|
|
93
106
|
const DEFAULTS = {
|
|
94
107
|
POPUP_ID: "ACTIVE_POP_UP"
|
|
@@ -96,30 +109,85 @@ const DEFAULTS = {
|
|
|
96
109
|
function generateId(prefix = "lcncsdk") {
|
|
97
110
|
return `${prefix}-${nanoid()}`;
|
|
98
111
|
}
|
|
112
|
+
const globalInstances = {};
|
|
99
113
|
function postMessage(args) {
|
|
100
|
-
if (
|
|
101
|
-
|
|
114
|
+
if (globalThis.parent && globalThis.parent !== globalThis) {
|
|
115
|
+
globalThis.parent.postMessage(args, "*");
|
|
102
116
|
} else {
|
|
103
|
-
|
|
117
|
+
globalThis.postMessage(args);
|
|
104
118
|
}
|
|
105
119
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
function onMessage(event) {
|
|
121
|
+
if (event.origin !== globalThis.location.origin) {
|
|
122
|
+
const data = event.data;
|
|
123
|
+
if (data == null ? void 0 : data.isEvent) {
|
|
124
|
+
const { target, eventParams, eventName, eventConfig = {} } = data;
|
|
125
|
+
let targetInstance = globalInstances[target];
|
|
126
|
+
targetInstance._dispatchEvent(eventName, eventParams);
|
|
127
|
+
if (eventConfig.once) {
|
|
128
|
+
targetInstance._removeEventListener(eventName);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let { _req: req, resp } = data;
|
|
133
|
+
if (req == null ? void 0 : req._id) {
|
|
134
|
+
let targetInstance = globalInstances[req._id];
|
|
135
|
+
targetInstance._dispatchMessageEvents(req, resp);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
globalThis.addEventListener("message", onMessage);
|
|
140
|
+
class EventBase {
|
|
141
|
+
constructor() {
|
|
112
142
|
__privateAdd(this, _listeners, void 0);
|
|
113
|
-
__privateAdd(this, _eventListeners, void 0);
|
|
114
143
|
__privateSet(this, _listeners, {});
|
|
115
|
-
__privateSet(this, _eventListeners, {});
|
|
116
|
-
self.addEventListener("message", __privateMethod(this, _onMessage, onMessage_fn).bind(this), false);
|
|
117
144
|
}
|
|
145
|
+
_addEventListener(eventName, callBack) {
|
|
146
|
+
var _a;
|
|
147
|
+
__privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
|
|
148
|
+
__privateGet(this, _listeners)[eventName].push(callBack);
|
|
149
|
+
}
|
|
150
|
+
_removeEventListener(eventName, callBack) {
|
|
151
|
+
if (callBack) {
|
|
152
|
+
let index = __privateGet(this, _listeners)[eventName].findIndex(callBack);
|
|
153
|
+
index > -1 && __privateGet(this, _listeners)[eventName].splice(index, 1);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
|
|
157
|
+
}
|
|
158
|
+
_dispatchEvent(eventName, eventParams) {
|
|
159
|
+
if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
|
|
160
|
+
__privateGet(this, _listeners)[eventName].forEach((callBack) => callBack(eventParams));
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
_dispatchMessageEvents(req, resp) {
|
|
166
|
+
let target = req._id;
|
|
167
|
+
if (Array.isArray(__privateGet(this, _listeners)[target])) {
|
|
168
|
+
__privateGet(this, _listeners)[target].forEach((listener) => {
|
|
169
|
+
try {
|
|
170
|
+
if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
|
|
171
|
+
listener(Object.values(resp)[0]);
|
|
172
|
+
} else {
|
|
173
|
+
listener(resp);
|
|
174
|
+
}
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.error("Message callback error: ", err);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
this._removeEventListener(target);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
_listeners = new WeakMap();
|
|
184
|
+
class BaseSDK extends EventBase {
|
|
118
185
|
_postMessageAsync(command, args, hasCallBack, callBack) {
|
|
119
186
|
return new Promise((resolve, reject) => {
|
|
120
187
|
const _id = generateId(command.toLowerCase());
|
|
121
188
|
postMessage(__spreadValues({ _id, command }, args));
|
|
122
|
-
|
|
189
|
+
globalInstances[_id] = this;
|
|
190
|
+
this._addEventListener(_id, async (data) => {
|
|
123
191
|
if (data == null ? void 0 : data.errorMessage) {
|
|
124
192
|
reject(data);
|
|
125
193
|
} else {
|
|
@@ -131,66 +199,17 @@ class BaseSDK {
|
|
|
131
199
|
});
|
|
132
200
|
});
|
|
133
201
|
}
|
|
134
|
-
_postMessage(command,
|
|
202
|
+
_postMessage(command, args, callBack) {
|
|
135
203
|
const _id = generateId(command.toLowerCase());
|
|
136
204
|
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);
|
|
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
|
-
});
|
|
205
|
+
if (callBack) {
|
|
206
|
+
this._addEventListener(args.eventName, callBack);
|
|
188
207
|
}
|
|
189
208
|
}
|
|
190
|
-
}
|
|
209
|
+
}
|
|
191
210
|
class Form extends BaseSDK {
|
|
192
211
|
constructor(instanceId) {
|
|
193
|
-
super(
|
|
212
|
+
super();
|
|
194
213
|
this.type = "Form";
|
|
195
214
|
this.instanceId = instanceId;
|
|
196
215
|
}
|
|
@@ -216,7 +235,7 @@ class Form extends BaseSDK {
|
|
|
216
235
|
}
|
|
217
236
|
class Table extends BaseSDK {
|
|
218
237
|
constructor(instanceId, tableId) {
|
|
219
|
-
super(
|
|
238
|
+
super();
|
|
220
239
|
this.tableId = tableId;
|
|
221
240
|
this.instanceId = instanceId;
|
|
222
241
|
}
|
|
@@ -248,7 +267,7 @@ class Table extends BaseSDK {
|
|
|
248
267
|
}
|
|
249
268
|
class TableForm extends BaseSDK {
|
|
250
269
|
constructor(instanceId, tableId, rowId) {
|
|
251
|
-
super(
|
|
270
|
+
super();
|
|
252
271
|
this.instanceId = instanceId;
|
|
253
272
|
this.type = "TabelForm";
|
|
254
273
|
this.tableId = tableId;
|
|
@@ -328,9 +347,21 @@ class Formatter extends BaseSDK {
|
|
|
328
347
|
}
|
|
329
348
|
class Component extends BaseSDK {
|
|
330
349
|
constructor(props) {
|
|
331
|
-
super(
|
|
350
|
+
super();
|
|
351
|
+
__privateAdd(this, _registerComponentAPIs);
|
|
332
352
|
this._id = props.componentId;
|
|
333
353
|
this.type = "Component";
|
|
354
|
+
globalInstances[this._id] = this;
|
|
355
|
+
__privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
|
|
356
|
+
}
|
|
357
|
+
onMount(callback) {
|
|
358
|
+
this._postMessage(LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER, {
|
|
359
|
+
id: this._id,
|
|
360
|
+
eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
|
|
361
|
+
eventConfig: {
|
|
362
|
+
once: true
|
|
363
|
+
}
|
|
364
|
+
}, callback);
|
|
334
365
|
}
|
|
335
366
|
refresh() {
|
|
336
367
|
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
|
|
@@ -348,9 +379,28 @@ class Component extends BaseSDK {
|
|
|
348
379
|
});
|
|
349
380
|
}
|
|
350
381
|
}
|
|
382
|
+
_registerComponentAPIs = new WeakSet();
|
|
383
|
+
registerComponentAPIs_fn = function(componentAPIs) {
|
|
384
|
+
componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
|
|
385
|
+
this[Api.name] = (...args) => {
|
|
386
|
+
if (Api.type === "method") {
|
|
387
|
+
return this._postMessageAsync(`COMPONENT_${Api.name}`, {
|
|
388
|
+
id: this._id,
|
|
389
|
+
parameters: args
|
|
390
|
+
});
|
|
391
|
+
} else if (Api.type === "event") {
|
|
392
|
+
this._postMessage(LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER, {
|
|
393
|
+
id: this._id,
|
|
394
|
+
eventName: Api.name,
|
|
395
|
+
eventConfig: args[1]
|
|
396
|
+
}, args[0]);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
});
|
|
400
|
+
};
|
|
351
401
|
class Popup extends BaseSDK {
|
|
352
402
|
constructor(props) {
|
|
353
|
-
super(
|
|
403
|
+
super();
|
|
354
404
|
this.type = "Popup";
|
|
355
405
|
this._id = props.popupId || DEFAULTS.POPUP_ID;
|
|
356
406
|
}
|
|
@@ -369,14 +419,14 @@ class Popup extends BaseSDK {
|
|
|
369
419
|
return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
|
|
370
420
|
}
|
|
371
421
|
getComponent(componentId) {
|
|
372
|
-
return this._postMessageAsync(LISTENER_CMDS.
|
|
422
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_GET, { componentId }, true, (data) => {
|
|
373
423
|
return new Component(data);
|
|
374
424
|
});
|
|
375
425
|
}
|
|
376
426
|
}
|
|
377
427
|
class Page extends BaseSDK {
|
|
378
428
|
constructor(props) {
|
|
379
|
-
super(
|
|
429
|
+
super();
|
|
380
430
|
this.type = "Page";
|
|
381
431
|
this.popup = new Popup({});
|
|
382
432
|
this._id = props.pageId;
|
|
@@ -409,14 +459,12 @@ class Page extends BaseSDK {
|
|
|
409
459
|
});
|
|
410
460
|
}
|
|
411
461
|
getComponent(componentId) {
|
|
412
|
-
return this._postMessageAsync(LISTENER_CMDS.
|
|
413
|
-
return new Component(data);
|
|
414
|
-
});
|
|
462
|
+
return this._postMessageAsync(LISTENER_CMDS.COMPONENT_GET, { componentId }, true, (data) => new Component(data));
|
|
415
463
|
}
|
|
416
464
|
}
|
|
417
465
|
class Application extends BaseSDK {
|
|
418
466
|
constructor(props) {
|
|
419
|
-
super(
|
|
467
|
+
super();
|
|
420
468
|
this._id = props.appId;
|
|
421
469
|
this.page = new Page(props);
|
|
422
470
|
}
|
|
@@ -438,9 +486,59 @@ class Application extends BaseSDK {
|
|
|
438
486
|
});
|
|
439
487
|
}
|
|
440
488
|
}
|
|
489
|
+
class NDEFReader extends BaseSDK {
|
|
490
|
+
constructor() {
|
|
491
|
+
super();
|
|
492
|
+
this.id = generateId(LISTENER_CMDS.WINDOW_NDEF_READER_NEW);
|
|
493
|
+
globalInstances[this.id] = this;
|
|
494
|
+
this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_NEW, {
|
|
495
|
+
id: this.id,
|
|
496
|
+
operation: "new"
|
|
497
|
+
}, (data) => {
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
scan() {
|
|
501
|
+
return new Promise((resolve, reject) => {
|
|
502
|
+
this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_SCAN, { id: this.id, operation: "scan" }, ({ data, err }) => {
|
|
503
|
+
console.log("scan data from main window ", data);
|
|
504
|
+
resolve(data);
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
write(data) {
|
|
509
|
+
return new Promise((resolve, reject) => {
|
|
510
|
+
this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_WRITE, { id: this.id, operation: "write", data }, ({ data: data2, err }) => {
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
addEventListener(eventName, cb) {
|
|
515
|
+
this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_ADD_EVENT_LISTENER, {
|
|
516
|
+
id: this.id,
|
|
517
|
+
operation: "addEventListener",
|
|
518
|
+
eventName
|
|
519
|
+
}, () => {
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
makeReadOnly() {
|
|
523
|
+
return new Promise((resolve, reject) => {
|
|
524
|
+
this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_MAKE_READONLY, { id: this.id, operation: "makeReadOnly" }, ({ data, err }) => {
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
abortScan() {
|
|
529
|
+
return new Promise((resolve, reject) => {
|
|
530
|
+
this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_ABORT_SCAN, { id: this.id, operation: "abortScan" }, ({ data, err }) => {
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const window = {
|
|
536
|
+
NDEFReader
|
|
537
|
+
};
|
|
441
538
|
class LowcodeSDK extends BaseSDK {
|
|
442
539
|
constructor(props) {
|
|
443
|
-
super(
|
|
540
|
+
super();
|
|
541
|
+
__privateAdd(this, _csrfToken, void 0);
|
|
444
542
|
if (props.tableId && props.tableRowId) {
|
|
445
543
|
this.context = new TableForm(props.formInstanceId, props.tableId, props.tableRowId);
|
|
446
544
|
} else if (props.formInstanceId) {
|
|
@@ -452,19 +550,32 @@ class LowcodeSDK extends BaseSDK {
|
|
|
452
550
|
} else if (props.componentId) {
|
|
453
551
|
this.context = new Component(props);
|
|
454
552
|
}
|
|
455
|
-
this.client = new Client(
|
|
456
|
-
this.formatter = new Formatter(
|
|
553
|
+
this.client = new Client();
|
|
554
|
+
this.formatter = new Formatter();
|
|
457
555
|
if (props.appId) {
|
|
458
556
|
this.app = new Application(props);
|
|
459
557
|
}
|
|
460
558
|
this.user = props.user;
|
|
559
|
+
this.env = props.envDetails;
|
|
461
560
|
this.account = props.account;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
561
|
+
__privateSet(this, _csrfToken, props.csrfToken);
|
|
562
|
+
}
|
|
563
|
+
async api(url, args) {
|
|
564
|
+
const response = await globalThis.fetch(url, __spreadProps(__spreadValues({}, args), {
|
|
565
|
+
headers: __spreadProps(__spreadValues({}, (args == null ? void 0 : args.headers) || {}), {
|
|
566
|
+
"X-Csrf-Token": __privateGet(this, _csrfToken)
|
|
567
|
+
})
|
|
568
|
+
}));
|
|
569
|
+
const contentType = response.headers.get("content-type");
|
|
570
|
+
if (contentType && contentType.includes("application/json")) {
|
|
571
|
+
return await response.json();
|
|
572
|
+
} else {
|
|
573
|
+
return response;
|
|
574
|
+
}
|
|
465
575
|
}
|
|
466
576
|
}
|
|
577
|
+
_csrfToken = new WeakMap();
|
|
467
578
|
function initSDK(config) {
|
|
468
579
|
return new LowcodeSDK(config);
|
|
469
580
|
}
|
|
470
|
-
export { initSDK as default };
|
|
581
|
+
export { initSDK as default, window };
|