diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml
new file mode 100644
index 0000000..14b47b3
--- /dev/null
+++ b/.github/actions/setup/action.yml
@@ -0,0 +1,61 @@
+name: Setup
+
+description: Sets up PHP and Composer
+
+inputs:
+ php-version:
+ description: The PHP version(s) you wish to use.
+ required: true
+ php-extensions:
+ description: The PHP extensions you want to install.
+ required: false
+ default: dom, curl, libxml, mbstring, zip, pcntl, pdo, gd, redis, sqlite, pdo_sqlite, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp, :php-psr
+ coverage:
+ description: The coverage driver to use.
+ required: false
+ default: none
+
+runs:
+ using: composite
+ steps:
+ - name: Get PHP extension cache hash
+ id: get-cache-hash
+ env:
+ PHP_EXTENSIONS: ${{ inputs.php-extensions }}
+ run: echo hash=$(echo $PHP_EXTENSIONS | md5sum | awk '{print $1}') >> $GITHUB_OUTPUT
+ shell: bash
+
+ - name: Setup cache environment
+ id: extcache
+ uses: shivammathur/cache-extensions@v1
+ with:
+ php-version: ${{ inputs.php-version }}
+ extensions: ${{ inputs.php-extensions }}
+ key: php-extensions-${{ steps.get-cache-hash.outputs.hash }}
+
+ - name: Cache extensions
+ uses: actions/cache@v4
+ with:
+ path: ${{ steps.extcache.outputs.dir }}
+ key: ${{ steps.extcache.outputs.key }}
+ restore-keys: ${{ steps.extcache.outputs.key }}
+
+ - name: Setup PHP and Composer
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ inputs.php-version }}
+ extensions: ${{ inputs.php-extensions }}
+ tools: composer:v2
+ coverage: ${{ inputs.coverage }}
+
+ - name: Get Composer cache dir
+ id: composer-cache-dir
+ run: echo dir=$(composer config cache-files-dir) >> $GITHUB_OUTPUT
+ shell: bash
+
+ - name: Cache dependencies
+ uses: actions/cache@v4.0.2
+ with:
+ key: composer-cache-${{ hashFiles('**/composer.lock') }}
+ path: ${{ steps.composer-cache-dir.outputs.dir }}
+ restore-keys: composer-cache-
diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml
index 4e23b92..9991f5a 100644
--- a/.github/workflows/fix-php-code-style-issues.yml
+++ b/.github/workflows/fix-php-code-style-issues.yml
@@ -1,6 +1,7 @@
name: "Fix PHP Code Styling"
on:
+ workflow_dispatch:
push:
paths:
- '**.php'
diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml
index 3855a08..3cd2ef2 100644
--- a/.github/workflows/phpstan.yml
+++ b/.github/workflows/phpstan.yml
@@ -1,6 +1,7 @@
name: PHPStan
on:
+ workflow_dispatch:
push:
paths:
- '**.php'
@@ -16,7 +17,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.1'
+ php-version: '8.2'
coverage: none
- name: Install composer dependencies
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index 99b6755..624fc35 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -1,10 +1,17 @@
name: run-tests
on:
+ workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
+ paths:
+ - '**.php'
+ - '.github/workflows/tests.yml'
+ - 'phpunit.xml.dist'
+ - 'composer.json'
+ - 'composer.lock'
jobs:
test:
@@ -12,20 +19,17 @@ jobs:
strategy:
fail-fast: true
matrix:
- os: [ubuntu-latest, windows-latest]
- php: [8.3, 8.2, 8.1]
- laravel: [11.*, 10.*]
- stability: [prefer-lowest, prefer-stable]
+ os: [ubuntu-latest]
+ php: [8.3, 8.2]
+ laravel: [12.*, 11.*]
+ stability: [prefer-stable]
include:
- - laravel: 10.*
- testbench: 8.*
- carbon: 2.*
- laravel: 11.*
testbench: 9.*
carbon: 3.*
- exclude:
- - laravel: 11.*
- php: 8.1
+ - laravel: 12.*
+ testbench: 10.*
+ carbon: 3.*
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
@@ -37,7 +41,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
+ extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, fileinfo
coverage: none
- name: Setup problem matchers
diff --git a/README.md b/README.md
index 9d7b362..b6e9bc5 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,14 @@
-# TODO make a description
+# Mason
+
+A simple block based drag and drop page / document builder field for Filament.
+
+
[](https://packagist.org/packages/awcodes/mason)
[](https://github.com/awcodes/mason/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/awcodes/mason/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain)
[](https://packagist.org/packages/awcodes/mason)
-
-
-This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
-
## Installation
You can install the package via composer:
@@ -17,37 +17,186 @@ You can install the package via composer:
composer require awcodes/mason
```
-You can publish and run the migrations with:
+In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.
-```bash
-php artisan vendor:publish --tag="mason-migrations"
-php artisan migrate
+> [!IMPORTANT]
+> If you have not set up a custom theme and are using a Panel follow the instructions in the [Filament Docs](https://filamentphp.com/docs/3.x/panels/themes#creating-a-custom-theme) first.
+
+1. Import the plugin's stylesheet into your panel's custom theme css file. This will most likely be at `resources/css/filament/admin/theme.css`.
+
+```css
+@import '/vendor/awcodes/mason/resources/css/index.css';
```
-You can publish the config file with:
+2. Add the plugin's views to your `resources/css/filament/admin/tailwind.config.js` file.
+
+```js
+content: [
+ './vendor/awcodes/mason/resources/**/*.blade.php',
+]
+```
+
+3. Rebuild your custom theme.
```bash
-php artisan vendor:publish --tag="mason-config"
+npm run build
```
-Optionally, you can publish the views using
+## Configuration
+
+You can publish the config file with:
```bash
-php artisan vendor:publish --tag="mason-views"
+php artisan vendor:publish --tag="mason-config"
```
This is the contents of the published config file:
```php
return [
+ 'generator' => [
+ 'namespace' => 'App\\Mason',
+ 'views_path' => 'mason',
+ ],
];
```
## Usage
+> [!IMPORTANT]
+> Since Mason uses json to store its data in the database you will need to make sure your model's field is cast to 'array' or 'json'.
+
+### Form Field
+
+In your Filament forms you should use the `Mason` component. The `Mason` component accepts a `name` prop which should be the name of the field in your model, and requires an array of actions that make up the 'bricks' available to the editor.
+
+```php
+use Awcodes\Mason\Mason;
+use Awcodes\Mason\Bricks\Section;
+
+->schema([
+ Mason::make('content')
+ ->bricks([
+ Section::make(),
+ ])
+ // optional
+ ->placeholder('Drag and drop bricks to get started...'),
+])
+```
+
+### Infolist Entry
+
+In your Filament infolist you should use the `MasonEntry` component. The `Mason` component accepts a `name` prop which should be the name of the field in your model.
+
```php
-$mason = new Awcodes\Mason();
-echo $mason->echoPhrase('Hello, Awcodes!');
+use Awcodes\Mason\MasonEntry;
+use Awcodes\Mason\Bricks\Section;
+
+->schema([
+ MasonEntry::make('content')
+ ->bricks([
+ Section::make(),
+ ])
+])
+```
+
+To keep from having to repeat yourself when assigning bricks to the editor and the entry it would help to create sets of bricks that make sense for their use case. Then you can just use that in the `bricks` method.
+
+```php
+class BrickCollection
+{
+ public static function make(): array
+ {
+ return [
+ NewsletterSignup::make(),
+ Section::make(),
+ Cards::make(),
+ SupportCenter::make(),
+ ];
+ }
+}
+
+Mason::make('content')
+ ->bricks(BrickCollection::make())
+
+MasonEntry::make('content')
+ ->bricks(BrickCollection::make())
+```
+
+## Creating Bricks
+
+Bricks are nothing more than Filament actions that have an associated view that is rendered in the editor with its data.
+
+To help you get started there is a `make:mason-brick` command that will create a new brick for you with the necessary class and blade template in the paths specified in the config file.
+
+```bash
+php artisan make:mason-brick Section
+```
+
+This will create a new brick in the `App\Mason` namespace with the class `Section` and a blade template in the `resources/views/mason` directory. Bricks follow the same conventions as Filament actions. The important things to note are the `fillForm` method and the `action` method. These are how the action interacts with the editor. For bricks that do not have data you can remove the `fillForm` method and the `form` method from the brick and it will be inserted into the editor as is.
+
+```php
+use Awcodes\Mason\Brick;
+use Awcodes\Mason\EditorCommand;
+use Awcodes\Mason\Mason;
+use Filament\Forms\Components\FileUpload;
+use Filament\Forms\Components\Radio;
+use Filament\Forms\Components\RichEditor;
+
+class Section
+{
+ public static function make(): Brick
+ {
+ return Brick::make('section')
+ ->label('Section')
+ ->modalHeading('Section Settings')
+ ->icon('heroicon-o-cube')
+ ->slideOver()
+ ->fillForm(fn (array $arguments): array => [
+ 'background_color' => $arguments['background_color'] ?? 'white',
+ 'text' => $arguments['text'] ?? null,
+ 'image' => $arguments['image'] ?? null,
+ ])
+ ->form([
+ Radio::make('background_color')
+ ->options([
+ 'white' => 'White',
+ 'gray' => 'Gray',
+ 'primary' => 'Primary',
+ ])
+ ->inline()
+ ->inlineLabel(false),
+ FileUpload::make('image'),
+ RichEditor::make('text'),
+ ])
+ ->action(function (array $arguments, array $data, Mason $component) {
+ $component->runCommands(
+ [
+ new EditorCommand(
+ name: 'setBrick',
+ arguments: [[
+ 'identifier' => 'section',
+ 'values' => $data,
+ 'path' => 'bricks.section',
+ 'view' => view('bricks.section', $data)->toHtml(),
+ ]],
+ ),
+ ],
+ editorSelection: $arguments['editorSelection'],
+ );
+ });
+ }
+}
+```
+
+## Rendering Content
+
+You are free to render the content however you see fit. The data is stored in the database as json so you can use the data however you see fit. But the plugin offers a helper method for converting the data to html should you choose to use it.
+
+Similar to the form field and entry components the helper needs to know what bricks are available. You can pass the bricks to the helper as the second argument. See, above about creating a collection of bricks. This will help keep your code DRY.
+
+```html
+{!! mason($post->content, \App\Mason\BrickCollection::make())->toHtml() !!}
```
## Testing
diff --git a/composer.json b/composer.json
index 641e200..fff992d 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "awcodes/mason",
- "description": "TODO make a description",
+ "description": "A simple block based drag and drop page / document builder field for Filament.",
"keywords": [
"awcodes",
"laravel",
@@ -21,23 +21,23 @@
}
],
"require": {
- "php": "^8.3",
+ "php": "^8.2",
"filament/filament": "^3.2.139",
"spatie/laravel-package-tools": "^1.15.0",
"stevebauman/hypertext": "^1.1",
"ueberdosis/tiptap-php": "^1.4"
},
"require-dev": {
- "larastan/larastan": "^2.0",
+ "larastan/larastan": "^2.0||^3.0",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^8.0",
- "orchestra/testbench": "^9.0",
- "pestphp/pest": "^2.1",
- "pestphp/pest-plugin-arch": "^2.0",
- "pestphp/pest-plugin-laravel": "^2.0",
- "phpstan/extension-installer": "^1.1",
- "phpstan/phpstan-deprecation-rules": "^1.0",
- "phpstan/phpstan-phpunit": "^1.0",
+ "orchestra/testbench": "^9.0||^10.0",
+ "pestphp/pest": "^2.1||^3.0",
+ "pestphp/pest-plugin-arch": "^2.0||^3.0",
+ "pestphp/pest-plugin-laravel": "^2.0||^3.0",
+ "phpstan/extension-installer": "^1.1||^2.0",
+ "phpstan/phpstan-deprecation-rules": "^1.0||^2.0",
+ "phpstan/phpstan-phpunit": "^1.0||^2.0",
"spatie/laravel-ray": "^1.26"
},
"autoload": {
@@ -77,10 +77,7 @@
"laravel": {
"providers": [
"Awcodes\\Mason\\MasonServiceProvider"
- ],
- "aliases": {
- "Mason": "Awcodes\\Mason\\Facades\\Mason"
- }
+ ]
}
},
"minimum-stability": "dev",
diff --git a/config/mason.php b/config/mason.php
index decc0c2..59e26d7 100644
--- a/config/mason.php
+++ b/config/mason.php
@@ -1,16 +1,6 @@
[
'namespace' => 'App\\Mason',
'views_path' => 'mason',
diff --git a/resources/css/index.css b/resources/css/index.css
index 467890e..455ec70 100644
--- a/resources/css/index.css
+++ b/resources/css/index.css
@@ -19,14 +19,18 @@
@apply min-h-full;
p.is-empty {
- @apply py-1 px-2;
-
- &:first-child::before {
- @apply text-gray-400 dark:text-gray-600;
- content: attr(data-placeholder);
- float: left;
- height: 0;
- pointer-events: none;
+ @apply h-0;
+
+ &:first-child {
+ @apply py-1 px-2 h-auto;
+
+ &::before {
+ @apply text-gray-400 dark:text-gray-600;
+ content: attr(data-placeholder);
+ float: left;
+ height: 0;
+ pointer-events: none;
+ }
}
}
@@ -63,13 +67,33 @@
@apply text-white block rounded p-1 hover:text-primary-500 hover:bg-gray-800;
svg {
- @apply w-4 h-4;
+ @apply w-6 h-6 lg:w-4 lg:h-4;
}
&:disabled {
@apply opacity-50;
}
}
+
+ button.no-values {
+ @apply hidden;
+ }
+ }
+
+ &:first-of-type {
+ [data-move-up-button] {
+ @apply hidden;
+ }
+ }
+
+ &:last-of-type {
+ [data-move-down-button] {
+ @apply hidden;
+ }
+ }
+
+ [data-delete-brick-button] {
+ @apply text-danger-400 dark:text-danger-400;
}
}
}
diff --git a/resources/dist/mason.css b/resources/dist/mason.css
index 3c7eccc..eb45463 100644
--- a/resources/dist/mason.css
+++ b/resources/dist/mason.css
@@ -1 +1 @@
-:root{--mason-primary:#0ea5e9}.mason-wrapper .mason-input-wrapper{overflow:hidden}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input{display:flex;max-height:40rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper{flex:1 1 0%}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor{height:100%;min-height:100%;flex:1 1 0%;overflow-y:auto}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap{min-height:100%}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty{padding:.25rem .5rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child:before{--tw-text-opacity:1;color:rgba(var(--gray-400),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child:is(.dark *):before{--tw-text-opacity:1;color:rgba(var(--gray-600),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child:before{content:attr(data-placeholder);float:left;height:0;pointer-events:none}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick]{min-height:2rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader{margin:1rem;height:1.25rem;width:1.25rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader{animation:spin 1s linear infinite;--tw-text-opacity:1;color:rgba(var(--gray-950),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader:is(.dark *){--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader circle{opacity:.25}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader path{opacity:.75}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-rendered{cursor:grab}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-rendered *{pointer-events:none}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls{position:absolute;display:none;align-items:center;border-bottom-left-radius:.375rem;--tw-bg-opacity:1;background-color:rgba(var(--gray-700),var(--tw-bg-opacity,1));padding:.25rem;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-950),var(--tw-bg-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls{z-index:1;top:2px;right:2px}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button{display:block;border-radius:.25rem;padding:.25rem;--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button:hover{--tw-bg-opacity:1;background-color:rgba(var(--gray-800),var(--tw-bg-opacity,1));--tw-text-opacity:1;color:rgba(var(--primary-500),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button svg{height:1rem;width:1rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button:disabled{opacity:.5}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar{display:none;height:100%;max-width:12rem;flex-shrink:0;flex-direction:column}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-color:rgba(var(--gray-950),.1)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar{border-inline-start-width:1px;border-color:rgba(var(--gray-950),.1);--tw-bg-opacity:1;background-color:rgba(var(--gray-50),var(--tw-bg-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar:is(.dark *)>:not([hidden])~:not([hidden]){border-color:hsla(0,0%,100%,.05)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar:is(.dark *){border-color:hsla(0,0%,100%,.05);background-color:rgba(var(--gray-950),.2)}@media (min-width:768px){.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar{display:flex}}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions-bricks,.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions-search,.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls{gap:.5rem;padding:.5rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls{display:flex;align-items:center}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls svg{height:1.25rem;width:1.25rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls .active{--tw-text-opacity:1;color:rgba(var(--primary-600),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls .active:is(.dark *){--tw-text-opacity:1;color:rgba(var(--primary-500),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions{display:flex;flex:1 1 0%;flex-direction:column}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-color:rgba(var(--gray-950),.1)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions{overflow:hidden}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions:is(.dark *)>:not([hidden])~:not([hidden]){border-color:hsla(0,0%,100%,.05)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks{display:flex;flex:1 1 0%;flex-direction:column;gap:.5rem;overflow-y:auto}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks .mason-actions-brick{display:flex;cursor:move;align-items:center;gap:.5rem;border-radius:.25rem;border-width:1px;--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1));padding-top:.5rem;padding-bottom:.5rem;padding-inline-start:.75rem;padding-inline-end:1rem;font-size:.75rem;line-height:1rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks .mason-actions-brick:is(.dark *){--tw-border-opacity:1;border-color:rgba(var(--gray-700),var(--tw-border-opacity,1));--tw-bg-opacity:1;background-color:rgba(var(--gray-800),var(--tw-bg-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks .mason-actions-brick.filtered{display:none!important}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input.sidebar-start{flex-direction:row-reverse}.mason-wrapper.is-focused .ProseMirror-selectednode{outline-offset:-4px;outline:var(--mason-primary) solid 4px}.mason-wrapper.is-focused .ProseMirror-selectednode .mason-brick-controls{display:flex!important}.mason-wrapper.fullscreen{position:fixed;inset:0;z-index:20;--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.mason-wrapper.fullscreen:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-900),var(--tw-bg-opacity,1))}.mason-wrapper.fullscreen .mason-input-wrapper{height:100%;border-radius:0}.mason-wrapper.fullscreen .mason-input-wrapper .fi-input-wrp-input{max-height:100%}.mason-wrapper.fullscreen .mason-editor{container-type:inline-size}.mason-wrapper.display-mobile,.mason-wrapper.display-tablet{--tw-bg-opacity:1;background-color:rgba(var(--gray-100),var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile:is(.dark *),.mason-wrapper.display-tablet:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-950),var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile .mason-editor-wrapper,.mason-wrapper.display-tablet .mason-editor-wrapper{padding:1.5rem}.mason-wrapper.display-mobile .mason-editor-wrapper .mason-editor,.mason-wrapper.display-tablet .mason-editor-wrapper .mason-editor{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile .mason-editor-wrapper .mason-editor:is(.dark *),.mason-wrapper.display-tablet .mason-editor-wrapper .mason-editor:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-900),var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile .mason-editor-wrapper .mason-editor{margin-left:auto;margin-right:auto;max-width:392px!important}.mason-wrapper.display-tablet .mason-editor-wrapper .mason-editor{margin-left:auto;margin-right:auto;max-width:768px!important}
\ No newline at end of file
+:root{--mason-primary:#0ea5e9}.mason-wrapper .mason-input-wrapper{overflow:hidden}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input{display:flex;max-height:40rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper{flex:1 1 0%}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor{height:100%;min-height:100%;flex:1 1 0%;overflow-y:auto}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap{min-height:100%}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty{height:0}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child{height:auto;padding:.25rem .5rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child:before{--tw-text-opacity:1;color:rgba(var(--gray-400),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child:is(.dark *):before{--tw-text-opacity:1;color:rgba(var(--gray-600),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap p.is-empty:first-child:before{content:attr(data-placeholder);float:left;height:0;pointer-events:none}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick]{min-height:2rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader{margin:1rem;height:1.25rem;width:1.25rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader{animation:spin 1s linear infinite;--tw-text-opacity:1;color:rgba(var(--gray-950),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader:is(.dark *){--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader circle{opacity:.25}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-loader path{opacity:.75}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-rendered{cursor:grab}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-rendered *{pointer-events:none}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls{position:absolute;display:none;align-items:center;border-bottom-left-radius:.375rem;--tw-bg-opacity:1;background-color:rgba(var(--gray-700),var(--tw-bg-opacity,1));padding:.25rem;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-950),var(--tw-bg-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls{z-index:1;top:2px;right:2px}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button{display:block;border-radius:.25rem;padding:.25rem;--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button:hover{--tw-bg-opacity:1;background-color:rgba(var(--gray-800),var(--tw-bg-opacity,1));--tw-text-opacity:1;color:rgba(var(--primary-500),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button svg{height:1.5rem;width:1.5rem}@media (min-width:1024px){.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button svg{height:1rem;width:1rem}}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button:disabled{opacity:.5}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] .mason-brick-controls button.no-values,.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick]:first-of-type [data-move-up-button],.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick]:last-of-type [data-move-down-button]{display:none}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] [data-delete-brick-button]{--tw-text-opacity:1;color:rgba(var(--danger-400),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-editor-wrapper .mason-editor .tiptap [data-mason-brick] [data-delete-brick-button]:is(.dark *){--tw-text-opacity:1;color:rgba(var(--danger-400),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar{display:none;height:100%;max-width:12rem;flex-shrink:0;flex-direction:column}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-color:rgba(var(--gray-950),.1)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar{border-inline-start-width:1px;border-color:rgba(var(--gray-950),.1);--tw-bg-opacity:1;background-color:rgba(var(--gray-50),var(--tw-bg-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar:is(.dark *)>:not([hidden])~:not([hidden]){border-color:hsla(0,0%,100%,.05)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar:is(.dark *){border-color:hsla(0,0%,100%,.05);background-color:rgba(var(--gray-950),.2)}@media (min-width:768px){.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar{display:flex}}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions-bricks,.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions-search,.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls{gap:.5rem;padding:.5rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls{display:flex;align-items:center}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls svg{height:1.25rem;width:1.25rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls .active{--tw-text-opacity:1;color:rgba(var(--primary-600),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-controls .active:is(.dark *){--tw-text-opacity:1;color:rgba(var(--primary-500),var(--tw-text-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions{display:flex;flex:1 1 0%;flex-direction:column}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse));border-color:rgba(var(--gray-950),.1)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions{overflow:hidden}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions:is(.dark *)>:not([hidden])~:not([hidden]){border-color:hsla(0,0%,100%,.05)}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks{display:flex;flex:1 1 0%;flex-direction:column;gap:.5rem;overflow-y:auto}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks .mason-actions-brick{display:flex;cursor:move;align-items:center;gap:.5rem;border-radius:.25rem;border-width:1px;--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1));padding-top:.5rem;padding-bottom:.5rem;padding-inline-start:.75rem;padding-inline-end:1rem;font-size:.75rem;line-height:1rem}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks .mason-actions-brick:is(.dark *){--tw-border-opacity:1;border-color:rgba(var(--gray-700),var(--tw-border-opacity,1));--tw-bg-opacity:1;background-color:rgba(var(--gray-800),var(--tw-bg-opacity,1))}.mason-wrapper .mason-input-wrapper .fi-input-wrp-input .mason-sidebar .mason-actions .mason-actions-bricks .mason-actions-brick.filtered{display:none!important}.mason-wrapper .mason-input-wrapper.sidebar-start .fi-input-wrp-input{flex-direction:row-reverse}.mason-wrapper.is-focused .ProseMirror-selectednode{outline-offset:-4px;outline:var(--mason-primary) solid 4px}.mason-wrapper.is-focused .ProseMirror-selectednode .mason-brick-controls{display:flex!important}.mason-wrapper.fullscreen{position:fixed;inset:0;z-index:20;--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.mason-wrapper.fullscreen:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-900),var(--tw-bg-opacity,1))}.mason-wrapper.fullscreen .mason-input-wrapper{height:100%;border-radius:0}.mason-wrapper.fullscreen .mason-input-wrapper .fi-input-wrp-input{max-height:100%}.mason-wrapper.fullscreen .mason-editor{container-type:inline-size}.mason-wrapper.display-mobile,.mason-wrapper.display-tablet{--tw-bg-opacity:1;background-color:rgba(var(--gray-100),var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile:is(.dark *),.mason-wrapper.display-tablet:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-950),var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile .mason-editor-wrapper,.mason-wrapper.display-tablet .mason-editor-wrapper{padding:1.5rem}.mason-wrapper.display-mobile .mason-editor-wrapper .mason-editor,.mason-wrapper.display-tablet .mason-editor-wrapper .mason-editor{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile .mason-editor-wrapper .mason-editor:is(.dark *),.mason-wrapper.display-tablet .mason-editor-wrapper .mason-editor:is(.dark *){--tw-bg-opacity:1;background-color:rgba(var(--gray-900),var(--tw-bg-opacity,1))}.mason-wrapper.display-mobile .mason-editor-wrapper .mason-editor{margin-left:auto;margin-right:auto;max-width:392px!important}.mason-wrapper.display-tablet .mason-editor-wrapper .mason-editor{margin-left:auto;margin-right:auto;max-width:768px!important}
\ No newline at end of file
diff --git a/resources/dist/mason.js b/resources/dist/mason.js
index 96ab0a5..6b0e5f4 100644
--- a/resources/dist/mason.js
+++ b/resources/dist/mason.js
@@ -1,16 +1,16 @@
-function W(n){this.content=n}W.prototype={constructor:W,find:function(n){for(var e=0;e>1}};W.from=function(n){if(n instanceof W)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new W(e)};var Nn=W;function yi(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=yi(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function bi(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=0,f=Math.min(o.text.length,l.text.length);for(;ce&&r(a,i+l,s||null,o)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),r,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Bt(r+1,o):Bt(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};N.none=[];var Pe=class extends Error{},k=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=xi(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ki(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(b.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};k.empty=new k(b.empty,0,0);function ki(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(ki(s.content,e-i-1,t-i-1)))}function xi(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=xi(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function dl(n,e,t){if(t.openStart>n.depth)throw new Pe("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Pe("Inconsistent open depths");return Si(n,e,t,0)}function Si(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function lt(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(ve(n.nodeAfter,r),s++));for(let l=s;li&&vn(n,e,i+1),o=r.depth>i&&vn(t,r,i+1),l=[];return lt(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(wi(s,o),ve(Ie(s,Ci(n,e,t,r,i+1)),l)):(s&&ve(Ie(s,Lt(n,e,i+1)),l),lt(e,t,i,l),o&&ve(Ie(o,Lt(t,r,i+1)),l)),lt(r,null,i,l),new b(l)}function Lt(n,e,t){let r=[];if(lt(null,n,t,r),n.depth>t){let i=vn(n,e,t+1);ve(Ie(i,Lt(n,e,t+1)),r)}return lt(e,null,t,r),new b(r)}function ul(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(b.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var $t=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Re(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new n(t,r,s)}static resolveCached(e,t){let r=ai.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Mi(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=b.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=b.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};ee.prototype.text=void 0;var Pn=class n extends ee{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Mi(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Mi(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var Be=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Rn(e,t);if(r.next==null)return n.empty;let i=Oi(r);r.next&&r.err("Unexpected trailing text");let s=Sl(xl(i));return wl(s,r),s}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(`
-`)}};Be.empty=new Be(!0);var Rn=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Oi(n){let e=[];do e.push(ml(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ml(n){let e=[];do e.push(gl(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function gl(n){let e=kl(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=yl(n,e);else break;return e}function ci(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function yl(n,e){let t=ci(n),r=t;return n.eat(",")&&(n.next!="}"?r=ci(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function bl(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function kl(n){if(n.eat("(")){let e=Oi(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=bl(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function xl(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[r.join(",")]=new Be(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ni(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ee(this,this.computeAttrs(e),b.from(t),N.setFrom(r))}createChecked(e=null,t,r){return t=b.from(t),this.checkContent(t),new ee(this,this.computeAttrs(e),t,N.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=b.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(b.empty,!0);return s?new ee(this,e,t.append(s),N.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Cl(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Bn=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Cl(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},ct=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Ai(e,i.attrs),this.excluded=null;let s=Ti(this.attrs);this.instance=s?new N(this,s):null}create(e=null){return!e&&this.instance?this.instance:new N(this,Ni(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},ft=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Nn.from(e.nodes),t.marks=Nn.from(e.marks||{}),this.nodes=Vt.compile(this.spec.nodes,this),this.marks=ct.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=Be.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?di(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:di(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Vt){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Pn(r,r.defaultAttrs,e,N.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return ee.fromJSON(this,e)}markFromJSON(e){return N.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function di(n,e){let t=[];for(let r=0;r-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ml(n){return n.tag!=null}function Ol(n){return n.style!=null}var he=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ml(i))this.tags.push(i);else if(Ol(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Jt(this,t,!1);return r.addAll(e,N.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Jt(this,t,!0);return r.addAll(e,N.none,t.from,t.to),k.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=hi(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=hi(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},vi={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},El={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ii={ol:!0,ul:!0},dt=1,zn=2,at=4;function ui(n,e,t){return e!=null?(e?dt:0)|(e==="full"?zn:0):n&&n.whitespace=="pre"?dt|zn:t&~at}var Ge=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=N.none,this.match=s||(o&at?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(b.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&dt)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=b.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(b.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!vi.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Jt=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=ui(null,t.preserveWhitespace,0)|(r?at:0);i?s=new Ge(i.type,i.attrs,N.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ge(null,null,N.none,!0,null,o):s=new Ge(e.schema.topNodeType,null,N.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top,s=i.options&zn?"full":this.localPreserveWS||(i.options&dt)>0;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)s!=="full"?r=r.replace(/\r?\n|\r/g," "):r=r.replace(/\r\n?/g,`
-`);else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],l=e.previousSibling;(!o||l&&l.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Ii.hasOwnProperty(o)&&this.parser.normalizeLists&&Tl(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,r));e:if(a?a.ignore:El.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(vi.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let d=a&&a.skip?t:this.readStyles(e,t);d&&this.addAll(e,d),c&&this.sync(s),this.needsBlock=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
-`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(o,t.attrs||null,r,t.preserveWhitespace);a&&(s=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(c.type):pi(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ge(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=dt)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Tl(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ii.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Nl(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function hi(n){let e={};for(let t in n)e[t]=n[t];return e}function pi(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&zt(An(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return zt(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=mi(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return mi(e.marks)}};function mi(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function An(n){return n.document||window.document}var gi=new WeakMap;function Dl(n){let e=gi.get(n);return e===void 0&&gi.set(n,e=Al(n)),e}function Al(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let d in c)if(c[d]!=null){let u=d.indexOf(" ");u>0?a.setAttributeNS(d.slice(0,u),d.slice(u+1),c[d]):a.setAttribute(d,c[d])}}for(let d=f;df)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:p}=zt(n,u,t,r);if(a.appendChild(h),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}var Bi=65535,zi=Math.pow(2,16);function vl(n,e){return n+e*zi}function Pi(n){return n&Bi}function Il(n){return(n-(n&Bi))/zi}var Fi=1,Li=2,Wt=4,$i=8,pt=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&$i)>0}get deletedBefore(){return(this.delInfo&(Fi|Wt))>0}get deletedAfter(){return(this.delInfo&(Li|Wt))>0}get deletedAcross(){return(this.delInfo&Wt)>0}},me=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=Pi(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+s],f=this.ranges[l+o],d=a+c;if(e<=d){let u=c?e==a?-1:e==d?1:t:t,h=a+i+(u<0?0:f);if(r)return h;let p=e==(t<0?a:d)?null:vl(l/3,e-a),m=e==a?Li:e==d?Fi:Wt;return(t<0?e!=a:e!=d)&&(m|=$i),new pt(h,m,p)}i+=f-c}return r?e+i:new pt(e+i,0,null)}touches(e,t){let r=0,i=Pi(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return L.fromReplace(e,this.from,this.to,s)}invert(){return new ze(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};z.jsonID("addMark",gt);var ze=class n extends z{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new k(Wn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return L.fromReplace(e,this.from,this.to,r)}invert(){return new gt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};z.jsonID("removeMark",ze);var yt=class n extends z{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return L.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return L.fromReplace(e,this.pos,this.pos+1,new k(b.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}};z.jsonID("replaceAround",R);function Vn(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Pl(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let d=a.marks;if(!r.isInSet(d)&&f.type.allowsMarkType(r.type)){let u=Math.max(c,e),h=Math.min(c+a.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(a)),s.forEach(a=>n.step(a))}function Rl(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof ct){let c=o.marks,f;for(;f=r.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;fn.step(new ze(o.from,o.to,o.style)))}function jn(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a=0;a--)n.step(o[a])}function Bl(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function ge(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,f=b.from(r.node(p).copy(f)),d++):a--;let u=b.empty,h=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=b.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new R(i,s,i,s,new k(r,0,0),t.length,!0))}function Vl(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,a)&&Jl(n.doc,n.mapping.slice(s).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let h=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);h&&!p?c=!1:!h&&p&&(c=!0)}c===!1&&Ji(n,o,l,s),jn(n,n.mapping.slice(s).map(l,1),r,void 0,c===null);let f=n.mapping.slice(s),d=f.map(l,1),u=f.map(l+o.nodeSize,1);return n.step(new R(d,u,d+1,u-1,new k(b.from(r.create(a,null,o.marks)),0,0),1,!0)),c===!0&&Vi(n,o,l,s),!1}})}function Vi(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Ji(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
-`))}})}function Jl(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Wl(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new R(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new k(b.from(o),0,0),1,!0))}function te(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>s;c--,f--){let d=i.node(c),u=i.index(c);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(u,d.childCount),p=r&&r[f+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[f]||d;if(!d.canReplace(u+1,d.childCount)||!m.type.validContent(h))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function jl(n,e,t=1,r){let i=n.doc.resolve(e),s=b.empty,o=b.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=b.from(i.node(l).copy(s));let f=r&&r[c];o=b.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}n.step(new j(e,e,new k(s.append(o),t,t),!0))}function oe(n,e){let t=n.resolve(e),r=t.index();return Wi(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Kl(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Wi(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Hl(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);f&&!d?r=!1:!f&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let f=n.doc.resolve(e+t);Ji(n,f.node(),f.before(),l)}o.inlineContent&&jn(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new j(c,a.map(e+t,-1),k.empty,!0)),r===!0){let f=n.doc.resolve(c);Vi(n,f.node(),f.before(),n.steps.length)}return n}function ql(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),c=r.node(o),f=!1;if(s==1)f=c.canReplace(a,a,i);else{let d=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=d&&c.canReplaceWith(a,a,d[0])}if(f)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function St(n,e,t=e,r=k.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return ji(i,s,r)?new j(e,t,r):new Jn(i,s,r).fit()}function ji(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Jn=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=b.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=b.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new k(s,o,l);return e>-1?new R(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new j(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Ln(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,d=null;if(t==1&&(o?c.matchType(o.type)||(d=c.fillBefore(b.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(f=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ln(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ln(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new k(ut(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new k(ut(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(d=g,f.push(Ki(m.mark(u.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?h:-1)))}let p=c==l.childCount;p||(h=-1),this.placed=ht(this.placed,t,b.from(f)),this.frontier[t].match=d,p&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:c}=this.frontier[l],f=$n(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ht(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ht(this.placed,this.depth,b.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(b.empty,!0);t.childCount&&(this.placed=ht(this.placed,this.frontier.length,t))}};function ut(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(ut(n.firstChild.content,e-1,t)))}function ht(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(ht(n.lastChild.content,e-1,t)))}function Ln(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ki(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(b.empty,!0)))),n.copy(r)}function $n(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Ul(t,s.content,o)?l:null}function Ul(n,e,t){for(let r=t;r0;u--,h--){let p=i.node(u).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(u)>-1?l=u:i.before(u)==h&&o.splice(1,0,-u)}let a=o.indexOf(l),c=[],f=r.openStart;for(let u=r.content,h=0;;h++){let p=u.firstChild;if(c.push(p),h==r.openStart)break;u=p.content}for(let u=f-1;u>=0;u--){let h=c[u],p=_l(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))f=u;else if(p||!h.type.isTextblock)break}for(let u=r.openStart;u>=0;u--){let h=(u+f+1)%(r.openStart+1),p=c[h];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));u--){let h=o[u];h<0||(e=i.before(h),t=s.after(h))}}function Hi(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(b.empty,!0))}return n}function Yl(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=ql(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new k(b.from(r),0,0))}function Xl(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=qi(r,i);for(let o=0;o0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function qi(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var jt=class n extends z{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return L.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return L.fromReplace(e,this.pos,this.pos+1,new k(b.from(i),0,t.isLeaf?0:1))}getMap(){return me.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};z.jsonID("attr",jt);var Kt=class n extends z{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return L.ok(r)}getMap(){return me.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};z.jsonID("docAttr",Kt);var Ye=class extends Error{};Ye=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Ye.prototype=Object.create(Error.prototype);Ye.prototype.constructor=Ye;Ye.prototype.name="TransformError";var kt=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new mt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Ye(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=k.empty){let i=St(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new k(b.from(r),0,0))}delete(e,t){return this.replace(e,t,k.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Gl(this,e,t,r),this}replaceRangeWith(e,t,r){return Yl(this,e,t,r),this}deleteRange(e,t){return Xl(this,e,t),this}lift(e,t){return zl(this,e,t),this}join(e,t=1){return Hl(this,e,t),this}wrap(e,t){return $l(this,e,t),this}setBlockType(e,t=e,r,i=null){return Vl(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Wl(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new jt(e,t,r)),this}setDocAttribute(e,t){return this.step(new Kt(e,t)),this}addNodeMark(e,t){return this.step(new yt(e,t)),this}removeNodeMark(e,t){if(!(t instanceof N)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new bt(e,t)),this}split(e,t=1,r){return jl(this,e,t,r),this}addMark(e,t,r){return Pl(this,e,t,r),this}removeMark(e,t,r){return Rl(this,e,t,r),this}clearIncompatible(e,t,r){return jn(this,e,t,r),this}};var Kn=Object.create(null),C=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Ut(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Ze(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Ze(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new U(e.node(0))}static atStart(e){return Ze(e,e,0,0,1)||new U(e)}static atEnd(e){return Ze(e,e,e.content.size,e.childCount,-1)||new U(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Kn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Kn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Kn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return M.between(this.$anchor,this.$head).getBookmark()}};C.prototype.visible=!0;var Ut=class{constructor(e,t){this.$from=e,this.$to=t}},Ui=!1;function _i(n){!Ui&&!n.parent.inlineContent&&(Ui=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var M=class n extends C{constructor(e,t=e){_i(e),_i(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return C.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=k.empty){if(super.replace(e,t),t==k.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new _t(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=C.findFrom(t,r,!0)||C.findFrom(t,-r,!0);if(s)t=s.$head;else return C.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(C.findFrom(e,-r,!0)||C.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&S.isSelectable(l))return S.create(n,t-(i<0?l.nodeSize:0))}else{let a=Ze(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Gi(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=f)}),n.setSelection(C.near(n.doc.resolve(o),t))}var Yi=1,qt=2,Xi=4,Un=class extends kt{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=qt,this}ensureMarks(e){return N.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&qt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~qt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||N.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(C.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Xi,this}get scrolledIntoView(){return(this.updated&Xi)>0}};function Zi(n,e){return!e||!n?n:n.bind(e)}var Fe=class{constructor(e,t,r){this.name=e,this.init=Zi(t.init,r),this.apply=Zi(t.apply,r)}},Ql=[new Fe("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Fe("selection",{init(n,e){return n.selection||C.atStart(e.doc)},apply(n){return n.selection}}),new Fe("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Fe("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],wt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ql.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Fe(r.key,r.spec.state,r))})}},Gt=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new wt(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ee.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=C.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Qi(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Qi(i,e,{})),t[r]=i}return t}var I=class{constructor(e){this.spec=e,this.props={},e.props&&Qi(e.props,this,this.props),this.key=e.key?e.key.key:es("plugin")}getState(e){return e[this.key]}},Hn=Object.create(null);function es(n){return n in Hn?n+"$"+ ++Hn[n]:(Hn[n]=0,n+"$")}var $=class{constructor(e="key"){this.key=es(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var V=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Et=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Qn=null,be=function(n,e,t){let r=Qn||(Qn=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ea=function(){Qn=null},Ke=function(n,e,t,r){return t&&(ts(n,e,t,r,-1)||ts(n,e,t,r,1))},ta=/^(img|br|input|textarea|hr)$/i;function ts(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:re(n))){let s=n.parentNode;if(!s||s.nodeType!=1||At(n)||ta.test(n.nodeName)||n.contentEditable=="false")return!1;e=V(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?re(n):0}else return!1}}function re(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function na(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=re(n)}else if(n.parentNode&&!At(n))e=V(n),n=n.parentNode;else return null}}function ra(n,e){for(;;){if(n.nodeType==3&&e2),ne=rt||(le?/Mac/.test(le.platform):!1),la=le?/Win/.test(le.platform):!1,ke=/Android \d/.test(Ne),vt=!!ns&&"webkitFontSmoothing"in ns.documentElement.style,aa=vt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ca(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ye(n,e){return typeof n=="number"?n:n[e]}function fa(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function rs(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Et(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,c=a?ca(s):fa(l),f=0,d=0;if(e.topc.bottom-ye(r,"bottom")&&(d=e.bottom-e.top>c.bottom-c.top?e.top+ye(i,"top")-c.top:e.bottom-c.bottom+ye(i,"bottom")),e.leftc.right-ye(r,"right")&&(f=e.right-c.right+ye(i,"right")),f||d)if(a)s.defaultView.scrollBy(f,d);else{let u=l.scrollLeft,h=l.scrollTop;d&&(l.scrollTop+=d),f&&(l.scrollLeft+=f);let p=l.scrollLeft-u,m=l.scrollTop-h;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function da(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Fs(n.dom)}}function Fs(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Et(r));return e}function ua({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ls(t,r==0?0:r-e)}function Ls(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=f,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?pa(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:$s(t,i)}function pa(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function yr(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function ma(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function ya(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&(!o&&a.left>r.left||a.top>r.top?i=l.posBefore:(!o&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Vs(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;vt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=ya(n,r,i,e))}l==null&&(l=ga(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function is(n){return n.top=0&&i==r.nodeValue.length?(a--,f=1):t<0?a--:c++,Ct(Ce(be(r,a,c),f),f<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==re(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return _n(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==re(r))){let a=r.childNodes[i-1],c=a.nodeType==3?be(a,re(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Ct(Ce(c,1),!1)}if(s==null&&i=0)}function Ct(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function _n(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Ws(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function xa(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Ws(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Js(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=be(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cf.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}var Sa=/[\u0590-\u08ac]/;function wa(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Sa.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Ws(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:d}=n.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let h=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(f,d),a&&(a!=f||c!=d)&&l.extend&&l.extend(a,c)}catch{}return u!=null&&(l.caretBidiLevel=u),g}):r.pos==r.start()||r.pos==r.end()}var ss=null,ls=null,as=!1;function Ca(n,e,t){return ss==e&&ls==t?as:(ss=e,ls=t,as=t=="up"||t=="down"?xa(n,e,t):wa(n,e,t))}var ie=0,cs=1,$e=2,ae=3,He=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ie,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tV(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof Zt){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Yt&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?V(s.dom)+1:0}}else{let s,o=!0;for(;s=r=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let d=l;d>0;d--){let u=this.children[d-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){i=V(u.dom)+1;break}e-=u.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;fp&&ot){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(h)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==r||t==o?$e:cs,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ae:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?$e:ae}r=o}this.dirty=$e}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?$e:cs;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==ie&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},rr=class extends He{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},it=class n extends He{constructor(e,t,r,i,s){super(e,[],r,i),this.mark=t,this.spec=s}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=pe.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ae||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ae&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ie){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=lr(s,0,e,r));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),f=c&&c.dom,d=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:d}=pe.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let u=f;return f=Hs(f,r,t),c?a=new ir(e,t,r,i,f,d||null,u,c,s,o+1):t.isText?new Xt(e,t,r,i,f,u,s):new n(e,t,r,i,f,d||null,u,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>b.empty)}return e}matchesNode(e,t,r){return this.dirty==ie&&e.eq(this.node)&&Qt(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new or(this,o&&o.node,e);Ta(this.node,this.innerDeco,(c,f,d)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!d&&a.syncToMarks(f==this.node.childCount?N.none:this.node.child(f).marks,r,e),a.placeWidget(c,e,i)},(c,f,d,u)=>{a.syncToMarks(c.marks,r,e);let h;a.findNodeMatch(c,f,d,u)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,f,d,h,e)||a.updateNextNode(c,f,d,e,u,i)||a.addNode(c,f,d,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==$e)&&(o&&this.protectLocalComposition(e,o),js(this.contentDOM,this.children,e),rt&&Na(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof M)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Da(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new rr(this,s,t,i);e.input.compositionNodes.push(o),this.children=lr(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==ae||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ie}updateOuterDeco(e){if(Qt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Ks(this.dom,this.nodeDOM,sr(this.outerDeco,this.node,t),sr(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function fs(n,e,t,r,i){Hs(r,e,n);let s=new Te(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Xt=class n extends Te{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==ae||this.dirty!=ie&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ie||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ie,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=ae)}get domAtom(){return!1}isText(e){return this.node.text==e}},Zt=class extends He{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ie&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},ir=class extends Te{constructor(e,t,r,i,s,o,l,a,c,f){super(e,t,r,i,s,o,l,c,f),this.spec=a}update(e,t,r,i){if(this.dirty==ae)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function js(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=it.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof it)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Ea(n,e){return n.type.side-e.type.side}function Ta(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let c=0;cs;)l.push(i[o++]);let p=s+u.nodeSize;if(u.isText){let g=p;o!g.inline):l.slice();r(u,m,e.forChild(s,u),h),s=p}}function Na(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Da(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function lr(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||f<=e?s.push(a):(ct&&s.push(a.slice(t-c,a.size,r)))}return s}function br(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,c;if(an(t)){for(a=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&S.isSelectable(d)&&i.parent&&!(d.isInline&&ia(t.focusNode,t.focusOffset,i.dom))){let u=i.posBefore;c=new S(o==u?l:r.resolve(u))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,u=o;for(let h=0;h{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!qs(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function va(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,V(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&Z&&Ee<=11&&(r.disabled=!0,r.disabled=!1)}function Us(n,e){if(e instanceof S){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ms(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ms(n)}function ms(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function kr(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||M.between(e,t,r)}function gs(n){return n.editable&&!n.hasFocus()?!1:_s(n)}function _s(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Ia(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Ke(e.node,e.offset,t.anchorNode,t.anchorOffset)}function ar(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&C.findFrom(s,e)}function Me(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ys(n,e,t){let r=n.state.selection;if(r instanceof M)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Me(n,new M(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=ar(n.state,e);return i&&i instanceof S?Me(n,i):!1}else if(!(ne&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?S.isSelectable(s)?Me(n,new S(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):vt?Me(n,new M(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof S&&r.node.isInline)return Me(n,new M(e>0?r.$to:r.$from));{let i=ar(n.state,e);return i?Me(n,i):!1}}}function en(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Ot(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function et(n,e){return e<0?Pa(n):Ra(n)}function Pa(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(se&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Ot(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Gs(t))break;{let l=t.previousSibling;for(;l&&Ot(l,-1);)i=t.parentNode,s=V(l),l=l.previousSibling;if(l)t=l,r=en(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?cr(n,t,r):i&&cr(n,i,s)}function Ra(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=en(t),s,o;for(;;)if(r{n.state==i&&xe(n)},50)}function bs(n,e){let t=n.state.doc.resolve(e);if(!(H||la)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ks(n,e,t){let r=n.state.selection;if(r instanceof M&&!r.empty||t.indexOf("s")>-1||ne&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=ar(n.state,e);if(o&&o instanceof S)return Me(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof U?C.near(o,e):C.findFrom(o,e);return l?Me(n,l):!1}return!1}function xs(n,e){if(!(n.state.selection instanceof M))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function Ss(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Fa(n){if(!_||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;Ss(n,r,"true"),setTimeout(()=>Ss(n,r,"false"),20)}return!1}function La(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function $a(n,e){let t=e.keyCode,r=La(e);if(t==8||ne&&t==72&&r=="c")return xs(n,-1)||et(n,-1);if(t==46&&!e.shiftKey||ne&&t==68&&r=="c")return xs(n,1)||et(n,1);if(t==13||t==27)return!0;if(t==37||ne&&t==66&&r=="c"){let i=t==37?bs(n,n.state.selection.from)=="ltr"?-1:1:-1;return ys(n,i,r)||et(n,i)}else if(t==39||ne&&t==70&&r=="c"){let i=t==39?bs(n,n.state.selection.from)=="ltr"?1:-1:1;return ys(n,i,r)||et(n,i)}else{if(t==38||ne&&t==80&&r=="c")return ks(n,-1,r)||et(n,-1);if(t==40||ne&&t==78&&r=="c")return Fa(n)||ks(n,1,r)||et(n,1);if(r==(ne?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ys(n,e){n.someProp("transformCopied",h=>{e=h(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let h=r.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let o=n.someProp("clipboardSerializer")||pe.fromSchema(n.state.schema),l=no(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c=a.firstChild,f,d=0;for(;c&&c.nodeType==1&&(f=to[c.nodeName.toLowerCase()]);){for(let h=f.length-1;h>=0;h--){let p=l.createElement(f[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let u=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,`
-
-`);return{dom:a,text:u,slice:e}}function Xs(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=e&&(r||s||!t);if(a){if(n.someProp("transformPastedText",u=>{e=u(e,s||r,n)}),s)return e?new k(b.from(n.state.schema.text(e.replace(/\r\n?/g,`
-`))),0,0):k.empty;let d=n.someProp("clipboardTextParser",u=>u(e,i,r,n));if(d)l=d;else{let u=i.marks(),{schema:h}=n.state,p=pe.fromSchema(h);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(h.text(m,u)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=ja(t),vt&&Ka(o);let c=o&&o.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let d=+f[3];d>0;d--){let u=o.firstChild;for(;u&&u.nodeType!=1;)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||he.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!Va.test(u.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Ha(ws(l,+f[1],+f[2]),f[4]);else if(l=k.maxOpen(Ja(l.content,i),!0),l.openStart||l.openEnd){let d=0,u=0;for(let h=l.content.firstChild;d{l=d(l,n)}),l}var Va=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Ja(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&Qs(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=eo(o[o.length-1],s.length));let f=Zs(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return b.from(o)}return n}function Zs(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,b.from(n));return n}function Qs(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(b.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ws(n,e,t){return et})),Yn.createHTML(n)):n}function ja(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=no().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&to[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>""+s+">").reverse().join("")),t.innerHTML=Wa(n),i)for(let s=0;s=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=b.from(a.create(r[l+1],i)),s++,o++}return new k(i,s,o)}var G={},Y={},qa={touchstart:!0,touchmove:!0},dr=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Ua(n){for(let e in G){let t=G[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Ga(n,r)&&!xr(n,r)&&(n.editable||!(r.type in Y))&&t(n,r)},qa[e]?{passive:!0}:void 0)}_&&n.dom.addEventListener("input",()=>null),ur(n)}function Oe(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function _a(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function ur(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>xr(n,r))})}function xr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Ga(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Ya(n,e){!xr(n,e)&&G[e.type]&&(n.editable||!(e.type in Y))&&G[e.type](n,e)}Y.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!io(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(ke&&H&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),rt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Le(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||$a(n,t)?t.preventDefault():Oe(n,"key")};Y.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Y.keypress=(n,e)=>{let t=e;if(io(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ne&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof M)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function cn(n){return{left:n.clientX,top:n.clientY}}function Xa(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Sr(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function nt(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Za(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&S.isSelectable(r)?(nt(n,new S(t),"pointer"),!0):!1}function Qa(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof S&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(S.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(nt(n,S.create(n.state.doc,i),"pointer"),!0):!1}function ec(n,e,t,r,i){return Sr(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?Qa(n,t):Za(n,t))}function tc(n,e,t,r){return Sr(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function nc(n,e,t,r){return Sr(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||rc(n,t,r)}function rc(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(nt(n,M.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)nt(n,M.create(r,l+1,l+1+o.content.size),"pointer");else if(S.isSelectable(o))nt(n,S.create(r,l),"pointer");else continue;return!0}}function wr(n){return tn(n)}var ro=ne?"metaKey":"ctrlKey";G.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=wr(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&Xa(t,n.input.lastClick)&&!t[ro]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(cn(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new hr(n,o,t,!!r)):(s=="doubleClick"?tc:nc)(n,o.pos,o.inside,t)?t.preventDefault():Oe(n,"pointer"))};var hr=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[ro],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let f=e.state.doc.resolve(t.pos);s=f.parent,o=f.depth?f.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:c}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof S&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&se&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Oe(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>xe(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(cn(e))),this.updateAllowDefault(e),this.allowDefault||!t?Oe(this.view,"pointer"):ec(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||_&&this.mightDrag&&!this.mightDrag.node.isAtom||H&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(nt(this.view,C.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Oe(this.view,"pointer")}move(e){this.updateAllowDefault(e),Oe(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};G.touchstart=n=>{n.input.lastTouch=Date.now(),wr(n),Oe(n,"pointer")};G.touchmove=n=>{n.input.lastTouch=Date.now(),Oe(n,"pointer")};G.contextmenu=n=>wr(n);function io(n,e){return n.composing?!0:_&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var ic=ke?5e3:-1;Y.compositionstart=Y.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof M&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),tn(n,!0),n.markCursor=null;else if(tn(n,!e.selection.empty),se&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}so(n,ic)};Y.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,so(n,20))};function so(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>tn(n),e))}function oo(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=oc());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function sc(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=na(e.focusNode,e.focusOffset),r=ra(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function oc(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function tn(n,e=!1){if(!(ke&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),oo(n),e||n.docView&&n.docView.dirty){let t=br(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function lc(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Tt=Z&&Ee<15||rt&&aa<604;G.copy=Y.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Tt?null:t.clipboardData,o=r.content(),{dom:l,text:a}=Ys(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):lc(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ac(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function cc(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Nt(n,r.value,null,i,e):Nt(n,r.textContent,r.innerHTML,i,e)},50)}function Nt(n,e,t,r,i){let s=Xs(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,s||k.empty)))return!0;if(!s)return!1;let o=ac(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function lo(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Y.paste=(n,e)=>{let t=e;if(n.composing&&!ke)return;let r=Tt?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Nt(n,lo(r),r.getData("text/html"),i,t)?t.preventDefault():cc(n,t)};var nn=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},ao=ne?"altKey":"ctrlKey";G.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(cn(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(r&&r.mightDrag)o=S.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=S.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:a,text:c,slice:f}=Ys(n,l);(!t.dataTransfer.files.length||!H||zs>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Tt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Tt||t.dataTransfer.setData("text/plain",c),n.dragging=new nn(f,!t[ao],o)};G.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Y.dragover=Y.dragenter=(n,e)=>e.preventDefault();Y.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(cn(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Xs(n,lo(t.dataTransfer),Tt?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[ao]);if(n.someProp("handleDrop",p=>p(n,t,o||k.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?Ht(n.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=n.state.tr;if(l){let{node:p}=r;p?p.replace(c):c.deleteSelection()}let f=c.mapping.map(a),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,u=c.doc;if(d?c.replaceRangeWith(f,f,o.content.firstChild):c.replaceRange(f,f,o),c.doc.eq(u))return;let h=c.doc.resolve(f);if(d&&S.isSelectable(o.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new S(h));else{let p=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,y,w)=>p=w),c.setSelection(kr(n,h,c.doc.resolve(p)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};G.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&xe(n)},20))};G.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};G.beforeinput=(n,e)=>{if(H&&ke&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,Le(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Y)G[n]=Y[n];function Dt(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var rn=class n{constructor(e,t){this.toDOM=e,this.spec=t||We,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ce(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Dt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Je=class n{constructor(e,t){this.attrs=e,this.spec=t||We}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ce(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==K||e.maps.length==0?this:this.mapInner(e,t,0,0,r||We)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let c=a+r,f;if(f=fo(t,l,c)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&a.type instanceof Je){let c=Math.max(s,a.from)-s,f=Math.min(o,a.to)-s;ci.map(e,t,We));return n.from(r)}forChild(e,t){if(t.isLeaf)return Q.empty;let r=[];for(let i=0;it instanceof Q)?e:e.reduce((t,r)=>t.concat(r instanceof Q?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(h-u);for(let y=0;yw+f-d)continue;let O=l[y]+f-d;h>=O?l[y+1]=u<=O?-2:-1:u>=f&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let u=t.map(n[c+1]+s,-1),h=u-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==h){let y=l[c+2].mapInner(t,g,f+1,n[c]+s+1,o);y!=K?(l[c]=d,l[c+1]=h,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=dc(l,n,e,t,i,s,o),f=on(c,r,0,o);e=f.local;for(let d=0;dt&&o.to{let c=fo(n,l,a+t);if(c){s=!0;let f=on(c,l,t+a+1,r);f!=K&&i.push(a,a+l.nodeSize,f)}});let o=co(s?uo(n):n,-t).sort(je);for(let l=0;l0;)e++;n.splice(e,0,t)}function Xn(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=K&&e.push(r)}),n.cursorWrapper&&e.push(Q.create(n.state.doc,[n.cursorWrapper.deco])),sn.from(e)}var uc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},hc=Z&&Ee<=11,mr=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},gr=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new mr,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),hc&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,uc)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(gs(this.view)){if(this.suppressingSelectionUpdates)return xe(this.view);if(Z&&Ee<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ke(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=Et(s))t.add(s);for(let s=e.anchorNode;s;s=Et(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&gs(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let f=0;fd.nodeName=="BR");if(f.length==2){let[d,u]=f;d.parentNode&&d.parentNode.parentNode==u.parentNode?u.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let u of f){let h=u.parentNode;h&&h.nodeName=="LI"&&(!d||gc(e,d)!=h)&&u.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),pc(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||xe(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;fi;g--){let y=r.childNodes[g-1],w=y.pmViewDesc;if(y.nodeName=="BR"&&!w){s=g;break}if(!w||w.size)break}let d=n.state.doc,u=n.someProp("domParser")||he.fromSchema(n.state.schema),h=d.resolve(o),p=null,m=u.parse(r,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:bc,context:h});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function bc(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(_&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||_&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var kc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function xc(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let E=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,we=br(n,E);if(we&&!n.state.selection.eq(we)){if(H&&ke&&n.input.lastKeyCode===13&&Date.now()-100fl(n,Le(13,"Enter"))))return;let Rt=n.state.tr.setSelection(we);E=="pointer"?Rt.setMeta("pointer",!0):E=="key"&&Rt.scrollIntoView(),s&&Rt.setMeta("composition",s),n.dispatch(Rt)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=yc(n,e,t),f=n.state.doc,d=f.slice(c.from,c.to),u,h;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||ke)&&i.some(E=>E.nodeType==1&&!kc.test(E.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",E=>E(n,Le(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&a instanceof M&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let E=Ns(n,n.state.doc,c.sel);if(E&&!E.eq(n.state.selection)){let we=n.state.tr.setSelection(E);s&&we.setMeta("composition",s),n.dispatch(we)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),Z&&Ee<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),y=f.resolve(p.start),w=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,O;if((rt&&n.input.lastIOSEnter>Date.now()-225&&(!w||i.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!w&&m.posE(n,Le(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&wc(f,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",E=>E(n,Le(8,"Backspace")))){ke&&H&&n.domObserver.suppressSelectionUpdates();return}H&&p.endB==p.start&&(n.input.lastChromeDelete=Date.now()),ke&&!w&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(E){return E(n,Le(13,"Enter"))})},20));let v=p.start,D=p.endA,A,X,q;if(w){if(m.pos==g.pos)Z&&Ee<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>xe(n),20)),A=n.state.tr.delete(v,D),X=f.resolve(p.start).marksAcross(f.resolve(p.endA));else if(p.endA==p.endB&&(q=Sc(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))A=n.state.tr,q.type=="add"?A.addMark(v,D,q.mark):A.removeMark(v,D,q.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let E=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",we=>we(n,v,D,E)))return;A=n.state.tr.insertText(E,v,D)}}if(A||(A=n.state.tr.replace(v,D,c.doc.slice(p.start-c.from,p.endB-c.from))),c.sel){let E=Ns(n,A.doc,c.sel);E&&!(H&&n.composing&&E.empty&&(p.start!=p.endB||n.input.lastChromeDeletee.content.size?null:kr(n,e.resolve(t.anchor),e.resolve(t.head))}function Sc(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,a;for(let f=0;ff.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;ft||Zn(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Cc(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));r-=o+a-s}if(o=o?s-r:0;s-=a,s&&s=l?s-r:0;s-=a,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ln=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new dr,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Rs),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Is(this),vs(this),this.nodeViews=Ps(this),this.docView=fs(this.state.doc,As(this),Xn(this),this.dom,this),this.domObserver=new gr(this,(r,i,s,o)=>xc(this,r,i,s,o)),this.domObserver.start(),Ua(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ur(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Rs),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(oo(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let h=Ps(this);Oc(h,this.nodeViews)&&(this.nodeViews=h,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ur(this),this.editable=Is(this),vs(this);let a=Xn(this),c=As(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,c,a);(d||!e.selection.eq(i.selection))&&(o=!0);let u=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&da(this);if(o){this.domObserver.stop();let h=d&&(Z||H)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Mc(i.selection,e.selection);if(d){let p=H?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=sc(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=fs(e.doc,c,a,this.dom,this)),p&&!this.trackWrites&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ia(this))?xe(this,h):(Us(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():u&&ua(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof S){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&rs(this,t.getBoundingClientRect(),e)}else rs(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new nn(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ba(this,e)}coordsAtPos(e,t=1){return Js(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Ca(this,t||this.state,e)}pasteHTML(e,t){return Nt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Nt(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(_a(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Xn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ea())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Ya(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?_&&this.root.nodeType===11&&sa(this.dom.ownerDocument)==this.dom&&mc(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function As(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ce.node(0,n.state.doc.content.size,e)]}function vs(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ce.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Is(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Mc(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Ps(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Oc(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Rs(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Se={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},dn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Ec=typeof navigator<"u"&&/Mac/.test(navigator.platform),Tc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(B=0;B<10;B++)Se[48+B]=Se[96+B]=String(B);var B;for(B=1;B<=24;B++)Se[B+111]="F"+B;var B;for(B=65;B<=90;B++)Se[B]=String.fromCharCode(B+32),dn[B]=String.fromCharCode(B);var B;for(fn in Se)dn.hasOwnProperty(fn)||(dn[fn]=Se[fn]);var fn;function ho(n){var e=Ec&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Tc&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?dn:Se)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var Nc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Dc(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=Se[r.keyCode])&&s!=i){let l=e[Mr(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var un=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function go(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Er=(n,e,t)=>{let r=go(n,t);if(!r)return!1;let i=Nr(r);if(!i){let o=r.blockRange(),l=o&&ge(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Oo(n,i,e,-1))return!0;if(r.parent.content.size==0&&(st(s,"end")||S.isSelectable(s)))for(let o=r.depth;;o--){let l=St(n.doc,r.before(o),r.after(o),k.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},yo=(n,e,t)=>{let r=go(n,t);if(!r)return!1;let i=Nr(r);return i?ko(n,i,e):!1},bo=(n,e,t)=>{let r=xo(n,t);if(!r)return!1;let i=vr(r);return i?ko(n,i,e):!1};function ko(n,e,t){let r=e.nodeBefore,i=r,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let f=i.lastChild;if(!f)return!1;i=f}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let f=l.firstChild;if(!f)return!1;l=f}let c=St(n.doc,s,a,k.empty);if(!c||c.from!=s||c instanceof j&&c.slice.size>=a-s)return!1;if(t){let f=n.tr.step(c);f.setSelection(M.create(f.doc,s)),t(f.scrollIntoView())}return!0}function st(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var Tr=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=Nr(r)}let o=s&&s.nodeBefore;return!o||!S.isSelectable(o)?!1:(e&&e(n.tr.setSelection(S.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Nr(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function xo(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=xo(n,t);if(!r)return!1;let i=vr(r);if(!i)return!1;let s=i.nodeAfter;if(Oo(n,i,e,1))return!0;if(r.parent.content.size==0&&(st(s,"start")||S.isSelectable(s))){let o=St(n.doc,r.before(),r.after(),k.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof S,i;if(r){if(t.node.isTextblock||!oe(n.doc,t.from))return!1;i=t.from}else if(i=Xe(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(S.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},wo=(n,e)=>{let t=n.selection,r;if(t instanceof S){if(t.node.isTextblock||!oe(n.doc,t.to))return!1;r=t.to}else if(r=Xe(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},Co=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&ge(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Ir=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
-`).scrollIntoView()),!0)};function Pr(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Pr(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,o.createAndFill());a.setSelection(C.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Br=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof U||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=Pr(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(te(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&ge(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Ic(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof S&&e.selection.node.isBlock)return!r.parentOffset||!te(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let h=r.depth;;h--)if(r.node(h).isBlock){a=r.end(h)==r.pos+(r.depth-h),c=r.start(h)==r.pos-(r.depth-h),l=Pr(r.node(h-1).contentMatchAt(r.indexAfter(h-1)));let m=n&&n(i.parent,a,r);s.unshift(m||(a&&l?{type:l}:null)),o=h;break}else{if(h==1)return!1;s.unshift(null)}let f=e.tr;(e.selection instanceof M||e.selection instanceof U)&&f.deleteSelection();let d=f.mapping.map(r.pos),u=te(f.doc,d,s.length,s);if(u||(s[0]=l?{type:l}:null,u=te(f.doc,d,s.length,s)),f.split(d,s.length,s),!a&&c&&r.node(o).type!=l){let h=f.mapping.map(r.before(o)),p=f.doc.resolve(h);l&&r.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&f.setNodeMarkup(f.mapping.map(r.before(o)),l)}return t&&t(f.scrollIntoView()),!0}}var Pc=Ic();var Mo=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(S.create(n.doc,i))),!0)},Rc=(n,e)=>(e&&e(n.tr.setSelection(new U(n.doc))),!0);function Bc(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||oe(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Oo(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Bc(n,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let h=e.pos+s.nodeSize,p=b.empty;for(let y=o.length-1;y>=0;y--)p=b.from(o[y].create(null,p));p=b.from(i.copy(p));let m=n.tr.step(new R(e.pos-1,h,e.pos,h,new k(p,1,0),o.length,!0)),g=m.doc.resolve(h+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&oe(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||r>0&&a?null:C.findFrom(e,1),d=f&&f.$from.blockRange(f.$to),u=d&&ge(d);if(u!=null&&u>=e.depth)return t&&t(n.tr.lift(d,u).scrollIntoView()),!0;if(c&&st(s,"start",!0)&&st(i,"end")){let h=i,p=[];for(;p.push(h),!h.isTextblock;)h=h.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(h.canReplace(h.childCount,h.childCount,m.content)){if(t){let y=b.empty;for(let O=p.length-1;O>=0;O--)y=b.from(p[O].copy(y));let w=n.tr.step(new R(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new k(y,p.length,0),0,!0));t(w.scrollIntoView())}return!0}}return!1}function Eo(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(M.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Fr=Eo(-1),Lr=Eo(1);function To(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&xt(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function $r(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let f=t.doc.resolve(c),d=f.index();i=f.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);s=new Re(a,a,e.depth),e.endIndex=0;f--)s=b.from(t[f].type.create(t[f].attrs,s));n.step(new R(e.start-(r?2:0),e.end,e.start,e.end,new k(s,0,0),t.length,!0));let o=0;for(let f=0;fo.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?$c(e,t,n,s):Vc(e,t,s):!0:!1}}function $c(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)h-=i.child(p).nodeSize,r.delete(h-1,h+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),f=s.index(-1);if(!c.canReplace(f+(l?0:1),f+1,o.content.append(a?b.empty:b.from(i))))return!1;let d=s.pos,u=d+o.nodeSize;return r.step(new R(d-(l?1:0),u+(a?1:0),d+1,u-1,new k((l?b.empty:b.from(i.copy(b.empty))).append(a?b.empty:b.from(i.copy(b.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function Ao(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,f=b.from(c?n.create():null),d=new k(b.from(n.create(null,b.from(l.type.create(null,f)))),c?3:1,0),u=s.start,h=s.end;t(e.tr.step(new R(u-(c?3:1),h,u,h,d,1,!0)).scrollIntoView())}return!0}}function Sn(n){let{state:e,transaction:t}=n,{selection:r}=t,{doc:i}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=t.selection,i=t.doc,s=t.storedMarks,t}}}var ot=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:r}=this,{view:i}=t,{tr:s}=r,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...f)=>{let d=a(...f)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,c=e||s.tr,f=()=>(!a&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),l.every(u=>u===!0)),d={...Object.fromEntries(Object.entries(r).map(([u,h])=>[u,(...m)=>{let g=this.buildProps(c,t),y=h(...m)(g);return l.push(y),d}])),run:f};return d}createCan(e){let{rawCommands:t,state:r}=this,i=!1,s=e||r.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(t).map(([a,c])=>[a,(...f)=>c(...f)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,t=!0){let{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l={tr:e,editor:i,view:o,state:Sn({state:s,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([a,c])=>[a,(...f)=>c(...f)(l)]))}};return l}},Kr=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let r=this.callbacks[e];return r&&r.forEach(i=>i.apply(this,t)),this}off(e,t){let r=this.callbacks[e];return r&&(t?this.callbacks[e]=r.filter(i=>i!==t):delete this.callbacks[e]),this}once(e,t){let r=(...i)=>{this.off(e,r),t.apply(this,i)};return this.on(e,r)}removeAllListeners(){this.callbacks={}}};function x(n,e,t){return n.config[e]===void 0&&n.parent?x(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?x(n.parent,e,t):null}):n.config[e]}function wn(n){let e=n.filter(i=>i.type==="extension"),t=n.filter(i=>i.type==="node"),r=n.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:r}}function Lo(n){let e=[],{nodeExtensions:t,markExtensions:r}=wn(n),i=[...t,...r],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return n.forEach(o=>{let l={name:o.name,options:o.options,storage:o.storage,extensions:i},a=x(o,"addGlobalAttributes",l);if(!a)return;a().forEach(f=>{f.types.forEach(d=>{Object.entries(f.attributes).forEach(([u,h])=>{e.push({type:d,name:u,attribute:{...s,...h}})})})})}),i.forEach(o=>{let l={name:o.name,options:o.options,storage:o.storage},a=x(o,"addAttributes",l);if(!a)return;let c=a();Object.entries(c).forEach(([f,d])=>{let u={...s,...d};typeof u?.default=="function"&&(u.default=u.default()),u?.isRequired&&u?.default===void 0&&delete u.default,e.push({type:o.name,name:f,attribute:u})})}),e}function F(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}function Xr(...n){return n.filter(e=>!!e).reduce((e,t)=>{let r={...e};return Object.entries(t).forEach(([i,s])=>{if(!r[i]){r[i]=s;return}if(i==="class"){let l=s?String(s).split(" "):[],a=r[i]?r[i].split(" "):[],c=l.filter(f=>!a.includes(f));r[i]=[...a,...c].join(" ")}else if(i==="style"){let l=s?s.split(";").map(f=>f.trim()).filter(Boolean):[],a=r[i]?r[i].split(";").map(f=>f.trim()).filter(Boolean):[],c=new Map;a.forEach(f=>{let[d,u]=f.split(":").map(h=>h.trim());c.set(d,u)}),l.forEach(f=>{let[d,u]=f.split(":").map(h=>h.trim());c.set(d,u)}),r[i]=Array.from(c.entries()).map(([f,d])=>`${f}: ${d}`).join("; ")}else r[i]=s}),r},{})}function Hr(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,r)=>Xr(t,r),{})}function $o(n){return typeof n=="function"}function T(n,e=void 0,...t){return $o(n)?e?n.bind(e)(...t):n(...t):n}function Jc(n={}){return Object.keys(n).length===0&&n.constructor===Object}function Wc(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function vo(n,e){return"style"in n?n:{...n,getAttrs:t=>{let r=n.getAttrs?n.getAttrs(t):n.attrs;if(r===!1)return!1;let i=e.reduce((s,o)=>{let l=o.attribute.parseHTML?o.attribute.parseHTML(t):Wc(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...r,...i}}}}function Io(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&Jc(t)?!1:t!=null))}function jc(n,e){var t;let r=Lo(n),{nodeExtensions:i,markExtensions:s}=wn(n),o=(t=i.find(c=>x(c,"topNode")))===null||t===void 0?void 0:t.name,l=Object.fromEntries(i.map(c=>{let f=r.filter(y=>y.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},u=n.reduce((y,w)=>{let O=x(w,"extendNodeSchema",d);return{...y,...O?O(c):{}}},{}),h=Io({...u,content:T(x(c,"content",d)),marks:T(x(c,"marks",d)),group:T(x(c,"group",d)),inline:T(x(c,"inline",d)),atom:T(x(c,"atom",d)),selectable:T(x(c,"selectable",d)),draggable:T(x(c,"draggable",d)),code:T(x(c,"code",d)),whitespace:T(x(c,"whitespace",d)),linebreakReplacement:T(x(c,"linebreakReplacement",d)),defining:T(x(c,"defining",d)),isolating:T(x(c,"isolating",d)),attrs:Object.fromEntries(f.map(y=>{var w;return[y.name,{default:(w=y?.attribute)===null||w===void 0?void 0:w.default}]}))}),p=T(x(c,"parseHTML",d));p&&(h.parseDOM=p.map(y=>vo(y,f)));let m=x(c,"renderHTML",d);m&&(h.toDOM=y=>m({node:y,HTMLAttributes:Hr(y,f)}));let g=x(c,"renderText",d);return g&&(h.toText=g),[c.name,h]})),a=Object.fromEntries(s.map(c=>{let f=r.filter(g=>g.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},u=n.reduce((g,y)=>{let w=x(y,"extendMarkSchema",d);return{...g,...w?w(c):{}}},{}),h=Io({...u,inclusive:T(x(c,"inclusive",d)),excludes:T(x(c,"excludes",d)),group:T(x(c,"group",d)),spanning:T(x(c,"spanning",d)),code:T(x(c,"code",d)),attrs:Object.fromEntries(f.map(g=>{var y;return[g.name,{default:(y=g?.attribute)===null||y===void 0?void 0:y.default}]}))}),p=T(x(c,"parseHTML",d));p&&(h.parseDOM=p.map(g=>vo(g,f)));let m=x(c,"renderHTML",d);return m&&(h.toDOM=g=>m({mark:g,HTMLAttributes:Hr(g,f)})),[c.name,h]}));return new ft({topNode:o,nodes:l,marks:a})}function Jr(n,e){return e.nodes[n]||e.marks[n]||null}function Po(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Zr(n,e){let t=pe.fromSchema(e).serializeFragment(n),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(t),i.innerHTML}var Kc=(n,e=500)=>{let t="",r=n.parentOffset;return n.parent.nodesBetween(Math.max(0,r-e),r,(i,s,o,l)=>{var a,c;let f=((c=(a=i.type.spec).toText)===null||c===void 0?void 0:c.call(a,{node:i,pos:s,parent:o,index:l}))||i.textContent||"%leaf%";t+=i.isAtom&&!i.isText?f:f.slice(0,Math.max(0,r-s))}),t};function Qr(n){return Object.prototype.toString.call(n)==="[object RegExp]"}var Hc=(n,e)=>{if(Qr(e))return e.exec(n);let t=e(n);if(!t)return null;let r=[t.text];return r.index=t.index,r.input=n,r.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(t.replaceWith)),r};function hn(n){var e;let{editor:t,from:r,to:i,text:s,rules:o,plugin:l}=n,{view:a}=t;if(a.composing)return!1;let c=a.state.doc.resolve(r);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(u=>u.type.spec.code))return!1;let f=!1,d=Kc(c)+s;return o.forEach(u=>{if(f)return;let h=Hc(d,u.find);if(!h)return;let p=a.state.tr,m=Sn({state:a.state,transaction:p}),g={from:r-(h[0].length-s.length),to:i},{commands:y,chain:w,can:O}=new ot({editor:t,state:m});u.handler({state:m,range:g,match:h,commands:y,chain:w,can:O})===null||!p.steps.length||(p.setMeta(l,{transform:p,from:r,to:i,text:s}),a.dispatch(p),f=!0)}),f}function qc(n){let{editor:e,rules:t}=n,r=new I({state:{init(){return null},apply(i,s,o){let l=i.getMeta(r);if(l)return l;let a=i.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:f}=a;typeof f=="string"?f=f:f=Zr(b.from(f),o.schema);let{from:d}=a,u=d+f.length;hn({editor:e,from:d,to:u,text:f,rules:t,plugin:r})}),i.selectionSet||i.docChanged?null:s}},props:{handleTextInput(i,s,o,l){return hn({editor:e,from:s,to:o,text:l,rules:t,plugin:r})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{let{$cursor:s}=i.state.selection;s&&hn({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:r})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;let{$cursor:o}=i.state.selection;return o?hn({editor:e,from:o.pos,to:o.pos,text:`
-`,rules:t,plugin:r}):!1}},isInputRules:!0});return r}function Uc(n){return Object.prototype.toString.call(n).slice(8,-1)}function pn(n){return Uc(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Cn(n,e){let t={...n};return pn(n)&&pn(e)&&Object.keys(e).forEach(r=>{pn(e[r])&&pn(n[r])?t[r]=Cn(n[r],e[r]):t[r]=e[r]}),t}var qr=class n{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=T(x(this,"addOptions",{name:this.name}))),this.storage=T(x(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new n(e)}configure(e={}){let t=this.extend({...this.config,addOptions:()=>Cn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){let t=new n(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=T(x(t,"addOptions",{name:t.name})),t.storage=T(x(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){let{tr:r}=e.state,i=e.state.selection.$from;if(i.pos===i.end()){let o=i.marks();if(!!!o.find(c=>c?.type.name===t.name))return!1;let a=o.find(c=>c?.type.name===t.name);return a&&r.removeStoredMark(a),r.insertText(" ",i.pos),e.view.dispatch(r),!0}return!1}};function _c(n){return typeof n=="number"}var Gc=(n,e,t)=>{if(Qr(e))return[...n.matchAll(e)];let r=e(n,t);return r?r.map(i=>{let s=[i.text];return s.index=i.index,s.input=n,s.data=i.data,i.replaceWith&&(i.text.includes(i.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(i.replaceWith)),s}):[]};function Yc(n){let{editor:e,state:t,from:r,to:i,rule:s,pasteEvent:o,dropEvent:l}=n,{commands:a,chain:c,can:f}=new ot({editor:e,state:t}),d=[];return t.doc.nodesBetween(r,i,(h,p)=>{if(!h.isTextblock||h.type.spec.code)return;let m=Math.max(r,p),g=Math.min(i,p+h.content.size),y=h.textBetween(m-p,g-p,void 0,"\uFFFC");Gc(y,s.find,o).forEach(O=>{if(O.index===void 0)return;let v=m+O.index+1,D=v+O[0].length,A={from:t.tr.mapping.map(v),to:t.tr.mapping.map(D)},X=s.handler({state:t,range:A,match:O,commands:a,chain:c,can:f,pasteEvent:o,dropEvent:l});d.push(X)})}),d.every(h=>h!==null)}var mn=null,Xc=n=>{var e;let t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)===null||e===void 0||e.setData("text/html",n),t};function Zc(n){let{editor:e,rules:t}=n,r=null,i=!1,s=!1,o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}let a=({state:f,from:d,to:u,rule:h,pasteEvt:p})=>{let m=f.tr,g=Sn({state:f,transaction:m});if(!(!Yc({editor:e,state:g,from:Math.max(d-1,0),to:u.b-1,rule:h,pasteEvent:p,dropEvent:l})||!m.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,m}};return t.map(f=>new I({view(d){let u=p=>{var m;r=!((m=d.dom.parentElement)===null||m===void 0)&&m.contains(p.target)?d.dom.parentElement:null,r&&(mn=e)},h=()=>{mn&&(mn=null)};return window.addEventListener("dragstart",u),window.addEventListener("dragend",h),{destroy(){window.removeEventListener("dragstart",u),window.removeEventListener("dragend",h)}}},props:{handleDOMEvents:{drop:(d,u)=>{if(s=r===d.dom.parentElement,l=u,!s){let h=mn;h&&setTimeout(()=>{let p=h.state.selection;p&&h.commands.deleteRange({from:p.from,to:p.to})},10)}return!1},paste:(d,u)=>{var h;let p=(h=u.clipboardData)===null||h===void 0?void 0:h.getData("text/html");return o=u,i=!!p?.includes("data-pm-slice"),!1}}},appendTransaction:(d,u,h)=>{let p=d[0],m=p.getMeta("uiEvent")==="paste"&&!i,g=p.getMeta("uiEvent")==="drop"&&!s,y=p.getMeta("applyPasteRules"),w=!!y;if(!m&&!g&&!w)return;if(w){let{text:D}=y;typeof D=="string"?D=D:D=Zr(b.from(D),h.schema);let{from:A}=y,X=A+D.length,q=Xc(D);return a({rule:f,state:h,from:A,to:{b:X},pasteEvt:q})}let O=u.doc.content.findDiffStart(h.doc.content),v=u.doc.content.findDiffEnd(h.doc.content);if(!(!_c(O)||!v||O===v.b))return a({rule:f,state:h,from:O,to:v,pasteEvt:o})}}))}function Qc(n){let e=n.filter((t,r)=>n.indexOf(t)!==r);return Array.from(new Set(e))}var Ur=class n{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=n.resolve(e),this.schema=jc(this.extensions,t),this.setupExtensions()}static resolve(e){let t=n.sort(n.flatten(e)),r=Qc(t.map(i=>i.name));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),t}static flatten(e){return e.map(t=>{let r={name:t.name,options:t.options,storage:t.storage},i=x(t,"addExtensions",r);return i?[t,...this.flatten(i())]:t}).flat(10)}static sort(e){return e.sort((r,i)=>{let s=x(r,"priority")||100,o=x(i,"priority")||100;return s>o?-1:s{let r={name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:Jr(t.name,this.schema)},i=x(t,"addCommands",r);return i?{...e,...i()}:e},{})}get plugins(){let{editor:e}=this,t=n.sort([...this.extensions].reverse()),r=[],i=[],s=t.map(o=>{let l={name:o.name,options:o.options,storage:o.storage,editor:e,type:Jr(o.name,this.schema)},a=[],c=x(o,"addKeyboardShortcuts",l),f={};if(o.type==="mark"&&x(o,"exitable",l)&&(f.ArrowRight=()=>qr.handleExit({editor:e,mark:o})),c){let m=Object.fromEntries(Object.entries(c()).map(([g,y])=>[g,()=>y({editor:e})]));f={...f,...m}}let d=po(f);a.push(d);let u=x(o,"addInputRules",l);Po(o,e.options.enableInputRules)&&u&&r.push(...u());let h=x(o,"addPasteRules",l);Po(o,e.options.enablePasteRules)&&h&&i.push(...h());let p=x(o,"addProseMirrorPlugins",l);if(p){let m=p();a.push(...m)}return a}).flat();return[qc({editor:e,rules:r}),...Zc({editor:e,rules:i}),...s]}get attributes(){return Lo(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=wn(this.extensions);return Object.fromEntries(t.filter(r=>!!x(r,"addNodeView")).map(r=>{let i=this.attributes.filter(a=>a.type===r.name),s={name:r.name,options:r.options,storage:r.storage,editor:e,type:F(r.name,this.schema)},o=x(r,"addNodeView",s);if(!o)return[];let l=(a,c,f,d,u)=>{let h=Hr(a,i);return o()({node:a,view:c,getPos:f,decorations:d,innerDecorations:u,editor:e,extension:r,HTMLAttributes:h})};return[r.name,l]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;let r={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:Jr(e.name,this.schema)};e.type==="mark"&&(!((t=T(x(e,"keepOnSplit",r)))!==null&&t!==void 0)||t)&&this.splittableMarks.push(e.name);let i=x(e,"onBeforeCreate",r),s=x(e,"onCreate",r),o=x(e,"onUpdate",r),l=x(e,"onSelectionUpdate",r),a=x(e,"onTransaction",r),c=x(e,"onFocus",r),f=x(e,"onBlur",r),d=x(e,"onDestroy",r);i&&this.editor.on("beforeCreate",i),s&&this.editor.on("create",s),o&&this.editor.on("update",o),l&&this.editor.on("selectionUpdate",l),a&&this.editor.on("transaction",a),c&&this.editor.on("focus",c),f&&this.editor.on("blur",f),d&&this.editor.on("destroy",d)})}},P=class n{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=T(x(this,"addOptions",{name:this.name}))),this.storage=T(x(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new n(e)}configure(e={}){let t=this.extend({...this.config,addOptions:()=>Cn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){let t=new n({...this.config,...e});return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=T(x(t,"addOptions",{name:t.name})),t.storage=T(x(t,"addStorage",{name:t.name,options:t.options})),t}};function Vo(n,e,t){let{from:r,to:i}=e,{blockSeparator:s=`
-
-`,textSerializers:o={}}=t||{},l="";return n.nodesBetween(r,i,(a,c,f,d)=>{var u;a.isBlock&&c>r&&(l+=s);let h=o?.[a.type.name];if(h)return f&&(l+=h({node:a,pos:c,parent:f,index:d,range:e})),!1;a.isText&&(l+=(u=a?.text)===null||u===void 0?void 0:u.slice(Math.max(r,c)-c,i-c))}),l}function Jo(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}var ef=P.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new I({key:new $("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:n}=this,{state:e,schema:t}=n,{doc:r,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(f=>f.$from.pos)),l=Math.max(...s.map(f=>f.$to.pos)),a=Jo(t);return Vo(r,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),tf=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window?.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),nf=(n=!1)=>({commands:e})=>e.setContent("",n),rf=()=>({state:n,tr:e,dispatch:t})=>{let{selection:r}=e,{ranges:i}=r;return t&&i.forEach(({$from:s,$to:o})=>{n.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;let{doc:c,mapping:f}=e,d=c.resolve(f.map(a)),u=c.resolve(f.map(a+l.nodeSize)),h=d.blockRange(u);if(!h)return;let p=ge(h);if(l.type.isTextblock){let{defaultType:m}=d.parent.contentMatchAt(d.index());e.setNodeMarkup(h.start,m)}(p||p===0)&&e.lift(h,p)})}),!0},sf=n=>e=>n(e),of=()=>({state:n,dispatch:e})=>Br(n,e),lf=(n,e)=>({editor:t,tr:r})=>{let{state:i}=t,s=i.doc.slice(n.from,n.to);r.deleteRange(n.from,n.to);let o=r.mapping.map(e);return r.insert(o,s.content),r.setSelection(new M(r.doc.resolve(o-1))),!0},af=()=>({tr:n,dispatch:e})=>{let{selection:t}=n,r=t.$anchor.node();if(r.content.size>0)return!1;let i=n.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===r.type){if(e){let l=i.before(s),a=i.after(s);n.delete(l,a).scrollIntoView()}return!0}return!1},cf=n=>({tr:e,state:t,dispatch:r})=>{let i=F(n,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(r){let a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},ff=n=>({tr:e,dispatch:t})=>{let{from:r,to:i}=n;return t&&e.delete(r,i),!0},df=()=>({state:n,dispatch:e})=>un(n,e),uf=()=>({commands:n})=>n.keyboardShortcut("Enter"),hf=()=>({state:n,dispatch:e})=>Rr(n,e);function bn(n,e,t={strict:!0}){let r=Object.keys(e);return r.length?r.every(i=>t.strict?e[i]===n[i]:Qr(e[i])?e[i].test(n[i]):e[i]===n[i]):!0}function Wo(n,e,t={}){return n.find(r=>r.type===e&&bn(Object.fromEntries(Object.keys(t).map(i=>[i,r.attrs[i]])),t))}function Ro(n,e,t={}){return!!Wo(n,e,t)}function jo(n,e,t){var r;if(!n||!e)return;let i=n.parent.childAfter(n.parentOffset);if((!i.node||!i.node.marks.some(f=>f.type===e))&&(i=n.parent.childBefore(n.parentOffset)),!i.node||!i.node.marks.some(f=>f.type===e)||(t=t||((r=i.node.marks[0])===null||r===void 0?void 0:r.attrs),!Wo([...i.node.marks],e,t)))return;let o=i.index,l=n.start()+i.offset,a=o+1,c=l+i.node.nodeSize;for(;o>0&&Ro([...n.parent.child(o-1).marks],e,t);)o-=1,l-=n.parent.child(o).nodeSize;for(;a({tr:t,state:r,dispatch:i})=>{let s=Ae(n,r.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:f}=l;if(i){let d=jo(a,s,e);if(d&&d.from<=c&&d.to>=f){let u=M.create(o,d.from,d.to);t.setSelection(u)}}return!0},mf=n=>e=>{let t=typeof n=="function"?n(e):n;for(let r=0;r({editor:t,view:r,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};let o=()=>{(ei()||gf())&&r.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(r.focus(),e?.scrollIntoView&&t.commands.scrollIntoView())})};if(r.hasFocus()&&n===null||n===!1)return!0;if(s&&n===null&&!Ko(t.state.selection))return o(),!0;let l=Ho(i.doc,n)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},bf=(n,e)=>t=>n.every((r,i)=>e(r,{...t,index:i})),kf=(n,e)=>({tr:t,commands:r})=>r.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),qo=n=>{let e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){let r=e[t];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?n.removeChild(r):r.nodeType===1&&qo(r)}return n};function gn(n){let e=`${n}`,t=new window.DOMParser().parseFromString(e,"text/html").body;return qo(t)}function kn(n,e,t){if(n instanceof ee||n instanceof b)return n;t={slice:!0,parseOptions:{},...t};let r=typeof n=="object"&&n!==null,i=typeof n=="string";if(r)try{if(Array.isArray(n)&&n.length>0)return b.fromArray(n.map(l=>e.nodeFromJSON(l)));let o=e.nodeFromJSON(n);return t.errorOnInvalidContent&&o.check(),o}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",s),kn("",e,t)}if(i){if(t.errorOnInvalidContent){let o=!1,l="",a=new ft({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(o=!0,l=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?he.fromSchema(a).parseSlice(gn(n),t.parseOptions):he.fromSchema(a).parse(gn(n),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}let s=he.fromSchema(e);return t.slice?s.parseSlice(gn(n),t.parseOptions).content:s.parse(gn(n),t.parseOptions)}return kn("",e,t)}function xf(n,e,t){let r=n.steps.length-1;if(r{o===0&&(o=f)}),n.setSelection(C.near(n.doc.resolve(o),t))}var Sf=n=>!("type"in n),wf=(n,e,t)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;try{l=kn(e,s.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions},errorOnInvalidContent:(o=t.errorOnInvalidContent)!==null&&o!==void 0?o:s.options.enableContentCheck})}catch(p){return s.emit("contentError",{editor:s,error:p,disableCollaboration:()=>{s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}}),!1}let{from:a,to:c}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},f=!0,d=!0;if((Sf(l)?l:[l]).forEach(p=>{p.check(),f=f?p.isText&&p.marks.length===0:!1,d=d?p.isBlock:!1}),a===c&&d){let{parent:p}=r.doc.resolve(a);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(a-=1,c+=1)}let h;if(f){if(Array.isArray(e))h=e.map(p=>p.text||"").join("");else if(e instanceof b){let p="";e.forEach(m=>{m.text&&(p+=m.text)}),h=p}else typeof e=="object"&&e&&e.text?h=e.text:h=e;r.insertText(h,a,c)}else h=l,r.replaceWith(a,c,h);t.updateSelection&&xf(r,r.steps.length-1,-1),t.applyInputRules&&r.setMeta("applyInputRules",{from:a,text:h}),t.applyPasteRules&&r.setMeta("applyPasteRules",{from:a,text:h})}return!0},Cf=()=>({state:n,dispatch:e})=>So(n,e),Mf=()=>({state:n,dispatch:e})=>wo(n,e),Of=()=>({state:n,dispatch:e})=>Er(n,e),Ef=()=>({state:n,dispatch:e})=>Dr(n,e),Tf=()=>({state:n,dispatch:e,tr:t})=>{try{let r=Xe(n.doc,n.selection.$from.pos,-1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},Nf=()=>({state:n,dispatch:e,tr:t})=>{try{let r=Xe(n.doc,n.selection.$from.pos,1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},Df=()=>({state:n,dispatch:e})=>yo(n,e),Af=()=>({state:n,dispatch:e})=>bo(n,e);function Uo(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function vf(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t==="Space"&&(t=" ");let r,i,s,o;for(let l=0;l({editor:e,view:t,tr:r,dispatch:i})=>{let s=vf(n).split(/-(?!$)/),o=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,l))});return a?.steps.forEach(c=>{let f=c.map(r.mapping);f&&i&&r.maybeStep(f)}),!0};function It(n,e,t={}){let{from:r,to:i,empty:s}=n.selection,o=e?F(e,n.schema):null,l=[];n.doc.nodesBetween(r,i,(d,u)=>{if(d.isText)return;let h=Math.max(r,u),p=Math.min(i,u+d.nodeSize);l.push({node:d,from:h,to:p})});let a=i-r,c=l.filter(d=>o?o.name===d.node.type.name:!0).filter(d=>bn(d.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((d,u)=>d+u.to-u.from,0)>=a}var Pf=(n,e={})=>({state:t,dispatch:r})=>{let i=F(n,t.schema);return It(t,i,e)?Co(t,r):!1},Rf=()=>({state:n,dispatch:e})=>zr(n,e),Bf=n=>({state:e,dispatch:t})=>{let r=F(n,e.schema);return Do(r)(e,t)},zf=()=>({state:n,dispatch:e})=>Ir(n,e);function Mn(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function Bo(n,e){let t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((r,i)=>(t.includes(i)||(r[i]=n[i]),r),{})}var Ff=(n,e)=>({tr:t,state:r,dispatch:i})=>{let s=null,o=null,l=Mn(typeof n=="string"?n:n.name,r.schema);return l?(l==="node"&&(s=F(n,r.schema)),l==="mark"&&(o=Ae(n,r.schema)),i&&t.selection.ranges.forEach(a=>{r.doc.nodesBetween(a.$from.pos,a.$to.pos,(c,f)=>{s&&s===c.type&&t.setNodeMarkup(f,void 0,Bo(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(d=>{o===d.type&&t.addMark(f,f+c.nodeSize,o.create(Bo(d.attrs,e)))})})}),!0):!1},Lf=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),$f=()=>({tr:n,dispatch:e})=>{if(e){let t=new U(n.doc);n.setSelection(t)}return!0},Vf=()=>({state:n,dispatch:e})=>Tr(n,e),Jf=()=>({state:n,dispatch:e})=>Ar(n,e),Wf=()=>({state:n,dispatch:e})=>Mo(n,e),jf=()=>({state:n,dispatch:e})=>Lr(n,e),Kf=()=>({state:n,dispatch:e})=>Fr(n,e);function _r(n,e,t={},r={}){return kn(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:r.errorOnInvalidContent})}var Hf=(n,e=!1,t={},r={})=>({editor:i,tr:s,dispatch:o,commands:l})=>{var a,c;let{doc:f}=s;if(t.preserveWhitespace!=="full"){let d=_r(n,i.schema,t,{errorOnInvalidContent:(a=r.errorOnInvalidContent)!==null&&a!==void 0?a:i.options.enableContentCheck});return o&&s.replaceWith(0,f.content.size,d).setMeta("preventUpdate",!e),!0}return o&&s.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:f.content.size},n,{parseOptions:t,errorOnInvalidContent:(c=r.errorOnInvalidContent)!==null&&c!==void 0?c:i.options.enableContentCheck})};function _o(n,e){let t=Ae(e,n.schema),{from:r,to:i,empty:s}=n.selection,o=[];s?(n.storedMarks&&o.push(...n.storedMarks),o.push(...n.selection.$head.marks())):n.doc.nodesBetween(r,i,a=>{o.push(...a.marks)});let l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function qf(n){for(let e=0;e0;t-=1){let r=n.node(t);if(e(r))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:r}}}function ti(n){return e=>Uf(e.$from,n)}function _f(n,e){let t={from:0,to:n.content.size};return Vo(n,t,e)}function Gf(n,e){let t=F(e,n.schema),{from:r,to:i}=n.selection,s=[];n.doc.nodesBetween(r,i,l=>{s.push(l)});let o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function Yf(n,e){let t=Mn(typeof e=="string"?e:e.name,n.schema);return t==="node"?Gf(n,e):t==="mark"?_o(n,e):{}}function yn(n,e,t){return Object.fromEntries(Object.entries(t).filter(([r])=>{let i=n.find(s=>s.type===e&&s.name===r);return i?i.attribute.keepOnSplit:!1}))}function Gr(n,e,t={}){let{empty:r,ranges:i}=n.selection,s=e?Ae(e,n.schema):null;if(r)return!!(n.storedMarks||n.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>bn(d.attrs,t,{strict:!1}));let o=0,l=[];if(i.forEach(({$from:d,$to:u})=>{let h=d.pos,p=u.pos;n.doc.nodesBetween(h,p,(m,g)=>{if(!m.isText&&!m.marks.length)return;let y=Math.max(h,g),w=Math.min(p,g+m.nodeSize),O=w-y;o+=O,l.push(...m.marks.map(v=>({mark:v,from:y,to:w})))})}),o===0)return!1;let a=l.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>bn(d.mark.attrs,t,{strict:!1})).reduce((d,u)=>d+u.to-u.from,0),c=l.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,u)=>d+u.to-u.from,0);return(a>0?a+c:a)>=o}function Xf(n,e,t={}){if(!e)return It(n,null,t)||Gr(n,null,t);let r=Mn(e,n.schema);return r==="node"?It(n,e,t):r==="mark"?Gr(n,e,t):!1}function zo(n,e){let{nodeExtensions:t}=wn(e),r=t.find(o=>o.name===n);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=T(x(r,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function Pt(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var r;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((r=n.text)!==null&&r!==void 0?r:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let i=!0;return n.content.forEach(s=>{i!==!1&&(Pt(s,{ignoreWhitespace:t,checkChildren:e})||(i=!1))}),i}return!1}function Zf(n,e,t){var r;let{selection:i}=e,s=null;if(Ko(i)&&(s=i.$cursor),s){let l=(r=n.storedMarks)!==null&&r!==void 0?r:s.marks();return!!t.isInSet(l)||!l.some(a=>a.type.excludes(t))}let{ranges:o}=i;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,a.pos,(f,d,u)=>{if(c)return!1;if(f.isInline){let h=!u||u.type.allowsMarkType(t),p=!!t.isInSet(f.marks)||!f.marks.some(m=>m.type.excludes(t));c=h&&p}return!c}),c})}var Qf=(n,e={})=>({tr:t,state:r,dispatch:i})=>{let{selection:s}=t,{empty:o,ranges:l}=s,a=Ae(n,r.schema);if(i)if(o){let c=_o(r,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{let f=c.$from.pos,d=c.$to.pos;r.doc.nodesBetween(f,d,(u,h)=>{let p=Math.max(h,f),m=Math.min(h+u.nodeSize,d);u.marks.find(y=>y.type===a)?u.marks.forEach(y=>{a===y.type&&t.addMark(p,m,a.create({...y.attrs,...e}))}):t.addMark(p,m,a.create(e))})});return Zf(r,t,a)},ed=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),td=(n,e={})=>({state:t,dispatch:r,chain:i})=>{let s=F(n,t.schema),o;return t.selection.$anchor.sameParent(t.selection.$head)&&(o=t.selection.$anchor.parent.attrs),s.isTextblock?i().command(({commands:l})=>$r(s,{...o,...e})(t)?!0:l.clearNodes()).command(({state:l})=>$r(s,{...o,...e})(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},nd=n=>({tr:e,dispatch:t})=>{if(t){let{doc:r}=e,i=qe(n,0,r.content.size),s=S.create(r,i);e.setSelection(s)}return!0},rd=n=>({tr:e,dispatch:t})=>{if(t){let{doc:r}=e,{from:i,to:s}=typeof n=="number"?{from:n,to:n}:n,o=M.atStart(r).from,l=M.atEnd(r).to,a=qe(i,o,l),c=qe(s,o,l),f=M.create(r,a,c);e.setSelection(f)}return!0},id=n=>({state:e,dispatch:t})=>{let r=F(n,e.schema);return Ao(r)(e,t)};function Fo(n,e){let t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){let r=t.filter(i=>e?.includes(i.type.name));n.tr.ensureMarks(r)}}var sd=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:r,editor:i})=>{let{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=i.extensionManager.attributes,f=yn(c,l.node().type.name,l.node().attrs);if(s instanceof S&&s.node.isBlock)return!l.parentOffset||!te(o,l.pos)?!1:(r&&(n&&Fo(t,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;let d=a.parentOffset===a.parent.content.size,u=l.depth===0?void 0:qf(l.node(-1).contentMatchAt(l.indexAfter(-1))),h=d&&u?[{type:u,attrs:f}]:void 0,p=te(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!p&&te(e.doc,e.mapping.map(l.pos),1,u?[{type:u}]:void 0)&&(p=!0,h=u?[{type:u,attrs:f}]:void 0),r){if(p&&(s instanceof M&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),u&&!d&&!l.parentOffset&&l.parent.type!==u)){let m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,u)&&e.setNodeMarkup(e.mapping.map(l.before()),u)}n&&Fo(t,i.extensionManager.splittableMarks),e.scrollIntoView()}return p},od=(n,e={})=>({tr:t,state:r,dispatch:i,editor:s})=>{var o;let l=F(n,r.schema),{$from:a,$to:c}=r.selection,f=r.selection.node;if(f&&f.isBlock||a.depth<2||!a.sameParent(c))return!1;let d=a.node(-1);if(d.type!==l)return!1;let u=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(i){let y=b.empty,w=a.index(-1)?1:a.index(-2)?2:3;for(let q=a.depth-w;q>=a.depth-3;q-=1)y=b.from(a.node(q).copy(y));let O=a.indexAfter(-1){if(X>-1)return!1;q.isTextblock&&q.content.size===0&&(X=E+1)}),X>-1&&t.setSelection(M.near(t.doc.resolve(X))),t.scrollIntoView()}return!0}let h=c.pos===a.end()?d.contentMatchAt(0).defaultType:null,p={...yn(u,d.type.name,d.attrs),...e},m={...yn(u,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,c.pos);let g=h?[{type:l,attrs:p},{type:h,attrs:m}]:[{type:l,attrs:p}];if(!te(t.doc,a.pos,2))return!1;if(i){let{selection:y,storedMarks:w}=r,{splittableMarks:O}=s.extensionManager,v=w||y.$to.parentOffset&&y.$from.marks();if(t.split(a.pos,2,g).scrollIntoView(),!v||!i)return!0;let D=v.filter(A=>O.includes(A.type.name));t.ensureMarks(D)}return!0},Wr=(n,e)=>{let t=ti(o=>o.type===e)(n.selection);if(!t)return!0;let r=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(r===void 0)return!0;let i=n.doc.nodeAt(r);return t.node.type===i?.type&&oe(n.doc,t.pos)&&n.join(t.pos),!0},jr=(n,e)=>{let t=ti(o=>o.type===e)(n.selection);if(!t)return!0;let r=n.doc.resolve(t.start).after(t.depth);if(r===void 0)return!0;let i=n.doc.nodeAt(r);return t.node.type===i?.type&&oe(n.doc,r)&&n.join(r),!0},ld=(n,e,t,r={})=>({editor:i,tr:s,state:o,dispatch:l,chain:a,commands:c,can:f})=>{let{extensions:d,splittableMarks:u}=i.extensionManager,h=F(n,o.schema),p=F(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:w}=m,O=y.blockRange(w),v=g||m.$to.parentOffset&&m.$from.marks();if(!O)return!1;let D=ti(A=>zo(A.type.name,d))(m);if(O.depth>=1&&D&&O.depth-D.depth<=1){if(D.node.type===h)return c.liftListItem(p);if(zo(D.node.type.name,d)&&h.validContent(D.node.content)&&l)return a().command(()=>(s.setNodeMarkup(D.pos,h),!0)).command(()=>Wr(s,h)).command(()=>jr(s,h)).run()}return!t||!v||!l?a().command(()=>f().wrapInList(h,r)?!0:c.clearNodes()).wrapInList(h,r).command(()=>Wr(s,h)).command(()=>jr(s,h)).run():a().command(()=>{let A=f().wrapInList(h,r),X=v.filter(q=>u.includes(q.type.name));return s.ensureMarks(X),A?!0:c.clearNodes()}).wrapInList(h,r).command(()=>Wr(s,h)).command(()=>jr(s,h)).run()},ad=(n,e={},t={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=t,o=Ae(n,r.schema);return Gr(r,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},cd=(n,e,t={})=>({state:r,commands:i})=>{let s=F(n,r.schema),o=F(e,r.schema),l=It(r,s,t),a;return r.selection.$anchor.sameParent(r.selection.$head)&&(a=r.selection.$anchor.parent.attrs),l?i.setNode(o,a):i.setNode(s,{...a,...t})},fd=(n,e={})=>({state:t,commands:r})=>{let i=F(n,t.schema);return It(t,i,e)?r.lift(i):r.wrapIn(i,e)},dd=()=>({state:n,dispatch:e})=>{let t=n.plugins;for(let r=0;r=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},ud=()=>({tr:n,dispatch:e})=>{let{selection:t}=n,{empty:r,ranges:i}=t;return r||e&&i.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},hd=(n,e={})=>({tr:t,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=Ae(n,r.schema),{$from:c,empty:f,ranges:d}=l;if(!i)return!0;if(f&&o){let{from:u,to:h}=l,p=(s=c.marks().find(g=>g.type===a))===null||s===void 0?void 0:s.attrs,m=jo(c,a,p);m&&(u=m.from,h=m.to),t.removeMark(u,h,a)}else d.forEach(u=>{t.removeMark(u.$from.pos,u.$to.pos,a)});return t.removeStoredMark(a),!0},pd=(n,e={})=>({tr:t,state:r,dispatch:i})=>{let s=null,o=null,l=Mn(typeof n=="string"?n:n.name,r.schema);return l?(l==="node"&&(s=F(n,r.schema)),l==="mark"&&(o=Ae(n,r.schema)),i&&t.selection.ranges.forEach(a=>{let c=a.$from.pos,f=a.$to.pos,d,u,h,p;t.selection.empty?r.doc.nodesBetween(c,f,(m,g)=>{s&&s===m.type&&(h=Math.max(g,c),p=Math.min(g+m.nodeSize,f),d=g,u=m)}):r.doc.nodesBetween(c,f,(m,g)=>{g=c&&g<=f&&(s&&s===m.type&&t.setNodeMarkup(g,void 0,{...m.attrs,...e}),o&&m.marks.length&&m.marks.forEach(y=>{if(o===y.type){let w=Math.max(g,c),O=Math.min(g+m.nodeSize,f);t.addMark(w,O,o.create({...y.attrs,...e}))}}))}),u&&(d!==void 0&&t.setNodeMarkup(d,void 0,{...u.attrs,...e}),o&&u.marks.length&&u.marks.forEach(m=>{o===m.type&&t.addMark(h,p,o.create({...m.attrs,...e}))}))}),!0):!1},md=(n,e={})=>({state:t,dispatch:r})=>{let i=F(n,t.schema);return To(i,e)(t,r)},gd=(n,e={})=>({state:t,dispatch:r})=>{let i=F(n,t.schema);return No(i,e)(t,r)},yd=Object.freeze({__proto__:null,blur:tf,clearContent:nf,clearNodes:rf,command:sf,createParagraphNear:of,cut:lf,deleteCurrentNode:af,deleteNode:cf,deleteRange:ff,deleteSelection:df,enter:uf,exitCode:hf,extendMarkRange:pf,first:mf,focus:yf,forEach:bf,insertContent:kf,insertContentAt:wf,joinBackward:Of,joinDown:Mf,joinForward:Ef,joinItemBackward:Tf,joinItemForward:Nf,joinTextblockBackward:Df,joinTextblockForward:Af,joinUp:Cf,keyboardShortcut:If,lift:Pf,liftEmptyBlock:Rf,liftListItem:Bf,newlineInCode:zf,resetAttributes:Ff,scrollIntoView:Lf,selectAll:$f,selectNodeBackward:Vf,selectNodeForward:Jf,selectParentNode:Wf,selectTextblockEnd:jf,selectTextblockStart:Kf,setContent:Hf,setMark:Qf,setMeta:ed,setNode:td,setNodeSelection:nd,setTextSelection:rd,sinkListItem:id,splitBlock:sd,splitListItem:od,toggleList:ld,toggleMark:ad,toggleNode:cd,toggleWrap:fd,undoInputRule:dd,unsetAllMarks:ud,unsetMark:hd,updateAttributes:pd,wrapIn:md,wrapInList:gd}),bd=P.create({name:"commands",addCommands(){return{...yd}}}),kd=P.create({name:"drop",addProseMirrorPlugins(){return[new I({key:new $("tiptapDrop"),props:{handleDrop:(n,e,t,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:r})}}})]}}),xd=P.create({name:"editable",addProseMirrorPlugins(){return[new I({key:new $("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Sd=P.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:n}=this;return[new I({key:new $("focusEvents"),props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;let r=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,t)=>{n.isFocused=!1;let r=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),wd=P.create({name:"keymap",addKeyboardShortcuts(){let n=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{let{selection:a,doc:c}=l,{empty:f,$anchor:d}=a,{pos:u,parent:h}=d,p=d.parent.isTextblock&&u>0?l.doc.resolve(u-1):d,m=p.parent.type.spec.isolating,g=d.pos-d.parentOffset,y=m&&p.parent.childCount===1?g===d.pos:C.atStart(c).from===u;return!f||!h.type.isTextblock||h.textContent.length||!y||y&&d.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...r},s={...r,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return ei()||Uo()?s:i},addProseMirrorPlugins(){return[new I({key:new $("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(m=>m.getMeta("composition")))return;let r=n.some(m=>m.docChanged)&&!e.doc.eq(t.doc),i=n.some(m=>m.getMeta("preventClearDocument"));if(!r||i)return;let{empty:s,from:o,to:l}=e.selection,a=C.atStart(e.doc).from,c=C.atEnd(e.doc).to;if(s||!(o===a&&l===c)||!Pt(t.doc))return;let u=t.tr,h=Sn({state:t,transaction:u}),{commands:p}=new ot({editor:this.editor,state:h});if(p.clearNodes(),!!u.steps.length)return u}})]}}),Cd=P.create({name:"paste",addProseMirrorPlugins(){return[new I({key:new $("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),Md=P.create({name:"tabindex",addProseMirrorPlugins(){return[new I({key:new $("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});var Yr=class n{get name(){return this.node.type.name}constructor(e,t,r=!1,i=null){this.currentNode=null,this.actualDepth=null,this.isBlock=r,this.resolvedPos=e,this.editor=t,this.currentNode=i}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!==null&&e!==void 0?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,r=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,r=this.to-1}this.editor.commands.insertContentAt({from:t,to:r},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;let e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new n(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new n(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new n(e,this.editor)}get children(){let e=[];return this.node.content.forEach((t,r)=>{let i=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,o=this.pos+r+(s?0:1),l=this.resolvedPos.doc.resolve(o);if(!i&&l.depth<=this.depth)return;let a=new n(l,this.editor,i,i?t:null);i&&(a.actualDepth=this.depth+1),e.push(new n(l,this.editor,i,i?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let r=null,i=this.parent;for(;i&&!r;){if(i.node.type.name===e)if(Object.keys(t).length>0){let s=i.node.attrs,o=Object.keys(t);for(let l=0;l{r&&i.length>0||(o.node.type.name===e&&s.every(a=>t[a]===o.node.attrs[a])&&i.push(o),!(r&&i.length>0)&&(i=i.concat(o.querySelectorAll(e,t,r))))}),i}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Od=`.ProseMirror {
+function J(n){this.content=n}J.prototype={constructor:J,find:function(n){for(var e=0;e>1}};J.from=function(n){if(n instanceof J)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new J(e)};var Tn=J;function yi(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=yi(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function ki(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=0,f=Math.min(o.text.length,l.text.length);for(;ce&&r(a,i+l,s||null,o)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),r,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Bt(r+1,o):Bt(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};T.none=[];var Pe=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=xi(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(bi(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(k.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(k.empty,0,0);function bi(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(bi(s.content,e-i-1,t-i-1)))}function xi(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=xi(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function fl(n,e,t){if(t.openStart>n.depth)throw new Pe("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Pe("Inconsistent open depths");return Si(n,e,t,0)}function Si(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function lt(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(De(n.nodeAfter,r),s++));for(let l=s;li&&Dn(n,e,i+1),o=r.depth>i&&Dn(t,r,i+1),l=[];return lt(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(wi(s,o),De(Ie(s,Ci(n,e,t,r,i+1)),l)):(s&&De(Ie(s,Lt(n,e,i+1)),l),lt(e,t,i,l),o&&De(Ie(o,Lt(t,r,i+1)),l)),lt(r,null,i,l),new k(l)}function Lt(n,e,t){let r=[];if(lt(null,n,t,r),n.depth>t){let i=Dn(n,e,t+1);De(Ie(i,Lt(n,e,t+1)),r)}return lt(e,null,t,r),new k(r)}function dl(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(k.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var $t=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Re(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new n(t,r,s)}static resolveCached(e,t){let r=ai.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Mi(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=k.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=k.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};ee.prototype.text=void 0;var Pn=class n extends ee{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Mi(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Mi(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var Be=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Rn(e,t);if(r.next==null)return n.empty;let i=Oi(r);r.next&&r.err("Unexpected trailing text");let s=xl(bl(i));return Sl(s,r),s}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(`
+`)}};Be.empty=new Be(!0);var Rn=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Oi(n){let e=[];do e.push(pl(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function pl(n){let e=[];do e.push(ml(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function ml(n){let e=kl(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=gl(n,e);else break;return e}function ci(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function gl(n,e){let t=ci(n),r=t;return n.eat(",")&&(n.next!="}"?r=ci(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function yl(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function kl(n){if(n.eat("(")){let e=Oi(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=yl(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function bl(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[r.join(",")]=new Be(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ti(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ee(this,this.computeAttrs(e),k.from(t),T.setFrom(r))}createChecked(e=null,t,r){return t=k.from(t),this.checkContent(t),new ee(this,this.computeAttrs(e),t,T.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=k.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(k.empty,!0);return s?new ee(this,e,t.append(s),T.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function wl(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Bn=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?wl(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},ct=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=vi(e,i.attrs),this.excluded=null;let s=Ni(this.attrs);this.instance=s?new T(this,s):null}create(e=null){return!e&&this.instance?this.instance:new T(this,Ti(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},ft=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Tn.from(e.nodes),t.marks=Tn.from(e.marks||{}),this.nodes=Vt.compile(this.spec.nodes,this),this.marks=ct.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=Be.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?di(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:di(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Vt){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Pn(r,r.defaultAttrs,e,T.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return ee.fromJSON(this,e)}markFromJSON(e){return T.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function di(n,e){let t=[];for(let r=0;r-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Cl(n){return n.tag!=null}function Ml(n){return n.style!=null}var he=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Cl(i))this.tags.push(i);else if(Ml(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Jt(this,t,!1);return r.addAll(e,T.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Jt(this,t,!0);return r.addAll(e,T.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=hi(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=hi(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},Di={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Ol={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ii={ol:!0,ul:!0},dt=1,zn=2,at=4;function ui(n,e,t){return e!=null?(e?dt:0)|(e==="full"?zn:0):n&&n.whitespace=="pre"?dt|zn:t&~at}var Ge=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=T.none,this.match=s||(o&at?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(k.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&dt)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=k.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(k.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Di.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Jt=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=ui(null,t.preserveWhitespace,0)|(r?at:0);i?s=new Ge(i.type,i.attrs,T.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ge(null,null,T.none,!0,null,o):s=new Ge(e.schema.topNodeType,null,T.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top,s=i.options&zn?"full":this.localPreserveWS||(i.options&dt)>0;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)s!=="full"?r=r.replace(/\r?\n|\r/g," "):r=r.replace(/\r\n?/g,`
+`);else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],l=e.previousSibling;(!o||l&&l.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Ii.hasOwnProperty(o)&&this.parser.normalizeLists&&El(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,r));e:if(a?a.ignore:Ol.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(Di.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let d=a&&a.skip?t:this.readStyles(e,t);d&&this.addAll(e,d),c&&this.sync(s),this.needsBlock=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
+`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(o,t.attrs||null,r,t.preserveWhitespace);a&&(s=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(c.type):pi(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ge(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=dt)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function El(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ii.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Nl(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function hi(n){let e={};for(let t in n)e[t]=n[t];return e}function pi(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&zt(vn(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return zt(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=mi(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return mi(e.marks)}};function mi(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function vn(n){return n.document||window.document}var gi=new WeakMap;function Tl(n){let e=gi.get(n);return e===void 0&&gi.set(n,e=Al(n)),e}function Al(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let d in c)if(c[d]!=null){let u=d.indexOf(" ");u>0?a.setAttributeNS(d.slice(0,u),d.slice(u+1),c[d]):a.setAttribute(d,c[d])}}for(let d=f;df)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:p}=zt(n,u,t,r);if(a.appendChild(h),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}var Bi=65535,zi=Math.pow(2,16);function vl(n,e){return n+e*zi}function Pi(n){return n&Bi}function Dl(n){return(n-(n&Bi))/zi}var Fi=1,Li=2,Wt=4,$i=8,pt=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&$i)>0}get deletedBefore(){return(this.delInfo&(Fi|Wt))>0}get deletedAfter(){return(this.delInfo&(Li|Wt))>0}get deletedAcross(){return(this.delInfo&Wt)>0}},me=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=Pi(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+s],f=this.ranges[l+o],d=a+c;if(e<=d){let u=c?e==a?-1:e==d?1:t:t,h=a+i+(u<0?0:f);if(r)return h;let p=e==(t<0?a:d)?null:vl(l/3,e-a),m=e==a?Li:e==d?Fi:Wt;return(t<0?e!=a:e!=d)&&(m|=$i),new pt(h,m,p)}i+=f-c}return r?e+i:new pt(e+i,0,null)}touches(e,t){let r=0,i=Pi(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return L.fromReplace(e,this.from,this.to,s)}invert(){return new ze(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};z.jsonID("addMark",gt);var ze=class n extends z{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Wn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return L.fromReplace(e,this.from,this.to,r)}invert(){return new gt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};z.jsonID("removeMark",ze);var yt=class n extends z{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return L.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return L.fromReplace(e,this.pos,this.pos+1,new b(k.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};z.jsonID("replaceAround",I);function Vn(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Il(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let d=a.marks;if(!r.isInSet(d)&&f.type.allowsMarkType(r.type)){let u=Math.max(c,e),h=Math.min(c+a.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(a)),s.forEach(a=>n.step(a))}function Pl(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof ct){let c=o.marks,f;for(;f=r.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;fn.step(new ze(o.from,o.to,o.style)))}function jn(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a=0;a--)n.step(o[a])}function Rl(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function ge(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,f=k.from(r.node(p).copy(f)),d++):a--;let u=k.empty,h=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=k.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new I(i,s,i,s,new b(r,0,0),t.length,!0))}function $l(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,a)&&Vl(n.doc,n.mapping.slice(s).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let h=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);h&&!p?c=!1:!h&&p&&(c=!0)}c===!1&&Ji(n,o,l,s),jn(n,n.mapping.slice(s).map(l,1),r,void 0,c===null);let f=n.mapping.slice(s),d=f.map(l,1),u=f.map(l+o.nodeSize,1);return n.step(new I(d,u,d+1,u-1,new b(k.from(r.create(a,null,o.marks)),0,0),1,!0)),c===!0&&Vi(n,o,l,s),!1}})}function Vi(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Ji(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
+`))}})}function Vl(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Jl(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new I(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(k.from(o),0,0),1,!0))}function te(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>s;c--,f--){let d=i.node(c),u=i.index(c);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(u,d.childCount),p=r&&r[f+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[f]||d;if(!d.canReplace(u+1,d.childCount)||!m.type.validContent(h))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Wl(n,e,t=1,r){let i=n.doc.resolve(e),s=k.empty,o=k.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=k.from(i.node(l).copy(s));let f=r&&r[c];o=k.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}n.step(new W(e,e,new b(s.append(o),t,t),!0))}function oe(n,e){let t=n.resolve(e),r=t.index();return Wi(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function jl(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Wi(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Hl(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);f&&!d?r=!1:!f&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let f=n.doc.resolve(e+t);Ji(n,f.node(),f.before(),l)}o.inlineContent&&jn(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new W(c,a.map(e+t,-1),b.empty,!0)),r===!0){let f=n.doc.resolve(c);Vi(n,f.node(),f.before(),n.steps.length)}return n}function Kl(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),c=r.node(o),f=!1;if(s==1)f=c.canReplace(a,a,i);else{let d=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=d&&c.canReplaceWith(a,a,d[0])}if(f)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function St(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return ji(i,s,r)?new W(e,t,r):new Jn(i,s,r).fit()}function ji(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Jn=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=k.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=k.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new b(s,o,l);return e>-1?new I(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new W(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Ln(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,d=null;if(t==1&&(o?c.matchType(o.type)||(d=c.fillBefore(k.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(f=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ln(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ln(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(ut(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(ut(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(d=g,f.push(Hi(m.mark(u.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?h:-1)))}let p=c==l.childCount;p||(h=-1),this.placed=ht(this.placed,t,k.from(f)),this.frontier[t].match=d,p&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:c}=this.frontier[l],f=$n(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ht(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ht(this.placed,this.depth,k.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(k.empty,!0);t.childCount&&(this.placed=ht(this.placed,this.frontier.length,t))}};function ut(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(ut(n.firstChild.content,e-1,t)))}function ht(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(ht(n.lastChild.content,e-1,t)))}function Ln(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Hi(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(k.empty,!0)))),n.copy(r)}function $n(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!ql(t,s.content,o)?l:null}function ql(n,e,t){for(let r=t;r0;u--,h--){let p=i.node(u).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(u)>-1?l=u:i.before(u)==h&&o.splice(1,0,-u)}let a=o.indexOf(l),c=[],f=r.openStart;for(let u=r.content,h=0;;h++){let p=u.firstChild;if(c.push(p),h==r.openStart)break;u=p.content}for(let u=f-1;u>=0;u--){let h=c[u],p=Ul(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))f=u;else if(p||!h.type.isTextblock)break}for(let u=r.openStart;u>=0;u--){let h=(u+f+1)%(r.openStart+1),p=c[h];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));u--){let h=o[u];h<0||(e=i.before(h),t=s.after(h))}}function Ki(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(k.empty,!0))}return n}function Gl(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Kl(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(k.from(r),0,0))}function Yl(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=qi(r,i);for(let o=0;o0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function qi(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var jt=class n extends z{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return L.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return L.fromReplace(e,this.pos,this.pos+1,new b(k.from(i),0,t.isLeaf?0:1))}getMap(){return me.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};z.jsonID("attr",jt);var Ht=class n extends z{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return L.ok(r)}getMap(){return me.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};z.jsonID("docAttr",Ht);var Ye=class extends Error{};Ye=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Ye.prototype=Object.create(Error.prototype);Ye.prototype.constructor=Ye;Ye.prototype.name="TransformError";var bt=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new mt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Ye(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=St(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(k.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return _l(this,e,t,r),this}replaceRangeWith(e,t,r){return Gl(this,e,t,r),this}deleteRange(e,t){return Yl(this,e,t),this}lift(e,t){return Bl(this,e,t),this}join(e,t=1){return Hl(this,e,t),this}wrap(e,t){return Ll(this,e,t),this}setBlockType(e,t=e,r,i=null){return $l(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Jl(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new jt(e,t,r)),this}setDocAttribute(e,t){return this.step(new Ht(e,t)),this}addNodeMark(e,t){return this.step(new yt(e,t)),this}removeNodeMark(e,t){if(!(t instanceof T)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new kt(e,t)),this}split(e,t=1,r){return Wl(this,e,t,r),this}addMark(e,t,r){return Il(this,e,t,r),this}removeMark(e,t,r){return Pl(this,e,t,r),this}clearIncompatible(e,t,r){return jn(this,e,t,r),this}};var Hn=Object.create(null),C=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Ut(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Ze(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Ze(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new q(e.node(0))}static atStart(e){return Ze(e,e,0,0,1)||new q(e)}static atEnd(e){return Ze(e,e,e.content.size,e.childCount,-1)||new q(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Hn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Hn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Hn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return M.between(this.$anchor,this.$head).getBookmark()}};C.prototype.visible=!0;var Ut=class{constructor(e,t){this.$from=e,this.$to=t}},Ui=!1;function _i(n){!Ui&&!n.parent.inlineContent&&(Ui=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var M=class n extends C{constructor(e,t=e){_i(e),_i(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return C.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new _t(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=C.findFrom(t,r,!0)||C.findFrom(t,-r,!0);if(s)t=s.$head;else return C.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(C.findFrom(e,-r,!0)||C.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&S.isSelectable(l))return S.create(n,t-(i<0?l.nodeSize:0))}else{let a=Ze(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Gi(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=f)}),n.setSelection(C.near(n.doc.resolve(o),t))}var Yi=1,qt=2,Xi=4,Un=class extends bt{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=qt,this}ensureMarks(e){return T.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&qt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~qt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||T.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(C.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Xi,this}get scrolledIntoView(){return(this.updated&Xi)>0}};function Zi(n,e){return!e||!n?n:n.bind(e)}var Fe=class{constructor(e,t,r){this.name=e,this.init=Zi(t.init,r),this.apply=Zi(t.apply,r)}},Zl=[new Fe("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Fe("selection",{init(n,e){return n.selection||C.atStart(e.doc)},apply(n){return n.selection}}),new Fe("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Fe("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],wt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Zl.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Fe(r.key,r.spec.state,r))})}},Gt=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new wt(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ee.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=C.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Qi(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Qi(i,e,{})),t[r]=i}return t}var P=class{constructor(e){this.spec=e,this.props={},e.props&&Qi(e.props,this,this.props),this.key=e.key?e.key.key:es("plugin")}getState(e){return e[this.key]}},Kn=Object.create(null);function es(n){return n in Kn?n+"$"+ ++Kn[n]:(Kn[n]=0,n+"$")}var U=class{constructor(e="key"){this.key=es(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var $=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Et=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Qn=null,ke=function(n,e,t){let r=Qn||(Qn=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Ql=function(){Qn=null},He=function(n,e,t,r){return t&&(ts(n,e,t,r,-1)||ts(n,e,t,r,1))},ea=/^(img|br|input|textarea|hr)$/i;function ts(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:re(n))){let s=n.parentNode;if(!s||s.nodeType!=1||vt(n)||ea.test(n.nodeName)||n.contentEditable=="false")return!1;e=$(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?re(n):0}else return!1}}function re(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ta(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=re(n)}else if(n.parentNode&&!vt(n))e=$(n),n=n.parentNode;else return null}}function na(n,e){for(;;){if(n.nodeType==3&&e2),ne=rt||(le?/Mac/.test(le.platform):!1),oa=le?/Win/.test(le.platform):!1,be=/Android \d/.test(Te),Dt=!!ns&&"webkitFontSmoothing"in ns.documentElement.style,la=Dt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function aa(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ye(n,e){return typeof n=="number"?n:n[e]}function ca(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function rs(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Et(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,c=a?aa(s):ca(l),f=0,d=0;if(e.topc.bottom-ye(r,"bottom")&&(d=e.bottom-e.top>c.bottom-c.top?e.top+ye(i,"top")-c.top:e.bottom-c.bottom+ye(i,"bottom")),e.leftc.right-ye(r,"right")&&(f=e.right-c.right+ye(i,"right")),f||d)if(a)s.defaultView.scrollBy(f,d);else{let u=l.scrollLeft,h=l.scrollTop;d&&(l.scrollTop+=d),f&&(l.scrollLeft+=f);let p=l.scrollLeft-u,m=l.scrollTop-h;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function fa(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Fs(n.dom)}}function Fs(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Et(r));return e}function da({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ls(t,r==0?0:r-e)}function Ls(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=f,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?ha(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:$s(t,i)}function ha(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function yr(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function pa(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function ga(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&(!o&&a.left>r.left||a.top>r.top?i=l.posBefore:(!o&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Vs(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;Dt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=ga(n,r,i,e))}l==null&&(l=ma(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function is(n){return n.top=0&&i==r.nodeValue.length?(a--,f=1):t<0?a--:c++,Ct(Ce(ke(r,a,c),f),f<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==re(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return _n(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==re(r))){let a=r.childNodes[i-1],c=a.nodeType==3?ke(a,re(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Ct(Ce(c,1),!1)}if(s==null&&i=0)}function Ct(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function _n(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Ws(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function ba(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Ws(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Js(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=ke(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cf.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}var xa=/[\u0590-\u08ac]/;function Sa(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!xa.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Ws(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:d}=n.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let h=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(f,d),a&&(a!=f||c!=d)&&l.extend&&l.extend(a,c)}catch{}return u!=null&&(l.caretBidiLevel=u),g}):r.pos==r.start()||r.pos==r.end()}var ss=null,ls=null,as=!1;function wa(n,e,t){return ss==e&&ls==t?as:(ss=e,ls=t,as=t=="up"||t=="down"?ba(n,e,t):Sa(n,e,t))}var ie=0,cs=1,$e=2,ae=3,Ke=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ie,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t$(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof Zt){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Yt&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?$(s.dom)+1:0}}else{let s,o=!0;for(;s=r=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let d=l;d>0;d--){let u=this.children[d-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){i=$(u.dom)+1;break}e-=u.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;fp&&ot){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(h)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==r||t==o?$e:cs,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ae:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?$e:ae}r=o}this.dirty=$e}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?$e:cs;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==ie&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},rr=class extends Ke{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},it=class n extends Ke{constructor(e,t,r,i,s){super(e,[],r,i),this.mark=t,this.spec=s}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=pe.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ae||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ae&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ie){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=lr(s,0,e,r));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),f=c&&c.dom,d=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:d}=pe.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let u=f;return f=Ks(f,r,t),c?a=new ir(e,t,r,i,f,d||null,u,c,s,o+1):t.isText?new Xt(e,t,r,i,f,u,s):new n(e,t,r,i,f,d||null,u,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>k.empty)}return e}matchesNode(e,t,r){return this.dirty==ie&&e.eq(this.node)&&Qt(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new or(this,o&&o.node,e);Ea(this.node,this.innerDeco,(c,f,d)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!d&&a.syncToMarks(f==this.node.childCount?T.none:this.node.child(f).marks,r,e),a.placeWidget(c,e,i)},(c,f,d,u)=>{a.syncToMarks(c.marks,r,e);let h;a.findNodeMatch(c,f,d,u)||l&&e.state.selection.from>i&&e.state.selection.to