Context component

<wy-context> | WyContext

The Weavy context component provides a declarative way of initializing the Weavy UIKit that does not require creating an instance of the Weavy class. This can be useful in some scenarios, for instance in low-code and no-code platforms with limited javascript functionality.

When used with child nodes, the Weavy context acts a regular context provider, which makes the configuration available to it's child nodes only. If no child nodes are present, the configuration is instead available globally in the DOM.

To use the context component in the UIKit you need initialize it with the url to your environment and tokenFactory/tokenUrl for authentication.

For use with React, you can instead use the standard React context provider or the useWeavy configuration hook, available in the @weavy/uikit-react package. See Getting started with Weavy using React on how to configure Weavy in React.

Component layout

This component does not render or occupy any visual space in the rendering.

You can add additional styling for other child Weavy components using CSS Custom Properties.

Importing

If you installed the UIKit with npm you can use the following snippet to import the component into your project. Otherwise, if you installed the UIKit as a <script> you can ignore this section.

import { WyContext } from "@weavy/uikit-web";

Examples

Globally available Weavy context

The context component is place by itself without any children and becomes available to the entire DOM.

It's configured with a tokenUrl endpoint that needs to be implemented and provided at your server.

<wy-context
  url="{WEAVY-URL}"
  tokenUrl="https://example.com/myapp/token"
></wy-context>
...
<h1>Messenger with standard weavy configuration</h1>
<wy-messenger></wy-messenger>

Scoped Weavy context provider

Placing components as children to the context makes the configuration only available to it's children.

It's configured with a tokenUrl endpoint that needs to be implemented and provided at your server.

<wy-context url="{WEAVY-URL}" tokenUrl="https://example.com/myapp/token">
  <h1>Messenger inside a weavy context provider</h1>
  <wy-messenger></wy-messenger>
</wy-context>

HTML attributes

Attributes can be set when using the component in HTML. All attributes have corresponding Javascript properties.

Most attributes are optional and/or has sensible default values. Any required attributes are indicated with an asterisk (*). Any multiple option requirements are marked by double asterisks (**).

Learn more about attributes and properties.

Attribute Value Description
url* string, URL URL to your Weavy environment.
tokenFactory** WeavyTokenFactory Async function returning an access_token. See Authentication for details.
tokenUrl** string, URL URL to token endpoint. Can be specified instead of tokenFactory.
annotations "none", "buttons-inline" Annotation appearance configuration shared with child components.
cloudFilePickerUrl string, url URL to the hosted cloud file picker. This usually does not need to be provided unless you intend to host your own Weavy cloud file picker.
configurationTimeout number Timeout (ms) before configuration is considered to have failed. Infinity disables the timeout
disableEnvironmentImports Disables dynamic import of modules from the environment.
enterToSend "never", "modifier", "auto", "always" Enter to send editor configuration shared with child components.
gcTime number The max-allowed age of the cache in milliseconds. If a persisted cache is found that is older than this time, it will be discarded. If set to Infinity, the cache will never be considered old.
locale string Preferred locale. See localization for details.
provider Enables forced scoped context mode so only child elements may consume the provided context.
reactions string Space separated string of unicode emojis to use for reactions. Defaults to reactions from the Weavy instance.
scrollBehavior "smooth", "instant", "auto" Which scroll behavior to use (where applicable). Note that not all browsers (Chrome) have similar scroll transitions, they may be very slow.
staleTime number The time (ms) after data is considered stale. If set to Infinity, the data will never be considered stale.
tokenFactoryRetryDelay number The time (ms) between tokenFactory attempts when a valid token isn't provided yet.
tokenFactoryTimeout number The time (ms) allowed to pass before tokenFactory is considered to have timed out. Infinity disables the timeout.

JavaScript properties

Properties can be used in JavaScript. Some of them have corresponding HTML attributes where applicable. Any required attributes are indicated with an asterisk (*). Any multiple option requirements are marked by double asterisks (**).

Property Type Default Description
url* string, URL URL to your Weavy environment.
tokenFactory** WeavyTokenFactory Token factory used for acquiring user access tokens.
tokenUrl** string, URL Token endpoint used when no token factory is supplied.
provider boolean false Enables scoped context mode so only child elements consume the provided context.
annotations "none", "buttons-inline" "buttons-inline" Annotation appearance configuration shared with child components.
cloudFilePickerUrl string, URL URL to the hosted cloud file picker. This usually does not need to be provided unless you intend to host your own Weavy cloud file picker.
configurationTimeout 5000 Timeout (ms) before configuration is considered to have failed. Infinity disables the timeout.
disableEnvironmentImports false Disables dynamic import of modules from the environment.
enterToSend "never", "modifier", "auto", "always" "auto" Controls the editor enter-to-send behavior.
locale string "en" Preferred locale. See localization for details.
locales LocaleModule[] Array of enabled locales. See localization for details.
gcTime number 86400000 (24h) Garbage-collection interval (ms) applied to caches.
scrollBehavior "smooth", "instant", "auto" "auto" Which scroll behavior to use (where applicable). Note that not all browsers (Chrome) have similar scroll transitions, they may be very slow.
staleTime number 1000 Default stale time (ms) for TanStack Query caches.
tokenFactoryRetryDelay number 2000 Delay (ms) before retrying the token factory.
tokenFactoryTimeout number 20000 Timeout (ms) applied to the token factory promise.
reactions string "😍 😎 😉 😜 👍" A space separated string of available reaction emojis in unicode.
version string readonly The semver version of the package.
sourceName string readonly The Weavy source name; package name.
weavy Weavy The Weavy instance.
Support

To access live chat with our developer success team you need a Weavy account.

Sign in or create a Weavy account