@broberg/cms-inline-edit 0.7.1 → 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.js CHANGED
@@ -1377,11 +1377,48 @@ function togglePageTools(options, forankring) {
1377
1377
  plus.setAttribute("data-testid", "page-tools-tags-plus");
1378
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;";
1379
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 = [];
1380
1384
  const felt = document.createElement("input");
1381
1385
  felt.type = "text";
1382
1386
  felt.placeholder = "tag1, tag2, tag3";
1383
1387
  felt.setAttribute("data-testid", "page-tools-tags-input");
1384
- felt.style.cssText = "flex:1;min-width:0;display:none;background:#12151a;border:1px solid #3a3f4a;border-radius:8px;padding:7px 9px;color:#fff;font:12px system-ui,sans-serif;outline:none;";
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());
1385
1422
  const gem = document.createElement("button");
1386
1423
  gem.type = "button";
1387
1424
  gem.setAttribute("data-testid", "page-tools-tags-gem");
@@ -1389,12 +1426,13 @@ function togglePageTools(options, forankring) {
1389
1426
  gem.textContent = "Gem";
1390
1427
  plus.addEventListener("click", () => {
1391
1428
  plus.style.display = "none";
1392
- felt.style.display = "block";
1429
+ boks.style.display = "flex";
1393
1430
  gem.style.display = "inline-block";
1394
1431
  felt.focus();
1395
1432
  });
1396
1433
  const gemTags = async () => {
1397
- const nye = parseTags(felt.value);
1434
+ tagify();
1435
+ const nye = [...chips];
1398
1436
  if (!nye.length) return;
1399
1437
  gem.disabled = true;
1400
1438
  gem.textContent = "\u2026";
@@ -1407,6 +1445,8 @@ function togglePageTools(options, forankring) {
1407
1445
  gem.textContent = holdt ? "Gemt \u2713" : "Fejl";
1408
1446
  if (holdt) {
1409
1447
  felt.value = "";
1448
+ chips.length = 0;
1449
+ tegnChips();
1410
1450
  setTimeout(() => {
1411
1451
  gem.textContent = "Gem";
1412
1452
  gem.disabled = false;
@@ -1421,12 +1461,27 @@ function togglePageTools(options, forankring) {
1421
1461
  };
1422
1462
  gem.addEventListener("click", () => void gemTags());
1423
1463
  felt.addEventListener("keydown", (e) => {
1464
+ if (e.key === ",") {
1465
+ e.preventDefault();
1466
+ tagify();
1467
+ return;
1468
+ }
1424
1469
  if (e.key === "Enter") {
1425
1470
  e.preventDefault();
1426
1471
  void gemTags();
1472
+ return;
1427
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();
1428
1482
  });
1429
- tagRow.append(plus, felt, gem);
1483
+ boks.appendChild(felt);
1484
+ tagRow.append(plus, boks, gem);
1430
1485
  popup.appendChild(tagRow);
1431
1486
  const lukP\u00E5Klik = (e) => {
1432
1487
  if (!popup.contains(e.target) && !forankring.contains(e.target)) luk();