Skip to content

Commit 342576b

Browse files
Isaac Salier-Hellendagzpao
authored andcommitted
Open source Draft.js 🎉
0 parents  commit 342576b

293 files changed

Lines changed: 33008 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
lib/
2+
dist/
3+
docs/
4+
examples/
5+
node_modules/
6+
website/

‎.eslintrc.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
module.exports = {
3+
parser: 'babel-eslint',
4+
5+
extends: './node_modules/fbjs-scripts/eslint/.eslintrc.js',
6+
7+
plugins: [
8+
'react',
9+
],
10+
11+
rules: {
12+
'react/jsx-uses-react': 1,
13+
'react/react-in-jsx-scope': 1,
14+
}
15+
};

‎.gitignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/dist/
2+
/lib/
3+
/node_modules/
4+
/examples/tex/node_modules/
5+
/website/build/
6+
/website/node_modules/
7+
/website/src/draft-js/lib/
8+
npm-debug.log

‎.travis.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
node_js:
3+
- 5
4+
sudo: false
5+
cache:
6+
directories:
7+
- node_modules
8+
before_install:
9+
- |
10+
npm install -g npm@latest-2
11+
npm --version
12+
script:
13+
- |
14+
npm test

‎CONTRIBUTING.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing to Draft.js
2+
We want to make contributing to this project as easy and transparent as
3+
possible.
4+
5+
## Our Development Process
6+
We use GitHub to sync code to and from our internal repository. We'll use GitHub
7+
to track issues and feature requests, as well as accept pull requests.
8+
9+
## Pull Requests
10+
We actively welcome your pull requests.
11+
12+
1. Fork the repo and create your branch from `master`.
13+
2. If you've added code that should be tested, add tests.
14+
3. If you've changed APIs, update the documentation.
15+
4. Ensure the test suite passes.
16+
5. Make sure your code lints.
17+
6. If you haven't already, complete the Contributor License Agreement ("CLA").
18+
19+
## Contributor License Agreement ("CLA")
20+
In order to accept your pull request, we need you to submit a CLA. You only need
21+
to do this once to work on any of Facebook's open source projects.
22+
23+
Complete your CLA here: <https://code.facebook.com/cla>
24+
25+
## Issues
26+
We use GitHub issues to track public bugs. Please ensure your description is
27+
clear and has sufficient instructions to be able to reproduce the issue.
28+
29+
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
30+
disclosure of security bugs. In those cases, please go through the process
31+
outlined on that page and do not file a public issue.
32+
33+
## Coding Style
34+
* 2 spaces for indentation rather than tabs
35+
* 80 character line length
36+
* Run `npm run lint` to conform to our lint rules
37+
38+
## License
39+
By contributing to Draft.js, you agree that your contributions will be licensed
40+
under its BSD license.

‎LICENSE‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BSD License
2+
3+
For Draft.js software
4+
5+
Copyright (c) 2013-present, Facebook, Inc.
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without modification,
9+
are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright notice, this
12+
list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
* Neither the name Facebook nor the names of its contributors may be used to
19+
endorse or promote products derived from this software without specific
20+
prior written permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

