@semapps/activitypub-components 0.5.3 → 0.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,4 +1,943 @@
1
- import*as e from"react";import t,{createContext as n,useState as r,useContext as o,useEffect as i,useMemo as a,useCallback as l,forwardRef as c,useImperativeHandle as u}from"react";import{useGetIdentity as s,fetchUtils as d,useRecordContext as f,useNotify as p,Form as m,TextField as h,DateField as v,RichTextField as g,useGetOne as b,LinearProgress as y,useGetList as E}from"react-admin";import w from"@tiptap/extension-placeholder";import{ToggleButtonGroup as x,ToggleButton as O,List as T,ListItem as k,ListItemText as L,Menu as A,MenuItem as C,Box as I,useTheme as S,Card as j,FormHelperText as R,Avatar as P,Button as N,Typography as z,CircularProgress as _}from"@mui/material";import D from"@mui/styles/makeStyles";import F from"@mui/icons-material/Send";import{buildBlankNodesQuery as U,useDataModel as B}from"@semapps/semantic-data-provider";import{AuthDialog as H}from"@semapps/auth-provider";import{mergeAttributes as M}from"@tiptap/core";import G from"@tiptap/extension-mention";import{useEditor as V,EditorContent as W,ReactRenderer as q}from"@tiptap/react";import J from"@tiptap/starter-kit";import K from"@tiptap/extension-underline";import Q from"@tiptap/extension-link";import X from"@tiptap/extension-text-align";import Y from"@tiptap/extension-image";import Z from"@tiptap/extension-text-style";import{Color as $}from"@tiptap/extension-color";import ee from"@tiptap/extension-highlight";import{styled as te,alpha as ne}from"@mui/material/styles";import{useTranslate as re,useResourceContext as oe,useInput as ie}from"ra-core";import{Labeled as ae,InputHelperText as le}from"ra-ui-materialui";import ce from"@mui/icons-material/ArrowDropDown";import ue from"@mui/icons-material/FormatBold";import se from"@mui/icons-material/FormatItalic";import de from"@mui/icons-material/FormatUnderlined";import fe from"@mui/icons-material/FormatStrikethrough";import pe from"@mui/icons-material/Code";import me from"@mui/icons-material/FormatColorText";import he from"@mui/icons-material/FontDownload";import{grey as ve,red as ge,orange as be,yellow as ye,green as Ee,blue as we,purple as xe}from"@mui/material/colors";import Oe from"@mui/icons-material/FormatAlignCenter";import Te from"@mui/icons-material/FormatAlignLeft";import ke from"@mui/icons-material/FormatAlignRight";import Le from"@mui/icons-material/FormatAlignJustify";import Ae from"@mui/icons-material/FormatListBulleted";import Ce from"@mui/icons-material/FormatListNumbered";import Ie from"@mui/icons-material/InsertLink";import Se from"@mui/icons-material/Image";import je from"@mui/icons-material/FormatQuote";import Re from"@mui/icons-material/FormatClear";import{ReferenceField as Pe,AvatarWithLabelField as Ne,ReferenceArrayField as ze}from"@semapps/field-components";import _e from"tippy.js";function De(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Fe(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?De(Object(n),!0).forEach((function(t){Me(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):De(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Ue(){
2
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3
- Ue=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var o=t&&t.prototype instanceof d?t:d,i=Object.create(o.prototype),a=new O(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return k()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var l=E(a,n);if(l){if(l===s)continue;return l}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===s)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(e,n,a),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var s={};function d(){}function f(){}function p(){}var m={};l(m,o,(function(){return this}));var h=Object.getPrototypeOf,v=h&&h(h(T([])));v&&v!==t&&n.call(v,o)&&(m=v);var g=p.prototype=d.prototype=Object.create(m);function b(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function y(e,t){var r;this._invoke=function(o,i){function a(){return new t((function(r,a){!function r(o,i,a,l){var c=u(e[o],e,i);if("throw"!==c.type){var s=c.arg,d=s.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,l)}),(function(e){r("throw",e,a,l)})):t.resolve(d).then((function(e){s.value=e,a(s)}),(function(e){return r("throw",e,a,l)}))}l(c.arg)}(o,i,r,a)}))}return r=r?r.then(a,a):a()}}function E(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,E(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,s;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function T(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return f.prototype=p,l(g,"constructor",p),l(p,"constructor",f),f.displayName=l(p,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,l(e,a,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},b(y.prototype),l(y.prototype,i,(function(){return this})),e.AsyncIterator=y,e.async=function(t,n,r,o,i){void 0===i&&(i=Promise);var a=new y(c(t,n,r,o),i);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},b(g),l(g,a,"Generator"),l(g,o,(function(){return this})),l(g,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=T,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var l=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(l&&c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(l){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),x(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;x(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}function Be(e,t,n,r,o,i,a){try{var l=e[i](a),c=l.value}catch(e){return void n(e)}l.done?t(c):Promise.resolve(c).then(r,o)}function He(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Be(i,r,o,a,l,"next",e)}function l(e){Be(i,r,o,a,l,"throw",e)}a(void 0)}))}}function Me(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ge(){return(Ge=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function Ve(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function We(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,l=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){l=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(l)throw o}}return i}(e,t)||Je(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function qe(e){return function(e){if(Array.isArray(e))return Ke(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Je(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Je(e,t){if(e){if("string"==typeof e)return Ke(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ke(e,t):void 0}}function Ke(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Qe(e){var t,n,r="";if("string"==typeof e||"number"==typeof e)r+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(n=Qe(e[t]))&&(r&&(r+=" "),r+=n);else for(t in e)e[t]&&(r&&(r+=" "),r+=t);return r}function Xe(){for(var e,t,n=0,r="";n<arguments.length;)(e=arguments[n++])&&(t=Qe(e))&&(r&&(r+=" "),r+=t);return r}var Ye,Ze=n(void 0),$e=function(t){var n=t.children,r=t.value;return e.createElement(Ze.Provider,{value:r},n)},et=function(){var e=r(!1),t=e[0],n=e[1],a=o(Ze);return i((function(){var e=function(){n(!0)};return null!=a&&(n(a.isEditable),a.on("create",e)),function(){null!=a&&a.off("create",e)}}),[a]),t?a:null},tt=function(){return(tt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},nt=function(t){var n=et(),o=re(),a=r([]),l=a[0],c=a[1],u=o("ra.tiptap.bold",{_:"Bold"}),s=o("ra.tiptap.italic",{_:"Italic"}),d=o("ra.tiptap.underline",{_:"Underline"}),f=o("ra.tiptap.strike",{_:"Strikethrough"}),p=o("ra.tiptap.code",{_:"Code"});i((function(){var e=function(){c((function(){return rt.reduce((function(e,t){return n&&n.isActive(t)&&e.push(t),e}),[])}))};return n&&(n.on("update",e),n.on("selectionUpdate",e)),function(){n&&(n.off("update",e),n.off("selectionUpdate",e))}}),[n]);return e.createElement(x,tt({},t,{disabled:!(null==n?void 0:n.isEditable),onChange:function(e,t){rt.forEach((function(e){var r=n&&n.isActive(e)&&!t.includes(e),o=n&&!n.isActive(e)&&t.includes(e);(r||o)&&ot[e](n)}))},value:l}),e.createElement(O,{value:"bold","aria-label":u,title:u},e.createElement(ue,{fontSize:"inherit"})),e.createElement(O,{value:"italic","aria-label":s,title:s},e.createElement(se,{fontSize:"inherit"})),e.createElement(O,{value:"underline","aria-label":d,title:d},e.createElement(de,{fontSize:"inherit"})),e.createElement(O,{value:"strike","aria-label":f,title:f},e.createElement(fe,{fontSize:"inherit"})),e.createElement(O,{value:"code","aria-label":p,title:p},e.createElement(pe,{fontSize:"inherit"})))},rt=["bold","italic","underline","strike","code"],ot={bold:function(e){return e.chain().focus().toggleBold().run()},italic:function(e){return e.chain().focus().toggleItalic().run()},underline:function(e){return e.chain().focus().toggleUnderline().run()},strike:function(e){return e.chain().focus().toggleStrike().run()},code:function(e){return e.chain().focus().toggleCode().run()}},it=function(){return(it=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},at=function(t){var n=et(),o=re(),a=o("ra.tiptap.list_bulleted",{_:"Bulleted list"}),l=o("ra.tiptap.list_numbered",{_:"Numbered list"}),c=r(),u=c[0],s=c[1];return i((function(){var e=function(){s((function(){return lt.reduce((function(e,t){return n&&n.isActive(t)?t:e}),void 0)}))};return n&&(n.on("update",e),n.on("selectionUpdate",e)),function(){n&&(n.off("update",e),n.off("selectionUpdate",e))}}),[n]),e.createElement(x,it({},t,{disabled:!(null==n?void 0:n.isEditable),exclusive:!0,onChange:function(e,t){lt.forEach((function(e){var r=n&&n.isActive(e)&&t!==e,o=n&&!n.isActive(e)&&t===e;(r||o)&&ct[e](n)}))},value:u}),e.createElement(O,{value:"bulletList","aria-label":a,title:a},e.createElement(Ae,{fontSize:"inherit"})),e.createElement(O,{value:"orderedList","aria-label":l,title:l},e.createElement(Ce,{fontSize:"inherit"})))},lt=["bulletList","orderedList"],ct={bulletList:function(e){return e.chain().focus().toggleBulletList().run()},orderedList:function(e){return e.chain().focus().toggleOrderedList().run()}},ut=function(){return(ut=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},st=function(t){var n=et(),o=re(),a=r("left"),l=a[0],c=a[1],u=o("ra.tiptap.align_left",{_:"Align left"}),s=o("ra.tiptap.align_right",{_:"Align right"}),d=o("ra.tiptap.align_center",{_:"Center"}),f=o("ra.tiptap.align_justify",{_:"Justify"});i((function(){var e=function(){c((function(e){return dt.reduce((function(e,t){return n&&n.isActive({textAlign:t})?t:e}),e)}))};return n&&(n.on("update",e),n.on("selectionUpdate",e)),function(){n&&(n.off("update",e),n.off("selectionUpdate",e))}}),[n]);return e.createElement(x,ut({},t,{disabled:!(null==n?void 0:n.isEditable),exclusive:!0,onChange:function(e,t){ft[t]&&ft[t](n)},value:l}),e.createElement(O,{value:"left","aria-label":u,title:u},e.createElement(Te,{fontSize:"inherit"})),e.createElement(O,{value:"center","aria-label":d,title:d},e.createElement(Oe,{fontSize:"inherit"})),e.createElement(O,{value:"right","aria-label":s,title:s},e.createElement(ke,{fontSize:"inherit"})),e.createElement(O,{value:"justify","aria-label":f,title:f},e.createElement(Le,{fontSize:"inherit"})))},dt=["left","center","right","justify","code"],ft={left:function(e){return e.chain().focus().setTextAlign("left").run()},center:function(e){return e.chain().focus().setTextAlign("center").run()},right:function(e){return e.chain().focus().setTextAlign("right").run()},justify:function(e){return e.chain().focus().setTextAlign("justify").run()}},pt=function(){return(pt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},mt=function(t){var n=et(),o=re(),a=function(){var e=et(),t=r(e?e.state.doc.textBetween(e.state.selection.from,e.state.selection.to):null),n=t[0],o=t[1];return i((function(){var t=function(){o(e?e.state.doc.textBetween(e.state.selection.from,e.state.selection.to):null)};return e&&e.on("selectionUpdate",t),function(){e&&e.off("selectionUpdate",t)}}),[e]),n}(),l=o("ra.tiptap.link",{_:"Add a link"});return e.createElement(O,pt({"aria-label":l,title:l},t,{disabled:!(null==n?void 0:n.isEditable)||!a,value:"link",onClick:function(){if(n.can().setLink({href:""})){var e=window.prompt("URL");n.chain().focus().extendMarkRange("link").setLink({href:e}).run()}},selected:n&&n.isActive("link")}),e.createElement(Ie,{fontSize:"inherit"}))},ht=function(){return(ht=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},vt=function(t){var n=et(),o=re(),a=r(!1),l=a[0],c=a[1],u=o("ra.tiptap.blockquote",{_:"Blockquote"});return i((function(){var e=function(){c(n&&n.isActive("blockquote"))};return n&&(n.on("update",e),n.on("selectionUpdate",e)),function(){n&&(n.off("update",e),n.off("selectionUpdate",e))}}),[n]),e.createElement(O,ht({"aria-label":u,title:u},t,{disabled:!(null==n?void 0:n.isEditable),onClick:function(){return n.chain().focus().toggleBlockquote().run()},selected:l,value:"quote"}),e.createElement(je,{fontSize:"inherit"}))},gt=function(){return(gt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},bt=function(t){var n=et(),r=re()("ra.tiptap.clear_format",{_:"Clear format"});return e.createElement(O,gt({"aria-label":r,title:r},t,{disabled:!(null==n?void 0:n.isEditable),value:"clear",onClick:function(){return n.chain().focus().unsetAllMarks().run()}}),e.createElement(Re,{fontSize:"inherit"}))},yt=function(t){var n,o=re(),a=et(),l=r(null),c=l[0],u=l[1],s=t.size,d=r(Et[0]),f=d[0],p=d[1];return i((function(){var e=function(){p((function(e){return Et.reduce((function(e,t){if(a){if("paragraph"===t.value&&a.isActive("paragraph"))return t;if(a.isActive("heading",{level:t.level}))return t}return e}),e)}))};return a&&(a.on("update",e),a.on("selectionUpdate",e)),function(){a&&(a.off("update",e),a.off("selectionUpdate",e))}}),[a]),e.createElement(Ot,null,e.createElement(T,{component:"nav","aria-label":o("ra.tiptap.select_level",{_:"Select the level"}),dense:!0,disablePadding:!0,className:xt.list},e.createElement(k,{button:!0,"aria-haspopup":"true","aria-controls":"level-menu","aria-label":o("ra.tiptap.current_level",{_:"Current level"}),disabled:!(null==a?void 0:a.isEditable),onClick:function(e){u(e.currentTarget)},className:Xe((n={},n[xt.sizeSmall]="small"===s,n[xt.sizeLarge]="large"===s,n))},e.createElement(L,{primary:o(f.label,{_:f.defaultLabel})}),e.createElement(ce,null))),e.createElement(A,{anchorEl:c,open:Boolean(c),id:"level-menu",onClose:function(e){u(null)}},Et.map((function(t,n){return e.createElement(C,{key:t.label,selected:t===f,onClick:function(e){!function(e,t){u(null);var n=Et[t];"paragraph"===n.value?a.chain().focus().setParagraph().run():"heading"===n.value&&a.chain().focus().setHeading({level:n.level}).run()}(0,n)}},o(t.label,{_:t.defaultLabel}))}))))},Et=[{label:"ra.tiptap.paragraph",defaultLabel:"Normal",value:"paragraph"},{label:"ra.tiptap.heading1",defaultLabel:"Heading 1",value:"heading",level:1},{label:"ra.tiptap.heading2",defaultLabel:"Heading 2",value:"heading",level:2},{label:"ra.tiptap.heading3",defaultLabel:"Heading 3",value:"heading",level:3},{label:"ra.tiptap.heading4",defaultLabel:"Heading 4",value:"heading",level:4},{label:"ra.tiptap.heading5",defaultLabel:"Heading 5",value:"heading",level:5},{label:"ra.tiptap.heading6",defaultLabel:"Heading 6",value:"heading",level:6}],wt="RaRichTextInputLevelSelect",xt={list:"".concat(wt,"-list"),sizeSmall:"".concat(wt,"-sizeSmall"),sizeLarge:"".concat(wt,"-sizeLarge")},Ot=te("div")((function(e){var t,n=e.theme;return(t={})["&.".concat(xt.list)]={borderRadius:n.shape.borderRadius,border:"1px solid ".concat(ne(n.palette.action.active,.12))},t["& .".concat(xt.sizeSmall)]={paddingTop:1,paddingBottom:1,"& .MuiTypography-root":{fontSize:n.typography.pxToRem(13)}},t["& .".concat(xt.sizeLarge)]={paddingTop:8,paddingBottom:8,"& .MuiTypography-root":{fontSize:n.typography.pxToRem(15)}},t})),Tt=function(){return(Tt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},kt=function(t){var n=re(),r=et(),o=n("ra.tiptap.image",{_:"Image"}),i=e.useCallback((function(){var e=window.prompt(n("ra.tiptap.image_dialog",{_:"Image URL"}));e&&r.chain().focus().setImage({src:e}).run()}),[r,n]);return r?e.createElement(O,Tt({"aria-label":o,title:o},t,{disabled:!(null==r?void 0:r.isEditable),value:"image",onClick:i}),e.createElement(Se,{fontSize:"inherit"})):null},Lt=function(){return(Lt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};!function(e){e.FONT="font",e.BACKGROUND="background"}(Ye||(Ye={}));var At=function(t){var n=re(),r=et(),o=e.useState(!1),i=o[0],a=o[1],l=e.useState(Ye.FONT),c=l[0],u=l[1],s=n("ra.tiptap.color",{_:"Color"}),d=n("ra.tiptap.highlight",{_:"Highlight"}),f=function(e){a(!0),u(e)};return r?e.createElement(I,{sx:{position:"relative"}},e.createElement(It,{onClick:function(){return a(!1)}},e.createElement(x,null,e.createElement(O,Lt({"aria-label":s,title:s},t,{disabled:!(null==r?void 0:r.isEditable),value:"color",onClick:function(){return f(Ye.FONT)}}),e.createElement(me,{fontSize:"inherit"})),e.createElement(O,Lt({"aria-label":d,title:d},t,{disabled:!(null==r?void 0:r.isEditable),value:"highlight",onClick:function(){return f(Ye.BACKGROUND)}}),e.createElement(he,{fontSize:"inherit"}))),i&&e.createElement(Ct,{editor:r,close:function(){return a(!1)},colorType:c}))):null},Ct=function(t){var n,r,o=t.editor,i=t.close,a=t.colorType,l=S(),c=[ve,ge,be,ye,Ee,we,xe];return e.createElement(j,{sx:{position:"absolute",top:38,left:a===Ye.FONT?0:"50%",p:1,border:"1px solid ".concat(null===(r=null===(n=null==l?void 0:l.palette)||void 0===n?void 0:n.background)||void 0===r?void 0:r.default),display:"flex",flexDirection:"column",gap:1,zIndex:1}},[900,700,500,300,100].map((function(t,n){return e.createElement(I,{key:"shade-".concat(t),sx:{display:"flex",flexDirection:"row",gap:1}},c.map((function(r,l){return e.createElement(I,{key:"color-".concat(n*c.length+l+1),sx:{width:16,height:16,cursor:"pointer",backgroundColor:r[t]},onClick:function(){return function(e){a===Ye.FONT?o.chain().focus().setColor(e).run():o.chain().focus().toggleHighlight({color:e}).run(),i()}(r[t])}})})))})))},It=function(t){var n=t.className,r=t.onClick,o=t.children,i=e.useRef(null);return St(i,r),e.createElement("div",{className:n,ref:i},o)},St=function(t,n){e.useEffect((function(){var e=function(e){t.current&&!t.current.contains(e.target)&&n()};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[t,n])},jt=function(){return(jt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},Rt=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n},Pt=function(t){var n=t.size,r=void 0===n?"medium":n,o=t.children,i=void 0===o?e.createElement(e.Fragment,null,e.createElement(yt,{size:r}),e.createElement(nt,{size:r}),e.createElement(At,{size:r}),e.createElement(st,{size:r}),e.createElement(at,{size:r}),e.createElement(mt,{size:r}),e.createElement(kt,{size:r}),e.createElement(vt,{size:r}),e.createElement(bt,{size:r})):o,a=Rt(t,["size","children"]);return e.createElement(zt,jt({className:Nt.root},a),i)},Nt={root:"".concat("RaRichTextInputToolbar","-root")},zt=te("div")((function(e){var t,n=e.theme;return(t={})["&.".concat(Nt.root)]={display:"flex",flexWrap:"wrap",alignItems:"center","& > *":{marginRight:n.spacing(1),marginBottom:n.spacing(1)},"& > *:last-child":{marginRight:0}},t})),_t=function(){return(_t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},Dt=function(t){var n,r,o=t.className,a=t.defaultValue,l=void 0===a?"":a,c=t.disabled,u=void 0!==c&&c,s=t.editorOptions,d=void 0===s?Ut:s,f=t.fullWidth,p=t.helperText,m=t.label,h=t.readOnly,v=void 0!==h&&h,g=t.source,b=t.toolbar,y=oe(t),E=ie(_t(_t({},t),{source:g,defaultValue:l})),w=E.id,x=E.field,O=E.isRequired,T=E.fieldState,k=E.formState.isSubmitted,L=V(_t(_t({},d),{editable:!u&&!v,content:x.value,editorProps:_t(_t({},null==d?void 0:d.editorProps),{attributes:_t(_t({},null===(n=null==d?void 0:d.editorProps)||void 0===n?void 0:n.attributes),{id:w})})})),A=T.error,C=T.invalid,I=T.isTouched;return i((function(){if(L){var e=L.state.selection,t=e.from,n=e.to;L.commands.setContent(x.value,!1,{preserveWhitespace:!0}),L.commands.setTextSelection({from:t,to:n})}}),[L,x.value]),i((function(){var e;L&&L.setOptions({editable:!u&&!v,editorProps:_t(_t({},null==d?void 0:d.editorProps),{attributes:_t(_t({},null===(e=null==d?void 0:d.editorProps)||void 0===e?void 0:e.attributes),{id:w})})})}),[u,L,v,w,null==d?void 0:d.editorProps,null===(r=null==d?void 0:d.editorProps)||void 0===r?void 0:r.attributes]),i((function(){if(L){var e=function(){if(L.isEmpty)return x.onChange(""),void x.onBlur();var e=L.getHTML();x.onChange(e),x.onBlur()};return L.on("update",e),function(){L.off("update",e)}}}),[L,x]),e.createElement(ae,{isRequired:O,label:m,id:"".concat(w,"-label"),color:(null==T?void 0:T.invalid)?"error":void 0,source:g,resource:y,fullWidth:f},e.createElement(Ft,{className:Xe("ra-input","ra-input-".concat(g),o),editor:L,error:A,helperText:p,id:w,isTouched:I,isSubmitted:k,invalid:C,toolbar:b||e.createElement(Pt,null)}))},Ft=function(t){var n=t.className,r=t.editor,o=t.error;t.fullWidth;var i=t.helperText,a=t.id,l=t.isTouched,c=t.isSubmitted,u=t.invalid,s=t.toolbar;return e.createElement(Ht,{className:n},e.createElement($e,{value:r},s,e.createElement(W,{"aria-labelledby":"".concat(a,"-label"),className:Bt.editorContent,editor:r})),e.createElement(R,{className:(l||c)&&u?"ra-rich-text-input-error":"",error:(l||c)&&u},e.createElement(le,{touched:l||c,error:null==o?void 0:o.message,helperText:i})))},Ut={extensions:[J,K,Q,X.configure({types:["heading","paragraph"]}),Y.configure({inline:!0}),Z,$,ee.configure({multicolor:!0})]},Bt={editorContent:"".concat("RaRichTextInput","-editorContent")},Ht=te("div",{name:"RaRichTextInput",overridesResolver:function(e,t){return t.root}})((function(e){var t,n=e.theme;return(t={display:"flex",flexDirection:"column",alignItems:"center"})["& .".concat(Bt.editorContent)]={width:"100%","& .ProseMirror":{backgroundColor:n.palette.background.default,borderColor:"light"===n.palette.mode?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)",borderRadius:n.shape.borderRadius,borderStyle:"solid",borderWidth:"1px",padding:n.spacing(1),'&[contenteditable="false"], &[contenteditable="false"]:hover, &[contenteditable="false"]:focus':{backgroundColor:n.palette.action.disabledBackground},"&:hover":{backgroundColor:n.palette.action.hover},"&:focus":{backgroundColor:n.palette.background.default},"& p":{margin:"0 0 1em 0","&:last-child":{marginBottom:0}}}},t})),Mt={ACCEPT:"Accept",ADD:"Add",ANNOUNCE:"Announce",ARRIVE:"Arrive",BLOCK:"Block",CREATE:"Create",DELETE:"Delete",DISLIKE:"Dislike",FLAG:"Flag",FOLLOW:"Follow",IGNORE:"Ignore",INVITE:"Invite",JOIN:"Join",LEAVE:"Leave",LIKE:"Like",LISTEN:"Listen",MOVE:"Move",OFFER:"Offer",QUESTION:"Question",REJECT:"Reject",READ:"Read",REMOVE:"Remove",TENTATIVE_REJECT:"TentativeReject",TENTATIVE_ACCEPT:"TentativeAccept",TRAVAL:"Travel",UNDO:"Undo",UPDATE:"Update",VIEW:"View"},Gt={APPLICATION:"Application",GROUP:"Group",ORGANIZATION:"Organization",PERSON:"Person",SERVICE:"Service"},Vt={ARTICLE:"Article",AUDIO:"Audio",DOCUMENT:"Document",EVENT:"Event",IMAGE:"Image",NOTE:"Note",PAGE:"Page",PLACE:"Place",PROFILE:"Profile",RELATIONSHIP:"Relationship",TOMBSTONE:"Tombstone",VIDEO:"Video"},Wt="https://www.w3.org/ns/activitystreams#Public",qt=function(){var e=s().identity,t=a((function(){var t;if(null!=e&&e.webIdData)return null==e||null===(t=e.webIdData)||void 0===t?void 0:t.outbox}),[e]),n=a((function(){var t,n;if(null!=e&&e.webIdData)return(null==e||null===(t=e.webIdData)||void 0===t||null===(n=t.endpoints)||void 0===n?void 0:n["void:sparqlEndpoint"])||(null==e?void 0:e.id)+"/sparql"}),[e]);return{post:l(function(){var e=He(Ue().mark((function e(n){var r,o,i;return Ue().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw new Error("Cannot post to outbox before user identity is loaded. Please use the loaded argument of useOutbox");case 2:return r=localStorage.getItem("token"),e.next=5,d.fetchJson(t,{method:"POST",body:JSON.stringify(Fe({"@context":"https://www.w3.org/ns/activitystreams"},n)),headers:new Headers({"Content-Type":"application/ld+json",Authorization:"Bearer ".concat(r)})});case 5:return o=e.sent,i=o.headers,e.abrupt("return",i.get("Location"));case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[t]),fetch:l(He(Ue().mark((function e(){var r,o,i,a,l;return Ue().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n&&t){e.next=2;break}return e.abrupt("return");case 2:return r=localStorage.getItem("token"),o=U(["as:object"]),i="\n PREFIX as: <https://www.w3.org/ns/activitystreams#>\n CONSTRUCT {\n ?s1 ?p1 ?o1 .\n ".concat(o.construct,"\n }\n WHERE {\n <").concat(t,"> as:items ?s1 .\n ?s1 ?p1 ?o1 .\n ").concat(o.where,"\n }\n "),e.next=7,d.fetchJson(n,{method:"POST",body:i,headers:new Headers({Accept:"application/ld+json",Authorization:r?"Bearer ".concat(r):void 0})});case 7:if(a=e.sent,!(l=a.json)["@graph"]){e.next=13;break}return e.abrupt("return",l["@graph"]);case 13:return e.abrupt("return",null);case 14:case"end":return e.stop()}}),e)}))),[n,t]),url:t,loaded:!!t,owner:null==e?void 0:e.id}},Jt=G.extend({renderHTML:function(e){var t=e.node,n=e.HTMLAttributes;return["span",M(this.options.HTMLAttributes,n),"@".concat(t.attrs.id.label)]},addAttributes:function(){return{label:{default:null,parseHTML:function(e){return{label:e.getAttribute("data-mention-label")}},renderHTML:function(e){return e.id.label?{"data-mention-label":e.id.label}:{}}},id:{default:null,parseHTML:function(e){return{id:e.getAttribute("data-mention-id")}},renderHTML:function(e){return e.id.id?{"data-mention-id":e.id.id}:{}}}}}}),Kt=D((function(e){return{form:{marginTop:-12},container:{paddingLeft:80,position:"relative"},avatar:{position:"absolute",top:16,left:0,bottom:0,width:64,height:64},editorContent:{"& > div":{backgroundColor:"rgba(0, 0, 0, 0.09)",padding:"2px 12px",borderWidth:"0px !important",borderRadius:0,borderBottom:"1px solid #FFF",minHeight:60,outline:"unset !important"},"& > div > p":{marginTop:12,marginBottom:12,fontFamily:e.typography.body1.fontFamily,marginBlockStart:"0.5em",marginBlockEnd:"0.5em"},"& > div > p.is-editor-empty:first-child::before":{color:"grey",content:"attr(data-placeholder)",float:"left",height:0,pointerEvents:"none"}},button:{marginTop:-10,marginBottom:15}}})),Qt=function(){return null},Xt=function(e){var n,o,i,a,c=e.context,u=e.placeholder,d=e.helperText,h=e.mentions,v=e.userResource,g=e.addItem,b=e.removeItem,y=f(),E=s(),x=E.identity,O=E.isLoading,T=B(v),k=Kt(),L=p(),A=qt(),C=We(r(!1),2),S=C[0],j=C[1],R=We(r(!1),2),z=R[0],_=R[1],D=l(function(){var e=He(Ue().mark((function e(t){var n,r,o,i,a;return Ue().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=(new DOMParser).parseFromString(t.comment,"text/html"),r=Array.from(n.body.getElementsByClassName("mention")),o=[],r.forEach((function(e){var t=e.attributes["data-mention-id"].value,r=e.attributes["data-mention-label"].value,i=n.createElement("a");i.setAttribute("href",new URL(window.location.href).origin+"/"+v+"/"+encodeURIComponent(t)+"/show"),i.textContent="@"+r,e.parentNode.replaceChild(i,e),o.push(t)})),"undefined"!==n.body.innerHTML){e.next=8;break}L("Votre commentaire est vide",{type:"error"}),e.next=23;break;case 8:return i=Date.now(),a={type:Vt.NOTE,attributedTo:A.owner,content:n.body.innerHTML,inReplyTo:y[c],published:(new Date).toISOString()},e.prev=10,g(Fe({id:i},a)),j(!1),e.next=15,A.post(Fe(Fe({},a),{},{to:[].concat(o,[Wt])}));case 15:L("Commentaire posté avec succès",{type:"success"}),e.next=23;break;case 18:e.prev=18,e.t0=e.catch(10),console.error(e.t0),b(i),L(e.t0.message,{type:"error"});case 23:case"end":return e.stop()}}),e,null,[[10,18]])})));return function(t){return e.apply(this,arguments)}}(),[A,L,j,g,b]),U=l((function(){null!=x&&x.id||_(!0)}),[x,_]);return h&&!h.items||O?null:t.createElement(t.Fragment,null,t.createElement(m,{onSubmit:D,className:k.form},t.createElement(I,{className:k.container,onClick:U},t.createElement(P,{src:(null==x||null===(n=x.webIdData)||void 0===n?void 0:n[null==T||null===(o=T.fieldsMapping)||void 0===o?void 0:o.image])||(null==x||null===(i=x.profileData)||void 0===i?void 0:i[null==T||null===(a=T.fieldsMapping)||void 0===a?void 0:a.image]),className:k.avatar}),t.createElement(Dt,{source:"comment",label:" ",toolbar:t.createElement(Qt,null),fullWidth:!0,classes:{editorContent:k.editorContent},editorOptions:Fe(Fe({},Ut),{},{onFocus:function(){j(!0)},extensions:[].concat(qe(Ut.extensions),[u?w.configure({placeholder:u}):null,h?Jt.configure({HTMLAttributes:{class:"mention"},suggestion:h}):null]),editable:!(null==x||!x.id)}),helperText:d}),S&&t.createElement(N,{type:"submit",size:"small",variant:"contained",color:"primary",endIcon:t.createElement(F,null),className:k.button},"Envoyer"))),t.createElement(H,{open:z,onClose:function(){return _(!1)},message:"Pour poster un commentaire, vous devez être connecté."}))},Yt=D((function(){return{container:{paddingLeft:80,marginTop:8,minHeight:80,position:"relative"},avatar:{position:"absolute",top:0,left:0,bottom:0,width:64,height:64},text:{paddingTop:2,paddingBottom:8},label:{fontWeight:"bold"},content:{"& p":{marginBlockStart:"0.5em",marginBlockEnd:"0.5em"}},loading:{zIndex:1e3,backgroundColor:"white",opacity:.5,position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",alignItems:"center",justifyContent:"center",minHeight:200,marginTop:5}}})),Zt=function(e){var n=e.comments,r=e.userResource,o=e.loading,i=Yt(),a=B(r);return t.createElement(I,{position:"relative"},n&&n.sort((function(e,t){return new Date(t.published)-new Date(e.published)})).map((function(e){var n,o;return t.createElement(I,{className:i.container,key:e.id},t.createElement(I,{className:i.avatar},t.createElement(Pe,{record:e,reference:r,source:"attributedTo",linkType:"show"},t.createElement(Ne,{image:null==a||null===(n=a.fieldsMapping)||void 0===n?void 0:n.image}))),t.createElement(I,{className:i.text},t.createElement(z,{variant:"body2"},t.createElement(Pe,{record:e,reference:r,source:"attributedTo",linkType:"show"},t.createElement(h,{variant:"body2",source:null==a||null===(o=a.fieldsMapping)||void 0===o?void 0:o.title,className:i.label}))," • ",t.createElement(v,{record:e,variant:"body2",source:"published",showTime:!0})),t.createElement(g,{record:e,variant:"body1",source:"content",className:i.content})))})),o&&t.createElement(I,{minHeight:200},t.createElement(I,{alignItems:"center",className:i.loading},t.createElement(_,{size:60,thickness:6}))))},$t=function(e){var t=s(),n=t.identity,o=t.loaded,c=We(r([]),2),u=c[0],f=c[1],p=We(r(!1),2),m=p[0],h=p[1],v=We(r(!1),2),g=v[0],b=v[1],y=We(r(!1),2),E=y[0],w=y[1],x=a((function(){if(e){if(e.startsWith("http"))return e;var t;if(null!=n&&n.webIdData)return null==n||null===(t=n.webIdData)||void 0===t?void 0:t[e]}}),[n,e]),O=l(He(Ue().mark((function e(){var t,r,o,i;return Ue().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(x){e.next=2;break}return e.abrupt("return");case 2:h(!0),t=new Headers({Accept:"application/ld+json"}),r=n.id&&new URL(n.id).origin,o=new URL(x).origin,i=localStorage.getItem("token"),r===o&&i&&t.set("Authorization","Bearer ".concat(i)),d.fetchJson(x,{headers:t}).then((function(e){var t=e.json;t&&t.items?f(t.items):t&&t.orderedItems?f(t.orderedItems):f([]),w(!1),b(!0),h(!1)})).catch((function(){w(!0),b(!0),h(!1)}));case 9:case"end":return e.stop()}}),e)}))),[f,b,h,w,x,n]);i((function(){!o||m||g||E||O()}),[O,o,m,g,E]);var T=l((function(e){f((function(t){return[].concat(qe(t),[e])}))}),[f]),k=l((function(e){f((function(t){return t.filter((function(t){return"string"==typeof t?t!==e:t.id!==e}))}))}),[f]);return{items:u,loading:m,loaded:g,error:E,refetch:O,addItem:T,removeItem:k,url:x}},en=function(e){e.source;var n=e.context,r=e.helperText,o=e.placeholder,i=e.userResource,a=e.mentions,l=f(),c=$t(l.replies),u=c.items,s=c.loading,d=c.addItem,p=c.removeItem;if(!i)throw new Error("No userResource defined for CommentsField");return t.createElement(t.Fragment,null,t.createElement(Xt,{context:n,helperText:r,userResource:i,placeholder:o,mentions:a,addItem:d,removeItem:p}),t.createElement(Zt,{comments:u,loading:s,userResource:i}))};en.defaultProps={label:"Commentaires",placeholder:"Commencez à taper votre commentaire...",source:"id",context:"id"};var tn=["collectionUrl","resource","children"],nn=function(e){var n=e.collectionUrl,r=e.resource,o=e.children,i=Ve(e,tn);if(1!==t.Children.count(o))throw new Error("<CollectionList> only accepts a single child");var a=b(r,n,{enabled:!!n}),l=a.data;return a.isLoading?t.createElement("div",{style:{marginTop:8}},t.createElement(y,null)):l?t.createElement(ze,Ge({reference:r,record:l,source:"items"},i),o):null},rn=["source","record","reference","children"],on=function(e){var n=e.source,r=e.record,o=e.reference,i=e.children,a=Ve(e,rn);if(1!==t.Children.count(i))throw new Error("<ReferenceCollectionField> only accepts a single child");return r&&r[n]?t.createElement(nn,Ge({resource:o,collectionUrl:r[n]},a),i):null},an=function(){var e=s().identity,t=a((function(){var t;if(null!=e&&e.webIdData)return null==e||null===(t=e.webIdData)||void 0===t?void 0:t.inbox}),[e]),n=a((function(){var t,n;if(null!=e&&e.webIdData)return(null==e||null===(t=e.webIdData)||void 0===t||null===(n=t.endpoints)||void 0===n?void 0:n["void:sparqlEndpoint"])||(null==e?void 0:e.id)+"/sparql"}),[e]);return{fetch:l(function(){var e=He(Ue().mark((function e(r){var o,i,a,l,c,u,s;return Ue().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=r.filters,n&&t){e.next=3;break}return e.abrupt("return");case 3:return i=localStorage.getItem("token"),a=U(["as:object"]),l="",o&&Object.keys(o).forEach((function(e){if(o[e]){var t=o[e].startsWith("http")?"<".concat(o[e],">"):o[e];l+="?s1 ".concat(e," ").concat(t," .")}})),c="\n PREFIX as: <https://www.w3.org/ns/activitystreams#>\n CONSTRUCT {\n ?s1 ?p1 ?o1 .\n ".concat(a.construct,"\n }\n WHERE {\n <").concat(t,"> as:items ?s1 .\n ?s1 ?p1 ?o1 .\n FILTER( (isIRI(?s1)) ) .\n ").concat(l,"\n ").concat(a.where,"\n }\n "),e.next=10,d.fetchJson(n,{method:"POST",body:c,headers:new Headers({Accept:"application/ld+json",Authorization:i?"Bearer ".concat(i):void 0})});case 10:if(u=e.sent,!(s=u.json)["@graph"]){e.next=16;break}return e.abrupt("return",s["@graph"]);case 16:return e.abrupt("return",null);case 17:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[n,t]),url:t,owner:null==e?void 0:e.id}},ln=function(){return{fetch:l(function(){var e=He(Ue().mark((function e(t){var n,r,o,i,a,l,c,u,s;return Ue().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.split("@"),(r=We(n,3))[0],o=r[1],!(i=r[2])){e.next=18;break}return a=i.includes(":")?"http":"https",l="".concat(a,"://").concat(i,"/.well-known/webfinger?resource=acct:").concat(o,"@").concat(i),e.prev=4,e.next=7,d.fetchJson(l);case 7:return c=e.sent,u=c.json,s=u.links.find((function(e){return"application/activity+json"===e.type})),e.abrupt("return",s?s.href:null);case 13:return e.prev=13,e.t0=e.catch(4),e.abrupt("return",null);case 16:e.next=19;break;case 18:return e.abrupt("return",null);case 19:case"end":return e.stop()}}),e,null,[[4,13]])})));return function(t){return e.apply(this,arguments)}}(),[])}},cn=D((function(e){return{items:{background:"#fff",borderRadius:"0.5rem",boxShadow:"0 0 0 1px rgba(0, 0, 0, 0.05), 0px 10px 20px rgba(0, 0, 0, 0.1)",color:"rgba(0, 0, 0, 0.8)",fontSize:"0.9rem",overflow:"hidden",padding:"0.2rem",position:"relative"},item:{background:"transparent",border:"1px solid transparent",borderRadius:"0.4rem",display:"block",margin:0,padding:"0.2rem 0.4rem",textAlign:"left",width:"100%","&.selected":{borderColor:"#000"}}}})),un=c((function(e,n){var o=We(r(0),2),a=o[0],l=o[1],c=cn(),s=function(t){var n=e.items[t];n&&e.command({id:n})};return i((function(){return l(0)}),[e.items]),u(n,(function(){return{onKeyDown:function(t){var n=t.event;return"ArrowUp"===n.key?(l((a+e.items.length-1)%e.items.length),!0):"ArrowDown"===n.key?(l((a+1)%e.items.length),!0):"Enter"===n.key&&(s(a),!0)}}})),t.createElement("div",{className:c.items},e.items.length?e.items.map((function(e,n){return t.createElement("button",{className:c.item+(n===a?" selected":""),key:n,onClick:function(){return s(n)}},e.label)})):t.createElement("div",{className:c.item},"Aucun résultat"))})),sn=function(){var e,t;return{onStart:function(n){e=new q(un,{props:n,editor:n.editor}),t=_e("body",{getReferenceClientRect:n.clientRect,appendTo:function(){return document.body},content:e.element,showOnCreate:!0,interactive:!0,trigger:"manual",placement:"bottom-start"})},onUpdate:function(n){e.updateProps(n),t[0].setProps({getReferenceClientRect:n.clientRect})},onKeyDown:function(n){var r;return"Escape"===n.event.key?(t[0].hide(),!0):null===(r=e.ref)||void 0===r?void 0:r.onKeyDown(n)},onExit:function(){t[0].destroy(),e.destroy()}}},dn=function(e){var t,n,r=B(e),o=E(e,{filter:{_predicates:[null==r||null===(t=r.fieldsMapping)||void 0===t?void 0:t.title],blankNodes:[]}},{enabled:!(null==r||null===(n=r.fieldsMapping)||void 0===n||!n.title)}).data,i=a((function(){if(o)return o.map((function(e){var t;return{id:e.id,label:e[null==r||null===(t=r.fieldsMapping)||void 0===t?void 0:t.title]}}))}),[o]);return{items:a((function(){if(i)return function(e){var t=e.query;return i.filter((function(e){return e.label.toLowerCase().startsWith(t.toLowerCase())})).slice(0,5)}}),[i]),render:sn}};export{Mt as ACTIVITY_TYPES,Gt as ACTOR_TYPES,nn as CollectionList,en as CommentsField,Vt as OBJECT_TYPES,Wt as PUBLIC_URI,on as ReferenceCollectionField,$t as useCollection,an as useInbox,dn as useMentions,qt as useOutbox,ln as useWebfinger};
1
+ import {jsxs as $2hSwr$jsxs, Fragment as $2hSwr$Fragment, jsx as $2hSwr$jsx} from "react/jsx-runtime";
2
+ import $2hSwr$react, {useState as $2hSwr$useState, useCallback as $2hSwr$useCallback, useMemo as $2hSwr$useMemo, useEffect as $2hSwr$useEffect, forwardRef as $2hSwr$forwardRef, useImperativeHandle as $2hSwr$useImperativeHandle} from "react";
3
+ import {useRecordContext as $2hSwr$useRecordContext, useGetIdentity as $2hSwr$useGetIdentity, useNotify as $2hSwr$useNotify, Form as $2hSwr$Form, fetchUtils as $2hSwr$fetchUtils, TextField as $2hSwr$TextField, DateField as $2hSwr$DateField, RichTextField as $2hSwr$RichTextField, useGetOne as $2hSwr$useGetOne, LinearProgress as $2hSwr$LinearProgress, useGetList as $2hSwr$useGetList} from "react-admin";
4
+ import {RichTextInput as $2hSwr$RichTextInput, DefaultEditorOptions as $2hSwr$DefaultEditorOptions} from "ra-input-rich-text";
5
+ import $2hSwr$tiptapextensionplaceholder from "@tiptap/extension-placeholder";
6
+ import {Box as $2hSwr$Box, Avatar as $2hSwr$Avatar, Button as $2hSwr$Button, Typography as $2hSwr$Typography, CircularProgress as $2hSwr$CircularProgress} from "@mui/material";
7
+ import $2hSwr$muistylesmakeStyles from "@mui/styles/makeStyles";
8
+ import $2hSwr$muiiconsmaterialSend from "@mui/icons-material/Send";
9
+ import {useDataModel as $2hSwr$useDataModel, buildBlankNodesQuery as $2hSwr$buildBlankNodesQuery} from "@semapps/semantic-data-provider";
10
+ import {AuthDialog as $2hSwr$AuthDialog} from "@semapps/auth-provider";
11
+ import {mergeAttributes as $2hSwr$mergeAttributes} from "@tiptap/core";
12
+ import $2hSwr$tiptapextensionmention from "@tiptap/extension-mention";
13
+ import {ReferenceField as $2hSwr$ReferenceField, AvatarWithLabelField as $2hSwr$AvatarWithLabelField, ReferenceArrayField as $2hSwr$ReferenceArrayField} from "@semapps/field-components";
14
+ import {ReactRenderer as $2hSwr$ReactRenderer} from "@tiptap/react";
15
+ import $2hSwr$tippyjs from "tippy.js";
16
+
17
+ // Components
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ const $338f387df48a40d7$export$1ec8e53e7d982d22 = {
32
+ ACCEPT: "Accept",
33
+ ADD: "Add",
34
+ ANNOUNCE: "Announce",
35
+ ARRIVE: "Arrive",
36
+ BLOCK: "Block",
37
+ CREATE: "Create",
38
+ DELETE: "Delete",
39
+ DISLIKE: "Dislike",
40
+ FLAG: "Flag",
41
+ FOLLOW: "Follow",
42
+ IGNORE: "Ignore",
43
+ INVITE: "Invite",
44
+ JOIN: "Join",
45
+ LEAVE: "Leave",
46
+ LIKE: "Like",
47
+ LISTEN: "Listen",
48
+ MOVE: "Move",
49
+ OFFER: "Offer",
50
+ QUESTION: "Question",
51
+ REJECT: "Reject",
52
+ READ: "Read",
53
+ REMOVE: "Remove",
54
+ TENTATIVE_REJECT: "TentativeReject",
55
+ TENTATIVE_ACCEPT: "TentativeAccept",
56
+ TRAVAL: "Travel",
57
+ UNDO: "Undo",
58
+ UPDATE: "Update",
59
+ VIEW: "View"
60
+ };
61
+ const $338f387df48a40d7$export$9649665d7ccb0dc2 = {
62
+ APPLICATION: "Application",
63
+ GROUP: "Group",
64
+ ORGANIZATION: "Organization",
65
+ PERSON: "Person",
66
+ SERVICE: "Service"
67
+ };
68
+ const $338f387df48a40d7$export$c49cfb2681596b20 = {
69
+ ARTICLE: "Article",
70
+ AUDIO: "Audio",
71
+ DOCUMENT: "Document",
72
+ EVENT: "Event",
73
+ IMAGE: "Image",
74
+ NOTE: "Note",
75
+ PAGE: "Page",
76
+ PLACE: "Place",
77
+ PROFILE: "Profile",
78
+ RELATIONSHIP: "Relationship",
79
+ TOMBSTONE: "Tombstone",
80
+ VIDEO: "Video"
81
+ };
82
+ const $338f387df48a40d7$export$4d8d554031975581 = "https://www.w3.org/ns/activitystreams#Public";
83
+
84
+
85
+
86
+
87
+
88
+ const $712f7f004b5f345e$var$useOutbox = ()=>{
89
+ const { identity: identity } = (0, $2hSwr$useGetIdentity)();
90
+ const outboxUrl = (0, $2hSwr$useMemo)(()=>{
91
+ if (identity?.webIdData) return identity?.webIdData?.outbox;
92
+ }, [
93
+ identity
94
+ ]);
95
+ const sparqlEndpoint = (0, $2hSwr$useMemo)(()=>{
96
+ if (identity?.webIdData) return identity?.webIdData?.endpoints?.["void:sparqlEndpoint"] || `${identity?.id}/sparql`;
97
+ }, [
98
+ identity
99
+ ]);
100
+ // Post an activity to the logged user's outbox and return its URI
101
+ const post = (0, $2hSwr$useCallback)(async (activity)=>{
102
+ if (!outboxUrl) throw new Error("Cannot post to outbox before user identity is loaded. Please use the loaded argument of useOutbox");
103
+ const token = localStorage.getItem("token");
104
+ const { headers: headers } = await (0, $2hSwr$fetchUtils).fetchJson(outboxUrl, {
105
+ method: "POST",
106
+ body: JSON.stringify({
107
+ "@context": "https://www.w3.org/ns/activitystreams",
108
+ ...activity
109
+ }),
110
+ headers: new Headers({
111
+ "Content-Type": "application/ld+json",
112
+ Authorization: `Bearer ${token}`
113
+ })
114
+ });
115
+ return headers.get("Location");
116
+ }, [
117
+ outboxUrl
118
+ ]);
119
+ const fetch = (0, $2hSwr$useCallback)(async ()=>{
120
+ if (!sparqlEndpoint || !outboxUrl) return;
121
+ const token = localStorage.getItem("token");
122
+ const blankNodesQuery = (0, $2hSwr$buildBlankNodesQuery)([
123
+ "as:object"
124
+ ]);
125
+ const query = `
126
+ PREFIX as: <https://www.w3.org/ns/activitystreams#>
127
+ CONSTRUCT {
128
+ ?s1 ?p1 ?o1 .
129
+ ${blankNodesQuery.construct}
130
+ }
131
+ WHERE {
132
+ <${outboxUrl}> as:items ?s1 .
133
+ ?s1 ?p1 ?o1 .
134
+ ${blankNodesQuery.where}
135
+ }
136
+ `;
137
+ const { json: json } = await (0, $2hSwr$fetchUtils).fetchJson(sparqlEndpoint, {
138
+ method: "POST",
139
+ body: query,
140
+ headers: new Headers({
141
+ Accept: "application/ld+json",
142
+ Authorization: token ? `Bearer ${token}` : undefined
143
+ })
144
+ });
145
+ if (json["@graph"]) return json["@graph"];
146
+ return null;
147
+ }, [
148
+ sparqlEndpoint,
149
+ outboxUrl
150
+ ]);
151
+ return {
152
+ post: post,
153
+ fetch: fetch,
154
+ url: outboxUrl,
155
+ loaded: !!outboxUrl,
156
+ owner: identity?.id
157
+ };
158
+ };
159
+ var $712f7f004b5f345e$export$2e2bcd8739ae039 = $712f7f004b5f345e$var$useOutbox;
160
+
161
+
162
+
163
+
164
+ // Fix a bug in the current version of the mention extension
165
+ // (The { id, label } object is located inside the id property)
166
+ // See https://github.com/ueberdosis/tiptap/pull/1322
167
+ const $6080c8a288f71367$var$CustomMention = (0, $2hSwr$tiptapextensionmention).extend({
168
+ renderHTML ({ node: node, HTMLAttributes: HTMLAttributes }) {
169
+ return [
170
+ "span",
171
+ (0, $2hSwr$mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),
172
+ `@${node.attrs.id.label}`
173
+ ];
174
+ },
175
+ addAttributes () {
176
+ return {
177
+ label: {
178
+ default: null,
179
+ parseHTML: (element)=>{
180
+ return {
181
+ label: element.getAttribute("data-mention-label")
182
+ };
183
+ },
184
+ renderHTML: (attributes)=>{
185
+ if (!attributes.id.label) return {};
186
+ return {
187
+ "data-mention-label": attributes.id.label
188
+ };
189
+ }
190
+ },
191
+ id: {
192
+ default: null,
193
+ parseHTML: (element)=>{
194
+ return {
195
+ id: element.getAttribute("data-mention-id")
196
+ };
197
+ },
198
+ renderHTML: (attributes)=>{
199
+ if (!attributes.id.id) return {};
200
+ return {
201
+ "data-mention-id": attributes.id.id
202
+ };
203
+ }
204
+ }
205
+ };
206
+ }
207
+ });
208
+ var $6080c8a288f71367$export$2e2bcd8739ae039 = $6080c8a288f71367$var$CustomMention;
209
+
210
+
211
+ const $3c17312a40ebf1ed$var$useStyles = (0, $2hSwr$muistylesmakeStyles)((theme)=>({
212
+ form: {
213
+ marginTop: -12 // Negative margin to keep the form close to the label
214
+ },
215
+ container: {
216
+ paddingLeft: 80,
217
+ position: "relative"
218
+ },
219
+ avatar: {
220
+ position: "absolute",
221
+ top: 16,
222
+ left: 0,
223
+ bottom: 0,
224
+ width: 64,
225
+ height: 64
226
+ },
227
+ editorContent: {
228
+ "& > div": {
229
+ backgroundColor: "rgba(0, 0, 0, 0.09)",
230
+ padding: "2px 12px",
231
+ borderWidth: "0px !important",
232
+ borderRadius: 0,
233
+ borderBottom: "1px solid #FFF",
234
+ minHeight: 60,
235
+ outline: "unset !important"
236
+ },
237
+ "& > div > p": {
238
+ marginTop: 12,
239
+ marginBottom: 12,
240
+ fontFamily: theme.typography.body1.fontFamily,
241
+ marginBlockStart: "0.5em",
242
+ marginBlockEnd: "0.5em"
243
+ },
244
+ "& > div > p.is-editor-empty:first-child::before": {
245
+ color: "grey",
246
+ content: "attr(data-placeholder)",
247
+ float: "left",
248
+ height: 0,
249
+ pointerEvents: "none"
250
+ }
251
+ },
252
+ button: {
253
+ marginTop: -10,
254
+ marginBottom: 15
255
+ }
256
+ }));
257
+ const $3c17312a40ebf1ed$var$EmptyToolbar = ()=>null;
258
+ const $3c17312a40ebf1ed$var$PostCommentForm = ({ context: context, placeholder: placeholder, helperText: helperText, mentions: mentions, userResource: userResource, addItem: addItem, removeItem: removeItem })=>{
259
+ const record = (0, $2hSwr$useRecordContext)();
260
+ const { identity: identity, isLoading: isLoading } = (0, $2hSwr$useGetIdentity)();
261
+ const userDataModel = (0, $2hSwr$useDataModel)(userResource);
262
+ const classes = $3c17312a40ebf1ed$var$useStyles();
263
+ const notify = (0, $2hSwr$useNotify)();
264
+ const outbox = (0, $712f7f004b5f345e$export$2e2bcd8739ae039)();
265
+ const [expanded, setExpanded] = (0, $2hSwr$useState)(false);
266
+ const [openAuth, setOpenAuth] = (0, $2hSwr$useState)(false);
267
+ const onSubmit = (0, $2hSwr$useCallback)(async (values)=>{
268
+ const document = new DOMParser().parseFromString(values.comment, "text/html");
269
+ const mentions = Array.from(document.body.getElementsByClassName("mention"));
270
+ const mentionedUsersUris = [];
271
+ mentions.forEach((node)=>{
272
+ const userUri = node.attributes["data-mention-id"].value;
273
+ const userLabel = node.attributes["data-mention-label"].value;
274
+ const link = document.createElement("a");
275
+ link.setAttribute("href", `${new URL(window.location.href).origin}/${userResource}/${encodeURIComponent(userUri)}/show`);
276
+ link.textContent = `@${userLabel}`;
277
+ node.parentNode.replaceChild(link, node);
278
+ mentionedUsersUris.push(userUri);
279
+ });
280
+ if (document.body.innerHTML === "undefined") notify("Votre commentaire est vide", {
281
+ type: "error"
282
+ });
283
+ else {
284
+ const tempId = Date.now();
285
+ const note = {
286
+ type: (0, $338f387df48a40d7$export$c49cfb2681596b20).NOTE,
287
+ attributedTo: outbox.owner,
288
+ content: document.body.innerHTML,
289
+ inReplyTo: record[context],
290
+ published: new Date().toISOString()
291
+ };
292
+ try {
293
+ addItem({
294
+ id: tempId,
295
+ ...note
296
+ });
297
+ // TODO reset the form
298
+ setExpanded(false);
299
+ await outbox.post({
300
+ ...note,
301
+ to: [
302
+ ...mentionedUsersUris,
303
+ (0, $338f387df48a40d7$export$4d8d554031975581)
304
+ ]
305
+ });
306
+ notify("Commentaire post\xe9 avec succ\xe8s", {
307
+ type: "success"
308
+ });
309
+ } catch (e) {
310
+ console.error(e);
311
+ removeItem(tempId);
312
+ notify(e.message, {
313
+ type: "error"
314
+ });
315
+ }
316
+ }
317
+ }, [
318
+ outbox,
319
+ notify,
320
+ setExpanded,
321
+ addItem,
322
+ removeItem
323
+ ]);
324
+ const openAuthIfDisconnected = (0, $2hSwr$useCallback)(()=>{
325
+ if (!identity?.id) setOpenAuth(true);
326
+ }, [
327
+ identity,
328
+ setOpenAuth
329
+ ]);
330
+ // Don't init the editor options until mentions and identity are loaded, as they can only be initialized once
331
+ if (mentions && !mentions.items || isLoading) return null;
332
+ return /*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Fragment), {
333
+ children: [
334
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$Form), {
335
+ onSubmit: onSubmit,
336
+ className: classes.form,
337
+ children: /*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Box), {
338
+ className: classes.container,
339
+ onClick: openAuthIfDisconnected,
340
+ children: [
341
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$Avatar), {
342
+ src: identity?.webIdData?.[userDataModel?.fieldsMapping?.image] || identity?.profileData?.[userDataModel?.fieldsMapping?.image],
343
+ className: classes.avatar
344
+ }),
345
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$RichTextInput), {
346
+ source: "comment",
347
+ label: " ",
348
+ toolbar: /*#__PURE__*/ (0, $2hSwr$jsx)($3c17312a40ebf1ed$var$EmptyToolbar, {}),
349
+ fullWidth: true,
350
+ classes: {
351
+ editorContent: classes.editorContent
352
+ },
353
+ editorOptions: {
354
+ ...(0, $2hSwr$DefaultEditorOptions),
355
+ onFocus () {
356
+ setExpanded(true);
357
+ },
358
+ extensions: [
359
+ ...(0, $2hSwr$DefaultEditorOptions).extensions,
360
+ placeholder ? (0, $2hSwr$tiptapextensionplaceholder).configure({
361
+ placeholder: placeholder
362
+ }) : null,
363
+ mentions ? (0, $6080c8a288f71367$export$2e2bcd8739ae039).configure({
364
+ HTMLAttributes: {
365
+ class: "mention"
366
+ },
367
+ suggestion: mentions
368
+ }) : null
369
+ ],
370
+ // Disable editor if user is not connected
371
+ editable: !!identity?.id
372
+ },
373
+ helperText: helperText
374
+ }),
375
+ expanded && /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$Button), {
376
+ type: "submit",
377
+ size: "small",
378
+ variant: "contained",
379
+ color: "primary",
380
+ endIcon: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$muiiconsmaterialSend), {}),
381
+ className: classes.button,
382
+ children: "Envoyer"
383
+ })
384
+ ]
385
+ })
386
+ }),
387
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$AuthDialog), {
388
+ open: openAuth,
389
+ onClose: ()=>setOpenAuth(false),
390
+ message: "Pour poster un commentaire, vous devez \xeatre connect\xe9."
391
+ })
392
+ ]
393
+ });
394
+ };
395
+ var $3c17312a40ebf1ed$export$2e2bcd8739ae039 = $3c17312a40ebf1ed$var$PostCommentForm;
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+ const $be88b298220210d1$var$useStyles = (0, $2hSwr$muistylesmakeStyles)(()=>({
406
+ container: {
407
+ paddingLeft: 80,
408
+ marginTop: 8,
409
+ minHeight: 80,
410
+ position: "relative"
411
+ },
412
+ avatar: {
413
+ position: "absolute",
414
+ top: 0,
415
+ left: 0,
416
+ bottom: 0,
417
+ width: 64,
418
+ height: 64
419
+ },
420
+ text: {
421
+ paddingTop: 2,
422
+ paddingBottom: 8
423
+ },
424
+ label: {
425
+ fontWeight: "bold"
426
+ },
427
+ content: {
428
+ "& p": {
429
+ marginBlockStart: "0.5em",
430
+ marginBlockEnd: "0.5em"
431
+ }
432
+ },
433
+ loading: {
434
+ zIndex: 1000,
435
+ backgroundColor: "white",
436
+ opacity: 0.5,
437
+ position: "absolute",
438
+ top: 0,
439
+ left: 0,
440
+ right: 0,
441
+ bottom: 0,
442
+ display: "flex",
443
+ alignItems: "center",
444
+ justifyContent: "center",
445
+ minHeight: 200,
446
+ marginTop: 5
447
+ }
448
+ }));
449
+ const $be88b298220210d1$var$CommentsList = ({ comments: comments, userResource: userResource, loading: loading })=>{
450
+ const classes = $be88b298220210d1$var$useStyles();
451
+ const userDataModel = (0, $2hSwr$useDataModel)(userResource);
452
+ return /*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Box), {
453
+ position: "relative",
454
+ children: [
455
+ comments && comments.sort((a, b)=>new Date(b.published) - new Date(a.published)).map((comment)=>/*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Box), {
456
+ className: classes.container,
457
+ children: [
458
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$Box), {
459
+ className: classes.avatar,
460
+ children: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$ReferenceField), {
461
+ record: comment,
462
+ reference: userResource,
463
+ source: "attributedTo",
464
+ linkType: "show",
465
+ children: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$AvatarWithLabelField), {
466
+ image: userDataModel?.fieldsMapping?.image
467
+ })
468
+ })
469
+ }),
470
+ /*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Box), {
471
+ className: classes.text,
472
+ children: [
473
+ /*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Typography), {
474
+ variant: "body2",
475
+ children: [
476
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$ReferenceField), {
477
+ record: comment,
478
+ reference: userResource,
479
+ source: "attributedTo",
480
+ linkType: "show",
481
+ children: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$TextField), {
482
+ variant: "body2",
483
+ source: userDataModel?.fieldsMapping?.title,
484
+ className: classes.label
485
+ })
486
+ }),
487
+ "\xa0•\xa0",
488
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$DateField), {
489
+ record: comment,
490
+ variant: "body2",
491
+ source: "published",
492
+ showTime: true
493
+ })
494
+ ]
495
+ }),
496
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$RichTextField), {
497
+ record: comment,
498
+ variant: "body1",
499
+ source: "content",
500
+ className: classes.content
501
+ })
502
+ ]
503
+ })
504
+ ]
505
+ }, comment.id)),
506
+ loading && /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$Box), {
507
+ minHeight: 200,
508
+ children: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$Box), {
509
+ alignItems: "center",
510
+ className: classes.loading,
511
+ children: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$CircularProgress), {
512
+ size: 60,
513
+ thickness: 6
514
+ })
515
+ })
516
+ })
517
+ ]
518
+ });
519
+ };
520
+ var $be88b298220210d1$export$2e2bcd8739ae039 = $be88b298220210d1$var$CommentsList;
521
+
522
+
523
+
524
+
525
+ const $c1e897431d8c5742$var$useCollection = (predicateOrUrl)=>{
526
+ const { identity: identity, isLoading: identityLoading } = (0, $2hSwr$useGetIdentity)();
527
+ const [items, setItems] = (0, $2hSwr$useState)([]);
528
+ const [loading, setLoading] = (0, $2hSwr$useState)(false);
529
+ const [loaded, setLoaded] = (0, $2hSwr$useState)(false);
530
+ const [error, setError] = (0, $2hSwr$useState)(false);
531
+ const collectionUrl = (0, $2hSwr$useMemo)(()=>{
532
+ if (predicateOrUrl) {
533
+ if (predicateOrUrl.startsWith("http")) return predicateOrUrl;
534
+ if (identity?.webIdData) return identity?.webIdData?.[predicateOrUrl];
535
+ }
536
+ }, [
537
+ identity,
538
+ predicateOrUrl
539
+ ]);
540
+ const fetch = (0, $2hSwr$useCallback)(async ()=>{
541
+ if (!collectionUrl) return;
542
+ setLoading(true);
543
+ const headers = new Headers({
544
+ Accept: "application/ld+json"
545
+ });
546
+ // Add authorization token if it is set and if the user is on the same server as the collection
547
+ const identityOrigin = identity.id && new URL(identity.id).origin;
548
+ const collectionOrigin = new URL(collectionUrl).origin;
549
+ const token = localStorage.getItem("token");
550
+ if (identityOrigin === collectionOrigin && token) headers.set("Authorization", `Bearer ${token}`);
551
+ (0, $2hSwr$fetchUtils).fetchJson(collectionUrl, {
552
+ headers: headers
553
+ }).then(({ json: json })=>{
554
+ if (json && json.items) setItems(json.items);
555
+ else if (json && json.orderedItems) setItems(json.orderedItems);
556
+ else setItems([]);
557
+ setError(false);
558
+ setLoaded(true);
559
+ setLoading(false);
560
+ }).catch(()=>{
561
+ setError(true);
562
+ setLoaded(true);
563
+ setLoading(false);
564
+ });
565
+ }, [
566
+ setItems,
567
+ setLoaded,
568
+ setLoading,
569
+ setError,
570
+ collectionUrl,
571
+ identity
572
+ ]);
573
+ (0, $2hSwr$useEffect)(()=>{
574
+ if (!identityLoading && !loading && !loaded && !error) fetch();
575
+ }, [
576
+ fetch,
577
+ identityLoading,
578
+ loading,
579
+ loaded,
580
+ error
581
+ ]);
582
+ const addItem = (0, $2hSwr$useCallback)((item)=>{
583
+ setItems((oldItems)=>[
584
+ ...oldItems,
585
+ item
586
+ ]);
587
+ }, [
588
+ setItems
589
+ ]);
590
+ const removeItem = (0, $2hSwr$useCallback)((itemId)=>{
591
+ setItems((oldItems)=>oldItems.filter((item)=>typeof item === "string" ? item !== itemId : item.id !== itemId));
592
+ }, [
593
+ setItems
594
+ ]);
595
+ return {
596
+ items: items,
597
+ loading: loading,
598
+ loaded: loaded,
599
+ error: error,
600
+ refetch: fetch,
601
+ addItem: addItem,
602
+ removeItem: removeItem,
603
+ url: collectionUrl
604
+ };
605
+ };
606
+ var $c1e897431d8c5742$export$2e2bcd8739ae039 = $c1e897431d8c5742$var$useCollection;
607
+
608
+
609
+ const $7ce737d4a1c88e63$var$CommentsField = ({ source: source, context: context, helperText: helperText, placeholder: placeholder, userResource: userResource, mentions: mentions })=>{
610
+ const record = (0, $2hSwr$useRecordContext)();
611
+ const { items: comments, loading: loading, addItem: addItem, removeItem: removeItem } = (0, $c1e897431d8c5742$export$2e2bcd8739ae039)(record.replies);
612
+ if (!userResource) throw new Error("No userResource defined for CommentsField");
613
+ return /*#__PURE__*/ (0, $2hSwr$jsxs)((0, $2hSwr$Fragment), {
614
+ children: [
615
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $3c17312a40ebf1ed$export$2e2bcd8739ae039), {
616
+ context: context,
617
+ helperText: helperText,
618
+ userResource: userResource,
619
+ placeholder: placeholder,
620
+ mentions: mentions,
621
+ addItem: addItem,
622
+ removeItem: removeItem
623
+ }),
624
+ /*#__PURE__*/ (0, $2hSwr$jsx)((0, $be88b298220210d1$export$2e2bcd8739ae039), {
625
+ comments: comments,
626
+ loading: loading,
627
+ userResource: userResource
628
+ })
629
+ ]
630
+ });
631
+ };
632
+ $7ce737d4a1c88e63$var$CommentsField.defaultProps = {
633
+ label: "Commentaires",
634
+ placeholder: "Commencez \xe0 taper votre commentaire...",
635
+ source: "id",
636
+ context: "id"
637
+ };
638
+ var $7ce737d4a1c88e63$export$2e2bcd8739ae039 = $7ce737d4a1c88e63$var$CommentsField;
639
+
640
+
641
+
642
+
643
+
644
+
645
+ const $d3be168cd1e7aaae$var$CollectionList = ({ collectionUrl: collectionUrl, resource: resource, children: children, ...rest })=>{
646
+ if ((0, $2hSwr$react).Children.count(children) !== 1) throw new Error("<CollectionList> only accepts a single child");
647
+ // TODO use a simple fetch call, as the resource is not good and it is useless
648
+ const { data: collection, isLoading: isLoading } = (0, $2hSwr$useGetOne)(resource, collectionUrl, {
649
+ enabled: !!collectionUrl
650
+ });
651
+ if (isLoading) return /*#__PURE__*/ (0, $2hSwr$jsx)("div", {
652
+ style: {
653
+ marginTop: 8
654
+ },
655
+ children: /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$LinearProgress), {})
656
+ });
657
+ if (!collection) return null;
658
+ return /*#__PURE__*/ (0, $2hSwr$jsx)((0, $2hSwr$ReferenceArrayField), {
659
+ reference: resource,
660
+ record: collection,
661
+ source: "items",
662
+ ...rest,
663
+ children: children
664
+ });
665
+ };
666
+ var $d3be168cd1e7aaae$export$2e2bcd8739ae039 = $d3be168cd1e7aaae$var$CollectionList;
667
+
668
+
669
+
670
+
671
+
672
+ const $ea214512ab1a2e8f$var$ReferenceCollectionField = ({ source: source, record: record, reference: reference, children: children, ...rest })=>{
673
+ if ((0, $2hSwr$react).Children.count(children) !== 1) throw new Error("<ReferenceCollectionField> only accepts a single child");
674
+ if (!record || !record[source]) return null;
675
+ return /*#__PURE__*/ (0, $2hSwr$jsx)((0, $d3be168cd1e7aaae$export$2e2bcd8739ae039), {
676
+ resource: reference,
677
+ collectionUrl: record[source],
678
+ ...rest,
679
+ children: children
680
+ });
681
+ };
682
+ var $ea214512ab1a2e8f$export$2e2bcd8739ae039 = $ea214512ab1a2e8f$var$ReferenceCollectionField;
683
+
684
+
685
+
686
+
687
+
688
+
689
+ const $542b37cc25b8ccca$var$useInbox = ()=>{
690
+ const { identity: identity } = (0, $2hSwr$useGetIdentity)();
691
+ const inboxUrl = (0, $2hSwr$useMemo)(()=>{
692
+ if (identity?.webIdData) return identity?.webIdData?.inbox;
693
+ }, [
694
+ identity
695
+ ]);
696
+ const sparqlEndpoint = (0, $2hSwr$useMemo)(()=>{
697
+ if (identity?.webIdData) return identity?.webIdData?.endpoints?.["void:sparqlEndpoint"] || `${identity?.id}/sparql`;
698
+ }, [
699
+ identity
700
+ ]);
701
+ const fetch = (0, $2hSwr$useCallback)(async ({ filters: filters })=>{
702
+ if (!sparqlEndpoint || !inboxUrl) return;
703
+ const token = localStorage.getItem("token");
704
+ const blankNodesQuery = (0, $2hSwr$buildBlankNodesQuery)([
705
+ "as:object"
706
+ ]);
707
+ let filtersWhereQuery = "";
708
+ if (filters) Object.keys(filters).forEach((predicate)=>{
709
+ if (filters[predicate]) {
710
+ const object = filters[predicate].startsWith("http") ? `<${filters[predicate]}>` : filters[predicate];
711
+ filtersWhereQuery += `?s1 ${predicate} ${object} .`;
712
+ }
713
+ });
714
+ const query = `
715
+ PREFIX as: <https://www.w3.org/ns/activitystreams#>
716
+ CONSTRUCT {
717
+ ?s1 ?p1 ?o1 .
718
+ ${blankNodesQuery.construct}
719
+ }
720
+ WHERE {
721
+ <${inboxUrl}> as:items ?s1 .
722
+ ?s1 ?p1 ?o1 .
723
+ FILTER( (isIRI(?s1)) ) .
724
+ ${filtersWhereQuery}
725
+ ${blankNodesQuery.where}
726
+ }
727
+ `;
728
+ const { json: json } = await (0, $2hSwr$fetchUtils).fetchJson(sparqlEndpoint, {
729
+ method: "POST",
730
+ body: query,
731
+ headers: new Headers({
732
+ Accept: "application/ld+json",
733
+ Authorization: token ? `Bearer ${token}` : undefined
734
+ })
735
+ });
736
+ if (json["@graph"]) return json["@graph"];
737
+ return null;
738
+ }, [
739
+ sparqlEndpoint,
740
+ inboxUrl
741
+ ]);
742
+ return {
743
+ fetch: fetch,
744
+ url: inboxUrl,
745
+ owner: identity?.id
746
+ };
747
+ };
748
+ var $542b37cc25b8ccca$export$2e2bcd8739ae039 = $542b37cc25b8ccca$var$useInbox;
749
+
750
+
751
+
752
+
753
+
754
+ const $2514c63dc8f4867c$var$useWebfinger = ()=>{
755
+ // Post an activity to the logged user's outbox and return its URI
756
+ const fetch = (0, $2hSwr$useCallback)(async (id)=>{
757
+ // eslint-disable-next-line
758
+ const [_, username, host] = id.split("@");
759
+ if (host) {
760
+ const protocol = host.includes(":") ? "http" : "https"; // If the host has a port, we are most likely on localhost
761
+ const webfingerUrl = `${protocol}://${host}/.well-known/webfinger?resource=acct:${username}@${host}`;
762
+ try {
763
+ const { json: json } = await (0, $2hSwr$fetchUtils).fetchJson(webfingerUrl);
764
+ const link = json.links.find((l)=>l.type === "application/activity+json");
765
+ return link ? link.href : null;
766
+ } catch (e) {
767
+ return null;
768
+ }
769
+ } else return null;
770
+ }, []);
771
+ return {
772
+ fetch: fetch
773
+ };
774
+ };
775
+ var $2514c63dc8f4867c$export$2e2bcd8739ae039 = $2514c63dc8f4867c$var$useWebfinger;
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+ const $cebd295d444aa91c$var$useStyles = (0, $2hSwr$muistylesmakeStyles)((theme)=>({
787
+ items: {
788
+ background: "#fff",
789
+ borderRadius: "0.5rem",
790
+ boxShadow: "0 0 0 1px rgba(0, 0, 0, 0.05), 0px 10px 20px rgba(0, 0, 0, 0.1)",
791
+ color: "rgba(0, 0, 0, 0.8)",
792
+ fontSize: "0.9rem",
793
+ overflow: "hidden",
794
+ padding: "0.2rem",
795
+ position: "relative"
796
+ },
797
+ item: {
798
+ background: "transparent",
799
+ border: "1px solid transparent",
800
+ borderRadius: "0.4rem",
801
+ display: "block",
802
+ margin: 0,
803
+ padding: "0.2rem 0.4rem",
804
+ textAlign: "left",
805
+ width: "100%",
806
+ "&.selected": {
807
+ borderColor: "#000"
808
+ }
809
+ }
810
+ }));
811
+ var $cebd295d444aa91c$export$2e2bcd8739ae039 = /*#__PURE__*/ (0, $2hSwr$forwardRef)((props, ref)=>{
812
+ const [selectedIndex, setSelectedIndex] = (0, $2hSwr$useState)(0);
813
+ const classes = $cebd295d444aa91c$var$useStyles();
814
+ const selectItem = (index)=>{
815
+ const item = props.items[index];
816
+ if (item) props.command({
817
+ id: item
818
+ });
819
+ };
820
+ const upHandler = ()=>{
821
+ setSelectedIndex((selectedIndex + props.items.length - 1) % props.items.length);
822
+ };
823
+ const downHandler = ()=>{
824
+ setSelectedIndex((selectedIndex + 1) % props.items.length);
825
+ };
826
+ const enterHandler = ()=>{
827
+ selectItem(selectedIndex);
828
+ };
829
+ (0, $2hSwr$useEffect)(()=>setSelectedIndex(0), [
830
+ props.items
831
+ ]);
832
+ (0, $2hSwr$useImperativeHandle)(ref, ()=>({
833
+ onKeyDown: ({ event: event })=>{
834
+ if (event.key === "ArrowUp") {
835
+ upHandler();
836
+ return true;
837
+ }
838
+ if (event.key === "ArrowDown") {
839
+ downHandler();
840
+ return true;
841
+ }
842
+ if (event.key === "Enter") {
843
+ enterHandler();
844
+ return true;
845
+ }
846
+ return false;
847
+ }
848
+ }));
849
+ return /*#__PURE__*/ (0, $2hSwr$jsx)("div", {
850
+ className: classes.items,
851
+ children: props.items.length ? props.items.map((item, index)=>/*#__PURE__*/ (0, $2hSwr$jsx)("button", {
852
+ className: classes.item + (index === selectedIndex ? " selected" : ""),
853
+ onClick: ()=>selectItem(index),
854
+ children: item.label
855
+ }, index)) : /*#__PURE__*/ (0, $2hSwr$jsx)("div", {
856
+ className: classes.item,
857
+ children: "Aucun r\xe9sultat"
858
+ })
859
+ });
860
+ });
861
+
862
+
863
+ const $a2389704c0801b9a$var$renderMentions = ()=>{
864
+ let component;
865
+ let popup;
866
+ return {
867
+ onStart: (props)=>{
868
+ component = new (0, $2hSwr$ReactRenderer)((0, $cebd295d444aa91c$export$2e2bcd8739ae039), {
869
+ props: props,
870
+ editor: props.editor
871
+ });
872
+ popup = (0, $2hSwr$tippyjs)("body", {
873
+ getReferenceClientRect: props.clientRect,
874
+ appendTo: ()=>document.body,
875
+ content: component.element,
876
+ showOnCreate: true,
877
+ interactive: true,
878
+ trigger: "manual",
879
+ placement: "bottom-start"
880
+ });
881
+ },
882
+ onUpdate (props) {
883
+ component.updateProps(props);
884
+ popup[0].setProps({
885
+ getReferenceClientRect: props.clientRect
886
+ });
887
+ },
888
+ onKeyDown (props) {
889
+ if (props.event.key === "Escape") {
890
+ popup[0].hide();
891
+ return true;
892
+ }
893
+ return component.ref?.onKeyDown(props);
894
+ },
895
+ onExit () {
896
+ popup[0].destroy();
897
+ component.destroy();
898
+ }
899
+ };
900
+ };
901
+ var $a2389704c0801b9a$export$2e2bcd8739ae039 = $a2389704c0801b9a$var$renderMentions;
902
+
903
+
904
+ const $51cccd331ea8b13d$var$useMentions = (userResource)=>{
905
+ const userDataModel = (0, $2hSwr$useDataModel)(userResource);
906
+ const { data: data } = (0, $2hSwr$useGetList)(userResource, {
907
+ filter: {
908
+ _predicates: [
909
+ userDataModel?.fieldsMapping?.title
910
+ ],
911
+ blankNodes: []
912
+ }
913
+ }, {
914
+ enabled: !!userDataModel?.fieldsMapping?.title
915
+ });
916
+ const availableMentions = (0, $2hSwr$useMemo)(()=>{
917
+ if (data) return data.map((item)=>({
918
+ id: item.id,
919
+ label: item[userDataModel?.fieldsMapping?.title]
920
+ }));
921
+ }, [
922
+ data
923
+ ]);
924
+ const items = (0, $2hSwr$useMemo)(()=>{
925
+ if (availableMentions) return ({ query: query })=>{
926
+ return availableMentions.filter(({ label: label })=>label.toLowerCase().startsWith(query.toLowerCase())).slice(0, 5);
927
+ };
928
+ }, [
929
+ availableMentions
930
+ ]);
931
+ return {
932
+ items: items,
933
+ render: (0, $a2389704c0801b9a$export$2e2bcd8739ae039)
934
+ };
935
+ };
936
+ var $51cccd331ea8b13d$export$2e2bcd8739ae039 = $51cccd331ea8b13d$var$useMentions;
937
+
938
+
939
+
940
+
941
+
942
+ export {$7ce737d4a1c88e63$export$2e2bcd8739ae039 as CommentsField, $d3be168cd1e7aaae$export$2e2bcd8739ae039 as CollectionList, $ea214512ab1a2e8f$export$2e2bcd8739ae039 as ReferenceCollectionField, $c1e897431d8c5742$export$2e2bcd8739ae039 as useCollection, $542b37cc25b8ccca$export$2e2bcd8739ae039 as useInbox, $712f7f004b5f345e$export$2e2bcd8739ae039 as useOutbox, $2514c63dc8f4867c$export$2e2bcd8739ae039 as useWebfinger, $51cccd331ea8b13d$export$2e2bcd8739ae039 as useMentions, $338f387df48a40d7$export$1ec8e53e7d982d22 as ACTIVITY_TYPES, $338f387df48a40d7$export$9649665d7ccb0dc2 as ACTOR_TYPES, $338f387df48a40d7$export$c49cfb2681596b20 as OBJECT_TYPES, $338f387df48a40d7$export$4d8d554031975581 as PUBLIC_URI};
4
943
  //# sourceMappingURL=index.es.js.map