tiny-markdown-editor 0.1.3 → 0.1.5
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 +2 -2
- package/dist/tiny-mde.css +2 -6
- package/dist/tiny-mde.js +5488 -5066
- package/dist/tiny-mde.min.css +1 -1
- package/dist/tiny-mde.min.js +1 -1
- package/dist/tiny-mde.tiny.js +1 -1
- package/lib/TinyMDE.js +265 -506
- package/lib/TinyMDECommandBar.js +27 -102
- package/lib/grammar.js +102 -111
- package/lib/index.js +1 -3
- package/lib/svg/svg.js +1 -0
- package/lib/tiny.js +1 -2
- package/package.json +17 -17
package/lib/TinyMDECommandBar.js
CHANGED
|
@@ -1,68 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/es.
|
|
6
|
-
|
|
7
|
-
require("core-js/modules/es.
|
|
8
|
-
|
|
9
|
-
require("core-js/modules/es.
|
|
10
|
-
|
|
11
|
-
require("core-js/modules/es.array.
|
|
12
|
-
|
|
13
|
-
require("core-js/modules/es.array.iterator");
|
|
14
|
-
|
|
15
|
-
require("core-js/modules/es.array.join");
|
|
16
|
-
|
|
17
|
-
require("core-js/modules/es.array.slice");
|
|
18
|
-
|
|
19
|
-
require("core-js/modules/es.function.name");
|
|
20
|
-
|
|
21
|
-
require("core-js/modules/es.object.assign");
|
|
22
|
-
|
|
23
|
-
require("core-js/modules/es.object.to-string");
|
|
24
|
-
|
|
25
|
-
require("core-js/modules/es.regexp.exec");
|
|
26
|
-
|
|
27
|
-
require("core-js/modules/es.regexp.to-string");
|
|
28
|
-
|
|
29
|
-
require("core-js/modules/es.string.iterator");
|
|
30
|
-
|
|
31
|
-
require("core-js/modules/es.string.match");
|
|
32
|
-
|
|
33
|
-
require("core-js/modules/es.string.split");
|
|
34
|
-
|
|
35
|
-
require("core-js/modules/es.string.anchor");
|
|
36
|
-
|
|
37
|
-
require("core-js/modules/es.string.bold");
|
|
38
|
-
|
|
39
|
-
require("core-js/modules/es.string.link");
|
|
40
|
-
|
|
41
|
-
require("core-js/modules/web.dom-collections.iterator");
|
|
42
|
-
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
require("core-js/modules/es.array.slice.js");
|
|
5
|
+
require("core-js/modules/es.object.to-string.js");
|
|
6
|
+
require("core-js/modules/es.array.from.js");
|
|
7
|
+
require("core-js/modules/es.string.iterator.js");
|
|
8
|
+
require("core-js/modules/es.symbol.js");
|
|
9
|
+
require("core-js/modules/es.symbol.description.js");
|
|
10
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
11
|
+
require("core-js/modules/es.array.iterator.js");
|
|
12
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
43
13
|
Object.defineProperty(exports, "__esModule", {
|
|
44
14
|
value: true
|
|
45
15
|
});
|
|
46
16
|
exports.default = void 0;
|
|
47
|
-
|
|
17
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
18
|
+
require("core-js/modules/es.object.assign.js");
|
|
19
|
+
require("core-js/modules/es.string.match.js");
|
|
20
|
+
require("core-js/modules/es.array.concat.js");
|
|
48
21
|
var _svg = _interopRequireDefault(require("./svg/svg"));
|
|
49
|
-
|
|
50
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
51
|
-
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
55
|
-
|
|
23
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
24
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
56
25
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
57
|
-
|
|
58
26
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
59
|
-
|
|
60
27
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
61
|
-
|
|
62
28
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
63
|
-
|
|
64
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
65
|
-
|
|
29
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
66
30
|
var isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
|
67
31
|
var DefaultCommands = {
|
|
68
32
|
'bold': {
|
|
@@ -162,13 +126,10 @@ var DefaultCommands = {
|
|
|
162
126
|
hotkey: 'Mod2-Shift-L'
|
|
163
127
|
}
|
|
164
128
|
};
|
|
165
|
-
|
|
166
129
|
var CommandBar = /*#__PURE__*/function () {
|
|
167
130
|
function CommandBar(props) {
|
|
168
131
|
var _this = this;
|
|
169
|
-
|
|
170
132
|
_classCallCheck(this, CommandBar);
|
|
171
|
-
|
|
172
133
|
this.e = null;
|
|
173
134
|
this.editor = null;
|
|
174
135
|
this.commands = [];
|
|
@@ -176,37 +137,29 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
176
137
|
this.state = {};
|
|
177
138
|
this.hotkeys = [];
|
|
178
139
|
var element = props.element;
|
|
179
|
-
|
|
180
140
|
if (element && !element.tagName) {
|
|
181
141
|
element = document.getElementById(props.element);
|
|
182
142
|
}
|
|
183
|
-
|
|
184
143
|
if (!element) {
|
|
185
144
|
element = document.body;
|
|
186
145
|
}
|
|
187
|
-
|
|
188
146
|
this.createCommandBarElement(element, props.commands || ['bold', 'italic', 'strikethrough', '|', 'code', '|', 'h1', 'h2', '|', 'ul', 'ol', '|', 'blockquote', 'hr', '|', 'insertLink', 'insertImage']);
|
|
189
147
|
document.addEventListener('keydown', function (e) {
|
|
190
148
|
return _this.handleKeydown(e);
|
|
191
149
|
});
|
|
192
150
|
if (props.editor) this.setEditor(props.editor);
|
|
193
151
|
}
|
|
194
|
-
|
|
195
152
|
_createClass(CommandBar, [{
|
|
196
153
|
key: "createCommandBarElement",
|
|
197
154
|
value: function createCommandBarElement(parentElement, commands) {
|
|
198
155
|
var _this2 = this;
|
|
199
|
-
|
|
200
156
|
this.e = document.createElement('div');
|
|
201
157
|
this.e.className = 'TMCommandBar';
|
|
202
|
-
|
|
203
158
|
var _iterator = _createForOfIteratorHelper(commands),
|
|
204
|
-
|
|
205
|
-
|
|
159
|
+
_step;
|
|
206
160
|
try {
|
|
207
161
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
208
162
|
var command = _step.value;
|
|
209
|
-
|
|
210
163
|
if (command == '|') {
|
|
211
164
|
var el = document.createElement('div');
|
|
212
165
|
el.className = 'TMCommandDivider';
|
|
@@ -214,9 +167,9 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
214
167
|
} else {
|
|
215
168
|
var _ret = function () {
|
|
216
169
|
var commandName = void 0;
|
|
217
|
-
|
|
218
170
|
if (typeof command == "string") {
|
|
219
171
|
// Reference to default command
|
|
172
|
+
|
|
220
173
|
if (DefaultCommands[command]) {
|
|
221
174
|
commandName = command;
|
|
222
175
|
_this2.commands[commandName] = DefaultCommands[commandName];
|
|
@@ -231,48 +184,38 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
231
184
|
} else {
|
|
232
185
|
return "continue";
|
|
233
186
|
}
|
|
234
|
-
|
|
235
187
|
var title = _this2.commands[commandName].title || commandName;
|
|
236
|
-
|
|
237
188
|
if (_this2.commands[commandName].hotkey) {
|
|
238
|
-
var keys = _this2.commands[commandName].hotkey.split('-');
|
|
239
|
-
|
|
240
|
-
|
|
189
|
+
var keys = _this2.commands[commandName].hotkey.split('-');
|
|
190
|
+
// construct modifiers
|
|
241
191
|
var modifiers = [];
|
|
242
192
|
var modifierexplanation = [];
|
|
243
|
-
|
|
244
193
|
for (var i = 0; i < keys.length - 1; i++) {
|
|
245
194
|
switch (keys[i]) {
|
|
246
195
|
case 'Ctrl':
|
|
247
196
|
modifiers.push('ctrlKey');
|
|
248
197
|
modifierexplanation.push('Ctrl');
|
|
249
198
|
break;
|
|
250
|
-
|
|
251
199
|
case 'Cmd':
|
|
252
200
|
modifiers.push('metaKey');
|
|
253
201
|
modifierexplanation.push('⌘');
|
|
254
202
|
break;
|
|
255
|
-
|
|
256
203
|
case 'Alt':
|
|
257
204
|
modifiers.push('altKey');
|
|
258
205
|
modifierexplanation.push('Alt');
|
|
259
206
|
break;
|
|
260
|
-
|
|
261
207
|
case 'Option':
|
|
262
208
|
modifiers.push('altKey');
|
|
263
209
|
modifierexplanation.push('⌥');
|
|
264
210
|
break;
|
|
265
|
-
|
|
266
211
|
case 'Win':
|
|
267
212
|
modifiers.push('metaKey');
|
|
268
213
|
modifierexplanation.push('⊞ Win');
|
|
269
214
|
break;
|
|
270
|
-
|
|
271
215
|
case 'Shift':
|
|
272
216
|
modifiers.push('shiftKey');
|
|
273
217
|
modifierexplanation.push('⇧');
|
|
274
218
|
break;
|
|
275
|
-
|
|
276
219
|
case 'Mod':
|
|
277
220
|
// Mod is a convenience mechanism: Ctrl on Windows, Cmd on Mac
|
|
278
221
|
if (isMacLike) {
|
|
@@ -282,9 +225,7 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
282
225
|
modifiers.push('ctrlKey');
|
|
283
226
|
modifierexplanation.push('Ctrl');
|
|
284
227
|
}
|
|
285
|
-
|
|
286
228
|
break;
|
|
287
|
-
|
|
288
229
|
case 'Mod2':
|
|
289
230
|
modifiers.push('altKey');
|
|
290
231
|
if (isMacLike) modifierexplanation.push('⌥');else modifierexplanation.push('Alt');
|
|
@@ -297,31 +238,25 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
297
238
|
var hotkey = {
|
|
298
239
|
modifiers: modifiers,
|
|
299
240
|
command: commandName
|
|
300
|
-
};
|
|
301
|
-
|
|
241
|
+
};
|
|
242
|
+
// TODO Right now this is working only for letters and numbers
|
|
302
243
|
if (keys[keys.length - 1].match(/^[0-9]$/)) {
|
|
303
244
|
hotkey.code = "Digit".concat(keys[keys.length - 1]);
|
|
304
245
|
} else {
|
|
305
246
|
hotkey.key = keys[keys.length - 1].toLowerCase();
|
|
306
247
|
}
|
|
307
|
-
|
|
308
248
|
_this2.hotkeys.push(hotkey);
|
|
309
|
-
|
|
310
249
|
title = title.concat(" (".concat(modifierexplanation.join('+'), ")"));
|
|
311
250
|
}
|
|
312
|
-
|
|
313
251
|
_this2.buttons[commandName] = document.createElement('div');
|
|
314
252
|
_this2.buttons[commandName].className = 'TMCommandButton TMCommandButton_Disabled';
|
|
315
253
|
_this2.buttons[commandName].title = title;
|
|
316
254
|
_this2.buttons[commandName].innerHTML = _this2.commands[commandName].innerHTML;
|
|
317
|
-
|
|
318
255
|
_this2.buttons[commandName].addEventListener('mousedown', function (e) {
|
|
319
256
|
return _this2.handleClick(commandName, e);
|
|
320
257
|
});
|
|
321
|
-
|
|
322
258
|
_this2.e.appendChild(_this2.buttons[commandName]);
|
|
323
259
|
}();
|
|
324
|
-
|
|
325
260
|
if (_ret === "continue") continue;
|
|
326
261
|
}
|
|
327
262
|
}
|
|
@@ -330,7 +265,6 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
330
265
|
} finally {
|
|
331
266
|
_iterator.f();
|
|
332
267
|
}
|
|
333
|
-
|
|
334
268
|
parentElement.appendChild(this.e);
|
|
335
269
|
}
|
|
336
270
|
}, {
|
|
@@ -338,7 +272,6 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
338
272
|
value: function handleClick(commandName, event) {
|
|
339
273
|
if (!this.editor) return;
|
|
340
274
|
event.preventDefault();
|
|
341
|
-
|
|
342
275
|
if (typeof this.commands[commandName].action == "string") {
|
|
343
276
|
if (this.state[commandName] === false) this.editor.setCommandState(commandName, true);else this.editor.setCommandState(commandName, false);
|
|
344
277
|
} else if (typeof this.commands[commandName].action == "function") {
|
|
@@ -349,7 +282,6 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
349
282
|
key: "setEditor",
|
|
350
283
|
value: function setEditor(editor) {
|
|
351
284
|
var _this3 = this;
|
|
352
|
-
|
|
353
285
|
this.editor = editor;
|
|
354
286
|
editor.addEventListener('selection', function (e) {
|
|
355
287
|
return _this3.handleSelection(e);
|
|
@@ -365,7 +297,6 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
365
297
|
} else {
|
|
366
298
|
this.state[command] = event.commandState[command];
|
|
367
299
|
}
|
|
368
|
-
|
|
369
300
|
if (this.state[command] === true) {
|
|
370
301
|
this.buttons[command].className = 'TMCommandButton TMCommandButton_Active';
|
|
371
302
|
} else if (this.state[command] === false) {
|
|
@@ -380,29 +311,25 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
380
311
|
key: "handleKeydown",
|
|
381
312
|
value: function handleKeydown(event) {
|
|
382
313
|
var _iterator2 = _createForOfIteratorHelper(this.hotkeys),
|
|
383
|
-
|
|
384
|
-
|
|
314
|
+
_step2;
|
|
385
315
|
try {
|
|
386
316
|
outer: for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
387
317
|
var hotkey = _step2.value;
|
|
388
|
-
|
|
389
318
|
if (hotkey.key && event.key.toLowerCase() == hotkey.key || hotkey.code && event.code == hotkey.code) {
|
|
390
319
|
// Key matches hotkey. Look for any required modifier that wasn't pressed
|
|
391
320
|
var _iterator3 = _createForOfIteratorHelper(hotkey.modifiers),
|
|
392
|
-
|
|
393
|
-
|
|
321
|
+
_step3;
|
|
394
322
|
try {
|
|
395
323
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
396
324
|
var modifier = _step3.value;
|
|
397
325
|
if (!event[modifier]) continue outer;
|
|
398
|
-
}
|
|
399
|
-
|
|
326
|
+
}
|
|
327
|
+
// Everything matches.
|
|
400
328
|
} catch (err) {
|
|
401
329
|
_iterator3.e(err);
|
|
402
330
|
} finally {
|
|
403
331
|
_iterator3.f();
|
|
404
332
|
}
|
|
405
|
-
|
|
406
333
|
this.handleClick(hotkey.command, event);
|
|
407
334
|
return;
|
|
408
335
|
}
|
|
@@ -414,9 +341,7 @@ var CommandBar = /*#__PURE__*/function () {
|
|
|
414
341
|
}
|
|
415
342
|
}
|
|
416
343
|
}]);
|
|
417
|
-
|
|
418
344
|
return CommandBar;
|
|
419
345
|
}();
|
|
420
|
-
|
|
421
346
|
var _default = CommandBar;
|
|
422
347
|
exports.default = _default;
|