Files
wordpress-theme-aksrt/assets/creator-studio/build/index.js
T
kate522andClaude Opus 5 fac4a714e0 feat(creator-studio): 前台 Gutenberg 创作工作台与受保护付费附件
前台投稿页改为沉浸式创作工作台:Gutenberg 负责区块解析与序列化,
React + TypeScript 负责工作台外壳与发布抽屉,Jio 服务端继续作为权限、
审核与付费的唯一权威。

- 新增 assets/creator-studio 独立构建(wp-scripts,锁定 WP 6.4 时代包),
  仅在投稿模板加载,构建缺失或游客访问时回退原有 TinyMCE 表单
- 自动保存(4s 防抖 + rev 冲突 409)、本地快照恢复、发布配置抽屉、
  移动端全屏单列与安全区适配
- 图片插入走现有 front-submit 上传管线,保留能力校验与待认领生命周期
- 已发布文章的改稿写入私有版本,审核通过前线上内容/链接/付费条款不变;
  原生后台「改稿审核」一次性应用或退回,并校验源文章并发指纹
- 私有附件新表 jio_private_asset + jio_dl_token.asset_id,schema 升到 3.4.0;
  文件存放 ABSPATH 之外,未配置私有存储时 fail closed
- 下载令牌绑定文章/附件/用户/IP/UA/次数,每次交付复核 Visibility 的
  订单、VIP 与配额判定;中断传输归还次数
- 付费字段改为写入前校验,非法价格不再留下半保存文章
- 新增 creator-studio 契约测试;更新受影响的 schema/下载/投稿契约

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-06 14:53:23 +08:00

