@payloadcms/richtext-lexical 3.0.0-beta.54 → 3.0.0-beta.56

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 (176) hide show
  1. package/dist/exports/client/{RelationshipComponent-5OU5HATX.js → RelationshipComponent-AFXEJMZQ.js} +2 -2
  2. package/dist/exports/client/bundled.css +1 -1
  3. package/dist/exports/client/chunk-OAQL5GDK.js +2 -0
  4. package/dist/exports/client/chunk-OAQL5GDK.js.map +7 -0
  5. package/dist/exports/client/{chunk-MLIITFAS.js → chunk-Q5DYR7MH.js} +2 -2
  6. package/dist/exports/client/chunk-Q5DYR7MH.js.map +7 -0
  7. package/dist/exports/client/{chunk-OSR74ZNW.js → chunk-YL52LJO3.js} +2 -2
  8. package/dist/exports/client/chunk-YL52LJO3.js.map +7 -0
  9. package/dist/exports/client/component-V5QZ7EVZ.js +2 -0
  10. package/dist/exports/client/component-V5QZ7EVZ.js.map +7 -0
  11. package/dist/exports/client/{component-QWIGEOVD.js → component-VM36FRT2.js} +2 -2
  12. package/dist/exports/client/{component-PEFMKIXI.js → component-YNZTTMBY.js} +2 -2
  13. package/dist/exports/client/component-YNZTTMBY.js.map +7 -0
  14. package/dist/exports/client/index.d.ts +3 -1
  15. package/dist/exports/client/index.d.ts.map +1 -1
  16. package/dist/exports/client/index.js +7 -7
  17. package/dist/exports/client/index.js.map +4 -4
  18. package/dist/features/blockquote/feature.server.d.ts +5 -0
  19. package/dist/features/blockquote/feature.server.d.ts.map +1 -1
  20. package/dist/features/blockquote/feature.server.js.map +1 -1
  21. package/dist/features/blocks/component/index.js +1 -1
  22. package/dist/features/blocks/component/index.js.map +1 -1
  23. package/dist/features/blocks/feature.server.d.ts.map +1 -1
  24. package/dist/features/blocks/feature.server.js +1 -11
  25. package/dist/features/blocks/feature.server.js.map +1 -1
  26. package/dist/features/blocks/nodes/BlocksNode.d.ts +2 -0
  27. package/dist/features/blocks/nodes/BlocksNode.d.ts.map +1 -1
  28. package/dist/features/blocks/nodes/BlocksNode.js +1 -1
  29. package/dist/features/blocks/nodes/BlocksNode.js.map +1 -1
  30. package/dist/features/converters/html/feature.server.d.ts +1 -1
  31. package/dist/features/converters/html/feature.server.d.ts.map +1 -1
  32. package/dist/features/converters/html/feature.server.js.map +1 -1
  33. package/dist/features/heading/feature.server.d.ts +5 -1
  34. package/dist/features/heading/feature.server.d.ts.map +1 -1
  35. package/dist/features/heading/feature.server.js.map +1 -1
  36. package/dist/features/heading/i18n.js +2 -2
  37. package/dist/features/heading/i18n.js.map +1 -1
  38. package/dist/features/horizontalRule/nodes/HorizontalRuleNode.d.ts +5 -2
  39. package/dist/features/horizontalRule/nodes/HorizontalRuleNode.d.ts.map +1 -1
  40. package/dist/features/horizontalRule/nodes/HorizontalRuleNode.js.map +1 -1
  41. package/dist/features/link/feature.server.d.ts.map +1 -1
  42. package/dist/features/link/feature.server.js +1 -11
  43. package/dist/features/link/feature.server.js.map +1 -1
  44. package/dist/features/link/nodes/AutoLinkNode.d.ts.map +1 -1
  45. package/dist/features/link/nodes/AutoLinkNode.js +7 -1
  46. package/dist/features/link/nodes/AutoLinkNode.js.map +1 -1
  47. package/dist/features/link/nodes/LinkNode.js +1 -1
  48. package/dist/features/link/nodes/LinkNode.js.map +1 -1
  49. package/dist/features/link/nodes/types.d.ts +7 -4
  50. package/dist/features/link/nodes/types.d.ts.map +1 -1
  51. package/dist/features/link/nodes/types.js.map +1 -1
  52. package/dist/features/link/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  53. package/dist/features/link/plugins/floatingLinkEditor/LinkEditor/index.js +9 -5
  54. package/dist/features/link/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  55. package/dist/features/lists/checklist/feature.server.js.map +1 -1
  56. package/dist/features/lists/htmlConverter.d.ts +1 -1
  57. package/dist/features/lists/htmlConverter.d.ts.map +1 -1
  58. package/dist/features/lists/htmlConverter.js.map +1 -1
  59. package/dist/features/lists/orderedList/feature.server.js.map +1 -1
  60. package/dist/features/lists/plugin/index.d.ts +10 -0
  61. package/dist/features/lists/plugin/index.d.ts.map +1 -1
  62. package/dist/features/lists/plugin/index.js.map +1 -1
  63. package/dist/features/lists/unorderedList/feature.server.js.map +1 -1
  64. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/heading/converter.d.ts.map +1 -1
  65. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/heading/converter.js.map +1 -1
  66. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/list/converter.d.ts.map +1 -1
  67. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/list/converter.js.map +1 -1
  68. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/listItem/converter.d.ts.map +1 -1
  69. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/listItem/converter.js.map +1 -1
  70. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/quote/converter.d.ts.map +1 -1
  71. package/dist/features/migrations/lexicalPluginToLexical/converter/converters/quote/converter.js.map +1 -1
  72. package/dist/features/migrations/slateToLexical/converter/converters/blockquote/converter.d.ts.map +1 -1
  73. package/dist/features/migrations/slateToLexical/converter/converters/blockquote/converter.js.map +1 -1
  74. package/dist/features/migrations/slateToLexical/converter/converters/heading/converter.d.ts.map +1 -1
  75. package/dist/features/migrations/slateToLexical/converter/converters/heading/converter.js.map +1 -1
  76. package/dist/features/migrations/slateToLexical/converter/converters/listItem/converter.d.ts.map +1 -1
  77. package/dist/features/migrations/slateToLexical/converter/converters/listItem/converter.js.map +1 -1
  78. package/dist/features/migrations/slateToLexical/converter/converters/orderedList/converter.d.ts.map +1 -1
  79. package/dist/features/migrations/slateToLexical/converter/converters/orderedList/converter.js.map +1 -1
  80. package/dist/features/migrations/slateToLexical/converter/converters/unorderedList/converter.d.ts.map +1 -1
  81. package/dist/features/migrations/slateToLexical/converter/converters/unorderedList/converter.js.map +1 -1
  82. package/dist/features/migrations/slateToLexical/feature.server.d.ts +3 -1
  83. package/dist/features/migrations/slateToLexical/feature.server.d.ts.map +1 -1
  84. package/dist/features/migrations/slateToLexical/feature.server.js +3 -1
  85. package/dist/features/migrations/slateToLexical/feature.server.js.map +1 -1
  86. package/dist/features/relationship/nodes/RelationshipNode.d.ts +6 -2
  87. package/dist/features/relationship/nodes/RelationshipNode.d.ts.map +1 -1
  88. package/dist/features/relationship/nodes/RelationshipNode.js +1 -1
  89. package/dist/features/relationship/nodes/RelationshipNode.js.map +1 -1
  90. package/dist/features/toolbars/types.d.ts +30 -3
  91. package/dist/features/toolbars/types.d.ts.map +1 -1
  92. package/dist/features/toolbars/types.js.map +1 -1
  93. package/dist/features/typesClient.d.ts +2 -2
  94. package/dist/features/typesClient.d.ts.map +1 -1
  95. package/dist/features/typesClient.js.map +1 -1
  96. package/dist/features/typesServer.d.ts +26 -3
  97. package/dist/features/typesServer.d.ts.map +1 -1
  98. package/dist/features/typesServer.js.map +1 -1
  99. package/dist/features/upload/component/index.d.ts.map +1 -1
  100. package/dist/features/upload/component/index.js +34 -11
  101. package/dist/features/upload/component/index.js.map +1 -1
  102. package/dist/features/upload/feature.server.d.ts.map +1 -1
  103. package/dist/features/upload/feature.server.js +1 -11
  104. package/dist/features/upload/feature.server.js.map +1 -1
  105. package/dist/features/upload/nodes/UploadNode.d.ts +6 -2
  106. package/dist/features/upload/nodes/UploadNode.d.ts.map +1 -1
  107. package/dist/features/upload/nodes/UploadNode.js +1 -1
  108. package/dist/features/upload/nodes/UploadNode.js.map +1 -1
  109. package/dist/field/index.js +8 -8
  110. package/dist/index.d.ts +8 -4
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +3 -0
  113. package/dist/index.js.map +1 -1
  114. package/dist/lexical/config/server/default.d.ts +1 -1
  115. package/dist/lexical/config/server/default.d.ts.map +1 -1
  116. package/dist/lexical/config/server/default.js.map +1 -1
  117. package/dist/lexical/config/types.d.ts +2 -2
  118. package/dist/lexical/config/types.d.ts.map +1 -1
  119. package/dist/lexical/config/types.js.map +1 -1
  120. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts +9 -2
  121. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts.map +1 -1
  122. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js.map +1 -1
  123. package/dist/nodeTypes.d.ts +31 -0
  124. package/dist/nodeTypes.d.ts.map +1 -0
  125. package/dist/nodeTypes.js +3 -0
  126. package/dist/nodeTypes.js.map +1 -0
  127. package/dist/types.d.ts +1 -1
  128. package/dist/types.js.map +1 -1
  129. package/dist/utilities/fieldsDrawer/Drawer.d.ts +18 -0
  130. package/dist/utilities/fieldsDrawer/Drawer.d.ts.map +1 -0
  131. package/dist/utilities/fieldsDrawer/Drawer.js +26 -0
  132. package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -0
  133. package/dist/utilities/fieldsDrawer/DrawerContent.d.ts +4 -0
  134. package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -0
  135. package/dist/{features/link/drawer/index.js → utilities/fieldsDrawer/DrawerContent.js} +38 -40
  136. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -0
  137. package/dist/utilities/generateSchemaMap.d.ts.map +1 -1
  138. package/dist/utilities/generateSchemaMap.js +9 -0
  139. package/dist/utilities/generateSchemaMap.js.map +1 -1
  140. package/dist/utilities/migrateSlateToLexical/index.d.ts +15 -0
  141. package/dist/utilities/migrateSlateToLexical/index.d.ts.map +1 -0
  142. package/dist/utilities/migrateSlateToLexical/index.js +105 -0
  143. package/dist/utilities/migrateSlateToLexical/index.js.map +1 -0
  144. package/dist/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.d.ts +9 -0
  145. package/dist/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.d.ts.map +1 -0
  146. package/dist/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.js +77 -0
  147. package/dist/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.js.map +1 -0
  148. package/dist/utilities/upgradeLexicalData/index.d.ts +11 -0
  149. package/dist/utilities/upgradeLexicalData/index.d.ts.map +1 -0
  150. package/dist/utilities/upgradeLexicalData/index.js +101 -0
  151. package/dist/utilities/upgradeLexicalData/index.js.map +1 -0
  152. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.d.ts +9 -0
  153. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.d.ts.map +1 -0
  154. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js +74 -0
  155. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js.map +1 -0
  156. package/package.json +9 -9
  157. package/dist/exports/client/chunk-MLIITFAS.js.map +0 -7
  158. package/dist/exports/client/chunk-OSR74ZNW.js.map +0 -7
  159. package/dist/exports/client/chunk-TZLHAUCW.js +0 -2
  160. package/dist/exports/client/chunk-TZLHAUCW.js.map +0 -7
  161. package/dist/exports/client/component-CEUVAHRO.js +0 -2
  162. package/dist/exports/client/component-CEUVAHRO.js.map +0 -7
  163. package/dist/exports/client/component-PEFMKIXI.js.map +0 -7
  164. package/dist/features/link/drawer/index.d.ts +0 -5
  165. package/dist/features/link/drawer/index.d.ts.map +0 -1
  166. package/dist/features/link/drawer/index.js.map +0 -1
  167. package/dist/features/link/drawer/types.d.ts +0 -10
  168. package/dist/features/link/drawer/types.d.ts.map +0 -1
  169. package/dist/features/link/drawer/types.js +0 -3
  170. package/dist/features/link/drawer/types.js.map +0 -1
  171. package/dist/features/upload/component/ExtraFieldsDrawer/index.d.ts +0 -12
  172. package/dist/features/upload/component/ExtraFieldsDrawer/index.d.ts.map +0 -1
  173. package/dist/features/upload/component/ExtraFieldsDrawer/index.js +0 -123
  174. package/dist/features/upload/component/ExtraFieldsDrawer/index.js.map +0 -1
  175. /package/dist/exports/client/{RelationshipComponent-5OU5HATX.js.map → RelationshipComponent-AFXEJMZQ.js.map} +0 -0
  176. /package/dist/exports/client/{component-QWIGEOVD.js.map → component-VM36FRT2.js.map} +0 -0
