@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.cjs CHANGED
@@ -6705,19 +6705,28 @@ function Divider() {
6705
6705
  }
6706
6706
  function LinkPopover({ editor }) {
6707
6707
  const active = editor.isActive("link");
6708
- const currentHref = editor.getAttributes("link").href ?? "";
6709
6708
  const [open, setOpen] = React.useState(false);
6710
- const [url, setUrl] = React.useState(currentHref);
6709
+ const [url, setUrl] = React.useState("");
6710
+ const [text, setText] = React.useState("");
6711
+ const [inserting, setInserting] = React.useState(false);
6711
6712
  const [error, setError] = React.useState(null);
6712
- React.useEffect(() => {
6713
- if (open) {
6714
- setUrl(currentHref);
6713
+ const handleOpenChange = (next) => {
6714
+ if (next) {
6715
+ const linkActive = editor.isActive("link");
6716
+ setUrl(editor.getAttributes("link").href ?? "");
6717
+ setText("");
6718
+ setInserting(editor.state.selection.empty && !linkActive);
6715
6719
  setError(null);
6716
6720
  }
6717
- }, [open, currentHref]);
6721
+ setOpen(next);
6722
+ };
6718
6723
  const apply = () => {
6719
6724
  const trimmed = url.trim();
6720
6725
  if (!trimmed) {
6726
+ if (inserting) {
6727
+ setError("Enter a URL.");
6728
+ return;
6729
+ }
6721
6730
  editor.chain().focus().unsetLink().run();
6722
6731
  setOpen(false);
6723
6732
  return;
@@ -6726,10 +6735,24 @@ function LinkPopover({ editor }) {
6726
6735
  setError("Only http(s), mailto, tel, sms, and xmpp links are allowed.");
6727
6736
  return;
6728
6737
  }
6729
- editor.chain().focus().extendMarkRange("link").setLink({ href: trimmed }).run();
6738
+ if (inserting) {
6739
+ editor.chain().focus().insertContent({
6740
+ type: "text",
6741
+ text: text.trim() || trimmed,
6742
+ marks: [{ type: "link", attrs: { href: trimmed } }]
6743
+ }).unsetMark("link").setMeta("preventAutolink", true).run();
6744
+ } else {
6745
+ editor.chain().focus().extendMarkRange("link").setLink({ href: trimmed }).run();
6746
+ }
6730
6747
  setOpen(false);
6731
6748
  };
6732
- return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
6749
+ const applyOnEnter = (e) => {
6750
+ if (e.key === "Enter") {
6751
+ e.preventDefault();
6752
+ apply();
6753
+ }
6754
+ };
6755
+ return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
6733
6756
  /* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
6734
6757
  "button",
6735
6758
  {
@@ -6744,6 +6767,24 @@ function LinkPopover({ editor }) {
6744
6767
  }
6745
6768
  ) }),
6746
6769
  /* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { align: "start", className: "w-72 p-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
6770
+ inserting && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6771
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "rt-link-text", className: "text-xs", children: "Text" }),
6772
+ /* @__PURE__ */ jsxRuntime.jsx(
6773
+ Input,
6774
+ {
6775
+ id: "rt-link-text",
6776
+ value: text,
6777
+ placeholder: "Link text",
6778
+ onChange: (e) => {
6779
+ setText(e.target.value);
6780
+ if (error) {
6781
+ setError(null);
6782
+ }
6783
+ },
6784
+ onKeyDown: applyOnEnter
6785
+ }
6786
+ )
6787
+ ] }),
6747
6788
  /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "rt-link-url", className: "text-xs", children: "URL" }),
6748
6789
  /* @__PURE__ */ jsxRuntime.jsx(
6749
6790
  Input,
@@ -6757,17 +6798,12 @@ function LinkPopover({ editor }) {
6757
6798
  setError(null);
6758
6799
  }
6759
6800
  },
6760
- onKeyDown: (e) => {
6761
- if (e.key === "Enter") {
6762
- e.preventDefault();
6763
- apply();
6764
- }
6765
- }
6801
+ onKeyDown: applyOnEnter
6766
6802
  }
6767
6803
  ),
6768
6804
  error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[11px] text-destructive", children: error }),
6769
6805
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between", children: [
6770
- active ? /* @__PURE__ */ jsxRuntime.jsx(
6806
+ active && !inserting ? /* @__PURE__ */ jsxRuntime.jsx(
6771
6807
  Button,
6772
6808
  {
6773
6809
  type: "button",
@@ -6780,7 +6816,7 @@ function LinkPopover({ editor }) {
6780
6816
  children: "Remove"
6781
6817
  }
6782
6818
  ) : /* @__PURE__ */ jsxRuntime.jsx("span", {}),
6783
- /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", size: "sm", onClick: apply, children: active ? "Update" : "Add link" })
6819
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", size: "sm", onClick: apply, children: active && !inserting ? "Update" : "Add link" })
6784
6820
  ] })
6785
6821
  ] }) })
6786
6822
  ] });