react-smart-copy 1.17.2 → 1.18.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 +9 -3
- 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/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-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/code.cjs +20 -112
- 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 +3 -95
- 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 +24 -338
- 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 +5 -319
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +8 -97
- 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 +3 -92
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +26 -934
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +4 -90
- package/dist/rich.d.ts +4 -90
- package/dist/rich.js +4 -912
- 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 +11 -39
- 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 +2 -30
- 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 +20 -2
- 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,7 @@
|
|
|
1
|
+
|
|
1
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return cause === void 0 ? {
|
|
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_text_field = require("./chunks/text-field-Ba8W3v4R.cjs");
|
|
35
5
|
//#region src/code/inspect.ts
|
|
36
6
|
/** Every finding kind, in a stable order. */
|
|
37
7
|
const CODE_FINDING_KINDS = Object.freeze([
|
|
@@ -212,7 +182,7 @@ function classify(codePoint, before, after) {
|
|
|
212
182
|
const ALL = /* @__PURE__ */ new Set(CODE_FINDING_KINDS);
|
|
213
183
|
function kindSet(kinds, name) {
|
|
214
184
|
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(", ")}.`);
|
|
185
|
+
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
186
|
return new Set(kinds);
|
|
217
187
|
}
|
|
218
188
|
/** Every suspicious character in `text`, in order of position. Stops once `limit` are found. */
|
|
@@ -305,7 +275,7 @@ function toFindings(text, raw) {
|
|
|
305
275
|
function positiveLimit(value, fallback, name) {
|
|
306
276
|
if (value === void 0) return fallback;
|
|
307
277
|
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)}).`);
|
|
278
|
+
throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a positive integer or Infinity (received ${String(value)}).`);
|
|
309
279
|
}
|
|
310
280
|
/**
|
|
311
281
|
* Finds characters that make code read differently from how it runs, or that a
|
|
@@ -502,7 +472,7 @@ const AUTO = [
|
|
|
502
472
|
];
|
|
503
473
|
/** A user pattern without `g` / `y`, so `exec` is stateless. */
|
|
504
474
|
function stateless(pattern, name) {
|
|
505
|
-
if (!(pattern instanceof RegExp)) throw copyFailure("invalid-payload", `\`prompt.${name}\` must be a RegExp.`);
|
|
475
|
+
if (!(pattern instanceof RegExp)) throw require_errors.copyFailure("invalid-payload", `\`prompt.${name}\` must be a RegExp.`);
|
|
506
476
|
return new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
507
477
|
}
|
|
508
478
|
function resolvePrompt(prompt, fallback) {
|
|
@@ -510,10 +480,10 @@ function resolvePrompt(prompt, fallback) {
|
|
|
510
480
|
if (value === false) return null;
|
|
511
481
|
if (value === "auto") return "auto";
|
|
512
482
|
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(", ")}.`);
|
|
483
|
+
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
484
|
return PROMPTS[value];
|
|
515
485
|
}
|
|
516
|
-
if (typeof value !== "object" || value === null) throw copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
|
|
486
|
+
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
487
|
return {
|
|
518
488
|
command: stateless(value.command, "command"),
|
|
519
489
|
continuation: value.continuation === void 0 ? null : stateless(value.continuation, "continuation"),
|
|
@@ -664,7 +634,7 @@ function dedentLines(lines) {
|
|
|
664
634
|
const oneOf = (value, allowed, fallback, name) => {
|
|
665
635
|
if (value === void 0) return fallback;
|
|
666
636
|
if (allowed.includes(value)) return value;
|
|
667
|
-
throw copyFailure("invalid-payload", `\`${name}\` must be one of: ${allowed.map((option) => JSON.stringify(option)).join(", ")}.`);
|
|
637
|
+
throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be one of: ${allowed.map((option) => JSON.stringify(option)).join(", ")}.`);
|
|
668
638
|
};
|
|
669
639
|
const flag = (value, fallback, name) => oneOf(value, [true, false], fallback, name);
|
|
670
640
|
function resolveText(options, defaults) {
|
|
@@ -825,7 +795,7 @@ const NO_SELECT = /(?:^|;)\s*(?:-webkit-)?user-select\s*:\s*none/i;
|
|
|
825
795
|
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
796
|
const TRANSPARENT = /^(?:transparent|rgba\(\s*0,\s*0,\s*0,\s*0\s*\))$/i;
|
|
827
797
|
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.`);
|
|
798
|
+
if (typeof value !== "object" || value === null || value.nodeType !== 1) throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a string or an Element.`);
|
|
829
799
|
}
|
|
830
800
|
function lookOf(style) {
|
|
831
801
|
const weight = style.fontWeight;
|
|
@@ -847,7 +817,7 @@ function extract(root, options) {
|
|
|
847
817
|
if (ignore !== void 0) try {
|
|
848
818
|
root.matches(ignore);
|
|
849
819
|
} catch (cause) {
|
|
850
|
-
throw copyFailure("invalid-payload", `\`ignore\` is not a valid CSS selector: ${ignore}`, cause);
|
|
820
|
+
throw require_errors.copyFailure("invalid-payload", `\`ignore\` is not a valid CSS selector: ${ignore}`, cause);
|
|
851
821
|
}
|
|
852
822
|
const view = root.ownerDocument.defaultView;
|
|
853
823
|
const computed = (element) => view === null ? null : view.getComputedStyle(element);
|
|
@@ -976,9 +946,9 @@ function codePayload(source, options = {}) {
|
|
|
976
946
|
clean: false
|
|
977
947
|
});
|
|
978
948
|
const withHtml = options.html ?? true;
|
|
979
|
-
if (typeof withHtml !== "boolean") throw copyFailure("invalid-payload", "`html` must be a boolean.");
|
|
949
|
+
if (typeof withHtml !== "boolean") throw require_errors.copyFailure("invalid-payload", "`html` must be a boolean.");
|
|
980
950
|
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).");
|
|
951
|
+
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
952
|
let lines;
|
|
983
953
|
let blockStyle = "";
|
|
984
954
|
if (typeof source === "string") lines = toLines([{
|
|
@@ -1007,68 +977,6 @@ function codePayload(source, options = {}) {
|
|
|
1007
977
|
};
|
|
1008
978
|
}
|
|
1009
979
|
//#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
980
|
//#region src/code/paste.ts
|
|
1073
981
|
const DEFAULT_CODE_MAX_LENGTH = 2e6;
|
|
1074
982
|
const INDENT = /^[ \t]*$/;
|
|
@@ -1098,16 +1006,16 @@ function pasteToCode(source, options = {}) {
|
|
|
1098
1006
|
});
|
|
1099
1007
|
const maxLength = positiveLimit(options.maxLength, DEFAULT_CODE_MAX_LENGTH, "maxLength");
|
|
1100
1008
|
const indent = options.indent ?? "";
|
|
1101
|
-
if (typeof indent !== "string" || !INDENT.test(indent)) throw copyFailure("invalid-payload", "`indent` may only hold spaces and tabs.");
|
|
1009
|
+
if (typeof indent !== "string" || !INDENT.test(indent)) throw require_errors.copyFailure("invalid-payload", "`indent` may only hold spaces and tabs.");
|
|
1102
1010
|
let text = source.text ?? "";
|
|
1103
1011
|
let from = "text";
|
|
1104
1012
|
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)}).`);
|
|
1013
|
+
if (source.html.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted HTML is longer than maxLength (${String(maxLength)}).`);
|
|
1106
1014
|
const body = new DOMParser().parseFromString(source.html, "text/html").body;
|
|
1107
1015
|
text = extract(body, { styles: false }).runs.map((run) => run.text).join("");
|
|
1108
1016
|
from = "html";
|
|
1109
1017
|
}
|
|
1110
|
-
if (text.length > maxLength) throw copyFailure("too-large", `The pasted text is longer than maxLength (${String(maxLength)}).`);
|
|
1018
|
+
if (text.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted text is longer than maxLength (${String(maxLength)}).`);
|
|
1111
1019
|
if (text.trim() === "") return null;
|
|
1112
1020
|
const { lines, fixed } = transform(toLines([{
|
|
1113
1021
|
text,
|
|
@@ -1140,7 +1048,7 @@ function pasteToCode(source, options = {}) {
|
|
|
1140
1048
|
*/
|
|
1141
1049
|
function pasteAsCode(event, options = {}) {
|
|
1142
1050
|
if (event.defaultPrevented || event.clipboardData === null) return false;
|
|
1143
|
-
const field = asTextField(event.currentTarget) ?? asTextField(event.target);
|
|
1051
|
+
const field = require_text_field.asTextField(event.currentTarget) ?? require_text_field.asTextField(event.target);
|
|
1144
1052
|
if (field === null || field.disabled || field.readOnly) return false;
|
|
1145
1053
|
const { indentToCursor, onPaste, ...rest } = options;
|
|
1146
1054
|
let indent = "";
|
|
@@ -1158,13 +1066,13 @@ function pasteAsCode(event, options = {}) {
|
|
|
1158
1066
|
indent
|
|
1159
1067
|
});
|
|
1160
1068
|
} catch (error) {
|
|
1161
|
-
if (isCopyFailure(error)) return false;
|
|
1069
|
+
if (require_errors.isCopyFailure(error)) return false;
|
|
1162
1070
|
throw error;
|
|
1163
1071
|
}
|
|
1164
1072
|
if (result === null) return false;
|
|
1165
1073
|
event.preventDefault();
|
|
1166
1074
|
if (onPaste?.(result) === false) return true;
|
|
1167
|
-
insertText(field, result.code);
|
|
1075
|
+
require_text_field.insertText(field, result.code);
|
|
1168
1076
|
return true;
|
|
1169
1077
|
}
|
|
1170
1078
|
//#endregion
|
|
@@ -1175,7 +1083,7 @@ exports.PROMPT_STYLES = PROMPT_STYLES;
|
|
|
1175
1083
|
exports.cleanCode = cleanCode;
|
|
1176
1084
|
exports.codeFromElement = codeFromElement;
|
|
1177
1085
|
exports.codePayload = codePayload;
|
|
1178
|
-
exports.insertText = insertText;
|
|
1086
|
+
exports.insertText = require_text_field.insertText;
|
|
1179
1087
|
exports.inspectCode = inspectCode;
|
|
1180
1088
|
exports.normalizeCode = normalizeCode;
|
|
1181
1089
|
exports.pasteAsCode = pasteAsCode;
|