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

253 Commits

Author SHA1 Message Date
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
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
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
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
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
Ian Storm Taylor
9b0e061bcf fix normalize docs 2018-08-01 15:53:17 -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
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
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
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
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
Guy Edwards
1385e5c837 Move data desc below data (#1900) 2018-06-14 18:17:15 -07:00
David Chang
844a4c0221 [docs] add Change.normalize into the docs, add some caveats about perf (#1898) 2018-06-13 16:45:37 -07:00
David Chang
bcf41a96b4 Update docs (#1893) 2018-06-12 10:42:09 -07:00
Sunny Hirai
360c522a45 Update change.md to include setValue (#1670)
* Update change.md

* Update change.md

* Update change.md

* Update change.md

* Update change.md
2018-04-27 15:55:08 -07:00
DamareYoh
a943eada85 added documentation for wrapNodeByKey (#1774)
* added documentation for wrapNodeByKey

* remove extraneous newline

* fixed weird typo!
2018-04-15 17:40:55 +01:00
Nikolay Kazakov
d2eb362234 Fixed syntax mismatch at normalize method (#1737)
`switch` operator was wrapped around `case` statements
2018-03-28 09:15:12 -07:00
Gabin Aureche
29901f0888 Add missing documentation for rule.marks (#1717) 2018-03-22 14:17:00 -07:00
Andrew Fleming
6678245fba Fix broken link in schema.md (#1684)
Correct broken link to `slate-schema-violations`
2018-03-03 19:01:40 -05:00
Zach Schneider
c5f0626a05 Convert setBlock and setInline to plurals for more intuitive naming. (#1558) 2018-02-21 18:03:30 -08:00
Renaud Chaput
de4c9e478a Lint JSON, CSS and Markdown files with Prettier (#1612)
* Process and Lint CSS, Markdown and JSON files with Prettier

* Run `yarn prettier` to re-format Markdown, CSS and JSON files
2018-02-07 07:58:41 -08:00
DamareYoh
eda5c02e79 Bugfix/undo merge node (#1594)
* fixed build for windows

* fixed issue where undo of merge node does not restore the node back to its original properties

* fixed lint issue

* updated operation docs for additional property on split_node and merge_node

* finished incomplete sentence in the docs.

* updated test to also verify data is restored

* renamed the 'original' property to 'properties' to be more consistent with similar operation interfaces, updated docs

* got rid of extra operations property.

* deserializing properties in merge_node and split_node, passing properties object in splitNodeByKey

* missed committing operations modles.

* updated operations.toJSON for new properties on merge_node and split_node

* fix linting error

* remove outdated comment.

* expanded check for split node inverse to include inline nodes

* partially revert update to test with deletion across inlines
2018-02-05 10:16:55 -08:00
Andreas Mischke
0ef7b116f1 Fix broken "Characters" link (#1586)
Link was pointing to `./mark.md`, now points to `./character.md`
2018-02-01 09:33:49 -05:00
Ian Storm Taylor
10eea06a8a refactor schema violations to be a separate package 2018-01-26 12:28:40 -08:00
CameronAckermanSEL
ef5106e30f Improve normalize suppression to make less verbose and safer (#1549)
* change normalization can be set with setOperationFlag, and changes can be executed in sequence with automatic suppression with guaranteed document normalization at the end.

* responded to developer feedback by renaming execute to withMutations (to mirror immutable JS), implemented tests, updated documentation

* fixed typos discovered in review.

* fixed missing normalize flag usages and added withMutations to the schemas guide

* responded to developer feedback

* fixed lint errors and cleaned up code

* readd missing tests

* getFlag now allows options to override the change flags

* removed normalize restoration asserts from unit tests

* unit test cleanup
2018-01-26 11:32:37 -08:00
DamareYoh
7d5a33025b added export constant enum for schema violations (#1532)
* added export constant enum for schema violations

* updated examples to use the schema violations enum

* use SchemaViolations enum in tests and docs

* fixed path for schema violations import
2018-01-17 10:24:28 -05:00
Jinxuan Zhu
e6c7934cb9 Document: add change.snapshotSelection in the change.md (#1534)
* docs: add chang.snapshotSelection

* Minor style tweaks
2018-01-17 00:05:29 -05:00
Conor Cussell
62ffb4681b Remove parse5 (#1531)
Fix stripUnwantedAttrs

Remove .only

Remove parse5 from deps

Better imports

Cleanup

More succint removal of attributes
2018-01-13 15:41:48 -08:00
David Hrdlicka
6f1fd08fcd Expose core plugins (#1524) 2018-01-11 12:01:03 -08:00
Ian Storm Taylor
5444a300b8
rename kind to object for clarity (#1501)
* rename `kind` to `object` for clarity

* add deprecation warning for direct access

* add deprecation warning for node creation
2018-01-04 15:26:53 -08:00
Ryan
7dc93dced9 Docs: Fix method capitalization on resetKeyGenerator (#1474) 2017-12-29 10:43:02 -08:00
Justin Weiss
082fb53633 Add a copyFragment helper for plugin onCut/onCopy functions (#1429)
* Add a `copyFragment` helper for plugin onCut/onCopy functions

* Rename `copyFragment` to `cloneFragment`

* Fix a missing clone-fragment reference
2017-12-11 06:56:38 -08:00
Justin Weiss
1ae4471692 Document the position field of merge_node (#1440)
`merge_node` has a `position` field, which is exactly what I needed in order to transform some operations. It should be documented.
2017-12-02 12:30:05 -08:00
Ian Storm Taylor
98ed83c23b
Add schema first/last definitions (#1360)
* add `first` and `last` validations to schema

* update docs

* update schema usage in images example

* fix forced-layout example
2017-10-31 21:11:05 -07:00
Ryan
49ebbf9595 update doc's text node key ranges -> leaves (#1343) 2017-10-30 09:06:50 -07:00
Ian Storm Taylor
e991d5d480 update kind property in docs 2017-10-28 16:27:13 -07:00
Ian Storm Taylor
56a1f69a2f update docs 2017-10-27 14:50:27 -07:00
Ian Storm Taylor
adb2678732
Rename "state" to "value" everywhere (#1313)
* rename state to value in slate core, as deprecation

* rename all references to state to value in slate core

* migrate slate-base64-serializer

* migrate slate-html-serializer

* migrate slate-hyperscript

* migrate slate-plain-serializer

* migrate slate-prop-types

* migrate slate-simulator

* fix change.setState compat

* deprecate references to state in slate-react

* remove all references to state in slate-react

* remove `value` and `schema` from props to all components

* fix default renderPlaceholder

* fix tests

* update examples

* update walkthroughs

* update guides

* update reference
2017-10-27 13:39:06 -07:00