From f4c918ce7c53c9492dfa968020a3517e952d66fd Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Fri, 25 Jan 2019 10:45:53 +0200 Subject: [PATCH] fix(api): allow entities to only provide a type attr in Flow types --- README.md | 7 ++++--- src/lib/filters/editor.js | 7 ++++--- src/lib/filters/entities.js | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7d15e6ab..3d153659 100644 --- a/README.md +++ b/README.md @@ -69,12 +69,13 @@ styles: $ReadOnlyArray, entities: $ReadOnlyArray<{ // Entity type, eg. "LINK" type: string, - // Allowed attributes. Other attributes will be removed. - attributes: $ReadOnlyArray, + // Allowed attributes. Other attributes will be removed. If this is omitted, all attributes are kept. + attributes?: $ReadOnlyArray, // Refine which entities are kept by whitelisting acceptable values with regular expression patterns. // It's also possible to use "true" to signify that a field is required to be present, // and "false" for fields required to be absent. - whitelist: { + // If this is omitted, all entities are kept. + whitelist?: { [attribute: string]: string | boolean, }, }>, diff --git a/src/lib/filters/editor.js b/src/lib/filters/editor.js index a6e15677..0e761552 100644 --- a/src/lib/filters/editor.js +++ b/src/lib/filters/editor.js @@ -35,12 +35,13 @@ type FilterOptions = { entities: $ReadOnlyArray<{ // Entity type, eg. "LINK" type: string, - // Allowed attributes. Other attributes will be removed. - attributes: $ReadOnlyArray, + // Allowed attributes. Other attributes will be removed. If this is omitted, all attributes are kept. + attributes?: $ReadOnlyArray, // Refine which entities are kept by whitelisting acceptable values with regular expression patterns. // It's also possible to use "true" to signify that a field is required to be present, // and "false" for fields required to be absent. - whitelist: { + // If this is omitted, all entities are kept. + whitelist?: { [attribute: string]: string | boolean, }, }>, diff --git a/src/lib/filters/entities.js b/src/lib/filters/entities.js index 44e205b6..0f9fc359 100644 --- a/src/lib/filters/entities.js +++ b/src/lib/filters/entities.js @@ -145,7 +145,7 @@ export const shouldRemoveImageEntity = ( export const shouldKeepEntityByAttribute = ( entityTypes: $ReadOnlyArray<{ type: string, - whitelist: { + whitelist?: { [attribute: string]: string | boolean, }, }>, @@ -179,7 +179,7 @@ export const shouldKeepEntityByAttribute = ( export const filterEntityData = ( entityTypes: $ReadOnlyArray<{ type: string, - attributes: $ReadOnlyArray, + attributes?: $ReadOnlyArray, }>, content: ContentState, ) => {