@cocreate/text 1.15.17 → 1.16.2
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 +22 -0
- package/demo/demos.html +5 -3
- package/docs/index.html +1 -1
- package/package.json +10 -10
- package/src/index.js +37 -24
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## [1.16.2](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.1...v1.16.2) (2022-06-13)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* updateElementText if input ant type = text,tel, url ([7eabd9a](https://github.com/CoCreate-app/CoCreate-text/commit/7eabd9acf331ed5012e49a519a9270dd59c2d3bf))
|
7
|
+
|
8
|
+
## [1.16.1](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.0...v1.16.1) (2022-06-12)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* update dependencies ([91842bc](https://github.com/CoCreate-app/CoCreate-text/commit/91842bcba271485f840064498784250fdf49bfab))
|
14
|
+
* update docs css document_id ([8a48ea0](https://github.com/CoCreate-app/CoCreate-text/commit/8a48ea0745c36f4f8a5954fe76252e98864ebfdf))
|
15
|
+
|
16
|
+
# [1.16.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.17...v1.16.0) (2022-06-11)
|
17
|
+
|
18
|
+
|
19
|
+
### Features
|
20
|
+
|
21
|
+
* undo and redo text ([fb9292e](https://github.com/CoCreate-app/CoCreate-text/commit/fb9292e74dde4b02e5dc977b1afecebb7bc33e73))
|
22
|
+
|
1
23
|
## [1.15.17](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.16...v1.15.17) (2022-05-23)
|
2
24
|
|
3
25
|
|
package/demo/demos.html
CHANGED
@@ -9,9 +9,11 @@
|
|
9
9
|
</head>
|
10
10
|
|
11
11
|
<body class="padding:20px">
|
12
|
-
<form collection="test" document_id="
|
13
|
-
<input type="
|
14
|
-
<
|
12
|
+
<form collection="test" document_id="62a3f5d5e6dfc91d581cdd2d">
|
13
|
+
<input type="email" name="email">
|
14
|
+
<input type="tel" name="tel">
|
15
|
+
<input type="url" name="url">
|
16
|
+
<h1 name='name' collection="test"></h1>
|
15
17
|
<!-- <textarea name="name2"></textarea> -->
|
16
18
|
<!--<h1 name='name' contenteditable>I will be replaced by crdt</h1>-->
|
17
19
|
<!-- <div name='name2' contenteditable>I will be replaced by crud</div> -->
|
package/docs/index.html
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
<meta name="keywords" content="helper classes, utility classes, css framework, css library, inline style classes" />
|
11
11
|
<meta name="robots" content="index,follow" />
|
12
12
|
<meta property="og:image" content="https://cdn.cocreate.app/docs/boilerplate.png">
|
13
|
-
<link rel="stylesheet" href="/docs/index.css" collection="files" document_id="
|
13
|
+
<link rel="stylesheet" href="/docs/index.css" collection="files" document_id="60888216117c640e7596303f" name="src" type="text/css" save="true"/>
|
14
14
|
</head>
|
15
15
|
|
16
16
|
<body>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/text",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.16.2",
|
4
4
|
"description": "A simple text component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
5
5
|
"keywords": [
|
6
6
|
"text",
|
@@ -61,14 +61,14 @@
|
|
61
61
|
"webpack-log": "^3.0.1"
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
|
-
"@cocreate/actions": "^1.4.
|
65
|
-
"@cocreate/crdt": "^1.
|
66
|
-
"@cocreate/crud-client": "^1.
|
67
|
-
"@cocreate/cursors": "^1.11.
|
68
|
-
"@cocreate/docs": "^1.3.
|
69
|
-
"@cocreate/hosting": "^1.3.
|
70
|
-
"@cocreate/observer": "^1.5.
|
71
|
-
"@cocreate/selection": "^1.4.
|
72
|
-
"@cocreate/uuid": "^1.2.
|
64
|
+
"@cocreate/actions": "^1.4.2",
|
65
|
+
"@cocreate/crdt": "^1.11.0",
|
66
|
+
"@cocreate/crud-client": "^1.7.0",
|
67
|
+
"@cocreate/cursors": "^1.11.20",
|
68
|
+
"@cocreate/docs": "^1.3.2",
|
69
|
+
"@cocreate/hosting": "^1.3.2",
|
70
|
+
"@cocreate/observer": "^1.5.2",
|
71
|
+
"@cocreate/selection": "^1.4.10",
|
72
|
+
"@cocreate/uuid": "^1.2.2"
|
73
73
|
}
|
74
74
|
}
|
package/src/index.js
CHANGED
@@ -7,6 +7,7 @@ import uuid from '@cocreate/uuid';
|
|
7
7
|
import {updateDom} from './updateDom';
|
8
8
|
import {insertAdjacentElement, removeElement, setInnerText, setAttribute, removeAttribute, setClass, setStyle, setClassStyle, replaceInnerText} from './updateText';
|
9
9
|
import {getSelection, processSelection} from '@cocreate/selection';
|
10
|
+
import action from '@cocreate/actions';
|
10
11
|
import './saveDomText';
|
11
12
|
|
12
13
|
let eventObj;
|
@@ -30,7 +31,7 @@ function initElement (element) {
|
|
30
31
|
if (document_id == "pending") return;
|
31
32
|
if (isCrdt == "false" || isRealtime == "false" || element.type == 'number' || name == '_id') return;
|
32
33
|
if (!crud.checkAttrValue(collection) || !crud.checkAttrValue(document_id)) return;
|
33
|
-
if (element.tagName === "INPUT" && ["text", "
|
34
|
+
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
34
35
|
if (!collection || !document_id || !name) return;
|
35
36
|
|
36
37
|
if (!isCrdt) {
|
@@ -85,16 +86,9 @@ function initDocument(doc) {
|
|
85
86
|
let element = doc.activeElement;
|
86
87
|
sendPosition(element);
|
87
88
|
});
|
88
|
-
// doc.removeEventListener('selectionchange', _selectionchange);
|
89
|
-
// doc.addEventListener('selectionchange', _selectionchange)
|
90
89
|
}
|
91
90
|
}
|
92
91
|
|
93
|
-
// function _selectionchange(event){
|
94
|
-
// let element = event.currentTarget.activeElement;
|
95
|
-
// sendPosition(element);
|
96
|
-
// }
|
97
|
-
|
98
92
|
export function _addEventListeners (element) {
|
99
93
|
element.addEventListener('mousedown', _mousedown);
|
100
94
|
element.addEventListener('blur', _blur);
|
@@ -199,10 +193,13 @@ function _keydown (event) {
|
|
199
193
|
event.preventDefault();
|
200
194
|
}
|
201
195
|
else if (event.ctrlKey) {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
196
|
+
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(element);
|
197
|
+
if (event.keyCode == 90) {
|
198
|
+
crdt.undoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
199
|
+
}
|
200
|
+
else if (event.keyCode == 89) {
|
201
|
+
crdt.redoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
202
|
+
}
|
206
203
|
}
|
207
204
|
}
|
208
205
|
|
@@ -301,9 +298,6 @@ function updateElements({elements, collection, document_id, name, value, start,
|
|
301
298
|
|
302
299
|
elements.forEach((element) => {
|
303
300
|
let isCrdt = element.getAttribute('crdt');
|
304
|
-
// if (isCrdt == 'false' && !element.hasAttribute('crdt') && !element.contentEditable) return;
|
305
|
-
// if (element.hasAttribute('contenteditable')){
|
306
|
-
// let isEditable = element.getAttribute('contenteditable');
|
307
301
|
if (!element.hasAttribute('contenteditable') && isCrdt == 'false') return;
|
308
302
|
|
309
303
|
updateElement({element, collection, document_id, name, value, start, length, string});
|
@@ -347,15 +341,16 @@ async function updateElement ({element, collection, document_id, name, value, st
|
|
347
341
|
}
|
348
342
|
|
349
343
|
function _updateElementText (element, value, start, end) {
|
350
|
-
if (element.tagName
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
344
|
+
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA") {
|
345
|
+
let prev_start = element.selectionStart;
|
346
|
+
let prev_end = element.selectionEnd;
|
347
|
+
let activeElement = element.ownerDocument.activeElement;
|
348
|
+
element.setRangeText(value, start, end, "end");
|
349
|
+
let p = processSelection(element, value, prev_start, prev_end, start, end);
|
350
|
+
if (activeElement == element)
|
351
|
+
sendPosition(element);
|
352
|
+
_dispatchInputEvent(element, p.value, p.start, p.end, p.prev_start, p.prev_end);
|
353
|
+
}
|
359
354
|
}
|
360
355
|
|
361
356
|
export function _dispatchInputEvent(element, content, start, end, prev_start, prev_end) {
|
@@ -395,6 +390,24 @@ observer.init({
|
|
395
390
|
}
|
396
391
|
});
|
397
392
|
|
393
|
+
action.init({
|
394
|
+
name: "undo",
|
395
|
+
endEvent: "undo",
|
396
|
+
callback: (btn, data) => {
|
397
|
+
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(btn);
|
398
|
+
crdt.undoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
399
|
+
}
|
400
|
+
});
|
401
|
+
|
402
|
+
action.init({
|
403
|
+
name: "redo",
|
404
|
+
endEvent: "redo",
|
405
|
+
callback: (btn, data) => {
|
406
|
+
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(btn);
|
407
|
+
crdt.redoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
408
|
+
}
|
409
|
+
});
|
410
|
+
|
398
411
|
init();
|
399
412
|
|
400
413
|
export default {initElements, initElement, updateText, updateElement, _addEventListeners, insertAdjacentElement, removeElement, setInnerText, setAttribute, removeAttribute, setClass, setStyle, setClassStyle, replaceInnerText};
|