From 9e8913ea0ad2a55cd0a0aaa59fb333c3fe2139f2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Nov 2026 17:36:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(creator-studio):=20=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E5=BC=8F=E5=88=9B=E4=BD=9C=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 顶部改为 fixed 创作工具栏:左侧返回/品牌/模式,中间文章标题与保存状态, 右侧撤销/重做、保存草稿、预览、发布 - 新增工作台级撤销/重做快照栈,连续编辑合并记录;支持 Ctrl/Cmd+Z / Shift+Z, 不覆盖 RichText 输入框自身的编辑历史 - 移动端收敛工具栏布局,保留撤销/重做、预览、发布 - 先保存草稿再请求审核/直接发布;请求使用服务端更新后的文章与版本 ID - 固定工具栏以独立 chrome 层布局,正文避开顶部工具栏高度 - 补充固定工具栏、历史操作与键盘快捷键契约 Co-Authored-By: Claude Opus 5 (1M context) --- assets/creator-studio/build/index.asset.php | 2 +- assets/creator-studio/build/index.css | 2 +- assets/creator-studio/build/index.js | 2 +- assets/creator-studio/scripts/interact.cjs | 33 ++- .../src/hooks/use-editor-history.ts | 121 +++++++++ assets/creator-studio/src/index.tsx | 150 +++++++++-- assets/creator-studio/src/styles/studio.scss | 244 ++++++++++++++++-- templates/pages/page-submit.php | 1 + .../creator-studio-contract.test.cjs | 13 + 9 files changed, 518 insertions(+), 50 deletions(-) create mode 100644 assets/creator-studio/src/hooks/use-editor-history.ts diff --git a/assets/creator-studio/build/index.asset.php b/assets/creator-studio/build/index.asset.php index 20e8b056..623c27f5 100644 --- a/assets/creator-studio/build/index.asset.php +++ b/assets/creator-studio/build/index.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-block-library', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-wordcount'), 'version' => '71ff9994e44c86df3517'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-block-library', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-wordcount'), 'version' => '635f07e202f61f4e377f'); diff --git a/assets/creator-studio/build/index.css b/assets/creator-studio/build/index.css index 755587b4..8afb3170 100644 --- a/assets/creator-studio/build/index.css +++ b/assets/creator-studio/build/index.css @@ -1 +1 @@ -.jio-page-submit{background:#fafbfa}.jio-page-submit .float-btn,.jio-page-submit .footer,.jio-page-submit .footer-tabbar,.jio-page-submit .header,.jio-page-submit .jio-float-buttons{display:none!important}.jio-page-submit #main-content.container{max-width:none;padding:0}#jio-creator-studio.is-ready{display:block}.jio-creator{--jc-ink:#243330;--jc-ink-soft:#5c6b66;--jc-paper:#fafbfa;--jc-line:#e2e9e5;--jc-accent:#267665;--jc-accent-strong:#1d5f52;--jc-warn:#b4573f;--jc-bar:60px;-webkit-font-smoothing:antialiased;background:var(--jc-paper);color:var(--jc-ink);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Noto Sans SC,PingFang SC,Microsoft YaHei,sans-serif;min-height:100vh;min-height:100dvh}.jio-creator *,.jio-creator :after,.jio-creator :before{box-sizing:border-box}.jio-creator button{color:inherit;font:inherit}.jio-creator__bar{align-items:center;backdrop-filter:blur(10px);background:rgba(250,251,250,.92);border-bottom:1px solid var(--jc-line);display:flex;gap:16px;height:var(--jc-bar);padding:0 clamp(16px,4vw,40px);position:sticky;top:0;z-index:30}.jio-creator__back{align-items:center;color:var(--jc-ink-soft);display:inline-flex;gap:6px;text-decoration:none}.jio-creator__back:focus-visible,.jio-creator__back:hover{color:var(--jc-accent)}.jio-creator__brand{color:var(--jc-ink-soft);font-size:13px;letter-spacing:.06em;margin-right:auto}.jio-creator__actions{align-items:center;display:flex;gap:10px}.jio-creator__save{align-items:center;color:var(--jc-ink-soft);display:inline-flex;font-size:13px;gap:6px}.jio-creator__save>i{color:var(--jc-line);font-size:7px}.jio-creator__save time{font-variant-numeric:tabular-nums;opacity:.7}.jio-creator__save.is-saved>i{color:var(--jc-accent)}.jio-creator__save.is-conflict,.jio-creator__save.is-conflict>i,.jio-creator__save.is-error,.jio-creator__save.is-error>i{color:var(--jc-warn)}.jio-creator__btn,.jio-creator__ghost,.jio-creator__primary{align-items:center;border:1px solid transparent;border-radius:8px;cursor:pointer;display:inline-flex;font-size:14px;justify-content:center;min-height:36px;padding:0 16px;transition:background .18s ease,border-color .18s ease,color .18s ease}.jio-creator__ghost{background:transparent;border-color:var(--jc-line)}.jio-creator__ghost:focus-visible,.jio-creator__ghost:hover{border-color:var(--jc-accent);color:var(--jc-accent)}.jio-creator__primary{background:var(--jc-accent);color:#fff}.jio-creator__primary:focus-visible,.jio-creator__primary:hover{background:var(--jc-accent-strong)}.jio-creator__primary:disabled{cursor:not-allowed;opacity:.5}.jio-creator__notice{align-items:center;background:#f1f5f2;border-bottom:1px solid var(--jc-line);color:var(--jc-ink-soft);display:flex;font-size:13px;gap:12px;margin:0 auto;max-width:820px;padding:10px 16px}.jio-creator__notice>span{flex:1}.jio-creator__notice button{background:transparent;border:0;color:var(--jc-accent);cursor:pointer}.jio-creator__notice.is-error{background:#fdf2ee;color:var(--jc-warn)}.jio-creator__hint{color:var(--jc-ink-soft);font-size:13px;margin:18px auto 0;max-width:820px;padding:0 clamp(16px,4vw,40px)}.jio-creator__canvas{margin:0 auto;padding:clamp(20px,4vw,44px) clamp(20px,5vw,52px) 140px;width:min(720px,100%)}.jio-creator__title{display:block;margin-bottom:6px}.jio-creator__title textarea{background:transparent;border:0;color:var(--jc-ink);font-family:Songti SC,"Noto Serif SC","Source Han Serif SC",serif;font-size:clamp(23px,2.6vw,27px);font-weight:500;letter-spacing:.01em;line-height:1.4;min-height:50px;padding:0;resize:none;width:100%}.jio-creator__title textarea:focus{outline:0}.jio-creator__title textarea::-moz-placeholder{color:#b7c2bd}.jio-creator__title textarea::placeholder{color:#b7c2bd}.jio-creator__excerpt{display:block;margin-bottom:22px}.jio-creator__excerpt>span{color:#9aa8a2;display:block;font-size:12px;letter-spacing:.02em;margin-bottom:4px}.jio-creator__excerpt textarea{background:transparent;border:0;color:var(--jc-ink-soft);font-family:inherit;font-size:14px;line-height:1.7;padding:6px 0;resize:none;width:100%}.jio-creator__excerpt textarea:focus{outline:0}.jio-creator__editor{min-height:40vh;position:relative}.jio-creator__editor .block-editor-writing-flow{font-size:16px;letter-spacing:.01em;line-height:1.85}.jio-creator__editor .block-editor-default-block-appender textarea.block-editor-default-block-appender__content{color:#b7c2bd}.jio-creator__editor .block-editor-block-list__layout{padding-bottom:40px}.jio-creator__editor .wp-block{max-width:none}.jio-creator__editor .block-editor-block-list__block{margin-bottom:1.1em;margin-top:0}.jio-creator__editor .block-editor-block-list__block[data-type="core/heading"]{margin-top:1.6em}.jio-creator__editor .block-editor-block-list__block.is-hovered:after,.jio-creator__editor .block-editor-block-list__block.is-selected:after{border-radius:3px;box-shadow:0 0 0 1.5px rgba(38,118,101,.35)}.jio-creator__editor .block-editor-block-contextual-toolbar{margin-left:0}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar{background:#2b3733;border:0;border-radius:8px;box-shadow:0 6px 20px rgba(20,32,28,.22)}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-toolbar,.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-toolbar-group{border:0}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button{color:hsla(0,0%,100%,.86)}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button:focus:not(:disabled),.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button:hover:not(:disabled){background:hsla(0,0%,100%,.12);color:#fff}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button.is-pressed,.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button[aria-pressed=true]{background:hsla(0,0%,100%,.2);color:#fff}.jio-creator__footer{border-top:1px solid var(--jc-line);color:var(--jc-ink-soft);display:flex;font-size:12px;justify-content:space-between;padding-top:20px}.jio-creator__cover{margin-bottom:18px;position:relative}.jio-creator__cover.is-empty{align-items:center;background:transparent;border:1px dashed #d3ded8;border-radius:8px;color:#8c9a94;cursor:pointer;display:inline-flex;font-size:12px;gap:7px;min-height:32px;padding:0 12px;transition:border-color .16s ease,color .16s ease}.jio-creator__cover.is-empty:focus-visible,.jio-creator__cover.is-empty:hover{border-color:var(--jc-accent);color:var(--jc-accent-strong);outline:0}.jio-creator__cover-thumb{background:#eef3f0;border:0;border-radius:10px;cursor:pointer;display:block;overflow:hidden;padding:0;position:relative;width:100%}.jio-creator__cover-thumb img{aspect-ratio:2.35/1;display:block;-o-object-fit:cover;object-fit:cover;width:100%}.jio-creator__cover-thumb:focus-visible{outline:2px solid var(--jc-accent);outline-offset:2px}.jio-creator__cover-edit{align-items:center;background:linear-gradient(0deg,rgba(15,25,22,.62),rgba(15,25,22,0));color:#fff;display:flex;font-size:12px;gap:6px;inset:auto 0 0 0;justify-content:center;opacity:0;padding:8px;position:absolute;transition:opacity .16s ease}.jio-creator__cover-thumb:focus-visible .jio-creator__cover-edit,.jio-creator__cover-thumb:hover .jio-creator__cover-edit{opacity:1}.jio-creator__cover-clear{background:rgba(15,25,22,.55);border:0;border-radius:50%;color:#fff;cursor:pointer;height:28px;position:absolute;right:8px;top:8px;width:28px}.jio-creator__cover-clear:focus-visible,.jio-creator__cover-clear:hover{background:rgba(15,25,22,.78);outline:0}.jio-creator__editor .wp-block-image,.jio-page-submit .entry-content .wp-block-image{margin-left:auto;margin-right:auto}.jio-creator__editor .wp-block-image img,.jio-page-submit .entry-content .wp-block-image img{border-radius:6px;display:block;height:auto;width:100%}.jio-creator__editor .wp-block-image.jio-img-w--half,.jio-page-submit .entry-content .wp-block-image.jio-img-w--half{margin-left:0;margin-right:auto;width:50%}@media(max-width:767px){.jio-creator__editor .wp-block-image.jio-img-w--half,.jio-page-submit .entry-content .wp-block-image.jio-img-w--half{margin-left:auto;width:100%}}.jio-creator__editor .wp-block-image.jio-img-w--medium,.jio-page-submit .entry-content .wp-block-image.jio-img-w--medium{width:72%}.jio-creator__editor .wp-block-image.jio-img-w--wide,.jio-page-submit .entry-content .wp-block-image.jio-img-w--wide{width:100%}.jio-creator__editor .wp-block-image.jio-img-w--full,.jio-page-submit .entry-content .wp-block-image.jio-img-w--full{margin-left:calc(clamp(24px,6vw,64px)/-2);max-width:none;width:calc(100% + clamp(24px,6vw,64px))}@media(max-width:767px){.jio-creator__editor .wp-block-image.jio-img-w--full,.jio-page-submit .entry-content .wp-block-image.jio-img-w--full{margin-left:0;width:100%}}.jio-creator__author{align-items:center;color:#8c9a94;display:flex;font-size:12px;gap:8px;margin:2px 0 20px}.jio-creator__author-avatar{border-radius:50%;flex:0 0 auto;height:24px;-o-object-fit:cover;object-fit:cover;width:24px}.jio-creator__author-avatar.is-placeholder{align-items:center;background:#e3ece7;color:#4a5f57;display:inline-flex;font-size:11px;font-weight:600;justify-content:center}.jio-creator__author-name{color:#4a5f57;font-weight:500}.jio-creator__author-meta{background:#eef5f2;border-radius:4px;color:#3c7d6c;font-size:11px;padding:1px 6px}.jio-creator__author-hint{color:#b0bcb7;margin-left:auto}.jio-creator__insert{align-items:center;background:transparent;border:1px dashed #d3ded8;border-radius:10px;color:#7c8c86;cursor:pointer;display:flex;font-size:14px;gap:8px;justify-content:center;margin:8px 0 26px;min-height:46px;transition:border-color .18s ease,color .18s ease,background .18s ease;width:100%}.jio-creator__insert i{font-size:12px}.jio-creator__insert:focus-visible,.jio-creator__insert:hover{background:#f1f7f4;border-color:var(--jc-accent);color:var(--jc-accent-strong);outline:0}.jio-insert{align-items:center;display:flex;inset:0;justify-content:center;padding:20px;position:fixed;z-index:520}.jio-insert__backdrop{background:rgba(23,34,31,.34);border:0;cursor:default;inset:0;position:absolute}.jio-insert__panel{background:#fff;border-radius:16px;box-shadow:0 24px 70px rgba(20,32,28,.22);max-height:min(78vh,640px);overflow:hidden auto;position:relative;width:min(560px,100%)}.jio-insert__head{align-items:center;background:#fff;border-bottom:1px solid #e2e9e5;display:flex;justify-content:space-between;padding:18px 22px 12px;position:sticky;top:0;z-index:1}.jio-insert__head h2{font-size:16px;font-weight:600;margin:0}.jio-insert__close{background:transparent;border:0;border-radius:50%;color:#5c6b66;cursor:pointer;height:30px;width:30px}.jio-insert__close:focus-visible,.jio-insert__close:hover{background:#eef3f0;outline:0}.jio-insert__body{padding:16px 22px 24px}.jio-insert__group{margin-bottom:20px}.jio-insert__group h3{color:#9aa8a2;font-size:12px;font-weight:500;letter-spacing:.04em;margin:0 0 12px}.jio-insert__grid{display:grid;gap:8px;grid-template-columns:repeat(6,minmax(0,1fr))}.jio-insert-item{align-items:center;background:#f7f9f8;border:1px solid transparent;border-radius:10px;color:#243330;cursor:pointer;display:flex;flex-direction:column;gap:8px;justify-content:center;padding:14px 4px 10px;transition:background .16s ease,color .16s ease,border-color .16s ease}.jio-insert-item:focus-visible,.jio-insert-item:hover{background:#eef5f2;border-color:var(--jc-accent);color:var(--jc-accent-strong);outline:0}.jio-insert-item__icon{align-items:center;background:#fff;border-radius:8px;display:flex;font-size:15px;height:30px;justify-content:center;width:30px}.jio-insert-item__label{font-size:12px;line-height:1.3;text-align:center}.jio-creator-drawer{display:flex;inset:0;justify-content:flex-end;position:fixed;z-index:500}.jio-creator-drawer__backdrop{background:rgba(23,34,31,.32);border:0;cursor:default;inset:0;position:absolute}.jio-creator-drawer__panel{background:#fff;box-shadow:-20px 0 60px rgba(20,32,28,.16);display:flex;flex-direction:column;height:100%;position:relative;width:min(460px,100%)}.jio-creator-drawer__head{align-items:center;border-bottom:1px solid #e2e9e5;display:flex;justify-content:space-between;padding:20px 24px}.jio-creator-drawer__head h2{font-size:17px;font-weight:600;margin:0}.jio-creator-drawer__close{background:transparent;border:0;color:#5c6b66;cursor:pointer}.jio-creator-drawer__body{flex:1;overflow-y:auto;padding:20px 24px 32px}.jio-creator-drawer__note{background:#f2f7f4;border-left:3px solid #267665;color:#5c6b66;font-size:13px;line-height:1.6;margin:0 0 20px;padding:12px 14px}.jio-creator-drawer__foot{background:#fff;border-top:1px solid #e2e9e5;display:flex;flex-direction:column;gap:12px;padding:16px 24px calc(16px + env(safe-area-inset-bottom))}.jio-creator-drawer__foot .jio-creator-primary{flex:1}.jio-creator-drawer__actions{align-items:center;display:flex;gap:12px}.jio-creator-drawer__captcha{min-height:40px}.jio-creator-field{margin-bottom:26px}.jio-creator-field>h3{color:#243330;font-size:13px;font-weight:600;margin:0 0 10px}.jio-creator-muted{color:#5c6b66;font-size:12px;line-height:1.6;margin:0}.jio-creator-error{color:#b4573f;font-size:12px;margin:8px 0 0}.jio-creator-chips{display:flex;flex-wrap:wrap;gap:8px}.jio-creator-chip{align-items:center;border:1px solid #e2e9e5;border-radius:999px;color:#5c6b66;cursor:pointer;display:inline-flex;font-size:13px;gap:6px;padding:5px 12px}.jio-creator-chip input{clip:rect(0,0,0,0);height:1px;overflow:hidden;position:absolute;width:1px}.jio-creator-chip.is-active{background:#eef5f2;border-color:#267665;color:#1d5f52}.jio-creator-chip button{background:transparent;border:0;color:inherit;cursor:pointer}.jio-creator-inline{display:flex;gap:8px;margin-top:10px}.jio-creator-inline input:not([type]),.jio-creator-inline input[type=text]{border:1px solid #e2e9e5;border-radius:8px;flex:1;height:36px;min-width:0;padding:0 12px}.jio-creator-inline label{align-items:center;display:inline-flex;font-size:13px;gap:6px}.jio-creator-switch{align-items:flex-start;display:flex;gap:16px;justify-content:space-between}.jio-creator-switch h3{font-size:13px;margin:0 0 4px}.jio-creator-toggle{flex:0 0 auto;position:relative}.jio-creator-toggle input{height:1px;opacity:0;position:absolute;width:1px}.jio-creator-toggle span{background:#d6dfda;border-radius:999px;display:block;height:24px;transition:background .18s ease;width:42px}.jio-creator-toggle span:after{background:#fff;border-radius:50%;content:"";display:block;height:18px;margin:3px;transition:transform .18s ease;width:18px}.jio-creator-toggle input:checked+span{background:#267665}.jio-creator-toggle input:checked+span:after{transform:translateX(18px)}.jio-creator-toggle input:focus-visible+span{outline:2px solid #267665;outline-offset:2px}.jio-creator-pay{background:#fcfdfc;border:1px solid #e2e9e5;border-radius:10px;margin-top:16px;padding:16px}.jio-creator-input{align-items:center;display:flex;font-size:13px;gap:12px;justify-content:space-between;margin-top:12px}.jio-creator-input input{border:1px solid #e2e9e5;border-radius:8px;height:36px;padding:0 12px;text-align:right;width:140px}.jio-creator-cover{border-radius:10px;overflow:hidden;position:relative}.jio-creator-cover img{aspect-ratio:2/1;display:block;-o-object-fit:cover;object-fit:cover;width:100%}.jio-creator-cover button{background:rgba(0,0,0,.55);border:0;border-radius:50%;color:#fff;cursor:pointer;height:30px;position:absolute;right:8px;top:8px;width:30px}.jio-creator-cover-empty{align-items:center;background:#fafcfb;border:1px dashed #e2e9e5;border-radius:10px;color:#5c6b66;cursor:pointer;display:flex;flex-direction:column;font-size:13px;gap:8px;justify-content:center;min-height:120px}.jio-creator-cover-empty input{height:1px;opacity:0;position:absolute;width:1px}.jio-creator-attachments{border-top:1px solid #e2e9e5;margin-top:18px;padding-top:16px}.jio-creator-attachments__head{align-items:center;display:flex;gap:12px;justify-content:space-between}.jio-creator-attachments__head h4{font-size:13px;margin:0}.jio-creator-upload{align-items:center;border:1px solid #e2e9e5;border-radius:8px;color:#1d5f52;cursor:pointer;display:inline-flex;font-size:12px;min-height:32px;padding:0 12px}.jio-creator-upload input{height:1px;opacity:0;position:absolute;width:1px}.jio-creator-files{list-style:none;margin:12px 0 0;padding:0}.jio-creator-files li{align-items:center;border-bottom:1px solid #f0f4f1;display:flex;font-size:13px;gap:10px;padding:8px 0}.jio-creator-files button{background:transparent;border:0;color:#5c6b66;cursor:pointer;margin-left:auto}.jio-creator-files__name{align-items:center;display:inline-flex;gap:8px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.jio-creator-files__name i{color:#267665}.jio-creator-reuse{font-size:13px;margin-top:14px}.jio-creator-reuse summary{color:#5c6b66;cursor:pointer}.jio-creator-reuse ul{list-style:none;margin:10px 0 0;padding:0}.jio-creator-reuse li{align-items:center;display:flex;gap:10px;padding:6px 0}.jio-creator-reuse button{background:#fff;border:1px solid #e2e9e5;border-radius:6px;cursor:pointer;margin-left:auto}.jio-creator-link{background:transparent;border:0;color:var(--jc-ink-soft,#5c6b66);cursor:pointer;font-size:13px;text-decoration:underline}@media(max-width:767px){.jio-creator{--jc-bar:54px}.jio-creator__brand{display:none}.jio-creator__bar{gap:10px;padding:0 12px}.jio-creator__save time{display:none}.jio-creator__ghost{padding:0 10px}.jio-creator__primary{padding:0 14px}.jio-creator__canvas{padding:20px 16px calc(120px + env(safe-area-inset-bottom))}.jio-creator__title textarea{font-size:24px}.jio-creator__editor .block-editor-writing-flow{font-size:16px;line-height:1.8}.jio-creator__inspector{margin-top:16px}.jio-creator-drawer{display:block}.jio-creator-drawer__backdrop{display:none}.jio-creator-drawer__panel{border-radius:0;box-shadow:none;height:100dvh;width:100%}.jio-creator-drawer__foot{background:#fff;bottom:0;position:sticky}.jio-insert{align-items:flex-end;padding:0}.jio-insert__panel{border-radius:16px 16px 0 0;max-height:76dvh;padding-bottom:env(safe-area-inset-bottom);width:100%}.jio-insert__grid{grid-template-columns:repeat(4,minmax(0,1fr))}.jio-creator__insert{margin-bottom:calc(26px + env(safe-area-inset-bottom))}}@media(prefers-reduced-motion:reduce){.jio-creator *{animation:none!important;transition:none!important}} +.jio-page-submit{background:#fafbfa}body.jio-page-submit.has-static-nav,body.jio-page-submit.nav-fixed{padding-top:0!important}.jio-page-submit .float-btn,.jio-page-submit .footer,.jio-page-submit .footer-tabbar,.jio-page-submit .header,.jio-page-submit .jio-float-buttons{display:none!important}.jio-page-submit #main-content.container{max-width:none;padding:0}#jio-creator-studio.is-ready{display:block}.jio-creator{--jc-ink:#243330;--jc-ink-soft:#5c6b66;--jc-paper:#fafbfa;--jc-line:#e2e9e5;--jc-accent:#267665;--jc-accent-strong:#1d5f52;--jc-warn:#b4573f;--jc-bar:60px;-webkit-font-smoothing:antialiased;background:var(--jc-paper);color:var(--jc-ink);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Noto Sans SC,PingFang SC,Microsoft YaHei,sans-serif;min-height:100vh;min-height:100dvh;padding-top:var(--jc-bar)}.jio-creator *,.jio-creator :after,.jio-creator :before{box-sizing:border-box}.jio-creator button{color:inherit;font:inherit}.jio-creator__bar{align-items:center;backdrop-filter:blur(14px);background:rgba(250,251,250,.97);border-bottom:1px solid var(--jc-line);box-shadow:0 2px 8px rgba(27,46,39,.035);display:flex;gap:20px;height:var(--jc-bar);justify-content:space-between;left:0;padding:0 clamp(16px,3vw,34px);position:fixed;right:0;top:0;z-index:300}.jio-creator__bar-actions,.jio-creator__bar-center,.jio-creator__bar-left{align-items:center;display:flex;gap:12px;min-width:0}.jio-creator__bar-left{flex:0 0 auto}.jio-creator__bar-center{flex:1 1 auto;gap:14px;justify-content:center}.jio-creator__bar-actions{flex:0 0 auto;gap:8px}.jio-creator__back{align-items:center;border-radius:7px;color:var(--jc-ink-soft);display:inline-flex;height:30px;justify-content:center;text-decoration:none;width:30px}.jio-creator__back:focus-visible,.jio-creator__back:hover{background:#edf3f0;color:var(--jc-accent);outline:0}.jio-creator__bar-brand{color:var(--jc-accent-strong);font-family:Songti SC,"Noto Serif SC","Source Han Serif SC",serif;font-size:17px;font-weight:700;letter-spacing:-.04em}.jio-creator__bar-divider{background:var(--jc-line);height:18px;width:1px}.jio-creator__bar-mode{color:var(--jc-ink-soft);font-size:13px}.jio-creator__doc-title{color:#65736d;font-size:13px;max-width:min(32vw,360px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.jio-creator__icon-btn{align-items:center;background:transparent;border:0;border-radius:7px;color:var(--jc-ink-soft);cursor:pointer;display:inline-flex;height:32px;justify-content:center;width:32px}.jio-creator__icon-btn:focus-visible:not(:disabled),.jio-creator__icon-btn:hover:not(:disabled){background:#edf3f0;color:var(--jc-accent-strong);outline:0}.jio-creator__icon-btn:disabled{color:#c7d0cc;cursor:default}.jio-creator__history{align-items:center;border-right:1px solid var(--jc-line);display:inline-flex;gap:2px;padding-right:8px}.jio-creator__save-draft{background:#fff;border-color:var(--jc-line);color:var(--jc-ink-soft)}.jio-creator__save-draft:focus-visible,.jio-creator__save-draft:hover{background:#f7faf8;border-color:#b7cdc3;color:var(--jc-accent-strong)}.jio-creator__save{align-items:center;color:var(--jc-ink-soft);display:inline-flex;font-size:13px;gap:6px}.jio-creator__save>i{color:var(--jc-line);font-size:7px}.jio-creator__save time{font-variant-numeric:tabular-nums;opacity:.7}.jio-creator__save.is-saved>i{color:var(--jc-accent)}.jio-creator__save.is-conflict,.jio-creator__save.is-conflict>i,.jio-creator__save.is-error,.jio-creator__save.is-error>i{color:var(--jc-warn)}.jio-creator__btn,.jio-creator__ghost,.jio-creator__primary{align-items:center;border:1px solid transparent;border-radius:8px;cursor:pointer;display:inline-flex;font-size:14px;justify-content:center;min-height:36px;padding:0 16px;transition:background .18s ease,border-color .18s ease,color .18s ease}.jio-creator__ghost{background:transparent;border-color:var(--jc-line)}.jio-creator__ghost:focus-visible,.jio-creator__ghost:hover{border-color:var(--jc-accent);color:var(--jc-accent)}.jio-creator__primary{background:var(--jc-accent);color:#fff}.jio-creator__primary:focus-visible,.jio-creator__primary:hover{background:var(--jc-accent-strong)}.jio-creator__primary:disabled{cursor:not-allowed;opacity:.5}.jio-creator__notice{align-items:center;background:#f1f5f2;border-bottom:1px solid var(--jc-line);color:var(--jc-ink-soft);display:flex;font-size:13px;gap:12px;margin:0 auto;max-width:820px;padding:10px 16px}.jio-creator__notice>span{flex:1}.jio-creator__notice button{background:transparent;border:0;color:var(--jc-accent);cursor:pointer}.jio-creator__notice.is-error{background:#fdf2ee;color:var(--jc-warn)}.jio-creator__hint{color:var(--jc-ink-soft);font-size:13px;margin:18px auto 0;max-width:820px;padding:0 clamp(16px,4vw,40px)}.jio-creator__canvas{margin:0 auto;padding:clamp(20px,4vw,44px) clamp(20px,5vw,52px) 140px;width:min(720px,100%)}.jio-creator__title{display:block;margin-bottom:6px}.jio-creator__title textarea{background:transparent;border:0;color:var(--jc-ink);font-family:Songti SC,"Noto Serif SC","Source Han Serif SC",serif;font-size:clamp(23px,2.6vw,27px);font-weight:500;letter-spacing:.01em;line-height:1.4;min-height:50px;padding:0;resize:none;width:100%}.jio-creator__title textarea:focus{outline:0}.jio-creator__title textarea::-moz-placeholder{color:#b7c2bd}.jio-creator__title textarea::placeholder{color:#b7c2bd}.jio-creator__excerpt{display:block;margin-bottom:22px}.jio-creator__excerpt>span{color:#9aa8a2;display:block;font-size:12px;letter-spacing:.02em;margin-bottom:4px}.jio-creator__excerpt textarea{background:transparent;border:0;color:var(--jc-ink-soft);font-family:inherit;font-size:14px;line-height:1.7;padding:6px 0;resize:none;width:100%}.jio-creator__excerpt textarea:focus{outline:0}.jio-creator__editor{min-height:40vh;position:relative}.jio-creator__editor .block-editor-writing-flow{font-size:16px;letter-spacing:.01em;line-height:1.85}.jio-creator__editor .block-editor-default-block-appender textarea.block-editor-default-block-appender__content{color:#b7c2bd}.jio-creator__editor .block-editor-block-list__layout{padding-bottom:40px}.jio-creator__editor .wp-block{max-width:none}.jio-creator__editor .block-editor-block-list__block{margin-bottom:1.1em;margin-top:0}.jio-creator__editor .block-editor-block-list__block[data-type="core/heading"]{margin-top:1.6em}.jio-creator__editor .block-editor-block-list__block.is-hovered:after,.jio-creator__editor .block-editor-block-list__block.is-selected:after{border-radius:3px;box-shadow:0 0 0 1.5px rgba(38,118,101,.35)}.jio-creator__editor .block-editor-block-contextual-toolbar{margin-left:0}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar{background:#2b3733;border:0;border-radius:8px;box-shadow:0 6px 20px rgba(20,32,28,.22)}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-toolbar,.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-toolbar-group{border:0}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button{color:hsla(0,0%,100%,.86)}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button:focus:not(:disabled),.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button:hover:not(:disabled){background:hsla(0,0%,100%,.12);color:#fff}.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button.is-pressed,.jio-creator__editor .block-editor-block-contextual-toolbar .block-editor-block-toolbar .components-button[aria-pressed=true]{background:hsla(0,0%,100%,.2);color:#fff}.jio-creator__footer{border-top:1px solid var(--jc-line);color:var(--jc-ink-soft);display:flex;font-size:12px;justify-content:space-between;padding-top:20px}.jio-creator__cover{margin-bottom:18px;position:relative}.jio-creator__cover.is-empty{align-items:center;background:transparent;border:1px dashed #d3ded8;border-radius:8px;color:#8c9a94;cursor:pointer;display:inline-flex;font-size:12px;gap:7px;min-height:32px;padding:0 12px;transition:border-color .16s ease,color .16s ease}.jio-creator__cover.is-empty:focus-visible,.jio-creator__cover.is-empty:hover{border-color:var(--jc-accent);color:var(--jc-accent-strong);outline:0}.jio-creator__cover-thumb{background:#eef3f0;border:0;border-radius:10px;cursor:pointer;display:block;overflow:hidden;padding:0;position:relative;width:100%}.jio-creator__cover-thumb img{aspect-ratio:2.35/1;display:block;-o-object-fit:cover;object-fit:cover;width:100%}.jio-creator__cover-thumb:focus-visible{outline:2px solid var(--jc-accent);outline-offset:2px}.jio-creator__cover-edit{align-items:center;background:linear-gradient(0deg,rgba(15,25,22,.62),rgba(15,25,22,0));color:#fff;display:flex;font-size:12px;gap:6px;inset:auto 0 0 0;justify-content:center;opacity:0;padding:8px;position:absolute;transition:opacity .16s ease}.jio-creator__cover-thumb:focus-visible .jio-creator__cover-edit,.jio-creator__cover-thumb:hover .jio-creator__cover-edit{opacity:1}.jio-creator__cover-clear{background:rgba(15,25,22,.55);border:0;border-radius:50%;color:#fff;cursor:pointer;height:28px;position:absolute;right:8px;top:8px;width:28px}.jio-creator__cover-clear:focus-visible,.jio-creator__cover-clear:hover{background:rgba(15,25,22,.78);outline:0}.jio-creator__editor .wp-block-image,.jio-page-submit .entry-content .wp-block-image{margin-left:auto;margin-right:auto}.jio-creator__editor .wp-block-image img,.jio-page-submit .entry-content .wp-block-image img{border-radius:6px;display:block;height:auto;width:100%}.jio-creator__editor .wp-block-image.jio-img-w--half,.jio-page-submit .entry-content .wp-block-image.jio-img-w--half{margin-left:0;margin-right:auto;width:50%}@media(max-width:767px){.jio-creator__editor .wp-block-image.jio-img-w--half,.jio-page-submit .entry-content .wp-block-image.jio-img-w--half{margin-left:auto;width:100%}}.jio-creator__editor .wp-block-image.jio-img-w--medium,.jio-page-submit .entry-content .wp-block-image.jio-img-w--medium{width:72%}.jio-creator__editor .wp-block-image.jio-img-w--wide,.jio-page-submit .entry-content .wp-block-image.jio-img-w--wide{width:100%}.jio-creator__editor .wp-block-image.jio-img-w--full,.jio-page-submit .entry-content .wp-block-image.jio-img-w--full{margin-left:calc(clamp(24px,6vw,64px)/-2);max-width:none;width:calc(100% + clamp(24px,6vw,64px))}@media(max-width:767px){.jio-creator__editor .wp-block-image.jio-img-w--full,.jio-page-submit .entry-content .wp-block-image.jio-img-w--full{margin-left:0;width:100%}}.jio-creator__author{align-items:center;color:#8c9a94;display:flex;font-size:12px;gap:8px;margin:2px 0 20px}.jio-creator__author-avatar{border-radius:50%;flex:0 0 auto;height:24px;-o-object-fit:cover;object-fit:cover;width:24px}.jio-creator__author-avatar.is-placeholder{align-items:center;background:#e3ece7;color:#4a5f57;display:inline-flex;font-size:11px;font-weight:600;justify-content:center}.jio-creator__author-name{color:#4a5f57;font-weight:500}.jio-creator__author-meta{background:#eef5f2;border-radius:4px;color:#3c7d6c;font-size:11px;padding:1px 6px}.jio-creator__author-hint{color:#b0bcb7;margin-left:auto}.jio-creator__insert{align-items:center;background:transparent;border:1px dashed #d3ded8;border-radius:10px;color:#7c8c86;cursor:pointer;display:flex;font-size:14px;gap:8px;justify-content:center;margin:8px 0 26px;min-height:46px;transition:border-color .18s ease,color .18s ease,background .18s ease;width:100%}.jio-creator__insert i{font-size:12px}.jio-creator__insert:focus-visible,.jio-creator__insert:hover{background:#f1f7f4;border-color:var(--jc-accent);color:var(--jc-accent-strong);outline:0}.jio-insert{align-items:center;display:flex;inset:0;justify-content:center;padding:20px;position:fixed;z-index:520}.jio-insert__backdrop{background:rgba(23,34,31,.34);border:0;cursor:default;inset:0;position:absolute}.jio-insert__panel{background:#fff;border-radius:16px;box-shadow:0 24px 70px rgba(20,32,28,.22);max-height:min(78vh,640px);overflow:hidden auto;position:relative;width:min(560px,100%)}.jio-insert__head{align-items:center;background:#fff;border-bottom:1px solid #e2e9e5;display:flex;justify-content:space-between;padding:18px 22px 12px;position:sticky;top:0;z-index:1}.jio-insert__head h2{font-size:16px;font-weight:600;margin:0}.jio-insert__close{background:transparent;border:0;border-radius:50%;color:#5c6b66;cursor:pointer;height:30px;width:30px}.jio-insert__close:focus-visible,.jio-insert__close:hover{background:#eef3f0;outline:0}.jio-insert__body{padding:16px 22px 24px}.jio-insert__group{margin-bottom:20px}.jio-insert__group h3{color:#9aa8a2;font-size:12px;font-weight:500;letter-spacing:.04em;margin:0 0 12px}.jio-insert__grid{display:grid;gap:8px;grid-template-columns:repeat(6,minmax(0,1fr))}.jio-insert-item{align-items:center;background:#f7f9f8;border:1px solid transparent;border-radius:10px;color:#243330;cursor:pointer;display:flex;flex-direction:column;gap:8px;justify-content:center;padding:14px 4px 10px;transition:background .16s ease,color .16s ease,border-color .16s ease}.jio-insert-item:focus-visible,.jio-insert-item:hover{background:#eef5f2;border-color:var(--jc-accent);color:var(--jc-accent-strong);outline:0}.jio-insert-item__icon{align-items:center;background:#fff;border-radius:8px;display:flex;font-size:15px;height:30px;justify-content:center;width:30px}.jio-insert-item__label{font-size:12px;line-height:1.3;text-align:center}.jio-creator-drawer{display:flex;inset:0;justify-content:flex-end;position:fixed;z-index:500}.jio-creator-drawer__backdrop{background:rgba(23,34,31,.32);border:0;cursor:default;inset:0;position:absolute}.jio-creator-drawer__panel{background:#fff;box-shadow:-20px 0 60px rgba(20,32,28,.16);display:flex;flex-direction:column;height:100%;position:relative;width:min(460px,100%)}.jio-creator-drawer__head{align-items:center;border-bottom:1px solid #e2e9e5;display:flex;justify-content:space-between;padding:20px 24px}.jio-creator-drawer__head h2{font-size:17px;font-weight:600;margin:0}.jio-creator-drawer__close{background:transparent;border:0;color:#5c6b66;cursor:pointer}.jio-creator-drawer__body{flex:1;overflow-y:auto;padding:20px 24px 32px}.jio-creator-drawer__note{background:#f2f7f4;border-left:3px solid #267665;color:#5c6b66;font-size:13px;line-height:1.6;margin:0 0 20px;padding:12px 14px}.jio-creator-drawer__foot{background:#fff;border-top:1px solid #e2e9e5;display:flex;flex-direction:column;gap:12px;padding:16px 24px calc(16px + env(safe-area-inset-bottom))}.jio-creator-drawer__foot .jio-creator-primary{flex:1}.jio-creator-drawer__actions{align-items:center;display:flex;gap:12px}.jio-creator-drawer__captcha{min-height:40px}.jio-creator-field{margin-bottom:26px}.jio-creator-field>h3{color:#243330;font-size:13px;font-weight:600;margin:0 0 10px}.jio-creator-muted{color:#5c6b66;font-size:12px;line-height:1.6;margin:0}.jio-creator-error{color:#b4573f;font-size:12px;margin:8px 0 0}.jio-creator-chips{display:flex;flex-wrap:wrap;gap:8px}.jio-creator-chip{align-items:center;border:1px solid #e2e9e5;border-radius:999px;color:#5c6b66;cursor:pointer;display:inline-flex;font-size:13px;gap:6px;padding:5px 12px}.jio-creator-chip input{clip:rect(0,0,0,0);height:1px;overflow:hidden;position:absolute;width:1px}.jio-creator-chip.is-active{background:#eef5f2;border-color:#267665;color:#1d5f52}.jio-creator-chip button{background:transparent;border:0;color:inherit;cursor:pointer}.jio-creator-inline{display:flex;gap:8px;margin-top:10px}.jio-creator-inline input:not([type]),.jio-creator-inline input[type=text]{border:1px solid #e2e9e5;border-radius:8px;flex:1;height:36px;min-width:0;padding:0 12px}.jio-creator-inline label{align-items:center;display:inline-flex;font-size:13px;gap:6px}.jio-creator-switch{align-items:flex-start;display:flex;gap:16px;justify-content:space-between}.jio-creator-switch h3{font-size:13px;margin:0 0 4px}.jio-creator-toggle{flex:0 0 auto;position:relative}.jio-creator-toggle input{height:1px;opacity:0;position:absolute;width:1px}.jio-creator-toggle span{background:#d6dfda;border-radius:999px;display:block;height:24px;transition:background .18s ease;width:42px}.jio-creator-toggle span:after{background:#fff;border-radius:50%;content:"";display:block;height:18px;margin:3px;transition:transform .18s ease;width:18px}.jio-creator-toggle input:checked+span{background:#267665}.jio-creator-toggle input:checked+span:after{transform:translateX(18px)}.jio-creator-toggle input:focus-visible+span{outline:2px solid #267665;outline-offset:2px}.jio-creator-pay{background:#fcfdfc;border:1px solid #e2e9e5;border-radius:10px;margin-top:16px;padding:16px}.jio-creator-input{align-items:center;display:flex;font-size:13px;gap:12px;justify-content:space-between;margin-top:12px}.jio-creator-input input{border:1px solid #e2e9e5;border-radius:8px;height:36px;padding:0 12px;text-align:right;width:140px}.jio-creator-cover{border-radius:10px;overflow:hidden;position:relative}.jio-creator-cover img{aspect-ratio:2/1;display:block;-o-object-fit:cover;object-fit:cover;width:100%}.jio-creator-cover button{background:rgba(0,0,0,.55);border:0;border-radius:50%;color:#fff;cursor:pointer;height:30px;position:absolute;right:8px;top:8px;width:30px}.jio-creator-cover-empty{align-items:center;background:#fafcfb;border:1px dashed #e2e9e5;border-radius:10px;color:#5c6b66;cursor:pointer;display:flex;flex-direction:column;font-size:13px;gap:8px;justify-content:center;min-height:120px}.jio-creator-cover-empty input{height:1px;opacity:0;position:absolute;width:1px}.jio-creator-attachments{border-top:1px solid #e2e9e5;margin-top:18px;padding-top:16px}.jio-creator-attachments__head{align-items:center;display:flex;gap:12px;justify-content:space-between}.jio-creator-attachments__head h4{font-size:13px;margin:0}.jio-creator-upload{align-items:center;border:1px solid #e2e9e5;border-radius:8px;color:#1d5f52;cursor:pointer;display:inline-flex;font-size:12px;min-height:32px;padding:0 12px}.jio-creator-upload input{height:1px;opacity:0;position:absolute;width:1px}.jio-creator-files{list-style:none;margin:12px 0 0;padding:0}.jio-creator-files li{align-items:center;border-bottom:1px solid #f0f4f1;display:flex;font-size:13px;gap:10px;padding:8px 0}.jio-creator-files button{background:transparent;border:0;color:#5c6b66;cursor:pointer;margin-left:auto}.jio-creator-files__name{align-items:center;display:inline-flex;gap:8px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.jio-creator-files__name i{color:#267665}.jio-creator-reuse{font-size:13px;margin-top:14px}.jio-creator-reuse summary{color:#5c6b66;cursor:pointer}.jio-creator-reuse ul{list-style:none;margin:10px 0 0;padding:0}.jio-creator-reuse li{align-items:center;display:flex;gap:10px;padding:6px 0}.jio-creator-reuse button{background:#fff;border:1px solid #e2e9e5;border-radius:6px;cursor:pointer;margin-left:auto}.jio-creator-link{background:transparent;border:0;color:var(--jc-ink-soft,#5c6b66);cursor:pointer;font-size:13px;text-decoration:underline}@media(max-width:767px){.jio-creator{--jc-bar:56px}.jio-creator__bar{gap:8px;padding:0 10px}.jio-creator__bar-actions,.jio-creator__bar-center,.jio-creator__bar-left{gap:6px}.jio-creator__bar-brand{font-size:15px}.jio-creator__bar-divider,.jio-creator__bar-mode,.jio-creator__doc-title,.jio-creator__save-draft{display:none}.jio-creator__bar-center{flex:0 0 auto;justify-content:flex-start}.jio-creator__bar-actions{flex:1 1 auto;justify-content:flex-end}.jio-creator__icon-btn{height:30px;width:28px}.jio-creator__history{gap:0;padding-right:4px}.jio-creator__preview{font-size:12px;min-height:32px;padding:0 9px}.jio-creator__primary{font-size:13px;min-height:32px;padding:0 12px}.jio-creator__save time{display:none}.jio-creator__ghost{padding:0 10px}.jio-creator__primary{padding:0 14px}.jio-creator__canvas{padding:20px 16px calc(120px + env(safe-area-inset-bottom))}.jio-creator__title textarea{font-size:24px}.jio-creator__editor .block-editor-writing-flow{font-size:16px;line-height:1.8}.jio-creator__inspector{margin-top:16px}.jio-creator-drawer{display:block}.jio-creator-drawer__backdrop{display:none}.jio-creator-drawer__panel{border-radius:0;box-shadow:none;height:100dvh;width:100%}.jio-creator-drawer__foot{background:#fff;bottom:0;position:sticky}.jio-insert{align-items:flex-end;padding:0}.jio-insert__panel{border-radius:16px 16px 0 0;max-height:76dvh;padding-bottom:env(safe-area-inset-bottom);width:100%}.jio-insert__grid{grid-template-columns:repeat(4,minmax(0,1fr))}.jio-creator__insert{margin-bottom:calc(26px + env(safe-area-inset-bottom))}}@media(prefers-reduced-motion:reduce){.jio-creator *{animation:none!important;transition:none!important}} diff --git a/assets/creator-studio/build/index.js b/assets/creator-studio/build/index.js index 4747bdd4..e374a633 100644 --- a/assets/creator-studio/build/index.js +++ b/assets/creator-studio/build/index.js @@ -1 +1 @@ -(()=>{"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,l=window.wp.wordcount,c=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.wp.hooks,b=window.wp.compose,y=window.wp.components,E=[{key:"half",label:(0,c.__)("半屏","jio"),className:"jio-img-w--half"},{key:"medium",label:(0,c.__)("中等","jio"),className:"jio-img-w--medium"},{key:"wide",label:(0,c.__)("通栏","jio"),className:"jio-img-w--wide"},{key:"full",label:(0,c.__)("全宽","jio"),className:"jio-img-w--full"}];function j(e){return a=>{if("core/image"!==a.name)return(0,t.createElement)(e,{...a});const r=String(a.attributes?.className||""),n=function(e){const t=E.find(t=>(e||"").split(/\s+/).includes(t.className));return t?t.key:"wide"}(r);return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(e,{...a}),(0,t.createElement)(i.BlockControls,{group:"inline"},(0,t.createElement)(y.ToolbarGroup,{controls:E.map(e=>({title:e.label,children:e.label,isActive:n===e.key,onClick:()=>(e=>{const t=r.split(/\s+/).filter(e=>e&&!E.some(t=>t.className===e));a.setAttributes({className:[...t,e.className].join(" ")})})(e)}))})))}}const g=window.jioCreatorStudio||{},h=g.nonce||"";function w(e){const{draft:r,setDraft:n,capabilities:o,limits:i,taxonomy:l,isPublishedEdit:s,onClose:m,onSaveDraft:u,onSubmit:p,privateStorage:_,privateUploads:f,saving:b,captcha:y}=e,[E,j]=(0,a.useState)(""),[w,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=E.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]))}),j("")};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,c.__)("关闭","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,c.__)("提交改稿","jio"):(0,c.__)("发布文章","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator-drawer__close",onClick:m,"aria-label":(0,c.__)("关闭","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,c.__)("审核通过前,读者看到的仍然是当前线上版本。","jio")),(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("h3",null,(0,c.__)("封面","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,c.__)("移除封面","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&&g.media?.uploadUrl?.image){v(""),k(!0);try{const t=await d(g.media.uploadUrl.image,e,h),a=Number(t.attachment_id||t.id||0),r=String(t.url||"");if(!a||!r)throw new Error((0,c.__)("上传后无法读取图片。","jio"));n({featured:{type:"image",mediaId:a,data:{id:a,url:r}}})}catch(e){v(String(e?.message||(0,c.__)("上传失败","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,c.__)("上传中…","jio"):(0,c.__)("上传封面","jio"))):(0,t.createElement)("p",{className:"jio-creator-muted"},(0,c.__)("当前账号不能设置封面。","jio"))),(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("h3",null,(0,c.__)("分类","jio")),(0,t.createElement)("div",{className:"jio-creator-chips"},0===l.categories.length&&(0,t.createElement)("span",{className:"jio-creator-muted"},(0,c.__)("暂无可选分类","jio")),l.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))))),l.tags&&(0,t.createElement)("section",{className:"jio-creator-field"},(0,t.createElement)("h3",null,(0,c.__)("标签","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,c.sprintf)((0,c.__)("移除标签 %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:E,placeholder:(0,c.__)("输入标签,逗号分隔","jio"),onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),L())}}),(0,t.createElement)("button",{type:"button",onClick:L},(0,c.__)("添加","jio")))),l.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,c.__)("付费内容","jio")),(0,t.createElement)("p",{className:"jio-creator-muted"},(0,c.__)("开启后,未购买读者只能看到免费部分。","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,c.__)("现金","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,c.__)("积分","jio")))),"cash"===r.pay.modo?(0,t.createElement)("label",{className:"jio-creator-input"},(0,t.createElement)("span",null,(0,c.__)("价格","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,c.__)("积分价格","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,c.__)("资料附件","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(g.creator.privateUrl,e,h,{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,c.__)("资料上传失败","jio")))}finally{k(!1)}}})()},disabled:N}),(0,t.createElement)("span",null,N?(0,c.__)("上传中…","jio"):(0,c.__)("添加 PDF / ZIP","jio"))):(0,t.createElement)("p",{className:"jio-creator-muted"},(0,c.__)("私有附件存储尚未配置,暂时不能上传付费资料。","jio"))),w&&(0,t.createElement)("p",{className:"jio-creator-error"},w),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,c.__)("受保护资料","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,c.__)("移除","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))))),f.length>0&&(0,t.createElement)("details",{className:"jio-creator-reuse"},(0,t.createElement)("summary",null,(0,c.__)("从已上传资料中选择","jio")),(0,t.createElement)("ul",null,f.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,c.__)("使用","jio"))))))))),!o.canPay&&o.canSaveDraft&&(0,t.createElement)("p",{className:"jio-creator-muted"},(0,c.__)("当前账号不能设置付费内容。","jio"))),(0,t.createElement)("footer",{className:"jio-creator-drawer__foot"},y&&(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:b},(0,c.__)("保存草稿","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator-primary",onClick:()=>p(!1),disabled:b||!x},s?(0,c.__)("提交审核","jio"):o.canPublishNow?(0,c.__)("发布","jio"):(0,c.__)("提交审核","jio")),o.canPublishNow&&(0,t.createElement)("button",{type:"button",className:"jio-creator-link",onClick:()=>p(!0),disabled:b||!x},(0,c.__)("立即发布","jio"))))))}function v({featured:e,canEdit:a,onOpen:r,onClear:n}){const o="string"==typeof e?.data?.url?e.data.url:"";return a?o?(0,t.createElement)("div",{className:"jio-creator__cover"},(0,t.createElement)("button",{type:"button",className:"jio-creator__cover-thumb",onClick:r},(0,t.createElement)("img",{src:o,alt:""}),(0,t.createElement)("span",{className:"jio-creator__cover-edit"},(0,t.createElement)("i",{className:"fa fas fa-pen","aria-hidden":"true"}),(0,c.__)("更换封面","jio"))),(0,t.createElement)("button",{type:"button",className:"jio-creator__cover-clear",onClick:n,"aria-label":(0,c.__)("移除封面","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))):(0,t.createElement)("button",{type:"button",className:"jio-creator__cover is-empty",onClick:r},(0,t.createElement)("i",{className:"fa far fa-image","aria-hidden":"true"}),(0,t.createElement)("span",null,(0,c.__)("添加封面","jio"))):null}function N({author:e}){const a="string"==typeof e?.name?e.name.trim():"";if(""===a)return null;const r="string"==typeof e?.avatar?e.avatar:"",n="string"==typeof e?.meta?e.meta:"";return(0,t.createElement)("div",{className:"jio-creator__author"},""!==r?(0,t.createElement)("img",{className:"jio-creator__author-avatar",src:r,alt:"",width:24,height:24}):(0,t.createElement)("span",{className:"jio-creator__author-avatar is-placeholder","aria-hidden":"true"},a.slice(0,1)),(0,t.createElement)("span",{className:"jio-creator__author-name"},a),""!==n&&(0,t.createElement)("span",{className:"jio-creator__author-meta"},n),(0,t.createElement)("span",{className:"jio-creator__author-hint"},(0,c.__)("原创内容","jio")))}function k({groups:e,onInsert:r,onClose:n}){const o=(0,a.useRef)(null),i=(0,a.useRef)(null),l=(0,a.useMemo)(()=>e.flatMap(e=>e.items),[e]);return(0,a.useEffect)(()=>{i.current?.focus();const e=e=>{if("Escape"===e.key)return e.preventDefault(),void n();if(!["ArrowRight","ArrowLeft","ArrowDown","ArrowUp"].includes(e.key))return;const t=Array.from(o.current?.querySelectorAll(".jio-insert-item")||[]),a=t.indexOf(document.activeElement);if(-1===a)return;e.preventDefault();const r=window.innerWidth<=767?4:6,i="ArrowRight"===e.key?1:"ArrowLeft"===e.key?-1:"ArrowDown"===e.key?r:-r,l=Math.min(t.length-1,Math.max(0,a+i));t[l]?.focus()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),(0,t.createElement)("div",{className:"jio-insert",role:"dialog","aria-modal":"true","aria-label":(0,c.__)("添加内容","jio")},(0,t.createElement)("button",{type:"button",className:"jio-insert__backdrop","aria-label":(0,c.__)("关闭","jio"),onClick:n}),(0,t.createElement)("div",{className:"jio-insert__panel",ref:o},(0,t.createElement)("header",{className:"jio-insert__head"},(0,t.createElement)("h2",null,(0,c.__)("添加内容","jio")),(0,t.createElement)("button",{type:"button",className:"jio-insert__close",onClick:n,ref:i,"aria-label":(0,c.__)("关闭","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,t.createElement)("div",{className:"jio-insert__body"},e.map(e=>0===e.items.length?null:(0,t.createElement)("section",{className:"jio-insert__group",key:e.label},(0,t.createElement)("h3",null,e.label),(0,t.createElement)("div",{className:"jio-insert__grid"},e.items.map(e=>(0,t.createElement)("button",{key:e.name,type:"button",className:"jio-insert-item",onClick:()=>r(e)},(0,t.createElement)("span",{className:"jio-insert-item__icon","aria-hidden":"true"},(0,t.createElement)("i",{className:e.icon})),(0,t.createElement)("span",{className:"jio-insert-item__label"},e.title)))))),0===l.length&&(0,t.createElement)("p",{className:"jio-creator-muted"},(0,c.__)("当前账号没有可插入的内容类型。","jio")))))}const S={ready:(0,c.__)("尚未保存","jio"),saving:(0,c.__)("保存中…","jio"),saved:(0,c.__)("已保存","jio"),error:(0,c.__)("保存失败","jio"),conflict:(0,c.__)("内容已在别处更新","jio"),submitting:(0,c.__)("提交中…","jio"),submitted:(0,c.__)("已提交","jio")};function C({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,S[e.state]||S.ready),"saved"===e.state&&e.at?(0,t.createElement)("time",null,e.at):null)}function I(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 x=window.jioCreatorStudio||{},L=x.nonce||"",M=`jio-studio-${x.sourceId||0}`;function P(){const e=x.pay||{},t=x.categories&&x.categories.selected||[],a=x.tags&&x.tags.items||[];return{postId:Number(x.sourceId||0),versionId:Number(x.versionId||0),rev:Number(x.versionRev||0),title:String(x.title||""),excerpt:String(x.excerpt||""),content:String(x.content||""),categories:t.map(Number),tags:a.slice(),custom:x.custom||{},featured:x.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 D(){const[e,n]=(0,a.useState)(P),[s,m]=(0,a.useState)(()=>(0,r.parse)(e.content||"")),[d,p]=(0,a.useState)({state:"ready",at:""}),[_,f]=(0,a.useState)(!1),[b,y]=(0,a.useState)(!1),[E,j]=(0,a.useState)(null),[g,h]=(0,a.useState)(null),S=(0,a.useRef)(!1),D=x.capabilities||{},R={titleMin:Number(x.limits?.titleMin||1),titleMax:Number(x.limits?.titleMax||30),titlePlaceholder:String(x.limits?.titlePlaceholder||(0,c.__)("请输入标题","jio")),priceMin:Number(x.pay?.priceMin||0),priceMax:Number(x.pay?.priceMax||0),pointsMin:Number(x.pay?.pointsMin||0),pointsMax:Number(x.pay?.pointsMax||0)},U=!!x.isPublished,A=(0,a.useCallback)(e=>{S.current=!0,n(t=>({...t,...e}))},[]),B=(0,a.useCallback)(e=>{S.current=!0,m(e)},[]),O=(0,a.useMemo)(()=>(0,r.serialize)(s),[s]),F=(0,a.useMemo)(()=>{const e=O.replace(/<[^>]*>/g," ");return(0,l.count)(e,"characters_excluding_spaces",{})},[O]),T=(0,a.useCallback)((t={})=>({post_id:e.postId,version_id:e.versionId,rev:e.rev,title:e.title,excerpt:e.excerpt,content:O,categories:e.categories,tags:e.tags,custom:e.custom,featured:e.featured,pay:I(e.pay),...t}),[e,O]),z=(0,a.useCallback)(async(t=!1)=>{if(!S.current&&(e.postId>0||e.versionId>0))return!0;const a=""!==e.title.trim()||""!==O.replace(/<[^>]*>/g,"").trim();if(t&&!a)return!0;p({state:"saving",at:""});try{const a=await u(x.creator.saveUrl,T({autosave:t}),L),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 S.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}},[T,e.postId,e.versionId,e.rev]),K=(0,a.useCallback)(async e=>{if(await z(!1)){p({state:"submitting",at:""});try{let t="";const a=window.JioCaptcha;if(x.captcha?.enabled&&a&&"function"==typeof a.run){const e=await a.run("front_submit");if(null===e)return p({state:"ready",at:""}),void j({tone:"error",text:(0,c.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const r=await u(x.creator.submitUrl,T({publish_now:e,captcha_proof:t}),L);S.current=!1,p({state:"submitted",at:""}),j({tone:"ok",text:String(r.message||(0,c.__)("已提交","jio"))}),f(!1);const n=r.url||r.goto||x.urls?.center;n&&window.setTimeout(()=>{window.location.href=n},900)}catch(e){p({state:"error",at:""}),j({tone:"error",text:String(e?.message||(0,c.__)("提交失败","jio"))})}}else j({tone:"error",text:(0,c.__)("内容保存失败,请重试后再提交","jio")})},[T,z]),W=(0,a.useCallback)(async()=>{if(await z(!1))try{const t=await u(x.creator.previewUrl,{post_id:e.postId,version_id:e.versionId},L);t.url&&window.open(String(t.url),"_blank","noopener")}catch(e){j({tone:"error",text:String(e?.message||(0,c.__)("预览失败","jio"))})}},[e.postId,e.versionId,z]),{markLocalSaved:J,clear:$}=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:M,snapshot:{title:e.title,content:O,at:(new Date).toISOString()},onFound:e=>h({savedAt:e})}),X=function({enabled:e,onSave:t,onLocal:r,remoteDelay:n=4e3,localDelay:o=1500}){const i=(0,a.useRef)(null),l=(0,a.useRef)(null),c=(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),l.current&&(window.clearTimeout(l.current),l.current=null)},[]),d=(0,a.useCallback)(async()=>{if(!c.current){c.current=!0;try{await s.current()}finally{c.current=!1}}},[]),p=(0,a.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,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:!!D.isLoggedIn,onSave:async()=>{const e=await z(!0);return e&&$(),e},onLocal:J}).schedule;(0,a.useEffect)(()=>{S.current&&X()},[e,O,X]),(0,a.useEffect)(()=>{const e=e=>{S.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(),z(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[z]);const q=(0,a.useCallback)(()=>{try{const e=window.localStorage.getItem(M);if(e){const t=JSON.parse(e);"string"==typeof t.title&&(S.current=!0,n(e=>({...e,title:t.title}))),"string"==typeof t.content&&(S.current=!0,m((0,r.parse)(t.content)))}}catch(e){}h(null)},[]),V=(0,o.useSelect)(e=>e("core/block-editor").getBlockCount(),[]),G=(0,a.useMemo)(()=>function(e){const t={label:(0,c.__)("文字","jio"),items:[{name:"core/paragraph",title:(0,c.__)("正文","jio"),icon:"fa fas fa-align-left"},{name:"core/heading",title:(0,c.__)("标题","jio"),icon:"fa fas fa-heading",attributes:{level:2}},{name:"core/list",title:(0,c.__)("列表","jio"),icon:"fa fas fa-list-ul"},{name:"core/quote",title:(0,c.__)("引用","jio"),icon:"fa fas fa-quote-left"}]},a={label:(0,c.__)("媒体","jio"),items:[]};e.canUploadImage&&a.items.push({name:"core/image",title:(0,c.__)("图片","jio"),icon:"fa far fa-image"}),e.canUploadVideo&&a.items.push({name:"core/video",title:(0,c.__)("视频","jio"),icon:"fa fas fa-video"}),e.canEmbed&&a.items.push({name:"core/embed",title:(0,c.__)("嵌入","jio"),icon:"fa fas fa-code"});const r={label:(0,c.__)("组件","jio"),items:[{name:"core/code",title:(0,c.__)("代码","jio"),icon:"fa fas fa-terminal"},{name:"core/separator",title:(0,c.__)("分隔线","jio"),icon:"fa fas fa-minus"},{name:"core/table",title:(0,c.__)("表格","jio"),icon:"fa fas fa-table"}]};return e.canPay&&r.items.push({name:"jio/paid-fragment",title:(0,c.__)("付费内容","jio"),icon:"fa fas fa-lock"}),[t,a,r]}(D),[D]),H=(0,a.useCallback)(e=>{y(!1),S.current=!0,m(t=>{const a=[...t];return 1!==a.length||"core/paragraph"!==a[0].name||a[0].attributes?.content?[...a,(0,r.createBlock)(e.name,e.attributes||{})]:[(0,r.createBlock)(e.name,e.attributes||{})]})},[]);return(0,t.createElement)("div",{className:"jio-creator","data-status":x.status||"","data-blocks":V}," ",(0,t.createElement)("header",{className:"jio-creator__bar"},(0,t.createElement)("a",{className:"jio-creator__back",href:x.urls?.center||"/"},(0,t.createElement)("i",{className:"fa fas fa-angle-left","aria-hidden":"true"}),(0,t.createElement)("span",null,(0,c.__)("返回","jio"))),(0,t.createElement)("div",{className:"jio-creator__brand"},"Jio Creator Studio"),(0,t.createElement)("div",{className:"jio-creator__actions"},(0,t.createElement)(C,{value:d}),(0,t.createElement)("button",{type:"button",className:"jio-creator__ghost",onClick:()=>{W()}},(0,c.__)("预览","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator__primary",onClick:()=>f(!0)},U?(0,c.__)("提交改稿","jio"):(0,c.__)("发布","jio")))),g&&(0,t.createElement)("div",{className:"jio-creator__notice",role:"status"},(0,t.createElement)("span",null,(0,c.__)("发现本地未同步的草稿。","jio")),(0,t.createElement)("button",{type:"button",onClick:q},(0,c.__)("恢复","jio")),(0,t.createElement)("button",{type:"button",onClick:()=>h(null)},(0,c.__)("忽略","jio"))),E&&(0,t.createElement)("div",{className:`jio-creator__notice is-${E.tone}`,role:"status"},(0,t.createElement)("span",null,E.text),(0,t.createElement)("button",{type:"button",onClick:()=>j(null),"aria-label":(0,c.__)("关闭","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),U&&(0,t.createElement)("p",{className:"jio-creator__hint"},(0,c.__)("这篇改稿不会立即覆盖线上文章;审核通过后才会替换。","jio")),(0,t.createElement)("main",{className:"jio-creator__canvas"},(0,t.createElement)(v,{featured:e.featured,canEdit:!!D.canUploadImage,onOpen:()=>f(!0),onClear:()=>A({featured:{type:"",data:{}}})}),(0,t.createElement)("label",{className:"jio-creator__title"},(0,t.createElement)("span",{className:"screen-reader-text"},(0,c.__)("文章标题","jio")),(0,t.createElement)("textarea",{value:e.title,onChange:e=>A({title:e.target.value}),rows:1,placeholder:R.titlePlaceholder||(0,c.__)("请输入标题","jio"),maxLength:4*(Number(R.titleMax)||30)})),(0,t.createElement)("label",{className:"jio-creator__excerpt"},(0,t.createElement)("span",null,(0,c.__)("摘要(可选)","jio")),(0,t.createElement)("textarea",{value:e.excerpt,onChange:e=>A({excerpt:e.target.value}),rows:2,placeholder:(0,c.__)("一句话概括这篇文章","jio")})),(0,t.createElement)(N,{author:x.author||{}}),(0,t.createElement)("div",{className:"jio-creator__editor"},(0,t.createElement)(i.BlockEditorProvider,{value:s,onInput:B,onChange:B,settings:{hasFixedToolbar:!1,supportsLayout:!1,mediaUpload:window.jioCreatorMediaUpload}},(0,t.createElement)(i.BlockTools,null,(0,t.createElement)(i.BlockList,null))),(0,t.createElement)("button",{type:"button",className:"jio-creator__insert",onClick:()=>y(!0),"aria-haspopup":"dialog","aria-expanded":b},(0,t.createElement)("i",{className:"fa fas fa-plus","aria-hidden":"true"}),(0,t.createElement)("span",null,(0,c.__)("添加内容","jio")))),(0,t.createElement)("footer",{className:"jio-creator__footer"},(0,t.createElement)("span",null,(0,c.__)("字数","jio"),":",F),(0,t.createElement)("span",null,(0,c.__)("约","jio")," ",Math.max(1,Math.round(F/400))," ",(0,c.__)("分钟阅读","jio")))),b&&(0,t.createElement)(k,{groups:G,onInsert:H,onClose:()=>y(!1)}),_&&(0,t.createElement)(w,{draft:e,setDraft:A,capabilities:D,limits:R,taxonomy:{categories:x.categories&&x.categories.items||[],tags:!!x.tags?.enabled,customDefs:x.customDefs||[]},isPublishedEdit:U,onClose:()=>f(!1),onSaveDraft:()=>{z(!1)},onSubmit:e=>{K(e)},privateStorage:!!x.privateStorage,privateUploads:x.privateUploads||[],captcha:!!x.captcha?.enabled,saving:"saving"===d.state||"submitting"===d.state}))}function R(){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))}(L),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||"上传失败")})}}(x,L),window.__jioImageWidthInstalled||(window.__jioImageWidthInstalled=!0,(0,f.addFilter)("editor.BlockEdit","jio/creator-studio/image-width",(0,b.createHigherOrderComponent)(j,"withJioImageWidth"))),e.classList.add("is-ready"),(0,a.createRoot)(e).render((0,t.createElement)(D,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",R):R()})(); \ 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 u(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 u(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 u(o);if(!o.ok)throw s(i,o.status);return i}const p=window.wp.apiFetch;var _=e.n(p);const f=window.wp.hooks,b=window.wp.compose,j=window.wp.components,y=[{key:"half",label:(0,l.__)("半屏","jio"),className:"jio-img-w--half"},{key:"medium",label:(0,l.__)("中等","jio"),className:"jio-img-w--medium"},{key:"wide",label:(0,l.__)("通栏","jio"),className:"jio-img-w--wide"},{key:"full",label:(0,l.__)("全宽","jio"),className:"jio-img-w--full"}];function E(e){return a=>{if("core/image"!==a.name)return(0,t.createElement)(e,{...a});const r=String(a.attributes?.className||""),n=function(e){const t=y.find(t=>(e||"").split(/\s+/).includes(t.className));return t?t.key:"wide"}(r);return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(e,{...a}),(0,t.createElement)(i.BlockControls,{group:"inline"},(0,t.createElement)(j.ToolbarGroup,{controls:y.map(e=>({title:e.label,children:e.label,isActive:n===e.key,onClick:()=>(e=>{const t=r.split(/\s+/).filter(e=>e&&!y.some(t=>t.className===e));a.setAttributes({className:[...t,e.className].join(" ")})})(e)}))})))}}const g=window.jioCreatorStudio||{},h=g.nonce||"";function w(e){const{draft:r,setDraft:n,capabilities:o,limits:i,taxonomy:c,isPublishedEdit:s,onClose:u,onSaveDraft:m,onSubmit:p,privateStorage:_,privateUploads:f,saving:b,captcha:j}=e,[y,E]=(0,a.useState)(""),[w,v]=(0,a.useState)(""),[N,k]=(0,a.useState)(!1),C=(0,a.useRef)(null),S=(0,a.useRef)(null),x=(0,a.useRef)(null);(0,a.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,a.useMemo)(()=>(r.title||"").trim().length,[r.title])>=Number(i.titleMin||1),L=()=>{const e=y.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]))}),E("")};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:u}),(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:u,"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:C,type:"file",accept:"image/*",onChange:()=>{(async()=>{const e=C.current?.files?.[0];if(e&&g.media?.uploadUrl?.image){v(""),k(!0);try{const t=await d(g.media.uploadUrl.image,e,h),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:y,placeholder:(0,l.__)("输入标签,逗号分隔","jio"),onChange:e=>E(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:S,type:"file",onChange:()=>{(async()=>{const e=S.current?.files?.[0];if(e){v(""),k(!0);try{const t=await d(g.creator.privateUrl,e,h,{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]}}),S.current&&(S.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"))),w&&(0,t.createElement)("p",{className:"jio-creator-error"},w),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"}))))),f.length>0&&(0,t.createElement)("details",{className:"jio-creator-reuse"},(0,t.createElement)("summary",null,(0,l.__)("从已上传资料中选择","jio")),(0,t.createElement)("ul",null,f.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"},j&&(0,t.createElement)("div",{className:"jio-creator-drawer__captcha",ref:x}),(0,t.createElement)("div",{className:"jio-creator-drawer__actions"},(0,t.createElement)("button",{type:"button",className:"jio-creator-ghost",onClick:m,disabled:b},(0,l.__)("保存草稿","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator-primary",onClick:()=>p(!1),disabled:b||!I},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:b||!I},(0,l.__)("立即发布","jio"))))))}function v({featured:e,canEdit:a,onOpen:r,onClear:n}){const o="string"==typeof e?.data?.url?e.data.url:"";return a?o?(0,t.createElement)("div",{className:"jio-creator__cover"},(0,t.createElement)("button",{type:"button",className:"jio-creator__cover-thumb",onClick:r},(0,t.createElement)("img",{src:o,alt:""}),(0,t.createElement)("span",{className:"jio-creator__cover-edit"},(0,t.createElement)("i",{className:"fa fas fa-pen","aria-hidden":"true"}),(0,l.__)("更换封面","jio"))),(0,t.createElement)("button",{type:"button",className:"jio-creator__cover-clear",onClick:n,"aria-label":(0,l.__)("移除封面","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))):(0,t.createElement)("button",{type:"button",className:"jio-creator__cover is-empty",onClick:r},(0,t.createElement)("i",{className:"fa far fa-image","aria-hidden":"true"}),(0,t.createElement)("span",null,(0,l.__)("添加封面","jio"))):null}function N({author:e}){const a="string"==typeof e?.name?e.name.trim():"";if(""===a)return null;const r="string"==typeof e?.avatar?e.avatar:"",n="string"==typeof e?.meta?e.meta:"";return(0,t.createElement)("div",{className:"jio-creator__author"},""!==r?(0,t.createElement)("img",{className:"jio-creator__author-avatar",src:r,alt:"",width:24,height:24}):(0,t.createElement)("span",{className:"jio-creator__author-avatar is-placeholder","aria-hidden":"true"},a.slice(0,1)),(0,t.createElement)("span",{className:"jio-creator__author-name"},a),""!==n&&(0,t.createElement)("span",{className:"jio-creator__author-meta"},n),(0,t.createElement)("span",{className:"jio-creator__author-hint"},(0,l.__)("原创内容","jio")))}function k({groups:e,onInsert:r,onClose:n}){const o=(0,a.useRef)(null),i=(0,a.useRef)(null),c=(0,a.useMemo)(()=>e.flatMap(e=>e.items),[e]);return(0,a.useEffect)(()=>{i.current?.focus();const e=e=>{if("Escape"===e.key)return e.preventDefault(),void n();if(!["ArrowRight","ArrowLeft","ArrowDown","ArrowUp"].includes(e.key))return;const t=Array.from(o.current?.querySelectorAll(".jio-insert-item")||[]),a=t.indexOf(document.activeElement);if(-1===a)return;e.preventDefault();const r=window.innerWidth<=767?4:6,i="ArrowRight"===e.key?1:"ArrowLeft"===e.key?-1:"ArrowDown"===e.key?r:-r,c=Math.min(t.length-1,Math.max(0,a+i));t[c]?.focus()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),(0,t.createElement)("div",{className:"jio-insert",role:"dialog","aria-modal":"true","aria-label":(0,l.__)("添加内容","jio")},(0,t.createElement)("button",{type:"button",className:"jio-insert__backdrop","aria-label":(0,l.__)("关闭","jio"),onClick:n}),(0,t.createElement)("div",{className:"jio-insert__panel",ref:o},(0,t.createElement)("header",{className:"jio-insert__head"},(0,t.createElement)("h2",null,(0,l.__)("添加内容","jio")),(0,t.createElement)("button",{type:"button",className:"jio-insert__close",onClick:n,ref:i,"aria-label":(0,l.__)("关闭","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),(0,t.createElement)("div",{className:"jio-insert__body"},e.map(e=>0===e.items.length?null:(0,t.createElement)("section",{className:"jio-insert__group",key:e.label},(0,t.createElement)("h3",null,e.label),(0,t.createElement)("div",{className:"jio-insert__grid"},e.items.map(e=>(0,t.createElement)("button",{key:e.name,type:"button",className:"jio-insert-item",onClick:()=>r(e)},(0,t.createElement)("span",{className:"jio-insert-item__icon","aria-hidden":"true"},(0,t.createElement)("i",{className:e.icon})),(0,t.createElement)("span",{className:"jio-insert-item__label"},e.title)))))),0===c.length&&(0,t.createElement)("p",{className:"jio-creator-muted"},(0,l.__)("当前账号没有可插入的内容类型。","jio")))))}const C={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 S({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,C[e.state]||C.ready),"saved"===e.state&&e.at?(0,t.createElement)("time",null,e.at):null)}function x(e){return JSON.parse(JSON.stringify(e))}function I(e){const t=x(e);return{value:t,signature:JSON.stringify(t)}}function L(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 M=window.jioCreatorStudio||{},R=M.nonce||"",D=`jio-studio-${M.sourceId||0}`;function P(){const e=M.pay||{},t=M.categories&&M.categories.selected||[],a=M.tags&&M.tags.items||[];return{postId:Number(M.sourceId||0),versionId:Number(M.versionId||0),rev:Number(M.versionRev||0),title:String(M.title||""),excerpt:String(M.excerpt||""),content:String(M.content||""),categories:t.map(Number),tags:a.slice(),custom:M.custom||{},featured:M.featured||{type:"",data:{}},pay:{enabled:!!e.enabled,modo:"points"===e.payModo?"points":"cash",price:String(e.price||"0.00"),points:Number(e.points||0),vip1Price:String(e.vip1Price||"0.00"),vip2Price:String(e.vip2Price||"0.00"),payLimit:Number(e.payLimit||0),downloads:Array.isArray(e.downloads)?e.downloads:[]}}}function U(){const[e,n]=(0,a.useState)(P),[s,u]=(0,a.useState)(()=>(0,r.parse)(e.content||"")),d=(0,a.useRef)(s);d.current=s;const p=(0,a.useRef)(e);p.current=e;const[_,f]=(0,a.useState)(()=>({state:M.sourceId||M.versionId||M.content?"saved":"ready",at:""})),[b,j]=(0,a.useState)(!1),[y,E]=(0,a.useState)(!1),[g,h]=(0,a.useState)(null),[C,U]=(0,a.useState)(null),O=(0,a.useRef)(!1),A=(0,a.useRef)(""),B=(0,a.useCallback)(e=>{O.current=!0,d.current=e.blocks,A.current=(0,r.serialize)(e.blocks),u(e.blocks);const t={...p.current,title:e.title,excerpt:e.excerpt};p.current=t,n(t)},[]),T=function({initial:e,onRestore:t,limit:r=80,mergeDelay:n=450}){const o=(0,a.useRef)({past:[],future:[],present:I(e),pending:null}),i=(0,a.useRef)(null),c=(0,a.useRef)(t);c.current=t;const[l,s]=(0,a.useState)({canUndo:!1,canRedo:!1}),u=(0,a.useCallback)(()=>{s({canUndo:o.current.past.length>0||null!==o.current.pending,canRedo:o.current.future.length>0})},[]),m=(0,a.useCallback)(()=>{null!==i.current&&(window.clearTimeout(i.current),i.current=null);const e=o.current;if(null===e.pending)return;const t=I(e.pending);e.pending=null,t.signature!==e.present.signature?(e.past=[...e.past,e.present].slice(-r),e.present=t,e.future=[],u()):u()},[r,u]),d=(0,a.useCallback)(e=>{o.current.pending=x(e),null!==i.current&&window.clearTimeout(i.current),i.current=window.setTimeout(m,n),u()},[m,n,u]),p=(0,a.useCallback)(()=>{m();const e=o.current;if(!e.past.length)return!1;const t=e.past[e.past.length-1];return e.past=e.past.slice(0,-1),e.future=[e.present,...e.future].slice(0,r),e.present=t,c.current(x(t.value)),u(),!0},[m,r,u]),_=(0,a.useCallback)(()=>{m();const e=o.current;if(!e.future.length)return!1;const t=e.future[0];return e.future=e.future.slice(1),e.past=[...e.past,e.present].slice(-r),e.present=t,c.current(x(t.value)),u(),!0},[m,r,u]);return(0,a.useEffect)(()=>()=>{null!==i.current&&window.clearTimeout(i.current)},[]),{...l,record:d,undo:p,redo:_,flush:m}}({initial:{blocks:s,title:e.title,excerpt:e.excerpt},onRestore:B}),z=(0,a.useRef)(T);z.current=T;const F=(0,a.useCallback)(()=>z.current.undo(),[]),K=(0,a.useCallback)(()=>z.current.redo(),[]);(0,a.useEffect)(()=>{const e=e=>{if(!e.metaKey&&!e.ctrlKey||"z"!==e.key.toLowerCase())return;const t=e.target;t?.closest('input, textarea, [contenteditable="true"]')||(e.preventDefault(),e.shiftKey?K():F())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[K,F]);const J=M.capabilities||{},W={titleMin:Number(M.limits?.titleMin||1),titleMax:Number(M.limits?.titleMax||30),titlePlaceholder:String(M.limits?.titlePlaceholder||(0,l.__)("请输入标题","jio")),priceMin:Number(M.pay?.priceMin||0),priceMax:Number(M.pay?.priceMax||0),pointsMin:Number(M.pay?.pointsMin||0),pointsMax:Number(M.pay?.pointsMax||0)},$=!!M.isPublished,X=(0,a.useCallback)(e=>{O.current=!0;const t={...p.current,...e};p.current=t,("title"in e||"excerpt"in e)&&z.current.record({blocks:d.current,title:t.title,excerpt:t.excerpt}),n(t)},[]),q=(0,a.useCallback)(e=>{O.current=!0,d.current=e;const t=(0,r.serialize)(e);if(""!==A.current&&t===A.current)return A.current="",void u(e);z.current.record({blocks:e,title:p.current.title,excerpt:p.current.excerpt}),u(e)},[]),V=(0,a.useMemo)(()=>(0,r.serialize)(s),[s]),G=(0,a.useMemo)(()=>{const e=V.replace(/<[^>]*>/g," ");return(0,c.count)(e,"characters_excluding_spaces",{})},[V]),H=(0,a.useCallback)((t={})=>({post_id:e.postId,version_id:e.versionId,rev:e.rev,title:e.title,excerpt:e.excerpt,content:V,categories:e.categories,tags:e.tags,custom:e.custom,featured:e.featured,pay:L(e.pay),...t}),[e,V]),Z=(0,a.useCallback)(async(t=!1)=>{if(!O.current&&(e.postId>0||e.versionId>0))return!0;const a=""!==e.title.trim()||""!==V.replace(/<[^>]*>/g,"").trim();if(t&&!a)return!0;f({state:"saving",at:""});try{const a=await m(M.creator.saveUrl,H({autosave:t}),R),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);O.current=!1;const c={...p.current,postId:r,versionId:o,rev:i};return p.current=c,n(c),f({state:"saved",at:(new Date).toLocaleTimeString()}),!0}catch(e){return f({state:409===e?.status?"conflict":"error",at:""}),!1}},[H,e.postId,e.versionId,e.rev]),Q=(0,a.useCallback)(async e=>{if(await Z(!1)){f({state:"submitting",at:""});try{let t="";const a=window.JioCaptcha;if(M.captcha?.enabled&&a&&"function"==typeof a.run){const e=await a.run("front_submit");if(null===e)return f({state:"ready",at:""}),void h({tone:"error",text:(0,l.__)("请先完成人机验证","jio")});t=String(e?.jio_captcha_proof||"")}const r=await m(M.creator.submitUrl,H({post_id:p.current.postId,version_id:p.current.versionId,rev:p.current.rev,publish_now:e,captcha_proof:t}),R);O.current=!1,f({state:"submitted",at:""}),h({tone:"ok",text:String(r.message||(0,l.__)("已提交","jio"))}),j(!1);const n=r.url||r.goto||M.urls?.center;n&&window.setTimeout(()=>{window.location.href=n},900)}catch(e){f({state:"error",at:""}),h({tone:"error",text:String(e?.message||(0,l.__)("提交失败","jio"))})}}else h({tone:"error",text:(0,l.__)("内容保存失败,请重试后再提交","jio")})},[H,Z]),Y=(0,a.useCallback)(async()=>{if(await Z(!1))try{const e=await m(M.creator.previewUrl,{post_id:p.current.postId,version_id:p.current.versionId},R);e.url&&window.open(String(e.url),"_blank","noopener")}catch(e){h({tone:"error",text:String(e?.message||(0,l.__)("预览失败","jio"))})}},[e.postId,e.versionId,Z]),{markLocalSaved:ee,clear:te}=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:D,snapshot:{title:e.title,content:V,at:(new Date).toISOString()},onFound:e=>U({savedAt:e})}),ae=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),u=(0,a.useRef)(r);s.current=t,u.current=r;const m=(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)(()=>{m(),u.current(),e&&(c.current=window.setTimeout(()=>u.current(),o),i.current=window.setTimeout(()=>{d()},n))},[m,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),m()}},[m,e,d]),(0,a.useMemo)(()=>({schedule:p,flush:d,cancel:m}),[m,d,p])}({enabled:!!J.isLoggedIn,onSave:async()=>{const e=await Z(!0);return e&&te(),e},onLocal:ee}).schedule;(0,a.useEffect)(()=>{O.current&&ae()},[e,V,ae]),(0,a.useEffect)(()=>{const e=e=>{O.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(),Z(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Z]);const re=(0,a.useCallback)(()=>{try{const e=window.localStorage.getItem(D);if(e){const t=JSON.parse(e);"string"==typeof t.title&&X({title:t.title}),"string"==typeof t.content&&q((0,r.parse)(t.content))}}catch(e){}U(null)},[]),ne=(0,o.useSelect)(e=>e("core/block-editor").getBlockCount(),[]),oe=(0,a.useMemo)(()=>function(e){const t={label:(0,l.__)("文字","jio"),items:[{name:"core/paragraph",title:(0,l.__)("正文","jio"),icon:"fa fas fa-align-left"},{name:"core/heading",title:(0,l.__)("标题","jio"),icon:"fa fas fa-heading",attributes:{level:2}},{name:"core/list",title:(0,l.__)("列表","jio"),icon:"fa fas fa-list-ul"},{name:"core/quote",title:(0,l.__)("引用","jio"),icon:"fa fas fa-quote-left"}]},a={label:(0,l.__)("媒体","jio"),items:[]};e.canUploadImage&&a.items.push({name:"core/image",title:(0,l.__)("图片","jio"),icon:"fa far fa-image"}),e.canUploadVideo&&a.items.push({name:"core/video",title:(0,l.__)("视频","jio"),icon:"fa fas fa-video"}),e.canEmbed&&a.items.push({name:"core/embed",title:(0,l.__)("嵌入","jio"),icon:"fa fas fa-code"});const r={label:(0,l.__)("组件","jio"),items:[{name:"core/code",title:(0,l.__)("代码","jio"),icon:"fa fas fa-terminal"},{name:"core/separator",title:(0,l.__)("分隔线","jio"),icon:"fa fas fa-minus"},{name:"core/table",title:(0,l.__)("表格","jio"),icon:"fa fas fa-table"}]};return e.canPay&&r.items.push({name:"jio/paid-fragment",title:(0,l.__)("付费内容","jio"),icon:"fa fas fa-lock"}),[t,a,r]}(J),[J]),ie=(0,a.useCallback)(e=>{E(!1),O.current=!0;const t=[...d.current];let a;a=1!==t.length||"core/paragraph"!==t[0].name||t[0].attributes?.content?[...t,(0,r.createBlock)(e.name,e.attributes||{})]:[(0,r.createBlock)(e.name,e.attributes||{})],d.current=a,z.current.record({blocks:a,title:p.current.title,excerpt:p.current.excerpt}),u(a)},[]);return(0,t.createElement)("div",{className:"jio-creator","data-status":M.status||"","data-blocks":ne},(0,t.createElement)("header",{className:"jio-creator__bar"},(0,t.createElement)("div",{className:"jio-creator__bar-left"},(0,t.createElement)("a",{className:"jio-creator__back",href:M.urls?.center||"/","aria-label":(0,l.__)("返回作者中心","jio")},(0,t.createElement)("i",{className:"fa fas fa-angle-left","aria-hidden":"true"})),(0,t.createElement)("span",{className:"jio-creator__bar-brand"},"Jio"),(0,t.createElement)("span",{className:"jio-creator__bar-divider","aria-hidden":"true"}),(0,t.createElement)("span",{className:"jio-creator__bar-mode"},$?(0,l.__)("修改文章","jio"):(0,l.__)("写文章","jio"))),(0,t.createElement)("div",{className:"jio-creator__bar-center"},(0,t.createElement)("span",{className:"jio-creator__doc-title"},e.title.trim()||(0,l.__)("无标题文章","jio")),(0,t.createElement)(S,{value:_})),(0,t.createElement)("div",{className:"jio-creator__bar-actions"},(0,t.createElement)("div",{className:"jio-creator__history",role:"group","aria-label":(0,l.__)("编辑历史","jio")},(0,t.createElement)("button",{type:"button",className:"jio-creator__icon-btn",onClick:()=>T.undo(),disabled:!T.canUndo,"aria-label":(0,l.__)("撤销","jio"),title:(0,l.__)("撤销","jio")},(0,t.createElement)("i",{className:"fa fas fa-undo","aria-hidden":"true"})),(0,t.createElement)("button",{type:"button",className:"jio-creator__icon-btn",onClick:()=>T.redo(),disabled:!T.canRedo,"aria-label":(0,l.__)("重做","jio"),title:(0,l.__)("重做","jio")},(0,t.createElement)("i",{className:"fa fas fa-redo","aria-hidden":"true"}))),(0,t.createElement)("button",{type:"button",className:"jio-creator__ghost jio-creator__save-draft",onClick:()=>{Z(!1)}},(0,l.__)("保存草稿","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator__ghost jio-creator__preview",onClick:()=>{Y()}},(0,l.__)("预览","jio")),(0,t.createElement)("button",{type:"button",className:"jio-creator__primary",onClick:()=>j(!0)},$?(0,l.__)("提交改稿","jio"):(0,l.__)("发布","jio")))),C&&(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:re},(0,l.__)("恢复","jio")),(0,t.createElement)("button",{type:"button",onClick:()=>U(null)},(0,l.__)("忽略","jio"))),g&&(0,t.createElement)("div",{className:`jio-creator__notice is-${g.tone}`,role:"status"},(0,t.createElement)("span",null,g.text),(0,t.createElement)("button",{type:"button",onClick:()=>h(null),"aria-label":(0,l.__)("关闭","jio")},(0,t.createElement)("i",{className:"fa fas fa-times","aria-hidden":"true"}))),$&&(0,t.createElement)("p",{className:"jio-creator__hint"},(0,l.__)("这篇改稿不会立即覆盖线上文章;审核通过后才会替换。","jio")),(0,t.createElement)("main",{className:"jio-creator__canvas"},(0,t.createElement)(v,{featured:e.featured,canEdit:!!J.canUploadImage,onOpen:()=>j(!0),onClear:()=>X({featured:{type:"",data:{}}})}),(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=>X({title:e.target.value}),rows:1,placeholder:W.titlePlaceholder||(0,l.__)("请输入标题","jio"),maxLength:4*(Number(W.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=>X({excerpt:e.target.value}),rows:2,placeholder:(0,l.__)("一句话概括这篇文章","jio")})),(0,t.createElement)(N,{author:M.author||{}}),(0,t.createElement)("div",{className:"jio-creator__editor"},(0,t.createElement)(i.BlockEditorProvider,{value:s,onInput:q,onChange:q,settings:{hasFixedToolbar:!1,supportsLayout:!1,mediaUpload:window.jioCreatorMediaUpload}},(0,t.createElement)(i.BlockTools,null,(0,t.createElement)(i.BlockList,null))),(0,t.createElement)("button",{type:"button",className:"jio-creator__insert",onClick:()=>E(!0),"aria-haspopup":"dialog","aria-expanded":y},(0,t.createElement)("i",{className:"fa fas fa-plus","aria-hidden":"true"}),(0,t.createElement)("span",null,(0,l.__)("添加内容","jio")))),(0,t.createElement)("footer",{className:"jio-creator__footer"},(0,t.createElement)("span",null,(0,l.__)("字数","jio"),":",G),(0,t.createElement)("span",null,(0,l.__)("约","jio")," ",Math.max(1,Math.round(G/400))," ",(0,l.__)("分钟阅读","jio")))),y&&(0,t.createElement)(k,{groups:oe,onInsert:ie,onClose:()=>E(!1)}),b&&(0,t.createElement)(w,{draft:e,setDraft:X,capabilities:J,limits:W,taxonomy:{categories:M.categories&&M.categories.items||[],tags:!!M.tags?.enabled,customDefs:M.customDefs||[]},isPublishedEdit:$,onClose:()=>j(!1),onSaveDraft:()=>{Z(!1)},onSubmit:e=>{Q(e)},privateStorage:!!M.privateStorage,privateUploads:M.privateUploads||[],captcha:!!M.captcha?.enabled,saving:"saving"===_.state||"submitting"===_.state}))}function O(){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))}(R),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||"上传失败")})}}(M,R),window.__jioImageWidthInstalled||(window.__jioImageWidthInstalled=!0,(0,f.addFilter)("editor.BlockEdit","jio/creator-studio/image-width",(0,b.createHigherOrderComponent)(E,"withJioImageWidth"))),e.classList.add("is-ready"),(0,a.createRoot)(e).render((0,t.createElement)(U,null)))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",O):O()})(); \ No newline at end of file diff --git a/assets/creator-studio/scripts/interact.cjs b/assets/creator-studio/scripts/interact.cjs index 988a6f2b..6d389e12 100644 --- a/assets/creator-studio/scripts/interact.cjs +++ b/assets/creator-studio/scripts/interact.cjs @@ -3,6 +3,7 @@ * 并记录无法捕获的 promise 拒绝。 */ const fs = require('fs'); +const path = require('path'); const puppeteer = require('puppeteer-core'); const CANDIDATES = [ @@ -21,7 +22,31 @@ const URL = process.argv[2] || 'https://localhost/jio-preview.html'; args: ['--disable-gpu', '--no-sandbox'], }); const page = await browser.newPage(); - await page.setViewport({ width: 1440, height: 1000 }); + await page.setViewport({ width: 1440, height: 560 }); + + if (process.env.JIO_USE_WORKTREE_BUILD === '1') { + await page.setRequestInterception(true); + page.on('request', (request) => { + const pathname = new URL(request.url()).pathname; + const jsSuffix = '/assets/creator-studio/build/index.js'; + const cssSuffix = '/assets/creator-studio/build/index.css'; + if (pathname.endsWith(jsSuffix)) { + request.respond({ + status: 200, + contentType: 'application/javascript', + body: fs.readFileSync(path.join(__dirname, '../build/index.js')), + }); + } else if (pathname.endsWith(cssSuffix)) { + request.respond({ + status: 200, + contentType: 'text/css', + body: fs.readFileSync(path.join(__dirname, '../build/index.css')), + }); + } else { + request.continue(); + } + }); + } const errors = []; page.on('pageerror', (e) => errors.push('pageerror: ' + e.message)); @@ -33,8 +58,12 @@ const URL = process.argv[2] || 'https://localhost/jio-preview.html'; blocks: document.querySelectorAll('.block-editor-block-list__block').length, hasInsertBtn: !!document.querySelector('.jio-creator__insert'), hasCover: !!document.querySelector('.jio-creator__cover'), + toolbarTop: document.querySelector('.jio-creator__bar')?.getBoundingClientRect().top, })); - console.log('BEFORE ' + JSON.stringify(before)); + await page.evaluate(() => window.scrollTo(0, 700)); + await new Promise((r) => setTimeout(r, 300)); + const toolbarAfterScroll = await page.$eval('.jio-creator__bar', (el) => el.getBoundingClientRect().top); + console.log('BEFORE ' + JSON.stringify({ ...before, toolbarAfterScroll })); // 打开插入面板 await page.click('.jio-creator__insert'); diff --git a/assets/creator-studio/src/hooks/use-editor-history.ts b/assets/creator-studio/src/hooks/use-editor-history.ts new file mode 100644 index 00000000..ca187a59 --- /dev/null +++ b/assets/creator-studio/src/hooks/use-editor-history.ts @@ -0,0 +1,121 @@ +/** + * 工作台级撤销/重做历史。 + * + * BlockEditorProvider 独立运行时不带 core/editor 的 post history store, + * 因此为标题、摘要、区块树保存快照。输入以 450ms 合并成一条历史记录, + * 避免每个字符都占用一步。 + * + * @package Jio + */ + +import { useCallback, useEffect, useRef, useState } from '@wordpress/element'; + +type Snapshot = { value: T; signature: string }; +type HistoryState = { past: Snapshot[]; future: Snapshot[]; present: Snapshot; pending: T | null }; + +type Options = { + initial: T; + onRestore: (value: T) => void; + limit?: number; + mergeDelay?: number; +}; + +function copy(value: T): T { + return JSON.parse(JSON.stringify(value)) as T; +} + +function snapshot(value: T): Snapshot { + const cloned = copy(value); + return { value: cloned, signature: JSON.stringify(cloned) }; +} + +export function useEditorHistory({ initial, onRestore, limit = 80, mergeDelay = 450 }: Options) { + const state = useRef>({ + past: [], + future: [], + present: snapshot(initial), + pending: null, + }); + const timer = useRef(null); + const restoreRef = useRef(onRestore); + restoreRef.current = onRestore; + const [availability, setAvailability] = useState({ canUndo: false, canRedo: false }); + + const updateAvailability = useCallback(() => { + setAvailability({ + canUndo: state.current.past.length > 0 || state.current.pending !== null, + canRedo: state.current.future.length > 0, + }); + }, []); + + const flush = useCallback(() => { + if (timer.current !== null) { + window.clearTimeout(timer.current); + timer.current = null; + } + const current = state.current; + if (current.pending === null) { + return; + } + const next = snapshot(current.pending); + current.pending = null; + if (next.signature === current.present.signature) { + updateAvailability(); + return; + } + current.past = [...current.past, current.present].slice(-limit); + current.present = next; + current.future = []; + updateAvailability(); + }, [limit, updateAvailability]); + + const record = useCallback( + (value: T) => { + state.current.pending = copy(value); + if (timer.current !== null) { + window.clearTimeout(timer.current); + } + timer.current = window.setTimeout(flush, mergeDelay); + updateAvailability(); + }, + [flush, mergeDelay, updateAvailability] + ); + + const undo = useCallback(() => { + flush(); + const current = state.current; + if (!current.past.length) { + return false; + } + const previous = current.past[current.past.length - 1]; + current.past = current.past.slice(0, -1); + current.future = [current.present, ...current.future].slice(0, limit); + current.present = previous; + restoreRef.current(copy(previous.value)); + updateAvailability(); + return true; + }, [flush, limit, updateAvailability]); + + const redo = useCallback(() => { + flush(); + const current = state.current; + if (!current.future.length) { + return false; + } + const next = current.future[0]; + current.future = current.future.slice(1); + current.past = [...current.past, current.present].slice(-limit); + current.present = next; + restoreRef.current(copy(next.value)); + updateAvailability(); + return true; + }, [flush, limit, updateAvailability]); + + useEffect(() => () => { + if (timer.current !== null) { + window.clearTimeout(timer.current); + } + }, []); + + return { ...availability, record, undo, redo, flush }; +} diff --git a/assets/creator-studio/src/index.tsx b/assets/creator-studio/src/index.tsx index 2a63552f..9833575f 100644 --- a/assets/creator-studio/src/index.tsx +++ b/assets/creator-studio/src/index.tsx @@ -27,6 +27,7 @@ import { InsertPanel, type InsertItem } from './panels/insert-panel'; import { buildInsertGroups } from './utils/insert-items'; import { SaveState, type SaveStateValue } from './components/save-state'; import { useAutosave } from './hooks/use-autosave'; +import { useEditorHistory } from './hooks/use-editor-history'; import { useLocalRecovery } from './hooks/use-local-recovery'; import { normalizePayForRequest } from './utils/pay'; import './styles/studio.scss'; @@ -109,12 +110,55 @@ function initialDraft(): Draft { function Studio(): JSX.Element { const [draft, setDraft] = useState(initialDraft); const [blocks, setBlocks] = useState(() => parse(draft.content || '')); - const [saveState, setSaveState] = useState({ state: 'ready', at: '' }); + const blocksRef = useRef(blocks); + blocksRef.current = blocks; + const draftRef = useRef(draft); + draftRef.current = draft; + const [saveState, setSaveState] = useState(() => ({ + state: bootstrap.sourceId || bootstrap.versionId || bootstrap.content ? 'saved' : 'ready', + at: '', + })); const [drawerOpen, setDrawerOpen] = useState(false); const [insertOpen, setInsertOpen] = useState(false); const [notice, setNotice] = useState<{ tone: 'ok' | 'error'; text: string } | null>(null); const [recovery, setRecovery] = useState(null); const dirtyRef = useRef(false); + const restoreBlockSignatureRef = useRef(''); + + const restoreHistory = useCallback((value: { blocks: any[]; title: string; excerpt: string }) => { + dirtyRef.current = true; + blocksRef.current = value.blocks; + restoreBlockSignatureRef.current = serialize(value.blocks); + setBlocks(value.blocks); + const next = { ...draftRef.current, title: value.title, excerpt: value.excerpt }; + draftRef.current = next; + setDraft(next); + }, []); + const history = useEditorHistory({ + initial: { blocks, title: draft.title, excerpt: draft.excerpt }, + onRestore: restoreHistory, + }); + const historyRef = useRef(history); + historyRef.current = history; + + const undo = useCallback(() => historyRef.current.undo(), []); + const redo = useCallback(() => historyRef.current.redo(), []); + + useEffect(() => { + const onKeyDown = (event: KeyboardEvent) => { + if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'z') { + return; + } + const target = event.target as HTMLElement | null; + if (target?.closest('input, textarea, [contenteditable="true"]')) { + return; + } + event.preventDefault(); + event.shiftKey ? redo() : undo(); + }; + window.addEventListener('keydown', onKeyDown); + return () => window.removeEventListener('keydown', onKeyDown); + }, [redo, undo]); const capabilities = bootstrap.capabilities || {}; const limits: Limits = { @@ -130,11 +174,32 @@ function Studio(): JSX.Element { const patchDraft = useCallback((patch: Partial) => { dirtyRef.current = true; - setDraft((current) => ({ ...current, ...patch })); + const next = { ...draftRef.current, ...patch }; + draftRef.current = next; + if ('title' in patch || 'excerpt' in patch) { + historyRef.current.record({ + blocks: blocksRef.current, + title: next.title, + excerpt: next.excerpt, + }); + } + setDraft(next); }, []); const onChangeBlocks = useCallback((next: any[]) => { dirtyRef.current = true; + blocksRef.current = next; + const signature = serialize(next); + if (restoreBlockSignatureRef.current !== '' && signature === restoreBlockSignatureRef.current) { + restoreBlockSignatureRef.current = ''; + setBlocks(next); + return; + } + historyRef.current.record({ + blocks: next, + title: draftRef.current.title, + excerpt: draftRef.current.excerpt, + }); setBlocks(next); }, []); @@ -183,7 +248,9 @@ function Studio(): JSX.Element { const versionId = Number(response.version_id || draft.versionId || 0); const rev = Number(response.rev || response.versionRev || draft.rev || 0); dirtyRef.current = false; - setDraft((current) => ({ ...current, postId: savedId, versionId, rev })); + const updated = { ...draftRef.current, postId: savedId, versionId, rev }; + draftRef.current = updated; + setDraft(updated); setSaveState({ state: 'saved', at: new Date().toLocaleTimeString() }); return true; } catch (error: any) { @@ -220,7 +287,13 @@ function Studio(): JSX.Element { } const response = await apiPost( bootstrap.creator.submitUrl, - buildPayload({ publish_now: publishNow, captcha_proof: captchaProof }), + buildPayload({ + post_id: draftRef.current.postId, + version_id: draftRef.current.versionId, + rev: draftRef.current.rev, + publish_now: publishNow, + captcha_proof: captchaProof, + }), nonce ); dirtyRef.current = false; @@ -249,7 +322,7 @@ function Studio(): JSX.Element { try { const response = await apiPost( bootstrap.creator.previewUrl, - { post_id: draft.postId, version_id: draft.versionId }, + { post_id: draftRef.current.postId, version_id: draftRef.current.versionId }, nonce ); if (response.url) { @@ -315,12 +388,10 @@ function Studio(): JSX.Element { if (raw) { const parsed = JSON.parse(raw); if (typeof parsed.title === 'string') { - dirtyRef.current = true; - setDraft((current) => ({ ...current, title: parsed.title })); + patchDraft({ title: parsed.title }); } if (typeof parsed.content === 'string') { - dirtyRef.current = true; - setBlocks(parse(parsed.content)); + onChangeBlocks(parse(parsed.content)); } } } catch (error) { @@ -340,28 +411,59 @@ function Studio(): JSX.Element { (item: InsertItem) => { setInsertOpen(false); dirtyRef.current = true; - setBlocks((current: any[]) => { - // 空文档时直接替换初始的空白段落,避免留下一个空行。 - const next = [...current]; - if (next.length === 1 && next[0].name === 'core/paragraph' && !next[0].attributes?.content) { - return [createBlock(item.name, item.attributes || {})]; - } - return [...next, createBlock(item.name, item.attributes || {})]; + const current = [...blocksRef.current]; + let next: any[]; + // 空文档时直接替换初始的空白段落,避免留下一个空行。 + if (current.length === 1 && current[0].name === 'core/paragraph' && !current[0].attributes?.content) { + next = [createBlock(item.name, item.attributes || {})]; + } else { + next = [...current, createBlock(item.name, item.attributes || {})]; + } + blocksRef.current = next; + historyRef.current.record({ + blocks: next, + title: draftRef.current.title, + excerpt: draftRef.current.excerpt, }); + setBlocks(next); }, [] ); return ( -
- -