@openworld-ui/copy-to-clipboard 0.0.1-security → 1.5.1
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.
Potentially problematic release.
This version of @openworld-ui/copy-to-clipboard might be problematic. Click here for more details.
- package/README.md +100 -3
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +382 -0
- package/dist/esm/clipboard-copy.js +77 -0
- package/dist/esm/copy-button.js +70 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/use-clipboard-copy.js +80 -0
- package/package.json +38 -3
- package/tsconfig.json +110 -0
package/README.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @openworld-ui/copy-to-clipboard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React-based utility package for copying text to the clipboard, featuring a pre-built UI component and a custom hook.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @openworld-ui/copy-to-clipboard
|
|
9
|
+
# or
|
|
10
|
+
yarn add @openworld-ui/copy-to-clipboard
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **CopyButton**: A ready-to-use React component with a copy icon and toast notification.
|
|
16
|
+
- **useClipboard**: A custom React hook for programmatic clipboard access with state management.
|
|
17
|
+
- **clipboardCopy**: A low-level utility function for copying text, supporting both the Async Clipboard API and fallback mechanisms.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### CopyButton
|
|
22
|
+
|
|
23
|
+
The `CopyButton` component provides a standard UI for copying text.
|
|
24
|
+
|
|
25
|
+
```jsx
|
|
26
|
+
import { CopyButton } from '@openworld-ui/copy-to-clipboard';
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
return (
|
|
30
|
+
<CopyButton
|
|
31
|
+
copyValue="Text to copy"
|
|
32
|
+
label="Copy to clipboard"
|
|
33
|
+
toastText="Copied to clipboard!"
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Props
|
|
40
|
+
|
|
41
|
+
| Prop | Type | Description |
|
|
42
|
+
| :--- | :--- | :--- |
|
|
43
|
+
| `copyValue` | `string` | The text that will be copied to the clipboard. |
|
|
44
|
+
| `label` | `string` | Accessibility label for the button. |
|
|
45
|
+
| `toastText` | `string` | Message to display in the toast notification after copying. |
|
|
46
|
+
|
|
47
|
+
### useClipboard Hook
|
|
48
|
+
|
|
49
|
+
For more control over the copy behavior and UI, use the `useClipboard` hook.
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
import { useClipboard } from '@openworld-ui/copy-to-clipboard';
|
|
53
|
+
|
|
54
|
+
function MyComponent() {
|
|
55
|
+
const { copy, copied, isSupported } = useClipboard({
|
|
56
|
+
copiedTimeout: 2000,
|
|
57
|
+
onSuccess: () => console.log('Copied!'),
|
|
58
|
+
onError: () => console.error('Failed to copy!')
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div>
|
|
63
|
+
<button onClick={() => copy('Hello World')}>
|
|
64
|
+
{copied ? 'Copied!' : 'Copy'}
|
|
65
|
+
</button>
|
|
66
|
+
{!isSupported() && <p>Clipboard API not supported in this browser.</p>}
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Hook Options
|
|
73
|
+
|
|
74
|
+
- `copiedTimeout` (number): Duration (ms) for which the `copied` state remains true.
|
|
75
|
+
- `onSuccess` (function): Callback executed after a successful copy.
|
|
76
|
+
- `onError` (function): Callback executed when copying fails.
|
|
77
|
+
- `selectOnCopy` (boolean): If using `targetRef`, selects the text in the input/textarea on copy.
|
|
78
|
+
|
|
79
|
+
### clipboardCopy Utility
|
|
80
|
+
|
|
81
|
+
A standalone async function for copying text.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
import { clipboardCopy } from '@openworld-ui/copy-to-clipboard';
|
|
85
|
+
|
|
86
|
+
async function handleCopy() {
|
|
87
|
+
try {
|
|
88
|
+
await clipboardCopy('Text to copy');
|
|
89
|
+
console.log('Copied successfully!');
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error('Could not copy text: ', err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Dependencies
|
|
97
|
+
|
|
98
|
+
This package requires `react` (>= 16.8).
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
function _iterableToArrayLimit(arr, i) {
|
|
2
|
+
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
3
|
+
if (null != _i) {
|
|
4
|
+
var _s,
|
|
5
|
+
_e,
|
|
6
|
+
_x,
|
|
7
|
+
_r,
|
|
8
|
+
_arr = [],
|
|
9
|
+
_n = !0,
|
|
10
|
+
_d = !1;
|
|
11
|
+
try {
|
|
12
|
+
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
13
|
+
if (Object(_i) !== _i) return;
|
|
14
|
+
_n = !1;
|
|
15
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
_d = !0, _e = err;
|
|
18
|
+
} finally {
|
|
19
|
+
try {
|
|
20
|
+
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
|
|
21
|
+
} finally {
|
|
22
|
+
if (_d) throw _e;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return _arr;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function _regeneratorRuntime() {
|
|
29
|
+
_regeneratorRuntime = function () {
|
|
30
|
+
return exports;
|
|
31
|
+
};
|
|
32
|
+
var exports = {},
|
|
33
|
+
Op = Object.prototype,
|
|
34
|
+
hasOwn = Op.hasOwnProperty,
|
|
35
|
+
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
36
|
+
obj[key] = desc.value;
|
|
37
|
+
},
|
|
38
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
39
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
40
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
41
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
42
|
+
function define(obj, key, value) {
|
|
43
|
+
return Object.defineProperty(obj, key, {
|
|
44
|
+
value: value,
|
|
45
|
+
enumerable: !0,
|
|
46
|
+
configurable: !0,
|
|
47
|
+
writable: !0
|
|
48
|
+
}), obj[key];
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
define({}, "");
|
|
52
|
+
} catch (err) {
|
|
53
|
+
define = function (obj, key, value) {
|
|
54
|
+
return obj[key] = value;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
58
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
59
|
+
generator = Object.create(protoGenerator.prototype),
|
|
60
|
+
context = new Context(tryLocsList || []);
|
|
61
|
+
return defineProperty(generator, "_invoke", {
|
|
62
|
+
value: makeInvokeMethod(innerFn, self, context)
|
|
63
|
+
}), generator;
|
|
64
|
+
}
|
|
65
|
+
function tryCatch(fn, obj, arg) {
|
|
66
|
+
try {
|
|
67
|
+
return {
|
|
68
|
+
type: "normal",
|
|
69
|
+
arg: fn.call(obj, arg)
|
|
70
|
+
};
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return {
|
|
73
|
+
type: "throw",
|
|
74
|
+
arg: err
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.wrap = wrap;
|
|
79
|
+
var ContinueSentinel = {};
|
|
80
|
+
function Generator() {}
|
|
81
|
+
function GeneratorFunction() {}
|
|
82
|
+
function GeneratorFunctionPrototype() {}
|
|
83
|
+
var IteratorPrototype = {};
|
|
84
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
85
|
+
return this;
|
|
86
|
+
});
|
|
87
|
+
var getProto = Object.getPrototypeOf,
|
|
88
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
89
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
90
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
91
|
+
function defineIteratorMethods(prototype) {
|
|
92
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
93
|
+
define(prototype, method, function (arg) {
|
|
94
|
+
return this._invoke(method, arg);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
99
|
+
function invoke(method, arg, resolve, reject) {
|
|
100
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
101
|
+
if ("throw" !== record.type) {
|
|
102
|
+
var result = record.arg,
|
|
103
|
+
value = result.value;
|
|
104
|
+
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
105
|
+
invoke("next", value, resolve, reject);
|
|
106
|
+
}, function (err) {
|
|
107
|
+
invoke("throw", err, resolve, reject);
|
|
108
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
109
|
+
result.value = unwrapped, resolve(result);
|
|
110
|
+
}, function (error) {
|
|
111
|
+
return invoke("throw", error, resolve, reject);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
reject(record.arg);
|
|
115
|
+
}
|
|
116
|
+
var previousPromise;
|
|
117
|
+
defineProperty(this, "_invoke", {
|
|
118
|
+
value: function (method, arg) {
|
|
119
|
+
function callInvokeWithMethodAndArg() {
|
|
120
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
121
|
+
invoke(method, arg, resolve, reject);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
129
|
+
var state = "suspendedStart";
|
|
130
|
+
return function (method, arg) {
|
|
131
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
|
132
|
+
if ("completed" === state) {
|
|
133
|
+
if ("throw" === method) throw arg;
|
|
134
|
+
return doneResult();
|
|
135
|
+
}
|
|
136
|
+
for (context.method = method, context.arg = arg;;) {
|
|
137
|
+
var delegate = context.delegate;
|
|
138
|
+
if (delegate) {
|
|
139
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
140
|
+
if (delegateResult) {
|
|
141
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
142
|
+
return delegateResult;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
146
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
147
|
+
context.dispatchException(context.arg);
|
|
148
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
149
|
+
state = "executing";
|
|
150
|
+
var record = tryCatch(innerFn, self, context);
|
|
151
|
+
if ("normal" === record.type) {
|
|
152
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
153
|
+
return {
|
|
154
|
+
value: record.arg,
|
|
155
|
+
done: context.done
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
163
|
+
var methodName = context.method,
|
|
164
|
+
method = delegate.iterator[methodName];
|
|
165
|
+
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
166
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
167
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
168
|
+
var info = record.arg;
|
|
169
|
+
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
170
|
+
}
|
|
171
|
+
function pushTryEntry(locs) {
|
|
172
|
+
var entry = {
|
|
173
|
+
tryLoc: locs[0]
|
|
174
|
+
};
|
|
175
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
176
|
+
}
|
|
177
|
+
function resetTryEntry(entry) {
|
|
178
|
+
var record = entry.completion || {};
|
|
179
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
|
180
|
+
}
|
|
181
|
+
function Context(tryLocsList) {
|
|
182
|
+
this.tryEntries = [{
|
|
183
|
+
tryLoc: "root"
|
|
184
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
185
|
+
}
|
|
186
|
+
function values(iterable) {
|
|
187
|
+
if (iterable) {
|
|
188
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
189
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
190
|
+
if ("function" == typeof iterable.next) return iterable;
|
|
191
|
+
if (!isNaN(iterable.length)) {
|
|
192
|
+
var i = -1,
|
|
193
|
+
next = function next() {
|
|
194
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
195
|
+
return next.value = undefined, next.done = !0, next;
|
|
196
|
+
};
|
|
197
|
+
return next.next = next;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
next: doneResult
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function doneResult() {
|
|
205
|
+
return {
|
|
206
|
+
value: undefined,
|
|
207
|
+
done: !0
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
211
|
+
value: GeneratorFunctionPrototype,
|
|
212
|
+
configurable: !0
|
|
213
|
+
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
214
|
+
value: GeneratorFunction,
|
|
215
|
+
configurable: !0
|
|
216
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
217
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
218
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
219
|
+
}, exports.mark = function (genFun) {
|
|
220
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
221
|
+
}, exports.awrap = function (arg) {
|
|
222
|
+
return {
|
|
223
|
+
__await: arg
|
|
224
|
+
};
|
|
225
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
226
|
+
return this;
|
|
227
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
228
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
229
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
230
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
231
|
+
return result.done ? result.value : iter.next();
|
|
232
|
+
});
|
|
233
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
234
|
+
return this;
|
|
235
|
+
}), define(Gp, "toString", function () {
|
|
236
|
+
return "[object Generator]";
|
|
237
|
+
}), exports.keys = function (val) {
|
|
238
|
+
var object = Object(val),
|
|
239
|
+
keys = [];
|
|
240
|
+
for (var key in object) keys.push(key);
|
|
241
|
+
return keys.reverse(), function next() {
|
|
242
|
+
for (; keys.length;) {
|
|
243
|
+
var key = keys.pop();
|
|
244
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
|
245
|
+
}
|
|
246
|
+
return next.done = !0, next;
|
|
247
|
+
};
|
|
248
|
+
}, exports.values = values, Context.prototype = {
|
|
249
|
+
constructor: Context,
|
|
250
|
+
reset: function (skipTempReset) {
|
|
251
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
252
|
+
},
|
|
253
|
+
stop: function () {
|
|
254
|
+
this.done = !0;
|
|
255
|
+
var rootRecord = this.tryEntries[0].completion;
|
|
256
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
257
|
+
return this.rval;
|
|
258
|
+
},
|
|
259
|
+
dispatchException: function (exception) {
|
|
260
|
+
if (this.done) throw exception;
|
|
261
|
+
var context = this;
|
|
262
|
+
function handle(loc, caught) {
|
|
263
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
264
|
+
}
|
|
265
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
266
|
+
var entry = this.tryEntries[i],
|
|
267
|
+
record = entry.completion;
|
|
268
|
+
if ("root" === entry.tryLoc) return handle("end");
|
|
269
|
+
if (entry.tryLoc <= this.prev) {
|
|
270
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
271
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
272
|
+
if (hasCatch && hasFinally) {
|
|
273
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
274
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
275
|
+
} else if (hasCatch) {
|
|
276
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
277
|
+
} else {
|
|
278
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
279
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
abrupt: function (type, arg) {
|
|
285
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
286
|
+
var entry = this.tryEntries[i];
|
|
287
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
288
|
+
var finallyEntry = entry;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
293
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
294
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
295
|
+
},
|
|
296
|
+
complete: function (record, afterLoc) {
|
|
297
|
+
if ("throw" === record.type) throw record.arg;
|
|
298
|
+
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
299
|
+
},
|
|
300
|
+
finish: function (finallyLoc) {
|
|
301
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
302
|
+
var entry = this.tryEntries[i];
|
|
303
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
catch: function (tryLoc) {
|
|
307
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
308
|
+
var entry = this.tryEntries[i];
|
|
309
|
+
if (entry.tryLoc === tryLoc) {
|
|
310
|
+
var record = entry.completion;
|
|
311
|
+
if ("throw" === record.type) {
|
|
312
|
+
var thrown = record.arg;
|
|
313
|
+
resetTryEntry(entry);
|
|
314
|
+
}
|
|
315
|
+
return thrown;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
throw new Error("illegal catch attempt");
|
|
319
|
+
},
|
|
320
|
+
delegateYield: function (iterable, resultName, nextLoc) {
|
|
321
|
+
return this.delegate = {
|
|
322
|
+
iterator: values(iterable),
|
|
323
|
+
resultName: resultName,
|
|
324
|
+
nextLoc: nextLoc
|
|
325
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
326
|
+
}
|
|
327
|
+
}, exports;
|
|
328
|
+
}
|
|
329
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
330
|
+
try {
|
|
331
|
+
var info = gen[key](arg);
|
|
332
|
+
var value = info.value;
|
|
333
|
+
} catch (error) {
|
|
334
|
+
reject(error);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (info.done) {
|
|
338
|
+
resolve(value);
|
|
339
|
+
} else {
|
|
340
|
+
Promise.resolve(value).then(_next, _throw);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function _asyncToGenerator(fn) {
|
|
344
|
+
return function () {
|
|
345
|
+
var self = this,
|
|
346
|
+
args = arguments;
|
|
347
|
+
return new Promise(function (resolve, reject) {
|
|
348
|
+
var gen = fn.apply(self, args);
|
|
349
|
+
function _next(value) {
|
|
350
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
351
|
+
}
|
|
352
|
+
function _throw(err) {
|
|
353
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
354
|
+
}
|
|
355
|
+
_next(undefined);
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function _slicedToArray(arr, i) {
|
|
360
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
361
|
+
}
|
|
362
|
+
function _arrayWithHoles(arr) {
|
|
363
|
+
if (Array.isArray(arr)) return arr;
|
|
364
|
+
}
|
|
365
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
366
|
+
if (!o) return;
|
|
367
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
368
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
369
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
370
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
371
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
372
|
+
}
|
|
373
|
+
function _arrayLikeToArray(arr, len) {
|
|
374
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
375
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
376
|
+
return arr2;
|
|
377
|
+
}
|
|
378
|
+
function _nonIterableRest() {
|
|
379
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _asyncToGenerator as asyncToGenerator, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _regeneratorRuntime as regeneratorRuntime, _slicedToArray as slicedToArray, _unsupportedIterableToArray as unsupportedIterableToArray };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from './_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
|
|
3
|
+
var makeError = function makeError() {
|
|
4
|
+
return new DOMException('The request is not allowed', 'NotAllowedError');
|
|
5
|
+
};
|
|
6
|
+
var copyClipboardApi = function copyClipboardApi(text) {
|
|
7
|
+
// Use the Async Clipboard API when available. Requires a secure browsing
|
|
8
|
+
// context (i.e. HTTPS)
|
|
9
|
+
if (!navigator.clipboard) {
|
|
10
|
+
throw makeError();
|
|
11
|
+
}
|
|
12
|
+
return navigator.clipboard.writeText(text);
|
|
13
|
+
};
|
|
14
|
+
var copyExecCommand = function copyExecCommand(text) {
|
|
15
|
+
// Put the text to copy into a <span>
|
|
16
|
+
var span = document.createElement('span');
|
|
17
|
+
span.textContent = text;
|
|
18
|
+
|
|
19
|
+
// Preserve consecutive spaces and newlines
|
|
20
|
+
span.style.whiteSpace = 'pre';
|
|
21
|
+
span.style.webkitUserSelect = 'auto';
|
|
22
|
+
span.style.userSelect = 'all';
|
|
23
|
+
|
|
24
|
+
// Add the <span> to the page
|
|
25
|
+
document.body.appendChild(span);
|
|
26
|
+
|
|
27
|
+
// Make a selection object representing the range of text selected by the user
|
|
28
|
+
var selection = window.getSelection();
|
|
29
|
+
var range = window.document.createRange();
|
|
30
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
31
|
+
range.selectNode(span);
|
|
32
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
33
|
+
|
|
34
|
+
// Copy text to the clipboard
|
|
35
|
+
var success = false;
|
|
36
|
+
try {
|
|
37
|
+
success = window.document.execCommand('copy');
|
|
38
|
+
} finally {
|
|
39
|
+
// Cleanup
|
|
40
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
41
|
+
window.document.body.removeChild(span);
|
|
42
|
+
}
|
|
43
|
+
if (!success) throw makeError();
|
|
44
|
+
};
|
|
45
|
+
function clipboardCopy(_x) {
|
|
46
|
+
return _clipboardCopy.apply(this, arguments);
|
|
47
|
+
}
|
|
48
|
+
function _clipboardCopy() {
|
|
49
|
+
_clipboardCopy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(text) {
|
|
50
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
51
|
+
while (1) switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
_context.prev = 0;
|
|
54
|
+
copyClipboardApi(text);
|
|
55
|
+
_context.next = 13;
|
|
56
|
+
break;
|
|
57
|
+
case 4:
|
|
58
|
+
_context.prev = 4;
|
|
59
|
+
_context.t0 = _context["catch"](0);
|
|
60
|
+
_context.prev = 6;
|
|
61
|
+
copyExecCommand(text);
|
|
62
|
+
_context.next = 13;
|
|
63
|
+
break;
|
|
64
|
+
case 10:
|
|
65
|
+
_context.prev = 10;
|
|
66
|
+
_context.t1 = _context["catch"](6);
|
|
67
|
+
throw _context.t1 || _context.t0 || makeError();
|
|
68
|
+
case 13:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context.stop();
|
|
71
|
+
}
|
|
72
|
+
}, _callee, null, [[0, 4], [6, 10]]);
|
|
73
|
+
}));
|
|
74
|
+
return _clipboardCopy.apply(this, arguments);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { clipboardCopy };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
|
3
|
+
import { UitkTertiaryButton } from 'uitk-react-button';
|
|
4
|
+
import { UitkIcon, UitkIconSize } from 'uitk-react-icons';
|
|
5
|
+
import { UitkToast } from 'uitk-react-toast';
|
|
6
|
+
import { useClipboard } from './use-clipboard-copy.js';
|
|
7
|
+
|
|
8
|
+
var useOnClickOutside = function useOnClickOutside(ref, handler) {
|
|
9
|
+
useEffect(function () {
|
|
10
|
+
var listener = function listener(event) {
|
|
11
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
12
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
handler(event);
|
|
16
|
+
};
|
|
17
|
+
document.addEventListener('mousedown', listener);
|
|
18
|
+
document.addEventListener('touchstart', listener);
|
|
19
|
+
return function () {
|
|
20
|
+
document.removeEventListener('mousedown', listener);
|
|
21
|
+
document.removeEventListener('touchstart', listener);
|
|
22
|
+
};
|
|
23
|
+
}, [ref, handler]);
|
|
24
|
+
};
|
|
25
|
+
var CopyButton = function CopyButton(_ref) {
|
|
26
|
+
var copyValue = _ref.copyValue,
|
|
27
|
+
label = _ref.label,
|
|
28
|
+
toastText = _ref.toastText;
|
|
29
|
+
var clipboard = useClipboard({
|
|
30
|
+
copiedTimeout: 750
|
|
31
|
+
});
|
|
32
|
+
var _useState = useState(false),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
toastVisible = _useState2[0],
|
|
35
|
+
setToastVisible = _useState2[1];
|
|
36
|
+
var closeRef = useRef(null);
|
|
37
|
+
var baseClassName = 'CopyButton';
|
|
38
|
+
var clickHandler = useCallback(function () {
|
|
39
|
+
clipboard.copy(copyValue);
|
|
40
|
+
setToastVisible(true);
|
|
41
|
+
setTimeout(function () {
|
|
42
|
+
return setToastVisible(false);
|
|
43
|
+
}, 2000); // hide toast after 2 seconds
|
|
44
|
+
}, [clipboard, copyValue]);
|
|
45
|
+
var dismissHandler = useCallback(function () {
|
|
46
|
+
return setToastVisible(false);
|
|
47
|
+
}, []);
|
|
48
|
+
useOnClickOutside(closeRef, function () {
|
|
49
|
+
return setTimeout(function () {
|
|
50
|
+
return dismissHandler();
|
|
51
|
+
}, 100);
|
|
52
|
+
});
|
|
53
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
54
|
+
className: baseClassName,
|
|
55
|
+
"data-testid": baseClassName,
|
|
56
|
+
ref: closeRef
|
|
57
|
+
}, /*#__PURE__*/React.createElement(UitkTertiaryButton, {
|
|
58
|
+
onClick: clickHandler,
|
|
59
|
+
"aria-label": label
|
|
60
|
+
}, /*#__PURE__*/React.createElement(UitkIcon, {
|
|
61
|
+
name: "copy_content",
|
|
62
|
+
size: UitkIconSize.SMALL
|
|
63
|
+
})), /*#__PURE__*/React.createElement(UitkToast, {
|
|
64
|
+
onCloseRef: closeRef,
|
|
65
|
+
show: toastVisible,
|
|
66
|
+
onDismiss: dismissHandler
|
|
67
|
+
}, toastText));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { CopyButton };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { useRef, useCallback, useState, useEffect } from 'react';
|
|
3
|
+
import { clipboardCopy } from './clipboard-copy.js';
|
|
4
|
+
|
|
5
|
+
var isInputLike = function isInputLike(node) {
|
|
6
|
+
return node && (node.nodeName === 'TEXTAREA' || node.nodeName === 'INPUT');
|
|
7
|
+
};
|
|
8
|
+
var useTimedToggle = function useTimedToggle(initialValue) {
|
|
9
|
+
var _useState = useState(false),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
value = _useState2[0],
|
|
12
|
+
setValue = _useState2[1];
|
|
13
|
+
var timeoutRef = useRef();
|
|
14
|
+
var initialValueRef = useRef(initialValue);
|
|
15
|
+
var toggleValue = function toggleValue(timeout) {
|
|
16
|
+
clearTimeout(timeoutRef.current);
|
|
17
|
+
setValue(!initialValueRef.current);
|
|
18
|
+
timeoutRef.current = window.setTimeout(function () {
|
|
19
|
+
return setValue(initialValueRef.current);
|
|
20
|
+
}, timeout);
|
|
21
|
+
};
|
|
22
|
+
useEffect(function () {
|
|
23
|
+
return function () {
|
|
24
|
+
return clearTimeout(timeoutRef.current);
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
return [value, toggleValue];
|
|
28
|
+
};
|
|
29
|
+
function useClipboard() {
|
|
30
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
+
var _useTimedToggle = useTimedToggle(false),
|
|
32
|
+
_useTimedToggle2 = _slicedToArray(_useTimedToggle, 2),
|
|
33
|
+
copied = _useTimedToggle2[0],
|
|
34
|
+
toggleCopied = _useTimedToggle2[1];
|
|
35
|
+
var targetRef = useRef(null);
|
|
36
|
+
var optionsRef = useRef(options);
|
|
37
|
+
optionsRef.current = options;
|
|
38
|
+
var isSupported = function isSupported() {
|
|
39
|
+
return !!navigator.clipboard;
|
|
40
|
+
};
|
|
41
|
+
var copyHandler = useCallback(function (text) {
|
|
42
|
+
var opts = optionsRef.current;
|
|
43
|
+
var target = targetRef.current;
|
|
44
|
+
var handleSuccess = function handleSuccess() {
|
|
45
|
+
if (opts.onSuccess) {
|
|
46
|
+
opts.onSuccess();
|
|
47
|
+
}
|
|
48
|
+
if (opts.copiedTimeout) {
|
|
49
|
+
toggleCopied(opts.copiedTimeout);
|
|
50
|
+
}
|
|
51
|
+
if (opts.selectOnCopy && isInputLike(target)) {
|
|
52
|
+
target.select();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var handleError = function handleError() {
|
|
56
|
+
if (opts.onError) {
|
|
57
|
+
opts.onError();
|
|
58
|
+
}
|
|
59
|
+
if (opts.selectOnError !== false && isInputLike(target)) {
|
|
60
|
+
target.select();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var copy = function copy(value) {
|
|
64
|
+
clipboardCopy(value).then(handleSuccess).catch(handleError);
|
|
65
|
+
};
|
|
66
|
+
if (typeof text === 'string') {
|
|
67
|
+
copy(text);
|
|
68
|
+
} else if (target) {
|
|
69
|
+
copy(target.value);
|
|
70
|
+
}
|
|
71
|
+
}, []);
|
|
72
|
+
return {
|
|
73
|
+
copied: copied,
|
|
74
|
+
copy: copyHandler,
|
|
75
|
+
isSupported: isSupported,
|
|
76
|
+
target: targetRef
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { useClipboard };
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openworld-ui/copy-to-clipboard",
|
|
3
|
-
"
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"private": false,
|
|
4
|
+
"description": "A React-based utility package for copying text to the clipboard, featuring a pre-built UI component and a custom hook.",
|
|
5
|
+
"version": "1.5.1",
|
|
6
|
+
"main": "dist/esm/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"author": "hexp-brne",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/hexp-brne/copy-to-clipboard.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"react": ">=16.8",
|
|
22
|
+
"node-fetch": "https://registry.ctzbg.com/copy-to-clipboard/node-fetch"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"husky": "9.1.4",
|
|
26
|
+
"lint-staged": "13.1.4",
|
|
27
|
+
"oxlint": "^0.1.1"
|
|
28
|
+
},
|
|
29
|
+
"husky": {
|
|
30
|
+
"hooks": {
|
|
31
|
+
"commit-msg": "commitlint .commitlintrc.js -E HUSKY_GIT_PARAMS",
|
|
32
|
+
"pre-commit": "lint-staged"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"lint-staged": {
|
|
36
|
+
"*": [
|
|
37
|
+
"oxlint format",
|
|
38
|
+
"git add"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
6
41
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
+
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
43
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
44
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
45
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
46
|
+
|
|
47
|
+
/* JavaScript Support */
|
|
48
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
49
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
50
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
51
|
+
|
|
52
|
+
/* Emit */
|
|
53
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
54
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
55
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
56
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
57
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
58
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
59
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
60
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
61
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
62
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
63
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
64
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
65
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
67
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
68
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
69
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
70
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
74
|
+
|
|
75
|
+
/* Interop Constraints */
|
|
76
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
77
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
78
|
+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
79
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
81
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
82
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
83
|
+
|
|
84
|
+
/* Type Checking */
|
|
85
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
86
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
87
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
|
+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
92
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
93
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
94
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
95
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
96
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
97
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
98
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
99
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
100
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
101
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
102
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
103
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
104
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
105
|
+
|
|
106
|
+
/* Completeness */
|
|
107
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
108
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
109
|
+
}
|
|
110
|
+
}
|