@broberg/cms-inline-edit 0.7.0 → 0.7.2
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/dist/index.cjs +61 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -382,6 +382,8 @@ function exitEditMode() {
|
|
|
382
382
|
deactivateRich();
|
|
383
383
|
editingActive = false;
|
|
384
384
|
document.body.removeAttribute("data-cms-editing");
|
|
385
|
+
document.querySelector("[data-cms-inline-edit-toolsrow]")?.remove();
|
|
386
|
+
document.querySelector("[data-cms-inline-edit-tools-popup]")?.remove();
|
|
385
387
|
document.querySelector("[data-cms-inline-edit-badge]")?.remove();
|
|
386
388
|
showIdlePill();
|
|
387
389
|
}
|
|
@@ -1417,11 +1419,48 @@ function togglePageTools(options, forankring) {
|
|
|
1417
1419
|
plus.setAttribute("data-testid", "page-tools-tags-plus");
|
|
1418
1420
|
plus.style.cssText = "background:rgba(255,255,255,.04);border:1px solid #3a3f4a;border-radius:9px;padding:8px 12px;color:#fff;font:600 12px system-ui,sans-serif;cursor:pointer;";
|
|
1419
1421
|
plus.textContent = "# Tags +";
|
|
1422
|
+
const boks = document.createElement("div");
|
|
1423
|
+
boks.setAttribute("data-testid", "page-tools-tags-boks");
|
|
1424
|
+
boks.style.cssText = "flex:1;min-width:0;display:none;flex-wrap:wrap;align-items:center;gap:5px;background:#12151a;border:1px solid #3a3f4a;border-radius:8px;padding:5px 7px;cursor:text;";
|
|
1425
|
+
const chips = [];
|
|
1420
1426
|
const felt = document.createElement("input");
|
|
1421
1427
|
felt.type = "text";
|
|
1422
1428
|
felt.placeholder = "tag1, tag2, tag3";
|
|
1423
1429
|
felt.setAttribute("data-testid", "page-tools-tags-input");
|
|
1424
|
-
felt.style.cssText = "flex:1;min-width:
|
|
1430
|
+
felt.style.cssText = "flex:1;min-width:70px;background:transparent;border:none;padding:2px;color:#fff;font:12px system-ui,sans-serif;outline:none;";
|
|
1431
|
+
const tegnChips = () => {
|
|
1432
|
+
Array.prototype.forEach.call(boks.querySelectorAll("[data-chip]"), (c) => c.remove());
|
|
1433
|
+
chips.forEach((t, i) => {
|
|
1434
|
+
const chip = document.createElement("span");
|
|
1435
|
+
chip.setAttribute("data-chip", "");
|
|
1436
|
+
chip.setAttribute("data-testid", "page-tools-tag-chip");
|
|
1437
|
+
chip.style.cssText = "display:inline-flex;align-items:center;gap:4px;background:rgba(0,178,255,.15);border:1px solid rgba(0,178,255,.45);border-radius:999px;padding:2px 4px 2px 8px;color:#7fd8ff;font:600 11px system-ui,sans-serif;";
|
|
1438
|
+
chip.textContent = t;
|
|
1439
|
+
const x = document.createElement("button");
|
|
1440
|
+
x.type = "button";
|
|
1441
|
+
x.setAttribute("data-testid", "page-tools-tag-fjern");
|
|
1442
|
+
x.setAttribute("aria-label", `Fjern ${t}`);
|
|
1443
|
+
x.style.cssText = "background:none;border:none;color:#7fd8ff;font:700 13px system-ui,sans-serif;cursor:pointer;line-height:1;padding:0 3px;";
|
|
1444
|
+
x.textContent = "\xD7";
|
|
1445
|
+
x.addEventListener("click", (e) => {
|
|
1446
|
+
e.stopPropagation();
|
|
1447
|
+
chips.splice(i, 1);
|
|
1448
|
+
tegnChips();
|
|
1449
|
+
felt.focus();
|
|
1450
|
+
});
|
|
1451
|
+
chip.appendChild(x);
|
|
1452
|
+
boks.insertBefore(chip, felt);
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
const tagify = () => {
|
|
1456
|
+
const nye = parseTags(felt.value);
|
|
1457
|
+
for (const t of nye) {
|
|
1458
|
+
if (!chips.some((c) => c.toLowerCase() === t.toLowerCase())) chips.push(t);
|
|
1459
|
+
}
|
|
1460
|
+
felt.value = "";
|
|
1461
|
+
tegnChips();
|
|
1462
|
+
};
|
|
1463
|
+
boks.addEventListener("click", () => felt.focus());
|
|
1425
1464
|
const gem = document.createElement("button");
|
|
1426
1465
|
gem.type = "button";
|
|
1427
1466
|
gem.setAttribute("data-testid", "page-tools-tags-gem");
|
|
@@ -1429,12 +1468,13 @@ function togglePageTools(options, forankring) {
|
|
|
1429
1468
|
gem.textContent = "Gem";
|
|
1430
1469
|
plus.addEventListener("click", () => {
|
|
1431
1470
|
plus.style.display = "none";
|
|
1432
|
-
|
|
1471
|
+
boks.style.display = "flex";
|
|
1433
1472
|
gem.style.display = "inline-block";
|
|
1434
1473
|
felt.focus();
|
|
1435
1474
|
});
|
|
1436
1475
|
const gemTags = async () => {
|
|
1437
|
-
|
|
1476
|
+
tagify();
|
|
1477
|
+
const nye = [...chips];
|
|
1438
1478
|
if (!nye.length) return;
|
|
1439
1479
|
gem.disabled = true;
|
|
1440
1480
|
gem.textContent = "\u2026";
|
|
@@ -1447,6 +1487,8 @@ function togglePageTools(options, forankring) {
|
|
|
1447
1487
|
gem.textContent = holdt ? "Gemt \u2713" : "Fejl";
|
|
1448
1488
|
if (holdt) {
|
|
1449
1489
|
felt.value = "";
|
|
1490
|
+
chips.length = 0;
|
|
1491
|
+
tegnChips();
|
|
1450
1492
|
setTimeout(() => {
|
|
1451
1493
|
gem.textContent = "Gem";
|
|
1452
1494
|
gem.disabled = false;
|
|
@@ -1461,12 +1503,27 @@ function togglePageTools(options, forankring) {
|
|
|
1461
1503
|
};
|
|
1462
1504
|
gem.addEventListener("click", () => void gemTags());
|
|
1463
1505
|
felt.addEventListener("keydown", (e) => {
|
|
1506
|
+
if (e.key === ",") {
|
|
1507
|
+
e.preventDefault();
|
|
1508
|
+
tagify();
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1464
1511
|
if (e.key === "Enter") {
|
|
1465
1512
|
e.preventDefault();
|
|
1466
1513
|
void gemTags();
|
|
1514
|
+
return;
|
|
1467
1515
|
}
|
|
1516
|
+
if (e.key === "Backspace" && felt.value === "" && chips.length) {
|
|
1517
|
+
e.preventDefault();
|
|
1518
|
+
chips.pop();
|
|
1519
|
+
tegnChips();
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1522
|
+
felt.addEventListener("input", () => {
|
|
1523
|
+
if (felt.value.includes(",")) tagify();
|
|
1468
1524
|
});
|
|
1469
|
-
|
|
1525
|
+
boks.appendChild(felt);
|
|
1526
|
+
tagRow.append(plus, boks, gem);
|
|
1470
1527
|
popup.appendChild(tagRow);
|
|
1471
1528
|
const lukP\u00E5Klik = (e) => {
|
|
1472
1529
|
if (!popup.contains(e.target) && !forankring.contains(e.target)) luk();
|