@inditeai/react 0.0.1 → 0.0.3
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/Bubble.d.ts +2 -1
- package/dist/Bubble.d.ts.map +1 -1
- package/dist/Popup.d.ts +2 -1
- package/dist/Popup.d.ts.map +1 -1
- package/dist/Standard.d.ts +2 -1
- package/dist/Standard.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/package.json +7 -5
- package/src/Bubble.tsx +51 -0
- package/src/Popup.tsx +56 -0
- package/src/Standard.tsx +34 -0
- package/src/index.ts +4 -0
- package/dist/stories/bubble.stories.d.ts +0 -2
- package/dist/stories/bubble.stories.d.ts.map +0 -1
- package/dist/stories/popup.stories.d.ts +0 -2
- package/dist/stories/popup.stories.d.ts.map +0 -1
- package/dist/stories/standard.stories.d.ts +0 -3
- package/dist/stories/standard.stories.d.ts.map +0 -1
package/dist/Bubble.d.ts
CHANGED
package/dist/Bubble.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bubble.d.ts","sourceRoot":"","sources":["../src/Bubble.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Bubble.d.ts","sourceRoot":"","sources":["../src/Bubble.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,uBAAuB,CAAA;AAE9B,KAAK,KAAK,GAAG,WAAW,CAAA;AAExB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,YAAY,EAAE,KAAK,CAAC,iBAAiB,CACnC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,WAAW,CACZ,CAAA;SACF;KACF;CACF;AAID,eAAO,MAAM,MAAM,UAAW,KAAK,SA6BlC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/Popup.d.ts
CHANGED
package/dist/Popup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../src/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../src/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,uBAAuB,CAAA;AAE9B,KAAK,KAAK,GAAG,UAAU,CAAA;AAEvB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,WAAW,EAAE,KAAK,CAAC,iBAAiB,CAClC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,WAAW,CACZ,GAAG;gBAAE,KAAK,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SACvB;KACF;CACF;AAID,eAAO,MAAM,KAAK,UAAW,KAAK,4CAkCjC,CAAA;AAED,eAAe,KAAK,CAAA"}
|
package/dist/Standard.d.ts
CHANGED
package/dist/Standard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Standard.d.ts","sourceRoot":"","sources":["../src/Standard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Standard.d.ts","sourceRoot":"","sources":["../src/Standard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,uBAAuB,CAAA;AAE9B,KAAK,KAAK,GAAG,QAAQ,GAAG;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,cAAc,EAAE,KAAK,CAAC,iBAAiB,CACrC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,WAAW,CACZ,GAAG;gBAAE,KAAK,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SACvB;KACF;CACF;AAID,eAAO,MAAM,QAAQ,6CAA8C,KAAK,4CASvE,CAAA;AAED,eAAe,QAAQ,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// v0.0.
|
|
2
|
-
import{jsx as
|
|
1
|
+
// v0.0.3
|
|
2
|
+
import{jsx as r}from"react/jsx-runtime";import{useRef as e,useEffect as t,useCallback as n}from"react";import"@inditeai/js/dist/web";export*from"@inditeai/js/dist";"function"==typeof SuppressedError&&SuppressedError;const o=n=>{var{style:o,className:c}=n,u=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]])}return t}(n,["style","className"]);const l=e(null);return t((()=>{l.current&&Object.assign(l.current,u)}),[u]),r("bot-standard",{ref:l,style:o,class:c})},c=r=>{const o=e(null),c=n((r=>{const e=document.createElement("bot-bubble");o.current=e,u(o.current,r),document.body.prepend(o.current)}),[]);t((()=>{o.current||c(r),u(o.current,r)}),[c,r]),t((()=>()=>{var r;null===(r=o.current)||void 0===r||r.remove(),o.current=null}),[]);const u=(r,e)=>{Object.assign(r,e)};return null},u=o=>{const c=e(null),u=e(null),l=n((r=>{var e;const t=document.createElement("bot-popup");u.current=t,s(u.current,r),c.current?null===(e=c.current)||void 0===e||e.append(u.current):console.warn("Could not attach popup to container because containerRef.current is null")}),[]);t((()=>{u.current||l(o),s(u.current,o)}),[l,o]),t((()=>()=>{var r;null===(r=u.current)||void 0===r||r.remove(),u.current=null}),[]);const s=(r,e)=>{Object.assign(r,e)};return r("div",{ref:c})};export{c as Bubble,u as Popup,o as Standard};
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inditeai/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Convenient library to display bots on your React app",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"stories:dev": "ladle serve -p 3006",
|
|
10
|
-
"stories:build": "ladle build",
|
|
11
9
|
"dev": "rollup --watch --config rollup.config.js",
|
|
12
10
|
"build": "rollup --config rollup.config.js",
|
|
13
11
|
"lint": "eslint --fix \"src/**/*.ts*\"",
|
|
14
12
|
"format:check": "prettier --check ./src"
|
|
15
13
|
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/Bacancy-DataProphets/Indite-packages.git"
|
|
17
|
+
},
|
|
16
18
|
"license": "MIT",
|
|
17
19
|
"dependencies": {
|
|
18
20
|
"@ladle/react": "2.5.1"
|
|
@@ -23,7 +25,7 @@
|
|
|
23
25
|
"@rollup/plugin-babel": "6.0.3",
|
|
24
26
|
"@rollup/plugin-node-resolve": "15.1.0",
|
|
25
27
|
"@rollup/plugin-terser": "0.4.3",
|
|
26
|
-
"@
|
|
28
|
+
"@inditeai/js": "1.2.0",
|
|
27
29
|
"@indite.io/lib": "workspace:*",
|
|
28
30
|
"@indite.io/prisma": "workspace:*",
|
|
29
31
|
"@indite.io/schemas": "workspace:*",
|
|
@@ -41,6 +43,6 @@
|
|
|
41
43
|
"@rollup/plugin-typescript": "11.1.2"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
|
-
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
46
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
45
47
|
}
|
|
46
48
|
}
|
package/src/Bubble.tsx
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import type { BubbleProps } from '@inditeai/js/dist'
|
|
3
|
+
import '@inditeai/js/dist/web'
|
|
4
|
+
|
|
5
|
+
type Props = BubbleProps
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
'bot-bubble': React.DetailedHTMLProps<
|
|
11
|
+
React.HTMLAttributes<HTMLElement>,
|
|
12
|
+
HTMLElement
|
|
13
|
+
>
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type BubbleElement = HTMLElement & Props
|
|
19
|
+
|
|
20
|
+
export const Bubble = (props: Props) => {
|
|
21
|
+
const bubbleElement = useRef<BubbleElement | null>(null)
|
|
22
|
+
|
|
23
|
+
const attachBubbleToDom = useCallback((props: Props) => {
|
|
24
|
+
const newBubbleElement = document.createElement(
|
|
25
|
+
'bot-bubble'
|
|
26
|
+
) as BubbleElement
|
|
27
|
+
bubbleElement.current = newBubbleElement
|
|
28
|
+
injectPropsToElement(bubbleElement.current, props)
|
|
29
|
+
document.body.prepend(bubbleElement.current)
|
|
30
|
+
}, [])
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!bubbleElement.current) attachBubbleToDom(props)
|
|
34
|
+
injectPropsToElement(bubbleElement.current as BubbleElement, props)
|
|
35
|
+
}, [attachBubbleToDom, props])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
bubbleElement.current?.remove()
|
|
40
|
+
bubbleElement.current = null
|
|
41
|
+
}
|
|
42
|
+
}, [])
|
|
43
|
+
|
|
44
|
+
const injectPropsToElement = (element: BubbleElement, props: Props) => {
|
|
45
|
+
Object.assign(element, props)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default Bubble
|
package/src/Popup.tsx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import type { PopupProps } from '@inditeai/js/dist'
|
|
3
|
+
import '@inditeai/js/dist/web'
|
|
4
|
+
|
|
5
|
+
type Props = PopupProps
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
'bot-popup': React.DetailedHTMLProps<
|
|
11
|
+
React.HTMLAttributes<HTMLElement>,
|
|
12
|
+
HTMLElement
|
|
13
|
+
> & { class?: string }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type PopupElement = HTMLElement & Props
|
|
19
|
+
|
|
20
|
+
export const Popup = (props: Props) => {
|
|
21
|
+
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
22
|
+
const popupRef = useRef<PopupElement | null>(null)
|
|
23
|
+
|
|
24
|
+
const attachPopupToContainer = useCallback((props: Props) => {
|
|
25
|
+
const popupElement = document.createElement('bot-popup') as PopupElement
|
|
26
|
+
popupRef.current = popupElement
|
|
27
|
+
injectPropsToElement(popupRef.current, props)
|
|
28
|
+
if (!containerRef.current) {
|
|
29
|
+
console.warn(
|
|
30
|
+
'Could not attach popup to container because containerRef.current is null'
|
|
31
|
+
)
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
containerRef.current?.append(popupRef.current)
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!popupRef.current) attachPopupToContainer(props)
|
|
39
|
+
injectPropsToElement(popupRef.current as PopupElement, props)
|
|
40
|
+
}, [attachPopupToContainer, props])
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
return () => {
|
|
44
|
+
popupRef.current?.remove()
|
|
45
|
+
popupRef.current = null
|
|
46
|
+
}
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
const injectPropsToElement = (element: PopupElement, props: Props) => {
|
|
50
|
+
Object.assign(element, props)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return <div ref={containerRef} />
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default Popup
|
package/src/Standard.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react'
|
|
2
|
+
import type { BotProps } from '@inditeai/js/dist'
|
|
3
|
+
import '@inditeai/js/dist/web'
|
|
4
|
+
|
|
5
|
+
type Props = BotProps & {
|
|
6
|
+
style?: React.CSSProperties
|
|
7
|
+
className?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
namespace JSX {
|
|
12
|
+
interface IntrinsicElements {
|
|
13
|
+
'bot-standard': React.DetailedHTMLProps<
|
|
14
|
+
React.HTMLAttributes<HTMLElement>,
|
|
15
|
+
HTMLElement
|
|
16
|
+
> & { class?: string }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type StandardElement = HTMLElement & Props
|
|
22
|
+
|
|
23
|
+
export const Standard = ({ style, className, ...assignableProps }: Props) => {
|
|
24
|
+
const ref = useRef<StandardElement | null>(null)
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!ref.current) return
|
|
28
|
+
Object.assign(ref.current, assignableProps)
|
|
29
|
+
}, [assignableProps])
|
|
30
|
+
|
|
31
|
+
return <bot-standard ref={ref} style={style} class={className} />
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default Standard
|
package/src/index.ts
ADDED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bubble.stories.d.ts","sourceRoot":"","sources":["../../src/stories/bubble.stories.tsx"],"names":[],"mappings":"AAaA,eAAO,MAAM,OAAO,+CA6CnB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popup.stories.d.ts","sourceRoot":"","sources":["../../src/stories/popup.stories.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,+CAiBnB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"standard.stories.d.ts","sourceRoot":"","sources":["../../src/stories/standard.stories.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,+CAWnB,CAAA;AAED,eAAO,MAAM,iBAAiB,+CAa7B,CAAA"}
|