editable.ts 0.0.1
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/LICENSE +21 -0
- package/README.md +571 -0
- package/dist/editable.umd.cjs +2 -0
- package/dist/editable.umd.cjs.map +1 -0
- package/lib/block.d.ts +13 -0
- package/lib/block.d.ts.map +1 -0
- package/lib/block.js +58 -0
- package/lib/block.js.map +1 -0
- package/lib/clipboard.d.ts +22 -0
- package/lib/clipboard.d.ts.map +1 -0
- package/lib/clipboard.js +154 -0
- package/lib/clipboard.js.map +1 -0
- package/lib/config.d.ts +37 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +64 -0
- package/lib/config.js.map +1 -0
- package/lib/content.d.ts +37 -0
- package/lib/content.d.ts.map +1 -0
- package/lib/content.js +526 -0
- package/lib/content.js.map +1 -0
- package/lib/core.d.ts +97 -0
- package/lib/core.d.ts.map +1 -0
- package/lib/core.js +261 -0
- package/lib/core.js.map +1 -0
- package/lib/create-default-behavior.d.ts +31 -0
- package/lib/create-default-behavior.d.ts.map +1 -0
- package/lib/create-default-behavior.js +178 -0
- package/lib/create-default-behavior.js.map +1 -0
- package/lib/create-default-events.d.ts +152 -0
- package/lib/create-default-events.d.ts.map +1 -0
- package/lib/create-default-events.js +183 -0
- package/lib/create-default-events.js.map +1 -0
- package/lib/cursor.d.ts +68 -0
- package/lib/cursor.d.ts.map +1 -0
- package/lib/cursor.js +354 -0
- package/lib/cursor.js.map +1 -0
- package/lib/dispatcher.d.ts +78 -0
- package/lib/dispatcher.d.ts.map +1 -0
- package/lib/dispatcher.js +416 -0
- package/lib/dispatcher.js.map +1 -0
- package/lib/eventable.d.ts +2 -0
- package/lib/eventable.d.ts.map +1 -0
- package/lib/eventable.js +104 -0
- package/lib/eventable.js.map +1 -0
- package/lib/feature-detection.d.ts +12 -0
- package/lib/feature-detection.d.ts.map +1 -0
- package/lib/feature-detection.js +42 -0
- package/lib/feature-detection.js.map +1 -0
- package/lib/highlight-support.d.ts +24 -0
- package/lib/highlight-support.d.ts.map +1 -0
- package/lib/highlight-support.js +172 -0
- package/lib/highlight-support.js.map +1 -0
- package/lib/highlight-text.d.ts +21 -0
- package/lib/highlight-text.d.ts.map +1 -0
- package/lib/highlight-text.js +147 -0
- package/lib/highlight-text.js.map +1 -0
- package/lib/keyboard.d.ts +33 -0
- package/lib/keyboard.d.ts.map +1 -0
- package/lib/keyboard.js +189 -0
- package/lib/keyboard.js.map +1 -0
- package/lib/monitored-highlighting.d.ts +28 -0
- package/lib/monitored-highlighting.d.ts.map +1 -0
- package/lib/monitored-highlighting.js +194 -0
- package/lib/monitored-highlighting.js.map +1 -0
- package/lib/node-iterator.d.ts +16 -0
- package/lib/node-iterator.d.ts.map +1 -0
- package/lib/node-iterator.js +97 -0
- package/lib/node-iterator.js.map +1 -0
- package/lib/node-type.d.ts +13 -0
- package/lib/node-type.d.ts.map +1 -0
- package/lib/node-type.js +15 -0
- package/lib/node-type.js.map +1 -0
- package/lib/parser.d.ts +89 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +251 -0
- package/lib/parser.js.map +1 -0
- package/lib/plugins/highlighting/match-collection.d.ts +7 -0
- package/lib/plugins/highlighting/match-collection.d.ts.map +1 -0
- package/lib/plugins/highlighting/match-collection.js +62 -0
- package/lib/plugins/highlighting/match-collection.js.map +1 -0
- package/lib/plugins/highlighting/spellcheck-service.d.ts +12 -0
- package/lib/plugins/highlighting/spellcheck-service.d.ts.map +1 -0
- package/lib/plugins/highlighting/spellcheck-service.js +24 -0
- package/lib/plugins/highlighting/spellcheck-service.js.map +1 -0
- package/lib/plugins/highlighting/text-search.d.ts +10 -0
- package/lib/plugins/highlighting/text-search.d.ts.map +1 -0
- package/lib/plugins/highlighting/text-search.js +92 -0
- package/lib/plugins/highlighting/text-search.js.map +1 -0
- package/lib/plugins/highlighting/whitespace-highlighting.d.ts +14 -0
- package/lib/plugins/highlighting/whitespace-highlighting.d.ts.map +1 -0
- package/lib/plugins/highlighting/whitespace-highlighting.js +52 -0
- package/lib/plugins/highlighting/whitespace-highlighting.js.map +1 -0
- package/lib/quotes.d.ts +8 -0
- package/lib/quotes.d.ts.map +1 -0
- package/lib/quotes.js +170 -0
- package/lib/quotes.js.map +1 -0
- package/lib/range-container.d.ts +22 -0
- package/lib/range-container.d.ts.map +1 -0
- package/lib/range-container.js +52 -0
- package/lib/range-container.js.map +1 -0
- package/lib/range-save-restore.d.ts +13 -0
- package/lib/range-save-restore.d.ts.map +1 -0
- package/lib/range-save-restore.js +153 -0
- package/lib/range-save-restore.js.map +1 -0
- package/lib/selection-watcher.d.ts +55 -0
- package/lib/selection-watcher.d.ts.map +1 -0
- package/lib/selection-watcher.js +126 -0
- package/lib/selection-watcher.js.map +1 -0
- package/lib/selection.d.ts +74 -0
- package/lib/selection.d.ts.map +1 -0
- package/lib/selection.js +341 -0
- package/lib/selection.js.map +1 -0
- package/lib/smartQuotes.d.ts +16 -0
- package/lib/smartQuotes.d.ts.map +1 -0
- package/lib/smartQuotes.js +92 -0
- package/lib/smartQuotes.js.map +1 -0
- package/lib/util/binary_search.d.ts +23 -0
- package/lib/util/binary_search.d.ts.map +1 -0
- package/lib/util/binary_search.js +137 -0
- package/lib/util/binary_search.js.map +1 -0
- package/lib/util/clone-deep.d.ts +8 -0
- package/lib/util/clone-deep.d.ts.map +1 -0
- package/lib/util/clone-deep.js +10 -0
- package/lib/util/clone-deep.js.map +1 -0
- package/lib/util/dom.d.ts +43 -0
- package/lib/util/dom.d.ts.map +1 -0
- package/lib/util/dom.js +272 -0
- package/lib/util/dom.js.map +1 -0
- package/lib/util/element.d.ts +10 -0
- package/lib/util/element.d.ts.map +1 -0
- package/lib/util/element.js +29 -0
- package/lib/util/element.js.map +1 -0
- package/lib/util/error.d.ts +2 -0
- package/lib/util/error.d.ts.map +1 -0
- package/lib/util/error.js +16 -0
- package/lib/util/error.js.map +1 -0
- package/lib/util/log.d.ts +2 -0
- package/lib/util/log.d.ts.map +1 -0
- package/lib/util/log.js +18 -0
- package/lib/util/log.js.map +1 -0
- package/lib/util/merge.d.ts +6 -0
- package/lib/util/merge.d.ts.map +1 -0
- package/lib/util/merge.js +31 -0
- package/lib/util/merge.js.map +1 -0
- package/lib/util/string.d.ts +25 -0
- package/lib/util/string.d.ts.map +1 -0
- package/lib/util/string.js +68 -0
- package/lib/util/string.js.map +1 -0
- package/lib/util/viewport.d.ts +6 -0
- package/lib/util/viewport.d.ts.map +1 -0
- package/lib/util/viewport.js +8 -0
- package/lib/util/viewport.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/util/element.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAGjD;AAID,wBAAgB,4BAA4B,CAAC,EAAC,SAAS,EAAE,SAAS,EAAC,EAAE;IACnE,SAAS,EAAE,IAAI,EAAE,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG;IAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAC,CAenD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,MAAM,CAIvD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import NodeIterator from '../node-iterator.js';
|
|
2
|
+
export function textNodesUnder(node) {
|
|
3
|
+
const iterator = new NodeIterator(node, 'getNextTextNode');
|
|
4
|
+
return [...iterator];
|
|
5
|
+
}
|
|
6
|
+
// NOTE: if there is only one text node, then just that node and
|
|
7
|
+
// the abs offset are returned
|
|
8
|
+
export function getTextNodeAndRelativeOffset({ textNodes, absOffset }) {
|
|
9
|
+
let cumulativeOffset = 0;
|
|
10
|
+
let relativeOffset = 0;
|
|
11
|
+
let targetNode;
|
|
12
|
+
for (let i = 0; i < textNodes.length; i++) {
|
|
13
|
+
const node = textNodes[i];
|
|
14
|
+
const nodeLength = node.textContent?.length || 0;
|
|
15
|
+
if (absOffset <= cumulativeOffset + nodeLength) {
|
|
16
|
+
targetNode = node;
|
|
17
|
+
relativeOffset = absOffset - cumulativeOffset;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
cumulativeOffset += nodeLength;
|
|
21
|
+
}
|
|
22
|
+
return { node: targetNode, relativeOffset };
|
|
23
|
+
}
|
|
24
|
+
export function getTotalCharCount(element) {
|
|
25
|
+
const textNodes = textNodesUnder(element);
|
|
26
|
+
const reducer = (acc, node) => acc + (node.textContent?.length || 0);
|
|
27
|
+
return textNodes.reduce(reducer, 0);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/util/element.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,qBAAqB,CAAA;AAE9C,MAAM,UAAU,cAAc,CAAC,IAAU;IACvC,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;IAC1D,OAAO,CAAC,GAAG,QAAQ,CAAW,CAAA;AAChC,CAAC;AAED,gEAAgE;AAChE,8BAA8B;AAC9B,MAAM,UAAU,4BAA4B,CAAC,EAAC,SAAS,EAAE,SAAS,EAGjE;IACC,IAAI,gBAAgB,GAAG,CAAC,CAAA;IACxB,IAAI,cAAc,GAAG,CAAC,CAAA;IACtB,IAAI,UAA4B,CAAA;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,CAAA;QAChD,IAAI,SAAS,IAAI,gBAAgB,GAAG,UAAU,EAAE,CAAC;YAC/C,UAAU,GAAG,IAAI,CAAA;YACjB,cAAc,GAAG,SAAS,GAAG,gBAAgB,CAAA;YAC7C,MAAK;QACP,CAAC;QACD,gBAAgB,IAAI,UAAU,CAAA;IAChC,CAAC;IACD,OAAO,EAAC,IAAI,EAAE,UAAU,EAAE,cAAc,EAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAa;IAC7C,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACzC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,IAAU,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,CAAC,CAAA;IAClF,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAalD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import config from '../config.js';
|
|
2
|
+
// Allows for safe error logging
|
|
3
|
+
// Falls back to console.log if console.error is not available
|
|
4
|
+
export default function error(...args) {
|
|
5
|
+
if (config.logErrors === false)
|
|
6
|
+
return;
|
|
7
|
+
const errorArgs = args.length === 1 ? args[0] : args;
|
|
8
|
+
if (!global.console)
|
|
9
|
+
return;
|
|
10
|
+
if (typeof console.error === 'function') {
|
|
11
|
+
console.error(errorArgs);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
console.log(errorArgs);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cAAc,CAAA;AAEjC,gCAAgC;AAChC,8DAA8D;AAC9D,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,GAAG,IAAW;IAC1C,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK;QAAE,OAAM;IAEtC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAEpD,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAM;IAE3B,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QACxB,OAAM;IACR,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/util/log.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAahD"}
|
package/lib/util/log.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import config from '../config.js';
|
|
2
|
+
// Allows for safe console logging
|
|
3
|
+
// If the last param is the string "trace" console.trace will be called
|
|
4
|
+
// configuration: disable with config.log = false
|
|
5
|
+
export default function log(...args) {
|
|
6
|
+
if (config.log === false)
|
|
7
|
+
return;
|
|
8
|
+
if (!global.console)
|
|
9
|
+
return;
|
|
10
|
+
const logArgs = args.length === 1 ? args[0] : args;
|
|
11
|
+
if (args.length !== 1 && logArgs[logArgs.length - 1] === 'trace') {
|
|
12
|
+
logArgs.pop();
|
|
13
|
+
if (console.trace)
|
|
14
|
+
console.trace();
|
|
15
|
+
}
|
|
16
|
+
console.log(logArgs);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/util/log.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cAAc,CAAA;AAEjC,kCAAkC;AAClC,uEAAuE;AACvE,iDAAiD;AACjD,MAAM,CAAC,OAAO,UAAU,GAAG,CAAC,GAAG,IAAW;IACxC,IAAI,MAAM,CAAC,GAAG,KAAK,KAAK;QAAE,OAAM;IAEhC,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAM;IAE3B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAElD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QACjE,OAAO,CAAC,GAAG,EAAE,CAAA;QACb,IAAI,OAAO,CAAC,KAAK;YAAE,OAAO,CAAC,KAAK,EAAE,CAAA;IACpC,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/util/merge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CA6B/F"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep merge objects, creating a new object with merged properties.
|
|
3
|
+
* Arrays are replaced (not merged).
|
|
4
|
+
*/
|
|
5
|
+
export function deepMerge(target, ...sources) {
|
|
6
|
+
const result = { ...target };
|
|
7
|
+
for (const source of sources) {
|
|
8
|
+
if (!source || typeof source !== 'object')
|
|
9
|
+
continue;
|
|
10
|
+
for (const key in source) {
|
|
11
|
+
if (!Object.prototype.hasOwnProperty.call(source, key))
|
|
12
|
+
continue;
|
|
13
|
+
const sourceValue = source[key];
|
|
14
|
+
const targetValue = result[key];
|
|
15
|
+
// Deep merge if both are plain objects
|
|
16
|
+
if (sourceValue &&
|
|
17
|
+
typeof sourceValue === 'object' &&
|
|
18
|
+
!Array.isArray(sourceValue) &&
|
|
19
|
+
targetValue &&
|
|
20
|
+
typeof targetValue === 'object' &&
|
|
21
|
+
!Array.isArray(targetValue)) {
|
|
22
|
+
result[key] = deepMerge({}, targetValue, sourceValue);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
result[key] = sourceValue;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/util/merge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAgC,MAAS,EAAE,GAAG,OAAqB;IAC1F,MAAM,MAAM,GAAG,EAAC,GAAG,MAAM,EAAQ,CAAA;IAEjC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;YAAE,SAAQ;QAEnD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;gBAAE,SAAQ;YAEhE,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;YAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;YAE/B,uCAAuC;YACvC,IACE,WAAW;gBACX,OAAO,WAAW,KAAK,QAAQ;gBAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;gBAC3B,WAAW;gBACX,OAAO,WAAW,KAAK,QAAQ;gBAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAC3B,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;YACvD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAW,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function trimRight(text: string): string;
|
|
2
|
+
export declare function trimLeft(text: string): string;
|
|
3
|
+
export declare function trim(text: string): string;
|
|
4
|
+
export declare function isString(obj: any): obj is string;
|
|
5
|
+
/**
|
|
6
|
+
* Turn any string into a regular expression.
|
|
7
|
+
* This can be used to search or replace a string conveniently.
|
|
8
|
+
*/
|
|
9
|
+
export declare function regexp(str: string, flags?: string): RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* Escape HTML characters <, > and &
|
|
12
|
+
* Usage: escapeHtml('<div>')
|
|
13
|
+
*
|
|
14
|
+
* @param { String }
|
|
15
|
+
* @param { Boolean } Optional. If true " and ' will also be escaped.
|
|
16
|
+
* @return { String } Escaped Html you can assign to innerHTML of an element.
|
|
17
|
+
*/
|
|
18
|
+
export declare function escapeHtml(s: string, forAttribute?: boolean): string;
|
|
19
|
+
/**
|
|
20
|
+
* Escape a string the browser way.
|
|
21
|
+
*/
|
|
22
|
+
export declare function browserEscapeHtml(str: string): string;
|
|
23
|
+
export declare function replaceLast(text: string | null | undefined, searchValue: string | null | undefined, replaceValue: string | null | undefined): string;
|
|
24
|
+
export declare function endsWithSingleSpace(text: string): boolean;
|
|
25
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/util/string.ts"],"names":[],"mappings":"AAUA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED;;;;;;;GAOG;AAGH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,CAIpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAapJ;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const toString = Object.prototype.toString;
|
|
2
|
+
const htmlCharacters = {
|
|
3
|
+
'&': '&',
|
|
4
|
+
'<': '<',
|
|
5
|
+
'>': '>',
|
|
6
|
+
'"': '"',
|
|
7
|
+
"'": '''
|
|
8
|
+
};
|
|
9
|
+
// TODO: replace with lodash methods
|
|
10
|
+
export function trimRight(text) {
|
|
11
|
+
return text.replace(/\s+$/, '');
|
|
12
|
+
}
|
|
13
|
+
export function trimLeft(text) {
|
|
14
|
+
return text.replace(/^\s+/, '');
|
|
15
|
+
}
|
|
16
|
+
export function trim(text) {
|
|
17
|
+
return text.replace(/^\s+|\s+$/g, '');
|
|
18
|
+
}
|
|
19
|
+
export function isString(obj) {
|
|
20
|
+
return toString.call(obj) === '[object String]';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turn any string into a regular expression.
|
|
24
|
+
* This can be used to search or replace a string conveniently.
|
|
25
|
+
*/
|
|
26
|
+
export function regexp(str, flags) {
|
|
27
|
+
if (!flags)
|
|
28
|
+
flags = 'g';
|
|
29
|
+
const escapedStr = str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
30
|
+
return new RegExp(escapedStr, flags);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Escape HTML characters <, > and &
|
|
34
|
+
* Usage: escapeHtml('<div>')
|
|
35
|
+
*
|
|
36
|
+
* @param { String }
|
|
37
|
+
* @param { Boolean } Optional. If true " and ' will also be escaped.
|
|
38
|
+
* @return { String } Escaped Html you can assign to innerHTML of an element.
|
|
39
|
+
*/
|
|
40
|
+
// TODO: replace with npm.im/he
|
|
41
|
+
export function escapeHtml(s, forAttribute) {
|
|
42
|
+
return s.replace(forAttribute ? /[&<>'"]/g : /[&<>]/g, function (c) {
|
|
43
|
+
return htmlCharacters[c] || c;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Escape a string the browser way.
|
|
48
|
+
*/
|
|
49
|
+
export function browserEscapeHtml(str) {
|
|
50
|
+
const div = document.createElement('div');
|
|
51
|
+
div.appendChild(document.createTextNode(str));
|
|
52
|
+
return div.innerHTML;
|
|
53
|
+
}
|
|
54
|
+
export function replaceLast(text, searchValue, replaceValue) {
|
|
55
|
+
if (!text)
|
|
56
|
+
return '';
|
|
57
|
+
text = `${text}`;
|
|
58
|
+
if (!searchValue || replaceValue == null)
|
|
59
|
+
return text;
|
|
60
|
+
const lastOccurrenceIndex = text.lastIndexOf(searchValue);
|
|
61
|
+
if (lastOccurrenceIndex === -1)
|
|
62
|
+
return text;
|
|
63
|
+
return `${text.slice(0, lastOccurrenceIndex)}${replaceValue}${text.slice(lastOccurrenceIndex + searchValue.length)}`;
|
|
64
|
+
}
|
|
65
|
+
export function endsWithSingleSpace(text) {
|
|
66
|
+
return /\S+\s{1}$/.test(text);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/util/string.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAA;AAC1C,MAAM,cAAc,GAA2B;IAC7C,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;CACb,CAAA;AAED,oCAAoC;AACpC,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAQ;IAC/B,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,iBAAiB,CAAA;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,KAAc;IAChD,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,GAAG,CAAA;IACvB,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAA;IAClE,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;GAOG;AAEH,+BAA+B;AAC/B,MAAM,UAAU,UAAU,CAAC,CAAS,EAAE,YAAsB;IAC1D,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAS;QACxE,OAAO,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IACzC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7C,OAAO,GAAG,CAAC,SAAS,CAAA;AACtB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAA+B,EAAE,WAAsC,EAAE,YAAuC;IAC1I,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,IAAI,GAAG,GAAG,IAAI,EAAE,CAAA;IAChB,IAAI,CAAC,WAAW,IAAI,YAAY,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IACrD,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACzD,IAAI,mBAAmB,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3C,OAAO,GACL,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CACnC,GACE,YACF,GACE,IAAI,CAAC,KAAK,CAAC,mBAAmB,GAAG,WAAW,CAAC,MAAM,CACrD,EAAE,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport.d.ts","sourceRoot":"","sources":["../../src/util/viewport.ts"],"names":[],"mappings":"AACA,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAI9D;AAED,OAAO,EAAC,iBAAiB,EAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// code from mdn: https://developer.mozilla.org/en-US/docs/Web/API/window.scrollX
|
|
2
|
+
function getScrollPosition(win) {
|
|
3
|
+
const x = (win.pageXOffset !== undefined) ? win.pageXOffset : (win.document.documentElement || win.document.body.parentNode || win.document.body).scrollLeft;
|
|
4
|
+
const y = (win.pageYOffset !== undefined) ? win.pageYOffset : (win.document.documentElement || win.document.body.parentNode || win.document.body).scrollTop;
|
|
5
|
+
return { x, y };
|
|
6
|
+
}
|
|
7
|
+
export { getScrollPosition };
|
|
8
|
+
//# sourceMappingURL=viewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport.js","sourceRoot":"","sources":["../../src/util/viewport.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,SAAS,iBAAiB,CAAC,GAAW;IACpC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,eAAe,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,CAAA;IAC5J,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,eAAe,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,CAAA;IAC3J,OAAO,EAAC,CAAC,EAAE,CAAC,EAAC,CAAA;AACf,CAAC;AAED,OAAO,EAAC,iBAAiB,EAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "editable.ts",
|
|
3
|
+
"description": "Friendly contenteditable API - A TypeScript library for block-level rich text editing with a clean, event-driven architecture",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@eslint/compat": "2.0.1",
|
|
9
|
+
"@types/node": "25.0.3",
|
|
10
|
+
"@preact/preset-vite": "2.10.2",
|
|
11
|
+
"@vitest/ui": "4.0.17",
|
|
12
|
+
"@vitest/coverage-v8": "4.0.17",
|
|
13
|
+
"eslint": "9.39.2",
|
|
14
|
+
"globals": "17.0.0",
|
|
15
|
+
"jsdom": "27.4.0",
|
|
16
|
+
"normalize.css": "8.0.1",
|
|
17
|
+
"prismjs": "1.30.0",
|
|
18
|
+
"preact": "10.28.2",
|
|
19
|
+
"prop-types": "15.8.1",
|
|
20
|
+
"rimraf": "6.1.2",
|
|
21
|
+
"terser": "5.46.0",
|
|
22
|
+
"typescript": "5.9.3",
|
|
23
|
+
"vite": "7.3.1",
|
|
24
|
+
"vite-plugin-css-injected-by-js": "3.5.2",
|
|
25
|
+
"vitest": "4.0.17"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22",
|
|
29
|
+
"npm": ">=11"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"lib",
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"keywords": [
|
|
38
|
+
"contenteditable",
|
|
39
|
+
"editable",
|
|
40
|
+
"rich-text",
|
|
41
|
+
"editor",
|
|
42
|
+
"typescript",
|
|
43
|
+
"block-editor",
|
|
44
|
+
"wysiwyg",
|
|
45
|
+
"text-editing",
|
|
46
|
+
"selection",
|
|
47
|
+
"range"
|
|
48
|
+
],
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"main": "./lib/core.js",
|
|
51
|
+
"types": "./lib/core.d.ts",
|
|
52
|
+
"module": "./lib/core.js",
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"types": "./lib/core.d.ts",
|
|
56
|
+
"import": "./lib/core.js",
|
|
57
|
+
"default": "./lib/core.js"
|
|
58
|
+
},
|
|
59
|
+
"./dist/editable.umd.cjs": {
|
|
60
|
+
"default": "./dist/editable.umd.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./package.json": "./package.json"
|
|
63
|
+
},
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "https://github.com/watzak/editable.ts.git"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"start": "vite --config vite/vite.config.docs.mjs",
|
|
70
|
+
"build:ts": "rimraf ./lib && tsc",
|
|
71
|
+
"build:dist": "rimraf ./dist && vite build --config vite/vite.config.dist.mjs",
|
|
72
|
+
"build:docs": "rimraf ./examples/dist && vite build --config vite/vite.config.docs.bundle.mjs && vite build --config vite/vite.config.docs.styles.mjs",
|
|
73
|
+
"build": "npm run build:ts -s && npm run build:dist -s && npm run build:docs -s",
|
|
74
|
+
"prepublishOnly": "npm run build -s",
|
|
75
|
+
"test:ci": "vitest run",
|
|
76
|
+
"test": "vitest run",
|
|
77
|
+
"posttest": "npm run lint -s",
|
|
78
|
+
"test:watch": "vitest",
|
|
79
|
+
"test:ui": "vitest --ui",
|
|
80
|
+
"test:coverage": "vitest run --coverage",
|
|
81
|
+
"lint": "eslint"
|
|
82
|
+
},
|
|
83
|
+
"overrides": {
|
|
84
|
+
"rimraf": "6.1.2"
|
|
85
|
+
}
|
|
86
|
+
}
|