jodit 3.8.5 → 3.9.2
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/.github/workflows/tests.yml +23 -0
- package/.idea/dictionaries/v_chupurnov.xml +1 -0
- package/.idea/workspace.xml +333 -1469
- package/CHANGELOG.MD +151 -25
- package/README.md +3 -3
- package/build/jodit.css +280 -258
- package/build/jodit.es2018.css +231 -213
- package/build/jodit.es2018.en.css +231 -213
- package/build/jodit.es2018.en.js +9981 -9818
- package/build/jodit.es2018.en.min.css +1 -1
- package/build/jodit.es2018.en.min.js +1 -10
- package/build/jodit.es2018.js +14124 -13961
- package/build/jodit.es2018.min.css +1 -1
- package/build/jodit.es2018.min.js +1 -10
- package/build/jodit.js +11285 -11049
- package/build/jodit.min.css +2 -2
- package/build/jodit.min.js +1 -10
- package/package.json +34 -33
- package/src/config.ts +8 -14
- package/src/core/async.ts +7 -18
- package/src/core/component/view-component.ts +0 -1
- package/src/core/constants.ts +7 -5
- package/src/core/create.ts +8 -27
- package/src/core/decorators/debounce.ts +0 -8
- package/src/core/decorators/hook.ts +0 -1
- package/src/core/decorators/nonenumerable.ts +1 -2
- package/src/core/decorators/persistent.ts +0 -3
- package/src/core/decorators/spy.ts +0 -1
- package/src/core/decorators/wait.ts +0 -1
- package/src/core/dom.ts +161 -205
- package/src/core/events/{events-native.ts → event-emitter.ts} +66 -35
- package/src/core/events/index.ts +1 -1
- package/src/core/events/observe-object.ts +0 -2
- package/src/core/global.ts +12 -8
- package/src/core/helpers/append-script.ts +0 -8
- package/src/core/helpers/array/as-array.ts +2 -5
- package/src/core/helpers/array/split-array.ts +0 -1
- package/src/core/helpers/array/to-array.ts +1 -0
- package/src/core/helpers/async/set-timeout.ts +0 -7
- package/src/core/helpers/browser.ts +0 -1
- package/src/core/helpers/checker/has-browser-color-picker.ts +0 -3
- package/src/core/helpers/checker/is-array.ts +0 -1
- package/src/core/helpers/checker/is-equal.ts +0 -3
- package/src/core/helpers/checker/is-function.ts +0 -2
- package/src/core/helpers/checker/is-html-from-word.ts +0 -3
- package/src/core/helpers/checker/is-html.ts +0 -1
- package/src/core/helpers/checker/is-number.ts +0 -1
- package/src/core/helpers/checker/is-numeric.ts +0 -2
- package/src/core/helpers/checker/is-plain-object.ts +0 -1
- package/src/core/helpers/checker/is-string.ts +0 -1
- package/src/core/helpers/checker/is-url.ts +0 -4
- package/src/core/helpers/color/color-to-hex.ts +2 -2
- package/src/core/helpers/config-proto.ts +0 -3
- package/src/core/helpers/convert-media-url-to-video-embed.ts +1 -6
- package/src/core/helpers/ctrl-key.ts +1 -3
- package/src/core/helpers/data-bind.ts +2 -8
- package/src/core/helpers/default-language.ts +0 -3
- package/src/core/helpers/each.ts +12 -0
- package/src/core/helpers/html/htmlspecialchars.ts +0 -4
- package/src/core/helpers/html/nl2br.ts +0 -1
- package/src/core/helpers/human-size-to-bytes.ts +1 -4
- package/src/core/helpers/normalize/normalize-color.ts +2 -3
- package/src/core/helpers/normalize/normalize-key-aliases.ts +0 -2
- package/src/core/helpers/normalize/normalize-path.ts +0 -2
- package/src/core/helpers/normalize/normalize-size.ts +0 -3
- package/src/core/helpers/selector.ts +0 -8
- package/src/core/helpers/size/get-content-width.ts +0 -2
- package/src/core/helpers/size/offset.ts +1 -7
- package/src/core/helpers/size/position.ts +0 -4
- package/src/core/helpers/string/camel-case.ts +1 -2
- package/src/core/helpers/string/i18n.ts +0 -7
- package/src/core/helpers/string/kebab-case.ts +7 -5
- package/src/core/helpers/string/stringify.ts +0 -3
- package/src/core/helpers/string/trim.ts +0 -2
- package/src/core/helpers/string/ucfirst.ts +2 -5
- package/src/core/helpers/type.ts +0 -1
- package/src/core/helpers/utils/get.ts +0 -2
- package/src/core/helpers/utils/mark-deprecated.ts +0 -4
- package/src/core/helpers/utils/set.ts +0 -2
- package/src/core/helpers/utils/utils.ts +52 -15
- package/src/core/plugin-system.ts +0 -31
- package/src/core/request/ajax.ts +212 -0
- package/src/core/request/config.ts +37 -0
- package/{types/types/core.js → src/core/request/index.ts} +3 -3
- package/src/core/request/response.ts +39 -0
- package/src/core/selection/select.ts +74 -40
- package/src/core/selection/style/api/element-has-same-style.ts +13 -0
- package/src/core/selection/style/api/get-suit-parent.ts +1 -1
- package/src/core/selection/style/api/is-normal-node.ts +1 -2
- package/src/core/selection/style/api/is-suit-element.ts +24 -4
- package/src/core/selection/style/api/toggle-styles.ts +0 -2
- package/src/core/selection/style/api/unwrap-children.ts +45 -16
- package/src/core/selection/style/api/wrap-unwrapped-text.ts +28 -23
- package/src/core/selection/style/apply-style.ts +19 -9
- package/src/core/traits/elms.ts +1 -0
- package/src/core/traits/mods.ts +1 -3
- package/src/core/ui/button/button/button.less +7 -3
- package/src/core/ui/button/button/button.ts +1 -1
- package/src/core/ui/button/group/group.less +5 -5
- package/src/core/ui/element.ts +0 -4
- package/src/core/ui/form/inputs/file/file.less +4 -4
- package/src/core/ui/form/validators/input.ts +0 -2
- package/src/core/ui/form/validators/select.ts +0 -1
- package/src/core/ui/helpers/get-control-type.ts +3 -3
- package/src/core/ui/icon.ts +0 -10
- package/src/core/ui/list/group.less +1 -1
- package/src/core/ui/list/group.ts +1 -6
- package/src/core/ui/list/list.ts +0 -3
- package/src/core/ui/popup/popup.ts +0 -11
- package/src/core/ui/progress-bar/progress-bar.less +8 -8
- package/src/core/view/view-with-toolbar.ts +0 -5
- package/src/core/view/view.ts +5 -21
- package/src/jodit.ts +14 -70
- package/src/modules/context-menu/context-menu.ts +4 -7
- package/src/modules/dialog/alert.ts +0 -6
- package/src/modules/dialog/confirm.ts +1 -1
- package/src/modules/dialog/dialog.ts +22 -47
- package/src/modules/file-browser/README.MD +1 -1
- package/src/modules/file-browser/data-provider.ts +22 -42
- package/src/modules/file-browser/file-browser.ts +3 -0
- package/src/modules/image-editor/image-editor.less +51 -46
- package/src/modules/index.ts +1 -1
- package/src/modules/status-bar/status-bar.less +12 -12
- package/src/modules/table.ts +122 -106
- package/src/modules/toolbar/button/button.less +5 -6
- package/src/modules/toolbar/button/button.ts +1 -1
- package/src/modules/toolbar/button/content.less +2 -2
- package/src/modules/uploader/uploader.ts +4 -3
- package/src/modules/widget/color-picker/color-picker.less +7 -6
- package/src/modules/widget/tabs/tabs.less +3 -3
- package/src/plugins/about/about.less +1 -1
- package/src/plugins/add-new-line/add-new-line.less +14 -15
- package/src/plugins/add-new-line/add-new-line.ts +1 -1
- package/src/plugins/clipboard/paste-storage/paste-storage.less +10 -11
- package/src/plugins/fix/clean-html.ts +39 -18
- package/src/plugins/fix/wrap-text-nodes.ts +1 -2
- package/src/plugins/fullsize/fullsize.less +5 -5
- package/src/plugins/image/image-properties/image-properties.less +11 -7
- package/src/plugins/image/image-properties/image-properties.ts +11 -8
- package/src/plugins/indent.ts +25 -18
- package/src/plugins/placeholder/placeholder.less +4 -4
- package/src/plugins/resizer/resizer.less +28 -23
- package/src/plugins/search/search.less +25 -25
- package/src/plugins/size/resize-handler.ts +1 -1
- package/src/plugins/size/size.ts +1 -3
- package/src/plugins/source/source.less +15 -15
- package/src/plugins/source/source.ts +1 -1
- package/src/plugins/table/select-cells.ts +23 -5
- package/src/plugins/xpath/xpath.less +3 -3
- package/src/styles/form.less +19 -14
- package/src/styles/modules/button-group.less +2 -2
- package/src/styles/modules/icon.less +9 -8
- package/src/types/ajax.d.ts +43 -6
- package/src/types/async.d.ts +5 -4
- package/src/types/events.d.ts +25 -10
- package/src/types/view.d.ts +2 -2
- package/tsconfig.json +1 -1
- package/types/config.d.ts +8 -14
- package/types/core/async.d.ts +3 -16
- package/types/core/component/view-component.d.ts +0 -1
- package/types/core/constants.d.ts +6 -5
- package/types/core/create.d.ts +0 -4
- package/types/core/decorators/debounce.d.ts +0 -8
- package/types/core/decorators/hook.d.ts +0 -1
- package/types/core/decorators/nonenumerable.d.ts +1 -2
- package/types/core/decorators/persistent.d.ts +0 -3
- package/types/core/decorators/wait.d.ts +0 -1
- package/types/core/dom.d.ts +47 -128
- package/types/core/events/{events-native.d.ts → event-emitter.d.ts} +26 -20
- package/types/core/events/index.d.ts +1 -1
- package/types/core/events/observe-object.d.ts +0 -2
- package/types/core/global.d.ts +2 -6
- package/types/core/helpers/append-script.d.ts +0 -8
- package/types/core/helpers/array/as-array.d.ts +3 -0
- package/types/core/helpers/array/split-array.d.ts +0 -1
- package/types/core/helpers/async/set-timeout.d.ts +0 -7
- package/types/core/helpers/browser.d.ts +0 -1
- package/types/core/helpers/checker/has-browser-color-picker.d.ts +0 -3
- package/types/core/helpers/checker/is-array.d.ts +0 -1
- package/types/core/helpers/checker/is-equal.d.ts +0 -3
- package/types/core/helpers/checker/is-function.d.ts +0 -2
- package/types/core/helpers/checker/is-html-from-word.d.ts +0 -3
- package/types/core/helpers/checker/is-html.d.ts +0 -1
- package/types/core/helpers/checker/is-number.d.ts +0 -1
- package/types/core/helpers/checker/is-numeric.d.ts +0 -2
- package/types/core/helpers/checker/is-plain-object.d.ts +0 -1
- package/types/core/helpers/checker/is-string.d.ts +0 -1
- package/types/core/helpers/checker/is-url.d.ts +0 -4
- package/types/core/helpers/color/color-to-hex.d.ts +2 -2
- package/types/core/helpers/config-proto.d.ts +0 -3
- package/types/core/helpers/convert-media-url-to-video-embed.d.ts +1 -6
- package/types/core/helpers/ctrl-key.d.ts +1 -3
- package/types/core/helpers/data-bind.d.ts +0 -6
- package/types/core/helpers/default-language.d.ts +0 -3
- package/types/core/helpers/each.d.ts +9 -0
- package/types/core/helpers/html/htmlspecialchars.d.ts +0 -4
- package/types/core/helpers/html/nl2br.d.ts +0 -1
- package/types/core/helpers/human-size-to-bytes.d.ts +1 -4
- package/types/core/helpers/normalize/normalize-color.d.ts +2 -3
- package/types/core/helpers/normalize/normalize-key-aliases.d.ts +0 -2
- package/types/core/helpers/normalize/normalize-path.d.ts +0 -2
- package/types/core/helpers/normalize/normalize-size.d.ts +0 -3
- package/types/core/helpers/selector.d.ts +0 -8
- package/types/core/helpers/size/get-content-width.d.ts +0 -2
- package/types/core/helpers/size/offset.d.ts +1 -7
- package/types/core/helpers/string/camel-case.d.ts +1 -2
- package/types/core/helpers/string/i18n.d.ts +0 -7
- package/types/core/helpers/string/kebab-case.d.ts +1 -5
- package/types/core/helpers/string/stringify.d.ts +0 -3
- package/types/core/helpers/string/trim.d.ts +0 -2
- package/types/core/helpers/string/ucfirst.d.ts +1 -4
- package/types/core/helpers/type.d.ts +0 -1
- package/types/core/helpers/utils/get.d.ts +0 -2
- package/types/core/helpers/utils/mark-deprecated.d.ts +0 -4
- package/types/core/helpers/utils/set.d.ts +0 -2
- package/types/core/helpers/utils/utils.d.ts +15 -18
- package/types/core/plugin-system.d.ts +0 -31
- package/types/core/request/ajax.d.ts +26 -0
- package/types/core/request/config.d.ts +14 -0
- package/{src/types/core.js → types/core/request/index.d.ts} +2 -3
- package/types/core/request/response.d.ts +16 -0
- package/types/core/selection/select.d.ts +8 -9
- package/types/core/selection/style/api/element-has-same-style.d.ts +4 -0
- package/types/core/selection/style/api/is-suit-element.d.ts +1 -0
- package/types/core/selection/style/api/toggle-styles.d.ts +0 -2
- package/types/core/selection/style/api/wrap-unwrapped-text.d.ts +2 -2
- package/types/core/traits/mods.d.ts +1 -3
- package/types/core/ui/element.d.ts +0 -4
- package/types/core/ui/form/validators/input.d.ts +0 -2
- package/types/core/ui/form/validators/select.d.ts +0 -1
- package/types/core/ui/helpers/get-control-type.d.ts +0 -2
- package/types/core/ui/icon.d.ts +0 -10
- package/types/core/ui/list/group.d.ts +1 -6
- package/types/core/ui/list/list.d.ts +0 -3
- package/types/core/ui/popup/popup.d.ts +0 -11
- package/types/core/view/view-with-toolbar.d.ts +0 -5
- package/types/core/view/view.d.ts +4 -20
- package/types/jodit.d.ts +2 -46
- package/types/modules/context-menu/context-menu.d.ts +3 -6
- package/types/modules/dialog/alert.d.ts +0 -6
- package/types/modules/dialog/confirm.d.ts +1 -1
- package/types/modules/dialog/dialog.d.ts +9 -28
- package/types/modules/file-browser/data-provider.d.ts +1 -1
- package/types/modules/index.d.ts +1 -1
- package/types/modules/table.d.ts +1 -1
- package/types/plugins/fix/clean-html.d.ts +4 -0
- package/types/plugins/size/resize-handler.d.ts +1 -1
- package/types/plugins/source/source.d.ts +1 -1
- package/types/types/ajax.d.ts +43 -6
- package/types/types/async.d.ts +5 -4
- package/types/types/events.d.ts +25 -10
- package/types/types/view.d.ts +2 -2
- package/.editorconfig +0 -15
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -109
- package/.prettierrc.json +0 -9
- package/.stylelintrc.json +0 -16
- package/app.css +0 -112
- package/composer.json +0 -12
- package/src/core/ajax.ts +0 -296
- package/src/types/core.d.ts +0 -7
- package/src/types/core.js.map +0 -1
- package/src/types/storage.d.ts +0 -13
- package/src/types/storage.js +0 -8
- package/src/types/storage.js.map +0 -1
- package/src/utils/create-entries.js +0 -57
- package/src/utils/css-variables-prefixes.js +0 -12
- package/src/utils/lang-loader.js +0 -57
- package/src/utils/lang-translater.js +0 -142
- package/src/utils/plugin-loader.js +0 -14
- package/src/utils/post-build.js +0 -28
- package/src/utils/svg-loader.js +0 -20
- package/types/core/ajax.d.ts +0 -59
- package/types/types/core.js.map +0 -1
- package/types/types/storage.js +0 -8
- package/types/types/storage.js.map +0 -1
package/src/core/dom.ts
CHANGED
|
@@ -10,11 +10,14 @@ import type {
|
|
|
10
10
|
ICreate,
|
|
11
11
|
IJodit,
|
|
12
12
|
NodeCondition,
|
|
13
|
-
Nullable
|
|
13
|
+
Nullable,
|
|
14
|
+
IDictionary
|
|
14
15
|
} from '../types';
|
|
15
16
|
import * as consts from './constants';
|
|
16
17
|
import {
|
|
18
|
+
$$,
|
|
17
19
|
asArray,
|
|
20
|
+
attr,
|
|
18
21
|
css,
|
|
19
22
|
dataBind,
|
|
20
23
|
error,
|
|
@@ -26,6 +29,8 @@ import {
|
|
|
26
29
|
toArray,
|
|
27
30
|
trim
|
|
28
31
|
} from './helpers';
|
|
32
|
+
import { Select } from './selection';
|
|
33
|
+
import { TEMP_ATTR } from './constants';
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Module for working with DOM
|
|
@@ -33,7 +38,6 @@ import {
|
|
|
33
38
|
export class Dom {
|
|
34
39
|
/**
|
|
35
40
|
* Remove all content from element
|
|
36
|
-
* @param node
|
|
37
41
|
*/
|
|
38
42
|
static detach(node: Node): void {
|
|
39
43
|
while (node.firstChild) {
|
|
@@ -43,10 +47,6 @@ export class Dom {
|
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
49
|
* Wrap all inline siblings
|
|
46
|
-
*
|
|
47
|
-
* @param current
|
|
48
|
-
* @param tag
|
|
49
|
-
* @param editor
|
|
50
50
|
*/
|
|
51
51
|
static wrapInline(
|
|
52
52
|
current: Node,
|
|
@@ -107,10 +107,6 @@ export class Dom {
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Wrap node inside another node
|
|
110
|
-
*
|
|
111
|
-
* @param current
|
|
112
|
-
* @param tag
|
|
113
|
-
* @param editor
|
|
114
110
|
*/
|
|
115
111
|
static wrap<K extends HTMLTagNames>(
|
|
116
112
|
current: Node,
|
|
@@ -138,7 +134,6 @@ export class Dom {
|
|
|
138
134
|
|
|
139
135
|
/**
|
|
140
136
|
* Remove parent of node and insert this node instead that parent
|
|
141
|
-
* @param node
|
|
142
137
|
*/
|
|
143
138
|
static unwrap(node: Node): void {
|
|
144
139
|
const parent = node.parentNode;
|
|
@@ -152,52 +147,8 @@ export class Dom {
|
|
|
152
147
|
}
|
|
153
148
|
}
|
|
154
149
|
|
|
155
|
-
/**
|
|
156
|
-
* It goes through all the internal elements of the node, causing a callback function
|
|
157
|
-
*
|
|
158
|
-
* @param elm elements , the internal node is necessary to sort out
|
|
159
|
-
* @param callback It called for each item found
|
|
160
|
-
* @example
|
|
161
|
-
* ```javascript
|
|
162
|
-
* Jodit.modules.Dom.each(parent.s.current(), function (node) {
|
|
163
|
-
* if (node.nodeType === Node.TEXT_NODE) {
|
|
164
|
-
* node.nodeValue = node.nodeValue.replace(Jodit.INVISIBLE_SPACE_REG_EX, '') // remove all of
|
|
165
|
-
* the text element codes invisible character
|
|
166
|
-
* }
|
|
167
|
-
* });
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
static each(
|
|
171
|
-
elm: Node | HTMLElement,
|
|
172
|
-
callback: (node: Node) => void | boolean
|
|
173
|
-
): boolean {
|
|
174
|
-
let node: Node | null | false = elm.firstChild;
|
|
175
|
-
|
|
176
|
-
if (node) {
|
|
177
|
-
while (node) {
|
|
178
|
-
const next = Dom.next(node, Boolean, elm);
|
|
179
|
-
|
|
180
|
-
if (callback(node) === false) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// inside callback - node could be removed
|
|
185
|
-
if (node.parentNode && !Dom.each(node, callback)) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
node = next;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
150
|
/**
|
|
197
151
|
* Call function for all nodes between `start` and `end`
|
|
198
|
-
*
|
|
199
|
-
* @param start
|
|
200
|
-
* @param end
|
|
201
152
|
*/
|
|
202
153
|
static between(
|
|
203
154
|
start: Node,
|
|
@@ -228,12 +179,10 @@ export class Dom {
|
|
|
228
179
|
/**
|
|
229
180
|
* Replace one tag to another transfer content
|
|
230
181
|
*
|
|
231
|
-
* @param
|
|
232
|
-
* @param
|
|
233
|
-
* @param
|
|
234
|
-
* @param
|
|
235
|
-
* @param {Document} [doc=document]
|
|
236
|
-
* @return {Node} Returns a new tag
|
|
182
|
+
* @param elm - The element that needs to be replaced by new
|
|
183
|
+
* @param newTagName - tag name for which will change `elm`
|
|
184
|
+
* @param withAttributes - If true move tag's attributes
|
|
185
|
+
* @param notMoveContent - false - Move content from elm to newTagName
|
|
237
186
|
* @example
|
|
238
187
|
* ```javascript
|
|
239
188
|
* Jodit.modules.Dom.replace(parent.editor.getElementsByTagName('span')[0], 'p');
|
|
@@ -274,8 +223,7 @@ export class Dom {
|
|
|
274
223
|
* Checks whether the Node text and blank (in this case it may contain invisible auxiliary characters ,
|
|
275
224
|
* it is also empty )
|
|
276
225
|
*
|
|
277
|
-
* @param
|
|
278
|
-
* @return {Boolean} true element is empty
|
|
226
|
+
* @param node - The element of wood to be checked
|
|
279
227
|
*/
|
|
280
228
|
static isEmptyTextNode(node: Node): boolean {
|
|
281
229
|
return (
|
|
@@ -288,10 +236,6 @@ export class Dom {
|
|
|
288
236
|
|
|
289
237
|
/**
|
|
290
238
|
* Check if element is empty
|
|
291
|
-
*
|
|
292
|
-
* @param {Node} node
|
|
293
|
-
* @param {RegExp} condNoEmptyElement
|
|
294
|
-
* @return {boolean}
|
|
295
239
|
*/
|
|
296
240
|
static isEmpty(
|
|
297
241
|
node: Node,
|
|
@@ -345,7 +289,6 @@ export class Dom {
|
|
|
345
289
|
|
|
346
290
|
/**
|
|
347
291
|
* Check if element is table cell
|
|
348
|
-
* @param elm
|
|
349
292
|
*/
|
|
350
293
|
static isCell(elm: unknown): elm is HTMLTableCellElement {
|
|
351
294
|
return Dom.isNode(elm) && /^(td|th)$/i.test(elm.nodeName);
|
|
@@ -353,9 +296,6 @@ export class Dom {
|
|
|
353
296
|
|
|
354
297
|
/**
|
|
355
298
|
* Check is element is Image element
|
|
356
|
-
*
|
|
357
|
-
* @param {Node} elm
|
|
358
|
-
* @return {boolean}
|
|
359
299
|
*/
|
|
360
300
|
static isImage(elm: unknown): elm is HTMLImageElement {
|
|
361
301
|
return (
|
|
@@ -378,7 +318,6 @@ export class Dom {
|
|
|
378
318
|
|
|
379
319
|
/**
|
|
380
320
|
* Check if element is text node
|
|
381
|
-
* @param node
|
|
382
321
|
*/
|
|
383
322
|
static isText(node: Node | null | false): node is Text {
|
|
384
323
|
return Boolean(node && node.nodeType === Node.TEXT_NODE);
|
|
@@ -386,11 +325,8 @@ export class Dom {
|
|
|
386
325
|
|
|
387
326
|
/**
|
|
388
327
|
* Check if element is element node
|
|
389
|
-
* @param node
|
|
390
328
|
*/
|
|
391
|
-
static isElement(
|
|
392
|
-
node: Node | null | false | EventTarget | object
|
|
393
|
-
): node is Element {
|
|
329
|
+
static isElement(node: unknown): node is Element {
|
|
394
330
|
if (!Dom.isNode(node)) {
|
|
395
331
|
return false;
|
|
396
332
|
}
|
|
@@ -402,7 +338,6 @@ export class Dom {
|
|
|
402
338
|
|
|
403
339
|
/**
|
|
404
340
|
* Check if element is HTMLElement node
|
|
405
|
-
* @param node
|
|
406
341
|
*/
|
|
407
342
|
static isHTMLElement(node: unknown): node is HTMLElement {
|
|
408
343
|
if (!Dom.isNode(node)) {
|
|
@@ -416,7 +351,6 @@ export class Dom {
|
|
|
416
351
|
|
|
417
352
|
/**
|
|
418
353
|
* Check element is inline block
|
|
419
|
-
* @param node
|
|
420
354
|
*/
|
|
421
355
|
static isInlineBlock(node: Node | null | false): node is HTMLElement {
|
|
422
356
|
return (
|
|
@@ -444,9 +378,6 @@ export class Dom {
|
|
|
444
378
|
|
|
445
379
|
/**
|
|
446
380
|
* Get last matched node inside root
|
|
447
|
-
*
|
|
448
|
-
* @param root
|
|
449
|
-
* @param condition
|
|
450
381
|
*/
|
|
451
382
|
static last(
|
|
452
383
|
root: Nullable<Node>,
|
|
@@ -489,50 +420,26 @@ export class Dom {
|
|
|
489
420
|
|
|
490
421
|
/**
|
|
491
422
|
* Find previous node
|
|
492
|
-
*
|
|
493
|
-
* @param node
|
|
494
|
-
* @param condition
|
|
495
|
-
* @param root
|
|
496
|
-
* @param [withChild]
|
|
497
423
|
*/
|
|
498
|
-
static prev(
|
|
424
|
+
static prev<T extends Node = Node>(
|
|
499
425
|
node: Node,
|
|
500
426
|
condition: NodeCondition,
|
|
501
|
-
root:
|
|
427
|
+
root: HTMLElement,
|
|
502
428
|
withChild: boolean = true
|
|
503
|
-
): Nullable<
|
|
504
|
-
return Dom.find(
|
|
505
|
-
node,
|
|
506
|
-
condition,
|
|
507
|
-
root,
|
|
508
|
-
false,
|
|
509
|
-
'previousSibling',
|
|
510
|
-
withChild ? 'lastChild' : false
|
|
511
|
-
);
|
|
429
|
+
): Nullable<T> {
|
|
430
|
+
return Dom.find<T>(node, condition, root, false, withChild);
|
|
512
431
|
}
|
|
513
432
|
|
|
514
433
|
/**
|
|
515
434
|
* Find next node what `condition(next) === true`
|
|
516
|
-
*
|
|
517
|
-
* @param node
|
|
518
|
-
* @param condition
|
|
519
|
-
* @param root
|
|
520
|
-
* @param [withChild]
|
|
521
435
|
*/
|
|
522
|
-
static next(
|
|
436
|
+
static next<T extends Node = Node>(
|
|
523
437
|
node: Node,
|
|
524
438
|
condition: NodeCondition,
|
|
525
|
-
root:
|
|
439
|
+
root: HTMLElement,
|
|
526
440
|
withChild: boolean = true
|
|
527
|
-
): Nullable<
|
|
528
|
-
return Dom.find(
|
|
529
|
-
node,
|
|
530
|
-
condition,
|
|
531
|
-
root,
|
|
532
|
-
undefined,
|
|
533
|
-
undefined,
|
|
534
|
-
withChild ? 'firstChild' : false
|
|
535
|
-
);
|
|
441
|
+
): Nullable<T> {
|
|
442
|
+
return Dom.find<T>(node, condition, root, true, withChild);
|
|
536
443
|
}
|
|
537
444
|
|
|
538
445
|
static prevWithClass(
|
|
@@ -563,69 +470,127 @@ export class Dom {
|
|
|
563
470
|
|
|
564
471
|
/**
|
|
565
472
|
* Find next/prev node what `condition(next) === true`
|
|
566
|
-
*
|
|
567
|
-
* @param node
|
|
568
|
-
* @param condition
|
|
569
|
-
* @param root
|
|
570
|
-
* @param [recurse] check first argument
|
|
571
|
-
* @param [sibling] nextSibling or previousSibling
|
|
572
|
-
* @param [child] firstChild or lastChild
|
|
573
473
|
*/
|
|
574
|
-
static find(
|
|
474
|
+
static find<T extends Node = Node>(
|
|
575
475
|
node: Node,
|
|
576
476
|
condition: NodeCondition,
|
|
577
|
-
root:
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
477
|
+
root: HTMLElement,
|
|
478
|
+
leftToRight: boolean = true,
|
|
479
|
+
withChild: boolean = true
|
|
480
|
+
): Nullable<T> {
|
|
481
|
+
const gen = this.nextGen(node, root, leftToRight, withChild);
|
|
482
|
+
|
|
483
|
+
let item = gen.next();
|
|
484
|
+
|
|
485
|
+
while (!item.done) {
|
|
486
|
+
if (condition(item.value)) {
|
|
487
|
+
return <T>item.value;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
item = gen.next();
|
|
584
491
|
}
|
|
585
492
|
|
|
586
|
-
|
|
587
|
-
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Find next/prev node what `condition(next) === true`
|
|
498
|
+
*/
|
|
499
|
+
static *nextGen(
|
|
500
|
+
start: Node,
|
|
501
|
+
root: HTMLElement,
|
|
502
|
+
leftToRight: boolean = true,
|
|
503
|
+
withChild: boolean = true
|
|
504
|
+
): Generator<Node> {
|
|
505
|
+
const stack: Node[] = [];
|
|
506
|
+
|
|
507
|
+
let currentNode = start;
|
|
588
508
|
|
|
589
509
|
do {
|
|
590
|
-
next =
|
|
510
|
+
let next = leftToRight
|
|
511
|
+
? currentNode.nextSibling
|
|
512
|
+
: currentNode.previousSibling;
|
|
591
513
|
|
|
592
|
-
|
|
593
|
-
|
|
514
|
+
while (next) {
|
|
515
|
+
stack.unshift(next);
|
|
516
|
+
next = leftToRight ? next.nextSibling : next.previousSibling;
|
|
594
517
|
}
|
|
595
518
|
|
|
596
|
-
|
|
597
|
-
const nextOne = Dom.find(
|
|
598
|
-
next[child] as Node,
|
|
599
|
-
condition,
|
|
600
|
-
next,
|
|
601
|
-
true,
|
|
602
|
-
sibling,
|
|
603
|
-
child
|
|
604
|
-
);
|
|
519
|
+
yield* this.runInStack(start, stack, leftToRight, withChild);
|
|
605
520
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
521
|
+
currentNode = <Node>currentNode.parentNode;
|
|
522
|
+
} while (currentNode !== root);
|
|
523
|
+
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* It goes through all the internal elements of the node, causing a callback function
|
|
529
|
+
*
|
|
530
|
+
* @param elm - the element whose children and descendants you want to iterate over
|
|
531
|
+
* @param callback - It called for each item found
|
|
532
|
+
* @example
|
|
533
|
+
* ```javascript
|
|
534
|
+
* Jodit.modules.Dom.each(parent.s.current(), function (node) {
|
|
535
|
+
* if (node.nodeType === Node.TEXT_NODE) {
|
|
536
|
+
* node.nodeValue = node.nodeValue.replace(Jodit.INVISIBLE_SPACE_REG_EX, '') // remove all of
|
|
537
|
+
* the text element codes invisible character
|
|
538
|
+
* }
|
|
539
|
+
* });
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
static each(
|
|
543
|
+
elm: Node,
|
|
544
|
+
callback: (node: Node) => void | boolean,
|
|
545
|
+
leftToRight: boolean = true
|
|
546
|
+
): boolean {
|
|
547
|
+
const gen = this.eachGen(elm, leftToRight);
|
|
548
|
+
|
|
549
|
+
let item = gen.next();
|
|
550
|
+
|
|
551
|
+
while (!item.done) {
|
|
552
|
+
if (callback(item.value) === false) {
|
|
553
|
+
return false;
|
|
609
554
|
}
|
|
610
555
|
|
|
611
|
-
|
|
612
|
-
|
|
556
|
+
item = gen.next();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
static eachGen(root: Node, leftToRight: boolean = true): Generator<Node> {
|
|
563
|
+
return this.runInStack(root, [root], leftToRight);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
private static *runInStack(
|
|
567
|
+
start: Node,
|
|
568
|
+
stack: Node[],
|
|
569
|
+
leftToRight: boolean,
|
|
570
|
+
withChild: boolean = true
|
|
571
|
+
): Generator<Node> {
|
|
572
|
+
while (stack.length) {
|
|
573
|
+
const item = <Node>stack.pop();
|
|
574
|
+
|
|
575
|
+
if (start !== item) {
|
|
576
|
+
yield item;
|
|
613
577
|
}
|
|
614
578
|
|
|
615
|
-
|
|
616
|
-
|
|
579
|
+
if (withChild) {
|
|
580
|
+
let child = leftToRight ? item.lastChild : item.firstChild;
|
|
617
581
|
|
|
618
|
-
|
|
582
|
+
while (child) {
|
|
583
|
+
stack.push(child);
|
|
584
|
+
child = leftToRight
|
|
585
|
+
? child.previousSibling
|
|
586
|
+
: child.nextSibling;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
619
590
|
}
|
|
620
591
|
|
|
621
592
|
/**
|
|
622
593
|
* Find next/prev node what `condition(next) === true`
|
|
623
|
-
*
|
|
624
|
-
* @param node
|
|
625
|
-
* @param condition
|
|
626
|
-
* @param root
|
|
627
|
-
* @param [sibling] nextSibling or previousSibling
|
|
628
|
-
* @param [child] firstChild or lastChild
|
|
629
594
|
*/
|
|
630
595
|
static findWithCurrent(
|
|
631
596
|
node: Node,
|
|
@@ -669,10 +634,6 @@ export class Dom {
|
|
|
669
634
|
|
|
670
635
|
/**
|
|
671
636
|
* Get not empty sibling
|
|
672
|
-
*
|
|
673
|
-
* @param node
|
|
674
|
-
* @param [left]
|
|
675
|
-
* @param [cond]
|
|
676
637
|
*/
|
|
677
638
|
static findSibling(
|
|
678
639
|
node: Node,
|
|
@@ -694,11 +655,6 @@ export class Dom {
|
|
|
694
655
|
|
|
695
656
|
/**
|
|
696
657
|
* It goes through all the elements in ascending order, and checks to see if they meet the predetermined condition
|
|
697
|
-
*
|
|
698
|
-
* @param node
|
|
699
|
-
* @param condition
|
|
700
|
-
* @param [root] Root element
|
|
701
|
-
* @param [checkRoot]
|
|
702
658
|
*/
|
|
703
659
|
static up<T extends HTMLElement>(
|
|
704
660
|
node: Nullable<Node>,
|
|
@@ -733,10 +689,6 @@ export class Dom {
|
|
|
733
689
|
|
|
734
690
|
/**
|
|
735
691
|
* Find parent by tag name
|
|
736
|
-
*
|
|
737
|
-
* @param node
|
|
738
|
-
* @param tags
|
|
739
|
-
* @param root
|
|
740
692
|
*/
|
|
741
693
|
static closest<T extends HTMLElement, K extends HTMLTagNames>(
|
|
742
694
|
node: Nullable<Node>,
|
|
@@ -784,10 +736,6 @@ export class Dom {
|
|
|
784
736
|
|
|
785
737
|
/**
|
|
786
738
|
* Furthest parent node matching condition
|
|
787
|
-
*
|
|
788
|
-
* @param node
|
|
789
|
-
* @param condition
|
|
790
|
-
* @param root
|
|
791
739
|
*/
|
|
792
740
|
static furthest<T extends HTMLElement>(
|
|
793
741
|
node: Nullable<Node>,
|
|
@@ -807,8 +755,6 @@ export class Dom {
|
|
|
807
755
|
|
|
808
756
|
/**
|
|
809
757
|
* Append new element in the start of root
|
|
810
|
-
* @param root
|
|
811
|
-
* @param newElement
|
|
812
758
|
*/
|
|
813
759
|
static appendChildFirst(
|
|
814
760
|
root: HTMLElement,
|
|
@@ -827,9 +773,6 @@ export class Dom {
|
|
|
827
773
|
|
|
828
774
|
/**
|
|
829
775
|
* Insert newElement after element
|
|
830
|
-
*
|
|
831
|
-
* @param elm
|
|
832
|
-
* @param newElement
|
|
833
776
|
*/
|
|
834
777
|
static after(elm: Node, newElement: Node | DocumentFragment): void {
|
|
835
778
|
const { parentNode } = elm;
|
|
@@ -847,9 +790,6 @@ export class Dom {
|
|
|
847
790
|
|
|
848
791
|
/**
|
|
849
792
|
* Insert newElement before element
|
|
850
|
-
*
|
|
851
|
-
* @param elm
|
|
852
|
-
* @param newElement
|
|
853
793
|
*/
|
|
854
794
|
static before(elm: Node, newElement: Node | DocumentFragment): void {
|
|
855
795
|
const { parentNode } = elm;
|
|
@@ -863,9 +803,6 @@ export class Dom {
|
|
|
863
803
|
|
|
864
804
|
/**
|
|
865
805
|
* Insert newElement as first child inside element
|
|
866
|
-
*
|
|
867
|
-
* @param elm
|
|
868
|
-
* @param newElement
|
|
869
806
|
*/
|
|
870
807
|
static prepend(root: Node, newElement: Node | DocumentFragment): void {
|
|
871
808
|
root.insertBefore(newElement, root.firstChild);
|
|
@@ -873,9 +810,6 @@ export class Dom {
|
|
|
873
810
|
|
|
874
811
|
/**
|
|
875
812
|
* Insert newElement as last child inside element
|
|
876
|
-
*
|
|
877
|
-
* @param elm
|
|
878
|
-
* @param newElement
|
|
879
813
|
*/
|
|
880
814
|
static append(
|
|
881
815
|
root: Node,
|
|
@@ -899,10 +833,6 @@ export class Dom {
|
|
|
899
833
|
|
|
900
834
|
/**
|
|
901
835
|
* Move all content to another element
|
|
902
|
-
*
|
|
903
|
-
* @param from
|
|
904
|
-
* @param to
|
|
905
|
-
* @param inStart
|
|
906
836
|
*/
|
|
907
837
|
static moveContent(from: Node, to: Node, inStart: boolean = false): void {
|
|
908
838
|
const fragment: DocumentFragment = (
|
|
@@ -922,10 +852,6 @@ export class Dom {
|
|
|
922
852
|
|
|
923
853
|
/**
|
|
924
854
|
* Call callback condition function for all elements of node
|
|
925
|
-
*
|
|
926
|
-
* @param node
|
|
927
|
-
* @param condition
|
|
928
|
-
* @param prev
|
|
929
855
|
*/
|
|
930
856
|
static all(
|
|
931
857
|
node: Node,
|
|
@@ -951,10 +877,6 @@ export class Dom {
|
|
|
951
877
|
|
|
952
878
|
/**
|
|
953
879
|
* Check root contains child or equal child
|
|
954
|
-
*
|
|
955
|
-
* @param root
|
|
956
|
-
* @param child
|
|
957
|
-
* @param [onlyContains]
|
|
958
880
|
*/
|
|
959
881
|
static isOrContains(
|
|
960
882
|
root: Node,
|
|
@@ -972,7 +894,6 @@ export class Dom {
|
|
|
972
894
|
|
|
973
895
|
/**
|
|
974
896
|
* Safe remove element from DOM
|
|
975
|
-
* @param node
|
|
976
897
|
*/
|
|
977
898
|
static safeRemove(node: Node | false | null | void): void {
|
|
978
899
|
node && node.parentNode && node.parentNode.removeChild(node);
|
|
@@ -980,7 +901,6 @@ export class Dom {
|
|
|
980
901
|
|
|
981
902
|
/**
|
|
982
903
|
* Hide element
|
|
983
|
-
* @param node
|
|
984
904
|
*/
|
|
985
905
|
static hide(node: Nullable<HTMLElement>): void {
|
|
986
906
|
if (!node) {
|
|
@@ -993,7 +913,6 @@ export class Dom {
|
|
|
993
913
|
|
|
994
914
|
/**
|
|
995
915
|
* Show element
|
|
996
|
-
* @param node
|
|
997
916
|
*/
|
|
998
917
|
static show(node: Nullable<HTMLElement>): void {
|
|
999
918
|
if (!node) {
|
|
@@ -1009,9 +928,6 @@ export class Dom {
|
|
|
1009
928
|
|
|
1010
929
|
/**
|
|
1011
930
|
* Check if element is some tag
|
|
1012
|
-
*
|
|
1013
|
-
* @param node
|
|
1014
|
-
* @param tagNames
|
|
1015
931
|
*/
|
|
1016
932
|
static isTag<K extends keyof HTMLElementTagNameMap>(
|
|
1017
933
|
node: Node | null | false | EventTarget,
|
|
@@ -1040,4 +956,44 @@ export class Dom {
|
|
|
1040
956
|
|
|
1041
957
|
return false;
|
|
1042
958
|
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Marks an item as temporary
|
|
962
|
+
*/
|
|
963
|
+
static markTemporary<K extends HTMLElement>(
|
|
964
|
+
element: K,
|
|
965
|
+
attributes?: IDictionary
|
|
966
|
+
): K {
|
|
967
|
+
attributes && attr(element, attributes);
|
|
968
|
+
attr(element, TEMP_ATTR, true);
|
|
969
|
+
return element;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Check if element is temporary
|
|
974
|
+
*/
|
|
975
|
+
static isTemporary(element: unknown): boolean {
|
|
976
|
+
if (!Dom.isElement(element)) {
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
return Select.isMarker(element) || attr(element, TEMP_ATTR) === 'true';
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Replace temporary elements from string
|
|
985
|
+
*/
|
|
986
|
+
static replaceTemporaryFromString(value: string): string {
|
|
987
|
+
return value.replace(
|
|
988
|
+
/<([a-z]+)[^>]+data-jodit-temp[^>]+>(.+?)<\/\1>/gi,
|
|
989
|
+
'$2'
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Get temporary list
|
|
995
|
+
*/
|
|
996
|
+
static temporaryList(root: HTMLElement): HTMLElement[] {
|
|
997
|
+
return $$(`[${TEMP_ATTR}]`, root);
|
|
998
|
+
}
|
|
1043
999
|
}
|