Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@github/text-expander-element
Advanced tools
Activates a suggestion menu to expand text snippets as you type.
Activates a suggestion menu to expand text snippets as you type.
$ npm install --save @github/text-expander-element
Import as ES modules:
import '@github/text-expander-element'
With a script tag:
<script type="module" src="./node_modules/@github/text-expander-element/dist/bundle.js">
<text-expander keys=": @ #" multiword="#">
<textarea></textarea>
</text-expander>
keys
is a space separated list of menu activation keysmultiword
defines whether the expansion should use several words or not
suffix
is a string that is appended to the value during expansion, default is a single space charactertext-expander-change
is fired when a key is matched. In event.detail
you can find:
key
: The matched key; for example: :
.text
: The matched text; for example: cat
, for :cat
.
key
is specified in the multiword
attribute then the matched text can contain multiple words; for example cat and dog
for :cat and dog
.provide
: A function to be called when you have the menu results. Takes a Promise
with {matched: boolean, fragment: HTMLElement}
where matched
tells the element whether a suggestion is available, and fragment
is the menu content to be displayed on the page.const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-change', function(event) {
const {key, provide, text} = event.detail
if (key !== ':') return
const suggestions = document.querySelector('.emoji-suggestions').cloneNode(true)
suggestions.hidden = false
for (const suggestion of suggestions.children) {
if (!suggestion.textContent.match(text)) {
suggestion.remove()
}
}
provide(Promise.resolve({matched: suggestions.childElementCount > 0, fragment: suggestions}))
})
The returned fragment should be consisted of filtered [role=option]
items to be selected. For example:
<ul class="emoji-suggestions" hidden>
<li role="option" data-value="🐈">🐈 :cat2:</li>
<li role="option" data-value="🐕">🐕 :dog:</li>
</ul>
text-expander-value
is fired when an item is selected. In event.detail
you can find:
key
: The matched key; for example: :
.item
: The selected item. This would be one of the [role=option]
. Use this to work out the value
.value
: A null value placeholder to replace the query. To replace the text query, simply re-assign this value.continue
: A boolean value to specify whether to continue autocompletion after inserting a value. Defaults to false
. If set to true
, will not add a space after inserted value and will keep firing the text-expander-change
event.const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-value', function(event) {
const {key, item} = event.detail
if (key === ':') {
event.detail.value = item.getAttribute('data-value')
}
})
text-expander-committed
is fired after the underlying input
value has been updated in the DOM. In event.detail
you can find:
input
: The HTMLInputElement
or HTMLTextAreaElement
that just had value
changes committed to the DOM.const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-committed', function(event) {
const {input} = event.detail
})
text-expander-activate
is fired just after the menu has been assigned and appended to the DOM, and just before it is about to be positioned near the text to expand. This is useful for assigning classes or calling imperative methods to show the menu, such as .showPopover()
.
text-expander-dectivate
is fired just before the menu is goind to be unassigned and removed from the DOM. This is useful for removing classes or running cleanup like removing from caches.
Browsers without native custom element support require a polyfill.
npm install
npm test
Distributed under the MIT license. See LICENSE for details.
FAQs
Activates a suggestion menu to expand text snippets as you type.
The npm package @github/text-expander-element receives a total of 1,923 weekly downloads. As such, @github/text-expander-element popularity was classified as popular.
We found that @github/text-expander-element demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 17 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.