@eliceio/cdk-cli 0.1.0-alpha.5 → 0.1.0-alpha.6
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 +45 -18
- package/es/commands/build/index.d.ts +1 -1
- package/es/commands/build/index.js +4 -4
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +1 -1
- package/es/commands/doctor/index.js +1 -1
- package/es/core/collect.js +1 -1
- package/es/core/config.js +1 -1
- package/es/core/prepare.js +1 -1
- package/es/core/sandbox.js +6 -3
- package/es/dev/host-page.js +18 -3
- package/es/dev/inject.d.ts +6 -0
- package/es/dev/inject.js +16 -1
- package/es/dev/mock-api.js +0 -16
- package/es/dev/server.d.ts +4 -2
- package/es/dev/server.js +11 -3
- package/es/rules/check.js +69 -6
- package/es/rules/csp.d.ts +26 -0
- package/es/rules/csp.js +42 -0
- package/es/rules/index.d.ts +1 -0
- package/es/rules/index.js +1 -0
- package/es/rules/refs.d.ts +12 -2
- package/es/rules/refs.js +50 -18
- package/es/rules/types.d.ts +5 -0
- package/es/rules.json.js +2 -2
- package/package.json +2 -2
- package/rules.json +37 -15
- package/skills/_shared/always.md +2 -1
- package/skills/elice-content-guide/SKILL.md +1 -1
- package/skills/elice-content-guide/topics/03-create-the-project.md +1 -1
- package/skills/elice-content-guide/topics/04-rules.md +3 -1
- package/skills/elice-content-guide/topics/07-move-existing-html.md +1 -1
- package/skills/elice-content-guide/topics/08-fix-check-errors.md +21 -18
- package/skills/elice-content-guide/topics/09-check.md +1 -0
- package/skills/elice-content-migrate/SKILL.md +4 -3
- package/templates/_shared/lib/cdk-mock.js +1 -1
- package/templates/_shared/lib/elice-content.css +22 -1
- package/templates/quiz/README.md +2 -2
- package/templates/quiz/core/editor.d.ts +2 -0
- package/templates/quiz/core/editor.js +16 -6
- package/templates/quiz/screens/edit.js +105 -24
- package/templates/quiz/styles.css +75 -12
- package/templates/quiz/template.json +1 -1
- package/templates/quiz/ui/templates/edit.d.ts +4 -0
- package/templates/quiz/ui/templates/edit.js +46 -10
- package/templates/quiz/ui/templates/page.js +1 -2
- package/templates/quiz/ui/templates/text.js +10 -7
- package/templates/quiz/ui/texts.js +12 -8
package/skills/_shared/always.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
## Always
|
|
2
2
|
|
|
3
3
|
- Never put correct answers in the content zip. The edit screen saves them to `settings.grading` (locally `.ecdk/settings.json` from `ecdk dev`).
|
|
4
|
-
- The content runs in a sandboxed iframe on
|
|
4
|
+
- The content runs in a sandboxed iframe on its own origin: use the SDK (`app.useSubmit`, `app.useSave`) for anything that must be kept (storage and cookies stay only in that browser), and in-page UI instead of `alert`/`confirm`, new windows, the parent window or external requests.
|
|
5
|
+
- The content CSP blocks external images, fonts, video, CSS, `<iframe>` and external APIs: put everything in the zip (fonts as files or data URIs). If a library calls outside hosts while running, that is blocked too → check the `ecdk dev` log for "막힌 외부 요청".
|
|
5
6
|
- If `ecdk`, `node` or `npm` is "command not found", the app started without the person's shell PATH (macOS desktop apps such as Helpy Code Desktop). Run each command through their login shell instead: `"$SHELL" -ilc 'ecdk build --json'` (use `zsh -ilc` when `$SHELL` is empty). With `--json`, read only the last JSON block of the output (a login shell may print other text first). If that also fails, ask the person how Node was installed.
|
|
6
7
|
- Fix every `ecdk validate` / `ecdk build` error before you report. Do not edit `lib/` (the screen kit). The SDK comes from npm through `package.json` (`npm update @eliceio/cdk`); `ecdk build` adds it to the zip as `lib/cdk.js`.
|
|
7
8
|
- Ask the person before you settle correct answers, install anything globally, or upload or save to LXP (a saved version is visible to learners at once). Before uploading, confirm the exact target page (기관 · 과목 · 수업 · 페이지) with the person.
|
|
@@ -17,7 +17,7 @@ One zip has up to three screens. The completion policy is not part of the zip: t
|
|
|
17
17
|
| Instructor (optional) | `instructor.html` + `screens/instructor.js` | What only instructors see: activity summary, explanations, teaching tips |
|
|
18
18
|
| Content edit (optional) | `edit.html` + `screens/edit.js` | Instructors edit text and data without code and save it → `app.content` of the other screens. Also sets the grader and the answers or rubric, saved to `settings.grading` (never sent to students) |
|
|
19
19
|
|
|
20
|
-
Elice opens the content in a **sandboxed (`allow-scripts`) iframe on
|
|
20
|
+
Elice opens the content in a **sandboxed (`allow-scripts allow-same-origin`) iframe on its own origin**, separate from Elice and from other contents. There is no server: everything runs as browser JS, and only submission, saving and grading go to the Elice server.
|
|
21
21
|
|
|
22
22
|
## Topics
|
|
23
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 3. Create the project
|
|
2
2
|
|
|
3
|
-
Run `ecdk create --list` first: it prints each template with its own version (`quiz@1.
|
|
3
|
+
Run `ecdk create --list` first: it prints each template with its own version (`quiz@1.3.0`), what it is for and its screens. Pick the template from that list. `ecdk create` records the template and version in `package.json` `"ecdk"` (`template`), `ecdk build` copies it to `metadata.json` `build.template`, and `ecdk doctor` says when the installed ecdk ships a newer version of that template (nothing changes on its own).
|
|
4
4
|
|
|
5
5
|
| Case | Start with |
|
|
6
6
|
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
1. **Never put correct answers in the content**: not in a data JSON file, the screen code, or comments. They reach the student's browser. Answers go only in `settings.grading` through the edit screen (the server never sends it to students; `ecdk dev` keeps it in `.ecdk/settings.json`, left out of the zip).
|
|
4
4
|
2. **Screen code calls only `lib/elice-content.js` (the kit).** Do not edit `lib/`. Do not call the SDK (`lib/cdk.js`, added by `ecdk build` from `node_modules`) directly.
|
|
5
|
-
3. **Do not use blocked features**: `
|
|
5
|
+
3. **Do not use blocked features**: `alert`/`confirm`/`prompt` · `window.open` · `<form>` submission · access to `window.parent`/`top` · `fetch`/`WebSocket` to external addresses · external `<script src>`. `localStorage` · `sessionStorage` · `indexedDB` · `document.cookie` work, but they stay only in that browser and device and are not the learner's record: to keep progress, submit it (`useSubmit`); to keep content, save it from the edit screen.
|
|
6
6
|
4. **Libraries and media go inside the zip.** Download libraries for charts, visualization or physics (for example Chart.js, D3, p5.js) into `vendor/` and load them by relative path instead of a CDN. Fonts, images and sounds also go in the zip. Limits: zip 20 MB, 300 files. Upload long videos separately as Elice video materials.
|
|
7
|
+
- The content CSP (same as LXP) blocks every external image, font, video, CSS file, `<iframe src>`/`<object>`/`<embed>` and `fetch` (errors `ref.external-request` · `html.iframe`; an `<iframe>` filled with `srcdoc` for a code preview is fine). Fonts go in the zip as files or data URIs: external fonts (Google Fonts too) are blocked for now; they open once the server allowlist is settled.
|
|
8
|
+
- A library may call outside hosts while it runs (web fonts, wasm, map tiles, APIs) and the CSP blocks them. `ref.vendor-external-url` warns about outside addresses in library files; open `ecdk dev` and look for "막힌 외부 요청" in the log, then put those files in the zip and point the library at them by relative path.
|
|
7
9
|
5. **Use relative paths** (`img/a.png`). Paths starting with `/` break. Match file name case. Prefer letters, digits, `-` and `_`.
|
|
8
10
|
6. **Switch views inside one HTML.** Show and hide steps or pages within the same HTML. Moving to another HTML or reloading loses the access token and shows "please reopen the material".
|
|
9
11
|
7. **Never insert user input as HTML**: use `textContent`. When `innerHTML` is really needed, escape it and leave `// ecdk-ignore-next-line sec.html-injection` with the reason.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
1. Create a skeleton with `ecdk create <new folder> --template blank`.
|
|
4
4
|
2. Move the original body, styles and scripts to the student screen (`index.html` · `screens/learn.js` · `styles.css`). Copy image, font and library folders as they are and use relative paths.
|
|
5
|
-
3. Download external CDN scripts and
|
|
5
|
+
3. Download external CDN scripts, fonts, images, CSS and videos into the zip (fonts as files or data URIs, long videos as Elice video materials, no `<iframe>`). After `ecdk dev`, check the log for "막힌 외部 요청".
|
|
6
6
|
4. Replace blocked code (storage, `alert`, external sends) as in [4](04-rules.md).
|
|
7
7
|
5. Merge multiple HTML pages into one HTML that switches views.
|
|
8
8
|
6. Decide submission and grading as in [2 ②](02-design-the-material.md). The completion policy is not written in the project: the instructor picks it in the LXP settings tab after the upload (suggest `on_access` when there is no submission).
|
|
@@ -2,23 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Read `check.issues[]` (`id` · `level` · `path` · `line` · `message`) from `ecdk build --json`. With an `error` no zip is made. Each `message` says how to fix it.
|
|
4
4
|
|
|
5
|
-
| id
|
|
6
|
-
|
|
|
7
|
-
| `ref.missing` · `ref.case-mismatch`
|
|
8
|
-
| `ref.root-absolute`
|
|
9
|
-
| `ref.external-script` · `ref.external-request` | Put the library
|
|
10
|
-
| `
|
|
11
|
-
| `
|
|
12
|
-
| `
|
|
13
|
-
| `
|
|
14
|
-
| `
|
|
15
|
-
| `
|
|
16
|
-
| `
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
22
|
-
| `
|
|
5
|
+
| id | Fix |
|
|
6
|
+
| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| `ref.missing` · `ref.case-mismatch` | Match the path and case to the real file |
|
|
8
|
+
| `ref.root-absolute` | Change `/…` to a relative path |
|
|
9
|
+
| `ref.external-script` · `ref.external-request` · `ref.insecure` | Put the library, image, font or video in the zip and use a relative path (fonts: files or data URIs) |
|
|
10
|
+
| `html.iframe` | Remove the `<iframe src>`/`<object>`/`<embed>` (an `<iframe>` with `srcdoc` for a code preview passes): upload video as an Elice video material, put other content in this HTML |
|
|
11
|
+
| `ref.external-font` (warn) | A font from a host in `rules.json` `externalAllow` (empty for now): closed-network schools cannot reach it, so put a font that matters in the zip |
|
|
12
|
+
| `ref.vendor-external-url` (warn) | A library file holds outside addresses: run `ecdk dev`, look for "막힌 외부 요청", put what it loads in the zip and set the library to a relative path |
|
|
13
|
+
| `api.storage` · `api.cookie` (warn) | Browser storage and cookies stay only in that browser and device and are not the learner's record. Submit results; save content from the edit screen |
|
|
14
|
+
| `api.dialog` · `api.window-open` · `html.form` | An in-page message · the same view · a button click + `useSubmit` |
|
|
15
|
+
| `api.external-send` | Remove the external send |
|
|
16
|
+
| `sec.html-injection` | Use `textContent`. If justified: escape + `ecdk-ignore` + the reason |
|
|
17
|
+
| `sec.secret` · `file.secret` | Remove the secret or the answer file (if it was already uploaded, tell the user to **revoke the key**) |
|
|
18
|
+
| `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 LXP settings tab |
|
|
19
|
+
| `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 |
|
|
20
|
+
| `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 |
|
|
21
|
+
| `sdk.outdated` (error) | The SDK in 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` (an old `lib/cdk.js` copy: `ecdk doctor --fix && npm install`), then build again |
|
|
22
|
+
| `sdk.lib-copy` (warn, project only) | An old `lib/cdk.js` copy and no `@eliceio/cdk` in `package.json`: `ecdk doctor --fix`, then `npm install` |
|
|
23
|
+
| `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"` |
|
|
24
|
+
| `manifest.*` · `entry.*` | Check `screens` and `kind` in `metadata.json` |
|
|
25
|
+
| `limit.*` · `file.large-image` | Shrink images and video, drop unused files (build output: "files not referenced anywhere") |
|
|
23
26
|
|
|
24
27
|
Use `ecdk-ignore`, which turns a rule off, only for legitimate code a regular expression cannot tell apart, and **always with the reason**. Do not scatter it to silence errors.
|
|
@@ -7,4 +7,5 @@ ecdk dev # http://localhost:4170: student, tutoring, instructor, conten
|
|
|
7
7
|
- With a browser tool, open it and finish the student activity (with the score and result when it submits), then check the tutoring lock, saving on the edit screen → the change on the student screen, saving answers on the edit view → grading of the student view (without saved grading a submission is only accepted, with no score), the mobile width, and the dark theme. Without one, ask the user to check in this order.
|
|
8
8
|
- Even after your own check, the person looks at the screens before uploading (see [0. What the person decides](00-what-the-person-decides.md)).
|
|
9
9
|
- Fix the content console errors and 404s printed in the terminal.
|
|
10
|
+
- `ecdk dev` serves the content with the LXP content CSP. "막힌 외부 요청: <address> (<directive>)" in the log above the content and in the terminal is a request LXP blocks too (an external image, font or `fetch`, or a library calling outside while it runs): put the file in the zip.
|
|
10
11
|
- Opening files directly with `file://` is not a check.
|
|
@@ -12,11 +12,12 @@ Read guide topics with the Read tool from the sibling `elice-content-guide` skil
|
|
|
12
12
|
## Steps
|
|
13
13
|
|
|
14
14
|
1. **Read** `../elice-content-guide/topics/07-move-existing-html.md` (move existing HTML) and `../elice-content-guide/topics/04-rules.md` (rules).
|
|
15
|
-
2. **Look at the original first.** List its entry HTML, the files it loads, and anything the sandbox blocks (
|
|
15
|
+
2. **Look at the original first.** List its entry HTML, the files it loads, and storage or cookies used to keep learner data, anything the sandbox blocks (dialogs, `window.open`, the parent window, external requests, absolute `/` paths). Tell the person what will change.
|
|
16
16
|
3. **Wrap it.** Make or reuse an ecdk project as `../elice-content-guide/topics/07-move-existing-html.md` says, keep the original files as they are where possible, and write `commentary.txt`. An old ecdk project (`elice.config.json`, or `lib/cdk.js` without `@eliceio/cdk` in `package.json`): `ecdk doctor --fix`, then `npm install`.
|
|
17
17
|
4. **Submission and grading.** Decide whether it submits and how it grades (`../elice-content-guide/topics/02-design-the-material.md`). Do not write a completion policy: 완료 정책은 LXP에 올린 뒤 설정 탭에서 교육자가 고른다 (tell the person which one fits, e.g. `on_access` without a submission). When it grades, set the grader and the answers on the edit screen (`app.useGradingBlock()`). Ask the person for correct answers when it is graded. Data the instructor should edit goes in the content the edit screen saves, not in a default JSON file; until it is saved the screens show `app.emptyState()`.
|
|
18
18
|
Keep the original design on the student screen. Screens you add (an edit screen, an empty state) follow the UI patterns in `../elice-content-guide/topics/05-screen-code.md`.
|
|
19
|
-
5. **
|
|
20
|
-
6. **
|
|
19
|
+
5. **Bring external assets in.** Download every external image, font, CSS file, video and library into the zip and use relative paths (fonts as files or data URIs; replace `<iframe>` embeds, video goes to an Elice video material). The content CSP blocks anything outside the zip.
|
|
20
|
+
6. **Check.** `ecdk validate`, fix errors (`../elice-content-guide/topics/08-fix-check-errors.md`), `ecdk dev`, compare with the original. In the `ecdk dev` log (above the content and in the terminal) look for "막힌 외부 요청": a library calling outside at runtime; bring that file into the zip too.
|
|
21
|
+
7. **Build and report.** `ecdk build --json` returns `ok: true`; report what changed from the original (`../elice-content-guide/topics/10-build.md`).
|
|
21
22
|
|
|
22
23
|
{{version}}
|
|
@@ -405,7 +405,7 @@ export class MockEliceCDK {
|
|
|
405
405
|
);
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
/**
|
|
408
|
+
/** The real SDK stops its token expiry timer and hashchange listener. The mock has neither. */
|
|
409
409
|
dispose() {}
|
|
410
410
|
|
|
411
411
|
/** mock 전용: 저장한 내용·제출·결과 지우기 */
|
|
@@ -371,7 +371,7 @@ button.ec-icon-button svg {
|
|
|
371
371
|
button.ec-icon-button:hover {
|
|
372
372
|
background: var(--eds-action-hover);
|
|
373
373
|
}
|
|
374
|
-
/* 목록 안 항목 하나 빼기(보기 · 그룹 삭제): 빨간
|
|
374
|
+
/* 목록 안 항목 하나 빼기(보기 · 그룹 삭제): 빨간 ✕. 묶음 전체 삭제(문항 카드)는 휴지통 + 기본 색 */
|
|
375
375
|
button.ec-icon-button.ec-danger {
|
|
376
376
|
color: var(--ec-no);
|
|
377
377
|
border-radius: 50%;
|
|
@@ -417,6 +417,27 @@ button.ec-text-button {
|
|
|
417
417
|
border: 0;
|
|
418
418
|
font-size: 13px;
|
|
419
419
|
}
|
|
420
|
+
/* 화면 안 짧은 알림 + 동작 하나 (예: 삭제 뒤 되돌리기). EDS Alert(standard) info 색 */
|
|
421
|
+
.ec-notice {
|
|
422
|
+
display: flex;
|
|
423
|
+
align-items: center;
|
|
424
|
+
justify-content: space-between;
|
|
425
|
+
gap: 12px;
|
|
426
|
+
padding: 8px 8px 8px 16px;
|
|
427
|
+
border-radius: var(--ec-radius);
|
|
428
|
+
background: var(--ec-info-bg);
|
|
429
|
+
color: var(--ec-info);
|
|
430
|
+
font-weight: var(--eds-fw-semibold);
|
|
431
|
+
}
|
|
432
|
+
.ec-notice button.ec-text-button {
|
|
433
|
+
flex: none;
|
|
434
|
+
background: none;
|
|
435
|
+
color: var(--ec-accent);
|
|
436
|
+
font-weight: var(--eds-fw-bold);
|
|
437
|
+
}
|
|
438
|
+
.ec-notice button.ec-text-button:hover {
|
|
439
|
+
background: var(--eds-primary-opacity01);
|
|
440
|
+
}
|
|
420
441
|
.ec-grading-examples {
|
|
421
442
|
display: grid;
|
|
422
443
|
grid-template-columns: max-content 1fr;
|
package/templates/quiz/README.md
CHANGED
|
@@ -28,7 +28,7 @@ core/ 동작 — 고치지 않습니다 (답 문자열 · 채점 약속,
|
|
|
28
28
|
| 바꾸고 싶은 것 | 고치는 곳 |
|
|
29
29
|
| -------------------------------------------- | ------------------------------------------------------------------------- |
|
|
30
30
|
| 색 · 간격 · 모서리 | `ui/theme.css`의 `--qz-*` 변수 (예: `--qz-accent`, `--qz-option-padding`) |
|
|
31
|
-
| 문구 ("
|
|
31
|
+
| 문구 ("정답", "편집 완료", 탭 제목 등) | `ui/texts.js` (HTML의 제목 · "불러오는 중"은 스크립트가 돌기 전 대비용) |
|
|
32
32
|
| 보기 카드 마크업 | `ui/templates/choice.js` (모양은 `styles.css`의 `.qz-option`) |
|
|
33
33
|
| 문항 겉모양 · 결과 · 해설 자리 | `ui/templates/question.js` |
|
|
34
34
|
| 순서 맞추기 · 그룹 분류 배치 | `ui/templates/order.js` · `ui/templates/group.js` |
|
|
@@ -45,7 +45,7 @@ core/ 동작 — 고치지 않습니다 (답 문자열 · 채점 약속,
|
|
|
45
45
|
| `input` | 주관식 입력란 (`text.js`) · 편집 칸 |
|
|
46
46
|
| `pool` · `slots` | 순서 맞추기 (`order.js`) |
|
|
47
47
|
| `pool` · `items`, 있으면 `pool-area` · `reset` · `remove` | 그룹 분류 (`group.js`) |
|
|
48
|
-
| `count` · `handle` · `delete` · `type` · `up` · `down` | 편집 화면 (`edit.js`) |
|
|
48
|
+
| `count` · `handle` · `delete` · `type` · `up` · `down` · `answer` · `undo` · `type-warning` · `answer-error` | 편집 화면 (`edit.js`) |
|
|
49
49
|
|
|
50
50
|
보기 · 칸 · 그룹 · 문항 요소의 `data-role` · `data-option` · `data-slot` · `data-group` · `data-id`, 상태 표시 `data-result`(`correct` · `wrong`) · `data-dragging` · `data-ghost`는 동작이 붙입니다. CSS에서 이 속성으로 상태를 꾸밀 수 있습니다.
|
|
51
51
|
|
|
@@ -38,6 +38,8 @@ export declare function createEditor(opts: {
|
|
|
38
38
|
items: any[],
|
|
39
39
|
key: string,
|
|
40
40
|
opts?: {
|
|
41
|
+
/** 추가한 뒤 (예: 순서 맞추기 칸 수 늘리기) */
|
|
42
|
+
onAdd?: () => void;
|
|
41
43
|
onDelete?: () => void;
|
|
42
44
|
onInput?: (item: any) => void;
|
|
43
45
|
/** 줄마다 정답 칸 (data-role="answer"): radio · checkbox · select(choices: [값, 이름]) */
|
|
@@ -68,12 +68,14 @@ export function createEditor({ rerender, root, templates, labels }) {
|
|
|
68
68
|
* @param {'option' | 'group'} kind
|
|
69
69
|
* @param {object[]} items q.options 또는 q.groups (직접 고침)
|
|
70
70
|
* @param {string} key 키보드로 옮긴 뒤 초점을 찾을 이름 (화면에서 겹치지 않게)
|
|
71
|
-
*
|
|
71
|
+
* 정답으로 고른 줄에는 data-correct를 붙인다 (그룹은 그룹에 넣은 보기)
|
|
72
|
+
* @param {{ onAdd?: () => void, onDelete?: () => void, onInput?: (item: object) => void,
|
|
72
73
|
* answer?: { type: 'radio' | 'checkbox' | 'select', name: string, choices?: [string, string][],
|
|
73
74
|
* get: (item: object) => boolean | string, set: (item: object, value: boolean | string) => void } }} [opts]
|
|
75
|
+
* onAdd: 추가한 뒤 할 일 (예: 순서 맞추기 칸 수 늘리기) ·
|
|
74
76
|
* onDelete: 지운 뒤 할 일 (예: 순서 맞추기 칸 수 줄이기, 정답에서 빼기) · onInput: 글을 고친 뒤 할 일
|
|
75
77
|
*/
|
|
76
|
-
function itemList(kind, items, key, { onDelete, onInput, answer } = {}) {
|
|
78
|
+
function itemList(kind, items, key, { onAdd, onDelete, onInput, answer } = {}) {
|
|
77
79
|
const isGroup = kind === 'group';
|
|
78
80
|
const text = isGroup ? 'name' : 'text';
|
|
79
81
|
const min = isGroup ? LIMITS.groupsMin : LIMITS.optionsMin;
|
|
@@ -98,10 +100,13 @@ export function createEditor({ rerender, root, templates, labels }) {
|
|
|
98
100
|
const value = answer.get(item);
|
|
99
101
|
if (answer.type === 'select') pick.value = String(value ?? '');
|
|
100
102
|
else pick.checked = Boolean(value);
|
|
101
|
-
pick.addEventListener('change', () =>
|
|
102
|
-
answer.set(item, answer.type === 'select' ? pick.value : pick.checked)
|
|
103
|
-
|
|
103
|
+
pick.addEventListener('change', () => {
|
|
104
|
+
answer.set(item, answer.type === 'select' ? pick.value : pick.checked);
|
|
105
|
+
// radio는 다른 줄의 정답도 바뀌므로 줄마다 다시 표시
|
|
106
|
+
rows.forEach((r, j) => markCorrect(r, items[j]));
|
|
107
|
+
});
|
|
104
108
|
}
|
|
109
|
+
markCorrect(row, item);
|
|
105
110
|
part(row, 'delete').addEventListener('click', () => {
|
|
106
111
|
items.splice(i, 1);
|
|
107
112
|
onDelete?.();
|
|
@@ -110,6 +115,9 @@ export function createEditor({ rerender, root, templates, labels }) {
|
|
|
110
115
|
sortHandle(part(row, 'handle'), items, i, key);
|
|
111
116
|
return row;
|
|
112
117
|
});
|
|
118
|
+
function markCorrect(row, item) {
|
|
119
|
+
if (answer) row.toggleAttribute('data-correct', Boolean(answer.get(item)));
|
|
120
|
+
}
|
|
113
121
|
const full = items.length >= max;
|
|
114
122
|
const add = ui.addButton({ kind, full, max });
|
|
115
123
|
add.addEventListener('click', () => {
|
|
@@ -122,9 +130,11 @@ export function createEditor({ rerender, root, templates, labels }) {
|
|
|
122
130
|
}
|
|
123
131
|
: { id: nextId(ids), text: '' },
|
|
124
132
|
);
|
|
133
|
+
onAdd?.();
|
|
125
134
|
rerender();
|
|
126
135
|
});
|
|
127
|
-
|
|
136
|
+
// 정답 칸이 있으면 목록 위에 "정답" 열 머리 · 최소 개수라 지울 수 없으면 목록 아래 안내
|
|
137
|
+
return ui.list({ kind, rows, add, answer: answer?.type, atMin: items.length <= min, min });
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
/** list[from]을 to 자리로 옮기고 다시 그린 뒤, 키보드로 옮겼으면 옮긴 손잡이에 초점을 둔다 */
|
|
@@ -42,6 +42,14 @@ const parsed = savedKey ? parseAnswerKey(draft.questions, savedKey) : {};
|
|
|
42
42
|
/** @type {Record<string, unknown>} */
|
|
43
43
|
const answers = parsed ?? {};
|
|
44
44
|
const unreadable = Boolean(savedKey) && parsed === null;
|
|
45
|
+
// 순서 맞추기 정답 칸 (문항 id → 화면). 끌어 놓기는 window에서 끝나 이벤트로 읽으면 마지막 놓기를 놓치므로,
|
|
46
|
+
// 값이 필요할 때(저장 · 다시 그리기 · 보기 삭제) 칸에서 바로 읽는다
|
|
47
|
+
const answerViews = new Map();
|
|
48
|
+
const readAnswerViews = () => {
|
|
49
|
+
for (const [id, view] of answerViews) answers[id] = view.getValue();
|
|
50
|
+
};
|
|
51
|
+
// 유형을 바꿔 정답을 다시 골라야 하는 문항 id (다음 저장까지 카드 위에 알림)
|
|
52
|
+
const retyped = new Set();
|
|
45
53
|
|
|
46
54
|
const form = createEditor({
|
|
47
55
|
rerender: render,
|
|
@@ -77,10 +85,7 @@ function answerField(q) {
|
|
|
77
85
|
}
|
|
78
86
|
const view = renderAnswerBody(q, { templates: quizTemplates });
|
|
79
87
|
if (answers[q.id] !== undefined) view.setValue(answers[q.id]);
|
|
80
|
-
|
|
81
|
-
const read = () => queueMicrotask(() => (answers[q.id] = view.getValue()));
|
|
82
|
-
for (const type of ['input', 'change', 'click', 'pointerup'])
|
|
83
|
-
view.el.addEventListener(type, read);
|
|
88
|
+
answerViews.set(q.id, view);
|
|
84
89
|
return form.ui.section({ label: a.label, hint: a.hint[q.type], body: view.el });
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -104,17 +109,31 @@ function inlineAnswer(q) {
|
|
|
104
109
|
function optionsOpts(q) {
|
|
105
110
|
const inline = INLINE_ANSWER_TYPES.includes(q.type);
|
|
106
111
|
return {
|
|
112
|
+
// 순서 맞추기 칸 수를 따로 정하지 않았으면(보기 수와 같음) 보기를 더할 때 같이 늘린다
|
|
113
|
+
onAdd: () => {
|
|
114
|
+
if (q.type === 'order' && q.slots === q.options.length - 1) q.slots = q.options.length;
|
|
115
|
+
},
|
|
107
116
|
onDelete: () => {
|
|
117
|
+
readAnswerViews();
|
|
108
118
|
if (q.type === 'order') q.slots = Math.min(q.slots, q.options.length);
|
|
109
119
|
if (answers[q.id] !== undefined) answers[q.id] = pruneAnswer(q, answers[q.id]);
|
|
120
|
+
// 다시 그릴 때 지우기 전 칸 값으로 덮지 않게
|
|
121
|
+
answerViews.delete(q.id);
|
|
110
122
|
},
|
|
111
123
|
answer: inline ? inlineAnswer(q) : undefined,
|
|
112
124
|
};
|
|
113
125
|
}
|
|
114
126
|
|
|
127
|
+
/** 정답을 고르는 묶음 (저장하지 못한 정답 문제를 여기에 표시) */
|
|
128
|
+
const answerArea = section => {
|
|
129
|
+
section.dataset.role = 'answers';
|
|
130
|
+
return section;
|
|
131
|
+
};
|
|
132
|
+
|
|
115
133
|
/** 문항 카드 안의 칸들. 유형마다 보이는 칸이 다르다 */
|
|
116
134
|
function questionFields(q, i) {
|
|
117
135
|
const body = [
|
|
136
|
+
retyped.has(q.id) && templates.typeWarning({ text: a.typeChanged }),
|
|
118
137
|
form.field(t.title, q.title, v => (q.title = v), { required: true, max: LIMITS.titleMax }),
|
|
119
138
|
// 문항 설명: 미리보기 없는 여러 줄 칸. 새 문항에는 키가 없고, 적으면 생긴다
|
|
120
139
|
form.field(t.description, q.description ?? '', v => (q.description = v), {
|
|
@@ -124,13 +143,12 @@ function questionFields(q, i) {
|
|
|
124
143
|
];
|
|
125
144
|
if (q.type === 'select_one' || q.type === 'select_multiple' || q.type === 'order') {
|
|
126
145
|
const options = form.itemList('option', q.options, `${i}o`, optionsOpts(q));
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
146
|
+
const section = form.ui.section({
|
|
147
|
+
label: t.options,
|
|
148
|
+
hint: q.type === 'order' ? undefined : a.hint[q.type],
|
|
149
|
+
body: options,
|
|
150
|
+
});
|
|
151
|
+
body.push(q.type === 'order' ? section : answerArea(section));
|
|
134
152
|
}
|
|
135
153
|
if (q.type === 'order') {
|
|
136
154
|
const slots = form.numberField(
|
|
@@ -146,7 +164,7 @@ function questionFields(q, i) {
|
|
|
146
164
|
}
|
|
147
165
|
if (q.type === 'group') {
|
|
148
166
|
const groups = form.itemList('group', q.groups, `${i}g`, {
|
|
149
|
-
// 지운 그룹에 넣은 보기는 "그룹 없음"으로
|
|
167
|
+
// 지운 그룹에 넣은 보기는 "오답 (그룹 없음)"으로
|
|
150
168
|
onDelete: () => {
|
|
151
169
|
if (answers[q.id] !== undefined) answers[q.id] = pruneAnswer(q, answers[q.id]);
|
|
152
170
|
},
|
|
@@ -158,11 +176,13 @@ function questionFields(q, i) {
|
|
|
158
176
|
});
|
|
159
177
|
body.push(
|
|
160
178
|
form.ui.section({ label: t.groups, body: groups }),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
answerArea(
|
|
180
|
+
form.ui.section({
|
|
181
|
+
label: t.options,
|
|
182
|
+
hint: a.hint.group,
|
|
183
|
+
body: form.itemList('option', q.options, `${i}o`, optionsOpts(q)),
|
|
184
|
+
})
|
|
185
|
+
)
|
|
166
186
|
);
|
|
167
187
|
}
|
|
168
188
|
if (q.type === 'text')
|
|
@@ -172,22 +192,25 @@ function questionFields(q, i) {
|
|
|
172
192
|
hint: t.placeholderHint,
|
|
173
193
|
})
|
|
174
194
|
);
|
|
175
|
-
if (!INLINE_ANSWER_TYPES.includes(q.type)) body.push(answerField(q));
|
|
176
|
-
|
|
177
|
-
|
|
195
|
+
if (!INLINE_ANSWER_TYPES.includes(q.type)) body.push(answerArea(answerField(q)));
|
|
196
|
+
// 표시 옵션: 보기 · 정답과 줄로 나눈다
|
|
197
|
+
const display = [];
|
|
198
|
+
if (q.type !== 'text') display.push(form.toggle(t.shuffle, q.shuffle, v => (q.shuffle = v)));
|
|
199
|
+
display.push(
|
|
178
200
|
form.toggle(t.explanationOn, q.explanation?.enabled, v => {
|
|
179
201
|
q.explanation = { ...(q.explanation ?? { text: '' }), enabled: v };
|
|
180
202
|
render();
|
|
181
203
|
})
|
|
182
204
|
);
|
|
183
205
|
if (q.explanation?.enabled)
|
|
184
|
-
|
|
206
|
+
display.push(
|
|
185
207
|
form.field(t.explanation, q.explanation.text, v => (q.explanation.text = v), {
|
|
186
208
|
multiline: true,
|
|
187
209
|
showOptional: false,
|
|
188
210
|
})
|
|
189
211
|
);
|
|
190
|
-
|
|
212
|
+
body.push(templates.displayOptions({ label: t.display, body: display }));
|
|
213
|
+
return body.filter(Boolean);
|
|
191
214
|
}
|
|
192
215
|
|
|
193
216
|
function questionCard(q, i) {
|
|
@@ -202,22 +225,60 @@ function questionCard(q, i) {
|
|
|
202
225
|
{
|
|
203
226
|
type: type => {
|
|
204
227
|
draft.questions[i] = convertType(q, type, texts.defaults);
|
|
205
|
-
// 유형이 바뀌면 답 모양이 달라지므로 정답을 다시 고른다
|
|
228
|
+
// 유형이 바뀌면 답 모양이 달라지므로 정답을 다시 고른다 (카드 위에 알림)
|
|
206
229
|
delete answers[q.id];
|
|
230
|
+
answerViews.delete(q.id);
|
|
231
|
+
retyped.add(q.id);
|
|
207
232
|
render();
|
|
208
233
|
},
|
|
209
234
|
up: () => swap(draft.questions, i, i - 1),
|
|
210
235
|
down: () => swap(draft.questions, i, i + 1),
|
|
236
|
+
// 지운 문항은 알림의 "되돌리기"로 같은 자리에 되살린다 (정답도 함께)
|
|
211
237
|
remove: () => {
|
|
238
|
+
readAnswerViews();
|
|
239
|
+
const removed = { q: structuredClone(q), answer: structuredClone(answers[q.id]) };
|
|
212
240
|
draft.questions.splice(i, 1);
|
|
213
241
|
delete answers[q.id];
|
|
242
|
+
answerViews.delete(q.id);
|
|
243
|
+
retyped.delete(q.id);
|
|
244
|
+
undo = () => {
|
|
245
|
+
draft.questions.splice(i, 0, removed.q);
|
|
246
|
+
if (removed.answer !== undefined) answers[q.id] = removed.answer;
|
|
247
|
+
render();
|
|
248
|
+
};
|
|
249
|
+
undoAt = i;
|
|
214
250
|
render();
|
|
215
251
|
},
|
|
216
252
|
}
|
|
217
253
|
);
|
|
218
254
|
}
|
|
219
255
|
|
|
256
|
+
/** 문항 삭제 뒤 되돌리기 (다음에 다시 그리면 없어짐) */
|
|
257
|
+
let undo = null;
|
|
258
|
+
let undoAt = 0;
|
|
259
|
+
const UNDO_MS = 6000;
|
|
260
|
+
|
|
261
|
+
/** 삭제 알림. 시간이 지나면 지운다 (다시 그리지 않음: 저장한 뒤라면 변경 표시가 생기지 않게) */
|
|
262
|
+
function undoNotice(restore, index) {
|
|
263
|
+
const node = templates.undoNotice({ text: t.questionDeleted(index + 1), action: t.undo });
|
|
264
|
+
const button = node.querySelector('[data-role="undo"]');
|
|
265
|
+
button.addEventListener('click', restore);
|
|
266
|
+
setTimeout(() => {
|
|
267
|
+
const next = node.nextElementSibling;
|
|
268
|
+
const focused = node.contains(document.activeElement);
|
|
269
|
+
node.remove();
|
|
270
|
+
if (focused) next?.focus();
|
|
271
|
+
}, UNDO_MS);
|
|
272
|
+
queueMicrotask(() => button.focus());
|
|
273
|
+
return node;
|
|
274
|
+
}
|
|
275
|
+
|
|
220
276
|
function render() {
|
|
277
|
+
readAnswerViews();
|
|
278
|
+
answerViews.clear();
|
|
279
|
+
const cards = draft.questions.map(questionCard);
|
|
280
|
+
if (undo) cards.splice(undoAt, 0, undoNotice(undo, undoAt));
|
|
281
|
+
undo = null;
|
|
221
282
|
root.replaceChildren(
|
|
222
283
|
templates.answersIntro({ text: unreadable ? `${a.unreadable} ${a.intro}` : a.intro }),
|
|
223
284
|
form.field(t.quizTitle, draft.title, v => (draft.title = v), { required: true }),
|
|
@@ -226,7 +287,7 @@ function render() {
|
|
|
226
287
|
multiline: true,
|
|
227
288
|
showOptional: false,
|
|
228
289
|
}),
|
|
229
|
-
...
|
|
290
|
+
...cards,
|
|
230
291
|
// 퀴즈 하나에 문항 하나: 문항이 있으면 "문항 추가" 대신 안내 (이미 여러 문항으로 저장된 퀴즈도 편집 · 저장은 됨)
|
|
231
292
|
canAddQuestion(draft.questions)
|
|
232
293
|
? form.addQuestion(() => {
|
|
@@ -251,11 +312,27 @@ function render() {
|
|
|
251
312
|
const problemAt = (problem, { answer = false } = {}) => {
|
|
252
313
|
const card = form.cardAt(problem.questionIndex);
|
|
253
314
|
const pick = answer ? card?.querySelector('[data-role="answer"]') : null;
|
|
315
|
+
if (answer) markAnswerError(card, problem.message);
|
|
254
316
|
(pick ?? card)?.scrollIntoView({ block: 'center' });
|
|
255
317
|
pick?.focus({ preventScroll: true });
|
|
256
318
|
return problem.message;
|
|
257
319
|
};
|
|
258
320
|
|
|
321
|
+
/** 정답 묶음을 오류로 표시하고 문장을 그 위에 둔다. 그 안에서 다시 고르면 지운다 */
|
|
322
|
+
function markAnswerError(card, message) {
|
|
323
|
+
const area = card?.querySelector('[data-role="answers"]');
|
|
324
|
+
if (!area) return;
|
|
325
|
+
area.querySelector('[data-role="answer-error"]')?.remove();
|
|
326
|
+
area.dataset.error = '';
|
|
327
|
+
area.lastElementChild.before(templates.answerError({ text: message }));
|
|
328
|
+
const clear = () => {
|
|
329
|
+
delete area.dataset.error;
|
|
330
|
+
area.querySelector('[data-role="answer-error"]')?.remove();
|
|
331
|
+
for (const type of ['input', 'change', 'pointerup']) area.removeEventListener(type, clear);
|
|
332
|
+
};
|
|
333
|
+
for (const type of ['input', 'change', 'pointerup']) area.addEventListener(type, clear);
|
|
334
|
+
}
|
|
335
|
+
|
|
259
336
|
render();
|
|
260
337
|
save = app.useSave({
|
|
261
338
|
label: t.done,
|
|
@@ -266,6 +343,7 @@ save = app.useSave({
|
|
|
266
343
|
},
|
|
267
344
|
// 정답 → 정답 정규식. 검증(정답 · 지운 보기 → 정규식 공통 검사 → 왕복 · 오답)을 통과해야 저장한다
|
|
268
345
|
getGrading: () => {
|
|
346
|
+
readAnswerViews();
|
|
269
347
|
const { questions } = draft;
|
|
270
348
|
const missing = validateAnswerKey(questions, answers, a.validation);
|
|
271
349
|
if (missing) return problemAt(missing, { answer: true });
|
|
@@ -275,6 +353,9 @@ save = app.useSave({
|
|
|
275
353
|
if (regexProblem) return regexProblem;
|
|
276
354
|
const keyProblem = checkAnswerKey(questions, answers, answerKey, a.validation);
|
|
277
355
|
if (keyProblem) return problemAt(keyProblem, { answer: true });
|
|
356
|
+
// 저장하면 유형 바꾸기 알림을 지운다
|
|
357
|
+
retyped.clear();
|
|
358
|
+
for (const node of root.querySelectorAll('[data-role="type-warning"]')) node.remove();
|
|
278
359
|
return { type: 'pattern', answer_key: answerKey };
|
|
279
360
|
},
|
|
280
361
|
});
|