File size: 16,671 Bytes
bb7f1f4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | /**
* TinyMCE version 6.4.1 (2023-03-29)
*/
(function () {
'use strict';
const Cell = initial => {
let value = initial;
const get = () => {
return value;
};
const set = v => {
value = v;
};
return {
get,
set
};
};
var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
const get$2 = toggleState => {
const isEnabled = () => {
return toggleState.get();
};
return { isEnabled };
};
const fireVisualChars = (editor, state) => {
return editor.dispatch('VisualChars', { state });
};
const hasProto = (v, constructor, predicate) => {
var _a;
if (predicate(v, constructor.prototype)) {
return true;
} else {
return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
}
};
const typeOf = x => {
const t = typeof x;
if (x === null) {
return 'null';
} else if (t === 'object' && Array.isArray(x)) {
return 'array';
} else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
return 'string';
} else {
return t;
}
};
const isType$1 = type => value => typeOf(value) === type;
const isSimpleType = type => value => typeof value === type;
const eq = t => a => t === a;
const isString = isType$1('string');
const isObject = isType$1('object');
const isNull = eq(null);
const isBoolean = isSimpleType('boolean');
const isNullable = a => a === null || a === undefined;
const isNonNullable = a => !isNullable(a);
const isNumber = isSimpleType('number');
class Optional {
constructor(tag, value) {
this.tag = tag;
this.value = value;
}
static some(value) {
return new Optional(true, value);
}
static none() {
return Optional.singletonNone;
}
fold(onNone, onSome) {
if (this.tag) {
return onSome(this.value);
} else {
return onNone();
}
}
isSome() {
return this.tag;
}
isNone() {
return !this.tag;
}
map(mapper) {
if (this.tag) {
return Optional.some(mapper(this.value));
} else {
return Optional.none();
}
}
bind(binder) {
if (this.tag) {
return binder(this.value);
} else {
return Optional.none();
}
}
exists(predicate) {
return this.tag && predicate(this.value);
}
forall(predicate) {
return !this.tag || predicate(this.value);
}
filter(predicate) {
if (!this.tag || predicate(this.value)) {
return this;
} else {
return Optional.none();
}
}
getOr(replacement) {
return this.tag ? this.value : replacement;
}
or(replacement) {
return this.tag ? this : replacement;
}
getOrThunk(thunk) {
return this.tag ? this.value : thunk();
}
orThunk(thunk) {
return this.tag ? this : thunk();
}
getOrDie(message) {
if (!this.tag) {
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
} else {
return this.value;
}
}
static from(value) {
return isNonNullable(value) ? Optional.some(value) : Optional.none();
}
getOrNull() {
return this.tag ? this.value : null;
}
getOrUndefined() {
return this.value;
}
each(worker) {
if (this.tag) {
worker(this.value);
}
}
toArray() {
return this.tag ? [this.value] : [];
}
toString() {
return this.tag ? `some(${ this.value })` : 'none()';
}
}
Optional.singletonNone = new Optional(false);
const map = (xs, f) => {
const len = xs.length;
const r = new Array(len);
for (let i = 0; i < len; i++) {
const x = xs[i];
r[i] = f(x, i);
}
return r;
};
const each$1 = (xs, f) => {
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
f(x, i);
}
};
const filter = (xs, pred) => {
const r = [];
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
if (pred(x, i)) {
r.push(x);
}
}
return r;
};
const keys = Object.keys;
const each = (obj, f) => {
const props = keys(obj);
for (let k = 0, len = props.length; k < len; k++) {
const i = props[k];
const x = obj[i];
f(x, i);
}
};
const Global = typeof window !== 'undefined' ? window : Function('return this;')();
const path = (parts, scope) => {
let o = scope !== undefined && scope !== null ? scope : Global;
for (let i = 0; i < parts.length && o !== undefined && o !== null; ++i) {
o = o[parts[i]];
}
return o;
};
const resolve = (p, scope) => {
const parts = p.split('.');
return path(parts, scope);
};
const unsafe = (name, scope) => {
return resolve(name, scope);
};
const getOrDie = (name, scope) => {
const actual = unsafe(name, scope);
if (actual === undefined || actual === null) {
throw new Error(name + ' not available on this browser');
}
return actual;
};
const getPrototypeOf = Object.getPrototypeOf;
const sandHTMLElement = scope => {
return getOrDie('HTMLElement', scope);
};
const isPrototypeOf = x => {
const scope = resolve('ownerDocument.defaultView', x);
return isObject(x) && (sandHTMLElement(scope).prototype.isPrototypeOf(x) || /^HTML\w*Element$/.test(getPrototypeOf(x).constructor.name));
};
const ELEMENT = 1;
const TEXT = 3;
const type = element => element.dom.nodeType;
const value = element => element.dom.nodeValue;
const isType = t => element => type(element) === t;
const isHTMLElement = element => isElement(element) && isPrototypeOf(element.dom);
const isElement = isType(ELEMENT);
const isText = isType(TEXT);
const rawSet = (dom, key, value) => {
if (isString(value) || isBoolean(value) || isNumber(value)) {
dom.setAttribute(key, value + '');
} else {
console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
throw new Error('Attribute value was not simple');
}
};
const set = (element, key, value) => {
rawSet(element.dom, key, value);
};
const get$1 = (element, key) => {
const v = element.dom.getAttribute(key);
return v === null ? undefined : v;
};
const remove$3 = (element, key) => {
element.dom.removeAttribute(key);
};
const read = (element, attr) => {
const value = get$1(element, attr);
return value === undefined || value === '' ? [] : value.split(' ');
};
const add$2 = (element, attr, id) => {
const old = read(element, attr);
const nu = old.concat([id]);
set(element, attr, nu.join(' '));
return true;
};
const remove$2 = (element, attr, id) => {
const nu = filter(read(element, attr), v => v !== id);
if (nu.length > 0) {
set(element, attr, nu.join(' '));
} else {
remove$3(element, attr);
}
return false;
};
const supports = element => element.dom.classList !== undefined;
const get = element => read(element, 'class');
const add$1 = (element, clazz) => add$2(element, 'class', clazz);
const remove$1 = (element, clazz) => remove$2(element, 'class', clazz);
const add = (element, clazz) => {
if (supports(element)) {
element.dom.classList.add(clazz);
} else {
add$1(element, clazz);
}
};
const cleanClass = element => {
const classList = supports(element) ? element.dom.classList : get(element);
if (classList.length === 0) {
remove$3(element, 'class');
}
};
const remove = (element, clazz) => {
if (supports(element)) {
const classList = element.dom.classList;
classList.remove(clazz);
} else {
remove$1(element, clazz);
}
cleanClass(element);
};
const fromHtml = (html, scope) => {
const doc = scope || document;
const div = doc.createElement('div');
div.innerHTML = html;
if (!div.hasChildNodes() || div.childNodes.length > 1) {
const message = 'HTML does not have a single root node';
console.error(message, html);
throw new Error(message);
}
return fromDom(div.childNodes[0]);
};
const fromTag = (tag, scope) => {
const doc = scope || document;
const node = doc.createElement(tag);
return fromDom(node);
};
const fromText = (text, scope) => {
const doc = scope || document;
const node = doc.createTextNode(text);
return fromDom(node);
};
const fromDom = node => {
if (node === null || node === undefined) {
throw new Error('Node cannot be null or undefined');
}
return { dom: node };
};
const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
const SugarElement = {
fromHtml,
fromTag,
fromText,
fromDom,
fromPoint
};
const charMap = {
'\xA0': 'nbsp',
'\xAD': 'shy'
};
const charMapToRegExp = (charMap, global) => {
let regExp = '';
each(charMap, (_value, key) => {
regExp += key;
});
return new RegExp('[' + regExp + ']', global ? 'g' : '');
};
const charMapToSelector = charMap => {
let selector = '';
each(charMap, value => {
if (selector) {
selector += ',';
}
selector += 'span.mce-' + value;
});
return selector;
};
const regExp = charMapToRegExp(charMap);
const regExpGlobal = charMapToRegExp(charMap, true);
const selector = charMapToSelector(charMap);
const nbspClass = 'mce-nbsp';
const getRaw = element => element.dom.contentEditable;
const wrapCharWithSpan = value => '<span data-mce-bogus="1" class="mce-' + charMap[value] + '">' + value + '</span>';
const isWrappedNbsp = node => node.nodeName.toLowerCase() === 'span' && node.classList.contains('mce-nbsp-wrap');
const isMatch = n => {
const value$1 = value(n);
return isText(n) && isString(value$1) && regExp.test(value$1);
};
const isContentEditableFalse = node => isHTMLElement(node) && getRaw(node) === 'false';
const isChildEditable = (node, currentState) => {
if (isHTMLElement(node) && !isWrappedNbsp(node.dom)) {
const value = getRaw(node);
if (value === 'true') {
return true;
} else if (value === 'false') {
return false;
}
}
return currentState;
};
const filterEditableDescendants = (scope, predicate, editable) => {
let result = [];
const dom = scope.dom;
const children = map(dom.childNodes, SugarElement.fromDom);
const isEditable = node => isWrappedNbsp(node.dom) || !isContentEditableFalse(node);
each$1(children, x => {
if (editable && isEditable(x) && predicate(x)) {
result = result.concat([x]);
}
result = result.concat(filterEditableDescendants(x, predicate, isChildEditable(x, editable)));
});
return result;
};
const findParentElm = (elm, rootElm) => {
while (elm.parentNode) {
if (elm.parentNode === rootElm) {
return rootElm;
}
elm = elm.parentNode;
}
return undefined;
};
const replaceWithSpans = text => text.replace(regExpGlobal, wrapCharWithSpan);
const show = (editor, rootElm) => {
const dom = editor.dom;
const nodeList = filterEditableDescendants(SugarElement.fromDom(rootElm), isMatch, editor.dom.isEditable(rootElm));
each$1(nodeList, n => {
var _a;
const parent = n.dom.parentNode;
if (isWrappedNbsp(parent)) {
add(SugarElement.fromDom(parent), nbspClass);
} else {
const withSpans = replaceWithSpans(dom.encode((_a = value(n)) !== null && _a !== void 0 ? _a : ''));
const div = dom.create('div', {}, withSpans);
let node;
while (node = div.lastChild) {
dom.insertAfter(node, n.dom);
}
editor.dom.remove(n.dom);
}
});
};
const hide = (editor, rootElm) => {
const nodeList = editor.dom.select(selector, rootElm);
each$1(nodeList, node => {
if (isWrappedNbsp(node)) {
remove(SugarElement.fromDom(node), nbspClass);
} else {
editor.dom.remove(node, true);
}
});
};
const toggle = editor => {
const body = editor.getBody();
const bookmark = editor.selection.getBookmark();
let parentNode = findParentElm(editor.selection.getNode(), body);
parentNode = parentNode !== undefined ? parentNode : body;
hide(editor, parentNode);
show(editor, parentNode);
editor.selection.moveToBookmark(bookmark);
};
const applyVisualChars = (editor, toggleState) => {
fireVisualChars(editor, toggleState.get());
const body = editor.getBody();
if (toggleState.get() === true) {
show(editor, body);
} else {
hide(editor, body);
}
};
const toggleVisualChars = (editor, toggleState) => {
toggleState.set(!toggleState.get());
const bookmark = editor.selection.getBookmark();
applyVisualChars(editor, toggleState);
editor.selection.moveToBookmark(bookmark);
};
const register$2 = (editor, toggleState) => {
editor.addCommand('mceVisualChars', () => {
toggleVisualChars(editor, toggleState);
});
};
const option = name => editor => editor.options.get(name);
const register$1 = editor => {
const registerOption = editor.options.register;
registerOption('visualchars_default_state', {
processor: 'boolean',
default: false
});
};
const isEnabledByDefault = option('visualchars_default_state');
const setup$1 = (editor, toggleState) => {
editor.on('init', () => {
applyVisualChars(editor, toggleState);
});
};
const first = (fn, rate) => {
let timer = null;
const cancel = () => {
if (!isNull(timer)) {
clearTimeout(timer);
timer = null;
}
};
const throttle = (...args) => {
if (isNull(timer)) {
timer = setTimeout(() => {
timer = null;
fn.apply(null, args);
}, rate);
}
};
return {
cancel,
throttle
};
};
const setup = (editor, toggleState) => {
const debouncedToggle = first(() => {
toggle(editor);
}, 300);
editor.on('keydown', e => {
if (toggleState.get() === true) {
e.keyCode === 13 ? toggle(editor) : debouncedToggle.throttle();
}
});
editor.on('remove', debouncedToggle.cancel);
};
const toggleActiveState = (editor, enabledStated) => api => {
api.setActive(enabledStated.get());
const editorEventCallback = e => api.setActive(e.state);
editor.on('VisualChars', editorEventCallback);
return () => editor.off('VisualChars', editorEventCallback);
};
const register = (editor, toggleState) => {
const onAction = () => editor.execCommand('mceVisualChars');
editor.ui.registry.addToggleButton('visualchars', {
tooltip: 'Show invisible characters',
icon: 'visualchars',
onAction,
onSetup: toggleActiveState(editor, toggleState)
});
editor.ui.registry.addToggleMenuItem('visualchars', {
text: 'Show invisible characters',
icon: 'visualchars',
onAction,
onSetup: toggleActiveState(editor, toggleState)
});
};
var Plugin = () => {
global.add('visualchars', editor => {
register$1(editor);
const toggleState = Cell(isEnabledByDefault(editor));
register$2(editor, toggleState);
register(editor, toggleState);
setup(editor, toggleState);
setup$1(editor, toggleState);
return get$2(toggleState);
});
};
Plugin();
})();
|