@cocreate/state 1.22.2 → 1.24.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 +26 -0
- package/docs/index.html +321 -326
- package/package.json +1 -1
- package/prettier.config.js +16 -0
- package/src/index.js +222 -164
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
# [1.24.0](https://github.com/CoCreate-app/CoCreate-state/compare/v1.23.0...v1.24.0) (2024-12-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* support setting empty string ([ee2ad83](https://github.com/CoCreate-app/CoCreate-state/commit/ee2ad83dfddfb9209b64fdbd154c5ed85340b238))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* support comma seperated states to apply multiple states ([1777635](https://github.com/CoCreate-app/CoCreate-state/commit/1777635b0d3f98979c08735e07d137d9bfc40230))
|
|
12
|
+
|
|
13
|
+
# [1.23.0](https://github.com/CoCreate-app/CoCreate-state/compare/v1.22.2...v1.23.0) (2024-11-04)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* observer taget has been renamed to selector ([4dcda48](https://github.com/CoCreate-app/CoCreate-state/commit/4dcda482405c2ec3cf39cca80f419b1715b3abef))
|
|
19
|
+
* pretier.config.js and file formating ([b1a9249](https://github.com/CoCreate-app/CoCreate-state/commit/b1a9249d198fbb90e0259771ea76489b950ab7e7))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add prettier.config.js and format files ([c171ae1](https://github.com/CoCreate-app/CoCreate-state/commit/c171ae1b706a187ea6a728f766d85bf159df7819))
|
|
25
|
+
* add prettier.config.js and format files ([db433e5](https://github.com/CoCreate-app/CoCreate-state/commit/db433e5982a558775ccb74a4b111cfbe2f429875))
|
|
26
|
+
|
|
1
27
|
## [1.22.2](https://github.com/CoCreate-app/CoCreate-state/compare/v1.22.1...v1.22.2) (2024-06-12)
|
|
2
28
|
|
|
3
29
|
|
package/docs/index.html
CHANGED
|
@@ -1,339 +1,334 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<title>CoCreate-state Documentation | CoCreateJS</title>
|
|
8
|
+
<link
|
|
9
|
+
rel="icon"
|
|
10
|
+
type="image/png"
|
|
11
|
+
sizes="32x32"
|
|
12
|
+
href="https://cocreate.app/images/favicon.ico"
|
|
13
|
+
/>
|
|
14
|
+
<meta
|
|
15
|
+
name="description"
|
|
16
|
+
content="Data attributes which can be used for components in CoCreate framework combined as a group of attributes that dynamically change attributes & fetch custom data"
|
|
17
|
+
/>
|
|
18
|
+
<meta
|
|
19
|
+
name="keywords"
|
|
20
|
+
content="helper classes, utility classes, css framework, css library, inline style classes"
|
|
21
|
+
/>
|
|
22
|
+
<meta name="robots" content="index,follow" />
|
|
23
|
+
<meta
|
|
24
|
+
property="og:image"
|
|
25
|
+
content="https://cdn.cocreate.app/docs/state.png"
|
|
26
|
+
/>
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
<link
|
|
29
|
+
rel="stylesheet"
|
|
30
|
+
href="../index.css"
|
|
31
|
+
array="files"
|
|
32
|
+
object="60888216117c640e7596303f"
|
|
33
|
+
key="src"
|
|
34
|
+
type="text/css"
|
|
35
|
+
save="true"
|
|
36
|
+
/>
|
|
37
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
38
|
+
</head>
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
share-network="share"
|
|
102
|
-
title="Share on share"
|
|
103
|
-
><i src="/assets/svg/share-alt.svg"></i
|
|
104
|
-
></a>
|
|
105
|
-
</div>
|
|
106
|
-
<a
|
|
107
|
-
href="https://github.com/CoCreate-app/CoCreate-state"
|
|
108
|
-
target="_blank"
|
|
109
|
-
class="margin-right:15px"
|
|
110
|
-
><i src="/assets/svg/github.svg"></i
|
|
111
|
-
></a>
|
|
112
|
-
</div>
|
|
40
|
+
<body>
|
|
41
|
+
<!-- Navbar -->
|
|
42
|
+
<nav
|
|
43
|
+
class="width:100% display:flex align-items:center background:transparent padding-top:10px padding-bottom:10px"
|
|
44
|
+
content_id="content"
|
|
45
|
+
scroll="sticky-nav,"
|
|
46
|
+
scroll-up="5"
|
|
47
|
+
scroll-down="5"
|
|
48
|
+
path="../"
|
|
49
|
+
src="../components/navbar.html"
|
|
50
|
+
></nav>
|
|
51
|
+
<sidenav
|
|
52
|
+
id="menuL"
|
|
53
|
+
class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl"
|
|
54
|
+
resizable
|
|
55
|
+
resize-selector="[content_id='content']"
|
|
56
|
+
resize-property="margin-left"
|
|
57
|
+
resize-value="width"
|
|
58
|
+
>
|
|
59
|
+
<menu array="files" object="603717b07de7fb350ae9fec8" key="src"></menu>
|
|
60
|
+
<div resize="right"></div>
|
|
61
|
+
</sidenav>
|
|
62
|
+
<main
|
|
63
|
+
class="padding-top:15px padding:15px@lg@xl"
|
|
64
|
+
content_id="content"
|
|
65
|
+
id="cocreate-state"
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
class="display:flex flex-wrap:wrap justify-content:space-between position:relative margin:10px"
|
|
69
|
+
>
|
|
70
|
+
<div class="display:flex align-items:center">
|
|
71
|
+
<h2>CoCreate-state</h2>
|
|
72
|
+
</div>
|
|
73
|
+
<div
|
|
74
|
+
class="display:flex align-items:center font-size:20px position:absolute right:0 padding:5px background:white"
|
|
75
|
+
>
|
|
76
|
+
<div
|
|
77
|
+
class="display:flex align-items:center transition:0.3s padding-left:10px"
|
|
78
|
+
share-network="true"
|
|
79
|
+
share-text="Data attributes which can be used for components in CoCreate framework combined as a group of attributes that dynamically change attributes & fetch custom data"
|
|
80
|
+
share-title="CoCreate-state"
|
|
81
|
+
share-height="600"
|
|
82
|
+
share-width="700"
|
|
83
|
+
share-media="https://cdn.cocreate.app/docs/state.png"
|
|
84
|
+
hover="display:block!important"
|
|
85
|
+
hover-selector=".social-networks"
|
|
86
|
+
>
|
|
87
|
+
<div class="display:none social-networks">
|
|
88
|
+
<a
|
|
89
|
+
class="margin-right:15px"
|
|
90
|
+
share-network="twitter"
|
|
91
|
+
title="Share on twitter"
|
|
92
|
+
><i src="/assets/svg/twitter.svg"></i
|
|
93
|
+
></a>
|
|
94
|
+
<a
|
|
95
|
+
class="margin-right:15px"
|
|
96
|
+
share-network="facebook"
|
|
97
|
+
title="Share on Facebook"
|
|
98
|
+
><i src="/assets/svg/facebook.svg"></i
|
|
99
|
+
></a>
|
|
100
|
+
<a
|
|
101
|
+
class="margin-right:15px"
|
|
102
|
+
share-network="instagram"
|
|
103
|
+
title="Share on instagram"
|
|
104
|
+
><i src="/assets/svg/instagram.svg"></i
|
|
105
|
+
></a>
|
|
113
106
|
</div>
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
107
|
+
<a
|
|
108
|
+
class="margin-right:15px"
|
|
109
|
+
share-network="share"
|
|
110
|
+
title="Share on share"
|
|
111
|
+
><i src="/assets/svg/share-alt.svg"></i
|
|
112
|
+
></a>
|
|
113
|
+
</div>
|
|
114
|
+
<a
|
|
115
|
+
href="https://github.com/CoCreate-app/CoCreate-state"
|
|
116
|
+
target="_blank"
|
|
117
|
+
class="margin-right:15px"
|
|
118
|
+
><i src="/assets/svg/github.svg"></i
|
|
119
|
+
></a>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
<h1
|
|
123
|
+
class="max-width:500px margin:20px_10px line-height:1.5 font-size:16px font-weight:100"
|
|
124
|
+
>
|
|
125
|
+
Data attributes which can be used for components in CoCreate framework
|
|
126
|
+
combined as a group of attributes that dynamically change attributes
|
|
127
|
+
& fetch custom data.
|
|
128
|
+
</h1>
|
|
129
|
+
<div id="state-section" class="display:flex flex-wrap:wrap">
|
|
130
|
+
<div
|
|
131
|
+
class="flex-grow:1 width:400px width:300px@xs padding:0px_10px margin-top:60px"
|
|
132
|
+
>
|
|
133
|
+
<div
|
|
134
|
+
id="state-install"
|
|
135
|
+
class="border-bottom:1px_solid_lightgrey"
|
|
136
|
+
scroll
|
|
137
|
+
scroll-intersect="color:dodgerblue"
|
|
138
|
+
scroll-selector="#state-install-section"
|
|
139
|
+
>
|
|
140
|
+
<span
|
|
141
|
+
class="display:flex align-items:center width:fit-content"
|
|
142
|
+
hover="display:block!important"
|
|
143
|
+
hover-selector="[href='#state-install']"
|
|
144
|
+
>
|
|
145
|
+
<h2 class="padding:5px_0px">Install</h2>
|
|
146
|
+
<a class="margin-left:10px display:none" href="#state-install"
|
|
147
|
+
><i src="/assets/svg/link.svg"></i
|
|
148
|
+
></a>
|
|
149
|
+
</span>
|
|
150
|
+
</div>
|
|
151
|
+
<pre><code class="language-bash">npm i @cocreate/state</code></pre>
|
|
152
|
+
<p class="padding:10px_0px line-height:1.5">
|
|
153
|
+
Or you can use cdn link:
|
|
154
|
+
</p>
|
|
155
|
+
<pre><code class="language-html"><script>https://cdn.cocreate.app/state/latest/CoCreate-state.min.js</script></code></pre>
|
|
146
156
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
This is state usage
|
|
168
|
-
</p>
|
|
157
|
+
<div
|
|
158
|
+
id="state-usage"
|
|
159
|
+
class="margin-top:80px border-bottom:1px_solid_lightgrey"
|
|
160
|
+
scroll
|
|
161
|
+
scroll-intersect="color:dodgerblue"
|
|
162
|
+
scroll-selector="#state-usage-section"
|
|
163
|
+
>
|
|
164
|
+
<span
|
|
165
|
+
class="display:flex align-items:center width:fit-content"
|
|
166
|
+
hover="display:block!important"
|
|
167
|
+
hover-selector="[href='#state-usage']"
|
|
168
|
+
>
|
|
169
|
+
<h2 class="padding:5px_0px">Usage</h2>
|
|
170
|
+
<a class="margin-left:10px display:none" href="#state-usage"
|
|
171
|
+
><i src="/assets/svg/link.svg"></i
|
|
172
|
+
></a>
|
|
173
|
+
</span>
|
|
174
|
+
</div>
|
|
175
|
+
<div class="">
|
|
176
|
+
<p class="padding:10px_0px line-height:1.5">This is state usage</p>
|
|
169
177
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
|
214
|
-
<h4>
|
|
215
|
-
<span>state</span>
|
|
216
|
-
<span class="cocreate-badge success"
|
|
217
|
-
>string</span
|
|
218
|
-
>
|
|
219
|
-
<span class="cocreate-badge warning"
|
|
220
|
-
>optional</span
|
|
221
|
-
>
|
|
222
|
-
</h4>
|
|
223
|
-
<p>state-attribute</p>
|
|
224
|
-
</li>
|
|
225
|
-
</ul>
|
|
226
|
-
</div>
|
|
178
|
+
<div class="flex-grow:1 min-width:300px width:100%">
|
|
179
|
+
<pre><code class="language-html"><div></div></code></pre>
|
|
180
|
+
</div>
|
|
181
|
+
<p class="padding:10px_0px line-height:1.5">This is state usage</p>
|
|
182
|
+
<p class="padding:10px_0px line-height:1.5">This is state usage</p>
|
|
183
|
+
</div>
|
|
184
|
+
<div
|
|
185
|
+
id="state-attributes"
|
|
186
|
+
class="margin-top:80px border-bottom:1px_solid_lightgrey"
|
|
187
|
+
scroll
|
|
188
|
+
scroll-intersect="color:dodgerblue"
|
|
189
|
+
scroll-selector="#state-attributes-section"
|
|
190
|
+
>
|
|
191
|
+
<span
|
|
192
|
+
class="display:flex align-items:center width:fit-content"
|
|
193
|
+
hover="display:block!important"
|
|
194
|
+
hover-selector="[href='#state-attributes']"
|
|
195
|
+
>
|
|
196
|
+
<h2 class="padding:5px_0px">Attributes</h2>
|
|
197
|
+
<a class="margin-left:10px display:none" href="#state-attributes"
|
|
198
|
+
><i src="/assets/svg/link.svg"></i
|
|
199
|
+
></a>
|
|
200
|
+
</span>
|
|
201
|
+
</div>
|
|
202
|
+
<ul class="list-style-type:none">
|
|
203
|
+
<li class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
|
204
|
+
<h4>
|
|
205
|
+
<span>state</span>
|
|
206
|
+
<span class="cocreate-badge success">string</span>
|
|
207
|
+
<span class="cocreate-badge warning">optional</span>
|
|
208
|
+
</h4>
|
|
209
|
+
<p>state-attribute</p>
|
|
210
|
+
</li>
|
|
211
|
+
<li class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
|
212
|
+
<h4>
|
|
213
|
+
<span>state</span>
|
|
214
|
+
<span class="cocreate-badge success">string</span>
|
|
215
|
+
<span class="cocreate-badge warning">optional</span>
|
|
216
|
+
</h4>
|
|
217
|
+
<p>state-attribute</p>
|
|
218
|
+
</li>
|
|
219
|
+
</ul>
|
|
220
|
+
</div>
|
|
227
221
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
222
|
+
<div
|
|
223
|
+
class="flex-grow:1 width:300px padding:0px_10px margin-top:60px border-bottom:1px_solid_lightgrey"
|
|
224
|
+
>
|
|
225
|
+
<!-- SandBox -->
|
|
226
|
+
<div
|
|
227
|
+
id="state-demo"
|
|
228
|
+
class="border-bottom:1px_solid_lightgrey"
|
|
229
|
+
scroll
|
|
230
|
+
scroll-intersect="color:dodgerblue"
|
|
231
|
+
scroll-selector="#state-demo-section"
|
|
232
|
+
>
|
|
233
|
+
<span
|
|
234
|
+
class="display:flex align-items:center width:fit-content"
|
|
235
|
+
hover="display:block!important"
|
|
236
|
+
hover-selector="[href='#state-demo']"
|
|
237
|
+
>
|
|
238
|
+
<h2 class="padding:5px_0px">Demo</h2>
|
|
239
|
+
<a class="margin-left:10px display:none" href="#state-demo"
|
|
240
|
+
><i src="/assets/svg/link.svg"></i
|
|
241
|
+
></a>
|
|
242
|
+
</span>
|
|
243
|
+
</div>
|
|
244
|
+
<div class="position:sticky top:0 padding:15px_0px height:100vh">
|
|
245
|
+
<!-- SandBox -->
|
|
246
|
+
<div
|
|
247
|
+
class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
|
|
248
|
+
id="playground"
|
|
249
|
+
>
|
|
250
|
+
<div
|
|
251
|
+
id="demo-code"
|
|
252
|
+
resizable
|
|
253
|
+
class="position:relative height:50%"
|
|
254
|
+
>
|
|
255
|
+
<textarea
|
|
256
|
+
type="code"
|
|
257
|
+
lang="html"
|
|
258
|
+
array="demos"
|
|
259
|
+
object=""
|
|
260
|
+
key="demo"
|
|
261
|
+
save="false"
|
|
262
|
+
id="demo"
|
|
263
|
+
class="height:100% width:100% outline:none border:none resize:none padding:5px"
|
|
264
|
+
></textarea>
|
|
265
|
+
<div resize="bottom" class="background:lightgrey"></div>
|
|
266
|
+
</div>
|
|
272
267
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
268
|
+
<div
|
|
269
|
+
id="demo-preview"
|
|
270
|
+
class="position:relative overflow:auto background-color:white"
|
|
271
|
+
>
|
|
272
|
+
<div class="demopreview padding:20px"></div>
|
|
273
|
+
</div>
|
|
278
274
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
fullscreen-selector="#playground"></a>
|
|
323
|
-
</div>
|
|
324
|
-
</div>
|
|
325
|
-
<!-- End SandBox -->
|
|
326
|
-
</div>
|
|
327
|
-
</div>
|
|
275
|
+
<div
|
|
276
|
+
class="font-size:20px position:absolute top:10px right:10px opacity:0.6"
|
|
277
|
+
>
|
|
278
|
+
<a
|
|
279
|
+
class="margin-right:10px"
|
|
280
|
+
id="eye"
|
|
281
|
+
show="#eye-slash"
|
|
282
|
+
hide="#eye, #demo-preview"
|
|
283
|
+
toggle="code-height"
|
|
284
|
+
toggle-selector="#demo-code"
|
|
285
|
+
><i class="height:18px" src="/assets/svg/eye.svg"></i
|
|
286
|
+
></a>
|
|
287
|
+
<a
|
|
288
|
+
class="margin-right:10px"
|
|
289
|
+
hidden
|
|
290
|
+
id="eye-slash"
|
|
291
|
+
show="#eye, #demo-preview"
|
|
292
|
+
hide="#eye-slash"
|
|
293
|
+
toggle="code-height"
|
|
294
|
+
toggle-selector="#demo-code"
|
|
295
|
+
><i src="/assets/svg/eye-slash.svg"></i
|
|
296
|
+
></a>
|
|
297
|
+
<a
|
|
298
|
+
class="margin-right:10px"
|
|
299
|
+
id="code"
|
|
300
|
+
show="#code-slash"
|
|
301
|
+
hide="#code, #demo-code"
|
|
302
|
+
><i src="/assets/svg/code.svg"></i
|
|
303
|
+
></a>
|
|
304
|
+
<a
|
|
305
|
+
class="margin-right:10px"
|
|
306
|
+
hidden
|
|
307
|
+
id="code-slash"
|
|
308
|
+
show="#code, #demo-code"
|
|
309
|
+
hide="#code-slash"
|
|
310
|
+
><i class="height:18px" src="/assets/svg/code.svg"></i
|
|
311
|
+
></a>
|
|
312
|
+
<a
|
|
313
|
+
class="margin-right:5px"
|
|
314
|
+
fullscreen
|
|
315
|
+
fullscreen-selector="#playground"
|
|
316
|
+
></a>
|
|
317
|
+
</div>
|
|
328
318
|
</div>
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
319
|
+
<!-- End SandBox -->
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
</div>
|
|
323
|
+
<button
|
|
324
|
+
href="https://github.com/CoCreate-app/CoCreate-state/tree/master/docs/index.html?message=docs%3A%20describe%20your%20change..."
|
|
325
|
+
target="_blank"
|
|
326
|
+
class="display:flex justify-content:center align-items:center position:fixed bottom:15px right:15px height:50px width:50px border-radius:50% box-shadow:0px_2px_10px_0px_rgba(0,_0,_0,_0.4)"
|
|
327
|
+
>
|
|
328
|
+
<i src="../assets/svg/pencil-alt.svg"></i>
|
|
329
|
+
</button>
|
|
330
|
+
</main>
|
|
336
331
|
|
|
337
|
-
|
|
338
|
-
|
|
332
|
+
<script src="https://CoCreate.app/dist/CoCreate.js"></script>
|
|
333
|
+
</body>
|
|
339
334
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/state",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "Data attributes which can be used for components in CoCreate framework combined as a group of attributes that dynamically change attributes & fetch custom data.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
package/src/index.js
CHANGED
|
@@ -1,205 +1,263 @@
|
|
|
1
|
-
import
|
|
2
|
-
import observer from
|
|
3
|
-
import action from
|
|
4
|
-
import uid from
|
|
5
|
-
import localStorage from
|
|
6
|
-
|
|
1
|
+
import "@cocreate/element-prototype";
|
|
2
|
+
import observer from "@cocreate/observer";
|
|
3
|
+
import action from "@cocreate/actions";
|
|
4
|
+
import uid from "@cocreate/uuid";
|
|
5
|
+
import localStorage from "@cocreate/local-storage";
|
|
7
6
|
|
|
8
7
|
function init() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
let elements = document.querySelectorAll("[state_id]");
|
|
9
|
+
initElements(elements);
|
|
10
|
+
window.addEventListener("storage", function (e) {
|
|
11
|
+
if (e.key == "statedAttributes") {
|
|
12
|
+
elements = document.querySelectorAll(
|
|
13
|
+
'[state_id]:not([state-onstoragechange="false"])'
|
|
14
|
+
);
|
|
15
|
+
initElements(elements);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
document.addEventListener("click", function (e) {
|
|
19
|
+
const target = e.target.closest("[state_to]");
|
|
20
|
+
if (target) {
|
|
21
|
+
if (target.closest('[actions*="state"]')) return;
|
|
22
|
+
stateAttributes(target);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
function initElements(elements) {
|
|
27
|
-
|
|
28
|
-
initElement(element);
|
|
28
|
+
for (let element of elements) initElement(element);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function initElement(element) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
let state_id = element.getAttribute("state_id");
|
|
33
|
+
if (!state_id) return;
|
|
34
|
+
|
|
35
|
+
let statedAttributes = localStorage.getItem("statedAttributes");
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
if (!statedAttributes || statedAttributes.length == 0) return;
|
|
38
|
+
statedAttributes = JSON.parse(statedAttributes);
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
statedAttributes = JSON.parse(statedAttributes);
|
|
40
|
+
if (state_id.includes(",")) state_id = state_id.split(",");
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
if (!Array.isArray(state_id)) state_id = [state_id];
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < state_id.length; i++) {
|
|
45
|
+
let attrValues = statedAttributes[`${state_id[i].trim()}`];
|
|
46
|
+
if (!attrValues) return;
|
|
47
|
+
_setAttributeValues(element, attrValues);
|
|
48
|
+
}
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
function _setAttributeValues(el, attrValues) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
let isOverwrite = el.getAttribute("state-overwrite");
|
|
53
|
+
if (isOverwrite === null || isOverwrite === undefined)
|
|
54
|
+
isOverwrite = attrValues["overwrite"];
|
|
55
|
+
|
|
56
|
+
if ((isOverwrite && isOverwrite != "false") || isOverwrite === "")
|
|
57
|
+
isOverwrite = true;
|
|
58
|
+
else if (!isOverwrite || isOverwrite === "false") isOverwrite = false;
|
|
59
|
+
|
|
60
|
+
// delete attrValues["overwrite"];
|
|
61
|
+
|
|
62
|
+
for (const key of Object.keys(attrValues)) {
|
|
63
|
+
_setAttributeValue(el, key, attrValues[key], isOverwrite);
|
|
64
|
+
_setAttributeValue(el, `state-${key}`, attrValues[key], isOverwrite);
|
|
65
|
+
if (key == "array" || key == "object" || key == "name") {
|
|
66
|
+
_setAttributeValue(
|
|
67
|
+
el,
|
|
68
|
+
`fetch-${key}`,
|
|
69
|
+
attrValues[key],
|
|
70
|
+
isOverwrite
|
|
71
|
+
);
|
|
72
|
+
_setAttributeValue(
|
|
73
|
+
el,
|
|
74
|
+
`state-fetch-${key}`,
|
|
75
|
+
attrValues[key],
|
|
76
|
+
isOverwrite
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (key == "template") {
|
|
80
|
+
_setAttributeValue(el, "template_id", attrValues[key], isOverwrite);
|
|
81
|
+
}
|
|
82
|
+
if (key == "template_id") {
|
|
83
|
+
_setAttributeValue(el, "template", attrValues[key], isOverwrite);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
async function _setAttributeValue(element, attribute, value, isOverwrite) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
// TODO: if (value !== undefined)???
|
|
90
|
+
if (!element.getAttribute(attribute) || isOverwrite) {
|
|
91
|
+
if (attribute == "value") {
|
|
92
|
+
if (element.value == "" || (element.value && isOverwrite))
|
|
93
|
+
element.value = value;
|
|
94
|
+
else if (
|
|
95
|
+
isOverwrite ||
|
|
96
|
+
(element.hasAttribute("value") && !(await element.getValue()))
|
|
97
|
+
)
|
|
98
|
+
element.setValue(value);
|
|
99
|
+
} else if (element.hasAttribute(attribute) && (value || value === ""))
|
|
100
|
+
element.setAttribute(attribute, value);
|
|
101
|
+
}
|
|
84
102
|
}
|
|
85
103
|
|
|
86
104
|
async function stateAttributes(element) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let state_to = elements[i].getAttribute('state_to');
|
|
114
|
-
Object.assign(statedAttributes, { [`${state_to}`]: attrValues });
|
|
115
|
-
_getStateId(attrValues, state_to);
|
|
116
|
-
}
|
|
117
|
-
statedAttributes = JSON.stringify(statedAttributes)
|
|
118
|
-
let href = element.closest('href')
|
|
119
|
-
if (!changeState && !href) {
|
|
120
|
-
// TODO: Handle $title when adding statedAttributes
|
|
121
|
-
let title = element.getAttribute('title') || document.title || '';
|
|
122
|
-
history.pushState({ statedAttributes, title, url: location.href }, title, location.href);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!changeState)
|
|
126
|
-
localStorage.setItem('statedAttributes', statedAttributes);
|
|
127
|
-
|
|
128
|
-
document.dispatchEvent(new CustomEvent('stateEnd', {
|
|
129
|
-
detail: {}
|
|
130
|
-
}))
|
|
105
|
+
let statedAttributes = {};
|
|
106
|
+
try {
|
|
107
|
+
const storedAttributes = localStorage.getItem("statedAttributes");
|
|
108
|
+
if (storedAttributes) {
|
|
109
|
+
statedAttributes = JSON.parse(storedAttributes);
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(
|
|
113
|
+
"Failed to parse statedAttributes from localStorage:",
|
|
114
|
+
error
|
|
115
|
+
);
|
|
116
|
+
// Optionally reset `statedAttributes` in localStorage to ensure valid data:
|
|
117
|
+
localStorage.setItem("statedAttributes", JSON.stringify({}));
|
|
118
|
+
}
|
|
119
|
+
let elements = [];
|
|
120
|
+
|
|
121
|
+
let form = element.closest("form");
|
|
122
|
+
if (form) {
|
|
123
|
+
elements = form.querySelectorAll("[state_to]");
|
|
124
|
+
} else {
|
|
125
|
+
if (element.hasAttribute("state_to")) elements.push(element);
|
|
126
|
+
let nestedElements = element.querySelectorAll("[state_to]");
|
|
127
|
+
elements.push(...nestedElements);
|
|
128
|
+
}
|
|
131
129
|
|
|
130
|
+
let changeState = false;
|
|
131
|
+
for (let i = 0; i < elements.length; i++) {
|
|
132
|
+
let attrValues = await _getAttributeValues(elements[i]);
|
|
133
|
+
if (attrValues.src === "$back" || attrValues.href === "$back") {
|
|
134
|
+
changeState = true;
|
|
135
|
+
window.history.back();
|
|
136
|
+
break;
|
|
137
|
+
} else if (
|
|
138
|
+
attrValues.src === "$forward" ||
|
|
139
|
+
attrValues.href === "$forward"
|
|
140
|
+
) {
|
|
141
|
+
changeState = true;
|
|
142
|
+
window.history.forward();
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let state_to = elements[i].getAttribute("state_to");
|
|
147
|
+
Object.assign(statedAttributes, { [`${state_to}`]: attrValues });
|
|
148
|
+
_getStateId(attrValues, state_to);
|
|
149
|
+
}
|
|
150
|
+
statedAttributes = JSON.stringify(statedAttributes);
|
|
151
|
+
let href = element.closest("href");
|
|
152
|
+
if (!changeState && !href) {
|
|
153
|
+
// TODO: Handle $title when adding statedAttributes
|
|
154
|
+
let title = element.getAttribute("title") || document.title || "";
|
|
155
|
+
history.pushState(
|
|
156
|
+
{ statedAttributes, title, url: location.href },
|
|
157
|
+
title,
|
|
158
|
+
location.href
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!changeState)
|
|
163
|
+
localStorage.setItem("statedAttributes", statedAttributes);
|
|
164
|
+
|
|
165
|
+
document.dispatchEvent(
|
|
166
|
+
new CustomEvent("stateEnd", {
|
|
167
|
+
detail: {}
|
|
168
|
+
})
|
|
169
|
+
);
|
|
132
170
|
}
|
|
133
171
|
|
|
134
172
|
async function _getAttributeValues(element) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
173
|
+
let attributeValues = {};
|
|
174
|
+
let attributes = element.attributes;
|
|
175
|
+
for (let attribute of attributes) {
|
|
176
|
+
if (attribute.name.startsWith("state-")) {
|
|
177
|
+
if (attribute.value == "$uid")
|
|
178
|
+
Object.assign(attributeValues, {
|
|
179
|
+
[`${attribute.name.substring(5)}`]: uid.generate(6)
|
|
180
|
+
});
|
|
181
|
+
else if (attribute.name == "state-value" && !attribute.value)
|
|
182
|
+
Object.assign(attributeValues, {
|
|
183
|
+
value: await element.getvalue()
|
|
184
|
+
});
|
|
185
|
+
else
|
|
186
|
+
Object.assign(attributeValues, {
|
|
187
|
+
[`${attribute.name.substring(6)}`]: attribute.value
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (
|
|
192
|
+
element.value !== undefined &&
|
|
193
|
+
!element.hasAttribute("state-value") &&
|
|
194
|
+
element.getvalue
|
|
195
|
+
)
|
|
196
|
+
Object.assign(attributeValues, { value: await element.getvalue() });
|
|
197
|
+
|
|
198
|
+
return attributeValues;
|
|
151
199
|
}
|
|
152
200
|
|
|
153
201
|
function _getStateId(attrValues, state_to) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
_setAttributeValues(element, attrValues);
|
|
202
|
+
const elements = document.querySelectorAll(`[state_id="${state_to}"]`);
|
|
203
|
+
for (let element of elements) _setAttributeValues(element, attrValues);
|
|
157
204
|
}
|
|
158
205
|
|
|
159
206
|
window.onload = function () {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
207
|
+
if (!history.length) {
|
|
208
|
+
const statedAttributes = localStorage.getItem("statedAttributes") || "";
|
|
209
|
+
history.replaceState(
|
|
210
|
+
{ statedAttributes, url: location.href, title: document.title },
|
|
211
|
+
document.title,
|
|
212
|
+
location.href
|
|
213
|
+
);
|
|
214
|
+
} else if (!history.state || history.state.url !== location.href) {
|
|
215
|
+
const statedAttributes = localStorage.getItem("statedAttributes") || "";
|
|
216
|
+
history.pushState(
|
|
217
|
+
{ statedAttributes, url: location.href, title: document.title },
|
|
218
|
+
document.title,
|
|
219
|
+
location.href
|
|
220
|
+
);
|
|
221
|
+
}
|
|
167
222
|
};
|
|
168
223
|
|
|
169
|
-
window.addEventListener(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
224
|
+
window.addEventListener("popstate", function (event) {
|
|
225
|
+
if (event.state) {
|
|
226
|
+
if (event.state.statedAttributes) {
|
|
227
|
+
localStorage.setItem(
|
|
228
|
+
"statedAttributes",
|
|
229
|
+
event.state.statedAttributes
|
|
230
|
+
);
|
|
231
|
+
let elements = document.querySelectorAll("[state_id]");
|
|
232
|
+
initElements(elements);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (event.state.url && event.state.url !== window.location.href) {
|
|
236
|
+
if (event.state.title)
|
|
237
|
+
sessionStorage.setItem("currentPageTitle", event.state.title); // Store title in session storage
|
|
238
|
+
|
|
239
|
+
location.href = event.state.url; // Navigate if the URL is different
|
|
240
|
+
} else if (event.state.title) {
|
|
241
|
+
document.title = event.state.title; // Update the title if provided
|
|
242
|
+
}
|
|
243
|
+
}
|
|
186
244
|
});
|
|
187
245
|
|
|
188
246
|
observer.init({
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
247
|
+
name: "CoCreateState",
|
|
248
|
+
observe: ["addedNodes"],
|
|
249
|
+
selector: "[state_id]",
|
|
250
|
+
callback: function (mutation) {
|
|
251
|
+
initElement(mutation.target);
|
|
252
|
+
}
|
|
195
253
|
});
|
|
196
254
|
|
|
197
255
|
action.init({
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
256
|
+
name: "state",
|
|
257
|
+
endEvent: "stateEnd",
|
|
258
|
+
callback: (data) => {
|
|
259
|
+
stateAttributes(data.element);
|
|
260
|
+
}
|
|
203
261
|
});
|
|
204
262
|
|
|
205
263
|
init();
|