@eliceio/cdk-cli 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/es/commands/create/index.js +1 -0
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/doctor/index.js +19 -2
- package/es/core/sandbox.js +1 -1
- package/es/rules/check.js +19 -2
- package/es/rules/grading.d.ts +25 -0
- package/es/rules/grading.js +131 -0
- package/es/rules/privacy.d.ts +2 -0
- package/es/rules/privacy.js +1 -1
- package/es/rules.json.js +1 -1
- package/package.json +2 -2
- package/rules.json +13 -1
- package/skills/_shared/references/02-design-the-material.md +1 -0
- package/skills/_shared/references/05-screen-code.md +26 -0
- package/skills/_shared/references/08-fix-check-errors.md +3 -1
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -0
- package/skills/_shared/references/13-edit-screen-design.md +1 -1
- package/skills/elice-content-create/SKILL.md +1 -1
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/elice-content.d.ts +45 -0
- package/templates/_shared/lib/elice-content.js +133 -5
- package/templates/video/README.md +68 -0
- package/templates/video/commentary.txt +2 -0
- package/templates/video/core/dom.d.ts +13 -0
- package/templates/video/core/dom.js +83 -0
- package/templates/video/core/settings.d.ts +19 -0
- package/templates/video/core/settings.js +52 -0
- package/templates/video/edit.html +17 -0
- package/templates/video/gitignore +4 -0
- package/templates/video/index.html +17 -0
- package/templates/video/metadata.json +9 -0
- package/templates/video/package.json +13 -0
- package/templates/video/screens/edit.js +69 -0
- package/templates/video/screens/learn.js +46 -0
- package/templates/video/styles.css +112 -0
- package/templates/video/template.json +6 -0
- package/templates/video/ui/templates/edit.js +26 -0
- package/templates/video/ui/templates/player.js +51 -0
- package/templates/video/ui/texts.d.ts +3 -0
- package/templates/video/ui/texts.js +50 -0
- package/templates/video/ui/theme.css +14 -0
|
@@ -19,10 +19,12 @@ Read `check.issues[]` (`id` · `level` · `path` · `line` · `message`) from `e
|
|
|
19
19
|
| `sec.secret` · `file.secret` | Remove the secret or the answer file (if it was already uploaded, tell the user to **revoke the key**) |
|
|
20
20
|
| `manifest.completion-policies-ignored` (warn) | Remove the old `completionPolicies` and `screens.completionPolicy` from `metadata.json` (and the completion policy screen files). The instructor picks the policy in the '설정' panel at the top of the LXP edit page |
|
|
21
21
|
| `grading.no-submit` (warn) | The edit screen saves the grading but nothing submits: add `useSubmit` to the student screen, or drop the grading block when the material is not graded |
|
|
22
|
+
| `grading.client-score` (warn) | The submitted answer (a `submit(` argument, `useSubmit`'s `getAnswer`) has a `score` · `scores` · `points` key. The server never uses a score inside the answer and puts the whole answer into the AI grading prompt: submit only the learner's answer and grade with `settings.grading` ([5](05-screen-code.md) "AI grading"). `ecdk-ignore` only for code that shows a score and does not submit it, with the reason |
|
|
23
|
+
| `grading.ai-without-grading` (warn) | The screens call `mlapi.fetch` and submit, but nothing saves `settings.grading`. Build the rubric on the edit screen: `useSave({ …, getGrading: () => ({ type: 'rubric', rubric: criteriaToRubric(content) }) })` and submit only the answer ([5](05-screen-code.md) "AI grading"). AI feedback that is only shown, with no grading: `ecdk-ignore-next-line grading.ai-without-grading` on the `mlapi.fetch` line with the reason, and `on_submit` on purpose (scores do not reflect the AI) |
|
|
22
24
|
| `project.legacy-file` (warn, project only) | An old `elice.config.json` · `content.json` · `grading.json` is left: `ecdk doctor --fix` moves `elice.config.json`; re-enter the content and answers in the edit screen, then delete the other files |
|
|
23
25
|
| `sdk.outdated` (error) | The installed SDK bundled into the zip is older than the minimum (1.0.0-alpha.3 or older cannot save in the LXP edit screen - draft save fails): `npm update @eliceio/cdk`, then build again |
|
|
24
26
|
| `project.deps` (doctor) · "@eliceio/cdk 패키지를 찾지 못했습니다" | The SDK package is not installed in the project: run `npm install` in the project, then build again |
|
|
25
|
-
| `project.grading` (doctor) | The saved `.ecdk/settings.json` `grading` breaks the server's save rules or does not match the public `gradingType`. Have the person open the edit view in `ecdk dev`, fix the marked field (points, answers) and save again; if you edited the file by hand, correct those values ([15](15-edit-settings-by-hand.md)). Never delete the file: the content goes with it
|
|
27
|
+
| `project.grading` (doctor) | The saved `.ecdk/settings.json` `grading` breaks the server's save rules or does not match the public `gradingType`. Have the person open the edit view in `ecdk dev`, fix the marked field (points, answers) and save again; if you edited the file by hand, correct those values ([15](15-edit-settings-by-hand.md)). Never delete the file: the content goes with it. It warns when the settings hold AI evaluation config (`criteria` · `apiId`) but no `grading`: save a `rubric` with the edit screen's `getGrading` ([5](05-screen-code.md) "AI grading") |
|
|
26
28
|
| `project.quiz` (doctor, quiz template) | The saved questions, answers or points do not pass the quiz edit screen's own checks (run with the project's `core/model.js`): answers or scores left in the old question order, `points` ≠ `scores`, an answer pointing at a deleted option, a missing `gradingType`, a regex the edit screen cannot read (a text answer in the wrong shape for the project's template version), quiz 1.10.0+: a regex answer not in the stored shape or with a blocked syntax, an answer regex over 500 characters, `answerFormat` · `requires` · `answerMode` the project's template does not know, text answers that look as typed (or a regex question) but `answerFormat` is missing, `answerFormat` 2 with URL-encoded text answers (saved again by a 1.9.x edit screen) - for these two, students typing 한글, spaces or `%` are marked wrong: have the person press "초안으로 저장" once in the edit view and the answers are saved again in the right shape. A warning (`warn`): tags written in snake_case (`answer_format` · `answer_mode`). Fix as [15](15-edit-settings-by-hand.md) says, run `ecdk doctor` again, then have the person save once in the edit view ("초안으로 저장") |
|
|
27
29
|
| `build.template-unknown` (warn) | The material was made with a template or template version this ecdk does not know. Update ecdk (`npm i -g @eliceio/cdk-cli`) or check `template` in `package.json` `"ecdk"` |
|
|
28
30
|
| `manifest.*` · `entry.*` | Check `screens` and `kind` in `metadata.json` |
|
|
@@ -74,6 +74,7 @@ The completion policy is not in the project or the zip (ADR 0012): it is a setti
|
|
|
74
74
|
|
|
75
75
|
- Show the proposal in the target summary and the approval (on a page that already has a policy, show the current one too; changing it needs the yes). Send it only after an explicit yes.
|
|
76
76
|
- **`on_graded` needs grading saved first** (the server answers `MATERIAL_GRADING_REQUIRED` otherwise). Send `on_graded` in the same save only together with `settings` that include `grading` (the server takes `settings` and the person agreed), or when the page already has grading (`get_material` shows it).
|
|
77
|
+
- **AI grading: check `grading` before `on_graded`.** Before a `save_draft` (or `update_material`) with `completion_policy: on_graded`, check that the settings you send (or the page's settings in `get_material`) contain `grading`. A material that grades with AI (its screens call `mlapi.fetch` to evaluate the answer, its content has evaluation criteria such as `criteria: [{ name, points, description }]`, or `ecdk validate` warns `grading.ai-without-grading` · `grading.client-score`) and has no `grading`: stop and fix it first. The edit screen saves `settings.grading = { type: 'rubric', rubric: <text built from the criteria> }` through `useSave`'s `getGrading`, the learn screen submits only the learner's answer, then save again in the `ecdk dev` edit view ([5](05-screen-code.md) "AI grading"). Never publish `on_graded` without grading: every submission would score 0 and never complete. When the AI only gives feedback on screen and nothing is graded, use `on_submit` deliberately and tell the person the scores will not reflect the AI result (every submission is 100).
|
|
77
78
|
- **Without settings** (the server has no `settings`, no file, or the person said no): do not send `on_graded` at the first save. Send no policy, or `on_submit` only if the person wants learners to complete by submitting until the answers exist (ask). Then the person enters the answers on the LXP edit screen and applies them with '수업 자료에 반영'; afterwards either the person picks 답안 확인 후 완료 in the '설정' panel, or, if `update_material` takes `completion_policy`, offer to set `on_graded` through the MCP once `get_material` shows the grading.
|
|
78
79
|
- **Only `on_graded` grades.** `on_submit` completes on any submission and does not grade: the submission comes back `is_correct: null`, `score: 100`, and the kit shows "제출했어요.". `on_access` completes on open. Saved answers are used only with `on_graded`; say so in the report so the person does not think grading is broken.
|
|
79
80
|
- Answers never go into the zip: only in `settings.grading`, sent with the save above or entered on the edit screen.
|
|
@@ -4,7 +4,7 @@ Every content edit screen (CMS) looks the same: the designer's edit-screen desig
|
|
|
4
4
|
|
|
5
5
|
## Layout rules
|
|
6
6
|
|
|
7
|
-
1. `<body class="ec-edit-page">` on `edit.html` (the content editor adds it itself): gray page, white cards, the save bar from `app.useSave` fixed white at the bottom with a top line. Content sits in the kit's centered `main` column (720px) by default. A material whose main editing surface is a wide visual (slides with a thumbnail strip) may widen `main` with its own token (like the document template's `--dc-max-width: 1120px`); never
|
|
7
|
+
1. `<body class="ec-edit-page">` on `edit.html` (the content editor adds it itself): gray page, white cards, the save bar from `app.useSave` fixed white at the bottom with a top line. Content sits in the kit's centered `main` column (720px) by default. A material whose main editing surface is a wide visual (slides with a thumbnail strip) may widen `main` with its own token (like the document template's `--dc-max-width: 1120px`). Only a material whose whole edit screen is one media field (the video template: upload, then the player preview) fills the width (`main { max-width: none }`, save bar `padding-inline: 16px`); a form of questions or options never does. Keep the template's own save button label (`useSave({ label })`, for example the quiz's '초안에 반영'); do not rename it.
|
|
8
8
|
2. **Top: title and description of the material**, in one card `.ec-edit-card.ec-edit-info` with underline fields and no visible labels (title `.ec-field-title`, description `.ec-field-body`). An always-true hint about how the screen works goes above it as one `.ec-info-line` (ⓘ, for example "정답으로 고른 보기로 자동 채점합니다."); a hint the person must read first goes in `.ec-edit-notice` (light purple box).
|
|
9
9
|
3. **One card per item** (question, step, slide, uploaded file): `.ec-edit-card`. Head `.ec-edit-card-head`: name in bold ("문항 1"), then a type `<select>` if the item has types, then on the right the bordered icon buttons ↑ · ↓ · trash (`button.ec-icon-button`, `aria-label` always). Hide ↑ · ↓ when there is one card. Below the last card a dashed full-width `button.ec-add` ("+ 문항 추가").
|
|
10
10
|
4. **Underline fields, placeholder as the label**: `.ec-field` + `input.ec-field-input` / `textarea.ec-field-input` with `placeholder` and `aria-label` (sizes `.ec-field-title` · `.ec-field-question` · `.ec-field-body`). A field whose meaning is not clear from its place (unit, value, file language) gets a small label above: `.ec-field-label` (+ `.ec-required` "\*" or `.ec-optional` "선택"), and a hint `.ec-field-hint`. Character count `.ec-field-count` shows only while the field has focus. An empty required field on save: `aria-invalid="true"` (red underline) and focus it.
|
|
@@ -13,7 +13,7 @@ Reference files are in `references/` in this skill's folder (see Always). For a
|
|
|
13
13
|
|
|
14
14
|
Write the progress line `[n/N] …` before and after every step below (Always › Progress); the person sees nothing else while you work.
|
|
15
15
|
|
|
16
|
-
1. **Design before code.** Read `references/00-what-the-person-decides.md` and `references/02-design-the-material.md`. Decide ① what the student does, ② whether the student submits and the grading (`type` `pattern` or `rubric`, set on the edit screen; the quiz template uses `pattern`, so do not ask for a quiz) and which completion policy fits (the publish skill sets it after the person agrees; only `on_graded` grades, `on_submit` completes on any submission without grading), ③ the instructor screen (seen only in the LXP editor preview; instructors on the learning page see the student screen), ④ the content edit screen, ⑤ the purpose. Decide what the request leaves out and tell the person briefly; ask only when the learning goal is unclear. Then show the numbered plan.
|
|
16
|
+
1. **Design before code.** Read `references/00-what-the-person-decides.md` and `references/02-design-the-material.md`. Decide ① what the student does, ② whether the student submits and the grading (`type` `pattern` or `rubric`, set on the edit screen; the quiz template uses `pattern`, so do not ask for a quiz; AI grading is `rubric` saved by the edit screen's `getGrading` and the student submits only the answer, never a score computed with `mlapi`, `references/05-screen-code.md` "AI grading") and which completion policy fits (the publish skill sets it after the person agrees; only `on_graded` grades, `on_submit` completes on any submission without grading), ③ the instructor screen (seen only in the LXP editor preview; instructors on the learning page see the student screen), ④ the content edit screen, ⑤ the purpose. Decide what the request leaves out and tell the person briefly; ask only when the learning goal is unclear. Then show the numbered plan.
|
|
17
17
|
2. **Environment and project.** `ecdk --version && ecdk doctor --json` (`references/01-check-the-environment.md`, also for `cli.latest`), then `ecdk create --list` to pick a template and `ecdk create <folder> --template <name>` (`references/03-create-the-project.md`; it runs `npm install` for the SDK, so when that fails run `npm install` in the project). Start `ecdk dev <folder>` in the background now and give the person the URL.
|
|
18
18
|
3. **Write the screens.** Start from the template's example code and the kit API table at the top of `references/05-screen-code.md`; do not open `lib/` to learn the API (the table is the API). Follow its UI patterns (kit icon buttons, list rows, drop zones; the quiz template: `references/06-using-the-quiz-template.md`); an edit screen you write by hand follows `references/13-edit-screen-design.md` (kit classes, layout, microcopy); when a student or instructor screen has nothing to show, always use `app.emptyState()`, never your own empty-state markup, illustration or text (`references/05-screen-code.md`, "Nothing to show"), and write `commentary.txt` (key concepts and intent, no answers). There is no default content file: the content and answers are what the edit screen saves (`ecdk dev` writes `.ecdk/settings.json`, local by default; the elice-content-publish skill can send it with the upload after the person agrees, otherwise the person enters it in the LXP edit screen).
|
|
19
19
|
- For a material that is not a quiz, start from the blank template and its content editor: design the content JSON shape and its schema first (`references/02-design-the-material.md` ④-1), put them in `screens/edit.js` (`useContentEditor(app, { initial, schema })`), then write the student screen against that shape. Replace the template's example everywhere it says `이 자료에 맞게 바꿀 곳`.
|
|
@@ -14,7 +14,7 @@ Reference files are in `references/` in this skill's folder (see Always). Read `
|
|
|
14
14
|
1. **MCP ready?** The `elice-material` tools must be available. If not, ask the person to run `ecdk setup --only mcp` and log in (Claude Code `/mcp` → elice-material → Authenticate, Helpy Code `⌘ ;`), then stop.
|
|
15
15
|
2. **Build.** `ecdk build --json` must return `ok: true`. Keep `zip` and `zipBytes`.
|
|
16
16
|
3. **Content and answers.** Check whether the input schema of `save_draft` (or `update_material`) lists `settings` as a key of `payload` (on an older server, a top-level parameter). If it does and this project has `.ecdk/settings.json`: make sure the edit screen saved it (the person saves the edit view in `ecdk dev`; a file you wrote by hand must go through that save), run `ecdk doctor` and send no `settings` while its `project.grading` or `project.quiz` check fails (tell the person why, never the answer values; they fix it in the edit view), show a short summary (title, number of questions or items, answers included or not and `grading.type`, never the answer values) and ask for an explicit yes to send it with the upload. `settings` replaces the page's settings as a whole: on a page that already has a version, compare `get_material`'s settings with the file first, and if keys would disappear or the LXP content differs (an instructor edited it in LXP), show the difference briefly and ask before overwriting (a new page needs no comparison). Adding images to a page that already has a version: merge its current settings (`get_material` or `get_draft`) into `.ecdk/settings.json` first, keeping `asset:` images as they are (`references/12-upload-with-the-material-mcp.md` item 8). No file: suggest filling the edit view in `ecdk dev` first, or skip it. No `settings` key, or the person says no: zip only (the fallback). Details: `references/12-upload-with-the-material-mcp.md` "Content and answers (settings)".
|
|
17
|
-
4. **Completion policy.** If `save_draft` (or `update_material`) lists `completion_policy` in its input schema (in `payload`), propose one (`references/12-upload-with-the-material-mcp.md` "Completion policy"): graded (the quiz template, or settings with `grading`) → `on_graded`, submits without grading → `on_submit`, no submission → `on_access`. `on_graded` only when the same save carries `settings` with `grading` (or the page already has grading); otherwise no policy at the first save, or `on_submit` if the person wants it (ask). Tell the person that only `on_graded` grades: `on_submit` completes on any submission without grading ("제출했어요."), `on_access` completes on open. The policy is a page setting and applies at once.
|
|
17
|
+
4. **Completion policy.** If `save_draft` (or `update_material`) lists `completion_policy` in its input schema (in `payload`), propose one (`references/12-upload-with-the-material-mcp.md` "Completion policy"): graded (the quiz template, or settings with `grading`) → `on_graded`, submits without grading → `on_submit`, no submission → `on_access`. `on_graded` only when the same save carries `settings` with `grading` (or the page already has grading); a material that grades with AI (`mlapi.fetch`, evaluation criteria) and has no `grading`: stop and fix it first (rubric from the criteria, `references/12-upload-with-the-material-mcp.md` "AI grading"), never `on_graded` without grading, and `on_submit` only on purpose for display-only AI feedback (tell the person scores won't reflect the AI); otherwise no policy at the first save, or `on_submit` if the person wants it (ask). Tell the person that only `on_graded` grades: `on_submit` completes on any submission without grading ("제출했어요."), `on_access` completes on open. The policy is a page setting and applies at once.
|
|
18
18
|
5. **Pick the page and confirm it.** Candidates: `.ecdk/link.json`, the LXP edit URL the person gives (`https://{org}.…/lecturepages/{id}/edit`), or the person's choice from `list_my_organizations` → `list_courses` → `list_lectures` → `list_custom_pages`. Never pick a page yourself (not the first in a list, not a guess by title, not a page from another project); if the answer is ambiguous, ask again. Before any upload call (`create_package_upload`, `submit_package`), show the full target, 기관 · 과목 · 수업 · 페이지 with names and ids, its LXP edit URL, whether content and answers go with it and the completion policy to set (the page's current one too), then wait for an explicit yes. Do this every time: also for `.ecdk/link.json` (and compare its `version_id` with `get_material`) and for a URL the person gave (confirm the names it resolves to). `.ecdk/link.json` and an edit URL give only the org's `name_short`: get the 기관 name from `list_my_organizations` and the 과목 · 수업 · 페이지 names from `get_material`. A new page (`create_custom_page`) needs its own yes that names the 수업 it goes into. If the page already has content or answers saved in LXP, say that sending settings replaces them and ask again.
|
|
19
19
|
6. **Upload.** `get_material` (keep `current_version.id`) → `create_package_upload` with `size_bytes = zipBytes` → run its `curl_command` with `package.zip` replaced by the zip path → `submit_package` → poll `get_draft` until ready or failed. On failure, report the server's reason with `ecdk validate dist/content.zip` and stop. Images or a PDF/PPTX for the settings: only now (draft ready), `create_asset_upload` per file → its `curl_command`, and put the returned `key`, never the URL, into the merged settings (`references/12-upload-with-the-material-mcp.md` "Images and documents"); no such tool: zip images, and tell the person.
|
|
20
20
|
7. **Approve.** Show what changes (page, title, whether the content and answers go with it or are entered on the LXP edit screen after saving, the completion policy) and the draft `preview_urls`. Saving is visible to learners at once if the page is open. Wait for an explicit yes.
|
|
@@ -60,6 +60,19 @@ export interface SubmitOptions<A = unknown> {
|
|
|
60
60
|
label?: string;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
export interface AutoSubmitOptions<A = unknown> {
|
|
64
|
+
/** 낼 답 (submit()을 부를 때 읽음) */
|
|
65
|
+
getAnswer: () => A;
|
|
66
|
+
/** 낸 직후, 또는 다시 열었을 때 지난 제출 */
|
|
67
|
+
onResult?: (result: SubmitResult & { answer?: A }, info: { restored: boolean }) => void;
|
|
68
|
+
/** 내지 못했을 때 (알림 줄에도 보임) */
|
|
69
|
+
onError?: (error: ContentError) => void;
|
|
70
|
+
/** 알림 줄을 붙일 화면 영역 (기본 #app, 그 뒤에 붙임) */
|
|
71
|
+
root?: Element;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type AutoSubmitState = 'idle' | 'sending' | 'done' | 'readonly';
|
|
75
|
+
|
|
63
76
|
export interface UploadFileOptions {
|
|
64
77
|
/** 올린 바이트 / 전체 바이트 */
|
|
65
78
|
onProgress?: (progress: { loaded: number; total: number }) => void;
|
|
@@ -245,6 +258,8 @@ export interface ContentApp<C = Record<string, unknown>> {
|
|
|
245
258
|
navigation: Navigation | null;
|
|
246
259
|
isLocal: boolean;
|
|
247
260
|
sdkKind: 'real' | 'mock' | 'custom';
|
|
261
|
+
/** 자료 id (토큰 · 주소가 아님) */
|
|
262
|
+
materialId: string | null;
|
|
248
263
|
account: { anonymousId: string; fullname: string | null } | null;
|
|
249
264
|
result: { score: number | null; submitCount: number; completedAt: string | null } | null;
|
|
250
265
|
readonly records: boolean;
|
|
@@ -288,6 +303,36 @@ export interface ContentApp<C = Record<string, unknown>> {
|
|
|
288
303
|
uploadImage(file: File, options?: UploadFileOptions): Promise<UploadedImage>;
|
|
289
304
|
url(assetKey: string): Promise<string | null>;
|
|
290
305
|
};
|
|
306
|
+
/**
|
|
307
|
+
* 버튼 없는 제출: 조건이 되면 submit()을 부른다. 한 번만 내고, 이미 낸 제출이 있으면 · 튜터면 내지 않는다
|
|
308
|
+
*/
|
|
309
|
+
useAutoSubmit<A = unknown>(
|
|
310
|
+
options: AutoSubmitOptions<A>
|
|
311
|
+
): {
|
|
312
|
+
/** 오류 알림 줄 */
|
|
313
|
+
element: Element;
|
|
314
|
+
/** 지난 제출을 확인했을 때 */
|
|
315
|
+
ready: Promise<void>;
|
|
316
|
+
readonly state: AutoSubmitState;
|
|
317
|
+
/** 이번에 또는 예전에 냈는지 */
|
|
318
|
+
readonly done: boolean;
|
|
319
|
+
/** 이미 냈거나 내는 중이거나 튜터면 아무것도 하지 않는다. 결과 또는 null */
|
|
320
|
+
submit(): Promise<SubmitResult | null>;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Elice 비디오 플레이어 (embed.js의 <elice-video> · <elice-video-upload>). 올리기 · 진행률 · 인코딩 대기 · 재생 화면은 플레이어가 그린다
|
|
324
|
+
*/
|
|
325
|
+
readonly videoPlayer: {
|
|
326
|
+
/** 플랫폼이 넘긴 embed.js 주소 (SDK videoPlayerUrl). 없으면 null */
|
|
327
|
+
readonly url: string | null;
|
|
328
|
+
/** embed.js를 불러온다 (전역 EliceVideoPlayer). url이 없으면 ContentError video_player_unavailable */
|
|
329
|
+
load(): Promise<unknown>;
|
|
330
|
+
/** 태그에 자료 id · 영상 id · 토큰을 넣고 토큰 갱신을 따라간다. 돌려주는 함수로 멈춘다 */
|
|
331
|
+
connect(
|
|
332
|
+
element: HTMLElement & { materialId: string; resourceId: string; token: string },
|
|
333
|
+
options?: { resourceId?: string }
|
|
334
|
+
): () => void;
|
|
335
|
+
};
|
|
291
336
|
/** 편집 화면 저장 영역 */
|
|
292
337
|
useSave(options: SaveOptions<C>): {
|
|
293
338
|
element: Element;
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* 자료 파일 (편집 화면에서 PDF · PPTX 올리기, 학생 화면에서 열기): app.assets.uploadFile(file, { onProgress, signal }) · await app.assets.url(asset_key)
|
|
10
10
|
* 이미지 (편집 화면에서 줄여 올리기): app.assets.uploadImage(file, { onProgress, signal }) · 보기는 같은 app.assets.url(asset_key)
|
|
11
11
|
* 화면 틀: data-ec-layout="single | split | stage | media" + data-ec-region (CSS만, lib/elice-content.css "레이아웃" 절)
|
|
12
|
+
* 버튼 없이 제출 (예: 영상을 N% 보면): app.useAutoSubmit({ getAnswer }) → 조건이 되면 auto.submit()
|
|
13
|
+
* Elice 비디오 플레이어 (동영상 올리기 · 재생): await app.videoPlayer.load() → <elice-video-upload> · <elice-video>에
|
|
14
|
+
* app.videoPlayer.connect(element, { resourceId })로 자료 id · 토큰(갱신 포함)을 넣는다
|
|
12
15
|
* 읽기 전용 잠금, 답 복원, 결과·오류 안내, 저장 문구, 로컬 mock 표시는 키트가 합니다.
|
|
13
16
|
*
|
|
14
17
|
* 화면(screens/*.js)은 이 키트만 부릅니다. 키트가 SDK로 인증 · 화면 확인 · 내용 불러오기 ·
|
|
@@ -79,6 +82,10 @@ const MESSAGES = {
|
|
|
79
82
|
save_regex_invalid: '정답 형식이 올바르지 않아요.',
|
|
80
83
|
save_invalid: '저장할 내용의 형식이 올바르지 않아요.',
|
|
81
84
|
not_initialized: '아직 준비되지 않았습니다.',
|
|
85
|
+
// 키트만의 코드: Elice 비디오 플레이어 (app.videoPlayer)
|
|
86
|
+
video_player_unavailable: '동영상을 불러올 수 없습니다.',
|
|
87
|
+
script_load_failed: '동영상 플레이어를 불러오지 못했어요. 잠시 뒤 다시 시도해 주세요.',
|
|
88
|
+
script_namespace_not_found: '동영상 플레이어를 불러오지 못했어요. 잠시 뒤 다시 시도해 주세요.',
|
|
82
89
|
// 키트만의 코드: 자료 파일 올리기 (app.assets.uploadFile)
|
|
83
90
|
upload_not_supported:
|
|
84
91
|
'아직 파일을 올릴 수 없어요. 이 SDK에는 파일 올리기가 없습니다 (@eliceio/cdk를 올려 주세요).',
|
|
@@ -422,6 +429,8 @@ export async function start(options) {
|
|
|
422
429
|
isLocal: launch.local,
|
|
423
430
|
/** 쓰고 있는 SDK: 'real' | 'mock' | 'custom' */
|
|
424
431
|
sdkKind: kind,
|
|
432
|
+
/** 자료 id (토큰 · 주소가 아님. 이 브라우저에 남기는 값의 키 등에) */
|
|
433
|
+
materialId: sdk.metadata?.materialId ?? null,
|
|
425
434
|
/** 보는 사람 { anonymousId, fullname } */
|
|
426
435
|
account: sdk.account,
|
|
427
436
|
/** 내 결과 { score(가장 최근 채점, 숫자 · null), submitCount, completedAt } 또는 null */
|
|
@@ -516,6 +525,46 @@ export async function start(options) {
|
|
|
516
525
|
return mountSubmit(app, opts);
|
|
517
526
|
},
|
|
518
527
|
|
|
528
|
+
/**
|
|
529
|
+
* 버튼 없는 제출 (예: 영상을 기준만큼 보면 학습 완료). 화면이 조건이 될 때 submit()을 부르면 한 번만 낸다.
|
|
530
|
+
* 이미 낸 제출이 있으면(다시 열기) 내지 않고, 튜터(보기 전용)는 내지 않는다. 미리보기 · 교육자는 useSubmit처럼
|
|
531
|
+
* 내지만 기록되지 않는다 (SDK · 서버가 정함). 오류는 useSubmit처럼 화면 영역 뒤 알림 줄에 보이고 다음 submit()에서 다시 시도
|
|
532
|
+
* @param {AutoSubmitOptions} opts
|
|
533
|
+
*/
|
|
534
|
+
useAutoSubmit(opts) {
|
|
535
|
+
return mountAutoSubmit(app, opts);
|
|
536
|
+
},
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Elice 비디오 플레이어 (`embed.js`의 <elice-video> 재생 · <elice-video-upload> 올리기). 올리기 · 진행률 · 인코딩 대기 ·
|
|
540
|
+
* 재생 · 오류 문구는 플레이어가 그리고, 화면은 태그를 놓고 이벤트(complete · ended …)로 저장 · 제출만 한다.
|
|
541
|
+
* - url: 플랫폼이 넘긴 이 환경의 embed.js 주소 (SDK videoPlayerUrl). 없으면 null (아직 넘기지 않는 플랫폼 · ecdk dev · mock)
|
|
542
|
+
* - load(): embed.js를 불러온다 (SDK loadScript, 전역 EliceVideoPlayer). url이 없으면 ContentError video_player_unavailable
|
|
543
|
+
* - connect(element, { resourceId }): 태그에 자료 id · 영상 id · 토큰을 넣고, 플랫폼이 토큰을 바꿀 때마다 다시 넣는다.
|
|
544
|
+
* 돌려주는 함수를 부르면 토큰 따라가기를 멈춘다. 토큰은 속성이 아니라 프로퍼티로만 넣는다 (DOM에 남지 않게)
|
|
545
|
+
*/
|
|
546
|
+
videoPlayer: Object.freeze({
|
|
547
|
+
get url() {
|
|
548
|
+
return sdk.videoPlayerUrl ?? null;
|
|
549
|
+
},
|
|
550
|
+
async load() {
|
|
551
|
+
const url = sdk.videoPlayerUrl ?? null;
|
|
552
|
+
if (!url) throw new ContentError('video_player_unavailable', MESSAGES.video_player_unavailable);
|
|
553
|
+
try {
|
|
554
|
+
const { loadScript } = await import('@eliceio/cdk');
|
|
555
|
+
return await loadScript(url, 'EliceVideoPlayer');
|
|
556
|
+
} catch (err) {
|
|
557
|
+
throw toContentError(err);
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
connect(element, { resourceId } = {}) {
|
|
561
|
+
element.materialId = sdk.metadata?.materialId ?? '';
|
|
562
|
+
if (resourceId) element.resourceId = resourceId;
|
|
563
|
+
element.token = sdk.accessToken ?? '';
|
|
564
|
+
return sdk.onAccessTokenChange?.(token => (element.token = token)) ?? (() => {});
|
|
565
|
+
},
|
|
566
|
+
}),
|
|
567
|
+
|
|
519
568
|
/**
|
|
520
569
|
* 자료 파일 (서버 스펙: POST /storage/upload-url → PUT, settings에는 asset_key, 보기는 asset_base_url + asset_key).
|
|
521
570
|
* SDK `assets.post` · `assets.get`(!99)을 부른다.
|
|
@@ -619,6 +668,14 @@ export async function start(options) {
|
|
|
619
668
|
* @property {string} [label] 버튼 글자 (기본 '제출')
|
|
620
669
|
*/
|
|
621
670
|
|
|
671
|
+
/**
|
|
672
|
+
* @typedef {object} AutoSubmitOptions
|
|
673
|
+
* @property {() => unknown} getAnswer 낼 답 (submit()을 부를 때 읽음)
|
|
674
|
+
* @property {(result: object, info: { restored: boolean }) => void} [onResult] 낸 직후, 또는 다시 열었을 때 지난 제출
|
|
675
|
+
* @property {(error: ContentError) => void} [onError] 내지 못했을 때 (알림 줄에도 보임)
|
|
676
|
+
* @property {Element} [root] 알림 줄을 붙일 화면 영역 (기본 #app, 그 뒤에 붙임)
|
|
677
|
+
*/
|
|
678
|
+
|
|
622
679
|
/**
|
|
623
680
|
* @typedef {object} StepperOptions
|
|
624
681
|
* @property {number} [count] 단계 수 (1 이상). 없으면 내용 영역 안 `[data-ec-step]` 요소 수
|
|
@@ -680,6 +737,81 @@ function resultText(r) {
|
|
|
680
737
|
: `${r.score}점이에요. 다시 풀어 볼 수 있어요.`;
|
|
681
738
|
}
|
|
682
739
|
|
|
740
|
+
/**
|
|
741
|
+
* 지난 점수: app.result에는 점수만 있어 채점했는지(isCorrect)는 마지막 제출에서 읽는다 (못 읽으면 점수로 짐작).
|
|
742
|
+
* 점수가 없으면 null (useSubmit · useAutoSubmit 공통)
|
|
743
|
+
*/
|
|
744
|
+
function pastScore(app) {
|
|
745
|
+
return app.result && app.result.score !== null && app.result.score !== undefined
|
|
746
|
+
? { score: app.result.score, isCorrect: app.result.score === 100 }
|
|
747
|
+
: null;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/** 답 하나를 내고 결과를 화면에 알린다 (useSubmit · useAutoSubmit 공통). 오류는 ContentError로 던진다 */
|
|
751
|
+
async function submitOnce(app, answer, onResult) {
|
|
752
|
+
const res = await app.submit(answer);
|
|
753
|
+
onResult?.(res, { restored: false });
|
|
754
|
+
return res;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function mountAutoSubmit(app, { getAnswer, onResult, onError, root }) {
|
|
758
|
+
const area = appRoot(root);
|
|
759
|
+
const error = h('p', { className: 'ec-error', role: 'alert' });
|
|
760
|
+
area.after(error);
|
|
761
|
+
// 'idle' 낼 수 있음 · 'sending' 내는 중 · 'done' 냈음(이번에 또는 예전에) · 'readonly' 튜터라 내지 않음
|
|
762
|
+
let state = app.readOnly ? 'readonly' : 'idle';
|
|
763
|
+
// 다시 열면: 지난 결과(완료 · 점수)나 마지막 제출이 있으면 이미 낸 것으로 본다
|
|
764
|
+
const done = app.result && (app.result.submitCount > 0 || app.result.completedAt);
|
|
765
|
+
if (done && state === 'idle') state = 'done';
|
|
766
|
+
const ready = app
|
|
767
|
+
.lastSubmission()
|
|
768
|
+
.then(last => {
|
|
769
|
+
if (!last) return;
|
|
770
|
+
if (state === 'idle') state = 'done';
|
|
771
|
+
onResult?.(last, { restored: true });
|
|
772
|
+
})
|
|
773
|
+
.catch(() => {
|
|
774
|
+
// 지난 제출을 읽지 못하면 결과(app.result)만으로 판단한다
|
|
775
|
+
const past = pastScore(app);
|
|
776
|
+
if (past) onResult?.(past, { restored: true });
|
|
777
|
+
});
|
|
778
|
+
let sending = null;
|
|
779
|
+
return {
|
|
780
|
+
element: error,
|
|
781
|
+
ready,
|
|
782
|
+
/** 'idle' · 'sending' · 'done' · 'readonly' */
|
|
783
|
+
get state() {
|
|
784
|
+
return state;
|
|
785
|
+
},
|
|
786
|
+
/** 이번에 또는 예전에 냈는지 */
|
|
787
|
+
get done() {
|
|
788
|
+
return state === 'done';
|
|
789
|
+
},
|
|
790
|
+
/** 조건이 되면 부른다. 이미 냈거나 내는 중이거나 튜터면 아무것도 하지 않는다 (결과 또는 null) */
|
|
791
|
+
async submit() {
|
|
792
|
+
await ready;
|
|
793
|
+
if (state !== 'idle') return sending ?? null;
|
|
794
|
+
state = 'sending';
|
|
795
|
+
error.textContent = '';
|
|
796
|
+
sending = submitOnce(app, getAnswer(), onResult)
|
|
797
|
+
.then(res => {
|
|
798
|
+
state = 'done';
|
|
799
|
+
return res;
|
|
800
|
+
})
|
|
801
|
+
.catch(e => {
|
|
802
|
+
state = 'idle';
|
|
803
|
+
error.textContent = e.message;
|
|
804
|
+
onError?.(e);
|
|
805
|
+
return null;
|
|
806
|
+
})
|
|
807
|
+
.finally(() => {
|
|
808
|
+
sending = null;
|
|
809
|
+
});
|
|
810
|
+
return sending;
|
|
811
|
+
},
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
|
|
683
815
|
const UNCHANGED_HINT = '답을 고치면 다시 제출할 수 있어요.';
|
|
684
816
|
|
|
685
817
|
function mountSubmit(
|
|
@@ -780,11 +912,7 @@ function mountSubmit(
|
|
|
780
912
|
button.hidden = true;
|
|
781
913
|
error.textContent = '보기 전용이라 제출할 수 없습니다.';
|
|
782
914
|
}
|
|
783
|
-
|
|
784
|
-
const past =
|
|
785
|
-
app.result && app.result.score !== null && app.result.score !== undefined
|
|
786
|
-
? { score: app.result.score, isCorrect: app.result.score === 100 }
|
|
787
|
-
: null;
|
|
915
|
+
const past = pastScore(app);
|
|
788
916
|
if (past && !app.readOnly) button.textContent = `다시 ${label}`;
|
|
789
917
|
// 다시 열면 마지막 제출의 답을 채우고, 채점 결과({ isCorrect, score })도 화면에 알려 준다.
|
|
790
918
|
// 복원 응답보다 먼저 제출했으면 늦게 온 복원은 버린다 (방금 낸 답 · 결과를 덮지 않게)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
Elice Custom HTML 학습자료 프로젝트입니다 (영상 템플릿). 영상 한 편을 보여 주고, 학생이 끝까지 보면 한 번 자동으로 제출합니다.
|
|
4
|
+
|
|
5
|
+
동영상 올리기 · 진행률 · 인코딩 대기 · 재생은 **Elice 비디오 플레이어**(`embed.js`의 `<elice-video-upload>` · `<elice-video>`)가 맡습니다. 이 템플릿은 태그를 놓고, 플레이어 이벤트로 저장할 영상 id와 제출만 다룹니다.
|
|
6
|
+
|
|
7
|
+
## 고치는 곳
|
|
8
|
+
|
|
9
|
+
| 파일 | 화면 |
|
|
10
|
+
| --------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
11
|
+
| `screens/learn.js` · `index.html` | 학생 화면 (`<elice-video>` 화면 가득 · 자동 제출) |
|
|
12
|
+
| `screens/edit.js` · `edit.html` | 내용 편집 화면 (`<elice-video-upload>` · ⓘ 안내 · '초안으로 저장'). 키트 편집 화면(`body.ec-edit-page`) |
|
|
13
|
+
| `ui/` | 모양: 색 · 문구 · 마크업 (`theme.css` · `texts.js` · `templates/`) |
|
|
14
|
+
| `styles.css` | 플레이어 태그의 크기 · 모서리, 플레이어를 띄울 수 없을 때 안내 |
|
|
15
|
+
| `core/settings.js` | 저장 모양과 검증 (고치지 않음) |
|
|
16
|
+
| `metadata.json` | 화면 구성(`screens`) · 학습 참고 내용(`commentary`). `ecdk build`가 `build`만 채움 |
|
|
17
|
+
| `package.json` | SDK 버전(`@eliceio/cdk`) · 빌드 옵션 `"ecdk"`. zip에 들어가지 않음 |
|
|
18
|
+
|
|
19
|
+
플레이어 안(재생 컨트롤 · 화질 · 재생 속도 · 올리기 칸과 받는 형식 · 최대 크기 안내 · 진행률 · 취소 · 인코딩 중 · '다른 파일로 변경' · 오류 문구)은 플레이어의 iframe이라 이 프로젝트에서 바꿀 수 없습니다. 바꿀 수 있는 것은 태그의 크기 · 모서리(`styles.css`)와 태그 밖 화면입니다. 올리기 태그의 높이는 플레이어가 상태(빈 칸 · 올리는 중 · 미리보기)마다 맞춥니다.
|
|
20
|
+
|
|
21
|
+
## 플레이어 쓰는 법 (키트 `app.videoPlayer`)
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
await app.videoPlayer.load(); // SDK loadScript(sdk.videoPlayerUrl, 'EliceVideoPlayer')
|
|
25
|
+
app.videoPlayer.connect(element, { resourceId }); // material-id · resource-id · token(sdk.accessToken), 토큰이 바뀌면(sdk.onAccessTokenChange) 다시 넣음
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
| 태그 | 이벤트 (버블링하지 않음, 태그에 직접) | 이 템플릿이 하는 일 |
|
|
29
|
+
| ---------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
30
|
+
| `<elice-video-upload>` | `progress`(`detail.percent`) · `complete`(`detail.resourceId`) · `cancel` · `error`(`detail.code`) | 올리는 중엔 저장을 막고, `complete`면 `settings.video.resource_id`를 바꾸고 '저장하지 않은 변경' 표시 |
|
|
31
|
+
| `<elice-video>` | `ready` · `ended` · `error`(`detail.code`) | `ended`면 한 번 자동 제출 |
|
|
32
|
+
|
|
33
|
+
- `sdk.videoPlayerUrl`은 플랫폼이 화면 주소 fragment(`videoPlayerUrl`)로 넘깁니다. 넘기지 않으면(ecdk dev, 아직 반영 전 LXP) 영상 자리에 "동영상을 불러올 수 없습니다"가 보입니다.
|
|
34
|
+
- `embed.js`는 zip에 넣지 않습니다 (플랫폼 환경마다 주소가 다름).
|
|
35
|
+
|
|
36
|
+
## 학습 완료
|
|
37
|
+
|
|
38
|
+
- `settings.completion.mode`: `'ended'`(기본, 끝까지 보면 제출) · `'open'`(학생 화면을 열면 바로 제출). 편집 화면에는 고르는 곳이 없습니다 (V3 내용 편집 화면에 없음).
|
|
39
|
+
- **N% 시청은 지금 없습니다**: 플레이어가 재생 위치 · 시청 비율 이벤트를 주지 않습니다 (`ready` · `ended` · `error`뿐). 옛 영상 템플릿(1.x)의 `mode: 'watch'`는 `'ended'`로 읽습니다.
|
|
40
|
+
- 끝(`ended`)은 학생 브라우저가 알립니다. 서버는 제출만 받고 실제로 봤는지 확인하지 않으며, 재생 막대로 끝까지 건너뛰어도 `ended`가 옵니다. 출결 · 이수 증빙이 필요한 과정에는 Elice 비디오 자료를 쓰세요.
|
|
41
|
+
- 제출 답은 `{ completedBy: 'ended' | 'open' }`(기록용), 채점은 없습니다 (`settings.grading` 없음). 다시 열었을 때 이미 낸 제출이 있으면 다시 내지 않고, 튜터링(보기 전용)은 제출하지 않습니다 (키트 `app.useAutoSubmit`).
|
|
42
|
+
- 완료 정책은 LXP 페이지 설정입니다: publish 스킬이 동의를 받아 업로드 때 정하거나 교육자가 LXP 편집 페이지 위쪽 '설정' 패널에서 **제출 시 학습 완료(on_submit)**로 골라야 이 기준이 학습 완료가 됩니다.
|
|
43
|
+
|
|
44
|
+
## 저장 모양 (`settings`)
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
{
|
|
48
|
+
video: { resource_id: '…' }, // <elice-video-upload> complete의 detail.resourceId
|
|
49
|
+
completion: { mode: 'ended' }, // 'ended' · 'open'
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- **인코딩 중 저장**: 올리기가 끝나면(`complete`) 인코딩 중이어도 저장할 수 있습니다. 인코딩이 끝나면 플레이어가 알아서 재생합니다.
|
|
54
|
+
- 다른 키(예: AI · MCP가 넣은 `title`)는 저장 때 그대로 둡니다. 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
55
|
+
- `ecdk dev`의 내용 편집에서 저장한 것은 `.ecdk/settings.json`에 남습니다 (zip에는 들어가지 않음). 기본으로는 로컬에만 있고, publish 스킬로 올릴 때 동의하면 업로드와 함께 보냅니다.
|
|
56
|
+
- 영상이 없으면 학생 화면은 "아직 내용이 없습니다" 안내를 보입니다 (`app.hasContent` · `app.emptyState()`).
|
|
57
|
+
|
|
58
|
+
교육자 화면은 없습니다 (`metadata.json` `screens.instructor.enabled: false`). LXP에서 교육자가 열면 학생 화면이 열리고, 교육자의 제출은 기록되지 않습니다.
|
|
59
|
+
|
|
60
|
+
`lib/`(화면 키트)는 플랫폼 연결 로직이라 고치지 않습니다. SDK는 `package.json` 의존성(`@eliceio/cdk`)이고 키트가 import하며, `ecdk build`(Vite)가 화면 코드와 함께 번들로 묶습니다 (처음 한 번 `npm install`, 올리기 `npm update @eliceio/cdk`).
|
|
61
|
+
|
|
62
|
+
## 명령
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
ecdk dev # 로컬에서 보기 (플레이어 주소가 없어 영상 자리는 안내만)
|
|
66
|
+
ecdk doctor # 환경·프로젝트 점검
|
|
67
|
+
ecdk build # 검사 후 dist/content.zip (편집 화면에 올릴 파일)
|
|
68
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// core/dom.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
export declare const present: (nodes: any[]) => any[];
|
|
4
|
+
export declare function el(
|
|
5
|
+
tag: string,
|
|
6
|
+
props?: Record<string, unknown>,
|
|
7
|
+
...children: any[]
|
|
8
|
+
): HTMLElement;
|
|
9
|
+
/** 최상위 요소가 하나면 그 요소(HTMLElement로 다룸), 아니면 DocumentFragment */
|
|
10
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): any;
|
|
11
|
+
export declare function part(root: Element, name: string): HTMLElement | null;
|
|
12
|
+
export declare function parts(root: Element, name: string): HTMLElement[];
|
|
13
|
+
export declare function lock<T extends Element>(root: T): T;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// 작은 DOM 도우미 (퀴즈 템플릿 core/dom.js와 같음). ui/templates/*는 html`…`로 마크업을 쓰고, 동작은 data-role로 그 안의 요소를 찾습니다.
|
|
2
|
+
|
|
3
|
+
/** 조건부로 넣은 null · undefined · false 빼기 */
|
|
4
|
+
export const present = (nodes) => nodes.filter((c) => c !== null && c !== undefined && c !== false);
|
|
5
|
+
|
|
6
|
+
export function el(tag, props = {}, ...children) {
|
|
7
|
+
const node = Object.assign(document.createElement(tag), props);
|
|
8
|
+
node.append(...present(children));
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const escape = (s) =>
|
|
13
|
+
s
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>')
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, ''');
|
|
19
|
+
|
|
20
|
+
const MARK = 'vd-node:';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* HTML 조각 템플릿. 끼워 넣는 값은
|
|
24
|
+
* 글자 · 숫자 → 이스케이프해서 글자로 (교육자 · 학생이 쓴 내용도 안전)
|
|
25
|
+
* 요소(Node) · 배열 → 그 자리에 그대로 (태그 사이에만, 속성 값에는 글자만)
|
|
26
|
+
* null · undefined · false → 아무것도 넣지 않음 (`${cond && '…'}`)
|
|
27
|
+
* 줄바꿈이 든 앞뒤 공백은 지우므로 들여쓰기를 자유롭게 해도 됩니다 (한 줄 안의 공백은 그대로).
|
|
28
|
+
* 최상위 요소가 하나면 그 요소를, 아니면 DocumentFragment를 돌려준다.
|
|
29
|
+
*/
|
|
30
|
+
export function html(strings, ...values) {
|
|
31
|
+
const nodes = [];
|
|
32
|
+
const part = (v) => {
|
|
33
|
+
if (v === null || v === undefined || v === false) return '';
|
|
34
|
+
if (Array.isArray(v)) return v.map(part).join('');
|
|
35
|
+
if (typeof Node !== 'undefined' && v instanceof Node) {
|
|
36
|
+
nodes.push(v);
|
|
37
|
+
return `<!--${MARK}${nodes.length - 1}-->`;
|
|
38
|
+
}
|
|
39
|
+
return escape(String(v));
|
|
40
|
+
};
|
|
41
|
+
const markup = strings.reduce((out, s, i) => out + part(values[i - 1]) + s);
|
|
42
|
+
const template = document.createElement('template');
|
|
43
|
+
// 끼워 넣는 값은 모두 위에서 이스케이프하거나 주석 자리표로 바꾼다 (퀴즈 quiz.test.ts 'html 템플릿'에서 확인)
|
|
44
|
+
// ecdk-ignore-next-line sec.html-injection
|
|
45
|
+
template.innerHTML = markup.trim();
|
|
46
|
+
const walker = document.createTreeWalker(
|
|
47
|
+
template.content,
|
|
48
|
+
NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT,
|
|
49
|
+
);
|
|
50
|
+
const swap = [];
|
|
51
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) swap.push(n);
|
|
52
|
+
for (const n of swap) {
|
|
53
|
+
if (n.nodeType === Node.COMMENT_NODE && n.data.startsWith(MARK))
|
|
54
|
+
n.replaceWith(nodes[Number(n.data.slice(MARK.length))]);
|
|
55
|
+
else if (n.nodeType === Node.TEXT_NODE) {
|
|
56
|
+
// 들여쓰기: 줄바꿈이 든 앞뒤 공백은 지우고, 그것만 있는 글자 노드는 뺀다 (JSX와 같은 규칙)
|
|
57
|
+
const data = n.data.replace(/^\s*\n\s*/, '').replace(/\s*\n\s*$/, '');
|
|
58
|
+
if (data === '') n.remove();
|
|
59
|
+
else if (data !== n.data) n.data = data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const fragment = template.content;
|
|
63
|
+
return fragment.childNodes.length === 1 && fragment.firstChild instanceof Element
|
|
64
|
+
? fragment.firstChild
|
|
65
|
+
: fragment;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** root 자신이나 그 안에서 data-role="name"인 첫 요소 */
|
|
69
|
+
export function part(root, name) {
|
|
70
|
+
const selector = `[data-role="${name}"]`;
|
|
71
|
+
return root.matches?.(selector) ? root : root.querySelector(selector);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** root 안의 data-role="name"인 모든 요소 */
|
|
75
|
+
export const parts = (root, name) => [...root.querySelectorAll(`[data-role="${name}"]`)];
|
|
76
|
+
|
|
77
|
+
/** 읽기 전용(교육자 · 튜터링)일 때 root와 그 안의 입력 · 버튼을 모두 막는다 */
|
|
78
|
+
export function lock(root) {
|
|
79
|
+
if ('disabled' in root) root.disabled = true;
|
|
80
|
+
for (const c of root.querySelectorAll('input, textarea, select, button, fieldset'))
|
|
81
|
+
c.disabled = true;
|
|
82
|
+
return root;
|
|
83
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// core/settings.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export type CompletionMode = 'ended' | 'open';
|
|
3
|
+
|
|
4
|
+
export interface VideoDraft {
|
|
5
|
+
rest: Record<string, unknown>;
|
|
6
|
+
video: { resource_id: string } | null;
|
|
7
|
+
completion: { mode: CompletionMode };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare const COMPLETION_MODES: readonly CompletionMode[];
|
|
11
|
+
export declare function normalizeSettings(
|
|
12
|
+
raw: Record<string, unknown> | null | undefined
|
|
13
|
+
): VideoDraft;
|
|
14
|
+
export declare function toSettings(draft: VideoDraft): Record<string, unknown>;
|
|
15
|
+
export declare function validateSettings(
|
|
16
|
+
draft: Pick<VideoDraft, 'video'>,
|
|
17
|
+
messages: { videoRequired: string; uploading: string },
|
|
18
|
+
state?: { uploading?: boolean }
|
|
19
|
+
): true | string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// 저장 모양(settings)과 검증. 편집 화면이 저장하고 학생 화면이 읽습니다. 고치지 않습니다: 키 이름을 바꾸면 저장한 자료를 읽지 못합니다.
|
|
2
|
+
//
|
|
3
|
+
// {
|
|
4
|
+
// video: { resource_id: '…' }, // Elice 비디오 플레이어가 올린 영상 id (<elice-video-upload> complete의 detail.resourceId)
|
|
5
|
+
// completion: { mode: 'ended' }, // 'ended' 끝까지 보면 제출(기본) · 'open' 열면 바로 제출
|
|
6
|
+
// }
|
|
7
|
+
// 그 밖의 키(예: AI · MCP가 넣은 title)는 저장 때 그대로 둡니다. 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
8
|
+
|
|
9
|
+
/** 학습 완료 기준: 플레이어가 알려 주는 것은 ready · ended · error뿐이라 'ended'(끝까지 봄)와 'open'(열람)만 */
|
|
10
|
+
export const COMPLETION_MODES = Object.freeze(['ended', 'open']);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 저장된 settings를 화면이 쓰는 모양으로. 모르는 값은 기본값.
|
|
14
|
+
* 옛 영상 템플릿(1.x)의 completion.mode 'watch'(N% 시청)는 플레이어가 시청 비율을 알려 주지 않아 'ended'로 읽는다
|
|
15
|
+
* @param {Record<string, unknown> | null | undefined} raw
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeSettings(raw) {
|
|
18
|
+
const s = raw && typeof raw === 'object' ? raw : {};
|
|
19
|
+
const v = s.video && typeof s.video === 'object' ? s.video : null;
|
|
20
|
+
const resourceId = v && typeof v.resource_id === 'string' && v.resource_id ? v.resource_id : null;
|
|
21
|
+
const mode = s.completion && typeof s.completion === 'object' ? s.completion.mode : undefined;
|
|
22
|
+
return {
|
|
23
|
+
/** 저장 때 그대로 둘 다른 키 */
|
|
24
|
+
rest: Object.fromEntries(
|
|
25
|
+
Object.entries(s).filter(([k]) => k !== 'video' && k !== 'completion')
|
|
26
|
+
),
|
|
27
|
+
video: resourceId ? { resource_id: resourceId } : null,
|
|
28
|
+
completion: { mode: COMPLETION_MODES.includes(mode) ? mode : 'ended' },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 화면 상태를 저장 모양으로 */
|
|
33
|
+
export function toSettings(draft) {
|
|
34
|
+
return {
|
|
35
|
+
...draft.rest,
|
|
36
|
+
...(draft.video ? { video: { resource_id: draft.video.resource_id } } : {}),
|
|
37
|
+
completion: { mode: draft.completion.mode },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 저장 전 검증. 통과면 true, 아니면 화면에 보일 문구.
|
|
43
|
+
* 인코딩 중에도 저장할 수 있다 (사용자 결정): 올리기가 끝나(complete) 영상 id가 있으면 된다
|
|
44
|
+
* @param {{ video: { resource_id: string } | null }} draft
|
|
45
|
+
* @param {{ videoRequired: string, uploading: string }} messages
|
|
46
|
+
* @param {{ uploading?: boolean }} [state]
|
|
47
|
+
*/
|
|
48
|
+
export function validateSettings(draft, messages, { uploading = false } = {}) {
|
|
49
|
+
if (uploading) return messages.uploading;
|
|
50
|
+
if (!draft.video) return messages.videoRequired;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="ko">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<!-- 제목 · "불러오는 중" 문구는 ui/texts.js(page)에서 고칩니다. 여기 글은 스크립트가 돌기 전에만 보입니다 -->
|
|
7
|
+
<title>내용 편집</title>
|
|
8
|
+
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
9
|
+
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
10
|
+
<link rel="stylesheet" href="ui/theme.css" />
|
|
11
|
+
<link rel="stylesheet" href="styles.css" />
|
|
12
|
+
<script type="module" src="screens/edit.js"></script>
|
|
13
|
+
</head>
|
|
14
|
+
<body class="ec-edit-page">
|
|
15
|
+
<main id="app"><div class="ec-sk ec-sk-edit" role="status"><span class="ec-visually-hidden">불러오는 중…</span><div class="ec-sk-bar ec-sk-shimmer"></div><div class="ec-sk-media ec-sk-shimmer"></div></div></main>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|