@livingdocs/editable.js 5.0.6 → 5.0.8
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/dist/editable.js +1 -1
- package/dist/editable.js.map +1 -1
- package/package.json +5 -5
- package/src/clipboard.js +1 -1
- package/src/content.js +15 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livingdocs/editable.js",
|
|
3
3
|
"description": "Friendly contenteditable API",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.8",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@babel/runtime": "^7.16.7",
|
|
7
7
|
"lodash-es": "^4.17.21"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"url-loader": "^4.1.1",
|
|
40
40
|
"webpack": "^5.68.0",
|
|
41
41
|
"webpack-cli": "^5.0.0",
|
|
42
|
-
"webpack-dev-server": "^
|
|
42
|
+
"webpack-dev-server": "^5.0.0"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=16",
|
|
@@ -80,11 +80,11 @@
|
|
|
80
80
|
"isCi": true,
|
|
81
81
|
"name": "Drone",
|
|
82
82
|
"service": "drone",
|
|
83
|
-
"commit": "
|
|
84
|
-
"build": "
|
|
83
|
+
"commit": "6f67ea1ff90ab471e60c30a7000bdcb8c802c0ac",
|
|
84
|
+
"build": "1487",
|
|
85
85
|
"branch": "master",
|
|
86
86
|
"isPr": false,
|
|
87
87
|
"slug": "livingdocsIO/editable.js",
|
|
88
|
-
"date": "2024-
|
|
88
|
+
"date": "2024-03-07T10:06:40.152Z"
|
|
89
89
|
}
|
|
90
90
|
}
|
package/src/clipboard.js
CHANGED
|
@@ -125,7 +125,7 @@ function conditionalNodeWrap (child, content, options) {
|
|
|
125
125
|
// returns string of concatenated attributes e.g. 'target="_blank" rel="nofollow" href="/test.com"'
|
|
126
126
|
function filterAttributes (nodeName, node) {
|
|
127
127
|
return Array.from(node.attributes).reduce((attributes, {name, value}) => {
|
|
128
|
-
if (allowedElements[nodeName][name] && value) {
|
|
128
|
+
if (allowedElements[nodeName]?.[name] && value) {
|
|
129
129
|
return `${attributes} ${name}="${value}"`
|
|
130
130
|
}
|
|
131
131
|
return attributes
|
package/src/content.js
CHANGED
|
@@ -15,6 +15,10 @@ const zeroWidthSpace = /\u200B/g
|
|
|
15
15
|
const zeroWidthNonBreakingSpace = /\uFEFF/g
|
|
16
16
|
const whitespaceExceptSpace = /[^\S ]/g
|
|
17
17
|
|
|
18
|
+
const everythingWhitespace = /^\s+$/
|
|
19
|
+
const leadingWhitespace = /^\s+/
|
|
20
|
+
const trailingWhitespace = /\s+$/
|
|
21
|
+
|
|
18
22
|
// Clean up the Html.
|
|
19
23
|
export function tidyHtml (element) {
|
|
20
24
|
// if (element.normalize) element.normalize()
|
|
@@ -143,25 +147,34 @@ export function cloneRangeContents (range) {
|
|
|
143
147
|
|
|
144
148
|
function removeWhitespaces (node, type, firstCall = true) {
|
|
145
149
|
let elem
|
|
150
|
+
// loop through all children:
|
|
151
|
+
// from left to right if type = 'firstChild',
|
|
152
|
+
// from right to left if type = 'lastChild'
|
|
146
153
|
while ((elem = node[type])) {
|
|
147
154
|
if (elem.nodeType === nodeType.textNode) {
|
|
148
|
-
if
|
|
155
|
+
// Just remove text nodes if they consist only of whitespace
|
|
156
|
+
if (everythingWhitespace.test(elem.textContent)) node.removeChild(elem)
|
|
149
157
|
else break
|
|
150
158
|
} else if (elem.nodeName === 'BR') {
|
|
151
159
|
elem.remove()
|
|
152
160
|
} else {
|
|
161
|
+
// For element nodes (e.g. <strong> tags), we repeat the logic recursively
|
|
162
|
+
// to remove empty text nodes or <br> tags.
|
|
153
163
|
if (elem[type]) removeWhitespaces(elem, type, false)
|
|
154
164
|
break
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
167
|
|
|
168
|
+
// Text nodes with leading/trailing whitespace can be trimmed if config allows.
|
|
169
|
+
// We only do it to the outermost text node. Once a text was wrapped in
|
|
170
|
+
// another element, we preserve the whitespace.
|
|
158
171
|
if (!firstCall) return
|
|
159
172
|
elem = node[type]
|
|
160
173
|
if (elem?.nodeType !== nodeType.textNode) return
|
|
161
174
|
// Remove whitespaces at the end or start of a block with content
|
|
162
175
|
// e.g. ' Hello world' > 'Hello World'
|
|
163
176
|
if (config.trimLeadingAndTrailingWhitespaces) {
|
|
164
|
-
elem.textContent = elem.textContent.replace(type.startsWith('last') ?
|
|
177
|
+
elem.textContent = elem.textContent.replace(type.startsWith('last') ? trailingWhitespace : leadingWhitespace, '')
|
|
165
178
|
}
|
|
166
179
|
}
|
|
167
180
|
|