@payloadcms/richtext-lexical 3.0.0-alpha.61 → 3.0.0-alpha.63

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 (98) hide show
  1. package/dist/field/features/blocks/component/index.d.ts.map +1 -1
  2. package/dist/field/features/blocks/component/index.js +5 -2
  3. package/dist/field/features/blocks/component/index.js.map +1 -1
  4. package/dist/field/features/blocks/feature.server.d.ts +4 -3
  5. package/dist/field/features/blocks/feature.server.d.ts.map +1 -1
  6. package/dist/field/features/blocks/feature.server.js +16 -30
  7. package/dist/field/features/blocks/feature.server.js.map +1 -1
  8. package/dist/field/features/converters/html/converter/index.d.ts.map +1 -1
  9. package/dist/field/features/converters/html/converter/index.js +22 -17
  10. package/dist/field/features/converters/html/converter/index.js.map +1 -1
  11. package/dist/field/features/converters/html/field/index.d.ts +8 -2
  12. package/dist/field/features/converters/html/field/index.d.ts.map +1 -1
  13. package/dist/field/features/converters/html/field/index.js +6 -3
  14. package/dist/field/features/converters/html/field/index.js.map +1 -1
  15. package/dist/field/features/horizontalrule/component/index.d.ts +10 -0
  16. package/dist/field/features/horizontalrule/component/index.d.ts.map +1 -0
  17. package/dist/field/features/horizontalrule/component/index.js +64 -0
  18. package/dist/field/features/horizontalrule/component/index.js.map +1 -0
  19. package/dist/field/features/horizontalrule/feature.client.d.ts +3 -0
  20. package/dist/field/features/horizontalrule/feature.client.d.ts.map +1 -0
  21. package/dist/field/features/horizontalrule/feature.client.js +53 -0
  22. package/dist/field/features/horizontalrule/feature.client.js.map +1 -0
  23. package/dist/field/features/horizontalrule/feature.server.d.ts +3 -0
  24. package/dist/field/features/horizontalrule/feature.server.d.ts.map +1 -0
  25. package/dist/field/features/horizontalrule/feature.server.js +36 -0
  26. package/dist/field/features/horizontalrule/feature.server.js.map +1 -0
  27. package/dist/field/features/horizontalrule/markdownTransformer.d.ts +3 -0
  28. package/dist/field/features/horizontalrule/markdownTransformer.d.ts.map +1 -0
  29. package/dist/field/features/horizontalrule/markdownTransformer.js +23 -0
  30. package/dist/field/features/horizontalrule/markdownTransformer.js.map +1 -0
  31. package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.d.ts +55 -0
  32. package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.d.ts.map +1 -0
  33. package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.js +89 -0
  34. package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.js.map +1 -0
  35. package/dist/field/features/horizontalrule/plugin/index.d.ts +6 -0
  36. package/dist/field/features/horizontalrule/plugin/index.d.ts.map +1 -0
  37. package/dist/field/features/horizontalrule/plugin/index.js +34 -0
  38. package/dist/field/features/horizontalrule/plugin/index.js.map +1 -0
  39. package/dist/field/features/horizontalrule/plugin/index.scss +20 -0
  40. package/dist/field/features/link/drawer/index.js +3 -2
  41. package/dist/field/features/link/drawer/index.js.map +1 -1
  42. package/dist/field/features/link/feature.server.d.ts.map +1 -1
  43. package/dist/field/features/link/feature.server.js +17 -3
  44. package/dist/field/features/link/feature.server.js.map +1 -1
  45. package/dist/field/features/lists/htmlConverter.d.ts.map +1 -1
  46. package/dist/field/features/lists/htmlConverter.js +12 -4
  47. package/dist/field/features/lists/htmlConverter.js.map +1 -1
  48. package/dist/field/features/types.d.ts +1 -5
  49. package/dist/field/features/types.d.ts.map +1 -1
  50. package/dist/field/features/types.js.map +1 -1
  51. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js +3 -2
  52. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js.map +1 -1
  53. package/dist/field/features/upload/component/index.d.ts.map +1 -1
  54. package/dist/field/features/upload/component/index.js +2 -2
  55. package/dist/field/features/upload/component/index.js.map +1 -1
  56. package/dist/field/features/upload/feature.server.d.ts.map +1 -1
  57. package/dist/field/features/upload/feature.server.js +28 -9
  58. package/dist/field/features/upload/feature.server.js.map +1 -1
  59. package/dist/field/features/upload/validate.d.ts.map +1 -1
  60. package/dist/field/features/upload/validate.js +4 -6
  61. package/dist/field/features/upload/validate.js.map +1 -1
  62. package/dist/field/lexical/config/server/default.d.ts.map +1 -1
  63. package/dist/field/lexical/config/server/default.js +3 -1
  64. package/dist/field/lexical/config/server/default.js.map +1 -1
  65. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.d.ts.map +1 -1
  66. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js +11 -6
  67. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
  68. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
  69. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js +8 -3
  70. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
  71. package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.d.ts +9 -0
  72. package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.d.ts.map +1 -0
  73. package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.js +35 -0
  74. package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.js.map +1 -0
  75. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.d.ts +1 -1
  76. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
  77. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js +17 -7
  78. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
  79. package/dist/field/lexical/theme/EditorTheme.scss +4 -0
  80. package/dist/field/lexical/ui/icons/HorizontalRule/index.d.ts +3 -0
  81. package/dist/field/lexical/ui/icons/HorizontalRule/index.d.ts.map +1 -0
  82. package/dist/field/lexical/ui/icons/HorizontalRule/index.js +19 -0
  83. package/dist/field/lexical/ui/icons/HorizontalRule/index.js.map +1 -0
  84. package/dist/generateComponentMap.d.ts.map +1 -1
  85. package/dist/generateComponentMap.js +22 -19
  86. package/dist/generateComponentMap.js.map +1 -1
  87. package/dist/generateSchemaMap.js +10 -9
  88. package/dist/generateSchemaMap.js.map +1 -1
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js.map +1 -1
  92. package/dist/scss/app.scss +2 -3
  93. package/dist/scss/vars.scss +0 -7
  94. package/package.json +14 -14
  95. package/src/index.ts +5 -1
  96. package/components.d.ts +0 -6
  97. package/components.js +0 -7
  98. package/dist/scss/fonts.scss +0 -75
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAkBzD,OAAO,cAAc,CAAA;AAGrB,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE1B,QAAQ,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,mBAAmB,EAAE,WAAW,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAuH1C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAkBzD,OAAO,cAAc,CAAA;AAGrB,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE1B,QAAQ,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,mBAAmB,EAAE,WAAW,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyH1C,CAAA"}
@@ -118,8 +118,11 @@ export const BlockComponent = (props)=>{
118
118
  initialState,
119
119
  reducedBlock,
120
120
  blockFieldWrapperName,
121
- onChange
122
- ]);
121
+ onChange,
122
+ schemaFieldsPath,
123
+ path
124
+ ]) // Adding formData to the dependencies here might break it
125
+ ;
123
126
  return /*#__PURE__*/ React.createElement("div", {
124
127
  className: baseClass
125
128
  }, formContent);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/field/features/blocks/component/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui/forms/Form'\n\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { type BlockFields } from '../nodes/BlocksNode.js'\nconst baseClass = 'lexical-block'\n\nimport type { ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { FormState } from 'payload/types'\n\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useFormSubmitted } from '@payloadcms/ui/forms/Form'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ClientComponentProps } from '../../types.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { BlockContent } from './BlockContent.js'\nimport './index.scss'\nimport { removeEmptyArrayValues } from './removeEmptyArrayValues.js'\n\ntype Props = {\n blockFieldWrapperName: string\n children?: React.ReactNode\n\n formData: BlockFields\n nodeKey?: string\n /**\n * This transformedFormData already comes wrapped in blockFieldWrapperName\n */\n transformedFormData: BlockFields\n}\n\nexport const BlockComponent: React.FC<Props> = (props) => {\n const { blockFieldWrapperName, formData, nodeKey } = props\n const config = useConfig()\n const submitted = useFormSubmitted()\n const { id } = useDocumentInfo()\n const { path, schemaPath } = useFieldProps()\n const { editorConfig, field: parentLexicalRichTextField } = useEditorConfigContext()\n\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.blocks.fields.${formData?.blockType}`\n const schemaFieldsPath = `${schemaPath}.feature.blocks.${formData?.blockType}`\n\n const reducedBlock: ReducedBlock = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.clientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedBlocks?.find((block) => block.slug === formData?.blockType)\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath)\n // Field Schema\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: JSON.parse(JSON.stringify(formData)),\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n if (state) {\n setInitialState({\n ...removeEmptyArrayValues({ fields: state }),\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n })\n }\n }\n\n if (formData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const formState = 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 return {\n ...formState,\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n }\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id, formData.blockName],\n )\n\n // Memoized Form JSX\n const formContent = useMemo(() => {\n return (\n reducedBlock &&\n initialState !== false && (\n <Form\n // @ts-expect-error TODO: Fix this\n fields={fieldMap}\n initialState={initialState}\n onChange={[onChange]}\n submitted={submitted}\n uuid={uuid()}\n >\n <BlockContent\n baseClass={baseClass}\n field={parentLexicalRichTextField}\n formData={formData}\n formSchema={Array.isArray(fieldMap) ? fieldMap : []}\n nodeKey={nodeKey}\n path={`${path}.feature.blocks.${formData.blockType}`}\n reducedBlock={reducedBlock}\n schemaPath={schemaFieldsPath}\n />\n </Form>\n )\n )\n }, [\n fieldMap,\n parentLexicalRichTextField,\n nodeKey,\n submitted,\n initialState,\n reducedBlock,\n blockFieldWrapperName,\n onChange,\n ])\n\n return <div className={baseClass}>{formContent}</div>\n}\n"],"names":["Form","React","useCallback","useEffect","useMemo","useState","baseClass","useFieldProps","useFormSubmitted","useConfig","useDocumentInfo","getFormState","v4","uuid","useEditorConfigContext","BlockContent","removeEmptyArrayValues","BlockComponent","props","blockFieldWrapperName","formData","nodeKey","config","submitted","id","path","schemaPath","editorConfig","field","parentLexicalRichTextField","initialState","setInitialState","richTextComponentMap","componentMapRenderedFieldsPath","blockType","schemaFieldsPath","reducedBlock","resolvedFeatureMap","get","clientFeatureProps","reducedBlocks","find","block","slug","fieldMap","awaitInitialState","state","apiRoute","routes","api","body","data","JSON","parse","stringify","operation","serverURL","fields","blockName","initialValue","passesCondition","valid","value","onChange","formState","prevFormState","formContent","formSchema","Array","isArray","div","className"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,IAAI,QAAQ,4BAA2B;AAChD,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAGxE,MAAMC,YAAY;AAKlB,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,SAAS,QAAQ,kCAAiC;AA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S;;IAKtB,GAAG;QACDS;QACAf;QACAR;QACAE;QACAO;QACAM;QACAjB;QACA4C;KACD;IAED,qBAAO,oBAACO;QAAIC,WAAWjE;OAAY4D;AACrC,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/field/features/blocks/component/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui/forms/Form'\n\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { type BlockFields } from '../nodes/BlocksNode.js'\nconst baseClass = 'lexical-block'\n\nimport type { ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { FormState } from 'payload/types'\n\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useFormSubmitted } from '@payloadcms/ui/forms/Form'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ClientComponentProps } from '../../types.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { BlockContent } from './BlockContent.js'\nimport './index.scss'\nimport { removeEmptyArrayValues } from './removeEmptyArrayValues.js'\n\ntype Props = {\n blockFieldWrapperName: string\n children?: React.ReactNode\n\n formData: BlockFields\n nodeKey?: string\n /**\n * This transformedFormData already comes wrapped in blockFieldWrapperName\n */\n transformedFormData: BlockFields\n}\n\nexport const BlockComponent: React.FC<Props> = (props) => {\n const { blockFieldWrapperName, formData, nodeKey } = props\n const config = useConfig()\n const submitted = useFormSubmitted()\n const { id } = useDocumentInfo()\n const { path, schemaPath } = useFieldProps()\n const { editorConfig, field: parentLexicalRichTextField } = useEditorConfigContext()\n\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.blocks.fields.${formData?.blockType}`\n const schemaFieldsPath = `${schemaPath}.feature.blocks.${formData?.blockType}`\n\n const reducedBlock: ReducedBlock = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.clientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedBlocks?.find((block) => block.slug === formData?.blockType)\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath)\n // Field Schema\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: JSON.parse(JSON.stringify(formData)),\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n if (state) {\n setInitialState({\n ...removeEmptyArrayValues({ fields: state }),\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n })\n }\n }\n\n if (formData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const formState = 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 return {\n ...formState,\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n }\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id, formData.blockName],\n )\n\n // Memoized Form JSX\n const formContent = useMemo(() => {\n return (\n reducedBlock &&\n initialState !== false && (\n <Form\n // @ts-expect-error TODO: Fix this\n fields={fieldMap}\n initialState={initialState}\n onChange={[onChange]}\n submitted={submitted}\n uuid={uuid()}\n >\n <BlockContent\n baseClass={baseClass}\n field={parentLexicalRichTextField}\n formData={formData}\n formSchema={Array.isArray(fieldMap) ? fieldMap : []}\n nodeKey={nodeKey}\n path={`${path}.feature.blocks.${formData.blockType}`}\n reducedBlock={reducedBlock}\n schemaPath={schemaFieldsPath}\n />\n </Form>\n )\n )\n }, [\n fieldMap,\n parentLexicalRichTextField,\n nodeKey,\n submitted,\n initialState,\n reducedBlock,\n blockFieldWrapperName,\n onChange,\n schemaFieldsPath,\n path,\n ]) // Adding formData to the dependencies here might break it\n\n return <div className={baseClass}>{formContent}</div>\n}\n"],"names":["Form","React","useCallback","useEffect","useMemo","useState","baseClass","useFieldProps","useFormSubmitted","useConfig","useDocumentInfo","getFormState","v4","uuid","useEditorConfigContext","BlockContent","removeEmptyArrayValues","BlockComponent","props","blockFieldWrapperName","formData","nodeKey","config","submitted","id","path","schemaPath","editorConfig","field","parentLexicalRichTextField","initialState","setInitialState","richTextComponentMap","componentMapRenderedFieldsPath","blockType","schemaFieldsPath","reducedBlock","resolvedFeatureMap","get","clientFeatureProps","reducedBlocks","find","block","slug","fieldMap","awaitInitialState","state","apiRoute","routes","api","body","data","JSON","parse","stringify","operation","serverURL","fields","blockName","initialValue","passesCondition","valid","value","onChange","formState","prevFormState","formContent","formSchema","Array","isArray","div","className"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,IAAI,QAAQ,4BAA2B;AAChD,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAGxE,MAAMC,YAAY;AAKlB,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,YAAY,QAAQ,wCAAuC;AACpE,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAKjC,SAASC,sBAAsB,QAAQ,yDAAwD;AAC/F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;AACrC,EAAC"}
