frst-components 0.22.20 → 0.22.22

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
@@ -3321,7 +3321,7 @@ const InputText$4 = styled__default["default"].div `
3321
3321
  width: 100%;
3322
3322
  height: ${({ height }) => height || '20px'};
3323
3323
  outline: 0;
3324
- color: ${({ theme, isPlaceholder }) => !isPlaceholder ? theme.colors.neutralsGrey1 : theme.colors.neutralsGrey4};
3324
+ color: ${({ theme }) => theme.colors.neutralsGrey1};
3325
3325
  font-family: 'Work Sans';
3326
3326
  font-style: normal;
3327
3327
  font-weight: normal;
@@ -3333,7 +3333,26 @@ const InputText$4 = styled__default["default"].div `
3333
3333
 
3334
3334
 
3335
3335
  padding: 0;
3336
- margin: ${({ isPlaceholder }) => isPlaceholder ? '10px 4px 10px 15px' : '10px 4px 40px 15px'};
3336
+ margin: 10px 4px 40px 15px;
3337
+ border: none;
3338
+ `;
3339
+ const InputPlaceholder = styled__default["default"].div `
3340
+ width: 100%;
3341
+ height: ${({ height }) => height || '20px'};
3342
+ outline: 0;
3343
+ color: ${({ theme }) => theme.colors.neutralsGrey4};
3344
+ font-family: 'Work Sans';
3345
+ font-style: normal;
3346
+ font-weight: normal;
3347
+ font-size: 16px;
3348
+ letter-spacing: -0.02em;
3349
+ border: 1px solid ${({ theme }) => theme.colors.neutralsGrey3};
3350
+ overflow: hidden;
3351
+ background-color: inherit;
3352
+
3353
+
3354
+ padding: 0;
3355
+ margin: 10px 4px 10px 15px;
3337
3356
  border: none;
3338
3357
  `;
3339
3358
  styled__default["default"].div `
@@ -3407,7 +3426,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3407
3426
  const [showMention, setShowMention] = React.useState(false);
3408
3427
  const [inputSearch, setInputSearch] = React.useState('');
3409
3428
  const divInputRef = React.useRef(null);
3410
- const mainContainerRef = React.useRef(null);
3429
+ const divPlaceholder = React.useRef(null);
3411
3430
  const mentionTopPosition = `${(divInputRef.current?.clientHeight ?? 15) + 20}px`;
3412
3431
  const [textLength, setTextLength] = React.useState(0);
3413
3432
  const [isPlaceholder, setPlaceholder] = React.useState(false);
@@ -3566,45 +3585,40 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3566
3585
  setTextLength(count);
3567
3586
  return count;
3568
3587
  };
