@stimulus-library/utilities 1.0.0-alpha.1 → 1.0.0-alpha.2

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.
@@ -1 +1,3 @@
1
- export declare const EventBus: any;
1
+ export declare const EventBus: import("mitt").Emitter<{
2
+ [idx: string]: any;
3
+ }>;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- export { BaseController } from "./baseController";
2
- export { EphemeralController } from "./ephemeralController";
1
+ export { BaseController } from "./base_controller";
2
+ export { EphemeralController } from "./ephemeral_controller";
3
3
  export * from './arrays';
4
4
  export * from './debounce';
5
- export * from './easingFunctions';
5
+ export * from './easing_functions';
6
6
  export * from './elements';
7
- export * from './eventBus';
7
+ export * from './event_bus';
8
8
  export * from './events';
9
- export * from './fetchRetry';
10
- export * from './getSet';
9
+ export * from './fetch_retry';
10
+ export * from './get_set';
11
11
  export * from './logging';
12
12
  export * from './numbers';
13
13
  export * from './reactive';
14
- export * from './requestSubmit';
14
+ export * from './request_submit';
15
15
  export * from './scroll';
16
16
  export * from './stimulus';
17
17
  export * from './strings';
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
- export { BaseController } from "./baseController";
2
- export { EphemeralController } from "./ephemeralController";
1
+ export { BaseController } from "./base_controller";
2
+ export { EphemeralController } from "./ephemeral_controller";
3
3
  export * from './arrays';
4
4
  export * from './debounce';
5
- export * from './easingFunctions';
5
+ export * from './easing_functions';
6
6
  export * from './elements';
7
- export * from './eventBus';
7
+ export * from './event_bus';
8
8
  export * from './events';
9
- export * from './fetchRetry';
10
- export * from './getSet';
9
+ export * from './fetch_retry';
10
+ export * from './get_set';
11
11
  export * from './logging';
12
12
  export * from './numbers';
13
13
  export * from './reactive';
14
- export * from './requestSubmit';
14
+ export * from './request_submit';
15
15
  export * from './scroll';
16
16
  export * from './stimulus';
17
17
  export * from './strings';
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "ruby on rails",
10
10
  "ruby-on-rails"
11
11
  ],
12
- "version": "1.0.0-alpha.1",
12
+ "version": "1.0.0-alpha.2",
13
13
  "license": "MIT",
14
14
  "author": {
15
15
  "name": "Sub-Xaero",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@hotwired/stimulus": "^3.0.0",
38
- "@stimulus-library/utilities": "^1.0.0-alpha.1",
38
+ "@stimulus-library/utilities": "^1.0.0-alpha.2",
39
39
  "mitt": "^3.0.0"
40
40
  },
