UNPKG

prism-react-editor

Version:

Lightweight, extensible code editor component for React apps

83 lines (82 loc) 3.32 kB
import { l as languageMap } from "./core-Dm5I6BkG.js"; import { n as getClosestToken, h as getLineBefore, o as voidTags } from "./local-Cq-4Fajb.js"; const space = "(?:\\s|//.*(?!.)|/\\*(?:[^*]|\\*(?!/))*\\*/)"; const braces = "\\{(?:[^{}]|\\{(?:[^{}]|\\{(?:[^{}]|\\{[^}]*\\})*\\})*\\})*\\}"; const clikeIndent = /[([{][^)\]}]*$|^[^.]*\b(?:case .+?|default):\s*$/; const isBracketPair = /\[]|\(\)|{}/; const xmlOpeningTag = /<(?![\d?!#@])([^\s/=>$<%]+)(?:\s(?:\s*[^\s/"'=>]+(?:\s*=\s*(?!\s)(?:"[^"]*"|'[^']*'|[^\s"'=>]+(?=[\s>]))?|(?=[\s/>])))+)?\s*>[ \t]*$/; const xmlClosingTag = /^<\/(?!\d)[^\s/=>$<%]+\s*>/; const openBracket = /[([{][^)\]}]*$/; const astroOpeningTag = RegExp( `<(?:(?![\\d!])([^\\s%=<>/]+)(?:\\s(?:\\s*(?:[^\\s{=<>/]+(?:\\s*=\\s*(?!\\s)(?:"[^"]*"|'[^']*'|[^\\s{=<>/"']+(?=[\\s/>])|${braces})?|(?=[\\s/>]))|${braces}))*)?\\s*)?>[ \\t]*$` ); const testBracketPair = ([start, end], value) => { return isBracketPair.test(value[start - 1] + value[end]); }; const clikeComment = { line: "//", block: ["/*", "*/"] }; const isOpen = (match, voidTags2) => !!match && !voidTags2?.test(match[1]); const htmlAutoIndent = (tagPattern, voidTags2) => [ ([start], value) => isOpen(value.slice(0, start).match(tagPattern), voidTags2) || openBracket.test(getLineBefore(value, start)), (selection, value) => testBracketPair(selection, value) || isOpen(value.slice(0, selection[0]).match(tagPattern), voidTags2) && xmlClosingTag.test(value.slice(selection[1])) ]; const markupComment = { block: ["<!--", "-->"] }; const markupLanguage = (comment = markupComment, tagPattern = xmlOpeningTag, voidTags2) => ({ comments: comment, autoIndent: htmlAutoIndent(tagPattern, voidTags2), autoCloseTags: ([start, end], value, editor) => { return autoCloseTags(editor, start, end, value, tagPattern, voidTags2); } }); const autoCloseTags = (editor, start, end, value, tagPattern, voidTags2) => { if (start == end) { let match = tagPattern.exec(value.slice(0, start) + ">"); let tagMatcher = editor.extensions.matchTags; if (match && (match = match[1] || "", !voidTags2?.test(match))) { if (tagMatcher) { let { pairs, tags } = tagMatcher; for (let i = tags.length; i; ) { let tag = tags[--i]; if (tag[1] >= start && tag[4] && tag[5] && tag[3] == match && pairs[i] == null) { return; } } } return `</${match}>`; } } }; const bracketIndenting = (comments = clikeComment, indentPattern = openBracket) => ({ comments, autoIndent: [ ([start], value) => indentPattern.test(getLineBefore(value, start)), testBracketPair ] }); const markupTemplateLang = (name, comments) => languageMap[name] = { comments, autoIndent: htmlAutoIndent(xmlOpeningTag, voidTags), autoCloseTags: ([start, end], value, editor) => { return getClosestToken(editor, "." + name, 0, 0, start) ? "" : autoCloseTags(editor, start, end, value, xmlOpeningTag, voidTags); } }; export { clikeIndent as a, bracketIndenting as b, clikeComment as c, astroOpeningTag as d, markupComment as e, autoCloseTags as f, braces as g, htmlAutoIndent as h, markupTemplateLang as i, markupLanguage as m, space as s, testBracketPair as t, xmlOpeningTag as x }; //# sourceMappingURL=index-DsT2G8SO.js.map