‎LICENSE-examples‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright (c) 2013-present, Facebook, Inc. All rights reserved.
2+
3+
The examples provided by Facebook are for non-commercial testing and evaluation
4+
purposes only. Facebook reserves all rights not expressly granted.
5+
6+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
9+
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
10+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
11+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎PATENTS‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Additional Grant of Patent Rights Version 2
2+
3+
"Software" means the Draft.js software distributed by Facebook, Inc.
4+
5+
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
6+
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
7+
(subject to the termination provision below) license under any Necessary
8+
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
9+
transfer the Software. For avoidance of doubt, no license is granted under
10+
Facebook's rights in any patent claims that are infringed by (i) modifications
11+
to the Software made by you or any third party or (ii) the Software in
12+
combination with any software or other technology.
13+
14+
The license granted hereunder will terminate, automatically and without notice,
15+
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
16+
directly or indirectly, or take a direct financial interest in, any Patent
17+
Assertion: (i) against Facebook or any of its subsidiaries or corporate
18+
affiliates, (ii) against any party if such Patent Assertion arises in whole or
19+
in part from any software, technology, product or service of Facebook or any of
20+
its subsidiaries or corporate affiliates, or (iii) against any party relating
21+
to the Software. Notwithstanding the foregoing, if Facebook or any of its
22+
subsidiaries or corporate affiliates files a lawsuit alleging patent
23+
infringement against you in the first instance, and you respond by filing a
24+
patent infringement counterclaim in that lawsuit against that party that is
25+
unrelated to the Software, the license granted hereunder will not terminate
26+
under section (i) of this paragraph due to such counterclaim.
27+
28+
A "Necessary Claim" is a claim of a patent owned by Facebook that is
29+
necessarily infringed by the Software standing alone.
30+
31+
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
32+
or contributory infringement or inducement to infringe any patent, including a
33+
cross-claim or counterclaim.

