Code Monkey home page Code Monkey logo

formfcw / directus-extension-flexible-editor Goto Github PK

View Code? Open in Web Editor NEW
96.0 3.0 11.0 30.18 MB

A Rich Text Editor (WYSIWYG) with JSON output, that allows to integrate M2A relations to make it extremely flexible. A truly rich editor for Directus.

License: GNU General Public License v3.0

Vue 31.01% TypeScript 68.41% JavaScript 0.25% HTML 0.33%
block-editor directus directus-custom-display directus-custom-interface directus-extension editor flexible-content flexible-editor json-editor node-editor

directus-extension-flexible-editor's Introduction

Flexible Editor for Directus

A Rich Text Editor (WYSIWYG) with JSON output, that allows to integrate M2A relations to make it extremely flexible.

flexible-editor.mp4

(Demo Video)

Under the hood, it integrates the Tiptap editor as an extension into the Directus app and utilizes an optional many-to-any (M2A) field to place and link relation nodes in the editor. This combination makes Flexible Editor a truely rich editor.

Installation

Basic Usage

In your Directus app simply click the Create Field button and choose Flexible Editor.

basic-usage.mp4

(Video about basic usage)

Interface Options

Navigate to the interface tab to adjust the settings.

Option Description
M2A Reference Field Described in detail below (Usage with relation nodes)
Placeholder Display a placeholder text when empty
Tools Select the editor tools you want to use
Formats Button Appearance Display the active format name instead of just an icon
Input Mode Multi-line text … Default behavior
Single-line text … Turns into an inline editor that only allows inline marks/blocks
Editor Height Grow till Overflow … The height grows with its content as long as it remains in the viewport
Grow … The height grows with its content
Fixed … The editor has a fixed height
Font Font that is used in the editor
Spellcheck Enable spell checking in the editor

Display

Navigate to the Display tab and select Flexible Editor to display the editor content as plain text inside the Directus app.

Usage with relation nodes

You can insert items from your Directus collections into the Flexible Editor. This is optional but gives you extreme flexibility when creating rich content. Therefore, you need to add a many-to-any (M2A) field, the editor field can connect to. For Flexible Editor to work this way, you must create the junction collection before adding a M2A field.

usage-with-relation-nodes.mp4

(Video about usage with relation nodes)

  1. Create a new (junction) collection and give it a name like xxxx_editor_nodes and set the Type of the Primary Key to Generate UUID. Finish the setup to create the collection.

  2. Open the data model of the collection you want to add Flexible Editor to and click Create Field in Advanced Mode and select Many to Any Relationship.

  3. Give the field a name like editor_nodes and on the Relationship tab, uncheck the Auto Fill option, so you can select the junction collection you created earlier manually (like xxxx_editor_nodes). Select the Related Collections you want to integrate into your Flexible Editor field. You don’t need to set a sort field, but you want to set the Relational Triggers to cascade when deleting or deselecting an item.

  4. On the Field tab, set the field Hidden on Detail as we manage the M2A items via Flexible Editor. Therefore no interface is required for the M2A field.

  5. Now that you have created your M2A field, open the interface settings for your Flexible Editor field and connect to the M2A field by selecting it in the M2A Reference Field.

  6. Set the Item Duplication Fields for your junction collection (xxxx_editor_nodes) in the data model settings. This is required to make copy & paste or drag & drop work.

    Tip: If you setup Flexible Editor the same way on different collections, you can copy & paste the duplication settings via Copy Raw Value from the field menu — by clicking the “Item Duplication Fields” label.

Things to keep in mind

You cannot use the same M2A junction collection for multiple collections (in which you use Flexible Editor). This would only work with an any-to-any relationship, which Directus doesn't support at the time of writing.

You should not set Item Duplication Fields for nested Flexible Editor fields as they are managed by their own junction collections.

If you want to duplicate nested M2A items (e.g. a Related Content collection, that relates to multiple other collection items) you only want to duplicate the IDs (in the junction collection) without copying the whole item!

Duplication currently only works within the same editor field or between Flexible Editor fields, that use the same M2A Reference Field. (This will be improved in future releases.)

This also means that you can use the same M2A Reference Field for multiple Flexible Editor fields, although this is not recommended as this will change in future releases.

The current implementation of duplicating relation nodes (M2A items) does not cover all use cases, but will be improved in future releases. If duplication fails you should get a warning.

Tutorial: Relation node with existing items

selecting-related-items.mp4

(Video tutorial about relation node with existing items)

Custom Editor Styles

For overwriting CSS of the editor content, you can add Custom CSS to your Project Settings inside Directus. You can use the .flexible-editor class for the editor itself as well as a .relation-block class for the relation nodes.

Rendering in the front-end

To render the JSON content generated by Flexible Editor you can follow the official Tiptap guide or you can use the Flexible Editor Content tools included in this package (recommended).

Rendering with interactive components

If you want to render your JSON content with interactive components, especially when using relation nodes, follow this Flexible Editor Content guide.

Rendering plain HTML or plain text

Tiptap provides official functions to generateText() or generateHTML() from the JSON output. Note that as of this writing, there are different versions of generateHTML(): one for client side (import { generateHTML } from "@tiptap/core") and one for server side (import { generateHTML } from "@tiptap/html") rendering!

Contribution

Contributions are welcome. Make sure to open an issue for bugs or start a discussion for feature requests, before you start writing code!

