stimulus_reflex
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -88,29 +88,1 @@ // Returns a string value for the passed array. | ||
} | ||
// Indicates if the passed element is considered a text input. | ||
// | ||
export const isTextInput = element => { | ||
return ( | ||
['INPUT', 'TEXTAREA', 'SELECT'].includes(element.tagName) && | ||
[ | ||
'color', | ||
'date', | ||
'datetime', | ||
'datetime-local', | ||
'email', | ||
'month', | ||
'number', | ||
'password', | ||
'range', | ||
'search', | ||
'select-one', | ||
'select-multiple', | ||
'tel', | ||
'text', | ||
'textarea', | ||
'time', | ||
'url', | ||
'week' | ||
].includes(element.type) | ||
) | ||
} |
{ | ||
"name": "stimulus_reflex", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "Build reactive applications with the Rails tooling you already know and love.", | ||
@@ -32,4 +32,4 @@ "keywords": [ | ||
"postinstall": "node scripts/post_install.js", | ||
"prettier-standard:check": "yarn run prettier-standard --check ./**/*.js", | ||
"prettier-standard:format": "yarn run prettier-standard ./**/*.js", | ||
"prettier-standard:check": "yarn run prettier-standard --check *.js **/*.js", | ||
"prettier-standard:format": "yarn run prettier-standard *.js **/*.js", | ||
"test": "yarn run mocha --require @babel/register" | ||
@@ -39,3 +39,3 @@ }, | ||
"@rails/actioncable": ">= 6.0", | ||
"cable_ready": ">= 4.1", | ||
"cable_ready": ">= 4.1.2", | ||
"inflected": ">= 2.0", | ||
@@ -42,0 +42,0 @@ "stimulus": ">= 1.1", |
@@ -12,4 +12,3 @@ import { Controller } from 'stimulus' | ||
extractElementAttributes, | ||
findElement, | ||
isTextInput | ||
findElement | ||
} from './attributes' | ||
@@ -27,23 +26,2 @@ | ||
// Initializes implicit data-reflex-permanent for text inputs. | ||
// | ||
const initializeImplicitReflexPermanent = event => { | ||
const element = event.target | ||
if (!isTextInput(element)) return | ||
element.reflexPermanent = element.hasAttribute( | ||
stimulusApplication.schema.reflexPermanentAttribute | ||
) | ||
element.setAttribute(stimulusApplication.schema.reflexPermanentAttribute, '') | ||
} | ||
// Resets implicit data-reflex-permanent for text inputs. | ||
// | ||
const resetImplicitReflexPermanent = event => { | ||
const element = event.target | ||
if (!isTextInput(element)) return | ||
if (element.reflexPermanent !== undefined && !element.reflexPermanent) { | ||
element.removeAttribute(stimulusApplication.schema.reflexPermanentAttribute) | ||
} | ||
} | ||
// Subscribes a StimulusReflex controller to an ActionCable channel. | ||
@@ -64,5 +42,5 @@ // | ||
if (data.operations.morph && data.operations.morph.length) { | ||
const urls = [ | ||
...new Set(data.operations.morph.map(m => m.stimulusReflex.url)) | ||
] | ||
const urls = Array.from( | ||
new Set(data.operations.morph.map(m => m.stimulusReflex.url)) | ||
) | ||
if (urls.length !== 1 || urls[0] !== location.href) return | ||
@@ -293,2 +271,5 @@ } | ||
) | ||
document.addEventListener('ajax:complete', () => | ||
setTimeout(setupDeclarativeReflexes, 1) | ||
) | ||
// Trigger success and after lifecycle methods from before-morph to ensure we can find a reference | ||
@@ -324,6 +305,4 @@ // to the source element in case it gets removed from the DOM via morph. | ||
}) | ||
document.addEventListener('focusin', initializeImplicitReflexPermanent) | ||
document.addEventListener('focusout', resetImplicitReflexPermanent) | ||
} | ||
export default { initialize, register } | ||
export default { initialize, register, setupDeclarativeReflexes } |
24073
660
Updatedcable_ready@>= 4.1.2