From 6459f32a561b8ec14a12b9fef7e5555bec768856 Mon Sep 17 00:00:00 2001 From: mitermayer Date: Wed, 1 Nov 2017 14:04:37 -0700 Subject: [PATCH 1/3] Making DraftBlockType less restrictive - Making DraftBlockType less restrictive and allowing to distinguish between internal types and custom user types --- src/model/constants/DraftBlockType.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; From be51e0ab3048612f05cc57c3383eabe64cb133ae Mon Sep 17 00:00:00 2001 From: mitermayer Date: Wed, 1 Nov 2017 14:43:13 -0700 Subject: [PATCH 2/3] Adding back the correct type for ContentBlock - While landing "" I had to change the type of ContentBlock key from DraftBlockType to string to avoid internal conflicts, but due to the new less strict typing we can revert it back --- src/model/immutable/ContentBlock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From ab5f52b7f1cce0d516d3c5e07d4035d7298c69e7 Mon Sep 17 00:00:00 2001 From: mitermayer Date: Wed, 1 Nov 2017 14:59:50 -0700 Subject: [PATCH 3/3] Adding specific typing for DefaultDraftBlockRenderMap to retain core block types inference - Making sure DefaultDraftBlockRenderMap still references the internal supported block types --- src/model/immutable/DefaultDraftBlockRenderMap.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/model/immutable/DefaultDraftBlockRenderMap.js b/src/model/immutable/DefaultDraftBlockRenderMap.js index 0d00b51b2c..cf5d3ccfe8 100644 --- a/src/model/immutable/DefaultDraftBlockRenderMap.js +++ b/src/model/immutable/DefaultDraftBlockRenderMap.js @@ -13,18 +13,23 @@ 'use strict'; -import type {DraftBlockRenderMap} from 'DraftBlockRenderMap'; - const {Map} = require('immutable'); const React = require('React'); - const cx = require('cx'); +import type {CoreDraftBlockType} from 'DraftBlockType'; +import type {DraftBlockRenderConfig} from 'DraftBlockRenderConfig'; + +type DefaultCoreDraftBlockRenderMap = Map< + CoreDraftBlockType, + DraftBlockRenderConfig, +>; + const UL_WRAP =
    ; const OL_WRAP =
      ; const PRE_WRAP =
      ;
       
      -const DefaultDraftBlockRenderMap: DraftBlockRenderMap = Map({
      +const DefaultDraftBlockRenderMap: DefaultCoreDraftBlockRenderMap = Map({
         'header-one': {
           element: 'h1',
         },