1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-01 13:18:29 +01:00

371 Commits

Author SHA1 Message Date
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
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
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
Kalley Powell
115cf469b9 Use <br /> inside empty block so those appear selected (#2300) 2018-10-25 09:41:43 -07:00
Ian Storm Taylor
29b762e9c2 Publish
- slate-base64-serializer@0.2.74
 - slate-html-serializer@0.7.13
 - slate-hyperscript@0.11.4
 - slate-plain-serializer@0.6.13
 - slate-prop-types@0.5.4
 - slate-react@0.19.6
 - slate@0.42.4
2018-10-24 16:09:16 -07:00
Ian Storm Taylor
bcc61a0bb2 Publish
- slate-hotkeys@0.2.7
 - slate-react@0.19.5
2018-10-24 14:52:39 -07:00
Kalley Powell
416590e1de Fix cloneFragment conditional handling of clipboardData.setData (#2298)
Seems the issue was introduced here: dc95ad66a5 (diff-dfb9fbad6106fa548b8335a644d03e49L109)

Remvoing the `return` ended  up calling `callback` twice instead of the intended once and both branches being followed
2018-10-24 14:41:06 -07:00
Ian Storm Taylor
ea6c4dcb08 Publish
- slate-base64-serializer@0.2.73
 - slate-hotkeys@0.2.6
 - slate-html-serializer@0.7.12
 - slate-hyperscript@0.11.3
 - slate-plain-serializer@0.6.12
 - slate-prop-types@0.5.3
 - slate-react@0.19.4
 - slate@0.42.3
2018-10-22 15:24:10 -07:00
Eric Edem
805c329e5d fix: use text utils to move forward and backward by word (#2169)
* fix: don't check for adjacent void with modified move

This was causing a problem where when the current text was followed by a void node using a modifier key to move forward would force the selection to creep forward a character at a time.

With this change, now the modifier will move as expected, but will jump over void nodes. This is not ideal, but seems like a behavior that will be slightly better than the current one.

* fix: modified key movement.

Use TextUtils.getWordOffsetForward and TextUtils.getWordOffsetBackward to move around by words.

The idea now is that if you move forward or backward, it is completely controlled by slate instead of trying to rely on a combination of browser behavior and slate trying to stop the browser from doing something wrong. This makes things quite a bit more intuitive in the implementation, and gives us a bit more control.

* tests: a whole bunch of selection movement tests.

* tests: more movement tests.
2018-10-22 11:21:20 -07:00
Ian Storm Taylor
d7123453c2 Publish
- slate-react@0.19.3
2018-10-10 09:52:54 -07:00
Ian Storm Taylor
6168ce932e fix editor resolution, remove constructor 2018-10-10 09:51:18 -07:00
Ian Storm Taylor
f939d168af Publish
- slate-base64-serializer@0.2.72
 - slate-html-serializer@0.7.11
 - slate-hyperscript@0.11.2
 - slate-plain-serializer@0.6.11
 - slate-prop-types@0.5.2
 - slate-react@0.19.2
 - slate@0.42.2
2018-10-09 18:46:54 -07:00
Ian Storm Taylor
3528bb7366 fix plugins stack ordering and defaulting 2018-10-09 18:43:47 -07:00
Ian Storm Taylor
7304c9b343 Publish
- slate-base64-serializer@0.2.71
 - slate-html-serializer@0.7.10
 - slate-hyperscript@0.11.1
 - slate-plain-serializer@0.6.10
 - slate-prop-types@0.5.1
 - slate-react@0.19.1
 - slate@0.42.1
2018-10-09 15:11:57 -07:00
Ian Storm Taylor
02c0f8e763 Publish
- slate-base64-serializer@0.2.70
 - slate-html-serializer@0.7.9
 - slate-hyperscript@0.11.0
 - slate-plain-serializer@0.6.9
 - slate-prop-types@0.5.0
 - slate-react@0.19.0
 - slate@0.42.0
2018-10-09 14:17:15 -07:00
Ian Storm Taylor
7a71de387c
Add controller (#2221)
* fold Stack into Editor

* switch Change objects to be tied to editors, not values

* introduce controller

* add the "commands" concept

* convert history into commands on `value.data`

* add the ability to not normalize on editor creation/setting

* convert schema to a mutable constructor

* add editor.command method

* convert plugin handlers to receive `next`

* switch commands to use the onCommand middleware

* add queries support, convert schema to queries

* split out browser plugin

* remove noop util

* fixes

* fixes

* start fixing tests, refactor hyperscript to be more literal

* fix slate-html-serializer tests

* fix schema tests with hyperscript

* fix text model tests with hyperscript

* fix more tests

* get all tests passing

* fix lint

* undo decorations example update

* update examples

* small changes to the api to make it nicer

* update docs

* update commands/queries plugin logic

* change normalizeNode and validateNode to be middleware

* fix decoration removal

* rename commands tests

* add useful errors to existing APIs

* update changelogs

* cleanup

* fixes

* update docs

* add editor docs
2018-10-09 14:03:27 -07:00
Ian Storm Taylor
e6372d829a Publish
- slate-base64-serializer@0.2.69
 - slate-html-serializer@0.7.8
 - slate-hyperscript@0.10.8
 - slate-plain-serializer@0.6.8
 - slate-prop-types@0.4.67
 - slate-react@0.18.11
 - slate-simulator@0.4.67
 - slate@0.41.3
2018-10-09 12:49:32 -07:00
Kaspars Dancis
b1ec914467 Replace "zero width whitspace" with "zero width no break" character (#2234)
This fixes https://github.com/ianstormtaylor/slate/issues/2231 where
a rogue empty line appears before an inline block.
2018-10-09 12:30:01 -07:00
Kaspars Dancis
1ff050265b Fix an occasional crash in Firefox in isInEditor (#2229)
* Fix an occasional crash in Firefox in isInEditor

* Update content.js
2018-10-05 14:25:32 -07:00
Ian Storm Taylor
aba8f19d0e Publish
- slate-base64-serializer@0.2.68
 - slate-html-serializer@0.7.7
 - slate-hyperscript@0.10.7
 - slate-plain-serializer@0.6.7
 - slate-prop-types@0.4.66
 - slate-react@0.18.10
 - slate-simulator@0.4.66
 - slate@0.41.2
2018-09-26 13:20:34 -07:00
Ian Storm Taylor
7b4eca5e16 Merge branch 'master' of github.com:ianstormtaylor/slate 2018-09-26 13:12:42 -07:00
Ian Storm Taylor
af8432f639 fix onClick when not finding a node 2018-09-26 13:12:35 -07:00
Grey Osten
329dac72d3 Normalize copying void inline nodes (#2198)
When a void inline nodes is selected along with other text/content it can be copied to the clipboard. When it’s the only thing selected it is ignored because anything marked contentedtiable=false is.
Updated isInEditor to return true if a contenteditable=false has a parent that is a void inline node.
2018-09-22 11:13:22 -07:00
Ian Storm Taylor
bf9b03e634 Publish
- slate-base64-serializer@0.2.67
 - slate-html-serializer@0.7.6
 - slate-hyperscript@0.10.6
 - slate-plain-serializer@0.6.6
 - slate-prop-types@0.4.65
 - slate-react@0.18.9
 - slate-simulator@0.4.65
 - slate@0.41.1
2018-09-21 15:09:49 -07:00
Ian Storm Taylor
ca6920a88f Publish
- slate-base64-serializer@0.2.66
 - slate-html-serializer@0.7.5
 - slate-hyperscript@0.10.5
 - slate-plain-serializer@0.6.5
 - slate-prop-types@0.4.64
 - slate-react@0.18.8
 - slate-simulator@0.4.64
 - slate@0.41.0
2018-09-21 11:19:48 -07:00
Ian Storm Taylor
c9cf16d019
refactor normalization to be operations-based (#2193)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Improvement.

#### What's the new behavior?

This changes the normalization logic to be operations (and `key`) based, instead of the current logic which is more haphazard, and which has bugs that lead to non-normalized documents in certain cases.

#### How does this change work?

Now, every time a change method is called, after it applies its operations, those operations will be normalized. Based on each operation we can know exactly which nodes are "dirty" and need to be re-validated.

This change also makes it easy for the `withoutNormalizing` (previously `withoutNormalization`) helper to be much more performant, and only normalize the "dirty" nodes instead of being forced to handle the entire document.

To accommodate this new behavior, the old "operation flags" have been removed, replaced with a set of more consistent helpers:

- `withoutNormalizing`
- `withoutSaving`
- `withoutMerging`

All of them take functions that will be run with the desired behavior in scope, similar to how Immutable.js's own `withMutations` works. Previously this was done with a more complex set of flags, which could be set and unset in a confusing number of different ways, and it was generally not very well thought out. Hopefully this cleans it up, and makes it more approachable for people.

We also automatically use the `withoutNormalizing` helper function for all of the changes that occur as part of schema `normalize` functions. Previously people had to use `{ normalize: false }` everywhere in those functions which was error-prone.

With this new architecture, you sure almost never need to think about normalization. Except for cases where you explicitly want to move through an interim state that is invalid according to Slate's default schema or your own custom schema. In which case you'd use `withoutNormalizing` to allow the invalid interim state to be moved through.

#### 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: #1363
Fixes: #2134
Fixes: #2135
Fixes: #2136
Fixes: #1579
Fixes: #2132
Fixes: #1657
2018-09-21 11:15:04 -07:00
Ian Storm Taylor
fd1832c73f Publish
- slate-base64-serializer@0.2.65
 - slate-hotkeys@0.2.5
 - slate-html-serializer@0.7.4
 - slate-hyperscript@0.10.4
 - slate-plain-serializer@0.6.4
 - slate-prop-types@0.4.63
 - slate-react@0.18.7
 - slate-simulator@0.4.63
 - slate@0.40.4
2018-09-21 09:43:39 -07:00
Ian Storm Taylor
fd87c746f8 fix versions... 2018-09-21 09:42:05 -07:00
Ian Storm Taylor
018ada8b88 fix selection.marks preservation from #2181 2018-09-18 10:08:33 -07:00
Nicolas Gaborit
4749cfc8b1 Actually fix marks being cleared on selection events (#2181)
* Fix marks being cleared on selection events

* Fix mistake
2018-09-18 09:49:18 -07:00
Bjørge Næss
3e7116dce1 Gracefully handle permission denied error when checking for element.nodeType (#2178) 2018-09-17 18:38:49 -07:00
Nicolas Gaborit
ea950ac1af Fix marks being cleared on selection events (#2158) 2018-09-17 18:33:01 -07:00
Per-Kristian Nordnes
f75a274c0e Fix deprecated .move > .moveForward in the after plugin (#2179) 2018-09-17 18:28:22 -07:00
Damien Erambert
222f746e85 Avoid crash in updateSelection() in content when window.getSelection() returns null (#2163) 2018-09-17 18:27:10 -07:00
Per-Kristian Nordnes
6340469266
Fix deprecated moveToStartOf and moveToEndOf (#2155)
In slate-react module (get-event-range)
2018-09-08 01:34:12 +02:00
Ian Storm Taylor
6369d0523a Publish
- slate-react@0.18.5
2018-09-04 12:00:41 -07:00
Eric Edem
3db717761e fix(content): attach the right onNativeSelectionChange. (#2150)
This undoes a recent change https://github.com/ianstormtaylor/slate/pull/2131

Which hooked up `this.handlers.onNativeSelectionChange` to `'selectionchange'` as well as `this.handlers.onBeforeInput` to `'beforeinput'`.

It turns out that in order to fix the iOS issues, we only needed the change to `onBeforeInput`. The corect handler for `'selectionchange'` is the instance method `this.onNativeSelectionChange`. This broke a whole bunch of focus related issues.
2018-09-04 10:36:48 -07:00
Ian Storm Taylor
54611b7dd7 Publish
- slate-react@0.18.4
2018-08-29 14:03:31 -07:00
Eric Edem
9d0546fad3 fix(content): use handlers that actually exist in event listeners (#2131)
* fix(content): use handlers that actually exist in event listeners

In a recent change, handlers now only exist in `Content#handlers`, but there were still a couple of places where they were being dereferenced directly from the instance. This was causing some side effects in iOS.

Fixes #2125
Fixes #2129

* fix(content): also fix removeEventListeners
2018-08-29 12:32:48 -07:00
Ian Storm Taylor
ba9b79112e Publish
- slate-base64-serializer@0.2.63
 - slate-html-serializer@0.7.2
 - slate-hyperscript@0.10.2
 - slate-plain-serializer@0.6.2
 - slate-prop-types@0.4.61
 - slate-react@0.18.3
 - slate-simulator@0.4.61
 - slate@0.40.2
2018-08-24 09:01:31 -07:00
Ian Storm Taylor
584ffec626 Publish
- slate-base64-serializer@0.2.62
 - slate-html-serializer@0.7.1
 - slate-hyperscript@0.10.1
 - slate-plain-serializer@0.6.1
 - slate-prop-types@0.4.60
 - slate-react@0.18.2
 - slate-simulator@0.4.60
 - slate@0.40.1
2018-08-23 13:54:58 -07:00
Ian Storm Taylor
8358d3777f Publish
- slate-react@0.18.1
2018-08-23 11:34:31 -07:00
Ian Storm Taylor
5d0f53da3f fix assertPathByKey, fixes #2119 2018-08-23 11:32:30 -07:00
Ian Storm Taylor
729727d91e Publish
- slate-base64-serializer@0.2.61
 - slate-dev-warning@0.0.1
 - slate-html-serializer@0.7.0
 - slate-hyperscript@0.10.0
 - slate-plain-serializer@0.6.0
 - slate-prop-types@0.4.59
 - slate-react@0.18.0
 - slate-simulator@0.4.59
 - slate@0.40.0
2018-08-22 18:31:50 -07:00
Ian Storm Taylor
36ed4397d8
Remove deprecations (#2113)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Debt.

#### What's the new behavior?

This removes almost all existing deprecations from previous API changes, to save on filesize and reduce complexity in the codebase going forward.

It also changes from using the `slate-dev-logger` to using the Facebook-inspired `slate-dev-warning` which can be compiled out of production builds with [`babel-plugin-dev-expression`](https://github.com/4Catalyzer/babel-plugin-dev-expression) to save even further on file size.

The only deprecations it keeps are in the `fromJSON` methods for data model changes like `.kind` and `.leaves` which may still may not have been migrated in databases, since this is a bigger pain point.

#### 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: #1922 
Fixes: #2105
Fixes: #646 
Fixes: #2109
Fixes: #2107 
Fixes: #2018
2018-08-22 18:22:40 -07:00
Ian Storm Taylor
3d48f7a3e0 Publish
- slate-base64-serializer@0.2.60
 - slate-html-serializer@0.6.32
 - slate-hyperscript@0.9.3
 - slate-plain-serializer@0.5.41
 - slate-prop-types@0.4.58
 - slate-react@0.17.3
 - slate-schema-violations@0.1.39
 - slate-simulator@0.4.58
 - slate@0.39.3
2018-08-22 15:43:19 -07:00