@kissflow/lowcode-client-sdk 1.0.0-beta.5 → 1.0.2-beta.7

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.
@@ -15,10 +15,10 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  exports.__esModule = true;
18
- exports.LowcodeSDK = void 0;
19
18
  var base_1 = require("./base");
20
19
  var constants_1 = require("./constants");
21
20
  var form_1 = require("./form");
21
+ var form_2 = require("./form");
22
22
  var client_1 = require("./client");
23
23
  var formatter_1 = require("./formatter");
24
24
  var app_1 = require("./app");
@@ -27,7 +27,12 @@ var LowcodeSDK = /** @class */ (function (_super) {
27
27
  __extends(LowcodeSDK, _super);
28
28
  function LowcodeSDK(props) {
29
29
  var _this = _super.call(this, {}) || this;
30
- _this.currentForm = new form_1.Form({});
30
+ if (props.tableId && props.rowId) {
31
+ _this.currentForm = new form_2.TableForm(props.instanceId, props.tableId, props.rowId);
32
+ }
33
+ else if (props.instanceId) {
34
+ _this.currentForm = new form_1.Form(props.instanceId);
35
+ }
31
36
  _this.client = new client_1.Client({});
32
37
  _this.formatter = new formatter_1.Formatter({});
33
38
  _this.app = new app_1.Application({});
@@ -48,7 +53,6 @@ var LowcodeSDK = /** @class */ (function (_super) {
48
53
  };
49
54
  return LowcodeSDK;
50
55
  }(base_1.BaseSDK));
51
- exports.LowcodeSDK = LowcodeSDK;
52
56
  function initSDK(config) {
53
57
  if (config === void 0) { config = {}; }
54
58
  return new LowcodeSDK(config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kissflow/lowcode-client-sdk",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.2-beta.7",
4
4
  "description": "JavaScript SDK for developing over the Kissflow lowcode platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/base.ts CHANGED
@@ -41,7 +41,7 @@ export class BaseSDK {
41
41
  args: any,
42
42
  hasCallBack?: boolean,
43
43
  callBack?: (data: any) => {}
44
- ): object | string {
44
+ ): object | string | any {
45
45
  return new Promise((resolve, reject) => {
46
46
  const _id = generateId(command.toLowerCase());
47
47
  postMessage({ _id, command, ...args });
package/src/component.ts CHANGED
@@ -12,4 +12,14 @@ export class Component extends BaseSDK {
12
12
  id: this.id
13
13
  });
14
14
  }
15
+ show() {
16
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_SHOW, {
17
+ id: this.id
18
+ });
19
+ }
20
+ hide() {
21
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_HIDE, {
22
+ id: this.id
23
+ });
24
+ }
15
25
  }
package/src/constants.ts CHANGED
@@ -7,7 +7,12 @@ export const LISTENER_CMDS = {
7
7
  //Forms SDK Functions
8
8
  GET_FORM_FIELD: "GET_FORM_FIELD",
9
9
  UPDATE_FORM: "UPDATE_FORM",
10
+ GET_TABLE: "GET_TABLE",
11
+ GET_TABLE_ROW: "GET_TABLE_ROW",
10
12
  ADD_TABLE_ROW: "ADD_TABLE_ROW",
13
+ DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
14
+ TO_JSON: "TO_JSON",
15
+ GET_TABLE_ROWS: "GET_TABLE_ROWS",
11
16
 
12
17
  //Client SDK functions
13
18
  MESSAGE: "MESSAGE",
@@ -34,7 +39,9 @@ export const LISTENER_CMDS = {
34
39
  OPEN_POPUP_PAGE: "OPEN_POPUP_PAGE",
35
40
  PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
36
41
 
37
- COMPONENT_REFRESH: "COMPONENT_REFRESH"
42
+ COMPONENT_REFRESH: "COMPONENT_REFRESH",
43
+ COMPONENT_SHOW: "COMPONENT_SHOW",
44
+ COMPONENT_HIDE: "COMPONENT_HIDE"
38
45
  };
39
46
 
40
47
 
package/src/form.ts CHANGED
@@ -2,8 +2,24 @@ import { BaseSDK } from "./base";
2
2
  import { LISTENER_CMDS } from "./constants";
3
3
 
4
4
  export class Form extends BaseSDK {
5
+ private instanceId: string;
6
+ id: string;
7
+ constructor(instanceId: string) {
8
+ super({});
9
+ this.instanceId = instanceId;
10
+ this.id = instanceId;
11
+ }
12
+ toJSON() {
13
+ return this._postMessageAsync(
14
+ LISTENER_CMDS.TO_JSON,
15
+ {
16
+ instanceId: this.instanceId
17
+ },
18
+ );
19
+ }
5
20
  getField(fieldId: string) {
6
21
  return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
22
+ instanceId: this.instanceId,
7
23
  fieldId
8
24
  });
9
25
  }
@@ -12,10 +28,111 @@ export class Form extends BaseSDK {
12
28
  data: args
13
29
  });
14
30
  }
