@payloadcms/richtext-lexical 3.0.0-beta.95 → 3.0.0-beta.96

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.
Files changed (66) hide show
  1. package/dist/exports/client/{Field-SUWHJ4HF.js → Field-E27BVLS5.js} +2 -2
  2. package/dist/exports/client/Field-E27BVLS5.js.map +7 -0
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/{chunk-YSI2QILQ.js → chunk-ZH3MUMBJ.js} +1 -1
  5. package/dist/exports/client/chunk-ZH3MUMBJ.js.map +7 -0
  6. package/dist/exports/client/index.js +2 -2
  7. package/dist/exports/client/index.js.map +2 -2
  8. package/dist/features/blocks/server/index.d.ts.map +1 -1
  9. package/dist/features/blocks/server/index.js +2 -0
  10. package/dist/features/blocks/server/index.js.map +1 -1
  11. package/dist/features/converters/html/field/index.d.ts.map +1 -1
  12. package/dist/features/converters/html/field/index.js +3 -1
  13. package/dist/features/converters/html/field/index.js.map +1 -1
  14. package/dist/features/experimental_table/server/index.d.ts.map +1 -1
  15. package/dist/features/experimental_table/server/index.js +3 -1
  16. package/dist/features/experimental_table/server/index.js.map +1 -1
  17. package/dist/features/link/client/plugins/autoLink/index.d.ts.map +1 -1
  18. package/dist/features/link/client/plugins/autoLink/index.js +3 -1
  19. package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
  20. package/dist/features/link/nodes/LinkNode.js +1 -1
  21. package/dist/features/link/nodes/LinkNode.js.map +1 -1
  22. package/dist/features/link/server/index.d.ts.map +1 -1
  23. package/dist/features/link/server/index.js +2 -0
  24. package/dist/features/link/server/index.js.map +1 -1
  25. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.d.ts.map +1 -1
  26. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +9 -3
  27. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
  28. package/dist/features/typesServer.d.ts +1 -0
  29. package/dist/features/typesServer.d.ts.map +1 -1
  30. package/dist/features/typesServer.js.map +1 -1
  31. package/dist/features/upload/server/feature.server.d.ts.map +1 -1
  32. package/dist/features/upload/server/feature.server.js +5 -1
  33. package/dist/features/upload/server/feature.server.js.map +1 -1
  34. package/dist/field/bundled.css +1 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +4 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  39. package/dist/lexical/LexicalEditor.js.map +1 -1
  40. package/dist/lexical/config/server/loader.d.ts +2 -1
  41. package/dist/lexical/config/server/loader.d.ts.map +1 -1
  42. package/dist/lexical/config/server/loader.js +2 -0
  43. package/dist/lexical/config/server/loader.js.map +1 -1
  44. package/dist/lexical/config/server/sanitize.d.ts +1 -1
  45. package/dist/lexical/config/server/sanitize.d.ts.map +1 -1
  46. package/dist/lexical/config/server/sanitize.js +2 -1
  47. package/dist/lexical/config/server/sanitize.js.map +1 -1
  48. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
  49. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +3 -1
  50. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
  51. package/dist/lexical/plugins/handles/utils/doesLineHeightAffectElement.d.ts.map +1 -1
  52. package/dist/lexical/plugins/handles/utils/doesLineHeightAffectElement.js +3 -1
  53. package/dist/lexical/plugins/handles/utils/doesLineHeightAffectElement.js.map +1 -1
  54. package/dist/lexical/utils/url.d.ts.map +1 -1
  55. package/dist/lexical/utils/url.js +18 -6
  56. package/dist/lexical/utils/url.js.map +1 -1
  57. package/dist/types.d.ts +2 -1
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/types.js.map +1 -1
  60. package/dist/utilities/createServerFeature.d.ts +1 -0
  61. package/dist/utilities/createServerFeature.d.ts.map +1 -1
  62. package/dist/utilities/createServerFeature.js +2 -0
  63. package/dist/utilities/createServerFeature.js.map +1 -1
  64. package/package.json +9 -7
  65. package/dist/exports/client/Field-SUWHJ4HF.js.map +0 -7
  66. package/dist/exports/client/chunk-YSI2QILQ.js.map +0 -7
@@ -1 +1 @@
1
- {"version":3,"file":"LexicalMenu.d.ts","sourceRoot":"","sources":["../../../../../src/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACtE,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAiBxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAE9F,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,OAAO,CAAA;IACtB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB,CAAA;AAID,MAAM,MAAM,YAAY,GAAG,CACzB,gBAAgB,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAC/C,SAAS,EAAE;IACT,MAAM,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACrC,oBAAoB,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAA;IAC3D,eAAe,EAAE,IAAI,GAAG,MAAM,CAAA;IAC9B,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9C,EACD,cAAc,EAAE,IAAI,GAAG,MAAM,KAC1B,GAAG,CAAC,OAAO,GAAG,WAAW,GAAG,IAAI,CAAA;AAyErC,wBAAgB,eAAe,CAC7B,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,OAAO,GACrB,eAAe,GAAG,WAAW,CAiB/B;AAYD,wBAA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E,MAAM,CAAA;IACb,IAAI,EAAE,qBAAqB,CAAA;CAC5B,CAA8D,CAAA;AAE/D,wBAAgB,WAAW,CAAC,EAC1B,gBAAgB,EAChB,KAAK,EACL,MAAM,EAEN,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,wBAAgC,GACjC,EAAE;IACD,gBAAgB,EAAE,SAAS,CAAC,WAAW,CAAC,CAAA;IACxC,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACrC,YAAY,EAAE,YAAY,CAAA;IAC1B,YAAY,EAAE,CACZ,IAAI,EAAE,aAAa,EACnB,uBAAuB,EAAE,QAAQ,GAAG,IAAI,EACxC,SAAS,EAAE,MAAM,IAAI,EACrB,cAAc,EAAE,MAAM,KACnB,IAAI,CAAA;IACT,UAAU,EAAE,cAAc,CAAA;IAC1B,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAgNrB;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,WAAW,EACvB,UAAU,EAAE,cAAc,GAAG,IAAI,EACjC,aAAa,EAAE,CAAC,CAAC,EAAE,cAAc,GAAG,IAAI,KAAK,IAAI,EACjD,SAAS,CAAC,EAAE,MAAM,GACjB,SAAS,CAAC,WAAW,CAAC,CA6FxB"}
@@ -8,7 +8,9 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } fr
8
8
  const baseClass = 'slash-menu-popup';
