zero-query 1.0.9 → 1.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/LICENSE +21 -21
- package/README.md +2 -0
- package/cli/args.js +33 -33
- package/cli/commands/build-api.js +443 -0
- package/cli/commands/build.js +254 -216
- package/cli/commands/bundle.js +1228 -1183
- package/cli/commands/create.js +137 -121
- package/cli/commands/dev/devtools/index.js +56 -56
- package/cli/commands/dev/devtools/js/components.js +49 -49
- package/cli/commands/dev/devtools/js/core.js +423 -423
- package/cli/commands/dev/devtools/js/elements.js +421 -421
- package/cli/commands/dev/devtools/js/network.js +166 -166
- package/cli/commands/dev/devtools/js/performance.js +73 -73
- package/cli/commands/dev/devtools/js/router.js +105 -105
- package/cli/commands/dev/devtools/js/source.js +132 -132
- package/cli/commands/dev/devtools/js/stats.js +35 -35
- package/cli/commands/dev/devtools/js/tabs.js +79 -79
- package/cli/commands/dev/devtools/panel.html +95 -95
- package/cli/commands/dev/devtools/styles.css +244 -244
- package/cli/commands/dev/index.js +107 -107
- package/cli/commands/dev/logger.js +75 -75
- package/cli/commands/dev/overlay.js +858 -858
- package/cli/commands/dev/server.js +220 -167
- package/cli/commands/dev/validator.js +94 -94
- package/cli/commands/dev/watcher.js +172 -172
- package/cli/help.js +114 -112
- package/cli/index.js +52 -52
- package/cli/scaffold/default/LICENSE +21 -21
- package/cli/scaffold/default/app/app.js +207 -207
- package/cli/scaffold/default/app/components/about.js +201 -201
- package/cli/scaffold/default/app/components/api-demo.js +143 -143
- package/cli/scaffold/default/app/components/contact-card.js +231 -231
- package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
- package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
- package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
- package/cli/scaffold/default/app/components/counter.js +127 -127
- package/cli/scaffold/default/app/components/home.js +249 -249
- package/cli/scaffold/default/app/components/not-found.js +16 -16
- package/cli/scaffold/default/app/components/playground/playground.css +115 -115
- package/cli/scaffold/default/app/components/playground/playground.html +161 -161
- package/cli/scaffold/default/app/components/playground/playground.js +116 -116
- package/cli/scaffold/default/app/components/todos.js +225 -225
- package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
- package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
- package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
- package/cli/scaffold/default/app/routes.js +15 -15
- package/cli/scaffold/default/app/store.js +101 -101
- package/cli/scaffold/default/global.css +552 -552
- package/cli/scaffold/default/index.html +99 -99
- package/cli/scaffold/minimal/app/app.js +85 -85
- package/cli/scaffold/minimal/app/components/about.js +68 -68
- package/cli/scaffold/minimal/app/components/counter.js +122 -122
- package/cli/scaffold/minimal/app/components/home.js +68 -68
- package/cli/scaffold/minimal/app/components/not-found.js +16 -16
- package/cli/scaffold/minimal/app/routes.js +9 -9
- package/cli/scaffold/minimal/app/store.js +36 -36
- package/cli/scaffold/minimal/global.css +300 -300
- package/cli/scaffold/minimal/index.html +44 -44
- package/cli/scaffold/ssr/app/app.js +41 -41
- package/cli/scaffold/ssr/app/components/about.js +55 -55
- package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
- package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
- package/cli/scaffold/ssr/app/components/home.js +37 -37
- package/cli/scaffold/ssr/app/components/not-found.js +15 -15
- package/cli/scaffold/ssr/app/routes.js +8 -8
- package/cli/scaffold/ssr/global.css +228 -228
- package/cli/scaffold/ssr/index.html +37 -37
- package/cli/scaffold/ssr/package.json +8 -8
- package/cli/scaffold/ssr/server/data/posts.js +144 -144
- package/cli/scaffold/ssr/server/index.js +213 -213
- package/cli/scaffold/webrtc/app/app.js +11 -0
- package/cli/scaffold/webrtc/app/components/video-room.js +295 -0
- package/cli/scaffold/webrtc/app/lib/room.js +252 -0
- package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
- package/cli/scaffold/webrtc/global.css +250 -0
- package/cli/scaffold/webrtc/index.html +21 -0
- package/cli/utils.js +305 -287
- package/dist/API.md +7264 -0
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +10313 -6252
- package/dist/zquery.min.js +8 -601
- package/index.d.ts +570 -365
- package/index.js +311 -232
- package/package.json +76 -69
- package/src/component.js +1709 -1454
- package/src/core.js +921 -921
- package/src/diff.js +497 -497
- package/src/errors.js +209 -209
- package/src/expression.js +922 -922
- package/src/http.js +242 -242
- package/src/package.json +1 -1
- package/src/reactive.js +255 -254
- package/src/router.js +843 -773
- package/src/ssr.js +418 -418
- package/src/store.js +318 -272
- package/src/utils.js +515 -515
- package/src/webrtc/e2ee.js +351 -0
- package/src/webrtc/errors.js +116 -0
- package/src/webrtc/ice.js +301 -0
- package/src/webrtc/index.js +131 -0
- package/src/webrtc/joinToken.js +119 -0
- package/src/webrtc/observe.js +172 -0
- package/src/webrtc/peer.js +351 -0
- package/src/webrtc/reactive.js +268 -0
- package/src/webrtc/room.js +625 -0
- package/src/webrtc/sdp.js +302 -0
- package/src/webrtc/sfu/index.js +43 -0
- package/src/webrtc/sfu/livekit.js +131 -0
- package/src/webrtc/sfu/mediasoup.js +150 -0
- package/src/webrtc/signaling.js +373 -0
- package/src/webrtc/turn.js +237 -0
- package/tests/_helpers/webrtcFakes.js +289 -0
- package/tests/audit.test.js +4158 -4158
- package/tests/cli.test.js +1136 -1023
- package/tests/compare.test.js +497 -0
- package/tests/component.test.js +3969 -3938
- package/tests/core.test.js +1910 -1910
- package/tests/dev-server.test.js +489 -0
- package/tests/diff.test.js +1416 -1416
- package/tests/docs.test.js +1664 -0
- package/tests/electron-features.test.js +864 -0
- package/tests/errors.test.js +619 -619
- package/tests/expression.test.js +1056 -1056
- package/tests/http.test.js +648 -648
- package/tests/reactive.test.js +819 -819
- package/tests/router.test.js +2327 -2327
- package/tests/ssr.test.js +870 -870
- package/tests/store.test.js +830 -830
- package/tests/test-minifier.js +153 -153
- package/tests/test-ssr.js +27 -27
- package/tests/utils.test.js +1377 -1377
- package/tests/webrtc/e2ee.test.js +283 -0
- package/tests/webrtc/ice.test.js +202 -0
- package/tests/webrtc/joinToken.test.js +89 -0
- package/tests/webrtc/observe.test.js +111 -0
- package/tests/webrtc/peer.test.js +373 -0
- package/tests/webrtc/reactive.test.js +235 -0
- package/tests/webrtc/room.test.js +406 -0
- package/tests/webrtc/sdp.test.js +151 -0
- package/tests/webrtc/sfu-livekit.test.js +119 -0
- package/tests/webrtc/sfu.test.js +160 -0
- package/tests/webrtc/signaling.test.js +251 -0
- package/tests/webrtc/turn.test.js +256 -0
- package/types/collection.d.ts +383 -383
- package/types/component.d.ts +186 -186
- package/types/errors.d.ts +135 -135
- package/types/http.d.ts +92 -92
- package/types/misc.d.ts +201 -201
- package/types/reactive.d.ts +98 -98
- package/types/router.d.ts +190 -190
- package/types/ssr.d.ts +102 -102
- package/types/store.d.ts +146 -145
- package/types/utils.d.ts +245 -245
- package/types/webrtc.d.ts +653 -0
|
@@ -1,196 +1,196 @@
|
|
|
1
|
-
// contacts.js - Contact book page
|
|
2
|
-
//
|
|
3
|
-
// Features used:
|
|
4
|
-
// templateUrl / styleUrl - external template & scoped styles
|
|
5
|
-
// z-if / z-show / z-for - conditional & list rendering
|
|
6
|
-
// z-model / z-ref - form bindings
|
|
7
|
-
// @click / @submit.prevent - event handling
|
|
8
|
-
// @keydown.escape - keyboard modifier
|
|
9
|
-
// $.getStore / dispatch - store integration
|
|
10
|
-
// $.bus.emit('toast') - notifications
|
|
11
|
-
|
|
12
|
-
$.component('contacts-page', {
|
|
13
|
-
templateUrl: 'contacts.html',
|
|
14
|
-
styleUrl: 'contacts.css',
|
|
15
|
-
|
|
16
|
-
state: () => ({
|
|
17
|
-
contacts: [],
|
|
18
|
-
showAddModal: false,
|
|
19
|
-
newName: '',
|
|
20
|
-
newEmail: '',
|
|
21
|
-
newRole: 'Developer',
|
|
22
|
-
newPhone: '',
|
|
23
|
-
newBio: '',
|
|
24
|
-
nameError: '',
|
|
25
|
-
emailError: '',
|
|
26
|
-
modalId: null,
|
|
27
|
-
confirmDeleteId: null,
|
|
28
|
-
totalAdded: 0,
|
|
29
|
-
favoriteCount: 0,
|
|
30
|
-
filterText: '',
|
|
31
|
-
filterRole: '',
|
|
32
|
-
// Derived state (not computed - external templates resolve state only)
|
|
33
|
-
filteredContacts: [],
|
|
34
|
-
modalContact: null,
|
|
35
|
-
}),
|
|
36
|
-
|
|
37
|
-
watch: {
|
|
38
|
-
filterText() { this._recompute(); },
|
|
39
|
-
filterRole() { this._recompute(); },
|
|
40
|
-
modalId() { this._recompute(); },
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
mounted() {
|
|
44
|
-
const store = $.getStore('main');
|
|
45
|
-
this._syncFromStore(store);
|
|
46
|
-
this._unsub = store.subscribe(() => this._syncFromStore(store));
|
|
47
|
-
|
|
48
|
-
// Global Escape handler - template @keydown.escape on overlays is
|
|
49
|
-
// unreliable when no child element has focus (detail modal has no inputs).
|
|
50
|
-
this._onEscape = (e) => {
|
|
51
|
-
if (e.key !== 'Escape') return;
|
|
52
|
-
if (this.state.showAddModal) { this.closeAddModal(); e.stopPropagation(); }
|
|
53
|
-
else if (this.state.modalId != null) { this.closeModal(); e.stopPropagation(); }
|
|
54
|
-
};
|
|
55
|
-
document.addEventListener('keydown', this._onEscape);
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
destroyed() {
|
|
59
|
-
if (this._unsub) this._unsub();
|
|
60
|
-
if (this._onEscape) document.removeEventListener('keydown', this._onEscape);
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
_syncFromStore(store) {
|
|
64
|
-
// Shallow-clone each contact so the framework detects new references
|
|
65
|
-
// (store actions mutate objects in place - same refs won't trigger re-render)
|
|
66
|
-
this.state.contacts = store.state.contacts.map(c => ({ ...c }));
|
|
67
|
-
this.state.totalAdded = store.state.contactsAdded;
|
|
68
|
-
this.state.favoriteCount = store.getters.favoriteCount;
|
|
69
|
-
this._recompute();
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
/** Recalculate derived state from current contacts + filter values. */
|
|
73
|
-
_recompute() {
|
|
74
|
-
let list = this.state.contacts;
|
|
75
|
-
const q = this.state.filterText.toLowerCase();
|
|
76
|
-
if (q) list = list.filter(c => c.name.toLowerCase().includes(q) || c.email.toLowerCase().includes(q));
|
|
77
|
-
if (this.state.filterRole) list = list.filter(c => c.role === this.state.filterRole);
|
|
78
|
-
this.state.filteredContacts = list;
|
|
79
|
-
|
|
80
|
-
this.state.modalContact = this.state.modalId != null
|
|
81
|
-
? this.state.contacts.find(c => c.id === this.state.modalId) || null
|
|
82
|
-
: null;
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
// -- Add-contact modal --
|
|
86
|
-
|
|
87
|
-
openAddModal() {
|
|
88
|
-
this.state.showAddModal = true;
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
closeAddModal() {
|
|
92
|
-
this.state.showAddModal = false;
|
|
93
|
-
this._clearForm();
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
_validateName(name) {
|
|
97
|
-
if (!name) return 'Name is required.';
|
|
98
|
-
if (name.length < 2) return 'At least 2 characters.';
|
|
99
|
-
return '';
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
_validateEmail(email) {
|
|
103
|
-
if (!email) return 'Email is required.';
|
|
104
|
-
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) return 'Enter a valid email.';
|
|
105
|
-
const store = $.getStore('main');
|
|
106
|
-
if (store.state.contacts.some(c => c.email.toLowerCase() === email.toLowerCase())) {
|
|
107
|
-
return 'Email already exists.';
|
|
108
|
-
}
|
|
109
|
-
return '';
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
validateName() {
|
|
113
|
-
this.state.nameError = this._validateName(this.state.newName.trim());
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
validateEmail() {
|
|
117
|
-
this.state.emailError = this._validateEmail(this.state.newEmail.trim());
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
addContact() {
|
|
121
|
-
const name = this.state.newName.trim();
|
|
122
|
-
const email = this.state.newEmail.trim();
|
|
123
|
-
|
|
124
|
-
const nameError = this._validateName(name);
|
|
125
|
-
const emailError = this._validateEmail(email);
|
|
126
|
-
this.state.nameError = nameError;
|
|
127
|
-
this.state.emailError = emailError;
|
|
128
|
-
if (nameError || emailError) return;
|
|
129
|
-
|
|
130
|
-
$.getStore('main').dispatch('addContact', {
|
|
131
|
-
name,
|
|
132
|
-
email,
|
|
133
|
-
role: this.state.newRole,
|
|
134
|
-
phone: this.state.newPhone.trim(),
|
|
135
|
-
bio: this.state.newBio.trim(),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
this._clearForm();
|
|
139
|
-
this.state.showAddModal = false;
|
|
140
|
-
$.bus.emit('toast', { message: `${name} added!`, type: 'success' });
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
// -- Detail modal --
|
|
144
|
-
|
|
145
|
-
openModal(id) {
|
|
146
|
-
this.state.modalId = Number(id);
|
|
147
|
-
this.state.confirmDeleteId = null;
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
closeModal() {
|
|
151
|
-
this.state.modalId = null;
|
|
152
|
-
this.state.confirmDeleteId = null;
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
// -- Actions --
|
|
156
|
-
|
|
157
|
-
toggleFavorite(id) {
|
|
158
|
-
$.getStore('main').dispatch('toggleFavorite', Number(id));
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
confirmDelete(id) {
|
|
162
|
-
this.state.confirmDeleteId = Number(id);
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
cancelDelete() {
|
|
166
|
-
this.state.confirmDeleteId = null;
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
deleteContact(id) {
|
|
170
|
-
const numId = Number(id);
|
|
171
|
-
const store = $.getStore('main');
|
|
172
|
-
const c = store.state.contacts.find(c => c.id === numId);
|
|
173
|
-
store.dispatch('deleteContact', numId);
|
|
174
|
-
this.state.modalId = null;
|
|
175
|
-
this.state.confirmDeleteId = null;
|
|
176
|
-
$.bus.emit('toast', { message: `${c ? c.name : 'Contact'} removed`, type: 'error' });
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
cycleStatus(id) {
|
|
180
|
-
$.getStore('main').dispatch('cycleContactStatus', Number(id));
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
setFilter(role) {
|
|
184
|
-
this.state.filterRole = this.state.filterRole === role ? '' : role;
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
_clearForm() {
|
|
188
|
-
this.state.newName = '';
|
|
189
|
-
this.state.newEmail = '';
|
|
190
|
-
this.state.newRole = 'Developer';
|
|
191
|
-
this.state.newPhone = '';
|
|
192
|
-
this.state.newBio = '';
|
|
193
|
-
this.state.nameError = '';
|
|
194
|
-
this.state.emailError = '';
|
|
195
|
-
},
|
|
196
|
-
});
|
|
1
|
+
// contacts.js - Contact book page
|
|
2
|
+
//
|
|
3
|
+
// Features used:
|
|
4
|
+
// templateUrl / styleUrl - external template & scoped styles
|
|
5
|
+
// z-if / z-show / z-for - conditional & list rendering
|
|
6
|
+
// z-model / z-ref - form bindings
|
|
7
|
+
// @click / @submit.prevent - event handling
|
|
8
|
+
// @keydown.escape - keyboard modifier
|
|
9
|
+
// $.getStore / dispatch - store integration
|
|
10
|
+
// $.bus.emit('toast') - notifications
|
|
11
|
+
|
|
12
|
+
$.component('contacts-page', {
|
|
13
|
+
templateUrl: 'contacts.html',
|
|
14
|
+
styleUrl: 'contacts.css',
|
|
15
|
+
|
|
16
|
+
state: () => ({
|
|
17
|
+
contacts: [],
|
|
18
|
+
showAddModal: false,
|
|
19
|
+
newName: '',
|
|
20
|
+
newEmail: '',
|
|
21
|
+
newRole: 'Developer',
|
|
22
|
+
newPhone: '',
|
|
23
|
+
newBio: '',
|
|
24
|
+
nameError: '',
|
|
25
|
+
emailError: '',
|
|
26
|
+
modalId: null,
|
|
27
|
+
confirmDeleteId: null,
|
|
28
|
+
totalAdded: 0,
|
|
29
|
+
favoriteCount: 0,
|
|
30
|
+
filterText: '',
|
|
31
|
+
filterRole: '',
|
|
32
|
+
// Derived state (not computed - external templates resolve state only)
|
|
33
|
+
filteredContacts: [],
|
|
34
|
+
modalContact: null,
|
|
35
|
+
}),
|
|
36
|
+
|
|
37
|
+
watch: {
|
|
38
|
+
filterText() { this._recompute(); },
|
|
39
|
+
filterRole() { this._recompute(); },
|
|
40
|
+
modalId() { this._recompute(); },
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
mounted() {
|
|
44
|
+
const store = $.getStore('main');
|
|
45
|
+
this._syncFromStore(store);
|
|
46
|
+
this._unsub = store.subscribe(() => this._syncFromStore(store));
|
|
47
|
+
|
|
48
|
+
// Global Escape handler - template @keydown.escape on overlays is
|
|
49
|
+
// unreliable when no child element has focus (detail modal has no inputs).
|
|
50
|
+
this._onEscape = (e) => {
|
|
51
|
+
if (e.key !== 'Escape') return;
|
|
52
|
+
if (this.state.showAddModal) { this.closeAddModal(); e.stopPropagation(); }
|
|
53
|
+
else if (this.state.modalId != null) { this.closeModal(); e.stopPropagation(); }
|
|
54
|
+
};
|
|
55
|
+
document.addEventListener('keydown', this._onEscape);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
destroyed() {
|
|
59
|
+
if (this._unsub) this._unsub();
|
|
60
|
+
if (this._onEscape) document.removeEventListener('keydown', this._onEscape);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
_syncFromStore(store) {
|
|
64
|
+
// Shallow-clone each contact so the framework detects new references
|
|
65
|
+
// (store actions mutate objects in place - same refs won't trigger re-render)
|
|
66
|
+
this.state.contacts = store.state.contacts.map(c => ({ ...c }));
|
|
67
|
+
this.state.totalAdded = store.state.contactsAdded;
|
|
68
|
+
this.state.favoriteCount = store.getters.favoriteCount;
|
|
69
|
+
this._recompute();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/** Recalculate derived state from current contacts + filter values. */
|
|
73
|
+
_recompute() {
|
|
74
|
+
let list = this.state.contacts;
|
|
75
|
+
const q = this.state.filterText.toLowerCase();
|
|
76
|
+
if (q) list = list.filter(c => c.name.toLowerCase().includes(q) || c.email.toLowerCase().includes(q));
|
|
77
|
+
if (this.state.filterRole) list = list.filter(c => c.role === this.state.filterRole);
|
|
78
|
+
this.state.filteredContacts = list;
|
|
79
|
+
|
|
80
|
+
this.state.modalContact = this.state.modalId != null
|
|
81
|
+
? this.state.contacts.find(c => c.id === this.state.modalId) || null
|
|
82
|
+
: null;
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// -- Add-contact modal --
|
|
86
|
+
|
|
87
|
+
openAddModal() {
|
|
88
|
+
this.state.showAddModal = true;
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
closeAddModal() {
|
|
92
|
+
this.state.showAddModal = false;
|
|
93
|
+
this._clearForm();
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
_validateName(name) {
|
|
97
|
+
if (!name) return 'Name is required.';
|
|
98
|
+
if (name.length < 2) return 'At least 2 characters.';
|
|
99
|
+
return '';
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
_validateEmail(email) {
|
|
103
|
+
if (!email) return 'Email is required.';
|
|
104
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) return 'Enter a valid email.';
|
|
105
|
+
const store = $.getStore('main');
|
|
106
|
+
if (store.state.contacts.some(c => c.email.toLowerCase() === email.toLowerCase())) {
|
|
107
|
+
return 'Email already exists.';
|
|
108
|
+
}
|
|
109
|
+
return '';
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
validateName() {
|
|
113
|
+
this.state.nameError = this._validateName(this.state.newName.trim());
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
validateEmail() {
|
|
117
|
+
this.state.emailError = this._validateEmail(this.state.newEmail.trim());
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
addContact() {
|
|
121
|
+
const name = this.state.newName.trim();
|
|
122
|
+
const email = this.state.newEmail.trim();
|
|
123
|
+
|
|
124
|
+
const nameError = this._validateName(name);
|
|
125
|
+
const emailError = this._validateEmail(email);
|
|
126
|
+
this.state.nameError = nameError;
|
|
127
|
+
this.state.emailError = emailError;
|
|
128
|
+
if (nameError || emailError) return;
|
|
129
|
+
|
|
130
|
+
$.getStore('main').dispatch('addContact', {
|
|
131
|
+
name,
|
|
132
|
+
email,
|
|
133
|
+
role: this.state.newRole,
|
|
134
|
+
phone: this.state.newPhone.trim(),
|
|
135
|
+
bio: this.state.newBio.trim(),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
this._clearForm();
|
|
139
|
+
this.state.showAddModal = false;
|
|
140
|
+
$.bus.emit('toast', { message: `${name} added!`, type: 'success' });
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
// -- Detail modal --
|
|
144
|
+
|
|
145
|
+
openModal(id) {
|
|
146
|
+
this.state.modalId = Number(id);
|
|
147
|
+
this.state.confirmDeleteId = null;
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
closeModal() {
|
|
151
|
+
this.state.modalId = null;
|
|
152
|
+
this.state.confirmDeleteId = null;
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
// -- Actions --
|
|
156
|
+
|
|
157
|
+
toggleFavorite(id) {
|
|
158
|
+
$.getStore('main').dispatch('toggleFavorite', Number(id));
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
confirmDelete(id) {
|
|
162
|
+
this.state.confirmDeleteId = Number(id);
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
cancelDelete() {
|
|
166
|
+
this.state.confirmDeleteId = null;
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
deleteContact(id) {
|
|
170
|
+
const numId = Number(id);
|
|
171
|
+
const store = $.getStore('main');
|
|
172
|
+
const c = store.state.contacts.find(c => c.id === numId);
|
|
173
|
+
store.dispatch('deleteContact', numId);
|
|
174
|
+
this.state.modalId = null;
|
|
175
|
+
this.state.confirmDeleteId = null;
|
|
176
|
+
$.bus.emit('toast', { message: `${c ? c.name : 'Contact'} removed`, type: 'error' });
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
cycleStatus(id) {
|
|
180
|
+
$.getStore('main').dispatch('cycleContactStatus', Number(id));
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
setFilter(role) {
|
|
184
|
+
this.state.filterRole = this.state.filterRole === role ? '' : role;
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
_clearForm() {
|
|
188
|
+
this.state.newName = '';
|
|
189
|
+
this.state.newEmail = '';
|
|
190
|
+
this.state.newRole = 'Developer';
|
|
191
|
+
this.state.newPhone = '';
|
|
192
|
+
this.state.newBio = '';
|
|
193
|
+
this.state.nameError = '';
|
|
194
|
+
this.state.emailError = '';
|
|
195
|
+
},
|
|
196
|
+
});
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
// counter.js - Interactive counter
|
|
2
|
-
//
|
|
3
|
-
// Features used:
|
|
4
|
-
// state / computed / watch - reactive data flow
|
|
5
|
-
// @click - event binding
|
|
6
|
-
// z-model + z-number - two-way binding with type coercion
|
|
7
|
-
// z-class / z-if / z-for - conditional & list rendering
|
|
8
|
-
// $.bus.emit('toast', …) - notifications via event bus
|
|
9
|
-
|
|
10
|
-
$.component('counter-page', {
|
|
11
|
-
styles: `
|
|
12
|
-
.ctr-display { padding: 2rem 0 1.25rem; text-align: center; }
|
|
13
|
-
.ctr-num { font-size: 4rem; font-weight: 800; font-variant-numeric: tabular-nums;
|
|
14
|
-
color: var(--accent); transition: color .2s;
|
|
15
|
-
letter-spacing: -0.02em; line-height: 1; }
|
|
16
|
-
.ctr-num.negative { color: var(--danger); }
|
|
17
|
-
.ctr-label { font-size: .82rem; color: var(--text-muted); margin-top: .35rem; }
|
|
18
|
-
.ctr-actions { display: flex; justify-content: center; gap: .65rem;
|
|
19
|
-
margin-bottom: 1.5rem; }
|
|
20
|
-
.ctr-actions .btn { min-width: 120px; justify-content: center; }
|
|
21
|
-
.ctr-config { display: flex; align-items: center; justify-content: center; gap: 1.25rem;
|
|
22
|
-
padding-top: 1.15rem; border-top: 1px solid var(--border); }
|
|
23
|
-
.ctr-config label { display: flex; align-items: center; gap: .5rem;
|
|
24
|
-
color: var(--text-muted); font-size: .88rem; }
|
|
25
|
-
.ctr-config .input-sm { width: 65px; text-align: center; }
|
|
26
|
-
|
|
27
|
-
.ctr-hist { display: flex; flex-wrap: wrap; gap: .4rem; }
|
|
28
|
-
.ctr-hist-item { display: inline-flex; align-items: center; gap: .3rem;
|
|
29
|
-
padding: .3rem .65rem; border-radius: var(--radius);
|
|
30
|
-
background: var(--bg-hover); border: 1px solid var(--border);
|
|
31
|
-
font-size: .82rem; font-variant-numeric: tabular-nums;
|
|
32
|
-
transition: border-color .15s; }
|
|
33
|
-
.ctr-hist-item:last-child { border-color: var(--accent); background: rgba(88,166,255,.06); }
|
|
34
|
-
.ctr-hist-op { color: var(--text-muted); font-weight: 500; }
|
|
35
|
-
.ctr-hist-val { color: var(--accent); font-weight: 600; }
|
|
36
|
-
|
|
37
|
-
@media (max-width: 768px) {
|
|
38
|
-
.ctr-num { font-size: 2.75rem; }
|
|
39
|
-
.ctr-actions { gap: .5rem; }
|
|
40
|
-
.ctr-actions .btn { min-width: 100px; }
|
|
41
|
-
.ctr-config { flex-wrap: wrap; gap: .75rem; justify-content: center; }
|
|
42
|
-
}
|
|
43
|
-
@media (max-width: 480px) {
|
|
44
|
-
.ctr-num { font-size: 2.25rem; }
|
|
45
|
-
.ctr-actions .btn { min-width: 0; flex: 1; }
|
|
46
|
-
}
|
|
47
|
-
`,
|
|
48
|
-
|
|
49
|
-
state: () => ({
|
|
50
|
-
count: 0,
|
|
51
|
-
step: 1,
|
|
52
|
-
history: [],
|
|
53
|
-
}),
|
|
54
|
-
|
|
55
|
-
computed: {
|
|
56
|
-
isNegative: (state) => state.count < 0,
|
|
57
|
-
historyCount: (state) => state.history.length,
|
|
58
|
-
lastAction: (state) => state.history.length ? state.history[state.history.length - 1] : null,
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
watch: {
|
|
62
|
-
count(val) {
|
|
63
|
-
if (val === 100) $.bus.emit('toast', { message: 'Century! 🎉', type: 'success' });
|
|
64
|
-
if (val === -100) $.bus.emit('toast', { message: 'Negative century!', type: 'error' });
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
increment() {
|
|
69
|
-
this.state.count += this.state.step;
|
|
70
|
-
this._pushHistory('+', this.state.step, this.state.count);
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
decrement() {
|
|
74
|
-
this.state.count -= this.state.step;
|
|
75
|
-
this._pushHistory('-', this.state.step, this.state.count);
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
_pushHistory(action, value, result) {
|
|
79
|
-
const raw = this.state.history.__raw || this.state.history;
|
|
80
|
-
const next = [...raw, { id: Date.now(), action, value, result }];
|
|
81
|
-
this.state.history = next.length > 8 ? next.slice(-8) : next;
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
reset() {
|
|
85
|
-
this.state.count = 0;
|
|
86
|
-
this.state.history = [];
|
|
87
|
-
$.bus.emit('toast', { message: 'Counter reset!', type: 'info' });
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
render() {
|
|
91
|
-
return `
|
|
92
|
-
<div class="page-header">
|
|
93
|
-
<h1>Counter</h1>
|
|
94
|
-
<p class="subtitle"><code>computed</code>, <code>watch</code>, <code>@click</code>, <code>z-model</code>, <code>z-class</code>, and <code>z-for</code> with <code>z-key</code>.</p>
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
<div class="card">
|
|
98
|
-
<div class="ctr-display">
|
|
99
|
-
<div class="ctr-num" z-class="{'negative': count < 0}">${this.state.count}</div>
|
|
100
|
-
<div class="ctr-label">current value${this.state.step !== 1 ? ` · step ${this.state.step}` : ''}</div>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<div class="ctr-actions">
|
|
104
|
-
<button class="btn btn-outline" @click="decrement">- Subtract</button>
|
|
105
|
-
<button class="btn btn-primary" @click="increment">+ Add</button>
|
|
106
|
-
</div>
|
|
107
|
-
|
|
108
|
-
<div class="ctr-config">
|
|
109
|
-
<label>Step size
|
|
110
|
-
<input type="number" z-model="step" z-number min="1" max="100" class="input input-sm" />
|
|
111
|
-
</label>
|
|
112
|
-
<button class="btn btn-ghost btn-sm" @click="reset">Reset</button>
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
|
|
116
|
-
<div class="card" z-if="history.length > 0">
|
|
117
|
-
<h3>History <small style="color:var(--text-muted);font-weight:400;font-size:.85rem;">${this.computed.historyCount} entries</small></h3>
|
|
118
|
-
<div class="ctr-hist">
|
|
119
|
-
<span z-for="e in history" z-key="{{e.id}}" class="ctr-hist-item">
|
|
120
|
-
<span class="ctr-hist-op">{{e.action}}{{e.value}}</span>
|
|
121
|
-
<span class="ctr-hist-val">→ {{e.result}}</span>
|
|
122
|
-
</span>
|
|
123
|
-
</div>
|
|
124
|
-
</div>
|
|
125
|
-
`;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
1
|
+
// counter.js - Interactive counter
|
|
2
|
+
//
|
|
3
|
+
// Features used:
|
|
4
|
+
// state / computed / watch - reactive data flow
|
|
5
|
+
// @click - event binding
|
|
6
|
+
// z-model + z-number - two-way binding with type coercion
|
|
7
|
+
// z-class / z-if / z-for - conditional & list rendering
|
|
8
|
+
// $.bus.emit('toast', …) - notifications via event bus
|
|
9
|
+
|
|
10
|
+
$.component('counter-page', {
|
|
11
|
+
styles: `
|
|
12
|
+
.ctr-display { padding: 2rem 0 1.25rem; text-align: center; }
|
|
13
|
+
.ctr-num { font-size: 4rem; font-weight: 800; font-variant-numeric: tabular-nums;
|
|
14
|
+
color: var(--accent); transition: color .2s;
|
|
15
|
+
letter-spacing: -0.02em; line-height: 1; }
|
|
16
|
+
.ctr-num.negative { color: var(--danger); }
|
|
17
|
+
.ctr-label { font-size: .82rem; color: var(--text-muted); margin-top: .35rem; }
|
|
18
|
+
.ctr-actions { display: flex; justify-content: center; gap: .65rem;
|
|
19
|
+
margin-bottom: 1.5rem; }
|
|
20
|
+
.ctr-actions .btn { min-width: 120px; justify-content: center; }
|
|
21
|
+
.ctr-config { display: flex; align-items: center; justify-content: center; gap: 1.25rem;
|
|
22
|
+
padding-top: 1.15rem; border-top: 1px solid var(--border); }
|
|
23
|
+
.ctr-config label { display: flex; align-items: center; gap: .5rem;
|
|
24
|
+
color: var(--text-muted); font-size: .88rem; }
|
|
25
|
+
.ctr-config .input-sm { width: 65px; text-align: center; }
|
|
26
|
+
|
|
27
|
+
.ctr-hist { display: flex; flex-wrap: wrap; gap: .4rem; }
|
|
28
|
+
.ctr-hist-item { display: inline-flex; align-items: center; gap: .3rem;
|
|
29
|
+
padding: .3rem .65rem; border-radius: var(--radius);
|
|
30
|
+
background: var(--bg-hover); border: 1px solid var(--border);
|
|
31
|
+
font-size: .82rem; font-variant-numeric: tabular-nums;
|
|
32
|
+
transition: border-color .15s; }
|
|
33
|
+
.ctr-hist-item:last-child { border-color: var(--accent); background: rgba(88,166,255,.06); }
|
|
34
|
+
.ctr-hist-op { color: var(--text-muted); font-weight: 500; }
|
|
35
|
+
.ctr-hist-val { color: var(--accent); font-weight: 600; }
|
|
36
|
+
|
|
37
|
+
@media (max-width: 768px) {
|
|
38
|
+
.ctr-num { font-size: 2.75rem; }
|
|
39
|
+
.ctr-actions { gap: .5rem; }
|
|
40
|
+
.ctr-actions .btn { min-width: 100px; }
|
|
41
|
+
.ctr-config { flex-wrap: wrap; gap: .75rem; justify-content: center; }
|
|
42
|
+
}
|
|
43
|
+
@media (max-width: 480px) {
|
|
44
|
+
.ctr-num { font-size: 2.25rem; }
|
|
45
|
+
.ctr-actions .btn { min-width: 0; flex: 1; }
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
|
|
49
|
+
state: () => ({
|
|
50
|
+
count: 0,
|
|
51
|
+
step: 1,
|
|
52
|
+
history: [],
|
|
53
|
+
}),
|
|
54
|
+
|
|
55
|
+
computed: {
|
|
56
|
+
isNegative: (state) => state.count < 0,
|
|
57
|
+
historyCount: (state) => state.history.length,
|
|
58
|
+
lastAction: (state) => state.history.length ? state.history[state.history.length - 1] : null,
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
watch: {
|
|
62
|
+
count(val) {
|
|
63
|
+
if (val === 100) $.bus.emit('toast', { message: 'Century! 🎉', type: 'success' });
|
|
64
|
+
if (val === -100) $.bus.emit('toast', { message: 'Negative century!', type: 'error' });
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
increment() {
|
|
69
|
+
this.state.count += this.state.step;
|
|
70
|
+
this._pushHistory('+', this.state.step, this.state.count);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
decrement() {
|
|
74
|
+
this.state.count -= this.state.step;
|
|
75
|
+
this._pushHistory('-', this.state.step, this.state.count);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
_pushHistory(action, value, result) {
|
|
79
|
+
const raw = this.state.history.__raw || this.state.history;
|
|
80
|
+
const next = [...raw, { id: Date.now(), action, value, result }];
|
|
81
|
+
this.state.history = next.length > 8 ? next.slice(-8) : next;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
reset() {
|
|
85
|
+
this.state.count = 0;
|
|
86
|
+
this.state.history = [];
|
|
87
|
+
$.bus.emit('toast', { message: 'Counter reset!', type: 'info' });
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
render() {
|
|
91
|
+
return `
|
|
92
|
+
<div class="page-header">
|
|
93
|
+
<h1>Counter</h1>
|
|
94
|
+
<p class="subtitle"><code>computed</code>, <code>watch</code>, <code>@click</code>, <code>z-model</code>, <code>z-class</code>, and <code>z-for</code> with <code>z-key</code>.</p>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div class="card">
|
|
98
|
+
<div class="ctr-display">
|
|
99
|
+
<div class="ctr-num" z-class="{'negative': count < 0}">${this.state.count}</div>
|
|
100
|
+
<div class="ctr-label">current value${this.state.step !== 1 ? ` · step ${this.state.step}` : ''}</div>
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div class="ctr-actions">
|
|
104
|
+
<button class="btn btn-outline" @click="decrement">- Subtract</button>
|
|
105
|
+
<button class="btn btn-primary" @click="increment">+ Add</button>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div class="ctr-config">
|
|
109
|
+
<label>Step size
|
|
110
|
+
<input type="number" z-model="step" z-number min="1" max="100" class="input input-sm" />
|
|
111
|
+
</label>
|
|
112
|
+
<button class="btn btn-ghost btn-sm" @click="reset">Reset</button>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div class="card" z-if="history.length > 0">
|
|
117
|
+
<h3>History <small style="color:var(--text-muted);font-weight:400;font-size:.85rem;">${this.computed.historyCount} entries</small></h3>
|
|
118
|
+
<div class="ctr-hist">
|
|
119
|
+
<span z-for="e in history" z-key="{{e.id}}" class="ctr-hist-item">
|
|
120
|
+
<span class="ctr-hist-op">{{e.action}}{{e.value}}</span>
|
|
121
|
+
<span class="ctr-hist-val">→ {{e.result}}</span>
|
|
122
|
+
</span>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
});
|