-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RichText fields to allowedResources validation
- Loading branch information
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
export const MAX_ALLOWED_RESOURCES = 3 | ||
export const MAX_RESOURCE_LINKS = 3 | ||
|
||
export const RICH_TEXT_RESOURCE_LINK_NODES = ['embedded-resource-block'] | ||
|
||
export const isResourceLink = (field) => | ||
field.type === 'ResourceLink' || (field.type === 'Array' && field.items?.type === 'ResourceLink') | ||
|
||
export const getEnabledResourceLinkNodes = (field): string[] | undefined => { | ||
if (field.type !== 'RichText' || !Array.isArray(field.validations)) { | ||
return undefined | ||
} | ||
|
||
for (const { enabledNodeTypes } of field.validations) { | ||
if (Array.isArray(enabledNodeTypes)) { | ||
return RICH_TEXT_RESOURCE_LINK_NODES.filter((nodeType) => enabledNodeTypes.includes(nodeType)) | ||
} | ||
} | ||
} |