@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.js
CHANGED
|
@@ -340,6 +340,8 @@ function exitEditMode() {
|
|
|
340
340
|
deactivateRich();
|
|
341
341
|
editingActive = false;
|
|
342
342
|
document.body.removeAttribute("data-cms-editing");
|
|
343
|
+
document.querySelector("[data-cms-inline-edit-toolsrow]")?.remove();
|
|
344
|
+
document.querySelector("[data-cms-inline-edit-tools-popup]")?.remove();
|
|
343
345
|
document.querySelector("[data-cms-inline-edit-badge]")?.remove();
|
|
344
346
|
showIdlePill();
|
|
345
347
|
}
|
|
@@ -1375,11 +1377,48 @@ function togglePageTools(options, forankring) {
|
|
|
1375
1377
|
plus.setAttribute("data-testid", "page-tools-tags-plus");
|
|
1376
1378
|
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;";
|
|
1377
1379
|
plus.textContent = "# Tags +";
|
|
1380
|
+
const boks = document.createElement("div");
|
|
1381
|
+
boks.setAttribute("data-testid", "page-tools-tags-boks");
|
|
1382
|
+
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;";
|
|
1383
|
+
const chips = [];
|
|
1378
1384
|
const felt = document.createElement("input");
|
|
1379
1385
|
felt.type = "text";
|
|
1380
1386
|
felt.placeholder = "tag1, tag2, tag3";
|
|
1381
1387
|
felt.setAttribute("data-testid", "page-tools-tags-input");
|
|
1382
|
-
felt.style.cssText = "flex:1;min-width:
|
|
1388
|
+
felt.style.cssText = "flex:1;min-width:70px;background:transparent;border:none;padding:2px;color:#fff;font:12px system-ui,sans-serif;outline:none;";
|
|
1389
|
+
const tegnChips = () => {
|
|
1390
|
+
Array.prototype.forEach.call(boks.querySelectorAll("[data-chip]"), (c) => c.remove());
|
|
1391
|
+
chips.forEach((t, i) => {
|
|
1392
|
+
const chip = document.createElement("span");
|
|
1393
|
+
chip.setAttribute("data-chip", "");
|
|
1394
|
+
chip.setAttribute("data-testid", "page-tools-tag-chip");
|
|
1395
|
+
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;";
|
|
1396
|
+
chip.textContent = t;
|
|
1397
|
+
const x = document.createElement("button");
|
|
1398
|
+
x.type = "button";
|
|
1399
|
+
x.setAttribute("data-testid", "page-tools-tag-fjern");
|
|
1400
|
+
x.setAttribute("aria-label", `Fjern ${t}`);
|
|
1401
|
+
x.style.cssText = "background:none;border:none;color:#7fd8ff;font:700 13px system-ui,sans-serif;cursor:pointer;line-height:1;padding:0 3px;";
|
|
1402
|
+
x.textContent = "\xD7";
|
|
1403
|
+
x.addEventListener("click", (e) => {
|
|
1404
|
+
e.stopPropagation();
|
|
1405
|
+
chips.splice(i, 1);
|
|
1406
|
+
tegnChips();
|
|
1407
|
+
felt.focus();
|
|
1408
|
+
});
|
|
1409
|
+
chip.appendChild(x);
|
|
1410
|
+
boks.insertBefore(chip, felt);
|
|
1411
|
+
});
|
|
1412
|
+
};
|
|
1413
|
+
const tagify = () => {
|
|
1414
|
+
const nye = parseTags(felt.value);
|
|
1415
|
+
for (const t of nye) {
|
|
1416
|
+
if (!chips.some((c) => c.toLowerCase() === t.toLowerCase())) chips.push(t);
|
|
1417
|
+
}
|
|
1418
|
+
felt.value = "";
|
|
1419
|
+
tegnChips();
|
|
1420
|
+
};
|
|
1421
|
+
boks.addEventListener("click", () => felt.focus());
|
|
1383
1422
|
const gem = document.createElement("button");
|
|
1384
1423
|
gem.type = "button";
|
|
1385
1424
|
gem.setAttribute("data-testid", "page-tools-tags-gem");
|
|
@@ -1387,12 +1426,13 @@ function togglePageTools(options, forankring) {
|
|
|
1387
1426
|
gem.textContent = "Gem";
|
|
1388
1427
|
plus.addEventListener("click", () => {
|
|
1389
1428
|
plus.style.display = "none";
|
|
1390
|
-
|
|
1429
|
+
boks.style.display = "flex";
|
|
1391
1430
|
gem.style.display = "inline-block";
|
|
1392
1431
|
felt.focus();
|
|
1393
1432
|
});
|
|
1394
1433
|
const gemTags = async () => {
|
|
1395
|
-
|
|
1434
|
+
tagify();
|
|
1435
|
+
const nye = [...chips];
|
|
1396
1436
|
if (!nye.length) return;
|
|
1397
1437
|
gem.disabled = true;
|
|
1398
1438
|
gem.textContent = "\u2026";
|
|
@@ -1405,6 +1445,8 @@ function togglePageTools(options, forankring) {
|
|
|
1405
1445
|
gem.textContent = holdt ? "Gemt \u2713" : "Fejl";
|
|
1406
1446
|
if (holdt) {
|
|
1407
1447
|
felt.value = "";
|
|
1448
|
+
chips.length = 0;
|
|
1449
|
+
tegnChips();
|
|
1408
1450
|
setTimeout(() => {
|
|
1409
1451
|
gem.textContent = "Gem";
|
|
1410
1452
|
gem.disabled = false;
|
|
@@ -1419,12 +1461,27 @@ function togglePageTools(options, forankring) {
|
|
|
1419
1461
|
};
|
|
1420
1462
|
gem.addEventListener("click", () => void gemTags());
|
|
1421
1463
|
felt.addEventListener("keydown", (e) => {
|
|
1464
|
+
if (e.key === ",") {
|
|
1465
|
+
e.preventDefault();
|
|
1466
|
+
tagify();
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1422
1469
|
if (e.key === "Enter") {
|
|
1423
1470
|
e.preventDefault();
|
|
1424
1471
|
void gemTags();
|
|
1472
|
+
return;
|
|
1425
1473
|
}
|
|
1474
|
+
if (e.key === "Backspace" && felt.value === "" && chips.length) {
|
|
1475
|
+
e.preventDefault();
|
|
1476
|
+
chips.pop();
|
|
1477
|
+
tegnChips();
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
felt.addEventListener("input", () => {
|
|
1481
|
+
if (felt.value.includes(",")) tagify();
|
|
1426
1482
|
});
|
|
1427
|
-
|
|
1483
|
+
boks.appendChild(felt);
|
|
1484
|
+
tagRow.append(plus, boks, gem);
|
|
1428
1485
|
popup.appendChild(tagRow);
|
|
1429
1486
|
const lukP\u00E5Klik = (e) => {
|
|
1430
1487
|
if (!popup.contains(e.target) && !forankring.contains(e.target)) luk();
|