@dxos/plugin-navtree 0.7.5-main.499c70c → 0.7.5-main.937ce75

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.
@@ -13,7 +13,7 @@ import { createExtension, isAction as isAction5, isGraphNode } from "@dxos/app-g
13
13
  import { Keyboard as Keyboard2 } from "@dxos/keyboard";
14
14
  import { create } from "@dxos/live-object";
15
15
  import { Path } from "@dxos/react-ui-mosaic";
16
- import { getHostPlatform as getHostPlatform3 } from "@dxos/util";
16
+ import { getHostPlatform as getHostPlatform2 } from "@dxos/util";
17
17
 
18
18
  // packages/plugins/plugin-navtree/src/components/CommandsDialog.tsx
19
19
  import React, { useMemo, useState } from "react";
@@ -123,175 +123,42 @@ import { Popover, toLocalizedString as toLocalizedString3, Treegrid, useTranslat
123
123
  import { Tree } from "@dxos/react-ui-list";
124
124
 
125
125
  // packages/plugins/plugin-navtree/src/components/NavTreeItemAction.tsx
126
- import { useControllableState } from "@radix-ui/react-use-controllable-state";
127
- import React2, { useRef, useState as useState2 } from "react";
128
- import { keySymbols as keySymbols2 } from "@dxos/keyboard";
129
- import { Button as Button2, Dialog as Dialog2, DropdownMenu, ContextMenu, Tooltip, useTranslation as useTranslation2, toLocalizedString as toLocalizedString2, Icon as Icon2 } from "@dxos/react-ui";
130
- import { SearchList as SearchList2 } from "@dxos/react-ui-searchlist";
131
- import { descriptionText as descriptionText2, hoverableControlItem, hoverableOpenControlItem, mx as mx2 } from "@dxos/react-ui-theme";
132
- import { getHostPlatform as getHostPlatform2 } from "@dxos/util";
133
- var getShortcut = (action) => {
134
- return typeof action.properties?.keyBinding === "string" ? action.properties.keyBinding : action.properties?.keyBinding?.[getHostPlatform2()];
135
- };
126
+ import React2, { useRef } from "react";
127
+ import { useTranslation as useTranslation2, toLocalizedString as toLocalizedString2, IconButton } from "@dxos/react-ui";
128
+ import { DropdownMenu } from "@dxos/react-ui-menu";
129
+ import { hoverableControlItem, hoverableOpenControlItem, mx as mx2 } from "@dxos/react-ui-theme";
136
130
  var fallbackIcon = "ph--placeholder--regular";
137
- var NavTreeItemActionDropdownMenu = ({ label, icon, testId, defaultMenuOpen, menuActions, menuOpen, suppressNextTooltip, onChangeMenuOpen, onAction }) => {
131
+ var actionButtonProps = {
132
+ iconOnly: true,
133
+ size: 4,
134
+ variant: "ghost",
135
+ density: "fine",
136
+ classNames: mx2("shrink-0 !pli-2 pointer-fine:!pli-1", hoverableControlItem, hoverableOpenControlItem)
137
+ };
138
+ var NavTreeItemActionDropdownMenu = ({ label, icon, testId, menuActions, onAction }) => {
138
139
  const { t } = useTranslation2(NAVTREE_PLUGIN);
139
- const [optionsMenuOpen, setOptionsMenuOpen] = useControllableState({
140
- prop: menuOpen,
141
- defaultProp: defaultMenuOpen,
142
- onChange: onChangeMenuOpen
143
- });
140
+ const suppressNextTooltip = useRef(false);
144
141
  return /* @__PURE__ */ React2.createElement(DropdownMenu.Root, {
145
- open: optionsMenuOpen,
146
- onOpenChange: (nextOpen) => {
147
- if (!nextOpen && suppressNextTooltip) {
148
- suppressNextTooltip.current = true;
149
- }
150
- return setOptionsMenuOpen(nextOpen);
151
- }
152
- }, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
153
- asChild: true
142
+ actions: menuActions,
143
+ onAction,
144
+ suppressNextTooltip
154
145
  }, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
155
146
  asChild: true
156
- }, /* @__PURE__ */ React2.createElement(Button2, {
157
- variant: "ghost",
158
- density: "fine",
159
- classNames: mx2("shrink-0 !pli-2 pointer-fine:!pli-1", hoverableControlItem, hoverableOpenControlItem),
160
- "data-testid": testId,
161
- "aria-label": t("tree item actions label")
162
- }, /* @__PURE__ */ React2.createElement("span", {
163
- className: "sr-only"
164
- }, toLocalizedString2(label, t)), /* @__PURE__ */ React2.createElement(Icon2, {
147
+ }, /* @__PURE__ */ React2.createElement(IconButton, {
148
+ ...actionButtonProps,
165
149
  icon: icon ?? fallbackIcon,
166
- size: 4
167
- })))), /* @__PURE__ */ React2.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Viewport, null, menuActions?.map((action) => {
168
- const shortcut = getShortcut(action);
169
- return /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
170
- key: action.id,
171
- onClick: (event) => {
172
- if (action.properties?.disabled) {
173
- return;
174
- }
175
- event.stopPropagation();
176
- if (suppressNextTooltip) {
177
- suppressNextTooltip.current = true;
178
- }
179
- setOptionsMenuOpen(false);
180
- onAction?.(action);
181
- },
182
- classNames: "gap-2",
183
- disabled: action.properties?.disabled,
184
- ...action.properties?.testId && {
185
- "data-testid": action.properties.testId
186
- }
187
- }, action.properties?.icon && /* @__PURE__ */ React2.createElement(Icon2, {
188
- icon: action.properties.icon,
189
- size: 4
190
- }), /* @__PURE__ */ React2.createElement("span", {
191
- className: "grow truncate"
192
- }, toLocalizedString2(action.properties.label, t)), shortcut && /* @__PURE__ */ React2.createElement("span", {
193
- className: mx2("shrink-0", descriptionText2)
194
- }, keySymbols2(shortcut).join("")));
195
- })), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null))));
196
- };
197
- var NavTreeItemActionSearchList = ({ menuActions, icon, label, testId, suppressNextTooltip, onAction }) => {
198
- const { t } = useTranslation2(NAVTREE_PLUGIN);
199
- const [optionsMenuOpen, setOptionsMenuOpen] = useState2(false);
200
- const button = useRef(null);
201
- const sortedActions = menuActions?.sort(({ properties: p1 }, { properties: p2 }) => {
202
- const t1 = toLocalizedString2(p1.label, t).toLowerCase();
203
- const t2 = toLocalizedString2(p2.label, t).toLowerCase();
204
- return t1.localeCompare(t2);
205
- });
206
- return /* @__PURE__ */ React2.createElement(Dialog2.Root, {
207
- open: optionsMenuOpen,
208
- onOpenChange: (nextOpen) => {
209
- if (!nextOpen && suppressNextTooltip) {
210
- suppressNextTooltip.current = true;
211
- }
212
- return setOptionsMenuOpen(nextOpen);
213
- }
214
- }, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
215
- asChild: true
216
- }, /* @__PURE__ */ React2.createElement(Dialog2.Trigger, {
217
- asChild: true
218
- }, /* @__PURE__ */ React2.createElement(Button2, {
219
- variant: "ghost",
220
- density: "fine",
221
- classNames: mx2("shrink-0 !pli-2 pointer-fine:!pli-1", hoverableControlItem, hoverableOpenControlItem),
150
+ label: toLocalizedString2(label, t),
222
151
  "data-testid": testId,
223
- onKeyDownCapture: (event) => {
224
- if (button.current && button.current === event.target) {
225
- switch (event.key) {
226
- case "Enter":
227
- case " ":
228
- event.stopPropagation();
229
- setOptionsMenuOpen(true);
230
- break;
231
- default:
232
- }
233
- }
234
- },
235
- ref: button
236
- }, /* @__PURE__ */ React2.createElement(Icon2, {
237
- icon: icon ?? fallbackIcon,
238
- size: 4
239
- })))), /* @__PURE__ */ React2.createElement(Dialog2.Portal, null, /* @__PURE__ */ React2.createElement(Dialog2.Overlay, null, /* @__PURE__ */ React2.createElement(Dialog2.Content, {
240
- classNames: "is-full max-is-[24rem] pli-2 plb-1"
241
- }, /* @__PURE__ */ React2.createElement(SearchList2.Root, {
242
- label: t("tree item searchlist input placeholder")
243
- }, /* @__PURE__ */ React2.createElement(SearchList2.Input, {
244
- placeholder: t("tree item searchlist input placeholder"),
245
- classNames: "pli-3"
246
- }), /* @__PURE__ */ React2.createElement(SearchList2.Content, {
247
- classNames: "min-bs-[12rem] bs-[50dvh] max-bs-[30rem] overflow-auto"
248
- }, sortedActions?.map((action) => {
249
- const label2 = toLocalizedString2(action.properties.label, t);
250
- const shortcut = getShortcut(action);
251
- return /* @__PURE__ */ React2.createElement(SearchList2.Item, {
252
- // TODO(burdon): Value should be id since label is not unique.
253
- value: label2,
254
- key: action.id,
255
- onSelect: () => {
256
- if (action.properties?.disabled) {
257
- return;
258
- }
259
- if (suppressNextTooltip) {
260
- suppressNextTooltip.current = true;
261
- }
262
- setOptionsMenuOpen(false);
263
- onAction?.(action);
264
- },
265
- classNames: "flex items-center gap-2 pli-2",
266
- disabled: action.properties?.disabled,
267
- ...action.properties?.testId && {
268
- "data-testid": action.properties.testId
269
- }
270
- }, action.properties?.icon && /* @__PURE__ */ React2.createElement(Icon2, {
271
- icon: action.properties?.icon,
272
- size: 4
273
- }), /* @__PURE__ */ React2.createElement("span", {
274
- className: "grow truncate"
275
- }, label2), shortcut && /* @__PURE__ */ React2.createElement("span", {
276
- className: mx2("shrink-0", descriptionText2)
277
- }, keySymbols2(shortcut).join("")));
278
- })), /* @__PURE__ */ React2.createElement("div", {
279
- role: "none",
280
- className: "flex items-center plb-2 pli-3"
281
- }, /* @__PURE__ */ React2.createElement("span", {
282
- className: descriptionText2
283
- }, toLocalizedString2(label, t))))))));
152
+ suppressNextTooltip
153
+ })));
284
154
  };