@@ -0,0 +1,18 @@
1
+ import type { FormState } from 'payload';
2
+ import React from 'react';
3
+ export type FieldsDrawerProps = {
4
+ className?: string;
5
+ data: any;
6
+ drawerSlug: string;
7
+ drawerTitle?: string;
8
+ featureKey: string;
9
+ handleDrawerSubmit: (fields: FormState, data: Record<string, unknown>) => void;
10
+ schemaPathSuffix?: string;
11
+ };
12
+ /**
13
+ * This FieldsDrawer component can be used to easily create a Drawer that contains a form with fields within your feature.
14
+ * The fields are taken directly from the schema map based on your `featureKey` and `schemaPathSuffix`. Thus, this can only
15
+ * be used if you provide your field schema inside the `generateSchemaMap` prop of your feature.server.ts.
16
+ */
17
+ export declare const FieldsDrawer: React.FC<FieldsDrawerProps>;
18
+ //# sourceMappingURL=Drawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/Drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGxC,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,GAAG,CAAA;IACT,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAqBpD,CAAA"}
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Drawer } from '@payloadcms/ui';
4
+ import React from 'react';
5
+ import { DrawerContent } from './DrawerContent.js';
6
+ /**
7
+ * This FieldsDrawer component can be used to easily create a Drawer that contains a form with fields within your feature.
8
+ * The fields are taken directly from the schema map based on your `featureKey` and `schemaPathSuffix`. Thus, this can only
9
+ * be used if you provide your field schema inside the `generateSchemaMap` prop of your feature.server.ts.
10
+ */ export const FieldsDrawer = ({ className, data, drawerSlug, drawerTitle, featureKey, handleDrawerSubmit, schemaPathSuffix })=>{
11
+ // The Drawer only renders its children (and itself) if it's open. Thus, by extracting the main content
12
+ // to DrawerContent, this should be faster
13
+ return /*#__PURE__*/ _jsx(Drawer, {
14
+ className: className,
15
+ slug: drawerSlug,
16
+ title: drawerTitle ?? '',
17
+ children: /*#__PURE__*/ _jsx(DrawerContent, {
18
+ data: data,
19
+ featureKey: featureKey,
20
+ handleDrawerSubmit: handleDrawerSubmit,
21
+ schemaPathSuffix: schemaPathSuffix
22
+ })
23
+ });
24
+ };
25
+
26
+ //# sourceMappingURL=Drawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/fieldsDrawer/Drawer.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport { Drawer } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { DrawerContent } from './DrawerContent.js'\n\nexport type FieldsDrawerProps = {\n className?: string\n data: any\n drawerSlug: string\n drawerTitle?: string\n featureKey: string\n handleDrawerSubmit: (fields: FormState, data: Record<string, unknown>) => void\n 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 handleDrawerSubmit,\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 handleDrawerSubmit={handleDrawerSubmit}\n schemaPathSuffix={schemaPathSuffix}\n />\n </Drawer>\n )\n}\n"],"names":["Drawer","React","DrawerContent","FieldsDrawer","className","data","drawerSlug","drawerTitle","featureKey","handleDrawerSubmit","schemaPathSuffix","slug","title"],"mappings":"AAAA;;AAGA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,OAAOC,WAAW,QAAO;AAEzB,SAASC,aAAa,QAAQ,qBAAoB;AAYlD;;;;CAIC,GACD,OAAO,MAAMC,eAA4C,CAAC,EACxDC,SAAS,EACTC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,kBAAkB,EAClBC,gBAAgB,EACjB;IACC,uGAAuG;IACvG,0CAA0C;IAC1C,qBACE,KAACV;QAAOI,WAAWA;QAAWO,MAAML;QAAYM,OAAOL,eAAe;kBACpE,cAAA,KAACL;YACCG,MAAMA;YACNG,YAAYA;YACZC,oBAAoBA;YACpBC,kBAAkBA;;;AAI1B,EAAC"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { FieldsDrawerProps } from './Drawer.js';
3
+ export declare const DrawerContent: React.FC<Omit<FieldsDrawerProps, 'drawerSlug' | 'drawerTitle'>>;
4
+ //# sourceMappingURL=DrawerContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DrawerContent.d.ts","sourceRoot":"","sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"names":[],"mappings":"AAcA,OAAO,KAA2C,MAAM,OAAO,CAAA;AAG/D,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,CAmFzF,CAAA"}
@@ -1,19 +1,19 @@
1
+ 'use client';
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Drawer, Form, FormSubmit, RenderFields, useConfig, useDocumentInfo, useFieldProps, useTranslation } from '@payloadcms/ui';
3
+ import { Form, FormSubmit, RenderFields, useConfig, useDocumentInfo, useFieldProps, useTranslation } from '@payloadcms/ui';
3
4
  import { getFormState } from '@payloadcms/ui/shared';
