@wallarm-org/design-system 1.14.0 → 1.15.0-rc-feature-remote-shell-pathless-drill.1

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.
@@ -27,33 +27,39 @@ const RemoteShell = ({ ref, className, children, config, basePath, onNavigate, '
27
27
  ]);
28
28
  const effectiveDrillLevel = visualDrillLevel ?? urlDrillLevel;
29
29
  const effectiveActiveItemId = effectiveDrillLevel < urlDrillLevel ? navStack[effectiveDrillLevel]?.activeItemId ?? activeItemId : activeItemId;
30
+ const prefixSegmentCount = navStack[effectiveDrillLevel]?.segmentCount ?? 2 * effectiveDrillLevel;
30
31
  const navigate = useCallback((path)=>{
31
32
  setVisualDrillLevel(null);
32
33
  const segments = pathname.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean);
33
- const prefixSegments = segments.slice(0, 2 * effectiveDrillLevel);
34
+ const prefixSegments = segments.slice(0, prefixSegmentCount);
34
35
  setPathname(`/${[
35
36
  ...prefixSegments,
36
37
  path
37
38
  ].join('/')}`);
38
39
  }, [
39
- effectiveDrillLevel,
40
+ prefixSegmentCount,
40
41
  pathname,
41
42
  setPathname
42
43
  ]);
43
44
  const drillInto = useCallback((drill)=>{
44
45
  setVisualDrillLevel(null);
45
46
  const segments = pathname.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean);
46
- const prefixSegments = segments.slice(0, 2 * effectiveDrillLevel);
47
+ const prefixSegments = segments.slice(0, prefixSegmentCount);
47
48
  const defaultEntity = drill.entities?.[0]?.id ?? 'default';
48
49
  const firstChildPath = findFirstLinkPath(drill.children) ?? '';
49
- setPathname(`/${[
50
+ const parts = '' === drill.path ? [
51
+ ...prefixSegments,
52
+ defaultEntity,
53
+ firstChildPath
54
+ ] : [
50
55
  ...prefixSegments,
51
56
  drill.path,
52
57
  defaultEntity,
53
58
  firstChildPath
54
- ].join('/')}`);
59
+ ];
60
+ setPathname(`/${parts.join('/')}`);
55
61
  }, [
56
- effectiveDrillLevel,
62
+ prefixSegmentCount,
57
63
  pathname,
58
64
  setPathname
59
65
  ]);
@@ -8,7 +8,10 @@ export interface MatchNavResult {
8
8
  * Pure function. Matches pathname against nav config.
9
9
  *
10
10
  * - `link` → single URL segment (`{path}`)
11
- * - `drill` → segment + dynamic param (`{path}/:param/...`), pushes new stack level
11
+ * - `drill` → segment + dynamic param (`{path}/:param/...`), pushes new stack level.
12
+ * A drill may declare `path: ''` (pathless): it consumes no segment of its own, so the
13
+ * param sits where the path would have been (`/:param/...`). A literal sibling `path`
14
+ * always matches before a pathless drill claims the segment (see `findPathlessDrill`).
12
15
  * - `group` → NO URL segment, children promoted to parent level
13
16
  *
14
17
  * Called via useMemo on every pathname change.
@@ -13,6 +13,26 @@ const findMatchingNode = (items, segment, groupPath = [])=>{
13
13
  }
14
14
  return null;
15
15
  };
16
+ const findPathlessDrills = (items, groupPath = [])=>{
17
+ const found = [];
18
+ for (const item of items)if ('section-header' !== item.type) {
19
+ if ('group' === item.type) found.push(...findPathlessDrills(item.children, [
20
+ ...groupPath,
21
+ item
22
+ ]));
23
+ else if ('drill' === item.type && '' === item.path) found.push({
24
+ node: item,
25
+ groupPath
26
+ });
27
+ }
28
+ return found;
29
+ };
30
+ const findPathlessDrill = (items)=>{
31
+ const candidates = findPathlessDrills(items);
32
+ if (0 === candidates.length) return null;
33
+ if (candidates.length > 1 && 'production' !== process.env.NODE_ENV) console.warn(`[RemoteShell] Multiple pathless drills found at the same nav level (${candidates.map((c)=>c.node.id).join(', ')}). Only one pathless drill per level is supported — using "${candidates[0].node.id}".`);
34
+ return candidates[0];
35
+ };
16
36
  const matchNav = (pathname, config)=>{
17
37
  const segments = pathname.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean);
18
38
  const navStack = [];
@@ -22,7 +42,8 @@ const matchNav = (pathname, config)=>{
22
42
  title: config.productLabel,
23
43
  parentLabel: null,
24
44
  items: config.items,
25
- activeItemId: null
45
+ activeItemId: null,
46
+ segmentCount: 0
26
47
  };
