@dxos/plugin-help 0.6.8-main.046e6cf

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 (70) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +15 -0
  3. package/dist/lib/browser/chunk-DI4HXWTJ.mjs +23 -0
  4. package/dist/lib/browser/chunk-DI4HXWTJ.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +551 -0
  6. package/dist/lib/browser/index.mjs.map +7 -0
  7. package/dist/lib/browser/meta.json +1 -0
  8. package/dist/lib/browser/meta.mjs +11 -0
  9. package/dist/lib/browser/meta.mjs.map +7 -0
  10. package/dist/types/src/HelpPlugin.d.ts +11 -0
  11. package/dist/types/src/HelpPlugin.d.ts.map +1 -0
  12. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.d.ts +10 -0
  13. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.d.ts.map +1 -0
  14. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.stories.d.ts +31 -0
  15. package/dist/types/src/components/HelpContextProvider/HelpContextProvider.stories.d.ts.map +1 -0
  16. package/dist/types/src/components/HelpContextProvider/index.d.ts +2 -0
  17. package/dist/types/src/components/HelpContextProvider/index.d.ts.map +1 -0
  18. package/dist/types/src/components/Shortcuts/Key.d.ts +5 -0
  19. package/dist/types/src/components/Shortcuts/Key.d.ts.map +1 -0
  20. package/dist/types/src/components/Shortcuts/ShortcutsDialog.d.ts +3 -0
  21. package/dist/types/src/components/Shortcuts/ShortcutsDialog.d.ts.map +1 -0
  22. package/dist/types/src/components/Shortcuts/ShortcutsHints.d.ts +5 -0
  23. package/dist/types/src/components/Shortcuts/ShortcutsHints.d.ts.map +1 -0
  24. package/dist/types/src/components/Shortcuts/ShortcutsList.d.ts +3 -0
  25. package/dist/types/src/components/Shortcuts/ShortcutsList.d.ts.map +1 -0
  26. package/dist/types/src/components/Shortcuts/ShortcutsSection.d.ts +3 -0
  27. package/dist/types/src/components/Shortcuts/ShortcutsSection.d.ts.map +1 -0
  28. package/dist/types/src/components/Shortcuts/index.d.ts +6 -0
  29. package/dist/types/src/components/Shortcuts/index.d.ts.map +1 -0
  30. package/dist/types/src/components/Shortcuts/styles.d.ts +2 -0
  31. package/dist/types/src/components/Shortcuts/styles.d.ts.map +1 -0
  32. package/dist/types/src/components/Tooltip/Tooltip.d.ts +44 -0
  33. package/dist/types/src/components/Tooltip/Tooltip.d.ts.map +1 -0
  34. package/dist/types/src/components/Tooltip/index.d.ts +2 -0
  35. package/dist/types/src/components/Tooltip/index.d.ts.map +1 -0
  36. package/dist/types/src/components/index.d.ts +4 -0
  37. package/dist/types/src/components/index.d.ts.map +1 -0
  38. package/dist/types/src/hooks/index.d.ts +2 -0
  39. package/dist/types/src/hooks/index.d.ts.map +1 -0
  40. package/dist/types/src/hooks/useHelp.d.ts +2 -0
  41. package/dist/types/src/hooks/useHelp.d.ts.map +1 -0
  42. package/dist/types/src/index.d.ts +8 -0
  43. package/dist/types/src/index.d.ts.map +1 -0
  44. package/dist/types/src/meta.d.ts +18 -0
  45. package/dist/types/src/meta.d.ts.map +1 -0
  46. package/dist/types/src/translations.d.ts +12 -0
  47. package/dist/types/src/translations.d.ts.map +1 -0
  48. package/dist/types/src/types.d.ts +20 -0
  49. package/dist/types/src/types.d.ts.map +1 -0
  50. package/package.json +71 -0
  51. package/src/HelpPlugin.tsx +140 -0
  52. package/src/components/HelpContextProvider/HelpContextProvider.stories.tsx +112 -0
  53. package/src/components/HelpContextProvider/HelpContextProvider.tsx +176 -0
  54. package/src/components/HelpContextProvider/index.ts +5 -0
  55. package/src/components/Shortcuts/Key.tsx +21 -0
  56. package/src/components/Shortcuts/ShortcutsDialog.tsx +30 -0
  57. package/src/components/Shortcuts/ShortcutsHints.tsx +43 -0
  58. package/src/components/Shortcuts/ShortcutsList.tsx +35 -0
  59. package/src/components/Shortcuts/ShortcutsSection.tsx +16 -0
  60. package/src/components/Shortcuts/index.ts +9 -0
  61. package/src/components/Shortcuts/styles.ts +10 -0
  62. package/src/components/Tooltip/Tooltip.tsx +111 -0
  63. package/src/components/Tooltip/index.ts +5 -0
  64. package/src/components/index.ts +7 -0
  65. package/src/hooks/index.ts +5 -0
  66. package/src/hooks/useHelp.tsx +13 -0
  67. package/src/index.ts +15 -0
  68. package/src/meta.tsx +23 -0
  69. package/src/translations.ts +18 -0
  70. package/src/types.ts +38 -0
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright (c) 2022 DXOS
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @dxos/plugin-help
2
+
3
+ Help plugin.
4
+
5
+ ## DXOS Resources
6
+
7
+ - [Website](https://dxos.org)
8
+ - [Developer Documentation](https://docs.dxos.org)
9
+ - Talk to us on [Discord](https://dxos.org/discord)
10
+
11
+ ## Contributions
12
+
13
+ Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
14
+
15
+ License: [MIT](./LICENSE) Copyright 2023 © DXOS
@@ -0,0 +1,23 @@
1
+ // packages/plugins/plugin-help/src/meta.tsx
2
+ import { Info } from "@phosphor-icons/react";
3
+ import React from "react";
4
+ import { pluginMeta } from "@dxos/app-framework";
5
+ var HELP_PLUGIN = "dxos.org/plugin/help";
6
+ var meta_default = pluginMeta({
7
+ id: HELP_PLUGIN,
8
+ name: "Help",
9
+ iconComponent: (props) => /* @__PURE__ */ React.createElement(Info, props),
10
+ iconSymbol: "ph--info--regular"
11
+ });
12
+ var HELP_ACTION = `${HELP_PLUGIN}/action`;
13
+ var HelpAction;
14
+ (function(HelpAction2) {
15
+ HelpAction2[HelpAction2["START"] = `${HELP_ACTION}/start`] = "START";
16
+ })(HelpAction || (HelpAction = {}));
17
+
18
+ export {
19
+ HELP_PLUGIN,
20
+ meta_default,
21
+ HelpAction
22
+ };
23
+ //# sourceMappingURL=chunk-DI4HXWTJ.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/meta.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Info, type IconProps } from '@phosphor-icons/react';\nimport React from 'react';\n\nimport { pluginMeta } from '@dxos/app-framework';\n\n// TODO(burdon): Rename Guide? Help?\nexport const HELP_PLUGIN = 'dxos.org/plugin/help';\n\nexport default pluginMeta({\n id: HELP_PLUGIN,\n name: 'Help',\n iconComponent: (props: IconProps) => <Info {...props} />,\n iconSymbol: 'ph--info--regular',\n});\n\nconst HELP_ACTION = `${HELP_PLUGIN}/action`;\nexport enum HelpAction {\n START = `${HELP_ACTION}/start`,\n}\n"],
5
+ "mappings": ";AAIA,SAASA,YAA4B;AACrC,OAAOC,WAAW;AAElB,SAASC,kBAAkB;AAGpB,IAAMC,cAAc;AAE3B,IAAA,eAAeC,WAAW;EACxBC,IAAIF;EACJG,MAAM;EACNC,eAAe,CAACC,UAAqB,sBAAA,cAACC,MAASD,KAAAA;EAC/CE,YAAY;AACd,CAAA;AAEA,IAAMC,cAAc,GAAGR,WAAAA;;UACXS,aAAAA;qCACF,GAAGD,WAAAA,QAAmB,IAAA;GADpBC,eAAAA,aAAAA,CAAAA,EAAAA;",
6
+ "names": ["Info", "React", "pluginMeta", "HELP_PLUGIN", "pluginMeta", "id", "name", "iconComponent", "props", "Info", "iconSymbol", "HELP_ACTION", "HelpAction"]
7
+ }
@@ -0,0 +1,551 @@
1
+ import {
2
+ HELP_PLUGIN,
3
+ HelpAction,
4
+ meta_default
5
+ } from "./chunk-DI4HXWTJ.mjs";
6
+
7
+ // packages/plugins/plugin-help/src/HelpPlugin.tsx
8
+ import { Keyboard as KeyboardIcon, Info } from "@phosphor-icons/react";
9
+ import React8 from "react";
10
+ import { resolvePlugin as resolvePlugin2, parseIntentPlugin, LayoutAction } from "@dxos/app-framework";
11
+ import { createExtension } from "@dxos/app-graph";
12
+ import { create } from "@dxos/echo-schema";
13
+ import { LocalStorageStore } from "@dxos/local-storage";
14
+
15
+ // packages/plugins/plugin-help/src/components/HelpContextProvider/HelpContextProvider.tsx
16
+ import React2, { useState, useEffect } from "react";
17
+ import Joyride, { ACTIONS, EVENTS } from "react-joyride";
18
+ import { usePlugins, resolvePlugin, parseLayoutPlugin } from "@dxos/app-framework";
19
+ import { useShellDisplay, ShellDisplay } from "@dxos/react-client";
20
+ import { tailwindConfig } from "@dxos/react-ui-theme";
21
+
22
+ // packages/plugins/plugin-help/src/types.ts
23
+ import { createContext } from "react";
24
+ var HelpContext = createContext({
25
+ running: false,
26
+ steps: [],
27
+ setSteps: () => {
28
+ },
29
+ setIndex: () => {
30
+ },
31
+ start: () => {
32
+ },
33
+ stop: () => {
34
+ }
35
+ });
36
+
37
+ // packages/plugins/plugin-help/src/components/Tooltip/Tooltip.tsx
38
+ import { useArrowNavigationGroup, useFocusableGroup } from "@fluentui/react-tabster";
39
+ import { CaretLeft, CaretRight, Circle, X } from "@phosphor-icons/react";
40
+ import React, { forwardRef } from "react";
41
+ import { Button } from "@dxos/react-ui";
42
+ import { getSize, mx } from "@dxos/react-ui-theme";
43
+ var floaterProps = {
44
+ styles: {
45
+ // Arrow color is set by joyride.
46
+ arrow: {
47
+ length: 8,
48
+ spread: 16
49
+ },
50
+ floater: {
51
+ // TODO(burdon): Get tokens from theme.
52
+ filter: "drop-shadow(0 0 0.75rem rgba(0, 0, 0, 0.2))"
53
+ }
54
+ }
55
+ };
56
+ var Tooltip = /* @__PURE__ */ forwardRef(({ step: { title, content }, index, size, isLastStep, backProps, closeProps, primaryProps }, forwardedRef) => {
57
+ const arrowGroup = useArrowNavigationGroup({
58
+ axis: "horizontal"
59
+ });
60
+ const trapFocus = useFocusableGroup({
61
+ tabBehavior: "limited-trap-focus"
62
+ });
63
+ return /* @__PURE__ */ React.createElement("div", {
64
+ className: "flex flex-col is-[15rem] min-bs-[10rem] overflow-hidden rounded-md shadow-xl surface-accent fg-inverse",
65
+ role: "tooltip",
66
+ "data-testid": "helpPlugin.tooltip",
67
+ "data-step": index + 1,
68
+ ...trapFocus,
69
+ ref: forwardedRef
70
+ }, /* @__PURE__ */ React.createElement("div", {
71
+ className: "flex p-2"
72
+ }, /* @__PURE__ */ React.createElement("h2", {
73
+ className: "grow pli-2 plb-1 text-lg font-medium fg-inverse"
74
+ }, title), /* @__PURE__ */ React.createElement(Button, {
75
+ density: "fine",
76
+ variant: "primary",
77
+ onClick: closeProps.onClick,
78
+ title: closeProps["aria-label"],
79
+ "data-testid": "helpPlugin.tooltip.close"
80
+ }, /* @__PURE__ */ React.createElement(X, {
81
+ weight: "bold",
82
+ className: getSize(4)
83
+ }))), /* @__PURE__ */ React.createElement("div", {
84
+ className: "flex grow pli-4 mlb-2"
85
+ }, content), /* @__PURE__ */ React.createElement("div", {
86
+ className: "flex p-2 items-center justify-between",
87
+ ...arrowGroup
88
+ }, /* @__PURE__ */ React.createElement(Button, {
89
+ variant: "primary",
90
+ onClick: backProps.onClick,
91
+ title: backProps["aria-label"],
92
+ classNames: [
93
+ !(index > 0 && backProps) && "invisible"
94
+ ],
95
+ "data-testid": "helpPlugin.tooltip.back"
96
+ }, /* @__PURE__ */ React.createElement(CaretLeft, {
97
+ className: getSize(5)
98
+ })), /* @__PURE__ */ React.createElement("div", {
99
+ className: "flex grow gap-2 justify-center"
100
+ }, /* @__PURE__ */ React.createElement("div", {
101
+ className: "flex"
102
+ }, Array.from({
103
+ length: size
104
+ }).map((_, i) => /* @__PURE__ */ React.createElement(Circle, {
105
+ key: i,
106
+ weight: index === i ? "fill" : "regular",
107
+ className: mx(getSize(2), "mli-1 cursor-pointer")
108
+ })))), isLastStep ? /* @__PURE__ */ React.createElement(Button, {
109
+ variant: "primary",
110
+ onClick: closeProps.onClick,
111
+ title: closeProps["aria-label"],
112
+ autoFocus: true,
113
+ "data-testid": "helpPlugin.tooltip.finish"
114
+ }, "Done") : /* @__PURE__ */ React.createElement(Button, {
115
+ variant: "primary",
116
+ onClick: primaryProps.onClick,
117
+ title: primaryProps["aria-label"],
118
+ autoFocus: true,
119
+ "data-testid": "helpPlugin.tooltip.next"
120
+ }, /* @__PURE__ */ React.createElement(CaretRight, {
121
+ className: getSize(6)
122
+ }))));
123
+ });
124
+
125
+ // packages/plugins/plugin-help/src/components/HelpContextProvider/HelpContextProvider.tsx
126
+ var tokens = tailwindConfig({}).theme;
127
+ var addStepClass = (target) => {
128
+ const element = typeof target === "string" ? document.querySelector(target) : target;
129
+ if (element) {
130
+ element.classList.add("joyride-target");
131
+ }
132
+ };
133
+ var removeTargetClass = (target) => {
134
+ const element = typeof target === "string" ? document.querySelector(target) : target;
135
+ if (element) {
136
+ element.classList.remove("joyride-target");
137
+ }
138
+ };
139
+ var getTarget = (step) => {
140
+ return typeof step.target === "string" ? document.querySelector(step.target) : step.target;
141
+ };
142
+ var waitForTarget = async (step) => {
143
+ if (typeof step.target === "string") {
144
+ const target = step.target;
145
+ const element = document.querySelector(target);
146
+ if (element) {
147
+ return;
148
+ }
149
+ await new Promise((resolve) => {
150
+ const observer = new MutationObserver((mutations) => {
151
+ mutations.forEach((mutation) => {
152
+ if (mutation.addedNodes.length > 0) {
153
+ const element2 = document.querySelector(target);
154
+ if (element2) {
155
+ observer.disconnect();
156
+ resolve();
157
+ }
158
+ }
159
+ });
160
+ });
161
+ observer.observe(document.body, {
162
+ childList: true,
163
+ subtree: true
164
+ });
165
+ });
166
+ }
167
+ };
168
+ var HelpContextProvider = ({ children, steps: initialSteps, running: runningProp, onRunningChanged }) => {
169
+ const shellDisplay = useShellDisplay();
170
+ const { plugins } = usePlugins();
171
+ const layoutPlugin = resolvePlugin(plugins, parseLayoutPlugin);
172
+ const [running, setRunning] = useState(!!runningProp && !!getTarget(initialSteps[0]));
173
+ const [stepIndex, _setStepIndex] = useState(0);
174
+ const [steps, setSteps] = useState(initialSteps);
175
+ const paused = shellDisplay !== ShellDisplay.NONE || layoutPlugin?.provides.layout.dialogOpen;
176
+ const setStepIndex = (index) => {
177
+ if (runningProp) {
178
+ const step = steps[index];
179
+ step?.before?.({
180
+ plugins,
181
+ step
182
+ });
183
+ }
184
+ _setStepIndex(index);
185
+ };
186
+ const setRunningChanged = (state) => {
187
+ if (typeof runningProp !== "undefined") {
188
+ onRunningChanged?.(state);
189
+ } else {
190
+ if (state) {
191
+ setStepIndex(0);
192
+ setRunning(true);
193
+ } else {
194
+ setRunning(false);
195
+ }
196
+ }
197
+ };
198
+ useEffect(() => {
199
+ const timeout = setTimeout(async () => {
200
+ if (runningProp) {
201
+ await waitForTarget(steps[stepIndex]);
202
+ setStepIndex(0);
203
+ setRunning(true);
204
+ } else if (typeof runningProp !== "undefined") {
205
+ setRunning(false);
206
+ }
207
+ });
208
+ return () => clearTimeout(timeout);
209
+ }, [
210
+ runningProp
211
+ ]);
212
+ const callback = async (options) => {
213
+ const { type, action, index, size } = options;
214
+ switch (type) {
215
+ case EVENTS.STEP_BEFORE:
216
+ addStepClass(options.step.target);
217
+ break;
218
+ case EVENTS.TOUR_END:
219
+ break;
220
+ case EVENTS.STEP_AFTER:
221
+ removeTargetClass(options.step.target);
222
+ switch (action) {
223
+ case ACTIONS.NEXT:
224
+ if (index < size - 1) {
225
+ setStepIndex(index + 1);
226
+ }
227
+ break;
228
+ case ACTIONS.PREV:
229
+ if (index > 0) {
230
+ setStepIndex(index - 1);
231
+ }
232
+ break;
233
+ case ACTIONS.CLOSE:
234
+ setRunningChanged(false);
235
+ setStepIndex(0);
236
+ break;
237
+ }
238
+ break;
239
+ }
240
+ };
241
+ return /* @__PURE__ */ React2.createElement(HelpContext.Provider, {
242
+ value: {
243
+ running: running && !paused,
244
+ steps,
245
+ setSteps,
246
+ setIndex: setStepIndex,
247
+ start: () => setRunningChanged(true),
248
+ stop: () => setRunningChanged(false)
249
+ }
250
+ }, /* @__PURE__ */ React2.createElement("style", null, `.joyride-target {
251
+ --controls-opacity: 1;
252
+ }`), /* @__PURE__ */ React2.createElement(Joyride, {
253
+ continuous: true,
254
+ steps,
255
+ stepIndex,
256
+ run: running && !paused,
257
+ callback,
258
+ floaterProps,
259
+ tooltipComponent: Tooltip
260
+ }), children);
261
+ };
262
+
263
+ // packages/plugins/plugin-help/src/components/Shortcuts/ShortcutsDialog.tsx
264
+ import React5 from "react";
265
+ import { Button as Button2, Dialog, useTranslation as useTranslation2 } from "@dxos/react-ui";
266
+
267
+ // packages/plugins/plugin-help/src/components/Shortcuts/ShortcutsList.tsx
268
+ import React4, { Fragment } from "react";
269
+ import { Keyboard } from "@dxos/keyboard";
270
+ import { toLocalizedString, useTranslation } from "@dxos/react-ui";
271
+ import { mx as mx3 } from "@dxos/react-ui-theme";
272
+
273
+ // packages/plugins/plugin-help/src/components/Shortcuts/Key.tsx
274
+ import React3 from "react";
275
+ import { keySymbols } from "@dxos/keyboard";
276
+
277
+ // packages/plugins/plugin-help/src/components/Shortcuts/styles.ts
278
+ import { mx as mx2 } from "@dxos/react-ui-theme";
279
+ var shortcutKey = mx2("inline-flex min-is-[24px] bs-[24px] pli-0.5 justify-center items-center text-xs", "rounded bg-neutral-100 dark:bg-neutral-900");
280
+
281
+ // packages/plugins/plugin-help/src/components/Shortcuts/Key.tsx
282
+ var Key = ({ binding }) => {
283
+ return /* @__PURE__ */ React3.createElement("span", {
284
+ role: "term",
285
+ className: "inline-flex gap-1",
286
+ "aria-label": binding,
287
+ id: binding
288
+ }, keySymbols(binding).map((c, i) => /* @__PURE__ */ React3.createElement("span", {
289
+ key: i,
290
+ className: shortcutKey
291
+ }, c)));
292
+ };
293
+
294
+ // packages/plugins/plugin-help/src/components/Shortcuts/ShortcutsList.tsx
295
+ var ShortcutsList = () => {
296
+ const { t } = useTranslation(HELP_PLUGIN);
297
+ const bindings = Keyboard.singleton.getBindings();
298
+ bindings.sort((a, b) => {
299
+ return toLocalizedString(a.data, t)?.toLowerCase().localeCompare(toLocalizedString(b.data, t)?.toLowerCase());
300
+ });
301
+ return /* @__PURE__ */ React4.createElement("dl", {
302
+ className: mx3("is-fit grid grid-cols-[min-content_minmax(12rem,1fr)] gap-2 mlb-4 fg-subdued")
303
+ }, bindings.map((binding, i) => /* @__PURE__ */ React4.createElement(Fragment, {
304
+ key: i
305
+ }, /* @__PURE__ */ React4.createElement(Key, {
306
+ binding: binding.shortcut
307
+ }), /* @__PURE__ */ React4.createElement("span", {
308
+ role: "definition",
309
+ className: "mis-4",
310
+ "aria-labelledby": binding.shortcut
311
+ }, toLocalizedString(binding.data, t)))));
312
+ };
313
+
314
+ // packages/plugins/plugin-help/src/components/Shortcuts/ShortcutsDialog.tsx
315
+ var ShortcutsDialogContent = () => {
316
+ const { t } = useTranslation2(HELP_PLUGIN);
317
+ return /* @__PURE__ */ React5.createElement(Dialog.Content, {
318
+ classNames: "max-bs-[40rem] md:is-auto overflow-hidden"
319
+ }, /* @__PURE__ */ React5.createElement(Dialog.Title, null, t("shortcuts dialog title")), /* @__PURE__ */ React5.createElement("div", {
320
+ className: "grow overflow-y-auto py-2"
321
+ }, /* @__PURE__ */ React5.createElement(ShortcutsList, null)), /* @__PURE__ */ React5.createElement(Dialog.Close, {
322
+ asChild: true
323
+ }, /* @__PURE__ */ React5.createElement(Button2, {
324
+ variant: "primary",
325
+ classNames: "mbs-2"
326
+ }, t("close label", {
327
+ ns: "os"
328
+ }))));
329
+ };
330
+
331
+ // packages/plugins/plugin-help/src/components/Shortcuts/ShortcutsHints.tsx
332
+ import { X as X2 } from "@phosphor-icons/react";
333
+ import React6 from "react";
334
+ import { Keyboard as Keyboard2 } from "@dxos/keyboard";
335
+ import { Button as Button3, DensityProvider, toLocalizedString as toLocalizedString2, useTranslation as useTranslation3 } from "@dxos/react-ui";
336
+ import { fixedBorder, groupSurface, mx as mx4 } from "@dxos/react-ui-theme";
337
+ var ShortcutsHints = ({ onClose }) => {
338
+ const { t } = useTranslation3("os");
339
+ const defaults = [
340
+ "meta+k",
341
+ "meta+/",
342
+ "meta+,"
343
+ ];
344
+ const bindings = Keyboard2.singleton.getBindings();
345
+ const hints = bindings.filter((binding) => defaults.includes(binding.shortcut));
346
+ const Shortcut = ({ binding }) => {
347
+ return /* @__PURE__ */ React6.createElement("div", {
348
+ role: "none",
349
+ className: "flex items-center gap-2"
350
+ }, /* @__PURE__ */ React6.createElement(Key, {
351
+ binding: binding.shortcut
352
+ }), /* @__PURE__ */ React6.createElement("span", {
353
+ className: "text-sm"
354
+ }, toLocalizedString2(binding.data, t)));
355
+ };
356
+ return /* @__PURE__ */ React6.createElement(DensityProvider, {
357
+ density: "fine"
358
+ }, /* @__PURE__ */ React6.createElement("div", {
359
+ className: mx4("flex items-center border rounded px-2 gap-4", fixedBorder, groupSurface)
360
+ }, hints.map((binding) => /* @__PURE__ */ React6.createElement(Shortcut, {
361
+ key: binding.shortcut,
362
+ binding
363
+ })), /* @__PURE__ */ React6.createElement(Button3, {
364
+ variant: "ghost",
365
+ classNames: "p-0 cursor-pointer",
366
+ onClick: onClose
367
+ }, /* @__PURE__ */ React6.createElement(X2, null))));
368
+ };
369
+
370
+ // packages/plugins/plugin-help/src/components/Shortcuts/ShortcutsSection.tsx
371
+ import React7 from "react";
372
+ import { descriptionText } from "@dxos/react-ui-theme";
373
+ var ShortcutsSection = () => {
374
+ return /* @__PURE__ */ React7.createElement("section", {
375
+ className: descriptionText
376
+ }, /* @__PURE__ */ React7.createElement(ShortcutsList, null));
377
+ };
378
+
379
+ // packages/plugins/plugin-help/src/translations.ts
380
+ var translations_default = [
381
+ {
382
+ "en-US": {
383
+ [HELP_PLUGIN]: {
384
+ "plugin name": "Help",
385
+ "open help tour": "Show welcome tour",
386
+ "open shortcuts label": "Show shortcuts",
387
+ "shortcuts dialog title": "Shortcuts"
388
+ }
389
+ }
390
+ }
391
+ ];
392
+
393
+ // packages/plugins/plugin-help/src/HelpPlugin.tsx
394
+ var HelpPlugin = ({ steps = [] }) => {
395
+ const settings = new LocalStorageStore(HELP_PLUGIN, {
396
+ showHints: true,
397
+ showWelcome: true
398
+ });
399
+ const state = create({
400
+ running: false
401
+ });
402
+ return {
403
+ meta: meta_default,
404
+ ready: async () => {
405
+ settings.prop({
406
+ key: "showHints",
407
+ storageKey: "show-hints",
408
+ type: LocalStorageStore.bool({
409
+ allowUndefined: true
410
+ })
411
+ }).prop({
412
+ key: "showWelcome",
413
+ storageKey: "show-welcome",
414
+ type: LocalStorageStore.bool({
415
+ allowUndefined: true
416
+ })
417
+ });
418
+ },
419
+ provides: {
420
+ context: ({ children }) => {
421
+ return /* @__PURE__ */ React8.createElement(HelpContextProvider, {
422
+ steps,
423
+ running: state.running,
424
+ onRunningChanged: (newState) => {
425
+ state.running = newState;
426
+ if (!newState) {
427
+ settings.values.showHints = false;
428
+ }
429
+ }
430
+ }, children);
431
+ },
432
+ translations: translations_default,
433
+ graph: {
434
+ builder: (plugins) => {
435
+ const intentPlugin = resolvePlugin2(plugins, parseIntentPlugin);
436
+ return createExtension({
437
+ id: HELP_PLUGIN,
438
+ filter: (node) => node.id === "root",
439
+ actions: () => [
440
+ {
441
+ id: HelpAction.START,
442
+ data: async () => {
443
+ settings.values.showHints = true;
444
+ await intentPlugin?.provides.intent.dispatch({
445
+ plugin: HELP_PLUGIN,
446
+ action: HelpAction.START
447
+ });
448
+ },
449
+ properties: {
450
+ label: [
451
+ "open help tour",
452
+ {
453
+ ns: HELP_PLUGIN
454
+ }
455
+ ],
456
+ icon: (props) => /* @__PURE__ */ React8.createElement(Info, props),
457
+ iconSymbol: "ph--info--regular",
458
+ keyBinding: {
459
+ macos: "shift+meta+/",
460
+ // TODO(wittjosiah): Test on windows to see if it behaves the same as linux.
461
+ windows: "shift+ctrl+/",
462
+ linux: "shift+ctrl+?"
463
+ },
464
+ testId: "helpPlugin.openHelp"
465
+ }
466
+ },
467
+ {
468
+ id: "dxos.org/plugin/help/open-shortcuts",
469
+ data: async () => {
470
+ settings.values.showHints = true;
471
+ await intentPlugin?.provides.intent.dispatch({
472
+ action: LayoutAction.SET_LAYOUT,
473
+ data: {
474
+ element: "dialog",
475
+ component: `${HELP_PLUGIN}/Shortcuts`
476
+ }
477
+ });
478
+ },
479
+ properties: {
480
+ label: [
481
+ "open shortcuts label",
482
+ {
483
+ ns: HELP_PLUGIN
484
+ }
485
+ ],
486
+ icon: (props) => /* @__PURE__ */ React8.createElement(KeyboardIcon, props),
487
+ iconSymbol: "ph--keyboard--regular",
488
+ keyBinding: {
489
+ macos: "meta+/",
490
+ windows: "ctrl+/"
491
+ }
492
+ }
493
+ }
494
+ ]
495
+ });
496
+ }
497
+ },
498
+ surface: {
499
+ component: ({ data, role }) => {
500
+ switch (role) {
501
+ case "hints":
502
+ return settings.values.showHints ? /* @__PURE__ */ React8.createElement(ShortcutsHints, {
503
+ onClose: () => settings.values.showHints = false
504
+ }) : null;
505
+ case "keyshortcuts":
506
+ return /* @__PURE__ */ React8.createElement(ShortcutsList, null);
507
+ }
508
+ switch (data.component) {
509
+ case `${HELP_PLUGIN}/Shortcuts`:
510
+ return /* @__PURE__ */ React8.createElement(ShortcutsDialogContent, null);
511
+ }
512
+ return null;
513
+ }
514
+ },
515
+ intent: {
516
+ resolver: async (intent) => {
517
+ switch (intent.action) {
518
+ case HelpAction.START:
519
+ state.running = true;
520
+ break;
521
+ }
522
+ }
523
+ }
524
+ }
525
+ };
526
+ };
527
+
528
+ // packages/plugins/plugin-help/src/hooks/useHelp.tsx
529
+ import { useContext } from "react";
530
+ import { raise } from "@dxos/debug";
531
+ var useHelp = () => {
532
+ return useContext(HelpContext) ?? raise(new Error("Missing HelpContext"));
533
+ };
534
+
535
+ // packages/plugins/plugin-help/src/index.ts
536
+ var src_default = HelpPlugin;
537
+ export {
538
+ HelpContextProvider,
539
+ HelpPlugin,
540
+ Key,
541
+ ShortcutsDialogContent,
542
+ ShortcutsHints,
543
+ ShortcutsList,
544
+ ShortcutsSection,
545
+ Tooltip,
546
+ src_default as default,
547
+ floaterProps,
548
+ tokens,
549
+ useHelp
550
+ };
551
+ //# sourceMappingURL=index.mjs.map