@pie-lib/editable-html 11.4.0 → 11.6.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +24 -52
  2. package/package.json +8 -7
  3. package/src/editor.jsx +2 -2
  4. package/src/plugins/media/media-dialog.js +1 -1
  5. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +1 -1
  6. package/src/plugins/toolbar/editor-and-toolbar.jsx +1 -1
  7. package/lib/block-tags.js +0 -25
  8. package/lib/block-tags.js.map +0 -1
  9. package/lib/constants.js +0 -16
  10. package/lib/constants.js.map +0 -1
  11. package/lib/editor.js +0 -1355
  12. package/lib/editor.js.map +0 -1
  13. package/lib/index.js +0 -269
  14. package/lib/index.js.map +0 -1
  15. package/lib/parse-html.js +0 -16
  16. package/lib/parse-html.js.map +0 -1
  17. package/lib/plugins/characters/custom-popper.js +0 -73
  18. package/lib/plugins/characters/custom-popper.js.map +0 -1
  19. package/lib/plugins/characters/index.js +0 -305
  20. package/lib/plugins/characters/index.js.map +0 -1
  21. package/lib/plugins/characters/utils.js +0 -381
  22. package/lib/plugins/characters/utils.js.map +0 -1
  23. package/lib/plugins/css/icons/index.js +0 -37
  24. package/lib/plugins/css/icons/index.js.map +0 -1
  25. package/lib/plugins/css/index.js +0 -397
  26. package/lib/plugins/css/index.js.map +0 -1
  27. package/lib/plugins/customPlugin/index.js +0 -114
  28. package/lib/plugins/customPlugin/index.js.map +0 -1
  29. package/lib/plugins/html/icons/index.js +0 -38
  30. package/lib/plugins/html/icons/index.js.map +0 -1
  31. package/lib/plugins/html/index.js +0 -80
  32. package/lib/plugins/html/index.js.map +0 -1
  33. package/lib/plugins/image/alt-dialog.js +0 -129
  34. package/lib/plugins/image/alt-dialog.js.map +0 -1
  35. package/lib/plugins/image/component.js +0 -419
  36. package/lib/plugins/image/component.js.map +0 -1
  37. package/lib/plugins/image/image-toolbar.js +0 -177
  38. package/lib/plugins/image/image-toolbar.js.map +0 -1
  39. package/lib/plugins/image/index.js +0 -263
  40. package/lib/plugins/image/index.js.map +0 -1
  41. package/lib/plugins/image/insert-image-handler.js +0 -161
  42. package/lib/plugins/image/insert-image-handler.js.map +0 -1
  43. package/lib/plugins/index.js +0 -402
  44. package/lib/plugins/index.js.map +0 -1
  45. package/lib/plugins/list/index.js +0 -334
  46. package/lib/plugins/list/index.js.map +0 -1
  47. package/lib/plugins/math/index.js +0 -454
  48. package/lib/plugins/math/index.js.map +0 -1
  49. package/lib/plugins/media/index.js +0 -387
  50. package/lib/plugins/media/index.js.map +0 -1
  51. package/lib/plugins/media/media-dialog.js +0 -709
  52. package/lib/plugins/media/media-dialog.js.map +0 -1
  53. package/lib/plugins/media/media-toolbar.js +0 -101
  54. package/lib/plugins/media/media-toolbar.js.map +0 -1
  55. package/lib/plugins/media/media-wrapper.js +0 -93
  56. package/lib/plugins/media/media-wrapper.js.map +0 -1
  57. package/lib/plugins/rendering/index.js +0 -46
  58. package/lib/plugins/rendering/index.js.map +0 -1
  59. package/lib/plugins/respArea/drag-in-the-blank/choice.js +0 -254
  60. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +0 -1
  61. package/lib/plugins/respArea/drag-in-the-blank/index.js +0 -97
  62. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +0 -1
  63. package/lib/plugins/respArea/explicit-constructed-response/index.js +0 -57
  64. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +0 -1
  65. package/lib/plugins/respArea/icons/index.js +0 -95
  66. package/lib/plugins/respArea/icons/index.js.map +0 -1
  67. package/lib/plugins/respArea/index.js +0 -341
  68. package/lib/plugins/respArea/index.js.map +0 -1
  69. package/lib/plugins/respArea/inline-dropdown/index.js +0 -75
  70. package/lib/plugins/respArea/inline-dropdown/index.js.map +0 -1
  71. package/lib/plugins/respArea/math-templated/index.js +0 -130
  72. package/lib/plugins/respArea/math-templated/index.js.map +0 -1
  73. package/lib/plugins/respArea/utils.js +0 -125
  74. package/lib/plugins/respArea/utils.js.map +0 -1
  75. package/lib/plugins/table/CustomTablePlugin.js +0 -133
  76. package/lib/plugins/table/CustomTablePlugin.js.map +0 -1
  77. package/lib/plugins/table/icons/index.js +0 -69
  78. package/lib/plugins/table/icons/index.js.map +0 -1
  79. package/lib/plugins/table/index.js +0 -483
  80. package/lib/plugins/table/index.js.map +0 -1
  81. package/lib/plugins/table/table-toolbar.js +0 -187
  82. package/lib/plugins/table/table-toolbar.js.map +0 -1
  83. package/lib/plugins/textAlign/icons/index.js +0 -226
  84. package/lib/plugins/textAlign/icons/index.js.map +0 -1
  85. package/lib/plugins/textAlign/index.js +0 -34
  86. package/lib/plugins/textAlign/index.js.map +0 -1
  87. package/lib/plugins/toolbar/default-toolbar.js +0 -229
  88. package/lib/plugins/toolbar/default-toolbar.js.map +0 -1
  89. package/lib/plugins/toolbar/done-button.js +0 -53
  90. package/lib/plugins/toolbar/done-button.js.map +0 -1
  91. package/lib/plugins/toolbar/editor-and-toolbar.js +0 -286
  92. package/lib/plugins/toolbar/editor-and-toolbar.js.map +0 -1
  93. package/lib/plugins/toolbar/index.js +0 -34
  94. package/lib/plugins/toolbar/index.js.map +0 -1
  95. package/lib/plugins/toolbar/toolbar-buttons.js +0 -194
  96. package/lib/plugins/toolbar/toolbar-buttons.js.map +0 -1
  97. package/lib/plugins/toolbar/toolbar.js +0 -376
  98. package/lib/plugins/toolbar/toolbar.js.map +0 -1
  99. package/lib/plugins/utils.js +0 -62
  100. package/lib/plugins/utils.js.map +0 -1
  101. package/lib/serialization.js +0 -677
  102. package/lib/serialization.js.map +0 -1
  103. package/lib/shared/alert-dialog.js +0 -75
  104. package/lib/shared/index.js +0 -136
  105. package/lib/theme.js +0 -9
  106. package/lib/theme.js.map +0 -1
