frst-components 0.22.18 → 0.22.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/dist/index.js CHANGED
@@ -3330,6 +3330,7 @@ const InputText$4 = styled__default["default"].div `
3330
3330
  border: 1px solid ${({ theme }) => theme.colors.neutralsGrey3};
3331
3331
  overflow: hidden;
3332
3332
  background-color: inherit;
3333
+
3333
3334
 
3334
3335
  padding: 0;
3335
3336
  margin: ${({ isPlaceholder }) => isPlaceholder ? '10px 4px 10px 15px' : '10px 4px 40px 15px'};
@@ -3406,6 +3407,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3406
3407
  const [showMention, setShowMention] = React.useState(false);
3407
3408
  const [inputSearch, setInputSearch] = React.useState('');
3408
3409
  const divInputRef = React.useRef(null);
3410
+ const mainContainerRef = React.useRef(null);
3409
3411
  const mentionTopPosition = `${(divInputRef.current?.clientHeight ?? 15) + 20}px`;
3410
3412
  const [textLength, setTextLength] = React.useState(0);
3411
3413
  const [isPlaceholder, setPlaceholder] = React.useState(false);
@@ -3513,6 +3515,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3513
3515
  let hasSpaceBeForeKey = false;
3514
3516
  let hasKeyPresent = false;
3515
3517
  let textBeforeCursor = "";
3518
+ let textBeforeKey = "";
3516
3519
  if (selection && selection.rangeCount > 0) {
3517
3520
  const range = selection.getRangeAt(0);
3518
3521
  if (range.startContainer.textContent === null)
@@ -3523,44 +3526,30 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3523
3526
  const atIndex = completeText.lastIndexOf('@');
3524
3527
  textBeforeCursor = range.startContainer.textContent.substring(atIndex, range.startOffset);
3525
3528
  hasSpaceBeForeKey = completeText.substring(atIndex - 1, atIndex).trim() === "";
3526
- console.log(`teste - completeText = ${completeText}`);
3527
- console.log(`teste textBeforeCursor ${textBeforeCursor}`);
3528
- console.log(`teste - atIndex = ${atIndex}`);
3529
- console.log(`teste - spaceBefore = ${completeText.substring(atIndex - 1, atIndex).trim() === ""}`);
3530
- console.log(`teste hasSpaceBeForeKey ${hasSpaceBeForeKey}`);
3531
- console.log(`teste textBeforeCursor = @ ? ${textBeforeCursor === "@"}`);
3532
- if (hasSpaceBeForeKey || textBeforeCursor === "@") {
3529
+ textBeforeKey = completeText.substring(atIndex - 1, atIndex).trim();
3530
+ if (hasSpaceBeForeKey || (textBeforeCursor === "@" && textBeforeKey.length === 0)) {
3533
3531
  if (atIndex !== -1) {
3534
3532
  // Get the characters after the last "@"
3535
3533
  const afterAt = completeText.substring(atIndex);
3536
- console.log(`teste afterAt = ${afterAt}`);
3537
3534
  if (afterAt.length > 1 || event.key === "@" || textBeforeCursor === "@") {
3538
- console.log(`teste hasKeyPresent ${hasKeyPresent}`);
3539
3535
  hasKeyPresent = true;
3540
3536
  }
3541
3537
  inputSearch = afterAt.replace('@', '');
3542
3538
  }
3543
3539
  else {
3544
- console.log(`teste esconde mention atIndex = ${atIndex}`);
3545
3540
  inputSearch = '';
3546
3541
  setShowMention(false);
3547
3542
  }
3548
3543
  }
3549
3544
  else {
3550
- console.log(`teste esconde mention`);
3551
3545
  setShowMention(false);
3552
3546
  }
3553
3547
  }
3554
- if ((hasSpaceBeForeKey && hasKeyPresent) || textBeforeCursor === "@") {
3555
- console.log(`teste, chamar backend com ${inputSearch}`);
3548
+ if ((hasSpaceBeForeKey && hasKeyPresent) || (textBeforeCursor === "@" && textBeforeKey.length === 0)) {
3556
3549
  setShowMention(true);
3557
3550
  setInputSearch(inputSearch);
3558
3551
  !!onChange && onChange(inputSearch);
3559
3552
  }
3560
- else {
3561
- console.log(`teste resultado foi ${hasSpaceBeForeKey && hasKeyPresent} e textBeforeCursor = @ ${textBeforeCursor === "@"}`);
3562
- console.log(`teste, não chamou o backend ${inputSearch}`);
3563
- }
3564
3553
  countChars();
3565
3554
  createFormatAndTextContentToSaveComment();
3566
3555
  };
@@ -3580,18 +3569,13 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3580
3569
  const clearDivContent = () => {
3581
3570
  if (!divInputRef.current)
3582
3571
  return;
3583
- console.log(`placeholder primeiro if divInputRef.current.childNodes.length === 0 && !focus resultado = ${divInputRef.current.childNodes.length === 0 && !focus}`);
3584
- console.log(`placeholder segundo if divInputRef.current.childNodes.length >= 1 resultado = ${divInputRef.current.childNodes.length >= 1}`);
3572
+ console.log(`active element = ${document.activeElement}`);
3585
3573
  if ((divInputRef.current.childNodes.length === 0 && !focus)) {
3586
- console.log(`placeholder vou incluir o placeholder`);
3587
- debugger;
3588
3574
  // create a textnode with the placeholder
3589
3575
  divInputRef.current.innerText = placeholder;
3590
3576
  setPlaceholder(true);
3591
3577
  }
3592
3578
  else if (!focus && divInputRef.current.childNodes.length >= 1) {
3593
- debugger;
3594
- console.log(`placeholder vou incluir 2 o placeholder`);
3595
3579
  // loop over all child element and check if they are empty
3596
3580
  let isEmpty = true;
3597
3581
  divInputRef.current.childNodes.forEach((child) => {
@@ -3600,11 +3584,9 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3600
3584
  setPlaceholder(false);
3601
3585
  }
3602
3586
  else if (child.textContent === placeholder) {
3603
- console.log(`placeholder child.textContent === placeholder resultado = ${child.textContent === placeholder}`);
3604
3587
  divInputRef.current.blur();
3605
3588
  }
3606
3589
  });
3607
- console.log('placeholder isEmpty = ', isEmpty);
3608
3590
  // if they are empty show the placeholder
3609
3591
  if (isEmpty) {
3610
3592
  // create a textnode with the placeholder
@@ -3613,20 +3595,15 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3613
3595
  }
3614
3596
  }
3615
3597
  else if (divInputRef.current.innerText === placeholder) {
3616
- console.log(`placeholder terceiro divInputRef.current.innerText === placeholder resultado = ${divInputRef.current.innerText === placeholder}`);
3617
- debugger;
3618
3598
  // create a paragraph node
3619
3599
  divInputRef.current.innerHTML = '';
3620
3600
  // clear complete the div
3621
3601
  divInputRef.current.innerText = '';
3622
- console.log(`placeholder clear`);
3623
3602
  const p = document.createElement('p');
3624
3603
  const br = document.createElement('br');
3625
3604
  p.appendChild(br);
3626
3605
  divInputRef.current.appendChild(p);
3627
- console.log(`placeholder divInputRef.current.innerHtml= ${divInputRef.current.innerHTML}`);
3628
3606
  setPlaceholder(false);
3629
- divInputRef.current.blur();
3630
3607
  }
3631
3608
  };
3632
3609
  React.useEffect(() => {
@@ -3667,7 +3644,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3667
3644
  setStyleLimitExceeded(textLength > limit);
3668
3645
  }, [textLength]);
3669
3646
  React.useEffect(() => {
3670
- if (!divInputRef.current)
3647
+ if (!divInputRef.current || !mainContainerRef.current)
3671
3648
  return;
3672
3649
  divInputRef.current.addEventListener('mousedown', () => {
3673
3650
  setFocus(true);
@@ -3678,6 +3655,15 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3678
3655
  divInputRef.current.addEventListener('blur', () => {
3679
3656
  setFocus(false);
3680
3657
  });
3658
+ mainContainerRef.current.addEventListener('mousedown', () => {
3659
+ setFocus(true);
3660
+ });
3661
+ mainContainerRef.current.addEventListener('focus', () => {
3662
+ setFocus(true);
3663
+ });
3664
+ mainContainerRef.current.addEventListener('blur', () => {
3665
+ setFocus(false);
3666
+ });
3681
3667
  //capture the cursor position on arrow up and down or left and right and check if it´s close to the @ key
3682
3668
  divInputRef.current.addEventListener('keyup', (event) => {
3683
3669
  if (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'Enter') {
@@ -3694,6 +3680,15 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3694
3680
  divInputRef.current?.removeEventListener('blur', () => {
3695
3681
  setFocus(false);
3696
3682
  });
3683
+ mainContainerRef.current?.removeEventListener('mousedown', () => {
3684
+ setFocus(true);
3685
+ });
3686
+ mainContainerRef.current?.removeEventListener('focus', () => {
3687
+ setFocus(true);
3688
+ });
3689
+ mainContainerRef.current?.removeEventListener('blur', () => {
3690
+ setFocus(false);
3691
+ });
3697
3692
  //capture the cursor position on arrow up and down or left and right and check if it´s close to the @ key
3698
3693
  divInputRef.current.removeEventListener('keyup', (event) => {
3699
3694
  if (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'Enter') {
@@ -3715,7 +3710,8 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3715
3710
  handleMentionUser,
3716
3711
  textLength,
3717
3712
  isPlaceholder,
3718
- styleLimitExceeded
3713
+ styleLimitExceeded,
3714
+ mainContainerRef
3719
3715
  };
3720
3716
  };
3721
3717
 
@@ -3895,8 +3891,8 @@ const Mentions = (mention) => {
3895
3891
  };
3896
3892
 
3897
3893
  function InputComment$1({ placeholder, onChange, limit, users, showCharacterCounter, styles, onSendMentions, onContentFormat, onContentUnformat, disabled, className, value, replyMentionedUser, group_uuid, limitMessageExceeded }) {
3898
- const { handleInput, isPlaceholder, focus, divInputRef, handleMentionUser, mentionTopPosition, setShowMention, showMention, textLength, styleLimitExceeded } = useInputHook({ limit, placeholder, onContentFormat, onContentUnformat, onSendMentions, onChange, value, replyMentionedUser });
3899
- return (jsxRuntime.jsx(styled.ThemeProvider, { theme: FRSTTheme, children: jsxRuntime.jsxs("div", { style: { minHeight: '48px', ...styles }, tabIndex: 0, contentEditable: false, children: [jsxRuntime.jsxs(InputWrapper$2, { focus: focus, tabIndex: 1, isPlaceholder: isPlaceholder, isInputLimit: styleLimitExceeded, contentEditable: false, children: [jsxRuntime.jsx(InputText$4, { tabIndex: 2, contentEditable: true, ref: divInputRef, onKeyUpCapture: (event) => {
3894
+ const { mainContainerRef, handleInput, isPlaceholder, focus, divInputRef, handleMentionUser, mentionTopPosition, setShowMention, showMention, textLength, styleLimitExceeded } = useInputHook({ limit, placeholder, onContentFormat, onContentUnformat, onSendMentions, onChange, value, replyMentionedUser });
3895
+ return (jsxRuntime.jsx(styled.ThemeProvider, { theme: FRSTTheme, children: jsxRuntime.jsxs("div", { ref: mainContainerRef, style: { minHeight: '48px', ...styles }, tabIndex: 0, children: [jsxRuntime.jsxs(InputWrapper$2, { focus: focus, tabIndex: 1, isPlaceholder: isPlaceholder, isInputLimit: styleLimitExceeded, children: [jsxRuntime.jsx(InputText$4, { tabIndex: 2, contentEditable: true, ref: divInputRef, onKeyUpCapture: (event) => {
3900
3896
  handleInput(event);
3901
3897
  }, "data-text": "enter", isPlaceholder: isPlaceholder, suppressContentEditableWarning: true, children: jsxRuntime.jsx("p", { children: jsxRuntime.jsx("br", {}) }) }), showMention && users && users.length > 0 && jsxRuntime.jsx(Mentions, { users: users, top: mentionTopPosition, onSelect: (user) => {
3902
3898
  setShowMention(false);
@@ -1 +1 @@
1
- {"version":3,"file":"inputCommentStyles.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/inputCommentStyles.ts"],"names":[],"mappings":"AAQA,UAAU,OAAO;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,UAAU,YAAY;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mBAAmB,CAAC,EAAE,GAAG,CAAA;CAC5B;AACD,UAAU,QAAQ;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CAE3B;AAED,eAAO,MAAM,YAAY,yEAoBxB,CAAA;AAED,eAAO,MAAM,SAAS,0EAiBrB,CAAA;AAED,eAAO,MAAM,SAAS,oEAiBrB,CAAA;AACD,eAAO,MAAM,eAAe,oEAG3B,CAAA;AACD,eAAO,MAAM,UAAU;mBAA8B,OAAO;SAkB3D,CAAA;AAED,eAAO,MAAM,WAAW,8EAWvB,CAAC;AACF,eAAO,MAAM,mBAAmB,oEAK/B,CAAA;AAGD,eAAO,MAAM,yBAAyB,qEAIrC,CAAA"}
1
+ {"version":3,"file":"inputCommentStyles.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/inputCommentStyles.ts"],"names":[],"mappings":"AAQA,UAAU,OAAO;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,UAAU,YAAY;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mBAAmB,CAAC,EAAE,GAAG,CAAA;CAC5B;AACD,UAAU,QAAQ;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CAE3B;AAED,eAAO,MAAM,YAAY,yEAoBxB,CAAA;AAED,eAAO,MAAM,SAAS,0EAkBrB,CAAA;AAED,eAAO,MAAM,SAAS,oEAiBrB,CAAA;AACD,eAAO,MAAM,eAAe,oEAG3B,CAAA;AACD,eAAO,MAAM,UAAU;mBAA8B,OAAO;SAkB3D,CAAA;AAED,eAAO,MAAM,WAAW,8EAWvB,CAAC;AACF,eAAO,MAAM,mBAAmB,oEAK/B,CAAA;AAGD,eAAO,MAAM,yBAAyB,qEAIrC,CAAA"}
@@ -24,6 +24,7 @@ export declare const useInputHook: ({ limit, placeholder, onSendMentions, onCont
24
24
  textLength: number;
25
25
  isPlaceholder: boolean;
26
26
  styleLimitExceeded: boolean;
27
+ mainContainerRef: React.MutableRefObject<HTMLDivElement>;
27
28
  };
28
29
  export {};
29
30
  //# sourceMappingURL=useInputHook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInputHook.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/useInputHook.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,M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A"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "frst-components",
3
3
  "homepage": "http://FRST-Falconi.github.io/storybook.frstfalconi.com",
4
- "version": "0.22.18",
4
+ "version": "0.22.20",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",