@stimulus-library/utilities 1.0.1 → 1.0.3

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.
@@ -10,8 +10,8 @@ export class BaseController extends Controller {
10
10
  }
11
11
  return new Proxy(this, {
12
12
  get: (obj, prop) => {
13
- let returnVal = Reflect.get(obj, prop);
14
- let self = this;
13
+ const returnVal = Reflect.get(obj, prop);
14
+ const self = this;
15
15
  if ("logFormattedMessage" in this.application) {
16
16
  return returnVal;
17
17
  }
@@ -38,17 +38,17 @@ export class BaseController extends Controller {
38
38
  return this.element;
39
39
  }
40
40
  get isTurboPreview() {
41
- return document.documentElement.hasAttribute('data-turbo-preview') || document.documentElement.hasAttribute('data-turbolinks-preview');
41
+ return document.documentElement.hasAttribute("data-turbo-preview") || document.documentElement.hasAttribute("data-turbolinks-preview");
42
42
  }
43
43
  get isTurbolinksPreview() {
44
44
  return this.isTurboPreview;
45
45
  }
46
46
  get csrfToken() {
47
- return this.metaValue('csrf-token');
47
+ return this.metaValue("csrf-token");
48
48
  }
49
49
  metaValue(name) {
50
50
  const element = document.head.querySelector(`meta[name="${name}"]`);
51
- return element?.getAttribute('content') || null;
51
+ return element?.getAttribute("content") || null;
52
52
  }
53
53
  eventName(eventName) {
54
54
  return `${this.identifier}:${eventName}`;
@@ -8,6 +8,9 @@ const c2 = c1 * 1.525;
8
8
  const c3 = c1 + 1;
9
9
  const c4 = (2 * PI) / 3;
10
10
  const c5 = (2 * PI) / 4.5;
11
+ // interface EasingDictionary {
12
+ // [easing: string]: EasingFunction;
13
+ // }
11
14
  const bounceOut = function (x) {
12
15
  const n1 = 7.5625;
13
16
  const d1 = 2.75;
package/dist/elements.js CHANGED
@@ -59,21 +59,21 @@ export function isTypeOfFormInputElement(element) {
59
59
  return isHTMLInputElement(element) || isHTMLSelectElement(element) || isHTMLTextAreaElement(element);
60
60
  }
61
61
  export function createHiddenButton(type) {
62
- let button = document.createElement('button');
62
+ const button = document.createElement("button");
63
63
  button.type = type;
64
- button.style.display = 'none';
65
- button.dataset.sythentic = 'true';
64
+ button.style.display = "none";
65
+ button.dataset.sythentic = "true";
66
66
  return button;
67
67
  }
68
68
  export function createHiddenInput(name, value) {
69
- let input = document.createElement('input');
70
- input.type = 'hidden';
69
+ const input = document.createElement("input");
70
+ input.type = "hidden";
71
71
  input.name = name;
72
72
  input.value = value;
73
73
  return input;
74
74
  }
75
75
  export function insertElement(targetElement, insertPosition, element) {
76
- let createdElement = targetElement.insertAdjacentElement(insertPosition, element);
76
+ const createdElement = targetElement.insertAdjacentElement(insertPosition, element);
77
77
  if (!createdElement) {
78
78
  throw new Error(`Failed to insert element ${element.nodeName} into ${targetElement.nodeName}`);
79
79
  }
@@ -86,7 +86,7 @@ export function insertHiddenButton(type, targetElement, insertPosition) {
86
86
  return insertElement(targetElement, insertPosition, createHiddenButton(type));
87
87
  }
88
88
  export function getAllRadiosInGroup(radio) {
89
- let parent = radio.form || document;
89
+ const parent = radio.form || document;
90
90
  return Array.from(parent.querySelectorAll(`input[type="radio"][name="${radio.name}"]`));
91
91
  }
92
92
  export function getOtherRadiosInGroup(radio) {
@@ -11,7 +11,7 @@ export class EphemeralController extends BaseController {
11
11
  // If there are no controllers left, remove the attribute
12
12
  delete element.dataset.controller;
13
13
  }
14
- let substringIdentifierValueRegex = new RegExp(`(\\s|^)${this.identifier}\\..+?(\\s|$)`, "g");
14
+ const substringIdentifierValueRegex = new RegExp(`(\\s|^)${this.identifier}\\..+?(\\s|$)`, "g");
15
15
  // @ts-ignore
16
16
  element.dataset.target = element.dataset.target?.replaceAll(substringIdentifierValueRegex, "") || "";
17
17
  delete element.dataset[camelCase(`${this.identifier}-target`)];
@@ -27,12 +27,12 @@ export class EphemeralController extends BaseController {
27
27
  delete element.dataset.action;
28
28
  }
29
29
  // @ts-ignore
30
- let values = this.constructor.values;
30
+ const values = this.constructor.values;
31
31
  if (values) {
32
32
  Object.keys(values).forEach(val => delete element.dataset[camelCase(`${this.identifier}-${val}-value`)]);
33
33
  }
34
34
  // @ts-ignore
35
- let classes = this.constructor.classes;
35
+ const classes = this.constructor.classes;
36
36
  if (classes) {
37
37
  Object.keys(classes).forEach(val => delete element.dataset[camelCase(`${this.identifier}-${val}-class`)]);
38
38
  }
package/dist/event_bus.js CHANGED
@@ -1,2 +1,2 @@
1
- import mitt from 'mitt';
1
+ import mitt from "mitt";
2
2
  export const EventBus = mitt();
package/dist/events.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { logEvent } from "./logging";
2
2
  export function dispatchEvent(controller, element, eventName, options = {}) {
3
- let mergedOptions = Object.assign({}, { bubbles: true, cancelable: true, detail: { target: element } }, options);
3
+ const mergedOptions = Object.assign({}, { bubbles: true, cancelable: true, detail: { target: element } }, options);
4
4
  if (!mergedOptions.detail.target) {
5
5
  mergedOptions.detail.target = element;
6
6
  }
7
- let event = new CustomEvent(eventName, mergedOptions);
7
+ const event = new CustomEvent(eventName, mergedOptions);
8
8
  logEvent(controller, eventName, event, element);
9
9
  element.dispatchEvent(event);
10
10
  }
package/dist/get_set.js CHANGED
@@ -51,16 +51,16 @@ const reIsPlainProp = /^\w*$/;
51
51
  const rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
52
52
  const reIsUint = /^(?:0|[1-9]\d*)$/;
53
53
  const reEscapeChar = /\\(\\)?/g;
54
- const symbolTag = '[object Symbol]';
54
+ const symbolTag = "[object Symbol]";
55
55
  const hasOwnProperty = Object.prototype.hasOwnProperty;
56
56
  const isArray = Array.isArray;
57
57
  const symbolProto = Symbol ? Symbol.prototype : undefined;
58
- const symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
58
+ // const symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
59
59
  const symbolToString = symbolProto ? symbolProto.toString : undefined;
60
60
  const INFINITY = 1 / 0;
61
61
  const MAX_SAFE_INTEGER = 9007199254740991;
62
- const MAX_INTEGER = 1.7976931348623157e+308;
63
- const NAN = 0 / 0;
62
+ // const MAX_INTEGER = 1.7976931348623157e+308;
63
+ // const NAN = 0 / 0;
64
64
  function arrayMap(array, iteratee) {
65
65
  let index = -1;
66
66
  const length = array == null ? 0 : array.length;
@@ -72,30 +72,30 @@ function arrayMap(array, iteratee) {
72
72
  }
73
73
  function baseToString(value) {
74
74
  // Exit early for strings to avoid a performance hit in some environments.
75
- if (typeof value == 'string') {
75
+ if (typeof value == "string") {
76
76
  return value;
77
77
  }
78
78
  if (isArray(value)) {
79
79
  // Recursively convert values (susceptible to call stack limits).
80
- return arrayMap(value, baseToString) + '';
80
+ return arrayMap(value, baseToString) + "";
81
81
  }
82
82
  if (isSymbol(value)) {
83
- return symbolToString ? symbolToString.call(value) : '';
83
+ return symbolToString ? symbolToString.call(value) : "";
84
84
  }
85
- const result = (value + '');
86
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
85
+ const result = (value + "");
86
+ return (result == "0" && (1 / value) == -INFINITY) ? "-0" : result;
87
87
  }
88
88
  function toString(value) {
89
- return value == null ? '' : baseToString(value);
89
+ return value == null ? "" : baseToString(value);
90
90
  }
91
91
  export function stringToPath(str) {
92
92
  const result = [];
93
93
  if (str.charCodeAt(0) === 46 /* . */) {
94
- result.push('');
94
+ result.push("");
95
95
  }
96
96
  // @ts-ignore
97
97
  str.replace(rePropName, function (match, number, quote, subString) {
98
- result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
98
+ result.push(quote ? subString.replace(reEscapeChar, "$1") : (number || match));
99
99
  });
100
100
  return result;
101
101
  }
@@ -111,18 +111,18 @@ function castPath(value, object) {
111
111
  return isKey(value, object) ? [value] : stringToPath(toString(value));
112
112
  }
113
113
  function toKey(value) {
114
- if (typeof value == 'string' || isSymbol(value)) {
114
+ if (typeof value == "string" || isSymbol(value)) {
115
115
  return value;
116
116
  }
117
- let result = (value + '');
118
- return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
117
+ const result = (value + "");
118
+ return (result == "0" && (1 / value) == -Infinity) ? "-0" : result;
119
119
  }
120
120
  function isKey(value, object) {
121
121
  if (isArray(value)) {
122
122
  return false;
123
123
  }
124
- let type = typeof value;
125
- if (type == 'number' || type == 'boolean' ||
124
+ const type = typeof value;
125
+ if (type == "number" || type == "boolean" ||
126
126
  value == null || isSymbol(value)) {
127
127
  return true;
128
128
  }
@@ -130,10 +130,10 @@ function isKey(value, object) {
130
130
  (object != null && value in Object(object));
131
131
  }
132
132
  function isObjectLike(value) {
133
- return value != null && typeof value == 'object';
133
+ return value != null && typeof value == "object";
134
134
  }
135
135
  function isSymbol(value) {
136
- return typeof value == 'symbol' ||
136
+ return typeof value == "symbol" ||
137
137
  (isObjectLike(value) && baseGetTag(value) == symbolTag);
138
138
  }
139
139
  function baseGetTag(value) {
@@ -145,7 +145,7 @@ function objectToString(value) {
145
145
  }
146
146
  const objectProto = Object.prototype;
147
147
  function baseGet(object, path) {
148
- let castedPath = castPath(path, object);
148
+ const castedPath = castPath(path, object);
149
149
  let index = 0;
150
150
  const length = castedPath.length;
151
151
  while (object != null && index < length) {
@@ -156,13 +156,13 @@ function baseGet(object, path) {
156
156
  }
157
157
  function isObject(value) {
158
158
  const type = typeof value;
159
- return value != null && (type == 'object' || type == 'function');
159
+ return value != null && (type == "object" || type == "function");
160
160
  }
161
161
  function isIndex(value, length = null) {
162
- let type = typeof value;
162
+ const type = typeof value;
163
163
  length = length == null ? MAX_SAFE_INTEGER : length;
164
164
  // @ts-ignore
165
- return !!length && (type == 'number' || (type != 'symbol' && reIsUint.test(value))) && (value > -1 && value % 1 == 0 && value < length);
165
+ return !!length && (type == "number" || (type != "symbol" && reIsUint.test(value))) && (value > -1 && value % 1 == 0 && value < length);
166
166
  }
167
167
  function eq(value, other) {
168
168
  return value === other || (value !== value && other !== other);
@@ -176,12 +176,12 @@ function assignValue(object, key, value) {
176
176
  }
177
177
  }
178
178
  function baseAssignValue(object, key, value) {
179
- if (key == '__proto__' && defineProperty) {
179
+ if (key == "__proto__" && defineProperty) {
180
180
  defineProperty(object, key, {
181
- 'configurable': true,
182
- 'enumerable': true,
183
- 'value': value,
184
- 'writable': true,
181
+ "configurable": true,
182
+ "enumerable": true,
183
+ "value": value,
184
+ "writable": true,
185
185
  });
186
186
  }
187
187
  else {
@@ -193,7 +193,7 @@ function baseSet(object, path, value) {
193
193
  if (!isObject(object)) {
194
194
  return object;
195
195
  }
196
- let castedPath = castPath(path, object);
196
+ const castedPath = castPath(path, object);
197
197
  let index = -1;
198
198
  const length = castedPath.length;
199
199
  const lastIndex = length - 1;
package/dist/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  export { BaseController } from "./base_controller";
2
2
  export { EphemeralController } from "./ephemeral_controller";
3
- export * from './arrays';
4
- export * from './debounce';
5
- export * from './easing_functions';
6
- export * from './elements';
7
- export * from './event_bus';
8
- export * from './events';
9
- export * from './fetch_retry';
10
- export * from './get_set';
11
- export * from './logging';
12
- export * from './numbers';
13
- export * from './reactive';
14
- export * from './request_submit';
15
- export * from './scroll';
16
- export * from './stimulus';
17
- export * from './strings';
18
- export * from './turbo';
3
+ export * from "./arrays";
4
+ export * from "./debounce";
5
+ export * from "./easing_functions";
6
+ export * from "./elements";
7
+ export * from "./event_bus";
8
+ export * from "./events";
9
+ export * from "./fetch_retry";
10
+ export * from "./get_set";
11
+ export * from "./logging";
12
+ export * from "./numbers";
13
+ export * from "./reactive";
14
+ export * from "./request_submit";
15
+ export * from "./scroll";
16
+ export * from "./stimulus";
17
+ export * from "./strings";
18
+ export * from "./turbo";
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  export { BaseController } from "./base_controller";
2
2
  export { EphemeralController } from "./ephemeral_controller";
3
- export * from './arrays';
4
- export * from './debounce';
5
- export * from './easing_functions';
6
- export * from './elements';
7
- export * from './event_bus';
8
- export * from './events';
9
- export * from './fetch_retry';
10
- export * from './get_set';
11
- export * from './logging';
12
- export * from './numbers';
13
- export * from './reactive';
14
- export * from './request_submit';
15
- export * from './scroll';
16
- export * from './stimulus';
17
- export * from './strings';
18
- export * from './turbo';
3
+ export * from "./arrays";
4
+ export * from "./debounce";
5
+ export * from "./easing_functions";
6
+ export * from "./elements";
7
+ export * from "./event_bus";
8
+ export * from "./events";
9
+ export * from "./fetch_retry";
10
+ export * from "./get_set";
11
+ export * from "./logging";
12
+ export * from "./numbers";
13
+ export * from "./reactive";
14
+ export * from "./request_submit";
15
+ export * from "./scroll";
16
+ export * from "./stimulus";
17
+ export * from "./strings";
18
+ export * from "./turbo";
package/dist/logging.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Controller } from "@hotwired/stimulus";
2
2
  export declare function logProperty(prop: string): boolean;
3
- export declare function log(controller: Controller, functionName: string, args?: {}): void;
4
- export declare function warn(controller: Controller, warning: string, args?: {}): void;
3
+ export declare function log(controller: Controller, functionName: string, args?: object): void;
4
+ export declare function warn(controller: Controller, warning: string, args?: object): void;
5
5
  export declare function logEvent(controller: Controller, eventName: string, event: CustomEvent, element: HTMLElement): void;
package/dist/logging.js CHANGED
@@ -41,7 +41,7 @@ export function log(controller, functionName, args = {}) {
41
41
  if (!controller.application.debug) {
42
42
  return;
43
43
  }
44
- let logger = console;
44
+ const logger = console;
45
45
  logger.groupCollapsed(...colorize(controller.identifier, "#3B82F6"), `#${functionName}`);
46
46
  logger.log({
47
47
  element: controller.element,
@@ -54,7 +54,7 @@ export function warn(controller, warning, args = {}) {
54
54
  if (!controller.application.debug) {
55
55
  return;
56
56
  }
57
- let logger = console;
57
+ const logger = console;
58
58
  logger.groupCollapsed(...colorize(controller.identifier, "#F39B1AFF"), `!! ${warning} !!`);
59
59
  logger.warn({
60
60
  element: controller.element,
@@ -67,7 +67,7 @@ export function logEvent(controller, eventName, event, element) {
67
67
  if (!controller.application.debug) {
68
68
  return;
69
69
  }
70
- let logger = console;
70
+ const logger = console;
71
71
  logger.groupCollapsed(...colorizeMany([
72
72
  { text: controller.identifier, color: "#3B82F6" },
73
73
  { text: eventName, color: "#0be000" },
@@ -82,7 +82,7 @@ function colorize(text, color) {
82
82
  }
83
83
  function colorizeMany(texts) {
84
84
  let str = "";
85
- let colors = texts.flatMap((x) => {
85
+ const colors = texts.flatMap((x) => {
86
86
  str += `%c${x.text}%c `;
87
87
  return [`color: ${x.color}`, "color: unset"];
88
88
  });
@@ -1 +1 @@
1
- export declare function reactive<T extends Object>(object: T): T;
1
+ export declare function reactive<T extends object>(object: T): T;
package/dist/reactive.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function reactive(object) {
2
- if (object === null || typeof object !== 'object') {
2
+ if (object === null || typeof object !== "object") {
3
3
  return object;
4
4
  }
5
5
  for (const property in object) {
@@ -4,17 +4,17 @@ export function requestSubmit(form) {
4
4
  form.requestSubmit();
5
5
  }
6
6
  else {
7
- let button = form.querySelector('button[type="submit"]');
7
+ let button = form.querySelector("button[type=\"submit\"]");
8
8
  if (!button) {
9
- button = insertHiddenButton("submit", form, 'beforeend');
9
+ button = insertHiddenButton("submit", form, "beforeend");
10
10
  }
11
11
  button.click();
12
12
  }
13
13
  }
14
14
  export function requestReset(form) {
15
- let button = form.querySelector('button[type="reset"]');
15
+ let button = form.querySelector("button[type=\"reset\"]");
16
16
  if (!button) {
17
- button = insertHiddenButton("reset", form, 'beforeend');
17
+ button = insertHiddenButton("reset", form, "beforeend");
18
18
  }
19
19
  button.click();
20
20
  }
package/dist/stimulus.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export function controllerMethod(controller, methodName) {
2
2
  // @ts-ignore
3
3
  const method = controller[methodName];
4
- if (typeof method == 'function') {
4
+ if (typeof method == "function") {
5
5
  return method;
6
6
  }
7
7
  else if (method != undefined) {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "ruby on rails",
10
10
  "ruby-on-rails"
11
11
  ],
12
- "version": "1.0.1",
12
+ "version": "1.0.3",
13
13
  "license": "MIT",
14
14
  "author": {
15
15
  "name": "Sub-Xaero",
@@ -23,6 +23,7 @@
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
+ "main": "dist/index.js",
26
27
  "module": "dist/index.js",
27
28
  "types": "dist/index.d.ts",
28
29
  "scripts": {
@@ -35,7 +36,7 @@
35
36
  },
36
37
  "dependencies": {
37
38
  "@hotwired/stimulus": "^3.0.0",
38
- "@stimulus-library/utilities": "^1.0.0-alpha.2",
39
+ "@stimulus-library/utilities": "^1.0.2",
39
40
  "mitt": "^3.0.0"
40
41
  },
41
42
  "devDependencies": {
@@ -49,12 +50,12 @@
49
50
  "lerna": "^7.0.0",
50
51
  "mocha": "^10.2.0",
51
52
  "rimraf": "^5.0.1",
52
- "sinon": "^15.1.0",
53
+ "sinon": "^16.0.0",
53
54
  "sinon-chai": "^3.7.0",
54
55
  "standard-version": "^9.5.0",
55
56
  "ts-node": "^10.9.1",
56
57
  "typescript": "^5.1.3",
57
58
  "vite": "^4.1.1"
58
59
  },
59
- "gitHead": "26a7da01746a2bdf8a2a731b79d37256b789bdc0"
60
+ "gitHead": "0b130c61801abbfba6e0a8bcaf4e4cb6b7f05047"
60
61
  }