tsondb 0.5.18 → 0.6.0
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/src/bin/tsondb.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/node/config.d.ts +20 -0
- package/dist/src/node/config.js +5 -0
- package/dist/src/node/index.d.ts +3 -2
- package/dist/src/node/index.js +13 -8
- package/dist/src/node/renderers/jsonschema/render.d.ts +1 -1
- package/dist/src/node/renderers/jsonschema/render.js +12 -7
- package/dist/src/node/renderers/ts/render.d.ts +1 -1
- package/dist/src/node/renderers/ts/render.js +12 -6
- package/dist/src/node/schema/Node.d.ts +100 -29
- package/dist/src/node/schema/Node.js +268 -61
- package/dist/src/node/schema/Schema.js +96 -1
- package/dist/src/node/schema/TypeParameter.d.ts +7 -9
- package/dist/src/node/schema/TypeParameter.js +7 -5
- package/dist/src/node/schema/declarations/Declaration.d.ts +10 -28
- package/dist/src/node/schema/declarations/Declaration.js +8 -110
- package/dist/src/node/schema/declarations/EntityDecl.d.ts +48 -48
- package/dist/src/node/schema/declarations/EntityDecl.js +15 -12
- package/dist/src/node/schema/declarations/EnumDecl.d.ts +14 -17
- package/dist/src/node/schema/declarations/EnumDecl.js +12 -12
- package/dist/src/node/schema/declarations/TypeAliasDecl.d.ts +8 -14
- package/dist/src/node/schema/declarations/TypeAliasDecl.js +10 -11
- package/dist/src/node/schema/index.d.ts +0 -2
- package/dist/src/node/schema/index.js +0 -1
- package/dist/src/node/schema/types/Type.d.ts +19 -42
- package/dist/src/node/schema/types/Type.js +29 -167
- package/dist/src/node/schema/types/generic/ArrayType.d.ts +5 -14
- package/dist/src/node/schema/types/generic/ArrayType.js +15 -20
- package/dist/src/node/schema/types/generic/EnumType.d.ts +5 -17
- package/dist/src/node/schema/types/generic/EnumType.js +12 -20
- package/dist/src/node/schema/types/generic/ObjectType.d.ts +5 -19
- package/dist/src/node/schema/types/generic/ObjectType.js +11 -15
- package/dist/src/node/schema/types/primitives/BooleanType.d.ts +7 -8
- package/dist/src/node/schema/types/primitives/BooleanType.js +5 -4
- package/dist/src/node/schema/types/primitives/DateType.d.ts +6 -8
- package/dist/src/node/schema/types/primitives/DateType.js +5 -4
- package/dist/src/node/schema/types/primitives/FloatType.d.ts +9 -21
- package/dist/src/node/schema/types/primitives/FloatType.js +5 -4
- package/dist/src/node/schema/types/primitives/IntegerType.d.ts +9 -21
- package/dist/src/node/schema/types/primitives/IntegerType.js +5 -4
- package/dist/src/node/schema/types/primitives/StringType.d.ts +6 -10
- package/dist/src/node/schema/types/primitives/StringType.js +5 -4
- package/dist/src/node/schema/types/references/ChildEntitiesType.d.ts +18 -0
- package/dist/src/node/schema/types/references/ChildEntitiesType.js +18 -0
- package/dist/src/node/schema/types/references/IncludeIdentifierType.d.ts +7 -13
- package/dist/src/node/schema/types/references/IncludeIdentifierType.js +12 -12
- package/dist/src/node/schema/types/references/NestedEntityMapType.d.ts +7 -17
- package/dist/src/node/schema/types/references/NestedEntityMapType.js +11 -13
- package/dist/src/node/schema/types/references/ReferenceIdentifierType.d.ts +4 -10
- package/dist/src/node/schema/types/references/ReferenceIdentifierType.js +3 -5
- package/dist/src/node/schema/types/references/TypeArgumentType.d.ts +5 -10
- package/dist/src/node/schema/types/references/TypeArgumentType.js +10 -5
- package/dist/src/node/server/api/declarations.js +24 -6
- package/dist/src/node/server/api/index.js +11 -0
- package/dist/src/node/server/api/instances.js +9 -6
- package/dist/src/node/server/index.d.ts +6 -1
- package/dist/src/node/server/index.js +7 -3
- package/dist/src/node/server/init.d.ts +2 -1
- package/dist/src/node/server/init.js +11 -11
- package/dist/src/node/server/utils/childInstances.d.ts +4 -0
- package/dist/src/node/server/utils/childInstances.js +41 -0
- package/dist/src/node/server/utils/instanceOperations.d.ts +8 -0
- package/dist/src/node/server/utils/instanceOperations.js +107 -0
- package/dist/src/node/server/utils/locales.d.ts +2 -0
- package/dist/src/node/server/utils/locales.js +8 -0
- package/dist/src/node/utils/childInstances.d.ts +32 -0
- package/dist/src/node/utils/childInstances.js +164 -0
- package/dist/src/node/utils/displayName.d.ts +2 -1
- package/dist/src/node/utils/displayName.js +5 -4
- package/dist/src/node/utils/files.d.ts +5 -0
- package/dist/src/node/utils/files.js +9 -0
- package/dist/src/node/utils/instanceOperations.d.ts +14 -0
- package/dist/src/node/utils/instanceOperations.js +88 -0
- package/dist/src/node/utils/instances.d.ts +1 -1
- package/dist/src/node/utils/instances.js +12 -6
- package/dist/src/node/utils/references.d.ts +3 -1
- package/dist/src/node/utils/references.js +43 -18
- package/dist/src/node/utils/referencesWorker.d.ts +5 -0
- package/dist/src/node/utils/referencesWorker.js +22 -0
- package/dist/src/node/utils/workers.d.ts +15 -0
- package/dist/src/node/utils/workers.js +90 -0
- package/dist/src/shared/api.d.ts +14 -1
- package/dist/src/shared/schema/Node.d.ts +63 -0
- package/dist/src/shared/schema/Node.js +128 -0
- package/dist/src/shared/schema/TypeParameter.d.ts +9 -0
- package/dist/src/shared/schema/TypeParameter.js +2 -0
- package/dist/src/shared/schema/declarations/Declaration.d.ts +21 -0
- package/dist/src/shared/schema/declarations/Declaration.js +4 -0
- package/dist/src/shared/schema/declarations/EntityDecl.d.ts +32 -0
- package/dist/src/shared/schema/declarations/EntityDecl.js +8 -0
- package/dist/src/shared/schema/declarations/EnumDecl.d.ts +11 -0
- package/dist/src/shared/schema/declarations/EnumDecl.js +9 -0
- package/dist/src/shared/schema/declarations/TypeAliasDecl.d.ts +11 -0
- package/dist/src/shared/schema/declarations/TypeAliasDecl.js +7 -0
- package/dist/src/shared/schema/types/ArrayType.d.ts +11 -0
- package/dist/src/shared/schema/types/ArrayType.js +8 -0
- package/dist/src/shared/schema/types/BooleanType.d.ts +7 -0
- package/dist/src/shared/schema/types/BooleanType.js +2 -0
- package/dist/src/shared/schema/types/ChildEntitiesType.d.ts +8 -0
- package/dist/src/shared/schema/types/ChildEntitiesType.js +2 -0
- package/dist/src/shared/schema/types/DateType.d.ts +8 -0
- package/dist/src/shared/schema/types/DateType.js +2 -0
- package/dist/src/shared/schema/types/EnumType.d.ts +14 -0
- package/dist/src/shared/schema/types/EnumType.js +28 -0
- package/dist/src/shared/schema/types/FloatType.d.ts +11 -0
- package/dist/src/shared/schema/types/FloatType.js +2 -0
- package/dist/src/shared/schema/types/IncludeIdentifierType.d.ts +11 -0
- package/dist/src/shared/schema/types/IncludeIdentifierType.js +13 -0
- package/dist/src/shared/schema/types/IntegerType.d.ts +11 -0
- package/dist/src/shared/schema/types/IntegerType.js +2 -0
- package/dist/src/shared/schema/types/NestedEntityMapType.d.ts +17 -0
- package/dist/src/shared/schema/types/NestedEntityMapType.js +14 -0
- package/dist/src/shared/schema/types/ObjectType.d.ts +19 -0
- package/dist/src/shared/schema/types/ObjectType.js +14 -0
- package/dist/src/shared/schema/types/ReferenceIdentifierType.d.ts +8 -0
- package/dist/src/shared/schema/types/ReferenceIdentifierType.js +2 -0
- package/dist/src/shared/schema/types/StringType.d.ts +10 -0
- package/dist/src/shared/schema/types/StringType.js +2 -0
- package/dist/src/shared/schema/types/Type.d.ts +20 -0
- package/dist/src/shared/schema/types/TypeArgumentType.d.ts +12 -0
- package/dist/src/shared/schema/types/TypeArgumentType.js +7 -0
- package/dist/src/shared/utils/array.d.ts +4 -0
- package/dist/src/shared/utils/array.js +30 -0
- package/dist/src/shared/utils/async.d.ts +8 -0
- package/dist/src/shared/utils/async.js +35 -0
- package/dist/src/shared/utils/compare.js +3 -3
- package/dist/src/shared/utils/displayName.d.ts +6 -2
- package/dist/src/shared/utils/displayName.js +21 -8
- package/dist/src/shared/utils/instances.d.ts +2 -3
- package/dist/src/shared/utils/instances.js +3 -1
- package/dist/src/shared/utils/markdown.d.ts +4 -0
- package/dist/src/shared/utils/markdown.js +173 -110
- package/dist/src/shared/utils/object.d.ts +2 -0
- package/dist/src/shared/utils/object.js +2 -0
- package/dist/src/shared/utils/result.d.ts +8 -2
- package/dist/src/shared/utils/result.js +1 -1
- package/dist/src/web/api/declarations.d.ts +26 -0
- package/dist/src/web/api/declarations.js +51 -0
- package/dist/src/web/api/git.d.ts +14 -0
- package/dist/src/web/api/git.js +20 -0
- package/dist/src/web/api/index.d.ts +1 -0
- package/dist/src/web/api/index.js +2 -0
- package/dist/src/web/api/instances.d.ts +2 -0
- package/dist/src/web/api/instances.js +2 -0
- package/dist/src/web/components/Git.js +19 -16
- package/dist/src/web/components/InstanceRouteSkeleton.d.ts +42 -0
- package/dist/src/web/components/InstanceRouteSkeleton.js +114 -0
- package/dist/src/web/components/Layout.js +3 -2
- package/dist/src/web/components/ModalDialog.d.ts +3 -0
- package/dist/src/web/components/ModalDialog.js +16 -0
- package/dist/src/web/components/Settings.d.ts +2 -0
- package/dist/src/web/components/Settings.js +47 -0
- package/dist/src/web/components/typeInputs/ArrayTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/ArrayTypeInput.js +5 -4
- package/dist/src/web/components/typeInputs/BooleanTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/BooleanTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.d.ts +6 -0
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.js +27 -0
- package/dist/src/web/components/typeInputs/DateTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/DateTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/EnumTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/EnumTypeInput.js +55 -22
- package/dist/src/web/components/typeInputs/FloatTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/FloatTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +3 -4
- package/dist/src/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/IncludeIdentifierTypeInput.js +3 -2
- package/dist/src/web/components/typeInputs/IntegerTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/IntegerTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/NestedEntityMapTypeInput.js +5 -4
- package/dist/src/web/components/typeInputs/ObjectTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/ObjectTypeInput.js +8 -5
- package/dist/src/web/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -8
- package/dist/src/web/components/typeInputs/ReferenceIdentifierTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/StringTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/StringTypeInput.js +3 -3
- package/dist/src/web/components/typeInputs/TypeInput.d.ts +12 -4
- package/dist/src/web/components/typeInputs/TypeInput.js +22 -17
- package/dist/src/web/components/typeInputs/utils/ValidationErrors.d.ts +1 -0
- package/dist/src/web/components/typeInputs/utils/ValidationErrors.js +1 -3
- package/dist/src/web/context/config.d.ts +11 -0
- package/dist/src/web/context/config.js +6 -0
- package/dist/src/web/context/entities.d.ts +8 -5
- package/dist/src/web/context/entities.js +1 -1
- package/dist/src/web/context/settings.d.ts +8 -0
- package/dist/src/web/context/settings.js +10 -0
- package/dist/src/web/hooks/useEntityFromRoute.d.ts +1 -1
- package/dist/src/web/hooks/useEntityFromRoute.js +2 -2
- package/dist/src/web/hooks/useInstanceNamesByEntity.d.ts +1 -1
- package/dist/src/web/hooks/useInstanceNamesByEntity.js +4 -2
- package/dist/src/web/hooks/useMappedAPIResource.js +2 -4
- package/dist/src/web/hooks/useSecondaryDeclarations.d.ts +1 -1
- package/dist/src/web/hooks/useSecondaryDeclarations.js +8 -4
- package/dist/src/web/hooks/useSettings.d.ts +10 -0
- package/dist/src/web/hooks/useSettings.js +51 -0
- package/dist/src/web/index.js +11 -5
- package/dist/src/web/routes/CreateInstance.js +40 -79
- package/dist/src/web/routes/Entity.js +42 -19
- package/dist/src/web/routes/Home.js +24 -5
- package/dist/src/web/routes/Instance.js +34 -85
- package/dist/src/web/utils/InlineMarkdown.d.ts +1 -1
- package/dist/src/web/utils/InlineMarkdown.js +13 -1
- package/dist/src/web/utils/api.d.ts +25 -0
- package/dist/src/web/utils/api.js +34 -0
- package/dist/src/web/utils/typeSkeleton.d.ts +1 -1
- package/dist/src/web/utils/typeSkeleton.js +2 -0
- package/package.json +2 -1
- package/public/css/styles.css +171 -12
- package/dist/src/node/schema/types/primitives/NumericType.d.ts +0 -6
- package/dist/src/node/schema/types/primitives/NumericType.js +0 -2
- package/dist/src/node/schema/types/primitives/PrimitiveType.d.ts +0 -6
- package/dist/src/node/schema/validation/type.d.ts +0 -4
- package/dist/src/node/schema/validation/type.js +0 -1
- package/dist/src/node/server/api/instanceOperations.d.ts +0 -6
- package/dist/src/node/server/api/instanceOperations.js +0 -93
- package/dist/src/shared/config.d.ts +0 -11
- package/dist/src/shared/config.js +0 -1
- package/dist/src/web/api.d.ts +0 -24
- package/dist/src/web/api.js +0 -201
- /package/dist/src/{node/schema/types/primitives/PrimitiveType.js → shared/schema/types/Type.js} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CreatedEntityTaggedInstanceContainerWithChildInstances, UpdatedEntityTaggedInstanceContainerWithChildInstances } from "../../node/utils/childInstances.ts";
|
|
2
|
+
import type { CreateInstanceOfEntityResponseBody, DeleteInstanceOfEntityResponseBody, GetAllChildInstancesOfInstanceResponseBody, GetAllDeclarationsResponseBody, GetAllInstancesOfEntityResponseBody, GetDeclarationResponseBody, GetInstanceOfEntityResponseBody, UpdateInstanceOfEntityResponseBody } from "../../shared/api.ts";
|
|
3
|
+
import type { SerializedDecl } from "../../shared/schema/declarations/Declaration.ts";
|
|
4
|
+
import type { SerializedEntityDecl } from "../../shared/schema/declarations/EntityDecl.ts";
|
|
5
|
+
import type { SerializedEnumDecl } from "../../shared/schema/declarations/EnumDecl.ts";
|
|
6
|
+
import type { SerializedTypeAliasDecl } from "../../shared/schema/declarations/TypeAliasDecl.ts";
|
|
7
|
+
type DeclKind = "Entity" | "Enum" | "TypeAlias";
|
|
8
|
+
type DeclTypeForKind<K extends DeclKind | undefined> = K extends "Entity" ? SerializedEntityDecl : K extends "Enum" ? SerializedEnumDecl : K extends "TypeAlias" ? SerializedTypeAliasDecl : SerializedDecl;
|
|
9
|
+
export declare const getAllDeclarations: {
|
|
10
|
+
(locales: string[], kind?: undefined): Promise<GetAllDeclarationsResponseBody>;
|
|
11
|
+
<D extends "Entity" | "Enum" | "TypeAlias">(locales: string[], kind: D): Promise<GetAllDeclarationsResponseBody<DeclTypeForKind<D>>>;
|
|
12
|
+
};
|
|
13
|
+
export declare const getAllEntities: (locales: string[]) => Promise<GetAllDeclarationsResponseBody<SerializedEntityDecl<string, {
|
|
14
|
+
[x: string]: import("../../shared/schema/types/ObjectType.ts").SerializedMemberDecl<import("../../shared/schema/types/Type.ts").SerializedType, boolean>;
|
|
15
|
+
}, string | undefined>>>;
|
|
16
|
+
export declare const getEntityByName: (locales: string[], name: string) => Promise<GetDeclarationResponseBody<SerializedEntityDecl<string, {
|
|
17
|
+
[x: string]: import("../../shared/schema/types/ObjectType.ts").SerializedMemberDecl<import("../../shared/schema/types/Type.ts").SerializedType, boolean>;
|
|
18
|
+
}, string | undefined>>>;
|
|
19
|
+
export declare const getInstancesByEntityName: (locales: string[], name: string) => Promise<GetAllInstancesOfEntityResponseBody>;
|
|
20
|
+
export declare const getLocaleInstances: (locales: string[], localeEntityName: string | undefined) => Promise<GetAllInstancesOfEntityResponseBody>;
|
|
21
|
+
export declare const createInstanceByEntityNameAndId: (locales: string[], name: string, content: CreatedEntityTaggedInstanceContainerWithChildInstances, id?: string) => Promise<CreateInstanceOfEntityResponseBody>;
|
|
22
|
+
export declare const getInstanceByEntityNameAndId: (locales: string[], name: string, id: string) => Promise<GetInstanceOfEntityResponseBody>;
|
|
23
|
+
export declare const updateInstanceByEntityNameAndId: (locales: string[], name: string, id: string, content: UpdatedEntityTaggedInstanceContainerWithChildInstances) => Promise<UpdateInstanceOfEntityResponseBody>;
|
|
24
|
+
export declare const deleteInstanceByEntityNameAndId: (locales: string[], name: string, id: string) => Promise<DeleteInstanceOfEntityResponseBody>;
|
|
25
|
+
export declare const getChildInstancesForInstanceByEntityName: (locales: string[], name: string, parentId: string) => Promise<GetAllChildInstancesOfInstanceResponseBody>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { deleteResource, getResource, postResource, putResource } from "../utils/api.js";
|
|
2
|
+
export const getAllDeclarations = async (locales, kind) => getResource("/api/declarations", {
|
|
3
|
+
locales,
|
|
4
|
+
modifyUrl: url => {
|
|
5
|
+
if (kind) {
|
|
6
|
+
url.searchParams.append("kind", kind);
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
export const getAllEntities = (locales) => getAllDeclarations(locales, "Entity");
|
|
11
|
+
export const getEntityByName = async (locales, name) => getResource(`/api/declarations/${name}`, {
|
|
12
|
+
locales,
|
|
13
|
+
});
|
|
14
|
+
export const getInstancesByEntityName = async (locales, name) => getResource(`/api/declarations/${name}/instances`, {
|
|
15
|
+
locales,
|
|
16
|
+
});
|
|
17
|
+
export const getLocaleInstances = (locales, localeEntityName) => localeEntityName
|
|
18
|
+
? getInstancesByEntityName(locales, localeEntityName)
|
|
19
|
+
: Promise.resolve({ instances: [], isLocaleEntity: true });
|
|
20
|
+
export const createInstanceByEntityNameAndId = async (locales, name, content, id) => {
|
|
21
|
+
const body = {
|
|
22
|
+
instance: content,
|
|
23
|
+
};
|
|
24
|
+
return postResource(`/api/declarations/${name}/instances`, {
|
|
25
|
+
locales,
|
|
26
|
+
body,
|
|
27
|
+
modifyUrl: url => {
|
|
28
|
+
if (id) {
|
|
29
|
+
url.searchParams.append("id", id);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export const getInstanceByEntityNameAndId = async (locales, name, id) => getResource(`/api/declarations/${name}/instances/${id}`, {
|
|
35
|
+
locales,
|
|
36
|
+
});
|
|
37
|
+
export const updateInstanceByEntityNameAndId = async (locales, name, id, content) => {
|
|
38
|
+
const body = {
|
|
39
|
+
instance: content,
|
|
40
|
+
};
|
|
41
|
+
return putResource(`/api/declarations/${name}/instances/${id}`, {
|
|
42
|
+
locales,
|
|
43
|
+
body,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export const deleteInstanceByEntityNameAndId = async (locales, name, id) => deleteResource(`/api/declarations/${name}/instances/${id}`, {
|
|
47
|
+
locales,
|
|
48
|
+
});
|
|
49
|
+
export const getChildInstancesForInstanceByEntityName = async (locales, name, parentId) => getResource(`/api/declarations/${name}/instances/${parentId}/children`, {
|
|
50
|
+
locales,
|
|
51
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GetAllGitBranchesResponseBody, GitStatusResponseBody } from "../../shared/api.ts";
|
|
2
|
+
export declare const getStatus: (locales: string[]) => Promise<GitStatusResponseBody>;
|
|
3
|
+
export declare const stageAllFiles: (locales: string[]) => Promise<void>;
|
|
4
|
+
export declare const stageAllFilesOfEntity: (locales: string[], entityName: string) => Promise<void>;
|
|
5
|
+
export declare const stageFileOfEntity: (locales: string[], entityName: string, id: string) => Promise<void>;
|
|
6
|
+
export declare const unstageAllFiles: (locales: string[]) => Promise<void>;
|
|
7
|
+
export declare const unstageAllFilesOfEntity: (locales: string[], entityName: string) => Promise<void>;
|
|
8
|
+
export declare const unstageFileOfEntity: (locales: string[], entityName: string, id: string) => Promise<void>;
|
|
9
|
+
export declare const commitStagedFiles: (locales: string[], message: string) => Promise<void>;
|
|
10
|
+
export declare const pushCommits: (locales: string[]) => Promise<void>;
|
|
11
|
+
export declare const pullCommits: (locales: string[]) => Promise<void>;
|
|
12
|
+
export declare const getBranches: (locales: string[]) => Promise<GetAllGitBranchesResponseBody>;
|
|
13
|
+
export declare const createBranch: (locales: string[], branchName: string) => Promise<void>;
|
|
14
|
+
export declare const switchBranch: (locales: string[], branchName: string) => Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getResource, postResource } from "../utils/api.js";
|
|
2
|
+
export const getStatus = async (locales) => getResource("/api/git/status", { locales });
|
|
3
|
+
export const stageAllFiles = async (locales) => postResource("/api/git/stage", { locales });
|
|
4
|
+
export const stageAllFilesOfEntity = async (locales, entityName) => postResource(`/api/git/stage/${entityName}`, { locales });
|
|
5
|
+
export const stageFileOfEntity = async (locales, entityName, id) => postResource(`/api/git/stage/${entityName}/${id}`, { locales });
|
|
6
|
+
export const unstageAllFiles = async (locales) => postResource(`/api/git/unstage`, { locales });
|
|
7
|
+
export const unstageAllFilesOfEntity = async (locales, entityName) => postResource(`/api/git/unstage/${entityName}`, { locales });
|
|
8
|
+
export const unstageFileOfEntity = async (locales, entityName, id) => postResource(`/api/git/unstage/${entityName}/${id}`, { locales });
|
|
9
|
+
export const commitStagedFiles = async (locales, message) => {
|
|
10
|
+
const body = { message };
|
|
11
|
+
return postResource(`/api/git/commit`, { locales, body });
|
|
12
|
+
};
|
|
13
|
+
export const pushCommits = async (locales) => postResource(`/api/git/push`, { locales });
|
|
14
|
+
export const pullCommits = async (locales) => postResource(`/api/git/pull`, { locales });
|
|
15
|
+
export const getBranches = async (locales) => getResource(`/api/git/branch`, { locales });
|
|
16
|
+
export const createBranch = async (locales, branchName) => {
|
|
17
|
+
const body = { branchName };
|
|
18
|
+
return postResource(`/api/git/branch`, { locales, body });
|
|
19
|
+
};
|
|
20
|
+
export const switchBranch = async (locales, branchName) => postResource(`/api/git/branch/${branchName}`, { locales });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getWebConfig: () => Promise<import("../context/config.ts").WebConfig>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
2
|
import { useLocation } from "preact-iso";
|
|
3
|
-
import { useEffect, useState } from "preact/hooks";
|
|
3
|
+
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
4
4
|
import { getGitStatusForDisplay, getLabelForGitStatus, isChangedInIndex, isChangedInWorkingDir, } from "../../shared/utils/git.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getAllEntities } from "../api/declarations.js";
|
|
6
|
+
import { commitStagedFiles, createBranch, getBranches, getStatus, pullCommits, pushCommits, stageAllFiles, stageFileOfEntity, switchBranch, unstageAllFiles, unstageFileOfEntity, } from "../api/git.js";
|
|
7
|
+
import { useSetting } from "../hooks/useSettings.js";
|
|
6
8
|
const filterFilesForDisplay = (predicate, entities, data) => Object.entries(data.instances)
|
|
7
9
|
.map(([entityName, instances]) => [
|
|
8
10
|
entityName,
|
|
@@ -17,9 +19,10 @@ const GitFileList = ({ filesByEntity, onFile, isIndex = false }) => filesByEntit
|
|
|
17
19
|
const gitStatusForDisplay = getGitStatusForDisplay(instance.gitStatus);
|
|
18
20
|
return (_jsxs("li", { class: "git-instance-list-item", children: [_jsx("span", { class: "title", children: instance.displayName }), _jsx("span", { class: `git-status git-status--${gitStatusForDisplay ?? ""}`, title: getLabelForGitStatus(gitStatusForDisplay), children: gitStatusForDisplay }), _jsx("button", { onClick: () => {
|
|
19
21
|
onFile(entityName, instance);
|
|
20
|
-
}, children: isIndex ? "Unstage" : "Stage" })] }, instance.
|
|
22
|
+
}, children: isIndex ? "Unstage" : "Stage" })] }, instance.id));
|
|
21
23
|
}) })] }, entityName))) }));
|
|
22
24
|
export const Git = () => {
|
|
25
|
+
const [locales] = useSetting("displayedLocales");
|
|
23
26
|
const [isOpen, setIsOpen] = useState(false);
|
|
24
27
|
const [commitsAhead, setCommitsAhead] = useState(0);
|
|
25
28
|
const [commitsBehind, setCommitsBehind] = useState(0);
|
|
@@ -29,17 +32,17 @@ export const Git = () => {
|
|
|
29
32
|
const [entities, setEntities] = useState([]);
|
|
30
33
|
const [allBranches, setAllBranches] = useState([]);
|
|
31
34
|
const [currentBranch, setCurrentBranch] = useState("");
|
|
32
|
-
const updateGitStatus = (localEntities) => Promise.all([
|
|
35
|
+
const updateGitStatus = useCallback((localEntities) => Promise.all([getStatus(locales), getBranches(locales)]).then(([statusData, branchesData]) => {
|
|
33
36
|
setIndexFiles(filterFilesForDisplay(isChangedInIndex, localEntities, statusData));
|
|
34
37
|
setWorkingTreeFiles(filterFilesForDisplay(isChangedInWorkingDir, localEntities, statusData));
|
|
35
38
|
setCommitsAhead(statusData.commitsAhead);
|
|
36
39
|
setCommitsBehind(statusData.commitsBehind);
|
|
37
40
|
setAllBranches(branchesData.allBranches);
|
|
38
41
|
setCurrentBranch(branchesData.currentBranch);
|
|
39
|
-
});
|
|
42
|
+
}), [locales]);
|
|
40
43
|
const location = useLocation();
|
|
41
44
|
useEffect(() => {
|
|
42
|
-
getAllEntities()
|
|
45
|
+
getAllEntities(locales)
|
|
43
46
|
.then(async (data) => {
|
|
44
47
|
const entitiesFromServer = data.declarations.map(decl => decl.declaration);
|
|
45
48
|
setEntities(entitiesFromServer);
|
|
@@ -50,9 +53,9 @@ export const Git = () => {
|
|
|
50
53
|
console.error("Error fetching entities:", error.toString());
|
|
51
54
|
}
|
|
52
55
|
});
|
|
53
|
-
}, [location.path]);
|
|
56
|
+
}, [location.path, locales, updateGitStatus]);
|
|
54
57
|
const stage = (entityName, instance) => {
|
|
55
|
-
stageFileOfEntity(entityName, instance.id)
|
|
58
|
+
stageFileOfEntity(locales, entityName, instance.id)
|
|
56
59
|
.then(() => updateGitStatus(entities))
|
|
57
60
|
.catch((error) => {
|
|
58
61
|
if (error instanceof Error) {
|
|
@@ -61,7 +64,7 @@ export const Git = () => {
|
|
|
61
64
|
});
|
|
62
65
|
};
|
|
63
66
|
const stageAll = () => {
|
|
64
|
-
stageAllFiles()
|
|
67
|
+
stageAllFiles(locales)
|
|
65
68
|
.then(() => updateGitStatus(entities))
|
|
66
69
|
.catch((error) => {
|
|
67
70
|
if (error instanceof Error) {
|
|
@@ -70,7 +73,7 @@ export const Git = () => {
|
|
|
70
73
|
});
|
|
71
74
|
};
|
|
72
75
|
const unstage = (entityName, instance) => {
|
|
73
|
-
unstageFileOfEntity(entityName, instance.id)
|
|
76
|
+
unstageFileOfEntity(locales, entityName, instance.id)
|
|
74
77
|
.then(() => updateGitStatus(entities))
|
|
75
78
|
.catch((error) => {
|
|
76
79
|
if (error instanceof Error) {
|
|
@@ -79,7 +82,7 @@ export const Git = () => {
|
|
|
79
82
|
});
|
|
80
83
|
};
|
|
81
84
|
const unstageAll = () => {
|
|
82
|
-
unstageAllFiles()
|
|
85
|
+
unstageAllFiles(locales)
|
|
83
86
|
.then(() => updateGitStatus(entities))
|
|
84
87
|
.catch((error) => {
|
|
85
88
|
if (error instanceof Error) {
|
|
@@ -91,7 +94,7 @@ export const Git = () => {
|
|
|
91
94
|
if (commitMessage.length > 0 &&
|
|
92
95
|
indexFiles.length > 0 &&
|
|
93
96
|
confirm("Do you want to commit all staged files?")) {
|
|
94
|
-
commitStagedFiles(commitMessage)
|
|
97
|
+
commitStagedFiles(locales, commitMessage)
|
|
95
98
|
.then(() => {
|
|
96
99
|
setCommitMessage("");
|
|
97
100
|
return updateGitStatus(entities);
|
|
@@ -104,7 +107,7 @@ export const Git = () => {
|
|
|
104
107
|
}
|
|
105
108
|
};
|
|
106
109
|
const push = () => {
|
|
107
|
-
pushCommits()
|
|
110
|
+
pushCommits(locales)
|
|
108
111
|
.then(() => {
|
|
109
112
|
alert("Pushed commits successfully");
|
|
110
113
|
return updateGitStatus(entities);
|
|
@@ -114,7 +117,7 @@ export const Git = () => {
|
|
|
114
117
|
});
|
|
115
118
|
};
|
|
116
119
|
const pull = () => {
|
|
117
|
-
pullCommits()
|
|
120
|
+
pullCommits(locales)
|
|
118
121
|
.then(() => {
|
|
119
122
|
alert("Pulled commits successfully");
|
|
120
123
|
return updateGitStatus(entities);
|
|
@@ -133,7 +136,7 @@ export const Git = () => {
|
|
|
133
136
|
alert("Branch name already exists");
|
|
134
137
|
return;
|
|
135
138
|
}
|
|
136
|
-
createBranch(newBranchName)
|
|
139
|
+
createBranch(locales, newBranchName)
|
|
137
140
|
.then(() => {
|
|
138
141
|
return updateGitStatus(entities);
|
|
139
142
|
})
|
|
@@ -144,7 +147,7 @@ export const Git = () => {
|
|
|
144
147
|
});
|
|
145
148
|
};
|
|
146
149
|
const onSwitchBranch = (event) => {
|
|
147
|
-
switchBranch(event.currentTarget.value)
|
|
150
|
+
switchBranch(locales, event.currentTarget.value)
|
|
148
151
|
.then(() => {
|
|
149
152
|
return updateGitStatus(entities);
|
|
150
153
|
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FunctionalComponent } from "preact";
|
|
2
|
+
import { type LocationHook } from "preact-iso";
|
|
3
|
+
import type { SetStateAction } from "preact/compat";
|
|
4
|
+
import { type Dispatch } from "preact/hooks";
|
|
5
|
+
import type { UnsafeEntityTaggedInstanceContainerWithChildInstances } from "../../node/utils/childInstances.ts";
|
|
6
|
+
import type { SerializedEntityDecl } from "../../shared/schema/declarations/EntityDecl.ts";
|
|
7
|
+
import { type GetDeclFromDeclName } from "../hooks/useSecondaryDeclarations.ts";
|
|
8
|
+
export type InstanceRouteSkeletonInitializer = (values: {
|
|
9
|
+
locales: string[];
|
|
10
|
+
entity: SerializedEntityDecl;
|
|
11
|
+
instanceId: string | undefined;
|
|
12
|
+
setInstanceContent: Dispatch<SetStateAction<unknown>>;
|
|
13
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
export type InstanceRouteSkeletonOnSubmitHandler = (values: {
|
|
16
|
+
locales: string[];
|
|
17
|
+
entity: SerializedEntityDecl;
|
|
18
|
+
instanceId: string | undefined;
|
|
19
|
+
instanceContent: unknown;
|
|
20
|
+
buttonName: string | undefined;
|
|
21
|
+
customId: string;
|
|
22
|
+
isLocaleEntity: boolean | undefined;
|
|
23
|
+
childInstances: UnsafeEntityTaggedInstanceContainerWithChildInstances[];
|
|
24
|
+
route: LocationHook["route"];
|
|
25
|
+
setInstanceContent: Dispatch<SetStateAction<unknown>>;
|
|
26
|
+
setCustomId: Dispatch<SetStateAction<string>>;
|
|
27
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
28
|
+
}) => Promise<void>;
|
|
29
|
+
export type InstanceRouteSkeletonTitleBuilder = (values: {
|
|
30
|
+
locales: string[];
|
|
31
|
+
entity: SerializedEntityDecl;
|
|
32
|
+
instanceId: string | undefined;
|
|
33
|
+
instanceContent: unknown;
|
|
34
|
+
}) => string | undefined;
|
|
35
|
+
type Props = {
|
|
36
|
+
mode: "create" | "edit";
|
|
37
|
+
init: InstanceRouteSkeletonInitializer;
|
|
38
|
+
titleBuilder: InstanceRouteSkeletonTitleBuilder;
|
|
39
|
+
onSubmit: InstanceRouteSkeletonOnSubmitHandler;
|
|
40
|
+
};
|
|
41
|
+
export declare const InstanceRouteSkeleton: FunctionalComponent<Props>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useLocation, useRoute } from "preact-iso";
|
|
3
|
+
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
4
|
+
import { removeAt } from "../../shared/utils/array.js";
|
|
5
|
+
import { getSerializedDisplayNameFromEntityInstance } from "../../shared/utils/displayName.js";
|
|
6
|
+
import { toTitleCase } from "../../shared/utils/string.js";
|
|
7
|
+
import { validateLocaleIdentifier } from "../../shared/validation/identifier.js";
|
|
8
|
+
import { deleteInstanceByEntityNameAndId, getChildInstancesForInstanceByEntityName, } from "../api/declarations.js";
|
|
9
|
+
import { useEntityFromRoute } from "../hooks/useEntityFromRoute.js";
|
|
10
|
+
import { useInstanceNamesByEntity } from "../hooks/useInstanceNamesByEntity.js";
|
|
11
|
+
import { useGetDeclFromDeclName, } from "../hooks/useSecondaryDeclarations.js";
|
|
12
|
+
import { useSetting } from "../hooks/useSettings.js";
|
|
13
|
+
import { homeTitle } from "../routes/Home.js";
|
|
14
|
+
import { NotFound } from "../routes/NotFound.js";
|
|
15
|
+
import { Layout } from "./Layout.js";
|
|
16
|
+
import { TypeInput } from "./typeInputs/TypeInput.js";
|
|
17
|
+
import { ValidationErrors } from "./typeInputs/utils/ValidationErrors.js";
|
|
18
|
+
export const InstanceRouteSkeleton = ({ mode, init, titleBuilder, onSubmit, }) => {
|
|
19
|
+
const { params: { name, id }, } = useRoute();
|
|
20
|
+
const [locales] = useSetting("displayedLocales");
|
|
21
|
+
const [getDeclFromDeclName, declsLoaded] = useGetDeclFromDeclName();
|
|
22
|
+
const { declaration: entity, isLocaleEntity } = useEntityFromRoute() ?? {};
|
|
23
|
+
const [instanceNamesByEntity] = useInstanceNamesByEntity();
|
|
24
|
+
const [instanceContent, setInstanceContent] = useState();
|
|
25
|
+
const [childInstances, setChildInstances] = useState([]);
|
|
26
|
+
const [customId, setCustomId] = useState("");
|
|
27
|
+
const { route } = useLocation();
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
document.title =
|
|
30
|
+
(entity && titleBuilder({ locales, entity, instanceContent, instanceId: id })) ??
|
|
31
|
+
"Not found — TSONDB";
|
|
32
|
+
}, [entity, id, instanceContent, locales, titleBuilder]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (entity && instanceContent === undefined) {
|
|
35
|
+
init({ locales, entity, instanceId: id, setInstanceContent, getDeclFromDeclName })
|
|
36
|
+
.then(() => id
|
|
37
|
+
? getChildInstancesForInstanceByEntityName(locales, entity.name, id).then(result => {
|
|
38
|
+
setChildInstances(result.instances);
|
|
39
|
+
})
|
|
40
|
+
: Promise.resolve())
|
|
41
|
+
.catch((error) => {
|
|
42
|
+
console.error("Error initializing instance route skeleton:", error);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, [entity, getDeclFromDeclName, id, init, instanceContent, locales, name]);
|
|
46
|
+
const handleSubmit = (event) => {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
if (entity && instanceContent !== undefined) {
|
|
49
|
+
const buttonName = event.submitter?.getAttribute("name") ?? undefined;
|
|
50
|
+
onSubmit({
|
|
51
|
+
locales,
|
|
52
|
+
entity,
|
|
53
|
+
instanceId: id,
|
|
54
|
+
instanceContent,
|
|
55
|
+
buttonName,
|
|
56
|
+
route,
|
|
57
|
+
customId,
|
|
58
|
+
getDeclFromDeclName,
|
|
59
|
+
isLocaleEntity,
|
|
60
|
+
setCustomId,
|
|
61
|
+
setInstanceContent,
|
|
62
|
+
childInstances,
|
|
63
|
+
}).catch((error) => {
|
|
64
|
+
console.error("Error submitting instance data:", error);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const handleOnChildChange = useCallback((index, value) => {
|
|
69
|
+
setChildInstances(old => old[index] ? old.with(index, { ...old[index], content: value }) : old);
|
|
70
|
+
}, []);
|
|
71
|
+
const handleOnChildAdd = useCallback((entityName, value) => {
|
|
72
|
+
setChildInstances(old => [
|
|
73
|
+
...old,
|
|
74
|
+
{ entityName, childInstances: [], id: undefined, content: value },
|
|
75
|
+
]);
|
|
76
|
+
}, []);
|
|
77
|
+
const handleOnChildRemove = useCallback((index) => {
|
|
78
|
+
setChildInstances(old => removeAt(old, index));
|
|
79
|
+
}, []);
|
|
80
|
+
if (!name || (mode === "edit" && !id)) {
|
|
81
|
+
return _jsx(NotFound, {});
|
|
82
|
+
}
|
|
83
|
+
if (!entity || instanceContent === undefined || !instanceNamesByEntity || !declsLoaded) {
|
|
84
|
+
return (_jsxs(Layout, { breadcrumbs: [
|
|
85
|
+
{ url: "/", label: homeTitle },
|
|
86
|
+
{
|
|
87
|
+
url: `/entities/${name}`,
|
|
88
|
+
label: entity ? toTitleCase(entity.namePlural) : name,
|
|
89
|
+
},
|
|
90
|
+
], children: [_jsxs("div", { class: "header-with-btns", children: [_jsxs("h1", { class: "empty-name", children: [_jsx("span", { children: id }), " ", id && (_jsx("span", { class: "id", "aria-hidden": true, children: id }))] }), _jsx("button", { class: "destructive", disabled: true, children: "Delete" })] }), _jsx("p", { class: "loading", children: "Loading \u2026" })] }));
|
|
91
|
+
}
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Already checked for NotFound above
|
|
93
|
+
const defaultName = mode === "edit" ? id : customId || `New ${toTitleCase(entity.name)}`;
|
|
94
|
+
const instanceName = getSerializedDisplayNameFromEntityInstance(entity, instanceContent, defaultName, locales).name;
|
|
95
|
+
const idErrors = mode === "create" && isLocaleEntity ? validateLocaleIdentifier(customId) : [];
|
|
96
|
+
return (_jsxs(Layout, { breadcrumbs: [
|
|
97
|
+
{ url: "/", label: homeTitle },
|
|
98
|
+
{ url: `/entities/${name}`, label: toTitleCase(entity.namePlural) },
|
|
99
|
+
], children: [_jsxs("div", { class: "header-with-btns", children: [_jsxs("h1", { class: instanceName.length === 0 ? "empty-name" : undefined, children: [_jsx("span", { children: instanceName || defaultName }), " ", id && (_jsx("span", { class: "id", "aria-hidden": true, children: id }))] }), id && (_jsx("button", { class: "destructive", onClick: () => {
|
|
100
|
+
if (confirm("Are you sure you want to delete this instance?")) {
|
|
101
|
+
deleteInstanceByEntityNameAndId(locales, entity.name, id)
|
|
102
|
+
.then(() => {
|
|
103
|
+
route(`/entities/${name}`);
|
|
104
|
+
})
|
|
105
|
+
.catch((error) => {
|
|
106
|
+
if (error instanceof Error) {
|
|
107
|
+
alert("Error deleting instance:\n\n" + error.toString());
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}, children: "Delete" }))] }), !id && isLocaleEntity && (_jsxs("div", { class: "field field--id", children: [_jsx("label", { htmlFor: "id", children: "ID" }), _jsx("p", { className: "comment", children: "The instance\u2019s identifier. An IETF language tag (BCP47)." }), _jsx("input", { type: "text", id: "id", value: customId, required: true, pattern: "[a-z]{2,3}(-[A-Z]{2,3})?", placeholder: "en-US, de-DE, \u2026", onInput: event => {
|
|
112
|
+
setCustomId(event.currentTarget.value);
|
|
113
|
+
}, "aria-invalid": idErrors.length > 0 }), _jsx(ValidationErrors, { errors: idErrors })] })), _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TypeInput, { type: entity.type, value: instanceContent, path: undefined, instanceNamesByEntity: instanceNamesByEntity, childInstances: childInstances, getDeclFromDeclName: getDeclFromDeclName, onChange: setInstanceContent, onChildChange: handleOnChildChange, onChildAdd: handleOnChildAdd, onChildRemove: handleOnChildRemove }), _jsx("div", { class: "form-footer btns", children: _jsx("button", { type: "submit", name: "save", class: "primary", children: "Save" }) })] })] }));
|
|
114
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
+
import { Settings } from "./Settings.js";
|
|
2
3
|
export const Layout = ({ breadcrumbs, children }) => {
|
|
3
|
-
return (_jsxs(_Fragment, { children: [
|
|
4
|
+
return (_jsxs(_Fragment, { children: [_jsxs("header", { children: [_jsx("nav", { children: _jsx("ol", { children: breadcrumbs.map(({ url, label }) => (_jsx("li", { children: _jsx("a", { href: url, children: label }) }, url))) }) }), _jsx(Settings, {})] }), _jsx("main", { children: children })] }));
|
|
4
5
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "preact/hooks";
|
|
3
|
+
export const ModalDialog = props => {
|
|
4
|
+
const ref = useRef(null);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (ref.current) {
|
|
7
|
+
if (props.open && !ref.current.open) {
|
|
8
|
+
ref.current.showModal();
|
|
9
|
+
}
|
|
10
|
+
else if (!props.open && ref.current.open) {
|
|
11
|
+
ref.current.close();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}, [props.open]);
|
|
15
|
+
return _jsx("dialog", { ...props, open: undefined, ref: ref });
|
|
16
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
+
import { useContext, useState } from "preact/hooks";
|
|
3
|
+
import { removeAt, reorder } from "../../shared/utils/array.js";
|
|
4
|
+
import { getLocaleInstances } from "../api/declarations.js";
|
|
5
|
+
import { ConfigContext } from "../context/config.js";
|
|
6
|
+
import { useMappedAPIResource } from "../hooks/useMappedAPIResource.js";
|
|
7
|
+
import { useSetting } from "../hooks/useSettings.js";
|
|
8
|
+
import { ModalDialog } from "./ModalDialog.js";
|
|
9
|
+
import { Select } from "./Select.js";
|
|
10
|
+
const localeMapper = (result) => result.instances;
|
|
11
|
+
export const Settings = () => {
|
|
12
|
+
const [locales, setLocales] = useSetting("displayedLocales");
|
|
13
|
+
const [enumDisplay, setEnumDisplay] = useSetting("enumDisplay");
|
|
14
|
+
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
|
15
|
+
const config = useContext(ConfigContext);
|
|
16
|
+
const [localeInstances] = useMappedAPIResource(getLocaleInstances, localeMapper, locales, config.localeEntityName);
|
|
17
|
+
const [newLocale, setNewLocale] = useState("");
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { class: "settings-toggle", onClick: () => {
|
|
19
|
+
setIsSettingsOpen(true);
|
|
20
|
+
}, children: "Settings" }), _jsxs(ModalDialog, { open: isSettingsOpen, class: "settings", closedBy: "any", onClose: () => {
|
|
21
|
+
setIsSettingsOpen(false);
|
|
22
|
+
}, children: [_jsxs("header", { children: [_jsx("h2", { children: "Settings" }), _jsx("button", { class: "close", onClick: () => {
|
|
23
|
+
setIsSettingsOpen(false);
|
|
24
|
+
}, children: "Close" })] }), _jsx("h3", { children: "Display Name Locales" }), _jsx("p", { class: "description", children: "Define the locales you want to see instances displayed in. Multiple locales can be specified as fallback locales. The instances will be grouped by the locale they are available in, in the order the locales are specified in." }), _jsxs("ol", { children: [locales.length === 0 && (_jsx("li", { class: "empty", "aria-hidden": true, children: "No locales selected" })), locales.map((locale, index) => (_jsx("li", { children: _jsxs("div", { class: "locale-content", children: [_jsx("span", { children: localeInstances?.find(instance => instance.id === locale)?.displayName ?? locale }), _jsx("button", { onClick: () => {
|
|
25
|
+
setLocales(locales => reorder(locales, index, index - 1));
|
|
26
|
+
}, disabled: index === 0, children: "Move Up" }), _jsx("button", { onClick: () => {
|
|
27
|
+
setLocales(locales => reorder(locales, index, index + 1));
|
|
28
|
+
}, disabled: index === locales.length - 1, children: "Move Down" }), _jsx("button", { onClick: () => {
|
|
29
|
+
setLocales(locales => removeAt(locales, index));
|
|
30
|
+
}, disabled: locales.length < 2, children: "Remove" })] }) }, locale)))] }), _jsxs("div", { class: "add-item-container", children: [_jsxs(Select, { value: newLocale, onInput: event => {
|
|
31
|
+
setNewLocale(event.currentTarget.value);
|
|
32
|
+
}, disabled: !localeInstances || localeInstances.length === 0, children: [_jsx("option", { value: "", disabled: true, children: !localeInstances || localeInstances.length === 0
|
|
33
|
+
? "No instances available"
|
|
34
|
+
: "No selected instance" }), localeInstances
|
|
35
|
+
?.filter(instance => !locales.includes(instance.id))
|
|
36
|
+
.map(instance => (_jsx("option", { value: instance.id, children: instance.displayName }, instance.id)))] }), _jsxs("button", { onClick: () => {
|
|
37
|
+
setLocales(locales => [...locales, newLocale]);
|
|
38
|
+
setNewLocale("");
|
|
39
|
+
}, disabled: newLocale === "", children: ["Add", " ", newLocale === ""
|
|
40
|
+
? "new locale"
|
|
41
|
+
: (localeInstances?.find(instance => instance.id === newLocale)?.displayName ??
|
|
42
|
+
newLocale)] })] }), _jsx("h3", { children: "Enum Display Mode" }), _jsx("p", { class: "description", children: "Choose how enumeration types are displayed." }), _jsxs("div", { className: "field--option", children: [_jsx("input", { type: "radio", name: "enum-display", id: "enum-display-select", value: "select", checked: enumDisplay === "select", onChange: () => {
|
|
43
|
+
setEnumDisplay("select");
|
|
44
|
+
} }), _jsx("label", { htmlFor: "enum-display-select", children: "Compact (Dropdowns)" })] }), _jsxs("div", { className: "field--option", children: [_jsx("input", { type: "radio", name: "enum-display", id: "enum-display-radio", value: "radio", checked: enumDisplay === "radio", onChange: () => {
|
|
45
|
+
setEnumDisplay("radio");
|
|
46
|
+
} }), _jsx("label", { htmlFor: "enum-display-radio", children: "Expanded (all nested form fields in radio lists)" })] })] })] }));
|
|
47
|
+
};
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import type { FunctionComponent } from "preact";
|
|
2
|
-
import type { SerializedArrayType } from "../../../
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
type: SerializedArrayType;
|
|
7
|
-
path: string | undefined;
|
|
8
|
-
value: unknown;
|
|
9
|
-
instanceNamesByEntity: InstanceNamesByEntity;
|
|
10
|
-
getDeclFromDeclName: GetDeclFromDeclName;
|
|
11
|
-
onChange: (value: unknown[]) => void;
|
|
12
|
-
};
|
|
2
|
+
import type { SerializedArrayType } from "../../../shared/schema/types/ArrayType.ts";
|
|
3
|
+
import { type TypeInputProps } from "./TypeInput.tsx";
|
|
4
|
+
type Props = TypeInputProps<SerializedArrayType, unknown[]>;
|
|
13
5
|
export declare const ArrayTypeInput: FunctionComponent<Props>;
|
|
14
6
|
export {};
|
|
@@ -5,17 +5,18 @@ import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
|
5
5
|
import { TypeInput } from "./TypeInput.js";
|
|
6
6
|
import { MismatchingTypeError } from "./utils/MismatchingTypeError.js";
|
|
7
7
|
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
8
|
-
export const ArrayTypeInput =
|
|
8
|
+
export const ArrayTypeInput = props => {
|
|
9
|
+
const { type, path, value, disabled, getDeclFromDeclName, onChange } = props;
|
|
9
10
|
if (!Array.isArray(value)) {
|
|
10
11
|
return _jsx(MismatchingTypeError, { expected: "array", actual: value });
|
|
11
12
|
}
|
|
12
13
|
const errors = validateArrayConstraints(type, value);
|
|
13
14
|
const isTuple = typeof type.minItems === "number" && type.minItems === type.maxItems;
|
|
14
|
-
return (_jsxs("div", { class: "field field--container field--array", children: [value.length > 0 && (_jsx("ol", { children: value.map((item, i) => (_jsxs("li", { class: "container-item array-item", children: [isTuple ? null : (_jsxs("div", { className: "container-item-header", children: [_jsxs("div", { className: "container-item-title", children: [i + 1, "."] }), _jsxs("button", { class: "destructive", onClick: () => {
|
|
15
|
+
return (_jsxs("div", { class: "field field--container field--array" + (disabled ? " field--disabled" : ""), children: [value.length > 0 && (_jsx("ol", { children: value.map((item, i) => (_jsxs("li", { class: "container-item array-item", children: [isTuple ? null : (_jsxs("div", { className: "container-item-header", children: [_jsxs("div", { className: "container-item-title", children: [i + 1, "."] }), _jsxs("button", { class: "destructive", onClick: () => {
|
|
15
16
|
onChange(removeAt(value, i));
|
|
16
|
-
}, disabled: type.minItems !== undefined && value.length <= type.minItems, children: ["Delete Item #", i + 1] })] })), _jsx(TypeInput, { type: type.items, path: path === undefined ? `[${i.toString()}]` : `${path}[${i.toString()}]`, value: item,
|
|
17
|
+
}, disabled: disabled || (type.minItems !== undefined && value.length <= type.minItems), children: ["Delete Item #", i + 1] })] })), _jsx(TypeInput, { ...props, parentKey: undefined, type: type.items, path: path === undefined ? `[${i.toString()}]` : `${path}[${i.toString()}]`, value: item, onChange: newItem => {
|
|
17
18
|
onChange(value.with(i, newItem));
|
|
18
19
|
} })] }, i))) })), isTuple ? null : (_jsx("div", { class: "add-item-container", children: _jsxs("button", { onClick: () => {
|
|
19
20
|
onChange([...value, createTypeSkeleton(getDeclFromDeclName, type.items)]);
|
|
20
|
-
}, disabled: type.maxItems !== undefined && value.length >= type.maxItems, children: ["Add Item #", value.length + 1] }) })), _jsx(ValidationErrors, { errors: errors })] }));
|
|
21
|
+
}, disabled: disabled || (type.maxItems !== undefined && value.length >= type.maxItems), children: ["Add Item #", value.length + 1] }) })), _jsx(ValidationErrors, { disabled: disabled, errors: errors })] }));
|
|
21
22
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { FunctionComponent } from "preact";
|
|
2
|
-
import type { SerializedBooleanType } from "../../../
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
value: unknown;
|
|
6
|
-
onChange: (value: boolean) => void;
|
|
7
|
-
};
|
|
2
|
+
import type { SerializedBooleanType } from "../../../shared/schema/types/BooleanType.ts";
|
|
3
|
+
import type { TypeInputProps } from "./TypeInput.tsx";
|
|
4
|
+
type Props = TypeInputProps<SerializedBooleanType, boolean>;
|
|
8
5
|
export declare const BooleanTypeInput: FunctionComponent<Props>;
|
|
9
6
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { MismatchingTypeError } from "./utils/MismatchingTypeError.js";
|
|
3
|
-
export const BooleanTypeInput = ({ value, onChange }) => {
|
|
3
|
+
export const BooleanTypeInput = ({ value, disabled, onChange }) => {
|
|
4
4
|
if (typeof value !== "boolean") {
|
|
5
5
|
return _jsx(MismatchingTypeError, { expected: "boolean", actual: value });
|
|
6
6
|
}
|
|
7
7
|
return (_jsx("div", { class: "field", children: _jsx("input", { type: "checkbox", checked: value, onInput: event => {
|
|
8
8
|
onChange(event.currentTarget.checked);
|
|
9
|
-
} }) }));
|
|
9
|
+
}, disabled: disabled }) }));
|
|
10
10
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedChildEntitiesType } from "../../../shared/schema/types/ChildEntitiesType.ts";
|
|
3
|
+
import { type TypeInputProps } from "./TypeInput.tsx";
|
|
4
|
+
type Props = TypeInputProps<SerializedChildEntitiesType>;
|
|
5
|
+
export declare const ChildEntitiesTypeInput: FunctionComponent<Props>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { isSerializedEntityDecl } from "../../../shared/schema/declarations/EntityDecl.js";
|
|
3
|
+
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
4
|
+
import { TypeInput } from "./TypeInput.js";
|
|
5
|
+
export const ChildEntitiesTypeInput = props => {
|
|
6
|
+
const { type, path, childInstances, disabled, getDeclFromDeclName, onChildAdd, onChildChange, onChildRemove, } = props;
|
|
7
|
+
const childEntity = getDeclFromDeclName(type.entity);
|
|
8
|
+
const childInstancesForEntity = childInstances
|
|
9
|
+
.map((childInstance, index) => [
|
|
10
|
+
childInstance,
|
|
11
|
+
index,
|
|
12
|
+
])
|
|
13
|
+
.filter(([childInstance]) => childInstance.entityName === type.entity);
|
|
14
|
+
if (childEntity === undefined || !isSerializedEntityDecl(childEntity)) {
|
|
15
|
+
return (_jsxs("div", { role: "alert", children: ["Unresolved entity declaration identifier ", _jsx("code", { children: type.entity })] }));
|
|
16
|
+
}
|
|
17
|
+
if (path === undefined) {
|
|
18
|
+
return _jsx("div", { role: "alert", children: "A child entities type cannot be the root type of a document." });
|
|
19
|
+
}
|
|
20
|
+
return (_jsxs("div", { class: "field field--container field--array", children: [childInstancesForEntity.length > 0 ? (_jsx("ol", { children: childInstancesForEntity.map(([item, originalIndex], i) => (_jsxs("li", { class: "container-item array-item", children: [_jsxs("div", { className: "container-item-header", children: [_jsxs("div", { className: "container-item-title", children: [i + 1, "."] }), _jsx("button", { class: "destructive", onClick: () => {
|
|
21
|
+
onChildRemove(i);
|
|
22
|
+
}, disabled: disabled, children: "Delete Item" })] }), _jsx(TypeInput, { ...props, type: childEntity.type, value: item.content, parentKey: childEntity.parentReferenceKey, onChange: newItem => {
|
|
23
|
+
onChildChange(originalIndex, newItem);
|
|
24
|
+
} })] }, i))) })) : (_jsx("p", { class: "empty", children: "No child entities" })), _jsx("div", { class: "add-item-container", children: _jsx("button", { onClick: () => {
|
|
25
|
+
onChildAdd(type.entity, createTypeSkeleton(getDeclFromDeclName, childEntity.type));
|
|
26
|
+
}, disabled: disabled, children: "Add Item" }) })] }));
|
|
27
|
+
};
|