diff --git a/assets/creator-studio/build/index.asset.php b/assets/creator-studio/build/index.asset.php index fe5de009..4f768bf9 100644 --- a/assets/creator-studio/build/index.asset.php +++ b/assets/creator-studio/build/index.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-block-library', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-wordcount'), 'version' => '9f8085a073c5e67a84ed'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-block-library', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-wordcount'), 'version' => 'd48b7a862f5ed6e6e859'); diff --git a/assets/creator-studio/build/index.js b/assets/creator-studio/build/index.js index 32172571..ab753ec6 100644 --- a/assets/creator-studio/build/index.js +++ b/assets/creator-studio/build/index.js @@ -1 +1 @@ -(()=>{"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()})(); \ No newline at end of file +(()=>{"use strict";const e={n:t=>{const a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.hasOwn(e,t)},t=window.React,a=window.wp.element,r=window.wp.blocks,n=window.wp.blockLibrary,o=window.wp.data,i=window.wp.blockEditor,c=window.wp.wordcount,l=window.wp.i18n;function s(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 m(e){try{return await e.json()}catch(e){return null}}async function u(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 m(r);if(!r.ok)throw s(n,r.status);return n}async function d(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 m(o);if(!o.ok)throw s(i,o.status);return i}const p=window.wp.apiFetch;var _=e.n(p);const f=window.jioCreatorStudio||{},y=f.nonce||"";function b(e){const{draft:r,setDraft:n,capabilities:o,limits:i,taxonomy:c,isPublishedEdit:s,onClose:m,onSaveDraft:u,onSubmit:p,privateStorage:_,privateUploads:b,saving:E,captcha:g}=e,[j,w]=(0,a.useState)(""),[h,v]=(0,a.useState)(""),[N,k]=(0,a.useState)(!1),S=(0,a.useRef)(null),C=(0,a.useRef)(null),I=(0,a.useRef)(null);(0,a.useEffect)(()=>{const e=I.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,a.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]))}),w("")};return(0,t.createElement)("div",{className:"jio-creator-drawer",role:"dialog","aria-modal":"true","aria-labelledby":"jio-creator-publish-title"},(0,t.createElement)("button",{type:"button",className:"jio-creator-drawer__backdrop","aria-label":(0,l.__)("关闭","jio"),onClick:m}),(0,t.createElement)("div",{className:"jio-creator-drawer__panel"},(0,t.createElement)("header",{className:"jio-creator-drawer__head"},(0,t.createElement)("h2",{id:"jio-creator-publish-title"},s?(0,l.__)("提交改稿","jio"):(0,l.__)("发布文章","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator-drawer__close",onClick:m,"aria-label":(0,l.__)("关闭","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,t.createElement)("div",{className:"jio-creator-drawer__body"},s&&(0,t.createElement)("p",{className:"jio-creator-drawer__note"},(0,l.__)("审核通过前,读者看到的仍然是当前线上版本。","jio")),(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("h3",null,(0,l.__)("封面","jio")),r.featured?.data?.url?(0,t.createElement)("div",{className:"jio-creator-cover"},(0,t.createElement)("img",{src:String(r.featured.data.url),alt:""}),(0,t.createElement)("button",{type:"button",onClick:()=>n({featured:{type:"",data:{}}}),"aria-label":(0,l.__)("移除封面","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))):o.canUploadImage?(0,t.createElement)("label",{className:"jio-creator-cover-empty"},(0,t.createElement)("input",{ref:S,type:"file",accept:"image/*",onChange:()=>{(async()=>{const e=S.current?.files?.[0];if(e&&f.media?.uploadUrl?.image){v(""),k(!0);try{const t=await d(f.media.uploadUrl.image,e,y),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,t.createElement)("i",{className:"fa fas fa-plus","aria-hidden":"true"}),(0,t.createElement)("span",null,N?(0,l.__)("上传中…","jio"):(0,l.__)("上传封面","jio"))):(0,t.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("当前账号不能设置封面。","jio"))),(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("h3",null,(0,l.__)("分类","jio")),(0,t.createElement)("div",{className:"jio-creator-chips"},0===c.categories.length&&(0,t.createElement)("span",{className:"jio-creator-muted"},(0,l.__)("暂无可选分类","jio")),c.categories.map(e=>(0,t.createElement)("label",{key:e.id,className:"jio-creator-chip"+(r.categories.includes(e.id)?" is-active":"")},(0,t.createElement)("input",{type:"checkbox",checked:r.categories.includes(e.id),onChange:()=>(e=>{const t=r.categories.includes(e);n({categories:t?r.categories.filter(t=>t!==e):[...r.categories,e]})})(e.id)}),(0,t.createElement)("span",null,e.name))))),c.tags&&(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("h3",null,(0,l.__)("标签","jio")),(0,t.createElement)("div",{className:"jio-creator-chips"},r.tags.map(e=>(0,t.createElement)("span",{key:e,className:"jio-creator-chip is-active"},(0,t.createElement)("span",null,e),(0,t.createElement)("button",{type:"button",onClick:()=>n({tags:r.tags.filter(t=>t!==e)}),"aria-label":(0,l.sprintf)((0,l.__)("移除标签 %s","jio"),e)},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))))),(0,t.createElement)("div",{className:"jio-creator-inline"},(0,t.createElement)("input",{type:"text",value:j,placeholder:(0,l.__)("输入标签,逗号分隔","jio"),onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),L())}}),(0,t.createElement)("button",{type:"button",onClick:L},(0,l.__)("添加","jio")))),c.customDefs.map(e=>(0,t.createElement)("section",{className:"jio-creator-field",key:e.key},(0,t.createElement)("h3",null,e.name),(0,t.createElement)("div",{className:"jio-creator-chips"},e.values.map(a=>{const o=r.custom[e.key]||[],i=o.includes(a.key);return(0,t.createElement)("label",{key:a.key,className:"jio-creator-chip"+(i?" is-active":"")},(0,t.createElement)("input",{type:"checkbox",checked:i,onChange:()=>n({custom:{...r.custom,[e.key]:i?o.filter(e=>e!==a.key):[...o,a.key]}})}),(0,t.createElement)("span",null,a.name))})))),o.canPay&&(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("div",{className:"jio-creator-switch"},(0,t.createElement)("div",null,(0,t.createElement)("h3",null,(0,l.__)("付费内容","jio")),(0,t.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("开启后,未购买读者只能看到免费部分。","jio"))),(0,t.createElement)("label",{className:"jio-creator-toggle"},(0,t.createElement)("input",{type:"checkbox",checked:r.pay.enabled,onChange:e=>n({pay:{...r.pay,enabled:e.target.checked}})}),(0,t.createElement)("span",{"aria-hidden":"true"}))),r.pay.enabled&&(0,t.createElement)("div",{className:"jio-creator-pay"},(0,t.createElement)("div",{className:"jio-creator-inline"},(0,t.createElement)("label",null,(0,t.createElement)("input",{type:"radio",checked:"cash"===r.pay.modo,onChange:()=>n({pay:{...r.pay,modo:"cash"}})}),(0,t.createElement)("span",null,(0,l.__)("现金","jio"))),(0,t.createElement)("label",null,(0,t.createElement)("input",{type:"radio",checked:"points"===r.pay.modo,onChange:()=>n({pay:{...r.pay,modo:"points"}})}),(0,t.createElement)("span",null,(0,l.__)("积分","jio")))),"cash"===r.pay.modo?(0,t.createElement)("label",{className:"jio-creator-input"},(0,t.createElement)("span",null,(0,l.__)("价格","jio")),(0,t.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,t.createElement)("label",{className:"jio-creator-input"},(0,t.createElement)("span",null,(0,l.__)("积分价格","jio")),(0,t.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,t.createElement)("div",{className:"jio-creator-attachments"},(0,t.createElement)("div",{className:"jio-creator-attachments__head"},(0,t.createElement)("h4",null,(0,l.__)("资料附件","jio")),_?(0,t.createElement)("label",{className:"jio-creator-upload"},(0,t.createElement)("input",{ref:C,type:"file",onChange:()=>{(async()=>{const e=C.current?.files?.[0];if(e){v(""),k(!0);try{const t=await d(f.creator.privateUrl,e,y,{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,t.createElement)("span",null,N?(0,l.__)("上传中…","jio"):(0,l.__)("添加 PDF / ZIP","jio"))):(0,t.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("私有附件存储尚未配置,暂时不能上传付费资料。","jio"))),h&&(0,t.createElement)("p",{className:"jio-creator-error"},h),r.pay.downloads.length>0&&(0,t.createElement)("ul",{className:"jio-creator-files"},r.pay.downloads.map((e,a)=>(0,t.createElement)("li",{key:`${e.assetKey||e.url}-${a}`},(0,t.createElement)("span",{className:"jio-creator-files__name"},e.assetKey?(0,t.createElement)(t.Fragment,null,(0,t.createElement)("i",{className:"fa fas fa-lock","aria-hidden":"true"}),e.fileName||e.label||(0,l.__)("受保护资料","jio")):(0,t.createElement)(t.Fragment,null,(0,t.createElement)("i",{className:"fa fas fa-link","aria-hidden":"true"}),e.label||e.url)),e.sizeLabel&&(0,t.createElement)("span",{className:"jio-creator-muted"},e.sizeLabel),(0,t.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,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))))),b.length>0&&(0,t.createElement)("details",{className:"jio-creator-reuse"},(0,t.createElement)("summary",null,(0,l.__)("从已上传资料中选择","jio")),(0,t.createElement)("ul",null,b.filter(e=>!r.pay.downloads.some(t=>t.assetKey===e.assetKey)).map(e=>(0,t.createElement)("li",{key:e.assetKey},(0,t.createElement)("span",null,e.fileName),(0,t.createElement)("span",{className:"jio-creator-muted"},e.sizeLabel),(0,t.createElement)("button",{type:"button",onClick:()=>n({pay:{...r.pay,enabled:!0,downloads:[...r.pay.downloads,{...e,type:"protected"}]}})},(0,l.__)("使用","jio"))))))))),!o.canPay&&o.canSaveDraft&&(0,t.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("当前账号不能设置付费内容。","jio"))),(0,t.createElement)("footer",{className:"jio-creator-drawer__foot"},g&&(0,t.createElement)("div",{className:"jio-creator-drawer__captcha",ref:I}),(0,t.createElement)("div",{className:"jio-creator-drawer__actions"},(0,t.createElement)("button",{type:"button",className:"jio-creator-ghost",onClick:u,disabled:E},(0,l.__)("保存草稿","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator-primary",onClick:()=>p(!1),disabled:E||!x},s?(0,l.__)("提交审核","jio"):o.canPublishNow?(0,l.__)("发布","jio"):(0,l.__)("提交审核","jio")),o.canPublishNow&&(0,t.createElement)("button",{type:"button",className:"jio-creator-link",onClick:()=>p(!0),disabled:E||!x},(0,l.__)("立即发布","jio"))))))}const E={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 g({value:e}){return(0,t.createElement)("span",{className:`jio-creator__save is-${e.state}`,role:"status","aria-live":"polite"},(0,t.createElement)("i",{className:"fa fas fa-circle","aria-hidden":"true"}),(0,t.createElement)("span",null,E[e.state]||E.ready),"saved"===e.state&&e.at?(0,t.createElement)("time",null,e.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}}}window.__jioCoreBlocksRegistered||"function"!=typeof n.registerCoreBlocks||((0,n.registerCoreBlocks)(),window.__jioCoreBlocksRegistered=!0);const w=window.jioCreatorStudio||{},h=w.nonce||"",v=`jio-studio-${w.sourceId||0}`;function N(){const e=w.pay||{},t=w.categories&&w.categories.selected||[],a=w.tags&&w.tags.items||[];return{postId:Number(w.sourceId||0),versionId:Number(w.versionId||0),rev:Number(w.versionRev||0),title:String(w.title||""),excerpt:String(w.excerpt||""),content:String(w.content||""),categories:t.map(Number),tags:a.slice(),custom:w.custom||{},featured:w.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 k(){const[e,n]=(0,a.useState)(N),[s,m]=(0,a.useState)(()=>(0,r.parse)(e.content||"")),[d,p]=(0,a.useState)({state:"ready",at:""}),[_,f]=(0,a.useState)(!1),[y,E]=(0,a.useState)(null),[k,S]=(0,a.useState)(null),C=(0,a.useRef)(!1),I=w.capabilities||{},x={titleMin:Number(w.limits?.titleMin||1),titleMax:Number(w.limits?.titleMax||30),titlePlaceholder:String(w.limits?.titlePlaceholder||(0,l.__)("请输入标题","jio")),priceMin:Number(w.pay?.priceMin||0),priceMax:Number(w.pay?.priceMax||0),pointsMin:Number(w.pay?.pointsMin||0),pointsMax:Number(w.pay?.pointsMax||0)},L=!!w.isPublished,M=(0,a.useCallback)(e=>{C.current=!0,n(t=>({...t,...e}))},[]),P=(0,a.useCallback)(e=>{C.current=!0,m(e)},[]),D=(0,a.useMemo)(()=>(0,r.serialize)(s),[s]),R=(0,a.useMemo)(()=>(0,c.count)(D.replace(/<[^>]*>/g," "),"words",{}),[D]),U=(0,a.useCallback)((t={})=>({post_id:e.postId,version_id:e.versionId,rev:e.rev,title:e.title,excerpt:e.excerpt,content:D,categories:e.categories,tags:e.tags,custom:e.custom,featured:e.featured,pay:j(e.pay),...t}),[e,D]),B=(0,a.useCallback)(async(t=!1)=>{if(!C.current&&(e.postId>0||e.versionId>0))return!0;const a=""!==e.title.trim()||""!==D.replace(/<[^>]*>/g,"").trim();if(t&&!a)return!0;p({state:"saving",at:""});try{const a=await u(w.creator.saveUrl,U({autosave:t}),h),r=Number(a.post_id||e.postId||0),o=Number(a.version_id||e.versionId||0),i=Number(a.rev||a.versionRev||e.rev||0);return C.current=!1,n(e=>({...e,postId:r,versionId:o,rev:i})),p({state:"saved",at:(new Date).toLocaleTimeString()}),!0}catch(e){return p({state:409===e?.status?"conflict":"error",at:""}),!1}},[U,e.postId,e.versionId,e.rev]),F=(0,a.useCallback)(async e=>{if(await B(!1)){p({state:"submitting",at:""});try{let t="";const a=window.JioCaptcha;if(w.captcha?.enabled&&a&&"function"==typeof a.run){const e=await a.run("front_submit");if(null===e)return p({state:"ready",at:""}),void E({tone:"error",text:(0,l.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const r=await u(w.creator.submitUrl,U({publish_now:e,captcha_proof:t}),h);C.current=!1,p({state:"submitted",at:""}),E({tone:"ok",text:String(r.message||(0,l.__)("已提交","jio"))}),f(!1);const n=r.url||r.goto||w.urls?.center;n&&window.setTimeout(()=>{window.location.href=n},900)}catch(e){p({state:"error",at:""}),E({tone:"error",text:String(e?.message||(0,l.__)("提交失败","jio"))})}}else E({tone:"error",text:(0,l.__)("内容保存失败,请重试后再提交","jio")})},[U,B]),O=(0,a.useCallback)(async()=>{if(await B(!1))try{const t=await u(w.creator.previewUrl,{post_id:e.postId,version_id:e.versionId},h);t.url&&window.open(String(t.url),"_blank","noopener")}catch(e){E({tone:"error",text:String(e?.message||(0,l.__)("预览失败","jio"))})}},[e.postId,e.versionId,B]),{markLocalSaved:z,clear:T}=function({key:e,snapshot:t,onFound:r}){const n=(0,a.useRef)(t);n.current=t;const o=(0,a.useRef)(!1);return(0,a.useEffect)(()=>{if(!o.current){o.current=!0;try{const a=window.localStorage.getItem(e);if(!a)return;const n=JSON.parse(a),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!==t.content&&r(String(n.at))}catch(t){window.localStorage.removeItem(e)}}},[e,r,t.content]),{markLocalSaved:(0,a.useCallback)(()=>{try{window.localStorage.setItem(e,JSON.stringify(n.current))}catch(e){}},[e]),clear:(0,a.useCallback)(()=>{try{window.localStorage.removeItem(e)}catch(e){}},[e])}}({key:v,snapshot:{title:e.title,content:D,at:(new Date).toISOString()},onFound:e=>S({savedAt:e})}),K=function({enabled:e,onSave:t,onLocal:r,remoteDelay:n=4e3,localDelay:o=1500}){const i=(0,a.useRef)(null),c=(0,a.useRef)(null),l=(0,a.useRef)(!1),s=(0,a.useRef)(t),m=(0,a.useRef)(r);s.current=t,m.current=r;const u=(0,a.useCallback)(()=>{i.current&&(window.clearTimeout(i.current),i.current=null),c.current&&(window.clearTimeout(c.current),c.current=null)},[]),d=(0,a.useCallback)(async()=>{if(!l.current){l.current=!0;try{await s.current()}finally{l.current=!1}}},[]),p=(0,a.useCallback)(()=>{u(),m.current(),e&&(c.current=window.setTimeout(()=>m.current(),o),i.current=window.setTimeout(()=>{d()},n))},[u,e,d,o,n]);return(0,a.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,a.useMemo)(()=>({schedule:p,flush:d,cancel:u}),[u,d,p])}({enabled:!!I.isLoggedIn,onSave:async()=>{const e=await B(!0);return e&&T(),e},onLocal:z}).schedule;(0,a.useEffect)(()=>{C.current&&K()},[e,D,K]),(0,a.useEffect)(()=>{const e=e=>{C.current&&(e.preventDefault(),e.returnValue="")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),(0,a.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,a.useCallback)(()=>{try{const e=window.localStorage.getItem(v);if(e){const t=JSON.parse(e);"string"==typeof t.title&&(C.current=!0,n(e=>({...e,title:t.title}))),"string"==typeof t.content&&(C.current=!0,m((0,r.parse)(t.content)))}}catch(e){}S(null)},[]),J=(0,o.useSelect)(e=>e("core/block-editor").getBlockCount(),[]);return(0,t.createElement)("div",{className:"jio-creator","data-status":w.status||"","data-blocks":J},(0,t.createElement)("header",{className:"jio-creator__bar"},(0,t.createElement)("a",{className:"jio-creator__back",href:w.urls?.center||"/"},(0,t.createElement)("i",{className:"fa fas fa-angle-left","aria-hidden":"true"}),(0,t.createElement)("span",null,(0,l.__)("返回","jio"))),(0,t.createElement)("div",{className:"jio-creator__brand"},"Jio Creator Studio"),(0,t.createElement)("div",{className:"jio-creator__actions"},(0,t.createElement)(g,{value:d}),(0,t.createElement)("button",{type:"button",className:"jio-creator__ghost",onClick:()=>{O()}},(0,l.__)("预览","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator__primary",onClick:()=>f(!0)},L?(0,l.__)("提交改稿","jio"):(0,l.__)("发布","jio")))),k&&(0,t.createElement)("div",{className:"jio-creator__notice",role:"status"},(0,t.createElement)("span",null,(0,l.__)("发现本地未同步的草稿。","jio")),(0,t.createElement)("button",{type:"button",onClick:A},(0,l.__)("恢复","jio")),(0,t.createElement)("button",{type:"button",onClick:()=>S(null)},(0,l.__)("忽略","jio"))),y&&(0,t.createElement)("div",{className:`jio-creator__notice is-${y.tone}`,role:"status"},(0,t.createElement)("span",null,y.text),(0,t.createElement)("button",{type:"button",onClick:()=>E(null),"aria-label":(0,l.__)("关闭","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),L&&(0,t.createElement)("p",{className:"jio-creator__hint"},(0,l.__)("这篇改稿不会立即覆盖线上文章;审核通过后才会替换。","jio")),(0,t.createElement)("main",{className:"jio-creator__canvas"},(0,t.createElement)("label",{className:"jio-creator__title"},(0,t.createElement)("span",{className:"screen-reader-text"},(0,l.__)("文章标题","jio")),(0,t.createElement)("textarea",{value:e.title,onChange:e=>M({title:e.target.value}),rows:1,placeholder:x.titlePlaceholder||(0,l.__)("请输入标题","jio"),maxLength:4*(Number(x.titleMax)||30)})),(0,t.createElement)("label",{className:"jio-creator__excerpt"},(0,t.createElement)("span",null,(0,l.__)("摘要(可选)","jio")),(0,t.createElement)("textarea",{value:e.excerpt,onChange:e=>M({excerpt:e.target.value}),rows:2,placeholder:(0,l.__)("一句话概括这篇文章","jio")})),(0,t.createElement)("div",{className:"jio-creator__editor"},(0,t.createElement)(i.BlockEditorProvider,{value:s,onInput:P,onChange:P,settings:{hasFixedToolbar:!1,supportsLayout:!1,mediaUpload:window.jioCreatorMediaUpload}},(0,t.createElement)(i.BlockTools,null,(0,t.createElement)(i.BlockList,null)),(0,t.createElement)("aside",{className:"jio-creator__inspector","aria-label":(0,l.__)("区块设置","jio")},(0,t.createElement)(i.BlockInspector,null)))),(0,t.createElement)("footer",{className:"jio-creator__footer"},(0,t.createElement)("span",null,(0,l.__)("字数","jio"),":",R),(0,t.createElement)("span",null,(0,l.__)("约","jio")," ",Math.max(1,Math.round(R/400))," ",(0,l.__)("分钟阅读","jio")))),_&&(0,t.createElement)(b,{draft:e,setDraft:M,capabilities:I,limits:x,taxonomy:{categories:w.categories&&w.categories.items||[],tags:!!w.tags?.enabled,customDefs:w.customDefs||[]},isPublishedEdit:L,onClose:()=>f(!1),onSaveDraft:()=>{B(!1)},onSubmit:e=>{F(e)},privateStorage:!!w.privateStorage,privateUploads:w.privateUploads||[],captcha:!!w.captcha?.enabled,saving:"saving"===d.state||"submitting"===d.state}))}function S(){const e=document.getElementById("jio-creator-studio");e&&(function(e){if(!e||"function"!=typeof _().use)return;if(window.__jioApiFetchNonceInstalled)return;window.__jioApiFetchNonceInstalled=!0;const t=_().createNonceMiddleware;"function"!=typeof t?_().use((t,a)=>(t.headers={...t.headers||{},"X-WP-Nonce":e},a(t))):_().use(t(e))}(h),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:c}=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 l=new FormData;l.append("file",o),fetch(a,{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":t},body:l}).then(e=>e.json().then(t=>{if(!e.ok)throw new Error(t&&t.message||"上传失败");return t})).then(e=>{c?.({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||"上传失败")})}}(w,h),e.classList.add("is-ready"),(0,a.createRoot)(e).render((0,t.createElement)(k,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",S):S()})(); \ No newline at end of file diff --git a/assets/creator-studio/package-lock.json b/assets/creator-studio/package-lock.json index f5dc1be5..5ef92cda 100644 --- a/assets/creator-studio/package-lock.json +++ b/assets/creator-studio/package-lock.json @@ -10,6 +10,7 @@ "devDependencies": { "@types/react": "18.3.31", "@types/react-dom": "18.3.7", + "@wordpress/api-fetch": "^6.28.0", "@wordpress/block-editor": "11.8.0", "@wordpress/block-library": "^8.8.0", "@wordpress/blocks": "12.8.0", @@ -4862,48 +4863,20 @@ "license": "MIT" }, "node_modules/@wordpress/api-fetch": { - "version": "6.55.0", - "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-6.55.0.tgz", - "integrity": "sha512-1HrCUsJdeRY5Y0IjplotINwqMRO81e7O7VhBScuKk7iOuDm/E1ioKv2uLGnPNWziYu+Zf025byxOqVzXDyM2gw==", + "version": "6.28.0", + "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-6.28.0.tgz", + "integrity": "sha512-kEe8zqjEs1paZAS0ZSaUkiLTIrNFBy11ZkdBDYOYgl707zZCQt50HYs/J+zATWegWpp5scd4Tt18cJy1O9dosg==", "dev": true, "license": "GPL-2.0-or-later", "dependencies": { "@babel/runtime": "^7.16.0", - "@wordpress/i18n": "^4.58.0", - "@wordpress/url": "^3.59.0" + "@wordpress/i18n": "^4.31.0", + "@wordpress/url": "^3.32.0" }, "engines": { "node": ">=12" } }, - "node_modules/@wordpress/api-fetch/node_modules/@wordpress/i18n": { - "version": "4.58.0", - "resolved": "https://registry.npmjs.org/@wordpress/i18n/-/i18n-4.58.0.tgz", - "integrity": "sha512-VfvS3BWv/RDjRKD6PscIcvYfWKnGJcI/DEqyDgUMhxCM6NRwoL478CsUKTiGJIymeyRodNRfprdcF086DpGKYw==", - "dev": true, - "license": "GPL-2.0-or-later", - "dependencies": { - "@babel/runtime": "^7.16.0", - "@wordpress/hooks": "^3.58.0", - "gettext-parser": "^1.3.1", - "memize": "^2.1.0", - "sprintf-js": "^1.1.1", - "tannin": "^1.2.0" - }, - "bin": { - "pot-to-php": "tools/pot-to-php.js" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@wordpress/api-fetch/node_modules/memize": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/memize/-/memize-2.1.1.tgz", - "integrity": "sha512-8Nl+i9S5D6KXnruM03Jgjb+LwSupvR13WBr4hJegaaEyobvowCVupi79y2WSiWvO1mzBWxPwEYE5feCe8vyA5w==", - "dev": true, - "license": "MIT" - }, "node_modules/@wordpress/autop": { "version": "3.58.0", "resolved": "https://registry.npmjs.org/@wordpress/autop/-/autop-3.58.0.tgz", @@ -5786,6 +5759,21 @@ "react-dom": ">=16.8.0" } }, + "node_modules/@wordpress/core-data/node_modules/@wordpress/api-fetch": { + "version": "6.55.0", + "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-6.55.0.tgz", + "integrity": "sha512-1HrCUsJdeRY5Y0IjplotINwqMRO81e7O7VhBScuKk7iOuDm/E1ioKv2uLGnPNWziYu+Zf025byxOqVzXDyM2gw==", + "dev": true, + "license": "GPL-2.0-or-later", + "dependencies": { + "@babel/runtime": "^7.16.0", + "@wordpress/i18n": "^4.58.0", + "@wordpress/url": "^3.59.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@wordpress/core-data/node_modules/@wordpress/block-editor": { "version": "12.26.0", "resolved": "https://registry.npmjs.org/@wordpress/block-editor/-/block-editor-12.26.0.tgz", @@ -6994,6 +6982,21 @@ "react-dom": ">=16.8.0" } }, + "node_modules/@wordpress/reusable-blocks/node_modules/@wordpress/api-fetch": { + "version": "6.55.0", + "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-6.55.0.tgz", + "integrity": "sha512-1HrCUsJdeRY5Y0IjplotINwqMRO81e7O7VhBScuKk7iOuDm/E1ioKv2uLGnPNWziYu+Zf025byxOqVzXDyM2gw==", + "dev": true, + "license": "GPL-2.0-or-later", + "dependencies": { + "@babel/runtime": "^7.16.0", + "@wordpress/i18n": "^4.58.0", + "@wordpress/url": "^3.59.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@wordpress/reusable-blocks/node_modules/@wordpress/block-editor": { "version": "12.26.0", "resolved": "https://registry.npmjs.org/@wordpress/block-editor/-/block-editor-12.26.0.tgz", @@ -7714,6 +7717,21 @@ "react-dom": ">=16.8.0" } }, + "node_modules/@wordpress/server-side-render/node_modules/@wordpress/api-fetch": { + "version": "6.55.0", + "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-6.55.0.tgz", + "integrity": "sha512-1HrCUsJdeRY5Y0IjplotINwqMRO81e7O7VhBScuKk7iOuDm/E1ioKv2uLGnPNWziYu+Zf025byxOqVzXDyM2gw==", + "dev": true, + "license": "GPL-2.0-or-later", + "dependencies": { + "@babel/runtime": "^7.16.0", + "@wordpress/i18n": "^4.58.0", + "@wordpress/url": "^3.59.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@wordpress/server-side-render/node_modules/@wordpress/blocks": { "version": "12.35.0", "resolved": "https://registry.npmjs.org/@wordpress/blocks/-/blocks-12.35.0.tgz", diff --git a/assets/creator-studio/package.json b/assets/creator-studio/package.json index 171f7159..768b29e1 100644 --- a/assets/creator-studio/package.json +++ b/assets/creator-studio/package.json @@ -9,6 +9,7 @@ "devDependencies": { "@types/react": "18.3.31", "@types/react-dom": "18.3.7", + "@wordpress/api-fetch": "^6.28.0", "@wordpress/block-editor": "11.8.0", "@wordpress/block-library": "^8.8.0", "@wordpress/blocks": "12.8.0", diff --git a/assets/creator-studio/scripts/smoke.cjs b/assets/creator-studio/scripts/smoke.cjs new file mode 100644 index 00000000..f02df7f4 --- /dev/null +++ b/assets/creator-studio/scripts/smoke.cjs @@ -0,0 +1,92 @@ +/** + * Creator Studio 冒烟检查:用 puppeteer-core 连接本机浏览器,打开投稿页, + * 抓取控制台错误、失败请求与未捕获的 Promise 拒绝。 + * + * 用法: + * node scripts/smoke.cjs [url] + * 浏览器路径可用环境变量覆盖(默认按常见位置探测 Chrome / Edge): + * JIO_BROWSER="/path/to/chrome" node scripts/smoke.cjs + */ +const fs = require('fs'); +const puppeteer = require('puppeteer-core'); + +const CANDIDATES = [ + process.env.JIO_BROWSER, + 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', + 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', + 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe', + 'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe', + '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', + '/usr/bin/google-chrome', + '/usr/bin/chromium', +].filter(Boolean); + +const EDGE = CANDIDATES.find((p) => fs.existsSync(p)); +const URL = process.argv[2] || 'https://localhost/submit/'; + +if (!EDGE) { + console.error('未找到可用浏览器,请设置 JIO_BROWSER 环境变量指向 Chrome/Edge 可执行文件。'); + process.exit(1); +} + +(async () => { + const browser = await puppeteer.launch({ + executablePath: EDGE, + headless: 'new', + ignoreHTTPSErrors: true, + args: ['--disable-gpu', '--no-sandbox'], + }); + const page = await browser.newPage(); + const events = []; + + page.on('console', (m) => { + if (m.type() === 'error' || m.type() === 'warning') { + events.push(`[console.${m.type()}] ${m.text()}`); + } + }); + page.on('pageerror', (e) => { + events.push(`[pageerror] ${e.message}\n stack: ${(e.stack || '').split('\n').slice(0, 6).join('\n ')}`); + }); + page.on('response', async (r) => { + if (r.status() >= 400) { + let body = ''; + try { body = (await r.text()).slice(0, 300); } catch (_) {} + events.push(`[http ${r.status()}] ${r.url()}\n body: ${body.replace(/\s+/g, ' ')}`); + } + }); + + await page.evaluateOnNewDocument(() => { + window.__jioRejections = []; + window.addEventListener('unhandledrejection', (e) => { + const r = e.reason; + window.__jioRejections.push( + r && r.status + ? `status=${r.status} code=${r.code || ''} msg=${r.message}` + : String(r && r.message ? r.message : r) + ); + }); + window.addEventListener('error', (e) => { + window.__jioRejections.push(`onerror: ${e.message} @ ${e.filename}:${e.lineno}`); + }); + }); + + await page.goto(URL, { waitUntil: 'networkidle2', timeout: 60000 }); + await new Promise((r) => setTimeout(r, 3000)); + + const state = await page.evaluate(() => ({ + hasBar: !!document.querySelector('.jio-creator__bar'), + hasCanvas: !!document.querySelector('.jio-creator__canvas'), + appender: !!document.querySelector('.block-editor-default-block-appender'), + blocks: document.querySelectorAll('.block-editor-block-list__block').length, + saveText: (document.querySelector('.jio-creator__save') || {}).textContent, + rejections: window.__jioRejections || [], + })); + console.log('STATE ' + JSON.stringify({ ...state, rejections: undefined })); + if (state.rejections.length) { + console.log('--- rejections ---'); + state.rejections.slice(0, 10).forEach((r) => console.log(r)); + } + console.log('--- events ---'); + events.slice(0, 30).forEach((e) => console.log(e)); + await browser.close(); +})(); diff --git a/assets/creator-studio/src/index.tsx b/assets/creator-studio/src/index.tsx index a312e81e..4a1af654 100644 --- a/assets/creator-studio/src/index.tsx +++ b/assets/creator-studio/src/index.tsx @@ -17,6 +17,7 @@ import { count as countWords } from '@wordpress/wordcount'; import { __ } from '@wordpress/i18n'; import { apiPost } from './services/api'; +import { installApiFetchNonce } from './services/api-fetch'; import { installMediaUploadBridge } from './services/media'; import { PublishDrawer } from './panels/publish-drawer'; import { SaveState, type SaveStateValue } from './components/save-state'; @@ -183,6 +184,13 @@ function Studio(): JSX.Element { const submit = useCallback( async (publishNow: boolean): Promise => { + // 提交前先落一次草稿:审核 / 立即发布都以服务端最终保存的内容为准, + // 避免自动保存尚未触发时提交到旧内容。 + const persisted = await save(false); + if (!persisted) { + setNotice({ tone: 'error', text: __('内容保存失败,请重试后再提交', 'jio') }); + return; + } setSaveState({ state: 'submitting', at: '' }); try { // 站点启用「前台投稿」人机验证时,先完成挑战再提交; @@ -218,7 +226,7 @@ function Studio(): JSX.Element { setNotice({ tone: 'error', text: String(error?.message || __('提交失败', 'jio')) }); } }, - [buildPayload] + [buildPayload, save] ); const preview = useCallback(async (): Promise => { @@ -436,6 +444,7 @@ function mount() { if (!target) { return; } + installApiFetchNonce(nonce); installMediaUploadBridge(bootstrap, nonce); target.classList.add('is-ready'); createRoot(target).render(); diff --git a/assets/creator-studio/src/services/api-fetch.ts b/assets/creator-studio/src/services/api-fetch.ts new file mode 100644 index 00000000..a9ce8d79 --- /dev/null +++ b/assets/creator-studio/src/services/api-fetch.ts @@ -0,0 +1,33 @@ +/** + * 给 @wordpress/api-fetch 注入 REST nonce。 + * + * WordPress 仅在后台为 wp-api 注入 wpApiSettings(含 nonce),前台工作台里 + * Gutenberg 的 core-data 请求(如 /wp/v2/users/me)因此全部 403。这里统一挂一个 + * nonce 中间件,让区块编辑器的数据请求与 Jio REST 使用同一次页面加载的 nonce。 + * + * @package Jio + */ + +import apiFetch from '@wordpress/api-fetch'; + +export function installApiFetchNonce(nonce: string): void { + if (!nonce || typeof apiFetch.use !== 'function') { + return; + } + if ((window as any).__jioApiFetchNonceInstalled) { + return; + } + (window as any).__jioApiFetchNonceInstalled = true; + + // createNonceMiddleware 在收到 rest_cookie_invalid_nonce 时会带着 nonce 重试, + // 比在每次请求上手工加 header 更稳妥。 + const factory = (apiFetch as any).createNonceMiddleware; + if (typeof factory === 'function') { + apiFetch.use(factory(nonce)); + return; + } + apiFetch.use((options: any, next: any) => { + options.headers = { ...(options.headers || {}), 'X-WP-Nonce': nonce }; + return next(options); + }); +} diff --git a/src/Core/CreatorRest.php b/src/Core/CreatorRest.php index 099a85f5..15380e7e 100644 --- a/src/Core/CreatorRest.php +++ b/src/Core/CreatorRest.php @@ -11,6 +11,8 @@ namespace Jio\Core; +use Jio\Content\PrivateAssets; + defined('ABSPATH') || exit; final class CreatorRest { diff --git a/src/Core/SubmissionVersion.php b/src/Core/SubmissionVersion.php index 7f1987ac..0d4b91e0 100644 --- a/src/Core/SubmissionVersion.php +++ b/src/Core/SubmissionVersion.php @@ -14,6 +14,8 @@ namespace Jio\Core; +use Jio\Content\PrivateAssets; + defined('ABSPATH') || exit; final class SubmissionVersion { diff --git a/tools/check-class-refs.php b/tools/check-class-refs.php new file mode 100644 index 00000000..849f9d80 --- /dev/null +++ b/tools/check-class-refs.php @@ -0,0 +1,69 @@ +getFileName(); + $src = file_get_contents($f); + + // 去掉注释与字符串,只保留可执行代码里的类引用。 + $code = ''; + foreach (token_get_all($src) as $tok) { + if (is_array($tok)) { + if (in_array($tok[0], [T_COMMENT, T_DOC_COMMENT, T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE], true)) { + continue; + } + $code .= $tok[1]; + } else { + $code .= $tok; + } + } + + $ns = ''; + if (preg_match('/^namespace\s+([^;]+);/m', $src, $mm)) { + $ns = trim($mm[1], '\\'); + } + + $imports = []; + preg_match_all('/^use\s+([A-Za-z0-9_\\\\]+)(?:\s+as\s+([A-Za-z0-9_]+))?;/m', $code, $um, PREG_SET_ORDER); + foreach ($um as $u) { + $full = $u[1]; + $short = (isset($u[2]) && $u[2] !== '') ? $u[2] : substr($full, strrpos($full, '\\') + 1); + $imports[$short] = true; + } + + // 只匹配未加前导反斜杠的短类名;`\Foo\Bar::baz()` 是全限定引用,不受命名空间影响。 + preg_match_all('/(?