create-middag-ui 0.3.3 → 0.4.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/lib/scaffold.js +86 -8
- package/package.json +1 -1
package/lib/scaffold.js
CHANGED
|
@@ -158,6 +158,8 @@ export default defineConfig({
|
|
|
158
158
|
alias: {
|
|
159
159
|
"@/": resolve(__dirname, "src") + "/",
|
|
160
160
|
"@mock/": resolve(__dirname, "mock") + "/",
|
|
161
|
+
"@inertiajs/react": resolve(__dirname, "mock/adapters/inertia-react.ts"),
|
|
162
|
+
"@inertiajs/core": resolve(__dirname, "mock/adapters/inertia-core.ts"),
|
|
161
163
|
},
|
|
162
164
|
},
|
|
163
165
|
});
|
|
@@ -295,7 +297,7 @@ export function scaffoldMockFiles(targetDir) {
|
|
|
295
297
|
* Replace this with real data from your server.
|
|
296
298
|
*/
|
|
297
299
|
export const helloContract: PageContract = {
|
|
298
|
-
shell: "
|
|
300
|
+
shell: "product",
|
|
299
301
|
meta: {
|
|
300
302
|
title: "Hello MIDDAG",
|
|
301
303
|
breadcrumbs: [
|
|
@@ -314,7 +316,6 @@ export const helloContract: PageContract = {
|
|
|
314
316
|
title: "Setup Complete",
|
|
315
317
|
value: "1",
|
|
316
318
|
subtitle: "@middag-io/react is working",
|
|
317
|
-
trend: { direction: "up", value: "100%", label: "Ready" },
|
|
318
319
|
},
|
|
319
320
|
},
|
|
320
321
|
{
|
|
@@ -332,7 +333,7 @@ export const helloContract: PageContract = {
|
|
|
332
333
|
{ id: 2, name: "Second item", status: "Draft" },
|
|
333
334
|
{ id: 3, name: "Third item", status: "Active" },
|
|
334
335
|
],
|
|
335
|
-
pagination: {
|
|
336
|
+
pagination: { page: 1, totalPages: 1, perPage: 10, totalRows: 3 },
|
|
336
337
|
},
|
|
337
338
|
},
|
|
338
339
|
],
|
|
@@ -353,7 +354,6 @@ export const helloContract: PageContract = {
|
|
|
353
354
|
import { createRoot } from "react-dom/client";
|
|
354
355
|
import { ContractPage, registerDefaults } from "@middag-io/react";
|
|
355
356
|
import "@middag-io/react/style.css";
|
|
356
|
-
import "./tailwind.css";
|
|
357
357
|
import { helloContract } from "./hello-contract";
|
|
358
358
|
|
|
359
359
|
// Register all default shells, layouts, and blocks
|
|
@@ -391,9 +391,87 @@ createRoot(document.getElementById("root")!).render(
|
|
|
391
391
|
);
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
// mock/
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
394
|
+
// mock/adapters/inertia-react.ts
|
|
395
|
+
const adaptersDir = join(mockDir, "adapters");
|
|
396
|
+
ensureDir(adaptersDir);
|
|
397
|
+
|
|
398
|
+
const inertiaReactPath = join(adaptersDir, "inertia-react.ts");
|
|
399
|
+
if (!skipIfExists(inertiaReactPath, "mock/adapters/inertia-react.ts")) {
|
|
400
|
+
writeFile(
|
|
401
|
+
inertiaReactPath,
|
|
402
|
+
`/**
|
|
403
|
+
* Mock @inertiajs/react \u2014 standalone adapter for mock dev server.
|
|
404
|
+
* Vite alias redirects @inertiajs/react imports here.
|
|
405
|
+
*/
|
|
406
|
+
import { createElement, forwardRef, useEffect, type ReactNode, type AnchorHTMLAttributes } from "react";
|
|
407
|
+
import { router } from "./inertia-core";
|
|
408
|
+
|
|
409
|
+
const mockSharedProps = {
|
|
410
|
+
navigation: { sections: [], activeKey: "" },
|
|
411
|
+
auth: { id: 1, name: "Dev User", email: "dev@localhost", capabilities: [] },
|
|
412
|
+
theme: { appearance: "light" as const },
|
|
413
|
+
flash: {},
|
|
414
|
+
locale: "en",
|
|
415
|
+
version: "0.0.0-mock",
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
export function usePage<T = Record<string, unknown>>(): { props: T; url: string } {
|
|
419
|
+
return { props: mockSharedProps as T, url: window.location.pathname };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export function Head({ title, children }: { title?: string; children?: ReactNode }) {
|
|
423
|
+
useEffect(() => { if (title) document.title = title; }, [title]);
|
|
424
|
+
return children ? createElement("span", { style: { display: "none" } }, children) : null;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface MockLinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
|
|
428
|
+
href?: string;
|
|
429
|
+
method?: string;
|
|
430
|
+
preserveScroll?: boolean;
|
|
431
|
+
preserveState?: boolean;
|
|
432
|
+
as?: string;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export const Link = forwardRef<HTMLAnchorElement, MockLinkProps>(function MockLink(
|
|
436
|
+
{ href, onClick, children, as: _as, method: _m, preserveScroll: _ps, preserveState: _pst, ...rest },
|
|
437
|
+
ref,
|
|
438
|
+
) {
|
|
439
|
+
const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
440
|
+
if (onClick) onClick(e);
|
|
441
|
+
if (e.defaultPrevented) return;
|
|
442
|
+
e.preventDefault();
|
|
443
|
+
if (href) window.location.hash = href;
|
|
444
|
+
};
|
|
445
|
+
return createElement("a", { ...rest, href: href ?? "#", ref, onClick: handleClick }, children);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
export { router };
|
|
449
|
+
`,
|
|
450
|
+
"mock/adapters/inertia-react.ts",
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// mock/adapters/inertia-core.ts
|
|
455
|
+
const inertiaCorePathFile = join(adaptersDir, "inertia-core.ts");
|
|
456
|
+
if (!skipIfExists(inertiaCorePathFile, "mock/adapters/inertia-core.ts")) {
|
|
457
|
+
writeFile(
|
|
458
|
+
inertiaCorePathFile,
|
|
459
|
+
`/**
|
|
460
|
+
* Mock @inertiajs/core \u2014 standalone adapter for mock dev server.
|
|
461
|
+
* Vite alias redirects @inertiajs/core imports here.
|
|
462
|
+
*/
|
|
463
|
+
export const router = {
|
|
464
|
+
get: (url: string) => { window.location.hash = url; },
|
|
465
|
+
post: (url: string) => { console.log("[mock] POST", url); },
|
|
466
|
+
put: (url: string) => { console.log("[mock] PUT", url); },
|
|
467
|
+
patch: (url: string) => { console.log("[mock] PATCH", url); },
|
|
468
|
+
delete: (url: string) => { console.log("[mock] DELETE", url); },
|
|
469
|
+
reload: () => { window.location.reload(); },
|
|
470
|
+
visit: (url: string) => { window.location.hash = url; },
|
|
471
|
+
on: () => () => {},
|
|
472
|
+
};
|
|
473
|
+
`,
|
|
474
|
+
"mock/adapters/inertia-core.ts",
|
|
475
|
+
);
|
|
398
476
|
}
|
|
399
477
|
}
|