@payloadcms/richtext-lexical 3.21.0 → 3.23.0-canary.597254e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/Field-ZQTPXWY3.js +2 -0
- package/dist/exports/client/Field-ZQTPXWY3.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/{chunk-JKFXKPNG.js → chunk-CIY6PKN6.js} +2 -2
- package/dist/exports/client/chunk-CIY6PKN6.js.map +7 -0
- package/dist/exports/client/chunk-KEEUF5NK.js +2 -0
- package/dist/exports/client/chunk-KEEUF5NK.js.map +7 -0
- package/dist/exports/client/chunk-PUXDVIHC.js +2 -0
- package/dist/exports/client/chunk-PUXDVIHC.js.map +7 -0
- package/dist/exports/client/{component-VJVZFYZJ.js → component-P5K7Z5NW.js} +2 -2
- package/dist/exports/client/componentInline-UG3ZWWJY.js +2 -0
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +61 -30
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/component/removeEmptyArrayValues.js +1 -1
- package/dist/features/blocks/client/component/removeEmptyArrayValues.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +42 -13
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/index.d.ts.map +1 -1
- package/dist/features/blocks/client/index.js +7 -4
- package/dist/features/blocks/client/index.js.map +1 -1
- package/dist/features/blocks/client/markdownTransformer.js +1 -1
- package/dist/features/blocks/client/markdownTransformer.js.map +1 -1
- package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.js +4 -4
- package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.js.map +1 -1
- package/dist/features/blocks/server/markdownTransformer.d.ts.map +1 -1
- package/dist/features/blocks/server/markdownTransformer.js +5 -4
- package/dist/features/blocks/server/markdownTransformer.js.map +1 -1
- package/dist/features/blocks/server/validate.d.ts.map +1 -1
- package/dist/features/blocks/server/validate.js +9 -3
- package/dist/features/blocks/server/validate.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +12 -10
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +39 -31
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/markdownTransformer.d.ts.map +1 -1
- package/dist/features/experimental_table/markdownTransformer.js +6 -2
- package/dist/features/experimental_table/markdownTransformer.js.map +1 -1
- package/dist/features/heading/markdownTransformer.js +1 -1
- package/dist/features/heading/markdownTransformer.js.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.js +35 -35
- package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/nodes/LinkNode.d.ts.map +1 -1
- package/dist/features/link/nodes/LinkNode.js +4 -6
- package/dist/features/link/nodes/LinkNode.js.map +1 -1
- package/dist/features/link/server/baseFields.d.ts.map +1 -1
- package/dist/features/link/server/baseFields.js +5 -8
- package/dist/features/link/server/baseFields.js.map +1 -1
- package/dist/features/link/server/validate.d.ts.map +1 -1
- package/dist/features/link/server/validate.js +9 -3
- package/dist/features/link/server/validate.js.map +1 -1
- package/dist/features/lists/shared/markdown.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/typesClient.d.ts +2 -1
- package/dist/features/typesClient.d.ts.map +1 -1
- package/dist/features/typesClient.js.map +1 -1
- package/dist/features/upload/server/feature.server.d.ts.map +1 -1
- package/dist/features/upload/server/feature.server.js +10 -8
- package/dist/features/upload/server/feature.server.js.map +1 -1
- package/dist/features/upload/server/validate.d.ts.map +1 -1
- package/dist/features/upload/server/validate.js +9 -3
- package/dist/features/upload/server/validate.js.map +1 -1
- package/dist/field/Field.d.ts +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +17 -7
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +23 -18
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +1 -0
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/lexical/config/client/loader.d.ts +3 -2
- package/dist/lexical/config/client/loader.d.ts.map +1 -1
- package/dist/lexical/config/client/loader.js +2 -0
- package/dist/lexical/config/client/loader.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.d.ts +12 -0
- package/dist/lexical/plugins/DecoratorPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js +198 -19
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +10 -4
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/useMenuTriggerMatch.js.map +1 -1
- package/dist/lexical/plugins/handles/utils/getNodeCloseToPoint.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/utils/getNodeCloseToPoint.js +2 -1
- package/dist/lexical/plugins/handles/utils/getNodeCloseToPoint.js.map +1 -1
- package/dist/utilities/buildInitialState.d.ts +1 -0
- package/dist/utilities/buildInitialState.d.ts.map +1 -1
- package/dist/utilities/buildInitialState.js +2 -0
- package/dist/utilities/buildInitialState.js.map +1 -1
- package/dist/utilities/createClientFeature.d.ts +2 -1
- package/dist/utilities/createClientFeature.d.ts.map +1 -1
- package/dist/utilities/createClientFeature.js +2 -0
- package/dist/utilities/createClientFeature.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +11 -3
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/package.json +6 -6
- package/dist/exports/client/Field-LOLYH42M.js +0 -2
- package/dist/exports/client/Field-LOLYH42M.js.map +0 -7
- package/dist/exports/client/chunk-JKFXKPNG.js.map +0 -7
- package/dist/exports/client/chunk-KDV47ZNZ.js +0 -2
- package/dist/exports/client/chunk-KDV47ZNZ.js.map +0 -7
- package/dist/exports/client/chunk-QP2NYEWJ.js +0 -2
- package/dist/exports/client/chunk-QP2NYEWJ.js.map +0 -7
- package/dist/exports/client/componentInline-DTNGYZCL.js +0 -2
- /package/dist/exports/client/{component-VJVZFYZJ.js.map → component-P5K7Z5NW.js.map} +0 -0
- /package/dist/exports/client/{componentInline-DTNGYZCL.js.map → componentInline-UG3ZWWJY.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMenuTriggerMatch.js","names":["c","_c","useCallback","PUNCTUATION","useMenuTriggerMatch","trigger","t0","$","maxLength","t1","minLength","t2","undefined","t3","t4","query","validChars","TypeaheadTriggerRegex","RegExp","match","exec","maybeLeadingWhitespace","matchingString","length","leadOffset","index","replaceableString"],"sources":["../../../../src/lexical/plugins/SlashMenu/useMenuTriggerMatch.ts"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useCallback } from 'react'\n\nimport { PUNCTUATION } from './LexicalTypeaheadMenuPlugin/index.js'\n\nexport type TriggerFn = ({\n editor,\n query,\n}: {\n editor: LexicalEditor\n /** The query string is the POTENTIAL trigger AND the text after the trigger text. */\n query: string\n}) => MenuTextMatch | null\n\nexport type MenuTextMatch = {\n leadOffset: number\n matchingString: string\n replaceableString: string\n}\n\n/**\n * Returns a function which checks if the trigger (e.g. '/') is present in the query and, if so, returns the matching string (text after the trigger)\n */\nexport function useMenuTriggerMatch(\n /**\n * Text which triggers the menu. Everything after this text will be used as the query.\n */\n trigger: string,\n { maxLength = 75, minLength = 1 }: { maxLength?: number; minLength?: number },\n): TriggerFn {\n return useCallback(\n ({ query }) => {\n const validChars = '[^' + trigger + PUNCTUATION + '\\\\s]'\n const TypeaheadTriggerRegex = new RegExp(\n '(^|\\\\s|\\\\()(' +\n '[' +\n trigger +\n ']' +\n '((?:' +\n validChars +\n '){0,' +\n maxLength +\n '})' +\n ')$',\n )\n const match = TypeaheadTriggerRegex.exec(query)\n if (match !== null) {\n const maybeLeadingWhitespace = match[1]
|
|
1
|
+
{"version":3,"file":"useMenuTriggerMatch.js","names":["c","_c","useCallback","PUNCTUATION","useMenuTriggerMatch","trigger","t0","$","maxLength","t1","minLength","t2","undefined","t3","t4","query","validChars","TypeaheadTriggerRegex","RegExp","match","exec","maybeLeadingWhitespace","matchingString","length","leadOffset","index","replaceableString"],"sources":["../../../../src/lexical/plugins/SlashMenu/useMenuTriggerMatch.ts"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useCallback } from 'react'\n\nimport { PUNCTUATION } from './LexicalTypeaheadMenuPlugin/index.js'\n\nexport type TriggerFn = ({\n editor,\n query,\n}: {\n editor: LexicalEditor\n /** The query string is the POTENTIAL trigger AND the text after the trigger text. */\n query: string\n}) => MenuTextMatch | null\n\nexport type MenuTextMatch = {\n leadOffset: number\n matchingString: string\n replaceableString: string\n}\n\n/**\n * Returns a function which checks if the trigger (e.g. '/') is present in the query and, if so, returns the matching string (text after the trigger)\n */\nexport function useMenuTriggerMatch(\n /**\n * Text which triggers the menu. Everything after this text will be used as the query.\n */\n trigger: string,\n { maxLength = 75, minLength = 1 }: { maxLength?: number; minLength?: number },\n): TriggerFn {\n return useCallback(\n ({ query }) => {\n const validChars = '[^' + trigger + PUNCTUATION + '\\\\s]'\n const TypeaheadTriggerRegex = new RegExp(\n '(^|\\\\s|\\\\()(' +\n '[' +\n trigger +\n ']' +\n '((?:' +\n validChars +\n '){0,' +\n maxLength +\n '})' +\n ')$',\n )\n const match = TypeaheadTriggerRegex.exec(query)\n if (match !== null) {\n const maybeLeadingWhitespace = match[1]!\n\n /**\n * matchingString is only the text AFTER the trigger text. (So everything after the /)\n */\n const matchingString = match[3]!\n\n if (matchingString.length >= minLength) {\n return {\n leadOffset: match.index + maybeLeadingWhitespace.length,\n matchingString,\n replaceableString: match[2]!, // replaceableString is the trigger text + the matching string\n }\n }\n }\n return null\n },\n [maxLength, minLength, trigger],\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,SAASC,WAAW,QAAQ;AAE5B,SAASC,WAAW,QAAQ;AAiB5B;;;AAGA,OAAO,SAAAC,oBAAAC,OAAA,EAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAN,EAAA;EAKL;IAAAO,SAAA,EAAAC,EAAA;IAAAC,SAAA,EAAAC;EAAA,IAAAL,EAA6E;EAA3E,MAAAE,SAAA,GAAAC,EAAc,KAAAG,SAAA,QAAdH,EAAc;EAAE,MAAAC,SAAA,GAAAC,EAAa,KAAAC,SAAA,OAAbD,EAAa;EAAA,IAAAE,EAAA;EAAA,IAAAN,CAAA,QAAAC,SAAA,IAAAD,CAAA,QAAAG,SAAA,IAAAH,CAAA,QAAAF,OAAA;IAG7BQ,EAAA,GAAAC,EAAA;MAAC;QAAAC;MAAA,IAAAD,EAAS;MACR,MAAAE,UAAA,GAAmB,OAAOX,OAAA,GAAAF,WAAU,GAAc;MAClD,MAAAc,qBAAA,OAAAC,MAAA,CACE,eACE,GACAb,OAAA,GACA,MACA,SACAW,UAAA,GACA,SACAR,SAAA,GACA,OACA;MAEJ,MAAAW,KAAA,GAAcF,qBAAA,CAAAG,IAAA,CAA2BL,KAAA;MAAA,IACrCI,KAAA,SAAU;QACZ,MAAAE,sBAAA,GAA+BF,KAAK;QAKpC,MAAAG,cAAA,GAAuBH,KAAK;QAAG,IAE3BG,cAAA,CAAAC,MAAA,IAAyBb,SAAA;UAAA;YAAAc,UAAA,EAEbL,KAAA,CAAAM,KAAA,GAAcJ,sBAAA,CAAAE,MAA6B;YAAAD,cAAA;YAAAI,iBAAA,EAEpCP,KAAK;UAAA;QAAA;MAAA;MAAA;IAAA;IAKhCZ,CAAA,MAAAC,SAAA;IAAAD,CAAA,MAAAG,SAAA;IAAAH,CAAA,MAAAF,OAAA;IAAAE,CAAA,MAAAM,EAAA;EAAA;IAAAA,EAAA,GAAAN,CAAA;EAAA;EAAA,OAjCKM,EAkC0B;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeCloseToPoint.d.ts","sourceRoot":"","sources":["../../../../../src/lexical/plugins/handles/utils/getNodeCloseToPoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAIzD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAW/C,KAAK,KAAK,GAAG;IACX,UAAU,EAAE,WAAW,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,aAAa,CAAA;IACrB,gHAAgH;IAChH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,SAAS,EAAE,WAAW,GAAG,IAAI,CAAA;IAC7B,SAAS,EAAE,WAAW,GAAG,IAAI,CAAA;IAC7B,YAAY,EAAE,MAAM,CAAA;IACpB,yBAAyB,EAAE,OAAO,CAAA;CACnC,CAAA;AAaD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"getNodeCloseToPoint.d.ts","sourceRoot":"","sources":["../../../../../src/lexical/plugins/handles/utils/getNodeCloseToPoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAIzD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAW/C,KAAK,KAAK,GAAG;IACX,UAAU,EAAE,WAAW,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,aAAa,CAAA;IACrB,gHAAgH;IAChH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,SAAS,EAAE,WAAW,GAAG,IAAI,CAAA;IAC7B,SAAS,EAAE,WAAW,GAAG,IAAI,CAAA;IAC7B,YAAY,EAAE,MAAM,CAAA;IACpB,yBAAyB,EAAE,OAAO,CAAA;CACnC,CAAA;AAaD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAgKxD"}
|
|
@@ -49,7 +49,8 @@ export function getNodeCloseToPoint(props) {
|
|
|
49
49
|
// Return null if matching block element is the first or last node
|
|
50
50
|
editor.getEditorState().read(() => {
|
|
51
51
|
if (useEdgeAsDefault) {
|
|
52
|
-
const
|
|
52
|
+
const firstNode = editor.getElementByKey(topLevelNodeKeys[0]);
|
|
53
|
+
const lastNode = editor.getElementByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]);
|
|
53
54
|
if (firstNode && lastNode) {
|
|
54
55
|
const [firstNodeRect, lastNodeRect] = [getBoundingClientRectWithoutTransform(firstNode), getBoundingClientRectWithoutTransform(lastNode)];
|
|
55
56
|
if (y < firstNodeRect.top) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeCloseToPoint.js","names":["$getNodeByKey","Point","Rect","getBoundingClientRectWithoutTransform","getCollapsedMargins","getTopLevelNodeKeys","Downward","Upward","Indeterminate","cache","props","result","isPointClose","previous","current","threshold","dx","x","dy","y","getNodeCloseToPoint","anchorElem","cache_threshold","editor","fuzzy","horizontalOffset","point","startIndex","useEdgeAsDefault","anchorElementRect","getBoundingClientRect","topLevelNodeKeys","closestBlockElem","blockElem","blockNode","distance","Infinity","foundAtIndex","isFoundNodeEmptyParagraph","getEditorState","read","firstNode","lastNode","getElementByKey","length","firstNodeRect","lastNodeRect","top","bottom","index","direction","key","elem","domRect","fromDOMRect","marginBottom","marginTop","rect","generateNewRect","left","right","isOnBottomSide","isOnTopSide","distanceFromPoint","getType","getTextContent","returnEmptyParagraphs"],"sources":["../../../../../src/lexical/plugins/handles/utils/getNodeCloseToPoint.ts"],"sourcesContent":["'use client'\nimport type { LexicalEditor, LexicalNode } from 'lexical'\n\nimport { $getNodeByKey } from 'lexical'\n\nimport { Point } from '../../../utils/point.js'\nimport { Rect } from '../../../utils/rect.js'\nimport { getBoundingClientRectWithoutTransform } from '../DraggableBlockPlugin/getBoundingRectWithoutTransform.js'\nimport { getCollapsedMargins } from '../utils/getCollapsedMargins.js'\nimport { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js'\n\n// Directions\nconst Downward = 1\nconst Upward = -1\nconst Indeterminate = 0\n\ntype Props = {\n anchorElem: HTMLElement\n cache_threshold?: number\n editor: LexicalEditor\n /** fuzzy makes the search not exact. If no exact match found, find the closes node instead of returning null */\n fuzzy?: boolean\n horizontalOffset?: number\n point: Point\n /**\n * By default, empty paragraphs are not returned. Set this to true to return empty paragraphs. @default false\n */\n returnEmptyParagraphs?: boolean\n /**\n * The index to start searching from. It can be a considerable performance optimization to start searching from the index of the\n * previously found node, as the node is likely to be close to the next node.\n */\n startIndex?: number\n useEdgeAsDefault?: boolean\n verbose?: boolean\n}\n\ntype Output = {\n blockElem: HTMLElement | null\n blockNode: LexicalNode | null\n foundAtIndex: number\n isFoundNodeEmptyParagraph: boolean\n}\n\nconst cache = {\n props: null as null | Props,\n result: null as null | Output,\n}\n\nfunction isPointClose(previous: Point, current: Point, threshold: number = 20): boolean {\n const dx = previous.x - current.x\n const dy = previous.y - current.y\n return dx * dx + dy * dy <= threshold * threshold\n}\n\nexport function getNodeCloseToPoint(props: Props): Output {\n const {\n anchorElem,\n cache_threshold = 20,\n editor,\n fuzzy = false,\n horizontalOffset = 0,\n point: { x, y },\n startIndex = 0,\n useEdgeAsDefault = false,\n } = props\n\n // Use cache\n if (\n cache_threshold > 0 &&\n cache.props &&\n cache.result &&\n cache.props.fuzzy === props.fuzzy &&\n cache.props.horizontalOffset === props.horizontalOffset &&\n cache.props.useEdgeAsDefault === props.useEdgeAsDefault &&\n isPointClose(cache.props.point, props.point, cache_threshold)\n ) {\n return cache.result\n }\n\n const anchorElementRect = anchorElem.getBoundingClientRect()\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n const closestBlockElem: {\n blockElem: HTMLElement | null\n blockNode: LexicalNode | null\n distance: number\n foundAtIndex: number\n isFoundNodeEmptyParagraph: boolean\n } = {\n blockElem: null,\n blockNode: null,\n distance: Infinity,\n foundAtIndex: -1,\n isFoundNodeEmptyParagraph: false,\n }\n\n // Return null if matching block element is the first or last node\n editor.getEditorState().read(() => {\n if (useEdgeAsDefault) {\n const [firstNode, lastNode] = [\n editor.getElementByKey(topLevelNodeKeys[0]),\n editor.getElementByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]),\n ]\n\n if (firstNode && lastNode) {\n const [firstNodeRect, lastNodeRect] = [\n getBoundingClientRectWithoutTransform(firstNode),\n getBoundingClientRectWithoutTransform(lastNode),\n ]\n\n if (y < firstNodeRect.top) {\n closestBlockElem.blockElem = firstNode\n closestBlockElem.distance = firstNodeRect.top - y\n closestBlockElem.blockNode = $getNodeByKey(topLevelNodeKeys[0])\n closestBlockElem.foundAtIndex = 0\n } else if (y > lastNodeRect.bottom) {\n closestBlockElem.distance = y - lastNodeRect.bottom\n closestBlockElem.blockNode = $getNodeByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1])\n closestBlockElem.blockElem = lastNode\n closestBlockElem.foundAtIndex = topLevelNodeKeys.length - 1\n }\n\n if (closestBlockElem?.blockElem) {\n return {\n blockElem: null,\n isFoundNodeEmptyParagraph: false,\n } as Output\n }\n }\n }\n\n // Find matching block element\n let index = startIndex\n let direction = Indeterminate\n\n while (index >= 0 && index < topLevelNodeKeys.length) {\n const key = topLevelNodeKeys[index]\n const elem = editor.getElementByKey(key)\n if (elem === null) {\n break\n }\n const point = new Point(x + horizontalOffset, y)\n //const domRect = Rect.fromDOM(elem)\n // Do not consider transform of blocks when calculating distance\n const domRect = Rect.fromDOMRect(getBoundingClientRectWithoutTransform(elem))\n\n const { marginBottom, marginTop } = getCollapsedMargins(elem)\n\n const rect = domRect.generateNewRect({\n bottom: domRect.bottom + marginBottom,\n left: anchorElementRect.left,\n right: anchorElementRect.right,\n top: domRect.top - marginTop,\n })\n\n const { distance, isOnBottomSide, isOnTopSide } = rect.distanceFromPoint(point)\n\n if (distance === 0) {\n closestBlockElem.blockElem = elem\n closestBlockElem.blockNode = $getNodeByKey(key)\n closestBlockElem.foundAtIndex = index\n closestBlockElem.distance = distance\n\n // Check if blockNode is an empty text node\n if (\n closestBlockElem.blockNode &&\n closestBlockElem.blockNode.getType() === 'paragraph' &&\n closestBlockElem.blockNode.getTextContent() === ''\n ) {\n if (!fuzzy && !props.returnEmptyParagraphs) {\n closestBlockElem.blockElem = null\n closestBlockElem.blockNode = null\n }\n\n closestBlockElem.isFoundNodeEmptyParagraph = true\n }\n break\n } else if (fuzzy) {\n if (distance < closestBlockElem.distance) {\n closestBlockElem.blockElem = elem\n closestBlockElem.blockNode = $getNodeByKey(key)\n closestBlockElem.distance = distance\n closestBlockElem.foundAtIndex = index\n }\n }\n\n if (direction === Indeterminate) {\n if (isOnTopSide) {\n direction = Upward\n } else if (isOnBottomSide) {\n direction = Downward\n } else {\n // stop search block element\n direction = Infinity\n }\n }\n\n index += direction\n }\n })\n\n // Store in cache before returning\n cache.props = props\n cache.result = {\n blockElem: closestBlockElem.blockElem,\n blockNode: closestBlockElem.blockNode,\n foundAtIndex: closestBlockElem.foundAtIndex,\n isFoundNodeEmptyParagraph: closestBlockElem.isFoundNodeEmptyParagraph,\n }\n\n return {\n blockElem: closestBlockElem.blockElem,\n blockNode: closestBlockElem.blockNode,\n foundAtIndex: closestBlockElem.foundAtIndex,\n isFoundNodeEmptyParagraph: closestBlockElem.isFoundNodeEmptyParagraph,\n }\n}\n"],"mappings":"AAAA;;AAGA,SAASA,aAAa,QAAQ;AAE9B,SAASC,KAAK,QAAQ;AACtB,SAASC,IAAI,QAAQ;AACrB,SAASC,qCAAqC,QAAQ;AACtD,SAASC,mBAAmB,QAAQ;AACpC,SAASC,mBAAmB,QAAQ;AAEpC;AACA,MAAMC,QAAA,GAAW;AACjB,MAAMC,MAAA,GAAS,CAAC;AAChB,MAAMC,aAAA,G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A,CAAiBM;EAC9C;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"getNodeCloseToPoint.js","names":["$getNodeByKey","Point","Rect","getBoundingClientRectWithoutTransform","getCollapsedMargins","getTopLevelNodeKeys","Downward","Upward","Indeterminate","cache","props","result","isPointClose","previous","current","threshold","dx","x","dy","y","getNodeCloseToPoint","anchorElem","cache_threshold","editor","fuzzy","horizontalOffset","point","startIndex","useEdgeAsDefault","anchorElementRect","getBoundingClientRect","topLevelNodeKeys","closestBlockElem","blockElem","blockNode","distance","Infinity","foundAtIndex","isFoundNodeEmptyParagraph","getEditorState","read","firstNode","getElementByKey","lastNode","length","firstNodeRect","lastNodeRect","top","bottom","index","direction","key","elem","domRect","fromDOMRect","marginBottom","marginTop","rect","generateNewRect","left","right","isOnBottomSide","isOnTopSide","distanceFromPoint","getType","getTextContent","returnEmptyParagraphs"],"sources":["../../../../../src/lexical/plugins/handles/utils/getNodeCloseToPoint.ts"],"sourcesContent":["'use client'\nimport type { LexicalEditor, LexicalNode } from 'lexical'\n\nimport { $getNodeByKey } from 'lexical'\n\nimport { Point } from '../../../utils/point.js'\nimport { Rect } from '../../../utils/rect.js'\nimport { getBoundingClientRectWithoutTransform } from '../DraggableBlockPlugin/getBoundingRectWithoutTransform.js'\nimport { getCollapsedMargins } from '../utils/getCollapsedMargins.js'\nimport { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js'\n\n// Directions\nconst Downward = 1\nconst Upward = -1\nconst Indeterminate = 0\n\ntype Props = {\n anchorElem: HTMLElement\n cache_threshold?: number\n editor: LexicalEditor\n /** fuzzy makes the search not exact. If no exact match found, find the closes node instead of returning null */\n fuzzy?: boolean\n horizontalOffset?: number\n point: Point\n /**\n * By default, empty paragraphs are not returned. Set this to true to return empty paragraphs. @default false\n */\n returnEmptyParagraphs?: boolean\n /**\n * The index to start searching from. It can be a considerable performance optimization to start searching from the index of the\n * previously found node, as the node is likely to be close to the next node.\n */\n startIndex?: number\n useEdgeAsDefault?: boolean\n verbose?: boolean\n}\n\ntype Output = {\n blockElem: HTMLElement | null\n blockNode: LexicalNode | null\n foundAtIndex: number\n isFoundNodeEmptyParagraph: boolean\n}\n\nconst cache = {\n props: null as null | Props,\n result: null as null | Output,\n}\n\nfunction isPointClose(previous: Point, current: Point, threshold: number = 20): boolean {\n const dx = previous.x - current.x\n const dy = previous.y - current.y\n return dx * dx + dy * dy <= threshold * threshold\n}\n\nexport function getNodeCloseToPoint(props: Props): Output {\n const {\n anchorElem,\n cache_threshold = 20,\n editor,\n fuzzy = false,\n horizontalOffset = 0,\n point: { x, y },\n startIndex = 0,\n useEdgeAsDefault = false,\n } = props\n\n // Use cache\n if (\n cache_threshold > 0 &&\n cache.props &&\n cache.result &&\n cache.props.fuzzy === props.fuzzy &&\n cache.props.horizontalOffset === props.horizontalOffset &&\n cache.props.useEdgeAsDefault === props.useEdgeAsDefault &&\n isPointClose(cache.props.point, props.point, cache_threshold)\n ) {\n return cache.result\n }\n\n const anchorElementRect = anchorElem.getBoundingClientRect()\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n const closestBlockElem: {\n blockElem: HTMLElement | null\n blockNode: LexicalNode | null\n distance: number\n foundAtIndex: number\n isFoundNodeEmptyParagraph: boolean\n } = {\n blockElem: null,\n blockNode: null,\n distance: Infinity,\n foundAtIndex: -1,\n isFoundNodeEmptyParagraph: false,\n }\n\n // Return null if matching block element is the first or last node\n editor.getEditorState().read(() => {\n if (useEdgeAsDefault) {\n const firstNode = editor.getElementByKey(topLevelNodeKeys[0]!)\n const lastNode = editor.getElementByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]!)\n\n if (firstNode && lastNode) {\n const [firstNodeRect, lastNodeRect] = [\n getBoundingClientRectWithoutTransform(firstNode),\n getBoundingClientRectWithoutTransform(lastNode),\n ]\n\n if (y < firstNodeRect.top) {\n closestBlockElem.blockElem = firstNode\n closestBlockElem.distance = firstNodeRect.top - y\n closestBlockElem.blockNode = $getNodeByKey(topLevelNodeKeys[0]!)\n closestBlockElem.foundAtIndex = 0\n } else if (y > lastNodeRect.bottom) {\n closestBlockElem.distance = y - lastNodeRect.bottom\n closestBlockElem.blockNode = $getNodeByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]!)\n closestBlockElem.blockElem = lastNode\n closestBlockElem.foundAtIndex = topLevelNodeKeys.length - 1\n }\n\n if (closestBlockElem?.blockElem) {\n return {\n blockElem: null,\n isFoundNodeEmptyParagraph: false,\n } as Output\n }\n }\n }\n\n // Find matching block element\n let index = startIndex\n let direction = Indeterminate\n\n while (index >= 0 && index < topLevelNodeKeys.length) {\n const key = topLevelNodeKeys[index]!\n const elem = editor.getElementByKey(key)\n if (elem === null) {\n break\n }\n const point = new Point(x + horizontalOffset, y)\n //const domRect = Rect.fromDOM(elem)\n // Do not consider transform of blocks when calculating distance\n const domRect = Rect.fromDOMRect(getBoundingClientRectWithoutTransform(elem))\n\n const { marginBottom, marginTop } = getCollapsedMargins(elem)\n\n const rect = domRect.generateNewRect({\n bottom: domRect.bottom + marginBottom,\n left: anchorElementRect.left,\n right: anchorElementRect.right,\n top: domRect.top - marginTop,\n })\n\n const { distance, isOnBottomSide, isOnTopSide } = rect.distanceFromPoint(point)\n\n if (distance === 0) {\n closestBlockElem.blockElem = elem\n closestBlockElem.blockNode = $getNodeByKey(key)\n closestBlockElem.foundAtIndex = index\n closestBlockElem.distance = distance\n\n // Check if blockNode is an empty text node\n if (\n closestBlockElem.blockNode &&\n closestBlockElem.blockNode.getType() === 'paragraph' &&\n closestBlockElem.blockNode.getTextContent() === ''\n ) {\n if (!fuzzy && !props.returnEmptyParagraphs) {\n closestBlockElem.blockElem = null\n closestBlockElem.blockNode = null\n }\n\n closestBlockElem.isFoundNodeEmptyParagraph = true\n }\n break\n } else if (fuzzy) {\n if (distance < closestBlockElem.distance) {\n closestBlockElem.blockElem = elem\n closestBlockElem.blockNode = $getNodeByKey(key)\n closestBlockElem.distance = distance\n closestBlockElem.foundAtIndex = index\n }\n }\n\n if (direction === Indeterminate) {\n if (isOnTopSide) {\n direction = Upward\n } else if (isOnBottomSide) {\n direction = Downward\n } else {\n // stop search block element\n direction = Infinity\n }\n }\n\n index += direction\n }\n })\n\n // Store in cache before returning\n cache.props = props\n cache.result = {\n blockElem: closestBlockElem.blockElem,\n blockNode: closestBlockElem.blockNode,\n foundAtIndex: closestBlockElem.foundAtIndex,\n isFoundNodeEmptyParagraph: closestBlockElem.isFoundNodeEmptyParagraph,\n }\n\n return {\n blockElem: closestBlockElem.blockElem,\n blockNode: closestBlockElem.blockNode,\n foundAtIndex: closestBlockElem.foundAtIndex,\n isFoundNodeEmptyParagraph: closestBlockElem.isFoundNodeEmptyParagraph,\n }\n}\n"],"mappings":"AAAA;;AAGA,SAASA,aAAa,QAAQ;AAE9B,SAASC,KAAK,QAAQ;AACtB,SAASC,IAAI,QAAQ;AACrB,SAASC,qCAAqC,QAAQ;AACtD,SAASC,mBAAmB,QAAQ;AACpC,SAASC,mBAAmB,QAAQ;AAEpC;AACA,MAAMC,QAAA,GAAW;AACjB,MAAMC,MAAA,GAAS,CAAC;AAChB,MAAMC,aAAA,GAAgB;AA8BtB,MAAMC,KAAA,GAAQ;EACZC,KAAA,EAAO;EACPC,MAAA,EAAQ;AACV;AAEA,SAASC,aAAaC,QAAe,EAAEC,OAAc,EAAEC,SAAA,GAAoB,EAAE;EAC3E,MAAMC,EAAA,GAAKH,QAAA,CAASI,CAAC,GAAGH,OAAA,CAAQG,CAAC;EACjC,MAAMC,EAAA,GAAKL,QAAA,CAASM,CAAC,GAAGL,OAAA,CAAQK,CAAC;EACjC,OAAOH,EAAA,GAAKA,EAAA,GAAKE,EAAA,GAAKA,EAAA,IAAMH,SAAA,GAAYA,SAAA;AAC1C;AAEA,OAAO,SAASK,oBAAoBV,KAAY;EAC9C,MAAM;IACJW,UAAU;IACVC,eAAA,GAAkB,EAAE;IACpBC,MAAM;IACNC,KAAA,GAAQ,KAAK;IACbC,gBAAA,GAAmB,CAAC;IACpB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GAAGY,KAAA;QAClC;MACF;MAEA,IAAIC,SAAA,KAAc1C,aAAA,EAAe;QAC/B,IAAIsD,WAAA,EAAa;UACfZ,SAAA,GAAY3C,MAAA;QACd,OAAO,IAAIsD,cAAA,EAAgB;UACzBX,SAAA,GAAY5C,QAAA;QACd,OAAO;UACL;UACA4C,SAAA,GAAYd,QAAA;QACd;MACF;MAEAa,KAAA,IAASC,SAAA;IACX;EACF;EAEA;EACAzC,KAAA,CAAMC,KAAK,GAAGA,KAAA;EACdD,KAAA,CAAME,MAAM,GAAG;IACbsB,SAAA,EAAWD,gBAAA,CAAiBC,SAAS;IACrCC,SAAA,EAAWF,gBAAA,CAAiBE,SAAS;IACrCG,YAAA,EAAcL,gBAAA,CAAiBK,YAAY;IAC3CC,yBAAA,EAA2BN,gBAAA,CAAiBM;EAC9C;EAEA,OAAO;IACLL,SAAA,EAAWD,gBAAA,CAAiBC,SAAS;IACrCC,SAAA,EAAWF,gBAAA,CAAiBE,SAAS;IACrCG,YAAA,EAAcL,gBAAA,CAAiBK,YAAY;IAC3CC,yBAAA,EAA2BN,gBAAA,CAAiBM;EAC9C;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildInitialState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildInitialState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,EACd,aAAa,EACb,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,uBAAuB,GAAG;IACpC,CAAC,MAAM,EAAE,MAAM,GAAG;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;QAClB,SAAS,CAAC,EAAE,SAAS,CAAA;KACtB,CAAA;CACF,CAAA;AAED,KAAK,KAAK,GAAG;IACX,OAAO,EAAE;QACP,oBAAoB,EAAE,oBAAoB,CAAA;QAC1C,cAAc,EAAE,MAAM,CAAA;QACtB,KAAK,EAAE,aAAa,CAAA;QACpB,cAAc,EAAE,cAAc,CAAA;QAC9B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACpB,sBAAsB,EAAE,MAAM,CAAA;QAC9B,SAAS,EAAE,SAAS,CAAA;QACpB,WAAW,CAAC,EAAE,yBAAyB,CAAA;QACvC,WAAW,EAAE,mBAAmB,CAAA;QAChC,aAAa,EAAE,GAAG,CAAA;QAClB,GAAG,EAAE,cAAc,CAAA;KACpB,CAAA;IACD,YAAY,CAAC,EAAE,uBAAuB,CAAA;IACtC,QAAQ,EAAE,qBAAqB,EAAE,CAAA;CAClC,CAAA;AAED,wBAAsB,iBAAiB,CAAC,EACtC,OAAO,EACP,YAAY,EAAE,oBAAoB,EAClC,QAAQ,GACT,EAAE,KAAK,GAAG,OAAO,CAAC,uBAAuB,CAAC,
|
|
1
|
+
{"version":3,"file":"buildInitialState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildInitialState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,EACd,aAAa,EACb,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,uBAAuB,GAAG;IACpC,CAAC,MAAM,EAAE,MAAM,GAAG;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;QAClB,SAAS,CAAC,EAAE,SAAS,CAAA;KACtB,CAAA;CACF,CAAA;AAED,KAAK,KAAK,GAAG;IACX,OAAO,EAAE;QACP,oBAAoB,EAAE,oBAAoB,CAAA;QAC1C,cAAc,EAAE,MAAM,CAAA;QACtB,YAAY,CAAC,EAAE,GAAG,CAAA;QAClB,KAAK,EAAE,aAAa,CAAA;QACpB,cAAc,EAAE,cAAc,CAAA;QAC9B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACpB,sBAAsB,EAAE,MAAM,CAAA;QAC9B,SAAS,EAAE,SAAS,CAAA;QACpB,WAAW,CAAC,EAAE,yBAAyB,CAAA;QACvC,WAAW,EAAE,mBAAmB,CAAA;QAChC,aAAa,EAAE,GAAG,CAAA;QAClB,GAAG,EAAE,cAAc,CAAA;KACpB,CAAA;IACD,YAAY,CAAC,EAAE,uBAAuB,CAAA;IACtC,QAAQ,EAAE,qBAAqB,EAAE,CAAA;CAClC,CAAA;AAED,wBAAsB,iBAAiB,CAAC,EACtC,OAAO,EACP,YAAY,EAAE,oBAAoB,EAClC,QAAQ,GACT,EAAE,KAAK,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA2D1C"}
|
|
@@ -26,8 +26,10 @@ export async function buildInitialState({
|
|
|
26
26
|
clientFieldSchemaMap: context.clientFieldSchemaMap,
|
|
27
27
|
collectionSlug: context.collectionSlug,
|
|
28
28
|
data: blockNode.fields,
|
|
29
|
+
documentData: context.documentData,
|
|
29
30
|
fields: context.fieldSchemaMap.get(schemaFieldsPath)?.fields,
|
|
30
31
|
fieldSchemaMap: context.fieldSchemaMap,
|
|
32
|
+
initialBlockData: blockNode.fields,
|
|
31
33
|
operation: context.operation,
|
|
32
34
|
permissions: true,
|
|
33
35
|
preferences: context.preferences,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildInitialState.js","names":["fieldSchemasToFormState","buildInitialState","context","initialState","initialStateFromArgs","nodeData","node","children","type","blockNode","id","fields","schemaFieldsPath","lexicalFieldSchemaPath","blockType","formStateResult","clientFieldSchemaMap","collectionSlug","data","fieldSchemaMap","get","operation","permissions","preferences","renderAllFields","renderFieldFn","req","schemaPath","formState","currentFieldPreferences","field","name","collapsedArray","collapsed","includes"],"sources":["../../src/utilities/buildInitialState.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\nimport type {\n ClientFieldSchemaMap,\n DocumentPreferences,\n FieldSchemaMap,\n FormState,\n Operation,\n PayloadRequest,\n RichTextField,\n SanitizedFieldPermissions,\n} from 'payload'\n\nimport { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState'\n\nimport type { SerializedBlockNode } from '../nodeTypes.js'\n\nexport type InitialLexicalFormState = {\n [nodeID: string]: {\n [key: string]: any\n formState?: FormState\n }\n}\n\ntype Props = {\n context: {\n clientFieldSchemaMap: ClientFieldSchemaMap\n collectionSlug: string\n field: RichTextField\n fieldSchemaMap: FieldSchemaMap\n id?: number | string\n lexicalFieldSchemaPath: string\n operation: Operation\n permissions?: SanitizedFieldPermissions\n preferences: DocumentPreferences\n renderFieldFn: any\n req: PayloadRequest\n }\n initialState?: InitialLexicalFormState\n nodeData: SerializedLexicalNode[]\n}\n\nexport async function buildInitialState({\n context,\n initialState: initialStateFromArgs,\n nodeData,\n}: Props): Promise<InitialLexicalFormState> {\n let initialState: InitialLexicalFormState = initialStateFromArgs ?? {}\n for (const node of nodeData) {\n if ('children' in node) {\n initialState = await buildInitialState({\n context,\n initialState,\n nodeData: node.children as SerializedLexicalNode[],\n })\n }\n\n if (node.type === 'block' || node.type === 'inlineBlock') {\n const blockNode = node as SerializedBlockNode\n const id = blockNode?.fields?.id\n if (!id) {\n continue\n }\n\n const schemaFieldsPath =\n node.type === 'block'\n ? `${context.lexicalFieldSchemaPath}.lexical_internal_feature.blocks.lexical_blocks.${blockNode.fields.blockType}.fields`\n : `${context.lexicalFieldSchemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockNode.fields.blockType}.fields`\n\n // Build form state for the block\n\n const formStateResult = await fieldSchemasToFormState({\n id: context.id,\n clientFieldSchemaMap: context.clientFieldSchemaMap,\n collectionSlug: context.collectionSlug,\n data: blockNode.fields,\n fields: (context.fieldSchemaMap.get(schemaFieldsPath) as any)?.fields,\n fieldSchemaMap: context.fieldSchemaMap,\n operation: context.operation as any, // TODO: Type\n permissions: true,\n preferences: context.preferences,\n renderAllFields: true, // If this function runs, the parent lexical field is being re-rendered => thus we can assume all its sub-fields need to be re-rendered\n renderFieldFn: context.renderFieldFn,\n req: context.req,\n schemaPath: schemaFieldsPath,\n })\n\n if (!initialState[id]) {\n initialState[id] = {}\n }\n\n initialState[id].formState = formStateResult\n\n if (node.type === 'block') {\n const currentFieldPreferences = context.preferences?.fields?.[context.field.name]\n const collapsedArray = currentFieldPreferences?.collapsed\n if (collapsedArray && collapsedArray.includes(id)) {\n initialState[id].collapsed = true\n }\n }\n }\n }\n return initialState\n}\n"],"mappings":"AAYA,SAASA,uBAAuB,QAAQ;
|
|
1
|
+
{"version":3,"file":"buildInitialState.js","names":["fieldSchemasToFormState","buildInitialState","context","initialState","initialStateFromArgs","nodeData","node","children","type","blockNode","id","fields","schemaFieldsPath","lexicalFieldSchemaPath","blockType","formStateResult","clientFieldSchemaMap","collectionSlug","data","documentData","fieldSchemaMap","get","initialBlockData","operation","permissions","preferences","renderAllFields","renderFieldFn","req","schemaPath","formState","currentFieldPreferences","field","name","collapsedArray","collapsed","includes"],"sources":["../../src/utilities/buildInitialState.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\nimport type {\n ClientFieldSchemaMap,\n DocumentPreferences,\n FieldSchemaMap,\n FormState,\n Operation,\n PayloadRequest,\n RichTextField,\n SanitizedFieldPermissions,\n} from 'payload'\n\nimport { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState'\n\nimport type { SerializedBlockNode } from '../nodeTypes.js'\n\nexport type InitialLexicalFormState = {\n [nodeID: string]: {\n [key: string]: any\n formState?: FormState\n }\n}\n\ntype Props = {\n context: {\n clientFieldSchemaMap: ClientFieldSchemaMap\n collectionSlug: string\n documentData?: any\n field: RichTextField\n fieldSchemaMap: FieldSchemaMap\n id?: number | string\n lexicalFieldSchemaPath: string\n operation: Operation\n permissions?: SanitizedFieldPermissions\n preferences: DocumentPreferences\n renderFieldFn: any\n req: PayloadRequest\n }\n initialState?: InitialLexicalFormState\n nodeData: SerializedLexicalNode[]\n}\n\nexport async function buildInitialState({\n context,\n initialState: initialStateFromArgs,\n nodeData,\n}: Props): Promise<InitialLexicalFormState> {\n let initialState: InitialLexicalFormState = initialStateFromArgs ?? {}\n for (const node of nodeData) {\n if ('children' in node) {\n initialState = await buildInitialState({\n context,\n initialState,\n nodeData: node.children as SerializedLexicalNode[],\n })\n }\n\n if (node.type === 'block' || node.type === 'inlineBlock') {\n const blockNode = node as SerializedBlockNode\n const id = blockNode?.fields?.id\n if (!id) {\n continue\n }\n\n const schemaFieldsPath =\n node.type === 'block'\n ? `${context.lexicalFieldSchemaPath}.lexical_internal_feature.blocks.lexical_blocks.${blockNode.fields.blockType}.fields`\n : `${context.lexicalFieldSchemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockNode.fields.blockType}.fields`\n\n // Build form state for the block\n\n const formStateResult = await fieldSchemasToFormState({\n id: context.id,\n clientFieldSchemaMap: context.clientFieldSchemaMap,\n collectionSlug: context.collectionSlug,\n data: blockNode.fields,\n documentData: context.documentData,\n fields: (context.fieldSchemaMap.get(schemaFieldsPath) as any)?.fields,\n fieldSchemaMap: context.fieldSchemaMap,\n initialBlockData: blockNode.fields,\n operation: context.operation as any, // TODO: Type\n permissions: true,\n preferences: context.preferences,\n renderAllFields: true, // If this function runs, the parent lexical field is being re-rendered => thus we can assume all its sub-fields need to be re-rendered\n renderFieldFn: context.renderFieldFn,\n req: context.req,\n schemaPath: schemaFieldsPath,\n })\n\n if (!initialState[id]) {\n initialState[id] = {}\n }\n\n initialState[id].formState = formStateResult\n\n if (node.type === 'block') {\n const currentFieldPreferences = context.preferences?.fields?.[context.field.name]\n const collapsedArray = currentFieldPreferences?.collapsed\n if (collapsedArray && collapsedArray.includes(id)) {\n initialState[id].collapsed = true\n }\n }\n }\n }\n return initialState\n}\n"],"mappings":"AAYA,SAASA,uBAAuB,QAAQ;AA8BxC,OAAO,eAAeC,kBAA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OAAA,CAAQuB,WAAW;QAChCC,eAAA,EAAiB;QACjBC,aAAA,EAAezB,OAAA,CAAQyB,aAAa;QACpCC,GAAA,EAAK1B,OAAA,CAAQ0B,GAAG;QAChBC,UAAA,EAAYjB;MACd;MAEA,IAAI,CAACT,YAAY,CAACO,EAAA,CAAG,EAAE;QACrBP,YAAY,CAACO,EAAA,CAAG,GAAG,CAAC;MACtB;MAEAP,YAAY,CAACO,EAAA,CAAG,CAACoB,SAAS,GAAGf,eAAA;MAE7B,IAAIT,IAAA,CAAKE,IAAI,KAAK,SAAS;QACzB,MAAMuB,uBAAA,GAA0B7B,OAAA,CAAQuB,WAAW,EAAEd,MAAA,GAAST,OAAA,CAAQ8B,KAAK,CAACC,IAAI,CAAC;QACjF,MAAMC,cAAA,GAAiBH,uBAAA,EAAyBI,SAAA;QAChD,IAAID,cAAA,IAAkBA,cAAA,CAAeE,QAAQ,CAAC1B,EAAA,GAAK;UACjDP,YAAY,CAACO,EAAA,CAAG,CAACyB,SAAS,GAAG;QAC/B;MACF;IACF;EACF;EACA,OAAOhC,YAAA;AACT","ignoreList":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { RichTextFieldClient } from 'payload';
|
|
1
|
+
import type { ClientConfig, RichTextFieldClient } from 'payload';
|
|
2
2
|
import type { BaseClientFeatureProps, ClientFeature, ClientFeatureProviderMap, FeatureProviderProviderClient, ResolvedClientFeatureMap } from '../features/typesClient.js';
|
|
3
3
|
import type { ClientEditorConfig } from '../lexical/config/types.js';
|
|
4
4
|
import type { FeatureClientSchemaMap } from '../types.js';
|
|
5
5
|
export type CreateClientFeatureArgs<UnSanitizedClientProps, ClientProps> = ((props: {
|
|
6
|
+
config: ClientConfig;
|
|
6
7
|
featureClientSchemaMap: FeatureClientSchemaMap;
|
|
7
8
|
/** unSanitizedEditorConfig.features, but mapped */
|
|
8
9
|
featureProviderMap: ClientFeatureProviderMap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClientFeature.d.ts","sourceRoot":"","sources":["../../src/utilities/createClientFeature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"createClientFeature.d.ts","sourceRoot":"","sources":["../../src/utilities/createClientFeature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEhE,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EAExB,6BAA6B,EAC7B,wBAAwB,EACzB,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,MAAM,MAAM,uBAAuB,CAAC,sBAAsB,EAAE,WAAW,IACnE,CAAC,CAAC,KAAK,EAAE;IACP,MAAM,EAAE,YAAY,CAAA;IACpB,sBAAsB,EAAE,sBAAsB,CAAA;IAC9C,mDAAmD;IACnD,kBAAkB,EAAE,wBAAwB,CAAA;IAC5C,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,KAAK,EAAE,sBAAsB,CAAC,sBAAsB,CAAC,CAAA;IAErD,gBAAgB,EAAE,wBAAwB,CAAA;IAC1C,UAAU,EAAE,MAAM,CAAA;IAElB,uBAAuB,EAAE,kBAAkB,CAAA;CAC5C,KAAK,aAAa,CAAC,WAAW,CAAC,CAAC,GACjC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,6BAA6B,CAAC,CAAA;AAEnE,eAAO,MAAM,mBAAmB,EAAE,CAChC,sBAAsB,GAAG,SAAS,EAClC,WAAW,GAAG,sBAAsB,EAEpC,IAAI,EAAE,uBAAuB,CAAC,sBAAsB,EAAE,WAAW,CAAC,KAC/D,6BAA6B,CAAC,sBAAsB,EAAE,WAAW,CAiDrE,CAAA"}
|
|
@@ -5,6 +5,7 @@ export const createClientFeature = feature => {
|
|
|
5
5
|
};
|
|
6
6
|
if (typeof feature === 'function') {
|
|
7
7
|
featureProviderClient.feature = ({
|
|
8
|
+
config,
|
|
8
9
|
featureClientSchemaMap,
|
|
9
10
|
featureProviderMap,
|
|
10
11
|
field,
|
|
@@ -13,6 +14,7 @@ export const createClientFeature = feature => {
|
|
|
13
14
|
unSanitizedEditorConfig
|
|
14
15
|
}) => {
|
|
15
16
|
const toReturn = feature({
|
|
17
|
+
config,
|
|
16
18
|
featureClientSchemaMap,
|
|
17
19
|
featureProviderMap,
|
|
18
20
|
field,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClientFeature.js","names":["createClientFeature","feature","featureProviderProvideClient","props","featureProviderClient","clientFeatureProps","featureClientSchemaMap","featureProviderMap","field","resolvedFeatures","schemaPath","unSanitizedEditorConfig","toReturn","sanitizedClientFeatureProps","newFeature"],"sources":["../../src/utilities/createClientFeature.ts"],"sourcesContent":["import type { RichTextFieldClient } from 'payload'\n\nimport type {\n BaseClientFeatureProps,\n ClientFeature,\n ClientFeatureProviderMap,\n FeatureProviderClient,\n FeatureProviderProviderClient,\n ResolvedClientFeatureMap,\n} from '../features/typesClient.js'\nimport type { ClientEditorConfig } from '../lexical/config/types.js'\nimport type { FeatureClientSchemaMap } from '../types.js'\n\nexport type CreateClientFeatureArgs<UnSanitizedClientProps, ClientProps> =\n | ((props: {\n featureClientSchemaMap: FeatureClientSchemaMap\n /** unSanitizedEditorConfig.features, but mapped */\n featureProviderMap: ClientFeatureProviderMap\n field?: RichTextFieldClient\n props: BaseClientFeatureProps<UnSanitizedClientProps>\n // other resolved features, which have been loaded before this one. All features declared in 'dependencies' should be available here\n resolvedFeatures: ResolvedClientFeatureMap\n schemaPath: string\n // unSanitized EditorConfig,\n unSanitizedEditorConfig: ClientEditorConfig\n }) => ClientFeature<ClientProps>)\n | Omit<ClientFeature<ClientProps>, 'sanitizedClientFeatureProps'>\n\nexport const createClientFeature: <\n UnSanitizedClientProps = undefined,\n ClientProps = UnSanitizedClientProps,\n>(\n args: CreateClientFeatureArgs<UnSanitizedClientProps, ClientProps>,\n) => FeatureProviderProviderClient<UnSanitizedClientProps, ClientProps> = (feature) => {\n const featureProviderProvideClient: FeatureProviderProviderClient<any, any> = (props) => {\n const featureProviderClient: Partial<FeatureProviderClient<any, any>> = {\n clientFeatureProps: props,\n }\n\n if (typeof feature === 'function') {\n featureProviderClient.feature = ({\n featureClientSchemaMap,\n featureProviderMap,\n field,\n resolvedFeatures,\n schemaPath,\n unSanitizedEditorConfig,\n }) => {\n const toReturn = feature({\n featureClientSchemaMap,\n featureProviderMap,\n field,\n props,\n resolvedFeatures,\n schemaPath,\n unSanitizedEditorConfig,\n })\n\n if (toReturn.sanitizedClientFeatureProps === null) {\n toReturn.sanitizedClientFeatureProps = props\n }\n\n return toReturn\n }\n } else {\n // We have to spread feature here! Otherwise, if the arg of createClientFeature is not a function, and 2\n // richText editors have the same feature (even if both call it, e.g. both call UploadFeature()),\n // the second richText editor here will override sanitizedClientFeatureProps of the first feature, as both richText\n // editor features share the same reference to the feature object.\n // Example: richText editor 1 and 2 both have UploadFeature. richText editor 1 calls UploadFeature() with custom fields,\n // richText editor 2 calls UploadFeature() with NO custom fields. If we don't spread feature here, richText editor 1\n // will not have any custom fields, as richText editor 2 will override the feature object.\n const newFeature: ClientFeature<any> = { ...feature }\n newFeature.sanitizedClientFeatureProps = props\n featureProviderClient.feature = newFeature\n }\n return featureProviderClient as FeatureProviderClient<any, any>\n }\n\n return featureProviderProvideClient\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"createClientFeature.js","names":["createClientFeature","feature","featureProviderProvideClient","props","featureProviderClient","clientFeatureProps","config","featureClientSchemaMap","featureProviderMap","field","resolvedFeatures","schemaPath","unSanitizedEditorConfig","toReturn","sanitizedClientFeatureProps","newFeature"],"sources":["../../src/utilities/createClientFeature.ts"],"sourcesContent":["import type { ClientConfig, RichTextFieldClient } from 'payload'\n\nimport type {\n BaseClientFeatureProps,\n ClientFeature,\n ClientFeatureProviderMap,\n FeatureProviderClient,\n FeatureProviderProviderClient,\n ResolvedClientFeatureMap,\n} from '../features/typesClient.js'\nimport type { ClientEditorConfig } from '../lexical/config/types.js'\nimport type { FeatureClientSchemaMap } from '../types.js'\n\nexport type CreateClientFeatureArgs<UnSanitizedClientProps, ClientProps> =\n | ((props: {\n config: ClientConfig\n featureClientSchemaMap: FeatureClientSchemaMap\n /** unSanitizedEditorConfig.features, but mapped */\n featureProviderMap: ClientFeatureProviderMap\n field?: RichTextFieldClient\n props: BaseClientFeatureProps<UnSanitizedClientProps>\n // other resolved features, which have been loaded before this one. All features declared in 'dependencies' should be available here\n resolvedFeatures: ResolvedClientFeatureMap\n schemaPath: string\n // unSanitized EditorConfig,\n unSanitizedEditorConfig: ClientEditorConfig\n }) => ClientFeature<ClientProps>)\n | Omit<ClientFeature<ClientProps>, 'sanitizedClientFeatureProps'>\n\nexport const createClientFeature: <\n UnSanitizedClientProps = undefined,\n ClientProps = UnSanitizedClientProps,\n>(\n args: CreateClientFeatureArgs<UnSanitizedClientProps, ClientProps>,\n) => FeatureProviderProviderClient<UnSanitizedClientProps, ClientProps> = (feature) => {\n const featureProviderProvideClient: FeatureProviderProviderClient<any, any> = (props) => {\n const featureProviderClient: Partial<FeatureProviderClient<any, any>> = {\n clientFeatureProps: props,\n }\n\n if (typeof feature === 'function') {\n featureProviderClient.feature = ({\n config,\n featureClientSchemaMap,\n featureProviderMap,\n field,\n resolvedFeatures,\n schemaPath,\n unSanitizedEditorConfig,\n }) => {\n const toReturn = feature({\n config,\n featureClientSchemaMap,\n featureProviderMap,\n field,\n props,\n resolvedFeatures,\n schemaPath,\n unSanitizedEditorConfig,\n })\n\n if (toReturn.sanitizedClientFeatureProps === null) {\n toReturn.sanitizedClientFeatureProps = props\n }\n\n return toReturn\n }\n } else {\n // We have to spread feature here! Otherwise, if the arg of createClientFeature is not a function, and 2\n // richText editors have the same feature (even if both call it, e.g. both call UploadFeature()),\n // the second richText editor here will override sanitizedClientFeatureProps of the first feature, as both richText\n // editor features share the same reference to the feature object.\n // Example: richText editor 1 and 2 both have UploadFeature. richText editor 1 calls UploadFeature() with custom fields,\n // richText editor 2 calls UploadFeature() with NO custom fields. If we don't spread feature here, richText editor 1\n // will not have any custom fields, as richText editor 2 will override the feature object.\n const newFeature: ClientFeature<any> = { ...feature }\n newFeature.sanitizedClientFeatureProps = props\n featureProviderClient.feature = newFeature\n }\n return featureProviderClient as FeatureProviderClient<any, any>\n }\n\n return featureProviderProvideClient\n}\n"],"mappings":"AA6BA,OAAO,MAAMA,mBAAA,GAK8DC,OAAA;EACzE,MAAMC,4BAAA,GAAyEC,KAAA;IAC7E,MAAMC,qBAAA,GAAkE;MACtEC,kBAAA,EAAoBF;IACtB;IAEA,IAAI,OAAOF,OAAA,KAAY,YAAY;MACjCG,qBAAA,CAAsBH,OAAO,GAAG,CAAC;QAC/BK,MAAM;QACNC,sBAAsB;QACtBC,kBAAkB;QAClBC,KAAK;QACLC,gBAAgB;QAChBC,UAAU;QACVC;MAAuB,CACxB;QACC,MAAMC,QAAA,GAAWZ,OAAA,CAAQ;UACvBK,MAAA;UACAC,sBAAA;UACAC,kBAAA;UACAC,KAAA;UACAN,KAAA;UACAO,gBAAA;UACAC,UAAA;UACAC;QACF;QAEA,IAAIC,QAAA,CAASC,2BAA2B,KAAK,MAAM;UACjDD,QAAA,CAASC,2BAA2B,GAAGX,KAAA;QACzC;QAEA,OAAOU,QAAA;MACT;IACF,OAAO;MACL;MACA;MACA;MACA;MACA;MACA;MACA;MACA,MAAME,UAAA,GAAiC;QAAE,GAAGd;MAAQ;MACpDc,UAAA,CAAWD,2BAA2B,GAAGX,KAAA;MACzCC,qBAAA,CAAsBH,OAAO,GAAGc,UAAA;IAClC;IACA,OAAOX,qBAAA;EACT;EAEA,OAAOF,4BAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrawerContent.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DrawerContent.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAGvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAIpD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,aAAa,CAAC,CA8IzF,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { Form, FormSubmit, RenderFields, useDocumentInfo, useServerFunctions, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import { Form, FormSubmit, RenderFields, useDocumentForm, useDocumentInfo, useServerFunctions, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import { abortAndIgnore } from '@payloadcms/ui/shared';
|
|
6
|
+
import { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared';
|
|
6
7
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
8
|
import { v4 as uuid } from 'uuid';
|
|
8
9
|
import { useEditorConfigContext } from '../../lexical/config/client/EditorConfigProvider.js';
|
|
@@ -24,6 +25,9 @@ export const DrawerContent = ({
|
|
|
24
25
|
getDocPreferences,
|
|
25
26
|
globalSlug
|
|
26
27
|
} = useDocumentInfo();
|
|
28
|
+
const {
|
|
29
|
+
fields: parentDocumentFields
|
|
30
|
+
} = useDocumentForm();
|
|
27
31
|
const onChangeAbortControllerRef = useRef(new AbortController());
|
|
28
32
|
const [initialState, setInitialState] = useState(false);
|
|
29
33
|
const {
|
|
@@ -51,7 +55,9 @@ export const DrawerContent = ({
|
|
|
51
55
|
fields: true
|
|
52
56
|
},
|
|
53
57
|
docPreferences: await getDocPreferences(),
|
|
58
|
+
documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),
|
|
54
59
|
globalSlug,
|
|
60
|
+
initialBlockData: data,
|
|
55
61
|
operation: 'update',
|
|
56
62
|
renderAllFields: true,
|
|
57
63
|
schemaPath: schemaFieldsPath,
|
|
@@ -63,7 +69,7 @@ export const DrawerContent = ({
|
|
|
63
69
|
return () => {
|
|
64
70
|
abortAndIgnore(controller);
|
|
65
71
|
};
|
|
66
|
-
}, [schemaFieldsPath, id, data, getFormState, collectionSlug, globalSlug, getDocPreferences]);
|
|
72
|
+
}, [schemaFieldsPath, id, data, getFormState, collectionSlug, globalSlug, getDocPreferences, parentDocumentFields]);
|
|
67
73
|
const onChange = useCallback(async ({
|
|
68
74
|
formState: prevFormState
|
|
69
75
|
}) => {
|
|
@@ -79,8 +85,10 @@ export const DrawerContent = ({
|
|
|
79
85
|
fields: true
|
|
80
86
|
},
|
|
81
87
|
docPreferences: await getDocPreferences(),
|
|
88
|
+
documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),
|
|
82
89
|
formState: prevFormState,
|
|
83
90
|
globalSlug,
|
|
91
|
+
initialBlockFormState: prevFormState,
|
|
84
92
|
operation: 'update',
|
|
85
93
|
schemaPath: schemaFieldsPath,
|
|
86
94
|
signal: controller_0.signal
|
|
@@ -89,7 +97,7 @@ export const DrawerContent = ({
|
|
|
89
97
|
return prevFormState;
|
|
90
98
|
}
|
|
91
99
|
return state_0;
|
|
92
|
-
}, [getFormState, id, collectionSlug, getDocPreferences, globalSlug, schemaFieldsPath]);
|
|
100
|
+
}, [getFormState, id, collectionSlug, getDocPreferences, parentDocumentFields, globalSlug, schemaFieldsPath]);
|
|
93
101
|
// cleanup effect
|
|
94
102
|
useEffect(() => {
|
|
95
103
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrawerContent.js","names":["Form","FormSubmit","RenderFields","useDocumentInfo","useServerFunctions","useTranslation","abortAndIgnore","React","useCallback","useEffect","useRef","useState","v4","uuid","useEditorConfigContext","DrawerContent","data","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPath","schemaPathSuffix","t","id","collectionSlug","getDocPreferences","globalSlug","onChangeAbortControllerRef","AbortController","initialState","setInitialState","fieldProps","featureClientSchemaMap","permissions","getFormState","schemaFieldsPath","
|
|
1
|
+
{"version":3,"file":"DrawerContent.js","names":["Form","FormSubmit","RenderFields","useDocumentForm","useDocumentInfo","useServerFunctions","useTranslation","abortAndIgnore","deepCopyObjectSimpleWithoutReactComponents","React","useCallback","useEffect","useRef","useState","v4","uuid","useEditorConfigContext","DrawerContent","data","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPath","schemaPathSuffix","t","id","collectionSlug","getDocPreferences","globalSlug","fields","parentDocumentFields","onChangeAbortControllerRef","AbortController","initialState","setInitialState","fieldProps","featureClientSchemaMap","permissions","getFormState","schemaFieldsPath","controller","awaitInitialState","state","docPermissions","docPreferences","documentFormState","initialBlockData","operation","renderAllFields","signal","onChange","formState","prevFormState","current","initialBlockFormState","_jsxs","beforeSubmit","disableValidationOnSubmit","Array","isArray","onSubmit","_jsx","forceRender","parentIndexPath","parentPath","parentSchemaPath","readOnly"],"sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport {\n Form,\n FormSubmit,\n RenderFields,\n useDocumentForm,\n useDocumentInfo,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport type { FieldsDrawerProps } from './Drawer.js'\n\nimport { useEditorConfigContext } from '../../lexical/config/client/EditorConfigProvider.js'\n\nexport const DrawerContent: React.FC<Omit<FieldsDrawerProps, 'drawerSlug' | 'drawerTitle'>> = ({\n data,\n featureKey,\n fieldMapOverride,\n handleDrawerSubmit,\n schemaFieldsPathOverride,\n schemaPath,\n schemaPathSuffix,\n}) => {\n const { t } = useTranslation()\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { fields: parentDocumentFields } = useDocumentForm()\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n\n const [initialState, setInitialState] = useState<false | FormState | undefined>(false)\n\n const {\n fieldProps: { featureClientSchemaMap, permissions },\n } = useEditorConfigContext()\n\n const { getFormState } = useServerFunctions()\n\n const schemaFieldsPath =\n schemaFieldsPathOverride ??\n `${schemaPath}.lexical_internal_feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n\n const fields: any = fieldMapOverride ?? featureClientSchemaMap[featureKey]?.[schemaFieldsPath] // Field Schema\n\n useEffect(() => {\n const controller = new AbortController()\n\n const awaitInitialState = async () => {\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: data ?? {},\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n globalSlug,\n initialBlockData: data,\n operation: 'update',\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n setInitialState(state)\n }\n\n void awaitInitialState()\n\n return () => {\n abortAndIgnore(controller)\n }\n }, [\n schemaFieldsPath,\n id,\n data,\n getFormState,\n collectionSlug,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n ])\n\n const onChange = useCallback(\n async ({ formState: prevFormState }: { formState: FormState }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n return state\n },\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n schemaFieldsPath,\n ],\n )\n\n // cleanup effect\n useEffect(() => {\n return () => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [])\n\n if (initialState === false) {\n return null\n }\n\n return (\n <Form\n beforeSubmit={[onChange]}\n disableValidationOnSubmit\n fields={Array.isArray(fields) ? fields : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleDrawerSubmit}\n uuid={uuid()}\n >\n <RenderFields\n fields={Array.isArray(fields) ? fields : []}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\" // See Blocks feature path for details as for why this is empty\n parentSchemaPath={schemaFieldsPath}\n permissions={permissions}\n readOnly={false}\n />\n <FormSubmit>{t('fields:saveChanges')}</FormSubmit>\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SACEA,IAAI,EACJC,UAAU,EACVC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,kBAAkB,EAClBC,cAAc,QACT;AACP,SAASC,cAAc,QAAQ;AAC/B,SAASC,0CAA0C,QAAQ;AAC3D,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAChE,SAASC,EAAA,IAAMC,IAAI,QAAQ;AAI3B,SAASC,sBAAsB,QAAQ;AAEvC,OAAO,MAAMC,aAAA,GAAiFA,CAAC;EAC7FC,IAAI;EACJC,UAAU;EACVC,gBAAgB;EAChBC,kBAAkB;EAClBC,wBAAwB;EACxBC,UAAU;EACVC;AAAgB,CACjB;EACC,MAAM;IAAEC;EAAC,CAAE,GAAGnB,cAAA;EACd,MAAM;IAAEoB,EAAE;IAAEC,cAAc;IAAEC,iBAAiB;I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AA,CAAS;IACpBU,QAAA,EAAUxC,kBAAA;IACVN,IAAA,EAAMA,IAAA;4BAEN+C,IAAA,CAAC5D,YAAA;MACC4B,MAAA,EAAQ6B,KAAA,CAAMC,OAAO,CAAC9B,MAAA,IAAUA,MAAA,GAAS,EAAE;MAC3CiC,WAAW;MACXC,eAAA,EAAgB;MAChBC,UAAA,EAAW,GAAG;MAAA;;MACdC,gBAAA,EAAkB1B,gBAAA;MAClBF,WAAA,EAAaA,WAAA;MACb6B,QAAA,EAAU;qBAEZL,IAAA,CAAC7D,UAAA;gBAAYwB,CAAA,CAAE;;;AAGrB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/richtext-lexical",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0-canary.597254e",
|
|
4
4
|
"description": "The officially supported Lexical richtext adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -352,8 +352,8 @@
|
|
|
352
352
|
"react-error-boundary": "4.1.2",
|
|
353
353
|
"ts-essentials": "10.0.3",
|
|
354
354
|
"uuid": "10.0.0",
|
|
355
|
-
"@payloadcms/translations": "3.
|
|
356
|
-
"@payloadcms/ui": "3.
|
|
355
|
+
"@payloadcms/translations": "3.23.0-canary.597254e",
|
|
356
|
+
"@payloadcms/ui": "3.23.0-canary.597254e"
|
|
357
357
|
},
|
|
358
358
|
"devDependencies": {
|
|
359
359
|
"@babel/cli": "7.26.4",
|
|
@@ -374,7 +374,7 @@
|
|
|
374
374
|
"eslint-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
|
|
375
375
|
"swc-plugin-transform-remove-imports": "3.1.0",
|
|
376
376
|
"@payloadcms/eslint-config": "3.9.0",
|
|
377
|
-
"payload": "3.
|
|
377
|
+
"payload": "3.23.0-canary.597254e"
|
|
378
378
|
},
|
|
379
379
|
"peerDependencies": {
|
|
380
380
|
"@faceless-ui/modal": "3.0.0-beta.2",
|
|
@@ -392,8 +392,8 @@
|
|
|
392
392
|
"lexical": "0.21.0",
|
|
393
393
|
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
394
394
|
"react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
395
|
-
"@payloadcms/next": "3.
|
|
396
|
-
"payload": "3.
|
|
395
|
+
"@payloadcms/next": "3.23.0-canary.597254e",
|
|
396
|
+
"payload": "3.23.0-canary.597254e"
|
|
397
397
|
},
|
|
398
398
|
"engines": {
|
|
399
399
|
"node": "^18.20.2 || >=20.9.0"
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";import{c as ye,f as W,g as B,i as xe,j as Ee,k as Ce,l as be,m as Ne}from"./chunk-JKFXKPNG.js";import{a as he,b as P}from"./chunk-3LGFOM34.js";import{jsx as O,jsxs as le}from"react/jsx-runtime";import{FieldDescription as Fo,FieldError as Oo,FieldLabel as _o,RenderCustomComponent as rt,useEditDepth as $o,useField as Ho}from"@payloadcms/ui";import{mergeFieldStyles as jo}from"@payloadcms/ui/shared";import it,{useCallback as st,useEffect as lt,useMemo as Ko,useState as at}from"react";import{ErrorBoundary as zo}from"react-error-boundary";import"./bundled.css";import{jsx as F}from"react/jsx-runtime";import{LexicalComposer as Ao}from"@lexical/react/LexicalComposer.js";import{useEditDepth as Do}from"@payloadcms/ui";import*as tt from"react";import{useMemo as Bo}from"react";import{c as xo}from"react/compiler-runtime";import{jsx as b,jsxs as Q}from"react/jsx-runtime";import{useLexicalComposerContext as Eo}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as Co}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as bo}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as No}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Po}from"@lexical/react/LexicalRichTextPlugin.js";import{BLUR_COMMAND as Ro,COMMAND_PRIORITY_LOW as Ze,FOCUS_COMMAND as wo}from"lexical";import*as J from"react";import{useEffect as To,useState as So}from"react";import{jsx as Pe}from"react/jsx-runtime";import"react";var H=({anchorElem:t,clientProps:e,plugin:o})=>o.position==="floatingAnchorElem"&&t?o.Component&&Pe(o.Component,{anchorElem:t,clientProps:e}):o.Component&&Pe(o.Component,{clientProps:e});import{c as mt}from"react/compiler-runtime";import{useLexicalComposerContext as ut}from"@lexical/react/LexicalComposerContext";import{mergeRegister as ft}from"@lexical/utils";import{$createNodeSelection as pt,$getNearestNodeFromDOMNode as gt,$getSelection as ht,$isDecoratorNode as yt,$isNodeSelection as xt,$setSelection as Re,CLICK_COMMAND as Et,COMMAND_PRIORITY_LOW as me,KEY_BACKSPACE_COMMAND as Ct,KEY_DELETE_COMMAND as bt}from"lexical";import{useEffect as Nt}from"react";function we(){let t=mt(3),[e]=ut(),o=Rt,r,n;return t[0]!==e?(r=()=>ft(e.registerCommand(Et,Pt,me),e.registerCommand(bt,o,me),e.registerCommand(Ct,o,me)),n=[e],t[0]=e,t[1]=r,t[2]=n):(r=t[1],n=t[2]),Nt(r,n),null}function Pt(t){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let e=Tt(t);if(!e)return!0;let{decoratorElement:o,decoratorNode:r}=e,{target:n}=t;if(!(n instanceof HTMLElement)||n.isContentEditable||n.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]'))Re(null);else{let a=pt();a.add(r.getKey()),Re(a),o.classList.add("decorator-selected")}return!0}function Rt(t){let e=ht();return xt(e)?(t.preventDefault(),e.getNodes().forEach(wt),!0):!1}function wt(t){t.remove()}function Tt(t){if(!(t.target instanceof Element))return;let e=t.target.closest('[data-lexical-decorator="true"]');if(!e)return;let o=gt(e);return yt(o)?{decoratorElement:e,decoratorNode:o}:void 0}import{jsx as ue}from"react/jsx-runtime";import{useLexicalComposerContext as Lt}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as At}from"lexical";import*as ve from"react";import{useCallback as Dt,useEffect as ke,useRef as Bt,useState as Ft}from"react";import{createPortal as Ot}from"react-dom";var Y=(t,e,o,r,n=50,c=25)=>{let a=0;if(t&&!t.contains(r)){let{bottom:s,left:d,right:x,top:g}=t.getBoundingClientRect(),l=g+window.scrollY,i=s+window.scrollY;if(o<l-c||o>i+c||e<d-n||e>x+n)return-1;(e<d||e>x)&&(a=e<d?e-d:e-x)}return a};import{$getNodeByKey as ee}from"lexical";function G(t){let e=t.getBoundingClientRect(),o=getComputedStyle(t).getPropertyValue("transform");if(!o||o==="none")return e;let r=o.split(",").pop();return e.y=e.y-Number(r?.replace(")","")),e}function Z(t){let e=(d,x)=>d?parseFloat(window.getComputedStyle(d)[x]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(t),n=e(t.previousElementSibling,"marginBottom"),c=e(t.nextElementSibling,"marginTop"),a=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),c),marginTop:a}}import{$getRoot as St}from"lexical";function j(t){return t.getEditorState().read(()=>St().getChildrenKeys())}var kt=1,vt=-1,Te=0,I={props:null,result:null};function Mt(t,e,o=20){let r=t.x-e.x,n=t.y-e.y;return r*r+n*n<=o*o}function V(t){let{anchorElem:e,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:c=0,point:{x:a,y:s},startIndex:d=0,useEdgeAsDefault:x=!1}=t;if(o>0&&I.props&&I.result&&I.props.fuzzy===t.fuzzy&&I.props.horizontalOffset===t.horizontalOffset&&I.props.useEdgeAsDefault===t.useEdgeAsDefault&&Mt(I.props.point,t.point,o))return I.result;let g=e.getBoundingClientRect(),l=j(r),i={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(x){let[u,h]=[r.getElementByKey(l[0]),r.getElementByKey(l[l.length-1])];if(u&&h){let[m,f]=[G(u),G(h)];if(s<m.top?(i.blockElem=u,i.distance=m.top-s,i.blockNode=ee(l[0]),i.foundAtIndex=0):s>f.bottom&&(i.distance=s-f.bottom,i.blockNode=ee(l[l.length-1]),i.blockElem=h,i.foundAtIndex=l.length-1),i?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let p=d,y=Te;for(;p>=0&&p<l.length;){let u=l[p],h=r.getElementByKey(u);if(h===null)break;let m=new B(a+c,s),f=be.fromDOMRect(G(h)),{marginBottom:E,marginTop:T}=Z(h),w=f.generateNewRect({bottom:f.bottom+E,left:g.left,right:g.right,top:f.top-T}),{distance:R,isOnBottomSide:S,isOnTopSide:C}=w.distanceFromPoint(m);if(R===0){i.blockElem=h,i.blockNode=ee(u),i.foundAtIndex=p,i.distance=R,i.blockNode&&i.blockNode.getType()==="paragraph"&&i.blockNode.getTextContent()===""&&(!n&&!t.returnEmptyParagraphs&&(i.blockElem=null,i.blockNode=null),i.isFoundNodeEmptyParagraph=!0);break}else n&&R<i.distance&&(i.blockElem=h,i.blockNode=ee(u),i.distance=R,i.foundAtIndex=p);y===Te&&(C?y=vt:S?y=kt:y=1/0),p+=y}}),I.props=t,I.result={blockElem:i.blockElem,blockNode:i.blockNode,foundAtIndex:i.foundAtIndex,isFoundNodeEmptyParagraph:i.isFoundNodeEmptyParagraph},{blockElem:i.blockElem,blockNode:i.blockNode,foundAtIndex:i.foundAtIndex,isFoundNodeEmptyParagraph:i.isFoundNodeEmptyParagraph}}function te(t,e){return!!t.closest(`.${e}`)}var It=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function Se(t){if(!t||It.includes(t.tagName)||t.offsetHeight===0||t.offsetWidth===0)return!1;let e=window.getComputedStyle(t);return!(e.display==="table-cell"||e.position==="absolute"||e.visibility==="hidden"||e.opacity==="0")}function oe(t,e,o,r=0){if(!t){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}let n=t.getBoundingClientRect(),c=window.getComputedStyle(t),a=e.getBoundingClientRect(),s=o.getBoundingClientRect(),d;if(["lexical-block","lexical-upload","lexical-relationship"].some(l=>t.firstElementChild?.classList.contains(l)))d=n.top+8-s.top;else{let l=Se(t)?parseInt(c.lineHeight,10):0;d=n.top+(l-a.height)/2-s.top}let g=r;e.style.opacity="1",e.style.transform=`translate(${g}px, ${d}px)`}var _t="add-block-menu",ne=1/0;function $t(t){return t===0?1/0:ne>=0&&ne<t?ne:Math.floor(t/2)}function Ht(t,e,o){let r=e.parentElement,{editorConfig:n}=P(),c=n?.admin?.hideGutter?-24:12,a=Bt(null),[s,d]=Ft(null);ke(()=>{function g(l){let i=l.target;if(!W(i))return;let p=Y(r,l.pageX,l.pageY,i);if(p===-1){d(null);return}if(te(i,_t))return;let y=j(t),{blockElem:u,blockNode:h,foundAtIndex:m}=V({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-p,point:new B(l.x,l.y),returnEmptyParagraphs:!0,startIndex:$t(y.length),useEdgeAsDefault:!1});ne=m,u&&h&&(s?.node!==h||s?.elem!==u)&&d({elem:u,node:h})}return document?.addEventListener("mousemove",g),()=>{document?.removeEventListener("mousemove",g)}},[r,e,t,s]),ke(()=>{a.current&&s?.node&&oe(s?.elem,a.current,e,c)},[e,s,c]);let x=Dt(g=>{let l=s;l?.node&&(t.update(()=>{let i=!0;if((l?.node.getType()!=="paragraph"||l.node.getTextContent()!=="")&&(i=!1),!i){let p=At();l?.node.insertAfter(p),setTimeout(()=>{l={elem:t.getElementByKey(p.getKey()),node:p},d(l)},0)}}),setTimeout(()=>{t.update(()=>{t.focus(),l?.node&&"select"in l.node&&typeof l.node.select=="function"&&l.node.select()})},1),setTimeout(()=>{t.dispatchCommand(Ee,{node:l?.node})},2),g.stopPropagation(),g.preventDefault())},[t,s]);return Ot(ue(ve.Fragment,{children:ue("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:g=>{x(g)},ref:a,type:"button",children:ue("div",{className:o?"icon":""})})}),e)}function Me(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=Lt();return Ht(r,o,r._editable)}import{jsx as re,jsxs as Kt}from"react/jsx-runtime";import{useLexicalComposerContext as zt}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as Ae}from"@lexical/rich-text";import{$getNearestNodeFromDOMNode as De,$getNodeByKey as Wt}from"lexical";import*as $e from"react";import{useEffect as fe,useRef as ie,useState as Be}from"react";import{createPortal as Yt}from"react-dom";var Ie=0,jt=-24;var K=0;function Le(t,e,o,r,n,c,a,s,d,x=!1){let{height:g,top:l}=r.getBoundingClientRect(),{top:i,width:p}=a.getBoundingClientRect(),{marginBottom:y,marginTop:u}=Z(r),h=l,m=c>=l+g/2+window.scrollY,f=!1;if(n?.elem)if(r!==n?.elem)(m&&n?.elem&&n?.elem===r.nextElementSibling||!m&&n?.elem&&n?.elem===r.previousElementSibling)&&(K++,K<200&&(f=!0));else{K++;let R=n?.boundingBox?.y,S=r.getBoundingClientRect().y;(m===n?.isBelow&&R===S||K<200)&&(f=!1)}if(f)return{isBelow:m,willStayInSamePosition:f};x?h+=g/2:m?h+=g+y/2:h-=u/2;let E=0;x||(m?E=-Ie:E=Ie);let T=h-i+E,w=jt-e;return o.style.width=`calc(${p}px - ${t})`,o.style.opacity=".8",o.style.transform=`translate(${w}px, calc(${T}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?m?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),K=0,{isBelow:m,willStayInSamePosition:f}}var Gt="draggable-block-menu",Fe="application/x-lexical-drag-block",q=1/0;function Oe(t){return t===0?1/0:q>=0&&q<t?q:Math.floor(t/2)}function Vt(t,e){let{transform:o}=e.style;t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=o})}function _e(t,e){t&&(t.style.opacity="0"),e&&(e.style.opacity="",e.style.marginBottom="",e.style.marginTop="")}function Ut(t,e,o){let r=e.parentElement,n=ie(null),c=ie(null),a=ie(null),s=ie(!1),[d,x]=Be(null),[g,l]=Be(null),{editorConfig:i}=P(),p=i?.admin?.hideGutter?-44:-8;fe(()=>{function h(m){let f=m.target;if(!W(f))return;let E=Y(r,m.pageX,m.pageY,f);if(E===-1){x(null);return}if(te(f,Gt))return;let T=j(t),{blockElem:w,foundAtIndex:R,isFoundNodeEmptyParagraph:S}=V({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-E,point:new B(m.x,m.y),startIndex:Oe(T.length),useEdgeAsDefault:!1,verbose:!1});q=R,!(!w&&!S)&&d!==w&&x(w)}return document?.addEventListener("mousemove",h),()=>{document?.removeEventListener("mousemove",h)}},[r,e,t,d]),fe(()=>{n.current&&oe(d,n.current,e,p)},[e,d,p]),fe(()=>{function h(f){if(!s.current)return!1;let[E]=Ae(f);if(E)return!1;let{pageY:T,target:w}=f;if(!W(w))return!1;let R=Y(r,f.pageX,f.pageY,w,100,50),S=j(t),{blockElem:C,foundAtIndex:z,isFoundNodeEmptyParagraph:A}=V({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-R,point:new B(f.x,f.y),startIndex:Oe(S.length),useEdgeAsDefault:!0,verbose:!0});q=z;let v=c.current;if(C===null||v===null)return!1;if(d!==C){let{isBelow:k,willStayInSamePosition:D}=Le(i?.admin?.hideGutter?"0px":"3rem",p+(i?.admin?.hideGutter?n?.current?.getBoundingClientRect()?.width??0:-(n?.current?.getBoundingClientRect()?.width??0)),v,C,g,T,e,f,a,A);f.preventDefault(),D||l({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:k})}else g?.elem&&(_e(v,g.elem),l({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:!1}));return!0}function m(f){if(!s.current)return!1;let[E]=Ae(f);if(E)return!1;let{dataTransfer:T,pageY:w,target:R}=f,S=T?.getData(Fe)||"";return t.update(()=>{let C=Wt(S);if(!C||!W(R))return!1;let z=Y(r,f.pageX,f.pageY,R,100,50),{blockElem:A,isFoundNodeEmptyParagraph:v}=V({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-z,point:new B(f.x,f.y),useEdgeAsDefault:!0});if(!A)return!1;let k=De(A);if(!k)return!1;if(k===C)return!0;let{height:D,top:ae}=G(A),ce=w>=ae+D/2+window.scrollY;v?(k.insertBefore(C),k.remove()):ce?k.insertAfter(C):k.insertBefore(C),d!==null&&x(null),document.querySelectorAll(".lexical-block-highlighter").forEach(M=>{M.remove()});let X=t.getElementByKey(C.getKey());setTimeout(()=>{let M=X?.getBoundingClientRect();if(!M)return;let N=document.createElement("div");N.className="lexical-block-highlighter",N.style.backgroundColor="var(--theme-elevation-1000",N.style.transition="opacity 0.5s ease-in-out",N.style.zIndex="1",N.style.pointerEvents="none",N.style.boxSizing="border-box",N.style.borderRadius="4px",N.style.position="absolute",document.body.appendChild(N),N.style.opacity="0.1",N.style.height=`${M.height+8}px`,N.style.width=`${M.width+8}px`,N.style.top=`${M.top+window.scrollY-4}px`,N.style.left=`${M.left-4}px`,setTimeout(()=>{N.style.opacity="0",setTimeout(()=>{N.remove()},500)},1e3)},120)}),!0}return document.addEventListener("dragover",h),document.addEventListener("drop",m),()=>{document.removeEventListener("dragover",h),document.removeEventListener("drop",m)}},[r,p,e,t,g,d,i?.admin?.hideGutter]);function y(h){let m=h.dataTransfer;if(!m||!d)return;Vt(m,d);let f="";t.update(()=>{let E=De(d);E&&(f=E.getKey())}),s.current=!0,m.setData(Fe,f)}function u(){s.current=!1,g?.elem&&_e(c.current,g?.elem)}return Yt(Kt($e.Fragment,{children:[re("div",{className:"icon draggable-block-menu",draggable:!0,onDragEnd:u,onDragStart:y,ref:n,children:re("div",{className:o?"icon":""})}),re("div",{className:"draggable-block-target-line",ref:c}),re("div",{className:"debug-highlight",ref:a})]}),e)}function He(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=zt();return Ut(r,o,r._editable)}import{c as Jt}from"react/compiler-runtime";import{jsx as pe}from"react/jsx-runtime";import{useLexicalComposerContext as qt}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as Qt,$getRoot as Xt}from"lexical";import"react";var je="insert-paragraph-at-end",Ke=()=>{let t=Jt(4),[e]=qt(),{editorConfig:o}=P();if(o?.admin?.hideInsertParagraphAtEnd)return null;let r;t[0]!==e?(r=()=>{e.update(Zt)},t[0]=e,t[1]=r):r=t[1];let n=r,c;return t[2]!==n?(c=pe("div",{"aria-label":"Insert Paragraph",className:je,onClick:n,role:"button",tabIndex:0,children:pe("div",{className:`${je}-inside`,children:pe("span",{children:"+"})})}),t[2]=n,t[3]=c):c=t[3],c};function Zt(){let t=Qt();Xt().append(t),t.select()}import{c as eo}from"react/compiler-runtime";import{useLexicalComposerContext as to}from"@lexical/react/LexicalComposerContext";import*as ze from"react";var We=()=>{let t=eo(4),{editorConfig:e}=P(),[o]=to(),r,n;return t[0]!==o||t[1]!==e.features.markdownTransformers?(r=()=>ye(o,e.features.markdownTransformers??[]),n=[o,e.features.markdownTransformers],t[0]=o,t[1]=e.features.markdownTransformers,t[2]=r,t[3]=n):(r=t[2],n=t[3]),ze.useEffect(r,n),null};import{jsx as U,jsxs as Ge}from"react/jsx-runtime";import{useLexicalComposerContext as no}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as Ve}from"@payloadcms/ui";import{useCallback as ro,useMemo as io,useState as so}from"react";import"react";import*as Ue from"react-dom";import{c as oo}from"react/compiler-runtime";import"react";function Ye(t,e){let o=oo(4),{maxLength:r,minLength:n}=e,c=r===void 0?75:r,a=n===void 0?1:n,s;return o[0]!==c||o[1]!==a||o[2]!==t?(s=d=>{let{query:x}=d,g="[^"+t+xe+"\\s]",i=new RegExp("(^|\\s|\\()(["+t+"]((?:"+g+"){0,"+c+"}))$").exec(x);if(i!==null){let p=i[1],y=i[3];if(y.length>=a)return{leadOffset:i.index+p.length,matchingString:y,replaceableString:i[2]}}return null},o[0]=c,o[1]=a,o[2]=t,o[3]=s):s=o[3],s}var L="slash-menu-popup";function lo({isSelected:t,item:e,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:c,schemaPath:a}}=P(),{i18n:s}=Ve(),d=`${L}__item ${L}__item-${e.key}`;t&&(d+=` ${L}__item--selected`);let x=e.key;return e.label&&(x=typeof e.label=="function"?e.label({featureClientSchemaMap:c,i18n:s,schemaPath:a}):e.label),x.length>25&&(x=x.substring(0,25)+"..."),Ge("button",{"aria-selected":t,className:d,id:L+"__item-"+e.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[e?.Icon&&U(e.Icon,{}),U("span",{className:`${L}__item-text`,children:x})]},e.key)}function Je({anchorElem:t=document.body}){let[e]=no(),[o,r]=so(null),{editorConfig:n}=P(),{i18n:c}=Ve(),{fieldProps:{featureClientSchemaMap:a,schemaPath:s}}=P(),d=Ye("/",{minLength:0}),x=ro(()=>{let l=[];for(let i of n.features.slashMenu.dynamicGroups)if(o){let p=i({editor:e,queryString:o});l=l.concat(p)}return l},[e,o,n?.features]),g=io(()=>{let l=[];for(let i of n?.features.slashMenu.groups??[])l.push(i);if(o){l=l.map(p=>{let y=p.items.filter(u=>{let h=u.key;return u.label&&(h=typeof u.label=="function"?u.label({featureClientSchemaMap:a,i18n:c,schemaPath:s}):u.label),new RegExp(o,"gi").exec(h)?!0:u.keywords!=null?u.keywords.some(m=>new RegExp(o,"gi").exec(m)):!1});return y.length?{...p,items:y}:null}),l=l.filter(p=>p!=null);let i=x();for(let p of i){let y=l.find(u=>u.key===p.key);y?l=l.filter(u=>u.key!==p.key):y={...p,items:[]},y?.items?.length&&(y.items=y.items.concat(y.items)),l.push(y)}}return l},[o,n?.features.slashMenu.groups,x,a,c,s]);return U(Ce,{anchorElem:t,groups:g,menuRenderFn:(l,{selectedItemKey:i,selectItemAndCleanUp:p,setSelectedItemKey:y})=>l.current&&g.length?Ue.createPortal(U("div",{className:L,children:g.map(u=>{let h=u.key;return u.label&&a&&(h=typeof u.label=="function"?u.label({featureClientSchemaMap:a,i18n:c,schemaPath:s}):u.label),Ge("div",{className:`${L}__group ${L}__group-${u.key}`,children:[U("div",{className:`${L}__group-title`,children:h}),u.items.map((m,f)=>U(lo,{index:f,isSelected:i===m.key,item:m,onClick:()=>{y(m.key),p(m)},onMouseEnter:()=>{y(m.key)},ref:E=>{m.ref={current:E}}},m.key))]},u.key)})}),l.current):null,onQueryChange:r,triggerFn:d})}import{c as ao}from"react/compiler-runtime";import{useLexicalComposerContext as co}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as mo,TextNode as uo}from"lexical";import{useEffect as fo}from"react";function qe(t){let e=ao(6),{features:o}=t,[r]=co(),n;e[0]!==r||e[1]!==o.enabledFormats?(n=()=>{let a=po(o.enabledFormats);if(a.length!==0)return r.registerNodeTransform(uo,s=>{a.forEach(d=>{s.hasFormat(d)&&s.toggleFormat(d)})})},e[0]=r,e[1]=o.enabledFormats,e[2]=n):n=e[2];let c;return e[3]!==r||e[4]!==o?(c=[r,o],e[3]=r,e[4]=o,e[5]=c):c=e[5],fo(n,c),null}function po(t){let e=Object.keys(mo),o=new Set(t);return e.filter(r=>!o.has(r))}import{c as go}from"react/compiler-runtime";import{jsx as Qe}from"react/jsx-runtime";import{ContentEditable as ho}from"@lexical/react/LexicalContentEditable.js";import{useTranslation as yo}from"@payloadcms/ui";import"react";function Xe(t){let e=go(7),{className:o,editorConfig:r}=t,{t:n}=yo(),c;if(e[0]!==o||e[1]!==r?.admin?.placeholder||e[2]!==n){let a;e[4]!==r?.admin?.placeholder||e[5]!==n?(a=r?.admin?.placeholder??n("lexical:general:placeholder"),e[4]=r?.admin?.placeholder,e[5]=n,e[6]=a):a=e[6],c=Qe(ho,{"aria-placeholder":n("lexical:general:placeholder"),className:o??"ContentEditable__root",placeholder:Qe("p",{className:"editor-placeholder",children:a})}),e[0]=o,e[1]=r?.admin?.placeholder,e[2]=n,e[3]=c}else c=e[3];return c}var et=t=>{let e=xo(19),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:c}=t,a=P(),[s]=Eo(),[d,x]=So(null),g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=u=>{u!==null&&x(u)},e[0]=g):g=e[0];let l=g,i,p;e[1]!==s||e[2]!==a?(i=()=>{if(!a?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}a?.parentEditor?.uuid&&a.parentEditor?.registerChild(a.uuid,a);let u=()=>{a.focusEditor(a)},h=()=>{a.blurEditor(a)},m=s.registerCommand(wo,()=>(u(),!0),Ze),f=s.registerCommand(Ro,()=>(h(),!0),Ze);return()=>{m(),f(),a.parentEditor?.unregisterChild?.(a.uuid)}},p=[s,a],e[1]=s,e[2]=a,e[3]=i,e[4]=p):(i=e[3],p=e[4]),To(i,p);let y;if(e[5]!==s||e[6]!==o||e[7]!==r||e[8]!==d||e[9]!==n||e[10]!==c){let u;e[12]!==c?(u=(m,f,E)=>{(!E.has("focus")||E.size>1)&&c?.(m,f,E)},e[12]=c,e[13]=u):u=e[13];let h;e[14]!==s||e[15]!==o.features.plugins||e[16]!==d||e[17]!==n?(h=d&&Q(J.Fragment,{children:[!n&&s.isEditable()&&Q(J.Fragment,{children:[b(He,{anchorElem:d}),b(Me,{anchorElem:d})]}),o.features.plugins?.map(m=>{if(m.position==="floatingAnchorElem"&&!(m.desktopOnly===!0&&n))return b(H,{anchorElem:d,clientProps:m.clientProps,plugin:m},m.key)}),s.isEditable()&&b(J.Fragment,{children:b(Je,{anchorElem:d})})]}),e[14]=s,e[15]=o.features.plugins,e[16]=d,e[17]=n,e[18]=h):h=e[18],y=Q(J.Fragment,{children:[o.features.plugins?.map(ko),Q("div",{className:"editor-container",ref:r,children:[o.features.plugins?.map(vo),b(Po,{contentEditable:b("div",{className:"editor-scroller",children:b("div",{className:"editor",ref:l,children:b(Xe,{editorConfig:o})})}),ErrorBoundary:Co}),b(Ke,{}),b(we,{}),b(qe,{features:o.features}),b(No,{ignoreSelectionChange:!0,onChange:u}),h,s.isEditable()&&Q(J.Fragment,{children:[b(bo,{}),o?.features?.markdownTransformers?.length>0&&b(We,{})]}),o.features.plugins?.map(Mo),o.features.plugins?.map(Io)]}),o.features.plugins?.map(Lo)]}),e[5]=s,e[6]=o,e[7]=r,e[8]=d,e[9]=n,e[10]=c,e[11]=y}else y=e[11];return y};function ko(t){if(t.position==="aboveContainer")return b(H,{clientProps:t.clientProps,plugin:t},t.key)}function vo(t){if(t.position==="top")return b(H,{clientProps:t.clientProps,plugin:t},t.key)}function Mo(t){if(t.position==="normal")return b(H,{clientProps:t.clientProps,plugin:t},t.key)}function Io(t){if(t.position==="bottom")return b(H,{clientProps:t.clientProps,plugin:t},t.key)}function Lo(t){if(t.position==="belowContainer")return b(H,{clientProps:t.clientProps,plugin:t},t.key)}var ot=({children:t,providers:e})=>{if(!e?.length)return t;let o=e[0];return e.length>1?F(o,{children:F(ot,{providers:e.slice(1),children:t})}):F(o,{children:t})},nt=t=>{let{composerKey:e,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:c,readOnly:a,value:s}=t,d=P(),x=Do(),g=tt.useRef(null),l=Bo(()=>{if(s&&typeof s!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(s));if(s&&Array.isArray(s)&&!("root"in s))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(s&&"jsonContent"in s)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");return{editable:a!==!0,editorState:s!=null?JSON.stringify(s):void 0,namespace:o.lexical.namespace,nodes:Ne({editorConfig:o}),onError:i=>{throw i},theme:o.lexical.theme}},[o]);return l?F(Ao,{initialConfig:l,children:F(he,{editorConfig:o,editorContainerRef:g,fieldProps:r,parentContext:d?.editDepth===x?d:void 0,children:F(ot,{providers:o.features.providers,children:F(et,{editorConfig:o,editorContainerRef:g,isSmallWidthViewport:n,onChange:c})})})},e+l.editable):F("p",{children:"Loading..."})};var se="rich-text-lexical",Wo=t=>{let{editorConfig:e,field:o,field:{name:r,admin:{className:n,description:c,readOnly:a}={},label:s,localized:d,required:x},path:g,readOnly:l,validate:i}=t,p=l||a,y=g??r,u=$o(),h=st((_,$)=>typeof i=="function"?i(_,{...$,required:x}):!0,[i,x]),{customComponents:{AfterInput:m,BeforeInput:f,Description:E,Error:T,Label:w}={},formInitializing:R,formProcessing:S,initialValue:C,setValue:z,showError:A,value:v}=Ho({path:y,validate:h}),k=p||S||R,[D,ae]=at(!1),[ge,ce]=at(),de=it.useRef(C),X=it.useRef(v);lt(()=>{let _=()=>{let $=window.matchMedia("(max-width: 768px)").matches;$!==D&&ae($)};return _(),window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_)}},[D]);let M=[se,"field-type",n,A&&"error",k&&`${se}--read-only`,e?.admin?.hideGutter!==!0&&!D?`${se}--show-gutter`:null].filter(Boolean).join(" "),N=`${y}.${u}`,ct=st(_=>{let $=_.toJSON();X.current=$,z($)},[z]),dt=Ko(()=>jo(o),[o]);return lt(()=>{JSON.stringify(C)!==JSON.stringify(de.current)&&(de.current=C,JSON.stringify(X.current)!==JSON.stringify(v)&&ce(new Date))},[C,v]),le("div",{className:M,style:dt,children:[O(rt,{CustomComponent:T,Fallback:O(Oo,{path:y,showError:A})}),w||O(_o,{label:s,localized:d,path:y,required:x}),le("div",{className:`${se}__wrap`,children:[le(zo,{fallbackRender:Yo,onReset:()=>{},children:[f,O(nt,{composerKey:N,editorConfig:e,fieldProps:t,isSmallWidthViewport:D,onChange:ct,readOnly:k,value:v},JSON.stringify({path:y,rerenderProviderKey:ge})),m]}),E,O(rt,{CustomComponent:E,Fallback:O(Fo,{description:c,path:y})})]})]},N)};function Yo({error:t}){return le("div",{className:"errorBoundary",role:"alert",children:[O("p",{children:"Something went wrong:"}),O("pre",{style:{color:"red"},children:t.message})]})}var xi=Wo;export{xi as RichText};
|
|
2
|
-
//# sourceMappingURL=Field-LOLYH42M.js.map
|