4
5
  import React, { useCallback, useEffect, useState } from 'react';
5
6
  import { v4 as uuid } from 'uuid';
6
- import { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js';
7
- const baseClass = 'lexical-link-edit-drawer';
8
- export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
7
+ import { useEditorConfigContext } from '../../lexical/config/client/EditorConfigProvider.js';
8
+ export const DrawerContent = ({ data, featureKey, handleDrawerSubmit, schemaPathSuffix })=>{
9
9
  const { t } = useTranslation();
10
10
  const { id } = useDocumentInfo();
11
11
  const { schemaPath } = useFieldProps();
12
12
  const config = useConfig();
13
13
  const [initialState, setInitialState] = useState(false);
14
14
  const { field: { richTextComponentMap } } = useEditorConfigContext();
15
- const componentMapRenderedFieldsPath = `feature.link.fields.fields`;
16
- const schemaFieldsPath = `${schemaPath}.feature.link.fields`;
15
+ const componentMapRenderedFieldsPath = `feature.${featureKey}.fields${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`;
16
+ const schemaFieldsPath = `${schemaPath}.feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`;
17
17
  const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath) // Field Schema
18
18
  ;
19
19
  useEffect(()=>{
@@ -22,7 +22,7 @@ export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
22
22
  apiRoute: config.routes.api,
23
23
  body: {
24
24
  id,
25
- data: stateData,
25
+ data,
26
26
  operation: 'update',
27
27
  schemaPath: schemaFieldsPath
28
28
  },
@@ -31,7 +31,7 @@ export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
31
31
  ;
32
32
  setInitialState(state);
33
33
  };
34
- if (stateData) {
34
+ if (data) {
35
35
  void awaitInitialState();
36
36
  }
37
37
  }, [
@@ -39,7 +39,7 @@ export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
39
39
  config.serverURL,
40
40
  schemaFieldsPath,
41
41
  id,
42
- stateData
42
+ data
43
43
  ]);
44
44
  const onChange = useCallback(async ({ formState: prevFormState })=>{
45
45
  return await getFormState({
@@ -58,37 +58,35 @@ export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
58
58
  schemaFieldsPath,
59
59
  id
60
60
  ]);
61
- return /*#__PURE__*/ _jsx(Drawer, {
62
- className: baseClass,
63
- slug: drawerSlug,
64
- title: t('fields:editLink') ?? '',
65
- children: initialState !== false && /*#__PURE__*/ _jsxs(Form, {
66
- beforeSubmit: [
67
- onChange
68
- ],
69
- disableValidationOnSubmit: true,
70
- fields: Array.isArray(fieldMap) ? fieldMap : [],
71
- initialState: initialState,
72
- onChange: [
73
- onChange
74
- ],
75
- onSubmit: handleModalSubmit,
76
- uuid: uuid(),
77
- children: [
78
- /*#__PURE__*/ _jsx(RenderFields, {
79
- fieldMap: Array.isArray(fieldMap) ? fieldMap : [],
80
- forceRender: true,
81
- path: "" // See Blocks feature path for details as for why this is empty
82
- ,
83
- readOnly: false,
84
- schemaPath: schemaFieldsPath
85
- }),
86
- /*#__PURE__*/ _jsx(FormSubmit, {
87
- children: t('general:submit')
88
- })
89
- ]
90
- })
61
+ if (initialState === false) {
62
+ return null;
63
+ }
64
+ return /*#__PURE__*/ _jsxs(Form, {
65
+ beforeSubmit: [
66
+ onChange
67
+ ],
68
+ disableValidationOnSubmit: true,
69
+ fields: Array.isArray(fieldMap) ? fieldMap : [],
70
+ initialState: initialState,
71
+ onChange: [
72
+ onChange
73
+ ],
74
+ onSubmit: handleDrawerSubmit,
75
+ uuid: uuid(),
76
+ children: [
77
+ /*#__PURE__*/ _jsx(RenderFields, {
78
+ fieldMap: Array.isArray(fieldMap) ? fieldMap : [],
79
+ forceRender: true,
80
+ path: "" // See Blocks feature path for details as for why this is empty
81
+ ,
82
+ readOnly: false,
83
+ schemaPath: schemaFieldsPath
84
+ }),
85
+ /*#__PURE__*/ _jsx(FormSubmit, {
86
+ children: t('fields:saveChanges')
87
+ })
88
+ ]
91
89
  });
92
90
  };
93
91
 
94
- //# sourceMappingURL=index.js.map
92
+ //# sourceMappingURL=DrawerContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"sourcesContent":["'use client'\nimport type { FormProps } from '@payloadcms/ui'\nimport type { FormState } from 'payload'\n\nimport {\n Form,\n FormSubmit,\n RenderFields,\n useConfig,\n useDocumentInfo,\n useFieldProps,\n useTranslation,\n} from '@payloadcms/ui'\nimport { getFormState } from '@payloadcms/ui/shared'\nimport React, { useCallback, useEffect, 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 handleDrawerSubmit,\n schemaPathSuffix,\n}) => {\n const { t } = useTranslation()\n const { id } = useDocumentInfo()\n const { schemaPath } = useFieldProps()\n const config = useConfig()\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.${featureKey}.fields${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n const schemaFieldsPath = `${schemaPath}.feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath) // Field Schema\n\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n setInitialState(state)\n }\n\n if (data) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id, data])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n return await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n formState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n })\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id],\n )\n\n if (initialState === false) {\n return null\n }\n\n return (\n <Form\n beforeSubmit={[onChange]}\n disableValidationOnSubmit\n fields={Array.isArray(fieldMap) ? fieldMap : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleDrawerSubmit}\n uuid={uuid()}\n >\n <RenderFields\n fieldMap={Array.isArray(fieldMap) ? fieldMap : []}\n forceRender\n path=\"\" // See Blocks feature path for details as for why this is empty\n readOnly={false}\n schemaPath={schemaFieldsPath}\n />\n\n <FormSubmit>{t('fields:saveChanges')}</FormSubmit>\n </Form>\n )\n}\n"],"names":["Form","FormSubmit","RenderFields","useConfig","useDocumentInfo","useFieldProps","useTranslation","getFormState","React","useCallback","useEffect","useState","v4","uuid","useEditorConfigContext","DrawerContent","data","featureKey","handleDrawerSubmit","schemaPathSuffix","t","id","schemaPath","config","initialState","setInitialState","field","richTextComponentMap","componentMapRenderedFieldsPath","schemaFieldsPath","fieldMap","get","awaitInitialState","state","apiRoute","routes","api","body","operation","serverURL","onChange","formState","prevFormState","beforeSubmit","disableValidationOnSubmit","fields","Array","isArray","onSubmit","forceRender","path","readOnly"],"mappings":"AAAA;;AAIA,SACEA,IAAI,EACJC,UAAU,EACVC,YAAY,EACZC,SAAS,EACTC,eAAe,EACfC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,SAASC,Y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zC,OAAO,EAAEgC,WAAWC,aAAa,EAAE;QACjC,OAAO,MAAMnC,aAAa;YACxB2B,UAAUX,OAAOY,MAAM,CAACC,GAAG;YAC3BC,MAAM;gBACJhB;gBACAoB,WAAWC;gBACXJ,WAAW;gBACXhB,YAAYO;YACd;YACAU,WAAWhB,OAAOgB,SAAS;QAC7B;IACF,GAEA;QAAChB,OAAOY,MAAM,CAACC,GAAG;QAAEb,OAAOgB,SAAS;QAAEV;QAAkBR;KAAG;IAG7D,IAAIG,iBAAiB,OAAO;QAC1B,OAAO;IACT;IAEA,qBACE,MAACxB;QACC2C,cAAc;YAACH;SAAS;QACxBI,yBAAyB;QACzBC,QAAQC,MAAMC,OAAO,CAACjB,YAAYA,WAAW,EAAE;QAC/CN,cAAcA;QACdgB,UAAU;YAACA;SAAS;QACpBQ,UAAU9B;QACVL,MAAMA;;0BAEN,KAACX;gBACC4B,UAAUgB,MAAMC,OAAO,CAACjB,YAAYA,WAAW,EAAE;gBACjDmB,WAAW;gBACXC,MAAK,GAAG,+DAA+D;;gBACvEC,UAAU;gBACV7B,YAAYO;;0BAGd,KAAC5B;0BAAYmB,EAAE;;;;AAGrB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"generateSchemaMap.d.ts","sourceRoot":"","sources":["../../src/utilities/generateSchemaMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAE1E,eAAO,MAAM,oBAAoB,SACxB;IAAE,kBAAkB,EAAE,wBAAwB,CAAA;CAAE,KAAG,eAAe,CAAC,mBAAmB,CAyB5F,CAAA"}
1
+ {"version":3,"file":"generateSchemaMap.d.ts","sourceRoot":"","sources":["../../src/utilities/generateSchemaMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAE1E,eAAO,MAAM,oBAAoB,SACxB;IAAE,kBAAkB,EAAE,wBAAwB,CAAA;CAAE,KAAG,eAAe,CAAC,mBAAmB,CAkC5F,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { traverseFields } from '@payloadcms/ui/utilities/buildFieldSchemaMap/traverseFields';
1
2
  export const getGenerateSchemaMap = (args)=>({ config, i18n, schemaMap, schemaPath })=>{
2
3
  for (const [featureKey, resolvedFeature] of args.resolvedFeatureMap.entries()){
3
4
  if (!('generateSchemaMap' in resolvedFeature) || typeof resolvedFeature.generateSchemaMap !== 'function') {
@@ -12,6 +13,14 @@ export const getGenerateSchemaMap = (args)=>({ config, i18n, schemaMap, schemaPa
12
13
  });
13
14
  if (schemas) {
14
15
  for (const [schemaKey, fields] of schemas.entries()){
16
+ // generate schema map entries for sub-fields using traverseFields
17
+ traverseFields({
18
+ config,
19
+ fields,
20
+ i18n,
21
+ schemaMap: schemas,
22
+ schemaPath: schemaKey
23
+ });
15
24
  schemaMap.set(`${schemaPath}.feature.${featureKey}.${schemaKey}`, fields);
16
25
  }
17
26
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/generateSchemaMap.ts"],"sourcesContent":["import type { RichTextAdapter } from 'payload'\n\nimport type { ResolvedServerFeatureMap } from '../features/typesServer.js'\n\nexport const getGenerateSchemaMap =\n (args: { resolvedFeatureMap: ResolvedServerFeatureMap }): RichTextAdapter['generateSchemaMap'] =>\n ({ config, i18n, schemaMap, schemaPath }) => {\n for (const [featureKey, resolvedFeature] of args.resolvedFeatureMap.entries()) {\n if (\n !('generateSchemaMap' in resolvedFeature) ||\n typeof resolvedFeature.generateSchemaMap !== 'function'\n ) {\n continue\n }\n const schemas = resolvedFeature.generateSchemaMap({\n config,\n i18n,\n props: resolvedFeature.sanitizedServerFeatureProps,\n schemaMap,\n schemaPath,\n })\n\n if (schemas) {\n for (const [schemaKey, fields] of schemas.entries()) {\n schemaMap.set(`${schemaPath}.feature.${featureKey}.${schemaKey}`, fields)\n }\n }\n }\n\n return schemaMap\n }\n"],"names":["getGenerateSchemaMap","args","config","i18n","schemaMap","schemaPath","featureKey","resolvedFeature","resolvedFeatureMap","entries","generateSchemaMap","schemas","props","sanitizedServerFeatureProps","schemaKey","fields","set"],"mappings":"AAIA,OAAO,MAAMA,uBACX,CAACC,OACD,CAAC,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,UAAU,EAAE;QACtC,KAAK,MAAM,CAACC,YAAYC,gBAAgB,IAAIN,KAAKO,kBAAkB,CAACC,OAAO,GAAI;YAC7E,IACE,CAAE,CAAA,uBAAuBF,eAAc,KACvC,OAAOA,gBAAgBG,iBAAiB,KAAK,YAC7C;gBACA;YACF;YACA,MAAMC,UAAUJ,gBAAgBG,iBAAiB,CAAC;gBAChDR;gBACAC;gBACAS,OAAOL,gBAAgBM,2BAA2B;gBAClDT;gBACAC;YACF;YAEA,IAAIM,SAAS;gBACX,KAAK,MAAM,CAACG,WAAWC,OAAO,IAAIJ,QAAQF,OAAO,GAAI;oBACnDL,UAAUY,GAAG,CAAC,CAAC,EAAEX,WAAW,SAAS,EAAEC,WAAW,CAAC,EAAEQ,UAAU,CAAC,EAAEC;gBACpE;YACF;QACF;QAEA,OAAOX;IACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/generateSchemaMap.ts"],"sourcesContent":["import type { RichTextAdapter } from 'payload'\n\nimport { traverseFields } from '@payloadcms/ui/utilities/buildFieldSchemaMap/traverseFields'\n\nimport type { ResolvedServerFeatureMap } from '../features/typesServer.js'\n\nexport const getGenerateSchemaMap =\n (args: { resolvedFeatureMap: ResolvedServerFeatureMap }): RichTextAdapter['generateSchemaMap'] =>\n ({ config, i18n, schemaMap, schemaPath }) => {\n for (const [featureKey, resolvedFeature] of args.resolvedFeatureMap.entries()) {\n if (\n !('generateSchemaMap' in resolvedFeature) ||\n typeof resolvedFeature.generateSchemaMap !== 'function'\n ) {\n continue\n }\n const schemas = resolvedFeature.generateSchemaMap({\n config,\n i18n,\n props: resolvedFeature.sanitizedServerFeatureProps,\n schemaMap,\n schemaPath,\n })\n\n if (schemas) {\n for (const [schemaKey, fields] of schemas.entries()) {\n // generate schema map entries for sub-fields using traverseFields\n traverseFields({\n config,\n fields,\n i18n,\n schemaMap: schemas,\n schemaPath: schemaKey,\n })\n\n schemaMap.set(`${schemaPath}.feature.${featureKey}.${schemaKey}`, fields)\n }\n }\n }\n\n return schemaMap\n }\n"],"names":["traverseFields","getGenerateSchemaMap","args","config","i18n","schemaMap","schemaPath","featureKey","resolvedFeature","resolvedFeatureMap","entries","generateSchemaMap","schemas","props","sanitizedServerFeatureProps","schemaKey","fields","set"],"mappings":"AAEA,SAASA,cAAc,QAAQ,8DAA6D;AAI5F,OAAO,MAAMC,uBACX,CAACC,OACD,CAAC,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,UAAU,EAAE;QACtC,KAAK,MAAM,CAACC,YAAYC,gBAAgB,IAAIN,KAAKO,kBAAkB,CAACC,OAAO,GAAI;YAC7E,IACE,CAAE,CAAA,uBAAuBF,eAAc,KACvC,OAAOA,gBAAgBG,iBAAiB,KAAK,YAC7C;gBACA;YACF;YACA,MAAMC,UAAUJ,gBAAgBG,iBAAiB,CAAC;gBAChDR;gBACAC;gBACAS,OAAOL,gBAAgBM,2BAA2B;gBAClDT;gBACAC;YACF;YAEA,IAAIM,SAAS;gBACX,KAAK,MAAM,CAACG,WAAWC,OAAO,IAAIJ,QAAQF,OAAO,GAAI;oBACnD,kEAAkE;oBAClEV,eAAe;wBACbG;wBACAa;wBACAZ;wBACAC,WAAWO;wBACXN,YAAYS;oBACd;oBAEAV,UAAUY,GAAG,CAAC,CAAC,EAAEX,WAAW,SAAS,EAAEC,WAAW,CAAC,EAAEQ,UAAU,CAAC,EAAEC;gBACpE;YACF;QACF;QAEA,OAAOX;IACT,EAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Payload } from 'payload';
2
+ /**
3
+ * This goes through every single collection and field in the payload config, and migrates its data from Slate to Lexical. This does not support sub-fields within slate.
4
+ *
5
+ * It will only translate fields fulfilling all these requirements:
6
+ * - field schema uses lexical editor
7
+ * - lexical editor has SlateToLexicalFeature added
8
+ * - saved field data is in Slate format
9
+ *
10
+ * @param payload
11
+ */
12
+ export declare function migrateSlateToLexical({ payload }: {
13
+ payload: Payload;
14
+ }): Promise<void>;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/migrateSlateToLexical/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyC,OAAO,EAAE,MAAM,SAAS,CAAA;AAI7E;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBA0B5E"}
@@ -0,0 +1,105 @@
1
+ import { migrateDocumentFieldsRecursively } from './migrateDocumentFieldsRecursively.js';
2
+ /**
3
+ * This goes through every single collection and field in the payload config, and migrates its data from Slate to Lexical. This does not support sub-fields within slate.
4
+ *
5
+ * It will only translate fields fulfilling all these requirements:
6
+ * - field schema uses lexical editor
7
+ * - lexical editor has SlateToLexicalFeature added
8
+ * - saved field data is in Slate format
9
+ *
10
+ * @param payload
11
+ */ export async function migrateSlateToLexical({ payload }) {
12
+ const collections = payload.config.collections;
13
+ const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [
14
+ null
15
+ ];
16
+ const totalCollections = collections.length;
17
+ for (const locale of allLocales){
18
+ let curCollection = 0;
19
+ for (const collection of collections){
20
+ curCollection++;
21
+ await migrateCollection({
22
+ collection,
23
+ cur: curCollection,
24
+ locale,
25
+ max: totalCollections,
26
+ payload
27
+ });
28
+ }
29
+ for (const global of payload.config.globals){
30
+ await migrateGlobal({
31
+ global,
32
+ locale,
33
+ payload
34
+ });
35
+ }
36
+ }
37
+ }
38
+ async function migrateGlobal({ global, locale, payload }) {
39
+ console.log(`SlateToLexical: ${locale}: Migrating global:`, global.slug);
40
+ const document = await payload.findGlobal({
41
+ slug: global.slug,
42
+ depth: 0,
43
+ locale: locale || undefined,
44
+ overrideAccess: true
45
+ });
46
+ const found = migrateDocument({
47
+ document,
48
+ fields: global.fields
49
+ });
50
+ if (found) {
51
+ await payload.updateGlobal({
52
+ slug: global.slug,
53
+ data: document,
54
+ depth: 0,
55
+ locale: locale || undefined
56
+ });
57
+ }
58
+ }
59
+ async function migrateCollection({ collection, cur, locale, max, payload }) {
60
+ console.log(`SlateToLexical: ${locale}: Migrating collection:`, collection.slug, '(' + cur + '/' + max + ')');
61
+ const documentCount = (await payload.count({
62
+ collection: collection.slug,
63
+ depth: 0,
64
+ locale: locale || undefined
65
+ })).totalDocs;
66
+ let page = 1;
67
+ let migrated = 0;
68
+ while(migrated < documentCount){
69
+ const documents = await payload.find({
70
+ collection: collection.slug,
71
+ depth: 0,
72
+ locale: locale || undefined,
73
+ overrideAccess: true,
74
+ page,
75
+ pagination: true
76
+ });
77
+ for (const document of documents.docs){
78
+ migrated++;
79
+ console.log(`SlateToLexical: ${locale}: Migrating collection:`, collection.slug, '(' + cur + '/' + max + ') - Migrating Document: ' + document.id + ' (' + migrated + '/' + documentCount + ')');
80
+ const found = migrateDocument({
81
+ document,
82
+ fields: collection.fields
83
+ });
84
+ if (found) {
85
+ await payload.update({
86
+ id: document.id,
87
+ collection: collection.slug,
88
+ data: document,
89
+ depth: 0,
90
+ locale: locale || undefined
91
+ });
92
+ }
93
+ }
94
+ page++;
95
+ }
96
+ }
97
+ function migrateDocument({ document, fields }) {
98
+ return !!migrateDocumentFieldsRecursively({
99
+ data: document,
100
+ fields,
101
+ found: 0
102
+ });
103
+ }
104
+
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/migrateSlateToLexical/index.ts"],"sourcesContent":["import type { CollectionConfig, Field, GlobalConfig, Payload } from 'payload'\n\nimport { migrateDocumentFieldsRecursively } from './migrateDocumentFieldsRecursively.js'\n\n/**\n * This goes through every single collection and field in the payload config, and migrates its data from Slate to Lexical. This does not support sub-fields within slate.\n *\n * It will only translate fields fulfilling all these requirements:\n * - field schema uses lexical editor\n * - lexical editor has SlateToLexicalFeature added\n * - saved field data is in Slate format\n *\n * @param payload\n */\nexport async function migrateSlateToLexical({ payload }: { payload: Payload }) {\n const collections = payload.config.collections\n\n const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [null]\n\n const totalCollections = collections.length\n for (const locale of allLocales) {\n let curCollection = 0\n for (const collection of collections) {\n curCollection++\n await migrateCollection({\n collection,\n cur: curCollection,\n locale,\n max: totalCollections,\n payload,\n })\n }\n for (const global of payload.config.globals) {\n await migrateGlobal({\n global,\n locale,\n payload,\n })\n }\n }\n}\n\nasync function migrateGlobal({\n global,\n locale,\n payload,\n}: {\n global: GlobalConfig\n locale: null | string\n payload: Payload\n}) {\n console.log(`SlateToLexical: ${locale}: Migrating global:`, global.slug)\n\n const document = await payload.findGlobal({\n slug: global.slug,\n depth: 0,\n locale: locale || undefined,\n overrideAccess: true,\n })\n\n const found = migrateDocument({\n document,\n fields: global.fields,\n })\n\n if (found) {\n await payload.updateGlobal({\n slug: global.slug,\n data: document,\n depth: 0,\n locale: locale || undefined,\n })\n }\n}\n\nasync function migrateCollection({\n collection,\n cur,\n locale,\n max,\n payload,\n}: {\n collection: CollectionConfig\n cur: number\n locale: null | string\n max: number\n payload: Payload\n}) {\n console.log(\n `SlateToLexical: ${locale}: Migrating collection:`,\n collection.slug,\n '(' + cur + '/' + max + ')',\n )\n\n const documentCount = (\n await payload.count({\n collection: collection.slug,\n depth: 0,\n locale: locale || undefined,\n })\n ).totalDocs\n\n let page = 1\n let migrated = 0\n\n while (migrated < documentCount) {\n const documents = await payload.find({\n collection: collection.slug,\n depth: 0,\n locale: locale || undefined,\n overrideAccess: true,\n page,\n pagination: true,\n })\n\n for (const document of documents.docs) {\n migrated++\n console.log(\n `SlateToLexical: ${locale}: Migrating collection:`,\n collection.slug,\n '(' +\n cur +\n '/' +\n max +\n ') - Migrating Document: ' +\n document.id +\n ' (' +\n migrated +\n '/' +\n documentCount +\n ')',\n )\n const found = migrateDocument({\n document,\n fields: collection.fields,\n })\n\n if (found) {\n await payload.update({\n id: document.id,\n collection: collection.slug,\n data: document,\n depth: 0,\n locale: locale || undefined,\n })\n }\n }\n page++\n }\n}\n\nfunction migrateDocument({\n document,\n fields,\n}: {\n document: Record<string, unknown>\n fields: Field[]\n}): boolean {\n return !!migrateDocumentFieldsRecursively({\n data: document,\n fields,\n found: 0,\n })\n}\n"],"names":["migrateDocumentFieldsRecursively","migrateSlateToLexical","payload","collections","config","allLocales","localization","localeCodes","totalCollections","length","locale","curCollection","collection","migrateCollection","cur","max","global","globals","migrateGlobal","console","log","slug","document","findGlobal","depth","undefined","overrideAccess","found","migrateDocument","fields","updateGlobal","data","documentCount","count","totalDocs","page","migrated","documents","find","pagination","docs","id","update"],"mappings":"AAEA,SAASA,gCAAgC,QAAQ,wCAAuC;AAExF;;;;;;;;;CASC,GACD,OAAO,eAAeC,sBAAsB,EAAEC,OAAO,EAAwB;IAC3E,MAAMC,cAAcD,QAAQE,MAAM,CAACD,WAAW;IAE9C,MAAME,aAAaH,QAAQE,MAAM,CAACE,YAAY,GAAGJ,QAAQE,MAAM,CAACE,YAAY,CAACC,WAAW,GAAG;QAAC;KAAK;IAEjG,MAAMC,mBAAmBL,YAAYM,MAAM;IAC3C,KAAK,MAAMC,UAAUL,WAAY;QAC/B,IAAIM,gBAAgB;QACpB,KAAK,MAAMC,cAAcT,YAAa;YACpCQ;YACA,MAAME,kBAAkB;gBACtBD;gBACAE,KAAKH;gBACLD;gBACAK,KAAKP;gBACLN;YACF;QACF;QACA,KAAK,MAAMc,UAAUd,QAAQE,MAAM,CAACa,OAAO,CAAE;YAC3C,MAAMC,cAAc;gBAClBF;gBACAN;gBACAR;YACF;QACF;IACF;AACF;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P,MACA,MACAC,MACA,6BACAO,SAASmB,EAAE,GACX,OACAL,WACA,MACAJ,gBACA;YAEJ,MAAML,QAAQC,gBAAgB;gBAC5BN;gBACAO,QAAQjB,WAAWiB,MAAM;YAC3B;YAEA,IAAIF,OAAO;gBACT,MAAMzB,QAAQwC,MAAM,CAAC;oBACnBD,IAAInB,SAASmB,EAAE;oBACf7B,YAAYA,WAAWS,IAAI;oBAC3BU,MAAMT;oBACNE,OAAO;oBACPd,QAAQA,UAAUe;gBACpB;YACF;QACF;QACAU;IACF;AACF;AAEA,SAASP,gBAAgB,EACvBN,QAAQ,EACRO,MAAM,EAIP;IACC,OAAO,CAAC,CAAC7B,iCAAiC;QACxC+B,MAAMT;QACNO;QACAF,OAAO;IACT;AACF"}
@@ -0,0 +1,9 @@
1
+ import type { Field } from 'payload';
2
+ type NestedRichTextFieldsArgs = {
3
+ data: unknown;
4
+ fields: Field[];
5
+ found: number;
6
+ };
7
+ export declare const migrateDocumentFieldsRecursively: ({ data, fields, found, }: NestedRichTextFieldsArgs) => number;
8
+ export {};
9
+ //# sourceMappingURL=migrateDocumentFieldsRecursively.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateDocumentFieldsRecursively.d.ts","sourceRoot":"","sources":["../../../src/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAYpC,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE,OAAO,CAAA;IAEb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gCAAgC,6BAI1C,wBAAwB,KAAG,MAwF7B,CAAA"}
@@ -0,0 +1,77 @@
1
+ import { fieldAffectsData, fieldHasSubFields, fieldIsArrayType } from 'payload/shared';
2
+ import { convertSlateToLexical } from '../../features/migrations/slateToLexical/converter/index.js';
3
+ export const migrateDocumentFieldsRecursively = ({ data, fields, found })=>{
4
+ for (const field of fields){
5
+ if (fieldHasSubFields(field) && !fieldIsArrayType(field)) {
6
+ if (fieldAffectsData(field) && typeof data[field.name] === 'object') {
7
+ migrateDocumentFieldsRecursively({
8
+ data: data[field.name],
9
+ fields: field.fields,
10
+ found
11
+ });
12
+ } else {
13
+ migrateDocumentFieldsRecursively({
14
+ data,
15
+ found,
16
+ fields: field.fields
17
+ });
18
+ }
19
+ } else if (field.type === 'tabs') {
20
+ field.tabs.forEach((tab)=>{
21
+ migrateDocumentFieldsRecursively({
22
+ data,
23
+ found,
24
+ fields: tab.fields
25
+ });
26
+ });
27
+ } else if (Array.isArray(data[field.name])) {
28
+ if (field.type === 'blocks') {
29
+ data[field.name].forEach((row, i)=>{
30
+ const block = field.blocks.find(({ slug })=>slug === row?.blockType);
31
+ if (block) {
32
+ migrateDocumentFieldsRecursively({
33
+ data: data[field.name][i],
34
+ found,
35
+ fields: block.fields
36
+ });
37
+ }
38
+ });
39
+ }
40
+ if (field.type === 'array') {
41
+ data[field.name].forEach((_, i)=>{
42
+ migrateDocumentFieldsRecursively({
43
+ data: data[field.name][i],
44
+ found,
45
+ fields: field.fields
46
+ });
47
+ });
48
+ }
49
+ }
50
+ if (field.type === 'richText' && Array.isArray(data[field.name])) {
51
+ // Slate richText
52
+ const editor = field.editor;
53
+ if (editor && typeof editor === 'object') {
54
+ if ('features' in editor && editor.features?.length) {
55
+ // find slatetolexical feature
56
+ const slateToLexicalFeature = editor.editorConfig.resolvedFeatureMap.get('slateToLexical');
57
+ if (slateToLexicalFeature) {
58
+ // DO CONVERSION
59
+ const converterProviders = slateToLexicalFeature.sanitizedServerFeatureProps.converters;
60
+ const converters = [];
61
+ for (const converter of converterProviders){
62
+ converters.push(converter.converter);
63
+ }
64
+ data[field.name] = convertSlateToLexical({
65
+ converters,
66
+ slateData: data[field.name]
67
+ });
68
+ found++;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ return found;
75
+ };
76
+
77
+ //# sourceMappingURL=migrateDocumentFieldsRecursively.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldAffectsData, fieldHasSubFields, fieldIsArrayType } from 'payload/shared'\n\nimport type {\n SlateNodeConverter,\n SlateNodeConverterProvider,\n} from '../../features/migrations/slateToLexical/converter/types.js'\nimport type { LexicalRichTextAdapter } from '../../types.js'\n\nimport { convertSlateToLexical } from '../../features/migrations/slateToLexical/converter/index.js'\n\ntype NestedRichTextFieldsArgs = {\n data: unknown\n\n fields: Field[]\n found: number\n}\n\nexport const migrateDocumentFieldsRecursively = ({\n data,\n fields,\n found,\n}: NestedRichTextFieldsArgs): number => {\n for (const field of fields) {\n if (fieldHasSubFields(field) && !fieldIsArrayType(field)) {\n if (fieldAffectsData(field) && typeof data[field.name] === 'object') {\n migrateDocumentFieldsRecursively({\n data: data[field.name],\n fields: field.fields,\n found,\n })\n } else {\n migrateDocumentFieldsRecursively({\n data,\n found,\n\n fields: field.fields,\n })\n }\n } else if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n migrateDocumentFieldsRecursively({\n data,\n found,\n\n fields: tab.fields,\n })\n })\n } else if (Array.isArray(data[field.name])) {\n if (field.type === 'blocks') {\n data[field.name].forEach((row, i) => {\n const block = field.blocks.find(({ slug }) => slug === row?.blockType)\n if (block) {\n migrateDocumentFieldsRecursively({\n data: data[field.name][i],\n found,\n\n fields: block.fields,\n })\n }\n })\n }\n\n if (field.type === 'array') {\n data[field.name].forEach((_, i) => {\n migrateDocumentFieldsRecursively({\n data: data[field.name][i],\n found,\n\n fields: field.fields,\n })\n })\n }\n }\n\n if (field.type === 'richText' && Array.isArray(data[field.name])) {\n // Slate richText\n const editor: LexicalRichTextAdapter = field.editor as LexicalRichTextAdapter\n if (editor && typeof editor === 'object') {\n if ('features' in editor && editor.features?.length) {\n // find slatetolexical feature\n const slateToLexicalFeature = editor.editorConfig.resolvedFeatureMap.get('slateToLexical')\n if (slateToLexicalFeature) {\n // DO CONVERSION\n\n const converterProviders = (\n slateToLexicalFeature.sanitizedServerFeatureProps as {\n converters?: SlateNodeConverterProvider[]\n }\n ).converters\n\n const converters: SlateNodeConverter[] = []\n\n for (const converter of converterProviders) {\n converters.push(converter.converter)\n }\n\n data[field.name] = convertSlateToLexical({\n converters,\n slateData: data[field.name],\n })\n\n found++\n }\n }\n }\n }\n }\n\n return found\n}\n"],"names":["fieldAffectsData","fieldHasSubFields","fieldIsArrayType","convertSlateToLexical","migrateDocumentFieldsRecursively","data","fields","found","field","name","type","tabs","forEach","tab","Array","isArray","row","i","block","blocks","find","slug","blockType","_","editor","features","length","slateToLexicalFeature","editorConfig","resolvedFeatureMap","get","converterProviders","sanitizedServerFeatureProps","converters","converter","push","slateData"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,iBAAgB;AAQtF,SAASC,qBAAqB,QAAQ,8DAA6D;AASnG,OAAO,MAAMC,mCAAmC,CAAC,EAC/CC,IAAI,EACJC,MAAM,EACNC,KAAK,EACoB;IACzB,KAAK,MAAMC,SAASF,OAAQ;QAC1B,IAAIL,kBAAkBO,UAAU,CAACN,iBAAiBM,QAAQ;YACxD,IAAIR,iBAAiBQ,UAAU,OAAOH,IAAI,CAACG,MAAMC,IAAI,CAAC,KAAK,UAAU;gBACnEL,iCAAiC;oBAC/BC,MAAMA,IAAI,CAACG,MAAMC,IAAI,CAAC;oBACtBH,QAAQE,MAAMF,MAAM;oBACpBC;gBACF;YACF,OAAO;gBACLH,iCAAiC;oBAC/BC;oBACAE;oBAEAD,QAAQE,MAAMF,MAAM;gBACtB;YACF;QACF,OAAO,IAAIE,MAAME,IAAI,KAAK,QAAQ;YAChCF,MAAMG,IAAI,CAACC,OAAO,CAAC,CAACC;gBAClBT,iCAAiC;oBAC/BC;oBACAE;oBAEAD,QAAQO,IAAIP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AAI,CAACD,UAAUA,SAAS;wBACrC;wBAEA7B,IAAI,CAACG,MAAMC,IAAI,CAAC,GAAGN,sBAAsB;4BACvC8B;4BACAG,WAAW/B,IAAI,CAACG,MAAMC,IAAI,CAAC;wBAC7B;wBAEAF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOA;AACT,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Payload } from 'payload';
2
+ /**
3
+ * This goes through every single document in your payload app and re-saves it, if it has a lexical editor.
4
+ * This way, the data is automatically converted to the new format, and that automatic conversion gets applied to every single document in your app.
5
+ *
6
+ * @param payload
7
+ */
8
+ export declare function upgradeLexicalData({ payload }: {
9
+ payload: Payload;
10
+ }): Promise<void>;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/upgradeLexicalData/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyC,OAAO,EAAE,MAAM,SAAS,CAAA;AAI7E;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBA0BzE"}
@@ -0,0 +1,101 @@
1
+ import { upgradeDocumentFieldsRecursively } from './upgradeDocumentFieldsRecursively.js';
2
+ /**
3
+ * This goes through every single document in your payload app and re-saves it, if it has a lexical editor.
4
+ * This way, the data is automatically converted to the new format, and that automatic conversion gets applied to every single document in your app.
5
+ *
6
+ * @param payload
7
+ */ export async function upgradeLexicalData({ payload }) {
8
+ const collections = payload.config.collections;
9
+ const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [
10
+ null
11
+ ];
12
+ const totalCollections = collections.length;
13
+ for (const locale of allLocales){
14
+ let curCollection = 0;
15
+ for (const collection of collections){
16
+ curCollection++;
17
+ await upgradeCollection({
18
+ collection,
19
+ cur: curCollection,
20
+ locale,
21
+ max: totalCollections,
22
+ payload
23
+ });
24
+ }
25
+ for (const global of payload.config.globals){
26
+ await upgradeGlobal({
27
+ global,
28
+ locale,
29
+ payload
30
+ });
31
+ }
32
+ }
33
+ }
34
+ async function upgradeGlobal({ global, locale, payload }) {
35
+ console.log(`Lexical Upgrader: ${locale}: Upgrading global:`, global.slug);
36
+ const document = await payload.findGlobal({
37
+ slug: global.slug,
38
+ depth: 0,
39
+ locale: locale || undefined,
40
+ overrideAccess: true
41
+ });
42
+ const found = upgradeDocument({
43
+ document,
44
+ fields: global.fields
45
+ });
46
+ if (found) {
47
+ await payload.updateGlobal({
48
+ slug: global.slug,
49
+ data: document,
50
+ depth: 0,
51
+ locale: locale || undefined
52
+ });
53
+ }
54
+ }
55
+ async function upgradeCollection({ collection, cur, locale, max, payload }) {
56
+ console.log(`Lexical Upgrade: ${locale}: Upgrading collection:`, collection.slug, '(' + cur + '/' + max + ')');
57
+ const documentCount = (await payload.count({
58
+ collection: collection.slug,
59
+ depth: 0,
60
+ locale: locale || undefined
61
+ })).totalDocs;
62
+ let page = 1;
63
+ let upgraded = 0;
64
+ while(upgraded < documentCount){
65
+ const documents = await payload.find({
66
+ collection: collection.slug,
67
+ depth: 0,
68
+ locale: locale || undefined,
69
+ overrideAccess: true,
70
+ page,
71
+ pagination: true
72
+ });
73
+ for (const document of documents.docs){
74
+ upgraded++;
75
+ console.log(`Lexical Upgrade: ${locale}: Upgrading collection:`, collection.slug, '(' + cur + '/' + max + ') - Upgrading Document: ' + document.id + ' (' + upgraded + '/' + documentCount + ')');
76
+ const found = upgradeDocument({
77
+ document,
78
+ fields: collection.fields
79
+ });
80
+ if (found) {
81
+ await payload.update({
82
+ id: document.id,
83
+ collection: collection.slug,
84
+ data: document,
85
+ depth: 0,
86
+ locale: locale || undefined
87
+ });
88
+ }
89
+ }
90
+ page++;
91
+ }
92
+ }
93
+ function upgradeDocument({ document, fields }) {
94
+ return !!upgradeDocumentFieldsRecursively({
95
+ data: document,
96
+ fields,
97
+ found: 0
98
+ });
99
+ }
100
+
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/upgradeLexicalData/index.ts"],"sourcesContent":["import type { CollectionConfig, Field, GlobalConfig, Payload } from 'payload'\n\nimport { upgradeDocumentFieldsRecursively } from './upgradeDocumentFieldsRecursively.js'\n\n/**\n * This goes through every single document in your payload app and re-saves it, if it has a lexical editor.\n * This way, the data is automatically converted to the new format, and that automatic conversion gets applied to every single document in your app.\n *\n * @param payload\n */\nexport async function upgradeLexicalData({ payload }: { payload: Payload }) {\n const collections = payload.config.collections\n\n const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [null]\n\n const totalCollections = collections.length\n for (const locale of allLocales) {\n let curCollection = 0\n for (const collection of collections) {\n curCollection++\n await upgradeCollection({\n collection,\n cur: curCollection,\n locale,\n max: totalCollections,\n payload,\n })\n }\n for (const global of payload.config.globals) {\n await upgradeGlobal({\n global,\n locale,\n payload,\n })\n }\n }\n}\n\nasync function upgradeGlobal({\n global,\n locale,\n payload,\n}: {\n global: GlobalConfig\n locale: null | string\n payload: Payload\n}) {\n console.log(`Lexical Upgrader: ${locale}: Upgrading global:`, global.slug)\n\n const document = await payload.findGlobal({\n slug: global.slug,\n depth: 0,\n locale: locale || undefined,\n overrideAccess: true,\n })\n\n const found = upgradeDocument({\n document,\n fields: global.fields,\n })\n\n if (found) {\n await payload.updateGlobal({\n slug: global.slug,\n data: document,\n depth: 0,\n locale: locale || undefined,\n })\n }\n}\n\nasync function upgradeCollection({\n collection,\n cur,\n locale,\n max,\n payload,\n}: {\n collection: CollectionConfig\n cur: number\n locale: null | string\n max: number\n payload: Payload\n}) {\n console.log(\n `Lexical Upgrade: ${locale}: Upgrading collection:`,\n collection.slug,\n '(' + cur + '/' + max + ')',\n )\n\n const documentCount = (\n await payload.count({\n collection: collection.slug,\n depth: 0,\n locale: locale || undefined,\n })\n ).totalDocs\n\n let page = 1\n let upgraded = 0\n\n while (upgraded < documentCount) {\n const documents = await payload.find({\n collection: collection.slug,\n depth: 0,\n locale: locale || undefined,\n overrideAccess: true,\n page,\n pagination: true,\n })\n\n for (const document of documents.docs) {\n upgraded++\n console.log(\n `Lexical Upgrade: ${locale}: Upgrading collection:`,\n collection.slug,\n '(' +\n cur +\n '/' +\n max +\n ') - Upgrading Document: ' +\n document.id +\n ' (' +\n upgraded +\n '/' +\n documentCount +\n ')',\n )\n const found = upgradeDocument({\n document,\n fields: collection.fields,\n })\n\n if (found) {\n await payload.update({\n id: document.id,\n collection: collection.slug,\n data: document,\n depth: 0,\n locale: locale || undefined,\n })\n }\n }\n page++\n }\n}\n\nfunction upgradeDocument({\n document,\n fields,\n}: {\n document: Record<string, unknown>\n fields: Field[]\n}): boolean {\n return !!upgradeDocumentFieldsRecursively({\n data: document,\n fields,\n found: 0,\n })\n}\n"],"names":["upgradeDocumentFieldsRecursively","upgradeLexicalData","payload","collections","config","allLocales","localization","localeCodes","totalCollections","length","locale","curCollection","collection","upgradeCollection","cur","max","global","globals","upgradeGlobal","console","log","slug","document","findGlobal","depth","undefined","overrideAccess","found","upgradeDocument","fields","updateGlobal","data","documentCount","count","totalDocs","page","upgraded","documents","find","pagination","docs","id","update"],"mappings":"AAEA,SAASA,gCAAgC,QAAQ,wCAAuC;AAExF;;;;;CAKC,GACD,OAAO,eAAeC,mBAAmB,EAAEC,OAAO,EAAwB;IACxE,MAAMC,cAAcD,QAAQE,MAAM,CAACD,WAAW;IAE9C,MAAME,aAAaH,QAAQE,MAAM,CAACE,YAAY,GAAGJ,QAAQE,MAAM,CAACE,YAAY,CAACC,WAAW,GAAG;QAAC;KAAK;IAEjG,MAAMC,mBAAmBL,YAAYM,MAAM;IAC3C,KAAK,MAAMC,UAAUL,WAAY;QAC/B,IAAIM,gBAAgB;QACpB,KAAK,MAAMC,cAAcT,YAAa;YACpCQ;YACA,MAAME,kBAAkB;gBACtBD;gBACAE,KAAKH;gBACLD;gBACAK,KAAKP;gBACLN;YACF;QACF;QACA,KAAK,MAAMc,UAAUd,QAAQE,MAA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,GAAG,CACT,CAAC,iBAAiB,EAAEV,OAAO,uBAAuB,CAAC,EACnDE,WAAWS,IAAI,EACf,MACEP,MACA,MACAC,MACA,6BACAO,SAASmB,EAAE,GACX,OACAL,WACA,MACAJ,gBACA;YAEJ,MAAML,QAAQC,gBAAgB;gBAC5BN;gBACAO,QAAQjB,WAAWiB,MAAM;YAC3B;YAEA,IAAIF,OAAO;gBACT,MAAMzB,QAAQwC,MAAM,CAAC;oBACnBD,IAAInB,SAASmB,EAAE;oBACf7B,YAAYA,WAAWS,IAAI;oBAC3BU,MAAMT;oBACNE,OAAO;oBACPd,QAAQA,UAAUe;gBACpB;YACF;QACF;QACAU;IACF;AACF;AAEA,SAASP,gBAAgB,EACvBN,QAAQ,EACRO,MAAM,EAIP;IACC,OAAO,CAAC,CAAC7B,iCAAiC;QACxC+B,MAAMT;QACNO;QACAF,OAAO;IACT;AACF"}
@@ -0,0 +1,9 @@
1
+ import type { Field } from 'payload';
2
+ type NestedRichTextFieldsArgs = {
3
+ data: unknown;
4
+ fields: Field[];
5
+ found: number;
6
+ };
7
+ export declare const upgradeDocumentFieldsRecursively: ({ data, fields, found, }: NestedRichTextFieldsArgs) => number;
8
+ export {};
9
+ //# sourceMappingURL=upgradeDocumentFieldsRecursively.d.ts.map