@componyx/ui 0.0.0-stage → 1.0.4

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.
Files changed (169) hide show
  1. package/AppSkin/AppSkin.css +1268 -0
  2. package/AppSkin/AppSkin.js +2748 -0
  3. package/AppSkin/Themes/Default.css +241 -0
  4. package/Base/Base.js +3407 -0
  5. package/Base/ComponentIcons.css +66 -0
  6. package/Base/Font/ComponentIcons.woff +0 -0
  7. package/Base/Font/UI.woff +0 -0
  8. package/Base/Library.js +8432 -0
  9. package/Base/NavigationManager.js +462 -0
  10. package/Base/ResponsiveTemplates.js +371 -0
  11. package/Base/Sanitizer.js +288 -0
  12. package/Base/Themes/Default.css +255 -0
  13. package/Base/UI.css +618 -0
  14. package/Base/UIResourcePath.js +6 -0
  15. package/Bindary/Bindary.js +2011 -0
  16. package/Bindary/Modules/Connection.js +216 -0
  17. package/Bindary/Modules/Core.js +854 -0
  18. package/Bindary/Modules/DataUpdater.js +351 -0
  19. package/Bindary/Modules/ExpressionEngine.js +347 -0
  20. package/Bindary/Modules/ProxyManager.js +482 -0
  21. package/Bindary/Modules/Renderer.js +605 -0
  22. package/Bindary/Modules/Router.js +291 -0
  23. package/Bindary/Modules/Scroller.js +89 -0
  24. package/Bindary/Modules/Template.js +1273 -0
  25. package/BookmarkSpy/BookmarkSpy.js +430 -0
  26. package/Box/Box.css +36 -0
  27. package/Box/Box.js +1685 -0
  28. package/Button/Button.css +470 -0
  29. package/Button/Button.js +1398 -0
  30. package/Button/Themes/Default.css +200 -0
  31. package/Carousel/Carousel.css +273 -0
  32. package/Carousel/Carousel.js +607 -0
  33. package/ColorButton/ColorButton.css +39 -0
  34. package/ColorButton/ColorButton.js +336 -0
  35. package/ColorPicker/ColorPicker.css +359 -0
  36. package/ColorPicker/ColorPicker.js +972 -0
  37. package/ComboBox/ComboBox.css +357 -0
  38. package/ComboBox/ComboBox.js +2342 -0
  39. package/ComboBox/Themes/Default.css +23 -0
  40. package/DataPager/DataPager.css +72 -0
  41. package/DataPager/DataPager.js +674 -0
  42. package/DatePicker/DatePicker.css +227 -0
  43. package/DatePicker/DatePicker.js +1531 -0
  44. package/DatePicker/Themes/Default.css +26 -0
  45. package/Dialog/Dialog.css +106 -0
  46. package/Dialog/Dialog.js +572 -0
  47. package/Dialog/Themes/Default.css +10 -0
  48. package/Editor/Data/Emoji.json +8285 -0
  49. package/Editor/Data/Special.json +1042 -0
  50. package/Editor/Editor.css +1562 -0
  51. package/Editor/Editor.js +4058 -0
  52. package/Editor/Font/Editor.woff +0 -0
  53. package/Editor/Modules/ComponentFactory.js +565 -0
  54. package/Editor/Modules/ContentManager.js +748 -0
  55. package/Editor/Modules/DialogManager.js +1234 -0
  56. package/Editor/Modules/EventManager.js +458 -0
  57. package/Editor/Modules/Format.js +950 -0
  58. package/Editor/Modules/History.js +191 -0
  59. package/Editor/Modules/LayoutState.js +379 -0
  60. package/Editor/Modules/ListManager.js +296 -0
  61. package/Editor/Modules/MenuManager.js +388 -0
  62. package/Editor/Modules/NodeManager.js +681 -0
  63. package/Editor/Modules/ParagraphButtons.js +122 -0
  64. package/Editor/Modules/Resizer.js +176 -0
  65. package/Editor/Modules/SelectionRange.js +564 -0
  66. package/Editor/Modules/SourceViewBuilder.js +212 -0
  67. package/Editor/Modules/SymbolPicker.js +208 -0
  68. package/Editor/Modules/Table.js +2327 -0
  69. package/Editor/Modules/TableDialog.js +757 -0
  70. package/Editor/Modules/Toolbar.js +375 -0
  71. package/Editor/Modules/TooltipMenu.js +125 -0
  72. package/Editor/Modules/Utility.js +131 -0
  73. package/Editor/Themes/Default.css +204 -0
  74. package/FileUpload/FileUpload.css +156 -0
  75. package/FileUpload/FileUpload.js +898 -0
  76. package/FileUpload/Themes/Default.css +17 -0
  77. package/Form/Form.css +1934 -0
  78. package/Form/Form.js +4943 -0
  79. package/Form/Modules/ActionManager.js +368 -0
  80. package/Form/Modules/BuildPanelManager.js +319 -0
  81. package/Form/Modules/ComponentFactory.js +468 -0
  82. package/Form/Modules/ComponentPanel.js +265 -0
  83. package/Form/Modules/ConfigPanelManager.js +685 -0
  84. package/Form/Modules/DataBinder.js +602 -0
  85. package/Form/Modules/DataObserver.js +717 -0
  86. package/Form/Modules/Draggable.js +756 -0
  87. package/Form/Modules/OptionsPanel.js +342 -0
  88. package/Form/Modules/Renderer.js +1889 -0
  89. package/Form/Modules/RuleEngine.js +585 -0
  90. package/Form/Modules/RulesPanel.js +1158 -0
  91. package/Form/Modules/Types.js +1709 -0
  92. package/Form/Modules/ValidationManager.js +194 -0
  93. package/Form/Themes/Default.css +216 -0
  94. package/FormField/FormField.css +468 -0
  95. package/FormField/FormField.js +576 -0
  96. package/FormField/Themes/Default.css +99 -0
  97. package/Grid/Grid.css +544 -0
  98. package/Grid/Grid.js +3761 -0
  99. package/Grid/Themes/Default.css +43 -0
  100. package/LICENSE +126 -0
  101. package/MaskedTextBox/MaskedTextBox.css +28 -0
  102. package/MaskedTextBox/MaskedTextBox.js +642 -0
  103. package/MaskedTextBox/Themes/Default.css +6 -0
  104. package/Menu/Menu.css +328 -0
  105. package/Menu/Menu.js +2386 -0
  106. package/Menu/Themes/Default.css +24 -0
  107. package/NumericBox/NumericBox.css +120 -0
  108. package/NumericBox/NumericBox.js +984 -0
  109. package/PanelBar/PanelBar.css +123 -0
  110. package/PanelBar/PanelBar.js +505 -0
  111. package/PanelBar/Themes/Default.css +51 -0
  112. package/PieChart/PieChart.css +95 -0
  113. package/PieChart/PieChart.js +820 -0
  114. package/PieChart/Themes/Default.css +9 -0
  115. package/README.md +178 -3
  116. package/Slider/Slider.css +348 -0
  117. package/Slider/Slider.js +1306 -0
  118. package/Slider/Themes/Default.css +44 -0
  119. package/TabStrip/TabStrip.css +52 -0
  120. package/TabStrip/TabStrip.js +362 -0
  121. package/TabStrip/Themes/Default.css +35 -0
  122. package/TimePicker/Themes/Default.css +30 -0
  123. package/TimePicker/TimePicker.css +253 -0
  124. package/TimePicker/TimePicker.js +1485 -0
  125. package/TooltipManager/Themes/Default.css +21 -0
  126. package/TooltipManager/TooltipManager.css +227 -0
  127. package/TooltipManager/TooltipManager.js +791 -0
  128. package/Validator/Validator.css +54 -0
  129. package/Validator/Validator.js +2508 -0
  130. package/componyx.html-data.json +619 -0
  131. package/index.js +27 -0
  132. package/package.json +43 -4
  133. package/types/AppSkin.d.ts +842 -0
  134. package/types/Base.d.ts +1034 -0
  135. package/types/Bindary.d.ts +1196 -0
  136. package/types/BookmarkSpy.d.ts +112 -0
  137. package/types/Box.d.ts +374 -0
  138. package/types/Button.d.ts +455 -0
  139. package/types/Carousel.d.ts +136 -0
  140. package/types/ColorButton.d.ts +120 -0
  141. package/types/ColorPicker.d.ts +225 -0
  142. package/types/ComboBox.d.ts +507 -0
  143. package/types/DataPager.d.ts +152 -0
  144. package/types/DatePicker.d.ts +354 -0
  145. package/types/Dialog.d.ts +160 -0
  146. package/types/Editor.d.ts +1289 -0
  147. package/types/FileUpload.d.ts +206 -0
  148. package/types/Form.d.ts +3078 -0
  149. package/types/FormField.d.ts +204 -0
  150. package/types/Grid.d.ts +911 -0
  151. package/types/Library.d.ts +1899 -0
  152. package/types/MaskedTextBox.d.ts +91 -0
  153. package/types/Menu.d.ts +577 -0
  154. package/types/NumericBox.d.ts +310 -0
  155. package/types/PanelBar.d.ts +223 -0
  156. package/types/PieChart.d.ts +224 -0
  157. package/types/ResponsiveTemplates.d.ts +108 -0
  158. package/types/Slider.d.ts +227 -0
  159. package/types/TabStrip.d.ts +185 -0
  160. package/types/TimePicker.d.ts +265 -0
  161. package/types/TooltipManager.d.ts +178 -0
  162. package/types/UI.d.ts +29 -0
  163. package/types/Validator.d.ts +653 -0
  164. package/types/index.d.ts +59 -0
  165. package/ui.css +11783 -0
  166. package/ui.js +79477 -0
  167. package/ui.min.css +138 -0
  168. package/ui.min.js +264 -0
  169. package/ui.min.js.map +1 -0
