facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
20.01k stars 1.71k forks source link

Feature: support set list style type by insertList function #6327

Open milkrong opened 5 months ago

milkrong commented 5 months ago

I am woking on the List plugin. While I have to set the list style type by using theme. Is there any way to support user to change it? as we can set list style type in css

image
ElasticBottle commented 5 months ago

You can set this via the editor theme

import type { InitialConfigType } from "@lexical/react/LexicalComposer";

const themeClass: InitialConfigType["theme"] = {
    list: {
        ol: "list-decimal",
        ul: "list-disc",
    }
};

and then pass the themeClass into the initial Config of the LexicalComposer

milkrong commented 5 months ago

You can set this via the editor theme

import type { InitialConfigType } from "@lexical/react/LexicalComposer";

const themeClass: InitialConfigType["theme"] = {
  list: {
      ol: "list-decimal",
      ul: "list-disc",
  }
};

and then pass the themeClass into the initial Config of the LexicalComposer

@ElasticBottle No, it's not my expectation. I want to support set list-style-type by some selection component in toolbar, which user can change it while using my text-editor. Not just providing a preset in config file by devleoper

e.g

editor.update(() => {
        const selection = $getSelection();
        if (selection !== null) {
          lastSelection.current = selection;
          $patchStyleList(selection, {
            "list-style": `${value}  `,
          });
        } 
}
Kingscliq commented 1 month ago

Hi @milkrong has this been fixed?

etrepum commented 1 month ago

No, there are only three list types supported by the list node and no support for adding extra metadata. Like most use cases that lexical doesn't support directly, the solution is to subclass the node and use node replacement to add support for additional properties and classes.

Kingscliq commented 1 month ago

can I work on it @etrepum ?