@kissflow/lowcode-client-sdk 1.0.2 → 1.0.3

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 CHANGED
@@ -26,28 +26,159 @@ SDK can also be loaded directly into HTML by adding:
26
26
  const kf = window.KF();
27
27
  ```
28
28
 
29
- ### 1) Form Functions
29
+ ## 1) Form Functions
30
30
 
31
- > Note: These function can be used only on button and other events inside the kissflow forms
32
- > Use Table:: as a prefix while using TableId
31
+ ### Main form functions
33
32
 
34
- ##### Get from field
33
+ `kf.currentForm` returns a `Form` class which has the following functions
34
+
35
+ ##### a) getField()
36
+ ###### Description:
37
+ Use this function to get the current value of a form field
38
+
39
+ ###### Syntax:
35
40
  ```js
36
41
  kf.currentForm.getField(fieldId).then((res) => {...})
37
42
  // or
38
43
  let value = await kf.currentForm.getField(fieldId)
39
44
  ```
40
- ##### Update form field
45
+
46
+ ##### b) updateField()
47
+ ###### Description:
48
+ Use this function to get update any field in the form
49
+ ###### Syntax:
41
50
  ```js
42
51
  kf.currentForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
43
52
  ```
44
- #### Update tableField
45
- Appends row details to the end of table.
53
+
54
+ ##### c) toJSON()
55
+ ###### Description:
56
+ Use this function to get the JSON data of the current form
57
+ ###### Syntax:
46
58
  ```js
47
- kf.currentForm.addTableRow("tableId", { columnId1: value, columnId2: value });
59
+ const json = await kf.currentForm.toJSON();
60
+ ```
61
+ ###### Output:
62
+ ```
63
+ {
64
+ "Untitled_Field": "testing",
65
+ "_created_at": "2022-03-01T03:04:09Z",
66
+ "_flow_name": "form events",
67
+ "_id": "Pk4_T1WGWuMe",
68
+ "_modified_at": "2022-03-01T03:04:09Z"
69
+ }
48
70
  ```
49
71
  ---
72
+ ### Table functions
73
+ `kf.currentForm.getTable(tableId)` returns a `Table` class which has the following functions
74
+ #### a) addRow()
75
+ ###### Description:
76
+ Appends row details to the end of table.
77
+ ###### Syntax:
78
+ ```js
79
+ const table = kf.currentForm.getTable(tableId);
80
+ table.addRow({ columnId1: value, columnId2: value });
81
+ ```
82
+ #### b) deleteRow()
83
+ ###### Description:
84
+ Deletes a row from the table based on the row id
85
+ ###### Syntax:
86
+ ```js
87
+ const table = kf.currentForm.getTable(tableId);
88
+ table.deleteRow(rowId);
89
+ ```
90
+ #### c) getRow()
91
+ ###### Description:
92
+ Use this function to perform form actions on any row inside a child table
93
+ ###### Syntax:
94
+ ```js
95
+ const table = kf.currentForm.getTable(tableId);
96
+ const row = table.getRow(rowId);
97
+ ```
98
+ ###### Output:
99
+ Returns an instance of `TableForm` class
50
100
 
101
+ #### d) getRows()
102
+ ###### Description:
103
+ Gets all the rows of the table
104
+ ###### Syntax:
105
+ ```js
106
+ const rows = await kf.currentForm.getTable(tableId).getRows();
107
+ ```
108
+ ###### Output:
109
+ Returns an array of `TableForm` instances
110
+
111
+ ##### e) toJSON()
112
+ ###### Description:
113
+ Use this function to get the JSON data of the child table
114
+ ###### Syntax:
115
+ ```js
116
+ const json = await kf.currentForm.getTable(tableId).toJSON();
117
+ ```
118
+ ###### Output:
119
+ ```
120
+ [{
121
+ "Untitled_Field": "row 1",
122
+ "_created_at": "2022-03-01T03:04:09Z",
123
+ "_flow_name": "form events",
124
+ "_id": "Pk4_T1WGWuMe",
125
+ "_modified_at": "2022-03-01T03:04:09Z"
126
+ },{
127
+ "Untitled_Field": "row 2",
128
+ "_created_at": "2022-03-01T03:04:09Z",
129
+ "_flow_name": "form events",
130
+ "_id": "Pk4_T1WGWuMe",
131
+ "_modified_at": "2022-03-01T03:04:09Z"
132
+ }]
133
+ ```
134
+ ---
135
+ ### Table Row functions
136
+ `kf.currentForm` returns a `TableForm` class which has the following functions
137
+
138
+ ##### a) getField()
139
+ ###### Description:
140
+ Use this function to get the value of the table row
141
+ ###### Syntax:
142
+ ```js
143
+ kf.currentForm.getField(fieldId).then((res) => {...})
144
+ // or
145
+ let value = await kf.currentForm.getField(fieldId)
146
+ ```
147
+ ##### b) updateField()
148
+ ###### Description:
149
+ Use this function to get update any field in the table row
150
+ ###### Syntax:
151
+ ```js
152
+ kf.currentForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
153
+ ```
154
+ ##### c) getParent()
155
+ ###### Description:
156
+ Use this function to perform form actions on the main form
157
+ ###### Syntax:
158
+ ```js
159
+ const mainForm = kf.currentForm.getParent();
160
+ mainForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
161
+ ```
162
+ ###### Output:
163
+ Returns an instance of `Form` class using which we can perform any action on the main form
164
+ ##### d) toJson()
165
+ ##### Description:
166
+ Get JSON output of table row
167
+ ##### Syntax:
168
+ ```js
169
+ const json = await kf.currentForm.toJSON();
170
+ ```
171
+ ###### Output:
172
+ ```
173
+ {
174
+ "Untitled_Field": "testing",
175
+ "_created_at": "2022-03-01T03:04:09Z",
176
+ "_flow_name": "form events",
177
+ "_id": "Pk4_T1WGWuMe",
178
+ "_modified_at": "2022-03-01T03:04:09Z"
179
+ }
180
+ ```
181
+ ---
51
182
  ### 2) Client Functions
52
183
  ##### Show Toast
53
184
  ```js