15
- addTableRow(tableId: string, rowObject: object) {
31
+ getTable(tableId: string) {
32
+ return new Table(this.instanceId, tableId);
33
+ }
34
+ }
35
+
36
+ class Table extends BaseSDK {
37
+ private tableId: string;
38
+ private instanceId: string;
39
+ id: string;
40
+
41
+ constructor(instanceId: string,tableId: string) {
42
+ super({});
43
+ this.tableId = tableId;
44
+ this.instanceId = instanceId
45
+ this.id = tableId;
46
+ }
47
+
48
+ // list of obj of rows
49
+ toJSON() {
50
+ return this._postMessageAsync(
51
+ LISTENER_CMDS.TO_JSON,
52
+ {
53
+ tableId: this.tableId
54
+ },
55
+ );
56
+ }
57
+
58
+ getRows():TableForm[] {
59
+ // list of TableForm class
60
+ return this._postMessageAsync(
61
+ LISTENER_CMDS.GET_TABLE_ROWS,
62
+ { tableId: this.tableId },
63
+ true, // has callBack
64
+ (data) => {
65
+ console.log(data);
66
+ return data.map((row) => new TableForm(this.instanceId, this.tableId, row.id))
67
+ }
68
+ );
69
+ }
70
+
71
+ getRow(rowId: string) {
72
+ return new TableForm(this.instanceId, this.tableId, rowId);
73
+ }
74
+
75
+ addRow(rowObject: object) {
16
76
  return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROW, {
17
- tableId,
77
+ tableId: this.tableId,
18
78
  rowObject
19
79
  });
20
80
  }
81
+
82
+ deleteRow(rowId: string) {
83
+ return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
84
+ tableId: this.tableId,
85
+ rowId
86
+ });
87
+ }
21
88
  }
89
+
90
+ export class TableForm extends BaseSDK {
91
+ private instanceId: string;
92
+ private tableId: string;
93
+ private rowId: string;
94
+ id: string
95
+ table: Table;
96
+ parent: Form;
97
+
98
+ constructor(instanceId: string, tableId: string, rowId: string) {
99
+ super({});
100
+ this.instanceId = instanceId;
101
+ this.tableId = tableId;
102
+ this.rowId = rowId;
103
+ this.id = rowId;
104
+ this.parent = new Form(instanceId);
105
+ this.table = new Table(instanceId, tableId);
106
+ }
107
+
108
+
109
+ toJSON() {
110
+ return this._postMessageAsync(
111
+ LISTENER_CMDS.GET_TABLE_ROW,
112
+ {
113
+ tableId: this.tableId,
114
+ rowId: this.rowId
115
+ },
116
+ );
117
+
118
+ }
119
+
120
+ getField(fieldId: string) {
121
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
122
+ instanceId: this.instanceId,
123
+ tableId: this.tableId,
124
+ rowId: this.rowId,
125
+ fieldId
126
+ });
127
+ }
128
+
129
+ updateField(args: object) {
130
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
131
+ instanceId: this.instanceId,
132
+ tableId: this.tableId,
133
+ rowId: this.rowId,
134
+ data: args
135
+ });
136
+ }
137
+ }
138
+
@@ -1,20 +1,26 @@
1
1
  import { BaseSDK } from "./base";
2
2
  import { LISTENER_CMDS } from "./constants";
3
3
  import { Form } from "./form";
4
+ import { TableForm } from "./form";
4
5
  import { Client } from "./client";
5
6
  import { Formatter } from './formatter';
6
7
  import { Application } from "./app";
7
8
  import { Component } from "./component";
8
9
 
9
- export class LowcodeSDK extends BaseSDK {
10
- currentForm: Form;
10
+ class LowcodeSDK extends BaseSDK {
11
+ currentForm: Form | TableForm;
11
12
  client: Client;
12
13
  formatter: Formatter;
13
14
  app: Application;
14
15
 
15
16
  constructor(props: any) {
16
17
  super({});
17
- this.currentForm = new Form({});
18
+ if (props.tableId && props.rowId) {
19
+ this.currentForm = new TableForm(props.instanceId, props.tableId, props.rowId);
20
+ }
21
+ else if(props.instanceId) {
22
+ this.currentForm = new Form(props.instanceId);
23
+ }
18
24
  this.client = new Client({});
19
25
  this.formatter = new Formatter({});
20
26
  this.app = new Application({});
package/webpack.config.js CHANGED
@@ -5,6 +5,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
5
5
  let config = {
6
6
  devtool: "source-map",
7
7
  mode: "development",
8
+ entry: "./src/index.ts",
8
9
  devServer: {
9
10
  contentBase: path.join(__dirname, "dist"),
10
11
  port: 3000,
@@ -43,7 +44,6 @@ let moduleLib = Object.assign({}, config, {
43
44
  experiments: {
44
45
  outputModule: true
45
46
  },
46
- entry: "./src/lowcode.sdk.ts",
47
47
  output: {
48
48
  filename: "kflowcode.sdk.module.js",
49
49
  path: path.resolve(__dirname, "dist"),
@@ -54,7 +54,6 @@ let moduleLib = Object.assign({}, config, {
54
54
  }
55
55
  });
56
56
  let commonLib = Object.assign({}, config, {
57
- entry: "./src/index.ts",
58
57
  output: {
59
58
  filename: "kflowcode.sdk.js",
60
59
  path: path.resolve(__dirname, "dist")