@stigmer/react 3.0.4 → 3.0.6

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 (88) hide show
  1. package/agent/AgentDetailView.d.ts +1 -11
  2. package/agent/AgentDetailView.d.ts.map +1 -1
  3. package/agent/AgentDetailView.js +3 -6
  4. package/agent/AgentDetailView.js.map +1 -1
  5. package/agent-instance/AgentInstanceDetailPanel.d.ts.map +1 -1
  6. package/agent-instance/AgentInstanceDetailPanel.js +2 -6
  7. package/agent-instance/AgentInstanceDetailPanel.js.map +1 -1
  8. package/agent-instance/AgentInstanceList.d.ts.map +1 -1
  9. package/agent-instance/AgentInstanceList.js +2 -6
  10. package/agent-instance/AgentInstanceList.js.map +1 -1
  11. package/iam-policy/useCheckPermission.d.ts +3 -1
  12. package/iam-policy/useCheckPermission.d.ts.map +1 -1
  13. package/iam-policy/useCheckPermission.js +11 -15
  14. package/iam-policy/useCheckPermission.js.map +1 -1
  15. package/index.d.ts +2 -2
  16. package/index.d.ts.map +1 -1
  17. package/index.js +1 -1
  18. package/index.js.map +1 -1
  19. package/library/InstanceVisibilitySelector.d.ts +8 -15
  20. package/library/InstanceVisibilitySelector.d.ts.map +1 -1
  21. package/library/InstanceVisibilitySelector.js +11 -139
  22. package/library/InstanceVisibilitySelector.js.map +1 -1
  23. package/library/ResourceVisibilityControl.d.ts +52 -0
  24. package/library/ResourceVisibilityControl.d.ts.map +1 -0
  25. package/library/ResourceVisibilityControl.js +81 -0
  26. package/library/ResourceVisibilityControl.js.map +1 -0
  27. package/library/ScopeToggle.d.ts +1 -1
  28. package/library/ScopeToggle.js +1 -1
  29. package/library/VisibilitySelector.d.ts +75 -0
  30. package/library/VisibilitySelector.d.ts.map +1 -0
  31. package/library/VisibilitySelector.js +171 -0
  32. package/library/VisibilitySelector.js.map +1 -0
  33. package/library/index.d.ts +6 -2
  34. package/library/index.d.ts.map +1 -1
  35. package/library/index.js +3 -1
  36. package/library/index.js.map +1 -1
  37. package/library/useUpdateVisibility.d.ts +5 -4
  38. package/library/useUpdateVisibility.d.ts.map +1 -1
  39. package/library/useUpdateVisibility.js +5 -4
  40. package/library/useUpdateVisibility.js.map +1 -1
  41. package/library/visibilityLevels.d.ts +74 -0
  42. package/library/visibilityLevels.d.ts.map +1 -0
  43. package/library/visibilityLevels.js +91 -0
  44. package/library/visibilityLevels.js.map +1 -0
  45. package/mcp-server/McpServerDetailView.d.ts +1 -11
  46. package/mcp-server/McpServerDetailView.d.ts.map +1 -1
  47. package/mcp-server/McpServerDetailView.js +3 -6
  48. package/mcp-server/McpServerDetailView.js.map +1 -1
  49. package/package.json +4 -4
  50. package/resource-detail/types.d.ts +1 -1
  51. package/skill/SkillDetailView.d.ts +1 -11
  52. package/skill/SkillDetailView.d.ts.map +1 -1
  53. package/skill/SkillDetailView.js +3 -6
  54. package/skill/SkillDetailView.js.map +1 -1
  55. package/src/agent/AgentDetailView.tsx +10 -35
  56. package/src/agent-instance/AgentInstanceDetailPanel.tsx +2 -7
  57. package/src/agent-instance/AgentInstanceList.tsx +2 -7
  58. package/src/iam-policy/useCheckPermission.ts +10 -15
  59. package/src/index.ts +8 -2
  60. package/src/library/InstanceVisibilitySelector.tsx +19 -276
  61. package/src/library/ResourceVisibilityControl.tsx +145 -0
  62. package/src/library/ScopeToggle.tsx +1 -1
  63. package/src/library/VisibilitySelector.tsx +393 -0
  64. package/src/library/index.ts +16 -2
  65. package/src/library/useUpdateVisibility.ts +5 -4
  66. package/src/library/visibilityLevels.ts +144 -0
  67. package/src/mcp-server/McpServerDetailView.tsx +10 -35
  68. package/src/resource-detail/types.ts +1 -1
  69. package/src/skill/SkillDetailView.tsx +10 -35
  70. package/src/workflow/WorkflowDetailView.tsx +10 -34
  71. package/src/workflow/instance/WorkflowInstanceDetailPanel.tsx +2 -7
  72. package/src/workflow/instance/WorkflowInstanceList.tsx +2 -7
  73. package/styles.css +1 -1
  74. package/workflow/WorkflowDetailView.d.ts +1 -10
  75. package/workflow/WorkflowDetailView.d.ts.map +1 -1
  76. package/workflow/WorkflowDetailView.js +3 -6
  77. package/workflow/WorkflowDetailView.js.map +1 -1
  78. package/workflow/instance/WorkflowInstanceDetailPanel.d.ts.map +1 -1
  79. package/workflow/instance/WorkflowInstanceDetailPanel.js +2 -6
  80. package/workflow/instance/WorkflowInstanceDetailPanel.js.map +1 -1
  81. package/workflow/instance/WorkflowInstanceList.d.ts.map +1 -1
  82. package/workflow/instance/WorkflowInstanceList.js +2 -6
  83. package/workflow/instance/WorkflowInstanceList.js.map +1 -1
  84. package/library/VisibilityToggle.d.ts +0 -42
  85. package/library/VisibilityToggle.d.ts.map +0 -1
  86. package/library/VisibilityToggle.js +0 -89
  87. package/library/VisibilityToggle.js.map +0 -1
  88. package/src/library/VisibilityToggle.tsx +0 -247
