@gradio/core 1.3.0 → 1.4.1
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/CHANGELOG.md +67 -0
- package/dist/src/Blocks.svelte +6 -17
- package/dist/src/MountComponents.svelte +11 -2
- package/dist/src/MountComponents.svelte.d.ts +1 -1
- package/dist/src/MountCustomComponent.svelte +38 -0
- package/dist/src/MountCustomComponent.svelte.d.ts +6 -0
- package/dist/src/init.svelte.d.ts +2 -1
- package/dist/src/init.svelte.js +44 -17
- package/dist/src/init.test.skip.d.ts +1 -0
- package/dist/src/init.test.skip.js +627 -0
- package/dist/src/init_utils.d.ts +4 -1
- package/dist/src/init_utils.js +1 -1
- package/dist/src/types.d.ts +2 -0
- package/dist/src/vite-env-override.d.ts +1 -0
- package/package.json +54 -54
- package/src/Blocks.svelte +6 -17
- package/src/MountComponents.svelte +11 -2
- package/src/MountCustomComponent.svelte +38 -0
- package/src/i18n.test.ts +28 -2
- package/src/init.svelte.ts +64 -27
- package/src/{init.test.ts → init.test.skip.ts} +304 -5
- package/src/init_utils.ts +2 -2
- package/src/types.ts +2 -1
- package/src/vite-env-override.d.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, test, expect, vi } from "vitest";
|
|
2
2
|
import { spy } from "tinyspy";
|
|
3
|
-
import {
|
|
3
|
+
import { setupWorker } from "msw/browser";
|
|
4
4
|
import { http, HttpResponse } from "msw";
|
|
5
5
|
import type { client_return } from "@gradio/client";
|
|
6
6
|
import { Dependency, TargetMap } from "./types";
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
process_server_fn,
|
|
12
12
|
get_component
|
|
13
13
|
} from "./_init";
|
|
14
|
+
import { get_api_url } from "./init.svelte";
|
|
15
|
+
import type { AppConfig } from "./types";
|
|
16
|
+
import { commands } from "@vitest/browser/context";
|
|
14
17
|
|
|
15
18
|
describe("process_frontend_fn", () => {
|
|
16
19
|
test("empty source code returns null", () => {
|
|
@@ -461,6 +464,8 @@ describe("get_component", () => {
|
|
|
461
464
|
value: "hi",
|
|
462
465
|
interactive: false
|
|
463
466
|
},
|
|
467
|
+
key: "test-component-one",
|
|
468
|
+
|
|
464
469
|
has_modes: false,
|
|
465
470
|
instance: {} as any,
|
|
466
471
|
component: {} as any
|
|
@@ -476,7 +481,7 @@ describe("get_component", () => {
|
|
|
476
481
|
);
|
|
477
482
|
});
|
|
478
483
|
|
|
479
|
-
test("if the component is not found then it should request the component from the server", async () => {
|
|
484
|
+
test.skip("if the component is not found then it should request the component from the server", async () => {
|
|
480
485
|
const api_url = "example.com";
|
|
481
486
|
const id = "test-random";
|
|
482
487
|
const variant = "component";
|
|
@@ -512,13 +517,307 @@ describe("get_component", () => {
|
|
|
512
517
|
}
|
|
513
518
|
);
|
|
514
519
|
|
|
515
|
-
const
|
|
516
|
-
|
|
520
|
+
const worker = setupWorker(...handlers);
|
|
521
|
+
worker.start();
|
|
517
522
|
|
|
518
523
|
await get_component("test-random", id, api_url, []).component;
|
|
519
524
|
|
|
520
525
|
expect(mock).toHaveBeenCalled();
|
|
521
526
|
|
|
522
|
-
|
|
527
|
+
worker.stop();
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
describe("get_api_url", () => {
|
|
532
|
+
describe("root URL with trailing slash", () => {
|
|
533
|
+
test("root with trailing slash, api_prefix with leading slash", () => {
|
|
534
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
535
|
+
root: "http://example.com/myapp/",
|
|
536
|
+
api_prefix: "/api",
|
|
537
|
+
theme: "default",
|
|
538
|
+
version: "1.0.0",
|
|
539
|
+
autoscroll: true
|
|
540
|
+
};
|
|
541
|
+
const result = get_api_url(config);
|
|
542
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
test("root with trailing slash, api_prefix without leading slash", () => {
|
|
546
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
547
|
+
root: "http://example.com/myapp/",
|
|
548
|
+
api_prefix: "api",
|
|
549
|
+
theme: "default",
|
|
550
|
+
version: "1.0.0",
|
|
551
|
+
autoscroll: true
|
|
552
|
+
};
|
|
553
|
+
const result = get_api_url(config);
|
|
554
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
test("root at domain root with trailing slash", () => {
|
|
558
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
559
|
+
root: "http://example.com/",
|
|
560
|
+
api_prefix: "/api",
|
|
561
|
+
theme: "default",
|
|
562
|
+
version: "1.0.0",
|
|
563
|
+
autoscroll: true
|
|
564
|
+
};
|
|
565
|
+
const result = get_api_url(config);
|
|
566
|
+
expect(result).toBe("http://example.com/api");
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
describe("root URL without trailing slash", () => {
|
|
571
|
+
test("root without trailing slash, api_prefix with leading slash", () => {
|
|
572
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
573
|
+
root: "http://example.com/myapp",
|
|
574
|
+
api_prefix: "/api",
|
|
575
|
+
theme: "default",
|
|
576
|
+
version: "1.0.0",
|
|
577
|
+
autoscroll: true
|
|
578
|
+
};
|
|
579
|
+
const result = get_api_url(config);
|
|
580
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test("root without trailing slash, api_prefix without leading slash", () => {
|
|
584
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
585
|
+
root: "http://example.com/myapp",
|
|
586
|
+
api_prefix: "api",
|
|
587
|
+
theme: "default",
|
|
588
|
+
version: "1.0.0",
|
|
589
|
+
autoscroll: true
|
|
590
|
+
};
|
|
591
|
+
const result = get_api_url(config);
|
|
592
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
test("root at domain root without trailing slash", () => {
|
|
596
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
597
|
+
root: "http://example.com",
|
|
598
|
+
api_prefix: "/api",
|
|
599
|
+
theme: "default",
|
|
600
|
+
version: "1.0.0",
|
|
601
|
+
autoscroll: true
|
|
602
|
+
};
|
|
603
|
+
const result = get_api_url(config);
|
|
604
|
+
expect(result).toBe("http://example.com/api");
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
describe("different root path combinations", () => {
|
|
609
|
+
test("root path is just '/'", () => {
|
|
610
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
611
|
+
root: "http://example.com/",
|
|
612
|
+
api_prefix: "/api",
|
|
613
|
+
theme: "default",
|
|
614
|
+
version: "1.0.0",
|
|
615
|
+
autoscroll: true
|
|
616
|
+
};
|
|
617
|
+
const result = get_api_url(config);
|
|
618
|
+
expect(result).toBe("http://example.com/api");
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
test("root path is '/' without trailing slash", () => {
|
|
622
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
623
|
+
root: "http://example.com",
|
|
624
|
+
api_prefix: "/api",
|
|
625
|
+
theme: "default",
|
|
626
|
+
version: "1.0.0",
|
|
627
|
+
autoscroll: true
|
|
628
|
+
};
|
|
629
|
+
const result = get_api_url(config);
|
|
630
|
+
expect(result).toBe("http://example.com/api");
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
test("root path is '/myapp'", () => {
|
|
634
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
635
|
+
root: "http://example.com/myapp",
|
|
636
|
+
api_prefix: "/api",
|
|
637
|
+
theme: "default",
|
|
638
|
+
version: "1.0.0",
|
|
639
|
+
autoscroll: true
|
|
640
|
+
};
|
|
641
|
+
const result = get_api_url(config);
|
|
642
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
test("root path is '/myapp/'", () => {
|
|
646
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
647
|
+
root: "http://example.com/myapp/",
|
|
648
|
+
api_prefix: "/api",
|
|
649
|
+
theme: "default",
|
|
650
|
+
version: "1.0.0",
|
|
651
|
+
autoscroll: true
|
|
652
|
+
};
|
|
653
|
+
const result = get_api_url(config);
|
|
654
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
test("root path is '/deep/nested/path'", () => {
|
|
658
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
659
|
+
root: "http://example.com/deep/nested/path",
|
|
660
|
+
api_prefix: "/api",
|
|
661
|
+
theme: "default",
|
|
662
|
+
version: "1.0.0",
|
|
663
|
+
autoscroll: true
|
|
664
|
+
};
|
|
665
|
+
const result = get_api_url(config);
|
|
666
|
+
expect(result).toBe("http://example.com/deep/nested/path/api");
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
test("root path is '/deep/nested/path/'", () => {
|
|
670
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
671
|
+
root: "http://example.com/deep/nested/path/",
|
|
672
|
+
api_prefix: "/api",
|
|
673
|
+
theme: "default",
|
|
674
|
+
version: "1.0.0",
|
|
675
|
+
autoscroll: true
|
|
676
|
+
};
|
|
677
|
+
const result = get_api_url(config);
|
|
678
|
+
expect(result).toBe("http://example.com/deep/nested/path/api");
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
describe("different api_prefix formats", () => {
|
|
683
|
+
test("api_prefix with leading slash", () => {
|
|
684
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
685
|
+
root: "http://example.com/myapp",
|
|
686
|
+
api_prefix: "/api",
|
|
687
|
+
theme: "default",
|
|
688
|
+
version: "1.0.0",
|
|
689
|
+
autoscroll: true
|
|
690
|
+
};
|
|
691
|
+
const result = get_api_url(config);
|
|
692
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
test("api_prefix without leading slash", () => {
|
|
696
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
697
|
+
root: "http://example.com/myapp",
|
|
698
|
+
api_prefix: "api",
|
|
699
|
+
theme: "default",
|
|
700
|
+
version: "1.0.0",
|
|
701
|
+
autoscroll: true
|
|
702
|
+
};
|
|
703
|
+
const result = get_api_url(config);
|
|
704
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
test("api_prefix with nested path and leading slash", () => {
|
|
708
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
709
|
+
root: "http://example.com/myapp",
|
|
710
|
+
api_prefix: "/api/v1",
|
|
711
|
+
theme: "default",
|
|
712
|
+
version: "1.0.0",
|
|
713
|
+
autoscroll: true
|
|
714
|
+
};
|
|
715
|
+
const result = get_api_url(config);
|
|
716
|
+
expect(result).toBe("http://example.com/myapp/api/v1");
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test("api_prefix with nested path without leading slash", () => {
|
|
720
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
721
|
+
root: "http://example.com/myapp",
|
|
722
|
+
api_prefix: "api/v1",
|
|
723
|
+
theme: "default",
|
|
724
|
+
version: "1.0.0",
|
|
725
|
+
autoscroll: true
|
|
726
|
+
};
|
|
727
|
+
const result = get_api_url(config);
|
|
728
|
+
expect(result).toBe("http://example.com/myapp/api/v1");
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
describe("edge cases", () => {
|
|
733
|
+
test("root with port number", () => {
|
|
734
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
735
|
+
root: "http://example.com:8080/myapp",
|
|
736
|
+
api_prefix: "/api",
|
|
737
|
+
theme: "default",
|
|
738
|
+
version: "1.0.0",
|
|
739
|
+
autoscroll: true
|
|
740
|
+
};
|
|
741
|
+
const result = get_api_url(config);
|
|
742
|
+
expect(result).toBe("http://example.com:8080/myapp/api");
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
test("root with HTTPS", () => {
|
|
746
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
747
|
+
root: "https://example.com/myapp",
|
|
748
|
+
api_prefix: "/api",
|
|
749
|
+
theme: "default",
|
|
750
|
+
version: "1.0.0",
|
|
751
|
+
autoscroll: true
|
|
752
|
+
};
|
|
753
|
+
const result = get_api_url(config);
|
|
754
|
+
expect(result).toBe("https://example.com/myapp/api");
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
test("root with query parameters (should be ignored)", () => {
|
|
758
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
759
|
+
root: "http://example.com/myapp?param=value",
|
|
760
|
+
api_prefix: "/api",
|
|
761
|
+
theme: "default",
|
|
762
|
+
version: "1.0.0",
|
|
763
|
+
autoscroll: true
|
|
764
|
+
};
|
|
765
|
+
const result = get_api_url(config);
|
|
766
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
test("root with hash (should be ignored)", () => {
|
|
770
|
+
const config: Omit<AppConfig, "api_url"> = {
|
|
771
|
+
root: "http://example.com/myapp#section",
|
|
772
|
+
api_prefix: "/api",
|
|
773
|
+
theme: "default",
|
|
774
|
+
version: "1.0.0",
|
|
775
|
+
autoscroll: true
|
|
776
|
+
};
|
|
777
|
+
const result = get_api_url(config);
|
|
778
|
+
expect(result).toBe("http://example.com/myapp/api");
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
describe("consistency checks", () => {
|
|
783
|
+
test("same result regardless of root trailing slash", () => {
|
|
784
|
+
const baseConfig = {
|
|
785
|
+
api_prefix: "/api",
|
|
786
|
+
theme: "default",
|
|
787
|
+
version: "1.0.0",
|
|
788
|
+
autoscroll: true
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
const config1: Omit<AppConfig, "api_url"> = {
|
|
792
|
+
...baseConfig,
|
|
793
|
+
root: "http://example.com/myapp"
|
|
794
|
+
};
|
|
795
|
+
const config2: Omit<AppConfig, "api_url"> = {
|
|
796
|
+
...baseConfig,
|
|
797
|
+
root: "http://example.com/myapp/"
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
expect(get_api_url(config1)).toBe(get_api_url(config2));
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
test("same result regardless of api_prefix leading slash", () => {
|
|
804
|
+
const baseConfig = {
|
|
805
|
+
root: "http://example.com/myapp",
|
|
806
|
+
theme: "default",
|
|
807
|
+
version: "1.0.0",
|
|
808
|
+
autoscroll: true
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const config1: Omit<AppConfig, "api_url"> = {
|
|
812
|
+
...baseConfig,
|
|
813
|
+
api_prefix: "/api"
|
|
814
|
+
};
|
|
815
|
+
const config2: Omit<AppConfig, "api_url"> = {
|
|
816
|
+
...baseConfig,
|
|
817
|
+
api_prefix: "api"
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
expect(get_api_url(config1)).toBe(get_api_url(config2));
|
|
821
|
+
});
|
|
523
822
|
});
|
|
524
823
|
});
|
package/src/init_utils.ts
CHANGED
|
@@ -13,7 +13,7 @@ export function get_component(
|
|
|
13
13
|
class_id: string,
|
|
14
14
|
root: string,
|
|
15
15
|
variant: "component" | "example" | "base" = "component"
|
|
16
|
-
): LoadingComponent {
|
|
16
|
+
): { component: LoadingComponent; runtime: false | typeof import("svelte") } {
|
|
17
17
|
if (type === "api") type = "state";
|
|
18
18
|
|
|
19
19
|
return load_component({
|
|
@@ -21,7 +21,7 @@ export function get_component(
|
|
|
21
21
|
name: type,
|
|
22
22
|
id: class_id,
|
|
23
23
|
variant
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
package/src/types.ts
CHANGED
|
@@ -26,9 +26,9 @@ export interface ProcessedComponentMeta {
|
|
|
26
26
|
id: number;
|
|
27
27
|
props: { shared_props: SharedProps; props: Record<string, unknown> };
|
|
28
28
|
component: Component | LoadingComponent | null;
|
|
29
|
+
runtime: false | typeof import("svelte");
|
|
29
30
|
documentation?: Documentation;
|
|
30
31
|
children: ProcessedComponentMeta[];
|
|
31
|
-
// parent?: ProcessedComponentMeta;
|
|
32
32
|
component_class_id: string; // ?;
|
|
33
33
|
key: string | number | null; // ?;
|
|
34
34
|
rendered_in?: number; // ?;
|
|
@@ -128,4 +128,5 @@ export interface AppConfig {
|
|
|
128
128
|
autoscroll: boolean;
|
|
129
129
|
api_prefix: string;
|
|
130
130
|
api_url: string;
|
|
131
|
+
fill_height?: boolean;
|
|
131
132
|
}
|