@webcoder49/code-input 2.6.0 → 2.6.3
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.
- package/SECURITY.md +7 -0
- package/code-input.js +154 -91
- package/code-input.min.js +1 -1
- package/docs/_index.md +12 -3
- package/docs/interface/js/_index.md +1 -1
- package/esm/code-input.d.mts +154 -0
- package/esm/code-input.mjs +1058 -0
- package/esm/plugins/auto-close-brackets.d.mts +15 -0
- package/esm/plugins/auto-close-brackets.mjs +84 -0
- package/esm/plugins/autocomplete.d.mts +14 -0
- package/esm/plugins/autocomplete.mjs +93 -0
- package/esm/plugins/autodetect.d.mts +11 -0
- package/esm/plugins/autodetect.mjs +35 -0
- package/esm/plugins/find-and-replace.d.mts +43 -0
- package/esm/plugins/find-and-replace.mjs +777 -0
- package/esm/plugins/go-to-line.d.mts +29 -0
- package/esm/plugins/go-to-line.mjs +217 -0
- package/esm/plugins/indent.d.mts +22 -0
- package/esm/plugins/indent.mjs +359 -0
- package/esm/plugins/select-token-callbacks.d.mts +51 -0
- package/esm/plugins/select-token-callbacks.mjs +296 -0
- package/esm/plugins/special-chars.d.mts +25 -0
- package/esm/plugins/special-chars.mjs +207 -0
- package/esm/plugins/test.d.mts +16 -0
- package/esm/plugins/test.mjs +56 -0
- package/esm/templates/hljs.d.mts +16 -0
- package/esm/templates/hljs.mjs +28 -0
- package/esm/templates/prism.d.mts +16 -0
- package/esm/templates/prism.mjs +25 -0
- package/package.json +1 -1
- package/esm/.code-input.mjs.kate-swp +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// NOTICE: This code is @generated from code outside the esm directory. Please do not edit it to contribute!
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugins are imported from the plugins folder. They will then
|
|
6
|
+
* provide custom extra functionality to code-input elements.
|
|
7
|
+
*/
|
|
8
|
+
export abstract class Plugin {
|
|
9
|
+
/**
|
|
10
|
+
* Create a Plugin
|
|
11
|
+
*
|
|
12
|
+
* @param {Array<string>} observedAttributes - The HTML attributes to watch for this plugin, and report any
|
|
13
|
+
* modifications to the `codeInput.Plugin.attributeChanged` method.
|
|
14
|
+
*/
|
|
15
|
+
constructor(observedAttributes: Array<string>)
|
|
16
|
+
/**
|
|
17
|
+
* Runs before code is highlighted.
|
|
18
|
+
* @param {codeInput.CodeInput} codeInput - The codeInput element
|
|
19
|
+
*/
|
|
20
|
+
beforeHighlight(codeInput: CodeInput): void
|
|
21
|
+
/**
|
|
22
|
+
* Runs after code is highlighted.
|
|
23
|
+
* @param {codeInput.CodeInput} codeInput - The codeInput element
|
|
24
|
+
*/
|
|
25
|
+
afterHighlight(codeInput: CodeInput): void
|
|
26
|
+
/**
|
|
27
|
+
* Runs before elements are added into a code-input element.
|
|
28
|
+
* @param {codeInput.CodeInput} codeInput - The codeInput element
|
|
29
|
+
*/
|
|
30
|
+
beforeElementsAdded(codeInput: CodeInput): void
|
|
31
|
+
/**
|
|
32
|
+
* Runs after elements are added into a code-input element (useful for adding events to the textarea).
|
|
33
|
+
* @param {codeInput.CodeInput} codeInput - The codeInput element
|
|
34
|
+
*/
|
|
35
|
+
afterElementsAdded(codeInput: CodeInput): void
|
|
36
|
+
/**
|
|
37
|
+
* Runs when an attribute of a code-input element is changed (you must add the attribute name to `codeInput.Plugin.observedAttributes` first).
|
|
38
|
+
* @param {codeInput.CodeInput} codeInput - The codeInput element
|
|
39
|
+
* @param {string} name - The name of the attribute
|
|
40
|
+
* @param {string} oldValue - The value of the attribute before it was changed
|
|
41
|
+
* @param {string} newValue - The value of the attribute after it is changed
|
|
42
|
+
*/
|
|
43
|
+
attributeChanged(codeInput: CodeInput, name: string, oldValue: string, newValue: string): void
|
|
44
|
+
/**
|
|
45
|
+
* The HTML attributes to watch for this plugin, and report any
|
|
46
|
+
* modifications to the `codeInput.Plugin.attributeChanged` method.
|
|
47
|
+
*/
|
|
48
|
+
observedAttributes: Array<string>
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Replace the values in destination with those from source where the keys match, in-place.
|
|
52
|
+
* @param {Object} destination Where to place the translated strings, already filled with the keys pointing to English strings.
|
|
53
|
+
* @param {Object} source The same keys, or some of them, mapped to translated strings. Keys not present here will retain the values they are maapped to in destination.
|
|
54
|
+
*/
|
|
55
|
+
addTranslations(destination: Object, source: Object): void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* If you're using one of the two named highlighters, please see
|
|
61
|
+
* `codeInput.templates.prism` or `codeInput.templates.hljs`.
|
|
62
|
+
* Otherwise please see this class' constructor.
|
|
63
|
+
* Templates are used in `<code-input>` elements and once registered with
|
|
64
|
+
* `codeInput.registerTemplate` will be in charge of the highlighting
|
|
65
|
+
* algorithm and settings for all code-inputs with a `template` attribute
|
|
66
|
+
* matching the registered name.
|
|
67
|
+
*/
|
|
68
|
+
export class Template {
|
|
69
|
+
/**
|
|
70
|
+
* **When `includeCodeInputInHighlightFunc` is `false`, `highlight` takes only the `<pre><code>` element as a parameter.**
|
|
71
|
+
*
|
|
72
|
+
* Constructor to create a custom template instance. Pass this into `codeInput.registerTemplate` to use it.
|
|
73
|
+
* I would strongly recommend using the built-in simpler template `codeInput.templates.prism` or `codeInput.templates.hljs`.
|
|
74
|
+
* @param {(codeElement: HTMLElement) => void} highlight - a callback to highlight the code, that takes an HTML `<code>` element inside a `<pre>` element as a parameter
|
|
75
|
+
* @param {boolean} preElementStyled - is the `<pre>` element CSS-styled (if so set to true), or the `<code>` element (false)?
|
|
76
|
+
* @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `<code>` element will be given the class name 'language-[lang attribute's value]'.
|
|
77
|
+
* @param {false} includeCodeInputInHighlightFunc - Setting this to true passes the `<code-input>` element as a second argument to the highlight function.
|
|
78
|
+
* @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.Plugin`
|
|
79
|
+
* @returns template object
|
|
80
|
+
*/
|
|
81
|
+
constructor(highlight?: (codeElement: HTMLElement) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: false, plugins?: Plugin[])
|
|
82
|
+
/**
|
|
83
|
+
* **When `includeCodeInputInHighlightFunc` is `true`, `highlight` takes two parameters: the `<pre><code>` element, and the `<code-input>` element.**
|
|
84
|
+
*
|
|
85
|
+
* Constructor to create a custom template instance. Pass this into `codeInput.registerTemplate` to use it.
|
|
86
|
+
* I would strongly recommend using the built-in simpler template `codeInput.templates.prism` or `codeInput.templates.hljs`.
|
|
87
|
+
* @param {(codeElement: HTMLElement, codeInput: CodeInput) => void} highlight - a callback to highlight the code, that takes an HTML `<code>` element inside a `<pre>` element as a parameter
|
|
88
|
+
* @param {boolean} preElementStyled - is the `<pre>` element CSS-styled (if so set to true), or the `<code>` element (false)?
|
|
89
|
+
* @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `<code>` element will be given the class name 'language-[lang attribute's value]'.
|
|
90
|
+
* @param {true} includeCodeInputInHighlightFunc - Setting this to true passes the `<code-input>` element as a second argument to the highlight function.
|
|
91
|
+
* @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.Plugin`
|
|
92
|
+
* @returns template object
|
|
93
|
+
*/
|
|
94
|
+
constructor(highlight?: (codeElement: HTMLElement, codeInput: CodeInput) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: true, plugins?: Plugin[])
|
|
95
|
+
highlight: Function
|
|
96
|
+
preElementStyled: boolean
|
|
97
|
+
isCode: boolean
|
|
98
|
+
includeCodeInputInHighlightFunc: boolean
|
|
99
|
+
plugins: Plugin[]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A `<code-input>` element, an instance of an `HTMLElement`, and the result
|
|
105
|
+
* of `document.createElement("code-input")`. Attributes are only set when
|
|
106
|
+
* the element's template has been registered, and before this are null.
|
|
107
|
+
*/
|
|
108
|
+
export class CodeInput extends HTMLTextAreaElement { // Tries to implement textarea interface
|
|
109
|
+
/**
|
|
110
|
+
* When the code-input's template is registered, this contains its codeInput.Template object.
|
|
111
|
+
*/
|
|
112
|
+
templateObject?: readonly Template
|
|
113
|
+
/**
|
|
114
|
+
* Exposed child textarea element for user to input code in; in this version of code-input you shouldn't need to access
|
|
115
|
+
* it because most textarea functionality is present on the code-input element itself.
|
|
116
|
+
*/
|
|
117
|
+
textareaElement?: HTMLTextAreaElement
|
|
118
|
+
/**
|
|
119
|
+
* Exposed child pre element where syntax-highlighted code is outputted.
|
|
120
|
+
* Contains this.codeElement as its only child.
|
|
121
|
+
*/
|
|
122
|
+
preElement?: HTMLPreElement
|
|
123
|
+
/**
|
|
124
|
+
* Exposed child pre element's child code element where syntax-highlighted code is outputted.
|
|
125
|
+
* Has this.preElement as its parent.
|
|
126
|
+
*/
|
|
127
|
+
codeElement?: HTMLElement
|
|
128
|
+
/**
|
|
129
|
+
* Exposed non-scrolling element designed to contain dialog boxes etc. from plugins,
|
|
130
|
+
* that shouldn't scroll with the code-input element.
|
|
131
|
+
*/
|
|
132
|
+
dialogContainerElement?: HTMLElement
|
|
133
|
+
/**
|
|
134
|
+
* Show some instructions to the user only if they are using keyboard navigation - for example, a prompt on how to navigate with the keyboard if Tab is repurposed.
|
|
135
|
+
* @param {string} instructions The instructions to display only if keyboard navigation is being used. If it's blank, no instructions will be shown.
|
|
136
|
+
* @param {boolean} includeAriaDescriptionFirst Whether to include the aria-description of the code-input element before the keyboard navigation instructions for a screenreader. Keep this as true when the textarea is first focused.
|
|
137
|
+
*/
|
|
138
|
+
setKeyboardNavInstructions(instructions: string, includeAriaDescriptionFirst: boolean): void
|
|
139
|
+
/**
|
|
140
|
+
* Allows plugins to store data in the scope of a single element.
|
|
141
|
+
* Key - name of the plugin, in camelCase
|
|
142
|
+
* Value - object of data to be stored; different plugins may use this differently.
|
|
143
|
+
*/
|
|
144
|
+
pluginData: Object
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Register a template so code-input elements with a template attribute that equals the templateName will use the template.
|
|
149
|
+
* See `codeInput.templates` for constructors to create templates.
|
|
150
|
+
* @param {string} templateName - the name to register the template under
|
|
151
|
+
* @param {Object} template - a Template object instance - see `codeInput.templates`
|
|
152
|
+
*/
|
|
153
|
+
export function registerTemplate(templateName: string, template: Template): void;
|
|
154
|
+
export default { Plugin, Template, CodeInput, registerTemplate };
|