@cocreate/text 1.14.7 → 1.15.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,31 @@
1
+ ## [1.15.1](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.0...v1.15.1) (2022-01-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * return if name == _id ([5bd2ce1](https://github.com/CoCreate-app/CoCreate-text/commit/5bd2ce1a21c639f870cbab70288963c126a0ac42))
7
+
8
+ # [1.15.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.14.9...v1.15.0) (2022-01-22)
9
+
10
+
11
+ ### Features
12
+
13
+ * removeClass and removeStyle to remove the className or property from CRDT string ([3e91719](https://github.com/CoCreate-app/CoCreate-text/commit/3e917190ef6a61d240d6dec955a76c5dbef651d8))
14
+
15
+ ## [1.14.9](https://github.com/CoCreate-app/CoCreate-text/compare/v1.14.8...v1.14.9) (2022-01-14)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * saveDomText.js updated to awiat value from crdt.getText ([1b7a433](https://github.com/CoCreate-app/CoCreate-text/commit/1b7a433acda72f4cf12ad283b6aa37b4367fbea5))
21
+
22
+ ## [1.14.8](https://github.com/CoCreate-app/CoCreate-text/compare/v1.14.7...v1.14.8) (2022-01-13)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * removed if case that resulted in value not inserting if oldValue and newValue where equal ([187167e](https://github.com/CoCreate-app/CoCreate-text/commit/187167e03fb1cfc5132848f443d32d4f2d3ffe8e))
28
+
1
29
  ## [1.14.7](https://github.com/CoCreate-app/CoCreate-text/compare/v1.14.6...v1.14.7) (2022-01-11)
2
30
 
3
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/text",
3
- "version": "1.14.7",
3
+ "version": "1.15.1",
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",
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;
@@ -308,8 +308,7 @@ async function updateElement ({element, collection, document_id, name, value, st
308
308
  _updateElementText(element, "", start, start + length);
309
309
  }
310
310
  if(value) {
311
- if (element.value != value)
312
- _updateElementText(element, value, start, start);
311
+ _updateElementText(element, value, start, start);
313
312
  }
314
313
  }
315
314
  else {
@@ -5,21 +5,22 @@ import crdt from '@cocreate/crdt';
5
5
 
6
6
  function save(btn){
7
7
  const { collection, document_id, name, namespace, room, isBroadcast, isBroadcastSender, isUpsert} = crud.getAttr(btn);
8
- let data = crdt.getText({collection, document_id, name});
9
- crud.updateDocument({
10
- collection: collection,
11
- document_id: document_id,
12
- data: {
13
- [name]: data
14
- },
15
- upsert: isUpsert,
16
- namespace: namespace,
17
- room: room,
18
- broadcast: isBroadcast,
19
- broadcast_sender: isBroadcastSender
8
+ crdt.getText({collection, document_id, name}).then(response => {
9
+ crud.updateDocument({
10
+ collection: collection,
11
+ document_id: document_id,
12
+ data: {
13
+ [name]: response
14
+ },
15
+ upsert: isUpsert,
16
+ namespace: namespace,
17
+ room: room,
18
+ broadcast: isBroadcast,
19
+ broadcast_sender: isBroadcastSender
20
+ });
21
+
22
+ document.dispatchEvent(new CustomEvent('savedDomText'));
20
23
  });
21
-
22
- document.dispatchEvent(new CustomEvent('savedDomText'));
23
24
  }
24
25
 
25
26
  action.init({
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, classname }) {
35
- updateDomText({ domTextEditor, target, attribute: 'class', value: classname });
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 setClassStyle({ domTextEditor, target, classname, value, unit }) {
39
- updateDomText({ domTextEditor, target, attribute: 'class', value: `${classname}:${value}${unit}` });
41
+ export function setStyle({ domTextEditor, target, property, value }) {
42
+ updateDomText({ domTextEditor, target, attribute: 'style', property, value });
40
43
  }
41
44
 
42
- export function setStyle({ domTextEditor, target, styleName }) {
43
- updateDomText({ domTextEditor, target, attribute: 'style', value: styleName });
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, removeAttribute: 'true'});
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, removeAttribute }) {
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 && removeAttribute != 'true')
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 });