@cocreate/text 1.14.9 → 1.15.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 +28 -0
- package/package.json +10 -10
- package/src/index.js +7 -6
- package/src/updateText.js +13 -10
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
## [1.15.3](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.2...v1.15.3) (2022-02-01)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update dependency versions ([4079711](https://github.com/CoCreate-app/CoCreate-text/commit/407971197a1fc21dbefdc4419ca836afb369bcad))
|
7
|
+
|
8
|
+
## [1.15.2](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.1...v1.15.2) (2022-01-31)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* use string param provided by crdt-update event ([6c05759](https://github.com/CoCreate-app/CoCreate-text/commit/6c05759ac0dd45e5c8123324192d5993ae25b05c))
|
14
|
+
|
15
|
+
## [1.15.1](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.0...v1.15.1) (2022-01-23)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* return if name == _id ([5bd2ce1](https://github.com/CoCreate-app/CoCreate-text/commit/5bd2ce1a21c639f870cbab70288963c126a0ac42))
|
21
|
+
|
22
|
+
# [1.15.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.14.9...v1.15.0) (2022-01-22)
|
23
|
+
|
24
|
+
|
25
|
+
### Features
|
26
|
+
|
27
|
+
* removeClass and removeStyle to remove the className or property from CRDT string ([3e91719](https://github.com/CoCreate-app/CoCreate-text/commit/3e917190ef6a61d240d6dec955a76c5dbef651d8))
|
28
|
+
|
1
29
|
## [1.14.9](https://github.com/CoCreate-app/CoCreate-text/compare/v1.14.8...v1.14.9) (2022-01-14)
|
2
30
|
|
3
31
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/text",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.15.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",
|
@@ -61,14 +61,14 @@
|
|
61
61
|
"webpack-log": "^3.0.1"
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
|
-
"@cocreate/actions": "^1.3.
|
65
|
-
"@cocreate/crdt": "^1.
|
66
|
-
"@cocreate/crud-client": "^1.4.
|
67
|
-
"@cocreate/cursors": "^1.11.
|
68
|
-
"@cocreate/docs": "^1.2.
|
69
|
-
"@cocreate/hosting": "^1.2.
|
70
|
-
"@cocreate/observer": "^1.
|
71
|
-
"@cocreate/selection": "^1.
|
72
|
-
"@cocreate/uuid": "^1.1.
|
64
|
+
"@cocreate/actions": "^1.3.28",
|
65
|
+
"@cocreate/crdt": "^1.9.0",
|
66
|
+
"@cocreate/crud-client": "^1.4.43",
|
67
|
+
"@cocreate/cursors": "^1.11.9",
|
68
|
+
"@cocreate/docs": "^1.2.65",
|
69
|
+
"@cocreate/hosting": "^1.2.60",
|
70
|
+
"@cocreate/observer": "^1.4.0",
|
71
|
+
"@cocreate/selection": "^1.4.0",
|
72
|
+
"@cocreate/uuid": "^1.1.55"
|
73
73
|
}
|
74
74
|
}
|
package/src/index.js
CHANGED
@@ -28,7 +28,7 @@ function initElements (elements) {
|
|
28
28
|
function initElement (element) {
|
29
29
|
const { collection, document_id, name, isRealtime, isCrdt, isCrud, isSave, isRead } = crud.getAttr(element);
|
30
30
|
if(document_id == "pending") return;
|
31
|
-
if(isCrdt == "false" || isRealtime == "false" || element.type == 'number') return;
|
31
|
+
if(isCrdt == "false" || isRealtime == "false" || element.type == 'number' || name == '_id') return;
|
32
32
|
if(!crud.checkAttrValue(collection) || !crud.checkAttrValue(document_id)) return;
|
33
33
|
if(element.tagName === "INPUT" && ["text", "email", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
34
34
|
if(!collection || !document_id || !name) return;
|
@@ -279,7 +279,7 @@ function _crdtUpdateListener () {
|
|
279
279
|
});
|
280
280
|
}
|
281
281
|
|
282
|
-
function updateElements({elements, collection, document_id, name, value, start, length}){
|
282
|
+
function updateElements({elements, collection, document_id, name, value, start, length, string}){
|
283
283
|
if(!elements){
|
284
284
|
let selectors = `[collection='${collection}'][document_id='${document_id}'][name='${name}']`;
|
285
285
|
elements = document.querySelectorAll(`input${selectors}, textarea${selectors}, [contenteditable]${selectors}, [editor='dom']${selectors}`);
|
@@ -292,11 +292,11 @@ function updateElements({elements, collection, document_id, name, value, start,
|
|
292
292
|
// let isEditable = element.getAttribute('contenteditable');
|
293
293
|
if (!element.hasAttribute('contenteditable') && isCrdt == 'false') return;
|
294
294
|
|
295
|
-
updateElement({element, collection, document_id, name, value, start, length});
|
295
|
+
updateElement({element, collection, document_id, name, value, start, length, string});
|
296
296
|
});
|
297
297
|
}
|
298
298
|
|
299
|
-
async function updateElement ({element, collection, document_id, name, value, start, length }) {
|
299
|
+
async function updateElement ({element, collection, document_id, name, value, start, length, string }) {
|
300
300
|
if (element.tagName == 'IFRAME') {
|
301
301
|
element = element.contentDocument.documentElement;
|
302
302
|
if (element.contenteditable != 'false')
|
@@ -313,14 +313,15 @@ async function updateElement ({element, collection, document_id, name, value, st
|
|
313
313
|
}
|
314
314
|
else {
|
315
315
|
let domTextEditor = element;
|
316
|
-
|
316
|
+
if (string == undefined)
|
317
|
+
string = await crdt.getText({collection, document_id, name});
|
318
|
+
let html = string;
|
317
319
|
if (length) {
|
318
320
|
let end = start + length;
|
319
321
|
updateDom({ domTextEditor, start, end, html });
|
320
322
|
}
|
321
323
|
if (value) {
|
322
324
|
if (element.innerHTML != value) {
|
323
|
-
// domTextEditor.htmlString = html;
|
324
325
|
updateDom({ domTextEditor, value, start, end: start, html });
|
325
326
|
}
|
326
327
|
}
|
package/src/updateText.js
CHANGED
@@ -31,16 +31,19 @@ export function setInnerText({ domTextEditor, target, value, start, end }) {
|
|
31
31
|
updateDomText({ domTextEditor, target, value, pos: {start, end} });
|
32
32
|
}
|
33
33
|
|
34
|
-
export function setClass({ domTextEditor, target,
|
35
|
-
updateDomText({ domTextEditor, target, attribute: 'class', value
|
34
|
+
export function setClass({ domTextEditor, target, value }) {
|
35
|
+
updateDomText({ domTextEditor, target, attribute: 'class', value });
|
36
|
+
}
|
37
|
+
export function removeClass({ domTextEditor, target, value }) {
|
38
|
+
updateDomText({ domTextEditor, target, attribute: 'class', value, remove: true });
|
36
39
|
}
|
37
40
|
|
38
|
-
export function
|
39
|
-
updateDomText({ domTextEditor, target, attribute: '
|
41
|
+
export function setStyle({ domTextEditor, target, property, value }) {
|
42
|
+
updateDomText({ domTextEditor, target, attribute: 'style', property, value });
|
40
43
|
}
|
41
44
|
|
42
|
-
export function
|
43
|
-
updateDomText({ domTextEditor, target, attribute: 'style',
|
45
|
+
export function removeStyle({ domTextEditor, target, property }) {
|
46
|
+
updateDomText({ domTextEditor, target, attribute: 'style', property, remove: true });
|
44
47
|
}
|
45
48
|
|
46
49
|
export function setAttribute({ domTextEditor, target, name, value }) {
|
@@ -48,22 +51,22 @@ export function setAttribute({ domTextEditor, target, name, value }) {
|
|
48
51
|
}
|
49
52
|
|
50
53
|
export function removeAttribute({ domTextEditor, target, name }) {
|
51
|
-
updateDomText({ domTextEditor, target, attribute: name,
|
54
|
+
updateDomText({ domTextEditor, target, attribute: name, remove: 'true'});
|
52
55
|
}
|
53
56
|
|
54
57
|
export function replaceInnerText({ domTextEditor, target, value }) {
|
55
58
|
updateDomText({ domTextEditor, target, value });
|
56
59
|
}
|
57
60
|
|
58
|
-
export function updateDomText({ domTextEditor, target, position, element, elementValue, attribute, value, pos,
|
59
|
-
let {start, end, newValue} = getStringPosition({ string: domTextEditor.htmlString, target, attribute, value });
|
61
|
+
export function updateDomText({ domTextEditor, target, position, element, elementValue, attribute, value, property, pos, remove }) {
|
62
|
+
let {start, end, newValue} = getStringPosition({ string: domTextEditor.htmlString, target, attribute, property, value, remove });
|
60
63
|
if (pos){
|
61
64
|
start += pos.start;
|
62
65
|
end += pos.end;
|
63
66
|
}
|
64
67
|
if(start != end)
|
65
68
|
_updateText({domTextEditor, start, end});
|
66
|
-
if(attribute &&
|
69
|
+
if(attribute && remove != 'true' || attribute && value)
|
67
70
|
_updateText({ domTextEditor, value: ` ${attribute}="${newValue}"`, start });
|
68
71
|
else if(value)
|
69
72
|
_updateText({ domTextEditor, value, start });
|