tsondb 0.7.7 → 0.7.8

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.
Files changed (49) hide show
  1. package/dist/src/node/server/api/git.js +156 -24
  2. package/dist/src/node/server/index.js +4 -0
  3. package/dist/src/node/utils/instanceOperations.d.ts +1 -1
  4. package/dist/src/node/utils/instanceOperations.js +2 -2
  5. package/dist/src/shared/api.d.ts +17 -1
  6. package/dist/src/shared/utils/git.d.ts +4 -0
  7. package/dist/src/shared/utils/git.js +6 -1
  8. package/dist/src/shared/utils/markdown.d.ts +36 -17
  9. package/dist/src/shared/utils/markdown.js +79 -23
  10. package/dist/src/shared/utils/object.d.ts +1 -0
  11. package/dist/src/shared/utils/object.js +1 -0
  12. package/dist/src/web/api/git.d.ts +5 -1
  13. package/dist/src/web/api/git.js +6 -2
  14. package/dist/src/web/components/ContextProviderWrapper.d.ts +7 -0
  15. package/dist/src/web/components/ContextProviderWrapper.js +5 -0
  16. package/dist/src/web/components/InstanceRouteSkeleton.d.ts +1 -0
  17. package/dist/src/web/components/InstanceRouteSkeleton.js +8 -4
  18. package/dist/src/web/components/LoadingOverlay.d.ts +1 -0
  19. package/dist/src/web/components/LoadingOverlay.js +3 -0
  20. package/dist/src/web/components/ModalDialog.js +4 -3
  21. package/dist/src/web/components/git/Git.js +47 -0
  22. package/dist/src/web/components/git/GitBranchManager.d.ts +7 -0
  23. package/dist/src/web/components/git/GitBranchManager.js +17 -0
  24. package/dist/src/web/components/git/GitFileList.d.ts +17 -0
  25. package/dist/src/web/components/git/GitFileList.js +11 -0
  26. package/dist/src/web/components/git/GitFileManager.d.ts +8 -0
  27. package/dist/src/web/components/git/GitFileManager.js +34 -0
  28. package/dist/src/web/components/git/GitStatusIndicator.d.ts +7 -0
  29. package/dist/src/web/components/git/GitStatusIndicator.js +6 -0
  30. package/dist/src/web/components/typeInputs/StringTypeInput.js +1 -1
  31. package/dist/src/web/context/entities.d.ts +6 -5
  32. package/dist/src/web/context/git.d.ts +2 -1
  33. package/dist/src/web/context/gitClient.d.ts +2 -0
  34. package/dist/src/web/context/gitClient.js +2 -0
  35. package/dist/src/web/hooks/useGitClient.d.ts +37 -0
  36. package/dist/src/web/hooks/useGitClient.js +313 -0
  37. package/dist/src/web/index.js +6 -2
  38. package/dist/src/web/routes/CreateInstance.js +2 -1
  39. package/dist/src/web/routes/Entity.js +10 -4
  40. package/dist/src/web/routes/Instance.js +2 -1
  41. package/dist/src/web/signals/loading.d.ts +2 -0
  42. package/dist/src/web/signals/loading.js +11 -0
  43. package/dist/src/web/utils/BlockMarkdown.js +1 -1
  44. package/dist/src/web/utils/debug.d.ts +1 -0
  45. package/dist/src/web/utils/debug.js +4 -0
  46. package/package.json +3 -3
  47. package/public/css/styles.css +132 -70
  48. package/dist/src/web/components/Git.js +0 -164
  49. /package/dist/src/web/components/{Git.d.ts → git/Git.d.ts} +0 -0
@@ -81,6 +81,7 @@
81
81
  --button-color-destructive: #fff;
82
82
  --button-color-destructive-hover: #fff;
83
83
  --button-color-disabled: hsl(260, 6%, 54%);
84
+ --disabled-color: #606164;
84
85
  --highlight-color: #f2d600;
85
86
  --highlight-background: #333300;
