@dxos/plugin-deck 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 (106) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +15 -0
  3. package/dist/lib/browser/chunk-YVHGFQQR.mjs +12 -0
  4. package/dist/lib/browser/chunk-YVHGFQQR.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1657 -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 +9 -0
  9. package/dist/lib/browser/meta.mjs.map +7 -0
  10. package/dist/types/src/DeckPlugin.d.ts +15 -0
  11. package/dist/types/src/DeckPlugin.d.ts.map +1 -0
  12. package/dist/types/src/components/DeckContext.d.ts +8 -0
  13. package/dist/types/src/components/DeckContext.d.ts.map +1 -0
  14. package/dist/types/src/components/DeckLayout/ActiveNode.d.ts +5 -0
  15. package/dist/types/src/components/DeckLayout/ActiveNode.d.ts.map +1 -0
  16. package/dist/types/src/components/DeckLayout/ComplementarySidebar.d.ts +9 -0
  17. package/dist/types/src/components/DeckLayout/ComplementarySidebar.d.ts.map +1 -0
  18. package/dist/types/src/components/DeckLayout/ContentEmpty.d.ts +3 -0
  19. package/dist/types/src/components/DeckLayout/ContentEmpty.d.ts.map +1 -0
  20. package/dist/types/src/components/DeckLayout/DeckLayout.d.ts +25 -0
  21. package/dist/types/src/components/DeckLayout/DeckLayout.d.ts.map +1 -0
  22. package/dist/types/src/components/DeckLayout/Fallback.d.ts +3 -0
  23. package/dist/types/src/components/DeckLayout/Fallback.d.ts.map +1 -0
  24. package/dist/types/src/components/DeckLayout/Fullscreen.d.ts +5 -0
  25. package/dist/types/src/components/DeckLayout/Fullscreen.d.ts.map +1 -0
  26. package/dist/types/src/components/DeckLayout/NodePlankHeading.d.ts +14 -0
  27. package/dist/types/src/components/DeckLayout/NodePlankHeading.d.ts.map +1 -0
  28. package/dist/types/src/components/DeckLayout/Plank.d.ts +14 -0
  29. package/dist/types/src/components/DeckLayout/Plank.d.ts.map +1 -0
  30. package/dist/types/src/components/DeckLayout/PlankError.d.ts +14 -0
  31. package/dist/types/src/components/DeckLayout/PlankError.d.ts.map +1 -0
  32. package/dist/types/src/components/DeckLayout/PlankLoading.d.ts +3 -0
  33. package/dist/types/src/components/DeckLayout/PlankLoading.d.ts.map +1 -0
  34. package/dist/types/src/components/DeckLayout/Sidebar.d.ts +8 -0
  35. package/dist/types/src/components/DeckLayout/Sidebar.d.ts.map +1 -0
  36. package/dist/types/src/components/DeckLayout/Toast.d.ts +5 -0
  37. package/dist/types/src/components/DeckLayout/Toast.d.ts.map +1 -0
  38. package/dist/types/src/components/DeckLayout/constants.d.ts +3 -0
  39. package/dist/types/src/components/DeckLayout/constants.d.ts.map +1 -0
  40. package/dist/types/src/components/DeckLayout/index.d.ts +3 -0
  41. package/dist/types/src/components/DeckLayout/index.d.ts.map +1 -0
  42. package/dist/types/src/components/LayoutContext.d.ts +5 -0
  43. package/dist/types/src/components/LayoutContext.d.ts.map +1 -0
  44. package/dist/types/src/components/LayoutSettings.d.ts +6 -0
  45. package/dist/types/src/components/LayoutSettings.d.ts.map +1 -0
  46. package/dist/types/src/components/index.d.ts +5 -0
  47. package/dist/types/src/components/index.d.ts.map +1 -0
  48. package/dist/types/src/hooks/index.d.ts +3 -0
  49. package/dist/types/src/hooks/index.d.ts.map +1 -0
  50. package/dist/types/src/hooks/useNode.d.ts +11 -0
  51. package/dist/types/src/hooks/useNode.d.ts.map +1 -0
  52. package/dist/types/src/hooks/useNodeActionExpander.d.ts +3 -0
  53. package/dist/types/src/hooks/useNodeActionExpander.d.ts.map +1 -0
  54. package/dist/types/src/index.d.ts +4 -0
  55. package/dist/types/src/index.d.ts.map +1 -0
  56. package/dist/types/src/layout.d.ts +25 -0
  57. package/dist/types/src/layout.d.ts.map +1 -0
  58. package/dist/types/src/layout.test.d.ts +2 -0
  59. package/dist/types/src/layout.test.d.ts.map +1 -0
  60. package/dist/types/src/meta.d.ts +7 -0
  61. package/dist/types/src/meta.d.ts.map +1 -0
  62. package/dist/types/src/translations.d.ts +41 -0
  63. package/dist/types/src/translations.d.ts.map +1 -0
  64. package/dist/types/src/types.d.ts +16 -0
  65. package/dist/types/src/types.d.ts.map +1 -0
  66. package/dist/types/src/util/check-app-scheme.d.ts +2 -0
  67. package/dist/types/src/util/check-app-scheme.d.ts.map +1 -0
  68. package/dist/types/src/util/index.d.ts +4 -0
  69. package/dist/types/src/util/index.d.ts.map +1 -0
  70. package/dist/types/src/util/layout-parts.d.ts +7 -0
  71. package/dist/types/src/util/layout-parts.d.ts.map +1 -0
  72. package/dist/types/src/util/overscroll.d.ts +7 -0
  73. package/dist/types/src/util/overscroll.d.ts.map +1 -0
  74. package/package.json +76 -0
  75. package/src/DeckPlugin.tsx +629 -0
  76. package/src/components/DeckContext.ts +14 -0
  77. package/src/components/DeckLayout/ActiveNode.tsx +24 -0
  78. package/src/components/DeckLayout/ComplementarySidebar.tsx +58 -0
  79. package/src/components/DeckLayout/ContentEmpty.tsx +21 -0
  80. package/src/components/DeckLayout/DeckLayout.tsx +270 -0
  81. package/src/components/DeckLayout/Fallback.tsx +28 -0
  82. package/src/components/DeckLayout/Fullscreen.tsx +32 -0
  83. package/src/components/DeckLayout/NodePlankHeading.tsx +160 -0
  84. package/src/components/DeckLayout/Plank.tsx +142 -0
  85. package/src/components/DeckLayout/PlankError.tsx +64 -0
  86. package/src/components/DeckLayout/PlankLoading.tsx +15 -0
  87. package/src/components/DeckLayout/Sidebar.tsx +43 -0
  88. package/src/components/DeckLayout/Toast.tsx +48 -0
  89. package/src/components/DeckLayout/constants.ts +6 -0
  90. package/src/components/DeckLayout/index.ts +6 -0
  91. package/src/components/LayoutContext.ts +12 -0
  92. package/src/components/LayoutSettings.tsx +86 -0
  93. package/src/components/index.ts +8 -0
  94. package/src/hooks/index.ts +6 -0
  95. package/src/hooks/useNode.ts +40 -0
  96. package/src/hooks/useNodeActionExpander.ts +24 -0
  97. package/src/index.ts +9 -0
  98. package/src/layout.test.ts +380 -0
  99. package/src/layout.ts +245 -0
  100. package/src/meta.ts +10 -0
  101. package/src/translations.ts +47 -0
  102. package/src/types.ts +38 -0
  103. package/src/util/check-app-scheme.ts +21 -0
  104. package/src/util/index.ts +7 -0
  105. package/src/util/layout-parts.ts +12 -0
  106. package/src/util/overscroll.ts +97 -0
