11<script setup lang="ts">
22import { computed , h , onMounted , ref , useAttrs , watch } from ' vue'
33import DOMPurify from ' isomorphic-dompurify'
4- import { useChildWithCursor , useCursorPosition } from ' ./composables'
4+ import { useChildWithCursor , useCursorPosition , useRecord } from ' ./composables'
55
66export interface Props {
77 text: string
@@ -21,26 +21,19 @@ const emit = defineEmits<{
2121}>()
2222
2323const attrs = useAttrs ()
24+ const record = useRecord ()
2425const input = ref <HTMLDivElement | null >(null )
2526const TEXT = computed (() => DOMPurify .sanitize (props .text ))
2627
27- function isStringRecord(value : typeof props .special ): value is Record <string , string | string []> {
28- return Object .values (value ).every (v => typeof v === ' string' || Array .isArray (v ))
29- }
30-
31- function isRegexRecord(value : typeof props .special ): value is Record <string , RegExp | RegExp []> {
32- return Object .values (value ).every (v => v instanceof RegExp || Array .isArray (v ))
33- }
34-
3528function styleSpecialValues() {
3629 let regex: RegExp | undefined
3730
38- if (isStringRecord (props .special )) {
31+ if (record . isString (props .special )) {
3932 const keys = Object .values (props .special ).flat ().sort ((a , b ) => b .length - a .length )
4033 const escapedKeys = keys .map (key => key .replace (/ [-\/\\ ^$*+?. ()|[\] {}] / g , ' \\ $&' ))
4134 regex = new RegExp (escapedKeys .join (' |' ), ' g' )
4235 }
43- else if (isRegexRecord (props .special )) {
36+ else if (record . isRegExp (props .special )) {
4437 const regexes = Object .values (props .special ).flat ().map (v => new RegExp (v .source ))
4538 regex = new RegExp (regexes .map (r => r .source ).join (' |' ), ' g' )
4639 }
0 commit comments