diff --git a/blocks/browse/da-list/da-list.css b/blocks/browse/da-list/da-list.css
index ad3bf07fe..ba1ed2309 100644
--- a/blocks/browse/da-list/da-list.css
+++ b/blocks/browse/da-list/da-list.css
@@ -254,47 +254,6 @@ da-list-item.is-expanded::after {
display: none;
}
-.da-list-status {
- position: fixed;
- inset: 0;
- background: rgb(255 255 255 / 60%);
- display: flex;
- justify-content: center;
- align-items: center;
- z-index: 500;
-}
-
-.da-list-status-toast {
- width: 280px;
- background: var(--s2-blue-800);
- line-height: 48px;
- border-radius: 6px;
- filter: drop-shadow(rgb(0 0 0 / 15%) 0 1px 4px);
- justify-content: space-between;
- align-items: center;
- box-sizing: border-box;
- color: #fff;
- font-size: 14px;
- overflow: hidden;
-}
-
-.da-list-status-title {
- font-weight: 700;
- padding: 0 12px 0 40px;
- margin: 0;
-}
-
-.da-list-status-description {
- line-height: 1.6;
- padding: 6px 12px;
- margin: 0;
- background: rgb(255 255 255 / 10%);
-}
-
-.da-list-status-type-info .da-list-status-title {
- background: var(--s2-blue-800) url("/blocks/browse/img/Smock_InfoOutline_18_N.svg") 12px 50% no-repeat;
-}
-
/* Checkbox */
.checkbox-wrapper {
diff --git a/blocks/browse/da-list/da-list.js b/blocks/browse/da-list/da-list.js
index 5712a610e..8d8cd1650 100644
--- a/blocks/browse/da-list/da-list.js
+++ b/blocks/browse/da-list/da-list.js
@@ -37,7 +37,7 @@ export default class DaList extends LitElement {
_dropFiles: { state: true },
_dropMessage: { state: true },
_dropConflicts: { state: true },
- _status: { state: true },
+ _toast: { state: true },
_confirm: { state: true },
_confirmText: { state: true },
_unpublish: { state: true },
@@ -94,16 +94,17 @@ export default class DaList extends LitElement {
async firstUpdated() {
await import('../../shared/da-dialog/da-dialog.js');
+ await import('../../shared/da-toast/da-toast.js');
await import('../da-actionbar/da-actionbar.js');
this.setupObserver();
}
setStatus(text, description, type = 'info') {
if (!text) {
- this._status = null;
+ this._toast = null;
return;
}
- this._status = { type, text, description };
+ this._toast = { type, text, description, duration: 0 };
}
handlePermissions(permissions) {
@@ -373,7 +374,7 @@ export default class DaList extends LitElement {
return pasteItem;
});
- const showStatus = setTimeout(() => {
+ const pasteStatusTimer = setTimeout(() => {
this.setStatus('Pasting', 'Please be patient. Pasting items with many children can take time.');
}, 2000);
@@ -383,7 +384,7 @@ export default class DaList extends LitElement {
await this.handleItemAction({ item, type });
}));
- clearTimeout(showStatus);
+ clearTimeout(pasteStatusTimer);
this.setStatus();
this.handleClear();
@@ -467,8 +468,7 @@ export default class DaList extends LitElement {
}
handleShare() {
- this.setStatus('Copied', 'URLs have been copied to the clipboard.');
- setTimeout(() => { this.setStatus(); }, 3000);
+ this._toast = { text: 'Copied', description: 'URLs have been copied to the clipboard.' };
}
dragenter(e) {
@@ -745,13 +745,7 @@ export default class DaList extends LitElement {
}
renderStatus() {
- return html`
-
-
-
${this._status.text}
- ${this._status.description ? html`
${this._status.description}
` : nothing}
-
-
`;
+ return html` { this._toast = null; }}>`;
}
renderConfirm() {
@@ -966,7 +960,7 @@ export default class DaList extends LitElement {
currentPath="${this.fullpath}"
role="row"
data-visible="${this._selectedItems?.length > 0}">
- ${this._status ? this.renderStatus() : nothing}
+ ${this._toast ? this.renderStatus() : nothing}
${this._confirm ? this.renderConfirm() : nothing}
${this._dropConflicts?.length ? this.renderDropConfirm() : nothing}
${!this._confirm && this._itemErrors.length ? this.renderErrors() : nothing}
diff --git a/blocks/browse/da-sites/da-sites.css b/blocks/browse/da-sites/da-sites.css
index 4aecf354d..be096a521 100644
--- a/blocks/browse/da-sites/da-sites.css
+++ b/blocks/browse/da-sites/da-sites.css
@@ -421,45 +421,3 @@ form button:hover {
text-align: center;
}
-/* Handle Share */
-
-.da-list-status {
- position: fixed;
- inset: 0;
- background: rgb(255 255 255 / 60%);
- display: flex;
- justify-content: center;
- align-items: center;
- z-index: 500;
-}
-
-.da-list-status-toast {
- width: 280px;
- background: var(--s2-blue-800);
- line-height: 48px;
- border-radius: 6px;
- filter: drop-shadow(rgb(0 0 0 / 15%) 0 1px 4px);
- justify-content: space-between;
- align-items: center;
- box-sizing: border-box;
- color: #FFF;
- font-size: 14px;
- overflow: hidden;
-}
-
-.da-list-status-title {
- font-weight: 700;
- padding: 0 12px 0 40px;
- margin: 0;
-}
-
-.da-list-status-description {
- line-height: 1.6;
- padding: 6px 12px;
- margin: 0;
- background: rgb(255 255 255 / 10%);
-}
-
-.da-list-status-type-info .da-list-status-title {
- background: var(--s2-blue-800) url('/blocks/browse/img/Smock_InfoOutline_18_N.svg') 12px 50% no-repeat;
-}
diff --git a/blocks/browse/da-sites/da-sites.js b/blocks/browse/da-sites/da-sites.js
index a8b79b6b6..f6fd9d93c 100644
--- a/blocks/browse/da-sites/da-sites.js
+++ b/blocks/browse/da-sites/da-sites.js
@@ -13,7 +13,7 @@ function getRandom() {
export default class DaSites extends LitElement {
static properties = {
_recents: { state: true },
- _status: { state: true },
+ _toast: { state: true },
_urlError: { state: true },
};
@@ -26,6 +26,7 @@ export default class DaSites extends LitElement {
super.connectedCallback();
this.shadowRoot.adoptedStyleSheets = [styles];
this._recents = this.getRecents();
+ import('../../shared/da-toast/da-toast.js');
}
getRecents() {
@@ -42,10 +43,6 @@ export default class DaSites extends LitElement {
return null;
}
- setStatus(text, description, type = 'info') {
- this._status = text ? { type, text, description } : null;
- }
-
handleRemove(site) {
// Get the index of the site to remove
const idx = this._recents.findIndex((recent) => recent.name === site.name);
@@ -100,18 +97,7 @@ export default class DaSites extends LitElement {
const data = [new ClipboardItem({ [blob.type]: blob })];
navigator.clipboard.write(data);
- this.setStatus('Copied', 'The link was copied to the clipboard.');
- setTimeout(() => { this.setStatus(); }, 3000);
- }
-
- renderStatus() {
- return html`
-
-
-
${this._status.text}
- ${this._status.description ? html`
${this._status.description}
` : nothing}
-
-
`;
+ this._toast = { text: 'Copied', description: 'The link was copied to the clipboard.' };
}
renderGo() {
@@ -230,7 +216,7 @@ export default class DaSites extends LitElement {
- ${this._status ? this.renderStatus() : nothing}
+ { this._toast = null; }}>
`;
}
}
diff --git a/blocks/edit/da-comments/da-comments.css b/blocks/edit/da-comments/da-comments.css
new file mode 100644
index 000000000..842a525d0
--- /dev/null
+++ b/blocks/edit/da-comments/da-comments.css
@@ -0,0 +1,612 @@
+:host {
+ font-family: var(--body-font-family);
+
+ --comments-panel-width: 375px;
+ --comments-panel-padding-left: 32px;
+ --comments-panel-top-offset: 36px;
+ --comments-card-gap: 16px;
+ --comment-surface: #fff;
+ --comment-surface-alt: var(--s2-gray-75);
+ --comment-border: var(--s2-gray-200);
+ --comment-border-hover: var(--s2-gray-400);
+ --comment-text-muted: var(--s2-gray-700);
+ --comment-text-placeholder: var(--s2-gray-600);
+ --comment-reaction-active-bg: var(--s2-blue-200);
+ --comment-reaction-active-border: var(--s2-blue-800);
+}
+
+.da-comments-panel {
+ display: block;
+ width: var(--comments-panel-width);
+ margin: 0 auto;
+ padding-left: var(--comments-panel-padding-left);
+ border: none;
+}
+
+.da-comments-panel.is-pinned {
+ position: sticky;
+ top: var(--comments-panel-top-offset);
+}
+
+.da-comments-title {
+ top: 0;
+ background: var(--comment-surface);
+ padding-top: 12px;
+ padding-bottom: 12px;
+ z-index: 10;
+}
+
+.da-comments-close-btn {
+ font-family: var(--body-font-family);
+ line-height: 32px;
+ font-weight: 700;
+ font-size: 20px;
+ text-transform: uppercase;
+ padding: 0 0 0 44px;
+ overflow: hidden;
+ display: block;
+ height: 32px;
+ border: none;
+ background: url('/blocks/edit/img/Smock_CloseCircle_18_N.svg') left center / 32px no-repeat;
+ cursor: pointer;
+}
+
+.da-comments-hint {
+ font-size: 12px;
+}
+
+.da-comments-hint kbd {
+ display: inline-block;
+ padding: 2px 6px;
+ background: var(--s2-gray-75);
+ border: 1px solid var(--s2-gray-200);
+ border-radius: 4px;
+ font-family: var(--body-font-family);
+ font-size: 12px;
+ color: var(--s2-gray-800);
+ white-space: nowrap;
+}
+
+
+.da-comments-list {
+ padding-right: 16px;
+}
+
+.da-comments-threads-list {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+.da-comments-empty {
+ color: var(--s2-gray-700);
+ font-size: 14px;
+ text-align: center;
+ padding: 24px 0;
+}
+
+.da-comments-detached-reference {
+ display: block;
+ font-size: 11px;
+ color: var(--comment-text-muted);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.da-comment-tabs {
+ display: flex;
+ gap: 16px;
+ margin: 16px 0;
+ box-shadow: inset 0 -2px 0 var(--s2-gray-200);
+ overflow-x: auto;
+}
+
+.da-comment-tab {
+ display: inline-flex;
+ gap: 6px;
+ align-items: center;
+ padding: 0 0 12px;
+ border: none;
+ background: transparent;
+ box-shadow: inset 0 -2px 0 transparent;
+ color: var(--comment-text-muted);
+ font-family: var(--body-font-family);
+ font-size: 13px;
+ font-weight: 500;
+ cursor: pointer;
+ white-space: nowrap;
+ transition: color 0.15s ease;
+}
+
+.da-comment-tab:hover {
+ color: var(--spectrum-blue-800);
+}
+
+.da-comment-tab.is-active {
+ color: var(--spectrum-blue-800);
+ box-shadow: inset 0 -2px 0 var(--spectrum-blue-800);
+}
+
+.da-comment-tab-count {
+ color: inherit;
+}
+
+.da-comments-thread-detail {
+ padding-right: 16px;
+ position: sticky;
+ top: 16px;
+}
+
+.da-comments-back-btn {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 8px 0;
+ margin-bottom: 12px;
+ border: none;
+ background: transparent;
+ color: var(--s2-gray-700);
+ font-family: var(--body-font-family);
+ font-size: 14px;
+ cursor: pointer;
+}
+
+.da-comments-back-btn:hover {
+ color: var(--spectrum-blue-800);
+}
+
+.da-comment-card {
+ position: relative;
+ background: var(--comment-surface);
+ border: 1px solid var(--s2-gray-200);
+ border-radius: 8px;
+ padding: 16px;
+ display: flex;
+ flex-direction: column;
+}
+
+.da-comments-inline-composer {
+ margin-bottom: 16px;
+ position: sticky;
+ top: 16px;
+ z-index: 10;
+}
+
+.da-comment-card.resolved {
+ background: var(--s2-gray-50);
+}
+
+.da-comments-thread-surface.is-preview {
+ margin-bottom: 8px;
+ cursor: pointer;
+ transition: all 0.2s;
+ animation: da-comments-slide-in 0.2s ease-out;
+}
+
+.da-comments-thread-surface.is-preview:hover {
+ background: var(--s2-gray-50);
+}
+
+.da-comment-avatar {
+ width: 32px;
+ height: 32px;
+ border-radius: 50%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ color: #fff;
+ font-size: 12px;
+ font-weight: 600;
+ flex-shrink: 0;
+}
+
+.da-comment {
+ margin-bottom: 12px;
+}
+
+.da-comment:last-child {
+ margin-bottom: 0;
+ border-bottom: 0;
+}
+
+.da-comment-header {
+ display: flex;
+ align-items: start;
+ gap: 8px;
+ margin-bottom: 8px;
+}
+
+.da-comment-meta {
+ flex: 1;
+ min-width: 0;
+}
+
+.da-comment-author {
+ display: block;
+ font-weight: 600;
+ font-size: 13px;
+ color: var(--s2-gray-800);
+}
+
+.da-comment-time {
+ font-size: 12px;
+ color: var(--s2-gray-700);
+}
+
+.da-comments-edited-indicator {
+ font-style: italic;
+ color: var(--s2-gray-600);
+}
+
+.da-comment-content {
+ font-size: 15px;
+ line-height: 1.5;
+ color: var(--s2-gray-800);
+ white-space: pre-wrap;
+ margin-left: 40px;
+ overflow-wrap: break-word;
+}
+
+.da-comment-content.is-clamped {
+ line-clamp: 4;
+ display: -webkit-box;
+ -webkit-line-clamp: 4;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+}
+
+.da-comment-header-actions {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+}
+
+.da-comments-btn-resolve,
+.da-comments-btn-menu {
+ padding: 4px;
+ border: none;
+ background: transparent;
+ color: var(--s2-gray-700);
+ cursor: pointer;
+ border-radius: 4px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.da-comment-header-actions button:not(.da-comments-menu-item):hover {
+ background: var(--s2-gray-100);
+ color: var(--s2-blue-800);
+ border-radius: 50%;
+}
+
+.da-comment-menu {
+ position: relative;
+}
+
+.da-comments-menu-dropdown {
+ position: absolute;
+ top: 100%;
+ right: 0;
+ min-width: 180px;
+ background: var(--comment-surface);
+ border: 1px solid var(--s2-gray-200);
+ border-radius: 8px;
+ box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
+ z-index: 100;
+ overflow: hidden;
+}
+
+.da-comments-menu-item {
+ display: block;
+ width: 100%;
+ padding: 10px 16px;
+ border: none;
+ background: transparent;
+ text-align: left;
+ font-family: var(--body-font-family);
+ font-size: 14px;
+ color: var(--s2-gray-800);
+ cursor: pointer;
+}
+
+.da-comments-menu-item:hover {
+ background: var(--s2-gray-75);
+}
+
+.da-comment-replies {
+ margin-top: 12px;
+ padding-top: 12px;
+ border-top: 1px solid var(--s2-gray-200);
+}
+
+.da-comments-thread-replies-summary {
+ display: inline-block;
+ margin-left: 40px;
+ font-size: 12px;
+ color: var(--spectrum-blue-800);
+ font-weight: 500;
+}
+
+.da-comment-reply {
+ padding-left: 24px;
+ border-bottom: 1px solid var(--s2-gray-100);
+ margin-bottom: 24px;
+ padding-bottom: 12px;
+}
+
+.da-comment-form {
+ margin-top: 12px;
+}
+
+.da-comment-form sl-textarea {
+ height: 100px;
+}
+
+.da-comments-reply-form:not(.da-comments-reply-form-expanded) .da-comment-form sl-textarea {
+ height: 36px;
+}
+
+.da-comment-form-actions {
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+ gap: 8px;
+ margin-top: 8px;
+}
+
+.da-comment-form-hint {
+ margin-right: auto;
+ font-size: 11px;
+ color: var(--s2-gray-600);
+}
+
+.da-comment-form-hint kbd {
+ font-family: inherit;
+ font-size: 11px;
+ padding: 1px 5px;
+ background: var(--s2-gray-75);
+ border: 1px solid var(--s2-gray-200);
+ border-radius: 3px;
+}
+
+.da-comment-thread-actions {
+ display: flex;
+ justify-content: flex-start;
+ flex-wrap: wrap;
+ gap: 8px;
+ margin-top: 12px;
+ padding-top: 12px;
+ border-top: 1px solid var(--s2-gray-200);
+}
+
+.da-comments-resolved-info {
+ width: 100%;
+ font-size: 12px;
+ color: var(--s2-gray-600);
+ margin-left: 40px;
+}
+
+.da-comment-form-actions sl-button,
+.da-comment-thread-actions sl-button {
+ flex: 0 0 auto;
+}
+
+.da-comments-reply-form {
+ margin-top: 12px;
+ padding-top: 12px;
+ border-top: 1px solid var(--s2-gray-200);
+}
+
+/* Edit form */
+.da-comments-edit-form {
+ margin-top: 8px;
+ margin-left: 40px;
+}
+
+@media (width <=600px) {
+ .da-comments-panel {
+ width: 100%;
+ padding: 0 16px;
+ }
+}
+
+@keyframes da-comments-slide-in {
+ from {
+ opacity: 0;
+ transform: translateX(20px);
+ }
+
+ to {
+ opacity: 1;
+ transform: translateX(0);
+ }
+}
+
+.da-comments-reactions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ margin-top: 8px;
+ margin-left: 40px;
+ align-items: center;
+}
+
+.da-comments-reaction {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 4px 8px;
+ border: 1px solid var(--comment-border);
+ border-radius: 12px;
+ background: var(--comment-surface-alt);
+ cursor: pointer;
+ font-size: 13px;
+ transition: all 0.15s;
+}
+
+.da-comments-reaction:disabled {
+ cursor: default;
+ opacity: 0.8;
+}
+
+.da-comments-reaction:hover:not(:disabled) {
+ background: var(--comment-surface-alt);
+ border-color: var(--comment-border-hover);
+}
+
+.da-comments-reaction-active {
+ background: var(--comment-reaction-active-bg);
+ border-color: var(--comment-reaction-active-border);
+}
+
+.da-comments-reaction-emoji {
+ font-size: 14px;
+ line-height: 1;
+}
+
+.da-comments-reaction-count {
+ font-size: 12px;
+ color: var(--comment-text-muted);
+ font-weight: 500;
+}
+
+.da-comments-reaction-picker-wrapper {
+ position: relative;
+}
+
+.da-comments-reaction-add {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ padding: 0;
+ border: 1px dashed var(--comment-border-hover);
+ border-radius: 50%;
+ background: transparent;
+ cursor: pointer;
+ color: var(--comment-text-placeholder);
+ transition: all 0.15s;
+}
+
+.da-comments-reaction-add:hover {
+ background: var(--comment-surface-alt);
+ border-color: var(--comment-border-hover);
+ color: var(--comment-text-muted);
+}
+
+.da-comments-reaction-picker {
+ position: absolute;
+ bottom: 100%;
+ left: 0;
+ display: flex;
+ gap: 4px;
+ padding: 8px;
+ background: var(--comment-surface);
+ border: 1px solid var(--comment-border);
+ border-radius: 8px;
+ box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
+ z-index: 100;
+ margin-bottom: 4px;
+}
+
+.da-comments-reaction-picker-item {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 32px;
+ height: 32px;
+ padding: 0;
+ border: none;
+ border-radius: 6px;
+ background: transparent;
+ cursor: pointer;
+ font-size: 18px;
+ transition: background 0.15s;
+}
+
+.da-comments-reaction-picker-item:hover {
+ background: var(--comment-surface-alt);
+}
+
+.da-comments-icon {
+ display: inline-block;
+ flex-shrink: 0;
+}
+
+.da-comments-icon-checkmark {
+ width: 18px;
+ height: 18px;
+ background-color: currentcolor;
+ mask: url('/blocks/edit/img/Smock_Checkmark_18_N.svg') center / contain no-repeat;
+}
+
+.da-comments-icon-chevron-left {
+ width: 18px;
+ height: 18px;
+ background-color: currentcolor;
+ mask: url('/blocks/browse/img/Smock_ChevronLeft_18_N.svg') center / contain no-repeat;
+}
+
+.da-comments-icon-add {
+ width: 18px;
+ height: 18px;
+ background-color: currentcolor;
+ mask: url('/blocks/edit/img/Smock_Add_18_N.svg') center / contain no-repeat;
+}
+
+.da-comments-icon-more {
+ width: 20px;
+ height: 20px;
+ background-color: currentcolor;
+ mask: url('/blocks/edit/img/S2_Icon_More_20_N.svg') center / contain no-repeat;
+}
+
+.da-comments-icon-reaction {
+ width: 16px;
+ height: 16px;
+ background-color: currentcolor;
+ mask: url('/blocks/edit/img/Smock_AddCircle_18_N.svg') center / contain no-repeat;
+}
+
+.da-comments-icon-detached {
+ width: 20px;
+ height: 20px;
+ background-color: var(--s2-orange-800);
+ mask: url('/blocks/edit/img/S2_Icon_AlertTriangle_20_N.svg') center / contain no-repeat;
+}
+
+.da-comments-detached-badge {
+ position: absolute;
+ top: 12px;
+ right: 12px;
+}
+
+.da-comments-compose-anchor-preview {
+ display: flex;
+ gap: 6px;
+ align-items: baseline;
+ margin: 0 0 12px;
+ padding: 8px 12px;
+ background: var(--s2-gray-50);
+ border-left: 2px solid var(--s2-blue-800);
+ font-size: 11px;
+ color: var(--s2-gray-700);
+ min-width: 0;
+}
+
+.da-comments-compose-anchor-label {
+ font-weight: 600;
+ color: var(--s2-gray-800);
+ flex-shrink: 0;
+}
+
+.da-comments-compose-anchor-text {
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ min-width: 0;
+ font-style: italic;
+}
\ No newline at end of file
diff --git a/blocks/edit/da-comments/da-comments.js b/blocks/edit/da-comments/da-comments.js
new file mode 100644
index 000000000..dc549239f
--- /dev/null
+++ b/blocks/edit/da-comments/da-comments.js
@@ -0,0 +1,691 @@
+import { LitElement, html, nothing, createRef, ref } from 'da-lit';
+import getSheet from '../../shared/sheet.js';
+import * as formatUtils from './helpers/format-utils.js';
+import * as reactionUtils from './helpers/reaction-utils.js';
+import * as mutations from './helpers/comment-mutations.js';
+import { generateColor } from '../../shared/utils.js';
+import { buildThreadGroups, findThreadIdForComment } from './helpers/thread-utils.js';
+import { buildDeepLinkUrl, parseDeepLink } from './helpers/deep-link.js';
+
+const sheet = await getSheet('/blocks/edit/da-comments/da-comments.css');
+
+const IS_MAC = /Mac|iPhone|iPad/.test(navigator.userAgent);
+const COMMENT_SHORTCUT = IS_MAC ? '⌘ + Option + M' : 'Ctrl + Alt + M';
+const SUBMIT_SHORTCUT = IS_MAC ? '⌘ + Enter' : 'Ctrl + Enter';
+
+export default class DaComments extends LitElement {
+ static properties = {
+ controller: { attribute: false },
+ currentUser: { state: true },
+ _activeTab: { state: true },
+ _draft: { state: true },
+ _openMenuId: { state: true },
+ _openReactionId: { state: true },
+ _pendingDelete: { state: true },
+ _toast: { state: true },
+ };
+
+ _popoverHostRef = createRef();
+
+ constructor() {
+ super();
+ this._activeTab = 'active';
+ }
+
+ get activeThreadCount() {
+ return this.controller?.counts?.active ?? 0;
+ }
+
+ willUpdate(changedProps) {
+ if (changedProps.has('controller')) {
+ if (this.controller) this.recomputeThreadGroups();
+ else this._threadGroups = null;
+ }
+ this.syncDraftFromPendingAnchor();
+ }
+
+ recomputeThreadGroups() {
+ this._threadGroups = buildThreadGroups({
+ ymap: this.controller?.ymap,
+ attachedIds: this.controller?.getAttachedThreadIds() ?? null,
+ });
+ }
+
+ syncDraftFromPendingAnchor() {
+ if (!this.controller) return;
+ if (!this.controller.panelOpen) return;
+ const pending = this.controller.pendingAnchor;
+ if (!pending) return;
+ if (this._draft?.mode === 'new') return;
+ this._draft = { mode: 'new', anchorData: pending, text: '' };
+ this._activeTab = 'active';
+ }
+
+ setupObservers() {
+ this.teardownObservers();
+ if (!this.controller) return;
+
+ this._unsubController = this.controller.subscribe(({ reason }) => {
+ if (reason === 'counts' || reason === 'docChange' || reason === 'init') {
+ this.recomputeThreadGroups();
+ }
+ if (reason === 'panelOpen' && !this.controller.panelOpen) {
+ this._draft = null;
+ }
+ this.requestUpdate();
+ });
+
+ const awareness = this.controller.wsProvider?.awareness;
+ if (awareness) {
+ this._syncUserFromAwareness = () => {
+ this.currentUser = awareness.getLocalState()?.user ?? null;
+ };
+ this._syncUserFromAwareness();
+ awareness.on('update', this._syncUserFromAwareness);
+ }
+ }
+
+ teardownObservers() {
+ this._unsubController?.();
+ this._unsubController = null;
+ if (this._syncUserFromAwareness) {
+ this.controller?.wsProvider?.awareness?.off('update', this._syncUserFromAwareness);
+ this._syncUserFromAwareness = null;
+ }
+ }
+
+ connectedCallback() {
+ super.connectedCallback();
+ this.shadowRoot.adoptedStyleSheets = [sheet];
+ this.setupObservers();
+ import('../../shared/da-dialog/da-dialog.js');
+ import('../../shared/da-toast/da-toast.js');
+ this.checkUrlForComment();
+ }
+
+ disconnectedCallback() {
+ super.disconnectedCallback();
+ this.teardownObservers();
+ document.removeEventListener('pointerdown', this.handleOutsideClick);
+ }
+
+ handleOutsideClick = (event) => {
+ const path = event.composedPath();
+ const host = this._popoverHostRef.value;
+ if (host && path.includes(host)) return;
+ if (path.some((el) => el?.localName === 'da-dialog')) return;
+ this._openMenuId = null;
+ this._openReactionId = null;
+ };
+
+ handleClose() {
+ if (this._draft) this.cancelDraft();
+ this.controller?.closePanel();
+ this.dispatchEvent(new CustomEvent('close', { bubbles: true, composed: true }));
+ }
+
+ updated(changedProps) {
+ if (changedProps.has('controller')) {
+ this.setupObservers();
+ }
+ if (changedProps.has('_openMenuId') || changedProps.has('_openReactionId')) {
+ const anyOpen = this._openMenuId || this._openReactionId;
+ if (anyOpen) document.addEventListener('pointerdown', this.handleOutsideClick);
+ else document.removeEventListener('pointerdown', this.handleOutsideClick);
+ }
+ if (changedProps.has('_draft') && this._draft) this.focusDraftTextarea();
+ this.resolvePendingCommentLink();
+ }
+
+ async focusDraftTextarea() {
+ await this.updateComplete;
+ const textarea = this.shadowRoot?.querySelector('.da-comment-form sl-textarea');
+ if (!textarea) return;
+ await textarea.updateComplete;
+ const inner = textarea.shadowRoot?.querySelector('textarea');
+ (inner ?? textarea).focus();
+ }
+
+ checkUrlForComment() {
+ const { commentId, cleaned } = parseDeepLink(new URL(window.location.href));
+ if (!commentId) return;
+ this.dispatchEvent(new CustomEvent('requestOpen', { bubbles: true, composed: true }));
+ this._pendingCommentLinkId = commentId;
+ this.resolvePendingCommentLink();
+ window.history.replaceState({}, '', cleaned.toString());
+ }
+
+ resolvePendingCommentLink() {
+ if (!this._pendingCommentLinkId || !this.controller) return;
+ const threadId = findThreadIdForComment({
+ ymap: this.controller.ymap,
+ commentId: this._pendingCommentLinkId,
+ });
+ if (!threadId) return;
+ this._pendingCommentLinkId = null;
+ this.controller.setSelectedThread(threadId);
+
+ requestAnimationFrame(() => {
+ this.controller?.scrollToThread(threadId, { behavior: 'smooth' });
+ });
+ }
+
+ getThreadById(threadId) {
+ if (!threadId || !this._threadGroups) return null;
+ const { active, detached, resolved } = this._threadGroups;
+ return [...active, ...detached, ...resolved].find((t) => t.id === threadId) ?? null;
+ }
+
+ selectThread(threadId) {
+ this.controller?.setSelectedThread(threadId);
+ this.controller?.scrollToThread(threadId);
+ this.cancelDraft();
+ }
+
+ backToList() {
+ this.controller?.setSelectedThread(null);
+ this.cancelDraft();
+ }
+
+ startReplyDraft(rootComment) {
+ this._draft = { mode: 'reply', threadId: rootComment.id, text: '' };
+ }
+
+ startEditDraft(comment) {
+ if (!comment) return;
+ this._draft = { mode: 'edit', commentId: comment.id, text: comment.body };
+ this._openMenuId = null;
+ }
+
+ cancelDraft() {
+ this._draft = null;
+ this._openMenuId = null;
+ this._openReactionId = null;
+ this.controller?.clearPendingAnchor();
+ }
+
+ updateDraftText(event) {
+ if (!this._draft) return;
+ this._draft = { ...this._draft, text: event.target.value };
+ }
+
+ handleDraftKeydown(event) {
+ if (event.key === 'Escape') this.cancelDraft();
+ if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
+ event.preventDefault();
+ this.submitDraft(event);
+ }
+ }
+
+ submitDraft(event) {
+ event.preventDefault();
+ const body = this._draft?.text?.trim();
+ if (!body || !this.currentUser) return;
+
+ const { ymap } = this.controller;
+ const user = this.currentUser;
+ const draft = this._draft;
+
+ if (draft.mode === 'new') {
+ const id = mutations.createRootComment({ ymap, user, anchor: draft.anchorData, body });
+ this.controller.setSelectedThread(id);
+ } else if (draft.mode === 'reply') {
+ mutations.createReply({ ymap, user, threadId: draft.threadId, body });
+ } else if (draft.mode === 'edit') {
+ mutations.updateBody({ ymap, commentId: draft.commentId, body });
+ }
+
+ this.controller.clearPendingAnchor();
+ this._draft = null;
+ }
+
+ deleteComment(commentId) {
+ mutations.deleteComment({ ymap: this.controller.ymap, commentId });
+ if (this.controller.selectedThreadId === commentId) {
+ this.controller.setSelectedThread(null);
+ }
+ }
+
+ handleResolveThread(threadId) {
+ mutations.resolveThread({
+ ymap: this.controller.ymap,
+ threadId,
+ user: this.currentUser,
+ });
+ this.cancelDraft();
+ }
+
+ handleUnresolveThread(threadId) {
+ mutations.unresolveThread({ ymap: this.controller.ymap, threadId, user: this.currentUser });
+ this._activeTab = 'active';
+ }
+
+ handleDeleteComment(commentId, threadId = this.controller?.selectedThreadId) {
+ this._openMenuId = null;
+ const thread = this.getThreadById(threadId);
+ if (!thread) return;
+
+ if (thread.id === commentId && thread.replies.length > 0) {
+ this._pendingDelete = { commentId };
+ return;
+ }
+ this.deleteComment(commentId);
+ }
+
+ handleConfirmDeleteComment() {
+ if (!this._pendingDelete) return;
+ this.deleteComment(this._pendingDelete.commentId);
+ this._pendingDelete = null;
+ }
+
+ handleDeleteThread(threadId) {
+ this.deleteComment(threadId);
+ this.cancelDraft();
+ this._activeTab = 'active';
+ }
+
+ toggleMenu(commentId, event) {
+ if (event) event.stopPropagation();
+ this._openMenuId = this._openMenuId === commentId ? null : commentId;
+ this._openReactionId = null;
+ }
+
+ toggleReactionPicker(commentId, event) {
+ if (event) event.stopPropagation();
+ this._openReactionId = this._openReactionId === commentId ? null : commentId;
+ this._openMenuId = null;
+ }
+
+ handleReaction(comment, emoji) {
+ if (!this.currentUser) return;
+ reactionUtils.toggleReaction({
+ ymap: this.controller.ymap,
+ threadId: comment.id,
+ emoji,
+ user: this.currentUser,
+ });
+ this._openReactionId = null;
+ }
+
+ canEditComment(comment) {
+ if (!comment || !this.currentUser) return false;
+ return this.currentUser.id === comment.author?.id;
+ }
+
+ copyThreadLink(threadId = this.controller?.selectedThreadId) {
+ if (!threadId) return;
+ const url = buildDeepLinkUrl(new URL(window.location.href), threadId);
+ this._openMenuId = null;
+ navigator.clipboard.writeText(url.toString())
+ .then(() => {
+ this._toast = { text: 'Copied', description: 'The link was copied to the clipboard.' };
+ })
+ .catch(() => {
+ this._toast = { text: 'Error', description: 'Could not copy link to clipboard.', type: 'error' };
+ });
+ }
+
+ _avatarColorCache = new Map();
+
+ renderAvatar(author) {
+ const key = author.email || author.id || '';
+ let color = author.color ?? this._avatarColorCache.get(key);
+ if (!color) {
+ color = generateColor(key);
+ this._avatarColorCache.set(key, color);
+ }
+ return html`
+
+ `;
+ }
+
+ renderForm({
+ placeholder, submitLabel, value, formClass = '', showActions = true, onFocus,
+ }) {
+ return html`
+
+ `;
+ }
+
+ renderCommentMenu(comment, threadId, isRoot, canEdit) {
+ if (!canEdit && !isRoot) return nothing;
+ const isOpen = this._openMenuId === comment.id;
+
+ return html`
+
+ `;
+ }
+
+ renderReactions(comment, { reactionsList, isResolved = false, showPicker = true } = {}) {
+ const list = reactionsList ?? reactionUtils.getReactionsList(comment);
+ const isPickerOpen = this._openReactionId === comment.id;
+ const canReact = !isResolved && this.currentUser;
+
+ return html`
+
+ `;
+ }
+
+ renderDetachedReference(comment) {
+ if (comment.anchorType === 'image') {
+ return html``;
+ }
+ if (comment.anchorType === 'table') {
+ const preview = formatUtils.formatAnchorPreview(comment);
+ if (preview === 'a table') {
+ return html``;
+ }
+ return html``;
+ }
+ if (!comment.anchorText) return nothing;
+ return html``;
+ }
+
+ renderComment({
+ comment, threadId, isRoot = false, isResolved = false,
+ isDetached = false, isPreview = false,
+ }) {
+ const isEditing = this._draft?.mode === 'edit'
+ && this._draft?.commentId === comment.id;
+ const canEdit = this.canEditComment(comment);
+ const reactionsList = !isPreview ? reactionUtils.getReactionsList(comment) : [];
+ const showMenu = !isPreview && !isEditing && !isResolved && (isRoot || canEdit);
+ const showResolve = !isPreview && isRoot && !isEditing && !isResolved && !!this.currentUser;
+ const showReactions = !isPreview
+ && (reactionsList.length > 0 || (!isResolved && this.currentUser));
+
+ return html`
+
+ `;
+ }
+
+ renderListView(viewModel) {
+ if (this._draft?.mode === 'new' && this.currentUser) {
+ const preview = formatUtils.formatAnchorPreview(this._draft.anchorData);
+ return html`
+
+ `;
+ }
+
+ if (!this.controller) {
+ return html``;
+ }
+
+ const { tabCounts, visibleThreads } = viewModel;
+ const tabs = [
+ { id: 'active', label: 'Active', count: tabCounts.active },
+ { id: 'resolved', label: 'Resolved', count: tabCounts.resolved },
+ ].filter((t) => t.count > 0 || t.id === 'active');
+
+ return html`
+
+ `;
+ }
+
+ renderStatusLine(label, user, at) {
+ if (!user) return nothing;
+ return html`
+
+ `;
+ }
+
+ renderThreadPreview(thread) {
+ const { id: threadId, replies, isDetached, isResolved } = thread;
+ return html`
+
+
+
+ `;
+ }
+
+ renderThreadView(thread) {
+ const { id: threadId, replies, isDetached, isResolved } = thread;
+ const isReplying = this._draft?.mode === 'reply'
+ && this._draft?.threadId === threadId;
+
+ return html`
+
+ `;
+ }
+
+ renderConfirmDeleteDialog() {
+ if (!this._pendingDelete) return nothing;
+ return html`
+ this.handleConfirmDeleteComment() }}
+ @close=${() => { this._pendingDelete = null; }}>
+ Deleting the comment will remove the entire thread.
+
+ `;
+ }
+
+ render() {
+ const { active, detached, resolved } = this._threadGroups
+ ?? { active: [], detached: [], resolved: [] };
+ const activeThreads = [...active, ...detached];
+ const visibleThreads = this._activeTab === 'resolved' ? resolved : activeThreads;
+ const tabCounts = { active: activeThreads.length, resolved: resolved.length };
+
+ const selectedThread = this.getThreadById(this.controller?.selectedThreadId);
+ const content = selectedThread
+ ? this.renderThreadView(selectedThread)
+ : this.renderListView({ visibleThreads, tabCounts });
+
+ const isComposing = this._draft?.mode === 'new' && this.currentUser;
+ const isPinned = isComposing || Boolean(selectedThread);
+
+ return html`
+
+ ${this.renderConfirmDeleteDialog()}
+ { this._toast = null; }}>
+ `;
+ }
+}
+
+customElements.define('da-comments', DaComments);
diff --git a/blocks/edit/da-comments/helpers/comment-mutations.js b/blocks/edit/da-comments/helpers/comment-mutations.js
new file mode 100644
index 000000000..f79d4e522
--- /dev/null
+++ b/blocks/edit/da-comments/helpers/comment-mutations.js
@@ -0,0 +1,79 @@
+export function createRootComment({ ymap, user, anchor, body, now = Date.now() }) {
+ const id = crypto.randomUUID();
+ ymap.set(id, {
+ id,
+ threadId: id,
+ parentId: null,
+ ...anchor,
+ author: user,
+ body,
+ createdAt: now,
+ edited: false,
+ editedAt: null,
+ resolved: false,
+ resolvedBy: null,
+ resolvedAt: null,
+ reactions: {},
+ });
+ return id;
+}
+
+export function createReply({ ymap, threadId, user, body, now = Date.now() }) {
+ const id = crypto.randomUUID();
+ ymap.set(id, {
+ id,
+ threadId,
+ parentId: threadId,
+ author: user,
+ body,
+ createdAt: now,
+ edited: false,
+ editedAt: null,
+ });
+ return id;
+}
+
+export function updateBody({ ymap, commentId, body, now = Date.now() }) {
+ const comment = ymap.get(commentId);
+ if (!comment) return;
+ ymap.set(commentId, { ...comment, body, edited: true, editedAt: now });
+}
+
+export function resolveThread({ ymap, threadId, user, now = Date.now() }) {
+ const comment = ymap.get(threadId);
+ if (!comment) return;
+ ymap.set(threadId, {
+ ...comment,
+ resolved: true,
+ resolvedBy: { id: user.id, name: user.name },
+ resolvedAt: now,
+ reopenedBy: null,
+ reopenedAt: null,
+ });
+}
+
+export function unresolveThread({ ymap, threadId, user, now = Date.now() }) {
+ const comment = ymap.get(threadId);
+ if (!comment) return;
+ ymap.set(threadId, {
+ ...comment,
+ resolved: false,
+ resolvedBy: null,
+ resolvedAt: null,
+ reopenedBy: { id: user.id, name: user.name },
+ reopenedAt: now,
+ });
+}
+
+export function deleteComment({ ymap, commentId }) {
+ const comment = ymap.get(commentId);
+ if (!comment) return;
+ if (comment.parentId == null) {
+ const replyIds = [];
+ ymap.forEach((entry, id) => {
+ if (entry.threadId === commentId && entry.parentId) replyIds.push(id);
+ });
+ replyIds.forEach((id) => ymap.delete(id));
+ }
+ ymap.delete(commentId);
+}
diff --git a/blocks/edit/da-comments/helpers/deep-link.js b/blocks/edit/da-comments/helpers/deep-link.js
new file mode 100644
index 000000000..0f868e9b5
--- /dev/null
+++ b/blocks/edit/da-comments/helpers/deep-link.js
@@ -0,0 +1,13 @@
+export function buildDeepLinkUrl(url, commentId) {
+ const out = new URL(url.toString());
+ out.searchParams.set('comment', commentId);
+ return out;
+}
+
+export function parseDeepLink(url) {
+ const commentId = url.searchParams.get('comment');
+ if (!commentId) return { commentId: null, cleaned: url };
+ const cleaned = new URL(url.toString());
+ cleaned.searchParams.delete('comment');
+ return { commentId, cleaned };
+}
diff --git a/blocks/edit/da-comments/helpers/format-utils.js b/blocks/edit/da-comments/helpers/format-utils.js
new file mode 100644
index 000000000..57dfa1017
--- /dev/null
+++ b/blocks/edit/da-comments/helpers/format-utils.js
@@ -0,0 +1,71 @@
+export function formatTimestamp(timestamp) {
+ const date = new Date(timestamp);
+ const now = new Date();
+ const diffMs = now - date;
+ const diffMins = Math.floor(diffMs / 60000);
+ const diffHours = Math.floor(diffMs / 3600000);
+ const diffDays = Math.floor(diffMs / 86400000);
+
+ if (diffMins < 1) return 'Just now';
+ if (diffMins < 60) return `${diffMins}m ago`;
+ if (diffHours < 24) return `${diffHours}h ago`;
+ if (diffDays < 7) return `${diffDays}d ago`;
+
+ return date.toLocaleDateString(undefined, {
+ month: 'short',
+ day: 'numeric',
+ year: date.getFullYear() !== now.getFullYear() ? 'numeric' : undefined,
+ });
+}
+
+export function formatFullTimestamp(timestamp) {
+ const date = new Date(timestamp);
+ return date.toLocaleString(undefined, {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit',
+ timeZoneName: 'short',
+ });
+}
+
+export function formatAnchorPreview(anchor) {
+ if (!anchor) return '';
+ if (anchor.anchorType === 'image') return 'an image';
+ if (anchor.anchorType === 'table') {
+ const text = (anchor.anchorText || '').trim();
+ return text || 'a table';
+ }
+ const text = (anchor.anchorText || '').trim();
+ if (!text) return '';
+ const truncated = text.length > 80 ? `${text.slice(0, 80).trim()}…` : text;
+ return `"${truncated}"`;
+}
+
+export function getInitials(name) {
+ if (!name) return '?';
+ const parts = name.split(' ').filter(Boolean);
+ if (parts.length === 0) return '?';
+ if (parts.length === 1) return parts[0].substring(0, 2).toUpperCase();
+ return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
+}
+
+export function getReplySummary({ rootComment, replies }) {
+ const uniqueAuthors = [];
+ const seen = new Set();
+
+ replies.forEach((reply) => {
+ const authorId = reply.author?.id;
+ if (!authorId || authorId === rootComment.author?.id || seen.has(authorId)) return;
+ seen.add(authorId);
+ uniqueAuthors.push(reply.author.name);
+ });
+
+ if (uniqueAuthors.length === 0) return '';
+ if (uniqueAuthors.length === 1) return ` from ${uniqueAuthors[0]}`;
+ if (uniqueAuthors.length === 2) return ` from ${uniqueAuthors[0]} and ${uniqueAuthors[1]}`;
+
+ const remainingCount = uniqueAuthors.length - 2;
+ return ` from ${uniqueAuthors[0]}, ${uniqueAuthors[1]} and ${remainingCount} ${remainingCount === 1 ? 'other' : 'others'}`;
+}
diff --git a/blocks/edit/da-comments/helpers/reaction-utils.js b/blocks/edit/da-comments/helpers/reaction-utils.js
new file mode 100644
index 000000000..f7b18d90c
--- /dev/null
+++ b/blocks/edit/da-comments/helpers/reaction-utils.js
@@ -0,0 +1,25 @@
+export const REACTION_EMOJIS = ['👍', '❤️', '🎉', '🚀', '🥳', '✅'];
+
+export function hasUserReacted({ comment, emoji, userId }) {
+ return comment.reactions?.[emoji]?.some((r) => r.userId === userId) || false;
+}
+
+export function toggleReaction({ ymap, threadId, emoji, user }) {
+ const comment = ymap.get(threadId);
+ if (!comment) return;
+ const reactions = { ...(comment.reactions || {}) };
+ const list = reactions[emoji] || [];
+ const reacted = list.some((r) => r.userId === user.id);
+ reactions[emoji] = reacted
+ ? list.filter((r) => r.userId !== user.id)
+ : [...list, { userId: user.id, name: user.name }];
+ if (reactions[emoji].length === 0) delete reactions[emoji];
+ ymap.set(threadId, { ...comment, reactions });
+}
+
+export function getReactionsList(comment) {
+ if (!comment.reactions) return [];
+ return Object.entries(comment.reactions)
+ .filter(([, users]) => users.length > 0)
+ .map(([emoji, users]) => ({ emoji, users, count: users.length }));
+}
diff --git a/blocks/edit/da-comments/helpers/thread-utils.js b/blocks/edit/da-comments/helpers/thread-utils.js
new file mode 100644
index 000000000..2a2a6ec88
--- /dev/null
+++ b/blocks/edit/da-comments/helpers/thread-utils.js
@@ -0,0 +1,45 @@
+export function buildThreadGroups({ ymap, attachedIds }) {
+ if (!ymap) return { active: [], detached: [], resolved: [] };
+
+ const roots = new Map();
+ const replyGroups = new Map();
+
+ ymap.forEach((comment) => {
+ if (!comment.parentId) {
+ roots.set(comment.id, comment);
+ } else {
+ const group = replyGroups.get(comment.threadId) ?? [];
+ group.push(comment);
+ replyGroups.set(comment.threadId, group);
+ }
+ });
+
+ const active = [];
+ const detached = [];
+ const resolved = [];
+
+ roots.forEach((root) => {
+ const replies = (replyGroups.get(root.id) ?? [])
+ .sort((a, b) => a.createdAt - b.createdAt);
+
+ if (root.resolved) {
+ resolved.push({ ...root, replies, isDetached: false, isResolved: true });
+ } else if (attachedIds == null || attachedIds.has(root.id)) {
+ active.push({ ...root, replies, isDetached: false, isResolved: false });
+ } else {
+ detached.push({ ...root, replies, isDetached: true, isResolved: false });
+ }
+ });
+
+ active.sort((a, b) => b.createdAt - a.createdAt);
+ detached.sort((a, b) => b.createdAt - a.createdAt);
+ resolved.sort((a, b) => b.resolvedAt - a.resolvedAt);
+
+ return { active, detached, resolved };
+}
+
+export function findThreadIdForComment({ ymap, commentId }) {
+ const entry = ymap?.get(commentId);
+ if (!entry) return null;
+ return entry.threadId;
+}
diff --git a/blocks/edit/da-content/da-content.css b/blocks/edit/da-content/da-content.css
index 3eaeb2987..e03b50ca6 100644
--- a/blocks/edit/da-content/da-content.css
+++ b/blocks/edit/da-content/da-content.css
@@ -29,7 +29,9 @@ da-version {
}
da-preview,
-da-versions {
+da-versions,
+da-comments {
+ display: none;
visibility: hidden;
position: absolute;
width: 0;
@@ -38,6 +40,7 @@ da-versions {
justify-self: right;
&.is-visible {
+ display: block;
visibility: unset;
position: relative;
width: unset;
@@ -88,6 +91,29 @@ da-versions {
background: url("/blocks/edit/img/S2_icon_OpenIn_20_N.svg") center center / 20px no-repeat;
}
+.da-editor-tab.show-comments {
+ position: relative;
+ background: url("/blocks/edit/img/S2_icon_Comment_20_N.svg") center center / 20px no-repeat;
+}
+
+.da-comment-badge {
+ position: absolute;
+ top: 4px;
+ right: 4px;
+ min-width: 14px;
+ height: 14px;
+ padding: 0 3px;
+ background: var(--spectrum-blue-800);
+ color: #fff;
+ font-size: 10px;
+ font-weight: 700;
+ line-height: 14px;
+ text-align: center;
+ text-indent: 0;
+ border-radius: 7px;
+ box-sizing: border-box;
+}
+
.da-preview-menuitem.show-preview:hover {
background-color: var(--editor-btn-bg-color-hover) !important;
}
diff --git a/blocks/edit/da-content/da-content.js b/blocks/edit/da-content/da-content.js
index c59ccf7a6..2a89e3fcc 100644
--- a/blocks/edit/da-content/da-content.js
+++ b/blocks/edit/da-content/da-content.js
@@ -12,6 +12,7 @@ export default class DaContent extends LitElement {
permissions: { attribute: false },
proseEl: { attribute: false },
wsProvider: { attribute: false },
+ commentsController: { attribute: false },
_editorLoaded: { state: true },
_showPane: { state: true },
_versionUrl: { state: true },
@@ -21,6 +22,33 @@ export default class DaContent extends LitElement {
connectedCallback() {
super.connectedCallback();
this.shadowRoot.adoptedStyleSheets = [sheet];
+
+ this._keydownHandler = (e) => {
+ if ((e.metaKey || e.ctrlKey) && e.altKey && e.code === 'KeyM') {
+ e.preventDefault();
+ const hasSelection = this.commentsController?.hasSelection;
+ if (this._showPane === 'comments' && !hasSelection) {
+ this.togglePane({ detail: null });
+ return;
+ }
+ this.commentsController?.requestCompose();
+ this._showPane = 'comments';
+ }
+ };
+
+ window.addEventListener('keydown', this._keydownHandler);
+ }
+
+ disconnectedCallback() {
+ super.disconnectedCallback();
+ window.removeEventListener('keydown', this._keydownHandler);
+ this.teardownCommentsObservers();
+ }
+
+ renderCommentBadge() {
+ const count = this.commentsController?.counts?.active ?? 0;
+ const label = this.commentsController?.hasSelection ? '+' : count;
+ return label ? html`` : nothing;
}
disconnectWebsocket() {
@@ -31,12 +59,12 @@ export default class DaContent extends LitElement {
}
async loadViews() {
- // Only import the web components once
if (this._editorLoaded) return;
const preview = import('../da-preview/da-preview.js');
const versions = import('../da-versions/da-versions.js');
- await Promise.all([preview, versions]);
+ const comments = import('../da-comments/da-comments.js');
+ await Promise.all([preview, versions, comments]);
this._editorLoaded = true;
}
@@ -58,6 +86,28 @@ export default class DaContent extends LitElement {
window.location = this._externalUrl;
}
+ setupCommentsObservers() {
+ this.teardownCommentsObservers();
+ if (!this.commentsController) return;
+ this._unsubscribeCommentsController = this.commentsController.subscribe(() => {
+ this.requestUpdate();
+ });
+ }
+
+ teardownCommentsObservers() {
+ this._unsubscribeCommentsController?.();
+ this._unsubscribeCommentsController = null;
+ }
+
+ handleToggleComments() {
+ if (this._showPane === 'comments') {
+ this.togglePane({ detail: null });
+ return;
+ }
+ this.commentsController?.requestCompose();
+ this._showPane = 'comments';
+ }
+
togglePane({ detail }) {
this._showPane = detail;
}
@@ -70,6 +120,14 @@ export default class DaContent extends LitElement {
this._versionUrl = detail.url;
}
+ updated(changedProps) {
+ if (changedProps.has('commentsController')) this.setupCommentsObservers();
+ if (changedProps.has('_showPane') && this.commentsController) {
+ if (this._showPane === 'comments') this.commentsController.setPanelOpen(true);
+ else this.commentsController.setPanelOpen(false);
+ }
+ }
+
render() {
const { owner, repo, previewUrl } = this.details;
const { pathname } = new URL(previewUrl);
@@ -83,7 +141,8 @@ export default class DaContent extends LitElement {
.proseEl=${this.proseEl}
.wsProvider=${this.wsProvider}
@proseloaded=${this.handleEditorLoaded}
- @versionreset=${this.handleVersionReset}>
+ @versionreset=${this.handleVersionReset}
+ @togglecomments=${this.handleToggleComments}>
${this._editorLoaded ? html`
@@ -95,6 +154,13 @@ export default class DaContent extends LitElement {
${this._externalUrl ? html`` : nothing}
+
` : nothing}
@@ -111,6 +177,11 @@ export default class DaContent extends LitElement {
class="${this._showPane === 'versions' ? 'is-visible' : ''}"
@preview=${this.handleVersionPreview}
@close=${this.togglePane}>
+
` : nothing}
`;
}
diff --git a/blocks/edit/da-editor/da-editor.css b/blocks/edit/da-editor/da-editor.css
index d6352c37a..83ea44da5 100644
--- a/blocks/edit/da-editor/da-editor.css
+++ b/blocks/edit/da-editor/da-editor.css
@@ -7,6 +7,12 @@
.da-prose-mirror {
--editor-btn-bg-color: #EFEFEF;
--editor-btn-bg-color-hover: var(--s2-blue-900);
+ --comment-highlight-bg: #fbf198; /* spectrum-yellow-100 */
+ --comment-highlight-bg-active: #f8d904; /* spectrum-yellow-300 */
+ --comment-highlight-border: #f8d904; /* spectrum-yellow-300 */
+ --comment-highlight-border-active: #e8c600; /* spectrum-yellow-400 */
+ --comment-pending-bg: #ffe9fc; /* spectrum-fuchsia-100 */
+ --comment-pending-border: #ed74ed; /* spectrum-fuchsia-600 */
position: relative;
grid-area: editor;
@@ -1008,3 +1014,42 @@ da-diff-deleted, da-diff-added {
background-color: #f0f7ff;
border-color: var(--s2-blue-800);
}
+
+.da-comment-highlight {
+ --da-comment-bg: var(--comment-highlight-bg);
+ --da-comment-border-color: var(--comment-highlight-border);
+ --da-comment-border-style: solid;
+
+ background-color: var(--da-comment-bg);
+ border-bottom: 2px var(--da-comment-border-style) var(--da-comment-border-color);
+ cursor: pointer;
+ transition: background-color 0.2s, box-shadow 0.2s;
+
+ &:has(> img) {
+ padding: 6px;
+ }
+}
+
+.da-comment-highlight-active {
+ --da-comment-bg: var(--comment-highlight-bg-active);
+ --da-comment-border-color: var(--comment-highlight-border-active);
+}
+
+.da-comment-highlight-pending {
+ --da-comment-bg: var(--comment-pending-bg);
+ --da-comment-border-color: var(--comment-pending-border);
+ --da-comment-border-style: dashed;
+}
+
+.ProseMirror .da-comment-highlight tr:first-child td,
+.ProseMirror .da-comment-highlight tr:first-child th {
+ background-color: var(--da-comment-bg);
+}
+
+img.da-comment-highlight {
+ pointer-events: auto;
+ box-shadow:
+ 0 0 0 6px var(--da-comment-bg),
+ 0 2px 0 6px var(--da-comment-border-color);
+}
+
diff --git a/blocks/edit/da-library/helpers/index.js b/blocks/edit/da-library/helpers/index.js
index ffa524d57..1a3d74474 100644
--- a/blocks/edit/da-library/helpers/index.js
+++ b/blocks/edit/da-library/helpers/index.js
@@ -79,6 +79,8 @@ async function fetchAndParseHtml(path, isAemHosted) {
const parser = new DOMParser();
return parser.parseFromString(html, 'text/html');
} catch (e) {
+ // eslint-disable-next-line no-console
+ console.log(e);
return null;
}
}
diff --git a/blocks/edit/img/S2_icon_Comment_20_N.svg b/blocks/edit/img/S2_icon_Comment_20_N.svg
new file mode 100644
index 000000000..6fc3c8dc5
--- /dev/null
+++ b/blocks/edit/img/S2_icon_Comment_20_N.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js
index ff7408a00..29cd961a7 100644
--- a/blocks/edit/prose/index.js
+++ b/blocks/edit/prose/index.js
@@ -24,9 +24,10 @@ import {
import { getSchema } from 'da-parser';
import { COLLAB_ORIGIN, DA_ORIGIN } from '../../shared/constants.js';
-import { daFetch, getAuthToken } from '../../shared/utils.js';
+import { daFetch, generateColor, getAuthToken } from '../../shared/utils.js';
import { getDiffClass, checkForLocNodes, addActiveView } from './diff/diff-utils.js';
import { debounce, initDaMetadata } from '../utils/helpers.js';
+import { createCommentsController } from './plugins/comments/helpers/controller.js';
async function checkDoc(path) {
return daFetch(path, { method: 'HEAD' });
@@ -73,6 +74,7 @@ async function loadCustomPlugins() {
{ default: toggleLibrary },
{ default: slashMenu },
{ default: linkMenu },
+ { default: commentPlugin },
] = await Promise.all([
import('./plugins/keyHandlers.js'),
import('./plugins/menu/menu.js'),
@@ -88,6 +90,7 @@ async function loadCustomPlugins() {
import('../da-library/da-library.js'),
import('./plugins/slashMenu/slashMenu.js'),
import('./plugins/linkMenu/linkMenu.js'),
+ import('./plugins/comments/commentPlugin.js'),
]);
return {
@@ -106,6 +109,7 @@ async function loadCustomPlugins() {
toggleLibrary,
slashMenu,
linkMenu,
+ commentPlugin,
};
}
@@ -308,26 +312,6 @@ function registerErrorHandler(ydoc) {
});
}
-function generateColor(name, hRange = [0, 360], sRange = [60, 80], lRange = [40, 60]) {
- let hash = 0;
- for (let i = 0; i < name.length; i += 1) {
- // eslint-disable-next-line no-bitwise
- hash = name.charCodeAt(i) + ((hash << 5) - hash);
- }
- hash = Math.abs(hash);
- const normalizeHash = (min, max) => Math.floor((hash % (max - min)) + min);
- const h = normalizeHash(hRange[0], hRange[1]);
- const s = normalizeHash(sRange[0], sRange[1]);
- const l = normalizeHash(lRange[0], lRange[1]) / 100;
- const a = (s * Math.min(l, 1 - l)) / 100;
- const f = (n) => {
- const k = (n + h / 30) % 12;
- const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
- return Math.round(255 * color).toString(16).padStart(2, '0');
- };
- return `#${f(0)}${f(8)}${f(4)}`;
-}
-
function storeCursorPosition(view) {
const { from, to } = view.state.selection;
lastCursorPosition = { from, to };
@@ -356,12 +340,9 @@ function addSyncedListener(wsProvider, canWrite) {
});
}
-function applyDelayedPlugins(pluginsPromise, schema, canWrite, basePlugins) {
+function applyDelayedPlugins(pluginsPromise, schema, canWrite, basePlugins, commentsController) {
pluginsPromise.then((plugins) => {
- const {
- syncPlugin,
- cursorPlugin,
- } = basePlugins;
+ const { syncPlugin, cursorPlugin } = basePlugins;
const undoPlugin = yUndoPlugin();
const trackPlugin = trackCursorAndChanges();
@@ -375,6 +356,7 @@ function applyDelayedPlugins(pluginsPromise, schema, canWrite, basePlugins) {
cursorPlugin,
undoPlugin,
trackPlugin,
+ plugins.commentPlugin(commentsController),
plugins.slashMenu(),
plugins.linkMenu(),
plugins.tableSelectHandle(),
@@ -466,6 +448,9 @@ export default async function initProse({ path, permissions, doc, daContent, wsP
});
}
+ const ymap = ydoc.getMap('comments');
+ const commentsController = createCommentsController({ ymap, ydoc, wsProvider });
+
const syncPlugin = ySyncPlugin(yXmlFragment);
const cursorPlugin = yCursorPlugin(wsProvider.awareness);
@@ -501,6 +486,7 @@ export default async function initProse({ path, permissions, doc, daContent, wsP
});
addActiveView(window.view);
+ commentsController.bindView(window.view);
// yMap for storing document metadata (not synced to ProseMirror doc.attrs)
initDaMetadata(ydoc.getMap('daMetadata'));
@@ -511,11 +497,12 @@ export default async function initProse({ path, permissions, doc, daContent, wsP
applyDelayedPlugins(pluginsPromise, schema, canWrite, {
syncPlugin,
cursorPlugin,
- });
+ }, commentsController);
document.execCommand('enableObjectResizing', false, 'false');
document.execCommand('enableInlineTableEditing', false, 'false');
daContent.proseEl = editor;
daContent.wsProvider = wsProvider;
+ daContent.commentsController = commentsController;
}
diff --git a/blocks/edit/prose/plugins/comments/commentPlugin.js b/blocks/edit/prose/plugins/comments/commentPlugin.js
new file mode 100644
index 000000000..2d80345bf
--- /dev/null
+++ b/blocks/edit/prose/plugins/comments/commentPlugin.js
@@ -0,0 +1,251 @@
+import {
+ Plugin,
+ PluginKey,
+ Decoration,
+ DecorationSet,
+ ySyncPluginKey,
+} from 'da-y-wrapper';
+import { decodeAnchor, encodeAnchor } from './helpers/anchor.js';
+
+export const commentPluginKey = new PluginKey('comments');
+
+export const SET_RANGES = 'setRanges';
+export const SET_SELECTED_THREAD = 'setSelectedThread';
+export const SET_PANEL_OPEN = 'setPanelOpen';
+export const SET_PENDING_ANCHOR = 'setPendingAnchor';
+
+export function computeRanges(ymap, state) {
+ const out = new Map();
+ ymap.forEach((comment, id) => {
+ if (comment.parentId != null) return;
+ if (comment.resolved) return;
+ const range = decodeAnchor({ anchor: comment, state });
+ if (range) out.set(id, { ...range, anchorType: comment.anchorType });
+ });
+ return out;
+}
+
+const emptyState = () => ({
+ ranges: new Map(),
+ selectedThreadId: null,
+ panelOpen: false,
+ pendingAnchor: null,
+});
+
+function applyAction(prev, action) {
+ switch (action.type) {
+ case SET_RANGES:
+ if (prev.ranges === action.payload) return prev;
+ return { ...prev, ranges: action.payload };
+ case SET_SELECTED_THREAD: {
+ const next = action.payload ?? null;
+ if (prev.selectedThreadId === next) return prev;
+ return { ...prev, selectedThreadId: next };
+ }
+ case SET_PANEL_OPEN: {
+ const next = Boolean(action.payload);
+ if (prev.panelOpen === next) return prev;
+ return { ...prev, panelOpen: next };
+ }
+ case SET_PENDING_ANCHOR: {
+ const next = action.payload ?? null;
+ if (prev.pendingAnchor === next) return prev;
+ return { ...prev, pendingAnchor: next };
+ }
+ default:
+ return prev;
+ }
+}
+
+function applyPluginMeta(prev, meta) {
+ if (!meta) return prev;
+ if (meta.batch?.length) {
+ return meta.batch.reduce((p, step) => applyAction(p, step), prev);
+ }
+ return applyAction(prev, meta);
+}
+
+function mapRanges(prevRanges, tr) {
+ const next = new Map();
+ prevRanges.forEach((entry, id) => {
+ const from = tr.mapping.map(entry.from, 1);
+ const to = tr.mapping.map(entry.to, 1);
+ if (from < to) next.set(id, { ...entry, from, to });
+ });
+ return next;
+}
+
+function rangesEqual(a, b) {
+ if (a.size !== b.size) return false;
+ let equal = true;
+ a.forEach((va, id) => {
+ if (!equal) return;
+ const vb = b.get(id);
+ if (!vb || vb.from !== va.from || vb.to !== va.to) equal = false;
+ });
+ return equal;
+}
+
+function pushAnchorDecoration(decorations, { from, to, anchorType, spec }) {
+ if (anchorType === 'image' || anchorType === 'table') {
+ decorations.push(Decoration.node(from, to, spec));
+ return;
+ }
+ decorations.push(Decoration.inline(from, to, spec));
+}
+
+function computeRangesWithRescue({ ymap, state, mapped }) {
+ const ranges = new Map();
+ const rescued = [];
+ ymap.forEach((comment, id) => {
+ if (comment.parentId != null) return;
+ if (comment.resolved) return;
+
+ const range = decodeAnchor({ anchor: comment, state });
+ if (range) {
+ ranges.set(id, { ...range, anchorType: comment.anchorType });
+ return;
+ }
+
+ if (comment.anchorType !== 'text' || !comment.anchorText) return;
+ const mappedEntry = mapped?.get(id);
+ if (!mappedEntry) return;
+ const actual = state.doc.textBetween(mappedEntry.from, mappedEntry.to, ' ');
+ if (actual !== comment.anchorText) return;
+ const encoded = encodeAnchor({
+ selectionData: {
+ from: mappedEntry.from,
+ to: mappedEntry.to,
+ anchorType: 'text',
+ anchorText: comment.anchorText,
+ },
+ state,
+ });
+ if (!encoded) return;
+ ranges.set(id, { from: mappedEntry.from, to: mappedEntry.to, anchorType: 'text' });
+ rescued.push({ id, entry: { ...comment, ...encoded } });
+ });
+ return { ranges, rescued };
+}
+
+export default function commentPlugin(controller) {
+ return new Plugin({
+ key: commentPluginKey,
+
+ state: {
+ init() { return emptyState(); },
+ apply(tr, prev, _oldState, newState) {
+ const meta = tr.getMeta(commentPluginKey);
+ let next = meta ? applyPluginMeta(prev, meta) : prev;
+ if (tr.docChanged) {
+ const yMeta = ySyncPluginKey.getState(newState);
+ const mustRebuild = yMeta?.isUndoRedoOperation || yMeta?.isChangeOrigin;
+ const ranges = mustRebuild
+ ? computeRanges(controller.ymap, newState)
+ : mapRanges(next.ranges, tr);
+ next = { ...next, ranges };
+ }
+ return next;
+ },
+ },
+
+ view(editorView) {
+ controller.bindView(editorView);
+
+ const onYmapChange = () => {
+ if (editorView.isDestroyed) return;
+ const ranges = computeRanges(controller.ymap, editorView.state);
+ editorView.dispatch(
+ editorView.state.tr.setMeta(commentPluginKey, { type: SET_RANGES, payload: ranges }),
+ );
+ };
+ controller.ymap.observe(onYmapChange);
+
+ return {
+ update(view, prevState) {
+ const prev = commentPluginKey.getState(prevState);
+ const next = commentPluginKey.getState(view.state);
+ controller.notifyPluginStateChange(prev, next);
+
+ const { from, to } = view.state.selection;
+ controller.setHasSelection(from !== to);
+
+ if (view.state.doc !== prevState.doc) {
+ controller.notifyDocChange();
+ const yMeta = ySyncPluginKey.getState(view.state);
+ const isLocalEdit = !yMeta?.isChangeOrigin && !yMeta?.isUndoRedoOperation;
+ if (isLocalEdit && next?.ranges.size > 0) {
+ const { ranges: fresh, rescued } = computeRangesWithRescue({
+ ymap: controller.ymap,
+ state: view.state,
+ mapped: next.ranges,
+ });
+ if (rescued.length) {
+ controller.ydoc.transact(() => {
+ rescued.forEach(({ id, entry }) => controller.ymap.set(id, entry));
+ });
+ } else if (!rangesEqual(fresh, next.ranges)) {
+ view.dispatch(view.state.tr.setMeta(commentPluginKey, {
+ type: SET_RANGES,
+ payload: fresh,
+ }));
+ }
+ }
+ }
+ },
+ destroy() {
+ controller.ymap.unobserve(onYmapChange);
+ controller.bindView(null);
+ },
+ };
+ },
+
+ props: {
+ decorations(state) {
+ const pluginState = commentPluginKey.getState(state);
+ if (!pluginState.panelOpen) return DecorationSet.empty;
+
+ const decorations = [];
+ pluginState.ranges.forEach(({ from, to, anchorType }, threadId) => {
+ const isSelected = threadId === pluginState.selectedThreadId;
+ const cls = isSelected
+ ? 'da-comment-highlight da-comment-highlight-active'
+ : 'da-comment-highlight';
+ pushAnchorDecoration(decorations, {
+ from,
+ to,
+ anchorType,
+ spec: { class: cls, 'data-comment-thread': threadId },
+ });
+ });
+
+ const { pendingAnchor } = pluginState;
+ const pendingRange = decodeAnchor({ anchor: pendingAnchor, state });
+ if (pendingRange) {
+ pushAnchorDecoration(decorations, {
+ from: pendingRange.from,
+ to: pendingRange.to,
+ anchorType: pendingAnchor?.anchorType,
+ spec: { class: 'da-comment-highlight da-comment-highlight-pending' },
+ });
+ }
+
+ return DecorationSet.create(state.doc, decorations);
+ },
+
+ handleDOMEvents: {
+ click(view, event) {
+ const pluginState = commentPluginKey.getState(view.state);
+ if (!pluginState.panelOpen) return false;
+ const target = event.target?.closest?.('[data-comment-thread]');
+ if (target) {
+ controller.setSelectedThread(target.getAttribute('data-comment-thread'));
+ return true;
+ }
+ if (pluginState.selectedThreadId) controller.setSelectedThread(null);
+ return false;
+ },
+ },
+ },
+ });
+}
diff --git a/blocks/edit/prose/plugins/comments/helpers/anchor.js b/blocks/edit/prose/plugins/comments/helpers/anchor.js
new file mode 100644
index 000000000..f6bee948d
--- /dev/null
+++ b/blocks/edit/prose/plugins/comments/helpers/anchor.js
@@ -0,0 +1,85 @@
+import {
+ Y,
+ ySyncPluginKey,
+ NodeSelection,
+ CellSelection,
+ absolutePositionToRelativePosition,
+ relativePositionToAbsolutePosition,
+} from 'da-y-wrapper';
+import { getTableInfo } from '../../tableUtils.js';
+
+function encodeRelPos(relPos) {
+ return Array.from(Y.encodeRelativePosition(relPos));
+}
+
+function decodeRelPos(encoded) {
+ if (!Array.isArray(encoded) || encoded.length === 0) return null;
+ return Y.decodeRelativePosition(Uint8Array.from(encoded));
+}
+
+export function encodeAnchor({ selectionData, state }) {
+ if (!selectionData) return null;
+ const binding = ySyncPluginKey.getState(state)?.binding;
+ if (!binding) return null;
+ return {
+ anchorFrom: encodeRelPos(
+ absolutePositionToRelativePosition(selectionData.from, binding.type, binding.mapping),
+ ),
+ anchorTo: encodeRelPos(
+ absolutePositionToRelativePosition(selectionData.to, binding.type, binding.mapping),
+ ),
+ anchorType: selectionData.anchorType,
+ anchorText: selectionData.anchorText,
+ };
+}
+
+export function decodeAnchor({ anchor, state }) {
+ if (!anchor?.anchorFrom || !anchor?.anchorTo) return null;
+ const binding = ySyncPluginKey.getState(state)?.binding;
+ if (!binding) return null;
+ const relFrom = decodeRelPos(anchor.anchorFrom);
+ const relTo = decodeRelPos(anchor.anchorTo);
+ if (!relFrom || !relTo) return null;
+ const { doc: yDoc, type, mapping } = binding;
+
+ try {
+ const from = relativePositionToAbsolutePosition(yDoc, type, relFrom, mapping);
+ const to = relativePositionToAbsolutePosition(yDoc, type, relTo, mapping);
+ if (from == null || to == null || from >= to) return null;
+ return { from, to };
+ } catch {
+ return null;
+ }
+}
+
+export function getSelectionData(state) {
+ const { selection, doc } = state;
+ if (!selection || selection.empty) return null;
+ if (selection instanceof CellSelection) return null;
+ const { from, to } = selection;
+
+ if (selection instanceof NodeSelection) {
+ if (selection.node.type.name === 'image') {
+ return { from, to, anchorType: 'image', anchorText: '' };
+ }
+ if (selection.node.type.name === 'table') {
+ const tableInfo = getTableInfo(state, from + 3);
+ const name = tableInfo?.tableName?.trim();
+ return {
+ from,
+ to,
+ anchorType: 'table',
+ anchorText: name ? `block: ${name}` : '',
+ };
+ }
+ return null;
+ }
+
+ return {
+ from,
+ to,
+ anchorType: 'text',
+ anchorText:
+ doc.textBetween(from, to, ' '),
+ };
+}
diff --git a/blocks/edit/prose/plugins/comments/helpers/controller.js b/blocks/edit/prose/plugins/comments/helpers/controller.js
new file mode 100644
index 000000000..f3b81694f
--- /dev/null
+++ b/blocks/edit/prose/plugins/comments/helpers/controller.js
@@ -0,0 +1,224 @@
+import {
+ SET_SELECTED_THREAD,
+ SET_PANEL_OPEN,
+ SET_PENDING_ANCHOR,
+ commentPluginKey,
+} from '../commentPlugin.js';
+import { decodeAnchor, encodeAnchor, getSelectionData } from './anchor.js';
+
+function computeCounts(ymap) {
+ let active = 0;
+ let resolved = 0;
+
+ ymap.forEach((c) => {
+ if (c.parentId != null) return;
+ if (c.resolved) resolved += 1;
+ else active += 1;
+ });
+
+ return { active, resolved };
+}
+
+export function createCommentsController({ ymap, ydoc, wsProvider }) {
+ let hasSelection = false;
+ let counts = computeCounts(ymap);
+ let boundView = null;
+
+ const channels = new Map();
+
+ const emit = (reason) => {
+ channels.get(reason)?.forEach((fn) => fn());
+ channels.get('*')?.forEach((fn) => fn(reason));
+ };
+
+ const getPluginState = () => (
+ boundView ? commentPluginKey.getState(boundView.state) : null
+ );
+
+ const dispatchPluginMeta = (meta) => {
+ if (!boundView) return;
+ boundView.dispatch(boundView.state.tr.setMeta(commentPluginKey, meta));
+ };
+
+ const onYmapChange = () => {
+ counts = computeCounts(ymap);
+ emit('counts');
+ };
+
+ let detachSync = null;
+ let observerAttached = false;
+
+ const attachObserver = () => {
+ ymap.observe(onYmapChange);
+ observerAttached = true;
+ onYmapChange();
+ };
+
+ if (wsProvider && !wsProvider.synced) {
+ const handleSynced = (isSynced) => {
+ if (!isSynced) return;
+ wsProvider.off('synced', handleSynced);
+ detachSync = null;
+ attachObserver();
+ };
+
+ wsProvider.on('synced', handleSynced);
+ detachSync = () => wsProvider.off('synced', handleSynced);
+ } else {
+ attachObserver();
+ }
+
+ return {
+ get ymap() { return ymap; },
+ get ydoc() { return ydoc; },
+ get wsProvider() { return wsProvider; },
+ get panelOpen() {
+ return Boolean(getPluginState()?.panelOpen);
+ },
+ get selectedThreadId() {
+ return getPluginState()?.selectedThreadId ?? null;
+ },
+ get pendingAnchor() {
+ return getPluginState()?.pendingAnchor ?? null;
+ },
+ get hasSelection() { return hasSelection; },
+ get counts() { return counts; },
+
+ getAttachedThreadIds() {
+ if (!boundView) return null;
+ const ids = new Set();
+ ymap.forEach((comment, id) => {
+ if (comment.parentId != null || comment.resolved) return;
+ const range = decodeAnchor({ anchor: comment, state: boundView.state });
+ if (range) ids.add(id);
+ });
+ return ids;
+ },
+
+ scrollToThread(threadId, { behavior = 'smooth' } = {}) {
+ if (!boundView || boundView.isDestroyed || !threadId) return;
+ const comment = ymap.get(threadId);
+ if (!comment) return;
+ const range = decodeAnchor({ anchor: comment, state: boundView.state });
+ if (!range) return;
+ const { anchorType } = comment;
+ const isTableOrImage = anchorType === 'table' || anchorType === 'image';
+ let targetEl = null;
+ if (isTableOrImage) {
+ targetEl = boundView.nodeDOM(range.from);
+ } else {
+ const { node } = boundView.domAtPos(range.from);
+ targetEl = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
+ }
+ targetEl?.scrollIntoView({ behavior, block: 'center' });
+ },
+
+ notifyDocChange() {
+ emit('docChange');
+ },
+
+ notifyPluginStateChange(prev, next) {
+ if (!next) return;
+ if (!prev) {
+ if (next.panelOpen) emit('panelOpen');
+ if (next.selectedThreadId != null) emit('selectedThreadId');
+ if (next.pendingAnchor != null) emit('pendingAnchor');
+ return;
+ }
+ if (prev.panelOpen !== next.panelOpen) emit('panelOpen');
+ if (prev.selectedThreadId !== next.selectedThreadId) emit('selectedThreadId');
+ if (prev.pendingAnchor !== next.pendingAnchor) emit('pendingAnchor');
+ },
+
+ bindView(view) {
+ boundView = view;
+ },
+
+ setPanelOpen(open) {
+ const next = Boolean(open);
+ const ps = getPluginState();
+ if (ps && ps.panelOpen === next) return;
+ if (!next && ps && (ps.selectedThreadId != null || ps.pendingAnchor != null)) {
+ dispatchPluginMeta({
+ batch: [
+ { type: SET_PANEL_OPEN, payload: false },
+ { type: SET_SELECTED_THREAD, payload: null },
+ { type: SET_PENDING_ANCHOR, payload: null },
+ ],
+ });
+ return;
+ }
+ dispatchPluginMeta({ type: SET_PANEL_OPEN, payload: next });
+ },
+
+ setSelectedThread(id) {
+ const next = id ?? null;
+ const ps = getPluginState();
+ if (ps && ps.selectedThreadId === next) return;
+ dispatchPluginMeta({ type: SET_SELECTED_THREAD, payload: next });
+ },
+
+ setPendingAnchor(anchor) {
+ const next = anchor ?? null;
+ const ps = getPluginState();
+ if (ps && ps.pendingAnchor === next) return;
+ dispatchPluginMeta({ type: SET_PENDING_ANCHOR, payload: next });
+ },
+
+ clearPendingAnchor() {
+ this.setPendingAnchor(null);
+ },
+
+ setHasSelection(next) {
+ const value = Boolean(next);
+ if (value === hasSelection) return;
+ hasSelection = value;
+ emit('hasSelection');
+ },
+
+ openPanel({ pendingAnchor: anchor = null } = {}) {
+ if (!boundView) return;
+ const batch = [];
+ if (anchor != null) {
+ batch.push({ type: SET_SELECTED_THREAD, payload: null });
+ }
+ batch.push(
+ { type: SET_PANEL_OPEN, payload: true },
+ { type: SET_PENDING_ANCHOR, payload: anchor },
+ );
+ dispatchPluginMeta({ batch });
+ },
+
+ closePanel() {
+ this.setPanelOpen(false);
+ },
+
+ requestCompose() {
+ if (!boundView) return;
+ const selectionData = getSelectionData(boundView.state);
+ const anchor = selectionData
+ ? encodeAnchor({ selectionData, state: boundView.state })
+ : null;
+ this.openPanel({ pendingAnchor: anchor });
+ },
+
+ on(reason, fn) {
+ if (!channels.has(reason)) channels.set(reason, new Set());
+ channels.get(reason).add(fn);
+ return () => channels.get(reason)?.delete(fn);
+ },
+
+ subscribe(fn) {
+ const off = this.on('*', (reason) => fn({ reason }));
+ fn({ reason: 'init' });
+ return off;
+ },
+
+ destroy() {
+ if (detachSync) detachSync();
+ if (observerAttached) ymap.unobserve(onYmapChange);
+ channels.clear();
+ boundView = null;
+ },
+ };
+}
diff --git a/blocks/shared/da-toast/da-toast.css b/blocks/shared/da-toast/da-toast.css
new file mode 100644
index 000000000..b77cc015d
--- /dev/null
+++ b/blocks/shared/da-toast/da-toast.css
@@ -0,0 +1,40 @@
+.da-toast-overlay {
+ position: fixed;
+ inset: 0;
+ background: rgb(255 255 255 / 60%);
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ z-index: 500;
+}
+
+.da-toast {
+ width: 280px;
+ background: var(--s2-blue-800);
+ line-height: 48px;
+ border-radius: 6px;
+ filter: drop-shadow(rgb(0 0 0 / 15%) 0 1px 4px);
+ justify-content: space-between;
+ align-items: center;
+ box-sizing: border-box;
+ color: #FFF;
+ font-size: 14px;
+ overflow: hidden;
+}
+
+.da-toast-title {
+ font-weight: 700;
+ padding: 0 12px 0 40px;
+ margin: 0;
+}
+
+.da-toast-description {
+ line-height: 1.6;
+ padding: 6px 12px;
+ margin: 0;
+ background: rgb(255 255 255 / 10%);
+}
+
+.da-toast-type-info .da-toast-title {
+ background: var(--s2-blue-800) url('/blocks/browse/img/Smock_InfoOutline_18_N.svg') 12px 50% no-repeat;
+}
diff --git a/blocks/shared/da-toast/da-toast.js b/blocks/shared/da-toast/da-toast.js
new file mode 100644
index 000000000..ab695cdf2
--- /dev/null
+++ b/blocks/shared/da-toast/da-toast.js
@@ -0,0 +1,44 @@
+import { LitElement, html, nothing } from 'da-lit';
+import getSheet from '../sheet.js';
+
+const sheet = await getSheet('/blocks/shared/da-toast/da-toast.css');
+
+export default class DaToast extends LitElement {
+ static properties = { toast: { attribute: false } };
+
+ connectedCallback() {
+ super.connectedCallback();
+ this.shadowRoot.adoptedStyleSheets = [sheet];
+ }
+
+ updated(changedProps) {
+ if (!changedProps.has('toast')) return;
+ clearTimeout(this._timerId);
+ if (!this.toast) return;
+ const duration = this.toast.duration ?? 3000;
+ if (!duration) return;
+ this._timerId = setTimeout(() => {
+ this.toast = null;
+ this.dispatchEvent(new Event('close'));
+ }, duration);
+ }
+
+ disconnectedCallback() {
+ super.disconnectedCallback();
+ clearTimeout(this._timerId);
+ }
+
+ render() {
+ if (!this.toast) return nothing;
+ const { text, description, type = 'info' } = this.toast;
+ return html`
+
+
+
${text}
+ ${description ? html`
${description}
` : nothing}
+
+
`;
+ }
+}
+
+customElements.define('da-toast', DaToast);
diff --git a/blocks/shared/utils.js b/blocks/shared/utils.js
index 2163d2763..8490a3213 100644
--- a/blocks/shared/utils.js
+++ b/blocks/shared/utils.js
@@ -251,6 +251,35 @@ export const getAemSiteToken = (() => {
};
})();
+/**
+ * Generate a consistent color for a user based on an identifier.
+ * Used for cursor colors and avatar backgrounds.
+ * @param {string} identifier - User email, ID, or other unique string
+ * @param {number[]} hRange - Hue range [min, max]
+ * @param {number[]} sRange - Saturation range [min, max]
+ * @param {number[]} lRange - Lightness range [min, max]
+ * @returns {string} Hex color string
+ */
+export function generateColor(identifier, hRange = [0, 360], sRange = [60, 80], lRange = [40, 60]) {
+ let hash = 0;
+ for (let i = 0; i < identifier.length; i += 1) {
+ // eslint-disable-next-line no-bitwise
+ hash = identifier.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ hash = Math.abs(hash);
+ const normalizeHash = (min, max) => Math.floor((hash % (max - min)) + min);
+ const h = normalizeHash(hRange[0], hRange[1]);
+ const s = normalizeHash(sRange[0], sRange[1]);
+ const l = normalizeHash(lRange[0], lRange[1]) / 100;
+ const a = (s * Math.min(l, 1 - l)) / 100;
+ const f = (n) => {
+ const k = (n + h / 30) % 12;
+ const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
+ return Math.round(255 * color).toString(16).padStart(2, '0');
+ };
+ return `#${f(0)}${f(8)}${f(4)}`;
+}
+
export function delay(ms) {
return new Promise((res) => { setTimeout(res, ms); });
}
diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js
index ed0727d75..3bcc4d43d 100644
--- a/deps/da-y-wrapper/dist/index.js
+++ b/deps/da-y-wrapper/dist/index.js
@@ -1,15 +1,15 @@
-var um=Object.defineProperty;var pm=(n,e)=>{for(var t in e)um(n,t,{get:e[t],enumerable:!0})};function he(n){this.content=n}he.prototype={constructor:he,find:function(n){for(var e=0;e>1}};he.from=function(n){if(n instanceof he)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new he(e)};var Zo=he;function Xa(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=Xa(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Qa(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),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},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=c}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?cs(r+1,o):cs(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}};D.none=[];var sn=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=eh(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(Za(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(w.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(w.empty,0,0);function Za(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(Za(s.content,e-i-1,t-i-1)))}function eh(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=eh(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function mm(n,e,t){if(t.openStart>n.depth)throw new sn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new sn("Inconsistent open depths");return th(n,e,t,0)}function th(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 Fr(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&&(nn(n.nodeAfter,r),s++));for(let l=s;li&&nl(n,e,i+1),o=r.depth>i&&nl(t,r,i+1),l=[];return Fr(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(nh(s,o),nn(rn(s,rh(n,e,t,r,i+1)),l)):(s&&nn(rn(s,fs(n,e,i+1)),l),Fr(e,t,i,l),o&&nn(rn(o,fs(t,r,i+1)),l)),Fr(r,null,i,l),new w(l)}function fs(n,e,t){let r=[];if(Fr(null,n,t,r),n.depth>t){let i=nl(n,e,t+1);nn(rn(i,fs(n,e,t+1)),r)}return Fr(e,null,t,r),new w(r)}function gm(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(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var ds=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 on(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:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=$a.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()+")"),ih(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=w.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 c=i;ct.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=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Be.prototype.text=void 0;var il=class n extends Be{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):ih(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 ih(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var ln=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new sl(e,t);if(r.next==null)return n.empty;let i=sh(r);r.next&&r.err("Unexpected trailing text");let s=Am(Mm(i));return Em(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=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(`
-`)}};ln.empty=new ln(!0);var sl=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 sh(n){let e=[];do e.push(bm(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function bm(n){let e=[];do e.push(xm(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function xm(n){let e=Cm(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=Sm(n,e);else break;return e}function qa(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Sm(n,e){let t=qa(n),r=t;return n.eat(",")&&(n.next!="}"?r=qa(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function km(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 Cm(n){if(n.eat("(")){let e=sh(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=km(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 Mm(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new ln(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:ch(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Be(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Be(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.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(w.empty,!0);return s?new Be(this,e,t.append(s),D.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 Tm(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 ol=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Tm(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},qr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=hh(e,i.attrs),this.excluded=null;let s=lh(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ch(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}},Hr=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=Zo.from(e.nodes),t.marks=Zo.from(e.marks||{}),this.nodes=us.compile(this.spec.nodes,this),this.marks=qr.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]=ln.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?Ja(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==""?[]:Ja(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 us){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 il(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Be.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Ja(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Dm(n){return n.tag!=null}function Om(n){return n.style!=null}var Wn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Dm(i))this.tags.push(i);else if(Om(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 gs(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new gs(this,t,!0);return r.addAll(e,D.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 c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||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=Wa(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=Wa(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)))}},fh={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},Nm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},dh={ol:!0,ul:!0},ps=1,ms=2,$r=4;function ja(n,e,t){return e!=null?(e?ps:0)|(e==="full"?ms:0):n&&n.whitespace=="pre"?ps|ms:t&~$r}var jn=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=D.none,this.match=s||(o&$r?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.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&ps)){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=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.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&&!fh.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},gs=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ja(null,t.preserveWhitespace,0)|(r?$r:0);i?s=new jn(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new jn(null,null,D.none,!0,null,o):s=new jn(e.schema.topNodeType,null,D.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;if(i.options&ms||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&ps)i.options&ms?r=r.replace(/\r\n?/g,`
-`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.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=e.nodeName.toLowerCase(),s;dh.hasOwnProperty(i)&&this.parser.normalizeLists&&Im(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Nm.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(fh.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}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!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;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 c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.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(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!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(a.type):Ka(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new jn(e,t,c,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;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,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}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 Im(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&dh.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Rm(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Wa(n){let e={};for(let t in n)e[t]=n[t];return e}function Ka(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 c=0;c{if(s.length||o.marks.length){let l=0,c=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&&as(tl(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return as(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=Ya(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Ya(e.marks)}};function Ya(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function tl(n){return n.document||window.document}var Ga=new WeakMap;function vm(n){let e=Ga.get(n);return e===void 0&&Ga.set(n,e=_m(n)),e}function _m(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,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let f in a)if(a[f]!=null){let d=f.indexOf(" ");d>0?c.setAttributeNS(f.slice(0,d),f.slice(d+1),a[f]):c.setAttribute(f,a[f])}}for(let f=h;fh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=as(n,d,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var mh=65535,gh=Math.pow(2,16);function Vm(n,e){return n+e*gh}function uh(n){return n&mh}function Bm(n){return(n-(n&mh))/gh}var yh=1,wh=2,ys=4,bh=8,Wr=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&bh)>0}get deletedBefore(){return(this.delInfo&(yh|ys))>0}get deletedAfter(){return(this.delInfo&(wh|ys))>0}get deletedAcross(){return(this.delInfo&ys)>0}},yt=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=uh(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],f=c+a;if(e<=f){let d=a?e==c?-1:e==f?1:t:t,u=c+i+(d<0?0:h);if(r)return u;let p=e==(t<0?c:f)?null:Vm(l/3,e-c),m=e==c?wh:e==f?yh:ys;return(t<0?e!=c:e!=f)&&(m|=bh),new Wr(u,m,p)}i+=h-a}return r?e+i:new Wr(e+i,0,null)}touches(e,t){let r=0,i=uh(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}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&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return re.fromReplace(e,this.from,this.to,s)}invert(){return new cn(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",Yr);var cn=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(dl(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return re.fromReplace(e,this.from,this.to,r)}invert(){return new Yr(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",cn);var Gr=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 re.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return re.fromReplace(e,this.pos,this.pos+1,new b(w.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",ee);function hl(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 Pm(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let f=c.marks;if(!r.isInSet(f)&&h.type.allowsMarkType(r.type)){let d=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(f);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Lm(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof qr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new cn(o.from,o.to,o.style)))}function ul(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function zm(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function an(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth,i=0,s=0;;--r){let o=n.$from.node(r),l=n.$from.index(r)+i,c=n.$to.indexAfter(r)-s;if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),f++):c--;let d=w.empty,u=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=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new ee(i,s,i,s,new b(r,0,0),t.length,!0))}function Jm(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 c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&jm(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Sh(n,o,l,s),ul(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),f=h.map(l,1),d=h.map(l+o.nodeSize,1);return n.step(new ee(f,d,f+1,d-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&xh(n,o,l,s),!1}})}function xh(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 c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Sh(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 jm(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Wm(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 ee(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Bt(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 a=i.depth-1,h=t-2;a>s;a--,h--){let f=i.node(a),d=i.index(a);if(f.type.spec.isolating)return!1;let u=f.content.cutByIndex(d,f.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Km(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ne(e,e,new b(s.append(o),t,t),!0))}function wt(n,e){let t=n.resolve(e),r=t.index();return kh(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Ym(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&&kh(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 Gm(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 h=o.whitespace=="pre",f=!!o.contentMatch.matchType(i);h&&!f?r=!1:!h&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Sh(n,h.node(),h.before(),l)}o.inlineContent&&ul(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ne(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);xh(n,h.node(),h.before(),n.steps.length)}return n}function Xm(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,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let f=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=f&&a.canReplaceWith(c,c,f[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function xs(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Mh(i,s,r)?new Ne(e,t,r):new fl(i,s,r).fit()}function Mh(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var fl=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.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=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):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 c=new b(s,o,l);return e>-1?new ee(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ne(r.pos,i.pos,c):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=cl(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:c,match:a}=this.frontier[l],h,f=null;if(t==1&&(o?a.matchType(o.type)||(f=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=cl(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=cl(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Jr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Jr(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||c==0||m.content.size)&&(f=g,h.push(Ah(m.mark(d.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=jr(this.placed,t,w.from(h)),this.frontier[t].match=f,p&&u<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:c,type:a}=this.frontier[l],h=al(e,l,a,c,!0);if(!h||h.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=jr(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=jr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=jr(this.placed,this.frontier.length,t))}};function Jr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Jr(n.firstChild.content,e-1,t)))}function jr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(jr(n.lastChild.content,e-1,t)))}function cl(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ah(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(w.empty,!0)))),n.copy(r)}function al(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&&!Qm(t,s.content,o)?l:null}function Qm(n,e,t){for(let r=t;r0;d--,u--){let p=i.node(d).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==u&&o.splice(1,0,-d)}let c=o.indexOf(l),a=[],h=r.openStart;for(let d=r.content,u=0;;u++){let p=d.firstChild;if(a.push(p),u==r.openStart)break;d=p.content}for(let d=h-1;d>=0;d--){let u=a[d],p=Zm(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=d;else if(p||!u.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let u=(d+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let u=o[d];u<0||(e=i.before(u),t=s.after(u))}}function Eh(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(w.empty,!0))}return n}function tg(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Xm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function ng(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Th(r,i);for(let o=0;o0&&(c||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 Th(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 ws=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 re.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 re.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return yt.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",ws);var bs=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 re.ok(r)}getMap(){return yt.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",bs);var Yn=class extends Error{};Yn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yn.prototype=Object.create(Error.prototype);Yn.prototype.constructor=Yn;Yn.prototype.name="TransformError";var Gn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Kr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yn(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=xs(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.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 eg(this,e,t,r),this}replaceRangeWith(e,t,r){return tg(this,e,t,r),this}deleteRange(e,t){return ng(this,e,t),this}lift(e,t){return Fm(this,e,t),this}join(e,t=1){return Gm(this,e,t),this}wrap(e,t){return Hm(this,e,t),this}setBlockType(e,t=e,r,i=null){return Jm(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Wm(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ws(e,t,r)),this}setDocAttribute(e,t){return this.step(new bs(e,t)),this}addNodeMark(e,t){return this.step(new Gr(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof D)t.isInSet(r.marks)&&this.step(new Kn(e,t));else{let i=r.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Kn(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,r){return Km(this,e,t,r),this}addMark(e,t,r){return Pm(this,e,t,r),this}removeMark(e,t,r){return Lm(this,e,t,r),this}clearIncompatible(e,t,r){return ul(this,e,t,r),this}};var ml=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Pt(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?Qn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Qn(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 Ie(e.node(0))}static atStart(e){return Qn(e,e,0,0,1)||new Ie(e)}static atEnd(e){return Qn(e,e,e.content.size,e.childCount,-1)||new Ie(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=ml[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 ml)throw new RangeError("Duplicate use of selection JSON ID "+e);return ml[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Pt=class{constructor(e,t){this.$from=e,this.$to=t}},Dh=!1;function Oh(n){!Dh&&!n.parent.inlineContent&&(Dh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Oh(e),Oh(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 S.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 ks(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=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.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&&k.isSelectable(l))return k.create(n,t-(i<0?l.nodeSize:0))}else{let c=Qn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Nh(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Ih=1,Ss=2,Rh=4,wl=class extends Gn{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|=Ss,this}ensureMarks(e){return D.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&Ss)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Ss,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)||D.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(S.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|=Rh,this}get scrolledIntoView(){return(this.updated&Rh)>0}};function vh(n,e){return!e||!n?n:n.bind(e)}var hn=class{constructor(e,t,r){this.name=e,this.init=vh(t.init,r),this.apply=vh(t.apply,r)}},ig=[new hn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new hn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new hn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new hn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Xr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ig.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 hn(r.key,r.spec.state,r))})}},bl=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 Xr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Be.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.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 c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function _h(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=_h(i,e,{})),t[r]=i}return t}var J=class{constructor(e){this.spec=e,this.props={},e.props&&_h(e.props,this,this.props),this.key=e.key?e.key.key:Uh("plugin")}getState(e){return e[this.key]}},gl=Object.create(null);function Uh(n){return n in gl?n+"$"+ ++gl[n]:(gl[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=Uh(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ie=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ti=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ml=null,xt=function(n,e,t){let r=Ml||(Ml=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},sg=function(){Ml=null},yn=function(n,e,t,r){return t&&(Vh(n,e,t,r,-1)||Vh(n,e,t,r,1))},og=/^(img|br|input|textarea|hr)$/i;function Vh(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Le(n))){let s=n.parentNode;if(!s||s.nodeType!=1||si(n)||og.test(n.nodeName)||n.contentEditable=="false")return!1;e=ie(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?Le(n):0}else return!1}}function Le(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lg(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=Le(n)}else if(n.parentNode&&!si(n))e=ie(n),n=n.parentNode;else return null}}function cg(n,e){for(;;){if(n.nodeType==3&&e2),Pe=rr||(Ze?/Mac/.test(Ze.platform):!1),dg=Ze?/Win/.test(Ze.platform):!1,We=/Android \d/.test(Ht),oi=!!Bh&&"webkitFontSmoothing"in Bh.documentElement.style,ug=oi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pg(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 bt(n,e){return typeof n=="number"?n:n[e]}function mg(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 Ph(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=ti(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?pg(s):mg(l),h=0,f=0;if(e.topa.bottom-bt(r,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+bt(i,"top")-a.top:e.bottom-a.bottom+bt(i,"bottom")),e.lefta.right-bt(r,"right")&&(h=e.right-a.right+bt(i,"right")),h||f)if(c)s.defaultView.scrollBy(h,f);else{let d=l.scrollLeft,u=l.scrollTop;f&&(l.scrollTop+=f),h&&(l.scrollLeft+=h);let p=l.scrollLeft-d,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function gg(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=c.top;break}}return{refDOM:r,refTop:i,stack:wf(n.dom)}}function wf(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ti(r));return e}function yg({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;bf(t,r==0?0:r-e)}function bf(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&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={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=f+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?bg(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:xf(t,i)}function bg(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 ql(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function xg(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 kg(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Sf(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;oi&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.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=kg(n,r,i,e))}l==null&&(l=Sg(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Lh(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Qr(Lt(xt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return xl(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1],a=c.nodeType==3?xt(c,Le(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Qr(Lt(a,1),!1)}if(s==null&&i=0)}function Qr(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 xl(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 Cf(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 Ag(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Cf(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=kf(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=xt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Eg=/[\u0590-\u08ac]/;function Tg(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?!Eg.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Cf(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,f),c&&(c!=h||a!=f)&&l.extend&&l.extend(c,a)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var zh=null,Fh=null,$h=!1;function Dg(n,e,t){return zh==e&&Fh==t?$h:(zh=e,Fh=t,$h=t=="up"||t=="down"?Ag(n,e,t):Tg(n,e,t))}var ze=0,qh=1,dn=2,et=3,wn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ze,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;tie(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 As){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 Cs&&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?ie(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ie(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let d=document.createRange();d.setEnd(c.node,c.offset),d.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(d)}}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,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?dn:qh,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=et:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?dn:et}r=o}this.dirty=dn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?dn:qh;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==ze&&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}},Dl=class extends wn{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}},ir=class n extends wn{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Vt.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&et||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=et&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ze){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Rl(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,f=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:f}=Vt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=Ef(h,r,t),a?c=new Ol(e,t,r,i,h,f||null,d,a,s,o+1):t.isText?new Ms(e,t,r,i,h,d,s):new n(e,t,r,i,h,f||null,d,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=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==ze&&e.eq(this.node)&&Es(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,c=new Il(this,o&&o.node,e);Rg(this.node,this.innerDeco,(a,h,f)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!f&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,f,d)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,f,u,e)||c.updateNextNode(a,h,f,e,d,i)||c.addNode(a,h,f,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==dn)&&(o&&this.protectLocalComposition(e,o),Mf(this.contentDOM,this.children,e),rr&&vg(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||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=_g(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 Dl(this,s,t,i);e.input.compositionNodes.push(o),this.children=Rl(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==et||!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=ze}updateOuterDeco(e){if(Es(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Af(this.dom,this.nodeDOM,Nl(this.outerDeco,this.node,t),Nl(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 Hh(n,e,t,r,i){Ef(r,e,n);let s=new qt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Ms=class n extends qt{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==et||this.dirty!=ze&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ze||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=ze,!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=et)}get domAtom(){return!1}isText(e){return this.node.text==e}},As=class extends wn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ze&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ol=class extends qt{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==et)return!1;if(this.spec.update){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):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 Mf(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 c=ir.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,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,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof ir)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Ig(n,e){return n.type.side-e.type.side}function Rg(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+d.nodeSize;if(d.isText){let g=p;o!g.inline):l.slice();r(d,m,e.forChild(s,d),u),s=p}}function vg(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 _g(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Rl(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function Hl(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),c,a;if(vs(t)){for(c=o;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&k.isSelectable(f)&&i.parent&&!(f.isInline&&ag(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new k(o==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,d=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Tf(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Vg(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,ie(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&Ee&&$t<=11&&(r.disabled=!0,r.disabled=!1)}function Df(n,e){if(e instanceof k){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Yh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Yh(n)}function Yh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Jl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Gh(n){return n.editable&&!n.hasFocus()?!1:Of(n)}function Of(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 Bg(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return yn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function vl(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&&S.findFrom(s,e)}function zt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Xh(n,e,t){let r=n.state.selection;if(r instanceof A)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 zt(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=vl(n.state,e);return i&&i instanceof k?zt(n,i):!1}else if(!(Pe&&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?k.isSelectable(s)?zt(n,new k(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):oi?zt(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof k&&r.node.isInline)return zt(n,new A(e>0?r.$to:r.$from));{let i=vl(n.state,e);return i?zt(n,i):!1}}}function Ts(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ei(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function er(n,e){return e<0?Pg(n):Lg(n)}function Pg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(Ke&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(ei(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Nf(t))break;{let l=t.previousSibling;for(;l&&ei(l,-1);)i=t.parentNode,s=ie(l),l=l.previousSibling;if(l)t=l,r=Ts(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?_l(n,t,r):i&&_l(n,i,s)}function Lg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Ts(t),s,o;for(;;)if(r{n.state==i&&St(n)},50)}function Qh(n,e){let t=n.state.doc.resolve(e);if(!(ue||dg)&&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 Zh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Pe&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=vl(n.state,e);if(o&&o instanceof k)return zt(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Ie?S.near(o,e):S.findFrom(o,e);return l?zt(n,l):!1}return!1}function ef(n,e){if(!(n.state.selection instanceof A))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 tf(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function $g(n){if(!be||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;tf(n,r,"true"),setTimeout(()=>tf(n,r,"false"),20)}return!1}function qg(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Hg(n,e){let t=e.keyCode,r=qg(e);if(t==8||Pe&&t==72&&r=="c")return ef(n,-1)||er(n,-1);if(t==46&&!e.shiftKey||Pe&&t==68&&r=="c")return ef(n,1)||er(n,1);if(t==13||t==27)return!0;if(t==37||Pe&&t==66&&r=="c"){let i=t==37?Qh(n,n.state.selection.from)=="ltr"?-1:1:-1;return Xh(n,i,r)||er(n,i)}else if(t==39||Pe&&t==70&&r=="c"){let i=t==39?Qh(n,n.state.selection.from)=="ltr"?1:-1:1;return Xh(n,i,r)||er(n,i)}else{if(t==38||Pe&&t==80&&r=="c")return Zh(n,-1,r)||er(n,-1);if(t==40||Pe&&t==78&&r=="c")return $g(n)||Zh(n,1,r)||er(n,1);if(r==(Pe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function If(n,e){n.someProp("transformCopied",u=>{e=u(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 u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Vt.fromSchema(n.state.schema),l=Bf(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,f=0;for(;a&&a.nodeType==1&&(h=Vf[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),f++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,`
+var dm=Object.defineProperty;var um=(n,e)=>{for(var t in e)dm(n,t,{get:e[t],enumerable:!0})};function he(n){this.content=n}he.prototype={constructor:he,find:function(n){for(var e=0;e>1}};he.from=function(n){if(n instanceof he)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new he(e)};var Zo=he;function Ka(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=Ka(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Ya(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),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},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=c}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?cs(r+1,o):cs(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}};D.none=[];var on=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=Xa(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(Ga(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(w.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(w.empty,0,0);function Ga(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(Ga(s.content,e-i-1,t-i-1)))}function Xa(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=Xa(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function pm(n,e,t){if(t.openStart>n.depth)throw new on("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new on("Inconsistent open depths");return Qa(n,e,t,0)}function Qa(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 Fr(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&&(rn(n.nodeAfter,r),s++));for(let l=s;li&&nl(n,e,i+1),o=r.depth>i&&nl(t,r,i+1),l=[];return Fr(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(Za(s,o),rn(sn(s,eh(n,e,t,r,i+1)),l)):(s&&rn(sn(s,fs(n,e,i+1)),l),Fr(e,t,i,l),o&&rn(sn(o,fs(t,r,i+1)),l)),Fr(r,null,i,l),new w(l)}function fs(n,e,t){let r=[];if(Fr(null,n,t,r),n.depth>t){let i=nl(n,e,t+1);rn(sn(i,fs(n,e,t+1)),r)}return Fr(e,null,t,r),new w(r)}function mm(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(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var ds=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 ln(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:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=La.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()+")"),th(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=w.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 c=i;ct.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=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Be.prototype.text=void 0;var il=class n extends Be{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):th(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 th(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var cn=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new sl(e,t);if(r.next==null)return n.empty;let i=nh(r);r.next&&r.err("Unexpected trailing text");let s=Mm(Cm(i));return Am(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=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(`
+`)}};cn.empty=new cn(!0);var sl=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 nh(n){let e=[];do e.push(wm(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function wm(n){let e=[];do e.push(bm(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function bm(n){let e=km(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=xm(n,e);else break;return e}function za(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function xm(n,e){let t=za(n),r=t;return n.eat(",")&&(n.next!="}"?r=za(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Sm(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 km(n){if(n.eat("(")){let e=nh(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=Sm(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 Cm(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new cn(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:sh(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Be(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Be(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.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(w.empty,!0);return s?new Be(this,e,t.append(s),D.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 Em(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 ol=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Em(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},qr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=lh(e,i.attrs),this.excluded=null;let s=ih(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,sh(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}},Hr=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=Zo.from(e.nodes),t.marks=Zo.from(e.marks||{}),this.nodes=us.compile(this.spec.nodes,this),this.marks=qr.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]=cn.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?$a(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==""?[]:$a(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 us){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 il(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Be.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function $a(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Tm(n){return n.tag!=null}function Dm(n){return n.style!=null}var Wn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Tm(i))this.tags.push(i);else if(Dm(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 gs(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new gs(this,t,!0);return r.addAll(e,D.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 c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||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=Ha(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=Ha(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)))}},ch={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},Om={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ah={ol:!0,ul:!0},ps=1,ms=2,$r=4;function qa(n,e,t){return e!=null?(e?ps:0)|(e==="full"?ms:0):n&&n.whitespace=="pre"?ps|ms:t&~$r}var jn=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=D.none,this.match=s||(o&$r?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.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&ps)){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=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.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&&!ch.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},gs=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=qa(null,t.preserveWhitespace,0)|(r?$r:0);i?s=new jn(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new jn(null,null,D.none,!0,null,o):s=new jn(e.schema.topNodeType,null,D.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;if(i.options&ms||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&ps)i.options&ms?r=r.replace(/\r\n?/g,`
+`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.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=e.nodeName.toLowerCase(),s;ah.hasOwnProperty(i)&&this.parser.normalizeLists&&Nm(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Om.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(ch.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}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!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;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 c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.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(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!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(a.type):Ja(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new jn(e,t,c,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;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,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}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 Nm(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ah.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Im(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Ha(n){let e={};for(let t in n)e[t]=n[t];return e}function Ja(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 c=0;c{if(s.length||o.marks.length){let l=0,c=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&&as(tl(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return as(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=ja(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ja(e.marks)}};function ja(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function tl(n){return n.document||window.document}var Wa=new WeakMap;function Rm(n){let e=Wa.get(n);return e===void 0&&Wa.set(n,e=vm(n)),e}function vm(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,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let f in a)if(a[f]!=null){let d=f.indexOf(" ");d>0?c.setAttributeNS(f.slice(0,d),f.slice(d+1),a[f]):c.setAttribute(f,a[f])}}for(let f=h;fh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=as(n,d,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var dh=65535,uh=Math.pow(2,16);function Um(n,e){return n+e*uh}function hh(n){return n&dh}function Vm(n){return(n-(n&dh))/uh}var ph=1,mh=2,ys=4,gh=8,Wr=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&gh)>0}get deletedBefore(){return(this.delInfo&(ph|ys))>0}get deletedAfter(){return(this.delInfo&(mh|ys))>0}get deletedAcross(){return(this.delInfo&ys)>0}},gt=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=hh(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],f=c+a;if(e<=f){let d=a?e==c?-1:e==f?1:t:t,u=c+i+(d<0?0:h);if(r)return u;let p=e==(t<0?c:f)?null:Um(l/3,e-c),m=e==c?mh:e==f?ph:ys;return(t<0?e!=c:e!=f)&&(m|=gh),new Wr(u,m,p)}i+=h-a}return r?e+i:new Wr(e+i,0,null)}touches(e,t){let r=0,i=hh(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}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&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ie.fromReplace(e,this.from,this.to,s)}invert(){return new an(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",Yr);var an=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(dl(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ie.fromReplace(e,this.from,this.to,r)}invert(){return new Yr(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",an);var Gr=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 ie.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ie.fromReplace(e,this.pos,this.pos+1,new b(w.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",ee);function hl(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 Bm(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let f=c.marks;if(!r.isInSet(f)&&h.type.allowsMarkType(r.type)){let d=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(f);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Pm(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof qr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new an(o.from,o.to,o.style)))}function ul(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Lm(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function hn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth,i=0,s=0;;--r){let o=n.$from.node(r),l=n.$from.index(r)+i,c=n.$to.indexAfter(r)-s;if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),f++):c--;let d=w.empty,u=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=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new ee(i,s,i,s,new b(r,0,0),t.length,!0))}function Hm(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 c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Jm(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&wh(n,o,l,s),ul(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),f=h.map(l,1),d=h.map(l+o.nodeSize,1);return n.step(new ee(f,d,f+1,d-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&yh(n,o,l,s),!1}})}function yh(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 c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function wh(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 Jm(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function jm(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 ee(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Pt(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 a=i.depth-1,h=t-2;a>s;a--,h--){let f=i.node(a),d=i.index(a);if(f.type.spec.isolating)return!1;let u=f.content.cutByIndex(d,f.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Wm(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ne(e,e,new b(s.append(o),t,t),!0))}function yt(n,e){let t=n.resolve(e),r=t.index();return bh(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Km(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&&bh(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 Ym(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 h=o.whitespace=="pre",f=!!o.contentMatch.matchType(i);h&&!f?r=!1:!h&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);wh(n,h.node(),h.before(),l)}o.inlineContent&&ul(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ne(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);yh(n,h.node(),h.before(),n.steps.length)}return n}function Gm(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,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let f=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=f&&a.canReplaceWith(c,c,f[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function xs(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Sh(i,s,r)?new Ne(e,t,r):new fl(i,s,r).fit()}function Sh(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var fl=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.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=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):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 c=new b(s,o,l);return e>-1?new ee(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ne(r.pos,i.pos,c):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=cl(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:c,match:a}=this.frontier[l],h,f=null;if(t==1&&(o?a.matchType(o.type)||(f=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=cl(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=cl(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Jr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Jr(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||c==0||m.content.size)&&(f=g,h.push(kh(m.mark(d.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=jr(this.placed,t,w.from(h)),this.frontier[t].match=f,p&&u<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:c,type:a}=this.frontier[l],h=al(e,l,a,c,!0);if(!h||h.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=jr(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=jr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=jr(this.placed,this.frontier.length,t))}};function Jr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Jr(n.firstChild.content,e-1,t)))}function jr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(jr(n.lastChild.content,e-1,t)))}function cl(n,e){for(let t=0;t1&&(r=r.replaceChild(0,kh(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(w.empty,!0)))),n.copy(r)}function al(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&&!Xm(t,s.content,o)?l:null}function Xm(n,e,t){for(let r=t;r0;d--,u--){let p=i.node(d).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==u&&o.splice(1,0,-d)}let c=o.indexOf(l),a=[],h=r.openStart;for(let d=r.content,u=0;;u++){let p=d.firstChild;if(a.push(p),u==r.openStart)break;d=p.content}for(let d=h-1;d>=0;d--){let u=a[d],p=Qm(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=d;else if(p||!u.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let u=(d+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let u=o[d];u<0||(e=i.before(u),t=s.after(u))}}function Ch(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(w.empty,!0))}return n}function eg(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Gm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function tg(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Mh(r,i);for(let o=0;o0&&(c||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 Mh(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 ws=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 ie.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 ie.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return gt.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",ws);var bs=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 ie.ok(r)}getMap(){return gt.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",bs);var Yn=class extends Error{};Yn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yn.prototype=Object.create(Error.prototype);Yn.prototype.constructor=Yn;Yn.prototype.name="TransformError";var Gn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Kr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yn(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=xs(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.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 Zm(this,e,t,r),this}replaceRangeWith(e,t,r){return eg(this,e,t,r),this}deleteRange(e,t){return tg(this,e,t),this}lift(e,t){return zm(this,e,t),this}join(e,t=1){return Ym(this,e,t),this}wrap(e,t){return qm(this,e,t),this}setBlockType(e,t=e,r,i=null){return Hm(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return jm(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ws(e,t,r)),this}setDocAttribute(e,t){return this.step(new bs(e,t)),this}addNodeMark(e,t){return this.step(new Gr(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof D)t.isInSet(r.marks)&&this.step(new Kn(e,t));else{let i=r.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Kn(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,r){return Wm(this,e,t,r),this}addMark(e,t,r){return Bm(this,e,t,r),this}removeMark(e,t,r){return Pm(this,e,t,r),this}clearIncompatible(e,t,r){return ul(this,e,t,r),this}};var ml=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Lt(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?Qn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Qn(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 Ie(e.node(0))}static atStart(e){return Qn(e,e,0,0,1)||new Ie(e)}static atEnd(e){return Qn(e,e,e.content.size,e.childCount,-1)||new Ie(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=ml[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 ml)throw new RangeError("Duplicate use of selection JSON ID "+e);return ml[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Lt=class{constructor(e,t){this.$from=e,this.$to=t}},Ah=!1;function Eh(n){!Ah&&!n.parent.inlineContent&&(Ah=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Eh(e),Eh(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 S.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 ks(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=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.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&&k.isSelectable(l))return k.create(n,t-(i<0?l.nodeSize:0))}else{let c=Qn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Th(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Dh=1,Ss=2,Oh=4,wl=class extends Gn{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|=Ss,this}ensureMarks(e){return D.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&Ss)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Ss,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)||D.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(S.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|=Oh,this}get scrolledIntoView(){return(this.updated&Oh)>0}};function Nh(n,e){return!e||!n?n:n.bind(e)}var fn=class{constructor(e,t,r){this.name=e,this.init=Nh(t.init,r),this.apply=Nh(t.apply,r)}},rg=[new fn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new fn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new fn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new fn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Xr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=rg.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 fn(r.key,r.spec.state,r))})}},bl=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 Xr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Be.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.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 c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Ih(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ih(i,e,{})),t[r]=i}return t}var J=class{constructor(e){this.spec=e,this.props={},e.props&&Ih(e.props,this,this.props),this.key=e.key?e.key.key:Rh("plugin")}getState(e){return e[this.key]}},gl=Object.create(null);function Rh(n){return n in gl?n+"$"+ ++gl[n]:(gl[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=Rh(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var se=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ti=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ml=null,bt=function(n,e,t){let r=Ml||(Ml=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ig=function(){Ml=null},wn=function(n,e,t,r){return t&&(vh(n,e,t,r,-1)||vh(n,e,t,r,1))},sg=/^(img|br|input|textarea|hr)$/i;function vh(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Le(n))){let s=n.parentNode;if(!s||s.nodeType!=1||si(n)||sg.test(n.nodeName)||n.contentEditable=="false")return!1;e=se(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?Le(n):0}else return!1}}function Le(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function og(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=Le(n)}else if(n.parentNode&&!si(n))e=se(n),n=n.parentNode;else return null}}function lg(n,e){for(;;){if(n.nodeType==3&&e2),Pe=rr||(Ze?/Mac/.test(Ze.platform):!1),fg=Ze?/Win/.test(Ze.platform):!1,je=/Android \d/.test(Jt),oi=!!_h&&"webkitFontSmoothing"in _h.documentElement.style,dg=oi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ug(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 wt(n,e){return typeof n=="number"?n:n[e]}function pg(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 Uh(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=ti(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?ug(s):pg(l),h=0,f=0;if(e.topa.bottom-wt(r,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+wt(i,"top")-a.top:e.bottom-a.bottom+wt(i,"bottom")),e.lefta.right-wt(r,"right")&&(h=e.right-a.right+wt(i,"right")),h||f)if(c)s.defaultView.scrollBy(h,f);else{let d=l.scrollLeft,u=l.scrollTop;f&&(l.scrollTop+=f),h&&(l.scrollLeft+=h);let p=l.scrollLeft-d,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function mg(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=c.top;break}}return{refDOM:r,refTop:i,stack:mf(n.dom)}}function mf(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ti(r));return e}function gg({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;gf(t,r==0?0:r-e)}function gf(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&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={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=f+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?wg(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:yf(t,i)}function wg(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 ql(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function bg(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 Sg(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function wf(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;oi&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.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=Sg(n,r,i,e))}l==null&&(l=xg(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Vh(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Qr(zt(bt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return xl(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1],a=c.nodeType==3?bt(c,Le(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Qr(zt(a,1),!1)}if(s==null&&i=0)}function Qr(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 xl(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 xf(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 Mg(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return xf(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=bf(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=bt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Ag=/[\u0590-\u08ac]/;function Eg(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?!Ag.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:xf(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,f),c&&(c!=h||a!=f)&&l.extend&&l.extend(c,a)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var Bh=null,Ph=null,Lh=!1;function Tg(n,e,t){return Bh==e&&Ph==t?Lh:(Bh=e,Ph=t,Lh=t=="up"||t=="down"?Mg(n,e,t):Eg(n,e,t))}var ze=0,zh=1,un=2,et=3,bn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ze,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;tse(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 As){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 Cs&&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?se(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=se(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let d=document.createRange();d.setEnd(c.node,c.offset),d.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(d)}}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,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?un:zh,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=et:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?un:et}r=o}this.dirty=un}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?un:zh;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==ze&&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}},Dl=class extends bn{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}},ir=class n extends bn{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Bt.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&et||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=et&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ze){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Rl(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,f=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:f}=Bt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=Cf(h,r,t),a?c=new Ol(e,t,r,i,h,f||null,d,a,s,o+1):t.isText?new Ms(e,t,r,i,h,d,s):new n(e,t,r,i,h,f||null,d,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=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==ze&&e.eq(this.node)&&Es(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,c=new Il(this,o&&o.node,e);Ig(this.node,this.innerDeco,(a,h,f)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!f&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,f,d)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,f,u,e)||c.updateNextNode(a,h,f,e,d,i)||c.addNode(a,h,f,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==un)&&(o&&this.protectLocalComposition(e,o),Sf(this.contentDOM,this.children,e),rr&&Rg(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||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=vg(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 Dl(this,s,t,i);e.input.compositionNodes.push(o),this.children=Rl(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==et||!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=ze}updateOuterDeco(e){if(Es(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=kf(this.dom,this.nodeDOM,Nl(this.outerDeco,this.node,t),Nl(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 Fh(n,e,t,r,i){Cf(r,e,n);let s=new Ht(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Ms=class n extends Ht{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==et||this.dirty!=ze&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ze||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=ze,!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=et)}get domAtom(){return!1}isText(e){return this.node.text==e}},As=class extends bn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ze&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ol=class extends Ht{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==et)return!1;if(this.spec.update){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):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 Sf(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 c=ir.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,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,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof ir)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Ng(n,e){return n.type.side-e.type.side}function Ig(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+d.nodeSize;if(d.isText){let g=p;o!g.inline):l.slice();r(d,m,e.forChild(s,d),u),s=p}}function Rg(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 vg(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Rl(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function Hl(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),c,a;if(vs(t)){for(c=o;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&k.isSelectable(f)&&i.parent&&!(f.isInline&&cg(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new k(o==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,d=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Mf(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ug(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,se(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&Ee&&qt<=11&&(r.disabled=!0,r.disabled=!1)}function Af(n,e){if(e instanceof k){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(jh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else jh(n)}function jh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Jl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Wh(n){return n.editable&&!n.hasFocus()?!1:Ef(n)}function Ef(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 Vg(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return wn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function vl(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&&S.findFrom(s,e)}function Ft(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Kh(n,e,t){let r=n.state.selection;if(r instanceof A)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 Ft(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=vl(n.state,e);return i&&i instanceof k?Ft(n,i):!1}else if(!(Pe&&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?k.isSelectable(s)?Ft(n,new k(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):oi?Ft(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof k&&r.node.isInline)return Ft(n,new A(e>0?r.$to:r.$from));{let i=vl(n.state,e);return i?Ft(n,i):!1}}}function Ts(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ei(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function er(n,e){return e<0?Bg(n):Pg(n)}function Bg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(We&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(ei(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Tf(t))break;{let l=t.previousSibling;for(;l&&ei(l,-1);)i=t.parentNode,s=se(l),l=l.previousSibling;if(l)t=l,r=Ts(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?_l(n,t,r):i&&_l(n,i,s)}function Pg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Ts(t),s,o;for(;;)if(r{n.state==i&&xt(n)},50)}function Yh(n,e){let t=n.state.doc.resolve(e);if(!(ue||fg)&&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 Gh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Pe&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=vl(n.state,e);if(o&&o instanceof k)return Ft(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Ie?S.near(o,e):S.findFrom(o,e);return l?Ft(n,l):!1}return!1}function Xh(n,e){if(!(n.state.selection instanceof A))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 Qh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Fg(n){if(!be||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;Qh(n,r,"true"),setTimeout(()=>Qh(n,r,"false"),20)}return!1}function $g(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function qg(n,e){let t=e.keyCode,r=$g(e);if(t==8||Pe&&t==72&&r=="c")return Xh(n,-1)||er(n,-1);if(t==46&&!e.shiftKey||Pe&&t==68&&r=="c")return Xh(n,1)||er(n,1);if(t==13||t==27)return!0;if(t==37||Pe&&t==66&&r=="c"){let i=t==37?Yh(n,n.state.selection.from)=="ltr"?-1:1:-1;return Kh(n,i,r)||er(n,i)}else if(t==39||Pe&&t==70&&r=="c"){let i=t==39?Yh(n,n.state.selection.from)=="ltr"?1:-1:1;return Kh(n,i,r)||er(n,i)}else{if(t==38||Pe&&t==80&&r=="c")return Gh(n,-1,r)||er(n,-1);if(t==40||Pe&&t==78&&r=="c")return Fg(n)||Gh(n,1,r)||er(n,1);if(r==(Pe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Df(n,e){n.someProp("transformCopied",u=>{e=u(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 u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Bt.fromSchema(n.state.schema),l=_f(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,f=0;for(;a&&a.nodeType==1&&(h=vf[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),f++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,`
-`);return{dom:c,text:d,slice:e}}function Rf(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",d=>{e=d(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,`
-`))),0,0):b.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:u}=n.state,p=Vt.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=Kg(t),oi&&Yg(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let f=+h[3];f>0;f--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Wn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Jg.test(d.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Gg(nf(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(jg(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let u=l.content.firstChild;f{l=f(l,n)}),l}var Jg=/^(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 jg(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 c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&_f(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Uf(o[o.length-1],s.length));let h=vf(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function vf(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function _f(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(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function nf(n,e,t){return et}).createHTML(n):n}function Kg(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Bf().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Vf[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>""+s+">").reverse().join("")),t.innerHTML=Wg(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var xe={},Se={},Xg={touchstart:!0,touchmove:!0},Vl=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.lastAndroidDelete=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 Qg(n){for(let e in xe){let t=xe[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{ey(n,r)&&!jl(n,r)&&(n.editable||!(r.type in Se))&&t(n,r)},Xg[e]?{passive:!0}:void 0)}be&&n.dom.addEventListener("input",()=>null),Bl(n)}function Ft(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Zg(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 Bl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>jl(n,r))})}function jl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function ey(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 ty(n,e){!jl(n,e)&&xe[e.type]&&(n.editable||!(e.type in Se))&&xe[e.type](n,e)}Se.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Lf(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(We&&ue&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),rr&&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,fn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Hg(n,t)?t.preventDefault():Ft(n,"key")};Se.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Se.keypress=(n,e)=>{let t=e;if(Lf(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Pe&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!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 _s(n){return{left:n.clientX,top:n.clientY}}function ny(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Wl(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 nr(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 ry(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&k.isSelectable(r)?(nr(n,new k(t),"pointer"),!0):!1}function iy(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof k&&(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(k.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?(nr(n,k.create(n.state.doc,i),"pointer"),!0):!1}function sy(n,e,t,r,i){return Wl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?iy(n,t):ry(n,t))}function oy(n,e,t,r){return Wl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function ly(n,e,t,r){return Wl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||cy(n,t,r)}function cy(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(nr(n,A.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)nr(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(k.isSelectable(o))nr(n,k.create(r,l),"pointer");else continue;return!0}}function Kl(n){return Ds(n)}var Pf=Pe?"metaKey":"ctrlKey";xe.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Kl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&ny(t,n.input.lastClick)&&!t[Pf]&&(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(_s(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Pl(n,o,t,!!r)):(s=="doubleClick"?oy:ly)(n,o.pos,o.inside,t)?t.preventDefault():Ft(n,"pointer"))};var Pl=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[Pf],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof k&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ke&&!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)),Ft(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(()=>St(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(_s(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ft(this.view,"pointer"):sy(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||be&&this.mightDrag&&!this.mightDrag.node.isAtom||ue&&!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)?(nr(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Ft(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ft(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)}};xe.touchstart=n=>{n.input.lastTouch=Date.now(),Kl(n),Ft(n,"pointer")};xe.touchmove=n=>{n.input.lastTouch=Date.now(),Ft(n,"pointer")};xe.contextmenu=n=>Kl(n);function Lf(n,e){return n.composing?!0:be&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var ay=We?5e3:-1;Se.compositionstart=Se.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),Ds(n,!0),n.markCursor=null;else if(Ds(n,!e.selection.empty),Ke&&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}zf(n,ay)};Se.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++,zf(n,20))};function zf(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Ds(n),e))}function Ff(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=fy());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function hy(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lg(e.focusNode,e.focusOffset),r=cg(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 fy(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Ds(n,e=!1){if(!(We&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ff(n),e||n.docView&&n.docView.dirty){let t=Hl(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 dy(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 ni=Ee&&$t<15||rr&&ug<604;xe.copy=Se.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=ni?null:t.clipboardData,o=r.content(),{dom:l,text:c}=If(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):dy(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function uy(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function py(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?ri(n,r.value,null,i,e):ri(n,r.textContent,r.innerHTML,i,e)},50)}function ri(n,e,t,r,i){let s=Rf(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=uy(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 $f(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," "):""}Se.paste=(n,e)=>{let t=e;if(n.composing&&!We)return;let r=ni?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&ri(n,$f(r),r.getData("text/html"),i,t)?t.preventDefault():py(n,t)};var Os=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},qf=Pe?"altKey":"ctrlKey";xe.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(_s(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof k?i.to-1:i.to))){if(r&&r.mightDrag)o=k.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=k.create(n.state.doc,f.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=If(n,l);(!t.dataTransfer.files.length||!ue||yf>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ni?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",ni||t.dataTransfer.setData("text/plain",a),n.dragging=new Os(h,!t[qf],o)};xe.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Se.dragover=Se.dragenter=(n,e)=>e.preventDefault();Se.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(_s(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=Rf(n,$f(t.dataTransfer),ni?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[qf]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Ch(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),f=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,d=a.doc;if(f?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(d))return;let u=a.doc.resolve(h);if(f&&k.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new k(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(Jl(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};xe.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())&&St(n)},20))};xe.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)};xe.beforeinput=(n,e)=>{if(ue&&We&&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,fn(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 Se)xe[n]=Se[n];function ii(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 Ns=class n{constructor(e,t){this.toDOM=e,this.spec=t||mn,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 se(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&&ii(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},pn=class n{constructor(e,t){this.attrs=e,this.spec=t||mn}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 se(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==de||e.maps.length==0?this:this.mapInner(e,t,0,0,r||mn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Jf(t,l,a)){for(i||(i=this.children.slice());sl&&f.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&&c.type instanceof pn){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,mn));return n.from(r)}forChild(e,t){if(t.isLeaf)return L.empty;let r=[];for(let i=0;it instanceof L)?e:e.reduce((t,r)=>t.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-d);for(let y=0;yE+h-f)continue;let N=l[y]+h-f;u>=N?l[y+1]=d<=N?-2:-1:d>=h&&g&&(l[y]+=g,l[y+1]+=g)}f+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let d=t.map(n[a+1]+s,-1),u=d-i,{index:p,offset:m}=r.content.findIndex(f),g=r.maybeChild(p);if(g&&m==f&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=de?(l[a]=f,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=gy(l,n,e,t,i,s,o),h=Rs(a,r,0,o);e=h.local;for(let f=0;ft&&o.to{let a=Jf(n,l,c+t);if(a){s=!0;let h=Rs(a,l,t+c+1,r);h!=de&&i.push(c,c+l.nodeSize,h)}});let o=Hf(s?jf(n):n,-t).sort(gn);for(let l=0;l0;)e++;n.splice(e,0,t)}function kl(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=de&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),Is.from(e)}var yy={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wy=Ee&&$t<=11,zl=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}},Fl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new zl,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()}),wy&&(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,yy)),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(Gh(this.view)){if(this.suppressingSelectionUpdates)return St(this.view);if(Ee&&$t<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&yn(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=ti(s))t.add(s);for(let s=e.anchorNode;s;s=ti(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}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&Gh(this.view)&&!this.ignoreSelectionChange(e)}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.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hf.nodeName=="BR");if(h.length==2){let[f,d]=h;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of h){let u=d.parentNode;u&&u.nodeName=="LI"&&(!f||Sy(e,f)!=u)&&d.remove()}}}let a=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),by(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||St(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 h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let f=n.state.doc,d=n.someProp("domParser")||Wn.fromSchema(n.state.schema),u=f.resolve(o),p=null,m=d.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Cy,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function Cy(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(be&&/^(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||be&&/^(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 My=/^(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 Ay(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Ut=Hl(n,T);if(Ut&&!n.state.selection.eq(Ut)){if(ue&&We&&n.input.lastKeyCode===13&&Date.now()-100dm(n,fn(13,"Enter"))))return;let ls=n.state.tr.setSelection(Ut);T=="pointer"?ls.setMeta("pointer",!0):T=="key"&&ls.scrollIntoView(),s&&ls.setMeta("composition",s),n.dispatch(ls)}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 c=n.state.selection,a=ky(n,e,t),h=n.state.doc,f=h.slice(a.from,a.to),d,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||We)&&i.some(T=>T.nodeType==1&&!My.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=af(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Ut=n.state.tr.setSelection(T);s&&Ut.setMeta("composition",s),n.dispatch(Ut)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),Ee&&$t<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((rr&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ty(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,fn(8,"Backspace")))){We&&ue&&n.domObserver.suppressSelectionUpdates();return}ue&&We&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),We&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,fn(13,"Enter"))})},20));let Ae=p.start,we=p.endA,Q,gt,_t;if(E){if(m.pos==g.pos)Ee&&$t<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>St(n),20)),Q=n.state.tr.delete(Ae,we),gt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(_t=Ey(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Q=n.state.tr,_t.type=="add"?Q.addMark(Ae,we,_t.mark):Q.removeMark(Ae,we,_t.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Ut=>Ut(n,Ae,we,T)))return;Q=n.state.tr.insertText(T,Ae,we)}}if(Q||(Q=n.state.tr.replace(Ae,we,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=af(n,Q.doc,a.sel);T&&!(ue&&We&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:Jl(n,e.resolve(t.anchor),e.resolve(t.head))}function Ey(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Cl(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 Dy(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 c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var $l=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 Vl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(mf),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=uf(this),df(this),this.nodeViews=pf(this),this.docView=Hh(this.state.doc,ff(this),kl(this),this.dom,this),this.domObserver=new Fl(this,(r,i,s,o)=>Ay(this,r,i,s,o)),this.domObserver.start(),Qg(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&&Bl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(mf),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&&(Ff(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 u=pf(this);Ny(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Bl(this),this.editable=uf(this),df(this);let c=kl(this),a=ff(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,a,c);(f||!e.selection.eq(i.selection))&&(o=!0);let d=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&gg(this);if(o){this.domObserver.stop();let u=f&&(Ee||ue)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Oy(i.selection,e.selection);if(f){let p=ue?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=hy(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Hh(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Bg(this))?St(this,u):(Df(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),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():d&&yg(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof k){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ph(this,t.getBoundingClientRect(),e)}else Ph(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 Os(e.slice,e.move,i<0?void 0:k.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 Cg(this,e)}coordsAtPos(e,t=1){return kf(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 Dg(this,t||this.state,e)}pasteHTML(e,t){return ri(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ri(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Zg(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],kl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,sg())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ty(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?be&&this.root.nodeType===11&&hg(this.dom.ownerDocument)==this.dom&&xy(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function ff(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"),[se.node(0,n.state.doc.content.size,e)]}function df(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:se.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function uf(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Oy(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 pf(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 Ny(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 mf(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 Iy=["p",0],Ry=["blockquote",0],vy=["hr"],_y=["pre",["code",0]],Uy=["br"],Vy={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Iy}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Ry}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return vy}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return _y}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Uy}}},By=["em",0],Py=["strong",0],Ly=["code",0],zy={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return By}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Py}},code:{parseDOM:[{tag:"code"}],toDOM(){return Ly}}},Fy=new Hr({nodes:Vy,marks:zy});var Kf=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function $y(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var qy=(n,e,t)=>{let r=$y(n,t);if(!r)return!1;let i=Yf(r);if(!i){let o=r.blockRange(),l=o&&an(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Qf(n,i,e,-1))return!0;if(r.parent.content.size==0&&(sr(s,"end")||k.isSelectable(s)))for(let o=r.depth;;o--){let l=xs(n.doc,r.before(o),r.after(o),b.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};function sr(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 Hy=(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=Yf(r)}let o=s&&s.nodeBefore;return!o||!k.isSelectable(o)?!1:(e&&e(n.tr.setSelection(k.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Yf(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 Jy(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Jy(n,t);if(!r)return!1;let i=Gf(r);if(!i)return!1;let s=i.nodeAfter;if(Qf(n,i,e,1))return!0;if(r.parent.content.size==0&&(sr(s,"start")||k.isSelectable(s))){let o=xs(n.doc,r.before(),r.after(),b.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 k,i;if(r){if(t.node.isTextblock||!wt(n.doc,t.from))return!1;i=t.from}else if(i=pl(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(k.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Xf=(n,e)=>{let t=n.selection,r;if(t instanceof k){if(t.node.isTextblock||!wt(n.doc,t.to))return!1;r=t.to}else if(r=pl(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},ci=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&an(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Ky=(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 Xl(n){for(let e=0;e