@stimulus-library/utilities 0.9.11

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.
Files changed (49) hide show
  1. package/dist/arrays.d.ts +1 -0
  2. package/dist/arrays.js +3 -0
  3. package/dist/baseController.d.ts +11 -0
  4. package/dist/baseController.js +59 -0
  5. package/dist/base_controller.d.ts +11 -0
  6. package/dist/base_controller.js +59 -0
  7. package/dist/debounce.d.ts +1 -0
  8. package/dist/debounce.js +19 -0
  9. package/dist/easingFunctions.d.ts +34 -0
  10. package/dist/easingFunctions.js +143 -0
  11. package/dist/elements.d.ts +48 -0
  12. package/dist/elements.js +102 -0
  13. package/dist/ephemeralController.d.ts +5 -0
  14. package/dist/ephemeralController.js +40 -0
  15. package/dist/ephemeral_controller.d.ts +5 -0
  16. package/dist/ephemeral_controller.js +40 -0
  17. package/dist/eventBus.d.ts +3 -0
  18. package/dist/eventBus.js +2 -0
  19. package/dist/event_bus.d.ts +1 -0
  20. package/dist/event_bus.js +2 -0
  21. package/dist/events.d.ts +2 -0
  22. package/dist/events.js +10 -0
  23. package/dist/fetchRetry.d.ts +1 -0
  24. package/dist/fetchRetry.js +11 -0
  25. package/dist/getSet.d.ts +3 -0
  26. package/dist/getSet.js +223 -0
  27. package/dist/get_set.d.ts +3 -0
  28. package/dist/get_set.js +223 -0
  29. package/dist/index.d.ts +18 -0
  30. package/dist/index.js +18 -0
  31. package/dist/logging.d.ts +5 -0
  32. package/dist/logging.js +90 -0
  33. package/dist/numbers.d.ts +1 -0
  34. package/dist/numbers.js +3 -0
  35. package/dist/reactive.d.ts +1 -0
  36. package/dist/reactive.js +23 -0
  37. package/dist/requestSubmit.d.ts +2 -0
  38. package/dist/requestSubmit.js +20 -0
  39. package/dist/request_submit.d.ts +2 -0
  40. package/dist/request_submit.js +20 -0
  41. package/dist/scroll.d.ts +10 -0
  42. package/dist/scroll.js +51 -0
  43. package/dist/stimulus.d.ts +2 -0
  44. package/dist/stimulus.js +13 -0
  45. package/dist/strings.d.ts +4 -0
  46. package/dist/strings.js +12 -0
  47. package/dist/turbo.d.ts +5 -0
  48. package/dist/turbo.js +3 -0
  49. package/package.json +50 -0
