@cocreate/text 1.27.1 → 1.28.0
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 +17 -0
- package/package.json +1 -1
- package/prettier.config.js +16 -0
- package/src/index.js +5 -3
- package/src/updateDom.js +10 -22
- package/src/updateText.js +5 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# [1.28.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.27.1...v1.28.0) (2024-11-04)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* formating ([df994e2](https://github.com/CoCreate-app/CoCreate-text/commit/df994e2495420d626f1429a8a00f0cd8287d1cbd))
|
7
|
+
* if condition remove ([ac7bf6a](https://github.com/CoCreate-app/CoCreate-text/commit/ac7bf6a3cca3c2e876900f5d86d372880295dc73))
|
8
|
+
* if no selection return ([a271cb3](https://github.com/CoCreate-app/CoCreate-text/commit/a271cb3c73e74d0b104939a2d6a662dd11da59f8))
|
9
|
+
* observer taget has been renamed to selector ([da1e9e9](https://github.com/CoCreate-app/CoCreate-text/commit/da1e9e9eeaddcbafcfb589278ff8fadd10e4dd52))
|
10
|
+
* pretier.config.js and file formating ([0ae4aed](https://github.com/CoCreate-app/CoCreate-text/commit/0ae4aed54f9358cd39b4de513684d9949f7e8844))
|
11
|
+
* send position on mousedown and arrow keys ([1e63d00](https://github.com/CoCreate-app/CoCreate-text/commit/1e63d00fedef6de42594c592a6171b5c061ebd06))
|
12
|
+
|
13
|
+
|
14
|
+
### Features
|
15
|
+
|
16
|
+
* add prettier.config.js and format files ([9a8b71d](https://github.com/CoCreate-app/CoCreate-text/commit/9a8b71d52a4fa98a95f723238fbe7cd32e254adc))
|
17
|
+
|
1
18
|
## [1.27.1](https://github.com/CoCreate-app/CoCreate-text/compare/v1.27.0...v1.27.1) (2024-06-19)
|
2
19
|
|
3
20
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -173,7 +173,7 @@ function _mousedown(event) {
|
|
173
173
|
if (array && object && key && !target.hasAttribute('contenteditable'))
|
174
174
|
target.setAttribute('contenteditable', 'true');
|
175
175
|
}
|
176
|
-
|
176
|
+
sendPosition(domTextEditor)
|
177
177
|
}
|
178
178
|
|
179
179
|
function _blur(event) {
|
@@ -245,6 +245,8 @@ function _keydown(event) {
|
|
245
245
|
} else if (event.keyCode == 89) {
|
246
246
|
updateText({ element, range, undoRedo: 'redo' });
|
247
247
|
}
|
248
|
+
} else {
|
249
|
+
sendPosition(element)
|
248
250
|
}
|
249
251
|
}
|
250
252
|
|
@@ -430,7 +432,7 @@ export function _dispatchInputEvent(element, content, start, end, prev_start, pr
|
|
430
432
|
observer.init({
|
431
433
|
name: 'CoCreateTextAddedNodes',
|
432
434
|
observe: ['addedNodes'],
|
433
|
-
|
435
|
+
selector: selectors,
|
434
436
|
callback(mutation) {
|
435
437
|
let isCrdt = mutation.target.getAttribute('crdt');
|
436
438
|
if (isCrdt) return;
|
@@ -442,7 +444,7 @@ observer.init({
|
|
442
444
|
name: 'CoCreateTextAttribtes',
|
443
445
|
observe: ['attributes'],
|
444
446
|
attributeName: [...getAttributeNames(['array', 'object', 'key']), 'contenteditable'],
|
445
|
-
|
447
|
+
selector: selectors,
|
446
448
|
callback(mutation) {
|
447
449
|
let _id = mutation.target.getAttribute('object')
|
448
450
|
if (!_id) {
|
package/src/updateDom.js
CHANGED
@@ -40,13 +40,11 @@ export function updateDom({ domTextEditor, value, start, end, html }) {
|
|
40
40
|
newEl.innerHTML = domTextEditor.htmlString;
|
41
41
|
domEl = domTextEditor;
|
42
42
|
type = 'innerHTML';
|
43
|
-
}
|
44
|
-
else if (element.tagName == 'HTML') {
|
43
|
+
} else if (element.tagName == 'HTML') {
|
45
44
|
// console.log('element = html')
|
46
45
|
domEl = domTextEditor;
|
47
46
|
type = 'innerHTML';
|
48
|
-
}
|
49
|
-
else if (path) {
|
47
|
+
} else if (path) {
|
50
48
|
// console.log("else path", path)
|
51
49
|
domEl = domTextEditor.querySelector(path);
|
52
50
|
// if (!domEl || !oldEl){
|
@@ -103,44 +101,34 @@ export function updateDom({ domTextEditor, value, start, end, html }) {
|
|
103
101
|
// console.log('newEl', newEl)
|
104
102
|
if (start != end && type == 'innerHTML') {
|
105
103
|
domTextEditor.htmlString = html;
|
106
|
-
if (domEl.tagName != 'HTML') {
|
107
|
-
|
108
|
-
|
109
|
-
// console.log('parent', domEl.parentElement)
|
110
|
-
} else {
|
111
|
-
domEl.replaceChildren(...newEl.childNodes);
|
112
|
-
// console.log('domEl', domEl)
|
113
|
-
}
|
114
|
-
}
|
115
|
-
else {
|
104
|
+
if (domEl.tagName != 'HTML' && newEl.parentElement) {
|
105
|
+
domEl.parentElement.replaceChildren(...newEl.parentElement.childNodes);
|
106
|
+
} else {
|
116
107
|
domEl.replaceChildren(...newEl.childNodes);
|
117
108
|
// console.log('Html tag', domEl)
|
118
109
|
}
|
110
|
+
|
119
111
|
if (curCaret && curCaret.range) {
|
120
112
|
curCaret.range.startContainer = domEl;
|
121
113
|
curCaret.range.endContainer = domEl;
|
122
114
|
}
|
123
|
-
}
|
124
|
-
else if (type == 'isStartTag') {
|
115
|
+
} else if (type == 'isStartTag') {
|
125
116
|
oldEl = domTextEditor.oldHtml.querySelector(path);
|
126
117
|
if (!oldEl && domEl.tagName == 'HTML')
|
127
118
|
oldEl = domTextEditor.oldHtml
|
128
119
|
assignAttributes(newEl, oldEl, domEl);
|
129
120
|
// console.log('isStartTag', domEl, newEl)
|
130
121
|
|
131
|
-
}
|
132
|
-
else if (type == 'insertAdjacent') {
|
122
|
+
} else if (type == 'insertAdjacent') {
|
133
123
|
domEl.insertAdjacentHTML(position, value);
|
134
124
|
// console.log('insertAdjacent', domEl, value)
|
135
|
-
}
|
136
|
-
else if (type == 'textNode') {
|
125
|
+
} else if (type == 'textNode') {
|
137
126
|
if (start != end)
|
138
127
|
domTextEditor.htmlString = html;
|
139
128
|
domEl.innerHTML = newEl.innerHTML;
|
140
129
|
// console.log('textnode', domEl.innerHTML, newEl.innerHTML)
|
141
130
|
|
142
|
-
}
|
143
|
-
else if (type == 'innerHTML') {
|
131
|
+
} else if (type == 'innerHTML') {
|
144
132
|
domEl.replaceChildren(...newEl.childNodes);
|
145
133
|
// console.log('innerHtml', domEl, newEl)
|
146
134
|
}
|
package/src/updateText.js
CHANGED
@@ -6,8 +6,9 @@ export function insertAdjacentElement({ domTextEditor, target, position, element
|
|
6
6
|
let remove;
|
7
7
|
if (element && !elementValue) {
|
8
8
|
remove = getStringPosition({ string: domTextEditor.htmlString, target: element });
|
9
|
-
if (!remove.start && !remove.end)
|
9
|
+
if (!remove || !remove.start && !remove.end)
|
10
10
|
throw new Error('insertAdjacentElement: element not found');
|
11
|
+
|
11
12
|
elementValue = domTextEditor.htmlString.substring(remove.start, remove.end);
|
12
13
|
}
|
13
14
|
|
@@ -58,7 +59,9 @@ export function replaceInnerText({ domTextEditor, target, value }) {
|
|
58
59
|
}
|
59
60
|
|
60
61
|
export function updateDomText({ domTextEditor, target, position, element, elementValue, attribute, value, property, pos, remove }) {
|
61
|
-
let
|
62
|
+
let selection = getStringPosition({ string: domTextEditor.htmlString, target, attribute, property, value, remove });
|
63
|
+
if (!selection) return
|
64
|
+
let { start, end, newValue } = selection;
|
62
65
|
if (pos) {
|
63
66
|
start += pos.start;
|
64
67
|
end += pos.end;
|