Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Jan 6, 2024
2 parents 40a2505 + 9e33afd commit 32bf4ff
Show file tree
Hide file tree
Showing 34 changed files with 1,976 additions and 1,449 deletions.
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# Changelog

## [1.6.0](https://github.com/bitfocus/companion-module-base/compare/v1.5.1...v1.6.0) (2023-10-14)

Requires Companion 3.2 or later

### Features

* bonjour discovery config fields ([#57](https://github.com/bitfocus/companion-module-base/issues/57)) ([37d3cd9](https://github.com/bitfocus/companion-module-base/commit/37d3cd91aea400eb2685954ba6b792fd58559973))
* support css colors and alpha colorpicker ([1660c3b](https://github.com/bitfocus/companion-module-base/commit/1660c3b37395c5fd240579b3ae4ed864c3f337a1))


### Bug Fixes

* expose ipc type ([c66d6f2](https://github.com/bitfocus/companion-module-base/commit/c66d6f2344ee5f4f239256765a9ec0fe559dc556))

## [1.5.1](https://github.com/bitfocus/companion-module-base/compare/v1.5.0...v1.5.1) (2023-10-02)


### Bug Fixes

* use sequential ids in ipcWrapper, to ensure nanoid doesn't drain the system entropy pool ([5b5c32c](https://github.com/bitfocus/companion-module-base/commit/5b5c32cf3b9a1fe5b9b900c90d02a1970fd0a7c1))

## [1.5.0](https://github.com/bitfocus/companion-module-base/compare/v1.4.3...v1.5.0) (2023-08-27)

Requires Companion 3.1 or later

### Features

* boolean feedback invert ([#59](https://github.com/bitfocus/companion-module-base/issues/59)) ([aa28207](https://github.com/bitfocus/companion-module-base/commit/aa28207ee5f71f280a5c61d78424f9f6a03e12f9))

## [1.4.3](https://github.com/bitfocus/companion-module-base/compare/v1.4.2...v1.4.3) (2023-08-13)


### Bug Fixes

* inline modified debounce-fn into this package ([a068123](https://github.com/bitfocus/companion-module-base/commit/a06812312b2582361d4e0e5e75795c4451a83ae9))
* simplify inlined debounce-fn ([cdc1f2b](https://github.com/bitfocus/companion-module-base/commit/cdc1f2b34913f6fd2008ab74b2dbdd7561d316ec))
* simplify inlined debounce-fn ([9b2f437](https://github.com/bitfocus/companion-module-base/commit/9b2f437bc1e1170d97db488126fe8d7c40363013))

## [1.4.2](https://github.com/bitfocus/companion-module-base/compare/v1.4.1...v1.4.2) (2023-08-13)


### Bug Fixes

* add `isVisibleData` parameter to `isVisible` functions ([ddb1b42](https://github.com/bitfocus/companion-module-base/commit/ddb1b427de4606e4417f79d83cf25d277480c427))
* Don't crash if action/feedback options are missing [#53](https://github.com/bitfocus/companion-module-base/issues/53) ([d4e271d](https://github.com/bitfocus/companion-module-base/commit/d4e271ded4b70d69641fc1655f2c14555c8865b0))

## [1.4.1](https://github.com/bitfocus/companion-module-base/compare/v1.4.0...v1.4.1) (2023-04-12)


Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# @companion-module/base

If you have found this without being directed here, then this is not for you.
Companion 3.0 is not ready for users yet, so you should not be targetting a module to it yet. We will make some announcements when we are ready

This module provides the base class and framework needed to write a module for [Companion 3.0](https://github.com/bitfocus/companion) and later in NodeJS.

In the future it will be possible to write modules in other languages, but it is not recommended as it will reduce the change of gettings other in the community to contribute features and fixes. If you interested in doing this then reach out and we can work together on creating an alternate framework for the language you are using.

## Supported versions of this library

Each version of Companion supports a limited range of versions of this library listed below. Any patch version (the third number) are not relevant for the compatibility check, so are not listed here

| Companion | Module-base |
| --------- | ------------------------- |
| v3.0 | v1.0 - v1.4 |
| v3.1 | v1.0 - v1.5 |
| v3.2 | v1.0 - v1.6 (unconfirmed) |

## Getting started with a new module

To get started with creating a new module, you should start with one of the following templates. These should be kept up to date, but you should make sure all the dependencies are up to date before you begin.

- TODO
- https://github.com/bitfocus/companion-module-template

## Documentation

Expand Down
37 changes: 37 additions & 0 deletions assets/manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"type": "object",
"title": "ModuleManifest",
"properties": {
"$schema": {
"type": "string"
},
"id": {
"type": "string",
"description": "Unique identifier for the module"
Expand Down Expand Up @@ -104,8 +107,42 @@
"items": {
"type": "string"
}
},
"bonjourQueries": {
"type": "object",
"description": "If the device or software for your module supports bonjour announcements, Companion will offer an easy way to watch for these announcements.\nEach query you define must have a matching config field of type 'bonjour-device' with the same name",
"patternProperties": {
"": {
"type": "object",
"title": "ModuleBonjourQuery",
"description": "",
"properties": {
"type": {
"type": "string"
},
"protocol": {
"type": "string",
"enum": ["tcp", "udp"]
},
"txt": {
"type": "object",
"description": "Match on any txt values returned in the query. This is useful to filter out devices of the same 'type' that are not supported",
"patternProperties": {
"": {
"type": "string"
}
},
"additionalProperties": false
}
},
"required": ["type", "protocol"],
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false,
"required": [
"id",
"name",
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = {
},
],
},
moduleNameMapper: {
'^(.+)\\.js$': '$1',
},
testMatch: ['**/__tests__/**/*.spec.(ts|js)'],
testEnvironment: 'node',
coverageThreshold: {
Expand Down
83 changes: 83 additions & 0 deletions lib/debounce-fn/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
declare namespace debounceFn {
interface Options {
/**
Time to wait until the `input` function is called.
@default 0
*/
readonly wait?: number

/**
Maximum time to wait until the `input` function is called.
Only applies when after is true.
Disabled when 0
@default 0
*/
readonly maxWait?: number

/**
Trigger the function on the leading edge of the `wait` interval.
For example, this can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.
@default false
*/
readonly before?: boolean

/**
Trigger the function on the trailing edge of the `wait` interval.
@default true
*/
readonly after?: boolean
}

interface BeforeOptions extends Options {
readonly before: true
}

interface NoBeforeNoAfterOptions extends Options {
readonly after: false
readonly before?: false
}

interface DebouncedFunction<ArgumentsType extends unknown[], ReturnType> {
(...arguments: ArgumentsType): ReturnType
cancel(): void
}
}

/**
[Debounce](https://davidwalsh.name/javascript-debounce-function) a function.
@param input - Function to debounce.
@returns A debounced function that delays calling the `input` function until after `wait` milliseconds have elapsed since the last time the debounced function was called.
It comes with a `.cancel()` method to cancel any scheduled `input` function calls.
@example
```
import debounceFn = require('debounce-fn');
window.onresize = debounceFn(() => {
// Do something on window resize
}, {wait: 100});
```
*/
declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
input: (...arguments: ArgumentsType) => ReturnType,
options: debounceFn.BeforeOptions
): debounceFn.DebouncedFunction<ArgumentsType, ReturnType>

declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
input: (...arguments: ArgumentsType) => ReturnType,
options: debounceFn.NoBeforeNoAfterOptions
): debounceFn.DebouncedFunction<ArgumentsType, undefined>

declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
input: (...arguments: ArgumentsType) => ReturnType,
options?: debounceFn.Options
): debounceFn.DebouncedFunction<ArgumentsType, ReturnType | undefined>

export = debounceFn
76 changes: 76 additions & 0 deletions lib/debounce-fn/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict'
const mimicFn = require('mimic-fn')

module.exports = (inputFunction, options = {}) => {
if (typeof inputFunction !== 'function') {
throw new TypeError(`Expected the first argument to be a function, got \`${typeof inputFunction}\``)
}

const { wait = 0, maxWait = 0, before = false, after = true } = options

if (!before && !after) {
throw new Error("Both `before` and `after` are false, function wouldn't be called.")
}

let timeout
let maxTimeout
let result

const debouncedFunction = function (...arguments_) {
const context = this

const later = () => {
timeout = undefined

if (maxTimeout) {
clearTimeout(maxTimeout)
maxTimeout = undefined
}

if (after) {
result = inputFunction.apply(context, arguments_)
}
}

const maxLater = () => {
maxTimeout = undefined

if (timeout) {
clearTimeout(timeout)
timeout = undefined
}

result = inputFunction.apply(context, arguments_)
}

const shouldCallNow = before && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)

if (maxWait > 0 && !maxTimeout && after) {
maxTimeout = setTimeout(maxLater, maxWait)
}

if (shouldCallNow) {
result = inputFunction.apply(context, arguments_)
}

return result
}

mimicFn(debouncedFunction, inputFunction)

debouncedFunction.cancel = () => {
if (timeout) {
clearTimeout(timeout)
timeout = undefined
}

if (maxTimeout) {
clearTimeout(maxTimeout)
maxTimeout = undefined
}
}

return debouncedFunction
}
9 changes: 9 additions & 0 deletions lib/debounce-fn/license
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64 changes: 64 additions & 0 deletions lib/debounce-fn/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# debounce-fn

> [Debounce](https://davidwalsh.name/javascript-debounce-function) a function
## Install

```
$ npm install debounce-fn
```

## Usage

```js
const debounceFn = require('debounce-fn');

window.onresize = debounceFn(() => {
// Do something on window resize
}, {wait: 100});
```

## API

### debounceFn(input, options?)

Returns a debounced function that delays calling the `input` function until after `wait` milliseconds have elapsed since the last time the debounced function was called.

It comes with a `.cancel()` method to cancel any scheduled `input` function calls.

#### input

Type: `Function`

Function to debounce.

#### options

Type: `object`

##### wait

Type: `number`\
Default: `0`

Time to wait until the `input` function is called.

##### before

Type: `boolean`\
Default: `false`

Trigger the function on the leading edge of the `wait` interval.

For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.

##### after

Type: `boolean`\
Default: `true`

Trigger the function on the trailing edge of the `wait` interval.

## Related

- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
Loading

0 comments on commit 32bf4ff

Please sign in to comment.