‎README.md‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# [Draft.js](https://facebook.github.io/draft-js/)
2+
3+
Draft.js is a JavaScript rich text editor framework, built for React and
4+
backed by an immutable model.
5+
6+
- **Extensible and Customizable:** We provide the building blocks to enable
7+
the creation of a broad variety of rich text composition experiences, from
8+
simple text styles to embedded media.
9+
- **Declarative Rich Text:** Draft.js fits seamlessly into
10+
[React](http://facebook.github.io/react/) applications,
11+
abstracting away the details of rendering, selection, and input behavior with a
12+
familiar declarative API.
13+
- **Immutable Editor State:** The Draft.js model is built
14+
with [immutable-js](https://facebook.github.io/immutable-js/), offering
15+
an API with functional state updates and aggressively leveraging data persistence
16+
for scalable memory usage.
17+
18+
[Learn how to use Draft.js in your own project.](https://facebook.github.io/draft-js/docs/quickstart-getting-started.html)
19+
20+
## Examples
21+
22+
Visit https://facebook.github.io/draft-js/ to try out a simple rich editor example.
23+
24+
The repository includes a variety of different editor examples to demonstrate
25+
some of the features offered by the framework.
26+
27+
To run the examples, first build Draft.js locally:
28+
29+
```
30+
git clone https://github.com/facebook/draft-js.git
31+
cd draft-js
32+
npm install
33+
npm run build
34+
```
35+
36+
then open the example HTML files in your browser.
37+
38+
Draft.js is used in production on Facebook, including status and
39+
comment inputs, [Notes](https://www.facebook.com/notes/), and
40+
[messenger.com](https://www.messenger.com).
41+
42+
## Contribute
43+
44+
We actively welcome pull requests. Learn how to
45+
[contribute](https://github.com/facebook/draft-js/blob/master/CONTRIBUTING.md).
46+
47+
## License
48+
49+
Draft.js is [BSD Licensed](https://github.com/facebook/draft-js/blob/master/LICENSE).
50+
We also provide an additional [patent grant](https://github.com/facebook/draft-js/blob/master/PATENTS).
51+
52+
Examples provided in this repository and in the documentation are separately
53+
licensed.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
id: api-reference-character-metadata
3+
title: CharacterMetadata
4+
layout: docs
5+
category: API Reference
6+
next: api-reference-entity
7+
permalink: docs/api-reference-character-metadata.html
8+
---
9+
10+
`CharacterMetadata` is an Immutable
11+
[Record](http://facebook.github.io/immutable-js/docs/#/Record/Record) that
12+
represents inline style and entity information for a single character.
13+
14+
`CharacterMetadata` objects are aggressively pooled and shared. If two characters
15+
have the same inline style and entity, they are represented with the same
16+
`CharacterMetadata` object. We therefore need only as many objects as combinations
17+
of utilized inline style sets with entity keys, keeping our memory footprint
18+
small even as the contents grow in size and complexity.
19+
20+
To that end, you should create or apply changes to `CharacterMetadata` objects
21+
via the provided set of static methods, which will ensure that pooling is utilized.
22+
23+
Most Draft use cases are unlikely to use these static methods, since most common edit
24+
operations are already implemented and available via utility modules. The getter
25+
methods, however, may come in handy at render time.
26+
27+
See the API reference on
28+
[ContentBlock](/draft-js/docs/api-reference-content-block.html#representing-styles-and-entities)
29+
for information on how `CharacterMetadata` is used within `ContentBlock`.
30+
31+
## Overview
32+
33+
*Static Methods*
34+
35+
<ul class="apiIndex">
36+
<li>
37+
<a href="#create">
38+
<pre>static create(...): CharacterMetadata</pre>
39+
</a>
40+
</li>
41+
<li>
42+
<a href="#applystyle">
43+
<pre>static applyStyle(...): CharacterMetadata</pre>
44+
</a>
45+
</li>
46+
<li>
47+
<a href="#removestyle">
48+
<pre>static removeStyle(...): CharacterMetadata</pre>
49+
</a>
50+
</li>
51+
<li>
52+
<a href="#applyentity">
53+
<pre>static applyEntity(...): CharacterMetadata</pre>
54+
</a>
55+
</li>
56+
</ul>
57+
58+
*Methods*
59+
60+
<ul class="apiIndex">
61+
<li>
62+
<a href="#getstyle">
63+
<pre>getStyle(): DraftInlineStyle</pre>
64+
</a>
65+
</li>
66+
<li>
67+
<a href="#hasstyle">
68+
<pre>hasStyle(style: string): boolean</pre>
69+
</a>
70+
</li>
71+
<li>
72+
<a href="#getentity">
73+
<pre>getEntity(): ?string</pre>
74+
</a>
75+
</li>
76+
</ul>
77+
78+
## Static Methods
79+
80+
Under the hood, these methods will utilize pooling to return a matching object,
81+
or return a new object if none exists.
82+
83+
### create
84+
85+
```
86+
static create(config?: CharacterMetadataConfig): CharacterMetadata
87+
```
88+
Generates a `CharacterMetadata` object from the provided configuration. This
89+
function should be used in lieu of a constructor.
90+
91+
The configuration will be used to check whether a pooled match for this
92+
configuration already exists. If so, the pooled object will be returned.
93+
Otherwise, a new `CharacterMetadata` will be pooled for this configuration,
94+
and returned.
95+
96+
### applyStyle
97+
98+
```
99+
static applyStyle(
100+
record: CharacterMetadata,
101+
style: string
102+
): CharacterMetadata
103+
```
104+
Apply an inline style to this `CharacterMetadata`.
105+
106+
### removeStyle
107+
108+
```
109+
static removeStyle(
110+
record: CharacterMetadata,
111+
style: string
112+
): CharacterMetadata
113+
```
114+
Remove an inline style from this `CharacterMetadata`.
115+
116+
### applyEntity
117+
118+
```
119+
static applyEntity(
120+
record: CharacterMetadata,
121+
entityKey: ?string
122+
): CharacterMetadata
123+
```
124+
125+
Apply an entity key -- or provide `null` to remove an entity key -- on this
126+
`CharacterMetadata`.
127+
128+
## Methods
129+
130+
### getStyle
131+
132+
```
133+
getStyle(): DraftInlineStyle
134+
```
135+
Returns the `DraftInlineStyle` for this character, an `OrderedSet` of strings
136+
that represents the inline style to apply for the character at render time.
137+
138+
### hasStyle
139+
140+
```
141+
hasStyle(style: string): boolean
142+
```
143+
Returns whether this character has the specified style.
144+
145+
### getEntity
146+
147+
```
148+
getEntity(): ?string
149+
```
150+
Returns the entity key (if any) for this character, as mapped to the global set of
151+
entities tracked by the [`Entity`](https://github.com/facebook/draft-js/blob/master/src/model/entity/DraftEntity.js)
152+
module.
153+
154+
By tracking a string key here, we can keep the corresponding metadata separate
155+
from the character representation.
156+
157+
If null, no entity is applied for this character.

0 commit comments

Comments
 (0)