@@ -65,7 +196,15 @@ kf.client.redirect(url);
65
196
  ### 3) Component Functions
66
197
  #### Refresh a component
67
198
  ```js
68
- kf.getComponent(componentId).refresh();
199
+ kf.app.page.getComponent(componentId).refresh();
200
+ ```
201
+ #### Show a component
202
+ ```js
203
+ kf.app.page.getComponent(componentId).show();
204
+ ```
205
+ #### Hide a component
206
+ ```js
207
+ kf.app.page.getComponent(componentId).hide();
69
208
  ```
70
209
  ---
71
210
 
@@ -160,27 +299,27 @@ kf.watchParams(function (data) {
160
299
  ### 9) Formatter Functions
161
300
  ##### Format to KF Date
162
301
  ```js
163
- kf.formatter.toKfDate("08-24-2021").then((res) => {...})
302
+ kf.formatter.toDate("08-24-2021").then((res) => {...})
164
303
  // or
165
- let value = await kf.formatter.toKfDate("08-24-2021");
304
+ let value = await kf.formatter.toDate("08-24-2021");
166
305
  ```
167
306
  ##### Format to KF Date Time
168
307
  ```js
169
- kf.formatter.toKfDateTime("2021-08-26T14:30").then((res) => {...})
308
+ kf.formatter.toDateTime("2021-08-26T14:30").then((res) => {...})
170
309
  // or
171
- let value = await kf.formatter.toKfDateTime("2021-08-26T14:30");
310
+ let value = await kf.formatter.toDateTime("2021-08-26T14:30");
172
311
  ```
173
312
  ##### Format to KF Number
174
313
  ```js
175
- kf.formatter.toKfNumber("1,00,000.500000").then((res) => {...})
314
+ kf.formatter.toNumber("1,00,000.500000").then((res) => {...})
176
315
  // or
177
- let value = await kf.formatter.toKfNumber("1,00,000.500000");
316
+ let value = await kf.formatter.toNumber("1,00,000.500000");
178
317
  ```
179
318
  ##### Format to KF Currency
180
319
  ```js
181
- kf.formatter.toKfCurrency("1,00,000.500000", "USD").then((res) => {...})
320
+ kf.formatter.toCurrency("1,00,000.500000", "USD").then((res) => {...})
182
321
  // or
183
- let value = await kf.formatter.toKfCurrency("1,00,000.500000", "USD");
322
+ let value = await kf.formatter.toCurrency("1,00,000.500000", "USD");
184
323
  ```
185
324
  ##### Format to KF Boolean
186
325
  ```js
package/custom.build.js CHANGED
@@ -5,7 +5,9 @@ let classMappings = {
5
5
  Application: { name: "Application" },
6
6
  Client: { name: "Client" },
7
7
  Component: { name: "Component" },
8
- Form: { name: "Form" },
8
+ Form: { name: "Form" },
9
+ Table: { name: "Table" },
10
+ TableForm: { name: "TableForm" },
9
11
  Formatter: { name: "Formatter" },
10
12
  LowcodeSDK: { name: "kf", staticDeclarations: true }
11
13
  };
@@ -48,7 +50,25 @@ function transfromTypings() {
48
50
  // fields on Class
49
51
  for (let i = 0; i < _class.fields.length; i++) {
50
52
  // if (_class.fields[i].type.modulePath) {
51
- let className = _class.fields[i].type.typeName;
53
+ let className = "";
54
+ if (!_class.fields[i].type) {
55
+ continue
56
+ } else if(_class.fields[i].type.options) {
57
+ // TODO: currently we add only the first typechecking
58
+ className = _class.fields[i].type.options[0].typeName;
59
+
60
+ // TODO: need to handle when there are multiple type
61
+ // let options = _class.fields[i].type.options
62
+ // for (let j = 0; j < options.length; j++) {
63
+ // className += options[j].typeName;
64
+ // if (j < options.length - 1) {
65
+ // className += " | ";
66
+ // }
67
+ // }
68
+ } else {
69
+ className = _class.fields[i].type.typeName;
70
+ }
71
+
52
72
  let fieldName = _class.fields[i].name;
53
73
  // console.log(_class.fields[i]);
54
74
  toWrite += `\t${
package/dist/base.js CHANGED
@@ -152,14 +152,13 @@ _BaseSDK_listeners = new WeakMap(), _BaseSDK_eventListeners = new WeakMap(), _Ba
152
152
  if (listeners) {
153
153
  listeners.forEach(function (listener) {
154
154
  try {
155
- if (data_1.resp) {
156
- if (Object.keys(data_1.resp).length === 1 &&
157
- _req_1.command !== constants_1.LISTENER_CMDS.API) {
158
- listener(Object.values(data_1.resp)[0]);
159
- }
160
- else {
161
- listener(data_1.resp);
162
- }
155
+ if (data_1.resp &&
156
+ Object.keys(data_1.resp).length === 1 &&
157
+ _req_1.command !== constants_1.LISTENER_CMDS.API) {
158
+ listener(Object.values(data_1.resp)[0]);
159
+ }
160
+ else {
161
+ listener(data_1.resp);
163
162
  }
164
163
  }
165
164
  catch (err) {
package/dist/component.js CHANGED
@@ -30,6 +30,16 @@ var Component = /** @class */ (function (_super) {
30
30
  id: this.id
31
31
  });
32
32
  };
33
+ Component.prototype.show = function () {
34
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.COMPONENT_SHOW, {
35
+ id: this.id
36
+ });
37
+ };
38
+ Component.prototype.hide = function () {
39
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.COMPONENT_HIDE, {
40
+ id: this.id
41
+ });
42
+ };
33
43
  return Component;
34
44
  }(base_1.BaseSDK));
35
45
  exports.Component = Component;
package/dist/constants.js CHANGED
@@ -9,7 +9,12 @@ exports.LISTENER_CMDS = {
9
9
  //Forms SDK Functions
10
10
  GET_FORM_FIELD: "GET_FORM_FIELD",
11
11
  UPDATE_FORM: "UPDATE_FORM",
12
+ GET_TABLE: "GET_TABLE",
13
+ GET_TABLE_ROW: "GET_TABLE_ROW",
12
14
  ADD_TABLE_ROW: "ADD_TABLE_ROW",
15
+ DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
16
+ TO_JSON: "TO_JSON",
17
+ GET_TABLE_ROWS: "GET_TABLE_ROWS",
13
18
  //Client SDK functions
14
19
  MESSAGE: "MESSAGE",
15
20
  CONFIRM: "CONFIRM",
@@ -31,7 +36,9 @@ exports.LISTENER_CMDS = {
31
36
  GET_PAGE_PARAMS: "GET_PAGE_PARAMS",
32
37
  OPEN_POPUP_PAGE: "OPEN_POPUP_PAGE",
33
38
  PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
34
- COMPONENT_REFRESH: "COMPONENT_REFRESH"
39
+ COMPONENT_REFRESH: "COMPONENT_REFRESH",
40
+ COMPONENT_SHOW: "COMPONENT_SHOW",
41
+ COMPONENT_HIDE: "COMPONENT_HIDE"
35
42
  };
36
43
  exports.EVENT_TYPES = {
37
44
  ON_CLOSE: "onClose",
package/dist/form.js CHANGED
@@ -15,16 +15,24 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  exports.__esModule = true;
18
- exports.Form = void 0;
18
+ exports.TableForm = exports.Form = void 0;
19
19
  var base_1 = require("./base");
20
20
  var constants_1 = require("./constants");
21
21
  var Form = /** @class */ (function (_super) {
22
22
  __extends(Form, _super);
23
- function Form() {
24
- return _super !== null && _super.apply(this, arguments) || this;
23
+ function Form(instanceId) {
24
+ var _this = _super.call(this, {}) || this;
25
+ _this.instanceId = instanceId;
26
+ return _this;
25
27
  }
28
+ Form.prototype.toJSON = function () {
29
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.TO_JSON, {
30
+ instanceId: this.instanceId
31
+ });
32
+ };
26
33
  Form.prototype.getField = function (fieldId) {
27
34
  return this._postMessageAsync(constants_1.LISTENER_CMDS.GET_FORM_FIELD, {
35
+ instanceId: this.instanceId,
28
36
  fieldId: fieldId
29
37
  });
30
38
  };
@@ -33,12 +41,86 @@ var Form = /** @class */ (function (_super) {
33
41
  data: args
34
42
  });
35
43
  };
36
- Form.prototype.addTableRow = function (tableId, rowObject) {
44
+ Form.prototype.getTable = function (tableId) {
45
+ return new Table(this.instanceId, tableId);
46
+ };
47
+ return Form;
48
+ }(base_1.BaseSDK));
49
+ exports.Form = Form;
50
+ var Table = /** @class */ (function (_super) {
51
+ __extends(Table, _super);
52
+ function Table(instanceId, tableId) {
53
+ var _this = _super.call(this, {}) || this;
54
+ _this.tableId = tableId;
55
+ _this.instanceId = instanceId;
56
+ return _this;
57
+ }
58
+ // list of obj of rows
59
+ Table.prototype.toJSON = function () {
60
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.TO_JSON, {
61
+ tableId: this.tableId
62
+ });
63
+ };
64
+ Table.prototype.getRows = function () {
65
+ var _this = this;
66
+ // list of TableForm class
67
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.GET_TABLE_ROWS, { tableId: this.tableId }, true, // has callBack
68
+ function (data) {
69
+ console.log(data);
70
+ return data.map(function (row) { return new TableForm(_this.instanceId, _this.tableId, row.id); });
71
+ });
72
+ };
73
+ Table.prototype.getRow = function (rowId) {
74
+ return new TableForm(this.instanceId, this.tableId, rowId);
75
+ };
76
+ Table.prototype.addRow = function (rowObject) {
37
77
  return this._postMessageAsync(constants_1.LISTENER_CMDS.ADD_TABLE_ROW, {
38
- tableId: tableId,
78
+ tableId: this.tableId,
39
79
  rowObject: rowObject
40
80
  });
41
81
  };
42
- return Form;
82
+ Table.prototype.deleteRow = function (rowId) {
83
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.DELETE_TABLE_ROW, {
84
+ tableId: this.tableId,
85
+ rowId: rowId
86
+ });
87
+ };
88
+ return Table;
43
89
  }(base_1.BaseSDK));
44
- exports.Form = Form;
90
+ var TableForm = /** @class */ (function (_super) {
91
+ __extends(TableForm, _super);
92
+ function TableForm(instanceId, tableId, rowId) {
93
+ var _this = _super.call(this, {}) || this;
94
+ _this.instanceId = instanceId;
95
+ _this.tableId = tableId;
96
+ _this.rowId = rowId;
97
+ return _this;
98
+ }
99
+ TableForm.prototype.getParent = function () {
100
+ return new Form(this.instanceId);
101
+ };
102
+ TableForm.prototype.toJSON = function () {
103
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.TO_JSON, {
104
+ tableId: this.tableId,
105
+ rowId: this.rowId
106
+ });
107
+ };
108
+ TableForm.prototype.getField = function (fieldId) {
109
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.GET_FORM_FIELD, {
110
+ instanceId: this.instanceId,
111
+ tableId: this.tableId,
112
+ rowId: this.rowId,
113
+ fieldId: fieldId
114
+ });
115
+ };
116
+ TableForm.prototype.updateField = function (args) {
117
+ return this._postMessageAsync(constants_1.LISTENER_CMDS.UPDATE_FORM, {
118
+ instanceId: this.instanceId,
119
+ tableId: this.tableId,
120
+ rowId: this.rowId,
121
+ data: args
122
+ });
123
+ };
124
+ return TableForm;
125
+ }(base_1.BaseSDK));
126
+ exports.TableForm = TableForm;
package/dist/formatter.js CHANGED
@@ -23,22 +23,22 @@ var Formatter = /** @class */ (function (_super) {
23
23
  function Formatter() {
24
24
  return _super !== null && _super.apply(this, arguments) || this;
25
25
  }
26
- Formatter.prototype.toKfDate = function (date) {
26
+ Formatter.prototype.toDate = function (date) {
27
27
  return this._postMessageAsync(constants_1.LISTENER_CMDS.FORMAT_DATE, {
28
28
  date: date
29
29
  });
30
30
  };
31
- Formatter.prototype.toKfDateTime = function (date) {
31
+ Formatter.prototype.toDateTime = function (date) {
32
32
  return this._postMessageAsync(constants_1.LISTENER_CMDS.FORMAT_DATE_TIME, {
33
33
  date: date
34
34
  });
35
35
  };
36
- Formatter.prototype.toKfNumber = function (value) {
36
+ Formatter.prototype.toNumber = function (value) {
37
37
  return this._postMessageAsync(constants_1.LISTENER_CMDS.FORMAT_NUMBER, {
38
38
  value: value
39
39
  });
40
40
  };
41
- Formatter.prototype.toKfCurrency = function (value, currencyCode) {
41
+ Formatter.prototype.toCurrency = function (value, currencyCode) {
42
42
  return this._postMessageAsync(constants_1.LISTENER_CMDS.FORMAT_CURRENCY, {
43
43
  value: value,
44
44
  currencyCode: currencyCode
@@ -1,46 +1,63 @@
1
1
 
2
+ declare class Component {
3
+ id: string
4
+ refresh(): any;
5
+ show(): any;
6
+ hide(): any;
7
+ }
2
8
  declare class Page {
3
9
  _id: string
4
- getParameter(key: string): string | object;
5
- getVariable(key: string): string | object;
6
- setVariable(key: string, value: any): string | object;
10
+ getParameter(key: string): any;
11
+ getVariable(key: string): any;
12
+ setVariable(key: string, value: any): any;
7
13
  openPopup(pageId: string, inputParams: object, popupProperties: {
8
14
  w: number;
9
15
  h: number;
10
- }): string | object;
16
+ }): any;
17
+ getComponent(componentId: string): Component;
11
18
  onClose(callback: Function): void;
12
19
  }
13
20
  declare class Application {
14
21
  page: Page
15
- getVariable(key: string): string | object;
16
- setVariable(key: string | object, value: any): string | object;
17
- openPage(pageId: string, pageParams: object): string | object;
22
+ getVariable(key: string): any;
23
+ setVariable(key: string | object, value: any): any;
24
+ openPage(pageId: string, pageParams: object): any;
18
25
  }
19
26
  declare class Client {
20
- showInfo(message: string): string | object;
27
+ showInfo(message: string): any;
21
28
  showConfirm(args: {
22
29
  title: string;
23
30
  content: string;
24
31
  okText: string;
25
32
  cancelText: string;
26
- }): string | object;
27
- redirect(url: string): string | object;
28
- }
29
- declare class Component {
30
- id: string
31
- refresh(): string | object;
33
+ }): any;
34
+ redirect(url: string): any;
32
35
  }
33
36
  declare class Form {
34
- getField(fieldId: string): string | object;
35
- updateField(args: object): string | object;
36
- addTableRow(tableId: string, rowObject: object): string | object;
37
+ toJSON(): any;
38
+ getField(fieldId: string): any;
39
+ updateField(args: object): any;
40
+ getTable(tableId: string): Table;
41
+ }
42
+ declare class Table {
43
+ toJSON(): any;
44
+ getRows(): TableForm[];
45
+ getRow(rowId: string): TableForm;
46
+ addRow(rowObject: object): any;
47
+ deleteRow(rowId: string): any;
48
+ }
49
+ declare class TableForm {
50
+ getParent(): Form;
51
+ toJSON(): any;
52
+ getField(fieldId: string): any;
53
+ updateField(args: object): any;
37
54
  }
38
55
  declare class Formatter {
39
- toKfDate(date: string): string | object;
40
- toKfDateTime(date: string): string | object;
41
- toKfNumber(value: string): string | object;
42
- toKfCurrency(value: string, currencyCode: string): string | object;
43
- toBoolean(value: string): string | object;
56
+ toDate(date: string): any;
57
+ toDateTime(date: string): any;
58
+ toNumber(value: string): any;
59
+ toCurrency(value: string, currencyCode: string): any;
60
+ toBoolean(value: string): any;
44
61
  }
45
62
  declare class kf {
46
63
  static currentForm: Form
@@ -50,5 +67,4 @@ declare class kf {
50
67
  api(url: string, args?: {}): string | object;
51
68
  watchParams(func: (data: any) => any): void;
52
69
  getContext(): string | object;
53
- getComponent(componentId: string): Component;
54
70
  }