-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e034ba0
commit f4d9a19
Showing
12 changed files
with
847 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../.eslintrc.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [year] [fullname] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# `datocms-structured-text-slate-utils` | ||
|
||
A set of Typescript types and helpers to convert Structured Text dast to Slate structures. | ||
|
||
## Installation | ||
|
||
Using [npm](http://npmjs.org/): | ||
|
||
```sh | ||
npm install datocms-structured-text-slate-utils | ||
``` | ||
|
||
Using [yarn](https://yarnpkg.com/): | ||
|
||
```sh | ||
yarn add datocms-structured-text-slate-utils | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('datocms-structured-text-slate-utils', () => { | ||
describe('definitions', () => { | ||
it('are coherent', () => { | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "datocms-structured-text-slate-utils", | ||
"version": "1.2.0", | ||
"description": "A set of helpers to translate DatoCMS Structured Text fields into Slate structures", | ||
"keywords": [ | ||
"datocms", | ||
"structured-text" | ||
], | ||
"author": "Stefano Verna <[email protected]>", | ||
"homepage": "https://github.com/datocms/structured-text/tree/master/packages/datocms-structured-text-slate-utils#readme", | ||
"license": "MIT", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"typings": "dist/types/index.d.ts", | ||
"sideEffects": false, | ||
"directories": { | ||
"lib": "dist", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/datocms/structured-text.git" | ||
}, | ||
"scripts": { | ||
"build": "tsc && tsc --project ./tsconfig.esnext.json", | ||
"prebuild": "rimraf dist" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/datocms/structured-text/issues" | ||
}, | ||
"dependencies": { | ||
"datocms-structured-text-utils": "1.2.0", | ||
"lodash-es": "^4.17.21", | ||
"slate": "0.60.1" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash-es": "^4.17.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Node as SlateNode } from 'slate'; | ||
import { | ||
Block, | ||
blockDef, | ||
Blockquote, | ||
blockquoteDef, | ||
blockquoteSourceDef, | ||
Code, | ||
codeDef, | ||
Heading, | ||
headingDef, | ||
InlineItem, | ||
inlineItemDef, | ||
InlineNode, | ||
inlineNodes, | ||
ItemLink, | ||
itemLinkDef, | ||
Link, | ||
linkDef, | ||
List, | ||
listDef, | ||
ListItem, | ||
listItemDef, | ||
NonTextNode, | ||
Paragraph, | ||
paragraphDef, | ||
Text, | ||
ThematicBreak, | ||
thematicBreakDef, | ||
} from './types'; | ||
|
||
export const isNonTextNode = (node: SlateNode): node is NonTextNode => | ||
'type' in node; | ||
|
||
export const isText = (node: SlateNode): node is Text => | ||
!isNonTextNode(node) && 'text' in node; | ||
|
||
export const isThematicBreak = ( | ||
element: NonTextNode, | ||
): element is ThematicBreak => element.type === thematicBreakDef.type; | ||
|
||
export const isParagraph = (element: NonTextNode): element is Paragraph => | ||
element.type === paragraphDef.type; | ||
|
||
export const isBlockquoteSource = ( | ||
element: NonTextNode, | ||
): element is Paragraph => element.type === blockquoteSourceDef.type; | ||
|
||
export const isHeading = (element: NonTextNode): element is Heading => | ||
element.type === headingDef.type; | ||
|
||
export const isLink = (element: NonTextNode): element is Link => | ||
element.type === linkDef.type; | ||
|
||
export const isItemLink = (element: NonTextNode): element is ItemLink => | ||
element.type === itemLinkDef.type; | ||
|
||
export const isInlineItem = (element: NonTextNode): element is InlineItem => | ||
element.type === inlineItemDef.type; | ||
|
||
export const isBlock = (element: NonTextNode): element is Block => | ||
element.type === blockDef.type; | ||
|
||
export const isList = (element: NonTextNode): element is List => | ||
element.type === listDef.type; | ||
|
||
export const isListItem = (element: NonTextNode): element is ListItem => | ||
element.type === listItemDef.type; | ||
|
||
export const isBlockquote = (element: NonTextNode): element is Blockquote => | ||
element.type === blockquoteDef.type; | ||
|
||
export const isCode = (element: NonTextNode): element is Code => | ||
element.type === codeDef.type; | ||
|
||
export const isInlineNode = (element: NonTextNode): element is InlineNode => | ||
inlineNodes.map((def) => def.type).includes(element.type); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './slateToDast'; |
Oops, something went wrong.