@brainfish-ai/widgets-initiator 0.1.1-beta → 0.5.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/LICENSE +21 -0
- package/README.md +94 -34
- package/components.json +16 -0
- package/dist/esm/index.css +4 -0
- package/dist/esm/index.css.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +801 -0
- package/package.json +141 -32
- package/package.json.bak +153 -0
- package/stats.html +4949 -0
- package/tailwind.config.js +140 -0
- package/.prettierignore +0 -7
- package/.prettierrc +0 -6
- package/dist/web.cjs.js +0 -2
- package/dist/web.cjs.js.map +0 -1
- package/dist/web.js +0 -2
- package/dist/web.js.map +0 -1
- package/index.html +0 -63
- package/postcss.config.cjs +0 -6
- package/src/register.ts +0 -31
- package/src/web.ts +0 -104
- package/tailwind.config.cjs +0 -9
- package/tsconfig.json +0 -14
- package/vite.config.ts +0 -33
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const { neutral, zinc } = require('tailwindcss/colors')
|
|
2
|
+
const plugin = require('tailwindcss/plugin');
|
|
3
|
+
const { fontFamily } = require('tailwindcss/defaultTheme');
|
|
4
|
+
|
|
5
|
+
const { BrainfishColors, customColor } = require('./src/colors');
|
|
6
|
+
const { blue, dark, green, orange, pink, primary, purple, red, yellow } = BrainfishColors;
|
|
7
|
+
|
|
8
|
+
/** @type {import('tailwindcss').Config} */
|
|
9
|
+
module.exports = {
|
|
10
|
+
darkMode: ["class"],
|
|
11
|
+
content: [
|
|
12
|
+
"./index.html",
|
|
13
|
+
"./src/**/*.{js,ts,jsx,tsx}",
|
|
14
|
+
],
|
|
15
|
+
theme: {
|
|
16
|
+
container: {
|
|
17
|
+
center: true,
|
|
18
|
+
padding: "2rem",
|
|
19
|
+
screens: {
|
|
20
|
+
"2xl": "1400px",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
extend: {
|
|
24
|
+
fontFamily: {
|
|
25
|
+
...fontFamily,
|
|
26
|
+
sans: ['var(--bfc-font-family)', 'system-ui', 'sans-serif'],
|
|
27
|
+
},
|
|
28
|
+
fontWeight: {
|
|
29
|
+
bold: '700',
|
|
30
|
+
normal: '500',
|
|
31
|
+
},
|
|
32
|
+
colors: {
|
|
33
|
+
transparent: 'transparent',
|
|
34
|
+
primary,
|
|
35
|
+
base: {
|
|
36
|
+
orange: orange[400],
|
|
37
|
+
yellow: yellow[400],
|
|
38
|
+
primary: primary[400],
|
|
39
|
+
green: green[400],
|
|
40
|
+
blue: blue[500],
|
|
41
|
+
purple: purple[500],
|
|
42
|
+
pink: pink[400],
|
|
43
|
+
red: red[500],
|
|
44
|
+
orangeLight: orange[100],
|
|
45
|
+
yellowLight: yellow[100],
|
|
46
|
+
primaryLight: primary[100],
|
|
47
|
+
greenLight: green[100],
|
|
48
|
+
blueLight: blue[100],
|
|
49
|
+
purpleLight: purple[100],
|
|
50
|
+
pinkLight: pink[100],
|
|
51
|
+
redLight: red[100],
|
|
52
|
+
},
|
|
53
|
+
dark,
|
|
54
|
+
orange,
|
|
55
|
+
yellow,
|
|
56
|
+
green,
|
|
57
|
+
blue,
|
|
58
|
+
purple,
|
|
59
|
+
pink,
|
|
60
|
+
red,
|
|
61
|
+
|
|
62
|
+
border: customColor('--bfc-border', dark[900]),
|
|
63
|
+
input: customColor('--bfc-input', dark[200]),
|
|
64
|
+
ring: customColor('--bfc-border', dark[900]),
|
|
65
|
+
background: customColor('--bfc-background', dark[200]),
|
|
66
|
+
foreground: customColor('--bfc-foreground', dark.DEFAULT),
|
|
67
|
+
feedback: {
|
|
68
|
+
positive: customColor('--bfc-feedback-positive', green[500]),
|
|
69
|
+
negative: customColor('--bfc-feedback-negative', red[500]),
|
|
70
|
+
},
|
|
71
|
+
link: customColor('--bfc-link', blue[500]),
|
|
72
|
+
surface: {
|
|
73
|
+
DEFAULT: customColor('--bfc-surface', neutral[800]),
|
|
74
|
+
border: customColor('--bfc-surface-border', zinc[800]),
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
secondary: {
|
|
78
|
+
DEFAULT: customColor('--bfc-secondary', 'transparent'),
|
|
79
|
+
foreground: customColor('--bfc-secondary-foreground', 'transparent'),
|
|
80
|
+
},
|
|
81
|
+
destructive: {
|
|
82
|
+
DEFAULT: customColor('--bfc-destructive', 'transparent'),
|
|
83
|
+
foreground: customColor('--bfc-destructive-foreground', 'transparent'),
|
|
84
|
+
},
|
|
85
|
+
muted: {
|
|
86
|
+
DEFAULT: customColor('--bfc-muted', 'transparent'),
|
|
87
|
+
foreground: customColor('--bfc-muted-foreground', 'transparent'),
|
|
88
|
+
},
|
|
89
|
+
accent: {
|
|
90
|
+
DEFAULT: customColor('--bfc-accent', 'transparent'),
|
|
91
|
+
foreground: customColor('--bfc-accent-foreground', 'transparent'),
|
|
92
|
+
},
|
|
93
|
+
popover: {
|
|
94
|
+
DEFAULT: customColor('--bfc-popover', 'transparent'),
|
|
95
|
+
foreground: customColor('--bfc-foreground', 'transparent'),
|
|
96
|
+
},
|
|
97
|
+
card: {
|
|
98
|
+
DEFAULT: customColor('--bfc-card', dark[200]),
|
|
99
|
+
foreground: customColor('--bfc-card-foreground', 'transparent'),
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
keyframes: {
|
|
103
|
+
"accordion-down": {
|
|
104
|
+
from: { height: 0 },
|
|
105
|
+
to: { height: "var(--bfc-radix-accordion-content-height)" },
|
|
106
|
+
},
|
|
107
|
+
"accordion-up": {
|
|
108
|
+
from: { height: "var(--bfc-radix-accordion-content-height)" },
|
|
109
|
+
to: { height: 0 },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
animation: {
|
|
113
|
+
"accordion-down": "accordion-down 0.2s ease-out",
|
|
114
|
+
"accordion-up": "accordion-up 0.2s ease-out",
|
|
115
|
+
},
|
|
116
|
+
maxWidth: {
|
|
117
|
+
threadWidth: '1400px',
|
|
118
|
+
},
|
|
119
|
+
spacing: {
|
|
120
|
+
headerHeight: '64px',
|
|
121
|
+
md: '16px',
|
|
122
|
+
lg: '24px',
|
|
123
|
+
xl: '32px',
|
|
124
|
+
},
|
|
125
|
+
gridTemplateColumns: {
|
|
126
|
+
12: 'repeat(12, minmax(0, 1fr))',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
plugins: [
|
|
131
|
+
require("tailwindcss-animate"),
|
|
132
|
+
require("@tailwindcss/container-queries"),
|
|
133
|
+
plugin(function ({ addBase }) {
|
|
134
|
+
addBase({
|
|
135
|
+
'ul': { listStyleType: 'disc' },
|
|
136
|
+
'ol': { listStyleType: 'decimal' },
|
|
137
|
+
});
|
|
138
|
+
}),
|
|
139
|
+
],
|
|
140
|
+
}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/dist/web.cjs.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var t,e;!function(t){t.Sidebar="sidebar",t.Searchbar="searchbar"}(t||(t={})),t.Sidebar,t.Searchbar,function(t){t.LINK="link",t.CALLBACK="callback",t.EMAIL="email",t.PHONE="phone"}(e||(e={}));const i="https://app.brainfi.sh";function n(t){return t.map((t=>t.type===e.CALLBACK?{...t,value:new Function(`return ${t.value}`)()}:t))}const o={Widgets:{init:async({widgetKey:e})=>{const o=`${i}/api/searchWidgets.getConfigByKey`,s=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","api-key":e}}).then((t=>t.json())).catch((t=>console.log("Error loading widget config",t)));if(!s)return void console.log("Error loading widget config");const a=(({config:t,apiKey:e})=>(t.settings?.bodyActionButtons&&(t.settings.bodyActionButtons=n(t.settings.bodyActionButtons)),t.settings?.footerActionButtons&&(t.settings.footerActionButtons=n(t.settings.footerActionButtons)),t.settings?.nextBestActions&&(t.settings.nextBestActions=n(t.settings.nextBestActions)),{...t,apiHost:`${i}`,widgetMode:t.widgetType,apiKey:e}))({config:s.config,apiKey:e}),r=a.version||"latest",{default:c}=await import(`https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${r}/dist/web.js`);switch(a.widgetType){case t.Searchbar:case"Search":c.SearchWidget.initStandard(a);break;case t.Sidebar:case"slide-over":c.HelpWidget.initPopup(a);break;default:return}}}};o&&(t=>{"undefined"!=typeof window&&(window.Brainfish?window.Brainfish={...window.Brainfish,...t}:window.Brainfish={...t})})(o),module.exports=o;
|
|
2
|
-
//# sourceMappingURL=web.cjs.js.map
|
package/dist/web.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web.cjs.js","sources":["../../common/dist/types/brainfish.js","../../common/dist/types/config.js","../../common/dist/window/inject-brainfish.js","../src/web.ts"],"sourcesContent":["export var WidgetType;\n(function (WidgetType) {\n WidgetType[\"Sidebar\"] = \"sidebar\";\n WidgetType[\"Searchbar\"] = \"searchbar\";\n})(WidgetType || (WidgetType = {}));\n;\nexport const WIDGET_NAMES = {\n [WidgetType.Sidebar]: 'brainfish-sidebar-widget',\n [WidgetType.Searchbar]: 'brainfish-searchbar-widget',\n};\n","const isUrlString = (value) => {\n const urlRegExp = /^(https?|ftp):\\/\\/[^\\s/$.?#].[^\\s]*$/i;\n return urlRegExp.test(value);\n};\nexport const validateUrlString = (value) => {\n if (!isUrlString(value)) {\n throw new Error(`Invalid URL: ${value}`);\n }\n return value;\n};\nexport var ActionType;\n(function (ActionType) {\n ActionType[\"LINK\"] = \"link\";\n ActionType[\"CALLBACK\"] = \"callback\";\n ActionType[\"EMAIL\"] = \"email\";\n ActionType[\"PHONE\"] = \"phone\";\n})(ActionType || (ActionType = {}));\n","export const injectBrainfishInWindow = (brainfish) => {\n if (typeof window === 'undefined')\n return;\n if (window.Brainfish) {\n window.Brainfish = { ...window.Brainfish, ...brainfish };\n }\n else {\n window.Brainfish = { ...brainfish };\n }\n};\n","// web.ts\n// entry point for web component\nimport * as Common from '@brainfish-ai/widgets-common';\nimport { Config, CallbackAction, Action } from '@brainfish-ai/widgets-common';\n\nconst API_HOST = import.meta.env.VITE_API_HOST;\n\nfunction mapActionButtons(\n actionButtons: (CallbackAction | Action)[]\n): (CallbackAction | Action)[] {\n return actionButtons.map((action) => {\n if (action.type === Common.ActionType.CALLBACK) {\n return {\n ...action,\n value: new Function(`return ${action.value}`)(),\n };\n }\n return action;\n });\n}\n\nconst transformConfig = ({\n config,\n apiKey,\n}: {\n config: Config;\n apiKey: string;\n}) => {\n if (!!config.settings?.bodyActionButtons) {\n config.settings.bodyActionButtons = mapActionButtons(\n config.settings.bodyActionButtons\n );\n }\n if (!!config.settings?.footerActionButtons) {\n config.settings.footerActionButtons = mapActionButtons(\n config.settings.footerActionButtons\n );\n }\n if (!!config.settings?.nextBestActions) {\n config.settings.nextBestActions = mapActionButtons(\n config.settings.nextBestActions\n );\n }\n return {\n ...config,\n apiHost: `${API_HOST}`,\n widgetMode: config.widgetType,\n apiKey,\n };\n};\n\nconst init = async ({ widgetKey }: { widgetKey: string }) => {\n const endpoint = `${API_HOST}/api/searchWidgets.getConfigByKey`;\n\n const configResponse = await fetch(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'api-key': widgetKey,\n },\n })\n .then((response) => response.json())\n .catch((error) => console.log('Error loading widget config', error));\n\n if (!configResponse) {\n console.log('Error loading widget config');\n return;\n }\n\n // const { config }: { config: Config } = configResponse;\n const config = transformConfig({\n config: configResponse.config,\n apiKey: widgetKey,\n });\n const version = config.version || 'latest';\n\n // import the widget based on the version from cdn.jsdelivr.net\n const { default: widget } = await import(\n `https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${version}/dist/web.js`\n );\n\n switch (config.widgetType) {\n case Common.WidgetType.Searchbar:\n case 'Search':\n widget.SearchWidget.initStandard(config);\n break;\n case Common.WidgetType.Sidebar:\n case 'slide-over': // for backwards compatibility\n widget.HelpWidget.initPopup(config);\n break;\n default:\n return;\n }\n};\n\nconst brainfish = {\n Widgets: { init }\n}\n\nif (brainfish) {\n Common.injectBrainfishInWindow(brainfish);\n}\n\nexport default brainfish;\n"],"names":["WidgetType","ActionType","Sidebar","Searchbar","API_HOST","mapActionButtons","actionButtons","map","action","type","Common.ActionType","CALLBACK","value","Function","brainfish","Widgets","init","async","widgetKey","endpoint","configResponse","fetch","method","headers","then","response","json","catch","error","console","log","config","apiKey","settings","bodyActionButtons","footerActionButtons","nextBestActions","apiHost","widgetMode","widgetType","transformConfig","version","default","widget","import","Common.WidgetType","SearchWidget","initStandard","HelpWidget","initPopup","window","Brainfish","Common.injectBrainfishInWindow"],"mappings":"aAAO,IAAIA,ECUAC,GDTX,SAAWD,GACPA,EAAoB,QAAI,UACxBA,EAAsB,UAAI,WAC7B,CAHD,CAGGA,IAAeA,EAAa,CAAE,IAG5BA,EAAWE,QACXF,EAAWG,UCGhB,SAAWF,GACPA,EAAiB,KAAI,OACrBA,EAAqB,SAAI,WACzBA,EAAkB,MAAI,QACtBA,EAAkB,MAAI,OACzB,CALD,CAKGA,IAAeA,EAAa,CAAA,IChBxB,MCKDG,EAAW,yBAEjB,SAASC,EACPC,GAEO,OAAAA,EAAcC,KAAKC,GACpBA,EAAOC,OAASC,EAAkBC,SAC7B,IACFH,EACHI,MAAO,IAAIC,SAAS,UAAUL,EAAOI,QAA9B,IAGJJ,GAEX,CAEA,MA0EMM,EAAY,CAChBC,QAAS,CAAEC,KA7CAC,OAASC,gBACd,MAAAC,EAAW,GAAGf,qCAEdgB,QAAuBC,MAAMF,EAAU,CAC3CG,OAAQ,OACRC,QAAS,CACP,eAAgB,mBAChB,UAAWL,KAGZM,MAAMC,GAAaA,EAASC,SAC5BC,OAAOC,GAAUC,QAAQC,IAAI,8BAA+BF,KAE/D,IAAKR,EAEH,YADAS,QAAQC,IAAI,+BAKd,MAAMC,EAjDgB,GACtBA,SACAC,aAKMD,EAAOE,UAAUC,oBACrBH,EAAOE,SAASC,kBAAoB7B,EAClC0B,EAAOE,SAASC,oBAGdH,EAAOE,UAAUE,sBACrBJ,EAAOE,SAASE,oBAAsB9B,EACpC0B,EAAOE,SAASE,sBAGdJ,EAAOE,UAAUG,kBACrBL,EAAOE,SAASG,gBAAkB/B,EAChC0B,EAAOE,SAASG,kBAGb,IACFL,EACHM,QAAS,GAAGjC,IACZkC,WAAYP,EAAOQ,WACnBP,WAuBaQ,CAAgB,CAC7BT,OAAQX,EAAeW,OACvBC,OAAQd,IAEJuB,EAAUV,EAAOU,SAAW,UAG1BC,QAASC,SAAiBC,OAChC,4DAA4DH,iBAG9D,OAAQV,EAAOQ,YACb,KAAKM,EAAkB1C,UACvB,IAAK,SACIwC,EAAAG,aAAaC,aAAahB,GACjC,MACF,KAAKc,EAAkB3C,QACvB,IAAK,aACIyC,EAAAK,WAAWC,UAAUlB,GAC5B,MACF,QACE,OACJ,IAOEjB,GDnGmC,CAACA,IACd,oBAAXoC,SAEPA,OAAOC,UACPD,OAAOC,UAAY,IAAKD,OAAOC,aAAcrC,GAG7CoC,OAAOC,UAAY,IAAKrC,GAC3B,EC4FHsC,CAA+BtC"}
|
package/dist/web.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var t,e;!function(t){t.Sidebar="sidebar",t.Searchbar="searchbar"}(t||(t={})),t.Sidebar,t.Searchbar,function(t){t.LINK="link",t.CALLBACK="callback",t.EMAIL="email",t.PHONE="phone"}(e||(e={}));const i="https://app.brainfi.sh";function n(t){return t.map((t=>t.type===e.CALLBACK?{...t,value:new Function(`return ${t.value}`)()}:t))}const o={Widgets:{init:async({widgetKey:e})=>{const o=`${i}/api/searchWidgets.getConfigByKey`,s=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","api-key":e}}).then((t=>t.json())).catch((t=>console.log("Error loading widget config",t)));if(!s)return void console.log("Error loading widget config");const a=(({config:t,apiKey:e})=>(t.settings?.bodyActionButtons&&(t.settings.bodyActionButtons=n(t.settings.bodyActionButtons)),t.settings?.footerActionButtons&&(t.settings.footerActionButtons=n(t.settings.footerActionButtons)),t.settings?.nextBestActions&&(t.settings.nextBestActions=n(t.settings.nextBestActions)),{...t,apiHost:`${i}`,widgetMode:t.widgetType,apiKey:e}))({config:s.config,apiKey:e}),r=a.version||"latest",{default:c}=await import(`https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${r}/dist/web.js`);switch(a.widgetType){case t.Searchbar:case"Search":c.SearchWidget.initStandard(a);break;case t.Sidebar:case"slide-over":c.HelpWidget.initPopup(a);break;default:return}}}};o&&(t=>{"undefined"!=typeof window&&(window.Brainfish?window.Brainfish={...window.Brainfish,...t}:window.Brainfish={...t})})(o);export{o as default};
|
|
2
|
-
//# sourceMappingURL=web.js.map
|
package/dist/web.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sources":["../../common/dist/types/brainfish.js","../../common/dist/types/config.js","../../common/dist/window/inject-brainfish.js","../src/web.ts"],"sourcesContent":["export var WidgetType;\n(function (WidgetType) {\n WidgetType[\"Sidebar\"] = \"sidebar\";\n WidgetType[\"Searchbar\"] = \"searchbar\";\n})(WidgetType || (WidgetType = {}));\n;\nexport const WIDGET_NAMES = {\n [WidgetType.Sidebar]: 'brainfish-sidebar-widget',\n [WidgetType.Searchbar]: 'brainfish-searchbar-widget',\n};\n","const isUrlString = (value) => {\n const urlRegExp = /^(https?|ftp):\\/\\/[^\\s/$.?#].[^\\s]*$/i;\n return urlRegExp.test(value);\n};\nexport const validateUrlString = (value) => {\n if (!isUrlString(value)) {\n throw new Error(`Invalid URL: ${value}`);\n }\n return value;\n};\nexport var ActionType;\n(function (ActionType) {\n ActionType[\"LINK\"] = \"link\";\n ActionType[\"CALLBACK\"] = \"callback\";\n ActionType[\"EMAIL\"] = \"email\";\n ActionType[\"PHONE\"] = \"phone\";\n})(ActionType || (ActionType = {}));\n","export const injectBrainfishInWindow = (brainfish) => {\n if (typeof window === 'undefined')\n return;\n if (window.Brainfish) {\n window.Brainfish = { ...window.Brainfish, ...brainfish };\n }\n else {\n window.Brainfish = { ...brainfish };\n }\n};\n","// web.ts\n// entry point for web component\nimport * as Common from '@brainfish-ai/widgets-common';\nimport { Config, CallbackAction, Action } from '@brainfish-ai/widgets-common';\n\nconst API_HOST = import.meta.env.VITE_API_HOST;\n\nfunction mapActionButtons(\n actionButtons: (CallbackAction | Action)[]\n): (CallbackAction | Action)[] {\n return actionButtons.map((action) => {\n if (action.type === Common.ActionType.CALLBACK) {\n return {\n ...action,\n value: new Function(`return ${action.value}`)(),\n };\n }\n return action;\n });\n}\n\nconst transformConfig = ({\n config,\n apiKey,\n}: {\n config: Config;\n apiKey: string;\n}) => {\n if (!!config.settings?.bodyActionButtons) {\n config.settings.bodyActionButtons = mapActionButtons(\n config.settings.bodyActionButtons\n );\n }\n if (!!config.settings?.footerActionButtons) {\n config.settings.footerActionButtons = mapActionButtons(\n config.settings.footerActionButtons\n );\n }\n if (!!config.settings?.nextBestActions) {\n config.settings.nextBestActions = mapActionButtons(\n config.settings.nextBestActions\n );\n }\n return {\n ...config,\n apiHost: `${API_HOST}`,\n widgetMode: config.widgetType,\n apiKey,\n };\n};\n\nconst init = async ({ widgetKey }: { widgetKey: string }) => {\n const endpoint = `${API_HOST}/api/searchWidgets.getConfigByKey`;\n\n const configResponse = await fetch(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'api-key': widgetKey,\n },\n })\n .then((response) => response.json())\n .catch((error) => console.log('Error loading widget config', error));\n\n if (!configResponse) {\n console.log('Error loading widget config');\n return;\n }\n\n // const { config }: { config: Config } = configResponse;\n const config = transformConfig({\n config: configResponse.config,\n apiKey: widgetKey,\n });\n const version = config.version || 'latest';\n\n // import the widget based on the version from cdn.jsdelivr.net\n const { default: widget } = await import(\n `https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${version}/dist/web.js`\n );\n\n switch (config.widgetType) {\n case Common.WidgetType.Searchbar:\n case 'Search':\n widget.SearchWidget.initStandard(config);\n break;\n case Common.WidgetType.Sidebar:\n case 'slide-over': // for backwards compatibility\n widget.HelpWidget.initPopup(config);\n break;\n default:\n return;\n }\n};\n\nconst brainfish = {\n Widgets: { init }\n}\n\nif (brainfish) {\n Common.injectBrainfishInWindow(brainfish);\n}\n\nexport default brainfish;\n"],"names":["WidgetType","ActionType","Sidebar","Searchbar","API_HOST","mapActionButtons","actionButtons","map","action","type","Common.ActionType","CALLBACK","value","Function","brainfish","Widgets","init","async","widgetKey","endpoint","configResponse","fetch","method","headers","then","response","json","catch","error","console","log","config","apiKey","settings","bodyActionButtons","footerActionButtons","nextBestActions","apiHost","widgetMode","widgetType","transformConfig","version","default","widget","import","Common.WidgetType","SearchWidget","initStandard","HelpWidget","initPopup","window","Brainfish","Common.injectBrainfishInWindow"],"mappings":"AAAO,IAAIA,ECUAC,GDTX,SAAWD,GACPA,EAAoB,QAAI,UACxBA,EAAsB,UAAI,WAC7B,CAHD,CAGGA,IAAeA,EAAa,CAAE,IAG5BA,EAAWE,QACXF,EAAWG,UCGhB,SAAWF,GACPA,EAAiB,KAAI,OACrBA,EAAqB,SAAI,WACzBA,EAAkB,MAAI,QACtBA,EAAkB,MAAI,OACzB,CALD,CAKGA,IAAeA,EAAa,CAAA,IChBxB,MCKDG,EAAW,yBAEjB,SAASC,EACPC,GAEO,OAAAA,EAAcC,KAAKC,GACpBA,EAAOC,OAASC,EAAkBC,SAC7B,IACFH,EACHI,MAAO,IAAIC,SAAS,UAAUL,EAAOI,QAA9B,IAGJJ,GAEX,CAEA,MA0EMM,EAAY,CAChBC,QAAS,CAAEC,KA7CAC,OAASC,gBACd,MAAAC,EAAW,GAAGf,qCAEdgB,QAAuBC,MAAMF,EAAU,CAC3CG,OAAQ,OACRC,QAAS,CACP,eAAgB,mBAChB,UAAWL,KAGZM,MAAMC,GAAaA,EAASC,SAC5BC,OAAOC,GAAUC,QAAQC,IAAI,8BAA+BF,KAE/D,IAAKR,EAEH,YADAS,QAAQC,IAAI,+BAKd,MAAMC,EAjDgB,GACtBA,SACAC,aAKMD,EAAOE,UAAUC,oBACrBH,EAAOE,SAASC,kBAAoB7B,EAClC0B,EAAOE,SAASC,oBAGdH,EAAOE,UAAUE,sBACrBJ,EAAOE,SAASE,oBAAsB9B,EACpC0B,EAAOE,SAASE,sBAGdJ,EAAOE,UAAUG,kBACrBL,EAAOE,SAASG,gBAAkB/B,EAChC0B,EAAOE,SAASG,kBAGb,IACFL,EACHM,QAAS,GAAGjC,IACZkC,WAAYP,EAAOQ,WACnBP,WAuBaQ,CAAgB,CAC7BT,OAAQX,EAAeW,OACvBC,OAAQd,IAEJuB,EAAUV,EAAOU,SAAW,UAG1BC,QAASC,SAAiBC,OAChC,4DAA4DH,iBAG9D,OAAQV,EAAOQ,YACb,KAAKM,EAAkB1C,UACvB,IAAK,SACIwC,EAAAG,aAAaC,aAAahB,GACjC,MACF,KAAKc,EAAkB3C,QACvB,IAAK,aACIyC,EAAAK,WAAWC,UAAUlB,GAC5B,MACF,QACE,OACJ,IAOEjB,GDnGmC,CAACA,IACd,oBAAXoC,SAEPA,OAAOC,UACPD,OAAOC,UAAY,IAAKD,OAAOC,aAAcrC,GAG7CoC,OAAOC,UAAY,IAAKrC,GAC3B,EC4FHsC,CAA+BtC"}
|
package/index.html
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<meta name="theme-color" content="#000000" />
|
|
7
|
-
<link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" />
|
|
8
|
-
<title>Solid App</title>
|
|
9
|
-
<style>
|
|
10
|
-
body {
|
|
11
|
-
background: #666;
|
|
12
|
-
}
|
|
13
|
-
</style>
|
|
14
|
-
<script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js"></script>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<!-- WIDGET INITIATOR - BEGINS -->
|
|
18
|
-
<script type="module">
|
|
19
|
-
// import Brainfish from '/dist/web.js';
|
|
20
|
-
import Brainfish from '/src/web.ts';
|
|
21
|
-
Brainfish.Widgets.init({ widgetKey: "bf_search_widget_QO3mYiUZRYX78ztRhNC4zH3R5iQ0E3sgRwunjz" }); // Replace with your sidebar widget key
|
|
22
|
-
Brainfish.Widgets.init({ widgetKey: "bf_search_widget_CPvciWdjZMXMhKJfEGNvno7oqHkOVjc3rRaHz7" }); // Replace with your searchbar widget key
|
|
23
|
-
</script>
|
|
24
|
-
<script src="https://unpkg.com/@phosphor-icons/web" async></script>
|
|
25
|
-
<style>
|
|
26
|
-
.brainfish-trigger-button {
|
|
27
|
-
position: fixed;
|
|
28
|
-
border-radius: 24px 4px 16px 24px;
|
|
29
|
-
height: 32px !important;
|
|
30
|
-
padding: 0 10px;
|
|
31
|
-
width: unset !important;
|
|
32
|
-
bottom: 40px;
|
|
33
|
-
right: 40px;
|
|
34
|
-
background-color: #501ec4 !important;
|
|
35
|
-
color: #FFF;
|
|
36
|
-
text-align: center;
|
|
37
|
-
box-shadow: 2px 2px 3px #999;
|
|
38
|
-
cursor: pointer;
|
|
39
|
-
z-index: 9995;
|
|
40
|
-
border: none;
|
|
41
|
-
display: flex;
|
|
42
|
-
align-items: center;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.ph {
|
|
46
|
-
font-size: 18px;
|
|
47
|
-
margin-right: 5px;
|
|
48
|
-
}
|
|
49
|
-
</style>
|
|
50
|
-
<!-- WIDGET INITIATOR - ENDS -->
|
|
51
|
-
</head>
|
|
52
|
-
<body style="display: flex">
|
|
53
|
-
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
54
|
-
<div id="root"></div>
|
|
55
|
-
<main style="width:80%">
|
|
56
|
-
<brainfish-search-widget />
|
|
57
|
-
</main>
|
|
58
|
-
<aside style="width: 20%">
|
|
59
|
-
<button class="brainfish-trigger-button" onClick="Brainfish.HelpWidget.open('brainfish-trigger-button')"><i
|
|
60
|
-
class="ph ph-question"></i>Help</button>
|
|
61
|
-
</aside>
|
|
62
|
-
</body>
|
|
63
|
-
</html>
|
package/postcss.config.cjs
DELETED
package/src/register.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// registers the web components
|
|
2
|
-
import { customElement } from "solid-element";
|
|
3
|
-
import { WIDGET_NAMES, WidgetType } from "./types/brainfish";
|
|
4
|
-
import SearchBar from './widgets/search-bar';
|
|
5
|
-
import Sidebar from "./widgets/sidebar";
|
|
6
|
-
import { SearchbarProps, SidebarProps } from "./widgets/initialize";
|
|
7
|
-
|
|
8
|
-
export function registerSearchBarWebComponent() {
|
|
9
|
-
if (typeof window === "undefined")
|
|
10
|
-
return false;
|
|
11
|
-
customElement(WIDGET_NAMES[WidgetType.Searchbar], getInitialSearchbarProps(), SearchBar);
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function registerSidebarWebComponent() {
|
|
16
|
-
if (typeof window === "undefined")
|
|
17
|
-
return false;
|
|
18
|
-
customElement(WIDGET_NAMES[WidgetType.Sidebar], getInitialSidebarProps(), Sidebar);
|
|
19
|
-
debugger;
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getInitialSidebarProps(): SidebarProps {
|
|
24
|
-
return {
|
|
25
|
-
widgetMode: 'sidebar'
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getInitialSearchbarProps(): SearchbarProps {
|
|
30
|
-
return {};
|
|
31
|
-
}
|
package/src/web.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// web.ts
|
|
2
|
-
// entry point for web component
|
|
3
|
-
import * as Common from '@brainfish-ai/widgets-common';
|
|
4
|
-
import { Config, CallbackAction, Action } from '@brainfish-ai/widgets-common';
|
|
5
|
-
|
|
6
|
-
const API_HOST = import.meta.env.VITE_API_HOST;
|
|
7
|
-
|
|
8
|
-
function mapActionButtons(
|
|
9
|
-
actionButtons: (CallbackAction | Action)[]
|
|
10
|
-
): (CallbackAction | Action)[] {
|
|
11
|
-
return actionButtons.map((action) => {
|
|
12
|
-
if (action.type === Common.ActionType.CALLBACK) {
|
|
13
|
-
return {
|
|
14
|
-
...action,
|
|
15
|
-
value: new Function(`return ${action.value}`)(),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
return action;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const transformConfig = ({
|
|
23
|
-
config,
|
|
24
|
-
apiKey,
|
|
25
|
-
}: {
|
|
26
|
-
config: Config;
|
|
27
|
-
apiKey: string;
|
|
28
|
-
}) => {
|
|
29
|
-
if (!!config.settings?.bodyActionButtons) {
|
|
30
|
-
config.settings.bodyActionButtons = mapActionButtons(
|
|
31
|
-
config.settings.bodyActionButtons
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
if (!!config.settings?.footerActionButtons) {
|
|
35
|
-
config.settings.footerActionButtons = mapActionButtons(
|
|
36
|
-
config.settings.footerActionButtons
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
if (!!config.settings?.nextBestActions) {
|
|
40
|
-
config.settings.nextBestActions = mapActionButtons(
|
|
41
|
-
config.settings.nextBestActions
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
...config,
|
|
46
|
-
apiHost: `${API_HOST}`,
|
|
47
|
-
widgetMode: config.widgetType,
|
|
48
|
-
apiKey,
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const init = async ({ widgetKey }: { widgetKey: string }) => {
|
|
53
|
-
const endpoint = `${API_HOST}/api/searchWidgets.getConfigByKey`;
|
|
54
|
-
|
|
55
|
-
const configResponse = await fetch(endpoint, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
'Content-Type': 'application/json',
|
|
59
|
-
'api-key': widgetKey,
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
.then((response) => response.json())
|
|
63
|
-
.catch((error) => console.log('Error loading widget config', error));
|
|
64
|
-
|
|
65
|
-
if (!configResponse) {
|
|
66
|
-
console.log('Error loading widget config');
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// const { config }: { config: Config } = configResponse;
|
|
71
|
-
const config = transformConfig({
|
|
72
|
-
config: configResponse.config,
|
|
73
|
-
apiKey: widgetKey,
|
|
74
|
-
});
|
|
75
|
-
const version = config.version || 'latest';
|
|
76
|
-
|
|
77
|
-
// import the widget based on the version from cdn.jsdelivr.net
|
|
78
|
-
const { default: widget } = await import(
|
|
79
|
-
`https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${version}/dist/web.js`
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
switch (config.widgetType) {
|
|
83
|
-
case Common.WidgetType.Searchbar:
|
|
84
|
-
case 'Search':
|
|
85
|
-
widget.SearchWidget.initStandard(config);
|
|
86
|
-
break;
|
|
87
|
-
case Common.WidgetType.Sidebar:
|
|
88
|
-
case 'slide-over': // for backwards compatibility
|
|
89
|
-
widget.HelpWidget.initPopup(config);
|
|
90
|
-
break;
|
|
91
|
-
default:
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const brainfish = {
|
|
97
|
-
Widgets: { init }
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (brainfish) {
|
|
101
|
-
Common.injectBrainfishInWindow(brainfish);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default brainfish;
|
package/tailwind.config.cjs
DELETED
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"jsx": "preserve",
|
|
10
|
-
"jsxImportSource": "solid-js",
|
|
11
|
-
"types": ["vite/client"],
|
|
12
|
-
"baseUrl": "."
|
|
13
|
-
}
|
|
14
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import solidPlugin from 'vite-plugin-solid';
|
|
3
|
-
import { terser } from 'rollup-plugin-terser';
|
|
4
|
-
import replace from '@rollup/plugin-replace';
|
|
5
|
-
import dotenv from 'dotenv';
|
|
6
|
-
|
|
7
|
-
const env = dotenv.config().parsed as { [key: string]: string };
|
|
8
|
-
|
|
9
|
-
export default defineConfig({
|
|
10
|
-
plugins: [
|
|
11
|
-
solidPlugin(),
|
|
12
|
-
replace({
|
|
13
|
-
values: {
|
|
14
|
-
'import.meta.env.VITE_API_HOST': JSON.stringify(env['VITE_API_HOST']),
|
|
15
|
-
'?inline': '',
|
|
16
|
-
},
|
|
17
|
-
preventAssignment: true,
|
|
18
|
-
}),
|
|
19
|
-
],
|
|
20
|
-
build: {
|
|
21
|
-
target: 'esnext',
|
|
22
|
-
sourcemap: true,
|
|
23
|
-
lib: {
|
|
24
|
-
entry: 'src/web.ts',
|
|
25
|
-
formats: ['es', 'cjs'],
|
|
26
|
-
fileName: (format) => `web${format === 'es' ? '' : '.cjs'}.js`,
|
|
27
|
-
},
|
|
28
|
-
minify: false,
|
|
29
|
-
rollupOptions: {
|
|
30
|
-
plugins: [terser()],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
});
|