rich-html-editor 0.2.2 → 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.
- package/README.md +3 -1
- package/dist/{chunk-ZDGUOGND.mjs → chunk-W3ULZ2LR.mjs} +23 -1
- package/dist/chunk-W3ULZ2LR.mjs.map +1 -0
- package/dist/index.js +138 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -5
- package/dist/index.mjs.map +1 -1
- package/dist/{state-CZIMHTJ3.mjs → state-DA3PGFTN.mjs} +2 -2
- package/package.json +1 -1
- package/dist/chunk-ZDGUOGND.mjs.map +0 -1
- /package/dist/{state-CZIMHTJ3.mjs.map → state-DA3PGFTN.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -16,10 +16,12 @@ import {
|
|
|
16
16
|
LABEL_BOLD,
|
|
17
17
|
LABEL_ITALIC,
|
|
18
18
|
LABEL_LINK,
|
|
19
|
+
LABEL_ORDERED_LIST,
|
|
19
20
|
LABEL_REDO,
|
|
20
21
|
LABEL_STRIKETHROUGH,
|
|
21
22
|
LABEL_UNDERLINE,
|
|
22
23
|
LABEL_UNDO,
|
|
24
|
+
LABEL_UNORDERED_LIST,
|
|
23
25
|
SIZE_OPTIONS,
|
|
24
26
|
STYLE_ID,
|
|
25
27
|
TOOLBAR_BG,
|
|
@@ -37,7 +39,7 @@ import {
|
|
|
37
39
|
getEditorEventEmitter,
|
|
38
40
|
pushStandaloneSnapshot,
|
|
39
41
|
sanitizeHtml
|
|
40
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-W3ULZ2LR.mjs";
|
|
41
43
|
|
|
42
44
|
// src/dom/styles.ts
|
|
43
45
|
function injectStyles(doc) {
|
|
@@ -647,6 +649,24 @@ function injectToolbar(doc, options) {
|
|
|
647
649
|
)
|
|
648
650
|
);
|
|
649
651
|
grp3.appendChild(makeButton2(LABEL_STRIKETHROUGH, "Strikethrough", "strike"));
|
|
652
|
+
grp3.appendChild(
|
|
653
|
+
makeButton2(
|
|
654
|
+
LABEL_UNORDERED_LIST,
|
|
655
|
+
"Unordered list",
|
|
656
|
+
"unorderedList",
|
|
657
|
+
void 0,
|
|
658
|
+
format.listType === "ul"
|
|
659
|
+
)
|
|
660
|
+
);
|
|
661
|
+
grp3.appendChild(
|
|
662
|
+
makeButton2(
|
|
663
|
+
LABEL_ORDERED_LIST,
|
|
664
|
+
"Ordered list",
|
|
665
|
+
"orderedList",
|
|
666
|
+
void 0,
|
|
667
|
+
format.listType === "ol"
|
|
668
|
+
)
|
|
669
|
+
);
|
|
650
670
|
toolbar.appendChild(grp3);
|
|
651
671
|
toolbar.appendChild(makeSep2());
|
|
652
672
|
const grp4 = makeGroup2();
|
|
@@ -731,7 +751,8 @@ function computeFormatState(doc) {
|
|
|
731
751
|
hiliteColor: null,
|
|
732
752
|
fontName: null,
|
|
733
753
|
fontSize: null,
|
|
734
|
-
formatBlock: null
|
|
754
|
+
formatBlock: null,
|
|
755
|
+
listType: null
|
|
735
756
|
};
|
|
736
757
|
const computed = (_a = doc.defaultView) == null ? void 0 : _a.getComputedStyle(el);
|
|
737
758
|
const bold = !!(el.closest("strong, b") || computed && (computed.fontWeight === "700" || Number(computed.fontWeight) >= 700));
|
|
@@ -767,6 +788,18 @@ function computeFormatState(doc) {
|
|
|
767
788
|
blockEl = blockEl.parentElement;
|
|
768
789
|
}
|
|
769
790
|
const formatBlock = blockEl ? blockEl.tagName.toLowerCase() : null;
|
|
791
|
+
let listType = null;
|
|
792
|
+
try {
|
|
793
|
+
if (blockEl && blockEl.tagName === "LI") {
|
|
794
|
+
const list = blockEl.closest("ul,ol");
|
|
795
|
+
if (list) listType = list.tagName.toLowerCase();
|
|
796
|
+
} else {
|
|
797
|
+
const possible = el.closest("ul,ol");
|
|
798
|
+
if (possible) listType = possible.tagName.toLowerCase();
|
|
799
|
+
}
|
|
800
|
+
} catch (e) {
|
|
801
|
+
listType = null;
|
|
802
|
+
}
|
|
770
803
|
return {
|
|
771
804
|
bold,
|
|
772
805
|
italic,
|
|
@@ -775,7 +808,8 @@ function computeFormatState(doc) {
|
|
|
775
808
|
hiliteColor,
|
|
776
809
|
fontName,
|
|
777
810
|
fontSize,
|
|
778
|
-
formatBlock
|
|
811
|
+
formatBlock,
|
|
812
|
+
listType
|
|
779
813
|
};
|
|
780
814
|
} catch (err) {
|
|
781
815
|
return {
|
|
@@ -786,7 +820,8 @@ function computeFormatState(doc) {
|
|
|
786
820
|
hiliteColor: null,
|
|
787
821
|
fontName: null,
|
|
788
822
|
fontSize: null,
|
|
789
|
-
formatBlock: null
|
|
823
|
+
formatBlock: null,
|
|
824
|
+
listType: null
|
|
790
825
|
};
|
|
791
826
|
}
|
|
792
827
|
}
|
|
@@ -1179,6 +1214,9 @@ function applyStandaloneCommand(command, value) {
|
|
|
1179
1214
|
} else {
|
|
1180
1215
|
wrapSelectionWithElement(doc, tag);
|
|
1181
1216
|
}
|
|
1217
|
+
} else if (command === "unorderedList" || command === "orderedList") {
|
|
1218
|
+
const tag = command === "unorderedList" ? "ul" : "ol";
|
|
1219
|
+
toggleList(doc, tag);
|
|
1182
1220
|
}
|
|
1183
1221
|
pushStandaloneSnapshot();
|
|
1184
1222
|
} catch (error) {
|
|
@@ -1214,6 +1252,57 @@ function wrapSelectionWithElement(doc, tagName, style) {
|
|
|
1214
1252
|
newRange.selectNodeContents(wrapper);
|
|
1215
1253
|
sel.addRange(newRange);
|
|
1216
1254
|
}
|
|
1255
|
+
function toggleList(doc, listTag) {
|
|
1256
|
+
var _a, _b;
|
|
1257
|
+
const sel = doc.getSelection();
|
|
1258
|
+
if (!sel || !sel.rangeCount) return;
|
|
1259
|
+
const node = sel.anchorNode || null;
|
|
1260
|
+
const block = findBlockAncestor(node);
|
|
1261
|
+
if (block && block.tagName === "LI" && block.parentElement) {
|
|
1262
|
+
const parentList = block.parentElement;
|
|
1263
|
+
const parentTag = parentList.tagName.toLowerCase();
|
|
1264
|
+
if (parentTag === listTag) {
|
|
1265
|
+
const frag = doc.createDocumentFragment();
|
|
1266
|
+
Array.from(parentList.children).forEach((li2) => {
|
|
1267
|
+
const p = doc.createElement("p");
|
|
1268
|
+
while (li2.firstChild) p.appendChild(li2.firstChild);
|
|
1269
|
+
frag.appendChild(p);
|
|
1270
|
+
});
|
|
1271
|
+
(_a = parentList.parentElement) == null ? void 0 : _a.replaceChild(frag, parentList);
|
|
1272
|
+
return;
|
|
1273
|
+
} else {
|
|
1274
|
+
const newList = doc.createElement(listTag);
|
|
1275
|
+
while (parentList.firstChild) newList.appendChild(parentList.firstChild);
|
|
1276
|
+
(_b = parentList.parentElement) == null ? void 0 : _b.replaceChild(newList, parentList);
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const range = sel.getRangeAt(0);
|
|
1281
|
+
if (range.collapsed) {
|
|
1282
|
+
const list2 = doc.createElement(listTag);
|
|
1283
|
+
const li2 = doc.createElement("li");
|
|
1284
|
+
const zw = doc.createTextNode("\u200B");
|
|
1285
|
+
li2.appendChild(zw);
|
|
1286
|
+
list2.appendChild(li2);
|
|
1287
|
+
range.insertNode(list2);
|
|
1288
|
+
const newRange2 = doc.createRange();
|
|
1289
|
+
newRange2.setStart(zw, 1);
|
|
1290
|
+
newRange2.collapse(true);
|
|
1291
|
+
sel.removeAllRanges();
|
|
1292
|
+
sel.addRange(newRange2);
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
const content = range.extractContents();
|
|
1296
|
+
const list = doc.createElement(listTag);
|
|
1297
|
+
const li = doc.createElement("li");
|
|
1298
|
+
li.appendChild(content);
|
|
1299
|
+
list.appendChild(li);
|
|
1300
|
+
range.insertNode(list);
|
|
1301
|
+
sel.removeAllRanges();
|
|
1302
|
+
const newRange = doc.createRange();
|
|
1303
|
+
newRange.selectNodeContents(li);
|
|
1304
|
+
sel.addRange(newRange);
|
|
1305
|
+
}
|
|
1217
1306
|
function findBlockAncestor(node) {
|
|
1218
1307
|
let n = node;
|
|
1219
1308
|
const BLOCKS = [
|
|
@@ -1355,6 +1444,33 @@ function attachStandaloneHandlers(doc) {
|
|
|
1355
1444
|
},
|
|
1356
1445
|
true
|
|
1357
1446
|
);
|
|
1447
|
+
doc.addEventListener(
|
|
1448
|
+
"keydown",
|
|
1449
|
+
(e) => {
|
|
1450
|
+
if (e.key !== "Enter") return;
|
|
1451
|
+
if (e.shiftKey) return;
|
|
1452
|
+
const sel = doc.getSelection();
|
|
1453
|
+
if (!sel || !sel.rangeCount) return;
|
|
1454
|
+
const node = sel.anchorNode;
|
|
1455
|
+
const el = node && node.nodeType === Node.ELEMENT_NODE ? node : node && node.parentElement || null;
|
|
1456
|
+
if (!el) return;
|
|
1457
|
+
const li = el.closest("li");
|
|
1458
|
+
if (!li || !li.parentElement) return;
|
|
1459
|
+
e.preventDefault();
|
|
1460
|
+
const list = li.parentElement;
|
|
1461
|
+
const newLi = doc.createElement("li");
|
|
1462
|
+
const zw = doc.createTextNode("\u200B");
|
|
1463
|
+
newLi.appendChild(zw);
|
|
1464
|
+
if (li.nextSibling) list.insertBefore(newLi, li.nextSibling);
|
|
1465
|
+
else list.appendChild(newLi);
|
|
1466
|
+
const range = doc.createRange();
|
|
1467
|
+
range.setStart(zw, 1);
|
|
1468
|
+
range.collapse(true);
|
|
1469
|
+
sel.removeAllRanges();
|
|
1470
|
+
sel.addRange(range);
|
|
1471
|
+
},
|
|
1472
|
+
true
|
|
1473
|
+
);
|
|
1358
1474
|
}
|
|
1359
1475
|
|
|
1360
1476
|
// src/core/editor.ts
|
|
@@ -1375,7 +1491,7 @@ function initRichEditor(iframe, config) {
|
|
|
1375
1491
|
_setRedoStack([]);
|
|
1376
1492
|
_setCurrentEditable(null);
|
|
1377
1493
|
if (config == null ? void 0 : config.maxStackSize) {
|
|
1378
|
-
import("./state-
|
|
1494
|
+
import("./state-DA3PGFTN.mjs").then((m) => m.setMaxStackSize(config.maxStackSize)).catch(() => {
|
|
1379
1495
|
});
|
|
1380
1496
|
}
|
|
1381
1497
|
attachStandaloneHandlers(doc);
|