Kit / slate-plugins

A collection of plugins for SlateJS, maintained by ConvertKit
https://convertkit-slate-plugins.netlify.com/
MIT License
52 stars 22 forks source link

Export some utils for the slate list package #48

Open pradel opened 5 years ago

pradel commented 5 years ago

Hey! Thanks for this really cool plugin! Would you accept a pr to export these functions as utils from the list package?

  const isListItem = block => block && block.type == blocks.list_item;

  const getListItem = (editor, block) => {
    const possibleListItem = editor.value.document.getParent(block.key);

    return isListItem(possibleListItem) ? possibleListItem : null;
  };

  const isList = block =>
    block &&
    (block.type == blocks.unordered_list || block.type == blocks.ordered_list);

  const getList = (editor, block) => {
    const possibleList = editor.value.document.getParent(block.key);
    return isList(possibleList) ? possibleList : null;
  };

I need these utils in order to be able to show an active status in my editor :)

brendancarney commented 5 years ago

Thanks! So it will require that we know the arguments passed into the plugin, so we couldn't just export them as utils. We could potentially add some queries: https://docs.slatejs.org/guides/commands-and-queries#reusing-commands-and-queries.

I'm not sure they will be much more helpful than using your own, like:

const isListItem = block =>  block.type == 'list-item`;

Let me know if you have any ideas.

pradel commented 5 years ago

@brendancarney I didn't know about queries, looks like a pretty good usecase for it 👍 I ended up duplicated these utils but this means that I have to keep my utils updated if you do any breaking change on your side for example. If you are open to the queries idea I can submit a pr :)