Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
3 lines
35 KiB
JavaScript
3 lines
35 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)}),i=await r(o);if(!o.ok)throw n(i,o.status);return i}async function i(e,t,a,o={}){const i=new FormData;i.append("file",t),Object.entries(o).forEach(([e,t])=>i.append(e,t));const l=await fetch(e,{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":a},body:i}),c=await r(l);if(!l.ok)throw n(c,l.status);return c}const l=window.jioCreatorStudio||{},c=l.nonce||"";function s(n){const{draft:r,setDraft:o,capabilities:s,limits:u,taxonomy:d,isPublishedEdit:m,onClose:p,onSaveDraft:_,onSubmit:f,privateStorage:b,privateUploads:g,saving:y,captcha:j}=n,[E,h]=(0,t.useState)(""),[v,N]=(0,t.useState)(""),[w,k]=(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 I=(0,t.useMemo)(()=>(r.title||"").trim().length,[r.title])>=Number(u.titleMin||1),x=()=>{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]))}),h("")};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=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),x())}}),(0,e.createElement)("button",{type:"button",onClick:x},(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]||[],i=n.includes(a.key);return(0,e.createElement)("label",{key:a.key,className:"jio-creator-chip"+(i?" is-active":"")},(0,e.createElement)("input",{type:"checkbox",checked:i,onChange:()=>o({custom:{...r.custom,[t.key]:i?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")),b?(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){N(""),k(!0);try{const t=await i(l.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){N(String(e?.message||(0,a.__)("资料上传失败","jio")))}finally{k(!1)}}})()},disabled:w}),(0,e.createElement)("span",null,w?(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:y},(0,a.__)("保存草稿","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-primary",onClick:()=>f(!1),disabled:y||!I},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:()=>f(!0),disabled:y||!I},(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:t,canUndo:n,canRedo:r,formatValue:o,onFormatChange:i,capabilities:l,onCommand:c,onRememberSelection:s,onOpenLink:d,onOpenMedia:m,onInsertBlock:p}){return(0,e.createElement)("div",{className:"jio-creator__toolbar-tools",role:"toolbar","aria-label":(0,a.__)("正文编辑工具","jio"),onMouseDown:e=>{s(),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:n,onClick:()=>c("undo")}),(0,e.createElement)(u,{label:(0,a.__)("重做","jio"),icon:"fa fas fa-redo",ready:r,onClick:()=>c("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"===o?"p":o,disabled:!t,onFocus:s,onChange:e=>{i(e.target.value),c("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:t,onClick:()=>c("Bold")}),(0,e.createElement)(u,{label:(0,a.__)("斜体","jio"),icon:"fa fas fa-italic",ready:t,onClick:()=>c("Italic")}),(0,e.createElement)(u,{label:(0,a.__)("下划线","jio"),icon:"fa fas fa-underline",ready:t,onClick:()=>c("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:t,onClick:()=>p("list")}),(0,e.createElement)(u,{label:(0,a.__)("目录","jio"),icon:"fa fas fa-list-ol",ready:t,onClick:()=>p("toc")}),(0,e.createElement)(u,{label:(0,a.__)("引用","jio"),icon:"fa fas fa-quote-left",ready:t,onClick:()=>c("format","blockquote")}),(0,e.createElement)(u,{label:(0,a.__)("分割线","jio"),icon:"fa fas fa-minus",ready:t,onClick:()=>p("divider")}),(0,e.createElement)(u,{label:(0,a.__)("代码块","jio"),icon:"fa fas fa-code",ready:t,onClick:()=>p("code")}),(0,e.createElement)(u,{label:(0,a.__)("注释","jio"),icon:"fa fas fa-comment-dots",ready:t,onClick:()=>p("footnote")}),(0,e.createElement)(u,{label:(0,a.__)("公式","jio"),icon:"fa fas fa-square-root-alt",ready:t,onClick:()=>p("math")}),(0,e.createElement)(u,{label:(0,a.__)("表格","jio"),icon:"fa fas fa-table",ready:t,onClick:()=>p("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")},l.canUploadImage&&(0,e.createElement)(u,{label:(0,a.__)("图片","jio"),icon:"fa far fa-image",ready:t,onClick:()=>m("image")}),(l.canUploadVideo||l.canEmbed)&&(0,e.createElement)(u,{label:(0,a.__)("视频","jio"),icon:"fa fas fa-video",ready:t,onClick:()=>m("video")}),(0,e.createElement)(u,{label:(0,a.__)("链接","jio"),icon:"fa fas fa-link",ready:t,onClick:d}),l.canUploadFile&&(0,e.createElement)(u,{label:(0,a.__)("附件","jio"),icon:"fa fas fa-paperclip",ready:t,onClick:()=>m("file")})))}const m=window.jioCreatorStudio||{},p=m.nonce||"",_=e=>String(e).padStart(2,"0");function f(e){return`${e.getFullYear()}-${_(e.getMonth()+1)}-${_(e.getDate())}T${_(e.getHours())}:${_(e.getMinutes())}`}function b({featured:n,canEditCover:r,canSchedule:o,scheduleEnabled:l,scheduleAt:c,onFeaturedChange:s,onScheduleChange:u}){const d=(0,t.useRef)(null),[_,b]=(0,t.useState)(!1),[g,y]=(0,t.useState)(""),j=(0,t.useMemo)(()=>f(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){y(""),b(!0);try{const n=await i(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){y(String(e?.message||(0,a.__)("上传失败","jio")))}finally{b(!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:l,disabled:!o,onChange:e=>u(e.target.checked,c||f(new Date(Date.now()+36e5)))}),(0,e.createElement)("span",{"aria-hidden":"true"}))),o&&l&&(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 y({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,""");function h(e){const t=e?"ol":"ul";return`<${t}><li></li></${t}><p></p>`}function v(){const e=(e,t)=>`<${e}>${E(t)}</${e}>`;return`<table class="jio-content-table"><thead><tr>${[1,2,3].map(t=>e("th",`${(0,a.__)("列","jio")} ${t}`)).join("")}</tr></thead><tbody>${[1,2].map(()=>`<tr>${[1,2,3].map(()=>e("td","")).join("")}</tr>`).join("")}</tbody></table><p></p>`}const N=window.jioCreatorStudio||{},w=N.nonce||"",k=`jio-studio-${N.sourceId||0}`,C="jio-creator-content";function S(){const e=N.pay||{},t=N.categories&&N.categories.selected||[],a=N.tags&&N.tags.items||[];return{postId:Number(N.sourceId||0),versionId:Number(N.versionId||0),rev:Number(N.versionRev||0),title:String(N.title||""),content:String(N.content||""),schedule:{enabled:!1,at:""},categories:t.map(Number),tags:a.slice(),custom:N.custom||{},featured:N.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 I(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function x(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 M(){const[n,r]=(0,t.useState)(S),i=(0,t.useRef)(n);i.current=n;const l=(0,t.useRef)(null),c=(0,t.useRef)(null),u=(0,t.useRef)(null),m=(0,t.useRef)(!1),p=(0,t.useRef)(()=>{}),[_,f]=(0,t.useState)(!1),[g,M]=(0,t.useState)({canUndo:!1,canRedo:!1}),[L,R]=(0,t.useState)("p"),[$,D]=(0,t.useState)(()=>({state:N.sourceId||N.versionId||N.content?"saved":"ready",at:""})),[P,U]=(0,t.useState)(!1),[F,T]=(0,t.useState)(null),[z,K]=(0,t.useState)(null),O=(0,t.useRef)(!1),B=(0,t.useRef)(0),A=N.capabilities||{},q={titleMin:Number(N.limits?.titleMin||1),titleMax:Number(N.limits?.titleMax||30),titlePlaceholder:String(N.limits?.titlePlaceholder||(0,a.__)("请输入标题","jio")),priceMin:Number(N.pay?.priceMin||0),priceMax:Number(N.pay?.priceMax||0),pointsMin:Number(N.pay?.pointsMin||0),pointsMax:Number(N.pay?.pointsMax||0)},J=!!N.isPublished,V=(0,t.useCallback)(e=>{O.current=!0,B.current+=1;const t={...i.current,...e};i.current=t,r(t)},[]),H=(0,t.useCallback)(e=>{if(e===i.current.content)return;O.current=!0,B.current+=1;const t={...i.current,content:e};i.current=t,r(t)},[]),W=(0,t.useCallback)(e=>{const t=e?.undoManager;t&&M({canUndo:"function"==typeof t.hasUndo&&t.hasUndo(),canRedo:"function"==typeof t.hasRedo&&t.hasRedo()})},[]),X=(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";R(["h1","h2","h3","blockquote"].includes(n)?n:"p")},[]),Y=(0,t.useCallback)((e={})=>{const t=i.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}},[]),Z=(0,t.useCallback)(async(e=!1)=>{const t=l.current;t&&!t.removed&&H(t.getContent());const a=i.current;if(!O.current&&(a.postId>0||a.versionId>0))return!0;const n=B.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;D({state:"saving",at:""});try{const t=await o(N.creator.saveUrl,Y({autosave:e}),w),a={...i.current,postId:Number(t.post_id||i.current.postId||0),versionId:Number(t.version_id||i.current.versionId||0),rev:Number(t.rev||t.versionRev||i.current.rev||0)};window.jioSubmitData&&(window.jioSubmitData.postId=a.postId);const l=B.current===n;return O.current=!l,i.current=a,r(a),D({state:l?"saved":"saving",at:l?(new Date).toLocaleTimeString():""}),l}catch(e){return D({state:409===e?.status?"conflict":"error",at:""}),!1}},[Y]);p.current=()=>{Z(!1)};const G=(0,t.useCallback)(async e=>{if(await Z(!1)){D({state:"submitting",at:""});try{let t="";const n=window.JioCaptcha;if(N.captcha?.enabled&&n&&"function"==typeof n.run){const e=await n.run("front_submit");if(null===e)return D({state:"ready",at:""}),void T({tone:"error",text:(0,a.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const r=await o(N.creator.submitUrl,Y({post_id:i.current.postId,version_id:i.current.versionId,rev:i.current.rev,publish_now:e,captcha_proof:t}),w);O.current=!1,D({state:"submitted",at:""}),T({tone:"ok",text:String(r.message||(0,a.__)("已提交","jio"))}),U(!1);const l=r.url||r.goto||N.urls?.center;l&&window.setTimeout(()=>{window.location.href=l},900)}catch(e){D({state:"error",at:""}),T({tone:"error",text:String(e?.message||(0,a.__)("提交失败","jio"))})}}else T({tone:"error",text:(0,a.__)("内容保存失败,请重试后再提交","jio")})},[Y,Z]),Q=(0,t.useCallback)(async()=>{if(await Z(!1))try{const e=await o(N.creator.previewUrl,{post_id:i.current.postId,version_id:i.current.versionId},w);e.url&&window.open(String(e.url),"_blank","noopener")}catch(e){T({tone:"error",text:String(e?.message||(0,a.__)("预览失败","jio"))})}},[Z]),{markLocalSaved:ee,clear:te}=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:k,snapshot:{title:n.title,content:n.content,at:(new Date).toISOString()},onFound:e=>K({savedAt:e})}),ae=function({enabled:e,onSave:a,onLocal:n,remoteDelay:r=4e3,localDelay:o=1500}){const i=(0,t.useRef)(null),l=(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)(()=>{i.current&&(window.clearTimeout(i.current),i.current=null),l.current&&(window.clearTimeout(l.current),l.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&&(l.current=window.setTimeout(()=>u.current(),o),i.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:!!A.isLoggedIn,onSave:async()=>{const e=await Z(!0);return e&&te(),e},onLocal:ee}).schedule;(0,t.useEffect)(()=>{O.current&&ae()},[n,ae]),(0,t.useEffect)(()=>{const e=e=>{O.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(),Z(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Z]),(0,t.useEffect)(()=>{const e=window.wp?.editor;if(!e||"function"!=typeof e.initialize)return void T({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:N.creator?.contentCss||"",content_style:'body{margin:0;color:#243330;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans SC","PingFang SC","Microsoft YaHei",sans-serif;font-size:16px;line-height:1.85;letter-spacing:.01em}p{margin:0 0 1.1em}h1,h2,h3,h4,h5,h6{margin:1.5em 0 .65em;line-height:1.4}img,iframe{max-width:100%}img{height:auto}',height:650,placeholder:String(N.limits?.contentPlaceholder||""),setup:e=>{l.current=e,e.on("init",()=>{m.current=!0,f(!0),null!==u.current&&(e.setContent(u.current),u.current=null),W(e),X(e)}),e.on("NodeChange",()=>X(e)),e.on("input change Undo Redo AddUndo",()=>{H(e.getContent()),W(e)}),e.on("keydown",e=>{(e.metaKey||e.ctrlKey)&&83===e.keyCode&&(e.preventDefault(),p.current())})}}};return e.initialize(C,t),()=>{e.remove?.(C),m.current=!1,l.current=null}},[H]);const ne=(0,t.useCallback)(()=>{try{const e=window.localStorage.getItem(k);if(e){const t=JSON.parse(e),a={};"string"==typeof t.title&&(a.title=t.title),"string"==typeof t.content&&(a.content=t.content),V(a),"string"==typeof t.content&&(m.current?l.current?.setContent(t.content):u.current=t.content)}}catch(e){}K(null)},[V]),re=(0,t.useCallback)(()=>{const e=l.current;e&&!e.removed&&(c.current=e.selection.getBookmark(2,!0))},[]),oe=(0,t.useCallback)(()=>{const e=l.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},[]),ie=(0,t.useCallback)((e,t)=>{const a=oe();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"),X(a)):a.execCommand(e),a.nodeChanged())},[oe]),le=(0,t.useCallback)(()=>{const e=oe();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?x(n):"";r&&e.execCommand("mceInsertLink",!1,{href:r})},[oe]),ce=(0,t.useCallback)(e=>{const t=oe();if(!t)return;const n={list:h(!1),toc:'<div class="jio-toc-placeholder"></div><p></p>',divider:"<hr><p></p>",code:'<pre class="enlighter-pre"><code class="gl" data-enlighter-language="generic">'+E((0,a.__)("在此输入代码","jio"))+"</code></pre><p></p>",footnote:"<p>[^1]<br>[^1]: "+E((0,a.__)("注释内容","jio"))+"</p>",math:'<span class="jio-math">E = mc^2</span>',table:v()}[e];n&&(t.insertContent(n),t.nodeChanged(),H(t.getContent()),W(t))},[oe]),se=(0,t.useCallback)(e=>{const t=l.current,n=window.JioSubmitMedia;t&&n&&"function"==typeof n.open?(re(),n.open({type:e,multiple:"image"===e&&void 0,onSelect:t=>{const a=Array.isArray(t)?t:[t],n=oe();if(!n)return;const r=a.map(t=>{const a=x(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=x(t?.url||a),n=e?` data-full-url="${I(e)}"`:"";return`<p><img src="${I(a)}"${r} alt="${I(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="${I(a)}"${r}><i class="fa fas fa-paperclip" aria-hidden="true"></i> ${I(e)}</a></p>`}return`<div contenteditable="false" data-video-url="${I(a)}" data-video-name="${I(String(t.filename||t.name||a))}"${r} class="new-dplayer post-dplayer dplayer"></div><p></p>`}).join("");r&&(n.insertContent(r),n.nodeChanged(),H(n.getContent()),W(n))},onEmbed:e=>{const t=oe();t&&(t.insertContent(`${e}<p></p>`),t.nodeChanged(),H(t.getContent()),W(t))}})):T({tone:"error",text:(0,a.__)("媒体工具尚未加载,请刷新页面后重试。","jio")})},[oe,re]);return(0,e.createElement)("div",{className:"jio-creator","data-status":N.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:N.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"},J?(0,a.__)("修改文章","jio"):(0,a.__)("写文章","jio"))),(0,e.createElement)(d,{ready:_,formatValue:L,onFormatChange:R,canUndo:g.canUndo,canRedo:g.canRedo,capabilities:A,onCommand:ie,onRememberSelection:re,onOpenLink:le,onOpenMedia:se,onInsertBlock:ce}),(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)(y,{value:$}),(0,e.createElement)("button",{type:"button",className:"jio-creator__save-draft",onClick:()=>{Z(!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:()=>{Q()}},(0,a.__)("预览","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator__primary",onClick:()=>U(!0)},J?(0,a.__)("提交改稿","jio"):(0,a.__)("发布","jio")))),z&&(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:ne},(0,a.__)("恢复","jio")),(0,e.createElement)("button",{type:"button",onClick:()=>K(null)},(0,a.__)("忽略","jio"))),F&&(0,e.createElement)("div",{className:`jio-creator__notice is-${F.tone}`,role:"status"},(0,e.createElement)("span",null,F.text),(0,e.createElement)("button",{type:"button",onClick:()=>T(null),"aria-label":(0,a.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),J&&(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=>V({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:C,defaultValue:n.content,onChange:e=>H(e.target.value),"aria-label":(0,a.__)("文章正文","jio")}))),(0,e.createElement)(b,{featured:n.featured,canEditCover:!!A.canUploadImage,canSchedule:!!A.canSchedule,scheduleEnabled:!!n.schedule.enabled,scheduleAt:n.schedule.at,onFeaturedChange:e=>V({featured:e}),onScheduleChange:(e,t)=>V({schedule:{enabled:e,at:t}})}),P&&(0,e.createElement)(s,{draft:n,setDraft:V,capabilities:A,limits:q,taxonomy:{categories:N.categories&&N.categories.items||[],tags:!!N.tags?.enabled,customDefs:N.customDefs||[]},isPublishedEdit:J,onClose:()=>U(!1),onSaveDraft:()=>{Z(!1)},onSubmit:e=>{G(e)},privateStorage:!!N.privateStorage,privateUploads:N.privateUploads||[],captcha:!!N.captcha?.enabled,saving:"saving"===$.state||"submitting"===$.state}))}function L(){const a=document.getElementById("jio-creator-studio");a&&(a.classList.add("is-ready"),(0,t.createRoot)(a).render((0,e.createElement)(M,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",L):L()})(); |