@bikdotai/bik-component-library 0.0.863 → 0.0.864-beta.0
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/template-context-mapper/utils/getDataFromTemplateComponent.js +1 -1
- package/dist/cjs/components/template-context-mapper/utils/getDataFromTemplateComponent.js.map +1 -1
- package/dist/esm/components/template-context-mapper/utils/getDataFromTemplateComponent.js +44 -38
- package/dist/esm/components/template-context-mapper/utils/getDataFromTemplateComponent.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=s=>{const a=[],p=[],o=[],l=[],n=[],d=[];let y=null;s.components.forEach((t,i)=>{if(t.type==="BODY"&&t.text&&a.push({component:t,i,type:"BODY"}),t.type==="TITLE"&&t.text&&a.push({component:t,i,type:"TITLE"}),t.type==="HEADER"&&t.format!=="NONE"&&t.format!=="TEXT"&&t.example?.header_handle?.[0]&&(y=t),t.type==="HEADER"&&t.format==="TEXT"&&a.push({component:t,i,type:"HEADER"}),t.type==="BUTTONS"){const u=t.buttons?.filter?.(f=>f.type==="URL");p.push({component:{...t,buttons:u},i});const b=t.buttons?.filter?.(f=>f.type==="QUICK_REPLY");o.push({component:{...t,buttons:b},i})}t.type==="limited_time_offer"&&a.push({component:t,i,type:"limited_time_offer"})});const r=a.findIndex(t=>t.type==="TITLE"),e=a.findIndex(t=>t.type==="BODY");if(r>-1&&e>-1&&r>e){const[t]=a.splice(r,1);a.splice(e,0,t)}return s.mapping&&s.mapping.body?.forEach(t=>{l.push(t)}),s.mapping&&s.mapping.header?.forEach(t=>{n.push(t)}),s.mapping&&s.mapping.title?.forEach(t=>{d.push(t)}),{imageComponent:y,descriptionComponents:a,urlBtns:p,qrbBtns:o,bodyVariables:l,headerVariables:n,titleVariables:d}},h=(s,a)=>{const p=s?.body?.map(e=>e)||[],o=s?.title?.map(e=>e)||[],l=s?.icon?.map(e=>e)||[],n=s?.image?.map(e=>e)||[],d=s?.redirectionLink?.map(e=>e)||[],r=Object.keys(a).map(e=>({type:e.toUpperCase(),component:{...a[e],type:e.toUpperCase()}}));return{bodyVariables:p,titleVariables:o,iconImage:l,bannerImage:n,redirectionLink:d,descriptionComponents:r}};exports.getAllDataFromTemplateComponent=T;exports.getAllDataFromWebpushTemplateComponent=h;
|
|
2
2
|
//# sourceMappingURL=getDataFromTemplateComponent.js.map
|
package/dist/cjs/components/template-context-mapper/utils/getDataFromTemplateComponent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDataFromTemplateComponent.js","sources":["../../../../../src/components/template-context-mapper/utils/getDataFromTemplateComponent.ts"],"sourcesContent":["import type {\n\tWebpushTemplateType,\n\tWebpushTemplateVariables,\n} from '@src/components/template-preview/models/WebpushTemplate';\nimport type { WhatsAppTemplate } from '@src/components/template-preview/models/WhatsAppTemplate';\n\ntype ComponentType = WhatsAppTemplate['components'][0];\n\nexport const getAllDataFromTemplateComponent = (template: WhatsAppTemplate) => {\n\tconst descriptionComponents: {\n\t\tcomponent: ComponentType;\n\t\ti: number;\n\t\ttype: ComponentType['type'];\n\t}[] = [];\n\tconst urlBtns: { component: ComponentType; i: number }[] = [],\n\t\tqrbBtns: { component: ComponentType; i: number }[] = [],\n\t\tbodyVariables: string[] = [],\n\t\theaderVariables: string[] = [],\n\t\ttitleVariables: string[] = [];\n\tlet imageComponent: ComponentType | null = null;\n\n\ttemplate.components.forEach((component, i) => {\n\t\tif (component.type === 'BODY' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'BODY' });\n\t\t}\n\n\t\tif (component.type === 'TITLE' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'TITLE' });\n\t\t}\n\n\t\tif (\n\t\t\tcomponent.type === 'HEADER' &&\n\t\t\tcomponent.format !== 'NONE' &&\n\t\t\tcomponent.format !== 'TEXT'\n\t\t) {\n\t\t\tif (component.example?.header_handle?.[0]) {\n\t\t\t\timageComponent = component;\n\t\t\t}\n\t\t}\n\n\t\tif (component.type === 'HEADER' && component.format === 'TEXT') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'HEADER' });\n\t\t}\n\n\t\tif (component.type === 'BUTTONS') {\n\t\t\tconst urlBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'URL',\n\t\t\t);\n\t\t\turlBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: urlBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t\tconst qrbBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'QUICK_REPLY',\n\t\t\t);\n\t\t\tqrbBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: qrbBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t}\n\n\t\tif (component.type === 'limited_time_offer') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'limited_time_offer' });\n\t\t}\n\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.body?.forEach((variable) => {\n\t\t\tbodyVariables.push(variable);\n\t\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.header?.forEach((variable) => {\n\t\t\theaderVariables.push(variable);\n\t\t});\n\
|
|
1
|
+
{"version":3,"file":"getDataFromTemplateComponent.js","sources":["../../../../../src/components/template-context-mapper/utils/getDataFromTemplateComponent.ts"],"sourcesContent":["import type {\n\tWebpushTemplateType,\n\tWebpushTemplateVariables,\n} from '@src/components/template-preview/models/WebpushTemplate';\nimport type { WhatsAppTemplate } from '@src/components/template-preview/models/WhatsAppTemplate';\n\ntype ComponentType = WhatsAppTemplate['components'][0];\n\nexport const getAllDataFromTemplateComponent = (template: WhatsAppTemplate) => {\n\tconst descriptionComponents: {\n\t\tcomponent: ComponentType;\n\t\ti: number;\n\t\ttype: ComponentType['type'];\n\t}[] = [];\n\tconst urlBtns: { component: ComponentType; i: number }[] = [],\n\t\tqrbBtns: { component: ComponentType; i: number }[] = [],\n\t\tbodyVariables: string[] = [],\n\t\theaderVariables: string[] = [],\n\t\ttitleVariables: string[] = [];\n\tlet imageComponent: ComponentType | null = null;\n\n\ttemplate.components.forEach((component, i) => {\n\t\tif (component.type === 'BODY' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'BODY' });\n\t\t}\n\n\t\tif (component.type === 'TITLE' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'TITLE' });\n\t\t}\n\n\t\tif (\n\t\t\tcomponent.type === 'HEADER' &&\n\t\t\tcomponent.format !== 'NONE' &&\n\t\t\tcomponent.format !== 'TEXT'\n\t\t) {\n\t\t\tif (component.example?.header_handle?.[0]) {\n\t\t\t\timageComponent = component;\n\t\t\t}\n\t\t}\n\n\t\tif (component.type === 'HEADER' && component.format === 'TEXT') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'HEADER' });\n\t\t}\n\n\t\tif (component.type === 'BUTTONS') {\n\t\t\tconst urlBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'URL',\n\t\t\t);\n\t\t\turlBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: urlBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t\tconst qrbBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'QUICK_REPLY',\n\t\t\t);\n\t\t\tqrbBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: qrbBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t}\n\n\t\tif (component.type === 'limited_time_offer') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'limited_time_offer' });\n\t\t}\n\t});\n\n\t// RCSChatPreview always renders TITLE above BODY regardless of the stored\n\t// component order (some templates have BODY stored before TITLE). Keep this\n\t// edit panel in that same visual order so \"variable 1\" here is the one the\n\t// merchant actually sees first in the message preview.\n\tconst titleIndex = descriptionComponents.findIndex((d) => d.type === 'TITLE');\n\tconst bodyIndex = descriptionComponents.findIndex((d) => d.type === 'BODY');\n\tif (titleIndex > -1 && bodyIndex > -1 && titleIndex > bodyIndex) {\n\t\tconst [titleEntry] = descriptionComponents.splice(titleIndex, 1);\n\t\tdescriptionComponents.splice(bodyIndex, 0, titleEntry);\n\t}\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.body?.forEach((variable) => {\n\t\t\tbodyVariables.push(variable);\n\t\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.header?.forEach((variable) => {\n\t\t\theaderVariables.push(variable);\n\t\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.title?.forEach((variable) => {\n\t\t\ttitleVariables.push(variable);\n\t\t});\n\n\treturn {\n\t\timageComponent,\n\t\tdescriptionComponents,\n\t\turlBtns,\n\t\tqrbBtns,\n\t\tbodyVariables,\n\t\theaderVariables,\n\t\ttitleVariables,\n\t};\n};\n\nexport const getAllDataFromWebpushTemplateComponent = (\n\tmapping: WebpushTemplateType['webpushBroadcastConfig'],\n\ttemplateVariables: WebpushTemplateVariables,\n) => {\n\tconst bodyVariables = mapping?.body?.map((each) => each) || [];\n\tconst titleVariables = mapping?.title?.map((each) => each) || [];\n\tconst iconImage = mapping?.icon?.map((each) => each) || [];\n\tconst bannerImage = mapping?.image?.map((each) => each) || [];\n\tconst redirectionLink = mapping?.redirectionLink?.map((each) => each) || [];\n\tconst KeysToMap = Object.keys(templateVariables);\n\tconst descriptionComponents = KeysToMap.map((key) => ({\n\t\ttype: key.toUpperCase(),\n\t\tcomponent: { ...templateVariables[key], type: key.toUpperCase() },\n\t}));\n\treturn {\n\t\tbodyVariables,\n\t\ttitleVariables,\n\t\ticonImage,\n\t\tbannerImage,\n\t\tredirectionLink,\n\t\tdescriptionComponents,\n\t};\n};\n"],"names":["getAllDataFromTemplateComponent","template","descriptionComponents","urlBtns","qrbBtns","bodyVariables","headerVariables","titleVariables","imageComponent","component","urlBtnsToAdd","btn","qrbBtnsToAdd","titleIndex","d","bodyIndex","titleEntry","variable","getAllDataFromWebpushTemplateComponent","mapping","templateVariables","each","iconImage","bannerImage","redirectionLink","key"],"mappings":"gFAQO,MAAMA,EAAmCC,GAA+B,CAC9E,MAAMC,EAIA,CAAA,EACAC,EAAqD,GAC1DC,EAAqD,CAAA,EACrDC,EAA0B,CAAA,EAC1BC,EAA4B,GAC5BC,EAA2B,CAAA,EAC5B,IAAIC,EAAuC,KAE3CP,EAAS,WAAW,QAAQ,CAACQ,EAAW,IAAM,CAuB7C,GAtBIA,EAAU,OAAS,QAAUA,EAAU,MAC1CP,EAAsB,KAAK,CAAE,UAAAO,EAAW,EAAG,KAAM,OAAQ,EAGtDA,EAAU,OAAS,SAAWA,EAAU,MAC3CP,EAAsB,KAAK,CAAE,UAAAO,EAAW,EAAG,KAAM,QAAS,EAI1DA,EAAU,OAAS,UACnBA,EAAU,SAAW,QACrBA,EAAU,SAAW,QAEjBA,EAAU,SAAS,gBAAgB,CAAC,IACvCD,EAAiBC,GAIfA,EAAU,OAAS,UAAYA,EAAU,SAAW,QACvDP,EAAsB,KAAK,CAAE,UAAAO,EAAW,EAAG,KAAM,SAAU,EAGxDA,EAAU,OAAS,UAAW,CACjC,MAAMC,EAAeD,EAAU,SAAS,SACtCE,GAAQA,EAAI,OAAS,KAAA,EAEvBR,EAAQ,KAAK,CACZ,UAAW,CACV,GAAGM,EACH,QAASC,CAAA,EAEV,CAAA,CACA,EACD,MAAME,EAAeH,EAAU,SAAS,SACtCE,GAAQA,EAAI,OAAS,aAAA,EAEvBP,EAAQ,KAAK,CACZ,UAAW,CACV,GAAGK,EACH,QAASG,CAAA,EAEV,CAAA,CAC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MA,EAAI,YAAA,CAAY,CAAE,EAC/D,EACF,MAAO,CACN,cAAApB,EACA,eAAAE,EACA,UAAAe,EACA,YAAAC,EACA,gBAAAC,EACA,sBAAAtB,CAAA,CAEF"}
|
|
@@ -1,61 +1,67 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
if (t.type === "BODY" && t.text &&
|
|
6
|
-
const
|
|
7
|
-
(
|
|
1
|
+
const h = (s) => {
|
|
2
|
+
const i = [], p = [], o = [], d = [], n = [], f = [];
|
|
3
|
+
let y = null;
|
|
4
|
+
s.components.forEach((t, r) => {
|
|
5
|
+
if (t.type === "BODY" && t.text && i.push({ component: t, i: r, type: "BODY" }), t.type === "TITLE" && t.text && i.push({ component: t, i: r, type: "TITLE" }), t.type === "HEADER" && t.format !== "NONE" && t.format !== "TEXT" && t.example?.header_handle?.[0] && (y = t), t.type === "HEADER" && t.format === "TEXT" && i.push({ component: t, i: r, type: "HEADER" }), t.type === "BUTTONS") {
|
|
6
|
+
const u = t.buttons?.filter?.(
|
|
7
|
+
(l) => l.type === "URL"
|
|
8
8
|
);
|
|
9
|
-
|
|
9
|
+
p.push({
|
|
10
10
|
component: {
|
|
11
11
|
...t,
|
|
12
|
-
buttons:
|
|
12
|
+
buttons: u
|
|
13
13
|
},
|
|
14
|
-
i:
|
|
14
|
+
i: r
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
(
|
|
16
|
+
const b = t.buttons?.filter?.(
|
|
17
|
+
(l) => l.type === "QUICK_REPLY"
|
|
18
18
|
);
|
|
19
|
-
|
|
19
|
+
o.push({
|
|
20
20
|
component: {
|
|
21
21
|
...t,
|
|
22
|
-
buttons:
|
|
22
|
+
buttons: b
|
|
23
23
|
},
|
|
24
|
-
i:
|
|
24
|
+
i: r
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
t.type === "limited_time_offer" &&
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
t.type === "limited_time_offer" && i.push({ component: t, i: r, type: "limited_time_offer" });
|
|
28
|
+
});
|
|
29
|
+
const a = i.findIndex((t) => t.type === "TITLE"), e = i.findIndex((t) => t.type === "BODY");
|
|
30
|
+
if (a > -1 && e > -1 && a > e) {
|
|
31
|
+
const [t] = i.splice(a, 1);
|
|
32
|
+
i.splice(e, 0, t);
|
|
33
|
+
}
|
|
34
|
+
return s.mapping && s.mapping.body?.forEach((t) => {
|
|
35
|
+
d.push(t);
|
|
36
|
+
}), s.mapping && s.mapping.header?.forEach((t) => {
|
|
37
|
+
n.push(t);
|
|
38
|
+
}), s.mapping && s.mapping.title?.forEach((t) => {
|
|
33
39
|
f.push(t);
|
|
34
40
|
}), {
|
|
35
|
-
imageComponent:
|
|
36
|
-
descriptionComponents:
|
|
37
|
-
urlBtns:
|
|
38
|
-
qrbBtns:
|
|
39
|
-
bodyVariables:
|
|
40
|
-
headerVariables:
|
|
41
|
+
imageComponent: y,
|
|
42
|
+
descriptionComponents: i,
|
|
43
|
+
urlBtns: p,
|
|
44
|
+
qrbBtns: o,
|
|
45
|
+
bodyVariables: d,
|
|
46
|
+
headerVariables: n,
|
|
41
47
|
titleVariables: f
|
|
42
48
|
};
|
|
43
|
-
},
|
|
44
|
-
const
|
|
45
|
-
type:
|
|
46
|
-
component: { ...
|
|
49
|
+
}, E = (s, i) => {
|
|
50
|
+
const p = s?.body?.map((e) => e) || [], o = s?.title?.map((e) => e) || [], d = s?.icon?.map((e) => e) || [], n = s?.image?.map((e) => e) || [], f = s?.redirectionLink?.map((e) => e) || [], a = Object.keys(i).map((e) => ({
|
|
51
|
+
type: e.toUpperCase(),
|
|
52
|
+
component: { ...i[e], type: e.toUpperCase() }
|
|
47
53
|
}));
|
|
48
54
|
return {
|
|
49
|
-
bodyVariables:
|
|
50
|
-
titleVariables:
|
|
51
|
-
iconImage:
|
|
52
|
-
bannerImage:
|
|
55
|
+
bodyVariables: p,
|
|
56
|
+
titleVariables: o,
|
|
57
|
+
iconImage: d,
|
|
58
|
+
bannerImage: n,
|
|
53
59
|
redirectionLink: f,
|
|
54
|
-
descriptionComponents:
|
|
60
|
+
descriptionComponents: a
|
|
55
61
|
};
|
|
56
62
|
};
|
|
57
63
|
export {
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
h as getAllDataFromTemplateComponent,
|
|
65
|
+
E as getAllDataFromWebpushTemplateComponent
|
|
60
66
|
};
|
|
61
67
|
//# sourceMappingURL=getDataFromTemplateComponent.js.map
|
package/dist/esm/components/template-context-mapper/utils/getDataFromTemplateComponent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDataFromTemplateComponent.js","sources":["../../../../../src/components/template-context-mapper/utils/getDataFromTemplateComponent.ts"],"sourcesContent":["import type {\n\tWebpushTemplateType,\n\tWebpushTemplateVariables,\n} from '@src/components/template-preview/models/WebpushTemplate';\nimport type { WhatsAppTemplate } from '@src/components/template-preview/models/WhatsAppTemplate';\n\ntype ComponentType = WhatsAppTemplate['components'][0];\n\nexport const getAllDataFromTemplateComponent = (template: WhatsAppTemplate) => {\n\tconst descriptionComponents: {\n\t\tcomponent: ComponentType;\n\t\ti: number;\n\t\ttype: ComponentType['type'];\n\t}[] = [];\n\tconst urlBtns: { component: ComponentType; i: number }[] = [],\n\t\tqrbBtns: { component: ComponentType; i: number }[] = [],\n\t\tbodyVariables: string[] = [],\n\t\theaderVariables: string[] = [],\n\t\ttitleVariables: string[] = [];\n\tlet imageComponent: ComponentType | null = null;\n\n\ttemplate.components.forEach((component, i) => {\n\t\tif (component.type === 'BODY' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'BODY' });\n\t\t}\n\n\t\tif (component.type === 'TITLE' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'TITLE' });\n\t\t}\n\n\t\tif (\n\t\t\tcomponent.type === 'HEADER' &&\n\t\t\tcomponent.format !== 'NONE' &&\n\t\t\tcomponent.format !== 'TEXT'\n\t\t) {\n\t\t\tif (component.example?.header_handle?.[0]) {\n\t\t\t\timageComponent = component;\n\t\t\t}\n\t\t}\n\n\t\tif (component.type === 'HEADER' && component.format === 'TEXT') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'HEADER' });\n\t\t}\n\n\t\tif (component.type === 'BUTTONS') {\n\t\t\tconst urlBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'URL',\n\t\t\t);\n\t\t\turlBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: urlBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t\tconst qrbBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'QUICK_REPLY',\n\t\t\t);\n\t\t\tqrbBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: qrbBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t}\n\n\t\tif (component.type === 'limited_time_offer') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'limited_time_offer' });\n\t\t}\n\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.body?.forEach((variable) => {\n\t\t\tbodyVariables.push(variable);\n\t\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.header?.forEach((variable) => {\n\t\t\theaderVariables.push(variable);\n\t\t});\n\
|
|
1
|
+
{"version":3,"file":"getDataFromTemplateComponent.js","sources":["../../../../../src/components/template-context-mapper/utils/getDataFromTemplateComponent.ts"],"sourcesContent":["import type {\n\tWebpushTemplateType,\n\tWebpushTemplateVariables,\n} from '@src/components/template-preview/models/WebpushTemplate';\nimport type { WhatsAppTemplate } from '@src/components/template-preview/models/WhatsAppTemplate';\n\ntype ComponentType = WhatsAppTemplate['components'][0];\n\nexport const getAllDataFromTemplateComponent = (template: WhatsAppTemplate) => {\n\tconst descriptionComponents: {\n\t\tcomponent: ComponentType;\n\t\ti: number;\n\t\ttype: ComponentType['type'];\n\t}[] = [];\n\tconst urlBtns: { component: ComponentType; i: number }[] = [],\n\t\tqrbBtns: { component: ComponentType; i: number }[] = [],\n\t\tbodyVariables: string[] = [],\n\t\theaderVariables: string[] = [],\n\t\ttitleVariables: string[] = [];\n\tlet imageComponent: ComponentType | null = null;\n\n\ttemplate.components.forEach((component, i) => {\n\t\tif (component.type === 'BODY' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'BODY' });\n\t\t}\n\n\t\tif (component.type === 'TITLE' && component.text) {\n\t\t\tdescriptionComponents.push({ component, i, type: 'TITLE' });\n\t\t}\n\n\t\tif (\n\t\t\tcomponent.type === 'HEADER' &&\n\t\t\tcomponent.format !== 'NONE' &&\n\t\t\tcomponent.format !== 'TEXT'\n\t\t) {\n\t\t\tif (component.example?.header_handle?.[0]) {\n\t\t\t\timageComponent = component;\n\t\t\t}\n\t\t}\n\n\t\tif (component.type === 'HEADER' && component.format === 'TEXT') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'HEADER' });\n\t\t}\n\n\t\tif (component.type === 'BUTTONS') {\n\t\t\tconst urlBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'URL',\n\t\t\t);\n\t\t\turlBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: urlBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t\tconst qrbBtnsToAdd = component.buttons?.filter?.(\n\t\t\t\t(btn) => btn.type === 'QUICK_REPLY',\n\t\t\t);\n\t\t\tqrbBtns.push({\n\t\t\t\tcomponent: {\n\t\t\t\t\t...component,\n\t\t\t\t\tbuttons: qrbBtnsToAdd,\n\t\t\t\t},\n\t\t\t\ti,\n\t\t\t});\n\t\t}\n\n\t\tif (component.type === 'limited_time_offer') {\n\t\t\tdescriptionComponents.push({ component, i, type: 'limited_time_offer' });\n\t\t}\n\t});\n\n\t// RCSChatPreview always renders TITLE above BODY regardless of the stored\n\t// component order (some templates have BODY stored before TITLE). Keep this\n\t// edit panel in that same visual order so \"variable 1\" here is the one the\n\t// merchant actually sees first in the message preview.\n\tconst titleIndex = descriptionComponents.findIndex((d) => d.type === 'TITLE');\n\tconst bodyIndex = descriptionComponents.findIndex((d) => d.type === 'BODY');\n\tif (titleIndex > -1 && bodyIndex > -1 && titleIndex > bodyIndex) {\n\t\tconst [titleEntry] = descriptionComponents.splice(titleIndex, 1);\n\t\tdescriptionComponents.splice(bodyIndex, 0, titleEntry);\n\t}\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.body?.forEach((variable) => {\n\t\t\tbodyVariables.push(variable);\n\t\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.header?.forEach((variable) => {\n\t\t\theaderVariables.push(variable);\n\t\t});\n\n\ttemplate.mapping &&\n\t\ttemplate.mapping.title?.forEach((variable) => {\n\t\t\ttitleVariables.push(variable);\n\t\t});\n\n\treturn {\n\t\timageComponent,\n\t\tdescriptionComponents,\n\t\turlBtns,\n\t\tqrbBtns,\n\t\tbodyVariables,\n\t\theaderVariables,\n\t\ttitleVariables,\n\t};\n};\n\nexport const getAllDataFromWebpushTemplateComponent = (\n\tmapping: WebpushTemplateType['webpushBroadcastConfig'],\n\ttemplateVariables: WebpushTemplateVariables,\n) => {\n\tconst bodyVariables = mapping?.body?.map((each) => each) || [];\n\tconst titleVariables = mapping?.title?.map((each) => each) || [];\n\tconst iconImage = mapping?.icon?.map((each) => each) || [];\n\tconst bannerImage = mapping?.image?.map((each) => each) || [];\n\tconst redirectionLink = mapping?.redirectionLink?.map((each) => each) || [];\n\tconst KeysToMap = Object.keys(templateVariables);\n\tconst descriptionComponents = KeysToMap.map((key) => ({\n\t\ttype: key.toUpperCase(),\n\t\tcomponent: { ...templateVariables[key], type: key.toUpperCase() },\n\t}));\n\treturn {\n\t\tbodyVariables,\n\t\ttitleVariables,\n\t\ticonImage,\n\t\tbannerImage,\n\t\tredirectionLink,\n\t\tdescriptionComponents,\n\t};\n};\n"],"names":["getAllDataFromTemplateComponent","template","descriptionComponents","urlBtns","qrbBtns","bodyVariables","headerVariables","titleVariables","imageComponent","component","i","urlBtnsToAdd","btn","qrbBtnsToAdd","titleIndex","d","bodyIndex","titleEntry","variable","getAllDataFromWebpushTemplateComponent","mapping","templateVariables","each","iconImage","bannerImage","redirectionLink","key"],"mappings":"AAQO,MAAMA,IAAkC,CAACC,MAA+B;AAC9E,QAAMC,IAIA,CAAA,GACAC,IAAqD,IAC1DC,IAAqD,CAAA,GACrDC,IAA0B,CAAA,GAC1BC,IAA4B,IAC5BC,IAA2B,CAAA;AAC5B,MAAIC,IAAuC;AAE3C,EAAAP,EAAS,WAAW,QAAQ,CAACQ,GAAWC,MAAM;AAuB7C,QAtBID,EAAU,SAAS,UAAUA,EAAU,QAC1CP,EAAsB,KAAK,EAAE,WAAAO,GAAW,GAAAC,GAAG,MAAM,QAAQ,GAGtDD,EAAU,SAAS,WAAWA,EAAU,QAC3CP,EAAsB,KAAK,EAAE,WAAAO,GAAW,GAAAC,GAAG,MAAM,SAAS,GAI1DD,EAAU,SAAS,YACnBA,EAAU,WAAW,UACrBA,EAAU,WAAW,UAEjBA,EAAU,SAAS,gBAAgB,CAAC,MACvCD,IAAiBC,IAIfA,EAAU,SAAS,YAAYA,EAAU,WAAW,UACvDP,EAAsB,KAAK,EAAE,WAAAO,GAAW,GAAAC,GAAG,MAAM,UAAU,GAGxDD,EAAU,SAAS,WAAW;AACjC,YAAME,IAAeF,EAAU,SAAS;AAAA,QACvC,CAACG,MAAQA,EAAI,SAAS;AAAA,MAAA;AAEvB,MAAAT,EAAQ,KAAK;AAAA,QACZ,WAAW;AAAA,UACV,GAAGM;AAAA,UACH,SAASE;AAAA,QAAA;AAAA,QAEV,GAAAD;AAAA,MAAA,CACA;AACD,YAAMG,IAAeJ,EAAU,SAAS;AAAA,QACvC,CAACG,MAAQA,EAAI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