1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-01 05:16:10 +01:00

443 Commits

Author SHA1 Message Date
Dylan
ea3443eb42 Fix a typo (#2362) 2018-11-01 12:15:13 -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
Max Nesov
1032d14ffb Update change.md (#2310)
moveToRangeOf => moveToRangeOfDocument
2018-10-24 09:11:41 -07:00
kyrisu
f56f28a8fa Fixed KeyDown handler signature in code snippet (#2294)
The paragraph mentioned handle signature being `event, change, next` but the snippet had a signature with `event, change, editor`
2018-10-22 11:19:55 -07:00
Alan Christopher Thomas
175b25ae51 Fix docs on queries to show editor argument (#2285) 2018-10-20 00:05:53 -07:00
Pier Bover
0deb2e2695 Fixed link (#2270) 2018-10-16 11:35:14 -07:00
Dundercover
7192a97600 Add range comparison methods to Point (#2248)
* Rename compare function in path-utils to compareOfSameSize
To make way for a new function that makes a full comparison

* Add compare function to path-utils that handles paths of different sizes

* Add function isAfterRange to Point

* Add function isBeforeRange to Point

* Add function isAtStartOfRange to Point

* Add function isAtEndOfRange to Point

* Add function isInRange to Point

* Add range comparison methods to the documentation of the Point model

* Remove `compareOfSameSize` in `path-utils.js`
Using `compare` instead

* Add `Point.isBeforePoint`

* Add `Point.isAfterPoint`

* Use own methods internally for range comparisons in `Point`

* Return null if paths don't finally match in `compare` method of `path-utils`
To convey that it is not a normal scenario

* Add first test for `Point` model (testing `isAfterPoint`)

* Add tests for `Point.isAfterPoint`

* Add tests for `Point.isBeforePoint`

* Add tests for `Point.isAfterRange`

* Add tests for `Point.isBeforeRange`

* Add tests for `Point.isAtEndOfRange`

* Add tests for `Point.isAtStartOfRange`

* Add tests for `Point.isInRange`
2018-10-15 15:44:09 -07:00
Kashif
c0c0eb65f2 Add missing import (#2252) 2018-10-11 21:34:23 -07:00
Ian Storm Taylor
3528bb7366 fix plugins stack ordering and defaulting 2018-10-09 18:43:47 -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
Andrei Cacio
de9a07900e Fixed broken HTML serializer link (#2239) 2018-10-09 08:51:36 -07:00
Eric Edem
6dc8b4baa5 docs(plugins): update signature docs (#2057)
`onChange()` also receives the editor as an argument.
2018-09-27 23:37:01 -07:00
Eric Edem
f60100bd93 Update products to include Cake (#2207)
Now that Cake is coming out of invite only mode, figured it was a good time to add it. :)
2018-09-25 13:29:15 -07:00
Nick Quaranto
237dd8395f Update resources with Chatterslate (#2204)
Just a quick update here with a link to https://github.com/chatterbugapp/chatterslate !
2018-09-25 11:27:39 -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
Maulik
ebc72bf38f Updating function in readme.md (#2185)
Typo in function definition
2018-09-19 11:38:27 -07:00
Florian
dbf35f2565 Add info on how to use schema (#2156) 2018-09-17 18:26:18 -07:00
Alan Christopher Thomas
fa51558ede Remove stale docs for shouldNodeComponentUpdate (#2160) 2018-09-17 18:24:06 -07:00
Eric Edem
ebea68d0ac fix(change.md): correct setOperationFlag() signature (#2161) 2018-09-15 17:30:25 -07:00
Charley DAVID
405cef0225 Add support for validating functions inside schema's rules (#2151)
* Add specs, defaults, and documentation to next/previous rule properties

* Add comparator function support for kind/object, type, data, and mark
2018-09-04 13:14:20 -07:00
Fiyaz Bin Hasan
c87900b29e small typo and broken link for range doc fixed (#2120) 2018-08-23 13:43:24 -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
7e8ee5b0e8 add value deprecations 2018-08-21 20:37:08 -07:00
Ian Storm Taylor
00d5785226
deprecate isVoid and related properties/methods (#2102)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Improvement.

#### What's the new behavior?

This deprecates the `node.isVoid` property in favor of using `schema.isVoid(node)`, which will allow us to remove the hardcoded "void" concept from the data model, and have it depend on the schema instead. 

This allows you to build different kinds of editors, with different void semantics, depending on your use case, without having this information hardcoded in the data itself. Even switching the `isVoid` semantics on the fly based on a user toggling a setting for example.

#### How does this change work?

This is the first step, which just deprecates `node.isVoid`, and provides the new alternative of `schema.isVoid(node)`, while still using the `isVoid` value of nodes under the covers.

The next step is to change the logic to search the schema for real, and completely remove the `isVoid` value from nodes.

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

<!-- 
Please run through this checklist for your pull request: 
-->

* [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`.)
2018-08-21 15:52:44 -07:00
Ian Storm Taylor
be262b3c73 fix prettier 2018-08-15 18:00:24 -07:00
Ian Storm Taylor
3cf62ef394 add schema text validators to be functions 2018-08-15 17:58:02 -07:00
David Chang
f37dd21137 [hyperscript] rename decorators option in params to decorations (#2074)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Debt.

#### What's the new behavior?

`createHyperscript` takes an options object that now looks for the `decorations` property instead of the `decorators` property

#### How does this change work?

Pretty straightforward rename of an option, then all of its uses and wherever the term decorators showed up in docs

#### 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: #1996
Reviewers: @ianstormtaylor
2018-08-15 12:41:39 -07:00
Ian Storm Taylor
ffd9ead175 update changes docs, add missing selection changes 2018-08-06 11:46:42 -07:00
Zach Schneider
70d9e7951b Remove the deprecated Character model, and methods that reference it (#2016)
Closes #1999
2018-08-03 15:24:05 -07:00
Ian Storm Taylor
d2f6e06a66 update setters and docs 2018-08-03 15:08:20 -07:00
Ian Storm Taylor
08f270dc1b
Add a Point model, and standardize Range/Point logic (#2035)
* add `Node.createRange` for range resolution

* fix lint

* fix range offset defaults to be `null`

* change `isBackward` to be computed from paths

* remove debuggers

* add point model, update range with deprecations, update hyperscript

* got all tests passing

* get tests passing, convert changes

* fix lint

* fix examples

* update deprecations

* update docs

* update slate-react point utils

* fix document.normalizeRange

* fix lint
2018-08-03 14:45:40 -07:00
Florian
8a1d75025a Fix typo: "the your" -> "your" (#2032) 2018-08-03 11:39:38 -07:00
Ian Storm Taylor
9b0e061bcf fix normalize docs 2018-08-01 15:53:17 -07:00
Florian
f7fd0b7a4e Docs: Remove leading semicolon in code snippet (#2020)
* Remove leading semicolon in code snippet

* Update changes.md
2018-08-01 09:04:12 -07:00
Cheng Zheng
142d9a82f6 Add Products: Taskade (#2008)
* Add Products: Taskade

* Alphabet order

* remove empty line
2018-07-31 22:39:32 -07:00
Martti Laine
1ff1dfa4b8 Add slate-react to the bundled source guide (#2010) 2018-07-31 16:46:30 -07:00
Ian Storm Taylor
ded82812b0
Refactor schema (#1993)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Improvement.

#### What's the new behavior?

- Tweaking the declarative schema definition syntax to make it easier to represent more complex states, as well as enable it to validate previously impossible things.
- Rename `validateNode` to `normalizeNode` for clarity.
- Introduce `validateNode`, `checkNode`, `assertNode` helpers for more advanced use cases, like front-end API validation of "invalid" fields that need to be fixed before they are sent to the server.

#### How does this change work?

The `schema.blocks/inlines/document` entries are now a shorthand for a more powerful `schema.rules` syntax. For example, this now allows for declaratively validating by a node's data, regardless of type:

```js
{
  rules: [
    {
      match: {
        data: { id: '2kd293lry' },
      },
      nodes: [
        { match: { type: 'paragraph' }},
        { match: { type: 'image' }},
      ]
    }
  ]
}
```

Previously you'd have to use `validateNode` for this, since the syntax wasn't flexible enough to validate nodes without hard-coding their `type`.

This also simplifies the "concatenation" of schema rules, because under the covers all of them are implemented using the `schema.rules` array, so they simply take effect in order, just like everything else in plugins.

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

<!-- 
Please run through this checklist for your pull request: 
-->

* [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: #1842
Fixes: #1923
2018-07-27 15:27:07 -07:00
Ian Storm Taylor
01405be31b
add paths to ranges (#1997)
#### Is this adding or improving a _feature_ or fixing a _bug_?

Feature.

#### What's the new behavior?

This pull request adds paths to `Range` objects, including the selection. The paths and keys are kept in sync automatically, so that you can use whichever is ideal for your use case.

This should allow us to use paths for lots of the internal logic, which are much quicker to work with than keys since they avoid having to lookup the key in the document and can just traverse right to the node in question.

#### How does this change work?

`Range` objects have two new properties:

```js
range.anchorPath
range.focusPath
```

(Eventually these will be `range.anchor.path` and `range.focus.path` when points are introduced.)

When operations occur and whenever ranges are created/normalized, the paths are updated and kept in sync with the keys.

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

<!-- 
Please run through this checklist for your pull request: 
-->

* [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/1408
Fixes: https://github.com/ianstormtaylor/slate/issues/1567
2018-07-27 12:40:04 -07:00
Dylan Phelan
09c93a6cd4 Initial fixes for IE compat of cloneFragment (#1943)
* Initial fixes for IE compat of cloneFragment

* Used prettier to fix styling

* Removed solutions that can be polyfilled; added COMPAT comment

* Updated FAQ to reflect ideology towards IE

* Update faq.md

* Update faq.md

* Update faq.md
2018-07-19 12:53:38 -07:00
Wout Mertens
eab4361d92 plugins reference: update available properties (#1957) 2018-07-19 12:10:09 -07:00
Enzo Ferey
939787969b Improved slate-simulator docs. (#1972)
* Improved slate-simulator docs.

* Update index.md
2018-07-19 12:08:31 -07:00
Enzo Ferey
31ca817f18 Added onKeyUp event suppor to slate-simulator and updated docs. (#1973) 2018-07-19 12:00:32 -07:00
Enzo Ferey
39d50b39e5 Added slate-instante-replace plugin to docs and direct links to NPM and Yarn for slate plugins. (#1968) 2018-07-19 11:57:26 -07:00
Samy Pessé
0ceefea2e7 Add prop "isFocused" / "isSelected" for custom nodes (#1950)
* Change the definition of isSelected and add isFocused

* Document prop "isFocused"

* Add unit tests for isFocused / isSelected

* Adapt examples

* Lint
2018-07-03 16:07:38 -07:00
Ian Storm Taylor
37418643e2
add start of glossary (#1946)
This is the start of a glossary in the docs for terms that folks might not know when first learning Slate. Hopefully it makes it easier to learn. If anyone wants to help fill it out, that would be amazing. Thanks!
2018-07-02 10:27:35 -06:00
Enzo Ferey
a698d4a74e Added missing paste event handler. (#1942)
Acording to https://github.com/ianstormtaylor/slate/blob/master/packages/slate-simulator/src/index.js onPaste event is suported by slate-simulator.
2018-07-01 15:15:36 -06:00
Ian Storm Taylor
1923888af1
Update resources.md 2018-06-30 15:08:28 -07:00
Jan Vlcek
6518afc83e Update schema rule marks documentation (#1931) 2018-06-23 06:20:28 -07:00
David Chang
2652680850 [core/models] add replaceMark method on Change, tests, docs (#1910)
* [core/models/change] add replaceMark method on Change, tests, docs

* Update change.md
2018-06-21 19:46:40 -07:00
Rik
270321b5dc docs: call correct changes function (#1921) 2018-06-21 19:31:37 -07:00