@brainfish-ai/widgets-initiator 0.0.1

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/.env ADDED
@@ -0,0 +1 @@
1
+ VITE_API_HOST=http://localhost:3000
@@ -0,0 +1,7 @@
1
+ # Ignore
2
+ infrastructure
3
+ releases
4
+ dist
5
+
6
+ # Ignore all HTML files:
7
+ *.html
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "tabWidth": 2,
3
+ "useTabs": false,
4
+ "singleQuote": true,
5
+ "jsxSingleQuote": false
6
+ }
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # A template for [SolidJS](https://github.com/solidjs/solid) with [TailwindCSS](https://github.com/tailwindlabs/tailwindcss) and [Animate.css](https://github.com/animate-css/animate.css).
2
+
3
+ Forked from the SolidJS [vite typescript starter template](https://github.com/solidjs/templates/tree/master/ts)
4
+
5
+ ## Usage
6
+
7
+ Those templates dependencies are maintained via [pnpm](https://pnpm.io) via `pnpm up -Lri`.
8
+
9
+ This is the reason you see a `pnpm-lock.yaml`. That being said, any package manager will work. This file can be safely be removed once you clone a template.
10
+
11
+ ```bash
12
+ $ npm install # or pnpm install or yarn install
13
+ ```
14
+
15
+ ## Available Scripts
16
+
17
+ In the project directory, you can run:
18
+
19
+ ### `npm dev` or `npm start`
20
+
21
+ Runs the app in the development mode.<br>
22
+ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
23
+
24
+ The page will reload if you make edits.<br>
25
+
26
+ ### `npm run build`
27
+
28
+ Builds the app for production to the `dist` folder.<br>
29
+ It correctly bundles Solid in production mode and optimizes the build for the best performance.
30
+
31
+ The build is minified and the filenames include the hashes.<br>
32
+ Your app is ready to be deployed!
33
+
34
+ ## Deployment
35
+
36
+ You can deploy the `dist` folder to any static host provider (netlify, surge, now, etc.)
37
+
38
+
39
+ ## Available Scripts
40
+
41
+ In the project directory, you can run:
42
+
43
+ ### `npm dev` or `npm start`
44
+
45
+ Runs the app in the development mode.<br>
46
+ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
47
+
48
+ The page will reload if you make edits.<br>
49
+
50
+ ### `npm run build`
51
+
52
+ Builds the app for production to the `dist` folder.<br>
53
+ It correctly bundles Solid in production mode and optimizes the build for the best performance.
54
+
55
+ The build is minified and the filenames include the hashes.<br>
56
+ Your app is ready to be deployed!
57
+
58
+ ## Deployment
59
+
60
+ You can deploy the `dist` folder to any static host provider (netlify, surge, now, etc.)
61
+ # brainfish-widgets
@@ -0,0 +1,2 @@
1
+ "use strict";var i;!function(i){i.Sidebar="sidebar",i.Searchbar="searchbar"}(i||(i={})),i.Sidebar,i.Searchbar;const e={Widgets:{init:async({widgetKey:e})=>{const a=await fetch("http://localhost:3000/api/searchWidgets.getConfigByKey",{method:"POST",headers:{"Content-Type":"application/json","api-key":e}}).then((i=>i.json())).catch((i=>console.log("Error loading widget config",i)));if(!a)return void console.log("Error loading widget config");const{config:t}=a,n=t.version||"latest",{default:r}=await import(`https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${n}/dist/web.js`);switch(t.widgetMode){case i.Searchbar:r.SearchWidget.initStandard(t);break;case i.Sidebar:case"slide-over":r.HelpWidget.initPopup(t);break;default:return}}}};e&&(i=>{"undefined"!=typeof window&&(window.Brainfish?window.Brainfish={...window.Brainfish,...i}:window.Brainfish={...i})})(e),module.exports=e;
2
+ //# sourceMappingURL=web.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.cjs.js","sources":["../../common/dist/types/brainfish.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","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/brainfish-widgets-common';\n\nconst init = async ({ widgetKey }: { widgetKey: string }) => {\n const API_HOST = import.meta.env.VITE_API_HOST || 'http://localhost:3000';\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 } = configResponse;\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.widgetMode) {\n case Common.WidgetType.Searchbar:\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","Sidebar","Searchbar","brainfish","Widgets","init","async","widgetKey","configResponse","fetch","method","headers","then","response","json","catch","error","console","log","config","version","default","widget","import","widgetMode","Common.WidgetType","SearchWidget","initStandard","HelpWidget","initPopup","window","Brainfish","Common.injectBrainfishInWindow"],"mappings":"aAAO,IAAIA,GACX,SAAWA,GACPA,EAAoB,QAAI,UACxBA,EAAsB,UAAI,WAC7B,CAHD,CAGGA,IAAeA,EAAa,CAAE,IAG5BA,EAAWC,QACXD,EAAWE,UCRT,MC4CDC,EAAY,CAChBC,QAAS,CAAEC,KAzCAC,OAASC,gBACd,MAGAC,QAAuBC,MAFZ,yDAE4B,CAC3CC,OAAQ,OACRC,QAAS,CACP,eAAgB,mBAChB,UAAWJ,KAGZK,MAAMC,GAAaA,EAASC,SAC5BC,OAAOC,GAAUC,QAAQC,IAAI,8BAA+BF,KAE/D,IAAKR,EAEH,YADAS,QAAQC,IAAI,+BAIR,MAAAC,OAAEA,GAAWX,EACbY,EAAUD,EAAOC,SAAW,UAG1BC,QAASC,SAAiBC,OAChC,4DAA4DH,iBAG9D,OAAQD,EAAOK,YACb,KAAKC,EAAkBvB,UACdoB,EAAAI,aAAaC,aAAaR,GACjC,MACF,KAAKM,EAAkBxB,QACvB,IAAK,aACIqB,EAAAM,WAAWC,UAAUV,GAC5B,MACF,QACE,OACJ,IAOEhB,GDhDmC,CAACA,IACd,oBAAX2B,SAEPA,OAAOC,UACPD,OAAOC,UAAY,IAAKD,OAAOC,aAAc5B,GAG7C2B,OAAOC,UAAY,IAAK5B,GAC3B,ECyCH6B,CAA+B7B"}
package/dist/web.js ADDED
@@ -0,0 +1,2 @@
1
+ var i;!function(i){i.Sidebar="sidebar",i.Searchbar="searchbar"}(i||(i={})),i.Sidebar,i.Searchbar;const e={Widgets:{init:async({widgetKey:e})=>{const a=await fetch("http://localhost:3000/api/searchWidgets.getConfigByKey",{method:"POST",headers:{"Content-Type":"application/json","api-key":e}}).then((i=>i.json())).catch((i=>console.log("Error loading widget config",i)));if(!a)return void console.log("Error loading widget config");const{config:t}=a,n=t.version||"latest",{default:r}=await import(`https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${n}/dist/web.js`);switch(t.widgetMode){case i.Searchbar:r.SearchWidget.initStandard(t);break;case i.Sidebar:case"slide-over":r.HelpWidget.initPopup(t);break;default:return}}}};e&&(i=>{"undefined"!=typeof window&&(window.Brainfish?window.Brainfish={...window.Brainfish,...i}:window.Brainfish={...i})})(e);export{e as default};
2
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sources":["../../common/dist/types/brainfish.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","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/brainfish-widgets-common';\n\nconst init = async ({ widgetKey }: { widgetKey: string }) => {\n const API_HOST = import.meta.env.VITE_API_HOST || 'http://localhost:3000';\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 } = configResponse;\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.widgetMode) {\n case Common.WidgetType.Searchbar:\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","Sidebar","Searchbar","brainfish","Widgets","init","async","widgetKey","configResponse","fetch","method","headers","then","response","json","catch","error","console","log","config","version","default","widget","import","widgetMode","Common.WidgetType","SearchWidget","initStandard","HelpWidget","initPopup","window","Brainfish","Common.injectBrainfishInWindow"],"mappings":"AAAO,IAAIA,GACX,SAAWA,GACPA,EAAoB,QAAI,UACxBA,EAAsB,UAAI,WAC7B,CAHD,CAGGA,IAAeA,EAAa,CAAE,IAG5BA,EAAWC,QACXD,EAAWE,UCRT,MC4CDC,EAAY,CAChBC,QAAS,CAAEC,KAzCAC,OAASC,gBACd,MAGAC,QAAuBC,MAFZ,yDAE4B,CAC3CC,OAAQ,OACRC,QAAS,CACP,eAAgB,mBAChB,UAAWJ,KAGZK,MAAMC,GAAaA,EAASC,SAC5BC,OAAOC,GAAUC,QAAQC,IAAI,8BAA+BF,KAE/D,IAAKR,EAEH,YADAS,QAAQC,IAAI,+BAIR,MAAAC,OAAEA,GAAWX,EACbY,EAAUD,EAAOC,SAAW,UAG1BC,QAASC,SAAiBC,OAChC,4DAA4DH,iBAG9D,OAAQD,EAAOK,YACb,KAAKC,EAAkBvB,UACdoB,EAAAI,aAAaC,aAAaR,GACjC,MACF,KAAKM,EAAkBxB,QACvB,IAAK,aACIqB,EAAAM,WAAWC,UAAUV,GAC5B,MACF,QACE,OACJ,IAOEhB,GDhDmC,CAACA,IACd,oBAAX2B,SAEPA,OAAOC,UACPD,OAAOC,UAAY,IAAKD,OAAOC,aAAc5B,GAG7C2B,OAAOC,UAAY,IAAK5B,GAC3B,ECyCH6B,CAA+B7B"}
package/index.html ADDED
@@ -0,0 +1,55 @@
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
+
15
+ <!-- WIDGET INITIATOR - BEGINS -->
16
+ <script type="module">
17
+ // import Brainfish from '/dist/web.js';
18
+ import Brainfish from '/src/web.ts';
19
+ Brainfish.Widgets.init({ widgetKey: "bf_search_widget_QO3mYiUZRYX78ztRhNC4zH3R5iQ0E3sgRwunjz" })
20
+ </script>
21
+ <script src="https://unpkg.com/@phosphor-icons/web" async></script>
22
+ <style>
23
+ .brainfish-trigger-button {
24
+ position: fixed;
25
+ border-radius: 24px 4px 16px 24px;
26
+ height: 32px !important;
27
+ padding: 0 10px;
28
+ width: unset !important;
29
+ bottom: 40px;
30
+ right: 40px;
31
+ background-color: #501ec4 !important;
32
+ color: #FFF;
33
+ text-align: center;
34
+ box-shadow: 2px 2px 3px #999;
35
+ cursor: pointer;
36
+ z-index: 9995;
37
+ border: none;
38
+ display: flex;
39
+ align-items: center;
40
+ }
41
+
42
+ .ph {
43
+ font-size: 18px;
44
+ margin-right: 5px;
45
+ }
46
+ </style>
47
+ <!-- WIDGET INITIATOR - ENDS -->
48
+ </head>
49
+ <body>
50
+ <noscript>You need to enable JavaScript to run this app.</noscript>
51
+ <div id="root"></div>
52
+
53
+ <button class="brainfish-trigger-button" onClick="Brainfish.HelpWidget.open('brainfish-trigger-button')"><i class="ph ph-question"></i>Help</button>
54
+ </body>
55
+ </html>
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@brainfish-ai/widgets-initiator",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "Brainfish Widgets Initiator",
7
+ "type": "module",
8
+ "private": false,
9
+ "scripts": {
10
+ "start": "vite",
11
+ "dev": "vite",
12
+ "build": "vite build",
13
+ "serve": "vite preview --port 6006"
14
+ },
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "@brainfish-ai/widgets-common": "^0.0.1",
18
+ "animated-tailwindcss": "^4.0.0",
19
+ "autoprefixer": "^10.4.16",
20
+ "postcss": "^8.4.31",
21
+ "rollup-plugin-terser": "^7.0.2",
22
+ "tailwindcss": "^3.3.5",
23
+ "typescript": "^5.2.2",
24
+ "vite": "^4.5.0",
25
+ "vite-plugin-solid": "^2.7.2"
26
+ },
27
+ "dependencies": {
28
+ "@fingerprintjs/fingerprintjs": "^4.2.1",
29
+ "lodash": "^4.17.21",
30
+ "phosphor-solid": "^1.1.5",
31
+ "solid-element": "1.8.0",
32
+ "solid-js": "^1.8.5"
33
+ },
34
+ "keywords": [
35
+ "typescript",
36
+ "solidjs",
37
+ "tailwind",
38
+ "tailwindcss",
39
+ "animate"
40
+ ]
41
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ }
@@ -0,0 +1,31 @@
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 ADDED
@@ -0,0 +1,53 @@
1
+ // web.ts
2
+ // entry point for web component
3
+ import * as Common from '@brainfish-ai/widgets-common';
4
+
5
+ const init = async ({ widgetKey }: { widgetKey: string }) => {
6
+ const API_HOST = import.meta.env.VITE_API_HOST || 'http://localhost:3000';
7
+ const endpoint = `${API_HOST}/api/searchWidgets.getConfigByKey`;
8
+
9
+ const configResponse = await fetch(endpoint, {
10
+ method: 'POST',
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ 'api-key': widgetKey,
14
+ },
15
+ })
16
+ .then((response) => response.json())
17
+ .catch((error) => console.log('Error loading widget config', error));
18
+
19
+ if (!configResponse) {
20
+ console.log('Error loading widget config');
21
+ return;
22
+ }
23
+
24
+ const { config } = configResponse;
25
+ const version = config.version || 'latest';
26
+
27
+ // import the widget based on the version from cdn.jsdelivr.net
28
+ const { default: widget } = await import(
29
+ `https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${version}/dist/web.js`
30
+ );
31
+
32
+ switch (config.widgetMode) {
33
+ case Common.WidgetType.Searchbar:
34
+ widget.SearchWidget.initStandard(config);
35
+ break;
36
+ case Common.WidgetType.Sidebar:
37
+ case 'slide-over': // for backwards compatibility
38
+ widget.HelpWidget.initPopup(config);
39
+ break;
40
+ default:
41
+ return;
42
+ }
43
+ };
44
+
45
+ const brainfish = {
46
+ Widgets: { init }
47
+ }
48
+
49
+ if (brainfish) {
50
+ Common.injectBrainfishInWindow(brainfish);
51
+ }
52
+
53
+ export default brainfish;
@@ -0,0 +1,9 @@
1
+ const { withAnimations } = require('animated-tailwindcss')
2
+
3
+ module.exports = withAnimations({
4
+ content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
5
+ theme: {
6
+ extend: {}
7
+ },
8
+ plugins: []
9
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
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
+ "paths": {
14
+ "@brainfish-ai/widgets-common": [
15
+ "./node_modules/@brainfish-ai/widgets-common"
16
+ ]
17
+ }
18
+ },
19
+ "include": ["./src/**/*", "./node_modules/@brainfish-ai/widgets-common"]
20
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'vite';
2
+ import solidPlugin from 'vite-plugin-solid';
3
+ import { terser } from 'rollup-plugin-terser';
4
+
5
+ export default defineConfig({
6
+ plugins: [solidPlugin()],
7
+ build: {
8
+ target: 'esnext',
9
+ sourcemap: true,
10
+ lib: {
11
+ entry: 'src/web.ts',
12
+ formats: ['es', 'cjs'],
13
+ fileName: (format) => `web${format === 'es' ? '' : '.cjs'}.js`,
14
+ },
15
+ minify: false,
16
+ rollupOptions: {
17
+ plugins: [terser()],
18
+ },
19
+ },
20
+ });