Skip to content

Commit

Permalink
Update with initial documentation for v1.11.0 (#31)
Browse files Browse the repository at this point in the history
* Update with initial documentation

* Re-add bdapi danger notice
  • Loading branch information
zerebos authored Dec 12, 2024
1 parent ed51088 commit e20e64d
Show file tree
Hide file tree
Showing 9 changed files with 17,421 additions and 12,606 deletions.
21 changes: 18 additions & 3 deletions docs/api/bdapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## Properties

### Components
A set of [react components](./components.md) plugins can make use of.

**Type:** `Components`
___

### ContextMenu
An instance of [ContextMenu](./contextmenu) for interacting with context menus.

Expand All @@ -22,8 +28,14 @@ An instance of [Data](./data) to manage data.
**Type:** `Data`
___

### Logger
An instance of [Logger](./logger.md) for logging information.

**Type:** `Logger`
___

### Net
An instance of [Net](./net) for networking requests.
An instance of [Net](./net.md) for using network related tools.

**Type:** `Net`
___
Expand Down Expand Up @@ -281,7 +293,10 @@ key|string|Which piece of data to load
___

### monkeyPatch <Badge type="danger">deprecated</Badge>
Monkey-patches a method on an object. The patching callback may be run before, after or instead of target method. - Be careful when monkey-patching. Think not only about original functionality of target method and your changes, but also about developers of other plugins, who may also patch this method before or after you. Try to change target method behaviour as little as possible, and avoid changing method signatures. - Display name of patched method is changed, so you can see if a function has been patched (and how many times) while debugging or in the stack trace. Also, patched methods have property `__monkeyPatched` set to `true`, in case you want to check something programmatically.
Monkey-patches a method on an object. The patching callback may be run before, after or instead of target method.

- Be careful when monkey-patching. Think not only about original functionality of target method and your changes, but also about developers of other plugins, who may also patch this method before or after you. Try to change target method behaviour as little as possible, and avoid changing method signatures.
- Display name of patched method is changed, so you can see if a function has been patched (and how many times) while debugging or in the stack trace. Also, patched methods have property `__monkeyPatched` set to `true`, in case you want to check something programmatically.

| Parameter | Type | Optional | Default | Description |
|:----------|:------:|:--------:|:-------:|:----------------------:|
Expand Down Expand Up @@ -309,7 +324,7 @@ callback|function|Function to run when removed
___

### openDialog <Badge type="danger">deprecated</Badge>
Gives access to the [Electron Dialog](https://www.electronjs.org/docs/latest/api/dialog/) api. Returns a `Promise` that resolves to an `object` that has a `boolean` cancelled and a `filePath` string for saving and a `filePaths` string array for opening.
Gives access to the [Electron Dialog](https://www.electronjs.org/docs/latest/api/dialog/) api. Returns a `Promise` that resolves to an `object` that has a `boolean` cancelled and a `filePath` string for saving and a `filePaths` string array for opening.

| Parameter | Type | Optional | Default | Description |
|:----------|:------:|:--------:|:-------:|:----------------------:|
Expand Down
59 changes: 59 additions & 0 deletions docs/api/components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Components

`Components` is a namespace holding a series of React components. It is available under [BdApi](./bdapi).

> [!NOTE]
> This documentation is in progress and currently just serves as a reference list with no additional info.
## Properties

### Button


### ColorInput


### DropdownInput


### ErrorBoundary


### Flex


### KeybindInput


### NumberInput


### RadioInput


### SearchInput


### SettingGroup


### SettingItem


### SliderInput


### SwitchInput


### Text


### TextInput


### Tooltip


## Methods

76 changes: 76 additions & 0 deletions docs/api/logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Logger

`Logger` is a helper class to log data in a nice and consistent way. An instance is available on [BdApi](./bdapi).

## Properties



## Methods

### debug
Logs used for debugging purposes.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
module|string|Name of the calling module.
message|...any|Messages to have logged.

**Returns:** `void`
___

### error
Logs an error message.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
pluginName|string|Name of the calling module
message|...any|Messages to have logged.

**Returns:** `void`
___

### info
Logs an informational message.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
module|string|Name of the calling module.
message|...any|Messages to have logged.

**Returns:** `void`
___

### log
Logs used for basic loggin.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
module|string|Name of the calling module.
message|...any|Messages to have logged.

**Returns:** `void`
___

### stacktrace
Logs an error using a collapsed error group with stacktrace.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
pluginName|string|Name of the calling module.
message|string|Message or error to have logged.
error|Error|Error object to log with the message.

**Returns:** `void`
___

### warn
Logs a warning message.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
module|string|Name of the calling module.
message|...any|Messages to have logged.

**Returns:** `void`
___
80 changes: 79 additions & 1 deletion docs/api/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,55 @@ content|string\|ReactElement\|Array.&lt;(string\|ReactElement)&gt;|A string of t
**Returns:** `void`
___

### buildSettingItem
Creates a single setting wrapped in a setting item that has a name and note.
The shape of the object should match the props of the component you want to render, check the
`BdApi.Components` section for details. Shown below are ones common to all setting types.

| Parameter | Type | Optional | Default | Description |
|:----------|:------:|:--------:|:-------:|:----------------------:|
setting|object|&#x274C;|*none*|
setting.type|string|&#x274C;|*none*|One of: dropdown, number, switch, text, slider, radio, keybind, color, custom
setting.id|string|&#x274C;|*none*|Identifier to used for callbacks
setting.name|string|&#x274C;|*none*|Visual name to display
setting.note|string|&#x274C;|*none*|Visual description to display
setting.value|any|&#x274C;|*none*|Current value of the setting
setting.children|ReactElement|&#x2705;|*none*|Only used for "custom" type
setting.onChange|CallableFunction|&#x2705;|*none*|Callback when the value changes (only argument is new value)
setting.disabled|boolean|&#x2705;|false|Whether this setting is disabled
setting.inline|boolean|&#x2705;|true|Whether the input should render inline with the name (this is false by default for radio type)

**Returns:** `void`
___

### buildSettingsPanel
Creates a settings panel (react element) based on json-like data.

The `settings` array here is an array of the same settings types described in `buildSetting` above.
However, this API allows one additional setting "type" called `category`. This has the same properties
as the Group React Component found under the `Components` API.

`onChange` will always be given 3 arguments: category id, setting id, and setting value. In the case
that you have settings on the "root" of the panel, the category id is `null`. Any `onChange`
listeners attached to individual settings will fire before the panel-level change listener.

`onDrawerToggle` is given 2 arguments: category id, and the current shown state. You can use this to
save drawer states.

`getDrawerState` is given 2 arguments: category id, and the default shown state. You can use this to
recall a saved drawer state.

| Parameter | Type | Optional | Default | Description |
|:----------|:------:|:--------:|:-------:|:----------------------:|
props|object|&#x274C;|*none*|
props.settings|Array.&lt;object&gt;|&#x274C;|*none*|Array of settings to show
props.onChange|CallableFunction|&#x274C;|*none*|Function called on every change
props.onDrawerToggle|CallableFunction|&#x2705;|*none*|Optionally used to save drawer states
props.getDrawerState|CallableFunction|&#x2705;|*none*|Optionially used to recall drawer states

**Returns:** `void`
___

### createTooltip
Creates a tooltip to automatically show on hover.

Expand All @@ -36,7 +85,7 @@ options.disabled|boolean|&#x2705;|false|Whether the tooltip should be disabled f
___

### openDialog
Gives access to the [Electron Dialog](https://www.electronjs.org/docs/latest/api/dialog/) api. Returns a `Promise` that resolves to an `object` that has a `boolean` cancelled and a `filePath` string for saving and a `filePaths` string array for opening.
Gives access to the [Electron Dialog](https://www.electronjs.org/docs/latest/api/dialog/) api. Returns a `Promise` that resolves to an `object` that has a `boolean` cancelled and a `filePath` string for saving and a `filePaths` string array for opening.

| Parameter | Type | Optional | Default | Description |
|:----------|:------:|:--------:|:-------:|:----------------------:|
Expand All @@ -57,6 +106,34 @@ options.modal|boolean|&#x2705;|false|Whether the dialog should act as a modal to
**Returns:** `Promise.<object>` - Result of the dialog
___

### showChangelogModal
Shows a changelog modal in a similar style to Discord's. Customizable with images, videos, colored sections and supports markdown.

The changes option is a array of objects that have this typing:
```ts
interface Changes {
title: string;
type: "fixed" | "added" | "progress" | "changed";
items: Array<string>;
blurb?: string;
}
```

| Parameter | Type | Optional | Default | Description |
|:----------|:------:|:--------:|:-------:|:----------------------:|
options|object|&#x274C;|*none*|Information to display in the modal
options.title|string|&#x274C;|*none*|Title to show in the modal header
options.subtitle|string|&#x274C;|*none*|Title to show below the main header
options.blurb|string|&#x2705;|*none*|Text to show in the body of the modal before the list of changes
options.banner|string|&#x2705;|*none*|URL to an image to display as the banner of the modal
options.video|string|&#x2705;|*none*|Youtube link or url of a video file to use as the banner
options.poster|string|&#x2705;|*none*|URL to use for the video freeze-frame poster
options.footer|string\|ReactElement\|Array.&lt;(string\|ReactElement)&gt;|&#x2705;|*none*|What to show in the modal footer
options.changes|Array.&lt;Changes&gt;|&#x2705;|*none*|List of changes to show (see description for details)

**Returns:** `string` - The key used for this modal.
___

### showConfirmationModal
Shows a generic but very customizable confirmation modal with optional confirm and cancel callbacks.

Expand All @@ -70,6 +147,7 @@ options.confirmText|string|&#x2705;|Okay|Text for the confirmation/submit button
options.cancelText|string|&#x2705;|Cancel|Text for the cancel button
options.onConfirm|callable|&#x2705;|NOOP|Callback to occur when clicking the submit button
options.onCancel|callable|&#x2705;|NOOP|Callback to occur when clicking the cancel button
options.onClose|callable|&#x2705;|NOOP|Callback to occur when exiting the modal

**Returns:** `string` - The key used for this modal.
___
Expand Down
23 changes: 23 additions & 0 deletions docs/api/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,26 @@ options.ignore|Array.&lt;string&gt;|&#x2705;|[]|Array of strings to use as keys

**Returns:** `void`
___

### getNestedValue
Gets a nested value (if it exists) of an object safely. keyPath should be something like `key.key2.key3`.
Numbers can be used for arrays as well like `key.key2.array.0.id`.

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
obj|object|object to get nested value from
keyPath|string|key path to the desired value

**Returns:** `void`
___

### semverCompare
This works on semantic versioning e.g. "1.0.0".

| Parameter | Type | Description |
|:----------|:------:|:----------------------:|
currentVersion|string|
newVersion|string|

**Returns:** `number` - 0 indicates equal, -1 indicates left hand greater, 1 indicates right hand greater
___
Loading

0 comments on commit e20e64d

Please sign in to comment.