create-switch-framework-app 0.1.0 → 0.2.2

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.
Files changed (37) hide show
  1. package/README.md +25 -25
  2. package/bin/create-switch-framework-app.js +48 -35
  3. package/package.json +1 -1
  4. package/templates/electron/base/app/(tabs)/+not-found.js +157 -157
  5. package/templates/electron/base/app/(tabs)/_layout.js +57 -93
  6. package/templates/electron/base/app/(tabs)/explore.js +55 -44
  7. package/templates/electron/base/app/(tabs)/index.js +10 -24
  8. package/templates/electron/base/app/+not-found.js +148 -158
  9. package/templates/electron/base/app/_layout.js +24 -44
  10. package/templates/electron/base/app/index.js +16 -30
  11. package/templates/electron/base/assets/logo.svg +5 -5
  12. package/templates/electron/base/components/SwSplashScreen.js +1 -1
  13. package/templates/electron/base/components/SwStarterSplashScreen.js +130 -140
  14. package/templates/electron/base/components/SwTabBar.js +146 -153
  15. package/templates/electron/base/electron/electron-builder.json +19 -19
  16. package/templates/electron/base/electron/main.js +30 -30
  17. package/templates/electron/base/electron/preload.js +5 -5
  18. package/templates/electron/base/index.js +2 -3
  19. package/templates/electron/base/main.js +1 -1
  20. package/templates/electron/base/preload.js +1 -1
  21. package/templates/electron/base/server.js +27 -42
  22. package/templates/web/base/app/(tabs)/+not-found.js +157 -157
  23. package/templates/web/base/app/(tabs)/_layout.js +57 -93
  24. package/templates/web/base/app/(tabs)/explore.js +55 -44
  25. package/templates/web/base/app/(tabs)/index.js +10 -24
  26. package/templates/web/base/app/+not-found.js +148 -158
  27. package/templates/web/base/app/_layout.js +24 -44
  28. package/templates/web/base/app/index.js +16 -30
  29. package/templates/web/base/assets/logo.svg +5 -5
  30. package/templates/web/base/components/SwSplashScreen.js +1 -1
  31. package/templates/web/base/components/SwStarterSplashScreen.js +130 -140
  32. package/templates/web/base/components/SwTabBar.js +146 -153
  33. package/templates/web/base/index.js +2 -3
  34. package/templates/electron/base/app/(tabs)/register.js +0 -12
  35. package/templates/electron/base/app/register.js +0 -12
  36. package/templates/web/base/app/(tabs)/register.js +0 -12
  37. package/templates/web/base/app/register.js +0 -12
