create-mana 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +28 -2
- package/bin/create-mana.mjs +5 -0
- package/kits/auth/files/src/api/auth.ts +100 -0
- package/kits/auth/files/src/api/profile.ts +48 -0
- package/kits/auth/files/src/api/types.ts +28 -0
- package/kits/auth/files/src/components/AppLayout.mana +31 -0
- package/kits/auth/files/src/components/VerifyBanner.mana +47 -0
- package/kits/auth/files/src/router/routes.ts +31 -0
- package/kits/auth/files/src/shared/events.ts +11 -0
- package/kits/auth/files/src/stores/session.ts +99 -0
- package/kits/auth/files/src/views/ForgotPassword.mana +83 -0
- package/kits/auth/files/src/views/Home.mana +15 -0
- package/kits/auth/files/src/views/Profile.mana +172 -0
- package/kits/auth/files/src/views/Register.mana +86 -0
- package/kits/auth/files/src/views/ResetPassword.mana +90 -0
- package/kits/auth/files/src/views/SignIn.mana +84 -0
- package/kits/auth/files/src/views/VerifyEmail.mana +78 -0
- package/kits/auth/files/tests/auth.test.mjs +93 -0
- package/kits/auth/files/tests/home.test.mjs +38 -0
- package/kits/auth/files/tests/profile.test.mjs +68 -0
- package/kits/auth/files/tests/support/users.mjs +2 -0
- package/kits/auth/kit.json +80 -0
- package/kits/base/files/README.md +39 -0
- package/kits/base/kit.json +7 -0
- package/kits/organisations/files/src/api/auth.ts +124 -0
- package/kits/organisations/files/src/api/members.ts +243 -0
- package/kits/organisations/files/src/api/notifications.ts +63 -0
- package/kits/organisations/files/src/api/organisations.ts +41 -0
- package/kits/organisations/files/src/api/scope.ts +98 -0
- package/kits/organisations/files/src/api/types.ts +72 -0
- package/kits/organisations/files/src/assets/styles/organisations.css +46 -0
- package/kits/organisations/files/src/components/AppLayout.mana +90 -0
- package/kits/organisations/files/src/components/NotificationBell.mana +35 -0
- package/kits/organisations/files/src/components/NotificationList.mana +112 -0
- package/kits/organisations/files/src/components/OrganisationSwitcher.mana +171 -0
- package/kits/organisations/files/src/composables/notifications.ts +28 -0
- package/kits/organisations/files/src/router/routes.ts +43 -0
- package/kits/organisations/files/src/shared/roles.ts +10 -0
- package/kits/organisations/files/src/stores/notifications.ts +41 -0
- package/kits/organisations/files/src/stores/session.ts +158 -0
- package/kits/organisations/files/src/utilities/format.ts +15 -0
- package/kits/organisations/files/src/views/Forbidden.mana +28 -0
- package/kits/organisations/files/src/views/Home.mana +15 -0
- package/kits/organisations/files/src/views/Invite.mana +156 -0
- package/kits/organisations/files/src/views/InviteMember.mana +99 -0
- package/kits/organisations/files/src/views/Members.mana +218 -0
- package/kits/organisations/files/src/views/NoOrganisation.mana +184 -0
- package/kits/organisations/files/src/views/Notifications.mana +30 -0
- package/kits/organisations/files/src/views/OrganisationForm.mana +76 -0
- package/kits/organisations/files/src/views/OrganisationSettings.mana +62 -0
- package/kits/organisations/files/src/views/Profile.mana +213 -0
- package/kits/organisations/files/src/views/Register.mana +113 -0
- package/kits/organisations/files/tests/auth.test.mjs +82 -0
- package/kits/organisations/files/tests/home.test.mjs +43 -0
- package/kits/organisations/files/tests/members.test.mjs +89 -0
- package/kits/organisations/files/tests/notifications.test.mjs +49 -0
- package/kits/organisations/files/tests/organisations.test.mjs +70 -0
- package/kits/organisations/files/tests/profile.test.mjs +79 -0
- package/kits/organisations/files/tests/support/users.mjs +3 -0
- package/kits/organisations/kit.json +51 -0
- package/lib/compose.mjs +209 -0
- package/lib/new.mjs +161 -0
- package/lib/prompts.mjs +182 -0
- package/package.json +36 -4
- package/template/.nvmrc +1 -0
- package/template/README.md +23 -0
- package/template/_gitignore +25 -0
- package/template/index.html +17 -0
- package/template/package.json +22 -0
- package/template/public/favicon.svg +1 -0
- package/template/public/icons.svg +24 -0
- package/template/src/App.mana +15 -0
- package/template/src/api/ApiError.ts +17 -0
- package/template/src/api/client.ts +116 -0
- package/template/src/assets/styles/main.css +158 -0
- package/template/src/components/AppLogo.mana +20 -0
- package/template/src/components/Button.mana +25 -0
- package/template/src/components/ConfirmHost.mana +43 -0
- package/template/src/components/TextField.mana +60 -0
- package/template/src/components/ToastHost.mana +40 -0
- package/template/src/composables/media.ts +19 -0
- package/template/src/composables/unsaved.ts +29 -0
- package/template/src/main.ts +25 -0
- package/template/src/router/index.ts +14 -0
- package/template/src/router/routes.ts +11 -0
- package/template/src/stores/confirm.ts +45 -0
- package/template/src/stores/toasts.ts +64 -0
- package/template/src/utilities/query.ts +40 -0
- package/template/src/utilities/timers.ts +12 -0
- package/template/src/views/Home.mana +12 -0
- package/template/src/views/NotFound.mana +13 -0
- package/template/tests/home.test.mjs +29 -0
- package/template/tests/support/api.mjs +44 -0
- package/template/tests/support/check.mjs +15 -0
- package/template/tests/support/dom.mjs +45 -0
- package/template/tests/support/paths.mjs +54 -0
- package/template/tests/support/settle.mjs +15 -0
- package/template/tsconfig.json +35 -0
- package/template/vite.config.ts +29 -0
- package/versions.json +3 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* Base and auth styles. */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
--page: #EEF0F3;
|
|
5
|
+
--paper: #FFFFFF;
|
|
6
|
+
--ink: #1C2128;
|
|
7
|
+
--muted: #5B6573;
|
|
8
|
+
--line: #B8C0CC;
|
|
9
|
+
--line-soft: #DDE2E9;
|
|
10
|
+
--fill: #E6E9EE;
|
|
11
|
+
--note: #2B59E0;
|
|
12
|
+
--note-soft: #EAF0FE;
|
|
13
|
+
--danger: #B42318;
|
|
14
|
+
--danger-soft: #FDECEA;
|
|
15
|
+
--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
* { box-sizing: border-box; }
|
|
19
|
+
/* Clear of the top bar, which stays in view (AppLayout sets --topbar-height), when the focus or a link moves the page. */
|
|
20
|
+
html { scroll-padding-top: var(--topbar-height, 0px); }
|
|
21
|
+
[hidden] { display: none !important; }
|
|
22
|
+
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
background: var(--page);
|
|
26
|
+
color: var(--ink);
|
|
27
|
+
font: 15px/1.5 var(--font);
|
|
28
|
+
-webkit-text-size-adjust: 100%;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.sr-only {
|
|
32
|
+
position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
|
|
33
|
+
overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:focus-visible { outline: 2px solid var(--note); outline-offset: 2px; }
|
|
37
|
+
|
|
38
|
+
/* ---------- auth screens ---------- */
|
|
39
|
+
|
|
40
|
+
.auth { width: min(100%, 400px); margin: auto; padding: 36px 20px 44px; }
|
|
41
|
+
|
|
42
|
+
h1 { margin: 0 0 24px; font-size: 24px; line-height: 1.25; font-weight: 700; }
|
|
43
|
+
|
|
44
|
+
.field { display: grid; align-content: start; gap: 6px; margin-bottom: 16px; }
|
|
45
|
+
label, .label { font-size: 14px; font-weight: 600; }
|
|
46
|
+
|
|
47
|
+
input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], select {
|
|
48
|
+
width: 100%; height: 42px; padding: 0 12px;
|
|
49
|
+
border: 1.5px solid var(--line); border-radius: 3px;
|
|
50
|
+
background: #fff; color: var(--ink); font: inherit;
|
|
51
|
+
}
|
|
52
|
+
input::placeholder { color: #8A93A0; }
|
|
53
|
+
input:focus-visible { outline: 2px solid var(--note); outline-offset: 1px; border-color: var(--ink); }
|
|
54
|
+
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
|
|
55
|
+
select:focus-visible { outline: 2px solid var(--note); outline-offset: 1px; border-color: var(--ink); }
|
|
56
|
+
|
|
57
|
+
.hint { margin: 0; color: var(--muted); font-size: 13px; }
|
|
58
|
+
.field:has(.error:not([hidden])) .hint { display: none; }
|
|
59
|
+
.error { margin: 0; color: var(--danger); font-size: 13px; }
|
|
60
|
+
|
|
61
|
+
.alert {
|
|
62
|
+
margin-bottom: 16px; padding: 10px 12px;
|
|
63
|
+
border: 1.5px solid var(--danger); border-radius: 3px;
|
|
64
|
+
background: var(--danger-soft); font-size: 14px;
|
|
65
|
+
}
|
|
66
|
+
.alert a { color: var(--ink); font-weight: 600; }
|
|
67
|
+
|
|
68
|
+
.notice {
|
|
69
|
+
margin-bottom: 16px; padding: 10px 12px;
|
|
70
|
+
border: 1.5px solid var(--ink); border-radius: 3px;
|
|
71
|
+
background: var(--fill); font-size: 14px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.notice a { color: var(--ink); font-weight: 600; }
|
|
75
|
+
|
|
76
|
+
.lead { margin: -12px 0 20px; color: var(--muted); }
|
|
77
|
+
|
|
78
|
+
.check { display: inline-flex; align-items: baseline; gap: 8px; cursor: pointer; font-size: 14px; }
|
|
79
|
+
.check input { accent-color: var(--ink); width: 15px; height: 15px; margin: 0; flex: none; transform: translateY(2px); }
|
|
80
|
+
.check a { color: var(--ink); font-weight: 600; text-underline-offset: 2px; }
|
|
81
|
+
|
|
82
|
+
.link, .switch a { color: var(--ink); font-weight: 600; text-underline-offset: 2px; }
|
|
83
|
+
.link { font-size: 13px; }
|
|
84
|
+
|
|
85
|
+
.submit { position: relative; margin-top: 8px; }
|
|
86
|
+
.btn {
|
|
87
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
|
|
88
|
+
height: 44px; padding: 0 16px;
|
|
89
|
+
border: 1.5px solid var(--ink); border-radius: 3px;
|
|
90
|
+
background: transparent; color: var(--ink);
|
|
91
|
+
font: inherit; font-weight: 600; cursor: pointer;
|
|
92
|
+
}
|
|
93
|
+
.btn.primary { width: 100%; background: var(--ink); color: #fff; }
|
|
94
|
+
.btn:disabled { background: var(--muted); border-color: var(--muted); color: #fff; cursor: progress; }
|
|
95
|
+
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
|
|
96
|
+
.link-button.danger { color: var(--danger); }
|
|
97
|
+
.btn.danger-outline { border-color: var(--danger); color: var(--danger); }
|
|
98
|
+
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
|
|
99
|
+
|
|
100
|
+
.spin {
|
|
101
|
+
display: none; width: 14px; height: 14px;
|
|
102
|
+
border: 2px solid #fff; border-right-color: transparent; border-radius: 50%;
|
|
103
|
+
animation: spin .8s linear infinite;
|
|
104
|
+
}
|
|
105
|
+
.is-submitting .spin { display: inline-block; }
|
|
106
|
+
.spin.dark { display: inline-block; margin-right: 8px; border-color: var(--ink); border-right-color: transparent; vertical-align: -2px; }
|
|
107
|
+
.is-submitting .field { opacity: .6; pointer-events: none; }
|
|
108
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
109
|
+
|
|
110
|
+
.switch { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
|
|
111
|
+
|
|
112
|
+
/* ---------- signed-in layout, ---------- */
|
|
113
|
+
|
|
114
|
+
#app { min-height: 100vh; display: flex; flex-direction: column; }
|
|
115
|
+
|
|
116
|
+
.spacer { flex: 1; }
|
|
117
|
+
.user { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
|
|
118
|
+
|
|
119
|
+
.form-narrow { max-width: 520px; }
|
|
120
|
+
.form-narrow + .form-narrow { margin-top: 16px; }
|
|
121
|
+
|
|
122
|
+
.banner {
|
|
123
|
+
display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
|
|
124
|
+
margin: 16px 16px 0; padding: 10px 12px;
|
|
125
|
+
border: 1.5px solid var(--ink); border-radius: 3px; background: var(--fill);
|
|
126
|
+
font-size: 14px;
|
|
127
|
+
}
|
|
128
|
+
.banner p { margin: 0; }
|
|
129
|
+
.close {
|
|
130
|
+
width: 28px; height: 28px; border: 0; border-radius: 3px; background: none;
|
|
131
|
+
color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer;
|
|
132
|
+
}
|
|
133
|
+
.close:hover { background: var(--line-soft); }
|
|
134
|
+
|
|
135
|
+
/* ---------- dialogs ---------- */
|
|
136
|
+
|
|
137
|
+
dialog.dialog { width: min(calc(100% - 32px), 480px); max-height: calc(100% - 32px); padding: 0; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--paper); color: var(--ink); box-shadow: 0 8px 0 rgba(28, 33, 40, .12); }
|
|
138
|
+
dialog.dialog::backdrop { background: rgba(28, 33, 40, .45); }
|
|
139
|
+
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1.5px solid var(--line); }
|
|
140
|
+
.dialog-head h2 { margin: 0; font-size: 17px; }
|
|
141
|
+
.dialog-body { padding: 14px 16px 2px; }
|
|
142
|
+
.dialog-text { margin: 0 0 12px; }
|
|
143
|
+
.dialog-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1.5px solid var(--line); }
|
|
144
|
+
.dialog-foot .btn { width: auto; height: 36px; padding: 0 14px; font-size: 14px; }
|
|
145
|
+
.optional { color: var(--muted); font-weight: 400; }
|
|
146
|
+
select, textarea { width: 100%; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); font: inherit; }
|
|
147
|
+
textarea { height: 72px; padding: 8px 12px; resize: vertical; }
|
|
148
|
+
select:disabled { background: var(--fill); color: var(--muted); }
|
|
149
|
+
textarea:focus-visible { outline: 2px solid var(--note); outline-offset: 1px; border-color: var(--ink); }
|
|
150
|
+
|
|
151
|
+
/* What the starter's own pages use. */
|
|
152
|
+
.muted { color: var(--muted); }
|
|
153
|
+
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: var(--fill); padding: 1px 4px; border-radius: 3px; }
|
|
154
|
+
.page { padding: 20px; max-width: 960px; width: 100%; margin: 0 auto; }
|
|
155
|
+
|
|
156
|
+
@media (prefers-reduced-motion: reduce) {
|
|
157
|
+
.spin { animation: none; }
|
|
158
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The the app logo: a placeholder box until there's a real one.
|
|
3
|
+
|
|
4
|
+
Receives nothing from its parent and has no state, which makes it the
|
|
5
|
+
simplest possible component: a template, and its own styles.
|
|
6
|
+
-->
|
|
7
|
+
<template>
|
|
8
|
+
<div class="logo-ph" aria-hidden="true"></div>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<style scoped>
|
|
12
|
+
.logo-ph {
|
|
13
|
+
width: 40px; height: 40px; margin-bottom: 20px;
|
|
14
|
+
border: 1.5px solid var(--ink);
|
|
15
|
+
background:
|
|
16
|
+
linear-gradient(to top right, transparent calc(50% - .75px), var(--ink) 50%, transparent calc(50% + .75px)),
|
|
17
|
+
linear-gradient(to bottom right, transparent calc(50% - .75px), var(--ink) 50%, transparent calc(50% + .75px));
|
|
18
|
+
}
|
|
19
|
+
.logo-ph.sm { width: 28px; height: 28px; margin: 0; }
|
|
20
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* A plain button.
|
|
4
|
+
*
|
|
5
|
+
* Its template uses the native <button>. Lowercase tags look for an element
|
|
6
|
+
* before a component, so that tag can't resolve back to this component.
|
|
7
|
+
*
|
|
8
|
+
* Everything comes from its parent as props, and the template reads them
|
|
9
|
+
* directly, so its script only declares them. `label` is a prop for now,
|
|
10
|
+
* since there's no way yet to pass markup into a component.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
withDefaults(defineProps<{
|
|
14
|
+
type?: "button" | "submit" | "reset";
|
|
15
|
+
label?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}>(), {
|
|
18
|
+
type: "button",
|
|
19
|
+
label: "",
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<button class="btn primary" :type="type" :disabled="disabled">{{ label }}</button>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Shows confirmStore's question as a native <dialog>: an
|
|
4
|
+
* alertdialog with its title and text, Cancel (or what the question calls
|
|
5
|
+
* it) and the confirming button, red for something that can't be undone.
|
|
6
|
+
* Closing it any other way (Escape, ×) answers no. It's in App, beside the
|
|
7
|
+
* toasts, so any page can ask.
|
|
8
|
+
*/
|
|
9
|
+
import { ref, watch } from "@mana-js/mana";
|
|
10
|
+
|
|
11
|
+
import { useConfirm } from "@/stores/confirm";
|
|
12
|
+
|
|
13
|
+
defineOptions({ name: "ConfirmHost" });
|
|
14
|
+
|
|
15
|
+
const confirmStore = useConfirm();
|
|
16
|
+
const open = ref(false);
|
|
17
|
+
|
|
18
|
+
// The question opens the dialog, and the answer closes it; the dialog closing itself is a no.
|
|
19
|
+
watch(() => confirmStore.current, question => open.value = question != null);
|
|
20
|
+
watch(open, isOpen => {
|
|
21
|
+
if(!isOpen && confirmStore.current)
|
|
22
|
+
confirmStore.answer(false);
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<dialog class="dialog" role="alertdialog" aria-labelledby="confirm-title" aria-describedby="confirm-text" m-model="open">
|
|
28
|
+
<div class="dialog-head">
|
|
29
|
+
<h2 id="confirm-title">{{ confirmStore.current?.title }}</h2>
|
|
30
|
+
<button type="button" class="close" aria-label="Close" @click="confirmStore.answer(false)">×</button>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<div class="dialog-body">
|
|
34
|
+
<p class="dialog-text" id="confirm-text">{{ confirmStore.current?.text }}</p>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div class="dialog-foot">
|
|
38
|
+
<div class="spacer"></div>
|
|
39
|
+
<button type="button" class="btn" @click="confirmStore.answer(false)">{{ confirmStore.current?.cancel ?? "Cancel" }}</button>
|
|
40
|
+
<button type="button" class="btn" :class="{ danger: confirmStore.current?.danger, primary: !confirmStore.current?.danger }" @click="confirmStore.answer(true)">{{ confirmStore.current?.confirm }}</button>
|
|
41
|
+
</div>
|
|
42
|
+
</dialog>
|
|
43
|
+
</template>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* A labelled input with an optional hint and its error message underneath
|
|
4
|
+
* (the error takes the hint's place). With type="password"
|
|
5
|
+
* it adds a Show/Hide toggle; each instance keeps its own revealed state, so
|
|
6
|
+
* two password fields on one page toggle independently.
|
|
7
|
+
*
|
|
8
|
+
* Props: id, label (required), type ("text" by default), name, autocomplete,
|
|
9
|
+
* placeholder, hint and error. Its value is what m-model on the tag fills
|
|
10
|
+
* (defineModel(), F14), which the input's own m-model reads and writes.
|
|
11
|
+
*
|
|
12
|
+
* The "action" slot puts something at the end of the label row (a "Forgot
|
|
13
|
+
* password?" link, say).
|
|
14
|
+
*
|
|
15
|
+
* The script holds what this component owns: `revealed`, and its value.
|
|
16
|
+
*/
|
|
17
|
+
import { ref } from "@mana-js/mana";
|
|
18
|
+
|
|
19
|
+
withDefaults(defineProps<{
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
autocomplete?: string;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
hint?: string;
|
|
27
|
+
error?: string | null;
|
|
28
|
+
}>(), {
|
|
29
|
+
type: "text",
|
|
30
|
+
});
|
|
31
|
+
const value = defineModel<string>({ default: "" });
|
|
32
|
+
|
|
33
|
+
const revealed = ref(false);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<div class="field">
|
|
38
|
+
<div class="label-row">
|
|
39
|
+
<label :for="id">{{ label }}</label>
|
|
40
|
+
<slot name="action"></slot>
|
|
41
|
+
</div>
|
|
42
|
+
<div :class="{ pw: type === 'password' }">
|
|
43
|
+
<input :id="id" :name="name" :type="revealed ? 'text' : type" :autocomplete="autocomplete" :placeholder="placeholder" :spellcheck="type === 'text'" :aria-describedby="(hint ? id + '-hint ' : '') + id + '-error'" :aria-invalid="!!error" m-model="value">
|
|
44
|
+
<button type="button" class="pw-toggle" m-if="type === 'password'" :aria-pressed="revealed" :aria-label="revealed ? 'Hide password' : 'Show password'" @click="revealed = !revealed;">{{ revealed ? 'Hide' : 'Show' }}</button>
|
|
45
|
+
</div>
|
|
46
|
+
<p class="hint" :id="id + '-hint'" m-if="hint">{{ hint }}</p>
|
|
47
|
+
<p class="error" :id="id + '-error'" m-if="error">{{ error }}</p>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<style scoped>
|
|
52
|
+
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
|
|
53
|
+
.pw { position: relative; }
|
|
54
|
+
.pw input { padding-right: 68px; }
|
|
55
|
+
.pw-toggle {
|
|
56
|
+
position: absolute; top: 5px; right: 5px; height: 32px; padding: 0 10px;
|
|
57
|
+
border: 0; border-radius: 3px; background: var(--fill); color: var(--ink);
|
|
58
|
+
font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Where toasts show: the top right of the window, over everything. It
|
|
4
|
+
* sits in App, but renders into <body> through <Teleport>, so no page's
|
|
5
|
+
* overflow or stacking can hide it.
|
|
6
|
+
*/
|
|
7
|
+
import { useToasts } from "@/stores/toasts";
|
|
8
|
+
|
|
9
|
+
const toastStore = useToasts();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<Teleport to="body">
|
|
14
|
+
<div class="toasts" role="region" aria-label="Notifications">
|
|
15
|
+
<div class="toast" role="alert" m-for="toast in toastStore.items" :key="toast.id">
|
|
16
|
+
<div>
|
|
17
|
+
<strong>{{ toast.title }}</strong>
|
|
18
|
+
<p m-if="toast.text">{{ toast.text }}</p>
|
|
19
|
+
<RouterLink m-if="toast.action" :to="toast.action.to">{{ toast.action.label }}</RouterLink>
|
|
20
|
+
</div>
|
|
21
|
+
<button type="button" aria-label="Dismiss" @click="toastStore.dismiss(toast.id)">×</button>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</Teleport>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<style scoped>
|
|
28
|
+
.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: grid; gap: 8px; width: min(340px, calc(100vw - 32px)); }
|
|
29
|
+
.toast {
|
|
30
|
+
display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
|
|
31
|
+
padding: 12px 14px; border-radius: 3px;
|
|
32
|
+
background: var(--ink); color: #fff; font-size: 14px;
|
|
33
|
+
}
|
|
34
|
+
.toast p { margin: 4px 0 0; }
|
|
35
|
+
.toast a { display: inline-block; margin-top: 6px; color: #fff; font-weight: 600; text-underline-offset: 2px; }
|
|
36
|
+
.toast button {
|
|
37
|
+
flex: none; width: 24px; height: 24px; border: 0; background: none;
|
|
38
|
+
color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Whether a CSS media query matches, for a component that lays something out
|
|
3
|
+
* in code (the dashboard's chart): a ref that follows the query until the
|
|
4
|
+
* component goes. Where there's no matchMedia (tests), it never matches.
|
|
5
|
+
*/
|
|
6
|
+
import { onUnmounted, ref } from "@mana-js/mana";
|
|
7
|
+
|
|
8
|
+
export function useMediaQuery(query: string) {
|
|
9
|
+
const list = typeof window.matchMedia == "function" ? window.matchMedia(query) : null;
|
|
10
|
+
const matches = ref(list?.matches ?? false);
|
|
11
|
+
const update = (event: MediaQueryListEvent) => {
|
|
12
|
+
matches.value = event.matches;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
list?.addEventListener("change", update);
|
|
16
|
+
onUnmounted(() => list?.removeEventListener("change", update));
|
|
17
|
+
|
|
18
|
+
return matches;
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Asks before a form's changes are lost: leaving its page within the app
|
|
3
|
+
* asks in a dialog (a leave guard, C18), and reloading or closing the tab
|
|
4
|
+
* gets the browser's own prompt (beforeunload, which no router sees). Called
|
|
5
|
+
* in a page's setup() with what says whether there are changes:
|
|
6
|
+
* useUnsavedChanges(() => form.name != saved.name)
|
|
7
|
+
*/
|
|
8
|
+
import { onBeforeRouteLeave, onUnmounted } from "@mana-js/mana";
|
|
9
|
+
|
|
10
|
+
import { useConfirm } from "@/stores/confirm";
|
|
11
|
+
|
|
12
|
+
export function useUnsavedChanges(changed: () => boolean) {
|
|
13
|
+
const confirmStore = useConfirm();
|
|
14
|
+
|
|
15
|
+
onBeforeRouteLeave(() => !changed() || confirmStore.ask({
|
|
16
|
+
title: "Leave without saving?",
|
|
17
|
+
text: "Your changes on this page haven't been saved. If you leave, they're lost.",
|
|
18
|
+
confirm: "Leave",
|
|
19
|
+
cancel: "Stay",
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
function unload(event: BeforeUnloadEvent) {
|
|
23
|
+
if(changed())
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
window.addEventListener("beforeunload", unload);
|
|
28
|
+
onUnmounted(() => window.removeEventListener("beforeunload", unload));
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp, createEvents, createStores } from "@mana-js/mana";
|
|
2
|
+
|
|
3
|
+
import App from "@/App.mana";
|
|
4
|
+
import router from "@/router";
|
|
5
|
+
// @mana:imports
|
|
6
|
+
|
|
7
|
+
import "@/assets/styles/main.css";
|
|
8
|
+
|
|
9
|
+
void setup();
|
|
10
|
+
|
|
11
|
+
async function setup() {
|
|
12
|
+
const app = createApp(App);
|
|
13
|
+
const events = createEvents();
|
|
14
|
+
|
|
15
|
+
app.use(createStores());
|
|
16
|
+
app.use(events);
|
|
17
|
+
|
|
18
|
+
// @mana:setup
|
|
19
|
+
|
|
20
|
+
app.use(router);
|
|
21
|
+
|
|
22
|
+
// @mana:ready
|
|
23
|
+
|
|
24
|
+
app.mount("#app");
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The router: the routes are in ./routes.ts, and the middleware they list is registered below (`router.middleware("auth", to => …)`), each one given the route going to and answering where to go
|
|
3
|
+
* instead, or nothing to let it through.
|
|
4
|
+
*/
|
|
5
|
+
import { createRouter } from "@mana-js/mana";
|
|
6
|
+
|
|
7
|
+
import routes from "@/router/routes";
|
|
8
|
+
// @mana:imports
|
|
9
|
+
|
|
10
|
+
const router = createRouter({ routes });
|
|
11
|
+
|
|
12
|
+
// @mana:middleware
|
|
13
|
+
|
|
14
|
+
export default router;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The pages, with Laravel-style routes. Each has a name, which links and redirects use instead of its path (`router.url("dashboard")`, `{ name: "dashboard" }`), and may list middleware, registered in
|
|
3
|
+
* ./index.ts. Each page is loaded when it's first visited, so the first download stays small: `component: () => import("@/views/Page.mana")`. The last route is the page for an address with no page.
|
|
4
|
+
*/
|
|
5
|
+
import HomeView from "@/views/Home.mana";
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
{ path: "/", name: "dashboard", component: HomeView },
|
|
9
|
+
// @mana:routes
|
|
10
|
+
{ path: "/{path}", name: "not-found", where: { path: ".*" }, component: () => import("@/views/NotFound.mana") },
|
|
11
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Questions the app asks before it does something: leaving a page
|
|
3
|
+
* with unsaved changes, removing someone, transferring ownership. A page
|
|
4
|
+
* awaits confirmStore.ask({ title, text, confirm }), which ConfirmHost shows
|
|
5
|
+
* as a dialog and settles true or false. Asking again while a question
|
|
6
|
+
* is open answers the open one no.
|
|
7
|
+
*/
|
|
8
|
+
import { defineStore, ref } from "@mana-js/mana";
|
|
9
|
+
|
|
10
|
+
export interface Confirmation {
|
|
11
|
+
title: string;
|
|
12
|
+
text: string;
|
|
13
|
+
confirm: string;
|
|
14
|
+
cancel?: string;
|
|
15
|
+
danger?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useConfirm = defineStore("confirm", () => {
|
|
19
|
+
const current = ref<Confirmation | null>(null);
|
|
20
|
+
// The answer the open question is waiting for.
|
|
21
|
+
let settle: ((answer: boolean) => void) | null = null;
|
|
22
|
+
|
|
23
|
+
function ask(confirmation: Confirmation) {
|
|
24
|
+
answer(false);
|
|
25
|
+
current.value = confirmation;
|
|
26
|
+
|
|
27
|
+
return new Promise<boolean>(resolve => {
|
|
28
|
+
settle = resolve;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function answer(yes: boolean) {
|
|
33
|
+
const pending = settle;
|
|
34
|
+
|
|
35
|
+
settle = null;
|
|
36
|
+
current.value = null;
|
|
37
|
+
pending?.(yes);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
current,
|
|
42
|
+
ask,
|
|
43
|
+
answer,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Toasts: rejections that aren't about one field (wrong credentials, an
|
|
3
|
+
* expired link, a request that failed) show as a toast; field errors stay
|
|
4
|
+
* under their fields. ToastHost renders them, outside the page.
|
|
5
|
+
*
|
|
6
|
+
* A toast stays until it's dismissed, the page tries again (clear()), or the
|
|
7
|
+
* app moves to another page: a page's toasts are about that page.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
defineStore,
|
|
11
|
+
reactive,
|
|
12
|
+
readonly,
|
|
13
|
+
useRouter,
|
|
14
|
+
watch,
|
|
15
|
+
} from "@mana-js/mana";
|
|
16
|
+
|
|
17
|
+
// A way on from a toast, such as "Ask for a new link" on an expired one.
|
|
18
|
+
export interface ToastAction {
|
|
19
|
+
label: string;
|
|
20
|
+
to: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Toast {
|
|
24
|
+
id: number;
|
|
25
|
+
title: string;
|
|
26
|
+
text: string | null;
|
|
27
|
+
action: ToastAction | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const useToasts = defineStore("toasts", () => {
|
|
31
|
+
const router = useRouter();
|
|
32
|
+
const items = reactive<Toast[]>([]);
|
|
33
|
+
let next = 1;
|
|
34
|
+
|
|
35
|
+
// Shows an error and returns its id, for dismiss().
|
|
36
|
+
function error(title: string, text: string | null = null, action: ToastAction | null = null) {
|
|
37
|
+
const id = next++;
|
|
38
|
+
|
|
39
|
+
items.push({ id, title, text, action });
|
|
40
|
+
|
|
41
|
+
return id;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function dismiss(id: number) {
|
|
45
|
+
const index = items.findIndex(toast => toast.id == id);
|
|
46
|
+
|
|
47
|
+
if(index != -1)
|
|
48
|
+
items.splice(index, 1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function clear() {
|
|
52
|
+
items.splice(0);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A page's toasts go with it.
|
|
56
|
+
watch(() => router.route.path, () => clear());
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
items: readonly(items),
|
|
60
|
+
error,
|
|
61
|
+
dismiss,
|
|
62
|
+
clear,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Reading and writing filters kept in the URL's query: a list's
|
|
3
|
+
* dates and page, so a filtered list can be bookmarked, and back and forward
|
|
4
|
+
* restore it. Anything malformed in the query is left out.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
8
|
+
|
|
9
|
+
// A day ("2026-10-01"), or null.
|
|
10
|
+
export function dateParam(value: string | undefined) {
|
|
11
|
+
return value && DATE.test(value) ? value : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// A page, from 1.
|
|
15
|
+
export function pageParam(value: string | undefined) {
|
|
16
|
+
const page = Number(value);
|
|
17
|
+
|
|
18
|
+
return Number.isInteger(page) && page > 1 ? page : 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The query for some values: only those that are set, and the first page left out.
|
|
22
|
+
export function queryOf(values: Readonly<Record<string, string | number | null>>) {
|
|
23
|
+
const query: Record<string, string> = {};
|
|
24
|
+
|
|
25
|
+
for(const [name, value] of Object.entries(values)) {
|
|
26
|
+
if(value === null || value === "" || (name == "page" && value == 1))
|
|
27
|
+
continue;
|
|
28
|
+
|
|
29
|
+
query[name] = String(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return query;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Whether two queries say the same.
|
|
36
|
+
export function sameQuery(a: Readonly<Record<string, string>>, b: Readonly<Record<string, string>>) {
|
|
37
|
+
const keys = Object.keys(a);
|
|
38
|
+
|
|
39
|
+
return keys.length == Object.keys(b).length && keys.every(key => a[key] === b[key]);
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Timers that don't keep a process alive: in Node (a suite) an interval or a timeout does, and the suite would never end; in a browser
|
|
3
|
+
* they're numbers, with nothing to do.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// The timer, set not to hold a Node process open.
|
|
7
|
+
export function unreffed<T>(timer: T): T {
|
|
8
|
+
if(typeof timer == "object" && timer !== null && "unref" in timer && typeof timer.unref == "function")
|
|
9
|
+
Reflect.apply(timer.unref, timer, []);
|
|
10
|
+
|
|
11
|
+
return timer;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* The home page: a greeting, to replace with your own first page.
|
|
4
|
+
*/
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<main class="page">
|
|
9
|
+
<h1>Mana Starter</h1>
|
|
10
|
+
<p class="muted">This is the page to start from: <code>src/views/Home.mana</code>. Its route is in <code>src/router/routes.ts</code>.</p>
|
|
11
|
+
</main>
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* A page that isn't one: said so, with the way back.
|
|
4
|
+
*/
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<div class="auth">
|
|
9
|
+
<h1>Page not found</h1>
|
|
10
|
+
<p class="lead">There's nothing at this address.</p>
|
|
11
|
+
<p class="switch"><RouterLink to="/">Go to the home page</RouterLink></p>
|
|
12
|
+
</div>
|
|
13
|
+
</template>
|