@bikdotai/bik-component-library 0.0.564-beta.picker.8 → 0.0.564-beta.picker.9
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/cjs/components/bik-layout/MockMenus.d.ts +1 -0
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.d.ts +2 -0
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js +1 -1
- package/dist/esm/components/bik-layout/MockMenus.d.ts +1 -0
- 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"),
|
|
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"),o=require("react"),l=require("../../constants/Theme.js"),i=require("../TypographyStyle.js"),s=require("./CustomEditor.styled.js"),c=require("./WhatsAppTextEditorHeader.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=u(o);const d="Character limit reached",v=new r.BaseWhatsappContentLangHelper,p={[c.EditorActionTypes.BOLD]:"*",[c.EditorActionTypes.ITALIC]:"_",[c.EditorActionTypes.STRIKETHROUGH]:"~"},g=a.default.forwardRef(((r,u)=>{var a,g,{onChange:h,onClickVariable:f,text:x,RightComponent:j,error:m,limit:C,onError:E,rows:O,actions:T}=r,y=e.__rest(r,["onChange","onClickVariable","text","RightComponent","error","limit","onError","rows","actions"]);const b=o.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,o=e;if(t===n)return w(o);{r=v.wrappWildcard(t,n,o,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 o=null!==(r=null===(n=b.current)||void 0===n?void 0:n.value)&&void 0!==r?r:"";o=o.slice(0,t)+e+o.slice(t);const l=v.getHTML(o);return b.current.value=o,{text:o,html:l}}o.useImperativeHandle(u,(()=>({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}))),o.useEffect((()=>{if(null==b?void 0:b.current){b.current.value=x||"";const e=v.getHTML(x||"");null==h||h(x||"",e)}}),[x]),o.useEffect((()=>{var e,t;(null===(e=null==b?void 0:b.current)||void 0===e?void 0:e.value)&&C&&((null===(t=null==b?void 0:b.current)||void 0===t?void 0:t.value.length)>C?null==E||E(d):null==E||E(null!=m?m:""))}),[null===(a=null==b?void 0:b.current)||void 0===a?void 0:a.value.length]);const H=o.useRef(null);console.log("textSpaceRef",b);const q=()=>{H.current&&b.current&&(H.current.scrollTop=b.current.scrollTop,H.current.scrollLeft=b.current.scrollLeft)};return t.jsxs(s.OuterContainer,{children:[t.jsxs(s.Container,Object.assign({isError:!!m},{children:[t.jsx(c.WhatsAppTextEditorHeader,{actions:T,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==h||h(n,r)}else{const{text:t,html:n}=L(null==p?void 0:p[e]);null==h||h(t,n)}}},RightComponent:j,onEmojiClick:function(e){const{text:t,html:n}=w(e);null==h||h(t,n)}}),t.jsxs("div",Object.assign({style:{position:"relative",background:""}},{children:[t.jsx("div",Object.assign({contentEditable:!1,ref:H,style:{position:"absolute",top:0,left:0,pointerEvents:"none",color:"transparent",zIndex:1,width:"100%",whiteSpace:"pre-wrap",wordWrap:"break-word",padding:"12px 16px",maxHeight:"100%",overflow:"auto",height:"48px"}},{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,o=n.split(r);return console.log(o),o.map(((e,n)=>r.test(e)?t.jsx("span",Object.assign({onClick:()=>{console.log(e),null==f||f(e)},onMouseEnter:()=>{console.log("hover",e)},style:{color:"purple",cursor:"pointer",pointerEvents:"auto"}},{children:e}),n):e))})()})),t.jsx(s.TextSpace,Object.assign({style:{zIndex:2,background:"none"},ref:b,onChange:function(e){const t=e.target.value,n=v.getHTML(t);null==h||h(t,n),q()}},y,{rows:O,onScroll:q}))]}))]})),m&&m!==d?t.jsxs("div",Object.assign({style:{display:"flex",gap:6,alignItems:"center"}},{children:[t.jsx(n.default,{width:16,height:16,color:l.COLORS.content.negative}),t.jsx(i.BodyCaption,Object.assign({color:l.COLORS.content.negative},{children:m}))]})):t.jsx(t.Fragment,{children:C&&(null==b?void 0:b.current)?t.jsxs(i.BodyCaption,Object.assign({style:{color:m===d||(null===(g=null==b?void 0:b.current)||void 0===g?void 0:g.value.length)>C?l.COLORS.content.negative:l.COLORS.content.secondary}},{children:[b.current.value.length,"/",C]})):t.jsx(t.Fragment,{})})]})}));g.displayName="WhatsAppTextEditor",exports.WhatsAppTextEditor=g;
|
|
@@ -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
|
|
1
|
+
import{__rest as t}from"../../_virtual/_tslib.js";import{jsxs as e,jsx as n,Fragment as r}from"react/jsx-runtime";import o from"../../assets/icons/info.svg.js";import{BaseWhatsappContentLangHelper as l}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 g}from"./CustomEditor.styled.js";import{EditorActionTypes as h,WhatsAppTextEditorHeader as m}from"./WhatsAppTextEditorHeader.js";const f="Character limit reached",x=new l,j={[h.BOLD]:"*",[h.ITALIC]:"_",[h.STRIKETHROUGH]:"~"},b=i.forwardRef(((l,i)=>{var h,b,{onChange:E,onClickVariable:C,text:T,RightComponent:w,error:y,limit:O,onError:S,rows:L,actions:H}=l,k=t(l,["onChange","onClickVariable","text","RightComponent","error","limit","onError","rows","actions"]);const R=c(null);function I(t){const e=null==R?void 0:R.current;null!=e&&(e.selectionStart?(e.focus(),e.selectionEnd=t):e.focus())}function W(t){var e,n;let r=null!==(n=null===(e=R.current)||void 0===e?void 0:e.value)&&void 0!==n?n:"";if(R.current&&t){const e=R.current.selectionStart,n=R.current.selectionEnd,o=t;if(e===n)return M(o);{r=x.wrappWildcard(e,n,o,r);const t=x.getHTML(r);return R.current.value=r,{text:r,html:t}}}return{text:r,html:r}}function M(t){var e,n;let r=null!==(n=null===(e=R.current)||void 0===e?void 0:e.value)&&void 0!==n?n:"";if(R.current&&t){const e=R.current.selectionStart;if(e===R.current.selectionEnd)return A(t,e)}return{text:r,html:r}}function A(t,e){var n,r;let o=null!==(r=null===(n=R.current)||void 0===n?void 0:n.value)&&void 0!==r?r:"";o=o.slice(0,e)+t+o.slice(e);const l=x.getHTML(o);return R.current.value=o,{text:o,html:l}}u(i,(()=>({addTextOrWrap:W,addText:M,get(){var t,e;return null!==(e=null===(t=R.current)||void 0===t?void 0:t.value)&&void 0!==e?e:""},setCaretPosition:I}))),s((()=>{if(null==R?void 0:R.current){R.current.value=T||"";const t=x.getHTML(T||"");null==E||E(T||"",t)}}),[T]),s((()=>{var t,e;(null===(t=null==R?void 0:R.current)||void 0===t?void 0:t.value)&&O&&((null===(e=null==R?void 0:R.current)||void 0===e?void 0:e.value.length)>O?null==S||S(f):null==S||S(null!=y?y:""))}),[null===(h=null==R?void 0:R.current)||void 0===h?void 0:h.value.length]);const _=c(null);console.log("textSpaceRef",R);const z=()=>{_.current&&R.current&&(_.current.scrollTop=R.current.scrollTop,_.current.scrollLeft=R.current.scrollLeft)};return e(v,{children:[e(p,Object.assign({isError:!!y},{children:[n(m,{actions:H,ref:R,onActionSelect:function(t){if((null==j?void 0:j[t])&&R.current){const e=R.current.selectionStart;if(e===R.current.selectionEnd){A(null==j?void 0:j[t],e);const{text:n,html:r}=A(null==j?void 0:j[t],e);I(e+1),null==E||E(n,r)}else{const{text:e,html:n}=W(null==j?void 0:j[t]);null==E||E(e,n)}}},RightComponent:w,onEmojiClick:function(t){const{text:e,html:n}=M(t);null==E||E(e,n)}}),e("div",Object.assign({style:{position:"relative",background:""}},{children:[n("div",Object.assign({contentEditable:!1,ref:_,style:{position:"absolute",top:0,left:0,pointerEvents:"none",color:"transparent",zIndex:1,width:"100%",whiteSpace:"pre-wrap",wordWrap:"break-word",padding:"12px 16px",maxHeight:"100%",overflow:"auto",height:"48px"}},{children:(()=>{var t;const e=(null===(t=null==R?void 0:R.current)||void 0===t?void 0:t.value)||"";console.log(e);const r=/(\{\{.*?\}\})/g,o=e.split(r);return console.log(o),o.map(((t,e)=>r.test(t)?n("span",Object.assign({onClick:()=>{console.log(t),null==C||C(t)},onMouseEnter:()=>{console.log("hover",t)},style:{color:"purple",cursor:"pointer",pointerEvents:"auto"}},{children:t}),e):t))})()})),n(g,Object.assign({style:{zIndex:2,background:"none"},ref:R,onChange:function(t){const e=t.target.value,n=x.getHTML(e);null==E||E(e,n),z()}},k,{rows:L,onScroll:z}))]}))]})),y&&y!==f?e("div",Object.assign({style:{display:"flex",gap:6,alignItems:"center"}},{children:[n(o,{width:16,height:16,color:a.content.negative}),n(d,Object.assign({color:a.content.negative},{children:y}))]})):n(r,{children:O&&(null==R?void 0:R.current)?e(d,Object.assign({style:{color:y===f||(null===(b=null==R?void 0:R.current)||void 0===b?void 0:b.value.length)>O?a.content.negative:a.content.secondary}},{children:[R.current.value.length,"/",O]})):n(r,{})})]})}));b.displayName="WhatsAppTextEditor";export{b as WhatsAppTextEditor};
|