Skip to content

Commit

Permalink
fix: fix indexing for group entries, fix koishijs/koishi#1381
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 25, 2024
1 parent e53aeff commit f61fafd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Unit Test
run: yarn test:json
- name: Report Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/coverage-final.json
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"serve": "^13.0.4",
"shx": "^0.3.4",
"typescript": "^5.3.2",
"vitepress": "1.0.0-rc.32",
"yakumo": "^1.0.0-alpha.9",
"yakumo-esbuild": "^1.0.0-alpha.2",
"yakumo-tsc": "^1.0.0-alpha.2"
"vitepress": "1.0.0-rc.40",
"yakumo": "^1.0.0-beta.12",
"yakumo-esbuild": "^1.0.0-beta.5",
"yakumo-tsc": "^1.0.0-beta.3"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "schemastery",
"description": "Type driven schema validator",
"version": "3.14.4",
"version": "3.14.5",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ function property(data: any, key: keyof any, schema: Schema, options?: Schemaste

Schema.extend('array', (data, { inner, meta }, options) => {
if (!Array.isArray(data)) throw new TypeError(`expected array but got ${data}`)
while (data.length && isNullable(data[data.length - 1])) data.pop()
checkWithinRange(data.length, meta, 'array length', !isNullable(inner!.meta.default))
return [data.map((_, index) => property(data, index, inner!, options))]
})
Expand Down
4 changes: 2 additions & 2 deletions packages/form/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "schemastery-vue",
"description": "Type driven schema validator",
"version": "7.3.2",
"version": "7.3.3",
"main": "src/index.ts",
"files": [
"src"
Expand All @@ -23,6 +23,6 @@
"vue": "^3"
},
"dependencies": {
"schemastery": "^3.14.4"
"schemastery": "^3.14.5"
}
}
11 changes: 11 additions & 0 deletions packages/form/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ export function useEntries() {
const isMax = computed(() => entries.value.length >= props.schema.meta.max)
const isMin = computed(() => entries.value.length >= props.schema.meta.max)

const reindex = () => {
if (props.schema.type !== 'array') return
for (let i = 0; i < entries.value.length; i++) {
entries.value[i][0] = '' + i
}
}

return {
entries,
isMax,
Expand All @@ -173,6 +180,7 @@ export function useEntries() {
entries.value[index][1] = entries.value[index - 1][1]
entries.value[index - 1][1] = temp
}
reindex()
},
down(index: number) {
if (props.schema.type === 'dict') {
Expand All @@ -182,12 +190,15 @@ export function useEntries() {
entries.value[index][1] = entries.value[index + 1][1]
entries.value[index + 1][1] = temp
}
reindex()
},
del(index: number) {
entries.value.splice(index, 1)
reindex()
},
insert(index: number) {
entries.value.splice(index, 0, ['', null])
reindex()
},
}
}
Expand Down

0 comments on commit f61fafd

Please sign in to comment.