Files
laipower/wp-content/plugins/activitypub/build/pre-publish-panel/plugin.js

3 lines
4.4 KiB
JavaScript

(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.plugins,i=window.wp.components,n=window.wp.data,a=window.wp.element,s=window.wp.i18n,r=window.wp.dom,u=window._activityPubOptions?.noteLength||500,l=["youtube","vimeo","dailymotion","tiktok","videopress"],d=["spotify","soundcloud","mixcloud"],c=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],p=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],g={gallery:(0,s.__)("Gallery","activitypub"),video:(0,s.__)("Video","activitypub"),audio:(0,s.__)("Audio","activitypub"),image:(0,s.__)("Image","activitypub"),status:(0,s.__)("Status","activitypub")},m=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",h=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:n}=o;if("core/image"===t)e.imageCount++;else if(p.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();l.includes(t)?e.videoCount++:d.includes(t)&&e.audioCount++}if(c.includes(t)){const o=(0,r.__unstableStripHTML)(m(t,i));e.textLength+=o.length,e.textBlockCount++}if(n&&n.length){const t=h(n);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},v=window.ReactJSXRuntime;(0,o.registerPlugin)("activitypub-pre-publish",{render:()=>{const{blocks:o,postFormat:r}=(0,n.useSelect)(o=>({blocks:o(e.store).getBlocks(),postFormat:o(t.store).getEditedPostAttribute("format")}),[]),{editPost:l}=(0,n.useDispatch)(t.store),d=(0,a.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=h(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength<u?{format:"gallery",message:(0,s.__)("This post contains multiple images. Changing the format to Gallery won't change your post content, but will share it as a media post on the Fediverse, making it visible on platforms like Pixelfed.","activitypub")}:o.videoCount>0&&o.textLength<u?{format:"video",message:(0,s.__)("This post contains a video. Changing the format to Video won't change your post content, but will share it as a media post on the Fediverse, improving compatibility with video-focused platforms.","activitypub")}:o.audioCount>0&&o.textLength<u?{format:"audio",message:(0,s.__)("This post contains audio content. Changing the format to Audio won't change your post content, but will share it as a media post on the Fediverse, improving compatibility with audio-focused platforms.","activitypub")}:1===o.imageCount&&0===o.videoCount&&0===o.audioCount&&o.textLength<u?{format:"image",message:(0,s.__)("This post contains an image. Changing the format to Image won't change your post content, but will share it as a media post on the Fediverse, making it visible on platforms like Pixelfed.","activitypub")}:!i&&o.textLength>0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,s.__)("This is a short post with no media. Changing the format to Status won't change your post content, but will share it as a Note on the Fediverse, which is the standard format on platforms like Mastodon.","activitypub")}:null})(o,r),[o,r]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!d){if(r&&"standard"!==r&&g[r]){const e=g[r]||r;return(0,v.jsx)(t.PluginPrePublishPanel,{title:(0,s.__)("Fediverse ⁂","activitypub"),initialOpen:!0,children:(0,v.jsx)("p",{children:(0,s.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */
(0,s.__)("This post will be shared in %s format on the Fediverse.","activitypub"),e)})})}return null}return(0,v.jsxs)(t.PluginPrePublishPanel,{title:(0,s.__)("Fediverse ⁂","activitypub"),initialOpen:!0,children:[(0,v.jsx)("p",{children:d.message}),(0,v.jsx)(i.Button,{variant:"secondary",onClick:()=>l({format:d.format}),children:(0,s.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */
(0,s.__)("Set format to %s","activitypub"),g[d.format]||d.format)})]})}})})();