Context component
<wy-context> | WyContext
The context component provides an alternative 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.
To use the context component in the UIKit you need initialize it with the
url to your environment and tokenFactory/tokenUrl for authentication.
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
The context component can be used by itself as seen in the example below.
<wy-context
url="{WEAVY-URL}"
tokenUrl="https://example.com/myapp/token"
></wy-context>
...
<h1>Messenger with standard weavy configuration</h1>
<wy-messenger></wy-messenger>
It can also be used as a context provider where you place other Weavy components as children of the context provider.
<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. |
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. | |
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. |