@apolitical/component-library 8.3.19 → 8.3.20
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/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -101,7 +101,7 @@ ${p}${d?"1.":"-"} ${u}${f?`
|
|
|
101
101
|
`:""}`;case o[re.paragraph]:return`${u}
|
|
102
102
|
|
|
103
103
|
`;case o[re.hr]:return`---
|
|
104
|
-
`;default:return u}}function Ua(e,t){const n=e.trim(),r=n,i=`${t}${r}${Xv(t)}`;if(r.length===e.length)return i;const a=t+r+Xv(t);return e.replace(n,a)}const Xv=e=>e.split("").reverse().join(""),SP=e=>e.map(t=>fT(t)).join("").trim();const kP=({onFallbackClick:e=()=>{}})=>{const t=he.useIntl(),n=Oa(),{dispatch:r,isInOverlay:i,mentionPopover:a,id:s,onMention:o}=y.useContext(Ei),{show:l,selectedUser:u,possibleUsers:c}=a,d=Kb(n,"mention-popover",`toolbar-${s}`);if(!l)return h.jsx(h.Fragment,{});const f=dT(i);return h.jsx(Ms,{parent:f,children:h.jsx(Yy,{ref:d,className:"mention-popover",onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),r([{type:"showMentionPopover",value:!1}]))},children:h.jsxs("ul",{children:[c.map(({userId:p,user:g},m)=>h.jsx(ci,{element:"li",className:J({selected:m===u}),member:{id:p,...g,link:!1},functions:{onClick:E=>{E.preventDefault(),E.stopPropagation();const v={...a,selectedUser:m};r([{type:"mentionPopover",value:v}]),cT(n,v,r,s),o&&o({id:p||"",name:g.name||""})}}},p)),h.jsx(ci,{element:"li",className:J("fallback",{selected:c.length===u}),member:{id:"0",name:t.formatMessage({id:"richTextEditor_mention_fallback"}),image:{thumbnail:`${Ur}icons/invite-user.svg`},link:!1},functions:{onClick:p=>{p.preventDefault(),p.stopPropagation(),e(),r([{type:"mentionPopover",value:{show:!1,selectedUser:0,possibleUsers:[],position:null}}])}}})]})})})};const wc=({formID:e,label:t,showLabel:n})=>{const{visible:r="",screenreader:i=""}=t||{};return n?h.jsx("label",{htmlFor:`${e}-input`,className:"rte-label text-small",onClick:a=>{a.preventDefault(),a.stopPropagation();const s=new CustomEvent("focusEditor",{detail:{id:`rte-${e}-input`}});window.dispatchEvent(s)},children:r}):h.jsx(ut,{element:"label",showOnFocus:!1,htmlFor:`${e}-input`,children:i})},Yp=({id:e,active:t,hasDivider:n=!1,callback:r,className:i="",children:a,"aria-pressed":s,...o})=>{const l=he.useIntl(),u=Oa(),{id:c,dispatch:d}=y.useContext(Ei),{tabbableOption:f,setFocus:p,openTooltip:g,dispatch:m}=y.useContext(vl),E={};return e!==f&&(E.tabIndex=-1),s!==null&&(E["aria-pressed"]=typeof s=="boolean"?s:t),h.jsxs("li",{id:`${c}-${e}`,className:J(e,{"has-divider":n}),onMouseEnter:()=>{m([{type:"openTooltip",value:e}])},onMouseLeave:()=>{m([{type:"openTooltip",value:null}])},onFocus:()=>{m([{type:"openTooltip",value:e}])},onBlur:v=>{v.stopPropagation(),m([{type:"openTooltip",value:null}]),u.selection&&d({type:"lastAnchor",value:u.selection.anchor})},contentEditable:!1,children:[h.jsxs("button",{...o,...E,className:J(e,i,{active:t}),onClick:v=>{v.stopPropagation(),v.preventDefault()},onMouseDown:v=>{v.stopPropagation(),v.preventDefault(),r()},onKeyDown:v=>{var b,T,_,w;if(v.key!=="Tab")switch(v.key){case"Enter":v.stopPropagation(),v.preventDefault(),r();break;case"ArrowLeft":case"ArrowRight":v.stopPropagation(),v.preventDefault();const A=v.currentTarget.closest("li");let S=A==null?void 0:A.nextElementSibling;if(v.key==="ArrowLeft"){const L=A==null?void 0:A.previousElementSibling;L?S=L:S=(b=A==null?void 0:A.parentElement)==null?void 0:b.lastElementChild}else S||(S=(T=A==null?void 0:A.parentElement)==null?void 0:T.firstElementChild);const B=S==null?void 0:S.className.split(" ")[0];B&&(p(B),(_=S==null?void 0:S.querySelector("button"))==null||_.focus());break;default:const F=v.currentTarget.closest("fieldset");if(F){(w=F==null?void 0:F.previousElementSibling)==null||w.focus();break}}},children:[h.jsx(ut,{showOnFocus:!1,children:l.formatMessage({id:`richTextEditor_${e}`})}),h.jsx(Da,{id:`tooltip-${e}`,styling:{extraPadding:!1,hasPointer:"bottom"},isOpen:g===e,accessibility:{"aria-hidden":!0},children:l.formatMessage({id:`richTextEditor_${e}`})})]}),a]})},Jv=[re.ol,re.ul],hT=(e,t)=>{const{selection:n}=e;if(!n)return!1;const[r]=Array.from(D.nodes(e,{at:D.unhangRange(e,n),match:i=>{const a=i;return!D.isEditor(i)&&Se.isElement(i)&&a.type===t}}));return!!r},DP=e=>{const[t]=D.nodes(e,{match:n=>n.type===re.blockquote});return!!t},pT=(e,t,n)=>{try{const r=DP(e),i=hT(e,t),a=Jv.includes(t);ue.unwrapNodes(e,{match:l=>{const u=l;return!D.isEditor(u)&&Se.isElement(u)&&Jv.includes(u.type)},split:!0});const o={type:i?re.paragraph:a?re.li:t};if(ue.setNodes(e,o),t===re.h3){const l={type:t};i?D.removeMark(e,t):D.addMark(e,t,!0),ue.setNodes(e,l)}if(a)if(i){const{selection:l}=e;if(!l)return;const[u,c]=D.parent(e,l,{edge:"end"});Array.from(D.nodes(e,{at:c,match:f=>{const p=f;return!D.isEditor(f)&&Se.isElement(f)&&p.type===re.li}})).forEach(([f,p])=>{Ee.string(f).trim()===""&&ue.removeNodes(e,{at:p})})}else{if(r){const u={type:re.blockquote,children:[]};ue.wrapNodes(e,u)}const l={type:t,children:[]};ue.wrapNodes(e,l)}}catch(r){const i=r.message;n(`Error toggling block: ${i}`)}},e9=({format:e,hasDivider:t=!1})=>{const{reportError:n}=y.useContext(Ei),{setFocus:r}=y.useContext(vl),i=Oa(),a=hT(i,e);return h.jsx(Yp,{id:e,active:a,hasDivider:t,callback:()=>{pT(i,e,n),r(a?null:e)}})},Lo=e=>{const[t]=D.nodes(e,{match:n=>{const r=n;return!D.isEditor(n)&&Se.isElement(n)&&r.type===re.link}});return!!t},OP=(e,t,n,r)=>{e.selection&&Zp(e,t,n,r)},NP=(e,t,n,r)=>{const{selection:i}=e;if(i&&le.isCollapsed(i)){const[s]=D.nodes(e,{match:o=>{const l=o;return!D.isEditor(o)&&Se.isElement(o)&&l.type===re.link}});if(s){const[o,l]=s,u={link:t};ue.setNodes(e,u,{at:l}),Gp(n)}}else Zp(e,t,n,r)},Zp=(e,t,n,r=i=>{console.error(i)})=>{try{Lo(e)&&mT(e);const{selection:i}=e,a=i&&le.isCollapsed(i),s={type:re.link,link:t,children:a?[{text:t}]:[]};a?(ue.insertNodes(e,s),ue.move(e,{distance:1,unit:"offset"})):(ue.wrapNodes(e,s,{split:!0}),ue.collapse(e,{edge:"end"}),ue.insertNodes(e,{text:""}),ue.move(e,{distance:1,unit:"offset"})),Gp(n)}catch(i){const a=i.message;r(`Error in wrapLink: ${a}`)}},mT=e=>{ue.unwrapNodes(e,{match:t=>{const n=t;return!D.isEditor(t)&&Se.isElement(t)&&n.type===re.link}})};let Ed=null;const IP=()=>{const e=he.useIntl(),t="richTextEditor_link_",{id:n,isInOverlay:r,enrichedUrl:i,dispatch:a,getLinkPreview:s,showLinkEditor:o,reportError:l}=y.useContext(Ei),u=Oa(),c=VO(u),d=(c==null?void 0:c.text)||_P(u),f=i!==!1,[p,g]=y.useState(Lo(u)),m=Kb(u,"link-editor",`${n}-link`),E=y.useRef(null);y.useEffect(()=>{var w;!p&&o&&((w=E.current)==null||w.focus())},[p]),y.useEffect(()=>{Ed&&clearTimeout(Ed),Ed=setTimeout(()=>{g(Lo(u))},500)},[u.selection]);const v=[],b=["open","edit","remove"].map(w=>{const A={variant:"tertiary",size:"small",children:e.formatMessage({id:`${t}${w}`},{link:c==null?void 0:c.pretty})};switch(v.push({className:w}),w){case"open":A.href=(c==null?void 0:c.full)||"",A.onClick=S=>{S.preventDefault(),S.stopPropagation(),window.open((c==null?void 0:c.full)||"","_blank"),a([{type:"showLinkEditor",value:!1}])},A.children=h.jsxs(h.Fragment,{children:[A.children,h.jsx(ut,{children:e.formatMessage({id:`${t}${w}_text`})})]});break;case"edit":A.onClick=()=>{g(!1)};break;case"remove":A.onClick=()=>{const S=[{type:"showLinkEditor",value:!1}];Lo(u)&&(mT(u),S.push({type:"lastAnchor",value:null}),i&&(c==null?void 0:c.full)===(i==null?void 0:i.url)&&S.push({type:"enrichedUrl",value:!1})),a(S)};break}return A}),T=[{id:"url",type:"url",inputRef:E,label:e.formatMessage({id:`${t}url`}),placeholder:e.formatMessage({id:`${t}placeholder`}),value:(c==null?void 0:c.full)||"",validation:[{condition:"required",error:e.formatMessage({id:`${t}error_required`})},{condition:"valid-url"}],submitOnEnter:!0,autoFocus:!0,functions:{onChange:()=>{},onKeyDown:w=>{if(w.key==="Tab"){if(!u)return;w.preventDefault(),w.stopPropagation();const A=D.end(u,[]);ue.select(u,A),ce.focus(u)}}}}];d&&T.unshift({component:()=>h.jsxs("p",{children:[h.jsx("strong",{"aria-label":e.formatMessage({id:`${t}text_aria`}),children:e.formatMessage({id:`${t}text`})})," ",d]})});const _=dT(r);return h.jsx(Ms,{parent:_,children:h.jsx(Da,{ref:m,id:`${n}-link-editor`,className:"link-editor",isOpen:o,styling:{extraPadding:!1,hasForm:!p},functions:{onBlur:()=>{a([{type:"showLinkEditor",value:!1}])}},callbacks:{onOpen:()=>{setTimeout(()=>{var w;return(w=E.current)==null?void 0:w.focus()})}},children:p?h.jsx(Bs,{wrappers:v,buttons:b}):h.jsx(Gr,{element:"fieldset",id:`${n}-link-editor`,className:J({"show-labels":d}),meta:{shouldReset:!0,showRequiredLabels:!1},functions:{onSuccess:async w=>{setTimeout(async()=>{a([{type:"showLinkEditor",value:!1}]);let A=w.url;if(w.url){const{full:S}=rp(w.url);A=S,c!=null&&c.full?NP(u,A,n,l):OP(u,A,n,l),a({type:"lastAnchor",value:null})}if(w.url&&s&&(!f||i&&(c==null?void 0:c.full)===i.url)){const S=await s(A);S.url&&a([{type:"enrichedUrl",value:S}])}})}},fields:T,button:{text:e.formatMessage({id:`${t}button`}),variant:"tertiary",size:"small"}})})})},PP=()=>{const e=Oa(),{dispatch:t}=y.useContext(Ei),{setFocus:n}=y.useContext(vl),[r,i]=y.useState(!1);return y.useEffect(()=>{i(Lo(e))},[e.selection]),h.jsx(Yp,{id:"link",active:r,hasDivider:!0,callback:()=>{t([{type:"showLinkEditor",value:!0}]),n(r?null:"link"),i(!0)},"aria-pressed":null})},RP=e=>[re.bold,re.italic,re.strikethrough].includes(e),gT=(e,t)=>{const n=D.marks(e);return n?n[t]===!0:!1},vT=(e,t,n)=>{try{gT(e,t)?D.removeMark(e,t):D.addMark(e,t,!0)}catch(r){const i=r.message;n(`Error toggling mark: ${i}`)}},FP=({format:e,hasDivider:t=!1})=>{const{reportError:n}=y.useContext(Ei),{setFocus:r}=y.useContext(vl),i=Oa(),a=gT(i,e);return h.jsx(Yp,{id:e,active:a,hasDivider:t,callback:()=>{vT(i,e,n),r(a?null:e)}})},Xl=[re.bold,re.italic,re.strikethrough],BP=[re.ol,re.ul,re.blockquote];const MP=({styling:e={showHeadingOption:!1},...t})=>{const n=he.useIntl(),{id:r}=y.useContext(Ei),i={tabbableOption:Xl[0],openTooltip:null},[a,s]=y.useReducer(Fs,i),o=l=>{l&&s([{type:"tabbableOption",value:l||Xl[0]}])};return h.jsxs(vl.Provider,{value:{...a,setFocus:o,dispatch:s},children:[h.jsxs("fieldset",{id:`toolbar-${r}`,className:"toolbar",...t,children:[h.jsx(ut,{element:"legend",showOnFocus:!1,children:n.formatMessage({id:"richTextEditor_toolbar"})}),h.jsxs("ul",{children:[(e==null?void 0:e.showHeadingOption)&&h.jsx(e9,{format:re.h3,hasDivider:!0},re.h3),Xl.map((l,u)=>h.jsx(FP,{format:l,hasDivider:u===Xl.length-1},l)),h.jsx(PP,{}),BP.map((l,u)=>h.jsx(e9,{format:l,hasDivider:u===1},l))]})]}),h.jsx(IP,{})]})},LP=y.memo(MP);function $P(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}function _h(e,t){return Array(t+1).join(e)}function jP(e){return e.replace(/^\n*/,"")}function HP(e){for(var t=e.length;t>0&&e[t-1]===`
|
|
104
|
+
`;default:return u}}function Ua(e,t){const n=e.trim(),r=n,i=`${t}${r}${Xv(t)}`;if(r.length===e.length)return i;const a=t+r+Xv(t);return e.replace(n,a)}const Xv=e=>e.split("").reverse().join(""),SP=e=>e.map(t=>fT(t)).join("").trim();const kP=({onFallbackClick:e=()=>{}})=>{const t=he.useIntl(),n=Oa(),{dispatch:r,isInOverlay:i,mentionPopover:a,id:s,onMention:o}=y.useContext(Ei),{show:l,selectedUser:u,possibleUsers:c}=a,d=Kb(n,"mention-popover",`toolbar-${s}`);if(!l)return h.jsx(h.Fragment,{});const f=dT(i);return h.jsx(Ms,{parent:f,children:h.jsx(Yy,{ref:d,className:"mention-popover",onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),r([{type:"showMentionPopover",value:!1}]))},children:h.jsxs("ul",{children:[c.map(({userId:p,user:g},m)=>h.jsx(ci,{element:"li",className:J({selected:m===u}),member:{id:p,...g,link:!1},functions:{onClick:E=>{E.preventDefault(),E.stopPropagation();const v={...a,selectedUser:m};r([{type:"mentionPopover",value:v}]),cT(n,v,r,s),o&&o({id:p||"",name:g.name||""})}}},p)),h.jsx(ci,{element:"li",className:J("fallback",{selected:c.length===u}),member:{id:"0",name:t.formatMessage({id:"richTextEditor_mention_fallback"}),image:{thumbnail:`${Ur}icons/invite-user.svg`},link:!1},functions:{onClick:p=>{p.preventDefault(),p.stopPropagation(),e(),r([{type:"mentionPopover",value:{show:!1,selectedUser:0,possibleUsers:[],position:null}}])}}})]})})})};const wc=({formID:e,label:t,showLabel:n})=>{const{visible:r="",screenreader:i=""}=t||{};return n?h.jsx("label",{htmlFor:`${e}-input`,className:"rte-label text-small",onClick:a=>{a.preventDefault(),a.stopPropagation();const s=new CustomEvent("focusEditor",{detail:{id:`rte-${e}-input`}});window.dispatchEvent(s)},children:r}):h.jsx(ut,{element:"label",showOnFocus:!1,htmlFor:`${e}-input`,children:i})},Yp=({id:e,active:t,hasDivider:n=!1,callback:r,className:i="",children:a,"aria-pressed":s,...o})=>{const l=he.useIntl(),u=Oa(),{id:c,dispatch:d}=y.useContext(Ei),{tabbableOption:f,setFocus:p,openTooltip:g,dispatch:m}=y.useContext(vl),E={};return e!==f&&(E.tabIndex=-1),s!==null&&(E["aria-pressed"]=typeof s=="boolean"?s:t),h.jsxs("li",{id:`${c}-${e}`,className:J(e,{"has-divider":n}),onMouseEnter:()=>{m([{type:"openTooltip",value:e}])},onMouseLeave:()=>{m([{type:"openTooltip",value:null}])},onFocus:()=>{m([{type:"openTooltip",value:e}])},onBlur:v=>{v.stopPropagation(),m([{type:"openTooltip",value:null}]),u.selection&&d({type:"lastAnchor",value:u.selection.anchor})},contentEditable:!1,children:[h.jsxs("button",{...o,...E,className:J(e,i,{active:t}),onClick:v=>{v.stopPropagation(),v.preventDefault()},onMouseDown:v=>{v.stopPropagation(),v.preventDefault(),r()},onKeyDown:v=>{var b,T,_,w;if(v.key!=="Tab")switch(v.key){case"Enter":v.stopPropagation(),v.preventDefault(),r();break;case"ArrowLeft":case"ArrowRight":v.stopPropagation(),v.preventDefault();const A=v.currentTarget.closest("li");let S=A==null?void 0:A.nextElementSibling;if(v.key==="ArrowLeft"){const L=A==null?void 0:A.previousElementSibling;L?S=L:S=(b=A==null?void 0:A.parentElement)==null?void 0:b.lastElementChild}else S||(S=(T=A==null?void 0:A.parentElement)==null?void 0:T.firstElementChild);const B=S==null?void 0:S.className.split(" ")[0];B&&(p(B),(_=S==null?void 0:S.querySelector("button"))==null||_.focus());break;default:const F=v.currentTarget.closest("fieldset");if(F){(w=F==null?void 0:F.previousElementSibling)==null||w.focus();break}}},children:[h.jsx(ut,{showOnFocus:!1,children:l.formatMessage({id:`richTextEditor_${e}`})}),h.jsx(Da,{id:`tooltip-${e}`,styling:{extraPadding:!1,hasPointer:"bottom"},isOpen:g===e,accessibility:{"aria-hidden":!0},children:l.formatMessage({id:`richTextEditor_${e}`})})]}),a]})},Jv=[re.ol,re.ul],hT=(e,t)=>{const{selection:n}=e;if(!n)return!1;const[r]=Array.from(D.nodes(e,{at:D.unhangRange(e,n),match:i=>{const a=i;return!D.isEditor(i)&&Se.isElement(i)&&a.type===t}}));return!!r},DP=e=>{const[t]=D.nodes(e,{match:n=>n.type===re.blockquote});return!!t},pT=(e,t,n)=>{try{const r=DP(e),i=hT(e,t),a=Jv.includes(t);ue.unwrapNodes(e,{match:l=>{const u=l;return!D.isEditor(u)&&Se.isElement(u)&&Jv.includes(u.type)},split:!0});const o={type:i?re.paragraph:a?re.li:t};if(ue.setNodes(e,o),t===re.h3){const l={type:i?re.paragraph:t};i?D.removeMark(e,t):D.addMark(e,t,!0),ue.setNodes(e,l)}if(a)if(i){const{selection:l}=e;if(!l)return;const[u,c]=D.parent(e,l,{edge:"end"});Array.from(D.nodes(e,{at:c,match:f=>{const p=f;return!D.isEditor(f)&&Se.isElement(f)&&p.type===re.li}})).forEach(([f,p])=>{Ee.string(f).trim()===""&&ue.removeNodes(e,{at:p})})}else{if(r){const u={type:re.blockquote,children:[]};ue.wrapNodes(e,u)}const l={type:t,children:[]};ue.wrapNodes(e,l)}}catch(r){const i=r.message;n(`Error toggling block: ${i}`)}},e9=({format:e,hasDivider:t=!1})=>{const{reportError:n}=y.useContext(Ei),{setFocus:r}=y.useContext(vl),i=Oa(),a=hT(i,e);return h.jsx(Yp,{id:e,active:a,hasDivider:t,callback:()=>{pT(i,e,n),r(a?null:e)}})},Lo=e=>{const[t]=D.nodes(e,{match:n=>{const r=n;return!D.isEditor(n)&&Se.isElement(n)&&r.type===re.link}});return!!t},OP=(e,t,n,r)=>{e.selection&&Zp(e,t,n,r)},NP=(e,t,n,r)=>{const{selection:i}=e;if(i&&le.isCollapsed(i)){const[s]=D.nodes(e,{match:o=>{const l=o;return!D.isEditor(o)&&Se.isElement(o)&&l.type===re.link}});if(s){const[o,l]=s,u={link:t};ue.setNodes(e,u,{at:l}),Gp(n)}}else Zp(e,t,n,r)},Zp=(e,t,n,r=i=>{console.error(i)})=>{try{Lo(e)&&mT(e);const{selection:i}=e,a=i&&le.isCollapsed(i),s={type:re.link,link:t,children:a?[{text:t}]:[]};a?(ue.insertNodes(e,s),ue.move(e,{distance:1,unit:"offset"})):(ue.wrapNodes(e,s,{split:!0}),ue.collapse(e,{edge:"end"}),ue.insertNodes(e,{text:""}),ue.move(e,{distance:1,unit:"offset"})),Gp(n)}catch(i){const a=i.message;r(`Error in wrapLink: ${a}`)}},mT=e=>{ue.unwrapNodes(e,{match:t=>{const n=t;return!D.isEditor(t)&&Se.isElement(t)&&n.type===re.link}})};let Ed=null;const IP=()=>{const e=he.useIntl(),t="richTextEditor_link_",{id:n,isInOverlay:r,enrichedUrl:i,dispatch:a,getLinkPreview:s,showLinkEditor:o,reportError:l}=y.useContext(Ei),u=Oa(),c=VO(u),d=(c==null?void 0:c.text)||_P(u),f=i!==!1,[p,g]=y.useState(Lo(u)),m=Kb(u,"link-editor",`${n}-link`),E=y.useRef(null);y.useEffect(()=>{var w;!p&&o&&((w=E.current)==null||w.focus())},[p]),y.useEffect(()=>{Ed&&clearTimeout(Ed),Ed=setTimeout(()=>{g(Lo(u))},500)},[u.selection]);const v=[],b=["open","edit","remove"].map(w=>{const A={variant:"tertiary",size:"small",children:e.formatMessage({id:`${t}${w}`},{link:c==null?void 0:c.pretty})};switch(v.push({className:w}),w){case"open":A.href=(c==null?void 0:c.full)||"",A.onClick=S=>{S.preventDefault(),S.stopPropagation(),window.open((c==null?void 0:c.full)||"","_blank"),a([{type:"showLinkEditor",value:!1}])},A.children=h.jsxs(h.Fragment,{children:[A.children,h.jsx(ut,{children:e.formatMessage({id:`${t}${w}_text`})})]});break;case"edit":A.onClick=()=>{g(!1)};break;case"remove":A.onClick=()=>{const S=[{type:"showLinkEditor",value:!1}];Lo(u)&&(mT(u),S.push({type:"lastAnchor",value:null}),i&&(c==null?void 0:c.full)===(i==null?void 0:i.url)&&S.push({type:"enrichedUrl",value:!1})),a(S)};break}return A}),T=[{id:"url",type:"url",inputRef:E,label:e.formatMessage({id:`${t}url`}),placeholder:e.formatMessage({id:`${t}placeholder`}),value:(c==null?void 0:c.full)||"",validation:[{condition:"required",error:e.formatMessage({id:`${t}error_required`})},{condition:"valid-url"}],submitOnEnter:!0,autoFocus:!0,functions:{onChange:()=>{},onKeyDown:w=>{if(w.key==="Tab"){if(!u)return;w.preventDefault(),w.stopPropagation();const A=D.end(u,[]);ue.select(u,A),ce.focus(u)}}}}];d&&T.unshift({component:()=>h.jsxs("p",{children:[h.jsx("strong",{"aria-label":e.formatMessage({id:`${t}text_aria`}),children:e.formatMessage({id:`${t}text`})})," ",d]})});const _=dT(r);return h.jsx(Ms,{parent:_,children:h.jsx(Da,{ref:m,id:`${n}-link-editor`,className:"link-editor",isOpen:o,styling:{extraPadding:!1,hasForm:!p},functions:{onBlur:()=>{a([{type:"showLinkEditor",value:!1}])}},callbacks:{onOpen:()=>{setTimeout(()=>{var w;return(w=E.current)==null?void 0:w.focus()})}},children:p?h.jsx(Bs,{wrappers:v,buttons:b}):h.jsx(Gr,{element:"fieldset",id:`${n}-link-editor`,className:J({"show-labels":d}),meta:{shouldReset:!0,showRequiredLabels:!1},functions:{onSuccess:async w=>{setTimeout(async()=>{a([{type:"showLinkEditor",value:!1}]);let A=w.url;if(w.url){const{full:S}=rp(w.url);A=S,c!=null&&c.full?NP(u,A,n,l):OP(u,A,n,l),a({type:"lastAnchor",value:null})}if(w.url&&s&&(!f||i&&(c==null?void 0:c.full)===i.url)){const S=await s(A);S.url&&a([{type:"enrichedUrl",value:S}])}})}},fields:T,button:{text:e.formatMessage({id:`${t}button`}),variant:"tertiary",size:"small"}})})})},PP=()=>{const e=Oa(),{dispatch:t}=y.useContext(Ei),{setFocus:n}=y.useContext(vl),[r,i]=y.useState(!1);return y.useEffect(()=>{i(Lo(e))},[e.selection]),h.jsx(Yp,{id:"link",active:r,hasDivider:!0,callback:()=>{t([{type:"showLinkEditor",value:!0}]),n(r?null:"link"),i(!0)},"aria-pressed":null})},RP=e=>[re.bold,re.italic,re.strikethrough].includes(e),gT=(e,t)=>{const n=D.marks(e);return n?n[t]===!0:!1},vT=(e,t,n)=>{try{gT(e,t)?D.removeMark(e,t):D.addMark(e,t,!0)}catch(r){const i=r.message;n(`Error toggling mark: ${i}`)}},FP=({format:e,hasDivider:t=!1})=>{const{reportError:n}=y.useContext(Ei),{setFocus:r}=y.useContext(vl),i=Oa(),a=gT(i,e);return h.jsx(Yp,{id:e,active:a,hasDivider:t,callback:()=>{vT(i,e,n),r(a?null:e)}})},Xl=[re.bold,re.italic,re.strikethrough],BP=[re.ol,re.ul,re.blockquote];const MP=({styling:e={showHeadingOption:!1},...t})=>{const n=he.useIntl(),{id:r}=y.useContext(Ei),i={tabbableOption:Xl[0],openTooltip:null},[a,s]=y.useReducer(Fs,i),o=l=>{l&&s([{type:"tabbableOption",value:l||Xl[0]}])};return h.jsxs(vl.Provider,{value:{...a,setFocus:o,dispatch:s},children:[h.jsxs("fieldset",{id:`toolbar-${r}`,className:"toolbar",...t,children:[h.jsx(ut,{element:"legend",showOnFocus:!1,children:n.formatMessage({id:"richTextEditor_toolbar"})}),h.jsxs("ul",{children:[(e==null?void 0:e.showHeadingOption)&&h.jsx(e9,{format:re.h3,hasDivider:!0},re.h3),Xl.map((l,u)=>h.jsx(FP,{format:l,hasDivider:u===Xl.length-1},l)),h.jsx(PP,{}),BP.map((l,u)=>h.jsx(e9,{format:l,hasDivider:u===1},l))]})]}),h.jsx(IP,{})]})},LP=y.memo(MP);function $P(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}function _h(e,t){return Array(t+1).join(e)}function jP(e){return e.replace(/^\n*/,"")}function HP(e){for(var t=e.length;t>0&&e[t-1]===`
|
|
105
105
|
`;)t--;return e.substring(0,t)}var UP=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function Qp(e){return Xp(e,UP)}var ET=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function yT(e){return Xp(e,ET)}function zP(e){return TT(e,ET)}var bT=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function qP(e){return Xp(e,bT)}function WP(e){return TT(e,bT)}function Xp(e,t){return t.indexOf(e.nodeName)>=0}function TT(e,t){return e.getElementsByTagName&&t.some(function(n){return e.getElementsByTagName(n).length})}var un={};un.paragraph={filter:"p",replacement:function(e){return`
|
|
106
106
|
|
|
107
107
|
`+e+`
|
package/index.mjs
CHANGED
|
@@ -23509,7 +23509,7 @@ const _h = ({ formID: e, label: t, showLabel: n }) => {
|
|
|
23509
23509
|
};
|
|
23510
23510
|
if (ue.setNodes(e, o), t === re.h3) {
|
|
23511
23511
|
const l = {
|
|
23512
|
-
type: t
|
|
23512
|
+
type: i ? re.paragraph : t
|
|
23513
23513
|
};
|
|
23514
23514
|
i ? D.removeMark(e, t) : D.addMark(e, t, !0), ue.setNodes(e, l);
|
|
23515
23515
|
}
|