@cocreate/selection 1.2.17 → 1.2.21

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [1.2.21](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.20...v1.2.21) (2021-12-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * check parent for closest contenteditable, return range.element ([dbe5d32](https://github.com/CoCreate-app/CoCreate-selection/commit/dbe5d32fbfdb3912ddcbe005f24c315fc444f17b))
7
+
8
+ ## [1.2.20](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.19...v1.2.20) (2021-11-27)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update dependencies ([d0921e7](https://github.com/CoCreate-app/CoCreate-selection/commit/d0921e7174f556203ceb3f5c3bcd3bfdae2abb02))
14
+
15
+ ## [1.2.19](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.18...v1.2.19) (2021-11-27)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * update dependencies ([f89acc8](https://github.com/CoCreate-app/CoCreate-selection/commit/f89acc8329f26470a755758756d3dcf225ad84d8))
21
+
22
+ ## [1.2.18](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.17...v1.2.18) (2021-11-27)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * update docs api and cocreateJS script ([b8be3e8](https://github.com/CoCreate-app/CoCreate-selection/commit/b8be3e8c967b5de5ab7866fa56d6547a899b1a0b))
28
+
1
29
  ## [1.2.17](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.16...v1.2.17) (2021-11-26)
2
30
 
3
31
 
package/docs/index.html CHANGED
@@ -68,50 +68,30 @@
68
68
  <!-- SandBox -->
69
69
  <h2 class="border-bottom:1px_solid_lightgrey padding:5px_0px">Demo</h2>
70
70
  <div class="position:sticky top:0 padding:10px_0px height:100vh">
71
- <div class="container svColumn overflow:hidden card border-radius:2px width:auto height:100%" id="sandbox">
72
- <div class="font-size:20px position:absolute top:10px right:10px opacity:0.6 z-index:7">
73
- <a class="margin-right:10px" id="preview" show="preview" hide="code"><i class="far fa-eye"></i></a>
74
- <a class="margin-right:10px hidden" id="code" show="code" hide="preview"><i class="fas fa-code"></i></a>
75
- <!--<a class="margin-right:10px"><i class="far fa-window-maximize"></i></a>-->
76
- <a target="modal" href="module_activity_datatable.html"
77
- pass-collection="modules"
78
- pass-document_id=""
79
- pass-fetch_value=""
80
- pass-prefix=""
81
- pass-to="render"
82
- modal-width="600px"
83
- modal-height="400px"
84
- modal-color="#229954"
85
- modal-header="false"
86
- class="margin-right:10px">
87
- <i class="fas fa-external-link-alt"></i>
88
- </a>
89
- <a class="fs-toggle margin-right:5px" fullscreen target="#sandbox"><i class="fas fa-expand"></i></a>
90
- </div>
91
-
92
- <div class="svRow">
93
-
94
- <div class="svColumn">
95
-
96
- <div class="svPanel">
97
- <div realtime="false"
98
- collection="modules"
99
- document_id="5eefe30952c6e94c75fb5e3f"
100
- name="html"
101
- id="7"
102
- class="codemirror height:100% min-width:300px">
103
- </div>
104
- </div>
105
- <div class="svSplitter svHorizontal"> </div>
106
-
107
- <div class="svPanel">
108
- <iframe get-value="7" frameBorder="0" height="100%" width="100%" class="min-width:300px"></iframe>
109
- </div>
110
-
111
- </div>
112
- </div>
113
- </div>
114
- <!-- End SandBox -->
71
+ <!-- SandBox -->
72
+ <div class="container svColumn overflow:hidden card position:relative border-radius:2px width:auto height:100%" id="sandbox">
73
+ <div class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
74
+ <a class="margin-right:10px" id="code" show="#preview" hide="#code, #view"><i class="far fa-eye"></i></a>
75
+ <a class="margin-right:10px hidden" id="preview" show="#code, #view" hide="#preview"><i class="fas fa-code"></i></a>
76
+ <a class="margin-right:5px" fullscreen target="#playground"><i class="fas fa-expand"></i></a>
77
+ </div>
78
+ <div class="svRow">
79
+
80
+ <div class="svColumn">
81
+
82
+ <div class="svPanel" id="view">
83
+ <textarea collection="demos" document_id="" name="demo" save="false" id="demo" class="height:100% width:100% border:none resize:none padding:5px"></textarea>
84
+ </div>
85
+ <div class="svSplitter svHorizontal"> </div>
86
+
87
+ <div class="svPanel">
88
+ <iframe get-value="demo" frameBorder="0" height="100%" width="100%" class="min-width:300px"></iframe>
89
+ </div>
90
+
91
+ </div>
92
+ </div>
93
+ </div>
94
+ <!-- End SandBox -->
115
95
  </div>
116
96
  </div>
117
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/selection",
3
- "version": "1.2.17",
3
+ "version": "1.2.21",
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",
@@ -61,8 +61,8 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.2.56",
65
- "@cocreate/hosting": "^1.2.52",
66
- "@cocreate/utils": "^1.3.12"
64
+ "@cocreate/docs": "^1.2.60",
65
+ "@cocreate/hosting": "^1.2.56",
66
+ "@cocreate/utils": "^1.3.16"
67
67
  }
68
68
  }
package/src/index.js CHANGED
@@ -33,6 +33,10 @@ export function getSelection(element) {
33
33
  if(range.startContainer != range.endContainer) {
34
34
  // toDo: replace common ancestor value
35
35
  }
36
+ let contenteditable = range.startContainer.parentElement.closest('[contenteditable][collection][document_id][name]');
37
+ if (contenteditable){
38
+ element = contenteditable;
39
+ }
36
40
  let domTextEditor = element;
37
41
  if (!domTextEditor.htmlString){
38
42
  domTextEditor = element.closest('[contenteditable]');
@@ -57,6 +61,7 @@ export function getSelection(element) {
57
61
  endContainer = range.endContainer.parentElement;
58
62
 
59
63
  let rangeObj = {
64
+ element: contenteditable,
60
65
  startOffset: range.startOffset,
61
66
  endOffset: range.endOffset,
62
67
  startContainer,
@@ -418,7 +423,11 @@ function getElFromString(dom, string, element, position, isAttribute) {
418
423
  }
419
424
 
420
425
  function getPosition(string, subString, index) {
421
- return string.split(subString, index).join(subString).length;
426
+ let angleArray = string.split(subString, index);
427
+ let startstring = angleArray.join(subString);
428
+ let start = startstring.length;
429
+ return start;
430
+ // return string.split(subString, index).join(subString).length;
422
431
  }
423
432
 
424
433
  export default {getSelection, setSelection, hasSelection, processSelection, getStringPosition, getElementPosition};