@payloadcms/richtext-lexical 3.59.0-internal.898dbd3 → 3.59.0-internal.917c03d

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 (81) hide show
  1. package/dist/exports/client/Field-CJFETHA3.js +2 -0
  2. package/dist/exports/client/Field-CJFETHA3.js.map +7 -0
  3. package/dist/exports/client/RelationshipComponent-TSIENULZ.js +2 -0
  4. package/dist/exports/client/RelationshipComponent-TSIENULZ.js.map +7 -0
  5. package/dist/exports/client/bundled.css +1 -1
  6. package/dist/exports/client/chunk-BQCXN3B4.js +2 -0
  7. package/dist/exports/client/chunk-BQCXN3B4.js.map +7 -0
  8. package/dist/exports/client/chunk-XNERFY6G.js +2 -0
  9. package/dist/exports/client/chunk-XNERFY6G.js.map +7 -0
  10. package/dist/exports/client/component-CYFKY3IL.js +2 -0
  11. package/dist/exports/client/component-CYFKY3IL.js.map +7 -0
  12. package/dist/exports/client/componentInline-NGTRUSGB.js +2 -0
  13. package/dist/exports/client/index.js +24 -24
  14. package/dist/exports/client/index.js.map +3 -3
  15. package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
  16. package/dist/features/blocks/client/component/BlockContent.js +4 -1
  17. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  18. package/dist/features/blocks/client/component/index.d.ts.map +1 -1
  19. package/dist/features/blocks/client/component/index.js +15 -12
  20. package/dist/features/blocks/client/component/index.js.map +1 -1
  21. package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
  22. package/dist/features/blocks/client/componentInline/index.js +13 -10
  23. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  24. package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts +1 -1
  25. package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts.map +1 -1
  26. package/dist/features/blocks/premade/CodeBlock/Component/Block.js +20 -15
  27. package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
  28. package/dist/features/blocks/premade/CodeBlock/Component/Code.d.ts +8 -0
  29. package/dist/features/blocks/premade/CodeBlock/Component/Code.d.ts.map +1 -1
  30. package/dist/features/blocks/premade/CodeBlock/Component/Code.js +15 -0
  31. package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
  32. package/dist/features/blocks/server/i18n.js +38 -38
  33. package/dist/features/blocks/server/i18n.js.map +1 -1
  34. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
  35. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +5 -3
  36. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
  37. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  38. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +3 -1
  39. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  40. package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
  41. package/dist/features/relationship/client/components/RelationshipComponent.js +5 -9
  42. package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
  43. package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
  44. package/dist/features/toolbars/fixed/client/Toolbar/index.js +7 -1
  45. package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
  46. package/dist/features/toolbars/inline/client/Toolbar/index.d.ts.map +1 -1
  47. package/dist/features/toolbars/inline/client/Toolbar/index.js +3 -1
  48. package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
  49. package/dist/features/upload/client/component/index.d.ts.map +1 -1
  50. package/dist/features/upload/client/component/index.js +6 -5
  51. package/dist/features/upload/client/component/index.js.map +1 -1
  52. package/dist/field/RenderLexical/index.d.ts.map +1 -1
  53. package/dist/field/RenderLexical/index.js +1 -0
  54. package/dist/field/RenderLexical/index.js.map +1 -1
  55. package/dist/field/bundled.css +1 -1
  56. package/dist/field/rscEntry.d.ts.map +1 -1
  57. package/dist/field/rscEntry.js +2 -0
  58. package/dist/field/rscEntry.js.map +1 -1
  59. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  60. package/dist/lexical/LexicalEditor.js +20 -26
  61. package/dist/lexical/LexicalEditor.js.map +1 -1
  62. package/dist/utilities/buildInitialState.d.ts +1 -0
  63. package/dist/utilities/buildInitialState.d.ts.map +1 -1
  64. package/dist/utilities/buildInitialState.js +1 -0
  65. package/dist/utilities/buildInitialState.js.map +1 -1
  66. package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
  67. package/dist/utilities/fieldsDrawer/DrawerContent.js +7 -3
  68. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
  69. package/package.json +6 -6
  70. package/dist/exports/client/Field-2MCIQXRP.js +0 -2
  71. package/dist/exports/client/Field-2MCIQXRP.js.map +0 -7
  72. package/dist/exports/client/RelationshipComponent-APF3CN47.js +0 -2
  73. package/dist/exports/client/RelationshipComponent-APF3CN47.js.map +0 -7
  74. package/dist/exports/client/chunk-CYLMY5ZJ.js +0 -2
  75. package/dist/exports/client/chunk-CYLMY5ZJ.js.map +0 -7
  76. package/dist/exports/client/chunk-K47TNP5J.js +0 -2
  77. package/dist/exports/client/chunk-K47TNP5J.js.map +0 -7
  78. package/dist/exports/client/component-VDJI45F2.js +0 -2
  79. package/dist/exports/client/component-VDJI45F2.js.map +0 -7
  80. package/dist/exports/client/componentInline-AGFSKAY4.js +0 -2
  81. /package/dist/exports/client/{componentInline-AGFSKAY4.js.map → componentInline-NGTRUSGB.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","createContext","useCallback","useEffect","useMemo","useRef","baseClass","useLexicalComposerContext","getTranslation","Button","Drawer","EditDepthProvider","Form","formatDrawerSlug","FormSubmit","RenderFields","ShimmerEffect","useConfig","useDocumentForm","useDocumentInfo","useEditDepth","useServerFunctions","useTranslation","abortAndIgnore","$getNodeByKey","deepCopyObjectSimpleWithoutReactComponents","reduceFieldsToValues","v4","uuid","useEditorConfigContext","useLexicalDrawer","$isInlineBlockNode","InlineBlockComponentContext","initialState","useInlineBlockComponentContext","use","InlineBlockComponent","props","cacheBuster","formData","nodeKey","editor","i18n","t","createdInlineBlock","fieldProps","featureClientSchemaMap","initialLexicalFormState","readOnly","schemaPath","setCreatedInlineBlock","uuidFromContext","fields","parentDocumentFields","getFormState","editDepth","firstTimeDrawer","setInitialState","useState","id","formState","hasMounted","prevCacheBuster","current","CustomLabel","setCustomLabel","customComponents","BlockLabel","CustomBlock","setCustomBlock","Block","drawerSlug","slug","depth","toggleDrawer","inlineBlockElemElemRef","collectionSlug","getDocPreferences","globalSlug","config","componentMapRenderedBlockPath","blockType","clientSchemaMap","blocksField","clientBlock","blockReferences","blocksMap","blocks","clientBlockFields","getKey","length","undefined","removeInlineBlock","update","remove","blockDisplayName","labels","singular","onChangeAbortControllerRef","AbortController","schemaFieldsPath","abortController","awaitInitialState","state","data","docPermissions","docPreferences","documentFormState","initialBlockData","initialBlockFormState","operation","renderAllFields","signal","newFormStateData","node","newData","setFields","onChange","prevFormState","submit","controller","isStateOutOfSync","Object","keys","some","key","value","onFormSubmit","RemoveButton","_jsx","buttonStyle","className","disabled","icon","onClick","e","preventDefault","round","size","tooltip","label","EditButton","el","InlineBlockContainer","children","filter","Boolean","join","ref","Label","_jsxs","isEditable","beforeSubmit","disableValidationOnSubmit","onSubmit","title","_Fragment","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","programmaticSubmit","height","width"],"sources":["../../../../../src/features/blocks/client/componentInline/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react'\nconst baseClass = 'inline-block'\n\nimport type { BlocksFieldClient, ClientBlock, Data, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Drawer,\n EditDepthProvider,\n Form,\n formatDrawerSlug,\n FormSubmit,\n RenderFields,\n ShimmerEffect,\n useConfig,\n useDocumentForm,\n useDocumentInfo,\n useEditDepth,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport { $getNodeByKey } from 'lexical'\n\nimport './index.scss'\n\nimport { deepCopyObjectSimpleWithoutReactComponents, reduceFieldsToValues } from 'payload/shared'\nimport { v4 as uuid } from 'uuid'\n\nimport type { InlineBlockFields } from '../../server/nodes/InlineBlocksNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\n\ntype Props = {\n /**\n * Can be modified by the node in order to trigger the re-fetch of the initial state based on the\n * formData. This is useful when node.setFields() is explicitly called from outside of the form - in\n * this case, the new field state is likely not reflected in the form state, so we need to re-fetch\n */\n readonly cacheBuster: number\n readonly formData: InlineBlockFields\n readonly nodeKey: string\n}\n\ntype InlineBlockComponentContextType = {\n EditButton?: React.FC\n initialState: false | FormState | undefined\n InlineBlockContainer?: React.FC<{ children: React.ReactNode }>\n Label?: React.FC\n nodeKey?: string\n RemoveButton?: React.FC\n}\n\nconst InlineBlockComponentContext = createContext<InlineBlockComponentContextType>({\n initialState: false,\n})\n\nexport const useInlineBlockComponentContext = () => React.use(InlineBlockComponentContext)\n\nexport const InlineBlockComponent: React.FC<Props> = (props) => {\n const { cacheBuster, formData, nodeKey } = props\n\n const [editor] = useLexicalComposerContext()\n const { i18n, t } = useTranslation<object, string>()\n const {\n createdInlineBlock,\n fieldProps: { featureClientSchemaMap, initialLexicalFormState, readOnly, schemaPath },\n setCreatedInlineBlock,\n uuid: uuidFromContext,\n } = useEditorConfigContext()\n const { fields: parentDocumentFields } = useDocumentForm()\n\n const { getFormState } = useServerFunctions()\n const editDepth = useEditDepth()\n const firstTimeDrawer = useRef(false)\n\n const [initialState, setInitialState] = React.useState<false | FormState | undefined>(\n () => initialLexicalFormState?.[formData.id]?.formState,\n )\n\n const hasMounted = useRef(false)\n const prevCacheBuster = useRef(cacheBuster)\n useEffect(() => {\n if (hasMounted.current) {\n if (prevCacheBuster.current !== cacheBuster) {\n setInitialState(false)\n }\n prevCacheBuster.current = cacheBuster\n } else {\n hasMounted.current = true\n }\n }, [cacheBuster])\n\n const [CustomLabel, setCustomLabel] = React.useState<React.ReactNode | undefined>(\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n initialState?.['_components']?.customComponents?.BlockLabel,\n )\n\n const [CustomBlock, setCustomBlock] = React.useState<React.ReactNode | undefined>(\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n initialState?.['_components']?.customComponents?.Block,\n )\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-${uuidFromContext}-${formData.id}`,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n const inlineBlockElemElemRef = useRef<HTMLDivElement | null>(null)\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { config } = useConfig()\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${formData.blockType}`\n\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap?.[\n componentMapRenderedBlockPath\n ]?.[0] as BlocksFieldClient\n\n const clientBlock: ClientBlock | undefined = blocksField.blockReferences\n ? typeof blocksField?.blockReferences?.[0] === 'string'\n ? config.blocksMap[blocksField?.blockReferences?.[0]]\n : blocksField?.blockReferences?.[0]\n : blocksField?.blocks?.[0]\n\n const clientBlockFields = clientBlock?.fields ?? []\n\n // Open drawer on \"mount\"\n useEffect(() => {\n if (!firstTimeDrawer.current && createdInlineBlock?.getKey() === nodeKey) {\n // > 2 because they always have \"id\" and \"blockName\" fields\n if (clientBlockFields.length > 2) {\n toggleDrawer()\n }\n setCreatedInlineBlock?.(undefined)\n firstTimeDrawer.current = true\n }\n }, [clientBlockFields.length, createdInlineBlock, nodeKey, setCreatedInlineBlock, toggleDrawer])\n\n const removeInlineBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels.singular, i18n)\n : clientBlock?.slug\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${clientBlock?.slug}.fields`\n\n // Initial state for newly created blocks\n useEffect(() => {\n const abortController = new AbortController()\n\n const awaitInitialState = async () => {\n /*\n * This will only run if a new block is created. For all existing blocks that are loaded when the document is loaded, or when the form is saved,\n * this is not run, as the lexical field RSC will fetch the state server-side and pass it to the client. That way, we avoid unnecessary client-side\n * requests. Though for newly created blocks, we need to fetch the state client-side, as the server doesn't know about the block yet.\n */\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: formData,\n docPermissions: { fields: true },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n globalSlug,\n initialBlockData: formData,\n initialBlockFormState: formData,\n operation: 'update',\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: abortController.signal,\n })\n\n if (state) {\n const newFormStateData: InlineBlockFields = reduceFieldsToValues(\n deepCopyObjectSimpleWithoutReactComponents(state),\n true,\n ) as InlineBlockFields\n\n // Things like default values may come back from the server => update the node with the new data\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n const newData = newFormStateData\n newData.blockType = formData.blockType\n\n node.setFields(newData, true)\n }\n })\n\n setInitialState(state)\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n\n if (formData && !initialState) {\n void awaitInitialState()\n }\n\n return () => {\n abortAndIgnore(abortController)\n }\n }, [\n getFormState,\n editor,\n nodeKey,\n schemaFieldsPath,\n id,\n formData,\n initialState,\n collectionSlug,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n ])\n\n /**\n * HANDLE ONCHANGE\n */\n const onChange = useCallback(\n async ({ formState: prevFormState, submit }: { formState: FormState; submit?: boolean }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\n operation: 'update',\n renderAllFields: submit ? true : false,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n if (submit) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n\n return state\n },\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n schemaFieldsPath,\n ],\n )\n // cleanup effect\n useEffect(() => {\n const isStateOutOfSync = (formData: InlineBlockFields, initialState: FormState) => {\n return Object.keys(initialState).some(\n (key) => initialState[key] && formData[key] !== initialState[key].value,\n )\n }\n\n return () => {\n // If the component is unmounted (either via removeInlineBlock or via lexical itself) and the form state got changed before,\n // we need to reset the initial state to force a re-fetch of the initial state when it gets mounted again (e.g. via lexical history undo).\n // Otherwise it would use an outdated initial state.\n if (initialState && isStateOutOfSync(formData, initialState)) {\n setInitialState(false)\n }\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [formData, initialState])\n\n /**\n * HANDLE FORM SUBMIT\n */\n const onFormSubmit = useCallback(\n (formState: FormState, newData: Data) => {\n newData.blockType = formData.blockType\n\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n node.setFields(newData as InlineBlockFields, true)\n }\n })\n },\n [editor, nodeKey, formData],\n )\n\n const RemoveButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeInlineBlock()\n }}\n round\n size=\"small\"\n tooltip={t('lexical:blocks:inlineBlocks:remove', { label: blockDisplayName })}\n />\n ),\n [blockDisplayName, readOnly, removeInlineBlock, t],\n )\n\n const EditButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__editButton`}\n disabled={readOnly}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n size=\"small\"\n tooltip={t('lexical:blocks:inlineBlocks:edit', { label: blockDisplayName })}\n />\n ),\n [blockDisplayName, readOnly, t, toggleDrawer],\n )\n\n const InlineBlockContainer = useMemo(\n () =>\n ({ children, className }: { children: React.ReactNode; className?: string }) => (\n <div\n className={[baseClass, baseClass + '-' + formData.blockType, className]\n .filter(Boolean)\n .join(' ')}\n ref={inlineBlockElemElemRef}\n >\n {children}\n </div>\n ),\n [formData.blockType],\n )\n\n const Label = useMemo(() => {\n if (CustomLabel) {\n return () => CustomLabel\n } else {\n return () => (\n <div>{clientBlock?.labels ? getTranslation(clientBlock?.labels.singular, i18n) : ''}</div>\n )\n }\n }, [CustomLabel, clientBlock?.labels, i18n])\n\n if (!clientBlock) {\n return (\n <InlineBlockContainer className={`${baseClass}-not-found`}>\n <span>Error: Block '{formData.blockType}' not found</span>\n {editor.isEditable() ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )\n }\n\n return (\n <Form\n beforeSubmit={[\n async ({ formState }) => {\n // This is only called when form is submitted from drawer\n return await onChange({ formState, submit: true })\n },\n ]}\n disableValidationOnSubmit\n el=\"div\"\n fields={clientBlock?.fields}\n initialState={initialState || {}}\n onChange={[onChange]}\n onSubmit={(formState, data) => {\n onFormSubmit(formState, data)\n toggleDrawer()\n }}\n uuid={uuid()}\n >\n <EditDepthProvider>\n <Drawer\n className={''}\n slug={drawerSlug}\n title={t(`lexical:blocks:inlineBlocks:${formData?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n >\n {initialState ? (\n <>\n <RenderFields\n fields={clientBlock?.fields}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\" // See Blocks feature path for details as for why this is empty\n parentSchemaPath={schemaFieldsPath}\n permissions={true}\n readOnly={false}\n />\n <FormSubmit programmaticSubmit={true}>{t('fields:saveChanges')}</FormSubmit>\n </>\n ) : null}\n </Drawer>\n </EditDepthProvider>\n {CustomBlock ? (\n <InlineBlockComponentContext\n value={{\n EditButton,\n initialState,\n InlineBlockContainer,\n Label,\n nodeKey,\n RemoveButton,\n }}\n >\n {CustomBlock}\n </InlineBlockComponentContext>\n ) : (\n <InlineBlockContainer>\n {initialState ? <Label /> : <ShimmerEffect height=\"15px\" width=\"40px\" />}\n {editor.isEditable() ? (\n <div className={`${baseClass}__actions`}>\n <EditButton />\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )}\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAEA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAC9E,MAAMC,SAAA,GAAY;AAIlB,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EACJC,gBAAgB,EAChBC,UAAU,EACVC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,cAAc,QACT;AACP,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ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AA,qBAAWpB,IAAA,CAACjH,aAAA;QAAcmJ,MAAA,EAAO;QAAOC,KAAA,EAAM;UAC9D3H,MAAA,CAAO8G,UAAU,kBAChBD,KAAA,CAAC;QAAInB,SAAA,EAAW,GAAG7H,SAAA,WAAoB;gCACrC2H,IAAA,CAACY,UAAA,O,aACDZ,IAAA,CAACD,YAAA;WAED;;;AAKd","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","createContext","useCallback","useEffect","useMemo","useRef","baseClass","useLexicalComposerContext","useLexicalEditable","getTranslation","Button","Drawer","EditDepthProvider","Form","formatDrawerSlug","FormSubmit","RenderFields","ShimmerEffect","useConfig","useDocumentForm","useDocumentInfo","useEditDepth","useServerFunctions","useTranslation","abortAndIgnore","$getNodeByKey","deepCopyObjectSimpleWithoutReactComponents","reduceFieldsToValues","v4","uuid","useEditorConfigContext","useLexicalDrawer","$isInlineBlockNode","InlineBlockComponentContext","initialState","useInlineBlockComponentContext","use","InlineBlockComponent","props","cacheBuster","formData","nodeKey","editor","isEditable","i18n","t","createdInlineBlock","fieldProps","featureClientSchemaMap","initialLexicalFormState","schemaPath","setCreatedInlineBlock","uuidFromContext","fields","parentDocumentFields","getFormState","editDepth","firstTimeDrawer","setInitialState","useState","id","formState","hasMounted","prevCacheBuster","current","CustomLabel","setCustomLabel","customComponents","BlockLabel","CustomBlock","setCustomBlock","Block","drawerSlug","slug","depth","toggleDrawer","inlineBlockElemElemRef","collectionSlug","getDocPreferences","globalSlug","config","componentMapRenderedBlockPath","blockType","clientSchemaMap","blocksField","clientBlock","blockReferences","blocksMap","blocks","clientBlockFields","getKey","length","undefined","removeInlineBlock","update","remove","blockDisplayName","labels","singular","onChangeAbortControllerRef","AbortController","schemaFieldsPath","abortController","awaitInitialState","state","data","docPermissions","docPreferences","documentFormState","initialBlockData","initialBlockFormState","operation","readOnly","renderAllFields","signal","newFormStateData","node","newData","setFields","onChange","prevFormState","submit","controller","isStateOutOfSync","Object","keys","some","key","value","onFormSubmit","RemoveButton","_jsx","buttonStyle","className","disabled","icon","onClick","e","preventDefault","round","size","tooltip","label","EditButton","el","InlineBlockContainer","children","filter","Boolean","join","ref","Label","_jsxs","beforeSubmit","disableValidationOnSubmit","onSubmit","title","_Fragment","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","programmaticSubmit","height","width"],"sources":["../../../../../src/features/blocks/client/componentInline/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react'\nconst baseClass = 'inline-block'\n\nimport type { BlocksFieldClient, ClientBlock, Data, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Drawer,\n EditDepthProvider,\n Form,\n formatDrawerSlug,\n FormSubmit,\n RenderFields,\n ShimmerEffect,\n useConfig,\n useDocumentForm,\n useDocumentInfo,\n useEditDepth,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\n\nimport './index.scss'\n\nimport { $getNodeByKey } from 'lexical'\nimport { deepCopyObjectSimpleWithoutReactComponents, reduceFieldsToValues } from 'payload/shared'\nimport { v4 as uuid } from 'uuid'\n\nimport type { InlineBlockFields } from '../../server/nodes/InlineBlocksNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\n\ntype Props = {\n /**\n * Can be modified by the node in order to trigger the re-fetch of the initial state based on the\n * formData. This is useful when node.setFields() is explicitly called from outside of the form - in\n * this case, the new field state is likely not reflected in the form state, so we need to re-fetch\n */\n readonly cacheBuster: number\n readonly formData: InlineBlockFields\n readonly nodeKey: string\n}\n\ntype InlineBlockComponentContextType = {\n EditButton?: React.FC\n initialState: false | FormState | undefined\n InlineBlockContainer?: React.FC<{ children: React.ReactNode }>\n Label?: React.FC\n nodeKey?: string\n RemoveButton?: React.FC\n}\n\nconst InlineBlockComponentContext = createContext<InlineBlockComponentContextType>({\n initialState: false,\n})\n\nexport const useInlineBlockComponentContext = () => React.use(InlineBlockComponentContext)\n\nexport const InlineBlockComponent: React.FC<Props> = (props) => {\n const { cacheBuster, formData, nodeKey } = props\n\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n const { i18n, t } = useTranslation<object, string>()\n const {\n createdInlineBlock,\n fieldProps: { featureClientSchemaMap, initialLexicalFormState, schemaPath },\n setCreatedInlineBlock,\n uuid: uuidFromContext,\n } = useEditorConfigContext()\n const { fields: parentDocumentFields } = useDocumentForm()\n\n const { getFormState } = useServerFunctions()\n const editDepth = useEditDepth()\n const firstTimeDrawer = useRef(false)\n\n const [initialState, setInitialState] = React.useState<false | FormState | undefined>(\n () => initialLexicalFormState?.[formData.id]?.formState,\n )\n\n const hasMounted = useRef(false)\n const prevCacheBuster = useRef(cacheBuster)\n useEffect(() => {\n if (hasMounted.current) {\n if (prevCacheBuster.current !== cacheBuster) {\n setInitialState(false)\n }\n prevCacheBuster.current = cacheBuster\n } else {\n hasMounted.current = true\n }\n }, [cacheBuster])\n\n const [CustomLabel, setCustomLabel] = React.useState<React.ReactNode | undefined>(\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n initialState?.['_components']?.customComponents?.BlockLabel,\n )\n\n const [CustomBlock, setCustomBlock] = React.useState<React.ReactNode | undefined>(\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n initialState?.['_components']?.customComponents?.Block,\n )\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-${uuidFromContext}-${formData.id}`,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n const inlineBlockElemElemRef = useRef<HTMLDivElement | null>(null)\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { config } = useConfig()\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${formData.blockType}`\n\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap?.[\n componentMapRenderedBlockPath\n ]?.[0] as BlocksFieldClient\n\n const clientBlock: ClientBlock | undefined = blocksField.blockReferences\n ? typeof blocksField?.blockReferences?.[0] === 'string'\n ? config.blocksMap[blocksField?.blockReferences?.[0]]\n : blocksField?.blockReferences?.[0]\n : blocksField?.blocks?.[0]\n\n const clientBlockFields = clientBlock?.fields ?? []\n\n // Open drawer on \"mount\"\n useEffect(() => {\n if (!firstTimeDrawer.current && createdInlineBlock?.getKey() === nodeKey) {\n // > 2 because they always have \"id\" and \"blockName\" fields\n if (clientBlockFields.length > 2) {\n toggleDrawer()\n }\n setCreatedInlineBlock?.(undefined)\n firstTimeDrawer.current = true\n }\n }, [clientBlockFields.length, createdInlineBlock, nodeKey, setCreatedInlineBlock, toggleDrawer])\n\n const removeInlineBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels.singular, i18n)\n : clientBlock?.slug\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${clientBlock?.slug}.fields`\n\n // Initial state for newly created blocks\n useEffect(() => {\n const abortController = new AbortController()\n\n const awaitInitialState = async () => {\n /*\n * This will only run if a new block is created. For all existing blocks that are loaded when the document is loaded, or when the form is saved,\n * this is not run, as the lexical field RSC will fetch the state server-side and pass it to the client. That way, we avoid unnecessary client-side\n * requests. Though for newly created blocks, we need to fetch the state client-side, as the server doesn't know about the block yet.\n */\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: formData,\n docPermissions: { fields: true },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n globalSlug,\n initialBlockData: formData,\n initialBlockFormState: formData,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: abortController.signal,\n })\n\n if (state) {\n const newFormStateData: InlineBlockFields = reduceFieldsToValues(\n deepCopyObjectSimpleWithoutReactComponents(state),\n true,\n ) as InlineBlockFields\n\n // Things like default values may come back from the server => update the node with the new data\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n const newData = newFormStateData\n newData.blockType = formData.blockType\n\n node.setFields(newData, true)\n }\n })\n\n setInitialState(state)\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n\n if (formData && !initialState) {\n void awaitInitialState()\n }\n\n return () => {\n abortAndIgnore(abortController)\n }\n }, [\n getFormState,\n editor,\n nodeKey,\n isEditable,\n schemaFieldsPath,\n id,\n formData,\n initialState,\n collectionSlug,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n ])\n\n /**\n * HANDLE ONCHANGE\n */\n const onChange = useCallback(\n async ({ formState: prevFormState, submit }: { formState: FormState; submit?: boolean }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: submit ? true : false,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n if (submit) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n\n return state\n },\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n isEditable,\n schemaFieldsPath,\n ],\n )\n // cleanup effect\n useEffect(() => {\n const isStateOutOfSync = (formData: InlineBlockFields, initialState: FormState) => {\n return Object.keys(initialState).some(\n (key) => initialState[key] && formData[key] !== initialState[key].value,\n )\n }\n\n return () => {\n // If the component is unmounted (either via removeInlineBlock or via lexical itself) and the form state got changed before,\n // we need to reset the initial state to force a re-fetch of the initial state when it gets mounted again (e.g. via lexical history undo).\n // Otherwise it would use an outdated initial state.\n if (initialState && isStateOutOfSync(formData, initialState)) {\n setInitialState(false)\n }\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [formData, initialState])\n\n /**\n * HANDLE FORM SUBMIT\n */\n const onFormSubmit = useCallback(\n (formState: FormState, newData: Data) => {\n newData.blockType = formData.blockType\n\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n node.setFields(newData as InlineBlockFields, true)\n }\n })\n },\n [editor, nodeKey, formData],\n )\n\n const RemoveButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeInlineBlock()\n }}\n round\n size=\"small\"\n tooltip={t('lexical:blocks:inlineBlocks:remove', { label: blockDisplayName })}\n />\n ),\n [blockDisplayName, isEditable, removeInlineBlock, t],\n )\n\n const EditButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__editButton`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n size=\"small\"\n tooltip={t('lexical:blocks:inlineBlocks:edit', { label: blockDisplayName })}\n />\n ),\n [blockDisplayName, isEditable, t, toggleDrawer],\n )\n\n const InlineBlockContainer = useMemo(\n () =>\n ({ children, className }: { children: React.ReactNode; className?: string }) => (\n <div\n className={[baseClass, baseClass + '-' + formData.blockType, className]\n .filter(Boolean)\n .join(' ')}\n ref={inlineBlockElemElemRef}\n >\n {children}\n </div>\n ),\n [formData.blockType],\n )\n\n const Label = useMemo(() => {\n if (CustomLabel) {\n return () => CustomLabel\n } else {\n return () => (\n <div>{clientBlock?.labels ? getTranslation(clientBlock?.labels.singular, i18n) : ''}</div>\n )\n }\n }, [CustomLabel, clientBlock?.labels, i18n])\n\n if (!clientBlock) {\n return (\n <InlineBlockContainer className={`${baseClass}-not-found`}>\n <span>Error: Block '{formData.blockType}' not found</span>\n {isEditable ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )\n }\n\n return (\n <Form\n beforeSubmit={[\n async ({ formState }) => {\n // This is only called when form is submitted from drawer\n return await onChange({ formState, submit: true })\n },\n ]}\n disableValidationOnSubmit\n el=\"div\"\n fields={clientBlock?.fields}\n initialState={initialState || {}}\n onChange={[onChange]}\n onSubmit={(formState, data) => {\n onFormSubmit(formState, data)\n toggleDrawer()\n }}\n uuid={uuid()}\n >\n <EditDepthProvider>\n <Drawer\n className={''}\n slug={drawerSlug}\n title={t(`lexical:blocks:inlineBlocks:${formData?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n >\n {initialState ? (\n <>\n <RenderFields\n fields={clientBlock?.fields}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\" // See Blocks feature path for details as for why this is empty\n parentSchemaPath={schemaFieldsPath}\n permissions={true}\n readOnly={!isEditable}\n />\n <FormSubmit programmaticSubmit={true}>{t('fields:saveChanges')}</FormSubmit>\n </>\n ) : null}\n </Drawer>\n </EditDepthProvider>\n {CustomBlock ? (\n <InlineBlockComponentContext\n value={{\n EditButton,\n initialState,\n InlineBlockContainer,\n Label,\n nodeKey,\n RemoveButton,\n }}\n >\n {CustomBlock}\n </InlineBlockComponentContext>\n ) : (\n <InlineBlockContainer>\n {initialState ? <Label /> : <ShimmerEffect height=\"15px\" width=\"40px\" />}\n {isEditable ? (\n <div className={`${baseClass}__actions`}>\n <EditButton />\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )}\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAEA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAC9E,MAAMC,SAAA,GAAY;AAIlB,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EACJC,gBAAgB,EAChBC,UAAU,EACVC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,cAAc,QACT;AACP,SAASC,cAAc,QAAQ;AAI/B,SAASC,aAAa,QAAQ;AAC9B,SAASC,0CAA0C,EAAEC,oBAAoB,QAAQ;AACjF,SAASC,EAAA,IAAMC,IAAI,QAAQ;AAI3B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,kBAAkB,QAAQ;AAsBnC,MAAMC,2BAAA,gBAA8BhC,aAAA,CAA+C;EACjFiC,YAAA,EAAc;AAChB;AAEA,OAAO,MAAMC,8BAAA,GAAiCA,CAAA,KAAMnC,KAAA,CAAMoC,GAAG,CAACH,2BAAA;AAE9D,OAAO,MAAMI,oBAAA,GAAyCC,KAAA;EACpD,MAAM;IAAEC,WAAW;IAAEC,QAAQ;IAAEC;EAAO,CAAE,GAAGH,KAAA;EAE3C,MAAM,CAACI,MAAA,CAAO,GAAGnC,yBAAA;EACjB,MAAMoC,UAAA,GAAanC,kBAAA;EACnB,MAAM;IAAEoC,IAAI;IAAEC;EAAC,CAAE,GAAGtB,cAAA;EACpB,MAAM;IACJuB,kBAAkB;IACl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AAW;QACX5D,IAAA,EAAMD,UAAA;QACNoF,KAAA,EAAO/G,CAAA,CAAE,+BAA+BL,QAAA,EAAUoB,EAAA,GAAK,SAAS,UAAU,EAAE;UAC1EkF,KAAA,EAAO9C,gBAAA,IAAoBnD,CAAA,CAAE;QAC/B;kBAECX,YAAA,gBACCsH,KAAA,CAAAK,SAAA;kCACE1B,IAAA,CAACnH,YAAA;YACCqC,MAAA,EAAQgC,WAAA,EAAahC,MAAA;YACrByG,WAAW;YACXC,eAAA,EAAgB;YAChBC,UAAA,EAAW,GAAG;YAAA;;YACdC,gBAAA,EAAkB5D,gBAAA;YAClB6D,WAAA,EAAa;YACblD,QAAA,EAAU,CAACrE;2BAEbwF,IAAA,CAACpH,UAAA;YAAWoJ,kBAAA,EAAoB;sBAAOtH,CAAA,CAAE;;aAEzC;;QAGPwB,WAAA,gBACC8D,IAAA,CAAClG,2BAAA;MACC+F,KAAA,EAAO;QACLe,UAAA;QACA7G,YAAA;QACA+G,oBAAA;QACAM,KAAA;QACA9G,OAAA;QACAyF;MACF;gBAEC7D;sBAGHmF,KAAA,CAACP,oBAAA;iBACE/G,YAAA,gBAAeiG,IAAA,CAACoB,KAAA,qBAAWpB,IAAA,CAAClH,aAAA;QAAcmJ,MAAA,EAAO;QAAOC,KAAA,EAAM;UAC9D1H,UAAA,gBACC6G,KAAA,CAAC;QAAInB,SAAA,EAAW,GAAG/H,SAAA,WAAoB;gCACrC6H,IAAA,CAACY,UAAA,O,aACDZ,IAAA,CAACD,YAAA;WAED;;;AAKd","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
1
  import './index.scss';
2
+ import React from 'react';
3
3
  import type { AdditionalCodeComponentProps } from './Code.js';
4
4
  export declare const CodeBlockBlockComponent: React.FC<Required<Pick<AdditionalCodeComponentProps, 'languages'>>>;
5
5
  //# sourceMappingURL=Block.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Block.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Block.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAA;AAQ7D,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAC5C,QAAQ,CAAC,IAAI,CAAC,4BAA4B,EAAE,WAAW,CAAC,CAAC,CA+F1D,CAAA"}
1
+ {"version":3,"file":"Block.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Block.tsx"],"names":[],"mappings":"AAKA,OAAO,cAAc,CAAA;AAWrB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAA;AAQ7D,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAC5C,QAAQ,CAAC,IAAI,CAAC,4BAA4B,EAAE,WAAW,CAAC,CAAC,CAmG1D,CAAA"}
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { c as _c } from "react/compiler-runtime";
4
4
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
+ import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
5
6
  import { ChevronIcon, CopyToClipboard, Popup, PopupList, RenderFields, useForm, useFormFields } from '@payloadcms/ui';
6
7
  import React from 'react';
7
8
  import { CodeBlockIcon } from '../../../../../lexical/ui/icons/CodeBlock/index.js';
@@ -10,7 +11,7 @@ import { Collapse } from './Collapse/index.js';
10
11
  import { FloatingCollapse } from './FloatingCollapse/index.js';
11
12
  const baseClass = 'payload-richtext-code-block';
12
13
  export const CodeBlockBlockComponent = args => {
13
- const $ = _c(14);
14
+ const $ = _c(15);
14
15
  const {
15
16
  languages
16
17
  } = args;
@@ -51,11 +52,12 @@ export const CodeBlockBlockComponent = args => {
51
52
  setSelectedLanguage
52
53
  } = useFormFields(t0);
53
54
  const selectedLanguageLabel = languages[selectedLanguageField?.value];
55
+ const isEditable = useLexicalEditable();
54
56
  const t1 = selectedLanguageField?.value;
55
57
  let t2;
56
- if ($[2] !== BlockCollapsible || $[3] !== RemoveButton || $[4] !== codeField?.value || $[5] !== formSchema || $[6] !== languages || $[7] !== selectedLanguageLabel || $[8] !== setSelectedLanguage || $[9] !== t1) {
58
+ if ($[2] !== BlockCollapsible || $[3] !== RemoveButton || $[4] !== codeField?.value || $[5] !== formSchema || $[6] !== isEditable || $[7] !== languages || $[8] !== selectedLanguageLabel || $[9] !== setSelectedLanguage || $[10] !== t1) {
57
59
  let t3;
58
- if ($[11] !== languages || $[12] !== setSelectedLanguage) {
60
+ if ($[12] !== languages || $[13] !== setSelectedLanguage) {
59
61
  t3 = t4 => {
60
62
  const {
61
63
  close
@@ -79,11 +81,11 @@ export const CodeBlockBlockComponent = args => {
79
81
  })
80
82
  });
81
83
  };
82
- $[11] = languages;
83
- $[12] = setSelectedLanguage;
84
- $[13] = t3;
84
+ $[12] = languages;
85
+ $[13] = setSelectedLanguage;
86
+ $[14] = t3;
85
87
  } else {
86
- t3 = $[13];
88
+ t3 = $[14];
87
89
  }
88
90
  t2 = _jsx(BlockCollapsible, {
89
91
  Actions: _jsxs("div", {
@@ -99,13 +101,14 @@ export const CodeBlockBlockComponent = args => {
99
101
  })]
100
102
  }),
101
103
  className: `${baseClass}__language-selector`,
104
+ disabled: !isEditable,
102
105
  horizontalAlign: "right",
103
106
  render: t3,
104
107
  showScrollbar: true,
105
108
  size: "large"
106
109
  }), _jsx(CopyToClipboard, {
107
110
  value: codeField?.value ?? ""
108
- }), _jsx(Collapse, {}), _jsx(RemoveButton, {})]
111
+ }), _jsx(Collapse, {}), isEditable && _jsx(RemoveButton, {})]
109
112
  }),