285
- var NavTreeItemMonolithicAction = ({ parent, properties: { disabled, caller, testId, label, icon } = {
155
+ var NavTreeItemMonolithicAction = ({ parent, properties: { disabled, caller, testId, icon } = {
286
156
  label: "never"
287
- }, data: invoke }) => {
288
- const { t } = useTranslation2(NAVTREE_PLUGIN);
289
- return /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
290
- asChild: true
291
- }, /* @__PURE__ */ React2.createElement(Button2, {
292
- variant: "ghost",
293
- density: "fine",
294
- classNames: mx2("shrink-0 !pli-2 pointer-fine:!pli-1", hoverableControlItem, hoverableOpenControlItem),
157
+ }, data: invoke, baseLabel }) => {
158
+ return /* @__PURE__ */ React2.createElement(IconButton, {
159
+ ...actionButtonProps,
160
+ icon: icon ?? fallbackIcon,
161
+ label: baseLabel,
295
162
  disabled,
296
163
  onClick: (event) => {
297
164
  if (disabled) {
@@ -306,70 +173,39 @@ var NavTreeItemMonolithicAction = ({ parent, properties: { disabled, caller, tes
306
173
  });
307
174
  },
308
175
  "data-testid": testId
309
- }, /* @__PURE__ */ React2.createElement("span", {
310
- className: "sr-only"
311
- }, toLocalizedString2(label, t)), /* @__PURE__ */ React2.createElement(Icon2, {
312
- icon: icon ?? fallbackIcon,
313
- size: 4
314
- })));
176
+ });
315
177
  };
316
178
  var NavTreeItemAction = ({ monolithic, menuActions, parent: node, ...props }) => {
317
179
  const { t } = useTranslation2(NAVTREE_PLUGIN);
318
- const suppressNextTooltip = useRef(false);
319
- const [triggerTooltipOpen, setTriggerTooltipOpen] = useState2(false);
320
180
  const monolithicAction = menuActions?.length === 1 && menuActions[0];
321
181
  const baseLabel = toLocalizedString2(monolithicAction ? monolithicAction.properties.label : props.label, t);
322
- return /* @__PURE__ */ React2.createElement(Tooltip.Root, {
323
- open: triggerTooltipOpen,
324
- onOpenChange: (nextOpen) => {
325
- if (suppressNextTooltip.current) {
326
- setTriggerTooltipOpen(false);
327
- suppressNextTooltip.current = false;
328
- } else {
329
- setTriggerTooltipOpen(nextOpen);
330
- }
331
- }
332
- }, baseLabel && /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, {
333
- classNames: "z-[31]",
334
- side: "bottom"
335
- }, baseLabel, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null))), monolithic && menuActions?.length === 1 ? /* @__PURE__ */ React2.createElement(NavTreeItemMonolithicAction, {
182
+ return monolithic && menuActions?.length === 1 ? /* @__PURE__ */ React2.createElement(NavTreeItemMonolithicAction, {
183
+ baseLabel,
336
184
  parent: node,
337
185
  ...menuActions[0]
338
- }) : props.menuType === "searchList" ? /* @__PURE__ */ React2.createElement(NavTreeItemActionSearchList, {
339
- ...props,
340
- menuActions,
341
- suppressNextTooltip,
342
- onAction: (action) => action.data?.(props.caller ? {
343
- node,
344
- caller: props.caller
345
- } : {
346
- node
347
- })
348
186
  }) : /* @__PURE__ */ React2.createElement(NavTreeItemActionDropdownMenu, {
349
187
  ...props,
188
+ label: baseLabel,
350
189
  parent: node,
351
190
  menuActions,
352
- suppressNextTooltip,
353
191
  onAction: (action) => action.data?.(props.caller ? {
354
192
  node,
355
193
  caller: props.caller
356
194
  } : {
357
195
  node
358
196
  })
359
- }));
197
+ });
360
198
  };
