@opensite/hooks 2.0.0 → 2.0.3

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 (96) hide show
  1. package/README.md +12 -9
  2. package/dist/browser/opensite-hooks.umd.cjs +1 -1
  3. package/dist/browser/opensite-hooks.umd.js +1 -1
  4. package/dist/browser/opensite-hooks.umd.js.map +1 -1
  5. package/dist/core/index.cjs +7 -0
  6. package/dist/core/index.d.ts +13 -0
  7. package/dist/core/index.js +7 -0
  8. package/dist/core/useBoolean.cjs +4 -2
  9. package/dist/core/useBoolean.js +4 -2
  10. package/dist/core/useMap.cjs +6 -2
  11. package/dist/core/useMap.js +6 -2
  12. package/dist/core/useOnClickOutside.cjs +5 -1
  13. package/dist/core/useOnClickOutside.js +5 -1
  14. package/dist/core/useOpenGraphExtractor.cjs +59 -0
  15. package/dist/core/useOpenGraphExtractor.d.ts +64 -0
  16. package/dist/core/useOpenGraphExtractor.js +59 -0
  17. package/dist/core/usePrevious.cjs +7 -2
  18. package/dist/core/usePrevious.js +7 -2
  19. package/dist/core/useWebsiteExtractorBase.cjs +153 -0
  20. package/dist/core/useWebsiteExtractorBase.d.ts +9 -0
  21. package/dist/core/useWebsiteExtractorBase.js +153 -0
  22. package/dist/core/useWebsiteLinksExtractor.cjs +16 -0
  23. package/dist/core/useWebsiteLinksExtractor.d.ts +14 -0
  24. package/dist/core/useWebsiteLinksExtractor.js +16 -0
  25. package/dist/core/useWebsiteMetaExtractor.cjs +20 -0
  26. package/dist/core/useWebsiteMetaExtractor.d.ts +12 -0
  27. package/dist/core/useWebsiteMetaExtractor.js +20 -0
  28. package/dist/core/useWebsiteRssExtractor.cjs +15 -0
  29. package/dist/core/useWebsiteRssExtractor.d.ts +12 -0
  30. package/dist/core/useWebsiteRssExtractor.js +15 -0
  31. package/dist/core/useWebsiteSchemaExtractor.cjs +15 -0
  32. package/dist/core/useWebsiteSchemaExtractor.d.ts +11 -0
  33. package/dist/core/useWebsiteSchemaExtractor.js +15 -0
  34. package/dist/core/websiteExtractorService.cjs +66 -0
  35. package/dist/core/websiteExtractorService.d.ts +3 -0
  36. package/dist/core/websiteExtractorService.js +66 -0
  37. package/dist/core/websiteExtractorTypes.cjs +25 -0
  38. package/dist/core/websiteExtractorTypes.d.ts +65 -0
  39. package/dist/core/websiteExtractorTypes.js +25 -0
  40. package/package.json +36 -1
  41. package/dist/hooks/index.cjs +0 -16
  42. package/dist/hooks/index.d.ts +0 -24
  43. package/dist/hooks/index.js +0 -16
  44. package/dist/hooks/useBoolean.cjs +0 -1
  45. package/dist/hooks/useBoolean.d.ts +0 -2
  46. package/dist/hooks/useBoolean.js +0 -1
  47. package/dist/hooks/useCopyToClipboard.cjs +0 -1
  48. package/dist/hooks/useCopyToClipboard.d.ts +0 -2
  49. package/dist/hooks/useCopyToClipboard.js +0 -1
  50. package/dist/hooks/useDebounceCallback.cjs +0 -1
  51. package/dist/hooks/useDebounceCallback.d.ts +0 -2
  52. package/dist/hooks/useDebounceCallback.js +0 -1
  53. package/dist/hooks/useDebounceValue.cjs +0 -1
  54. package/dist/hooks/useDebounceValue.d.ts +0 -2
  55. package/dist/hooks/useDebounceValue.js +0 -1
  56. package/dist/hooks/useEventListener.cjs +0 -1
  57. package/dist/hooks/useEventListener.d.ts +0 -1
  58. package/dist/hooks/useEventListener.js +0 -1
  59. package/dist/hooks/useHover.cjs +0 -1
  60. package/dist/hooks/useHover.d.ts +0 -1
  61. package/dist/hooks/useHover.js +0 -1
  62. package/dist/hooks/useIsClient.cjs +0 -1
  63. package/dist/hooks/useIsClient.d.ts +0 -1
  64. package/dist/hooks/useIsClient.js +0 -1
  65. package/dist/hooks/useIsomorphicLayoutEffect.cjs +0 -1
  66. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +0 -1
  67. package/dist/hooks/useIsomorphicLayoutEffect.js +0 -1
  68. package/dist/hooks/useLocalStorage.cjs +0 -1
  69. package/dist/hooks/useLocalStorage.d.ts +0 -2
  70. package/dist/hooks/useLocalStorage.js +0 -1
  71. package/dist/hooks/useMap.cjs +0 -1
  72. package/dist/hooks/useMap.d.ts +0 -2
  73. package/dist/hooks/useMap.js +0 -1
  74. package/dist/hooks/useMediaQuery.cjs +0 -1
  75. package/dist/hooks/useMediaQuery.d.ts +0 -2
  76. package/dist/hooks/useMediaQuery.js +0 -1
  77. package/dist/hooks/useOnClickOutside.cjs +0 -1
  78. package/dist/hooks/useOnClickOutside.d.ts +0 -1
  79. package/dist/hooks/useOnClickOutside.js +0 -1
  80. package/dist/hooks/usePrevious.cjs +0 -1
  81. package/dist/hooks/usePrevious.d.ts +0 -1
  82. package/dist/hooks/usePrevious.js +0 -1
  83. package/dist/hooks/useResizeObserver.cjs +0 -1
  84. package/dist/hooks/useResizeObserver.d.ts +0 -1
  85. package/dist/hooks/useResizeObserver.js +0 -1
  86. package/dist/hooks/useSessionStorage.cjs +0 -1
  87. package/dist/hooks/useSessionStorage.d.ts +0 -2
  88. package/dist/hooks/useSessionStorage.js +0 -1
  89. package/dist/hooks/useThrottle.cjs +0 -1
  90. package/dist/hooks/useThrottle.d.ts +0 -2
  91. package/dist/hooks/useThrottle.js +0 -1
  92. package/dist/test/setup.cjs +0 -98
  93. package/dist/test/setup.d.ts +0 -5
  94. package/dist/test/setup.js +0 -98
  95. package/dist/test/utils.cjs +0 -73
  96. package/dist/test/utils.js +0 -73
