-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add JSDoc and README for cs-ui-lib (#323)
Co-authored-by: feederbox826 <[email protected]>
- Loading branch information
1 parent
7eb37b4
commit 8d3631a
Showing
2 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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,70 @@ | ||
# CommunityScripts UI Plugin library | ||
|
||
This is a set of slimmed down functions from StashUserscriptLibrary, targeting CommunityScripts originally introduced in [#319](https://github.com/stashapp/CommunityScripts/pull/319) | ||
|
||
|
||
## functions | ||
All the following functions are exposed under `window.csLib` and `csLib` | ||
|
||
## callGQL | ||
```js | ||
/** | ||
* This is a wrapped GraphQL (GQL) query caller | ||
* @param {...Object} reqData | ||
* @param {Object} reqData.query - GraphQL query | ||
* @param {Object}= reqData.variables - GraphQL variables | ||
* @returns {Object} - GQL response data with the `data` wrapper removed | ||
* | ||
* @example | ||
* // fetch the count of organized scenes | ||
* const filter = { organized: true }; | ||
* const query = `query findScenes($filter: SceneFilter) { findScenes(filter: $filter) { count } }`; | ||
* const variables = { filter }; | ||
* const response = await callGQL({ query, variables }); | ||
* // response = { findScenes: { count: 3 } } | ||
*/ | ||
``` | ||
|
||
## getConfiguration | ||
```js | ||
/** | ||
* Get configuration of a plugin from the server via GraphQL | ||
* @param {string} pluginId - The ID of the plugin as it is registered in the server | ||
* @param {*}= fallback - Fallback value if the configuration is not found. Defaults to an empty object | ||
* @returns {Object} - The configuration object of the plugin as it is stored in the server | ||
* | ||
* @example | ||
* // set default config | ||
* const defaultConfig = { enabled: true, theme: 'light' }; | ||
* // fetch config from the server | ||
* const config = await getConfiguration('CommunityScriptsUIPlugin', defaultConfig); | ||
* // config = { theme: 'dark' } | ||
* // merge fetched with default config | ||
* const pluginConfig = { | ||
* ...defaultConfig | ||
* ...config | ||
* }; | ||
* // pluginConfig = { enabled: true, theme: 'dark' } | ||
* } | ||
*/ | ||
``` | ||
|
||
## waitForElement | ||
```js | ||
/** | ||
* Waits for an element to be available in the DOM and runs the callback function once it is | ||
* @param {string} selector - The CSS selector of the element to wait for | ||
* @param {function} callback - The function to be called once the element is available (with the element as an argument) | ||
* @returns | ||
* | ||
* @example | ||
* // wait for the element with the class 'my-element' to be available | ||
* // and change its color to red | ||
* function myCallback(el) { | ||
* el.style.color = 'red'; | ||
* }; | ||
* waitForElement('.my-element', myCallback); | ||
*/ | ||
``` | ||
|
||
## pathElementListener |
This file contains 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