@squeletteapp/widget-react 0.1.1 → 1.0.0

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.
@@ -1,27 +0,0 @@
1
- import * as React from 'react';
2
- import { type WidgetOptions } from './hooks';
3
- export interface FeedbackWidgetProps extends Omit<WidgetOptions, 'buttonSelector'> {
4
- workspaceSlug: string;
5
- boardSlug?: string;
6
- children: React.ReactNode;
7
- className?: string;
8
- asChild?: boolean;
9
- onOpenChange?: (isOpen: boolean) => void;
10
- }
11
- export interface RoadmapWidgetProps extends Omit<WidgetOptions, 'buttonSelector'> {
12
- workspaceSlug: string;
13
- boardSlug: string;
14
- children: React.ReactNode;
15
- className?: string;
16
- asChild?: boolean;
17
- }
18
- export interface ChangelogWidgetProps extends Omit<WidgetOptions, 'buttonSelector'> {
19
- workspaceSlug: string;
20
- children: React.ReactNode;
21
- className?: string;
22
- asChild?: boolean;
23
- onOpenChange?: (isOpen: boolean) => void;
24
- }
25
- export declare function FeedbackWidget({ workspaceSlug, boardSlug, children, className, asChild, onOpenChange, ...options }: FeedbackWidgetProps): import("react/jsx-runtime").JSX.Element;
26
- export declare function RoadmapWidget({ workspaceSlug, boardSlug, children, className, asChild, ...options }: RoadmapWidgetProps): import("react/jsx-runtime").JSX.Element;
27
- export declare function ChangelogWidget({ workspaceSlug, children, className, asChild, onOpenChange, ...options }: ChangelogWidgetProps): import("react/jsx-runtime").JSX.Element;
@@ -1,39 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Slot } from '@radix-ui/react-slot';
3
- import * as React from 'react';
4
- import { useChangelogWidget, useFeedbackWidget, useRoadmapWidget, } from './hooks';
5
- export function FeedbackWidget({ workspaceSlug, boardSlug, children, className, asChild = false, onOpenChange, ...options }) {
6
- const buttonId = React.useId();
7
- useFeedbackWidget(workspaceSlug, boardSlug, {
8
- ...options,
9
- buttonSelector: `#${buttonId}`,
10
- onOpenChange,
11
- });
12
- if (asChild) {
13
- return React.createElement(Slot, { className, id: buttonId }, children);
14
- }
15
- return (_jsx("button", { className: className, id: buttonId, type: "button", children: children }));
16
- }
17
- export function RoadmapWidget({ workspaceSlug, boardSlug, children, className, asChild = false, ...options }) {
18
- const buttonId = React.useId();
19
- useRoadmapWidget(workspaceSlug, boardSlug, {
20
- ...options,
21
- buttonSelector: `#${buttonId}`,
22
- });
23
- if (asChild) {
24
- return React.createElement(Slot, { className, id: buttonId }, children);
25
- }
26
- return (_jsx("button", { className: className, id: buttonId, type: "button", children: children }));
27
- }
28
- export function ChangelogWidget({ workspaceSlug, children, className, asChild = false, onOpenChange, ...options }) {
29
- const buttonId = React.useId();
30
- useChangelogWidget(workspaceSlug, {
31
- ...options,
32
- buttonSelector: `#${buttonId}`,
33
- onOpenChange,
34
- });
35
- if (asChild) {
36
- return React.createElement(Slot, { className, id: buttonId }, children);
37
- }
38
- return (_jsx("button", { className: className, id: buttonId, type: "button", children: children }));
39
- }
package/dist/hooks.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export interface WidgetOptions {
2
- buttonSelector: string;
3
- position?: 'top' | 'bottom' | 'left' | 'right';
4
- theme?: string;
5
- onLoad?: () => void;
6
- onOpenChange?: (isOpen: boolean) => void;
7
- }
8
- export interface WidgetInstance {
9
- destroy: () => void;
10
- }
11
- export declare function useFeedbackWidget(workspaceSlug: string, boardSlug: string | undefined, options: WidgetOptions): WidgetInstance | null;
12
- export declare function useRoadmapWidget(workspaceSlug: string, boardSlug: string, options: WidgetOptions): WidgetInstance | null;
13
- export declare function useChangelogWidget(workspaceSlug: string, options: WidgetOptions): WidgetInstance | null;
14
- export declare function useWidget(options: {
15
- url: string;
16
- buttonSelector: string;
17
- position?: 'top' | 'bottom' | 'left' | 'right';
18
- onLoad?: () => void;
19
- onOpenChange?: (isOpen: boolean) => void;
20
- }): WidgetInstance | null;
package/dist/hooks.js DELETED
@@ -1,143 +0,0 @@
1
- import { createChangelogWidget, createFeedbackWidget, createRoadmapWidget, createWidget, } from '@squeletteapp/widget';
2
- import { useCallback, useEffect, useRef } from 'react';
3
- export function useFeedbackWidget(workspaceSlug, boardSlug, options) {
4
- const widgetRef = useRef(null);
5
- const onOpenChangeRef = useRef(options.onOpenChange);
6
- // Always keep the latest onOpenChange callback
7
- onOpenChangeRef.current = options.onOpenChange;
8
- const initWidget = useCallback(() => {
9
- if (widgetRef.current) {
10
- widgetRef.current.destroy();
11
- }
12
- const element = document.querySelector(options.buttonSelector);
13
- if (!element) {
14
- return null;
15
- }
16
- widgetRef.current = createFeedbackWidget(workspaceSlug, boardSlug, {
17
- ...options,
18
- onOpenChange: onOpenChangeRef.current
19
- ? (isOpen) => { var _a; return (_a = onOpenChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onOpenChangeRef, isOpen); }
20
- : undefined,
21
- });
22
- return widgetRef.current;
23
- }, [
24
- workspaceSlug,
25
- boardSlug,
26
- options.buttonSelector,
27
- options.position,
28
- options.theme,
29
- options.onLoad,
30
- ]);
31
- useEffect(() => {
32
- // Use requestAnimationFrame to ensure DOM is ready
33
- const frame = requestAnimationFrame(() => {
34
- const widget = initWidget();
35
- widgetRef.current = widget;
36
- });
37
- return () => {
38
- cancelAnimationFrame(frame);
39
- if (widgetRef.current) {
40
- widgetRef.current.destroy();
41
- }
42
- };
43
- }, [initWidget]);
44
- return widgetRef.current;
45
- }
46
- export function useRoadmapWidget(workspaceSlug, boardSlug, options) {
47
- const widgetRef = useRef(null);
48
- const initWidget = useCallback(() => {
49
- if (widgetRef.current) {
50
- widgetRef.current.destroy();
51
- }
52
- const element = document.querySelector(options.buttonSelector);
53
- if (!element) {
54
- return null;
55
- }
56
- widgetRef.current = createRoadmapWidget(workspaceSlug, boardSlug, options);
57
- return widgetRef.current;
58
- }, [workspaceSlug, boardSlug, options]);
59
- useEffect(() => {
60
- // Use requestAnimationFrame to ensure DOM is ready
61
- const frame = requestAnimationFrame(() => {
62
- const widget = initWidget();
63
- widgetRef.current = widget;
64
- });
65
- return () => {
66
- cancelAnimationFrame(frame);
67
- if (widgetRef.current) {
68
- widgetRef.current.destroy();
69
- }
70
- };
71
- }, [initWidget]);
72
- return widgetRef.current;
73
- }
74
- export function useChangelogWidget(workspaceSlug, options) {
75
- const widgetRef = useRef(null);
76
- const onOpenChangeRef = useRef(options.onOpenChange);
77
- // Always keep the latest onOpenChange callback
78
- onOpenChangeRef.current = options.onOpenChange;
79
- const initWidget = useCallback(() => {
80
- if (widgetRef.current) {
81
- widgetRef.current.destroy();
82
- }
83
- const element = document.querySelector(options.buttonSelector);
84
- if (!element) {
85
- return null;
86
- }
87
- widgetRef.current = createChangelogWidget(workspaceSlug, {
88
- ...options,
89
- onOpenChange: onOpenChangeRef.current
90
- ? (isOpen) => { var _a; return (_a = onOpenChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onOpenChangeRef, isOpen); }
91
- : undefined,
92
- });
93
- return widgetRef.current;
94
- }, [
95
- workspaceSlug,
96
- options.buttonSelector,
97
- options.position,
98
- options.theme,
99
- options.onLoad,
100
- ]);
101
- useEffect(() => {
102
- // Use requestAnimationFrame to ensure DOM is ready
103
- const frame = requestAnimationFrame(() => {
104
- const widget = initWidget();
105
- widgetRef.current = widget;
106
- });
107
- return () => {
108
- cancelAnimationFrame(frame);
109
- if (widgetRef.current) {
110
- widgetRef.current.destroy();
111
- }
112
- };
113
- }, [initWidget]);
114
- return widgetRef.current;
115
- }
116
- export function useWidget(options) {
117
- const widgetRef = useRef(null);
118
- const initWidget = useCallback(() => {
119
- if (widgetRef.current) {
120
- widgetRef.current.destroy();
121
- }
122
- const element = document.querySelector(options.buttonSelector);
123
- if (!element) {
124
- return null;
125
- }
126
- widgetRef.current = createWidget(options);
127
- return widgetRef.current;
128
- }, [options]);
129
- useEffect(() => {
130
- // Use requestAnimationFrame to ensure DOM is ready
131
- const frame = requestAnimationFrame(() => {
132
- const widget = initWidget();
133
- widgetRef.current = widget;
134
- });
135
- return () => {
136
- cancelAnimationFrame(frame);
137
- if (widgetRef.current) {
138
- widgetRef.current.destroy();
139
- }
140
- };
141
- }, [initWidget]);
142
- return widgetRef.current;
143
- }