@@ -1,98 +0,0 @@
1
- /**
2
- * Vitest test setup file
3
- * Runs before each test file
4
- */
5
- import { cleanup } from "@testing-library/react";
6
- import { afterEach, vi } from "vitest";
7
- // Cleanup after each test case (unmounts React trees that were mounted with render)
8
- afterEach(() => {
9
- cleanup();
10
- });
11
- // Mock window.matchMedia for useMediaQuery tests
12
- Object.defineProperty(window, "matchMedia", {
13
- writable: true,
14
- value: vi.fn().mockImplementation((query) => ({
15
- matches: false,
16
- media: query,
17
- onchange: null,
18
- addListener: vi.fn(), // deprecated
19
- removeListener: vi.fn(), // deprecated
20
- addEventListener: vi.fn(),
21
- removeEventListener: vi.fn(),
22
- dispatchEvent: vi.fn(),
23
- })),
24
- });
25
- // Mock ResizeObserver for useResizeObserver tests
26
- class MockResizeObserver {
27
- callback;
28
- constructor(callback) {
29
- this.callback = callback;
30
- }
31
- observe = vi.fn();
32
- unobserve = vi.fn();
33
- disconnect = vi.fn();
34
- }
35
- Object.defineProperty(window, "ResizeObserver", {
36
- writable: true,
37
- value: MockResizeObserver,
38
- });
39
- // Mock clipboard API for useCopyToClipboard tests
40
- Object.defineProperty(navigator, "clipboard", {
41
- writable: true,
42
- value: {
43
- writeText: vi.fn().mockResolvedValue(undefined),
44
- readText: vi.fn().mockResolvedValue(""),
45
- },
46
- });
47
- // Mock localStorage
48
- const localStorageMock = (() => {
49
- let store = {};
50
- return {
51
- getItem: vi.fn((key) => store[key] ?? null),
52
- setItem: vi.fn((key, value) => {
53
- store[key] = value;
54
- }),
55
- removeItem: vi.fn((key) => {
56
- delete store[key];
57
- }),
58
- clear: vi.fn(() => {
59
- store = {};
60
- }),
61
- get length() {
62
- return Object.keys(store).length;
63
- },
64
- key: vi.fn((index) => Object.keys(store)[index] ?? null),
65
- };
66
- })();
67
- Object.defineProperty(window, "localStorage", {
68
- value: localStorageMock,
69
- });
70
- // Mock sessionStorage (same as localStorage)
71
- const sessionStorageMock = (() => {
72
- let store = {};
73
- return {
74
- getItem: vi.fn((key) => store[key] ?? null),
75
- setItem: vi.fn((key, value) => {
76
- store[key] = value;
77
- }),
78
- removeItem: vi.fn((key) => {
79
- delete store[key];
80
- }),
81
- clear: vi.fn(() => {
82
- store = {};
83
- }),
84
- get length() {
85
- return Object.keys(store).length;
86
- },
87
- key: vi.fn((index) => Object.keys(store)[index] ?? null),
88
- };
89
- })();
90
- Object.defineProperty(window, "sessionStorage", {
91
- value: sessionStorageMock,
92
- });
93
- // Clear mocks between tests
94
- afterEach(() => {
95
- vi.clearAllMocks();
96
- localStorageMock.clear();
97
- sessionStorageMock.clear();
98
- });
@@ -1,5 +0,0 @@
1
- /**
2
- * Vitest test setup file
3
- * Runs before each test file
4
- */
5
- export {};
@@ -1,98 +0,0 @@
1
- /**
2
- * Vitest test setup file
3
- * Runs before each test file
4
- */
5
- import { cleanup } from "@testing-library/react";
6
- import { afterEach, vi } from "vitest";
7
- // Cleanup after each test case (unmounts React trees that were mounted with render)
8
- afterEach(() => {
9
- cleanup();
10
- });
11
- // Mock window.matchMedia for useMediaQuery tests
12
- Object.defineProperty(window, "matchMedia", {
13
- writable: true,
14
- value: vi.fn().mockImplementation((query) => ({
15
- matches: false,
16
- media: query,
17
- onchange: null,
18
- addListener: vi.fn(), // deprecated
19
- removeListener: vi.fn(), // deprecated
20
- addEventListener: vi.fn(),
21
- removeEventListener: vi.fn(),
22
- dispatchEvent: vi.fn(),
23
- })),
24
- });
25
- // Mock ResizeObserver for useResizeObserver tests
26
- class MockResizeObserver {
27
- callback;
28
- constructor(callback) {
29
- this.callback = callback;
30
- }
31
- observe = vi.fn();
32
- unobserve = vi.fn();
33
- disconnect = vi.fn();
34
- }
35
- Object.defineProperty(window, "ResizeObserver", {
36
- writable: true,
37
- value: MockResizeObserver,
38
- });
39
- // Mock clipboard API for useCopyToClipboard tests
40
- Object.defineProperty(navigator, "clipboard", {
41
- writable: true,
42
- value: {
43
- writeText: vi.fn().mockResolvedValue(undefined),
44
- readText: vi.fn().mockResolvedValue(""),
45
- },
46
- });
47
- // Mock localStorage
48
- const localStorageMock = (() => {
49
- let store = {};
50
- return {
51
- getItem: vi.fn((key) => store[key] ?? null),
52
- setItem: vi.fn((key, value) => {
53
- store[key] = value;
54
- }),
55
- removeItem: vi.fn((key) => {
56
- delete store[key];
57
- }),
58
- clear: vi.fn(() => {
59
- store = {};
60
- }),
61
- get length() {
62
- return Object.keys(store).length;
63
- },
64
- key: vi.fn((index) => Object.keys(store)[index] ?? null),
65
- };
66
- })();
67
- Object.defineProperty(window, "localStorage", {
68
- value: localStorageMock,
69
- });
70
- // Mock sessionStorage (same as localStorage)
71
- const sessionStorageMock = (() => {
72
- let store = {};
73
- return {
74
- getItem: vi.fn((key) => store[key] ?? null),
75
- setItem: vi.fn((key, value) => {
76
- store[key] = value;
77
- }),
78
- removeItem: vi.fn((key) => {
79
- delete store[key];
80
- }),
81
- clear: vi.fn(() => {
82
- store = {};
83
- }),
84
- get length() {
85
- return Object.keys(store).length;
86
- },
87
- key: vi.fn((index) => Object.keys(store)[index] ?? null),
88
- };
89
- })();
90
- Object.defineProperty(window, "sessionStorage", {
91
- value: sessionStorageMock,
92
- });
93
- // Clear mocks between tests
94
- afterEach(() => {
95
- vi.clearAllMocks();
96
- localStorageMock.clear();
97
- sessionStorageMock.clear();
98
- });
@@ -1,73 +0,0 @@
1
- /**
2
- * Test utilities for React hook testing
3
- */
4
- import { render } from "@testing-library/react";
5
- /**
6
- * Custom render function that wraps components with providers if needed
7
- */
8
- function customRender(ui, options) {
9
- return render(ui, { ...options });
10
- }
11
- // Re-export everything from testing-library
12
- export * from "@testing-library/react";
13
- // Override render with our custom version
14
- export { customRender as render };
15
- /**
16
- * Helper to wait for a specific amount of time
17
- * Useful for testing debounce/throttle hooks
18
- */
19
- export function wait(ms) {
20
- return new Promise((resolve) => setTimeout(resolve, ms));
21
- }
22
- /**
23
- * Helper to mock matchMedia with specific matches value
24
- */
25
- export function mockMatchMedia(matches) {
26
- Object.defineProperty(window, "matchMedia", {
27
- writable: true,
28
- value: (query) => ({
29
- matches,
30
- media: query,
31
- onchange: null,
32
- addListener: () => { },
33
- removeListener: () => { },
34
- addEventListener: () => { },
35
- removeEventListener: () => { },
36
- dispatchEvent: () => false,
37
- }),
38
- });
39
- }
40
- /**
41
- * Helper to create a mock storage event
42
- */
43
- export function createStorageEvent(key, newValue, storageArea = localStorage) {
44
- return new StorageEvent("storage", {
45
- key,
46
- newValue,
47
- oldValue: null,
48
- storageArea,
49
- url: window.location.href,
50
- });
51
- }
52
- /**
53
- * Helper to create a mock resize observer entry
54
- */
55
- export function createResizeObserverEntry(target, width, height) {
56
- return {
57
- target,
58
- contentRect: {
59
- width,
60
- height,
61
- top: 0,
62
- right: width,
63
- bottom: height,
64
- left: 0,
65
- x: 0,
66
- y: 0,
67
- toJSON: () => ({}),
68
- },
69
- borderBoxSize: [{ blockSize: height, inlineSize: width }],
70
- contentBoxSize: [{ blockSize: height, inlineSize: width }],
71
- devicePixelContentBoxSize: [{ blockSize: height, inlineSize: width }],
72
- };
73
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * Test utilities for React hook testing
3
- */
4
- import { render } from "@testing-library/react";
5
- /**
6
- * Custom render function that wraps components with providers if needed
7
- */
8
- function customRender(ui, options) {
9
- return render(ui, { ...options });
10
- }
11
- // Re-export everything from testing-library
12
- export * from "@testing-library/react";
13
- // Override render with our custom version
14
- export { customRender as render };
15
- /**
16
- * Helper to wait for a specific amount of time
17
- * Useful for testing debounce/throttle hooks
18
- */
19
- export function wait(ms) {
20
- return new Promise((resolve) => setTimeout(resolve, ms));
21
- }
22
- /**
23
- * Helper to mock matchMedia with specific matches value
24
- */
25
- export function mockMatchMedia(matches) {
26
- Object.defineProperty(window, "matchMedia", {
27
- writable: true,
28
- value: (query) => ({
29
- matches,
30
- media: query,
31
- onchange: null,
32
- addListener: () => { },
33
- removeListener: () => { },
34
- addEventListener: () => { },
35
- removeEventListener: () => { },
36
- dispatchEvent: () => false,
37
- }),
38
- });
39
- }
40
- /**
41
- * Helper to create a mock storage event
42
- */
43
- export function createStorageEvent(key, newValue, storageArea = localStorage) {
44
- return new StorageEvent("storage", {
45
- key,
46
- newValue,
47
- oldValue: null,
48
- storageArea,
49
- url: window.location.href,
50
- });
51
- }
52
- /**
53
- * Helper to create a mock resize observer entry
54
- */
55
- export function createResizeObserverEntry(target, width, height) {
56
- return {
57
- target,
58
- contentRect: {
59
- width,
60
- height,
61
- top: 0,
62
- right: width,
63
- bottom: height,
64
- left: 0,
65
- x: 0,
66
- y: 0,
67
- toJSON: () => ({}),
68
- },
69
- borderBoxSize: [{ blockSize: height, inlineSize: width }],
70
- contentBoxSize: [{ blockSize: height, inlineSize: width }],
71
- devicePixelContentBoxSize: [{ blockSize: height, inlineSize: width }],
72
- };
73
- }