@gofreego/tsutils 0.1.11 → 0.1.13

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/index.mjs CHANGED
@@ -403,8 +403,10 @@ var getHighlighter = async () => {
403
403
  var ReadmeViewer = ({
404
404
  content,
405
405
  className = "",
406
- isDark = false
406
+ isDark: propIsDark,
407
+ muiTheme
407
408
  }) => {
409
+ const isDark = propIsDark !== void 0 ? propIsDark : muiTheme?.palette?.mode === "dark";
408
410
  const [highlighter, setHighlighter] = useState(null);
409
411
  const [copiedBlocks, setCopiedBlocks] = useState(/* @__PURE__ */ new Set());
410
412
  useEffect(() => {
@@ -425,74 +427,85 @@ var ReadmeViewer = ({
425
427
  console.error("Failed to copy text: ", err);
426
428
  }
427
429
  };
428
- return /* @__PURE__ */ jsx("div", { className: `readme-viewer markdown-body ${className}`, children: /* @__PURE__ */ jsx(
429
- ReactMarkdown,
430
- {
431
- remarkPlugins: [remarkGfm, remarkMath],
432
- rehypePlugins: [rehypeKatex],
433
- components: {
434
- code({ className: className2, children, ...props }) {
435
- const match = /language-(\w+)/.exec(className2 || "");
436
- if (match && highlighter) {
437
- const codeText = String(children).replace(/\n$/, "");
438
- const blockId = `code-${Math.random().toString(36).substr(2, 9)}`;
439
- let highlightedHtml = "";
440
- try {
441
- highlightedHtml = highlighter.codeToHtml(codeText, {
442
- lang: match[1],
443
- theme: isDark ? "github-dark" : "github-light"
444
- });
445
- } catch (e) {
430
+ return /* @__PURE__ */ jsxs("div", { className: `readme-viewer markdown-body ${className}`, children: [
431
+ /* @__PURE__ */ jsx("style", { children: `
432
+ .shiki-wrapper pre.shiki {
433
+ padding: 16px !important;
434
+ border-radius: 8px !important;
435
+ overflow-x: auto;
436
+ margin-bottom: 16px;
437
+ border: 1px solid var(--md-sys-color-outline-variant, #e0e0e0);
438
+ }
439
+ ` }),
440
+ /* @__PURE__ */ jsx(
441
+ ReactMarkdown,
442
+ {
443
+ remarkPlugins: [remarkGfm, remarkMath],
444
+ rehypePlugins: [rehypeKatex],
445
+ components: {
446
+ code({ className: className2, children, ...props }) {
447
+ const match = /language-(\w+)/.exec(className2 || "");
448
+ if (match && highlighter) {
449
+ const codeText = String(children).replace(/\n$/, "");
450
+ const blockId = `code-${Math.random().toString(36).substr(2, 9)}`;
451
+ let highlightedHtml = "";
446
452
  try {
447
453
  highlightedHtml = highlighter.codeToHtml(codeText, {
448
- lang: "text",
454
+ lang: match[1],
449
455
  theme: isDark ? "github-dark" : "github-light"
450
456
  });
451
- } catch (fallbackError) {
452
- highlightedHtml = `<pre><code>${codeText}</code></pre>`;
457
+ } catch (e) {
458
+ try {
459
+ highlightedHtml = highlighter.codeToHtml(codeText, {
460
+ lang: "text",
461
+ theme: isDark ? "github-dark" : "github-light"
462
+ });
463
+ } catch (fallbackError) {
464
+ highlightedHtml = `<pre><code>${codeText}</code></pre>`;
465
+ }
453
466
  }
467
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
468
+ /* @__PURE__ */ jsx("div", { className: "shiki-wrapper", dangerouslySetInnerHTML: { __html: highlightedHtml } }),
469
+ /* @__PURE__ */ jsx(
470
+ "button",
471
+ {
472
+ onClick: () => copyToClipboard(codeText, blockId),
473
+ style: {
474
+ position: "absolute",
475
+ top: "8px",
476
+ right: "8px",
477
+ backgroundColor: "var(--md-sys-color-surface-container-high)",
478
+ border: "1px solid var(--md-sys-color-outline-variant)",
479
+ borderRadius: "4px",
480
+ padding: "6px",
481
+ fontSize: "14px",
482
+ cursor: "pointer",
483
+ color: "var(--md-sys-color-on-surface-variant)",
484
+ alignItems: "center",
485
+ justifyContent: "center",
486
+ transition: "all 0.2s ease",
487
+ width: "32px",
488
+ height: "32px"
489
+ },
490
+ onMouseEnter: (e) => {
491
+ e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
492
+ },
493
+ onMouseLeave: (e) => {
494
+ e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
495
+ },
496
+ title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
497
+ children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsx(CheckIcon, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsx(ContentCopyIcon, { style: { fontSize: "16px" } })
498
+ }
499
+ )
500
+ ] });
454
501
  }
455
- return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
456
- /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: highlightedHtml } }),
457
- /* @__PURE__ */ jsx(
458
- "button",
459
- {
460
- onClick: () => copyToClipboard(codeText, blockId),
461
- style: {
462
- position: "absolute",
463
- top: "8px",
464
- right: "8px",
465
- backgroundColor: "var(--md-sys-color-surface-container-high)",
466
- border: "1px solid var(--md-sys-color-outline-variant)",
467
- borderRadius: "4px",
468
- padding: "6px",
469
- fontSize: "14px",
470
- cursor: "pointer",
471
- color: "var(--md-sys-color-on-surface-variant)",
472
- alignItems: "center",
473
- justifyContent: "center",
474
- transition: "all 0.2s ease",
475
- width: "32px",
476
- height: "32px"
477
- },
478
- onMouseEnter: (e) => {
479
- e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
480
- },
481
- onMouseLeave: (e) => {
482
- e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
483
- },
484
- title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
485
- children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsx(CheckIcon, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsx(ContentCopyIcon, { style: { fontSize: "16px" } })
486
- }
487
- )
488
- ] });
502
+ return /* @__PURE__ */ jsx("code", { className: className2, ...props, children });
489
503
  }
490
- return /* @__PURE__ */ jsx("code", { className: className2, ...props, children });
491
- }
492
- },
493
- children: content
494
- }
495
- ) });
504
+ },
505
+ children: content
506
+ }
507
+ )
508
+ ] });
496
509
  };
