Skip to content

Commit 0c7d09b

Browse files
committed
Merge branch 'main' into fix/content-parsing-improvement
2 parents f2a21d3 + 75f56ad commit 0c7d09b

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

src/app/src/components/shared/item/ItemCardForm.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@ const schema = computed(() => z.object({
6565
extension: z.enum([...CONTENT_EXTENSIONS, ...MEDIA_EXTENSIONS] as [string, ...string[]]).nullish(),
6666
prefix: z.preprocess(
6767
val => val === '' ? null : val,
68-
z.number().int().positive().nullish(),
68+
z.string()
69+
.regex(/^\d+$/, 'Prefix must be a string containing only digits')
70+
.refine(
71+
(prefix: string | null | undefined) => {
72+
if (prefix === null || prefix === undefined) {
73+
return true
74+
}
75+
76+
const num = Number(prefix)
77+
78+
return Number.isInteger(num) && num >= 0
79+
},
80+
'Prefix must be a non-negative integer',
81+
)
82+
.nullish(),
6983
),
7084
}).refine(() => {
7185
const siblings = props.parentItem.children?.filter(child => !child.hide) || []
@@ -87,7 +101,7 @@ const schema = computed(() => z.object({
87101
type Schema = {
88102
name: string
89103
extension: string | null | undefined
90-
prefix: number | null | undefined
104+
prefix: string | null | undefined
91105
}
92106
const state = reactive<Schema>({
93107
name: originalName.value,
@@ -267,11 +281,11 @@ async function onSubmit() {
267281
<span />
268282
</template>
269283
<UInput
270-
v-model.number="state.prefix"
271-
type="number"
284+
v-model="state.prefix"
285+
type="text"
286+
pattern="[0-9]*"
272287
variant="soft"
273288
placeholder=""
274-
min="1"
275289
class="h-5"
276290
size="xs"
277291
:disabled="isLoading"

src/app/src/types/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface TreeItem {
1010
name: string
1111
fsPath: string // unique identifier
1212
type: 'file' | 'directory' | 'root'
13-
prefix: number | null
13+
prefix: string | null
1414
status?: TreeStatus
1515
routePath?: string
1616
children?: TreeItem[]

src/app/src/utils/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ export const FILE_ICONS = {
5050
...AUDIO_EXTENSIONS.reduce((acc, ext) => ({ ...acc, [ext]: 'i-lucide-file-audio' }), {}),
5151
}
5252

53-
export function parseName(name: string): { name: string, prefix: number | null, extension: string | null } {
53+
export function parseName(name: string): { name: string, prefix: string | null, extension: string | null } {
5454
const prefixMatch = name.match(/^(\d+)\./)
5555
const extensionMatch = name.match(/\.(\w+)$/)
5656
return {
57-
prefix: prefixMatch ? Number.parseInt(prefixMatch[1], 10) : null,
57+
prefix: prefixMatch ? prefixMatch[1] : null,
5858
extension: extensionMatch ? extensionMatch[1] : null,
5959
name: name.replace(/^\d+\./, ''),
6060
}

src/app/test/mocks/tree.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@ export const tree: TreeItem[] = [
1212
name: 'getting-started',
1313
fsPath: '1.getting-started',
1414
type: 'directory',
15-
prefix: 1,
15+
prefix: '1',
1616
children: [
1717
{
1818
name: 'introduction',
1919
fsPath: '1.getting-started/2.introduction.md',
2020
type: 'file',
2121
routePath: '/getting-started/introduction',
22-
prefix: 2,
22+
prefix: '2',
2323
},
2424
{
2525
name: 'installation',
2626
fsPath: '1.getting-started/3.installation.md',
2727
type: 'file',
2828
routePath: '/getting-started/installation',
29-
prefix: 3,
29+
prefix: '3',
3030
},
3131
{
3232
name: 'advanced',
3333
fsPath: '1.getting-started/1.advanced',
3434
type: 'directory',
35-
prefix: 1,
35+
prefix: '1',
3636
children: [
3737
{
3838
name: 'studio',
3939
fsPath: '1.getting-started/1.advanced/1.studio.md',
4040
type: 'file',
4141
routePath: '/getting-started/installation/advanced/studio',
42-
prefix: 1,
42+
prefix: '1',
4343
},
4444
],
4545
},

src/app/test/unit/utils/tree.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ describe('buildTree of documents with one level of depth', () => {
2525
name: 'getting-started',
2626
fsPath: '1.getting-started',
2727
type: 'directory',
28-
prefix: 1,
28+
prefix: '1',
2929
children: [
3030
{
3131
name: 'introduction',
3232
fsPath: '1.getting-started/2.introduction.md',
3333
type: 'file',
3434
routePath: '/getting-started/introduction',
35-
prefix: 2,
35+
prefix: '2',
3636
},
3737
{
3838
name: 'installation',
3939
fsPath: '1.getting-started/3.installation.md',
4040
type: 'file',
4141
routePath: '/getting-started/installation',
42-
prefix: 3,
42+
prefix: '3',
4343
},
4444
],
4545
},
@@ -97,7 +97,7 @@ describe('buildTree of documents with one level of depth', () => {
9797
type: 'file',
9898
routePath: deletedDbItem.path,
9999
status: TreeStatus.Deleted,
100-
prefix: 2,
100+
prefix: '2',
101101
},
102102
],
103103
},
@@ -131,7 +131,7 @@ describe('buildTree of documents with one level of depth', () => {
131131
type: 'file',
132132
routePath: deletedDbItem.path,
133133
status: TreeStatus.Deleted,
134-
prefix: 3,
134+
prefix: '3',
135135
},
136136
],
137137
},
@@ -282,7 +282,7 @@ describe('buildTree of documents with one level of depth', () => {
282282
name: createdDbItem.path!.split('/').pop()!,
283283
type: 'file',
284284
status: TreeStatus.Renamed,
285-
prefix: 2,
285+
prefix: '2',
286286
},
287287
],
288288
},
@@ -296,27 +296,27 @@ describe('buildTree of documents with two levels of depth', () => {
296296
name: 'essentials',
297297
fsPath: '1.essentials',
298298
type: 'directory',
299-
prefix: 1,
299+
prefix: '1',
300300
children: [
301301
{
302302
name: 'configuration',
303303
fsPath: '1.essentials/2.configuration.md',
304304
type: 'file',
305305
routePath: '/essentials/configuration',
306-
prefix: 2,
306+
prefix: '2',
307307
},
308308
{
309309
name: 'nested',
310310
fsPath: '1.essentials/1.nested',
311311
type: 'directory',
312-
prefix: 1,
312+
prefix: '1',
313313
children: [
314314
{
315315
name: 'advanced',
316316
fsPath: '1.essentials/1.nested/2.advanced.md',
317317
type: 'file',
318318
routePath: '/essentials/nested/advanced',
319-
prefix: 2,
319+
prefix: '2',
320320
},
321321
],
322322
},
@@ -424,7 +424,7 @@ describe('buildTree of documents with two levels of depth', () => {
424424
routePath: deletedDbItem.path,
425425
type: 'file',
426426
status: TreeStatus.Deleted,
427-
prefix: 2,
427+
prefix: '2',
428428
},
429429
],
430430
},
@@ -452,21 +452,21 @@ describe('buildTree of documents with language prefixed', () => {
452452
name: 'getting-started',
453453
fsPath: 'en/1.getting-started',
454454
type: 'directory',
455-
prefix: 1,
455+
prefix: '1',
456456
children: [
457457
{
458458
name: 'introduction',
459459
fsPath: 'en/1.getting-started/2.introduction.md',
460460
type: 'file',
461461
routePath: '/en/getting-started/introduction',
462-
prefix: 2,
462+
prefix: '2',
463463
},
464464
{
465465
name: 'installation',
466466
fsPath: 'en/1.getting-started/3.installation.md',
467467
type: 'file',
468468
routePath: '/en/getting-started/installation',
469-
prefix: 3,
469+
prefix: '3',
470470
},
471471
],
472472
},

0 commit comments

Comments
 (0)