@@ -0,0 +1,191 @@
1
+ /*! Componyx.UI | (c) E.H. Daanen / Componyx | BUSL-1.1 | componyx.com/license */
2
+ componyx.UI.editor_modules = componyx.UI.editor_modules || {};
3
+ /**
4
+ * History module — manages undo/redo snapshots for the editor.
5
+ * @class History
6
+ * @memberof componyx.UI.editor_modules
7
+ * @ignore
8
+ */
9
+ componyx.UI.editor_modules.History = class History
10
+ {
11
+ constructor(editor)
12
+ {
13
+ this.editor = editor;
14
+ this.historyStack = new Map();
15
+ this.cancelHistoryAction = false;
16
+ }
17
+
18
+ /** Initializes the history object. */
19
+ init(editableElement)
20
+ {
21
+ this.historyStack.set(editableElement, { items: [], index: -1 });
22
+ }
23
+
24
+ dispose()
25
+ {
26
+ this.historyStack = new Map();
27
+ }
28
+
29
+ /**
30
+ * Adds a history item.
31
+ * @param {any} range
32
+ * @param {any} marker
33
+ */
34
+ addItem(range, marker)
35
+ {
36
+ let editableElement = this.editor.getEditorElement();
37
+
38
+ if (this.cancelHistoryAction || !this.hasDocumentChanged())
39
+ {
40
+ if (marker)
41
+ this.editor.selectionRange.removeRangeMarker(marker);
42
+
43
+ return;
44
+ }
45
+
46
+ let blockViewOn = this.editor.isBlockViewSelected();
47
+ this.editor.activateDocument();
48
+
49
+ this.editor.hideOverlays();
50
+ this.editor.disableBlockView();
51
+ range = this.editor.selectionRange.ensureTextRange(range || this.editor.selectionRange.getRange());
52
+
53
+ let history = this.historyStack.get(editableElement),
54
+ deleteCount = history.items.length - (history.index + 1),
55
+ snapshot = {
56
+ marker: marker || this.editor.selectionRange.createRangeMarker(range),
57
+ html: editableElement.innerHTML
58
+ };
59
+
60
+ if (blockViewOn)
61
+ {
62
+ this.editor.toggleBlockView(true);
63
+ }
64
+
65
+ range = this.editor.selectionRange.restoreRangeToMarker(snapshot.marker, editableElement.ownerDocument.createRange());
66
+ this.editor.selectionRange.removeRangeMarker(snapshot.marker);
67
+ editableElement.normalize();
68
+ this.editor.selectionRange.selectNodesInRange(range);
69
+
70
+ if (deleteCount > 0)
71
+ history.items.splice(deleteCount * -1);
72
+
73
+ history.items.push(snapshot);
74
+ const maxLength = this.editor.maxHistoryLength;
75
+ if (maxLength && history.items.length > maxLength)
76
+ {
77
+ const overflow = history.items.length - maxLength;
78
+ history.items.splice(0, overflow);
79
+ }
80
+
81
+ history.index = history.items.length - 1;
82
+
83
+ if (history.index > 0)
84
+ this.editor.getComponent('undo').enable();
85
+
86
+ this.editor.getComponent('redo').disable();
87
+
88
+ return range;
89
+ }
90
+
91
+ /** Undoes an action. */
92
+ undo(editableElement)
93
+ {
94
+ let history = this.historyStack.get(editableElement);
95
+
96
+ if (history.index == 0)
97
+ return;
98
+
99
+ history.index--;
100
+ this.restoreItem();
101
+ this.editor.getComponent('redo').enable();
102
+
103
+ if (history.index == 0)
104
+ this.editor.getComponent('undo').disable();
105
+
106
+ this.editor.events.onUndo.fire(this.editor, null);
107
+ }
108
+
109
+ /** Redoes an action. */
110
+ redo(editableElement)
111
+ {
112
+ let history = this.historyStack.get(editableElement);
113
+
114
+ if (history.index == (history.items.length - 1))
115
+ return;
116
+
117
+ history.index++;
118
+ this.restoreItem();
119
+ this.editor.getComponent('undo').enable();
120
+
121
+ if (history.index == (history.items.length - 1))
122
+ this.editor.getComponent('redo').disable();
123
+
124
+ this.editor.events.onRedo.fire(this.editor, null);
125
+ }
126
+
127
+ /**
128
+ * Restores the editor state to a history item.
129
+ */
130
+ restoreItem()
131
+ {
132
+ this.editor.activateDocument();
133
+
134
+ let editableElement = this.editor.getEditorElement(),
135
+ history = this.historyStack.get(editableElement),
136
+ snapshot = history.items[history.index];
137
+
138
+ this.editor.hideOverlays();
139
+ this.editor.disableBlockView();
140
+ editableElement.innerHTML = snapshot.html;
141
+ this.editor.contentManager.createSelectables(editableElement);
142
+ let range = this.editor.selectionRange.restoreRangeToMarker(snapshot.marker, editableElement.ownerDocument.createRange());
143
+ this.editor.selectionRange.removeRangeMarker(snapshot.marker);
144
+ this.editor.selectionRange.selectNodesInRange(range);
145
+
146
+ if (this.editor.isBlockViewSelected())
147
+ this.editor.toggleBlockView(true);
148
+ }
149
+
150
+ /** Returns a value indicating if the document has changed. */
151
+ hasDocumentChanged()
152
+ {
153
+ let editableElement = this.editor.getEditorElement();
154
+ let history = this.historyStack.get(editableElement);
155
+
156
+ if ($lib.isEmpty(history.items))
157
+ return true;
158
+
159
+ let item = history.items[history.index],
160
+ marker = item.marker,
161
+ tempEl = $lib.element('', '', '', [item.html]);
162
+
163
+ $lib.remove(tempEl.querySelector('#' + marker.startId));
164
+
165
+ if (marker.endId)
166
+ $lib.remove(tempEl.querySelector('#' + marker.endId));
167
+
168
+ return tempEl.innerHTML != editableElement.innerHTML;
169
+ }
170
+
171
+ /**
172
+ * Disables history tracking for the specified method.
173
+ * @param {any} method
174
+ */
175
+ noHistory(method)
176
+ {
177
+ this.cancelHistoryAction = true;
178
+ let result = method();
179
+ this.cancelHistoryAction = false;
180
+ return result;
181
+ }
182
+
183
+ destroy()
184
+ {
185
+ this.historyStack = new Map();
186
+ }
187
+ };
188
+
189
+ var History = componyx.UI.editor_modules.History;
190
+
191
+ export { History as default };
@@ -0,0 +1,379 @@
1
+ /*! Componyx.UI | (c) E.H. Daanen / Componyx | BUSL-1.1 | componyx.com/license */
2
+ componyx.UI.editor_modules = componyx.UI.editor_modules || {};
3
+
4
+ /**
5
+ * LayoutState module - layout state tracking and updates.
6
+ * @class LayoutState
7
+ * @memberof componyx.UI.editor_modules
8
+ * @ignore
9
+ */
10
+ componyx.UI.editor_modules.LayoutState = class LayoutState
11
+ {
12
+ constructor(editor)
13
+ {
14
+ this.editor = editor;
15
+ this.utility = editor.utility;
16
+ this.tree = null;
17
+ this.activeLayout = {};
18
+ this.activeMode = { editableElement: null, keys: {} };
19
+ this.checkCommands = [];
20
+ }
21
+
22
+ /** Initializes layout settings. */
23
+ init()
24
+ {
25
+ this.activeLayout.block = 'P';
26
+ this.activeLayout.align = 'left';
27
+ this.activeLayout.fontSize = this.editor.defaultFontSize;
28
+ this.activeLayout.fontFamily = this.editor.defaultFontFamily;
29
+ this.activeLayout.styleItem = {};
30
+
31
+ this.checkCommands = this.editor.getSortedCommands().filter((cmd) => { return !$lib.isEmpty(cmd.isActive) });
32
+ this.checkCommands.forEach((cmd) => { this.activeLayout[cmd.id] = null; });
33
+ }
34
+
35
+ dispose()
36
+ {
37
+ this.editor = null;
38
+ this.utility = null;
39
+ this.tree = null;
40
+ this.activeLayout = {};
41
+ this.activeMode = { editableElement: null, keys: {} };
42
+ this.checkCommands = [];
43
+ }
44
+
45
+ /** Gets the layout state. */
46
+ getState()
47
+ {
48
+ this.editor.activateDocument();
49
+ let range = this.editor.selectionRange.getRange();
50
+
51
+ if (range)
52
+ {
53
+ let sContainer = range.startContainer,
54
+ el = (sContainer.nodeType == 1) ? sContainer : sContainer.parentElement,
55
+ rootEl = this.editor.nodeManager.getRootNode(el),
56
+ nodes = this.getSurroundingLayoutNodes(el, rootEl),
57
+ layoutNodes = nodes.layoutNodes,
58
+ tree = nodes.tree;
59
+
60
+ if (tree.length)
61
+ {
62
+ if (this.tree && this.tree.length == tree.length)
63
+ {
64
+ let change = false;
65
+
66
+ $lib.each(this.tree, (n, i) =>
67
+ {
68
+ return !(change = !n.isEqualNode(tree[i]));
69
+ });
70
+
71
+ if (!change)
72
+ return; // selection and nodes within selection have not changed
73
+ }
74
+
75
+ this.tree = [];
76
+ $lib.each(tree, (n, i) =>
77
+ {
78
+ this.tree.push(n.cloneNode(true));
79
+ });
80
+
81
+ this.activeLayout.block = rootEl.nodeName;
82
+ this.activeLayout.align = rootEl.style.textAlign || this.editor.defaultAlign;
83
+ this.activeLayout.lineHeight = rootEl.style.lineHeight || this.editor.defaultLineHeight;
84
+
85
+ this.activeLayout.fontFamily = this.editor.defaultFontFamily;
86
+ this.activeLayout.styleItem = {};
87
+
88
+ this.detectFontSize(el, layoutNodes);
89
+
90
+ if (layoutNodes.fontFamilyNode)
91
+ this.activeLayout.fontFamily = layoutNodes.fontFamilyNode.style.fontFamily.replace(/\"/g, '');
92
+
93
+ if (layoutNodes.styleNode)
94
+ {
95
+ let menuItem = this.editor.menuManager.loadMenuItem(layoutNodes.styleNode.getAttribute(this.utility.attrPrefix + 'styleid'));
96
+ if (menuItem)
97
+ this.activeLayout.styleItem = menuItem.item;
98
+ }
99
+
100
+ this.checkCommands.forEach((cmd) =>
101
+ {
102
+ this.activeLayout[cmd.id] = layoutNodes[cmd.id];
103
+ });
104
+
105
+ if (!this.editor.hasEditables())
106
+ {
107
+ this.updatePath(tree);
108
+ this.updateWordCount();
109
+ }
110
+ }
111
+ }
112
+
113
+ this.updateLayoutSettings();
114
+ }
115
+
116
+ /**
117
+ * Gets the surrounding layout-nodes for the specified element.
118
+ * @param {Node} el
119
+ * @param {Node} rootEl
120
+ */
121
+ getSurroundingLayoutNodes(el, rootEl)
122
+ {
123
+ let layoutNodes = {},
124
+ nodes = [],
125
+ checkCommands = this.checkCommands.slice(),
126
+ editableElement = this.editor.getEditorElement();
127
+
128
+ while (el && el != editableElement)
129
+ {
130
+ nodes.push(el);
131
+
132
+ if (el != rootEl)
133
+ {
134
+ if (!$lib.isEmpty(el.style.fontSize) && !layoutNodes.fontSizeNode)
135
+ layoutNodes.fontSizeNode = el;
136
+
137
+ if (!$lib.isEmpty(el.style.fontFamily) && !layoutNodes.fontFamilyNode)
138
+ layoutNodes.fontFamilyNode = el;
139
+ }
140
+
141
+ if (!$lib.isEmpty(el.getAttribute(this.utility.attrPrefix + 'styleid')) && !layoutNodes.styleNode)
142
+ layoutNodes.styleNode = el;
143
+
144
+ $lib.each(checkCommands, (cmd, index) =>
145
+ {
146
+ if (cmd.isActive(el, cmd))
147
+ {
148
+ layoutNodes[cmd.id] = (cmd.getNode) ? cmd.getNode(el) : el;
149
+ }
150
+ });
151
+
152
+ el = (el == rootEl) ? null : el.parentElement;
153
+ }
154
+
155
+ return { layoutNodes: layoutNodes, tree: nodes.reverse() };
156
+ }
157
+
158
+ /**
159
+ * Detects and sets the font size
160
+ * @param {Node} el
161
+ * @param {Object} layoutNodes
162
+ */
163
+ detectFontSize(el, layoutNodes)
164
+ {
165
+ let fontSize = this.getFontSize(el);
166
+
167
+ if (layoutNodes.fontSizeNode && (layoutNodes.fontSizeNode == el || this.getFontSize(layoutNodes.fontSizeNode) == fontSize))
168
+ this.activeLayout.fontSize = layoutNodes.fontSizeNode.style.fontSize;
169
+ else
170
+ {
171
+ this.activeLayout.fontSize = fontSize;
172
+
173
+ let itemPath = this.editor.menuManager.loadMenuItem('fontSize_' + fontSize);
174
+
175
+ if (!itemPath && this.editor.addMissingFontSize)
176
+ {
177
+ this.deselectMenuItem('fontSize');
178
+ this.editor.menuManager.buildFontSizeMenu([fontSize]);
179
+ this.editor.deactivateDocument();
180
+ this.editor.menuManager.renderMenuItem('FontSize');
181
+ this.editor.activateDocument();
182
+ }
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Gets the computed font size
188
+ * @param {Node} el
189
+ */
190
+ getFontSize(el)
191
+ {
192
+ let fontSize = window.getComputedStyle(el, null).getPropertyValue('font-size');
193
+ return parseFloat(fontSize) + 'px';
194
+ }
195
+
196
+ /** Updates layout settings. */
197
+ updateLayoutSettings()
198
+ {
199
+ this.updateContent('block', this.activeLayout.block);
200
+ this.updateContent('fontFamily', this.activeLayout.fontFamily);
201
+ this.updateContent('fontSize', this.activeLayout.fontSize);
202
+ this.updateContent('align', this.activeLayout.align);
203
+ this.updateContent('lineHeight', this.activeLayout.lineHeight);
204
+ this.updateContent('style', this.activeLayout.styleItem.text, this.activeLayout.styleItem.id);
205
+
206
+ this.checkCommands.forEach((cmd) =>
207
+ {
208
+ let name = cmd.id,
209
+ button = this.editor.getComponent(name);
210
+
211
+ if (!button)
212
+ return;
213
+
214
+ if (this.activeLayout[name] && !button.selected)
215
+ button.select();
216
+ else if (!this.activeLayout[name] && button.selected)
217
+ button.deselect();
218
+ });
219
+ }
220
+
221
+ /**
222
+ * Updates button content and menu selection
223
+ * @param {string} buttonId
224
+ * @param {string} text
225
+ * @param {string} id
226
+ */
227
+ updateContent(buttonId, text, id)
228
+ {
229
+ if (!id)
230
+ id = text;
231
+
232
+ let menuItemId = buttonId + '_' + id,
233
+ button = this.editor.getComponent(buttonId),
234
+ itemPath = this.editor.menuManager.loadMenuItem(menuItemId);
235
+
236
+ if (!itemPath)
237
+ return this.deselectMenuItem(buttonId);
238
+
239
+ if (button && !button.hasIcon)
240
+ {
241
+ button.text = text;
242
+ button.updateContent();
243
+ }
244
+
245
+ this.cancelMenuItemCommand(itemPath.item);
246
+ this.editor.menuManager.selectMenuItem(menuItemId);
247
+ }
248
+
249
+ /**
250
+ * Cancel menu-item command.
251
+ * @param {Object} item
252
+ */
253
+ cancelMenuItemCommand(item)
254
+ {
255
+ let command = item.command;
256
+ item.command = function ()
257
+ {
258
+ item.command = command;
259
+ };
260
+ }
261
+
262
+ /**
263
+ * Deselect the selected menu-item for the specified group
264
+ * @param {string} buttonId
265
+ */
266
+ deselectMenuItem(buttonId)
267
+ {
268
+ let selectedId = this.editor.menuManager.getSelectedItemId(buttonId);
269
+
270
+ if (selectedId)
271
+ this.editor.menuManager.deselectMenuItem(selectedId);
272
+ }
273
+
274
+ /**
275
+ * Updates the document node path.
276
+ * @param {Node[]} tree
277
+ */
278
+ updatePath(tree)
279
+ {
280
+ let pathEl = this.editor.getPathElement();
281
+
282
+ if (!pathEl)
283
+ return;
284
+
285
+ let length = tree.length;
286
+
287
+ pathEl.innerHTML = '';
288
+
289
+ $lib.each(tree, (node, index) =>
290
+ {
291
+ $lib.on($lib.element(pathEl, '', '', node.nodeName.toLowerCase(), '', { className: 'path-item' }),
292
+ 'click',
293
+ this.editor.selectNode.bind(node, true));
294
+
295
+ if (length > index + 1)
296
+ $lib.element(pathEl, '', '', '›', '', { className: 'path-divider' });
297
+ });
298
+ }
299
+
300
+ /** Updates the document word count. */
301
+ updateWordCount()
302
+ {
303
+ let wordCountEl = this.editor.getWordCountElement();
304
+
305
+ if (!wordCountEl)
306
+ return;
307
+
308
+ wordCountEl.innerHTML = '';
309
+ this.editor.applyTemplate(wordCountEl, 'WordCount', this.getWordCount());
310
+ }
311
+
312
+ /** Gets the document word count. */
313
+ getWordCount()
314
+ {
315
+ let editableElement = this.editor.getEditorElement(),
316
+ t = editableElement.textContent,
317
+ words = [];
318
+
319
+ $lib.each(editableElement.childNodes, (el) =>
320
+ {
321
+ let lineWords = el.textContent.replace(/\n+/g, ' ').replace(/\s+/g, ' ').replace(/^\s+/, '').replace(/\s+$/, '').split(' ');
322
+
323
+ if (lineWords[0] == '')
324
+ lineWords.shift();
325
+
326
+ words = words.concat(lineWords);
327
+ });
328
+
329
+ return {
330
+ words: words.length,
331
+ chars: t.replace(/\n+/g, '').length
332
+ };
333
+ }
334
+
335
+ /**
336
+ * Adds an active mode.
337
+ * @param {string} key
338
+ * @param {Function} toggleMethod
339
+ */
340
+ addActiveMode(key, toggleMethod)
341
+ {
342
+ this.activeMode.editableElement = this.editor.getEditorElement();
343
+ this.activeMode.keys[key] = toggleMethod.bind(this.editor, false);
344
+ }
345
+
346
+ /**
347
+ * Removes an active mode.
348
+ * @param {string} key
349
+ */
350
+ removeActiveMode(key)
351
+ {
352
+ delete this.activeMode.keys[key];
353
+ }
354
+
355
+ /**
356
+ * Resets all active modes.
357
+ */
358
+ resetActiveModes()
359
+ {
360
+ let editableElement = this.editor.getEditorElement();
361
+
362
+ if (!this.activeMode.editableElement || this.activeMode.editableElement == editableElement || $lib.isEmpty(this.activeMode.keys))
363
+ return;
364
+
365
+ let currentEditableElement = editableElement;
366
+ this.editor.setActiveEditor(this.activeMode.editableElement);
367
+
368
+ $lib.each(this.activeMode.keys, function (method)
369
+ {
370
+ method();
371
+ });
372
+
373
+ this.editor.setActiveEditor(currentEditableElement);
374
+ }
375
+ };
376
+
377
+ var LayoutState = componyx.UI.editor_modules.LayoutState;
378
+
379
+ export { LayoutState as default };