Skip to content

Commit

Permalink
Making DraftBlockType less restrictive
Browse files Browse the repository at this point in the history
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
  • Loading branch information
midas19910709 committed Nov 2, 2017
1 parent d78d4ab commit 5612b30
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/model/constants/DraftBlockType.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* The list of default valid block types.
*/
export type DraftBlockType =
export type CoreDraftBlockType =
| 'unstyled'
| 'paragraph'
| 'header-one'
Expand All @@ -30,3 +30,10 @@ export type DraftBlockType =
| 'blockquote'
| 'code-block'
| 'atomic';

/**
* User defined types can be of any valid string.
*/
export type CustomBlockType = string;

export type DraftBlockType = CoreDraftBlockType | CustomBlockType;
2 changes: 1 addition & 1 deletion src/model/immutable/ContentBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {List, Map, OrderedSet, Record, Repeat} = Immutable;
const EMPTY_SET = OrderedSet();

type ContentBlockConfig = {
key?: string,
key?: DraftBlockType,
type?: string,
text?: string,
characterList?: List<CharacterMetadata>,
Expand Down
10 changes: 8 additions & 2 deletions src/model/immutable/DefaultDraftBlockRenderMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@

'use strict';

import type {DraftBlockRenderMap} from 'DraftBlockRenderMap';
import type {DraftBlockRenderConfig} from 'DraftBlockRenderConfig';
import type {CoreDraftBlockType} from 'DraftBlockType';

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

const cx = require('cx');

type DefaultCoreDraftBlockRenderMap = Map<
CoreDraftBlockType,
DraftBlockRenderConfig,
>;

const UL_WRAP = <ul className={cx('public/DraftStyleDefault/ul')} />;
const OL_WRAP = <ol className={cx('public/DraftStyleDefault/ol')} />;
const PRE_WRAP = <pre className={cx('public/DraftStyleDefault/pre')} />;

const DefaultDraftBlockRenderMap: DraftBlockRenderMap = Map({
const DefaultDraftBlockRenderMap: DefaultCoreDraftBlockRenderMap = Map({
'header-one': {
element: 'h1',
},
Expand Down
6 changes: 4 additions & 2 deletions src/model/immutable/DraftBlockRenderMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
'use strict';

import type {DraftBlockRenderConfig} from 'DraftBlockRenderConfig';
import type {DraftBlockType} from 'DraftBlockType';
import type {Map} from 'immutable';

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

0 comments on commit 5612b30

Please sign in to comment.