@tightknitai/block-kitchen 0.10.16 → 0.10.17

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
@@ -6675,19 +6675,28 @@ function Divider() {
6675
6675
  }
6676
6676
  function LinkPopover({ editor }) {
6677
6677
  const active = editor.isActive("link");
6678
- const currentHref = editor.getAttributes("link").href ?? "";
6679
6678
  const [open, setOpen] = useState(false);
6680
- const [url, setUrl] = useState(currentHref);
6679
+ const [url, setUrl] = useState("");
6680
+ const [text, setText] = useState("");
6681
+ const [inserting, setInserting] = useState(false);
6681
6682
  const [error, setError] = useState(null);
6682
- useEffect(() => {
6683
- if (open) {
6684
- setUrl(currentHref);
6683
+ const handleOpenChange = (next) => {
6684
+ if (next) {
6685
+ const linkActive = editor.isActive("link");
6686
+ setUrl(editor.getAttributes("link").href ?? "");
6687
+ setText("");
6688
+ setInserting(editor.state.selection.empty && !linkActive);
6685
6689
  setError(null);
6686
6690
  }
6687
- }, [open, currentHref]);
6691
+ setOpen(next);
6692
+ };
6688
6693
  const apply = () => {
6689
6694
  const trimmed = url.trim();
6690
6695
  if (!trimmed) {
6696
+ if (inserting) {
6697
+ setError("Enter a URL.");
6698
+ return;
6699
+ }
6691
6700
  editor.chain().focus().unsetLink().run();
6692
6701
  setOpen(false);
6693
6702
  return;
@@ -6696,10 +6705,24 @@ function LinkPopover({ editor }) {
6696
6705
  setError("Only http(s), mailto, tel, sms, and xmpp links are allowed.");
6697
6706
  return;
6698
6707
  }
6699
- editor.chain().focus().extendMarkRange("link").setLink({ href: trimmed }).run();
6708
+ if (inserting) {
6709
+ editor.chain().focus().insertContent({
6710
+ type: "text",
6711
+ text: text.trim() || trimmed,
6712
+ marks: [{ type: "link", attrs: { href: trimmed } }]
6713
+ }).unsetMark("link").setMeta("preventAutolink", true).run();
6714
+ } else {
6715
+ editor.chain().focus().extendMarkRange("link").setLink({ href: trimmed }).run();
6716
+ }
6700
6717
  setOpen(false);
6701
6718
  };
6702
- return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
6719
+ const applyOnEnter = (e) => {
6720
+ if (e.key === "Enter") {
6721
+ e.preventDefault();
6722
+ apply();
6723
+ }
6724
+ };
6725
+ return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
6703
6726
  /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
6704
6727
  "button",
6705
6728
  {
@@ -6714,6 +6737,24 @@ function LinkPopover({ editor }) {
6714
6737
  }
6715
6738
  ) }),
6716
6739
  /* @__PURE__ */ jsx(PopoverContent, { align: "start", className: "w-72 p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
6740
+ inserting && /* @__PURE__ */ jsxs(Fragment, { children: [
6741
+ /* @__PURE__ */ jsx(Label, { htmlFor: "rt-link-text", className: "text-xs", children: "Text" }),
6742
+ /* @__PURE__ */ jsx(
6743
+ Input,
6744
+ {
6745
+ id: "rt-link-text",
6746
+ value: text,
6747
+ placeholder: "Link text",
6748
+ onChange: (e) => {
6749
+ setText(e.target.value);
6750
+ if (error) {
6751
+ setError(null);
6752
+ }
6753
+ },
6754
+ onKeyDown: applyOnEnter
6755
+ }
6756
+ )
6757
+ ] }),
6717
6758
  /* @__PURE__ */ jsx(Label, { htmlFor: "rt-link-url", className: "text-xs", children: "URL" }),
6718
6759
  /* @__PURE__ */ jsx(
6719
6760
  Input,
@@ -6727,17 +6768,12 @@ function LinkPopover({ editor }) {
6727
6768
  setError(null);
6728
6769
  }
6729
6770
  },
6730
- onKeyDown: (e) => {
6731
- if (e.key === "Enter") {
6732
- e.preventDefault();
6733
- apply();
6734
- }
6735
- }
6771
+ onKeyDown: applyOnEnter
6736
6772
  }
6737
6773
  ),
6738
6774
  error && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-destructive", children: error }),
6739
6775
  /* @__PURE__ */ jsxs("div", { className: "flex justify-between", children: [
6740
- active ? /* @__PURE__ */ jsx(
6776
+ active && !inserting ? /* @__PURE__ */ jsx(
6741
6777
  Button,
6742
6778
  {
6743
6779
  type: "button",
@@ -6750,7 +6786,7 @@ function LinkPopover({ editor }) {
6750
6786
  children: "Remove"
6751
6787
  }
6752
6788
  ) : /* @__PURE__ */ jsx("span", {}),
6753
- /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", onClick: apply, children: active ? "Update" : "Add link" })
6789
+ /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", onClick: apply, children: active && !inserting ? "Update" : "Add link" })
6754
6790
  ] })
6755
6791
  ] }) })
6756
6792
  ] });