@techie_doubts/editor-plugin-color-syntax 3.1.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/README.md +167 -0
- package/dist/td-editor-plugin-color-syntax.css +153 -0
- package/dist/td-editor-plugin-color-syntax.js +521 -0
- package/dist/toastui-editor-plugin-color-syntax.css +153 -0
- package/dist/toastui-editor-plugin-color-syntax.js +523 -0
- package/package.json +54 -0
- package/types/index.d.ts +7 -0
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* TOAST UI Editor : Color Syntax Plugin
|
|
3
|
+
* @version 3.1.0 | Fri Feb 20 2026
|
|
4
|
+
* @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
8
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
9
|
+
module.exports = factory(require("tui-color-picker"));
|
|
10
|
+
else if(typeof define === 'function' && define.amd)
|
|
11
|
+
define(["tui-color-picker"], factory);
|
|
12
|
+
else if(typeof exports === 'object')
|
|
13
|
+
exports["toastui"] = factory(require("tui-color-picker"));
|
|
14
|
+
else
|
|
15
|
+
root["toastui"] = root["toastui"] || {}, root["toastui"]["Editor"] = root["toastui"]["Editor"] || {}, root["toastui"]["Editor"]["plugin"] = root["toastui"]["Editor"]["plugin"] || {}, root["toastui"]["Editor"]["plugin"]["uml"] = factory(root["tui"]["colorPicker"]);
|
|
16
|
+
})(self, function(__WEBPACK_EXTERNAL_MODULE__262__) {
|
|
17
|
+
return /******/ (function() { // webpackBootstrap
|
|
18
|
+
/******/ "use strict";
|
|
19
|
+
/******/ var __webpack_modules__ = ({
|
|
20
|
+
|
|
21
|
+
/***/ 262:
|
|
22
|
+
/***/ (function(module) {
|
|
23
|
+
|
|
24
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__262__;
|
|
25
|
+
|
|
26
|
+
/***/ })
|
|
27
|
+
|
|
28
|
+
/******/ });
|
|
29
|
+
/************************************************************************/
|
|
30
|
+
/******/ // The module cache
|
|
31
|
+
/******/ var __webpack_module_cache__ = {};
|
|
32
|
+
/******/
|
|
33
|
+
/******/ // The require function
|
|
34
|
+
/******/ function __webpack_require__(moduleId) {
|
|
35
|
+
/******/ // Check if module is in cache
|
|
36
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
37
|
+
/******/ if (cachedModule !== undefined) {
|
|
38
|
+
/******/ return cachedModule.exports;
|
|
39
|
+
/******/ }
|
|
40
|
+
/******/ // Create a new module (and put it into the cache)
|
|
41
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
42
|
+
/******/ // no module.id needed
|
|
43
|
+
/******/ // no module.loaded needed
|
|
44
|
+
/******/ exports: {}
|
|
45
|
+
/******/ };
|
|
46
|
+
/******/
|
|
47
|
+
/******/ // Execute the module function
|
|
48
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
49
|
+
/******/
|
|
50
|
+
/******/ // Return the exports of the module
|
|
51
|
+
/******/ return module.exports;
|
|
52
|
+
/******/ }
|
|
53
|
+
/******/
|
|
54
|
+
/************************************************************************/
|
|
55
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
56
|
+
/******/ !function() {
|
|
57
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
58
|
+
/******/ __webpack_require__.n = function(module) {
|
|
59
|
+
/******/ var getter = module && module.__esModule ?
|
|
60
|
+
/******/ function() { return module['default']; } :
|
|
61
|
+
/******/ function() { return module; };
|
|
62
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
63
|
+
/******/ return getter;
|
|
64
|
+
/******/ };
|
|
65
|
+
/******/ }();
|
|
66
|
+
/******/
|
|
67
|
+
/******/ /* webpack/runtime/define property getters */
|
|
68
|
+
/******/ !function() {
|
|
69
|
+
/******/ // define getter functions for harmony exports
|
|
70
|
+
/******/ __webpack_require__.d = function(exports, definition) {
|
|
71
|
+
/******/ for(var key in definition) {
|
|
72
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
73
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
74
|
+
/******/ }
|
|
75
|
+
/******/ }
|
|
76
|
+
/******/ };
|
|
77
|
+
/******/ }();
|
|
78
|
+
/******/
|
|
79
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
80
|
+
/******/ !function() {
|
|
81
|
+
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
82
|
+
/******/ }();
|
|
83
|
+
/******/
|
|
84
|
+
/************************************************************************/
|
|
85
|
+
var __webpack_exports__ = {};
|
|
86
|
+
|
|
87
|
+
// EXPORTS
|
|
88
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
89
|
+
"default": function() { return /* binding */ colorSyntaxPlugin; }
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// EXTERNAL MODULE: external {"commonjs":"tui-color-picker","commonjs2":"tui-color-picker","amd":"tui-color-picker","root":["tui","colorPicker"]}
|
|
93
|
+
var external_commonjs_tui_color_picker_commonjs2_tui_color_picker_amd_tui_color_picker_root_tui_colorPicker_ = __webpack_require__(262);
|
|
94
|
+
var external_commonjs_tui_color_picker_commonjs2_tui_color_picker_amd_tui_color_picker_root_tui_colorPicker_default = /*#__PURE__*/__webpack_require__.n(external_commonjs_tui_color_picker_commonjs2_tui_color_picker_amd_tui_color_picker_root_tui_colorPicker_);
|
|
95
|
+
;// ./src/i18n/langs.ts
|
|
96
|
+
function addLangs(i18n) {
|
|
97
|
+
i18n.setLanguage('ar', {
|
|
98
|
+
'Text color': 'لون النص',
|
|
99
|
+
'Background color': 'لون الخلفية',
|
|
100
|
+
});
|
|
101
|
+
i18n.setLanguage(['cs', 'cs-CZ'], {
|
|
102
|
+
'Text color': 'Barva textu',
|
|
103
|
+
'Background color': 'Barva pozadí',
|
|
104
|
+
});
|
|
105
|
+
i18n.setLanguage(['de', 'de-DE'], {
|
|
106
|
+
'Text color': 'Textfarbe',
|
|
107
|
+
'Background color': 'Hintergrundfarbe',
|
|
108
|
+
});
|
|
109
|
+
i18n.setLanguage(['en', 'en-US'], {
|
|
110
|
+
'Text color': 'Text color',
|
|
111
|
+
'Background color': 'Background color',
|
|
112
|
+
});
|
|
113
|
+
i18n.setLanguage(['es', 'es-ES'], {
|
|
114
|
+
'Text color': 'Color del texto',
|
|
115
|
+
'Background color': 'Color de fondo',
|
|
116
|
+
});
|
|
117
|
+
i18n.setLanguage(['fi', 'fi-FI'], {
|
|
118
|
+
'Text color': 'Tekstin väri',
|
|
119
|
+
'Background color': 'Taustaväri',
|
|
120
|
+
});
|
|
121
|
+
i18n.setLanguage(['fr', 'fr-FR'], {
|
|
122
|
+
'Text color': 'Couleur du texte',
|
|
123
|
+
'Background color': 'Couleur de fond',
|
|
124
|
+
});
|
|
125
|
+
i18n.setLanguage(['gl', 'gl-ES'], {
|
|
126
|
+
'Text color': 'Cor do texto',
|
|
127
|
+
'Background color': 'Cor de fondo',
|
|
128
|
+
});
|
|
129
|
+
i18n.setLanguage(['hr', 'hr-HR'], {
|
|
130
|
+
'Text color': 'Boja teksta',
|
|
131
|
+
'Background color': 'Boja pozadine',
|
|
132
|
+
});
|
|
133
|
+
i18n.setLanguage(['it', 'it-IT'], {
|
|
134
|
+
'Text color': 'Colore del testo',
|
|
135
|
+
'Background color': 'Colore di sfondo',
|
|
136
|
+
});
|
|
137
|
+
i18n.setLanguage(['ja', 'ja-JP'], {
|
|
138
|
+
'Text color': '文字色相',
|
|
139
|
+
'Background color': '背景色',
|
|
140
|
+
});
|
|
141
|
+
i18n.setLanguage(['ko', 'ko-KR'], {
|
|
142
|
+
'Text color': '글자 색상',
|
|
143
|
+
'Background color': '배경 색상',
|
|
144
|
+
});
|
|
145
|
+
i18n.setLanguage(['nb', 'nb-NO'], {
|
|
146
|
+
'Text color': 'Tekstfarge',
|
|
147
|
+
'Background color': 'Bakgrunnsfarge',
|
|
148
|
+
});
|
|
149
|
+
i18n.setLanguage(['nl', 'nl-NL'], {
|
|
150
|
+
'Text color': 'Tekstkleur',
|
|
151
|
+
'Background color': 'Achtergrondkleur',
|
|
152
|
+
});
|
|
153
|
+
i18n.setLanguage(['pl', 'pl-PL'], {
|
|
154
|
+
'Text color': 'Kolor tekstu',
|
|
155
|
+
'Background color': 'Kolor tła',
|
|
156
|
+
});
|
|
157
|
+
i18n.setLanguage(['pt', 'pt-BR'], {
|
|
158
|
+
'Text color': 'Cor do texto',
|
|
159
|
+
'Background color': 'Cor de fundo',
|
|
160
|
+
});
|
|
161
|
+
i18n.setLanguage(['ru', 'ru-RU'], {
|
|
162
|
+
'Text color': 'Цвет текста',
|
|
163
|
+
'Background color': 'Цвет фона',
|
|
164
|
+
});
|
|
165
|
+
i18n.setLanguage(['sv', 'sv-SE'], {
|
|
166
|
+
'Text color': 'Textfärg',
|
|
167
|
+
'Background color': 'Bakgrundsfärg',
|
|
168
|
+
});
|
|
169
|
+
i18n.setLanguage(['tr', 'tr-TR'], {
|
|
170
|
+
'Text color': 'Metin rengi',
|
|
171
|
+
'Background color': 'Arka plan rengi',
|
|
172
|
+
});
|
|
173
|
+
i18n.setLanguage(['uk', 'uk-UA'], {
|
|
174
|
+
'Text color': 'Колір тексту',
|
|
175
|
+
'Background color': 'Колір фону',
|
|
176
|
+
});
|
|
177
|
+
i18n.setLanguage('zh-CN', {
|
|
178
|
+
'Text color': '文字颜色',
|
|
179
|
+
'Background color': '背景颜色',
|
|
180
|
+
});
|
|
181
|
+
i18n.setLanguage('zh-TW', {
|
|
182
|
+
'Text color': '文字顏色',
|
|
183
|
+
'Background color': '背景顏色',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
;// ./src/utils/dom.ts
|
|
188
|
+
function hasClass(element, className) {
|
|
189
|
+
return element.classList.contains(className);
|
|
190
|
+
}
|
|
191
|
+
function findParentByClassName(el, className) {
|
|
192
|
+
var currentEl = el;
|
|
193
|
+
while (currentEl && !hasClass(currentEl, className)) {
|
|
194
|
+
currentEl = currentEl.parentElement;
|
|
195
|
+
}
|
|
196
|
+
return currentEl;
|
|
197
|
+
}
|
|
198
|
+
function removeProseMirrorHackNodes(html) {
|
|
199
|
+
var reProseMirrorImage = /<img class="ProseMirror-separator" alt="">/g;
|
|
200
|
+
var reProseMirrorTrailingBreak = / class="ProseMirror-trailingBreak"/g;
|
|
201
|
+
var resultHTML = html;
|
|
202
|
+
resultHTML = resultHTML.replace(reProseMirrorImage, '');
|
|
203
|
+
resultHTML = resultHTML.replace(reProseMirrorTrailingBreak, '');
|
|
204
|
+
return resultHTML;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
;// ./src/index.ts
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
var PREFIX = 'toastui-editor-';
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// Style helpers
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
function parseStyleString(style) {
|
|
217
|
+
var result = {};
|
|
218
|
+
if (!style) {
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
style.split(';').forEach(function (part) {
|
|
222
|
+
var colon = part.indexOf(':');
|
|
223
|
+
if (colon > 0) {
|
|
224
|
+
var key = part.slice(0, colon).trim();
|
|
225
|
+
var val = part.slice(colon + 1).trim();
|
|
226
|
+
if (key && val) {
|
|
227
|
+
result[key] = val;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
function buildStyleString(styles) {
|
|
234
|
+
return Object.keys(styles)
|
|
235
|
+
.map(function (k) { return k + ": " + styles[k]; })
|
|
236
|
+
.join('; ');
|
|
237
|
+
}
|
|
238
|
+
function getExistingSpanStyle(selection, schema) {
|
|
239
|
+
var $from = selection.$from;
|
|
240
|
+
var spanType = schema.marks.span;
|
|
241
|
+
if (!spanType) {
|
|
242
|
+
return '';
|
|
243
|
+
}
|
|
244
|
+
if (!selection.empty) {
|
|
245
|
+
var from = selection.from, to = selection.to;
|
|
246
|
+
var style_1 = '';
|
|
247
|
+
$from.doc.nodesBetween(from, to, function (node) {
|
|
248
|
+
if (style_1 || !node.isText) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
var m = spanType.isInSet(node.marks);
|
|
252
|
+
if (m) {
|
|
253
|
+
style_1 = (m.attrs.htmlAttrs && m.attrs.htmlAttrs.style) || '';
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return style_1;
|
|
257
|
+
}
|
|
258
|
+
var mark = spanType.isInSet($from.marks());
|
|
259
|
+
if (mark) {
|
|
260
|
+
return (mark.attrs.htmlAttrs && mark.attrs.htmlAttrs.style) || '';
|
|
261
|
+
}
|
|
262
|
+
if ($from.nodeBefore) {
|
|
263
|
+
var m = spanType.isInSet($from.nodeBefore.marks);
|
|
264
|
+
if (m) {
|
|
265
|
+
return (m.attrs.htmlAttrs && m.attrs.htmlAttrs.style) || '';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return '';
|
|
269
|
+
}
|
|
270
|
+
// ---------------------------------------------------------------------------
|
|
271
|
+
// Markdown helpers: detect and rewrite existing <span style="..."> wrappers
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
var RE_SPAN_WRAP = /^<span\s+style="([^"]*)">([\s\S]*)<\/span>$/i;
|
|
274
|
+
function parseMdSpanStyle(text) {
|
|
275
|
+
var m = RE_SPAN_WRAP.exec(text);
|
|
276
|
+
if (!m) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
return { inner: m[2], styles: parseStyleString(m[1]) };
|
|
280
|
+
}
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// DOM helpers
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
function createApplyButton(text) {
|
|
285
|
+
var button = document.createElement('button');
|
|
286
|
+
button.setAttribute('type', 'button');
|
|
287
|
+
button.textContent = text;
|
|
288
|
+
return button;
|
|
289
|
+
}
|
|
290
|
+
function getCurrentEditorEl(el, containerCls) {
|
|
291
|
+
var root = findParentByClassName(el, PREFIX + "defaultUI");
|
|
292
|
+
return root.querySelector("." + containerCls + " .ProseMirror");
|
|
293
|
+
}
|
|
294
|
+
function createColorPicker(preset, usageStatistics, i18n) {
|
|
295
|
+
var container = document.createElement('div');
|
|
296
|
+
var option = {
|
|
297
|
+
container: container,
|
|
298
|
+
usageStatistics: usageStatistics,
|
|
299
|
+
};
|
|
300
|
+
if (preset) {
|
|
301
|
+
option.preset = preset;
|
|
302
|
+
}
|
|
303
|
+
var picker = external_commonjs_tui_color_picker_commonjs2_tui_color_picker_amd_tui_color_picker_root_tui_colorPicker_default().create(option);
|
|
304
|
+
var button = createApplyButton(i18n.get('OK'));
|
|
305
|
+
picker.slider.toggle(true);
|
|
306
|
+
container.appendChild(button);
|
|
307
|
+
return { container: container, picker: picker, button: button };
|
|
308
|
+
}
|
|
309
|
+
// ---------------------------------------------------------------------------
|
|
310
|
+
// Plugin
|
|
311
|
+
// ---------------------------------------------------------------------------
|
|
312
|
+
var containerClassName;
|
|
313
|
+
var currentEditorEl;
|
|
314
|
+
/**
|
|
315
|
+
* Color syntax plugin with text color and background color toolbar buttons.
|
|
316
|
+
*/
|
|
317
|
+
function colorSyntaxPlugin(context, options) {
|
|
318
|
+
if (options === void 0) { options = {}; }
|
|
319
|
+
var eventEmitter = context.eventEmitter, i18n = context.i18n, _a = context.usageStatistics, usageStatistics = _a === void 0 ? true : _a, pmState = context.pmState;
|
|
320
|
+
var preset = options.preset;
|
|
321
|
+
addLangs(i18n);
|
|
322
|
+
// --- text color picker (original) --------------------------------------
|
|
323
|
+
var textPicker = createColorPicker(preset, usageStatistics, i18n);
|
|
324
|
+
// --- background color picker (new) -------------------------------------
|
|
325
|
+
var bgPicker = createColorPicker(preset, usageStatistics, i18n);
|
|
326
|
+
// --- focus tracking ----------------------------------------------------
|
|
327
|
+
eventEmitter.listen('focus', function (editType) {
|
|
328
|
+
containerClassName = "" + PREFIX + (editType === 'markdown' ? 'md' : 'ww') + "-container";
|
|
329
|
+
});
|
|
330
|
+
// --- text color OK click -----------------------------------------------
|
|
331
|
+
textPicker.container.addEventListener('click', function (ev) {
|
|
332
|
+
if (ev.target.getAttribute('type') === 'button') {
|
|
333
|
+
var hexInput = textPicker.container.querySelector('.tui-colorpicker-palette-hex');
|
|
334
|
+
var selectedColor = hexInput ? hexInput.value.trim() : textPicker.picker.getColor();
|
|
335
|
+
currentEditorEl = getCurrentEditorEl(textPicker.container, containerClassName);
|
|
336
|
+
currentEditorEl.focus();
|
|
337
|
+
eventEmitter.emit('command', 'color', { selectedColor: selectedColor });
|
|
338
|
+
eventEmitter.emit('closePopup');
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
// --- background color OK click -----------------------------------------
|
|
342
|
+
bgPicker.container.addEventListener('click', function (ev) {
|
|
343
|
+
if (ev.target.getAttribute('type') === 'button') {
|
|
344
|
+
var hexInput = bgPicker.container.querySelector('.tui-colorpicker-palette-hex');
|
|
345
|
+
var selectedColor = hexInput ? hexInput.value.trim() : bgPicker.picker.getColor();
|
|
346
|
+
currentEditorEl = getCurrentEditorEl(bgPicker.container, containerClassName);
|
|
347
|
+
currentEditorEl.focus();
|
|
348
|
+
eventEmitter.emit('command', 'bgColor', { selectedColor: selectedColor });
|
|
349
|
+
eventEmitter.emit('closePopup');
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
// --- toolbar items -----------------------------------------------------
|
|
353
|
+
var textToolbarItem = {
|
|
354
|
+
name: 'color',
|
|
355
|
+
tooltip: i18n.get('Text color'),
|
|
356
|
+
className: PREFIX + "toolbar-icons color",
|
|
357
|
+
popup: {
|
|
358
|
+
className: PREFIX + "popup-color",
|
|
359
|
+
body: textPicker.container,
|
|
360
|
+
style: { width: 'auto' },
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
var bgToolbarItem = {
|
|
364
|
+
name: 'bgColor',
|
|
365
|
+
tooltip: i18n.get('Background color'),
|
|
366
|
+
className: PREFIX + "toolbar-icons bgcolor",
|
|
367
|
+
text: 'BG',
|
|
368
|
+
popup: {
|
|
369
|
+
className: PREFIX + "popup-color",
|
|
370
|
+
body: bgPicker.container,
|
|
371
|
+
style: { width: 'auto' },
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
// --- commands -----------------------------------------------------------
|
|
375
|
+
return {
|
|
376
|
+
markdownCommands: {
|
|
377
|
+
color: function (payload, _a, dispatch) {
|
|
378
|
+
var tr = _a.tr, selection = _a.selection, schema = _a.schema;
|
|
379
|
+
var selectedColor = (payload || {}).selectedColor;
|
|
380
|
+
if (typeof selectedColor === 'undefined') {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
var slice = selection.content();
|
|
384
|
+
var rawText = slice.content.textBetween(0, slice.content.size, '\n');
|
|
385
|
+
var parsed = parseMdSpanStyle(rawText);
|
|
386
|
+
var existing = parsed ? parsed.styles : {};
|
|
387
|
+
var inner = parsed ? parsed.inner : rawText;
|
|
388
|
+
if (selectedColor) {
|
|
389
|
+
existing.color = selectedColor;
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
delete existing.color;
|
|
393
|
+
}
|
|
394
|
+
var styleStr = buildStyleString(existing);
|
|
395
|
+
if (styleStr) {
|
|
396
|
+
var fullText = "<span style=\"" + styleStr + "\">" + inner + "</span>";
|
|
397
|
+
tr.replaceSelectionWith(schema.text(fullText));
|
|
398
|
+
var start = tr.mapping.map(selection.from);
|
|
399
|
+
tr.setSelection(pmState.TextSelection.create(tr.doc, start, start + fullText.length));
|
|
400
|
+
}
|
|
401
|
+
else if (inner) {
|
|
402
|
+
tr.replaceSelectionWith(schema.text(inner));
|
|
403
|
+
}
|
|
404
|
+
dispatch(tr);
|
|
405
|
+
return true;
|
|
406
|
+
},
|
|
407
|
+
bgColor: function (payload, _a, dispatch) {
|
|
408
|
+
var tr = _a.tr, selection = _a.selection, schema = _a.schema;
|
|
409
|
+
var selectedColor = (payload || {}).selectedColor;
|
|
410
|
+
if (typeof selectedColor === 'undefined') {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
var slice = selection.content();
|
|
414
|
+
var rawText = slice.content.textBetween(0, slice.content.size, '\n');
|
|
415
|
+
var parsed = parseMdSpanStyle(rawText);
|
|
416
|
+
var existing = parsed ? parsed.styles : {};
|
|
417
|
+
var inner = parsed ? parsed.inner : rawText;
|
|
418
|
+
if (selectedColor) {
|
|
419
|
+
existing.background = selectedColor;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
delete existing.background;
|
|
423
|
+
}
|
|
424
|
+
var styleStr = buildStyleString(existing);
|
|
425
|
+
if (styleStr) {
|
|
426
|
+
var fullText = "<span style=\"" + styleStr + "\">" + inner + "</span>";
|
|
427
|
+
tr.replaceSelectionWith(schema.text(fullText));
|
|
428
|
+
var start = tr.mapping.map(selection.from);
|
|
429
|
+
tr.setSelection(pmState.TextSelection.create(tr.doc, start, start + fullText.length));
|
|
430
|
+
}
|
|
431
|
+
else if (inner) {
|
|
432
|
+
tr.replaceSelectionWith(schema.text(inner));
|
|
433
|
+
}
|
|
434
|
+
dispatch(tr);
|
|
435
|
+
return true;
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
wysiwygCommands: {
|
|
439
|
+
color: function (payload, _a, dispatch) {
|
|
440
|
+
var tr = _a.tr, selection = _a.selection, schema = _a.schema;
|
|
441
|
+
var selectedColor = (payload || {}).selectedColor;
|
|
442
|
+
if (typeof selectedColor === 'undefined') {
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
var from = selection.from, to = selection.to;
|
|
446
|
+
var existingStyle = getExistingSpanStyle(selection, schema);
|
|
447
|
+
var existing = parseStyleString(existingStyle);
|
|
448
|
+
if (selectedColor) {
|
|
449
|
+
existing.color = selectedColor;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
delete existing.color;
|
|
453
|
+
}
|
|
454
|
+
var styleStr = buildStyleString(existing);
|
|
455
|
+
if (styleStr) {
|
|
456
|
+
var attrs = { htmlAttrs: { style: styleStr } };
|
|
457
|
+
tr.addMark(from, to, schema.marks.span.create(attrs));
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
tr.removeMark(from, to, schema.marks.span);
|
|
461
|
+
}
|
|
462
|
+
tr.setSelection(pmState.TextSelection.create(tr.doc, from, to));
|
|
463
|
+
dispatch(tr);
|
|
464
|
+
return true;
|
|
465
|
+
},
|
|
466
|
+
bgColor: function (payload, _a, dispatch) {
|
|
467
|
+
var tr = _a.tr, selection = _a.selection, schema = _a.schema;
|
|
468
|
+
var selectedColor = (payload || {}).selectedColor;
|
|
469
|
+
if (typeof selectedColor === 'undefined') {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
var from = selection.from, to = selection.to;
|
|
473
|
+
var existingStyle = getExistingSpanStyle(selection, schema);
|
|
474
|
+
var existing = parseStyleString(existingStyle);
|
|
475
|
+
if (selectedColor) {
|
|
476
|
+
existing.background = selectedColor;
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
delete existing.background;
|
|
480
|
+
}
|
|
481
|
+
var styleStr = buildStyleString(existing);
|
|
482
|
+
if (styleStr) {
|
|
483
|
+
var attrs = { htmlAttrs: { style: styleStr } };
|
|
484
|
+
tr.addMark(from, to, schema.marks.span.create(attrs));
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
tr.removeMark(from, to, schema.marks.span);
|
|
488
|
+
}
|
|
489
|
+
tr.setSelection(pmState.TextSelection.create(tr.doc, from, to));
|
|
490
|
+
dispatch(tr);
|
|
491
|
+
return true;
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
toolbarItems: [
|
|
495
|
+
{
|
|
496
|
+
groupIndex: 0,
|
|
497
|
+
itemIndex: 3,
|
|
498
|
+
item: textToolbarItem,
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
groupIndex: 0,
|
|
502
|
+
itemIndex: 4,
|
|
503
|
+
item: bgToolbarItem,
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
toHTMLRenderers: {
|
|
507
|
+
htmlInline: {
|
|
508
|
+
span: function (node, _a) {
|
|
509
|
+
var entering = _a.entering;
|
|
510
|
+
return entering
|
|
511
|
+
? { type: 'openTag', tagName: 'span', attributes: node.attrs }
|
|
512
|
+
: { type: 'closeTag', tagName: 'span' };
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
__webpack_exports__ = __webpack_exports__["default"];
|
|
520
|
+
/******/ return __webpack_exports__;
|
|
521
|
+
/******/ })()
|
|
522
|
+
;
|
|
523
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@techie_doubts/editor-plugin-color-syntax",
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"description": "TOAST UI Editor : Color Syntax Plugin",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nhn",
|
|
7
|
+
"nhn cloud",
|
|
8
|
+
"toast",
|
|
9
|
+
"toastui",
|
|
10
|
+
"toast-ui",
|
|
11
|
+
"editor",
|
|
12
|
+
"plugin",
|
|
13
|
+
"color-syntax",
|
|
14
|
+
"color-picker"
|
|
15
|
+
],
|
|
16
|
+
"main": "dist/td-editor-plugin-color-syntax.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/*.js",
|
|
19
|
+
"dist/*.css",
|
|
20
|
+
"types/index.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"types": "types/index.d.ts",
|
|
23
|
+
"author": "NHN Cloud FE Development Lab <dl_javascript@nhn.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/nhn/tui.editor.git",
|
|
28
|
+
"directory": "plugins/color-syntax"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/nhn/tui.editor/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://ui.toast.com",
|
|
34
|
+
"browserslist": "last 2 versions, not ie <= 10",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"test:types": "tsc",
|
|
38
|
+
"test": "jest --watch",
|
|
39
|
+
"test:ci": "jest",
|
|
40
|
+
"serve": "snowpack dev",
|
|
41
|
+
"serve:ie": "webpack serve",
|
|
42
|
+
"build:cdn": "webpack build --env cdn & webpack build --env cdn minify",
|
|
43
|
+
"build": "webpack build && npm run build:cdn"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"cross-env": "^6.0.3"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@techie_doubts/tui.color-picker.2026": "^2.2.8"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/types/index.d.ts
ADDED