@cocreate/selection 1.13.2 → 1.14.1
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 +24 -0
- package/docs/index.html +251 -251
- package/package.json +5 -9
- package/prettier.config.js +16 -0
- package/src/index.js +90 -82
- package/webpack.config.js +65 -90
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## [1.14.1](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.14.0...v1.14.1) (2025-04-30)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* added css-loader ([946d1eb](https://github.com/CoCreate-app/CoCreate-selection/commit/946d1ebc99a7c28530344de3f8d9adaafa0399d7))
|
7
|
+
* update query attributes ([4d2d2d2](https://github.com/CoCreate-app/CoCreate-selection/commit/4d2d2d2763aec857894294e7eb7e48034f6c617c))
|
8
|
+
* updated cocreate modules versions ([28de805](https://github.com/CoCreate-app/CoCreate-selection/commit/28de8051db32f4802bbbb4c476b9f5e72a82fed2))
|
9
|
+
* webpack.config and devdependencies ([73d9fd0](https://github.com/CoCreate-app/CoCreate-selection/commit/73d9fd05796f66d7ab71365610dc6b9bb28e3f05))
|
10
|
+
|
11
|
+
# [1.14.0](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.13.2...v1.14.0) (2024-11-04)
|
12
|
+
|
13
|
+
|
14
|
+
### Bug Fixes
|
15
|
+
|
16
|
+
* html[contenteditable] ([68b79f0](https://github.com/CoCreate-app/CoCreate-selection/commit/68b79f08d2f970fcd15abdf947dca9bc8b4146a9))
|
17
|
+
* observer taget has been renamed to selector ([c36ae20](https://github.com/CoCreate-app/CoCreate-selection/commit/c36ae20b8d254c3ede29ad559af93237c8a49115))
|
18
|
+
* pretier.config.js and file formating ([6039624](https://github.com/CoCreate-app/CoCreate-selection/commit/603962428197395e8db671597e4c5aea26b79524))
|
19
|
+
|
20
|
+
|
21
|
+
### Features
|
22
|
+
|
23
|
+
* add prettier.config.js and format files ([cf8e664](https://github.com/CoCreate-app/CoCreate-selection/commit/cf8e664884b66db4455a28c572099cefafc16c33))
|
24
|
+
|
1
25
|
## [1.13.2](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.13.1...v1.13.2) (2024-09-21)
|
2
26
|
|
3
27
|
|
package/docs/index.html
CHANGED
@@ -1,263 +1,263 @@
|
|
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
|
-
|
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-selection Documentation | CoCreateJS</title>
|
8
|
+
<link
|
9
|
+
rel="icon"
|
10
|
+
type="image/png"
|
11
|
+
sizes="32x32"
|
12
|
+
href="https://cocreate.app/images/favicon.ico" />
|
13
|
+
<meta
|
14
|
+
name="description"
|
15
|
+
content="A headless javascript micro component. Easy configuration using HTML5 attributes or JavaScript api." />
|
16
|
+
<meta
|
17
|
+
name="keywords"
|
18
|
+
content="helper classes, utility classes, css framework, css library, inline style classes" />
|
19
|
+
<meta name="robots" content="index,follow" />
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
<link
|
22
|
+
rel="stylesheet"
|
23
|
+
href="../index.css"
|
24
|
+
array="files"
|
25
|
+
object="60888216117c640e7596303f"
|
26
|
+
key="src"
|
27
|
+
type="text/css"
|
28
|
+
save="true" />
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
31
|
+
</head>
|
32
32
|
|
33
|
-
|
34
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
33
|
+
<body>
|
34
|
+
<!-- Navbar -->
|
35
|
+
<nav
|
36
|
+
class="width:100% display:flex align-items:center background:transparent padding-top:10px padding-bottom:10px"
|
37
|
+
content_id="content"
|
38
|
+
scroll="sticky-nav,"
|
39
|
+
scroll-up="5"
|
40
|
+
scroll-down="5"
|
41
|
+
path="../"
|
42
|
+
src="../components/navbar.html"></nav>
|
43
|
+
<sidenav
|
44
|
+
id="menuL"
|
45
|
+
class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl"
|
46
|
+
resizable
|
47
|
+
resize-query="[content_id='content']"
|
48
|
+
resize-property="margin-left"
|
49
|
+
resize-value="width">
|
50
|
+
<menu
|
51
|
+
array="files"
|
52
|
+
object="603717b07de7fb350ae9fec8"
|
53
|
+
key="src"></menu>
|
54
|
+
<div resize="right"></div>
|
55
|
+
</sidenav>
|
56
|
+
<main
|
57
|
+
class="padding-top:15px padding:15px@lg@xl"
|
58
|
+
content_id="content"
|
59
|
+
id="cocreate-selection">
|
60
|
+
<div
|
61
|
+
class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
|
62
|
+
<div class="display:flex align-items:center">
|
63
|
+
<h2>CoCreate-selection</h2>
|
64
|
+
</div>
|
65
|
+
<div
|
66
|
+
class="display:flex align-items:center font-size:20px"
|
67
|
+
share-height="600"
|
68
|
+
share-width="500"
|
69
|
+
share-media="https://via.placeholder.com/300/09f/fff.png">
|
70
|
+
<a
|
71
|
+
href="https://github.com/CoCreate-app/CoCreate-selection"
|
72
|
+
target="_blank"
|
73
|
+
class="margin-right:15px"
|
74
|
+
><i src="/assets/svg/github.svg"></i
|
75
|
+
></a>
|
76
|
+
<a
|
77
|
+
class="margin-right:15px share"
|
78
|
+
share-network="twitter"
|
79
|
+
title="Share on twitter"
|
80
|
+
><i src="/assets/svg/twitter.svg"></i
|
81
|
+
></a>
|
82
|
+
<a
|
83
|
+
class="margin-right:15px share"
|
84
|
+
share-network="facebook"
|
85
|
+
title="Share on Facebook"
|
86
|
+
><i src="/assets/svg/facebook.svg"></i
|
87
|
+
></a>
|
88
|
+
<a
|
89
|
+
class="margin-right:15px share"
|
90
|
+
share-network="instagram"
|
91
|
+
title="Share on instagram"
|
92
|
+
><i src="/assets/svg/instagram.svg"></i
|
93
|
+
></a>
|
94
|
+
<a
|
95
|
+
class="margin-right:15px share"
|
96
|
+
share-network="share"
|
97
|
+
title="Share on share"
|
98
|
+
><i src="/assets/svg/share-alt.svg"></i
|
99
|
+
></a>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
<h1 class="max-width:500px margin:20px_10px">
|
103
|
+
A simple HTML5, CSS and pure javascript component. Easy
|
104
|
+
configuration using data-attributes and highly styleable.
|
105
|
+
</h1>
|
106
|
+
<div id="selection-section" class="display:flex flex-wrap:wrap">
|
107
|
+
<div class="flex-grow:1 width:300px padding:20px_10px">
|
108
|
+
<h2
|
109
|
+
class="border-bottom:1px_solid_lightgrey padding:5px_0px">
|
110
|
+
Install
|
111
|
+
</h2>
|
112
|
+
<pre
|
113
|
+
class="margin-top:15px"><code class="language-javascript">npm install cocreate-selection</code></pre>
|
114
|
+
<p class="padding:10px_0px">Or you can use cdn link:</p>
|
115
|
+
<pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-selection.min.js</code></pre>
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
117
|
+
<h2
|
118
|
+
class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
|
119
|
+
Usage
|
120
|
+
</h2>
|
121
|
+
<p class="padding:10px_0px">selection usage content</p>
|
122
|
+
<pre><code class="language-html"><div></div></code></pre>
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
124
|
+
<h2
|
125
|
+
class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
|
126
|
+
Reference
|
127
|
+
</h2>
|
128
|
+
<p class="padding:10px_0px">
|
129
|
+
This is selection reference content
|
130
|
+
</p>
|
131
|
+
<pre><code class="language-javascript"><div></div></code></pre>
|
132
|
+
<p class="padding:10px_0px">
|
133
|
+
This is selection reference content
|
134
|
+
</p>
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
136
|
+
<h2
|
137
|
+
class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
|
138
|
+
Attributes
|
139
|
+
</h2>
|
140
|
+
<ul class="list-style-type:none">
|
141
|
+
<li
|
142
|
+
class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
143
|
+
<h4>
|
144
|
+
<span>selection</span>
|
145
|
+
<span class="cocreate-badge success"
|
146
|
+
>string</span
|
147
|
+
>
|
148
|
+
<span class="cocreate-badge warning"
|
149
|
+
>optional</span
|
150
|
+
>
|
151
|
+
</h4>
|
152
|
+
<p>selection-attribute</p>
|
153
|
+
</li>
|
154
|
+
<li
|
155
|
+
class="padding:15px_0px border-bottom:1px_solid_lightgrey">
|
156
|
+
<h4>
|
157
|
+
<span>selection</span>
|
158
|
+
<span class="cocreate-badge success"
|
159
|
+
>string</span
|
160
|
+
>
|
161
|
+
<span class="cocreate-badge warning"
|
162
|
+
>optional</span
|
163
|
+
>
|
164
|
+
</h4>
|
165
|
+
<p>selection-attribute</p>
|
166
|
+
</li>
|
167
|
+
</ul>
|
168
|
+
</div>
|
169
169
|
|
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
|
-
|
170
|
+
<div
|
171
|
+
class="flex-grow:1 width:300px padding:0px_10px margin:20px_0px border-bottom:1px_solid_lightgrey">
|
172
|
+
<!-- SandBox -->
|
173
|
+
<h2
|
174
|
+
class="border-bottom:1px_solid_lightgrey padding:5px_0px">
|
175
|
+
Demo
|
176
|
+
</h2>
|
177
|
+
<div
|
178
|
+
class="position:sticky top:0 padding:10px_0px height:100vh">
|
179
|
+
<!-- SandBox -->
|
180
|
+
<div
|
181
|
+
class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
|
182
|
+
id="playground">
|
183
|
+
<div
|
184
|
+
id="demo-code"
|
185
|
+
resizable
|
186
|
+
class="position:relative height:50%">
|
187
|
+
<textarea
|
188
|
+
type="code"
|
189
|
+
lang="html"
|
190
|
+
array="demos"
|
191
|
+
object=""
|
192
|
+
key="demo"
|
193
|
+
save="false"
|
194
|
+
id="demo"
|
195
|
+
input-query=".demopreview"
|
196
|
+
input-attribute="value"
|
197
|
+
input-events="input, onload"
|
198
|
+
class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
|
199
|
+
<div
|
200
|
+
resize="bottom"
|
201
|
+
class="background:lightgrey"></div>
|
202
|
+
</div>
|
203
203
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
204
|
+
<div
|
205
|
+
id="demo-preview"
|
206
|
+
class="position:relative overflow:auto background-color:white">
|
207
|
+
<div class="demopreview padding:20px"></div>
|
208
|
+
</div>
|
209
209
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
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
|
-
|
210
|
+
<div
|
211
|
+
class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
|
212
|
+
<a
|
213
|
+
class="margin-right:10px"
|
214
|
+
id="eye"
|
215
|
+
show="#eye-slash"
|
216
|
+
hide="#eye, #demo-preview"
|
217
|
+
toggle="code-height"
|
218
|
+
toggle-query="#demo-code"
|
219
|
+
><i
|
220
|
+
class="height:18px"
|
221
|
+
src="/assets/svg/eye.svg"></i
|
222
|
+
></a>
|
223
|
+
<a
|
224
|
+
class="margin-right:10px"
|
225
|
+
hidden
|
226
|
+
id="eye-slash"
|
227
|
+
show="#eye, #demo-preview"
|
228
|
+
hide="#eye-slash"
|
229
|
+
toggle="code-height"
|
230
|
+
toggle-query="#demo-code"
|
231
|
+
><i src="/assets/svg/eye-slash.svg"></i
|
232
|
+
></a>
|
233
|
+
<a
|
234
|
+
class="margin-right:10px"
|
235
|
+
id="code"
|
236
|
+
show="#code-slash"
|
237
|
+
hide="#code, #demo-code"
|
238
|
+
><i src="/assets/svg/code.svg"></i
|
239
|
+
></a>
|
240
|
+
<a
|
241
|
+
class="margin-right:10px"
|
242
|
+
hidden
|
243
|
+
id="code-slash"
|
244
|
+
show="#code, #demo-code"
|
245
|
+
hide="#code-slash"
|
246
|
+
><i
|
247
|
+
class="height:18px"
|
248
|
+
src="/assets/svg/code.svg"></i
|
249
|
+
></a>
|
250
|
+
<a
|
251
|
+
class="margin-right:5px"
|
252
|
+
fullscreen
|
253
|
+
fullscreen-query="#playground"></a>
|
254
|
+
</div>
|
255
|
+
</div>
|
256
|
+
<!-- End SandBox -->
|
257
|
+
</div>
|
258
|
+
</div>
|
259
|
+
</div>
|
260
|
+
</main>
|
261
|
+
<script src="https://CoCreate.app/dist/CoCreate.js"></script>
|
262
|
+
</body>
|
263
263
|
</html>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/selection",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.14.1",
|
4
4
|
"description": "A simple selection component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
5
5
|
"keywords": [
|
6
6
|
"selection",
|
@@ -45,19 +45,15 @@
|
|
45
45
|
},
|
46
46
|
"main": "./src/index.js",
|
47
47
|
"devDependencies": {
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"clean-webpack-plugin": "^3.0.0",
|
52
|
-
"file-loader": "^6.2.0",
|
48
|
+
"css-loader": "^5.1.3",
|
49
|
+
"esbuild": "^0.25.2",
|
50
|
+
"esbuild-loader": "^4.3.0",
|
53
51
|
"mini-css-extract-plugin": "^1.5.0",
|
54
|
-
"style-loader": "^3.3.1",
|
55
|
-
"terser-webpack-plugin": "^5.1.1",
|
56
52
|
"webpack": "^5.24.4",
|
57
53
|
"webpack-cli": "^4.5.0",
|
58
54
|
"webpack-log": "^3.0.1"
|
59
55
|
},
|
60
56
|
"dependencies": {
|
61
|
-
"@cocreate/utils": "^1.
|
57
|
+
"@cocreate/utils": "^1.38.0"
|
62
58
|
}
|
63
59
|
}
|
package/src/index.js
CHANGED
@@ -5,103 +5,111 @@ String.prototype.customSplice = function (index, absIndex, string) {
|
|
5
5
|
};
|
6
6
|
|
7
7
|
export function getSelection(element) {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
let range = selection.getRangeAt(0);
|
21
|
-
|
22
|
-
let contenteditable
|
23
|
-
if (range.startContainer.nodeType === 3)
|
24
|
-
contenteditable = range.startContainer.parentElement.closest('[contenteditable][array][object][key]');
|
25
|
-
else
|
26
|
-
contenteditable = range.startContainer.closest('[contenteditable][array][object][key]');
|
27
|
-
|
28
|
-
if (contenteditable) {
|
29
|
-
element = contenteditable;
|
30
|
-
} else return { start: range.startOffset, end: range.endOffset }
|
8
|
+
try {
|
9
|
+
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
10
|
+
return {
|
11
|
+
start: element.selectionStart,
|
12
|
+
end: element.selectionEnd
|
13
|
+
};
|
14
|
+
} else {
|
15
|
+
let Document = element.ownerDocument;
|
16
|
+
let selection = Document.getSelection();
|
17
|
+
if (!selection.rangeCount)
|
18
|
+
return { start: 0, end: 0 };
|
31
19
|
|
32
|
-
|
33
|
-
if (!domTextEditor.htmlString) {
|
34
|
-
domTextEditor = domTextEditor.closest('[contenteditable]');
|
35
|
-
}
|
20
|
+
let range = selection.getRangeAt(0);
|
36
21
|
|
22
|
+
let contenteditable
|
23
|
+
if (range.startContainer.nodeType === 3)
|
24
|
+
contenteditable = range.startContainer.parentElement.closest('[contenteditable][array][object][key], html[contenteditable]');
|
25
|
+
else
|
26
|
+
contenteditable = range.startContainer.closest('[contenteditable][array][object][key], html[contenteditable]');
|
37
27
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end = getNodePosition(range.endContainer, domTextEditor, range.endOffset)
|
42
|
-
} else if (range.endOffset !== range.startOffset)
|
43
|
-
end = start + (range.endOffset - range.startOffset)
|
28
|
+
if (contenteditable) {
|
29
|
+
element = contenteditable;
|
30
|
+
} else return { start: range.startOffset, end: range.endOffset }
|
44
31
|
|
45
|
-
|
46
|
-
|
47
|
-
|
32
|
+
let domTextEditor = element;
|
33
|
+
if (!domTextEditor.htmlString) {
|
34
|
+
domTextEditor = domTextEditor.closest('[contenteditable]');
|
35
|
+
}
|
48
36
|
|
49
|
-
let endContainer = range.endContainer;
|
50
|
-
if (endContainer.nodeType == 3)
|
51
|
-
endContainer = range.endContainer.parentElement;
|
52
37
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
38
|
+
let start = getNodePosition(range.startContainer, domTextEditor, range.startOffset)
|
39
|
+
let end = start
|
40
|
+
if (range.startContainer !== range.endContainer) {
|
41
|
+
end = getNodePosition(range.endContainer, domTextEditor, range.endOffset)
|
42
|
+
} else if (range.endOffset !== range.startOffset)
|
43
|
+
end = start + (range.endOffset - range.startOffset)
|
44
|
+
|
45
|
+
let startContainer = range.startContainer;
|
46
|
+
if (startContainer.nodeType == 3)
|
47
|
+
startContainer = range.startContainer.parentElement;
|
48
|
+
|
49
|
+
let endContainer = range.endContainer;
|
50
|
+
if (endContainer.nodeType == 3)
|
51
|
+
endContainer = range.endContainer.parentElement;
|
52
|
+
|
53
|
+
let textStart = 0, node = range.startContainer
|
54
|
+
while (node) {
|
55
|
+
textStart += node.textContent.length;
|
56
|
+
if (node === contenteditable)
|
57
|
+
node = undefined
|
58
|
+
else
|
59
|
+
node = node.previousSibling;
|
60
|
+
}
|
61
|
+
let textEnd = textStart + (range.endOffset - range.startOffset)
|
62
|
+
|
63
|
+
let rangeObj = {
|
64
|
+
element,
|
65
|
+
domTextEditor,
|
66
|
+
startOffset: range.startOffset,
|
67
|
+
endOffset: range.endOffset,
|
68
|
+
startContainer,
|
69
|
+
endContainer,
|
70
|
+
elementStart: start,
|
71
|
+
elementEnd: end,
|
72
|
+
nodeStartContainer: range.startContainer,
|
73
|
+
nodeEndContainer: range.endContainer,
|
74
|
+
textStart,
|
75
|
+
textEnd
|
76
|
+
};
|
77
|
+
|
78
|
+
return { element: contenteditable, value: selection.toString(), start, end, range: rangeObj };
|
60
79
|
}
|
61
|
-
|
62
|
-
|
63
|
-
let rangeObj = {
|
64
|
-
element,
|
65
|
-
domTextEditor,
|
66
|
-
startOffset: range.startOffset,
|
67
|
-
endOffset: range.endOffset,
|
68
|
-
startContainer,
|
69
|
-
endContainer,
|
70
|
-
elementStart: start,
|
71
|
-
elementEnd: end,
|
72
|
-
nodeStartContainer: range.startContainer,
|
73
|
-
nodeEndContainer: range.endContainer,
|
74
|
-
textStart,
|
75
|
-
textEnd
|
76
|
-
};
|
77
|
-
|
78
|
-
return { element: contenteditable, value: selection.toString(), start, end, range: rangeObj };
|
80
|
+
} catch (error) {
|
81
|
+
console.error("Error fetching selection from element:", error);
|
79
82
|
}
|
80
|
-
|
81
83
|
}
|
82
84
|
|
83
85
|
|
84
86
|
function getNodePosition(container, domTextEditor, position) {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
try {
|
88
|
+
let string = domTextEditor.htmlString
|
89
|
+
if (!string)
|
90
|
+
return 0
|
91
|
+
let node = container.previousSibling
|
92
|
+
while (node && node.nodeType === 3) {
|
93
|
+
position += node.textContent.length;
|
94
|
+
node = node.previousSibling;
|
95
|
+
}
|
96
|
+
|
97
|
+
let nodePosition
|
98
|
+
if (node && node.nodeType === 1) {
|
99
|
+
nodePosition = getStringPosition({ string, target: node, position: 'afterend' });
|
100
|
+
position += nodePosition.end
|
101
|
+
} else if (container.parentElement !== domTextEditor && container !== domTextEditor) {
|
102
|
+
let parentElement = container.parentElement
|
103
|
+
nodePosition = getStringPosition({ string, target: parentElement, position: 'afterbegin' });
|
104
|
+
position += nodePosition.start
|
105
|
+
}
|
106
|
+
|
107
|
+
return position
|
93
108
|
|
94
|
-
|
95
|
-
|
96
|
-
nodePosition = getStringPosition({ string, target: node, position: 'afterend' });
|
97
|
-
position += nodePosition.end
|
98
|
-
} else if (container.parentElement !== domTextEditor && container !== domTextEditor) {
|
99
|
-
let parentElement = container.parentElement
|
100
|
-
nodePosition = getStringPosition({ string, target: parentElement, position: 'afterbegin' });
|
101
|
-
position += nodePosition.start
|
109
|
+
} catch (error) {
|
110
|
+
console.error("Error getting node position:", error);
|
102
111
|
}
|
103
112
|
|
104
|
-
return position
|
105
113
|
}
|
106
114
|
|
107
115
|
export function processSelection(element, value = "", prev_start, prev_end, start, end, range) {
|
package/webpack.config.js
CHANGED
@@ -1,90 +1,65 @@
|
|
1
|
-
const path = require("path")
|
2
|
-
const
|
3
|
-
const
|
4
|
-
const {
|
5
|
-
|
6
|
-
module.exports = (env, argv) => {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
parallel: true,
|
67
|
-
// sourceMap: true, // Must be set to true if using source-maps in production
|
68
|
-
terserOptions: {
|
69
|
-
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
70
|
-
// extractComments: 'all',
|
71
|
-
compress: {
|
72
|
-
drop_console: true,
|
73
|
-
},
|
74
|
-
},
|
75
|
-
}),
|
76
|
-
],
|
77
|
-
splitChunks: {
|
78
|
-
chunks: "all",
|
79
|
-
minSize: 200,
|
80
|
-
// maxSize: 99999,
|
81
|
-
//minChunks: 1,
|
82
|
-
|
83
|
-
cacheGroups: {
|
84
|
-
defaultVendors: false,
|
85
|
-
},
|
86
|
-
},
|
87
|
-
},
|
88
|
-
}
|
89
|
-
return config
|
90
|
-
}
|
1
|
+
const path = require("path");
|
2
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
3
|
+
const { EsbuildPlugin } = require("esbuild-loader");
|
4
|
+
const { FileUploader } = require("@cocreate/webpack");
|
5
|
+
|
6
|
+
module.exports = async (env, argv) => {
|
7
|
+
const isProduction = argv && argv.mode === "production";
|
8
|
+
const config = {
|
9
|
+
entry: {
|
10
|
+
"CoCreate-selection": "./src/index.js"
|
11
|
+
},
|
12
|
+
output: {
|
13
|
+
path: path.resolve(__dirname, "dist"),
|
14
|
+
filename: isProduction ? "[name].min.js" : "[name].js",
|
15
|
+
libraryExport: "default",
|
16
|
+
library: ["CoCreate", "selection"],
|
17
|
+
clean: true
|
18
|
+
},
|
19
|
+
plugins: [
|
20
|
+
new MiniCssExtractPlugin({
|
21
|
+
filename: isProduction ? "[name].min.css" : "[name].css"
|
22
|
+
}),
|
23
|
+
new FileUploader(env, argv)
|
24
|
+
],
|
25
|
+
mode: isProduction ? "production" : "development",
|
26
|
+
devtool: isProduction ? "source-map" : "eval-source-map",
|
27
|
+
module: {
|
28
|
+
rules: [
|
29
|
+
{
|
30
|
+
test: /.js$/,
|
31
|
+
exclude: /node_modules/,
|
32
|
+
use: {
|
33
|
+
loader: "esbuild-loader",
|
34
|
+
options: {
|
35
|
+
loader: "js",
|
36
|
+
target: "es2017"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
},
|
40
|
+
{
|
41
|
+
test: /.css$/i,
|
42
|
+
use: [MiniCssExtractPlugin.loader, "css-loader"]
|
43
|
+
}
|
44
|
+
]
|
45
|
+
},
|
46
|
+
optimization: {
|
47
|
+
minimize: isProduction,
|
48
|
+
minimizer: [
|
49
|
+
new EsbuildPlugin({
|
50
|
+
target: "es2017",
|
51
|
+
css: true
|
52
|
+
})
|
53
|
+
],
|
54
|
+
splitChunks: {
|
55
|
+
cacheGroups: {
|
56
|
+
defaultVendors: false
|
57
|
+
}
|
58
|
+
}
|
59
|
+
},
|
60
|
+
performance: {
|
61
|
+
hints: isProduction ? "warning" : false
|
62
|
+
}
|
63
|
+
};
|
64
|
+
return config;
|
65
|
+
};
|