dochub-sdk 0.1.216 → 0.1.218
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/classes/vue2/Constructors.ts +9 -0
- package/helpers/index.ts +1 -0
- package/helpers/path.ts +41 -0
- package/package.json +1 -1
@@ -13,4 +13,13 @@ export class DocHubConstructorProto extends DocHubComponentProto {
|
|
13
13
|
type: Object,
|
14
14
|
required: true
|
15
15
|
}) readonly context: DocHubEditorContext;
|
16
|
+
/**
|
17
|
+
* Идентификатор конструктора.
|
18
|
+
* Один компонент может быть вызван для нужд разных конструкторов.
|
19
|
+
* Для идентификации конструктора используется UID.
|
20
|
+
*/
|
21
|
+
@Prop({
|
22
|
+
type: String,
|
23
|
+
required: true
|
24
|
+
}) readonly uid: string;
|
16
25
|
}
|
package/helpers/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './path';
|
package/helpers/path.ts
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* Вычисляет относительный путь из прямых
|
3
|
+
*/
|
4
|
+
export function getRelativePath(baseUrl: string, targetUrl: string): string {
|
5
|
+
const structBase = baseUrl?.split('@');
|
6
|
+
const structTarget = targetUrl.split('@');
|
7
|
+
if (
|
8
|
+
(structBase.length !== structTarget.length) // Если по структуре URL адреса не сходятся сразу выходим
|
9
|
+
|| (structBase.length === 2 && structBase[0] !== structTarget[0]) // Если репа или ветка не та, тоже выходим
|
10
|
+
) return targetUrl;
|
11
|
+
|
12
|
+
// За основу берем правую часть структуры
|
13
|
+
const base = new URL(structBase.pop() || '/', 'null:/');
|
14
|
+
const target = new URL(structTarget.pop() || '/', 'null:/');
|
15
|
+
// Проверяем, что базовый и целевой URL имеют одинаковый протокол и хост
|
16
|
+
if (base.protocol !== target.protocol || base.host !== target.host) {
|
17
|
+
throw new Error('Base and target URLs must have the same protocol and host.');
|
18
|
+
}
|
19
|
+
// Получаем пути
|
20
|
+
const basePathSegments = base.pathname.split('/').filter(segment => segment);
|
21
|
+
const targetPathSegments = target.pathname.split('/').filter(segment => segment);
|
22
|
+
// Находим общую часть пути
|
23
|
+
let commonLength = 0;
|
24
|
+
while (commonLength < basePathSegments.length && commonLength < targetPathSegments.length &&
|
25
|
+
basePathSegments[commonLength] === targetPathSegments[commonLength]) {
|
26
|
+
commonLength++;
|
27
|
+
}
|
28
|
+
// Создаем относительный путь
|
29
|
+
const relativePathSegments: string[] = [];
|
30
|
+
// Добавляем "../" для каждого сегмента, который нужно поднять
|
31
|
+
for (let i = commonLength + 1; i < basePathSegments.length; i++) {
|
32
|
+
relativePathSegments.push('..');
|
33
|
+
}
|
34
|
+
// Добавляем оставшиеся сегменты целевого пути
|
35
|
+
for (let i = commonLength; i < targetPathSegments.length; i++) {
|
36
|
+
relativePathSegments.push(targetPathSegments[i]);
|
37
|
+
}
|
38
|
+
// Собираем относительный путь
|
39
|
+
const relativePath = relativePathSegments.join('/') || '';
|
40
|
+
return relativePath;
|
41
|
+
}
|