tera-system-ui 0.0.12 → 0.0.13
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/dist/components/brand-logo/BrandLogo.svelte +31 -31
- package/dist/components/button/Button.svelte +49 -49
- package/dist/components/combobox/Combobox.svelte +8 -8
- package/dist/components/command/command.scss +72 -72
- package/dist/components/command/components/Command.svelte +120 -120
- package/dist/components/command/components/CommandEmpty.svelte +30 -30
- package/dist/components/command/components/CommandGroup.svelte +110 -110
- package/dist/components/command/components/CommandInput.svelte +92 -92
- package/dist/components/command/components/CommandItem.svelte +110 -110
- package/dist/components/command/components/CommandList.svelte +56 -56
- package/dist/components/command/components/CommandLoading.svelte +28 -28
- package/dist/components/command/components/CommandSeparator.svelte +21 -21
- package/dist/components/dialog/Dialog.js +4 -4
- package/dist/components/dialog/Dialog.svelte +106 -106
- package/dist/components/dialog/dialog.scss +85 -81
- package/dist/components/header/Header.svelte +36 -36
- package/dist/components/header/header.scss +19 -19
- package/dist/components/icons/IconArrowBigRightFilled.svelte +10 -10
- package/dist/components/icons/IconBook.svelte +10 -10
- package/dist/components/icons/IconBookmarkPlus.svelte +10 -10
- package/dist/components/icons/IconCalculator.svelte +10 -10
- package/dist/components/icons/IconCheck.svelte +10 -10
- package/dist/components/icons/IconChevronDown.svelte +10 -10
- package/dist/components/icons/IconCopy.svelte +10 -10
- package/dist/components/icons/IconCopyCheckFilled.svelte +10 -10
- package/dist/components/icons/IconHamburger.svelte +10 -10
- package/dist/components/icons/IconLanguage.svelte +10 -10
- package/dist/components/icons/IconLoader2.svelte +10 -10
- package/dist/components/icons/IconMoon.svelte +10 -10
- package/dist/components/icons/IconPointFilled.svelte +10 -10
- package/dist/components/icons/IconSearch.svelte +10 -10
- package/dist/components/icons/IconSun.svelte +10 -10
- package/dist/components/icons/IconSwitchHorizontal.svelte +10 -10
- package/dist/components/icons/IconSwitchVertical.svelte +10 -10
- package/dist/components/icons/IconTransform.svelte +10 -10
- package/dist/components/icons/IconX.svelte +10 -10
- package/dist/components/input/Input.svelte +24 -24
- package/dist/components/language-picker-button/LanguagePickerButton.svelte +109 -109
- package/dist/components/light-dark-toggle/LightDarkToggle.svelte +36 -36
- package/dist/components/popover/Popover.svelte +136 -136
- package/dist/components/popover-responsive/PopoverResponsive.svelte +87 -87
- package/dist/components/side-navigation/SideNavigation.svelte +113 -113
- package/dist/components/side-navigation/SideNavigationItem.svelte +17 -17
- package/dist/components/side-navigation/SideNavigationLayout.svelte +19 -19
- package/dist/components/side-navigation/sidenav.scss +149 -149
- package/dist/components/tera-ui-context/TeraUiContext.svelte +28 -28
- package/dist/themes/scrollbar.scss +37 -37
- package/package.json +1 -1
- package/scripts/add-component-template.js +120 -120
- package/scripts/generate-ts-index.js +136 -136
- package/dist/paraglide/.prettierignore +0 -3
- package/dist/paraglide/messages/de.d.ts +0 -1
- package/dist/paraglide/messages/de.js +0 -18
- package/dist/paraglide/messages/en.d.ts +0 -1
- package/dist/paraglide/messages/en.js +0 -18
- package/dist/paraglide/messages/es.d.ts +0 -1
- package/dist/paraglide/messages/es.js +0 -18
- package/dist/paraglide/messages/fr.d.ts +0 -1
- package/dist/paraglide/messages/fr.js +0 -18
- package/dist/paraglide/messages/it.d.ts +0 -1
- package/dist/paraglide/messages/it.js +0 -18
- package/dist/paraglide/messages/pt.d.ts +0 -1
- package/dist/paraglide/messages/pt.js +0 -18
- package/dist/paraglide/messages/ru.d.ts +0 -1
- package/dist/paraglide/messages/ru.js +0 -18
- package/dist/paraglide/messages/vi.d.ts +0 -1
- package/dist/paraglide/messages/vi.js +0 -18
- package/dist/paraglide/messages.d.ts +0 -3
- package/dist/paraglide/messages.js +0 -38
- package/dist/paraglide/runtime.d.ts +0 -52
- package/dist/paraglide/runtime.js +0 -141
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
--sidebar-width: 0;
|
|
3
|
-
--sidebar-transition-duration: 0.2s;
|
|
4
|
-
--sidebar-main-margin-left: 0;
|
|
5
|
-
--sidebar-border-width: 0;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.side-nav_main-layout {
|
|
9
|
-
transition: padding-left var(--sidebar-transition-duration);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.side-nav_main-side-bar {
|
|
13
|
-
container-type: inline-size;
|
|
14
|
-
z-index: 50;
|
|
15
|
-
width: var(--sidebar-width);
|
|
16
|
-
overflow-x: hidden;
|
|
17
|
-
border-right: var(--sidebar-border-width) solid theme('colors.neutral.token.5');
|
|
18
|
-
height: 100dvh;
|
|
19
|
-
position: fixed;
|
|
20
|
-
top: 0;
|
|
21
|
-
left: 0;
|
|
22
|
-
bottom: 0;
|
|
23
|
-
|
|
24
|
-
transition: width var(--sidebar-transition-duration);
|
|
25
|
-
background: theme('colors.neutral.token.1');
|
|
26
|
-
|
|
27
|
-
ul {
|
|
28
|
-
width: var(--sidebar-width);
|
|
29
|
-
transition: width var(--sidebar-transition-duration);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.sm-hidden {
|
|
36
|
-
opacity: 0;
|
|
37
|
-
transition: opacity var(--sidebar-transition-duration);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@container (min-width: 3rem) {
|
|
41
|
-
.sm-hidden {
|
|
42
|
-
opacity: 1;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.side-nav_main-content {
|
|
47
|
-
margin-left: var(--sidebar-main-margin-left);
|
|
48
|
-
transition: margin-left var(--sidebar-transition-duration);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.side-nav_main-layout {
|
|
53
|
-
&[data-side-nav-state="expand"], &[data-side-nav-temporary-expand="true"] {
|
|
54
|
-
--sidebar-width: 16.5rem;
|
|
55
|
-
--sidebar-border-width: 1px;
|
|
56
|
-
.header-brand-logo {
|
|
57
|
-
display: none;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@media (min-width: theme('screens.md')) {
|
|
63
|
-
:root {
|
|
64
|
-
--sidebar-main-margin-left: 3rem;
|
|
65
|
-
--sidebar-border-width: 1px;
|
|
66
|
-
--sidebar-width: 3rem;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@media (min-width: theme('screens.xl')) {
|
|
71
|
-
:root {
|
|
72
|
-
--sidebar-main-margin-left: var(--sidebar-width);
|
|
73
|
-
--sidebar-width: 16.5rem;
|
|
74
|
-
}
|
|
75
|
-
.header-brand-logo {
|
|
76
|
-
display: none;
|
|
77
|
-
}
|
|
78
|
-
.side-nav_main-layout {
|
|
79
|
-
&[data-side-nav-state="compact"] {
|
|
80
|
-
--sidebar-main-margin-left: 3rem;
|
|
81
|
-
--sidebar-width: 3rem;
|
|
82
|
-
.header-brand-logo {
|
|
83
|
-
display: block;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
&[data-side-nav-temporary-expand="true"] {
|
|
88
|
-
--sidebar-width: 16.5rem;
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.side-nav_item {
|
|
96
|
-
color: theme('colors.neutral.token.13');
|
|
97
|
-
|
|
98
|
-
a {
|
|
99
|
-
display: flex;
|
|
100
|
-
gap: 0.5rem;
|
|
101
|
-
align-items: center;
|
|
102
|
-
width: 100%;
|
|
103
|
-
position: relative;
|
|
104
|
-
white-space: nowrap;
|
|
105
|
-
@apply px-3 py-3 font-semibold;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
svg {
|
|
109
|
-
&.icon {
|
|
110
|
-
min-width: 24px;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
&.selected a {
|
|
115
|
-
//background-color: theme('colors.neutral.token.11');
|
|
116
|
-
color: theme('colors.neutral.token.1');
|
|
117
|
-
//@apply rounded-full;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
&.selected {
|
|
121
|
-
a::after {
|
|
122
|
-
content: '';
|
|
123
|
-
position: absolute;
|
|
124
|
-
inset-inline: 0.25rem;
|
|
125
|
-
inset-block: 0.2rem;
|
|
126
|
-
background: theme('colors.neutral.token.11');
|
|
127
|
-
border-radius: theme('borderRadius.DEFAULT');
|
|
128
|
-
z-index: 0;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
//&.selected {
|
|
133
|
-
// a::after {
|
|
134
|
-
// content: '';
|
|
135
|
-
// position: absolute;
|
|
136
|
-
// left: 0;
|
|
137
|
-
// top: 0;
|
|
138
|
-
// bottom: 0;
|
|
139
|
-
// width: 4px;
|
|
140
|
-
// height: 100%;
|
|
141
|
-
// background: theme('colors.primary.token.4');
|
|
142
|
-
// border-radius: 4px 0 0 4px;
|
|
143
|
-
// }
|
|
144
|
-
//}
|
|
145
|
-
|
|
146
|
-
&:hover {
|
|
147
|
-
background-color: theme('colors.neutral.token.3');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
1
|
+
:root {
|
|
2
|
+
--sidebar-width: 0;
|
|
3
|
+
--sidebar-transition-duration: 0.2s;
|
|
4
|
+
--sidebar-main-margin-left: 0;
|
|
5
|
+
--sidebar-border-width: 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.side-nav_main-layout {
|
|
9
|
+
transition: padding-left var(--sidebar-transition-duration);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.side-nav_main-side-bar {
|
|
13
|
+
container-type: inline-size;
|
|
14
|
+
z-index: 50;
|
|
15
|
+
width: var(--sidebar-width);
|
|
16
|
+
overflow-x: hidden;
|
|
17
|
+
border-right: var(--sidebar-border-width) solid theme('colors.neutral.token.5');
|
|
18
|
+
height: 100dvh;
|
|
19
|
+
position: fixed;
|
|
20
|
+
top: 0;
|
|
21
|
+
left: 0;
|
|
22
|
+
bottom: 0;
|
|
23
|
+
|
|
24
|
+
transition: width var(--sidebar-transition-duration);
|
|
25
|
+
background: theme('colors.neutral.token.1');
|
|
26
|
+
|
|
27
|
+
ul {
|
|
28
|
+
width: var(--sidebar-width);
|
|
29
|
+
transition: width var(--sidebar-transition-duration);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
.sm-hidden {
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transition: opacity var(--sidebar-transition-duration);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@container (min-width: 3rem) {
|
|
41
|
+
.sm-hidden {
|
|
42
|
+
opacity: 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.side-nav_main-content {
|
|
47
|
+
margin-left: var(--sidebar-main-margin-left);
|
|
48
|
+
transition: margin-left var(--sidebar-transition-duration);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
.side-nav_main-layout {
|
|
53
|
+
&[data-side-nav-state="expand"], &[data-side-nav-temporary-expand="true"] {
|
|
54
|
+
--sidebar-width: 16.5rem;
|
|
55
|
+
--sidebar-border-width: 1px;
|
|
56
|
+
.header-brand-logo {
|
|
57
|
+
display: none;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@media (min-width: theme('screens.md')) {
|
|
63
|
+
:root {
|
|
64
|
+
--sidebar-main-margin-left: 3rem;
|
|
65
|
+
--sidebar-border-width: 1px;
|
|
66
|
+
--sidebar-width: 3rem;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@media (min-width: theme('screens.xl')) {
|
|
71
|
+
:root {
|
|
72
|
+
--sidebar-main-margin-left: var(--sidebar-width);
|
|
73
|
+
--sidebar-width: 16.5rem;
|
|
74
|
+
}
|
|
75
|
+
.header-brand-logo {
|
|
76
|
+
display: none;
|
|
77
|
+
}
|
|
78
|
+
.side-nav_main-layout {
|
|
79
|
+
&[data-side-nav-state="compact"] {
|
|
80
|
+
--sidebar-main-margin-left: 3rem;
|
|
81
|
+
--sidebar-width: 3rem;
|
|
82
|
+
.header-brand-logo {
|
|
83
|
+
display: block;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&[data-side-nav-temporary-expand="true"] {
|
|
88
|
+
--sidebar-width: 16.5rem;
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
.side-nav_item {
|
|
96
|
+
color: theme('colors.neutral.token.13');
|
|
97
|
+
|
|
98
|
+
a {
|
|
99
|
+
display: flex;
|
|
100
|
+
gap: 0.5rem;
|
|
101
|
+
align-items: center;
|
|
102
|
+
width: 100%;
|
|
103
|
+
position: relative;
|
|
104
|
+
white-space: nowrap;
|
|
105
|
+
@apply px-3 py-3 font-semibold;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
svg {
|
|
109
|
+
&.icon {
|
|
110
|
+
min-width: 24px;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
&.selected a {
|
|
115
|
+
//background-color: theme('colors.neutral.token.11');
|
|
116
|
+
color: theme('colors.neutral.token.1');
|
|
117
|
+
//@apply rounded-full;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&.selected {
|
|
121
|
+
a::after {
|
|
122
|
+
content: '';
|
|
123
|
+
position: absolute;
|
|
124
|
+
inset-inline: 0.25rem;
|
|
125
|
+
inset-block: 0.2rem;
|
|
126
|
+
background: theme('colors.neutral.token.11');
|
|
127
|
+
border-radius: theme('borderRadius.DEFAULT');
|
|
128
|
+
z-index: 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//&.selected {
|
|
133
|
+
// a::after {
|
|
134
|
+
// content: '';
|
|
135
|
+
// position: absolute;
|
|
136
|
+
// left: 0;
|
|
137
|
+
// top: 0;
|
|
138
|
+
// bottom: 0;
|
|
139
|
+
// width: 4px;
|
|
140
|
+
// height: 100%;
|
|
141
|
+
// background: theme('colors.primary.token.4');
|
|
142
|
+
// border-radius: 4px 0 0 4px;
|
|
143
|
+
// }
|
|
144
|
+
//}
|
|
145
|
+
|
|
146
|
+
&:hover {
|
|
147
|
+
background-color: theme('colors.neutral.token.3');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type TeraUiContextProps} from "./TeraUiContext";
|
|
3
|
-
import {setGlobalContext} from "./global-context";
|
|
4
|
-
import {setLanguageTag} from "../../paraglide/runtime";
|
|
5
|
-
import * as m from '../../paraglide/messages.js'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let {
|
|
9
|
-
children,
|
|
10
|
-
supportLanguages = ['en'],
|
|
11
|
-
language = 'en',
|
|
12
|
-
...props
|
|
13
|
-
}: TeraUiContextProps = $props();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setGlobalContext({
|
|
17
|
-
supportLanguages,
|
|
18
|
-
language,
|
|
19
|
-
...props
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
setLanguageTag(language)
|
|
23
|
-
console.log('setLanguageTag', language)
|
|
24
|
-
console.log('test translate', m.text_select_language())
|
|
25
|
-
|
|
26
|
-
</script>
|
|
27
|
-
|
|
28
|
-
{@render children()}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type TeraUiContextProps} from "./TeraUiContext";
|
|
3
|
+
import {setGlobalContext} from "./global-context";
|
|
4
|
+
import {setLanguageTag} from "../../paraglide/runtime";
|
|
5
|
+
import * as m from '../../paraglide/messages.js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
children,
|
|
10
|
+
supportLanguages = ['en'],
|
|
11
|
+
language = 'en',
|
|
12
|
+
...props
|
|
13
|
+
}: TeraUiContextProps = $props();
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
setGlobalContext({
|
|
17
|
+
supportLanguages,
|
|
18
|
+
language,
|
|
19
|
+
...props
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
setLanguageTag(language)
|
|
23
|
+
console.log('setLanguageTag', language)
|
|
24
|
+
console.log('test translate', m.text_select_language())
|
|
25
|
+
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
{@render children()}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/* Light mode scrollbar styles */
|
|
2
|
-
::-webkit-scrollbar {
|
|
3
|
-
width: 8px;
|
|
4
|
-
height: 8px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
::-webkit-scrollbar-track {
|
|
8
|
-
background: transparent; /* Transparent track */
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
::-webkit-scrollbar-thumb {
|
|
12
|
-
background-color: rgba(0, 0, 0, 0.2); /* Light mode: dark thumb */
|
|
13
|
-
border-radius: 10px;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
::-webkit-scrollbar-thumb:hover {
|
|
17
|
-
background-color: rgba(0, 0, 0, 0.4); /* Darker thumb on hover */
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/* Dark mode scrollbar styles */
|
|
21
|
-
.dark ::-webkit-scrollbar-thumb {
|
|
22
|
-
background-color: rgba(255, 255, 255, 0.2); /* Dark mode: light thumb */
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.dark ::-webkit-scrollbar-thumb:hover {
|
|
26
|
-
background-color: rgba(255, 255, 255, 0.4); /* Lighter thumb on hover */
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/* Firefox scrollbar styling */
|
|
30
|
-
* {
|
|
31
|
-
scrollbar-width: thin;
|
|
32
|
-
scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
html.dark, .dark * {
|
|
36
|
-
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
|
|
37
|
-
}
|
|
1
|
+
/* Light mode scrollbar styles */
|
|
2
|
+
::-webkit-scrollbar {
|
|
3
|
+
width: 8px;
|
|
4
|
+
height: 8px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
::-webkit-scrollbar-track {
|
|
8
|
+
background: transparent; /* Transparent track */
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
::-webkit-scrollbar-thumb {
|
|
12
|
+
background-color: rgba(0, 0, 0, 0.2); /* Light mode: dark thumb */
|
|
13
|
+
border-radius: 10px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
::-webkit-scrollbar-thumb:hover {
|
|
17
|
+
background-color: rgba(0, 0, 0, 0.4); /* Darker thumb on hover */
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Dark mode scrollbar styles */
|
|
21
|
+
.dark ::-webkit-scrollbar-thumb {
|
|
22
|
+
background-color: rgba(255, 255, 255, 0.2); /* Dark mode: light thumb */
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.dark ::-webkit-scrollbar-thumb:hover {
|
|
26
|
+
background-color: rgba(255, 255, 255, 0.4); /* Lighter thumb on hover */
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Firefox scrollbar styling */
|
|
30
|
+
* {
|
|
31
|
+
scrollbar-width: thin;
|
|
32
|
+
scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
html.dark, .dark * {
|
|
36
|
+
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
import path from "path";
|
|
6
|
-
// Get the component name from the command line arguments
|
|
7
|
-
const componentName = process.argv[3];
|
|
8
|
-
const command = process.argv[2];
|
|
9
|
-
|
|
10
|
-
if (!componentName) {
|
|
11
|
-
console.error("Please provide a component name: `npx tera-ui add component-name`");
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (command !== 'add') {
|
|
16
|
-
console.error(`Please provide a correct command: current command ${command}`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const PASCAL_CASE = 'PASCAL_CASE';
|
|
22
|
-
const KEBAB_CASE = 'KEBAB_CASE';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function convertCase(text, convertTo) {
|
|
26
|
-
const isPascalCase = /^[A-Z][a-z0-9]+([A-Z][a-z0-9]*)*$/.test(text);
|
|
27
|
-
const isKebabCase = /^[a-z]+(-[a-z0-9]+)*$/.test(text);
|
|
28
|
-
|
|
29
|
-
if ((convertTo === PASCAL_CASE && isPascalCase) ||
|
|
30
|
-
(convertTo === KEBAB_CASE && isKebabCase)) {
|
|
31
|
-
return text;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (convertTo === PASCAL_CASE) {
|
|
35
|
-
return text
|
|
36
|
-
.toLowerCase()
|
|
37
|
-
.replace(/(?:^|[-_])(.)/g, (_, char) => char.toUpperCase());
|
|
38
|
-
} else if (convertTo === KEBAB_CASE) {
|
|
39
|
-
return text
|
|
40
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
41
|
-
.toLowerCase();
|
|
42
|
-
} else {
|
|
43
|
-
throw new Error("Invalid 'convertTo' parameter. Use 'PASCAL_CASE' or 'KEBAB_CASE'.");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
function readFileContent(path) {
|
|
49
|
-
try {
|
|
50
|
-
const data = fs.readFileSync(path, 'utf8');
|
|
51
|
-
return data;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("Error reading file:", error.message);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const componentTemplateFolder = path.join(process.cwd(), 'scripts/file-template/component');
|
|
60
|
-
|
|
61
|
-
function getComponentSvelte(componentName) {
|
|
62
|
-
let template = readFileContent(componentTemplateFolder + '/Component.svelte')
|
|
63
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
64
|
-
return template.replaceAll('ComponentProps', componentNameCase + 'Props')
|
|
65
|
-
.replaceAll('"./Component"', `"./${componentNameCase}"`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getComponentTS(componentName) {
|
|
69
|
-
let template = readFileContent(componentTemplateFolder + '/Component.ts')
|
|
70
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
71
|
-
return template.replaceAll('Component', componentNameCase);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getIndexTS(componentName) {
|
|
75
|
-
let template = readFileContent(componentTemplateFolder + '/index.ts')
|
|
76
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
77
|
-
return template.replaceAll('Component', componentNameCase);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function getComponentStoriesSvelte(componentName) {
|
|
82
|
-
let template = readFileContent(componentTemplateFolder + '/Component.stories.svelte')
|
|
83
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
84
|
-
return template.replaceAll('ComponentName', componentNameCase)
|
|
85
|
-
.replaceAll('component-path', convertCase(componentName, KEBAB_CASE));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Define the component folder and files
|
|
90
|
-
const componentDir = path.join(process.cwd(), 'src', 'lib', 'components', convertCase(componentName, KEBAB_CASE));
|
|
91
|
-
const componentStoriesDir = path.join(process.cwd(), 'src', 'stories', convertCase(componentName, KEBAB_CASE));
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const files = {
|
|
95
|
-
[`${convertCase(componentName, PASCAL_CASE)}.svelte`]: getComponentSvelte(componentName),
|
|
96
|
-
[`${convertCase(componentName, PASCAL_CASE)}.ts`]: getComponentTS(componentName),
|
|
97
|
-
[`index.ts`]: getIndexTS(componentName),
|
|
98
|
-
[`${convertCase(componentName, PASCAL_CASE)}.stories.svelte`]: getComponentStoriesSvelte(componentName),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// Create the folder and files with template content
|
|
103
|
-
if (!fs.existsSync(componentDir)) {
|
|
104
|
-
fs.mkdirSync(componentDir);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!fs.existsSync(componentStoriesDir)) {
|
|
108
|
-
fs.mkdirSync(componentStoriesDir);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for (const [filename, content] of Object.entries(files)) {
|
|
113
|
-
const filePath = filename.includes('.stories.')
|
|
114
|
-
? path.join(componentStoriesDir, filename)
|
|
115
|
-
: path.join(componentDir, filename);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
console.log(`Component ${componentName} created successfully with 3 template files!`);
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
import path from "path";
|
|
6
|
+
// Get the component name from the command line arguments
|
|
7
|
+
const componentName = process.argv[3];
|
|
8
|
+
const command = process.argv[2];
|
|
9
|
+
|
|
10
|
+
if (!componentName) {
|
|
11
|
+
console.error("Please provide a component name: `npx tera-ui add component-name`");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (command !== 'add') {
|
|
16
|
+
console.error(`Please provide a correct command: current command ${command}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const PASCAL_CASE = 'PASCAL_CASE';
|
|
22
|
+
const KEBAB_CASE = 'KEBAB_CASE';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
function convertCase(text, convertTo) {
|
|
26
|
+
const isPascalCase = /^[A-Z][a-z0-9]+([A-Z][a-z0-9]*)*$/.test(text);
|
|
27
|
+
const isKebabCase = /^[a-z]+(-[a-z0-9]+)*$/.test(text);
|
|
28
|
+
|
|
29
|
+
if ((convertTo === PASCAL_CASE && isPascalCase) ||
|
|
30
|
+
(convertTo === KEBAB_CASE && isKebabCase)) {
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (convertTo === PASCAL_CASE) {
|
|
35
|
+
return text
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/(?:^|[-_])(.)/g, (_, char) => char.toUpperCase());
|
|
38
|
+
} else if (convertTo === KEBAB_CASE) {
|
|
39
|
+
return text
|
|
40
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
41
|
+
.toLowerCase();
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error("Invalid 'convertTo' parameter. Use 'PASCAL_CASE' or 'KEBAB_CASE'.");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
function readFileContent(path) {
|
|
49
|
+
try {
|
|
50
|
+
const data = fs.readFileSync(path, 'utf8');
|
|
51
|
+
return data;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error("Error reading file:", error.message);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const componentTemplateFolder = path.join(process.cwd(), 'scripts/file-template/component');
|
|
60
|
+
|
|
61
|
+
function getComponentSvelte(componentName) {
|
|
62
|
+
let template = readFileContent(componentTemplateFolder + '/Component.svelte')
|
|
63
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
64
|
+
return template.replaceAll('ComponentProps', componentNameCase + 'Props')
|
|
65
|
+
.replaceAll('"./Component"', `"./${componentNameCase}"`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getComponentTS(componentName) {
|
|
69
|
+
let template = readFileContent(componentTemplateFolder + '/Component.ts')
|
|
70
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
71
|
+
return template.replaceAll('Component', componentNameCase);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getIndexTS(componentName) {
|
|
75
|
+
let template = readFileContent(componentTemplateFolder + '/index.ts')
|
|
76
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
77
|
+
return template.replaceAll('Component', componentNameCase);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function getComponentStoriesSvelte(componentName) {
|
|
82
|
+
let template = readFileContent(componentTemplateFolder + '/Component.stories.svelte')
|
|
83
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
84
|
+
return template.replaceAll('ComponentName', componentNameCase)
|
|
85
|
+
.replaceAll('component-path', convertCase(componentName, KEBAB_CASE));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// Define the component folder and files
|
|
90
|
+
const componentDir = path.join(process.cwd(), 'src', 'lib', 'components', convertCase(componentName, KEBAB_CASE));
|
|
91
|
+
const componentStoriesDir = path.join(process.cwd(), 'src', 'stories', convertCase(componentName, KEBAB_CASE));
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const files = {
|
|
95
|
+
[`${convertCase(componentName, PASCAL_CASE)}.svelte`]: getComponentSvelte(componentName),
|
|
96
|
+
[`${convertCase(componentName, PASCAL_CASE)}.ts`]: getComponentTS(componentName),
|
|
97
|
+
[`index.ts`]: getIndexTS(componentName),
|
|
98
|
+
[`${convertCase(componentName, PASCAL_CASE)}.stories.svelte`]: getComponentStoriesSvelte(componentName),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// Create the folder and files with template content
|
|
103
|
+
if (!fs.existsSync(componentDir)) {
|
|
104
|
+
fs.mkdirSync(componentDir);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!fs.existsSync(componentStoriesDir)) {
|
|
108
|
+
fs.mkdirSync(componentStoriesDir);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
for (const [filename, content] of Object.entries(files)) {
|
|
113
|
+
const filePath = filename.includes('.stories.')
|
|
114
|
+
? path.join(componentStoriesDir, filename)
|
|
115
|
+
: path.join(componentDir, filename);
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log(`Component ${componentName} created successfully with 3 template files!`);
|