create-nativecore 0.1.1 → 0.2.0
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/README.md +6 -14
- package/bin/index.mjs +402 -431
- package/package.json +3 -2
- package/template/.env.example +28 -0
- package/template/.htmlhintrc +14 -0
- package/template/api/data/dashboard.json +11 -0
- package/template/api/data/users.json +18 -0
- package/template/api/mockApi.js +161 -0
- package/template/assets/icon.svg +13 -0
- package/template/assets/logo.svg +25 -0
- package/template/eslint.config.js +94 -0
- package/template/index.html +137 -0
- package/template/manifest.json +19 -0
- package/template/public/.well-known/security.txt +9 -0
- package/template/public/_headers +24 -0
- package/template/public/_redirects +14 -0
- package/template/public/assets/icon.svg +13 -0
- package/template/public/assets/logo.svg +25 -0
- package/template/public/manifest.json +19 -0
- package/template/public/robots.txt +13 -0
- package/template/public/sitemap.xml +27 -0
- package/template/scripts/build-for-bots.mjs +121 -0
- package/template/scripts/convert-to-ts.mjs +106 -0
- package/template/scripts/fix-encoding.mjs +38 -0
- package/template/scripts/fix-svg-paths.mjs +32 -0
- package/template/scripts/generate-cf-router.mjs +52 -0
- package/template/scripts/inject-dev-tools.mjs +41 -0
- package/template/scripts/inject-version.mjs +65 -0
- package/template/scripts/make-component.mjs +445 -0
- package/template/scripts/make-component.mjs.backup +432 -0
- package/template/scripts/make-controller.mjs +119 -0
- package/template/scripts/make-core-component.mjs +303 -0
- package/template/scripts/make-view.mjs +346 -0
- package/template/scripts/minify.mjs +71 -0
- package/template/scripts/prepare-static-assets.mjs +141 -0
- package/template/scripts/prompt-bot-build.mjs +223 -0
- package/template/scripts/remove-component.mjs +170 -0
- package/template/scripts/remove-core-component.mjs +156 -0
- package/template/scripts/remove-dev.mjs +13 -0
- package/template/scripts/remove-view.mjs +200 -0
- package/template/scripts/strip-dev-blocks.mjs +30 -0
- package/template/scripts/watch-compile.mjs +69 -0
- package/template/server.js +1066 -0
- package/template/src/app.ts +115 -0
- package/template/src/components/appRegistry.ts +8 -0
- package/template/src/components/core/app-footer.ts +27 -0
- package/template/src/components/core/app-header.ts +175 -0
- package/template/src/components/core/app-sidebar.ts +238 -0
- package/template/src/components/core/loading-spinner.ts +25 -0
- package/template/src/components/core/nc-a.ts +313 -0
- package/template/src/components/core/nc-accordion.ts +186 -0
- package/template/src/components/core/nc-alert.ts +153 -0
- package/template/src/components/core/nc-animation.ts +1150 -0
- package/template/src/components/core/nc-autocomplete.ts +271 -0
- package/template/src/components/core/nc-avatar-group.ts +113 -0
- package/template/src/components/core/nc-avatar.ts +148 -0
- package/template/src/components/core/nc-badge.ts +86 -0
- package/template/src/components/core/nc-bottom-nav.ts +214 -0
- package/template/src/components/core/nc-breadcrumb.ts +96 -0
- package/template/src/components/core/nc-button.ts +307 -0
- package/template/src/components/core/nc-card.ts +160 -0
- package/template/src/components/core/nc-checkbox.ts +282 -0
- package/template/src/components/core/nc-chip.ts +115 -0
- package/template/src/components/core/nc-code.ts +314 -0
- package/template/src/components/core/nc-collapsible.ts +154 -0
- package/template/src/components/core/nc-color-picker.ts +268 -0
- package/template/src/components/core/nc-copy-button.ts +119 -0
- package/template/src/components/core/nc-date-picker.ts +443 -0
- package/template/src/components/core/nc-div.ts +280 -0
- package/template/src/components/core/nc-divider.ts +81 -0
- package/template/src/components/core/nc-drawer.ts +230 -0
- package/template/src/components/core/nc-dropdown.ts +178 -0
- package/template/src/components/core/nc-empty-state.ts +134 -0
- package/template/src/components/core/nc-file-upload.ts +354 -0
- package/template/src/components/core/nc-form.ts +312 -0
- package/template/src/components/core/nc-image.ts +184 -0
- package/template/src/components/core/nc-input.ts +383 -0
- package/template/src/components/core/nc-kbd.ts +48 -0
- package/template/src/components/core/nc-menu-item.ts +193 -0
- package/template/src/components/core/nc-menu.ts +376 -0
- package/template/src/components/core/nc-modal.ts +238 -0
- package/template/src/components/core/nc-nav-item.ts +151 -0
- package/template/src/components/core/nc-number-input.ts +350 -0
- package/template/src/components/core/nc-otp-input.ts +235 -0
- package/template/src/components/core/nc-pagination.ts +178 -0
- package/template/src/components/core/nc-popover.ts +260 -0
- package/template/src/components/core/nc-progress-circular.ts +119 -0
- package/template/src/components/core/nc-progress.ts +134 -0
- package/template/src/components/core/nc-radio.ts +235 -0
- package/template/src/components/core/nc-rating.ts +266 -0
- package/template/src/components/core/nc-rich-text.ts +283 -0
- package/template/src/components/core/nc-scroll-top.ts +116 -0
- package/template/src/components/core/nc-select.ts +452 -0
- package/template/src/components/core/nc-skeleton.ts +107 -0
- package/template/src/components/core/nc-slider.ts +285 -0
- package/template/src/components/core/nc-snackbar.ts +230 -0
- package/template/src/components/core/nc-splash.ts +343 -0
- package/template/src/components/core/nc-stepper.ts +247 -0
- package/template/src/components/core/nc-switch.ts +281 -0
- package/template/src/components/core/nc-tab-item.ts +138 -0
- package/template/src/components/core/nc-table.ts +279 -0
- package/template/src/components/core/nc-tabs.ts +554 -0
- package/template/src/components/core/nc-tag-input.ts +279 -0
- package/template/src/components/core/nc-textarea.ts +216 -0
- package/template/src/components/core/nc-time-picker.ts +438 -0
- package/template/src/components/core/nc-timeline.ts +186 -0
- package/template/src/components/core/nc-tooltip.ts +143 -0
- package/template/src/components/frameworkRegistry.ts +68 -0
- package/template/src/components/preloadRegistry.ts +28 -0
- package/template/src/components/registry.ts +8 -0
- package/template/src/components/ui/dashboard-signal-lab.ts +284 -0
- package/template/src/constants/apiEndpoints.ts +27 -0
- package/template/src/constants/errorMessages.ts +23 -0
- package/template/src/constants/index.ts +8 -0
- package/template/src/constants/routePaths.ts +15 -0
- package/template/src/constants/storageKeys.ts +18 -0
- package/template/src/controllers/dashboard.controller.ts +200 -0
- package/template/src/controllers/home.controller.ts +21 -0
- package/template/src/controllers/index.ts +11 -0
- package/template/src/controllers/login.controller.ts +131 -0
- package/template/src/core/component.ts +354 -0
- package/template/src/core/errorHandler.ts +85 -0
- package/template/src/core/gpu-animation.ts +604 -0
- package/template/src/core/http.ts +173 -0
- package/template/src/core/lazyComponents.ts +90 -0
- package/template/src/core/router.ts +642 -0
- package/template/src/core/signals.ts +146 -0
- package/template/src/core/state.ts +248 -0
- package/template/src/dev/component-editor.ts +1363 -0
- package/template/src/dev/component-overlay.ts +278 -0
- package/template/src/dev/context-menu.ts +223 -0
- package/template/src/dev/denc-tools.ts +250 -0
- package/template/src/dev/hmr.ts +189 -0
- package/template/src/dev/nfbs.code-workspace +27 -0
- package/template/src/dev/outline-panel.ts +1247 -0
- package/template/src/middleware/auth.middleware.ts +23 -0
- package/template/src/routes/routes.ts +38 -0
- package/template/src/services/api.service.ts +394 -0
- package/template/src/services/auth.service.ts +176 -0
- package/template/src/services/index.ts +8 -0
- package/template/src/services/logger.service.ts +74 -0
- package/template/src/services/storage.service.ts +88 -0
- package/template/src/stores/appStore.ts +57 -0
- package/template/src/stores/uiStore.ts +36 -0
- package/template/src/styles/core-variables.css +219 -0
- package/template/src/styles/core.css +710 -0
- package/template/src/styles/main.css +3164 -0
- package/template/src/styles/variables.css +152 -0
- package/template/src/types/global.d.ts +47 -0
- package/template/src/utils/cacheBuster.ts +20 -0
- package/template/src/utils/dom.ts +149 -0
- package/template/src/utils/events.ts +203 -0
- package/template/src/utils/form.ts +176 -0
- package/template/src/utils/formatters.ts +169 -0
- package/template/src/utils/helpers.ts +195 -0
- package/template/src/utils/markdown.ts +307 -0
- package/template/src/utils/sidebar.ts +96 -0
- package/template/src/utils/smoothScroll.ts +85 -0
- package/template/src/utils/templates.ts +23 -0
- package/template/src/utils/validation.ts +73 -0
- package/template/src/views/protected/dashboard.html +293 -0
- package/template/src/views/public/home.html +150 -0
- package/template/src/views/public/login.html +102 -0
- package/template/tests/unit/component.test.ts +87 -0
- package/template/tests/unit/computed.test.ts +79 -0
- package/template/tests/unit/form.test.ts +68 -0
- package/template/tests/unit/formatters.test.ts +49 -0
- package/template/tests/unit/lazy-components.test.ts +59 -0
- package/template/tests/unit/markdown.test.ts +62 -0
- package/template/tests/unit/router.test.ts +112 -0
- package/template/tests/unit/signals.test.ts +54 -0
- package/template/tests/unit/validation.test.ts +50 -0
- package/template/tsconfig.build.json +21 -0
- package/template/tsconfig.json +51 -0
- package/template/vitest.config.ts +36 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client
|
|
3
|
+
* Enhanced wrapper around fetch with interceptors, retries, and better error handling
|
|
4
|
+
*/
|
|
5
|
+
import errorHandler from './errorHandler.js';
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
export interface HttpConfig extends RequestInit {
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
params?: Record<string, string>;
|
|
11
|
+
data?: any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RequestInterceptor = (config: HttpConfig) => HttpConfig | Promise<HttpConfig>;
|
|
15
|
+
export type ResponseInterceptor = (response: Response) => Response | Promise<Response>;
|
|
16
|
+
|
|
17
|
+
class HttpClient {
|
|
18
|
+
private baseURL: string = '';
|
|
19
|
+
private defaultHeaders: Record<string, string> = {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
};
|
|
22
|
+
private timeout: number = 30000;
|
|
23
|
+
private requestInterceptors: RequestInterceptor[] = [];
|
|
24
|
+
private responseInterceptors: ResponseInterceptor[] = [];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Set base URL
|
|
28
|
+
*/
|
|
29
|
+
setBaseURL(url: string): this {
|
|
30
|
+
this.baseURL = url;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set timeout
|
|
36
|
+
*/
|
|
37
|
+
setTimeout(ms: number): this {
|
|
38
|
+
this.timeout = ms;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Add request interceptor
|
|
44
|
+
*/
|
|
45
|
+
addRequestInterceptor(interceptor: RequestInterceptor): this {
|
|
46
|
+
this.requestInterceptors.push(interceptor);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Add response interceptor
|
|
52
|
+
*/
|
|
53
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): this {
|
|
54
|
+
this.responseInterceptors.push(interceptor);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Make HTTP request
|
|
60
|
+
*/
|
|
61
|
+
async request<T = any>(endpoint: string, options: HttpConfig = {}): Promise<T> {
|
|
62
|
+
const url = this.buildURL(endpoint);
|
|
63
|
+
|
|
64
|
+
let config: HttpConfig = {
|
|
65
|
+
...options,
|
|
66
|
+
headers: {
|
|
67
|
+
...this.defaultHeaders,
|
|
68
|
+
...options.headers,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Apply request interceptors
|
|
73
|
+
for (const interceptor of this.requestInterceptors) {
|
|
74
|
+
config = await interceptor(config);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const response = await this.fetchWithTimeout(url, config, this.timeout);
|
|
79
|
+
|
|
80
|
+
// Apply response interceptors
|
|
81
|
+
let processedResponse = response;
|
|
82
|
+
for (const interceptor of this.responseInterceptors) {
|
|
83
|
+
processedResponse = await interceptor(processedResponse);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const data = await processedResponse.json();
|
|
87
|
+
|
|
88
|
+
if (!processedResponse.ok) {
|
|
89
|
+
throw new Error(data.message || `HTTP ${processedResponse.status}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return data;
|
|
93
|
+
|
|
94
|
+
} catch (error) {
|
|
95
|
+
errorHandler.handleError(error as Error, { endpoint, method: config.method });
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* GET request
|
|
102
|
+
*/
|
|
103
|
+
async get<T = any>(endpoint: string, config: HttpConfig = {}): Promise<T> {
|
|
104
|
+
return this.request<T>(endpoint, { ...config, method: 'GET' });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* POST request
|
|
109
|
+
*/
|
|
110
|
+
async post<T = any>(endpoint: string, data?: any, config: HttpConfig = {}): Promise<T> {
|
|
111
|
+
return this.request<T>(endpoint, {
|
|
112
|
+
...config,
|
|
113
|
+
method: 'POST',
|
|
114
|
+
body: JSON.stringify(data),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* PUT request
|
|
120
|
+
*/
|
|
121
|
+
async put<T = any>(endpoint: string, data?: any, config: HttpConfig = {}): Promise<T> {
|
|
122
|
+
return this.request<T>(endpoint, {
|
|
123
|
+
...config,
|
|
124
|
+
method: 'PUT',
|
|
125
|
+
body: JSON.stringify(data),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* DELETE request
|
|
131
|
+
*/
|
|
132
|
+
async delete<T = any>(endpoint: string, config: HttpConfig = {}): Promise<T> {
|
|
133
|
+
return this.request<T>(endpoint, { ...config, method: 'DELETE' });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* PATCH request
|
|
138
|
+
*/
|
|
139
|
+
async patch<T = any>(endpoint: string, data?: any, config: HttpConfig = {}): Promise<T> {
|
|
140
|
+
return this.request<T>(endpoint, {
|
|
141
|
+
...config,
|
|
142
|
+
method: 'PATCH',
|
|
143
|
+
body: JSON.stringify(data),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Build full URL
|
|
149
|
+
*/
|
|
150
|
+
private buildURL(endpoint: string): string {
|
|
151
|
+
if (endpoint.startsWith('http')) return endpoint;
|
|
152
|
+
return `${this.baseURL}${endpoint}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Fetch with timeout
|
|
157
|
+
*/
|
|
158
|
+
private fetchWithTimeout(url: string, config: HttpConfig, timeout: number): Promise<Response> {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
const timer = setTimeout(() => {
|
|
161
|
+
reject(new Error(`Request timeout after ${timeout}ms`));
|
|
162
|
+
}, timeout);
|
|
163
|
+
|
|
164
|
+
fetch(url, config as RequestInit)
|
|
165
|
+
.then(resolve)
|
|
166
|
+
.catch(reject)
|
|
167
|
+
.finally(() => clearTimeout(timer));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const http = new HttpClient();
|
|
173
|
+
export default http;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component Lazy Loading Registry
|
|
3
|
+
*/
|
|
4
|
+
import { bustCache } from '../utils/cacheBuster.js';
|
|
5
|
+
|
|
6
|
+
class ComponentRegistry {
|
|
7
|
+
private components = new Map<string, string>();
|
|
8
|
+
private loaded = new Set<string>();
|
|
9
|
+
private observer: MutationObserver | null = null;
|
|
10
|
+
|
|
11
|
+
register(tagName: string, modulePath: string): void {
|
|
12
|
+
this.components.set(tagName, modulePath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async loadComponent(tagName: string): Promise<void> {
|
|
16
|
+
// Check if already loaded or if component is already defined
|
|
17
|
+
if (this.loaded.has(tagName) || customElements.get(tagName)) {
|
|
18
|
+
this.loaded.add(tagName); // Mark as loaded even if prefetched
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const modulePath = this.components.get(tagName);
|
|
23
|
+
if (!modulePath) {
|
|
24
|
+
console.warn(`Component ${tagName} not registered`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const absolutePath = modulePath.startsWith('./')
|
|
30
|
+
? `/dist/components/${modulePath.slice(2)}`
|
|
31
|
+
: modulePath;
|
|
32
|
+
|
|
33
|
+
const finalPath = bustCache(absolutePath);
|
|
34
|
+
await import(finalPath);
|
|
35
|
+
this.loaded.add(tagName);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(`Failed to load component ${tagName}:`, error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async scanAndLoad(root: HTMLElement | Document = document.body): Promise<void> {
|
|
42
|
+
const promises: Promise<void>[] = [];
|
|
43
|
+
|
|
44
|
+
for (const tagName of this.components.keys()) {
|
|
45
|
+
if (!this.loaded.has(tagName)) {
|
|
46
|
+
const elements = root.querySelectorAll(tagName);
|
|
47
|
+
if (elements.length > 0) {
|
|
48
|
+
promises.push(this.loadComponent(tagName));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await Promise.all(promises);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
startObserving(): void {
|
|
57
|
+
if (this.observer) return;
|
|
58
|
+
|
|
59
|
+
this.observer = new MutationObserver((mutations) => {
|
|
60
|
+
for (const mutation of mutations) {
|
|
61
|
+
if (mutation.type === 'childList') {
|
|
62
|
+
mutation.addedNodes.forEach(node => {
|
|
63
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
64
|
+
this.scanAndLoad(node as HTMLElement);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this.observer.observe(document.body, {
|
|
72
|
+
childList: true,
|
|
73
|
+
subtree: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
stopObserving(): void {
|
|
78
|
+
if (this.observer) {
|
|
79
|
+
this.observer.disconnect();
|
|
80
|
+
this.observer = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const componentRegistry = new ComponentRegistry();
|
|
86
|
+
|
|
87
|
+
export async function initLazyComponents(): Promise<void> {
|
|
88
|
+
await componentRegistry.scanAndLoad();
|
|
89
|
+
componentRegistry.startObserving();
|
|
90
|
+
}
|