codemirror 6.0.2.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +23 -0
- data/LICENSE +28 -0
- data/README.md +210 -0
- data/app/assets/javascripts/codemirror/autocomplete.js +1 -0
- data/app/assets/javascripts/codemirror/commands.js +1 -0
- data/app/assets/javascripts/codemirror/index.js +1 -0
- data/app/assets/javascripts/codemirror/lang-angular.js +1 -0
- data/app/assets/javascripts/codemirror/lang-cpp.js +1 -0
- data/app/assets/javascripts/codemirror/lang-css.js +1 -0
- data/app/assets/javascripts/codemirror/lang-go.js +1 -0
- data/app/assets/javascripts/codemirror/lang-html.js +1 -0
- data/app/assets/javascripts/codemirror/lang-java.js +1 -0
- data/app/assets/javascripts/codemirror/lang-javascript.js +1 -0
- data/app/assets/javascripts/codemirror/lang-json.js +1 -0
- data/app/assets/javascripts/codemirror/lang-less.js +1 -0
- data/app/assets/javascripts/codemirror/lang-liquid.js +1 -0
- data/app/assets/javascripts/codemirror/lang-markdown.js +1 -0
- data/app/assets/javascripts/codemirror/lang-php.js +1 -0
- data/app/assets/javascripts/codemirror/lang-python.js +1 -0
- data/app/assets/javascripts/codemirror/lang-rust.js +1 -0
- data/app/assets/javascripts/codemirror/lang-sass.js +1 -0
- data/app/assets/javascripts/codemirror/lang-sql.js +1 -0
- data/app/assets/javascripts/codemirror/lang-vue.js +1 -0
- data/app/assets/javascripts/codemirror/lang-wast.js +1 -0
- data/app/assets/javascripts/codemirror/lang-xml.js +1 -0
- data/app/assets/javascripts/codemirror/lang-yaml.js +1 -0
- data/app/assets/javascripts/codemirror/language.js +1 -0
- data/app/assets/javascripts/codemirror/lezer-common.js +1 -0
- data/app/assets/javascripts/codemirror/lezer-highlight.js +1 -0
- data/app/assets/javascripts/codemirror/lezer-lr.js +1 -0
- data/app/assets/javascripts/codemirror/lint.js +1 -0
- data/app/assets/javascripts/codemirror/search.js +1 -0
- data/app/assets/javascripts/codemirror/state.js +1 -0
- data/app/assets/javascripts/codemirror/theme-one-dark.js +1 -0
- data/app/assets/javascripts/codemirror/view.js +1 -0
- data/config/importmap.rb +46 -0
- data/lib/codemirror/engine.rb +24 -0
- data/lib/codemirror/version.rb +18 -0
- data/lib/codemirror.rb +7 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e86859addf6064dc51c565913234881cf1f4c78766636e275ad1f04a668dcb85
|
|
4
|
+
data.tar.gz: e7176f442c4738b12226f8b04932f9ec7e0e11e9cab7ea62ce8aac563b9efee7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9408ad78d5617c274921124f28519c49e0a328762636bcc12d895019325ca118f687b323280a2556732a2e2367cf0a6e64ffd6bbb997cf33edef4108ea78af69
|
|
7
|
+
data.tar.gz: 7949a9018a74c6fed101840957a5499b5eb569ff1897b10bca9e8ce9e026a00defa0ded93bfb63007b1bef6c30cfdd6ff40ba8bb1de1b831e0fb3a1b4e416b72
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this gem are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
The gem version tracks the bundled CodeMirror version with an extra build
|
|
11
|
+
segment (`<codemirror version>.<build>`), so the first release is `6.0.2.0`.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Initial release.
|
|
16
|
+
- Prebuilt CodeMirror 6 ES modules served through the Rails asset pipeline
|
|
17
|
+
(Propshaft or Sprockets).
|
|
18
|
+
- Import-map pins for the CodeMirror core, the One Dark theme, and 20 language
|
|
19
|
+
packages (`config/importmap.rb`), merged automatically when importmap-rails
|
|
20
|
+
is installed.
|
|
21
|
+
- `npm --prefix build run update` to bump, rebuild, and re-pin the bundled
|
|
22
|
+
CodeMirror packages.
|
|
23
|
+
- Bundled from CodeMirror `6.0.2`.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 desheikh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The bundled JavaScript in app/assets/javascripts/codemirror/ is built from the
|
|
26
|
+
CodeMirror 6 packages, which are distributed under the MIT License.
|
|
27
|
+
Copyright (C) 2018-2024 by Marijn Haverbeke and others.
|
|
28
|
+
See https://codemirror.net/ for details.
|
data/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# codemirror
|
|
2
|
+
|
|
3
|
+
The [CodeMirror 6](https://codemirror.net/) editor, packaged as Rails assets.
|
|
4
|
+
|
|
5
|
+
Point being: you can drop a real code editor into a Rails app without adding
|
|
6
|
+
Node, a bundler, or a build step. Install the gem, import from `"codemirror"`
|
|
7
|
+
in your JavaScript, done. It's built for the Propshaft + import map setup that
|
|
8
|
+
ships with Rails 7.1 and 8.
|
|
9
|
+
|
|
10
|
+
The old `codemirror-rails` gem stopped at CodeMirror 5 years ago. This is a
|
|
11
|
+
fresh start for CodeMirror 6.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
# Gemfile
|
|
17
|
+
gem "codemirror"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
bundle install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires Ruby 4.0+. That's the whole setup. The gem registers its assets with
|
|
25
|
+
the pipeline and adds its pins to your import map automatically, so there's
|
|
26
|
+
nothing to configure. If you want to double-check the pins landed:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
bin/importmap json | grep codemirror
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You'll want `propshaft` and `importmap-rails`, which are already there in a
|
|
33
|
+
default Rails app.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
Import from the usual CodeMirror package names, same as you would with npm:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// app/javascript/editor.js
|
|
41
|
+
import { EditorView, basicSetup } from "codemirror"
|
|
42
|
+
import { javascript } from "@codemirror/lang-javascript"
|
|
43
|
+
import { oneDark } from "@codemirror/theme-one-dark"
|
|
44
|
+
|
|
45
|
+
export function mountEditor(parent, doc = "") {
|
|
46
|
+
return new EditorView({
|
|
47
|
+
doc,
|
|
48
|
+
parent,
|
|
49
|
+
extensions: [basicSetup, javascript(), oneDark],
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Most of the time you'll want this behind a Stimulus controller, syncing the
|
|
55
|
+
editor into a hidden field so the form actually submits the code:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
// app/javascript/controllers/code_editor_controller.js
|
|
59
|
+
import { Controller } from "@hotwired/stimulus"
|
|
60
|
+
import { EditorView, basicSetup } from "codemirror"
|
|
61
|
+
import { EditorState } from "@codemirror/state"
|
|
62
|
+
import { javascript } from "@codemirror/lang-javascript"
|
|
63
|
+
import { oneDark } from "@codemirror/theme-one-dark"
|
|
64
|
+
|
|
65
|
+
export default class extends Controller {
|
|
66
|
+
static targets = ["input"]
|
|
67
|
+
|
|
68
|
+
connect() {
|
|
69
|
+
this.view = new EditorView({
|
|
70
|
+
state: EditorState.create({
|
|
71
|
+
doc: this.inputTarget.value,
|
|
72
|
+
extensions: [
|
|
73
|
+
basicSetup,
|
|
74
|
+
javascript(),
|
|
75
|
+
oneDark,
|
|
76
|
+
EditorView.updateListener.of((update) => {
|
|
77
|
+
if (update.docChanged) {
|
|
78
|
+
this.inputTarget.value = update.state.doc.toString()
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
}),
|
|
83
|
+
parent: this.element,
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
disconnect() {
|
|
88
|
+
this.view?.destroy()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```erb
|
|
94
|
+
<%# app/views/snippets/_form.html.erb %>
|
|
95
|
+
<div data-controller="code-editor">
|
|
96
|
+
<%= form.hidden_field :body, data: { code_editor_target: "input" } %>
|
|
97
|
+
</div>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## What's in the box
|
|
101
|
+
|
|
102
|
+
The core `codemirror` package (`basicSetup`, `minimalSetup`, `EditorView`), the
|
|
103
|
+
lower-level pieces it's built on (`@codemirror/state`, `view`, `language`,
|
|
104
|
+
`commands`, `search`, `autocomplete`, `lint`), the One Dark theme, and a bunch
|
|
105
|
+
of languages:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
import { javascript } from "@codemirror/lang-javascript" // + TypeScript, JSX
|
|
109
|
+
import { html } from "@codemirror/lang-html"
|
|
110
|
+
import { css } from "@codemirror/lang-css"
|
|
111
|
+
import { json } from "@codemirror/lang-json"
|
|
112
|
+
import { python } from "@codemirror/lang-python"
|
|
113
|
+
import { markdown } from "@codemirror/lang-markdown"
|
|
114
|
+
import { sql } from "@codemirror/lang-sql"
|
|
115
|
+
import { xml } from "@codemirror/lang-xml"
|
|
116
|
+
import { rust } from "@codemirror/lang-rust"
|
|
117
|
+
import { cpp } from "@codemirror/lang-cpp"
|
|
118
|
+
import { java } from "@codemirror/lang-java"
|
|
119
|
+
import { php } from "@codemirror/lang-php"
|
|
120
|
+
import { yaml } from "@codemirror/lang-yaml"
|
|
121
|
+
import { go } from "@codemirror/lang-go"
|
|
122
|
+
import { vue } from "@codemirror/lang-vue"
|
|
123
|
+
import { angular } from "@codemirror/lang-angular"
|
|
124
|
+
import { sass } from "@codemirror/lang-sass"
|
|
125
|
+
import { less } from "@codemirror/lang-less"
|
|
126
|
+
import { wast } from "@codemirror/lang-wast"
|
|
127
|
+
import { liquid } from "@codemirror/lang-liquid"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Every package is pinned individually, so nothing loads until you import it. Need
|
|
131
|
+
a keymap or a specific extension? Those specifiers work too:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
import { keymap } from "@codemirror/view"
|
|
135
|
+
import { indentWithTab } from "@codemirror/commands"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
If your language or extension isn't here, it's usually a one-line addition to
|
|
139
|
+
`build/package.json` followed by a rebuild — see below, or open an issue.
|
|
140
|
+
|
|
141
|
+
## Working on the gem
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
git clone git@github.com:desheikh/codemirror.git
|
|
145
|
+
cd codemirror
|
|
146
|
+
npm --prefix build install
|
|
147
|
+
bundle install
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The JavaScript is generated, not hand-written. `build/build.mjs` reads the
|
|
151
|
+
package list in `build/package.json` and writes both the modules and the pins:
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
npm --prefix build run build # -> app/assets/javascripts/codemirror/ + config/importmap.rb
|
|
155
|
+
MINIFY=0 npm --prefix build run build # unminified, for reading/debugging
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
There are two checks. `check` links the whole module graph the way a browser
|
|
159
|
+
would and builds a real editor state, which catches broken imports and the
|
|
160
|
+
duplicate-singleton problem. The Ruby tests make sure the pins and the shipped
|
|
161
|
+
files never drift apart.
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
npm --prefix build run check
|
|
165
|
+
bundle exec rake test
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Bumping CodeMirror
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
npm --prefix build run update
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
This pulls the latest of every bundled package, rebuilds everything, and points
|
|
175
|
+
`Codemirror::CODEMIRROR_VERSION` at the new release (resetting
|
|
176
|
+
`Codemirror::BUILD` to `0` if the CodeMirror version actually changed). Look
|
|
177
|
+
over the diff, run the two checks, and you're good.
|
|
178
|
+
|
|
179
|
+
## Versioning
|
|
180
|
+
|
|
181
|
+
The gem version follows the bundled CodeMirror version, with one extra number
|
|
182
|
+
for our own builds on top of it:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
6.0.2.0, 6.0.2.1, ... = <codemirror version>.<build>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`CODEMIRROR_VERSION` and `BUILD` live in `lib/codemirror/version.rb`. In
|
|
189
|
+
practice the build number does most of the moving, since upstream rarely bumps
|
|
190
|
+
the umbrella `codemirror` package even when the individual pieces change.
|
|
191
|
+
|
|
192
|
+
## Releasing
|
|
193
|
+
|
|
194
|
+
Releases are automated. Push a commit that bumps the version to `master` and
|
|
195
|
+
the [release workflow](.github/workflows/release.yml) does the rest: it notices
|
|
196
|
+
`Codemirror::VERSION` isn't on RubyGems yet, then builds, pushes, tags
|
|
197
|
+
`vX.Y.Z.B`, and cuts a GitHub release. Merges that don't change the version are
|
|
198
|
+
ignored, so there's no harm in it running on every push.
|
|
199
|
+
|
|
200
|
+
So a normal release is just:
|
|
201
|
+
|
|
202
|
+
1. `npm --prefix build run update` (or edit `build/package.json` and rebuild),
|
|
203
|
+
and commit the regenerated assets.
|
|
204
|
+
2. Bump `Codemirror::BUILD` if it's a new build for the same CodeMirror version.
|
|
205
|
+
3. Update `CHANGELOG.md`.
|
|
206
|
+
4. Merge to `master`.
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
MIT, same as CodeMirror itself. See `LICENSE`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{RangeValue as t,Annotation as e,EditorSelection as n,Transaction as i,Text as o,StateEffect as s,Facet as l,Prec as r,codePointSize as a,codePointAt as c,CharCategory as h,StateField as p,combineConfig as f,RangeSet as u,fromCodePoint as d,MapMode as m}from"@codemirror/state";import{getTooltip as g,keymap as v,EditorView as b,showTooltip as w,Decoration as y,ViewPlugin as x,logException as C,Direction as I,WidgetType as k}from"@codemirror/view";import{syntaxTree as O,indentUnit as D}from"@codemirror/language";class T{constructor(t,e,n,i){this.state=t,this.pos=e,this.explicit=n,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=O(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),n=Math.max(e.from,this.pos-250),i=e.text.slice(n-e.from,this.pos-e.from),o=i.search(P(t,!1));return o<0?null:{from:n+o,to:this.pos,text:i.slice(o)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,n){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),n&&n.onDocChange&&(this.abortOnDocChange=!0))}}function A(t){let e=Object.keys(t).join(""),n=/\w/.test(e);return n&&(e=e.replace(/\w/g,"")),`[${n?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function L(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[n,i]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),n=Object.create(null);for(let{label:i}of t){e[i[0]]=!0;for(let t=1;t<i.length;t++)n[i[t]]=!0}let i=A(e)+A(n)+"*$";return[new RegExp("^"+i),new RegExp(i)]}(e);return t=>{let o=t.matchBefore(i);return o||t.explicit?{from:o?o.from:t.pos,options:e,validFor:n}:null}}function R(t,e){return n=>{for(let i=O(n.state).resolveInner(n.pos,-1);i;i=i.parent){if(t.indexOf(i.name)>-1)return e(n);if(i.type.isTop)break}return null}}function S(t,e){return n=>{for(let e=O(n.state).resolveInner(n.pos,-1);e;e=e.parent){if(t.indexOf(e.name)>-1)return null;if(e.type.isTop)break}return e(n)}}class E{constructor(t,e,n,i){this.completion=t,this.source=e,this.match=n,this.score=i}}function M(t){return t.selection.main.from}function P(t,e){var n;let{source:i}=t,o=e&&"^"!=i[0],s="$"!=i[i.length-1];return o||s?new RegExp(`${o?"^":""}(?:${i})${s?"$":""}`,null!==(n=t.flags)&&void 0!==n?n:t.ignoreCase?"i":""):t}const B=e.define();function $(t,e,i,o){let{main:s}=t.selection,l=i-s.from,r=o-s.from;return{...t.changeByRange(a=>{if(a!=s&&i!=o&&t.sliceDoc(a.from+l,a.from+r)!=t.sliceDoc(i,o))return{range:a};let c=t.toText(e);return{changes:{from:a.from+l,to:o==s.from?a.to:a.from+r,insert:c},range:n.cursor(a.from+l+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const F=new WeakMap;function N(t){if(!Array.isArray(t))return t;let e=F.get(t);return e||F.set(t,e=L(t)),e}const U=s.define(),W=s.define();class q{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e<t.length;){let n=c(t,e),i=a(n);this.chars.push(n);let o=t.slice(e,e+i),s=o.toUpperCase();this.folded.push(c(s==o?o.toLowerCase():s,0)),e+=i}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(t){if(0==this.pattern.length)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:e,folded:n,any:i,precise:o,byWord:s}=this;if(1==e.length){let i=c(t,0),o=a(i),s=o==t.length?0:-100;if(i==e[0]);else{if(i!=n[0])return null;s+=-200}return this.ret(s,[0,o])}let l=t.indexOf(this.pattern);if(0==l)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let r=e.length,h=0;if(l<0){for(let o=0,s=Math.min(t.length,200);o<s&&h<r;){let s=c(t,o);s!=e[h]&&s!=n[h]||(i[h++]=o),o+=a(s)}if(h<r)return null}let p=0,f=0,u=!1,m=0,g=-1,v=-1,b=/[a-z]/.test(t),w=!0;for(let i=0,h=Math.min(t.length,200),y=0;i<h&&f<r;){let h=c(t,i);l<0&&(p<r&&h==e[p]&&(o[p++]=i),m<r&&(h==e[m]||h==n[m]?(0==m&&(g=i),v=i+1,m++):m=0));let x,C=h<255?h>=48&&h<=57||h>=97&&h<=122?2:h>=65&&h<=90?1:0:(x=d(h))!=x.toLowerCase()?1:x!=x.toUpperCase()?2:0;(!i||1==C&&b||0==y&&0!=C)&&(e[f]==h||n[f]==h&&(u=!0)?s[f++]=i:s.length&&(w=!1)),y=C,i+=a(h)}return f==r&&0==s[0]&&w?this.result((u?-200:0)-100,s,t):m==r&&0==g?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):m==r?this.ret(-900-t.length,[g,v]):f==r?this.result((u?-200:0)-100-700+(w?0:-1100),s,t):2==e.length?null:this.result((i[0]?-700:0)-200-1100,i,t)}result(t,e,n){let i=[],o=0;for(let t of e){let e=t+(this.astral?a(c(n,t)):1);o&&i[o-1]==t?i[o-1]=e:(i[o++]=t,i[o++]=e)}return this.ret(t-n.length,i)}}class j{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let e=t.slice(0,this.pattern.length),n=e==this.pattern?0:e.toLowerCase()==this.folded?-200:null;return null==n?null:(this.matched=[0,e.length],this.score=n+(t.length==this.pattern.length?0:-100),this)}}const H=l.define({combine:t=>f(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:z,filterStrict:!1,compareCompletions:(t,e)=>(t.sortText||t.label).localeCompare(e.sortText||e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>n=>V(t(n),e(n)),optionClass:(t,e)=>n=>V(t(n),e(n)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function V(t,e){return t?e?t+" "+e:t:e}function z(t,e,n,i,o,s){let l,r,a=t.textDirection==I.RTL,c=a,h=!1,p="top",f=e.left-o.left,u=o.right-e.right,d=i.right-i.left,m=i.bottom-i.top;if(c&&f<Math.min(d,u)?c=!1:!c&&u<Math.min(d,f)&&(c=!0),d<=(c?f:u))l=Math.max(o.top,Math.min(n.top,o.bottom-m))-e.top,r=Math.min(400,c?f:u);else{h=!0,r=Math.min(400,(a?e.right:o.right-e.left)-30);let t=o.bottom-e.bottom;t>=m||t>e.top?l=n.bottom-e.top:(p="bottom",l=e.bottom-n.top)}return{style:`${p}: ${l/((e.bottom-e.top)/s.offsetHeight)}px; max-width: ${r/((e.right-e.left)/s.offsetWidth)}px`,class:"cm-completionInfo-"+(h?a?"left-narrow":"right-narrow":c?"left":"right")}}const K=s.define();function Q(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/n);return{from:t*n,to:(t+1)*n}}let i=Math.ceil((t-e)/n);return{from:t-i*n,to:t-(i-1)*n}}class Y{constructor(t,e,n){this.view=t,this.stateField=e,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let i=t.state.field(e),{options:o,selected:s}=i.open,l=t.state.facet(H);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map(t=>"cm-completionIcon-"+t)),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,n,i){let o=document.createElement("span");o.className="cm-completionLabel";let s=t.displayLabel||t.label,l=0;for(let t=0;t<i.length;){let e=i[t++],n=i[t++];e>l&&o.appendChild(document.createTextNode(s.slice(l,e)));let r=o.appendChild(document.createElement("span"));r.appendChild(document.createTextNode(s.slice(e,n))),r.className="cm-completionMatchedText",l=n}return l<s.length&&o.appendChild(document.createTextNode(s.slice(l))),o},position:50},{render(t){if(!t.detail)return null;let e=document.createElement("span");return e.className="cm-completionDetail",e.textContent=t.detail,e},position:80}),e.sort((t,e)=>t.position-e.position).map(t=>t.render)}(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Q(o.length,s,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",n=>{let{options:i}=t.state.field(e).open;for(let e,o=n.target;o&&o!=this.dom;o=o.parentNode)if("LI"==o.nodeName&&(e=/-(\d+)$/.exec(o.id))&&+e[1]<i.length)return this.applyCompletion(t,i[+e[1]]),void n.preventDefault();if(n.target==this.list){let e=this.list.classList.contains("cm-completionListIncompleteTop")&&n.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&n.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;null!=e&&(t.dispatch({effects:K.of(e)}),n.preventDefault())}}),this.dom.addEventListener("focusout",e=>{let n=t.state.field(this.stateField,!1);n&&n.tooltip&&t.state.facet(H).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:W.of(null)})}),this.showOptions(o,i.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let n=t.state.field(this.stateField),i=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),n!=i){let{options:o,selected:s,disabled:l}=n.open;i.open&&i.open.options==o||(this.range=Q(o.length,s,t.state.facet(H).maxRenderedOptions),this.showOptions(o,n.id)),this.updateSel(),l!=(null===(e=i.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;(e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=Q(e.options.length,e.selected,this.view.state.facet(H).maxRenderedOptions),this.showOptions(e.options,t.id));let n=this.updateSelectedOption(e.selected);if(n){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:o}=i;if(!o)return;let s="string"==typeof o?document.createTextNode(o):o(i);if(!s)return;"then"in s?s.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,i)}).catch(t=>C(this.view.state,t,"completion info")):(this.addInfoPane(s,i),n.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,e){this.destroyInfo();let n=this.info=document.createElement("div");if(n.className="cm-tooltip cm-completionInfo",n.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=t.nodeType)n.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:i}=t;n.appendChild(e),this.infoDestroy=i||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let n=this.list.firstChild,i=this.range.from;n;n=n.nextSibling,i++)"LI"==n.nodeName&&n.id?i==t?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),e=n):n.hasAttribute("aria-selected")&&(n.removeAttribute("aria-selected"),n.removeAttribute("aria-describedby")):i--;return e&&function(t,e){let n=t.getBoundingClientRect(),i=e.getBoundingClientRect(),o=n.height/t.offsetHeight;i.top<n.top?t.scrollTop-=(n.top-i.top)/o:i.bottom>n.bottom&&(t.scrollTop+=(i.bottom-n.bottom)/o)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),i=t.getBoundingClientRect(),o=this.space;if(!o){let t=this.dom.ownerDocument.documentElement;o={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return i.top>Math.min(o.bottom,e.bottom)-10||i.bottom<Math.max(o.top,e.top)+10?null:this.view.state.facet(H).positionInfo(this.view,e,i,n,o,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,n){const i=document.createElement("ul");i.id=e,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",t=>{t.target==i&&t.preventDefault()});let o=null;for(let s=n.from;s<n.to;s++){let{completion:l,match:r}=t[s],{section:a}=l;if(a){let t="string"==typeof a?a:a.name;if(t!=o&&(s>n.from||0==n.from))if(o=t,"string"!=typeof a&&a.header)i.appendChild(a.header(a));else{i.appendChild(document.createElement("completion-section")).textContent=t}}const c=i.appendChild(document.createElement("li"));c.id=e+"-"+s,c.setAttribute("role","option");let h=this.optionClass(l);h&&(c.className=h);for(let t of this.optionContent){let e=t(l,this.view.state,this.view,r);e&&c.appendChild(e)}}return n.from&&i.classList.add("cm-completionListIncompleteTop"),n.to<t.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function X(t,e){return n=>new Y(n,t,e)}function _(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class G{constructor(t,e,n,i,o,s){this.options=t,this.attrs=e,this.tooltip=n,this.timestamp=i,this.selected=o,this.disabled=s}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new G(this.options,et(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,n,i,o,s){if(i&&!s&&t.some(t=>t.isPending))return i.setDisabled();let l=function(t,e){let n=[],i=null,o=null,s=t=>{n.push(t);let{section:e}=t.completion;if(e){i||(i=[]);let t="string"==typeof e?e:e.name;i.some(e=>e.name==t)||i.push("string"==typeof e?{name:t}:e)}},l=e.facet(H);for(let i of t)if(i.hasResult()){let t=i.result.getMatch;if(!1===i.result.filter)for(let e of i.result.options)s(new E(e,i.source,t?t(e):[],1e9-n.length));else{let n,r=e.sliceDoc(i.from,i.to),a=l.filterStrict?new j(r):new q(r);for(let e of i.result.options)if(n=a.match(e.label)){let l=e.displayLabel?t?t(e,n.matched):[]:n.matched,r=n.score+(e.boost||0);if(s(new E(e,i.source,l,r)),"object"==typeof e.section&&"dynamic"===e.section.rank){let{name:t}=e.section;o||(o=Object.create(null)),o[t]=Math.max(r,o[t]||-1e9)}}}}if(i){let t=Object.create(null),e=0,s=(t,e)=>("dynamic"===t.rank&&"dynamic"===e.rank?o[e.name]-o[t.name]:0)||("number"==typeof t.rank?t.rank:1e9)-("number"==typeof e.rank?e.rank:1e9)||(t.name<e.name?-1:1);for(let n of i.sort(s))e-=1e5,t[n.name]=e;for(let e of n){let{section:n}=e.completion;n&&(e.score+=t["string"==typeof n?n:n.name])}}let r=[],a=null,c=l.compareCompletions;for(let t of n.sort((t,e)=>e.score-t.score||c(t.completion,e.completion))){let e=t.completion;!a||a.label!=e.label||a.detail!=e.detail||null!=a.type&&null!=e.type&&a.type!=e.type||a.apply!=e.apply||a.boost!=e.boost?r.push(t):_(t.completion)>_(a)&&(r[r.length-1]=t),a=t.completion}return r}(t,e);if(!l.length)return i&&t.some(t=>t.isPending)?i.setDisabled():null;let r=e.facet(H).selectOnOpen?0:-1;if(i&&i.selected!=r&&-1!=i.selected){let t=i.options[i.selected].completion;for(let e=0;e<l.length;e++)if(l[e].completion==t){r=e;break}}return new G(l,et(n,r),{pos:t.reduce((t,e)=>e.hasResult()?Math.min(t,e.from):t,1e8),create:ct,above:o.aboveCursor},i?i.timestamp:Date.now(),r,!1)}map(t){return new G(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new G(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class J{constructor(t,e,n){this.active=t,this.id=e,this.open=n}static start(){return new J(nt,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,n=e.facet(H),i=(n.override||e.languageDataAt("autocomplete",M(e)).map(N)).map(e=>(this.active.find(t=>t.source==e)||new ot(e,this.active.some(t=>0!=t.state)?1:0)).update(t,n));i.length==this.active.length&&i.every((t,e)=>t==this.active[e])&&(i=this.active);let o=this.open,s=t.effects.some(t=>t.is(lt));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||i.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let n=0,i=0;;){for(;n<t.length&&!t[n].hasResult();)n++;for(;i<e.length&&!e[i].hasResult();)i++;let o=n==t.length,s=i==e.length;if(o||s)return o==s;if(t[n++].result!=e[i++].result)return!1}}(i,this.active)||s?o=G.build(i,e,this.id,o,n,s):o&&o.disabled&&!i.some(t=>t.isPending)&&(o=null),!o&&i.every(t=>!t.isPending)&&i.some(t=>t.hasResult())&&(i=i.map(t=>t.hasResult()?new ot(t.source,0):t));for(let e of t.effects)e.is(K)&&(o=o&&o.setSelected(e.value,this.id));return i==this.active&&o==this.open?this:new J(i,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Z:tt}}const Z={"aria-autocomplete":"list"},tt={};function et(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const nt=[];function it(t,e){if(t.isUserEvent("input.complete")){let n=t.annotation(B);if(n&&e.activateOnCompletion(n))return 12}let n=t.isUserEvent("input.type");return n&&e.activateOnTyping?5:n?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class ot{constructor(t,e,n=!1){this.source=t,this.state=e,this.explicit=n}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let n=it(t,e),i=this;(8&n||16&n&&this.touches(t))&&(i=new ot(i.source,0)),4&n&&0==i.state&&(i=new ot(this.source,1)),i=i.updateFor(t,n);for(let e of t.effects)if(e.is(U))i=new ot(i.source,1,e.value);else if(e.is(W))i=new ot(i.source,0);else if(e.is(lt))for(let t of e.value)t.source==i.source&&(i=t);return i}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(M(t.state))}}class st extends ot{constructor(t,e,n,i,o,s){super(t,3,e),this.limit=n,this.result=i,this.from=o,this.to=s}hasResult(){return!0}updateFor(t,e){var n;if(!(3&e))return this.map(t.changes);let i=this.result;i.map&&!t.changes.empty&&(i=i.map(i,t.changes));let o=t.changes.mapPos(this.from),s=t.changes.mapPos(this.to,1),l=M(t.state);if(l>s||!i||2&e&&(M(t.startState)==this.from||l<this.limit))return new ot(this.source,4&e?1:0);let r=t.changes.mapPos(this.limit);return function(t,e,n,i){if(!t)return!1;let o=e.sliceDoc(n,i);return"function"==typeof t?t(o,n,i,e):P(t,!0).test(o)}(i.validFor,t.state,o,s)?new st(this.source,this.explicit,r,i,o,s):i.update&&(i=i.update(i,o,s,new T(t.state,l,!1)))?new st(this.source,this.explicit,r,i,i.from,null!==(n=i.to)&&void 0!==n?n:M(t.state)):new ot(this.source,1,this.explicit)}map(t){if(t.empty)return this;let e=this.result.map?this.result.map(this.result,t):this.result;return e?new st(this.source,this.explicit,t.mapPos(this.limit),e,t.mapPos(this.from),t.mapPos(this.to,1)):new ot(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}const lt=s.define({map:(t,e)=>t.map(t=>t.map(e))}),rt=p.define({create:()=>J.start(),update:(t,e)=>t.update(e),provide:t=>[w.from(t,t=>t.tooltip),b.contentAttributes.from(t,t=>t.attrs)]});function at(t,e){const n=e.completion.apply||e.completion.label;let i=t.state.field(rt).active.find(t=>t.source==e.source);return i instanceof st&&("string"==typeof n?t.dispatch({...$(t.state,n,i.from,i.to),annotations:B.of(e.completion)}):n(t,e.completion,i.from,i.to),!0)}const ct=X(rt,at);function ht(t,e="option"){return n=>{let i=n.state.field(rt,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<n.state.facet(H).interactionDelay)return!1;let o,s=1;"page"==e&&(o=g(n,i.open.tooltip))&&(s=Math.max(2,Math.floor(o.dom.offsetHeight/o.dom.querySelector("li").offsetHeight)-1));let{length:l}=i.open.options,r=i.open.selected>-1?i.open.selected+s*(t?1:-1):t?0:l-1;return r<0?r="page"==e?0:l-1:r>=l&&(r="page"==e?l-1:0),n.dispatch({effects:K.of(r)}),!0}}const pt=t=>{let e=t.state.field(rt,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(H).interactionDelay)&&at(t,e.open.options[e.open.selected])},ft=t=>!!t.state.field(rt,!1)&&(t.dispatch({effects:U.of(!0)}),!0),ut=t=>{let e=t.state.field(rt,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:W.of(null)}),!0)};class dt{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const mt=x.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(rt).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(rt),n=t.state.facet(H);if(!t.selectionSet&&!t.docChanged&&t.startState.field(rt)==e)return;let i=t.transactions.some(t=>{let e=it(t,n);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let e=0;e<this.running.length;e++){let n=this.running[e];if(i||n.context.abortOnDocChange&&t.docChanged||n.updates.length+t.transactions.length>50&&Date.now()-n.time>1e3){for(let t of n.context.abortListeners)try{t()}catch(t){C(this.view.state,t)}n.context.abortListeners=null,this.running.splice(e--,1)}else n.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(U)))&&(this.pendingStart=!0);let o=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),o):-1,0!=this.composing)for(let e of t.transactions)e.isUserEvent("input.type")?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(rt);for(let t of e.active)t.isPending&&!this.running.some(e=>e.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(H).updateSyncTime))}startQuery(t){let{state:e}=this.view,n=M(e),i=new T(e,n,t.explicit,this.view),o=new dt(t,i);this.running.push(o),Promise.resolve(t.source(i)).then(t=>{o.context.aborted||(o.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:W.of(null)}),C(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(H).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(H),i=this.view.state.field(rt);for(let o=0;o<this.running.length;o++){let s=this.running[o];if(void 0===s.done)continue;if(this.running.splice(o--,1),s.done){let i=M(s.updates.length?s.updates[0].startState:this.view.state),o=Math.min(i,s.done.from+(s.active.explicit?0:1)),l=new st(s.active.source,s.active.explicit,o,s.done,s.done.from,null!==(t=s.done.to)&&void 0!==t?t:i);for(let t of s.updates)l=l.update(t,n);if(l.hasResult()){e.push(l);continue}}let l=i.active.find(t=>t.source==s.active.source);if(l&&l.isPending)if(null==s.done){let t=new ot(s.active.source,0);for(let e of s.updates)t=t.update(e,n);t.isPending||e.push(t)}else this.startQuery(l)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:lt.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(rt,!1);if(e&&e.tooltip&&this.view.state.facet(H).closeOnBlur){let n=e.open&&g(this.view,e.open.tooltip);n&&n.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:W.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:U.of(!1)}),20),this.composing=0}}}),gt="object"==typeof navigator&&/Win/.test(navigator.platform),vt=r.highest(b.domEventHandlers({keydown(t,e){let n=e.state.field(rt,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||t.key.length>1||t.ctrlKey&&(!gt||!t.altKey)||t.metaKey)return!1;let i=n.open.options[n.open.selected],o=n.active.find(t=>t.source==i.source),s=i.completion.commitCharacters||o.result.commitCharacters;return s&&s.indexOf(t.key)>-1&&at(e,i),!1}})),bt=b.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class wt{constructor(t,e,n,i){this.field=t,this.line=e,this.from=n,this.to=i}}class yt{constructor(t,e,n){this.field=t,this.from=e,this.to=n}map(t){let e=t.mapPos(this.from,-1,m.TrackDel),n=t.mapPos(this.to,1,m.TrackDel);return null==e||null==n?null:new yt(this.field,e,n)}}class xt{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let n=[],i=[e],o=t.doc.lineAt(e),s=/^\s*/.exec(o.text)[0];for(let o of this.lines){if(n.length){let n=s,l=/^\t*/.exec(o)[0].length;for(let e=0;e<l;e++)n+=t.facet(D);i.push(e+n.length-l),o=n+o.slice(l)}n.push(o),e+=o.length+1}let l=this.fieldPositions.map(t=>new yt(t.field,i[t.line]+t.from,i[t.line]+t.to));return{text:n,ranges:l}}static parse(t){let e,n=[],i=[],o=[];for(let s of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(s);){let t=e[1]?+e[1]:null,l=e[2]||e[3]||"",r=-1;0===t&&(t=1e9);let a=l.replace(/\\[{}]/g,t=>t[1]);for(let e=0;e<n.length;e++)(null!=t?n[e].seq==t:a&&n[e].name==a)&&(r=e);if(r<0){let e=0;for(;e<n.length&&(null==t||null!=n[e].seq&&n[e].seq<t);)e++;n.splice(e,0,{seq:t,name:a}),r=e;for(let t of o)t.field>=r&&t.field++}for(let t of o)if(t.line==i.length&&t.from>e.index){let n=e[2]?3+(e[1]||"").length:2;t.from-=n,t.to-=n}o.push(new wt(r,i.length,e.index,e.index+a.length)),s=s.slice(0,e.index)+l+s.slice(e.index+e[0].length)}s=s.replace(/\\([{}])/g,(t,e,n)=>{for(let t of o)t.line==i.length&&t.from>n&&(t.from--,t.to--);return e}),i.push(s)}return new xt(i,o)}}let Ct=y.widget({widget:new class extends k{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),It=y.mark({class:"cm-snippetField"});class kt{constructor(t,e){this.ranges=t,this.active=e,this.deco=y.set(t.map(t=>(t.from==t.to?Ct:It).range(t.from,t.to)),!0)}map(t){let e=[];for(let n of this.ranges){let i=n.map(t);if(!i)return null;e.push(i)}return new kt(e,this.active)}selectionInsideField(t){return t.ranges.every(t=>this.ranges.some(e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))}}const Ot=s.define({map:(t,e)=>t&&t.map(e)}),Dt=s.define(),Tt=p.define({create:()=>null,update(t,e){for(let n of e.effects){if(n.is(Ot))return n.value;if(n.is(Dt)&&t)return new kt(t.ranges,n.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>b.decorations.from(t,t=>t?t.deco:y.none)});function At(t,e){return n.create(t.filter(t=>t.field==e).map(t=>n.range(t.from,t.to)))}function Lt(t){let e=xt.parse(t);return(t,n,l,r)=>{let{text:a,ranges:c}=e.instantiate(t.state,l),{main:h}=t.state.selection,p={changes:{from:l,to:r==h.from?h.to:r,insert:o.of(a)},scrollIntoView:!0,annotations:n?[B.of(n),i.userEvent.of("input.complete")]:void 0};if(c.length&&(p.selection=At(c,0)),c.some(t=>t.field>0)){let e=new kt(c,0),n=p.effects=[Ot.of(e)];void 0===t.state.field(Tt,!1)&&n.push(s.appendConfig.of([Tt,Nt,Wt,bt]))}t.dispatch(t.state.update(p))}}function Rt(t){return({state:e,dispatch:n})=>{let i=e.field(Tt,!1);if(!i||t<0&&0==i.active)return!1;let o=i.active+t,s=t>0&&!i.ranges.some(e=>e.field==o+t);return n(e.update({selection:At(i.ranges,o),effects:Ot.of(s?null:new kt(i.ranges,o)),scrollIntoView:!0})),!0}}const St=({state:t,dispatch:e})=>!!t.field(Tt,!1)&&(e(t.update({effects:Ot.of(null)})),!0),Et=Rt(1),Mt=Rt(-1);function Pt(t){let e=t.field(Tt,!1);return!(!e||!e.ranges.some(t=>t.field==e.active+1))}function Bt(t){let e=t.field(Tt,!1);return!!(e&&e.active>0)}const $t=[{key:"Tab",run:Et,shift:Mt},{key:"Escape",run:St}],Ft=l.define({combine:t=>t.length?t[0]:$t}),Nt=r.highest(v.compute([Ft],t=>t.facet(Ft)));function Ut(t,e){return{...e,apply:Lt(t)}}const Wt=b.domEventHandlers({mousedown(t,e){let n,i=e.state.field(Tt,!1);if(!i||null==(n=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let o=i.ranges.find(t=>t.from<=n&&t.to>=n);return!(!o||o.field==i.active)&&(e.dispatch({selection:At(i.ranges,o.field),effects:Ot.of(i.ranges.some(t=>t.field>o.field)?new kt(i.ranges,o.field):null),scrollIntoView:!0}),!0)}});function qt(t,e){return new RegExp(e(t.source),t.unicode?"u":"")}const jt=Object.create(null);function Ht(t,e,n,i,o){for(let s=t.iterLines(),l=0;!s.next().done;){let t,{value:r}=s;for(e.lastIndex=0;t=e.exec(r);)if(!i[t[0]]&&l+t.index!=o&&(n.push({type:"text",label:t[0]}),i[t[0]]=!0,n.length>=2e3))return;l+=r.length+1}}function Vt(t,e,n,i,o){let s=t.length>=1e3,l=s&&e.get(t);if(l)return l;let r=[],a=Object.create(null);if(t.children){let s=0;for(let l of t.children){if(l.length>=1e3)for(let t of Vt(l,e,n,i-s,o-s))a[t.label]||(a[t.label]=!0,r.push(t));else Ht(l,n,r,a,o-s);s+=l.length+1}}else Ht(t,n,r,a,o);return s&&r.length<2e3&&e.set(t,r),r}const zt=t=>{var e;let n=null!==(e=t.state.languageDataAt("wordChars",t.pos)[0])&&void 0!==e?e:"",i=function(t){let e=t.replace(/[\]\-\\]/g,"\\$&");try{return new RegExp(`[\\p{Alphabetic}\\p{Number}_${e}]+`,"ug")}catch(t){return new RegExp(`[w${e}]`,"g")}}(n),o=t.matchBefore(qt(i,t=>t+"$"));if(!o&&!t.explicit)return null;let s=o?o.from:t.pos,l=Vt(t.state.doc,function(t){return jt[t]||(jt[t]=new WeakMap)}(n),i,5e4,s);return{from:s,options:l,validFor:qt(i,t=>"^"+t)}},Kt={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Qt=s.define({map(t,e){let n=e.mapPos(t,-1,m.TrackAfter);return null==n?void 0:n}}),Yt=new class extends t{};Yt.startSide=1,Yt.endSide=-1;const Xt=p.define({create:()=>u.empty,update(t,e){if(t=t.map(e.changes),e.selection){let n=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=n.from&&t<=n.to})}for(let n of e.effects)n.is(Qt)&&(t=t.update({add:[Yt.range(n.value,n.value+1)]}));return t}});function _t(){return[ee,Xt]}const Gt="()[]{}<>«»»«[]{}";function Jt(t){for(let e=0;e<16;e+=2)if(Gt.charCodeAt(e)==t)return Gt.charAt(e+1);return d(t<128?t:t+1)}function Zt(t,e){return t.languageDataAt("closeBrackets",e)[0]||Kt}const te="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),ee=b.inputHandler.of((t,e,n,i)=>{if((te?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let o=t.state.selection.main;if(i.length>2||2==i.length&&1==a(c(i,0))||e!=o.from||n!=o.to)return!1;let s=oe(t.state,i);return!!s&&(t.dispatch(s),!0)}),ne=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Zt(t,t.selection.main.head).brackets||Kt.brackets,o=null,s=t.changeByRange(e=>{if(e.empty){let o=function(t,e){let n=t.sliceString(e-2,e);return a(c(n,0))==n.length?n:n.slice(1)}(t.doc,e.head);for(let s of i)if(s==o&&le(t.doc,e.head)==Jt(c(s,0)))return{changes:{from:e.head-s.length,to:e.head+s.length},range:n.cursor(e.head-s.length)}}return{range:o=e}});return o||e(t.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!o},ie=[{key:"Backspace",run:ne}];function oe(t,e){let n=Zt(t,t.selection.main.head),i=n.brackets||Kt.brackets;for(let o of i){let s=Jt(c(o,0));if(e==o)return s==o?ce(t,o,i.indexOf(o+o+o)>-1,n):re(t,o,s,n.before||Kt.before);if(e==s&&se(t,t.selection.main.from))return ae(t,o,s)}return null}function se(t,e){let n=!1;return t.field(Xt).between(0,t.doc.length,t=>{t==e&&(n=!0)}),n}function le(t,e){let n=t.sliceString(e,e+2);return n.slice(0,a(c(n,0)))}function re(t,e,i,o){let s=null,l=t.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:i,from:l.to}],effects:Qt.of(l.to+e.length),range:n.range(l.anchor+e.length,l.head+e.length)};let r=le(t.doc,l.head);return!r||/\s/.test(r)||o.indexOf(r)>-1?{changes:{insert:e+i,from:l.head},effects:Qt.of(l.head+e.length),range:n.cursor(l.head+e.length)}:{range:s=l}});return s?null:t.update(l,{scrollIntoView:!0,userEvent:"input.type"})}function ae(t,e,i){let o=null,s=t.changeByRange(e=>e.empty&&le(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:n.cursor(e.head+i.length)}:o={range:e});return o?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function ce(t,e,i,o){let s=o.stringPrefixes||Kt.stringPrefixes,l=null,r=t.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:e,from:o.to}],effects:Qt.of(o.to+e.length),range:n.range(o.anchor+e.length,o.head+e.length)};let r,a=o.head,c=le(t.doc,a);if(c==e){if(he(t,a))return{changes:{insert:e+e,from:a},effects:Qt.of(a+e.length),range:n.cursor(a+e.length)};if(se(t,a)){let o=i&&t.sliceDoc(a,a+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+o.length,insert:o},range:n.cursor(a+o.length)}}}else{if(i&&t.sliceDoc(a-2*e.length,a)==e+e&&(r=pe(t,a-2*e.length,s))>-1&&he(t,r))return{changes:{insert:e+e+e+e,from:a},effects:Qt.of(a+e.length),range:n.cursor(a+e.length)};if(t.charCategorizer(a)(c)!=h.Word&&pe(t,a,s)>-1&&!function(t,e,n,i){let o=O(t).resolveInner(e,-1),s=i.reduce((t,e)=>Math.max(t,e.length),0);for(let l=0;l<5;l++){let l=t.sliceDoc(o.from,Math.min(o.to,o.from+n.length+s)),r=l.indexOf(n);if(!r||r>-1&&i.indexOf(l.slice(0,r))>-1){let e=o.firstChild;for(;e&&e.from==o.from&&e.to-e.from>n.length+r;){if(t.sliceDoc(e.to-n.length,e.to)==n)return!1;e=e.firstChild}return!0}let a=o.to==e&&o.parent;if(!a)break;o=a}return!1}(t,a,e,s))return{changes:{insert:e+e,from:a},effects:Qt.of(a+e.length),range:n.cursor(a+e.length)}}return{range:l=o}});return l?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function he(t,e){let n=O(t).resolveInner(e+1);return n.parent&&n.from==e}function pe(t,e,n){let i=t.charCategorizer(e);if(i(t.sliceDoc(e-1,e))!=h.Word)return e;for(let o of n){let n=e-o.length;if(t.sliceDoc(n,e)==o&&i(t.sliceDoc(n-1,n))!=h.Word)return n}return-1}function fe(t={}){return[vt,rt,H.of(t),mt,de,bt]}const ue=[{key:"Ctrl-Space",run:ft},{mac:"Alt-`",run:ft},{mac:"Alt-i",run:ft},{key:"Escape",run:ut},{key:"ArrowDown",run:ht(!0)},{key:"ArrowUp",run:ht(!1)},{key:"PageDown",run:ht(!0,"page")},{key:"PageUp",run:ht(!1,"page")},{key:"Enter",run:pt}],de=r.highest(v.computeN([H],t=>t.facet(H).defaultKeymap?[ue]:[]));function me(t){let e=t.field(rt,!1);return e&&e.active.some(t=>t.isPending)?"pending":e&&e.active.some(t=>0!=t.state)?"active":null}const ge=new WeakMap;function ve(t){var e;let n=null===(e=t.field(rt,!1))||void 0===e?void 0:e.open;if(!n||n.disabled)return[];let i=ge.get(n.options);return i||ge.set(n.options,i=n.options.map(t=>t.completion)),i}function be(t){var e;let n=null===(e=t.field(rt,!1))||void 0===e?void 0:e.open;return n&&!n.disabled&&n.selected>=0?n.options[n.selected].completion:null}function we(t){var e;let n=null===(e=t.field(rt,!1))||void 0===e?void 0:e.open;return n&&!n.disabled&&n.selected>=0?n.selected:null}function ye(t){return K.of(t)}export{T as CompletionContext,pt as acceptCompletion,fe as autocompletion,St as clearSnippet,_t as closeBrackets,ie as closeBracketsKeymap,ut as closeCompletion,zt as completeAnyWord,L as completeFromList,ue as completionKeymap,me as completionStatus,ve as currentCompletions,ne as deleteBracketPair,Pt as hasNextSnippetField,Bt as hasPrevSnippetField,R as ifIn,S as ifNotIn,oe as insertBracket,$ as insertCompletionText,ht as moveCompletionSelection,Et as nextSnippetField,B as pickedCompletion,Mt as prevSnippetField,be as selectedCompletion,we as selectedCompletionIndex,ye as setSelectedCompletion,Lt as snippet,Ut as snippetCompletion,Ft as snippetKeymap,ft as startCompletion};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Annotation as e,Facet as t,StateField as n,Transaction as r,ChangeSet as o,ChangeDesc as l,EditorSelection as s,StateEffect as a,Text as i,findClusterBreak as c,countColumn as f,combineConfig as u,CharCategory as h}from"@codemirror/state";import{EditorView as m,Direction as d}from"@codemirror/view";import{IndentContext as p,getIndentation as g,indentString as y,syntaxTree as v,matchBrackets as A,getIndentUnit as k,indentUnit as w}from"@codemirror/language";import{NodeProp as D}from"@lezer/common";const S=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=I(e.state,n.from);return r.line?M(e):!!r.block&&T(e)};function x(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let o=e(t,n);return!!o&&(r(n.update(o)),!0)}}const M=x(L,0),B=x(L,1),C=x(L,2),b=x(R,0),E=x(R,1),O=x(R,2),T=x((e,t)=>R(e,t,function(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),o=n.to<=r.to?r:e.doc.lineAt(n.to);o.from>r.from&&o.from==n.to&&(o=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let l=t.length-1;l>=0&&t[l].to>r.from?t[l].to=o.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:o.to})}return t}(t)),0);function I(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const V=50;function R(e,t,n=t.selection.ranges){let r=n.map(e=>I(t,e.from).block);if(!r.every(e=>e))return null;let o=n.map((e,n)=>function(e,{open:t,close:n},r,o){let l,s,a=e.sliceDoc(r-V,r),i=e.sliceDoc(o,o+V),c=/\s*$/.exec(a)[0].length,f=/^\s*/.exec(i)[0].length,u=a.length-c;if(a.slice(u-t.length,u)==t&&i.slice(f,f+n.length)==n)return{open:{pos:r-c,margin:c&&1},close:{pos:o+f,margin:f&&1}};o-r<=2*V?l=s=e.sliceDoc(r,o):(l=e.sliceDoc(r,r+V),s=e.sliceDoc(o-V,o));let h=/^\s*/.exec(l)[0].length,m=/\s*$/.exec(s)[0].length,d=s.length-m-n.length;return l.slice(h,h+t.length)==t&&s.slice(d,d+n.length)==n?{open:{pos:r+h+t.length,margin:/\s/.test(l.charAt(h+t.length))?1:0},close:{pos:o-m-n.length,margin:/\s/.test(s.charAt(d-1))?1:0}}:null}(t,r[n],e.from,e.to));if(2!=e&&!o.every(e=>e))return{changes:t.changes(n.map((e,t)=>o[t]?[]:[{from:e.from,insert:r[t].open+" "},{from:e.to,insert:" "+r[t].close}]))};if(1!=e&&o.some(e=>e)){let e=[];for(let t,n=0;n<o.length;n++)if(t=o[n]){let o=r[n],{open:l,close:s}=t;e.push({from:l.pos-o.open.length,to:l.pos+l.margin},{from:s.pos-s.margin,to:s.pos+o.close.length})}return{changes:e}}return null}function L(e,t,n=t.selection.ranges){let r=[],o=-1;e:for(let{from:e,to:l}of n){let n,s=r.length,a=1e9;for(let s=e;s<=l;){let i=t.doc.lineAt(s);if(null==n&&(n=I(t,i.from).line,!n))continue e;if(i.from>o&&(e==l||l>i.from)){o=i.from;let e=/^\s*/.exec(i.text)[0].length,t=e==i.length,l=i.text.slice(e,e+n.length)==n?e:-1;e<i.text.length&&e<a&&(a=e),r.push({line:i,comment:l,token:n,indent:e,empty:t,single:!1})}s=i.to+1}if(a<1e9)for(let e=s;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=a);r.length==s+1&&(r[s].single=!0)}if(2!=e&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:o,empty:l,single:s}of r)!s&&l||e.push({from:t.from+o,insert:n+" "});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(1!=e&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:o}of r)if(n>=0){let r=t.from+n,l=r+o.length;" "==t.text[l-t.from]&&l++,e.push({from:r,to:l})}return{changes:e}}return null}const J=e.define(),N=e.define(),U=t.define(),z=t.define({combine:e=>u(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}),H=n.define({create:()=>ae.empty,update(e,t){let n=t.state.facet(z),o=t.annotation(J);if(o){let r=X.fromTransaction(t,o.selection),l=o.side,s=0==l?e.undone:e.done;return s=r?Y(s,s.length,n.minDepth,r):ne(s,t.startState.selection),new ae(0==l?o.rest:s,0==l?s:o.rest)}let l=t.annotation(N);if("full"!=l&&"before"!=l||(e=e.isolate()),!1===t.annotation(r.addToHistory))return t.changes.empty?e:e.addMapping(t.changes.desc);let s=X.fromTransaction(t),a=t.annotation(r.time),i=t.annotation(r.userEvent);return s?e=e.addChanges(s,a,i,n,t):t.selection&&(e=e.addSelection(t.startState.selection,a,i,n.newGroupDelay)),"full"!=l&&"after"!=l||(e=e.isolate()),e},toJSON:e=>({done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}),fromJSON:e=>new ae(e.done.map(X.fromJSON),e.undone.map(X.fromJSON))});function G(e={}){return[H,z.of(e),m.domEventHandlers({beforeinput(e,t){let n="historyUndo"==e.inputType?q:"historyRedo"==e.inputType?$:null;return!!n&&(e.preventDefault(),n(t))}})]}const P=H;function W(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let o=n.field(H,!1);if(!o)return!1;let l=o.pop(e,n,t);return!!l&&(r(l),!0)}}const q=W(0,!1),$=W(1,!1),j=W(0,!0),F=W(1,!0);function _(e){return function(t){let n=t.field(H,!1);if(!n)return 0;let r=0==e?n.done:n.undone;return r.length-(r.length&&!r[0].changes?1:0)}}const K=_(0),Q=_(1);class X{constructor(e,t,n,r,o){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=o}setSelAfter(e){return new X(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:null===(e=this.changes)||void 0===e?void 0:e.toJSON(),mapped:null===(t=this.mapped)||void 0===t?void 0:t.toJSON(),startSelection:null===(n=this.startSelection)||void 0===n?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(e){return new X(e.changes&&o.fromJSON(e.changes),[],e.mapped&&l.fromJSON(e.mapped),e.startSelection&&s.fromJSON(e.startSelection),e.selectionsAfter.map(s.fromJSON))}static fromTransaction(e,t){let n=ee;for(let t of e.startState.facet(U)){let r=t(e);r.length&&(n=n.concat(r))}return!n.length&&e.changes.empty?null:new X(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,ee)}static selection(e){return new X(void 0,ee,void 0,void 0,e)}}function Y(e,t,n,r){let o=t+1>n+20?t-n-1:0,l=e.slice(o,t);return l.push(r),l}function Z(e,t){return e.length?t.length?e.concat(t):e:t}const ee=[],te=200;function ne(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-te));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),Y(e,e.length-1,1e9,n.setSelAfter(r)))}return[X.selection([t])]}function re(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function oe(e,t){if(!e.length)return e;let n=e.length,r=ee;for(;n;){let o=le(e[n-1],t,r);if(o.changes&&!o.changes.empty||o.effects.length){let t=e.slice(0,n);return t[n-1]=o,t}t=o.mapped,n--,r=o.selectionsAfter}return r.length?[X.selection(r)]:ee}function le(e,t,n){let r=Z(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):ee,n);if(!e.changes)return X.selection(r);let o=e.changes.map(t),l=t.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(l):l;return new X(o,a.mapEffects(e.effects,t),s,e.startSelection.map(l),r)}const se=/^(input\.type|delete)($|\.)/;class ae{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new ae(this.done,this.undone):this}addChanges(e,t,n,r,o){let l=this.done,s=l[l.length-1];return l=s&&s.changes&&!s.changes.empty&&e.changes&&(!n||se.test(n))&&(!s.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(o,function(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,o,l)=>{for(let e=0;e<n.length;){let t=n[e++],s=n[e++];l>=t&&o<=s&&(r=!0)}}),r}(s.changes,e.changes))||"input.type.compose"==n)?Y(l,l.length-1,r.minDepth,new X(e.changes.compose(s.changes),Z(a.mapEffects(e.effects,s.changes),s.effects),s.mapped,s.startSelection,ee)):Y(l,l.length,r.minDepth,e),new ae(l,ee,t,n)}addSelection(e,t,n,r){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:ee;return o.length>0&&t-this.prevTime<r&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&(l=o[o.length-1],s=e,l.ranges.length==s.ranges.length&&0===l.ranges.filter((e,t)=>e.empty!=s.ranges[t].empty).length)?this:new ae(ne(this.done,e),this.undone,t,n);var l,s}addMapping(e){return new ae(oe(this.done,e),oe(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=0==e?this.done:this.undone;if(0==r.length)return null;let o=r[r.length-1],l=o.selectionsAfter[0]||(o.startSelection?o.startSelection.map(o.changes.invertedDesc,1):t.selection);if(n&&o.selectionsAfter.length)return t.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:J.of({side:e,rest:re(r),selection:l}),userEvent:0==e?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let n=1==r.length?ee:r.slice(0,r.length-1);return o.mapped&&(n=oe(n,o.mapped)),t.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:J.of({side:e,rest:n,selection:l}),filter:!1,userEvent:0==e?"undo":"redo",scrollIntoView:!0})}return null}}ae.empty=new ae(ee,ee);const ie=[{key:"Mod-z",run:q,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:$,preventDefault:!0},{linux:"Ctrl-Shift-z",run:$,preventDefault:!0},{key:"Mod-u",run:j,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:F,preventDefault:!0}];function ce(e,t){return s.create(e.ranges.map(t),e.mainIndex)}function fe(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function ue({state:e,dispatch:t},n){let r=ce(e.selection,n);return!r.eq(e.selection,!0)&&(t(fe(e,r)),!0)}function he(e,t){return s.cursor(t?e.to:e.from)}function me(e,t){return ue(e,n=>n.empty?e.moveByChar(n,t):he(n,t))}function de(e){return e.textDirectionAt(e.state.selection.main.head)==d.LTR}const pe=e=>me(e,!de(e)),ge=e=>me(e,de(e)),ye=e=>me(e,!0),ve=e=>me(e,!1);function Ae(e,t,n){let r=t.head,o=e.doc.lineAt(r);return r=r==(n?o.to:o.from)?n?Math.min(e.doc.length,o.to+1):Math.max(0,o.from-1):o.from+c(o.text,r-o.from,n),s.cursor(r,n?-1:1)}function ke(e,t){return ue(e,n=>n.empty?Ae(e.state,n,t):he(n,t))}const we=e=>ke(e,!0),De=e=>ke(e,!1);function Se(e,t){return ue(e,n=>n.empty?e.moveByGroup(n,t):he(n,t))}const xe=e=>Se(e,!de(e)),Me=e=>Se(e,de(e)),Be=e=>Se(e,!0),Ce=e=>Se(e,!1);function be(e,t,n){let r=e.state.charCategorizer(t),o=r(n),l=o!=h.Space;return e=>{let t=r(e);return t!=h.Space?l&&t==o:(l=!1,!0)}}const Ee=e=>ue(e,t=>t.empty?e.moveByChar(t,!0,n=>be(e,t.head,n)):he(t,!0)),Oe="undefined"!=typeof Intl&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Te(e,t,n){let r=e.state.charCategorizer(t.from),o=h.Space,l=t.from,a=0,i=!1,c=!1,f=!1,u=t=>{if(i)return!1;l+=n?t.length:-t.length;let s,u=r(t);if(u==h.Word&&t.charCodeAt(0)<128&&/[\W_]/.test(t)&&(u=-1),o==h.Space&&(o=u),o!=u)return!1;if(o==h.Word)if(t.toLowerCase()==t){if(!n&&c)return!1;f=!0}else if(f){if(n)return!1;i=!0}else{if(c&&n&&r(s=e.state.sliceDoc(l,l+1))==h.Word&&s.toLowerCase()==s)return!1;c=!0}return a++,!0},m=e.moveByChar(t,n,e=>(u(e),u));if(Oe&&o==h.Word&&m.from==t.from+a*(n?1:-1)){let r=Math.min(t.head,m.head),o=Math.max(t.head,m.head),l=e.state.sliceDoc(r,o);if(l.length>1&&/[\u4E00-\uffff]/.test(l)){let e=Array.from(Oe.segment(l));if(e.length>1)return n?s.cursor(t.head+e[1].index,-1):s.cursor(m.head+e[e.length-1].index,1)}}return m}function Ie(e,t){return ue(e,n=>n.empty?Te(e,n,t):he(n,t))}const Ve=e=>Ie(e,!0),Re=e=>Ie(e,!1);function Le(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Je(e,t,n){let r,o,l=v(e).resolveInner(t.head),a=n?D.closedBy:D.openedBy;for(let r=t.head;;){let t=n?l.childAfter(r):l.childBefore(r);if(!t)break;Le(e,t,a)?l=t:r=n?t.to:t.from}return o=l.type.prop(a)&&(r=n?A(e,l.from,1):A(e,l.to,-1))&&r.matched?n?r.end.to:r.end.from:n?l.to:l.from,s.cursor(o,n?-1:1)}const Ne=e=>ue(e,t=>Je(e.state,t,!de(e))),Ue=e=>ue(e,t=>Je(e.state,t,de(e)));function ze(e,t){return ue(e,n=>{if(!n.empty)return he(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const He=e=>ze(e,!1),Ge=e=>ze(e,!0);function Pe(e){let t,n=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,r=0,o=0;if(n){for(let t of e.state.facet(m.scrollMargins)){let n=t(e);(null==n?void 0:n.top)&&(r=Math.max(null==n?void 0:n.top,r)),(null==n?void 0:n.bottom)&&(o=Math.max(null==n?void 0:n.bottom,o))}t=e.scrollDOM.clientHeight-r-o}else t=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:o,selfScroll:n,height:Math.max(e.defaultLineHeight,t-5)}}function We(e,t){let n,r=Pe(e),{state:o}=e,l=ce(o.selection,n=>n.empty?e.moveVertically(n,t,r.height):he(n,t));if(l.eq(o.selection))return!1;if(r.selfScroll){let t=e.coordsAtPos(o.selection.main.head),s=e.scrollDOM.getBoundingClientRect(),a=s.top+r.marginTop,i=s.bottom-r.marginBottom;t&&t.top>a&&t.bottom<i&&(n=m.scrollIntoView(l.main.head,{y:"start",yMargin:t.top-a}))}return e.dispatch(fe(o,l),{effects:n}),!0}const qe=e=>We(e,!1),$e=e=>We(e,!0);function je(e,t,n){let r=e.lineBlockAt(t.head),o=e.moveToLineBoundary(t,n);if(o.head==t.head&&o.head!=(n?r.to:r.from)&&(o=e.moveToLineBoundary(t,n,!1)),!n&&o.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(o=s.cursor(r.from+n))}return o}const Fe=e=>ue(e,t=>je(e,t,!0)),_e=e=>ue(e,t=>je(e,t,!1)),Ke=e=>ue(e,t=>je(e,t,!de(e))),Qe=e=>ue(e,t=>je(e,t,de(e))),Xe=e=>ue(e,t=>s.cursor(e.lineBlockAt(t.head).from,1)),Ye=e=>ue(e,t=>s.cursor(e.lineBlockAt(t.head).to,-1));function Ze(e,t,n){let r=!1,o=ce(e.selection,t=>{let o=A(e,t.head,-1)||A(e,t.head,1)||t.head>0&&A(e,t.head-1,1)||t.head<e.doc.length&&A(e,t.head+1,-1);if(!o||!o.end)return t;r=!0;let l=o.start.from==t.head?o.end.to:o.end.from;return n?s.range(t.anchor,l):s.cursor(l)});return!!r&&(t(fe(e,o)),!0)}const et=({state:e,dispatch:t})=>Ze(e,t,!1),tt=({state:e,dispatch:t})=>Ze(e,t,!0);function nt(e,t,n){let r=ce(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=s.range(e.head,e.anchor));let r=n(e);return s.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return!r.eq(e.state.selection)&&(e.dispatch(fe(e.state,r)),!0)}function rt(e,t){return nt(e,t,n=>e.moveByChar(n,t))}const ot=e=>rt(e,!de(e)),lt=e=>rt(e,de(e)),st=e=>rt(e,!0),at=e=>rt(e,!1),it=e=>nt(e,!0,t=>Ae(e.state,t,!0)),ct=e=>nt(e,!1,t=>Ae(e.state,t,!1));function ft(e,t){return nt(e,t,n=>e.moveByGroup(n,t))}const ut=e=>ft(e,!de(e)),ht=e=>ft(e,de(e)),mt=e=>ft(e,!0),dt=e=>ft(e,!1),pt=e=>nt(e,!0,t=>e.moveByChar(t,!0,n=>be(e,t.head,n)));function gt(e,t){return nt(e,t,n=>Te(e,n,t))}const yt=e=>gt(e,!0),vt=e=>gt(e,!1),At=e=>{let t=!de(e);return nt(e,t,n=>Je(e.state,n,t))},kt=e=>{let t=de(e);return nt(e,t,n=>Je(e.state,n,t))};function wt(e,t){return nt(e,t,n=>e.moveVertically(n,t))}const Dt=e=>wt(e,!1),St=e=>wt(e,!0);function xt(e,t){return nt(e,t,n=>e.moveVertically(n,t,Pe(e).height))}const Mt=e=>xt(e,!1),Bt=e=>xt(e,!0),Ct=e=>nt(e,!0,t=>je(e,t,!0)),bt=e=>nt(e,!1,t=>je(e,t,!1)),Et=e=>{let t=!de(e);return nt(e,t,n=>je(e,n,t))},Ot=e=>{let t=de(e);return nt(e,t,n=>je(e,n,t))},Tt=e=>nt(e,!1,t=>s.cursor(e.lineBlockAt(t.head).from)),It=e=>nt(e,!0,t=>s.cursor(e.lineBlockAt(t.head).to)),Vt=({state:e,dispatch:t})=>(t(fe(e,{anchor:0})),!0),Rt=({state:e,dispatch:t})=>(t(fe(e,{anchor:e.doc.length})),!0),Lt=({state:e,dispatch:t})=>(t(fe(e,{anchor:e.selection.main.anchor,head:0})),!0),Jt=({state:e,dispatch:t})=>(t(fe(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Nt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),Ut=({state:e,dispatch:t})=>{let n=an(e).map(({from:t,to:n})=>s.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:s.create(n),userEvent:"select"})),!0},zt=({state:e,dispatch:t})=>{let n=ce(e.selection,t=>{let n=v(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return s.range(n.to,n.from)}return t});return!n.eq(e.selection)&&(t(fe(e,n)),!0)};function Ht(e,t){let{state:n}=e,r=n.selection,o=n.selection.ranges.slice();for(let r of n.selection.ranges){let l=n.doc.lineAt(r.head);if(t?l.to<e.state.doc.length:l.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<l.from||r.head>l.to){o.some(e=>e.head==r.head)||o.push(r);break}if(r.head==n.head)break;n=r}}return o.length!=r.ranges.length&&(e.dispatch(fe(n,s.create(o,o.length-1))),!0)}const Gt=e=>Ht(e,!1),Pt=e=>Ht(e,!0),Wt=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=s.create([n.main]):n.main.empty||(r=s.create([s.cursor(n.main.head)])),!!r&&(t(fe(e,r)),!0)};function qt(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,o=r.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let s=t(r);s<o?(n="delete.backward",s=$t(e,s,!1)):s>o&&(n="delete.forward",s=$t(e,s,!0)),o=Math.min(o,s),l=Math.max(l,s)}else o=$t(e,o,!1),l=$t(e,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:s.cursor(o,o<r.head?-1:1)}});return!o.changes.empty&&(e.dispatch(r.update(o,{scrollIntoView:!0,userEvent:n,effects:"delete.selection"==n?m.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function $t(e,t,n){if(e instanceof m)for(let r of e.state.facet(m.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}const jt=(e,t,n)=>qt(e,r=>{let o,l,s=r.from,{state:a}=e,i=a.doc.lineAt(s);if(n&&!t&&s>i.from&&s<i.from+200&&!/[^ \t]/.test(o=i.text.slice(0,s-i.from))){if("\t"==o[o.length-1])return s-1;let e=f(o,a.tabSize)%k(a)||k(a);for(let t=0;t<e&&" "==o[o.length-1-t];t++)s--;l=s}else l=c(i.text,s-i.from,t,t)+i.from,l==s&&i.number!=(t?a.doc.lines:1)?l+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(i.text.slice(l-i.from,s-i.from))&&(l=c(i.text,l-i.from,!1,!1)+i.from);return l}),Ft=e=>jt(e,!1,!0),_t=e=>jt(e,!1,!1),Kt=e=>jt(e,!0,!1),Qt=(e,t)=>qt(e,n=>{let r=n.head,{state:o}=e,l=o.doc.lineAt(r),s=o.charCategorizer(r);for(let e=null;;){if(r==(t?l.to:l.from)){r==n.head&&l.number!=(t?o.doc.lines:1)&&(r+=t?1:-1);break}let a=c(l.text,r-l.from,t)+l.from,i=l.text.slice(Math.min(r,a)-l.from,Math.max(r,a)-l.from),f=s(i);if(null!=e&&f!=e)break;" "==i&&r==n.head||(e=f),r=a}return r}),Xt=e=>Qt(e,!1),Yt=e=>Qt(e,!0),Zt=e=>qt(e,t=>e.moveByChar(t,!0,n=>be(e,t.head,n)).head),en=e=>qt(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),tn=e=>qt(e,t=>{let n=e.lineBlockAt(t.head).from;return t.head>n?n:Math.max(0,t.head-1)}),nn=e=>qt(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),rn=e=>qt(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),on=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=[];for(let t=0,r="",o=e.doc.iter();;){if(o.next(),o.lineBreak||o.done){let e=r.search(/\s+$/);if(e>-1&&n.push({from:t-(r.length-e),to:t}),o.done)break;r=""}else r=o.value;t+=o.value.length}return!!n.length&&(t(e.update({changes:n,userEvent:"delete"})),!0)},ln=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:i.of(["",""])},range:s.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},sn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||0==t.from||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),o=n==r.from?n-1:c(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:c(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:e.doc.slice(n,l).append(e.doc.slice(o,n))},range:s.cursor(l)}});return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function an(e){let t=[],n=-1;for(let r of e.selection.ranges){let o=e.doc.lineAt(r.from),l=e.doc.lineAt(r.to);if(r.empty||r.to!=l.from||(l=e.doc.lineAt(r.to-1)),n>=o.number){let e=t[t.length-1];e.to=l.to,e.ranges.push(r)}else t.push({from:o.from,to:l.to,ranges:[r]});n=l.number+1}return t}function cn(e,t,n){if(e.readOnly)return!1;let r=[],o=[];for(let t of an(e)){if(n?t.to==e.doc.length:0==t.from)continue;let l=e.doc.lineAt(n?t.to+1:t.from-1),a=l.length+1;if(n){r.push({from:t.to,to:l.to},{from:t.from,insert:l.text+e.lineBreak});for(let n of t.ranges)o.push(s.range(Math.min(e.doc.length,n.anchor+a),Math.min(e.doc.length,n.head+a)))}else{r.push({from:l.from,to:t.from},{from:t.to,insert:e.lineBreak+l.text});for(let e of t.ranges)o.push(s.range(e.anchor-a,e.head-a))}}return!!r.length&&(t(e.update({changes:r,scrollIntoView:!0,selection:s.create(o,e.selection.mainIndex),userEvent:"move.line"})),!0)}const fn=({state:e,dispatch:t})=>cn(e,t,!1),un=({state:e,dispatch:t})=>cn(e,t,!0);function hn(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of an(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let o=e.changes(r);return t(e.update({changes:o,selection:e.selection.map(o,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const mn=({state:e,dispatch:t})=>hn(e,t,!1),dn=({state:e,dispatch:t})=>hn(e,t,!0),pn=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(an(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=ce(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),o=e.coordsAtPos(t.head,t.assoc||1);o&&(n=r.bottom+e.documentTop-o.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0},gn=({state:e,dispatch:t})=>(t(e.update(e.replaceSelection(e.lineBreak),{scrollIntoView:!0,userEvent:"input"})),!0),yn=({state:e,dispatch:t})=>(t(e.update(e.changeByRange(t=>{let n=/^\s*/.exec(e.doc.lineAt(t.from).text)[0];return{changes:{from:t.from,to:t.to,insert:e.lineBreak+n},range:s.cursor(t.from+n.length+1)}}),{scrollIntoView:!0,userEvent:"input"})),!0);const vn=kn(!1),An=kn(!0);function kn(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:o}=n,l=t.doc.lineAt(r),a=!e&&r==o&&function(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n,r=v(e).resolveInner(t),o=r.childBefore(t),l=r.childAfter(t);return o&&l&&o.to<=t&&l.from>=t&&(n=o.type.prop(D.closedBy))&&n.indexOf(l.name)>-1&&e.doc.lineAt(o.to).from==e.doc.lineAt(l.from).from&&!/\S/.test(e.sliceDoc(o.to,l.from))?{from:o.to,to:l.from}:null}(t,r);e&&(r=o=(o<=l.to?l:t.doc.lineAt(o)).to);let c=new p(t,{simulateBreak:r,simulateDoubleBreak:!!a}),u=g(c,r);for(null==u&&(u=f(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?({from:r,to:o}=a):r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let h=["",y(t,u)];return a&&h.push(y(t,c.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:i.of(h)},range:s.cursor(r+1+h[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function wn(e,t){let n=-1;return e.changeByRange(r=>{let o=[];for(let l=r.from;l<=r.to;){let s=e.doc.lineAt(l);s.number>n&&(r.empty||r.to>s.from)&&(t(s,o,r),n=s.number),l=s.to+1}let l=e.changes(o);return{changes:o,range:s.range(l.mapPos(r.anchor,1),l.mapPos(r.head,1))}})}const Dn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new p(e,{overrideIndentation:e=>{let t=n[e];return null==t?-1:t}}),o=wn(e,(t,o,l)=>{let s=g(r,t.from);if(null==s)return;/\S/.test(t.text)||(s=0);let a=/^\s*/.exec(t.text)[0],i=y(e,s);(a!=i||l.from<t.from+a.length)&&(n[t.from]=s,o.push({from:t.from,to:t.from+a.length,insert:i}))});return o.changes.empty||t(e.update(o,{userEvent:"indent"})),!0},Sn=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(wn(e,(t,n)=>{n.push({from:t.from,insert:e.facet(w)})}),{userEvent:"input.indent"})),!0),xn=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(wn(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let o=f(r,e.tabSize),l=0,s=y(e,Math.max(0,o-k(e)));for(;l<r.length&&l<s.length&&r.charCodeAt(l)==s.charCodeAt(l);)l++;n.push({from:t.from+l,to:t.from+r.length,insert:s.slice(l)})}),{userEvent:"delete.dedent"})),!0),Mn=e=>(e.setTabFocusMode(),!0),Bn=e=>(e.setTabFocusMode(2e3),!0),Cn=({state:e,dispatch:t})=>e.selection.ranges.some(e=>!e.empty)?Sn({state:e,dispatch:t}):(t(e.update(e.replaceSelection("\t"),{scrollIntoView:!0,userEvent:"input"})),!0),bn=[{key:"Ctrl-b",run:pe,shift:ot,preventDefault:!0},{key:"Ctrl-f",run:ge,shift:lt},{key:"Ctrl-p",run:He,shift:Dt},{key:"Ctrl-n",run:Ge,shift:St},{key:"Ctrl-a",run:Xe,shift:Tt},{key:"Ctrl-e",run:Ye,shift:It},{key:"Ctrl-d",run:Kt},{key:"Ctrl-h",run:Ft},{key:"Ctrl-k",run:en},{key:"Ctrl-Alt-h",run:Xt},{key:"Ctrl-o",run:ln},{key:"Ctrl-t",run:sn},{key:"Ctrl-v",run:$e}],En=[{key:"ArrowLeft",run:pe,shift:ot,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:xe,shift:ut,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Ke,shift:Et,preventDefault:!0},{key:"ArrowRight",run:ge,shift:lt,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Me,shift:ht,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Qe,shift:Ot,preventDefault:!0},{key:"ArrowUp",run:He,shift:Dt,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Vt,shift:Lt},{mac:"Ctrl-ArrowUp",run:qe,shift:Mt},{key:"ArrowDown",run:Ge,shift:St,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Rt,shift:Jt},{mac:"Ctrl-ArrowDown",run:$e,shift:Bt},{key:"PageUp",run:qe,shift:Mt},{key:"PageDown",run:$e,shift:Bt},{key:"Home",run:_e,shift:bt,preventDefault:!0},{key:"Mod-Home",run:Vt,shift:Lt},{key:"End",run:Fe,shift:Ct,preventDefault:!0},{key:"Mod-End",run:Rt,shift:Jt},{key:"Enter",run:vn,shift:vn},{key:"Mod-a",run:Nt},{key:"Backspace",run:Ft,shift:Ft,preventDefault:!0},{key:"Delete",run:Kt,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Xt,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:Yt,preventDefault:!0},{mac:"Mod-Backspace",run:nn,preventDefault:!0},{mac:"Mod-Delete",run:rn,preventDefault:!0}].concat(bn.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),On=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Ne,shift:At},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Ue,shift:kt},{key:"Alt-ArrowUp",run:fn},{key:"Shift-Alt-ArrowUp",run:mn},{key:"Alt-ArrowDown",run:un},{key:"Shift-Alt-ArrowDown",run:dn},{key:"Mod-Alt-ArrowUp",run:Gt},{key:"Mod-Alt-ArrowDown",run:Pt},{key:"Escape",run:Wt},{key:"Mod-Enter",run:An},{key:"Alt-l",mac:"Ctrl-l",run:Ut},{key:"Mod-i",run:zt,preventDefault:!0},{key:"Mod-[",run:xn},{key:"Mod-]",run:Sn},{key:"Mod-Alt-\\",run:Dn},{key:"Shift-Mod-k",run:pn},{key:"Shift-Mod-\\",run:et},{key:"Mod-/",run:S},{key:"Alt-A",run:b},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Mn}].concat(En),Tn={key:"Tab",run:Sn,shift:xn};export{Gt as addCursorAbove,Pt as addCursorBelow,E as blockComment,O as blockUncomment,dn as copyLineDown,mn as copyLineUp,ve as cursorCharBackward,De as cursorCharBackwardLogical,ye as cursorCharForward,we as cursorCharForwardLogical,pe as cursorCharLeft,ge as cursorCharRight,Rt as cursorDocEnd,Vt as cursorDocStart,Ce as cursorGroupBackward,Be as cursorGroupForward,Ee as cursorGroupForwardWin,xe as cursorGroupLeft,Me as cursorGroupRight,_e as cursorLineBoundaryBackward,Fe as cursorLineBoundaryForward,Ke as cursorLineBoundaryLeft,Qe as cursorLineBoundaryRight,Ge as cursorLineDown,Ye as cursorLineEnd,Xe as cursorLineStart,He as cursorLineUp,et as cursorMatchingBracket,$e as cursorPageDown,qe as cursorPageUp,Re as cursorSubwordBackward,Ve as cursorSubwordForward,Ne as cursorSyntaxLeft,Ue as cursorSyntaxRight,On as defaultKeymap,Ft as deleteCharBackward,_t as deleteCharBackwardStrict,Kt as deleteCharForward,Xt as deleteGroupBackward,Yt as deleteGroupForward,Zt as deleteGroupForwardWin,pn as deleteLine,nn as deleteLineBoundaryBackward,rn as deleteLineBoundaryForward,en as deleteToLineEnd,tn as deleteToLineStart,on as deleteTrailingWhitespace,bn as emacsStyleKeymap,G as history,P as historyField,ie as historyKeymap,xn as indentLess,Sn as indentMore,Dn as indentSelection,Tn as indentWithTab,An as insertBlankLine,gn as insertNewline,vn as insertNewlineAndIndent,yn as insertNewlineKeepIndent,Cn as insertTab,U as invertedEffects,N as isolateHistory,B as lineComment,C as lineUncomment,un as moveLineDown,fn as moveLineUp,$ as redo,Q as redoDepth,F as redoSelection,Nt as selectAll,at as selectCharBackward,ct as selectCharBackwardLogical,st as selectCharForward,it as selectCharForwardLogical,ot as selectCharLeft,lt as selectCharRight,Jt as selectDocEnd,Lt as selectDocStart,dt as selectGroupBackward,mt as selectGroupForward,pt as selectGroupForwardWin,ut as selectGroupLeft,ht as selectGroupRight,Ut as selectLine,bt as selectLineBoundaryBackward,Ct as selectLineBoundaryForward,Et as selectLineBoundaryLeft,Ot as selectLineBoundaryRight,St as selectLineDown,It as selectLineEnd,Tt as selectLineStart,Dt as selectLineUp,tt as selectMatchingBracket,Bt as selectPageDown,Mt as selectPageUp,zt as selectParentSyntax,vt as selectSubwordBackward,yt as selectSubwordForward,At as selectSyntaxLeft,kt as selectSyntaxRight,Wt as simplifySelection,ln as splitLine,En as standardKeymap,Bn as temporarilySetTabFocusMode,b as toggleBlockComment,T as toggleBlockCommentByLine,S as toggleComment,M as toggleLineComment,Mn as toggleTabFocusMode,sn as transposeChars,q as undo,K as undoDepth,j as undoSelection};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lineNumbers as o,highlightActiveLineGutter as r,highlightSpecialChars as m,drawSelection as i,dropCursor as e,rectangularSelection as t,crosshairCursor as c,highlightActiveLine as f,keymap as l}from"@codemirror/view";export{EditorView}from"@codemirror/view";import{EditorState as a}from"@codemirror/state";import{foldGutter as p,indentOnInput as d,syntaxHighlighting as n,defaultHighlightStyle as s,bracketMatching as w,foldKeymap as u}from"@codemirror/language";import{history as b,defaultKeymap as g,historyKeymap as k}from"@codemirror/commands";import{highlightSelectionMatches as v,searchKeymap as x}from"@codemirror/search";import{closeBrackets as h,autocompletion as E,closeBracketsKeymap as M,completionKeymap as S}from"@codemirror/autocomplete";import{lintKeymap as V}from"@codemirror/lint";const j=(()=>[o(),r(),m(),b(),p(),i(),e(),a.allowMultipleSelections.of(!0),d(),n(s,{fallback:!0}),w(),h(),E(),t(),c(),f(),v(),l.of([...M,...g,...x,...k,...u,...S,...V])])(),q=(()=>[m(),b(),i(),n(s,{fallback:!0}),l.of([...g,...k])])();export{j as basicSetup,q as minimalSetup};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LRLanguage as O,LanguageSupport as r}from"@codemirror/language";import{html as e}from"@codemirror/lang-html";import{javascriptLanguage as t}from"@codemirror/lang-javascript";import{styleTags as n,tags as a}from"@lezer/highlight";import{parseMixed as o}from"@lezer/common";import{LRParser as i,ExternalTokenizer as p}from"@lezer/lr";const l=new p(O=>{let r=O.pos;for(;;){if(10==O.next){O.advance();break}if(123==O.next&&123==O.peek(1)||O.next<0)break;O.advance()}O.pos>r&&O.acceptToken(1)});function Q(O,r,e){return new p(t=>{let n=t.pos;for(;t.next!=O&&t.next>=0&&(e||38!=t.next&&(123!=t.next||123!=t.peek(1)));)t.advance();t.pos>n&&t.acceptToken(r)})}const S=Q(39,33,!1),u=Q(34,34,!1),q=Q(39,35,!0),s=Q(34,36,!0),P=i.deserialize({version:14,states:"(jOVOqOOOeQpOOOvO!bO'#CaOOOP'#Cx'#CxQVOqOOO!OQpO'#CfO!WQpO'#ClO!]QpO'#CrO!bQpO'#CsOOQO'#Cv'#CvQ!gQpOOQ!lQpOOQ!qQpOOOOOV,58{,58{O!vOpO,58{OOOP-E6v-E6vO!{QpO,59QO#TQpO,59QOOQO,59W,59WO#YQpO,59^OOQO,59_,59_O#_QpOOO#_QpOOO#gQpOOOOOV1G.g1G.gO#oQpO'#CyO#tQpO1G.lOOQO1G.l1G.lO#|QpO1G.lOOQO1G.x1G.xO$UO`O'#DUO$ZOWO'#DUOOQO'#Co'#CoQOQpOOOOQO'#Cu'#CuO$`OtO'#CwO$qOrO'#CwOOQO,59e,59eOOQO-E6w-E6wOOQO7+$W7+$WO%SQpO7+$WO%[QpO7+$WOOOO'#Cp'#CpO%aOpO,59pOOOO'#Cq'#CqO%fOpO,59pOOOS'#Cz'#CzO%kOtO,59cOOQO,59c,59cOOOQ'#C{'#C{O%|OrO,59cO&_QpO<<GrOOQO<<Gr<<GrOOQO1G/[1G/[OOOS-E6x-E6xOOQO1G.}1G.}OOOQ-E6y-E6yOOQOAN=^AN=^",stateData:"&d~OvOS~OPROSQOVROWRO~OZTO[XO^VOaUOhWO~OR]OU^O~O[`O^aO~O[bO~O[cO~O[dO~ObeO~ObfO~ObgO~ORhO~O]kOwiO~O[lO~O_mO~OynOzoO~OysOztO~O[uO~O]wOwiO~O_yOwiO~OtzO~Os|O~OSQOV!OOW!OOr!OOy!QO~OSQOV!ROW!ROq!ROz!QO~O_!TOwiO~O]!UO~Oy!VO~Oz!VO~OSQOV!OOW!OOr!OOy!XO~OSQOV!ROW!ROq!ROz!XO~O]!ZO~O",goto:"#dyPPPPPzPPPP!WPPPPP!WPP!Z!^!a!d!dP!g!j!m!p!v#Q#WPPPPPPPP#^SROSS!Os!PT!Rt!SRYPRqeR{nR}oRZPRqfR[PRqgQSOR_SQj`SvjxRxlQ!PsR!W!PQ!StR!Y!SQpeRrf",nodeNames:"⚠ Text Content }} {{ Interpolation InterpolationContent Entity InvalidEntity Attribute BoundAttributeName [ Identifier ] ( ) ReferenceName # Is ExpressionAttributeValue AttributeInterpolation AttributeInterpolation EventName DirectiveName * StatementAttributeValue AttributeName AttributeValue",maxTerm:42,nodeProps:[["openedBy",3,"{{",15,"("],["closedBy",4,"}}",14,")"],["isolate",-4,5,19,25,27,""]],skippedNodes:[0],repeatNodeCount:4,tokenData:"0r~RyOX#rXY$mYZ$mZ]#r]^$m^p#rpq$mqr#rrs%jst&Qtv#rvw&hwx)zxy*byz*xz{+`{}#r}!O+v!O!P-]!P!Q#r!Q![+v![!]+v!]!_#r!_!`-s!`!c#r!c!}+v!}#O.Z#O#P#r#P#Q.q#Q#R#r#R#S+v#S#T#r#T#o+v#o#p/X#p#q#r#q#r0Z#r%W#r%W;'S+v;'S;:j-V;:j;=`$g<%lO+vQ#wTUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rQ$ZSO#q#r#r;'S#r;'S;=`$g<%lO#rQ$jP;=`<%l#rR$t[UQvPOX#rXY$mYZ$mZ]#r]^$m^p#rpq$mq#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR%qTyPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR&XTaPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR&oXUQWPOp'[pq#rq!]'[!]!^#r!^#q'[#q#r(d#r;'S'[;'S;=`)t<%lO'[R'aXUQOp'[pq#rq!]'[!]!^'|!^#q'[#q#r(d#r;'S'[;'S;=`)t<%lO'[R(TTVPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR(gXOp'[pq#rq!]'[!]!^'|!^#q'[#q#r)S#r;'S'[;'S;=`)t<%lO'[P)VUOp)Sq!])S!]!^)i!^;'S)S;'S;=`)n<%lO)SP)nOVPP)qP;=`<%l)SR)wP;=`<%l'[R*RTzPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR*iT^PUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR+PT_PUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR+gThPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR+}b[PUQO}#r}!O+v!O!Q#r!Q![+v![!]+v!]!c#r!c!}+v!}#R#r#R#S+v#S#T#r#T#o+v#o#q#r#q#r$W#r%W#r%W;'S+v;'S;:j-V;:j;=`$g<%lO+vR-YP;=`<%l+vR-dTwPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR-zTUQbPO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR.bTZPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR.xT]PUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR/^VUQO#o#r#o#p/s#p#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#rR/zTSPUQO#q#r#q#r$W#r;'S#r;'S;=`$g<%lO#r~0^TO#q#r#q#r0m#r;'S#r;'S;=`$g<%lO#r~0rOR~",tokenizers:[l,S,u,q,s,0,1],topRules:{Content:[0,2],Attribute:[1,9]},tokenPrec:0}),g=t.parser.configure({top:"SingleExpression"}),m=P.configure({props:[n({Text:a.content,Is:a.definitionOperator,AttributeName:a.attributeName,"AttributeValue ExpressionAttributeValue StatementAttributeValue":a.attributeValue,Entity:a.character,InvalidEntity:a.invalid,"BoundAttributeName/Identifier":a.attributeName,"EventName/Identifier":a.special(a.attributeName),"ReferenceName/Identifier":a.variableName,"DirectiveName/Identifier":a.keyword,"{{ }}":a.brace,"( )":a.paren,"[ ]":a.bracket,"# '*'":a.punctuation})]}),R={parser:g},$={parser:t.parser},c={parser:m.configure({wrap:o((O,r)=>"InterpolationContent"==O.name?R:null)})},v={parser:m.configure({wrap:o((O,r)=>{var e;return"InterpolationContent"==O.name?R:"AttributeInterpolation"!=O.name?null:"StatementAttributeValue"==(null===(e=O.node.parent)||void 0===e?void 0:e.name)?$:R}),top:"Attribute"})},b=e({selfClosingTags:!0});function d(O){return O.configure({wrap:o(W)},"angular")}const f=d(b.language);function W(O,r){switch(O.name){case"Attribute":return/^[*#(\[]|\{\{/.test(r.read(O.from,O.to))?v:null;case"Text":return c}return null}function C(e={}){let t=b;if(e.base){if("html"!=e.base.language.name||!(e.base.language instanceof O))throw new RangeError("The base option must be the result of calling html(...)");t=e.base}return new r(t.language==b.language?f:d(t.language),[t.support,t.language.data.of({closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/})])}export{C as angular,f as angularLanguage};
|