@scalar/use-hooks 0.3.4 → 0.3.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scalar/use-hooks
2
2
 
3
+ ## 0.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#7678](https://github.com/scalar/scalar/pull/7678): feat: added object stringification to useClipboard
8
+
9
+ ## 0.3.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#7661](https://github.com/scalar/scalar/pull/7661): fix: all issues for client modal v2 preparation
14
+
3
15
  ## 0.3.4
4
16
 
5
17
  ### Patch Changes
@@ -3,6 +3,6 @@ import type { UseClipboardOptions } from './types.js';
3
3
  * A hook for interacting with the clipboard
4
4
  */
5
5
  export declare function useClipboard(opts?: UseClipboardOptions): {
6
- copyToClipboard: (value: string) => Promise<void>;
6
+ copyToClipboard: (value: unknown) => Promise<void>;
7
7
  };
8
8
  //# sourceMappingURL=useClipboard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useClipboard.d.ts","sourceRoot":"","sources":["../../src/useClipboard/useClipboard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,mBAAwB;6BAInB,MAAM;EAY7C"}
1
+ {"version":3,"file":"useClipboard.d.ts","sourceRoot":"","sources":["../../src/useClipboard/useClipboard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAalD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,mBAAwB;6BAInB,OAAO;EAa9C"}
@@ -1,10 +1,20 @@
1
1
  import { useToasts } from "@scalar/use-toasts";
2
+ const serializeValue = (value) => {
3
+ if (value === void 0) {
4
+ return "undefined";
5
+ }
6
+ if (typeof value === "string") {
7
+ return value;
8
+ }
9
+ return JSON.stringify(value);
10
+ };
2
11
  function useClipboard(opts = {}) {
3
12
  const { notify = (m) => toast(m, "info") } = opts;
4
13
  const { toast } = useToasts();
5
14
  async function copyToClipboard(value) {
6
15
  try {
7
- await navigator.clipboard.writeText(value);
16
+ const serialized = serializeValue(value);
17
+ await navigator.clipboard.writeText(serialized);
8
18
  notify("Copied to the clipboard");
9
19
  } catch (e) {
10
20
  const error = e;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useClipboard/useClipboard.ts"],
4
- "sourcesContent": ["import { useToasts } from '@scalar/use-toasts'\n\nimport type { UseClipboardOptions } from './types'\n\n/**\n * A hook for interacting with the clipboard\n */\nexport function useClipboard(opts: UseClipboardOptions = {}) {\n const { notify = (m) => toast(m, 'info') } = opts\n const { toast } = useToasts()\n\n async function copyToClipboard(value: string) {\n try {\n await navigator.clipboard.writeText(value)\n notify('Copied to the clipboard')\n } catch (e) {\n const error = e as Error\n console.error(error.message)\n notify('Failed to copy to clipboard')\n }\n }\n\n return { copyToClipboard }\n}\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAOnB,SAAS,aAAa,OAA4B,CAAC,GAAG;AAC3D,QAAM,EAAE,SAAS,CAAC,MAAM,MAAM,GAAG,MAAM,EAAE,IAAI;AAC7C,QAAM,EAAE,MAAM,IAAI,UAAU;AAE5B,iBAAe,gBAAgB,OAAe;AAC5C,QAAI;AACF,YAAM,UAAU,UAAU,UAAU,KAAK;AACzC,aAAO,yBAAyB;AAAA,IAClC,SAAS,GAAG;AACV,YAAM,QAAQ;AACd,cAAQ,MAAM,MAAM,OAAO;AAC3B,aAAO,6BAA6B;AAAA,IACtC;AAAA,EACF;AAEA,SAAO,EAAE,gBAAgB;AAC3B;",
4
+ "sourcesContent": ["import { useToasts } from '@scalar/use-toasts'\n\nimport type { UseClipboardOptions } from './types'\n\n/** Safely serialize a value to a string */\nconst serializeValue = (value: unknown) => {\n if (value === undefined) {\n return 'undefined'\n }\n if (typeof value === 'string') {\n return value\n }\n return JSON.stringify(value)\n}\n\n/**\n * A hook for interacting with the clipboard\n */\nexport function useClipboard(opts: UseClipboardOptions = {}) {\n const { notify = (m) => toast(m, 'info') } = opts\n const { toast } = useToasts()\n\n async function copyToClipboard(value: unknown) {\n try {\n const serialized = serializeValue(value)\n await navigator.clipboard.writeText(serialized)\n notify('Copied to the clipboard')\n } catch (e) {\n const error = e as Error\n console.error(error.message)\n notify('Failed to copy to clipboard')\n }\n }\n\n return { copyToClipboard }\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB;AAK1B,MAAM,iBAAiB,CAAC,UAAmB;AACzC,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,SAAO,KAAK,UAAU,KAAK;AAC7B;AAKO,SAAS,aAAa,OAA4B,CAAC,GAAG;AAC3D,QAAM,EAAE,SAAS,CAAC,MAAM,MAAM,GAAG,MAAM,EAAE,IAAI;AAC7C,QAAM,EAAE,MAAM,IAAI,UAAU;AAE5B,iBAAe,gBAAgB,OAAgB;AAC7C,QAAI;AACF,YAAM,aAAa,eAAe,KAAK;AACvC,YAAM,UAAU,UAAU,UAAU,UAAU;AAC9C,aAAO,yBAAyB;AAAA,IAClC,SAAS,GAAG;AACV,YAAM,QAAQ;AACd,cAAQ,MAAM,MAAM,OAAO;AAC3B,aAAO,6BAA6B;AAAA,IACtC;AAAA,EACF;AAEA,SAAO,EAAE,gBAAgB;AAC3B;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "url": "git+https://github.com/scalar/scalar.git",
11
11
  "directory": "packages/use-hooks"
12
12
  },
13
- "version": "0.3.4",
13
+ "version": "0.3.6",
14
14
  "engines": {
15
15
  "node": ">=20"
16
16
  },