@commonpub/layer 0.27.1 → 0.28.1

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.
@@ -176,9 +176,9 @@ function confirmWithdraw(entryId: string): void {
176
176
  .cpub-entry-score { font-size: 10px; color: var(--text-faint); font-family: var(--font-mono); display: flex; align-items: center; gap: 3px; }
177
177
 
178
178
  .cpub-entry-vote-btn {
179
- display: inline-flex; align-items: center; gap: 4px;
179
+ display: inline-flex; align-items: center; justify-content: center; gap: 4px;
180
180
  font-size: 11px; font-family: var(--font-mono); font-weight: 600;
181
- padding: 3px 8px; border: var(--border-width-default) solid var(--border2);
181
+ padding: 4px 10px; min-height: 28px; border: var(--border-width-default) solid var(--border2);
182
182
  background: var(--surface); color: var(--text-dim); cursor: pointer;
183
183
  transition: all 0.15s;
184
184
  }
@@ -187,7 +187,7 @@ function confirmWithdraw(entryId: string): void {
187
187
  .cpub-entry-vote-btn:disabled { opacity: 0.4; cursor: default; }
188
188
  .cpub-entry-vote-btn i { font-size: 10px; }
189
189
 
190
- .cpub-withdraw-btn { display: flex; align-items: center; gap: 4px; font-size: 10px; font-family: var(--font-mono); padding: 3px 8px; border-radius: var(--radius); border: var(--border-width-default) solid var(--red-border); background: var(--surface); color: var(--red); cursor: pointer; margin-left: auto; }
190
+ .cpub-withdraw-btn { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 10px; font-family: var(--font-mono); padding: 4px 10px; min-height: 28px; border-radius: var(--radius); border: var(--border-width-default) solid var(--red-border); background: var(--surface); color: var(--red); cursor: pointer; margin-left: auto; }
191
191
  .cpub-withdraw-btn:hover { background: var(--red-bg); }
192
192
 
193
193
  .cpub-empty-state { text-align: center; padding: 32px 0; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonpub/layer",
3
- "version": "0.27.1",
3
+ "version": "0.28.1",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -53,16 +53,16 @@
53
53
  "vue": "^3.4.0",
54
54
  "vue-router": "^4.3.0",
55
55
  "zod": "^4.3.6",
56
+ "@commonpub/config": "0.15.0",
57
+ "@commonpub/docs": "0.6.3",
56
58
  "@commonpub/explainer": "0.7.15",
59
+ "@commonpub/protocol": "0.12.0",
57
60
  "@commonpub/learning": "0.5.2",
58
- "@commonpub/editor": "0.7.11",
59
- "@commonpub/schema": "0.20.0",
60
- "@commonpub/docs": "0.6.3",
61
+ "@commonpub/schema": "0.21.0",
61
62
  "@commonpub/ui": "0.9.1",
62
- "@commonpub/server": "2.61.1",
63
- "@commonpub/auth": "0.6.0",
64
- "@commonpub/protocol": "0.12.0",
65
- "@commonpub/config": "0.15.0"
63
+ "@commonpub/editor": "0.7.11",
64
+ "@commonpub/server": "2.62.0",
65
+ "@commonpub/auth": "0.6.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@testing-library/jest-dom": "^6.9.1",
@@ -92,6 +92,8 @@ async function acceptInvite(): Promise<void> {
92
92
 
93
93
  // Entry submission
94
94
  const showSubmitDialog = ref(false);
95
+ const submitDialogRef = ref<HTMLElement | null>(null);
96
+ useFocusTrap(submitDialogRef, () => showSubmitDialog.value, () => { showSubmitDialog.value = false; });
95
97
  const submitContentId = ref('');
96
98
  const submitting = ref(false);
97
99
  const { data: userContent } = useFetch('/api/content', {
@@ -156,7 +158,7 @@ async function withdrawEntry(entryId: string): Promise<void> {
156
158
 
157
159
  <!-- SUBMIT ENTRY DIALOG -->
158
160
  <div v-if="showSubmitDialog" class="cpub-submit-overlay" @click.self="showSubmitDialog = false">
159
- <div class="cpub-submit-dialog" role="dialog" aria-label="Submit entry">
161
+ <div ref="submitDialogRef" class="cpub-submit-dialog" role="dialog" aria-modal="true" aria-label="Submit entry">
160
162
  <div class="cpub-submit-header">
161
163
  <h2>Submit Entry</h2>
162
164
  <button class="cpub-submit-close" aria-label="Close" @click="showSubmitDialog = false"><i class="fa-solid fa-times"></i></button>
@@ -296,8 +298,9 @@ async function withdrawEntry(entryId: string): Promise<void> {
296
298
  .cpub-invite-text i { color: var(--accent); }
297
299
 
298
300
  /* TABS */
299
- .cpub-tabbar { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: var(--border-width-default) solid var(--border); margin-bottom: 20px; }
300
- .cpub-tab { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: var(--font-mono); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); cursor: pointer; }
301
+ .cpub-tabbar { display: flex; gap: 2px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; border-bottom: var(--border-width-default) solid var(--border); margin-bottom: 20px; }
302
+ .cpub-tabbar::-webkit-scrollbar { display: none; }
303
+ .cpub-tab { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; min-height: 40px; flex-shrink: 0; white-space: nowrap; background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: var(--font-mono); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); cursor: pointer; }
301
304
  .cpub-tab:hover { color: var(--text-dim); }
302
305
  .cpub-tab-active { color: var(--accent); border-bottom-color: var(--accent); }
303
306
  .cpub-tab i { font-size: 11px; }
@@ -6,15 +6,24 @@ const slug = route.params.slug as string;
6
6
  const { user } = useAuth();
7
7
  const toast = useToast();
8
8
 
9
- import type { Serialized, ContestDetail, ContestEntryItem, ContestJudgeItem } from '@commonpub/server';
9
+ import type { Serialized, ContestDetail, ContestEntryItem, ContestJudgeItem, JudgeScoreEntry } from '@commonpub/server';
10
10
 
11
11
  const { data: contest } = useLazyFetch<Serialized<ContestDetail>>(`/api/contests/${slug}`);
12
12
  const { data: judgesData, refresh: refreshJudges } = useLazyFetch<ContestJudgeItem[]>(`/api/contests/${slug}/judges`);
13
- const { data: entriesData, refresh: refreshEntries } = useLazyFetch<{ items: (Serialized<ContestEntryItem> & { judgeScores?: Array<{ judgeId: string; score: number; feedback?: string }> })[]; total: number }>(
13
+ const { data: entriesData, refresh: refreshEntries } = useLazyFetch<{ items: (Serialized<ContestEntryItem> & { judgeScores?: JudgeScoreEntry[] })[]; total: number }>(
14
14
  `/api/contests/${slug}/entries`,
15
15
  { query: { includeJudgeScores: true } },
16
16
  );
17
17
 
18
+ // Judging rubric: when defined, judges score each criterion (0..max) and the
19
+ // overall is the normalized weighted sum (computed server-side).
20
+ const criteria = computed(() => contest.value?.judgingCriteria ?? []);
21
+ const hasCriteria = computed(() => criteria.value.length > 0);
22
+ function critMax(i: number): number {
23
+ const w = criteria.value[i]?.weight;
24
+ return typeof w === 'number' && w > 0 ? w : 100;
25
+ }
26
+
18
27
  useSeoMeta({ title: () => `Judge: ${contest.value?.title || 'Contest'} — ${useSiteName()}` });
19
28
 
20
29
  // Judge authorization derives from the contest_judges table.
@@ -54,6 +63,7 @@ const entryList = computed(() => {
54
63
  rank: entry.rank ?? null,
55
64
  myScore: myScore?.score ?? null,
56
65
  myFeedback: myScore?.feedback ?? '',
66
+ myCriteriaScores: myScore?.criteriaScores ?? null,
57
67
  };
58
68
  });
59
69
  });
@@ -63,6 +73,7 @@ const totalCount = computed(() => entryList.value.length);
63
73
  const progressPct = computed(() => totalCount.value > 0 ? Math.round((scoredCount.value / totalCount.value) * 100) : 0);
64
74
 
65
75
  const scoring = ref<Record<string, number>>({});
76
+ const critScoring = ref<Record<string, number[]>>({}); // per entry → [criterionScore...]
66
77
  const feedback = ref<Record<string, string>>({});
67
78
  const submitting = ref<string | null>(null);
68
79
  const error = ref('');
@@ -77,18 +88,50 @@ watch(entryList, (list) => {
77
88
  if (entry.myFeedback && feedback.value[entry.id] === undefined) {
78
89
  feedback.value[entry.id] = entry.myFeedback;
79
90
  }
91
+ if (hasCriteria.value && critScoring.value[entry.id] === undefined) {
92
+ // seed from a prior per-criterion submission, aligned by index
93
+ critScoring.value[entry.id] = criteria.value.map((c, i) =>
94
+ entry.myCriteriaScores?.[i]?.score ?? 0,
95
+ );
96
+ }
80
97
  }
81
98
  }, { immediate: true });
82
99
 
100
+ // Live preview of the normalized overall when scoring by criteria.
101
+ function critTotal(entryId: string): number {
102
+ const vals = critScoring.value[entryId] ?? [];
103
+ const totalMax = criteria.value.reduce((s, _c, i) => s + critMax(i), 0);
104
+ if (totalMax <= 0) return 0;
105
+ const sum = criteria.value.reduce((s, _c, i) => s + Math.min(Math.max(vals[i] ?? 0, 0), critMax(i)), 0);
106
+ return Math.round((sum / totalMax) * 100);
107
+ }
108
+
83
109
  async function submitScore(entryId: string): Promise<void> {
84
110
  if (!inJudgingPhase.value) {
85
111
  error.value = 'Scoring is only open during the judging phase.';
86
112
  return;
87
113
  }
88
- const score = scoring.value[entryId];
89
- if (score === undefined || score < 1 || score > 100) {
90
- error.value = 'Score must be between 1 and 100.';
91
- return;
114
+
115
+ let body: Record<string, unknown>;
116
+ if (hasCriteria.value) {
117
+ const vals = critScoring.value[entryId] ?? [];
118
+ const criteriaScores = criteria.value.map((c, i) => ({
119
+ label: c.label,
120
+ score: Math.round(vals[i] ?? 0),
121
+ max: critMax(i),
122
+ }));
123
+ if (criteriaScores.some((c) => c.score < 0 || c.score > c.max)) {
124
+ error.value = 'Each criterion score must be between 0 and its maximum.';
125
+ return;
126
+ }
127
+ body = { entryId, criteriaScores, feedback: feedback.value[entryId] || undefined };
128
+ } else {
129
+ const score = scoring.value[entryId];
130
+ if (score === undefined || score < 1 || score > 100) {
131
+ error.value = 'Score must be between 1 and 100.';
132
+ return;
133
+ }
134
+ body = { entryId, score, feedback: feedback.value[entryId] || undefined };
92
135
  }
93
136
 
94
137
  error.value = '';
@@ -96,14 +139,7 @@ async function submitScore(entryId: string): Promise<void> {
96
139
  submitting.value = entryId;
97
140
 
98
141
  try {
99
- await $fetch(`/api/contests/${slug}/judge`, {
100
- method: 'POST',
101
- body: {
102
- entryId,
103
- score,
104
- feedback: feedback.value[entryId] || undefined,
105
- },
106
- });
142
+ await $fetch(`/api/contests/${slug}/judge`, { method: 'POST', body });
107
143
  success.value = 'Score submitted for entry.';
108
144
  await refreshEntries().catch(() => {
109
145
  success.value = 'Score saved — refresh to see the updated totals.';
@@ -202,14 +238,35 @@ async function submitScore(entryId: string): Promise<void> {
202
238
  <span class="cpub-judge-score-value">{{ entry.myScore }}</span>
203
239
  </div>
204
240
  <div class="cpub-judge-score-controls">
241
+ <!-- Per-criterion scoring (when the contest defines a rubric) -->
242
+ <div v-if="hasCriteria && critScoring[entry.id]" class="cpub-judge-criteria-inputs">
243
+ <div v-for="(crit, i) in criteria" :key="i" class="cpub-judge-crit-row">
244
+ <label class="cpub-judge-crit-label">{{ crit.label }}</label>
245
+ <div class="cpub-judge-crit-input-wrap">
246
+ <input
247
+ v-model.number="critScoring[entry.id][i]"
248
+ type="number"
249
+ class="cpub-judge-crit-input"
250
+ min="0"
251
+ :max="critMax(i)"
252
+ :aria-label="`${crit.label} score, max ${critMax(i)}`"
253
+ />
254
+ <span class="cpub-judge-crit-max">/ {{ critMax(i) }}</span>
255
+ </div>
256
+ </div>
257
+ <div class="cpub-judge-crit-total">Overall <strong>{{ critTotal(entry.id) }}</strong> / 100</div>
258
+ </div>
259
+
205
260
  <div class="cpub-judge-score-input-wrap">
206
261
  <input
262
+ v-if="!hasCriteria"
207
263
  v-model.number="scoring[entry.id]"
208
264
  type="number"
209
265
  class="cpub-judge-score-input"
210
266
  min="1"
211
267
  max="100"
212
268
  placeholder="1-100"
269
+ aria-label="Overall score, 1 to 100"
213
270
  />
214
271
  <button
215
272
  class="cpub-judge-score-btn"
@@ -279,6 +336,15 @@ async function submitScore(entryId: string): Promise<void> {
279
336
  .cpub-judge-score-label { display: block; font-family: var(--font-mono); font-size: 9px; color: var(--text-faint); text-transform: uppercase; }
280
337
  .cpub-judge-score-value { font-size: 20px; font-weight: 700; color: var(--accent); font-family: var(--font-mono); }
281
338
  .cpub-judge-score-controls { display: flex; flex-direction: column; gap: 6px; }
339
+ .cpub-judge-criteria-inputs { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: var(--border-width-default) dashed var(--border); background: var(--surface2); margin-bottom: 2px; }
340
+ .cpub-judge-crit-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
341
+ .cpub-judge-crit-label { font-size: 11px; color: var(--text-dim); flex: 1; min-width: 0; }
342
+ .cpub-judge-crit-input-wrap { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
343
+ .cpub-judge-crit-input { width: 52px; padding: 4px 6px; border: var(--border-width-default) solid var(--border); background: var(--surface); color: var(--text); font-size: 12px; font-family: var(--font-mono); text-align: center; outline: none; }
344
+ .cpub-judge-crit-input:focus { border-color: var(--accent); }
345
+ .cpub-judge-crit-max { font-size: 10px; color: var(--text-faint); font-family: var(--font-mono); }
346
+ .cpub-judge-crit-total { font-size: 11px; font-family: var(--font-mono); color: var(--text-dim); text-align: right; padding-top: 4px; border-top: var(--border-width-default) solid var(--border); }
347
+ .cpub-judge-crit-total strong { color: var(--accent); font-size: 13px; }
282
348
  .cpub-judge-score-input-wrap { display: flex; gap: 0; }
283
349
  .cpub-judge-score-input {
284
350
  width: 70px; padding: 6px 8px; border: var(--border-width-default) solid var(--border); background: var(--surface);
@@ -121,6 +121,7 @@ function medalColor(rank: number): string {
121
121
  <!-- LEADERBOARD -->
122
122
  <div v-if="leaderboard.length > 0" class="cpub-leaderboard">
123
123
  <h2 class="cpub-leaderboard-title">Full Leaderboard</h2>
124
+ <div class="cpub-leaderboard-scroll">
124
125
  <table class="cpub-leaderboard-table">
125
126
  <thead>
126
127
  <tr>
@@ -150,6 +151,7 @@ function medalColor(rank: number): string {
150
151
  </tr>
151
152
  </tbody>
152
153
  </table>
154
+ </div>
153
155
  </div>
154
156
 
155
157
  <div v-else class="cpub-results-empty">
@@ -190,7 +192,9 @@ function medalColor(rank: number): string {
190
192
  /* LEADERBOARD */
191
193
  .cpub-leaderboard { margin-bottom: 32px; }
192
194
  .cpub-leaderboard-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
193
- .cpub-leaderboard-table { width: 100%; border-collapse: collapse; font-size: 12px; }
195
+ /* Horizontal scroll on narrow screens instead of overflowing the page. */
196
+ .cpub-leaderboard-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
197
+ .cpub-leaderboard-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 420px; }
194
198
  .cpub-leaderboard-table th { text-align: left; font-size: 10px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 8px 12px; border-bottom: var(--border-width-default) solid var(--border); }
195
199
  .cpub-leaderboard-table td { padding: 10px 12px; border-bottom: var(--border-width-default) solid var(--border); }
196
200
  .cpub-lb-top3 { background: var(--surface2); }
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event): Promise<{ success: boolean }> =
7
7
  const db = useDB();
8
8
  const input = await parseBody(event, judgeEntrySchema);
9
9
 
10
- const result = await judgeContestEntry(db, input.entryId, input.score, user.id, input.feedback);
10
+ const result = await judgeContestEntry(db, input.entryId, input.score, user.id, input.feedback, input.criteriaScores);
11
11
  if (!result.judged) {
12
12
  throw createError({ statusCode: 403, statusMessage: result.error ?? 'Judging failed' });
13
13
  }