@bikdotai/bik-component-library 0.0.564-beta.picker.5 → 0.0.564-beta.picker.6
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/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.d.ts +2 -0
- package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js +1 -1
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.d.ts +2 -0
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ export type CustomEditorProps = React.TextareaHTMLAttributes<HTMLTextAreaElement
|
|
|
12
12
|
* Calls only for editor only error, not for errors coming from outside
|
|
13
13
|
*/
|
|
14
14
|
onError?: (err: string) => void;
|
|
15
|
+
onClickVariable?: (variable: string) => void;
|
|
15
16
|
};
|
|
16
17
|
export type CustomEditorRef = {
|
|
17
18
|
addTextOrWrap: (textToAdd: string) => {
|
|
@@ -37,4 +38,5 @@ export declare const WhatsAppTextEditor: React.ForwardRefExoticComponent<React.T
|
|
|
37
38
|
* Calls only for editor only error, not for errors coming from outside
|
|
38
39
|
*/
|
|
39
40
|
onError?: ((err: string) => void) | undefined;
|
|
41
|
+
onClickVariable?: ((variable: string) => void) | undefined;
|
|
40
42
|
} & React.RefAttributes<CustomEditorRef>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),n=require("../../assets/icons/info.svg.js"),r=require("../../helpers/BaseWhatsappContentLang.helper.js"),l=require("react"),o=require("../../constants/Theme.js"),i=require("../TypographyStyle.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),n=require("../../assets/icons/info.svg.js"),r=require("../../helpers/BaseWhatsappContentLang.helper.js"),l=require("react"),o=require("../../constants/Theme.js"),i=require("../TypographyStyle.js"),s=require("./CustomEditor.styled.js"),u=require("./WhatsAppTextEditorHeader.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=c(l);const d="Character limit reached",v=new r.BaseWhatsappContentLangHelper,p={[u.EditorActionTypes.BOLD]:"*",[u.EditorActionTypes.ITALIC]:"_",[u.EditorActionTypes.STRIKETHROUGH]:"~"},h=a.default.forwardRef(((r,c)=>{var a,h,{onChange:g,onClickVariable:x,text:f,RightComponent:j,error:C,limit:m,onError:O,rows:y,actions:E}=r,T=e.__rest(r,["onChange","onClickVariable","text","RightComponent","error","limit","onError","rows","actions"]);const b=l.useRef(null);function S(e){const t=null==b?void 0:b.current;null!=t&&(t.selectionStart?(t.focus(),t.selectionEnd=e):t.focus())}function L(e){var t,n;let r=null!==(n=null===(t=b.current)||void 0===t?void 0:t.value)&&void 0!==n?n:"";if(b.current&&e){const t=b.current.selectionStart,n=b.current.selectionEnd,l=e;if(t===n)return w(l);{r=v.wrappWildcard(t,n,l,r);const e=v.getHTML(r);return b.current.value=r,{text:r,html:e}}}return{text:r,html:r}}function w(e){var t,n;let r=null!==(n=null===(t=b.current)||void 0===t?void 0:t.value)&&void 0!==n?n:"";if(b.current&&e){const t=b.current.selectionStart;if(t===b.current.selectionEnd)return R(e,t)}return{text:r,html:r}}function R(e,t){var n,r;let l=null!==(r=null===(n=b.current)||void 0===n?void 0:n.value)&&void 0!==r?r:"";l=l.slice(0,t)+e+l.slice(t);const o=v.getHTML(l);return b.current.value=l,{text:l,html:o}}l.useImperativeHandle(c,(()=>({addTextOrWrap:L,addText:w,get(){var e,t;return null!==(t=null===(e=b.current)||void 0===e?void 0:e.value)&&void 0!==t?t:""},setCaretPosition:S}))),l.useEffect((()=>{if(null==b?void 0:b.current){b.current.value=f||"";const e=v.getHTML(f||"");null==g||g(f||"",e)}}),[f]),l.useEffect((()=>{var e,t;(null===(e=null==b?void 0:b.current)||void 0===e?void 0:e.value)&&m&&((null===(t=null==b?void 0:b.current)||void 0===t?void 0:t.value.length)>m?null==O||O(d):null==O||O(null!=C?C:""))}),[null===(a=null==b?void 0:b.current)||void 0===a?void 0:a.value.length]);return t.jsxs(s.OuterContainer,{children:[t.jsxs(s.Container,Object.assign({isError:!!C},{children:[t.jsx(u.WhatsAppTextEditorHeader,{actions:E,ref:b,onActionSelect:function(e){if((null==p?void 0:p[e])&&b.current){const t=b.current.selectionStart;if(t===b.current.selectionEnd){R(null==p?void 0:p[e],t);const{text:n,html:r}=R(null==p?void 0:p[e],t);S(t+1),null==g||g(n,r)}else{const{text:t,html:n}=L(null==p?void 0:p[e]);null==g||g(t,n)}}},RightComponent:j,onEmojiClick:function(e){const{text:t,html:n}=w(e);null==g||g(t,n)}}),t.jsxs("div",Object.assign({style:{position:"relative"}},{children:[t.jsx("div",Object.assign({style:{position:"absolute",top:0,left:0,pointerEvents:"none",color:"transparent",zIndex:1,width:"100%",whiteSpace:"pre-wrap",wordWrap:"break-word",padding:"12px 16px"}},{children:(()=>{var e;const n=(null===(e=null==b?void 0:b.current)||void 0===e?void 0:e.value)||"";console.log(n);const r=/(\{\{.*?\}\})/g;return n.split(r).map(((e,n)=>r.test(e)?t.jsx("span",Object.assign({onClick:()=>null==x?void 0:x(e),style:{color:"purple"}},{children:e}),n):e))})()})),t.jsx(s.TextSpace,Object.assign({style:{zIndex:2,background:"none",caretColor:o.COLORS.content.primary},ref:b,onChange:function(e){const t=e.target.value,n=v.getHTML(t);null==g||g(t,n)}},T,{rows:y}))]}))]})),C&&C!==d?t.jsxs("div",Object.assign({style:{display:"flex",gap:6,alignItems:"center"}},{children:[t.jsx(n.default,{width:16,height:16,color:o.COLORS.content.negative}),t.jsx(i.BodyCaption,Object.assign({color:o.COLORS.content.negative},{children:C}))]})):t.jsx(t.Fragment,{children:m&&(null==b?void 0:b.current)?t.jsxs(i.BodyCaption,Object.assign({style:{color:C===d||(null===(h=null==b?void 0:b.current)||void 0===h?void 0:h.value.length)>m?o.COLORS.content.negative:o.COLORS.content.secondary}},{children:[b.current.value.length,"/",m]})):t.jsx(t.Fragment,{})})]})}));h.displayName="WhatsAppTextEditor",exports.WhatsAppTextEditor=h;
|
|
@@ -12,6 +12,7 @@ export type CustomEditorProps = React.TextareaHTMLAttributes<HTMLTextAreaElement
|
|
|
12
12
|
* Calls only for editor only error, not for errors coming from outside
|
|
13
13
|
*/
|
|
14
14
|
onError?: (err: string) => void;
|
|
15
|
+
onClickVariable?: (variable: string) => void;
|
|
15
16
|
};
|
|
16
17
|
export type CustomEditorRef = {
|
|
17
18
|
addTextOrWrap: (textToAdd: string) => {
|
|
@@ -37,4 +38,5 @@ export declare const WhatsAppTextEditor: React.ForwardRefExoticComponent<React.T
|
|
|
37
38
|
* Calls only for editor only error, not for errors coming from outside
|
|
38
39
|
*/
|
|
39
40
|
onError?: ((err: string) => void) | undefined;
|
|
41
|
+
onClickVariable?: ((variable: string) => void) | undefined;
|
|
40
42
|
} & React.RefAttributes<CustomEditorRef>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest as t}from"../../_virtual/_tslib.js";import{jsxs as n,jsx as e,Fragment as r}from"react/jsx-runtime";import l from"../../assets/icons/info.svg.js";import{BaseWhatsappContentLangHelper as o}from"../../helpers/BaseWhatsappContentLang.helper.js";import i,{useRef as
|
|
1
|
+
import{__rest as t}from"../../_virtual/_tslib.js";import{jsxs as n,jsx as e,Fragment as r}from"react/jsx-runtime";import l from"../../assets/icons/info.svg.js";import{BaseWhatsappContentLangHelper as o}from"../../helpers/BaseWhatsappContentLang.helper.js";import i,{useRef as c,useImperativeHandle as u,useEffect as s}from"react";import{COLORS as a}from"../../constants/Theme.js";import{BodyCaption as d}from"../TypographyStyle.js";import{OuterContainer as v,Container as p,TextSpace as h}from"./CustomEditor.styled.js";import{EditorActionTypes as m,WhatsAppTextEditorHeader as g}from"./WhatsAppTextEditorHeader.js";const f="Character limit reached",x=new o,j={[m.BOLD]:"*",[m.ITALIC]:"_",[m.STRIKETHROUGH]:"~"},C=i.forwardRef(((o,i)=>{var m,C,{onChange:b,onClickVariable:y,text:E,RightComponent:T,error:w,limit:O,onError:S,rows:H,actions:L}=o,k=t(o,["onChange","onClickVariable","text","RightComponent","error","limit","onError","rows","actions"]);const I=c(null);function R(t){const n=null==I?void 0:I.current;null!=n&&(n.selectionStart?(n.focus(),n.selectionEnd=t):n.focus())}function W(t){var n,e;let r=null!==(e=null===(n=I.current)||void 0===n?void 0:n.value)&&void 0!==e?e:"";if(I.current&&t){const n=I.current.selectionStart,e=I.current.selectionEnd,l=t;if(n===e)return A(l);{r=x.wrappWildcard(n,e,l,r);const t=x.getHTML(r);return I.current.value=r,{text:r,html:t}}}return{text:r,html:r}}function A(t){var n,e;let r=null!==(e=null===(n=I.current)||void 0===n?void 0:n.value)&&void 0!==e?e:"";if(I.current&&t){const n=I.current.selectionStart;if(n===I.current.selectionEnd)return M(t,n)}return{text:r,html:r}}function M(t,n){var e,r;let l=null!==(r=null===(e=I.current)||void 0===e?void 0:e.value)&&void 0!==r?r:"";l=l.slice(0,n)+t+l.slice(n);const o=x.getHTML(l);return I.current.value=l,{text:l,html:o}}u(i,(()=>({addTextOrWrap:W,addText:A,get(){var t,n;return null!==(n=null===(t=I.current)||void 0===t?void 0:t.value)&&void 0!==n?n:""},setCaretPosition:R}))),s((()=>{if(null==I?void 0:I.current){I.current.value=E||"";const t=x.getHTML(E||"");null==b||b(E||"",t)}}),[E]),s((()=>{var t,n;(null===(t=null==I?void 0:I.current)||void 0===t?void 0:t.value)&&O&&((null===(n=null==I?void 0:I.current)||void 0===n?void 0:n.value.length)>O?null==S||S(f):null==S||S(null!=w?w:""))}),[null===(m=null==I?void 0:I.current)||void 0===m?void 0:m.value.length]);return n(v,{children:[n(p,Object.assign({isError:!!w},{children:[e(g,{actions:L,ref:I,onActionSelect:function(t){if((null==j?void 0:j[t])&&I.current){const n=I.current.selectionStart;if(n===I.current.selectionEnd){M(null==j?void 0:j[t],n);const{text:e,html:r}=M(null==j?void 0:j[t],n);R(n+1),null==b||b(e,r)}else{const{text:n,html:e}=W(null==j?void 0:j[t]);null==b||b(n,e)}}},RightComponent:T,onEmojiClick:function(t){const{text:n,html:e}=A(t);null==b||b(n,e)}}),n("div",Object.assign({style:{position:"relative"}},{children:[e("div",Object.assign({style:{position:"absolute",top:0,left:0,pointerEvents:"none",color:"transparent",zIndex:1,width:"100%",whiteSpace:"pre-wrap",wordWrap:"break-word",padding:"12px 16px"}},{children:(()=>{var t;const n=(null===(t=null==I?void 0:I.current)||void 0===t?void 0:t.value)||"";console.log(n);const r=/(\{\{.*?\}\})/g;return n.split(r).map(((t,n)=>r.test(t)?e("span",Object.assign({onClick:()=>null==y?void 0:y(t),style:{color:"purple"}},{children:t}),n):t))})()})),e(h,Object.assign({style:{zIndex:2,background:"none",caretColor:a.content.primary},ref:I,onChange:function(t){const n=t.target.value,e=x.getHTML(n);null==b||b(n,e)}},k,{rows:H}))]}))]})),w&&w!==f?n("div",Object.assign({style:{display:"flex",gap:6,alignItems:"center"}},{children:[e(l,{width:16,height:16,color:a.content.negative}),e(d,Object.assign({color:a.content.negative},{children:w}))]})):e(r,{children:O&&(null==I?void 0:I.current)?n(d,Object.assign({style:{color:w===f||(null===(C=null==I?void 0:I.current)||void 0===C?void 0:C.value.length)>O?a.content.negative:a.content.secondary}},{children:[I.current.value.length,"/",O]})):e(r,{})})]})}));C.displayName="WhatsAppTextEditor";export{C as WhatsAppTextEditor};
|