@@ -1,10 +1,11 @@
1
1
  import type { Block, FieldWithRichTextRequiredEditor } from 'payload/types';
2
2
  import type { FeatureProviderProviderServer } from '../types.js';
3
3
  import type { BlocksFeatureClientProps } from './feature.client.js';
4
+ export type LexicalBlock = Omit<Block, 'fields'> & {
5
+ fields: FieldWithRichTextRequiredEditor[];
6
+ };
4
7
  export type BlocksFeatureProps = {
5
- blocks: Array<Omit<Block, 'fields'> & {
6
- fields: FieldWithRichTextRequiredEditor[];
7
- }>;
8
+ blocks: LexicalBlock[];
8
9
  };
9
10
  export declare const BlocksFeature: FeatureProviderProviderServer<BlocksFeatureProps, BlocksFeatureClientProps>;
10
11
  //# sourceMappingURL=feature.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAqB,+BAA+B,EAAE,MAAM,eAAe,CAAA;AAK9F,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAQnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,KAAK,CACX,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG;QACtB,MAAM,EAAE,+BAA+B,EAAE,CAAA;KAC1C,CACF,CAAA;CACF,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,6BAA6B,CACvD,kBAAkB,EAClB,wBAAwB,CAwIzB,CAAA"}
1
+ {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAqB,+BAA+B,EAAE,MAAM,eAAe,CAAA;AAM9F,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAQnE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG;IACjD,MAAM,EAAE,+BAA+B,EAAE,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,YAAY,EAAE,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,6BAA6B,CACvD,kBAAkB,EAClB,wBAAwB,CAwHzB,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { traverseFields } from '@payloadcms/next/utilities';
1
2
  import { baseBlockFields, sanitizeFields } from 'payload/config';
2
3
  import { fieldsToJSONSchema, formatLabels } from 'payload/utilities';
3
4
  import { cloneDeep } from '../../lexical/utils/cloneDeep.js';
@@ -12,6 +13,7 @@ export const BlocksFeature = (props)=>{
12
13
  const blockCopy = cloneDeep(block);
13
14
  return {
14
15
  ...blockCopy,
16
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
15
17
  fields: blockCopy.fields.concat(baseBlockFields),
16
18
  labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels
17
19
  };
@@ -37,38 +39,22 @@ export const BlocksFeature = (props)=>{
37
39
  return {
38
40
  ClientComponent: BlocksFeatureClientComponent,
39
41
  clientFeatureProps: clientProps,
40
- generateSchemaMap: ({ config, props, schemaMap: schemaMapFromProps, schemaPath })=>{
41
- const schemaMap = {};
42
+ generateSchemaMap: ({ config, i18n, props })=>{
43
+ const validRelationships = config.collections.map((c)=>c.slug) || [];
42
44
  /**
43
- * Add sub-fields to the schemaMap. E.g. if you have an array field as part of the block and it runs addRow, it will request these
44
- * sub-fields from the component map. Thus we need to put them in the component map here.
45
- */ const handleFields = (parentPath, fields)=>{
46
- for (const field of fields){
47
- if ('name' in field && 'fields' in field) {
48
- schemaMap[parentPath + '.' + field.name] = field.fields;
49
- handleFields(parentPath + '.' + field.name, field.fields);
50
- }
51
- if ('blocks' in field) {
52
- for (const block of field.blocks){
53
- schemaMap[parentPath + '.' + field.name + '.' + block.slug] = block.fields || [];
54
- handleFields(parentPath + '.' + field.name + '.' + block.slug, block.fields);
55
- }
56
- }
57
- if ('tabs' in field) {
58
- for (const tab of field.tabs){
59
- if ('name' in tab) {
60
- schemaMap[parentPath + '.' + tab.name] = tab.fields || [];
61
- handleFields(parentPath + '.' + tab.name, tab.fields);
62
- } else {
63
- handleFields(parentPath, tab.fields);
64
- }
65
- }
66
- }
67
- }
68
- };
45
+ * Add sub-fields to the schemaMap. E.g. if you have an array field as part of the block, and it runs addRow, it will request these
46
+ * sub-fields from the component map. Thus, we need to put them in the component map here.
47
+ */ const schemaMap = new Map();
69
48
  for (const block of props.blocks){
70
- schemaMap[block.slug] = block.fields || [];
71
- handleFields(block.slug, block.fields);
49
+ schemaMap.set(block.slug, block.fields || []);
50
+ traverseFields({
51
+ config,
52
+ fields: block.fields,
53
+ i18n,
54
+ schemaMap,
55
+ schemaPath: block.slug,
56
+ validRelationships
57
+ });
72
58
  }
73
59
  return schemaMap;
74
60
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/field/features/blocks/feature.server.ts"],"sourcesContent":["import type { Block, BlockField, Field, FieldWithRichTextRequiredEditor } from 'payload/types'\n\nimport { baseBlockFields, sanitizeFields } from 'payload/config'\nimport { fieldsToJSONSchema, formatLabels } from 'payload/utilities'\n\nimport type { FeatureProviderProviderServer } from '../types.js'\nimport type { BlocksFeatureClientProps } from './feature.client.js'\n\nimport { cloneDeep } from '../../lexical/utils/cloneDeep.js'\nimport { BlocksFeatureClientComponent } from './feature.client.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { blockPopulationPromiseHOC } from './populationPromise.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type BlocksFeatureProps = {\n blocks: Array<\n Omit<Block, 'fields'> & {\n fields: FieldWithRichTextRequiredEditor[]\n }\n >\n}\n\nexport const BlocksFeature: FeatureProviderProviderServer<\n BlocksFeatureProps,\n BlocksFeatureClientProps\n> = (props) => {\n // Sanitization taken from payload/src/fields/config/sanitize.ts\n\n if (props?.blocks?.length) {\n props.blocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n\n return {\n ...blockCopy,\n fields: blockCopy.fields.concat(baseBlockFields),\n labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels,\n }\n })\n // unSanitizedBlock.fields are sanitized in the React component and not here.\n // That's because we do not have access to the payload config here.\n }\n\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n reducedBlocks: [],\n }\n for (const block of props.blocks) {\n clientProps.reducedBlocks.push({\n slug: block.slug,\n fieldMap: [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n labels: block.labels,\n })\n }\n\n return {\n feature: () => {\n return {\n ClientComponent: BlocksFeatureClientComponent,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ config, props, schemaMap: schemaMapFromProps, schemaPath }) => {\n const schemaMap: {\n [key: string]: Field[]\n } = {}\n\n /**\n * Add sub-fields to the schemaMap. E.g. if you have an array field as part of the block and it runs addRow, it will request these\n * sub-fields from the component map. Thus we need to put them in the component map here.\n */\n const handleFields = (parentPath: string, fields: Field[]) => {\n for (const field of fields) {\n if ('name' in field && 'fields' in field) {\n schemaMap[parentPath + '.' + field.name] = field.fields\n handleFields(parentPath + '.' + field.name, field.fields)\n }\n if ('blocks' in field) {\n for (const block of field.blocks) {\n schemaMap[parentPath + '.' + field.name + '.' + block.slug] = block.fields || []\n handleFields(parentPath + '.' + field.name + '.' + block.slug, block.fields)\n }\n }\n if ('tabs' in field) {\n for (const tab of field.tabs) {\n if ('name' in tab) {\n schemaMap[parentPath + '.' + tab.name] = tab.fields || []\n handleFields(parentPath + '.' + tab.name, tab.fields)\n } else {\n handleFields(parentPath, tab.fields)\n }\n }\n }\n }\n }\n\n for (const block of props.blocks) {\n schemaMap[block.slug] = block.fields || []\n handleFields(block.slug, block.fields)\n }\n\n return schemaMap\n },\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length) {\n return currentSchema\n }\n\n // sanitize blocks\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const sanitizedBlocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n return {\n ...blockCopy,\n fields: sanitizeFields({\n config,\n fields: blockCopy.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n }),\n }\n })\n\n const blocksField: BlockField = {\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: sanitizedBlocks,\n }\n // This is only done so that interfaceNameDefinitions sets those block's interfaceNames.\n // we don't actually use the JSON Schema itself in the generated types yet.\n fieldsToJSONSchema(\n collectionIDFieldTypes,\n [blocksField],\n interfaceNameDefinitions,\n config,\n )\n\n return currentSchema\n },\n },\n nodes: [\n {\n node: BlockNode,\n populationPromises: [blockPopulationPromiseHOC(props)],\n validations: [blockValidationHOC(props)],\n },\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blocks',\n serverFeatureProps: props,\n }\n}\n"],"names":["baseBlockFields","sanitizeFields","fieldsToJSONSchema","formatLabels","cloneDeep","BlocksFeatureClientComponent","BlockNode","blockPopulationPromiseHOC","blockValidationHOC","BlocksFeature","props","blocks","length","map","block","blockCopy","fields","concat","labels","slug","clientProps","reducedBlocks","push","fieldMap","imageAltText","imageURL","feature","ClientComponent","clientFeatureProps","generateSchemaMap","config","schemaMap","schemaMapFromProps","schemaPath","handleFields","parentPath","field","name","tab","tabs","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","interfaceNameDefinitions","validRelationships","collections","c","sanitizedBlocks","requireFieldLevelRichTextEditor","blocksField","type","nodes","node","populationPromises","validations","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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wBACT;wBAEA,kBAAkB;wBAClB,MAAME,qBAAqBf,OAAOgB,WAAW,CAACjC,GAAG,CAAC,CAACkC,IAAMA,EAAE5B,IAAI,KAAK,EAAE;wBAEtE,MAAM6B,kBAAkBtC,MAAMC,MAAM,CAACE,GAAG,CAAC,CAACC;4BACxC,MAAMC,YAAYX,UAAUU;4BAC5B,OAAO;gCACL,GAAGC,SAAS;gCACZC,QAAQf,eAAe;oCACrB6B;oCACAd,QAAQD,UAAUC,MAAM;oCACxBiC,iCAAiC;oCACjCJ;gCACF;4BACF;wBACF;wBAEA,MAAMK,cAA0B;4BAC9Bb,MAAMD,OAAOC,OAAO;4BACpBc,MAAM;4BACNxC,QAAQqC;wBACV;wBACA,wFAAwF;wBACxF,2EAA2E;wBAC3E9C,mBACEwC,wBACA;4BAACQ;yBAAY,EACbN,0BACAd;wBAGF,OAAOa;oBACT;gBACF;gBACAS,OAAO;oBACL;wBACEC,MAAM/C;wBACNgD,oBAAoB;4BAAC/C,0BAA0BG;yBAAO;wBACtD6C,aAAa;4BAAC/C,mBAAmBE;yBAAO;oBAC1C;iBACD;gBACD8C,oBAAoB9C;YACtB;QACF;QACA+C,KAAK;QACLD,oBAAoB9C;IACtB;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/field/features/blocks/feature.server.ts"],"sourcesContent":["import type { Block, BlockField, Field, FieldWithRichTextRequiredEditor } from 'payload/types'\n\nimport { traverseFields } from '@payloadcms/next/utilities'\nimport { baseBlockFields, sanitizeFields } from 'payload/config'\nimport { fieldsToJSONSchema, formatLabels } from 'payload/utilities'\n\nimport type { FeatureProviderProviderServer } from '../types.js'\nimport type { BlocksFeatureClientProps } from './feature.client.js'\n\nimport { cloneDeep } from '../../lexical/utils/cloneDeep.js'\nimport { BlocksFeatureClientComponent } from './feature.client.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { blockPopulationPromiseHOC } from './populationPromise.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type LexicalBlock = Omit<Block, 'fields'> & {\n fields: FieldWithRichTextRequiredEditor[]\n}\n\nexport type BlocksFeatureProps = {\n blocks: LexicalBlock[]\n}\n\nexport const BlocksFeature: FeatureProviderProviderServer<\n BlocksFeatureProps,\n BlocksFeatureClientProps\n> = (props) => {\n // Sanitization taken from payload/src/fields/config/sanitize.ts\n\n if (props?.blocks?.length) {\n props.blocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n\n return {\n ...blockCopy,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n fields: blockCopy.fields.concat(baseBlockFields as FieldWithRichTextRequiredEditor[]),\n labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels,\n }\n })\n // unSanitizedBlock.fields are sanitized in the React component and not here.\n // That's because we do not have access to the payload config here.\n }\n\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n reducedBlocks: [],\n }\n for (const block of props.blocks) {\n clientProps.reducedBlocks.push({\n slug: block.slug,\n fieldMap: [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n labels: block.labels,\n })\n }\n\n return {\n feature: () => {\n return {\n ClientComponent: BlocksFeatureClientComponent,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ config, i18n, props }) => {\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n /**\n * Add sub-fields to the schemaMap. E.g. if you have an array field as part of the block, and it runs addRow, it will request these\n * sub-fields from the component map. Thus, we need to put them in the component map here.\n */\n const schemaMap = new Map<string, Field[]>()\n\n for (const block of props.blocks) {\n schemaMap.set(block.slug, block.fields || [])\n\n traverseFields({\n config,\n fields: block.fields,\n i18n,\n schemaMap,\n schemaPath: block.slug,\n validRelationships,\n })\n }\n\n return schemaMap\n },\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length) {\n return currentSchema\n }\n\n // sanitize blocks\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const sanitizedBlocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n return {\n ...blockCopy,\n fields: sanitizeFields({\n config,\n fields: blockCopy.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n }),\n }\n })\n\n const blocksField: BlockField = {\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: sanitizedBlocks,\n }\n // This is only done so that interfaceNameDefinitions sets those block's interfaceNames.\n // we don't actually use the JSON Schema itself in the generated types yet.\n fieldsToJSONSchema(\n collectionIDFieldTypes,\n [blocksField],\n interfaceNameDefinitions,\n config,\n )\n\n return currentSchema\n },\n },\n nodes: [\n {\n node: BlockNode,\n populationPromises: [blockPopulationPromiseHOC(props)],\n validations: [blockValidationHOC(props)],\n },\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blocks',\n serverFeatureProps: props,\n }\n}\n"],"names":["traverseFields","baseBlockFields","sanitizeFields","fieldsToJSONSchema","formatLabels","cloneDeep","BlocksFeatureClientComponent","BlockNode","blockPopulationPromiseHOC","blockValidationHOC","BlocksFeature","props","blocks","length","map","block","blockCopy","fields","concat","labels","slug","clientProps","reducedBlocks","push","fieldMap","imageAltText","imageURL","feature","ClientComponent","clientFeatureProps","generateSchemaMap","config","i18n","validRelationships","collections","c","schemaMap","Map","set","schemaPath","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","field","interfaceNameDefinitions","sanitizedBlocks","requireFieldLevelRichTextEditor","blocksField","name","type","nodes","node","populationPromises","validations","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,eAAe,EAAEC,cAAc,QAAQ,iBAAgB;AAChE,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,oBAAmB;AAKpE,SA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I,EAAEL,MAAME,MAAM,IAAI,EAAE;wBAE5CjB,eAAe;4BACb+B;4BACAd,QAAQF,MAAME,MAAM;4BACpBe;4BACAI;4BACAG,YAAYxB,MAAMK,IAAI;4BACtBa;wBACF;oBACF;oBAEA,OAAOG;gBACT;gBACAI,gBAAgB;oBACdC,oBAAoB,CAAC,EACnBC,sBAAsB,EACtBX,MAAM,EACNY,aAAa,EACbC,KAAK,EACLC,wBAAwB,EACzB;wBACC,IAAI,CAAClC,OAAOC,QAAQC,QAAQ;4BAC1B,OAAO8B;wBACT;wBAEA,kBAAkB;wBAClB,MAAMV,qBAAqBF,OAAOG,WAAW,CAACpB,GAAG,CAAC,CAACqB,IAAMA,EAAEf,IAAI,KAAK,EAAE;wBAEtE,MAAM0B,kBAAkBnC,MAAMC,MAAM,CAACE,GAAG,CAAC,CAACC;4BACxC,MAAMC,YAAYX,UAAUU;4BAC5B,OAAO;gCACL,GAAGC,SAAS;gCACZC,QAAQf,eAAe;oCACrB6B;oCACAd,QAAQD,UAAUC,MAAM;oCACxB8B,iCAAiC;oCACjCd;gCACF;4BACF;wBACF;wBAEA,MAAMe,cAA0B;4BAC9BC,MAAML,OAAOK,OAAO;4BACpBC,MAAM;4BACNtC,QAAQkC;wBACV;wBACA,wFAAwF;wBACxF,2EAA2E;wBAC3E3C,mBACEuC,wBACA;4BAACM;yBAAY,EACbH,0BACAd;wBAGF,OAAOY;oBACT;gBACF;gBACAQ,OAAO;oBACL;wBACEC,MAAM7C;wBACN8C,oBAAoB;4BAAC7C,0BAA0BG;yBAAO;wBACtD2C,aAAa;4BAAC7C,mBAAmBE;yBAAO;oBAC1C;iBACD;gBACD4C,oBAAoB5C;YACtB;QACF;QACA6C,KAAK;QACLD,oBAAoB5C;IACtB;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/converters/html/converter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAA;AAEhF,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,IAAI,EACJ,OAAO,GACR,EAAE;IACD,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,IAAI,EAAE,qBAAqB,CAAA;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAUlB;AAED,wBAAsB,yBAAyB,CAAC,EAC9C,UAAU,EACV,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,YAAY,EAAE,qBAAqB,EAAE,CAAA;IACrC,MAAM,EAAE,+BAA+B,CAAA;IACvC;;OAEG;IACH,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/converters/html/converter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAA;AAEhF,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,IAAI,EACJ,OAAO,GACR,EAAE;IACD,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,IAAI,EAAE,qBAAqB,CAAA;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAUlB;AAED,wBAAsB,yBAAyB,CAAC,EAC9C,UAAU,EACV,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,YAAY,EAAE,qBAAqB,EAAE,CAAA;IACrC,MAAM,EAAE,+BAA+B,CAAA;IACvC;;OAEG;IACH,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoClB"}
@@ -13,25 +13,30 @@ export async function convertLexicalNodesToHTML({ converters, lexicalNodes, pare
13
13
  const unknownConverter = converters.find((converter)=>converter.nodeTypes.includes('unknown'));
14
14
  const htmlArray = await Promise.all(lexicalNodes.map(async (node, i)=>{
15
15
  const converterForNode = converters.find((converter)=>converter.nodeTypes.includes(node.type));
16
- if (!converterForNode) {
17
- if (unknownConverter) {
18
- return unknownConverter.converter({
19
- childIndex: i,
20
- converters,
21
- node,
22
- parent,
23
- payload
24
- });
16
+ try {
17
+ if (!converterForNode) {
18
+ if (unknownConverter) {
19
+ return await unknownConverter.converter({
20
+ childIndex: i,
21
+ converters,
22
+ node,
23
+ parent,
24
+ payload
25
+ });
26
+ }
27
+ return '<span>unknown node</span>';
25
28
  }
26
- return '<span>unknown node</span>';
29
+ return await converterForNode.converter({
30
+ childIndex: i,
31
+ converters,
32
+ node,
33
+ parent,
34
+ payload
35
+ });
36
+ } catch (error) {
37
+ console.error('Error converting lexical node to HTML:', error, 'node:', node);
38
+ return '';
27
39
  }
28
- return converterForNode.converter({
29
- childIndex: i,
30
- converters,
31
- node,
32
- parent,
33
- payload
34
- });
35
40
  }));
36
41
  return htmlArray.join('') || '';
37
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/field/features/converters/html/converter/index.ts"],"sourcesContent":["import type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\nimport type { Payload } from 'payload'\n\nimport type { HTMLConverter, SerializedLexicalNodeWithParent } from './types.js'\n\nexport async function convertLexicalToHTML({\n converters,\n data,\n payload,\n}: {\n converters: HTMLConverter[]\n data: SerializedEditorState\n /**\n * When the converter is called, payload CAN be passed in depending on where it's run.\n */\n payload: Payload | null\n}): Promise<string> {\n if (data?.root?.children?.length) {\n return await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: data?.root?.children,\n parent: data?.root,\n payload,\n })\n }\n return ''\n}\n\nexport async function convertLexicalNodesToHTML({\n converters,\n lexicalNodes,\n parent,\n payload,\n}: {\n converters: HTMLConverter[]\n lexicalNodes: SerializedLexicalNode[]\n parent: SerializedLexicalNodeWithParent\n /**\n * When the converter is called, payload CAN be passed in depending on where it's run.\n */\n payload: Payload | null\n}): Promise<string> {\n const unknownConverter = converters.find((converter) => converter.nodeTypes.includes('unknown'))\n\n const htmlArray = await Promise.all(\n lexicalNodes.map(async (node, i) => {\n const converterForNode = converters.find((converter) =>\n converter.nodeTypes.includes(node.type),\n )\n if (!converterForNode) {\n if (unknownConverter) {\n return unknownConverter.converter({ childIndex: i, converters, node, parent, payload })\n }\n return '<span>unknown node</span>'\n }\n return converterForNode.converter({\n childIndex: i,\n converters,\n node,\n parent,\n payload,\n })\n }),\n )\n\n return htmlArray.join('') || ''\n}\n"],"names":["convertLexicalToHTML","converters","data","payload","root","children","length","convertLexicalNodesToHTML","lexicalNodes","parent","unknownConverter","find","converter","nodeTypes","includes","htmlArray","Promise","all","map","node","i","converterForNode","type","childIndex","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,OAAO,eAAeA,qBAAqB,EACzCC,UAAU,EACVC,IAAI,EACJC,OAAO,EAQR;IACC,IAAID,MAAME,MAAMC,UAAUC,QAAQ;QAChC,OAAO,MAAMC,0BAA0B;YACrCN;YACAO,cAAcN,MAAME,MAAMC;YAC1BI,QAAQP,MAAME;YACdD;QACF;IACF;IACA,OAAO;AACT;AAEA,OAAO,eAAeI,0BAA0B,EAC9CN,UAAU,EACVO,YAAY,EACZC,MAAM,EACNN,OAAO,EASR;IACC,MAAMO,mBAAmBT,WAAWU,IAAI,CAAC,CAACC,YAAcA,UAAUC,SAAS,CAACC,QAAQ,CAAC;IAErF,MAAMC,YAAY,MAAMC,QAAQC,GAAG,CACjCT,aAAaU,GAAG,CAAC,OAAOC,MAAMC;QAC5B,MAAMC,mBAAmBpB,WAAWU,IAAI,CAAC,CAACC,YACxCA,UAAUC,SAAS,CAACC,QAAQ,CAACK,KAAKG,IAAI;QAExC,IAAI,CAACD,kBAAkB;YACrB,IAAIX,kBAAkB;gBACpB,OAAOA,iBAAiBE,SAAS,CAAC;oBAAEW,YAAYH;oBAAGnB;oBAAYkB;oBAAMV;oBAAQN;gBAAQ;YACvF;YACA,OAAO;QACT;QACA,OAAOkB,iBAAiBT,SAAS,CAAC;YAChCW,YAAYH;YACZnB;YACAkB;YACAV;YACAN;QACF;IACF;IAGF,OAAOY,UAAUS,IAAI,CAAC,OAAO;AAC/B"}
1
+ {"version":3,"sources":["../../../../../../src/field/features/converters/html/converter/index.ts"],"sourcesContent":["import type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\nimport type { Payload } from 'payload'\n\nimport type { HTMLConverter, SerializedLexicalNodeWithParent } from './types.js'\n\nexport async function convertLexicalToHTML({\n converters,\n data,\n payload,\n}: {\n converters: HTMLConverter[]\n data: SerializedEditorState\n /**\n * When the converter is called, payload CAN be passed in depending on where it's run.\n */\n payload: Payload | null\n}): Promise<string> {\n if (data?.root?.children?.length) {\n return await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: data?.root?.children,\n parent: data?.root,\n payload,\n })\n }\n return ''\n}\n\nexport async function convertLexicalNodesToHTML({\n converters,\n lexicalNodes,\n parent,\n payload,\n}: {\n converters: HTMLConverter[]\n lexicalNodes: SerializedLexicalNode[]\n parent: SerializedLexicalNodeWithParent\n /**\n * When the converter is called, payload CAN be passed in depending on where it's run.\n */\n payload: Payload | null\n}): Promise<string> {\n const unknownConverter = converters.find((converter) => converter.nodeTypes.includes('unknown'))\n\n const htmlArray = await Promise.all(\n lexicalNodes.map(async (node, i) => {\n const converterForNode = converters.find((converter) =>\n converter.nodeTypes.includes(node.type),\n )\n try {\n if (!converterForNode) {\n if (unknownConverter) {\n return await unknownConverter.converter({\n childIndex: i,\n converters,\n node,\n parent,\n payload,\n })\n }\n return '<span>unknown node</span>'\n }\n return await converterForNode.converter({\n childIndex: i,\n converters,\n node,\n parent,\n payload,\n })\n } catch (error) {\n console.error('Error converting lexical node to HTML:', error, 'node:', node)\n return ''\n }\n }),\n )\n\n return htmlArray.join('') || ''\n}\n"],"names":["convertLexicalToHTML","converters","data","payload","root","children","length","convertLexicalNodesToHTML","lexicalNodes","parent","unknownConverter","find","converter","nodeTypes","includes","htmlArray","Promise","all","map","node","i","converterForNode","type","childIndex","error","console","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,OAAO,eAAeA,qBAAqB,EACzCC,UAAU,EACVC,IAAI,EACJC,OAAO,EAQR;IACC,IAAID,MAAME,MAAMC,UAAUC,QAAQ;QAChC,OAAO,MAAMC,0BAA0B;YACrCN;YACAO,cAAcN,MAAME,MAAMC;YAC1BI,QAAQP,MAAME;YACdD;QACF;IACF;IACA,OAAO;AACT;AAEA,OAAO,eAAeI,0BAA0B,EAC9CN,UAAU,EACVO,YAAY,EACZC,MAAM,EACNN,OAAO,EASR;IACC,MAAMO,mBAAmBT,WAAWU,IAAI,CAAC,CAACC,YAAcA,UAAUC,SAAS,CAACC,QAAQ,CAAC;IAErF,MAAMC,YAAY,MAAMC,QAAQC,GAAG,CACjCT,aAAaU,GAAG,CAAC,OAAOC,MAAMC;QAC5B,MAAMC,mBAAmBpB,WAAWU,IAAI,CAAC,CAACC,YACxCA,UAAUC,SAAS,CAACC,QAAQ,CAACK,KAAKG,IAAI;QAExC,IAAI;YACF,IAAI,CAACD,kBAAkB;gBACrB,IAAIX,kBAAkB;oBACpB,OAAO,MAAMA,iBAAiBE,SAAS,CAAC;wBACtCW,YAAYH;wBACZnB;wBACAkB;wBACAV;wBACAN;oBACF;gBACF;gBACA,OAAO;YACT;YACA,OAAO,MAAMkB,iBAAiBT,SAAS,CAAC;gBACtCW,YAAYH;gBACZnB;gBACAkB;gBACAV;gBACAN;YACF;QACF,EAAE,OAAOqB,OAAO;YACdC,QAAQD,KAAK,CAAC,0CAA0CA,OAAO,SAASL;YACxE,OAAO;QACT;IACF;IAGF,OAAOJ,UAAUW,IAAI,CAAC,OAAO;AAC/B"}
@@ -1,7 +1,13 @@
1
- import type { TextField } from 'payload/types';
1
+ import type { Field } from 'payload/types';
2
2
  import type { SanitizedServerEditorConfig } from '../../../../lexical/config/types.js';
3
3
  import type { HTMLConverter } from '../converter/types.js';
4
4
  type Props = {
5
+ /**
6
+ * Whether the lexicalHTML field should be hidden in the admin panel
7
+ *
8
+ * @default true
9
+ */
10
+ hidden?: boolean;
5
11
  name: string;
6
12
  };
7
13
  /**
@@ -18,6 +24,6 @@ export declare const lexicalHTML: (
18
24
  *
19
25
  * This has to be a SIBLING field of this lexicalHTML field - otherwise, it won't be able to find the lexical field.
20
26
  **/
21
- lexicalFieldName: string, props: Props) => TextField;
27
+ lexicalFieldName: string, props: Props) => Field;
22
28
  export {};
23
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/converters/html/field/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,SAAS,EAAE,MAAM,eAAe,CAAA;AAGpE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAA;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAM1D,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,sBAEnC;IACD,YAAY,EAAE,2BAA2B,CAAA;CAC1C,oBAqBA,CAAA;AAED,eAAO,MAAM,WAAW,EAAE;AACxB;;;;IAII;AACJ,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,KAAK,KACT,SAsHJ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/converters/html/field/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAiB,MAAM,eAAe,CAAA;AAGzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAA;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAM1D,KAAK,KAAK,GAAG;IACX;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,sBAEnC;IACD,YAAY,EAAE,2BAA2B,CAAA;CAC1C,oBAqBA,CAAA;AAED,eAAO,MAAM,WAAW,EAAE;AACxB;;;;IAII;AACJ,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,KAAK,KACT,KAyHJ,CAAA"}
@@ -17,12 +17,15 @@ import { convertLexicalToHTML } from '../converter/index.js';
17
17
  return finalConverters;
18
18
  };
19
19
  export const lexicalHTML = (lexicalFieldName, props)=>{
20
- const { name = 'lexicalHTML' } = props;
20
+ const { name = 'lexicalHTML', hidden = true } = props;
21
21
  return {
22
22
  name,
23
- type: 'text',
23
+ type: 'code',
24
24
  admin: {
25
- hidden: true
25
+ editorOptions: {
26
+ language: 'html'
27
+ },
28
+ hidden
26
29
  },
27
30
  hooks: {
28
31
  afterRead: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/field/features/converters/html/field/index.ts"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { Field, RichTextField, TextField } from 'payload/types'\n\nimport type { AdapterProps, LexicalRichTextAdapter } from '../../../../../types.js'\nimport type { SanitizedServerEditorConfig } from '../../../../lexical/config/types.js'\nimport type { HTMLConverter } from '../converter/types.js'\nimport type { HTMLConverterFeatureProps } from '../feature.server.js'\n\nimport { defaultHTMLConverters } from '../converter/defaultConverters.js'\nimport { convertLexicalToHTML } from '../converter/index.js'\n\ntype Props = {\n name: string\n}\n\n/**\n * Combines the default HTML converters with HTML converters found in the features, and with HTML converters configured in the htmlConverter feature.\n *\n * @param editorConfig\n */\nexport const consolidateHTMLConverters = ({\n editorConfig,\n}: {\n editorConfig: SanitizedServerEditorConfig\n}) => {\n const htmlConverterFeature = editorConfig.resolvedFeatureMap.get('htmlConverter')\n const htmlConverterFeatureProps: HTMLConverterFeatureProps =\n htmlConverterFeature?.serverFeatureProps\n\n const defaultConvertersWithConvertersFromFeatures = defaultHTMLConverters\n\n for (const converter of editorConfig.features.converters.html) {\n defaultConvertersWithConvertersFromFeatures.push(converter)\n }\n\n const finalConverters =\n htmlConverterFeatureProps?.converters &&\n typeof htmlConverterFeatureProps?.converters === 'function'\n ? htmlConverterFeatureProps.converters({\n defaultConverters: defaultConvertersWithConvertersFromFeatures,\n })\n : (htmlConverterFeatureProps?.converters as HTMLConverter[]) ||\n defaultConvertersWithConvertersFromFeatures\n\n return finalConverters\n}\n\nexport const lexicalHTML: (\n /**\n * A string which matches the lexical field name you want to convert to HTML.\n *\n * This has to be a SIBLING field of this lexicalHTML field - otherwise, it won't be able to find the lexical field.\n **/\n lexicalFieldName: string,\n props: Props,\n) => TextField = (lexicalFieldName, props) => {\n const { name = 'lexicalHTML' } = props\n return {\n name,\n type: 'text',\n admin: {\n hidden: true,\n },\n hooks: {\n afterRead: [\n async ({ collection, field, global, req, siblingData }) => {\n const fields = collection ? collection.fields : global.fields\n\n // find the path of this field, as well as its sibling fields, by looking for this `field` in fields and traversing it recursively\n function findFieldPathAndSiblingFields(\n fields: Field[],\n path: string[],\n ): {\n path: string[]\n siblingFields: Field[]\n } {\n for (const curField of fields) {\n if (curField === field) {\n return {\n path: [...path, curField.name],\n siblingFields: fields,\n }\n }\n\n if ('fields' in curField) {\n const result = findFieldPathAndSiblingFields(\n curField.fields,\n 'name' in curField ? [...path, curField.name] : [...path],\n )\n if (result) {\n return result\n }\n } else if ('tabs' in curField) {\n for (const tab of curField.tabs) {\n const result = findFieldPathAndSiblingFields(\n tab.fields,\n 'name' in tab ? [...path, tab.name] : [...path],\n )\n if (result) {\n return result\n }\n }\n } else if ('blocks' in curField) {\n for (const block of curField.blocks) {\n if (block?.fields?.length) {\n const result = findFieldPathAndSiblingFields(block.fields, [\n ...path,\n curField.name,\n block.slug,\n ])\n if (result) {\n return result\n }\n }\n }\n }\n }\n\n return null\n }\n\n const foundSiblingFields = findFieldPathAndSiblingFields(fields, [])\n\n if (!foundSiblingFields)\n throw new Error(\n `Could not find sibling fields of current lexicalHTML field with name ${field?.name}`,\n )\n\n const { siblingFields } = foundSiblingFields\n const lexicalField: RichTextField<SerializedEditorState, AdapterProps> =\n siblingFields.find(\n (field) => 'name' in field && field.name === lexicalFieldName,\n ) as RichTextField<SerializedEditorState, AdapterProps>\n\n const lexicalFieldData: SerializedEditorState = siblingData[lexicalFieldName]\n\n if (!lexicalFieldData) {\n return ''\n }\n\n if (!lexicalField) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the referenced lexical field was not found',\n )\n }\n\n const config = (lexicalField?.editor as LexicalRichTextAdapter)?.editorConfig\n\n if (!config) {\n throw new Error(\n 'The linked lexical field does not have an editorConfig. This is needed for the lexicalHTML field.',\n )\n }\n\n if (!config?.resolvedFeatureMap?.has('htmlConverter')) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the linked lexical field does not have a HTMLConverterFeature',\n )\n }\n\n const finalConverters = consolidateHTMLConverters({\n editorConfig: config,\n })\n\n return await convertLexicalToHTML({\n converters: finalConverters,\n data: lexicalFieldData,\n payload: req.payload,\n })\n },\n ],\n },\n }\n}\n"],"names":["defaultHTMLConverters","convertLexicalToHTML","consolidateHTMLConverters","editorConfig","htmlConverterFeature","resolvedFeatureMap","get","htmlConverterFeatureProps","serverFeatureProps","defaultConvertersWithConvertersFromFeatures","converter","features","converters","html","push","finalConverters","defaultConverters","lexicalHTML","lexicalFieldName","props","name","type","admin","hidden","hooks","afterRead","collection","field","global","req","siblingData","fields","findFieldPathAndSiblingFields","path","curField","siblingFields","result","tab","tabs","block","blocks","length","slug","foundSiblingFields","Error","lexicalField","find","lexicalFieldData","config","editor","has","data","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,SAASA,qBAAqB,QAAQ,oCAAmC;AACzE,SAASC,oBAAoB,QAAQ,wBAAuB;AAM5D;;;;CAIC,GACD,OAAO,MAAMC,4BAA4B,CAAC,EACxCC,YAAY,EAGb;IACC,MAAMC,uBAAuBD,aAAaE,kBAAkB,CAACC,GAAG,CAAC;IACjE,MAAMC,4BACJH,sBAAsBI;IAExB,MAAMC,8CAA8CT;IAEpD,KAAK,MAAMU,aAAaP,aAAaQ,QAAQ,CAACC,UAAU,CAACC,IAAI,CAAE;QAC7DJ,4CAA4CK,IAAI,CAACJ;IACnD;IAEA,MAAMK,kBACJR,2BAA2BK,cAC3B,OAAOL,2BAA2BK,eAAe,aAC7CL,0BAA0BK,UAAU,CAAC;QACnCI,mBAAmBP;IACrB,KACA,AAACF,2BAA2BK,cAC5BH;IAEN,OAAOM;AACT,EAAC;AAED,OAAO,MAAME,cAQI,CAACC,kBAAkBC;IAClC,MAAM,EAAEC,OAAO,aAAa,EAAE,GAAGD;IACjC,OAAO;QACLC;QACAC,MAAM;QACNC,OAAO;YACLC,QAAQ;QACV;QACAC,OAAO;YACLC,WAAW;gBACT,OAAO,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,WAAW,EAAE;oBACpD,MAAMC,SAASL,aAAaA,WAAWK,MAAM,GAAGH,OAAOG,MAAM;oBAE7D,kIA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Z,iBAAiB;oBAE7E,IAAI,CAAC6B,kBAAkB;wBACrB,OAAO;oBACT;oBAEA,IAAI,CAACF,cAAc;wBACjB,MAAM,IAAID,MACR;oBAEJ;oBAEA,MAAMI,SAAUH,cAAcI,QAAmC9C;oBAEjE,IAAI,CAAC6C,QAAQ;wBACX,MAAM,IAAIJ,MACR;oBAEJ;oBAEA,IAAI,CAACI,QAAQ3C,oBAAoB6C,IAAI,kBAAkB;wBACrD,MAAM,IAAIN,MACR;oBAEJ;oBAEA,MAAM7B,kBAAkBb,0BAA0B;wBAChDC,cAAc6C;oBAChB;oBAEA,OAAO,MAAM/C,qBAAqB;wBAChCW,YAAYG;wBACZoC,MAAMJ;wBACNK,SAASvB,IAAIuB,OAAO;oBACtB;gBACF;aACD;QACH;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../../../src/field/features/converters/html/field/index.ts"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { Field, RichTextField } from 'payload/types'\n\nimport type { AdapterProps, LexicalRichTextAdapter } from '../../../../../types.js'\nimport type { SanitizedServerEditorConfig } from '../../../../lexical/config/types.js'\nimport type { HTMLConverter } from '../converter/types.js'\nimport type { HTMLConverterFeatureProps } from '../feature.server.js'\n\nimport { defaultHTMLConverters } from '../converter/defaultConverters.js'\nimport { convertLexicalToHTML } from '../converter/index.js'\n\ntype Props = {\n /**\n * Whether the lexicalHTML field should be hidden in the admin panel\n *\n * @default true\n */\n hidden?: boolean\n name: string\n}\n\n/**\n * Combines the default HTML converters with HTML converters found in the features, and with HTML converters configured in the htmlConverter feature.\n *\n * @param editorConfig\n */\nexport const consolidateHTMLConverters = ({\n editorConfig,\n}: {\n editorConfig: SanitizedServerEditorConfig\n}) => {\n const htmlConverterFeature = editorConfig.resolvedFeatureMap.get('htmlConverter')\n const htmlConverterFeatureProps: HTMLConverterFeatureProps =\n htmlConverterFeature?.serverFeatureProps\n\n const defaultConvertersWithConvertersFromFeatures = defaultHTMLConverters\n\n for (const converter of editorConfig.features.converters.html) {\n defaultConvertersWithConvertersFromFeatures.push(converter)\n }\n\n const finalConverters =\n htmlConverterFeatureProps?.converters &&\n typeof htmlConverterFeatureProps?.converters === 'function'\n ? htmlConverterFeatureProps.converters({\n defaultConverters: defaultConvertersWithConvertersFromFeatures,\n })\n : (htmlConverterFeatureProps?.converters as HTMLConverter[]) ||\n defaultConvertersWithConvertersFromFeatures\n\n return finalConverters\n}\n\nexport const lexicalHTML: (\n /**\n * A string which matches the lexical field name you want to convert to HTML.\n *\n * This has to be a SIBLING field of this lexicalHTML field - otherwise, it won't be able to find the lexical field.\n **/\n lexicalFieldName: string,\n props: Props,\n) => Field = (lexicalFieldName, props) => {\n const { name = 'lexicalHTML', hidden = true } = props\n return {\n name,\n type: 'code',\n admin: {\n editorOptions: {\n language: 'html',\n },\n hidden,\n },\n hooks: {\n afterRead: [\n async ({ collection, field, global, req, siblingData }) => {\n const fields = collection ? collection.fields : global.fields\n\n // find the path of this field, as well as its sibling fields, by looking for this `field` in fields and traversing it recursively\n function findFieldPathAndSiblingFields(\n fields: Field[],\n path: string[],\n ): {\n path: string[]\n siblingFields: Field[]\n } {\n for (const curField of fields) {\n if (curField === field) {\n return {\n path: [...path, curField.name],\n siblingFields: fields,\n }\n }\n\n if ('fields' in curField) {\n const result = findFieldPathAndSiblingFields(\n curField.fields,\n 'name' in curField ? [...path, curField.name] : [...path],\n )\n if (result) {\n return result\n }\n } else if ('tabs' in curField) {\n for (const tab of curField.tabs) {\n const result = findFieldPathAndSiblingFields(\n tab.fields,\n 'name' in tab ? [...path, tab.name] : [...path],\n )\n if (result) {\n return result\n }\n }\n } else if ('blocks' in curField) {\n for (const block of curField.blocks) {\n if (block?.fields?.length) {\n const result = findFieldPathAndSiblingFields(block.fields, [\n ...path,\n curField.name,\n block.slug,\n ])\n if (result) {\n return result\n }\n }\n }\n }\n }\n\n return null\n }\n\n const foundSiblingFields = findFieldPathAndSiblingFields(fields, [])\n\n if (!foundSiblingFields)\n throw new Error(\n `Could not find sibling fields of current lexicalHTML field with name ${field?.name}`,\n )\n\n const { siblingFields } = foundSiblingFields\n const lexicalField: RichTextField<SerializedEditorState, AdapterProps> =\n siblingFields.find(\n (field) => 'name' in field && field.name === lexicalFieldName,\n ) as RichTextField<SerializedEditorState, AdapterProps>\n\n const lexicalFieldData: SerializedEditorState = siblingData[lexicalFieldName]\n\n if (!lexicalFieldData) {\n return ''\n }\n\n if (!lexicalField) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the referenced lexical field was not found',\n )\n }\n\n const config = (lexicalField?.editor as LexicalRichTextAdapter)?.editorConfig\n\n if (!config) {\n throw new Error(\n 'The linked lexical field does not have an editorConfig. This is needed for the lexicalHTML field.',\n )\n }\n\n if (!config?.resolvedFeatureMap?.has('htmlConverter')) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the linked lexical field does not have a HTMLConverterFeature',\n )\n }\n\n const finalConverters = consolidateHTMLConverters({\n editorConfig: config,\n })\n\n return await convertLexicalToHTML({\n converters: finalConverters,\n data: lexicalFieldData,\n payload: req.payload,\n })\n },\n ],\n },\n }\n}\n"],"names":["defaultHTMLConverters","convertLexicalToHTML","consolidateHTMLConverters","editorConfig","htmlConverterFeature","resolvedFeatureMap","get","htmlConverterFeatureProps","serverFeatureProps","defaultConvertersWithConvertersFromFeatures","converter","features","converters","html","push","finalConverters","defaultConverters","lexicalHTML","lexicalFieldName","props","name","hidden","type","admin","editorOptions","language","hooks","afterRead","collection","field","global","req","siblingData","fields","findFieldPathAndSiblingFields","path","curField","siblingFields","result","tab","tabs","block","blocks","length","slug","foundSiblingFields","Error","lexicalField","find","lexicalFieldData","config","editor","has","data","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,SAASA,qBAAqB,QAAQ,oCAAmC;AACzE,SAAS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AO,MAAMjD,qBAAqB;wBAChCW,YAAYG;wBACZsC,MAAMJ;wBACNK,SAASvB,IAAIuB,OAAO;oBACtB;gBACF;aACD;QACH;IACF;AACF,EAAC"}
@@ -0,0 +1,10 @@
1
+ import type { NodeKey } from 'lexical';
2
+ /**
3
+ * React component rendered in the lexical editor, WITHIN the hr element created by createDOM of the HorizontalRuleNode.
4
+ *
5
+ * @param nodeKey every node has a unique key (this key is not saved to the database and thus may differ between sessions). It's useful for working with the CURRENT lexical editor state
6
+ */
7
+ export declare function HorizontalRuleComponent({ nodeKey }: {
8
+ nodeKey: NodeKey;
9
+ }): any;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/horizontalrule/component/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAqBtC;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,OAmDxE"}
@@ -0,0 +1,64 @@
1
+ 'use client';
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
+ import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js';
4
+ import lexicalUtilsImport from '@lexical/utils';
5
+ const { mergeRegister } = lexicalUtilsImport;
6
+ import lexicalImport from 'lexical';
7
+ const { $getNodeByKey, $getSelection, $isNodeSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND } = lexicalImport;
8
+ import { useCallback, useEffect } from 'react';
9
+ import { $isHorizontalRuleNode } from '../nodes/HorizontalRuleNode.js';
10
+ /**
11
+ * React component rendered in the lexical editor, WITHIN the hr element created by createDOM of the HorizontalRuleNode.
12
+ *
13
+ * @param nodeKey every node has a unique key (this key is not saved to the database and thus may differ between sessions). It's useful for working with the CURRENT lexical editor state
14
+ */ export function HorizontalRuleComponent({ nodeKey }) {
15
+ const [editor] = useLexicalComposerContext();
16
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
17
+ const onDelete = useCallback((event)=>{
18
+ if (isSelected && $isNodeSelection($getSelection())) {
19
+ event.preventDefault();
20
+ const node = $getNodeByKey(nodeKey);
21
+ if ($isHorizontalRuleNode(node)) {
22
+ node.remove();
23
+ return true;
24
+ }
25
+ }
26
+ return false;
27
+ }, [
28
+ isSelected,
29
+ nodeKey
30
+ ]);
31
+ useEffect(()=>{
32
+ return mergeRegister(editor.registerCommand(CLICK_COMMAND, (event)=>{
33
+ const hrElem = editor.getElementByKey(nodeKey);
34
+ if (event.target === hrElem) {
35
+ if (!event.shiftKey) {
36
+ clearSelection();
37
+ }
38
+ setSelected(!isSelected);
39
+ return true;
40
+ }
41
+ return false;
42
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW));
43
+ }, [
44
+ clearSelection,
45
+ editor,
46
+ isSelected,
47
+ nodeKey,
48
+ onDelete,
49
+ setSelected
50
+ ]);
51
+ useEffect(()=>{
52
+ const hrElem = editor.getElementByKey(nodeKey);
53
+ if (hrElem !== null) {
54
+ hrElem.className = isSelected ? 'selected' : '';
55
+ }
56
+ }, [
57
+ editor,
58
+ isSelected,
59
+ nodeKey
60
+ ]);
61
+ return null;
62
+ }
63
+
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/field/features/horizontalrule/component/index.tsx"],"sourcesContent":["'use client'\n\nimport type { NodeKey } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport lexicalUtilsImport from '@lexical/utils'\nconst { mergeRegister } = lexicalUtilsImport\n\nimport lexicalImport from 'lexical'\nconst {\n $getNodeByKey,\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} = lexicalImport\nimport { useCallback, useEffect } from 'react'\n\nimport { $isHorizontalRuleNode } from '../nodes/HorizontalRuleNode.js'\n\n/**\n * React component rendered in the lexical editor, WITHIN the hr element created by createDOM of the HorizontalRuleNode.\n *\n * @param nodeKey every node has a unique key (this key is not saved to the database and thus may differ between sessions). It's useful for working with the CURRENT lexical editor state\n */\nexport function HorizontalRuleComponent({ nodeKey }: { nodeKey: NodeKey }) {\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n\n const onDelete = useCallback(\n (event: KeyboardEvent) => {\n if (isSelected && $isNodeSelection($getSelection())) {\n event.preventDefault()\n const node = $getNodeByKey(nodeKey)\n if ($isHorizontalRuleNode(node)) {\n node.remove()\n return true\n }\n }\n return false\n },\n [isSelected, nodeKey],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n CLICK_COMMAND,\n (event: MouseEvent) => {\n const hrElem = editor.getElementByKey(nodeKey)\n\n if (event.target === hrElem) {\n if (!event.shiftKey) {\n clearSelection()\n }\n setSelected(!isSelected)\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected])\n\n useEffect(() => {\n const hrElem = editor.getElementByKey(nodeKey)\n if (hrElem !== null) {\n hrElem.className = isSelected ? 'selected' : ''\n }\n }, [editor, isSelected, nodeKey])\n\n return null\n}\n"],"names":["useLexicalComposerContext","useLexicalNodeSelection","lexicalUtilsImport","mergeRegister","lexicalImport","$getNodeByKey","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","useCallback","useEffect","$isHorizontalRuleNode","HorizontalRuleComponent","nodeKey","editor","isSelected","setSelected","clearSelection","onDelete","event","preventDefault","node","remove","registerCommand","hrElem","getElementByKey","target","shiftKey","className"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,4CAA2C;AACnF,OAAOC,wBAAwB,iBAAgB;AAC/C,MAAM,EAAEC,aAAa,EAAE,GAAGD;AAE1B,OAAOE,mBAAmB,UAAS;AACnC,MAAM,EACJC,aAAa,EACbC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,EACnB,GAAGP;AACJ,SAASQ,WAAW,EAAEC,SAAS,QAAQ,QAAO;AAE9C,SAASC,qBAAqB,QAAQ,iCAAgC;AAEtE;;;;CAIC,GACD,OAAO,SAASC,wBAAwB,EAAEC,OAAO,EAAwB;IACvE,MAAM,CAACC,OAAO,GAAGjB;IACjB,MAAM,CAACkB,YAAYC,aAAaC,eAAe,GAAGnB,wBAAwBe;IAE1E,MAAMK,WAAWT,YACf,CAACU;QACC,IAAIJ,cAAcX,iBAAiBD,kBAAkB;YACnDgB,MAAMC,cAAc;YACpB,MAAMC,OAAOnB,cAAcW;YAC3B,IAAIF,sBAAsBU,OAAO;gBAC/BA,KAAKC,MAAM;gBACX,OAAO;YACT;QACF;QACA,OAAO;IACT,GACA;QAACP;QAAYF;KAAQ;IAGvBH,UAAU;QACR,OAAOV,cACLc,OAAOS,eAAe,CACpBlB,eACA,CAACc;YACC,MAAMK,SAASV,OAAOW,eAAe,CAACZ;YAEtC,IAAIM,MAAMO,MAAM,KAAKF,QAAQ;gBAC3B,IAAI,CAACL,MAAMQ,QAAQ,EAAE;oBACnBV;gBACF;gBACAD,YAAY,CAACD;gBACb,OAAO;YACT;YAEA,OAAO;QACT,GACAT,uBAEFQ,OAAOS,eAAe,CAACf,oBAAoBU,UAAUZ,uBACrDQ,OAAOS,eAAe,CAAChB,uBAAuBW,UAAUZ;IAE5D,GAAG;QAACW;QAAgBH;QAAQC;QAAYF;QAASK;QAAUF;KAAY;IAEvEN,UAAU;QACR,MAAMc,SAASV,OAAOW,eAAe,CAACZ;QACtC,IAAIW,WAAW,MAAM;YACnBA,OAAOI,SAAS,GAAGb,aAAa,aAAa;QAC/C;IACF,GAAG;QAACD;QAAQC;QAAYF;KAAQ;IAEhC,OAAO;AACT"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ export declare const HorizontalRuleFeatureClientComponent: import("react").FC<undefined>;
3
+ //# sourceMappingURL=feature.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.client.d.ts","sourceRoot":"","sources":["../../../../src/field/features/horizontalrule/feature.client.tsx"],"names":[],"mappings":";AA8CA,eAAO,MAAM,oCAAoC,+BAEhD,CAAA"}
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+ import { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js';
3
+ import { HorizontalRuleIcon } from '../../lexical/ui/icons/HorizontalRule/index.js';
4
+ import { createClientComponent } from '../createClientComponent.js';
5
+ import { MarkdownTransformer } from './markdownTransformer.js';
6
+ import { HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from './nodes/HorizontalRuleNode.js';
7
+ import { HorizontalRulePlugin } from './plugin/index.js';
8
+ const HorizontalRuleFeatureClient = (props)=>{
9
+ return {
10
+ clientFeatureProps: props,
11
+ feature: ()=>({
12
+ clientFeatureProps: props,
13
+ markdownTransformers: [
14
+ MarkdownTransformer
15
+ ],
16
+ nodes: [
17
+ HorizontalRuleNode
18
+ ],
19
+ plugins: [
20
+ {
21
+ Component: HorizontalRulePlugin,
22
+ position: 'normal'
23
+ }
24
+ ],
25
+ slashMenu: {
26
+ options: [
27
+ {
28
+ displayName: 'Basic',
29
+ key: 'basic',
30
+ options: [
31
+ new SlashMenuOption(`horizontalrule`, {
32
+ Icon: HorizontalRuleIcon,
33
+ displayName: `Horizontal Rule`,
34
+ keywords: [
35
+ 'hr',
36
+ 'horizontal rule',
37
+ 'line',
38
+ 'separator'
39
+ ],
40
+ onSelect: ({ editor })=>{
41
+ editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined);
42
+ }
43
+ })
44
+ ]
45
+ }
46
+ ]
47
+ }
48
+ })
49
+ };
50
+ };
51
+ export const HorizontalRuleFeatureClientComponent = createClientComponent(HorizontalRuleFeatureClient);
52
+
53
+ //# sourceMappingURL=feature.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/field/features/horizontalrule/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport type { FeatureProviderProviderClient } from '../types.js'\n\nimport { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport { HorizontalRuleIcon } from '../../lexical/ui/icons/HorizontalRule/index.js'\nimport { createClientComponent } from '../createClientComponent.js'\nimport { MarkdownTransformer } from './markdownTransformer.js'\nimport { HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from './nodes/HorizontalRuleNode.js'\nimport { HorizontalRulePlugin } from './plugin/index.js'\n\nconst HorizontalRuleFeatureClient: FeatureProviderProviderClient<undefined> = (props) => {\n return {\n clientFeatureProps: props,\n feature: () => ({\n clientFeatureProps: props,\n markdownTransformers: [MarkdownTransformer],\n nodes: [HorizontalRuleNode],\n plugins: [\n {\n Component: HorizontalRulePlugin,\n position: 'normal',\n },\n ],\n slashMenu: {\n options: [\n {\n displayName: 'Basic',\n key: 'basic',\n options: [\n new SlashMenuOption(`horizontalrule`, {\n Icon: HorizontalRuleIcon,\n displayName: `Horizontal Rule`,\n keywords: ['hr', 'horizontal rule', 'line', 'separator'],\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined)\n },\n }),\n ],\n },\n ],\n },\n }),\n }\n}\n\nexport const HorizontalRuleFeatureClientComponent = createClientComponent(\n HorizontalRuleFeatureClient,\n)\n"],"names":["SlashMenuOption","HorizontalRuleIcon","createClientComponent","MarkdownTransformer","HorizontalRuleNode","INSERT_HORIZONTAL_RULE_COMMAND","HorizontalRulePlugin","HorizontalRuleFeatureClient","props","clientFeatureProps","feature","markdownTransformers","nodes","plugins","Component","position","slashMenu","options","displayName","key","Icon","keywords","onSelect","editor","dispatchCommand","undefined","HorizontalRuleFeatureClientComponent"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,eAAe,QAAQ,sEAAqE;AACrG,SAASC,kBAAkB,QAAQ,iDAAgD;AACnF,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,kBAAkB,EAAEC,8BAA8B,QAAQ,gCAA+B;AAClG,SAASC,oBAAoB,QAAQ,oBAAmB;AAExD,MAAMC,8BAAwE,CAACC;IAC7E,OAAO;QACLC,oBAAoBD;QACpBE,SAAS,IAAO,CAAA;gBACdD,oBAAoBD;gBACpBG,sBAAsB;oBAACR;iBAAoB;gBAC3CS,OAAO;oBAACR;iBAAmB;gBAC3BS,SAAS;oBACP;wBACEC,WAAWR;wBACXS,UAAU;oBACZ;iBACD;gBACDC,WAAW;oBACTC,SAAS;wBACP;4BACEC,aAAa;4BACbC,KAAK;4BACLF,SAAS;gCACP,IAAIjB,gBAAgB,CAAC,cAAc,CAAC,EAAE;oCACpCoB,MAAMnB;oCACNiB,aAAa,CAAC,eAAe,CAAC;oCAC9BG,UAAU;wCAAC;wCAAM;wCAAmB;wCAAQ;qCAAY;oCACxDC,UAAU,CAAC,EAAEC,MAAM,EAAE;wCACnBA,OAAOC,eAAe,CAACnB,gCAAgCoB;oCACzD;gCACF;6BACD;wBACH;qBACD;gBACH;YACF,CAAA;IACF;AACF;AAEA,OAAO,MAAMC,uCAAuCxB,sBAClDK,6BACD"}
@@ -0,0 +1,3 @@
1
+ import type { FeatureProviderProviderServer } from '../types.js';
2
+ export declare const HorizontalRuleFeature: FeatureProviderProviderServer<undefined, undefined>;
3
+ //# sourceMappingURL=feature.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/horizontalrule/feature.server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAOhE,eAAO,MAAM,qBAAqB,EAAE,6BAA6B,CAAC,SAAS,EAAE,SAAS,CA4BrF,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { HorizontalRuleFeatureClientComponent } from './feature.client.js';
2
+ import { MarkdownTransformer } from './markdownTransformer.js';
3
+ import { HorizontalRuleNode } from './nodes/HorizontalRuleNode.js';
4
+ export const HorizontalRuleFeature = (props)=>{
5
+ return {
6
+ feature: ()=>{
7
+ return {
8
+ ClientComponent: HorizontalRuleFeatureClientComponent,
9
+ clientFeatureProps: null,
10
+ markdownTransformers: [
11
+ MarkdownTransformer
12
+ ],
13
+ nodes: [
14
+ {
15
+ converters: {
16
+ html: {
17
+ converter: ()=>{
18
+ return `<hr/>`;
19
+ },
20
+ nodeTypes: [
21
+ HorizontalRuleNode.getType()
22
+ ]
23
+ }
24
+ },
25
+ node: HorizontalRuleNode
26
+ }
27
+ ],
28
+ serverFeatureProps: props
29
+ };
30
+ },
31
+ key: 'horizontalrule',
32
+ serverFeatureProps: props
33
+ };
34
+ };
35
+
36
+ //# sourceMappingURL=feature.server.js.map