@riebeckite/plugin-text-fragment 0.0.30 → 0.0.32
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 +37 -14
- package/dist/index.js +37 -14
- package/dist/src/text-fragment.client.d.ts +1 -1
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -50,7 +50,7 @@ function stripUrlFragment(url) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// src/text-fragment.client.ts
|
|
53
|
-
var ARTICLE_SELECTOR =
|
|
53
|
+
var ARTICLE_SELECTOR = ".rb-article-body";
|
|
54
54
|
var EXCLUDED_SELECTOR = "pre, code, a[href], [data-no-share]";
|
|
55
55
|
var POPOVER_GAP = 8;
|
|
56
56
|
var DEFAULT_TEXT_FRAGMENT_LABELS = {
|
|
@@ -86,6 +86,7 @@ function initTextFragmentShare(labels = {}) {
|
|
|
86
86
|
popover.appendChild(status);
|
|
87
87
|
document.body.appendChild(popover);
|
|
88
88
|
let active = null;
|
|
89
|
+
const copyingTimers = /* @__PURE__ */ new Set();
|
|
89
90
|
let isCopying = false;
|
|
90
91
|
const hide = () => {
|
|
91
92
|
active = null;
|
|
@@ -118,18 +119,20 @@ function initTextFragmentShare(labels = {}) {
|
|
|
118
119
|
popover.hidden = false;
|
|
119
120
|
positionPopover(popover, selection.rect);
|
|
120
121
|
} finally {
|
|
121
|
-
window.setTimeout(() => {
|
|
122
|
+
const timer = window.setTimeout(() => {
|
|
123
|
+
copyingTimers.delete(timer);
|
|
122
124
|
isCopying = false;
|
|
123
125
|
}, 0);
|
|
126
|
+
copyingTimers.add(timer);
|
|
124
127
|
}
|
|
125
128
|
};
|
|
126
|
-
|
|
129
|
+
const onLinkButtonClick = () => {
|
|
127
130
|
void copy(
|
|
128
131
|
(selection) => buildTextFragmentUrl(resolvePageUrl(), selection),
|
|
129
132
|
resolved.linkCopiedLabel
|
|
130
133
|
);
|
|
131
|
-
}
|
|
132
|
-
|
|
134
|
+
};
|
|
135
|
+
const onQuoteButtonClick = () => {
|
|
133
136
|
void copy(
|
|
134
137
|
(selection) => buildQuoteMarkdown({
|
|
135
138
|
url: resolvePageUrl(),
|
|
@@ -138,23 +141,43 @@ function initTextFragmentShare(labels = {}) {
|
|
|
138
141
|
}),
|
|
139
142
|
resolved.quoteCopiedLabel
|
|
140
143
|
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
document.addEventListener("mouseup", refresh);
|
|
145
|
-
document.addEventListener("keyup", refresh);
|
|
146
|
-
document.addEventListener("keydown", (event) => {
|
|
144
|
+
};
|
|
145
|
+
const onPopoverMouseDown = (event) => event.preventDefault();
|
|
146
|
+
const onKeyDown = (event) => {
|
|
147
147
|
if (event.key === "Escape" && !popover.hidden) {
|
|
148
148
|
event.preventDefault();
|
|
149
149
|
hide();
|
|
150
150
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
151
|
+
};
|
|
152
|
+
const onMouseDown = (event) => {
|
|
153
153
|
if (popover.hidden) return;
|
|
154
154
|
if (event.target instanceof Node && popover.contains(event.target)) return;
|
|
155
155
|
hide();
|
|
156
|
-
}
|
|
156
|
+
};
|
|
157
|
+
linkButton.addEventListener("click", onLinkButtonClick);
|
|
158
|
+
quoteButton.addEventListener("click", onQuoteButtonClick);
|
|
159
|
+
popover.addEventListener("mousedown", onPopoverMouseDown);
|
|
160
|
+
document.addEventListener("selectionchange", refresh);
|
|
161
|
+
document.addEventListener("mouseup", refresh);
|
|
162
|
+
document.addEventListener("keyup", refresh);
|
|
163
|
+
document.addEventListener("keydown", onKeyDown);
|
|
164
|
+
document.addEventListener("mousedown", onMouseDown);
|
|
157
165
|
window.addEventListener("scroll", hide, { passive: true });
|
|
166
|
+
return () => {
|
|
167
|
+
initialized = false;
|
|
168
|
+
for (const timer of copyingTimers) window.clearTimeout(timer);
|
|
169
|
+
copyingTimers.clear();
|
|
170
|
+
linkButton.removeEventListener("click", onLinkButtonClick);
|
|
171
|
+
quoteButton.removeEventListener("click", onQuoteButtonClick);
|
|
172
|
+
popover.removeEventListener("mousedown", onPopoverMouseDown);
|
|
173
|
+
document.removeEventListener("selectionchange", refresh);
|
|
174
|
+
document.removeEventListener("mouseup", refresh);
|
|
175
|
+
document.removeEventListener("keyup", refresh);
|
|
176
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
177
|
+
document.removeEventListener("mousedown", onMouseDown);
|
|
178
|
+
window.removeEventListener("scroll", hide);
|
|
179
|
+
popover.remove();
|
|
180
|
+
};
|
|
158
181
|
}
|
|
159
182
|
function createButton(label) {
|
|
160
183
|
const button = document.createElement("button");
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function stripUrlFragment(url) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/text-fragment.client.ts
|
|
60
|
-
var ARTICLE_SELECTOR =
|
|
60
|
+
var ARTICLE_SELECTOR = ".rb-article-body";
|
|
61
61
|
var EXCLUDED_SELECTOR = "pre, code, a[href], [data-no-share]";
|
|
62
62
|
var POPOVER_GAP = 8;
|
|
63
63
|
var DEFAULT_TEXT_FRAGMENT_LABELS = {
|
|
@@ -93,6 +93,7 @@ function initTextFragmentShare(labels = {}) {
|
|
|
93
93
|
popover.appendChild(status);
|
|
94
94
|
document.body.appendChild(popover);
|
|
95
95
|
let active = null;
|
|
96
|
+
const copyingTimers = /* @__PURE__ */ new Set();
|
|
96
97
|
let isCopying = false;
|
|
97
98
|
const hide = () => {
|
|
98
99
|
active = null;
|
|
@@ -125,18 +126,20 @@ function initTextFragmentShare(labels = {}) {
|
|
|
125
126
|
popover.hidden = false;
|
|
126
127
|
positionPopover(popover, selection.rect);
|
|
127
128
|
} finally {
|
|
128
|
-
window.setTimeout(() => {
|
|
129
|
+
const timer = window.setTimeout(() => {
|
|
130
|
+
copyingTimers.delete(timer);
|
|
129
131
|
isCopying = false;
|
|
130
132
|
}, 0);
|
|
133
|
+
copyingTimers.add(timer);
|
|
131
134
|
}
|
|
132
135
|
};
|
|
133
|
-
|
|
136
|
+
const onLinkButtonClick = () => {
|
|
134
137
|
void copy(
|
|
135
138
|
(selection) => buildTextFragmentUrl(resolvePageUrl(), selection),
|
|
136
139
|
resolved.linkCopiedLabel
|
|
137
140
|
);
|
|
138
|
-
}
|
|
139
|
-
|
|
141
|
+
};
|
|
142
|
+
const onQuoteButtonClick = () => {
|
|
140
143
|
void copy(
|
|
141
144
|
(selection) => buildQuoteMarkdown({
|
|
142
145
|
url: resolvePageUrl(),
|
|
@@ -145,23 +148,43 @@ function initTextFragmentShare(labels = {}) {
|
|
|
145
148
|
}),
|
|
146
149
|
resolved.quoteCopiedLabel
|
|
147
150
|
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
document.addEventListener("mouseup", refresh);
|
|
152
|
-
document.addEventListener("keyup", refresh);
|
|
153
|
-
document.addEventListener("keydown", (event) => {
|
|
151
|
+
};
|
|
152
|
+
const onPopoverMouseDown = (event) => event.preventDefault();
|
|
153
|
+
const onKeyDown = (event) => {
|
|
154
154
|
if (event.key === "Escape" && !popover.hidden) {
|
|
155
155
|
event.preventDefault();
|
|
156
156
|
hide();
|
|
157
157
|
}
|
|
158
|
-
}
|
|
159
|
-
|
|
158
|
+
};
|
|
159
|
+
const onMouseDown = (event) => {
|
|
160
160
|
if (popover.hidden) return;
|
|
161
161
|
if (event.target instanceof Node && popover.contains(event.target)) return;
|
|
162
162
|
hide();
|
|
163
|
-
}
|
|
163
|
+
};
|
|
164
|
+
linkButton.addEventListener("click", onLinkButtonClick);
|
|
165
|
+
quoteButton.addEventListener("click", onQuoteButtonClick);
|
|
166
|
+
popover.addEventListener("mousedown", onPopoverMouseDown);
|
|
167
|
+
document.addEventListener("selectionchange", refresh);
|
|
168
|
+
document.addEventListener("mouseup", refresh);
|
|
169
|
+
document.addEventListener("keyup", refresh);
|
|
170
|
+
document.addEventListener("keydown", onKeyDown);
|
|
171
|
+
document.addEventListener("mousedown", onMouseDown);
|
|
164
172
|
window.addEventListener("scroll", hide, { passive: true });
|
|
173
|
+
return () => {
|
|
174
|
+
initialized = false;
|
|
175
|
+
for (const timer of copyingTimers) window.clearTimeout(timer);
|
|
176
|
+
copyingTimers.clear();
|
|
177
|
+
linkButton.removeEventListener("click", onLinkButtonClick);
|
|
178
|
+
quoteButton.removeEventListener("click", onQuoteButtonClick);
|
|
179
|
+
popover.removeEventListener("mousedown", onPopoverMouseDown);
|
|
180
|
+
document.removeEventListener("selectionchange", refresh);
|
|
181
|
+
document.removeEventListener("mouseup", refresh);
|
|
182
|
+
document.removeEventListener("keyup", refresh);
|
|
183
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
184
|
+
document.removeEventListener("mousedown", onMouseDown);
|
|
185
|
+
window.removeEventListener("scroll", hide);
|
|
186
|
+
popover.remove();
|
|
187
|
+
};
|
|
165
188
|
}
|
|
166
189
|
function createButton(label) {
|
|
167
190
|
const button = document.createElement("button");
|
|
@@ -14,4 +14,4 @@ export declare const DEFAULT_TEXT_FRAGMENT_LABELS: TextFragmentLabels;
|
|
|
14
14
|
* Client-only: returns immediately when there is no `document`, and only wires
|
|
15
15
|
* its listeners once per page.
|
|
16
16
|
*/
|
|
17
|
-
export declare function initTextFragmentShare(labels?: Partial<TextFragmentLabels>): void;
|
|
17
|
+
export declare function initTextFragmentShare(labels?: Partial<TextFragmentLabels>): (() => void) | undefined;
|
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.32",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@riebeckite/core": "0.0.
|
|
24
|
+
"@riebeckite/core": "0.0.32"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"tsx": "^4.22.4"
|