@tutti-os/workspace-user-project 0.0.13 → 0.0.15
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.
|
@@ -87,21 +87,10 @@ async function prepareWorkspaceUserProjectSelection(api, input) {
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
if (defaultSelection) {
|
|
91
|
-
return {
|
|
92
|
-
isSelectedPathMissing,
|
|
93
|
-
projects,
|
|
94
|
-
selection: { kind: "none" }
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
const recentProject = projects[0];
|
|
98
90
|
return {
|
|
99
91
|
isSelectedPathMissing,
|
|
100
92
|
projects,
|
|
101
|
-
selection:
|
|
102
|
-
kind: "select",
|
|
103
|
-
path: recentProject.path
|
|
104
|
-
} : { kind: "none" }
|
|
93
|
+
selection: { kind: "none" }
|
|
105
94
|
};
|
|
106
95
|
}
|
|
107
96
|
async function checkWorkspaceUserProjectPathMissing(api, path) {
|
|
@@ -131,4 +120,4 @@ export {
|
|
|
131
120
|
prepareWorkspaceUserProjectSelection,
|
|
132
121
|
checkWorkspaceUserProjectPathMissing
|
|
133
122
|
};
|
|
134
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-JKSIGLCI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/index.ts"],"sourcesContent":["import type {\n WorkspaceUserProject,\n WorkspaceUserProjectApi,\n WorkspaceUserProjectCreationErrorCode,\n WorkspaceUserProjectSelectionPreparation,\n WorkspaceUserProjectSelectionPreparationInput\n} from \"../contracts/index.ts\";\n\nexport function upsertWorkspaceUserProject(\n projects: readonly WorkspaceUserProject[],\n project: WorkspaceUserProject\n): WorkspaceUserProject[] {\n const existingIndex = projects.findIndex(\n (item) => item.id === project.id || item.path === project.path\n );\n if (existingIndex < 0) {\n return [project, ...projects];\n }\n const next = [...projects];\n next[existingIndex] = project;\n return next;\n}\n\nexport function resolveWorkspaceUserProjectDisplayLabel(\n project: Pick<WorkspaceUserProject, \"id\" | \"label\" | \"path\">\n): string {\n const label = stripAbsolutePathFromWorkspaceUserProjectLabel(project.label);\n if (label) {\n return label;\n }\n return basenameWorkspaceUserProjectPath(project.path) || project.id;\n}\n\nexport function stripAbsolutePathFromWorkspaceUserProjectLabel(\n label: string\n): string {\n const trimmedLabel = label.trim();\n if (!trimmedLabel) {\n return \"\";\n }\n const pathStart = findAbsolutePathStart(trimmedLabel);\n if (pathStart < 0) {\n return trimmedLabel;\n }\n if (pathStart === 0) {\n return basenameWorkspaceUserProjectPath(trimmedLabel);\n }\n return trimmedLabel\n .slice(0, pathStart)\n .replace(/[\\s/\\\\|:()[\\]{}-]+$/u, \"\")\n .trim();\n}\n\nexport function basenameWorkspaceUserProjectPath(path: string): string {\n const normalizedPath = path.trim().replace(/[\\\\/]+$/u, \"\");\n if (!normalizedPath) {\n return \"\";\n }\n const segments = normalizedPath.split(/[\\\\/]+/u);\n return segments[segments.length - 1] ?? \"\";\n}\n\nexport function getWorkspaceUserProjectErrorCode(\n error: unknown\n): WorkspaceUserProjectCreationErrorCode | null {\n if (!error || typeof error !== \"object\") {\n return null;\n }\n\n const code = (error as { code?: unknown }).code;\n if (typeof code === \"string\") {\n return code;\n }\n\n return getWorkspaceUserProjectErrorCode((error as { cause?: unknown }).cause);\n}\n\nexport async function prepareWorkspaceUserProjectSelection(\n api: WorkspaceUserProjectApi,\n input: WorkspaceUserProjectSelectionPreparationInput\n): Promise<WorkspaceUserProjectSelectionPreparation> {\n if (api.prepareSelection) {\n return api.prepareSelection(input);\n }\n const response = await api.list();\n const projects = response.projects;\n const selectedPath = input.selectedPath?.trim() ?? \"\";\n const isSelectedPathMissing =\n input.projectLocked && selectedPath\n ? await checkWorkspaceUserProjectPathMissing(api, selectedPath)\n : false;\n\n if (\n !input.projectLocked &&\n selectedPath &&\n !projects.some((project) => project.path === selectedPath)\n ) {\n await api.rememberDefaultSelection?.({ path: null });\n return {\n isSelectedPathMissing,\n projects,\n selection: {\n kind: \"clear\",\n suppressedPath: selectedPath\n }\n };\n }\n\n if (input.projectLocked || selectedPath) {\n return {\n isSelectedPathMissing,\n projects,\n selection: { kind: \"none\" }\n };\n }\n\n const defaultSelection = await api.getDefaultSelection?.();\n const defaultPath = defaultSelection?.path?.trim() ?? \"\";\n if (defaultPath && projects.some((project) => project.path === defaultPath)) {\n return {\n isSelectedPathMissing,\n projects,\n selection: {\n kind: \"select\",\n path: defaultPath\n }\n };\n }\n
|
|
1
|
+
{"version":3,"sources":["../src/core/index.ts"],"sourcesContent":["import type {\n WorkspaceUserProject,\n WorkspaceUserProjectApi,\n WorkspaceUserProjectCreationErrorCode,\n WorkspaceUserProjectSelectionPreparation,\n WorkspaceUserProjectSelectionPreparationInput\n} from \"../contracts/index.ts\";\n\nexport function upsertWorkspaceUserProject(\n projects: readonly WorkspaceUserProject[],\n project: WorkspaceUserProject\n): WorkspaceUserProject[] {\n const existingIndex = projects.findIndex(\n (item) => item.id === project.id || item.path === project.path\n );\n if (existingIndex < 0) {\n return [project, ...projects];\n }\n const next = [...projects];\n next[existingIndex] = project;\n return next;\n}\n\nexport function resolveWorkspaceUserProjectDisplayLabel(\n project: Pick<WorkspaceUserProject, \"id\" | \"label\" | \"path\">\n): string {\n const label = stripAbsolutePathFromWorkspaceUserProjectLabel(project.label);\n if (label) {\n return label;\n }\n return basenameWorkspaceUserProjectPath(project.path) || project.id;\n}\n\nexport function stripAbsolutePathFromWorkspaceUserProjectLabel(\n label: string\n): string {\n const trimmedLabel = label.trim();\n if (!trimmedLabel) {\n return \"\";\n }\n const pathStart = findAbsolutePathStart(trimmedLabel);\n if (pathStart < 0) {\n return trimmedLabel;\n }\n if (pathStart === 0) {\n return basenameWorkspaceUserProjectPath(trimmedLabel);\n }\n return trimmedLabel\n .slice(0, pathStart)\n .replace(/[\\s/\\\\|:()[\\]{}-]+$/u, \"\")\n .trim();\n}\n\nexport function basenameWorkspaceUserProjectPath(path: string): string {\n const normalizedPath = path.trim().replace(/[\\\\/]+$/u, \"\");\n if (!normalizedPath) {\n return \"\";\n }\n const segments = normalizedPath.split(/[\\\\/]+/u);\n return segments[segments.length - 1] ?? \"\";\n}\n\nexport function getWorkspaceUserProjectErrorCode(\n error: unknown\n): WorkspaceUserProjectCreationErrorCode | null {\n if (!error || typeof error !== \"object\") {\n return null;\n }\n\n const code = (error as { code?: unknown }).code;\n if (typeof code === \"string\") {\n return code;\n }\n\n return getWorkspaceUserProjectErrorCode((error as { cause?: unknown }).cause);\n}\n\nexport async function prepareWorkspaceUserProjectSelection(\n api: WorkspaceUserProjectApi,\n input: WorkspaceUserProjectSelectionPreparationInput\n): Promise<WorkspaceUserProjectSelectionPreparation> {\n if (api.prepareSelection) {\n return api.prepareSelection(input);\n }\n const response = await api.list();\n const projects = response.projects;\n const selectedPath = input.selectedPath?.trim() ?? \"\";\n const isSelectedPathMissing =\n input.projectLocked && selectedPath\n ? await checkWorkspaceUserProjectPathMissing(api, selectedPath)\n : false;\n\n if (\n !input.projectLocked &&\n selectedPath &&\n !projects.some((project) => project.path === selectedPath)\n ) {\n await api.rememberDefaultSelection?.({ path: null });\n return {\n isSelectedPathMissing,\n projects,\n selection: {\n kind: \"clear\",\n suppressedPath: selectedPath\n }\n };\n }\n\n if (input.projectLocked || selectedPath) {\n return {\n isSelectedPathMissing,\n projects,\n selection: { kind: \"none\" }\n };\n }\n\n const defaultSelection = await api.getDefaultSelection?.();\n const defaultPath = defaultSelection?.path?.trim() ?? \"\";\n if (defaultPath && projects.some((project) => project.path === defaultPath)) {\n return {\n isSelectedPathMissing,\n projects,\n selection: {\n kind: \"select\",\n path: defaultPath\n }\n };\n }\n return {\n isSelectedPathMissing,\n projects,\n selection: { kind: \"none\" }\n };\n}\n\nexport async function checkWorkspaceUserProjectPathMissing(\n api: Pick<WorkspaceUserProjectApi, \"checkPath\">,\n path: string\n): Promise<boolean> {\n try {\n const result = await api.checkPath?.({ path });\n return result ? !result.exists || !result.isDirectory : false;\n } catch {\n return false;\n }\n}\n\nfunction findAbsolutePathStart(value: string): number {\n const indexes = [\n value.search(/\\/[^\\s/]/u),\n value.search(/[A-Za-z]:[\\\\/]/u),\n value.search(/\\\\\\\\[^\\s\\\\]/u),\n value.search(/~[\\\\/]/u)\n ].filter((index) => index >= 0);\n return indexes.length > 0 ? Math.min(...indexes) : -1;\n}\n"],"mappings":";AAQO,SAAS,2BACd,UACA,SACwB;AACxB,QAAM,gBAAgB,SAAS;AAAA,IAC7B,CAAC,SAAS,KAAK,OAAO,QAAQ,MAAM,KAAK,SAAS,QAAQ;AAAA,EAC5D;AACA,MAAI,gBAAgB,GAAG;AACrB,WAAO,CAAC,SAAS,GAAG,QAAQ;AAAA,EAC9B;AACA,QAAM,OAAO,CAAC,GAAG,QAAQ;AACzB,OAAK,aAAa,IAAI;AACtB,SAAO;AACT;AAEO,SAAS,wCACd,SACQ;AACR,QAAM,QAAQ,+CAA+C,QAAQ,KAAK;AAC1E,MAAI,OAAO;AACT,WAAO;AAAA,EACT;AACA,SAAO,iCAAiC,QAAQ,IAAI,KAAK,QAAQ;AACnE;AAEO,SAAS,+CACd,OACQ;AACR,QAAM,eAAe,MAAM,KAAK;AAChC,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AACA,QAAM,YAAY,sBAAsB,YAAY;AACpD,MAAI,YAAY,GAAG;AACjB,WAAO;AAAA,EACT;AACA,MAAI,cAAc,GAAG;AACnB,WAAO,iCAAiC,YAAY;AAAA,EACtD;AACA,SAAO,aACJ,MAAM,GAAG,SAAS,EAClB,QAAQ,wBAAwB,EAAE,EAClC,KAAK;AACV;AAEO,SAAS,iCAAiC,MAAsB;AACrE,QAAM,iBAAiB,KAAK,KAAK,EAAE,QAAQ,YAAY,EAAE;AACzD,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,eAAe,MAAM,SAAS;AAC/C,SAAO,SAAS,SAAS,SAAS,CAAC,K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,EAC5B;AACF;AAEA,eAAsB,qCACpB,KACA,MACkB;AAClB,MAAI;AACF,UAAM,SAAS,MAAM,IAAI,YAAY,EAAE,KAAK,CAAC;AAC7C,WAAO,SAAS,CAAC,OAAO,UAAU,CAAC,OAAO,cAAc;AAAA,EAC1D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,sBAAsB,OAAuB;AACpD,QAAM,UAAU;AAAA,IACd,MAAM,OAAO,WAAW;AAAA,IACxB,MAAM,OAAO,iBAAiB;AAAA,IAC9B,MAAM,OAAO,cAAc;AAAA,IAC3B,MAAM,OAAO,SAAS;AAAA,EACxB,EAAE,OAAO,CAAC,UAAU,SAAS,CAAC;AAC9B,SAAO,QAAQ,SAAS,IAAI,KAAK,IAAI,GAAG,OAAO,IAAI;AACrD;","names":[]}
|
package/dist/core/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resolveWorkspaceUserProjectDisplayLabel,
|
|
7
7
|
stripAbsolutePathFromWorkspaceUserProjectLabel,
|
|
8
8
|
upsertWorkspaceUserProject
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-JKSIGLCI.js";
|
|
10
10
|
export {
|
|
11
11
|
basenameWorkspaceUserProjectPath,
|
|
12
12
|
checkWorkspaceUserProjectPathMissing,
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resolveWorkspaceUserProjectDisplayLabel,
|
|
7
7
|
stripAbsolutePathFromWorkspaceUserProjectLabel,
|
|
8
8
|
upsertWorkspaceUserProject
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JKSIGLCI.js";
|
|
10
10
|
import {
|
|
11
11
|
createDefaultWorkspaceUserProjectI18nRuntime,
|
|
12
12
|
createWorkspaceUserProjectI18nRuntime,
|
package/dist/ui/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
prepareWorkspaceUserProjectSelection,
|
|
5
5
|
resolveWorkspaceUserProjectDisplayLabel,
|
|
6
6
|
upsertWorkspaceUserProject
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-JKSIGLCI.js";
|
|
8
8
|
import {
|
|
9
9
|
createDefaultWorkspaceUserProjectI18nRuntime
|
|
10
10
|
} from "../chunk-LSYV5EMT.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tutti-os/workspace-user-project",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"directory": "packages/workspace/user-project"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tutti-os/ui-i18n-runtime": "0.0.
|
|
40
|
-
"@tutti-os/ui-system": "0.0.
|
|
39
|
+
"@tutti-os/ui-i18n-runtime": "0.0.15",
|
|
40
|
+
"@tutti-os/ui-system": "0.0.15",
|
|
41
41
|
"valtio": "^2.3.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -64,6 +64,6 @@
|
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsup --config tsup.config.ts",
|
|
66
66
|
"test": "node --test --experimental-strip-types \"./src/**/*.test.ts\"",
|
|
67
|
-
"typecheck": "
|
|
67
|
+
"typecheck": "node ../../../tools/scripts/run-tsgo-typecheck.mjs"
|
|
68
68
|
}
|
|
69
69
|
}
|