Giter Club home page Giter Club logo

slate-plugins's Introduction

ConvertKit Slate Plugins - obsoleted

Please note that due to underlying changes to the SlateJS editor, this repo may have incompatibilities with the current Slate API. There are no plans to update these to the current version.

A collection of plugins for SlateJS, a customizable framework for building rich text editors.

Plugins

Adds code block editing behaviors to a SlateJS editor.

A convenient way to handle keyboard events in a SlateJS editor.

Adds list editing behaviors to a SlateJS editor.

Other

A library for testing SlateJS editors.

Documentation

Documentation is built using Docz and can be found at https://convertkit-slate-plugins.netlify.com/.

Development

To run Docz locally:

yarn
yarn bootstrap
yarn start

slate-plugins's People

Contributors

brendancarney avatar danielhara avatar gabri3l avatar noelherrick avatar pacoyang avatar pkeuter 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

Watchers

 avatar  avatar  avatar  avatar  avatar

slate-plugins's Issues

slate-lists: TypeError when calling decreaseListItemDepth on a non-list block

TypeError: Cannot read property 'key' of null
./packages/slate-lists/src/commands/decrease-list-item-depth.js:8:49
   5 | 
   6 | const listItem = document.getParent(startBlock.key);
   7 | const list = document.getParent(listItem.key);
>  8 | const parentListItem = document.getParent(list.key);
   9 | if (parentListItem.type != blocks.list_item) return;
  10 | const parentList = document.getParent(parentListItem.key);
  11 | 

Not sure if we should be checking for whether the block is a list item in the event handler, or if that's something that we should guard against behind the scenes.

Perhaps this involves disabling indent/outdent buttons when on a non-list block in the example. #25 could help with this?

slate-code and syntax highlighting

I'm following the example for slate-code but no highlighting occurs, and the following warnings are reported in the console:

As of [email protected], the `leaves` property of Text nodes has been removed. Instead, each text node contains a string of text and a unique set of marks and leaves are unnecessary.
As of [email protected] the `decoration.mark` property has been changed to `decoration.type` and `decoration.data` directly. 

Can't find anything in the docs restricting the plugin to a specific version of Slate, or am I missing something? I guess the API for Slate is still subject to sudden changes.

wrapList / toggleList eliminates nodes it shouldn't?

If the container of the list is inside another block node, the behavior of wrapList seems incorrect. If, for example, your schema looks like section -> paragraph -> unordered-list. Calling wrapList when the cursor is in the paragraph will eliminate the entire section node.

Content disappear with existing list

Version: "^0.2.5"
We have recently adopted this lib for our editor. Here is the sample code that we have previously generated using default list

<ul><li><span><strong>A: </strong></span><span>content A</span></li><li><span><strong>B: </strong></span><span>content B</span></li><li><span><strong>C: </strong></span><span>Content C</span></li><li><span><strong>D: </strong></span><span>Content D</span></li></ul>

After the rendering with this plugin, some of the content were lost, the html becomes

<ul class="unordered-list" data-key="25"><li class="list-item" data-key="26"><div class="list-item-child" data-key="69"><span data-key="27"><span data-slate-leaf="true" data-offset-key="27:0"><span><strong><span data-slate-content="true">A: </span></strong></span></span></span></div></li><li class="list-item" data-key="29"><div class="list-item-child" data-key="68"><span data-key="30"><span data-slate-leaf="true" data-offset-key="30:0"><span><strong><span data-slate-content="true">B: </span></strong></span></span></span></div></li><li class="list-item" data-key="32"><div class="list-item-child" data-key="67"><span data-key="33"><span data-slate-leaf="true" data-offset-key="33:0"><span><strong><span data-slate-content="true">C: </span></strong></span></span></span></div></li><li class="list-item" data-key="35"><div class="list-item-child" data-key="66"><span data-key="36"><span data-slate-leaf="true" data-offset-key="36:0"><span><strong><span data-slate-content="true">D: </span></strong></span></span></span></div></li></ul>

All the Contents span are gone as show in screenshot:
Screen_Shot_2020-01-10_at_3_28_32_PM

If we add a div to each li element, it seems to be working. Below is an example:

<ul><li><div><span><strong>A: </strong></span><span>Content A</span></div></li><li><div><span><strong>B: </strong></span><span>Content B</span></div></li><li><div><span><strong>C: </strong></span><span>Content C</span></div></li><li><div><span><strong>D: </strong></span><span>Content D</span></div></li></ul>

Blockquotes: Example crashes

The example of blockquotes crashes after placing the cursor at the end of the only quote, and pressing enter:

Peek 2019-10-28 00-37

This seems to happen while the loading of the page is not yet complete.

I'm running Chrome 78.0.3904.70 in Ubuntu 18.04

Export some utils for the slate list package

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 :)

Shift + Enter inside list item

Not sure if bug or not, i.e if we or this plugin should prevent Shift+Enter event..

If caret is in list-item-child which is not empty and you press Shift+Enter, new list-item-child with zero-width element is created and appended to same line and you need to press Shift+Enter again to make another list-item-child which finally appreas on next line.

I've found at least 3 bugs (and would probably find more) related to Shift+Enter and list-item-child which leads me to belive that Shift+Enter and multi-line list items are not intended features..

I tried the demo in documentation.

Awesome plugins by the way! I might use the list one if this issue gets resolved.

List item deleted when changing depth

How to reproduce:

  • Go to list docs
  • Drop caret into either Subitem 2 or Item 2
  • If Item 2, increasing depth deletes the item
  • If Subitem 2, decrease depth and if then increased, item gets deleted

