import {OperateNodes} from '../editor' export const getMatchString = (str: string, matchStr: string) => { const current = matchStr.split('') let baseStr = str const sortArr: number[] = [] current.forEach((item, index) => { if (str.includes(item)) { sortArr.push(index) baseStr = baseStr.substr(1) } }) if (sortArr.length === current.length && justArrSort(sortArr)) { return true } } // 判断数组是否有序 export const justArrSort = (arr: number[]) => { return arr.toString() === arr.sort((a, b) => a - b).toString() } // 初始化编辑器的value export const initialValue = (t: string) => [ { type: 'paragraph', children: [{text: t || ''}], }, ] // 默认初始值 export const getInitialValue = (t: string, op: OperateNodes) => { // 多个内容选中 const isArray = Array.isArray(op.nodes) const isSingleArr = [ {text: `${op.isReply ? `${t} :` : ''}`}, {type: 'mention', character: op.nodes, children: [{text: ''}]}, {text: ' '}, ] const temp = isArray ? getInsertMulNodes(t, op) : isSingleArr return [ { type: 'paragraph', children: temp, }, ] } const getInsertMulNodes = (t: string, op: OperateNodes) => { const insertNodes: any[] = [] op.nodes.forEach((item: any) => { insertNodes.push({type: 'mention', character: item, children: [{text: ''}]}) insertNodes.push({text: ' '}) }) return insertNodes }