9
9
  const scrollIntoViewIfNeeded = target => {
10
10
  const typeaheadContainerNode = document.getElementById('slash-menu');
11
- if (!typeaheadContainerNode) return;
11
+ if (!typeaheadContainerNode) {
12
+ return;
13
+ }
12
14
  const typeaheadRect = typeaheadContainerNode.getBoundingClientRect();
13
15
  if (typeaheadRect.top + typeaheadRect.height > window.innerHeight) {
14
16
  typeaheadContainerNode.scrollIntoView({
@@ -1 +1 @@
1
- {"version":3,"file":"LexicalMenu.js","names":["c","_c","useLexicalComposerContext","mergeRegister","$getSelection","$isRangeSelection","COMMAND_PRIORITY_LOW","KEY_ARROW_DOWN_COMMAND","KEY_ARROW_UP_COMMAND","KEY_ENTER_COMMAND","KEY_ESCAPE_COMMAND","KEY_TAB_COMMAND","createCommand","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","baseClass","scrollIntoViewIfNeeded","target","typeaheadContainerNode","document","getElementById","typeaheadRect","getBoundingClientRect","top","height","window","innerHeight","scrollIntoView","block","getFullMatchOffset","documentText","entryText","offset","triggerOffset","i","length","substring","$splitNodeContainingQuery","match","selection","isCollapsed","anchor","type","anchorNode","getNode","isSimpleText","selectionOffset","textContent","getTextContent","slice","characterOffset","replaceableString","queryOffset","matchingString","startOffset","newNode","splitText","getScrollParent","element","includeHidden","style","getComputedStyle","excludeStaticParent","position","overflowRegex","body","parent","parentElement","test","overflow","overflowY","overflowX","isTriggerVisibleInNearestScrollContainer","targetElement","containerElement","tRect","cRect","bottom","useDynamicPositioning","resolution","onReposition","onVisibilityChange","$","editor","t0","t1","rootElement","getRootElement","rootScrollParent","ticking","previousIsInView","handleScroll","requestAnimationFrame","isInView","resizeObserver","ResizeObserver","addEventListener","capture","passive","observe","unobserve","removeEventListener","SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND","LexicalMenu","anchorElementRef","close","groups","menuRenderFn","onSelectItem","shouldSplitNodeWithQuery","selectedItemKey","setSelectedItemKey","updateSelectedItem","item","rootElem","setAttribute","key","setSelectedItemKeyToFirstMatchingItem","allItems","flatMap","group","items","firstMatchingItem","selectItemAndCleanUp","selectedItem","update","textNodeContainingQuery","removeAttribute","registerCommand","ref","current","payload","event","selectedIndex","findIndex","newSelectedIndex","newSelectedItem","dispatchCommand","index","preventDefault","stopImmediatePropagation","find","listItemProps","useMenuAnchorRef","anchorElem","setResolution","className","createElement","positionMenu","containerDiv","VERTICAL_OFFSET","menuEle","firstChild","width","getRect","left","rawTop","scrollY","scrollX","menuRect","menuHeight","menuWidth","rootElementRect","right","wouldGoOffBottomOfScreen","wouldGoOffTopOfScreen","margin","isConnected","display","append","remove"],"sources":["../../../../../src/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand, LexicalEditor, TextNode } from 'lexical'\nimport type { JSX, ReactPortal, RefObject } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_LOW,\n KEY_ARROW_DOWN_COMMAND,\n KEY_ARROW_UP_COMMAND,\n KEY_ENTER_COMMAND,\n KEY_ESCAPE_COMMAND,\n KEY_TAB_COMMAND,\n createCommand,\n} from 'lexical'\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport type { MenuTextMatch } from '../useMenuTriggerMatch.js'\nimport type { SlashMenuGroupInternal, SlashMenuItem, SlashMenuItemInternal } from './types.js'\n\nexport type MenuResolution = {\n getRect: () => DOMRect\n match?: MenuTextMatch\n}\n\nconst baseClass = 'slash-menu-popup'\n\nexport type MenuRenderFn = (\n anchorElementRef: RefObject<HTMLElement | null>,\n itemProps: {\n groups: Array<SlashMenuGroupInternal>\n selectItemAndCleanUp: (selectedItem: SlashMenuItem) => void\n selectedItemKey: null | string\n setSelectedItemKey: (itemKey: string) => void\n },\n matchingString: null | string,\n) => JSX.Element | ReactPortal | null\n\nconst scrollIntoViewIfNeeded = (target: HTMLElement) => {\n const typeaheadContainerNode = document.getElementById('slash-menu')\n if (!typeaheadContainerNode) return\n\n const typeaheadRect = typeaheadContainerNode.getBoundingClientRect()\n\n if (typeaheadRect.top + typeaheadRect.height > window.innerHeight) {\n typeaheadContainerNode.scrollIntoView({\n block: 'center',\n })\n }\n\n if (typeaheadRect.top < 0) {\n typeaheadContainerNode.scrollIntoView({\n block: 'center',\n })\n }\n\n target.scrollIntoView({ block: 'nearest' })\n}\n\n/**\n * Walk backwards along user input and forward through entity title to try\n * and replace more of the user's text with entity.\n */\nfunction getFullMatchOffset(documentText: string, entryText: string, offset: number) {\n let triggerOffset = offset\n for (let i = triggerOffset; i <= entryText.length; i++) {\n if (documentText.substring(documentText.length - i) === entryText.substring(0, i)) {\n triggerOffset = i\n }\n }\n return triggerOffset\n}\n\n/**\n * Split Lexical TextNode and return a new TextNode only containing matched text.\n * Common use cases include: removing the node, replacing with a new node.\n */\nfunction $splitNodeContainingQuery(match: MenuTextMatch): TextNode | null {\n const selection = $getSelection()\n if (!$isRangeSelection(selection) || !selection.isCollapsed()) {\n return null\n }\n const anchor = selection.anchor\n if (anchor.type !== 'text') {\n return null\n }\n const anchorNode = anchor.getNode()\n if (!anchorNode.isSimpleText()) {\n return null\n }\n const selectionOffset = anchor.offset\n const textContent = anchorNode.getTextContent().slice(0, selectionOffset)\n const characterOffset = match.replaceableString.length\n const queryOffset = getFullMatchOffset(textContent, match.matchingString, characterOffset)\n const startOffset = selectionOffset - queryOffset\n if (startOffset < 0) {\n return null\n }\n let newNode\n if (startOffset === 0) {\n ;[newNode] = anchorNode.splitText(selectionOffset)\n } else {\n ;[, newNode] = anchorNode.splitText(startOffset, selectionOffset)\n }\n\n return newNode\n}\n\n// Got from https://stackoverflow.com/a/42543908/2013580\nexport function getScrollParent(\n element: HTMLElement,\n includeHidden: boolean,\n): HTMLBodyElement | HTMLElement {\n let style = getComputedStyle(element)\n const excludeStaticParent = style.position === 'absolute'\n const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/\n if (style.position === 'fixed') {\n return document.body\n }\n for (let parent: HTMLElement | null = element; (parent = parent.parentElement); ) {\n style = getComputedStyle(parent)\n if (excludeStaticParent && style.position === 'static') {\n continue\n }\n if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) {\n return parent\n }\n }\n return document.body\n}\n\nfunction isTriggerVisibleInNearestScrollContainer(\n targetElement: HTMLElement,\n containerElement: HTMLElement,\n): boolean {\n const tRect = targetElement.getBoundingClientRect()\n const cRect = containerElement.getBoundingClientRect()\n return tRect.top > cRect.top && tRect.top < cRect.bottom\n}\n\n// Reposition the menu on scroll, window resize, and element resize.\nexport function useDynamicPositioning(\n resolution: MenuResolution | null,\n targetElement: HTMLElement | null,\n onReposition: () => void,\n onVisibilityChange?: (isInView: boolean) => void,\n) {\n const [editor] = useLexicalComposerContext()\n useEffect(() => {\n if (targetElement != null && resolution != null) {\n const rootElement = editor.getRootElement()\n const rootScrollParent =\n rootElement != null ? getScrollParent(rootElement, false) : document.body\n let ticking = false\n let previousIsInView = isTriggerVisibleInNearestScrollContainer(\n targetElement,\n rootScrollParent,\n )\n const handleScroll = function () {\n if (!ticking) {\n window.requestAnimationFrame(function () {\n onReposition()\n ticking = false\n })\n ticking = true\n }\n const isInView = isTriggerVisibleInNearestScrollContainer(targetElement, rootScrollParent)\n if (isInView !== previousIsInView) {\n previousIsInView = isInView\n if (onVisibilityChange != null) {\n onVisibilityChange(isInView)\n }\n }\n }\n const resizeObserver = new ResizeObserver(onReposition)\n window.addEventListener('resize', onReposition)\n document.addEventListener('scroll', handleScroll, {\n capture: true,\n passive: true,\n })\n resizeObserver.observe(targetElement)\n return () => {\n resizeObserver.unobserve(targetElement)\n window.removeEventListener('resize', onReposition)\n document.removeEventListener('scroll', handleScroll, true)\n }\n }\n }, [targetElement, editor, onVisibilityChange, onReposition, resolution])\n}\n\nexport const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND: LexicalCommand<{\n index: number\n item: SlashMenuItemInternal\n}> = createCommand('SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND')\n\nexport function LexicalMenu({\n anchorElementRef,\n close,\n editor,\n // groups filtering is already handled in SlashMenu/index.tsx. Thus, groups always contains the matching items.\n groups,\n menuRenderFn,\n onSelectItem,\n resolution,\n shouldSplitNodeWithQuery = false,\n}: {\n anchorElementRef: RefObject<HTMLElement>\n close: () => void\n editor: LexicalEditor\n groups: Array<SlashMenuGroupInternal>\n menuRenderFn: MenuRenderFn\n onSelectItem: (\n item: SlashMenuItem,\n textNodeContainingQuery: TextNode | null,\n closeMenu: () => void,\n matchingString: string,\n ) => void\n resolution: MenuResolution\n shouldSplitNodeWithQuery?: boolean\n}): JSX.Element | null {\n const [selectedItemKey, setSelectedItemKey] = useState<null | string>(null)\n\n const matchingString = (resolution.match && resolution.match.matchingString) || ''\n\n const updateSelectedItem = useCallback(\n (item: SlashMenuItem) => {\n const rootElem = editor.getRootElement()\n if (rootElem !== null) {\n rootElem.setAttribute('aria-activedescendant', `${baseClass}__item-${item.key}`)\n setSelectedItemKey(item.key)\n }\n },\n [editor],\n )\n\n const setSelectedItemKeyToFirstMatchingItem = useCallback(() => {\n // set selected item to the first of the matching ones\n if (groups !== null && matchingString != null) {\n // groups filtering is already handled in SlashMenu/index.tsx. Thus, groups always contains the matching items.\n const allItems = groups.flatMap((group) => group.items)\n\n if (allItems.length) {\n const firstMatchingItem = allItems[0]\n updateSelectedItem(firstMatchingItem)\n }\n }\n }, [groups, updateSelectedItem, matchingString])\n\n useEffect(() => {\n setSelectedItemKeyToFirstMatchingItem()\n }, [matchingString, setSelectedItemKeyToFirstMatchingItem])\n\n const selectItemAndCleanUp = useCallback(\n (selectedItem: SlashMenuItem) => {\n editor.update(() => {\n const textNodeContainingQuery =\n resolution.match != null && shouldSplitNodeWithQuery\n ? $splitNodeContainingQuery(resolution.match)\n : null\n\n onSelectItem(\n selectedItem,\n textNodeContainingQuery,\n close,\n resolution.match ? resolution.match.matchingString : '',\n )\n })\n },\n [editor, shouldSplitNodeWithQuery, resolution.match, onSelectItem, close],\n )\n\n useEffect(() => {\n return () => {\n const rootElem = editor.getRootElement()\n if (rootElem !== null) {\n rootElem.removeAttribute('aria-activedescendant')\n }\n }\n }, [editor])\n\n useLayoutEffect(() => {\n if (groups === null) {\n setSelectedItemKey(null)\n } else if (selectedItemKey === null) {\n setSelectedItemKeyToFirstMatchingItem()\n }\n }, [groups, selectedItemKey, updateSelectedItem, setSelectedItemKeyToFirstMatchingItem])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND,\n ({ item }) => {\n if (item.ref && item.ref.current != null) {\n scrollIntoViewIfNeeded(item.ref.current)\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, updateSelectedItem])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<KeyboardEvent>(\n KEY_ARROW_DOWN_COMMAND,\n (payload) => {\n const event = payload\n if (groups !== null && groups.length && selectedItemKey !== null) {\n const allItems = groups.flatMap((group) => group.items)\n const selectedIndex = allItems.findIndex((item) => item.key === selectedItemKey)\n\n const newSelectedIndex = selectedIndex !== allItems.length - 1 ? selectedIndex + 1 : 0\n\n const newSelectedItem = allItems[newSelectedIndex]\n\n updateSelectedItem(newSelectedItem)\n if (newSelectedItem.ref != null && newSelectedItem.ref.current) {\n editor.dispatchCommand(SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND, {\n index: newSelectedIndex,\n item: newSelectedItem,\n })\n }\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand<KeyboardEvent>(\n KEY_ARROW_UP_COMMAND,\n (payload) => {\n const event = payload\n if (groups !== null && groups.length && selectedItemKey !== null) {\n const allItems = groups.flatMap((group) => group.items)\n const selectedIndex = allItems.findIndex((item) => item.key === selectedItemKey)\n\n const newSelectedIndex = selectedIndex !== 0 ? selectedIndex - 1 : allItems.length - 1\n\n const newSelectedItem = allItems[newSelectedIndex]\n\n updateSelectedItem(newSelectedItem)\n if (newSelectedItem.ref != null && newSelectedItem.ref.current) {\n scrollIntoViewIfNeeded(newSelectedItem.ref.current)\n }\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand<KeyboardEvent>(\n KEY_ESCAPE_COMMAND,\n (payload) => {\n const event = payload\n event.preventDefault()\n event.stopImmediatePropagation()\n close()\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand<KeyboardEvent>(\n KEY_TAB_COMMAND,\n (payload) => {\n const event = payload\n\n if (groups === null || selectedItemKey === null) {\n return false\n }\n const allItems = groups.flatMap((group) => group.items)\n const selectedItem = allItems.find((item) => item.key === selectedItemKey)\n if (!selectedItem) {\n return false\n }\n\n event.preventDefault()\n event.stopImmediatePropagation()\n selectItemAndCleanUp(selectedItem)\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand(\n KEY_ENTER_COMMAND,\n (event: KeyboardEvent | null) => {\n if (groups === null || selectedItemKey === null) {\n return false\n }\n const allItems = groups.flatMap((group) => group.items)\n const selectedItem = allItems.find((item) => item.key === selectedItemKey)\n if (!selectedItem) {\n return false\n }\n\n if (event !== null) {\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n selectItemAndCleanUp(selectedItem)\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [selectItemAndCleanUp, close, editor, groups, selectedItemKey, updateSelectedItem])\n\n const listItemProps = useMemo(\n () => ({\n groups,\n selectItemAndCleanUp,\n selectedItemKey,\n setSelectedItemKey,\n }),\n [selectItemAndCleanUp, selectedItemKey, groups],\n )\n\n return menuRenderFn(\n anchorElementRef,\n listItemProps,\n resolution.match ? resolution.match.matchingString : '',\n )\n}\n\nexport function useMenuAnchorRef(\n anchorElem: HTMLElement,\n resolution: MenuResolution | null,\n setResolution: (r: MenuResolution | null) => void,\n className?: string,\n): RefObject<HTMLElement> {\n const [editor] = useLexicalComposerContext()\n const anchorElementRef = useRef<HTMLElement>(document.createElement('div'))\n const positionMenu = useCallback(() => {\n const rootElement = editor.getRootElement()\n const containerDiv = anchorElementRef.current\n\n const VERTICAL_OFFSET = 32\n\n const menuEle = containerDiv.firstChild as Element\n if (rootElement !== null && resolution !== null) {\n const { height, width } = resolution.getRect()\n let { left, top } = resolution.getRect()\n\n const rawTop = top\n top -= anchorElem.getBoundingClientRect().top + window.scrollY\n left -= anchorElem.getBoundingClientRect().left + window.scrollX\n containerDiv.style.left = `${left + window.scrollX}px`\n containerDiv.style.height = `${height}px`\n containerDiv.style.width = `${width}px`\n if (menuEle !== null) {\n const menuRect = menuEle.getBoundingClientRect()\n const menuHeight = menuRect.height\n const menuWidth = menuRect.width\n\n const rootElementRect = rootElement.getBoundingClientRect()\n\n if (left + menuWidth > rootElementRect.right) {\n containerDiv.style.left = `${rootElementRect.right - menuWidth + window.scrollX}px`\n }\n\n const wouldGoOffBottomOfScreen = rawTop + menuHeight + VERTICAL_OFFSET > window.innerHeight\n //const wouldGoOffBottomOfContainer = top + menuHeight > rootElementRect.bottom\n const wouldGoOffTopOfScreen = rawTop < 0\n\n // Position slash menu above the cursor instead of below (default) if it would otherwise go off the bottom of the screen.\n if (wouldGoOffBottomOfScreen && !wouldGoOffTopOfScreen) {\n const margin = 24\n containerDiv.style.top = `${\n top + VERTICAL_OFFSET - menuHeight + window.scrollY - (height + margin)\n }px`\n } else {\n containerDiv.style.top = `${top + window.scrollY + VERTICAL_OFFSET}px`\n }\n }\n\n if (!containerDiv.isConnected) {\n if (className != null) {\n containerDiv.className = className\n }\n containerDiv.setAttribute('aria-label', 'Slash menu')\n containerDiv.setAttribute('id', 'slash-menu')\n containerDiv.setAttribute('role', 'listbox')\n containerDiv.style.display = 'block'\n containerDiv.style.position = 'absolute'\n anchorElem.append(containerDiv)\n }\n anchorElementRef.current = containerDiv\n rootElement.setAttribute('aria-controls', 'slash-menu')\n }\n }, [editor, resolution, className, anchorElem])\n\n useEffect(() => {\n const rootElement = editor.getRootElement()\n if (resolution !== null) {\n positionMenu()\n return () => {\n if (rootElement !== null) {\n rootElement.removeAttribute('aria-controls')\n }\n\n const containerDiv = anchorElementRef.current\n if (containerDiv !== null && containerDiv.isConnected) {\n containerDiv.remove()\n }\n }\n }\n }, [editor, positionMenu, resolution])\n\n const onVisibilityChange = useCallback(\n (isInView: boolean) => {\n if (resolution !== null) {\n if (!isInView) {\n setResolution(null)\n }\n }\n },\n [resolution, setResolution],\n )\n\n useDynamicPositioning(resolution, anchorElementRef.current, positionMenu, onVisibilityChange)\n\n return anchorElementRef\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,QAAQ;AAC9B,SACEC,aAAa,EACbC,iBAAiB,EACjBC,oBAAoB,EACpBC,sBAAsB,EACtBC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,eAAe,EACfC,aAAa,QACR;AACP,SAASC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAUnF,MAAMC,SAAA,GAAY;AAalB,MAAMC,sBAAA,GAA0BC,MAAA;EAC9B,MAAMC,sBAAA,GAAyBC,QAAA,CAASC,cAAc,CAAC;EACvD,IAAI,CAACF,sBAAA,EAAwB;EAE7B,MAAMG,aAAA,GAAgBH,sBAAA,CAAuBI,qBAAqB;EAElE,IAAID,aAAA,CAAcE,GAAG,GAAGF,aAAA,CAAcG,MAAM,GAAGC,MAAA,CAAOC,WAAW,EAAE;IACjER,sBAAA,CAAuBS,cAAc,CAAC;MACpCC,KAAA,EAAO;IACT;EACF;EAEA,IAAIP,aAAA,CAAcE,GAAG,GAAG,GAAG;IACzBL,sBAAA,CAAuBS,cAAc,CAAC;MACpCC,KAAA,EAAO;IACT;EACF;EAEAX,MAAA,CAAOU,cAAc,CAAC;IAAEC,KAAA,EAAO;EAAU;AAC3C;AAEA;;;;AAIA,SAASC,mBAAmBC,YAAoB,EAAEC,SAAiB,EAAEC,MAAc;EACjF,IAAIC,aAAA,GAAgBD,MAAA;EACpB,KAAK,IAAIE,CAAA,GAAID,aAAA,EAAe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AAA;MACA,OAAO;QACL,IAAI9D,aAAA,KAAgB,MAAM;UACxBA,aAAA,CAAYyC,eAAe,CAAC;QAC9B;QAEA,MAAMsB,cAAA,GAAe7C,gBAAA,CAAiB0B,OAAO;QAC7C,IAAImB,cAAA,KAAiB,QAAQA,cAAA,CAAakB,WAAW,EAAE;UACrDlB,cAAA,CAAaqB,MAAM;QACrB;MACF;IACF;EACF,GAAG,CAACvF,MAAA,EAAQiE,YAAA,EAAcrE,UAAA,CAAW;EAErC,MAAME,kBAAA,GAAqBxE,WAAA,CACxBoF,QAAA;IACC,IAAId,UAAA,KAAe,MAAM;MACvB,IAAI,CAACc,QAAA,EAAU;QACboD,aAAA,CAAc;MAChB;IACF;EACF,GACA,CAAClE,UAAA,EAAYkE,aAAA,CAAc;EAG7BnE,qBAAA,CAAsBC,UAAA,EAAYyB,gBAAA,CAAiB0B,OAAO,EAAEkB,YAAA,EAAcnE,kBAAA;EAE1E,OAAOuB,gBAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"LexicalMenu.js","names":["c","_c","useLexicalComposerContext","mergeRegister","$getSelection","$isRangeSelection","COMMAND_PRIORITY_LOW","KEY_ARROW_DOWN_COMMAND","KEY_ARROW_UP_COMMAND","KEY_ENTER_COMMAND","KEY_ESCAPE_COMMAND","KEY_TAB_COMMAND","createCommand","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","baseClass","scrollIntoViewIfNeeded","target","typeaheadContainerNode","document","getElementById","typeaheadRect","getBoundingClientRect","top","height","window","innerHeight","scrollIntoView","block","getFullMatchOffset","documentText","entryText","offset","triggerOffset","i","length","substring","$splitNodeContainingQuery","match","selection","isCollapsed","anchor","type","anchorNode","getNode","isSimpleText","selectionOffset","textContent","getTextContent","slice","characterOffset","replaceableString","queryOffset","matchingString","startOffset","newNode","splitText","getScrollParent","element","includeHidden","style","getComputedStyle","excludeStaticParent","position","overflowRegex","body","parent","parentElement","test","overflow","overflowY","overflowX","isTriggerVisibleInNearestScrollContainer","targetElement","containerElement","tRect","cRect","bottom","useDynamicPositioning","resolution","onReposition","onVisibilityChange","$","editor","t0","t1","rootElement","getRootElement","rootScrollParent","ticking","previousIsInView","handleScroll","requestAnimationFrame","isInView","resizeObserver","ResizeObserver","addEventListener","capture","passive","observe","unobserve","removeEventListener","SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND","LexicalMenu","anchorElementRef","close","groups","menuRenderFn","onSelectItem","shouldSplitNodeWithQuery","selectedItemKey","setSelectedItemKey","updateSelectedItem","item","rootElem","setAttribute","key","setSelectedItemKeyToFirstMatchingItem","allItems","flatMap","group","items","firstMatchingItem","selectItemAndCleanUp","selectedItem","update","textNodeContainingQuery","removeAttribute","registerCommand","ref","current","payload","event","selectedIndex","findIndex","newSelectedIndex","newSelectedItem","dispatchCommand","index","preventDefault","stopImmediatePropagation","find","listItemProps","useMenuAnchorRef","anchorElem","setResolution","className","createElement","positionMenu","containerDiv","VERTICAL_OFFSET","menuEle","firstChild","width","getRect","left","rawTop","scrollY","scrollX","menuRect","menuHeight","menuWidth","rootElementRect","right","wouldGoOffBottomOfScreen","wouldGoOffTopOfScreen","margin","isConnected","display","append","remove"],"sources":["../../../../../src/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand, LexicalEditor, TextNode } from 'lexical'\nimport type { JSX, ReactPortal, RefObject } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_LOW,\n KEY_ARROW_DOWN_COMMAND,\n KEY_ARROW_UP_COMMAND,\n KEY_ENTER_COMMAND,\n KEY_ESCAPE_COMMAND,\n KEY_TAB_COMMAND,\n createCommand,\n} from 'lexical'\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport type { MenuTextMatch } from '../useMenuTriggerMatch.js'\nimport type { SlashMenuGroupInternal, SlashMenuItem, SlashMenuItemInternal } from './types.js'\n\nexport type MenuResolution = {\n getRect: () => DOMRect\n match?: MenuTextMatch\n}\n\nconst baseClass = 'slash-menu-popup'\n\nexport type MenuRenderFn = (\n anchorElementRef: RefObject<HTMLElement | null>,\n itemProps: {\n groups: Array<SlashMenuGroupInternal>\n selectItemAndCleanUp: (selectedItem: SlashMenuItem) => void\n selectedItemKey: null | string\n setSelectedItemKey: (itemKey: string) => void\n },\n matchingString: null | string,\n) => JSX.Element | ReactPortal | null\n\nconst scrollIntoViewIfNeeded = (target: HTMLElement) => {\n const typeaheadContainerNode = document.getElementById('slash-menu')\n if (!typeaheadContainerNode) {\n return\n }\n\n const typeaheadRect = typeaheadContainerNode.getBoundingClientRect()\n\n if (typeaheadRect.top + typeaheadRect.height > window.innerHeight) {\n typeaheadContainerNode.scrollIntoView({\n block: 'center',\n })\n }\n\n if (typeaheadRect.top < 0) {\n typeaheadContainerNode.scrollIntoView({\n block: 'center',\n })\n }\n\n target.scrollIntoView({ block: 'nearest' })\n}\n\n/**\n * Walk backwards along user input and forward through entity title to try\n * and replace more of the user's text with entity.\n */\nfunction getFullMatchOffset(documentText: string, entryText: string, offset: number) {\n let triggerOffset = offset\n for (let i = triggerOffset; i <= entryText.length; i++) {\n if (documentText.substring(documentText.length - i) === entryText.substring(0, i)) {\n triggerOffset = i\n }\n }\n return triggerOffset\n}\n\n/**\n * Split Lexical TextNode and return a new TextNode only containing matched text.\n * Common use cases include: removing the node, replacing with a new node.\n */\nfunction $splitNodeContainingQuery(match: MenuTextMatch): TextNode | null {\n const selection = $getSelection()\n if (!$isRangeSelection(selection) || !selection.isCollapsed()) {\n return null\n }\n const anchor = selection.anchor\n if (anchor.type !== 'text') {\n return null\n }\n const anchorNode = anchor.getNode()\n if (!anchorNode.isSimpleText()) {\n return null\n }\n const selectionOffset = anchor.offset\n const textContent = anchorNode.getTextContent().slice(0, selectionOffset)\n const characterOffset = match.replaceableString.length\n const queryOffset = getFullMatchOffset(textContent, match.matchingString, characterOffset)\n const startOffset = selectionOffset - queryOffset\n if (startOffset < 0) {\n return null\n }\n let newNode\n if (startOffset === 0) {\n ;[newNode] = anchorNode.splitText(selectionOffset)\n } else {\n ;[, newNode] = anchorNode.splitText(startOffset, selectionOffset)\n }\n\n return newNode\n}\n\n// Got from https://stackoverflow.com/a/42543908/2013580\nexport function getScrollParent(\n element: HTMLElement,\n includeHidden: boolean,\n): HTMLBodyElement | HTMLElement {\n let style = getComputedStyle(element)\n const excludeStaticParent = style.position === 'absolute'\n const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/\n if (style.position === 'fixed') {\n return document.body\n }\n for (let parent: HTMLElement | null = element; (parent = parent.parentElement); ) {\n style = getComputedStyle(parent)\n if (excludeStaticParent && style.position === 'static') {\n continue\n }\n if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) {\n return parent\n }\n }\n return document.body\n}\n\nfunction isTriggerVisibleInNearestScrollContainer(\n targetElement: HTMLElement,\n containerElement: HTMLElement,\n): boolean {\n const tRect = targetElement.getBoundingClientRect()\n const cRect = containerElement.getBoundingClientRect()\n return tRect.top > cRect.top && tRect.top < cRect.bottom\n}\n\n// Reposition the menu on scroll, window resize, and element resize.\nexport function useDynamicPositioning(\n resolution: MenuResolution | null,\n targetElement: HTMLElement | null,\n onReposition: () => void,\n onVisibilityChange?: (isInView: boolean) => void,\n) {\n const [editor] = useLexicalComposerContext()\n useEffect(() => {\n if (targetElement != null && resolution != null) {\n const rootElement = editor.getRootElement()\n const rootScrollParent =\n rootElement != null ? getScrollParent(rootElement, false) : document.body\n let ticking = false\n let previousIsInView = isTriggerVisibleInNearestScrollContainer(\n targetElement,\n rootScrollParent,\n )\n const handleScroll = function () {\n if (!ticking) {\n window.requestAnimationFrame(function () {\n onReposition()\n ticking = false\n })\n ticking = true\n }\n const isInView = isTriggerVisibleInNearestScrollContainer(targetElement, rootScrollParent)\n if (isInView !== previousIsInView) {\n previousIsInView = isInView\n if (onVisibilityChange != null) {\n onVisibilityChange(isInView)\n }\n }\n }\n const resizeObserver = new ResizeObserver(onReposition)\n window.addEventListener('resize', onReposition)\n document.addEventListener('scroll', handleScroll, {\n capture: true,\n passive: true,\n })\n resizeObserver.observe(targetElement)\n return () => {\n resizeObserver.unobserve(targetElement)\n window.removeEventListener('resize', onReposition)\n document.removeEventListener('scroll', handleScroll, true)\n }\n }\n }, [targetElement, editor, onVisibilityChange, onReposition, resolution])\n}\n\nexport const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND: LexicalCommand<{\n index: number\n item: SlashMenuItemInternal\n}> = createCommand('SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND')\n\nexport function LexicalMenu({\n anchorElementRef,\n close,\n editor,\n // groups filtering is already handled in SlashMenu/index.tsx. Thus, groups always contains the matching items.\n groups,\n menuRenderFn,\n onSelectItem,\n resolution,\n shouldSplitNodeWithQuery = false,\n}: {\n anchorElementRef: RefObject<HTMLElement>\n close: () => void\n editor: LexicalEditor\n groups: Array<SlashMenuGroupInternal>\n menuRenderFn: MenuRenderFn\n onSelectItem: (\n item: SlashMenuItem,\n textNodeContainingQuery: TextNode | null,\n closeMenu: () => void,\n matchingString: string,\n ) => void\n resolution: MenuResolution\n shouldSplitNodeWithQuery?: boolean\n}): JSX.Element | null {\n const [selectedItemKey, setSelectedItemKey] = useState<null | string>(null)\n\n const matchingString = (resolution.match && resolution.match.matchingString) || ''\n\n const updateSelectedItem = useCallback(\n (item: SlashMenuItem) => {\n const rootElem = editor.getRootElement()\n if (rootElem !== null) {\n rootElem.setAttribute('aria-activedescendant', `${baseClass}__item-${item.key}`)\n setSelectedItemKey(item.key)\n }\n },\n [editor],\n )\n\n const setSelectedItemKeyToFirstMatchingItem = useCallback(() => {\n // set selected item to the first of the matching ones\n if (groups !== null && matchingString != null) {\n // groups filtering is already handled in SlashMenu/index.tsx. Thus, groups always contains the matching items.\n const allItems = groups.flatMap((group) => group.items)\n\n if (allItems.length) {\n const firstMatchingItem = allItems[0]\n updateSelectedItem(firstMatchingItem)\n }\n }\n }, [groups, updateSelectedItem, matchingString])\n\n useEffect(() => {\n setSelectedItemKeyToFirstMatchingItem()\n }, [matchingString, setSelectedItemKeyToFirstMatchingItem])\n\n const selectItemAndCleanUp = useCallback(\n (selectedItem: SlashMenuItem) => {\n editor.update(() => {\n const textNodeContainingQuery =\n resolution.match != null && shouldSplitNodeWithQuery\n ? $splitNodeContainingQuery(resolution.match)\n : null\n\n onSelectItem(\n selectedItem,\n textNodeContainingQuery,\n close,\n resolution.match ? resolution.match.matchingString : '',\n )\n })\n },\n [editor, shouldSplitNodeWithQuery, resolution.match, onSelectItem, close],\n )\n\n useEffect(() => {\n return () => {\n const rootElem = editor.getRootElement()\n if (rootElem !== null) {\n rootElem.removeAttribute('aria-activedescendant')\n }\n }\n }, [editor])\n\n useLayoutEffect(() => {\n if (groups === null) {\n setSelectedItemKey(null)\n } else if (selectedItemKey === null) {\n setSelectedItemKeyToFirstMatchingItem()\n }\n }, [groups, selectedItemKey, updateSelectedItem, setSelectedItemKeyToFirstMatchingItem])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND,\n ({ item }) => {\n if (item.ref && item.ref.current != null) {\n scrollIntoViewIfNeeded(item.ref.current)\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, updateSelectedItem])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<KeyboardEvent>(\n KEY_ARROW_DOWN_COMMAND,\n (payload) => {\n const event = payload\n if (groups !== null && groups.length && selectedItemKey !== null) {\n const allItems = groups.flatMap((group) => group.items)\n const selectedIndex = allItems.findIndex((item) => item.key === selectedItemKey)\n\n const newSelectedIndex = selectedIndex !== allItems.length - 1 ? selectedIndex + 1 : 0\n\n const newSelectedItem = allItems[newSelectedIndex]\n\n updateSelectedItem(newSelectedItem)\n if (newSelectedItem.ref != null && newSelectedItem.ref.current) {\n editor.dispatchCommand(SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND, {\n index: newSelectedIndex,\n item: newSelectedItem,\n })\n }\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand<KeyboardEvent>(\n KEY_ARROW_UP_COMMAND,\n (payload) => {\n const event = payload\n if (groups !== null && groups.length && selectedItemKey !== null) {\n const allItems = groups.flatMap((group) => group.items)\n const selectedIndex = allItems.findIndex((item) => item.key === selectedItemKey)\n\n const newSelectedIndex = selectedIndex !== 0 ? selectedIndex - 1 : allItems.length - 1\n\n const newSelectedItem = allItems[newSelectedIndex]\n\n updateSelectedItem(newSelectedItem)\n if (newSelectedItem.ref != null && newSelectedItem.ref.current) {\n scrollIntoViewIfNeeded(newSelectedItem.ref.current)\n }\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand<KeyboardEvent>(\n KEY_ESCAPE_COMMAND,\n (payload) => {\n const event = payload\n event.preventDefault()\n event.stopImmediatePropagation()\n close()\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand<KeyboardEvent>(\n KEY_TAB_COMMAND,\n (payload) => {\n const event = payload\n\n if (groups === null || selectedItemKey === null) {\n return false\n }\n const allItems = groups.flatMap((group) => group.items)\n const selectedItem = allItems.find((item) => item.key === selectedItemKey)\n if (!selectedItem) {\n return false\n }\n\n event.preventDefault()\n event.stopImmediatePropagation()\n selectItemAndCleanUp(selectedItem)\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand(\n KEY_ENTER_COMMAND,\n (event: KeyboardEvent | null) => {\n if (groups === null || selectedItemKey === null) {\n return false\n }\n const allItems = groups.flatMap((group) => group.items)\n const selectedItem = allItems.find((item) => item.key === selectedItemKey)\n if (!selectedItem) {\n return false\n }\n\n if (event !== null) {\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n selectItemAndCleanUp(selectedItem)\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [selectItemAndCleanUp, close, editor, groups, selectedItemKey, updateSelectedItem])\n\n const listItemProps = useMemo(\n () => ({\n groups,\n selectItemAndCleanUp,\n selectedItemKey,\n setSelectedItemKey,\n }),\n [selectItemAndCleanUp, selectedItemKey, groups],\n )\n\n return menuRenderFn(\n anchorElementRef,\n listItemProps,\n resolution.match ? resolution.match.matchingString : '',\n )\n}\n\nexport function useMenuAnchorRef(\n anchorElem: HTMLElement,\n resolution: MenuResolution | null,\n setResolution: (r: MenuResolution | null) => void,\n className?: string,\n): RefObject<HTMLElement> {\n const [editor] = useLexicalComposerContext()\n const anchorElementRef = useRef<HTMLElement>(document.createElement('div'))\n const positionMenu = useCallback(() => {\n const rootElement = editor.getRootElement()\n const containerDiv = anchorElementRef.current\n\n const VERTICAL_OFFSET = 32\n\n const menuEle = containerDiv.firstChild as Element\n if (rootElement !== null && resolution !== null) {\n const { height, width } = resolution.getRect()\n let { left, top } = resolution.getRect()\n\n const rawTop = top\n top -= anchorElem.getBoundingClientRect().top + window.scrollY\n left -= anchorElem.getBoundingClientRect().left + window.scrollX\n containerDiv.style.left = `${left + window.scrollX}px`\n containerDiv.style.height = `${height}px`\n containerDiv.style.width = `${width}px`\n if (menuEle !== null) {\n const menuRect = menuEle.getBoundingClientRect()\n const menuHeight = menuRect.height\n const menuWidth = menuRect.width\n\n const rootElementRect = rootElement.getBoundingClientRect()\n\n if (left + menuWidth > rootElementRect.right) {\n containerDiv.style.left = `${rootElementRect.right - menuWidth + window.scrollX}px`\n }\n\n const wouldGoOffBottomOfScreen = rawTop + menuHeight + VERTICAL_OFFSET > window.innerHeight\n //const wouldGoOffBottomOfContainer = top + menuHeight > rootElementRect.bottom\n const wouldGoOffTopOfScreen = rawTop < 0\n\n // Position slash menu above the cursor instead of below (default) if it would otherwise go off the bottom of the screen.\n if (wouldGoOffBottomOfScreen && !wouldGoOffTopOfScreen) {\n const margin = 24\n containerDiv.style.top = `${\n top + VERTICAL_OFFSET - menuHeight + window.scrollY - (height + margin)\n }px`\n } else {\n containerDiv.style.top = `${top + window.scrollY + VERTICAL_OFFSET}px`\n }\n }\n\n if (!containerDiv.isConnected) {\n if (className != null) {\n containerDiv.className = className\n }\n containerDiv.setAttribute('aria-label', 'Slash menu')\n containerDiv.setAttribute('id', 'slash-menu')\n containerDiv.setAttribute('role', 'listbox')\n containerDiv.style.display = 'block'\n containerDiv.style.position = 'absolute'\n anchorElem.append(containerDiv)\n }\n anchorElementRef.current = containerDiv\n rootElement.setAttribute('aria-controls', 'slash-menu')\n }\n }, [editor, resolution, className, anchorElem])\n\n useEffect(() => {\n const rootElement = editor.getRootElement()\n if (resolution !== null) {\n positionMenu()\n return () => {\n if (rootElement !== null) {\n rootElement.removeAttribute('aria-controls')\n }\n\n const containerDiv = anchorElementRef.current\n if (containerDiv !== null && containerDiv.isConnected) {\n containerDiv.remove()\n }\n }\n }\n }, [editor, positionMenu, resolution])\n\n const onVisibilityChange = useCallback(\n (isInView: boolean) => {\n if (resolution !== null) {\n if (!isInView) {\n setResolution(null)\n }\n }\n },\n [resolution, setResolution],\n )\n\n useDynamicPositioning(resolution, anchorElementRef.current, positionMenu, onVisibilityChange)\n\n return anchorElementRef\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,QAAQ;AAC9B,SACEC,aAAa,EACbC,iBAAiB,EACjBC,oBAAoB,EACpBC,sBAAsB,EACtBC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,eAAe,EACfC,aAAa,QACR;AACP,SAASC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAUnF,MAAMC,SAAA,GAAY;AAalB,MAAMC,sBAAA,GAA0BC,MAAA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[]}
@@ -1 +1 @@
1
- {"version":3,"file":"doesLineHeightAffectElement.d.ts","sourceRoot":"","sources":["../../../../../src/lexical/plugins/handles/utils/doesLineHeightAffectElement.ts"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,WAAW,WA2BhE"}
1
+ {"version":3,"file":"doesLineHeightAffectElement.d.ts","sourceRoot":"","sources":["../../../../../src/lexical/plugins/handles/utils/doesLineHeightAffectElement.ts"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,WAAW,WA6BhE"}
@@ -9,7 +9,9 @@ const replacedElements = ['IMG', 'INPUT', 'TEXTAREA', 'SELECT', 'BUTTON', 'VIDEO
9
9
  * @param htmlElem
10
10
  */
11
11
  export function doesLineHeightAffectElement(htmlElem) {
12
- if (!htmlElem) return false;
12
+ if (!htmlElem) {
13
+ return false;
14
+ }
13
15
  // Check for replaced elements, elements that typically don't support line-height adjustments,
14
16
  // and elements without visible content
15
17
  if (replacedElements.includes(htmlElem.tagName) || htmlElem.offsetHeight === 0 || htmlElem.offsetWidth === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"doesLineHeightAffectElement.js","names":["replacedElements","doesLineHeightAffectElement","htmlElem","includes","tagName","offsetHeight","offsetWidth","style","window","getComputedStyle","display","position","visibility","opacity"],"sources":["../../../../../src/lexical/plugins/handles/utils/doesLineHeightAffectElement.ts"],"sourcesContent":["'use client'\nconst replacedElements = [\n 'IMG',\n 'INPUT',\n 'TEXTAREA',\n 'SELECT',\n 'BUTTON',\n 'VIDEO',\n 'OBJECT',\n 'EMBED',\n 'IFRAME',\n 'HR',\n]\n\n/**\n * From ChatGPT, only that verified it works for HR elements.\n *\n * HTML Elements can have CSS lineHeight applied to them, but it doesn't always affect the visual layout.\n * This function checks if the line-height property has an effect on the element's layout.\n * @param htmlElem\n */\nexport function doesLineHeightAffectElement(htmlElem: HTMLElement) {\n if (!htmlElem) return false\n\n // Check for replaced elements, elements that typically don't support line-height adjustments,\n // and elements without visible content\n\n if (\n replacedElements.includes(htmlElem.tagName) ||\n htmlElem.offsetHeight === 0 ||\n htmlElem.offsetWidth === 0\n ) {\n return false\n }\n\n // Check for specific CSS properties that negate line-height's visual effects\n const style = window.getComputedStyle(htmlElem)\n if (\n style.display === 'table-cell' ||\n style.position === 'absolute' ||\n style.visibility === 'hidden' ||\n style.opacity === '0'\n ) {\n return false\n }\n\n // This is a basic check, and there can be more complex scenarios where line-height doesn't have an effect.\n return true\n}\n"],"mappings":"AAAA;;AACA,MAAMA,gBAAA,GAAmB,CACvB,OACA,SACA,YACA,UACA,UACA,SACA,UACA,SACA,UACA,KACD;AAED;;;;;;;AAOA,OAAO,SAASC,4BAA4BC,QAAqB;EAC/D,IAAI,CAACA,QAAA,EAAU,OAAO;EAEtB;EACA;EAEA,IACEF,gBAAA,CAAiBG,QAAQ,CAACD,QAAA,CAASE,OAAO,KAC1CF,QAAA,CAASG,YAAY,KAAK,KAC1BH,QAAA,CAASI,WAAW,KAAK,GACzB;IACA,OAAO;EACT;EAEA;EACA,MAAMC,KAAA,GAAQC,MAAA,CAAOC,gBAAgB,CAACP,QAAA;EACtC,IACEK,KAAA,CAAMG,OAAO,KAAK,gBAClBH,KAAA,CAAMI,QAAQ,KAAK,cACnBJ,KAAA,CAAMK,UAAU,KAAK,YACrBL,KAAA,CAAMM,OAAO,KAAK,KAClB;IACA,OAAO;EACT;EAEA;EACA,OAAO;AACT","ignoreList":[]}
1
+ {"version":3,"file":"doesLineHeightAffectElement.js","names":["replacedElements","doesLineHeightAffectElement","htmlElem","includes","tagName","offsetHeight","offsetWidth","style","window","getComputedStyle","display","position","visibility","opacity"],"sources":["../../../../../src/lexical/plugins/handles/utils/doesLineHeightAffectElement.ts"],"sourcesContent":["'use client'\nconst replacedElements = [\n 'IMG',\n 'INPUT',\n 'TEXTAREA',\n 'SELECT',\n 'BUTTON',\n 'VIDEO',\n 'OBJECT',\n 'EMBED',\n 'IFRAME',\n 'HR',\n]\n\n/**\n * From ChatGPT, only that verified it works for HR elements.\n *\n * HTML Elements can have CSS lineHeight applied to them, but it doesn't always affect the visual layout.\n * This function checks if the line-height property has an effect on the element's layout.\n * @param htmlElem\n */\nexport function doesLineHeightAffectElement(htmlElem: HTMLElement) {\n if (!htmlElem) {\n return false\n }\n\n // Check for replaced elements, elements that typically don't support line-height adjustments,\n // and elements without visible content\n\n if (\n replacedElements.includes(htmlElem.tagName) ||\n htmlElem.offsetHeight === 0 ||\n htmlElem.offsetWidth === 0\n ) {\n return false\n }\n\n // Check for specific CSS properties that negate line-height's visual effects\n const style = window.getComputedStyle(htmlElem)\n if (\n style.display === 'table-cell' ||\n style.position === 'absolute' ||\n style.visibility === 'hidden' ||\n style.opacity === '0'\n ) {\n return false\n }\n\n // This is a basic check, and there can be more complex scenarios where line-height doesn't have an effect.\n return true\n}\n"],"mappings":"AAAA;;AACA,MAAMA,gBAAA,GAAmB,CACvB,OACA,SACA,YACA,UACA,UACA,SACA,UACA,SACA,UACA,KACD;AAED;;;;;;;AAOA,OAAO,SAASC,4BAA4BC,QAAqB;EAC/D,IAAI,CAACA,QAAA,EAAU;IACb,OAAO;EACT;EAEA;EACA;EAEA,IACEF,gBAAA,CAAiBG,QAAQ,CAACD,QAAA,CAASE,OAAO,KAC1CF,QAAA,CAASG,YAAY,KAAK,KAC1BH,QAAA,CAASI,WAAW,KAAK,GACzB;IACA,OAAO;EACT;EAEA;EACA,MAAMC,KAAA,GAAQC,MAAA,CAAOC,gBAAgB,CAACP,QAAA;EACtC,IACEK,KAAA,CAAMG,OAAO,KAAK,gBAClBH,KAAA,CAAMI,QAAQ,KAAK,cACnBJ,KAAA,CAAMK,UAAU,KAAK,YACrBL,KAAA,CAAMM,OAAO,KAAK,KAClB;IACA,OAAO;EACT;EAEA;EACA,OAAO;AACT","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/lexical/utils/url.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAa/C;AAcD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIvD;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAuBhD"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/lexical/utils/url.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAe/C;AAcD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMvD;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CA+BhD"}
@@ -3,7 +3,9 @@ export function sanitizeUrl(url) {
3
3
  /** A pattern that matches safe data URLs. */
4
4
  const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[a-z\d+/]+=*$/i;
5
5
  url = String(url).trim();
6
- if (url.match(SAFE_URL_PATTERN) != null || url.match(DATA_URL_PATTERN) != null) return url;
6
+ if (url.match(SAFE_URL_PATTERN) != null || url.match(DATA_URL_PATTERN) != null) {
7
+ return url;
8
+ }
7
9
  return 'https://';
8
10
  }
9
11
  // Source: https://stackoverflow.com/a/8234912/2013580
@@ -20,7 +22,9 @@ const relativeOrAnchorRegExp = /^[\w\-./]*(?:#\w[\w-]*)?$/;
20
22
  * @param url
21
23
  */
22
24
  export function validateUrlMinimal(url) {
23
- if (!url) return false;
25
+ if (!url) {
26
+ return false;
27
+ }
24
28
  return !url.includes(' ');
25
29
  }
26
30
  // Do not keep validateUrl function too loose. This is run when pasting in text, to determine if links are in that text and if it should create AutoLinkNodes.
@@ -28,12 +32,20 @@ export function validateUrlMinimal(url) {
28
32
  export function validateUrl(url) {
29
33
  // TODO Fix UI for link insertion; it should never default to an invalid URL such as https://.
30
34
  // Maybe show a dialog where they user can type the URL before inserting it.
31
- if (!url) return false;
32
- if (url === 'https://') return true;
35
+ if (!url) {
36
+ return false;
37
+ }
38
+ if (url === 'https://') {
39
+ return true;
40
+ }
33
41
  // This makes sure URLs starting with www. instead of https are valid too
34
- if (absoluteRegExp.test(url)) return true;
42
+ if (absoluteRegExp.test(url)) {
43
+ return true;
44
+ }
35
45
  // Check relative or anchor links
36
- if (relativeOrAnchorRegExp.test(url)) return true;
46
+ if (relativeOrAnchorRegExp.test(url)) {
47
+ return true;
48
+ }
37
49
  // While this doesn't allow URLs starting with www (which is why we use the regex above), it does properly handle tel: URLs
38
50
  try {
39
51
  new URL(url);
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","names":["sanitizeUrl","url","SAFE_URL_PATTERN","DATA_URL_PATTERN","String","trim","match","absoluteRegExp","relativeOrAnchorRegExp","validateUrlMinimal","includes","validateUrl","test","URL"],"sources":["../../../src/lexical/utils/url.ts"],"sourcesContent":["export function sanitizeUrl(url: string): string {\n /** A pattern that matches safe URLs. */\n const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi\n\n /** A pattern that matches safe data URLs. */\n const DATA_URL_PATTERN =\n /^data:(?:image\\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\\/(?:mpeg|mp4|ogg|webm)|audio\\/(?:mp3|oga|ogg|opus));base64,[a-z\\d+/]+=*$/i\n\n url = String(url).trim()\n\n if (url.match(SAFE_URL_PATTERN) != null || url.match(DATA_URL_PATTERN) != null) return url\n\n return 'https://'\n}\n\n// Source: https://stackoverflow.com/a/8234912/2013580\nconst absoluteRegExp =\n /(?:[A-Za-z]{3,9}:(?:\\/\\/)?(?:[-;:&=+$,\\w]+@)?[A-Za-z\\d.-]+|(?:www.|[-;:&=+$,\\w]+@)[A-Za-z\\d.-]+)(?:\\/[+~%/.\\w-]*)?\\??[-+=&;%@.\\w]*#?\\w*/\n\n/**\n * This regex checks for relative URLs starting with / or anchor links starting with # in a string. Tested for the following use cases:\n * - /privacy-policy\n * - /privacy-policy#primary-terms\n * - #primary-terms\n * */\nconst relativeOrAnchorRegExp = /^[\\w\\-./]*(?:#\\w[\\w-]*)?$/\n\n/**\n * Prevents unreasonable URLs from being inserted into the editor.\n * @param url\n */\nexport function validateUrlMinimal(url: string): boolean {\n if (!url) return false\n\n return !url.includes(' ')\n}\n\n// Do not keep validateUrl function too loose. This is run when pasting in text, to determine if links are in that text and if it should create AutoLinkNodes.\n// This is why we do not allow stuff like anchors here, as we don't want copied anchors to be turned into AutoLinkNodes.\nexport function validateUrl(url: string): boolean {\n // TODO Fix UI for link insertion; it should never default to an invalid URL such as https://.\n // Maybe show a dialog where they user can type the URL before inserting it.\n\n if (!url) return false\n\n if (url === 'https://') return true\n\n // This makes sure URLs starting with www. instead of https are valid too\n if (absoluteRegExp.test(url)) return true\n\n // Check relative or anchor links\n if (relativeOrAnchorRegExp.test(url)) return true\n\n // While this doesn't allow URLs starting with www (which is why we use the regex above), it does properly handle tel: URLs\n try {\n new URL(url)\n return true\n } catch {\n /* empty */\n }\n\n return false\n}\n"],"mappings":"AAAA,OAAO,SAASA,YAAYC,GAAW;EACrC,yCACA,MAAMC,gBAAA,GAAmB;EAEzB;EACA,MAAMC,gBAAA,GACJ;EAEFF,GAAA,GAAMG,MAAA,CAAOH,GAAA,EAAKI,IAAI;EAEtB,IAAIJ,GAAA,CAAIK,KAAK,CAACJ,gBAAA,KAAqB,QAAQD,GAAA,CAAIK,KAAK,CAACH,gBAAA,KAAqB,MAAM,OAAOF,GAAA;EAEvF,OAAO;AACT;AAEA;AACA,MAAMM,cAAA,GACJ;AAEF;;;;;;AAMA,MAAMC,sBAAA,GAAyB;AAE/B;;;;AAIA,OAAO,SAASC,mBAAmBR,GAAW;EAC5C,IAAI,CAACA,GAAA,EAAK,OAAO;EAEjB,OAAO,CAACA,GAAA,CAAIS,QAAQ,CAAC;AACvB;AAEA;AACA;AACA,OAAO,SAASC,YAAYV,GAAW;EACrC;EACA;EAEA,IAAI,CAACA,GAAA,EAAK,OAAO;EAEjB,IAAIA,GAAA,KAAQ,YAAY,OAAO;EAE/B;EACA,IAAIM,cAAA,CAAeK,IAAI,CAACX,GAAA,GAAM,OAAO;EAErC;EACA,IAAIO,sBAAA,CAAuBI,IAAI,CAACX,GAAA,GAAM,OAAO;EAE7C;EACA,IAAI;IACF,IAAIY,GAAA,CAAIZ,GAAA;IACR,OAAO;EACT,EAAE,MAAM;IACN;EAGF,OAAO;AACT","ignoreList":[]}
1
+ {"version":3,"file":"url.js","names":["sanitizeUrl","url","SAFE_URL_PATTERN","DATA_URL_PATTERN","String","trim","match","absoluteRegExp","relativeOrAnchorRegExp","validateUrlMinimal","includes","validateUrl","test","URL"],"sources":["../../../src/lexical/utils/url.ts"],"sourcesContent":["export function sanitizeUrl(url: string): string {\n /** A pattern that matches safe URLs. */\n const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi\n\n /** A pattern that matches safe data URLs. */\n const DATA_URL_PATTERN =\n /^data:(?:image\\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\\/(?:mpeg|mp4|ogg|webm)|audio\\/(?:mp3|oga|ogg|opus));base64,[a-z\\d+/]+=*$/i\n\n url = String(url).trim()\n\n if (url.match(SAFE_URL_PATTERN) != null || url.match(DATA_URL_PATTERN) != null) {\n return url\n }\n\n return 'https://'\n}\n\n// Source: https://stackoverflow.com/a/8234912/2013580\nconst absoluteRegExp =\n /(?:[A-Za-z]{3,9}:(?:\\/\\/)?(?:[-;:&=+$,\\w]+@)?[A-Za-z\\d.-]+|(?:www.|[-;:&=+$,\\w]+@)[A-Za-z\\d.-]+)(?:\\/[+~%/.\\w-]*)?\\??[-+=&;%@.\\w]*#?\\w*/\n\n/**\n * This regex checks for relative URLs starting with / or anchor links starting with # in a string. Tested for the following use cases:\n * - /privacy-policy\n * - /privacy-policy#primary-terms\n * - #primary-terms\n * */\nconst relativeOrAnchorRegExp = /^[\\w\\-./]*(?:#\\w[\\w-]*)?$/\n\n/**\n * Prevents unreasonable URLs from being inserted into the editor.\n * @param url\n */\nexport function validateUrlMinimal(url: string): boolean {\n if (!url) {\n return false\n }\n\n return !url.includes(' ')\n}\n\n// Do not keep validateUrl function too loose. This is run when pasting in text, to determine if links are in that text and if it should create AutoLinkNodes.\n// This is why we do not allow stuff like anchors here, as we don't want copied anchors to be turned into AutoLinkNodes.\nexport function validateUrl(url: string): boolean {\n // TODO Fix UI for link insertion; it should never default to an invalid URL such as https://.\n // Maybe show a dialog where they user can type the URL before inserting it.\n\n if (!url) {\n return false\n }\n\n if (url === 'https://') {\n return true\n }\n\n // This makes sure URLs starting with www. instead of https are valid too\n if (absoluteRegExp.test(url)) {\n return true\n }\n\n // Check relative or anchor links\n if (relativeOrAnchorRegExp.test(url)) {\n return true\n }\n\n // While this doesn't allow URLs starting with www (which is why we use the regex above), it does properly handle tel: URLs\n try {\n new URL(url)\n return true\n } catch {\n /* empty */\n }\n\n return false\n}\n"],"mappings":"AAAA,OAAO,SAASA,YAAYC,GAAW;EACrC,yCACA,MAAMC,gBAAA,GAAmB;EAEzB;EACA,MAAMC,gBAAA,GACJ;EAEFF,GAAA,GAAMG,MAAA,CAAOH,GAAA,EAAKI,IAAI;EAEtB,IAAIJ,GAAA,CAAIK,KAAK,CAACJ,gBAAA,KAAqB,QAAQD,GAAA,CAAIK,KAAK,CAACH,gBAAA,KAAqB,MAAM;IAC9E,OAAOF,GAAA;EACT;EAEA,OAAO;AACT;AAEA;AACA,MAAMM,cAAA,GACJ;AAEF;;;;;;AAMA,MAAMC,sBAAA,GAAyB;AAE/B;;;;AAIA,OAAO,SAASC,mBAAmBR,GAAW;EAC5C,IAAI,CAACA,GAAA,EAAK;IACR,OAAO;EACT;EAEA,OAAO,CAACA,GAAA,CAAIS,QAAQ,CAAC;AACvB;AAEA;AACA;AACA,OAAO,SAASC,YAAYV,GAAW;EACrC;EACA;EAEA,IAAI,CAACA,GAAA,EAAK;IACR,OAAO;EACT;EAEA,IAAIA,GAAA,KAAQ,YAAY;IACtB,OAAO;EACT;EAEA;EACA,IAAIM,cAAA,CAAeK,IAAI,CAACX,GAAA,GAAM;IAC5B,OAAO;EACT;EAEA;EACA,IAAIO,sBAAA,CAAuBI,IAAI,CAACX,GAAA,GAAM;IACpC,OAAO;EACT;EAEA;EACA,IAAI;IACF,IAAIY,GAAA,CAAIZ,GAAA;IACR,OAAO;EACT,EAAE,MAAM;IACN;EAGF,OAAO;AACT","ignoreList":[]}
package/dist/types.d.ts CHANGED
@@ -48,9 +48,10 @@ export type LexicalRichTextAdapterProvider =
48
48
  /**
49
49
  * This is being called during the payload sanitization process
50
50
  */
51
- ({ config, isRoot, }: {
51
+ ({ config, isRoot, parentIsLocalized, }: {
52
52
  config: SanitizedConfig;
53
53
  isRoot?: boolean;
54
+ parentIsLocalized: boolean;
54
55
  }) => Promise<LexicalRichTextAdapter>;
55
56
  export type LexicalRichTextFieldProps = {
56
57
  admin: LexicalFieldAdminProps;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACzF,OAAO,KAAK,EAGV,eAAe,EACf,kBAAkB,EAClB,eAAe,EAChB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAE5E,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAA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B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;CACjD,GAAG,eAAe,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAA;AAExD,MAAM,MAAM,8BAA8B;AACxC;;GAEG;AACH,CAAC,EACC,MAAM,EACN,MAAM,EACN,iBAAiB,GAClB,EAAE;IACD,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,iBAAiB,EAAE,OAAO,CAAA;CAC3B,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAA;AAEvC,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,sBAAsB,CAAA;IAC7B,mBAAmB,EAAE,mBAAmB,CAAA;CACzC,GAAG,kBAAkB,CAAC,qBAAqB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAA;AAEnE,MAAM,MAAM,YAAY,GAAG;IACzB,YAAY,EAAE,2BAA2B,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,iCAAiC,GAAG;IAC9C,aAAa,EAAE,KAAK,CAAC,SAAS,CAAA;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;CACd,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig, SerializedEditorState } from 'lexical'\nimport type {\n FieldPermissions,\n FieldTypes,\n RichTextAdapter,\n RichTextFieldProps,\n SanitizedConfig,\n} from 'payload'\nimport type React from 'react'\n\nimport type { FeatureProviderServer } from './features/typesServer.js'\nimport type { SanitizedServerEditorConfig } from './lexical/config/types.js'\n\nexport type LexicalFieldAdminProps = {\n /**\n * Controls if the gutter (padding to the left & gray vertical line) should be hidden. @default false\n */\n hideGutter?: boolean\n}\n\nexport type LexicalEditorProps = {\n admin?: LexicalFieldAdminProps\n features?:\n | (({\n defaultFeatures,\n rootFeatures,\n }: {\n /**\n * This opinionated array contains all \"recommended\" default features.\n *\n * @Example\n *\n * ```ts\n * editor: lexicalEditor({\n * features: ({ defaultFeatures }) => [...defaultFeatures, FixedToolbarFeature()],\n * })\n * ```\n */\n defaultFeatures: FeatureProviderServer<any, any, any>[]\n /**\n * This array contains all features that are enabled in the root richText editor (the one defined in the payload.config.ts).\n * If this field is the root richText editor, or if the root richText editor is not a lexical editor, this array will be empty.\n *\n * @Example\n *\n * ```ts\n * editor: lexicalEditor({\n * features: ({ rootFeatures }) => [...rootFeatures, FixedToolbarFeature()],\n * })\n * ```\n */\n rootFeatures: FeatureProviderServer<any, any, any>[]\n }) => FeatureProviderServer<any, any, any>[])\n | FeatureProviderServer<any, any, any>[]\n lexical?: LexicalEditorConfig\n}\n\nexport type LexicalRichTextAdapter = {\n editorConfig: SanitizedServerEditorConfig\n features: FeatureProviderServer<any, any, any>[]\n} & RichTextAdapter<SerializedEditorState, AdapterProps>\n\nexport type LexicalRichTextAdapterProvider =\n /**\n * This is being called during the payload sanitization process\n */\n ({\n config,\n isRoot,\n }: {\n config: SanitizedConfig\n isRoot?: boolean\n }) => Promise<LexicalRichTextAdapter>\n\nexport type LexicalRichTextFieldProps = {\n admin: LexicalFieldAdminProps\n lexicalEditorConfig: LexicalEditorConfig\n} & RichTextFieldProps<SerializedEditorState, AdapterProps, object>\n\nexport type AdapterProps = {\n editorConfig: SanitizedServerEditorConfig\n}\n\nexport type GeneratedFeatureProviderComponent = {\n ClientFeature: React.ReactNode\n key: string\n order: number\n}\n"],"mappings":"AAmFA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig, SerializedEditorState } from 'lexical'\nimport type {\n FieldPermissions,\n FieldTypes,\n RichTextAdapter,\n RichTextFieldProps,\n SanitizedConfig,\n} from 'payload'\nimport type React from 'react'\n\nimport type { FeatureProviderServer } from './features/typesServer.js'\nimport type { SanitizedServerEditorConfig } from './lexical/config/types.js'\n\nexport type LexicalFieldAdminProps = {\n /**\n * Controls if the gutter (padding to the left & gray vertical line) should be hidden. @default false\n */\n hideGutter?: boolean\n}\n\nexport type LexicalEditorProps = {\n admin?: LexicalFieldAdminProps\n features?:\n | (({\n defaultFeatures,\n rootFeatures,\n }: {\n /**\n * This opinionated array contains all \"recommended\" default features.\n *\n * @Example\n *\n * ```ts\n * editor: lexicalEditor({\n * features: ({ defaultFeatures }) => [...defaultFeatures, FixedToolbarFeature()],\n * })\n * ```\n */\n defaultFeatures: FeatureProviderServer<any, any, any>[]\n /**\n * This array contains all features that are enabled in the root richText editor (the one defined in the payload.config.ts).\n * If this field is the root richText editor, or if the root richText editor is not a lexical editor, this array will be empty.\n *\n * @Example\n *\n * ```ts\n * editor: lexicalEditor({\n * features: ({ rootFeatures }) => [...rootFeatures, FixedToolbarFeature()],\n * })\n * ```\n */\n rootFeatures: FeatureProviderServer<any, any, any>[]\n }) => FeatureProviderServer<any, any, any>[])\n | FeatureProviderServer<any, any, any>[]\n lexical?: LexicalEditorConfig\n}\n\nexport type LexicalRichTextAdapter = {\n editorConfig: SanitizedServerEditorConfig\n features: FeatureProviderServer<any, any, any>[]\n} & RichTextAdapter<SerializedEditorState, AdapterProps>\n\nexport type LexicalRichTextAdapterProvider =\n /**\n * This is being called during the payload sanitization process\n */\n ({\n config,\n isRoot,\n parentIsLocalized,\n }: {\n config: SanitizedConfig\n isRoot?: boolean\n parentIsLocalized: boolean\n }) => Promise<LexicalRichTextAdapter>\n\nexport type LexicalRichTextFieldProps = {\n admin: LexicalFieldAdminProps\n lexicalEditorConfig: LexicalEditorConfig\n} & RichTextFieldProps<SerializedEditorState, AdapterProps, object>\n\nexport type AdapterProps = {\n editorConfig: SanitizedServerEditorConfig\n}\n\nexport type GeneratedFeatureProviderComponent = {\n ClientFeature: React.ReactNode\n key: string\n order: number\n}\n"],"mappings":"AAqFA","ignoreList":[]}
@@ -7,6 +7,7 @@ export type CreateServerFeatureArgs<UnSanitizedProps, SanitizedProps, ClientProp
7
7
  /** unSanitizedEditorConfig.features, but mapped */
8
8
  featureProviderMap: ServerFeatureProviderMap;
9
9
  isRoot?: boolean;
10
+ parentIsLocalized: boolean;
10
11
  props: UnSanitizedProps;
11
12
  resolvedFeatures: ResolvedServerFeatureMap;
12
13
  unSanitizedEditorConfig: ServerEditorConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"createServerFeature.d.ts","sourceRoot":"","sources":["../../src/utilities/createServerFeature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EACV,6BAA6B,EAC7B,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,wBAAwB,EACzB,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,MAAM,MAAM,uBAAuB,CAAC,gBAAgB,EAAE,cAAc,EAAE,WAAW,IAAI;IACnF,OAAO,EACH,CAAC,CAAC,KAAK,EAAE;QACP,MAAM,EAAE,eAAe,CAAA;QACvB,mDAAmD;QACnD,kBAAkB,EAAE,wBAAwB,CAAA;QAC5C,MAAM,CAAC,EAAE,OAAO,CAAA;QAChB,KAAK,EAAE,gBAAgB,CAAA;QAEvB,gBAAgB,EAAE,wBAAwB,CAAA;QAE1C,uBAAuB,EAAE,kBAAkB,CAAA;KAC5C,KACG,OAAO,CAAC,aAAa,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,GACnD,aAAa,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,GAC/C,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE,6BAA6B,CAAC,CAAA;CACpF,GAAG,IAAI,CACN,qBAAqB,CAAC,gBAAgB,EAAE,WAAW,CAAC,EACpD,cAAc,GAAG,sBAAsB,GAAG,kBAAkB,GAAG,KAAK,CACrE,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,CAChC,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,mBAAmB,EAAE,CAChC,gBAAgB,GAAG,SAAS,EAC5B,cAAc,GAAG,gBAAgB,EACjC,WAAW,GAAG,SAAS,EAEvB,IAAI,EAAE,uBAAuB,CAAC,gBAAgB,EAAE,cAAc,EAAE,WAAW,CAAC,KACzE,6BAA6B,CAAC,gBAAgB,EAAE,cAAc,EAAE,WAAW,CAmD/E,CAAA"}
@@ -18,6 +18,7 @@ export const createServerFeature = ({
18
18
  config,
19
19
  featureProviderMap,
20
20
  isRoot,
21
+ parentIsLocalized,
21
22
  resolvedFeatures,
22
23
  unSanitizedEditorConfig
23
24
  }) => {
@@ -25,6 +26,7 @@ export const createServerFeature = ({
25
26
  config,
26
27
  featureProviderMap,
27
28
  isRoot,
29
+ parentIsLocalized,
28
30
  props,
29
31
  resolvedFeatures,
30
32
  unSanitizedEditorConfig
@@ -1 +1 @@
1
- {"version":3,"file":"createServerFeature.js","names":["createServerFeature","dependencies","dependenciesPriority","dependenciesSoft","feature","key","featureProviderProviderServer","props","featureProviderServer","serverFeatureProps","config","featureProviderMap","isRoot","resolvedFeatures","unSanitizedEditorConfig","toReturn","sanitizedServerFeatureProps","newFeature"],"sources":["../../src/utilities/createServerFeature.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport type {\n FeatureProviderProviderServer,\n FeatureProviderServer,\n ResolvedServerFeatureMap,\n ServerFeature,\n ServerFeatureProviderMap,\n} from '../features/typesServer.js'\nimport type { ServerEditorConfig } from '../lexical/config/types.js'\n\nexport type CreateServerFeatureArgs<UnSanitizedProps, SanitizedProps, ClientProps> = {\n feature:\n | ((props: {\n config: SanitizedConfig\n /** unSanitizedEditorConfig.features, but mapped */\n featureProviderMap: ServerFeatureProviderMap\n isRoot?: boolean\n props: UnSanitizedProps\n // other resolved features, which have been loaded before this one. All features declared in 'dependencies' should be available here\n resolvedFeatures: ResolvedServerFeatureMap\n // unSanitized EditorConfig,\n unSanitizedEditorConfig: ServerEditorConfig\n }) =>\n | Promise<ServerFeature<SanitizedProps, ClientProps>>\n | ServerFeature<SanitizedProps, ClientProps>)\n | Omit<ServerFeature<SanitizedProps, ClientProps>, 'sanitizedServerFeatureProps'>\n} & Pick<\n FeatureProviderServer<UnSanitizedProps, ClientProps>,\n 'dependencies' | 'dependenciesPriority' | 'dependenciesSoft' | 'key'\n>\n\nexport const createServerFeature: <\n UnSanitizedProps = undefined,\n SanitizedProps = UnSanitizedProps,\n ClientProps = undefined,\n>(\n args: CreateServerFeatureArgs<UnSanitizedProps, SanitizedProps, ClientProps>,\n) => FeatureProviderProviderServer<UnSanitizedProps, SanitizedProps, ClientProps> = ({\n dependencies,\n dependenciesPriority,\n dependenciesSoft,\n feature,\n key,\n}) => {\n const featureProviderProviderServer: FeatureProviderProviderServer<any, any, any> = (props) => {\n const featureProviderServer: Partial<FeatureProviderServer<any, any, any>> = {\n dependencies,\n dependenciesPriority,\n dependenciesSoft,\n key,\n serverFeatureProps: props,\n }\n\n if (typeof feature === 'function') {\n featureProviderServer.feature = async ({\n config,\n featureProviderMap,\n isRoot,\n resolvedFeatures,\n unSanitizedEditorConfig,\n }) => {\n const toReturn = await feature({\n config,\n featureProviderMap,\n isRoot,\n props,\n resolvedFeatures,\n unSanitizedEditorConfig,\n })\n\n if (toReturn.sanitizedServerFeatureProps === null) {\n toReturn.sanitizedServerFeatureProps = props\n }\n return toReturn\n }\n } else {\n // For explanation why we have to spread feature, see createClientFeature.ts\n const newFeature: ServerFeature<any, any> = { ...feature }\n\n newFeature.sanitizedServerFeatureProps = props\n featureProviderServer.feature = newFeature\n }\n return featureProviderServer as FeatureProviderServer<any, any, any>\n }\n\n return featureProviderProviderServer\n}\n"],"mappings":"AAgCA,OAAO,MAAMA,mBAAA,GAMuEA,CAAC;EACnFC,YAAY;EACZC,oBAAoB;EACpBC,gBAAgB;EAChBC,OAAO;EACPC;AAAG,CACJ;EACC,MAAMC,6BAAA,GAA+EC,KAAA;IACnF,MAAMC,qBAAA,GAAuE;MAC3EP,YAAA;MACAC,oBAAA;MACAC,gBAAA;MACAE,GAAA;MACAI,kBAAA,EAAoBF;IACtB;IAEA,IAAI,OAAOH,OAAA,KAAY,YAAY;MACjCI,qBAAA,CAAsBJ,OAAO,GAAG,OAAO;QACrCM,MAAM;QACNC,kBAAkB;QAClBC,MAAM;QACNC,gBAAgB;QAChBC;MAAuB,CACxB;QACC,MAAMC,QAAA,GAAW,MAAMX,OAAA,CAAQ;UAC7BM,MAAA;UACAC,kBAAA;UACAC,MAAA;UACAL,KAAA;UACAM,gBAAA;UACAC;QACF;QAEA,IAAIC,QAAA,CAASC,2BAA2B,KAAK,MAAM;UACjDD,QAAA,CAASC,2BAA2B,GAAGT,KAAA;QACzC;QACA,OAAOQ,QAAA;MACT;IACF,OAAO;MACL;MACA,MAAME,UAAA,GAAsC;QAAE,GAAGb;MAAQ;MAEzDa,UAAA,CAAWD,2BAA2B,GAAGT,KAAA;MACzCC,qBAAA,CAAsBJ,OAAO,GAAGa,UAAA;IAClC;IACA,OAAOT,qBAAA;EACT;EAEA,OAAOF,6BAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"createServerFeature.js","names":["createServerFeature","dependencies","dependenciesPriority","dependenciesSoft","feature","key","featureProviderProviderServer","props","featureProviderServer","serverFeatureProps","config","featureProviderMap","isRoot","parentIsLocalized","resolvedFeatures","unSanitizedEditorConfig","toReturn","sanitizedServerFeatureProps","newFeature"],"sources":["../../src/utilities/createServerFeature.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport type {\n FeatureProviderProviderServer,\n FeatureProviderServer,\n ResolvedServerFeatureMap,\n ServerFeature,\n ServerFeatureProviderMap,\n} from '../features/typesServer.js'\nimport type { ServerEditorConfig } from '../lexical/config/types.js'\n\nexport type CreateServerFeatureArgs<UnSanitizedProps, SanitizedProps, ClientProps> = {\n feature:\n | ((props: {\n config: SanitizedConfig\n /** unSanitizedEditorConfig.features, but mapped */\n featureProviderMap: ServerFeatureProviderMap\n isRoot?: boolean\n parentIsLocalized: boolean\n props: UnSanitizedProps\n // other resolved features, which have been loaded before this one. All features declared in 'dependencies' should be available here\n resolvedFeatures: ResolvedServerFeatureMap\n // unSanitized EditorConfig,\n unSanitizedEditorConfig: ServerEditorConfig\n }) =>\n | Promise<ServerFeature<SanitizedProps, ClientProps>>\n | ServerFeature<SanitizedProps, ClientProps>)\n | Omit<ServerFeature<SanitizedProps, ClientProps>, 'sanitizedServerFeatureProps'>\n} & Pick<\n FeatureProviderServer<UnSanitizedProps, ClientProps>,\n 'dependencies' | 'dependenciesPriority' | 'dependenciesSoft' | 'key'\n>\n\nexport const createServerFeature: <\n UnSanitizedProps = undefined,\n SanitizedProps = UnSanitizedProps,\n ClientProps = undefined,\n>(\n args: CreateServerFeatureArgs<UnSanitizedProps, SanitizedProps, ClientProps>,\n) => FeatureProviderProviderServer<UnSanitizedProps, SanitizedProps, ClientProps> = ({\n dependencies,\n dependenciesPriority,\n dependenciesSoft,\n feature,\n key,\n}) => {\n const featureProviderProviderServer: FeatureProviderProviderServer<any, any, any> = (props) => {\n const featureProviderServer: Partial<FeatureProviderServer<any, any, any>> = {\n dependencies,\n dependenciesPriority,\n dependenciesSoft,\n key,\n serverFeatureProps: props,\n }\n\n if (typeof feature === 'function') {\n featureProviderServer.feature = async ({\n config,\n featureProviderMap,\n isRoot,\n parentIsLocalized,\n resolvedFeatures,\n unSanitizedEditorConfig,\n }) => {\n const toReturn = await feature({\n config,\n featureProviderMap,\n isRoot,\n parentIsLocalized,\n props,\n resolvedFeatures,\n unSanitizedEditorConfig,\n })\n\n if (toReturn.sanitizedServerFeatureProps === null) {\n toReturn.sanitizedServerFeatureProps = props\n }\n return toReturn\n }\n } else {\n // For explanation why we have to spread feature, see createClientFeature.ts\n const newFeature: ServerFeature<any, any> = { ...feature }\n\n newFeature.sanitizedServerFeatureProps = props\n featureProviderServer.feature = newFeature\n }\n return featureProviderServer as FeatureProviderServer<any, any, any>\n }\n\n return featureProviderProviderServer\n}\n"],"mappings":"AAiCA,OAAO,MAAMA,mBAAA,GAMuEA,CAAC;EACnFC,YAAY;EACZC,oBAAoB;EACpBC,gBAAgB;EAChBC,OAAO;EACPC;AAAG,CACJ;EACC,MAAMC,6BAAA,GAA+EC,KAAA;IACnF,MAAMC,qBAAA,GAAuE;MAC3EP,YAAA;MACAC,oBAAA;MACAC,gBAAA;MACAE,GAAA;MACAI,kBAAA,EAAoBF;IACtB;IAEA,IAAI,OAAOH,OAAA,KAAY,YAAY;MACjCI,qBAAA,CAAsBJ,OAAO,GAAG,OAAO;QACrCM,MAAM;QACNC,kBAAkB;QAClBC,MAAM;QACNC,iBAAiB;QACjBC,gBAAgB;QAChBC;MAAuB,CACxB;QACC,MAAMC,QAAA,GAAW,MAAMZ,OAAA,CAAQ;UAC7BM,MAAA;UACAC,kBAAA;UACAC,MAAA;UACAC,iBAAA;UACAN,KAAA;UACAO,gBAAA;UACAC;QACF;QAEA,IAAIC,QAAA,CAASC,2BAA2B,KAAK,MAAM;UACjDD,QAAA,CAASC,2BAA2B,GAAGV,KAAA;QACzC;QACA,OAAOS,QAAA;MACT;IACF,OAAO;MACL;MACA,MAAME,UAAA,GAAsC;QAAE,GAAGd;MAAQ;MAEzDc,UAAA,CAAWD,2BAA2B,GAAGV,KAAA;MACzCC,qBAAA,CAAsBJ,OAAO,GAAGc,UAAA;IAClC;IACA,OAAOV,qBAAA;EACT;EAEA,OAAOF,6BAAA;AACT","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-lexical",
3
- "version": "3.0.0-beta.95",
3
+ "version": "3.0.0-beta.96",
4
4
  "description": "The officially supported Lexical richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -56,8 +56,8 @@
56
56
  "lexical": "0.17.0",
57
57
  "react-error-boundary": "4.0.13",
58
58
  "uuid": "10.0.0",
59
- "@payloadcms/translations": "3.0.0-beta.95",
60
- "@payloadcms/ui": "3.0.0-beta.95"
59
+ "@payloadcms/translations": "3.0.0-beta.96",
60
+ "@payloadcms/ui": "3.0.0-beta.96"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@babel/cli": "^7.24.5",
@@ -77,8 +77,8 @@
77
77
  "esbuild-sass-plugin": "3.3.1",
78
78
  "eslint-plugin-react-compiler": "0.0.0-experimental-72f06b2-20240822",
79
79
  "swc-plugin-transform-remove-imports": "1.15.0",
80
- "payload": "3.0.0-beta.95",
81
- "@payloadcms/eslint-config": "3.0.0-beta.59"
80
+ "@payloadcms/eslint-config": "3.0.0-beta.59",
81
+ "payload": "3.0.0-beta.96"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "@faceless-ui/modal": "3.0.0-beta.2",
@@ -96,8 +96,8 @@
96
96
  "lexical": "0.17.0",
97
97
  "react": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
98
98
  "react-dom": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
99
- "@payloadcms/next": "3.0.0-beta.95",
100
- "payload": "3.0.0-beta.95"
99
+ "@payloadcms/next": "3.0.0-beta.96",
100
+ "payload": "3.0.0-beta.96"
101
101
  },
102
102
  "engines": {
103
103
  "node": "^18.20.2 || >=20.9.0"
@@ -120,6 +120,8 @@
120
120
  "build:without_reactcompiler": "rm -rf dist && rm -rf tsconfig.tsbuildinfo && pnpm copyfiles && pnpm build:types && pnpm build:swc && pnpm build:esbuild && rm -rf dist/exports/client && mv dist/exports/client_unoptimized dist/exports/client",
121
121
  "clean": "rimraf {dist,*.tsbuildinfo}",
122
122
  "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
123
+ "lint": "eslint .",
124
+ "lint:fix": "eslint . --fix",
123
125
  "translateNewKeys": "node --no-deprecation --import @swc-node/register/esm-register scripts/translateNewKeys.ts"
124
126
  }
125
127
  }