1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 17:23:07 +01:00

108 Commits

Author SHA1 Message Date
Sunny Hirai
4b92b752ef docs: Added TypeScript info to the Installing Slate walkthrough 2021-03-30 14:58:31 -07:00
Sunny Hirai
08275f68f3
Custom TypeScript Types (#3835)
This PR adds better TypeScript types into Slate and is based on the proposal here: https://github.com/ianstormtaylor/slate/issues/3725

* Extend Slate's types like Element and Text

* Supports type discrimination (ie. if an element has type === "table" then we get a reduced set of properties)

* added custom types

* files

* more extensions

* files

* changed fixtures

* changes eslint file

* changed element.children to descendant

* updated types

* more type changes

* changed a lot of typing, still getting building errors

* extended text type in slate-react

* removed type assertions

* Clean up of custom types and a couple uneeded comments.

* Rename headingElement-true.tsx.tsx to headingElement-true.tsx

* moved basetext and baselement

* Update packages/slate/src/interfaces/text.ts

Co-authored-by: Brent Farese <25846953+BrentFarese@users.noreply.github.com>

* Fix some type issues with core functions.

* Clean up text and element files.

* Convert other types to extended types.

* Change the type of editor.marks to the appropriate type.

* Add version 100.0.0 to package.json

* Revert "Add version 100.0.0 to package.json"

This reverts commit 329e44e43d968700655b1c46f968bfd3147e7339.

* added custom types

* files

* more extensions

* files

* changed fixtures

* changes eslint file

* changed element.children to descendant

* updated types

* more type changes

* changed a lot of typing, still getting building errors

* extended text type in slate-react

* removed type assertions

* Clean up of custom types and a couple uneeded comments.

* Rename headingElement-true.tsx.tsx to headingElement-true.tsx

* moved basetext and baselement

* Update packages/slate/src/interfaces/text.ts

Co-authored-by: Brent Farese <25846953+BrentFarese@users.noreply.github.com>

* Fix some type issues with core functions.

* Clean up text and element files.

* Convert other types to extended types.

* Change the type of editor.marks to the appropriate type.

* Run linter.

* Remove key:string uknown from the base types.

* Clean up types after removing key:string unknown.

* Lint and prettier fixes.

* Implement custom-types

Co-authored-by: mdmjg <mdj308@nyu.edu>

* added custom types to examples

* reset yarn lock

* added ts to fixtures

* examples custom types

* Working fix

* ts-thesunny-try

* Extract interface types.

* Fix minor return type in create-editor.

* Fix the typing issue with Location having compile time CustomTypes

* Extract types for Transforms.

* Update README.

* Fix dependency on slate-history in slate-react

Co-authored-by: mdmjg <mdj308@nyu.edu>
Co-authored-by: Brent Farese <brentfarese@gmail.com>
Co-authored-by: Brent Farese <25846953+BrentFarese@users.noreply.github.com>
Co-authored-by: Tim Buckley <timothypbuckley@gmail.com>
2020-11-24 12:30:06 -08:00
CameronAckermanSEL
e40fd0534d fix #3830 2020-08-19 09:41:28 -07:00
Frederik Eychenié
32e120af19
docs: remove unused "selection" from code example (#3731) 2020-06-13 09:49:00 -07:00
Ali Muqaddas
9834fe4e95
Fix: ESlint Error (#3688)
Value is defined in the upper scope
2020-05-17 08:51:07 -07:00
Kevin Simons
3c80c3e88b
Fix a few issues with the documentation (#3679)
* Fix a few issues with the documentation

* Add Kitemaker to the list of sites using Slate
2020-05-13 08:56:24 -07:00
George Rodier
9a6e8fba92
Import Transforms in custom elements walkthough (#3630) 2020-04-22 09:09:42 -07:00
Kirk Swenson
f6bfe034d7
Fix typos and other minor issues in docs (#3597)
Fixed typos and grammatical errors in the documentation
2020-04-10 09:05:03 -07:00
Ken Aoki
5da89b8656
Update 01-installing-slate.md (#3554) 2020-03-24 18:12:06 -07:00
Xleine
217bdd611b fix some doc's bug (with v0.57.1) (#3393)
* fix: code blocks's info string
this info string. should be `jsx`

* fix: editor's exec invoke
now, editor.exec() is not available in Slate v0.57.1
so, use editor.insertText() to instead it

*  refactor: delete a nerver used value

* update add new chinese translate
      update chinese translate to `v0.57.1`

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
2020-01-27 15:24:15 -05:00
Aykut Kardaş
f813af790e An unused state was deleted. (#3413) 2020-01-27 15:22:54 -05:00
David Calhoun
27db5e6c45 docs: walkthroughs: make implicit React dependencies explicit (#3402) 2020-01-27 15:21:08 -05:00
Leon
8cd9b79352 Update 04-applying-custom-formatting.md (#3371) 2020-01-03 23:02:40 -08:00
Ian Storm Taylor
e1f4ff1f6c fix docs 2019-12-19 14:37:10 -05:00
Ian Storm Taylor
dae32cd473 update docs for removal of commands 2019-12-19 14:34:34 -05:00
Ian Storm Taylor
0bbe121d76
Remove commands (#3351)
* remove commands in favor of editor-level functions

* update examples

* fix lint
2019-12-18 15:00:42 -05:00
Ian Storm Taylor
235a578967
rename Node.text to Node.string (#3341) 2019-12-17 22:17:21 -05:00
Ian Storm Taylor
7d832b5e12
Standardize node matching APIs (#3327)
* add lowest mode and universal flag to `Editor.nodes`

* add `mode` handling to all transforms

* add extra `Editor.is*` helpers

* change `Editor.previous` to make all optional

* change `Editor.next` to make all optional

* change `Editor.match` to make all optional

* add `Editor.void` helper

* remove non-function match arguments

* remove NodeMatch interface

* change to lowest match by default everywhere

* rename `Editor.match` to `Editor.above`

* use new helpers

* cleanup

* make NodeEntry generic, cleanup

* fix NodeEntry generics

* ensure only ancestors are returned from Editor.above

* add type-narrowing to `Editor.nodes`, remove extras

* remove other Node entry types

* cleanup

* remove `Editor.block` and `Editor.inline` helpers
2019-12-15 19:36:05 -05:00
Ian Storm Taylor
6552da940a
Add format_text command, and editor.marks state (#3308)
* add format_text command, refactor command extensions

* update onChange to not receive selection

* update docs

* fix tests
2019-12-12 15:37:55 -05:00
Ian Storm Taylor
e68a5cd305
remove the slate-schema package (#3291) 2019-12-10 17:53:27 -05:00
Ian Storm Taylor
be8b7222ee update walkthroughs 2019-12-06 12:06:53 -05:00
Tim Buckley
ed974222a9 Custom Format docs typo fix: leaf -> props (#3257)
* Custom Format docs typo fix: leaf -> props

* Update 04-applying-custom-formatting.md
2019-12-05 19:13:34 -05:00
Ian Storm Taylor
124ff37c3a update docs 2019-12-05 12:52:52 -05:00
Ian Storm Taylor
4c03b497d9
remove marks, in favor of text properties (#3235)
* remove marks, in favor of text properties

* fix lint

* fix more examples

* update docs
2019-12-05 11:21:15 -05:00
Ian Storm Taylor
6fc935a4b8 remove Editor.toggleMarks from docs 2019-12-02 22:23:58 -05:00
Wee
434ce21cec feat: allow MarkTransforms methods to take a single mark (resolve #3175) (#3183) 2019-12-01 13:49:29 -05:00
Ian Storm Taylor
68569f286e improve Editor.marks and Editor.nodes abstraction 2019-11-29 23:15:08 -05:00
sherwinyu
0da1dd128c Update Adding Event Handlers walkthrough (#3169)
The previous example no longer uses `onChange`, so don't reference it in this walkthrough.
2019-11-29 17:25:40 -05:00
sherwinyu
2ad7735869 Fix typos in Installing Slate walkthrough (#3168) 2019-11-29 15:07:16 -05:00
Marton Langa
6608a5df39 Remove controlled value state (#3153) 2019-11-28 17:21:12 -05:00
Marton Langa
5de91cb4ee Fix variable name (#3156) 2019-11-28 17:20:54 -05:00
Ian Storm Taylor
7f2bbcfef2 fix linter 2019-11-28 12:38:12 -05:00
Matt Mazzola
d457bc52b9 Docs fixes for 0.50.0 (#3133)
* docs: typos

* docs: markdown inline code formatting

https://meta.stackexchange.com/questions/82718/how-do-i-escape-a-backtick-within-in-line-code-in-markdown

* docs: remove unused value, move comment, add deps to callback

* docs: add deps to renderMark callback
2019-11-28 10:37:35 -05:00
Ian Storm Taylor
4ff6972096
Next (#3093)
* remove some key usage from core, refactor Operations.apply

* undeprecate some methods

* convert more key usage to paths

* update deprecations

* convert selection commands to use all paths

* refactor word boundary selection logic

* convert many at-range commands to use paths

* convert wrapBlock and wrapInline to not use keys

* cleanup

* remove chainability from editor

* simplify commands, queries and middleware

* convert deleteAtRange

* remove key usage from schema, deprecate *ByKey methods

* migrate *ByKey tests, remove index from *ByPath signatures

* rename at-current-range tests

* deprecate mode key usage, migrate more tests away from keys

* deprecate range and point methods which rely on keys to work

* refactor insertBlock, without fixing warnings

* add pathRef/pointRef, fix insertBlock/Inline deprecations, work on insertFragment

* refactor insertFragment

* get rich-text example rendering

* fix lint

* refactor query files, fix more tests

* remove unused queries, refactor others

* deprecate splitDescendantsByPath

* merge master

* add typescript, convert slate, slate-hyperscript, slate-plain-serializer

* add Point, Path, Range, Annotation tests

* add Annotation, Change, Element, Fragment, Mark, Range, Selection, Value interfaces tests

* add Operation and Text tests

* add Node tests

* get operations and normalization tests working for slate

* get *AtPath command tests passing

* rename *AtPath command tests

* rename

* get *AtPoint tests working

* rename

* rename

* add value queries tests

* add element, mark and path queries tests

* convert most on-selection tests

* convert on-selection commands

* rename

* get addMarks and delete commands working

* rename

* rename

* rename

* refactor value.positions(), work on delete tests

* progress on delete tests

* more delete work

* finish delete tests

* start converting to at-based commands

* restructure query tests

* restructure operations tests

* more work converting to multi-purpose commands

* lots of progress on converting to at-based commands

* add unwrapNodes

* remove setValue

* more progress

* refactor node commands to use consistent matching logic

* cleanup, get non-fragment commands passing

* remove annotations and isAtomic

* rename surround/pluck to cover/uncover

* add location concept, change at-path to from-path for iterables

* refactor batches

* add location-based queries

* refactor hanging logic

* more location query work

* renaming

* use getMatch more

* add split to wrap/unwrap

* flip levels/ancestors ordering

* switch splitNodes to use levels

* change split to always:false by default

* fix tests

* add more queries tests

* fixing more delete logic

* add more splitNodes tests

* get rest of delete tests passing

* fix location-based logic in some commands

* cleanup

* get previous packages tests passing again

* add slate-history package

* start slate-schema work

* start of react working

* rendering fixes

* get rich and plain text examples working

* get image example working with hooks and dropping

* refactor onDrop to be internal

* inline more event handlers

* refactor lots of event-related logic

* change rendering to use render props

* delete unused stuff

* cleanup dom utils

* remove unused deps

* remove unnecessary packages, add placeholder

* remove slate-react-placeholder package

* remove unused dep

* remove unnecessary tests, fix readonly example

* convert checklists example

* switch to next from webpack

* get link example working

* convert more examples

* preserve keys, memoized leafs/texts, fix node lookup

* fix to always useLayoutEffect for ordering

* fix annotations to be maps, memoize elements

* remove Change interface

* remove String interface

* rename Node.entries to Node.nodes

* remove unnecessary value queries

* default to selection when iterating, cleanup

* remove unused files

* update scroll into view logic

* fix undoing, remove constructor types

* dont sync selection while composing

* add workflows

* remove unused deps

* convert mentions example

* tweaks

* convert remaining examples

* rename h to jsx, update schema

* fix schema tests

* fix slate-schema logic and tests

* really fix slate-schema and forced-layout example

* get start of insertFragment tests working

* remove Fragment interface

* remove debugger

* get all non-skipped tests passing

* cleanup deps

* run prettier

* configure eslint for typescript

* more eslint fixes...

* more passing

* update some docs

* fix examples

* port windows undo hotkey change

* fix deps, add basic firefox support

* add event overriding, update walkthroughs

* add commands, remove classes, cleanup examples

* cleanup rollup config

* update tests

* rename queries tests

* update other tests

* update walkthroughs

* cleanup interface exports

* cleanup, change mark transforms to require location

* undo mark transform change

* more

* fix tests

* fix example

* update walkthroughs

* update docs

* update docs

* remove annotations

* remove value, move selection and children to editor

* add migrating doc

* fix lint

* fix tests

* fix DOM types aliasing

* add next export

* update deps, fix prod build

* fix prod build

* update scripts

* update docs and changelogs

* update workflow and pull request template
2019-11-27 20:54:42 -05:00
Stewart Sum
6fc0bc85e6 Update saving-and-loading-html-content.md (#3064)
Change the name of the first argument of the serialize function from 'object' to 'obj' in the description to match what is used in the code.
2019-11-09 17:56:18 -05:00
Lionel
1aa1783c9c Update installing-slate.md (#2975)
Just noticed a missing word in this doc, thought I'd add a quick fix.
2019-08-21 22:40:18 -04:00
Daniil Khanin
5f26890ff9 Update applying-custom-formatting.md (#2843) 2019-06-07 18:56:36 +01:00
Ken Powers
e4c6beaab4 Remove leaves from walkthough docs (#2831) 2019-06-07 18:53:33 +01:00
Jon Portella
fbe70a1f28 Fix: prop name (#2780)
Nodes weren't properly rendering because the Editor was trying to call the function prop renderBlock but instead another called renderNode was passed.
2019-05-20 13:34:30 -07:00
Matthew Steedman
f76a00acdc Replace renderNode with renderBlock (#2762) 2019-05-11 18:52:09 -07:00
Mate Paiva
bd7ee85c9b Fix missing break in last example (#2629)
In the last chunk of code, it was missing the `break` (or `return`). So, if used as is, the bold key will toggle the `code` feature as well.
2019-03-06 16:45:08 -05:00
Mate Paiva
e5e1e570b8 Remove return true on key down function (#2628)
Correct me if I am wrong, but I believe that this `return true` is a no-op. I removed it and everything kept working as usual. And, when I was following the tutorial, that particular line created an interrogation mark in my brain. So, my suggestion is to remove that line to avoid creating entropy for no reason.
2019-03-06 16:44:35 -05:00
Nandu
7a6de8725c Add break in the Switch statement for Custom Formatting Walkthrough (#2550)
The Custom Formatting Walkthrough does not work as expected. When
Ctrl + B is pressed it applies both Bold and Code styles to the
content. This is because of the case statement running beyond
the Bold case due to the absence of a break keyword.
2019-01-21 18:27:43 -08:00
Denys Vuika
59d184b153 Update saving-and-loading-html-content.md (#2452)
fix example code
2018-12-02 13:15:16 -08: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
Kashif
c0c0eb65f2 Add missing import (#2252) 2018-10-11 21:34:23 -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
Maulik
ebc72bf38f Updating function in readme.md (#2185)
Typo in function definition
2018-09-19 11:38:27 -07:00
Martti Laine
1ff1dfa4b8 Add slate-react to the bundled source guide (#2010) 2018-07-31 16:46:30 -07:00