@delali/web-editor 0.4.1 → 0.4.3

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.
@@ -11516,7 +11516,7 @@ function BadgeShapeButton({ shape, selected, setShape, updateElement }) {
11516
11516
 
11517
11517
  // src/ui/icon-picker.tsx
11518
11518
  import { icons as lucideIcons } from "lucide-react";
11519
- import { dynamicIconImports } from "lucide-react/dynamic";
11519
+ import { dynamicIconImports } from "lucide-react/dynamic.mjs";
11520
11520
  import * as React34 from "react";
11521
11521
  import { Fragment as Fragment11, jsx as jsx91, jsxs as jsxs54 } from "react/jsx-runtime";
11522
11522
  var toPascalCase = (str) => str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
@@ -15249,11 +15249,49 @@ import { filterWords } from "@platejs/combobox";
15249
15249
  import { useComboboxInput, useHTMLInputCursorState } from "@platejs/combobox/react";
15250
15250
  import { cva as cva22 } from "class-variance-authority";
15251
15251
  import { useComposedRef as useComposedRef2, useEditorRef as useEditorRef24 } from "platejs/react";
15252
- import React55, { useEffect as useEffect36 } from "react";
15252
+ import React55, { useEffect as useEffect37 } from "react";
15253
+
15254
+ // src/hooks/use-return-focus-to-editor-on-input-removal.ts
15255
+ import { useEffect as useEffect35, useLayoutEffect as useLayoutEffect2, useRef as useRef15 } from "react";
15256
+ var focusEditableAtEditorSelection = (editor) => {
15257
+ const editable = editor.api.toDOMNode(editor);
15258
+ if (!(editable == null ? void 0 : editable.isConnected)) {
15259
+ return;
15260
+ }
15261
+ const document2 = editable.ownerDocument;
15262
+ const activeElement = document2.activeElement;
15263
+ if (activeElement && activeElement !== document2.body) {
15264
+ return;
15265
+ }
15266
+ const domRange = editor.selection ? editor.api.toDOMRange(editor.selection) : void 0;
15267
+ editable.focus({ preventScroll: true });
15268
+ const domSelection = document2.getSelection();
15269
+ if (domRange && domSelection) {
15270
+ domSelection.removeAllRanges();
15271
+ domSelection.addRange(domRange);
15272
+ }
15273
+ };
15274
+ var useReturnFocusToEditorOnInputRemoval = (editor, inputRef) => {
15275
+ const inputHadFocusWhenRemoved = useRef15(false);
15276
+ useLayoutEffect2(() => {
15277
+ const input = inputRef.current;
15278
+ return () => {
15279
+ inputHadFocusWhenRemoved.current = !!input && input.ownerDocument.activeElement === input;
15280
+ };
15281
+ }, [inputRef]);
15282
+ useEffect35(
15283
+ () => () => {
15284
+ if (inputHadFocusWhenRemoved.current) {
15285
+ focusEditableAtEditorSelection(editor);
15286
+ }
15287
+ },
15288
+ [editor]
15289
+ );
15290
+ };
15253
15291
 
15254
15292
  // src/hooks/use-shield-input-selection-from-editor.ts
15255
15293
  import { RangeApi as RangeApi2 } from "platejs";
15256
- import { useEffect as useEffect35 } from "react";
15294
+ import { useEffect as useEffect36 } from "react";
15257
15295
  var SLATE_TEXT_SELECTOR = "[data-slate-string], [data-slate-zero-width]";
15258
15296
  var isCaretInEditorText = (node) => {
15259
15297
  var _a;
@@ -15271,7 +15309,7 @@ var wouldPullCaretOutOfInput = (editor, input) => {
15271
15309
  return !!range && RangeApi2.equals(range, editor.selection);
15272
15310
  };
15273
15311
  var useShieldInputSelectionFromEditor = (editor, inputRef) => {
15274
- useEffect35(() => {
15312
+ useEffect36(() => {
15275
15313
  const input = inputRef.current;
15276
15314
  const view = input == null ? void 0 : input.ownerDocument.defaultView;
15277
15315
  if (!input || !view) {
@@ -15335,7 +15373,7 @@ function InlineCombobox({
15335
15373
  [setValueProp, hasValueProp]
15336
15374
  );
15337
15375
  const insertPoint = React55.useRef(null);
15338
- useEffect36(() => {
15376
+ useEffect37(() => {
15339
15377
  const path = editor.api.findPath(element);
15340
15378
  if (!path) return;
15341
15379
  const point = editor.api.before(path);
@@ -15401,6 +15439,7 @@ function InlineComboboxInput(_a) {
15401
15439
  const editor = useEditorRef24();
15402
15440
  const ref = useComposedRef2(refProp, contextRef);
15403
15441
  useShieldInputSelectionFromEditor(editor, contextRef);
15442
+ useReturnFocusToEditorOnInputRemoval(editor, contextRef);
15404
15443
  return /* @__PURE__ */ jsxs79(Fragment19, { children: [
15405
15444
  showTrigger && trigger,
15406
15445
  /* @__PURE__ */ jsxs79("span", { className: "relative min-h-lh", children: [
@@ -15500,7 +15539,7 @@ function InlineComboboxEmpty({ children, className }) {
15500
15539
  const { setHasEmpty } = React55.useContext(InlineComboboxContext);
15501
15540
  const store = Ariakit2.useComboboxContext();
15502
15541
  const items = (_a = store == null ? void 0 : store.useState("items")) != null ? _a : [];
15503
- useEffect36(() => {
15542
+ useEffect37(() => {
15504
15543
  setHasEmpty(true);
15505
15544
  return () => {
15506
15545
  setHasEmpty(false);
@@ -15660,11 +15699,11 @@ import { ArrowUpRightIcon as ArrowUpRightIcon3, PencilIcon as PencilIcon6, Trash
15660
15699
 
15661
15700
  // src/ui/smart-link-copy-button.tsx
15662
15701
  import { CheckIcon as CheckIcon15, CopyIcon as CopyIcon2, XIcon as XIcon7 } from "lucide-react";
15663
- import { useCallback as useCallback40, useEffect as useEffect37, useState as useState39 } from "react";
15702
+ import { useCallback as useCallback40, useEffect as useEffect38, useState as useState39 } from "react";
15664
15703
  import { jsx as jsx130 } from "react/jsx-runtime";
15665
15704
  function SmartLinkCopyButton({ disabled, onCopy }) {
15666
15705
  const [feedback, setFeedback] = useState39("idle");
15667
- useEffect37(() => {
15706
+ useEffect38(() => {
15668
15707
  if (feedback === "idle") return;
15669
15708
  const timeoutId = window.setTimeout(() => {
15670
15709
  setFeedback("idle");
@@ -16009,12 +16048,12 @@ var PlainLinkElement = (props) => /* @__PURE__ */ jsx133(LinkElement, __spreadPr
16009
16048
 
16010
16049
  // src/ui/link-toolbar.tsx
16011
16050
  import { useEditorPlugin as useEditorPlugin12, useEditorSelector as useEditorSelector2, usePluginOption as usePluginOption17 } from "platejs/react";
16012
- import { useCallback as useCallback45, useEffect as useEffect40, useState as useState43 } from "react";
16051
+ import { useCallback as useCallback45, useEffect as useEffect41, useState as useState43 } from "react";
16013
16052
 
16014
16053
  // src/ui/link-search-panel.tsx
16015
16054
  import { BookmarkIcon, LinkIcon as LinkIcon4 } from "lucide-react";
16016
16055
  import { useEditorPlugin as useEditorPlugin10 } from "platejs/react";
16017
- import { useCallback as useCallback43, useEffect as useEffect38, useState as useState41 } from "react";
16056
+ import { useCallback as useCallback43, useEffect as useEffect39, useState as useState41 } from "react";
16018
16057
 
16019
16058
  // src/ui/link-toolbar-shared.ts
16020
16059
  import { unwrapLink as unwrapLink2, upsertLink } from "@platejs/link";
@@ -16165,7 +16204,7 @@ function LinkSearchPanel({ initialUrl }) {
16165
16204
  const safeUrl = trimmedQuery.length > 0 ? getSafeSmartLinkUrl(trimmedQuery) : null;
16166
16205
  const searchTerm = isLikelySmartLinkUrl(query) ? "" : trimmedQuery;
16167
16206
  const debouncedSearch = useDebounce(searchTerm, 200);
16168
- useEffect38(() => {
16207
+ useEffect39(() => {
16169
16208
  if (!canLinkPage) {
16170
16209
  setPages([]);
16171
16210
  setIsLoading(false);
@@ -16304,7 +16343,7 @@ import { CursorOverlayPlugin as CursorOverlayPlugin2 } from "@platejs/selection/
16304
16343
  import { LinkIcon as LinkIcon5, Trash2Icon as Trash2Icon4 } from "lucide-react";
16305
16344
  import { NodeApi as NodeApi16 } from "platejs";
16306
16345
  import { useEditorPlugin as useEditorPlugin11, usePluginOption as usePluginOption16 } from "platejs/react";
16307
- import { useCallback as useCallback44, useEffect as useEffect39, useState as useState42 } from "react";
16346
+ import { useCallback as useCallback44, useEffect as useEffect40, useState as useState42 } from "react";
16308
16347
  import { jsx as jsx135, jsxs as jsxs85 } from "react/jsx-runtime";
16309
16348
  function EditLinkCommand({ autoFocus, initialUrl, setInitialUrl }) {
16310
16349
  const [url, setUrl] = useState42(initialUrl);
@@ -16313,7 +16352,7 @@ function EditLinkCommand({ autoFocus, initialUrl, setInitialUrl }) {
16313
16352
  const { editor, setOption } = useEditorPlugin11(linkPlugin);
16314
16353
  const activeLinkId = usePluginOption16(linkPlugin, "activeId");
16315
16354
  const editingLinkEntry = useActiveLink();
16316
- useEffect39(() => {
16355
+ useEffect40(() => {
16317
16356
  var _a;
16318
16357
  if (!editingLinkEntry) return;
16319
16358
  setText(NodeApi16.string(editingLinkEntry[0]));
@@ -16437,10 +16476,10 @@ function LinkFloatingToolbar() {
16437
16476
  const aboveUrl = (_a = aboveLink == null ? void 0 : aboveLink.url) != null ? _a : "";
16438
16477
  const [initialUrl, setInitialUrl] = useState43(aboveUrl);
16439
16478
  const open = mode === "insert" || mode === "edit" || mode === "cursor";
16440
- useEffect40(() => {
16479
+ useEffect41(() => {
16441
16480
  setInitialUrl(aboveUrl);
16442
16481
  }, [aboveUrl]);
16443
- useEffect40(() => {
16482
+ useEffect41(() => {
16444
16483
  if (aboveLink) {
16445
16484
  const timeoutId = window.setTimeout(() => {
16446
16485
  var _a2;
@@ -17504,7 +17543,7 @@ import {
17504
17543
  useReadOnly as useReadOnly18,
17505
17544
  useSelected as useSelected5
17506
17545
  } from "platejs/react";
17507
- import React62, { useEffect as useEffect43 } from "react";
17546
+ import React62, { useEffect as useEffect44 } from "react";
17508
17547
  import { jsx as jsx154, jsxs as jsxs95 } from "react/jsx-runtime";
17509
17548
  function EquationElement(props) {
17510
17549
  const element = useElement14();
@@ -17565,7 +17604,7 @@ function InlineEquationElement(props) {
17565
17604
  const selected = useSelected5();
17566
17605
  const isCollapsed = useEditorSelector5((editor) => editor.api.isCollapsed(), []);
17567
17606
  const [open, setOpen] = React62.useState(selected && isCollapsed);
17568
- useEffect43(() => {
17607
+ useEffect44(() => {
17569
17608
  if (selected && isCollapsed) {
17570
17609
  setOpen(true);
17571
17610
  }
@@ -17645,7 +17684,7 @@ function EquationPopoverContent(_a) {
17645
17684
  const editor = useEditorRef34();
17646
17685
  const readOnly = useReadOnly18();
17647
17686
  const element = useElement14();
17648
- useEffect43(() => {
17687
+ useEffect44(() => {
17649
17688
  if (isInline && open) {
17650
17689
  setOpen(true);
17651
17690
  }
@@ -18490,7 +18529,7 @@ import { useDraggable as useDraggable2 } from "@platejs/dnd";
18490
18529
  import { PlaceholderPlugin as PlaceholderPlugin2, useImage, useMediaState as useMediaState4 } from "@platejs/media/react";
18491
18530
  import { ResizableProvider as ResizableProvider5 } from "@platejs/resizable";
18492
18531
  import { PlateElement as PlateElement27, useEditorPlugin as useEditorPlugin16, withHOC as withHOC5 } from "platejs/react";
18493
- import React67, { useEffect as useEffect45, useMemo as useMemo17 } from "react";
18532
+ import React67, { useEffect as useEffect46, useMemo as useMemo17 } from "react";
18494
18533
  import { LazyLoadImage } from "react-lazy-load-image-component";
18495
18534
  import { jsx as jsx165, jsxs as jsxs104 } from "react/jsx-runtime";
18496
18535
  var ImageElement = withHOC5(
@@ -18631,7 +18670,7 @@ var ImageElement = withHOC5(
18631
18670
  );
18632
18671
  var ImagePlaceholder = ({ file }) => {
18633
18672
  const objectUrl = useMemo17(() => file ? URL.createObjectURL(file) : null, [file]);
18634
- useEffect45(() => {
18673
+ useEffect46(() => {
18635
18674
  if (!objectUrl) return;
18636
18675
  return () => URL.revokeObjectURL(objectUrl);
18637
18676
  }, [objectUrl]);
@@ -18649,7 +18688,7 @@ import {
18649
18688
  import { AudioLinesIcon, FileUpIcon as FileUpIcon2, FilmIcon, ImageIcon as ImageIcon2 } from "lucide-react";
18650
18689
  import { KEYS as KEYS29, nanoid as nanoid10 } from "platejs";
18651
18690
  import { PlateElement as PlateElement28, useEditorPlugin as useEditorPlugin17, withHOC as withHOC6 } from "platejs/react";
18652
- import { useCallback as useCallback60, useEffect as useEffect46, useRef as useRef15, useState as useState49 } from "react";
18691
+ import { useCallback as useCallback60, useEffect as useEffect47, useRef as useRef16, useState as useState49 } from "react";
18653
18692
  import { useFilePicker } from "use-file-picker";
18654
18693
 
18655
18694
  // src/hooks/use-upload-file.ts
@@ -18823,8 +18862,8 @@ var PlaceholderElement = withHOC6(PlaceholderProvider, (props) => {
18823
18862
  const isImage = mediaType === KEYS29.img;
18824
18863
  const file = updatedFiles == null ? void 0 : updatedFiles[0];
18825
18864
  const progress = file ? progresses == null ? void 0 : progresses[file.name] : void 0;
18826
- const imageRef = useRef15(null);
18827
- useEffect46(() => {
18865
+ const imageRef = useRef16(null);
18866
+ useEffect47(() => {
18828
18867
  if (!imageRef.current) return;
18829
18868
  const { height, width } = imageRef.current;
18830
18869
  setSize == null ? void 0 : setSize({
@@ -18925,15 +18964,15 @@ function MediaPlaceholderPopover({ children }) {
18925
18964
  }
18926
18965
  }
18927
18966
  });
18928
- const isReplaced = useRef15(false);
18929
- useEffect46(() => {
18967
+ const isReplaced = useRef16(false);
18968
+ useEffect47(() => {
18930
18969
  if (isReplaced.current) return;
18931
18970
  isReplaced.current = true;
18932
18971
  const currentFiles = api.placeholder.getUploadingFile(element.id);
18933
18972
  if (!currentFiles) return;
18934
18973
  replaceCurrentPlaceholder(currentFiles);
18935
18974
  }, [isReplaced]);
18936
- useEffect46(() => {
18975
+ useEffect47(() => {
18937
18976
  if (!uploadedFile) return;
18938
18977
  const path = editor.api.findPath(element);
18939
18978
  setMediaNode(
@@ -18966,15 +19005,15 @@ function MediaPlaceholderPopover({ children }) {
18966
19005
  },
18967
19006
  [editor, element, mediaType]
18968
19007
  );
18969
- useEffect46(() => {
19008
+ useEffect47(() => {
18970
19009
  setOpen(selected);
18971
19010
  }, [selected, setOpen]);
18972
- useEffect46(() => {
19011
+ useEffect47(() => {
18973
19012
  if (isUploading) {
18974
19013
  setOpen(false);
18975
19014
  }
18976
19015
  }, [isUploading]);
18977
- useEffect46(() => {
19016
+ useEffect47(() => {
18978
19017
  var _a2;
18979
19018
  setProgresses({ [(_a2 = uploadingFile == null ? void 0 : uploadingFile.name) != null ? _a2 : ""]: progress });
18980
19019
  setIsUploading(isUploading);
@@ -19008,7 +19047,7 @@ function ImageProgress({
19008
19047
  progress = 0
19009
19048
  }) {
19010
19049
  const [objectUrl, setObjectUrl] = useState49(null);
19011
- useEffect46(() => {
19050
+ useEffect47(() => {
19012
19051
  const url = URL.createObjectURL(file);
19013
19052
  setObjectUrl(url);
19014
19053
  return () => {
@@ -19167,13 +19206,13 @@ function ImagePreview() {
19167
19206
  // src/ui/media-upload-toast.tsx
19168
19207
  import { PlaceholderPlugin as PlaceholderPlugin5, UploadErrorCode } from "@platejs/media/react";
19169
19208
  import { usePluginOption as usePluginOption21 } from "platejs/react";
19170
- import { useEffect as useEffect47 } from "react";
19209
+ import { useEffect as useEffect48 } from "react";
19171
19210
  import { toast as toast4 } from "sonner";
19172
19211
 
19173
19212
  // src/ui/use-placeholder-max-file-size.ts
19174
19213
  import { PlaceholderPlugin as PlaceholderPlugin4 } from "@platejs/media/react";
19175
19214
  import { useEditorRef as useEditorRef40 } from "platejs/react";
19176
- import { useLayoutEffect as useLayoutEffect2 } from "react";
19215
+ import { useLayoutEffect as useLayoutEffect3 } from "react";
19177
19216
  var PLACEHOLDER_FILE_KIND_PATTERNS = {
19178
19217
  audio: "audio/*",
19179
19218
  blob: "*",
@@ -19206,7 +19245,7 @@ var acceptedFileTypesFromKey = (key) => {
19206
19245
  };
19207
19246
  var useEditorMaxFileSize = (editor, maxFileSize, acceptedFileTypes) => {
19208
19247
  const acceptedFileTypesKey = acceptedFileTypes == null ? void 0 : acceptedFileTypes.join(FILE_TYPE_KEY_SEPARATOR);
19209
- useLayoutEffect2(() => {
19248
+ useLayoutEffect3(() => {
19210
19249
  var _a;
19211
19250
  const previous = EDITOR_UPLOAD_CONFIGS.get(editor);
19212
19251
  if (maxFileSize === void 0 && acceptedFileTypesKey === void 0) {
@@ -19245,7 +19284,7 @@ function MediaUploadToast() {
19245
19284
  }
19246
19285
  var useUploadErrorToast = () => {
19247
19286
  const uploadError = usePluginOption21(PlaceholderPlugin5, "error");
19248
- useEffect47(() => {
19287
+ useEffect48(() => {
19249
19288
  if (!uploadError) return;
19250
19289
  const { code, data } = uploadError;
19251
19290
  switch (code) {
@@ -19708,13 +19747,13 @@ import { useCallback as useCallback64, useState as useState54 } from "react";
19708
19747
 
19709
19748
  // src/ui/mention-page-combobox-group.tsx
19710
19749
  import { FileTextIcon as FileTextIcon3 } from "lucide-react";
19711
- import { useEffect as useEffect48, useState as useState52 } from "react";
19750
+ import { useEffect as useEffect49, useState as useState52 } from "react";
19712
19751
  import { jsx as jsx172, jsxs as jsxs110 } from "react/jsx-runtime";
19713
19752
  function PageComboboxGroup({ search, onPageHover, onPageSelect }) {
19714
19753
  const adapter = useEditorAdapter();
19715
19754
  const debouncedSearch = useDebounce(search, 250);
19716
19755
  const [pages, setPages] = useState52([]);
19717
- useEffect48(() => {
19756
+ useEffect49(() => {
19718
19757
  if (!adapter.permissions.canLinkPage) {
19719
19758
  setPages([]);
19720
19759
  return;
@@ -19763,13 +19802,13 @@ function PageStatusBadge({ status }) {
19763
19802
  }
19764
19803
 
19765
19804
  // src/ui/mention-people-combobox-group.tsx
19766
- import { useEffect as useEffect49, useState as useState53 } from "react";
19805
+ import { useEffect as useEffect50, useState as useState53 } from "react";
19767
19806
  import { jsx as jsx173, jsxs as jsxs111 } from "react/jsx-runtime";
19768
19807
  function PeopleComboboxGroup({ search, onUserHover, onUserSelect }) {
19769
19808
  const adapter = useEditorAdapter();
19770
19809
  const debouncedSearch = useDebounce(search, 150);
19771
19810
  const [members, setMembers] = useState53([]);
19772
- useEffect49(() => {
19811
+ useEffect50(() => {
19773
19812
  if (!adapter.permissions.canMention) {
19774
19813
  setMembers([]);
19775
19814
  return;
@@ -21394,7 +21433,7 @@ import {
21394
21433
  useSelected as useSelected8,
21395
21434
  withHOC as withHOC8
21396
21435
  } from "platejs/react";
21397
- import { useRef as useRef18 } from "react";
21436
+ import { useRef as useRef19 } from "react";
21398
21437
 
21399
21438
  // src/ui/table-icons.tsx
21400
21439
  import { jsx as jsx180, jsxs as jsxs118 } from "react/jsx-runtime";
@@ -21598,7 +21637,7 @@ var TableElement = withHOC8(
21598
21637
  const isSelectionAreaVisible = usePluginOption22(BlockSelectionPlugin10, "isSelectionAreaVisible");
21599
21638
  const hasControls = !readOnly && !isSelectionAreaVisible;
21600
21639
  const { marginLeft, props: tableProps } = useTableElement();
21601
- const tableRef = useRef18(null);
21640
+ const tableRef = useRef19(null);
21602
21641
  useTableSelectionDom(tableRef);
21603
21642
  const isSelectingTable = useBlockSelected2(props.element.id);
21604
21643
  const content = /* @__PURE__ */ jsx181(
@@ -1,5 +1,5 @@
1
1
  import { type LucideProps } from 'lucide-react';
2
- import { type IconName } from 'lucide-react/dynamic';
2
+ import type { IconName } from 'lucide-react/dynamic';
3
3
  import * as React from 'react';
4
4
  interface SafeIconProps extends Omit<LucideProps, 'ref'> {
5
5
  name: IconName | string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/web-editor",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "A rich text editor for React, built on Plate, with Yjs multi-user editing, comments, AI, uploads, and Markdown, MDX, and HTML conversion.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",