diff --git a/assets/creator-studio/build/index.asset.php b/assets/creator-studio/build/index.asset.php index f8d3d31f..36fadb97 100644 --- a/assets/creator-studio/build/index.asset.php +++ b/assets/creator-studio/build/index.asset.php @@ -1 +1 @@ - array('react', 'wp-element', 'wp-i18n'), 'version' => '5aca6e340eab7503b9b9'); + array('react', 'wp-element', 'wp-i18n'), 'version' => 'e6c1894c680db1bc0999'); diff --git a/assets/creator-studio/build/index.js b/assets/creator-studio/build/index.js index 98dc0419..9e677f7f 100644 --- a/assets/creator-studio/build/index.js +++ b/assets/creator-studio/build/index.js @@ -4,5 +4,5 @@ (0,a.__)("%d小时前","jio"),Math.floor(o/N)):oe.replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),q=[{value:"generic",label:(0,a.__)("通用","jio")},{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"php",label:"PHP"},{value:"python",label:"Python"},{value:"java",label:"Java"},{value:"go",label:"Go"},{value:"rust",label:"Rust"},{value:"csharp",label:"C#"},{value:"cpp",label:"C++"},{value:"sql",label:"SQL"},{value:"json",label:"JSON"},{value:"bash",label:"Shell"},{value:"css",label:"CSS"},{value:"html",label:"HTML"},{value:"markdown",label:"Markdown"}];const L=(e,t,a)=>Math.min(a,Math.max(t,Number.isFinite(e)?Math.round(e):t)),I={table:(0,a.__)("插入表格","jio"),math:(0,a.__)("插入公式","jio"),footnote:(0,a.__)("插入注释","jio")};function R({kind:n,onSubmit:o,onClose:r}){const[l,i]=(0,t.useState)(3),[c,s]=(0,t.useState)(3),[d,u]=(0,t.useState)(!0),[m,p]=(0,t.useState)(!1),[_,f]=(0,t.useState)("a^2 + b^2 = c^2"),[b,g]=(0,t.useState)(!0),[h,j]=(0,t.useState)(""),y=(0,t.useRef)(null),E=(0,t.useRef)(null),v=(0,t.useRef)(null),k=(0,t.useRef)(null);(0,t.useEffect)(()=>{(E.current||v.current||k.current)?.focus();const e=e=>{"Escape"===e.key&&(e.preventDefault(),r())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]);const N=(0,t.useMemo)(()=>"footnote"===n?""!==h.trim():"math"!==n||""!==_.trim(),[n,h,_]);return(0,e.createElement)("div",{className:"jio-creator-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"jio-creator-dialog-title"},(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__backdrop","aria-label":(0,a.__)("关闭","jio"),onClick:r}),(0,e.createElement)("div",{className:"jio-creator-dialog__panel",ref:y},(0,e.createElement)("header",{className:"jio-creator-dialog__head"},(0,e.createElement)("h2",{id:"jio-creator-dialog-title"},I[n]),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__close",onClick:r,"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,e.createElement)("div",{className:"jio-creator-dialog__body"},"table"===n&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"jio-creator-dialog__row"},(0,e.createElement)("label",null,(0,e.createElement)("span",null,(0,a.__)("行数","jio")),(0,e.createElement)("input",{ref:E,type:"number",min:1,max:20,value:l,onChange:e=>i(Number(e.target.value))})),(0,e.createElement)("label",null,(0,e.createElement)("span",null,(0,a.__)("列数","jio")),(0,e.createElement)("input",{type:"number",min:1,max:10,value:c,onChange:e=>s(Number(e.target.value))}))),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:d,onChange:e=>u(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("首行为表头","jio"))),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:m,onChange:e=>p(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("隔行变色","jio")))),"math"===n&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("label",{className:"jio-creator-dialog__field"},(0,e.createElement)("span",null,(0,a.__)("公式","jio")),(0,e.createElement)("textarea",{ref:v,rows:3,value:_,onChange:e=>f(e.target.value),placeholder:"a^2 + b^2 = c^2"})),(0,e.createElement)("p",{className:"jio-creator-muted"},(0,a.__)("支持上标 ^ 与下标 _,例如 x^2 与 a_n;暂不支持完整 LaTeX。","jio")),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:b,onChange:e=>g(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("独占一行显示","jio")))),"footnote"===n&&(0,e.createElement)("label",{className:"jio-creator-dialog__field"},(0,e.createElement)("span",null,(0,a.__)("注释内容","jio")),(0,e.createElement)("textarea",{ref:k,rows:4,value:h,onChange:e=>j(e.target.value),placeholder:(0,a.__)("填写要补充说明的内容","jio")}))),(0,e.createElement)("footer",{className:"jio-creator-dialog__foot"},(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__ghost",onClick:r},(0,a.__)("取消","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__primary",onClick:()=>{N&&o("table"!==n?"math"!==n?{kind:n,note:h.trim()}:{kind:n,formula:_.trim(),display:b}:{kind:n,rows:L(l,1,20),cols:L(c,1,10),header:d,striped:m})},disabled:!N},(0,a.__)("插入","jio")))))}const D=window.jioCreatorStudio||{},P=D.nonce||"",z=`jio-studio-${D.sourceId||0}`,A="jio-creator-content";function T(){const e=D.pay||{},t=D.categories&&D.categories.selected||[],a=D.tags&&D.tags.items||[];return{postId:Number(D.sourceId||0),versionId:Number(D.versionId||0),rev:Number(D.versionRev||0),title:String(D.title||""),content:String(D.content||""),schedule:{enabled:!1,at:""},categories:t.map(Number),tags:a.slice(),custom:D.custom||{},featured:D.featured||{type:"",data:{}},pay:{enabled:!!e.enabled,modo:"points"===e.payModo?"points":"cash",price:String(e.price||"0.00"),points:Number(e.points||0),vip1Price:String(e.vip1Price||"0.00"),vip2Price:String(e.vip2Price||"0.00"),payLimit:Number(e.payLimit||0),downloads:Array.isArray(e.downloads)?e.downloads:[]}}}function U(e){if(!e||e.removed)return;const t=e.getDoc(),a=e.getContentAreaContainer()?.querySelector("iframe");if(!t||!a)return;const n=Math.max(320,t.documentElement.scrollHeight,t.body?t.body.scrollHeight:0);a.style.height=`${n}px`,a.style.overflow="hidden"}function B(e){var t;const a=null!==(t=e?.getBody?.())&&void 0!==t?t:null;a&&a.querySelectorAll("pre.enlighter-pre[data-jio-code]").forEach(e=>{const t=e.querySelector(":scope > .jio-code-lang"),a=e.getAttribute("data-enlighter-language")||"generic";if(t){t.setAttribute("data-jio-code-lang",a);const e=q.find(e=>e.value===a)?.label||a;return void((t.textContent||"")!==e&&(t.textContent=e))}const n=document.createElement("span");n.className="jio-code-lang",n.contentEditable="false",n.setAttribute("data-jio-code-lang",a),n.textContent=q.find(e=>e.value===a)?.label||a,e.insertBefore(n,e.firstChild)})}function F(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(//g,">")}function O(e){const t=String(e||"").trim();if(!t)return"";try{const e=new URL(t,window.location.href);return"http:"===e.protocol||"https:"===e.protocol?e.href:""}catch(e){return""}}function K(e){const t=document.createElement("div");return t.innerHTML=e,(t.textContent||"").replace(/\s+/g,"")}function H(){const[n,o]=(0,t.useState)(T),l=(0,t.useRef)(n);l.current=n;const i=(0,t.useRef)(null),c=(0,t.useRef)(null),d=(0,t.useRef)(null),m=(0,t.useRef)(!1),p=(0,t.useRef)(()=>{}),[_,f]=(0,t.useState)(!1),[h,E]=(0,t.useState)({canUndo:!1,canRedo:!1}),[v,k]=(0,t.useState)("p"),[N,w]=(0,t.useState)(()=>({state:D.sourceId||D.versionId||D.content?"saved":"ready",at:""})),[C,S]=(0,t.useState)(!1),[x,L]=(0,t.useState)(null),[I,H]=(0,t.useState)(null),J=(0,t.useRef)(null),[V,W]=(0,t.useState)(null),[Q,X]=(0,t.useState)(null),Y=(0,t.useRef)(!1),G=(0,t.useRef)(0),Z=D.capabilities||{},ee={titleMin:Number(D.limits?.titleMin||1),titleMax:Number(D.limits?.titleMax||30),titlePlaceholder:String(D.limits?.titlePlaceholder||(0,a.__)("请输入标题","jio")),priceMin:Number(D.pay?.priceMin||0),priceMax:Number(D.pay?.priceMax||0),pointsMin:Number(D.pay?.pointsMin||0),pointsMax:Number(D.pay?.pointsMax||0)},te=!!D.isPublished,ae=(0,t.useMemo)(()=>Array.from(K(n.content)).length,[n.content]),ne=(0,t.useCallback)(e=>{Y.current=!0,G.current+=1;const t={...l.current,...e};l.current=t,o(t)},[]),oe=(0,t.useCallback)(e=>{if(e===l.current.content)return;Y.current=!0,G.current+=1;const t={...l.current,content:e};l.current=t,o(t)},[]),re=(0,t.useCallback)(e=>{const t=e?.undoManager;t&&E({canUndo:"function"==typeof t.hasUndo&&t.hasUndo(),canRedo:"function"==typeof t.hasRedo&&t.hasRedo()})},[]),le=(0,t.useCallback)(e=>{const t=e?.selection?.getNode(),a=t?e.dom.getParent(t,"p,h1,h2,h3,blockquote")||t:null,n=a?.nodeName?.toLowerCase()||"p";k(["h1","h2","h3","blockquote"].includes(n)?n:"p")},[]),ie=(0,t.useCallback)((e={})=>{const t=l.current;return{post_id:t.postId,version_id:t.versionId,rev:t.rev,title:t.title,content:t.content,categories:t.categories,tags:t.tags,custom:t.custom,featured:t.featured,schedule:{enabled:!!t.schedule.enabled,at:t.schedule.enabled?t.schedule.at:""},pay:g(t.pay),...e}},[]),ce=(0,t.useCallback)(async(e=!1)=>{const t=i.current;t&&!t.removed&&oe(j(t.getContent()));const a=l.current;if(!Y.current&&(a.postId>0||a.versionId>0))return!0;const n=G.current,c=""!==a.title.trim()||""!==K(a.content).trim();if(e&&!c)return!0;w({state:"saving",at:""});try{const t=await r(D.creator.saveUrl,ie({autosave:e}),P),a={...l.current,postId:Number(t.post_id||l.current.postId||0),versionId:Number(t.version_id||l.current.versionId||0),rev:Number(t.rev||t.versionRev||l.current.rev||0)};window.jioSubmitData&&(window.jioSubmitData.postId=a.postId);const i=G.current===n;return Y.current=!i,l.current=a,o(a),w({state:i?"saved":"saving",at:i?(new Date).toLocaleTimeString():""}),i}catch(e){return w({state:409===e?.status?"conflict":"error",at:""}),!1}},[ie]);p.current=()=>{ce(!1)};const se=(0,t.useCallback)(async e=>{if(await ce(!1)){w({state:"submitting",at:""});try{let t="";const n=window.JioCaptcha;if(D.captcha?.enabled&&n&&"function"==typeof n.run){const e=await n.run("front_submit");if(null===e)return w({state:"ready",at:""}),void W({tone:"error",text:(0,a.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const o=await r(D.creator.submitUrl,ie({post_id:l.current.postId,version_id:l.current.versionId,rev:l.current.rev,publish_now:e,captcha_proof:t}),P);Y.current=!1,w({state:"submitted",at:""}),W({tone:"ok",text:String(o.message||(0,a.__)("已提交","jio"))}),S(!1);const i=o.url||o.goto||D.urls?.center;i&&window.setTimeout(()=>{window.location.href=i},900)}catch(e){w({state:"error",at:""}),W({tone:"error",text:String(e?.message||(0,a.__)("提交失败","jio"))})}}else W({tone:"error",text:(0,a.__)("内容保存失败,请重试后再提交","jio")})},[ie,ce]),de=(0,t.useCallback)(async()=>{if(await ce(!1))try{const e=await r(D.creator.previewUrl,{post_id:l.current.postId,version_id:l.current.versionId},P);e.url&&window.open(String(e.url),"_blank","noopener")}catch(e){W({tone:"error",text:String(e?.message||(0,a.__)("预览失败","jio"))})}},[ce]),{markLocalSaved:ue,clear:me}=function({key:e,snapshot:a,onFound:n}){const o=(0,t.useRef)(a);o.current=a;const r=(0,t.useRef)(!1);return(0,t.useEffect)(()=>{if(!r.current){r.current=!0;try{const t=window.localStorage.getItem(e);if(!t)return;const o=JSON.parse(t),r="string"==typeof o.at?Date.parse(o.at):NaN;if(!Number.isFinite(r)||Date.now()-r>6048e5)return void window.localStorage.removeItem(e);"string"==typeof o.content&&o.content!==a.content&&n(String(o.at))}catch(t){window.localStorage.removeItem(e)}}},[e,n,a.content]),{markLocalSaved:(0,t.useCallback)(()=>{try{window.localStorage.setItem(e,JSON.stringify(o.current))}catch(e){}},[e]),clear:(0,t.useCallback)(()=>{try{window.localStorage.removeItem(e)}catch(e){}},[e])}}({key:z,snapshot:{title:n.title,content:n.content,at:(new Date).toISOString()},onFound:e=>X({savedAt:e})}),pe=function({enabled:e,onSave:a,onLocal:n,remoteDelay:o=4e3,localDelay:r=1500}){const l=(0,t.useRef)(null),i=(0,t.useRef)(null),c=(0,t.useRef)(!1),s=(0,t.useRef)(a),d=(0,t.useRef)(n);s.current=a,d.current=n;const u=(0,t.useCallback)(()=>{l.current&&(window.clearTimeout(l.current),l.current=null),i.current&&(window.clearTimeout(i.current),i.current=null)},[]),m=(0,t.useCallback)(async()=>{if(!c.current){c.current=!0;try{await s.current()}finally{c.current=!1}}},[]),p=(0,t.useCallback)(()=>{u(),d.current(),e&&(i.current=window.setTimeout(()=>d.current(),r),l.current=window.setTimeout(()=>{m()},o))},[u,e,m,r,o]);return(0,t.useEffect)(()=>{if(!e)return;const t=()=>{"hidden"===document.visibilityState&&m()},a=()=>{m()};return document.addEventListener("visibilitychange",t),window.addEventListener("blur",a),()=>{document.removeEventListener("visibilitychange",t),window.removeEventListener("blur",a),u()}},[u,e,m]),(0,t.useMemo)(()=>({schedule:p,flush:m,cancel:u}),[u,m,p])}({enabled:!!Z.isLoggedIn,onSave:async()=>{const e=await ce(!0);return e&&me(),e},onLocal:ue}).schedule;(0,t.useEffect)(()=>{Y.current&&pe()},[n,pe]),(0,t.useEffect)(()=>{const e=e=>{Y.current&&(e.preventDefault(),e.returnValue="")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),(0,t.useEffect)(()=>{const e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()&&(e.preventDefault(),ce(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ce]),(0,t.useEffect)(()=>{const e=window.wp?.editor;if(!e||"function"!=typeof e.initialize)return void W({tone:"error",text:(0,a.__)("TinyMCE 加载失败,请刷新页面后重试。","jio")});const t={quicktags:!1,tinymce:{menubar:!1,statusbar:!1,resize:!1,toolbar1:"",toolbar2:"",toolbar3:"",plugins:"paste,link,lists,wordpress,wplink",wpautop:!0,body_class:"jio-creator__tinymce",content_css:D.creator?.contentCss||"",content_style:'\nbody {\n\tmargin: 0;\n\tcolor: #2b2b2b;\n\tfont-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;\n\tfont-size: 16px;\n\tline-height: 1.8;\n\tletter-spacing: 0.01em;\n}\np { margin: 0 0 1.1em; }\nh1, h2, h3, h4, h5, h6 { margin: 1.5em 0 0.65em; line-height: 1.4; }\nimg, iframe { max-width: 100%; }\nimg { height: auto; }\n\n/* 代码块:右上角显示当前语言,点击即可更换(交互在父组件里接管)。 */\n.enlighter-pre {\n\tposition: relative;\n\tmargin: 0 0 1.1em;\n\tpadding: 40px 14px 14px;\n\toverflow: auto;\n\tborder-radius: 8px;\n\tbackground: #f2f4f5;\n\tcursor: pointer;\n}\n.enlighter-pre code.gl {\n\tdisplay: block;\n\tborder: 0;\n\tbackground: transparent;\n\tcolor: #2b2b2b;\n\tfont-family: Consolas, Monaco, monospace;\n\tfont-size: 13px;\n\tline-height: 1.5;\n\twhite-space: pre-wrap;\n}\n.enlighter-pre .jio-code-lang {\n\tposition: absolute;\n\ttop: 9px;\n\tright: 9px;\n\tpadding: 3px 10px;\n\tborder-radius: 4px;\n\tbackground: linear-gradient(135deg, #3dcabd 10%, #254bdd 100%);\n\tcolor: #fff;\n\tfont-size: 12px;\n\tline-height: 1.5;\n\tcursor: pointer;\n\tuser-select: none;\n}\n.enlighter-pre .jio-code-lang:hover {\n\tfilter: brightness(1.08);\n}\n\n/* 引用:与前台主题的 .quote_q 视觉一致。 */\n.quote_q {\n\tposition: relative;\n\tmargin: 10px 0 20px;\n\tpadding: 1.2em;\n\tborder-radius: 6px;\n\tcolor: var(--quote-color, #555);\n\tbackground: rgba(85, 85, 85, 0.04);\n}\n.quote_q.qe_wzk_c-red { --quote-color: #dc3f3f; background: rgba(220, 63, 63, 0.05); }\n.quote_q.qe_wzk_lan { --quote-color: #0092ff; background: rgba(0, 146, 255, 0.05); }\n.quote_q.qe_wzk_lv { --quote-color: #23790e; background: rgba(35, 121, 14, 0.05); }\n.quote_q::after {\n\tposition: absolute;\n\ttop: 18px;\n\tleft: 18px;\n\tcolor: var(--quote-color, #555);\n\tcontent: \'\\201C\';\n\tfont-size: 1.4em;\n\tline-height: 1;\n\topacity: 0.6;\n}\n.quote_q > div { padding-left: 2em; opacity: 0.85; }\n.quote_q > div > p:last-child { margin-bottom: 0; }\n\n/* 表格。 */\n.jio-content-table {\n\twidth: 100%;\n\tmargin: 0 0 1.1em;\n\tborder-collapse: collapse;\n\tfont-size: 14px;\n}\n.jio-content-table th,\n.jio-content-table td {\n\tpadding: 10px 12px;\n\tborder: 1px solid #e6e9e8;\n\tline-height: 1.6;\n}\n.jio-content-table thead th {\n\tbackground: #f6f8f7;\n\tfont-weight: 600;\n\ttext-align: left;\n}\n.jio-content-table.is-striped tbody tr:nth-child(odd) td { background: #f7f9f8; }\n\n/* 公式。 */\n.jio-math {\n\tfont-family: "Cambria Math", "Latin Modern Math", "Times New Roman", serif;\n\tfont-size: 1.05em;\n\twhite-space: pre-wrap;\n}\n.jio-math--block {\n\tdisplay: block;\n\tmargin: 12px 0;\n\tpadding: 10px;\n\tborder-radius: 6px;\n\tbackground: #f8faf9;\n\ttext-align: center;\n}\n.jio-math sup, .jio-math sub { font-size: 0.72em; }\n.jio-toc-placeholder {\n\theight: 40px;\n\tmargin: 0 0 1.1em;\n\tborder: 1px dashed #d3ded8;\n\tborder-radius: 8px;\n\tbackground: #f7faf9;\n\tcolor: #8c9a94;\n\tfont-size: 12px;\n\tline-height: 40px;\n\ttext-align: center;\n}\n.jio-toc-placeholder::after { content: \'目录将在发布后自动生成\'; }\n\n/* 注释:编辑器里显示上标标记,发布后由服务端渲染编号与注释列表。 */\n.jio-footnote-ref {\n\tdisplay: inline-block;\n\tmax-width: 100%;\n\tpadding: 0 6px;\n\tborder-radius: 4px;\n\tbackground: #eef5f2;\n\tcolor: #267665;\n\tfont-size: 0.78em;\n\tline-height: 1.6;\n\tvertical-align: super;\n\tcursor: default;\n}\n.jio-footnote-ref::before {\n\tcontent: \'注 \';\n\topacity: 0.6;\n}\n\n/* 附件链接。 */\n.jio-file-link {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tgap: 6px;\n\tpadding: 6px 12px;\n\tborder: 1px solid #e6e9e8;\n\tborder-radius: 6px;\n\tbackground: #f7f8f8;\n\ttext-decoration: none;\n}\n',height:520,placeholder:String(D.limits?.contentPlaceholder||""),setup:e=>{i.current=e,e.on("init",()=>{m.current=!0,f(!0),null!==d.current?(e.setContent(y(d.current)),d.current=null):e.setContent(y(e.getContent())),B(e),U(e),function(e){const t=e.getDoc();if(!t||t.getElementById("jio-block-actions"))return;const a=t.createElement("div");a.id="jio-block-actions",a.className="jio-creator__block-actions",a.innerHTML='',t.body.appendChild(a);let n=null;const o=()=>{n=null,a.classList.remove("is-visible")};t.addEventListener("mouseover",e=>{const r=e.target?.closest?.("table,pre.enlighter-pre,hr,.quote_q,p");r&&r!==t.body&&!r.classList.contains("jio-code-lang")&&(e=>{if(!e||e===t.body)return void o();if("P"===e.tagName&&""===(e.textContent||"").trim())return void o();n=e;const r=e.getBoundingClientRect();a.style.top=`${r.top+t.documentElement.scrollTop+6}px`,a.style.left=r.right-40+"px",a.classList.add("is-visible")})(r)}),t.addEventListener("mouseleave",o),a.addEventListener("mousedown",e=>e.preventDefault()),a.addEventListener("click",t=>{const a=t.target?.closest("[data-jio-block-delete]");if(!a||!n)return;t.preventDefault();const r=n;o(),e.undoManager.transact(()=>{e.dom.remove(r)}),e.nodeChanged(),e.undoManager.add(),0===e.getBody().children.length&&(e.setContent("

"),e.selection.setCursorLocation(e.getBody().firstChild,0)),U(e)})}(e),re(e),le(e)}),e.on("NodeChange",()=>le(e)),e.on("input change Undo Redo AddUndo",()=>{oe(j(e.getContent())),re(e),B(e),U(e)}),e.on("keydown",t=>{if((t.metaKey||t.ctrlKey)&&83===t.keyCode)return t.preventDefault(),void p.current();!function(e,t){const a=Number(t.keyCode);if(8!==a&&46!==a)return;const n=e.selection;if(!n||!n.isCollapsed())return;const o=e.getBody(),r=n.getNode(),l=(i=r)&&1===i.nodeType&&""===(i.textContent||"").trim()&&!e.dom.getParent(i,"table,pre,hr,.quote_q,.jio-math--block,.jio-toc-placeholder",o)?r:null;var i;const c=l?8===a?l.previousElementSibling:l.nextElementSibling:null;if((e=>!!e&&1===e.nodeType&&!!e.matches?.("table,pre,hr,.quote_q,.jio-math--block,.jio-toc-placeholder"))(c))return t.preventDefault(),e.dom.remove(c),e.nodeChanged(),void e.undoManager.add();const s=e.dom.getParent(r,"table,pre,hr,.quote_q,.jio-math--block,.jio-toc-placeholder",o);if(!s)return;const d=t=>{const a=e.dom.createRng();a.selectNodeContents(s),a.collapse(t);const o=n.getRng();return o&&"function"==typeof o.compareBoundaryPoints&&0===o.compareBoundaryPoints(t?1:3,a)};if(!(8===a&&d(!0)||46===a&&d(!1)))return;t.preventDefault();const u=s.parentElement;e.dom.remove(s),u&&0===u.children.length&&(e.setContent("

"),e.selection.setCursorLocation(e.getBody().firstChild,0)),e.nodeChanged(),e.undoManager.add()}(e,t)})}}};return e.initialize(A,t),()=>{e.remove?.(A),m.current=!1,i.current=null}},[oe]);const _e=(0,t.useCallback)(()=>{try{const e=window.localStorage.getItem(z);if(e){const t=JSON.parse(e),a={};"string"==typeof t.title&&(a.title=t.title),"string"==typeof t.content&&(a.content=t.content),ne(a),"string"==typeof t.content&&(m.current?i.current?.setContent(t.content):d.current=t.content)}}catch(e){}X(null)},[ne]),fe=(0,t.useCallback)(()=>{const e=i.current;e&&!e.removed&&(c.current=e.selection.getBookmark(2,!0))},[]),be=(0,t.useCallback)(()=>{const e=i.current;if(!e||e.removed)return null;if(e.focus(),c.current){try{e.selection.moveToBookmark(c.current)}catch(e){}c.current=null}return e},[]),ge=(0,t.useCallback)((e,t)=>{const a=be();a&&("undo"===e?a.undoManager.undo():"redo"===e?a.undoManager.redo():"format"===e?("p"===t?a.execCommand("FormatBlock",!1,"p"):a.formatter.toggle(t||"h2"),le(a)):a.execCommand(e),a.nodeChanged())},[be]),he=(0,t.useCallback)(()=>{const e=be();if(!e)return;const t=window.wpLink;if(t&&"function"==typeof t.open)return void t.open(e.id);const n=window.prompt((0,a.__)("输入链接地址","jio"),"https://"),o=n?O(n):"";o&&e.execCommand("mceInsertLink",!1,{href:o})},[be]),je=(0,t.useCallback)(e=>{const t=be();t&&e&&(t.insertContent(e),t.nodeChanged(),oe(j(t.getContent())),re(t),B(t))},[be]),ye=(0,t.useCallback)(e=>{fe(),"table"!==e&&"math"!==e&&"footnote"!==e?"code"!==e?"list"!==e?"toc"!==e?"divider"===e&&je("

"):je("

[jio_toc]

"):je("

"):je(function(e="generic",t=""){const n=$(""!==t?t:(0,a.__)("在此输入代码","jio"));return`
`+n+"

"}("generic")):L(e)},[je,fe]),Ee=(0,t.useCallback)(e=>{const t=be();if(!t)return;const a=String(t.selection.getContent()||"").trim(),n=t.dom.getParent(t.selection.getNode(),".quote_q");if(n)return n.className="quote_q quote-mce"+(e?` ${e}`:""),void t.nodeChanged();je(function(e,t){const a=["quote_q","quote-mce"];t&&a.push(t);const n=""!==e.trim()?`

${e}

`:"

";return`
${n}

`}(a,e))},[be,je]),ve=(0,t.useCallback)(e=>{L(null),"table"===e.kind?je(function({rows:e,cols:t,header:n,striped:o}){const r=Math.max(1,Math.min(20,e)),l=Math.max(1,Math.min(10,t)),i=e=>Array.from({length:l},(t,n)=>`<${e}>${"th"===e?$(`${(0,a.__)("列","jio")} ${n+1}`):""}`).join("");let c="";n&&(c+=`${i("th")}`);const s=Math.max(1,n?r-1:r);c+=`${Array.from({length:s},()=>`${i("td")}`).join("")}`;const d=["jio-content-table"];return o&&d.push("is-striped"),`${c}

`}(e)):"math"===e.kind?je(function({formula:e,display:t}){const a=(n=e.trim(),$(n).replace(/\^\{([^{}]*)\}|\^(\S)/gu,"$1$2").replace(/_\{([^{}]*)\}|_(\S)/gu,"$1$2"));var n;const o=`data-jio-math-source="${$(e.trim())}" data-jio-math-display="${t?"1":"0"}"`;return t?`

${a}

`:`${a}`}(e)):je(function(e){const t=e.trim()||(0,a.__)("注释内容","jio");return`${$(t)}`}(e.note))},[je]),ke=(0,t.useCallback)(e=>{const t=i.current,n=window.JioSubmitMedia;t&&n&&"function"==typeof n.open?(fe(),n.open({type:e,multiple:"image"===e&&void 0,onSelect:t=>{const a=Array.isArray(t)?t:[t],n=be();if(!n)return;const o=a.map(t=>{const a=O(t?.large_url||t?.url);if(!a)return"";const n=Number(t.attachment_id||t.id||0),o=n>0?` data-edit-file-id="${n}"`:"";if("image"===e){const e=O(t?.url||a),n=e?` data-full-url="${F(e)}"`:"";return`

${F(String(t.name||t.title||

`}if("file"===e){const e=String(t.filename||t.name||a.split("/").pop()||"");return`

${F(e)}

`}return`

`}).join("");o&&(n.insertContent(o),n.nodeChanged(),oe(n.getContent()),re(n))},onEmbed:e=>{const t=be();t&&(t.insertContent(`${e}

`),t.nodeChanged(),oe(t.getContent()),re(t))}})):W({tone:"error",text:(0,a.__)("媒体工具尚未加载,请刷新页面后重试。","jio")})},[be,fe]);return(0,e.createElement)("div",{className:"jio-creator","data-status":D.status||"","data-editor-ready":_?"true":"false"},(0,e.createElement)("header",{className:"jio-creator__bar"},(0,e.createElement)("div",{className:"jio-creator__bar-left"},(0,e.createElement)("a",{className:"jio-creator__back",href:D.urls?.center||"/","aria-label":(0,a.__)("返回作者中心","jio")},(0,e.createElement)("i",{className:"fa fas fa-angle-left","aria-hidden":"true"})),(0,e.createElement)("span",{className:"jio-creator__bar-brand"},"Jio"),(0,e.createElement)("span",{className:"jio-creator__bar-divider","aria-hidden":"true"}),(0,e.createElement)("span",{className:"jio-creator__bar-mode"},te?(0,a.__)("修改文章","jio"):(0,a.__)("写文章","jio"))),(0,e.createElement)(u,{ready:_,formatValue:v,onFormatChange:k,canUndo:h.canUndo,canRedo:h.canRedo,capabilities:Z,onCommand:ge,onRememberSelection:fe,onOpenLink:he,onOpenMedia:ke,onInsertBlock:ye,onInsertQuote:Ee})),Q&&(0,e.createElement)("div",{className:"jio-creator__notice",role:"status"},(0,e.createElement)("span",null,(0,a.__)("发现本地未同步的草稿。","jio")),(0,e.createElement)("button",{type:"button",onClick:_e},(0,a.__)("恢复","jio")),(0,e.createElement)("button",{type:"button",onClick:()=>X(null)},(0,a.__)("忽略","jio"))),V&&(0,e.createElement)("div",{className:`jio-creator__notice is-${V.tone}`,role:"status"},(0,e.createElement)("span",null,V.text),(0,e.createElement)("button",{type:"button",onClick:()=>W(null),"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),te&&(0,e.createElement)("p",{className:"jio-creator__hint"},(0,a.__)("这篇改稿不会立即覆盖线上文章;审核通过后才会替换。","jio")),(0,e.createElement)("main",{className:"jio-creator__canvas"},(0,e.createElement)("label",{className:"jio-creator__title"},(0,e.createElement)("span",{className:"screen-reader-text"},(0,a.__)("文章标题","jio")),(0,e.createElement)("textarea",{value:n.title,onChange:e=>ne({title:e.target.value}),rows:1,placeholder:(0,a.sprintf)(/* translators: %d: max title length */ /* translators: %d: max title length */ +(0,a.__)("%d年前","jio"),Math.floor(o/S))}(n.at):"",d=x[n.state]||x.ready;return(0,e.createElement)("footer",{className:"jio-creator__status",role:"contentinfo"},(0,e.createElement)("div",{className:"jio-creator__status-left"},(0,e.createElement)("span",{className:"jio-creator__status-count"},(0,a.__)("字数","jio"),":",t),(0,e.createElement)("span",{className:"jio-creator__status-mode"},(0,a.__)("Markdown 语法输入中","jio"))),(0,e.createElement)("div",{className:"jio-creator__status-meta"},(0,e.createElement)(k,{value:n}),(0,e.createElement)("span",{className:"jio-creator__status-dot","aria-hidden":"true"},"·"),(0,e.createElement)("span",{className:"jio-creator__status-time"},s||d)),(0,e.createElement)("div",{className:"jio-creator__status-actions"},(0,e.createElement)("button",{type:"button",className:"jio-creator__status-ghost",onClick:l,disabled:r},(0,a.__)("保存草稿","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator__status-ghost",onClick:i,disabled:r},(0,a.__)("预览","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator__status-primary",onClick:c,disabled:r},o?(0,a.__)("提交改稿","jio"):(0,a.__)("发布","jio"))))}const $=e=>e.replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),q=[{value:"generic",label:(0,a.__)("通用","jio")},{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"php",label:"PHP"},{value:"python",label:"Python"},{value:"java",label:"Java"},{value:"go",label:"Go"},{value:"rust",label:"Rust"},{value:"csharp",label:"C#"},{value:"cpp",label:"C++"},{value:"sql",label:"SQL"},{value:"json",label:"JSON"},{value:"bash",label:"Shell"},{value:"css",label:"CSS"},{value:"html",label:"HTML"},{value:"markdown",label:"Markdown"}];const L=(e,t,a)=>Math.min(a,Math.max(t,Number.isFinite(e)?Math.round(e):t)),I={table:(0,a.__)("插入表格","jio"),math:(0,a.__)("插入公式","jio"),footnote:(0,a.__)("插入注释","jio")};function R({kind:n,onSubmit:o,onClose:r}){const[l,i]=(0,t.useState)(3),[c,s]=(0,t.useState)(3),[d,u]=(0,t.useState)(!0),[m,p]=(0,t.useState)(!1),[_,f]=(0,t.useState)("a^2 + b^2 = c^2"),[b,g]=(0,t.useState)(!0),[h,j]=(0,t.useState)(""),y=(0,t.useRef)(null),E=(0,t.useRef)(null),v=(0,t.useRef)(null),k=(0,t.useRef)(null);(0,t.useEffect)(()=>{(E.current||v.current||k.current)?.focus();const e=e=>{"Escape"===e.key&&(e.preventDefault(),r())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]);const N=(0,t.useMemo)(()=>"footnote"===n?""!==h.trim():"math"!==n||""!==_.trim(),[n,h,_]);return(0,e.createElement)("div",{className:"jio-creator-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"jio-creator-dialog-title"},(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__backdrop","aria-label":(0,a.__)("关闭","jio"),onClick:r}),(0,e.createElement)("div",{className:"jio-creator-dialog__panel",ref:y},(0,e.createElement)("header",{className:"jio-creator-dialog__head"},(0,e.createElement)("h2",{id:"jio-creator-dialog-title"},I[n]),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__close",onClick:r,"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,e.createElement)("div",{className:"jio-creator-dialog__body"},"table"===n&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"jio-creator-dialog__row"},(0,e.createElement)("label",null,(0,e.createElement)("span",null,(0,a.__)("行数","jio")),(0,e.createElement)("input",{ref:E,type:"number",min:1,max:20,value:l,onChange:e=>i(Number(e.target.value))})),(0,e.createElement)("label",null,(0,e.createElement)("span",null,(0,a.__)("列数","jio")),(0,e.createElement)("input",{type:"number",min:1,max:10,value:c,onChange:e=>s(Number(e.target.value))}))),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:d,onChange:e=>u(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("首行为表头","jio"))),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:m,onChange:e=>p(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("隔行变色","jio")))),"math"===n&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("label",{className:"jio-creator-dialog__field"},(0,e.createElement)("span",null,(0,a.__)("公式","jio")),(0,e.createElement)("textarea",{ref:v,rows:3,value:_,onChange:e=>f(e.target.value),placeholder:"a^2 + b^2 = c^2"})),(0,e.createElement)("p",{className:"jio-creator-muted"},(0,a.__)("支持上标 ^ 与下标 _,例如 x^2 与 a_n;暂不支持完整 LaTeX。","jio")),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:b,onChange:e=>g(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("独占一行显示","jio")))),"footnote"===n&&(0,e.createElement)("label",{className:"jio-creator-dialog__field"},(0,e.createElement)("span",null,(0,a.__)("注释内容","jio")),(0,e.createElement)("textarea",{ref:k,rows:4,value:h,onChange:e=>j(e.target.value),placeholder:(0,a.__)("填写要补充说明的内容","jio")}))),(0,e.createElement)("footer",{className:"jio-creator-dialog__foot"},(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__ghost",onClick:r},(0,a.__)("取消","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__primary",onClick:()=>{N&&o("table"!==n?"math"!==n?{kind:n,note:h.trim()}:{kind:n,formula:_.trim(),display:b}:{kind:n,rows:L(l,1,20),cols:L(c,1,10),header:d,striped:m})},disabled:!N},(0,a.__)("插入","jio")))))}const D=window.jioCreatorStudio||{},P=D.nonce||"",z=`jio-studio-${D.sourceId||0}`,A="jio-creator-content";function T(){const e=D.pay||{},t=D.categories&&D.categories.selected||[],a=D.tags&&D.tags.items||[];return{postId:Number(D.sourceId||0),versionId:Number(D.versionId||0),rev:Number(D.versionRev||0),title:String(D.title||""),content:String(D.content||""),schedule:{enabled:!1,at:""},categories:t.map(Number),tags:a.slice(),custom:D.custom||{},featured:D.featured||{type:"",data:{}},pay:{enabled:!!e.enabled,modo:"points"===e.payModo?"points":"cash",price:String(e.price||"0.00"),points:Number(e.points||0),vip1Price:String(e.vip1Price||"0.00"),vip2Price:String(e.vip2Price||"0.00"),payLimit:Number(e.payLimit||0),downloads:Array.isArray(e.downloads)?e.downloads:[]}}}function U(e){if(!e||e.removed)return;const t=e.getDoc(),a=e.getContentAreaContainer()?.querySelector("iframe");if(!t||!a)return;const n=Math.max(320,t.documentElement.scrollHeight,t.body?t.body.scrollHeight:0);a.style.height=`${n}px`,a.style.overflow="hidden"}function B(e){var t;const a=null!==(t=e?.getBody?.())&&void 0!==t?t:null;a&&a.querySelectorAll("pre.enlighter-pre[data-jio-code]").forEach(e=>{const t=e.querySelector(":scope > .jio-code-lang"),a=e.getAttribute("data-enlighter-language")||"generic";if(t){t.setAttribute("data-jio-code-lang",a);const e=q.find(e=>e.value===a)?.label||a;return void((t.textContent||"")!==e&&(t.textContent=e))}const n=document.createElement("span");n.className="jio-code-lang",n.contentEditable="false",n.setAttribute("data-jio-code-lang",a),n.textContent=q.find(e=>e.value===a)?.label||a,e.insertBefore(n,e.firstChild)})}function F(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(//g,">")}function O(e){const t=String(e||"").trim();if(!t)return"";try{const e=new URL(t,window.location.href);return"http:"===e.protocol||"https:"===e.protocol?e.href:""}catch(e){return""}}function K(e){const t=document.createElement("div");return t.innerHTML=e,(t.textContent||"").replace(/\s+/g,"")}function H(){const[n,o]=(0,t.useState)(T),l=(0,t.useRef)(n);l.current=n;const i=(0,t.useRef)(null),c=(0,t.useRef)(null),d=(0,t.useRef)(null),m=(0,t.useRef)(!1),p=(0,t.useRef)(()=>{}),[_,f]=(0,t.useState)(!1),[h,E]=(0,t.useState)({canUndo:!1,canRedo:!1}),[v,k]=(0,t.useState)("p"),[N,w]=(0,t.useState)(()=>({state:D.sourceId||D.versionId||D.content?"saved":"ready",at:""})),[C,S]=(0,t.useState)(!1),[x,L]=(0,t.useState)(null),[I,H]=(0,t.useState)(null),J=(0,t.useRef)(null),[V,W]=(0,t.useState)(null),[Q,X]=(0,t.useState)(null),Y=(0,t.useRef)(!1),G=(0,t.useRef)(0),Z=D.capabilities||{},ee={titleMin:Number(D.limits?.titleMin||1),titleMax:Number(D.limits?.titleMax||30),titlePlaceholder:String(D.limits?.titlePlaceholder||(0,a.__)("请输入标题","jio")),priceMin:Number(D.pay?.priceMin||0),priceMax:Number(D.pay?.priceMax||0),pointsMin:Number(D.pay?.pointsMin||0),pointsMax:Number(D.pay?.pointsMax||0)},te=!!D.isPublished,ae=(0,t.useMemo)(()=>Array.from(K(n.content)).length,[n.content]),ne=(0,t.useCallback)(e=>{Y.current=!0,G.current+=1;const t={...l.current,...e};l.current=t,o(t)},[]),oe=(0,t.useCallback)(e=>{if(e===l.current.content)return;Y.current=!0,G.current+=1;const t={...l.current,content:e};l.current=t,o(t)},[]),re=(0,t.useCallback)(e=>{const t=e?.undoManager;t&&E({canUndo:"function"==typeof t.hasUndo&&t.hasUndo(),canRedo:"function"==typeof t.hasRedo&&t.hasRedo()})},[]),le=(0,t.useCallback)(e=>{const t=e?.selection?.getNode(),a=t?e.dom.getParent(t,"p,h1,h2,h3,blockquote")||t:null,n=a?.nodeName?.toLowerCase()||"p";k(["h1","h2","h3","blockquote"].includes(n)?n:"p")},[]),ie=(0,t.useCallback)((e={})=>{const t=l.current;return{post_id:t.postId,version_id:t.versionId,rev:t.rev,title:t.title,content:t.content,categories:t.categories,tags:t.tags,custom:t.custom,featured:t.featured,schedule:{enabled:!!t.schedule.enabled,at:t.schedule.enabled?t.schedule.at:""},pay:g(t.pay),...e}},[]),ce=(0,t.useCallback)(async(e=!1)=>{const t=i.current;t&&!t.removed&&oe(j(t.getContent()));const a=l.current;if(!Y.current&&(a.postId>0||a.versionId>0))return!0;const n=G.current;if(""===a.title.trim()&&""===K(a.content).trim()&&!/<(?:img|table|pre|hr|iframe|video)/i.test(a.content))return!0;w({state:"saving",at:""});try{const t=await r(D.creator.saveUrl,ie({autosave:e}),P),a={...l.current,postId:Number(t.post_id||l.current.postId||0),versionId:Number(t.version_id||l.current.versionId||0),rev:Number(t.rev||t.versionRev||l.current.rev||0)};window.jioSubmitData&&(window.jioSubmitData.postId=a.postId);const i=G.current===n;return Y.current=!i,l.current=a,o(a),w({state:i?"saved":"saving",at:i?(new Date).toLocaleTimeString():""}),i}catch(e){return w({state:409===e?.status?"conflict":"error",at:""}),!1}},[ie]);p.current=()=>{ce(!1)};const se=(0,t.useCallback)(async e=>{if(await ce(!1)){w({state:"submitting",at:""});try{let t="";const n=window.JioCaptcha;if(D.captcha?.enabled&&n&&"function"==typeof n.run){const e=await n.run("front_submit");if(null===e)return w({state:"ready",at:""}),void W({tone:"error",text:(0,a.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const o=await r(D.creator.submitUrl,ie({post_id:l.current.postId,version_id:l.current.versionId,rev:l.current.rev,publish_now:e,captcha_proof:t}),P);Y.current=!1,w({state:"submitted",at:""}),W({tone:"ok",text:String(o.message||(0,a.__)("已提交","jio"))}),S(!1);const i=o.url||o.goto||D.urls?.center;i&&window.setTimeout(()=>{window.location.href=i},900)}catch(e){w({state:"error",at:""}),W({tone:"error",text:String(e?.message||(0,a.__)("提交失败","jio"))})}}else W({tone:"error",text:(0,a.__)("内容保存失败,请重试后再提交","jio")})},[ie,ce]),de=(0,t.useCallback)(async()=>{if(await ce(!1))try{const e=await r(D.creator.previewUrl,{post_id:l.current.postId,version_id:l.current.versionId},P);e.url&&window.open(String(e.url),"_blank","noopener")}catch(e){W({tone:"error",text:String(e?.message||(0,a.__)("预览失败","jio"))})}},[ce]),{markLocalSaved:ue,clear:me}=function({key:e,snapshot:a,onFound:n}){const o=(0,t.useRef)(a);o.current=a;const r=(0,t.useRef)(!1);return(0,t.useEffect)(()=>{if(!r.current){r.current=!0;try{const t=window.localStorage.getItem(e);if(!t)return;const o=JSON.parse(t),r="string"==typeof o.at?Date.parse(o.at):NaN;if(!Number.isFinite(r)||Date.now()-r>6048e5)return void window.localStorage.removeItem(e);"string"==typeof o.content&&o.content!==a.content&&n(String(o.at))}catch(t){window.localStorage.removeItem(e)}}},[e,n,a.content]),{markLocalSaved:(0,t.useCallback)(()=>{try{window.localStorage.setItem(e,JSON.stringify(o.current))}catch(e){}},[e]),clear:(0,t.useCallback)(()=>{try{window.localStorage.removeItem(e)}catch(e){}},[e])}}({key:z,snapshot:{title:n.title,content:n.content,at:(new Date).toISOString()},onFound:e=>X({savedAt:e})}),pe=function({enabled:e,onSave:a,onLocal:n,remoteDelay:o=4e3,localDelay:r=1500}){const l=(0,t.useRef)(null),i=(0,t.useRef)(null),c=(0,t.useRef)(!1),s=(0,t.useRef)(a),d=(0,t.useRef)(n);s.current=a,d.current=n;const u=(0,t.useCallback)(()=>{l.current&&(window.clearTimeout(l.current),l.current=null),i.current&&(window.clearTimeout(i.current),i.current=null)},[]),m=(0,t.useCallback)(async()=>{if(!c.current){c.current=!0;try{await s.current()}finally{c.current=!1}}},[]),p=(0,t.useCallback)(()=>{u(),d.current(),e&&(i.current=window.setTimeout(()=>d.current(),r),l.current=window.setTimeout(()=>{m()},o))},[u,e,m,r,o]);return(0,t.useEffect)(()=>{if(!e)return;const t=()=>{"hidden"===document.visibilityState&&m()},a=()=>{m()};return document.addEventListener("visibilitychange",t),window.addEventListener("blur",a),()=>{document.removeEventListener("visibilitychange",t),window.removeEventListener("blur",a),u()}},[u,e,m]),(0,t.useMemo)(()=>({schedule:p,flush:m,cancel:u}),[u,m,p])}({enabled:!!Z.isLoggedIn,onSave:async()=>{const e=await ce(!0);return e&&me(),e},onLocal:ue}).schedule;(0,t.useEffect)(()=>{Y.current&&pe()},[n,pe]),(0,t.useEffect)(()=>{const e=e=>{Y.current&&(e.preventDefault(),e.returnValue="")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),(0,t.useEffect)(()=>{const e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()&&(e.preventDefault(),ce(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ce]),(0,t.useEffect)(()=>{const e=window.wp?.editor;if(!e||"function"!=typeof e.initialize)return void W({tone:"error",text:(0,a.__)("TinyMCE 加载失败,请刷新页面后重试。","jio")});const t={quicktags:!1,tinymce:{menubar:!1,statusbar:!1,resize:!1,toolbar1:"",toolbar2:"",toolbar3:"",plugins:"paste,link,lists,wordpress,wplink",wpautop:!0,body_class:"jio-creator__tinymce",content_css:D.creator?.contentCss||"",content_style:'\nbody {\n\tmargin: 0;\n\tcolor: #2b2b2b;\n\tfont-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;\n\tfont-size: 16px;\n\tline-height: 1.8;\n\tletter-spacing: 0.01em;\n}\np { margin: 0 0 1.1em; }\nh1, h2, h3, h4, h5, h6 { margin: 1.5em 0 0.65em; line-height: 1.4; }\nimg, iframe { max-width: 100%; }\nimg { height: auto; }\n\n/* 代码块:右上角显示当前语言,点击即可更换(交互在父组件里接管)。 */\n.enlighter-pre {\n\tposition: relative;\n\tmargin: 0 0 1.1em;\n\tpadding: 40px 14px 14px;\n\toverflow: auto;\n\tborder-radius: 8px;\n\tbackground: #f2f4f5;\n\tcursor: pointer;\n}\n.enlighter-pre code.gl {\n\tdisplay: block;\n\tborder: 0;\n\tbackground: transparent;\n\tcolor: #2b2b2b;\n\tfont-family: Consolas, Monaco, monospace;\n\tfont-size: 13px;\n\tline-height: 1.5;\n\twhite-space: pre-wrap;\n}\n.enlighter-pre .jio-code-lang {\n\tposition: absolute;\n\ttop: 9px;\n\tright: 9px;\n\tpadding: 3px 10px;\n\tborder-radius: 4px;\n\tbackground: linear-gradient(135deg, #3dcabd 10%, #254bdd 100%);\n\tcolor: #fff;\n\tfont-size: 12px;\n\tline-height: 1.5;\n\tcursor: pointer;\n\tuser-select: none;\n}\n.enlighter-pre .jio-code-lang:hover {\n\tfilter: brightness(1.08);\n}\n\n/* 引用:与前台主题的 .quote_q 视觉一致。 */\n.quote_q {\n\tposition: relative;\n\tmargin: 10px 0 20px;\n\tpadding: 1.2em;\n\tborder-radius: 6px;\n\tcolor: var(--quote-color, #555);\n\tbackground: rgba(85, 85, 85, 0.04);\n}\n.quote_q.qe_wzk_c-red { --quote-color: #dc3f3f; background: rgba(220, 63, 63, 0.05); }\n.quote_q.qe_wzk_lan { --quote-color: #0092ff; background: rgba(0, 146, 255, 0.05); }\n.quote_q.qe_wzk_lv { --quote-color: #23790e; background: rgba(35, 121, 14, 0.05); }\n.quote_q::after {\n\tposition: absolute;\n\ttop: 18px;\n\tleft: 18px;\n\tcolor: var(--quote-color, #555);\n\tcontent: \'\\201C\';\n\tfont-size: 1.4em;\n\tline-height: 1;\n\topacity: 0.6;\n}\n.quote_q > div { padding-left: 2em; opacity: 0.85; }\n.quote_q > div > p:last-child { margin-bottom: 0; }\n\n/* 表格。 */\n.jio-content-table {\n\twidth: 100%;\n\tmargin: 0 0 1.1em;\n\tborder-collapse: collapse;\n\tfont-size: 14px;\n}\n.jio-content-table th,\n.jio-content-table td {\n\tpadding: 10px 12px;\n\tborder: 1px solid #e6e9e8;\n\tline-height: 1.6;\n}\n.jio-content-table thead th {\n\tbackground: #f6f8f7;\n\tfont-weight: 600;\n\ttext-align: left;\n}\n.jio-content-table.is-striped tbody tr:nth-child(odd) td { background: #f7f9f8; }\n\n/* 公式。 */\n.jio-math {\n\tfont-family: "Cambria Math", "Latin Modern Math", "Times New Roman", serif;\n\tfont-size: 1.05em;\n\twhite-space: pre-wrap;\n}\n.jio-math--block {\n\tdisplay: block;\n\tmargin: 12px 0;\n\tpadding: 10px;\n\tborder-radius: 6px;\n\tbackground: #f8faf9;\n\ttext-align: center;\n}\n.jio-math sup, .jio-math sub { font-size: 0.72em; }\n.jio-toc-placeholder {\n\theight: 40px;\n\tmargin: 0 0 1.1em;\n\tborder: 1px dashed #d3ded8;\n\tborder-radius: 8px;\n\tbackground: #f7faf9;\n\tcolor: #8c9a94;\n\tfont-size: 12px;\n\tline-height: 40px;\n\ttext-align: center;\n}\n.jio-toc-placeholder::after { content: \'目录将在发布后自动生成\'; }\n\n/* 注释:编辑器里显示上标标记,发布后由服务端渲染编号与注释列表。 */\n.jio-footnote-ref {\n\tdisplay: inline-block;\n\tmax-width: 100%;\n\tpadding: 0 6px;\n\tborder-radius: 4px;\n\tbackground: #eef5f2;\n\tcolor: #267665;\n\tfont-size: 0.78em;\n\tline-height: 1.6;\n\tvertical-align: super;\n\tcursor: default;\n}\n.jio-footnote-ref::before {\n\tcontent: \'注 \';\n\topacity: 0.6;\n}\n\n/* 附件链接。 */\n.jio-file-link {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tgap: 6px;\n\tpadding: 6px 12px;\n\tborder: 1px solid #e6e9e8;\n\tborder-radius: 6px;\n\tbackground: #f7f8f8;\n\ttext-decoration: none;\n}\n',height:520,placeholder:String(D.limits?.contentPlaceholder||""),setup:e=>{i.current=e,e.on("init",()=>{m.current=!0,f(!0),null!==d.current?(e.setContent(y(d.current)),d.current=null):e.setContent(y(e.getContent())),B(e),U(e),function(e){const t=e.getDoc();if(!t||t.getElementById("jio-block-actions"))return;const a=t.createElement("div");a.id="jio-block-actions",a.className="jio-creator__block-actions",a.innerHTML='',t.body.appendChild(a);let n=null;const o=()=>{n=null,a.classList.remove("is-visible")};t.addEventListener("mouseover",e=>{const r=e.target?.closest?.("table,pre.enlighter-pre,hr,.quote_q,p");r&&r!==t.body&&!r.classList.contains("jio-code-lang")&&(e=>{if(!e||e===t.body)return void o();if("P"===e.tagName&&""===(e.textContent||"").trim())return void o();n=e;const r=e.getBoundingClientRect();a.style.top=`${r.top+t.documentElement.scrollTop+6}px`,a.style.left=r.right-40+"px",a.classList.add("is-visible")})(r)}),t.addEventListener("mouseleave",o),a.addEventListener("mousedown",e=>e.preventDefault()),a.addEventListener("click",t=>{const a=t.target?.closest("[data-jio-block-delete]");if(!a||!n)return;t.preventDefault();const r=n;o(),e.undoManager.transact(()=>{e.dom.remove(r)}),e.nodeChanged(),e.undoManager.add(),0===e.getBody().children.length&&(e.setContent("

"),e.selection.setCursorLocation(e.getBody().firstChild,0)),U(e)})}(e),re(e),le(e)}),e.on("NodeChange",()=>le(e)),e.on("input change Undo Redo AddUndo",()=>{oe(j(e.getContent())),re(e),B(e),U(e)}),e.on("keydown",t=>{if((t.metaKey||t.ctrlKey)&&83===t.keyCode)return t.preventDefault(),void p.current();!function(e,t){const a=Number(t.keyCode);if(8!==a&&46!==a)return;const n=e.selection;if(!n||!n.isCollapsed())return;const o=e.getBody(),r=n.getNode(),l=(i=r)&&1===i.nodeType&&""===(i.textContent||"").trim()&&!e.dom.getParent(i,"table,pre,hr,.quote_q,.jio-math--block,.jio-toc-placeholder",o)?r:null;var i;const c=l?8===a?l.previousElementSibling:l.nextElementSibling:null;if((e=>!!e&&1===e.nodeType&&!!e.matches?.("table,pre,hr,.quote_q,.jio-math--block,.jio-toc-placeholder"))(c))return t.preventDefault(),e.dom.remove(c),e.nodeChanged(),void e.undoManager.add();const s=e.dom.getParent(r,"table,pre,hr,.quote_q,.jio-math--block,.jio-toc-placeholder",o);if(!s)return;const d=t=>{const a=e.dom.createRng();a.selectNodeContents(s),a.collapse(t);const o=n.getRng();return o&&"function"==typeof o.compareBoundaryPoints&&0===o.compareBoundaryPoints(t?1:3,a)};if(!(8===a&&d(!0)||46===a&&d(!1)))return;t.preventDefault();const u=s.parentElement;e.dom.remove(s),u&&0===u.children.length&&(e.setContent("

"),e.selection.setCursorLocation(e.getBody().firstChild,0)),e.nodeChanged(),e.undoManager.add()}(e,t)})}}};return e.initialize(A,t),()=>{e.remove?.(A),m.current=!1,i.current=null}},[oe]);const _e=(0,t.useCallback)(()=>{try{const e=window.localStorage.getItem(z);if(e){const t=JSON.parse(e),a={};"string"==typeof t.title&&(a.title=t.title),"string"==typeof t.content&&(a.content=t.content),ne(a),"string"==typeof t.content&&(m.current?i.current?.setContent(t.content):d.current=t.content)}}catch(e){}X(null)},[ne]),fe=(0,t.useCallback)(()=>{const e=i.current;e&&!e.removed&&(c.current=e.selection.getBookmark(2,!0))},[]),be=(0,t.useCallback)(()=>{const e=i.current;if(!e||e.removed)return null;if(e.focus(),c.current){try{e.selection.moveToBookmark(c.current)}catch(e){}c.current=null}return e},[]),ge=(0,t.useCallback)((e,t)=>{const a=be();a&&("undo"===e?a.undoManager.undo():"redo"===e?a.undoManager.redo():"format"===e?("p"===t?a.execCommand("FormatBlock",!1,"p"):a.formatter.toggle(t||"h2"),le(a)):a.execCommand(e),a.nodeChanged())},[be]),he=(0,t.useCallback)(()=>{const e=be();if(!e)return;const t=window.wpLink;if(t&&"function"==typeof t.open)return void t.open(e.id);const n=window.prompt((0,a.__)("输入链接地址","jio"),"https://"),o=n?O(n):"";o&&e.execCommand("mceInsertLink",!1,{href:o})},[be]),je=(0,t.useCallback)(e=>{const t=be();t&&e&&(t.insertContent(e),t.nodeChanged(),oe(j(t.getContent())),re(t),B(t))},[be]),ye=(0,t.useCallback)(e=>{fe(),"table"!==e&&"math"!==e&&"footnote"!==e?"code"!==e?"list"!==e?"toc"!==e?"divider"===e&&je("

"):je("

[jio_toc]

"):je("

"):je(function(e="generic",t=""){const n=$(""!==t?t:(0,a.__)("在此输入代码","jio"));return`
`+n+"

"}("generic")):L(e)},[je,fe]),Ee=(0,t.useCallback)(e=>{const t=be();if(!t)return;const a=String(t.selection.getContent()||"").trim(),n=t.dom.getParent(t.selection.getNode(),".quote_q");if(n)return n.className="quote_q quote-mce"+(e?` ${e}`:""),void t.nodeChanged();je(function(e,t){const a=["quote_q","quote-mce"];t&&a.push(t);const n=""!==e.trim()?`

${e}

`:"

";return`
${n}

`}(a,e))},[be,je]),ve=(0,t.useCallback)(e=>{L(null),"table"===e.kind?je(function({rows:e,cols:t,header:n,striped:o}){const r=Math.max(1,Math.min(20,e)),l=Math.max(1,Math.min(10,t)),i=e=>Array.from({length:l},(t,n)=>`<${e}>${"th"===e?$(`${(0,a.__)("列","jio")} ${n+1}`):""}`).join("");let c="";n&&(c+=`${i("th")}`);const s=Math.max(1,n?r-1:r);c+=`${Array.from({length:s},()=>`${i("td")}`).join("")}`;const d=["jio-content-table"];return o&&d.push("is-striped"),`${c}

`}(e)):"math"===e.kind?je(function({formula:e,display:t}){const a=(n=e.trim(),$(n).replace(/\^\{([^{}]*)\}|\^(\S)/gu,"$1$2").replace(/_\{([^{}]*)\}|_(\S)/gu,"$1$2"));var n;const o=`data-jio-math-source="${$(e.trim())}" data-jio-math-display="${t?"1":"0"}"`;return t?`

${a}

`:`${a}`}(e)):je(function(e){const t=e.trim()||(0,a.__)("注释内容","jio");return`${$(t)}`}(e.note))},[je]),ke=(0,t.useCallback)(e=>{const t=i.current,n=window.JioSubmitMedia;t&&n&&"function"==typeof n.open?(fe(),n.open({type:e,multiple:"image"===e&&void 0,onSelect:t=>{const a=Array.isArray(t)?t:[t],n=be();if(!n)return;const o=a.map(t=>{const a=O(t?.large_url||t?.url);if(!a)return"";const n=Number(t.attachment_id||t.id||0),o=n>0?` data-edit-file-id="${n}"`:"";if("image"===e){const e=O(t?.url||a),n=e?` data-full-url="${F(e)}"`:"";return`

${F(String(t.name||t.title||

`}if("file"===e){const e=String(t.filename||t.name||a.split("/").pop()||"");return`

${F(e)}

`}return`

`}).join("");o&&(n.insertContent(o),n.nodeChanged(),oe(n.getContent()),re(n))},onEmbed:e=>{const t=be();t&&(t.insertContent(`${e}

`),t.nodeChanged(),oe(t.getContent()),re(t))}})):W({tone:"error",text:(0,a.__)("媒体工具尚未加载,请刷新页面后重试。","jio")})},[be,fe]);return(0,e.createElement)("div",{className:"jio-creator","data-status":D.status||"","data-editor-ready":_?"true":"false"},(0,e.createElement)("header",{className:"jio-creator__bar"},(0,e.createElement)("div",{className:"jio-creator__bar-left"},(0,e.createElement)("a",{className:"jio-creator__back",href:D.urls?.center||"/","aria-label":(0,a.__)("返回作者中心","jio")},(0,e.createElement)("i",{className:"fa fas fa-angle-left","aria-hidden":"true"})),(0,e.createElement)("span",{className:"jio-creator__bar-brand"},"Jio"),(0,e.createElement)("span",{className:"jio-creator__bar-divider","aria-hidden":"true"}),(0,e.createElement)("span",{className:"jio-creator__bar-mode"},te?(0,a.__)("修改文章","jio"):(0,a.__)("写文章","jio"))),(0,e.createElement)(u,{ready:_,formatValue:v,onFormatChange:k,canUndo:h.canUndo,canRedo:h.canRedo,capabilities:Z,onCommand:ge,onRememberSelection:fe,onOpenLink:he,onOpenMedia:ke,onInsertBlock:ye,onInsertQuote:Ee})),Q&&(0,e.createElement)("div",{className:"jio-creator__notice",role:"status"},(0,e.createElement)("span",null,(0,a.__)("发现本地未同步的草稿。","jio")),(0,e.createElement)("button",{type:"button",onClick:_e},(0,a.__)("恢复","jio")),(0,e.createElement)("button",{type:"button",onClick:()=>X(null)},(0,a.__)("忽略","jio"))),V&&(0,e.createElement)("div",{className:`jio-creator__notice is-${V.tone}`,role:"status"},(0,e.createElement)("span",null,V.text),(0,e.createElement)("button",{type:"button",onClick:()=>W(null),"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),te&&(0,e.createElement)("p",{className:"jio-creator__hint"},(0,a.__)("这篇改稿不会立即覆盖线上文章;审核通过后才会替换。","jio")),(0,e.createElement)("main",{className:"jio-creator__canvas"},(0,e.createElement)("label",{className:"jio-creator__title"},(0,e.createElement)("span",{className:"screen-reader-text"},(0,a.__)("文章标题","jio")),(0,e.createElement)("textarea",{value:n.title,onChange:e=>ne({title:e.target.value}),rows:1,placeholder:(0,a.sprintf)(/* translators: %d: max title length */ /* translators: %d: max title length */ (0,a.__)("请输入标题(最多 %d 个字)","jio"),Number(ee.titleMax)||100),spellCheck:!1,maxLength:Number(ee.titleMax)||100})),(0,e.createElement)("div",{className:"jio-creator__editor","data-editor-ready":_?"true":"false"},(0,e.createElement)("textarea",{id:A,defaultValue:n.content,onChange:e=>oe(e.target.value),"aria-label":(0,a.__)("文章正文","jio")}))),(0,e.createElement)(b,{featured:n.featured,canEditCover:!!Z.canUploadImage,canSchedule:!!Z.canSchedule,scheduleEnabled:!!n.schedule.enabled,scheduleAt:n.schedule.at,onFeaturedChange:e=>ne({featured:e}),onScheduleChange:(e,t)=>ne({schedule:{enabled:e,at:t}})}),null!==I&&(0,e.createElement)("div",{className:"jio-creator-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"jio-code-lang-title"},(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__backdrop","aria-label":(0,a.__)("关闭","jio"),onClick:()=>H(null)}),(0,e.createElement)("div",{className:"jio-creator-dialog__panel"},(0,e.createElement)("header",{className:"jio-creator-dialog__head"},(0,e.createElement)("h2",{id:"jio-code-lang-title"},(0,a.__)("代码语言","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__close",onClick:()=>H(null),"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,e.createElement)("div",{className:"jio-creator-dialog__body"},(0,e.createElement)("div",{className:"jio-creator__lang-grid"},q.map(t=>(0,e.createElement)("button",{key:t.value,type:"button",className:"jio-creator__lang-item"+(t.value===I?" is-active":""),onClick:()=>{const e=J.current;if(J.current=null,H(null),!e)return;e.setAttribute("data-enlighter-language",t.value);const a=e.querySelector("code");a&&a.setAttribute("data-enlighter-language",t.value),B(i.current),oe(j(i.current.getContent()))}},t.label)))))),x&&(0,e.createElement)(R,{kind:x,onSubmit:ve,onClose:()=>L(null)}),(0,e.createElement)(M,{charCount:ae,saveState:N,isPublishedEdit:te,saving:!_||"saving"===N.state||"submitting"===N.state,onSaveDraft:()=>{ce(!1)},onPreview:()=>{de()},onPublish:()=>S(!0)}),C&&(0,e.createElement)(s,{draft:n,setDraft:ne,capabilities:Z,limits:ee,taxonomy:{categories:D.categories&&D.categories.items||[],tags:!!D.tags?.enabled,customDefs:D.customDefs||[]},isPublishedEdit:te,onClose:()=>S(!1),onSaveDraft:()=>{ce(!1)},onSubmit:e=>{se(e)},privateStorage:!!D.privateStorage,privateUploads:D.privateUploads||[],captcha:!!D.captcha?.enabled,saving:"saving"===N.state||"submitting"===N.state}))}function J(){const a=document.getElementById("jio-creator-studio");a&&(a.classList.add("is-ready"),(0,t.createRoot)(a).render((0,e.createElement)(H,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",J):J()})(); \ No newline at end of file diff --git a/assets/creator-studio/src/index.tsx b/assets/creator-studio/src/index.tsx index 29862bc3..cd745409 100644 --- a/assets/creator-studio/src/index.tsx +++ b/assets/creator-studio/src/index.tsx @@ -459,8 +459,10 @@ function Studio(): JSX.Element { return true; } const requestRevision = editRevisionRef.current; - const hasDocument = current.title.trim() !== '' || plainText(current.content).trim() !== ''; - if (autosave && !hasDocument) { + // 空文档(连块级内容都没有)不发请求:服务端会拒绝,前端也不该把它当失败。 + const hasDocument = current.title.trim() !== '' || plainText(current.content).trim() !== '' + || /<(?:img|table|pre|hr|iframe|video)/i.test(current.content); + if (!hasDocument) { return true; } setSaveState({ state: 'saving', at: '' }); diff --git a/src/Core/FrontSubmitSave.php b/src/Core/FrontSubmitSave.php index b295169a..25443e55 100644 --- a/src/Core/FrontSubmitSave.php +++ b/src/Core/FrontSubmitSave.php @@ -65,11 +65,16 @@ trait FrontSubmitSave { $content = (string) ($data['post_content'] ?? $data['content'] ?? ''); $excerpt = sanitize_textarea_field((string) ($data['excerpt'] ?? $data['post_excerpt'] ?? '')); - if ($title === '') { - return ['success' => false, 'message' => __('请填写文章标题', 'jio')]; - } - if (trim(wp_strip_all_tags($content)) === '') { - return ['success' => false, 'message' => __('还未填写任何内容', 'jio')]; + // 草稿只要有任何可保存的内容就落库;正式投稿才要求标题与正文齐备。 + if (!$is_draft) { + if ($title === '') { + return ['success' => false, 'message' => __('请填写文章标题', 'jio')]; + } + if (trim(wp_strip_all_tags($content)) === '') { + return ['success' => false, 'message' => __('还未填写任何内容', 'jio')]; + } + } elseif ($title === '' && trim(wp_strip_all_tags($content)) === '') { + return ['success' => false, 'message' => __('请先写点什么再保存', 'jio')]; } $categories = $this->normalize_category_ids($data); diff --git a/tests/widget-system/creator-studio-contract.test.cjs b/tests/widget-system/creator-studio-contract.test.cjs index bf5d6fd1..8366726c 100644 --- a/tests/widget-system/creator-studio-contract.test.cjs +++ b/tests/widget-system/creator-studio-contract.test.cjs @@ -66,6 +66,19 @@ test('stale autosave requests are rejected instead of overwriting', () => { assert.match(appSource, /status === 409/); }); +test('drafts save with partial content instead of being rejected', () => { + // 只写标题、或正文只有图片/表格/代码块时,也必须能存草稿。 + assert.match(saveTrait, /请先写点什么再保存/); + const draftBranch = saveTrait.indexOf('if (!$is_draft) {'); + const titleGuard = saveTrait.indexOf("if ($title === '') {"); + assert.ok(draftBranch !== -1 && titleGuard !== -1, 'draft branch and title guard both exist'); + assert.ok(draftBranch < titleGuard, 'title/content requirements only apply to submit'); + // 前端空文档不再发保存请求。 + assert.match(appSource, /const hasDocument = /); + assert.match(appSource, /if \(!hasDocument\) \{\s*return true;/); + assert.match(appSource, /img\|table\|pre\|hr\|iframe\|video/); +}); + test('paid payload is validated before any post write', () => { const prepareAt = saveTrait.indexOf('prepare_pay_meta'); const insertAt = saveTrait.indexOf('wp_insert_post');