Skip to content

Commit 7b80193

Browse files
committed
feat: finish upgrading page
1 parent cdefce5 commit 7b80193

21 files changed

+441
-119
lines changed

docs/.vitepress/config.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {exampleAutoAnchorPreprocessor} from "./theme/anchor/exampleAutoAnchorPre
1010
import {mathjaxContainerPreprocessor} from "./theme/mathjax/mathjaxContainerPreprocessor";
1111
import {withMermaid} from "vitepress-plugin-mermaid";
1212
import {mermaidSpaceConverter} from "./theme/mermaid/mermaidSpaceConverter";
13-
import {injectUpgradePartsPlugin} from "./theme/upgrade/injectUpgradePartsPlugin";
13+
import {injectUpgradingPartsPlugin} from "./theme/upgrading/injectUpgradingPartsPlugin";
1414

1515
const defaultLocale: string = 'en';
1616
const supportLocales: string[] = [
@@ -109,7 +109,7 @@ const vitepressOptions: UserConfig = {
109109
},
110110
config: (md) => {
111111
tabsPlugin(md);
112-
injectUpgradePartsPlugin(md);
112+
injectUpgradingPartsPlugin(md);
113113
mermaidSpaceConverter(md);
114114
exampleAutoAnchorPreprocessor(md);
115115
mathjaxContainerPreprocessor(md);

docs/.vitepress/theme/upgrade/injectUpgradePartsPlugin.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/.vitepress/theme/upgrade/upgrade.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/.vitepress/theme/upgrade/DoNotToDoAnythingTip.vue renamed to docs/.vitepress/theme/upgrading/DoNotToDoAnythingTip.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup>
22
3-
import {nowChanges, nowUpgradeInfo} from "./upgrade";
3+
import {nowChanges, nowUpgradingInfo} from "./upgrading";
44
</script>
55

66
<template>
77
<div style="text-align: center" v-if="nowChanges.length === 0 ">
8-
<b>Congratulations!<br/>You do not need to do anything to upgrade from {{nowUpgradeInfo.from}} to {{nowUpgradeInfo.to}}</b>
8+
<b>Congratulations!<br/>You do not need to do anything to upgrading from {{ nowUpgradingInfo.from }} to {{ nowUpgradingInfo.to }}</b>
99
</div>
1010
</template>
1111

docs/.vitepress/theme/upgrade/UpgradeHelper.vue renamed to docs/.vitepress/theme/upgrading/UpgradingHelper.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup lang="ts">
22
33
import {onMounted, onUnmounted, ref, watch} from "vue";
4-
import {getChanges, getVersionsAfter, getVersionsBefore, keyVersions, nowChanges, nowUpgradeInfo} from "./upgrade";
4+
import {getChanges, getVersionsAfter, getVersionsBefore, keyVersions, nowChanges, nowUpgradingInfo} from "./upgrading";
55
66
const fromOptions = ref([]);
77
const toOptions = ref([]);
8-
const nowFrom = ref(nowUpgradeInfo.value.from);
9-
const nowTo = ref(nowUpgradeInfo.value.to);
8+
const nowFrom = ref(nowUpgradingInfo.value.from);
9+
const nowTo = ref(nowUpgradingInfo.value.to);
1010
const isFromDropdownOpen = ref(false);
1111
const isToDropdownOpen = ref(false);
1212
@@ -52,16 +52,16 @@ function selectTo(version: string) {
5252
}
5353
5454
function update() {
55-
nowUpgradeInfo.value = {
55+
nowUpgradingInfo.value = {
5656
from: nowFrom.value,
5757
to: nowTo.value
5858
};
59-
window.location.hash = `#${nowUpgradeInfo.value.from}-${nowUpgradeInfo.value.to}`;
60-
fromOptions.value = getVersionsBefore(nowUpgradeInfo.value.to);
61-
toOptions.value = getVersionsAfter(nowUpgradeInfo.value.from);
62-
nowChanges.value = getChanges(nowUpgradeInfo.value);
59+
window.location.hash = `#${nowUpgradingInfo.value.from}-${nowUpgradingInfo.value.to}`;
60+
fromOptions.value = getVersionsBefore(nowUpgradingInfo.value.to);
61+
toOptions.value = getVersionsAfter(nowUpgradingInfo.value.from);
62+
nowChanges.value = getChanges(nowUpgradingInfo.value);
6363
const changes = nowChanges.value.map(change => `${change.from}-to-${change.to}`);
64-
document.querySelectorAll('.upgrade-parts-container div').forEach(ele => {
64+
document.querySelectorAll('.upgrading-parts-container div').forEach(ele => {
6565
if (changes.includes(ele.id)) {
6666
ele.classList.add('show');
6767
} else {
@@ -129,15 +129,19 @@ function reload() {
129129
130130
.dropdown-content {
131131
opacity: 0;
132-
overflow: hidden;
132+
overflow-x: hidden;
133+
-ms-overflow-x: hidden;
134+
overflow-y: auto;
135+
-ms-overflow-y: auto;
133136
display: block;
134137
position: absolute;
135138
background-color: var(--vp-c-bg-elv);
136139
border-radius: 4px;
137140
border: 1px solid var(--vp-c-divider);
138141
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
139-
z-index: 1;
142+
z-index: 5;
140143
transition: opacity 0.25s;
144+
max-height: 32vh;
141145
}
142146
143147
.dropdown-content a {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import MarkdownIt from "markdown-it";
2+
import {upgradingInfos} from "./upgrading";
3+
import fs from "fs";
4+
5+
export const injectUpgradingPartsPlugin = (md: MarkdownIt) => {
6+
md.core.ruler.before('normalize', 'generate-upgrading-page', (state) => {
7+
const INJECT_UPGRADING_PARTS = '<div class="upgrading-parts-container"></div>';
8+
if (!state.src.includes(INJECT_UPGRADING_PARTS)) {
9+
return;
10+
}
11+
state.src = `<div class="upgrading-parts-container">
12+
${state.src.replace(INJECT_UPGRADING_PARTS, upgradingInfos
13+
.map(info => {
14+
const targetPartFile = `./docs/en/upgrading-parts/${info.from}-to-${info.to}.md`;
15+
const targetPartContent = fs.readFileSync(targetPartFile, 'utf-8');
16+
return `
17+
<div id="${info.from}-to-${info.to}" class="default-hide">
18+
19+
<h2 style="font-family: 'Helvetica Neue', sans-serif;">${info.from}${info.to}</h2>
20+
21+
${targetPartContent}
22+
23+
</div>
24+
25+
`
26+
}).join('\n'))}
27+
</div>`;
28+
});
29+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {ref, Ref} from "vue";
2+
3+
class UpgradingInfo {
4+
from: string
5+
to: string
6+
}
7+
8+
export const upgradingInfos: UpgradingInfo[] = [
9+
{from: '6.5.2', to: '7.0.0'},
10+
{from: '7.0.0', to: '8.0.0'},
11+
{from: '8.0.0', to: '8.1.0'},
12+
{from: '8.3.1', to: '8.4.0'},
13+
{from: '8.5.0', to: '8.5.1'},
14+
{from: '8.5.1', to: '8.6.0'},
15+
{from: '8.6.0', to: '8.7.0'},
16+
{from: '8.8.0', to: '9.0.0'},
17+
{from: '9.0.0', to: '9.0.1'},
18+
{from: '9.0.1', to: '9.0.2'},
19+
{from: '9.0.3', to: '9.1.0'},
20+
{from: '9.2.0', to: '9.3.0'},
21+
]
22+
23+
export const keyVersions = Array.from(new Set(upgradingInfos.map(info => [info.from, info.to]).flat()));
24+
25+
export function getVersionsBefore(version: string) {
26+
const index = keyVersions.indexOf(version)
27+
if (index === -1) {
28+
return []
29+
}
30+
return keyVersions.slice(0, index)
31+
}
32+
33+
export function getVersionsAfter(version: string) {
34+
const index = keyVersions.indexOf(version)
35+
if (index === -1) {
36+
return []
37+
}
38+
return keyVersions.slice(index + 1)
39+
}
40+
41+
export function getDefaultUpgradingInfo() {
42+
return upgradingInfos[upgradingInfos.length - 1]
43+
}
44+
45+
export function getChanges(info: UpgradingInfo) {
46+
const result = [];
47+
let put = false;
48+
upgradingInfos.forEach(upgradingInfo => {
49+
if (info.from === upgradingInfo.from) {
50+
put = info.from !== upgradingInfo.from || info.to !== upgradingInfo.to;
51+
result.push(upgradingInfo);
52+
} else if (info.from === upgradingInfo.to) {
53+
put = true;
54+
} else if (info.to === upgradingInfo.from) {
55+
put = false;
56+
} else if (info.to === upgradingInfo.to) {
57+
put = false;
58+
result.push(upgradingInfo);
59+
} else if (put) {
60+
result.push(upgradingInfo);
61+
}
62+
});
63+
return result;
64+
}
65+
66+
export const nowUpgradingInfo: Ref<UpgradingInfo> = ref(getDefaultUpgradingInfo());
67+
export const nowChanges: Ref<UpgradingInfo[]> = ref([]);

docs/en/upgrade-parts/8.6.0-to-8.7.0.md

Whitespace-only changes.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
### Maven repository
2+
3+
The Maven repository used to serve the CommandAPI has changed from JitPack.io to Maven Central. For Maven projects, you no longer require wan explicit `<repository>` entry for the CommandAPI. for Gradle projects, you need to ensure `mavenCentral()` in present in your `repositories` section.
4+
5+
**The group ID has changed from `dev.jorel.CommandAPI` to `dev.jorel`**
6+
7+
More information about setting up your development environment can be found in [Setting up your development environment](../dev-setup/setup).
8+
9+
### CommandAPI command failures
10+
11+
The `CommandAPI.fail()` no longer automatically throws the exception that it creates, and instead now requires you to manually throw the exception yourself. This improves upon invalid states in command executors and allows invalid states to be identified more easily at compile time. To update, simply add the `throw` keyword before you call `CommandAPI.fail()`:
12+
13+
```java
14+
new CommandAPICommand("mycommand")
15+
.executes((sender, args) -> {
16+
if(!sender.hasPermission("some.permission")) {
17+
CommandAPI.fail("You don't have permission to run /mycommand!"); // [!code --]
18+
return; // [!code --]
19+
throw CommandAPI.fail("You don't have permission to run /mycommand!"); // [!code ++]
20+
}
21+
sender.sendMessage("Hello!");
22+
})
23+
```
24+
25+
### Suggestions
26+
27+
Suggestions have been overhauled and no longer take in a `Function<SuggestionsInfo, String[]>` anymore. Instead, they now take in a `ArgumentSuggestions` object which represents argument suggestions (and whether they are executed asynchronously or have tooltips).
28+
29+
#### Normal (string) suggestions
30+
31+
These normal suggestions methods have been replaced with an `ArgumentSuggestions` parameter instead of a function:
32+
33+
```java
34+
Argument replaceSuggestions(Function<SuggestionInfo, String[]> suggestions); // [!code --]
35+
Argument includeSuggestions(Function<SuggestionInfo, String[]> suggestions); // [!code --]
36+
37+
Argument replaceSuggestions(ArgumentSuggestions suggestions); // [!code ++]
38+
Argument includeSuggestions(ArgumentSuggestions suggestions); // [!code ++]
39+
```
40+
41+
The same functionality can be reproduced by wrapping your existing functions in `ArgumentSuggestions.strings`:
42+
43+
```java
44+
List<Argument> arguments = new ArrayList<>();
45+
arguments.add(new StringArgument("world").replaceSuggestions(info -> // [!code --]
46+
arguments.add(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(info -> // [!code ++]
47+
new String[] {"northland", "eastland", "southland", "westland" }
48+
)));
49+
```
50+
51+
#### Normal (strings with tooltips) suggestions
52+
53+
The `...T()` methods have been replaced with the normal methods above, and can use the `ArgumentSuggestions.stringsWithTooltips` method:
54+
55+
```java
56+
Argument replaceSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions); // [!code --]
57+
Argument includeSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions); // [!code --]
58+
59+
Argument replaceSuggestions(ArgumentSuggestions suggestions); // [!code ++]
60+
Argument includeSuggestions(ArgumentSuggestions suggestions); // [!code ++]
61+
```
62+
63+
For example:
64+
65+
```java
66+
List<Argument> arguments = new ArrayList<>();
67+
arguments.add(new StringArgument("emote")
68+
.replaceSuggestionsT( info -> new IStringTooltip[] { // [!code --]
69+
.replaceSuggestions(ArgumentSuggestions.stringsWithTooltips(info -> new IStringTooltip[] { // [!code ++]
70+
StringTooltip.of("wave", "Waves at a player"),
71+
StringTooltip.of("hug", "Gives a player a hug"),
72+
StringTooltip.of("glare", "Gives a player the death glare")
73+
}
74+
))
75+
);
76+
```
77+
78+
#### Safe suggestions
79+
80+
Similar to above with normal suggestions, safe suggestions have been replaced with `replaceSafeSuggestions` and `includeSafeSuggestions` respectively:
81+
82+
```java
83+
Argument replaceWithSafeSuggestions(Function<SuggestionInfo, S[]> suggestions); // [!code --]
84+
Argument includeWithSafeSuggestions(Function<SuggestionInfo, S[]> suggestions); // [!code --]
85+
86+
Argument replaceSafeSuggestions(SafeSuggestions<T> suggestions); // [!code ++]
87+
Argument includeSafeSuggestions(SafeSuggestions<T> suggestions); // [!code ++]
88+
```
89+
90+
These can be used with the `SafeSuggestions.suggest` and `SafeSuggestions.tooltips` methods to wrap existing functions. For example:
91+
92+
```java
93+
List<Argument> arguments = new ArrayList<>();
94+
arguments.add(new RecipeArgument("recipe").replaceWithSafeSuggestions(info -> // [!code --]
95+
arguments.add(new RecipeArgument("recipe").replaceSafeSuggestions(SafeSuggestions.suggest(info -> // [!code ++]
96+
new Recipe[] { emeraldSwordRecipe, /* Other recipes here */ }
97+
)));
98+
```

0 commit comments

Comments
 (0)