directus-extension-flexible-editor's People

Contributors

codysaylor avatar formfcw avatar madc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

directus-extension-flexible-editor's Issues

Flexible editor display template not visible

Describe the bug
I am using the flexible editor field as the display template for one of my models. The flexible editor field is set to "flexible editor" for the display template, which says "display the content of Flexible Editor as plain text." In some places this is resulting in no value being visible. For example, when this model is added as a relational node in the flexible editor, no text is appearing. On inspecting the interface div, I've found that it is a block element and is rendering outside of the bounds of the container div - setting the interface div to "display: inline" is resolving the issue - for now I've added CSS to my project settings.

flexible-editor-display-template.mov

In the video I used a specific css selector for this example, but in my project I've added a less specific selector and have not come across any issues yet
[interface="flexible-editor-interface"] { display: inline }

To Reproduce

  1. Add a flexible editor to a model.
  2. Set up a relational node that contains a flexible editor field.
  3. Set the display template of the flexible editor field to "flexible editor".
  4. Set the display template of the model to your flexible editor field.
  5. Add the relational node to the flexible editor from step 1.
  6. Create/edit an item in the model from step 1. Insert the relational node making sure to populate the flexible editor field.
  7. Your relational node will show the name of the name of the node with no value.

Flexible Editor Version:
1.1.0

Directus Version:
10.1.1

Duplication not working for JSON fields

Describe the bug
Duplication not working for related collections that have JSON fields, as long as they are selected in the item duplication fields.

This should be solved with the planned rewrite: #11

Flexible Editor Version:
1.0.0

Directus Version:
10.4.3

No value in flexible editor when the item is opened in a drawer.

Describe the bug
When you open a related item and it opens in a drawer, the flexible editor fields are always empty, even when there should be content.

To Reproduce

  1. Add 2 fields to a content model: a Flexible Editor and a O2M relationship.
  2. Create an item and add content to the flexible editor. Save and create new.
  3. Creating your second item, add a relationship to the first item. Save and stay.
  4. Viewing your second item, click on the related item (your first item). The first item opens in a drawer, but there is no content in the flexible editor field.

Flexible Editor Version:
1.1.3

Directus Version:
10.6.1

Deleting an already existing block and then undoing the change shows ID: Value has to be unique

Describe the bug
When deleting a block that was already saved before inside the editor and then undoing the change, the error ID: Value has to be unique is shown. Probably, because it tries to create a new block instead of referencing the old one.

To Reproduce

  1. Create a block in the flexible editor, save the collection item.
  2. Open the collection item, delete the block and undo the change.
  3. Try to save

Flexible Editor Version:
[e.g. 1.1.7]

Directus Version:
[e.g. 10.8.3]

Duplicated relation blocks show empty M2A items in drawer

Describe the bug
When duplicating relation blocks that relate to M2A items, the items are empty if you open the drawer after duplication.
Use case: when duplicating related content block, then the related items are empty if you open the drawer.

Flexible Editor Version:
1.0.0

Directus Version:
10.4.3

dragging+dropping existing relation block with edits shows duplication warning

Describe the bug
When dragging+dropping an existing relation block with edits, the original will also get the duplication warning, if there is a duplication warning.

This is probably a tiptap issue.
This is probably the same bug as #16 and could be solved with this planned rewrite: #11

Flexible Editor Version:
1.0.0

Directus Version:
10.4.3

When creating a new block of the same type, it overwrites the latest block

Describe the bug
Creating a new block of type X will overwrite the last block in the editor, if this block is also of type X.
This only occurs if directly adding a new block, without first clicking inside the text editing area.

Video:

overwrite_bug.mp4

Flexible Editor Version:
[e.g. 1.4.0]

Directus Version:
[e.g. 10.10.5]

Can’t nest bullet list with ordered list easily

Describe the bug
Can’t nest bullet list with ordered list easily. Only works after the second element.

This is probably a tiptap issue.

Flexible Editor Version:
1.0.0

Directus Version:
10.4.3

No option to select existing items when adding blocks

Describe the bug
When adding a block using the Flexible Editor, it goes straight to the Creating X in Xs drawer and does not give me the option to select an existing item.

Screen.Recording.2023-07-24.at.13.25.43.mov

To Reproduce
Install flexible editor extension in a new project and follow the usage-with-relation-nodes.mp4 video to set it up.

Flexible Editor Version:
1.0.0

Directus Version:
10.4.3

Related nodes don't work when nested 2 groups deep

Describe the bug
Flexible editors only work up to 1 group deep. When you put a flexible editor field in a group within a group and add a relation node, it immediately gives the error that "the related item does not exist". The item is not created in the junction collection and the M2A reference field doesn't change.

To Reproduce
Steps to reproduce the behavior.

  1. Add 2 group fields to your collection and put one inside the other

  2. Add a flexible editor field to your collection, and put it inside both groups
    Screenshot 2023-09-29 at 09 52 09

  3. Set up at least one relation node for the flexible editor

  4. Create a new item in the collection

  5. Add a related item to the flexible editor field
    Immediately upon creating the related item, you'll see 'the related item does not exist'

Flexible Editor and Directus Versions:

  • 1.1.0 in 10.4.3 ❌
  • 1.1.5 in 10.6.1 ❌
  • 1.1.5 in 10.7.0-beta.0 ❌

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.