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

73 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
Florian
dbf35f2565 Add info on how to use schema (#2156) 2018-09-17 18:26:18 -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
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
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
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
David Chang
bcf41a96b4 Update docs (#1893) 2018-06-12 10:42:09 -07:00
Dominic Eden
5b03db6e36 [fix/add-image-details-to-changes-guide] add extra details on how to … (#1870)
* [fix/add-image-details-to-changes-guide] add extra details on how to insert an image into a Slate Value.

* [fix/add-image-details-to-changes-guide] fix linting errors with Prettier

* Update changes.md

* Update changes.md
2018-06-10 16:59:35 -07:00
Jinxuan Zhu
6e6e9cf710 Fix spell check bug (#1753)
* Fix spell check bug by add data-text:true

* Fix spell check bug by spell check add length to a leaf

* Fix tests to use data-text:true for marks

* Rename data-text to data-slate-leaf; Remove setRef; unlift attributes in leaf

* Update examples with data-*

* Add attributes to document

* Fix renderMark in all documents

* Prettier markdown
2018-04-27 14:06:24 -07:00
Lars Karbo
c071df36ea add js to markdown ``` code syntax (#1727) 2018-03-26 07:08:28 -07:00
Andrew Fleming
7238c6a82e Improve grammar in schemas.md (#1685)
Grammar correction
2018-03-03 18:59:14 -05:00
Andrew Fleming
91101465fa Update data-model.md (#1682)
Typo corrected
2018-03-03 18:58:30 -05: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
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
Francesco Agnoletto
cfe5dac0f8 Fix broken links on docs (#1529)
@ianstormtaylor plugins + typo in core-plugins link
2018-01-13 09:24:52 -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
Conor Cussell
7032339ca2 Fix small error in docs (#1435)
- make the placeholder have an opacity
- correct `contentEditable` jsx attribute
2017-12-02 12:34:38 -08:00
Tobias Andersen
1abc7e74b8 fix some typos in docs/guides (#1412) 2017-11-16 11:14:38 -08:00
Ian Storm Taylor
3482437e5c update docs to get it to rebuild? 2017-10-28 14:32:45 -07:00
Ian Storm Taylor
c9f1168cd7 add rendering and schema guides 2017-10-27 18:59:20 -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
Ian Storm Taylor
44addc8140 update plugins guide 2017-10-27 13:12:26 -07:00
Ian Storm Taylor
759979f995 add extra code sample to plugins guide 2017-10-27 13:11:30 -07:00
Ian Storm Taylor
2ab806189a update docs 2017-10-26 09:22:06 -07:00
Ian Storm Taylor
b215e5b7ac update docs 2017-10-25 20:23:22 -07:00
Ian Storm Taylor
c22839c6eb add data model guide, update docs 2017-10-25 20:13:52 -07:00
Ian Storm Taylor
509d3d50fc remove rendering from schema & make it expressive (#1262)
* split rendering out of schema

* remove default components

* first stab at new schema

* make default normalizations smarter

* revert to forcing defaults to be verbose?

* refactor reason constants

* split nodes into blocks/inlines

* get tests passing

* restructure schema tests

* add parent test

* cleanup

* remove defaults from schema

* refactor schema rule.nodes validation, update example

* embed schema in state objects

* fixes

* update examples, and fixes

* update walkthroughs

* update docs

* remove old schemas doc page

* add more tests

* update benchmarks
2017-10-25 17:32:29 -07:00
Ian Storm Taylor
3f25e6a902 update plugins guide 2017-10-25 11:18:48 -07:00
Ian Storm Taylor
0694daf26a add plugins guide 2017-10-25 11:04:37 -07:00
Ian Storm Taylor
c442e52ca6 update docs 2017-10-18 08:58:23 -07:00
Ian Storm Taylor
63855ed15c fix operation link in docs 2017-10-18 08:50:24 -07:00
Alan Christopher Thomas
1237016c9e Mention schema rules as a valid place to make changes (#1256)
* Update Change guide to mention schema rules

* Fix typos
2017-10-18 08:49:31 -07:00
Ian Storm Taylor
d66e127e7d update editor.change() to use change.call(), update docs 2017-10-18 01:42:36 -07:00
Ian Storm Taylor
a802e74bb0 update docs 2017-10-18 01:16:14 -07:00
Ian Storm Taylor
8d60943645 update docs 2017-10-18 01:12:43 -07:00
Ian Storm Taylor
117d8c55cc update docs 2017-10-17 20:53:38 -07:00
Ian Storm Taylor
68e4e090f0 update docs 2017-10-17 20:30:11 -07:00
Ian Storm Taylor
204f491b6b update docs 2017-10-17 20:07:14 -07:00
Ian Storm Taylor
c98ad903c8 Upgrade docs (#1182)
* remove table of contents

* remove more hard-coded table of contents

* remove comparisons, rewrite "why" section to be more general

* update intro
2017-09-25 11:50:23 -07:00
Ian Storm Taylor
7470a6dd53 Expose transforms (#836)
* refactor to extract applyOperation util

* change handlers to receive transform instead of state

* change onChange to receive a transform, update rich-text example

* fix stack iterationg, convert check-list example

* convert code-highlighting, embeds, emojis examples

* change operations to use full paths, not indexes

* switch split and join to be recursive

* fix linter

* fix onChange calls

* make all operations invertable, add src/operations/* logic

* rename "join" to "merge"

* remove .length property of nodes

* fix node.getFragmentAtRange logic

* convert remaining examples, fix existing changes

* fix .apply() calls and tests

* change setSave and setIsNative transforms

* fix insert_text operations to include marks always

* cleanup and fixes

* fix node inheritance

* fix core onCut handler

* skip constructor in node inheritance

* cleanup

* change updateDescendant to updateNode

* add and update docs

* eliminate need for .apply(), change history to mutable

* add missing file

* add deprecation support to Transform objects

* rename "transform" to "change"

* update benchmark

* add deprecation util to logger

* update transform isNative attr

* fix remaining warn use

* simplify history checkpointing logic

* fix tests

* revert history to being immutable

* fix history

* fix normalize

* fix syntax error from merge
2017-09-05 18:03:41 -07:00
Ian Storm Taylor
5091587814 simplify schema rules, update docs 2016-08-14 15:51:07 -07:00
Ian Storm Taylor
06af3de5e5 start adding docs 2016-08-14 14:38:27 -07:00
Ian Storm Taylor
cd9c745a27 add bundled guide to readme 2016-08-07 17:40:28 -07:00
Ian Storm Taylor
030beab8cd fix bundled file, add bundled installation guide 2016-08-07 17:25:43 -07:00
Gonçalo Margalho
3128c26b82 Fix typo in serialize methods (#230) 2016-08-07 12:48:09 -07:00