@firecms/editor 3.0.0-tw4.2 → 3.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/dist/index.umd.js CHANGED
@@ -31,7 +31,7 @@
31
31
  } = react.useCurrentEditor();
32
32
  tippyOptions?.placement;
33
33
  let t1;
34
- const shouldShow = _temp$1;
34
+ const shouldShow = _temp$2;
35
35
  const t2 = tippyOptions?.placement ?? options?.placement;
36
36
  let t3;
37
37
  if ($[5] !== options || $[6] !== t2) {
@@ -85,7 +85,7 @@
85
85
  }
86
86
  return t6;
87
87
  });
88
- function _temp$1(t0) {
88
+ function _temp$2(t0) {
89
89
  const {
90
90
  editor: editor_0,
91
91
  state: state$1
@@ -445,7 +445,7 @@
445
445
  if ($[0] !== editor) {
446
446
  const items2 = [{
447
447
  name: "bold",
448
- isActive: _temp,
448
+ isActive: _temp$1,
449
449
  command: _temp2,
450
450
  icon: ui.FormatBoldIcon
451
451
  }, {
@@ -482,7 +482,7 @@
482
482
  }
483
483
  return t0;
484
484
  };
485
- function _temp(editor_0) {
485
+ function _temp$1(editor_0) {
486
486
  return editor_0?.isActive("bold") ?? false;
487
487
  }
488
488
  function _temp2(editor_1) {
@@ -1397,18 +1397,50 @@
1397
1397
  return item.searchTerms?.some((term) => term.toLowerCase().startsWith(query.toLowerCase()));
1398
1398
  });
1399
1399
  },
1400
+ allow: ({
1401
+ editor,
1402
+ range
1403
+ }) => {
1404
+ return editor.can().insertContentAt(range, {
1405
+ type: "command"
1406
+ });
1407
+ },
1400
1408
  render: () => {
1401
1409
  let component;
1402
1410
  let containerEl = null;
1403
1411
  let cleanupAutoUpdate = null;
1404
1412
  let reference = null;
1413
+ let escapeListener = null;
1414
+ function exit() {
1415
+ if (cleanupAutoUpdate) cleanupAutoUpdate();
1416
+ if (containerEl && containerEl.parentNode) {
1417
+ containerEl.parentNode.removeChild(containerEl);
1418
+ }
1419
+ if (escapeListener) {
1420
+ document.removeEventListener("keydown", escapeListener, true);
1421
+ escapeListener = null;
1422
+ }
1423
+ containerEl = null;
1424
+ reference = null;
1425
+ component?.destroy();
1426
+ }
1405
1427
  return {
1406
1428
  onStart: (props) => {
1429
+ escapeListener = (e) => {
1430
+ if (e.key === "Escape") {
1431
+ e.preventDefault();
1432
+ e.stopPropagation();
1433
+ e.stopImmediatePropagation();
1434
+ exit();
1435
+ }
1436
+ };
1437
+ document.addEventListener("keydown", escapeListener, true);
1407
1438
  component = new react.ReactRenderer(CommandList, {
1408
1439
  props: {
1409
1440
  ...props,
1410
1441
  upload,
1411
- aiController
1442
+ aiController,
1443
+ onClose: exit
1412
1444
  },
1413
1445
  editor: props.editor
1414
1446
  });
@@ -1416,6 +1448,7 @@
1416
1448
  return;
1417
1449
  }
1418
1450
  containerEl = document.createElement("div");
1451
+ containerEl.setAttribute("data-suggestion-menu", "true");
1419
1452
  containerEl.style.position = "fixed";
1420
1453
  containerEl.style.left = "0px";
1421
1454
  containerEl.style.top = "0px";
@@ -1467,18 +1500,14 @@
1467
1500
  onKeyDown(props) {
1468
1501
  if (props.event.key === "Escape") {
1469
1502
  props.event.preventDefault();
1503
+ props.event.stopPropagation();
1504
+ exit();
1470
1505
  return true;
1471
1506
  }
1472
1507
  return component.ref?.onKeyDown(props);
1473
1508
  },
1474
1509
  onExit() {
1475
- if (cleanupAutoUpdate) cleanupAutoUpdate();
1476
- if (containerEl && containerEl.parentNode) {
1477
- containerEl.parentNode.removeChild(containerEl);
1478
- }
1479
- containerEl = null;
1480
- reference = null;
1481
- component?.destroy();
1510
+ exit();
1482
1511
  }
1483
1512
  };
1484
1513
  }
@@ -1491,10 +1520,12 @@
1491
1520
  } = react.useCurrentEditor();
1492
1521
  let t0;
1493
1522
  if ($[0] !== editor || $[1] !== props.aiController || $[2] !== props.range || $[3] !== props.upload) {
1494
- t0 = (item) => {
1523
+ t0 = (item, event) => {
1495
1524
  if (!editor) {
1496
1525
  return;
1497
1526
  }
1527
+ event?.preventDefault();
1528
+ event?.stopPropagation();
1498
1529
  item?.command?.({
1499
1530
  editor,
1500
1531
  range: props.range,
@@ -1570,17 +1601,17 @@
1570
1601
  t6 = () => ({
1571
1602
  onKeyDown: (t72) => {
1572
1603
  const {
1573
- event
1604
+ event: event_0
1574
1605
  } = t72;
1575
- if (event.key === "ArrowUp") {
1606
+ if (event_0.key === "ArrowUp") {
1576
1607
  upHandler();
1577
1608
  return true;
1578
1609
  }
1579
- if (event.key === "ArrowDown") {
1610
+ if (event_0.key === "ArrowDown") {
1580
1611
  downHandler();
1581
1612
  return true;
1582
1613
  }
1583
- if (event.key === "Enter") {
1614
+ if (event_0.key === "Enter") {
1584
1615
  enterHandler();
1585
1616
  return true;
1586
1617
  }
@@ -1636,7 +1667,7 @@
1636
1667
  return;
1637
1668
  }
1638
1669
  itemRefs.current[index] = el;
1639
- }, onClick: () => selectItem(item_1), tabIndex: index === selectedIndex ? 0 : -1, "aria-selected": index === selectedIndex, className: ui.cls("flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-blue-50 hover:dark:bg-surface-700 aria-selected:bg-blue-50 aria-selected:dark:bg-surface-700", index === selectedIndex ? "bg-blue-100 dark:bg-surface-accent-950" : ""), children: [
1670
+ }, onMouseDown: _temp, onClick: (e_0) => selectItem(item_1, e_0), tabIndex: index === selectedIndex ? 0 : -1, "aria-selected": index === selectedIndex, className: ui.cls("flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-blue-50 hover:dark:bg-surface-700 aria-selected:bg-blue-50 aria-selected:dark:bg-surface-700", index === selectedIndex ? "bg-blue-100 dark:bg-surface-accent-950" : ""), children: [
1640
1671
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: ui.cls("flex h-10 w-10 items-center justify-center rounded-md border bg-white dark:bg-surface-900", ui.defaultBorderMixin), children: item_1.icon }),
1641
1672
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1642
1673
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium", children: item_1.title }),
@@ -1839,6 +1870,9 @@
1839
1870
  input.click();
1840
1871
  }
1841
1872
  }];
1873
+ function _temp(e) {
1874
+ return e.preventDefault();
1875
+ }
1842
1876
  const proseClasses = {
1843
1877
  "sm": "prose-sm",
1844
1878
  "base": "prose-base",