@qxs-bns/components-wc 0.0.25 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/es/editor/blocksuite-editor.mjs +312 -43
  2. package/es/editor/blocksuite-editor.mjs.map +1 -1
  3. package/es/entry-subject.mjs +1 -1
  4. package/es/index.mjs +1 -1
  5. package/es/subject/blank-fill.mjs +34 -56
  6. package/es/subject/blank-fill.mjs.map +1 -1
  7. package/es/subject/draft.mjs +2 -0
  8. package/es/subject/draft.mjs.map +1 -0
  9. package/es/subject/list.mjs +57 -99
  10. package/es/subject/list.mjs.map +1 -1
  11. package/es/subject/page-end.mjs +3 -3
  12. package/es/subject/page-end.mjs.map +1 -1
  13. package/es/subject/pagination.mjs +2 -0
  14. package/es/subject/pagination.mjs.map +1 -0
  15. package/es/subject/runtime.mjs +2 -0
  16. package/es/subject/runtime.mjs.map +1 -0
  17. package/es/subject/scale.mjs +101 -152
  18. package/es/subject/scale.mjs.map +1 -1
  19. package/es/subject/single.mjs +89 -88
  20. package/es/subject/single.mjs.map +1 -1
  21. package/es/subject/sort-controller.mjs +2 -0
  22. package/es/subject/sort-controller.mjs.map +1 -0
  23. package/es/subject/sortable.mjs +30 -0
  24. package/es/subject/sortable.mjs.map +1 -0
  25. package/es/subject/sorting-card.mjs +52 -0
  26. package/es/subject/sorting-card.mjs.map +1 -0
  27. package/es/subject/text-fill.mjs +24 -45
  28. package/es/subject/text-fill.mjs.map +1 -1
  29. package/es/subject/types.mjs +1 -1
  30. package/es/subject/types.mjs.map +1 -1
  31. package/lib/editor/blocksuite-editor.cjs +304 -35
  32. package/lib/editor/blocksuite-editor.cjs.map +1 -1
  33. package/lib/entry-subject.cjs +1 -1
  34. package/lib/index.cjs +1 -1
  35. package/lib/subject/blank-fill.cjs +24 -46
  36. package/lib/subject/blank-fill.cjs.map +1 -1
  37. package/lib/subject/draft.cjs +2 -0
  38. package/lib/subject/draft.cjs.map +1 -0
  39. package/lib/subject/list.cjs +16 -58
  40. package/lib/subject/list.cjs.map +1 -1
  41. package/lib/subject/page-end.cjs +3 -3
  42. package/lib/subject/page-end.cjs.map +1 -1
  43. package/lib/subject/pagination.cjs +2 -0
  44. package/lib/subject/pagination.cjs.map +1 -0
  45. package/lib/subject/runtime.cjs +2 -0
  46. package/lib/subject/runtime.cjs.map +1 -0
  47. package/lib/subject/scale.cjs +98 -149
  48. package/lib/subject/scale.cjs.map +1 -1
  49. package/lib/subject/single.cjs +89 -88
  50. package/lib/subject/single.cjs.map +1 -1
  51. package/lib/subject/sort-controller.cjs +2 -0
  52. package/lib/subject/sort-controller.cjs.map +1 -0
  53. package/lib/subject/sortable.cjs +30 -0
  54. package/lib/subject/sortable.cjs.map +1 -0
  55. package/lib/subject/sorting-card.cjs +52 -0
  56. package/lib/subject/sorting-card.cjs.map +1 -0
  57. package/lib/subject/text-fill.cjs +24 -45
  58. package/lib/subject/text-fill.cjs.map +1 -1
  59. package/lib/subject/types.cjs +1 -1
  60. package/lib/subject/types.cjs.map +1 -1
  61. package/package.json +1 -1
