@payloadcms/richtext-lexical 3.59.0-internal.898dbd3 → 3.59.0-internal.cb85185
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/Field-RQHCQRLV.js +2 -0
- package/dist/exports/client/Field-RQHCQRLV.js.map +7 -0
- package/dist/exports/client/RelationshipComponent-TSIENULZ.js +2 -0
- package/dist/exports/client/RelationshipComponent-TSIENULZ.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-BQCXN3B4.js +2 -0
- package/dist/exports/client/chunk-BQCXN3B4.js.map +7 -0
- package/dist/exports/client/chunk-XNERFY6G.js +2 -0
- package/dist/exports/client/chunk-XNERFY6G.js.map +7 -0
- package/dist/exports/client/component-CYFKY3IL.js +2 -0
- package/dist/exports/client/component-CYFKY3IL.js.map +7 -0
- package/dist/exports/client/componentInline-NGTRUSGB.js +2 -0
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +4 -1
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +15 -12
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +13 -10
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +20 -15
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Code.d.ts +8 -0
- package/dist/features/blocks/premade/CodeBlock/Component/Code.d.ts.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js +15 -0
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +5 -3
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +3 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.js +5 -9
- package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js +7 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.d.ts.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +3 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/upload/client/component/index.d.ts.map +1 -1
- package/dist/features/upload/client/component/index.js +6 -5
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/field/RenderLexical/index.d.ts.map +1 -1
- package/dist/field/RenderLexical/index.js +1 -0
- package/dist/field/RenderLexical/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +2 -0
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +10 -8
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/utilities/buildInitialState.d.ts +1 -0
- package/dist/utilities/buildInitialState.d.ts.map +1 -1
- package/dist/utilities/buildInitialState.js +1 -0
- package/dist/utilities/buildInitialState.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +7 -3
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/package.json +7 -7
- package/dist/exports/client/Field-2MCIQXRP.js +0 -2
- package/dist/exports/client/Field-2MCIQXRP.js.map +0 -7
- package/dist/exports/client/RelationshipComponent-APF3CN47.js +0 -2
- package/dist/exports/client/RelationshipComponent-APF3CN47.js.map +0 -7
- package/dist/exports/client/chunk-CYLMY5ZJ.js +0 -2
- package/dist/exports/client/chunk-CYLMY5ZJ.js.map +0 -7
- package/dist/exports/client/chunk-K47TNP5J.js +0 -2
- package/dist/exports/client/chunk-K47TNP5J.js.map +0 -7
- package/dist/exports/client/component-VDJI45F2.js +0 -2
- package/dist/exports/client/component-VDJI45F2.js.map +0 -7
- package/dist/exports/client/componentInline-AGFSKAY4.js +0 -2
- /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;AAI9B,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,gBAA8B/B,aAAA,CAA+C;EACjFgC,YAAA,EAAc;AAChB;AAEA,OAAO,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+
{"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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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":"
|
|
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
|
+
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] !==
|
|
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 ($[
|
|
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
|
-
$[
|
|
83
|
-
$[
|
|
84
|
-
$[
|
|
84
|
+
$[12] = languages;
|
|
85
|
+
$[13] = setSelectedLanguage;
|
|
86
|
+
$[14] = t3;
|
|
85
87
|
} else {
|
|
86
|
-
t3 = $[
|
|
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] =
|
|
136
|
-
$[7] =
|
|
137
|
-
$[8] =
|
|
138
|
-
$[9] =
|
|
139
|
-
$[10] =
|
|
139
|
+
$[6] = isEditable;
|
|
140
|
+
$[7] = languages;
|
|
141
|
+
$[8] = selectedLanguageLabel;
|
|
142
|
+
$[9] = setSelectedLanguage;
|
|
143
|
+
$[10] = t1;
|
|
144
|
+
$[11] = t2;
|
|
140
145
|
} else {
|
|
141
|
-
t2 = $[
|
|
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
|
|
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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AA,CAAA9B,QAAA,IAAC,GAEAyB,UAAA,IAAcK,IAAA,CAACrB,YAAA;MAAA,C;;;0BAKAqB,IAAA,CAAA7B,gBAAA,IAAC;QAAAgD,mBAAA;QAAAC,sBAAA;MAAA;MAAAC,IAAA,EAKnBrB,IAAA,CAAC;QAAAa,SAAA,EAAe,GAAAzC,SAAA,QAAoB;QAAA8B,QAAA,EAClCF,IAAA,CAAAhC,aAAA,IAAC;MAAA,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,
|
|
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;
|
|
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={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;AA4D/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,CAAO,KAAKA,MAAM,CAAC,WAAW;EAEpE,MAAMC,QAA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TableHoverActionsPlugin/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AA+Q9B,wBAAgB,uBAAuB,CAAC,EACtC,UAA0B,GAC3B,EAAE;IACD,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB,GAAG,IAAI,GAAG,KAAK,CAAC,WAAW,CAQ3B"}
|
|
@@ -3,6 +3,7 @@
|
|
|
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
5
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
6
|
+
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
6
7
|
import { $getTableAndElementByKey, $getTableColumnIndexFromTableCellNode, $getTableRowIndexFromTableCellNode, $insertTableColumnAtSelection, $insertTableRowAtSelection, $isTableCellNode, $isTableNode, getTableElement, TableNode } from '@lexical/table';
|
|
7
8
|
import { $findMatchingParent, mergeRegister } from '@lexical/utils';
|
|
8
9
|
import { $getNearestNodeFromDOMNode, isHTMLElement } from 'lexical';
|
|
@@ -16,6 +17,7 @@ function TableHoverActionsContainer({
|
|
|
16
17
|
anchorElem
|
|
17
18
|
}) {
|
|
18
19
|
const [editor] = useLexicalComposerContext();
|
|
20
|
+
const isEditable = useLexicalEditable();
|
|
19
21
|
const editorConfig = useEditorConfigContext();
|
|
20
22
|
const [isShownRow, setShownRow] = useState(false);
|
|
21
23
|
const [isShownColumn, setShownColumn] = useState(false);
|
|
@@ -181,7 +183,7 @@ function TableHoverActionsContainer({
|
|
|
181
183
|
}
|
|
182
184
|
});
|
|
183
185
|
};
|
|
184
|
-
if (!
|
|
186
|
+
if (!isEditable) {
|
|
185
187
|
return null;
|
|
186
188
|
}
|
|
187
189
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
@@ -226,8 +228,8 @@ export function TableHoverActionsPlugin(t0) {
|
|
|
226
228
|
anchorElem: t1
|
|
227
229
|
} = t0;
|
|
228
230
|
const anchorElem = t1 === undefined ? document.body : t1;
|
|
229
|
-
const
|
|
230
|
-
if (!
|
|
231
|
+
const isEditable = useLexicalEditable();
|
|
232
|
+
if (!isEditable) {
|
|
231
233
|
return null;
|
|
232
234
|
}
|
|
233
235
|
let t2;
|
package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$getTableAndElementByKey","$getTableColumnIndexFromTableCellNode","$getTableRowIndexFromTableCellNode","$insertTableColumnAtSelection","$insertTableRowAtSelection","$isTableCellNode","$isTableNode","getTableElement","TableNode","$findMatchingParent","mergeRegister","$getNearestNodeFromDOMNode","isHTMLElement","useEffect","useMemo","useRef","useState","React","createPortal","useEditorConfigContext","useDebounce","BUTTON_WIDTH_PX","TableHoverActionsContainer","anchorElem","editor","editorConfig","isShownRow","setShownRow","isShownColumn","setShownColumn","shouldListenMouseMove","setShouldListenMouseMove","position","setPosition","tableSetRef","Set","tableCellDOMNodeRef","debouncedOnMouseMove","event","isOutside","tableDOMNode","getMouseInfo","lexical","current","hoveredRowNode","hoveredColumnNode","tableDOMElement","getEditorState","read","maybeTableCell","table","node","getElementByKey","getKey","rowCount","getChildrenSize","colCount","getChildAtIndex","rowIndex","colIndex","tableContainerElement","parentElement","bottom","tableElemBottom","height","tableElemHeight","left","tableElemLeft","right","tableElemRight","width","tableElemWidth","y","tableElemY","getBoundingClientRect","tableHasScroll","classList","contains","scrollWidth","clientWidth","editorElemLeft","editorElemY","offsetLeft","top","offsetWidth","tableResizeObserver","ResizeObserver","document","addEventListener","removeEventListener","registerMutationListener","mutations","resetObserver","key","type","add","delete","disconnect","tableKey","tableElement","observe","size","skipInitialization","insertAction","insertRow","update","maybeTableNode","selectEnd","isEditable","_jsxs","_Fragment","_jsx","className","theme","tableAddRows","onClick","style","tableAddColumns","target","closest","tableCell","tableCellResizer","TableHoverActionsPlugin","t0","$","t1","undefined","body","t2"],"sources":["../../../../../../src/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type { TableCellNode, TableRowNode } from '@lexical/table'\nimport type { EditorConfig, NodeKey } from 'lexical'\nimport type { JSX } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport {\n $getTableAndElementByKey,\n $getTableColumnIndexFromTableCellNode,\n $getTableRowIndexFromTableCellNode,\n $insertTableColumnAtSelection,\n $insertTableRowAtSelection,\n $isTableCellNode,\n $isTableNode,\n getTableElement,\n TableNode,\n} from '@lexical/table'\nimport { $findMatchingParent, mergeRegister } from '@lexical/utils'\nimport { $getNearestNodeFromDOMNode, isHTMLElement } from 'lexical'\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useDebounce } from '../../utils/useDebounce.js'\n\nconst BUTTON_WIDTH_PX = 20\n\nfunction TableHoverActionsContainer({\n anchorElem,\n}: {\n anchorElem: HTMLElement\n}): JSX.Element | null {\n const [editor] = useLexicalComposerContext()\n const editorConfig = useEditorConfigContext()\n const [isShownRow, setShownRow] = useState<boolean>(false)\n const [isShownColumn, setShownColumn] = useState<boolean>(false)\n const [shouldListenMouseMove, setShouldListenMouseMove] = useState<boolean>(false)\n const [position, setPosition] = useState({})\n const tableSetRef = useRef<Set<NodeKey>>(new Set())\n const tableCellDOMNodeRef = useRef<HTMLElement | null>(null)\n\n const debouncedOnMouseMove = useDebounce(\n (event: MouseEvent) => {\n const { isOutside, tableDOMNode } = getMouseInfo(event, editorConfig.editorConfig?.lexical)\n\n if (isOutside) {\n setShownRow(false)\n setShownColumn(false)\n return\n }\n\n if (!tableDOMNode) {\n return\n }\n\n tableCellDOMNodeRef.current = tableDOMNode\n\n let hoveredRowNode: null | TableCellNode = null\n let hoveredColumnNode: null | TableCellNode = null\n let tableDOMElement: HTMLElement | null = null\n\n editor.getEditorState().read(\n () => {\n const maybeTableCell = $getNearestNodeFromDOMNode(tableDOMNode)\n\n if ($isTableCellNode(maybeTableCell)) {\n const table = $findMatchingParent(maybeTableCell, (node) => $isTableNode(node))\n if (!$isTableNode(table)) {\n return\n }\n\n tableDOMElement = getTableElement(table, editor.getElementByKey(table.getKey()))\n\n if (tableDOMElement) {\n const rowCount = table.getChildrenSize()\n const colCount = (table.getChildAtIndex(0) as TableRowNode)?.getChildrenSize()\n\n const rowIndex = $getTableRowIndexFromTableCellNode(maybeTableCell)\n const colIndex = $getTableColumnIndexFromTableCellNode(maybeTableCell)\n\n if (rowIndex === rowCount - 1) {\n hoveredRowNode = maybeTableCell\n } else if (colIndex === colCount - 1) {\n hoveredColumnNode = maybeTableCell\n }\n }\n }\n },\n { editor },\n )\n\n if (!tableDOMElement) {\n return\n }\n\n // this is the scrollable div container of the table (in case of overflow)\n const tableContainerElement = (tableDOMElement as HTMLTableElement).parentElement\n\n if (!tableContainerElement) {\n return\n }\n\n const {\n bottom: tableElemBottom,\n height: tableElemHeight,\n left: tableElemLeft,\n right: tableElemRight,\n width: tableElemWidth,\n y: tableElemY,\n } = (tableDOMElement as HTMLTableElement).getBoundingClientRect()\n\n let tableHasScroll = false\n if (\n tableContainerElement &&\n tableContainerElement.classList.contains('LexicalEditorTheme__tableScrollableWrapper')\n ) {\n tableHasScroll = tableContainerElement.scrollWidth > tableContainerElement.clientWidth\n }\n\n const { left: editorElemLeft, y: editorElemY } = anchorElem.getBoundingClientRect()\n\n if (hoveredRowNode) {\n setShownColumn(false)\n setShownRow(true)\n setPosition({\n height: BUTTON_WIDTH_PX,\n left:\n tableHasScroll && tableContainerElement\n ? tableContainerElement.offsetLeft\n : tableElemLeft - editorElemLeft,\n top: tableElemBottom - editorElemY + 5,\n width:\n tableHasScroll && tableContainerElement\n ? tableContainerElement.offsetWidth\n : tableElemWidth,\n })\n } else if (hoveredColumnNode) {\n setShownColumn(true)\n setShownRow(false)\n setPosition({\n height: tableElemHeight,\n left: tableElemRight - editorElemLeft + 5,\n top: tableElemY - editorElemY,\n width: BUTTON_WIDTH_PX,\n })\n }\n },\n 50,\n 250,\n )\n\n // Hide the buttons on any table dimensions change to prevent last row cells\n // overlap behind the 'Add Row' button when text entry changes cell height\n const tableResizeObserver = useMemo(() => {\n return new ResizeObserver(() => {\n setShownRow(false)\n setShownColumn(false)\n })\n }, [])\n\n useEffect(() => {\n if (!shouldListenMouseMove) {\n return\n }\n\n document.addEventListener('mousemove', debouncedOnMouseMove)\n\n return () => {\n setShownRow(false)\n setShownColumn(false)\n\n document.removeEventListener('mousemove', debouncedOnMouseMove)\n }\n }, [shouldListenMouseMove, debouncedOnMouseMove])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerMutationListener(\n TableNode,\n (mutations) => {\n editor.getEditorState().read(\n () => {\n let resetObserver = false\n for (const [key, type] of mutations) {\n switch (type) {\n case 'created': {\n tableSetRef.current.add(key)\n resetObserver = true\n break\n }\n case 'destroyed': {\n tableSetRef.current.delete(key)\n resetObserver = true\n break\n }\n default:\n break\n }\n }\n if (resetObserver) {\n // Reset resize observers\n tableResizeObserver.disconnect()\n for (const tableKey of tableSetRef.current) {\n const { tableElement } = $getTableAndElementByKey(tableKey)\n tableResizeObserver.observe(tableElement)\n }\n setShouldListenMouseMove(tableSetRef.current.size > 0)\n }\n },\n { editor },\n )\n },\n { skipInitialization: false },\n ),\n )\n }, [editor, tableResizeObserver])\n\n const insertAction = (insertRow: boolean) => {\n editor.update(() => {\n if (tableCellDOMNodeRef.current) {\n const maybeTableNode = $getNearestNodeFromDOMNode(tableCellDOMNodeRef.current)\n maybeTableNode?.selectEnd()\n if (insertRow) {\n $insertTableRowAtSelection()\n setShownRow(false)\n } else {\n $insertTableColumnAtSelection()\n setShownColumn(false)\n }\n }\n })\n }\n\n if (!editor?.isEditable()) {\n return null\n }\n\n return (\n <>\n {isShownRow && (\n <button\n aria-label=\"Add Row\"\n className={editorConfig.editorConfig.lexical.theme.tableAddRows}\n onClick={() => insertAction(true)}\n style={{ ...position }}\n type=\"button\"\n />\n )}\n {isShownColumn && (\n <button\n aria-label=\"Add Column\"\n className={editorConfig.editorConfig.lexical.theme.tableAddColumns}\n onClick={() => insertAction(false)}\n style={{ ...position }}\n type=\"button\"\n />\n )}\n </>\n )\n}\n\nfunction getMouseInfo(\n event: MouseEvent,\n editorConfig: EditorConfig,\n): {\n isOutside: boolean\n tableDOMNode: HTMLElement | null\n} {\n const target = event.target\n\n if (isHTMLElement(target)) {\n const tableDOMNode = target.closest<HTMLElement>(\n `td.${editorConfig.theme.tableCell}, th.${editorConfig.theme.tableCell}`,\n )\n\n const isOutside = !(\n tableDOMNode ||\n target.closest<HTMLElement>(`button.${editorConfig.theme.tableAddRows}`) ||\n target.closest<HTMLElement>(`button.${editorConfig.theme.tableAddColumns}`) ||\n target.closest<HTMLElement>(`div.${editorConfig.theme.tableCellResizer}`)\n )\n\n return { isOutside, tableDOMNode }\n } else {\n return { isOutside: true, tableDOMNode: null }\n }\n}\n\nexport function TableHoverActionsPlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): null | React.ReactPortal {\n const [editor] = useLexicalComposerContext()\n if (!editor?.isEditable()) {\n return null\n }\n\n return createPortal(<TableHoverActionsContainer anchorElem={anchorElem} />, anchorElem)\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAMA,SAASC,yBAAyB,QAAQ;AAC1C,SACEC,wBAAwB,EACxBC,qCAAqC,EACrCC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,OAAO;IACL,OAAO;MAAED,SAAA,EAAW;MAAMC,YAAA,EAAc;IAAK;EAC/C;AACF;AAEA,OAAO,SAAAkF,wBAAAC,EAAA;EAAA,MAAAC,CAAA,GAAA9H,EAAA;EAAiC;IAAAyB,UAAA,EAAAsG;EAAA,IAAAF,EAIvC;EAHC,MAAApG,UAAA,GAAAsG,EAA0B,KAAAC,SAAA,GAAAvC,QAAA,CAAAwC,IAAA,GAA1BF,EAA0B;EAI1B,OAAArG,MAAA,IAAiBzB,yBAAA;EAAA,KACZyB,MAAA,EAAAoF,UAAA;IAAA;EAAA;EAAA,IAAAoB,EAAA;EAAA,IAAAJ,CAAA,QAAArG,UAAA;IAIEyG,EAAA,GAAA9G,YAAA,CAAa6F,IAAA,CAAAzF,0BAAA;MAAAC;IAAA,C,GAAwDA,UAAA;IAAAqG,CAAA,MAAArG,UAAA;IAAAqG,CAAA,MAAAI,EAAA;EAAA;IAAAA,EAAA,GAAAJ,CAAA;EAAA;EAAA,OAArEI,EAAqE;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useLexicalEditable","$getTableAndElementByKey","$getTableColumnIndexFromTableCellNode","$getTableRowIndexFromTableCellNode","$insertTableColumnAtSelection","$insertTableRowAtSelection","$isTableCellNode","$isTableNode","getTableElement","TableNode","$findMatchingParent","mergeRegister","$getNearestNodeFromDOMNode","isHTMLElement","useEffect","useMemo","useRef","useState","React","createPortal","useEditorConfigContext","useDebounce","BUTTON_WIDTH_PX","TableHoverActionsContainer","anchorElem","editor","isEditable","editorConfig","isShownRow","setShownRow","isShownColumn","setShownColumn","shouldListenMouseMove","setShouldListenMouseMove","position","setPosition","tableSetRef","Set","tableCellDOMNodeRef","debouncedOnMouseMove","event","isOutside","tableDOMNode","getMouseInfo","lexical","current","hoveredRowNode","hoveredColumnNode","tableDOMElement","getEditorState","read","maybeTableCell","table","node","getElementByKey","getKey","rowCount","getChildrenSize","colCount","getChildAtIndex","rowIndex","colIndex","tableContainerElement","parentElement","bottom","tableElemBottom","height","tableElemHeight","left","tableElemLeft","right","tableElemRight","width","tableElemWidth","y","tableElemY","getBoundingClientRect","tableHasScroll","classList","contains","scrollWidth","clientWidth","editorElemLeft","editorElemY","offsetLeft","top","offsetWidth","tableResizeObserver","ResizeObserver","document","addEventListener","removeEventListener","registerMutationListener","mutations","resetObserver","key","type","add","delete","disconnect","tableKey","tableElement","observe","size","skipInitialization","insertAction","insertRow","update","maybeTableNode","selectEnd","_jsxs","_Fragment","_jsx","className","theme","tableAddRows","onClick","style","tableAddColumns","target","closest","tableCell","tableCellResizer","TableHoverActionsPlugin","t0","$","t1","undefined","body","t2"],"sources":["../../../../../../src/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type { TableCellNode, TableRowNode } from '@lexical/table'\nimport type { EditorConfig, NodeKey } from 'lexical'\nimport type { JSX } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport {\n $getTableAndElementByKey,\n $getTableColumnIndexFromTableCellNode,\n $getTableRowIndexFromTableCellNode,\n $insertTableColumnAtSelection,\n $insertTableRowAtSelection,\n $isTableCellNode,\n $isTableNode,\n getTableElement,\n TableNode,\n} from '@lexical/table'\nimport { $findMatchingParent, mergeRegister } from '@lexical/utils'\nimport { $getNearestNodeFromDOMNode, isHTMLElement } from 'lexical'\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useDebounce } from '../../utils/useDebounce.js'\n\nconst BUTTON_WIDTH_PX = 20\n\nfunction TableHoverActionsContainer({\n anchorElem,\n}: {\n anchorElem: HTMLElement\n}): JSX.Element | null {\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n\n const editorConfig = useEditorConfigContext()\n const [isShownRow, setShownRow] = useState<boolean>(false)\n const [isShownColumn, setShownColumn] = useState<boolean>(false)\n const [shouldListenMouseMove, setShouldListenMouseMove] = useState<boolean>(false)\n const [position, setPosition] = useState({})\n const tableSetRef = useRef<Set<NodeKey>>(new Set())\n const tableCellDOMNodeRef = useRef<HTMLElement | null>(null)\n\n const debouncedOnMouseMove = useDebounce(\n (event: MouseEvent) => {\n const { isOutside, tableDOMNode } = getMouseInfo(event, editorConfig.editorConfig?.lexical)\n\n if (isOutside) {\n setShownRow(false)\n setShownColumn(false)\n return\n }\n\n if (!tableDOMNode) {\n return\n }\n\n tableCellDOMNodeRef.current = tableDOMNode\n\n let hoveredRowNode: null | TableCellNode = null\n let hoveredColumnNode: null | TableCellNode = null\n let tableDOMElement: HTMLElement | null = null\n\n editor.getEditorState().read(\n () => {\n const maybeTableCell = $getNearestNodeFromDOMNode(tableDOMNode)\n\n if ($isTableCellNode(maybeTableCell)) {\n const table = $findMatchingParent(maybeTableCell, (node) => $isTableNode(node))\n if (!$isTableNode(table)) {\n return\n }\n\n tableDOMElement = getTableElement(table, editor.getElementByKey(table.getKey()))\n\n if (tableDOMElement) {\n const rowCount = table.getChildrenSize()\n const colCount = (table.getChildAtIndex(0) as TableRowNode)?.getChildrenSize()\n\n const rowIndex = $getTableRowIndexFromTableCellNode(maybeTableCell)\n const colIndex = $getTableColumnIndexFromTableCellNode(maybeTableCell)\n\n if (rowIndex === rowCount - 1) {\n hoveredRowNode = maybeTableCell\n } else if (colIndex === colCount - 1) {\n hoveredColumnNode = maybeTableCell\n }\n }\n }\n },\n { editor },\n )\n\n if (!tableDOMElement) {\n return\n }\n\n // this is the scrollable div container of the table (in case of overflow)\n const tableContainerElement = (tableDOMElement as HTMLTableElement).parentElement\n\n if (!tableContainerElement) {\n return\n }\n\n const {\n bottom: tableElemBottom,\n height: tableElemHeight,\n left: tableElemLeft,\n right: tableElemRight,\n width: tableElemWidth,\n y: tableElemY,\n } = (tableDOMElement as HTMLTableElement).getBoundingClientRect()\n\n let tableHasScroll = false\n if (\n tableContainerElement &&\n tableContainerElement.classList.contains('LexicalEditorTheme__tableScrollableWrapper')\n ) {\n tableHasScroll = tableContainerElement.scrollWidth > tableContainerElement.clientWidth\n }\n\n const { left: editorElemLeft, y: editorElemY } = anchorElem.getBoundingClientRect()\n\n if (hoveredRowNode) {\n setShownColumn(false)\n setShownRow(true)\n setPosition({\n height: BUTTON_WIDTH_PX,\n left:\n tableHasScroll && tableContainerElement\n ? tableContainerElement.offsetLeft\n : tableElemLeft - editorElemLeft,\n top: tableElemBottom - editorElemY + 5,\n width:\n tableHasScroll && tableContainerElement\n ? tableContainerElement.offsetWidth\n : tableElemWidth,\n })\n } else if (hoveredColumnNode) {\n setShownColumn(true)\n setShownRow(false)\n setPosition({\n height: tableElemHeight,\n left: tableElemRight - editorElemLeft + 5,\n top: tableElemY - editorElemY,\n width: BUTTON_WIDTH_PX,\n })\n }\n },\n 50,\n 250,\n )\n\n // Hide the buttons on any table dimensions change to prevent last row cells\n // overlap behind the 'Add Row' button when text entry changes cell height\n const tableResizeObserver = useMemo(() => {\n return new ResizeObserver(() => {\n setShownRow(false)\n setShownColumn(false)\n })\n }, [])\n\n useEffect(() => {\n if (!shouldListenMouseMove) {\n return\n }\n\n document.addEventListener('mousemove', debouncedOnMouseMove)\n\n return () => {\n setShownRow(false)\n setShownColumn(false)\n\n document.removeEventListener('mousemove', debouncedOnMouseMove)\n }\n }, [shouldListenMouseMove, debouncedOnMouseMove])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerMutationListener(\n TableNode,\n (mutations) => {\n editor.getEditorState().read(\n () => {\n let resetObserver = false\n for (const [key, type] of mutations) {\n switch (type) {\n case 'created': {\n tableSetRef.current.add(key)\n resetObserver = true\n break\n }\n case 'destroyed': {\n tableSetRef.current.delete(key)\n resetObserver = true\n break\n }\n default:\n break\n }\n }\n if (resetObserver) {\n // Reset resize observers\n tableResizeObserver.disconnect()\n for (const tableKey of tableSetRef.current) {\n const { tableElement } = $getTableAndElementByKey(tableKey)\n tableResizeObserver.observe(tableElement)\n }\n setShouldListenMouseMove(tableSetRef.current.size > 0)\n }\n },\n { editor },\n )\n },\n { skipInitialization: false },\n ),\n )\n }, [editor, tableResizeObserver])\n\n const insertAction = (insertRow: boolean) => {\n editor.update(() => {\n if (tableCellDOMNodeRef.current) {\n const maybeTableNode = $getNearestNodeFromDOMNode(tableCellDOMNodeRef.current)\n maybeTableNode?.selectEnd()\n if (insertRow) {\n $insertTableRowAtSelection()\n setShownRow(false)\n } else {\n $insertTableColumnAtSelection()\n setShownColumn(false)\n }\n }\n })\n }\n\n if (!isEditable) {\n return null\n }\n\n return (\n <>\n {isShownRow && (\n <button\n aria-label=\"Add Row\"\n className={editorConfig.editorConfig.lexical.theme.tableAddRows}\n onClick={() => insertAction(true)}\n style={{ ...position }}\n type=\"button\"\n />\n )}\n {isShownColumn && (\n <button\n aria-label=\"Add Column\"\n className={editorConfig.editorConfig.lexical.theme.tableAddColumns}\n onClick={() => insertAction(false)}\n style={{ ...position }}\n type=\"button\"\n />\n )}\n </>\n )\n}\n\nfunction getMouseInfo(\n event: MouseEvent,\n editorConfig: EditorConfig,\n): {\n isOutside: boolean\n tableDOMNode: HTMLElement | null\n} {\n const target = event.target\n\n if (isHTMLElement(target)) {\n const tableDOMNode = target.closest<HTMLElement>(\n `td.${editorConfig.theme.tableCell}, th.${editorConfig.theme.tableCell}`,\n )\n\n const isOutside = !(\n tableDOMNode ||\n target.closest<HTMLElement>(`button.${editorConfig.theme.tableAddRows}`) ||\n target.closest<HTMLElement>(`button.${editorConfig.theme.tableAddColumns}`) ||\n target.closest<HTMLElement>(`div.${editorConfig.theme.tableCellResizer}`)\n )\n\n return { isOutside, tableDOMNode }\n } else {\n return { isOutside: true, tableDOMNode: null }\n }\n}\n\nexport function TableHoverActionsPlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): null | React.ReactPortal {\n const isEditable = useLexicalEditable()\n\n if (!isEditable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AA,CAAauF,KAAK,CAACC,YAAY,EAAE,KACvEI,MAAA,CAAOC,OAAO,CAAc,UAAU7F,YAAA,CAAauF,KAAK,CAACI,eAAe,EAAE,KAC1EC,MAAA,CAAOC,OAAO,CAAc,OAAO7F,YAAA,CAAauF,KAAK,CAACQ,gBAAgB,EAAE;IAG1E,OAAO;MAAEjF,SAAA;MAAWC;IAAa;EACnC,OAAO;IACL,OAAO;MAAED,SAAA,EAAW;MAAMC,YAAA,EAAc;IAAK;EAC/C;AACF;AAEA,OAAO,SAAAiF,wBAAAC,EAAA;EAAA,MAAAC,CAAA,GAAA/H,EAAA;EAAiC;IAAA0B,UAAA,EAAAsG;EAAA,IAAAF,EAIvC;EAHC,MAAApG,UAAA,GAAAsG,EAA0B,KAAAC,SAAA,GAAAtC,QAAA,CAAAuC,IAAA,GAA1BF,EAA0B;EAI1B,MAAApG,UAAA,GAAmB1B,kBAAA;EAAA,KAEd0B,UAAA;IAAA;EAAA;EAAA,IAAAuG,EAAA;EAAA,IAAAJ,CAAA,QAAArG,UAAA;IAIEyG,EAAA,GAAA9G,YAAA,CAAa6F,IAAA,CAAAzF,0BAAA;MAAAC;IAAA,C,GAAwDA,UAAA;IAAAqG,CAAA,MAAArG,UAAA;IAAAqG,CAAA,MAAAI,EAAA;EAAA;IAAAA,EAAA,GAAAJ,CAAA;EAAA;EAAA,OAArEI,EAAqE;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.tsx"],"names":[],"mappings":"AA6BA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAqBvE,wBAAgB,UAAU,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,WAAW,CAAA;CAAE,GAAG,KAAK,CAAC,SAAS,CAmYvF"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
4
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
|
|
5
|
+
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
5
6
|
import { $findMatchingParent, mergeRegister } from '@lexical/utils';
|
|
6
7
|
import { getTranslation } from '@payloadcms/translations';
|
|
7
8
|
import { CloseMenuIcon, EditIcon, ExternalLinkIcon, formatDrawerSlug, useConfig, useEditDepth, useLocale, useTranslation } from '@payloadcms/ui';
|
|
@@ -35,6 +36,7 @@ export function LinkEditor({
|
|
|
35
36
|
},
|
|
36
37
|
uuid
|
|
37
38
|
} = useEditorConfigContext();
|
|
39
|
+
const isEditable = useLexicalEditable();
|
|
38
40
|
const {
|
|
39
41
|
config,
|
|
40
42
|
getEntityConfig
|
|
@@ -249,7 +251,7 @@ export function LinkEditor({
|
|
|
249
251
|
className: "link-input__label-pure",
|
|
250
252
|
children: linkLabel
|
|
251
253
|
})]
|
|
252
|
-
}) : null,
|
|
254
|
+
}) : null, isEditable && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
253
255
|
children: [/*#__PURE__*/_jsx("button", {
|
|
254
256
|
"aria-label": "Edit link",
|
|
255
257
|
className: "link-edit",
|