@openviking/react 0.1.5 → 0.1.7

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 (145) hide show
  1. package/README.md +15 -11
  2. package/dist/2~0.js +6 -5
  3. package/dist/37~0.js +27 -0
  4. package/dist/3c~0.js +24 -12
  5. package/dist/3~0.js +19 -9
  6. package/dist/ae~0.js +8 -1
  7. package/dist/ark-message-list-view~0.js +9 -4
  8. package/dist/a~0.js +13 -7
  9. package/dist/c7r~0.js +50 -0
  10. package/dist/ck~0.js +7 -0
  11. package/dist/client/paths.d.ts +10 -0
  12. package/dist/client/provider.d.ts +6 -1
  13. package/dist/components/agent-connect/style.css +268 -37
  14. package/dist/components/directory-tour/style.css +265 -21
  15. package/dist/components/directory-tour.js +1 -1
  16. package/dist/components/experience-dashboard/dashboard-tabs.d.ts +11 -0
  17. package/dist/components/experience-dashboard/experience-dashboard.d.ts +2 -0
  18. package/dist/components/experience-dashboard/experience-impact.d.ts +11 -0
  19. package/dist/components/experience-dashboard/experience-list.d.ts +9 -0
  20. package/dist/components/experience-dashboard/experience-pagination.d.ts +8 -0
  21. package/dist/components/experience-dashboard/experience-tests.d.ts +6 -0
  22. package/dist/components/experience-dashboard/experience-trajectories.d.ts +6 -0
  23. package/dist/components/experience-dashboard/index.d.ts +2 -0
  24. package/dist/components/experience-dashboard/labels.d.ts +2 -0
  25. package/dist/components/experience-dashboard/style.css +914 -0
  26. package/dist/components/experience-dashboard/style.js +0 -0
  27. package/dist/components/experience-dashboard/types.d.ts +106 -0
  28. package/dist/components/experience-dashboard.js +1 -0
  29. package/dist/components/file-browser-entries/style.css +463 -86
  30. package/dist/components/file-preview/style.css +267 -78
  31. package/dist/components/file-tree/file-tree-toolbar.d.ts +3 -3
  32. package/dist/components/file-tree/locales/en-US.d.ts +3 -0
  33. package/dist/components/file-tree/locales/zh-CN.d.ts +3 -0
  34. package/dist/components/file-tree/style.css +372 -88
  35. package/dist/components/file-tree/types.d.ts +13 -4
  36. package/dist/components/scope-switcher/style.css +412 -39
  37. package/dist/components/style.css +9326 -4553
  38. package/dist/components/tui/style.css +385 -67
  39. package/dist/components/viking-bot/interaction/style.css +143 -22
  40. package/dist/components/viking-bot/style.css +1075 -278
  41. package/dist/components/wiki-dashboard/index.d.ts +2 -0
  42. package/dist/components/wiki-dashboard/labels.d.ts +2 -0
  43. package/dist/components/wiki-dashboard/style.css +956 -0
  44. package/dist/components/wiki-dashboard/style.js +0 -0
  45. package/dist/components/wiki-dashboard/types.d.ts +92 -0
  46. package/dist/components/wiki-dashboard/wiki-action-button.d.ts +9 -0
  47. package/dist/components/wiki-dashboard/wiki-conflict-card.d.ts +15 -0
  48. package/dist/components/wiki-dashboard/wiki-dashboard.d.ts +2 -0
  49. package/dist/components/wiki-dashboard/wiki-file-icon.d.ts +3 -0
  50. package/dist/components/wiki-dashboard/wiki-severity-filter.d.ts +8 -0
  51. package/dist/components/wiki-dashboard.js +1 -0
  52. package/dist/c~0.js +16 -8
  53. package/dist/ep~0.js +345 -0
  54. package/dist/e~0.js +33 -328
  55. package/dist/fj~0.js +507 -0
  56. package/dist/fl~0.js +709 -0
  57. package/dist/f~0.js +12 -27
  58. package/dist/icons/index.d.ts +28 -0
  59. package/dist/icons.js +1 -1
  60. package/dist/index.d.ts +4 -0
  61. package/dist/index.js +3 -1
  62. package/dist/k~0.js +277 -1
  63. package/dist/lk~0.js +56 -14
  64. package/dist/l~0.js +2786 -446
  65. package/dist/modules/console/index.d.ts +1 -2
  66. package/dist/modules/console/style.css +1787 -346
  67. package/dist/modules/console.js +1 -1
  68. package/dist/modules/file-browser/acl/acl-add-principal.d.ts +12 -0
  69. package/dist/modules/file-browser/acl/acl-candidate.d.ts +8 -0
  70. package/dist/modules/file-browser/acl/acl-client.d.ts +13 -0
  71. package/dist/modules/file-browser/acl/acl-confirmation.d.ts +6 -0
  72. package/dist/modules/file-browser/acl/acl-entry.d.ts +13 -0
  73. package/dist/modules/file-browser/acl/acl-labels.d.ts +47 -0
  74. package/dist/modules/file-browser/acl/acl-menu.d.ts +10 -0
  75. package/dist/modules/file-browser/acl/acl-modal.d.ts +17 -0
  76. package/dist/modules/file-browser/acl/acl-model.d.ts +17 -0
  77. package/dist/modules/file-browser/acl/acl-principal-tabs.d.ts +6 -0
  78. package/dist/modules/file-browser/acl/acl-tag.d.ts +7 -0
  79. package/dist/modules/file-browser/acl/locales/en-US.d.ts +44 -0
  80. package/dist/modules/file-browser/acl/locales/zh-CN.d.ts +44 -0
  81. package/dist/modules/file-browser/acl/use-acl-principals.d.ts +17 -0
  82. package/dist/modules/file-browser/acl/use-acl-report.d.ts +27 -0
  83. package/dist/modules/file-browser/acl-types.d.ts +86 -0
  84. package/dist/modules/file-browser/dashboard-data.d.ts +9 -0
  85. package/dist/modules/file-browser/dashboard-indicator.d.ts +8 -0
  86. package/dist/modules/file-browser/dashboard-labels.d.ts +9 -0
  87. package/dist/modules/file-browser/dashboard-model.d.ts +17 -0
  88. package/dist/modules/file-browser/dashboard-resource.d.ts +12 -0
  89. package/dist/modules/file-browser/experience-dashboard-pane.d.ts +8 -0
  90. package/dist/modules/file-browser/experience-data.d.ts +31 -0
  91. package/dist/modules/file-browser/file-browser-detail.d.ts +4 -1
  92. package/dist/modules/file-browser/file-browser-labels.d.ts +1 -1
  93. package/dist/modules/file-browser/file-browser-search.d.ts +20 -0
  94. package/dist/modules/file-browser/file-browser-toolbar.d.ts +3 -10
  95. package/dist/modules/file-browser/file-browser-tree-pane.d.ts +4 -7
  96. package/dist/modules/file-browser/file-browser.d.ts +1 -1
  97. package/dist/modules/file-browser/fs-directories.d.ts +9 -0
  98. package/dist/modules/file-browser/fs-lines.d.ts +36 -0
  99. package/dist/modules/file-browser/fs-memory-fields.d.ts +65 -0
  100. package/dist/modules/file-browser/fs-model.d.ts +15 -3
  101. package/dist/modules/file-browser/fs-read-file.d.ts +14 -0
  102. package/dist/modules/file-browser/index.d.ts +3 -2
  103. package/dist/modules/file-browser/locales/en-US.d.ts +5 -0
  104. package/dist/modules/file-browser/locales/zh-CN.d.ts +5 -0
  105. package/dist/modules/file-browser/style.css +4033 -483
  106. package/dist/modules/file-browser/types.d.ts +82 -20
  107. package/dist/modules/file-browser/use-browser-dashboards.d.ts +31 -0
  108. package/dist/modules/file-browser/use-dashboard-query.d.ts +9 -0
  109. package/dist/modules/file-browser/use-experience-dashboard.d.ts +27 -0
  110. package/dist/modules/file-browser/use-file-browser-acl.d.ts +15 -0
  111. package/dist/modules/file-browser/use-file-browser.d.ts +6 -51
  112. package/dist/modules/file-browser/use-fs-tree.d.ts +3 -0
  113. package/dist/modules/file-browser/use-wiki-dashboard.d.ts +17 -0
  114. package/dist/modules/file-browser/wiki-conflicts.d.ts +12 -0
  115. package/dist/modules/file-browser/wiki-dashboard-pane.d.ts +14 -0
  116. package/dist/modules/file-browser.js +1 -1
  117. package/dist/modules/scope-cascade/controller.d.ts +2 -2
  118. package/dist/modules/scope-cascade/index.d.ts +1 -2
  119. package/dist/modules/scope-cascade/scope-cascade.d.ts +1 -1
  120. package/dist/modules/scope-cascade/style.css +581 -39
  121. package/dist/modules/scope-cascade/types.d.ts +8 -3
  122. package/dist/modules/scope-cascade/use-scope-cascade.d.ts +2 -2
  123. package/dist/modules/scope-cascade.js +1 -1
  124. package/dist/modules/style.css +13589 -7966
  125. package/dist/n~0.js +73 -165
  126. package/dist/rt~0.js +255 -0
  127. package/dist/r~0.js +18 -39
  128. package/dist/shared/components/button/button.d.ts +20 -0
  129. package/dist/shared/components/input/input.d.ts +17 -0
  130. package/dist/shared/components/modal/locales/en-US.d.ts +4 -0
  131. package/dist/shared/components/modal/locales/zh-CN.d.ts +4 -0
  132. package/dist/shared/components/modal/modal.d.ts +2 -0
  133. package/dist/shared/components/modal/types.d.ts +18 -0
  134. package/dist/shared/components/overlay/lock-body-scroll.d.ts +1 -0
  135. package/dist/shared/components/popover/popover.d.ts +1 -1
  136. package/dist/shared/components/popover/types.d.ts +7 -1
  137. package/dist/shared/dashboard/dashboard-state.d.ts +12 -0
  138. package/dist/static/image/dashboard-background.png +0 -0
  139. package/dist/style.css +16088 -5602
  140. package/dist/s~0.js +16 -0
  141. package/dist/u~0.js +15 -6
  142. package/dist/viking-bot-composer~0.js +30 -12
  143. package/dist/viking-bot-interaction~0.js +2 -1
  144. package/package.json +14 -3
  145. package/dist/o~0.js +0 -106
