@actualwave/react-native-codeditor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +790 -0
- package/app.plugin.js +133 -0
- package/lib/module/BlockingView.js +25 -0
- package/lib/module/CodeEditor.js +239 -0
- package/lib/module/EditorAPI.js +2 -0
- package/lib/module/WebViewAPI.js +133 -0
- package/lib/module/index.js +6 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/app.plugin.d.ts +3 -0
- package/lib/typescript/babel.config.d.ts +10 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/react-native.config.d.ts +2 -0
- package/lib/typescript/scripts/copy-assets.d.ts +2 -0
- package/lib/typescript/src/BlockingView.d.ts +3 -0
- package/lib/typescript/src/CodeEditor.d.ts +33 -0
- package/lib/typescript/src/EditorAPI.d.ts +66 -0
- package/lib/typescript/src/WebViewAPI.d.ts +46 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/package.json +106 -0
- package/react-native.config.js +3 -0
- package/src/assets/codemirror/@actualwave_codemirror-lang-sksl.js +15 -0
- package/src/assets/codemirror/@babel_runtime_helpers_interopRequireDefault.js +1 -0
- package/src/assets/codemirror/@babel_runtime_helpers_objectSpread2.js +1 -0
- package/src/assets/codemirror/@babel_runtime_helpers_toConsumableArray.js +1 -0
- package/src/assets/codemirror/@codemirror_autocomplete.js +206 -0
- package/src/assets/codemirror/@codemirror_collab.js +31 -0
- package/src/assets/codemirror/@codemirror_commands.js +411 -0
- package/src/assets/codemirror/@codemirror_lang-angular.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-cpp.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-css.js +14 -0
- package/src/assets/codemirror/@codemirror_lang-go.js +13 -0
- package/src/assets/codemirror/@codemirror_lang-html.js +20 -0
- package/src/assets/codemirror/@codemirror_lang-java.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-javascript.js +54 -0
- package/src/assets/codemirror/@codemirror_lang-jinja.js +15 -0
- package/src/assets/codemirror/@codemirror_lang-json.js +10 -0
- package/src/assets/codemirror/@codemirror_lang-less.js +10 -0
- package/src/assets/codemirror/@codemirror_lang-lezer.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-liquid.js +15 -0
- package/src/assets/codemirror/@codemirror_lang-markdown.js +55 -0
- package/src/assets/codemirror/@codemirror_lang-php.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-python.js +19 -0
- package/src/assets/codemirror/@codemirror_lang-rust.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-sass.js +10 -0
- package/src/assets/codemirror/@codemirror_lang-sql.js +52 -0
- package/src/assets/codemirror/@codemirror_lang-vue.js +6 -0
- package/src/assets/codemirror/@codemirror_lang-wast.js +2 -0
- package/src/assets/codemirror/@codemirror_lang-xml.js +13 -0
- package/src/assets/codemirror/@codemirror_lang-yaml.js +13 -0
- package/src/assets/codemirror/@codemirror_language-data.js +5 -0
- package/src/assets/codemirror/@codemirror_language.js +524 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_apl.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_asciiarmor.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_asn1.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_asterisk.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_brainfuck.js +13 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_clike.js +31 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_clojure.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_cmake.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_cobol.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_coffeescript.js +14 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_commonlisp.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_crystal.js +18 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_css.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_cypher.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_d.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_diff.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_dockerfile.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_dtd.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_dylan.js +35 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ebnf.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ecl.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_eiffel.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_elm.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_erlang.js +52 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_factor.js +14 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_fcl.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_forth.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_fortran.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_gas.js +13 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_gherkin.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_go.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_groovy.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_haskell.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_haxe.js +12 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_http.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_idl.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_javascript.js +23 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_jinja2.js +8 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_julia.js +17 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_livescript.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_lua.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mathematica.js +26 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mbox.js +11 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mirc.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mllike.js +8 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_modelica.js +12 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mscgen.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mumps.js +16 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_nginx.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_nsis.js +20 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ntriples.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_octave.js +8 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_oz.js +17 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pascal.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pegjs.js +25 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_perl.js +247 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pig.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_powershell.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_properties.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_protobuf.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pug.js +24 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_puppet.js +42 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_python.js +15 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_q.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_r.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_rpm.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ruby.js +4 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_rust.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sas.js +23 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sass.js +26 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_scheme.js +14 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_shell.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sieve.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_simple-mode.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_smalltalk.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_solr.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sparql.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_spreadsheet.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sql.js +84 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_stex.js +11 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_stylus.js +45 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_swift.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_tcl.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_textile.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_tiddlywiki.js +33 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_tiki.js +20 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_toml.js +4 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_troff.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ttcn-cfg.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ttcn.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_turtle.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_vb.js +11 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_vbscript.js +26 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_velocity.js +15 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_verilog.js +67 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_vhdl.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_wast.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_webidl.js +25 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_xml.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_xquery.js +51 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_yacas.js +16 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_yaml.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_z80.js +1 -0
- package/src/assets/codemirror/@codemirror_lint.js +46 -0
- package/src/assets/codemirror/@codemirror_merge.js +167 -0
- package/src/assets/codemirror/@codemirror_search.js +121 -0
- package/src/assets/codemirror/@codemirror_state.js +793 -0
- package/src/assets/codemirror/@codemirror_theme-one-dark.js +12 -0
- package/src/assets/codemirror/@codemirror_view.js +1210 -0
- package/src/assets/codemirror/@lezer_common.js +407 -0
- package/src/assets/codemirror/@lezer_cpp.js +4 -0
- package/src/assets/codemirror/@lezer_css.js +4 -0
- package/src/assets/codemirror/@lezer_go.js +3 -0
- package/src/assets/codemirror/@lezer_highlight.js +380 -0
- package/src/assets/codemirror/@lezer_html.js +20 -0
- package/src/assets/codemirror/@lezer_java.js +2 -0
- package/src/assets/codemirror/@lezer_javascript.js +7 -0
- package/src/assets/codemirror/@lezer_json.js +2 -0
- package/src/assets/codemirror/@lezer_lezer.js +2 -0
- package/src/assets/codemirror/@lezer_lr.js +325 -0
- package/src/assets/codemirror/@lezer_markdown.js +286 -0
- package/src/assets/codemirror/@lezer_php.js +3 -0
- package/src/assets/codemirror/@lezer_python.js +5 -0
- package/src/assets/codemirror/@lezer_rust.js +3 -0
- package/src/assets/codemirror/@lezer_sass.js +5 -0
- package/src/assets/codemirror/@lezer_xml.js +3 -0
- package/src/assets/codemirror/@lezer_yaml.js +12 -0
- package/src/assets/codemirror/@marijn_find-cluster-break.js +10 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-androidstudio.js +3 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-andromeda.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-atomone.js +6 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-aura.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-basic.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-bbedit.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-copilot.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-darcula.js +6 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-dracula.js +6 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-duotone.js +5 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-eclipse.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-github.js +3 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-material.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-monokai.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-nord.js +2 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-okaidia.js +2 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-solarized.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-sublime.js +2 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-tokyo-night.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-vscode.js +5 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-xcode.js +3 -0
- package/src/assets/codemirror/@uiw_codemirror-themes.js +1 -0
- package/src/assets/codemirror/_core.js +4494 -0
- package/src/assets/codemirror/codemirror.js +46 -0
- package/src/assets/codemirror/crelt.js +1 -0
- package/src/assets/codemirror/style-mod.js +36 -0
- package/src/assets/codemirror/w3c-keyname.js +8 -0
- package/src/assets/codemirror-editor.umd.js +415 -0
- package/src/assets/editor.html +377 -0
- package/src/assets/webview-interface.umd.js +2 -0
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
async function moduleInitFunction(requireAsyncModule,exports={}){const module={exports:exports};var hasRequiredDist,require$$0=await requireAsyncModule("@marijn/find-cluster-break"),dist={},distExports=function requireDist(){return hasRequiredDist?dist:(hasRequiredDist=1,function(exports){function textLength(text){let length=-1;for(let line of text)length+=line.length+1;return length}function appendText(text,target,from=0,to=1e9){for(let pos=0,i=0,first=!0;i<text.length&&pos<=to;i++){let line=text[i],end=pos+line.length;end>=from&&(end>to&&(line=line.slice(0,to-pos)),pos<from&&(line=line.slice(from-pos)),first?(target[target.length-1]+=line,first=!1):target.push(line)),pos=end+1}return target}function sliceText(text,from,to){return appendText(text,[""],from,to)}function clip(text,from,to){return from=Math.max(0,Math.min(text.length,from)),[from,Math.max(from,Math.min(text.length,to))]}/**
|
|
2
|
+
Returns a next grapheme cluster break _after_ (not equal to)
|
|
3
|
+
`pos`, if `forward` is true, or before otherwise. Returns `pos`
|
|
4
|
+
itself if no further cluster break is available in the string.
|
|
5
|
+
Moves across surrogate pairs, extending characters (when
|
|
6
|
+
`includeExtending` is true), characters joined with zero-width
|
|
7
|
+
joiners, and flag emoji.
|
|
8
|
+
*/function findClusterBreak(str,pos,forward=!0,includeExtending=!0){return findClusterBreak$1.findClusterBreak(str,pos,forward,includeExtending)}function surrogateLow(ch){return 56320<=ch&&57344>ch}function surrogateHigh(ch){return 55296<=ch&&56320>ch}/**
|
|
9
|
+
Find the code point at the given position in a string (like the
|
|
10
|
+
[`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
|
|
11
|
+
string method).
|
|
12
|
+
*/function codePointAt(str,pos){let code0=str.charCodeAt(pos);if(!surrogateHigh(code0)||pos+1==str.length)return code0;let code1=str.charCodeAt(pos+1);return surrogateLow(code1)?(code0-55296<<10)+(code1-56320)+65536:code0}/**
|
|
13
|
+
Given a Unicode codepoint, return the JavaScript string that
|
|
14
|
+
respresents it (like
|
|
15
|
+
[`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).
|
|
16
|
+
*/function fromCodePoint(code){return 65535>=code?String.fromCharCode(code):(code-=65536,String.fromCharCode((code>>10)+55296,(1023&code)+56320))}/**
|
|
17
|
+
The amount of positions a character takes up in a JavaScript string.
|
|
18
|
+
*/function codePointSize(code){return 65536>code?1:2}function addSection(sections,len,ins,forceJoin=!1){if(!(0==len&&0>=ins)){let last=sections.length-2;0<=last&&0>=ins&&ins==sections[last+1]?sections[last]+=len:0<=last&&0==len&&0==sections[last]?sections[last+1]+=ins:forceJoin?(sections[last]+=len,sections[last+1]+=ins):sections.push(len,ins)}}function addInsert(values,sections,value){if(0!=value.length){let index=sections.length-2>>1;if(index<values.length)values[values.length-1]=values[values.length-1].append(value);else{for(;values.length<index;)values.push(Text.empty);values.push(value)}}}function iterChanges(desc,f,individual){let inserted=desc.inserted;for(let posA=0,posB=0,i=0;i<desc.sections.length;){let len=desc.sections[i++],ins=desc.sections[i++];if(0>ins)posA+=len,posB+=len;else{let endA=posA,endB=posB,text=Text.empty;for(;;){if(endA+=len,endB+=ins,ins&&inserted&&(text=text.append(inserted[i-2>>1])),individual||i==desc.sections.length||0>desc.sections[i+1])break;len=desc.sections[i++],ins=desc.sections[i++]}f(posA,endA,posB,endB,text),posA=endA,posB=endB}}}function mapSet(setA,setB,before,mkSet=!1){// Produce a copy of setA that applies to the document after setB
|
|
19
|
+
// has been applied (assuming both start at the same document).
|
|
20
|
+
let sections=[],insert=mkSet?[]:null,a=new SectionIter(setA),b=new SectionIter(setB);// Iterate over both sets in parallel. inserted tracks, for changes
|
|
21
|
+
// in A that have to be processed piece-by-piece, whether their
|
|
22
|
+
// content has been inserted already, and refers to the section
|
|
23
|
+
// index.
|
|
24
|
+
for(let inserted=-1;;)if(a.done&&b.len||b.done&&a.len)throw new Error("Mismatched change set lengths");else if(-1==a.ins&&-1==b.ins){// Move across ranges skipped by both sets.
|
|
25
|
+
let len=Math.min(a.len,b.len);addSection(sections,len,-1),a.forward(len),b.forward(len)}else if(0<=b.ins&&(0>a.ins||inserted==a.i||0==a.off&&(b.len<a.len||b.len==a.len&&!before))){// If there's a change in B that comes before the next change in
|
|
26
|
+
// A (ordered by start pos, then len, then before flag), skip
|
|
27
|
+
// that (and process any changes in A it covers).
|
|
28
|
+
let len=b.len;for(addSection(sections,b.ins,-1);len;){let piece=Math.min(a.len,len);0<=a.ins&&inserted<a.i&&a.len<=piece&&(addSection(sections,0,a.ins),insert&&addInsert(insert,sections,a.text),inserted=a.i),a.forward(piece),len-=piece}b.next()}else if(0<=a.ins){// Process the part of a change in A up to the start of the next
|
|
29
|
+
// non-deletion change in B (if overlapping).
|
|
30
|
+
let len=0,left=a.len;for(;left;)if(-1==b.ins){let piece=Math.min(left,b.len);len+=piece,left-=piece,b.forward(piece)}else if(0==b.ins&&b.len<left)left-=b.len,b.next();else break;addSection(sections,len,inserted<a.i?a.ins:0),insert&&inserted<a.i&&addInsert(insert,sections,a.text),inserted=a.i,a.forward(a.len-left)}else{if(a.done&&b.done)return insert?ChangeSet.createSet(sections,insert):ChangeDesc.create(sections);throw new Error("Mismatched change set lengths")}}function composeSets(setA,setB,mkSet=!1){let sections=[],insert=mkSet?[]:null,a=new SectionIter(setA),b=new SectionIter(setB);for(let open=!1;;){if(a.done&&b.done)return insert?ChangeSet.createSet(sections,insert):ChangeDesc.create(sections);if(0==a.ins)addSection(sections,a.len,0,open),a.next();else if(0==b.len&&!b.done)addSection(sections,0,b.ins,open),insert&&addInsert(insert,sections,b.text),b.next();else if(a.done||b.done)throw new Error("Mismatched change set lengths");else{let len=Math.min(a.len2,b.len),sectionLen=sections.length;if(-1==a.ins){let insB=-1==b.ins?-1:b.off?0:b.ins;addSection(sections,len,insB,open),insert&&insB&&addInsert(insert,sections,b.text)}else-1==b.ins?(addSection(sections,a.off?0:a.len,len,open),insert&&addInsert(insert,sections,a.textBit(len))):(addSection(sections,a.off?0:a.len,b.off?0:b.ins,open),insert&&!b.off&&addInsert(insert,sections,b.text));open=(a.ins>len||0<=b.ins&&b.len>len)&&(open||sections.length>sectionLen),a.forward2(len),b.forward(len)}}}function checkSelection(selection,docLength){for(let range of selection.ranges)if(range.to>docLength)throw new RangeError("Selection points outside of document")}function sameArray(a,b){return a==b||a.length==b.length&&a.every((e,i)=>e===b[i])}function compareArray(a,b,compare){if(a.length!=b.length)return!1;for(let i=0;i<a.length;i++)if(!compare(a[i],b[i]))return!1;return!0}function ensureAll(state,addrs){let changed=!1;for(let addr of addrs)1&ensureAddr(state,addr)/* SlotStatus.Changed */&&(changed=!0);return changed}function dynamicFacetSlot(addresses,facet,providers){function get(state){let values=[];for(let value,i=0;i<providerAddrs.length;i++)if(value=getAddr(state,providerAddrs[i]),2==providerTypes[i]/* Provider.Multi */)for(let val of value)values.push(val);else values.push(value);return facet.combine(values)}let providerAddrs=providers.map(p=>addresses[p.id]),providerTypes=providers.map(p=>p.type),dynamic=providerAddrs.filter(p=>!(1&p)),idx=addresses[facet.id]>>1;return{create(state){for(let addr of providerAddrs)ensureAddr(state,addr);return state.values[idx]=get(state),1/* SlotStatus.Changed */},update(state,tr){if(!ensureAll(state,dynamic))return 0;let value=get(state);return facet.compare(value,state.values[idx])?0:(state.values[idx]=value,1/* SlotStatus.Changed */)},reconfigure(state,oldState){let depChanged=ensureAll(state,providerAddrs),oldProviders=oldState.config.facets[facet.id],oldValue=oldState.facet(facet);if(oldProviders&&!depChanged&&sameArray(providers,oldProviders))return state.values[idx]=oldValue,0;let value=get(state);return facet.compare(value,oldValue)?(state.values[idx]=oldValue,0):(state.values[idx]=value,1/* SlotStatus.Changed */)}}}function prec(value){return ext=>new PrecExtension(ext,value)}/**
|
|
31
|
+
By default extensions are registered in the order they are found
|
|
32
|
+
in the flattened form of nested array that was provided.
|
|
33
|
+
Individual extension values can be assigned a precedence to
|
|
34
|
+
override this. Extensions that do not have a precedence set get
|
|
35
|
+
the precedence of the nearest parent with a precedence, or
|
|
36
|
+
[`default`](https://codemirror.net/6/docs/ref/#state.Prec.default) if there is no such parent. The
|
|
37
|
+
final ordering of extensions is determined by first sorting by
|
|
38
|
+
precedence and then by order within each precedence.
|
|
39
|
+
*/function flatten(extension,compartments,newCompartments){function inner(ext,prec){let known=seen.get(ext);if(null!=known){if(known<=prec)return;let found=result[known].indexOf(ext);-1<found&&result[known].splice(found,1),ext instanceof CompartmentInstance&&newCompartments.delete(ext.compartment)}if(seen.set(ext,prec),Array.isArray(ext))for(let e of ext)inner(e,prec);else if(ext instanceof CompartmentInstance){if(newCompartments.has(ext.compartment))throw new RangeError(`Duplicate use of compartment in extensions`);let content=compartments.get(ext.compartment)||ext.inner;newCompartments.set(ext.compartment,content),inner(content,prec)}else if(ext instanceof PrecExtension)inner(ext.inner,ext.prec);else if(ext instanceof StateField)result[prec].push(ext),ext.provides&&inner(ext.provides,prec);else if(ext instanceof FacetProvider)result[prec].push(ext),ext.facet.extensions&&inner(ext.facet.extensions,Prec_.default);else{let content=ext.extension;if(!content)throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);inner(content,prec)}}let result=[[],[],[],[],[]],seen=new Map;return inner(extension,Prec_.default),result.reduce((a,b)=>a.concat(b))}function ensureAddr(state,addr){if(1&addr)return 2/* SlotStatus.Computed */;let idx=addr>>1,status=state.status[idx];if(4==status/* SlotStatus.Computing */)throw new Error("Cyclic dependency between fields and/or facets");if(2&status/* SlotStatus.Computed */)return status;state.status[idx]=4/* SlotStatus.Computing */;let changed=state.computeSlot(state,state.config.dynamicSlots[idx]);return state.status[idx]=2/* SlotStatus.Computed */|changed}function getAddr(state,addr){return 1&addr?state.config.staticValues[addr>>1]:state.values[addr>>1]}function joinRanges(a,b){let result=[];for(let iA=0,iB=0;;){let from,to;if(iA<a.length&&(iB==b.length||b[iB]>=a[iA]))from=a[iA++],to=a[iA++];else if(iB<b.length)from=b[iB++],to=b[iB++];else return result;!result.length||result[result.length-1]<from?result.push(from,to):result[result.length-1]<to&&(result[result.length-1]=to)}}function mergeTransaction(a,b,sequential){var _a;let mapForA,mapForB,changes;return sequential?(mapForA=b.changes,mapForB=ChangeSet.empty(b.changes.length),changes=a.changes.compose(b.changes)):(mapForA=b.changes.map(a.changes),mapForB=a.changes.mapDesc(b.changes,!0),changes=a.changes.compose(mapForA)),{changes,selection:b.selection?b.selection.map(mapForB):null===(_a=a.selection)||void 0===_a?void 0:_a.map(mapForA),effects:StateEffect.mapEffects(a.effects,mapForA).concat(StateEffect.mapEffects(b.effects,mapForB)),annotations:a.annotations.length?a.annotations.concat(b.annotations):b.annotations,scrollIntoView:a.scrollIntoView||b.scrollIntoView}}function resolveTransactionInner(state,spec,docSize){let sel=spec.selection,annotations=asArray(spec.annotations);return spec.userEvent&&(annotations=annotations.concat(Transaction.userEvent.of(spec.userEvent))),{changes:spec.changes instanceof ChangeSet?spec.changes:ChangeSet.of(spec.changes||[],docSize,state.facet(lineSeparator)),selection:sel&&(sel instanceof EditorSelection?sel:EditorSelection.single(sel.anchor,sel.head)),effects:asArray(spec.effects),annotations,scrollIntoView:!!spec.scrollIntoView}}function resolveTransaction(state,specs,filter){let s=resolveTransactionInner(state,specs.length?specs[0]:{},state.doc.length);specs.length&&!1===specs[0].filter&&(filter=!1);for(let i=1;i<specs.length;i++){!1===specs[i].filter&&(filter=!1);let seq=!!specs[i].sequential;s=mergeTransaction(s,resolveTransactionInner(state,specs[i],seq?s.changes.newLength:state.doc.length),seq)}let tr=Transaction.create(state,s.changes,s.selection,s.effects,s.annotations,s.scrollIntoView);return extendTransaction(filter?filterTransaction(tr):tr)}// Finish a transaction by applying filters if necessary.
|
|
40
|
+
function filterTransaction(tr){let state=tr.startState,result=!0;// Change filters
|
|
41
|
+
for(let filter of state.facet(changeFilter)){let value=filter(tr);if(!1===value){result=!1;break}Array.isArray(value)&&(result=!0===result?value:joinRanges(result,value))}if(!0!==result){let changes,back;if(!1===result)back=tr.changes.invertedDesc,changes=ChangeSet.empty(state.doc.length);else{let filtered=tr.changes.filter(result);changes=filtered.changes,back=filtered.filtered.mapDesc(filtered.changes).invertedDesc}tr=Transaction.create(state,changes,tr.selection&&tr.selection.map(back),StateEffect.mapEffects(tr.effects,back),tr.annotations,tr.scrollIntoView)}// Transaction filters
|
|
42
|
+
let filters=state.facet(transactionFilter);for(let filtered,i=filters.length-1;0<=i;i--)filtered=filters[i](tr),tr=filtered instanceof Transaction?filtered:Array.isArray(filtered)&&1==filtered.length&&filtered[0]instanceof Transaction?filtered[0]:resolveTransaction(state,asArray(filtered),!1);return tr}function extendTransaction(tr){let state=tr.startState,extenders=state.facet(transactionExtender),spec=tr;for(let extension,i=extenders.length-1;0<=i;i--)extension=extenders[i](tr),extension&&Object.keys(extension).length&&(spec=mergeTransaction(spec,resolveTransactionInner(state,extension,tr.changes.newLength),!0));return spec==tr?tr:Transaction.create(state,tr.changes,tr.selection,spec.effects,spec.annotations,spec.scrollIntoView)}function asArray(value){return null==value?none:Array.isArray(value)?value:[value]}/**
|
|
43
|
+
The categories produced by a [character
|
|
44
|
+
categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used
|
|
45
|
+
do things like selecting by word.
|
|
46
|
+
*/function hasWordChar(str){if(wordChar)return wordChar.test(str);for(let ch,i=0;i<str.length;i++)if(ch=str[i],/\w/.test(ch)||"\x80"<ch&&(ch.toUpperCase()!=ch.toLowerCase()||nonASCIISingleCaseWordChar.test(ch)))return!0;return!1}function makeCategorizer(wordChars){return char=>{if(!/\S/.test(char))return exports.CharCategory.Space;if(hasWordChar(char))return exports.CharCategory.Word;for(let i=0;i<wordChars.length;i++)if(-1<char.indexOf(wordChars[i]))return exports.CharCategory.Word;return exports.CharCategory.Other}}/**
|
|
47
|
+
The editor state class is a persistent (immutable) data structure.
|
|
48
|
+
To update a state, you [create](https://codemirror.net/6/docs/ref/#state.EditorState.update) a
|
|
49
|
+
[transaction](https://codemirror.net/6/docs/ref/#state.Transaction), which produces a _new_ state
|
|
50
|
+
instance, without modifying the original object.
|
|
51
|
+
|
|
52
|
+
As such, _never_ mutate properties of a state directly. That'll
|
|
53
|
+
just break things.
|
|
54
|
+
*/ /**
|
|
55
|
+
Utility function for combining behaviors to fill in a config
|
|
56
|
+
object from an array of provided configs. `defaults` should hold
|
|
57
|
+
default values for all optional fields in `Config`.
|
|
58
|
+
|
|
59
|
+
The function will, by default, error
|
|
60
|
+
when a field gets two values that aren't `===`-equal, but you can
|
|
61
|
+
provide combine functions per field to do something else.
|
|
62
|
+
*/function combineConfig(configs,defaults,// Should hold only the optional properties of Config, but I haven't managed to express that
|
|
63
|
+
combine={}){let result={};for(let config of configs)for(let key of Object.keys(config)){let value=config[key],current=result[key];if(void 0===current)result[key]=value;else if(current===value||void 0===value);// No conflict
|
|
64
|
+
else if(Object.hasOwnProperty.call(combine,key))result[key]=combine[key](current,value);else throw new Error("Config merge conflict for field "+key)}for(let key in defaults)void 0===result[key]&&(result[key]=defaults[key]);return result}/**
|
|
65
|
+
Each range is associated with a value, which must inherit from
|
|
66
|
+
this class.
|
|
67
|
+
*/function cmpVal(a,b){return a==b||a.constructor==b.constructor&&a.eq(b)}/**
|
|
68
|
+
A range associates a value with a range of positions.
|
|
69
|
+
*/function cmpRange(a,b){return a.from-b.from||a.value.startSide-b.value.startSide}function lazySort(ranges){if(1<ranges.length)for(let cur,prev=ranges[0],i=1;i<ranges.length;i++){if(cur=ranges[i],0<cmpRange(prev,cur))return ranges.slice().sort(cmpRange);prev=cur}return ranges}function findSharedChunks(a,b,textDiff){let inA=new Map;for(let set of a)for(let i=0;i<set.chunk.length;i++)0>=set.chunk[i].maxPoint&&inA.set(set.chunk[i],set.chunkPos[i]);let shared=new Set;for(let set of b)for(let known,i=0;i<set.chunk.length;i++)known=inA.get(set.chunk[i]),null==known||(textDiff?textDiff.mapPos(known):known)!=set.chunkPos[i]||(null===textDiff||void 0===textDiff?void 0:textDiff.touchesRange(known,known+set.chunk[i].length))||shared.add(set.chunk[i]);return shared}function heapBubble(heap,index){for(let childIndex,cur=heap[index];;){if(childIndex=(index<<1)+1,childIndex>=heap.length)break;let child=heap[childIndex];if(childIndex+1<heap.length&&0<=child.compare(heap[childIndex+1])&&(child=heap[childIndex+1],childIndex++),0>cur.compare(child))break;heap[childIndex]=cur,heap[index]=child,index=childIndex}}function compare(a,startA,b,startB,length,comparator){a.goto(startA),b.goto(startB);let endB=startB+length,pos=startB,dPos=startB-startA,bounds=!!comparator.boundChange;for(let boundChange=!1;;){let dEnd=a.to+dPos-b.to,diff=dEnd||a.endSide-b.endSide,end=0>diff?a.to+dPos:b.to,clipEnd=Math.min(end,endB),point=a.point||b.point;if(point?(!(a.point&&b.point&&cmpVal(a.point,b.point)&&sameValues(a.activeForPoint(a.to),b.activeForPoint(b.to)))&&comparator.comparePoint(pos,clipEnd,a.point,b.point),boundChange=!1):(boundChange&&comparator.boundChange(pos),clipEnd>pos&&!sameValues(a.active,b.active)&&comparator.compareRange(pos,clipEnd,a.active,b.active),bounds&&clipEnd<endB&&(dEnd||a.openEnd(end)!=b.openEnd(end))&&(boundChange=!0)),end>endB)break;pos=end,0>=diff&&a.next(),0<=diff&&b.next()}}function sameValues(a,b){if(a.length!=b.length)return!1;for(let i=0;i<a.length;i++)if(a[i]!=b[i]&&!cmpVal(a[i],b[i]))return!1;return!0}function remove(array,index){for(let i=index,e=array.length-1;i<e;i++)array[i]=array[i+1];array.pop()}function insert(array,index,value){for(let i=array.length-1;i>=index;i--)array[i+1]=array[i];array[index]=value}function findMinIndex(value,array){let found=-1,foundPos=1e9/* C.Far */;for(let i=0;i<array.length;i++)0>(array[i]-foundPos||value[i].endSide-value[found].endSide)&&(found=i,foundPos=array[i]);return found}/**
|
|
70
|
+
Count the column position at the given offset into the string,
|
|
71
|
+
taking extending characters and tab size into account.
|
|
72
|
+
*/function countColumn(string,tabSize,to=string.length){let n=0;for(let i=0;i<to&&i<string.length;)9==string.charCodeAt(i)?(n+=tabSize-n%tabSize,i++):(n++,i=findClusterBreak(string,i));return n}/**
|
|
73
|
+
Find the offset that corresponds to the given column position in a
|
|
74
|
+
string, taking extending characters and tab size into account. By
|
|
75
|
+
default, the string length is returned when it is too short to
|
|
76
|
+
reach the column. Pass `strict` true to make it return -1 in that
|
|
77
|
+
situation.
|
|
78
|
+
*/function findColumn(string,col,tabSize,strict){for(let i=0,n=0;;){if(n>=col)return i;if(i==string.length)break;n+=9==string.charCodeAt(i)?tabSize-n%tabSize:1,i=findClusterBreak(string,i)}return!0===strict?-1:string.length}var findClusterBreak$1=require$$0;/**
|
|
79
|
+
The data structure for documents. @nonabstract
|
|
80
|
+
*/class Text{/**
|
|
81
|
+
Get the line description around the given position.
|
|
82
|
+
*/lineAt(pos){if(0>pos||pos>this.length)throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);return this.lineInner(pos,!1,1,0)}/**
|
|
83
|
+
Get the description for the given (1-based) line number.
|
|
84
|
+
*/line(n){if(1>n||n>this.lines)throw new RangeError(`Invalid line number ${n} in ${this.lines}-line document`);return this.lineInner(n,!0,1,0)}/**
|
|
85
|
+
Replace a range of the text with the given content.
|
|
86
|
+
*/replace(from,to,text){[from,to]=clip(this,from,to);let parts=[];return this.decompose(0,from,parts,2/* Open.To */),text.length&&text.decompose(0,text.length,parts,3/* Open.To */),this.decompose(to,this.length,parts,1/* Open.From */),TextNode.from(parts,this.length-(to-from)+text.length)}/**
|
|
87
|
+
Append another document to this one.
|
|
88
|
+
*/append(other){return this.replace(this.length,this.length,other)}/**
|
|
89
|
+
Retrieve the text between the given points.
|
|
90
|
+
*/slice(from,to=this.length){[from,to]=clip(this,from,to);let parts=[];return this.decompose(from,to,parts,0),TextNode.from(parts,to-from)}/**
|
|
91
|
+
Test whether this text is equal to another instance.
|
|
92
|
+
*/eq(other){if(other==this)return!0;if(other.length!=this.length||other.lines!=this.lines)return!1;let start=this.scanIdentical(other,1),end=this.length-this.scanIdentical(other,-1),a=new RawTextCursor(this),b=new RawTextCursor(other);for(let skip=start,pos=start;;){if(a.next(skip),b.next(skip),skip=0,a.lineBreak!=b.lineBreak||a.done!=b.done||a.value!=b.value)return!1;if(pos+=a.value.length,a.done||pos>=end)return!0}}/**
|
|
93
|
+
Iterate over the text. When `dir` is `-1`, iteration happens
|
|
94
|
+
from end to start. This will return lines and the breaks between
|
|
95
|
+
them as separate strings.
|
|
96
|
+
*/iter(dir=1){return new RawTextCursor(this,dir)}/**
|
|
97
|
+
Iterate over a range of the text. When `from` > `to`, the
|
|
98
|
+
iterator will run in reverse.
|
|
99
|
+
*/iterRange(from,to=this.length){return new PartialTextCursor(this,from,to)}/**
|
|
100
|
+
Return a cursor that iterates over the given range of lines,
|
|
101
|
+
_without_ returning the line breaks between, and yielding empty
|
|
102
|
+
strings for empty lines.
|
|
103
|
+
|
|
104
|
+
When `from` and `to` are given, they should be 1-based line numbers.
|
|
105
|
+
*/iterLines(from,to){let inner;if(null==from)inner=this.iter();else{null==to&&(to=this.lines+1);let start=this.line(from).from;inner=this.iterRange(start,Math.max(start,to==this.lines+1?this.length:1>=to?0:this.line(to-1).to))}return new LineCursor(inner)}/**
|
|
106
|
+
Return the document as a string, using newline characters to
|
|
107
|
+
separate lines.
|
|
108
|
+
*/toString(){return this.sliceString(0)}/**
|
|
109
|
+
Convert the document to an array of lines (which can be
|
|
110
|
+
deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
|
|
111
|
+
*/toJSON(){let lines=[];return this.flatten(lines),lines}/**
|
|
112
|
+
@internal
|
|
113
|
+
*/constructor(){}/**
|
|
114
|
+
Create a `Text` instance for the given array of lines.
|
|
115
|
+
*/static of(text){if(0==text.length)throw new RangeError("A document must have at least one line");return 1!=text.length||text[0]?32>=text.length/* Tree.Branch */?new TextLeaf(text):TextNode.from(TextLeaf.split(text,[])):Text.empty}}// Leaves store an array of line strings. There are always line breaks
|
|
116
|
+
// between these strings. Leaves are limited in size and have to be
|
|
117
|
+
// contained in TextNode instances for bigger documents.
|
|
118
|
+
class TextLeaf extends Text{constructor(text,length=textLength(text)){super(),this.text=text,this.length=length}get lines(){return this.text.length}get children(){return null}lineInner(target,isLine,line,offset){for(let i=0;;i++){let string=this.text[i],end=offset+string.length;if((isLine?line:end)>=target)return new Line(offset,end,line,string);offset=end+1,line++}}decompose(from,to,target,open){let text=0>=from&&to>=this.length?this:new TextLeaf(sliceText(this.text,from,to),Math.min(to,this.length)-Math.max(0,from));if(1&open/* Open.From */){let prev=target.pop(),joined=appendText(text.text,prev.text.slice(),0,text.length);if(32>=joined.length/* Tree.Branch */)target.push(new TextLeaf(joined,prev.length+text.length));else{let mid=joined.length>>1;target.push(new TextLeaf(joined.slice(0,mid)),new TextLeaf(joined.slice(mid)))}}else target.push(text)}replace(from,to,text){if(!(text instanceof TextLeaf))return super.replace(from,to,text);[from,to]=clip(this,from,to);let lines=appendText(this.text,appendText(text.text,sliceText(this.text,0,from)),to),newLen=this.length+text.length-(to-from);return 32>=lines.length/* Tree.Branch */?new TextLeaf(lines,newLen):TextNode.from(TextLeaf.split(lines,[]),newLen)}sliceString(from,to=this.length,lineSep="\n"){[from,to]=clip(this,from,to);let result="";for(let pos=0,i=0;pos<=to&&i<this.text.length;i++){let line=this.text[i],end=pos+line.length;pos>from&&i&&(result+=lineSep),from<end&&to>pos&&(result+=line.slice(Math.max(0,from-pos),to-pos)),pos=end+1}return result}flatten(target){for(let line of this.text)target.push(line)}scanIdentical(){return 0}static split(text,target){let part=[],len=-1;for(let line of text)part.push(line),len+=line.length+1,32==part.length/* Tree.Branch */&&(target.push(new TextLeaf(part,len)),part=[],len=-1);return-1<len&&target.push(new TextLeaf(part,len)),target}}// Nodes provide the tree structure of the `Text` type. They store a
|
|
119
|
+
// number of other nodes or leaves, taking care to balance themselves
|
|
120
|
+
// on changes. There are implied line breaks _between_ the children of
|
|
121
|
+
// a node (but not before the first or after the last child).
|
|
122
|
+
class TextNode extends Text{constructor(children,length){super(),this.children=children,this.length=length,this.lines=0;for(let child of children)this.lines+=child.lines}lineInner(target,isLine,line,offset){for(let i=0;;i++){let child=this.children[i],end=offset+child.length,endLine=line+child.lines-1;if((isLine?endLine:end)>=target)return child.lineInner(target,isLine,line,offset);offset=end+1,line=endLine+1}}decompose(from,to,target,open){for(let i=0,pos=0;pos<=to&&i<this.children.length;i++){let child=this.children[i],end=pos+child.length;if(from<=end&&to>=pos){let childOpen=open&((pos<=from?1/* Open.From */:0)|(end>=to?2/* Open.To */:0));pos>=from&&end<=to&&!childOpen?target.push(child):child.decompose(from-pos,to-pos,target,childOpen)}pos=end+1}}replace(from,to,text){if([from,to]=clip(this,from,to),text.lines<this.lines)for(let i=0,pos=0;i<this.children.length;i++){let child=this.children[i],end=pos+child.length;// Fast path: if the change only affects one child and the
|
|
123
|
+
// child's size remains in the acceptable range, only update
|
|
124
|
+
// that child
|
|
125
|
+
if(from>=pos&&to<=end){let updated=child.replace(from-pos,to-pos,text),totalLines=this.lines-child.lines+updated.lines;if(updated.lines<totalLines>>4&&updated.lines>totalLines>>6){let copy=this.children.slice();return copy[i]=updated,new TextNode(copy,this.length-(to-from)+text.length)}return super.replace(pos,end,updated)}pos=end+1}return super.replace(from,to,text)}sliceString(from,to=this.length,lineSep="\n"){[from,to]=clip(this,from,to);let result="";for(let i=0,pos=0;i<this.children.length&&pos<=to;i++){let child=this.children[i],end=pos+child.length;pos>from&&i&&(result+=lineSep),from<end&&to>pos&&(result+=child.sliceString(from-pos,to-pos,lineSep)),pos=end+1}return result}flatten(target){for(let child of this.children)child.flatten(target)}scanIdentical(other,dir){if(!(other instanceof TextNode))return 0;let length=0,[iA,iB,eA,eB]=0<dir?[0,0,this.children.length,other.children.length]:[this.children.length-1,other.children.length-1,-1,-1];for(;;iA+=dir,iB+=dir){if(iA==eA||iB==eB)return length;let chA=this.children[iA],chB=other.children[iB];if(chA!=chB)return length+chA.scanIdentical(chB,dir);length+=chA.length+1}}static from(children,length=children.reduce((l,ch)=>l+ch.length+1,-1)){function add(child){let last;if(child.lines>maxChunk&&child instanceof TextNode)for(let node of child.children)add(node);else child.lines>minChunk&&(currentLines>minChunk||!currentLines)?(flush(),chunked.push(child)):child instanceof TextLeaf&¤tLines&&(last=currentChunk[currentChunk.length-1])instanceof TextLeaf&&32>=child.lines+last.lines/* Tree.Branch */?(currentLines+=child.lines,currentLen+=child.length+1,currentChunk[currentChunk.length-1]=new TextLeaf(last.text.concat(child.text),last.length+1+child.length)):(currentLines+child.lines>chunk&&flush(),currentLines+=child.lines,currentLen+=child.length+1,currentChunk.push(child))}function flush(){0==currentLines||(chunked.push(1==currentChunk.length?currentChunk[0]:TextNode.from(currentChunk,currentLen)),currentLen=-1,currentLines=currentChunk.length=0)}let lines=0;for(let ch of children)lines+=ch.lines;if(32>lines/* Tree.Branch */){let flat=[];for(let ch of children)ch.flatten(flat);return new TextLeaf(flat,length)}let chunk=Math.max(32/* Tree.Branch */,lines>>5/* Tree.BranchShift */),maxChunk=chunk<<1,minChunk=chunk>>1,chunked=[],currentLines=0,currentLen=-1,currentChunk=[];for(let child of children)add(child);return flush(),1==chunked.length?chunked[0]:new TextNode(chunked,length)}}Text.empty=new TextLeaf([""],0);class RawTextCursor{constructor(text,dir=1){this.dir=dir,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[text],this.offsets=[0<dir?1:(text instanceof TextLeaf?text.text.length:text.children.length)<<1]}nextInner(skip,dir){for(this.done=this.lineBreak=!1;;){let last=this.nodes.length-1,top=this.nodes[last],offsetValue=this.offsets[last],offset=offsetValue>>1,size=top instanceof TextLeaf?top.text.length:top.children.length;if(offset==(0<dir?size:0)){if(0==last)return this.done=!0,this.value="",this;0<dir&&this.offsets[last-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&offsetValue)==(0<dir?0:1)){if(this.offsets[last]+=dir,0==skip)return this.lineBreak=!0,this.value="\n",this;skip--}else if(top instanceof TextLeaf){// Move to the next string
|
|
126
|
+
let next=top.text[offset+(0>dir?-1:0)];if(this.offsets[last]+=dir,next.length>Math.max(0,skip))return this.value=0==skip?next:0<dir?next.slice(skip):next.slice(0,next.length-skip),this;skip-=next.length}else{let next=top.children[offset+(0>dir?-1:0)];skip>next.length?(skip-=next.length,this.offsets[last]+=dir):(0>dir&&this.offsets[last]--,this.nodes.push(next),this.offsets.push(0<dir?1:(next instanceof TextLeaf?next.text.length:next.children.length)<<1))}}}next(skip=0){return 0>skip&&(this.nextInner(-skip,-this.dir),skip=this.value.length),this.nextInner(skip,this.dir)}}class PartialTextCursor{constructor(text,start,end){this.value="",this.done=!1,this.cursor=new RawTextCursor(text,start>end?-1:1),this.pos=start>end?text.length:0,this.from=Math.min(start,end),this.to=Math.max(start,end)}nextInner(skip,dir){if(0>dir?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;skip+=Math.max(0,0>dir?this.pos-this.to:this.from-this.pos);let limit=0>dir?this.pos-this.from:this.to-this.pos;skip>limit&&(skip=limit),limit-=skip;let{value}=this.cursor.next(skip);return this.pos+=(value.length+skip)*dir,this.value=value.length<=limit?value:0>dir?value.slice(value.length-limit):value.slice(0,limit),this.done=!this.value,this}next(skip=0){return 0>skip?skip=Math.max(skip,this.from-this.pos):0<skip&&(skip=Math.min(skip,this.to-this.pos)),this.nextInner(skip,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class LineCursor{constructor(inner){this.inner=inner,this.afterBreak=!0,this.value="",this.done=!1}next(skip=0){let{done,lineBreak,value}=this.inner.next(skip);return done&&this.afterBreak?(this.value="",this.afterBreak=!1):done?(this.done=!0,this.value=""):lineBreak?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=value,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(Text.prototype[Symbol.iterator]=function(){return this.iter()},RawTextCursor.prototype[Symbol.iterator]=PartialTextCursor.prototype[Symbol.iterator]=LineCursor.prototype[Symbol.iterator]=function(){return this});/**
|
|
127
|
+
This type describes a line in the document. It is created
|
|
128
|
+
on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).
|
|
129
|
+
*/class Line{/**
|
|
130
|
+
@internal
|
|
131
|
+
*/constructor(/**
|
|
132
|
+
The position of the start of the line.
|
|
133
|
+
*/from,/**
|
|
134
|
+
The position at the end of the line (_before_ the line break,
|
|
135
|
+
or at the end of document for the last line).
|
|
136
|
+
*/to,/**
|
|
137
|
+
This line's line number (1-based).
|
|
138
|
+
*/number,/**
|
|
139
|
+
The line's content.
|
|
140
|
+
*/text){this.from=from,this.to=to,this.number=number,this.text=text}/**
|
|
141
|
+
The length of the line (not including any line break after it).
|
|
142
|
+
*/get length(){return this.to-this.from}}const DefaultSplit=/\r\n?|\n/;/**
|
|
143
|
+
Distinguishes different ways in which positions can be mapped.
|
|
144
|
+
*/exports.MapMode=void 0,function(MapMode){MapMode[MapMode.Simple=0]="Simple",MapMode[MapMode.TrackDel=1]="TrackDel",MapMode[MapMode.TrackBefore=2]="TrackBefore",MapMode[MapMode.TrackAfter=3]="TrackAfter"}(exports.MapMode||(exports.MapMode={}));/**
|
|
145
|
+
A change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet)
|
|
146
|
+
that doesn't store the inserted text. As such, it can't be
|
|
147
|
+
applied, but is cheaper to store and manipulate.
|
|
148
|
+
*/class ChangeDesc{// Sections are encoded as pairs of integers. The first is the
|
|
149
|
+
// length in the current document, and the second is -1 for
|
|
150
|
+
// unaffected sections, and the length of the replacement content
|
|
151
|
+
// otherwise. So an insertion would be (0, n>0), a deletion (n>0,
|
|
152
|
+
// 0), and a replacement two positive numbers.
|
|
153
|
+
/**
|
|
154
|
+
@internal
|
|
155
|
+
*/constructor(/**
|
|
156
|
+
@internal
|
|
157
|
+
*/sections){this.sections=sections}/**
|
|
158
|
+
The length of the document before the change.
|
|
159
|
+
*/get length(){let result=0;for(let i=0;i<this.sections.length;i+=2)result+=this.sections[i];return result}/**
|
|
160
|
+
The length of the document after the change.
|
|
161
|
+
*/get newLength(){let result=0;for(let ins,i=0;i<this.sections.length;i+=2)ins=this.sections[i+1],result+=0>ins?this.sections[i]:ins;return result}/**
|
|
162
|
+
False when there are actual changes in this set.
|
|
163
|
+
*/get empty(){return 0==this.sections.length||2==this.sections.length&&0>this.sections[1]}/**
|
|
164
|
+
Iterate over the unchanged parts left by these changes. `posA`
|
|
165
|
+
provides the position of the range in the old document, `posB`
|
|
166
|
+
the new position in the changed document.
|
|
167
|
+
*/iterGaps(f){for(let i=0,posA=0,posB=0;i<this.sections.length;){let len=this.sections[i++],ins=this.sections[i++];0>ins?(f(posA,posB,len),posB+=len):posB+=ins,posA+=len}}/**
|
|
168
|
+
Iterate over the ranges changed by these changes. (See
|
|
169
|
+
[`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
|
|
170
|
+
variant that also provides you with the inserted text.)
|
|
171
|
+
`fromA`/`toA` provides the extent of the change in the starting
|
|
172
|
+
document, `fromB`/`toB` the extent of the replacement in the
|
|
173
|
+
changed document.
|
|
174
|
+
|
|
175
|
+
When `individual` is true, adjacent changes (which are kept
|
|
176
|
+
separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
|
|
177
|
+
reported separately.
|
|
178
|
+
*/iterChangedRanges(f,individual=!1){iterChanges(this,f,individual)}/**
|
|
179
|
+
Get a description of the inverted form of these changes.
|
|
180
|
+
*/get invertedDesc(){let sections=[];for(let i=0;i<this.sections.length;){let len=this.sections[i++],ins=this.sections[i++];0>ins?sections.push(len,ins):sections.push(ins,len)}return new ChangeDesc(sections)}/**
|
|
181
|
+
Compute the combined effect of applying another set of changes
|
|
182
|
+
after this one. The length of the document after this set should
|
|
183
|
+
match the length before `other`.
|
|
184
|
+
*/composeDesc(other){return this.empty?other:other.empty?this:composeSets(this,other)}/**
|
|
185
|
+
Map this description, which should start with the same document
|
|
186
|
+
as `other`, over another set of changes, so that it can be
|
|
187
|
+
applied after it. When `before` is true, map as if the changes
|
|
188
|
+
in `this` happened before the ones in `other`.
|
|
189
|
+
*/mapDesc(other,before=!1){return other.empty?this:mapSet(this,other,before)}mapPos(pos,assoc=-1,mode=exports.MapMode.Simple){let posA=0,posB=0;for(let i=0;i<this.sections.length;){let len=this.sections[i++],ins=this.sections[i++],endA=posA+len;if(0>ins){if(endA>pos)return posB+(pos-posA);posB+=len}else{if(mode!=exports.MapMode.Simple&&endA>=pos&&(mode==exports.MapMode.TrackDel&&posA<pos&&endA>pos||mode==exports.MapMode.TrackBefore&&posA<pos||mode==exports.MapMode.TrackAfter&&endA>pos))return null;if(endA>pos||endA==pos&&0>assoc&&!len)return pos==posA||0>assoc?posB:posB+ins;posB+=ins}posA=endA}if(pos>posA)throw new RangeError(`Position ${pos} is out of range for changeset of length ${posA}`);return posB}/**
|
|
190
|
+
Check whether these changes touch a given range. When one of the
|
|
191
|
+
changes entirely covers the range, the string `"cover"` is
|
|
192
|
+
returned.
|
|
193
|
+
*/touchesRange(from,to=from){for(let i=0,pos=0;i<this.sections.length&&pos<=to;){let len=this.sections[i++],ins=this.sections[i++],end=pos+len;if(0<=ins&&pos<=to&&end>=from)return!(pos<from&&end>to)||"cover";pos=end}return!1}/**
|
|
194
|
+
@internal
|
|
195
|
+
*/toString(){let result="";for(let i=0;i<this.sections.length;){let len=this.sections[i++],ins=this.sections[i++];result+=(result?" ":"")+len+(0<=ins?":"+ins:"")}return result}/**
|
|
196
|
+
Serialize this change desc to a JSON-representable value.
|
|
197
|
+
*/toJSON(){return this.sections}/**
|
|
198
|
+
Create a change desc from its JSON representation (as produced
|
|
199
|
+
by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
|
|
200
|
+
*/static fromJSON(json){if(!Array.isArray(json)||json.length%2||json.some(a=>"number"!=typeof a))throw new RangeError("Invalid JSON representation of ChangeDesc");return new ChangeDesc(json)}/**
|
|
201
|
+
@internal
|
|
202
|
+
*/static create(sections){return new ChangeDesc(sections)}}/**
|
|
203
|
+
A change set represents a group of modifications to a document. It
|
|
204
|
+
stores the document length, and can only be applied to documents
|
|
205
|
+
with exactly that length.
|
|
206
|
+
*/class ChangeSet extends ChangeDesc{constructor(sections,/**
|
|
207
|
+
@internal
|
|
208
|
+
*/inserted){super(sections),this.inserted=inserted}/**
|
|
209
|
+
Apply the changes to a document, returning the modified
|
|
210
|
+
document.
|
|
211
|
+
*/apply(doc){if(this.length!=doc.length)throw new RangeError("Applying change set to a document with the wrong length");return iterChanges(this,(fromA,toA,fromB,_toB,text)=>doc=doc.replace(fromB,fromB+(toA-fromA),text),!1),doc}mapDesc(other,before=!1){return mapSet(this,other,before,!0)}/**
|
|
212
|
+
Given the document as it existed _before_ the changes, return a
|
|
213
|
+
change set that represents the inverse of this set, which could
|
|
214
|
+
be used to go from the document created by the changes back to
|
|
215
|
+
the document as it existed before the changes.
|
|
216
|
+
*/invert(doc){let sections=this.sections.slice(),inserted=[];for(let i=0,pos=0;i<sections.length;i+=2){let len=sections[i],ins=sections[i+1];if(0<=ins){sections[i]=ins,sections[i+1]=len;for(let index=i>>1;inserted.length<index;)inserted.push(Text.empty);inserted.push(len?doc.slice(pos,pos+len):Text.empty)}pos+=len}return new ChangeSet(sections,inserted)}/**
|
|
217
|
+
Combine two subsequent change sets into a single set. `other`
|
|
218
|
+
must start in the document produced by `this`. If `this` goes
|
|
219
|
+
`docA` → `docB` and `other` represents `docB` → `docC`, the
|
|
220
|
+
returned value will represent the change `docA` → `docC`.
|
|
221
|
+
*/compose(other){return this.empty?other:other.empty?this:composeSets(this,other,!0)}/**
|
|
222
|
+
Given another change set starting in the same document, maps this
|
|
223
|
+
change set over the other, producing a new change set that can be
|
|
224
|
+
applied to the document produced by applying `other`. When
|
|
225
|
+
`before` is `true`, order changes as if `this` comes before
|
|
226
|
+
`other`, otherwise (the default) treat `other` as coming first.
|
|
227
|
+
|
|
228
|
+
Given two changes `A` and `B`, `A.compose(B.map(A))` and
|
|
229
|
+
`B.compose(A.map(B, true))` will produce the same document. This
|
|
230
|
+
provides a basic form of [operational
|
|
231
|
+
transformation](https://en.wikipedia.org/wiki/Operational_transformation),
|
|
232
|
+
and can be used for collaborative editing.
|
|
233
|
+
*/map(other,before=!1){return other.empty?this:mapSet(this,other,before,!0)}/**
|
|
234
|
+
Iterate over the changed ranges in the document, calling `f` for
|
|
235
|
+
each, with the range in the original document (`fromA`-`toA`)
|
|
236
|
+
and the range that replaces it in the new document
|
|
237
|
+
(`fromB`-`toB`).
|
|
238
|
+
|
|
239
|
+
When `individual` is true, adjacent changes are reported
|
|
240
|
+
separately.
|
|
241
|
+
*/iterChanges(f,individual=!1){iterChanges(this,f,individual)}/**
|
|
242
|
+
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
|
|
243
|
+
set.
|
|
244
|
+
*/get desc(){return ChangeDesc.create(this.sections)}/**
|
|
245
|
+
@internal
|
|
246
|
+
*/filter(ranges){let resultSections=[],resultInserted=[],filteredSections=[],iter=new SectionIter(this);done:for(let next,i=0,pos=0;;){for(next=i==ranges.length?1e9:ranges[i++];pos<next||pos==next&&0==iter.len;){if(iter.done)break done;let len=Math.min(iter.len,next-pos);addSection(filteredSections,len,-1);let ins=-1==iter.ins?-1:0==iter.off?iter.ins:0;addSection(resultSections,len,ins),0<ins&&addInsert(resultInserted,resultSections,iter.text),iter.forward(len),pos+=len}for(let end=ranges[i++];pos<end;){if(iter.done)break done;let len=Math.min(iter.len,end-pos);addSection(resultSections,len,-1),addSection(filteredSections,len,-1==iter.ins?-1:0==iter.off?iter.ins:0),iter.forward(len),pos+=len}}return{changes:new ChangeSet(resultSections,resultInserted),filtered:ChangeDesc.create(filteredSections)}}/**
|
|
247
|
+
Serialize this change set to a JSON-representable value.
|
|
248
|
+
*/toJSON(){let parts=[];for(let i=0;i<this.sections.length;i+=2){let len=this.sections[i],ins=this.sections[i+1];0>ins?parts.push(len):0==ins?parts.push([len]):parts.push([len].concat(this.inserted[i>>1].toJSON()))}return parts}/**
|
|
249
|
+
Create a change set for the given changes, for a document of the
|
|
250
|
+
given length, using `lineSep` as line separator.
|
|
251
|
+
*/static of(changes,length,lineSep){function flush(force=!1){if(force||sections.length){pos<length&&addSection(sections,length-pos,-1);let set=new ChangeSet(sections,inserted);total=total?total.compose(set.map(total)):set,sections=[],inserted=[],pos=0}}function process(spec){if(Array.isArray(spec))for(let sub of spec)process(sub);else if(spec instanceof ChangeSet){if(spec.length!=length)throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);flush(),total=total?total.compose(spec.map(total)):spec}else{let{from,to=from,insert}=spec;if(from>to||0>from||to>length)throw new RangeError(`Invalid change range ${from} to ${to} (in doc of length ${length})`);let insText=insert?"string"==typeof insert?Text.of(insert.split(lineSep||DefaultSplit)):insert:Text.empty,insLen=insText.length;if(from==to&&0==insLen)return;from<pos&&flush(),from>pos&&addSection(sections,from-pos,-1),addSection(sections,to-from,insLen),addInsert(inserted,sections,insText),pos=to}}let sections=[],inserted=[],pos=0,total=null;return process(changes),flush(!total),total}/**
|
|
252
|
+
Create an empty changeset of the given length.
|
|
253
|
+
*/static empty(length){return new ChangeSet(length?[length,-1]:[],[])}/**
|
|
254
|
+
Create a changeset from its JSON representation (as produced by
|
|
255
|
+
[`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
|
|
256
|
+
*/static fromJSON(json){if(!Array.isArray(json))throw new RangeError("Invalid JSON representation of ChangeSet");let sections=[],inserted=[];for(let part,i=0;i<json.length;i++)if(part=json[i],"number"==typeof part)sections.push(part,-1);else if(!Array.isArray(part)||"number"!=typeof part[0]||part.some((e,i)=>i&&"string"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeSet");else if(1==part.length)sections.push(part[0],0);else{for(;inserted.length<i;)inserted.push(Text.empty);inserted[i]=Text.of(part.slice(1)),sections.push(part[0],inserted[i].length)}return new ChangeSet(sections,inserted)}/**
|
|
257
|
+
@internal
|
|
258
|
+
*/static createSet(sections,inserted){return new ChangeSet(sections,inserted)}}class SectionIter{constructor(set){this.set=set,this.i=0,this.next()}next(){let{sections}=this.set;this.i<sections.length?(this.len=sections[this.i++],this.ins=sections[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return-2==this.ins}get len2(){return 0>this.ins?this.len:this.ins}get text(){let{inserted}=this.set,index=this.i-2>>1;return index>=inserted.length?Text.empty:inserted[index]}textBit(len){let{inserted}=this.set,index=this.i-2>>1;return index>=inserted.length&&!len?Text.empty:inserted[index].slice(this.off,null==len?void 0:this.off+len)}forward(len){len==this.len?this.next():(this.len-=len,this.off+=len)}forward2(len){-1==this.ins?this.forward(len):len==this.ins?this.next():(this.ins-=len,this.off+=len)}}/**
|
|
259
|
+
A single selection range. When
|
|
260
|
+
[`allowMultipleSelections`](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
|
|
261
|
+
is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelection) may hold
|
|
262
|
+
multiple ranges. By default, selections hold exactly one range.
|
|
263
|
+
*/class SelectionRange{constructor(/**
|
|
264
|
+
The lower boundary of the range.
|
|
265
|
+
*/from,/**
|
|
266
|
+
The upper boundary of the range.
|
|
267
|
+
*/to,flags){this.from=from,this.to=to,this.flags=flags}/**
|
|
268
|
+
The anchor of the range—the side that doesn't move when you
|
|
269
|
+
extend it.
|
|
270
|
+
*/get anchor(){return 32&this.flags/* RangeFlag.Inverted */?this.to:this.from}/**
|
|
271
|
+
The head of the range, which is moved when the range is
|
|
272
|
+
[extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
|
|
273
|
+
*/get head(){return 32&this.flags/* RangeFlag.Inverted */?this.from:this.to}/**
|
|
274
|
+
True when `anchor` and `head` are at the same position.
|
|
275
|
+
*/get empty(){return this.from==this.to}/**
|
|
276
|
+
If this is a cursor that is explicitly associated with the
|
|
277
|
+
character on one of its sides, this returns the side. -1 means
|
|
278
|
+
the character before its position, 1 the character after, and 0
|
|
279
|
+
means no association.
|
|
280
|
+
*/get assoc(){return 8&this.flags/* RangeFlag.AssocBefore */?-1:16&this.flags/* RangeFlag.AssocAfter */?1:0}/**
|
|
281
|
+
The bidirectional text level associated with this cursor, if
|
|
282
|
+
any.
|
|
283
|
+
*/get bidiLevel(){let level=7&this.flags/* RangeFlag.BidiLevelMask */;return 7==level?null:level}/**
|
|
284
|
+
The goal column (stored vertical offset) associated with a
|
|
285
|
+
cursor. This is used to preserve the vertical position when
|
|
286
|
+
[moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
|
|
287
|
+
lines of different length.
|
|
288
|
+
*/get goalColumn(){let value=this.flags>>6/* RangeFlag.GoalColumnOffset */;return 16777215==value/* RangeFlag.NoGoalColumn */?void 0:value}/**
|
|
289
|
+
Map this range through a change, producing a valid range in the
|
|
290
|
+
updated document.
|
|
291
|
+
*/map(change,assoc=-1){let from,to;return this.empty?from=to=change.mapPos(this.from,assoc):(from=change.mapPos(this.from,1),to=change.mapPos(this.to,-1)),from==this.from&&to==this.to?this:new SelectionRange(from,to,this.flags)}/**
|
|
292
|
+
Extend this range to cover at least `from` to `to`.
|
|
293
|
+
*/extend(from,to=from,assoc=0){if(from<=this.anchor&&to>=this.anchor)return EditorSelection.range(from,to,void 0,void 0,assoc);let head=Math.abs(from-this.anchor)>Math.abs(to-this.anchor)?from:to;return EditorSelection.range(this.anchor,head,void 0,void 0,assoc)}/**
|
|
294
|
+
Compare this range to another range.
|
|
295
|
+
*/eq(other,includeAssoc=!1){return this.anchor==other.anchor&&this.head==other.head&&this.goalColumn==other.goalColumn&&(!includeAssoc||!this.empty||this.assoc==other.assoc)}/**
|
|
296
|
+
Return a JSON-serializable object representing the range.
|
|
297
|
+
*/toJSON(){return{anchor:this.anchor,head:this.head}}/**
|
|
298
|
+
Convert a JSON representation of a range to a `SelectionRange`
|
|
299
|
+
instance.
|
|
300
|
+
*/static fromJSON(json){if(!json||"number"!=typeof json.anchor||"number"!=typeof json.head)throw new RangeError("Invalid JSON representation for SelectionRange");return EditorSelection.range(json.anchor,json.head)}/**
|
|
301
|
+
@internal
|
|
302
|
+
*/static create(from,to,flags){return new SelectionRange(from,to,flags)}}/**
|
|
303
|
+
An editor selection holds one or more selection ranges.
|
|
304
|
+
*/class EditorSelection{constructor(/**
|
|
305
|
+
The ranges in the selection, sorted by position. Ranges cannot
|
|
306
|
+
overlap (but they may touch, if they aren't empty).
|
|
307
|
+
*/ranges,/**
|
|
308
|
+
The index of the _main_ range in the selection (which is
|
|
309
|
+
usually the range that was added last).
|
|
310
|
+
*/mainIndex){this.ranges=ranges,this.mainIndex=mainIndex}/**
|
|
311
|
+
Map a selection through a change. Used to adjust the selection
|
|
312
|
+
position for changes.
|
|
313
|
+
*/map(change,assoc=-1){return change.empty?this:EditorSelection.create(this.ranges.map(r=>r.map(change,assoc)),this.mainIndex)}/**
|
|
314
|
+
Compare this selection to another selection. By default, ranges
|
|
315
|
+
are compared only by position. When `includeAssoc` is true,
|
|
316
|
+
cursor ranges must also have the same
|
|
317
|
+
[`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
|
|
318
|
+
*/eq(other,includeAssoc=!1){if(this.ranges.length!=other.ranges.length||this.mainIndex!=other.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(other.ranges[i],includeAssoc))return!1;return!0}/**
|
|
319
|
+
Get the primary selection range. Usually, you should make sure
|
|
320
|
+
your code applies to _all_ ranges, by using methods like
|
|
321
|
+
[`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
|
|
322
|
+
*/get main(){return this.ranges[this.mainIndex]}/**
|
|
323
|
+
Make sure the selection only has one range. Returns a selection
|
|
324
|
+
holding only the main range from this selection.
|
|
325
|
+
*/asSingle(){return 1==this.ranges.length?this:new EditorSelection([this.main],0)}/**
|
|
326
|
+
Extend this selection with an extra range.
|
|
327
|
+
*/addRange(range,main=!0){return EditorSelection.create([range].concat(this.ranges),main?0:this.mainIndex+1)}/**
|
|
328
|
+
Replace a given range with another range, and then normalize the
|
|
329
|
+
selection to merge and sort ranges if necessary.
|
|
330
|
+
*/replaceRange(range,which=this.mainIndex){let ranges=this.ranges.slice();return ranges[which]=range,EditorSelection.create(ranges,this.mainIndex)}/**
|
|
331
|
+
Convert this selection to an object that can be serialized to
|
|
332
|
+
JSON.
|
|
333
|
+
*/toJSON(){return{ranges:this.ranges.map(r=>r.toJSON()),main:this.mainIndex}}/**
|
|
334
|
+
Create a selection from a JSON representation.
|
|
335
|
+
*/static fromJSON(json){if(!json||!Array.isArray(json.ranges)||"number"!=typeof json.main||json.main>=json.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new EditorSelection(json.ranges.map(r=>SelectionRange.fromJSON(r)),json.main)}/**
|
|
336
|
+
Create a selection holding a single range.
|
|
337
|
+
*/static single(anchor,head=anchor){return new EditorSelection([EditorSelection.range(anchor,head)],0)}/**
|
|
338
|
+
Sort and merge the given set of ranges, creating a valid
|
|
339
|
+
selection.
|
|
340
|
+
*/static create(ranges,mainIndex=0){if(0==ranges.length)throw new RangeError("A selection needs at least one range");for(let range,pos=0,i=0;i<ranges.length;i++){if(range=ranges[i],range.empty?range.from<=pos:range.from<pos)return EditorSelection.normalized(ranges.slice(),mainIndex);pos=range.to}return new EditorSelection(ranges,mainIndex)}/**
|
|
341
|
+
Create a cursor selection range at the given position. You can
|
|
342
|
+
safely ignore the optional arguments in most situations.
|
|
343
|
+
*/static cursor(pos,assoc=0,bidiLevel,goalColumn){return SelectionRange.create(pos,pos,(0==assoc?0:0>assoc?8/* RangeFlag.AssocBefore */:16/* RangeFlag.AssocAfter */)|(null==bidiLevel?7:Math.min(6,bidiLevel))|(null!==goalColumn&&void 0!==goalColumn?goalColumn:16777215/* RangeFlag.NoGoalColumn */)<<6/* RangeFlag.GoalColumnOffset */)}/**
|
|
344
|
+
Create a selection range.
|
|
345
|
+
*/static range(anchor,head,goalColumn,bidiLevel,assoc){let flags=(null!==goalColumn&&void 0!==goalColumn?goalColumn:16777215/* RangeFlag.NoGoalColumn */)<<6/* RangeFlag.GoalColumnOffset */|(null==bidiLevel?7:Math.min(6,bidiLevel));return assoc||anchor==head||(assoc=head<anchor?1:-1),head<anchor?SelectionRange.create(head,anchor,48/* RangeFlag.AssocAfter */|flags):SelectionRange.create(anchor,head,(assoc?0>assoc?8/* RangeFlag.AssocBefore */:16:0/* RangeFlag.AssocAfter */)|flags)}/**
|
|
346
|
+
@internal
|
|
347
|
+
*/static normalized(ranges,mainIndex=0){let main=ranges[mainIndex];ranges.sort((a,b)=>a.from-b.from),mainIndex=ranges.indexOf(main);for(let i=1;i<ranges.length;i++){let range=ranges[i],prev=ranges[i-1];if(range.empty?range.from<=prev.to:range.from<prev.to){let from=prev.from,to=Math.max(range.to,prev.to);i<=mainIndex&&mainIndex--,ranges.splice(--i,2,range.anchor>range.head?EditorSelection.range(to,from):EditorSelection.range(from,to))}}return new EditorSelection(ranges,mainIndex)}}let nextID=0;/**
|
|
348
|
+
A facet is a labeled value that is associated with an editor
|
|
349
|
+
state. It takes inputs from any number of extensions, and combines
|
|
350
|
+
those into a single output value.
|
|
351
|
+
|
|
352
|
+
Examples of uses of facets are the [tab
|
|
353
|
+
size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
|
|
354
|
+
attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
|
|
355
|
+
listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
|
|
356
|
+
|
|
357
|
+
Note that `Facet` instances can be used anywhere where
|
|
358
|
+
[`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
|
|
359
|
+
*/class Facet{constructor(/**
|
|
360
|
+
@internal
|
|
361
|
+
*/combine,/**
|
|
362
|
+
@internal
|
|
363
|
+
*/compareInput,/**
|
|
364
|
+
@internal
|
|
365
|
+
*/compare,isStatic,enables){this.combine=combine,this.compareInput=compareInput,this.compare=compare,this.isStatic=isStatic,this.id=nextID++,this.default=combine([]),this.extensions="function"==typeof enables?enables(this):enables}/**
|
|
366
|
+
Returns a facet reader for this facet, which can be used to
|
|
367
|
+
[read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
|
|
368
|
+
*/get reader(){return this}/**
|
|
369
|
+
Define a new facet.
|
|
370
|
+
*/static define(config={}){return new Facet(config.combine||(a=>a),config.compareInput||((a,b)=>a===b),config.compare||(config.combine?(a,b)=>a===b:sameArray),!!config.static,config.enables)}/**
|
|
371
|
+
Returns an extension that adds the given value to this facet.
|
|
372
|
+
*/of(value){return new FacetProvider([],this,0/* Provider.Static */,value)}/**
|
|
373
|
+
Create an extension that computes a value for the facet from a
|
|
374
|
+
state. You must take care to declare the parts of the state that
|
|
375
|
+
this value depends on, since your function is only called again
|
|
376
|
+
for a new state when one of those parts changed.
|
|
377
|
+
|
|
378
|
+
In cases where your value depends only on a single field, you'll
|
|
379
|
+
want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
|
|
380
|
+
*/compute(deps,get){if(this.isStatic)throw new Error("Can't compute a static facet");return new FacetProvider(deps,this,1/* Provider.Single */,get)}/**
|
|
381
|
+
Create an extension that computes zero or more values for this
|
|
382
|
+
facet from a state.
|
|
383
|
+
*/computeN(deps,get){if(this.isStatic)throw new Error("Can't compute a static facet");return new FacetProvider(deps,this,2/* Provider.Multi */,get)}from(field,get){return get||(get=x=>x),this.compute([field],state=>get(state.field(field)))}}class FacetProvider{constructor(dependencies,facet,type,value){this.dependencies=dependencies,this.facet=facet,this.type=type,this.value=value,this.id=nextID++}dynamicSlot(addresses){var _a;let getter=this.value,compare=this.facet.compareInput,id=this.id,idx=addresses[id]>>1,multi=2==this.type/* Provider.Multi */,depDoc=!1,depSel=!1,depAddrs=[];for(let dep of this.dependencies)"doc"==dep?depDoc=!0:"selection"==dep?depSel=!0:0==(1&(null!==(_a=addresses[dep.id])&&void 0!==_a?_a:1))&&depAddrs.push(addresses[dep.id]);return{create(state){return state.values[idx]=getter(state),1/* SlotStatus.Changed */},update(state,tr){if(depDoc&&tr.docChanged||depSel&&(tr.docChanged||tr.selection)||ensureAll(state,depAddrs)){let newVal=getter(state);if(multi?!compareArray(newVal,state.values[idx],compare):!compare(newVal,state.values[idx]))return state.values[idx]=newVal,1/* SlotStatus.Changed */}return 0},reconfigure:(state,oldState)=>{let newVal,oldAddr=oldState.config.address[id];if(null!=oldAddr){let oldVal=getAddr(oldState,oldAddr);if(this.dependencies.every(dep=>dep instanceof Facet?oldState.facet(dep)===state.facet(dep):!(dep instanceof StateField)||oldState.field(dep,!1)==state.field(dep,!1))||(multi?compareArray(newVal=getter(state),oldVal,compare):compare(newVal=getter(state),oldVal)))return state.values[idx]=oldVal,0}else newVal=getter(state);return state.values[idx]=newVal,1/* SlotStatus.Changed */}}}}const initField=Facet.define({static:!0});/**
|
|
384
|
+
Fields can store additional information in an editor state, and
|
|
385
|
+
keep it in sync with the rest of the state.
|
|
386
|
+
*/class StateField{constructor(/**
|
|
387
|
+
@internal
|
|
388
|
+
*/id,createF,updateF,compareF,/**
|
|
389
|
+
@internal
|
|
390
|
+
*/spec){this.id=id,this.createF=createF,this.updateF=updateF,this.compareF=compareF,this.spec=spec,this.provides=void 0}/**
|
|
391
|
+
Define a state field.
|
|
392
|
+
*/static define(config){let field=new StateField(nextID++,config.create,config.update,config.compare||((a,b)=>a===b),config);return config.provide&&(field.provides=config.provide(field)),field}create(state){let init=state.facet(initField).find(i=>i.field==this);return((null===init||void 0===init?void 0:init.create)||this.createF)(state)}/**
|
|
393
|
+
@internal
|
|
394
|
+
*/slot(addresses){let idx=addresses[this.id]>>1;return{create:state=>(state.values[idx]=this.create(state),1/* SlotStatus.Changed */),update:(state,tr)=>{let oldVal=state.values[idx],value=this.updateF(oldVal,tr);return this.compareF(oldVal,value)?0:(state.values[idx]=value,1/* SlotStatus.Changed */)},reconfigure:(state,oldState)=>{let reInit,init=state.facet(initField),oldInit=oldState.facet(initField);return(reInit=init.find(i=>i.field==this))&&reInit!=oldInit.find(i=>i.field==this)?(state.values[idx]=reInit.create(state),1/* SlotStatus.Changed */):null==oldState.config.address[this.id]?(state.values[idx]=this.create(state),1/* SlotStatus.Changed */):(state.values[idx]=oldState.field(this),0)}}}/**
|
|
395
|
+
Returns an extension that enables this field and overrides the
|
|
396
|
+
way it is initialized. Can be useful when you need to provide a
|
|
397
|
+
non-default starting value for the field.
|
|
398
|
+
*/init(create){return[this,initField.of({field:this,create})]}/**
|
|
399
|
+
State field instances can be used as
|
|
400
|
+
[`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
|
|
401
|
+
given state.
|
|
402
|
+
*/get extension(){return this}}const Prec_={lowest:4,low:3,default:2,high:1,highest:0},Prec={/**
|
|
403
|
+
The highest precedence level, for extensions that should end up
|
|
404
|
+
near the start of the precedence ordering.
|
|
405
|
+
*/highest:prec(Prec_.highest),/**
|
|
406
|
+
A higher-than-default precedence, for extensions that should
|
|
407
|
+
come before those with default precedence.
|
|
408
|
+
*/high:prec(Prec_.high),/**
|
|
409
|
+
The default precedence, which is also used for extensions
|
|
410
|
+
without an explicit precedence.
|
|
411
|
+
*/default:prec(Prec_.default),/**
|
|
412
|
+
A lower-than-default precedence.
|
|
413
|
+
*/low:prec(Prec_.low),/**
|
|
414
|
+
The lowest precedence level. Meant for things that should end up
|
|
415
|
+
near the end of the extension order.
|
|
416
|
+
*/lowest:prec(Prec_.lowest)};class PrecExtension{constructor(inner,prec){this.inner=inner,this.prec=prec}}/**
|
|
417
|
+
Extension compartments can be used to make a configuration
|
|
418
|
+
dynamic. By [wrapping](https://codemirror.net/6/docs/ref/#state.Compartment.of) part of your
|
|
419
|
+
configuration in a compartment, you can later
|
|
420
|
+
[replace](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) that part through a
|
|
421
|
+
transaction.
|
|
422
|
+
*/class Compartment{/**
|
|
423
|
+
Create an instance of this compartment to add to your [state
|
|
424
|
+
configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
|
|
425
|
+
*/of(ext){return new CompartmentInstance(this,ext)}/**
|
|
426
|
+
Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
|
|
427
|
+
reconfigures this compartment.
|
|
428
|
+
*/reconfigure(content){return Compartment.reconfigure.of({compartment:this,extension:content})}/**
|
|
429
|
+
Get the current content of the compartment in the state, or
|
|
430
|
+
`undefined` if it isn't present.
|
|
431
|
+
*/get(state){return state.config.compartments.get(this)}}class CompartmentInstance{constructor(compartment,inner){this.compartment=compartment,this.inner=inner}}class Configuration{constructor(base,compartments,dynamicSlots,address,staticValues,facets){for(this.base=base,this.compartments=compartments,this.dynamicSlots=dynamicSlots,this.address=address,this.staticValues=staticValues,this.facets=facets,this.statusTemplate=[];this.statusTemplate.length<dynamicSlots.length;)this.statusTemplate.push(0/* SlotStatus.Unresolved */)}staticFacet(facet){let addr=this.address[facet.id];return null==addr?facet.default:this.staticValues[addr>>1]}static resolve(base,compartments,oldState){let fields=[],facets=Object.create(null),newCompartments=new Map;for(let ext of flatten(base,compartments,newCompartments))ext instanceof StateField?fields.push(ext):(facets[ext.facet.id]||(facets[ext.facet.id]=[])).push(ext);let address=Object.create(null),staticValues=[],dynamicSlots=[];for(let field of fields)address[field.id]=dynamicSlots.length<<1,dynamicSlots.push(a=>field.slot(a));let oldFacets=null===oldState||void 0===oldState?void 0:oldState.config.facets;for(let id in facets){let providers=facets[id],facet=providers[0].facet,oldProviders=oldFacets&&oldFacets[id]||[];if(!providers.every(p=>0==p.type/* Provider.Static */)){for(let p of providers)0==p.type/* Provider.Static */?(address[p.id]=1|staticValues.length<<1,staticValues.push(p.value)):(address[p.id]=dynamicSlots.length<<1,dynamicSlots.push(a=>p.dynamicSlot(a)));address[facet.id]=dynamicSlots.length<<1,dynamicSlots.push(a=>dynamicFacetSlot(a,facet,providers))}else if(address[facet.id]=1|staticValues.length<<1,sameArray(oldProviders,providers))staticValues.push(oldState.facet(facet));else{let value=facet.combine(providers.map(p=>p.value));staticValues.push(oldState&&facet.compare(value,oldState.facet(facet))?oldState.facet(facet):value)}}let dynamic=dynamicSlots.map(f=>f(address));return new Configuration(base,newCompartments,dynamic,address,staticValues,facets)}}const languageData=Facet.define(),allowMultipleSelections=Facet.define({combine:values=>values.some(v=>v),static:!0}),lineSeparator=Facet.define({combine:values=>values.length?values[0]:void 0,static:!0}),changeFilter=Facet.define(),transactionFilter=Facet.define(),transactionExtender=Facet.define(),readOnly=Facet.define({combine:values=>!!values.length&&values[0]});/**
|
|
432
|
+
Annotations are tagged values that are used to add metadata to
|
|
433
|
+
transactions in an extensible way. They should be used to model
|
|
434
|
+
things that effect the entire transaction (such as its [time
|
|
435
|
+
stamp](https://codemirror.net/6/docs/ref/#state.Transaction^time) or information about its
|
|
436
|
+
[origin](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)). For effects that happen
|
|
437
|
+
_alongside_ the other changes made by the transaction, [state
|
|
438
|
+
effects](https://codemirror.net/6/docs/ref/#state.StateEffect) are more appropriate.
|
|
439
|
+
*/class Annotation{/**
|
|
440
|
+
@internal
|
|
441
|
+
*/constructor(/**
|
|
442
|
+
The annotation type.
|
|
443
|
+
*/type,/**
|
|
444
|
+
The value of this annotation.
|
|
445
|
+
*/value){this.type=type,this.value=value}/**
|
|
446
|
+
Define a new type of annotation.
|
|
447
|
+
*/static define(){return new AnnotationType}}/**
|
|
448
|
+
Marker that identifies a type of [annotation](https://codemirror.net/6/docs/ref/#state.Annotation).
|
|
449
|
+
*/class AnnotationType{/**
|
|
450
|
+
Create an instance of this annotation.
|
|
451
|
+
*/of(value){return new Annotation(this,value)}}/**
|
|
452
|
+
Representation of a type of state effect. Defined with
|
|
453
|
+
[`StateEffect.define`](https://codemirror.net/6/docs/ref/#state.StateEffect^define).
|
|
454
|
+
*/class StateEffectType{/**
|
|
455
|
+
@internal
|
|
456
|
+
*/constructor(// The `any` types in these function types are there to work
|
|
457
|
+
// around TypeScript issue #37631, where the type guard on
|
|
458
|
+
// `StateEffect.is` mysteriously stops working when these properly
|
|
459
|
+
// have type `Value`.
|
|
460
|
+
/**
|
|
461
|
+
@internal
|
|
462
|
+
*/map){this.map=map}/**
|
|
463
|
+
Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
|
|
464
|
+
type.
|
|
465
|
+
*/of(value){return new StateEffect(this,value)}}/**
|
|
466
|
+
State effects can be used to represent additional effects
|
|
467
|
+
associated with a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction.effects). They
|
|
468
|
+
are often useful to model changes to custom [state
|
|
469
|
+
fields](https://codemirror.net/6/docs/ref/#state.StateField), when those changes aren't implicit in
|
|
470
|
+
document or selection changes.
|
|
471
|
+
*/class StateEffect{/**
|
|
472
|
+
@internal
|
|
473
|
+
*/constructor(/**
|
|
474
|
+
@internal
|
|
475
|
+
*/type,/**
|
|
476
|
+
The value of this effect.
|
|
477
|
+
*/value){this.type=type,this.value=value}/**
|
|
478
|
+
Map this effect through a position mapping. Will return
|
|
479
|
+
`undefined` when that ends up deleting the effect.
|
|
480
|
+
*/map(mapping){let mapped=this.type.map(this.value,mapping);return void 0===mapped?void 0:mapped==this.value?this:new StateEffect(this.type,mapped)}/**
|
|
481
|
+
Tells you whether this effect object is of a given
|
|
482
|
+
[type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
|
|
483
|
+
*/is(type){return this.type==type}/**
|
|
484
|
+
Define a new effect type. The type parameter indicates the type
|
|
485
|
+
of values that his effect holds. It should be a type that
|
|
486
|
+
doesn't include `undefined`, since that is used in
|
|
487
|
+
[mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
|
|
488
|
+
removed.
|
|
489
|
+
*/static define(spec={}){return new StateEffectType(spec.map||(v=>v))}/**
|
|
490
|
+
Map an array of effects through a change set.
|
|
491
|
+
*/static mapEffects(effects,mapping){if(!effects.length)return effects;let result=[];for(let effect of effects){let mapped=effect.map(mapping);mapped&&result.push(mapped)}return result}}/**
|
|
492
|
+
This effect can be used to reconfigure the root extensions of
|
|
493
|
+
the editor. Doing this will discard any extensions
|
|
494
|
+
[appended](https://codemirror.net/6/docs/ref/#state.StateEffect^appendConfig), but does not reset
|
|
495
|
+
the content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure)
|
|
496
|
+
compartments.
|
|
497
|
+
*/StateEffect.reconfigure=StateEffect.define(),StateEffect.appendConfig=StateEffect.define();/**
|
|
498
|
+
Changes to the editor state are grouped into transactions.
|
|
499
|
+
Typically, a user action creates a single transaction, which may
|
|
500
|
+
contain any number of document changes, may change the selection,
|
|
501
|
+
or have other effects. Create a transaction by calling
|
|
502
|
+
[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately
|
|
503
|
+
dispatch one by calling
|
|
504
|
+
[`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
|
|
505
|
+
*/class Transaction{constructor(/**
|
|
506
|
+
The state from which the transaction starts.
|
|
507
|
+
*/startState,/**
|
|
508
|
+
The document changes made by this transaction.
|
|
509
|
+
*/changes,/**
|
|
510
|
+
The selection set by this transaction, or undefined if it
|
|
511
|
+
doesn't explicitly set a selection.
|
|
512
|
+
*/selection,/**
|
|
513
|
+
The effects added to the transaction.
|
|
514
|
+
*/effects,/**
|
|
515
|
+
@internal
|
|
516
|
+
*/annotations,/**
|
|
517
|
+
Whether the selection should be scrolled into view after this
|
|
518
|
+
transaction is dispatched.
|
|
519
|
+
*/scrollIntoView){this.startState=startState,this.changes=changes,this.selection=selection,this.effects=effects,this.annotations=annotations,this.scrollIntoView=scrollIntoView,this._doc=null,this._state=null,selection&&checkSelection(selection,changes.newLength),annotations.some(a=>a.type==Transaction.time)||(this.annotations=annotations.concat(Transaction.time.of(Date.now())))}/**
|
|
520
|
+
@internal
|
|
521
|
+
*/static create(startState,changes,selection,effects,annotations,scrollIntoView){return new Transaction(startState,changes,selection,effects,annotations,scrollIntoView)}/**
|
|
522
|
+
The new document produced by the transaction. Contrary to
|
|
523
|
+
[`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
|
|
524
|
+
force the entire new state to be computed right away, so it is
|
|
525
|
+
recommended that [transaction
|
|
526
|
+
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
|
|
527
|
+
when they need to look at the new document.
|
|
528
|
+
*/get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}/**
|
|
529
|
+
The new selection produced by the transaction. If
|
|
530
|
+
[`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
|
|
531
|
+
this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
|
|
532
|
+
current selection through the changes made by the transaction.
|
|
533
|
+
*/get newSelection(){return this.selection||this.startState.selection.map(this.changes)}/**
|
|
534
|
+
The new state created by the transaction. Computed on demand
|
|
535
|
+
(but retained for subsequent access), so it is recommended not to
|
|
536
|
+
access it in [transaction
|
|
537
|
+
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
|
|
538
|
+
*/get state(){return this._state||this.startState.applyTransaction(this),this._state}/**
|
|
539
|
+
Get the value of the given annotation type, if any.
|
|
540
|
+
*/annotation(type){for(let ann of this.annotations)if(ann.type==type)return ann.value}/**
|
|
541
|
+
Indicates whether the transaction changed the document.
|
|
542
|
+
*/get docChanged(){return!this.changes.empty}/**
|
|
543
|
+
Indicates whether this transaction reconfigures the state
|
|
544
|
+
(through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
|
|
545
|
+
with a top-level configuration
|
|
546
|
+
[effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
|
|
547
|
+
*/get reconfigured(){return this.startState.config!=this.state.config}/**
|
|
548
|
+
Returns true if the transaction has a [user
|
|
549
|
+
event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
|
|
550
|
+
or more specific than `event`. For example, if the transaction
|
|
551
|
+
has `"select.pointer"` as user event, `"select"` and
|
|
552
|
+
`"select.pointer"` will match it.
|
|
553
|
+
*/isUserEvent(event){let e=this.annotation(Transaction.userEvent);return!!(e&&(e==event||e.length>event.length&&e.slice(0,event.length)==event&&"."==e[event.length]))}}/**
|
|
554
|
+
Annotation used to store transaction timestamps. Automatically
|
|
555
|
+
added to every transaction, holding `Date.now()`.
|
|
556
|
+
*/Transaction.time=Annotation.define(),Transaction.userEvent=Annotation.define(),Transaction.addToHistory=Annotation.define(),Transaction.remote=Annotation.define();const none=[];exports.CharCategory=void 0,function(CharCategory){CharCategory[CharCategory.Word=0]="Word",CharCategory[CharCategory.Space=1]="Space",CharCategory[CharCategory.Other=2]="Other"}(exports.CharCategory||(exports.CharCategory={}));const nonASCIISingleCaseWordChar=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let wordChar;try{wordChar=/[\p{Alphabetic}\p{Number}_]/u}catch(_){}class EditorState{constructor(/**
|
|
557
|
+
@internal
|
|
558
|
+
*/config,/**
|
|
559
|
+
The current document.
|
|
560
|
+
*/doc,/**
|
|
561
|
+
The current selection.
|
|
562
|
+
*/selection,/**
|
|
563
|
+
@internal
|
|
564
|
+
*/values,computeSlot,tr){this.config=config,this.doc=doc,this.selection=selection,this.values=values,this.status=config.statusTemplate.slice(),this.computeSlot=computeSlot,tr&&(tr._state=this);for(let i=0;i<this.config.dynamicSlots.length;i++)ensureAddr(this,i<<1);this.computeSlot=null}field(field,require=!0){let addr=this.config.address[field.id];if(null==addr){if(require)throw new RangeError("Field is not present in this state");return}return ensureAddr(this,addr),getAddr(this,addr)}/**
|
|
565
|
+
Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
|
|
566
|
+
state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
|
|
567
|
+
can be passed. Unless
|
|
568
|
+
[`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
|
|
569
|
+
[changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
|
|
570
|
+
are assumed to start in the _current_ document (not the document
|
|
571
|
+
produced by previous specs), and its
|
|
572
|
+
[selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
|
|
573
|
+
[effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
|
|
574
|
+
to the document created by its _own_ changes. The resulting
|
|
575
|
+
transaction contains the combined effect of all the different
|
|
576
|
+
specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
|
|
577
|
+
specs take precedence over earlier ones.
|
|
578
|
+
*/update(...specs){return resolveTransaction(this,specs,!0)}/**
|
|
579
|
+
@internal
|
|
580
|
+
*/applyTransaction(tr){let conf=this.config,{base,compartments}=conf;for(let effect of tr.effects)effect.is(Compartment.reconfigure)?(conf&&(compartments=new Map,conf.compartments.forEach((val,key)=>compartments.set(key,val)),conf=null),compartments.set(effect.value.compartment,effect.value.extension)):effect.is(StateEffect.reconfigure)?(conf=null,base=effect.value):effect.is(StateEffect.appendConfig)&&(conf=null,base=asArray(base).concat(effect.value));let startValues;if(!conf){conf=Configuration.resolve(base,compartments,this);let intermediateState=new EditorState(conf,this.doc,this.selection,conf.dynamicSlots.map(()=>null),(state,slot)=>slot.reconfigure(state,this),null);startValues=intermediateState.values}else startValues=tr.startState.values.slice();let selection=tr.startState.facet(allowMultipleSelections)?tr.newSelection:tr.newSelection.asSingle();new EditorState(conf,tr.newDoc,selection,startValues,(state,slot)=>slot.update(state,tr),tr)}/**
|
|
581
|
+
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
582
|
+
replaces every selection range with the given content.
|
|
583
|
+
*/replaceSelection(text){return"string"==typeof text&&(text=this.toText(text)),this.changeByRange(range=>({changes:{from:range.from,to:range.to,insert:text},range:EditorSelection.cursor(range.from+text.length)}))}/**
|
|
584
|
+
Create a set of changes and a new selection by running the given
|
|
585
|
+
function for each range in the active selection. The function
|
|
586
|
+
can return an optional set of changes (in the coordinate space
|
|
587
|
+
of the start document), plus an updated range (in the coordinate
|
|
588
|
+
space of the document produced by the call's own changes). This
|
|
589
|
+
method will merge all the changes and ranges into a single
|
|
590
|
+
changeset and selection, and return it as a [transaction
|
|
591
|
+
spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
|
|
592
|
+
[`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
|
|
593
|
+
*/changeByRange(f){let sel=this.selection,result1=f(sel.ranges[0]),changes=this.changes(result1.changes),ranges=[result1.range],effects=asArray(result1.effects);for(let i=1;i<sel.ranges.length;i++){let result=f(sel.ranges[i]),newChanges=this.changes(result.changes),newMapped=newChanges.map(changes);for(let j=0;j<i;j++)ranges[j]=ranges[j].map(newMapped);let mapBy=changes.mapDesc(newChanges,!0);ranges.push(result.range.map(mapBy)),changes=changes.compose(newMapped),effects=StateEffect.mapEffects(effects,newMapped).concat(StateEffect.mapEffects(asArray(result.effects),mapBy))}return{changes,selection:EditorSelection.create(ranges,sel.mainIndex),effects}}/**
|
|
594
|
+
Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
|
|
595
|
+
description, taking the state's document length and line
|
|
596
|
+
separator into account.
|
|
597
|
+
*/changes(spec=[]){return spec instanceof ChangeSet?spec:ChangeSet.of(spec,this.doc.length,this.facet(EditorState.lineSeparator))}/**
|
|
598
|
+
Using the state's [line
|
|
599
|
+
separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
|
|
600
|
+
[`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
|
|
601
|
+
*/toText(string){return Text.of(string.split(this.facet(EditorState.lineSeparator)||DefaultSplit))}/**
|
|
602
|
+
Return the given range of the document as a string.
|
|
603
|
+
*/sliceDoc(from=0,to=this.doc.length){return this.doc.sliceString(from,to,this.lineBreak)}/**
|
|
604
|
+
Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
|
|
605
|
+
*/facet(facet){let addr=this.config.address[facet.id];return null==addr?facet.default:(ensureAddr(this,addr),getAddr(this,addr))}/**
|
|
606
|
+
Convert this state to a JSON-serializable object. When custom
|
|
607
|
+
fields should be serialized, you can pass them in as an object
|
|
608
|
+
mapping property names (in the resulting object, which should
|
|
609
|
+
not use `doc` or `selection`) to fields.
|
|
610
|
+
*/toJSON(fields){let result={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(fields)for(let prop in fields){let value=fields[prop];value instanceof StateField&&null!=this.config.address[value.id]&&(result[prop]=value.spec.toJSON(this.field(fields[prop]),this))}return result}/**
|
|
611
|
+
Deserialize a state from its JSON representation. When custom
|
|
612
|
+
fields should be deserialized, pass the same object you passed
|
|
613
|
+
to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
|
|
614
|
+
third argument.
|
|
615
|
+
*/static fromJSON(json,config={},fields){if(!json||"string"!=typeof json.doc)throw new RangeError("Invalid JSON representation for EditorState");let fieldInit=[];if(fields)for(let prop in fields)if(Object.prototype.hasOwnProperty.call(json,prop)){let field=fields[prop],value=json[prop];fieldInit.push(field.init(state=>field.spec.fromJSON(value,state)))}return EditorState.create({doc:json.doc,selection:EditorSelection.fromJSON(json.selection),extensions:config.extensions?fieldInit.concat([config.extensions]):fieldInit})}/**
|
|
616
|
+
Create a new state. You'll usually only need this when
|
|
617
|
+
initializing an editor—updated states are created by applying
|
|
618
|
+
transactions.
|
|
619
|
+
*/static create(config={}){let configuration=Configuration.resolve(config.extensions||[],new Map),doc=config.doc instanceof Text?config.doc:Text.of((config.doc||"").split(configuration.staticFacet(EditorState.lineSeparator)||DefaultSplit)),selection=config.selection?config.selection instanceof EditorSelection?config.selection:EditorSelection.single(config.selection.anchor,config.selection.head):EditorSelection.single(0);return checkSelection(selection,doc.length),configuration.staticFacet(allowMultipleSelections)||(selection=selection.asSingle()),new EditorState(configuration,doc,selection,configuration.dynamicSlots.map(()=>null),(state,slot)=>slot.create(state),null)}/**
|
|
620
|
+
The size (in columns) of a tab in the document, determined by
|
|
621
|
+
the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
|
|
622
|
+
*/get tabSize(){return this.facet(EditorState.tabSize)}/**
|
|
623
|
+
Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
|
|
624
|
+
string for this state.
|
|
625
|
+
*/get lineBreak(){return this.facet(EditorState.lineSeparator)||"\n"}/**
|
|
626
|
+
Returns true when the editor is
|
|
627
|
+
[configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
|
|
628
|
+
*/get readOnly(){return this.facet(readOnly)}/**
|
|
629
|
+
Look up a translation for the given phrase (via the
|
|
630
|
+
[`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
|
|
631
|
+
original string if no translation is found.
|
|
632
|
+
|
|
633
|
+
If additional arguments are passed, they will be inserted in
|
|
634
|
+
place of markers like `$1` (for the first value) and `$2`, etc.
|
|
635
|
+
A single `$` is equivalent to `$1`, and `$$` will produce a
|
|
636
|
+
literal dollar sign.
|
|
637
|
+
*/phrase(phrase,...insert){for(let map of this.facet(EditorState.phrases))if(Object.prototype.hasOwnProperty.call(map,phrase)){phrase=map[phrase];break}return insert.length&&(phrase=phrase.replace(/\$(\$|\d*)/g,(m,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>insert.length?m:insert[n-1]})),phrase}/**
|
|
638
|
+
Find the values for a given language data field, provided by the
|
|
639
|
+
the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
|
|
640
|
+
|
|
641
|
+
Examples of language data fields are...
|
|
642
|
+
|
|
643
|
+
- [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
|
|
644
|
+
comment syntax.
|
|
645
|
+
- [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
|
|
646
|
+
for providing language-specific completion sources.
|
|
647
|
+
- [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
|
|
648
|
+
characters that should be considered part of words in this
|
|
649
|
+
language.
|
|
650
|
+
- [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
|
|
651
|
+
bracket closing behavior.
|
|
652
|
+
*/languageDataAt(name,pos,side=-1){let values=[];for(let provider of this.facet(languageData))for(let result of provider(this,pos,side))Object.prototype.hasOwnProperty.call(result,name)&&values.push(result[name]);return values}/**
|
|
653
|
+
Return a function that can categorize strings (expected to
|
|
654
|
+
represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
|
|
655
|
+
into one of:
|
|
656
|
+
|
|
657
|
+
- Word (contains an alphanumeric character or a character
|
|
658
|
+
explicitly listed in the local language's `"wordChars"`
|
|
659
|
+
language data, which should be a string)
|
|
660
|
+
- Space (contains only whitespace)
|
|
661
|
+
- Other (anything else)
|
|
662
|
+
*/charCategorizer(at){let chars=this.languageDataAt("wordChars",at);return makeCategorizer(chars.length?chars[0]:"")}/**
|
|
663
|
+
Find the word at the given position, meaning the range
|
|
664
|
+
containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
|
|
665
|
+
around it. If no word characters are adjacent to the position,
|
|
666
|
+
this returns null.
|
|
667
|
+
*/wordAt(pos){let{text,from,length}=this.doc.lineAt(pos),cat=this.charCategorizer(pos),start=pos-from,end=pos-from;for(;0<start;){let prev=findClusterBreak(text,start,!1);if(cat(text.slice(prev,start))!=exports.CharCategory.Word)break;start=prev}for(;end<length;){let next=findClusterBreak(text,end);if(cat(text.slice(end,next))!=exports.CharCategory.Word)break;end=next}return start==end?null:EditorSelection.range(start+from,end+from)}}/**
|
|
668
|
+
A facet that, when enabled, causes the editor to allow multiple
|
|
669
|
+
ranges to be selected. Be careful though, because by default the
|
|
670
|
+
editor relies on the native DOM selection, which cannot handle
|
|
671
|
+
multiple selections. An extension like
|
|
672
|
+
[`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) can be used to make
|
|
673
|
+
secondary selections visible to the user.
|
|
674
|
+
*/EditorState.allowMultipleSelections=allowMultipleSelections,EditorState.tabSize=Facet.define({combine:values=>values.length?values[0]:4}),EditorState.lineSeparator=lineSeparator,EditorState.readOnly=readOnly,EditorState.phrases=Facet.define({compare(a,b){let kA=Object.keys(a),kB=Object.keys(b);return kA.length==kB.length&&kA.every(k=>a[k]==b[k])}}),EditorState.languageData=languageData,EditorState.changeFilter=changeFilter,EditorState.transactionFilter=transactionFilter,EditorState.transactionExtender=transactionExtender,Compartment.reconfigure=StateEffect.define();class RangeValue{/**
|
|
675
|
+
Compare this value with another value. Used when comparing
|
|
676
|
+
rangesets. The default implementation compares by identity.
|
|
677
|
+
Unless you are only creating a fixed number of unique instances
|
|
678
|
+
of your value type, it is a good idea to implement this
|
|
679
|
+
properly.
|
|
680
|
+
*/eq(other){return this==other}/**
|
|
681
|
+
Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
|
|
682
|
+
*/range(from,to=from){return Range.create(from,to,this)}}RangeValue.prototype.startSide=RangeValue.prototype.endSide=0,RangeValue.prototype.point=!1,RangeValue.prototype.mapMode=exports.MapMode.TrackDel;class Range{constructor(/**
|
|
683
|
+
The range's start position.
|
|
684
|
+
*/from,/**
|
|
685
|
+
Its end position.
|
|
686
|
+
*/to,/**
|
|
687
|
+
The value associated with this range.
|
|
688
|
+
*/value){this.from=from,this.to=to,this.value=value}/**
|
|
689
|
+
@internal
|
|
690
|
+
*/static create(from,to,value){return new Range(from,to,value)}}class Chunk{constructor(from,to,value,// Chunks are marked with the largest point that occurs
|
|
691
|
+
// in them (or -1 for no points), so that scans that are
|
|
692
|
+
// only interested in points (such as the
|
|
693
|
+
// heightmap-related logic) can skip range-only chunks.
|
|
694
|
+
maxPoint){this.from=from,this.to=to,this.value=value,this.maxPoint=maxPoint}get length(){return this.to[this.to.length-1]}// Find the index of the given position and side. Use the ranges'
|
|
695
|
+
// `from` pos when `end == false`, `to` when `end == true`.
|
|
696
|
+
findIndex(pos,side,end,startAt=0){let arr=end?this.to:this.from;for(let lo=startAt,hi=arr.length;;){if(lo==hi)return lo;let mid=lo+hi>>1,diff=arr[mid]-pos||(end?this.value[mid].endSide:this.value[mid].startSide)-side;if(mid==lo)return 0<=diff?lo:hi;0<=diff?hi=mid:lo=mid+1}}between(offset,from,to,f){for(let i=this.findIndex(from,-1e9/* C.Far */,!0),e=this.findIndex(to,1e9/* C.Far */,!1,i);i<e;i++)if(!1===f(this.from[i]+offset,this.to[i]+offset,this.value[i]))return!1}map(offset,changes){let value=[],from=[],to=[],newPos=-1,maxPoint=-1;for(let i=0;i<this.value.length;i++){let newFrom,newTo,val=this.value[i],curFrom=this.from[i]+offset,curTo=this.to[i]+offset;if(curFrom==curTo){let mapped=changes.mapPos(curFrom,val.startSide,val.mapMode);if(null==mapped)continue;if(newFrom=newTo=mapped,val.startSide!=val.endSide&&(newTo=changes.mapPos(curFrom,val.endSide),newTo<newFrom))continue}else if(newFrom=changes.mapPos(curFrom,val.startSide),newTo=changes.mapPos(curTo,val.endSide),newFrom>newTo||newFrom==newTo&&0<val.startSide&&0>=val.endSide)continue;0>(newTo-newFrom||val.endSide-val.startSide)||(0>newPos&&(newPos=newFrom),val.point&&(maxPoint=Math.max(maxPoint,newTo-newFrom)),value.push(val),from.push(newFrom-newPos),to.push(newTo-newPos))}return{mapped:value.length?new Chunk(from,to,value,maxPoint):null,pos:newPos}}}/**
|
|
697
|
+
A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a
|
|
698
|
+
way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and
|
|
699
|
+
[update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data
|
|
700
|
+
structure.
|
|
701
|
+
*/class RangeSet{constructor(/**
|
|
702
|
+
@internal
|
|
703
|
+
*/chunkPos,/**
|
|
704
|
+
@internal
|
|
705
|
+
*/chunk,/**
|
|
706
|
+
@internal
|
|
707
|
+
*/nextLayer,/**
|
|
708
|
+
@internal
|
|
709
|
+
*/maxPoint){this.chunkPos=chunkPos,this.chunk=chunk,this.nextLayer=nextLayer,this.maxPoint=maxPoint}/**
|
|
710
|
+
@internal
|
|
711
|
+
*/static create(chunkPos,chunk,nextLayer,maxPoint){return new RangeSet(chunkPos,chunk,nextLayer,maxPoint)}/**
|
|
712
|
+
@internal
|
|
713
|
+
*/get length(){let last=this.chunk.length-1;return 0>last?0:Math.max(this.chunkEnd(last),this.nextLayer.length)}/**
|
|
714
|
+
The number of ranges in the set.
|
|
715
|
+
*/get size(){if(this.isEmpty)return 0;let size=this.nextLayer.size;for(let chunk of this.chunk)size+=chunk.value.length;return size}/**
|
|
716
|
+
@internal
|
|
717
|
+
*/chunkEnd(index){return this.chunkPos[index]+this.chunk[index].length}/**
|
|
718
|
+
Update the range set, optionally adding new ranges or filtering
|
|
719
|
+
out existing ones.
|
|
720
|
+
|
|
721
|
+
(Note: The type parameter is just there as a kludge to work
|
|
722
|
+
around TypeScript variance issues that prevented `RangeSet<X>`
|
|
723
|
+
from being a subtype of `RangeSet<Y>` when `X` is a subtype of
|
|
724
|
+
`Y`.)
|
|
725
|
+
*/update(updateSpec){let{add=[],sort=!1,filterFrom=0,filterTo=this.length}=updateSpec,filter=updateSpec.filter;if(0==add.length&&!filter)return this;if(sort&&(add=add.slice().sort(cmpRange)),this.isEmpty)return add.length?RangeSet.of(add):this;let cur=new LayerCursor(this,null,-1).goto(0),i=0,spill=[],builder=new RangeSetBuilder;for(;cur.value||i<add.length;)if(i<add.length&&0<=(cur.from-add[i].from||cur.startSide-add[i].value.startSide)){let range=add[i++];builder.addInner(range.from,range.to,range.value)||spill.push(range)}else 1==cur.rangeIndex&&cur.chunkIndex<this.chunk.length&&(i==add.length||this.chunkEnd(cur.chunkIndex)<add[i].from)&&(!filter||filterFrom>this.chunkEnd(cur.chunkIndex)||filterTo<this.chunkPos[cur.chunkIndex])&&builder.addChunk(this.chunkPos[cur.chunkIndex],this.chunk[cur.chunkIndex])?cur.nextChunk():((!filter||filterFrom>cur.to||filterTo<cur.from||filter(cur.from,cur.to,cur.value))&&!builder.addInner(cur.from,cur.to,cur.value)&&spill.push(Range.create(cur.from,cur.to,cur.value)),cur.next());return builder.finishInner(this.nextLayer.isEmpty&&!spill.length?RangeSet.empty:this.nextLayer.update({add:spill,filter,filterFrom,filterTo}))}/**
|
|
726
|
+
Map this range set through a set of changes, return the new set.
|
|
727
|
+
*/map(changes){if(changes.empty||this.isEmpty)return this;let chunks=[],chunkPos=[],maxPoint=-1;for(let i=0;i<this.chunk.length;i++){let start=this.chunkPos[i],chunk=this.chunk[i],touch=changes.touchesRange(start,start+chunk.length);if(!1===touch)maxPoint=Math.max(maxPoint,chunk.maxPoint),chunks.push(chunk),chunkPos.push(changes.mapPos(start));else if(!0===touch){let{mapped,pos}=chunk.map(start,changes);mapped&&(maxPoint=Math.max(maxPoint,mapped.maxPoint),chunks.push(mapped),chunkPos.push(pos))}}let next=this.nextLayer.map(changes);return 0==chunks.length?next:new RangeSet(chunkPos,chunks,next||RangeSet.empty,maxPoint)}/**
|
|
728
|
+
Iterate over the ranges that touch the region `from` to `to`,
|
|
729
|
+
calling `f` for each. There is no guarantee that the ranges will
|
|
730
|
+
be reported in any specific order. When the callback returns
|
|
731
|
+
`false`, iteration stops.
|
|
732
|
+
*/between(from,to,f){if(!this.isEmpty){for(let i=0;i<this.chunk.length;i++){let start=this.chunkPos[i],chunk=this.chunk[i];if(to>=start&&from<=start+chunk.length&&!1===chunk.between(start,from-start,to-start,f))return}this.nextLayer.between(from,to,f)}}/**
|
|
733
|
+
Iterate over the ranges in this set, in order, including all
|
|
734
|
+
ranges that end at or after `from`.
|
|
735
|
+
*/iter(from=0){return HeapCursor.from([this]).goto(from)}/**
|
|
736
|
+
@internal
|
|
737
|
+
*/get isEmpty(){return this.nextLayer==this}/**
|
|
738
|
+
Iterate over the ranges in a collection of sets, in order,
|
|
739
|
+
starting from `from`.
|
|
740
|
+
*/static iter(sets,from=0){return HeapCursor.from(sets).goto(from)}/**
|
|
741
|
+
Iterate over two groups of sets, calling methods on `comparator`
|
|
742
|
+
to notify it of possible differences.
|
|
743
|
+
*/static compare(oldSets,newSets,/**
|
|
744
|
+
This indicates how the underlying data changed between these
|
|
745
|
+
ranges, and is needed to synchronize the iteration.
|
|
746
|
+
*/textDiff,comparator,/**
|
|
747
|
+
Can be used to ignore all non-point ranges, and points below
|
|
748
|
+
the given size. When -1, all ranges are compared.
|
|
749
|
+
*/minPointSize=-1){let a=oldSets.filter(set=>0<set.maxPoint||!set.isEmpty&&set.maxPoint>=minPointSize),b=newSets.filter(set=>0<set.maxPoint||!set.isEmpty&&set.maxPoint>=minPointSize),sharedChunks=findSharedChunks(a,b,textDiff),sideA=new SpanCursor(a,sharedChunks,minPointSize),sideB=new SpanCursor(b,sharedChunks,minPointSize);textDiff.iterGaps((fromA,fromB,length)=>compare(sideA,fromA,sideB,fromB,length,comparator)),textDiff.empty&&0==textDiff.length&&compare(sideA,0,sideB,0,0,comparator)}/**
|
|
750
|
+
Compare the contents of two groups of range sets, returning true
|
|
751
|
+
if they are equivalent in the given range.
|
|
752
|
+
*/static eq(oldSets,newSets,from=0,to){null==to&&(to=999999999);let a=oldSets.filter(set=>!set.isEmpty&&0>newSets.indexOf(set)),b=newSets.filter(set=>!set.isEmpty&&0>oldSets.indexOf(set));if(a.length!=b.length)return!1;if(!a.length)return!0;let sharedChunks=findSharedChunks(a,b),sideA=new SpanCursor(a,sharedChunks,0).goto(from),sideB=new SpanCursor(b,sharedChunks,0).goto(from);for(;;){if(sideA.to!=sideB.to||!sameValues(sideA.active,sideB.active)||sideA.point&&(!sideB.point||!cmpVal(sideA.point,sideB.point)))return!1;if(sideA.to>to)return!0;sideA.next(),sideB.next()}}/**
|
|
753
|
+
Iterate over a group of range sets at the same time, notifying
|
|
754
|
+
the iterator about the ranges covering every given piece of
|
|
755
|
+
content. Returns the open count (see
|
|
756
|
+
[`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
|
|
757
|
+
of the iteration.
|
|
758
|
+
*/static spans(sets,from,to,iterator,/**
|
|
759
|
+
When given and greater than -1, only points of at least this
|
|
760
|
+
size are taken into account.
|
|
761
|
+
*/minPointSize=-1){let cursor=new SpanCursor(sets,null,minPointSize).goto(from),pos=from,openRanges=cursor.openStart;for(;;){let curTo=Math.min(cursor.to,to);if(cursor.point){let active=cursor.activeForPoint(cursor.to),openCount=cursor.pointFrom<from?active.length+1:0>cursor.point.startSide?active.length:Math.min(active.length,openRanges);iterator.point(pos,curTo,cursor.point,active,openCount,cursor.pointRank),openRanges=Math.min(cursor.openEnd(curTo),active.length)}else curTo>pos&&(iterator.span(pos,curTo,cursor.active,openRanges),openRanges=cursor.openEnd(curTo));if(cursor.to>to)return openRanges+(cursor.point&&cursor.to>to?1:0);pos=cursor.to,cursor.next()}}/**
|
|
762
|
+
Create a range set for the given range or array of ranges. By
|
|
763
|
+
default, this expects the ranges to be _sorted_ (by start
|
|
764
|
+
position and, if two start at the same position,
|
|
765
|
+
`value.startSide`). You can pass `true` as second argument to
|
|
766
|
+
cause the method to sort them.
|
|
767
|
+
*/static of(ranges,sort=!1){let build=new RangeSetBuilder;for(let range of ranges instanceof Range?[ranges]:sort?lazySort(ranges):ranges)build.add(range.from,range.to,range.value);return build.finish()}/**
|
|
768
|
+
Join an array of range sets into a single set.
|
|
769
|
+
*/static join(sets){if(!sets.length)return RangeSet.empty;let result=sets[sets.length-1];for(let i=sets.length-2;0<=i;i--)for(let layer=sets[i];layer!=RangeSet.empty;layer=layer.nextLayer)result=new RangeSet(layer.chunkPos,layer.chunk,result,Math.max(layer.maxPoint,result.maxPoint));return result}}/**
|
|
770
|
+
The empty set of ranges.
|
|
771
|
+
*/RangeSet.empty=new RangeSet([],[],null,-1),RangeSet.empty.nextLayer=RangeSet.empty;/**
|
|
772
|
+
A range set builder is a data structure that helps build up a
|
|
773
|
+
[range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating
|
|
774
|
+
an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
|
|
775
|
+
*/class RangeSetBuilder{finishChunk(newArrays){this.chunks.push(new Chunk(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,newArrays&&(this.from=[],this.to=[],this.value=[])}/**
|
|
776
|
+
Create an empty builder.
|
|
777
|
+
*/constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9/* C.Far */,this.lastTo=-1e9/* C.Far */,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}/**
|
|
778
|
+
Add a range. Ranges should be added in sorted (by `from` and
|
|
779
|
+
`value.startSide`) order.
|
|
780
|
+
*/add(from,to,value){this.addInner(from,to,value)||(this.nextLayer||(this.nextLayer=new RangeSetBuilder)).add(from,to,value)}/**
|
|
781
|
+
@internal
|
|
782
|
+
*/addInner(from,to,value){let diff=from-this.lastTo||value.startSide-this.last.endSide;if(0>=diff&&0>(from-this.lastFrom||value.startSide-this.last.startSide))throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(0>diff)&&(250==this.from.length/* C.ChunkSize */&&this.finishChunk(!0),0>this.chunkStart&&(this.chunkStart=from),this.from.push(from-this.chunkStart),this.to.push(to-this.chunkStart),this.last=value,this.lastFrom=from,this.lastTo=to,this.value.push(value),value.point&&(this.maxPoint=Math.max(this.maxPoint,to-from)),!0)}/**
|
|
783
|
+
@internal
|
|
784
|
+
*/addChunk(from,chunk){if(0>(from-this.lastTo||chunk.value[0].startSide-this.last.endSide))return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,chunk.maxPoint),this.chunks.push(chunk),this.chunkPos.push(from);let last=chunk.value.length-1;return this.last=chunk.value[last],this.lastFrom=chunk.from[last]+from,this.lastTo=chunk.to[last]+from,!0}/**
|
|
785
|
+
Finish the range set. Returns the new set. The builder can't be
|
|
786
|
+
used anymore after this has been called.
|
|
787
|
+
*/finish(){return this.finishInner(RangeSet.empty)}/**
|
|
788
|
+
@internal
|
|
789
|
+
*/finishInner(next){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return next;let result=RangeSet.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(next):next,this.setMaxPoint);// Make sure further `add` calls produce errors
|
|
790
|
+
return this.from=null,result}}class LayerCursor{constructor(layer,skip,minPoint,rank=0){this.layer=layer,this.skip=skip,this.minPoint=minPoint,this.rank=rank}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(pos,side=-1e9/* C.Far */){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(pos,side,!1),this}gotoInner(pos,side,forward){for(;this.chunkIndex<this.layer.chunk.length;){let next=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(next)||this.layer.chunkEnd(this.chunkIndex)<pos||next.maxPoint<this.minPoint))break;this.chunkIndex++,forward=!1}if(this.chunkIndex<this.layer.chunk.length){let rangeIndex=this.layer.chunk[this.chunkIndex].findIndex(pos-this.layer.chunkPos[this.chunkIndex],side,!0);(!forward||this.rangeIndex<rangeIndex)&&this.setRangeIndex(rangeIndex)}this.next()}forward(pos,side){0>(this.to-pos||this.endSide-side)&&this.gotoInner(pos,side,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9/* C.Far */,this.value=null;break}else{let chunkPos=this.layer.chunkPos[this.chunkIndex],chunk=this.layer.chunk[this.chunkIndex],from=chunkPos+chunk.from[this.rangeIndex];if(this.from=from,this.to=chunkPos+chunk.to[this.rangeIndex],this.value=chunk.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),0>this.minPoint||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(index){if(index==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=index}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(other){return this.from-other.from||this.startSide-other.startSide||this.rank-other.rank||this.to-other.to||this.endSide-other.endSide}}class HeapCursor{constructor(heap){this.heap=heap}static from(sets,skip=null,minPoint=-1){let heap=[];for(let i=0;i<sets.length;i++)for(let cur=sets[i];!cur.isEmpty;cur=cur.nextLayer)cur.maxPoint>=minPoint&&heap.push(new LayerCursor(cur,skip,minPoint,i));return 1==heap.length?heap[0]:new HeapCursor(heap)}get startSide(){return this.value?this.value.startSide:0}goto(pos,side=-1e9/* C.Far */){for(let cur of this.heap)cur.goto(pos,side);for(let i=this.heap.length>>1;0<=i;i--)heapBubble(this.heap,i);return this.next(),this}forward(pos,side){for(let cur of this.heap)cur.forward(pos,side);for(let i=this.heap.length>>1;0<=i;i--)heapBubble(this.heap,i);0>(this.to-pos||this.value.endSide-side)&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9/* C.Far */,this.value=null,this.rank=-1;else{let top=this.heap[0];this.from=top.from,this.to=top.to,this.value=top.value,this.rank=top.rank,top.value&&top.next(),heapBubble(this.heap,0)}}}class SpanCursor{constructor(sets,skip,minPoint){this.minPoint=minPoint,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9/* C.Far */,this.endSide=0,this.openStart=-1,this.cursor=HeapCursor.from(sets,skip,minPoint)}goto(pos,side=-1e9/* C.Far */){return this.cursor.goto(pos,side),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=pos,this.endSide=side,this.openStart=-1,this.next(),this}forward(pos,side){for(;-1<this.minActive&&0>(this.activeTo[this.minActive]-pos||this.active[this.minActive].endSide-side);)this.removeActive(this.minActive);this.cursor.forward(pos,side)}removeActive(index){remove(this.active,index),remove(this.activeTo,index),remove(this.activeRank,index),this.minActive=findMinIndex(this.active,this.activeTo)}addActive(trackOpen){let i=0,{value,to,rank}=this.cursor;// Organize active marks by rank first, then by size
|
|
791
|
+
for(;i<this.activeRank.length&&0<(rank-this.activeRank[i]||to-this.activeTo[i]);)i++;insert(this.active,i,value),insert(this.activeTo,i,to),insert(this.activeRank,i,rank),trackOpen&&insert(trackOpen,i,this.cursor.from),this.minActive=findMinIndex(this.active,this.activeTo)}// After calling this, if `this.point` != null, the next range is a
|
|
792
|
+
// point. Otherwise, it's a regular range, covered by `this.active`.
|
|
793
|
+
next(){let from=this.to,wasPoint=this.point;this.point=null;let trackOpen=0>this.openStart?[]:null;for(;;){let a=this.minActive;if(-1<a&&0>(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)){if(this.activeTo[a]>from){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),trackOpen&&remove(trackOpen,a)}else if(!this.cursor.value){this.to=this.endSide=1e9/* C.Far */;break}else if(this.cursor.from>from){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let nextVal=this.cursor.value;if(!nextVal.point)this.addActive(trackOpen),this.cursor.next();else if(wasPoint&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=nextVal,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=nextVal.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}}if(trackOpen){this.openStart=0;for(let i=trackOpen.length-1;0<=i&&trackOpen[i]<from;i--)this.openStart++}}activeForPoint(to){if(!this.active.length)return this.active;let active=[];for(let i=this.active.length-1;0<=i&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>to||this.activeTo[i]==to&&this.active[i].endSide>=this.point.endSide)&&active.push(this.active[i]);return active.reverse()}openEnd(to){let open=0;for(let i=this.activeTo.length-1;0<=i&&this.activeTo[i]>to;i--)open++;return open}}exports.Annotation=Annotation,exports.AnnotationType=AnnotationType,exports.ChangeDesc=ChangeDesc,exports.ChangeSet=ChangeSet,exports.Compartment=Compartment,exports.EditorSelection=EditorSelection,exports.EditorState=EditorState,exports.Facet=Facet,exports.Line=Line,exports.Prec=Prec,exports.Range=Range,exports.RangeSet=RangeSet,exports.RangeSetBuilder=RangeSetBuilder,exports.RangeValue=RangeValue,exports.SelectionRange=SelectionRange,exports.StateEffect=StateEffect,exports.StateEffectType=StateEffectType,exports.StateField=StateField,exports.Text=Text,exports.Transaction=Transaction,exports.codePointAt=codePointAt,exports.codePointSize=codePointSize,exports.combineConfig=combineConfig,exports.countColumn=countColumn,exports.findClusterBreak=findClusterBreak,exports.findColumn=findColumn,exports.fromCodePoint=fromCodePoint}(dist),dist)}(),index=/*@__PURE__*/function getDefaultExportFromCjs(x){return x}(distExports);return module.exports=index,module.exports}
|