497
510
  var ReadmeViewer_default = ReadmeViewer;
498
511
  var NotificationContext = createContext(void 0);
@@ -1162,7 +1175,7 @@ var HttpClient = class {
1162
1175
  try {
1163
1176
  error.data = await response.json();
1164
1177
  } catch {
1165
- error.data = await response.text();
1178
+ error.data = { code: response.status, message: await response.text() };
1166
1179
  }
1167
1180
  throw error;
1168
1181
  }
@@ -1181,6 +1194,15 @@ var HttpClient = class {
1181
1194
  throw error;
1182
1195
  }
1183
1196
  }
1197
+ setDefaultHeader(key, value) {
1198
+ this.defaultHeaders[key] = value;
1199
+ }
1200
+ removeDefaultHeader(key) {
1201
+ delete this.defaultHeaders[key];
1202
+ }
1203
+ getDefaultHeaders() {
1204
+ return { ...this.defaultHeaders };
1205
+ }
1184
1206
  get(url, config) {
1185
1207
  return this.request(url, { ...config, method: "GET" });
1186
1208
  }
@@ -1197,6 +1219,16 @@ var HttpClient = class {
1197
1219
  return this.request(url, { ...config, method: "DELETE" });
1198
1220
  }
1199
1221
  };
1222
+ function extractErrorMessage(error) {
1223
+ if (error instanceof Error) {
1224
+ const httpError = error;
1225
+ if (httpError.data) {
1226
+ return httpError.data.message;
1227
+ }
1228
+ return error.message;
1229
+ }
1230
+ return "An unexpected error occurred";
1231
+ }
1200
1232
 
1201
1233
  // src/utils/cn.ts
1202
1234
  function cn(...classes) {
@@ -1393,6 +1425,6 @@ var PermissionManager = class {
1393
1425
  };
1394
1426
  PermissionManager.cachedPermissions = null;
1395
1427
 
1396
- export { AuthProvider, ConfirmDialog, HttpClient, LocalStorage, NotificationProvider, PermissionManager, ReadmeViewer_default as ReadmeViewer, SidebarLayout, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens_exports as tokens, transition, useAuth, useNotification, useTheme, zIndex };
1428
+ export { AuthProvider, ConfirmDialog, HttpClient, LocalStorage, NotificationProvider, PermissionManager, ReadmeViewer_default as ReadmeViewer, SidebarLayout, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, extractErrorMessage, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens_exports as tokens, transition, useAuth, useNotification, useTheme, zIndex };
1397
1429
  //# sourceMappingURL=index.mjs.map
1398
1430
  //# sourceMappingURL=index.mjs.map