react-smart-copy 1.11.0 → 1.12.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/dist/markdown.js CHANGED
@@ -1243,63 +1243,7 @@ function convert(root, resolved, truncated) {
1243
1243
  };
1244
1244
  }
1245
1245
  //#endregion
1246
- //#region src/markdown/paste.ts
1247
- const MONOSPACE_PRE = /white-space\s*:\s*pre/i;
1248
- const MONOSPACE_FONT = /font-family\s*:[^;]*\b(monospace|courier|consolas|menlo|monaco|mono)\b/i;
1249
- /** Every visible character sits inside a `<pre>` or a monospace `white-space: pre` box. */
1250
- function isCodeOnly(body) {
1251
- const walker = body.ownerDocument.createTreeWalker(body, 4);
1252
- let seen = false;
1253
- for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
1254
- if (node.data.trim() === "") continue;
1255
- seen = true;
1256
- let code = false;
1257
- for (let element = node.parentElement; element !== null && element !== body; element = element.parentElement) {
1258
- const style = element.getAttribute("style") ?? "";
1259
- if (element.localName === "pre" || MONOSPACE_PRE.test(style) && MONOSPACE_FONT.test(style)) {
1260
- code = true;
1261
- break;
1262
- }
1263
- }
1264
- if (!code) return false;
1265
- }
1266
- return seen;
1267
- }
1268
- /**
1269
- * Markdown for what was pasted. Rich content (the HTML flavour) is converted;
1270
- * plain text is returned as it is, because plain text pasted into a Markdown
1271
- * editor is usually Markdown already (copied from another `.md` file or editor),
1272
- * and escaping it would break it. Returns `null` when there is nothing to paste.
1273
- *
1274
- * Never throws for clipboard content: on a server without `DOMParser`, or when
1275
- * the HTML holds nothing to convert, it falls back to the text.
1276
- *
1277
- * @example
1278
- * usePaste({ accept: ['html', 'text'], onPaste: (result) => {
1279
- * const pasted = pasteToMarkdown(result);
1280
- * if (pasted) insertText(textarea, pasted.markdown);
1281
- * } });
1282
- */
1283
- function pasteToMarkdown(source, options = {}) {
1284
- const resolved = resolveOptions(options);
1285
- const text = source.text ?? null;
1286
- const html = source.html ?? null;
1287
- if (html !== null && html.trim() !== "" && typeof DOMParser !== "undefined") {
1288
- const { body, truncated } = parseHtml(html, resolved);
1289
- if (!(options.codeAsText !== false && text !== null && text !== "" && isCodeOnly(body))) {
1290
- const converted = convert(body, resolved, truncated);
1291
- if (converted.markdown !== "") return {
1292
- ...converted,
1293
- source: "html"
1294
- };
1295
- }
1296
- }
1297
- return text === null || text === "" ? null : {
1298
- markdown: text.replace(/\r\n?/g, "\n"),
1299
- source: "text",
1300
- truncated: false
1301
- };
1302
- }
1246
+ //#region src/core/text-field.ts
1303
1247
  const TEXT_INPUTS = /* @__PURE__ */ new Set([
1304
1248
  "text",
1305
1249
  "search",
@@ -1360,6 +1304,64 @@ function setNativeValue(field, next) {
1360
1304
  if (setter) setter.call(field, next);
1361
1305
  else field.value = next;
1362
1306
  }
1307
+ //#endregion
1308
+ //#region src/markdown/paste.ts
1309
+ const MONOSPACE_PRE = /white-space\s*:\s*pre/i;
1310
+ const MONOSPACE_FONT = /font-family\s*:[^;]*\b(monospace|courier|consolas|menlo|monaco|mono)\b/i;
1311
+ /** Every visible character sits inside a `<pre>` or a monospace `white-space: pre` box. */
1312
+ function isCodeOnly(body) {
1313
+ const walker = body.ownerDocument.createTreeWalker(body, 4);
1314
+ let seen = false;
1315
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
1316
+ if (node.data.trim() === "") continue;
1317
+ seen = true;
1318
+ let code = false;
1319
+ for (let element = node.parentElement; element !== null && element !== body; element = element.parentElement) {
1320
+ const style = element.getAttribute("style") ?? "";
1321
+ if (element.localName === "pre" || MONOSPACE_PRE.test(style) && MONOSPACE_FONT.test(style)) {
1322
+ code = true;
1323
+ break;
1324
+ }
1325
+ }
1326
+ if (!code) return false;
1327
+ }
1328
+ return seen;
1329
+ }
1330
+ /**
1331
+ * Markdown for what was pasted. Rich content (the HTML flavour) is converted;
1332
+ * plain text is returned as it is, because plain text pasted into a Markdown
1333
+ * editor is usually Markdown already (copied from another `.md` file or editor),
1334
+ * and escaping it would break it. Returns `null` when there is nothing to paste.
1335
+ *
1336
+ * Never throws for clipboard content: on a server without `DOMParser`, or when
1337
+ * the HTML holds nothing to convert, it falls back to the text.
1338
+ *
1339
+ * @example
1340
+ * usePaste({ accept: ['html', 'text'], onPaste: (result) => {
1341
+ * const pasted = pasteToMarkdown(result);
1342
+ * if (pasted) insertText(textarea, pasted.markdown);
1343
+ * } });
1344
+ */
1345
+ function pasteToMarkdown(source, options = {}) {
1346
+ const resolved = resolveOptions(options);
1347
+ const text = source.text ?? null;
1348
+ const html = source.html ?? null;
1349
+ if (html !== null && html.trim() !== "" && typeof DOMParser !== "undefined") {
1350
+ const { body, truncated } = parseHtml(html, resolved);
1351
+ if (!(options.codeAsText !== false && text !== null && text !== "" && isCodeOnly(body))) {
1352
+ const converted = convert(body, resolved, truncated);
1353
+ if (converted.markdown !== "") return {
1354
+ ...converted,
1355
+ source: "html"
1356
+ };
1357
+ }
1358
+ }
1359
+ return text === null || text === "" ? null : {
1360
+ markdown: text.replace(/\r\n?/g, "\n"),
1361
+ source: "text",
1362
+ truncated: false
1363
+ };
1364
+ }
1363
1365
  /**
1364
1366
  * A paste handler for Markdown text fields: when the clipboard holds rich
1365
1367
  * content (Google Docs, Word, a web page), it is inserted as Markdown; plain