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,50 +1,30 @@
1
- import { Stack, registerScreens } from '/switch-framework/index.js';
2
- import tabsLayout from './(tabs)/_layout.js';
3
-
4
- const tabScreens = Array.isArray(tabsLayout?.screens) ? tabsLayout.screens : [];
5
-
6
- const stackScreens = [
7
- Stack.screen({
8
- name: 'index',
9
- path: '/',
10
- title: 'Welcome',
11
- tag: 'sw-index-screen'
12
- }),
13
- Stack.screen({
14
- name: '+not-found',
15
- path: '/+not-found',
16
- title: 'Not Found',
17
- tag: 'sw-user-not-found-screen'
18
- })
19
- ];
20
-
21
- const screens = registerScreens({
22
- stackScreens,
23
- tabsLayout,
24
- tabScreens,
25
- validate: true
26
- }).screens;
27
-
28
- const layout = {
29
- splash: 'sw-starter-splash',
30
- initialRoute: 'index',
31
- screens,
32
-
33
- async init({ globalStates, renderSplashscreen }) {
1
+ import { StackLayout, createState, registerComponents } from 'switch-framework';
2
+ import { SwStarterSplashScreen } from '../components/SwStarterSplashScreen.js';
3
+ import { SwTabBar } from '../components/SwTabBar.js';
4
+ import { SwIndexScreen } from './index.js';
5
+ import NotFoundScreen from './+not-found.js';
6
+ import { SwTabsLayout } from './(tabs)/_layout.js';
7
+
8
+ registerComponents([SwStarterSplashScreen, SwTabBar]);
9
+
10
+ export class SwStackLayout extends StackLayout {
11
+ static tag = 'sw-stack-layout';
12
+ static stackScreens = [SwIndexScreen, NotFoundScreen];
13
+ static tabsLayout = SwTabsLayout;
14
+ static splash = 'sw-starter-splash';
15
+ static initialRoute = 'index';
16
+
17
+ static async init({ globalStates, renderSplashscreen }) {
34
18
  renderSplashscreen('sw-starter-splash');
35
19
 
36
- // your async operation here that made splashscreen appear
37
- await new Promise((resolve) => setTimeout(resolve, 3000));
20
+ // Example: create app-level state
21
+ createState('example-counter', 0);
38
22
 
39
- globalStates.setState({
40
- tabsLayout
41
- });
23
+ // Simulate async init (e.g. load config, auth check)
24
+ await new Promise((resolve) => setTimeout(resolve, 3000));
42
25
 
43
- return {
44
- splash: 'sw-starter-splash',
45
- initialRoute: 'index'
46
- };
26
+ return { splash: 'sw-starter-splash', initialRoute: 'index' };
47
27
  }
48
- };
28
+ }
49
29
 
50
- export default layout;
30
+ export default SwStackLayout.getAppLayout();
@@ -1,37 +1,27 @@
1
- export const screen = {
2
- name: 'index',
3
- path: '/',
4
- title: 'Welcome',
5
- tag: 'sw-index-screen',
6
- layout: 'stack'
7
- };
8
-
9
- export class SwIndexScreen extends HTMLElement {
10
- constructor() {
11
- super();
12
- this.attachShadow({ mode: 'open' });
13
- }
14
-
15
- async connectedCallback() {
16
- this.render();
17
-
18
- const replace = globalStates?.getState ? globalStates.getState('replace') : null;
19
- const redirect = globalStates?.getState ? globalStates.getState('redirect') : null;
20
-
21
- this.shadowRoot.querySelector('#go_home').addEventListener('click', () => {
22
- if (typeof replace === 'function') return replace('home');
1
+ import { SwitchComponent } from 'switch-framework';
2
+ import { navigate } from 'switch-framework/router';
3
+
4
+ export class SwIndexScreen extends SwitchComponent {
5
+ static screenName = 'index';
6
+ static path = '/';
7
+ static title = 'Welcome';
8
+ static tag = 'sw-index-screen';
9
+ static layout = 'stack';
10
+
11
+ connected() {
12
+ this.shadowRoot.querySelector('#go_home')?.addEventListener('click', () => {
13
+ navigate('home');
23
14
  });
24
15
  }
25
16
 
26
17
  render() {
27
- this.shadowRoot.innerHTML = `
28
- ${this.styleSheet()}
18
+ return `
29
19
  <div class="wrap">
30
20
  <div class="spacer-top"></div>
31
21
 
32
22
  <div class="hero">
33
23
  <div class="logo-container">
34
- <img class="logo" src="/assets/logo.svg" alt="Expo" />
24
+ <img class="logo" src="/assets/logo.svg" alt="Switch Framework" />
35
25
  </div>
36
26
  <div class="title">Introducing<br>Switch Framework</div>
37
27
  </div>
@@ -44,7 +34,7 @@ export class SwIndexScreen extends HTMLElement {
44
34
  <div class="card">
45
35
  <div class="row">
46
36
  <div class="l">Try editing</div>
47
- <div class="r">src/app/index.tsx</div>
37
+ <div class="r">src/app/index.js</div>
48
38
  </div>
49
39
  <div class="row">
50
40
  <div class="l">Dev tools</div>
@@ -259,7 +249,3 @@ export class SwIndexScreen extends HTMLElement {
259
249
  `;
260
250
  }
261
251
  }
262
-
263
- if (!customElements.get('sw-index-screen')) {
264
- customElements.define('sw-index-screen', SwIndexScreen);
265
- }
@@ -1,5 +1,5 @@
1
- <svg width="160" height="160" viewBox="0 0 160 160" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <rect x="8" y="8" width="144" height="144" rx="36" fill="#E60023"/>
3
- <path d="M53 59C53 49.6112 60.6112 42 70 42H90C99.3888 42 107 49.6112 107 59V63C107 72.3888 99.3888 80 90 80H78C72.4772 80 68 84.4772 68 90V94C68 103.389 60.3888 111 51 111H50" stroke="white" stroke-width="12" stroke-linecap="round"/>
4
- <path d="M110 111H94" stroke="white" stroke-width="12" stroke-linecap="round"/>
5
- </svg>
1
+ <svg width="160" height="160" viewBox="0 0 160 160" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect x="8" y="8" width="144" height="144" rx="36" fill="#E60023"/>
3
+ <path d="M53 59C53 49.6112 60.6112 42 70 42H90C99.3888 42 107 49.6112 107 59V63C107 72.3888 99.3888 80 90 80H78C72.4772 80 68 84.4772 68 90V94C68 103.389 60.3888 111 51 111H50" stroke="white" stroke-width="12" stroke-linecap="round"/>
4
+ <path d="M110 111H94" stroke="white" stroke-width="12" stroke-linecap="round"/>
5
+ </svg>
@@ -1 +1 @@
1
- export { SwStarterSplashScreen as SwSplashScreen } from './SwStarterSplashScreen.js';
1
+ export { SwStarterSplashScreen as SwSplashScreen } from './SwStarterSplashScreen.js';
@@ -1,140 +1,130 @@
1
- export class SwStarterSplashScreen extends HTMLElement {
2
- constructor() {
3
- super();
4
- this.attachShadow({ mode: 'open' });
5
- }
6
-
7
- connectedCallback() {
8
- this.render();
9
- }
10
-
11
- render() {
12
- this.shadowRoot.innerHTML = `
13
- ${this.styleSheet()}
14
- <div class="wrap">
15
- <div class="card">
16
- <div class="logo-container">
17
- <img class="logo" src="/assets/logo.svg" alt="Expo" />
18
- </div>
19
- <div class="title">Switch Framework</div>
20
- <div class="sub">Launching...</div>
21
-
22
- <div class="loader-container">
23
- <div class="loader"></div>
24
- </div>
25
- </div>
26
- </div>
27
- `;
28
- }
29
-
30
- styleSheet() {
31
- return `
32
- <style>
33
- :host {
34
- position: fixed;
35
- inset: 0;
36
- display: block;
37
- background: var(--page_background, #fff);
38
- z-index: 9999;
39
- }
40
-
41
- * {
42
- box-sizing: border-box;
43
- font-family: var(--font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
44
- }
45
-
46
- .wrap {
47
- height: 100%;
48
- display: flex;
49
- align-items: center;
50
- justify-content: center;
51
- padding: 18px;
52
- }
53
-
54
- .card {
55
- width: min(520px, 100%);
56
- display: flex;
57
- flex-direction: column;
58
- align-items: center;
59
- gap: 16px;
60
- }
61
-
62
- .logo-container {
63
- display: flex;
64
- align-items: center;
65
- justify-content: center;
66
- width: 100px;
67
- height: 100px;
68
- background: linear-gradient(135deg, #0091ff 0%, #0073e6 100%);
69
- border-radius: 28px;
70
- box-shadow: 0 20px 40px rgba(0, 145, 255, 0.25);
71
- animation: fadeInScale 0.6s ease-out;
72
- }
73
-
74
- .logo {
75
- width: 56px;
76
- height: 56px;
77
- filter: brightness(0) invert(1);
78
- }
79
-
80
- .title {
81
- font-weight: 700;
82
- font-size: 24px;
83
- color: var(--main_text, #000);
84
- animation: fadeIn 0.8s ease-out 0.2s both;
85
- }
86
-
87
- .sub {
88
- font-weight: 600;
89
- font-size: 13px;
90
- color: var(--sub_text, #666);
91
- animation: fadeIn 0.8s ease-out 0.3s both;
92
- }
93
-
94
- .loader-container {
95
- margin-top: 12px;
96
- animation: fadeIn 0.8s ease-out 0.4s both;
97
- }
98
-
99
- .loader {
100
- width: 48px;
101
- height: 48px;
102
- border: 3px solid rgba(0, 145, 255, 0.15);
103
- border-top: 3px solid #0091ff;
104
- border-radius: 50%;
105
- animation: spin 1s linear infinite;
106
- }
107
-
108
- @keyframes spin {
109
- to {
110
- transform: rotate(360deg);
111
- }
112
- }
113
-
114
- @keyframes fadeIn {
115
- from {
116
- opacity: 0;
117
- }
118
- to {
119
- opacity: 1;
120
- }
121
- }
122
-
123
- @keyframes fadeInScale {
124
- from {
125
- opacity: 0;
126
- transform: scale(0.8);
127
- }
128
- to {
129
- opacity: 1;
130
- transform: scale(1);
131
- }
132
- }
133
- </style>
134
- `;
135
- }
136
- }
137
-
138
- if (!customElements.get('sw-starter-splash')) {
139
- customElements.define('sw-starter-splash', SwStarterSplashScreen);
140
- }
1
+ import { SwitchComponent } from 'switch-framework';
2
+
3
+ export class SwStarterSplashScreen extends SwitchComponent {
4
+ static tag = 'sw-starter-splash';
5
+
6
+ render() {
7
+ return `
8
+ <div class="wrap">
9
+ <div class="card">
10
+ <div class="logo-container">
11
+ <img class="logo" src="/assets/logo.svg" alt="Switch Framework" />
12
+ </div>
13
+ <div class="title">Switch Framework</div>
14
+ <div class="sub">Launching...</div>
15
+
16
+ <div class="loader-container">
17
+ <div class="loader"></div>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ `;
22
+ }
23
+
24
+ styleSheet() {
25
+ return `
26
+ <style>
27
+ :host {
28
+ position: fixed;
29
+ inset: 0;
30
+ display: block;
31
+ background: var(--page_background, #fff);
32
+ z-index: 9999;
33
+ }
34
+
35
+ * {
36
+ box-sizing: border-box;
37
+ font-family: var(--font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
38
+ }
39
+
40
+ .wrap {
41
+ height: 100%;
42
+ display: flex;
43
+ align-items: center;
44
+ justify-content: center;
45
+ padding: 18px;
46
+ }
47
+
48
+ .card {
49
+ width: min(520px, 100%);
50
+ display: flex;
51
+ flex-direction: column;
52
+ align-items: center;
53
+ gap: 16px;
54
+ }
55
+
56
+ .logo-container {
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ width: 100px;
61
+ height: 100px;
62
+ background: linear-gradient(135deg, #0091ff 0%, #0073e6 100%);
63
+ border-radius: 28px;
64
+ box-shadow: 0 20px 40px rgba(0, 145, 255, 0.25);
65
+ animation: fadeInScale 0.6s ease-out;
66
+ }
67
+
68
+ .logo {
69
+ width: 56px;
70
+ height: 56px;
71
+ filter: brightness(0) invert(1);
72
+ }
73
+
74
+ .title {
75
+ font-weight: 700;
76
+ font-size: 24px;
77
+ color: var(--main_text, #000);
78
+ animation: fadeIn 0.8s ease-out 0.2s both;
79
+ }
80
+
81
+ .sub {
82
+ font-weight: 600;
83
+ font-size: 13px;
84
+ color: var(--sub_text, #666);
85
+ animation: fadeIn 0.8s ease-out 0.3s both;
86
+ }
87
+
88
+ .loader-container {
89
+ margin-top: 12px;
90
+ animation: fadeIn 0.8s ease-out 0.4s both;
91
+ }
92
+
93
+ .loader {
94
+ width: 48px;
95
+ height: 48px;
96
+ border: 3px solid rgba(0, 145, 255, 0.15);
97
+ border-top: 3px solid #0091ff;
98
+ border-radius: 50%;
99
+ animation: spin 1s linear infinite;
100
+ }
101
+
102
+ @keyframes spin {
103
+ to {
104
+ transform: rotate(360deg);
105
+ }
106
+ }
107
+
108
+ @keyframes fadeIn {
109
+ from {
110
+ opacity: 0;
111
+ }
112
+ to {
113
+ opacity: 1;
114
+ }
115
+ }
116
+
117
+ @keyframes fadeInScale {
118
+ from {
119
+ opacity: 0;
120
+ transform: scale(0.8);
121
+ }
122
+ to {
123
+ opacity: 1;
124
+ transform: scale(1);
125
+ }
126
+ }
127
+ </style>
128
+ `;
129
+ }
130
+ }