@github/markdown-toolbar-element
Advanced tools
+52
-0
@@ -42,2 +42,35 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
| const styles = new WeakMap(); | ||
| const manualStyles = { | ||
| 'header-1': { prefix: '# ' }, | ||
| 'header-2': { prefix: '## ' }, | ||
| 'header-3': { prefix: '### ' }, | ||
| 'header-4': { prefix: '#### ' }, | ||
| 'header-5': { prefix: '##### ' }, | ||
| 'header-6': { prefix: '###### ' }, | ||
| bold: { prefix: '**', suffix: '**', trimFirst: true }, | ||
| italic: { prefix: '_', suffix: '_', trimFirst: true }, | ||
| quote: { prefix: '> ', multiline: true, surroundWithNewlines: true }, | ||
| code: { | ||
| prefix: '`', | ||
| suffix: '`', | ||
| blockPrefix: '```', | ||
| blockSuffix: '```' | ||
| }, | ||
| link: { prefix: '[', suffix: '](url)', replaceNext: 'url', scanFor: 'https?://' }, | ||
| image: { prefix: '', replaceNext: 'url', scanFor: 'https?://' }, | ||
| 'unordered-list': { | ||
| prefix: '- ', | ||
| multiline: true, | ||
| unorderedList: true | ||
| }, | ||
| 'ordered-list': { | ||
| prefix: '1. ', | ||
| multiline: true, | ||
| orderedList: true | ||
| }, | ||
| 'task-list': { prefix: '- [ ] ', multiline: true, surroundWithNewlines: true }, | ||
| mention: { prefix: '@', prefixSpace: true }, | ||
| ref: { prefix: '#', prefixSpace: true }, | ||
| strikethrough: { prefix: '~~', suffix: '~~', trimFirst: true } | ||
| }; | ||
| class MarkdownButtonElement extends HTMLElement { | ||
@@ -207,2 +240,15 @@ constructor() { | ||
| } | ||
| function applyFromToolbar(event) { | ||
| const { target, currentTarget } = event; | ||
| if (!(target instanceof HTMLElement)) | ||
| return; | ||
| const mdButton = target.closest('[data-md-button]'); | ||
| if (!mdButton || mdButton.closest('markdown-toolbar') !== currentTarget) | ||
| return; | ||
| const mdButtonStyle = target.getAttribute('data-md-button'); | ||
| const style = manualStyles[mdButtonStyle]; | ||
| if (!style) | ||
| return; | ||
| applyStyle(target, style); | ||
| } | ||
| class MarkdownToolbarElement extends HTMLElement { | ||
@@ -216,2 +262,4 @@ connectedCallback() { | ||
| this.addEventListener('focus', onToolbarFocus, { once: true }); | ||
| this.addEventListener('keydown', keydown(applyFromToolbar)); | ||
| this.addEventListener('click', applyFromToolbar); | ||
| } | ||
@@ -236,2 +284,4 @@ disconnectedCallback() { | ||
| return; | ||
| if (target.hasAttribute('data-no-focus')) | ||
| return; | ||
| target.removeAttribute('tabindex'); | ||
@@ -254,2 +304,4 @@ let tabindex = '0'; | ||
| return; | ||
| if (toolbar.hasAttribute('data-no-focus')) | ||
| return; | ||
| const buttons = getButtons(toolbar); | ||
@@ -256,0 +308,0 @@ const index = buttons.indexOf(event.target); |
+2
-2
| { | ||
| "name": "@github/markdown-toolbar-element", | ||
| "version": "2.1.1", | ||
| "version": "2.2.0", | ||
| "description": "Markdown formatting buttons for text inputs.", | ||
@@ -40,3 +40,3 @@ "repository": "github/markdown-toolbar-element", | ||
| "karma-mocha-reporter": "^2.2.3", | ||
| "mocha": "^9.1.3", | ||
| "mocha": "^10.0.0", | ||
| "typescript": "^4.2.4" | ||
@@ -43,0 +43,0 @@ }, |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34326
5.86%751
7.44%0
-100%