UNPKG

@atlaskit/editor-plugin-status

Version:

Status plugin for @atlaskit/editor-core

21 lines 754 B
import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; const MAX_STATUS_TURN_INTO_CHARS = 30; const SUPPORTED_SOURCE_TYPES = new Set(['paragraph', 'heading']); const getTurnIntoStatusSourceNode = selection => { if (!selection || !(selection instanceof NodeSelection)) { return null; } return selection.node; }; export const canTurnIntoStatus = node => { if (!node || !SUPPORTED_SOURCE_TYPES.has(node.type.name)) { return false; } for (let i = 0; i < node.childCount; i++) { if (!node.child(i).isText) { return false; } } return node.textContent.trim().length <= MAX_STATUS_TURN_INTO_CHARS; }; export const isStatusTurnIntoHidden = selection => !canTurnIntoStatus(getTurnIntoStatusSourceNode(selection));