Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

[Question/Feature] Change sublist type via options #77

Open
omar-sr88 opened this issue Aug 8, 2018 · 2 comments
Open

[Question/Feature] Change sublist type via options #77

omar-sr88 opened this issue Aug 8, 2018 · 2 comments
Labels

Comments

@omar-sr88
Copy link

I found no other way of communicating this, so hence the issue.

It is not clear to me if I can set what kind of nested list behavior I can have.

In my concrete example I want that all nested lists of Number list to be Bullet lists.

Setting Slate's schema does not seem to validate correctly out of the box.

@omar-sr88
Copy link
Author

omar-sr88 commented Aug 9, 2018

I wrote some code and could push this as a PR after discussion/refinements in case there is no other way around this. My approach was pretty simple:

1 - Create a new opt field:

export type OptionsFormat = {
    types?: string[],
    typeItem?: string,
    typeDefault?: string,
    canMerge?: (listA: Node, listB: Node) => boolean,
    nestedType?: { from: string, to: string }[]
};

One of those objects would be something like { from: 'ol_list' | 'ul_list', to: 'ol_list' | 'ul_list' }.

2 - onTab, test to see if nested list should be different or same as parent (on increaseItemDepth.js)

   let sublistType = currentList.type;
    if (opts.nestedType) {
        const parentType = opts.nestedType.find(
            node => node.from === currentList.type
        );
        sublistType = parentType ? parentType.to : sublistType;
    }`

    const newSublist = Block.create({
        object: 'block',
        type: sublistType,
        data: currentList.data
    });

@Soreine
Copy link
Contributor

Soreine commented Aug 19, 2018

@omar-sr88 I understand your use case.

Setting Slate's schema does not seem to validate correctly out of the box.

I think this should be the preferred way to solve this though. To extend your schema so that the type of any list under list items are normalized to bullet list

You should be able to do it without trouble through by writing a plugin with a plugin.schema.validateNode function for that.
If you would like to use the schema, then it can become quite ugly. You need to mutate the schema of your slate-edit-list plugin instance, and extend it in a way that preserve the plugin's logic, while also adding your logic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants