@licium/editor-plugin-text-align 1.0.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.
@@ -0,0 +1,38 @@
1
+ /*!
2
+ * TOAST UI Editor : Text Align Plugin
3
+ * @version 1.0.0 | Sat Jan 03 2026
4
+ * @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
5
+ * @license MIT
6
+ */
7
+ .toastui-editor-toolbar-icons.alignLeft,
8
+ .toastui-editor-toolbar-icons.alignCenter,
9
+ .toastui-editor-toolbar-icons.alignRight {
10
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI5NiIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDk2IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiMzMzMiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIj4KICA8bGluZSB4MT0iOCIgeTE9IjYiIHgyPSIyNCIgeTI9IjYiIC8+CiAgPGxpbmUgeDE9IjgiIHkxPSIxMCIgeDI9IjIwIiB5Mj0iMTAiIC8+CiAgPGxpbmUgeDE9IjgiIHkxPSIxNCIgeDI9IjI0IiB5Mj0iMTQiIC8+CiAgPGxpbmUgeDE9IjgiIHkxPSIxOCIgeDI9IjIwIiB5Mj0iMTgiIC8+CgogIDxsaW5lIHgxPSI0MCIgeTE9IjYiIHgyPSI1NiIgeTI9IjYiIC8+CiAgPGxpbmUgeDE9IjQyIiB5MT0iMTAiIHgyPSI1NCIgeTI9IjEwIiAvPgogIDxsaW5lIHgxPSI0MCIgeTE9IjE0IiB4Mj0iNTYiIHkyPSIxNCIgLz4KICA8bGluZSB4MT0iNDIiIHkxPSIxOCIgeDI9IjU0IiB5Mj0iMTgiIC8+CgogIDxsaW5lIHgxPSI3MiIgeTE9IjYiIHgyPSI4OCIgeTI9IjYiIC8+CiAgPGxpbmUgeDE9Ijc2IiB5MT0iMTAiIHgyPSI4OCIgeTI9IjEwIiAvPgogIDxsaW5lIHgxPSI3MiIgeTE9IjE0IiB4Mj0iODgiIHkyPSIxNCIgLz4KICA8bGluZSB4MT0iNzYiIHkxPSIxOCIgeDI9Ijg4IiB5Mj0iMTgiIC8+Cjwvc3ZnPg==);
11
+ background-size: 96px 24px;
12
+ background-repeat: no-repeat;
13
+ text-indent: -9999px;
14
+ /* Hide text fallback */
15
+ }
16
+
17
+ .toastui-editor-toolbar-icons.alignLeft {
18
+ background-position: 0 4px;
19
+ }
20
+
21
+ .toastui-editor-toolbar-icons.alignCenter {
22
+ background-position: -32px 4px;
23
+ }
24
+
25
+ .toastui-editor-toolbar-icons.alignRight {
26
+ background-position: -64px 4px;
27
+ }
28
+
29
+ .toastui-editor-defaultUI-toolbar button.active {
30
+ background-color: #fca0704d;
31
+ color: #333;
32
+ }
33
+
34
+ .toastui-editor-dark .toastui-editor-toolbar-icons.alignLeft,
35
+ .toastui-editor-dark .toastui-editor-toolbar-icons.alignCenter,
36
+ .toastui-editor-dark .toastui-editor-toolbar-icons.alignRight {
37
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI5NiIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDk2IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNlZWUiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIj4KICA8bGluZSB4MT0iOCIgeTE9IjYiIHgyPSIyNCIgeTI9IjYiIC8+CiAgPGxpbmUgeDE9IjgiIHkxPSIxMCIgeDI9IjIwIiB5Mj0iMTAiIC8+CiAgPGxpbmUgeDE9IjgiIHkxPSIxNCIgeDI9IjI0IiB5Mj0iMTQiIC8+CiAgPGxpbmUgeDE9IjgiIHkxPSIxOCIgeDI9IjIwIiB5Mj0iMTgiIC8+CgogIDxsaW5lIHgxPSI0MCIgeTE9IjYiIHgyPSI1NiIgeTI9IjYiIC8+CiAgPGxpbmUgeDE9IjQyIiB5MT0iMTAiIHgyPSI1NCIgeTI9IjEwIiAvPgogIDxsaW5lIHgxPSI0MCIgeTE9IjE0IiB4Mj0iNTYiIHkyPSIxNCIgLz4KICA8bGluZSB4MT0iNDIiIHkxPSIxOCIgeDI9IjU0IiB5Mj0iMTgiIC8+CgogIDxsaW5lIHgxPSI3MiIgeTE9IjYiIHgyPSI4OCIgeTI9IjYiIC8+CiAgPGxpbmUgeDE9Ijc2IiB5MT0iMTAiIHgyPSI4OCIgeTI9IjEwIiAvPgogIDxsaW5lIHgxPSI3MiIgeTE9IjE0IiB4Mj0iODgiIHkyPSIxNCIgLz4KICA8bGluZSB4MT0iNzYiIHkxPSIxOCIgeDI9Ijg4IiB5Mj0iMTgiIC8+Cjwvc3ZnPg==);
38
+ }
@@ -0,0 +1,304 @@
1
+ /*!
2
+ * TOAST UI Editor : Text Align Plugin
3
+ * @version 1.0.0 | Sat Jan 03 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();
10
+ else if(typeof define === 'function' && define.amd)
11
+ define([], factory);
12
+ else if(typeof exports === 'object')
13
+ exports["toastui"] = factory();
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"]["textAlign"] = factory();
16
+ })(self, function() {
17
+ return /******/ (function() { // webpackBootstrap
18
+ /******/ "use strict";
19
+ /******/ // The require scope
20
+ /******/ var __webpack_require__ = {};
21
+ /******/
22
+ /************************************************************************/
23
+ /******/ /* webpack/runtime/define property getters */
24
+ /******/ !function() {
25
+ /******/ // define getter functions for harmony exports
26
+ /******/ __webpack_require__.d = function(exports, definition) {
27
+ /******/ for(var key in definition) {
28
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
29
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
30
+ /******/ }
31
+ /******/ }
32
+ /******/ };
33
+ /******/ }();
34
+ /******/
35
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
36
+ /******/ !function() {
37
+ /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
38
+ /******/ }();
39
+ /******/
40
+ /************************************************************************/
41
+ var __webpack_exports__ = {};
42
+
43
+ // EXPORTS
44
+ __webpack_require__.d(__webpack_exports__, {
45
+ "default": function() { return /* binding */ textAlignPlugin; }
46
+ });
47
+
48
+ ;// CONCATENATED MODULE: ./src/i18n/langs.ts
49
+ function addLangs(i18n) {
50
+ i18n.setLanguage(['en', 'en-US'], {
51
+ alignLeft: 'Align left',
52
+ alignCenter: 'Align center',
53
+ alignRight: 'Align right',
54
+ });
55
+ i18n.setLanguage(['de', 'de-DE'], {
56
+ alignLeft: 'Linksbündig',
57
+ alignCenter: 'Zentriert',
58
+ alignRight: 'Rechtsbündig',
59
+ });
60
+ // Add other languages as needed
61
+ }
62
+
63
+ ;// CONCATENATED MODULE: ./src/index.ts
64
+
65
+
66
+ var PREFIX = 'toastui-editor-';
67
+ function createToolbarItemOption(text, commandName, i18n) {
68
+ return {
69
+ name: commandName,
70
+ command: commandName,
71
+ tooltip: i18n.get(commandName),
72
+ text: text,
73
+ className: PREFIX + "toolbar-icons " + commandName,
74
+ };
75
+ }
76
+ function textAlignPlugin(context, options) {
77
+ if (options === void 0) { options = {}; }
78
+ var i18n = context.i18n, eventEmitter = context.eventEmitter, _a = context.usageStatistics, usageStatistics = _a === void 0 ? true : _a;
79
+ addLangs(i18n);
80
+ // Active state listener
81
+ eventEmitter.listen('caretChange', function () {
82
+ updateToolbarState();
83
+ });
84
+ return {
85
+ markdownCommands: {
86
+ alignLeft: function (payload, _a, dispatch) {
87
+ var tr = _a.tr, selection = _a.selection, schema = _a.schema;
88
+ return execMarkdownAlign('left', selection, schema, tr, dispatch);
89
+ },
90
+ alignCenter: function (payload, _a, dispatch) {
91
+ var tr = _a.tr, selection = _a.selection, schema = _a.schema;
92
+ return execMarkdownAlign('center', selection, schema, tr, dispatch);
93
+ },
94
+ alignRight: function (payload, _a, dispatch) {
95
+ var tr = _a.tr, selection = _a.selection, schema = _a.schema;
96
+ return execMarkdownAlign('right', selection, schema, tr, dispatch);
97
+ },
98
+ },
99
+ wysiwygCommands: {
100
+ alignLeft: function (payload, _a, dispatch) {
101
+ var tr = _a.tr, selection = _a.selection, schema = _a.schema;
102
+ return execWysiwygAlign('left', selection, schema, tr, dispatch);
103
+ },
104
+ alignCenter: function (payload, _a, dispatch) {
105
+ var tr = _a.tr, selection = _a.selection, schema = _a.schema;
106
+ return execWysiwygAlign('center', selection, schema, tr, dispatch);
107
+ },
108
+ alignRight: function (payload, _a, dispatch) {
109
+ var tr = _a.tr, selection = _a.selection, schema = _a.schema;
110
+ return execWysiwygAlign('right', selection, schema, tr, dispatch);
111
+ },
112
+ },
113
+ toolbarItems: [
114
+ {
115
+ groupIndex: 0,
116
+ itemIndex: 3,
117
+ item: createToolbarItemOption('', 'alignLeft', i18n),
118
+ },
119
+ {
120
+ groupIndex: 0,
121
+ itemIndex: 4,
122
+ item: createToolbarItemOption('', 'alignCenter', i18n),
123
+ },
124
+ {
125
+ groupIndex: 0,
126
+ itemIndex: 5,
127
+ item: createToolbarItemOption('', 'alignRight', i18n),
128
+ },
129
+ ],
130
+ toHTMLRenderers: {
131
+ htmlInline: {
132
+ span: function (node, _a) {
133
+ var entering = _a.entering, origin = _a.origin;
134
+ var style = node.attrs ? node.attrs.style : null;
135
+ if (style && style.indexOf('text-align') > -1) {
136
+ return entering
137
+ ? { type: 'openTag', tagName: 'span', attributes: { style: style } }
138
+ : { type: 'closeTag', tagName: 'span' };
139
+ }
140
+ return origin();
141
+ },
142
+ },
143
+ },
144
+ };
145
+ }
146
+ function updateToolbarState() {
147
+ // 1. Reset all buttons
148
+ var buttons = document.querySelectorAll('.toastui-editor-toolbar-icons.alignLeft, .toastui-editor-toolbar-icons.alignCenter, .toastui-editor-toolbar-icons.alignRight');
149
+ buttons.forEach(function (btn) { return btn.classList.remove('active'); });
150
+ // 2. Determine active state
151
+ // Getting state from plugin context is hard.
152
+ // For Markdown: Parse current line of cursor?
153
+ // For WYSIWYG: Parse selection marks?
154
+ // Naive checker for demo quality:
155
+ var selection = window.getSelection();
156
+ if (!selection || selection.rangeCount === 0)
157
+ return;
158
+ var range = selection.getRangeAt(0);
159
+ var container = range.commonAncestorContainer;
160
+ if (container.nodeType === 3)
161
+ container = container.parentElement; // Text node -> Element
162
+ var el = container;
163
+ // Check for span with style
164
+ var activeAlign = null;
165
+ var current = el;
166
+ // Walk up a few levels to find span
167
+ while (current &&
168
+ current.classList &&
169
+ !current.classList.contains('ProseMirror') &&
170
+ !current.classList.contains('toastui-editor-contents')) {
171
+ if (current.tagName === 'SPAN' && current.style.textAlign) {
172
+ activeAlign = current.style.textAlign;
173
+ break;
174
+ }
175
+ current = current.parentElement;
176
+ }
177
+ if (!activeAlign) {
178
+ // Check inner text if in Markdown mode (Textarea)
179
+ // This is very hard because DOM is just text.
180
+ // We skip Markdown active state highlight for this iteration,
181
+ // focusing on WYSIWYG visual feedback.
182
+ }
183
+ if (activeAlign) {
184
+ var activeBtn = document.querySelector(".toastui-editor-toolbar-icons.align" + capitalize(activeAlign));
185
+ if (activeBtn)
186
+ activeBtn.classList.add('active');
187
+ }
188
+ }
189
+ function capitalize(s) {
190
+ return s.charAt(0).toUpperCase() + s.slice(1);
191
+ }
192
+ function execMarkdownAlign(alignType, selection, schema, tr, dispatch) {
193
+ var doc = tr.doc;
194
+ var from = selection.from, to = selection.to;
195
+ // Always expand to full line(s) to avoid nesting inside words
196
+ var $from = doc.resolve(from);
197
+ var $to = doc.resolve(to);
198
+ // In Markdown mode (CodeMirror-like), we usually want to operate on lines.
199
+ // We can use doc.resolve(from).blockRange() -> this gives the text block (paragraph).
200
+ // This is safer than char-level selection for block alignment.
201
+ var fromLine = $from.pos - $from.parentOffset; // Start of line
202
+ var toLine = $to.pos + ($to.parent.content.size - $to.parentOffset); // End of line
203
+ // Wait, doc.resolve in Markdown mode... TUI's internal doc structure for Markdown is just a series of blocks?
204
+ // Let's rely on blockRange() which TUI implementation respects.
205
+ var blockRange = $from.blockRange($to);
206
+ var targetFrom = from;
207
+ var targetTo = to;
208
+ if (blockRange) {
209
+ targetFrom = blockRange.start + 1; // +1 to skip start token? No, text nodes.
210
+ targetTo = blockRange.end - 1;
211
+ // Actually, let's look at the Slice content.
212
+ // If we use blockRange, we get the whole "Paragraph" structure.
213
+ }
214
+ // Fallback: If no blockRange (rare), use raw selection.
215
+ // But to fix the "nesting" issue, we MUST select the whole line content including any existing HTML tags.
216
+ // In TUI Markdown, each line is likely a textblock.
217
+ // Let's try to grab the whole block content.
218
+ var resolvedFrom = doc.resolve(from);
219
+ var startPos = resolvedFrom.start();
220
+ var endPos = resolvedFrom.end();
221
+ targetFrom = startPos;
222
+ targetTo = endPos;
223
+ var slice = doc.slice(targetFrom, targetTo);
224
+ var textContent = slice.content.textBetween(0, slice.content.size, '\n');
225
+ // Looser regex to match existing tags
226
+ // Matches: <span ...> ... </span>
227
+ var regex = /^\s*<span\s+[^>]*style="[^"]*text-align:\s*(left|center|right)[^"]*"[^>]*>([\s\S]*?)<\/span>\s*$/i;
228
+ var match = textContent.match(regex);
229
+ var newText = textContent;
230
+ var currentAlign = null;
231
+ if (match) {
232
+ currentAlign = match[1].toLowerCase();
233
+ newText = match[2]; // Inner content
234
+ }
235
+ var finalWrapped = newText;
236
+ if (currentAlign === alignType) {
237
+ // Toggle off: Just return the inner text (unwrap)
238
+ // newText is already stripped of the span
239
+ }
240
+ else {
241
+ // Apply new alignment
242
+ var style = "display: block; text-align: " + alignType;
243
+ finalWrapped = "<span style=\"" + style + "\">" + newText + "</span>";
244
+ }
245
+ try {
246
+ tr.replaceWith(targetFrom, targetTo, schema.text(finalWrapped));
247
+ dispatch(tr);
248
+ return true;
249
+ }
250
+ catch (e) {
251
+ return false;
252
+ }
253
+ }
254
+ function execWysiwygAlign(alignType, selection, schema, tr, dispatch) {
255
+ var empty = selection.empty;
256
+ var styleBase = 'display: block; text-align: ';
257
+ var targetFrom = selection.from;
258
+ var targetTo = selection.to;
259
+ var markType = schema.marks.span;
260
+ if (!markType)
261
+ return false;
262
+ if (empty) {
263
+ var $from = selection.$from;
264
+ var blockRange = $from.blockRange();
265
+ if (blockRange) {
266
+ targetFrom = blockRange.start;
267
+ targetTo = blockRange.end;
268
+ }
269
+ }
270
+ var existingMark = null;
271
+ var existingAlign = null;
272
+ tr.doc.nodesBetween(targetFrom, targetTo, function (node) {
273
+ if (existingMark)
274
+ return false;
275
+ node.marks.forEach(function (mark) {
276
+ if (mark.type === markType && mark.attrs.style && mark.attrs.style.indexOf(styleBase) > -1) {
277
+ existingMark = mark;
278
+ var match = mark.attrs.style.match(/text-align: (left|center|right)/);
279
+ if (match)
280
+ existingAlign = match[1];
281
+ }
282
+ });
283
+ return true;
284
+ });
285
+ if (existingMark) {
286
+ tr.removeMark(targetFrom, targetTo, existingMark);
287
+ }
288
+ if (existingAlign === alignType) {
289
+ dispatch(tr);
290
+ return true;
291
+ }
292
+ var style = "" + styleBase + alignType;
293
+ var attrs = { htmlAttrs: { style: style } };
294
+ var mark = markType.create(attrs);
295
+ tr.addMark(targetFrom, targetTo, mark);
296
+ dispatch(tr);
297
+ return true;
298
+ }
299
+
300
+ __webpack_exports__ = __webpack_exports__["default"];
301
+ /******/ return __webpack_exports__;
302
+ /******/ })()
303
+ ;
304
+ });
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@licium/editor-plugin-text-align",
3
+ "version": "1.0.0",
4
+ "description": "TOAST UI Editor : Text Align Plugin",
5
+ "keywords": [
6
+ "nhn",
7
+ "nhn cloud",
8
+ "toast",
9
+ "toastui",
10
+ "toast-ui",
11
+ "editor",
12
+ "plugin",
13
+ "text-align",
14
+ "align"
15
+ ],
16
+ "main": "dist/toastui-editor-plugin-text-align.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/text-align"
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
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }
@@ -0,0 +1,5 @@
1
+ import type { PluginContext, PluginInfo } from '@licium/editor';
2
+
3
+ export type PluginOptions = object;
4
+
5
+ export default function textAlignPlugin(context: PluginContext, options: PluginOptions): PluginInfo;