drupal-visual-editor
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Drupal Visual Editor

Provide delightful editorial experiences for content editors within Drupal regardless of your FE implementation.

Usage with Remix

Adding your VisualEditorComponentContainer component

Create a file at app/components/helpers/VisualEditorComponentContainer.tsx and paste this content:

import type { VisualEditorComponentProps } from "drupal-visual-editor"
import { openVisualEditorComponent } from "drupal-visual-editor"

interface VisualEditorComponentContainerProps extends VisualEditorComponentProps {
  children?: React.ReactNode;
}

export default function VisualEditorComponentContainer(
  { action, storage, uuid, children }: VisualEditorComponentContainerProps
) {
  return (
    // eslint-disable-next-line
    <section
      id={`${storage}-${uuid}`}
      data-visual-editor-component={`${storage}-${uuid}`}
      onClick={() => openVisualEditorComponent({
        action,
        storage,
        uuid,
      })}
    >
      {children}
    </section>
  )
}

Using the new created React VisualEditorComponentContainer Component

At your component resolver file import the VisualEditorComponentContainer

import VisualEditorComponentContainer from "~/components/helpers/VisualEditorComponentContainer";

Wrap your component using the imported VisualEditorComponentContainer component

  // Wrap standard ParagraphComponent using VisualEditorComponentContainer wrapper
  if (environment === 'preview') {

    <VisualEditorComponentContainer
      action='edit'
      storage='paragraph'
      uuid={paragraph.id}
    >
      {ParagraphComponent}
    </VisualEditorComponentContainer>

  }

Addign styles to component container

Create a file at app/preview.css and paste this content:

[data-visual-editor-component]:hover {
  border-color: purple; border-style: dashed;
  border-width: thin;
  overflow: hidden;
  cursor: pointer;
}

Import your recently created app/preview.css file at app/root.tsx

import './preview.css'

For a fully functional example visit any of those repositories:

Supporting organizations

Development sponsored by Octahedroid

Package Sidebar

Install

npm i drupal-visual-editor

Weekly Downloads

6

Version

0.1.0

License

MIT

Unpacked Size

4.33 kB

Total Files

6

Last publish

Collaborators

  • jmolivas