3569
- const clearDivContent = () => {
3570
- if (!divInputRef.current)
3571
- return;
3572
- console.log(`active element = ${document.activeElement}`);
3573
- if ((divInputRef.current.childNodes.length === 0 && !focus)) {
3574
- // create a textnode with the placeholder
3575
- divInputRef.current.innerText = placeholder;
3576
- setPlaceholder(true);
3577
- }
3578
- else if (!focus && divInputRef.current.childNodes.length >= 1) {
3579
- // loop over all child element and check if they are empty
3580
- let isEmpty = true;
3588
+ const areChildrenEmpty = () => {
3589
+ // return if divInputRef has child empty
3590
+ let isEmpty = false;
3591
+ //if divInputRef is not focused
3592
+ const isFocused = divInputRef.current === document.activeElement;
3593
+ if (divInputRef.current && !isFocused) {
3581
3594
  divInputRef.current.childNodes.forEach((child) => {
3582
- if (child.textContent !== '' && child.textContent != placeholder) {
3583
- isEmpty = false;
3584
- setPlaceholder(false);
3585
- }
3586
- else if (child.textContent === placeholder) {
3587
- divInputRef.current.blur();
3595
+ if (child.textContent.length <= 0) {
3596
+ isEmpty = true;
3588
3597
  }
3589
3598
  });
3590
- // if they are empty show the placeholder
3591
- if (isEmpty) {
3592
- // create a textnode with the placeholder
3593
- divInputRef.current.innerText = placeholder;
3594
- setPlaceholder(true);
3595
- }
3596
3599
  }
3597
- else if (divInputRef.current.innerText === placeholder) {
3598
- // create a paragraph node
3599
- divInputRef.current.innerHTML = '';
3600
- // clear complete the div
3601
- divInputRef.current.innerText = '';
3602
- const p = document.createElement('p');
3603
- const br = document.createElement('br');
3604
- p.appendChild(br);
3605
- divInputRef.current.appendChild(p);
3600
+ return isEmpty;
3601
+ };
3602
+ const handlePlaceholderInputText = (isPlaceHolderFocus = false) => {
3603
+ // if divInputRef has any element hide the placeholder
3604
+ if (isPlaceHolderFocus) {
3605
+ divPlaceholder.current?.style.setProperty('display', 'none');
3606
+ divInputRef.current.style.setProperty('display', 'block');
3607
+ divInputRef.current.focus();
3606
3608
  setPlaceholder(false);
3607
3609
  }
3610
+ else {
3611
+ if (!areChildrenEmpty()) {
3612
+ divPlaceholder.current?.style.setProperty('display', 'none');
3613
+ divInputRef.current.style.setProperty('display', 'block');
3614
+ setPlaceholder(false);
3615
+ }
3616
+ else {
3617
+ divPlaceholder.current?.style.setProperty('display', 'block');
3618
+ divInputRef.current.style.setProperty('display', 'none');
3619
+ setPlaceholder(true);
3620
+ }
3621
+ }
3608
3622
  };
3609
3623
  React.useEffect(() => {
3610
3624
  divInputRef.current?.addEventListener('input', resizeDiv);
@@ -3613,8 +3627,10 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3613
3627
  };
3614
3628
  }, []);
3615
3629
  React.useEffect(() => {
3616
- if (!replyMentionedUser || !divInputRef?.current)
3630
+ if (!replyMentionedUser || !divInputRef?.current) {
3631
+ handlePlaceholderInputText();
3617
3632
  return;
3633
+ }
3618
3634
  divInputRef.current?.focus();
3619
3635
  const selection = window.getSelection();
3620
3636
  if (selection && selection.rangeCount > 0) {
@@ -3625,44 +3641,41 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3625
3641
  const spaceNode = document.createTextNode('\u00A0'); // Unicode for non-breaking space
3626
3642
  addMentionToRangeAndSpaceNode(range, spaceNode, mentionedUser);
3627
3643
  createNewRangeAndMoveCursorToTheEnd(selection, spaceNode);
3644
+ handlePlaceholderInputText();
3628
3645
  }
3629
3646
  }, [replyMentionedUser]);
3630
- React.useEffect(() => {
3631
- setPlaceholder(false);
3632
- if ((!value || value.length <= 0) && !focus && !replyMentionedUser) {
3633
- divInputRef.current.innerText = placeholder;
3634
- setPlaceholder(true);
3635
- resizeDiv();
3636
- }
3637
- }, [value]);
3638
- React.useEffect(() => {
3639
- if (!divInputRef.current)
3640
- return;
3641
- clearDivContent();
3642
- }, [focus]);
3643
3647
  React.useEffect(() => {
3644
3648
  setStyleLimitExceeded(textLength > limit);
3645
3649
  }, [textLength]);
3646
3650
  React.useEffect(() => {
3647
- if (!divInputRef.current || !mainContainerRef.current)
3651
+ if (!divInputRef.current || !divPlaceholder.current)
3648
3652
  return;
3649
- divInputRef.current.addEventListener('mousedown', () => {
3650
- setFocus(true);
3653
+ document.addEventListener('mousedown', () => {
3654
+ handlePlaceholderInputText();
3651
3655
  });
3652
- divInputRef.current.addEventListener('focus', () => {
3653
- setFocus(true);
3656
+ document.addEventListener('focus', () => {
3657
+ handlePlaceholderInputText();
3654
3658
  });
3655
- divInputRef.current.addEventListener('blur', () => {
3656
- setFocus(false);
3659
+ document.addEventListener('blur', () => {
3660
+ handlePlaceholderInputText();
3661
+ });
3662
+ divPlaceholder.current.addEventListener('mousedown', () => {
3663
+ handlePlaceholderInputText(true);
3657
3664
  });
3658
- mainContainerRef.current.addEventListener('mousedown', () => {
3659
- setFocus(true);
3665
+ divPlaceholder.current.addEventListener('focus', () => {
3666
+ handlePlaceholderInputText(true);
3660
3667
  });
3661
- mainContainerRef.current.addEventListener('focus', () => {
3662
- setFocus(true);
3668
+ divPlaceholder.current.addEventListener('blur', () => {
3669
+ handlePlaceholderInputText(true);
3663
3670
  });
3664
- mainContainerRef.current.addEventListener('blur', () => {
3665
- setFocus(false);
3671
+ divInputRef.current.addEventListener('mousedown', () => {
3672
+ handlePlaceholderInputText();
3673
+ });
3674
+ divInputRef.current.addEventListener('focus', () => {
3675
+ handlePlaceholderInputText();
3676
+ });
3677
+ divInputRef.current.addEventListener('blur', () => {
3678
+ handlePlaceholderInputText();
3666
3679
  });
3667
3680
  //capture the cursor position on arrow up and down or left and right and check if it´s close to the @ key
3668
3681
  divInputRef.current.addEventListener('keyup', (event) => {
@@ -3671,23 +3684,32 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3671
3684
  }
3672
3685
  });
3673
3686
  return () => {
3674
- divInputRef.current?.removeEventListener('mousedown', () => {
3675
- setFocus(true);
3687
+ document.removeEventListener('mousedown', () => {
3688
+ handlePlaceholderInputText();
3689
+ });
3690
+ document.removeEventListener('focus', () => {
3691
+ handlePlaceholderInputText();
3692
+ });
3693
+ document.removeEventListener('blur', () => {
3694
+ handlePlaceholderInputText();
3676
3695
  });
3677
- divInputRef.current?.removeEventListener('focus', () => {
3678
- setFocus(true);
3696
+ divPlaceholder.current.removeEventListener('mousedown', () => {
3697
+ handlePlaceholderInputText(true);
3679
3698
  });
3680
- divInputRef.current?.removeEventListener('blur', () => {
3681
- setFocus(false);
3699
+ divPlaceholder.current.removeEventListener('focus', () => {
3700
+ handlePlaceholderInputText(true);
3682
3701
  });
3683
- mainContainerRef.current?.removeEventListener('mousedown', () => {
3684
- setFocus(true);
3702
+ divPlaceholder.current.removeEventListener('blur', () => {
3703
+ handlePlaceholderInputText(true);
3685
3704
  });
3686
- mainContainerRef.current?.removeEventListener('focus', () => {
3687
- setFocus(true);
3705
+ divInputRef.current.removeEventListener('mousedown', () => {
3706
+ handlePlaceholderInputText();
3688
3707
  });
3689
- mainContainerRef.current?.removeEventListener('blur', () => {
3690
- setFocus(false);
3708
+ divInputRef.current.removeEventListener('focus', () => {
3709
+ handlePlaceholderInputText();
3710
+ });
3711
+ divInputRef.current.removeEventListener('blur', () => {
3712
+ handlePlaceholderInputText();
3691
3713
  });
3692
3714
  //capture the cursor position on arrow up and down or left and right and check if it´s close to the @ key
3693
3715
  divInputRef.current.removeEventListener('keyup', (event) => {
@@ -3697,9 +3719,20 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3697
3719
  });
3698
3720
  };
3699
3721
  }, []);
3722
+ React.useEffect(() => {
3723
+ if (replyMentionedUser)
3724
+ return;
3725
+ if (!value || value.length <= 0 && document.activeElement !== divInputRef.current) {
3726
+ divPlaceholder.current?.style.setProperty('display', 'block');
3727
+ divInputRef.current.style.setProperty('display', 'none');
3728
+ divInputRef.current.innerHTML = '<p><br /></p>';
3729
+ setPlaceholder(true);
3730
+ countChars();
3731
+ }
3732
+ }, [value]);
3700
3733
  return {
3701
3734
  handleInput,
3702
- clearDivContent,
3735
+ handlePlaceholderInputText,
3703
3736
  focus,
3704
3737
  showMention,
3705
3738
  setShowMention,
@@ -3711,7 +3744,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3711
3744
  textLength,
3712
3745
  isPlaceholder,
3713
3746
  styleLimitExceeded,
3714
- mainContainerRef
3747
+ divPlaceholder
3715
3748
  };
3716
3749
  };
3717
3750
 
@@ -3891,10 +3924,10 @@ const Mentions = (mention) => {
3891
3924
  };
3892
3925
 
3893
3926
  function InputComment$1({ placeholder, onChange, limit, users, showCharacterCounter, styles, onSendMentions, onContentFormat, onContentUnformat, disabled, className, value, replyMentionedUser, group_uuid, limitMessageExceeded }) {
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) => {
3927
+ const { divPlaceholder, handleInput, isPlaceholder, divInputRef, handleMentionUser, mentionTopPosition, setShowMention, showMention, textLength, styleLimitExceeded } = useInputHook({ limit, placeholder, onContentFormat, onContentUnformat, onSendMentions, onChange, value, replyMentionedUser });
3928
+ return (jsxRuntime.jsx(styled.ThemeProvider, { theme: FRSTTheme, children: jsxRuntime.jsxs("div", { style: { minHeight: '48px', ...styles }, tabIndex: 0, children: [jsxRuntime.jsxs(InputWrapper$2, { tabIndex: 1, isPlaceholder: isPlaceholder, isInputLimit: styleLimitExceeded, children: [jsxRuntime.jsx(InputText$4, { tabIndex: 2, contentEditable: true, ref: divInputRef, onKeyUpCapture: (event) => {
3896
3929
  handleInput(event);
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) => {
3930
+ }, "data-text": "enter", suppressContentEditableWarning: true, children: jsxRuntime.jsx("p", { children: jsxRuntime.jsx("br", {}) }) }), jsxRuntime.jsx(InputPlaceholder, { style: { display: 'none' }, contentEditable: true, ref: divPlaceholder, children: placeholder }), showMention && users && users.length > 0 && jsxRuntime.jsx(Mentions, { users: users, top: mentionTopPosition, onSelect: (user) => {
3898
3931
  setShowMention(false);
3899
3932
  handleMentionUser(user);
3900
3933
  } })] }), jsxRuntime.jsx(HelperContainer, { children: !isPlaceholder ?
@@ -10,10 +10,10 @@ interface IEmojiWindow {
10
10
  }
11
11
  interface TextArea {
12
12
  height?: string;
13
- isPlaceholder?: boolean;
14
13
  }
15
14
  export declare const InputWrapper: import("styled-components").StyledComponent<"div", any, Wrapper, never>;
16
15
  export declare const InputText: import("styled-components").StyledComponent<"div", any, TextArea, never>;
16
+ export declare const InputPlaceholder: import("styled-components").StyledComponent<"div", any, TextArea, never>;
17
17
  export declare const SmileIcon: import("styled-components").StyledComponent<"div", any, {}, never>;
18
18
  export declare const HelperContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
19
19
  export declare const HelperText: import("styled-components").StyledComponent<"span", any, {
@@ -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,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"}
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;CAElB;AAED,eAAO,MAAM,YAAY,yEAoBxB,CAAA;AAED,eAAO,MAAM,SAAS,0EAkBrB,CAAA;AACD,eAAO,MAAM,gBAAgB,0EAkB5B,CAAA;AACD,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"}
@@ -12,7 +12,7 @@ interface IInputHook {
12
12
  }
13
13
  export declare const useInputHook: ({ limit, placeholder, onSendMentions, onContentFormat, onContentUnformat, onChange, value, replyMentionedUser }: IInputHook) => {
14
14
  handleInput: (event: React.KeyboardEvent) => void;
15
- clearDivContent: () => void;
15
+ handlePlaceholderInputText: (isPlaceHolderFocus?: boolean) => void;
16
16
  focus: boolean;
17
17
  showMention: boolean;
18
18
  setShowMention: React.Dispatch<React.SetStateAction<boolean>>;
@@ -24,7 +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
+ divPlaceholder: React.MutableRefObject<HTMLDivElement>;
28
28
  };
29
29
  export {};
30
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,MAAM,SAAS,CAAC;AAE/B,UAAU,UAAU;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC5C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAC5B;AAED,eAAO,MAAM,YAAY,oHAAqH,UAAU;yBA4HxH,mBAAmB;;;;;;;;;8BA/Ed,IAAI;;;;;CAoTxC,CAAA"}
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,MAAM,SAAS,CAAC;AAE/B,UAAU,UAAU;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC5C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAC5B;AAED,eAAO,MAAM,YAAY,oHAAqH,UAAU;yBA4HxH,mBAAmB;sDA+EQ,OAAO;;;;;;;;8BA9J7B,IAAI;;;;;CA4UxC,CAAA"}
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.20",
4
+ "version": "0.22.22",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",