@teambit/lanes.ui.models.lanes-model 0.0.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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lanes-model.d.ts +110 -0
- package/dist/lanes-model.js +174 -0
- package/dist/lanes-model.js.map +1 -0
- package/dist/tsconfig.json +32 -0
- package/index.ts +9 -0
- package/lanes-model.ts +270 -0
- package/package-tar/teambit-lanes.ui.models.lanes-model-0.0.1.tgz +0 -0
- package/package.json +49 -0
- package/preview-1664735485436.js +7 -0
- package/tsconfig.json +32 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LanesModel = void 0;
|
|
4
|
+
var lanes_model_1 = require("./lanes-model");
|
|
5
|
+
Object.defineProperty(exports, "LanesModel", { enumerable: true, get: function () { return lanes_model_1.LanesModel; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ComponentModel, ComponentModelProps } from '@teambit/component';
|
|
2
|
+
import { LaneId } from '@teambit/lane-id';
|
|
3
|
+
import { ComponentID, ComponentIdObj } from '@teambit/component-id';
|
|
4
|
+
/**
|
|
5
|
+
* GQL (lanes/getLanes/components)
|
|
6
|
+
* Return type of each Component in a Lane
|
|
7
|
+
*/
|
|
8
|
+
export declare type LaneComponentQueryResult = {
|
|
9
|
+
id: ComponentIdObj;
|
|
10
|
+
head: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* GQL
|
|
14
|
+
* lanes/list
|
|
15
|
+
* lanes/current
|
|
16
|
+
* Return type of each Lane in a Scope/Workspace
|
|
17
|
+
*/
|
|
18
|
+
export declare type LaneQueryResult = {
|
|
19
|
+
id: {
|
|
20
|
+
name: string;
|
|
21
|
+
scope: string;
|
|
22
|
+
};
|
|
23
|
+
remote?: string;
|
|
24
|
+
isMerged: boolean;
|
|
25
|
+
components: Array<{
|
|
26
|
+
id: ComponentIdObj;
|
|
27
|
+
}>;
|
|
28
|
+
readmeComponent?: ComponentModelProps;
|
|
29
|
+
hash: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* GQL
|
|
33
|
+
* Return type of the lanes query
|
|
34
|
+
*/
|
|
35
|
+
export declare type LanesQueryResult = {
|
|
36
|
+
list?: LaneQueryResult[];
|
|
37
|
+
current?: LaneQueryResult;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* GQL (lanes)
|
|
41
|
+
* Return type of the entire /lanes query.
|
|
42
|
+
* Represents All Lanes and Current Lane in Scope/Workspace
|
|
43
|
+
*/
|
|
44
|
+
export declare type LanesQuery = {
|
|
45
|
+
lanes?: LanesQueryResult;
|
|
46
|
+
};
|
|
47
|
+
export declare type LanesHost = 'workspace' | 'scope';
|
|
48
|
+
/**
|
|
49
|
+
* Represents a single Lane in a Workspace/Scope
|
|
50
|
+
*/
|
|
51
|
+
export declare type LaneModel = {
|
|
52
|
+
id: LaneId;
|
|
53
|
+
hash: string;
|
|
54
|
+
components: ComponentID[];
|
|
55
|
+
readmeComponent?: ComponentModel;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Props to instantiate a LanesModel
|
|
59
|
+
*/
|
|
60
|
+
export declare type LanesModelProps = {
|
|
61
|
+
lanes?: LaneModel[];
|
|
62
|
+
viewedLane?: LaneModel;
|
|
63
|
+
currentLane?: LaneModel;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Represents the entire Lanes State in a Workspace/Scope
|
|
67
|
+
* Provides helper methods to extract and map Lane information
|
|
68
|
+
* Keeps track of all the lanes and the currently selected lane from the UI
|
|
69
|
+
*/
|
|
70
|
+
export declare class LanesModel {
|
|
71
|
+
static lanesPrefix: string;
|
|
72
|
+
static baseLaneComponentRoute: string;
|
|
73
|
+
static lanePath: string;
|
|
74
|
+
static laneUrlParamsKey: string;
|
|
75
|
+
private static laneFromPathRegex;
|
|
76
|
+
static getLaneIdFromPathname: (pathname: string, urlSearchParams?: URLSearchParams) => LaneId | undefined;
|
|
77
|
+
static getLaneUrl: (laneId: LaneId, relative?: boolean) => string;
|
|
78
|
+
static getLaneComponentUrl: (componentId: ComponentID, laneId: LaneId) => string;
|
|
79
|
+
static getMainComponentUrl: (componentId: ComponentID, laneId?: LaneId) => string;
|
|
80
|
+
static mapToLaneModel(laneData: LaneQueryResult, host: string): LaneModel;
|
|
81
|
+
static groupByScope(laneIds: LaneId[]): Map<string, LaneId[]>;
|
|
82
|
+
static groupByComponentNameAndId(lanes: LaneModel[]): {
|
|
83
|
+
byName: Map<string, LaneModel[]>;
|
|
84
|
+
byId: Map<string, LaneModel[]>;
|
|
85
|
+
};
|
|
86
|
+
static from({ data, host, viewedLaneId }: {
|
|
87
|
+
data: LanesQuery;
|
|
88
|
+
host: string;
|
|
89
|
+
viewedLaneId?: LaneId;
|
|
90
|
+
}): LanesModel;
|
|
91
|
+
constructor({ lanes, viewedLane, currentLane }: LanesModelProps);
|
|
92
|
+
readonly laneIdsByScope: Map<string, LaneId[]>;
|
|
93
|
+
readonly lanesByComponentName: Map<string, LaneModel[]>;
|
|
94
|
+
readonly lanesByComponentId: Map<string, LaneModel[]>;
|
|
95
|
+
viewedLane?: LaneModel;
|
|
96
|
+
currentLane?: LaneModel;
|
|
97
|
+
readonly lanes: LaneModel[];
|
|
98
|
+
getLaneComponentUrlByVersion: (componentId: ComponentID, laneId?: LaneId) => string;
|
|
99
|
+
setViewedLane: (viewedLaneId?: LaneId) => void;
|
|
100
|
+
resolveComponent: (idStrWithoutVersion: string, laneId?: LaneId) => ComponentID;
|
|
101
|
+
getDefaultLane: () => LaneModel;
|
|
102
|
+
getNonMainLanes: () => LaneModel[];
|
|
103
|
+
isInViewedLane: (componentId: ComponentID, includeVersion?: boolean) => boolean;
|
|
104
|
+
getLanesByComponentName: (componentId: ComponentID) => LaneModel[];
|
|
105
|
+
getLanesByComponentId: (componentId: ComponentID) => LaneModel[];
|
|
106
|
+
isComponentOnMain: (componentId: ComponentID, includeVersion?: boolean) => boolean;
|
|
107
|
+
isComponentOnMainButNotOnLane: (componentId: ComponentID, includeVersion?: boolean, laneId?: LaneId) => boolean;
|
|
108
|
+
isComponentOnLaneButNotOnMain: (componentId: ComponentID, includeVersion?: boolean, laneId?: LaneId) => boolean;
|
|
109
|
+
isComponentOnNonDefaultLanes: (componentId: ComponentID, includeVersion?: boolean, laneId?: LaneId) => boolean;
|
|
110
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LanesModel = void 0;
|
|
4
|
+
const component_1 = require("@teambit/component");
|
|
5
|
+
const lane_id_1 = require("@teambit/lane-id");
|
|
6
|
+
const component_id_1 = require("@teambit/component-id");
|
|
7
|
+
const base_ui_utils_string_affix_1 = require("@teambit/base-ui.utils.string.affix");
|
|
8
|
+
const path_to_regexp_1 = require("path-to-regexp");
|
|
9
|
+
/**
|
|
10
|
+
* Represents the entire Lanes State in a Workspace/Scope
|
|
11
|
+
* Provides helper methods to extract and map Lane information
|
|
12
|
+
* Keeps track of all the lanes and the currently selected lane from the UI
|
|
13
|
+
*/
|
|
14
|
+
class LanesModel {
|
|
15
|
+
constructor({ lanes, viewedLane, currentLane }) {
|
|
16
|
+
this.getLaneComponentUrlByVersion = (componentId, laneId) => {
|
|
17
|
+
var _a;
|
|
18
|
+
// if there is no version, the component is new and is on main
|
|
19
|
+
const defaultLane = this.getDefaultLane();
|
|
20
|
+
if (!componentId.version || !laneId || !defaultLane)
|
|
21
|
+
return LanesModel.getMainComponentUrl(componentId);
|
|
22
|
+
const lane = (_a = this.getLanesByComponentId(componentId)) === null || _a === void 0 ? void 0 : _a.find((l) => l.id.isEqual(laneId));
|
|
23
|
+
if (!lane) {
|
|
24
|
+
// return url from main if it exits
|
|
25
|
+
return defaultLane.components.find((c) => c.isEqual(componentId))
|
|
26
|
+
? LanesModel.getMainComponentUrl(componentId, laneId)
|
|
27
|
+
: undefined;
|
|
28
|
+
}
|
|
29
|
+
if (lane.id.isDefault())
|
|
30
|
+
return LanesModel.getMainComponentUrl(componentId);
|
|
31
|
+
return LanesModel.getLaneComponentUrl(componentId, lane.id);
|
|
32
|
+
};
|
|
33
|
+
this.setViewedLane = (viewedLaneId) => {
|
|
34
|
+
this.viewedLane = viewedLaneId ? this.lanes.find((lane) => lane.id.isEqual(viewedLaneId)) : undefined;
|
|
35
|
+
};
|
|
36
|
+
this.resolveComponent = (idStrWithoutVersion, laneId) => {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = ((laneId && this.lanes.find((lane) => lane.id.isEqual(laneId))) || this.viewedLane)) === null || _a === void 0 ? void 0 : _a.components.find((component) => component.toStringWithoutVersion() === idStrWithoutVersion);
|
|
39
|
+
};
|
|
40
|
+
this.getDefaultLane = () => this.lanes.find((lane) => lane.id.isDefault());
|
|
41
|
+
this.getNonMainLanes = () => this.lanes.filter((lane) => !lane.id.isDefault());
|
|
42
|
+
this.isInViewedLane = (componentId, includeVersion) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if (includeVersion) {
|
|
45
|
+
return (_a = this.viewedLane) === null || _a === void 0 ? void 0 : _a.components.some((comp) => includeVersion && comp.isEqual(componentId));
|
|
46
|
+
}
|
|
47
|
+
return (_b = this.viewedLane) === null || _b === void 0 ? void 0 : _b.components.some((comp) => includeVersion && comp.isEqual(componentId, { ignoreVersion: true }));
|
|
48
|
+
};
|
|
49
|
+
this.getLanesByComponentName = (componentId) => this.lanesByComponentName.get(componentId.fullName);
|
|
50
|
+
this.getLanesByComponentId = (componentId) => this.lanesByComponentId.get(componentId.toString());
|
|
51
|
+
this.isComponentOnMain = (componentId, includeVersion) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (includeVersion) {
|
|
54
|
+
return !!((_a = this.getLanesByComponentId(componentId)) === null || _a === void 0 ? void 0 : _a.some((lane) => lane.id.isDefault()));
|
|
55
|
+
}
|
|
56
|
+
return !!((_b = this.getLanesByComponentName(componentId)) === null || _b === void 0 ? void 0 : _b.some((lane) => lane.id.isDefault()));
|
|
57
|
+
};
|
|
58
|
+
this.isComponentOnMainButNotOnLane = (componentId, includeVersion, laneId) => {
|
|
59
|
+
return (this.isComponentOnMain(componentId, includeVersion) &&
|
|
60
|
+
!this.isComponentOnNonDefaultLanes(componentId, includeVersion, laneId));
|
|
61
|
+
};
|
|
62
|
+
this.isComponentOnLaneButNotOnMain = (componentId, includeVersion, laneId) => {
|
|
63
|
+
return (!this.isComponentOnMain(componentId, includeVersion) &&
|
|
64
|
+
this.isComponentOnNonDefaultLanes(componentId, includeVersion, laneId));
|
|
65
|
+
};
|
|
66
|
+
this.isComponentOnNonDefaultLanes = (componentId, includeVersion, laneId) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (includeVersion) {
|
|
69
|
+
return !!((_a = this.getLanesByComponentId(componentId)) === null || _a === void 0 ? void 0 : _a.some((lane) => !lane.id.isDefault() && (!laneId || lane.id.isEqual(laneId))));
|
|
70
|
+
}
|
|
71
|
+
return !!((_b = this.getLanesByComponentName(componentId)) === null || _b === void 0 ? void 0 : _b.some((lane) => !lane.id.isDefault() && (!laneId || lane.id.isEqual(laneId))));
|
|
72
|
+
};
|
|
73
|
+
this.viewedLane = viewedLane;
|
|
74
|
+
this.currentLane = currentLane;
|
|
75
|
+
this.lanes = lanes || [];
|
|
76
|
+
this.laneIdsByScope = LanesModel.groupByScope(this.lanes.map((lane) => lane.id));
|
|
77
|
+
const { byId, byName } = LanesModel.groupByComponentNameAndId(this.lanes);
|
|
78
|
+
this.lanesByComponentId = byId;
|
|
79
|
+
this.lanesByComponentName = byName;
|
|
80
|
+
}
|
|
81
|
+
static mapToLaneModel(laneData, host) {
|
|
82
|
+
const { id, components, readmeComponent, hash } = laneData;
|
|
83
|
+
const componentIds = (components === null || components === void 0 ? void 0 : components.map((component) => {
|
|
84
|
+
const componentModel = component_id_1.ComponentID.fromObject(component.id);
|
|
85
|
+
return componentModel;
|
|
86
|
+
})) || [];
|
|
87
|
+
const readmeComponentModel = readmeComponent && component_1.ComponentModel.from(Object.assign(Object.assign({}, readmeComponent), { host }));
|
|
88
|
+
return {
|
|
89
|
+
id: lane_id_1.LaneId.from(id.name, id.scope),
|
|
90
|
+
components: componentIds,
|
|
91
|
+
readmeComponent: readmeComponentModel,
|
|
92
|
+
hash,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
static groupByScope(laneIds) {
|
|
96
|
+
const grouped = new Map();
|
|
97
|
+
laneIds.forEach((laneId) => {
|
|
98
|
+
const { scope } = laneId;
|
|
99
|
+
if (!grouped.has(scope)) {
|
|
100
|
+
grouped.set(scope, [laneId]);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const existing = grouped.get(scope);
|
|
104
|
+
grouped.set(scope, [...existing, laneId]);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return grouped;
|
|
108
|
+
}
|
|
109
|
+
static groupByComponentNameAndId(lanes) {
|
|
110
|
+
const byName = new Map();
|
|
111
|
+
const byId = new Map();
|
|
112
|
+
lanes.forEach((lane) => {
|
|
113
|
+
const { components } = lane;
|
|
114
|
+
components.forEach((component) => {
|
|
115
|
+
const name = component.fullName;
|
|
116
|
+
const id = component.toString();
|
|
117
|
+
const existingByName = byName.get(name) || [];
|
|
118
|
+
const existingById = byId.get(id) || [];
|
|
119
|
+
existingByName.push(lane);
|
|
120
|
+
existingById.push(lane);
|
|
121
|
+
byName.set(name, existingByName);
|
|
122
|
+
byId.set(id, existingById);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return { byName, byId };
|
|
126
|
+
}
|
|
127
|
+
static from({ data, host, viewedLaneId }) {
|
|
128
|
+
var _a, _b, _c, _d;
|
|
129
|
+
const lanes = ((_b = (_a = data === null || data === void 0 ? void 0 : data.lanes) === null || _a === void 0 ? void 0 : _a.list) === null || _b === void 0 ? void 0 : _b.map((lane) => LanesModel.mapToLaneModel(lane, host))) || [];
|
|
130
|
+
const currentLane = ((_d = (_c = data.lanes) === null || _c === void 0 ? void 0 : _c.current) === null || _d === void 0 ? void 0 : _d.id)
|
|
131
|
+
? lanes.find((lane) => { var _a, _b; return lane.id.isEqual((_b = (_a = data.lanes) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.id); })
|
|
132
|
+
: undefined;
|
|
133
|
+
const lanesModel = new LanesModel({ lanes, currentLane });
|
|
134
|
+
lanesModel.setViewedLane(viewedLaneId);
|
|
135
|
+
return lanesModel;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.LanesModel = LanesModel;
|
|
139
|
+
LanesModel.lanesPrefix = '~lane';
|
|
140
|
+
LanesModel.baseLaneComponentRoute = '/~component';
|
|
141
|
+
LanesModel.lanePath = ':scopeId/:laneId';
|
|
142
|
+
LanesModel.laneUrlParamsKey = 'lane';
|
|
143
|
+
LanesModel.laneFromPathRegex = (0, path_to_regexp_1.pathToRegexp)(`${LanesModel.lanesPrefix}/${LanesModel.lanePath}`, undefined, {
|
|
144
|
+
end: false,
|
|
145
|
+
start: false,
|
|
146
|
+
});
|
|
147
|
+
LanesModel.getLaneIdFromPathname = (pathname, urlSearchParams) => {
|
|
148
|
+
const matches = LanesModel.laneFromPathRegex.exec(pathname);
|
|
149
|
+
if (matches) {
|
|
150
|
+
const [, scopeId, laneId] = matches;
|
|
151
|
+
return lane_id_1.LaneId.from(laneId, scopeId);
|
|
152
|
+
}
|
|
153
|
+
if (urlSearchParams) {
|
|
154
|
+
const laneIdQueryParam = urlSearchParams.get(LanesModel.laneUrlParamsKey);
|
|
155
|
+
return laneIdQueryParam ? lane_id_1.LaneId.parse(laneIdQueryParam) : undefined;
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
};
|
|
159
|
+
LanesModel.getLaneUrl = (laneId, relative) => `${relative ? '' : '/'}${LanesModel.lanesPrefix}/${laneId.toString()}`;
|
|
160
|
+
LanesModel.getLaneComponentUrl = (componentId, laneId) => {
|
|
161
|
+
const isExternalComponent = componentId.scope !== laneId.scope;
|
|
162
|
+
const laneUrl = LanesModel.getLaneUrl(laneId);
|
|
163
|
+
const urlSearch = (0, base_ui_utils_string_affix_1.affix)('?version=', componentId.version);
|
|
164
|
+
if (!isExternalComponent) {
|
|
165
|
+
return `${laneUrl}${LanesModel.baseLaneComponentRoute}/${componentId.fullName}${urlSearch}`;
|
|
166
|
+
}
|
|
167
|
+
return `${laneUrl}${LanesModel.baseLaneComponentRoute}/${componentId.toStringWithoutVersion()}${urlSearch}`;
|
|
168
|
+
};
|
|
169
|
+
LanesModel.getMainComponentUrl = (componentId, laneId) => {
|
|
170
|
+
const componentUrl = componentId.fullName;
|
|
171
|
+
const urlSearch = (0, base_ui_utils_string_affix_1.affix)(`?${LanesModel.laneUrlParamsKey}=`, laneId === null || laneId === void 0 ? void 0 : laneId.toString());
|
|
172
|
+
return `${componentUrl}${urlSearch}`;
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=lanes-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lanes-model.js","sourceRoot":"","sources":["../lanes-model.ts"],"names":[],"mappings":";;;AAAA,kDAAyE;AACzE,8CAA0C;AAC1C,wDAAoE;AACpE,oFAA4D;AAC5D,mDAA8C;AA4D9C;;;;GAIG;AACH,MAAa,UAAU;IAiHrB,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAmB;QA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|
+
"composite": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
"moduleResolution": "node",
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"rootDir": ".",
|
|
22
|
+
"resolveJsonModule": true
|
|
23
|
+
},
|
|
24
|
+
"exclude": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"include": [
|
|
29
|
+
"**/*",
|
|
30
|
+
"**/*.json"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/index.ts
ADDED
package/lanes-model.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { ComponentModel, ComponentModelProps } from '@teambit/component';
|
|
2
|
+
import { LaneId } from '@teambit/lane-id';
|
|
3
|
+
import { ComponentID, ComponentIdObj } from '@teambit/component-id';
|
|
4
|
+
import { affix } from '@teambit/base-ui.utils.string.affix';
|
|
5
|
+
import { pathToRegexp } from 'path-to-regexp';
|
|
6
|
+
/**
|
|
7
|
+
* GQL (lanes/getLanes/components)
|
|
8
|
+
* Return type of each Component in a Lane
|
|
9
|
+
*/
|
|
10
|
+
export type LaneComponentQueryResult = {
|
|
11
|
+
id: ComponentIdObj;
|
|
12
|
+
head: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* GQL
|
|
16
|
+
* lanes/list
|
|
17
|
+
* lanes/current
|
|
18
|
+
* Return type of each Lane in a Scope/Workspace
|
|
19
|
+
*/
|
|
20
|
+
export type LaneQueryResult = {
|
|
21
|
+
id: { name: string; scope: string };
|
|
22
|
+
remote?: string;
|
|
23
|
+
isMerged: boolean;
|
|
24
|
+
components: Array<{ id: ComponentIdObj }>;
|
|
25
|
+
readmeComponent?: ComponentModelProps;
|
|
26
|
+
hash: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* GQL
|
|
30
|
+
* Return type of the lanes query
|
|
31
|
+
*/
|
|
32
|
+
export type LanesQueryResult = {
|
|
33
|
+
list?: LaneQueryResult[];
|
|
34
|
+
current?: LaneQueryResult;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* GQL (lanes)
|
|
38
|
+
* Return type of the entire /lanes query.
|
|
39
|
+
* Represents All Lanes and Current Lane in Scope/Workspace
|
|
40
|
+
*/
|
|
41
|
+
export type LanesQuery = {
|
|
42
|
+
lanes?: LanesQueryResult;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type LanesHost = 'workspace' | 'scope';
|
|
46
|
+
// export type LaneComponentModel = { model: ComponentModel; url: string };
|
|
47
|
+
/**
|
|
48
|
+
* Represents a single Lane in a Workspace/Scope
|
|
49
|
+
*/
|
|
50
|
+
export type LaneModel = {
|
|
51
|
+
id: LaneId;
|
|
52
|
+
hash: string;
|
|
53
|
+
components: ComponentID[];
|
|
54
|
+
readmeComponent?: ComponentModel;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Props to instantiate a LanesModel
|
|
58
|
+
*/
|
|
59
|
+
export type LanesModelProps = {
|
|
60
|
+
lanes?: LaneModel[];
|
|
61
|
+
viewedLane?: LaneModel;
|
|
62
|
+
currentLane?: LaneModel;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Represents the entire Lanes State in a Workspace/Scope
|
|
67
|
+
* Provides helper methods to extract and map Lane information
|
|
68
|
+
* Keeps track of all the lanes and the currently selected lane from the UI
|
|
69
|
+
*/
|
|
70
|
+
export class LanesModel {
|
|
71
|
+
static lanesPrefix = '~lane';
|
|
72
|
+
static baseLaneComponentRoute = '/~component';
|
|
73
|
+
static lanePath = ':scopeId/:laneId';
|
|
74
|
+
static laneUrlParamsKey = 'lane';
|
|
75
|
+
|
|
76
|
+
private static laneFromPathRegex = pathToRegexp(`${LanesModel.lanesPrefix}/${LanesModel.lanePath}`, undefined, {
|
|
77
|
+
end: false,
|
|
78
|
+
start: false,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
static getLaneIdFromPathname = (pathname: string, urlSearchParams?: URLSearchParams): LaneId | undefined => {
|
|
82
|
+
const matches = LanesModel.laneFromPathRegex.exec(pathname);
|
|
83
|
+
if (matches) {
|
|
84
|
+
const [, scopeId, laneId] = matches;
|
|
85
|
+
return LaneId.from(laneId, scopeId);
|
|
86
|
+
}
|
|
87
|
+
if (urlSearchParams) {
|
|
88
|
+
const laneIdQueryParam = urlSearchParams.get(LanesModel.laneUrlParamsKey);
|
|
89
|
+
return laneIdQueryParam ? LaneId.parse(laneIdQueryParam) : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return undefined;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
static getLaneUrl = (laneId: LaneId, relative?: boolean) =>
|
|
96
|
+
`${relative ? '' : '/'}${LanesModel.lanesPrefix}/${laneId.toString()}`;
|
|
97
|
+
|
|
98
|
+
static getLaneComponentUrl = (componentId: ComponentID, laneId: LaneId) => {
|
|
99
|
+
const isExternalComponent = componentId.scope !== laneId.scope;
|
|
100
|
+
|
|
101
|
+
const laneUrl = LanesModel.getLaneUrl(laneId);
|
|
102
|
+
const urlSearch = affix('?version=', componentId.version);
|
|
103
|
+
|
|
104
|
+
if (!isExternalComponent) {
|
|
105
|
+
return `${laneUrl}${LanesModel.baseLaneComponentRoute}/${componentId.fullName}${urlSearch}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return `${laneUrl}${LanesModel.baseLaneComponentRoute}/${componentId.toStringWithoutVersion()}${urlSearch}`;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
static getMainComponentUrl = (componentId: ComponentID, laneId?: LaneId) => {
|
|
112
|
+
const componentUrl = componentId.fullName;
|
|
113
|
+
const urlSearch = affix(`?${LanesModel.laneUrlParamsKey}=`, laneId?.toString());
|
|
114
|
+
return `${componentUrl}${urlSearch}`;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
static mapToLaneModel(laneData: LaneQueryResult, host: string): LaneModel {
|
|
118
|
+
const { id, components, readmeComponent, hash } = laneData;
|
|
119
|
+
|
|
120
|
+
const componentIds =
|
|
121
|
+
components?.map((component) => {
|
|
122
|
+
const componentModel = ComponentID.fromObject(component.id);
|
|
123
|
+
return componentModel;
|
|
124
|
+
}) || [];
|
|
125
|
+
|
|
126
|
+
const readmeComponentModel = readmeComponent && ComponentModel.from({ ...readmeComponent, host });
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
id: LaneId.from(id.name, id.scope),
|
|
130
|
+
components: componentIds,
|
|
131
|
+
readmeComponent: readmeComponentModel,
|
|
132
|
+
hash,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static groupByScope(laneIds: LaneId[]): Map<string, LaneId[]> {
|
|
137
|
+
const grouped = new Map<string, LaneId[]>();
|
|
138
|
+
laneIds.forEach((laneId) => {
|
|
139
|
+
const { scope } = laneId;
|
|
140
|
+
if (!grouped.has(scope)) {
|
|
141
|
+
grouped.set(scope, [laneId]);
|
|
142
|
+
} else {
|
|
143
|
+
const existing = grouped.get(scope) as LaneId[];
|
|
144
|
+
grouped.set(scope, [...existing, laneId]);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return grouped;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static groupByComponentNameAndId(lanes: LaneModel[]): {
|
|
151
|
+
byName: Map<string, LaneModel[]>;
|
|
152
|
+
byId: Map<string, LaneModel[]>;
|
|
153
|
+
} {
|
|
154
|
+
const byName = new Map<string, LaneModel[]>();
|
|
155
|
+
const byId = new Map<string, LaneModel[]>();
|
|
156
|
+
|
|
157
|
+
lanes.forEach((lane) => {
|
|
158
|
+
const { components } = lane;
|
|
159
|
+
components.forEach((component) => {
|
|
160
|
+
const name = component.fullName;
|
|
161
|
+
const id = component.toString();
|
|
162
|
+
const existingByName = byName.get(name) || [];
|
|
163
|
+
const existingById = byId.get(id) || [];
|
|
164
|
+
existingByName.push(lane);
|
|
165
|
+
existingById.push(lane);
|
|
166
|
+
byName.set(name, existingByName);
|
|
167
|
+
byId.set(id, existingById);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
return { byName, byId };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static from({ data, host, viewedLaneId }: { data: LanesQuery; host: string; viewedLaneId?: LaneId }): LanesModel {
|
|
174
|
+
const lanes = data?.lanes?.list?.map((lane) => LanesModel.mapToLaneModel(lane, host)) || [];
|
|
175
|
+
const currentLane = data.lanes?.current?.id
|
|
176
|
+
? lanes.find((lane) => lane.id.isEqual(data.lanes?.current?.id as LaneId))
|
|
177
|
+
: undefined;
|
|
178
|
+
const lanesModel = new LanesModel({ lanes, currentLane });
|
|
179
|
+
lanesModel.setViewedLane(viewedLaneId);
|
|
180
|
+
return lanesModel;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
constructor({ lanes, viewedLane, currentLane }: LanesModelProps) {
|
|
184
|
+
this.viewedLane = viewedLane;
|
|
185
|
+
this.currentLane = currentLane;
|
|
186
|
+
this.lanes = lanes || [];
|
|
187
|
+
this.laneIdsByScope = LanesModel.groupByScope(this.lanes.map((lane) => lane.id));
|
|
188
|
+
const { byId, byName } = LanesModel.groupByComponentNameAndId(this.lanes);
|
|
189
|
+
this.lanesByComponentId = byId;
|
|
190
|
+
this.lanesByComponentName = byName;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
readonly laneIdsByScope: Map<string, LaneId[]>;
|
|
194
|
+
readonly lanesByComponentName: Map<string, LaneModel[]>;
|
|
195
|
+
readonly lanesByComponentId: Map<string, LaneModel[]>;
|
|
196
|
+
|
|
197
|
+
viewedLane?: LaneModel;
|
|
198
|
+
currentLane?: LaneModel;
|
|
199
|
+
readonly lanes: LaneModel[];
|
|
200
|
+
|
|
201
|
+
getLaneComponentUrlByVersion = (componentId: ComponentID, laneId?: LaneId) => {
|
|
202
|
+
// if there is no version, the component is new and is on main
|
|
203
|
+
const defaultLane = this.getDefaultLane();
|
|
204
|
+
if (!componentId.version || !laneId || !defaultLane) return LanesModel.getMainComponentUrl(componentId);
|
|
205
|
+
const lane = this.getLanesByComponentId(componentId)?.find((l) => l.id.isEqual(laneId));
|
|
206
|
+
if (!lane) {
|
|
207
|
+
// return url from main if it exits
|
|
208
|
+
return defaultLane.components.find((c) => c.isEqual(componentId))
|
|
209
|
+
? LanesModel.getMainComponentUrl(componentId, laneId)
|
|
210
|
+
: undefined;
|
|
211
|
+
}
|
|
212
|
+
if (lane.id.isDefault()) return LanesModel.getMainComponentUrl(componentId);
|
|
213
|
+
return LanesModel.getLaneComponentUrl(componentId, lane.id);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
setViewedLane = (viewedLaneId?: LaneId) => {
|
|
217
|
+
this.viewedLane = viewedLaneId ? this.lanes.find((lane) => lane.id.isEqual(viewedLaneId)) : undefined;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
resolveComponent = (idStrWithoutVersion: string, laneId?: LaneId) =>
|
|
221
|
+
((laneId && this.lanes.find((lane) => lane.id.isEqual(laneId))) || this.viewedLane)?.components.find(
|
|
222
|
+
(component) => component.toStringWithoutVersion() === idStrWithoutVersion
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
getDefaultLane = () => this.lanes.find((lane) => lane.id.isDefault());
|
|
226
|
+
getNonMainLanes = () => this.lanes.filter((lane) => !lane.id.isDefault());
|
|
227
|
+
|
|
228
|
+
isInViewedLane = (componentId: ComponentID, includeVersion?: boolean) => {
|
|
229
|
+
if (includeVersion) {
|
|
230
|
+
return this.viewedLane?.components.some((comp) => includeVersion && comp.isEqual(componentId));
|
|
231
|
+
}
|
|
232
|
+
return this.viewedLane?.components.some(
|
|
233
|
+
(comp) => includeVersion && comp.isEqual(componentId, { ignoreVersion: true })
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
getLanesByComponentName = (componentId: ComponentID) => this.lanesByComponentName.get(componentId.fullName);
|
|
238
|
+
getLanesByComponentId = (componentId: ComponentID) => this.lanesByComponentId.get(componentId.toString());
|
|
239
|
+
|
|
240
|
+
isComponentOnMain = (componentId: ComponentID, includeVersion?: boolean) => {
|
|
241
|
+
if (includeVersion) {
|
|
242
|
+
return !!this.getLanesByComponentId(componentId)?.some((lane) => lane.id.isDefault());
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return !!this.getLanesByComponentName(componentId)?.some((lane) => lane.id.isDefault());
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
isComponentOnMainButNotOnLane = (componentId: ComponentID, includeVersion?: boolean, laneId?: LaneId) => {
|
|
249
|
+
return (
|
|
250
|
+
this.isComponentOnMain(componentId, includeVersion) &&
|
|
251
|
+
!this.isComponentOnNonDefaultLanes(componentId, includeVersion, laneId)
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
isComponentOnLaneButNotOnMain = (componentId: ComponentID, includeVersion?: boolean, laneId?: LaneId) => {
|
|
255
|
+
return (
|
|
256
|
+
!this.isComponentOnMain(componentId, includeVersion) &&
|
|
257
|
+
this.isComponentOnNonDefaultLanes(componentId, includeVersion, laneId)
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
isComponentOnNonDefaultLanes = (componentId: ComponentID, includeVersion?: boolean, laneId?: LaneId) => {
|
|
261
|
+
if (includeVersion) {
|
|
262
|
+
return !!this.getLanesByComponentId(componentId)?.some(
|
|
263
|
+
(lane) => !lane.id.isDefault() && (!laneId || lane.id.isEqual(laneId))
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return !!this.getLanesByComponentName(componentId)?.some(
|
|
267
|
+
(lane) => !lane.id.isDefault() && (!laneId || lane.id.isEqual(laneId))
|
|
268
|
+
);
|
|
269
|
+
};
|
|
270
|
+
}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/lanes.ui.models.lanes-model",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"componentId": {
|
|
6
|
+
"scope": "teambit.lanes",
|
|
7
|
+
"name": "ui/models/lanes-model",
|
|
8
|
+
"version": "0.0.1"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"path-to-regexp": "6.2.0",
|
|
12
|
+
"core-js": "^3.0.0",
|
|
13
|
+
"@teambit/base-ui.utils.string.affix": "1.0.0",
|
|
14
|
+
"@teambit/component-id": "0.0.417",
|
|
15
|
+
"@teambit/lane-id": "0.0.97"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/mocha": "9.1.0",
|
|
19
|
+
"@types/testing-library__jest-dom": "5.9.5",
|
|
20
|
+
"@babel/runtime": "7.12.18",
|
|
21
|
+
"@types/jest": "^26.0.0",
|
|
22
|
+
"@types/react-dom": "^17.0.5",
|
|
23
|
+
"@types/react": "^17.0.8",
|
|
24
|
+
"@types/node": "12.20.4"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react-dom": "^16.8.0 || ^17.0.0",
|
|
28
|
+
"react": "^16.8.0 || ^17.0.0"
|
|
29
|
+
},
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"private": false,
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=12.22.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/teambit/bit"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"bit",
|
|
41
|
+
"components",
|
|
42
|
+
"collaboration",
|
|
43
|
+
"web",
|
|
44
|
+
"react",
|
|
45
|
+
"react-components",
|
|
46
|
+
"angular",
|
|
47
|
+
"angular-components"
|
|
48
|
+
]
|
|
49
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"es2019",
|
|
5
|
+
"DOM",
|
|
6
|
+
"ES6",
|
|
7
|
+
"DOM.Iterable"
|
|
8
|
+
],
|
|
9
|
+
"target": "es2015",
|
|
10
|
+
"module": "CommonJS",
|
|
11
|
+
"jsx": "react",
|
|
12
|
+
"allowJs": true,
|
|
13
|
+
"composite": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
"moduleResolution": "node",
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"rootDir": ".",
|
|
22
|
+
"resolveJsonModule": true
|
|
23
|
+
},
|
|
24
|
+
"exclude": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"include": [
|
|
29
|
+
"**/*",
|
|
30
|
+
"**/*.json"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|