123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- /**
- * Copyright (c) Tiny Technologies, Inc. All rights reserved.
- * Licensed under the LGPL or a commercial license.
- * For LGPL see License.txt in the project root for license information.
- * For commercial licenses see https://www.tiny.cloud/
- *
- * Version: 5.2.0 (2020-02-13)
- */
- (function () {
- 'use strict';
- var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
- var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
- var applyListFormat = function (editor, listName, styleValue) {
- var cmd = listName === 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList';
- editor.execCommand(cmd, false, styleValue === false ? null : { 'list-style-type': styleValue });
- };
- var Actions = { applyListFormat: applyListFormat };
- var register = function (editor) {
- editor.addCommand('ApplyUnorderedListStyle', function (ui, value) {
- Actions.applyListFormat(editor, 'UL', value['list-style-type']);
- });
- editor.addCommand('ApplyOrderedListStyle', function (ui, value) {
- Actions.applyListFormat(editor, 'OL', value['list-style-type']);
- });
- };
- var Commands = { register: register };
- var getNumberStyles = function (editor) {
- var styles = editor.getParam('advlist_number_styles', 'default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman');
- return styles ? styles.split(/[ ,]/) : [];
- };
- var getBulletStyles = function (editor) {
- var styles = editor.getParam('advlist_bullet_styles', 'default,circle,square');
- return styles ? styles.split(/[ ,]/) : [];
- };
- var Settings = {
- getNumberStyles: getNumberStyles,
- getBulletStyles: getBulletStyles
- };
- var noop = function () {
- };
- var constant = function (value) {
- return function () {
- return value;
- };
- };
- var never = constant(false);
- var always = constant(true);
- var none = function () {
- return NONE;
- };
- var NONE = function () {
- var eq = function (o) {
- return o.isNone();
- };
- var call = function (thunk) {
- return thunk();
- };
- var id = function (n) {
- return n;
- };
- var me = {
- fold: function (n, s) {
- return n();
- },
- is: never,
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function (msg) {
- throw new Error(msg || 'error: getOrDie called on none.');
- },
- getOrNull: constant(null),
- getOrUndefined: constant(undefined),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: none,
- equals: eq,
- equals_: eq,
- toArray: function () {
- return [];
- },
- toString: constant('none()')
- };
- if (Object.freeze) {
- Object.freeze(me);
- }
- return me;
- }();
- var some = function (a) {
- var constant_a = constant(a);
- var self = function () {
- return me;
- };
- var bind = function (f) {
- return f(a);
- };
- var me = {
- fold: function (n, s) {
- return s(a);
- },
- is: function (v) {
- return a === v;
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function (f) {
- return some(f(a));
- },
- each: function (f) {
- f(a);
- },
- bind: bind,
- exists: bind,
- forall: bind,
- filter: function (f) {
- return f(a) ? me : NONE;
- },
- toArray: function () {
- return [a];
- },
- toString: function () {
- return 'some(' + a + ')';
- },
- equals: function (o) {
- return o.is(a);
- },
- equals_: function (o, elementEq) {
- return o.fold(never, function (b) {
- return elementEq(a, b);
- });
- }
- };
- return me;
- };
- var from = function (value) {
- return value === null || value === undefined ? NONE : some(value);
- };
- var Option = {
- some: some,
- none: none,
- from: from
- };
- var isChildOfBody = function (editor, elm) {
- return editor.$.contains(editor.getBody(), elm);
- };
- var isTableCellNode = function (node) {
- return node && /^(TH|TD)$/.test(node.nodeName);
- };
- var isListNode = function (editor) {
- return function (node) {
- return node && /^(OL|UL|DL)$/.test(node.nodeName) && isChildOfBody(editor, node);
- };
- };
- var getSelectedStyleType = function (editor) {
- var listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
- var style = editor.dom.getStyle(listElm, 'listStyleType');
- return Option.from(style);
- };
- var ListUtils = {
- isTableCellNode: isTableCellNode,
- isListNode: isListNode,
- getSelectedStyleType: getSelectedStyleType
- };
- var findIndex = function (list, predicate) {
- for (var index = 0; index < list.length; index++) {
- var element = list[index];
- if (predicate(element)) {
- return index;
- }
- }
- return -1;
- };
- var styleValueToText = function (styleValue) {
- return styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function (chr) {
- return chr.toUpperCase();
- });
- };
- var isWithinList = function (editor, e, nodeName) {
- var tableCellIndex = findIndex(e.parents, ListUtils.isTableCellNode);
- var parents = tableCellIndex !== -1 ? e.parents.slice(0, tableCellIndex) : e.parents;
- var lists = global$1.grep(parents, ListUtils.isListNode(editor));
- return lists.length > 0 && lists[0].nodeName === nodeName;
- };
- var addSplitButton = function (editor, id, tooltip, cmd, nodeName, styles) {
- editor.ui.registry.addSplitButton(id, {
- tooltip: tooltip,
- icon: nodeName === 'OL' ? 'ordered-list' : 'unordered-list',
- presets: 'listpreview',
- columns: 3,
- fetch: function (callback) {
- var items = global$1.map(styles, function (styleValue) {
- var iconStyle = nodeName === 'OL' ? 'num' : 'bull';
- var iconName = styleValue === 'disc' || styleValue === 'decimal' ? 'default' : styleValue;
- var itemValue = styleValue === 'default' ? '' : styleValue;
- var displayText = styleValueToText(styleValue);
- return {
- type: 'choiceitem',
- value: itemValue,
- icon: 'list-' + iconStyle + '-' + iconName,
- text: displayText
- };
- });
- callback(items);
- },
- onAction: function () {
- return editor.execCommand(cmd);
- },
- onItemAction: function (splitButtonApi, value) {
- Actions.applyListFormat(editor, nodeName, value);
- },
- select: function (value) {
- var listStyleType = ListUtils.getSelectedStyleType(editor);
- return listStyleType.map(function (listStyle) {
- return value === listStyle;
- }).getOr(false);
- },
- onSetup: function (api) {
- var nodeChangeHandler = function (e) {
- api.setActive(isWithinList(editor, e, nodeName));
- };
- editor.on('NodeChange', nodeChangeHandler);
- return function () {
- return editor.off('NodeChange', nodeChangeHandler);
- };
- }
- });
- };
- var addButton = function (editor, id, tooltip, cmd, nodeName, styles) {
- editor.ui.registry.addToggleButton(id, {
- active: false,
- tooltip: tooltip,
- icon: nodeName === 'OL' ? 'ordered-list' : 'unordered-list',
- onSetup: function (api) {
- var nodeChangeHandler = function (e) {
- api.setActive(isWithinList(editor, e, nodeName));
- };
- editor.on('NodeChange', nodeChangeHandler);
- return function () {
- return editor.off('NodeChange', nodeChangeHandler);
- };
- },
- onAction: function () {
- return editor.execCommand(cmd);
- }
- });
- };
- var addControl = function (editor, id, tooltip, cmd, nodeName, styles) {
- if (styles.length > 0) {
- addSplitButton(editor, id, tooltip, cmd, nodeName, styles);
- } else {
- addButton(editor, id, tooltip, cmd, nodeName);
- }
- };
- var register$1 = function (editor) {
- addControl(editor, 'numlist', 'Numbered list', 'InsertOrderedList', 'OL', Settings.getNumberStyles(editor));
- addControl(editor, 'bullist', 'Bullet list', 'InsertUnorderedList', 'UL', Settings.getBulletStyles(editor));
- };
- var Buttons = { register: register$1 };
- function Plugin () {
- global.add('advlist', function (editor) {
- var hasPlugin = function (editor, plugin) {
- var plugins = editor.settings.plugins ? editor.settings.plugins : '';
- return global$1.inArray(plugins.split(/[ ,]/), plugin) !== -1;
- };
- if (hasPlugin(editor, 'lists')) {
- Buttons.register(editor);
- Commands.register(editor);
- }
- });
- }
- Plugin();
- }());
|