@cocreate/element-prototype 1.35.0 → 2.0.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/CONTRIBUTING.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # Contributing to CoCreate-element-prototype
2
2
 
3
- This project is work of [many contributors](https://github.com/CoCreate-app/CoCreate-element-prototype/graphs/contributors).
4
- You're encouraged to submit [pull requests](https://github.com/CoCreate-app/CoCreate-element-prototype/pulls),
5
- [propose features and discuss issues](https://github.com/CoCreate-app/CoCreate-element-prototype/issues).
3
+ This project is work of [many contributors](https://github.com/CoCreateJS/element-prototype/graphs/contributors).
4
+ You're encouraged to submit [pull requests](https://github.com/CoCreateJS/element-prototype/pulls),
5
+ [propose features and discuss issues](https://github.com/CoCreateJS/element-prototype/issues).
6
6
 
7
7
  In the examples below, substitute your Github username for `contributor` in URLs.
8
8
 
9
9
  ## Fork the Project
10
10
 
11
- Fork the [project on Github](https://github.com/CoCreate-app/CoCreate-element-prototype) and check out your copy.
11
+ Fork the [project on Github](https://github.com/CoCreateJS/element-prototype) and check out your copy.
12
12
 
13
13
  ```
14
14
  git clone https://github.com/contributor/CoCreate-element-prototype.git
15
15
  cd CoCreate-element-prototype
16
- git remote add upstream https://github.com/CoCreate-app/CoCreate-element-prototype.git
16
+ git remote add upstream https://github.com/CoCreateJS/element-prototype.git
17
17
  ```
18
18
 
19
19
  ## Create a Topic Branch
@@ -75,7 +75,7 @@ git push origin my-feature-branch
75
75
 
76
76
  ## Make a Pull Request
77
77
 
78
- Go to [https://github.com/CoCreate-app/CoCreate-element-prototype](https://github.com/CoCreate-app/CoCreate-element-prototype) and select your feature branch.
78
+ Go to [https://github.com/CoCreateJS/element-prototype](https://github.com/CoCreateJS/element-prototype) and select your feature branch.
79
79
  Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
80
80
 
81
81
  ## Rebase
@@ -12,8 +12,8 @@ module.exports = {
12
12
  "pathname": "/docs/element-prototype/index.html",
13
13
  "src": "{{./docs/index.html}}",
14
14
  "host": [
15
- "cocreate.app",
16
- "general.cocreate.app"
15
+ "CoCreateJS.com",
16
+ "general.CoCreateJS.com"
17
17
  ],
18
18
  "directory": "element-prototype",
19
19
  "content-type": "{{content-type}}",
package/README.md CHANGED
@@ -1,28 +1,115 @@
1
1
  # CoCreate-element-prototype
2
2
 
3
- A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API. Take it for a spin in our [playground!](https://cocreate.app/docs/element-prototype)
3
+ A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API. Take it for a spin in our [playground!](https://CoCreateJS.com/docs/element-prototype)
4
4
 
5
- ![min file size in bytes](https://img.badgesize.io/https://cdn.cocreate.app/element-prototype/latest/CoCreate-element-prototype.min.js?style=flat-square&label=minified&color=orange)
6
- ![gzip file size in bytes](https://img.badgesize.io/https://cdn.cocreate.app/element-prototype/latest/CoCreate-element-prototype.min.js?compression=gzip&style=flat-square&label=gzip&color=yellow)
7
- ![brotlifile size in bytes](https://img.badgesize.io/https://cdn.cocreate.app/element-prototype/latest/CoCreate-element-prototype.min.js?compression=brotli&style=flat-square&label=brotli)
8
- ![GitHub latest release](https://img.shields.io/github/v/release/CoCreate-app/CoCreate-element-prototype?style=flat-square)
9
- ![GitHub](https://img.shields.io/github/license/CoCreate-app/CoCreate-element-prototype?style=flat-square)
5
+ ![min file size in bytes](https://img.badgesize.io/https://cdn.CoCreateJS.com/element-prototype/latest/CoCreate-element-prototype.min.js?style=flat-square&label=minified&color=orange)
6
+ ![gzip file size in bytes](https://img.badgesize.io/https://cdn.CoCreateJS.com/element-prototype/latest/CoCreate-element-prototype.min.js?compression=gzip&style=flat-square&label=gzip&color=yellow)
7
+ ![brotlifile size in bytes](https://img.badgesize.io/https://cdn.CoCreateJS.com/element-prototype/latest/CoCreate-element-prototype.min.js?compression=brotli&style=flat-square&label=brotli)
8
+ ![GitHub latest release](https://img.shields.io/github/v/release/CoCreateJS/element-prototype?style=flat-square)
9
+ ![GitHub](https://img.shields.io/github/license/CoCreateJS/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
- ![CoCreate-element-prototype](https://cdn.cocreate.app/docs/CoCreate-element-prototype.gif)
12
+ ![CoCreate-element-prototype](https://cdn.CoCreateJS.com/docs/CoCreate-element-prototype.gif)
13
+
14
+ ## [Docs & Demo](https://CoCreateJS.com/docs/element-prototype)
15
+
16
+ For a complete guide and working demo refer to the [doumentation](https://CoCreateJS.com/docs/element-prototype)
17
+
18
+ ## Generic element values
19
+
20
+ For generic elements, including contenteditable elements, `getValue()` and
21
+ `getValueAsync()` select the `value` attribute first, then the `.value` property
22
+ when it exists, and finally `innerHTML`. An empty attribute or property remains
23
+ an empty value; it does not fall through to rendered content.
24
+
25
+ Explicit DOM read types bypass both stored values: `get-value-type="text"` or
26
+ `"innerText"` reads visible text, `"textContent"` reads text content,
27
+ `"innerHTML"` reads inner markup, and `"outerHTML"`, `"element"`, or `"node"`
28
+ reads outer markup. `value-type` supplies the same options when a scoped
29
+ `get-value-type` is not specified. Conversion types such as `boolean` and `json`
30
+ retain the normal value precedence and convert the selected value afterward.
31
+ DOM reads still support `get-value-remove-query` filtering.
32
+ The prototype methods also accept an explicit type argument, such as
33
+ `element.getValue("textContent")` or `element.getValueAsync("innerHTML")`.
34
+ Programmatically claimed Editor hosts use property storage even before their
35
+ initial asynchronous read has finished.
36
+
37
+ Non-native elements marked with `component`, `editor`, or an enabled
38
+ `contenteditable` attribute
39
+ store incoming values on their own `.value` property after setter transformations
40
+ and conversion, then dispatch
41
+ the configured events. This branch does not write a `value` attribute or replace
42
+ DOM content directly. An existing property setter, such as Editor's source setter,
43
+ still runs when `.value` is assigned. Generic elements can retain structured
44
+ objects and arrays without JSON serialization. Inputs, textareas, and selects
45
+ follow their native field paths even with these marker attributes. Iframes use
46
+ their dedicated setter path when marked `editor`, while an
47
+ explicit `component` marker still opts an iframe into property storage;
48
+ checkbox, radio, select, password, and date handling therefore still applies.
49
+ `crdt="true"` no longer suppresses shared-setter native assignments; file inputs
50
+ remain excluded from ordinary value assignment.
51
+
52
+ The shared getters return these stored component/editor values directly without
53
+ consuming them. Before an editor has a `.value` property, its getter still uses
54
+ the existing element-specific or generic fallback to support initialization.
55
+ Component/editor/contenteditable reads bypass the generic precedence and transformations above,
56
+ as component storage did previously. Native field and iframe handling retain
57
+ their dedicated paths when this component/editor branch does not apply. Element
58
+ methods supplied by a component may bypass this shared handler. Editor preserves
59
+ these shared methods and consumes their input notifications. Setter-generated
60
+ `input` and `change` events include the replacement in `event.detail.value`,
61
+ alongside the existing `skip` flag; source-only notifications can omit the value.
62
+ This lets an iframe adapter receive a full reset's source without assigning
63
+ `src` or `srcdoc` itself. Before an iframe has a stored value, the shared getter
64
+ reads its `srcdoc` attribute or serializes its accessible current document.
65
+ No separate component value storage Map is used.
66
+
67
+ ## Value transformations
68
+
69
+ Value transformations accept three attribute namespaces:
70
+
71
+ - `value-*` applies to both reads and writes.
72
+ - `get-value-*` applies to `getValue()` and `getValueAsync()`.
73
+ - `set-value-*` applies to `setValue()`.
74
+
75
+ Each direction-specific attribute overrides its corresponding shared attribute,
76
+ regardless of attribute order. Other options still fall back independently.
77
+ For example, `value-uppercase` with `set-value-uppercase="false"` uppercases
78
+ only reads. An empty scoped regex/encoding attribute disables that operation;
79
+ `"false"` also disables case, regex, and encoding/decoding transformations.
80
+ An empty case attribute enables case conversion.
81
+
82
+ Supported transformation suffixes include `lowercase`, `uppercase`, `replace`,
83
+ `replaceall`, `replacement`, `test`, `match`, `split`, `lastindex`, `search`,
84
+ `exec`, `encode`, and `decode`. The `type` suffix supports `boolean`, `object`,
85
+ `json`, `array`, `array.$keys`, `array.$values`, and `array.$entries`, as well as
86
+ existing element read/render types. `prefix` and `suffix` also honor scoped
87
+ overrides, retaining their existing add-on-read and strip-on-write behavior.
88
+
89
+ Setter transformations run in this order: case, regex operations (in effective
90
+ attribute order), encoding, decoding, and type conversion. They run before
91
+ component storage or element rendering. Components retain structured values;
92
+ textareas serialize objects and arrays as JSON.
13
93
 
14
- ## [Docs & Demo](https://cocreate.app/docs/element-prototype)
94
+ ```html
95
+ <textarea value-uppercase></textarea>
96
+ <textarea get-value-encode="base64" set-value-decode="base64"></textarea>
97
+ <div component set-value-type="object"></div>
98
+ ```
15
99
 
16
- For a complete guide and working demo refer to the [doumentation](https://cocreate.app/docs/element-prototype)
100
+ Calling `setValue('{"enabled":true}')` on the component above stores an object;
101
+ its `getValue()` returns that object. Use scoped attributes for transformations
102
+ that should happen only once: unscoped replacements or encoding can run again
103
+ when reading a value that was previously written.
17
104
 
18
105
  ## CDN
19
106
 
20
107
  ```html
21
- <script src="https://cdn.cocreate.app/element-prototype/latest/CoCreate-element-prototype.min.js"></script>
108
+ <script src="https://cdn.CoCreateJS.com/element-prototype/latest/CoCreate-element-prototype.min.js"></script>
22
109
  ```
23
110
 
24
111
  ```html
25
- <script src="https://cdn.cocreate.app/element-prototype/latest/CoCreate-element-prototype.min.css"></script>
112
+ <script src="https://cdn.CoCreateJS.com/element-prototype/latest/CoCreate-element-prototype.min.css"></script>
26
113
  ```
27
114
 
28
115
  ## NPM
@@ -50,13 +137,13 @@ $ yarn install @cocreate/element-prototype
50
137
 
51
138
  # Announcements
52
139
 
53
- All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreate-app/CoCreate-element-prototype/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreate-app/CoCreate-element-prototype/releases). You may also subscribe to email for releases and breaking changes.
140
+ All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreateJS/element-prototype/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreateJS/element-prototype/releases). You may also subscribe to email for releases and breaking changes.
54
141
 
55
142
  <a name="roadmap"></a>
56
143
 
57
144
  # Roadmap
58
145
 
59
- If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreate-app/CoCreate-element-prototype/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-element-prototype/pulls). We would love to hear your feedback.
146
+ If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreateJS/element-prototype/issues) and [pull requests](https://github.com/CoCreateJS/element-prototype/pulls). We would love to hear your feedback.
60
147
 
61
148
  <a name="about"></a>
62
149
 
@@ -64,7 +151,7 @@ If you are interested in the future direction of this project, please take a loo
64
151
 
65
152
  CoCreate-element-prototype is guided and supported by the CoCreate Developer Experience Team.
66
153
 
67
- Please Email the Developer Experience Team [here](mailto:develop@cocreate.app) in case of any queries.
154
+ Please Email the Developer Experience Team [here](mailto:develop@CoCreateJS.com) in case of any queries.
68
155
 
69
156
  CoCreate-element-prototype is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
70
157
 
@@ -72,9 +159,9 @@ CoCreate-element-prototype is maintained and funded by CoCreate. The names and l
72
159
 
73
160
  # How to Contribute
74
161
 
75
- We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreate-app/CoCreate-element-prototype/blob/master/CONTRIBUTING.md) guide for details.
162
+ We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreateJS/element-prototype/blob/master/CONTRIBUTING.md) guide for details.
76
163
 
77
- We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreate-app/CoCreate-element-prototype/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-element-prototype/pulls) or merely upvote or comment on existing issues or pull requests.
164
+ We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreateJS/element-prototype/issues) and [pull requests](https://github.com/CoCreateJS/element-prototype/pulls) or merely upvote or comment on existing issues or pull requests.
78
165
 
79
166
  We appreciate your continued support, thank you!
80
167
 
@@ -84,8 +171,28 @@ We appreciate your continued support, thank you!
84
171
 
85
172
  This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.
86
173
 
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).
174
+ - **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/CoCreateJS/element-prototype/blob/master/LICENSE).
88
175
 
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.
176
+ - **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://CoCreateJS.com). 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
177
 
91
178
  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.
179
+
180
+ ### Values on select options
181
+
182
+ Select getters process each selected option through the corresponding synchronous
183
+ or asynchronous value getter before applying the select's own transformations.
184
+ A single select returns one processed value; `multiple` returns an array.
185
+
186
+ ```html
187
+ <select>
188
+ <option value="">Any state</option>
189
+ <option value="true" value-type="boolean">Enabled</option>
190
+ <option value="false" value-type="boolean">Disabled</option>
191
+ </select>
192
+ ```
193
+
194
+ Here the values are `""`, `true`, and `false`. Types and transformations declared
195
+ on options affect only those options. Existing select-level types still apply
196
+ to the collected result; select-level prefixes and suffixes still apply to each
197
+ value in a multiple select. With no selected option, the result is `""` for a
198
+ single select or `[]` for a multiple select, before select-level transformations.
package/demo/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  </head>
15
15
 
16
16
  <body>
17
- <!--<script src="https://cdn.cocreate.app/element-prototype/latest/CoCreate-element-prototype.min.js"></script>-->
18
- <script src="https://CoCreate.app/dist/CoCreate.js"></script>
17
+ <!--<script src="https://cdn.CoCreateJS.com/element-prototype/latest/CoCreate-element-prototype.min.js"></script>-->
18
+ <script src="https://CoCreateJS.com/dist/CoCreate.js"></script>
19
19
  </body>
20
20
  </html>
package/docs/index.html CHANGED
@@ -9,7 +9,7 @@
9
9
  rel="icon"
10
10
  type="image/png"
11
11
  sizes="32x32"
12
- href="https://cocreate.app/images/favicon.ico" />
12
+ href="https://CoCreateJS.com/images/favicon.ico" />
13
13
  <meta
14
14
  name="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
@@ -36,7 +36,7 @@
36
36
  share-width="500"
37
37
  share-media="https://via.placeholder.com/300/09f/fff.png">
38
38
  <a
39
- href="https://github.com/CoCreate-app/CoCreate-element-prototype"
39
+ href="https://github.com/CoCreateJS/CoCreate-element-prototype"
40
40
  target="_blank"
41
41
  class="margin-right:15px"
42
42
  ><i src="/assets/svg/github.svg"></i
@@ -82,7 +82,7 @@
82
82
  <pre
83
83
  class="margin-top:15px"><code class="language-javascript">npm install cocreate-element-prototype</code></pre>
84
84
  <p class="padding:10px_0px">Or you can use cdn link:</p>
85
- <pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-element-prototype.min.js</code></pre>
85
+ <pre><code class="language-javascript">https://cdn.CoCreateJS.com/js/CoCreate-element-prototype.min.js</code></pre>
86
86
 
87
87
  <h2
88
88
  class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
@@ -229,6 +229,6 @@
229
229
  </div>
230
230
 
231
231
  <!--CoCreateJS-->
232
- <script src="https://CoCreate.app/dist/CoCreate.js"></script>
232
+ <script src="https://CoCreateJS.com/dist/CoCreate.js"></script>
233
233
  </body>
234
234
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.35.0",
3
+ "version": "2.0.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",
@@ -22,24 +22,24 @@
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "git+https://github.com/CoCreate-app/CoCreate-element-prototype.git"
25
+ "url": "git+https://github.com/CoCreateJS/element-prototype.git"
26
26
  },
27
27
  "author": "CoCreate LLC",
28
28
  "license": "AGPL-3.0",
29
29
  "bugs": {
30
- "url": "https://github.com/CoCreate-app/CoCreate-element-prototype/issues"
30
+ "url": "https://github.com/CoCreateJS/element-prototype/issues"
31
31
  },
32
- "homepage": "https://cocreate.app/docs/element-prototype",
32
+ "homepage": "https://CoCreateJS.com/docs/element-prototype",
33
33
  "funding": {
34
34
  "type": "GitHub Sponsors ❤",
35
- "url": "https://github.com/sponsors/CoCreate-app"
35
+ "url": "https://github.com/sponsors/CoCreateJS"
36
36
  },
37
37
  "main": "./src/index.js",
38
38
  "dependencies": {
39
- "@cocreate/utils": "^1.50.3"
39
+ "@cocreate/utils": "^1.54.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@cocreate/webpack": "^1.7.0"
42
+ "@cocreate/webpack": "^1.9.0"
43
43
  },
44
44
  "allowScripts": {
45
45
  "@cocreate/utils@1.42.2": true,
@@ -51,6 +51,20 @@ function updateAttributes(e) {
51
51
  }
52
52
  }
53
53
 
54
+ function parseObjectValue(value) {
55
+ if (typeof value !== "string") return value;
56
+
57
+ const firstCharacter = value.trimStart()[0];
58
+ if (firstCharacter !== "{" && firstCharacter !== "[") return value;
59
+
60
+ try {
61
+ const parsed = JSON.parse(value);
62
+ return parsed !== null && typeof parsed === "object" ? parsed : value;
63
+ } catch {
64
+ return value;
65
+ }
66
+ }
67
+
54
68
  /**
55
69
  * Custom getAttribute function that processes the attribute value synchronously
56
70
  * @param {Element} element - The element from which to get the attribute
@@ -62,13 +76,23 @@ function getAttribute(element, name) {
62
76
  throw new Error("First argument must be an Element");
63
77
  }
64
78
 
65
- const value = originalGetAttribute.call(element, name);
66
- if (!value || typeof value !== "string") {
67
- return value;
68
- }
79
+ const rawValue = originalGetAttribute.call(element, name);
80
+ if (typeof rawValue !== "string") return rawValue;
81
+ // Preserve a whole literal for its next consumer without evaluating operators.
82
+ if (
83
+ rawValue.length >= 2 &&
84
+ rawValue.startsWith("`") &&
85
+ rawValue.indexOf("`", 1) === rawValue.length - 1
86
+ ) return rawValue.slice(1, -1);
87
+ if (!rawValue.includes("$")) return rawValue;
88
+ const value = parseObjectValue(rawValue);
69
89
 
70
90
  // Evaluate formulas or step paths synchronously via the unified AST Engine
71
- return astSync({ executeAST: value, node: element });
91
+ return astSync({
92
+ executeAST: value,
93
+ node: element,
94
+ sandbox: { $this: element }
95
+ });
72
96
  }
73
97
 
74
98
  /**
@@ -82,13 +106,23 @@ async function getAttributeAsync(element, name) {
82
106
  throw new Error("First argument must be an Element");
83
107
  }
84
108
 
85
- const value = originalGetAttribute.call(element, name);
86
- if (!value || typeof value !== "string") {
87
- return value;
88
- }
109
+ const rawValue = originalGetAttribute.call(element, name);
110
+ if (typeof rawValue !== "string") return rawValue;
111
+ // Preserve a whole literal for its next consumer without evaluating operators.
112
+ if (
113
+ rawValue.length >= 2 &&
114
+ rawValue.startsWith("`") &&
115
+ rawValue.indexOf("`", 1) === rawValue.length - 1
116
+ ) return rawValue.slice(1, -1);
117
+ if (!rawValue.includes("$")) return rawValue;
118
+ const value = parseObjectValue(rawValue);
89
119
 
90
120
  // Evaluate async formulas, database lookups, or template blocks asynchronously
91
- return await astAsync({ executeAST: value, node: element });
121
+ return await astAsync({
122
+ executeAST: value,
123
+ node: element,
124
+ sandbox: { $this: element }
125
+ });
92
126
  }
93
127
 
94
128
  // Override the native getAttribute method on the global Element prototype