jodit 4.18.12 → 4.19.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 +22 -0
- package/es2015/jodit.css +10 -1
- package/es2015/jodit.fat.min.css +1 -1
- package/es2015/jodit.fat.min.js +18 -12
- package/es2015/jodit.js +2464 -300
- package/es2015/jodit.min.css +1 -1
- package/es2015/jodit.min.js +18 -12
- package/es2015/plugins/debug/debug.css +1 -1
- package/es2015/plugins/debug/debug.js +1 -1
- package/es2015/plugins/debug/debug.min.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2018/jodit.fat.min.css +1 -1
- package/es2018/jodit.fat.min.js +18 -12
- package/es2018/jodit.min.css +1 -1
- package/es2018/jodit.min.js +18 -12
- package/es2018/plugins/debug/debug.min.js +1 -1
- package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2021/jodit.css +10 -1
- package/es2021/jodit.fat.min.css +1 -1
- package/es2021/jodit.fat.min.js +26 -19
- package/es2021/jodit.js +2426 -297
- package/es2021/jodit.min.css +1 -1
- package/es2021/jodit.min.js +26 -19
- package/es2021/plugins/debug/debug.css +1 -1
- package/es2021/plugins/debug/debug.js +1 -1
- package/es2021/plugins/debug/debug.min.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2021.en/jodit.css +10 -1
- package/es2021.en/jodit.fat.min.css +1 -1
- package/es2021.en/jodit.fat.min.js +29 -22
- package/es2021.en/jodit.js +2400 -271
- package/es2021.en/jodit.min.css +1 -1
- package/es2021.en/jodit.min.js +29 -22
- package/es2021.en/plugins/debug/debug.css +1 -1
- package/es2021.en/plugins/debug/debug.js +1 -1
- package/es2021.en/plugins/debug/debug.min.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es5/jodit.css +11 -2
- package/es5/jodit.fat.min.css +1 -1
- package/es5/jodit.fat.min.js +2 -2
- package/es5/jodit.js +2823 -360
- package/es5/jodit.min.css +3 -3
- package/es5/jodit.min.js +2 -2
- package/es5/plugins/debug/debug.css +1 -1
- package/es5/plugins/debug/debug.js +1 -1
- package/es5/plugins/debug/debug.min.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es5/polyfills.fat.min.js +1 -1
- package/es5/polyfills.js +1 -1
- package/es5/polyfills.min.js +1 -1
- package/esm/config.d.ts +44 -1
- package/esm/config.js +2 -1
- package/esm/core/constants.js +1 -1
- package/esm/core/dom/dom.js +4 -2
- package/esm/core/event-emitter/event-emitter.js +1 -0
- package/esm/core/helpers/utils/align.d.ts +6 -1
- package/esm/core/helpers/utils/align.js +22 -12
- package/esm/core/helpers/utils/image-caption.d.ts +24 -0
- package/esm/core/helpers/utils/image-caption.js +43 -0
- package/esm/core/helpers/utils/index.d.ts +1 -0
- package/esm/core/helpers/utils/index.js +1 -0
- package/esm/core/selection/selection.d.ts +3 -0
- package/esm/core/selection/selection.js +20 -5
- package/esm/core/ui/helpers/focus-form-field.d.ts +12 -0
- package/esm/core/ui/helpers/focus-form-field.js +21 -0
- package/esm/jodit.js +18 -2
- package/esm/langs/ar.d.ts +2 -0
- package/esm/langs/ar.js +2 -0
- package/esm/langs/az.d.ts +2 -0
- package/esm/langs/az.js +2 -0
- package/esm/langs/cs_cz.d.ts +2 -0
- package/esm/langs/cs_cz.js +2 -0
- package/esm/langs/de.d.ts +2 -0
- package/esm/langs/de.js +2 -0
- package/esm/langs/es.d.ts +2 -0
- package/esm/langs/es.js +2 -0
- package/esm/langs/fa.d.ts +2 -0
- package/esm/langs/fa.js +2 -0
- package/esm/langs/fi.d.ts +2 -0
- package/esm/langs/fi.js +2 -0
- package/esm/langs/fr.d.ts +2 -0
- package/esm/langs/fr.js +2 -0
- package/esm/langs/he.d.ts +2 -0
- package/esm/langs/he.js +2 -0
- package/esm/langs/hu.d.ts +2 -0
- package/esm/langs/hu.js +2 -0
- package/esm/langs/id.d.ts +2 -0
- package/esm/langs/id.js +2 -0
- package/esm/langs/it.d.ts +2 -0
- package/esm/langs/it.js +2 -0
- package/esm/langs/ja.d.ts +2 -0
- package/esm/langs/ja.js +2 -0
- package/esm/langs/ko.d.ts +2 -0
- package/esm/langs/ko.js +2 -0
- package/esm/langs/mn.d.ts +2 -0
- package/esm/langs/mn.js +2 -0
- package/esm/langs/nl.d.ts +2 -0
- package/esm/langs/nl.js +2 -0
- package/esm/langs/no.d.ts +2 -0
- package/esm/langs/no.js +2 -0
- package/esm/langs/pl.d.ts +2 -0
- package/esm/langs/pl.js +2 -0
- package/esm/langs/pt_br.d.ts +2 -0
- package/esm/langs/pt_br.js +2 -0
- package/esm/langs/ru.d.ts +2 -0
- package/esm/langs/ru.js +2 -0
- package/esm/langs/sk.d.ts +2 -0
- package/esm/langs/sk.js +2 -0
- package/esm/langs/sv.d.ts +2 -0
- package/esm/langs/sv.js +2 -0
- package/esm/langs/tr.d.ts +2 -0
- package/esm/langs/tr.js +2 -0
- package/esm/langs/ua.d.ts +2 -0
- package/esm/langs/ua.js +2 -0
- package/esm/langs/zh_cn.d.ts +2 -0
- package/esm/langs/zh_cn.js +2 -0
- package/esm/langs/zh_tw.d.ts +2 -0
- package/esm/langs/zh_tw.js +2 -0
- package/esm/modules/table/table.d.ts +27 -0
- package/esm/modules/table/table.js +110 -2
- package/esm/modules/toolbar/button/button.js +11 -3
- package/esm/modules/uploader/helpers/send-files.js +3 -1
- package/esm/modules/widget/tabs/tabs.js +2 -0
- package/esm/plugins/all.d.ts +1 -0
- package/esm/plugins/all.js +1 -0
- package/esm/plugins/backspace/backspace.js +17 -1
- package/esm/plugins/backspace/cases/check-remove-char.js +1 -11
- package/esm/plugins/backspace/helpers.d.ts +5 -0
- package/esm/plugins/backspace/helpers.js +11 -0
- package/esm/plugins/clean-html/clean-html.js +2 -2
- package/esm/plugins/clean-html/helpers/index.d.ts +1 -0
- package/esm/plugins/clean-html/helpers/index.js +1 -0
- package/esm/plugins/clean-html/helpers/remove-format/remove-format-for-word.d.ts +16 -0
- package/esm/plugins/clean-html/helpers/remove-format/remove-format-for-word.js +109 -0
- package/esm/plugins/drag-and-drop-element/drag-and-drop-element.js +4 -2
- package/esm/plugins/format-block/config.d.ts +13 -0
- package/esm/plugins/format-block/config.js +38 -1
- package/esm/plugins/format-block/content-fonts.d.ts +17 -0
- package/esm/plugins/format-block/content-fonts.js +156 -0
- package/esm/plugins/image-caption/config.d.ts +31 -0
- package/esm/plugins/image-caption/config.js +11 -0
- package/esm/plugins/image-caption/image-caption.d.ts +140 -0
- package/esm/plugins/image-caption/image-caption.js +799 -0
- package/esm/plugins/image-processor/image-processor.d.ts +2 -1
- package/esm/plugins/image-processor/image-processor.js +9 -4
- package/esm/plugins/image-properties/config.js +1 -0
- package/esm/plugins/image-properties/image-properties.js +19 -5
- package/esm/plugins/image-properties/interface.d.ts +6 -0
- package/esm/plugins/image-properties/readers/align.d.ts +1 -1
- package/esm/plugins/image-properties/readers/index.js +9 -3
- package/esm/plugins/image-properties/readers/margin.d.ts +1 -1
- package/esm/plugins/image-properties/readers/size.d.ts +5 -1
- package/esm/plugins/image-properties/readers/size.js +4 -5
- package/esm/plugins/image-properties/ui/ui-image-main-tab.d.ts +2 -0
- package/esm/plugins/image-properties/ui/ui-image-main-tab.js +20 -0
- package/esm/plugins/image-properties/writers/caption.d.ts +15 -0
- package/esm/plugins/image-properties/writers/caption.js +18 -0
- package/esm/plugins/image-properties/writers/index.js +15 -10
- package/esm/plugins/image-properties/writers/link.js +7 -2
- package/esm/plugins/image-properties/writers/margin.d.ts +1 -1
- package/esm/plugins/image-properties/writers/size.d.ts +5 -2
- package/esm/plugins/image-properties/writers/size.js +16 -2
- package/esm/plugins/indent/helpers.d.ts +9 -0
- package/esm/plugins/indent/helpers.js +23 -3
- package/esm/plugins/indent/indent.js +2 -20
- package/esm/plugins/index.d.ts +1 -0
- package/esm/plugins/inline-popup/config/config.js +4 -0
- package/esm/plugins/inline-popup/config/items/cells.js +29 -0
- package/esm/plugins/inline-popup/config/items/img.js +35 -5
- package/esm/plugins/inline-popup/icons/caption.svg.js +1 -0
- package/esm/plugins/inline-popup/icons/headerrow.svg.js +1 -0
- package/esm/plugins/inline-popup/inline-popup.js +3 -2
- package/esm/plugins/placeholder/placeholder.js +7 -1
- package/esm/plugins/resize-cells/resize-cells.d.ts +49 -0
- package/esm/plugins/resize-cells/resize-cells.js +247 -13
- package/esm/plugins/resizer/resizer.js +13 -2
- package/esm/plugins/select-cells/select-cells.d.ts +5 -0
- package/esm/plugins/select-cells/select-cells.js +29 -11
- package/esm/plugins/tab/cases/index.d.ts +1 -0
- package/esm/plugins/tab/cases/index.js +1 -0
- package/esm/plugins/tab/cases/on-tab-inside-li.js +3 -1
- package/esm/plugins/tab/cases/tab-spaces.d.ts +32 -0
- package/esm/plugins/tab/cases/tab-spaces.js +263 -0
- package/esm/plugins/tab/config.d.ts +10 -0
- package/esm/plugins/tab/config.js +2 -1
- package/esm/plugins/tab/tab.js +61 -6
- package/esm/types/types.d.ts +16 -0
- package/esm/types/uploader.d.ts +6 -0
- package/package.json +1 -1
- package/types/config.d.ts +44 -1
- package/types/core/helpers/utils/align.d.ts +6 -1
- package/types/core/helpers/utils/image-caption.d.ts +24 -0
- package/types/core/helpers/utils/index.d.ts +1 -0
- package/types/core/selection/selection.d.ts +3 -0
- package/types/core/ui/helpers/focus-form-field.d.ts +12 -0
- package/types/langs/ar.d.ts +2 -0
- package/types/langs/az.d.ts +2 -0
- package/types/langs/cs_cz.d.ts +2 -0
- package/types/langs/de.d.ts +2 -0
- package/types/langs/es.d.ts +2 -0
- package/types/langs/fa.d.ts +2 -0
- package/types/langs/fi.d.ts +2 -0
- package/types/langs/fr.d.ts +2 -0
- package/types/langs/he.d.ts +2 -0
- package/types/langs/hu.d.ts +2 -0
- package/types/langs/id.d.ts +2 -0
- package/types/langs/it.d.ts +2 -0
- package/types/langs/ja.d.ts +2 -0
- package/types/langs/ko.d.ts +2 -0
- package/types/langs/mn.d.ts +2 -0
- package/types/langs/nl.d.ts +2 -0
- package/types/langs/no.d.ts +2 -0
- package/types/langs/pl.d.ts +2 -0
- package/types/langs/pt_br.d.ts +2 -0
- package/types/langs/ru.d.ts +2 -0
- package/types/langs/sk.d.ts +2 -0
- package/types/langs/sv.d.ts +2 -0
- package/types/langs/tr.d.ts +2 -0
- package/types/langs/ua.d.ts +2 -0
- package/types/langs/zh_cn.d.ts +2 -0
- package/types/langs/zh_tw.d.ts +2 -0
- package/types/modules/table/table.d.ts +27 -0
- package/types/plugins/backspace/helpers.d.ts +5 -0
- package/types/plugins/clean-html/helpers/index.d.ts +1 -0
- package/types/plugins/clean-html/helpers/remove-format/remove-format-for-word.d.ts +16 -0
- package/types/plugins/format-block/config.d.ts +13 -0
- package/types/plugins/format-block/content-fonts.d.ts +17 -0
- package/types/plugins/image-caption/config.d.ts +31 -0
- package/types/plugins/image-caption/image-caption.d.ts +140 -0
- package/types/plugins/image-processor/image-processor.d.ts +2 -1
- package/types/plugins/image-properties/interface.d.ts +6 -0
- package/types/plugins/image-properties/readers/align.d.ts +1 -1
- package/types/plugins/image-properties/readers/margin.d.ts +1 -1
- package/types/plugins/image-properties/readers/size.d.ts +5 -1
- package/types/plugins/image-properties/ui/ui-image-main-tab.d.ts +2 -0
- package/types/plugins/image-properties/writers/caption.d.ts +15 -0
- package/types/plugins/image-properties/writers/margin.d.ts +1 -1
- package/types/plugins/image-properties/writers/size.d.ts +5 -2
- package/types/plugins/indent/helpers.d.ts +9 -0
- package/types/plugins/index.d.ts +1 -0
- package/types/plugins/resize-cells/resize-cells.d.ts +49 -0
- package/types/plugins/select-cells/select-cells.d.ts +5 -0
- package/types/plugins/tab/cases/index.d.ts +1 -0
- package/types/plugins/tab/cases/tab-spaces.d.ts +32 -0
- package/types/plugins/tab/config.d.ts +10 -0
- package/types/types/types.d.ts +16 -0
- package/types/types/uploader.d.ts +6 -0
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
+
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
+
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
+
*/
|
|
6
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
7
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
9
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
else
|
|
11
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
12
|
+
if (d = decorators[i])
|
|
13
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
};
|
|
16
|
+
import * as consts from "../../core/constants.js";
|
|
17
|
+
import { autobind, debounce, watch } from "../../core/decorators/index.js";
|
|
18
|
+
import { Dom } from "../../core/dom/dom.js";
|
|
19
|
+
import { getContainer, pluginSystem } from "../../core/global.js";
|
|
20
|
+
import { attr, call, clearHAlign, css, getAlignClasses, getCaptionedImage, getCaptionWrapper, getHAlign, getImageCaption, hAlignElement, isNumeric, toArray } from "../../core/helpers/index.js";
|
|
21
|
+
import { cssInline } from "../../core/helpers/utils/css.js";
|
|
22
|
+
import { Plugin } from "../../core/plugin/plugin.js";
|
|
23
|
+
import { isMoved } from "../../core/selection/helpers/index.js";
|
|
24
|
+
import "./config.js";
|
|
25
|
+
const MARGINS = [
|
|
26
|
+
'margin-top',
|
|
27
|
+
'margin-right',
|
|
28
|
+
'margin-bottom',
|
|
29
|
+
'margin-left'
|
|
30
|
+
];
|
|
31
|
+
const ARROWS = new Set([
|
|
32
|
+
consts.KEY_UP,
|
|
33
|
+
consts.KEY_DOWN,
|
|
34
|
+
consts.KEY_LEFT,
|
|
35
|
+
consts.KEY_RIGHT
|
|
36
|
+
]);
|
|
37
|
+
// Blocks that only hold text, which a block wrapper can't go inside
|
|
38
|
+
const TEXT_BLOCK = /^(P|H[1-6]|PRE)$/i;
|
|
39
|
+
// They would replace the caption with a heading, quote or list
|
|
40
|
+
const BLOCK_COMMANDS = new Set([
|
|
41
|
+
'formatblock',
|
|
42
|
+
'insertorderedlist',
|
|
43
|
+
'insertunorderedlist'
|
|
44
|
+
]);
|
|
45
|
+
const PLACEHOLDER = 'data-jodit-placeholder';
|
|
46
|
+
/**
|
|
47
|
+
* Jodit's focus colour round a caption being typed in, in place of the
|
|
48
|
+
* browser's, and a placeholder in a blank caption. `:where` leaves both for
|
|
49
|
+
* the content's own styles to change
|
|
50
|
+
*/
|
|
51
|
+
const CAPTION_STYLE = ':where(.jodit-wysiwyg [contenteditable=false] [contenteditable=true]:focus){outline:1px solid var(--jd-color-border-selected,#1e88e5)}' +
|
|
52
|
+
`:where(.jodit-wysiwyg [${PLACEHOLDER}]){position:relative}` +
|
|
53
|
+
`:where(.jodit-wysiwyg [${PLACEHOLDER}])::before{position:absolute;top:0;right:0;left:0;padding:inherit;color:var(--jd-color-placeholder,#a5a5a5);content:attr(${PLACEHOLDER});pointer-events:none}`;
|
|
54
|
+
/**
|
|
55
|
+
* Captions images: wraps an image in `imageCaption`'s elements and back, and
|
|
56
|
+
* keeps the caret in the caption
|
|
57
|
+
*/
|
|
58
|
+
export class imageCaption extends Plugin {
|
|
59
|
+
constructor() {
|
|
60
|
+
super(...arguments);
|
|
61
|
+
/**
|
|
62
|
+
* The caption given last, while nothing has changed round it and it's
|
|
63
|
+
* still blank, so taking it off can put everything back as it was
|
|
64
|
+
*/
|
|
65
|
+
this.__fresh = null;
|
|
66
|
+
this.__press = null;
|
|
67
|
+
this.__afterPress = [];
|
|
68
|
+
this.__arrow = null;
|
|
69
|
+
}
|
|
70
|
+
/** @override */
|
|
71
|
+
afterInit(jodit) {
|
|
72
|
+
// It goes in the editing document, so iframe mode has it whatever `iframeStyle` holds
|
|
73
|
+
getContainer(jodit, 'imageCaption', 'style', true).textContent =
|
|
74
|
+
CAPTION_STYLE;
|
|
75
|
+
jodit.e.on('beforeCommandSelectall', this.__onSelectAll, {
|
|
76
|
+
top: true
|
|
77
|
+
});
|
|
78
|
+
this.onChangePlace();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gives `image` a caption, or takes it away, as `on` says, or else the
|
|
82
|
+
* other way round from how it is. Returns the caption it gave, or null
|
|
83
|
+
* when it took one away
|
|
84
|
+
*/
|
|
85
|
+
onToggleImageCaption(image, on) {
|
|
86
|
+
const wrapper = getCaptionWrapper(this.j, image);
|
|
87
|
+
if (wrapper && on !== true) {
|
|
88
|
+
const fresh = this.__freshCaption(wrapper);
|
|
89
|
+
if (fresh) {
|
|
90
|
+
this.__unrecorded(() => this.__restore(fresh));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.__uncaption(wrapper, image);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (!wrapper && on !== false) {
|
|
98
|
+
return this.__caption(image);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
__freshCaption(wrapper) {
|
|
102
|
+
const fresh = this.__fresh;
|
|
103
|
+
if (!fresh ||
|
|
104
|
+
fresh.wrapper !== wrapper ||
|
|
105
|
+
wrapper.parentNode !== fresh.parent ||
|
|
106
|
+
wrapper.previousSibling !== fresh.previous ||
|
|
107
|
+
wrapper.nextSibling !== fresh.next ||
|
|
108
|
+
shape(wrapper, fresh.image) !== fresh.shape ||
|
|
109
|
+
getImageCaption(this.j, wrapper) !== fresh.caption ||
|
|
110
|
+
!Dom.isEmpty(fresh.caption)) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return fresh;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Giving a caption isn't a step in the history of its own, as the first
|
|
117
|
+
* thing typed in it is, so Undo never brings back a blank caption
|
|
118
|
+
*/
|
|
119
|
+
__caption(image) {
|
|
120
|
+
const { j } = this;
|
|
121
|
+
const { snapshot } = j.history;
|
|
122
|
+
// The steps before it are recorded first
|
|
123
|
+
j.setEditorValue();
|
|
124
|
+
j.e.fire('internalUpdate');
|
|
125
|
+
const before = snapshot.make();
|
|
126
|
+
let fresh;
|
|
127
|
+
snapshot.transaction(() => {
|
|
128
|
+
fresh = this.__fresh = { ...this.__wrap(image), before };
|
|
129
|
+
j.setEditorValue();
|
|
130
|
+
});
|
|
131
|
+
// The value is as it was, so no `change` updates the toolbars
|
|
132
|
+
j.e.fire('updateToolbar');
|
|
133
|
+
return fresh.caption;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Changes the content with no step in the history of its own, so Undo
|
|
137
|
+
* never brings back a blank caption. A step still open takes it in
|
|
138
|
+
*/
|
|
139
|
+
__unrecorded(changes) {
|
|
140
|
+
const { j } = this;
|
|
141
|
+
j.setEditorValue();
|
|
142
|
+
this.__fresh = null;
|
|
143
|
+
j.history.snapshot.transaction(() => {
|
|
144
|
+
changes();
|
|
145
|
+
j.setEditorValue();
|
|
146
|
+
});
|
|
147
|
+
j.e.fire('internalUpdate');
|
|
148
|
+
j.e.fire('updateToolbar');
|
|
149
|
+
}
|
|
150
|
+
__wrap(image) {
|
|
151
|
+
var _a;
|
|
152
|
+
const { j } = this;
|
|
153
|
+
const { wrapper: wrapperPart, inner, caption: captionPart } = j.o.imageCaption;
|
|
154
|
+
const link = Dom.closest(image, 'a', j.editor);
|
|
155
|
+
const target = link &&
|
|
156
|
+
!((_a = link.textContent) === null || _a === void 0 ? void 0 : _a.trim()) &&
|
|
157
|
+
link.getElementsByTagName('img').length === 1
|
|
158
|
+
? link
|
|
159
|
+
: image;
|
|
160
|
+
const attributes = [attr(image, 'style'), attr(image, 'class')];
|
|
161
|
+
const place = target.parentNode;
|
|
162
|
+
const width = cssInline(image, 'width') ||
|
|
163
|
+
pixels(attr(image, 'width')) ||
|
|
164
|
+
(image.offsetWidth ? `${image.offsetWidth}px` : '');
|
|
165
|
+
const classes = getAlignClasses(j, image);
|
|
166
|
+
const align = getHAlign(image, classes);
|
|
167
|
+
clearHAlign(image, classes);
|
|
168
|
+
const wrapper = this.__create(wrapperPart);
|
|
169
|
+
const box = inner ? this.__create(inner) : wrapper;
|
|
170
|
+
const caption = this.__create(captionPart);
|
|
171
|
+
caption.appendChild(j.createInside.element('br'));
|
|
172
|
+
const split = this.__insert(wrapper, target);
|
|
173
|
+
if (box !== wrapper) {
|
|
174
|
+
Dom.append(wrapper, box);
|
|
175
|
+
}
|
|
176
|
+
Dom.append(box, [target, caption]);
|
|
177
|
+
moveMargins(image, wrapper);
|
|
178
|
+
// The wrapper takes the image's width, and the image fills it, so the
|
|
179
|
+
// caption wraps under the image
|
|
180
|
+
if (width) {
|
|
181
|
+
css(wrapper, 'width', width);
|
|
182
|
+
css(image, 'width', '100%');
|
|
183
|
+
}
|
|
184
|
+
hAlignElement(wrapper, align, getAlignClasses(j, wrapper));
|
|
185
|
+
this.__mark(wrapper);
|
|
186
|
+
return {
|
|
187
|
+
caption,
|
|
188
|
+
wrapper,
|
|
189
|
+
image,
|
|
190
|
+
target,
|
|
191
|
+
place,
|
|
192
|
+
split,
|
|
193
|
+
attributes,
|
|
194
|
+
parent: wrapper.parentNode,
|
|
195
|
+
previous: wrapper.previousSibling,
|
|
196
|
+
next: wrapper.nextSibling,
|
|
197
|
+
shape: shape(wrapper, image)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Puts the image back as it was before its caption: in the line the
|
|
202
|
+
* caption split, and with its own alignment, margins and width. The image
|
|
203
|
+
* goes into the part of the line holding the caret, so the caret stays
|
|
204
|
+
*/
|
|
205
|
+
__restore(fresh) {
|
|
206
|
+
var _a, _b;
|
|
207
|
+
const { wrapper, image, target, place, split, attributes } = fresh;
|
|
208
|
+
if (!split) {
|
|
209
|
+
Dom.before(wrapper, target);
|
|
210
|
+
}
|
|
211
|
+
else if (!split.head && !split.tail) {
|
|
212
|
+
Dom.append(place, target);
|
|
213
|
+
Dom.before(wrapper, split.block);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const { sel } = this.j.s;
|
|
217
|
+
const caret = (sel === null || sel === void 0 ? void 0 : sel.rangeCount)
|
|
218
|
+
? sel.getRangeAt(0).startContainer
|
|
219
|
+
: null;
|
|
220
|
+
const { head, tail } = split;
|
|
221
|
+
if (head && !(tail && caret && Dom.isOrContains(tail, caret))) {
|
|
222
|
+
Dom.append(head, [target, ...toArray((_a = tail === null || tail === void 0 ? void 0 : tail.childNodes) !== null && _a !== void 0 ? _a : [])]);
|
|
223
|
+
Dom.safeRemove(tail);
|
|
224
|
+
}
|
|
225
|
+
else if (tail) {
|
|
226
|
+
const first = tail.firstChild;
|
|
227
|
+
[...toArray((_b = head === null || head === void 0 ? void 0 : head.childNodes) !== null && _b !== void 0 ? _b : []), target].forEach(node => tail.insertBefore(node, first));
|
|
228
|
+
Dom.safeRemove(head);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
Dom.safeRemove(wrapper);
|
|
232
|
+
attr(image, { style: attributes[0], class: attributes[1] });
|
|
233
|
+
}
|
|
234
|
+
__uncaption(wrapper, image) {
|
|
235
|
+
var _a;
|
|
236
|
+
const { j } = this;
|
|
237
|
+
// Read while the wrapper is still one, with its caption
|
|
238
|
+
const align = getHAlign(wrapper, getAlignClasses(j, wrapper));
|
|
239
|
+
const width = cssInline(wrapper, 'width');
|
|
240
|
+
Dom.safeRemove(getImageCaption(j, wrapper));
|
|
241
|
+
const target = (_a = Dom.closest(image, 'a', wrapper)) !== null && _a !== void 0 ? _a : image;
|
|
242
|
+
moveMargins(wrapper, image);
|
|
243
|
+
if (width) {
|
|
244
|
+
css(image, 'width', width);
|
|
245
|
+
}
|
|
246
|
+
hAlignElement(image, align, getAlignClasses(j, image));
|
|
247
|
+
// A block wrapper leaves the image in a paragraph of its own
|
|
248
|
+
if (Dom.isBlock(wrapper) &&
|
|
249
|
+
wrapper.parentNode === j.editor &&
|
|
250
|
+
j.o.enter.toLowerCase() !== consts.BR) {
|
|
251
|
+
const line = j.createInside.element(j.o.enter);
|
|
252
|
+
Dom.before(wrapper, line);
|
|
253
|
+
Dom.append(line, target);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
Dom.before(wrapper, target);
|
|
257
|
+
}
|
|
258
|
+
Dom.safeRemove(wrapper);
|
|
259
|
+
}
|
|
260
|
+
__create({ tag, className }) {
|
|
261
|
+
return this.j.createInside.element(tag, className ? { class: className } : {});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Puts `wrapper` where `target` is. A block can't go in a paragraph, so the
|
|
265
|
+
* paragraph is split round it, and a part left empty goes
|
|
266
|
+
*/
|
|
267
|
+
__insert(wrapper, target) {
|
|
268
|
+
const { j } = this;
|
|
269
|
+
const block = Dom.isBlock(wrapper)
|
|
270
|
+
? Dom.closest(target, Dom.isBlock, j.editor)
|
|
271
|
+
: null;
|
|
272
|
+
if (!block || !TEXT_BLOCK.test(block.nodeName)) {
|
|
273
|
+
Dom.before(target, wrapper);
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
const range = j.ed.createRange();
|
|
277
|
+
range.setStartBefore(block);
|
|
278
|
+
range.setEndBefore(target);
|
|
279
|
+
const start = range.extractContents();
|
|
280
|
+
range.setStartAfter(target);
|
|
281
|
+
range.setEndAfter(block);
|
|
282
|
+
const end = range.extractContents();
|
|
283
|
+
const [head, tail] = [start, end].map((part, index) => {
|
|
284
|
+
const line = part.firstChild;
|
|
285
|
+
if (!line || Dom.isEmpty(line)) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
call(index ? Dom.after : Dom.before, block, line);
|
|
289
|
+
return line;
|
|
290
|
+
});
|
|
291
|
+
Dom.before(block, wrapper);
|
|
292
|
+
Dom.safeRemove(block);
|
|
293
|
+
return { block, head, tail };
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The wrapper can't be edited, apart from its caption, so typing can't
|
|
297
|
+
* land between the image and the caption
|
|
298
|
+
*/
|
|
299
|
+
__mark(wrapper) {
|
|
300
|
+
attr(wrapper, 'contenteditable', false);
|
|
301
|
+
const caption = getImageCaption(this.j, wrapper);
|
|
302
|
+
if (caption) {
|
|
303
|
+
attr(caption, 'contenteditable', true);
|
|
304
|
+
this.__placeholder(caption);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
__placeholder(caption) {
|
|
308
|
+
const text = Dom.isEmpty(caption) ? this.j.i18n('Caption') : null;
|
|
309
|
+
if (attr(caption, PLACEHOLDER) !== text) {
|
|
310
|
+
attr(caption, PLACEHOLDER, text);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
onChange() {
|
|
314
|
+
const { j } = this;
|
|
315
|
+
if (j.isInDestruct || j.getMode() === consts.MODE_SOURCE) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
toArray(j.editor.getElementsByTagName(j.o.imageCaption.wrapper.tag)).forEach(elm => {
|
|
319
|
+
if (Dom.isHTMLElement(elm) && getCaptionedImage(j, elm)) {
|
|
320
|
+
this.__mark(elm);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The placeholder goes with the first letter typed or pasted, and comes
|
|
326
|
+
* back when the last is deleted
|
|
327
|
+
*/
|
|
328
|
+
onInput() {
|
|
329
|
+
const caption = this.__caretCaption();
|
|
330
|
+
if (caption) {
|
|
331
|
+
this.__placeholder(caption);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* The editor's own attributes stay out of the value, as the caption would
|
|
336
|
+
* be editable on the page. So does a caption given and left blank, as
|
|
337
|
+
* leaving it takes it off, so saving at once keeps the image as it was
|
|
338
|
+
*/
|
|
339
|
+
onAfterGetValueFromEditor(data) {
|
|
340
|
+
if (!data.value.includes('contenteditable')) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const { j } = this;
|
|
344
|
+
const template = j.c.element('template');
|
|
345
|
+
template.innerHTML = data.value;
|
|
346
|
+
const wrappers = (root) => toArray(root.querySelectorAll(j.o.imageCaption.wrapper.tag)).filter(wrapper => getCaptionedImage(j, wrapper));
|
|
347
|
+
const copies = wrappers(template.content);
|
|
348
|
+
const fresh = this.__fresh && this.__freshCaption(this.__fresh.wrapper);
|
|
349
|
+
const copy = fresh && copies[wrappers(j.editor).indexOf(fresh.wrapper)];
|
|
350
|
+
const placed = fresh && copy && placedIn(j, fresh, copy);
|
|
351
|
+
let changed = false;
|
|
352
|
+
if (placed) {
|
|
353
|
+
this.__restore(placed);
|
|
354
|
+
changed = true;
|
|
355
|
+
}
|
|
356
|
+
copies.forEach(wrapper => {
|
|
357
|
+
[wrapper, getImageCaption(j, wrapper)].forEach(elm => ['contenteditable', PLACEHOLDER].forEach(name => {
|
|
358
|
+
if (elm === null || elm === void 0 ? void 0 : elm.hasAttribute(name)) {
|
|
359
|
+
elm.removeAttribute(name);
|
|
360
|
+
changed = true;
|
|
361
|
+
}
|
|
362
|
+
}));
|
|
363
|
+
});
|
|
364
|
+
if (changed) {
|
|
365
|
+
data.value = template.innerHTML;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
onChangePlace() {
|
|
369
|
+
const { j } = this;
|
|
370
|
+
// Captured, to come first: the editor's own `focusout` listener can stop
|
|
371
|
+
// the event as it fires `blur`, and an image's `mousedown` listener
|
|
372
|
+
// moves the focus before the press reaches the editor
|
|
373
|
+
j.e
|
|
374
|
+
.off([j.editor, j.ow, j.ew], '.imageCaption')
|
|
375
|
+
.on(j.editor, 'focusout.imageCaption', this.__onFocusOut, {
|
|
376
|
+
capture: true
|
|
377
|
+
})
|
|
378
|
+
.on(j.editor, 'mousedown.imageCaption', this.__onMouseDown, {
|
|
379
|
+
capture: true
|
|
380
|
+
})
|
|
381
|
+
.on([j.ow, j.ew], 'mouseup.imageCaption', this.__onMouseUp);
|
|
382
|
+
}
|
|
383
|
+
__onMouseDown(event) {
|
|
384
|
+
this.__press = event.target;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* A caption left blank goes when the focus leaves it. That's checked once
|
|
388
|
+
* the focus has landed, as switching windows or opening the editor's own
|
|
389
|
+
* popups keeps it, and once a press that took the focus is over, as the
|
|
390
|
+
* browsers fire no click when its target moves
|
|
391
|
+
*/
|
|
392
|
+
__onFocusOut(event) {
|
|
393
|
+
const caption = event.target;
|
|
394
|
+
if (getImageCaption(this.j, getCaptionWrapper(this.j, caption)) !==
|
|
395
|
+
caption) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (this.__press) {
|
|
399
|
+
this.__afterPress.push(caption);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
this.__dropBlank(caption, null);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
__onMouseUp() {
|
|
406
|
+
const press = this.__press;
|
|
407
|
+
this.__press = null;
|
|
408
|
+
this.__afterPress
|
|
409
|
+
.splice(0)
|
|
410
|
+
.forEach(caption => this.__dropBlank(caption, press));
|
|
411
|
+
}
|
|
412
|
+
__dropBlank(caption, press) {
|
|
413
|
+
// `async.setTimeout` runs a timeout of 0 at once
|
|
414
|
+
this.j.async.setTimeout(() => {
|
|
415
|
+
const { j } = this;
|
|
416
|
+
const wrapper = getCaptionWrapper(j, caption);
|
|
417
|
+
const image = getCaptionedImage(j, wrapper);
|
|
418
|
+
if (!wrapper ||
|
|
419
|
+
!image ||
|
|
420
|
+
!Dom.isEmpty(caption) ||
|
|
421
|
+
this.__keepsFocus(caption)) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const clicked = Boolean(press && Dom.isOrContains(wrapper, press));
|
|
425
|
+
const fresh = this.__freshCaption(wrapper);
|
|
426
|
+
this.__unrecorded(() => fresh ? this.__restore(fresh) : this.__uncaption(wrapper, image));
|
|
427
|
+
// The click opened the image's popup below the caption, so it
|
|
428
|
+
// opens again below the image, as after the popup's Caption button
|
|
429
|
+
if (clicked) {
|
|
430
|
+
j.e.fire('recalcPositionPopup');
|
|
431
|
+
j.e.fire('closeAllPopups');
|
|
432
|
+
}
|
|
433
|
+
}, 1);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* The caption has the focus, or had it when another window took it, or
|
|
437
|
+
* the editor's own popups and dialogs have it, as the link form
|
|
438
|
+
*/
|
|
439
|
+
__keepsFocus(caption) {
|
|
440
|
+
const { j } = this;
|
|
441
|
+
const doc = caption.ownerDocument;
|
|
442
|
+
if (doc.activeElement === caption &&
|
|
443
|
+
(doc.hasFocus() || !j.od.hasFocus())) {
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
const active = j.od.activeElement;
|
|
447
|
+
return Boolean(active &&
|
|
448
|
+
active !== j.iframe &&
|
|
449
|
+
!Dom.isOrContains(j.editor, active) &&
|
|
450
|
+
(Dom.isOrContains(j.container, active) ||
|
|
451
|
+
Dom.closest(active, elm => Dom.isElement(elm) &&
|
|
452
|
+
attr(elm, 'data-editor_id') === j.id, j.od.body)));
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* The caption the caret is in
|
|
456
|
+
*/
|
|
457
|
+
__caretCaption() {
|
|
458
|
+
const { s } = this.j;
|
|
459
|
+
if (!s.isInsideArea) {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
const node = s.range.startContainer;
|
|
463
|
+
const caption = getImageCaption(this.j, getCaptionWrapper(this.j, node));
|
|
464
|
+
return caption && Dom.isOrContains(caption, node) ? caption : null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Enter in a caption starts a line after the image, and Shift+Enter
|
|
468
|
+
* breaks the caption's line, as everywhere
|
|
469
|
+
*/
|
|
470
|
+
onBeforeEnter(event) {
|
|
471
|
+
const caption = (event === null || event === void 0 ? void 0 : event.shiftKey) ? null : this.__caretCaption();
|
|
472
|
+
const wrapper = getCaptionWrapper(this.j, caption);
|
|
473
|
+
if (!wrapper) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const { j } = this;
|
|
477
|
+
this.__focusEditor();
|
|
478
|
+
// The Enter plugin breaks the line after an inline wrapper
|
|
479
|
+
if (!Dom.isBlock(wrapper)) {
|
|
480
|
+
j.s.setCursorAfter(wrapper);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const line = this.__line();
|
|
484
|
+
Dom.after(wrapper, line);
|
|
485
|
+
j.s.setCursorIn(line);
|
|
486
|
+
j.synchronizeValues();
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* The caption keeps the focus, as an editable element of its own, and
|
|
491
|
+
* would take the caret back, so the editor takes it before the caret
|
|
492
|
+
* leaves the caption
|
|
493
|
+
*/
|
|
494
|
+
__focusEditor() {
|
|
495
|
+
this.j.editor.focus({ preventScroll: true });
|
|
496
|
+
}
|
|
497
|
+
__line() {
|
|
498
|
+
const { j } = this;
|
|
499
|
+
const line = j.createInside.element(j.o.enter);
|
|
500
|
+
if (!Dom.isTag(line, 'br')) {
|
|
501
|
+
Dom.append(line, j.createInside.element('br'));
|
|
502
|
+
}
|
|
503
|
+
return line;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* A caption holds text. An image, a table or a block put in it would end
|
|
507
|
+
* the captioned image, so it goes after the image, as Enter would
|
|
508
|
+
*/
|
|
509
|
+
onBeforeInsertNode(node) {
|
|
510
|
+
const wrapper = getCaptionWrapper(this.j, this.__caretCaption());
|
|
511
|
+
if (!wrapper || !holdsMoreThanText(node)) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const { j } = this;
|
|
515
|
+
this.__focusEditor();
|
|
516
|
+
if (!Dom.isBlock(wrapper)) {
|
|
517
|
+
j.s.setCursorAfter(wrapper);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const line = this.__line();
|
|
521
|
+
Dom.after(wrapper, line);
|
|
522
|
+
j.s.setCursorIn(line);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* A selected captioned image goes as an image on a line of its own does,
|
|
526
|
+
* leaving the line empty, rather than joining the lines either side
|
|
527
|
+
*/
|
|
528
|
+
onBeforeCommandDelete() {
|
|
529
|
+
const wrapper = this.__selectedWrapper();
|
|
530
|
+
if (!wrapper || !Dom.isBlock(wrapper)) {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
const line = this.__line();
|
|
534
|
+
Dom.before(wrapper, line);
|
|
535
|
+
Dom.safeRemove(wrapper);
|
|
536
|
+
this.j.s.setCursorIn(line);
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* The captioned image the selection holds, as a click on the image selects
|
|
541
|
+
*/
|
|
542
|
+
__selectedWrapper() {
|
|
543
|
+
const { s } = this.j;
|
|
544
|
+
if (!s.isInsideArea || s.isCollapsed()) {
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
const { startContainer, startOffset, endContainer, endOffset } = s.range;
|
|
548
|
+
const node = startContainer.childNodes[startOffset];
|
|
549
|
+
return startContainer === endContainer &&
|
|
550
|
+
endOffset === startOffset + 1 &&
|
|
551
|
+
getCaptionedImage(this.j, node)
|
|
552
|
+
? node
|
|
553
|
+
: null;
|
|
554
|
+
}
|
|
555
|
+
onKeyDown(event) {
|
|
556
|
+
var _a;
|
|
557
|
+
this.__arrow = null;
|
|
558
|
+
// Typing replaces a selected captioned image, on the line it leaves
|
|
559
|
+
if (((_a = event.key) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
560
|
+
!event.ctrlKey &&
|
|
561
|
+
!event.metaKey &&
|
|
562
|
+
this.__selectedWrapper()) {
|
|
563
|
+
this.j.execCommand('Delete');
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (!ARROWS.has(event.key) ||
|
|
567
|
+
event.shiftKey ||
|
|
568
|
+
event.altKey ||
|
|
569
|
+
event.ctrlKey ||
|
|
570
|
+
event.metaKey ||
|
|
571
|
+
!this.j.s.isCollapsed()) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const caption = this.__caretCaption();
|
|
575
|
+
if (caption) {
|
|
576
|
+
this.__arrow = {
|
|
577
|
+
key: event.key,
|
|
578
|
+
range: this.j.s.range.cloneRange(),
|
|
579
|
+
caption
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* An arrow key that couldn't move the caret in the caption takes it out,
|
|
585
|
+
* past the image, as the caption is an editable element of its own
|
|
586
|
+
*/
|
|
587
|
+
onKeyUp(event) {
|
|
588
|
+
const arrow = this.__arrow;
|
|
589
|
+
this.__arrow = null;
|
|
590
|
+
if (!arrow || event.key !== arrow.key || isMoved(this.j, arrow.range)) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const wrapper = getCaptionWrapper(this.j, arrow.caption);
|
|
594
|
+
if (!wrapper) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
const forward = arrow.key === consts.KEY_DOWN || arrow.key === consts.KEY_RIGHT;
|
|
598
|
+
const { s } = this.j;
|
|
599
|
+
this.__focusEditor();
|
|
600
|
+
if (!Dom.isBlock(wrapper)) {
|
|
601
|
+
if (forward) {
|
|
602
|
+
s.setCursorAfter(wrapper);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
s.setCursorBefore(wrapper);
|
|
606
|
+
}
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const sibling = Dom.findNotEmptySibling(wrapper, !forward);
|
|
610
|
+
if (Dom.isHTMLElement(sibling)) {
|
|
611
|
+
s.setCursorIn(sibling, forward);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (Dom.isText(sibling)) {
|
|
615
|
+
if (forward) {
|
|
616
|
+
s.setCursorBefore(sibling);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
s.setCursorAfter(sibling);
|
|
620
|
+
}
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const line = this.__line();
|
|
624
|
+
call(forward ? Dom.after : Dom.before, wrapper, line);
|
|
625
|
+
s.setCursorIn(line);
|
|
626
|
+
this.j.synchronizeValues();
|
|
627
|
+
}
|
|
628
|
+
onBeforeCommand(command) {
|
|
629
|
+
const name = command.toLowerCase();
|
|
630
|
+
if (BLOCK_COMMANDS.has(name) && this.__caretCaption()) {
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
// A caption given and left blank was never a step, so Undo takes it off
|
|
634
|
+
const fresh = name === 'undo' && this.__fresh
|
|
635
|
+
? this.__freshCaption(this.__fresh.wrapper)
|
|
636
|
+
: null;
|
|
637
|
+
if (fresh) {
|
|
638
|
+
this.__unrecorded(() => {
|
|
639
|
+
this.__restore(fresh);
|
|
640
|
+
this.j.history.snapshot.restore(fresh.before);
|
|
641
|
+
});
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Select all in a caption selects the caption, as the caption is an
|
|
647
|
+
* editable element of its own
|
|
648
|
+
*/
|
|
649
|
+
__onSelectAll() {
|
|
650
|
+
const caption = this.__caretCaption();
|
|
651
|
+
if (caption) {
|
|
652
|
+
this.j.e.stopPropagation('beforeCommandSelectall');
|
|
653
|
+
this.j.s.select(caption, true);
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
/** @override */
|
|
658
|
+
beforeDestruct(jodit) {
|
|
659
|
+
jodit.e
|
|
660
|
+
.off('beforeCommandSelectall', this.__onSelectAll)
|
|
661
|
+
.off([jodit.editor, jodit.ow, jodit.ew], '.imageCaption');
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
__decorate([
|
|
665
|
+
watch(':toggleImageCaption')
|
|
666
|
+
], imageCaption.prototype, "onToggleImageCaption", null);
|
|
667
|
+
__decorate([
|
|
668
|
+
watch([':change', ':afterInit', ':afterSetMode', ':changePlace']),
|
|
669
|
+
debounce()
|
|
670
|
+
], imageCaption.prototype, "onChange", null);
|
|
671
|
+
__decorate([
|
|
672
|
+
watch([':input', ':keyup', ':afterPaste'])
|
|
673
|
+
], imageCaption.prototype, "onInput", null);
|
|
674
|
+
__decorate([
|
|
675
|
+
watch(':afterGetValueFromEditor')
|
|
676
|
+
], imageCaption.prototype, "onAfterGetValueFromEditor", null);
|
|
677
|
+
__decorate([
|
|
678
|
+
watch(':changePlace')
|
|
679
|
+
], imageCaption.prototype, "onChangePlace", null);
|
|
680
|
+
__decorate([
|
|
681
|
+
autobind
|
|
682
|
+
], imageCaption.prototype, "__onMouseDown", null);
|
|
683
|
+
__decorate([
|
|
684
|
+
autobind
|
|
685
|
+
], imageCaption.prototype, "__onFocusOut", null);
|
|
686
|
+
__decorate([
|
|
687
|
+
autobind
|
|
688
|
+
], imageCaption.prototype, "__onMouseUp", null);
|
|
689
|
+
__decorate([
|
|
690
|
+
watch(':beforeEnter')
|
|
691
|
+
], imageCaption.prototype, "onBeforeEnter", null);
|
|
692
|
+
__decorate([
|
|
693
|
+
watch(':beforeInsertNode')
|
|
694
|
+
], imageCaption.prototype, "onBeforeInsertNode", null);
|
|
695
|
+
__decorate([
|
|
696
|
+
watch(':beforeCommandDelete')
|
|
697
|
+
], imageCaption.prototype, "onBeforeCommandDelete", null);
|
|
698
|
+
__decorate([
|
|
699
|
+
watch(':keydown')
|
|
700
|
+
], imageCaption.prototype, "onKeyDown", null);
|
|
701
|
+
__decorate([
|
|
702
|
+
watch(':keyup')
|
|
703
|
+
], imageCaption.prototype, "onKeyUp", null);
|
|
704
|
+
__decorate([
|
|
705
|
+
watch(':beforeCommand')
|
|
706
|
+
], imageCaption.prototype, "onBeforeCommand", null);
|
|
707
|
+
__decorate([
|
|
708
|
+
autobind
|
|
709
|
+
], imageCaption.prototype, "__onSelectAll", null);
|
|
710
|
+
/**
|
|
711
|
+
* `fresh` in `wrapper`, a copy of its wrapper, with the lines round it, made
|
|
712
|
+
* from the editor's value
|
|
713
|
+
*/
|
|
714
|
+
function placedIn(jodit, fresh, wrapper) {
|
|
715
|
+
var _a;
|
|
716
|
+
const image = getCaptionedImage(jodit, wrapper);
|
|
717
|
+
const { split } = fresh;
|
|
718
|
+
if (!image) {
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
const placed = {
|
|
722
|
+
wrapper,
|
|
723
|
+
image,
|
|
724
|
+
target: (_a = Dom.closest(image, 'a', wrapper)) !== null && _a !== void 0 ? _a : image,
|
|
725
|
+
place: fresh.place,
|
|
726
|
+
split: null,
|
|
727
|
+
attributes: fresh.attributes
|
|
728
|
+
};
|
|
729
|
+
if (split) {
|
|
730
|
+
const head = split.head ? wrapper.previousSibling : null;
|
|
731
|
+
const tail = split.tail ? wrapper.nextSibling : null;
|
|
732
|
+
if ((split.head && !Dom.isHTMLElement(head)) ||
|
|
733
|
+
(split.tail && !Dom.isHTMLElement(tail))) {
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
const block = split.block.cloneNode(true);
|
|
737
|
+
placed.split = {
|
|
738
|
+
block,
|
|
739
|
+
head: head,
|
|
740
|
+
tail: tail
|
|
741
|
+
};
|
|
742
|
+
placed.place = counterpart(split.block, fresh.place, block);
|
|
743
|
+
}
|
|
744
|
+
return placed;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* The node in `copy`, a clone of `root`, where `node` is in `root`
|
|
748
|
+
*/
|
|
749
|
+
function counterpart(root, node, copy) {
|
|
750
|
+
const path = [];
|
|
751
|
+
for (let elm = node; elm !== root && elm.parentNode; elm = elm.parentNode) {
|
|
752
|
+
path.unshift(toArray(elm.parentNode.childNodes).indexOf(elm));
|
|
753
|
+
}
|
|
754
|
+
return path.reduce((elm, index) => elm.childNodes[index], copy);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* The attributes of a caption's wrapper and image that the image's
|
|
758
|
+
* alignment, margins and size are in
|
|
759
|
+
*/
|
|
760
|
+
function shape(wrapper, image) {
|
|
761
|
+
return [wrapper, image]
|
|
762
|
+
.flatMap(elm => [attr(elm, 'style'), attr(elm, 'class')])
|
|
763
|
+
.join('|');
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* The node is, or holds, more than text and inline formatting: an image, a
|
|
767
|
+
* table, a rule or another block
|
|
768
|
+
*/
|
|
769
|
+
function holdsMoreThanText(node) {
|
|
770
|
+
if (!Dom.isElement(node) && !Dom.isFragment(node)) {
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
return [node, ...toArray(node.querySelectorAll('*'))].some(elm => Dom.isElement(elm) &&
|
|
774
|
+
(Dom.isBlock(elm) ||
|
|
775
|
+
consts.NO_EMPTY_TAGS.has(elm.nodeName.toLowerCase())));
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* A `width` attribute's value as a CSS width
|
|
779
|
+
*/
|
|
780
|
+
function pixels(value) {
|
|
781
|
+
if (!value) {
|
|
782
|
+
return '';
|
|
783
|
+
}
|
|
784
|
+
return isNumeric(value) ? `${value}px` : value;
|
|
785
|
+
}
|
|
786
|
+
function moveMargins(from, to) {
|
|
787
|
+
var _a;
|
|
788
|
+
MARGINS.forEach(side => {
|
|
789
|
+
const value = cssInline(from, side);
|
|
790
|
+
if (value) {
|
|
791
|
+
css(to, side, value);
|
|
792
|
+
css(from, side, '');
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
if (!((_a = attr(from, 'style')) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
796
|
+
attr(from, 'style', null);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
pluginSystem.add('imageCaption', imageCaption);
|