From b0f00ffa58e9a56dd4c164b9c2b4fefbdf8b9e88 Mon Sep 17 00:00:00 2001 From: mitermayer Date: Wed, 1 Nov 2017 22:19:15 -0700 Subject: [PATCH] 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: https://github.com/facebook/draft-js/issues/1453 Closes https://github.com/facebook/draft-js/pull/1480 Differential Revision: D6215628 fbshipit-source-id: e4647bf2bafe9adb7788740ec64c1445e307e632 --- src/model/constants/DraftBlockType.js | 9 ++++++++- src/model/immutable/ContentBlock.js | 2 +- src/model/immutable/DefaultDraftBlockRenderMap.js | 10 ++++++++-- src/model/immutable/DraftBlockRenderMap.js | 6 ++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/model/constants/DraftBlockType.js b/src/model/constants/DraftBlockType.js index 83cba61916..3f27bbfdff 100644 --- a/src/model/constants/DraftBlockType.js +++ b/src/model/constants/DraftBlockType.js @@ -16,7 +16,7 @@ /** * The list of default valid block types. */ -export type DraftBlockType = +export type CoreDraftBlockType = | 'unstyled' | 'paragraph' | 'header-one' @@ -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; diff --git a/src/model/immutable/ContentBlock.js b/src/model/immutable/ContentBlock.js index 32ba9f1b15..c0034b6be9 100644 --- a/src/model/immutable/ContentBlock.js +++ b/src/model/immutable/ContentBlock.js @@ -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, diff --git a/src/model/immutable/DefaultDraftBlockRenderMap.js b/src/model/immutable/DefaultDraftBlockRenderMap.js index 0d00b51b2c..db7abd3ea0 100644 --- a/src/model/immutable/DefaultDraftBlockRenderMap.js +++ b/src/model/immutable/DefaultDraftBlockRenderMap.js @@ -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 =