@np-dev/ui-ai-anotation 0.1.0 → 0.1.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.
Files changed (36) hide show
  1. package/README.md +106 -21
  2. package/dist/cjs/index.cjs +247 -14
  3. package/dist/cjs/index.cjs.map +4 -4
  4. package/dist/cjs/index.native.cjs +11 -11
  5. package/dist/cjs/index.native.cjs.map +3 -3
  6. package/dist/cjs/index.web.cjs +5 -5
  7. package/dist/cjs/index.web.cjs.map +2 -2
  8. package/dist/esm/index.js +248 -14
  9. package/dist/esm/index.js.map +4 -4
  10. package/dist/esm/index.native.js +11 -11
  11. package/dist/esm/index.native.js.map +3 -3
  12. package/dist/esm/index.web.js +5 -5
  13. package/dist/esm/index.web.js.map +2 -2
  14. package/dist/types/components/ErrorBoundary.d.ts +159 -0
  15. package/dist/types/index.d.ts +5 -3
  16. package/dist/types/index.web.d.ts +2 -2
  17. package/dist/types/store.d.ts +2 -2
  18. package/package.json +1 -1
  19. package/src/components/AnnotationInput.tsx +2 -2
  20. package/src/components/AnnotationList.tsx +2 -2
  21. package/src/components/ErrorBoundary.tsx +426 -0
  22. package/src/components/Highlighter.tsx +2 -2
  23. package/src/components/Toolbar.tsx +4 -3
  24. package/src/components/native/AnnotationInput.tsx +2 -2
  25. package/src/components/native/AnnotationList.tsx +2 -2
  26. package/src/components/native/Highlighter.tsx +2 -2
  27. package/src/components/native/Toolbar.tsx +2 -2
  28. package/src/components/web/AnnotationInput.tsx +2 -2
  29. package/src/components/web/AnnotationList.tsx +2 -2
  30. package/src/components/web/Highlighter.tsx +2 -2
  31. package/src/components/web/Toolbar.tsx +2 -2
  32. package/src/extension.tsx +1 -1
  33. package/src/index.native.tsx +4 -4
  34. package/src/index.tsx +6 -4
  35. package/src/index.web.tsx +3 -3
  36. package/src/store.tsx +3 -3
package/dist/esm/index.js CHANGED
@@ -1,9 +1,12 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1
3
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
4
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
5
  }) : x)(function(x) {
4
6
  if (typeof require !== "undefined") return require.apply(this, arguments);
5
7
  throw Error('Dynamic require of "' + x + '" is not supported');
6
8
  });
9
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
10
 
8
11
  // src/store.tsx
9
12
  import { createContext, useContext, useReducer } from "react";
@@ -50,14 +53,14 @@ function reducer(state, action) {
50
53
  return state;
51
54
  }
52
55
  }
