@cocreate/api 1.21.2 → 1.22.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # [1.22.0](https://github.com/CoCreate-app/CoCreate-api/compare/v1.21.3...v1.22.0) (2024-11-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handling array[] ([93bafda](https://github.com/CoCreate-app/CoCreate-api/commit/93bafdaab1712ae1c99a408142c8ec9e912a34c5))
7
+ * observer taget has been renamed to selector ([9802a6c](https://github.com/CoCreate-app/CoCreate-api/commit/9802a6c96b0f37de1166f240720544652eb5666b))
8
+ * pretier.config.js and file formating ([12031c1](https://github.com/CoCreate-app/CoCreate-api/commit/12031c1ea0db05ae7881fdca959ec022ee2cae86))
9
+
10
+
11
+ ### Features
12
+
13
+ * add prettier.config.js and format files ([090db4f](https://github.com/CoCreate-app/CoCreate-api/commit/090db4f1d7c2e26d0b76b82ab70b83c58be49323))
14
+
15
+ ## [1.21.3](https://github.com/CoCreate-app/CoCreate-api/compare/v1.21.2...v1.21.3) (2024-08-24)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * dynaically fire endEvent provided by action ([ad8084e](https://github.com/CoCreate-app/CoCreate-api/commit/ad8084e5e5822c9f1f49e0acd00676b57c1e4f2b))
21
+ * removed listener and use await with request to get response ([db14d2c](https://github.com/CoCreate-app/CoCreate-api/commit/db14d2cdcc17d0edd967f660ec5206ab0172fd4d))
22
+ * update doc ([d68a2e2](https://github.com/CoCreate-app/CoCreate-api/commit/d68a2e207c8f3e3d497ccff4f6cece3eb5639488))
23
+
1
24
  ## [1.21.2](https://github.com/CoCreate-app/CoCreate-api/compare/v1.21.1...v1.21.2) (2024-06-23)
2
25
 
3
26
 
package/docs/index.html CHANGED
@@ -17,8 +17,15 @@
17
17
  </head>
18
18
 
19
19
  <body>
20
- <nav class="nav display:flex align-items:center left:0px background:whitesmoke padding-top:10px padding-bottom:10px" content_id="content" scroll="sticky-nav,hide-nav" scroll-up="10" scroll-down="10" array="files" object="60395ef42b3ac232657040fd"
21
- key="src">
20
+ <nav
21
+ class="nav display:flex align-items:center left:0px background:whitesmoke padding-top:10px padding-bottom:10px"
22
+ content_id="content"
23
+ scroll="sticky-nav,hide-nav"
24
+ scroll-up="10"
25
+ scroll-down="10"
26
+ array="files"
27
+ object="60395ef42b3ac232657040fd"
28
+ key="src">
22
29
  </nav>
23
30
  <sidenav id="menuL" class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl" resizable resize-selector="[content_id='content']" resize-property="margin-left" resize-value="width">
24
31
  <menu array="files" object="603717b07de7fb350ae9fec8" key="src"></menu>
@@ -42,8 +49,9 @@
42
49
  <a href="https://github.com/CoCreate-app/CoCreate-dnd" target="_blank" class=""><i src="/assets/svg/github.svg"></i></a>
43
50
  </div>
44
51
  </div>
45
- <h1 class="max-width:500px margin:20px_10px line-height:1.5 font-size:16px font-weight:100">CoCreate-api is a simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. CoCreate-api includes the
46
- client component and server side for api processing.</h1>
52
+
53
+ <!-- <h1 class="max-width:500px margin:20px_10px line-height:1.5 font-size:16px font-weight:100">CoCreate-api is a simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. CoCreate-api includes the
54
+ client component and server side for api processing.</h1> -->
47
55
  <div id="api-section" class="display:flex flex-wrap:wrap">
48
56
  <div class="flex-grow:1 width:400px width:300px@xs padding:0px_10px margin-top:60px">
49
57
 
@@ -74,7 +82,7 @@
74
82
  <span class="display:flex align-items:center width:fit-content" hover="display:block!important" hover-selector="[href='#api-usage']">
75
83
  <h2 class="padding:5px_0px">Usage</h2>
76
84
  <a class="margin-left:10px display:none" href="#api-usage"><i src="/assets/svg/link.svg"></i></a>
77
- </span>
85
+ </span>
78
86
  </div>
79
87
 
80
88
  <h4 class="margin-top:20px padding:5px_0px">Install package</h4>
@@ -218,7 +226,6 @@
218
226
 
219
227
  </div>
220
228
  <!-- End SandBox -->
221
- </div>
222
229
  </div>
223
230
  </div>
224
231
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/api",
3
- "version": "1.21.2",
3
+ "version": "1.22.0",
4
4
  "description": "A simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. CoCreate-api includes the client component and server side for api processing. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. ",
5
5
  "keywords": [
6
6
  "thirdparty-api-intergration",
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ tabWidth: 4,
3
+ semi: true,
4
+ trailingComma: "none",
5
+ bracketSameLine: true,
6
+ useTabs: true,
7
+ overrides: [
8
+ {
9
+ files: ["*.json", "*.yml", "*.yaml"],
10
+ options: {
11
+ tabWidth: 2,
12
+ useTabs: false
13
+ },
14
+ }
15
+ ],
16
+ };
package/src/index.js CHANGED
@@ -29,10 +29,6 @@ const CoCreateApi = {
29
29
  if (typeof this.modules[name] === 'undefined') {
30
30
  this.modules[name] = { name, endPoints, options };
31
31
 
32
- Socket.listen(name, (data) => {
33
- self.response(name, data);
34
- });
35
-
36
32
  Actions.init({
37
33
  name,
38
34
  callback: (action) => {
@@ -58,7 +54,7 @@ const CoCreateApi = {
58
54
  Observer.init({
59
55
  name: `${name}NodeObserver`,
60
56
  observe: ['addedNodes'],
61
- target: `[${name}]`,
57
+ selector: `[${name}]`,
62
58
  callback: function (mutation) {
63
59
  inputEvent(mutation.target)
64
60
  self.request({ name, element: mutation.target, type: 'nodeObserver' })
@@ -91,12 +87,13 @@ const CoCreateApi = {
91
87
  this.modules[object.name][object.method].request(object)
92
88
  else if (!object.event && object.type === 'action' || object.event && object.event.includes(object.type)) {
93
89
  let data = await CoCreateApi.getData(object);
94
- CoCreateApi.send(object.name, object.method, data);
90
+ CoCreateApi.send(object, data);
95
91
  }
96
92
  },
97
93
 
98
- response: function (name, data) {
99
- const method = data.method.substring(name.length + 1);
94
+ response: function (object, data) {
95
+ const name = object.name
96
+ const method = object.method;
100
97
  if (this.modules[name][method] && this.modules[name][method].response)
101
98
  this.modules[name][method].response(data[name])
102
99
  else if (data.error) {
@@ -110,9 +107,9 @@ const CoCreateApi = {
110
107
  }]
111
108
  });
112
109
  } else {
113
- CoCreateApi.setData({ name, method, data })
110
+ CoCreateApi.setData(object, data)
114
111
 
115
- document.dispatchEvent(new CustomEvent(name, {
112
+ document.dispatchEvent(new CustomEvent(object.endEvent, {
116
113
  detail: {
117
114
  data: data[name]
118
115
  }
@@ -120,8 +117,9 @@ const CoCreateApi = {
120
117
  }
121
118
  },
122
119
 
123
- send: function (name, method, data) {
124
- Socket.send({ method: name + '.' + method, [name]: data, broadcast: false, broadcastBrowser: false, status: 'await' });
120
+ send: async function (object, data) {
121
+ data = await Socket.send({ method: object.name + '.' + object.method, [object.name]: data, broadcast: false, broadcastBrowser: false, status: 'await' });
122
+ this.response(object, data);
125
123
  },
126
124
 
127
125
  getData: async function ({ name, method, element, form }) {
@@ -141,7 +139,18 @@ const CoCreateApi = {
141
139
  continue
142
140
  let key = elements[i].getAttribute(`${name}-key`)
143
141
  if (key) {
144
- data[key] = await elements[i].getValue()
142
+ let value = await elements[i].getValue()
143
+ if (key.endsWith('[]')) {
144
+ if (!data[key])
145
+ data[key] = [];
146
+
147
+ if (Array.isArray(value))
148
+ data[key].push(...value);
149
+ else
150
+ data[key].push(value);
151
+ } else
152
+ data[key] = await elements[i].getValue()
153
+
145
154
  }
146
155
 
147
156
  let endpoint = elements[i].getAttribute('endpoint')
@@ -171,11 +180,13 @@ const CoCreateApi = {
171
180
  return data
172
181
  },
173
182
 
174
- setData: function ({ name, method, data, form }) {
183
+ setData: function (object, data) {
184
+ const name = object.name
185
+ let form = object.form
175
186
  if (!form)
176
187
  form = document;
177
188
 
178
- let elements = form.querySelectorAll(`[${name}="${method}"]`);
189
+ let elements = form.querySelectorAll(`[${name}="${object.method}"]`);
179
190
  if (!elements || elements.length == 0)
180
191
  return
181
192
 
@@ -211,7 +222,7 @@ const CoCreateApi = {
211
222
  Observer.init({
212
223
  name: `apiNodeObserver`,
213
224
  observe: ['addedNodes'],
214
- target: '[module], [api]',
225
+ selector: '[module], [api]',
215
226
  callback: function (mutation) {
216
227
  let name = mutation.target.getAttribute('api') || mutation.target.getAttribute('module')
217
228
  CoCreateApi.register({ name, endPoints: {} });