86
87
  --highlight-color-bold: rgb(236, 170, 105);
@@ -722,43 +723,43 @@ form > .field--container {
722
723
  color: var(--disabled-color);
723
724
  }
724
725
 
725
- .field--string .preview {
726
+ .preview {
726
727
  padding: 1rem;
727
728
  background: var(--markdown-background);
728
729
  flex: 1 1 0;
729
730
  }
730
731
 
731
- .field--string .preview p {
732
+ .preview p {
732
733
  margin: 0.5rem 0 0;
733
734
  }
734
735
 
735
- .field--string .preview > :first-child {
736
+ .preview > :first-child {
736
737
  margin-top: 0;
737
738
  }
738
739
 
739
- .field--string .preview > :last-child {
740
+ .preview > :last-child {
740
741
  margin-bottom: 0;
741
742
  }
742
743
 
743
- .field--string .preview table {
744
+ .preview table {
744
745
  border-collapse: collapse;
745
746
  margin: 0.5rem 0;
746
747
  }
747
748
 
748
- .field--string .preview table :is(th, td) {
749
+ .preview table :is(th, td) {
749
750
  vertical-align: top;
750
751
  padding: 0.25rem 0.5rem;
751
752
  }
752
753
 
753
- .field--string .preview table :is(th, td):first-child {
754
+ .preview table :is(th, td):first-child {
754
755
  padding-left: 0;
755
756
  }
756
757
 
757
- .field--string .preview table :is(th, td):last-child {
758
+ .preview table :is(th, td):last-child {
758
759
  padding-right: 0;
759
760
  }
760
761
 
761
- .field--string .preview table tbody tr {
762
+ .preview table tbody tr {
762
763
  border-top: 1px solid var(--tertiary-color);
763
764
  }
764
765
 
@@ -886,12 +887,7 @@ main:has(.form-footer) {
886
887
 
887
888
  aside.git {
888
889
  grid-area: aside;
889
- position: absolute;
890
- top: 5rem;
891
- right: 0;
892
- width: 30rem;
893
- max-width: calc(100% - 1.5rem);
894
- max-height: calc(100% - 6.5rem);
890
+ display: none;
895
891
  }
896
892
 
897
893
  aside.git h2 {
@@ -900,14 +896,10 @@ aside.git h2 {
900
896
 
901
897
  @media (min-width: 80rem) {
902
898
  aside.git {
899
+ display: block;
903
900
  width: 30rem;
904
901
  border-left: 1px solid var(--separator-color);
905
902
  padding-left: 1rem;
906
- top: unset;
907
- right: unset;
908
- position: static;
909
- max-height: none;
910
- max-width: none;
911
903
  }
912
904
 
913
905
  aside.git h2 {
@@ -919,103 +911,80 @@ aside.git h2 {
919
911
  }
920
912
  }
921
913
 
922
- aside.git h3 {
914
+ .git-files h3 {
923
915
  font-size: 1.25rem;
924
916
  margin: 0;
925
917
  }
926
918
 
927
- aside.git ul {
919
+ .git-files ul {
928
920
  list-style-type: " ";
929
921
  padding: 0;
930
922
  margin: 0;
931
923
  display: block;
932
924
  }
933
925
 
934
- aside.git .git-entity-list-item > .title {
935
- margin: 1rem 0 0.5rem;
936
- }
937
-
938
- aside.git .git-instance-list-item {
939
- display: flex;
940
- justify-content: space-between;
941
- margin: 0.25rem 0 0;
942
- gap: 0.25rem;
926
+ .git-files .git-entity-list-item > .title {
927
+ margin: 1.5rem 0 0.75rem;
943
928
  }
944
929
 
945
- aside.git li .title {
930
+ .git-files li .title {
946
931
  display: block;
947
932
  margin: 0.25rem 0;
948
933
  flex: 1 1 0;
949
934
  }
950
935
 
951
- aside.git li.git-entity-list-item > .title {
936
+ .git-files li.git-entity-list-item > .title {
952
937
  font-weight: 600;
953
938
  }
954
939
 
955
- aside.git li button {
940
+ .git-files li button {
956
941
  padding: 0 0.5rem;
957
942
  line-height: 1.75rem;
958
943
  height: 1.75rem;
959
944
  }
960
945
 
961
- aside.git .git-section-title {
946
+ .git-files .git-section-title {
962
947
  display: flex;
963
948
  justify-content: space-between;
964
949
  align-items: center;
965
950
  gap: 0.5rem;
966
- margin: 1rem 0 0.5rem;
951
+ margin: 2rem 0 1rem;
967
952
  }
968
953
 
969
- aside.git .git-section-title h2 {
954
+ .git-files .git-section-title h2 {
970
955
  margin: 0;
971
956
  }
972
957
 
973
- aside.git p.no-changes {
958
+ .git-files p.no-changes {
974
959
  color: var(--tertiary-color);
975
960
  margin: 0;
976
961
  }
977
962
 
978
- aside.git .commit,
979
- aside.git .sync,
980
- aside.git .branch {
981
- display: flex;
982
- gap: 0.5rem;
963
+ .git-branches ul {
964
+ padding: 0;
965
+ margin: 0;
983
966
  }
984
967
 
985
- aside.git .sync,
986
- aside.git .branch {
987
- margin-bottom: 1rem;
968
+ .git-branches ul li {
969
+ display: flex;
970
+ align-items: start;
971
+ margin-top: 0.5rem;
988
972
  }
989
973
 
990
- aside.git .commit input,
991
- aside.git .branch .select-wrapper {
974
+ .branch__full-name {
975
+ text-overflow: ellipsis;
976
+ overflow: hidden;
977
+ white-space: nowrap;
992
978
  flex: 1 1 0;
993
979
  }
994
980
 
995
- .git-overlay {
996
- display: none;
997
- position: absolute;
998
- right: 1.5rem;
999
- box-shadow: 0 0.5rem 2rem var(--shadow-color);
1000
- z-index: 1000;
1001
- padding: 1rem;
1002
- background: var(--background);
1003
- overflow-y: auto;
1004
- max-height: calc(90vh - 5rem);
1005
- }
1006
-
1007
- @media (min-width: 80rem) {
1008
- .git-overlay {
1009
- display: block;
1010
- position: static;
1011
- box-shadow: none;
1012
- padding: 0.5rem 0 0;
1013
- max-height: none;
1014
- }
981
+ .branch__origin {
982
+ color: var(--secondary-color);
1015
983
  }
1016
984
 
1017
- .git-overlay.git-overlay--open {
1018
- display: block;
985
+ .branch__current-indicator {
986
+ color: var(--secondary-color);
987
+ flex: none;
1019
988
  }
1020
989
 
1021
990
  dialog {
@@ -1026,14 +995,24 @@ dialog {
1026
995
  padding: 1.6rem 1.5rem;
1027
996
  max-height: calc(100% - 2rem);
1028
997
  max-width: calc(100% - 2rem);
998
+ overscroll-behavior: contain;
1029
999
  }
1030
1000
 
1031
1001
  dialog::backdrop {
1032
1002
  background: rgba(0, 0, 0, 0.5);
1003
+ transition: background 0.25s ease-in-out;
1004
+ }
1005
+
1006
+ dialog header {
1007
+ display: flex;
1008
+ align-items: center;
1009
+ gap: 0.5rem;
1010
+ margin-bottom: 1.6rem;
1033
1011
  }
1034
1012
 
1035
1013
  dialog header :is(h1, h2, h3, h4, h5, h6) {
1036
1014
  margin: 0;
1015
+ flex: 1 1 0;
1037
1016
  }
1038
1017
 
1039
1018
  dialog.settings {
@@ -1049,6 +1028,17 @@ dialog.settings section.locale-settings ol li:not(:first-child) {
1049
1028
  margin-top: 0.5rem;
1050
1029
  }
1051
1030
 
1031
+ dialog.git {
1032
+ max-width: min(calc(100% - 2rem), 36rem);
1033
+ width: 100%;
1034
+ }
1035
+
1036
+ @media (min-width: 80rem) {
1037
+ dialog.git header .git__tab--files {
1038
+ display: none;
1039
+ }
1040
+ }
1041
+
1052
1042
  .locale-content {
1053
1043
  display: flex;
1054
1044
  gap: 0.25rem;
@@ -1058,3 +1048,75 @@ dialog.settings section.locale-settings ol li:not(:first-child) {
1058
1048
  .locale-content span {
1059
1049
  flex: 1 1 0;
1060
1050
  }
1051
+
1052
+ .form-row {
1053
+ display: flex;
1054
+ gap: 0.5rem;
1055
+ flex-wrap: wrap;
1056
+ margin-block: 1rem;
1057
+ }
1058
+
1059
+ .form-row--sides {
1060
+ justify-content: space-between;
1061
+ }
1062
+
1063
+ .form-row--compact {
1064
+ gap: 0.25rem;
1065
+ margin-block: 0.5rem;
1066
+ }
1067
+
1068
+ .form-row__group {
1069
+ display: flex;
1070
+ gap: 0.5rem;
1071
+ }
1072
+
1073
+ .form-row--compact .form-row__group {
1074
+ gap: 0.25rem;
1075
+ }
1076
+
1077
+ .form-row__text {
1078
+ padding-block: 0.5rem;
1079
+ }
1080
+
1081
+ .form-row--compact .form-row__text {
1082
+ padding-block: 0.175rem;
1083
+ }
1084
+
1085
+ .form-row__fill {
1086
+ flex: 1 1 0;
1087
+ }
1088
+
1089
+ .form-row--compact button {
1090
+ padding: 0.175rem 0.5rem;
1091
+ height: 1.75rem;
1092
+ }
1093
+
1094
+ .loading-overlay {
1095
+ position: fixed;
1096
+ top: 0;
1097
+ left: 0;
1098
+ width: 100vw;
1099
+ height: 100vh;
1100
+ background: rgba(0, 0, 0, 0.5);
1101
+ color: white;
1102
+ display: flex;
1103
+ align-items: center;
1104
+ justify-content: center;
1105
+ font-size: 2rem;
1106
+ z-index: 1000;
1107
+ font-weight: 200;
1108
+ letter-spacing: 0.05em;
1109
+ transition: opacity 0.25s ease-in-out;
1110
+ opacity: 0;
1111
+ pointer-events: none;
1112
+ }
1113
+
1114
+ #app:not(:has(dialog[open])) > .loading-overlay--open,
1115
+ dialog[open] > .loading-overlay--open {
1116
+ opacity: 1;
1117
+ pointer-events: auto;
1118
+ }
1119
+
1120
+ dialog[open]:has(> .loading-overlay--open)::backdrop {
1121
+ background: rgba(0, 0, 0, 0.75);
1122
+ }
@@ -1,164 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useLocation } from "preact-iso";
3
- import { useCallback, useContext, useEffect, useState } from "preact/hooks";
4
- import { getGitStatusForDisplay, getLabelForGitStatus, isChangedInIndex, isChangedInWorkingDir, } from "../../shared/utils/git.js";
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 { GitContext } from "../context/git.js";
8
- import { useSetting } from "../hooks/useSettings.js";
9
- const filterFilesForDisplay = (predicate, entities, data) => Object.entries(data.instances)
10
- .map(([entityName, instances]) => [
11
- entityName,
12
- entities.find(entity => entity.name === entityName)?.namePlural ?? entityName,
13
- instances
14
- .filter(instance => instance.gitStatus !== undefined && predicate(instance.gitStatus))
15
- .sort((a, b) => a.displayName.localeCompare(b.displayName, undefined, { numeric: true })),
16
- ])
17
- .filter(([_1, _2, instances]) => instances.length > 0)
18
- .sort((a, b) => a[1].localeCompare(b[1]));
19
- const GitFileList = ({ filesByEntity, onFile, isIndex = false }) => filesByEntity.length === 0 ? (_jsx("p", { class: "no-changes", children: "No changes" })) : (_jsx("ul", { class: "git-entity-list", children: filesByEntity.map(([entityName, entityNamePlural, instances]) => (_jsxs("li", { class: "git-entity-list-item", children: [_jsx("span", { class: "title", children: entityNamePlural }), _jsx("ul", { class: "git-instance-list", children: instances.map(instance => {
20
- const gitStatusForDisplay = getGitStatusForDisplay(instance.gitStatus);
21
- 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: () => {
22
- onFile(entityName, instance);
23
- }, children: isIndex ? "Unstage" : "Stage" })] }, instance.id));
24
- }) })] }, entityName))) }));
25
- export const Git = () => {
26
- const [locales] = useSetting("displayedLocales");
27
- const [isOpen] = useContext(GitContext);
28
- const [commitsAhead, setCommitsAhead] = useState(0);
29
- const [commitsBehind, setCommitsBehind] = useState(0);
30
- const [commitMessage, setCommitMessage] = useState("");
31
- const [indexFiles, setIndexFiles] = useState([]);
32
- const [workingTreeFiles, setWorkingTreeFiles] = useState([]);
33
- const [entities, setEntities] = useState([]);
34
- const [allBranches, setAllBranches] = useState([]);
35
- const [currentBranch, setCurrentBranch] = useState("");
36
- const updateGitStatus = useCallback((localEntities) => Promise.all([getStatus(locales), getBranches(locales)]).then(([statusData, branchesData]) => {
37
- setIndexFiles(filterFilesForDisplay(isChangedInIndex, localEntities, statusData));
38
- setWorkingTreeFiles(filterFilesForDisplay(isChangedInWorkingDir, localEntities, statusData));
39
- setCommitsAhead(statusData.commitsAhead);
40
- setCommitsBehind(statusData.commitsBehind);
41
- setAllBranches(branchesData.allBranches);
42
- setCurrentBranch(branchesData.currentBranch);
43
- }), [locales]);
44
- const location = useLocation();
45
- useEffect(() => {
46
- getAllEntities(locales)
47
- .then(async (data) => {
48
- const entitiesFromServer = data.declarations.map(decl => decl.declaration);
49
- setEntities(entitiesFromServer);
50
- return updateGitStatus(entitiesFromServer);
51
- })
52
- .catch((error) => {
53
- if (error instanceof Error) {
54
- console.error("Error fetching entities:", error.toString());
55
- }
56
- });
57
- }, [location.path, locales, updateGitStatus]);
58
- const stage = (entityName, instance) => {
59
- stageFileOfEntity(locales, entityName, instance.id)
60
- .then(() => updateGitStatus(entities))
61
- .catch((error) => {
62
- if (error instanceof Error) {
63
- console.error("Error staging instance:", error.toString());
64
- }
65
- });
66
- };
67
- const stageAll = () => {
68
- stageAllFiles(locales)
69
- .then(() => updateGitStatus(entities))
70
- .catch((error) => {
71
- if (error instanceof Error) {
72
- console.error("Error staging all instances:", error.toString());
73
- }
74
- });
75
- };
76
- const unstage = (entityName, instance) => {
77
- unstageFileOfEntity(locales, entityName, instance.id)
78
- .then(() => updateGitStatus(entities))
79
- .catch((error) => {
80
- if (error instanceof Error) {
81
- console.error("Error unstaging instance:", error.toString());
82
- }
83
- });
84
- };
85
- const unstageAll = () => {
86
- unstageAllFiles(locales)
87
- .then(() => updateGitStatus(entities))
88
- .catch((error) => {
89
- if (error instanceof Error) {
90
- console.error("Error unstaging all instances:", error.toString());
91
- }
92
- });
93
- };
94
- const commit = () => {
95
- if (commitMessage.length > 0 &&
96
- indexFiles.length > 0 &&
97
- confirm("Do you want to commit all staged files?")) {
98
- commitStagedFiles(locales, commitMessage)
99
- .then(() => {
100
- setCommitMessage("");
101
- return updateGitStatus(entities);
102
- })
103
- .catch((error) => {
104
- if (error instanceof Error) {
105
- console.error("Error committing instances:", error.toString());
106
- }
107
- });
108
- }
109
- };
110
- const push = () => {
111
- pushCommits(locales)
112
- .then(() => {
113
- alert("Pushed commits successfully");
114
- return updateGitStatus(entities);
115
- })
116
- .catch((error) => {
117
- console.error("Error pushing commits:", error);
118
- });
119
- };
120
- const pull = () => {
121
- pullCommits(locales)
122
- .then(() => {
123
- alert("Pulled commits successfully");
124
- return updateGitStatus(entities);
125
- })
126
- .catch((error) => {
127
- console.error("Error pulling commits:", error);
128
- });
129
- };
130
- const onCreateBranch = () => {
131
- const newBranchName = prompt("Enter new branch name:");
132
- if (!newBranchName) {
133
- alert("Branch name cannot be empty");
134
- return;
135
- }
136
- if (allBranches.includes(newBranchName)) {
137
- alert("Branch name already exists");
138
- return;
139
- }
140
- createBranch(locales, newBranchName)
141
- .then(() => {
142
- return updateGitStatus(entities);
143
- })
144
- .catch((error) => {
145
- if (error instanceof Error) {
146
- alert("Error switching branch:" + error.toString());
147
- }
148
- });
149
- };
150
- const onSwitchBranch = (event) => {
151
- switchBranch(locales, event.currentTarget.value)
152
- .then(() => {
153
- return updateGitStatus(entities);
154
- })
155
- .catch((error) => {
156
- if (error instanceof Error) {
157
- alert("Error switching branch: " + error.toString());
158
- }
159
- });
160
- };
161
- return (_jsxs("aside", { class: "git", children: [_jsx("h2", { class: "h1-faded", children: "Version Control" }), _jsxs("div", { className: `git-overlay ${isOpen ? "git-overlay--open" : ""}`, children: [_jsxs("div", { class: "sync", children: [_jsxs("button", { onClick: push, children: ["Push", commitsAhead > 0 ? ` (${commitsAhead.toString()})` : ""] }), _jsxs("button", { onClick: pull, children: ["Pull", commitsBehind > 0 ? ` (${commitsBehind.toString()})` : ""] })] }), _jsxs("div", { className: "branch", children: [_jsx("div", { className: "select-wrapper", children: _jsx("select", { value: currentBranch, onInput: onSwitchBranch, children: allBranches.map(branch => (_jsx("option", { value: branch, children: branch }, branch))) }) }), _jsx("button", { onClick: onCreateBranch, children: "New branch" })] }), _jsxs("div", { class: "commit", children: [_jsx("input", { type: "text", value: commitMessage, onInput: event => {
162
- setCommitMessage(event.currentTarget.value);
163
- }, placeholder: "added X to instance Y, \u2026" }), _jsx("button", { onClick: commit, disabled: commitMessage.length === 0 || indexFiles.length === 0, children: "Commit" })] }), _jsxs("div", { className: "git-section-title", children: [_jsx("h3", { children: "Files to be committed" }), _jsx("button", { onClick: unstageAll, children: "Unstage all" })] }), _jsx(GitFileList, { filesByEntity: indexFiles, isIndex: true, onFile: unstage }), _jsxs("div", { className: "git-section-title", children: [_jsx("h3", { children: "Working tree changes" }), _jsx("button", { onClick: stageAll, children: "Stage all" })] }), _jsx(GitFileList, { filesByEntity: workingTreeFiles, onFile: stage })] })] }));
164
- };