53
- function AiAnnotationProvider({ children }) {
56
+ function AgentAnnotationProvider({ children }) {
54
57
  const [state, dispatch] = useReducer(reducer, initialState);
55
58
  return /* @__PURE__ */ jsx(AnnotationContext.Provider, { value: { state, dispatch }, children });
56
59
  }
57
- function useAiAnnotation() {
60
+ function useAgentAnnotation() {
58
61
  const context = useContext(AnnotationContext);
59
62
  if (!context) {
60
- throw new Error("useAiAnnotation must be used within an AiAnnotationProvider");
63
+ throw new Error("useAgentAnnotation must be used within an AgentAnnotationProvider");
61
64
  }
62
65
  return context;
63
66
  }
@@ -177,7 +180,7 @@ function formatComponentDetails(details) {
177
180
  return lines.join("\n");
178
181
  }
179
182
  function AnnotationInput({ onClose, componentName, componentDetails }) {
180
- const { dispatch } = useAiAnnotation();
183
+ const { dispatch } = useAgentAnnotation();
181
184
  const [note, setNote] = useState2("");
182
185
  const [includeDetails, setIncludeDetails] = useState2(true);
183
186
  const [isVisible, setIsVisible] = useState2(false);
@@ -644,7 +647,7 @@ function getComponentDetails(element, options) {
644
647
  // src/components/Highlighter.tsx
645
648
  import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
646
649
  function Highlighter() {
647
- const { state, dispatch } = useAiAnnotation();
650
+ const { state, dispatch } = useAgentAnnotation();
648
651
  const { hoveredElement, mode, hoveredComponentInfo } = state;
649
652
  const [rect, setRect] = useState3(null);
650
653
  const [showInput, setShowInput] = useState3(false);
@@ -1063,7 +1066,7 @@ import { useState as useState4 } from "react";
1063
1066
  import { X as X2, Trash2, Trash, ChevronDown, ChevronRight } from "lucide-react";
1064
1067
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1065
1068
  function AnnotationList() {
1066
- const { state, dispatch } = useAiAnnotation();
1069
+ const { state, dispatch } = useAgentAnnotation();
1067
1070
  const [expandedId, setExpandedId] = useState4(null);
1068
1071
  if (!state.showList) return null;
1069
1072
  const toggleExpand = (id) => {
@@ -1293,7 +1296,7 @@ function AnnotationList() {
1293
1296
  // src/components/Toolbar.tsx
1294
1297
  import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
1295
1298
  function Toolbar() {
1296
- const { state, dispatch } = useAiAnnotation();
1299
+ const { state, dispatch } = useAgentAnnotation();
1297
1300
  const [showCopied, setShowCopied] = useState5(false);
1298
1301
  const [isAnimating, setIsAnimating] = useState5(false);
1299
1302
  const contentRef = useRef2(null);
@@ -1317,7 +1320,8 @@ function Toolbar() {
1317
1320
  const sections = state.annotations.map((a, index) => {
1318
1321
  const lines = [];
1319
1322
  lines.push(`${"=".repeat(50)}`);
1320
- lines.push(`Annotation ${index + 1}: ${a.componentName}`);
1323
+ lines.push(`Annotation ${index + 1}`);
1324
+ lines.push(`Component: ${a.componentName}`);
1321
1325
  lines.push(`${"=".repeat(50)}`);
1322
1326
  lines.push("");
1323
1327
  lines.push("## Instruction");
@@ -1478,6 +1482,235 @@ function Toolbar() {
1478
1482
  ] });
1479
1483
  }
1480
1484
 
1485
+ // src/components/ErrorBoundary.tsx
1486
+ import { Component } from "react";
1487
+ import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1488
+ var defaultStyles = {
1489
+ container: {
1490
+ display: "flex",
1491
+ flexDirection: "column",
1492
+ alignItems: "center",
1493
+ justifyContent: "center",
1494
+ minHeight: "100vh",
1495
+ padding: "24px",
1496
+ backgroundColor: "#1e1e1e",
1497
+ color: "#e5e7eb",
1498
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
1499
+ },
1500
+ content: {
1501
+ maxWidth: "600px",
1502
+ width: "100%",
1503
+ textAlign: "center"
1504
+ },
1505
+ icon: {
1506
+ fontSize: "48px",
1507
+ marginBottom: "16px"
1508
+ },
1509
+ title: {
1510
+ fontSize: "24px",
1511
+ fontWeight: 600,
1512
+ marginBottom: "8px",
1513
+ color: "#f87171"
1514
+ },
1515
+ subtitle: {
1516
+ fontSize: "16px",
1517
+ color: "#9ca3af",
1518
+ marginBottom: "24px"
1519
+ },
1520
+ errorBox: {
1521
+ backgroundColor: "#2d2d2d",
1522
+ border: "1px solid #404040",
1523
+ borderRadius: "8px",
1524
+ padding: "16px",
1525
+ marginBottom: "24px",
1526
+ textAlign: "left",
1527
+ maxHeight: "200px",
1528
+ overflow: "auto"
1529
+ },
1530
+ errorText: {
1531
+ fontFamily: "monospace",
1532
+ fontSize: "12px",
1533
+ color: "#f87171",
1534
+ whiteSpace: "pre-wrap",
1535
+ wordBreak: "break-word",
1536
+ margin: 0
1537
+ },
1538
+ buttonContainer: {
1539
+ display: "flex",
1540
+ gap: "12px",
1541
+ justifyContent: "center",
1542
+ flexWrap: "wrap"
1543
+ },
1544
+ button: {
1545
+ padding: "10px 20px",
1546
+ borderRadius: "6px",
1547
+ border: "none",
1548
+ fontSize: "14px",
1549
+ fontWeight: 500,
1550
+ cursor: "pointer",
1551
+ transition: "all 0.2s"
1552
+ },
1553
+ primaryButton: {
1554
+ backgroundColor: "#3b82f6",
1555
+ color: "white"
1556
+ },
1557
+ secondaryButton: {
1558
+ backgroundColor: "#404040",
1559
+ color: "#e5e7eb"
1560
+ },
1561
+ successButton: {
1562
+ backgroundColor: "#22c55e",
1563
+ color: "white"
1564
+ }
1565
+ };
1566
+ var ErrorBoundary = class extends Component {
1567
+ constructor(props) {
1568
+ super(props);
1569
+ __publicField(this, "handleReset", () => {
1570
+ this.props.onReset?.();
1571
+ this.setState({
1572
+ hasError: false,
1573
+ error: null,
1574
+ errorInfo: null,
1575
+ copied: false
1576
+ });
1577
+ });
1578
+ __publicField(this, "handleCopyToClipboard", async () => {
1579
+ const text = this.formatError();
1580
+ try {
1581
+ await navigator.clipboard.writeText(text);
1582
+ this.setState({ copied: true });
1583
+ setTimeout(() => this.setState({ copied: false }), 2e3);
1584
+ } catch (err) {
1585
+ console.error("Failed to copy error details:", err);
1586
+ }
1587
+ });
1588
+ this.state = {
1589
+ hasError: false,
1590
+ error: null,
1591
+ errorInfo: null,
1592
+ copied: false
1593
+ };
1594
+ }
1595
+ static getDerivedStateFromError(error) {
1596
+ return { hasError: true, error };
1597
+ }
1598
+ componentDidCatch(error, errorInfo) {
1599
+ this.setState({ errorInfo });
1600
+ this.props.onError?.(error, errorInfo);
1601
+ }
1602
+ formatError() {
1603
+ const { error, errorInfo } = this.state;
1604
+ if (!error) return "";
1605
+ const lines = [
1606
+ "=".repeat(50),
1607
+ "ERROR REPORT",
1608
+ "=".repeat(50),
1609
+ "",
1610
+ `Error: ${error.name}`,
1611
+ `Message: ${error.message}`,
1612
+ "",
1613
+ "Stack Trace:",
1614
+ error.stack || "No stack trace available"
1615
+ ];
1616
+ if (errorInfo?.componentStack) {
1617
+ lines.push("", "Component Stack:", errorInfo.componentStack);
1618
+ }
1619
+ lines.push("", `Timestamp: ${(/* @__PURE__ */ new Date()).toISOString()}`);
1620
+ lines.push(`User Agent: ${typeof navigator !== "undefined" ? navigator.userAgent : "N/A"}`);
1621
+ return lines.join("\n");
1622
+ }
1623
+ getErrorInfo() {
1624
+ return {
1625
+ error: this.state.error,
1626
+ errorInfo: this.state.errorInfo,
1627
+ formattedError: this.formatError(),
1628
+ reset: this.handleReset
1629
+ };
1630
+ }
1631
+ renderDefaultFallback() {
1632
+ const {
1633
+ title = "Something went wrong",
1634
+ subtitle = "An unexpected error occurred",
1635
+ showErrorDetails = true,
1636
+ showCopyButton = true,
1637
+ showRetryButton = true,
1638
+ retryButtonLabel = "Try Again",
1639
+ copyButtonLabel = "Copy Error Details",
1640
+ customButtons = [],
1641
+ containerStyle,
1642
+ errorDetailsStyle
1643
+ } = this.props;
1644
+ const { error, copied } = this.state;
1645
+ const errorInfo = this.getErrorInfo();
1646
+ return /* @__PURE__ */ jsx7("div", { style: { ...defaultStyles.container, ...containerStyle }, children: /* @__PURE__ */ jsxs5("div", { style: defaultStyles.content, children: [
1647
+ /* @__PURE__ */ jsx7("div", { style: defaultStyles.icon, children: "\u26A0\uFE0F" }),
1648
+ /* @__PURE__ */ jsx7("h1", { style: defaultStyles.title, children: title }),
1649
+ /* @__PURE__ */ jsx7("p", { style: defaultStyles.subtitle, children: subtitle }),
1650
+ showErrorDetails && error && /* @__PURE__ */ jsx7("div", { style: { ...defaultStyles.errorBox, ...errorDetailsStyle }, children: /* @__PURE__ */ jsxs5("pre", { style: defaultStyles.errorText, children: [
1651
+ error.name,
1652
+ ": ",
1653
+ error.message,
1654
+ error.stack && `
1655
+
1656
+ ${error.stack.split("\n").slice(1, 5).join("\n")}`
1657
+ ] }) }),
1658
+ /* @__PURE__ */ jsxs5("div", { style: defaultStyles.buttonContainer, children: [
1659
+ showRetryButton && /* @__PURE__ */ jsx7(
1660
+ "button",
1661
+ {
1662
+ onClick: this.handleReset,
1663
+ style: { ...defaultStyles.button, ...defaultStyles.primaryButton },
1664
+ children: retryButtonLabel
1665
+ }
1666
+ ),
1667
+ showCopyButton && /* @__PURE__ */ jsx7(
1668
+ "button",
1669
+ {
1670
+ onClick: this.handleCopyToClipboard,
1671
+ style: {
1672
+ ...defaultStyles.button,
1673
+ ...copied ? defaultStyles.successButton : defaultStyles.secondaryButton
1674
+ },
1675
+ children: copied ? "\u2713 Copied!" : copyButtonLabel
1676
+ }
1677
+ ),
1678
+ customButtons.map((btn, index) => /* @__PURE__ */ jsx7(
1679
+ "button",
1680
+ {
1681
+ onClick: () => btn.onClick(errorInfo),
1682
+ style: { ...defaultStyles.button, ...defaultStyles.secondaryButton, ...btn.style },
1683
+ className: btn.className,
1684
+ children: btn.label
1685
+ },
1686
+ index
1687
+ ))
1688
+ ] })
1689
+ ] }) });
1690
+ }
1691
+ render() {
1692
+ const { hasError } = this.state;
1693
+ const { children, fallback: FallbackComponent, fallbackElement } = this.props;
1694
+ if (hasError) {
1695
+ if (FallbackComponent) {
1696
+ const errorInfo = this.getErrorInfo();
1697
+ return /* @__PURE__ */ jsx7(
1698
+ FallbackComponent,
1699
+ {
1700
+ ...errorInfo,
1701
+ copyToClipboard: this.handleCopyToClipboard
1702
+ }
1703
+ );
1704
+ }
1705
+ if (fallbackElement) {
1706
+ return /* @__PURE__ */ jsx7(Fragment3, { children: fallbackElement });
1707
+ }
1708
+ return this.renderDefaultFallback();
1709
+ }
1710
+ return children;
1711
+ }
1712
+ };
1713
+
1481
1714
  // src/utils/platform.ts
1482
1715
  var isWeb = typeof document !== "undefined" && typeof window !== "undefined";
1483
1716
  var isNative = !isWeb && typeof global !== "undefined";
@@ -1497,18 +1730,19 @@ function isTauriEnv2() {
1497
1730
  }
1498
1731
 
1499
1732
  // src/index.tsx
1500
- import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1501
- function AiAnnotationProvider2({ children }) {
1502
- return /* @__PURE__ */ jsxs5(AiAnnotationProvider, { children: [
1733
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1734
+ function AgentAnnotationProvider2({ children }) {
1735
+ return /* @__PURE__ */ jsxs6(AgentAnnotationProvider, { children: [
1503
1736
  children,
1504
- /* @__PURE__ */ jsx7(Toolbar, {})
1737
+ /* @__PURE__ */ jsx8(Toolbar, {})
1505
1738
  ] });
1506
1739
  }
1507
1740
  export {
1508
- AiAnnotationProvider2 as AiAnnotationProvider,
1741
+ AgentAnnotationProvider2 as AgentAnnotationProvider,
1509
1742
  AnnotationInput,
1510
1743
  AnnotationList,
1511
1744
  Draggable,
1745
+ ErrorBoundary,
1512
1746
  Highlighter,
1513
1747
  Toolbar,
1514
1748
  captureScreenshot,
@@ -1519,6 +1753,6 @@ export {
1519
1753
  isNative,
1520
1754
  isTauriEnv2 as isTauriEnv,
1521
1755
  isWeb,
1522
- useAiAnnotation
1756
+ useAgentAnnotation
1523
1757
  };
1524
1758
  //# sourceMappingURL=index.js.map