overtype 2.3.7 → 2.3.9
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 +218 -23
- package/dist/overtype.js.map +3 -3
- package/dist/overtype.min.js +49 -941
- package/package.json +1 -1
- package/src/overtype.d.ts +24 -1
- package/src/overtype.js +92 -24
package/dist/overtype.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.9
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -35,6 +35,7 @@ var OverType = (() => {
|
|
|
35
35
|
OverType: () => OverType,
|
|
36
36
|
default: () => overtype_default,
|
|
37
37
|
defaultToolbarButtons: () => defaultToolbarButtons,
|
|
38
|
+
markdownActions: () => markdown_actions_esm_exports,
|
|
38
39
|
toolbarButtons: () => toolbarButtons
|
|
39
40
|
});
|
|
40
41
|
|
|
@@ -1913,6 +1914,30 @@ var OverType = (() => {
|
|
|
1913
1914
|
}
|
|
1914
1915
|
|
|
1915
1916
|
// node_modules/markdown-actions/dist/markdown-actions.esm.js
|
|
1917
|
+
var markdown_actions_esm_exports = {};
|
|
1918
|
+
__export(markdown_actions_esm_exports, {
|
|
1919
|
+
applyCustomFormat: () => applyCustomFormat,
|
|
1920
|
+
default: () => src_default,
|
|
1921
|
+
expandSelection: () => expandSelection2,
|
|
1922
|
+
getActiveFormats: () => getActiveFormats2,
|
|
1923
|
+
getDebugMode: () => getDebugMode,
|
|
1924
|
+
hasFormat: () => hasFormat2,
|
|
1925
|
+
insertHeader: () => insertHeader,
|
|
1926
|
+
insertLink: () => insertLink,
|
|
1927
|
+
preserveSelection: () => preserveSelection,
|
|
1928
|
+
setDebugMode: () => setDebugMode,
|
|
1929
|
+
setUndoMethod: () => setUndoMethod,
|
|
1930
|
+
toggleBold: () => toggleBold,
|
|
1931
|
+
toggleBulletList: () => toggleBulletList,
|
|
1932
|
+
toggleCode: () => toggleCode,
|
|
1933
|
+
toggleH1: () => toggleH1,
|
|
1934
|
+
toggleH2: () => toggleH2,
|
|
1935
|
+
toggleH3: () => toggleH3,
|
|
1936
|
+
toggleItalic: () => toggleItalic,
|
|
1937
|
+
toggleNumberedList: () => toggleNumberedList,
|
|
1938
|
+
toggleQuote: () => toggleQuote,
|
|
1939
|
+
toggleTaskList: () => toggleTaskList
|
|
1940
|
+
});
|
|
1916
1941
|
var __defProp2 = Object.defineProperty;
|
|
1917
1942
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1918
1943
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
@@ -1999,6 +2024,9 @@ var OverType = (() => {
|
|
|
1999
2024
|
return __spreadValues(__spreadValues({}, getDefaultStyle()), format);
|
|
2000
2025
|
}
|
|
2001
2026
|
var debugMode = false;
|
|
2027
|
+
function setDebugMode(enabled) {
|
|
2028
|
+
debugMode = enabled;
|
|
2029
|
+
}
|
|
2002
2030
|
function getDebugMode() {
|
|
2003
2031
|
return debugMode;
|
|
2004
2032
|
}
|
|
@@ -2119,6 +2147,19 @@ var OverType = (() => {
|
|
|
2119
2147
|
console.groupEnd();
|
|
2120
2148
|
}
|
|
2121
2149
|
}
|
|
2150
|
+
function setUndoMethod(method) {
|
|
2151
|
+
switch (method) {
|
|
2152
|
+
case "native":
|
|
2153
|
+
canInsertText = true;
|
|
2154
|
+
break;
|
|
2155
|
+
case "manual":
|
|
2156
|
+
canInsertText = false;
|
|
2157
|
+
break;
|
|
2158
|
+
case "auto":
|
|
2159
|
+
canInsertText = null;
|
|
2160
|
+
break;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2122
2163
|
function isMultipleLines(string) {
|
|
2123
2164
|
return string.trim().split("\n").length > 1;
|
|
2124
2165
|
}
|
|
@@ -2188,6 +2229,15 @@ var OverType = (() => {
|
|
|
2188
2229
|
}
|
|
2189
2230
|
return { newlinesToAppend, newlinesToPrepend };
|
|
2190
2231
|
}
|
|
2232
|
+
function preserveSelection(textarea, callback) {
|
|
2233
|
+
const start = textarea.selectionStart;
|
|
2234
|
+
const end = textarea.selectionEnd;
|
|
2235
|
+
const scrollTop = textarea.scrollTop;
|
|
2236
|
+
callback();
|
|
2237
|
+
textarea.selectionStart = start;
|
|
2238
|
+
textarea.selectionEnd = end;
|
|
2239
|
+
textarea.scrollTop = scrollTop;
|
|
2240
|
+
}
|
|
2191
2241
|
function applyLineOperation(textarea, operation, options = {}) {
|
|
2192
2242
|
const originalStart = textarea.selectionStart;
|
|
2193
2243
|
const originalEnd = textarea.selectionEnd;
|
|
@@ -2561,6 +2611,43 @@ ${blockSuffix}` : suffix;
|
|
|
2561
2611
|
}
|
|
2562
2612
|
return formats;
|
|
2563
2613
|
}
|
|
2614
|
+
function hasFormat(textarea, format) {
|
|
2615
|
+
const activeFormats = getActiveFormats(textarea);
|
|
2616
|
+
return activeFormats.includes(format);
|
|
2617
|
+
}
|
|
2618
|
+
function expandSelection(textarea, options = {}) {
|
|
2619
|
+
if (!textarea)
|
|
2620
|
+
return;
|
|
2621
|
+
const { toWord, toLine, toFormat } = options;
|
|
2622
|
+
const { selectionStart, selectionEnd, value } = textarea;
|
|
2623
|
+
if (toLine) {
|
|
2624
|
+
const lines = value.split("\n");
|
|
2625
|
+
let lineStart = 0;
|
|
2626
|
+
let lineEnd = 0;
|
|
2627
|
+
let currentPos = 0;
|
|
2628
|
+
for (const line of lines) {
|
|
2629
|
+
if (selectionStart >= currentPos && selectionStart <= currentPos + line.length) {
|
|
2630
|
+
lineStart = currentPos;
|
|
2631
|
+
lineEnd = currentPos + line.length;
|
|
2632
|
+
break;
|
|
2633
|
+
}
|
|
2634
|
+
currentPos += line.length + 1;
|
|
2635
|
+
}
|
|
2636
|
+
textarea.selectionStart = lineStart;
|
|
2637
|
+
textarea.selectionEnd = lineEnd;
|
|
2638
|
+
} else if (toWord && selectionStart === selectionEnd) {
|
|
2639
|
+
let start = selectionStart;
|
|
2640
|
+
let end = selectionEnd;
|
|
2641
|
+
while (start > 0 && !/\s/.test(value[start - 1])) {
|
|
2642
|
+
start--;
|
|
2643
|
+
}
|
|
2644
|
+
while (end < value.length && !/\s/.test(value[end])) {
|
|
2645
|
+
end++;
|
|
2646
|
+
}
|
|
2647
|
+
textarea.selectionStart = start;
|
|
2648
|
+
textarea.selectionEnd = end;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2564
2651
|
function toggleBold(textarea) {
|
|
2565
2652
|
if (!textarea || textarea.disabled || textarea.readOnly)
|
|
2566
2653
|
return;
|
|
@@ -2754,6 +2841,51 @@ ${blockSuffix}` : suffix;
|
|
|
2754
2841
|
function getActiveFormats2(textarea) {
|
|
2755
2842
|
return getActiveFormats(textarea);
|
|
2756
2843
|
}
|
|
2844
|
+
function hasFormat2(textarea, format) {
|
|
2845
|
+
return hasFormat(textarea, format);
|
|
2846
|
+
}
|
|
2847
|
+
function expandSelection2(textarea, options = {}) {
|
|
2848
|
+
expandSelection(textarea, options);
|
|
2849
|
+
}
|
|
2850
|
+
function applyCustomFormat(textarea, format) {
|
|
2851
|
+
if (!textarea || textarea.disabled || textarea.readOnly)
|
|
2852
|
+
return;
|
|
2853
|
+
const style = mergeWithDefaults(format);
|
|
2854
|
+
let result;
|
|
2855
|
+
if (style.multiline) {
|
|
2856
|
+
const selectedText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd);
|
|
2857
|
+
if (isMultipleLines(selectedText)) {
|
|
2858
|
+
result = multilineStyle(textarea, style);
|
|
2859
|
+
} else {
|
|
2860
|
+
result = blockStyle(textarea, style);
|
|
2861
|
+
}
|
|
2862
|
+
} else {
|
|
2863
|
+
result = blockStyle(textarea, style);
|
|
2864
|
+
}
|
|
2865
|
+
insertText(textarea, result);
|
|
2866
|
+
}
|
|
2867
|
+
var src_default = {
|
|
2868
|
+
toggleBold,
|
|
2869
|
+
toggleItalic,
|
|
2870
|
+
toggleCode,
|
|
2871
|
+
insertLink,
|
|
2872
|
+
toggleBulletList,
|
|
2873
|
+
toggleNumberedList,
|
|
2874
|
+
toggleQuote,
|
|
2875
|
+
toggleTaskList,
|
|
2876
|
+
insertHeader,
|
|
2877
|
+
toggleH1,
|
|
2878
|
+
toggleH2,
|
|
2879
|
+
toggleH3,
|
|
2880
|
+
getActiveFormats: getActiveFormats2,
|
|
2881
|
+
hasFormat: hasFormat2,
|
|
2882
|
+
expandSelection: expandSelection2,
|
|
2883
|
+
applyCustomFormat,
|
|
2884
|
+
preserveSelection,
|
|
2885
|
+
setUndoMethod,
|
|
2886
|
+
setDebugMode,
|
|
2887
|
+
getDebugMode
|
|
2888
|
+
};
|
|
2757
2889
|
|
|
2758
2890
|
// src/toolbar.js
|
|
2759
2891
|
var Toolbar = class {
|
|
@@ -4679,21 +4811,9 @@ ${blockSuffix}` : suffix;
|
|
|
4679
4811
|
* @returns {Array} Array of OverType instances
|
|
4680
4812
|
*/
|
|
4681
4813
|
constructor(target, options = {}) {
|
|
4682
|
-
|
|
4683
|
-
if (typeof target === "string") {
|
|
4684
|
-
elements
|
|
4685
|
-
if (elements.length === 0) {
|
|
4686
|
-
throw new Error(`No elements found for selector: ${target}`);
|
|
4687
|
-
}
|
|
4688
|
-
elements = Array.from(elements);
|
|
4689
|
-
} else if (target instanceof Element) {
|
|
4690
|
-
elements = [target];
|
|
4691
|
-
} else if (target instanceof NodeList) {
|
|
4692
|
-
elements = Array.from(target);
|
|
4693
|
-
} else if (Array.isArray(target)) {
|
|
4694
|
-
elements = target;
|
|
4695
|
-
} else {
|
|
4696
|
-
throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
|
|
4814
|
+
const elements = _OverType._resolveTargets(target);
|
|
4815
|
+
if (typeof target === "string" && elements.length === 0) {
|
|
4816
|
+
throw new Error(`No elements found for selector: ${target}`);
|
|
4697
4817
|
}
|
|
4698
4818
|
const instances = elements.map((element) => {
|
|
4699
4819
|
if (element.overTypeInstance) {
|
|
@@ -4779,6 +4899,8 @@ ${blockSuffix}` : suffix;
|
|
|
4779
4899
|
onChange: null,
|
|
4780
4900
|
onKeydown: null,
|
|
4781
4901
|
onRender: null,
|
|
4902
|
+
onFocus: null,
|
|
4903
|
+
onBlur: null,
|
|
4782
4904
|
// Features
|
|
4783
4905
|
showActiveLineRaw: false,
|
|
4784
4906
|
showStats: false,
|
|
@@ -5229,6 +5351,24 @@ ${blockSuffix}` : suffix;
|
|
|
5229
5351
|
this.updatePreview();
|
|
5230
5352
|
this._notifyChange();
|
|
5231
5353
|
}
|
|
5354
|
+
/**
|
|
5355
|
+
* Handle focus events
|
|
5356
|
+
* @private
|
|
5357
|
+
*/
|
|
5358
|
+
handleFocus(event) {
|
|
5359
|
+
if (this.options.onFocus) {
|
|
5360
|
+
this.options.onFocus(event, this);
|
|
5361
|
+
}
|
|
5362
|
+
}
|
|
5363
|
+
/**
|
|
5364
|
+
* Handle blur events
|
|
5365
|
+
* @private
|
|
5366
|
+
*/
|
|
5367
|
+
handleBlur(event) {
|
|
5368
|
+
if (this.options.onBlur) {
|
|
5369
|
+
this.options.onBlur(event, this);
|
|
5370
|
+
}
|
|
5371
|
+
}
|
|
5232
5372
|
/**
|
|
5233
5373
|
* Handle keydown events
|
|
5234
5374
|
* @private
|
|
@@ -5773,9 +5913,9 @@ ${blockSuffix}` : suffix;
|
|
|
5773
5913
|
* // HTML: <div class="editor" data-ot-toolbar="true" data-ot-theme="cave"></div>
|
|
5774
5914
|
* OverType.initFromData('.editor', { fontSize: '14px' });
|
|
5775
5915
|
*/
|
|
5776
|
-
static initFromData(
|
|
5777
|
-
const elements =
|
|
5778
|
-
return
|
|
5916
|
+
static initFromData(target, defaults = {}) {
|
|
5917
|
+
const elements = _OverType._resolveTargets(target);
|
|
5918
|
+
return elements.map((el) => {
|
|
5779
5919
|
const options = { ...defaults };
|
|
5780
5920
|
for (const attr of el.attributes) {
|
|
5781
5921
|
if (attr.name.startsWith("data-ot-")) {
|
|
@@ -5787,6 +5927,33 @@ ${blockSuffix}` : suffix;
|
|
|
5787
5927
|
return new _OverType(el, options)[0];
|
|
5788
5928
|
});
|
|
5789
5929
|
}
|
|
5930
|
+
/**
|
|
5931
|
+
* Normalize various target shapes to an array of Elements
|
|
5932
|
+
* @private
|
|
5933
|
+
* @param {string|Element|NodeList|Element[]} target
|
|
5934
|
+
* @returns {Element[]}
|
|
5935
|
+
*/
|
|
5936
|
+
static _resolveTargets(target) {
|
|
5937
|
+
if (target == null) {
|
|
5938
|
+
throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
|
|
5939
|
+
}
|
|
5940
|
+
if (typeof target === "string") {
|
|
5941
|
+
return Array.from(document.querySelectorAll(target));
|
|
5942
|
+
}
|
|
5943
|
+
if (target instanceof Element) {
|
|
5944
|
+
return [target];
|
|
5945
|
+
}
|
|
5946
|
+
if (target instanceof NodeList) {
|
|
5947
|
+
return Array.from(target);
|
|
5948
|
+
}
|
|
5949
|
+
if (Array.isArray(target)) {
|
|
5950
|
+
return target;
|
|
5951
|
+
}
|
|
5952
|
+
if (typeof target.length === "number") {
|
|
5953
|
+
return Array.from(target);
|
|
5954
|
+
}
|
|
5955
|
+
throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
|
|
5956
|
+
}
|
|
5790
5957
|
/**
|
|
5791
5958
|
* Parse a data attribute value to the appropriate type
|
|
5792
5959
|
* @private
|
|
@@ -5803,11 +5970,22 @@ ${blockSuffix}` : suffix;
|
|
|
5803
5970
|
return value;
|
|
5804
5971
|
}
|
|
5805
5972
|
/**
|
|
5806
|
-
* Get instance from
|
|
5807
|
-
*
|
|
5808
|
-
*
|
|
5973
|
+
* Get instance from a target. Accepts the same shapes as the constructor;
|
|
5974
|
+
* for multi-element targets, returns the instance for the first matching
|
|
5975
|
+
* element, or null if none.
|
|
5976
|
+
* @param {string|Element|NodeList|Element[]} target
|
|
5977
|
+
* @returns {OverType|null}
|
|
5809
5978
|
*/
|
|
5810
|
-
static getInstance(
|
|
5979
|
+
static getInstance(target) {
|
|
5980
|
+
let element;
|
|
5981
|
+
if (target instanceof Element) {
|
|
5982
|
+
element = target;
|
|
5983
|
+
} else {
|
|
5984
|
+
const elements = _OverType._resolveTargets(target);
|
|
5985
|
+
element = elements[0];
|
|
5986
|
+
}
|
|
5987
|
+
if (!element)
|
|
5988
|
+
return null;
|
|
5811
5989
|
return element.overTypeInstance || _OverType.instances.get(element) || null;
|
|
5812
5990
|
}
|
|
5813
5991
|
/**
|
|
@@ -5985,6 +6163,22 @@ ${blockSuffix}` : suffix;
|
|
|
5985
6163
|
instance.handleKeydown(e);
|
|
5986
6164
|
}
|
|
5987
6165
|
});
|
|
6166
|
+
document.addEventListener("focus", (e) => {
|
|
6167
|
+
if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
|
|
6168
|
+
const wrapper = e.target.closest(".overtype-wrapper");
|
|
6169
|
+
const instance = wrapper == null ? void 0 : wrapper._instance;
|
|
6170
|
+
if (instance)
|
|
6171
|
+
instance.handleFocus(e);
|
|
6172
|
+
}
|
|
6173
|
+
}, true);
|
|
6174
|
+
document.addEventListener("blur", (e) => {
|
|
6175
|
+
if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
|
|
6176
|
+
const wrapper = e.target.closest(".overtype-wrapper");
|
|
6177
|
+
const instance = wrapper == null ? void 0 : wrapper._instance;
|
|
6178
|
+
if (instance)
|
|
6179
|
+
instance.handleBlur(e);
|
|
6180
|
+
}
|
|
6181
|
+
}, true);
|
|
5988
6182
|
document.addEventListener("scroll", (e) => {
|
|
5989
6183
|
if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
|
|
5990
6184
|
const wrapper = e.target.closest(".overtype-wrapper");
|
|
@@ -6041,6 +6235,7 @@ if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
|
6041
6235
|
// Extract exports BEFORE reassigning OverType (var OverType is window.OverType)
|
|
6042
6236
|
window.toolbarButtons = OverType.toolbarButtons;
|
|
6043
6237
|
window.defaultToolbarButtons = OverType.defaultToolbarButtons;
|
|
6238
|
+
window.markdownActions = OverType.markdownActions;
|
|
6044
6239
|
window.OverType = OverType.default ? OverType.default : OverType;
|
|
6045
6240
|
}
|
|
6046
6241
|
|