package/src/types.ts ADDED
@@ -0,0 +1,38 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import type {
6
+ GraphBuilderProvides,
7
+ IntentResolverProvides,
8
+ LayoutProvides,
9
+ LocationProvides,
10
+ SettingsProvides,
11
+ SurfaceProvides,
12
+ TranslationsProvides,
13
+ } from '@dxos/app-framework';
14
+
15
+ // TODO(Zan): In the future we should consider adding new planks adjacent to the attended plank.
16
+ export const NewPlankPositions = ['start', 'end'] as const;
17
+ export type NewPlankPositioning = (typeof NewPlankPositions)[number];
18
+
19
+ export const OverscrollOptions = ['none', 'centering'] as const;
20
+ export type Overscroll = (typeof OverscrollOptions)[number];
21
+
22
+ export type DeckSettingsProps = {
23
+ showFooter: boolean;
24
+ customSlots: boolean;
25
+ flatDeck: boolean;
26
+ enableNativeRedirect: boolean;
27
+ disableDeck: boolean;
28
+ newPlankPositioning: NewPlankPositioning;
29
+ overscroll: Overscroll;
30
+ };
31
+
32
+ export type DeckPluginProvides = SurfaceProvides &
33
+ IntentResolverProvides &
34
+ GraphBuilderProvides &
35
+ TranslationsProvides &
36
+ SettingsProvides<DeckSettingsProps> &
37
+ LayoutProvides &
38
+ LocationProvides;
@@ -0,0 +1,21 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ // TODO(mjamesderocher): Factor out as part of NavigationPlugin.
6
+ export const checkAppScheme = (url: string) => {
7
+ const iframe = document.createElement('iframe');
8
+ iframe.style.display = 'none';
9
+ document.body.appendChild(iframe);
10
+
11
+ iframe.src = url + window.location.pathname.replace(/^\/+/, '') + window.location.search;
12
+
13
+ const timer = setTimeout(() => {
14
+ document.body.removeChild(iframe);
15
+ }, 3000);
16
+
17
+ window.addEventListener('pagehide', (event) => {
18
+ clearTimeout(timer);
19
+ document.body.removeChild(iframe);
20
+ });
21
+ };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './check-app-scheme';
6
+ export * from './layout-parts';
7
+ export * from './overscroll';
@@ -0,0 +1,12 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type LayoutMode, type LayoutPart } from '@dxos/app-framework';
6
+
7
+ /**
8
+ * If in solo mode and the part is the main part, open it in solo mode.
9
+ * From the dispatch POV we refer to both 'solo' and 'main' as 'main'.
10
+ */
11
+ export const getEffectivePart = (partName: LayoutPart, layoutMode: LayoutMode): LayoutPart =>
12
+ layoutMode === 'solo' && partName === 'main' ? 'solo' : partName;
@@ -0,0 +1,97 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type LayoutMode, type LayoutParts } from '@dxos/app-framework';
6
+ import { PLANK_DEFAULTS } from '@dxos/react-ui-deck';
7
+
8
+ import { type Overscroll } from '../types';
9
+
10
+ export const calculateOverscroll = (
11
+ layoutMode: LayoutMode,
12
+ sidebarOpen: boolean,
13
+ complementarySidebarOpen: boolean,
14
+ layoutParts: LayoutParts,
15
+ plankSizing: Record<string, number>,
16
+ overscroll: Overscroll,
17
+ ) => {
18
+ if (!(layoutMode === 'deck' && overscroll === 'centering')) {
19
+ return;
20
+ }
21
+ if (!layoutParts.main || layoutParts.main.length === 0) {
22
+ return;
23
+ }
24
+
25
+ /**
26
+ * ┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
27
+ * | Overscroll Padding Calculation for Centering Planks on Screen. │
28
+ * ├────────────────────────────────────────────────────────────────────────────────────────────────────┤
29
+ * │ NOTE(Zan): I found the way you calculate the overscroll padding to center a plank on the screen │
30
+ * │ at the edges of the scroll context a bit confusing, so I've diagrammed it here. │
31
+ * │ │
32
+ * │ Multiple Planks: │
33
+ * │ ─────────────── │
34
+ * | Use the following overscroll padding calculation centering the boundary planks on the SCREEN. │
35
+ * │ │
36
+ * │ Left Padding: Right Padding: │
37
+ * │ ┌───┬────┬──────────────────┬──────┐ ┌──────┬──────────────────┬────┬───┐ │
38
+ * │ │ │████│ Ideal │ │ │ │ Ideal │████│ │ │
39
+ * │ │ S │█PL█│ first │ │ │ │ last │█PR█│ C │ │
40
+ * │ │ │████│ plank │ │ │ │ plank │████│ │ │
41
+ * │ └───┴────┴──────────────────┴──────┘ └──────┴──────────────────┴────┴───┘ │
42
+ * │ <--------- screen width -----------> <---------- screen width ----------> │
43
+ * │ │
44
+ * │ PL = ((screen width - Plank Width) / 2) - S │
45
+ * │ PR = ((screen width - Plank Width) / 2) - C │
46
+ * │ │
47
+ * │ S = Sidebar width C = Complementary sidebar width │
48
+ * │ PL = Padding Left PR = Padding Right │
49
+ * │ │
50
+ * │ Single Plank: │
51
+ * │ ───────────── │
52
+ * │ For a single plank we use the following overscroll padding calculation to center the plank in │
53
+ * │ the content area: │
54
+ * │ │
55
+ * │ ┌───┬───────────────────────┬───┬───────────────────────┬───┐ │
56
+ * │ │ │███████████████████████│ │███████████████████████│ │ │
57
+ * │ │ S │█████ Left Padding ████│ P │████ Right Padding ████│ C │ │
58
+ * │ │ │███████████████████████│ │███████████████████████│ │ │
59
+ * │ └───┴───────────────────────┴───┴───────────────────────┴───┘ │
60
+ * │ <------------------------ screen width ---------------------> │
61
+ * │ │
62
+ * │ Left/Right Padding Width = (screen width - S - P - C) / 2 │
63
+ * │ │
64
+ * │ S = Sidebar width (may be 0) │
65
+ * │ P = Plank width (centered) │
66
+ * │ C = Complementary sidebar width (may be 0) │
67
+ * └────────────────────────────────────────────────────────────────────────────────────────────────────┘
68
+ */
69
+
70
+ // TODO(Zan): Move complementary sidebar size (360px), sidebar size (270px), plank resize handle size (20px) to CSS variables.
71
+ const sidebarWidth = sidebarOpen ? '270px' : '0px';
72
+ const complementarySidebarWidth = complementarySidebarOpen ? '360px' : '0px';
73
+
74
+ const getPlankSize = (id: string) => (plankSizing[id] ?? PLANK_DEFAULTS.size).toFixed(2) + 'rem';
75
+
76
+ if (layoutParts.main.length === 1) {
77
+ // Center the plank in the content area.
78
+
79
+ const plank = layoutParts.main[0];
80
+ const plankSize = getPlankSize(plank.id);
81
+ const overscrollPadding = `max(0px, calc(((100dvw - ${sidebarWidth} - ${complementarySidebarWidth} - (${plankSize} + 20px)) / 2)))`;
82
+
83
+ return { paddingLeft: overscrollPadding, paddingRight: overscrollPadding };
84
+ } else {
85
+ // Center the plank on the screen.
86
+
87
+ const firstPlank = layoutParts.main[0];
88
+ const firstPlankInlineSize = getPlankSize(firstPlank.id);
89
+ const paddingLeft = `max(0px, calc(((100dvw - (${firstPlankInlineSize} + 20px)) / 2) - ${sidebarWidth}))`;
90
+
91
+ const lastPlank = layoutParts.main[layoutParts.main.length - 1];
92
+ const lastPlankInlineSize = getPlankSize(lastPlank.id);
93
+ const paddingRight = `max(0px, calc(((100dvw - (${lastPlankInlineSize} + 20px)) / 2) - ${complementarySidebarWidth}))`;
94
+
95
+ return { paddingLeft, paddingRight };
96
+ }
97
+ };