@@ -1,397 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = CSSPlugin;
9
- exports.removeDialogs = void 0;
10
-
11
- var _react = _interopRequireDefault(require("react"));
12
-
13
- var _reactDom = _interopRequireDefault(require("react-dom"));
14
-
15
- var _List = _interopRequireDefault(require("@material-ui/core/List"));
16
-
17
- var _slate = require("slate");
18
-
19
- var _immutable = _interopRequireDefault(require("immutable"));
20
-
21
- var _ListItem = _interopRequireDefault(require("@material-ui/core/ListItem"));
22
-
23
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
24
-
25
- var _debug = _interopRequireDefault(require("debug"));
26
-
27
- var _icons = _interopRequireDefault(require("./icons"));
28
-
29
- var log = (0, _debug["default"])('@pie-lib:editable-html:plugins:characters');
30
-
31
- var removeDialogs = function removeDialogs() {
32
- var prevDialogs = document.querySelectorAll('.insert-css-dialog');
33
- log('[characters:removeDialogs]');
34
- prevDialogs.forEach(function (s) {
35
- return s.remove();
36
- });
37
- };
38
-
39
- exports.removeDialogs = removeDialogs;
40
-
41
- var insertDialog = function insertDialog(_ref) {
42
- var _parentNode$data, _parentNode$data$get;
43
-
44
- var editorDOM = _ref.editorDOM,
45
- value = _ref.value,
46
- callback = _ref.callback,
47
- opts = _ref.opts,
48
- textNode = _ref.textNode,
49
- parentNode = _ref.parentNode;
50
- var newEl = document.createElement('div');
51
- log('[characters:insertDialog]');
52
- removeDialogs();
53
- newEl.className = 'insert-css-dialog';
54
- var popoverEl;
55
-
56
- var closePopOver = function closePopOver() {
57
- if (popoverEl) {
58
- popoverEl.remove();
59
- }
60
- };
61
-
62
- var firstCallMade = false;
63
-
64
- var listener = function listener(e) {
65
- // this will be triggered right after setting it because
66
- // this toolbar is added on the mousedown event
67
- // so right after mouseup, the click will be triggered
68
- if (firstCallMade) {
69
- var focusIsInModals = newEl.contains(e.target) || popoverEl && popoverEl.contains(e.target);
70
- var focusIsInEditor = editorDOM.contains(e.target);
71
-
72
- if (!(focusIsInModals || focusIsInEditor)) {
73
- handleClose();
74
- }
75
- } else {
76
- firstCallMade = true;
77
- }
78
- };
79
-
80
- var handleClose = function handleClose() {
81
- callback(undefined, true);
82
- newEl.remove();
83
- closePopOver();
84
- document.body.removeEventListener('click', listener);
85
- };
86
-
87
- var handleChange = function handleChange(name) {
88
- callback(name, true);
89
- newEl.remove();
90
- closePopOver();
91
- document.body.removeEventListener('click', listener);
92
- };
93
-
94
- var selectedText = textNode.text.slice(value.selection.anchorOffset, value.selection.focusOffset);
95
- var parentNodeClass = parentNode === null || parentNode === void 0 ? void 0 : (_parentNode$data = parentNode.data) === null || _parentNode$data === void 0 ? void 0 : (_parentNode$data$get = _parentNode$data.get('attributes')) === null || _parentNode$data$get === void 0 ? void 0 : _parentNode$data$get["class"];
96
-
97
- var createHTML = function createHTML(name) {
98
- var html = "<span class=\"".concat(name, "\">").concat(selectedText, "</span>");
99
-
100
- if (parentNode) {
101
- var tag;
102
-
103
- if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.object) === 'inline') {
104
- tag = 'span';
105
- }
106
-
107
- if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.object) === 'block') {
108
- tag = 'div';
109
- }
110
-
111
- html = "<".concat(tag, " class=\"").concat(parentNodeClass, "\">").concat(parentNode.text.slice(0, value.selection.anchorOffset)).concat(html).concat(parentNode.text.slice(value.selection.focusOffset), "</").concat(tag, ">");
112
- }
113
-
114
- return html;
115
- };
116
-
117
- var el = /*#__PURE__*/_react["default"].createElement("div", {
118
- style: {
119
- background: 'white',
120
- height: 500,
121
- padding: 20,
122
- overflow: 'hidden',
123
- display: 'flex',
124
- flexFlow: 'column'
125
- }
126
- }, /*#__PURE__*/_react["default"].createElement("h2", null, "Please choose a css class"), parentNodeClass && /*#__PURE__*/_react["default"].createElement("div", null, "The current parent has this class ", parentNodeClass), /*#__PURE__*/_react["default"].createElement(_List["default"], {
127
- component: "nav",
128
- style: {
129
- overflow: 'scroll'
130
- }
131
- }, opts.names.map(function (name, i) {
132
- return /*#__PURE__*/_react["default"].createElement(_ListItem["default"], {
133
- key: "rule-".concat(i),
134
- button: true,
135
- onClick: function onClick() {
136
- return handleChange(name);
137
- }
138
- }, /*#__PURE__*/_react["default"].createElement("div", {
139
- style: {
140
- marginRight: 20
141
- }
142
- }, name), /*#__PURE__*/_react["default"].createElement("div", {
143
- dangerouslySetInnerHTML: {
144
- __html: createHTML(name)
145
- }
146
- }));
147
- })));
148
-
149
- _reactDom["default"].render(el, newEl, function () {
150
- var cursorItem = document.querySelector("[data-key=\"".concat(value.anchorKey, "\"]"));
151
-
152
- if (cursorItem) {
153
- var bodyRect = editorDOM.parentElement.parentElement.parentElement.getBoundingClientRect();
154
- var boundRect = cursorItem.getBoundingClientRect();
155
- editorDOM.parentElement.parentElement.parentElement.appendChild(newEl); // when height of toolbar exceeds screen - can happen in scrollable contexts
156
-
157
- var additionalTopOffset = 0;
158
-
159
- if (boundRect.y < newEl.offsetHeight) {
160
- additionalTopOffset = newEl.offsetHeight - boundRect.y + 10;
161
- }
162
-
163
- newEl.style.maxWidth = '500px';
164
- newEl.style.position = 'absolute';
165
- newEl.style.top = 0;
166
- newEl.style.zIndex = 99999;
167
- var leftValue = "".concat(boundRect.left + Math.abs(bodyRect.left) + cursorItem.offsetWidth + 10, "px");
168
- var rightValue = "".concat(boundRect.x, "px");
169
- newEl.style.left = leftValue;
170
- var leftAlignedWidth = newEl.offsetWidth;
171
- newEl.style.left = 'unset';
172
- newEl.style.right = rightValue;
173
- var rightAlignedWidth = newEl.offsetWidth;
174
- newEl.style.left = 'unset';
175
- newEl.style.right = 'unset';
176
-
177
- if (leftAlignedWidth >= rightAlignedWidth) {
178
- newEl.style.left = leftValue;
179
- } else {
180
- newEl.style.right = rightValue;
181
- }
182
-
183
- document.body.addEventListener('click', listener);
184
- }
185
- });
186
- };
187
-
188
- var findParentNodeInfo = function findParentNodeInfo(value, textNode) {
189
- var _closestInline$nodes, _closestBlock$nodes;
190
-
191
- var closestInline = value.document.getClosestInline(value.selection.endKey);
192
- var closestBlock = value.document.getClosestBlock(value.selection.endKey);
193
- var nodeToUse = null;
194
-
195
- if (closestInline !== null && closestInline !== void 0 && (_closestInline$nodes = closestInline.nodes) !== null && _closestInline$nodes !== void 0 && _closestInline$nodes.find(function (n) {
196
- return n.key === textNode.key;
197
- })) {
198
- nodeToUse = closestInline;
199
- }
200
-
201
- if (closestBlock !== null && closestBlock !== void 0 && (_closestBlock$nodes = closestBlock.nodes) !== null && _closestBlock$nodes !== void 0 && _closestBlock$nodes.find(function (n) {
202
- return n.key === textNode.key;
203
- })) {
204
- nodeToUse = closestBlock;
205
- }
206
-
207
- return nodeToUse;
208
- };
209
- /**
210
- * Find the node that has a class attribute and return it.
211
- * Keeping this in case the implementation of classes needs to be changed
212
- * @param value
213
- * @param opts
214
- * @returns {*}
215
- */
216
-
217
-
218
- var getNodeWithClass = function getNodeWithClass(value, opts) {
219
- var _blocksAtRange$, _inlinesAtRange$, _blockData$attributes, _inlineData$attribute;
220
-
221
- var blocksAtRange = value.document.getBlocksAtRangeAsArray(value.selection);
222
- var inlinesAtRange = value.document.getInlinesAtRangeAsArray(value.selection);
223
- var blockData = ((_blocksAtRange$ = blocksAtRange[0]) === null || _blocksAtRange$ === void 0 ? void 0 : _blocksAtRange$.data.toJSON()) || {};
224
- var inlineData = ((_inlinesAtRange$ = inlinesAtRange[0]) === null || _inlinesAtRange$ === void 0 ? void 0 : _inlinesAtRange$.data.toJSON()) || {};
225
-
226
- if (!((_blockData$attributes = blockData.attributes) !== null && _blockData$attributes !== void 0 && _blockData$attributes["class"]) && !((_inlineData$attribute = inlineData.attributes) !== null && _inlineData$attribute !== void 0 && _inlineData$attribute["class"])) {
227
- return null;
228
- }
229
-
230
- var _ref2 = blockData.attributes || {},
231
- blockClass = _ref2["class"];
232
-
233
- var _ref3 = inlineData.attributes || {},
234
- inlineClass = _ref3["class"];
235
-
236
- var inlineHasClass = opts.names.find(function (name) {
237
- return inlineClass.includes(name);
238
- });
239
-
240
- if (inlineHasClass) {
241
- return inlinesAtRange[0];
242
- }
243
-
244
- var blockHasClass = opts.names.find(function (name) {
245
- return blockClass.includes(name);
246
- });
247
-
248
- if (blockHasClass) {
249
- return blocksAtRange[0];
250
- }
251
-
252
- return null;
253
- };
254
- /**
255
- * Plugin in order to be able to add a css clas that is provided through the model
256
- * on a text element. Works like a mark (bold, italic etc.).
257
- * @param opts
258
- * @constructor
259
- */
260
-
261
-
262
- function CSSPlugin(opts) {
263
- var plugin = {
264
- name: 'extraCSSRules',
265
- toolbar: {
266
- isMark: true,
267
- icon: /*#__PURE__*/_react["default"].createElement(_icons["default"], null),
268
- ariaLabel: 'CSS editor',
269
- type: 'css',
270
- onToggle: function onToggle(change) {
271
- var type = 'css';
272
- var hasMark = change.value.activeMarks.find(function (entry) {
273
- return entry.type === type;
274
- });
275
-
276
- if (hasMark) {
277
- change.removeMark(hasMark);
278
- } else {
279
- var newMark = _slate.Mark.create(type);
280
-
281
- change.addMark(newMark);
282
- }
283
-
284
- return change;
285
- },
286
- onClick: function onClick(value, onChange, getFocusedValue) {
287
- var type = 'css';
288
- var hasMark = value.activeMarks.find(function (entry) {
289
- return entry.type === type;
290
- });
291
- var change = value.change();
292
-
293
- if (hasMark) {
294
- change.removeMark(hasMark);
295
- onChange(change);
296
- return;
297
- } // keeping this if implementation needs to be changed to regular blocks instead of marks
298
- // let nodeWithClass = getNodeWithClass(value, opts);
299
- //
300
- // if (nodeWithClass) {
301
- // const nodeAttributes = nodeWithClass.data.get('attributes');
302
- //
303
- // opts.names.forEach((name) => {
304
- // if (nodeAttributes.class.includes(name)) {
305
- // nodeAttributes.class = nodeAttributes.class.replace(name, '');
306
- // }
307
- // });
308
- //
309
- // // keeping only one space between classes
310
- // nodeAttributes.class = nodeAttributes.class.replace(/ +/g, ' ');
311
- //
312
- // nodeWithClass.data.set('attributes', nodeAttributes);
313
- //
314
- // let change = value.change();
315
- // change.replaceNodeByKey(nodeWithClass.key, nodeWithClass);
316
- //
317
- // onChange(change);
318
- // return;
319
- // }
320
-
321
-
322
- var editorDOM = document.querySelector("[data-key=\"".concat(value.document.key, "\"]"));
323
- var valueToUse = value;
324
-
325
- var callback = function callback(className, focus) {
326
- if (getFocusedValue) {
327
- valueToUse = getFocusedValue() || valueToUse;
328
- }
329
-
330
- if (className) {
331
- var _change = valueToUse.change();
332
-
333
- var newMark = _slate.Mark.create({
334
- object: 'mark',
335
- type: 'css',
336
- data: {
337
- attributes: {
338
- "class": className
339
- }
340
- }
341
- });
342
-
343
- _change.addMark(newMark); // keeping this if implementation needs to be changed to regular blocks instead of marks
344
- // change = change.wrapInline({ type: 'span', data: { attributes: { class: className } } });
345
- //
346
- // // change = change.splitBlockAtRange(adaptedRange);
347
- // //
348
- // // const newBlock = change.value.document.getFurthestBlock(change.value.selection.endKey);
349
- // //
350
- // // change = change.setNodeByKey(newBlock.key, { data: { attributes: { class: className } } });
351
- //
352
- // valueToUse = change.value;
353
- // log('[characters:insert]: ', value);
354
-
355
-
356
- onChange(_change);
357
- }
358
-
359
- log('[characters:click]');
360
-
361
- if (focus) {
362
- setTimeout(function () {
363
- if (editorDOM) {
364
- editorDOM.focus();
365
- }
366
- }, 0);
367
- }
368
- };
369
-
370
- var textNode = value.document.getTextsAtRangeAsArray(value.selection)[0];
371
-
372
- if (textNode) {
373
- var parentNode = findParentNodeInfo(value, textNode, opts);
374
- insertDialog({
375
- editorDOM: editorDOM,
376
- value: valueToUse,
377
- callback: callback,
378
- opts: opts,
379
- textNode: textNode,
380
- parentNode: parentNode
381
- });
382
- }
383
- }
384
- },
385
- renderMark: function renderMark(props) {
386
- if (props.mark.type === 'css') {
387
- var _ref4 = props.mark || {},
388
- data = _ref4.data;
389
-
390
- var jsonData = (data === null || data === void 0 ? void 0 : data.toJSON()) || {};
391
- return /*#__PURE__*/_react["default"].createElement("span", jsonData.attributes, props.children);
392
- }
393
- }
394
- };
395
- return plugin;
396
- }
397
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/plugins/css/index.jsx"],"names":["log","removeDialogs","prevDialogs","document","querySelectorAll","forEach","s","remove","insertDialog","editorDOM","value","callback","opts","textNode","parentNode","newEl","createElement","className","popoverEl","closePopOver","firstCallMade","listener","e","focusIsInModals","contains","target","focusIsInEditor","handleClose","undefined","body","removeEventListener","handleChange","name","selectedText","text","slice","selection","anchorOffset","focusOffset","parentNodeClass","data","get","createHTML","html","tag","object","el","background","height","padding","overflow","display","flexFlow","names","map","i","marginRight","__html","ReactDOM","render","cursorItem","querySelector","anchorKey","bodyRect","parentElement","getBoundingClientRect","boundRect","appendChild","additionalTopOffset","y","offsetHeight","style","maxWidth","position","top","zIndex","leftValue","left","Math","abs","offsetWidth","rightValue","x","leftAlignedWidth","right","rightAlignedWidth","addEventListener","findParentNodeInfo","closestInline","getClosestInline","endKey","closestBlock","getClosestBlock","nodeToUse","nodes","find","n","key","getNodeWithClass","blocksAtRange","getBlocksAtRangeAsArray","inlinesAtRange","getInlinesAtRangeAsArray","blockData","toJSON","inlineData","attributes","blockClass","inlineClass","inlineHasClass","includes","blockHasClass","CSSPlugin","plugin","toolbar","isMark","icon","ariaLabel","type","onToggle","change","hasMark","activeMarks","entry","removeMark","newMark","Mark","create","addMark","onClick","onChange","getFocusedValue","valueToUse","focus","setTimeout","getTextsAtRangeAsArray","renderMark","props","mark","jsonData","children"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,IAAMA,GAAG,GAAG,uBAAM,2CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,GAAM;AACjC,MAAMC,WAAW,GAAGC,QAAQ,CAACC,gBAAT,CAA0B,oBAA1B,CAApB;AAEAJ,EAAAA,GAAG,CAAC,4BAAD,CAAH;AACAE,EAAAA,WAAW,CAACG,OAAZ,CAAoB,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,MAAF,EAAP;AAAA,GAApB;AACD,CALM;;;;AAOP,IAAMC,YAAY,GAAG,SAAfA,YAAe,OAAgE;AAAA;;AAA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P,QAAN,CAAeoI,sBAAf,CAAsC7H,KAAK,CAAC0B,SAA5C,EAAuD,CAAvD,CAAjB;;AAEA,YAAIvB,QAAJ,EAAc;AACZ,cAAMC,UAAU,GAAGyE,kBAAkB,CAAC7E,KAAD,EAAQG,QAAR,EAAkBD,IAAlB,CAArC;AAEAJ,UAAAA,YAAY,CAAC;AAAEC,YAAAA,SAAS,EAATA,SAAF;AAAaC,YAAAA,KAAK,EAAE0H,UAApB;AAAgCzH,YAAAA,QAAQ,EAARA,QAAhC;AAA0CC,YAAAA,IAAI,EAAJA,IAA1C;AAAgDC,YAAAA,QAAQ,EAARA,QAAhD;AAA0DC,YAAAA,UAAU,EAAVA;AAA1D,WAAD,CAAZ;AACD;AACF;AAhHM,KAFI;AAoHb0H,IAAAA,UApHa,sBAoHFC,KApHE,EAoHK;AAChB,UAAIA,KAAK,CAACC,IAAN,CAAWpB,IAAX,KAAoB,KAAxB,EAA+B;AAC7B,oBAAiBmB,KAAK,CAACC,IAAN,IAAc,EAA/B;AAAA,YAAQlG,IAAR,SAAQA,IAAR;;AACA,YAAMmG,QAAQ,GAAG,CAAAnG,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAEgE,MAAN,OAAkB,EAAnC;AAEA,4BAAO,wCAAUmC,QAAQ,CAACjC,UAAnB,EAAgC+B,KAAK,CAACG,QAAtC,CAAP;AACD;AACF;AA3HY,GAAf;AA8HA,SAAO3B,MAAP;AACD","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport List from '@material-ui/core/List';\nimport { Leaf, Mark } from 'slate';\nimport Immutable from 'immutable';\nimport ListItem from '@material-ui/core/ListItem';\nimport isEmpty from 'lodash/isEmpty';\nimport debug from 'debug';\nimport CssIcon from './icons';\n\nconst log = debug('@pie-lib:editable-html:plugins:characters');\n\nexport const removeDialogs = () => {\n const prevDialogs = document.querySelectorAll('.insert-css-dialog');\n\n log('[characters:removeDialogs]');\n prevDialogs.forEach((s) => s.remove());\n};\n\nconst insertDialog = ({ editorDOM, value, callback, opts, textNode, parentNode }) => {\n const newEl = document.createElement('div');\n\n log('[characters:insertDialog]');\n\n removeDialogs();\n\n newEl.className = 'insert-css-dialog';\n\n let popoverEl;\n\n const closePopOver = () => {\n if (popoverEl) {\n popoverEl.remove();\n }\n };\n\n let firstCallMade = false;\n\n const listener = (e) => {\n // this will be triggered right after setting it because\n // this toolbar is added on the mousedown event\n // so right after mouseup, the click will be triggered\n if (firstCallMade) {\n const focusIsInModals = newEl.contains(e.target) || (popoverEl && popoverEl.contains(e.target));\n const focusIsInEditor = editorDOM.contains(e.target);\n\n if (!(focusIsInModals || focusIsInEditor)) {\n handleClose();\n }\n } else {\n firstCallMade = true;\n }\n };\n\n const handleClose = () => {\n callback(undefined, true);\n newEl.remove();\n closePopOver();\n document.body.removeEventListener('click', listener);\n };\n\n const handleChange = (name) => {\n callback(name, true);\n newEl.remove();\n closePopOver();\n document.body.removeEventListener('click', listener);\n };\n\n const selectedText = textNode.text.slice(value.selection.anchorOffset, value.selection.focusOffset);\n const parentNodeClass = parentNode?.data?.get('attributes')?.class;\n const createHTML = (name) => {\n let html = `<span class=\"${name}\">${selectedText}</span>`;\n\n if (parentNode) {\n let tag;\n\n if (parentNode?.object === 'inline') {\n tag = 'span';\n }\n\n if (parentNode?.object === 'block') {\n tag = 'div';\n }\n\n html = `<${tag} class=\"${parentNodeClass}\">${parentNode.text.slice(\n 0,\n value.selection.anchorOffset,\n )}${html}${parentNode.text.slice(value.selection.focusOffset)}</${tag}>`;\n }\n\n return html;\n };\n\n const el = (\n <div\n style={{ background: 'white', height: 500, padding: 20, overflow: 'hidden', display: 'flex', flexFlow: 'column' }}\n >\n <h2>Please choose a css class</h2>\n {parentNodeClass && <div>The current parent has this class {parentNodeClass}</div>}\n <List component=\"nav\" style={{ overflow: 'scroll' }}>\n {opts.names.map((name, i) => (\n <ListItem key={`rule-${i}`} button onClick={() => handleChange(name)}>\n <div style={{ marginRight: 20 }}>{name}</div>\n <div\n dangerouslySetInnerHTML={{\n __html: createHTML(name),\n }}\n />\n </ListItem>\n ))}\n </List>\n </div>\n );\n\n ReactDOM.render(el, newEl, () => {\n const cursorItem = document.querySelector(`[data-key=\"${value.anchorKey}\"]`);\n\n if (cursorItem) {\n const bodyRect = editorDOM.parentElement.parentElement.parentElement.getBoundingClientRect();\n const boundRect = cursorItem.getBoundingClientRect();\n\n editorDOM.parentElement.parentElement.parentElement.appendChild(newEl);\n\n // when height of toolbar exceeds screen - can happen in scrollable contexts\n let additionalTopOffset = 0;\n if (boundRect.y < newEl.offsetHeight) {\n additionalTopOffset = newEl.offsetHeight - boundRect.y + 10;\n }\n\n newEl.style.maxWidth = '500px';\n newEl.style.position = 'absolute';\n newEl.style.top = 0;\n newEl.style.zIndex = 99999;\n\n const leftValue = `${boundRect.left + Math.abs(bodyRect.left) + cursorItem.offsetWidth + 10}px`;\n\n const rightValue = `${boundRect.x}px`;\n\n newEl.style.left = leftValue;\n\n const leftAlignedWidth = newEl.offsetWidth;\n\n newEl.style.left = 'unset';\n newEl.style.right = rightValue;\n\n const rightAlignedWidth = newEl.offsetWidth;\n\n newEl.style.left = 'unset';\n newEl.style.right = 'unset';\n\n if (leftAlignedWidth >= rightAlignedWidth) {\n newEl.style.left = leftValue;\n } else {\n newEl.style.right = rightValue;\n }\n\n document.body.addEventListener('click', listener);\n }\n });\n};\n\nconst findParentNodeInfo = (value, textNode) => {\n const closestInline = value.document.getClosestInline(value.selection.endKey);\n const closestBlock = value.document.getClosestBlock(value.selection.endKey);\n let nodeToUse = null;\n\n if (closestInline?.nodes?.find((n) => n.key === textNode.key)) {\n nodeToUse = closestInline;\n }\n\n if (closestBlock?.nodes?.find((n) => n.key === textNode.key)) {\n nodeToUse = closestBlock;\n }\n\n return nodeToUse;\n};\n\n/**\n * Find the node that has a class attribute and return it.\n * Keeping this in case the implementation of classes needs to be changed\n * @param value\n * @param opts\n * @returns {*}\n */\nconst getNodeWithClass = (value, opts) => {\n const blocksAtRange = value.document.getBlocksAtRangeAsArray(value.selection);\n const inlinesAtRange = value.document.getInlinesAtRangeAsArray(value.selection);\n const blockData = blocksAtRange[0]?.data.toJSON() || {};\n const inlineData = inlinesAtRange[0]?.data.toJSON() || {};\n\n if (!blockData.attributes?.class && !inlineData.attributes?.class) {\n return null;\n }\n\n const { class: blockClass } = blockData.attributes || {};\n const { class: inlineClass } = inlineData.attributes || {};\n const inlineHasClass = opts.names.find((name) => inlineClass.includes(name));\n\n if (inlineHasClass) {\n return inlinesAtRange[0];\n }\n\n const blockHasClass = opts.names.find((name) => blockClass.includes(name));\n\n if (blockHasClass) {\n return blocksAtRange[0];\n }\n\n return null;\n};\n\n/**\n * Plugin in order to be able to add a css clas that is provided through the model\n * on a text element. Works like a mark (bold, italic etc.).\n * @param opts\n * @constructor\n */\nexport default function CSSPlugin(opts) {\n const plugin = {\n name: 'extraCSSRules',\n toolbar: {\n isMark: true,\n icon: <CssIcon />,\n ariaLabel: 'CSS editor',\n type: 'css',\n onToggle: (change) => {\n const type = 'css';\n const hasMark = change.value.activeMarks.find((entry) => {\n return entry.type === type;\n });\n\n if (hasMark) {\n change.removeMark(hasMark);\n } else {\n const newMark = Mark.create(type);\n\n change.addMark(newMark);\n }\n\n return change;\n },\n onClick: (value, onChange, getFocusedValue) => {\n const type = 'css';\n const hasMark = value.activeMarks.find((entry) => {\n return entry.type === type;\n });\n\n let change = value.change();\n\n if (hasMark) {\n change.removeMark(hasMark);\n onChange(change);\n return;\n }\n\n // keeping this if implementation needs to be changed to regular blocks instead of marks\n // let nodeWithClass = getNodeWithClass(value, opts);\n //\n // if (nodeWithClass) {\n // const nodeAttributes = nodeWithClass.data.get('attributes');\n //\n // opts.names.forEach((name) => {\n // if (nodeAttributes.class.includes(name)) {\n // nodeAttributes.class = nodeAttributes.class.replace(name, '');\n // }\n // });\n //\n // // keeping only one space between classes\n // nodeAttributes.class = nodeAttributes.class.replace(/ +/g, ' ');\n //\n // nodeWithClass.data.set('attributes', nodeAttributes);\n //\n // let change = value.change();\n // change.replaceNodeByKey(nodeWithClass.key, nodeWithClass);\n //\n // onChange(change);\n // return;\n // }\n\n const editorDOM = document.querySelector(`[data-key=\"${value.document.key}\"]`);\n let valueToUse = value;\n\n const callback = (className, focus) => {\n if (getFocusedValue) {\n valueToUse = getFocusedValue() || valueToUse;\n }\n\n if (className) {\n let change = valueToUse.change();\n\n const newMark = Mark.create({\n object: 'mark',\n type: 'css',\n data: {\n attributes: {\n class: className,\n },\n },\n });\n\n change.addMark(newMark);\n // keeping this if implementation needs to be changed to regular blocks instead of marks\n // change = change.wrapInline({ type: 'span', data: { attributes: { class: className } } });\n //\n // // change = change.splitBlockAtRange(adaptedRange);\n // //\n // // const newBlock = change.value.document.getFurthestBlock(change.value.selection.endKey);\n // //\n // // change = change.setNodeByKey(newBlock.key, { data: { attributes: { class: className } } });\n //\n // valueToUse = change.value;\n // log('[characters:insert]: ', value);\n onChange(change);\n }\n\n log('[characters:click]');\n\n if (focus) {\n setTimeout(() => {\n if (editorDOM) {\n editorDOM.focus();\n }\n }, 0);\n }\n };\n const textNode = value.document.getTextsAtRangeAsArray(value.selection)[0];\n\n if (textNode) {\n const parentNode = findParentNodeInfo(value, textNode, opts);\n\n insertDialog({ editorDOM, value: valueToUse, callback, opts, textNode, parentNode });\n }\n },\n },\n renderMark(props) {\n if (props.mark.type === 'css') {\n const { data } = props.mark || {};\n const jsonData = data?.toJSON() || {};\n\n return <span {...jsonData.attributes}>{props.children}</span>;\n }\n },\n };\n\n return plugin;\n}\n"],"file":"index.js"}
@@ -1,114 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.ICON_TYPE = exports.CONTENT_TYPE = void 0;
9
- exports["default"] = CustomPlugin;
10
-
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
-
13
- var _react = _interopRequireDefault(require("react"));
14
-
15
- var _serialization = require("../../serialization");
16
-
17
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
-
19
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
-
21
- // We're possibly going to have to support content types, so starting it as an enum
22
- var CONTENT_TYPE = {
23
- FRAGMENT: 'FRAGMENT'
24
- }; // We're possibly going to have to support multiple icon types, so starting it as an enum
25
-
26
- exports.CONTENT_TYPE = CONTENT_TYPE;
27
- var ICON_TYPE = {
28
- SVG: 'SVG'
29
- };
30
- exports.ICON_TYPE = ICON_TYPE;
31
-
32
- var getIcon = function getIcon(customPluginProps) {
33
- var svg = customPluginProps.icon;
34
-
35
- switch (customPluginProps.iconType) {
36
- case ICON_TYPE.SVG:
37
- return /*#__PURE__*/_react["default"].createElement("span", {
38
- style: {
39
- width: 28,
40
- height: 28
41
- },
42
- dangerouslySetInnerHTML: {
43
- __html: svg
44
- }
45
- });
46
-
47
- default:
48
- return /*#__PURE__*/_react["default"].createElement("span", null, customPluginProps.iconAlt);
49
- }
50
- };
51
-
52
- function CustomPlugin(type, customPluginProps) {
53
- var toolbar = {
54
- icon: getIcon(customPluginProps),
55
- onClick: function onClick(value, onChange, getFocusedValue) {
56
- var editorDOM = document.querySelector("[data-key=\"".concat(value.document.key, "\"]"));
57
- var valueToUse = value;
58
-
59
- var callback = function callback(_ref, focus) {
60
- var customContent = _ref.customContent,
61
- contentType = _ref.contentType;
62
- valueToUse = getFocusedValue();
63
-
64
- switch (contentType) {
65
- case CONTENT_TYPE.FRAGMENT:
66
- default:
67
- {
68
- var contentValue = (0, _serialization.htmlToValue)(customContent);
69
- var change = valueToUse.change().insertFragment(contentValue.document);
70
- valueToUse = change.value;
71
- onChange(change);
72
- break;
73
- }
74
- }
75
-
76
- if (focus) {
77
- if (editorDOM) {
78
- editorDOM.focus();
79
- }
80
- }
81
- }; // NOTE: the emitted event (custom event named by client) will be suffixed with "PIE-"
82
-
83
-
84
- window.dispatchEvent(new CustomEvent("PIE-".concat(customPluginProps.event), {
85
- detail: _objectSpread(_objectSpread({}, customPluginProps), {}, {
86
- callback: callback
87
- })
88
- }));
89
- },
90
- supports: function supports(node) {
91
- return node.object === 'inline' && node.type === type;
92
- }
93
- };
94
- return {
95
- name: type,
96
- toolbar: toolbar,
97
- renderNode: function renderNode(props) {
98
- if (props.node.type === type) {
99
- var node = props.node;
100
- var data = node.data;
101
- var jsonData = data.toJSON();
102
- var customContent = jsonData.customContent,
103
- contentType = jsonData.contentType;
104
-
105
- switch (contentType) {
106
- case CONTENT_TYPE.FRAGMENT:
107
- default:
108
- return customContent;
109
- }
110
- }
111
- }
112
- };
113
- }
114
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/plugins/customPlugin/index.jsx"],"names":["CONTENT_TYPE","FRAGMENT","ICON_TYPE","SVG","getIcon","customPluginProps","svg","icon","iconType","width","height","__html","iconAlt","CustomPlugin","type","toolbar","onClick","value","onChange","getFocusedValue","editorDOM","document","querySelector","key","valueToUse","callback","focus","customContent","contentType","contentValue","change","insertFragment","window","dispatchEvent","CustomEvent","event","detail","supports","node","object","name","renderNode","props","data","jsonData","toJSON"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;;;;;AAEA;AACO,IAAMA,YAAY,GAAG;AAC1BC,EAAAA,QAAQ,EAAE;AADgB,CAArB,C,CAIP;;;A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,UAAU,GAAGM,MAAM,CAACb,KAApB;AACAC,cAAAA,QAAQ,CAACY,MAAD,CAAR;AAEA;AACD;AAVH;;AAaA,YAAIJ,KAAJ,EAAW;AACT,cAAIN,SAAJ,EAAe;AACbA,YAAAA,SAAS,CAACM,KAAV;AACD;AACF;AACF,OArBD,CAH6C,CA0B7C;;;AACAM,MAAAA,MAAM,CAACC,aAAP,CACE,IAAIC,WAAJ,eAAuB7B,iBAAiB,CAAC8B,KAAzC,GAAkD;AAChDC,QAAAA,MAAM,kCACD/B,iBADC;AAEJoB,UAAAA,QAAQ,EAARA;AAFI;AAD0C,OAAlD,CADF;AAQD,KArCa;AAsCdY,IAAAA,QAAQ,EAAE,kBAACC,IAAD;AAAA,aAAUA,IAAI,CAACC,MAAL,KAAgB,QAAhB,IAA4BD,IAAI,CAACxB,IAAL,KAAcA,IAApD;AAAA;AAtCI,GAAhB;AAyCA,SAAO;AACL0B,IAAAA,IAAI,EAAE1B,IADD;AAELC,IAAAA,OAAO,EAAPA,OAFK;AAGL0B,IAAAA,UAHK,sBAGMC,KAHN,EAGa;AAChB,UAAIA,KAAK,CAACJ,IAAN,CAAWxB,IAAX,KAAoBA,IAAxB,EAA8B;AAC5B,YAAQwB,IAAR,GAAiBI,KAAjB,CAAQJ,IAAR;AACA,YAAQK,IAAR,GAAiBL,IAAjB,CAAQK,IAAR;AACA,YAAMC,QAAQ,GAAGD,IAAI,CAACE,MAAL,EAAjB;AACA,YAAQlB,aAAR,GAAuCiB,QAAvC,CAAQjB,aAAR;AAAA,YAAuBC,WAAvB,GAAuCgB,QAAvC,CAAuBhB,WAAvB;;AAEA,gBAAQA,WAAR;AACE,eAAK5B,YAAY,CAACC,QAAlB;AACA;AACE,mBAAO0B,aAAP;AAHJ;AAKD;AACF;AAhBI,GAAP;AAkBD","sourcesContent":["import React from 'react';\nimport { htmlToValue } from '../../serialization';\n\n// We're possibly going to have to support content types, so starting it as an enum\nexport const CONTENT_TYPE = {\n FRAGMENT: 'FRAGMENT',\n};\n\n// We're possibly going to have to support multiple icon types, so starting it as an enum\nexport const ICON_TYPE = {\n SVG: 'SVG',\n};\n\nconst getIcon = (customPluginProps) => {\n const svg = customPluginProps.icon;\n\n switch (customPluginProps.iconType) {\n case ICON_TYPE.SVG:\n return <span style={{ width: 28, height: 28 }} dangerouslySetInnerHTML={{ __html: svg }} />;\n default:\n return <span>{customPluginProps.iconAlt}</span>;\n }\n};\n\nexport default function CustomPlugin(type, customPluginProps) {\n const toolbar = {\n icon: getIcon(customPluginProps),\n onClick: (value, onChange, getFocusedValue) => {\n const editorDOM = document.querySelector(`[data-key=\"${value.document.key}\"]`);\n let valueToUse = value;\n const callback = ({ customContent, contentType }, focus) => {\n valueToUse = getFocusedValue();\n\n switch (contentType) {\n case CONTENT_TYPE.FRAGMENT:\n default: {\n const contentValue = htmlToValue(customContent);\n const change = valueToUse.change().insertFragment(contentValue.document);\n\n valueToUse = change.value;\n onChange(change);\n\n break;\n }\n }\n\n if (focus) {\n if (editorDOM) {\n editorDOM.focus();\n }\n }\n };\n\n // NOTE: the emitted event (custom event named by client) will be suffixed with \"PIE-\"\n window.dispatchEvent(\n new CustomEvent(`PIE-${customPluginProps.event}`, {\n detail: {\n ...customPluginProps,\n callback,\n },\n }),\n );\n },\n supports: (node) => node.object === 'inline' && node.type === type,\n };\n\n return {\n name: type,\n toolbar,\n renderNode(props) {\n if (props.node.type === type) {\n const { node } = props;\n const { data } = node;\n const jsonData = data.toJSON();\n const { customContent, contentType } = jsonData;\n\n switch (contentType) {\n case CONTENT_TYPE.FRAGMENT:\n default:\n return customContent;\n }\n }\n },\n };\n}\n"],"file":"index.js"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _styles = require("@material-ui/core/styles");
13
-
14
- var styles = function styles(theme) {
15
- return {
16
- icon: {
17
- fontFamily: 'Cerebri Sans, Arial, sans-serif',
18
- fontSize: theme.typography.fontSize,
19
- fontWeight: 'bold',
20
- lineHeight: '14px',
21
- position: 'relative',
22
- whiteSpace: 'nowrap'
23
- }
24
- };
25
- };
26
-
27
- var HtmlModeIcon = function HtmlModeIcon(_ref) {
28
- var classes = _ref.classes,
29
- isHtmlMode = _ref.isHtmlMode;
30
- return /*#__PURE__*/_react["default"].createElement("div", {
31
- className: classes.icon
32
- }, isHtmlMode ? 'Exit <HTML> mode' : '<HTML>');
33
- };
34
-
35
- var _default = (0, _styles.withStyles)(styles)(HtmlModeIcon);
36
-
37
- exports["default"] = _default;
38
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/plugins/html/icons/index.jsx"],"names":["styles","theme","icon","fontFamily","fontSize","typography","fontWeight","lineHeight","position","whiteSpace","HtmlModeIcon","classes","isHtmlMode"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,IAAI,EAAE;AACJC,MAAAA,UAAU,EAAE,iCADR;AAEJC,MAAAA,QAAQ,EAAEH,KAAK,CAACI,UAAN,CAAiBD,QAFvB;AAGJE,MAAAA,UAAU,EAAE,MAHR;AAIJC,MAAAA,UAAU,EAAE,MAJR;AAKJC,MAAAA,QAAQ,EAAE,UALN;AAMJC,MAAAA,UAAU,EAAE;AANR;AADmB,GAAZ;AAAA,CAAf;;AAWA,IAAMC,YAAY,GAAG,SAAfA,YAAe;AAAA,MAAGC,OAAH,QAAGA,OAAH;AAAA,MAAYC,UAAZ,QAAYA,UAAZ;AAAA,sBACnB;AAAK,IAAA,SAAS,EAAED,OAAO,CAACT;AAAxB,KAA+BU,UAAU,GAAG,kBAAH,GAAwB,QAAjE,CADmB;AAAA,CAArB;;eAIe,wBAAWZ,MAAX,EAAmBU,YAAnB,C","sourcesContent":["import React from 'react';\nimport { withStyles } from '@material-ui/core/styles';\n\nconst styles = (theme) => ({\n icon: {\n fontFamily: 'Cerebri Sans, Arial, sans-serif',\n fontSize: theme.typography.fontSize,\n fontWeight: 'bold',\n lineHeight: '14px',\n position: 'relative',\n whiteSpace: 'nowrap',\n },\n});\n\nconst HtmlModeIcon = ({ classes, isHtmlMode }) => (\n <div className={classes.icon}>{isHtmlMode ? 'Exit <HTML> mode' : '<HTML>'}</div>\n);\n\nexport default withStyles(styles)(HtmlModeIcon);\n"],"file":"index.js"}