andy-widget-react 2.3.1 → 3.0.0-next.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/AndyChat.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\nimport { defineAndyChat, type AndyChatElement, type WidgetOverrides } from 'andy-widget-core'\nimport type { AndyChatProps, SalesAndyChatProps } from './types'\n\n/** The 2.x props that override the Agent's copy and look, as the element's `overrides`. */\nconst OVERRIDES = [\n\t'name',\n\t'headline',\n\t'description',\n\t'welcomeMessage',\n\t'predefinedQuestions',\n\t'theme',\n\t'orientation',\n\t'brandColor',\n\t'useBrandColor',\n\t'bubbleStyle',\n\t'bubbleLabel',\n\t'logoUrl'\n] as const satisfies ReadonlyArray<keyof WidgetOverrides & keyof SalesAndyChatProps>\n\nconst overridesOf = (props: SalesAndyChatProps): WidgetOverrides =>\n\tObject.fromEntries(OVERRIDES.filter(key => props[key] !== undefined).map(key => [key, props[key]]))\n\n/** Each deprecated prop logs one notice per page. */\nconst noticed = new Set<string>()\nconst notice = (prop: string, message: string) => {\n\tif (noticed.has(prop)) return\n\tnoticed.add(prop)\n\tconsole.warn(`AndyChat: ${message}`)\n}\n\n/**\n * The Andy Widget for React: one `<andy-chat>` element (`andy-widget-core`), whose Widget Mode comes from\n * identity. It shows Sales (`agentId`) to a Visitor and Support to a Requester with a valid pass, and starts a\n * fresh panel on every identity change; this component only hands the element its props. The 2.x props keep\n * working: `embedId` and `mode=\"support\"` as deprecated aliases, the copy and look overrides over the Agent's\n * config, and `previewMode`.\n */\nconst AndyChat: React.FC<AndyChatProps> = props => {\n\t// `mode=\"support\"` never showed Sales, so it keeps the Widget Support-only.\n\tconst sales = props.mode === 'support' ? undefined : props\n\tconst agentId = sales?.agentId ?? sales?.embedId\n\tconst { support, orientation, initialOpen = false } = props\n\tconst lang = props.lang ?? support?.lang\n\tconst supportAlias = !sales\n\tconst embedAlias = sales?.embedId !== undefined\n\tuseEffect(() => {\n\t\tif (supportAlias) notice('mode', '`mode=\"support\"` is deprecated. Pass `support` without `agentId`.')\n\t\tif (embedAlias) notice('embedId', '`embedId` is deprecated. Use `agentId`.')\n\t}, [supportAlias, embedAlias])\n\n\tconst host = useRef<HTMLDivElement>(null)\n\tconst [element, setElement] = useState<AndyChatElement | null>(null)\n\tconst pass = useRef(support?.getRequesterPass)\n\tpass.current = support?.getRequesterPass\n\tuseEffect(() => {\n\t\tdefineAndyChat()\n\t\tconst created = document.createElement('andy-chat')\n\t\tcreated.open = initialOpen\n\t\thost.current?.append(created)\n\t\tsetElement(created)\n\t\t// Removing the element ends its identity: pass, chat, requests and drafts go with it.\n\t\treturn () => created.remove()\n\t}, [])\n\tuseEffect(() => {\n\t\tif (lang) element?.setAttribute('lang', lang)\n\t\telse element?.removeAttribute('lang')\n\t}, [element, lang])\n\tconst overrides = sales ? overridesOf(sales) : {}\n\tconst overridesKey = JSON.stringify(overrides)\n\tconst preview = sales?.previewMode === true\n\tuseEffect(() => {\n\t\tif (!element) return\n\t\telement.overrides = overrides\n\t\telement.preview = preview\n\t\telement.agentId = agentId\n\t\t// The element compares installation, contextKey and API, so a new callback each render is not a new identity.\n\t\telement.support = support\n\t\t\t? { ...support, ...(lang ? { lang } : {}), ...(orientation ? { position: orientation } : {}), getRequesterPass: () => pass.current?.() }\n\t\t\t: null\n\t}, [element, agentId, support, lang, orientation, overridesKey, preview])\n\treturn <div ref={host} className='andy-widget-host' />\n}\n\nexport default AndyChat\n"],"names":["useEffect","useRef","useState","defineAndyChat","_jsx"],"mappings":";;;;;;;;;AAIA;AACA,MAAM,SAAS,GAAG;IACjB,MAAM;IACN,UAAU;IACV,aAAa;IACb,gBAAgB;IAChB,qBAAqB;IACrB,OAAO;IACP,aAAa;IACb,YAAY;IACZ,eAAe;IACf,aAAa;IACb,aAAa;IACb;CACmF;AAEpF,MAAM,WAAW,GAAG,CAAC,KAAyB,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