361
199
 
362
200
  // packages/plugins/plugin-navtree/src/components/NavTree.tsx
363
201
  var NAV_TREE_ITEM = "NavTreeItem";
364
202
  var NavTree = ({ getActions: getActions2, loadDescendents, renderItemEnd: renderItemEnd2, popoverAnchorId, ...props }) => {
365
- const renderColumns = useCallback(({ item, path, open, menuOpen, setMenuOpen }) => {
203
+ const renderColumns = useCallback(({ item, path, open }) => {
366
204
  return /* @__PURE__ */ React3.createElement(NavTreeColumns, {
367
205
  path,
368
206
  node: item,
369
207
  getActions: getActions2,
370
208
  open,
371
- menuOpen,
372
- setMenuOpen,
373
209
  loadDescendents,
374
210
  renderItemEnd: renderItemEnd2,
375
211
  popoverAnchorId
@@ -386,7 +222,7 @@ var NavTree = ({ getActions: getActions2, loadDescendents, renderItemEnd: render
386
222
  renderColumns
387
223
  });
388
224
  };
389
- var NavTreeColumns = ({ path, node, getActions: getActions2, open, menuOpen, setMenuOpen, loadDescendents, renderItemEnd: ItemEnd, popoverAnchorId }) => {
225
+ var NavTreeColumns = ({ path, node, getActions: getActions2, open, loadDescendents, renderItemEnd: ItemEnd, popoverAnchorId }) => {
390
226
  const { t } = useTranslation3(NAVTREE_PLUGIN);
391
227
  const level = path.length - 2;
392
228
  const { actions: _actions, groupedActions } = getActions2(node);
@@ -424,9 +260,7 @@ var NavTreeColumns = ({ path, node, getActions: getActions2, open, menuOpen, set
424
260
  parent: node,
425
261
  menuActions: actions,
426
262
  menuType: "dropdown",
427
- caller: NAV_TREE_ITEM,
428
- menuOpen,
429
- onChangeMenuOpen: setMenuOpen
263
+ caller: NAV_TREE_ITEM
430
264
  }) : /* @__PURE__ */ React3.createElement(Treegrid.Cell, null)), ItemEnd && /* @__PURE__ */ React3.createElement(ItemEnd, {
431
265
  node,
432
266
  open
@@ -453,7 +287,7 @@ import { formatDistance } from "date-fns/formatDistance";
453
287
  import React4 from "react";
454
288
  import { SettingsAction, parseNavigationPlugin, useResolvePlugin, useIntentDispatcher as useIntentDispatcher2, createIntent as createIntent2 } from "@dxos/app-framework";
455
289
  import { useConfig } from "@dxos/react-client";
456
- import { Button as Button3, Link, Message, Popover as Popover2, Tooltip as Tooltip2, Trans, useDefaultValue, useSidebars, useTranslation as useTranslation4 } from "@dxos/react-ui";
290
+ import { Button as Button2, Link, Message, Popover as Popover2, Tooltip, Trans, useDefaultValue, useSidebars, useTranslation as useTranslation4 } from "@dxos/react-ui";
457
291
  import { LayoutControls } from "@dxos/react-ui-stack";
458
292
  import { getSize, mx as mx3 } from "@dxos/react-ui-theme";
459
293
  var buttonStyles = "pli-1.5 text-xs font-normal";
@@ -475,7 +309,7 @@ var NavTreeFooter = (props) => {
475
309
  className: mx3("flex bs-[--rail-size] pbe-[env(safe-area-inset-bottom)] box-content justify-end", layoutPart === "complementary" && "md:justify-end flex-row-reverse")
476
310
  }, /* @__PURE__ */ React4.createElement(Popover2.Root, null, /* @__PURE__ */ React4.createElement(Popover2.Trigger, {
477
311
  asChild: true
478
- }, /* @__PURE__ */ React4.createElement(Button3, {
312
+ }, /* @__PURE__ */ React4.createElement(Button2, {
479
313
  variant: "ghost",
480
314
  classNames: buttonStyles,
481
315
  ...!navigationSidebarOpen && {
@@ -525,9 +359,9 @@ var NavTreeFooter = (props) => {
525
359
  variant: "neutral"
526
360
  })
527
361
  }
528
- }))), /* @__PURE__ */ React4.createElement(Popover2.Arrow, null)))), /* @__PURE__ */ React4.createElement(Tooltip2.Root, null, /* @__PURE__ */ React4.createElement(Tooltip2.Trigger, {
362
+ }))), /* @__PURE__ */ React4.createElement(Popover2.Arrow, null)))), /* @__PURE__ */ React4.createElement(Tooltip.Root, null, /* @__PURE__ */ React4.createElement(Tooltip.Trigger, {
529
363
  asChild: true
530
- }, /* @__PURE__ */ React4.createElement(Button3, {
364
+ }, /* @__PURE__ */ React4.createElement(Button2, {
531
365
  variant: "ghost",
532
366
  classNames: buttonStyles,
533
367
  "data-testid": "treeView.openSettings",
@@ -540,9 +374,9 @@ var NavTreeFooter = (props) => {
540
374
  className: "sr-only"
541
375
  }, t("open settings label")), /* @__PURE__ */ React4.createElement(GearSix, {
542
376
  className: mx3(getSize(5), "rotate-90")
543
- }))), /* @__PURE__ */ React4.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React4.createElement(Tooltip2.Content, {
377
+ }))), /* @__PURE__ */ React4.createElement(Tooltip.Portal, null, /* @__PURE__ */ React4.createElement(Tooltip.Content, {
544
378
  classNames: "z-[12]"
545
- }, t("open settings label"), /* @__PURE__ */ React4.createElement(Tooltip2.Arrow, null)))), navigationPlugin?.meta.id === "dxos.org/plugin/deck" && /* @__PURE__ */ React4.createElement(LayoutControls, {
379
+ }, t("open settings label"), /* @__PURE__ */ React4.createElement(Tooltip.Arrow, null)))), navigationPlugin?.meta.id === "dxos.org/plugin/deck" && /* @__PURE__ */ React4.createElement(LayoutControls, {
546
380
  variant: "hide-disabled",
547
381
  capabilities: {
548
382
  incrementStart: false,
@@ -913,12 +747,12 @@ var NotchStart = () => {
913
747
  import { MagnifyingGlass } from "@phosphor-icons/react";
914
748
  import React8 from "react";
915
749
  import { createIntent as createIntent5, LayoutAction as LayoutAction3, useIntentDispatcher as useIntentDispatcher5 } from "@dxos/app-framework";
916
- import { Button as Button4, useTranslation as useTranslation6 } from "@dxos/react-ui";
750
+ import { Button as Button3, useTranslation as useTranslation6 } from "@dxos/react-ui";
917
751
  import { getSize as getSize2 } from "@dxos/react-ui-theme";
918
752
  var CommandsTrigger = () => {
919
753
  const { dispatchPromise: dispatch } = useIntentDispatcher5();
920
754
  const { t } = useTranslation6(NAVTREE_PLUGIN);
921
- return /* @__PURE__ */ React8.createElement(Button4, {
755
+ return /* @__PURE__ */ React8.createElement(Button3, {
922
756
  classNames: "w-full h-full !rounded-none",
923
757
  onClick: () => dispatch(createIntent5(LayoutAction3.SetLayout, {
924
758
  element: "dialog",
@@ -949,7 +783,6 @@ var translations_default = [
949
783
  "see release label": "See release on GitHub",
950
784
  "powered by dxos message": "Powered by <dxos>DXOS</dxos>",
951
785
  "tree item actions label": "More actions",
952
- "tree item searchlist input placeholder": "Search for actions\u2026",
953
786
  "empty branch message": "\xA0"
954
787
  }
955
788
  }
@@ -1074,7 +907,7 @@ var NavTreePlugin = () => {
1074
907
  let shortcut;
1075
908
  if (typeof node.properties.keyBinding === "object") {
1076
909
  const availablePlatforms = Object.keys(node.properties.keyBinding);
1077
- const platform = getHostPlatform3();
910
+ const platform = getHostPlatform2();
1078
911
  shortcut = availablePlatforms.includes(platform) ? node.properties.keyBinding[platform] : platform === "ios" ? node.properties.keyBinding.macos : platform === "linux" || platform === "unknown" ? node.properties.keyBinding.windows : void 0;
1079
912
  } else {
1080
913
  shortcut = node.properties.keyBinding;