carbon-react 158.27.3 → 158.27.4

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.
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{SELECTION_CHANGE_COMMAND as o,$getSelection as n,$isRangeSelection as r,COMMAND_PRIORITY_LOW as s,TextNode as a,$getRoot as i,$isParagraphNode as p}from"lexical";import{useState as c,useEffect as d}from"react";import{Box as m}from"../../../../../box/box.component.js";import{StyledSpanNode as l}from"../../../__nodes__/styled-span.node.js";import f from"./typography-dropdown/dropdown.component.js";function u(e){let t=e.anchor.getNode();for(;t;){if(t instanceof l)return t;t=t.getParent()}return null}const g=({contentEditorRef:g,namespace:h,isFirstButton:x=!1,isOpen:C,setIsOpen:y,focusedIndex:F=-1,setFocusedIndex:I,size:O})=>{const[T]=t(),[b,j]=c("paragraph");d((()=>T.registerCommand(o,(()=>(setTimeout((()=>{T.getEditorState().read((()=>{const e=n();if(r(e)){const t=u(e);j(t?t.getTypographyKey():"paragraph")}}))}),0),!1)),s)),[T]);const v=e=>{const t=e;j(t),T.update((()=>{const e=n();if(r(e)){const o=e.getNodes(),n=e.anchor.offset,r=e.focus.offset;let s=null;o.forEach((e=>{if(e instanceof a||e instanceof l){let o;o="paragraph"===t?new a(e.getTextContent()):l.createFromOption(t,e.getTextContent()),e.replace(o),s||(s=o)}})),s&&s.select(n,r)}else{let e;e="paragraph"===t?new a(""):l.createFromOption(t,"");const o=i(),n=o.getLastChild();p(n)?n.append(e):o.append(e),e.select()}}),{discrete:!0}),setTimeout((()=>{var e;null==g||null===(e=g.current)||void 0===e||e.focus(),T.dispatchCommand(o,void 0)}),0)};return e(m,{minWidth:"150px",marginRight:"spacing05",children:e(f,{size:O,namespace:h,onChange:e=>{v(e)},value:b,isFirstButton:x,options:["title","subtitle","sectionHeader","sectionSubheader","paragraph"].map((e=>({id:e,key:e,onClick:()=>{v(e)}}))),isOpen:C,setIsOpen:y,focusedIndex:F,setFocusedIndex:I})})};export{g as default,u as getStyledSpanFromSelection};
1
+ import{jsx as e}from"react/jsx-runtime";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{SELECTION_CHANGE_COMMAND as o,$getSelection as n,$isRangeSelection as r,COMMAND_PRIORITY_LOW as s,$isParagraphNode as a,TextNode as i,$getRoot as p}from"lexical";import{$isListItemNode as c}from"@lexical/list";import{useState as d,useEffect as m}from"react";import{Box as l}from"../../../../../box/box.component.js";import{StyledSpanNode as f}from"../../../__nodes__/styled-span.node.js";import u from"./typography-dropdown/dropdown.component.js";function g(e){let t=e.anchor.getNode();for(;t;){if(t instanceof f)return t;t=t.getParent()}return null}const h=({contentEditorRef:h,namespace:x,isFirstButton:C=!1,isOpen:y,setIsOpen:F,focusedIndex:I=-1,setFocusedIndex:O,size:b})=>{const[j]=t(),[v,w]=d("paragraph");m((()=>j.registerCommand(o,(()=>(setTimeout((()=>{j.getEditorState().read((()=>{const e=n();if(r(e)){const t=g(e);w(t?t.getTypographyKey():"paragraph")}}))}),0),!1)),s)),[j]);const T=e=>{const t=e;w(t),j.update((()=>{const e=n();if(r(e)){const o=e.getNodes(),n=e.anchor.offset,r=e.focus.offset;let s=null;o.forEach((e=>{const o=e instanceof i||e instanceof f,n=a(e),r=c(e);if(!o&&!n&&!r)return;const p="paragraph"===t,d=n||r?"​":e.getTextContent(),m=p?new i(d):f.createFromOption(t,d);o?e.replace(m):e.append(m),s||(s=m)})),s&&s.select(n,r)}else{let e;e="paragraph"===t?new i(""):f.createFromOption(t,"");const o=p(),n=o.getLastChild();a(n)?n.append(e):o.append(e),e.select()}}),{discrete:!0}),setTimeout((()=>{var e;null==h||null===(e=h.current)||void 0===e||e.focus(),j.dispatchCommand(o,void 0)}),0)};return e(l,{minWidth:"150px",marginRight:"spacing05",children:e(u,{size:b,namespace:x,onChange:e=>{T(e)},value:v,isFirstButton:C,options:["title","subtitle","sectionHeader","sectionSubheader","paragraph"].map((e=>({id:e,key:e,onClick:()=>{T(e)}}))),isOpen:y,setIsOpen:F,focusedIndex:I,setFocusedIndex:O})})};export{h as default,g as getStyledSpanFromSelection};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@lexical/react/LexicalComposerContext"),o=require("lexical"),n=require("react"),r=require("../../../../../box/box.component.js"),s=require("../../../__nodes__/styled-span.node.js"),a=require("./typography-dropdown/dropdown.component.js");function i(e){let t=e.anchor.getNode();for(;t;){if(t instanceof s.StyledSpanNode)return t;t=t.getParent()}return null}exports.default=({contentEditorRef:c,namespace:d,isFirstButton:p=!1,isOpen:l,setIsOpen:u,focusedIndex:g=-1,setFocusedIndex:x,size:f})=>{const[S]=t.useLexicalComposerContext(),[m,h]=n.useState("paragraph");n.useEffect((()=>S.registerCommand(o.SELECTION_CHANGE_COMMAND,(()=>(setTimeout((()=>{S.getEditorState().read((()=>{const e=o.$getSelection();if(o.$isRangeSelection(e)){const t=i(e);h(t?t.getTypographyKey():"paragraph")}}))}),0),!1)),o.COMMAND_PRIORITY_LOW)),[S]);const C=e=>{const t=e;h(t),S.update((()=>{const e=o.$getSelection();if(o.$isRangeSelection(e)){const n=e.getNodes(),r=e.anchor.offset,a=e.focus.offset;let i=null;n.forEach((e=>{if(e instanceof o.TextNode||e instanceof s.StyledSpanNode){let n;n="paragraph"===t?new o.TextNode(e.getTextContent()):s.StyledSpanNode.createFromOption(t,e.getTextContent()),e.replace(n),i||(i=n)}})),i&&i.select(r,a)}else{let e;e="paragraph"===t?new o.TextNode(""):s.StyledSpanNode.createFromOption(t,"");const n=o.$getRoot(),r=n.getLastChild();o.$isParagraphNode(r)?r.append(e):n.append(e),e.select()}}),{discrete:!0}),setTimeout((()=>{var e;null==c||null===(e=c.current)||void 0===e||e.focus(),S.dispatchCommand(o.SELECTION_CHANGE_COMMAND,void 0)}),0)};return e.jsx(r.Box,{minWidth:"150px",marginRight:"spacing05",children:e.jsx(a.default,{size:f,namespace:d,onChange:e=>{C(e)},value:m,isFirstButton:p,options:["title","subtitle","sectionHeader","sectionSubheader","paragraph"].map((e=>({id:e,key:e,onClick:()=>{C(e)}}))),isOpen:l,setIsOpen:u,focusedIndex:g,setFocusedIndex:x})})},exports.getStyledSpanFromSelection=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@lexical/react/LexicalComposerContext"),o=require("lexical"),n=require("@lexical/list"),r=require("react"),s=require("../../../../../box/box.component.js"),a=require("../../../__nodes__/styled-span.node.js"),i=require("./typography-dropdown/dropdown.component.js");function c(e){let t=e.anchor.getNode();for(;t;){if(t instanceof a.StyledSpanNode)return t;t=t.getParent()}return null}exports.default=({contentEditorRef:d,namespace:p,isFirstButton:l=!1,isOpen:u,setIsOpen:g,focusedIndex:x=-1,setFocusedIndex:f,size:m})=>{const[S]=t.useLexicalComposerContext(),[h,N]=r.useState("paragraph");r.useEffect((()=>S.registerCommand(o.SELECTION_CHANGE_COMMAND,(()=>(setTimeout((()=>{S.getEditorState().read((()=>{const e=o.$getSelection();if(o.$isRangeSelection(e)){const t=c(e);N(t?t.getTypographyKey():"paragraph")}}))}),0),!1)),o.COMMAND_PRIORITY_LOW)),[S]);const C=e=>{const t=e;N(t),S.update((()=>{const e=o.$getSelection();if(o.$isRangeSelection(e)){const r=e.getNodes(),s=e.anchor.offset,i=e.focus.offset;let c=null;r.forEach((e=>{const r=e instanceof o.TextNode||e instanceof a.StyledSpanNode,s=o.$isParagraphNode(e),i=n.$isListItemNode(e);if(!r&&!s&&!i)return;const d="paragraph"===t,p=s||i?"​":e.getTextContent(),l=d?new o.TextNode(p):a.StyledSpanNode.createFromOption(t,p);r?e.replace(l):e.append(l),c||(c=l)})),c&&c.select(s,i)}else{let e;e="paragraph"===t?new o.TextNode(""):a.StyledSpanNode.createFromOption(t,"");const n=o.$getRoot(),r=n.getLastChild();o.$isParagraphNode(r)?r.append(e):n.append(e),e.select()}}),{discrete:!0}),setTimeout((()=>{var e;null==d||null===(e=d.current)||void 0===e||e.focus(),S.dispatchCommand(o.SELECTION_CHANGE_COMMAND,void 0)}),0)};return e.jsx(s.Box,{minWidth:"150px",marginRight:"spacing05",children:e.jsx(i.default,{size:m,namespace:p,onChange:e=>{C(e)},value:h,isFirstButton:l,options:["title","subtitle","sectionHeader","sectionSubheader","paragraph"].map((e=>({id:e,key:e,onClick:()=>{C(e)}}))),isOpen:u,setIsOpen:g,focusedIndex:x,setFocusedIndex:f})})},exports.getStyledSpanFromSelection=c;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "158.27.3",
3
+ "version": "158.27.4",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",