1 line
23 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(()=>{"use strict";const e=window.React,t=window.wp.element,a=window.wp.blocks,r=window.wp.blockLibrary,n=window.wp.data,o=window.wp.blockEditor,i=window.wp.wordcount,l=window.wp.i18n;function c(e,t){const a=e&&(e.message||e.error)||(401===t?"登录状态已失效,请刷新页面重新登录。":"请求失败,请稍后重试。"),r=new Error(String(a));return r.status=t,r.code=e&&e.code?String(e.code):"",r.data=e,r}async function s(e){try{return await e.json()}catch(e){return null}}async function m(e,t,a){const r=await fetch(e,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-WP-Nonce":a},body:JSON.stringify(t)}),n=await s(r);if(!r.ok)throw c(n,r.status);return n}async function u(e,t,a,r={}){const n=new FormData;n.append("file",t),Object.entries(r).forEach(([e,t])=>n.append(e,t));const o=await fetch(e,{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":a},body:n}),i=await s(o);if(!o.ok)throw c(i,o.status);return i}const d=window.jioCreatorStudio||{},p=d.nonce||"";function _(a){const{draft:r,setDraft:n,capabilities:o,limits:i,taxonomy:c,isPublishedEdit:s,onClose:m,onSaveDraft:_,onSubmit:y,privateStorage:f,privateUploads:b,saving:E,captcha:g}=a,[j,h]=(0,t.useState)(""),[w,v]=(0,t.useState)(""),[N,k]=(0,t.useState)(!1),S=(0,t.useRef)(null),C=(0,t.useRef)(null),x=(0,t.useRef)(null);(0,t.useEffect)(()=>{const e=x.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(i.titleMin||1),L=()=>{const e=j.trim();if(!e)return;const t=e.split(/[,,\n]+/u).map(e=>e.trim()).filter(Boolean);n({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,l.__)("关闭","jio"),onClick:m}),(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"},s?(0,l.__)("提交改稿","jio"):(0,l.__)("发布文章","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-drawer__close",onClick:m,"aria-label":(0,l.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,e.createElement)("div",{className:"jio-creator-drawer__body"},s&&(0,e.createElement)("p",{className:"jio-creator-drawer__note"},(0,l.__)("审核通过前,读者看到的仍然是当前线上版本。","jio")),(0,e.createElement)("section",{className:"jio-creator-field"},(0,e.createElement)("h3",null,(0,l.__)("封面","jio")),r.featured?.data?.url?(0,e.createElement)("div",{className:"jio-creator-cover"},(0,e.createElement)("img",{src:String(r.featured.data.url),alt:""}),(0,e.createElement)("button",{type:"button",onClick:()=>n({featured:{type:"",data:{}}}),"aria-label":(0,l.__)("移除封面","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))):o.canUploadImage?(0,e.createElement)("label",{className:"jio-creator-cover-empty"},(0,e.createElement)("input",{ref:S,type:"file",accept:"image/*",onChange:()=>{(async()=>{const e=S.current?.files?.[0];if(e&&d.media?.uploadUrl?.image){v(""),k(!0);try{const t=await u(d.media.uploadUrl.image,e,p),a=Number(t.attachment_id||t.id||0),r=String(t.url||"");if(!a||!r)throw new Error((0,l.__)("上传后无法读取图片。","jio"));n({featured:{type:"image",mediaId:a,data:{id:a,url:r}}})}catch(e){v(String(e?.message||(0,l.__)("上传失败","jio")))}finally{k(!1)}}})()},disabled:N}),(0,e.createElement)("i",{className:"fa fas fa-plus","aria-hidden":"true"}),(0,e.createElement)("span",null,N?(0,l.__)("上传中…","jio"):(0,l.__)("上传封面","jio"))):(0,e.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("当前账号不能设置封面。","jio"))),(0,e.createElement)("section",{className:"jio-creator-field"},(0,e.createElement)("h3",null,(0,l.__)("分类","jio")),(0,e.createElement)("div",{className:"jio-creator-chips"},0===c.categories.length&&(0,e.createElement)("span",{className:"jio-creator-muted"},(0,l.__)("暂无可选分类","jio")),c.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);n({categories:t?r.categories.filter(t=>t!==e):[...r.categories,e]})})(t.id)}),(0,e.createElement)("span",null,t.name))))),c.tags&&(0,e.createElement)("section",{className:"jio-creator-field"},(0,e.createElement)("h3",null,(0,l.__)("标签","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:()=>n({tags:r.tags.filter(e=>e!==t)}),"aria-label":(0,l.sprintf)((0,l.__)("移除标签 %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:j,placeholder:(0,l.__)("输入标签,逗号分隔","jio"),onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),L())}}),(0,e.createElement)("button",{type:"button",onClick:L},(0,l.__)("添加","jio")))),c.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 o=r.custom[t.key]||[],i=o.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:()=>n({custom:{...r.custom,[t.key]:i?o.filter(e=>e!==a.key):[...o,a.key]}})}),(0,e.createElement)("span",null,a.name))})))),o.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,l.__)("付费内容","jio")),(0,e.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("开启后,未购买读者只能看到免费部分。","jio"))),(0,e.createElement)("label",{className:"jio-creator-toggle"},(0,e.createElement)("input",{type:"checkbox",checked:r.pay.enabled,onChange:e=>n({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:()=>n({pay:{...r.pay,modo:"cash"}})}),(0,e.createElement)("span",null,(0,l.__)("现金","jio"))),(0,e.createElement)("label",null,(0,e.createElement)("input",{type:"radio",checked:"points"===r.pay.modo,onChange:()=>n({pay:{...r.pay,modo:"points"}})}),(0,e.createElement)("span",null,(0,l.__)("积分","jio")))),"cash"===r.pay.modo?(0,e.createElement)("label",{className:"jio-creator-input"},(0,e.createElement)("span",null,(0,l.__)("价格","jio")),(0,e.createElement)("input",{type:"number",min:Number(i.priceMin||0),step:"0.01",value:r.pay.price,onChange:e=>n({pay:{...r.pay,price:e.target.value}})})):(0,e.createElement)("label",{className:"jio-creator-input"},(0,e.createElement)("span",null,(0,l.__)("积分价格","jio")),(0,e.createElement)("input",{type:"number",min:0,step:"1",value:r.pay.points,onChange:e=>n({pay:{...r.pay,points:Number(e.target.value)||0}})})),o.canPayDownload&&(0,e.createElement)("div",{className:"jio-creator-attachments"},(0,e.createElement)("div",{className:"jio-creator-attachments__head"},(0,e.createElement)("h4",null,(0,l.__)("资料附件","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){v(""),k(!0);try{const t=await u(d.creator.privateUrl,e,p,{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:""};n({pay:{...r.pay,enabled:!0,downloads:[...r.pay.downloads,a]}}),C.current&&(C.current.value="")}catch(e){v(String(e?.message||(0,l.__)("资料上传失败","jio")))}finally{k(!1)}}})()},disabled:N}),(0,e.createElement)("span",null,N?(0,l.__)("上传中…","jio"):(0,l.__)("添加 PDF / ZIP","jio"))):(0,e.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("私有附件存储尚未配置,暂时不能上传付费资料。","jio"))),w&&(0,e.createElement)("p",{className:"jio-creator-error"},w),r.pay.downloads.length>0&&(0,e.createElement)("ul",{className:"jio-creator-files"},r.pay.downloads.map((t,a)=>(0,e.createElement)("li",{key:`${t.assetKey||t.url}-${a}`},(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,l.__)("受保护资料","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=>{n({pay:{...r.pay,downloads:r.pay.downloads.filter((t,a)=>a!==e)}})})(a),"aria-label":(0,l.__)("移除","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))))),b.length>0&&(0,e.createElement)("details",{className:"jio-creator-reuse"},(0,e.createElement)("summary",null,(0,l.__)("从已上传资料中选择","jio")),(0,e.createElement)("ul",null,b.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:()=>n({pay:{...r.pay,enabled:!0,downloads:[...r.pay.downloads,{...t,type:"protected"}]}})},(0,l.__)("使用","jio"))))))))),!o.canPay&&o.canSaveDraft&&(0,e.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("当前账号不能设置付费内容。","jio"))),(0,e.createElement)("footer",{className:"jio-creator-drawer__foot"},g&&(0,e.createElement)("div",{className:"jio-creator-drawer__captcha",ref:x}),(0,e.createElement)("div",{className:"jio-creator-drawer__actions"},(0,e.createElement)("button",{type:"button",className:"jio-creator-ghost",onClick:_,disabled:E},(0,l.__)("保存草稿","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator-primary",onClick:()=>y(!1),disabled:E||!I},s?(0,l.__)("提交审核","jio"):o.canPublishNow?(0,l.__)("发布","jio"):(0,l.__)("提交审核","jio")),o.canPublishNow&&(0,e.createElement)("button",{type:"button",className:"jio-creator-link",onClick:()=>y(!0),disabled:E||!I},(0,l.__)("立即发布","jio"))))))}const y={ready:(0,l.__)("尚未保存","jio"),saving:(0,l.__)("保存中…","jio"),saved:(0,l.__)("已保存","jio"),error:(0,l.__)("保存失败","jio"),conflict:(0,l.__)("内容已在别处更新","jio"),submitting:(0,l.__)("提交中…","jio"),submitted:(0,l.__)("已提交","jio")};function f({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,y[t.state]||y.ready),"saved"===t.state&&t.at?(0,e.createElement)("time",null,t.at):null)}function b(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}}}window.__jioCoreBlocksRegistered||"function"!=typeof r.registerCoreBlocks||((0,r.registerCoreBlocks)(),window.__jioCoreBlocksRegistered=!0);const E=window.jioCreatorStudio||{},g=E.nonce||"",j=`jio-studio-${E.sourceId||0}`;function h(){const e=E.pay||{},t=E.categories&&E.categories.selected||[],a=E.tags&&E.tags.items||[];return{postId:Number(E.sourceId||0),versionId:Number(E.versionId||0),rev:Number(E.versionRev||0),title:String(E.title||""),excerpt:String(E.excerpt||""),content:String(E.content||""),categories:t.map(Number),tags:a.slice(),custom:E.custom||{},featured:E.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 w(){const[r,c]=(0,t.useState)(h),[s,u]=(0,t.useState)(()=>(0,a.parse)(r.content||"")),[d,p]=(0,t.useState)({state:"ready",at:""}),[y,w]=(0,t.useState)(!1),[v,N]=(0,t.useState)(null),[k,S]=(0,t.useState)(null),C=(0,t.useRef)(!1),x=E.capabilities||{},I={titleMin:Number(E.limits?.titleMin||1),titleMax:Number(E.limits?.titleMax||30),titlePlaceholder:String(E.limits?.titlePlaceholder||(0,l.__)("请输入标题","jio")),priceMin:Number(E.pay?.priceMin||0),priceMax:Number(E.pay?.priceMax||0),pointsMin:Number(E.pay?.pointsMin||0),pointsMax:Number(E.pay?.pointsMax||0)},L=!!E.isPublished,M=(0,t.useCallback)(e=>{C.current=!0,c(t=>({...t,...e}))},[]),P=(0,t.useCallback)(e=>{C.current=!0,u(e)},[]),D=(0,t.useMemo)(()=>(0,a.serialize)(s),[s]),R=(0,t.useMemo)(()=>(0,i.count)(D.replace(/<[^>]*>/g," "),"words",{}),[D]),U=(0,t.useCallback)((e={})=>({post_id:r.postId,version_id:r.versionId,rev:r.rev,title:r.title,excerpt:r.excerpt,content:D,categories:r.categories,tags:r.tags,custom:r.custom,featured:r.featured,pay:b(r.pay),...e}),[r,D]),B=(0,t.useCallback)(async(e=!1)=>{if(!C.current&&(r.postId>0||r.versionId>0))return!0;const t=""!==r.title.trim()||""!==D.replace(/<[^>]*>/g,"").trim();if(e&&!t)return!0;p({state:"saving",at:""});try{const t=await m(E.creator.saveUrl,U({autosave:e}),g),a=Number(t.post_id||r.postId||0),n=Number(t.version_id||r.versionId||0),o=Number(t.rev||t.versionRev||r.rev||0);return C.current=!1,c(e=>({...e,postId:a,versionId:n,rev:o})),p({state:"saved",at:(new Date).toLocaleTimeString()}),!0}catch(e){return p({state:409===e?.status?"conflict":"error",at:""}),!1}},[U,r.postId,r.versionId,r.rev]),z=(0,t.useCallback)(async e=>{p({state:"submitting",at:""});try{let t="";const a=window.JioCaptcha;if(E.captcha?.enabled&&a&&"function"==typeof a.run){const e=await a.run("front_submit");if(null===e)return p({state:"ready",at:""}),void N({tone:"error",text:(0,l.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const r=await m(E.creator.submitUrl,U({publish_now:e,captcha_proof:t}),g);C.current=!1,p({state:"submitted",at:""}),N({tone:"ok",text:String(r.message||(0,l.__)("已提交","jio"))}),w(!1);const n=r.url||r.goto||E.urls?.center;n&&window.setTimeout(()=>{window.location.href=n},900)}catch(e){p({state:"error",at:""}),N({tone:"error",text:String(e?.message||(0,l.__)("提交失败","jio"))})}},[U]),T=(0,t.useCallback)(async()=>{if(await B(!1))try{const e=await m(E.creator.previewUrl,{post_id:r.postId,version_id:r.versionId},g);e.url&&window.open(String(e.url),"_blank","noopener")}catch(e){N({tone:"error",text:String(e?.message||(0,l.__)("预览失败","jio"))})}},[r.postId,r.versionId,B]),{markLocalSaved:K,clear:F}=function({key:e,snapshot:a,onFound:r}){const n=(0,t.useRef)(a);n.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 n=JSON.parse(t),o="string"==typeof n.at?Date.parse(n.at):NaN;if(!Number.isFinite(o)||Date.now()-o>6048e5)return void window.localStorage.removeItem(e);"string"==typeof n.content&&n.content!==a.content&&r(String(n.at))}catch(t){window.localStorage.removeItem(e)}}},[e,r,a.content]),{markLocalSaved:(0,t.useCallback)(()=>{try{window.localStorage.setItem(e,JSON.stringify(n.current))}catch(e){}},[e]),clear:(0,t.useCallback)(()=>{try{window.localStorage.removeItem(e)}catch(e){}},[e])}}({key:j,snapshot:{title:r.title,content:D,at:(new Date).toISOString()},onFound:e=>S({savedAt:e})}),O=function({enabled:e,onSave:a,onLocal:r,remoteDelay:n=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),m=(0,t.useRef)(r);s.current=a,m.current=r;const u=(0,t.useCallback)(()=>{i.current&&(window.clearTimeout(i.current),i.current=null),l.current&&(window.clearTimeout(l.current),l.current=null)},[]),d=(0,t.useCallback)(async()=>{if(!c.current){c.current=!0;try{await s.current()}finally{c.current=!1}}},[]),p=(0,t.useCallback)(()=>{u(),m.current(),e&&(l.current=window.setTimeout(()=>m.current(),o),i.current=window.setTimeout(()=>{d()},n))},[u,e,d,o,n]);return(0,t.useEffect)(()=>{if(!e)return;const t=()=>{"hidden"===document.visibilityState&&d()},a=()=>{d()};return document.addEventListener("visibilitychange",t),window.addEventListener("blur",a),()=>{document.removeEventListener("visibilitychange",t),window.removeEventListener("blur",a),u()}},[u,e,d]),(0,t.useMemo)(()=>({schedule:p,flush:d,cancel:u}),[u,d,p])}({enabled:!!x.isLoggedIn,onSave:async()=>{const e=await B(!0);return e&&F(),e},onLocal:K}).schedule;(0,t.useEffect)(()=>{C.current&&O()},[r,D,O]),(0,t.useEffect)(()=>{const e=e=>{C.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(),B(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[B]);const A=(0,t.useCallback)(()=>{try{const e=window.localStorage.getItem(j);if(e){const t=JSON.parse(e);"string"==typeof t.title&&(C.current=!0,c(e=>({...e,title:t.title}))),"string"==typeof t.content&&(C.current=!0,u((0,a.parse)(t.content)))}}catch(e){}S(null)},[]),J=(0,n.useSelect)(e=>e("core/block-editor").getBlockCount(),[]);return(0,e.createElement)("div",{className:"jio-creator","data-status":E.status||"","data-blocks":J},(0,e.createElement)("header",{className:"jio-creator__bar"},(0,e.createElement)("a",{className:"jio-creator__back",href:E.urls?.center||"/"},(0,e.createElement)("i",{className:"fa fas fa-angle-left","aria-hidden":"true"}),(0,e.createElement)("span",null,(0,l.__)("返回","jio"))),(0,e.createElement)("div",{className:"jio-creator__brand"},"Jio Creator Studio"),(0,e.createElement)("div",{className:"jio-creator__actions"},(0,e.createElement)(f,{value:d}),(0,e.createElement)("button",{type:"button",className:"jio-creator__ghost",onClick:()=>{T()}},(0,l.__)("预览","jio")),(0,e.createElement)("button",{type:"button",className:"jio-creator__primary",onClick:()=>w(!0)},L?(0,l.__)("提交改稿","jio"):(0,l.__)("发布","jio")))),k&&(0,e.createElement)("div",{className:"jio-creator__notice",role:"status"},(0,e.createElement)("span",null,(0,l.__)("发现本地未同步的草稿。","jio")),(0,e.createElement)("button",{type:"button",onClick:A},(0,l.__)("恢复","jio")),(0,e.createElement)("button",{type:"button",onClick:()=>S(null)},(0,l.__)("忽略","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:()=>N(null),"aria-label":(0,l.__)("关闭","jio")},(0,e.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),L&&(0,e.createElement)("p",{className:"jio-creator__hint"},(0,l.__)("这篇改稿不会立即覆盖线上文章;审核通过后才会替换。","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,l.__)("文章标题","jio")),(0,e.createElement)("textarea",{value:r.title,onChange:e=>M({title:e.target.value}),rows:1,placeholder:I.titlePlaceholder||(0,l.__)("请输入标题","jio"),maxLength:4*(Number(I.titleMax)||30)})),(0,e.createElement)("label",{className:"jio-creator__excerpt"},(0,e.createElement)("span",null,(0,l.__)("摘要(可选)","jio")),(0,e.createElement)("textarea",{value:r.excerpt,onChange:e=>M({excerpt:e.target.value}),rows:2,placeholder:(0,l.__)("一句话概括这篇文章","jio")})),(0,e.createElement)("div",{className:"jio-creator__editor"},(0,e.createElement)(o.BlockEditorProvider,{value:s,onInput:P,onChange:P,settings:{hasFixedToolbar:!1,supportsLayout:!1,mediaUpload:window.jioCreatorMediaUpload}},(0,e.createElement)(o.BlockTools,null,(0,e.createElement)(o.BlockList,null)),(0,e.createElement)("aside",{className:"jio-creator__inspector","aria-label":(0,l.__)("区块设置","jio")},(0,e.createElement)(o.BlockInspector,null)))),(0,e.createElement)("footer",{className:"jio-creator__footer"},(0,e.createElement)("span",null,(0,l.__)("字数","jio"),":",R),(0,e.createElement)("span",null,(0,l.__)("约","jio")," ",Math.max(1,Math.round(R/400))," ",(0,l.__)("分钟阅读","jio")))),y&&(0,e.createElement)(_,{draft:r,setDraft:M,capabilities:x,limits:I,taxonomy:{categories:E.categories&&E.categories.items||[],tags:!!E.tags?.enabled,customDefs:E.customDefs||[]},isPublishedEdit:L,onClose:()=>w(!1),onSaveDraft:()=>{B(!1)},onSubmit:e=>{z(e)},privateStorage:!!E.privateStorage,privateUploads:E.privateUploads||[],captcha:!!E.captcha?.enabled,saving:"saving"===d.state||"submitting"===d.state}))}function v(){const a=document.getElementById("jio-creator-studio");a&&(function(e,t){const a=e?.blocks?.mediaUploadUrl;if(!a)return;const r=Number(e?.media?.maxBytes||0),n=!1!==e?.capabilities?.canUploadImage;window.jioCreatorMediaUpload=e=>{const{file:o,onError:i,onSuccess:l}=e||{};if(!o||"object"==typeof o&&!(o instanceof File))return void i?.("无效的文件");if(!n)return void i?.("当前账号不能上传图片");if(r>0&&o.size>r)return void i?.("图片大小超过限制");const c=new FormData;c.append("file",o),fetch(a,{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":t},body:c}).then(e=>e.json().then(t=>{if(!e.ok)throw new Error(t&&t.message||"上传失败");return t})).then(e=>{l?.({id:Number(e.attachment_id||e.id||0),url:String(e.url||""),alt:"",caption:"",title:String(e.title||e.name||""),width:Number(e.width||0),height:Number(e.height||0),sizes:e.sizes||{},mime:String(e.mime||"")})}).catch(e=>{i?.(e?.message||"上传失败")})}}(E,g),a.classList.add("is-ready"),(0,t.createRoot)(a).render((0,e.createElement)(w,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",v):v()})();