1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-11 17:53:59 +02:00
Commit Graph

1000 Commits

Author SHA1 Message Date
github-actions[bot]
9874ed704f Version Packages (#4637)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-11-07 07:09:15 -07:00
Charlie Martin
9e8d5e2b9b fix: drag and drop in iframes (#4506) (#4636)
* fix: drag and drop in iframes (#4506)

* Create changeset

* Update iframe-drop-actions.md
2021-10-28 12:36:46 -07:00
github-actions[bot]
35abac13b0 Version Packages (#4632)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-26 21:48:52 -07:00
zhugexinxin
2ee2753d72 fix: image disappears when the drag fails (#4631) 2021-10-26 21:44:09 -07:00
Eric Charles
e54f2a0ea0 Fix double insertion due to insertTextData being called when it should not (#4625)
* fix double paste due to insertTextData being called when it should not

* Document return type of insertTextData and insert FragmentData

* Add changeset
2021-10-26 21:09:36 -07:00
github-actions[bot]
02e9245646 Version Packages (#4629)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-25 09:44:43 -07:00
Jim Fisher
ec01e75fff Revert "Do NOT use exact match when updating dom selection" (#4627)
* Revert "Do NOT use exact match when updating dom selection"

The change to `exactMatch: false` in https://github.com/ianstormtaylor/slate/pull/4304
was intended to fix https://github.com/ianstormtaylor/slate/issues/4293,
a bug where "backwards typing" happened in nested editors.

But this change has introduced at least two new bugs:

- https://github.com/ianstormtaylor/slate/issues/4601
- https://github.com/ianstormtaylor/slate/issues/4626

These are (IMO) worse than the original "backwards typing" bug.

From discussion in https://github.com/ianstormtaylor/slate/pull/4304,
the true underlying bug is in ReactEditor.toSlateRange. I'll attempt to
fix this underlying bug instead.

* changeset
2021-10-25 08:43:06 -07:00
github-actions[bot]
381f91b1dd Version Packages (#4624)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-24 22:18:10 -07:00
github-actions[bot]
d467e33c33 Version Packages (#4610)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-24 08:11:55 -07:00
Nicklas Andersson
0b59ad5414 Feat: Enable selection when editor in readonly=true (#4620)
* make editor.selection avaliable when Editor is contenteditable="false"

* remove dom selection limition of read-only

* Improve grammar of comments regarding selection when read-only is true

* Add Changeset

Co-authored-by: Xheldon <c1006044256@gmail.com>
2021-10-24 07:31:31 -07:00
Jim Fisher
77d9f60ab5 Fix crash when a void node deletes itself on click (#4616)
* Fix crash when a void node deletes itself on click

Fixes https://github.com/ianstormtaylor/slate/issues/4240

* Add 'image delete' feature to example

My immediate motivation is to demonstrate the bug that this fixes. But
this is also a very common editor feature, and I think it's valuable
to show how to achieve it.

* add changeset

* fix:eslint

* revert changes to mentions.tsx
2021-10-24 07:31:00 -07:00
Eric Charles
b50a772136 Add missing insertFragmentData and insertTextData on the ReactEditor class (#4622) 2021-10-23 03:48:05 -07:00
Eric Charles
72160fac08 Add insertFragmentData and insertTextData to the ReactEditor API (#4614)
* Add insertFragmentData and insertTextData to the ReactEditor API

* Add patch changeset

* Docs for insertFragment and insertTextData
2021-10-22 06:44:56 -07:00
I Made Budi Surya Darma
b186d3ea12 Fix crash on drag and drop image on readOnly editable (#4617)
* Fix crash on drag and drop image on readOnly editable

* add changeset
2021-10-22 06:39:30 -07:00
Jim Fisher
67badb7dd0 Allow typing at the end of an inline element (#4578)
* Allow typing at the end of an inline

This fixes https://github.com/ianstormtaylor/slate/issues/4524

Steps to reproduce the buggy behavior:

* Create a page with an inline element, or go to
  https://codepen.io/jameshfisher/pen/xxrXvVO
* Put the cursor at the end of the inline code element
* Type something

Expected behavior: If the cursor is at the end of an inline, text
should be inserted at the end of the inline.

Actual behavior: Slate moves the cursor outside the inline before
inserting text.

This current behavior is explicitly coded. I nevertheless claim that
this is a bug, or at least a misfeature in core. My expected behavior
comes from:

* The fact that the cursor is inside the inline. For the user, the
  blinking cursor is visually inside the inline, not outside it. For the
  developer, the cursor (i.e. editor.selection) is inside the inline,
  not outside it. The definition of "the cursor" is "this is where your
  text will go when you type". To break that behavior is really jarring.
* Slate's principle that "all of its logic is implemented with a series
  of plugins". If the current behavior is actually desirable in some
  circumstance, it should be in a plugin, not core. It's harder and less
  elegant for me to remove the core behavior with my own plugin.
* Comparison with other editors. The following editors all insert text
  at the end of the inline, as expected: default contenteditable,
  Medium, Coda.io, Google Docs, OneNote, Evernote, QuillJS, TinyMCE,
  EditorJS, ProseMirror. Two editors with the current buggy behavior are
  Notion and Dropbox Paper, but I find it hard to imagine that their
  current behavior on this issue is actually designed, and not just
  accidental.
* Usability: how else is the user supposed to enter text at the end of
  the inline ..? The only way seems to be to insert text before the end
  of the inline, and then delete the rest of the inline. This is
  obviously horrible.

* add changeset

* Fix test: insert at the end of an inline should _not_ have special behavior

* The selection is no longer moved in insertText so we don't need this special case

* fix:prettier

* Revert "The selection is no longer moved in insertText so we don't need this special case"

This reverts commit f9f36cd439.

* Explain the real reason for this special case - native browser bugs
2021-10-19 10:46:17 -07:00
github-actions[bot]
3678590ccf Version Packages (#4594)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-18 14:05:11 -07:00
Jake Donham
87ab2efa41 defer native events within Editable to avoid bugs with Editor (#4605)
* defer native events internally to Editable

* add changeset

* suggestions to make DeferredOperation a closure instead of an object type

Co-authored-by: Nemanja Tosic <netosic90@gmail.com>

* fix misapplied suggestion

Co-authored-by: Nemanja Tosic <netosic90@gmail.com>
2021-10-18 13:05:16 -07:00
Jim Fisher
f40e515dc7 Fix bug: setting selection from contentEditable:false element causes crash (#4584)
* Fix bug: setting selection from contentEditable:false element causes crash

Fixes https://github.com/ianstormtaylor/slate/issues/4583

When clicking some text in a `contentEditable:false` element, if the
handler for this sets the selection, Slate crashes. Slate tries to find
a Slate range for the text that was clicked on, but there is no such
range, because the text is inside a `contentEditable:false` element.
Slate seems to be making a bad assumption that the current DOM selection
necessarily corresponds to a Slate range, but this is not the case if
the user just clicked into an element with `contentEditable: false`.
To fix this, I changed `exactMatch: false` to `exactMatch: true`,
which seems to mean "fail gracefully if there is no exact match".

* changeset

* Revert "Fix bug: setting selection from contentEditable:false element causes crash"

This reverts commit 71234284cd.

* Unconflate exactMatch flag: add suppressThrow flag for separate behavior

* Fix bug: setting selection from contentEditable:false element causes crash

Fixes #4583

When clicking some text in a `contentEditable:false` element, if the
handler for this sets the selection, Slate crashes. Slate tries to find
a Slate range for the text that was clicked on, but there is no such
range, because the text is inside a `contentEditable:false` element.
Slate seems to be making a bad assumption that the current DOM selection
necessarily corresponds to a Slate range, but this is not the case if
the user just clicked into an element with `contentEditable: false`.
2021-10-13 11:45:00 -07:00
Jim Fisher
4b2e4000d6 Don't remove selection when hovering over a non-selectable DOM element (#4577)
* Don't remove selection when hovering over a non-selectable node

Fixes https://github.com/ianstormtaylor/slate/issues/4545

To reproduce the buggy behavior:

1. Create a page that renders a Slate element with a `contentEditable: false` element in it.
2. Start selecting some text with the mouse.
3. During the drag, mouseover the `contentEditable: false` element.

Expected behavior: After doing a drag-to-select with the mouse, from a valid anchor point on mousedown to a valid focus point on mouseup, the selection is set to those anchor and focus points.

Actual behavior: your selection is removed as soon as your mouse hits the `contentEditable: false` element. This is because the current behavior clears the selection if it is momentarily not a valid Slate location.

* Add changeset
2021-10-11 17:39:53 -07:00
Bryan Haakman
11ef83b47f Only use Slate Provider's value prop as initial state (#4540)
* Only use value prop as initial state

* Add onChange call back

* add changeset
2021-10-11 17:38:02 -07:00
github-actions[bot]
b18dd40026 Version Packages (#4592)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-11 17:29:35 -07:00
Jake Donham
ae65ae5f71 revert #4455 / #4512; fix triple-click by unhanging range with void (#4588)
* revert #4455 / #4512; fix triple-click by unhanging range with void

* added changeset
2021-10-11 05:15:04 -07:00
github-actions[bot]
1ce3f4cf62 Version Packages (#4557)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-10-06 16:26:31 -04:00
Jake Donham
b108491820 fix forced update in TextString in case of double render (#4556)
* fix forced update in TextString in case of double render

* added changeset
2021-09-28 10:19:47 -07:00
Claudéric Demers
37d60c58b8 only apply Firefox toSlatePoint offset fix if ending in \n\n (#4552) 2021-09-27 10:14:07 -07:00
github-actions[bot]
ffac781086 Version Packages (#4551)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-09-27 09:20:26 -07:00
David Ruisinger
7ba486aa39 Do NOT use exact match when updating dom selection (#4304)
* Do NOT use exact match when updating dom selection

* Added changeset
2021-09-27 09:05:39 -07:00
github-actions[bot]
997fee8b5c Version Packages (#4544)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-09-27 06:54:30 -07:00
Claudéric Demers
677da0ca87 Fix toSlatePoint when text node ends in \n in Firefox (#4547)
In Firefox, `range.cloneContents()` returns an extra trailing '\n', when the document ends with a new-line character. This results in the offset length being off by one, so we need to subtract one to account for this.
2021-09-26 08:07:14 -07:00
Nemanja Tosic
f9c41a569c Fix deletion of expanded range (#4549) 2021-09-26 08:05:52 -07:00
Victor Baron
bc85497d58 Fix - delete selected inline void in chrome (#4526)
* Fix - delete selected inline void in chrome

* Add changeset

* Fix prettier on changeset

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
2021-09-24 04:12:29 -07:00
github-actions[bot]
38717ad455 Version Packages (#4539)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-09-23 12:28:47 -07:00
Nemanja Tosic
bd80a0b8dc Fix erroneous text after native insert (#4529) 2021-09-19 13:43:29 -07:00
github-actions[bot]
35b722cadd Version Packages (#4520)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-09-14 01:20:36 -07:00
Trang Le
cc7cb623cf fix(react-editor): reset focus offset when triple clicking (#4512)
* fix(react-editor): reset focus offset when triple clicking

* fix(react editor): remove commented-out code
2021-09-13 09:59:42 -07:00
github-actions[bot]
2a346ded9d Version Packages (#4436)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-09-10 17:54:01 -07:00
Tom Scott
50bb3d7e32 Upgrade is-plain-object to v5.0.0 (#4500)
* Upgrade `is-plain-object` to v5.0.0

The `is-plain-object` package recently had a major version upgrade that
broke libraries which import its default export, such as this one. This
causes issues when other packages in the same application require a
higher version of `is-plain-object`, resulting in an error originating
in Slate's codebase. To remedy this, Slate is now depending on
`is-plain-object@^5.0.0` and its import references across the codebase
have been updated.

Fixes #4499

* Add changeset

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
2021-09-09 12:55:13 -07:00
Trang Le
f5c0cbd7ec Fix: regression caused by triple click fix (#4498)
* fix: check if data-slate-tring node is not null

Only reset the focus node of a selection when the node with attribute `data-slate-string` is defined

* fix: rewrite logic for checking triple click

* Add changeset

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
2021-09-08 17:34:57 +01:00
Dylan Schiemann
3dd74dd58d Update error message for useSlate (#4493)
* Update error message for useSlate

fixes #4479

* Add changeset
2021-09-07 05:00:48 -07:00
Eric Charles
d338dcc7ce Jest testing for slate-react (#4459)
* initial skeleton for jest testing

* run in serial mocha, then jest on slate-react only

* run-s without glob patterns https://github.com/yarnpkg/berry/issues/22

* don't run mocha on slate-react package

* use yarn run instead of run-s
2021-09-01 14:25:11 -07:00
I Made Budi Surya Darma
e51566ada8 Add key for Children SelectedContext.Provider (#4480)
* Add key for Children context

* add changeset
2021-08-31 05:22:56 -07:00
Trang Le
2d1aaafa0b Fix(editable component): reselect the range created by triple click (#4455)
* fix(editable component): reselect the range created by triple click

* Revert "fix(editable component): reselect the range created by triple click"

Reason: attaching a handler for `onClick` event is no longer needed.

* fix(react-editor): reselect DOMSelection when triple clicked

Reason: Triple clicking an element in Chrome will falsely set the focus node as the next sibling node with focusOffset 0

* test: add e2e test for triple click
2021-08-28 05:02:30 -07:00
Bryan Haakman
8eb1abac87 Migrate yarn to berry v3 (#4417)
* Migrate to yarn berry v3

* Fix yarn dependencies for linting

* Specifically invoke bash in yarn clean to make brace expansion work

* Upgrade cypress to 8.x to support yarn berry

* Try out yarn berry workaround for netlify

From https://answers.netlify.com/t/using-the-new-yarn-release-2-0-0-berry/8270

* Update .yarnrc.yml for syntax consistency

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>

* use rimraf for clean command with escaped glob pattern

* Use workspace:* resolution for workspace packages and rewrite yarn.lock

* set workspace package versions explicit again

* update peer dependencies

* disable import/named for ts and tsx files

* Replace 'key' with 'key=true' wherever babel complains

* replace all instances of key to someKey in tests to satisfy eslint and babel

* remove unnecessary yarn packageExtension and remove cross-env dependency

* upgrade yarn to latest

* Upgrade next.js to 10.x to support yarn berry

* update .yarnrc to satisfy netlify

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
2021-08-28 04:59:10 -07:00
Per-Kristian Nordnes
c1433f56cf [slate-react]: fix selection bugs when multiple editors share value (#4475)
* [slate-react]: fix selection bugs when multiple editors share value

The KEY_TO_ELEMENT weakmap must be scoped to the instance to avoid collisions between multiple editors.

This is solved by wrapping it in another WeakMap keyed on the editor object, that returns the KEY_TO_ELEMENT Weakmap for that editor.

* Add changeset

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
2021-08-25 15:59:23 +02:00
Ulion
48b7129447 Make onDomSelectionChange triggered after onClick. (#4132)
* Delay onDomSelectionChange but not cause performance issue.

* Add changeset

* Update changeset

Changeset editor via GitHub's UI seems to violate our prettier rules 🤦🏼‍♂️

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
2021-08-21 17:03:07 -07:00
Dylan Schiemann
ace397f966 Double character insert regression (#4460)
* fix double character regression

* add changeset
2021-08-19 07:49:17 -07:00
Githoniel
8e4120ae31 fix: insert new node in advance to avoid ime double input with editor marks (#4451)
* fix: insert new node in advance to avoid ime double input

* chore: add changeset

* refactor: minor refator as review
2021-08-16 04:42:26 -07:00
I Made Budi Surya Darma
d06706c9e1 Read data-slate-fragment when application/x-slate-fragment is missing (#4454)
* fix missing slate-fragment onpaste ion safari

* add changeset
2021-08-13 10:54:58 -07:00
Dylan Schiemann
935b3a79d6 fix: chinese input double in qq browser (#4452)
* fix: chinese input double in qq browser

* add changeset

* update changeset
2021-08-13 04:46:06 -07:00
I Made Budi Surya Darma
834ce3483d fix(android): Fix editors mark is not inserted on insert text in android (#4342)
* fix(android): Fix mark is not inputed on insert text in android

* add changeset

* null mark only when mark exist

Co-authored-by: surya darma <budi.surya@kumparan.com>
2021-08-13 03:55:27 -07:00