It also seems that if you repeat Subitem 2 steps for middle list item in a sub-list that has more than 2 items, all list items after that one get deleted after depth increase. Don't remember seeing this bug before.

Ubuntu, Chromium (can't test it on other platforms at the moment)

Deserialization results in broken plugin functionality

When deserializing some html so that it can be used with a slatejs editor inner list-items are lost. Using the following sample html:

<ol>
  <li>
    one
    <ol>
      <li>
         two
      </li>
    </ol>
  </li>
</ol>

Here, the ordered list within the list-item containing "one" will be lost as this seems to be part of the slate architecture.

Looking at the above sample code, wrapping the "one" in a div (as part of the deserialization process) will preserve the inner ordered list, but now the list slate-list-plugin will not work as intended - the plugin will not allow you to add or remove new list-items and does not seem to recognize the structure as a list because the inner list-item "two" will now also be wrapped in a div.

When loading some Value like the following into the editor, however, everything works as intended and the above issue is not encountered (like in the example):

{"object":"value","document":{"object":"document","data":{},"nodes":[{"object":"block","type":"ordered-list","data":{},"nodes":[{"object":"block","type":"list-item","data":{},"nodes":[{"object":"block","type":"list-item-child","data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"one","marks":[]}]}]},{"object":"block","type":"ordered-list","data":{},"nodes":[{"object":"block","type":"list-item","data":{},"nodes":[{"object":"block","type":"list-item-child","data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"two","marks":[]}]}]}]}]}]}]}]}}

Was looking through the codebase for a sample deserialization method but could not find one, but this seems to be an issue with deserialization.

Replace JSX with tagged template literals

This provides a few benefits:

  • Can use React and convenient slate values in the same file
  • No transpilation required to create a slate value
  • Users don't need to use slate-hyperscript directly

Here's a potential API. The naming will almost surely change as I don't like it right now.

const structure = {
  blocks: {
    paragraph: "paragraph"
  },
  marks: {
    bold: "bold"
  }
}  

const { editor, html } = SlateTest({ plugins: Code() }, { structure });

const value = html`
  <paragraph>
    Some sample <bold>text</bold>
  </paragraph>
`

A few open questions:

  • Should this be completely outside of the SlateTest function? In other words, should it be a separate import?
  • The html name could be confusing, but it does automatically get you syntax highlighting depending on your editor setup.

Add line count

I was wondering if you wanted to add line count as well. I did on my project and thought it was worth asking if it's a feature you would want. If so I can send a PR for it, it's pretty small to be honest. Let me know!

Missing schema normalizations in slate-lists

I think there might be some missing normalization rules for slate-lists, but haven't had the time to dig into all of it yet. I know at the very least that by highlighting list items and dragging around, I can get my editor into weird states where list-item-child blocks don't have child text nodes.

Screenshot from 2019-05-09 10-05-45
Screenshot from 2019-05-09 10-06-25

Not sure what others are missing/leading to three bullets showing on the same line. A little gif tinkering with the documentation example for a couple seconds. The flash to white at the end is actually the page crashing with the exception below.

Peek 2019-05-09 10-10
Screenshot from 2019-05-09 10-11-49

Delete behavior is off

By current I mean the list item where caret is located when Delete is pressed.

I should also note that depth doesn't play any role with Delete, next or previous list items are literally visually next and previous, even if different depth (I don't have a problem with that).

Good cases:

  • If current and next item have content, next item is deleted and its content is appended to current's
  • If current has content and next is empty, next list item is just deleted
  • If current is last item in list and has content, nothing happens after Delete

Bad cases:
Why bad? I personally don't care about Delete functionality at all but it would be nice if it worked properly if it's already there. From list documentation:

Delete or Backspace at the start of an item: remove the item

  • If two empty list items are next to each other, pressing Delete moves caret to other empty item, this behavior repeats if Delete is pressed again, nothing gets removed
  • If current is last and empty item in list, caret is moved to previous list item, last empty item only gets removed when Delete is pressed again (when caret is in previous item)
  • If current is first and empty item in list, caret is moved off the list (previous block) and I get two list bullets side-by-side situation, few frames later, I get the following error:

err

These descriptions might get pretty cryptic, my apologies.

Support for v0.5?

Is there going to be an upgrade to slate v0.5? Really hoping so. Cheers

lists: Add query for being inside list

This is useful for e.g. button bars
Not sure what to call it, isList, hasList, inList?

	queries: {
		isList: editor => !!getListItem(editor, editor.value.startBlock)
	}

getListItem will then need a guard for undefined block

Add example on docs on Activating code blocks

Hey @brendancarney thanks for this plugin! I'm fairly new to Slate and I was having a hard time understanding how to enable a block of code. I am having fun with Slate creating useful shortcuts, maybe it could be a good idea to expand the docs to instruct different ways of enabling code blocks when typing. Maybe that will be a simpler example than having a context menu. Once I have something working I might just send a PR your way if that's ok!

I mean after you get around how things come together in Slate it feels pretty straightforward, but an example with actual code wouldn't hurt.

List structure lost after copy-pasting

After copy-pasting, sometimes the list structure is lost, and pressing Enter does not start a new list item bullet:
I suspect this is because copy-pasting introduces paragraphs, which are not dealt with in the normalization of slate-lists.

Peek 2020-01-06 15-01

Expected behavior:

Should strip all paragraphs insidelist-item-child elements, so that the list structure behaviour is not affected.

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.