overtype 2.3.7 → 2.3.8
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/README.md +5 -4
- package/dist/overtype-webcomponent.esm.js +220 -23
- package/dist/overtype-webcomponent.esm.js.map +3 -3
- package/dist/overtype-webcomponent.js +216 -23
- package/dist/overtype-webcomponent.js.map +3 -3
- package/dist/overtype-webcomponent.min.js +52 -945
- package/dist/overtype.cjs +218 -23
- package/dist/overtype.cjs.map +3 -3
- package/dist/overtype.d.ts +24 -1
- package/dist/overtype.esm.js +221 -23
- package/dist/overtype.esm.js.map +3 -3
- package/dist/overtype.js +217 -23
- package/dist/overtype.js.map +3 -3
- package/dist/overtype.min.js +48 -941
- package/package.json +1 -1
- package/src/overtype.d.ts +24 -1
- package/src/overtype.js +93 -24
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.8
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -1910,6 +1910,30 @@ var OverTypeEditor = (() => {
|
|
|
1910
1910
|
}
|
|
1911
1911
|
|
|
1912
1912
|
// node_modules/markdown-actions/dist/markdown-actions.esm.js
|
|
1913
|
+
var markdown_actions_esm_exports = {};
|
|
1914
|
+
__export(markdown_actions_esm_exports, {
|
|
1915
|
+
applyCustomFormat: () => applyCustomFormat,
|
|
1916
|
+
default: () => src_default,
|
|
1917
|
+
expandSelection: () => expandSelection2,
|
|
1918
|
+
getActiveFormats: () => getActiveFormats2,
|
|
1919
|
+
getDebugMode: () => getDebugMode,
|
|
1920
|
+
hasFormat: () => hasFormat2,
|
|
1921
|
+
insertHeader: () => insertHeader,
|
|
1922
|
+
insertLink: () => insertLink,
|
|
1923
|
+
preserveSelection: () => preserveSelection,
|
|
1924
|
+
setDebugMode: () => setDebugMode,
|
|
1925
|
+
setUndoMethod: () => setUndoMethod,
|
|
1926
|
+
toggleBold: () => toggleBold,
|
|
1927
|
+
toggleBulletList: () => toggleBulletList,
|
|
1928
|
+
toggleCode: () => toggleCode,
|
|
1929
|
+
toggleH1: () => toggleH1,
|
|
1930
|
+
toggleH2: () => toggleH2,
|
|
1931
|
+
toggleH3: () => toggleH3,
|
|
1932
|
+
toggleItalic: () => toggleItalic,
|
|
1933
|
+
toggleNumberedList: () => toggleNumberedList,
|
|
1934
|
+
toggleQuote: () => toggleQuote,
|
|
1935
|
+
toggleTaskList: () => toggleTaskList
|
|
1936
|
+
});
|
|
1913
1937
|
var __defProp2 = Object.defineProperty;
|
|
1914
1938
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1915
1939
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
@@ -1996,6 +2020,9 @@ var OverTypeEditor = (() => {
|
|
|
1996
2020
|
return __spreadValues(__spreadValues({}, getDefaultStyle()), format);
|
|
1997
2021
|
}
|
|
1998
2022
|
var debugMode = false;
|
|
2023
|
+
function setDebugMode(enabled) {
|
|
2024
|
+
debugMode = enabled;
|
|
2025
|
+
}
|
|
1999
2026
|
function getDebugMode() {
|
|
2000
2027
|
return debugMode;
|
|
2001
2028
|
}
|
|
@@ -2116,6 +2143,19 @@ var OverTypeEditor = (() => {
|
|
|
2116
2143
|
console.groupEnd();
|
|
2117
2144
|
}
|
|
2118
2145
|
}
|
|
2146
|
+
function setUndoMethod(method) {
|
|
2147
|
+
switch (method) {
|
|
2148
|
+
case "native":
|
|
2149
|
+
canInsertText = true;
|
|
2150
|
+
break;
|
|
2151
|
+
case "manual":
|
|
2152
|
+
canInsertText = false;
|
|
2153
|
+
break;
|
|
2154
|
+
case "auto":
|
|
2155
|
+
canInsertText = null;
|
|
2156
|
+
break;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2119
2159
|
function isMultipleLines(string) {
|
|
2120
2160
|
return string.trim().split("\n").length > 1;
|
|
2121
2161
|
}
|
|
@@ -2185,6 +2225,15 @@ var OverTypeEditor = (() => {
|
|
|
2185
2225
|
}
|
|
2186
2226
|
return { newlinesToAppend, newlinesToPrepend };
|
|
2187
2227
|
}
|
|
2228
|
+
function preserveSelection(textarea, callback) {
|
|
2229
|
+
const start = textarea.selectionStart;
|
|
2230
|
+
const end = textarea.selectionEnd;
|
|
2231
|
+
const scrollTop = textarea.scrollTop;
|
|
2232
|
+
callback();
|
|
2233
|
+
textarea.selectionStart = start;
|
|
2234
|
+
textarea.selectionEnd = end;
|
|
2235
|
+
textarea.scrollTop = scrollTop;
|
|
2236
|
+
}
|
|
2188
2237
|
function applyLineOperation(textarea, operation, options = {}) {
|
|
2189
2238
|
const originalStart = textarea.selectionStart;
|
|
2190
2239
|
const originalEnd = textarea.selectionEnd;
|
|
@@ -2558,6 +2607,43 @@ ${blockSuffix}` : suffix;
|
|
|
2558
2607
|
}
|
|
2559
2608
|
return formats;
|
|
2560
2609
|
}
|
|
2610
|
+
function hasFormat(textarea, format) {
|
|
2611
|
+
const activeFormats = getActiveFormats(textarea);
|
|
2612
|
+
return activeFormats.includes(format);
|
|
2613
|
+
}
|
|
2614
|
+
function expandSelection(textarea, options = {}) {
|
|
2615
|
+
if (!textarea)
|
|
2616
|
+
return;
|
|
2617
|
+
const { toWord, toLine, toFormat } = options;
|
|
2618
|
+
const { selectionStart, selectionEnd, value } = textarea;
|
|
2619
|
+
if (toLine) {
|
|
2620
|
+
const lines = value.split("\n");
|
|
2621
|
+
let lineStart = 0;
|
|
2622
|
+
let lineEnd = 0;
|
|
2623
|
+
let currentPos = 0;
|
|
2624
|
+
for (const line of lines) {
|
|
2625
|
+
if (selectionStart >= currentPos && selectionStart <= currentPos + line.length) {
|
|
2626
|
+
lineStart = currentPos;
|
|
2627
|
+
lineEnd = currentPos + line.length;
|
|
2628
|
+
break;
|
|
2629
|
+
}
|
|
2630
|
+
currentPos += line.length + 1;
|
|
2631
|
+
}
|
|
2632
|
+
textarea.selectionStart = lineStart;
|
|
2633
|
+
textarea.selectionEnd = lineEnd;
|
|
2634
|
+
} else if (toWord && selectionStart === selectionEnd) {
|
|
2635
|
+
let start = selectionStart;
|
|
2636
|
+
let end = selectionEnd;
|
|
2637
|
+
while (start > 0 && !/\s/.test(value[start - 1])) {
|
|
2638
|
+
start--;
|
|
2639
|
+
}
|
|
2640
|
+
while (end < value.length && !/\s/.test(value[end])) {
|
|
2641
|
+
end++;
|
|
2642
|
+
}
|
|
2643
|
+
textarea.selectionStart = start;
|
|
2644
|
+
textarea.selectionEnd = end;
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2561
2647
|
function toggleBold(textarea) {
|
|
2562
2648
|
if (!textarea || textarea.disabled || textarea.readOnly)
|
|
2563
2649
|
return;
|
|
@@ -2751,6 +2837,51 @@ ${blockSuffix}` : suffix;
|
|
|
2751
2837
|
function getActiveFormats2(textarea) {
|
|
2752
2838
|
return getActiveFormats(textarea);
|
|
2753
2839
|
}
|
|
2840
|
+
function hasFormat2(textarea, format) {
|
|
2841
|
+
return hasFormat(textarea, format);
|
|
2842
|
+
}
|
|
2843
|
+
function expandSelection2(textarea, options = {}) {
|
|
2844
|
+
expandSelection(textarea, options);
|
|
2845
|
+
}
|
|
2846
|
+
function applyCustomFormat(textarea, format) {
|
|
2847
|
+
if (!textarea || textarea.disabled || textarea.readOnly)
|
|
2848
|
+
return;
|
|
2849
|
+
const style = mergeWithDefaults(format);
|
|
2850
|
+
let result;
|
|
2851
|
+
if (style.multiline) {
|
|
2852
|
+
const selectedText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd);
|
|
2853
|
+
if (isMultipleLines(selectedText)) {
|
|
2854
|
+
result = multilineStyle(textarea, style);
|
|
2855
|
+
} else {
|
|
2856
|
+
result = blockStyle(textarea, style);
|
|
2857
|
+
}
|
|
2858
|
+
} else {
|
|
2859
|
+
result = blockStyle(textarea, style);
|
|
2860
|
+
}
|
|
2861
|
+
insertText(textarea, result);
|
|
2862
|
+
}
|
|
2863
|
+
var src_default = {
|
|
2864
|
+
toggleBold,
|
|
2865
|
+
toggleItalic,
|
|
2866
|
+
toggleCode,
|
|
2867
|
+
insertLink,
|
|
2868
|
+
toggleBulletList,
|
|
2869
|
+
toggleNumberedList,
|
|
2870
|
+
toggleQuote,
|
|
2871
|
+
toggleTaskList,
|
|
2872
|
+
insertHeader,
|
|
2873
|
+
toggleH1,
|
|
2874
|
+
toggleH2,
|
|
2875
|
+
toggleH3,
|
|
2876
|
+
getActiveFormats: getActiveFormats2,
|
|
2877
|
+
hasFormat: hasFormat2,
|
|
2878
|
+
expandSelection: expandSelection2,
|
|
2879
|
+
applyCustomFormat,
|
|
2880
|
+
preserveSelection,
|
|
2881
|
+
setUndoMethod,
|
|
2882
|
+
setDebugMode,
|
|
2883
|
+
getDebugMode
|
|
2884
|
+
};
|
|
2754
2885
|
|
|
2755
2886
|
// src/toolbar.js
|
|
2756
2887
|
var Toolbar = class {
|
|
@@ -4676,21 +4807,9 @@ ${blockSuffix}` : suffix;
|
|
|
4676
4807
|
* @returns {Array} Array of OverType instances
|
|
4677
4808
|
*/
|
|
4678
4809
|
constructor(target, options = {}) {
|
|
4679
|
-
|
|
4680
|
-
if (typeof target === "string") {
|
|
4681
|
-
elements
|
|
4682
|
-
if (elements.length === 0) {
|
|
4683
|
-
throw new Error(`No elements found for selector: ${target}`);
|
|
4684
|
-
}
|
|
4685
|
-
elements = Array.from(elements);
|
|
4686
|
-
} else if (target instanceof Element) {
|
|
4687
|
-
elements = [target];
|
|
4688
|
-
} else if (target instanceof NodeList) {
|
|
4689
|
-
elements = Array.from(target);
|
|
4690
|
-
} else if (Array.isArray(target)) {
|
|
4691
|
-
elements = target;
|
|
4692
|
-
} else {
|
|
4693
|
-
throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
|
|
4810
|
+
const elements = _OverType._resolveTargets(target);
|
|
4811
|
+
if (typeof target === "string" && elements.length === 0) {
|
|
4812
|
+
throw new Error(`No elements found for selector: ${target}`);
|
|
4694
4813
|
}
|
|
4695
4814
|
const instances = elements.map((element) => {
|
|
4696
4815
|
if (element.overTypeInstance) {
|
|
@@ -4776,6 +4895,8 @@ ${blockSuffix}` : suffix;
|
|
|
4776
4895
|
onChange: null,
|
|
4777
4896
|
onKeydown: null,
|
|
4778
4897
|
onRender: null,
|
|
4898
|
+
onFocus: null,
|
|
4899
|
+
onBlur: null,
|
|
4779
4900
|
// Features
|
|
4780
4901
|
showActiveLineRaw: false,
|
|
4781
4902
|
showStats: false,
|
|
@@ -5226,6 +5347,24 @@ ${blockSuffix}` : suffix;
|
|
|
5226
5347
|
this.updatePreview();
|
|
5227
5348
|
this._notifyChange();
|
|
5228
5349
|
}
|
|
5350
|
+
/**
|
|
5351
|
+
* Handle focus events
|
|
5352
|
+
* @private
|
|
5353
|
+
*/
|
|
5354
|
+
handleFocus(event) {
|
|
5355
|
+
if (this.options.onFocus) {
|
|
5356
|
+
this.options.onFocus(event, this);
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
/**
|
|
5360
|
+
* Handle blur events
|
|
5361
|
+
* @private
|
|
5362
|
+
*/
|
|
5363
|
+
handleBlur(event) {
|
|
5364
|
+
if (this.options.onBlur) {
|
|
5365
|
+
this.options.onBlur(event, this);
|
|
5366
|
+
}
|
|
5367
|
+
}
|
|
5229
5368
|
/**
|
|
5230
5369
|
* Handle keydown events
|
|
5231
5370
|
* @private
|
|
@@ -5770,9 +5909,9 @@ ${blockSuffix}` : suffix;
|
|
|
5770
5909
|
* // HTML: <div class="editor" data-ot-toolbar="true" data-ot-theme="cave"></div>
|
|
5771
5910
|
* OverType.initFromData('.editor', { fontSize: '14px' });
|
|
5772
5911
|
*/
|
|
5773
|
-
static initFromData(
|
|
5774
|
-
const elements =
|
|
5775
|
-
return
|
|
5912
|
+
static initFromData(target, defaults = {}) {
|
|
5913
|
+
const elements = _OverType._resolveTargets(target);
|
|
5914
|
+
return elements.map((el) => {
|
|
5776
5915
|
const options = { ...defaults };
|
|
5777
5916
|
for (const attr of el.attributes) {
|
|
5778
5917
|
if (attr.name.startsWith("data-ot-")) {
|
|
@@ -5784,6 +5923,33 @@ ${blockSuffix}` : suffix;
|
|
|
5784
5923
|
return new _OverType(el, options)[0];
|
|
5785
5924
|
});
|
|
5786
5925
|
}
|
|
5926
|
+
/**
|
|
5927
|
+
* Normalize various target shapes to an array of Elements
|
|
5928
|
+
* @private
|
|
5929
|
+
* @param {string|Element|NodeList|Element[]} target
|
|
5930
|
+
* @returns {Element[]}
|
|
5931
|
+
*/
|
|
5932
|
+
static _resolveTargets(target) {
|
|
5933
|
+
if (target == null) {
|
|
5934
|
+
throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
|
|
5935
|
+
}
|
|
5936
|
+
if (typeof target === "string") {
|
|
5937
|
+
return Array.from(document.querySelectorAll(target));
|
|
5938
|
+
}
|
|
5939
|
+
if (target instanceof Element) {
|
|
5940
|
+
return [target];
|
|
5941
|
+
}
|
|
5942
|
+
if (target instanceof NodeList) {
|
|
5943
|
+
return Array.from(target);
|
|
5944
|
+
}
|
|
5945
|
+
if (Array.isArray(target)) {
|
|
5946
|
+
return target;
|
|
5947
|
+
}
|
|
5948
|
+
if (typeof target.length === "number") {
|
|
5949
|
+
return Array.from(target);
|
|
5950
|
+
}
|
|
5951
|
+
throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
|
|
5952
|
+
}
|
|
5787
5953
|
/**
|
|
5788
5954
|
* Parse a data attribute value to the appropriate type
|
|
5789
5955
|
* @private
|
|
@@ -5800,11 +5966,22 @@ ${blockSuffix}` : suffix;
|
|
|
5800
5966
|
return value;
|
|
5801
5967
|
}
|
|
5802
5968
|
/**
|
|
5803
|
-
* Get instance from
|
|
5804
|
-
*
|
|
5805
|
-
*
|
|
5969
|
+
* Get instance from a target. Accepts the same shapes as the constructor;
|
|
5970
|
+
* for multi-element targets, returns the instance for the first matching
|
|
5971
|
+
* element, or null if none.
|
|
5972
|
+
* @param {string|Element|NodeList|Element[]} target
|
|
5973
|
+
* @returns {OverType|null}
|
|
5806
5974
|
*/
|
|
5807
|
-
static getInstance(
|
|
5975
|
+
static getInstance(target) {
|
|
5976
|
+
let element;
|
|
5977
|
+
if (target instanceof Element) {
|
|
5978
|
+
element = target;
|
|
5979
|
+
} else {
|
|
5980
|
+
const elements = _OverType._resolveTargets(target);
|
|
5981
|
+
element = elements[0];
|
|
5982
|
+
}
|
|
5983
|
+
if (!element)
|
|
5984
|
+
return null;
|
|
5808
5985
|
return element.overTypeInstance || _OverType.instances.get(element) || null;
|
|
5809
5986
|
}
|
|
5810
5987
|
/**
|
|
@@ -5982,6 +6159,22 @@ ${blockSuffix}` : suffix;
|
|
|
5982
6159
|
instance.handleKeydown(e);
|
|
5983
6160
|
}
|
|
5984
6161
|
});
|
|
6162
|
+
document.addEventListener("focus", (e) => {
|
|
6163
|
+
if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
|
|
6164
|
+
const wrapper = e.target.closest(".overtype-wrapper");
|
|
6165
|
+
const instance = wrapper == null ? void 0 : wrapper._instance;
|
|
6166
|
+
if (instance)
|
|
6167
|
+
instance.handleFocus(e);
|
|
6168
|
+
}
|
|
6169
|
+
}, true);
|
|
6170
|
+
document.addEventListener("blur", (e) => {
|
|
6171
|
+
if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
|
|
6172
|
+
const wrapper = e.target.closest(".overtype-wrapper");
|
|
6173
|
+
const instance = wrapper == null ? void 0 : wrapper._instance;
|
|
6174
|
+
if (instance)
|
|
6175
|
+
instance.handleBlur(e);
|
|
6176
|
+
}
|
|
6177
|
+
}, true);
|
|
5985
6178
|
document.addEventListener("scroll", (e) => {
|
|
5986
6179
|
if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
|
|
5987
6180
|
const wrapper = e.target.closest(".overtype-wrapper");
|