stimulus-library 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -43
- package/dist/controllers/forms/disable_inputs_controller.js +21 -0
- package/dist/controllers/media/fallback_iframe_controller.js +44 -0
- package/dist/controllers/signal/signal_attribute_sync_controller.js +10 -0
- package/dist/controllers/signal/signal_content_sync_controller.js +9 -0
- package/dist/controllers/tables/table_filter_controller.js +53 -0
- package/dist/mixins/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
# Stimulus-Library
|
|
2
|
-
|
|
3
|
-
[Documentation](https://sub-xaero.github.io/stimulus-library/) | [Full List of Controllers](https://sub-xaero.github.io/stimulus-library/)
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
To get started, you'll need to add the `stimulus-library` package to your project.
|
|
13
|
-
|
|
14
|
-
To do so, either add `stimulus-library` to your package.json manually
|
|
15
|
-
|
|
16
|
-
```json
|
|
17
|
-
{
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"stimulus-library": "latest"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
or run
|
|
25
|
-
`npm install --save stimulus-library` or `yarn add stimulus-library`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Then, to get started, import and register the controllers you want to use.
|
|
29
|
-
|
|
30
|
-
*Please Note* as below, that when registering the name for the controller, you should use `kebab-case` and omit the `-controller` suffix.
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
import { Application } from "@hotwired/stimulus";
|
|
34
|
-
import { AutoSubmitFormController } from "stimulus-library";
|
|
35
|
-
|
|
36
|
-
const application = Application.start();
|
|
37
|
-
application.register("auto-submit-form", AutoSubmitFormController);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Tree-shaking
|
|
41
|
-
If you use the ESM builds of the library, this library fully supports tree-shaking,
|
|
42
|
-
only the controllers you directly import will be bundled with your application.
|
|
43
|
-
|
|
1
|
+
# Stimulus-Library
|
|
2
|
+
|
|
3
|
+
[Documentation](https://sub-xaero.github.io/stimulus-library/) | [Full List of Controllers](https://sub-xaero.github.io/stimulus-library/)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
To get started, you'll need to add the `stimulus-library` package to your project.
|
|
13
|
+
|
|
14
|
+
To do so, either add `stimulus-library` to your package.json manually
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"stimulus-library": "latest"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or run
|
|
25
|
+
`npm install --save stimulus-library` or `yarn add stimulus-library`
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Then, to get started, import and register the controllers you want to use.
|
|
29
|
+
|
|
30
|
+
*Please Note* as below, that when registering the name for the controller, you should use `kebab-case` and omit the `-controller` suffix.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { Application } from "@hotwired/stimulus";
|
|
34
|
+
import { AutoSubmitFormController } from "stimulus-library";
|
|
35
|
+
|
|
36
|
+
const application = Application.start();
|
|
37
|
+
application.register("auto-submit-form", AutoSubmitFormController);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Tree-shaking
|
|
41
|
+
If you use the ESM builds of the library, this library fully supports tree-shaking,
|
|
42
|
+
only the controllers you directly import will be bundled with your application.
|
|
43
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseController } from "../../utilities/base_controller";
|
|
2
|
+
export class DisableInputsController extends BaseController {
|
|
3
|
+
connect() {
|
|
4
|
+
}
|
|
5
|
+
disable() {
|
|
6
|
+
let shouldClear = this.hasClearValue && this.clearValue;
|
|
7
|
+
this.inputTargets.forEach((el, _) => {
|
|
8
|
+
if (shouldClear) {
|
|
9
|
+
el.value = "";
|
|
10
|
+
}
|
|
11
|
+
el.disabled = true;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
enable() {
|
|
15
|
+
this.inputTargets.forEach((el, _) => el.disabled = false);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
DisableInputsController.targets = ["input"];
|
|
19
|
+
DisableInputsController.values = {
|
|
20
|
+
clear: Boolean,
|
|
21
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BaseController } from "../../utilities/base_controller";
|
|
2
|
+
export class FallbackImageController extends BaseController {
|
|
3
|
+
initialize() {
|
|
4
|
+
this._hasLoadedSuccessfully = this._hasLoadedSuccessfully.bind(this);
|
|
5
|
+
this._success = this._success.bind(this);
|
|
6
|
+
this._fail = this._fail.bind(this);
|
|
7
|
+
}
|
|
8
|
+
connect() {
|
|
9
|
+
let element = this.el;
|
|
10
|
+
element.onerror = this._fail;
|
|
11
|
+
if (element.complete && !this._hasLoadedSuccessfully()) {
|
|
12
|
+
this._fail();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this._success();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
disconnect() {
|
|
19
|
+
this.removeSuccessClasses();
|
|
20
|
+
this.removeFailClasses();
|
|
21
|
+
}
|
|
22
|
+
_success() {
|
|
23
|
+
this.addSuccessClasses();
|
|
24
|
+
}
|
|
25
|
+
_fail() {
|
|
26
|
+
let element = this.el;
|
|
27
|
+
this.addFailClasses();
|
|
28
|
+
if (this.hasPlaceholderValue && element.src !== this.placeholderValue) {
|
|
29
|
+
this.dispatchEvent(element, this.eventName("placeholder"));
|
|
30
|
+
element.src = this.placeholderValue;
|
|
31
|
+
element.onerror = this._fail;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.dispatchEvent(element, this.eventName("fail"));
|
|
35
|
+
element.style.display = "none";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_hasLoadedSuccessfully() {
|
|
39
|
+
let element = this.el;
|
|
40
|
+
return element.naturalHeight > 0 && element.naturalWidth > 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
FallbackImageController.values = { placeholder: String };
|
|
44
|
+
FallbackImageController.classes = ["success", "fail"];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SignalBaseController } from "./base_controller";
|
|
2
|
+
export class SignalAttributeSyncController extends SignalBaseController {
|
|
3
|
+
_onSignal(payload) {
|
|
4
|
+
this.el.setAttribute(this.attributeValue, payload.value);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
SignalAttributeSyncController.values = {
|
|
8
|
+
name: String,
|
|
9
|
+
attribute: String,
|
|
10
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BaseController } from "../../utilities/base_controller";
|
|
2
|
+
import { useMutationObserver } from "../../mixins/use_mutation_observer";
|
|
3
|
+
export class TableFilterController extends BaseController {
|
|
4
|
+
get _tableBody() {
|
|
5
|
+
return this.el.tBodies[0];
|
|
6
|
+
}
|
|
7
|
+
get _tableRows() {
|
|
8
|
+
return Array.from(this._tableBody.rows);
|
|
9
|
+
}
|
|
10
|
+
connect() {
|
|
11
|
+
useMutationObserver(this, this._tableBody, this.mutate, { childList: true });
|
|
12
|
+
requestAnimationFrame(() => {
|
|
13
|
+
this.filter();
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
filter(event) {
|
|
17
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
18
|
+
if (this.searchValue == "") {
|
|
19
|
+
this._tableRows.forEach((row) => this._showElement(row));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let filter = this.searchValue.toLocaleUpperCase();
|
|
23
|
+
this._tableRows.forEach((row) => {
|
|
24
|
+
this.columns(row).forEach((col) => {
|
|
25
|
+
let text = col.textContent || col.innerText;
|
|
26
|
+
if (text.includes(filter)) {
|
|
27
|
+
this._showElement(row);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this._hideElement(row);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
clear() {
|
|
36
|
+
this.searchValue = "";
|
|
37
|
+
}
|
|
38
|
+
columns(row) {
|
|
39
|
+
return Array.from(row.cells);
|
|
40
|
+
}
|
|
41
|
+
mutate(entries) {
|
|
42
|
+
this.filter();
|
|
43
|
+
}
|
|
44
|
+
_showElement(el) {
|
|
45
|
+
el.style.display = "";
|
|
46
|
+
}
|
|
47
|
+
_hideElement(el) {
|
|
48
|
+
el.style.display = "none";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
TableFilterController.values = {
|
|
52
|
+
search: String,
|
|
53
|
+
};
|
package/dist/mixins/index.js
CHANGED
|
@@ -2,7 +2,9 @@ export * from './use_event_listener';
|
|
|
2
2
|
export * from './use_fullscreen';
|
|
3
3
|
export * from './use_geolocation';
|
|
4
4
|
export * from './use_injected_html';
|
|
5
|
+
export * from './use_intersection';
|
|
5
6
|
export * from './use_interval';
|
|
6
7
|
export * from './use_localstorage';
|
|
8
|
+
export * from './use_mutation_observer';
|
|
7
9
|
export * from './use_temporary_content';
|
|
8
10
|
export * from './use_timeout';
|