@riebeckite/plugin-text-fragment 0.0.35 → 0.0.37
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/client.js +4 -41
- package/dist/index.js +4 -41
- package/package.json +3 -2
package/dist/client.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/text-fragment.client.ts
|
|
2
|
+
import { copyText } from "@riebeckite/ui/copy";
|
|
3
|
+
|
|
1
4
|
// src/text-fragment.ts
|
|
2
5
|
var TEXT_FRAGMENT_PREFIX = "#:~:text=";
|
|
3
6
|
var MAX_TEXT_FRAGMENT_LENGTH = 200;
|
|
@@ -113,7 +116,7 @@ function initTextFragmentShare(labels = {}) {
|
|
|
113
116
|
if (!selection) return;
|
|
114
117
|
isCopying = true;
|
|
115
118
|
try {
|
|
116
|
-
const copied = await
|
|
119
|
+
const copied = await copyText(buildValue(selection.text));
|
|
117
120
|
status.textContent = copied ? successMessage : resolved.copyFailedLabel;
|
|
118
121
|
active = selection;
|
|
119
122
|
popover.hidden = false;
|
|
@@ -223,46 +226,6 @@ function positionPopover(popover, rect) {
|
|
|
223
226
|
function resolvePageUrl() {
|
|
224
227
|
return window.location.href.split("#")[0] ?? window.location.href;
|
|
225
228
|
}
|
|
226
|
-
async function copyToClipboard(value) {
|
|
227
|
-
try {
|
|
228
|
-
if (window.isSecureContext && navigator.clipboard) {
|
|
229
|
-
await navigator.clipboard.writeText(value);
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
} catch {
|
|
233
|
-
}
|
|
234
|
-
return copyWithExecCommand(value);
|
|
235
|
-
}
|
|
236
|
-
function copyWithExecCommand(value) {
|
|
237
|
-
const selection = window.getSelection();
|
|
238
|
-
const savedRanges = [];
|
|
239
|
-
if (selection) {
|
|
240
|
-
for (let index = 0; index < selection.rangeCount; index += 1) {
|
|
241
|
-
savedRanges.push(selection.getRangeAt(index).cloneRange());
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const textarea = document.createElement("textarea");
|
|
245
|
-
textarea.value = value;
|
|
246
|
-
textarea.setAttribute("readonly", "");
|
|
247
|
-
textarea.style.position = "fixed";
|
|
248
|
-
textarea.style.top = "-1000px";
|
|
249
|
-
textarea.style.opacity = "0";
|
|
250
|
-
document.body.appendChild(textarea);
|
|
251
|
-
textarea.select();
|
|
252
|
-
let copied = false;
|
|
253
|
-
try {
|
|
254
|
-
copied = document.execCommand("copy");
|
|
255
|
-
} catch {
|
|
256
|
-
copied = false;
|
|
257
|
-
} finally {
|
|
258
|
-
textarea.remove();
|
|
259
|
-
if (selection && savedRanges.length > 0) {
|
|
260
|
-
selection.removeAllRanges();
|
|
261
|
-
for (const range of savedRanges) selection.addRange(range);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return copied;
|
|
265
|
-
}
|
|
266
229
|
export {
|
|
267
230
|
DEFAULT_TEXT_FRAGMENT_LABELS,
|
|
268
231
|
initTextFragmentShare
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
definePlugin
|
|
6
6
|
} from "@riebeckite/core";
|
|
7
7
|
|
|
8
|
+
// src/text-fragment.client.ts
|
|
9
|
+
import { copyText } from "@riebeckite/ui/copy";
|
|
10
|
+
|
|
8
11
|
// src/text-fragment.ts
|
|
9
12
|
var TEXT_FRAGMENT_PREFIX = "#:~:text=";
|
|
10
13
|
var MAX_TEXT_FRAGMENT_LENGTH = 200;
|
|
@@ -120,7 +123,7 @@ function initTextFragmentShare(labels = {}) {
|
|
|
120
123
|
if (!selection) return;
|
|
121
124
|
isCopying = true;
|
|
122
125
|
try {
|
|
123
|
-
const copied = await
|
|
126
|
+
const copied = await copyText(buildValue(selection.text));
|
|
124
127
|
status.textContent = copied ? successMessage : resolved.copyFailedLabel;
|
|
125
128
|
active = selection;
|
|
126
129
|
popover.hidden = false;
|
|
@@ -230,46 +233,6 @@ function positionPopover(popover, rect) {
|
|
|
230
233
|
function resolvePageUrl() {
|
|
231
234
|
return window.location.href.split("#")[0] ?? window.location.href;
|
|
232
235
|
}
|
|
233
|
-
async function copyToClipboard(value) {
|
|
234
|
-
try {
|
|
235
|
-
if (window.isSecureContext && navigator.clipboard) {
|
|
236
|
-
await navigator.clipboard.writeText(value);
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
} catch {
|
|
240
|
-
}
|
|
241
|
-
return copyWithExecCommand(value);
|
|
242
|
-
}
|
|
243
|
-
function copyWithExecCommand(value) {
|
|
244
|
-
const selection = window.getSelection();
|
|
245
|
-
const savedRanges = [];
|
|
246
|
-
if (selection) {
|
|
247
|
-
for (let index = 0; index < selection.rangeCount; index += 1) {
|
|
248
|
-
savedRanges.push(selection.getRangeAt(index).cloneRange());
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const textarea = document.createElement("textarea");
|
|
252
|
-
textarea.value = value;
|
|
253
|
-
textarea.setAttribute("readonly", "");
|
|
254
|
-
textarea.style.position = "fixed";
|
|
255
|
-
textarea.style.top = "-1000px";
|
|
256
|
-
textarea.style.opacity = "0";
|
|
257
|
-
document.body.appendChild(textarea);
|
|
258
|
-
textarea.select();
|
|
259
|
-
let copied = false;
|
|
260
|
-
try {
|
|
261
|
-
copied = document.execCommand("copy");
|
|
262
|
-
} catch {
|
|
263
|
-
copied = false;
|
|
264
|
-
} finally {
|
|
265
|
-
textarea.remove();
|
|
266
|
-
if (selection && savedRanges.length > 0) {
|
|
267
|
-
selection.removeAllRanges();
|
|
268
|
-
for (const range of savedRanges) selection.addRange(range);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return copied;
|
|
272
|
-
}
|
|
273
236
|
|
|
274
237
|
// index.ts
|
|
275
238
|
function textFragment(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-text-fragment",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@riebeckite/core": "0.0.
|
|
24
|
+
"@riebeckite/core": "0.0.37",
|
|
25
|
+
"@riebeckite/ui": "0.0.37"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"tsx": "^4.22.4"
|