@cocreate/element-prototype 1.15.0 → 1.17.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,27 @@
1
+ # [1.17.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.16.0...v1.17.0) (2023-12-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * password value or empty string ([acd9f55](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/acd9f55438837fccc66bc5156652a5be5ae8d9ec))
7
+
8
+
9
+ ### Features
10
+
11
+ * skip param to dispatch event with sip false ([c5816b1](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/c5816b136d7133125c6c94abe05082a59a93c72c))
12
+
13
+ # [1.16.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.15.0...v1.16.0) (2023-11-25)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * update licensing details ([4aeb6f8](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/4aeb6f88f74467e09e68f10187eef534d2b95395))
19
+
20
+
21
+ ### Features
22
+
23
+ * upgrade dependencies for latest features and fixes ([0a04fc1](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/0a04fc1a9d64bd47aa92848f93f851d10ab213a1))
24
+
1
25
  # [1.15.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.14.1...v1.15.0) (2023-11-25)
2
26
 
3
27
 
package/README.md CHANGED
@@ -9,7 +9,6 @@ A simple element-prototype component in vanilla javascript. Easily configured us
9
9
  ![GitHub](https://img.shields.io/github/license/CoCreate-app/CoCreate-element-prototype?style=flat-square)
10
10
  ![GitHub](https://img.shields.io/static/v1?style=flat-square&label=&message=Hiring&color=blueviolet)
11
11
 
12
-
13
12
  ![CoCreate-element-prototype](https://cdn.cocreate.app/docs/CoCreate-element-prototype.gif)
14
13
 
15
14
  ## [Docs & Demo](https://cocreate.app/docs/element-prototype)
@@ -40,12 +39,12 @@ $ yarn install @cocreate/element-prototype
40
39
 
41
40
  # Table of Contents
42
41
 
43
- - [Table of Contents](#table-of-contents)
44
- - [Announcements](#announcements)
45
- - [Roadmap](#roadmap)
46
- - [How to Contribute](#how-to-contribute)
47
- - [About](#about)
48
- - [License](#license)
42
+ - [Table of Contents](#table-of-contents)
43
+ - [Announcements](#announcements)
44
+ - [Roadmap](#roadmap)
45
+ - [How to Contribute](#how-to-contribute)
46
+ - [About](#about)
47
+ - [License](#license)
49
48
 
50
49
  <a name="announcements"></a>
51
50
 
@@ -79,6 +78,14 @@ We want this library to be community-driven, and CoCreate led. We need your help
79
78
 
80
79
  We appreciate your continued support, thank you!
81
80
 
81
+ <a name="license"></a>
82
+
82
83
  # License
83
84
 
84
- [The MIT License (MIT)](https://github.com/CoCreate-app/CoCreate-element-prototype/blob/master/LICENSE)
85
+ This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.
86
+
87
+ - **Open Source Use**: For open-source projects and non-commercial use, this software is available under the AGPLv3. The AGPLv3 allows you to freely use, modify, and distribute this software, provided that all modifications and derivative works are also licensed under the AGPLv3. For the full license text, see the [LICENSE file](https://github.com/CoCreate-app/CoCreate-element-prototype/blob/master/LICENSE).
88
+
89
+ - **Commercial Use**: For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our [website](https://cocreate.app). This license permits proprietary use and modification of the software without the copyleft requirements of the AGPLv3. It is ideal for integrating this software into proprietary commercial products and applications.
90
+
91
+ If you have not purchased a commercial license and intend to use this software for commercial purposes, you are required to sign up for an API key on our website.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "element-prototype",
@@ -58,6 +58,6 @@
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
60
  "dependencies": {
61
- "@cocreate/utils": "^1.28.0"
61
+ "@cocreate/utils": "^1.29.0"
62
62
  }
63
63
  }
package/src/getValue.js CHANGED
@@ -60,7 +60,7 @@ const getValue = (element) => {
60
60
  } else if (element.type === 'range') {
61
61
  value = [Number(element.min), Number(element.value)];
62
62
  } else if (element.type === "password") {
63
- value = btoa(value);
63
+ value = btoa(value || '');
64
64
  } else if (element.tagName == "SELECT" && element.hasAttribute('multiple')) {
65
65
  let options = element.selectedOptions;
66
66
  value = [];
package/src/setValue.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import { getAttributes } from '@cocreate/utils';
2
2
  import { storage } from './getValue';
3
3
 
4
- HTMLElement.prototype.setValue = function (value) {
5
- setValue(this, value)
4
+ HTMLElement.prototype.setValue = function (value, dispatch) {
5
+ setValue(this, value, dispatch)
6
6
  };
7
7
 
8
- HTMLInputElement.prototype.setValue = function (value) {
9
- setValue(this, value)
8
+ HTMLInputElement.prototype.setValue = function (value, dispatch) {
9
+ setValue(this, value, dispatch)
10
10
  };
11
11
 
12
- HTMLHeadingElement.prototype.setValue = function (value) {
13
- setValue(this, value)
12
+ HTMLHeadingElement.prototype.setValue = function (value, dispatch) {
13
+ setValue(this, value, dispatch)
14
14
  };
15
15
 
16
16
  // TODO: check if using a a switch case will provide better performance
17
- const setValue = (el, value) => {
17
+ const setValue = (el, value, dispatch) => {
18
18
  if (value === null || value === undefined) return;
19
19
  if (el.hasAttribute('component') || el.hasAttribute('plugin'))
20
20
  return storage.set(el, value)
@@ -78,7 +78,7 @@ const setValue = (el, value) => {
78
78
 
79
79
  el.value = value;
80
80
  }
81
- dispatchEvents(el)
81
+ dispatchEvents(el, dispatch)
82
82
  } else if (el.tagName === 'IMG' || el.tagName === 'SOURCE') {
83
83
  el.src = value;
84
84
  } else if (el.tagName === 'IFRAME') {
@@ -119,6 +119,12 @@ const setValue = (el, value) => {
119
119
  }
120
120
  } else
121
121
  el.innerHTML = newElement.innerHTML;
122
+
123
+ let scripts = el.querySelectorAll('script');
124
+ for (let script of scripts) {
125
+ setScript(script)
126
+ }
127
+
122
128
  }
123
129
 
124
130
  if (el.hasAttribute("value")) {
@@ -127,7 +133,7 @@ const setValue = (el, value) => {
127
133
  }
128
134
 
129
135
  if (el.getAttribute('contenteditable'))
130
- dispatchEvents(el);
136
+ dispatchEvents(el, dispatch);
131
137
 
132
138
  if (el.tagName == 'HEAD' || el.tagName == 'BODY') {
133
139
  el.removeAttribute('array');
@@ -150,8 +156,26 @@ function setState(el) {
150
156
  }
151
157
 
152
158
  function setScript(script, value) {
159
+ let srcAttribute = script.src
160
+ if (srcAttribute) {
161
+ let pageOrigin = window.location.origin;
162
+ let srcOrigin;
163
+
164
+ try {
165
+ srcOrigin = new URL(srcAttribute, document.baseURI).origin;
166
+ } catch (e) {
167
+ // Handle invalid URLs
168
+ console.error("Invalid URL in src attribute:", srcAttribute);
169
+ return;
170
+ }
171
+ if (pageOrigin !== srcOrigin)
172
+ return
173
+ }
174
+
153
175
  let newScript = document.createElement('script');
154
- newScript.attributes = script.attributes;
176
+ for (let attr of script.attributes) {
177
+ newScript.setAttribute(attr.name, attr.value);
178
+ }
155
179
  newScript.innerHTML = script.innerHTML;
156
180
  if (value) {
157
181
  if (script.hasAttribute("src"))
@@ -168,11 +192,11 @@ function __decryptPassword(str) {
168
192
  return decode_str;
169
193
  }
170
194
 
171
- function dispatchEvents(el) {
195
+ function dispatchEvents(el, skip = true) {
172
196
  let inputEvent = new CustomEvent('input', {
173
197
  bubbles: true,
174
198
  detail: {
175
- skip: true
199
+ skip
176
200
  },
177
201
  });
178
202
 
@@ -185,7 +209,7 @@ function dispatchEvents(el) {
185
209
  let changeEvent = new CustomEvent('change', {
186
210
  bubbles: true,
187
211
  detail: {
188
- skip: true
212
+ skip
189
213
  },
190
214
  });
191
215