-
Notifications
You must be signed in to change notification settings - Fork 92
feat(deskcrew): add DeskCrew to the registry #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
webmilmind1
wants to merge
2
commits into
nuxt:main
Choose a base branch
from
webmilmind1:feat/deskcrew-registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| --- | ||
| title: DeskCrew | ||
| description: Add a lazy-loaded DeskCrew support widget to your Nuxt app. | ||
| links: | ||
| - label: useScriptDeskCrew | ||
| icon: i-simple-icons-github | ||
| to: https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/deskcrew.ts | ||
| size: xs | ||
| - label: "<ScriptDeskCrew>" | ||
| icon: i-simple-icons-github | ||
| to: https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/components/ScriptDeskCrew.vue | ||
| size: xs | ||
| --- | ||
|
|
||
| [DeskCrew](https://deskcrew.io/) is a support widget combining live chat, AI answers from your | ||
| knowledge base, a help centre and a changelog. | ||
|
|
||
| Use [`useScriptDeskCrew()`{lang="ts"}](#usescriptdeskcrew){lang="ts"} for direct SDK calls, or | ||
| [`<ScriptDeskCrew>`{lang="html"}](#scriptdeskcrew){lang="html"} for a custom chat launcher. | ||
|
|
||
| ::script-stats | ||
| :: | ||
|
|
||
| ::script-docs | ||
| :: | ||
|
|
||
| ## [`<ScriptDeskCrew>`{lang="html"}](/scripts/deskcrew){lang="html"} | ||
|
|
||
| The headless facade holds back the DeskCrew widget until its | ||
| [element trigger](/docs/guides/script-triggers#element-event-triggers) fires. It listens for | ||
| `click` by default, so a visitor who never opens chat downloads none of the widget. | ||
|
|
||
| ### Component API | ||
|
|
||
| See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full | ||
| props, events, and slots. | ||
|
|
||
| #### With environment variables | ||
|
|
||
| ```ts [nuxt.config.ts] | ||
| export default defineNuxtConfig({ | ||
| scripts: { | ||
| registry: { | ||
| deskcrew: { trigger: 'onNuxtReady' }, | ||
| } | ||
| }, | ||
| runtimeConfig: { | ||
| public: { | ||
| scripts: { | ||
| deskcrew: { | ||
| widgetKey: '', // NUXT_PUBLIC_SCRIPTS_DESKCREW_WIDGET_KEY | ||
| board: '', // NUXT_PUBLIC_SCRIPTS_DESKCREW_BOARD | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ```text [.env] | ||
| NUXT_PUBLIC_SCRIPTS_DESKCREW_WIDGET_KEY=<YOUR_PUBLIC_KEY> | ||
| NUXT_PUBLIC_SCRIPTS_DESKCREW_BOARD=<YOUR_BOARD_SLUG> | ||
| ``` | ||
|
|
||
| ### Events | ||
|
|
||
| The component emits `ready` once the widget has mounted its launcher, and `error` if the script | ||
| fails to load. | ||
|
|
||
| ### Slots | ||
|
|
||
| `awaitingLoad`, `loading`, `error` and the default slot behave as documented for facade | ||
| components. | ||
|
|
||
| ## [`useScriptDeskCrew()`{lang="ts"}](/scripts/deskcrew){lang="ts"} | ||
|
|
||
| ```ts | ||
| export function useScriptDeskCrew<T extends DeskCrewApi>(_options?: DeskCrewInput) {} | ||
| ``` | ||
|
|
||
| ::script-types | ||
| :: | ||
|
|
||
| ### Identifying a visitor | ||
|
|
||
| Identity is a signed token minted by your own backend, so it is a runtime call rather than a | ||
| `nuxt.config` option. Everything in `nuxt.config` is a deploy-time constant, and baking one | ||
| visitor's token into a build would hand that identity to every other visitor. | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| const { proxy } = useScriptDeskCrew({ widgetKey: 'pub_xxxxxxxx' }) | ||
| const { data } = await useFetch('/api/deskcrew-token') | ||
| watchEffect(() => { | ||
| if (data.value?.token) | ||
| proxy.identify({ token: data.value.token }) | ||
| }) | ||
| </script> | ||
| ``` | ||
|
|
||
| ### Other surfaces | ||
|
|
||
| `embed()`{lang="ts"}, `changelog()`{lang="ts"} and `surveys()`{lang="ts"} each mount a surface. Call each at most once per | ||
| page: a second call logs a warning and does nothing. | ||
|
|
||
| ::callout | ||
| DeskCrew serves its widget from its own origin and derives its API endpoint from the script's | ||
| `src`, so this script does not support [bundling](/docs/guides/bundling) or | ||
| [first-party mode](/docs/guides/first-party). It loads directly from `deskcrew.io`. | ||
| :: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/script/src/runtime/components/ScriptDeskCrew.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <script setup lang="ts"> | ||
| import type { ElementScriptTrigger } from '#nuxt-scripts/types' | ||
| import { useMutationObserver } from '@vueuse/core' | ||
| import { computed, onMounted, ref, shallowRef, watch } from 'vue' | ||
| import { useScriptTriggerElement } from '../composables/useScriptTriggerElement' | ||
| import { useScriptDeskCrew } from '../registry/deskcrew' | ||
|
|
||
| const props = withDefaults(defineProps<{ | ||
| /** | ||
| * Defines the trigger event to load the script. | ||
| */ | ||
| trigger?: ElementScriptTrigger | ||
| widgetKey: string | ||
| board?: string | ||
| color?: string | ||
| position?: 'left' | 'right' | ||
| greeting?: string | ||
| launcher?: 'logo' | ||
| }>(), { | ||
| trigger: 'click', | ||
| }) | ||
|
|
||
| const emits = defineEmits<{ | ||
| ready: [e: ReturnType<typeof useScriptDeskCrew>] | ||
| error: [] | ||
| }>() | ||
|
|
||
| defineSlots<{ | ||
| default?: (props: { ready: boolean }) => any | ||
| awaitingLoad?: () => any | ||
| loading?: () => any | ||
| error?: () => any | ||
| }>() | ||
|
|
||
| const rootEl = ref(null) | ||
| const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl }) | ||
|
|
||
| const isReady = ref(false) | ||
| const deskcrew = useScriptDeskCrew({ | ||
| widgetKey: props.widgetKey, | ||
| board: props.board, | ||
| color: props.color, | ||
| position: props.position, | ||
| greeting: props.greeting, | ||
| launcher: props.launcher, | ||
| scriptOptions: { | ||
| trigger, | ||
| }, | ||
| }) | ||
| const { onLoaded, status } = deskcrew | ||
| if (props.trigger === 'click') { | ||
| onLoaded((instance) => { | ||
| instance.open() | ||
| }) | ||
| } | ||
|
|
||
| defineExpose({ | ||
| deskcrew, | ||
| }) | ||
|
|
||
| const observerTarget = shallowRef<HTMLElement | null>(null) | ||
| function markReady() { | ||
| if (isReady.value) | ||
| return true | ||
| // The widget mounts a Shadow DOM host into document.body with this id, so its | ||
| // presence is the only reliable signal that the UI actually exists. Waiting on | ||
| // script load alone would flip the facade away before anything is rendered. | ||
| if (!document.getElementById('deskcrew-root')) | ||
| return false | ||
| isReady.value = true | ||
| observerTarget.value = null | ||
| emits('ready', deskcrew) | ||
| return true | ||
| } | ||
| useMutationObserver(observerTarget, markReady, { childList: true, subtree: true }) | ||
|
|
||
| onMounted(() => { | ||
| watch(status, (status) => { | ||
| if (status === 'loaded') { | ||
| if (!markReady()) | ||
| observerTarget.value = document.body | ||
| } | ||
| else if (status === 'error') { | ||
| observerTarget.value = null | ||
| isReady.value = false | ||
| emits('error') | ||
| } | ||
| }, { immediate: true }) | ||
| }) | ||
|
|
||
| const rootAttrs = computed(() => { | ||
| return { | ||
| ...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}), | ||
| } | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div | ||
| ref="rootEl" | ||
| :style="{ display: isReady ? 'none' : 'block' }" | ||
| v-bind="rootAttrs" | ||
| > | ||
| <slot :ready="isReady" /> | ||
| <slot v-if="status === 'awaitingLoad'" name="awaitingLoad" /> | ||
| <slot v-else-if="status === 'error'" name="error" /> | ||
| <slot v-else-if="status === 'loading' || !isReady" name="loading" /> | ||
| </div> | ||
| </template> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix the in-page link fragments.
Markdownlint reports
#usescriptdeskcrewand#scriptdeskcrewas invalid fragments. Add explicit stable heading IDs or update the fragments to match the IDs generated by the documentation renderer.🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 18-18: Link fragments should be valid
(MD051, link-fragments)
[warning] 19-19: Link fragments should be valid
(MD051, link-fragments)
🤖 Prompt for AI Agents
Source: Linters/SAST tools