1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-31 20:48:30 +01:00

2636 Commits

Author SHA1 Message Date
Ian Storm Taylor
8eb8e26958 Publish
- slate-react@0.20.1
slate-react@0.20.1
2018-10-28 16:28:45 -07:00
Eric Hartline
e16b0d58f4 add clarification for paste HTML example (#2344)
* add clarification for paste HTML example

fixes #1392

* Update value.json
2018-10-28 12:37:16 -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
slate@0.43.0 slate-react@0.20.0 slate-prop-types@0.5.7 slate-plain-serializer@0.6.16 slate-hyperscript@0.11.7 slate-html-serializer@0.7.16 slate-base64-serializer@0.2.77
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
slate@0.42.6 slate-react@0.19.8 slate-prop-types@0.5.6 slate-plain-serializer@0.6.15 slate-hyperscript@0.11.6 slate-html-serializer@0.7.15 slate-base64-serializer@0.2.76
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
slate@0.42.5 slate-react@0.19.7 slate-prop-types@0.5.5 slate-plain-serializer@0.6.14 slate-hyperscript@0.11.5 slate-html-serializer@0.7.14 slate-base64-serializer@0.2.75
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
Brian Bucknam
abc75bb45e Fix exception in Input Tester example (#2278)
* Fix bolded text in input-tester initial value

* Fix crash on Input Tester example with certain input events

If an Input event with inputType  "insertReplacementText" is received, the example crashes because "event.dataTransfer.get is not a function"
The correct API is `getData()`, not `get()`.
Ref: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/getData

* Revert "Fix bolded text in input-tester initial value"

This reverts commit 82e1213be39a9f19c837ff3d28c4c025035d595b.

* Revert "Revert "Fix bolded text in input-tester initial value""

This reverts commit b5a0a2440f388f741222574974cf5fd2ff454a91.
2018-10-25 09:43:45 -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
slate@0.42.4 slate-react@0.19.6 slate-prop-types@0.5.4 slate-plain-serializer@0.6.13 slate-hyperscript@0.11.4 slate-html-serializer@0.7.13 slate-base64-serializer@0.2.74
2018-10-24 16:09:16 -07:00
Eric Edem
2561ce4a89 fix: use ancestors for dirt paths (#2316)
* fix: use ancestors for dirt paths

Not just parents.

* fix: also revalidate ancestors when mutating existing nodes.
2018-10-24 16:06:53 -07:00
Slapbox
611fa85b80 Fixes deleteWordForward at line ending (#2290)
#### Is this adding or improving a _feature_ or fixing a _bug_?
Bug fix - Very minor change

#### What's the new behavior?

`deleteWordBackward` at line ending behaves the same as `deleteCharForward`

#### How does this change work?

If `TextUtils.getWordOffsetForward(text, o)` returns 0, instead we substitute in `1` to delete the line break and join the blocks. The relevant test for this change (`join-blocks`) is also added.

#### 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: #2258
Reviewers: @ianstormtaylor
2018-10-24 15:46:01 -07:00
Ian Storm Taylor
bcc61a0bb2 Publish
- slate-hotkeys@0.2.7
 - slate-react@0.19.5
slate-react@0.19.5 slate-hotkeys@0.2.7
2018-10-24 14:52:39 -07:00
Eric Edem
b1073f5672 fix: extend forward / backward (#2314)
#### Is this adding or improving a _feature_ or fixing a _bug_?

_bug_

#### What's the new behavior?

Fix behavior for <kbd>shift + left</kbd> and <kbd>shift + right</kbd>. Now they will correctly move forward / backward.

#### How does this change work?

turns out that the hotkey `'left'` would also pick up with a modifier key `'shift+left'` so checking for `Hotkeys.isExtendForward()` needs to come before `Hotkeys.isMoveForward()` and it needs to short circuit with `return true`. Likewise for backward.

#### 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: #2307 
Reviewers: @ianstormtaylor
2018-10-24 14:50:20 -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
Max Nesov
1032d14ffb Update change.md (#2310)
moveToRangeOf => moveToRangeOfDocument
2018-10-24 09:11:41 -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
slate@0.42.3 slate-react@0.19.4 slate-prop-types@0.5.3 slate-plain-serializer@0.6.12 slate-hyperscript@0.11.3 slate-html-serializer@0.7.12 slate-hotkeys@0.2.6 slate-base64-serializer@0.2.73
2018-10-22 15:24:10 -07:00
Ian Storm Taylor
93df22a128 add unwrapChildrenByPath/Key command 2018-10-22 15:21:45 -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
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
Eric Edem
4c52f7ceff add favicon to the examples (#2283)
Was tired of seeing the error so I stoled this from the gitbook documentation.
2018-10-20 13:11:40 -07:00
Alan Christopher Thomas
175b25ae51 Fix docs on queries to show editor argument (#2285) 2018-10-20 00:05:53 -07:00
Brian Bucknam
53fd59bc62 Fix bolded text in input-tester initial value (#2277) 2018-10-17 11:59:28 -07:00
Eric Edem
63ad062083 feat: add a basic mention implementation example (#2233)
* feat: add a basic mention implementation example

Just a simple example to get people started when trying to implement their own mentions implementation.

* feat(MentionsExample): use a floating suggestions menu.

* fix(MentionsExample): update to slate 0.42
2018-10-16 20:14:22 -07:00
Francis Belanger
861f30a3f9 Add possibility to specify a custom delimiter to slate-plain-serializer (#2266)
* Add possibility to specify a custom delimiter

* Add custom delimiter to the serialize method

* Fix lint
2018-10-16 11:38:19 -07:00
Pier Bover
0deb2e2695 Fixed link (#2270) 2018-10-16 11:35:14 -07:00
Alan Christopher Thomas
996edd19f5 Fix insertTextAtRange selection (#2256)
* Make a test case for buggy insertTextAtRange selection behavior

* Insert text at previous path, not selection key, closes #2209
2018-10-15 15:48:00 -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
Stephen O'Brien
6c2168c8fe Update ‘Submitting Pull Requests’ to refer to an active label (#2265)
I’m hoping to start making a few contributions myself and was checking this guide out, but noticed that the `✓ easy one` label hasn’t been used in a while and has no open issues.

Instead, we now recommend the `♥ help please` label as a source of issues to fix for potential contributors.
2018-10-15 11:47:17 -07:00
Kashif
c0c0eb65f2 Add missing import (#2252) 2018-10-11 21:34:23 -07:00
Jinxuan Zhu
3c1e3a1574 Fix word counting (#2247) 2018-10-10 14:00:45 -07:00
Ian Storm Taylor
10bf13804f refactor plugins example, fixes #2243 2018-10-10 10:10:27 -07:00
Ian Storm Taylor
d7123453c2 Publish
- slate-react@0.19.3
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
9c597cf97f fix hover manu example 2018-10-10 01:04:35 -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
slate@0.42.2 slate-react@0.19.2 slate-prop-types@0.5.2 slate-plain-serializer@0.6.11 slate-hyperscript@0.11.2 slate-html-serializer@0.7.11 slate-base64-serializer@0.2.72
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
slate@0.42.1 slate-react@0.19.1 slate-prop-types@0.5.1 slate-plain-serializer@0.6.10 slate-hyperscript@0.11.1 slate-html-serializer@0.7.10 slate-base64-serializer@0.2.71
2018-10-09 15:11:57 -07:00
Ian Storm Taylor
bd24739411 fix to pass editor to queries 2018-10-09 15:06:35 -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
slate@0.42.0 slate-react@0.19.0 slate-prop-types@0.5.0 slate-plain-serializer@0.6.9 slate-hyperscript@0.11.0 slate-html-serializer@0.7.9 slate-base64-serializer@0.2.70
2018-10-09 14:17:15 -07:00
Ian Storm Taylor
cfa904bb1f update readme beta notice 2018-10-09 14:13:27 -07:00
Ian Storm Taylor
5ad951f08a update badge labels 2018-10-09 14:11:57 -07:00
Ian Storm Taylor
9f53d60bd1 remove packages-specific readme 2018-10-09 14:11:20 -07:00