41
41
  "devDependencies": {
@@ -1,11 +0,0 @@
1
- import { Context, Controller } from "@hotwired/stimulus";
2
- export declare class BaseController extends Controller {
3
- constructor(context: Context);
4
- get el(): HTMLElement;
5
- get isTurboPreview(): boolean;
6
- get isTurbolinksPreview(): boolean;
7
- get csrfToken(): string | null;
8
- metaValue(name: string): string | null;
9
- eventName(eventName: string): string;
10
- dispatchEvent(element: HTMLElement, eventName: string, options?: CustomEventInit): void;
11
- }
@@ -1,59 +0,0 @@
1
- import { Controller } from "@hotwired/stimulus";
2
- import { log, logProperty } from "./logging";
3
- import { dispatchEvent } from "./events";
4
- export class BaseController extends Controller {
5
- constructor(context) {
6
- super(context);
7
- // @ts-ignore
8
- if (!this.application.debug) {
9
- return this;
10
- }
11
- return new Proxy(this, {
12
- get: (obj, prop) => {
13
- let returnVal = Reflect.get(obj, prop);
14
- let self = this;
15
- if ("logFormattedMessage" in this.application) {
16
- return returnVal;
17
- }
18
- if (logProperty(prop.toString())) {
19
- if (typeof returnVal == "function") {
20
- return new Proxy(returnVal, {
21
- apply(target, thisArg, argArray) {
22
- log(self, prop.toString(), {
23
- args: argArray,
24
- });
25
- return Reflect.apply(target, thisArg, argArray);
26
- },
27
- });
28
- }
29
- else {
30
- log(this, prop.toString());
31
- }
32
- }
33
- return returnVal;
34
- },
35
- });
36
- }
37
- get el() {
38
- return this.element;
39
- }
40
- get isTurboPreview() {
41
- return document.documentElement.hasAttribute('data-turbo-preview') || document.documentElement.hasAttribute('data-turbolinks-preview');
42
- }
43
- get isTurbolinksPreview() {
44
- return this.isTurboPreview;
45
- }
46
- get csrfToken() {
47
- return this.metaValue('csrf-token');
48
- }
49
- metaValue(name) {
50
- const element = document.head.querySelector(`meta[name="${name}"]`);
51
- return element?.getAttribute('content') || null;
52
- }
53
- eventName(eventName) {
54
- return `${this.identifier}:${eventName}`;
55
- }
56
- dispatchEvent(element, eventName, options = {}) {
57
- dispatchEvent(this, element, eventName, options);
58
- }
59
- }
@@ -1,5 +0,0 @@
1
- import { BaseController } from "./baseController";
2
- export declare class EphemeralController extends BaseController {
3
- _cleanupSelf(): void;
4
- cleanup(element: HTMLElement): void;
5
- }
@@ -1,40 +0,0 @@
1
- import { camelCase } from "./strings";
2
- import { BaseController } from "./baseController";
3
- export class EphemeralController extends BaseController {
4
- _cleanupSelf() {
5
- this.cleanup(this.el);
6
- }
7
- cleanup(element) {
8
- // @ts-ignore
9
- element.dataset.controller = element.dataset.controller?.replaceAll(new RegExp(`(\\s|^)${this.identifier}(\\s|$)`, "g"), "") || "";
10
- if (element.dataset.controller == "") {
11
- // If there are no controllers left, remove the attribute
12
- delete element.dataset.controller;
13
- }
14
- let substringIdentifierValueRegex = new RegExp(`(\\s|^)${this.identifier}\\..+?(\\s|$)`, "g");
15
- // @ts-ignore
16
- element.dataset.target = element.dataset.target?.replaceAll(substringIdentifierValueRegex, "") || "";
17
- delete element.dataset[camelCase(`${this.identifier}-target`)];
18
- if (element.dataset.target == "") {
19
- // If there are no targets left, remove the attribute
20
- delete element.dataset.target;
21
- }
22
- // @ts-ignore
23
- element.dataset.action = element.dataset.target?.replaceAll(substringIdentifierValueRegex, "") || "";
24
- delete element.dataset[camelCase(`${this.identifier}-action`)];
25
- if (element.dataset.action == "") {
26
- // If there are no actions left, remove the attribute
27
- delete element.dataset.action;
28
- }
29
- // @ts-ignore
30
- let values = this.constructor.values;
31
- if (values) {
32
- Object.keys(values).forEach(val => delete element.dataset[camelCase(`${this.identifier}-${val}-value`)]);
33
- }
34
- // @ts-ignore
35
- let classes = this.constructor.classes;
36
- if (classes) {
37
- Object.keys(classes).forEach(val => delete element.dataset[camelCase(`${this.identifier}-${val}-class`)]);
38
- }
39
- }
40
- }
@@ -1,3 +0,0 @@
1
- export declare const EventBus: import("mitt").Emitter<{
2
- [idx: string]: any;
3
- }>;
package/dist/eventBus.js DELETED
@@ -1,2 +0,0 @@
1
- import mitt from 'mitt';
2
- export const EventBus = mitt();
package/dist/getSet.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function stringToPath(str: string): string[];
2
- export declare function get<T extends object>(object: T, path: string, defaultValue?: any): any;
3
- export declare function set<T extends object>(object: T, path: string, value: any): any;
package/dist/getSet.js DELETED
@@ -1,223 +0,0 @@
1
- // The following code is extracted and modified from lodash v4.17.21
2
- // Original copyright and license information is below.
3
- //
4
- // The MIT License
5
- //
6
- // Copyright JS Foundation and other contributors <https://js.foundation/>
7
- //
8
- // Based on Underscore.js, copyright Jeremy Ashkenas,
9
- // DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
10
- //
11
- // This software consists of voluntary contributions made by many
12
- // individuals. For exact contribution history, see the revision history
13
- // available at https://github.com/lodash/lodash
14
- //
15
- // The following license applies to all parts of this software except as
16
- // documented below:
17
- //
18
- // ====
19
- //
20
- // Permission is hereby granted, free of charge, to any person obtaining
21
- // a copy of this software and associated documentation files (the
22
- // "Software"), to deal in the Software without restriction, including
23
- // without limitation the rights to use, copy, modify, merge, publish,
24
- // distribute, sublicense, and/or sell copies of the Software, and to
25
- // permit persons to whom the Software is furnished to do so, subject to
26
- // the following conditions:
27
- //
28
- // The above copyright notice and this permission notice shall be
29
- // included in all copies or substantial portions of the Software.
30
- //
31
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38
- //
39
- // ====
40
- //
41
- // Copyright and related rights for sample code are waived via CC0. Sample
42
- // code is defined as all source code displayed within the prose of the
43
- // documentation.
44
- //
45
- // CC0: http://creativecommons.org/publicdomain/zero/1.0/
46
- //
47
- // ====
48
- /** Used to match property names within property paths. */
49
- const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
50
- const reIsPlainProp = /^\w*$/;
51
- const rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
52
- const reIsUint = /^(?:0|[1-9]\d*)$/;
53
- const reEscapeChar = /\\(\\)?/g;
54
- const symbolTag = '[object Symbol]';
55
- const hasOwnProperty = Object.prototype.hasOwnProperty;
56
- const isArray = Array.isArray;
57
- const symbolProto = Symbol ? Symbol.prototype : undefined;
58
- const symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
59
- const symbolToString = symbolProto ? symbolProto.toString : undefined;
60
- const INFINITY = 1 / 0;
61
- const MAX_SAFE_INTEGER = 9007199254740991;
62
- const MAX_INTEGER = 1.7976931348623157e+308;
63
- const NAN = 0 / 0;
64
- function arrayMap(array, iteratee) {
65
- let index = -1;
66
- const length = array == null ? 0 : array.length;
67
- const result = Array(length);
68
- while (++index < length) {
69
- result[index] = iteratee(array[index], index, array);
70
- }
71
- return result;
72
- }
73
- function baseToString(value) {
74
- // Exit early for strings to avoid a performance hit in some environments.
75
- if (typeof value == 'string') {
76
- return value;
77
- }
78
- if (isArray(value)) {
79
- // Recursively convert values (susceptible to call stack limits).
80
- return arrayMap(value, baseToString) + '';
81
- }
82
- if (isSymbol(value)) {
83
- return symbolToString ? symbolToString.call(value) : '';
84
- }
85
- const result = (value + '');
86
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
87
- }
88
- function toString(value) {
89
- return value == null ? '' : baseToString(value);
90
- }
91
- export function stringToPath(str) {
92
- const result = [];
93
- if (str.charCodeAt(0) === 46 /* . */) {
94
- result.push('');
95
- }
96
- // @ts-ignore
97
- str.replace(rePropName, function (match, number, quote, subString) {
98
- result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
99
- });
100
- return result;
101
- }
102
- function defineProperty(object, key, value) {
103
- // @ts-ignore
104
- object[key] = value;
105
- return object;
106
- }
107
- function castPath(value, object) {
108
- if (isArray(value)) {
109
- return value;
110
- }
111
- return isKey(value, object) ? [value] : stringToPath(toString(value));
112
- }
113
- function toKey(value) {
114
- if (typeof value == 'string' || isSymbol(value)) {
115
- return value;
116
- }
117
- let result = (value + '');
118
- return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
119
- }
120
- function isKey(value, object) {
121
- if (isArray(value)) {
122
- return false;
123
- }
124
- let type = typeof value;
125
- if (type == 'number' || type == 'boolean' ||
126
- value == null || isSymbol(value)) {
127
- return true;
128
- }
129
- return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
130
- (object != null && value in Object(object));
131
- }
132
- function isObjectLike(value) {
133
- return value != null && typeof value == 'object';
134
- }
135
- function isSymbol(value) {
136
- return typeof value == 'symbol' ||
137
- (isObjectLike(value) && baseGetTag(value) == symbolTag);
138
- }
139
- function baseGetTag(value) {
140
- // @ts-ignore
141
- return objectToString.call(value);
142
- }
143
- function objectToString(value) {
144
- return objectProto.toString.call(value);
145
- }
146
- const objectProto = Object.prototype;
147
- function baseGet(object, path) {
148
- let castedPath = castPath(path, object);
149
- let index = 0;
150
- const length = castedPath.length;
151
- while (object != null && index < length) {
152
- // @ts-ignore
153
- object = object[toKey(castedPath[index++])];
154
- }
155
- return (index && index == length) ? object : undefined;
156
- }
157
- function isObject(value) {
158
- const type = typeof value;
159
- return value != null && (type == 'object' || type == 'function');
160
- }
161
- function isIndex(value, length = null) {
162
- let type = typeof value;
163
- length = length == null ? MAX_SAFE_INTEGER : length;
164
- // @ts-ignore
165
- return !!length && (type == 'number' || (type != 'symbol' && reIsUint.test(value))) && (value > -1 && value % 1 == 0 && value < length);
166
- }
167
- function eq(value, other) {
168
- return value === other || (value !== value && other !== other);
169
- }
170
- function assignValue(object, key, value) {
171
- // @ts-ignore
172
- const objValue = object[key];
173
- if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
174
- (value === undefined && !(key in object))) {
175
- baseAssignValue(object, key, value);
176
- }
177
- }
178
- function baseAssignValue(object, key, value) {
179
- if (key == '__proto__' && defineProperty) {
180
- defineProperty(object, key, {
181
- 'configurable': true,
182
- 'enumerable': true,
183
- 'value': value,
184
- 'writable': true,
185
- });
186
- }
187
- else {
188
- // @ts-ignore
189
- object[key] = value;
190
- }
191
- }
192
- function baseSet(object, path, value) {
193
- if (!isObject(object)) {
194
- return object;
195
- }
196
- let castedPath = castPath(path, object);
197
- let index = -1;
198
- const length = castedPath.length;
199
- const lastIndex = length - 1;
200
- let nested = object;
201
- while (nested != null && ++index < length) {
202
- const key = toKey(castedPath[index]);
203
- let newValue = value;
204
- if (index != lastIndex) {
205
- // @ts-ignore
206
- const objValue = nested[key];
207
- newValue = isObject(objValue)
208
- ? objValue
209
- : (isIndex(castedPath[index + 1]) ? [] : {});
210
- }
211
- assignValue(nested, key, newValue);
212
- // @ts-ignore
213
- nested = nested[key];
214
- }
215
- return object;
216
- }
217
- export function get(object, path, defaultValue = null) {
218
- const result = object == null ? undefined : baseGet(object, path);
219
- return result === undefined ? defaultValue : result;
220
- }
221
- export function set(object, path, value) {
222
- return object == null ? object : baseSet(object, path, value);
223
- }
@@ -1,2 +0,0 @@
1
- export declare function requestSubmit(form: HTMLFormElement): void;
2
- export declare function requestReset(form: HTMLFormElement): void;
@@ -1,20 +0,0 @@
1
- import { insertHiddenButton } from "./elements";
2
- export function requestSubmit(form) {
3
- if (form.requestSubmit) {
4
- form.requestSubmit();
5
- }
6
- else {
7
- let button = form.querySelector('button[type="submit"]');
8
- if (!button) {
9
- button = insertHiddenButton("submit", form, 'beforeend');
10
- }
11
- button.click();
12
- }
13
- }
14
- export function requestReset(form) {
15
- let button = form.querySelector('button[type="reset"]');
16
- if (!button) {
17
- button = insertHiddenButton("reset", form, 'beforeend');
18
- }
19
- button.click();
20
- }
File without changes
File without changes