Skip to content

Commit 5d23912

Browse files
aforismesenfacebook-github-bot
authored andcommitted
Making DraftBlockType less restrictive
Summary: DraftBlockType needs to be less strict in order to allow user defined block types however we also want to retain a way to identify our core draft blocks. fixes: facebookarchive/draft-js#1453 Closes facebookarchive/draft-js#1480 Differential Revision: D6215628 fbshipit-source-id: e4647bf2bafe9adb7788740ec64c1445e307e632
1 parent df9cead commit 5d23912

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/model/constants/DraftBlockType.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* The list of default valid block types.
1818
*/
19-
export type DraftBlockType =
19+
export type CoreDraftBlockType =
2020
| 'unstyled'
2121
| 'paragraph'
2222
| 'header-one'
@@ -30,3 +30,10 @@ export type DraftBlockType =
3030
| 'blockquote'
3131
| 'code-block'
3232
| 'atomic';
33+
34+
/**
35+
* User defined types can be of any valid string.
36+
*/
37+
export type CustomBlockType = string;
38+
39+
export type DraftBlockType = CoreDraftBlockType | CustomBlockType;

src/model/immutable/ContentBlock.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const {List, Map, OrderedSet, Record, Repeat} = Immutable;
2626
const EMPTY_SET = OrderedSet();
2727

2828
type ContentBlockConfig = {
29-
key?: string,
29+
key?: DraftBlockType,
3030
type?: string,
3131
text?: string,
3232
characterList?: List<CharacterMetadata>,

src/model/immutable/DefaultDraftBlockRenderMap.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@
1313

1414
'use strict';
1515

16-
import type {DraftBlockRenderMap} from 'DraftBlockRenderMap';
16+
import type {DraftBlockRenderConfig} from 'DraftBlockRenderConfig';
17+
import type {CoreDraftBlockType} from 'DraftBlockType';
1718

1819
const {Map} = require('immutable');
1920
const React = require('React');
2021

2122
const cx = require('cx');
2223

24+
type DefaultCoreDraftBlockRenderMap = Map<
25+
CoreDraftBlockType,
26+
DraftBlockRenderConfig,
27+
>;
28+
2329
const UL_WRAP = <ul className={cx('public/DraftStyleDefault/ul')} />;
2430
const OL_WRAP = <ol className={cx('public/DraftStyleDefault/ol')} />;
2531
const PRE_WRAP = <pre className={cx('public/DraftStyleDefault/pre')} />;
2632

27-
const DefaultDraftBlockRenderMap: DraftBlockRenderMap = Map({
33+
const DefaultDraftBlockRenderMap: DefaultCoreDraftBlockRenderMap = Map({
2834
'header-one': {
2935
element: 'h1',
3036
},

src/model/immutable/DraftBlockRenderMap.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
'use strict';
1515

1616
import type {DraftBlockRenderConfig} from 'DraftBlockRenderConfig';
17-
import type {DraftBlockType} from 'DraftBlockType';
1817
import type {Map} from 'immutable';
1918

20-
export type DraftBlockRenderMap = Map<DraftBlockType, DraftBlockRenderConfig>;
19+
// We should be able to be more specific on the key type
20+
// once we upgrade to immutable v4
21+
// https://github.com/facebook/immutable-js/issues/1371
22+
export type DraftBlockRenderMap = Map<any, DraftBlockRenderConfig>;

0 commit comments

Comments
 (0)