react-smart-copy 1.17.2 → 1.19.0
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 +86 -5
- package/dist/capture.cjs +30 -153
- package/dist/capture.cjs.map +1 -1
- package/dist/capture.d.cts +2 -25
- package/dist/capture.d.ts +2 -25
- package/dist/capture.js +5 -128
- package/dist/capture.js.map +1 -1
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs +102 -0
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs.map +1 -0
- package/dist/chunks/clipboard-adapter-CtH4VELE.d.cts +43 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js +97 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js.map +1 -0
- package/dist/chunks/clipboard-adapter-Ds0irroN.d.ts +43 -0
- package/dist/chunks/contrast-C6CVklEI.cjs +842 -0
- package/dist/chunks/contrast-C6CVklEI.cjs.map +1 -0
- package/dist/chunks/contrast-DpK2JIVu.js +789 -0
- package/dist/chunks/contrast-DpK2JIVu.js.map +1 -0
- package/dist/chunks/copy-interceptor-C6NABy1l.d.ts +141 -0
- package/dist/chunks/copy-interceptor-CZWzGOkL.d.cts +141 -0
- package/dist/chunks/core-Cp2HSpaz.js +1035 -0
- package/dist/chunks/core-Cp2HSpaz.js.map +1 -0
- package/dist/chunks/core-DYf_Lhbe.cjs +1142 -0
- package/dist/chunks/core-DYf_Lhbe.cjs.map +1 -0
- package/dist/chunks/deadline-C29AlS_Q.js +46 -0
- package/dist/chunks/deadline-C29AlS_Q.js.map +1 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs +51 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs.map +1 -0
- package/dist/chunks/errors-9h8sdFFX.js +120 -0
- package/dist/chunks/errors-9h8sdFFX.js.map +1 -0
- package/dist/chunks/errors-BwOF6T_M.cjs +167 -0
- package/dist/chunks/errors-BwOF6T_M.cjs.map +1 -0
- package/dist/chunks/index-mr7sSAgP.d.ts +426 -0
- package/dist/chunks/index-vz0iW5V2.d.cts +426 -0
- package/dist/chunks/inert-html-D75NyVvT.js +34 -0
- package/dist/chunks/inert-html-D75NyVvT.js.map +1 -0
- package/dist/chunks/inert-html-DyxjWDok.cjs +39 -0
- package/dist/chunks/inert-html-DyxjWDok.cjs.map +1 -0
- package/dist/chunks/mime--LB7kdqG.cjs +153 -0
- package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
- package/dist/chunks/mime-aa-HA2dm.js +100 -0
- package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
- package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
- package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
- package/dist/chunks/payload-CUymxwim.cjs +100 -0
- package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
- package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
- package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
- package/dist/chunks/payload-DGw-JOo7.js +71 -0
- package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
- package/dist/chunks/payload-DI5AorDz.js +103 -0
- package/dist/chunks/payload-DI5AorDz.js.map +1 -0
- package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
- package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
- package/dist/chunks/share-Bop47Znn.js +208 -0
- package/dist/chunks/share-Bop47Znn.js.map +1 -0
- package/dist/chunks/share-C0esXvRK.d.cts +115 -0
- package/dist/chunks/share-ayDz974N.cjs +231 -0
- package/dist/chunks/share-ayDz974N.cjs.map +1 -0
- package/dist/chunks/share-e7FenIr2.d.ts +115 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
- package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
- package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
- package/dist/chunks/text-field-DUvrMMaK.js +66 -0
- package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
- package/dist/chunks/url-B9jdFGQy.cjs +86 -0
- package/dist/chunks/url-B9jdFGQy.cjs.map +1 -0
- package/dist/chunks/url-BcMYVCXQ.js +135 -0
- package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
- package/dist/chunks/url-D4PGsRm8.cjs +164 -0
- package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
- package/dist/chunks/url-DWdElCT3.d.cts +43 -0
- package/dist/chunks/url-DWdElCT3.d.ts +43 -0
- package/dist/chunks/url-vJaFPbNL.js +57 -0
- package/dist/chunks/url-vJaFPbNL.js.map +1 -0
- package/dist/code.cjs +22 -113
- package/dist/code.cjs.map +1 -1
- package/dist/code.d.cts +4 -28
- package/dist/code.d.ts +4 -28
- package/dist/code.js +5 -96
- package/dist/code.js.map +1 -1
- package/dist/color.cjs +21 -893
- package/dist/color.cjs.map +1 -1
- package/dist/color.d.cts +4 -28
- package/dist/color.d.ts +4 -28
- package/dist/color.js +4 -876
- package/dist/color.js.map +1 -1
- package/dist/core.cjs +52 -1659
- package/dist/core.d.cts +8 -878
- package/dist/core.d.ts +8 -878
- package/dist/core.js +7 -1614
- package/dist/image.cjs +23 -94
- package/dist/image.cjs.map +1 -1
- package/dist/image.d.cts +1 -0
- package/dist/image.d.ts +1 -0
- package/dist/image.js +3 -74
- package/dist/image.js.map +1 -1
- package/dist/index.cjs +74 -2072
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -978
- package/dist/index.d.ts +8 -978
- package/dist/index.js +7 -2005
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +26 -339
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +5 -83
- package/dist/link.d.ts +5 -83
- package/dist/link.js +7 -320
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +19 -159
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -16
- package/dist/markdown.d.ts +3 -16
- package/dist/markdown.js +6 -146
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +1123 -940
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +101 -91
- package/dist/rich.d.ts +101 -91
- package/dist/rich.js +1099 -919
- package/dist/rich.js.map +1 -1
- package/dist/share.cjs +5 -640
- package/dist/share.d.cts +3 -248
- package/dist/share.d.ts +3 -248
- package/dist/share.js +1 -637
- package/dist/structured.cjs +13 -95
- package/dist/structured.cjs.map +1 -1
- package/dist/structured.d.cts +2 -11
- package/dist/structured.d.ts +2 -11
- package/dist/structured.js +4 -86
- package/dist/structured.js.map +1 -1
- package/dist/table.cjs +13 -40
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +2 -12
- package/dist/table.d.ts +2 -12
- package/dist/table.js +4 -31
- package/dist/table.js.map +1 -1
- package/dist/testing.cjs +10 -43
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +6 -181
- package/dist/testing.d.ts +6 -181
- package/dist/testing.js +3 -36
- package/dist/testing.js.map +1 -1
- package/package.json +37 -5
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/share.cjs.map +0 -1
- package/dist/share.js.map +0 -1
package/dist/code.cjs
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
|
+
|
|
1
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type,
|
|
6
|
-
message
|
|
7
|
-
} : {
|
|
8
|
-
type,
|
|
9
|
-
message,
|
|
10
|
-
cause
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Branded (not `instanceof`) so failures stay recognisable even when the core
|
|
15
|
-
* is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
|
|
16
|
-
*/
|
|
17
|
-
const COPY_FAILURE_BRAND = Symbol.for("react-smart-copy.CopyFailure");
|
|
18
|
-
/** Error thrown by adapters to carry a fully classified {@link CopyError}. */
|
|
19
|
-
var CopyFailure = class extends Error {
|
|
20
|
-
constructor(copyError) {
|
|
21
|
-
super(copyError.message);
|
|
22
|
-
this[COPY_FAILURE_BRAND] = true;
|
|
23
|
-
this.name = "CopyFailure";
|
|
24
|
-
this.copyError = copyError;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
function isCopyFailure(value) {
|
|
28
|
-
return typeof value === "object" && value !== null && value[COPY_FAILURE_BRAND] === true;
|
|
29
|
-
}
|
|
30
|
-
/** Shorthand for throwing a classified failure. */
|
|
31
|
-
function copyFailure(type, message, cause) {
|
|
32
|
-
return new CopyFailure(createCopyError(type, message, cause));
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
3
|
+
const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
|
|
4
|
+
const require_inert_html = require("./chunks/inert-html-DyxjWDok.cjs");
|
|
5
|
+
const require_text_field = require("./chunks/text-field-Ba8W3v4R.cjs");
|
|
35
6
|
//#region src/code/inspect.ts
|
|
36
7
|
/** Every finding kind, in a stable order. */
|
|
37
8
|
const CODE_FINDING_KINDS = Object.freeze([
|
|
@@ -212,7 +183,7 @@ function classify(codePoint, before, after) {
|
|
|
212
183
|
const ALL = /* @__PURE__ */ new Set(CODE_FINDING_KINDS);
|
|
213
184
|
function kindSet(kinds, name) {
|
|
214
185
|
if (kinds === void 0) return ALL;
|
|
215
|
-
if (!Array.isArray(kinds) || !kinds.every((kind) => ALL.has(kind))) throw copyFailure("invalid-payload", `\`${name}\` must be a list of: ${CODE_FINDING_KINDS.join(", ")}.`);
|
|
186
|
+
if (!Array.isArray(kinds) || !kinds.every((kind) => ALL.has(kind))) throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a list of: ${CODE_FINDING_KINDS.join(", ")}.`);
|
|
216
187
|
return new Set(kinds);
|
|
217
188
|
}
|
|
218
189
|
/** Every suspicious character in `text`, in order of position. Stops once `limit` are found. */
|
|
@@ -305,7 +276,7 @@ function toFindings(text, raw) {
|
|
|
305
276
|
function positiveLimit(value, fallback, name) {
|
|
306
277
|
if (value === void 0) return fallback;
|
|
307
278
|
if (value === Infinity || Number.isInteger(value) && value > 0) return value;
|
|
308
|
-
throw copyFailure("invalid-payload", `\`${name}\` must be a positive integer or Infinity (received ${String(value)}).`);
|
|
279
|
+
throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a positive integer or Infinity (received ${String(value)}).`);
|
|
309
280
|
}
|
|
310
281
|
/**
|
|
311
282
|
* Finds characters that make code read differently from how it runs, or that a
|
|
@@ -502,7 +473,7 @@ const AUTO = [
|
|
|
502
473
|
];
|
|
503
474
|
/** A user pattern without `g` / `y`, so `exec` is stateless. */
|
|
504
475
|
function stateless(pattern, name) {
|
|
505
|
-
if (!(pattern instanceof RegExp)) throw copyFailure("invalid-payload", `\`prompt.${name}\` must be a RegExp.`);
|
|
476
|
+
if (!(pattern instanceof RegExp)) throw require_errors.copyFailure("invalid-payload", `\`prompt.${name}\` must be a RegExp.`);
|
|
506
477
|
return new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
507
478
|
}
|
|
508
479
|
function resolvePrompt(prompt, fallback) {
|
|
@@ -510,10 +481,10 @@ function resolvePrompt(prompt, fallback) {
|
|
|
510
481
|
if (value === false) return null;
|
|
511
482
|
if (value === "auto") return "auto";
|
|
512
483
|
if (typeof value === "string") {
|
|
513
|
-
if (!Object.prototype.hasOwnProperty.call(PROMPTS, value)) throw copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
|
|
484
|
+
if (!Object.prototype.hasOwnProperty.call(PROMPTS, value)) throw require_errors.copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
|
|
514
485
|
return PROMPTS[value];
|
|
515
486
|
}
|
|
516
|
-
if (typeof value !== "object" || value === null) throw copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
|
|
487
|
+
if (typeof value !== "object" || value === null) throw require_errors.copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
|
|
517
488
|
return {
|
|
518
489
|
command: stateless(value.command, "command"),
|
|
519
490
|
continuation: value.continuation === void 0 ? null : stateless(value.continuation, "continuation"),
|
|
@@ -664,7 +635,7 @@ function dedentLines(lines) {
|
|
|
664
635
|
const oneOf = (value, allowed, fallback, name) => {
|
|
665
636
|
if (value === void 0) return fallback;
|
|
666
637
|
if (allowed.includes(value)) return value;
|
|
667
|
-
throw copyFailure("invalid-payload", `\`${name}\` must be one of: ${allowed.map((option) => JSON.stringify(option)).join(", ")}.`);
|
|
638
|
+
throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be one of: ${allowed.map((option) => JSON.stringify(option)).join(", ")}.`);
|
|
668
639
|
};
|
|
669
640
|
const flag = (value, fallback, name) => oneOf(value, [true, false], fallback, name);
|
|
670
641
|
function resolveText(options, defaults) {
|
|
@@ -825,7 +796,7 @@ const NO_SELECT = /(?:^|;)\s*(?:-webkit-)?user-select\s*:\s*none/i;
|
|
|
825
796
|
const SAFE_COLOR = /^(?:#[\da-f]{3,8}|[a-z]{3,20}|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([\d\s.,%/+-]{1,80}\)|color\([a-z\d-]{1,24}[\d\s.,%/+-]{1,80}\))$/i;
|
|
826
797
|
const TRANSPARENT = /^(?:transparent|rgba\(\s*0,\s*0,\s*0,\s*0\s*\))$/i;
|
|
827
798
|
function assertElement(value, name) {
|
|
828
|
-
if (typeof value !== "object" || value === null || value.nodeType !== 1) throw copyFailure("invalid-payload", `\`${name}\` must be a string or an Element.`);
|
|
799
|
+
if (typeof value !== "object" || value === null || value.nodeType !== 1) throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a string or an Element.`);
|
|
829
800
|
}
|
|
830
801
|
function lookOf(style) {
|
|
831
802
|
const weight = style.fontWeight;
|
|
@@ -847,7 +818,7 @@ function extract(root, options) {
|
|
|
847
818
|
if (ignore !== void 0) try {
|
|
848
819
|
root.matches(ignore);
|
|
849
820
|
} catch (cause) {
|
|
850
|
-
throw copyFailure("invalid-payload", `\`ignore\` is not a valid CSS selector: ${ignore}`, cause);
|
|
821
|
+
throw require_errors.copyFailure("invalid-payload", `\`ignore\` is not a valid CSS selector: ${ignore}`, cause);
|
|
851
822
|
}
|
|
852
823
|
const view = root.ownerDocument.defaultView;
|
|
853
824
|
const computed = (element) => view === null ? null : view.getComputedStyle(element);
|
|
@@ -976,9 +947,9 @@ function codePayload(source, options = {}) {
|
|
|
976
947
|
clean: false
|
|
977
948
|
});
|
|
978
949
|
const withHtml = options.html ?? true;
|
|
979
|
-
if (typeof withHtml !== "boolean") throw copyFailure("invalid-payload", "`html` must be a boolean.");
|
|
950
|
+
if (typeof withHtml !== "boolean") throw require_errors.copyFailure("invalid-payload", "`html` must be a boolean.");
|
|
980
951
|
const { language } = options;
|
|
981
|
-
if (language !== void 0 && (typeof language !== "string" || !LANGUAGE.test(language))) throw copyFailure("invalid-payload", "`language` may only hold letters, digits and _ + # . - (at most 64).");
|
|
952
|
+
if (language !== void 0 && (typeof language !== "string" || !LANGUAGE.test(language))) throw require_errors.copyFailure("invalid-payload", "`language` may only hold letters, digits and _ + # . - (at most 64).");
|
|
982
953
|
let lines;
|
|
983
954
|
let blockStyle = "";
|
|
984
955
|
if (typeof source === "string") lines = toLines([{
|
|
@@ -1007,68 +978,6 @@ function codePayload(source, options = {}) {
|
|
|
1007
978
|
};
|
|
1008
979
|
}
|
|
1009
980
|
//#endregion
|
|
1010
|
-
//#region src/core/text-field.ts
|
|
1011
|
-
const TEXT_INPUTS = /* @__PURE__ */ new Set([
|
|
1012
|
-
"text",
|
|
1013
|
-
"search",
|
|
1014
|
-
"url",
|
|
1015
|
-
"tel",
|
|
1016
|
-
"password"
|
|
1017
|
-
]);
|
|
1018
|
-
function asTextField(target) {
|
|
1019
|
-
if (typeof target !== "object" || target === null) return null;
|
|
1020
|
-
const element = target;
|
|
1021
|
-
if (element.nodeName === "TEXTAREA") return target;
|
|
1022
|
-
if (element.nodeName === "INPUT" && typeof element.type === "string" && TEXT_INPUTS.has(element.type)) return target;
|
|
1023
|
-
return null;
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
|
|
1027
|
-
* selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
|
|
1028
|
-
* works, `input` events fire (so React and other frameworks see the change),
|
|
1029
|
-
* and `maxlength` is respected. Returns `false` for disabled or read-only fields.
|
|
1030
|
-
*/
|
|
1031
|
-
function insertText(field, text) {
|
|
1032
|
-
if (field.disabled || field.readOnly) return false;
|
|
1033
|
-
const value = field.nodeName === "INPUT" ? text.replace(/[ \t]*(?:\r\n|\r|\n)+[ \t]*/g, " ") : text;
|
|
1034
|
-
const doc = field.ownerDocument;
|
|
1035
|
-
field.focus();
|
|
1036
|
-
const start = field.selectionStart;
|
|
1037
|
-
const end = field.selectionEnd;
|
|
1038
|
-
try {
|
|
1039
|
-
if (start !== null && end !== null) field.setSelectionRange(start, end);
|
|
1040
|
-
if (doc.activeElement === field && doc.execCommand("insertText", false, value)) return true;
|
|
1041
|
-
} catch {}
|
|
1042
|
-
const from = start ?? field.value.length;
|
|
1043
|
-
const to = end ?? from;
|
|
1044
|
-
let insert = value;
|
|
1045
|
-
if (field.maxLength >= 0) {
|
|
1046
|
-
const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));
|
|
1047
|
-
insert = insert.slice(0, room);
|
|
1048
|
-
if (/[\ud800-\udbff]$/.test(insert)) insert = insert.slice(0, -1);
|
|
1049
|
-
}
|
|
1050
|
-
if (start === null) setNativeValue(field, field.value + insert);
|
|
1051
|
-
else field.setRangeText(insert, from, to, "end");
|
|
1052
|
-
const view = doc.defaultView;
|
|
1053
|
-
const event = view !== null && typeof view.InputEvent === "function" ? new view.InputEvent("input", {
|
|
1054
|
-
bubbles: true,
|
|
1055
|
-
inputType: "insertFromPaste",
|
|
1056
|
-
data: insert
|
|
1057
|
-
}) : new Event("input", { bubbles: true });
|
|
1058
|
-
field.dispatchEvent(event);
|
|
1059
|
-
return true;
|
|
1060
|
-
}
|
|
1061
|
-
/**
|
|
1062
|
-
* Sets a field's value through the prototype's setter. React tracks the value
|
|
1063
|
-
* set on the element itself; going around it lets React see the change and
|
|
1064
|
-
* call `onChange` for the `input` event that follows.
|
|
1065
|
-
*/
|
|
1066
|
-
function setNativeValue(field, next) {
|
|
1067
|
-
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field), "value")?.set;
|
|
1068
|
-
if (setter) setter.call(field, next);
|
|
1069
|
-
else field.value = next;
|
|
1070
|
-
}
|
|
1071
|
-
//#endregion
|
|
1072
981
|
//#region src/code/paste.ts
|
|
1073
982
|
const DEFAULT_CODE_MAX_LENGTH = 2e6;
|
|
1074
983
|
const INDENT = /^[ \t]*$/;
|
|
@@ -1098,16 +1007,16 @@ function pasteToCode(source, options = {}) {
|
|
|
1098
1007
|
});
|
|
1099
1008
|
const maxLength = positiveLimit(options.maxLength, DEFAULT_CODE_MAX_LENGTH, "maxLength");
|
|
1100
1009
|
const indent = options.indent ?? "";
|
|
1101
|
-
if (typeof indent !== "string" || !INDENT.test(indent)) throw copyFailure("invalid-payload", "`indent` may only hold spaces and tabs.");
|
|
1010
|
+
if (typeof indent !== "string" || !INDENT.test(indent)) throw require_errors.copyFailure("invalid-payload", "`indent` may only hold spaces and tabs.");
|
|
1102
1011
|
let text = source.text ?? "";
|
|
1103
1012
|
let from = "text";
|
|
1104
1013
|
if (text === "" && typeof source.html === "string" && source.html.trim() !== "" && typeof DOMParser !== "undefined") {
|
|
1105
|
-
if (source.html.length > maxLength) throw copyFailure("too-large", `The pasted HTML is longer than maxLength (${String(maxLength)}).`);
|
|
1106
|
-
const body =
|
|
1014
|
+
if (source.html.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted HTML is longer than maxLength (${String(maxLength)}).`);
|
|
1015
|
+
const body = require_inert_html.parseInertHtml(source.html).body;
|
|
1107
1016
|
text = extract(body, { styles: false }).runs.map((run) => run.text).join("");
|
|
1108
1017
|
from = "html";
|
|
1109
1018
|
}
|
|
1110
|
-
if (text.length > maxLength) throw copyFailure("too-large", `The pasted text is longer than maxLength (${String(maxLength)}).`);
|
|
1019
|
+
if (text.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted text is longer than maxLength (${String(maxLength)}).`);
|
|
1111
1020
|
if (text.trim() === "") return null;
|
|
1112
1021
|
const { lines, fixed } = transform(toLines([{
|
|
1113
1022
|
text,
|
|
@@ -1140,7 +1049,7 @@ function pasteToCode(source, options = {}) {
|
|
|
1140
1049
|
*/
|
|
1141
1050
|
function pasteAsCode(event, options = {}) {
|
|
1142
1051
|
if (event.defaultPrevented || event.clipboardData === null) return false;
|
|
1143
|
-
const field = asTextField(event.currentTarget) ?? asTextField(event.target);
|
|
1052
|
+
const field = require_text_field.asTextField(event.currentTarget) ?? require_text_field.asTextField(event.target);
|
|
1144
1053
|
if (field === null || field.disabled || field.readOnly) return false;
|
|
1145
1054
|
const { indentToCursor, onPaste, ...rest } = options;
|
|
1146
1055
|
let indent = "";
|
|
@@ -1158,13 +1067,13 @@ function pasteAsCode(event, options = {}) {
|
|
|
1158
1067
|
indent
|
|
1159
1068
|
});
|
|
1160
1069
|
} catch (error) {
|
|
1161
|
-
if (isCopyFailure(error)) return false;
|
|
1070
|
+
if (require_errors.isCopyFailure(error)) return false;
|
|
1162
1071
|
throw error;
|
|
1163
1072
|
}
|
|
1164
1073
|
if (result === null) return false;
|
|
1165
1074
|
event.preventDefault();
|
|
1166
1075
|
if (onPaste?.(result) === false) return true;
|
|
1167
|
-
insertText(field, result.code);
|
|
1076
|
+
require_text_field.insertText(field, result.code);
|
|
1168
1077
|
return true;
|
|
1169
1078
|
}
|
|
1170
1079
|
//#endregion
|
|
@@ -1175,7 +1084,7 @@ exports.PROMPT_STYLES = PROMPT_STYLES;
|
|
|
1175
1084
|
exports.cleanCode = cleanCode;
|
|
1176
1085
|
exports.codeFromElement = codeFromElement;
|
|
1177
1086
|
exports.codePayload = codePayload;
|
|
1178
|
-
exports.insertText = insertText;
|
|
1087
|
+
exports.insertText = require_text_field.insertText;
|
|
1179
1088
|
exports.inspectCode = inspectCode;
|
|
1180
1089
|
exports.normalizeCode = normalizeCode;
|
|
1181
1090
|
exports.pasteAsCode = pasteAsCode;
|