File without changes
@@ -0,0 +1,92 @@
1
+ import type { HTMLAttributes } from 'react';
2
+ export interface WikiConflict {
3
+ id: string;
4
+ matchText: string;
5
+ description: string;
6
+ reason: string;
7
+ severity: 'high' | 'medium' | 'low';
8
+ state: 'unfixed' | 'fixed';
9
+ beginTime: number;
10
+ fixTime: number | null;
11
+ fixPlan: string;
12
+ resolutionBasis: string;
13
+ resolutionSource?: 'manual' | 'automatic';
14
+ location: {
15
+ status: 'unique';
16
+ start: number;
17
+ end: number;
18
+ line: number;
19
+ } | {
20
+ status: 'missing' | 'ambiguous';
21
+ };
22
+ }
23
+ export interface WikiDirectoryData {
24
+ files: readonly string[];
25
+ conflictFileCount?: number;
26
+ limited?: boolean;
27
+ }
28
+ export interface WikiFileData {
29
+ conflicts: readonly WikiConflict[];
30
+ /** Document path to display; omitted paths hide the path column. */
31
+ path?: string;
32
+ }
33
+ export type WikiDashboardData = WikiDirectoryData | WikiFileData;
34
+ export interface WikiDashboardLabels {
35
+ title: string;
36
+ pendingLabel: string;
37
+ discuss: string;
38
+ conflicts: string;
39
+ conflictFiles: string;
40
+ pending: string;
41
+ all: string;
42
+ severity: string;
43
+ high: string;
44
+ medium: string;
45
+ low: string;
46
+ fixed: string;
47
+ reason: string;
48
+ file: string;
49
+ empty: string;
50
+ loading: string;
51
+ failed: string;
52
+ retry: string;
53
+ open: string;
54
+ edit: string;
55
+ solution: string;
56
+ occurred: string;
57
+ fixedAt: string;
58
+ evidence: string;
59
+ history: string;
60
+ historyHint: string;
61
+ unavailable: string;
62
+ limited: string;
63
+ }
64
+ interface WikiDashboardCommonProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
65
+ loading?: boolean;
66
+ error?: Error | null;
67
+ locale?: 'en-US' | 'zh-CN';
68
+ onRetry?: () => void;
69
+ labels?: Partial<WikiDashboardLabels>;
70
+ }
71
+ export type WikiDashboardProps = WikiDashboardCommonProps & ({
72
+ kind: 'directory';
73
+ data?: WikiDirectoryData;
74
+ editDisabledReason?: never;
75
+ discussDisabledReason?: never;
76
+ onOpenUri?: (uri: string) => void;
77
+ onOpenDashboard?: (uri: string) => void;
78
+ onEdit?: (uri: string) => void;
79
+ onDiscuss?: never;
80
+ } | {
81
+ kind: 'file';
82
+ data?: WikiFileData;
83
+ /** Explanation shown when editing has no handler. Defaults to labels.unavailable. */
84
+ editDisabledReason?: string;
85
+ /** Explanation shown when discussion has no handler. Defaults to labels.unavailable. */
86
+ discussDisabledReason?: string;
87
+ onOpenUri?: () => void;
88
+ onOpenDashboard?: never;
89
+ onEdit?: (conflict: WikiConflict) => void;
90
+ onDiscuss?: (conflict: WikiConflict) => void;
91
+ });
92
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare function WikiActionButton({ label, hint, onClick, children, ...aria }: {
3
+ label: string;
4
+ hint: string;
5
+ onClick?: () => void;
6
+ children: ReactNode;
7
+ 'aria-expanded'?: boolean;
8
+ 'aria-controls'?: string;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ import type { WikiConflict, WikiDashboardProps, WikiDashboardLabels } from './types.js';
2
+ export declare function WikiConflictCard({ conflict, path, labels: t, editDisabledReason, discussDisabledReason, onOpenUri, onEdit, onDiscuss, }: {
3
+ conflict: WikiConflict;
4
+ path?: string;
5
+ labels: WikiDashboardLabels;
6
+ editDisabledReason?: string;
7
+ discussDisabledReason?: string;
8
+ onOpenUri?: () => void;
9
+ onEdit?: Extract<WikiDashboardProps, {
10
+ kind: 'file';
11
+ }>['onEdit'];
12
+ onDiscuss?: Extract<WikiDashboardProps, {
13
+ kind: 'file';
14
+ }>['onDiscuss'];
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { WikiDashboardProps } from './types.js';
2
+ export declare function WikiDashboard(props: WikiDashboardProps): import("react").JSX.Element;
@@ -0,0 +1,3 @@
1
+ export declare function WikiFileIcon({ name }: {
2
+ name: string;
3
+ }): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { WikiConflict, WikiDashboardLabels } from './types.js';
2
+ type Severity = WikiConflict['severity'] | 'all';
3
+ export declare function WikiSeverityFilter({ value, onChange, labels: t, }: {
4
+ value: Severity;
5
+ onChange: (value: Severity) => void;
6
+ labels: WikiDashboardLabels;
7
+ }): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1 @@
1
+ export { WikiDashboard } from "../fj~0.js";
package/dist/c~0.js CHANGED
@@ -2,9 +2,9 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Suspense, createContext, forwardRef, lazy, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import { resolveLocale } from "./nx~0.js";
5
- import { useOverlayPosition } from "./o~0.js";
5
+ import { Tooltip, useOverlayPosition } from "./rt~0.js";
6
6
  import { useLocale, LocaleProvider } from "./28~0.js";
7
- import { Tooltip } from "./r~0.js";
7
+ import { button_Button } from "./e~0.js";
8
8
  import { VikingBotIcon } from "./lg~0.js";
9
9
  import { VikingBotInteraction } from "./w~0.js";
10
10
  const en_US_messages = {
@@ -204,9 +204,12 @@ function VikingBotSessionActions({ sessions, extra, labels: overrides, locale: l
204
204
  trigger: (props)=>/*#__PURE__*/ jsx(Tooltip, {
205
205
  content: labels.sessionHistory,
206
206
  disabled: true === props['aria-expanded'],
207
- children: /*#__PURE__*/ jsx("button", {
207
+ children: /*#__PURE__*/ jsx(button_Button, {
208
208
  ...props,
209
- type: "button",
209
+ size: "mini",
210
+ type: "text",
211
+ iconOnly: true,
212
+ htmlType: "button",
210
213
  className: "ov-viking-bot__header-action",
211
214
  "aria-label": labels.sessionHistory,
212
215
  children: /*#__PURE__*/ jsx(VikingBotIcon, {
@@ -258,8 +261,10 @@ function VikingBotSessionActions({ sessions, extra, labels: overrides, locale: l
258
261
  }, item.id);
259
262
  })
260
263
  }),
261
- sessions.hasMore && sessions.onLoadMore ? /*#__PURE__*/ jsx("button", {
262
- type: "button",
264
+ sessions.hasMore && sessions.onLoadMore ? /*#__PURE__*/ jsx(button_Button, {
265
+ size: "small",
266
+ type: "default",
267
+ htmlType: "button",
263
268
  disabled: sessions.isLoading,
264
269
  onClick: sessions.onLoadMore,
265
270
  children: labels.loadMore
@@ -269,8 +274,11 @@ function VikingBotSessionActions({ sessions, extra, labels: overrides, locale: l
269
274
  }),
270
275
  /*#__PURE__*/ jsx(Tooltip, {
271
276
  content: labels.newSession,
272
- children: /*#__PURE__*/ jsx("button", {
273
- type: "button",
277
+ children: /*#__PURE__*/ jsx(button_Button, {
278
+ size: "mini",
279
+ type: "text",
280
+ iconOnly: true,
281
+ htmlType: "button",
274
282
  className: "ov-viking-bot__header-action",
275
283
  "aria-label": labels.newSession,
276
284
  onClick: sessions.onNew,
package/dist/ep~0.js ADDED
@@ -0,0 +1,345 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { useLocale } from "./28~0.js";
5
+ import { resolveLocale } from "./nx~0.js";
6
+ import { button_Button } from "./e~0.js";
7
+ function useTourAnchor(target, locateTarget, timeout, attempt) {
8
+ const [state, setState] = useState({
9
+ anchor: null,
10
+ failed: false
11
+ });
12
+ useEffect(()=>{
13
+ const controller = new AbortController();
14
+ setState({
15
+ anchor: null,
16
+ failed: false
17
+ });
18
+ const timer = window.setTimeout(()=>{
19
+ controller.abort();
20
+ setState({
21
+ anchor: null,
22
+ failed: true
23
+ });
24
+ }, timeout);
25
+ Promise.resolve().then(()=>locateTarget?.(target, controller.signal) ?? null).then((anchor)=>{
26
+ if (controller.signal.aborted) return;
27
+ window.clearTimeout(timer);
28
+ if (anchor?.isConnected) {
29
+ anchor.scrollIntoView({
30
+ block: 'nearest',
31
+ inline: 'nearest'
32
+ });
33
+ setState({
34
+ anchor,
35
+ failed: false
36
+ });
37
+ } else setState({
38
+ anchor: null,
39
+ failed: true
40
+ });
41
+ }, ()=>{
42
+ if (controller.signal.aborted) return;
43
+ window.clearTimeout(timer);
44
+ setState({
45
+ anchor: null,
46
+ failed: true
47
+ });
48
+ });
49
+ return ()=>{
50
+ controller.abort();
51
+ window.clearTimeout(timer);
52
+ };
53
+ }, [
54
+ target,
55
+ locateTarget,
56
+ timeout,
57
+ attempt
58
+ ]);
59
+ return state;
60
+ }
61
+ function useTourPosition(anchor, surface, placement) {
62
+ const [position, setPosition] = useState();
63
+ useEffect(()=>{
64
+ if (!surface) return;
65
+ surface.showPopover?.();
66
+ const update = ()=>{
67
+ const a = anchor?.getBoundingClientRect();
68
+ const box = surface.getBoundingClientRect();
69
+ const width = window.innerWidth;
70
+ const height = window.innerHeight;
71
+ const margin = 8;
72
+ let left = (width - box.width) / 2;
73
+ let top = (height - box.height) / 2;
74
+ const missing = Boolean(anchor && !anchor.isConnected);
75
+ let visible = !anchor || missing;
76
+ if (anchor && a && !missing) {
77
+ let clip = {
78
+ left: 0,
79
+ top: 0,
80
+ right: width,
81
+ bottom: height
82
+ };
83
+ for(let parent = anchor.parentElement; parent; parent = parent.parentElement){
84
+ const css = window.getComputedStyle(parent);
85
+ const rect = parent.getBoundingClientRect();
86
+ if (/(auto|scroll|hidden|clip)/.test(css.overflowX)) clip = {
87
+ ...clip,
88
+ left: Math.max(clip.left, rect.left),
89
+ right: Math.min(clip.right, rect.right)
90
+ };
91
+ if (/(auto|scroll|hidden|clip)/.test(css.overflowY)) clip = {
92
+ ...clip,
93
+ top: Math.max(clip.top, rect.top),
94
+ bottom: Math.min(clip.bottom, rect.bottom)
95
+ };
96
+ }
97
+ visible = anchor.isConnected && a.width > 0 && a.height > 0 && a.top < clip.bottom && a.bottom > clip.top && a.left < clip.right && a.right > clip.left;
98
+ const right = a.right + 6;
99
+ const leftSide = a.left - box.width - 6;
100
+ left = 'right' === placement ? right + box.width <= width - margin || leftSide < margin ? right : leftSide : leftSide >= margin || right + box.width > width - margin ? leftSide : right;
101
+ top = a.top - 16;
102
+ const css = window.getComputedStyle(anchor);
103
+ for(let i = 0; i < css.length; i++){
104
+ const name = css[i];
105
+ if (name?.startsWith('--ov-ui-')) surface.style.setProperty(name, css.getPropertyValue(name));
106
+ }
107
+ }
108
+ const next = {
109
+ left: Math.max(margin, Math.min(left, width - box.width - margin)),
110
+ top: Math.max(margin, Math.min(top, height - box.height - margin)),
111
+ targetTop: a?.top ?? 0,
112
+ targetLeft: a?.left ?? 0,
113
+ targetWidth: a?.width ?? 0,
114
+ targetHeight: a?.height ?? 0,
115
+ visible,
116
+ missing
117
+ };
118
+ setPosition((old)=>old && Object.keys(next).every((key)=>old[key] === next[key]) ? old : next);
119
+ };
120
+ update();
121
+ const resize = new ResizeObserver(update);
122
+ resize.observe(surface);
123
+ for(let node = anchor; node; node = node.parentElement)resize.observe(node);
124
+ const mutation = new MutationObserver(update);
125
+ mutation.observe(document.body, {
126
+ childList: true,
127
+ subtree: true
128
+ });
129
+ window.addEventListener('scroll', update, true);
130
+ window.addEventListener('resize', update);
131
+ window.visualViewport?.addEventListener('resize', update);
132
+ window.visualViewport?.addEventListener('scroll', update);
133
+ return ()=>{
134
+ resize.disconnect();
135
+ mutation.disconnect();
136
+ window.removeEventListener('scroll', update, true);
137
+ window.removeEventListener('resize', update);
138
+ window.visualViewport?.removeEventListener('resize', update);
139
+ window.visualViewport?.removeEventListener('scroll', update);
140
+ if (surface.isConnected) surface.hidePopover?.();
141
+ };
142
+ }, [
143
+ anchor,
144
+ surface,
145
+ placement
146
+ ]);
147
+ return position;
148
+ }
149
+ const messages = {
150
+ close: 'Close guide',
151
+ next: 'Next',
152
+ done: 'Got it',
153
+ locating: 'Locating directory…',
154
+ unavailable: 'This directory is unavailable. Retry or skip this step.',
155
+ retry: 'Retry',
156
+ skip: 'Skip',
157
+ progress: (current, total)=>`${current}/${total}`
158
+ };
159
+ const en_US = messages;
160
+ const zh_CN_messages = {
161
+ close: '关闭引导',
162
+ next: '下一步',
163
+ done: '知道了',
164
+ locating: '正在定位目录…',
165
+ unavailable: '此目录暂不可用,请重试或跳过这一步。',
166
+ retry: '重试',
167
+ skip: '跳过',
168
+ progress: (current, total)=>`${current}/${total}`
169
+ };
170
+ const zh_CN = zh_CN_messages;
171
+ function DirectoryTour(props) {
172
+ if (!props.open || 0 === props.steps.length) return null;
173
+ return /*#__PURE__*/ jsx(TourSession, {
174
+ ...props
175
+ });
176
+ }
177
+ function TourSession(props) {
178
+ const [index, setIndex] = useState(props.defaultStep ?? 0);
179
+ const skipped = useRef(new Set());
180
+ const current = props.currentStep ?? index;
181
+ const step = props.steps[current];
182
+ if (!step) return null;
183
+ const advance = (skip)=>{
184
+ if (skip) skipped.current.add(step.id);
185
+ if (current === props.steps.length - 1) props.onComplete?.({
186
+ skippedStepIds: [
187
+ ...skipped.current
188
+ ]
189
+ });
190
+ else {
191
+ if (void 0 === props.currentStep) setIndex(current + 1);
192
+ props.onStepChange?.(current + 1);
193
+ }
194
+ };
195
+ return /*#__PURE__*/ jsx(TourStep, {
196
+ ...props,
197
+ step: step,
198
+ index: current,
199
+ advance: advance
200
+ }, step.id);
201
+ }
202
+ function TourStep({ step, index, advance, steps, locateTarget, locateTimeout = 10000, placement = 'right', onClose, labels, locale: localeProp, className, style }) {
203
+ const locale = useLocale(localeProp);
204
+ const text = resolveLocale({
205
+ 'en-US': en_US,
206
+ 'zh-CN': zh_CN
207
+ }, locale, labels);
208
+ const [attempt, retry] = useState(0);
209
+ const [surface, setSurface] = useState(null);
210
+ const { anchor, failed } = useTourAnchor(step.target, locateTarget, locateTimeout, attempt);
211
+ const position = useTourPosition(anchor, surface, placement);
212
+ const titleId = useId();
213
+ const bodyId = useId();
214
+ useEffect(()=>{
215
+ const close = (event)=>{
216
+ if ('Escape' === event.key) {
217
+ event.preventDefault();
218
+ onClose?.();
219
+ }
220
+ };
221
+ document.addEventListener('keydown', close);
222
+ return ()=>document.removeEventListener('keydown', close);
223
+ }, [
224
+ onClose
225
+ ]);
226
+ useEffect(()=>{
227
+ const previous = document.activeElement;
228
+ return ()=>{
229
+ if (previous instanceof HTMLElement && previous.isConnected) previous.focus({
230
+ preventScroll: true
231
+ });
232
+ };
233
+ }, []);
234
+ const visible = position?.visible;
235
+ useEffect(()=>{
236
+ if (surface && visible) surface.focus({
237
+ preventScroll: true
238
+ });
239
+ }, [
240
+ surface,
241
+ visible
242
+ ]);
243
+ if ("u" < typeof document) return null;
244
+ const unavailable = failed || position?.missing;
245
+ const locating = !anchor && !failed;
246
+ return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsxs("div", {
247
+ ref: setSurface,
248
+ popover: "manual",
249
+ role: "dialog",
250
+ "aria-modal": "false",
251
+ "aria-labelledby": titleId,
252
+ "aria-describedby": bodyId,
253
+ "aria-busy": locating,
254
+ tabIndex: -1,
255
+ className: [
256
+ 'ov-directory-tour',
257
+ className
258
+ ].filter(Boolean).join(' '),
259
+ style: {
260
+ ...style,
261
+ top: position?.top ?? 0,
262
+ left: position?.left ?? 0,
263
+ visibility: position?.visible ? 'visible' : 'hidden'
264
+ },
265
+ children: [
266
+ anchor && !unavailable && position?.visible && /*#__PURE__*/ jsx("div", {
267
+ className: "ov-directory-tour__highlight",
268
+ "aria-hidden": "true",
269
+ style: {
270
+ top: position.targetTop,
271
+ left: position.targetLeft,
272
+ width: position.targetWidth,
273
+ height: position.targetHeight
274
+ }
275
+ }),
276
+ /*#__PURE__*/ jsxs("div", {
277
+ className: "ov-directory-tour__card",
278
+ children: [
279
+ onClose && /*#__PURE__*/ jsx(button_Button, {
280
+ size: "mini",
281
+ type: "text",
282
+ iconOnly: true,
283
+ className: "ov-directory-tour__close",
284
+ htmlType: "button",
285
+ "aria-label": text.close,
286
+ onClick: onClose,
287
+ children: "\xd7"
288
+ }),
289
+ !locating && !unavailable && step.illustration && /*#__PURE__*/ jsx("div", {
290
+ className: "ov-directory-tour__illustration",
291
+ children: step.illustration
292
+ }),
293
+ /*#__PURE__*/ jsx("h2", {
294
+ id: titleId,
295
+ className: "ov-directory-tour__title",
296
+ children: step.title
297
+ }),
298
+ /*#__PURE__*/ jsx("div", {
299
+ id: bodyId,
300
+ className: "ov-directory-tour__description",
301
+ role: unavailable ? 'alert' : void 0,
302
+ children: unavailable ? text.unavailable : locating ? text.locating : step.description
303
+ }),
304
+ /*#__PURE__*/ jsxs("footer", {
305
+ className: "ov-directory-tour__actions",
306
+ children: [
307
+ /*#__PURE__*/ jsx("span", {
308
+ className: "ov-directory-tour__progress",
309
+ "aria-live": "polite",
310
+ children: text.progress(index + 1, steps.length)
311
+ }),
312
+ unavailable ? /*#__PURE__*/ jsxs(Fragment, {
313
+ children: [
314
+ /*#__PURE__*/ jsx(button_Button, {
315
+ size: "small",
316
+ type: "default",
317
+ htmlType: "button",
318
+ onClick: ()=>retry((value)=>value + 1),
319
+ children: text.retry
320
+ }),
321
+ /*#__PURE__*/ jsx(button_Button, {
322
+ size: "small",
323
+ type: "default",
324
+ htmlType: "button",
325
+ onClick: ()=>advance(true),
326
+ children: text.skip
327
+ })
328
+ ]
329
+ }) : /*#__PURE__*/ jsx(button_Button, {
330
+ size: "small",
331
+ type: "primary",
332
+ htmlType: "button",
333
+ className: "ov-directory-tour__primary",
334
+ disabled: locating,
335
+ onClick: ()=>advance(false),
336
+ children: step.nextLabel ?? (index === steps.length - 1 ? text.done : text.next)
337
+ })
338
+ ]
339
+ })
340
+ ]
341
+ })
342
+ ]
343
+ }), document.body);
344
+ }
345
+ export { DirectoryTour };