@rxtx4816/cockpit-plugin-base-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.
Files changed (41) hide show
  1. package/eslint.config.base.js +85 -0
  2. package/package.json +116 -0
  3. package/scripts/test-vm.sh +608 -0
  4. package/src/bootstrap.tsx +7 -0
  5. package/src/cockpit.d.ts +63 -0
  6. package/src/components/ConfirmDialog.test.tsx +61 -0
  7. package/src/components/ConfirmDialog.tsx +65 -0
  8. package/src/components/ErrorBoundary.test.tsx +50 -0
  9. package/src/components/ErrorBoundary.tsx +30 -0
  10. package/src/components/HelpPopover.tsx +30 -0
  11. package/src/components/LogViewer.tsx +108 -0
  12. package/src/components/StatusBadge.test.tsx +32 -0
  13. package/src/components/StatusBadge.tsx +18 -0
  14. package/src/components/ToastProvider.css +20 -0
  15. package/src/components/ToastProvider.test.tsx +61 -0
  16. package/src/components/ToastProvider.tsx +76 -0
  17. package/src/components/index.ts +8 -0
  18. package/src/css.d.ts +4 -0
  19. package/src/dark-theme.ts +30 -0
  20. package/src/hooks/useAsyncAction.test.ts +59 -0
  21. package/src/hooks/useAsyncAction.ts +31 -0
  22. package/src/hooks/useAsyncStream.test.ts +122 -0
  23. package/src/hooks/useAsyncStream.ts +94 -0
  24. package/src/hooks/useAutoRefresh.test.ts +106 -0
  25. package/src/hooks/useAutoRefresh.ts +23 -0
  26. package/src/hooks/useConfirmAction.test.ts +68 -0
  27. package/src/hooks/useConfirmAction.ts +35 -0
  28. package/src/hooks/usePollingFetch.ts +41 -0
  29. package/src/i18n.ts +51 -0
  30. package/src/index.ts +11 -0
  31. package/src/systemd/ServiceControl.tsx +172 -0
  32. package/src/systemd/api.test.ts +83 -0
  33. package/src/systemd/api.ts +36 -0
  34. package/src/systemd/index.ts +5 -0
  35. package/src/systemd/types.ts +1 -0
  36. package/src/systemd/useServiceStatus.test.ts +96 -0
  37. package/src/systemd/useServiceStatus.ts +29 -0
  38. package/src/testing/helpers.ts +30 -0
  39. package/src/testing/setup.ts +57 -0
  40. package/tsconfig.base.json +17 -0
  41. package/vitest.config.base.ts +47 -0
