@tansy/lms 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/admin.css +21 -0
- package/admin.d.ts +2 -0
- package/admin.js +128 -0
- package/builder.d.ts +7 -0
- package/builder.js +193 -0
- package/client.d.ts +2 -0
- package/client.js +19 -0
- package/editors.d.ts +3 -0
- package/editors.js +62 -0
- package/index.d.ts +12 -0
- package/index.js +576 -0
- package/lms.css +92 -0
- package/logic.d.ts +47 -0
- package/logic.js +115 -0
- package/messages.d.ts +364 -0
- package/messages.js +674 -0
- package/outline.d.ts +5 -0
- package/outline.js +21 -0
- package/package.json +44 -4
- package/parts.d.ts +69 -0
- package/parts.js +295 -0
- package/render.d.ts +81 -0
- package/render.js +186 -0
- package/schema.d.ts +706 -0
- package/schema.js +240 -0
- package/service.d.ts +124 -0
- package/service.js +282 -0
- package/site-messages.d.ts +3 -0
- package/site-messages.js +187 -0
- package/tools.d.ts +3 -0
- package/tools.js +74 -0
- package/words.d.ts +3 -0
- package/words.js +5 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
What changed in each release of `@tansy/lms`. Releases up to 0.1.0 went out with every other package
|
|
4
|
+
on one version and are described in [tansy's changelog](../../CHANGELOG.md).
|
|
5
|
+
|
|
6
|
+
## 0.1.1 — 2026-11-22
|
|
7
|
+
|
|
8
|
+
No changes of its own. Released beside `tansy` 0.1.1, from which every package moves on its own
|
|
9
|
+
version, and it now requires it: the `tansy` peer range is ^0.1.1.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohamed Salah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Generated by scripts/package-metadata.mjs. Change that script, not this file. -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @tansy/lms
|
|
4
|
+
|
|
5
|
+
Turns tansy into a learning platform: courses, lessons, enrollments, progress, quizzes and certificates.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tansy/lms
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Add it to `tansy.config.ts`. See [the lms plugin documentation](https://github.com/mhmdsalahsebai/tansy/blob/main/docs/plugins/lms.md) for what it adds and the options it takes.
|
|
12
|
+
|
|
13
|
+
A first-party plugin for [tansy](https://github.com/mhmdsalahsebai/tansy), a self-hosted, runtime-schema CMS for Next.js. MIT licensed.
|
package/admin.css
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* The course builder in the dashboard. Uses the dashboard's tokens, so it follows its theme. */
|
|
2
|
+
.lms-admin-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cms-space-2); margin-top: var(--cms-space-1); font-size: var(--cms-text-sm); color: var(--cms-color-text-soft); }
|
|
3
|
+
.lms-admin-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cms-space-2); }
|
|
4
|
+
.lms-admin-grid { display: grid; gap: var(--cms-space-6); align-items: start; }
|
|
5
|
+
@media (min-width: 72rem) { .lms-admin-grid { grid-template-columns: minmax(0, 1fr) 22rem; } }
|
|
6
|
+
.lms-admin-panel { padding: var(--cms-space-5); }
|
|
7
|
+
.lms-admin-section + .lms-admin-section { margin-top: var(--cms-space-5); padding-top: var(--cms-space-5); border-top: 1px solid var(--cms-color-border); }
|
|
8
|
+
.lms-admin-section-head { display: flex; align-items: center; gap: var(--cms-space-2); margin-bottom: var(--cms-space-3); }
|
|
9
|
+
.lms-admin-section-head .lms-admin-title-input { font-weight: 600; }
|
|
10
|
+
.lms-admin-lessons { display: grid; gap: var(--cms-space-2); margin: 0 0 var(--cms-space-3); padding: 0; list-style: none; }
|
|
11
|
+
.lms-admin-lesson { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cms-space-3); padding: var(--cms-space-2) var(--cms-space-3); border: 1px solid var(--cms-color-border); border-radius: var(--cms-radius-md); background: var(--cms-color-surface); }
|
|
12
|
+
.lms-admin-lesson-main { flex: 1 1 14rem; min-width: 0; }
|
|
13
|
+
.lms-admin-mover { display: inline-flex; flex-direction: column; }
|
|
14
|
+
.lms-admin-mover .cms-icon-btn { width: 1.5rem; height: 1.25rem; font-size: var(--cms-text-xs); }
|
|
15
|
+
.lms-admin-title-input { flex: 1 1 auto; width: 100%; min-width: 0; padding: var(--cms-space-1) var(--cms-space-2); border: 1px solid transparent; border-radius: var(--cms-radius-sm); background: transparent; font: inherit; color: var(--cms-color-text-strong); }
|
|
16
|
+
.lms-admin-title-input:hover { border-color: var(--cms-color-border); }
|
|
17
|
+
.lms-admin-title-input:focus { border-color: var(--cms-focus-ring); outline: none; background: var(--cms-color-surface); }
|
|
18
|
+
.lms-admin-select { width: auto; }
|
|
19
|
+
.lms-admin-add { display: flex; gap: var(--cms-space-2); max-width: 32rem; }
|
|
20
|
+
.lms-admin-add + .lms-admin-add { margin-top: var(--cms-space-2); }
|
|
21
|
+
.lms-admin .cms-link:disabled { opacity: 0.5; }
|
package/admin.d.ts
ADDED
package/admin.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { adminPath, Badge, DataTable, defineAdminPlugin, PageHeader } from "tansy/admin";
|
|
3
|
+
import { CollectionGrid, getT } from "tansy/server";
|
|
4
|
+
import { CourseBuilder, NewCourse } from "./builder";
|
|
5
|
+
/** This plugin's words in the person's interface language. */
|
|
6
|
+
async function words(userId) {
|
|
7
|
+
const { t } = await getT(userId);
|
|
8
|
+
return (key, values) => t(`ext.lms.${key}`, values);
|
|
9
|
+
}
|
|
10
|
+
const text = (value) => (typeof value === "string" ? value : "");
|
|
11
|
+
/** As the signed-in person, so someone who can't read a collection gets nothing rather than another person's view. */
|
|
12
|
+
async function allRows(records, slug, query, limit = 2000) {
|
|
13
|
+
try {
|
|
14
|
+
const rows = [];
|
|
15
|
+
for (let page = 1; rows.length < limit; page++) {
|
|
16
|
+
const result = await records.list(slug, { ...query, page, perPage: 200 });
|
|
17
|
+
rows.push(...result.items);
|
|
18
|
+
if (page >= result.totalPages)
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
return rows;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const WEEK = 7 * 24 * 60 * 60 * 1000;
|
|
28
|
+
const recent = (value) => typeof value === "string" && Date.now() - Date.parse(value) < WEEK;
|
|
29
|
+
async function Learners({ records, user }) {
|
|
30
|
+
const t = await words(user.id);
|
|
31
|
+
const [courses, enrollments, progress, lessons, quizzes, attempts] = await Promise.all([
|
|
32
|
+
allRows(records, "lms-courses", { sort: "title", fields: "id,title,status" }, 500),
|
|
33
|
+
allRows(records, "lms-enrollments", { fields: "id,course,student,state,completedAt" }),
|
|
34
|
+
allRows(records, "lms-progress", { fields: "course,student" }),
|
|
35
|
+
allRows(records, "lms-lessons", { filter: 'status = "published"', fields: "id,course" }),
|
|
36
|
+
allRows(records, "lms-quizzes", { fields: "id,course" }),
|
|
37
|
+
allRows(records, "lms-attempts", { fields: "quiz,passed" }),
|
|
38
|
+
]);
|
|
39
|
+
if (!courses || !enrollments || !progress || !lessons) {
|
|
40
|
+
return _jsxs("div", { className: "cms-gutter", children: [_jsx(PageHeader, { title: t("pages.lms/learners") }), _jsx("p", { className: "cms-empty", children: t("learners.cantRead") })] });
|
|
41
|
+
}
|
|
42
|
+
const quizCourse = new Map((quizzes ?? []).map((quiz) => [quiz.id, quiz.course]));
|
|
43
|
+
const rows = courses.map((course) => {
|
|
44
|
+
const enrolled = enrollments.filter((e) => e.course === course.id && e.state !== "revoked");
|
|
45
|
+
const total = lessons.filter((l) => l.course === course.id).length;
|
|
46
|
+
const students = new Set(enrolled.map((e) => e.student));
|
|
47
|
+
const finished = progress.filter((p) => p.course === course.id && students.has(p.student)).length;
|
|
48
|
+
const tries = (attempts ?? []).filter((a) => quizCourse.get(a.quiz) === course.id);
|
|
49
|
+
return {
|
|
50
|
+
id: course.id,
|
|
51
|
+
title: text(course.title),
|
|
52
|
+
draft: course.status === "draft",
|
|
53
|
+
enrolled: enrolled.length,
|
|
54
|
+
completed: enrolled.filter((e) => e.state === "completed").length,
|
|
55
|
+
recentCompletions: enrolled.filter((e) => e.state === "completed" && recent(e.completedAt)).length,
|
|
56
|
+
average: total && enrolled.length ? Math.round((finished / (total * enrolled.length)) * 100) : null,
|
|
57
|
+
passRate: tries.length ? Math.round((tries.filter((a) => a.passed === true).length / tries.length) * 100) : null,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
return (_jsxs("div", { className: "cms-gutter", children: [_jsx(PageHeader, { title: t("pages.lms/learners"), description: t("learners.intro") }), _jsx(DataTable, { label: t("pages.lms/learners"), columns: [{ id: "course", label: t("columns.course") }, { id: "enrolled", label: t("columns.enrolled"), numeric: true }, { id: "completed", label: t("columns.completed"), numeric: true }, { id: "week", label: t("columns.completedWeek"), numeric: true }, { id: "average", label: t("columns.average"), numeric: true }, { id: "passRate", label: t("columns.passRate"), numeric: true }], rows: rows.map((row) => ({
|
|
61
|
+
id: row.id,
|
|
62
|
+
href: adminPath(`/ext/lms/courses/${row.id}`),
|
|
63
|
+
cells: {
|
|
64
|
+
course: _jsxs(_Fragment, { children: [row.title || t("common.course", { id: row.id }), row.draft && _jsxs(_Fragment, { children: [" ", _jsx(Badge, { tone: "warning", tight: true, children: t("common.draftBadge") })] })] }),
|
|
65
|
+
enrolled: row.enrolled,
|
|
66
|
+
completed: row.completed,
|
|
67
|
+
week: row.recentCompletions,
|
|
68
|
+
average: row.average === null ? null : t("common.percent", { value: row.average }),
|
|
69
|
+
passRate: row.passRate === null ? null : t("common.percent", { value: row.passRate }),
|
|
70
|
+
},
|
|
71
|
+
})), empty: { title: t("learners.noCourses") } })] }));
|
|
72
|
+
}
|
|
73
|
+
/** Runs the school, so works on every course. Anyone else, such as an instructor, on their own. */
|
|
74
|
+
const managesAll = (permissions) => permissions.includes("ext.lms:manage") || permissions.includes("record:update");
|
|
75
|
+
async function Courses({ user }) {
|
|
76
|
+
const t = await words(user.id);
|
|
77
|
+
const all = managesAll(user.permissions);
|
|
78
|
+
if (!all && !/^[A-Za-z0-9_-]{1,64}$/.test(user.id))
|
|
79
|
+
return null;
|
|
80
|
+
// Instructors also see other people's published courses through the public rule, so their list is narrowed to their own.
|
|
81
|
+
return (_jsx(CollectionGrid, { collection: "lms-courses", title: t("pages.lms/courses"), description: all ? t("courses.allDescription") : t("courses.ownDescription"), recordPath: "/ext/lms/courses/:id", filter: all ? undefined : `createdById = "${user.id}"`, createAction: _jsx(NewCourse, {}) }));
|
|
82
|
+
}
|
|
83
|
+
async function Builder({ records, params, user }) {
|
|
84
|
+
const t = await words(user.id);
|
|
85
|
+
const id = /^[1-9]\d{0,15}$/.test(params.id ?? "") ? Number(params.id) : null;
|
|
86
|
+
// As the signed-in person: a course they can't read reads as missing.
|
|
87
|
+
const course = id === null ? null : await records.get("lms-courses", id, { fields: "id" }).catch(() => null);
|
|
88
|
+
if (!course)
|
|
89
|
+
return _jsxs("div", { className: "cms-gutter", children: [_jsx(PageHeader, { title: t("courses.notFound") }), _jsxs("p", { className: "cms-muted", children: [t("courses.notFoundBody"), " ", _jsx("a", { className: "cms-link", href: adminPath("/ext/lms/courses"), children: t("courses.back") })] })] });
|
|
90
|
+
return _jsx(CourseBuilder, { courseId: id, canManage: user.permissions.includes("ext.lms:manage") });
|
|
91
|
+
}
|
|
92
|
+
async function Overview({ records, user }) {
|
|
93
|
+
const t = await words(user.id);
|
|
94
|
+
const [enrollments, courses] = await Promise.all([
|
|
95
|
+
allRows(records, "lms-enrollments", { sort: "-createdAt", fields: "course,state,enrolledAt,completedAt" }, 1000),
|
|
96
|
+
allRows(records, "lms-courses", { fields: "id,title" }, 500),
|
|
97
|
+
]);
|
|
98
|
+
if (!enrollments)
|
|
99
|
+
return _jsx("p", { className: "cms-muted cms-text-sm", children: t("widget.cantRead") });
|
|
100
|
+
const started = new Map();
|
|
101
|
+
for (const enrollment of enrollments.filter((e) => recent(e.enrolledAt)))
|
|
102
|
+
started.set(enrollment.course, (started.get(enrollment.course) ?? 0) + 1);
|
|
103
|
+
const top = [...started].sort((a, b) => b[1] - a[1]).slice(0, 3);
|
|
104
|
+
const title = (id) => text(courses?.find((course) => course.id === id)?.title) || t("common.course", { id: String(id) });
|
|
105
|
+
return (_jsxs("ul", { className: "cms-muted cms-text-sm", children: [_jsx("li", { children: t("widget.newEnrollments", { count: enrollments.filter((e) => recent(e.enrolledAt)).length }) }), _jsx("li", { children: t("widget.completed", { count: enrollments.filter((e) => e.state === "completed" && recent(e.completedAt)).length }) }), top.length > 0 && _jsx("li", { children: t("widget.mostStarted", { courses: top.map(([id, count]) => `${title(id)} (${count})`).join(", ") }) })] }));
|
|
106
|
+
}
|
|
107
|
+
export default defineAdminPlugin({
|
|
108
|
+
pages: [
|
|
109
|
+
{ path: "lms/courses", title: "Courses", collection: "lms-courses", component: Courses },
|
|
110
|
+
{ path: "lms/courses/:id", title: "Course", collection: "lms-courses", component: Builder },
|
|
111
|
+
{ path: "lms/learners", title: "Learners", permission: "ext.lms:manage", component: Learners },
|
|
112
|
+
],
|
|
113
|
+
section: {
|
|
114
|
+
title: "LMS",
|
|
115
|
+
icon: "academic",
|
|
116
|
+
items: [
|
|
117
|
+
{ page: "lms/courses" },
|
|
118
|
+
{ page: "lms/learners" },
|
|
119
|
+
{ collection: "lms-enrollments" },
|
|
120
|
+
{ collection: "lms-certificates" },
|
|
121
|
+
{ collection: "lms-attempts" },
|
|
122
|
+
{ collection: "lms-my-courses", title: "My courses page" },
|
|
123
|
+
{ collection: "lms-certificate", title: "Certificate check page" },
|
|
124
|
+
{ settings: true },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
widgets: [{ id: "lms-overview", title: "Courses", permission: "ext.lms:manage", component: Overview }],
|
|
128
|
+
});
|
package/builder.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./admin.css";
|
|
2
|
+
export declare function CourseBuilder({ courseId, canManage }: {
|
|
3
|
+
courseId: number;
|
|
4
|
+
canManage: boolean;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
/** Creates a draft course and opens it in the builder. */
|
|
7
|
+
export declare function NewCourse(): import("react").JSX.Element;
|
package/builder.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { adminPath, Alert, apiPath, Badge, Button, PageHeader, Field, Input, Modal, PageSkeleton, translate, useT } from "tansy/admin";
|
|
5
|
+
import "./admin.css";
|
|
6
|
+
class ApiError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/** This plugin's words, in a component. */
|
|
9
|
+
function useWords() {
|
|
10
|
+
const { t } = useT();
|
|
11
|
+
return (key, values) => t(`ext.lms.${key}`, values);
|
|
12
|
+
}
|
|
13
|
+
/** This plugin's words outside a component, such as an error from a click. */
|
|
14
|
+
const word = (key, values) => translate(`ext.lms.${key}`, values);
|
|
15
|
+
/** Through the records API, so every change passes the same rules and permissions as anywhere else. */
|
|
16
|
+
async function call(path, init) {
|
|
17
|
+
const response = await fetch(apiPath(path), { method: init?.method ?? "GET", headers: init?.body === undefined ? undefined : { "content-type": "application/json" }, body: init?.body === undefined ? undefined : JSON.stringify(init.body) });
|
|
18
|
+
const json = await response.json().catch(() => null);
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const detail = json?.error?.details?.[0];
|
|
21
|
+
throw new ApiError(detail?.message ? `${json?.error?.message ?? word("builder.notSaved")} ${detail.path ? `${detail.path}: ` : ""}${detail.message}` : (json?.error?.message ?? word("builder.failed", { status: response.status })));
|
|
22
|
+
}
|
|
23
|
+
return json;
|
|
24
|
+
}
|
|
25
|
+
const records = (slug) => `/collections/${slug}/records`;
|
|
26
|
+
const list = async (slug, filter, fields) => (await call(`${records(slug)}?filter=${encodeURIComponent(filter)}&perPage=200&fields=${fields}`)).items;
|
|
27
|
+
const create = (slug, body) => call(records(slug), { method: "POST", body });
|
|
28
|
+
const update = (slug, id, body) => call(`${records(slug)}/${id}`, { method: "PATCH", body });
|
|
29
|
+
const remove = (slug, id) => call(`${records(slug)}/${id}`, { method: "DELETE" });
|
|
30
|
+
const byPosition = (items) => [...items].sort((a, b) => (a.position ?? Infinity) - (b.position ?? Infinity) || a.id - b.id);
|
|
31
|
+
const nextPosition = (items) => Math.max(0, ...items.map((item) => item.position ?? 0)) + 10;
|
|
32
|
+
const move = (items, from, to) => { const copy = [...items]; const [item] = copy.splice(from, 1); copy.splice(to, 0, item); return copy; };
|
|
33
|
+
/** Positions 10 apart in this order, saving only the ones that change. */
|
|
34
|
+
async function renumber(slug, items) {
|
|
35
|
+
for (const [index, item] of items.entries()) {
|
|
36
|
+
const position = (index + 1) * 10;
|
|
37
|
+
if (item.position !== position)
|
|
38
|
+
await update(slug, item.id, { position });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function fetchCourse(courseId, priceField) {
|
|
42
|
+
const [course, sections, lessons] = await Promise.all([
|
|
43
|
+
call(`${records("lms-courses")}/${courseId}?fields=id,title,summary,access,level,byline,estimatedMinutes,status${priceField ? `,${priceField}` : ""}`).then((row) => ({ ...row, price: priceField && typeof row[priceField] === "number" ? row[priceField] : null })),
|
|
44
|
+
list("lms-sections", `course = ${courseId}`, "id,title,position"),
|
|
45
|
+
list("lms-lessons", `course = ${courseId}`, "id,title,section,position,status,preview"),
|
|
46
|
+
]);
|
|
47
|
+
// Quizzes are optional: someone who can't list them still builds the rest.
|
|
48
|
+
const quizzes = await list("lms-quizzes", `course = ${courseId}`, "id,title,lesson").catch(() => []);
|
|
49
|
+
return { course, sections: byPosition(sections), lessons: byPosition(lessons), quizzes };
|
|
50
|
+
}
|
|
51
|
+
function Mover({ label, index, count, disabled, onMove }) {
|
|
52
|
+
const t = useWords();
|
|
53
|
+
return (_jsxs("span", { className: "lms-admin-mover", children: [_jsx("button", { type: "button", className: "cms-icon-btn", disabled: disabled || index === 0, onClick: () => onMove(index - 1), "aria-label": t("builder.moveLabelUp", { label }), title: t("builder.moveUp"), children: "\u2191" }), _jsx("button", { type: "button", className: "cms-icon-btn", disabled: disabled || index === count - 1, onClick: () => onMove(index + 1), "aria-label": t("builder.moveLabelDown", { label }), title: t("builder.moveDown"), children: "\u2193" })] }));
|
|
54
|
+
}
|
|
55
|
+
/** A one-line form that adds something by its title. */
|
|
56
|
+
function AddForm({ label, placeholder, disabled, onAdd }) {
|
|
57
|
+
const [title, setTitle] = useState("");
|
|
58
|
+
const submit = async (event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
if (!title.trim())
|
|
61
|
+
return;
|
|
62
|
+
await onAdd(title.trim());
|
|
63
|
+
setTitle("");
|
|
64
|
+
};
|
|
65
|
+
return (_jsxs("form", { className: "lms-admin-add", onSubmit: submit, children: [_jsx(Input, { "aria-label": placeholder, placeholder: placeholder, value: title, maxLength: 200, onChange: (event) => setTitle(event.target.value), disabled: disabled }), _jsx(Button, { type: "submit", variant: "secondary", disabled: disabled || !title.trim(), children: label })] }));
|
|
66
|
+
}
|
|
67
|
+
/** A title edited in place, saved when it loses focus. */
|
|
68
|
+
function TitleInput({ value, label, disabled, onSave }) {
|
|
69
|
+
const [draft, setDraft] = useState(value);
|
|
70
|
+
// A saved title replaces whatever was typed, as React's guide does for state that follows a prop.
|
|
71
|
+
const [shown, setShown] = useState(value);
|
|
72
|
+
if (shown !== value) {
|
|
73
|
+
setShown(value);
|
|
74
|
+
setDraft(value);
|
|
75
|
+
}
|
|
76
|
+
return _jsx("input", { className: "lms-admin-title-input", "aria-label": label, value: draft, maxLength: 200, disabled: disabled, onChange: (event) => setDraft(event.target.value), onBlur: () => { if (draft.trim() && draft !== value)
|
|
77
|
+
onSave(draft.trim());
|
|
78
|
+
else
|
|
79
|
+
setDraft(value); }, onKeyDown: (event) => { if (event.key === "Enter")
|
|
80
|
+
event.currentTarget.blur(); } });
|
|
81
|
+
}
|
|
82
|
+
function StatusBadge({ status }) {
|
|
83
|
+
const t = useWords();
|
|
84
|
+
return status === "published" ? _jsx(Badge, { tone: "success", children: t("builder.published") }) : _jsx(Badge, { tone: "warning", children: t("builder.draft") });
|
|
85
|
+
}
|
|
86
|
+
export function CourseBuilder({ courseId, canManage }) {
|
|
87
|
+
const t = useWords();
|
|
88
|
+
const [course, setCourse] = useState(null);
|
|
89
|
+
const [details, setDetails] = useState(null);
|
|
90
|
+
const [sections, setSections] = useState([]);
|
|
91
|
+
const [lessons, setLessons] = useState([]);
|
|
92
|
+
const [quizzes, setQuizzes] = useState([]);
|
|
93
|
+
const [collectionIds, setCollectionIds] = useState({});
|
|
94
|
+
/** The Payments price field on courses, when the owner has added one. Courses are sold through it. */
|
|
95
|
+
const [priceField, setPriceField] = useState(null);
|
|
96
|
+
const priceRef = useRef(null);
|
|
97
|
+
const [error, setError] = useState(null);
|
|
98
|
+
const [notice, setNotice] = useState(null);
|
|
99
|
+
const [busy, setBusy] = useState(false);
|
|
100
|
+
const load = useCallback(() => fetchCourse(courseId, priceRef.current).then(({ course: loaded, sections: sectionRows, lessons: lessonRows, quizzes: quizRows }) => {
|
|
101
|
+
setCourse(loaded);
|
|
102
|
+
setDetails((current) => current ?? loaded);
|
|
103
|
+
setSections(sectionRows);
|
|
104
|
+
setLessons(lessonRows);
|
|
105
|
+
setQuizzes(quizRows);
|
|
106
|
+
}), [courseId]);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
// The collections first, so the course is read with its price field when it has one.
|
|
109
|
+
call("/collections").then((rows) => {
|
|
110
|
+
setCollectionIds(Object.fromEntries(rows.map((row) => [row.slug, Number(row.id)])));
|
|
111
|
+
priceRef.current = rows.find((row) => row.slug === "lms-courses")?.fields?.find((field) => field.type === "payments_price")?.name ?? null;
|
|
112
|
+
setPriceField(priceRef.current);
|
|
113
|
+
}, () => setCollectionIds({})).then(load).catch((err) => setError(err.message));
|
|
114
|
+
}, [load]);
|
|
115
|
+
/** Runs a change, then reloads, so what shows is always what was saved. */
|
|
116
|
+
const run = async (work, done) => {
|
|
117
|
+
setBusy(true);
|
|
118
|
+
setError(null);
|
|
119
|
+
setNotice(null);
|
|
120
|
+
try {
|
|
121
|
+
await work();
|
|
122
|
+
if (done)
|
|
123
|
+
setNotice(done);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
setError(err instanceof ApiError ? err.message : t("builder.wrong"));
|
|
127
|
+
}
|
|
128
|
+
await load().catch(() => undefined);
|
|
129
|
+
setBusy(false);
|
|
130
|
+
};
|
|
131
|
+
const editorHref = (slug, id) => (collectionIds[slug] ? adminPath(`/collections/${collectionIds[slug]}/content/${id}`) : null);
|
|
132
|
+
const editLink = (slug, id, children) => {
|
|
133
|
+
const href = editorHref(slug, id);
|
|
134
|
+
return href ? _jsx("a", { className: "cms-link", href: href, children: children }) : null;
|
|
135
|
+
};
|
|
136
|
+
if (!course || !details) {
|
|
137
|
+
return _jsx("div", { className: "cms-gutter", children: error ? _jsx(Alert, { children: error }) : _jsx(PageSkeleton, { kind: "detail" }) });
|
|
138
|
+
}
|
|
139
|
+
const set = (name, value) => setDetails({ ...details, [name]: value });
|
|
140
|
+
const saveDetails = (event) => {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
const body = { title: details.title, summary: details.summary ?? "", access: details.access, level: details.level || null, estimatedMinutes: details.estimatedMinutes ?? null };
|
|
143
|
+
if (canManage)
|
|
144
|
+
body.byline = details.byline ?? "";
|
|
145
|
+
// Only a paid course keeps a price.
|
|
146
|
+
if (priceField)
|
|
147
|
+
body[priceField] = details.access === "paid" ? details.price ?? null : null;
|
|
148
|
+
void run(async () => { await update("lms-courses", courseId, body); setDetails(null); }, t("builder.detailsSaved"));
|
|
149
|
+
};
|
|
150
|
+
const groups = [
|
|
151
|
+
...sections.map((section) => ({ section, lessons: lessons.filter((lesson) => lesson.section === section.id) })),
|
|
152
|
+
{ section: null, lessons: lessons.filter((lesson) => !sections.some((section) => section.id === lesson.section)) },
|
|
153
|
+
];
|
|
154
|
+
const addQuiz = (lesson) => run(async () => {
|
|
155
|
+
const quiz = await create("lms-quizzes", { title: t("builder.quizTitle", { lesson: lesson.title }).slice(0, 200), lesson: lesson.id });
|
|
156
|
+
// The quiz shows where a Quiz block places it, so put one at the end of the lesson.
|
|
157
|
+
const stored = await call(`${records("lms-lessons")}/${lesson.id}?fields=content`);
|
|
158
|
+
const content = Array.isArray(stored.content) ? stored.content : [];
|
|
159
|
+
await update("lms-lessons", lesson.id, { content: [...content, { id: crypto.randomUUID(), type: "lms_quiz", v: 1, value: { quiz: quiz.id } }] });
|
|
160
|
+
}, t("builder.quizAdded"));
|
|
161
|
+
const lessonRow = (lesson, index, siblings) => {
|
|
162
|
+
const quiz = quizzes.find((candidate) => candidate.lesson === lesson.id);
|
|
163
|
+
return (_jsxs("li", { className: "lms-admin-lesson", children: [_jsx(Mover, { label: lesson.title, index: index, count: siblings.length, disabled: busy, onMove: (to) => run(() => renumber("lms-lessons", move(siblings, index, to))) }), _jsxs("div", { className: "lms-admin-lesson-main", children: [_jsx(TitleInput, { value: lesson.title, label: t("builder.lessonTitle"), disabled: busy, onSave: (title) => run(() => update("lms-lessons", lesson.id, { title })) }), _jsxs("div", { className: "lms-admin-meta", children: [_jsx(StatusBadge, { status: lesson.status }), lesson.preview && _jsx(Badge, { tone: "info", children: t("builder.freePreview") }), quiz ? _jsxs("span", { children: [t("builder.quiz"), " ", editLink("lms-quizzes", quiz.id, quiz.title)] }) : _jsx("button", { type: "button", className: "cms-link", disabled: busy, onClick: () => addQuiz(lesson), children: t("builder.addQuiz") })] })] }), _jsxs("div", { className: "lms-admin-actions", children: [editLink("lms-lessons", lesson.id, t("builder.editContent")), sections.length > 0 && (_jsxs("select", { className: "cms-input lms-admin-select", "aria-label": t("builder.sectionFor", { lesson: lesson.title }), value: lesson.section ?? "", disabled: busy, onChange: (event) => {
|
|
164
|
+
const section = event.target.value ? Number(event.target.value) : null;
|
|
165
|
+
void run(() => update("lms-lessons", lesson.id, { section, position: nextPosition(lessons.filter((other) => other.section === section)) }));
|
|
166
|
+
}, children: [_jsx("option", { value: "", children: t("builder.noSection") }), sections.map((section) => _jsx("option", { value: section.id, children: section.title }, section.id))] })), _jsx(Button, { variant: "secondary", disabled: busy, onClick: () => run(() => update("lms-lessons", lesson.id, { preview: !lesson.preview })), children: lesson.preview ? t("builder.removePreview") : t("builder.makePreview") }), _jsx(Button, { variant: "secondary", disabled: busy, onClick: () => run(() => update("lms-lessons", lesson.id, { status: lesson.status === "published" ? "draft" : "published" })), children: lesson.status === "published" ? t("builder.unpublish") : t("builder.publish") }), _jsx(Button, { variant: "danger", disabled: busy, onClick: () => { if (window.confirm(t("builder.confirmDeleteLesson", { lesson: lesson.title })))
|
|
167
|
+
void run(() => remove("lms-lessons", lesson.id), t("builder.lessonDeleted")); }, children: t("builder.delete") })] })] }, lesson.id));
|
|
168
|
+
};
|
|
169
|
+
const published = course.status === "published";
|
|
170
|
+
return (_jsxs("div", { className: "cms-gutter lms-admin", children: [_jsx(PageHeader, { back: { href: adminPath("/ext/lms/courses"), label: t("builder.backToCourses") }, title: course.title || t("common.course", { id: course.id }), meta: _jsxs(_Fragment, { children: [_jsx(StatusBadge, { status: course.status }), _jsx("span", { children: t("builder.counts", { lessons: lessons.length, sections: sections.length }) })] }), actions: (_jsxs(_Fragment, { children: [editLink("lms-courses", courseId, t("builder.coverAndDescription")), _jsx(Button, { disabled: busy, variant: published ? "secondary" : "primary", onClick: () => run(() => update("lms-courses", courseId, { status: published ? "draft" : "published" }), published ? t("builder.draftAgain") : t("builder.nowPublished")), children: published ? t("builder.unpublishCourse") : t("builder.publishCourse") })] })) }), error && _jsx("div", { className: "cms-mb-4", children: _jsx(Alert, { children: error }) }), notice && _jsx("div", { className: "cms-mb-4", children: _jsx(Alert, { kind: "success", children: notice }) }), _jsxs("div", { className: "lms-admin-grid", children: [_jsxs("section", { className: "cms-panel lms-admin-panel", "aria-labelledby": "lms-curriculum", children: [_jsx("h2", { id: "lms-curriculum", className: "cms-section-title cms-mb-4", children: t("builder.curriculum") }), groups.map(({ section, lessons: inGroup }) => (section || inGroup.length > 0) && (_jsxs("div", { className: "lms-admin-section", children: [_jsx("div", { className: "lms-admin-section-head", children: section ? (_jsxs(_Fragment, { children: [_jsx(Mover, { label: section.title, index: sections.indexOf(section), count: sections.length, disabled: busy, onMove: (to) => run(() => renumber("lms-sections", move(sections, sections.indexOf(section), to))) }), _jsx(TitleInput, { value: section.title, label: t("builder.sectionTitle"), disabled: busy, onSave: (title) => run(() => update("lms-sections", section.id, { title })) }), _jsx(Button, { variant: "danger", disabled: busy || inGroup.length > 0, title: inGroup.length ? t("builder.moveLessonsFirst") : undefined, onClick: () => { if (window.confirm(t("builder.confirmDeleteSection", { section: section.title })))
|
|
171
|
+
void run(() => remove("lms-sections", section.id), t("builder.sectionDeleted")); }, children: t("builder.deleteSection") })] })) : _jsx("strong", { className: "cms-muted", children: t("builder.notInSection") }) }), inGroup.length > 0 ? _jsx("ol", { className: "lms-admin-lessons", children: inGroup.map((lesson, index) => lessonRow(lesson, index, inGroup)) }) : _jsx("p", { className: "cms-muted cms-text-sm", children: t("builder.noLessons") }), section && _jsx(AddForm, { label: t("builder.addLesson"), placeholder: t("builder.newLesson"), disabled: busy, onAdd: (title) => run(() => create("lms-lessons", { title, course: courseId, section: section.id, position: nextPosition(inGroup) }), t("builder.lessonAdded")) })] }, section?.id ?? "none"))), sections.length === 0 && lessons.length === 0 && _jsx("p", { className: "cms-muted cms-mb-4", children: t("builder.start") }), _jsxs("div", { className: "lms-admin-section", children: [_jsx(AddForm, { label: t("builder.addSection"), placeholder: t("builder.newSection"), disabled: busy, onAdd: (title) => run(() => create("lms-sections", { title, course: courseId, position: nextPosition(sections) }), t("builder.sectionAdded")) }), sections.length === 0 && _jsx(AddForm, { label: t("builder.addLesson"), placeholder: t("builder.lessonWithoutSection"), disabled: busy, onAdd: (title) => run(() => create("lms-lessons", { title, course: courseId, position: nextPosition(lessons) }), t("builder.lessonAdded")) })] })] }), _jsxs("form", { className: "cms-panel lms-admin-panel cms-stack-4", onSubmit: saveDetails, "aria-labelledby": "lms-details", children: [_jsx("h2", { id: "lms-details", className: "cms-section-title", children: t("builder.details") }), _jsx(Field, { label: t("builder.title"), children: _jsx(Input, { required: true, maxLength: 200, value: details.title ?? "", onChange: (event) => set("title", event.target.value) }) }), _jsx(Field, { label: t("builder.summary"), hint: t("builder.summaryHint"), children: _jsx("textarea", { className: "cms-input", rows: 3, maxLength: 500, value: details.summary ?? "", onChange: (event) => set("summary", event.target.value) }) }), _jsx(Field, { label: t("builder.whoCanEnroll"), children: _jsxs("select", { className: "cms-input", value: details.access ?? "free", onChange: (event) => set("access", event.target.value), children: [_jsx("option", { value: "free", children: t("builder.accessFree") }), _jsx("option", { value: "paid", children: t("builder.accessPaid") }), _jsx("option", { value: "enrollment", children: t("builder.accessEnrollment") })] }) }), details.access === "paid" && (priceField
|
|
172
|
+
? _jsx(Field, { label: t("builder.price"), hint: t("builder.priceHint"), children: _jsx(Input, { type: "number", required: true, min: 0.01, step: 0.01, value: details.price ?? "", onChange: (event) => set("price", event.target.value === "" ? null : Number(event.target.value)) }) })
|
|
173
|
+
: _jsx(Alert, { children: t("builder.noPayments") })), _jsx(Field, { label: t("builder.level"), children: _jsxs("select", { className: "cms-input", value: details.level ?? "", onChange: (event) => set("level", event.target.value), children: [_jsx("option", { value: "", children: t("builder.notSet") }), _jsx("option", { value: "beginner", children: t("builder.beginner") }), _jsx("option", { value: "intermediate", children: t("builder.intermediate") }), _jsx("option", { value: "advanced", children: t("builder.advanced") })] }) }), _jsx(Field, { label: t("builder.minutes"), children: _jsx(Input, { type: "number", min: 0, step: 1, value: details.estimatedMinutes ?? "", onChange: (event) => set("estimatedMinutes", event.target.value === "" ? null : Number(event.target.value)) }) }), _jsx(Field, { label: t("builder.taughtBy"), hint: canManage ? t("builder.taughtByManager") : t("builder.taughtByOwn"), children: _jsx(Input, { maxLength: 200, value: details.byline ?? "", disabled: !canManage, onChange: (event) => set("byline", event.target.value) }) }), _jsx("div", { children: _jsx(Button, { type: "submit", loading: busy, children: t("builder.saveDetails") }) })] })] })] }));
|
|
174
|
+
}
|
|
175
|
+
/** Creates a draft course and opens it in the builder. */
|
|
176
|
+
export function NewCourse() {
|
|
177
|
+
const t = useWords();
|
|
178
|
+
const [open, setOpen] = useState(false);
|
|
179
|
+
const [busy, setBusy] = useState(false);
|
|
180
|
+
const [error, setError] = useState(null);
|
|
181
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: () => setOpen(true), children: t("courses.create") }), _jsx(Modal, { open: open, onClose: () => setOpen(false), title: t("courses.create"), children: _jsxs("div", { className: "cms-stack-4", children: [_jsx(AddForm, { label: t("courses.create"), placeholder: t("courses.newTitle"), disabled: busy, onAdd: async (title) => {
|
|
182
|
+
setBusy(true);
|
|
183
|
+
setError(null);
|
|
184
|
+
try {
|
|
185
|
+
const course = await create("lms-courses", { title });
|
|
186
|
+
window.location.href = adminPath(`/ext/lms/courses/${course.id}`);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
setError(err instanceof ApiError ? err.message : t("courses.notCreated"));
|
|
190
|
+
setBusy(false);
|
|
191
|
+
}
|
|
192
|
+
} }), error && _jsx(Alert, { children: error })] }) })] }));
|
|
193
|
+
}
|
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAdminClient, translate } from "tansy/admin";
|
|
2
|
+
import { blockEditors } from "./editors";
|
|
3
|
+
import { BuilderPanel, enrollByEmail } from "./outline";
|
|
4
|
+
export default defineAdminClient({
|
|
5
|
+
recordActions: [{
|
|
6
|
+
id: "lms-enroll",
|
|
7
|
+
label: "Enroll users",
|
|
8
|
+
permission: "ext.lms:enroll",
|
|
9
|
+
collections: ["lms-courses"],
|
|
10
|
+
run: async ({ record }) => {
|
|
11
|
+
const typed = window.prompt(translate("ext.lms.enroll.prompt"));
|
|
12
|
+
if (!typed?.trim())
|
|
13
|
+
return;
|
|
14
|
+
window.alert(await enrollByEmail(Number(record.id), typed));
|
|
15
|
+
},
|
|
16
|
+
}],
|
|
17
|
+
recordPanels: [{ id: "lms-builder", component: BuilderPanel }],
|
|
18
|
+
blockEditors,
|
|
19
|
+
});
|
package/editors.d.ts
ADDED
package/editors.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useT } from "tansy/admin";
|
|
4
|
+
import { embedUrl } from "./logic";
|
|
5
|
+
import "./lms.css";
|
|
6
|
+
/*
|
|
7
|
+
* The lesson and quiz blocks on the editor's canvas, built from the same markup and
|
|
8
|
+
* classes as render.tsx, so they look as they will on the site and are edited in place.
|
|
9
|
+
*/
|
|
10
|
+
const text = (value) => (typeof value === "string" ? value : "");
|
|
11
|
+
function TextEditor({ Field }) {
|
|
12
|
+
const { t } = useT();
|
|
13
|
+
return _jsx(Field, { name: "body", placeholder: t("ext.lms.editors.startWriting") });
|
|
14
|
+
}
|
|
15
|
+
function VideoEditor({ block, selected, Field }) {
|
|
16
|
+
const { t } = useT();
|
|
17
|
+
const file = text(block.value.file);
|
|
18
|
+
const src = embedUrl(text(block.value.url));
|
|
19
|
+
const hasTranscript = block.value.transcript !== undefined && block.value.transcript !== null;
|
|
20
|
+
return (_jsxs("figure", { className: "lms-figure", children: [file
|
|
21
|
+
? _jsx(Field, { name: "file" })
|
|
22
|
+
: src
|
|
23
|
+
// Inert until selected, so a click selects the block rather than playing the video.
|
|
24
|
+
? _jsx("div", { className: "lms-embed", inert: !selected, children: _jsx("iframe", { src: src, title: text(block.value.title) || t("ext.lms.editors.video"), loading: "lazy", allow: "encrypted-media; picture-in-picture; fullscreen", referrerPolicy: "strict-origin-when-cross-origin", sandbox: "allow-scripts allow-same-origin allow-presentation" }) })
|
|
25
|
+
: (_jsxs("div", { className: "lms-editor-placeholder", children: [_jsx(Field, { name: "file", placeholder: t("ext.lms.editors.uploadVideo") }), _jsx("p", { className: "lms-muted", children: t("ext.lms.editors.orPaste") }), _jsx(Field, { name: "url" })] })), selected && _jsx("div", { className: "lms-editor-note", children: _jsx(Field, { name: "title", placeholder: t("ext.lms.editors.videoTitle") }) }), (selected || hasTranscript) && (_jsxs("details", { open: true, children: [_jsx("summary", { children: t("ext.lms.editors.transcript") }), _jsx(Field, { name: "transcript", placeholder: t("ext.lms.editors.addTranscript") })] }))] }));
|
|
26
|
+
}
|
|
27
|
+
function DownloadEditor({ block, selected, Field }) {
|
|
28
|
+
const { t } = useT();
|
|
29
|
+
const file = text(block.value.file);
|
|
30
|
+
return (_jsxs("div", { children: [_jsxs("div", { className: "lms-download lms-download-edit", children: [_jsx("span", { "aria-hidden": "true", children: "\u2193" }), _jsx(Field, { name: "label", placeholder: t("ext.lms.editors.download") })] }), (selected || !file) && _jsx(Field, { name: "file", placeholder: t("ext.lms.editors.downloadFile") })] }));
|
|
31
|
+
}
|
|
32
|
+
/** Choices as rows, each with a control to mark it correct, writing `choices` and `correct` as the grader reads them. */
|
|
33
|
+
function QuestionEditor({ block, selected, setField, Field }) {
|
|
34
|
+
const { t } = useT();
|
|
35
|
+
const kind = block.value.kind === "multiple" || block.value.kind === "short" ? block.value.kind : "single";
|
|
36
|
+
const choices = Array.isArray(block.value.choices) ? block.value.choices.map((choice) => (typeof choice === "string" ? choice : "")) : [];
|
|
37
|
+
const correct = block.value.correct;
|
|
38
|
+
const marked = (Array.isArray(correct) ? correct : [correct]).filter((item) => typeof item === "number");
|
|
39
|
+
const accepted = (Array.isArray(correct) ? correct : [correct]).filter((item) => typeof item === "string");
|
|
40
|
+
const setChoices = (next, nextMarked = marked) => {
|
|
41
|
+
setField("choices", next.length ? next : "");
|
|
42
|
+
const kept = nextMarked.filter((index) => index < next.length);
|
|
43
|
+
setField("correct", kind === "multiple" ? (kept.length ? kept : "") : kept[0] ?? "");
|
|
44
|
+
};
|
|
45
|
+
const mark = (index) => {
|
|
46
|
+
if (kind === "multiple")
|
|
47
|
+
setField("correct", marked.includes(index) ? marked.filter((item) => item !== index) : [...marked, index].sort((a, b) => a - b));
|
|
48
|
+
else
|
|
49
|
+
setField("correct", index);
|
|
50
|
+
};
|
|
51
|
+
const remove = (index) => setChoices(choices.filter((_, at) => at !== index), marked.filter((item) => item !== index).map((item) => (item > index ? item - 1 : item)));
|
|
52
|
+
return (_jsxs("div", { className: "lms-question-edit", children: [_jsx("div", { className: "lms-question-prompt", children: _jsx(Field, { name: "prompt", placeholder: t("ext.lms.editors.ask") }) }), kind === "short" ? (_jsxs("label", { className: "lms-editor-note", children: [t("ext.lms.editors.accepted"), _jsx("textarea", { className: "lms-editor-input", rows: Math.max(2, accepted.length + 1), value: accepted.join("\n"), onChange: (event) => {
|
|
53
|
+
const lines = event.target.value.split("\n");
|
|
54
|
+
setField("correct", lines.some((line) => line.trim()) ? lines : "");
|
|
55
|
+
} })] })) : (_jsxs("ol", { className: "lms-choices-edit", children: [choices.map((choice, index) => (_jsxs("li", { children: [_jsx("input", { type: kind === "multiple" ? "checkbox" : "radio", name: `correct-${block.id}`, checked: marked.includes(index), onChange: () => mark(index), "aria-label": t("ext.lms.editors.choiceCorrect", { number: index + 1 }), title: t("ext.lms.editors.correct") }), _jsx("input", { className: "lms-editor-input", value: choice, placeholder: t("ext.lms.editors.choice", { number: index + 1 }), "aria-label": t("ext.lms.editors.choice", { number: index + 1 }), onChange: (event) => setChoices(choices.map((item, at) => (at === index ? event.target.value : item))) }), selected && _jsx("button", { type: "button", className: "lms-editor-remove", "aria-label": t("ext.lms.editors.removeChoice", { number: index + 1 }), onClick: () => remove(index), children: "\u00D7" })] }, index))), (selected || !choices.length) && _jsx("li", { children: _jsx("button", { type: "button", className: "lms-editor-add", onClick: () => setChoices([...choices, ""]), children: t("ext.lms.editors.addChoice") }) })] })), (selected || (block.value.explanation !== undefined && block.value.explanation !== null)) && (_jsxs("details", { open: true, children: [_jsx("summary", { children: t("ext.lms.editors.explanation") }), _jsx(Field, { name: "explanation", placeholder: t("ext.lms.editors.why") })] }))] }));
|
|
56
|
+
}
|
|
57
|
+
export const blockEditors = [
|
|
58
|
+
{ blocks: ["lms_text"], component: TextEditor },
|
|
59
|
+
{ blocks: ["lms_video"], component: VideoEditor },
|
|
60
|
+
{ blocks: ["lms_download"], component: DownloadEditor },
|
|
61
|
+
{ blocks: ["lms_question"], component: QuestionEditor },
|
|
62
|
+
];
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface LmsOptions {
|
|
2
|
+
/** The prefix of course addresses, read on first install. After that, edit URL patterns in the dashboard. */
|
|
3
|
+
basePath?: string;
|
|
4
|
+
/** Percent needed to pass a quiz, until changed under LMS → Settings. Each quiz can set its own. */
|
|
5
|
+
passingScore?: number;
|
|
6
|
+
/** Issue a certificate when a course is completed, until changed under LMS → Settings. */
|
|
7
|
+
certificates?: boolean;
|
|
8
|
+
/** Whether a course counts as completed only once its quizzes are passed, until changed under LMS → Settings. */
|
|
9
|
+
requireQuizzes?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Turns the CMS into a learning platform: courses, lessons, enrollments, progress, quizzes and certificates. See docs/plugins/lms.md. */
|
|
12
|
+
export declare function lms(options?: LmsOptions): import("tansy/plugin").CmsPlugin;
|