110
113
  className: baseClass,
111
114
  collapsibleProps: {
@@ -124,7 +127,8 @@ export const CodeBlockBlockComponent = args => {
124
127
  parentIndexPath: "",
125
128
  parentPath: "",
126
129
  parentSchemaPath: "",
127
- permissions: true
130
+ permissions: true,
131
+ readOnly: !isEditable
128
132
  })
129
133
  })
130
134
  });
@@ -132,13 +136,14 @@ export const CodeBlockBlockComponent = args => {
132
136
  $[3] = RemoveButton;
133
137
  $[4] = codeField?.value;
134
138
  $[5] = formSchema;
135
- $[6] = languages;
136
- $[7] = selectedLanguageLabel;
137
- $[8] = setSelectedLanguage;
138
- $[9] = t1;
139
- $[10] = t2;
139
+ $[6] = isEditable;
140
+ $[7] = languages;
141
+ $[8] = selectedLanguageLabel;
142
+ $[9] = setSelectedLanguage;
143
+ $[10] = t1;
144
+ $[11] = t2;
140
145
  } else {
141
- t2 = $[10];
146
+ t2 = $[11];
142
147
  }
143
148
  return t2;
144
149
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Block.js","names":["c","_c","ChevronIcon","CopyToClipboard","Popup","PopupList","RenderFields","useForm","useFormFields","React","CodeBlockIcon","useBlockComponentContext","Collapse","FloatingCollapse","baseClass","CodeBlockBlockComponent","args","$","languages","BlockCollapsible","formSchema","RemoveButton","setModified","codeField","_temp","t0","t1","fields_0","dispatch","selectedLanguageField","fields","language","setSelectedLanguage","type","path","value","selectedLanguageLabel","t2","t3","t4","close","_jsx","ButtonGroup","children","Object","entries","map","t5","languageCode","languageLabel","Button","active","disabled","onClick","className","Actions","_jsxs","button","horizontalAlign","render","disableHeaderToggle","disableToggleIndicator","Pill","_Fragment","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","code"],"sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Block.tsx"],"sourcesContent":["'use client'\nimport type {} from 'payload'\n\nimport {\n ChevronIcon,\n CopyToClipboard,\n Popup,\n PopupList,\n RenderFields,\n useForm,\n useFormFields,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport './index.scss'\n\nimport type { AdditionalCodeComponentProps } from './Code.js'\n\nimport { CodeBlockIcon } from '../../../../../lexical/ui/icons/CodeBlock/index.js'\nimport { useBlockComponentContext } from '../../../client/component/BlockContent.js'\nimport { Collapse } from './Collapse/index.js'\nimport { FloatingCollapse } from './FloatingCollapse/index.js'\n\nconst baseClass = 'payload-richtext-code-block'\nexport const CodeBlockBlockComponent: React.FC<\n Required<Pick<AdditionalCodeComponentProps, 'languages'>>\n> = (args) => {\n const { languages } = args\n const { BlockCollapsible, formSchema, RemoveButton } = useBlockComponentContext()\n const { setModified } = useForm()\n\n const { codeField } = useFormFields(([fields]) => ({\n codeField: fields?.code,\n }))\n\n const { selectedLanguageField, setSelectedLanguage } = useFormFields(([fields, dispatch]) => ({\n selectedLanguageField: fields?.language,\n setSelectedLanguage: (language: string) => {\n dispatch({\n type: 'UPDATE',\n path: 'language',\n value: language,\n })\n setModified(true)\n },\n }))\n\n const selectedLanguageLabel = languages[selectedLanguageField?.value as keyof typeof languages]\n\n return (\n <BlockCollapsible\n Actions={\n <div className={`${baseClass}__actions`}>\n <Popup\n button={\n <div\n className={`${baseClass}__language-selector-button`}\n data-selected-language={selectedLanguageField?.value}\n >\n <span>{selectedLanguageLabel}</span>\n <ChevronIcon className={`${baseClass}__chevron`} />\n </div>\n }\n className={`${baseClass}__language-selector`}\n horizontalAlign=\"right\"\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {Object.entries(languages).map(([languageCode, languageLabel]) => {\n return (\n <PopupList.Button\n active={false}\n disabled={false}\n key={languageCode}\n onClick={() => {\n setSelectedLanguage(languageCode)\n close()\n }}\n >\n <span className={`${baseClass}__language-code`} data-language={languageCode}>\n {languageLabel}\n </span>\n </PopupList.Button>\n )\n })}\n </PopupList.ButtonGroup>\n )}\n showScrollbar\n size=\"large\"\n />\n <CopyToClipboard value={(codeField?.value as string) ?? ''} />\n\n <Collapse />\n\n <RemoveButton />\n </div>\n }\n className={baseClass}\n collapsibleProps={{\n AfterCollapsible: <FloatingCollapse />,\n disableHeaderToggle: true,\n disableToggleIndicator: true,\n }}\n Pill={\n <div className={`${baseClass}__pill`}>\n <CodeBlockIcon />\n </div>\n }\n >\n <>\n <RenderFields\n fields={formSchema}\n forceRender={true}\n parentIndexPath=\"\"\n parentPath={''}\n parentSchemaPath=\"\"\n permissions={true}\n />\n </>\n </BlockCollapsible>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SACEC,WAAW,EACXC,eAAe,EACfC,KAAK,EACLC,SAAS,EACTC,YAAY,EACZC,OAAO,EACPC,aAAa,QACR;AACP,OAAOC,KAAA,MAAW;AAMlB,SAASC,aAAa,QAAQ;AAC9B,SAASC,wBAAwB,QAAQ;AACzC,SAASC,QAAQ,QAAQ;AACzB,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,SAAA,GAAY;AAClB,OAAO,MAAMC,uBAAA,GAETC,IAAA;EAAA,MAAAC,CAAA,GAAAhB,EAAA;EACF;IAAAiB;EAAA,IAAsBF,IAAA;EACtB;IAAAG,gBAAA;IAAAC,UAAA;IAAAC;EAAA,IAAuDV,wBAAA;EACvD;IAAAW;EAAA,IAAwBf,OAAA;EAExB;IAAAgB;EAAA,IAAsBf,aAAA,CAAAgB,KAEtB;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAK,WAAA;IAEqEG,EAAA,GAAAC,EAAA;MAAC,OAAAC,QAAA,EAAAC,QAAA,IAAAF,EAAkB;MAAA;QAAAG,qBAAA,EAC/DC,QAAA,EAAAC,QAAA;QAAAC,mBAAA,EAAAD,QAAA;UAErBH,QAAA;YAAAK,IAAA,EACQ;YAAAC,IAAA,EACA;YAAAC,KAAA,EACCJ;UAAA,CACT;UACAT,WAAA,KAAY;QAAA;MAAA;IAAA;IAEhBL,CAAA,MAAAK,WAAA;IAAAL,CAAA,MAAAQ,EAAA;EAAA;IAAAA,EAAA,GAAAR,CAAA;EAAA;EAVA;IAAAY,qBAAA;IAAAG;EAAA,IAAuDxB,aAAA,CAAciB,EAUrE;EAEA,MAAAW,qBAAA,GAA8BlB,SAAS,CAACW,qBAAA,EAAAM,KAAA;EAUF,MAAAT,EAAA,GAA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AMP;YAAA,C,GACPK,IAAA,CAAAvC,WAAA;cAAAoD,SAAA,EAAwB,GAAAxC,SAAA;YAAuB,C;;qBAGxC,GAAAA,SAAA,qBAAiC;UAAA4C,eAAA,EAC5B;UAAAC,MAAA,EACRrB,E;;gBAsBH;QAAA,C,GAEPG,IAAA,CAAAtC,eAAA;UAAAgC,KAAA,EAAwBZ,SAAC,EAAAY,KAAA,IAA+B;QAAA,C,GAExDM,IAAA,CAAA7B,QAAA,IAAC,GAED6B,IAAA,CAACpB,YAAA;MAAA,C;;;0BAKeoB,IAAA,CAAA5B,gBAAA,IAAC;QAAA+C,mBAAA;QAAAC,sBAAA;MAAA;MAAAC,IAAA,EAKnBrB,IAAA,CAAC;QAAAa,SAAA,EAAe,GAAAxC,SAAA,QAAoB;QAAA6B,QAAA,EAClCF,IAAA,CAAA/B,aAAA,IAAC;MAAA,C;gBAIL+B,IAAA,CAAAsB,SAAA;QAAApB,QAAA,EACEF,IAAA,CAAAnC,YAAA;UAAAwB,MAAA,EACUV,UAAA;UAAA4C,WAAA;UAAAC,eAAA,EAEQ;UAAAC,UAAA,EACJ;UAAAC,gBAAA,EACK;UAAAC,WAAA;QAAA,C;;;;;;;;;;;;;;;SAhEvB/B,E;CAsEJ;AA9FI,SAAAb,MAAAC,EAAA;EAKmC,OAAAK,MAAA,IAAAL,EAAQ;EAAA;IAAAF,SAAA,EAChCO,MAAA,EAAAuC;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"Block.js","names":["c","_c","useLexicalEditable","ChevronIcon","CopyToClipboard","Popup","PopupList","RenderFields","useForm","useFormFields","React","CodeBlockIcon","useBlockComponentContext","Collapse","FloatingCollapse","baseClass","CodeBlockBlockComponent","args","$","languages","BlockCollapsible","formSchema","RemoveButton","setModified","codeField","_temp","t0","t1","fields_0","dispatch","selectedLanguageField","fields","language","setSelectedLanguage","type","path","value","selectedLanguageLabel","isEditable","t2","t3","t4","close","_jsx","ButtonGroup","children","Object","entries","map","t5","languageCode","languageLabel","Button","active","disabled","onClick","className","Actions","_jsxs","button","horizontalAlign","render","disableHeaderToggle","disableToggleIndicator","Pill","_Fragment","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","readOnly","code"],"sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Block.tsx"],"sourcesContent":["'use client'\nimport type {} from 'payload'\n\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\n\nimport './index.scss'\n\nimport {\n ChevronIcon,\n CopyToClipboard,\n Popup,\n PopupList,\n RenderFields,\n useForm,\n useFormFields,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport type { AdditionalCodeComponentProps } from './Code.js'\n\nimport { CodeBlockIcon } from '../../../../../lexical/ui/icons/CodeBlock/index.js'\nimport { useBlockComponentContext } from '../../../client/component/BlockContent.js'\nimport { Collapse } from './Collapse/index.js'\nimport { FloatingCollapse } from './FloatingCollapse/index.js'\n\nconst baseClass = 'payload-richtext-code-block'\nexport const CodeBlockBlockComponent: React.FC<\n Required<Pick<AdditionalCodeComponentProps, 'languages'>>\n> = (args) => {\n const { languages } = args\n const { BlockCollapsible, formSchema, RemoveButton } = useBlockComponentContext()\n const { setModified } = useForm()\n\n const { codeField } = useFormFields(([fields]) => ({\n codeField: fields?.code,\n }))\n\n const { selectedLanguageField, setSelectedLanguage } = useFormFields(([fields, dispatch]) => ({\n selectedLanguageField: fields?.language,\n setSelectedLanguage: (language: string) => {\n dispatch({\n type: 'UPDATE',\n path: 'language',\n value: language,\n })\n setModified(true)\n },\n }))\n\n const selectedLanguageLabel = languages[selectedLanguageField?.value as keyof typeof languages]\n\n const isEditable = useLexicalEditable()\n\n return (\n <BlockCollapsible\n Actions={\n <div className={`${baseClass}__actions`}>\n <Popup\n button={\n <div\n className={`${baseClass}__language-selector-button`}\n data-selected-language={selectedLanguageField?.value}\n >\n <span>{selectedLanguageLabel}</span>\n <ChevronIcon className={`${baseClass}__chevron`} />\n </div>\n }\n className={`${baseClass}__language-selector`}\n disabled={!isEditable}\n horizontalAlign=\"right\"\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {Object.entries(languages).map(([languageCode, languageLabel]) => {\n return (\n <PopupList.Button\n active={false}\n disabled={false}\n key={languageCode}\n onClick={() => {\n setSelectedLanguage(languageCode)\n close()\n }}\n >\n <span className={`${baseClass}__language-code`} data-language={languageCode}>\n {languageLabel}\n </span>\n </PopupList.Button>\n )\n })}\n </PopupList.ButtonGroup>\n )}\n showScrollbar\n size=\"large\"\n />\n <CopyToClipboard value={(codeField?.value as string) ?? ''} />\n\n <Collapse />\n\n {isEditable && <RemoveButton />}\n </div>\n }\n className={baseClass}\n collapsibleProps={{\n AfterCollapsible: <FloatingCollapse />,\n disableHeaderToggle: true,\n disableToggleIndicator: true,\n }}\n Pill={\n <div className={`${baseClass}__pill`}>\n <CodeBlockIcon />\n </div>\n }\n >\n <>\n <RenderFields\n fields={formSchema}\n forceRender={true}\n parentIndexPath=\"\"\n parentPath={''}\n parentSchemaPath=\"\"\n permissions={true}\n readOnly={!isEditable}\n />\n </>\n </BlockCollapsible>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,kBAAkB,QAAQ;AAInC,SACEC,WAAW,EACXC,eAAe,EACfC,KAAK,EACLC,SAAS,EACTC,YAAY,EACZC,OAAO,EACPC,aAAa,QACR;AACP,OAAOC,KAAA,MAAW;AAIlB,SAASC,aAAa,QAAQ;AAC9B,SAASC,wBAAwB,QAAQ;AACzC,SAASC,QAAQ,QAAQ;AACzB,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,SAAA,GAAY;AAClB,OAAO,MAAMC,uBAAA,GAETC,IAAA;EAAA,MAAAC,CAAA,GAAAjB,EAAA;EACF;IAAAkB;EAAA,IAAsBF,IAAA;EACtB;IAAAG,gBAAA;IAAAC,UAAA;IAAAC;EAAA,IAAuDV,wBAAA;EACvD;IAAAW;EAAA,IAAwBf,OAAA;EAExB;IAAAgB;EAAA,IAAsB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,C;gBAILgC,IAAA,CAAAsB,SAAA;QAAApB,QAAA,EACEF,IAAA,CAAApC,YAAA;UAAAwB,MAAA,EACUV,UAAA;UAAA6C,WAAA;UAAAC,eAAA,EAEQ;UAAAC,UAAA,EACJ;UAAAC,gBAAA,EACK;UAAAC,WAAA;UAAAC,QAAA,GAENjC;QAAA,C;;;;;;;;;;;;;;;;SAnEjBC,E;CAwEJ;AAlGI,SAAAd,MAAAC,EAAA;EAKmC,OAAAK,MAAA,IAAAL,EAAQ;EAAA;IAAAF,SAAA,EAChCO,MAAA,EAAAyC;EAAA;AAAA","ignoreList":[]}
@@ -24,6 +24,14 @@ export type AdditionalCodeComponentProps = {
24
24
  * Configure typescript settings for the editor
25
25
  */
26
26
  typescript?: {
27
+ /**
28
+ * By default, the editor will not perform semantic validation. This means that
29
+ * while syntax errors will be highlighted, other issues like missing imports or incorrect
30
+ * types will not be.
31
+ *
32
+ * @default false
33
+ */
34
+ enableSemanticValidation?: boolean;
27
35
  /**
28
36
  * Additional types to fetch and include in the editor for autocompletion.
29
37
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Code.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Code.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAGpE,OAAO,KAAkB,MAAM,OAAO,CAAA;AAEtC,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,UAAU,CAAC,EAAE;QACX;;;;;;WAMG;QACH,UAAU,CAAC,EAAE,KAAK,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAA;YAChB,GAAG,EAAE,MAAM,CAAA;SACZ,CAAC,CAAA;QACF;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QAChC;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAA;QACf;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,4BAA4B,GAAG,oBAAoB,CAuGvF,CAAA"}
1
+ {"version":3,"file":"Code.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Code.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAGpE,OAAO,KAAkB,MAAM,OAAO,CAAA;AAEtC,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,UAAU,CAAC,EAAE;QACX;;;;;;WAMG;QACH,wBAAwB,CAAC,EAAE,OAAO,CAAA;QAClC;;;;;;WAMG;QACH,UAAU,CAAC,EAAE,KAAK,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAA;YAChB,GAAG,EAAE,MAAM,CAAA;SACZ,CAAC,CAAA;QACF;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QAChC;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAA;QACf;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,4BAA4B,GAAG,oBAAoB,CAwHvF,CAAA"}
@@ -29,6 +29,11 @@ export const CodeComponent = ({
29
29
  admin: {
30
30
  ...field.admin,
31
31
  editorOptions: {},
32
+ editorProps: {
33
+ // If typescript is set, @monaco-editor/react needs to set the URI to a .ts or .tsx file when it calls createModel().
34
+ // This is done through the `defaultPath` prop.
35
+ defaultPath: language === 'ts' ? 'file.tsx' : undefined
36
+ },
32
37
  language
33
38
  }
34
39
  }), [field, language]);
@@ -57,11 +62,21 @@ export const CodeComponent = ({
57
62
  monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
58
63
  allowNonTsExtensions: true,
59
64
  // Set module resolution to NodeJs to enable autocompletion
65
+ allowJs: true,
66
+ allowSyntheticDefaultImports: true,
67
+ esModuleInterop: true,
68
+ jsx: monaco.languages.typescript.JsxEmit.React,
60
69
  moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
70
+ noEmit: true,
61
71
  paths: typescript?.paths,
72
+ reactNamespace: 'React',
62
73
  target: monaco.languages.typescript.ScriptTarget[typescript?.target ?? 'ESNext'],
63
74
  typeRoots: typescript?.typeRoots ?? ['node_modules/@types']
64
75
  });
76
+ monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
77
+ noSemanticValidation: typescript?.enableSemanticValidation ? false : true,
78
+ noSyntaxValidation: false
79
+ });
65
80
  const run = async () => {
66
81
  if (typescript?.fetchTypes && Array.isArray(typescript.fetchTypes) && typescript.fetchTypes.length > 0) {
67
82
  await Promise.all(typescript.fetchTypes.map(async type => {
@@ -1 +1 @@
1
- {"version":3,"file":"Code.js","names":["CodeField","useFormFields","React","useMemo","CodeComponent","autoComplete","field","forceRender","languages","js","plaintext","ts","path","permissions","readOnly","renderedBlocks","schemaPath","typescript","validate","languageField","fields","language","value","initialValue","label","props","type","admin","editorOptions","key","name","_jsx","onMount","_editor","monaco","editor","defineTheme","base","colors","inherit","rules","typescriptDefaults","setCompilerOptions","allowNonTsExtensions","moduleResolution","ModuleResolutionKind","NodeJs","paths","target","ScriptTarget","typeRoots","run","fetchTypes","Array","isArray","length","Promise","all","map","types","fetch","url","typesText","text","addExtraLib","filePath"],"sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Code.tsx"],"sourcesContent":["'use client'\n\nimport type { CodeFieldClient, CodeFieldClientProps } from 'payload'\n\nimport { CodeField, useFormFields } from '@payloadcms/ui'\nimport React, { useMemo } from 'react'\n\nexport type AdditionalCodeComponentProps = {\n /**\n * @default first key of the `languages` prop\n */\n defaultLanguage?: string\n /**\n * @default\n * {\n * js: 'JavaScript',\n * plaintext: 'Plain Text',\n * ts: 'TypeScript',\n * }\n */\n languages?: Record<string, string>\n /**\n * Override the name of the block.\n *\n * @default 'Code'\n */\n slug?: string\n /**\n * Configure typescript settings for the editor\n */\n typescript?: {\n /**\n * Additional types to fetch and include in the editor for autocompletion.\n *\n * For example, to include types for payload, you would set this to\n *\n * [{ url: 'https://unpkg.com/payload@latest/dist/index.d.ts', filePath: 'file:///node_modules/payload/index.d.ts' }]\n */\n fetchTypes?: Array<{\n filePath: string\n url: string\n }>\n /**\n * @default undefined\n */\n paths?: Record<string, string[]>\n /**\n * @default \"ESNext\"\n */\n target?: string\n /**\n * @default ['node_modules/@types']\n */\n typeRoots?: string[]\n }\n}\n\nexport const CodeComponent: React.FC<AdditionalCodeComponentProps & CodeFieldClientProps> = ({\n autoComplete,\n field,\n forceRender,\n languages = {\n js: 'JavaScript',\n plaintext: 'Plain Text',\n ts: 'TypeScript',\n },\n path,\n permissions,\n readOnly,\n renderedBlocks,\n schemaPath,\n typescript,\n validate,\n}) => {\n const languageField = useFormFields(([fields]) => fields['language'])\n\n const language: string =\n (languageField?.value as string) || (languageField?.initialValue as string) || 'typescript'\n\n const label = languages[language]\n\n const props: CodeFieldClient = useMemo<CodeFieldClient>(\n () => ({\n ...field,\n type: 'code',\n admin: {\n ...field.admin,\n editorOptions: {},\n language,\n },\n }),\n [field, language],\n )\n\n const key = `${field.name}-${language}-${label}`\n\n return (\n props && (\n <CodeField\n autoComplete={autoComplete}\n field={props}\n forceRender={forceRender}\n key={key}\n onMount={(_editor, monaco) => {\n monaco.editor.defineTheme('vs-dark', {\n base: 'vs-dark',\n colors: {\n 'editor.background': '#222222',\n },\n inherit: true,\n rules: [],\n })\n\n monaco.editor.defineTheme('vs', {\n base: 'vs',\n colors: {\n 'editor.background': '#f5f5f5',\n },\n inherit: true,\n rules: [],\n })\n monaco.languages.typescript.typescriptDefaults.setCompilerOptions({\n allowNonTsExtensions: true,\n // Set module resolution to NodeJs to enable autocompletion\n moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,\n paths: typescript?.paths,\n target: monaco.languages.typescript.ScriptTarget[\n typescript?.target ?? ('ESNext' as any)\n ] as any,\n typeRoots: typescript?.typeRoots ?? ['node_modules/@types'],\n })\n const run = async () => {\n if (\n typescript?.fetchTypes &&\n Array.isArray(typescript.fetchTypes) &&\n typescript.fetchTypes.length > 0\n ) {\n await Promise.all(\n typescript.fetchTypes.map(async (type) => {\n const types = await fetch(type.url)\n const typesText = await types.text()\n monaco.languages.typescript.typescriptDefaults.addExtraLib(\n typesText,\n type.filePath,\n )\n }),\n )\n }\n }\n void run()\n }}\n path={path}\n permissions={permissions}\n readOnly={readOnly}\n renderedBlocks={renderedBlocks}\n schemaPath={schemaPath}\n validate={validate}\n />\n )\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,SAAS,EAAEC,aAAa,QAAQ;AACzC,OAAOC,KAAA,IAASC,OAAO,QAAQ;AAoD/B,OAAO,MAAMC,aAAA,GAA+EA,CAAC;EAC3FC,YAAY;EACZC,KAAK;EACLC,WAAW;EACXC,SAAA,GAAY;IACVC,EAAA,EAAI;IACJC,SAAA,EAAW;IACXC,EAAA,EAAI;EACN,CAAC;EACDC,IAAI;EACJC,WAAW;EACXC,QAAQ;EACRC,cAAc;EACdC,UAAU;EACVC,UAAU;EACVC;AAAQ,CACT;EACC,MAAMC,aAAA,GAAgBlB,aAAA,CAAc,CAAC,CAACmB,MAAA,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CAC9ChC,UAAA,EAAY+B,MAAA,IAAW,SACxB;QACDE,SAAA,EAAWjC,UAAA,EAAYiC,SAAA,IAAa,CAAC;MACvC;MACA,MAAMC,GAAA,GAAM,MAAAA,CAAA;QACV,IACElC,UAAA,EAAYmC,UAAA,IACZC,KAAA,CAAMC,OAAO,CAACrC,UAAA,CAAWmC,UAAU,KACnCnC,UAAA,CAAWmC,UAAU,CAACG,MAAM,GAAG,GAC/B;UACA,MAAMC,OAAA,CAAQC,GAAG,CACfxC,UAAA,CAAWmC,UAAU,CAACM,GAAG,CAAC,MAAOhC,IAAA;YAC/B,MAAMiC,KAAA,GAAQ,MAAMC,KAAA,CAAMlC,IAAA,CAAKmC,GAAG;YAClC,MAAMC,SAAA,GAAY,MAAMH,KAAA,CAAMI,IAAI;YAClC7B,MAAA,CAAO1B,SAAS,CAACS,UAAU,CAACwB,kBAAkB,CAACuB,WAAW,CACxDF,SAAA,EACApC,IAAA,CAAKuC,QAAQ;UAEjB;QAEJ;MACF;MACA,KAAKd,GAAA;IACP;IACAvC,IAAA,EAAMA,IAAA;IACNC,WAAA,EAAaA,WAAA;IACbC,QAAA,EAAUA,QAAA;IACVC,cAAA,EAAgBA,cAAA;IAChBC,UAAA,EAAYA,UAAA;IACZE,QAAA,EAAUA;KAtDLW,GAAA;AA0Db","ignoreList":[]}
1
+ {"version":3,"file":"Code.js","names":["CodeField","useFormFields","React","useMemo","CodeComponent","autoComplete","field","forceRender","languages","js","plaintext","ts","path","permissions","readOnly","renderedBlocks","schemaPath","typescript","validate","languageField","fields","language","value","initialValue","label","props","type","admin","editorOptions","editorProps","defaultPath","undefined","key","name","_jsx","onMount","_editor","monaco","editor","defineTheme","base","colors","inherit","rules","typescriptDefaults","setCompilerOptions","allowNonTsExtensions","allowJs","allowSyntheticDefaultImports","esModuleInterop","jsx","JsxEmit","moduleResolution","ModuleResolutionKind","NodeJs","noEmit","paths","reactNamespace","target","ScriptTarget","typeRoots","setDiagnosticsOptions","noSemanticValidation","enableSemanticValidation","noSyntaxValidation","run","fetchTypes","Array","isArray","length","Promise","all","map","types","fetch","url","typesText","text","addExtraLib","filePath"],"sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Code.tsx"],"sourcesContent":["'use client'\n\nimport type { CodeFieldClient, CodeFieldClientProps } from 'payload'\n\nimport { CodeField, useFormFields } from '@payloadcms/ui'\nimport React, { useMemo } from 'react'\n\nexport type AdditionalCodeComponentProps = {\n /**\n * @default first key of the `languages` prop\n */\n defaultLanguage?: string\n /**\n * @default\n * {\n * js: 'JavaScript',\n * plaintext: 'Plain Text',\n * ts: 'TypeScript',\n * }\n */\n languages?: Record<string, string>\n /**\n * Override the name of the block.\n *\n * @default 'Code'\n */\n slug?: string\n /**\n * Configure typescript settings for the editor\n */\n typescript?: {\n /**\n * By default, the editor will not perform semantic validation. This means that\n * while syntax errors will be highlighted, other issues like missing imports or incorrect\n * types will not be.\n *\n * @default false\n */\n enableSemanticValidation?: boolean\n /**\n * Additional types to fetch and include in the editor for autocompletion.\n *\n * For example, to include types for payload, you would set this to\n *\n * [{ url: 'https://unpkg.com/payload@latest/dist/index.d.ts', filePath: 'file:///node_modules/payload/index.d.ts' }]\n */\n fetchTypes?: Array<{\n filePath: string\n url: string\n }>\n /**\n * @default undefined\n */\n paths?: Record<string, string[]>\n /**\n * @default \"ESNext\"\n */\n target?: string\n /**\n * @default ['node_modules/@types']\n */\n typeRoots?: string[]\n }\n}\n\nexport const CodeComponent: React.FC<AdditionalCodeComponentProps & CodeFieldClientProps> = ({\n autoComplete,\n field,\n forceRender,\n languages = {\n js: 'JavaScript',\n plaintext: 'Plain Text',\n ts: 'TypeScript',\n },\n path,\n permissions,\n readOnly,\n renderedBlocks,\n schemaPath,\n typescript,\n validate,\n}) => {\n const languageField = useFormFields(([fields]) => fields['language'])\n\n const language: string =\n (languageField?.value as string) || (languageField?.initialValue as string) || 'typescript'\n\n const label = languages[language]\n\n const props: CodeFieldClient = useMemo<CodeFieldClient>(\n () => ({\n ...field,\n type: 'code',\n admin: {\n ...field.admin,\n editorOptions: {},\n editorProps: {\n // If typescript is set, @monaco-editor/react needs to set the URI to a .ts or .tsx file when it calls createModel().\n // This is done through the `defaultPath` prop.\n defaultPath: language === 'ts' ? 'file.tsx' : undefined,\n },\n language,\n },\n }),\n [field, language],\n )\n\n const key = `${field.name}-${language}-${label}`\n\n return (\n props && (\n <CodeField\n autoComplete={autoComplete}\n field={props}\n forceRender={forceRender}\n key={key}\n onMount={(_editor, monaco) => {\n monaco.editor.defineTheme('vs-dark', {\n base: 'vs-dark',\n colors: {\n 'editor.background': '#222222',\n },\n inherit: true,\n rules: [],\n })\n\n monaco.editor.defineTheme('vs', {\n base: 'vs',\n colors: {\n 'editor.background': '#f5f5f5',\n },\n inherit: true,\n rules: [],\n })\n monaco.languages.typescript.typescriptDefaults.setCompilerOptions({\n allowNonTsExtensions: true,\n // Set module resolution to NodeJs to enable autocompletion\n allowJs: true,\n allowSyntheticDefaultImports: true,\n esModuleInterop: true,\n jsx: monaco.languages.typescript.JsxEmit.React,\n moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,\n noEmit: true,\n paths: typescript?.paths,\n reactNamespace: 'React',\n target: monaco.languages.typescript.ScriptTarget[\n typescript?.target ?? ('ESNext' as any)\n ] as any,\n typeRoots: typescript?.typeRoots ?? ['node_modules/@types'],\n })\n\n monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({\n noSemanticValidation: typescript?.enableSemanticValidation ? false : true,\n noSyntaxValidation: false,\n })\n\n const run = async () => {\n if (\n typescript?.fetchTypes &&\n Array.isArray(typescript.fetchTypes) &&\n typescript.fetchTypes.length > 0\n ) {\n await Promise.all(\n typescript.fetchTypes.map(async (type) => {\n const types = await fetch(type.url)\n const typesText = await types.text()\n monaco.languages.typescript.typescriptDefaults.addExtraLib(\n typesText,\n type.filePath,\n )\n }),\n )\n }\n }\n void run()\n }}\n path={path}\n permissions={permissions}\n readOnly={readOnly}\n renderedBlocks={renderedBloc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CAAC,MAAO9C,IAAA;YAC/B,MAAM+C,KAAA,GAAQ,MAAMC,KAAA,CAAMhD,IAAA,CAAKiD,GAAG;YAClC,MAAMC,SAAA,GAAY,MAAMH,KAAA,CAAMI,IAAI;YAClCxC,MAAA,CAAO7B,SAAS,CAACS,UAAU,CAAC2B,kBAAkB,CAACkC,WAAW,CACxDF,SAAA,EACAlD,IAAA,CAAKqD,QAAQ;UAEjB;QAEJ;MACF;MACA,KAAKd,GAAA;IACP;IACArD,IAAA,EAAMA,IAAA;IACNC,WAAA,EAAaA,WAAA;IACbC,QAAA,EAAUA,QAAA;IACVC,cAAA,EAAgBA,cAAA;IAChBC,UAAA,EAAYA,UAAA;IACZE,QAAA,EAAUA;KAlELc,GAAA;AAsEb","ignoreList":[]}
@@ -2,9 +2,9 @@ export const i18n = {
2
2
  ar: {
3
3
  inlineBlocks: {
4
4
  create: 'أنشئ {{label}}',
5
- edit: 'تحرير {{التسمية}}',
5
+ edit: 'تحرير {{label}}',
6
6
  label: 'الكتل الداخلية',
7
- remove: 'إزالة {{التسمية}}'
7
+ remove: 'إزالة {{label}}'
8
8
  },
9
9
  label: 'كتل'
10
10
  },
@@ -19,16 +19,16 @@ export const i18n = {
19
19
  },
20
20
  bg: {
21
21
  inlineBlocks: {
22
- create: 'Създайте {{етикет}}',
23
- edit: 'Редактирай {{етикет}}',
22
+ create: 'Създайте {{label}}',
23
+ edit: 'Редактирай {{label}}',
24
24
  label: 'Вградени блокове',
25
- remove: 'Премахнете {{етикет}}'
25
+ remove: 'Премахнете {{label}}'
26
26
  },
27
27
  label: 'Блокове'
28
28
  },
29
29
  cs: {
30
30
  inlineBlocks: {
31
- create: 'Vytvořte {{štítek}}',
31
+ create: 'Vytvořte {{label}}',
32
32
  edit: 'Upravit {{label}}',
33
33
  label: 'Inline bloky',
34
34
  remove: 'Odstraňte {{label}}'
@@ -64,8 +64,8 @@ export const i18n = {
64
64
  },
65
65
  es: {
66
66
  inlineBlocks: {
67
- create: 'Crear {{etiqueta}}',
68
- edit: 'Editar {{etiqueta}}',
67
+ create: 'Crear {{label}}',
68
+ edit: 'Editar {{label}}',
69
69
  label: 'Bloques en línea',
70
70
  remove: 'Eliminar {{label}}'
71
71
  },
@@ -82,10 +82,10 @@ export const i18n = {
82
82
  },
83
83
  fa: {
84
84
  inlineBlocks: {
85
- create: 'ایجاد {{برچسب}}',
86
- edit: 'ویرایش {{برچسب}}',
85
+ create: 'ایجاد {{label}}',
86
+ edit: 'ویرایش {{label}}',
87
87
  label: 'بلوک‌های درون خطی',
88
- remove: 'حذف {{برچسب}}'
88
+ remove: 'حذف {{label}}'
89
89
  },
90
90
  label: 'بلوک ها'
91
91
  },
@@ -100,26 +100,26 @@ export const i18n = {
100
100
  },
101
101
  he: {
102
102
  inlineBlocks: {
103
- create: 'צור {{תווית}}',
104
- edit: 'ערוך {{תווית}}',
103
+ create: 'צור {{label}}',
104
+ edit: 'ערוך {{label}}',
105
105
  label: 'בלוקים משורשרים',
106
- remove: 'הסר {{תווית}}'
106
+ remove: 'הסר {{label}}'
107
107
  },
108
108
  label: 'חסימות'
109
109
  },
110
110
  hr: {
111
111
  inlineBlocks: {
112
- create: 'Stvori {{oznaka}}',
112
+ create: 'Stvori {{label}}',
113
113
  edit: 'Uredi {{label}}',
114
114
  label: 'Unutrašnji blokovi',
115
- remove: 'Ukloni {{oznaka}}'
115
+ remove: 'Ukloni {{label}}'
116
116
  },
117
117
  label: 'Blokovi'
118
118
  },
119
119
  hu: {
120
120
  inlineBlocks: {
121
- create: 'Hozzon létre {{címke}}',
122
- edit: 'Szerkesztés {{címke}}',
121
+ create: 'Hozzon létre {{label}}',
122
+ edit: 'Szerkesztés {{label}}',
123
123
  label: 'Beágyazott blokkok',
124
124
  remove: 'Távolítsa el a {{label}}'
125
125
  },
@@ -127,7 +127,7 @@ export const i18n = {
127
127
  },
128
128
  it: {
129
129
  inlineBlocks: {
130
- create: 'Crea {{etichetta}}',
130
+ create: 'Crea {{label}}',
131
131
  edit: 'Modifica {{label}}',
132
132
  label: 'Blocchi in linea',
133
133
  remove: 'Rimuovi {{label}}'
@@ -139,7 +139,7 @@ export const i18n = {
139
139
  create: '{{label}}を作成する',
140
140
  edit: '{{label}}を編集する',
141
141
  label: 'インラインブロック',
142
- remove: '{{ラベル}}を削除します'
142
+ remove: '{{label}}を削除します'
143
143
  },
144
144
  label: 'ブロック'
145
145
  },
@@ -182,9 +182,9 @@ export const i18n = {
182
182
  pl: {
183
183
  inlineBlocks: {
184
184
  create: 'Utwórz {{label}}',
185
- edit: 'Edytuj {{etykieta}}',
185
+ edit: 'Edytuj {{label}}',
186
186
  label: 'Blokowanie w linii',
187
- remove: 'Usuń {{etykieta}}'
187
+ remove: 'Usuń {{label}}'
188
188
  },
189
189
  label: 'Bloki'
190
190
  },
@@ -199,10 +199,10 @@ export const i18n = {
199
199
  },
200
200
  ro: {
201
201
  inlineBlocks: {
202
- create: 'Creează {{eticheta}}',
203
- edit: 'Editați {{eticheta}}',
202
+ create: 'Creează {{label}}',
203
+ edit: 'Editați {{label}}',
204
204
  label: 'Blocuri in linie',
205
- remove: 'Ștergeți {{etichetă}}'
205
+ remove: 'Ștergeți {{label}}'
206
206
  },
207
207
  label: 'Blocuri'
208
208
  },
@@ -220,22 +220,22 @@ export const i18n = {
220
220
  create: 'Kreiraj {{label}}',
221
221
  edit: 'Izmeni {{label}}',
222
222
  label: 'Umetnuti blokovi',
223
- remove: 'Ukloni {{oznaka}}'
223
+ remove: 'Ukloni {{label}}'
224
224
  },
225
225
  label: 'Blokovi'
226
226
  },
227
227
  ru: {
228
228
  inlineBlocks: {
229
229
  create: 'Создать {{label}}',
230
- edit: 'Изменить {{метка}}',
230
+ edit: 'Изменить {{label}}',
231
231
  label: 'Встроенные блоки',
232
- remove: 'Удалить {{метка}}'
232
+ remove: 'Удалить {{label}}'
233
233
  },
234
234
  label: 'Блоки'
235
235
  },
236
236
  sk: {
237
237
  inlineBlocks: {
238
- create: 'Vytvorte {{označenie}}',
238
+ create: 'Vytvorte {{label}}',
239
239
  edit: 'Upraviť {{label}}',
240
240
  label: 'Inline bloky',
241
241
  remove: 'Odstráňte {{label}}'
@@ -244,7 +244,7 @@ export const i18n = {
244
244
  },
245
245
  sl: {
246
246
  inlineBlocks: {
247
- create: 'Ustvari {{oznaka}}',
247
+ create: 'Ustvari {{label}}',
248
248
  edit: 'Uredi {{label}}',
249
249
  label: 'Vrstični bloki',
250
250
  remove: 'Odstrani {{label}}'
@@ -254,9 +254,9 @@ export const i18n = {
254
254
  sv: {
255
255
  inlineBlocks: {
256
256
  create: 'Skapa {{label}}',
257
- edit: 'Redigera {{etikett}}',
257
+ edit: 'Redigera {{label}}',
258
258
  label: 'Inline-blockar',
259
- remove: 'Ta bort {{etikett}}'
259
+ remove: 'Ta bort {{label}}'
260
260
  },
261
261
  label: 'Block'
262
262
  },
@@ -280,10 +280,10 @@ export const i18n = {
280
280
  },
281
281
  tr: {
282
282
  inlineBlocks: {
283
- create: '{{Etiketi}} oluşturun',
284
- edit: "{{Etiket}}'i düzenleyin",
283
+ create: '{{label}} oluşturun',
284
+ edit: "{{label}}'i düzenleyin",
285
285
  label: 'Satır İçi Bloklar',
286
- remove: '{{Etiketi}} kaldırın'
286
+ remove: '{{label}} kaldırın'
287
287
  },
288
288
  label: 'Bloklar'
289
289
  },
@@ -292,16 +292,16 @@ export const i18n = {
292
292
  create: 'Створити {{label}}',
293
293
  edit: 'Редагувати {{label}}',
294
294
  label: 'Вбудовані блоки',
295
- remove: 'Видалити {{мітку}}'
295
+ remove: 'Видалити {{label}}'
296
296
  },
297
297
  label: 'Блоки'
298
298
  },
299
299
  vi: {
300
300
  inlineBlocks: {
301
301
  create: 'Tạo {{label}}',
302
- edit: 'Chỉnh sửa {{nhãn}}',
302
+ edit: 'Chỉnh sửa {{label}}',
303
303
  label: 'Khối nội tuyến',
304
- remove: 'Xóa {{nhãn}}'
304
+ remove: 'Xóa {{label}}'
305
305
  },
306
306
  label: 'Khối'
307
307
  },