@@ -1,6 +1,38 @@
1
- import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/extension-blockquote";import o from"@tiptap/extension-bold";import r from"@tiptap/extension-bullet-list";import l from"@tiptap/extension-code";import s from"@tiptap/extension-document";import n from"@tiptap/extension-heading";import a from"@tiptap/extension-history";import d from"@tiptap/extension-horizontal-rule";import c from"@tiptap/extension-image";import h from"@tiptap/extension-italic";import b from"@tiptap/extension-link";import p from"@tiptap/extension-list-item";import u from"@tiptap/extension-ordered-list";import g from"@tiptap/extension-paragraph";import m from"@tiptap/extension-placeholder";import x from"@tiptap/extension-strike";import{Table as v}from"@tiptap/extension-table";import{TableCell as f}from"@tiptap/extension-table-cell";import{TableHeader as y}from"@tiptap/extension-table-header";import{TableRow as _}from"@tiptap/extension-table-row";import w from"@tiptap/extension-text";import k from"@tiptap/extension-text-align";import C from"@tiptap/extension-underline";import{css as M,LitElement as T,html as $}from"lit";import{property as A,state as R}from"lit/decorators.js";import{safeCustomElement as B}from"../base/define.mjs";var P=Object.defineProperty,S=Object.getOwnPropertyDescriptor,q=(e,t,i,o)=>{for(var r,l=o>1?void 0:o?S(t,i):t,s=e.length-1;s>=0;s--)(r=e[s])&&(l=(o?r(t,i,l):r(l))||l);return o&&l&&P(t,i,l),l};let V=class extends T{constructor(){super(...arguments),this.content="",this["model-value"]="",this.placeholder="输入 / 唤出快捷命令",this["use-model"]="false",this.readonly="false",this.preview="false",this["custom-styles"]="",this._injectedStyleEl=null,this["upload-image"]=async e=>new Promise((t,i)=>{const o=new FileReader;o.onload=e=>t(e.target?.result),o.onerror=i,o.readAsDataURL(e)}),this._editor=null,this._pendingContent=null,this._tableRows=3,this._tableCols=3,this._hoverRow=0,this._hoverCol=0,this._tableDropdownOpen=!1,this._tableCellToolbar={x:0,y:0,visible:!1,cellRow:0,cellCol:0},this._imageToolbar={x:0,y:0,visible:!1},this._imageMoreMenuVisible=!1,this._hasSlashCommand=!1,this._isUpdating=!1,this._tableEdgeDetectionSetup=!1}_injectCustomStyles(){const e=this.shadowRoot;if(!e)return;if(this._injectedStyleEl&&(this._injectedStyleEl.remove(),this._injectedStyleEl=null),!this["custom-styles"])return;const t=document.createElement("style");t.textContent=this["custom-styles"],e.appendChild(t),this._injectedStyleEl=t}get _useModelValue(){return!0===this["use-model"]||"true"===this["use-model"]||""===this["use-model"]||this.hasAttribute("use-model")}get _readonlyValue(){return!1!==this.readonly&&"false"!==this.readonly}get _previewValue(){return!1!==this.preview&&"false"!==this.preview}_initEditor(){if(this._editor)return;const M=this.shadowRoot?.querySelector(".editor-content");if(!M)return void requestAnimationFrame(()=>this._initEditor());for(;M.firstChild;)M.removeChild(M.firstChild);const T=this._useModelValue,$=this.getAttribute("model-value")??this["model-value"],A=this.content,R=T?(this._pendingContent??$)||"<p></p>":(this._pendingContent??A)||"<p></p>",B=[s,g,w,o,h,C,x,l,n.configure({levels:[1,2,3]}),r,u,p,i,d,a,c.configure({inline:!1,allowBase64:!0}),b.configure({openOnClick:!1,HTMLAttributes:{rel:"noopener noreferrer"}}),k.configure({types:["heading","paragraph"]}),v.configure({resizable:!0}),_,f,y,m.configure({placeholder:this.placeholder}),e.create({name:"clearMarksOnEnter",addKeyboardShortcuts(){return{Enter:()=>(this.editor.chain().focus().unsetAllMarks().clearNodes().run(),!1)}}})];this._editor=new t({element:M,extensions:B,editable:!this._readonlyValue,content:R}),this._pendingContent=null,this._editor.on("selectionUpdate",()=>{this._updateBubbleMenuPosition(),this._editor?.isActive("table")?this._showTableCellToolbar():this._hideTableCellToolbar();const e=this._editor;if(e){const{selection:t}=e.state,{$from:i}=t;if("image"===i.node(i.depth).type.name){const t=e.view.coordsAtPos(i.start()),o=this.shadowRoot?.querySelector(".editor-wrapper")?.getBoundingClientRect();if(o){const e=t.left-o.left+(t.right-t.left)/2,i=t.top-o.top-40;this._showImageToolbar({x:e,y:i})}}else this._hideImageToolbar()}}),this._editor.on("transaction",()=>{this._editor?.isActive("table")?this._showTableCellToolbar():this._hideTableCellToolbar(),this._checkSlashCommand(),this._setupTableEdgeDetection()}),this._editor.on("update",()=>{this._emitContentChange()})}_emitContentChange(){if(!this._editor)return;const e=this._editor.getHTML();this.dispatchEvent(new CustomEvent("content-change",{detail:e,bubbles:!0,composed:!0}))}_setupTableEdgeDetection(){const e=this.shadowRoot?.querySelector(".editor-content"),t=this.shadowRoot?.querySelector(".editor-wrapper");if(!e||this._tableEdgeDetectionSetup)return;this._tableEdgeDetectionSetup=!0;const i=()=>{this._editor?.chain().focus().run()};e.addEventListener("click",i),t?.addEventListener("click",i)}_checkSlashCommand(){if(!this._editor)return;const{selection:e}=this._editor.state,t=this._editor.state.doc.textBetween(Math.max(0,e.from-10),e.from," ");this._hasSlashCommand=t.endsWith("/")}firstUpdated(){this._injectCustomStyles(),this._initEditor()}updated(e){if(e.has("custom-styles")&&this._injectCustomStyles(),this._editor){if(e.has("content")||e.has("model-value")&&this._useModelValue){const e=this._useModelValue?this["model-value"]:this.content;e!==this._editor.getHTML()&&this._editor.commands.setContent(e||"<p></p>")}e.has("readonly")&&this._editor.setEditable(!this._readonlyValue)}else e.has("content")&&(this._pendingContent=this.content),e.has("model-value")&&this._useModelValue&&(this._pendingContent=this["model-value"])}disconnectedCallback(){super.disconnectedCallback(),this._editor?.destroy(),this._editor=null}getContent(){return this._editor?.getHTML()??""}forceUpdate(){if(this.requestUpdate(),this._editor){const e=this._useModelValue?this["model-value"]:this.content;e!==this._editor.getHTML()&&this._editor.commands.setContent(e||"<p></p>")}}_applyFormat(e){if(this._hasSlashCommand&&this._editor){const{selection:e}=this._editor.state;this._editor.chain().focus().deleteRange({from:e.from-1,to:e.from}).run(),this._hasSlashCommand=!1}e()}_toggleBold(){this._applyFormat(()=>this._editor?.chain().focus().toggleBold().run())}_toggleItalic(){this._applyFormat(()=>this._editor?.chain().focus().toggleItalic().run())}_toggleUnderline(){this._applyFormat(()=>this._editor?.chain().focus().toggleUnderline().run())}_toggleStrike(){this._applyFormat(()=>this._editor?.chain().focus().toggleStrike().run())}_toggleCode(){this._applyFormat(()=>this._editor?.chain().focus().toggleCode().run())}_setHeading(e){this._applyFormat(()=>this._editor?.chain().focus().toggleHeading({level:e}).run())}_setParagraph(){this._applyFormat(()=>this._editor?.chain().focus().setParagraph().run())}_toggleBulletList(){this._applyFormat(()=>this._editor?.chain().focus().toggleBulletList().run())}_toggleOrderedList(){this._applyFormat(()=>this._editor?.chain().focus().toggleOrderedList().run())}_toggleBlockquote(){this._applyFormat(()=>this._editor?.chain().focus().toggleBlockquote().run())}_setTextAlign(e){this._applyFormat(()=>this._editor?.chain().focus().setTextAlign(e).run())}_setLink(){const e=window.prompt("请输入链接地址:");e&&this._applyFormat(()=>this._editor?.chain().focus().setLink({href:e}).run())}_insertTable(e,t){this._editor?.chain().focus().insertTable({rows:e??this._tableRows,cols:t??this._tableCols,withHeaderRow:!0}).run()}async _handleImageUpload(e){const t=e.target,i=t.files?.[0];if(i)try{const e=await this["upload-image"](i);this._editor?.chain().focus().setImage({src:e}).run()}catch(e){}t.value=""}_triggerImageUpload(){const e=this.shadowRoot?.querySelector(".image-input");e?.click()}_insertTableByClick(e,t){if(this._hasSlashCommand&&this._editor){const{selection:e}=this._editor.state;this._editor.chain().focus().deleteRange({from:e.from-1,to:e.from}).run(),this._hasSlashCommand=!1}this._tableRows=e,this._tableCols=t,this._insertTable(e,t)}_showTableCellToolbar(){if(!this._editor?.isActive("table"))return;const{state:e}=this._editor,{selection:t}=e,i=this._editor.view.coordsAtPos(t.from),o=this.shadowRoot?.querySelector(".editor-wrapper");if(!o)return;const r=o.getBoundingClientRect(),l=this._getTableCellRow(),s=this._getTableCellCol();(0===l||0===s)&&requestAnimationFrame(()=>{this._tableCellToolbar={x:i.left-r.left,y:i.bottom-r.top+8,visible:!0,cellRow:l,cellCol:s}})}_getTableCellRow(){if(!this._editor)return 0;const{selection:e}=this._editor.state,t=this._editor.state.doc.resolve(e.from);for(let e=t.depth;e>0;e--){if("tableCell"===t.node(e).type.name)return t.index(e-1)}return 0}_getTableCellCol(){if(!this._editor)return 0;const{selection:e}=this._editor.state,t=this._editor.state.doc.resolve(e.from);for(let e=t.depth;e>0;e--){if("tableCell"===t.node(e).type.name)return t.index(e)}return 0}_hideTableCellToolbar(){requestAnimationFrame(()=>{this._tableCellToolbar={...this._tableCellToolbar,visible:!1}})}_addTableRowAbove(){this._editor?.chain().focus().addRowBefore().run(),this._hideTableCellToolbar()}_addTableRowBelow(){this._editor?.chain().focus().addRowAfter().run(),this._hideTableCellToolbar()}_addTableColumnLeft(){this._editor?.chain().focus().addColumnBefore().run(),this._hideTableCellToolbar()}_addTableColumnRight(){this._editor?.chain().focus().addColumnAfter().run(),this._hideTableCellToolbar()}_deleteTableRow(){this._editor?.chain().focus().deleteRow().run(),this._hideTableCellToolbar()}_deleteTableColumn(){this._editor?.chain().focus().deleteColumn().run(),this._hideTableCellToolbar()}_deleteTable(){this._editor?.chain().focus().deleteTable().run(),this._hideTableCellToolbar()}_showImageToolbar(e){requestAnimationFrame(()=>{this._imageToolbar={x:e.x,y:e.y,visible:!0},this._imageMoreMenuVisible=!1})}_hideImageToolbar(){requestAnimationFrame(()=>{this._imageToolbar={...this._imageToolbar,visible:!1},this._imageMoreMenuVisible=!1})}_toggleImageMoreMenu(){this._imageMoreMenuVisible=!this._imageMoreMenuVisible}_deleteImage(){this._editor?.chain().focus().deleteNode("image").run(),this._hideImageToolbar()}_insertImageAfter(){this._triggerImageUpload(),this._imageMoreMenuVisible=!1}_setImageAlignLeft(){const e=this._editor;if(e){const{selection:t}=e.state,i=t.from;e.chain().focus().setNodeSelection(i).run();const o=this.shadowRoot?.querySelector(".ProseMirror img.ProseMirror-selectednode");o&&(o.style.display="block",o.style.margin="0 auto 0 0")}this._imageMoreMenuVisible=!1}_setImageAlignCenter(){const e=this._editor;if(e){const{selection:t}=e.state,i=t.from;e.chain().focus().setNodeSelection(i).run();const o=this.shadowRoot?.querySelector(".ProseMirror img.ProseMirror-selectednode");o&&(o.style.display="block",o.style.margin="0 auto")}this._imageMoreMenuVisible=!1}_setImageAlignRight(){const e=this._editor;if(e){const{selection:t}=e.state,i=t.from;e.chain().focus().setNodeSelection(i).run();const o=this.shadowRoot?.querySelector(".ProseMirror img.ProseMirror-selectednode");o&&(o.style.display="block",o.style.margin="0 0 0 auto")}this._imageMoreMenuVisible=!1}_getTextLabel(){const e=this._editor;return e?e.isActive("heading",{level:1})?"标题 1":e.isActive("heading",{level:2})?"标题 2":e.isActive("heading",{level:3})?"标题 3":"正文":"正文"}_getAlignLabel(){const e=this._editor;return e?e.isActive({textAlign:"center"})?"居中":e.isActive({textAlign:"right"})?"右对齐":"左对齐":"对齐"}_updateBubbleMenuPosition(){requestAnimationFrame(()=>{const e=this.shadowRoot?.querySelector(".bubble-menu"),t=this.shadowRoot?.querySelector(".ProseMirror"),i=this.shadowRoot?.querySelector(".editor-wrapper");if(!e||!t||!i)return;const o=this._editor,r=o?.isActive("table")??!1,{selection:l}=o?.state??{selection:null};if(r&&l&&!l.empty&&o){const{from:t,to:i}=l,r=o.state.doc.resolve(t),s=o.state.doc.resolve(i);let n=!1;for(let e=r.depth;e>=0;e--)if("table"===r.node(e).type.name){n=!0;break}const a=r.node(r.depth),d=s.node(s.depth);if("table"!==a.type.name&&"table"!==d.type.name||(n=!0),n)return e.style.opacity="0",void(e.style.visibility="hidden")}if(l&&!l.empty);else if(!l||l.empty&&!this._hasSlashCommand)return e.style.opacity="0",void(e.style.visibility="hidden");const s=i.getBoundingClientRect(),n=e.getBoundingClientRect(),{from:a}=l,d=this._editor?.view.coordsAtPos(a);if(!d)return;let c=d.left-s.left,h=d.top-s.top-40;c+n.width>s.width&&(c=s.width-n.width-8),c<0&&(c=8),h<0&&(h=d.bottom-s.top+8),e.style.left=`${c}px`,e.style.top=`${h}px`,e.style.opacity="1",e.style.visibility="visible"})}render(){const e=this._editor;return $`
2
- <div class="editor-wrapper ${e?"":"loading"} ${this._previewValue?"preview":""}">
3
- ${e?"":$`
1
+ import{Node as e,mergeAttributes as t,Editor as i}from"@tiptap/core";import o from"@tiptap/extension-blockquote";import r from"@tiptap/extension-bold";import s from"@tiptap/extension-bullet-list";import l from"@tiptap/extension-code";import n from"@tiptap/extension-document";import a from"@tiptap/extension-heading";import d from"@tiptap/extension-history";import c from"@tiptap/extension-horizontal-rule";import h from"@tiptap/extension-image";import b from"@tiptap/extension-italic";import p from"@tiptap/extension-link";import u from"@tiptap/extension-list-item";import g from"@tiptap/extension-ordered-list";import m from"@tiptap/extension-paragraph";import x from"@tiptap/extension-placeholder";import v from"@tiptap/extension-strike";import{Table as y}from"@tiptap/extension-table";import{TableCell as _}from"@tiptap/extension-table-cell";import{TableHeader as f}from"@tiptap/extension-table-header";import{TableRow as w}from"@tiptap/extension-table-row";import k from"@tiptap/extension-text";import C from"@tiptap/extension-text-align";import $ from"@tiptap/extension-underline";import{css as M,LitElement as T,html as A}from"lit";import{property as I,state as S}from"lit/decorators.js";import{safeCustomElement as B}from"../base/define.mjs";var L=Object.defineProperty,R=Object.getOwnPropertyDescriptor,P=(e,t,i,o)=>{for(var r,s=o>1?void 0:o?R(t,i):t,l=e.length-1;l>=0;l--)(r=e[l])&&(s=(o?r(t,i,s):r(s))||s);return o&&s&&L(t,i,s),s};const V="输入内容",E="输入 / 唤出快捷命令",H=e.create({name:"taskList",group:"block list",content:"taskItem+",defining:!0,parseHTML:()=>[{tag:'ul[data-type="taskList"]'}],renderHTML(e){let{HTMLAttributes:i}=e;return["ul",t(i,{"data-type":"taskList"}),0]},addCommands(){return{toggleTaskList:()=>e=>{let{commands:t}=e;return t.toggleList(this.name,"taskItem")}}}}),z=e.create({name:"taskItem",defining:!0,content:"paragraph block*",addAttributes:()=>({checked:{default:!1,parseHTML:e=>"true"===e.getAttribute("data-checked"),renderHTML:e=>({"data-checked":String(Boolean(e.checked))})}}),parseHTML:()=>[{tag:'li[data-type="taskItem"]'}],renderHTML(e){let{HTMLAttributes:i}=e;const o=Boolean(i.checked);return["li",t(i,{"data-type":"taskItem"}),["label",{contenteditable:"false"},["input",{type:"checkbox",checked:o?"checked":null}],["span"]],["div",0]]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),q=h.extend({addAttributes(){return{...this.parent?.(),width:{default:null,parseHTML:e=>{const t=e.getAttribute("width"),i=Number(t);return Number.isFinite(i)&&i>0?i:null},renderHTML:e=>e.width?{width:String(e.width)}:{}},align:{default:"center",parseHTML:e=>e.getAttribute("data-align")||"center",renderHTML:e=>e.align?{"data-align":String(e.align)}:{}}}},renderHTML(e){let{HTMLAttributes:i}=e;const o=String(i.align||"center"),r=Number(i.width),s=["display:block","max-width:100%","height:auto",`margin:${"left"===o?"0 auto 0 0":"right"===o?"0 0 0 auto":"0 auto"}`,Number.isFinite(r)&&r>0?`width:${r}px`:"",i.style||""].filter(Boolean).join(";");return["img",t(this.options.HTMLAttributes,i,{style:s})]}});let F=class extends T{constructor(){super(...arguments),this.content="",this["model-value"]="",this.placeholder=V,this["toolbar-mode"]="header",this["header-always-visible"]="false",this["use-model"]="false",this.readonly="false",this.preview="false",this["custom-styles"]="",this._injectedStyleEl=null,this["upload-image"]=async e=>new Promise((t,i)=>{const o=new FileReader;o.onload=e=>t(e.target?.result),o.onerror=i,o.readAsDataURL(e)}),this._editor=null,this._pendingContent=null,this._tableRows=3,this._tableCols=3,this._hoverRow=0,this._hoverCol=0,this._tableDropdownOpen=!1,this._tableCellToolbar={x:0,y:0,visible:!1,cellRow:0,cellCol:0},this._imageToolbar={x:0,y:0,visible:!1},this._isEditorFocused=!1,this._selectedImage=null,this._hasSlashCommand=!1,this._slashCommandRange=null,this._isUpdating=!1,this._pendingImageInsertPos=null,this._tableEdgeDetectionSetup=!1}_injectCustomStyles(){const e=this.shadowRoot;if(!e)return;if(this._injectedStyleEl&&(this._injectedStyleEl.remove(),this._injectedStyleEl=null),!this["custom-styles"])return;const t=document.createElement("style");t.textContent=this["custom-styles"],e.appendChild(t),this._injectedStyleEl=t}get _useModelValue(){return!0===this["use-model"]||"true"===this["use-model"]||""===this["use-model"]||this.hasAttribute("use-model")}get _readonlyValue(){return!1!==this.readonly&&"false"!==this.readonly}get _previewValue(){return!1!==this.preview&&"false"!==this.preview}get _isEditable(){return!this._readonlyValue&&!this._previewValue}get _toolbarModeValue(){return"header"===this["toolbar-mode"]?"header":"slash"}get _headerAlwaysVisibleValue(){return!0===this["header-always-visible"]||"true"===this["header-always-visible"]||""===this["header-always-visible"]||this.hasAttribute("header-always-visible")}get _resolvedPlaceholder(){return this.placeholder&&this.placeholder!==V&&this.placeholder!==E?this.placeholder:"header"===this._toolbarModeValue?V:E}_initEditor(){if(this._editor)return;const e=this.shadowRoot?.querySelector(".editor-content");if(!e)return void requestAnimationFrame(()=>this._initEditor());for(;e.firstChild;)e.removeChild(e.firstChild);const t=this._useModelValue,h=this.getAttribute("model-value")??this["model-value"],M=this.content,T=t?(this._pendingContent??h)||"<p></p>":(this._pendingContent??M)||"<p></p>",A=[n,m,k,r,b,$,v,l,a.configure({levels:[1,2,3]}),s,g,H,z,u,o,c,d,q.configure({inline:!1,allowBase64:!0}),p.configure({openOnClick:!1,HTMLAttributes:{rel:"noopener noreferrer"}}),C.configure({types:["heading","paragraph"]}),y.configure({resizable:!0}),w,_,f,x.configure({placeholder:this._resolvedPlaceholder})];this._editor=new i({element:e,extensions:A,editable:this._isEditable,content:T}),this._pendingContent=null,this._editor.on("selectionUpdate",()=>{"slash"===this._toolbarModeValue&&this._updateBubbleMenuPosition(),this._editor?.isActive("table")?this._showTableCellToolbar():this._hideTableCellToolbar(),this._syncImageSelectionState()}),this._editor.on("transaction",()=>{this._editor?.isActive("table")?this._showTableCellToolbar():this._hideTableCellToolbar(),this._checkSlashCommand(),this._setupTableEdgeDetection(),this._syncImageSelectionState()}),this._editor.on("update",()=>{this._emitContentChange()})}_toggleTaskItemChecked(e){const t=e.target,i=this._editor;if(!(t instanceof HTMLInputElement&&"checkbox"===t.type&&i))return;const o=t.closest('li[data-type="taskItem"]');if(!o)return;e.preventDefault(),e.stopPropagation();const r=i.view.posAtDOM(o,0),s=Math.max(0,r-2),l=Math.min(i.state.doc.content.size,r+2);let n=null;if(i.state.doc.nodesBetween(s,l,(e,t)=>{if("taskItem"===e.type.name)return n=t,!1}),null===n)return;const a=i.state.doc.nodeAt(n);a&&"taskItem"===a.type.name&&i.view.dispatch(i.state.tr.setNodeMarkup(n,void 0,{...a.attrs,checked:!a.attrs.checked}))}_emitContentChange(){if(!this._editor)return;const e=this._editor.getHTML();this.dispatchEvent(new CustomEvent("content-change",{detail:e,bubbles:!0,composed:!0}))}_setupTableEdgeDetection(){const e=this.shadowRoot?.querySelector(".editor-content"),t=this.shadowRoot?.querySelector(".editor-wrapper");if(!e||this._tableEdgeDetectionSetup)return;this._tableEdgeDetectionSetup=!0;const i=e=>{this._toggleTaskItemChecked(e);const t=e.target;t instanceof Element&&t.closest(".editor-header, .bubble-menu, .table-cell-toolbar, .image-toolbar")||this._isEditable&&this._editor?.chain().focus().run()};e.addEventListener("click",i),t?.addEventListener("click",i)}_handleWrapperFocusIn(){this._isEditorFocused=!0}_handleWrapperFocusOut(e){const t=e.relatedTarget,i=this.shadowRoot?.querySelector(".editor-wrapper");t&&i?.contains(t)||(this._isEditorFocused=!1,this._tableDropdownOpen=!1)}_isHeaderVisible(){return"header"===this._toolbarModeValue&&!this._previewValue&&(this._headerAlwaysVisibleValue||this._isEditorFocused||this._tableDropdownOpen||Boolean(this._selectedImage))}_getImageSelection(){const e=this._editor,t=e?.state.selection;return e&&t?.node&&"image"===t.node.type?.name?{pos:t.from,attrs:t.node.attrs??{}}:null}_getImageMaxWidth(){const e=this.shadowRoot?.querySelector(".editor-content"),t=(e?.clientWidth??560)-32;return Math.max(24,Math.min(560,t))}async _getImageNaturalWidth(e){return await new Promise(t=>{const i=URL.createObjectURL(e),o=new window.Image;o.onload=()=>{const e=o.naturalWidth;URL.revokeObjectURL(i),t(Number.isFinite(e)&&e>0?e:null)},o.onerror=()=>{URL.revokeObjectURL(i),t(null)},o.src=i})}_syncImageSelectionState(){const e=this._getImageSelection();if(!e)return this._selectedImage=null,void("slash"===this._toolbarModeValue&&this._hideImageToolbar());const t=Number(e.attrs.width),i=String(e.attrs.align||"center");if(this._selectedImage={pos:e.pos,width:Number.isFinite(t)&&t>0?t:this._getImageMaxWidth(),align:i},"slash"!==this._toolbarModeValue)return void this._hideImageToolbar();const o=this._editor,r=this.shadowRoot?.querySelector(".editor-wrapper")?.getBoundingClientRect();if(!o||!r)return;const s=o.view.coordsAtPos(e.pos),l=s.left-r.left+(s.right-s.left)/2,n=s.top-r.top-40;this._showImageToolbar({x:l,y:n})}_clearSlashCommandText(){if(!this._editor||!this._slashCommandRange)return;const{from:e,to:t}=this._slashCommandRange;this._editor.chain().focus().deleteRange({from:e,to:t}).run(),this._hasSlashCommand=!1,this._slashCommandRange=null}_checkSlashCommand(){if(!this._editor)return;const{selection:e}=this._editor.state;if(!e.empty)return this._hasSlashCommand=!1,void(this._slashCommandRange=null);const{$from:t}=e,i=t.parent.textBetween(0,t.parentOffset," "," "),o=/(?:^|\s)(\/\S*)$/.exec(i);if(!o)return this._hasSlashCommand=!1,void(this._slashCommandRange=null);const r=o[1];this._hasSlashCommand=!0,this._slashCommandRange={from:e.from-r.length,to:e.from}}firstUpdated(){this._injectCustomStyles(),this._initEditor()}updated(e){if(e.has("custom-styles")&&this._injectCustomStyles(),this._editor){if(e.has("content")||e.has("model-value")&&this._useModelValue){const e=this._useModelValue?this["model-value"]:this.content;e!==this._editor.getHTML()&&this._editor.commands.setContent(e||"<p></p>")}(e.has("readonly")||e.has("preview"))&&this._editor.setEditable(this._isEditable)}else e.has("content")&&(this._pendingContent=this.content),e.has("model-value")&&this._useModelValue&&(this._pendingContent=this["model-value"])}disconnectedCallback(){super.disconnectedCallback(),this._editor?.destroy(),this._editor=null}getContent(){return this._editor?.getHTML()??""}forceUpdate(){if(this.requestUpdate(),this._editor){const e=this._useModelValue?this["model-value"]:this.content;e!==this._editor.getHTML()&&this._editor.commands.setContent(e||"<p></p>")}}_applyFormat(e){this._clearSlashCommandText(),e()}_toggleBold(){this._applyFormat(()=>this._editor?.chain().focus().toggleBold().run())}_toggleItalic(){this._applyFormat(()=>this._editor?.chain().focus().toggleItalic().run())}_toggleUnderline(){this._applyFormat(()=>this._editor?.chain().focus().toggleUnderline().run())}_toggleStrike(){this._applyFormat(()=>this._editor?.chain().focus().toggleStrike().run())}_toggleCode(){this._applyFormat(()=>this._editor?.chain().focus().toggleCode().run())}_setHeading(e){this._applyFormat(()=>this._editor?.chain().focus().toggleHeading({level:e}).run())}_setParagraph(){this._applyFormat(()=>this._editor?.chain().focus().setParagraph().run())}_toggleBulletList(){this._applyFormat(()=>this._editor?.chain().focus().toggleBulletList().run())}_toggleOrderedList(){this._applyFormat(()=>this._editor?.chain().focus().toggleOrderedList().run())}_toggleTaskList(){this._applyFormat(()=>this._editor?.chain().focus().toggleTaskList().run())}_toggleBlockquote(){this._applyFormat(()=>this._editor?.chain().focus().toggleBlockquote().run())}_setTextAlign(e){this._applyFormat(()=>this._editor?.chain().focus().setTextAlign(e).run())}_setLink(){const e=window.prompt("请输入链接地址:");e&&this._applyFormat(()=>this._editor?.chain().focus().setLink({href:e}).run())}_insertTable(e,t){this._editor?.chain().focus().insertTable({rows:e??this._tableRows,cols:t??this._tableCols,withHeaderRow:!0}).run()}async _handleImageUpload(e){const t=e.target,i=t.files?.[0];if(i)try{const e=await this._getImageNaturalWidth(i),t=await this["upload-image"](i),o=e?Math.min(e,this._getImageMaxWidth()):this._getImageMaxWidth();this._clearSlashCommandText();const r=this._pendingImageInsertPos;this._pendingImageInsertPos=null,null!==r?this._insertImageAt(r,{src:t,width:o,align:"center"}):this._editor?.chain().focus().setImage({src:t,width:o,align:"center"}).run()}catch(e){}t.value=""}_triggerImageUpload(){this._clearSlashCommandText();const e=this.shadowRoot?.querySelector(".image-input");e?.click()}_insertTableByClick(e,t){this._clearSlashCommandText(),this._tableRows=e,this._tableCols=t,this._insertTable(e,t)}_showTableCellToolbar(){if(!this._editor?.isActive("table"))return;const{state:e}=this._editor,{selection:t}=e,i=this._editor.view.coordsAtPos(t.from),o=this.shadowRoot?.querySelector(".editor-wrapper");if(!o)return;const r=o.getBoundingClientRect(),s=this._getTableCellRow(),l=this._getTableCellCol();(0===s||0===l)&&requestAnimationFrame(()=>{this._tableCellToolbar={x:i.left-r.left,y:i.bottom-r.top+8,visible:!0,cellRow:s,cellCol:l}})}_getTableCellRow(){if(!this._editor)return 0;const{selection:e}=this._editor.state,t=this._editor.state.doc.resolve(e.from);for(let e=t.depth;e>0;e--){if("tableCell"===t.node(e).type.name)return t.index(e-1)}return 0}_getTableCellCol(){if(!this._editor)return 0;const{selection:e}=this._editor.state,t=this._editor.state.doc.resolve(e.from);for(let e=t.depth;e>0;e--){if("tableCell"===t.node(e).type.name)return t.index(e)}return 0}_hideTableCellToolbar(){requestAnimationFrame(()=>{this._tableCellToolbar={...this._tableCellToolbar,visible:!1}})}_addTableRowAbove(){this._editor?.chain().focus().addRowBefore().run(),this._hideTableCellToolbar()}_addTableRowBelow(){this._editor?.chain().focus().addRowAfter().run(),this._hideTableCellToolbar()}_addTableColumnLeft(){this._editor?.chain().focus().addColumnBefore().run(),this._hideTableCellToolbar()}_addTableColumnRight(){this._editor?.chain().focus().addColumnAfter().run(),this._hideTableCellToolbar()}_deleteTableRow(){this._editor?.chain().focus().deleteRow().run(),this._hideTableCellToolbar()}_deleteTableColumn(){this._editor?.chain().focus().deleteColumn().run(),this._hideTableCellToolbar()}_deleteTable(){this._editor?.chain().focus().deleteTable().run(),this._hideTableCellToolbar()}_showImageToolbar(e){requestAnimationFrame(()=>{this._imageToolbar={x:e.x,y:e.y,visible:!0}})}_hideImageToolbar(){requestAnimationFrame(()=>{this._imageToolbar={...this._imageToolbar,visible:!1}})}_deleteImage(){const e=this._getSelectedImageNode();if(!e)return;const{editor:t,pos:i,node:o}=e;t.view.dispatch(t.state.tr.delete(i,i+o.nodeSize)),this._selectedImage=null,this._pendingImageInsertPos=null,this._hideImageToolbar()}_insertImageAfter(){const e=this._getSelectedImageNode();e?(this._pendingImageInsertPos=e.pos+e.node.nodeSize,this._triggerImageUpload()):this._triggerImageUpload()}_getSelectedImageNode(){const e=this._editor,t=this._selectedImage?.pos;if(!e||void 0===t)return null;const i=e.state.doc.nodeAt(t);return i&&"image"===i.type.name?{editor:e,pos:t,node:i}:null}_insertImageAt(e,t){const i=this._editor;if(!i)return;const o=Math.max(0,Math.min(e,i.state.doc.content.size));i.chain().insertContentAt(o,{type:"image",attrs:t}).setNodeSelection(o).run()}_updateSelectedImageAttributes(e){const t=this._getSelectedImageNode();if(!t)return;const{editor:i,pos:o,node:r}=t;i.view.dispatch(i.state.tr.setNodeMarkup(o,void 0,{...r.attrs,...e}))}_setImageWidth(e){const t=Math.max(24,Math.min(this._getImageMaxWidth(),Math.round(e)));this._updateSelectedImageAttributes({width:t})}_handleImageWidthInput(e){const t=e.target.value.trim();if(!t)return;const i=Number(t);Number.isFinite(i)&&this._setImageWidth(i)}_setImageAlignLeft(){this._updateSelectedImageAttributes({align:"left"})}_setImageAlignCenter(){this._updateSelectedImageAttributes({align:"center"})}_setImageAlignRight(){this._updateSelectedImageAttributes({align:"right"})}_getTextLabel(){const e=this._editor;return e?e.isActive("heading",{level:1})?"标题 1":e.isActive("heading",{level:2})?"标题 2":e.isActive("heading",{level:3})?"标题 3":"正文":"正文"}_getAlignLabel(){const e=this._editor;return e?e.isActive({textAlign:"center"})?"居中":e.isActive({textAlign:"right"})?"右对齐":"左对齐":"对齐"}_renderImageControls(){const e=this._selectedImage;return e?A`
2
+ <button class="bubble-btn danger" title="删除图片" @click=${this._deleteImage}>
3
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
4
+ </button>
5
+ <button class="bubble-btn" title="添加图片" @click=${this._insertImageAfter}>
6
+ <svg viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
7
+ </button>
8
+ <div class="bubble-divider"></div>
9
+ <button class="bubble-btn ${"left"===e.align?"is-active":""}" title="左对齐" @click=${this._setImageAlignLeft}>
10
+ <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>
11
+ </button>
12
+ <button class="bubble-btn ${"center"===e.align?"is-active":""}" title="居中" @click=${this._setImageAlignCenter}>
13
+ <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>
14
+ </button>
15
+ <button class="bubble-btn ${"right"===e.align?"is-active":""}" title="右对齐" @click=${this._setImageAlignRight}>
16
+ <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>
17
+ </button>
18
+ <div class="image-size-control">
19
+ <span class="image-size-label">宽度</span>
20
+ <input
21
+ class="image-size-range"
22
+ type="number"
23
+ min="${24}"
24
+ max="${this._getImageMaxWidth()}"
25
+ .value=${String(e.width)}
26
+ @input=${this._handleImageWidthInput}
27
+ />
28
+ </div>
29
+ `:""}_updateBubbleMenuPosition(){"slash"===this._toolbarModeValue&&requestAnimationFrame(()=>{const e=this.shadowRoot?.querySelector(".bubble-menu"),t=this.shadowRoot?.querySelector(".ProseMirror"),i=this.shadowRoot?.querySelector(".editor-wrapper");if(!e||!t||!i)return;const o=this._editor,r=o?.isActive("table")??!1,{selection:s}=o?.state??{selection:null};if(r&&s&&!s.empty&&o){const{from:t,to:i}=s,r=o.state.doc.resolve(t),l=o.state.doc.resolve(i);let n=!1;for(let e=r.depth;e>=0;e--)if("table"===r.node(e).type.name){n=!0;break}const a=r.node(r.depth),d=l.node(l.depth);if("table"!==a.type.name&&"table"!==d.type.name||(n=!0),n)return e.style.opacity="0",void(e.style.visibility="hidden")}if(s&&!s.empty);else if(!s||s.empty&&!this._hasSlashCommand)return e.style.opacity="0",void(e.style.visibility="hidden");const l=i.getBoundingClientRect(),n=e.getBoundingClientRect(),{from:a}=s,d=this._editor?.view.coordsAtPos(a);if(!d)return;let c=d.left-l.left,h=d.top-l.top-40;c+n.width>l.width&&(c=l.width-n.width-8),c<0&&(c=8),h<0&&(h=d.bottom-l.top+8),e.style.left=`${c}px`,e.style.top=`${h}px`,e.style.opacity="1",e.style.visibility="visible"})}render(){const e=this._editor;return A`
30
+ <div
31
+ class="editor-wrapper ${e?"":"loading"} ${this._previewValue?"preview":""}"
32
+ @focusin=${this._handleWrapperFocusIn}
33
+ @focusout=${this._handleWrapperFocusOut}
34
+ >
35
+ ${e?"":A`
4
36
  <div class="loading-placeholder">
5
37
  <div class="loading-spinner"></div>
6
38
  <span>编辑器加载中...</span>
@@ -13,8 +45,150 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
13
45
  @change=${this._handleImageUpload}
14
46
  />
15
47
 
48
+ ${this._previewValue||"header"!==this._toolbarModeValue?"":A`
49
+ <div class="editor-header ${this._isHeaderVisible()?"is-visible":""}">
50
+ <div class="editor-header__inner">
51
+ ${this._selectedImage?this._renderImageControls():A`
52
+ <button
53
+ class="bubble-btn ${e?.isActive("bold")?"is-active":""}"
54
+ @click=${this._toggleBold}
55
+ title="加粗"
56
+ >
57
+ <svg viewBox="0 0 24 24"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>
58
+ </button>
59
+ <button
60
+ class="bubble-btn ${e?.isActive("italic")?"is-active":""}"
61
+ @click=${this._toggleItalic}
62
+ title="斜体"
63
+ >
64
+ <svg viewBox="0 0 24 24"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>
65
+ </button>
66
+ <button
67
+ class="bubble-btn ${e?.isActive("underline")?"is-active":""}"
68
+ @click=${this._toggleUnderline}
69
+ title="下划线"
70
+ >
71
+ <svg viewBox="0 0 24 24"><path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/></svg>
72
+ </button>
73
+ <button
74
+ class="bubble-btn ${e?.isActive("strike")?"is-active":""}"
75
+ @click=${this._toggleStrike}
76
+ title="删除线"
77
+ >
78
+ <svg viewBox="0 0 24 24"><path d="M17.3 4.9c-2.3-.6-4.4-1-6.2-.9-2.7 0-5.3.7-5.3 3.6 0 1.5 1.8 3.3 5.3 3.9h.2m8.2 3.2c.3.4.4.8.4 1.3 0 2.9-2.7 3.6-6.2 3.6-2.3 0-4.4-.3-6.2-.9M4 12h16"/></svg>
79
+ </button>
80
+
81
+ <div class="bubble-divider"></div>
82
+
83
+ <div class="bubble-dropdown">
84
+ <button class="bubble-dropdown-btn">
85
+ ${this._getTextLabel()}
86
+ <svg viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"/></svg>
87
+ </button>
88
+ <div class="bubble-dropdown-menu">
89
+ <button class="bubble-dropdown-item ${e?.isActive("heading")?"":"is-active"}" @click=${this._setParagraph}>正文</button>
90
+ <button class="bubble-dropdown-item ${e?.isActive("heading",{level:1})?"is-active":""}" @click=${()=>this._setHeading(1)}>标题 1</button>
91
+ <button class="bubble-dropdown-item ${e?.isActive("heading",{level:2})?"is-active":""}" @click=${()=>this._setHeading(2)}>标题 2</button>
92
+ <button class="bubble-dropdown-item ${e?.isActive("heading",{level:3})?"is-active":""}" @click=${()=>this._setHeading(3)}>标题 3</button>
93
+ </div>
94
+ </div>
95
+
96
+ <div class="bubble-divider"></div>
97
+
98
+ <div class="bubble-dropdown">
99
+ <button class="bubble-dropdown-btn">
100
+ ${this._getAlignLabel()}
101
+ <svg viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"/></svg>
102
+ </button>
103
+ <div class="bubble-dropdown-menu">
104
+ <button class="bubble-dropdown-item ${e?.isActive({textAlign:"left"})?"is-active":""}" @click=${()=>this._setTextAlign("left")}>
105
+ <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>
106
+ 左对齐
107
+ </button>
108
+ <button class="bubble-dropdown-item ${e?.isActive({textAlign:"center"})?"is-active":""}" @click=${()=>this._setTextAlign("center")}>
109
+ <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>
110
+ 居中
111
+ </button>
112
+ <button class="bubble-dropdown-item ${e?.isActive({textAlign:"right"})?"is-active":""}" @click=${()=>this._setTextAlign("right")}>
113
+ <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>
114
+ 右对齐
115
+ </button>
116
+ </div>
117
+ </div>
118
+
119
+ <div class="bubble-divider"></div>
120
+
121
+ <button class="bubble-btn ${e?.isActive("code")?"is-active":""}" @click=${this._toggleCode} title="行内代码">
122
+ <svg viewBox="0 0 24 24"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
123
+ </button>
124
+ <button class="bubble-btn ${e?.isActive("link")?"is-active":""}" @click=${this._setLink} title="链接">
125
+ <svg viewBox="0 0 24 24"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
126
+ </button>
127
+ <button class="bubble-btn" @click=${this._triggerImageUpload} title="图片">
128
+ <svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
129
+ </button>
130
+
131
+ <div class="bubble-divider"></div>
132
+
133
+ <button class="bubble-btn ${e?.isActive("bulletList")?"is-active":""}" @click=${this._toggleBulletList} title="无序列表">
134
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
135
+ <line x1="9" y1="6" x2="20" y2="6"/>
136
+ <line x1="9" y1="12" x2="20" y2="12"/>
137
+ <line x1="9" y1="18" x2="20" y2="18"/>
138
+ <circle cx="4" cy="6" r="0.5" fill="currentColor" stroke="none"/>
139
+ <circle cx="4" cy="12" r="0.5" fill="currentColor" stroke="none"/>
140
+ <circle cx="4" cy="18" r="0.5" fill="currentColor" stroke="none"/>
141
+ </svg>
142
+ </button>
143
+ <button class="bubble-btn ${e?.isActive("orderedList")?"is-active":""}" @click=${this._toggleOrderedList} title="有序列表">
144
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
145
+ <line x1="10" y1="6" x2="21" y2="6"/>
146
+ <line x1="10" y1="12" x2="21" y2="12"/>
147
+ <line x1="10" y1="18" x2="21" y2="18"/>
148
+ <path d="M4 6h1v4"/>
149
+ <path d="M4 10h2"/>
150
+ <path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1.5"/>
151
+ </svg>
152
+ </button>
153
+ <button class="bubble-btn ${e?.isActive("taskList")?"is-active":""}" @click=${this._toggleTaskList} title="待办列表">
154
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
155
+ <rect x="3" y="5" width="4" height="4" rx="1"/>
156
+ <polyline points="4 7 5 8 6.5 6.5"/>
157
+ <line x1="10" y1="7" x2="21" y2="7"/>
158
+ <rect x="3" y="15" width="4" height="4" rx="1"/>
159
+ <line x1="10" y1="17" x2="21" y2="17"/>
160
+ </svg>
161
+ </button>
162
+ <button class="bubble-btn ${e?.isActive("blockquote")?"is-active":""}" @click=${this._toggleBlockquote} title="引用">
163
+ <svg viewBox="0 0 24 24"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V21z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>
164
+ </button>
165
+
166
+ <div class="bubble-divider"></div>
167
+
168
+ <div
169
+ class="bubble-dropdown ${this._tableDropdownOpen?"is-open":""}"
170
+ @mouseenter=${()=>{this._tableDropdownOpen=!0,this._hoverRow=0,this._hoverCol=0}}
171
+ @mouseleave=${()=>this._tableDropdownOpen=!1}
172
+ >
173
+ <button class="bubble-dropdown-btn" title="表格">
174
+ <svg viewBox="0 0 24 24" style="width:18px;height:18px;stroke:currentColor;stroke-width:2;fill:none;"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>
175
+ </button>
176
+ <div class="bubble-dropdown-menu">
177
+ <div class="table-grid-preview">
178
+ ${this._renderTableGrid()}
179
+ </div>
180
+ <div class="table-size-hint">
181
+ <span>${this._hoverRow>0?`${this._hoverRow} × ${this._hoverCol}`:`${this._tableRows} × ${this._tableCols}`}</span>
182
+ </div>
183
+ </div>
184
+ </div>
185
+ `}
186
+ </div>
187
+ </div>
188
+ `}
189
+
16
190
  <!-- Bubble Menu (悬浮操作栏) -->
17
- ${this._previewValue?"":$`
191
+ ${this._previewValue||"slash"!==this._toolbarModeValue?"":A`
18
192
  <div class="bubble-menu">
19
193
  <!-- 文本格式 -->
20
194
  <button
@@ -175,6 +349,19 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
175
349
  <path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1.5"/>
176
350
  </svg>
177
351
  </button>
352
+ <button
353
+ class="bubble-btn ${e?.isActive("taskList")?"is-active":""}"
354
+ @click=${this._toggleTaskList}
355
+ title="待办列表"
356
+ >
357
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
358
+ <rect x="3" y="5" width="4" height="4" rx="1"/>
359
+ <polyline points="4 7 5 8 6.5 6.5"/>
360
+ <line x1="10" y1="7" x2="21" y2="7"/>
361
+ <rect x="3" y="15" width="4" height="4" rx="1"/>
362
+ <line x1="10" y1="17" x2="21" y2="17"/>
363
+ </svg>
364
+ </button>
178
365
 
179
366
  <!-- 引用 -->
180
367
  <button
@@ -208,16 +395,16 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
208
395
  </div>
209
396
  `}
210
397
 
211
- <div class="editor-content"></div>
398
+ <div class="editor-content" data-empty-hint=${this._resolvedPlaceholder}></div>
212
399
 
213
400
  <!-- Table Cell Toolbar -->
214
- ${this._tableCellToolbar.visible&&e?.isActive("table")?$`
401
+ ${this._tableCellToolbar.visible&&e?.isActive("table")?A`
215
402
  <div
216
403
  class="table-cell-toolbar"
217
404
  style="left: ${this._tableCellToolbar.x}px; top: ${this._tableCellToolbar.y}px;"
218
405
  @mousedown=${e=>e.preventDefault()}
219
406
  >
220
- ${0===this._tableCellToolbar.cellRow?$`
407
+ ${0===this._tableCellToolbar.cellRow?A`
221
408
  <button class="table-cell-toolbar-btn" title="上方添加行" @click=${this._addTableRowAbove}>
222
409
  <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><rect x="4" y="8" width="16" height="8" rx="1"/><line x1="12" y1="3" x2="12" y2="7"/><line x1="10" y1="5" x2="14" y2="5"/></svg>
223
410
  </button>
@@ -228,8 +415,8 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
228
415
  <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><rect x="4" y="8" width="16" height="8" rx="1"/><line x1="9" y1="10" x2="9" y2="14"/><line x1="15" y1="10" x2="15" y2="14"/></svg>
229
416
  </button>
230
417
  `:""}
231
- ${0===this._tableCellToolbar.cellCol?$`
232
- ${0!==this._tableCellToolbar.cellRow?$`<div style="width:1px;height:20px;background:#e3e3e3;margin:0 4px;"></div>`:""}
418
+ ${0===this._tableCellToolbar.cellCol?A`
419
+ ${0!==this._tableCellToolbar.cellRow?A`<div style="width:1px;height:20px;background:#e3e3e3;margin:0 4px;"></div>`:""}
233
420
  <button class="table-cell-toolbar-btn" title="左侧添加列" @click=${this._addTableColumnLeft}>
234
421
  <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><rect x="8" y="4" width="8" height="16" rx="1"/><line x1="3" y1="12" x2="7" y2="12"/><line x1="5" y1="10" x2="5" y2="14"/></svg>
235
422
  </button>
@@ -240,7 +427,7 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
240
427
  <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><rect x="8" y="4" width="8" height="16" rx="1"/><line x1="10" y1="9" x2="14" y2="9"/><line x1="10" y1="15" x2="14" y2="15"/></svg>
241
428
  </button>
242
429
  `:""}
243
- ${0===this._tableCellToolbar.cellRow&&0===this._tableCellToolbar.cellCol?$`
430
+ ${0===this._tableCellToolbar.cellRow&&0===this._tableCellToolbar.cellCol?A`
244
431
  <div style="width:1px;height:20px;background:#e3e3e3;margin:0 4px;"></div>
245
432
  <button class="table-cell-toolbar-btn danger" title="删除表格" @click=${this._deleteTable}>
246
433
  <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
@@ -250,51 +437,24 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
250
437
  `:""}
251
438
 
252
439
  <!-- Image Toolbar -->
253
- ${this._imageToolbar.visible?$`
440
+ ${"slash"===this._toolbarModeValue&&this._imageToolbar.visible?A`
254
441
  <div
255
442
  class="image-toolbar"
256
443
  style="left: ${this._imageToolbar.x}px; top: ${this._imageToolbar.y}px;"
257
444
  @mousedown=${e=>e.preventDefault()}
258
445
  >
259
- <button class="image-toolbar-btn danger" title="删除图片" @click=${this._deleteImage}>
260
- <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
261
- </button>
262
- <button class="image-toolbar-btn" title="添加图片" @click=${this._insertImageAfter}>
263
- <svg viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
264
- </button>
265
- <div class="image-toolbar-divider"></div>
266
- <div style="position: relative;">
267
- <button class="image-toolbar-btn" title="更多" @click=${this._toggleImageMoreMenu}>
268
- <svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>
269
- </button>
270
- ${this._imageMoreMenuVisible?$`
271
- <div class="image-more-menu">
272
- <button class="image-more-menu-item" @click=${this._setImageAlignLeft}>
273
- <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>
274
- 左对齐
275
- </button>
276
- <button class="image-more-menu-item" @click=${this._setImageAlignCenter}>
277
- <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>
278
- 居中
279
- </button>
280
- <button class="image-more-menu-item" @click=${this._setImageAlignRight}>
281
- <svg viewBox="0 0 24 24"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>
282
- 右对齐
283
- </button>
284
- </div>
285
- `:""}
286
- </div>
446
+ ${this._renderImageControls()}
287
447
  </div>
288
448
  `:""}
289
449
  </div>
290
- `}_renderTableGrid(){const e=[];for(let t=0;t<100;t++){const i=Math.floor(t/10)+1,o=t%10+1,r=this._hoverRow>0&&i<=this._hoverRow&&o<=this._hoverCol;e.push($`
450
+ `}_renderTableGrid(){const e=[];for(let t=0;t<100;t++){const i=Math.floor(t/10)+1,o=t%10+1,r=this._hoverRow>0&&i<=this._hoverRow&&o<=this._hoverCol;e.push(A`
291
451
  <div
292
452
  class="table-cell ${r?"selected":""}"
293
453
  @click=${()=>{this._insertTableByClick(i,o),this._tableDropdownOpen=!1}}
294
454
  @mouseenter=${()=>{this._hoverRow=i,this._hoverCol=o}}
295
455
  @mouseleave=${()=>{this._hoverRow=0,this._hoverCol=0}}
296
456
  ></div>
297
- `)}return e}};V.styles=M`
457
+ `)}return e}};F.styles=M`
298
458
  :host {
299
459
  display: block;
300
460
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
@@ -324,6 +484,34 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
324
484
  min-height: unset;
325
485
  }
326
486
 
487
+ .editor-header {
488
+ max-height: 0;
489
+ opacity: 0;
490
+ overflow: hidden;
491
+ padding: 0 16px;
492
+ border-bottom: 1px solid transparent;
493
+ transition:
494
+ max-height 0.24s ease,
495
+ opacity 0.18s ease,
496
+ padding 0.24s ease,
497
+ border-color 0.24s ease;
498
+ }
499
+
500
+ .editor-header.is-visible {
501
+ max-height: 132px;
502
+ opacity: 1;
503
+ overflow: visible;
504
+ padding: 10px 12px;
505
+ border-bottom-color: #eef1f5;
506
+ }
507
+
508
+ .editor-header__inner {
509
+ display: flex;
510
+ align-items: center;
511
+ flex-wrap: wrap;
512
+ overflow: visible;
513
+ }
514
+
327
515
  .editor-content {
328
516
  padding: 12px 16px;
329
517
  min-height: 80px;
@@ -331,7 +519,7 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
331
519
  }
332
520
 
333
521
  .editor-content:empty::before {
334
- content: '输入 / 唤出快捷命令';
522
+ content: attr(data-empty-hint);
335
523
  color: #c0c0c0;
336
524
  pointer-events: none;
337
525
  display: block;
@@ -445,6 +633,51 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
445
633
  margin: 0;
446
634
  }
447
635
 
636
+ .ProseMirror ul[data-type="taskList"] {
637
+ padding-left: 0;
638
+ list-style: none;
639
+ }
640
+
641
+ .ProseMirror li[data-type="taskItem"] {
642
+ display: flex;
643
+ align-items: flex-start;
644
+ gap: 8px;
645
+ list-style: none;
646
+ margin: 0.2em 0;
647
+ }
648
+
649
+ .ProseMirror li[data-type="taskItem"] > label {
650
+ display: inline-flex;
651
+ align-items: center;
652
+ justify-content: center;
653
+ width: 18px;
654
+ height: 28px;
655
+ flex: 0 0 18px;
656
+ cursor: pointer;
657
+ user-select: none;
658
+ }
659
+
660
+ .ProseMirror li[data-type="taskItem"] > label > input {
661
+ width: 14px;
662
+ height: 14px;
663
+ margin: 0;
664
+ cursor: pointer;
665
+ }
666
+
667
+ .ProseMirror li[data-type="taskItem"] > label > span {
668
+ display: none;
669
+ }
670
+
671
+ .ProseMirror li[data-type="taskItem"] > div {
672
+ flex: 1;
673
+ min-width: 0;
674
+ }
675
+
676
+ .ProseMirror li[data-type="taskItem"][data-checked="true"] > div p {
677
+ color: #8a8f98;
678
+ text-decoration: line-through;
679
+ }
680
+
448
681
  .ProseMirror li {
449
682
  margin: 0.1em 0;
450
683
  }
@@ -637,6 +870,11 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
637
870
  color: #fff;
638
871
  }
639
872
 
873
+ .bubble-btn.danger:hover {
874
+ background: #fef0f0;
875
+ color: #f56c6c;
876
+ }
877
+
640
878
  .bubble-btn svg {
641
879
  width: 16px;
642
880
  height: 16px;
@@ -785,6 +1023,37 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
785
1023
  color: #8c8c8c;
786
1024
  }
787
1025
 
1026
+ .image-size-control {
1027
+ display: flex;
1028
+ align-items: center;
1029
+ gap: 6px;
1030
+ padding-left: 8px;
1031
+ margin-left: 2px;
1032
+ border-left: 1px solid #e3e3e3;
1033
+ white-space: nowrap;
1034
+ }
1035
+
1036
+ .image-size-label {
1037
+ font-size: 12px;
1038
+ color: #7a7f88;
1039
+ }
1040
+
1041
+ .image-size-range {
1042
+ width: 72px;
1043
+ height: 26px;
1044
+ padding: 0 8px;
1045
+ border: 1px solid #d8dde6;
1046
+ border-radius: 6px;
1047
+ font-size: 12px;
1048
+ color: #37352f;
1049
+ background: #fff;
1050
+ outline: none;
1051
+ }
1052
+
1053
+ .image-size-range:focus {
1054
+ border-color: var(--qxs-color-primary, #3D61E3);
1055
+ }
1056
+
788
1057
  /* Image Toolbar */
789
1058
  .image-toolbar {
790
1059
  position: absolute;
@@ -888,5 +1157,5 @@ import{Extension as e,Editor as t}from"@tiptap/core";import i from"@tiptap/exten
888
1157
  outline: 2px solid var(--qxs-color-primary, #3D61E3);
889
1158
  outline-offset: 2px;
890
1159
  }
891
- `,q([A({type:String,attribute:"content"})],V.prototype,"content",2),q([A({type:String,attribute:"model-value"})],V.prototype,"model-value",2),q([A({type:String,attribute:"placeholder"})],V.prototype,"placeholder",2),q([A({type:String,attribute:"use-model"})],V.prototype,"use-model",2),q([A({type:String,attribute:"readonly"})],V.prototype,"readonly",2),q([A({type:String,attribute:"preview"})],V.prototype,"preview",2),q([A({type:String,attribute:"custom-styles"})],V.prototype,"custom-styles",2),q([A({type:Object,attribute:"upload-image"})],V.prototype,"upload-image",2),q([R()],V.prototype,"_editor",2),q([R()],V.prototype,"_pendingContent",2),q([R()],V.prototype,"_hoverRow",2),q([R()],V.prototype,"_hoverCol",2),q([R()],V.prototype,"_tableDropdownOpen",2),q([R()],V.prototype,"_tableCellToolbar",2),q([R()],V.prototype,"_imageToolbar",2),q([R()],V.prototype,"_imageMoreMenuVisible",2),V=q([B("qxs-blocksuite-editor")],V);export{V as QxsBlocksuiteEditor};
1160
+ `,P([I({type:String,attribute:"content"})],F.prototype,"content",2),P([I({type:String,attribute:"model-value"})],F.prototype,"model-value",2),P([I({type:String,attribute:"placeholder"})],F.prototype,"placeholder",2),P([I({type:String,attribute:"toolbar-mode"})],F.prototype,"toolbar-mode",2),P([I({type:String,attribute:"header-always-visible"})],F.prototype,"header-always-visible",2),P([I({type:String,attribute:"use-model"})],F.prototype,"use-model",2),P([I({type:String,attribute:"readonly"})],F.prototype,"readonly",2),P([I({type:String,attribute:"preview"})],F.prototype,"preview",2),P([I({type:String,attribute:"custom-styles"})],F.prototype,"custom-styles",2),P([I({type:Object,attribute:"upload-image"})],F.prototype,"upload-image",2),P([S()],F.prototype,"_editor",2),P([S()],F.prototype,"_pendingContent",2),P([S()],F.prototype,"_hoverRow",2),P([S()],F.prototype,"_hoverCol",2),P([S()],F.prototype,"_tableDropdownOpen",2),P([S()],F.prototype,"_tableCellToolbar",2),P([S()],F.prototype,"_imageToolbar",2),P([S()],F.prototype,"_isEditorFocused",2),P([S()],F.prototype,"_selectedImage",2),F=P([B("qxs-blocksuite-editor")],F);export{F as QxsBlocksuiteEditor};
892
1161
  //# sourceMappingURL=blocksuite-editor.mjs.map