@payloadcms/richtext-lexical 3.0.0-beta.119 → 3.0.0-beta.120

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 (57) hide show
  1. package/dist/exports/client/RelationshipComponent-LBWKOBGF.js +2 -0
  2. package/dist/exports/client/RelationshipComponent-LBWKOBGF.js.map +7 -0
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/chunk-5PBXL4HT.js +2 -0
  5. package/dist/exports/client/chunk-5PBXL4HT.js.map +7 -0
  6. package/dist/exports/client/chunk-7SR2HYD6.js +2 -0
  7. package/dist/exports/client/chunk-7SR2HYD6.js.map +7 -0
  8. package/dist/exports/client/{chunk-QZNJUROL.js → chunk-XY4TCSM7.js} +2 -2
  9. package/dist/exports/client/component-4TP4L5EV.js +2 -0
  10. package/dist/exports/client/component-4TP4L5EV.js.map +7 -0
  11. package/dist/exports/client/index.js +7 -7
  12. package/dist/exports/client/index.js.map +4 -4
  13. package/dist/features/blocks/client/plugin/index.d.ts.map +1 -1
  14. package/dist/features/blocks/client/plugin/index.js +32 -37
  15. package/dist/features/blocks/client/plugin/index.js.map +1 -1
  16. package/dist/features/experimental_table/client/plugins/TablePlugin/index.d.ts.map +1 -1
  17. package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +27 -32
  18. package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
  19. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  20. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +8 -9
  21. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  22. package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
  23. package/dist/features/relationship/client/components/RelationshipComponent.js +10 -7
  24. package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
  25. package/dist/features/relationship/client/drawer/index.d.ts.map +1 -1
  26. package/dist/features/relationship/client/drawer/index.js +24 -23
  27. package/dist/features/relationship/client/drawer/index.js.map +1 -1
  28. package/dist/features/upload/client/component/index.d.ts.map +1 -1
  29. package/dist/features/upload/client/component/index.js +30 -28
  30. package/dist/features/upload/client/component/index.js.map +1 -1
  31. package/dist/features/upload/client/drawer/index.d.ts.map +1 -1
  32. package/dist/features/upload/client/drawer/index.js +32 -32
  33. package/dist/features/upload/client/drawer/index.js.map +1 -1
  34. package/dist/field/bundled.css +1 -1
  35. package/dist/utilities/fieldsDrawer/Drawer.d.ts.map +1 -1
  36. package/dist/utilities/fieldsDrawer/Drawer.js +63 -27
  37. package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
  38. package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.d.ts +13 -0
  39. package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.d.ts.map +1 -0
  40. package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js +129 -0
  41. package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js.map +1 -0
  42. package/dist/utilities/fieldsDrawer/useLexicalDrawer.d.ts +10 -0
  43. package/dist/utilities/fieldsDrawer/useLexicalDrawer.d.ts.map +1 -0
  44. package/dist/utilities/fieldsDrawer/useLexicalDrawer.js +136 -0
  45. package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -0
  46. package/dist/utilities/fieldsDrawer/useLexicalListDrawer.d.ts +16 -0
  47. package/dist/utilities/fieldsDrawer/useLexicalListDrawer.d.ts.map +1 -0
  48. package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js +144 -0
  49. package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js.map +1 -0
  50. package/package.json +7 -7
  51. package/dist/exports/client/RelationshipComponent-FTWR5YDX.js +0 -2
  52. package/dist/exports/client/RelationshipComponent-FTWR5YDX.js.map +0 -7
  53. package/dist/exports/client/chunk-WAMTSCVM.js +0 -2
  54. package/dist/exports/client/chunk-WAMTSCVM.js.map +0 -7
  55. package/dist/exports/client/component-6PBZ2U3Z.js +0 -2
  56. package/dist/exports/client/component-6PBZ2U3Z.js.map +0 -7
  57. /package/dist/exports/client/{chunk-QZNJUROL.js.map → chunk-XY4TCSM7.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/Drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGvE,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,WAAW,EAAE,CAAA;IACzC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAA;IAC1E,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAA;IAC1C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACnC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAyBpD,CAAA"}
1
+ {"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/Drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGvE,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,WAAW,EAAE,CAAA;IACzC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAA;IAC1E,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAA;IAC1C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACnC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAsCpD,CAAA"}
@@ -1,7 +1,8 @@
1
1
  'use client';
2
2
 
3
+ import { c as _c } from "react/compiler-runtime";
3
4
  import { jsx as _jsx } from "react/jsx-runtime";
4
- import { Drawer } from '@payloadcms/ui';
5
+ import { Drawer, useModal } from '@payloadcms/ui';
5
6
  import React from 'react';
6
7
  import { DrawerContent } from './DrawerContent.js';
7
8
  /**
@@ -9,31 +10,66 @@ import { DrawerContent } from './DrawerContent.js';
9
10
  * The fields are taken directly from the schema map based on your `featureKey` and `schemaPathSuffix`. Thus, this can only
10
11
  * be used if you provide your field schema inside the `generateSchemaMap` prop of your feature.server.ts.
11
12
  */
12
- export const FieldsDrawer = ({
13
- className,
14
- data,
15
- drawerSlug,
16
- drawerTitle,
17
- featureKey,
18
- fieldMapOverride,
19
- handleDrawerSubmit,
20
- schemaFieldsPathOverride,
21
- schemaPathSuffix
22
- }) => {
23
- // The Drawer only renders its children (and itself) if it's open. Thus, by extracting the main content
24
- // to DrawerContent, this should be faster
25
- return /*#__PURE__*/_jsx(Drawer, {
26
- className: className,
27
- slug: drawerSlug,
28
- title: drawerTitle ?? '',
29
- children: /*#__PURE__*/_jsx(DrawerContent, {
30
- data: data,
31
- featureKey: featureKey,
32
- fieldMapOverride: fieldMapOverride,
33
- handleDrawerSubmit: handleDrawerSubmit,
34
- schemaFieldsPathOverride: schemaFieldsPathOverride,
35
- schemaPathSuffix: schemaPathSuffix
36
- })
37
- });
13
+ export const FieldsDrawer = t0 => {
14
+ const $ = _c(14);
15
+ const {
16
+ className,
17
+ data,
18
+ drawerSlug,
19
+ drawerTitle,
20
+ featureKey,
21
+ fieldMapOverride,
22
+ handleDrawerSubmit,
23
+ schemaFieldsPathOverride,
24
+ schemaPathSuffix
25
+ } = t0;
26
+ const {
27
+ closeModal
28
+ } = useModal();
29
+ const t1 = drawerTitle ?? "";
30
+ let t2;
31
+ if ($[0] !== closeModal || $[1] !== drawerSlug || $[2] !== handleDrawerSubmit) {
32
+ t2 = (args, args2) => {
33
+ closeModal(drawerSlug);
34
+ setTimeout(() => {
35
+ handleDrawerSubmit(args, args2);
36
+ }, 1);
37
+ };
38
+ $[0] = closeModal;
39
+ $[1] = drawerSlug;
40
+ $[2] = handleDrawerSubmit;
41
+ $[3] = t2;
42
+ } else {
43
+ t2 = $[3];
44
+ }
45
+ let t3;
46
+ if ($[4] !== data || $[5] !== featureKey || $[6] !== fieldMapOverride || $[7] !== t2 || $[8] !== schemaFieldsPathOverride || $[9] !== schemaPathSuffix || $[10] !== className || $[11] !== drawerSlug || $[12] !== t1) {
47
+ t3 = _jsx(Drawer, {
48
+ className,
49
+ slug: drawerSlug,
50
+ title: t1,
51
+ children: _jsx(DrawerContent, {
52
+ data,
53
+ featureKey,
54
+ fieldMapOverride,
55
+ handleDrawerSubmit: t2,
56
+ schemaFieldsPathOverride,
57
+ schemaPathSuffix
58
+ })
59
+ });
60
+ $[4] = data;
61
+ $[5] = featureKey;
62
+ $[6] = fieldMapOverride;
63
+ $[7] = t2;
64
+ $[8] = schemaFieldsPathOverride;
65
+ $[9] = schemaPathSuffix;
66
+ $[10] = className;
67
+ $[11] = drawerSlug;
68
+ $[12] = t1;
69
+ $[13] = t3;
70
+ } else {
71
+ t3 = $[13];
72
+ }
73
+ return t3;
38
74
  };
39
75
  //# sourceMappingURL=Drawer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Drawer.js","names":["Drawer","React","DrawerContent","FieldsDrawer","className","data","drawerSlug","drawerTitle","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPathSuffix","_jsx","slug","title"],"sources":["../../../src/utilities/fieldsDrawer/Drawer.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Data, FormState, JsonObject } from 'payload'\n\nimport { Drawer } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { DrawerContent } from './DrawerContent.js'\n\nexport type FieldsDrawerProps = {\n readonly className?: string\n readonly data?: Data\n readonly drawerSlug: string\n readonly drawerTitle?: string\n readonly featureKey: string\n readonly fieldMapOverride?: ClientField[]\n readonly handleDrawerSubmit: (fields: FormState, data: JsonObject) => void\n readonly schemaFieldsPathOverride?: string\n readonly schemaPathSuffix?: string\n}\n\n/**\n * This FieldsDrawer component can be used to easily create a Drawer that contains a form with fields within your feature.\n * The fields are taken directly from the schema map based on your `featureKey` and `schemaPathSuffix`. Thus, this can only\n * be used if you provide your field schema inside the `generateSchemaMap` prop of your feature.server.ts.\n */\nexport const FieldsDrawer: React.FC<FieldsDrawerProps> = ({\n className,\n data,\n drawerSlug,\n drawerTitle,\n featureKey,\n fieldMapOverride,\n handleDrawerSubmit,\n schemaFieldsPathOverride,\n schemaPathSuffix,\n}) => {\n // The Drawer only renders its children (and itself) if it's open. Thus, by extracting the main content\n // to DrawerContent, this should be faster\n return (\n <Drawer className={className} slug={drawerSlug} title={drawerTitle ?? ''}>\n <DrawerContent\n data={data}\n featureKey={featureKey}\n fieldMapOverride={fieldMapOverride}\n handleDrawerSubmit={handleDrawerSubmit}\n schemaFieldsPathOverride={schemaFieldsPathOverride}\n schemaPathSuffix={schemaPathSuffix}\n />\n </Drawer>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,MAAM,QAAQ;AACvB,OAAOC,KAAA,MAAW;AAElB,SAASC,aAAa,QAAQ;AAc9B;;;;;AAKA,OAAO,MAAMC,YAAA,GAA4CA,CAAC;EACxDC,SAAS;EACTC,IAAI;EACJC,UAAU;EACVC,WAAW;EACXC,UAAU;EACVC,gBAAgB;EAChBC,kBAAkB;EAClBC,wBAAwB;EACxBC;AAAgB,CACjB;EACC;EACA;EACA,oBACEC,IAAA,CAACb,MAAA;IAAOI,SAAA,EAAWA,SAAA;IAAWU,IAAA,EAAMR,UAAA;IAAYS,KAAA,EAAOR,WAAA,IAAe;cACpE,aAAAM,IAAA,CAACX,aAAA;MACCG,IAAA,EAAMA,IAAA;MACNG,UAAA,EAAYA,UAAA;MACZC,gBAAA,EAAkBA,gBAAA;MAClBC,kBAAA,EAAoBA,kBAAA;MACpBC,wBAAA,EAA0BA,wBAAA;MAC1BC,gBAAA,EAAkBA;;;AAI1B","ignoreList":[]}
1
+ {"version":3,"file":"Drawer.js","names":["c","_c","Drawer","useModal","React","DrawerContent","FieldsDrawer","t0","$","className","data","drawerSlug","drawerTitle","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPathSuffix","closeModal","t1","t2","args","args2","setTimeout","t3","_jsx","slug","title","children"],"sources":["../../../src/utilities/fieldsDrawer/Drawer.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Data, FormState, JsonObject } from 'payload'\n\nimport { Drawer, useModal } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { DrawerContent } from './DrawerContent.js'\n\nexport type FieldsDrawerProps = {\n readonly className?: string\n readonly data?: Data\n readonly drawerSlug: string\n readonly drawerTitle?: string\n readonly featureKey: string\n readonly fieldMapOverride?: ClientField[]\n readonly handleDrawerSubmit: (fields: FormState, data: JsonObject) => void\n readonly schemaFieldsPathOverride?: string\n readonly schemaPathSuffix?: string\n}\n\n/**\n * This FieldsDrawer component can be used to easily create a Drawer that contains a form with fields within your feature.\n * The fields are taken directly from the schema map based on your `featureKey` and `schemaPathSuffix`. Thus, this can only\n * be used if you provide your field schema inside the `generateSchemaMap` prop of your feature.server.ts.\n */\nexport const FieldsDrawer: React.FC<FieldsDrawerProps> = ({\n className,\n data,\n drawerSlug,\n drawerTitle,\n featureKey,\n fieldMapOverride,\n handleDrawerSubmit,\n schemaFieldsPathOverride,\n schemaPathSuffix,\n}) => {\n const { closeModal } = useModal()\n // The Drawer only renders its children (and itself) if it's open. Thus, by extracting the main content\n // to DrawerContent, this should be faster\n return (\n <Drawer className={className} slug={drawerSlug} title={drawerTitle ?? ''}>\n <DrawerContent\n data={data}\n featureKey={featureKey}\n fieldMapOverride={fieldMapOverride}\n handleDrawerSubmit={(args, args2) => {\n // Simply close drawer - no need for useLexicalDrawer here as at this point,\n // we don't need to restore the cursor position. This is handled by the useEffect in useLexicalDrawer.\n closeModal(drawerSlug)\n\n // Actual drawer submit logic needs to be triggered after the drawer is closed.\n // That's because the lexical selection / cursor restore logic that is striggerer by\n // `useLexicalDrawer` neeeds to be triggered before any editor.update calls that may happen\n // in the `handleDrawerSubmit` function.\n setTimeout(() => {\n handleDrawerSubmit(args, args2)\n }, 1)\n }}\n schemaFieldsPathOverride={schemaFieldsPathOverride}\n schemaPathSuffix={schemaPathSuffix}\n />\n </Drawer>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,MAAM,EAAEC,QAAQ,QAAQ;AACjC,OAAOC,KAAA,MAAW;AAElB,SAASC,aAAa,QAAQ;AAc9B;;;;;AAKA,OAAO,MAAMC,YAAA,GAA4CC,EAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EAAC;IAAAQ,SAAA;IAAAC,IAAA;IAAAC,UAAA;IAAAC,WAAA;IAAAC,UAAA;IAAAC,gBAAA;IAAAC,kBAAA;IAAAC,wBAAA;IAAAC;EAAA,IAAAV,EAUzD;EACC;IAAAW;EAAA,IAAuBf,QAAA;EAIkC,MAAAgB,EAAA,GAAAP,WAAA,IAAe;EAAA,IAAAQ,EAAA;EAAA,IAAAZ,CAAA,QAAAU,UAAA,IAAAV,CAAA,QAAAG,UAAA,IAAAH,CAAA,QAAAO,kBAAA;IAK9CK,EAAA,GAAAA,CAAAC,IAAA,EAAAC,KAAA;MAGlBJ,UAAA,CAAWP,UAAA;MAMXY,UAAA;QACER,kBAAA,CAAmBM,IAAA,EAAMC,KAAA;MAAA,IACxB;IAAA;IACLd,CAAA,MAAAU,UAAA;IAAAV,CAAA,MAAAG,UAAA;IAAAH,CAAA,MAAAO,kBAAA;IAAAP,CAAA,MAAAY,EAAA;EAAA;IAAAA,EAAA,GAAAZ,CAAA;EAAA;EAAA,IAAAgB,EAAA;EAAA,IAAAhB,CAAA,QAAAE,IAAA,IAAAF,CAAA,QAAAK,UAAA,IAAAL,CAAA,QAAAM,gBAAA,IAAAN,CAAA,QAAAY,EAAA,IAAAZ,CAAA,QAAAQ,wBAAA,IAAAR,CAAA,QAAAS,gBAAA,IAAAT,CAAA,SAAAC,SAAA,IAAAD,CAAA,SAAAG,UAAA,IAAAH,CAAA,SAAAW,EAAA;IAjBJK,EAAA,GAAAC,IAAA,CAAAvB,MAAA;MAAAO,SAAA;MAAAiB,IAAA,EAAoCf,UAAA;MAAAgB,KAAA,EAAmBR,EAAe;MAAAS,QAAA,EACpEH,IAAA,CAAApB,aAAA;QAAAK,IAAA;QAAAG,UAAA;QAAAC,gBAAA;QAAAC,kBAAA,EAIsBK,EAYpB;QAAAJ,wBAAA;QAAAC;MAAA,C;;;;;;;;;;;;;;;SAjBJO,E;CAuBJ","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { UseDocumentDrawer } from '@payloadcms/ui';
2
+ /**
3
+ *
4
+ * Wrapper around useDocumentDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.
5
+ * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.
6
+ */
7
+ export declare const useLexicalDocumentDrawer: (args: Parameters<UseDocumentDrawer>[0]) => {
8
+ closeDocumentDrawer: () => void;
9
+ DocumentDrawer: ReturnType<UseDocumentDrawer>[0];
10
+ documentDrawerSlug: string;
11
+ DocumentDrawerToggler: ReturnType<UseDocumentDrawer>[1];
12
+ };
13
+ //# sourceMappingURL=useLexicalDocumentDrawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLexicalDocumentDrawer.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/useLexicalDocumentDrawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAQvD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,SAC7B,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KACrC;IACD,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAC/B,cAAc,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,kBAAkB,EAAE,MAAM,CAAA;IAC1B,qBAAqB,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;CA4DxD,CAAA"}
@@ -0,0 +1,129 @@
1
+ 'use client';
2
+
3
+ import { c as _c } from "react/compiler-runtime";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
6
+ import { useDocumentDrawer, useModal } from '@payloadcms/ui';
7
+ import { $getPreviousSelection, $getSelection, $setSelection } from 'lexical';
8
+ import { useCallback, useEffect, useState } from 'react';
9
+ /**
10
+ *
11
+ * Wrapper around useDocumentDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.
12
+ * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.
13
+ */
14
+ export const useLexicalDocumentDrawer = args => {
15
+ const $ = _c(21);
16
+ const [editor] = useLexicalComposerContext();
17
+ const [selectionState, setSelectionState] = useState(null);
18
+ const [wasOpen, setWasOpen] = useState(false);
19
+ const [DocumentDrawer, DocumentDrawerToggler, t0] = useDocumentDrawer(args);
20
+ const {
21
+ closeDrawer,
22
+ drawerSlug: documentDrawerSlug
23
+ } = t0;
24
+ const {
25
+ modalState
26
+ } = useModal();
27
+ let t1;
28
+ if ($[0] !== editor) {
29
+ t1 = () => {
30
+ editor.read(() => {
31
+ const selection = $getSelection() ?? $getPreviousSelection();
32
+ setSelectionState(selection);
33
+ });
34
+ setWasOpen(true);
35
+ };
36
+ $[0] = editor;
37
+ $[1] = t1;
38
+ } else {
39
+ t1 = $[1];
40
+ }
41
+ const storeSelection = t1;
42
+ let t2;
43
+ if ($[2] !== selectionState || $[3] !== editor) {
44
+ t2 = () => {
45
+ if (selectionState) {
46
+ editor.update(() => {
47
+ $setSelection(selectionState.clone());
48
+ }, {
49
+ discrete: true,
50
+ skipTransforms: true
51
+ });
52
+ }
53
+ };
54
+ $[2] = selectionState;
55
+ $[3] = editor;
56
+ $[4] = t2;
57
+ } else {
58
+ t2 = $[4];
59
+ }
60
+ const restoreSelection = t2;
61
+ let t3;
62
+ if ($[5] !== closeDrawer) {
63
+ t3 = () => {
64
+ closeDrawer();
65
+ };
66
+ $[5] = closeDrawer;
67
+ $[6] = t3;
68
+ } else {
69
+ t3 = $[6];
70
+ }
71
+ const closeDocumentDrawer = t3;
72
+ let t4;
73
+ let t5;
74
+ if ($[7] !== wasOpen || $[8] !== modalState || $[9] !== documentDrawerSlug || $[10] !== restoreSelection) {
75
+ t4 = () => {
76
+ if (!wasOpen) {
77
+ return;
78
+ }
79
+ const thisModalState = modalState[documentDrawerSlug];
80
+ if (thisModalState && !thisModalState?.isOpen) {
81
+ setWasOpen(false);
82
+ setTimeout(() => {
83
+ restoreSelection();
84
+ }, 1);
85
+ }
86
+ };
87
+ t5 = [modalState, documentDrawerSlug, restoreSelection, wasOpen];
88
+ $[7] = wasOpen;
89
+ $[8] = modalState;
90
+ $[9] = documentDrawerSlug;
91
+ $[10] = restoreSelection;
92
+ $[11] = t4;
93
+ $[12] = t5;
94
+ } else {
95
+ t4 = $[11];
96
+ t5 = $[12];
97
+ }
98
+ useEffect(t4, t5);
99
+ let t6;
100
+ if ($[13] !== DocumentDrawerToggler || $[14] !== storeSelection) {
101
+ t6 = props => _jsx(DocumentDrawerToggler, {
102
+ ...props,
103
+ onClick: storeSelection
104
+ });
105
+ $[13] = DocumentDrawerToggler;
106
+ $[14] = storeSelection;
107
+ $[15] = t6;
108
+ } else {
109
+ t6 = $[15];
110
+ }
111
+ let t7;
112
+ if ($[16] !== closeDocumentDrawer || $[17] !== DocumentDrawer || $[18] !== documentDrawerSlug || $[19] !== t6) {
113
+ t7 = {
114
+ closeDocumentDrawer,
115
+ DocumentDrawer,
116
+ documentDrawerSlug,
117
+ DocumentDrawerToggler: t6
118
+ };
119
+ $[16] = closeDocumentDrawer;
120
+ $[17] = DocumentDrawer;
121
+ $[18] = documentDrawerSlug;
122
+ $[19] = t6;
123
+ $[20] = t7;
124
+ } else {
125
+ t7 = $[20];
126
+ }
127
+ return t7;
128
+ };
129
+ //# sourceMappingURL=useLexicalDocumentDrawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLexicalDocumentDrawer.js","names":["c","_c","useLexicalComposerContext","useDocumentDrawer","useModal","$getPreviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalDocumentDrawer","args","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","DocumentDrawer","DocumentDrawerToggler","t0","closeDrawer","drawerSlug","documentDrawerSlug","modalState","t1","read","selection","storeSelection","t2","update","clone","discrete","skipTransforms","restoreSelection","t3","closeDocumentDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6","props","_jsx","onClick","t7"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalDocumentDrawer.tsx"],"sourcesContent":["'use client'\nimport type { UseDocumentDrawer } from '@payloadcms/ui'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useDocumentDrawer, useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useDocumentDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalDocumentDrawer = (\n args: Parameters<UseDocumentDrawer>[0],\n): {\n closeDocumentDrawer: () => void\n DocumentDrawer: ReturnType<UseDocumentDrawer>[0]\n documentDrawerSlug: string\n DocumentDrawerToggler: ReturnType<UseDocumentDrawer>[1]\n} => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const [\n DocumentDrawer,\n DocumentDrawerToggler,\n { closeDrawer: closeDrawer, drawerSlug: documentDrawerSlug },\n ] = useDocumentDrawer(args)\n const { modalState } = useModal()\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n })\n setWasOpen(true)\n }, [editor])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeDocumentDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n closeDrawer()\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[documentDrawerSlug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n setTimeout(() => {\n restoreSelection()\n }, 1)\n }\n }, [modalState, documentDrawerSlug, restoreSelection, wasOpen])\n\n return {\n closeDocumentDrawer,\n DocumentDrawer,\n documentDrawerSlug,\n DocumentDrawerToggler: (props) => <DocumentDrawerToggler {...props} onClick={storeSelection} />,\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,iBAAiB,EAAEC,QAAQ,QAAQ;AAC5C,SAASC,qBAAqB,EAAEC,aAAa,EAAEC,aAAa,QAAQ;AACpE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,wBAAA,GAA2BC,IAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAQtC,OAAAa,MAAA,IAAiBZ,yBAAA;EACjB,OAAAa,cAAA,EAAAC,iBAAA,IAA4CN,QAAA,KAA+B;EAC3E,OAAAO,OAAA,EAAAC,UAAA,IAA8BR,QAAA,MAAkB;EAEhD,OAAAS,cAAA,EAAAC,qBAAA,EAAAC,EAAA,IAIIlB,iBAAA,CAAkBS,IAAA;EADpB;IAAAU,WAAA;IAAAC,UAAA,EAAAC;EAAA,IAAAH,EAA4D;EAE9D;IAAAI;EAAA,IAAuBrB,QAAA;EAAA,IAAAsB,EAAA;EAAA,IAAAb,CAAA,QAAAC,MAAA;IAEYY,EAAA,GAAAA,CAAA;MACjCZ,MAAA,CAAAa,IAAA;QACE,MAAAC,SAAA,GAAkBtB,aAAA,MAAmBD,qBAAA;QACrCW,iBAAA,CAAkBY,SAAA;MAAA,CACpB;MACAV,UAAA,KAAW;IAAA;IACbL,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAa,EAAA;EAAA;IAAAA,EAAA,GAAAb,CAAA;EAAA;EANA,MAAAgB,cAAA,GAAuBH,EAMZ;EAAA,IAAAI,EAAA;EAAA,IAAAjB,CAAA,QAAAE,cAAA,IAAAF,CAAA,QAAAC,MAAA;I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AA0B,EAAA,GAAA1B,CAAA;EAAA;EAb9DJ,SAAA,CAAU6B,EAaV,EAAGC,EAA2D;EAAA,IAAAI,EAAA;EAAA,IAAA9B,CAAA,SAAAO,qBAAA,IAAAP,CAAA,SAAAgB,cAAA;IAMrCc,EAAA,GAAAC,KAAA,IAAWC,IAAA,CAACzB,qBAAA;MAAA,GAA0BwB,KAAK;MAAAE,OAAA,EAAWjB;IAAA,C;;;;;;;;;IAJxEkB,EAAA;MAAAV,mBAAA;MAAAlB,cAAA;MAAAK,kBAAA;MAAAJ,qBAAA,EAIkBuB;;IACzB9B,CAAA,OAAAwB,mBAAA;IAAAxB,CAAA,OAAAM,cAAA;IAAAN,CAAA,OAAAW,kBAAA;IAAAX,CAAA,OAAA8B,EAAA;IAAA9B,CAAA,OAAAkC,EAAA;EAAA;IAAAA,EAAA,GAAAlC,CAAA;EAAA;EAAA,OALOkC,EAKP;AAAA,CACF","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * Wrapper around useModal that restores and saves selection state (cursor position) when opening and closing the drawer.
4
+ * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.
5
+ */
6
+ export declare const useLexicalDrawer: (slug: string, restoreLate?: boolean) => {
7
+ closeDrawer: () => void;
8
+ toggleDrawer: () => void;
9
+ };
10
+ //# sourceMappingURL=useLexicalDrawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLexicalDrawer.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/useLexicalDrawer.tsx"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,SAAU,MAAM,gBAAgB,OAAO;;;CAwEnE,CAAA"}
@@ -0,0 +1,136 @@
1
+ 'use client';
2
+
3
+ import { c as _c } from "react/compiler-runtime";
4
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
5
+ import { useModal } from '@payloadcms/ui';
6
+ import { $getPreviousSelection, $getSelection, $setSelection } from 'lexical';
7
+ import { useCallback, useEffect, useState } from 'react';
8
+ /**
9
+ *
10
+ * Wrapper around useModal that restores and saves selection state (cursor position) when opening and closing the drawer.
11
+ * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.
12
+ */
13
+ export const useLexicalDrawer = (slug, restoreLate) => {
14
+ const $ = _c(24);
15
+ const [editor] = useLexicalComposerContext();
16
+ const [selectionState, setSelectionState] = useState(null);
17
+ const [wasOpen, setWasOpen] = useState(false);
18
+ const {
19
+ closeModal: closeBaseModal,
20
+ isModalOpen: isBaseModalOpen,
21
+ modalState,
22
+ toggleModal: toggleBaseModal
23
+ } = useModal();
24
+ let t0;
25
+ if ($[0] !== editor) {
26
+ t0 = () => {
27
+ editor.read(() => {
28
+ const selection = $getSelection() ?? $getPreviousSelection();
29
+ setSelectionState(selection);
30
+ });
31
+ };
32
+ $[0] = editor;
33
+ $[1] = t0;
34
+ } else {
35
+ t0 = $[1];
36
+ }
37
+ const storeSelection = t0;
38
+ let t1;
39
+ if ($[2] !== selectionState || $[3] !== editor) {
40
+ t1 = () => {
41
+ if (selectionState) {
42
+ editor.update(() => {
43
+ $setSelection(selectionState.clone());
44
+ }, {
45
+ discrete: true,
46
+ skipTransforms: true
47
+ });
48
+ }
49
+ };
50
+ $[2] = selectionState;
51
+ $[3] = editor;
52
+ $[4] = t1;
53
+ } else {
54
+ t1 = $[4];
55
+ }
56
+ const restoreSelection = t1;
57
+ let t2;
58
+ if ($[5] !== closeBaseModal || $[6] !== slug) {
59
+ t2 = () => {
60
+ closeBaseModal(slug);
61
+ };
62
+ $[5] = closeBaseModal;
63
+ $[6] = slug;
64
+ $[7] = t2;
65
+ } else {
66
+ t2 = $[7];
67
+ }
68
+ const closeDrawer = t2;
69
+ let t3;
70
+ if ($[8] !== isBaseModalOpen || $[9] !== slug || $[10] !== storeSelection || $[11] !== restoreSelection || $[12] !== toggleBaseModal) {
71
+ t3 = () => {
72
+ if (!isBaseModalOpen(slug)) {
73
+ storeSelection();
74
+ } else {
75
+ restoreSelection();
76
+ }
77
+ setWasOpen(true);
78
+ toggleBaseModal(slug);
79
+ };
80
+ $[8] = isBaseModalOpen;
81
+ $[9] = slug;
82
+ $[10] = storeSelection;
83
+ $[11] = restoreSelection;
84
+ $[12] = toggleBaseModal;
85
+ $[13] = t3;
86
+ } else {
87
+ t3 = $[13];
88
+ }
89
+ const toggleDrawer = t3;
90
+ let t4;
91
+ let t5;
92
+ if ($[14] !== wasOpen || $[15] !== modalState || $[16] !== slug || $[17] !== restoreLate || $[18] !== restoreSelection) {
93
+ t4 = () => {
94
+ if (!wasOpen) {
95
+ return;
96
+ }
97
+ const thisModalState = modalState[slug];
98
+ if (thisModalState && !thisModalState?.isOpen) {
99
+ setWasOpen(false);
100
+ if (restoreLate) {
101
+ setTimeout(() => {
102
+ restoreSelection();
103
+ }, 1);
104
+ } else {
105
+ restoreSelection();
106
+ }
107
+ }
108
+ };
109
+ t5 = [modalState, slug, restoreSelection, wasOpen, restoreLate];
110
+ $[14] = wasOpen;
111
+ $[15] = modalState;
112
+ $[16] = slug;
113
+ $[17] = restoreLate;
114
+ $[18] = restoreSelection;
115
+ $[19] = t4;
116
+ $[20] = t5;
117
+ } else {
118
+ t4 = $[19];
119
+ t5 = $[20];
120
+ }
121
+ useEffect(t4, t5);
122
+ let t6;
123
+ if ($[21] !== closeDrawer || $[22] !== toggleDrawer) {
124
+ t6 = {
125
+ closeDrawer,
126
+ toggleDrawer
127
+ };
128
+ $[21] = closeDrawer;
129
+ $[22] = toggleDrawer;
130
+ $[23] = t6;
131
+ } else {
132
+ t6 = $[23];
133
+ }
134
+ return t6;
135
+ };
136
+ //# sourceMappingURL=useLexicalDrawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLexicalDrawer.js","names":["c","_c","useLexicalComposerContext","useModal","$getPreviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalDrawer","slug","restoreLate","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","closeModal","closeBaseModal","isModalOpen","isBaseModalOpen","modalState","toggleModal","toggleBaseModal","t0","read","selection","storeSelection","t1","update","clone","discrete","skipTransforms","restoreSelection","t2","closeDrawer","t3","toggleDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalDrawer.tsx"],"sourcesContent":["'use client'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useModal that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalDrawer = (slug: string, restoreLate?: boolean) => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const {\n closeModal: closeBaseModal,\n isModalOpen: isBaseModalOpen,\n modalState,\n toggleModal: toggleBaseModal,\n } = useModal()\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n })\n }, [editor])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n closeBaseModal(slug)\n }\n\n const toggleDrawer = () => {\n if (!isBaseModalOpen(slug)) {\n storeSelection()\n } else {\n restoreSelection()\n }\n setWasOpen(true)\n toggleBaseModal(slug)\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[slug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n\n if (restoreLate) {\n // restoreLate is used for upload extra field drawers. For some reason, the selection is not restored if we call restoreSelection immediately.\n setTimeout(() => {\n restoreSelection()\n }, 1)\n } else {\n restoreSelection()\n }\n }\n }, [modalState, slug, restoreSelection, wasOpen, restoreLate])\n\n return {\n closeDrawer,\n toggleDrawer,\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,QAAQ,QAAQ;AACzB,SAASC,qBAAqB,EAAEC,aAAa,EAAEC,aAAa,QAAQ;AACpE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,gBAAA,GAAmBA,CAAAC,IAAA,EAAAC,WAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAC9B,OAAAa,MAAA,IAAiBZ,yBAAA;EACjB,OAAAa,cAAA,EAAAC,iBAAA,IAA4CP,QAAA,KAA+B;EAC3E,OAAAQ,OAAA,EAAAC,UAAA,IAA8BT,QAAA,MAAkB;EAEhD;IAAAU,UAAA,EAAAC,cAAA;IAAAC,WAAA,EAAAC,eAAA;IAAAC,UAAA;IAAAC,WAAA,EAAAC;EAAA,IAKItB,QAAA;EAAA,IAAAuB,EAAA;EAAA,IAAAb,CAAA,QAAAC,MAAA;IAE+BY,EAAA,GAAAA,CAAA;MACjCZ,MAAA,CAAAa,IAAA;QACE,MAAAC,SAAA,GAAkBvB,aAAA,MAAmBD,qBAAA;QACrCY,iBAAA,CAAkBY,SAAA;MAAA,CACpB;IAAA;IACFf,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAa,EAAA;EAAA;IAAAA,EAAA,GAAAb,CAAA;EAAA;EALA,MAAAgB,cAAA,GAAuBH,EAKZ;EAAA,IAAAI,EAAA;EAAA,I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'lexical';
3
+ /**
4
+ *
5
+ * Wrapper around useListDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.
6
+ * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.
7
+ */
8
+ export declare const useLexicalListDrawer: (args: Parameters<UseListDrawer>[0]) => {
9
+ closeListDrawer: () => void;
10
+ isListDrawerOpen: boolean;
11
+ ListDrawer: ReturnType<UseListDrawer>[0];
12
+ listDrawerSlug: string;
13
+ ListDrawerToggler: ReturnType<UseListDrawer>[1];
14
+ openListDrawer: (selection?: BaseSelection) => void;
15
+ };
16
+ //# sourceMappingURL=useLexicalListDrawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLexicalListDrawer.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/useLexicalListDrawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAO5C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SACzB,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KACjC;IACD,eAAe,EAAE,MAAM,IAAI,CAAA;IAC3B,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IACxC,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,cAAc,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAA;CA6EpD,CAAA"}
@@ -0,0 +1,144 @@
1
+ 'use client';
2
+
3
+ import { c as _c } from "react/compiler-runtime";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
6
+ import { useListDrawer, useModal } from '@payloadcms/ui';
7
+ import { $getPreviousSelection, $getSelection, $setSelection } from 'lexical';
8
+ import { useCallback, useEffect, useState } from 'react';
9
+ /**
10
+ *
11
+ * Wrapper around useListDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.
12
+ * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.
13
+ */
14
+ export const useLexicalListDrawer = args => {
15
+ const $ = _c(23);
16
+ const [editor] = useLexicalComposerContext();
17
+ const [selectionState, setSelectionState] = useState(null);
18
+ const [wasOpen, setWasOpen] = useState(false);
19
+ const [BaseListDrawer, BaseListDrawerToggler, t0] = useListDrawer(args);
20
+ const {
21
+ closeDrawer: baseCloseDrawer,
22
+ drawerSlug: listDrawerSlug,
23
+ isDrawerOpen,
24
+ openDrawer: baseOpenDrawer
25
+ } = t0;
26
+ const {
27
+ modalState
28
+ } = useModal();
29
+ let t1;
30
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31
+ t1 = () => {
32
+ const selection = $getSelection() ?? $getPreviousSelection();
33
+ setSelectionState(selection);
34
+ };
35
+ $[0] = t1;
36
+ } else {
37
+ t1 = $[0];
38
+ }
39
+ const $storeSelection = t1;
40
+ let t2;
41
+ if ($[1] !== selectionState || $[2] !== editor) {
42
+ t2 = () => {
43
+ if (selectionState) {
44
+ editor.update(() => {
45
+ $setSelection(selectionState.clone());
46
+ }, {
47
+ discrete: true,
48
+ skipTransforms: true
49
+ });
50
+ }
51
+ };
52
+ $[1] = selectionState;
53
+ $[2] = editor;
54
+ $[3] = t2;
55
+ } else {
56
+ t2 = $[3];
57
+ }
58
+ const restoreSelection = t2;
59
+ let t3;
60
+ if ($[4] !== baseCloseDrawer) {
61
+ t3 = () => {
62
+ baseCloseDrawer();
63
+ };
64
+ $[4] = baseCloseDrawer;
65
+ $[5] = t3;
66
+ } else {
67
+ t3 = $[5];
68
+ }
69
+ const closeListDrawer = t3;
70
+ let t4;
71
+ let t5;
72
+ if ($[6] !== wasOpen || $[7] !== modalState || $[8] !== listDrawerSlug || $[9] !== restoreSelection) {
73
+ t4 = () => {
74
+ if (!wasOpen) {
75
+ return;
76
+ }
77
+ const thisModalState = modalState[listDrawerSlug];
78
+ if (thisModalState && !thisModalState?.isOpen) {
79
+ setWasOpen(false);
80
+ setTimeout(() => {
81
+ restoreSelection();
82
+ }, 1);
83
+ }
84
+ };
85
+ t5 = [modalState, listDrawerSlug, restoreSelection, wasOpen];
86
+ $[6] = wasOpen;
87
+ $[7] = modalState;
88
+ $[8] = listDrawerSlug;
89
+ $[9] = restoreSelection;
90
+ $[10] = t4;
91
+ $[11] = t5;
92
+ } else {
93
+ t4 = $[10];
94
+ t5 = $[11];
95
+ }
96
+ useEffect(t4, t5);
97
+ let t6;
98
+ if ($[12] !== BaseListDrawerToggler) {
99
+ t6 = props => _jsx(BaseListDrawerToggler, {
100
+ ...props,
101
+ onClick: () => {
102
+ $storeSelection();
103
+ }
104
+ });
105
+ $[12] = BaseListDrawerToggler;
106
+ $[13] = t6;
107
+ } else {
108
+ t6 = $[13];
109
+ }
110
+ let t7;
111
+ if ($[14] !== baseOpenDrawer) {
112
+ t7 = () => {
113
+ $storeSelection();
114
+ baseOpenDrawer();
115
+ setWasOpen(true);
116
+ };
117
+ $[14] = baseOpenDrawer;
118
+ $[15] = t7;
119
+ } else {
120
+ t7 = $[15];
121
+ }
122
+ let t8;
123
+ if ($[16] !== closeListDrawer || $[17] !== isDrawerOpen || $[18] !== BaseListDrawer || $[19] !== listDrawerSlug || $[20] !== t6 || $[21] !== t7) {
124
+ t8 = {
125
+ closeListDrawer,
126
+ isListDrawerOpen: isDrawerOpen,
127
+ ListDrawer: BaseListDrawer,
128
+ listDrawerSlug,
129
+ ListDrawerToggler: t6,
130
+ openListDrawer: t7
131
+ };
132
+ $[16] = closeListDrawer;
133
+ $[17] = isDrawerOpen;
134
+ $[18] = BaseListDrawer;
135
+ $[19] = listDrawerSlug;
136
+ $[20] = t6;
137
+ $[21] = t7;
138
+ $[22] = t8;
139
+ } else {
140
+ t8 = $[22];
141
+ }
142
+ return t8;
143
+ };
144
+ //# sourceMappingURL=useLexicalListDrawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLexicalListDrawer.js","names":["c","_c","useLexicalComposerContext","useListDrawer","useModal","$getPreviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalListDrawer","args","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","BaseListDrawer","BaseListDrawerToggler","t0","closeDrawer","baseCloseDrawer","drawerSlug","listDrawerSlug","isDrawerOpen","openDrawer","baseOpenDrawer","modalState","t1","Symbol","for","selection","$storeSelection","t2","update","clone","discrete","skipTransforms","restoreSelection","t3","closeListDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6","props","_jsx","onClick","t7","t8","isListDrawerOpen","ListDrawer","ListDrawerToggler"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalListDrawer.tsx"],"sourcesContent":["'use client'\nimport type { UseListDrawer } from '@payloadcms/ui'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useListDrawer, useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useListDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalListDrawer = (\n args: Parameters<UseListDrawer>[0],\n): {\n closeListDrawer: () => void\n isListDrawerOpen: boolean\n ListDrawer: ReturnType<UseListDrawer>[0]\n listDrawerSlug: string\n ListDrawerToggler: ReturnType<UseListDrawer>[1]\n openListDrawer: (selection?: BaseSelection) => void\n} => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const [\n BaseListDrawer,\n BaseListDrawerToggler,\n {\n closeDrawer: baseCloseDrawer,\n drawerSlug: listDrawerSlug,\n isDrawerOpen,\n openDrawer: baseOpenDrawer,\n },\n ] = useListDrawer(args)\n const { modalState } = useModal()\n\n const $storeSelection = useCallback(() => {\n // editor.read() causes an error here when creating a new upload node from the slash menu. It seems like we can omit it here though, as all\n // invocations of that functions are wrapped in editor.read() or editor.update() somewhere in the call stack.\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n }, [])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeListDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n baseCloseDrawer()\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[listDrawerSlug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n setTimeout(() => {\n restoreSelection()\n }, 1)\n }\n }, [modalState, listDrawerSlug, restoreSelection, wasOpen])\n\n return {\n closeListDrawer,\n isListDrawerOpen: isDrawerOpen,\n ListDrawer: BaseListDrawer,\n listDrawerSlug,\n ListDrawerToggler: (props) => (\n <BaseListDrawerToggler\n {...props}\n onClick={() => {\n $storeSelection()\n }}\n />\n ),\n openListDrawer: () => {\n $storeSelection()\n baseOpenDrawer()\n setWasOpen(true)\n },\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,EAAEC,QAAQ,QAAQ;AACxC,SAASC,qBAAqB,EAAEC,aAAa,EAAEC,aAAa,QAAQ;AACpE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,oBAA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