Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): expose onMount to CodeField #10223

Merged
merged 1 commit into from
Dec 28, 2024
Merged

feat(ui): expose onMount to CodeField #10223

merged 1 commit into from
Dec 28, 2024

Conversation

AlessioGr
Copy link
Member

This is useful for modifying the monaco instance, e.g. to add external types to the editor:

<CodeField
        autoComplete={autoComplete}
        field={props}
        forceRender={forceRender}
        key={key}
        onMount={(editor, monaco) => {
          console.log('editor mounted')
          monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
            allowNonTsExtensions: true,
            moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
            paths: {
              payload: ['file:///node_modules/payload/index.d.ts'],
            },
            target: monaco.languages.typescript.ScriptTarget.ESNext,
            typeRoots: ['node_modules/@types', 'node_modules/payload'],
          })
          const run = async () => {
            const types = await fetch('https://unpkg.com/payload@latest/dist/index.d.ts')
            const typesText = await types.text()
            monaco.languages.typescript.typescriptDefaults.addExtraLib(
              typesText,
              'file:///node_modules/payload/index.d.ts',
            )
          }
          void run()
        }}
        path={path}
        permissions={permissions}
        readOnly={readOnly}
        renderedBlocks={renderedBlocks}
        schemaPath={schemaPath}
        validate={validate}
      />

@AlessioGr AlessioGr changed the title feat: expose onMount to CodeField feat(ui): expose onMount to CodeField Dec 28, 2024
@AlessioGr AlessioGr enabled auto-merge (squash) December 28, 2024 07:55
@AlessioGr AlessioGr merged commit 68a5f5c into main Dec 28, 2024
74 checks passed
@AlessioGr AlessioGr deleted the feat/expose-onMount branch December 28, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant