@yargram/react 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.
- package/.storybook/main.ts +21 -0
- package/.storybook/preview.ts +21 -0
- package/dist/components/LogWindow/LogEntryRow.d.ts +8 -0
- package/dist/components/LogWindow/LogEntryRow.d.ts.map +1 -0
- package/dist/components/LogWindow/LogEntryRow.js +14 -0
- package/dist/components/LogWindow/LogWindow.d.ts +41 -0
- package/dist/components/LogWindow/LogWindow.d.ts.map +1 -0
- package/dist/components/LogWindow/LogWindow.js +144 -0
- package/dist/components/LogWindow/LogWindow.stories.d.ts +29 -0
- package/dist/components/LogWindow/LogWindow.stories.d.ts.map +1 -0
- package/dist/components/LogWindow/LogWindow.stories.js +183 -0
- package/dist/components/LogWindow/LogWindow.test.d.ts +2 -0
- package/dist/components/LogWindow/LogWindow.test.d.ts.map +1 -0
- package/dist/components/LogWindow/LogWindow.test.js +61 -0
- package/dist/components/LogWindow/LogWindowEscapeDemo.d.ts +12 -0
- package/dist/components/LogWindow/LogWindowEscapeDemo.d.ts.map +1 -0
- package/dist/components/LogWindow/LogWindowEscapeDemo.js +56 -0
- package/dist/components/LogWindow/NetworkEntryRow.d.ts +8 -0
- package/dist/components/LogWindow/NetworkEntryRow.d.ts.map +1 -0
- package/dist/components/LogWindow/NetworkEntryRow.js +32 -0
- package/dist/components/LogWindow/index.d.ts +7 -0
- package/dist/components/LogWindow/index.d.ts.map +1 -0
- package/dist/components/LogWindow/index.js +4 -0
- package/dist/components/LogWindow/types.d.ts +36 -0
- package/dist/components/LogWindow/types.d.ts.map +1 -0
- package/dist/components/LogWindow/types.js +1 -0
- package/dist/components/LoginWindow/LoginForm.d.ts +11 -0
- package/dist/components/LoginWindow/LoginForm.d.ts.map +1 -0
- package/dist/components/LoginWindow/LoginForm.js +28 -0
- package/dist/components/LoginWindow/LoginForm.test.d.ts +2 -0
- package/dist/components/LoginWindow/LoginForm.test.d.ts.map +1 -0
- package/dist/components/LoginWindow/LoginForm.test.js +34 -0
- package/dist/components/LoginWindow/LoginWindow.d.ts +15 -0
- package/dist/components/LoginWindow/LoginWindow.d.ts.map +1 -0
- package/dist/components/LoginWindow/LoginWindow.js +27 -0
- package/dist/components/LoginWindow/index.d.ts +3 -0
- package/dist/components/LoginWindow/index.d.ts.map +1 -0
- package/dist/components/LoginWindow/index.js +1 -0
- package/dist/contexts/ApiContext.d.ts +35 -0
- package/dist/contexts/ApiContext.d.ts.map +1 -0
- package/dist/contexts/ApiContext.js +82 -0
- package/dist/contexts/ApiContext.test.d.ts +2 -0
- package/dist/contexts/ApiContext.test.d.ts.map +1 -0
- package/dist/contexts/ApiContext.test.js +45 -0
- package/dist/contexts/PrinterContext.d.ts +12 -0
- package/dist/contexts/PrinterContext.d.ts.map +1 -0
- package/dist/contexts/PrinterContext.js +17 -0
- package/dist/contexts/PrinterContext.test.d.ts +2 -0
- package/dist/contexts/PrinterContext.test.d.ts.map +1 -0
- package/dist/contexts/PrinterContext.test.js +19 -0
- package/dist/contexts/YahmanContext.d.ts +69 -0
- package/dist/contexts/YahmanContext.d.ts.map +1 -0
- package/dist/contexts/YahmanContext.js +414 -0
- package/dist/contexts/YahmanContext.stories.d.ts +16 -0
- package/dist/contexts/YahmanContext.stories.d.ts.map +1 -0
- package/dist/contexts/YahmanContext.stories.js +64 -0
- package/dist/contexts/YargramContext.d.ts +69 -0
- package/dist/contexts/YargramContext.d.ts.map +1 -0
- package/dist/contexts/YargramContext.js +414 -0
- package/dist/contexts/YargramContext.stories.d.ts +16 -0
- package/dist/contexts/YargramContext.stories.d.ts.map +1 -0
- package/dist/contexts/YargramContext.stories.js +64 -0
- package/dist/contexts/YargramContext.test.d.ts +2 -0
- package/dist/contexts/YargramContext.test.d.ts.map +1 -0
- package/dist/contexts/YargramContext.test.js +54 -0
- package/dist/hooks/useLogWindowShortcut.d.ts +24 -0
- package/dist/hooks/useLogWindowShortcut.d.ts.map +1 -0
- package/dist/hooks/useLogWindowShortcut.js +61 -0
- package/dist/hooks/useLogWindowShortcut.test.d.ts +2 -0
- package/dist/hooks/useLogWindowShortcut.test.d.ts.map +1 -0
- package/dist/hooks/useLogWindowShortcut.test.js +93 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/test/setup.d.ts +2 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +1 -0
- package/package.json +49 -0
- package/src/components/LogWindow/LogEntryRow.tsx +38 -0
- package/src/components/LogWindow/LogWindow.css +614 -0
- package/src/components/LogWindow/LogWindow.stories.tsx +206 -0
- package/src/components/LogWindow/LogWindow.test.tsx +68 -0
- package/src/components/LogWindow/LogWindow.tsx +379 -0
- package/src/components/LogWindow/LogWindowEscapeDemo.tsx +100 -0
- package/src/components/LogWindow/NetworkEntryRow.tsx +102 -0
- package/src/components/LogWindow/index.ts +13 -0
- package/src/components/LogWindow/types.ts +40 -0
- package/src/components/LoginWindow/LoginForm.test.tsx +38 -0
- package/src/components/LoginWindow/LoginForm.tsx +78 -0
- package/src/components/LoginWindow/LoginWindow.css +198 -0
- package/src/components/LoginWindow/LoginWindow.tsx +90 -0
- package/src/components/LoginWindow/index.ts +2 -0
- package/src/contexts/ApiContext.test.tsx +68 -0
- package/src/contexts/ApiContext.tsx +155 -0
- package/src/contexts/PrinterContext.test.tsx +37 -0
- package/src/contexts/PrinterContext.tsx +35 -0
- package/src/contexts/YargramContext.stories.tsx +148 -0
- package/src/contexts/YargramContext.test.tsx +105 -0
- package/src/contexts/YargramContext.tsx +676 -0
- package/src/hooks/useLogWindowShortcut.test.ts +111 -0
- package/src/hooks/useLogWindowShortcut.ts +96 -0
- package/src/index.ts +14 -0
- package/src/test/setup.ts +1 -0
- package/tsconfig.json +16 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { renderHook, act } from '@testing-library/react';
|
|
3
|
+
import { useLogWindowShortcut } from './useLogWindowShortcut';
|
|
4
|
+
describe('useLogWindowShortcut', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
vi.useFakeTimers();
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.useRealTimers();
|
|
10
|
+
});
|
|
11
|
+
it('returns isOpen false initially', () => {
|
|
12
|
+
const { result } = renderHook(() => useLogWindowShortcut());
|
|
13
|
+
expect(result.current.isOpen).toBe(false);
|
|
14
|
+
expect(result.current.escapeCount).toBe(0);
|
|
15
|
+
});
|
|
16
|
+
it('open() sets isOpen to true', () => {
|
|
17
|
+
const { result } = renderHook(() => useLogWindowShortcut());
|
|
18
|
+
act(() => {
|
|
19
|
+
result.current.open();
|
|
20
|
+
});
|
|
21
|
+
expect(result.current.isOpen).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it('close() sets isOpen to false', () => {
|
|
24
|
+
const { result } = renderHook(() => useLogWindowShortcut());
|
|
25
|
+
act(() => {
|
|
26
|
+
result.current.open();
|
|
27
|
+
});
|
|
28
|
+
act(() => {
|
|
29
|
+
result.current.close();
|
|
30
|
+
});
|
|
31
|
+
expect(result.current.isOpen).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
it('toggle() flips isOpen', () => {
|
|
34
|
+
const { result } = renderHook(() => useLogWindowShortcut());
|
|
35
|
+
expect(result.current.isOpen).toBe(false);
|
|
36
|
+
act(() => {
|
|
37
|
+
result.current.toggle();
|
|
38
|
+
});
|
|
39
|
+
expect(result.current.isOpen).toBe(true);
|
|
40
|
+
act(() => {
|
|
41
|
+
result.current.toggle();
|
|
42
|
+
});
|
|
43
|
+
expect(result.current.isOpen).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
it('opening after threshold Escape key presses', () => {
|
|
46
|
+
const { result } = renderHook(() => useLogWindowShortcut({ escapeCount: 3, resetAfterMs: 2000 }));
|
|
47
|
+
const dispatchEscape = () => {
|
|
48
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
|
49
|
+
};
|
|
50
|
+
expect(result.current.isOpen).toBe(false);
|
|
51
|
+
act(() => {
|
|
52
|
+
dispatchEscape();
|
|
53
|
+
});
|
|
54
|
+
expect(result.current.escapeCount).toBe(1);
|
|
55
|
+
act(() => {
|
|
56
|
+
dispatchEscape();
|
|
57
|
+
});
|
|
58
|
+
expect(result.current.escapeCount).toBe(2);
|
|
59
|
+
act(() => {
|
|
60
|
+
dispatchEscape();
|
|
61
|
+
});
|
|
62
|
+
expect(result.current.isOpen).toBe(true);
|
|
63
|
+
expect(result.current.escapeCount).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
it('resets escape count after resetAfterMs', () => {
|
|
66
|
+
const { result } = renderHook(() => useLogWindowShortcut({ escapeCount: 5, resetAfterMs: 500 }));
|
|
67
|
+
const dispatchEscape = () => {
|
|
68
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
|
69
|
+
};
|
|
70
|
+
act(() => {
|
|
71
|
+
dispatchEscape();
|
|
72
|
+
dispatchEscape();
|
|
73
|
+
});
|
|
74
|
+
expect(result.current.escapeCount).toBe(2);
|
|
75
|
+
act(() => {
|
|
76
|
+
vi.advanceTimersByTime(600);
|
|
77
|
+
});
|
|
78
|
+
expect(result.current.escapeCount).toBe(0);
|
|
79
|
+
});
|
|
80
|
+
it('calls onTrigger when provided and threshold reached', () => {
|
|
81
|
+
const onTrigger = vi.fn();
|
|
82
|
+
const { result } = renderHook(() => useLogWindowShortcut({ escapeCount: 2, onTrigger }));
|
|
83
|
+
const dispatchEscape = () => {
|
|
84
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
|
85
|
+
};
|
|
86
|
+
act(() => {
|
|
87
|
+
dispatchEscape();
|
|
88
|
+
dispatchEscape();
|
|
89
|
+
});
|
|
90
|
+
expect(onTrigger).toHaveBeenCalledTimes(1);
|
|
91
|
+
expect(result.current.isOpen).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useApi, type RestApiContextValue, type GraphqlApiContextValue, } from './contexts/ApiContext';
|
|
2
|
+
export { usePrinter } from './contexts/PrinterContext';
|
|
3
|
+
export { YargramProvider, useYargram } from './contexts/YargramContext';
|
|
4
|
+
export type { YargramProviderProps } from './contexts/YargramContext';
|
|
5
|
+
export { gql } from '@apollo/client';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACxE,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Api(provider: 'rest' | 'graphql' で REST: get/post/put/delete、GraphQL: ransack/handing)
|
|
2
|
+
export { useApi, } from './contexts/ApiContext';
|
|
3
|
+
// Printer
|
|
4
|
+
export { usePrinter } from './contexts/PrinterContext';
|
|
5
|
+
// 統合 Context(Api + Printer + LogWindow)
|
|
6
|
+
export { YargramProvider, useYargram } from './contexts/YargramContext';
|
|
7
|
+
export { gql } from '@apollo/client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yargram/react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./src/index.ts",
|
|
5
|
+
"types": "./src/index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"import": "./src/index.ts",
|
|
10
|
+
"require": "./src/index.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": ">=18.0.0",
|
|
15
|
+
"react-dom": ">=18.0.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@apollo/client": "^3.11.0",
|
|
19
|
+
"@auth0/auth0-react": "^2.13.0",
|
|
20
|
+
"@yargram/core": "workspace:*",
|
|
21
|
+
"graphql": "^16.8.0",
|
|
22
|
+
"lucide-react": "^0.460.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@storybook/addon-essentials": "^8.4.0",
|
|
26
|
+
"@storybook/react": "^8.4.0",
|
|
27
|
+
"@storybook/react-vite": "^8.4.0",
|
|
28
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
29
|
+
"@testing-library/react": "^16.0.1",
|
|
30
|
+
"@testing-library/user-event": "^14.5.2",
|
|
31
|
+
"@types/react": "^18.2.0",
|
|
32
|
+
"@types/react-dom": "^18.2.0",
|
|
33
|
+
"jsdom": "^25.0.1",
|
|
34
|
+
"react": "^18.2.0",
|
|
35
|
+
"react-dom": "^18.2.0",
|
|
36
|
+
"storybook": "^8.4.0",
|
|
37
|
+
"typescript": "^5.0.0",
|
|
38
|
+
"vite": "^5.4.0",
|
|
39
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
40
|
+
"vitest": "^2.1.6"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"storybook": "storybook dev -p 6006",
|
|
44
|
+
"build-storybook": "storybook build",
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Info, AlertTriangle, CircleAlert } from 'lucide-react';
|
|
3
|
+
import type { LogEntry as LogEntryType, LogLevel } from './types';
|
|
4
|
+
import './LogWindow.css';
|
|
5
|
+
|
|
6
|
+
type LogEntryRowProps = {
|
|
7
|
+
entry: LogEntryType;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const levelIcons: Record<LogLevel, React.ComponentType<{ size?: number | string; className?: string }>> = {
|
|
11
|
+
info: Info,
|
|
12
|
+
warn: AlertTriangle,
|
|
13
|
+
error: CircleAlert,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export function LogEntryRow({ entry }: LogEntryRowProps) {
|
|
18
|
+
const levelClass = `logWindowEntry${entry.level.charAt(0).toUpperCase() + entry.level.slice(1)}` as
|
|
19
|
+
| 'logWindowEntryInfo'
|
|
20
|
+
| 'logWindowEntryWarn'
|
|
21
|
+
| 'logWindowEntryError';
|
|
22
|
+
const iconClass = `logWindowEntryIcon${entry.level.charAt(0).toUpperCase() + entry.level.slice(1)}` as
|
|
23
|
+
| 'logWindowEntryIconInfo'
|
|
24
|
+
| 'logWindowEntryIconWarn'
|
|
25
|
+
| 'logWindowEntryIconError';
|
|
26
|
+
|
|
27
|
+
const IconComponent = levelIcons[entry.level];
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className={`logWindowEntry ${levelClass}`}>
|
|
31
|
+
<span className={`logWindowEntryIcon ${iconClass}`}>
|
|
32
|
+
<IconComponent size={12} />
|
|
33
|
+
</span>
|
|
34
|
+
<span className="logWindowEntryMessage">{entry.message}</span>
|
|
35
|
+
<span className="logWindowEntrySource">{entry.source}</span>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|