27
48
  navStack.push(rootEntry);
28
49
  breadcrumbSegments.push({
@@ -35,7 +56,7 @@ const matchNav = (pathname, config)=>{
35
56
  let currentStackEntry = rootEntry;
36
57
  while(segmentIndex < segments.length){
37
58
  const seg = segments[segmentIndex];
38
- const result = findMatchingNode(currentItems, seg);
59
+ const result = findMatchingNode(currentItems, seg) ?? findPathlessDrill(currentItems);
39
60
  if (!result) break;
40
61
  const { node: match, groupPath } = result;
41
62
  if ('link' === match.type) {
@@ -53,25 +74,35 @@ const matchNav = (pathname, config)=>{
53
74
  break;
54
75
  }
55
76
  if ('drill' === match.type) {
77
+ const isPathless = '' === match.path;
56
78
  const drillStartIndex = segmentIndex;
57
79
  currentStackEntry.activeItemId = match.id;
58
- segmentIndex++;
59
- if (segmentIndex >= segments.length) {
60
- activeItemId = match.id;
61
- breadcrumbSegments.push({
62
- type: 'static',
63
- label: match.label
64
- });
65
- break;
80
+ let paramValue;
81
+ if (isPathless) {
82
+ paramValue = seg;
83
+ segmentIndex++;
84
+ } else {
85
+ segmentIndex++;
86
+ if (segmentIndex >= segments.length) {
87
+ activeItemId = match.id;
88
+ breadcrumbSegments.push({
89
+ type: 'static',
90
+ label: match.label
91
+ });
92
+ break;
93
+ }
94
+ paramValue = segments[segmentIndex];
95
+ segmentIndex++;
66
96
  }
67
- const paramValue = segments[segmentIndex];
68
- segmentIndex++;
69
97
  const matchedEntity = match.entities?.find((e)=>e.id === paramValue);
70
98
  const entityLabel = matchedEntity?.label ?? paramValue;
71
99
  const prefixSegments = segments.slice(0, drillStartIndex);
72
100
  const childPath = segments.slice(segmentIndex).join('/');
73
101
  const scopeItems = match.entities?.map((e)=>{
74
- const parts = [
102
+ const parts = isPathless ? [
103
+ ...prefixSegments,
104
+ e.id
105
+ ] : [
75
106
  ...prefixSegments,
76
107
  match.path,
77
108
  e.id
@@ -95,7 +126,8 @@ const matchNav = (pathname, config)=>{
95
126
  title: entityLabel,
96
127
  parentLabel: currentStackEntry.title,
97
128
  items: match.children,
98
- activeItemId: null
129
+ activeItemId: null,
130
+ segmentCount: currentStackEntry.segmentCount + (isPathless ? 1 : 2)
99
131
  };
100
132
  navStack.push(drillEntry);
101
133
  currentItems = match.children;
@@ -25,6 +25,13 @@ export interface NavConfigDrill {
25
25
  type: 'drill';
26
26
  id: string;
27
27
  label: string;
28
+ /**
29
+ * URL segment for this drill (`{path}/:param/...`). Pass `''` for a **pathless drill**:
30
+ * it consumes no segment of its own, so the dynamic param sits where the path would have
31
+ * been (`/:param/...`). At most one pathless drill is supported per nav level (including
32
+ * across transparent groups); a literal sibling path always matches before a pathless
33
+ * drill claims the segment.
34
+ */
28
35
  path: string;
29
36
  /** URL parameter name for the dynamic segment */
30
37
  param: string;
@@ -58,6 +65,13 @@ export interface NavStackEntry {
58
65
  parentLabel: string | null;
59
66
  items: NavConfigNode[];
60
67
  activeItemId: string | null;
68
+ /**
69
+ * Number of pathname segments consumed to reach this stack level (0 for the root).
70
+ * A normal drill consumes 2 segments (its path, then the param); a pathless drill
71
+ * consumes 1 (just the param). Used to rebuild the URL prefix for the current level
72
+ * without assuming a fixed 2-segments-per-level ratio.
73
+ */
74
+ segmentCount: number;
61
75
  }
62
76
  export interface BreadcrumbSegment {
63
77
  type: 'link' | 'scope-switcher' | 'static';
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "1.13.0",
3
- "generatedAt": "2026-09-02T21:31:52.442Z",
2
+ "version": "1.14.0",
3
+ "generatedAt": "2026-09-03T13:26:17.498Z",
4
4
  "components": [
5
5
  {
6
6
  "name": "Accordion",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wallarm-org/design-system",
3
- "version": "1.14.0",
3
+ "version": "1.15.0-rc-feature-remote-shell-pathless-drill.1",
4
4
  "description": "Core design system library with React components and Storybook documentation",
5
5
  "publishConfig": {
6
6
  "access": "public",