@@ -0,0 +1,85 @@
1
+ import eslint from "@eslint/js";
2
+ import tseslint from "@typescript-eslint/eslint-plugin";
3
+ import tsparser from "@typescript-eslint/parser";
4
+ import react from "eslint-plugin-react";
5
+ import reactHooks from "eslint-plugin-react-hooks";
6
+
7
+ // Globals shared by all Cockpit plugins.
8
+ // Pass extraGlobals to add plugin-specific names (e.g. CockpitHttpClient for caddy).
9
+ const BASE_GLOBALS = {
10
+ console: "readonly",
11
+ document: "readonly",
12
+ window: "readonly",
13
+ Window: "readonly",
14
+ Element: "readonly",
15
+ HTMLElement: "readonly",
16
+ HTMLDivElement: "readonly",
17
+ HTMLInputElement: "readonly",
18
+ HTMLSelectElement: "readonly",
19
+ HTMLTextAreaElement: "readonly",
20
+ HTMLButtonElement: "readonly",
21
+ setTimeout: "readonly",
22
+ clearTimeout: "readonly",
23
+ setInterval: "readonly",
24
+ clearInterval: "readonly",
25
+ localStorage: "readonly",
26
+ Event: "readonly",
27
+ CustomEvent: "readonly",
28
+ Promise: "readonly",
29
+ queueMicrotask: "readonly",
30
+ MutationObserver: "readonly",
31
+ URL: "readonly",
32
+ navigator: "readonly",
33
+ Blob: "readonly",
34
+ KeyboardEvent: "readonly",
35
+ StorageEvent: "readonly",
36
+ MessageEvent: "readonly",
37
+ sessionStorage: "readonly",
38
+ performance: "readonly",
39
+ HTMLPreElement: "readonly",
40
+ HTMLTableSectionElement: "readonly",
41
+ requestAnimationFrame: "readonly",
42
+ cockpit: "readonly",
43
+ CockpitProcess: "readonly",
44
+ CockpitChannel: "readonly",
45
+ };
46
+
47
+ /**
48
+ * @param {Record<string, "readonly" | "writable">} extraGlobals
49
+ * @returns {import("eslint").Linter.Config[]}
50
+ */
51
+ export function createEslintConfig(extraGlobals = {}) {
52
+ return [
53
+ {
54
+ ignores: ["src/main.js", "src/main.css"],
55
+ },
56
+ eslint.configs.recommended,
57
+ {
58
+ files: ["src/**/*.{ts,tsx}"],
59
+ languageOptions: {
60
+ parser: tsparser,
61
+ parserOptions: {
62
+ ecmaVersion: "latest",
63
+ sourceType: "module",
64
+ ecmaFeatures: { jsx: true },
65
+ },
66
+ globals: { ...BASE_GLOBALS, ...extraGlobals },
67
+ },
68
+ plugins: {
69
+ "@typescript-eslint": tseslint,
70
+ react,
71
+ "react-hooks": reactHooks,
72
+ },
73
+ rules: {
74
+ ...tseslint.configs.recommended.rules,
75
+ ...react.configs.recommended.rules,
76
+ ...reactHooks.configs.recommended.rules,
77
+ "react/react-in-jsx-scope": "off",
78
+ "react-hooks/set-state-in-effect": "off",
79
+ "no-unused-vars": "off",
80
+ "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
81
+ },
82
+ settings: { react: { version: "detect" } },
83
+ },
84
+ ];
85
+ }
package/package.json ADDED
@@ -0,0 +1,116 @@
1
+ {
2
+ "name": "@rxtx4816/cockpit-plugin-base-react",
3
+ "version": "1.0.0",
4
+ "description": "Shared infrastructure for Cockpit plugins: i18n, dark theme, test setup, config presets, CI/CD workflows, and QEMU VM harness",
5
+ "type": "module",
6
+ "author": "RXTX4816",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/RXTX4816/cockpit-plugin-base-react",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/RXTX4816/cockpit-plugin-base-react.git"
12
+ },
13
+ "publishConfig": {
14
+ "registry": "https://registry.npmjs.org",
15
+ "access": "public"
16
+ },
17
+ "types": "./src/cockpit.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "default": "./src/index.ts"
21
+ },
22
+ "./dark-theme": {
23
+ "default": "./src/dark-theme.ts"
24
+ },
25
+ "./i18n": {
26
+ "default": "./src/i18n.ts"
27
+ },
28
+ "./bootstrap": {
29
+ "default": "./src/bootstrap.tsx"
30
+ },
31
+ "./hooks/useAsyncAction": {
32
+ "default": "./src/hooks/useAsyncAction.ts"
33
+ },
34
+ "./hooks/useAutoRefresh": {
35
+ "default": "./src/hooks/useAutoRefresh.ts"
36
+ },
37
+ "./hooks/useAsyncStream": {
38
+ "default": "./src/hooks/useAsyncStream.ts"
39
+ },
40
+ "./hooks/useConfirmAction": {
41
+ "default": "./src/hooks/useConfirmAction.ts"
42
+ },
43
+ "./hooks/usePollingFetch": {
44
+ "default": "./src/hooks/usePollingFetch.ts"
45
+ },
46
+ "./components": {
47
+ "default": "./src/components/index.ts"
48
+ },
49
+ "./systemd": {
50
+ "default": "./src/systemd/index.ts"
51
+ },
52
+ "./testing": {
53
+ "default": "./src/testing/setup.ts"
54
+ },
55
+ "./testing/helpers": {
56
+ "default": "./src/testing/helpers.ts"
57
+ },
58
+ "./tsconfig.base.json": "./tsconfig.base.json",
59
+ "./eslint.config.base": {
60
+ "default": "./eslint.config.base.js"
61
+ },
62
+ "./vitest.config.base": {
63
+ "default": "./vitest.config.base.ts"
64
+ }
65
+ },
66
+ "files": [
67
+ "src/",
68
+ "scripts/",
69
+ "tsconfig.base.json",
70
+ "eslint.config.base.js",
71
+ "vitest.config.base.ts"
72
+ ],
73
+ "bin": {
74
+ "cockpit-test-vm": "./scripts/test-vm.sh"
75
+ },
76
+ "scripts": {
77
+ "typecheck": "tsc --noEmit",
78
+ "test": "vitest run",
79
+ "test:watch": "vitest"
80
+ },
81
+ "peerDependencies": {
82
+ "i18next": ">=26",
83
+ "react": ">=19",
84
+ "react-dom": ">=19",
85
+ "react-i18next": ">=17"
86
+ },
87
+ "devDependencies": {
88
+ "@patternfly/react-core": "^6.5.1",
89
+ "@testing-library/jest-dom": "^6.9.1",
90
+ "@testing-library/react": "^16.3.2",
91
+ "@types/react": "^19.2.17",
92
+ "@types/react-dom": "^19.2.3",
93
+ "@typescript-eslint/eslint-plugin": "^8.61.1",
94
+ "@typescript-eslint/parser": "^8.61.1",
95
+ "eslint": "^9.39.4",
96
+ "eslint-plugin-react": "^7.37.5",
97
+ "eslint-plugin-react-hooks": "^7.1.1",
98
+ "i18next": "^26.3.1",
99
+ "jsdom": "^29.1.1",
100
+ "react": "^19.2.7",
101
+ "react-dom": "^19.2.7",
102
+ "react-i18next": "^17.0.8",
103
+ "typescript": "^6.0.3",
104
+ "vitest": "^4.1.9"
105
+ },
106
+ "engines": {
107
+ "node": ">=22.0.0"
108
+ },
109
+ "keywords": [
110
+ "cockpit",
111
+ "plugin",
112
+ "base",
113
+ "shared",
114
+ "infrastructure"
115
+ ]
116
+ }