Skip to content

Commit

Permalink
Merge branch 'master' into lp-native-single-character-inserts
Browse files Browse the repository at this point in the history
  • Loading branch information
luddep committed May 15, 2020
2 parents b708490 + c00f246 commit 2d58cb0
Show file tree
Hide file tree
Showing 38 changed files with 374 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Expand Up @@ -19,7 +19,7 @@ If you don't include these, there's a very good chance your issue will be closed
We need to keep the issues actionable, or else maintaining Slate becomes overwhelming. Thank you for understanding!
https://codesandbox.io/s/slate-reproductions-k0tpx
https://codesandbox.io/s/slate-reproductions-c7gyg
http://recordit.co/
-->

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,10 +1,11 @@
*.log
.next/
.vscode/
.idea/
build/
dist/
lib/
node_modules/
packages/*/yarn.lock
site/out/
tmp/
tmp/
6 changes: 6 additions & 0 deletions Changelog.md
Expand Up @@ -2,6 +2,12 @@

This is a list of changes to Slate with each new release. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller, patch-level changes won't be noted since the library is moving quickly while in beta.

### `0.58.0` - May 5th, 2020

###### BREAKING

**User properties on Elements and Texts now have an unknown type instead of any.** Previously, the arbitrary user defined keys on the `Text` and `Element` interface had a type of `any` which effectively removed any potential type checking on those properties. Now these have a type of `unknown` so that type checking can be done by consumers of the API when they are applying their own custom properties to the `Text`s and `Element`s.

---

### `0.57.0` — December 18, 2019
Expand Down
34 changes: 26 additions & 8 deletions config/rollup/rollup.config.js
Expand Up @@ -22,6 +22,7 @@ function configure(pkg, env, target) {
const isProd = env === 'production'
const isUmd = target === 'umd'
const isModule = target === 'module'
const isCommonJs = target === 'cjs'
const input = `packages/${pkg.name}/src/index.ts`
const deps = []
.concat(pkg.dependencies ? Object.keys(pkg.dependencies) : [])
Expand Down Expand Up @@ -103,7 +104,7 @@ function configure(pkg, env, target) {
],
modules: false,
targets: {
esmodules: true,
esmodules: isModule,
},
},
],
Expand All @@ -116,7 +117,7 @@ function configure(pkg, env, target) {
? {}
: {
regenerator: false,
useESModules: true,
useESModules: isModule,
},
],
'@babel/plugin-proposal-class-properties',
Expand Down Expand Up @@ -147,17 +148,12 @@ function configure(pkg, env, target) {
}
}

if (isModule) {
if (isCommonJs) {
return {
plugins,
input,
onwarn,
output: [
{
file: `packages/${pkg.name}/${pkg.module}`,
format: 'es',
sourcemap: true,
},
{
file: `packages/${pkg.name}/${pkg.main}`,
format: 'cjs',
Expand All @@ -173,6 +169,27 @@ function configure(pkg, env, target) {
},
}
}

if (isModule) {
return {
plugins,
input,
onwarn,
output: [
{
file: `packages/${pkg.name}/${pkg.module}`,
format: 'es',
sourcemap: true,
}
],
// We need to explicitly state which modules are external, meaning that
// they are present at runtime. In the case of non-UMD configs, this means
// all non-Slate packages.
external: id => {
return !!deps.find(dep => dep === id || id.startsWith(`${dep}/`))
},
}
}
}

/**
Expand All @@ -182,6 +199,7 @@ function configure(pkg, env, target) {
function factory(pkg, options = {}) {
const isProd = process.env.NODE_ENV === 'production'
return [
configure(pkg, 'development', 'cjs', options),
configure(pkg, 'development', 'module', options),
isProd && configure(pkg, 'development', 'umd', options),
isProd && configure(pkg, 'production', 'umd', options),
Expand Down
6 changes: 6 additions & 0 deletions docs/Summary.md
Expand Up @@ -32,6 +32,12 @@
- [Refs](./api/refs.md)
- [Miscellaneous](./api/miscellaneous.md)

## Libraries

- [Slate React](./libraries/slate-react.md)
- [Slate History](./libraries/slate-history.md)
- [Slate Hyperscript](./libraries/slate-hyperscript.md)

## General

- [Resources](./general/resources.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/locations.md
Expand Up @@ -28,7 +28,7 @@ type Path = number[]
interface Point {
path: Path
offset: number
[key: string]: any
[key: string]: unknown
}
```

Expand Down Expand Up @@ -68,7 +68,7 @@ Options: `{affinity?: 'forward' | 'backward' | null}`
interface Range {
anchor: Point
focus: Point
[key: string]: any
[key: string]: unknown
}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/api/nodes.md
Expand Up @@ -123,7 +123,7 @@ interface Editor {
selection: Range | null
operations: Operation[]
marks: Record<string, any> | null
[key: string]: any
[key: string]: unknown

// Schema-specific node behaviors.
isInline: (element: Element) => boolean
Expand Down Expand Up @@ -212,7 +212,7 @@ Apply an operation in the editor.
```typescript
interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
```

Expand All @@ -237,7 +237,7 @@ Check if an element matches a set of `props`. Note: This checks custom propertie
```typescript
interface Text {
text: string,
[key: string]: any
[key: string]: unknown
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/01-interfaces.md
Expand Up @@ -5,7 +5,7 @@ Slate works with pure JSON objects. All it requires is that those JSON objects c
```ts
interface Text {
text: string
[key: string]: any
[key: string]: unknown
}
```

Expand All @@ -22,7 +22,7 @@ To take another example, the `Element` node interface in Slate is:
```ts
interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/concepts/02-nodes.md
Expand Up @@ -55,7 +55,7 @@ Elements make up the middle layers of a richtext document. They are the nodes th
```ts
interface Element {
children: Node[]
[key: string]: any
[key: string]: unknown
}
```

Expand Down Expand Up @@ -107,7 +107,7 @@ But in certain cases, like for links, you might want to make them "inline" flowi
You can define which nodes are treated as inline nodes by overriding the `editor.isInline` function. (By default it always returns `false`.) Note that inline nodes cannot be the first or last child of a parent block, nor can it be next to another inline node in the children array. Slate will automatically space these with `{ text: '' }` children by default with [`normalizeNode`](https://docs.slatejs.org/concepts/10-normalizing#built-in-constraints).

Elements can either contain block elements as children. Or they can contain inline elements intermingled with text nodes as children. But elements **cannot** contain some children that are blocks and some that are inlines.
Elements can either contain block elements or inline elements intermingled with text nodes as children. But elements **cannot** contain some children that are blocks and some that are inlines.

## Voids

Expand All @@ -126,7 +126,7 @@ Text nodes are the lowest-level nodes in the tree, containing the text content o
```ts
interface Text {
text: string
[key: string]: any
[key: string]: unknown
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/03-locations.md
Expand Up @@ -37,7 +37,7 @@ Points are slightly more specific than paths, and contain an `offset` into a spe
interface Point {
path: Path
offset: number
[key: string]: any
[key: string]: unknown
}
```

Expand Down Expand Up @@ -71,7 +71,7 @@ Ranges are a way to refer not just to a single point in the document, but to a w
interface Range {
anchor: Point
focus: Point
[key: string]: any
[key: string]: unknown
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/06-editor.md
Expand Up @@ -8,7 +8,7 @@ interface Editor {
selection: Range | null
operations: Operation[]
marks: Record<string, any> | null
[key: string]: any
[key: string]: unknown

// Schema-specific node behaviors.
isInline: (element: Element) => boolean
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/07-plugins.md
Expand Up @@ -11,7 +11,7 @@ const withImages = editor => {
const { isVoid } = editor

editor.isVoid = element => {
return element.type === 'image' ? true : isVoid(editor)
return element.type === 'image' ? true : isVoid(element)
}

return editor
Expand Down
3 changes: 2 additions & 1 deletion docs/general/resources.md
Expand Up @@ -20,6 +20,7 @@ These products use Slate, and can give you an idea of what's possible:
- [Grafana](https://grafana.com/)
- [Guilded](https://www.guilded.gg)
- [Guru](https://www.getguru.com/)
- [Kitemaker](https://kitemaker.co)
- [Netlify CMS](https://www.netlifycms.org)
- [Outline](https://www.getoutline.com/)
- [Prezly](https://www.prezly.com/)
Expand All @@ -33,7 +34,7 @@ These products use Slate, and can give you an idea of what's possible:

These pre-packaged editors are built on top of Slate, and can be helpful to see how you might structure your code:

- [Accord Project Markdown Editor](https://github.com/accordproject/markdown-editor/) is a WYSIWYG editor for [CommonMark](https://commonmark.org/).
- [Accord Project Markdown Editor](https://github.com/accordproject/web-components) is a WYSIWYG editor for [CommonMark](https://commonmark.org/).
- [Canner Editor](https://github.com/Canner/canner-slate-editor) is a rich text editor.
- [Chatterslate](https://github.com/chatterbugapp/chatterslate) helps teach language grammar and more at [Chatterbug](https://chatterbug.com).
- [French Press Editor](https://github.com/roast-cms/french-press-editor) is a customizeable editor with offline support.
Expand Down
15 changes: 15 additions & 0 deletions docs/libraries/slate-history.md
@@ -0,0 +1,15 @@
# Slate History

This sub-library tracks changes to the Slate value state over time, and enables undo and redo functionality.

## `History`

`History` objects hold all of the operations that are applied to a value, so they can be undone or redone as necessary.

## `HistoryEditor`

`HistoryEditor` contains helpers for history-enabled editors.

## `withHistory`

The `withHistory` plugin keeps track of the operation history of a Slate editor as operations are applied to it, using undo and redo stacks.
3 changes: 3 additions & 0 deletions docs/libraries/slate-hyperscript.md
@@ -0,0 +1,3 @@
# Slate Hyperscript

This package contains a hyperscript helper for creating Slate documents with JSX!

0 comments on commit 2d58cb0

Please sign in to comment.