stimulus-use
Advanced tools
Comparing version 0.25.0 to 0.25.1
import { Controller } from 'stimulus'; | ||
import { Logger } from "./logger"; | ||
import { Logger } from './logger'; | ||
export interface StimulusUseOptions { | ||
@@ -4,0 +4,0 @@ debug?: boolean; |
@@ -5,3 +5,3 @@ const defaultOptions = { | ||
dispatchEvent: true, | ||
eventPrefix: true, | ||
eventPrefix: true | ||
}; | ||
@@ -44,3 +44,3 @@ export class StimulusUse { | ||
composed, | ||
detail, | ||
detail | ||
}); | ||
@@ -47,0 +47,0 @@ return customEvent; |
@@ -29,3 +29,3 @@ export const method = (controller, methodName) => { | ||
composed, | ||
detail, | ||
detail | ||
}); | ||
@@ -36,8 +36,8 @@ return customEvent; | ||
const rect = el.getBoundingClientRect(); | ||
const windowHeight = (window.innerHeight || document.documentElement.clientHeight); | ||
const windowWidth = (window.innerWidth || document.documentElement.clientWidth); | ||
const vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0); | ||
const horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0); | ||
return (vertInView && horInView); | ||
const windowHeight = window.innerHeight || document.documentElement.clientHeight; | ||
const windowWidth = window.innerWidth || document.documentElement.clientWidth; | ||
const vertInView = rect.top <= windowHeight && rect.top + rect.height >= 0; | ||
const horInView = rect.left <= windowWidth && rect.left + rect.width >= 0; | ||
return vertInView && horInView; | ||
} | ||
//# sourceMappingURL=index.js.map |
import { Controller, Context } from 'stimulus'; | ||
import { DispatchOptions } from "../use-dispatch"; | ||
import { DispatchOptions } from '../use-dispatch'; | ||
export declare class ApplicationController extends Controller { | ||
@@ -4,0 +4,0 @@ options?: DispatchOptions; |
@@ -6,4 +6,5 @@ import { useDispatch } from '../use-dispatch/index'; | ||
get() { | ||
return document.documentElement.hasAttribute('data-turbolinks-preview') || document.documentElement.hasAttribute('data-turbo-preview'); | ||
}, | ||
return (document.documentElement.hasAttribute('data-turbolinks-preview') || | ||
document.documentElement.hasAttribute('data-turbo-preview')); | ||
} | ||
}); | ||
@@ -14,3 +15,3 @@ // getter to detect if a Stimulus controller is connected | ||
return !!Array.from(this.context.module.connectedContexts).find(c => c === this.context); | ||
}, | ||
} | ||
}); | ||
@@ -21,3 +22,3 @@ // getter to get the csrf token | ||
return this.metaValue('csrf-token'); | ||
}, | ||
} | ||
}); | ||
@@ -29,5 +30,5 @@ useDispatch(controller, options); | ||
return element && element.getAttribute('content'); | ||
}, | ||
} | ||
}); | ||
}; | ||
//# sourceMappingURL=use-application.js.map |
@@ -6,3 +6,3 @@ import { composeEventName, extendedEvent, isElementInViewport } from '../support/index'; | ||
dispatchEvent: true, | ||
eventPrefix: true, | ||
eventPrefix: true | ||
}; | ||
@@ -44,3 +44,3 @@ export const useClickOutside = (controller, options = {}) => { | ||
controllerDisconnect(); | ||
}, | ||
} | ||
}); | ||
@@ -47,0 +47,0 @@ observe(); |
@@ -22,6 +22,7 @@ import { Controller } from 'stimulus'; | ||
(_a = constructor.debounces) === null || _a === void 0 ? void 0 : _a.forEach((func) => { | ||
if (typeof func === "string") { | ||
if (typeof func === 'string') { | ||
; | ||
controller[func] = debounce(controller[func], options === null || options === void 0 ? void 0 : options.wait); | ||
} | ||
if (typeof func === "object") { | ||
if (typeof func === 'object') { | ||
const { name, wait } = func; | ||
@@ -28,0 +29,0 @@ if (!name) |
@@ -6,3 +6,3 @@ import { composeEventName } from '../support/index'; | ||
bubbles: true, | ||
cancelable: true, | ||
cancelable: true | ||
}; | ||
@@ -22,7 +22,7 @@ export class UseDispatch extends StimulusUse { | ||
bubbles, | ||
cancelable, | ||
cancelable | ||
}); | ||
// dispatch the event from the given element or by default from the root element of the controller | ||
targetElement.dispatchEvent(event); | ||
log("dispatch", { eventName: eventNameWithPrefix, detail, bubbles, cancelable }); | ||
log('dispatch', { eventName: eventNameWithPrefix, detail, bubbles, cancelable }); | ||
return event; | ||
@@ -29,0 +29,0 @@ }; |
@@ -14,3 +14,3 @@ import { StimulusUse } from '../stimulus-use'; | ||
this.onEnter = (event) => { | ||
this.call("mouseEnter", event); | ||
this.call('mouseEnter', event); | ||
this.log('mouseEnter', { hover: true }); | ||
@@ -20,3 +20,3 @@ this.dispatch('mouseEnter', { hover: false }); | ||
this.onLeave = (event) => { | ||
this.call("mouseLeave", event); | ||
this.call('mouseLeave', event); | ||
this.log('mouseLeave', { hover: false }); | ||
@@ -23,0 +23,0 @@ this.dispatch('mouseLeave', { hover: false }); |
@@ -9,3 +9,3 @@ import { extendedEvent, method, composeEventName } from '../support/index'; | ||
dispatchEvent: true, | ||
eventPrefix: true, | ||
eventPrefix: true | ||
}; | ||
@@ -74,3 +74,3 @@ export const useIdle = (controller, options = {}) => { | ||
controllerDisconnect(); | ||
}, | ||
} | ||
}); | ||
@@ -77,0 +77,0 @@ observe(); |
import { method, extendedEvent, composeEventName } from '../support/index'; | ||
const defaultOptions = { | ||
dispatchEvent: true, | ||
eventPrefix: true, | ||
eventPrefix: true | ||
}; | ||
@@ -53,3 +53,3 @@ export const useIntersection = (controller, options = {}) => { | ||
controllerDisconnect(); | ||
}, | ||
} | ||
}); | ||
@@ -56,0 +56,0 @@ observe(); |
@@ -40,3 +40,3 @@ import { method } from '../support/index'; | ||
controllerDisconnect(); | ||
}, | ||
} | ||
}); | ||
@@ -43,0 +43,0 @@ observe(); |
@@ -7,2 +7,3 @@ const memoize = (controller, name, value) => { | ||
var _a; | ||
; | ||
(_a = controller.constructor.memos) === null || _a === void 0 ? void 0 : _a.forEach((getter) => { | ||
@@ -9,0 +10,0 @@ memoize(controller, getter, controller[getter]); |
@@ -6,3 +6,3 @@ const defineMetaGetter = (controller, metaName, suffix) => { | ||
return typeCast(metaValue(metaName)); | ||
}, | ||
} | ||
}); | ||
@@ -33,3 +33,3 @@ }; | ||
// define the metas getter to retreive an object with all metas | ||
Object.defineProperty(controller, "metas", { | ||
Object.defineProperty(controller, 'metas', { | ||
get() { | ||
@@ -44,5 +44,5 @@ const result = {}; | ||
return result; | ||
}, | ||
} | ||
}); | ||
}; | ||
//# sourceMappingURL=use-meta.js.map |
@@ -10,3 +10,3 @@ import { StimulusUse } from '../stimulus-use'; | ||
catch (error) { | ||
this.controller.application.handleError(error, "At a minimum, one of childList, attributes, and/or characterData must be true", {}); | ||
this.controller.application.handleError(error, 'At a minimum, one of childList, attributes, and/or characterData must be true', {}); | ||
} | ||
@@ -20,3 +20,3 @@ }; | ||
this.log('mutate', { entries }); | ||
this.dispatch("mutate", { entries }); | ||
this.dispatch('mutate', { entries }); | ||
}; | ||
@@ -23,0 +23,0 @@ this.targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element; |
import { composeEventName, extendedEvent, method } from '../support/index'; | ||
const defaultOptions = { | ||
dispatchEvent: true, | ||
eventPrefix: true, | ||
eventPrefix: true | ||
}; | ||
@@ -17,3 +17,3 @@ export const useResize = (controller, options = {}) => { | ||
controller, | ||
entry, | ||
entry | ||
}); | ||
@@ -35,3 +35,3 @@ targetElement.dispatchEvent(appearEvent); | ||
controllerDisconnect(); | ||
}, | ||
} | ||
}); | ||
@@ -38,0 +38,0 @@ observe(); |
@@ -66,3 +66,3 @@ import { StimulusUse } from '../stimulus-use'; | ||
this.targets = options.targets || controller.constructor.targets; | ||
this.prefixedTargets = this.targets.map((target) => `${this.identifierPrefix}${target}`); | ||
this.prefixedTargets = this.targets.map(target => `${this.identifierPrefix}${target}`); | ||
this.observer = new MutationObserver(this.mutation); | ||
@@ -145,3 +145,3 @@ this.enhanceController(); | ||
targetsUsedByThisControllerFromNode(node) { | ||
if (node.nodeName == "#text" || node.nodeName == "#comment") { | ||
if (node.nodeName == '#text' || node.nodeName == '#comment') { | ||
// Failsafe, just in case we try processing a text or comment node | ||
@@ -158,3 +158,3 @@ return []; | ||
let targetsToCheck = this.stripIdentifierPrefix(targetStr).split(' '); | ||
return this.targets.filter((n) => targetsToCheck.indexOf(n) !== -1); | ||
return this.targets.filter(n => targetsToCheck.indexOf(n) !== -1); | ||
} | ||
@@ -161,0 +161,0 @@ stripIdentifierPrefix(target) { |
@@ -22,6 +22,7 @@ import { Controller } from 'stimulus'; | ||
(_a = constructor.throttles) === null || _a === void 0 ? void 0 : _a.forEach((func) => { | ||
if (typeof func === "string") { | ||
if (typeof func === 'string') { | ||
; | ||
controller[func] = throttle(controller[func], options === null || options === void 0 ? void 0 : options.wait); | ||
} | ||
if (typeof func === "object") { | ||
if (typeof func === 'object') { | ||
const { name, wait } = func; | ||
@@ -28,0 +29,0 @@ if (!name) |
@@ -1,3 +0,3 @@ | ||
export { TransitionController } from "./transition-controller"; | ||
export { TransitionController } from './transition-controller'; | ||
export { useTransition, TransitionOptions } from './use-transition'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export { TransitionController } from "./transition-controller"; | ||
export { TransitionController } from './transition-controller'; | ||
export { useTransition } from './use-transition'; | ||
//# sourceMappingURL=index.js.map |
const alpineNames = { | ||
enterFromClass: "enter", | ||
enterActiveClass: "enterStart", | ||
enterToClass: "enterEnd", | ||
leaveFromClass: "leave", | ||
leaveActiveClass: "leaveStart", | ||
leaveToClass: "leaveEnd", | ||
enterFromClass: 'enter', | ||
enterActiveClass: 'enterStart', | ||
enterToClass: 'enterEnd', | ||
leaveFromClass: 'leave', | ||
leaveActiveClass: 'leaveStart', | ||
leaveToClass: 'leaveEnd' | ||
}; | ||
const defaultOptions = { | ||
transitioned: false, | ||
hiddenClass: "hidden", | ||
hiddenClass: 'hidden', | ||
preserveOriginalClass: true, | ||
@@ -24,6 +24,6 @@ removeToClasses: true | ||
// data attributes are only available on HTMLElement and SVGElement | ||
if (!((targetElement instanceof HTMLElement) || (targetElement instanceof SVGElement))) | ||
if (!(targetElement instanceof HTMLElement || targetElement instanceof SVGElement)) | ||
return; | ||
const dataset = targetElement.dataset; | ||
const leaveAfter = parseInt(dataset.leaveAfter || "") || options.leaveAfter || 0; | ||
const leaveAfter = parseInt(dataset.leaveAfter || '') || options.leaveAfter || 0; | ||
const { transitioned, hiddenClass, preserveOriginalClass, removeToClasses } = Object.assign(defaultOptions, options); | ||
@@ -38,6 +38,6 @@ const controllerEnter = (_a = controller.enter) === null || _a === void 0 ? void 0 : _a.bind(controller); | ||
controllerEnter && controllerEnter(event); | ||
const enterFromClasses = getAttribute("enterFrom", options, dataset); | ||
const enterActiveClasses = getAttribute("enterActive", options, dataset); | ||
const enterToClasses = getAttribute("enterTo", options, dataset); | ||
const leaveToClasses = getAttribute("leaveTo", options, dataset); | ||
const enterFromClasses = getAttribute('enterFrom', options, dataset); | ||
const enterActiveClasses = getAttribute('enterActive', options, dataset); | ||
const enterToClasses = getAttribute('enterTo', options, dataset); | ||
const leaveToClasses = getAttribute('leaveTo', options, dataset); | ||
if (!!hiddenClass) { | ||
@@ -61,6 +61,6 @@ targetElement.classList.remove(hiddenClass); | ||
controllerLeave && controllerLeave(event); | ||
const leaveFromClasses = getAttribute("leaveFrom", options, dataset); | ||
const leaveActiveClasses = getAttribute("leaveActive", options, dataset); | ||
const leaveToClasses = getAttribute("leaveTo", options, dataset); | ||
const enterToClasses = getAttribute("enterTo", options, dataset); | ||
const leaveFromClasses = getAttribute('leaveFrom', options, dataset); | ||
const leaveActiveClasses = getAttribute('leaveActive', options, dataset); | ||
const leaveToClasses = getAttribute('leaveTo', options, dataset); | ||
const enterToClasses = getAttribute('enterTo', options, dataset); | ||
if (!removeToClasses) { | ||
@@ -145,11 +145,8 @@ removeClasses(targetElement, enterToClasses); | ||
const datasetAlpineName = alpineNames[name]; | ||
const classes = options[name] || dataset[datasetName] || dataset[datasetAlpineName] || " "; | ||
return isEmpty(classes) ? [] : classes.split(" "); | ||
const classes = options[name] || dataset[datasetName] || dataset[datasetAlpineName] || ' '; | ||
return isEmpty(classes) ? [] : classes.split(' '); | ||
} | ||
async function afterTransition(element) { | ||
return new Promise(resolve => { | ||
const duration = Number(getComputedStyle(element) | ||
.transitionDuration | ||
.split(",")[0] | ||
.replace('s', '')) * 1000; | ||
const duration = Number(getComputedStyle(element).transitionDuration.split(',')[0].replace('s', '')) * 1000; | ||
setTimeout(() => { | ||
@@ -168,4 +165,4 @@ resolve(duration); | ||
function isEmpty(str) { | ||
return (str.length === 0 || !str.trim()); | ||
return str.length === 0 || !str.trim(); | ||
} | ||
//# sourceMappingURL=use-transition.js.map |
@@ -24,3 +24,3 @@ import { method } from '../support/index'; | ||
controllerDisconnect(); | ||
}, | ||
} | ||
}); | ||
@@ -27,0 +27,0 @@ observe(); |
{ | ||
"name": "stimulus-use", | ||
"version": "0.25.0", | ||
"version": "0.25.1", | ||
"description": "A collection of standard controllers and utilities for Stimulus", | ||
@@ -19,2 +19,4 @@ "main": "dist/index.umd.js", | ||
"test:treeshake": "$npm_execpath run agadoo", | ||
"lint": "prettier --check *.js **/*.js **/*.ts src/**/*.ts spec/**/*.js playground/**/*.js", | ||
"format": "prettier --write *.js **/*.js **/*.ts src/**/*.ts spec/**/*.js playground/**/*.js", | ||
"dev": "tsc -b -w", | ||
@@ -63,2 +65,3 @@ "clean": "rimraf dist *.tsbuildinfo coverage", | ||
"postcss-loader": "^4.1.0", | ||
"prettier": "^2.3.1", | ||
"rimraf": "^3.0.2", | ||
@@ -85,3 +88,8 @@ "sinon": "^9.0.3", | ||
}, | ||
"peerDependenciesMeta": { | ||
"hotkeys-js": { | ||
"optional": true | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
280663
1884
47