@@ -1,158 +1,158 @@
1
- export const screen = {
2
- name: '+not-found',
3
- path: '/+not-found',
4
- title: 'Not Found',
5
- tag: 'sw-user-not-found-screen',
6
- layout: 'stack'
7
- };
8
-
9
- export class SwUserNotFoundScreen extends HTMLElement {
10
- constructor() {
11
- super();
12
- this.attachShadow({ mode: 'open' });
13
- }
14
-
15
- static get observedAttributes() {
16
- return ['path'];
17
- }
18
-
19
- connectedCallback() {
20
- this.render();
21
- }
22
-
23
- attributeChangedCallback() {
24
- this.render();
25
- }
26
-
27
- render() {
28
- const path = this.getAttribute('path') || window.location.pathname || '';
29
-
30
- this.shadowRoot.innerHTML = `
31
- ${this.styleSheet()}
32
- <div class="wrap">
33
- <div class="card">
34
- <div class="code">404</div>
35
- <div class="h">This screen does not exist</div>
36
- <div class="p">No screen is registered for:</div>
37
- <div class="path">${path}</div>
38
-
39
- <div class="row">
40
- <button class="btn" id="home">Go to Home</button>
41
- <button class="btn secondary" id="back">Go Back</button>
42
- </div>
43
- </div>
44
- </div>
45
- `;
46
-
47
- this.shadowRoot.getElementById('home')?.addEventListener('click', () => {
48
- const navigate = globalStates?.getState ? globalStates.getState('navigate') : null;
49
- if (typeof navigate === 'function') navigate('home');
50
- });
51
-
52
- this.shadowRoot.getElementById('back')?.addEventListener('click', () => {
53
- const goBack = globalStates?.getState ? globalStates.getState('go_back') : null;
54
- if (typeof goBack === 'function') goBack();
55
- else window.history.back();
56
- });
57
- }
58
-
59
- styleSheet() {
60
- return `
61
- <style>
62
- :host {
63
- display: block;
64
- width: 100%;
65
- min-height: 100dvh;
66
- font-family: var(--font);
67
- }
68
-
69
- * {
70
- box-sizing: border-box;
71
- font-family: inherit;
72
- }
73
-
74
- .wrap {
75
- min-height: 100vh;
76
- display: flex;
77
- align-items: center;
78
- justify-content: center;
79
- padding: 18px;
80
- }
81
-
82
- .card {
83
- width: min(680px, 100%);
84
- background: transparent;
85
- border: none;
86
- border-radius: 18px;
87
- padding: 18px;
88
- box-shadow: none;
89
- }
90
-
91
- .code {
92
- font-weight: 1000;
93
- font-size: 44px;
94
- line-height: 1;
95
- color: var(--main_text);
96
- }
97
-
98
- .h {
99
- margin-top: 10px;
100
- font-weight: 1000;
101
- font-size: 20px;
102
- color: var(--main_text);
103
- }
104
-
105
- .p {
106
- margin-top: 6px;
107
- color: var(--sub_text);
108
- font-weight: 800;
109
- }
110
-
111
- .path {
112
- margin-top: 10px;
113
- padding: 10px 12px;
114
- border-radius: 14px;
115
- background: var(--surface_2);
116
- border: 1px solid var(--border_light);
117
- font-weight: 900;
118
- color: var(--main_text);
119
- word-break: break-word;
120
- }
121
-
122
- .row {
123
- margin-top: 14px;
124
- display: flex;
125
- gap: 10px;
126
- flex-wrap: wrap;
127
- }
128
-
129
- .btn {
130
- border: none;
131
- background: linear-gradient(135deg, #0091ff 0%, #0073e6 100%);
132
- color: #fff;
133
- font-weight: 1000;
134
- border-radius: 999px;
135
- padding: 10px 14px;
136
- cursor: pointer;
137
- }
138
-
139
- .btn:hover {
140
- opacity: 0.9;
141
- }
142
-
143
- .btn.secondary {
144
- background: var(--surface_2);
145
- color: var(--main_text);
146
- }
147
-
148
- .btn.secondary:hover {
149
- background: var(--surface_3);
150
- }
151
- </style>
152
- `;
153
- }
154
- }
155
-
156
- if (!customElements.get('sw-user-not-found-screen')) {
157
- customElements.define('sw-user-not-found-screen', SwUserNotFoundScreen);
1
+ export const screen = {
2
+ name: '+not-found',
3
+ path: '/+not-found',
4
+ title: 'Not Found',
5
+ tag: 'sw-user-not-found-screen',
6
+ layout: 'stack'
7
+ };
8
+
9
+ export class SwUserNotFoundScreen extends HTMLElement {
10
+ constructor() {
11
+ super();
12
+ this.attachShadow({ mode: 'open' });
13
+ }
14
+
15
+ static get observedAttributes() {
16
+ return ['path'];
17
+ }
18
+
19
+ connectedCallback() {
20
+ this.render();
21
+ }
22
+
23
+ attributeChangedCallback() {
24
+ this.render();
25
+ }
26
+
27
+ render() {
28
+ const path = this.getAttribute('path') || window.location.pathname || '';
29
+
30
+ this.shadowRoot.innerHTML = `
31
+ ${this.styleSheet()}
32
+ <div class="wrap">
33
+ <div class="card">
34
+ <div class="code">404</div>
35
+ <div class="h">This screen does not exist</div>
36
+ <div class="p">No screen is registered for:</div>
37
+ <div class="path">${path}</div>
38
+
39
+ <div class="row">
40
+ <button class="btn" id="home">Go to Home</button>
41
+ <button class="btn secondary" id="back">Go Back</button>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ `;
46
+
47
+ this.shadowRoot.getElementById('home')?.addEventListener('click', () => {
48
+ const navigate = globalStates?.getState ? globalStates.getState('navigate') : null;
49
+ if (typeof navigate === 'function') navigate('home');
50
+ });
51
+
52
+ this.shadowRoot.getElementById('back')?.addEventListener('click', () => {
53
+ const goBack = globalStates?.getState ? globalStates.getState('go_back') : null;
54
+ if (typeof goBack === 'function') goBack();
55
+ else window.history.back();
56
+ });
57
+ }
58
+
59
+ styleSheet() {
60
+ return `
61
+ <style>
62
+ :host {
63
+ display: block;
64
+ width: 100%;
65
+ min-height: 100dvh;
66
+ font-family: var(--font);
67
+ }
68
+
69
+ * {
70
+ box-sizing: border-box;
71
+ font-family: inherit;
72
+ }
73
+
74
+ .wrap {
75
+ min-height: 100vh;
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ padding: 18px;
80
+ }
81
+
82
+ .card {
83
+ width: min(680px, 100%);
84
+ background: transparent;
85
+ border: none;
86
+ border-radius: 18px;
87
+ padding: 18px;
88
+ box-shadow: none;
89
+ }
90
+
91
+ .code {
92
+ font-weight: 1000;
93
+ font-size: 44px;
94
+ line-height: 1;
95
+ color: var(--main_text);
96
+ }
97
+
98
+ .h {
99
+ margin-top: 10px;
100
+ font-weight: 1000;
101
+ font-size: 20px;
102
+ color: var(--main_text);
103
+ }
104
+
105
+ .p {
106
+ margin-top: 6px;
107
+ color: var(--sub_text);
108
+ font-weight: 800;
109
+ }
110
+
111
+ .path {
112
+ margin-top: 10px;
113
+ padding: 10px 12px;
114
+ border-radius: 14px;
115
+ background: var(--surface_2);
116
+ border: 1px solid var(--border_light);
117
+ font-weight: 900;
118
+ color: var(--main_text);
119
+ word-break: break-word;
120
+ }
121
+
122
+ .row {
123
+ margin-top: 14px;
124
+ display: flex;
125
+ gap: 10px;
126
+ flex-wrap: wrap;
127
+ }
128
+
129
+ .btn {
130
+ border: none;
131
+ background: linear-gradient(135deg, #0091ff 0%, #0073e6 100%);
132
+ color: #fff;
133
+ font-weight: 1000;
134
+ border-radius: 999px;
135
+ padding: 10px 14px;
136
+ cursor: pointer;
137
+ }
138
+
139
+ .btn:hover {
140
+ opacity: 0.9;
141
+ }
142
+
143
+ .btn.secondary {
144
+ background: var(--surface_2);
145
+ color: var(--main_text);
146
+ }
147
+
148
+ .btn.secondary:hover {
149
+ background: var(--surface_3);
150
+ }
151
+ </style>
152
+ `;
153
+ }
154
+ }
155
+
156
+ if (!customElements.get('sw-user-not-found-screen')) {
157
+ customElements.define('sw-user-not-found-screen', SwUserNotFoundScreen);
158
158
  }
@@ -1,16 +1,22 @@
1
- import { Tabs } from '/switch-framework/index.js';
1
+ import { TabLayout, registerComponents } from 'switch-framework';
2
+ import { SwTabBar } from '../../components/SwTabBar.js';
3
+ import { SwHomeScreen } from './index.js';
4
+ import { SwExploreScreen } from './explore.js';
2
5
 
3
- export const tabsLayout = Tabs({
4
- name: 'sw-tabs-layout',
5
- initialTab: 'home',
6
- tabs: [
6
+ registerComponents([SwTabBar]);
7
+
8
+ export class SwTabsLayout extends TabLayout {
9
+ static tag = 'sw-tabs-layout';
10
+ static initialTab = 'home';
11
+ static tabs = [
7
12
  {
8
13
  name: 'home',
9
14
  title: 'Home',
10
15
  icon: 'home',
11
16
  path: '/home',
12
17
  screen: 'sw-home-screen',
13
- match: ['home']
18
+ match: ['home'],
19
+ initialRoute: 'home'
14
20
  },
15
21
  {
16
22
  name: 'explore',
@@ -18,31 +24,15 @@ export const tabsLayout = Tabs({
18
24
  icon: 'compass',
19
25
  path: '/explore',
20
26
  screen: 'sw-explore-screen',
21
- match: ['explore']
27
+ match: ['explore'],
28
+ initialRoute: 'explore'
22
29
  }
23
- ],
24
- options: {
25
- position: 'bottom'
26
- }
27
- });
28
-
29
- export class SwTabsLayout extends HTMLElement {
30
- constructor() {
31
- super();
32
- this.attachShadow({ mode: 'open' });
33
- }
34
-
35
- connectedCallback() {
36
- this.render();
37
- }
38
-
39
- getContentContainer() {
40
- return this.shadowRoot.querySelector('.tabcontainer');
41
- }
30
+ ];
31
+ static options = { position: 'bottom' };
32
+ static screens = [SwHomeScreen, SwExploreScreen];
42
33
 
43
34
  render() {
44
- this.shadowRoot.innerHTML = `
45
- ${this.styleSheet()}
35
+ return `
46
36
  <div class="layout">
47
37
  <div class="tabcontainer"></div>
48
38
  <div class="tabbar">
@@ -54,72 +44,46 @@ export class SwTabsLayout extends HTMLElement {
54
44
 
55
45
  styleSheet() {
56
46
  return `
57
- <style>
58
- :host {
59
- display: flex;
60
- flex-direction: column;
61
- width: 100%;
62
- height: inherit;
63
- overflow: hidden;
64
- font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif
65
- }
66
-
67
- * {
68
- box-sizing: border-box;
69
- font-family: inherit
70
- }
71
-
72
-
73
- .layout {
74
- min-height: 0;
75
- height: 100%;
76
- display: grid;
77
- grid-template-rows: minmax(0, 1fr) auto;
78
- overflow: hidden;
79
- }
80
-
81
- .tabbar {
82
- height: auto;
83
- position: sticky;
84
- bottom: 0;
85
- z-index: 50;
86
- }
87
-
88
-
89
- .tabcontainer {
90
- z-index: 1;
91
- min-height: 0;
92
- overflow: auto;
93
- overflow-x: hidden;
94
- padding-bottom: calc(12px + 56px + env(safe-area-inset-bottom, 0px));
95
- }
96
-
97
- </style>
47
+ <style>
48
+ :host {
49
+ display: flex;
50
+ flex-direction: column;
51
+ width: 100%;
52
+ height: inherit;
53
+ overflow: hidden;
54
+ font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
55
+ }
56
+
57
+ * {
58
+ box-sizing: border-box;
59
+ font-family: inherit;
60
+ }
61
+
62
+ .layout {
63
+ min-height: 0;
64
+ height: 100%;
65
+ display: grid;
66
+ grid-template-rows: minmax(0, 1fr) auto;
67
+ overflow: hidden;
68
+ }
69
+
70
+ .tabbar {
71
+ height: auto;
72
+ position: sticky;
73
+ bottom: 0;
74
+ z-index: 50;
75
+ }
76
+
77
+ .tabcontainer {
78
+ z-index: 1;
79
+ min-height: 0;
80
+ overflow: auto;
81
+ overflow-x: hidden;
82
+ padding-bottom: calc(12px + 56px + env(safe-area-inset-bottom, 0px));
83
+ }
84
+ </style>
98
85
  `;
99
86
  }
100
87
  }
101
88
 
102
- if (!customElements.get('sw-tabs-layout')) {
103
- customElements.define('sw-tabs-layout', SwTabsLayout);
104
- }
105
-
106
- export const screens = [
107
- Tabs.screen({
108
- name: 'home',
109
- path: '/home',
110
- title: 'Home',
111
- tag: 'sw-home-screen',
112
- layout: 'tabs'
113
- }),
114
- Tabs.screen({
115
- name: 'explore',
116
- path: '/explore',
117
- title: 'Explore',
118
- tag: 'sw-explore-screen',
119
- layout: 'tabs'
120
- })
121
- ];
122
-
123
- tabsLayout.screens = screens;
124
-
125
- export default tabsLayout;
89
+ export default SwTabsLayout;
@@ -1,44 +1,55 @@
1
- export const screen = {
2
- name: 'explore',
3
- path: '/explore',
4
- title: 'Explore',
5
- tag: 'sw-explore-screen',
6
- layout: 'tabs'
7
- };
8
-
9
- export class SwExploreScreen extends HTMLElement {
10
- constructor() {
11
- super();
12
- this.attachShadow({ mode: 'open' });
13
- }
14
-
15
- connectedCallback() {
16
- this.render();
17
- }
18
-
19
- render() {
20
- this.shadowRoot.innerHTML = `
21
- ${this.styleSheet()}
22
- <div class="wrap">
23
- <div class="h">Explore</div>
24
- <div class="p">This is a placeholder tab. Replace it with whatever you want.</div>
25
- </div>
26
- `;
27
- }
28
-
29
- styleSheet() {
30
- return `
31
- <style>
32
- :host{display:block;padding:18px;font-family:var(--font)}
33
- *{box-sizing:border-box;font-family:inherit}
34
- .wrap{max-width:900px;margin:0 auto;display:flex;flex-direction:column;gap:10px}
35
- .h{font-weight:1000;font-size:22px;color:var(--main_text)}
36
- .p{color:var(--sub_text);font-weight:800;line-height:1.5}
37
- </style>
38
- `;
39
- }
40
- }
41
-
42
- if (!customElements.get('sw-explore-screen')) {
43
- customElements.define('sw-explore-screen', SwExploreScreen);
44
- }
1
+ import { SwitchComponent } from 'switch-framework';
2
+
3
+ export class SwExploreScreen extends SwitchComponent {
4
+ static screenName = 'explore';
5
+ static path = '/explore';
6
+ static title = 'Explore';
7
+ static tag = 'sw-explore-screen';
8
+ static layout = 'tabs';
9
+
10
+ render() {
11
+ return `
12
+ <div class="wrap">
13
+ <div class="h">Explore</div>
14
+ <div class="p">This is a placeholder tab. Replace it with whatever you want.</div>
15
+ </div>
16
+ `;
17
+ }
18
+
19
+ styleSheet() {
20
+ return `
21
+ <style>
22
+ :host {
23
+ display: block;
24
+ padding: 18px;
25
+ font-family: var(--font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
26
+ }
27
+
28
+ * {
29
+ box-sizing: border-box;
30
+ font-family: inherit;
31
+ }
32
+
33
+ .wrap {
34
+ max-width: 900px;
35
+ margin: 0 auto;
36
+ display: flex;
37
+ flex-direction: column;
38
+ gap: 10px;
39
+ }
40
+
41
+ .h {
42
+ font-weight: 1000;
43
+ font-size: 22px;
44
+ color: var(--main_text, #000);
45
+ }
46
+
47
+ .p {
48
+ color: var(--sub_text, #666);
49
+ font-weight: 600;
50
+ line-height: 1.5;
51
+ }
52
+ </style>
53
+ `;
54
+ }
55
+ }
@@ -1,30 +1,20 @@
1
- export const screen = {
2
- name: 'home',
3
- path: '/home',
4
- title: 'Home',
5
- tag: 'sw-home-screen',
6
- layout: 'tabs'
7
- };
8
-
9
- export class SwHomeScreen extends HTMLElement {
10
- constructor() {
11
- super();
12
- this.attachShadow({ mode: 'open' });
13
- }
1
+ import { SwitchComponent } from 'switch-framework';
14
2
 
15
- connectedCallback() {
16
- this.render();
17
- }
3
+ export class SwHomeScreen extends SwitchComponent {
4
+ static screenName = 'home';
5
+ static path = '/home';
6
+ static title = 'Home';
7
+ static tag = 'sw-home-screen';
8
+ static layout = 'tabs';
18
9
 
19
10
  render() {
20
- this.shadowRoot.innerHTML = `
21
- ${this.styleSheet()}
11
+ return `
22
12
  <div class="wrap">
23
13
  <div class="spacer-top"></div>
24
14
 
25
15
  <div class="hero">
26
16
  <div class="logo-container">
27
- <img class="logo" src="/assets/logo.svg" alt="Expo" />
17
+ <img class="logo" src="/assets/logo.svg" alt="Switch Framework" />
28
18
  </div>
29
19
  <div class="title">Tabs View</div>
30
20
  </div>
@@ -37,7 +27,7 @@ export class SwHomeScreen extends HTMLElement {
37
27
  <div class="card">
38
28
  <div class="row">
39
29
  <div class="l">Try editing</div>
40
- <div class="r">src/app/index.tsx</div>
30
+ <div class="r">src/app/(tabs)/index.js</div>
41
31
  </div>
42
32
  <div class="row">
43
33
  <div class="l">Dev tools</div>
@@ -212,7 +202,3 @@ export class SwHomeScreen extends HTMLElement {
212
202
  `;
213
203
  }
214
204
  }
215
-
216
- if (!customElements.get('sw-home-screen')) {
217
- customElements.define('sw-home-screen', SwHomeScreen);
218
- }