@@ -1,247 +0,0 @@
1
- "use client";
2
-
3
- import { useCallback, useRef, useState } from "react";
4
- import { cn } from "@stigmer/theme";
5
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
6
-
7
- /** Props for {@link VisibilityToggle}. */
8
- export interface VisibilityToggleProps {
9
- /** Current visibility of the resource. */
10
- readonly visibility: ApiResourceVisibility;
11
- /**
12
- * Called when the user confirms a visibility change.
13
- * The toggle shows an inline confirmation before invoking this
14
- * callback when switching to PUBLIC.
15
- */
16
- readonly onVisibilityChange: (v: ApiResourceVisibility) => void;
17
- /** Shows a spinner/disabled state while the RPC is in flight. */
18
- readonly isPending?: boolean;
19
- /** Disables all interaction (e.g., when the user lacks can_edit). */
20
- readonly disabled?: boolean;
21
- /** Additional CSS classes applied to the root element. */
22
- readonly className?: string;
23
- }
24
-
25
- const OPTIONS: readonly {
26
- readonly value: ApiResourceVisibility;
27
- readonly label: string;
28
- }[] = [
29
- { value: ApiResourceVisibility.visibility_private, label: "Private" },
30
- { value: ApiResourceVisibility.visibility_public, label: "Public" },
31
- ];
32
-
33
- /**
34
- * Segmented control for toggling resource visibility between
35
- * Private and Public.
36
- *
37
- * Switching to PUBLIC shows a brief inline confirmation prompt
38
- * since making a resource publicly visible is a consequential
39
- * action. Switching to PRIVATE applies immediately without
40
- * confirmation (revoking access is always safe).
41
- *
42
- * Follows the same visual pattern as {@link ScopeToggle} —
43
- * WAI-ARIA Radio Group with roving tabindex. All visual
44
- * properties flow through `--stgm-*` design tokens.
45
- *
46
- * @example
47
- * ```tsx
48
- * <VisibilityToggle
49
- * visibility={skill.metadata.visibility}
50
- * onVisibilityChange={handleVisibilityChange}
51
- * isPending={isPending}
52
- * />
53
- * ```
54
- */
55
- export function VisibilityToggle({
56
- visibility,
57
- onVisibilityChange,
58
- isPending = false,
59
- disabled = false,
60
- className,
61
- }: VisibilityToggleProps) {
62
- const [confirming, setConfirming] = useState(false);
63
- const optionRefs = useRef<(HTMLButtonElement | null)[]>([]);
64
-
65
- const isPublic =
66
- visibility === ApiResourceVisibility.visibility_public;
67
- const effectivelyDisabled = disabled || isPending;
68
-
69
- const handleSelect = useCallback(
70
- (value: ApiResourceVisibility) => {
71
- if (value === visibility) return;
72
-
73
- if (value === ApiResourceVisibility.visibility_public) {
74
- setConfirming(true);
75
- return;
76
- }
77
-
78
- onVisibilityChange(value);
79
- },
80
- [visibility, onVisibilityChange],
81
- );
82
-
83
- const confirmPublic = useCallback(() => {
84
- setConfirming(false);
85
- onVisibilityChange(ApiResourceVisibility.visibility_public);
86
- }, [onVisibilityChange]);
87
-
88
- const cancelConfirm = useCallback(() => {
89
- setConfirming(false);
90
- }, []);
91
-
92
- const handleKeyDown = useCallback(
93
- (e: React.KeyboardEvent<HTMLButtonElement>, index: number) => {
94
- let nextIndex: number | null = null;
95
-
96
- if (e.key === "ArrowRight" || e.key === "ArrowDown") {
97
- e.preventDefault();
98
- nextIndex = (index + 1) % OPTIONS.length;
99
- } else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
100
- e.preventDefault();
101
- nextIndex = (index - 1 + OPTIONS.length) % OPTIONS.length;
102
- }
103
-
104
- if (nextIndex !== null) {
105
- optionRefs.current[nextIndex]?.focus();
106
- handleSelect(OPTIONS[nextIndex].value);
107
- }
108
- },
109
- [handleSelect],
110
- );
111
-
112
- return (
113
- <div className={cn("inline-flex flex-col gap-1.5", className)}>
114
- <div
115
- role="radiogroup"
116
- aria-label="Resource visibility"
117
- aria-disabled={effectivelyDisabled || undefined}
118
- className={cn(
119
- "inline-flex rounded-md bg-muted p-0.5",
120
- effectivelyDisabled && "pointer-events-none opacity-50",
121
- )}
122
- >
123
- {OPTIONS.map((option, index) => {
124
- const isSelected = visibility === option.value;
125
- const isPublicOption =
126
- option.value === ApiResourceVisibility.visibility_public;
127
-
128
- return (
129
- <button
130
- key={option.value}
131
- ref={(el) => {
132
- optionRefs.current[index] = el;
133
- }}
134
- type="button"
135
- role="radio"
136
- aria-checked={isSelected}
137
- tabIndex={isSelected ? 0 : -1}
138
- disabled={effectivelyDisabled}
139
- onClick={() => handleSelect(option.value)}
140
- onKeyDown={(e) => handleKeyDown(e, index)}
141
- className={cn(
142
- "inline-flex cursor-pointer items-center gap-1 rounded-sm px-2.5 py-1 text-xs font-medium transition-colors",
143
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
144
- isSelected && isPublicOption
145
- ? "bg-emerald-100 text-emerald-800 shadow-sm dark:bg-emerald-900/40 dark:text-emerald-300"
146
- : isSelected
147
- ? "bg-amber-50 text-amber-800 shadow-sm dark:bg-amber-900/30 dark:text-amber-300"
148
- : "text-muted-foreground hover:text-foreground",
149
- )}
150
- >
151
- {isPending && isSelected ? (
152
- <span
153
- className="inline-block size-3 animate-spin rounded-full border-2 border-current border-t-transparent"
154
- aria-hidden="true"
155
- />
156
- ) : isPublicOption ? (
157
- <GlobeIcon className="size-3" />
158
- ) : (
159
- <LockIcon className="size-3" />
160
- )}
161
- {option.label}
162
- </button>
163
- );
164
- })}
165
- </div>
166
-
167
- {confirming && (
168
- <div
169
- className={cn(
170
- "flex items-center gap-2 rounded-md border border-amber-200 bg-amber-50 px-3 py-1.5 text-xs",
171
- "dark:border-amber-800/50 dark:bg-amber-950/30",
172
- )}
173
- role="alert"
174
- >
175
- <span className="text-amber-800 dark:text-amber-200">
176
- Make visible to all users?
177
- </span>
178
- <button
179
- type="button"
180
- onClick={confirmPublic}
181
- className={cn(
182
- "rounded px-2 py-0.5 text-xs font-medium",
183
- "bg-amber-600 text-white hover:bg-amber-700",
184
- "dark:bg-amber-600 dark:hover:bg-amber-500",
185
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
186
- )}
187
- >
188
- Confirm
189
- </button>
190
- <button
191
- type="button"
192
- onClick={cancelConfirm}
193
- className={cn(
194
- "rounded px-2 py-0.5 text-xs font-medium",
195
- "text-amber-700 hover:text-amber-900",
196
- "dark:text-amber-300 dark:hover:text-amber-100",
197
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
198
- )}
199
- >
200
- Cancel
201
- </button>
202
- </div>
203
- )}
204
- </div>
205
- );
206
- }
207
-
208
- // ---------------------------------------------------------------------------
209
- // Icons — inline SVGs following the SDK pattern (no icon library dependency)
210
- // ---------------------------------------------------------------------------
211
-
212
- function LockIcon({ className }: { readonly className?: string }) {
213
- return (
214
- <svg
215
- className={className}
216
- viewBox="0 0 16 16"
217
- fill="none"
218
- stroke="currentColor"
219
- strokeWidth="1.5"
220
- strokeLinecap="round"
221
- strokeLinejoin="round"
222
- aria-hidden="true"
223
- >
224
- <rect x="3.5" y="7" width="9" height="7" rx="1.5" />
225
- <path d="M5.5 7V5a2.5 2.5 0 0 1 5 0v2" />
226
- </svg>
227
- );
228
- }
229
-
230
- function GlobeIcon({ className }: { readonly className?: string }) {
231
- return (
232
- <svg
233
- className={className}
234
- viewBox="0 0 16 16"
235
- fill="none"
236
- stroke="currentColor"
237
- strokeWidth="1.5"
238
- strokeLinecap="round"
239
- strokeLinejoin="round"
240
- aria-hidden="true"
241
- >
242
- <circle cx="8" cy="8" r="6" />
243
- <path d="M2 8h12" />
244
- <path d="M8 2c1.66 1.46 2.6 3.63 2.6 6s-.94 4.54-2.6 6c-1.66-1.46-2.6-3.63-2.6-6s.94-4.54 2.6-6Z" />
245
- </svg>
246
- );
247
- }