1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 17:23:07 +01:00

819 Commits

Author SHA1 Message Date
Ian Storm Taylor
7a47a52e29 Publish
- slate-base64-serializer@0.2.85
 - slate-html-serializer@0.7.24
 - slate-hyperscript@0.11.15
 - slate-plain-serializer@0.6.24
 - slate-prop-types@0.5.15
 - slate-react-placeholder@0.1.3
 - slate-react@0.21.6
 - slate@0.44.0
2018-11-08 13:17:10 -08:00
Ian Storm Taylor
bd3399f362 update changelog 2018-11-08 13:14:11 -08:00
Krzysztof Mędrzycki
746b63db7e Improve schema validation for nodes and min/max (#2388)
* Better schema violations for underflow and overflow

* Rename child_required_under/overflow to child_min/max_invalid

* Remove tailing whitespace

* Add tests to cover more branches

* Insert missing comma
2018-11-08 13:05:59 -08:00
Dundercover
698edc24d8 Add node.getLeafXAtRange and node.getRootXAtRange (#2399)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Adding and improving

#### What's the new behavior?

Renames the following node methods (deprecating the old ones):

- `getBlocksAtRangeAsArray` -> `getLeafBlocksAtRangeAsArray`
- `getBlocksAtRange` -> `getLeafBlocksAtRange`
- `getInlinesAtRangeAsArray` -> `getLeafInlinesAtRangeAsArray`
- `getInlinesAtRange` -> `getLeafInlinesAtRange`

Adds the following nodes methods:

- `getRootBlocksAtRange`
- `getRootInlinesAtRange`

#### How does this change work?

Have not changed the implementation of the renamed methods. Added tests for both renamed methods and added methods.

#### Have you checked that...?

* [x] The new code matches the existing patterns and styles.
* [x] The tests pass with `yarn test`.
* [x] The linter passes with `yarn lint`. (Fix errors with `yarn prettier`.)
* [x] The relevant examples still work. (Run examples with `yarn watch`.)

#### Does this fix any issues or need any specific reviewers?

Discussed in #2351
2018-11-08 13:04:27 -08:00
Dundercover
e6d611d726 Add node.getNodesAtRange (#2398)
* Add `Node.getNodesAtRange`

* Add tests for `Node.getNodesAtRange`
2018-11-08 11:31:54 -08:00
Ian Storm Taylor
f2f97e502e Publish
- slate-react@0.21.5
2018-11-07 16:47:24 -08:00
Ian Storm Taylor
e493905f29
fix focusing across multiple editors (#2396) 2018-11-07 16:45:01 -08:00
Gersom van Ginkel
990d37b694 Avoid async commands causing rerenders after unmount. (#2395)
* When the component unmounts, make sure async commands don't trigger react updates.

* Eslint fix
2018-11-07 11:34:15 -08:00
Irwan Fario Subastian
8d616b1f98 fix softbreak at the end of the leaf (#2389) 2018-11-06 18:25:51 -08:00
Ian Storm Taylor
312a4ce1a5 Publish
- slate-react@0.21.4
2018-11-06 14:04:11 -08:00
Ian Storm Taylor
836ab1d494 fix findDOMPoint for non-empty void node offsets 2018-11-06 14:01:55 -08:00
Ian Storm Taylor
9446bcbf6d Publish
- slate-react@0.21.3
2018-11-06 13:53:36 -08:00
Ian Storm Taylor
07ecbc69c9 fix findDOMPoint for void nodes with content length 2018-11-06 13:51:52 -08:00
Ian Storm Taylor
60e897599f Publish
- slate-base64-serializer@0.2.84
 - slate-html-serializer@0.7.23
 - slate-hyperscript@0.11.14
 - slate-plain-serializer@0.6.23
 - slate-prop-types@0.5.14
 - slate-react-placeholder@0.1.2
 - slate-react@0.21.2
 - slate@0.43.7
2018-11-06 12:54:58 -08:00
Ian Storm Taylor
7079433ac1 fix findDOMPoint behavior for void nodes 2018-11-06 12:53:05 -08:00
Dundercover
b773d44ae9 Data property for Operation model (#2373)
* Add possibility to add arbitrary data to operations
Using a data property similar to the node models (block, inline, etc)

* Fix broken example 'Syncing Operations'
Using data property on operations that are applied
2018-11-04 21:02:05 -08:00
Dundercover
220dd476e3 Check if inline ancestor exists before using it in wrapInlineAtRange (#2374) 2018-11-04 20:58:45 -08:00
Ian Storm Taylor
24af6113dc Publish
- slate-react-placeholder@0.1.1
 - slate-react@0.21.1
2018-11-02 17:42:51 -07:00
Ian Storm Taylor
456d8f570f fix slate-react-* peerDependencies 2018-11-02 17:39:29 -07:00
Ian Storm Taylor
bb6d39edb6 Publish
- slate-base64-serializer@0.2.83
 - slate-html-serializer@0.7.22
 - slate-hyperscript@0.11.13
 - slate-plain-serializer@0.6.22
 - slate-prop-types@0.5.13
 - slate-react-placeholder@0.1.0
 - slate-react@0.21.0
 - slate@0.43.6
2018-11-02 17:07:12 -07:00
Ian Storm Taylor
a09c3c2fdf
Remove renderPlaceholder (#2370)
* add placeholder plugin in slate-react

* remove renderPlaceholder logic

* extract placeholder into a plugin

* remove other old placeholder-based logic

* update changelogs
2018-11-02 17:04:20 -07:00
Ian Storm Taylor
0cf94c73c9 Publish
- slate-base64-serializer@0.2.82
 - slate-html-serializer@0.7.21
 - slate-hyperscript@0.11.12
 - slate-plain-serializer@0.6.21
 - slate-prop-types@0.5.12
 - slate-react@0.20.8
 - slate@0.43.5
2018-11-02 16:18:24 -07:00
Ian Storm Taylor
8fce9b18c9 Merge branch 'master' of github.com:ianstormtaylor/slate 2018-11-02 16:14:20 -07:00
Ian Storm Taylor
f438f12d5b fix peer dependency ranges 2018-11-02 16:14:14 -07:00
Yevhen
08fae3f67c Fix typo in docs (#2369) 2018-11-02 08:17:34 -07:00
Ian Storm Taylor
562f7be4b6 Publish
- slate-react@0.20.7
2018-11-01 19:29:44 -07:00
Slapbox
0436ad4a64 Skip operations on child nodes if !node.nodes.size (#2365)
* Skip operations on child nodes if !node.nodes.size

Avoid running decoration and text decoration related functions on child nodes that don't exist.

* Uses isLeafBlock

* Restores the original order of statements
2018-11-01 18:26:46 -07:00
Ian Storm Taylor
fac8228f23 Publish
- slate-base64-serializer@0.2.81
 - slate-html-serializer@0.7.20
 - slate-hyperscript@0.11.11
 - slate-plain-serializer@0.6.20
 - slate-prop-types@0.5.11
 - slate-react@0.20.6
 - slate@0.43.4
2018-11-01 17:59:52 -07:00
Ian Storm Taylor
6e18719f3d
Fix delete intent (#2367)
* fix delete intent

* refactor deleteAtRange helper logic

* cleanup delete at range commands

* cleanup
2018-11-01 17:57:52 -07:00
Ian Storm Taylor
d5bb44383d Publish
- slate-base64-serializer@0.2.80
 - slate-html-serializer@0.7.19
 - slate-hyperscript@0.11.10
 - slate-plain-serializer@0.6.19
 - slate-prop-types@0.5.10
 - slate-react@0.20.5
 - slate@0.43.3
2018-10-31 14:33:50 -07:00
Slapbox
a8c08581a5 Checks for nodes in isLeafBlock & isLeafInline (#2357)
These functions now check for `nodes` before running `nodes.first()`
2018-10-31 14:15:38 -07:00
Ian Storm Taylor
317297469e Publish
- slate-base64-serializer@0.2.79
 - slate-html-serializer@0.7.18
 - slate-hyperscript@0.11.9
 - slate-plain-serializer@0.6.18
 - slate-prop-types@0.5.9
 - slate-react@0.20.4
 - slate@0.43.2
2018-10-31 10:26:11 -07:00
Ian Storm Taylor
02ba0591f8 fix insertFragment selection 2018-10-31 10:24:32 -07:00
Ian Storm Taylor
caedc1f108 Publish
- slate-base64-serializer@0.2.78
 - slate-html-serializer@0.7.17
 - slate-hyperscript@0.11.8
 - slate-plain-serializer@0.6.17
 - slate-prop-types@0.5.8
 - slate-react@0.20.3
 - slate@0.43.1
2018-10-31 10:11:00 -07:00
Ian Storm Taylor
c874637451 fix insert fragment selection with non-normalized fragment 2018-10-31 10:05:45 -07:00
Ian Storm Taylor
46df9f6c52 Publish
- slate-react@0.20.2
2018-10-29 17:35:31 -07:00
Ian Storm Taylor
4a2d7845ba rollback isInEditor check for void nodes 2018-10-29 17:30:24 -07:00
Ian Storm Taylor
8eb8e26958 Publish
- slate-react@0.20.1
2018-10-28 16:28:45 -07:00
Per-Kristian Nordnes
43812193ea Fix deprecated editor.change in after/onCut (#2343) 2018-10-28 12:18:53 -07:00
Ian Storm Taylor
8271cecc1e Publish
- slate-base64-serializer@0.2.77
 - slate-html-serializer@0.7.16
 - slate-hyperscript@0.11.7
 - slate-plain-serializer@0.6.16
 - slate-prop-types@0.5.7
 - slate-react@0.20.0
 - slate@0.43.0
2018-10-27 12:26:11 -07:00
Ian Storm Taylor
c86dfbd65b update changelogs 2018-10-27 12:24:35 -07:00
Ian Storm Taylor
8dd919dc34
remove change, fold into editor (#2337)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Improvement / debt.

#### What's the new behavior?

This pull request removes the `Change` object as we know it, and folds all of its behaviors into the new `Editor` controller instead, simplifying a lot of the confusion around what is a "change vs. editor" and when to use which. It makes the standard API a **lot** nicer to use I think.

---

###### NEW

**The `editor.command` and `editor.query` methods can take functions.** Previously they only accepted a `type` string and would look up the command or query by type. Now, they also accept a custom function. This is helpful for plugin authors, who want to accept a "command option", since it gives users more flexibility to write one-off commands or queries. For example a plugin could be passed either:

```js
Hotkey({
  hotkey: 'cmd+b',
  command: 'addBoldMark',
})
```

Or a custom command function:

```js
Hotkey({
  hotkey: 'cmd+b',
  command: editor => editor.addBoldMark().moveToEnd()
})
```

###### BREAKING

**The `Change` object has been removed.** The `Change` object as we know it previously has been removed, and all of its behaviors have been folded into the `Editor` controller. This includes the top-level commands and queries methods, as well as methods like `applyOperation` and `normalize`. _All places that used to receive `change` now receive `editor`, which is API equivalent._

**Changes are now flushed to `onChange` asynchronously.** Previously this was done synchronously, which resulted in some strange race conditions in React environments. Now they will always be flushed asynchronously, just like `setState`.

**The `render*` and `decorate*` middleware signatures have changed!** Previously the `render*` and `decorate*` middleware was passed `(props, next)`. However now, for consistency with the other middleware they are all passed `(props, editor, next)`. This way, all middleware always receive `editor` and `next` as their final two arguments.

**The `normalize*` and `validate*` middleware signatures have changed!** Previously the `normalize*` and `validate*` middleware was passed `(node, next)`. However now, for consistency with the other middleware they are all passed `(node, editor, next)`. This way, all middleware always receive `editor` and `next` as their final two arguments.

**The `editor.event` method has been removed.** Previously this is what you'd use when writing tests to simulate events being fired—which were slightly different to other running other middleware. With the simplification to the editor and to the newly-consistent middleware signatures, you can now use `editor.run` directly to simulate events:

```js
editor.run('onKeyDown', { key: 'Tab', ... })
```

###### DEPRECATED

**The `editor.change` method is deprecated.** With the removal of the `Change` object, there's no need anymore to create the small closures with `editor.change()`. Instead you can directly invoke commands on the editor in series, and all of the changes will be emitted asynchronously on the next tick.

```js
editor
  .insertText('word')
  .moveFocusForward(10)
  .addMark('bold')
```

**The `applyOperations` method is deprecated.** Instead you can loop a set of operations and apply each one using `applyOperation`. This is to reduce the number of methods exposed on the `Editor` to keep it simpler.

**The `change.call` method is deprecated.** Previously this was used to call a one-off function as a change method. Now this behavior is equivalent to calling `editor.command(fn)` instead.

---

Fixes: https://github.com/ianstormtaylor/slate/issues/2334
Fixes: https://github.com/ianstormtaylor/slate/issues/2282
2018-10-27 12:18:23 -07:00
Ian Storm Taylor
633fc9eebc Publish
- slate-base64-serializer@0.2.76
 - slate-html-serializer@0.7.15
 - slate-hyperscript@0.11.6
 - slate-plain-serializer@0.6.15
 - slate-prop-types@0.5.6
 - slate-react@0.19.8
 - slate@0.42.6
2018-10-25 18:49:32 -07:00
Ian Storm Taylor
a59e34cbfe allow setting selection properties on cursor in hyperscript, fixes #2326 2018-10-25 18:47:11 -07:00
Per-Kristian Nordnes
7c4c126cd9 When trying to move a node from a path to an equal path, ignore it (#2327) 2018-10-25 18:35:36 -07:00
Ian Storm Taylor
7f65eda65a Publish
- slate-base64-serializer@0.2.75
 - slate-html-serializer@0.7.14
 - slate-hyperscript@0.11.5
 - slate-plain-serializer@0.6.14
 - slate-prop-types@0.5.5
 - slate-react@0.19.7
 - slate@0.42.5
2018-10-25 12:40:50 -07:00
Per-Kristian Nordnes
125ea00245 Fix invalid transform path in move_node operation (#2324)
* Add failing deleteAtRange test

* Fix invalid move node path increment (fixes #2291)

* Add another three block delete all test without any void nodes

* Test the correct variables in transform path (move_node)
2018-10-25 12:36:53 -07:00
Stephen O'Brien
4e906b3be2 [proposal] Meld fragment into document in Commands.insertFragmentAtRange (#2273)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Fixing a bug. This is a proposed solution for https://github.com/ianstormtaylor/slate/issues/2064 (which also aims to maintain the existing _single nested block_ behavior added in https://github.com/ianstormtaylor/slate/pull/1366).

#### What's the new behavior?

Today, we always insert all nodes of the fragment at the range.

After this change, if the fragment is wrapped by/nested in blocks, and the nesting pattern already exists at the range, we meld the fragment contents into the document’s existing nesting pattern as much as possible.

Put another way, we can skip adding the fragment’s wrapping nodes if equivalent nodes already wrap the range.

Here’s a quick sketch that may better demonstrate the intention:
![image](https://user-images.githubusercontent.com/1694410/47054250-d6862480-d17e-11e8-89b8-337d7569389e.png)

Here, both the document and fragment wrap their content in two paragraphs. Therefore, we can add the fragment contents within the existing pair of nested paragraphs.

#### How does this change work?

A new function is added, `findInsertionNode`. Given a `fragment`, `document`, and `startKey`, it returns a node from the fragment to be inserted into the document. By default, the node returned will be the `fragment`, but if a common nesting pattern is detected, a sub-node of the fragment will be returned.

The detection algorithm is as follows:
1. Ensure the fragment has a single child node, call it `fragmentInner`
2. Find the furthest document ancestor of the `startKey` matching `fragmentInner.type`. Call this `documentInner`
3. Drill into both `documentInner` and `fragmentInner` as long as each has a single child node and their types match. The stopping point for the fragment is the sub-node to insert into the document.

`Commands.insertFragmentAtRange` remains mostly unchanged. One important modification is that the _single nested block_ (again, see https://github.com/ianstormtaylor/slate/pull/1366) only happens if the found insertion node is the fragment. For anything more inner, we meld.

#### Have you checked that...?

* [x] The new code matches the existing patterns and styles.
* [x] The tests pass with `yarn test`.
* [x] The linter passes with `yarn lint`. (Fix errors with `yarn prettier`.)
* [x] The relevant examples still work. (Run examples with `yarn watch`.)

#### Does this fix any issues or need any specific reviewers?

Fixes: https://github.com/ianstormtaylor/slate/issues/2064
2018-10-25 10:08:18 -07:00
Stephen O'Brien
9cdd6c9637 Alter cursor placement in insertFragment tests to reflect reality (#2271)
Previously, `start-inline` and `end-inline` included the cursor at the end of an inline, i.e.
```js
<paragraph>
  <link>example<cursor /></link>
</paragraph>
```

Using Slate in a browser, it doesn’t seem possible to me to actually achieve this state: i.e. whenever the cursor is on either side of an inline such as a link, typing will not add text to that inline. (This is consistent with other editors, for example Google Docs).

Now, these tests are updated to have a cursor just outside the inline. This leads to more sensible outputs.

(Finally, I removed a TODO comment indicating that `middle-inline-fragment-inline`’s cursor output was incorrect. I believe this is a sensible expectation, which matches behavior in editors including Google Docs.)

Fixes https://github.com/ianstormtaylor/slate/issues/1754
2018-10-25 09:57:50 -07:00
Kaspars Dancis
d5834bb5b0 Prevent crash when handling composition of 2+ keypresses when selection is not collapsed (#2218)
https://github.com/ianstormtaylor/slate/issues/1879
When composition starts and the current selection is not collapsed, the
second composition key-down would drop the text wrapping <spans> which
resulted on crash in content.updateSelection after composition ends
(because it cannot find <span> nodes in DOM). This is a workaround that
erases selection as soon as composition starts and preventing <spans>
to be dropped.
2018-10-25 09:47:29 -07:00