@cocreate/text 1.16.0 → 1.16.3
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 +3 -1
- package/docs/index.html +1 -1
- package/package.json +9 -9
- package/src/index.js +19 -14
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## [1.16.3](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.2...v1.16.3) (2022-06-16)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* when iframe need to get iframe elements attributes to send to crdt undo and redo ([ddfc15e](https://github.com/CoCreate-app/CoCreate-text/commit/ddfc15e1184ff7adf4bfabb9a7d147a531b645d6))
|
7
|
+
|
8
|
+
## [1.16.2](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.1...v1.16.2) (2022-06-13)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* updateElementText if input ant type = text,tel, url ([7eabd9a](https://github.com/CoCreate-app/CoCreate-text/commit/7eabd9acf331ed5012e49a519a9270dd59c2d3bf))
|
14
|
+
|
15
|
+
## [1.16.1](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.0...v1.16.1) (2022-06-12)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* update dependencies ([91842bc](https://github.com/CoCreate-app/CoCreate-text/commit/91842bcba271485f840064498784250fdf49bfab))
|
21
|
+
* update docs css document_id ([8a48ea0](https://github.com/CoCreate-app/CoCreate-text/commit/8a48ea0745c36f4f8a5954fe76252e98864ebfdf))
|
22
|
+
|
1
23
|
# [1.16.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.17...v1.16.0) (2022-06-11)
|
2
24
|
|
3
25
|
|
package/demo/demos.html
CHANGED
@@ -10,7 +10,9 @@
|
|
10
10
|
|
11
11
|
<body class="padding:20px">
|
12
12
|
<form collection="test" document_id="62a3f5d5e6dfc91d581cdd2d">
|
13
|
-
<input type="
|
13
|
+
<input type="email" name="email">
|
14
|
+
<input type="tel" name="tel">
|
15
|
+
<input type="url" name="url">
|
14
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>-->
|
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.16.
|
3
|
+
"version": "1.16.3",
|
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",
|
@@ -62,13 +62,13 @@
|
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
64
|
"@cocreate/actions": "^1.4.2",
|
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.
|
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
@@ -31,7 +31,7 @@ function initElement (element) {
|
|
31
31
|
if (document_id == "pending") return;
|
32
32
|
if (isCrdt == "false" || isRealtime == "false" || element.type == 'number' || name == '_id') return;
|
33
33
|
if (!crud.checkAttrValue(collection) || !crud.checkAttrValue(document_id)) return;
|
34
|
-
if (element.tagName === "INPUT" && ["text", "
|
34
|
+
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
35
35
|
if (!collection || !document_id || !name) return;
|
36
36
|
|
37
37
|
if (!isCrdt) {
|
@@ -193,12 +193,11 @@ function _keydown (event) {
|
|
193
193
|
event.preventDefault();
|
194
194
|
}
|
195
195
|
else if (event.ctrlKey) {
|
196
|
-
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(element);
|
197
196
|
if (event.keyCode == 90) {
|
198
|
-
|
197
|
+
updateText({element, range, undoRedo: 'undo'});
|
199
198
|
}
|
200
199
|
else if (event.keyCode == 89) {
|
201
|
-
|
200
|
+
updateText({element, range, undoRedo: 'redo'});
|
202
201
|
}
|
203
202
|
}
|
204
203
|
}
|
@@ -258,7 +257,7 @@ export function sendPosition (element) {
|
|
258
257
|
cursors.sendPosition({ collection, document_id, name, start, end });
|
259
258
|
}
|
260
259
|
|
261
|
-
function updateText ({element, value, start, end, range}) {
|
260
|
+
function updateText ({element, value, start, end, range, undoRedo}) {
|
262
261
|
if (range) {
|
263
262
|
if (range.element)
|
264
263
|
element = range.element;
|
@@ -269,6 +268,11 @@ function updateText ({element, value, start, end, range}) {
|
|
269
268
|
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(element);
|
270
269
|
if (isCrdt == "false") return;
|
271
270
|
|
271
|
+
if (undoRedo == 'undo')
|
272
|
+
return crdt.undoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
273
|
+
if (undoRedo == 'redo')
|
274
|
+
return crdt.redoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
275
|
+
|
272
276
|
let length = end - start;
|
273
277
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
274
278
|
crdt.updateText({ collection, document_id, name, value, start, length, crud: isCrud, save: isSave });
|
@@ -341,15 +345,16 @@ async function updateElement ({element, collection, document_id, name, value, st
|
|
341
345
|
}
|
342
346
|
|
343
347
|
function _updateElementText (element, value, start, end) {
|
344
|
-
if (element.tagName
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
348
|
+
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA") {
|
349
|
+
let prev_start = element.selectionStart;
|
350
|
+
let prev_end = element.selectionEnd;
|
351
|
+
let activeElement = element.ownerDocument.activeElement;
|
352
|
+
element.setRangeText(value, start, end, "end");
|
353
|
+
let p = processSelection(element, value, prev_start, prev_end, start, end);
|
354
|
+
if (activeElement == element)
|
355
|
+
sendPosition(element);
|
356
|
+
_dispatchInputEvent(element, p.value, p.start, p.end, p.prev_start, p.prev_end);
|
357
|
+
}
|
353
358
|
}
|
354
359
|
|
355
360
|
export function _dispatchInputEvent(element, content, start, end, prev_start, prev_end) {
|