package/dist/scroll.js ADDED
@@ -0,0 +1,51 @@
1
+ export async function scrollToElement(element, { behavior = "smooth", block = "start", inline = "nearest" } = {}) {
2
+ element.scrollIntoView({ behavior, block, inline });
3
+ }
4
+ export async function scrollAbsoluteTop(element, { behavior = "smooth" } = {}) {
5
+ element.scrollTo({ top: 0, left: 0, behavior });
6
+ }
7
+ export async function scrollAbsoluteBottom(element, { behavior = "smooth" } = {}) {
8
+ if (element == window) {
9
+ element.scrollTo({ top: document.body.scrollHeight, left: 0, behavior });
10
+ }
11
+ else {
12
+ element.scrollTo({ top: element.scrollHeight, left: 0, behavior });
13
+ }
14
+ }
15
+ export async function scrollAbsoluteLeft(element, { behavior = "smooth" } = {}) {
16
+ element.scrollTo({ left: 0, behavior });
17
+ }
18
+ export async function scrollAbsoluteRight(element, { behavior = "smooth" } = {}) {
19
+ if (element == window) {
20
+ element.scrollTo({ left: document.body.scrollWidth, behavior });
21
+ }
22
+ else {
23
+ element.scrollTo({ left: element.scrollWidth, behavior });
24
+ }
25
+ }
26
+ export async function scrollUp(element, amount, { behavior = "smooth" } = {}) {
27
+ element.scrollBy({ top: -amount, left: 0, behavior });
28
+ }
29
+ export async function scrollDown(element, amount, { behavior = "smooth" } = {}) {
30
+ element.scrollBy({ top: amount, left: 0, behavior });
31
+ }
32
+ export async function scrollLeft(element, amount, { behavior = "smooth" } = {}) {
33
+ element.scrollBy({ top: 0, left: -amount, behavior });
34
+ }
35
+ export async function scrollRight(element, amount, { behavior = "smooth" } = {}) {
36
+ element.scrollBy({ top: 0, left: amount, behavior });
37
+ }
38
+ export function getScrollParent(node) {
39
+ if (!node) {
40
+ return null;
41
+ }
42
+ if (node == document.body) {
43
+ return window;
44
+ }
45
+ const overflowY = getComputedStyle(node).overflowY;
46
+ const isScrollable = overflowY !== "visible" && overflowY !== "hidden";
47
+ if (isScrollable && node.scrollHeight >= node.clientHeight) {
48
+ return node;
49
+ }
50
+ return getScrollParent(node.parentElement) || document.body;
51
+ }
@@ -0,0 +1,2 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+ export declare function controllerMethod<C extends Controller>(controller: C, methodName: string): (...args: any[]) => any;
@@ -0,0 +1,13 @@
1
+ export function controllerMethod(controller, methodName) {
2
+ // @ts-ignore
3
+ const method = controller[methodName];
4
+ if (typeof method == 'function') {
5
+ return method;
6
+ }
7
+ else if (method != undefined) {
8
+ return () => method;
9
+ }
10
+ else {
11
+ return () => void 0;
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare function upperFirst(str: string): string;
2
+ export declare function lowerFirst(str: string): string;
3
+ export declare function camelCase(str: string): string;
4
+ export declare function pascalCase(str: string): string;
@@ -0,0 +1,12 @@
1
+ export function upperFirst(str) {
2
+ return str.charAt(0).toUpperCase() + str.slice(1);
3
+ }
4
+ export function lowerFirst(str) {
5
+ return str.charAt(0).toLowerCase() + str.slice(1);
6
+ }
7
+ export function camelCase(str) {
8
+ return lowerFirst(str.replace(/[-_\s]([A-Za-z])/g, (g) => g[1].toUpperCase() + g.slice(2)));
9
+ }
10
+ export function pascalCase(str) {
11
+ return upperFirst(camelCase(str));
12
+ }
@@ -0,0 +1,5 @@
1
+ export interface TurboFrame extends HTMLElement {
2
+ nodeName: "TURBO-FRAME";
3
+ src: string;
4
+ }
5
+ export declare function isTurboFrame(element: HTMLElement): element is TurboFrame;
package/dist/turbo.js ADDED
@@ -0,0 +1,3 @@
1
+ export function isTurboFrame(element) {
2
+ return element.nodeName == "TURBO-FRAME";
3
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@stimulus-library/utilities",
3
+ "description": "A library of useful controllers for Stimulus",
4
+ "keywords": [
5
+ "stimulusjs",
6
+ "stimulus-js",
7
+ "stimulus library",
8
+ "stimulus controller",
9
+ "ruby on rails",
10
+ "ruby-on-rails"
11
+ ],
12
+ "version": "0.9.11",
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "Sub-Xaero",
16
+ "url": "https://github.com/Sub-Xaero/"
17
+ },
18
+ "homepage": "https://sub-xaero.github.io/stimulus-library/",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/Sub-Xaero/stimulus-library"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "module": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "scripts": {
29
+ "build": "tsc",
30
+ "dev": "tsc --watch",
31
+ "prepack": "npm run build",
32
+ "release": "standard-version",
33
+ "test": "cypress run",
34
+ "test:treeshake": "agadoo dist"
35
+ },
36
+ "dependencies": {
37
+ "@hotwired/stimulus": "^3.0.0",
38
+ "@stimulus-library/utilities": "*"
39
+ },
40
+ "devDependencies": {
41
+ "agadoo": "^3.0.0",
42
+ "cypress": "^12.5.1",
43
+ "fast-glob": "^3.2.12",
44
+ "lerna": "^6.5.1",
45
+ "rimraf": "^4.1.2",
46
+ "standard-version": "^9.5.0",
47
+ "typescript": "^4.9.5",
48
+ "vite": "^4.1.1"
49
+ }
50
+ }