@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 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
- <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" />
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
- <link
22
- rel="stylesheet"
23
- href="../index.css"
24
- array="files"
25
- object="60888216117c640e7596303f"
26
- key="src"
27
- type="text/css"
28
- save="true" />
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
- <link rel="manifest" href="/manifest.webmanifest" />
31
- </head>
30
+ <link rel="manifest" href="/manifest.webmanifest" />
31
+ </head>
32
32
 
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-selector="[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>
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
- <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">&lt;div&gt;&lt;/div&gt;</code></pre>
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">&lt;div&gt;&lt;/div&gt;</code></pre>
123
123
 
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">&lt;div&gt;&lt;/div&gt;</code></pre>
132
- <p class="padding:10px_0px">
133
- This is selection reference content
134
- </p>
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">&lt;div&gt;&lt;/div&gt;</code></pre>
132
+ <p class="padding:10px_0px">
133
+ This is selection reference content
134
+ </p>
135
135
 
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>
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
- <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-selector=".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>
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
- <div
205
- id="demo-preview"
206
- class="position:relative overflow:auto background-color:white">
207
- <div class="demopreview padding:20px"></div>
208
- </div>
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
- <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-selector="#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-selector="#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-selector="#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>
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.13.2",
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
- "@babel/core": "^7.9.6",
49
- "@babel/preset-env": "^7.9.6",
50
- "babel-loader": "^8.1.0",
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.33.7"
57
+ "@cocreate/utils": "^1.38.0"
62
58
  }
63
59
  }
@@ -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
@@ -5,103 +5,111 @@ String.prototype.customSplice = function (index, absIndex, string) {
5
5
  };
6
6
 
7
7
  export function getSelection(element) {
8
- if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
9
- return {
10
- start: element.selectionStart,
11
- end: element.selectionEnd
12
- };
13
-
14
- } else {
15
- let Document = element.ownerDocument;
16
- let selection = Document.getSelection();
17
- if (!selection.rangeCount)
18
- return { start: 0, end: 0 };
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
- let domTextEditor = element;
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
- 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)
28
+ if (contenteditable) {
29
+ element = contenteditable;
30
+ } else return { start: range.startOffset, end: range.endOffset }
44
31
 
45
- let startContainer = range.startContainer;
46
- if (startContainer.nodeType == 3)
47
- startContainer = range.startContainer.parentElement;
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
- 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;
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
- 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 };
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
- let string = domTextEditor.htmlString
86
- if (!string)
87
- return 0
88
- let node = container.previousSibling
89
- while (node && node.nodeType === 3) {
90
- position += node.textContent.length;
91
- node = node.previousSibling;
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
- let nodePosition
95
- if (node && node.nodeType === 1) {
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 TerserPlugin = require("terser-webpack-plugin")
3
- const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
- const { CleanWebpackPlugin } = require("clean-webpack-plugin")
5
-
6
- module.exports = (env, argv) => {
7
- let isProduction = false
8
- if (argv.mode === 'production')
9
- isProduction = true
10
-
11
- const config = {
12
- entry: {
13
- "CoCreate-selection": "./src/index.js",
14
- },
15
- output: {
16
- path: path.resolve(__dirname, "dist"),
17
- filename: isProduction ? "[name].min.js" : "[name].js",
18
- libraryTarget: "umd",
19
- libraryExport: "default",
20
- library: ["CoCreate", "selection"],
21
- globalObject: "this",
22
- },
23
-
24
- plugins: [
25
- new CleanWebpackPlugin(),
26
- new MiniCssExtractPlugin({
27
- filename: "[name].css",
28
- }),
29
- ],
30
- // Default mode for Webpack is production.
31
- // Depending on mode Webpack will apply different things
32
- // on final bundle. For now we don't need production's JavaScript
33
- // minifying and other thing so let's set mode to development
34
- mode: isProduction ? "production" : "development",
35
- module: {
36
- rules: [
37
- {
38
- test: /.js$/,
39
- exclude: /(node_modules)/,
40
- use: {
41
- loader: "babel-loader",
42
- options: {
43
- plugins: ["@babel/plugin-transform-modules-commonjs"],
44
- },
45
- },
46
- },
47
- {
48
- test: /.css$/i,
49
- use: [
50
- { loader: "style-loader", options: { injectType: "linkTag" } },
51
- "file-loader",
52
- ],
53
- },
54
- ],
55
- },
56
-
57
- // add source map
58
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
59
-
60
- optimization: {
61
- minimize: true,
62
- minimizer: [
63
- new TerserPlugin({
64
- extractComments: true,
65
- // cache: true,
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
+ };