@bikdotai/bik-component-library 0.0.564-beta.picker.1 → 0.0.564-beta.picker.10
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/cjs/components/variable-picker-v3/Content.js +1 -1
- package/dist/cjs/components/variable-picker-v3/model.d.ts +2 -1
- 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/dist/esm/components/variable-picker-v3/Content.js +1 -1
- package/dist/esm/components/variable-picker-v3/model.d.ts +2 -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"),u=require("./CustomEditor.styled.js"),s=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,h={[s.EditorActionTypes.BOLD]:"*",[s.EditorActionTypes.ITALIC]:"_",[s.EditorActionTypes.STRIKETHROUGH]:"~"},p=a.default.forwardRef(((r,c)=>{var a,p,{onChange:f,
|
|
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"),u=require("./CustomEditor.styled.js"),s=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,h={[s.EditorActionTypes.BOLD]:"*",[s.EditorActionTypes.ITALIC]:"_",[s.EditorActionTypes.STRIKETHROUGH]:"~"},p=a.default.forwardRef(((r,c)=>{var a,p,{onChange:f,onClickVariable:g,text:x,RightComponent:j,error:C,limit:m,onError:E,rows:T,actions:O}=r,y=e.__rest(r,["onChange","onClickVariable","text","RightComponent","error","limit","onError","rows","actions"]);const L=l.useRef(null);function S(e){const t=null==L?void 0:L.current;null!=t&&(t.selectionStart?(t.focus(),t.selectionEnd=e):t.focus())}function b(e){var t,n;let r=null!==(n=null===(t=L.current)||void 0===t?void 0:t.value)&&void 0!==n?n:"";if(L.current&&e){const t=L.current.selectionStart,n=L.current.selectionEnd,l=e;if(t===n)return R(l);{r=v.wrappWildcard(t,n,l,r);const e=v.getHTML(r);return L.current.value=r,{text:r,html:e}}}return{text:r,html:r}}function R(e){var t,n;let r=null!==(n=null===(t=L.current)||void 0===t?void 0:t.value)&&void 0!==n?n:"";if(L.current&&e){const t=L.current.selectionStart;if(t===L.current.selectionEnd)return H(e,t)}return{text:r,html:r}}function H(e,t){var n,r;let l=null!==(r=null===(n=L.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 L.current.value=l,{text:l,html:o}}return l.useImperativeHandle(c,(()=>({addTextOrWrap:b,addText:R,get(){var e,t;return null!==(t=null===(e=L.current)||void 0===e?void 0:e.value)&&void 0!==t?t:""},setCaretPosition:S}))),l.useEffect((()=>{if(null==L?void 0:L.current){L.current.value=x||"";const e=v.getHTML(x||"");null==f||f(x||"",e)}}),[x]),l.useEffect((()=>{var e,t;(null===(e=null==L?void 0:L.current)||void 0===e?void 0:e.value)&&m&&((null===(t=null==L?void 0:L.current)||void 0===t?void 0:t.value.length)>m?null==E||E(d):null==E||E(null!=C?C:""))}),[null===(a=null==L?void 0:L.current)||void 0===a?void 0:a.value.length]),t.jsxs(u.OuterContainer,{children:[t.jsxs(u.Container,Object.assign({isError:!!C},{children:[t.jsx(s.WhatsAppTextEditorHeader,{actions:O,ref:L,onActionSelect:function(e){if((null==h?void 0:h[e])&&L.current){const t=L.current.selectionStart;if(t===L.current.selectionEnd){H(null==h?void 0:h[e],t);const{text:n,html:r}=H(null==h?void 0:h[e],t);S(t+1),null==f||f(n,r)}else{const{text:t,html:n}=b(null==h?void 0:h[e]);null==f||f(t,n)}}},RightComponent:j,onEmojiClick:function(e){const{text:t,html:n}=R(e);null==f||f(t,n)}}),t.jsx(u.TextSpace,Object.assign({style:{zIndex:2,background:"none"},ref:L,onChange:function(e){const t=e.target.value,n=v.getHTML(t);null==f||f(t,n)}},y,{rows:T}))]})),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==L?void 0:L.current)?t.jsxs(i.BodyCaption,Object.assign({style:{color:C===d||(null===(p=null==L?void 0:L.current)||void 0===p?void 0:p.value.length)>m?o.COLORS.content.negative:o.COLORS.content.secondary}},{children:[L.current.value.length,"/",m]})):t.jsx(t.Fragment,{})})]})}));p.displayName="WhatsAppTextEditor",exports.WhatsAppTextEditor=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_back.svg.js"),a=require("../../assets/icons/cross.svg.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_back.svg.js"),a=require("../../assets/icons/cross.svg.js"),i=require("../../assets/icons/plus.svg.js"),l=require("../../assets/icons/triangle_error.svg.js"),r=require("react"),n=require("../../constants/Theme.js"),o=require("../accordion/Accordion.js"),c=require("../icon-button/IconButton.js"),d=require("../input/Input.js"),u=require("../list-item/ListItem.js"),h=require("../switch/Switch.js"),b=require("../tooltips/Tooltip.js"),p=require("../TypographyStyle.js"),j=require("./context.js"),g=require("./DefaultVariableContent.js"),x=require("./model.js"),y=require("./NoResult.js"),m=require("./recommendVaribles.js"),f=require("./searchVariables.js"),v=require("./styles.js"),O=require("./SubHeaderItems.js");const S=(e,t)=>{if(0===t.length)return e;const a=e.toLowerCase().indexOf(t.toLowerCase());if(-1===a)return e;const i=e.slice(0,a),l=e.slice(a,a+t.length),r=e.slice(a+t.length);return s.jsxs("span",{children:[i,s.jsx("b",Object.assign({style:{color:n.COLORS.content.primary}},{children:l})),r]})},C=/.*\..*/;exports.VariablePickerContent=V=>{const{data:w,onSelect:R,showHeader:k,showBackButton:q,hideHeaderCross:T,onBackButtonClick:B,isEvaluationList:I,autoOpenFirst:L,headerText:N,contentHeight:_}=V,[D,E]=r.useState(w),[H,P]=r.useState(""),[$,F]=r.useState([]),[A,M]=r.useState(""),[W,z]=r.useState(!1),[K,G]=r.useState([]),[J,Q]=r.useState(!1),[U,X]=r.useState(),Y=J&&V.type===x.PickerType.EMBEDDED&&!T;console.log("variables",D),r.useEffect((()=>{Z(!0)}),[]),r.useEffect((()=>{$.length>0?G([$[$.length-1]]):G(w)}),[$]);const Z=s=>e.__awaiter(void 0,void 0,void 0,(function*(){if(z(s),s){const e=m.showOnlyRecommendedVariables(D,$);E(e)}else if($.length>0){const e=A==$[$.length-1].displayName;if(H.length>0&&e){const e=f.searchVariables(H,K,$);E(e)}else E([$[$.length-1].variables])}else if(H.length>0){const e=f.searchVariables(H,K,$);E(e)}else E(w)})),ee=()=>{if(_)return _;let e=131;return $.length>0&&(e+=32),(V.showHeader||V.showBackButton)&&(e+=40),`calc(100% - ${e}px)`},se=e=>{if(!V.disabled)if(I){const s=(e=>{if(e.actualValue.match(C)){const s=e.actualValue.replace("{{","").replace("}}","").split(".");let t=s[0];return s.forEach(((e,s)=>{if(0===s)return;const a=(e=>/\w+\[\d+\]/g.test(e))(e);if(a){const s=e.match(/(\w+)\[(\d+)\]/);if(s){const e=s[1],a=s[2];t+=`['${e}'][${a}]`}}else t+=`['${e}']`})),t}return e.actualValueEval?e.actualValueEval:e.actualValue})(e);R(Object.assign(Object.assign({},e),{actualValue:s}))}else{if(e.isDefaultValueSupported)return X(e),void Q(!0);R(e)}};return s.jsx(j.VariablePickerContext.Provider,Object.assign({value:{variables:D,searchText:H,subHeaderStack:$,showRecommended:W,setSubHeaderStack:F,setSearchText:P,setVariables:E,setShowRecommended:z}},{children:s.jsxs("div",Object.assign({tabIndex:-1,id:"variable-picker-v3",style:{backgroundColor:"white",borderRadius:4,height:"100%",outline:"none"},onClick:e=>e.stopPropagation()},{children:[(k||q||J)&&s.jsxs(v.HeaderWrapper,Object.assign({openDefault:J},{children:[s.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",gap:8}},{children:[(q||J)&&s.jsx(c.IconButton,{Icon:()=>s.jsx(t.default,{width:16,height:16,style:{display:"flex",color:n.COLORS.content.primary}}),onClick:()=>{J?J&&Q(!1):B&&B()}}),(k||J)&&s.jsx(p.TitleRegular,{children:J?"Set up":null!=N?N:"Select Variable"})]})),Y&&s.jsx(c.IconButton,{style:{color:"#212121"},Icon:a.default,onClick:()=>V.onClose&&V.onClose()})]})),J&&U?s.jsx(g.DefaultVariableContent,{variable:U,onInsertVariable:e=>{R(e),console.log("uploa",e)}}):s.jsxs(s.Fragment,{children:[s.jsx("div",Object.assign({style:{padding:"0 16px",paddingTop:12,backgroundColor:n.COLORS.surface.subdued,borderTopLeftRadius:4,borderTopRightRadius:4}},{children:s.jsx(d.Input,{id:"search-bar-v3-picker",onBlur:e=>{V.onSearchBlur&&V.onSearchBlur(e)},value:H,noKeyDownChange:!0,placeholder:"Search",onChangeText:e=>{e||M("");const s=f.searchVariables(e,K,$);if(W){const e=m.showOnlyRecommendedVariables(s,$);E(e)}else E(s);P(e);const t=$.length>0?$[$.length-1].displayName:"home";M(t)}})})),s.jsxs(v.RecommendWrapper,{children:[s.jsx(p.BodySecondary,Object.assign({style:{color:n.COLORS.content.secondary}},{children:"Only Recommended"})),s.jsx(h.Switch,{value:W,onValueChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield Z(s)}))})]}),$.length>0&&s.jsxs(v.BackHeader,{children:[s.jsx("div",Object.assign({style:{position:"absolute",left:16}},{children:s.jsx(c.IconButton,{id:"back-btn-v3",style:{display:"flex"},Icon:()=>s.jsx(t.default,{width:12,height:12,style:{color:n.COLORS.content.secondary}}),onClick:e=>{e.stopPropagation();let s=H;const t=[...$],a=t.pop();if(F(t),a.displayName===A&&(P(""),s=""),s.length>0){const e=t.length>0?[t[t.length-1]]:w,a=f.searchVariables(s,e,t);if(W){const e=m.showOnlyRecommendedVariables(a,t);E(e)}else E(a)}else if(t.length>0)if(W){const e=m.showOnlyRecommendedVariables([t[t.length-1].variables],t);E(e)}else E([t[t.length-1].variables]);else if(W){const e=m.showOnlyRecommendedVariables(w,$);E(e)}else E(w)}})})),s.jsx(p.BodyCaption,Object.assign({style:{color:n.COLORS.content.secondary}},{children:$[$.length-1].displayName}))]}),s.jsx(s.Fragment,{children:D.length>0?s.jsx(v.Container,Object.assign({height:ee()},{children:D.map(((e,t)=>{var a,r;return e.displayName&&void 0!==e.variables?s.jsx("div",Object.assign({style:{borderBottom:`1px solid ${n.COLORS.stroke.primary}`}},{children:s.jsx(o.BikAccordion,Object.assign({autoOpen:L&&0===t,headerPadding:"12px 16px",header:s.jsx(p.TitleSmall,Object.assign({style:{color:n.COLORS.content.secondary}},{children:S(e.displayName,H)}))},{children:s.jsx(O.default,{parentVariable:e,disabled:null!==(a=V.disabled)&&void 0!==a&&a,searchText:H,variable:e.variables,onSelect:e=>{if(e.isDefaultValueSupported)return X(e),void Q(!0);R(e)}})}))}),e.displayName+W):e.displayName?s.jsx(b.Tooltip,Object.assign({body:O.renderTooltipBody(e),placement:"bottom"},{children:s.jsx(u.ListItem,{variant:V.disabled?"readonly":(null==e?void 0:e.selected)?"selected":"default",version:"2.0",leadingIcon:(null==e?void 0:e.selected)||V.disabled?s.jsx(s.Fragment,{}):s.jsx(i.default,{width:14,height:14}),customListItemLabel:s.jsxs("div",Object.assign({style:{display:"flex",gap:4}},{children:[s.jsx(p.BodySecondary,Object.assign({style:{fontSize:"14px",color:n.COLORS.text.primary}},{children:S(e.displayName,H)})),!e.isAvailable&&s.jsx(b.Tooltip,Object.assign({body:"Not Recommended"},{children:s.jsx("div",Object.assign({style:{display:"flex",marginTop:2}},{children:s.jsx(l.default,{width:16,height:16,color:n.COLORS.content.secondary})}))}))]})),listItem:{label:e.displayName,value:e.displayName},subText:e.description||"",onClick:()=>se(e)},t)}),t):s.jsx(O.default,{disabled:null!==(r=V.disabled)&&void 0!==r&&r,searchText:H,variable:e,onSelect:e=>se(e)},t)}))})):s.jsx(y.default,{height:ee(),searchText:H})})]})]}))}))},exports.highlightSearchText=S;
|
|
@@ -17,6 +17,7 @@ export interface VariablePickerV3Props {
|
|
|
17
17
|
disabled?: boolean;
|
|
18
18
|
autoOpenFirst?: boolean;
|
|
19
19
|
headerText?: string;
|
|
20
|
+
contentHeight?: string;
|
|
20
21
|
}
|
|
21
22
|
export interface VariableListInterfaceV3 {
|
|
22
23
|
isSubHeader?: boolean;
|
|
@@ -54,6 +55,6 @@ export interface VariableV3 {
|
|
|
54
55
|
[key: string]: VariableV3;
|
|
55
56
|
};
|
|
56
57
|
needsFetching?: boolean;
|
|
57
|
-
|
|
58
|
+
isDefaultValueSupported?: boolean;
|
|
58
59
|
enableDefaultValueForGlobalUsage?: boolean;
|
|
59
60
|
}
|
|
@@ -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 m,TextSpace as h}from"./CustomEditor.styled.js";import{EditorActionTypes as f,WhatsAppTextEditorHeader as g}from"./WhatsAppTextEditorHeader.js";const p="Character limit reached",x=new o,j={[f.BOLD]:"*",[f.ITALIC]:"_",[f.STRIKETHROUGH]:"~"},C=i.forwardRef(((o,i)=>{var f,C,{onChange:T,onClickVariable:E,text:y,RightComponent:b,error:O,limit:w,onError:H,rows:L,actions:S}=o,R=t(o,["onChange","onClickVariable","text","RightComponent","error","limit","onError","rows","actions"]);const I=c(null);function W(t){const n=null==I?void 0:I.current;null!=n&&(n.selectionStart?(n.focus(),n.selectionEnd=t):n.focus())}function k(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}}return u(i,(()=>({addTextOrWrap:k,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:W}))),s((()=>{if(null==I?void 0:I.current){I.current.value=y||"";const t=x.getHTML(y||"");null==T||T(y||"",t)}}),[y]),s((()=>{var t,n;(null===(t=null==I?void 0:I.current)||void 0===t?void 0:t.value)&&w&&((null===(n=null==I?void 0:I.current)||void 0===n?void 0:n.value.length)>w?null==H||H(p):null==H||H(null!=O?O:""))}),[null===(f=null==I?void 0:I.current)||void 0===f?void 0:f.value.length]),n(v,{children:[n(m,Object.assign({isError:!!O},{children:[e(g,{actions:S,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);W(n+1),null==T||T(e,r)}else{const{text:n,html:e}=k(null==j?void 0:j[t]);null==T||T(n,e)}}},RightComponent:b,onEmojiClick:function(t){const{text:n,html:e}=A(t);null==T||T(n,e)}}),e(h,Object.assign({style:{zIndex:2,background:"none"},ref:I,onChange:function(t){const n=t.target.value,e=x.getHTML(n);null==T||T(n,e)}},R,{rows:L}))]})),O&&O!==p?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:O}))]})):e(r,{children:w&&(null==I?void 0:I.current)?n(d,Object.assign({style:{color:O===p||(null===(C=null==I?void 0:I.current)||void 0===C?void 0:C.value.length)>w?a.content.negative:a.content.secondary}},{children:[I.current.value.length,"/",w]})):e(r,{})})]})}));C.displayName="WhatsAppTextEditor";export{C as WhatsAppTextEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../_virtual/_tslib.js";import{jsx as t,jsxs as
|
|
1
|
+
import{__awaiter as e}from"../../_virtual/_tslib.js";import{jsx as t,jsxs as s,Fragment as o}from"react/jsx-runtime";import i from"../../assets/icons/arrow_back.svg.js";import l from"../../assets/icons/cross.svg.js";import a from"../../assets/icons/plus.svg.js";import n from"../../assets/icons/triangle_error.svg.js";import{useState as r,useEffect as c}from"react";import{COLORS as d}from"../../constants/Theme.js";import{BikAccordion as h}from"../accordion/Accordion.js";import{IconButton as p}from"../icon-button/IconButton.js";import{Input as m}from"../input/Input.js";import{ListItem as u}from"../list-item/ListItem.js";import{Switch as g}from"../switch/Switch.js";import{Tooltip as b}from"../tooltips/Tooltip.js";import{TitleRegular as f,BodySecondary as y,BodyCaption as v,TitleSmall as j}from"../TypographyStyle.js";import{VariablePickerContext as x}from"./context.js";import{DefaultVariableContent as O}from"./DefaultVariableContent.js";import{PickerType as w}from"./model.js";import S from"./NoResult.js";import{showOnlyRecommendedVariables as k}from"./recommendVaribles.js";import{searchVariables as C}from"./searchVariables.js";import{HeaderWrapper as V,RecommendWrapper as T,BackHeader as I,Container as N}from"./styles.js";import B,{renderTooltipBody as R}from"./SubHeaderItems.js";const D=(e,o)=>{if(0===o.length)return e;const i=e.toLowerCase().indexOf(o.toLowerCase());if(-1===i)return e;const l=e.slice(0,i),a=e.slice(i,i+o.length),n=e.slice(i+o.length);return s("span",{children:[l,t("b",Object.assign({style:{color:d.content.primary}},{children:a})),n]})},E=/.*\..*/,H=H=>{const{data:L,onSelect:$,showHeader:P,showBackButton:_,hideHeaderCross:A,onBackButtonClick:z,isEvaluationList:F,autoOpenFirst:K,headerText:M,contentHeight:q}=H,[G,J]=r(L),[Q,U]=r(""),[W,X]=r([]),[Y,Z]=r(""),[ee,te]=r(!1),[se,oe]=r([]),[ie,le]=r(!1),[ae,ne]=r(),re=ie&&H.type===w.EMBEDDED&&!A;console.log("variables",G),c((()=>{ce(!0)}),[]),c((()=>{W.length>0?oe([W[W.length-1]]):oe(L)}),[W]);const ce=t=>e(void 0,void 0,void 0,(function*(){if(te(t),t){const e=k(G,W);J(e)}else if(W.length>0){const e=Y==W[W.length-1].displayName;if(Q.length>0&&e){const e=C(Q,se,W);J(e)}else J([W[W.length-1].variables])}else if(Q.length>0){const e=C(Q,se,W);J(e)}else J(L)})),de=()=>{if(q)return q;let e=131;return W.length>0&&(e+=32),(H.showHeader||H.showBackButton)&&(e+=40),`calc(100% - ${e}px)`},he=e=>{if(!H.disabled)if(F){const t=(e=>{if(e.actualValue.match(E)){const t=e.actualValue.replace("{{","").replace("}}","").split(".");let s=t[0];return t.forEach(((e,t)=>{if(0===t)return;const o=(e=>/\w+\[\d+\]/g.test(e))(e);if(o){const t=e.match(/(\w+)\[(\d+)\]/);if(t){const e=t[1],o=t[2];s+=`['${e}'][${o}]`}}else s+=`['${e}']`})),s}return e.actualValueEval?e.actualValueEval:e.actualValue})(e);$(Object.assign(Object.assign({},e),{actualValue:t}))}else{if(e.isDefaultValueSupported)return ne(e),void le(!0);$(e)}};return t(x.Provider,Object.assign({value:{variables:G,searchText:Q,subHeaderStack:W,showRecommended:ee,setSubHeaderStack:X,setSearchText:U,setVariables:J,setShowRecommended:te}},{children:s("div",Object.assign({tabIndex:-1,id:"variable-picker-v3",style:{backgroundColor:"white",borderRadius:4,height:"100%",outline:"none"},onClick:e=>e.stopPropagation()},{children:[(P||_||ie)&&s(V,Object.assign({openDefault:ie},{children:[s("div",Object.assign({style:{display:"flex",alignItems:"center",gap:8}},{children:[(_||ie)&&t(p,{Icon:()=>t(i,{width:16,height:16,style:{display:"flex",color:d.content.primary}}),onClick:()=>{ie?ie&&le(!1):z&&z()}}),(P||ie)&&t(f,{children:ie?"Set up":null!=M?M:"Select Variable"})]})),re&&t(p,{style:{color:"#212121"},Icon:l,onClick:()=>H.onClose&&H.onClose()})]})),ie&&ae?t(O,{variable:ae,onInsertVariable:e=>{$(e),console.log("uploa",e)}}):s(o,{children:[t("div",Object.assign({style:{padding:"0 16px",paddingTop:12,backgroundColor:d.surface.subdued,borderTopLeftRadius:4,borderTopRightRadius:4}},{children:t(m,{id:"search-bar-v3-picker",onBlur:e=>{H.onSearchBlur&&H.onSearchBlur(e)},value:Q,noKeyDownChange:!0,placeholder:"Search",onChangeText:e=>{e||Z("");const t=C(e,se,W);if(ee){const e=k(t,W);J(e)}else J(t);U(e);const s=W.length>0?W[W.length-1].displayName:"home";Z(s)}})})),s(T,{children:[t(y,Object.assign({style:{color:d.content.secondary}},{children:"Only Recommended"})),t(g,{value:ee,onValueChange:t=>e(void 0,void 0,void 0,(function*(){yield ce(t)}))})]}),W.length>0&&s(I,{children:[t("div",Object.assign({style:{position:"absolute",left:16}},{children:t(p,{id:"back-btn-v3",style:{display:"flex"},Icon:()=>t(i,{width:12,height:12,style:{color:d.content.secondary}}),onClick:e=>{e.stopPropagation();let t=Q;const s=[...W],o=s.pop();if(X(s),o.displayName===Y&&(U(""),t=""),t.length>0){const e=s.length>0?[s[s.length-1]]:L,o=C(t,e,s);if(ee){const e=k(o,s);J(e)}else J(o)}else if(s.length>0)if(ee){const e=k([s[s.length-1].variables],s);J(e)}else J([s[s.length-1].variables]);else if(ee){const e=k(L,W);J(e)}else J(L)}})})),t(v,Object.assign({style:{color:d.content.secondary}},{children:W[W.length-1].displayName}))]}),t(o,{children:G.length>0?t(N,Object.assign({height:de()},{children:G.map(((e,i)=>{var l,r;return e.displayName&&void 0!==e.variables?t("div",Object.assign({style:{borderBottom:`1px solid ${d.stroke.primary}`}},{children:t(h,Object.assign({autoOpen:K&&0===i,headerPadding:"12px 16px",header:t(j,Object.assign({style:{color:d.content.secondary}},{children:D(e.displayName,Q)}))},{children:t(B,{parentVariable:e,disabled:null!==(l=H.disabled)&&void 0!==l&&l,searchText:Q,variable:e.variables,onSelect:e=>{if(e.isDefaultValueSupported)return ne(e),void le(!0);$(e)}})}))}),e.displayName+ee):e.displayName?t(b,Object.assign({body:R(e),placement:"bottom"},{children:t(u,{variant:H.disabled?"readonly":(null==e?void 0:e.selected)?"selected":"default",version:"2.0",leadingIcon:(null==e?void 0:e.selected)||H.disabled?t(o,{}):t(a,{width:14,height:14}),customListItemLabel:s("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(y,Object.assign({style:{fontSize:"14px",color:d.text.primary}},{children:D(e.displayName,Q)})),!e.isAvailable&&t(b,Object.assign({body:"Not Recommended"},{children:t("div",Object.assign({style:{display:"flex",marginTop:2}},{children:t(n,{width:16,height:16,color:d.content.secondary})}))}))]})),listItem:{label:e.displayName,value:e.displayName},subText:e.description||"",onClick:()=>he(e)},i)}),i):t(B,{disabled:null!==(r=H.disabled)&&void 0!==r&&r,searchText:Q,variable:e,onSelect:e=>he(e)},i)}))})):t(S,{height:de(),searchText:Q})})]})]}))}))};export{H as VariablePickerContent,D as highlightSearchText};
|
|
@@ -17,6 +17,7 @@ export interface VariablePickerV3Props {
|
|
|
17
17
|
disabled?: boolean;
|
|
18
18
|
autoOpenFirst?: boolean;
|
|
19
19
|
headerText?: string;
|
|
20
|
+
contentHeight?: string;
|
|
20
21
|
}
|
|
21
22
|
export interface VariableListInterfaceV3 {
|
|
22
23
|
isSubHeader?: boolean;
|
|
@@ -54,6 +55,6 @@ export interface VariableV3 {
|
|
|
54
55
|
[key: string]: VariableV3;
|
|
55
56
|
};
|
|
56
57
|
needsFetching?: boolean;
|
|
57
|
-
|
|
58
|
+
isDefaultValueSupported?: boolean;
|
|
58
59
|
enableDefaultValueForGlobalUsage?: boolean;
|
|
59
60
|
}
|