Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
3 lines
46 KiB
JavaScript
3 lines
46 KiB
JavaScript
(()=>{"use strict";const e=window.React,t=window.wp.element,a=window.wp.i18n;function n(e,t){const a=e&&(e.message||e.error)||(401===t?"登录状态已失效,请刷新页面重新登录。":"请求失败,请稍后重试。"),n=new Error(String(a));return n.status=t,n.code=e&&e.code?String(e.code):"",n.data=e,n}async function r(e){try{return await e.json()}catch(e){return null}}async function o(e,t,a){const o=await fetch(e,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-WP-Nonce":a},body:JSON.stringify(t)}),l=await r(o);if(!o.ok)throw n(l,o.status);return l}async function l(e,t,a,o={}){const l=new FormData;l.append("file",t),Object.entries(o).forEach(([e,t])=>l.append(e,t));const i=await fetch(e,{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":a},body:l}),c=await r(i);if(!i.ok)throw n(c,i.status);return c}const i=window.jioCreatorStudio||{},c=i.nonce||"";function s(n){const{draft:r,setDraft:o,capabilities:s,limits:u,taxonomy:d,isPublishedEdit:m,onClose:p,onSaveDraft:_,onSubmit:b,privateStorage:f,privateUploads:g,saving:h,captcha:j}=n,[E,y]=(0,t.useState)(""),[v,k]=(0,t.useState)(""),[N,w]=(0,t.useState)(!1),C=(0,t.useRef)(null),S=(0,t.useRef)(null);(0,t.useEffect)(()=>{const e=S.current,t=document.getElementById("jio-creator-captcha");if(!e||!t)return;const a=t.parentElement;return e.appendChild(t),t.removeAttribute("hidden"),()=>{a&&(a.appendChild(t),t.setAttribute("hidden",""))}},[]);const x=(0,t.useMemo)(()=>(r.title||"").trim().length,[r.title])>=Number(u.titleMin||1),M=()=>{const e=E.trim();if(!e)return;const t=e.split(/[,,\n]+/u).map(e=>e.trim()).filter(Boolean);o({tags:Array.from(new Set([...r.tags,...t]))}),y("")};return(0,e.createElement)("div",{className:"jio-creator-drawer",role:"dialog","aria-modal":"true","aria-labelledby":"jio-creator-publish-title"},(0,e.createElement)("button",{type:"button",className:"jio-creator-drawer__backdrop","aria-label":(0,a.__)("关闭","jio"),onClick:p}),(0,e.createElement)("div",{className:"jio-creator-drawer__panel"},(0,e.createElement)("header",{className:"jio-creator-drawer__head"},(0,e.createElement)("h2",{id:"jio-creator-publish-title"},m?(0,a.__)("提交改稿","jio"):(0,a.__)("发布文章","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-drawer__close",onClick:p,"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,e.createElement)("div",{className:"jio-creator-drawer__body"},m&&(0,e.createElement)("p",{className:"jio-creator-drawer__note"},(0,a.__)("审核通过前,读者看到的仍然是当前线上版本。","jio")),(0,e.createElement)("section",{className:"jio-creator-field"},(0,e.createElement)("h3",null,(0,a.__)("分类","jio")),(0,e.createElement)("div",{className:"jio-creator-chips"},0===d.categories.length&&(0,e.createElement)("span",{className:"jio-creator-muted"},(0,a.__)("暂无可选分类","jio")),d.categories.map(t=>(0,e.createElement)("label",{key:t.id,className:"jio-creator-chip"+(r.categories.includes(t.id)?" is-active":"")},(0,e.createElement)("input",{type:"checkbox",checked:r.categories.includes(t.id),onChange:()=>(e=>{const t=r.categories.includes(e);o({categories:t?r.categories.filter(t=>t!==e):[...r.categories,e]})})(t.id)}),(0,e.createElement)("span",null,t.name))))),d.tags&&(0,e.createElement)("section",{className:"jio-creator-field"},(0,e.createElement)("h3",null,(0,a.__)("标签","jio")),(0,e.createElement)("div",{className:"jio-creator-chips"},r.tags.map(t=>(0,e.createElement)("span",{key:t,className:"jio-creator-chip is-active"},(0,e.createElement)("span",null,t),(0,e.createElement)("button",{type:"button",onClick:()=>o({tags:r.tags.filter(e=>e!==t)}),"aria-label":(0,a.sprintf)((0,a.__)("移除标签 %s","jio"),t)},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))))),(0,e.createElement)("div",{className:"jio-creator-inline"},(0,e.createElement)("input",{type:"text",value:E,placeholder:(0,a.__)("输入标签,逗号分隔","jio"),onChange:e=>y(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),M())}}),(0,e.createElement)("button",{type:"button",onClick:M},(0,a.__)("添加","jio")))),d.customDefs.map(t=>(0,e.createElement)("section",{className:"jio-creator-field",key:t.key},(0,e.createElement)("h3",null,t.name),(0,e.createElement)("div",{className:"jio-creator-chips"},t.values.map(a=>{const n=r.custom[t.key]||[],l=n.includes(a.key);return(0,e.createElement)("label",{key:a.key,className:"jio-creator-chip"+(l?" is-active":"")},(0,e.createElement)("input",{type:"checkbox",checked:l,onChange:()=>o({custom:{...r.custom,[t.key]:l?n.filter(e=>e!==a.key):[...n,a.key]}})}),(0,e.createElement)("span",null,a.name))})))),s.canPay&&(0,e.createElement)("section",{className:"jio-creator-field"},(0,e.createElement)("div",{className:"jio-creator-switch"},(0,e.createElement)("div",null,(0,e.createElement)("h3",null,(0,a.__)("付费内容","jio")),(0,e.createElement)("p",{className:"jio-creator-muted"},(0,a.__)("开启后,未购买读者只能看到免费部分。","jio"))),(0,e.createElement)("label",{className:"jio-creator-toggle"},(0,e.createElement)("input",{type:"checkbox",checked:r.pay.enabled,onChange:e=>o({pay:{...r.pay,enabled:e.target.checked}})}),(0,e.createElement)("span",{"aria-hidden":"true"}))),r.pay.enabled&&(0,e.createElement)("div",{className:"jio-creator-pay"},(0,e.createElement)("div",{className:"jio-creator-inline"},(0,e.createElement)("label",null,(0,e.createElement)("input",{type:"radio",checked:"cash"===r.pay.modo,onChange:()=>o({pay:{...r.pay,modo:"cash"}})}),(0,e.createElement)("span",null,(0,a.__)("现金","jio"))),(0,e.createElement)("label",null,(0,e.createElement)("input",{type:"radio",checked:"points"===r.pay.modo,onChange:()=>o({pay:{...r.pay,modo:"points"}})}),(0,e.createElement)("span",null,(0,a.__)("积分","jio")))),"cash"===r.pay.modo?(0,e.createElement)("label",{className:"jio-creator-input"},(0,e.createElement)("span",null,(0,a.__)("价格","jio")),(0,e.createElement)("input",{type:"number",min:Number(u.priceMin||0),step:"0.01",value:r.pay.price,onChange:e=>o({pay:{...r.pay,price:e.target.value}})})):(0,e.createElement)("label",{className:"jio-creator-input"},(0,e.createElement)("span",null,(0,a.__)("积分价格","jio")),(0,e.createElement)("input",{type:"number",min:0,step:"1",value:r.pay.points,onChange:e=>o({pay:{...r.pay,points:Number(e.target.value)||0}})})),s.canPayDownload&&(0,e.createElement)("div",{className:"jio-creator-attachments"},(0,e.createElement)("div",{className:"jio-creator-attachments__head"},(0,e.createElement)("h4",null,(0,a.__)("资料附件","jio")),f?(0,e.createElement)("label",{className:"jio-creator-upload"},(0,e.createElement)("input",{ref:C,type:"file",onChange:()=>{(async()=>{const e=C.current?.files?.[0];if(e){k(""),w(!0);try{const t=await l(i.creator.privateUrl,e,c,{post_id:String(r.postId||0)}),a={type:"protected",assetKey:String(t.asset_key||""),fileName:String(t.name||e.name),sizeBytes:Number(t.size||e.size),sizeLabel:String(t.size_label||""),label:""};o({pay:{...r.pay,enabled:!0,downloads:[...r.pay.downloads,a]}}),C.current&&(C.current.value="")}catch(e){k(String(e?.message||(0,a.__)("资料上传失败","jio")))}finally{w(!1)}}})()},disabled:N}),(0,e.createElement)("span",null,N?(0,a.__)("上传中…","jio"):(0,a.__)("添加 PDF / ZIP","jio"))):(0,e.createElement)("p",{className:"jio-creator-muted"},(0,a.__)("私有附件存储尚未配置,暂时不能上传付费资料。","jio"))),v&&(0,e.createElement)("p",{className:"jio-creator-error"},v),r.pay.downloads.length>0&&(0,e.createElement)("ul",{className:"jio-creator-files"},r.pay.downloads.map((t,n)=>(0,e.createElement)("li",{key:`${t.assetKey||t.url}-${n}`},(0,e.createElement)("span",{className:"jio-creator-files__name"},t.assetKey?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("i",{className:"fa fas fa-lock","aria-hidden":"true"}),t.fileName||t.label||(0,a.__)("受保护资料","jio")):(0,e.createElement)(e.Fragment,null,(0,e.createElement)("i",{className:"fa fas fa-link","aria-hidden":"true"}),t.label||t.url)),t.sizeLabel&&(0,e.createElement)("span",{className:"jio-creator-muted"},t.sizeLabel),(0,e.createElement)("button",{type:"button",onClick:()=>(e=>{o({pay:{...r.pay,downloads:r.pay.downloads.filter((t,a)=>a!==e)}})})(n),"aria-label":(0,a.__)("移除","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))))),g.length>0&&(0,e.createElement)("details",{className:"jio-creator-reuse"},(0,e.createElement)("summary",null,(0,a.__)("从已上传资料中选择","jio")),(0,e.createElement)("ul",null,g.filter(e=>!r.pay.downloads.some(t=>t.assetKey===e.assetKey)).map(t=>(0,e.createElement)("li",{key:t.assetKey},(0,e.createElement)("span",null,t.fileName),(0,e.createElement)("span",{className:"jio-creator-muted"},t.sizeLabel),(0,e.createElement)("button",{type:"button",onClick:()=>o({pay:{...r.pay,enabled:!0,downloads:[...r.pay.downloads,{...t,type:"protected"}]}})},(0,a.__)("使用","jio"))))))))),!s.canPay&&s.canSaveDraft&&(0,e.createElement)("p",{className:"jio-creator-muted"},(0,a.__)("当前账号不能设置付费内容。","jio"))),(0,e.createElement)("footer",{className:"jio-creator-drawer__foot"},j&&(0,e.createElement)("div",{className:"jio-creator-drawer__captcha",ref:S}),(0,e.createElement)("div",{className:"jio-creator-drawer__actions"},(0,e.createElement)("button",{type:"button",className:"jio-creator-ghost",onClick:_,disabled:h},(0,a.__)("保存草稿","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-primary",onClick:()=>b(!1),disabled:h||!x},m?(0,a.__)("提交审核","jio"):s.canPublishNow?(0,a.__)("发布","jio"):(0,a.__)("提交审核","jio")),s.canPublishNow&&(0,e.createElement)("button",{type:"button",className:"jio-creator-link",onClick:()=>b(!0),disabled:h||!x},(0,a.__)("立即发布","jio"))))))}function u({label:t,icon:a,ready:n,onClick:r,title:o}){return(0,e.createElement)("button",{type:"button",className:"jio-creator__tool-btn",disabled:!n,onClick:r,title:o||t,"aria-label":o||t},(0,e.createElement)("i",{className:a,"aria-hidden":"true"}),(0,e.createElement)("span",{className:"jio-creator__tool-label"},t))}function d({ready:n,canUndo:r,canRedo:o,formatValue:l,onFormatChange:i,capabilities:c,onCommand:s,onRememberSelection:d,onOpenLink:m,onOpenMedia:p,onInsertBlock:_,onInsertQuote:b}){const[f,g]=(0,t.useState)(!1),h=(0,t.useRef)(null);return(0,t.useEffect)(()=>{if(!f)return;const e=e=>{h.current?.contains(e.target)||g(!1)},t=e=>{"Escape"===e.key&&g(!1)};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[f]),(0,e.createElement)("div",{className:"jio-creator__toolbar-tools",role:"toolbar","aria-label":(0,a.__)("正文编辑工具","jio"),onMouseDown:e=>{d(),e.target.closest("button")&&e.preventDefault()}},(0,e.createElement)("div",{className:"jio-creator__toolbar-group",role:"group","aria-label":(0,a.__)("撤销和重做","jio")},(0,e.createElement)(u,{label:(0,a.__)("撤销","jio"),icon:"fa fas fa-undo",ready:r,onClick:()=>s("undo")}),(0,e.createElement)(u,{label:(0,a.__)("重做","jio"),icon:"fa fas fa-redo",ready:o,onClick:()=>s("redo")})),(0,e.createElement)("span",{className:"jio-creator__toolbar-divider","aria-hidden":"true"}),(0,e.createElement)("div",{className:"jio-creator__toolbar-group",role:"group","aria-label":(0,a.__)("段落样式","jio")},(0,e.createElement)("label",{className:"jio-creator__format-field"},(0,e.createElement)("select",{className:"jio-creator__format-select","aria-label":(0,a.__)("标题级别","jio"),value:"blockquote"===l?"p":l,disabled:!n,onFocus:d,onChange:e=>{i(e.target.value),s("format",e.target.value)}},(0,e.createElement)("option",{value:"p"},(0,a.__)("正文","jio")),(0,e.createElement)("option",{value:"h1"},(0,a.__)("标题 1","jio")),(0,e.createElement)("option",{value:"h2"},(0,a.__)("标题 2","jio")),(0,e.createElement)("option",{value:"h3"},(0,a.__)("标题 3","jio"))),(0,e.createElement)("i",{className:"fa fas fa-heading","aria-hidden":"true"}),(0,e.createElement)("span",{className:"jio-creator__tool-label"},(0,a.__)("标题","jio")))),(0,e.createElement)("span",{className:"jio-creator__toolbar-divider","aria-hidden":"true"}),(0,e.createElement)("div",{className:"jio-creator__toolbar-group",role:"group","aria-label":(0,a.__)("文字格式","jio")},(0,e.createElement)(u,{label:(0,a.__)("加粗","jio"),icon:"fa fas fa-bold",ready:n,onClick:()=>s("Bold")}),(0,e.createElement)(u,{label:(0,a.__)("斜体","jio"),icon:"fa fas fa-italic",ready:n,onClick:()=>s("Italic")}),(0,e.createElement)(u,{label:(0,a.__)("下划线","jio"),icon:"fa fas fa-underline",ready:n,onClick:()=>s("Underline")})),(0,e.createElement)("span",{className:"jio-creator__toolbar-divider","aria-hidden":"true"}),(0,e.createElement)("div",{className:"jio-creator__toolbar-group",role:"group","aria-label":(0,a.__)("段落块","jio")},(0,e.createElement)(u,{label:(0,a.__)("列表","jio"),icon:"fa fas fa-list-ul",ready:n,onClick:()=>_("list")}),(0,e.createElement)(u,{label:(0,a.__)("目录","jio"),icon:"fa fas fa-list-ol",ready:n,onClick:()=>_("toc")}),(0,e.createElement)("div",{className:"jio-creator__quote",ref:h},(0,e.createElement)(u,{label:(0,a.__)("引用","jio"),icon:"fa fas fa-quote-left",ready:n,onClick:()=>g(e=>!e)}),f&&(0,e.createElement)("div",{className:"jio-creator__quote-menu",role:"menu","aria-label":(0,a.__)("引用样式","jio")},[{key:"",label:(0,a.__)("灰色引用","jio"),className:""},{key:"qe_wzk_c-red",label:(0,a.__)("红色引用","jio"),className:"is-red"},{key:"qe_wzk_lan",label:(0,a.__)("蓝色引用","jio"),className:"is-blue"},{key:"qe_wzk_lv",label:(0,a.__)("绿色引用","jio"),className:"is-green"}].map(t=>(0,e.createElement)("button",{key:t.key||"default",type:"button",role:"menuitem",className:`jio-creator__quote-option ${t.className}`.trim(),onClick:()=>{g(!1),b(t.key)}},(0,e.createElement)("span",{className:"jio-creator__quote-swatch","aria-hidden":"true"}),t.label)))),(0,e.createElement)(u,{label:(0,a.__)("分割线","jio"),icon:"fa fas fa-minus",ready:n,onClick:()=>_("divider")}),(0,e.createElement)(u,{label:(0,a.__)("代码块","jio"),icon:"fa fas fa-code",ready:n,onClick:()=>_("code")}),(0,e.createElement)(u,{label:(0,a.__)("注释","jio"),icon:"fa fas fa-comment-dots",ready:n,onClick:()=>_("footnote")}),(0,e.createElement)(u,{label:(0,a.__)("公式","jio"),icon:"fa fas fa-square-root-alt",ready:n,onClick:()=>_("math")}),(0,e.createElement)(u,{label:(0,a.__)("表格","jio"),icon:"fa fas fa-table",ready:n,onClick:()=>_("table")})),(0,e.createElement)("span",{className:"jio-creator__toolbar-divider","aria-hidden":"true"}),(0,e.createElement)("div",{className:"jio-creator__toolbar-group",role:"group","aria-label":(0,a.__)("媒体和链接","jio")},c.canUploadImage&&(0,e.createElement)(u,{label:(0,a.__)("图片","jio"),icon:"fa far fa-image",ready:n,onClick:()=>p("image")}),(c.canUploadVideo||c.canEmbed)&&(0,e.createElement)(u,{label:(0,a.__)("视频","jio"),icon:"fa fas fa-video",ready:n,onClick:()=>p("video")}),(0,e.createElement)(u,{label:(0,a.__)("链接","jio"),icon:"fa fas fa-link",ready:n,onClick:m}),c.canUploadFile&&(0,e.createElement)(u,{label:(0,a.__)("附件","jio"),icon:"fa fas fa-paperclip",ready:n,onClick:()=>p("file")})))}const m=window.jioCreatorStudio||{},p=m.nonce||"",_=e=>String(e).padStart(2,"0");function b(e){return`${e.getFullYear()}-${_(e.getMonth()+1)}-${_(e.getDate())}T${_(e.getHours())}:${_(e.getMinutes())}`}function f({featured:n,canEditCover:r,canSchedule:o,scheduleEnabled:i,scheduleAt:c,onFeaturedChange:s,onScheduleChange:u}){const d=(0,t.useRef)(null),[_,f]=(0,t.useState)(!1),[g,h]=(0,t.useState)(""),j=(0,t.useMemo)(()=>b(new Date(Date.now()+3e5)),[]),E="string"==typeof n?.data?.url?n.data.url:"";return(0,e.createElement)("section",{className:"jio-creator__settings","aria-label":(0,a.__)("发布设置","jio")},(0,e.createElement)("h2",{className:"jio-creator__settings-title"},(0,a.__)("发布设置","jio")),r&&(0,e.createElement)("div",{className:"jio-creator__setting-row"},(0,e.createElement)("div",{className:"jio-creator__setting-copy"},(0,e.createElement)("span",{className:"jio-creator__setting-label"},(0,a.__)("添加封面","jio")),(0,e.createElement)("p",{className:"jio-creator__setting-help"},(0,a.__)("用于列表卡片、分享卡片;不设置时自动使用正文首图。","jio"))),(0,e.createElement)("div",{className:"jio-creator__cover-control"},E?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("button",{type:"button",className:"jio-creator__cover-preview",onClick:()=>d.current?.click(),"aria-label":(0,a.__)("更换封面","jio")},(0,e.createElement)("img",{src:E,alt:""})),(0,e.createElement)("button",{type:"button",className:"jio-creator__cover-clear",onClick:()=>s({type:"",data:{}}),"aria-label":(0,a.__)("移除封面","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))):(0,e.createElement)("button",{type:"button",className:"jio-creator__cover-add",onClick:()=>d.current?.click(),disabled:_},(0,e.createElement)("i",{className:"fa fas fa-plus","aria-hidden":"true"}),(0,e.createElement)("span",null,_?(0,a.__)("上传中…","jio"):(0,a.__)("添加封面","jio"))),(0,e.createElement)("input",{ref:d,type:"file",accept:"image/*",className:"jio-creator__cover-input",onChange:()=>{(async()=>{const e=d.current?.files?.[0],t=m.media?.uploadUrl?.image;if(e&&t){h(""),f(!0);try{const n=await l(t,e,p),r=Number(n.attachment_id||n.id||0),o=String(n.url||"");if(!r||!o)throw new Error((0,a.__)("上传后无法读取图片。","jio"));s({type:"image",mediaId:r,data:{id:r,url:o}})}catch(e){h(String(e?.message||(0,a.__)("上传失败","jio")))}finally{f(!1),d.current&&(d.current.value="")}}})()}}))),g&&(0,e.createElement)("p",{className:"jio-creator-error"},g),(0,e.createElement)("div",{className:"jio-creator__setting-row"},(0,e.createElement)("div",{className:"jio-creator__setting-copy"},(0,e.createElement)("span",{className:"jio-creator__setting-label"},(0,a.__)("定时发布","jio")),(0,e.createElement)("p",{className:"jio-creator__setting-help"},o?(0,a.__)("开启后到点自动发布,发布前不会出现在文章列表。","jio"):(0,a.__)("当前账号提交后需要审核,审核通过后才会发布。","jio"))),(0,e.createElement)("label",{className:"jio-creator-toggle"},(0,e.createElement)("input",{type:"checkbox",checked:i,disabled:!o,onChange:e=>u(e.target.checked,c||b(new Date(Date.now()+36e5)))}),(0,e.createElement)("span",{"aria-hidden":"true"}))),o&&i&&(0,e.createElement)("div",{className:"jio-creator__schedule"},(0,e.createElement)("label",null,(0,e.createElement)("span",null,(0,a.__)("发布时间","jio")),(0,e.createElement)("input",{type:"datetime-local",value:c,min:j,onChange:e=>u(!0,e.target.value)})),(0,e.createElement)("p",{className:"jio-creator-muted"},(0,a.sprintf)(/* translators: %s: site timezone */ /* translators: %s: site timezone */
|
||
(0,a.__)("按站点时区(%s)发布,至少需要晚于当前时间 1 分钟。","jio"),String(m.timezone||"UTC")))))}const g={ready:(0,a.__)("尚未保存","jio"),saving:(0,a.__)("保存中…","jio"),saved:(0,a.__)("已保存","jio"),error:(0,a.__)("保存失败","jio"),conflict:(0,a.__)("内容已在别处更新","jio"),submitting:(0,a.__)("提交中…","jio"),submitted:(0,a.__)("已提交","jio")};function h({value:t}){return(0,e.createElement)("span",{className:`jio-creator__save is-${t.state}`,role:"status","aria-live":"polite"},(0,e.createElement)("i",{className:"fa fas fa-circle","aria-hidden":"true"}),(0,e.createElement)("span",null,g[t.state]||g.ready),"saved"===t.state&&t.at?(0,e.createElement)("time",null,t.at):null)}function j(e){const t=(e.downloads||[]).map(e=>{const t="string"==typeof e.assetKey?e.assetKey:"";if(t)return{type:"protected",asset_key:t,label:"string"==typeof e.label?e.label:""};const a="string"==typeof e.url?e.url.trim():"";return a?{type:"direct",url:a,label:"string"==typeof e.label?e.label:"",extract_code:"string"==typeof e.extractCode?e.extractCode:""}:null}).filter(Boolean);return{enabled:!!e.enabled,fields:{pay_type:e.enabled?t.length>0?"download":"reading":"no",pay_modo:"points"===e.modo?"points":"0",price:"points"===e.modo?"0.00":String(e.price||"0.00"),points_price:"points"===e.modo?Math.max(0,Number(e.points)||0):0,vip1_price:"points"===e.modo?"0.00":String(e.vip1Price||"0.00"),vip2_price:"points"===e.modo?"0.00":String(e.vip2Price||"0.00"),pay_limit:Number(e.payLimit)||0,downloads:t}}}const E=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),y=[{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"}];function v(e="generic",t=""){const n=E(""!==t?t:(0,a.__)("在此输入代码","jio"));return`<pre class="enlighter-pre" data-enlighter-language="${E(e)}"><code class="gl" data-enlighter-language="${E(e)}">`+n+"</code></pre><p></p>"}const k=(e,t,a)=>Math.min(a,Math.max(t,Number.isFinite(e)?Math.round(e):t)),N={table:(0,a.__)("插入表格","jio"),math:(0,a.__)("插入公式","jio"),footnote:(0,a.__)("插入注释","jio"),code:(0,a.__)("插入代码块","jio")};function w({kind:n,initialLanguage:r="generic",initialCode:o="",onSubmit:l,onClose:i}){const[c,s]=(0,t.useState)(3),[u,d]=(0,t.useState)(3),[m,p]=(0,t.useState)(!0),[_,b]=(0,t.useState)(!1),[f,g]=(0,t.useState)("a^2 + b^2 = c^2"),[h,j]=(0,t.useState)(!0),[E,v]=(0,t.useState)(""),[w,C]=(0,t.useState)(r),[S,x]=(0,t.useState)(o),M=(0,t.useRef)(null),q=(0,t.useRef)(null),L=(0,t.useRef)(null),$=(0,t.useRef)(null);(0,t.useEffect)(()=>{(q.current||L.current||$.current)?.focus();const e=e=>{"Escape"===e.key&&(e.preventDefault(),i())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[i]);const I=(0,t.useMemo)(()=>"footnote"===n?""!==E.trim():"math"!==n||""!==f.trim(),[n,E,f]);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:i}),(0,e.createElement)("div",{className:"jio-creator-dialog__panel",ref:M},(0,e.createElement)("header",{className:"jio-creator-dialog__head"},(0,e.createElement)("h2",{id:"jio-creator-dialog-title"},N[n]),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__close",onClick:i,"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:q,type:"number",min:1,max:20,value:c,onChange:e=>s(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:u,onChange:e=>d(Number(e.target.value))}))),(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"))),(0,e.createElement)("label",{className:"jio-creator-dialog__check"},(0,e.createElement)("input",{type:"checkbox",checked:_,onChange:e=>b(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:L,rows:3,value:f,onChange:e=>g(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:h,onChange:e=>j(e.target.checked)}),(0,e.createElement)("span",null,(0,a.__)("独占一行显示","jio")))),"code"===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)("select",{value:w,onChange:e=>C(e.target.value)},y.map(t=>(0,e.createElement)("option",{key:t.value,value:t.value},t.label)))),(0,e.createElement)("label",{className:"jio-creator-dialog__field"},(0,e.createElement)("span",null,(0,a.__)("代码(可留空,稍后在正文里填写)","jio")),(0,e.createElement)("textarea",{rows:6,value:S,onChange:e=>x(e.target.value),placeholder:"console.log('hello');"}))),"footnote"===n&&(0,e.createElement)("label",{className:"jio-creator-dialog__field"},(0,e.createElement)("span",null,(0,a.__)("注释内容","jio")),(0,e.createElement)("textarea",{ref:$,rows:4,value:E,onChange:e=>v(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:i},(0,a.__)("取消","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-dialog__primary",onClick:()=>{I&&l("table"!==n?"math"!==n?"code"!==n?{kind:n,note:E.trim()}:{kind:n,language:w,code:S}:{kind:n,formula:f.trim(),display:h}:{kind:n,rows:k(c,1,20),cols:k(u,1,10),header:m,striped:_})},disabled:!I},(0,a.__)("插入","jio")))))}const C=window.jioCreatorStudio||{},S=C.nonce||"",x=`jio-studio-${C.sourceId||0}`,M="jio-creator-content";function q(){const e=C.pay||{},t=C.categories&&C.categories.selected||[],a=C.tags&&C.tags.items||[];return{postId:Number(C.sourceId||0),versionId:Number(C.versionId||0),rev:Number(C.versionRev||0),title:String(C.title||""),content:String(C.content||""),schedule:{enabled:!1,at:""},categories:t.map(Number),tags:a.slice(),custom:C.custom||{},featured:C.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 L(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function $(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 I(){const[n,r]=(0,t.useState)(q),l=(0,t.useRef)(n);l.current=n;const i=(0,t.useRef)(null),c=(0,t.useRef)(null),u=(0,t.useRef)(null),m=(0,t.useRef)(!1),p=(0,t.useRef)(()=>{}),[_,b]=(0,t.useState)(!1),[g,y]=(0,t.useState)({canUndo:!1,canRedo:!1}),[k,N]=(0,t.useState)("p"),[I,R]=(0,t.useState)(()=>({state:C.sourceId||C.versionId||C.content?"saved":"ready",at:""})),[D,P]=(0,t.useState)(!1),[U,z]=(0,t.useState)(null),[F,T]=(0,t.useState)(null),A=(0,t.useRef)(null),[O,B]=(0,t.useState)(null),[K,J]=(0,t.useState)(null),H=(0,t.useRef)(!1),V=(0,t.useRef)(0),X=C.capabilities||{},Q={titleMin:Number(C.limits?.titleMin||1),titleMax:Number(C.limits?.titleMax||30),titlePlaceholder:String(C.limits?.titlePlaceholder||(0,a.__)("请输入标题","jio")),priceMin:Number(C.pay?.priceMin||0),priceMax:Number(C.pay?.priceMax||0),pointsMin:Number(C.pay?.pointsMin||0),pointsMax:Number(C.pay?.pointsMax||0)},Y=!!C.isPublished,W=(0,t.useCallback)(e=>{H.current=!0,V.current+=1;const t={...l.current,...e};l.current=t,r(t)},[]),G=(0,t.useCallback)(e=>{if(e===l.current.content)return;H.current=!0,V.current+=1;const t={...l.current,content:e};l.current=t,r(t)},[]),Z=(0,t.useCallback)(e=>{const t=e?.undoManager;t&&y({canUndo:"function"==typeof t.hasUndo&&t.hasUndo(),canRedo:"function"==typeof t.hasRedo&&t.hasRedo()})},[]),ee=(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";N(["h1","h2","h3","blockquote"].includes(n)?n:"p")},[]),te=(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:j(t.pay),...e}},[]),ae=(0,t.useCallback)(async(e=!1)=>{const t=i.current;t&&!t.removed&&G(t.getContent());const a=l.current;if(!H.current&&(a.postId>0||a.versionId>0))return!0;const n=V.current,c=""!==a.title.trim()||""!==function(e){const t=document.createElement("div");return t.innerHTML=e,(t.textContent||"").replace(/\s+/g,"")}(a.content).trim();if(e&&!c)return!0;R({state:"saving",at:""});try{const t=await o(C.creator.saveUrl,te({autosave:e}),S),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=V.current===n;return H.current=!i,l.current=a,r(a),R({state:i?"saved":"saving",at:i?(new Date).toLocaleTimeString():""}),i}catch(e){return R({state:409===e?.status?"conflict":"error",at:""}),!1}},[te]);p.current=()=>{ae(!1)};const ne=(0,t.useCallback)(async e=>{if(await ae(!1)){R({state:"submitting",at:""});try{let t="";const n=window.JioCaptcha;if(C.captcha?.enabled&&n&&"function"==typeof n.run){const e=await n.run("front_submit");if(null===e)return R({state:"ready",at:""}),void B({tone:"error",text:(0,a.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const r=await o(C.creator.submitUrl,te({post_id:l.current.postId,version_id:l.current.versionId,rev:l.current.rev,publish_now:e,captcha_proof:t}),S);H.current=!1,R({state:"submitted",at:""}),B({tone:"ok",text:String(r.message||(0,a.__)("已提交","jio"))}),P(!1);const i=r.url||r.goto||C.urls?.center;i&&window.setTimeout(()=>{window.location.href=i},900)}catch(e){R({state:"error",at:""}),B({tone:"error",text:String(e?.message||(0,a.__)("提交失败","jio"))})}}else B({tone:"error",text:(0,a.__)("内容保存失败,请重试后再提交","jio")})},[te,ae]),re=(0,t.useCallback)(async()=>{if(await ae(!1))try{const e=await o(C.creator.previewUrl,{post_id:l.current.postId,version_id:l.current.versionId},S);e.url&&window.open(String(e.url),"_blank","noopener")}catch(e){B({tone:"error",text:String(e?.message||(0,a.__)("预览失败","jio"))})}},[ae]),{markLocalSaved:oe,clear:le}=function({key:e,snapshot:a,onFound:n}){const r=(0,t.useRef)(a);r.current=a;const o=(0,t.useRef)(!1);return(0,t.useEffect)(()=>{if(!o.current){o.current=!0;try{const t=window.localStorage.getItem(e);if(!t)return;const r=JSON.parse(t),o="string"==typeof r.at?Date.parse(r.at):NaN;if(!Number.isFinite(o)||Date.now()-o>6048e5)return void window.localStorage.removeItem(e);"string"==typeof r.content&&r.content!==a.content&&n(String(r.at))}catch(t){window.localStorage.removeItem(e)}}},[e,n,a.content]),{markLocalSaved:(0,t.useCallback)(()=>{try{window.localStorage.setItem(e,JSON.stringify(r.current))}catch(e){}},[e]),clear:(0,t.useCallback)(()=>{try{window.localStorage.removeItem(e)}catch(e){}},[e])}}({key:x,snapshot:{title:n.title,content:n.content,at:(new Date).toISOString()},onFound:e=>J({savedAt:e})}),ie=function({enabled:e,onSave:a,onLocal:n,remoteDelay:r=4e3,localDelay:o=1500}){const l=(0,t.useRef)(null),i=(0,t.useRef)(null),c=(0,t.useRef)(!1),s=(0,t.useRef)(a),u=(0,t.useRef)(n);s.current=a,u.current=n;const d=(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)(()=>{d(),u.current(),e&&(i.current=window.setTimeout(()=>u.current(),o),l.current=window.setTimeout(()=>{m()},r))},[d,e,m,o,r]);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),d()}},[d,e,m]),(0,t.useMemo)(()=>({schedule:p,flush:m,cancel:d}),[d,m,p])}({enabled:!!X.isLoggedIn,onSave:async()=>{const e=await ae(!0);return e&&le(),e},onLocal:oe}).schedule;(0,t.useEffect)(()=>{H.current&&ie()},[n,ie]),(0,t.useEffect)(()=>{const e=e=>{H.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(),ae(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ae]),(0,t.useEffect)(()=>{const e=window.wp?.editor;if(!e||"function"!=typeof e.initialize)return void B({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:C.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::before {\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\tcontent: attr(data-enlighter-language);\n\tfont-size: 12px;\n\tline-height: 1.5;\n\tpointer-events: none;\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 { font-family: "Cambria Math", "Latin Modern Math", "Times New Roman", serif; }\n.jio-math--block { display: block; margin: 12px 0; text-align: center; }\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-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:650,placeholder:String(C.limits?.contentPlaceholder||""),setup:e=>{i.current=e,e.on("init",()=>{m.current=!0,b(!0),null!==u.current&&(e.setContent(u.current),u.current=null),Z(e),ee(e)}),e.on("NodeChange",()=>ee(e)),e.on("click",t=>{const a=e.dom.getParent(t.target,"pre.enlighter-pre");if(!a)return;const n=a.getBoundingClientRect(),r=Number(t.clientY)-n.top,o=Number(t.clientX)-n.left;if(r>40||o<n.width-120)return;t.preventDefault();const l=String(a.getAttribute("data-enlighter-language")||"generic");A.current=a,T({language:l,code:String((a.textContent||"").trim())})}),e.on("input change Undo Redo AddUndo",()=>{G(e.getContent()),Z(e)}),e.on("keydown",e=>{(e.metaKey||e.ctrlKey)&&83===e.keyCode&&(e.preventDefault(),p.current())})}}};return e.initialize(M,t),()=>{e.remove?.(M),m.current=!1,i.current=null}},[G]);const ce=(0,t.useCallback)(()=>{try{const e=window.localStorage.getItem(x);if(e){const t=JSON.parse(e),a={};"string"==typeof t.title&&(a.title=t.title),"string"==typeof t.content&&(a.content=t.content),W(a),"string"==typeof t.content&&(m.current?i.current?.setContent(t.content):u.current=t.content)}}catch(e){}J(null)},[W]),se=(0,t.useCallback)(()=>{const e=i.current;e&&!e.removed&&(c.current=e.selection.getBookmark(2,!0))},[]),ue=(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},[]),de=(0,t.useCallback)((e,t)=>{const a=ue();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"),ee(a)):a.execCommand(e),a.nodeChanged())},[ue]),me=(0,t.useCallback)(()=>{const e=ue();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://"),r=n?$(n):"";r&&e.execCommand("mceInsertLink",!1,{href:r})},[ue]),pe=(0,t.useCallback)(e=>{const t=ue();t&&e&&(t.insertContent(e),t.nodeChanged(),G(t.getContent()),Z(t))},[ue]),_e=(0,t.useCallback)(e=>{se(),"table"!==e&&"math"!==e&&"footnote"!==e?"code"!==e?"list"!==e?"toc"!==e?"divider"===e&&pe("<hr><p></p>"):pe('<div class="jio-toc-placeholder"></div><p></p>'):pe("<ul><li></li></ul><p></p>"):T({language:"generic",code:""}):z(e)},[pe,se]),be=(0,t.useCallback)(e=>{const t=ue();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();pe(function(e,t){const a=["quote_q","quote-mce"];t&&a.push(t);const n=""!==e.trim()?`<p>${e}</p>`:"<p></p>";return`<div class="${a.join(" ")}"><div>${n}</div></div><p></p>`}(a,e))},[ue,pe]),fe=(0,t.useCallback)(e=>{z(null),"table"===e.kind?pe(function({rows:e,cols:t,header:n,striped:r}){const o=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?E(`${(0,a.__)("列","jio")} ${n+1}`):""}</${e}>`).join("");let c="";n&&(c+=`<thead><tr>${i("th")}</tr></thead>`);const s=Math.max(1,n?o-1:o);c+=`<tbody>${Array.from({length:s},()=>`<tr>${i("td")}</tr>`).join("")}</tbody>`;const u=["jio-content-table"];return r&&u.push("is-striped"),`<table class="${u.join(" ")}">${c}</table><p></p>`}(e)):"math"===e.kind?pe(function({formula:e,display:t}){const a=`<span class="${t?"jio-math jio-math--block":"jio-math"}">${E(e.trim())}</span>`;return t?`<p>${a}</p>`:a}(e)):"footnote"===e.kind?pe(function(e){const t=e.trim()||(0,a.__)("注释内容","jio");return`<p>[^1]<br>[^1]: ${E(t)}</p>`}(e.note)):pe(v(e.language,e.code))},[pe]),ge=(0,t.useCallback)(e=>{const t=i.current,n=window.JioSubmitMedia;t&&n&&"function"==typeof n.open?(se(),n.open({type:e,multiple:"image"===e&&void 0,onSelect:t=>{const a=Array.isArray(t)?t:[t],n=ue();if(!n)return;const r=a.map(t=>{const a=$(t?.large_url||t?.url);if(!a)return"";const n=Number(t.attachment_id||t.id||0),r=n>0?` data-edit-file-id="${n}"`:"";if("image"===e){const e=$(t?.url||a),n=e?` data-full-url="${L(e)}"`:"";return`<p><img src="${L(a)}"${r} alt="${L(String(t.name||t.title||""))}"${n}></p>`}if("file"===e){const e=String(t.filename||t.name||a.split("/").pop()||"");return`<p><a class="jio-file-link" href="${L(a)}"${r}><i class="fa fas fa-paperclip" aria-hidden="true"></i> ${L(e)}</a></p>`}return`<div contenteditable="false" data-video-url="${L(a)}" data-video-name="${L(String(t.filename||t.name||a))}"${r} class="new-dplayer post-dplayer dplayer"></div><p></p>`}).join("");r&&(n.insertContent(r),n.nodeChanged(),G(n.getContent()),Z(n))},onEmbed:e=>{const t=ue();t&&(t.insertContent(`${e}<p></p>`),t.nodeChanged(),G(t.getContent()),Z(t))}})):B({tone:"error",text:(0,a.__)("媒体工具尚未加载,请刷新页面后重试。","jio")})},[ue,se]);return(0,e.createElement)("div",{className:"jio-creator","data-status":C.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:C.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"},Y?(0,a.__)("修改文章","jio"):(0,a.__)("写文章","jio"))),(0,e.createElement)(d,{ready:_,formatValue:k,onFormatChange:N,canUndo:g.canUndo,canRedo:g.canRedo,capabilities:X,onCommand:de,onRememberSelection:se,onOpenLink:me,onOpenMedia:ge,onInsertBlock:_e,onInsertQuote:be}),(0,e.createElement)("div",{className:"jio-creator__bar-actions jio-creator__toolbar-extension","data-toolbar-extension":!0,"aria-label":(0,a.__)("工具扩展区","jio")},(0,e.createElement)(h,{value:I}),(0,e.createElement)("button",{type:"button",className:"jio-creator__save-draft",onClick:()=>{ae(!1)},disabled:!_},(0,e.createElement)("i",{className:"fa fas fa-save","aria-hidden":"true"}),(0,e.createElement)("span",null,(0,a.__)("保存草稿","jio"))),(0,e.createElement)("button",{type:"button",className:"jio-creator__ghost jio-creator__preview",onClick:()=>{re()}},(0,a.__)("预览","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator__primary",onClick:()=>P(!0)},Y?(0,a.__)("提交改稿","jio"):(0,a.__)("发布","jio")))),K&&(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:ce},(0,a.__)("恢复","jio")),(0,e.createElement)("button",{type:"button",onClick:()=>J(null)},(0,a.__)("忽略","jio"))),O&&(0,e.createElement)("div",{className:`jio-creator__notice is-${O.tone}`,role:"status"},(0,e.createElement)("span",null,O.text),(0,e.createElement)("button",{type:"button",onClick:()=>B(null),"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),Y&&(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=>W({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(Q.titleMax)||100),spellCheck:!1,maxLength:Number(Q.titleMax)||100})),(0,e.createElement)("div",{className:"jio-creator__editor","data-editor-ready":_?"true":"false"},(0,e.createElement)("textarea",{id:M,defaultValue:n.content,onChange:e=>G(e.target.value),"aria-label":(0,a.__)("文章正文","jio")}))),(0,e.createElement)(f,{featured:n.featured,canEditCover:!!X.canUploadImage,canSchedule:!!X.canSchedule,scheduleEnabled:!!n.schedule.enabled,scheduleAt:n.schedule.at,onFeaturedChange:e=>W({featured:e}),onScheduleChange:(e,t)=>W({schedule:{enabled:e,at:t}})}),U&&(0,e.createElement)(w,{kind:U,onSubmit:fe,onClose:()=>z(null)}),F&&(0,e.createElement)(w,{kind:"code",initialLanguage:F.language,initialCode:F.code,onSubmit:e=>{if(T(null),"code"!==e.kind)return;const t=A.current;if(A.current=null,pe(v(e.language,e.code)),t){const e=i.current;e&&!e.removed&&(e.dom.remove(t),G(e.getContent()))}},onClose:()=>{T(null),A.current=null}}),D&&(0,e.createElement)(s,{draft:n,setDraft:W,capabilities:X,limits:Q,taxonomy:{categories:C.categories&&C.categories.items||[],tags:!!C.tags?.enabled,customDefs:C.customDefs||[]},isPublishedEdit:Y,onClose:()=>P(!1),onSaveDraft:()=>{ae(!1)},onSubmit:e=>{ne(e)},privateStorage:!!C.privateStorage,privateUploads:C.privateUploads||[],captcha:!!C.captcha?.enabled,saving:"saving"===I.state||"submitting"===I.state}))}function R(){const a=document.getElementById("jio-creator-studio");a&&(a.classList.add("is-ready"),(0,t.createRoot)(a).render((0,e.createElement)(I,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",R):R()})(); |