From 47943ef8aaab6dec18cbf75f953ee41d07aa3bdc Mon Sep 17 00:00:00 2001 From: Matt Wiebe Date: Thu, 10 Aug 2023 15:33:33 -0500 Subject: [PATCH] add styles to block --- build/followers/index.asset.php | 2 +- build/followers/index.js | 748 +++++++++++++++++++++++++++++++- build/followers/style-view.css | 81 +++- build/followers/view.asset.php | 2 +- build/followers/view.js | 657 +++++++++++++++++++++++++++- src/follow-me/block.json | 17 +- src/follow-me/edit.js | 35 +- src/follow-me/style.scss | 2 - 8 files changed, 1526 insertions(+), 18 deletions(-) diff --git a/build/followers/index.asset.php b/build/followers/index.asset.php index 06c1d9d..3bed19b 100644 --- a/build/followers/index.asset.php +++ b/build/followers/index.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => '284dffd27ea0242085be'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => '5c6d5c49b2b56744818c'); diff --git a/build/followers/index.js b/build/followers/index.js index df9590b..2e841f5 100644 --- a/build/followers/index.js +++ b/build/followers/index.js @@ -1,3 +1,745 @@ -(()=>{var e={184:(e,t)=>{var a;!function(){"use strict";var n={}.hasOwnProperty;function l(){for(var e=[],t=0;t{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.blocks,t=window.wp.element,n=window.wp.primitives,l=(0,t.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(n.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"}));function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t{e.preventDefault(),!a&&r(l)}},n)}const g={outlined:"outlined",minimal:"minimal"};function f(e){let{compact:a,nextLabel:n,page:l,pageClick:r,perPage:o,prevLabel:i,total:c,variant:s=g.outlined}=e;const p=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,n)=>e>=1&&e<=t&&n.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(l,Math.ceil(c/o)),u=w()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":a});return(0,t.createElement)("nav",{className:u},i&&(0,t.createElement)(d,{key:"prev",page:l-1,pageClick:r,active:1===l,"aria-label":i,className:"wp-block-query-pagination-previous block-editor-block-list__block"},i),!a&&(0,t.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},p.map((e=>(0,t.createElement)(d,{key:e,page:e,pageClick:r,active:e===l,className:"page-numbers"},e)))),n&&(0,t.createElement)(d,{key:"next",page:l+1,pageClick:r,active:l===Math.ceil(c/o),"aria-label":n,className:"wp-block-query-pagination-next block-editor-block-list__block"},n))}const{namespace:y}=window._activityPubOptions;function h(e){let{selectedUser:a,per_page:n,order:l,title:o,page:i,setPage:c,className:u="",followLinks:b=!0}=e;const w="site"===a?0:a,[d,g]=(0,p.useState)([]),[h,_]=(0,p.useState)(0),[E,x]=(0,p.useState)(0),[C,S]=function(){const[e,t]=(0,p.useState)(1);return[e,t]}(),O=i||C,N=c||S,P=(0,t.createInterpolateElement)(/* translators: arrow for previous followers link */ -(0,s.__)(" Less","activitypub"),{span:(0,t.createElement)("span",{class:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),L=(0,t.createInterpolateElement)(/* translators: arrow for next followers link */ -(0,s.__)("More ","activitypub"),{span:(0,t.createElement)("span",{class:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})});return(0,p.useEffect)((()=>{const e=function(e,t,a,n){const l=`/${y}/users/${e}/followers`,r={per_page:t,order:a,page:n,context:"full"};return(0,m.addQueryArgs)(l,r)}(w,n,l,O);v()({path:e}).then((e=>{_(Math.ceil(e.totalItems/n)),x(e.totalItems),g(e.orderedItems)})).catch((e=>console.error(e)))}),[w,n,l,O]),(0,t.createElement)("div",{className:"activitypub-follower-block "+u},(0,t.createElement)("h3",null,o),(0,t.createElement)("ul",null,d&&d.map((e=>(0,t.createElement)("li",{key:e.url},(0,t.createElement)(k,r({},e,{followLinks:b})))))),h>1&&(0,t.createElement)(f,{page:O,perPage:n,total:E,pageClick:N,nextLabel:L,prevLabel:P,compact:"is-style-compact"===u}))}function k(e){let{name:a,icon:n,url:l,preferredUsername:i,followLinks:c=!0}=e;const s=`@${i}`,p={};return c||(p.onClick=e=>e.preventDefault()),(0,t.createElement)(o.ExternalLink,r({className:"activitypub-link",href:l,title:s},p),(0,t.createElement)("img",{width:"40",height:"40",src:n.url,class:"avatar activitypub-avatar"}),(0,t.createElement)("span",{class:"activitypub-actor"},(0,t.createElement)("strong",{className:"activitypub-name"},a),(0,t.createElement)("span",{class:"sep"},"/"),(0,t.createElement)("span",{class:"activitypub-handle"},s)))}const _=window._activityPubOptions?.enabled;(0,e.registerBlockType)("activitypub/followers",{edit:function(e){let{attributes:a,setAttributes:n}=e;const{order:l,per_page:p,selectedUser:u,title:v}=a,m=(0,c.useBlockProps)(),[b,w]=(0,t.useState)(1),d=[{label:(0,s.__)("New to old","activitypub"),value:"desc"},{label:(0,s.__)("Old to new","activitypub"),value:"asc"}],g=function(){const e=_?.users?(0,i.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,t.useMemo)((()=>{if(!e)return[];const t=_?.site?[{label:(0,s.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:t.id}),e)),t)}),[e])}(),f=e=>t=>{w(1),n({[e]:t})};return(0,t.createElement)("div",m,(0,t.createElement)(c.InspectorControls,{key:"setting"},(0,t.createElement)(o.PanelBody,{title:(0,s.__)("Followers Options","activitypub")},(0,t.createElement)(o.TextControl,{label:(0,s.__)("Title","activitypub"),help:(0,s.__)("Title to display above the list of followers. Blank for none.","activitypub"),value:v,onChange:e=>n({title:e})}),(0,t.createElement)(o.SelectControl,{label:(0,s.__)("Select User","activitypub"),value:u,options:g,onChange:f("selectedUser")}),(0,t.createElement)(o.SelectControl,{label:(0,s.__)("Sort","activitypub"),value:l,options:d,onChange:f("order")}),(0,t.createElement)(o.RangeControl,{label:(0,s.__)("Number of Followers","activitypub"),value:p,onChange:f("per_page"),min:1,max:10}))),(0,t.createElement)(h,r({},a,{page:b,setPage:w,followLinks:!1})))},save:()=>null,icon:l})})()})(); \ No newline at end of file +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ "./node_modules/@wordpress/icons/build-module/library/people.js": +/*!**********************************************************************!*\ + !*** ./node_modules/@wordpress/icons/build-module/library/people.js ***! + \**********************************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ }); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives"); +/* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__); + + +/** + * WordPress dependencies + */ + +const people = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.SVG, { + xmlns: "http://www.w3.org/2000/svg", + viewBox: "0 0 24 24" +}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.Path, { + d: "M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z", + fillRule: "evenodd" +})); +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (people); +//# sourceMappingURL=people.js.map + +/***/ }), + +/***/ "./src/followers/edit.js": +/*!*******************************!*\ + !*** ./src/followers/edit.js ***! + \*******************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (/* binding */ Edit) +/* harmony export */ }); +/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/extends */ "./node_modules/@babel/runtime/helpers/esm/extends.js"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _followers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./followers */ "./src/followers/followers.js"); +/* harmony import */ var _shared_use_user_options__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../shared/use-user-options */ "./src/shared/use-user-options.js"); + + + + + + + + +function Edit(_ref) { + let { + attributes, + setAttributes + } = _ref; + const { + order, + per_page, + selectedUser, + title + } = attributes; + const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.useBlockProps)(); + const [page, setPage] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)(1); + const orderOptions = [{ + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('New to old', 'activitypub'), + value: 'desc' + }, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Old to new', 'activitypub'), + value: 'asc' + }]; + const usersOptions = (0,_shared_use_user_options__WEBPACK_IMPORTED_MODULE_6__.useUserOptions)(); + const setAttributestAndResetPage = key => { + return value => { + setPage(1); + setAttributes({ + [key]: value + }); + }; + }; + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("div", blockProps, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, { + key: "setting" + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.PanelBody, { + title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Followers Options', 'activitypub') + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.TextControl, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Title', 'activitypub'), + help: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Title to display above the list of followers. Blank for none.', 'activitypub'), + value: title, + onChange: value => setAttributes({ + title: value + }) + }), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.SelectControl, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Select User', 'activitypub'), + value: selectedUser, + options: usersOptions, + onChange: setAttributestAndResetPage('selectedUser') + }), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.SelectControl, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Sort', 'activitypub'), + value: order, + options: orderOptions, + onChange: setAttributestAndResetPage('order') + }), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.RangeControl, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Number of Followers', 'activitypub'), + value: per_page, + onChange: setAttributestAndResetPage('per_page'), + min: 1, + max: 10 + }))), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_followers__WEBPACK_IMPORTED_MODULE_5__.Followers, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, attributes, { + page: page, + setPage: setPage, + followLinks: false + }))); +} + +/***/ }), + +/***/ "./src/followers/followers.js": +/*!************************************!*\ + !*** ./src/followers/followers.js ***! + \************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ Followers: () => (/* binding */ Followers) +/* harmony export */ }); +/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/extends */ "./node_modules/@babel/runtime/helpers/esm/extends.js"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react */ "react"); +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch"); +/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); +/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _pagination__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./pagination */ "./src/followers/pagination.js"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_7__); + + + + + + + + + +const { + namespace +} = window._activityPubOptions; +function getPath(userId, per_page, order, page) { + const path = `/${namespace}/users/${userId}/followers`; + const args = { + per_page, + order, + page, + context: 'full' + }; + return (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_4__.addQueryArgs)(path, args); +} +function usePage() { + const [page, setPage] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(1); + return [page, setPage]; +} +function Followers(_ref) { + let { + selectedUser, + per_page, + order, + title, + page: passedPage, + setPage: passedSetPage, + className = '', + followLinks = true + } = _ref; + const userId = selectedUser === 'site' ? 0 : selectedUser; + const [followers, setFollowers] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)([]); + const [pages, setPages] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(0); + const [total, setTotal] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(0); + const [localPage, setLocalPage] = usePage(); + const page = passedPage || localPage; + const setPage = passedSetPage || setLocalPage; + const prevLabel = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createInterpolateElement)( /* translators: arrow for previous followers link */ + (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)(' Less', 'activitypub'), { + span: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "wp-block-query-pagination-previous-arrow is-arrow-arrow", + "aria-hidden": "true" + }) + }); + const nextLabel = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createInterpolateElement)( /* translators: arrow for next followers link */ + (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('More ', 'activitypub'), { + span: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "wp-block-query-pagination-next-arrow is-arrow-arrow", + "aria-hidden": "true" + }) + }); + (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => { + const path = getPath(userId, per_page, order, page); + _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default()({ + path + }).then(data => { + setPages(Math.ceil(data.totalItems / per_page)); + setTotal(data.totalItems); + setFollowers(data.orderedItems); + }).catch(error => console.error(error)); + }, [userId, per_page, order, page]); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("div", { + className: "activitypub-follower-block " + className + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("h3", null, title), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("ul", null, followers && followers.map(follower => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("li", { + key: follower.url + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(Follower, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, follower, { + followLinks: followLinks + }))))), pages > 1 && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_pagination__WEBPACK_IMPORTED_MODULE_6__.Pagination, { + page: page, + perPage: per_page, + total: total, + pageClick: setPage, + nextLabel: nextLabel, + prevLabel: prevLabel, + compact: className === 'is-style-compact' + })); +} +function Follower(_ref2) { + let { + name, + icon, + url, + preferredUsername, + followLinks = true + } = _ref2; + const handle = `@${preferredUsername}`; + const extraProps = {}; + if (!followLinks) { + extraProps.onClick = event => event.preventDefault(); + } + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_7__.ExternalLink, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({ + className: "activitypub-link", + href: url, + title: handle + }, extraProps), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("img", { + width: "40", + height: "40", + src: icon.url, + class: "avatar activitypub-avatar" + }), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "activitypub-actor" + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("strong", { + className: "activitypub-name" + }, name), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "sep" + }, "/"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "activitypub-handle" + }, handle))); +} + +/***/ }), + +/***/ "./src/followers/pagination-page.js": +/*!******************************************!*\ + !*** ./src/followers/pagination-page.js ***! + \******************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ PaginationPage: () => (/* binding */ PaginationPage) +/* harmony export */ }); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js"); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__); + + +function PaginationPage(_ref) { + let { + active, + children, + page, + pageClick, + className + } = _ref; + const handleClick = event => { + event.preventDefault(); + !active && pageClick(page); + }; + const classes = classnames__WEBPACK_IMPORTED_MODULE_1___default()('wp-block activitypub-pager', className, { + 'current': active + }); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", { + className: classes, + onClick: handleClick + }, children); +} + +/***/ }), + +/***/ "./src/followers/pagination.js": +/*!*************************************!*\ + !*** ./src/followers/pagination.js ***! + \*************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ Pagination: () => (/* binding */ Pagination) +/* harmony export */ }); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js"); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _pagination_page__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pagination-page */ "./src/followers/pagination-page.js"); + +// Adapted from: https://github.com/Automattic/wp-calypso/tree/trunk/client/components/pagination +// Markup adapted to imitate the core query-pagination component so we can inherit those styles. + + +const PaginationVariant = { + outlined: 'outlined', + minimal: 'minimal' +}; +function Pagination(_ref) { + let { + compact, + nextLabel, + page, + pageClick, + perPage, + prevLabel, + total, + variant = PaginationVariant.outlined + } = _ref; + const getPageList = (page, pageCount) => { + let pageList = [1, page - 2, page - 1, page, page + 1, page + 2, pageCount]; + pageList.sort((a, b) => a - b); + + // Remove pages less than 1, or greater than total number of pages, and remove duplicates + pageList = pageList.filter((pageNumber, index, originalPageList) => { + return pageNumber >= 1 && pageNumber <= pageCount && originalPageList.lastIndexOf(pageNumber) === index; + }); + for (let i = pageList.length - 2; i >= 0; i--) { + if (pageList[i] === pageList[i + 1]) { + pageList.splice(i + 1, 1); + } + } + return pageList; + }; + const pageList = getPageList(page, Math.ceil(total / perPage)); + const className = classnames__WEBPACK_IMPORTED_MODULE_1___default()('alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex', `is-${variant}`, { + 'is-compact': compact + }); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("nav", { + className: className + }, prevLabel && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pagination_page__WEBPACK_IMPORTED_MODULE_2__.PaginationPage, { + key: "prev", + page: page - 1, + pageClick: pageClick, + active: page === 1, + "aria-label": prevLabel, + className: "wp-block-query-pagination-previous block-editor-block-list__block" + }, prevLabel), !compact && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { + className: "block-editor-block-list__block wp-block wp-block-query-pagination-numbers" + }, pageList.map(pageNumber => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pagination_page__WEBPACK_IMPORTED_MODULE_2__.PaginationPage, { + key: pageNumber, + page: pageNumber, + pageClick: pageClick, + active: pageNumber === page, + className: "page-numbers" + }, pageNumber))), nextLabel && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pagination_page__WEBPACK_IMPORTED_MODULE_2__.PaginationPage, { + key: "next", + page: page + 1, + pageClick: pageClick, + active: page === Math.ceil(total / perPage), + "aria-label": nextLabel, + className: "wp-block-query-pagination-next block-editor-block-list__block" + }, nextLabel)); +} + +/***/ }), + +/***/ "./src/shared/use-user-options.js": +/*!****************************************!*\ + !*** ./src/shared/use-user-options.js ***! + \****************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ useUserOptions: () => (/* binding */ useUserOptions) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__); + + + +const enabled = window._activityPubOptions?.enabled; +function useUserOptions() { + const users = enabled?.users ? (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => select('core').getUsers({ + who: 'authors' + })) : []; + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => { + if (!users) { + return []; + } + const withBlogUser = enabled?.site ? [{ + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Whole Site', 'activitypub'), + value: 'site' + }] : []; + return users.reduce((acc, user) => { + acc.push({ + label: user.name, + value: user.id + }); + return acc; + }, withBlogUser); + }, [users]); +} + +/***/ }), + +/***/ "./node_modules/classnames/index.js": +/*!******************************************!*\ + !*** ./node_modules/classnames/index.js ***! + \******************************************/ +/***/ ((module, exports) => { + +var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! + Copyright (c) 2018 Jed Watson. + Licensed under the MIT License (MIT), see + http://jedwatson.github.io/classnames +*/ +/* global define */ + +(function () { + 'use strict'; + + var hasOwn = {}.hasOwnProperty; + var nativeCodeString = '[native code]'; + + function classNames() { + var classes = []; + + for (var i = 0; i < arguments.length; i++) { + var arg = arguments[i]; + if (!arg) continue; + + var argType = typeof arg; + + if (argType === 'string' || argType === 'number') { + classes.push(arg); + } else if (Array.isArray(arg)) { + if (arg.length) { + var inner = classNames.apply(null, arg); + if (inner) { + classes.push(inner); + } + } + } else if (argType === 'object') { + if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) { + classes.push(arg.toString()); + continue; + } + + for (var key in arg) { + if (hasOwn.call(arg, key) && arg[key]) { + classes.push(key); + } + } + } + } + + return classes.join(' '); + } + + if ( true && module.exports) { + classNames.default = classNames; + module.exports = classNames; + } else if (true) { + // register as 'classnames', consistent with npm package name + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { + return classNames; + }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), + __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else {} +}()); + + +/***/ }), + +/***/ "react": +/*!************************!*\ + !*** external "React" ***! + \************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["React"]; + +/***/ }), + +/***/ "@wordpress/api-fetch": +/*!**********************************!*\ + !*** external ["wp","apiFetch"] ***! + \**********************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["apiFetch"]; + +/***/ }), + +/***/ "@wordpress/block-editor": +/*!*************************************!*\ + !*** external ["wp","blockEditor"] ***! + \*************************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["blockEditor"]; + +/***/ }), + +/***/ "@wordpress/blocks": +/*!********************************!*\ + !*** external ["wp","blocks"] ***! + \********************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["blocks"]; + +/***/ }), + +/***/ "@wordpress/components": +/*!************************************!*\ + !*** external ["wp","components"] ***! + \************************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["components"]; + +/***/ }), + +/***/ "@wordpress/data": +/*!******************************!*\ + !*** external ["wp","data"] ***! + \******************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["data"]; + +/***/ }), + +/***/ "@wordpress/element": +/*!*********************************!*\ + !*** external ["wp","element"] ***! + \*********************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["element"]; + +/***/ }), + +/***/ "@wordpress/i18n": +/*!******************************!*\ + !*** external ["wp","i18n"] ***! + \******************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["i18n"]; + +/***/ }), + +/***/ "@wordpress/primitives": +/*!************************************!*\ + !*** external ["wp","primitives"] ***! + \************************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["primitives"]; + +/***/ }), + +/***/ "@wordpress/url": +/*!*****************************!*\ + !*** external ["wp","url"] ***! + \*****************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["url"]; + +/***/ }), + +/***/ "./node_modules/@babel/runtime/helpers/esm/extends.js": +/*!************************************************************!*\ + !*** ./node_modules/@babel/runtime/helpers/esm/extends.js ***! + \************************************************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (/* binding */ _extends) +/* harmony export */ }); +function _extends() { + _extends = Object.assign ? Object.assign.bind() : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; + }; + return _extends.apply(this, arguments); +} + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be in strict mode. +(() => { +"use strict"; +/*!********************************!*\ + !*** ./src/followers/index.js ***! + \********************************/ +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); +/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/people.js"); +/* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./edit */ "./src/followers/edit.js"); + + + +const save = () => null; +(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockType)('activitypub/followers', { + edit: _edit__WEBPACK_IMPORTED_MODULE_1__["default"], + save, + icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_2__["default"] +}); +})(); + +/******/ })() +; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/followers/style-view.css b/build/followers/style-view.css index 824879e..46780f4 100644 --- a/build/followers/style-view.css +++ b/build/followers/style-view.css @@ -1 +1,80 @@ -.activitypub-follower-block.is-style-compact .activitypub-handle,.activitypub-follower-block.is-style-compact .sep{display:none}.activitypub-follower-block.is-style-with-lines ul li{border-bottom:.5px solid;margin-bottom:.5rem;padding-bottom:.5rem}.activitypub-follower-block.is-style-with-lines ul li:last-child{border-bottom:none}.activitypub-follower-block.is-style-with-lines .activitypub-handle,.activitypub-follower-block.is-style-with-lines .activitypub-name{text-decoration:none}.activitypub-follower-block.is-style-with-lines .activitypub-handle:hover,.activitypub-follower-block.is-style-with-lines .activitypub-name:hover{text-decoration:underline}.activitypub-follower-block ul{margin:0!important;padding:0!important}.activitypub-follower-block li{display:flex;margin-bottom:1rem}.activitypub-follower-block img{border-radius:50%;height:40px;margin-right:var(--wp--preset--spacing--20,.5rem);width:40px}.activitypub-follower-block .activitypub-link{align-items:center;color:inherit!important;display:flex;flex-flow:row nowrap;max-width:100%;text-decoration:none!important}.activitypub-follower-block .activitypub-handle,.activitypub-follower-block .activitypub-name{text-decoration:underline;text-decoration-thickness:.8px;text-underline-position:under}.activitypub-follower-block .activitypub-handle:hover,.activitypub-follower-block .activitypub-name:hover{text-decoration:none}.activitypub-follower-block .activitypub-name{font-size:var(--wp--preset--font-size--normal,16px)}.activitypub-follower-block .activitypub-actor{font-size:var(--wp--preset--font-size--small,13px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.activitypub-follower-block .sep{padding:0 .2rem}.activitypub-follower-block .wp-block-query-pagination{margin-top:1.5rem}.activitypub-follower-block .activitypub-pager{cursor:default}.activitypub-follower-block .activitypub-pager.current{opacity:.33}.activitypub-follower-block .page-numbers{padding:0 .2rem}.activitypub-follower-block .page-numbers.current{font-weight:700;opacity:1} +/*!*************************************************************************************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/followers/style.scss ***! + \*************************************************************************************************************************************************************************************************************************************************/ +.activitypub-follower-block.is-style-compact .activitypub-handle, .activitypub-follower-block.is-style-compact .sep { + display: none; +} +.activitypub-follower-block.is-style-with-lines ul li { + border-bottom: 0.5px solid; + padding-bottom: 0.5rem; + margin-bottom: 0.5rem; +} +.activitypub-follower-block.is-style-with-lines ul li:last-child { + border-bottom: none; +} +.activitypub-follower-block.is-style-with-lines .activitypub-name, .activitypub-follower-block.is-style-with-lines .activitypub-handle { + text-decoration: none; +} +.activitypub-follower-block.is-style-with-lines .activitypub-name:hover, .activitypub-follower-block.is-style-with-lines .activitypub-handle:hover { + text-decoration: underline; +} +.activitypub-follower-block ul { + margin: 0 !important; + padding: 0 !important; +} +.activitypub-follower-block li { + display: flex; + margin-bottom: 1rem; +} +.activitypub-follower-block img { + border-radius: 50%; + width: 40px; + height: 40px; + margin-right: var(--wp--preset--spacing--20, 0.5rem); +} +.activitypub-follower-block .activitypub-link { + display: flex; + flex-flow: row nowrap; + align-items: center; + max-width: 100%; + color: inherit !important; + text-decoration: none !important; +} +.activitypub-follower-block .activitypub-name, .activitypub-follower-block .activitypub-handle { + text-decoration: underline; + text-decoration-thickness: 0.8px; + text-underline-position: under; +} +.activitypub-follower-block .activitypub-name:hover, .activitypub-follower-block .activitypub-handle:hover { + text-decoration: none; +} +.activitypub-follower-block .activitypub-name { + font-size: var(--wp--preset--font-size--normal, 16px); +} +.activitypub-follower-block .activitypub-actor { + font-size: var(--wp--preset--font-size--small, 13px); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.activitypub-follower-block .sep { + padding: 0 0.2rem; +} +.activitypub-follower-block .wp-block-query-pagination { + margin-top: 1.5rem; +} +.activitypub-follower-block .activitypub-pager { + cursor: default; +} +.activitypub-follower-block .activitypub-pager.current { + opacity: 0.33; +} +.activitypub-follower-block .page-numbers { + padding: 0 0.2rem; +} +.activitypub-follower-block .page-numbers.current { + opacity: 1; + font-weight: bold; +} + +/*# sourceMappingURL=style-view.css.map*/ \ No newline at end of file diff --git a/build/followers/view.asset.php b/build/followers/view.asset.php index 7f57812..de43b37 100644 --- a/build/followers/view.asset.php +++ b/build/followers/view.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'd645fd4aa610b479e8f4'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '95b455d4d08e5f4afe09'); diff --git a/build/followers/view.js b/build/followers/view.js index f28d93f..f0f3e22 100644 --- a/build/followers/view.js +++ b/build/followers/view.js @@ -1,3 +1,654 @@ -(()=>{var e,t={189:(e,t,a)=>{"use strict";const r=window.wp.element;function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t{e.preventDefault(),!t&&l(n)}},a)}const v={outlined:"outlined",minimal:"minimal"};function b(e){let{compact:t,nextLabel:a,page:n,pageClick:l,perPage:o,prevLabel:i,total:c,variant:s=v.outlined}=e;const p=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(n,Math.ceil(c/o)),b=u()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":t});return(0,r.createElement)("nav",{className:b},i&&(0,r.createElement)(m,{key:"prev",page:n-1,pageClick:l,active:1===n,"aria-label":i,className:"wp-block-query-pagination-previous block-editor-block-list__block"},i),!t&&(0,r.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},p.map((e=>(0,r.createElement)(m,{key:e,page:e,pageClick:l,active:e===n,className:"page-numbers"},e)))),a&&(0,r.createElement)(m,{key:"next",page:n+1,pageClick:l,active:n===Math.ceil(c/o),"aria-label":a,className:"wp-block-query-pagination-next block-editor-block-list__block"},a))}const f=window.wp.components,{namespace:d}=window._activityPubOptions;function w(e){let{selectedUser:t,per_page:a,order:o,title:p,page:u,setPage:m,className:v="",followLinks:f=!0}=e;const w="site"===t?0:t,[y,k]=(0,l.useState)([]),[h,E]=(0,l.useState)(0),[O,x]=(0,l.useState)(0),[_,N]=function(){const[e,t]=(0,l.useState)(1);return[e,t]}(),j=u||_,S=m||N,C=(0,r.createInterpolateElement)(/* translators: arrow for previous followers link */ -(0,s.__)(" Less","activitypub"),{span:(0,r.createElement)("span",{class:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),L=(0,r.createInterpolateElement)(/* translators: arrow for next followers link */ -(0,s.__)("More ","activitypub"),{span:(0,r.createElement)("span",{class:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})});return(0,l.useEffect)((()=>{const e=function(e,t,a,r){const n=`/${d}/users/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,c.addQueryArgs)(n,l)}(w,a,o,j);i()({path:e}).then((e=>{E(Math.ceil(e.totalItems/a)),x(e.totalItems),k(e.orderedItems)})).catch((e=>console.error(e)))}),[w,a,o,j]),(0,r.createElement)("div",{className:"activitypub-follower-block "+v},(0,r.createElement)("h3",null,p),(0,r.createElement)("ul",null,y&&y.map((e=>(0,r.createElement)("li",{key:e.url},(0,r.createElement)(g,n({},e,{followLinks:f})))))),h>1&&(0,r.createElement)(b,{page:j,perPage:a,total:O,pageClick:S,nextLabel:L,prevLabel:C,compact:"is-style-compact"===v}))}function g(e){let{name:t,icon:a,url:l,preferredUsername:o,followLinks:i=!0}=e;const c=`@${o}`,s={};return i||(s.onClick=e=>e.preventDefault()),(0,r.createElement)(f.ExternalLink,n({className:"activitypub-link",href:l,title:c},s),(0,r.createElement)("img",{width:"40",height:"40",src:a.url,class:"avatar activitypub-avatar"}),(0,r.createElement)("span",{class:"activitypub-actor"},(0,r.createElement)("strong",{className:"activitypub-name"},t),(0,r.createElement)("span",{class:"sep"},"/"),(0,r.createElement)("span",{class:"activitypub-handle"},c)))}const y=window.wp.domReady;a.n(y)()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follower-block"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,r.render)((0,r.createElement)(w,t),e)}))}))},184:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e=[],t=0;t{if(!a){var o=1/0;for(p=0;p=l)&&Object.keys(r.O).every((e=>r.O[e](a[c])))?a.splice(c--,1):(i=!1,l0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[a,n,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={638:0,962:0};r.O.j=t=>0===e[t];var t=(t,a)=>{var n,l,[o,i,c]=a,s=0;if(o.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(c)var p=c(r)}for(t&&t(a);sr(189)));n=r.O(n)})(); \ No newline at end of file +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ "./src/followers/followers.js": +/*!************************************!*\ + !*** ./src/followers/followers.js ***! + \************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ Followers: () => (/* binding */ Followers) +/* harmony export */ }); +/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/extends */ "./node_modules/@babel/runtime/helpers/esm/extends.js"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react */ "react"); +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch"); +/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); +/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _pagination__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./pagination */ "./src/followers/pagination.js"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_7__); + + + + + + + + + +const { + namespace +} = window._activityPubOptions; +function getPath(userId, per_page, order, page) { + const path = `/${namespace}/users/${userId}/followers`; + const args = { + per_page, + order, + page, + context: 'full' + }; + return (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_4__.addQueryArgs)(path, args); +} +function usePage() { + const [page, setPage] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(1); + return [page, setPage]; +} +function Followers(_ref) { + let { + selectedUser, + per_page, + order, + title, + page: passedPage, + setPage: passedSetPage, + className = '', + followLinks = true + } = _ref; + const userId = selectedUser === 'site' ? 0 : selectedUser; + const [followers, setFollowers] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)([]); + const [pages, setPages] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(0); + const [total, setTotal] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(0); + const [localPage, setLocalPage] = usePage(); + const page = passedPage || localPage; + const setPage = passedSetPage || setLocalPage; + const prevLabel = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createInterpolateElement)( /* translators: arrow for previous followers link */ + (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)(' Less', 'activitypub'), { + span: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "wp-block-query-pagination-previous-arrow is-arrow-arrow", + "aria-hidden": "true" + }) + }); + const nextLabel = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createInterpolateElement)( /* translators: arrow for next followers link */ + (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('More ', 'activitypub'), { + span: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "wp-block-query-pagination-next-arrow is-arrow-arrow", + "aria-hidden": "true" + }) + }); + (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => { + const path = getPath(userId, per_page, order, page); + _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default()({ + path + }).then(data => { + setPages(Math.ceil(data.totalItems / per_page)); + setTotal(data.totalItems); + setFollowers(data.orderedItems); + }).catch(error => console.error(error)); + }, [userId, per_page, order, page]); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("div", { + className: "activitypub-follower-block " + className + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("h3", null, title), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("ul", null, followers && followers.map(follower => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("li", { + key: follower.url + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(Follower, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, follower, { + followLinks: followLinks + }))))), pages > 1 && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_pagination__WEBPACK_IMPORTED_MODULE_6__.Pagination, { + page: page, + perPage: per_page, + total: total, + pageClick: setPage, + nextLabel: nextLabel, + prevLabel: prevLabel, + compact: className === 'is-style-compact' + })); +} +function Follower(_ref2) { + let { + name, + icon, + url, + preferredUsername, + followLinks = true + } = _ref2; + const handle = `@${preferredUsername}`; + const extraProps = {}; + if (!followLinks) { + extraProps.onClick = event => event.preventDefault(); + } + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_7__.ExternalLink, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({ + className: "activitypub-link", + href: url, + title: handle + }, extraProps), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("img", { + width: "40", + height: "40", + src: icon.url, + class: "avatar activitypub-avatar" + }), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "activitypub-actor" + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("strong", { + className: "activitypub-name" + }, name), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "sep" + }, "/"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.createElement)("span", { + class: "activitypub-handle" + }, handle))); +} + +/***/ }), + +/***/ "./src/followers/pagination-page.js": +/*!******************************************!*\ + !*** ./src/followers/pagination-page.js ***! + \******************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ PaginationPage: () => (/* binding */ PaginationPage) +/* harmony export */ }); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js"); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__); + + +function PaginationPage(_ref) { + let { + active, + children, + page, + pageClick, + className + } = _ref; + const handleClick = event => { + event.preventDefault(); + !active && pageClick(page); + }; + const classes = classnames__WEBPACK_IMPORTED_MODULE_1___default()('wp-block activitypub-pager', className, { + 'current': active + }); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", { + className: classes, + onClick: handleClick + }, children); +} + +/***/ }), + +/***/ "./src/followers/pagination.js": +/*!*************************************!*\ + !*** ./src/followers/pagination.js ***! + \*************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ Pagination: () => (/* binding */ Pagination) +/* harmony export */ }); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js"); +/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _pagination_page__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pagination-page */ "./src/followers/pagination-page.js"); + +// Adapted from: https://github.com/Automattic/wp-calypso/tree/trunk/client/components/pagination +// Markup adapted to imitate the core query-pagination component so we can inherit those styles. + + +const PaginationVariant = { + outlined: 'outlined', + minimal: 'minimal' +}; +function Pagination(_ref) { + let { + compact, + nextLabel, + page, + pageClick, + perPage, + prevLabel, + total, + variant = PaginationVariant.outlined + } = _ref; + const getPageList = (page, pageCount) => { + let pageList = [1, page - 2, page - 1, page, page + 1, page + 2, pageCount]; + pageList.sort((a, b) => a - b); + + // Remove pages less than 1, or greater than total number of pages, and remove duplicates + pageList = pageList.filter((pageNumber, index, originalPageList) => { + return pageNumber >= 1 && pageNumber <= pageCount && originalPageList.lastIndexOf(pageNumber) === index; + }); + for (let i = pageList.length - 2; i >= 0; i--) { + if (pageList[i] === pageList[i + 1]) { + pageList.splice(i + 1, 1); + } + } + return pageList; + }; + const pageList = getPageList(page, Math.ceil(total / perPage)); + const className = classnames__WEBPACK_IMPORTED_MODULE_1___default()('alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex', `is-${variant}`, { + 'is-compact': compact + }); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("nav", { + className: className + }, prevLabel && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pagination_page__WEBPACK_IMPORTED_MODULE_2__.PaginationPage, { + key: "prev", + page: page - 1, + pageClick: pageClick, + active: page === 1, + "aria-label": prevLabel, + className: "wp-block-query-pagination-previous block-editor-block-list__block" + }, prevLabel), !compact && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { + className: "block-editor-block-list__block wp-block wp-block-query-pagination-numbers" + }, pageList.map(pageNumber => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pagination_page__WEBPACK_IMPORTED_MODULE_2__.PaginationPage, { + key: pageNumber, + page: pageNumber, + pageClick: pageClick, + active: pageNumber === page, + className: "page-numbers" + }, pageNumber))), nextLabel && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_pagination_page__WEBPACK_IMPORTED_MODULE_2__.PaginationPage, { + key: "next", + page: page + 1, + pageClick: pageClick, + active: page === Math.ceil(total / perPage), + "aria-label": nextLabel, + className: "wp-block-query-pagination-next block-editor-block-list__block" + }, nextLabel)); +} + +/***/ }), + +/***/ "./src/followers/view.js": +/*!*******************************!*\ + !*** ./src/followers/view.js ***! + \*******************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./style.scss */ "./src/followers/style.scss"); +/* harmony import */ var _followers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./followers */ "./src/followers/followers.js"); +/* harmony import */ var _wordpress_dom_ready__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/dom-ready */ "@wordpress/dom-ready"); +/* harmony import */ var _wordpress_dom_ready__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_dom_ready__WEBPACK_IMPORTED_MODULE_3__); + + + + + +_wordpress_dom_ready__WEBPACK_IMPORTED_MODULE_3___default()(() => { + // iterate over a nodelist + [].forEach.call(document.querySelectorAll('.activitypub-follower-block'), element => { + const attrs = JSON.parse(element.dataset.attrs); + (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.render)((0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_followers__WEBPACK_IMPORTED_MODULE_2__.Followers, attrs), element); + }); +}); + +/***/ }), + +/***/ "./node_modules/classnames/index.js": +/*!******************************************!*\ + !*** ./node_modules/classnames/index.js ***! + \******************************************/ +/***/ ((module, exports) => { + +var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! + Copyright (c) 2018 Jed Watson. + Licensed under the MIT License (MIT), see + http://jedwatson.github.io/classnames +*/ +/* global define */ + +(function () { + 'use strict'; + + var hasOwn = {}.hasOwnProperty; + var nativeCodeString = '[native code]'; + + function classNames() { + var classes = []; + + for (var i = 0; i < arguments.length; i++) { + var arg = arguments[i]; + if (!arg) continue; + + var argType = typeof arg; + + if (argType === 'string' || argType === 'number') { + classes.push(arg); + } else if (Array.isArray(arg)) { + if (arg.length) { + var inner = classNames.apply(null, arg); + if (inner) { + classes.push(inner); + } + } + } else if (argType === 'object') { + if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) { + classes.push(arg.toString()); + continue; + } + + for (var key in arg) { + if (hasOwn.call(arg, key) && arg[key]) { + classes.push(key); + } + } + } + } + + return classes.join(' '); + } + + if ( true && module.exports) { + classNames.default = classNames; + module.exports = classNames; + } else if (true) { + // register as 'classnames', consistent with npm package name + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { + return classNames; + }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), + __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else {} +}()); + + +/***/ }), + +/***/ "./src/followers/style.scss": +/*!**********************************!*\ + !*** ./src/followers/style.scss ***! + \**********************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +// extracted by mini-css-extract-plugin + + +/***/ }), + +/***/ "react": +/*!************************!*\ + !*** external "React" ***! + \************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["React"]; + +/***/ }), + +/***/ "@wordpress/api-fetch": +/*!**********************************!*\ + !*** external ["wp","apiFetch"] ***! + \**********************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["apiFetch"]; + +/***/ }), + +/***/ "@wordpress/components": +/*!************************************!*\ + !*** external ["wp","components"] ***! + \************************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["components"]; + +/***/ }), + +/***/ "@wordpress/dom-ready": +/*!**********************************!*\ + !*** external ["wp","domReady"] ***! + \**********************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["domReady"]; + +/***/ }), + +/***/ "@wordpress/element": +/*!*********************************!*\ + !*** external ["wp","element"] ***! + \*********************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["element"]; + +/***/ }), + +/***/ "@wordpress/i18n": +/*!******************************!*\ + !*** external ["wp","i18n"] ***! + \******************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["i18n"]; + +/***/ }), + +/***/ "@wordpress/url": +/*!*****************************!*\ + !*** external ["wp","url"] ***! + \*****************************/ +/***/ ((module) => { + +"use strict"; +module.exports = window["wp"]["url"]; + +/***/ }), + +/***/ "./node_modules/@babel/runtime/helpers/esm/extends.js": +/*!************************************************************!*\ + !*** ./node_modules/@babel/runtime/helpers/esm/extends.js ***! + \************************************************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (/* binding */ _extends) +/* harmony export */ }); +function _extends() { + _extends = Object.assign ? Object.assign.bind() : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; + }; + return _extends.apply(this, arguments); +} + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = __webpack_modules__; +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/chunk loaded */ +/******/ (() => { +/******/ var deferred = []; +/******/ __webpack_require__.O = (result, chunkIds, fn, priority) => { +/******/ if(chunkIds) { +/******/ priority = priority || 0; +/******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1]; +/******/ deferred[i] = [chunkIds, fn, priority]; +/******/ return; +/******/ } +/******/ var notFulfilled = Infinity; +/******/ for (var i = 0; i < deferred.length; i++) { +/******/ var [chunkIds, fn, priority] = deferred[i]; +/******/ var fulfilled = true; +/******/ for (var j = 0; j < chunkIds.length; j++) { +/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) { +/******/ chunkIds.splice(j--, 1); +/******/ } else { +/******/ fulfilled = false; +/******/ if(priority < notFulfilled) notFulfilled = priority; +/******/ } +/******/ } +/******/ if(fulfilled) { +/******/ deferred.splice(i--, 1) +/******/ var r = fn(); +/******/ if (r !== undefined) result = r; +/******/ } +/******/ } +/******/ return result; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/jsonp chunk loading */ +/******/ (() => { +/******/ // no baseURI +/******/ +/******/ // object to store loaded and loading chunks +/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched +/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded +/******/ var installedChunks = { +/******/ "followers/view": 0, +/******/ "followers/style-view": 0 +/******/ }; +/******/ +/******/ // no chunk on demand loading +/******/ +/******/ // no prefetching +/******/ +/******/ // no preloaded +/******/ +/******/ // no HMR +/******/ +/******/ // no HMR manifest +/******/ +/******/ __webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0); +/******/ +/******/ // install a JSONP callback for chunk loading +/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => { +/******/ var [chunkIds, moreModules, runtime] = data; +/******/ // add "moreModules" to the modules object, +/******/ // then flag all "chunkIds" as loaded and fire callback +/******/ var moduleId, chunkId, i = 0; +/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) { +/******/ for(moduleId in moreModules) { +/******/ if(__webpack_require__.o(moreModules, moduleId)) { +/******/ __webpack_require__.m[moduleId] = moreModules[moduleId]; +/******/ } +/******/ } +/******/ if(runtime) var result = runtime(__webpack_require__); +/******/ } +/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data); +/******/ for(;i < chunkIds.length; i++) { +/******/ chunkId = chunkIds[i]; +/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) { +/******/ installedChunks[chunkId][0](); +/******/ } +/******/ installedChunks[chunkId] = 0; +/******/ } +/******/ return __webpack_require__.O(result); +/******/ } +/******/ +/******/ var chunkLoadingGlobal = globalThis["webpackChunkwordpress_activitypub"] = globalThis["webpackChunkwordpress_activitypub"] || []; +/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0)); +/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal)); +/******/ })(); +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module depends on other loaded chunks and execution need to be delayed +/******/ var __webpack_exports__ = __webpack_require__.O(undefined, ["followers/style-view"], () => (__webpack_require__("./src/followers/view.js"))) +/******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__); +/******/ +/******/ })() +; +//# sourceMappingURL=view.js.map \ No newline at end of file diff --git a/src/follow-me/block.json b/src/follow-me/block.json index 48d18ee..efff7f3 100644 --- a/src/follow-me/block.json +++ b/src/follow-me/block.json @@ -9,7 +9,22 @@ "textdomain": "activitypub", "icon": "groups", "supports": { - "html": false + "html": false, + "color": { + "gradients": true, + "link": true, + "__experimentalDefaultControls": { + "background": true, + "text": true, + "link": true + } + }, + "__experimentalBorder": { + "radius": true, + "width": true, + "color": true, + "style": true + } }, "attributes": { "selectedUser": { diff --git a/src/follow-me/edit.js b/src/follow-me/edit.js index 4382df0..1ec952e 100644 --- a/src/follow-me/edit.js +++ b/src/follow-me/edit.js @@ -34,7 +34,7 @@ function getNormalizedProfile( profile ) { } profile.handle = generateHandle( profile ); const data = { ...DEFAULT_PROFILE_DATA, ...profile }; - data.avatar = data.icon.url; + data.avatar = data?.icon?.url; return data; } @@ -49,6 +49,27 @@ function generateHandle( profile ) { } } +function styleToVar( text ) { + // if it starts with a hash, leave it be + if ( text.match( /^#/ ) ) { + return text; + } + // var:preset|color|luminous-vivid-amber + // var(--wp--preset--color--luminous-vivid-amber) + // we will receive the top format, we need to output the bottom format + const [ , , color ] = text.split( '|' ); + return `var(--wp--preset--color--${ color })`; +} + +function styleToButtonStyle( style ) { + if ( ! style ) { + return {}; + } + return { + backgroundColor: styleToVar( style.color.text ) + } +} + export default function Edit( { attributes, setAttributes } ) { const [ profile, setProfile ] = useState( getNormalizedProfile() ); const { selectedUser } = attributes; @@ -62,6 +83,8 @@ export default function Edit( { attributes, setAttributes } ) { const blockProps = useBlockProps(); const usersOptions = useUserOptions(); + const style = styleToButtonStyle( attributes?.style?.elements?.link ); + return (
@@ -74,13 +97,13 @@ export default function Edit( { attributes, setAttributes } ) { /> - +
); } function Profile( profile ) { - const { handle, avatar, name } = profile; + const { handle, avatar, name, style } = profile; return (
@@ -88,16 +111,16 @@ function Profile( profile ) {
{ name }
{ handle }
- + ); } -function Follow( { profile } ) { +function Follow( { profile, style } ) { const [ isOpen, setIsOpen ] = useState( false ); return ( <> -