@eliceio/cdk-cli 1.8.1-qa.0 → 1.9.0-youtubeqa.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 +21 -20
- package/assets/link-bridge.js +1 -0
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/dev/host-page.js +11 -0
- package/es/dev/link-bridge.d.ts +27 -0
- package/es/dev/link-bridge.js +142 -0
- package/es/dev/server.js +3 -0
- package/es/rules/check.js +3 -3
- package/es/rules/csp.d.ts +2 -2
- package/es/rules/csp.js +30 -5
- package/es/rules.json.js +1 -1
- package/package.json +3 -2
- package/rules.json +5 -5
- package/skills/_shared/references/02-design-the-material.md +1 -1
- package/skills/_shared/references/03-create-the-project.md +1 -0
- package/skills/_shared/references/04-rules.md +2 -2
- package/skills/_shared/references/08-fix-check-errors.md +1 -1
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
- package/skills/_shared/references/18-using-the-lesson-template.md +1 -1
- package/skills/elice-content-create/SKILL.md +1 -1
- package/templates/entry/screens/edit.js +3 -8
- package/templates/entry/template.json +1 -1
- package/templates/youtube/README.md +66 -0
- package/templates/youtube/commentary.txt +2 -0
- package/templates/youtube/core/dom.d.ts +13 -0
- package/templates/youtube/core/dom.js +83 -0
- package/templates/youtube/core/settings.d.ts +21 -0
- package/templates/youtube/core/settings.js +71 -0
- package/templates/youtube/core/youtube.d.ts +9 -0
- package/templates/youtube/core/youtube.js +111 -0
- package/templates/youtube/edit.html +17 -0
- package/templates/youtube/gitignore +4 -0
- package/templates/youtube/index.html +17 -0
- package/templates/youtube/metadata.json +9 -0
- package/templates/youtube/package.json +13 -0
- package/templates/youtube/screens/edit.js +69 -0
- package/templates/youtube/screens/learn.js +18 -0
- package/templates/youtube/styles.css +101 -0
- package/templates/youtube/template.json +14 -0
- package/templates/youtube/ui/templates/edit.js +60 -0
- package/templates/youtube/ui/templates/player.js +61 -0
- package/templates/youtube/ui/texts.d.ts +3 -0
- package/templates/youtube/ui/texts.js +50 -0
- package/templates/youtube/ui/theme.css +14 -0
package/rules.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.24.0",
|
|
3
3
|
"manifest": {
|
|
4
4
|
"file": "metadata.json",
|
|
5
5
|
"kinds": ["material", "description"],
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"externalAllow": {
|
|
18
18
|
"style-src": [],
|
|
19
19
|
"font-src": [],
|
|
20
|
-
"frame-src": ["https://entry-workspace.elice.io"]
|
|
20
|
+
"frame-src": ["https://entry-workspace.elice.io", "https://www.youtube-nocookie.com/embed/"]
|
|
21
21
|
},
|
|
22
22
|
"minVersions": {
|
|
23
23
|
"sdk": "1.0.0-alpha.4"
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
{
|
|
121
121
|
"id": "api.window-open",
|
|
122
122
|
"pattern": "\\bwindow\\.open\\s*\\(",
|
|
123
|
-
"title": "새 창
|
|
123
|
+
"title": "window.open 새 창 (sandbox 팝업이라 외부 페이지가 깨짐, 외부 링크는 <a href>로 두면 LXP가 새 탭으로 엶)"
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"id": "api.external-send",
|
|
@@ -621,7 +621,7 @@
|
|
|
621
621
|
"id": "html.iframe",
|
|
622
622
|
"level": "error",
|
|
623
623
|
"scope": "client",
|
|
624
|
-
"title": "src로 띄우는 iframe · frame, object · embed (콘텐츠 CSP가 막음, 영상은 Elice 비디오 자료로, srcdoc 미리보기 · 허용 목록(externalAllow frame-src)
|
|
624
|
+
"title": "src로 띄우는 iframe · frame, object · embed (콘텐츠 CSP가 막음, 영상은 Elice 비디오 자료로, srcdoc 미리보기 · 허용 목록(externalAllow frame-src) 출처 · 경로의 iframe은 통과, YouTube는 https://www.youtube-nocookie.com/embed/ 주소만)"
|
|
625
625
|
},
|
|
626
626
|
{
|
|
627
627
|
"id": "html.form",
|
|
@@ -669,7 +669,7 @@
|
|
|
669
669
|
"id": "api.window-open",
|
|
670
670
|
"level": "error",
|
|
671
671
|
"scope": "client",
|
|
672
|
-
"title": "새 창
|
|
672
|
+
"title": "window.open 새 창 (sandbox 팝업)"
|
|
673
673
|
},
|
|
674
674
|
{
|
|
675
675
|
"id": "sec.secret",
|
|
@@ -39,7 +39,7 @@ Read or watch / change values and observe (simulation, visualization) / follow s
|
|
|
39
39
|
- **`entry` (Entry template only, two modes)**: `{ "type": "entry", "mode": "general", "answer_project": { "enc": "gzip+base64", "data": "…" } }` (compared with the answer project, 0 or 100; no other keys) or `{ "type": "entry", "mode": "ai", "answer_project": {…}, "rubrics": [{ "object": "ik8o", "criteria": "…", "score": 100 }] }` (`object` is an object id of the answer project — there is no whole-project criterion, `""` or an unknown id is rejected with 422 `entry_rubric_object_not_found`; the AI mode also needs `settings.entry.startProject`, and the general answer project needs at least one script or global list, else 422 `entry_answer_project_empty`; 1–10 criteria of 1–1,000 characters, integer scores 1–100 summing to 100; `question_results` and `grading_feedback.criteria` per criterion, in the submit response and in the submission history). The Entry template's edit screen saves it; do not write it by hand ([17](17-using-the-entry-template.md)).
|
|
40
40
|
- **Choosing between `pattern` and `partial_pattern` is the person's call.** For a material with several questions, ask: "모두 맞혀야 100점" (`pattern`) or "문항별 부분 점수" (`partial_pattern`). For partial scores, take the per-question scores from the person or from the planning material; if neither gives them, use an equal score and say so in the summary (the quiz template's automatic score is `ceil(100 / questions)` each, 3 → 34 · 34 · 34; the kit's `splitScores` sums to exactly 100, 3 → 33 · 33 · 34). In the quiz template the author can also change the grader and the scores on the edit screen. Scores are integers 0–100 summing to at least 100 (usually exactly 100). Students must answer every question before they submit (the quiz blocks an unanswered question), so a skipped question cannot score 0 by design.
|
|
41
41
|
- **Regexes run on the server in Python `re`**, not JavaScript: for a case-insensitive match put `(?i)` at the very start (`(?i)^(paris|파리)$`); the kit, `ecdk dev` and the local mock turn a leading `(?i)` · `(?s)` · `(?m)` into the JS flag. Avoid what the two engines read differently: `\w` · `\d` · `\b` match Unicode (Korean letters, full-width digits) in Python but only ASCII in JS, so write the characters out (`[0-9]`, `[가-힣A-Za-z]`); named groups are `(?P<name>…)` in Python and `(?<name>…)` in JS (do not use them); lookbehind must be fixed-width in Python; inline flags anywhere but the start fail in both. The generated keys (escaped literals, `(?:…|…)`, `^…$`) mean the same in both.
|
|
42
|
-
- **The completion policy is picked in LXP**, not in the project: the publish skill proposes it from this table and sets it with the upload after the person agrees (graded: the quiz template or settings with `grading` → `on_graded`; the survey template → `on_access` (decided 2026-11-25; may change; it still submits with `useSubmit`); other submits without grading → `on_submit`; no submission → `on_access`), or the instructor chooses it in the '설정' panel at the top of the LXP edit page, which applies at once (ADR 0012). The templates carry a default that the server sets when the template is applied to a page that has never been saved (quiz `on_graded`; survey, document and
|
|
42
|
+
- **The completion policy is picked in LXP**, not in the project: the publish skill proposes it from this table and sets it with the upload after the person agrees (graded: the quiz template or settings with `grading` → `on_graded`; the survey template → `on_access` (decided 2026-11-25; may change; it still submits with `useSubmit`); other submits without grading → `on_submit`; no submission → `on_access`), or the instructor chooses it in the '설정' panel at the top of the LXP edit page, which applies at once (ADR 0012). The templates carry a default that the server sets when the template is applied to a page that has never been saved (quiz `on_graded`; survey, document, video and YouTube `on_access`); a saved page keeps its policy. `on_graded` needs `settings.grading` saved first, so it goes in the same save as settings with `grading`, or later. Do not write it in `metadata.json` (the old `completionPolicies` and `screens.completionPolicy` are ignored with the warning `manifest.completion-policies-ignored`, and `ecdk build` leaves them out of the zip). The content can read the current policy (SDK `material.completionPolicy`) but never sets it. Build what the suggested policy needs: a submission (`useSubmit`) for `on_submit` · `on_graded`, and the grading saved on the edit screen for `on_graded`. The server rejects `on_graded` without `settings.grading` (`MATERIAL_GRADING_REQUIRED`). The edit screen never sends a policy.
|
|
43
43
|
- **Only `on_graded` grades.** `on_submit` completes on any submission and does not grade, even with saved answers: the submission comes back `is_correct: null`, `score: 100`, and the kit shows "제출했어요.". `on_access` completes on open. A quiz with `on_submit` shows no score; that is the policy, not broken grading.
|
|
44
44
|
- Custom HTML does not use manual grading (`manual`) or no grading (`none`). With `pattern` there is no per-question grading: every question must be right for 100 (use `partial_pattern` for a score per question). Changing the answers does not regrade past submissions.
|
|
45
45
|
- Answers never go in the zip (`metadata.json` · data JSON · code), and there is no answer file in the project: answers exist only in `settings.grading`, saved on the edit screen. The old `gradingTypes` field is gone (2026-11-10): `ecdk build` warns when it is still in `metadata.json` or an old `elice.config.json`. A grading with the 11-10 policy and grader fields is rejected with how to rewrite it.
|
|
@@ -10,6 +10,7 @@ Run `ecdk create --list` first: it prints each template with its own version (`q
|
|
|
10
10
|
| The person designs the screens, or an interaction the lesson layouts cannot do (live simulation, game, custom visualization) | `ecdk create <folder> --template blank` (three screens with a small example to replace, "예측하고 확인하기", and the kit content editor on the edit screen: see 5) |
|
|
11
11
|
| A material in several steps (intro → experiment → summary, slides) | `ecdk create <folder> --template steps` (kit stepper `app.useStepper` and a different content layout per step, example "진자의 주기", content editor on the edit screen: see [14](14-layouts.md)) |
|
|
12
12
|
| One document to read (PDF or PPTX, completion on opening) | `ecdk create <folder> --template document` (the edit screen uploads a `.pdf` or `.pptx` and edits PPTX slide text in place; the student screen pages through it; `on_access` picked in LXP; `.ppt` · `.pps` · `.ppsx` must be saved as `.pptx` or `.pdf` first; in `ecdk dev` the file stays in `.ecdk/assets/`; for a page on LXP upload it with the MCP `create_asset_upload`, [12](12-upload-with-the-material-mcp.md) "Images and documents") |
|
|
13
|
+
| A YouTube video (one video URL, completion on opening, like the LXP YouTube material) | `ecdk create <folder> --template youtube` (the edit screen takes one YouTube URL (watch, youtu.be, Shorts, live, embed; a `t=` start time is kept) with a live preview; the student screen shows the `youtube-nocookie.com/embed/` player and a 'YouTube에서 보기' link; no submission, `on_access` picked in LXP; the player shows only where the server's content CSP allows that path) |
|
|
13
14
|
| Block coding or Entry Python practice in Entry, AI blocks included | `ecdk create <folder> --template entry` (the Entry workspace in an iframe, so it works only where the server's content CSP allows the workspace; the person builds the start and answer projects on the edit screen; general or AI grading; then [17](17-using-the-entry-template.md)) |
|
|
14
15
|
| A dark screen | Add `--theme dark` to the above |
|
|
15
16
|
| A problem description | Create with blank, set `metadata.json` to `{ "kind": "description", "screens": { "learn": { "enabled": true, "entry": "index.html" } }, "commentary": "commentary.txt" }`, delete the other screen files |
|
|
@@ -2,11 +2,11 @@
|
|
|
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 (`@eliceio/cdk`, imported by the kit and bundled by `ecdk build`) directly.
|
|
5
|
-
3. **Do not use blocked features**: `alert`/`confirm`/`prompt` · `window.open` · `<form>` submission · access to `window.parent`/`top` · `fetch`/`WebSocket` to external addresses (an AI call to mlapi goes through `sdk.mlapi.fetch`, which the check allows) · 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.
|
|
5
|
+
3. **Do not use blocked features**: `alert`/`confirm`/`prompt` · `window.open` (the popup inherits the sandbox, so login or video pages break in it; for an external page use a plain `<a href="https://…">` link, which the platform opens in a new tab outside the sandbox) · `<form>` submission · access to `window.parent`/`top` · `fetch`/`WebSocket` to external addresses (an AI call to mlapi goes through `sdk.mlapi.fetch`, which the check allows) · 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
|
- **Never collect a learner's personal data** (name, phone number, email, address, date of birth, student number, resident registration number, bank account, face photo, location …) through any of these: a submission, `kvstore`, the edit screen's content (`settings`, sent to every viewer), a file upload (`assets`) or an AI call (`mlapi`, sent to an outside model). Submissions and `kvstore` values stay on the server where instructors and operators read them. Use `app.account.anonymousId` to tell learners apart ([2](02-design-the-material.md) "Personal data").
|
|
7
7
|
- The check warns about it (`privacy.personal-field`): an input that takes personal data (`type="tel"` · `type="email"`, an `autocomplete` of name · tel · email · address · birthday · card, or an input whose `name` · `id` · `placeholder` · `<label>` says 전화 · 이메일 · 학번 · 주민 · phone · email …), a personal key (`phone` · `email` · `studentId` · `연락처` …) in `submit` · `useSubmit` · `kvstore.post`, or `account.fullname` inside `submit` · `useSubmit` · `kvstore.post` · `saveSettings` · `useSave` · `mlapi.fetch` · `assets.post`. Remove the field or the value; do not silence it. Only code that never stores or sends the value (a regex lab that checks an email format on screen) may use `ecdk-ignore-next-line privacy.personal-field` with the reason.
|
|
8
8
|
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.
|
|
9
|
-
- 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.
|
|
9
|
+
- 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). The only external frames allowed are the `rules.json` `externalAllow` `frame-src` entries: the Entry workspace and YouTube players under `https://www.youtube-nocookie.com/embed/` (not `youtube.com`, no IFrame API script; use the youtube template). 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.
|
|
10
10
|
- 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.
|
|
11
11
|
5. **Use relative paths** (`img/a.png`). Paths starting with `/` break. Match file name case. Prefer letters, digits, `-` and `_`.
|
|
12
12
|
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".
|
|
@@ -11,7 +11,7 @@ Read `check.issues[]` (`id` · `level` · `path` · `line` · `message`) from `e
|
|
|
11
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
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
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`
|
|
14
|
+
| `api.dialog` · `api.window-open` · `html.form` | An in-page message · the same view · a button click + `useSubmit` · an external page as a plain `<a href="https://…">` (opened in a new tab) |
|
|
15
15
|
| `api.external-send` | Remove the external send. An AI call to mlapi goes through `sdk.mlapi.fetch` (the check allows it, also with the absolute `https://mlapi.run/…` address) |
|
|
16
16
|
| `sec.answer-in-bundle` | A correct answer saved on the edit screen (`.ecdk/settings.json` grading) appears as is in screen code, a data JSON or `commentary.txt`, which students can read from the zip. Remove it there; answers live only in the grading settings |
|
|
17
17
|
| `privacy.personal-field` (warn) | Learner personal data: an input for it (`type="tel"` · `"email"`, a personal `autocomplete`, a name · id · placeholder · label saying phone · email · 학번 …), a personal key in `submit` · `kvstore.post`, or `account.fullname` in a submit · save · upload · `mlapi` call. Remove it: tell learners apart with `app.account.anonymousId`, only show `fullname`, make surveys anonymous ([2](02-design-the-material.md) "Personal data"). `ecdk-ignore` only for code that never stores or sends the value, with the reason |
|
|
@@ -64,7 +64,7 @@ Next time, read it, confirm the page with the person as above (기관 · 과목
|
|
|
64
64
|
|
|
65
65
|
**Completion policy** (2026-11-12: the upload can set it)
|
|
66
66
|
|
|
67
|
-
The completion policy is not in the project or the zip (ADR 0012): it is a setting of the LXP page, independent of versions, and it applies as soon as it is set. The publish skill proposes one and sets it with the save after the person agrees, when the save tool takes it. Detect support like `settings`: use `completion_policy` only when the input schema of `save_draft` (or `update_material`) lists it in `payload`. If no tool has it, tell the person after saving which one to pick in the '설정' panel opened from the top of the LXP edit page (choosing applies at once). The templates carry a default that the server sets when the template is applied to a page that has never been saved (quiz and Entry `on_graded`; survey, document, video and board `on_access`); a saved page keeps its policy, so still check `get_material` and propose as below.
|
|
67
|
+
The completion policy is not in the project or the zip (ADR 0012): it is a setting of the LXP page, independent of versions, and it applies as soon as it is set. The publish skill proposes one and sets it with the save after the person agrees, when the save tool takes it. Detect support like `settings`: use `completion_policy` only when the input schema of `save_draft` (or `update_material`) lists it in `payload`. If no tool has it, tell the person after saving which one to pick in the '설정' panel opened from the top of the LXP edit page (choosing applies at once). The templates carry a default that the server sets when the template is applied to a page that has never been saved (quiz and Entry `on_graded`; survey, document, video, YouTube and board `on_access`); a saved page keeps its policy, so still check `get_material` and propose as below.
|
|
68
68
|
|
|
69
69
|
| The material | Propose |
|
|
70
70
|
| -------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
@@ -4,7 +4,7 @@ the lesson template (`ecdk create <folder> --template lesson`) makes a **learnin
|
|
|
4
4
|
|
|
5
5
|
## When to use it
|
|
6
6
|
|
|
7
|
-
- **The default** for a learning material when the request is not one of the type templates (quiz, survey, PDF/PPT document, video, Entry, board) and the person has not specified their own screen layout: explanations, guided practice, workshop material, "학습 자료 · 교육 자료 · 실습 자료 · 강의 자료 만들어줘".
|
|
7
|
+
- **The default** for a learning material when the request is not one of the type templates (quiz, survey, PDF/PPT document, video, YouTube video, Entry, board) and the person has not specified their own screen layout: explanations, guided practice, workshop material, "학습 자료 · 교육 자료 · 실습 자료 · 강의 자료 만들어줘".
|
|
8
8
|
- **Not lesson**: a type template fits (use that template), the person describes their own screens, or the activity needs an interaction the layouts cannot do (a simulation whose picture changes with the values, a game, a custom visualization) → the blank template ([3](03-create-the-project.md)). Tell the person the choice in one line.
|
|
9
9
|
- A graded test is the quiz template: lesson quizzes are **self-check only** (the student sees right or wrong and the explanation on the page; nothing is submitted or graded, and the answers are in the content, which students can read). Suggest the completion policy `on_access` (done on open) in LXP. The template has no instructor screen.
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ Write the progress line `[n/N] …` before and after every step below (Always
|
|
|
16
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`; a survey (opinions, feedback, self-assessment, no right answers): the survey template and `references/16-using-the-survey-template.md` for the settings shape, question-writing rules, personal data and where the answers are; block coding in Entry: the Entry template and `references/17-using-the-entry-template.md`, where the person builds the start and answer projects on the edit screen and you never write project JSON); 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
|
-
- **A learning material the person did not give a screen layout for** (explanations, guided practice, self-check, "학습 자료 만들어줘") and that is not a quiz, survey, PDF/PPT document, video, Entry or board request: use the lesson template and `references/18-using-the-lesson-template.md`. You write only the content (`.ecdk/settings.json`, the lesson content object with layouts from `references/19-lesson-layouts.md`), never screen code; `ecdk doctor` (`project.lesson`) checks it. Lesson quizzes are self-check only. In a run without a person, skip the edit-view save and report how the content reaches LXP (`references/18-using-the-lesson-template.md` step 8).
|
|
19
|
+
- **A learning material the person did not give a screen layout for** (explanations, guided practice, self-check, "학습 자료 만들어줘") and that is not a quiz, survey, PDF/PPT document, video, YouTube video, Entry or board request: use the lesson template and `references/18-using-the-lesson-template.md`. You write only the content (`.ecdk/settings.json`, the lesson content object with layouts from `references/19-lesson-layouts.md`), never screen code; `ecdk doctor` (`project.lesson`) checks it. Lesson quizzes are self-check only. In a run without a person, skip the edit-view save and report how the content reaches LXP (`references/18-using-the-lesson-template.md` step 8).
|
|
20
20
|
- When the person wants to design the screens themselves, or the activity needs an interaction the lesson layouts cannot do (a live simulation, a game, a custom visualization), 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 `이 자료에 맞게 바꿀 곳`.
|
|
21
21
|
- If the person describes the content (for example "5 questions about perceptrons"), fill it in so the upload can carry it: write `.ecdk/settings.json` in the shape `references/09-check.md` describes (the edit screen's content object at the top level, `grading` when graded), then have the person open the edit view in `ecdk dev`, check it and save with the edit screen's button, so the edit screen's own validation runs. Draft the answers, but the person confirms them before any upload (Always). One quiz material holds up to 20 questions (`references/06-using-the-quiz-template.md`): put them all in one material; only more than 20 means several quiz materials (pages). If the person prefers, give the content as draft text (the content editor: one JSON block for 코드 보기) to enter in the LXP edit screen instead. Not for the Entry template: its settings are Entry projects the person builds on the edit screen, never written by you, also in a run without a person (`references/17-using-the-entry-template.md` "Who makes what").
|
|
22
22
|
4. **Check each screen** with `ecdk dev <folder> --check --screens <screen>` after you write it (`references/09-check.md`), fix what it reports (error ids: `references/08-fix-check-errors.md`). The person looks at the screens too.
|
|
@@ -63,17 +63,12 @@ const workspaces = { start: null, answer: null };
|
|
|
63
63
|
const held = { start: null, answer: null };
|
|
64
64
|
const heldListeners = { start: new Set(), answer: new Set() };
|
|
65
65
|
/** 정답 작품 워크스페이스가 처음 열 작품: 저장된 정답 → 없으면 지금 시작 화면 작품 (오브젝트 id가 같아야 AI 채점 기준이 맞음) */
|
|
66
|
-
const answerStart = async () =>
|
|
67
|
-
|
|
68
|
-
async function startNow() {
|
|
69
|
-
return (await workspaces.start?.getProject().catch(() => null)) ?? startProject;
|
|
70
|
-
}
|
|
66
|
+
const answerStart = async () =>
|
|
67
|
+
savedAnswer ?? (await workspaces.start?.getProject().catch(() => null)) ?? startProject;
|
|
71
68
|
|
|
72
|
-
// getInitialProject: 워크스페이스 [작품 불러오기] > [시작 상태로 작품 초기화하기]가 묻는 작품.
|
|
73
|
-
// 정답 작품 탭에서는 저장된 정답이 아니라 지금 시작 화면을 준다 (시작 화면에 블록을 더해 정답을 만들므로)
|
|
74
69
|
const providers = {
|
|
75
70
|
start: { getProject: () => startProject, getInitialProject: () => startProject },
|
|
76
|
-
answer: { getProject: answerStart, getInitialProject:
|
|
71
|
+
answer: { getProject: answerStart, getInitialProject: answerStart },
|
|
77
72
|
};
|
|
78
73
|
|
|
79
74
|
function workspace(name) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
Elice Custom HTML 학습자료 프로젝트입니다 (YouTube 템플릿). YouTube 영상 주소 하나를 받아 학생 화면에 플레이어로 보여 줍니다. 제출은 없고, 완료 정책은 **열람 시 완료(on_access)**를 권장합니다.
|
|
4
|
+
|
|
5
|
+
플레이어는 `https://www.youtube-nocookie.com/embed/<영상 ID>` iframe입니다. YouTube IFrame API 스크립트는 쓰지 않습니다 (콘텐츠 CSP가 외부 스크립트를 막음). 콘텐츠 CSP는 `frame-src`에서 `https://www.youtube-nocookie.com/embed/` 경로만 허용합니다 (`rules.json` `externalAllow`). 서버 콘텐츠 CSP에 이 경로가 들어가기 전의 LXP에서는 플레이어 자리가 비어 보이고, 'YouTube에서 보기' 링크만 동작합니다.
|
|
6
|
+
|
|
7
|
+
## 고치는 곳
|
|
8
|
+
|
|
9
|
+
| 파일 | 화면 |
|
|
10
|
+
| --------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
11
|
+
| `screens/learn.js` · `index.html` | 학생 화면 (16:9 플레이어 + 'YouTube에서 보기' 링크, 제출 없음) |
|
|
12
|
+
| `screens/edit.js` · `edit.html` | 내용 편집 화면 ('YouTube 주소' 한 칸 · 미리보기 · '초안으로 저장'). 키트 편집 화면(`body.ec-edit-page`) |
|
|
13
|
+
| `ui/` | 모양: 색 · 문구 · 마크업 (`theme.css` · `texts.js` · `templates/`) |
|
|
14
|
+
| `styles.css` | 플레이어 자리 · 링크 줄 · 미리보기 자리 |
|
|
15
|
+
| `core/youtube.js` | 주소 읽기 · 플레이어 주소 만들기 (고치지 않음) |
|
|
16
|
+
| `core/settings.js` | 저장 모양과 검증 (고치지 않음) |
|
|
17
|
+
| `metadata.json` | 화면 구성(`screens`) · 학습 참고 내용(`commentary`). `ecdk build`가 `build`만 채움 |
|
|
18
|
+
| `package.json` | SDK 버전(`@eliceio/cdk`) · 빌드 옵션 `"ecdk"`. zip에 들어가지 않음 |
|
|
19
|
+
|
|
20
|
+
플레이어 안(재생 · 컨트롤 · 화질 · 자막 · '동영상을 재생할 수 없음' 같은 오류)은 YouTube iframe이라 이 프로젝트에서 바꿀 수 없습니다.
|
|
21
|
+
|
|
22
|
+
## 받는 주소
|
|
23
|
+
|
|
24
|
+
- `https://www.youtube.com/watch?v=ID` (`&t=90` · `&t=1m30s` · `&start=90`이 있으면 그 시각부터)
|
|
25
|
+
- `https://youtu.be/ID` · `https://www.youtube.com/embed/ID` · `/shorts/ID` · `/live/ID`
|
|
26
|
+
- `https://m.youtube.com/watch?v=ID` · `https://music.youtube.com/watch?v=ID` · `https://www.youtube-nocookie.com/embed/ID`
|
|
27
|
+
- 앞의 `https://`는 생략해도 됩니다. ID는 영문 · 숫자 · `-` · `_` 11자입니다. 재생목록 · 채널 주소처럼 영상 ID가 없는 주소는 받지 않습니다.
|
|
28
|
+
|
|
29
|
+
## 학생 화면
|
|
30
|
+
|
|
31
|
+
- 플레이어: `https://www.youtube-nocookie.com/embed/ID?rel=0&playsinline=1`(시작 시각이 있으면 `&start=N`), `allow="autoplay; encrypted-media; picture-in-picture; fullscreen"` · `allowfullscreen` · `referrerpolicy="strict-origin-when-cross-origin"`. YouTube는 퍼가는 페이지의 출처(리퍼러)를 보고 재생을 허락하므로 `referrerpolicy`를 지우지 마세요 (리퍼러가 없으면 "오류 153").
|
|
32
|
+
- 플레이어 아래 'YouTube에서 보기'는 보통 `<a href>` 링크입니다. LXP가 sandbox 밖 새 탭(앱은 앱 브라우저)으로 엽니다. `window.open`은 쓰지 않습니다 (sandbox 팝업에서 YouTube 페이지가 깨짐). 퍼가기를 막은 영상은 플레이어에서 재생되지 않으니 이 링크로 보게 됩니다.
|
|
33
|
+
- 화면 폭을 채우되, 링크 줄까지 한 화면에 보이도록 높이에 맞춰 폭을 줄입니다.
|
|
34
|
+
- 주소를 저장하지 않았으면 빈 안내("학습 자료를 준비하고 있어요")를 보입니다 (`app.hasContent` · `app.emptyState()`).
|
|
35
|
+
|
|
36
|
+
## 학습 완료
|
|
37
|
+
|
|
38
|
+
- 제출하지 않습니다. LXP 페이지 설정의 완료 정책은 **열람 시 완료(on_access)**로 둡니다 (기존 LXP YouTube 자료와 같음). publish 스킬이 동의를 받아 업로드 때 정하거나, 교육자가 LXP 편집 페이지 위쪽 '설정' 패널에서 고릅니다.
|
|
39
|
+
- 시청 비율 · 끝까지 봄 · 재생 위치는 읽지 않습니다 (IFrame API를 쓰지 않음). 출결 · 이수 증빙이 필요한 과정에는 Elice 비디오 자료를 쓰세요.
|
|
40
|
+
|
|
41
|
+
## 저장 모양 (`settings`)
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
{
|
|
45
|
+
youtube: {
|
|
46
|
+
url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ&t=30', // 교육자가 넣은 주소
|
|
47
|
+
videoId: 'aqz-KE-bpKQ', // 주소에서 읽은 영상 ID
|
|
48
|
+
start: 30, // 시작 초 (주소에 t= · start=가 있을 때만)
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- 다른 키(예: AI · MCP가 넣은 `title`)는 저장 때 그대로 둡니다. 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
54
|
+
- `ecdk dev`의 내용 편집에서 저장한 것은 `.ecdk/settings.json`에 남습니다 (zip에는 들어가지 않음). 기본으로는 로컬에만 있고, publish 스킬로 올릴 때 동의하면 업로드와 함께 보냅니다.
|
|
55
|
+
|
|
56
|
+
교육자 화면은 없습니다 (`metadata.json` `screens.instructor.enabled: false`). LXP에서 교육자가 열면 학생 화면이 열립니다.
|
|
57
|
+
|
|
58
|
+
`lib/`(화면 키트)는 플랫폼 연결 로직이라 고치지 않습니다. SDK는 `package.json` 의존성(`@eliceio/cdk`)이고 키트가 import하며, `ecdk build`(Vite)가 화면 코드와 함께 번들로 묶습니다 (처음 한 번 `npm install`, 올리기 `npm update @eliceio/cdk`).
|
|
59
|
+
|
|
60
|
+
## 명령
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
ecdk dev # 로컬에서 보기 (ecdk dev CSP도 youtube-nocookie /embed/를 허용해 플레이어가 뜸)
|
|
64
|
+
ecdk doctor # 환경·프로젝트 점검
|
|
65
|
+
ecdk build # 검사 후 dist/content.zip (편집 화면에 올릴 파일)
|
|
66
|
+
```
|
|
@@ -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 = 'yt-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,21 @@
|
|
|
1
|
+
// core/settings.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export interface YouTubeValue {
|
|
3
|
+
url: string;
|
|
4
|
+
videoId: string;
|
|
5
|
+
start?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface YouTubeDraft {
|
|
9
|
+
rest: Record<string, unknown>;
|
|
10
|
+
youtube: YouTubeValue | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare function normalizeSettings(
|
|
14
|
+
raw: Record<string, unknown> | null | undefined
|
|
15
|
+
): YouTubeDraft;
|
|
16
|
+
export declare function fromUrl(text: string): YouTubeValue | null;
|
|
17
|
+
export declare function toSettings(draft: YouTubeDraft): Record<string, unknown>;
|
|
18
|
+
export declare function validateUrl(
|
|
19
|
+
text: string,
|
|
20
|
+
messages: { urlRequired: string; urlInvalid: string }
|
|
21
|
+
): true | string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// 저장 모양(settings)과 검증. 편집 화면이 저장하고 학생 화면이 읽습니다. 고치지 않습니다: 키 이름을 바꾸면 저장한 자료를 읽지 못합니다.
|
|
2
|
+
//
|
|
3
|
+
// {
|
|
4
|
+
// youtube: {
|
|
5
|
+
// url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ&t=30', // 교육자가 넣은 주소 (앞뒤 공백만 뺌)
|
|
6
|
+
// videoId: 'aqz-KE-bpKQ', // 주소에서 읽은 영상 ID
|
|
7
|
+
// start: 30, // 시작 초 (주소에 t= · start=가 있을 때만)
|
|
8
|
+
// },
|
|
9
|
+
// }
|
|
10
|
+
// 학생 화면은 videoId · start만 씁니다 (url은 편집 화면이 다시 보여 줄 때). 그 밖의 키(예: AI · MCP가 넣은 title)는
|
|
11
|
+
// 저장 때 그대로 둡니다. 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
12
|
+
import { parseYouTubeUrl } from './youtube.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 저장된 settings를 화면이 쓰는 모양으로. videoId가 맞지 않으면 url을 다시 읽고, 그래도 아니면 youtube 없음
|
|
16
|
+
* @param {Record<string, unknown> | null | undefined} raw
|
|
17
|
+
*/
|
|
18
|
+
export function normalizeSettings(raw) {
|
|
19
|
+
const s = raw && typeof raw === 'object' ? raw : {};
|
|
20
|
+
const y = s.youtube && typeof s.youtube === 'object' ? s.youtube : null;
|
|
21
|
+
const url = y && typeof y.url === 'string' ? y.url.trim() : '';
|
|
22
|
+
const parsed = parseYouTubeUrl(url);
|
|
23
|
+
let youtube = null;
|
|
24
|
+
if (parsed) youtube = { url, ...parsed };
|
|
25
|
+
else if (y && typeof y.videoId === 'string' && parseYouTubeUrl(`youtu.be/${y.videoId}`)) {
|
|
26
|
+
const start = Number.isSafeInteger(y.start) && y.start > 0 ? y.start : undefined;
|
|
27
|
+
youtube = { url, videoId: y.videoId, ...(start ? { start } : {}) };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
/** 저장 때 그대로 둘 다른 키 */
|
|
31
|
+
rest: Object.fromEntries(Object.entries(s).filter(([k]) => k !== 'youtube')),
|
|
32
|
+
youtube,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 편집 화면의 주소 칸 글을 저장할 youtube 값으로. 빈 칸 · YouTube 주소가 아니면 null
|
|
38
|
+
* @param {string} text
|
|
39
|
+
*/
|
|
40
|
+
export function fromUrl(text) {
|
|
41
|
+
const url = typeof text === 'string' ? text.trim() : '';
|
|
42
|
+
const parsed = parseYouTubeUrl(url);
|
|
43
|
+
return parsed ? { url, ...parsed } : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 화면 상태를 저장 모양으로 */
|
|
47
|
+
export function toSettings(draft) {
|
|
48
|
+
const y = draft.youtube;
|
|
49
|
+
return {
|
|
50
|
+
...draft.rest,
|
|
51
|
+
...(y
|
|
52
|
+
? {
|
|
53
|
+
youtube: {
|
|
54
|
+
url: y.url,
|
|
55
|
+
videoId: y.videoId,
|
|
56
|
+
...(y.start ? { start: y.start } : {}),
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 저장 전 검증. 통과면 true, 아니면 화면에 보일 문구
|
|
65
|
+
* @param {string} text 주소 칸 글
|
|
66
|
+
* @param {{ urlRequired: string, urlInvalid: string }} messages
|
|
67
|
+
*/
|
|
68
|
+
export function validateUrl(text, messages) {
|
|
69
|
+
if (typeof text !== 'string' || text.trim() === '') return messages.urlRequired;
|
|
70
|
+
return fromUrl(text) ? true : messages.urlInvalid;
|
|
71
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// core/youtube.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export declare const VIDEO_ID: RegExp;
|
|
3
|
+
export declare const EMBED_BASE: string;
|
|
4
|
+
export declare function parseStart(value: string | null | undefined): number | undefined;
|
|
5
|
+
export declare function parseYouTubeUrl(
|
|
6
|
+
input: string | null | undefined
|
|
7
|
+
): { videoId: string; start?: number } | null;
|
|
8
|
+
export declare function embedUrl(videoId: string, start?: number): string;
|
|
9
|
+
export declare function watchUrl(videoId: string, start?: number): string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// YouTube 주소 읽기 · 플레이어 주소 만들기. 편집 화면(검증 · 미리보기)과 학생 화면(플레이어)이 같이 씁니다. 고치지 않습니다.
|
|
2
|
+
//
|
|
3
|
+
// 받는 주소 (http · https, 앞의 https:// 생략 가능):
|
|
4
|
+
// youtube.com/watch?v=ID (&t=… · &start=…), m.youtube.com/watch?v=ID, music.youtube.com/watch?v=ID
|
|
5
|
+
// youtu.be/ID, youtube.com/embed/ID · /shorts/ID · /live/ID, youtube-nocookie.com/embed/ID
|
|
6
|
+
// ID는 영문 · 숫자 · - · _ 11자. 재생목록 · 채널 주소처럼 영상 ID가 없는 주소는 받지 않습니다.
|
|
7
|
+
// 시작 시각은 t= · start= (초 "90" · "90s" · "1m30s" · "1h2m3s")를 초로 읽습니다.
|
|
8
|
+
//
|
|
9
|
+
// 플레이어는 www.youtube-nocookie.com/embed/ 주소만 씁니다: LXP 콘텐츠 CSP가 frame-src로 이 경로만 허용합니다.
|
|
10
|
+
// YouTube IFrame API 스크립트는 쓰지 않습니다 (script-src가 외부 스크립트를 막음).
|
|
11
|
+
|
|
12
|
+
/** 영상 ID: 영문 · 숫자 · - · _ 11자 */
|
|
13
|
+
export const VIDEO_ID = /^[A-Za-z0-9_-]{11}$/;
|
|
14
|
+
|
|
15
|
+
/** 플레이어(iframe) 주소의 앞부분. rules.json externalAllow frame-src와 같아야 LXP · ecdk dev에서 뜹니다 */
|
|
16
|
+
export const EMBED_BASE = 'https://www.youtube-nocookie.com/embed/';
|
|
17
|
+
|
|
18
|
+
const WATCH_HOSTS = new Set([
|
|
19
|
+
'youtube.com',
|
|
20
|
+
'www.youtube.com',
|
|
21
|
+
'm.youtube.com',
|
|
22
|
+
'music.youtube.com',
|
|
23
|
+
]);
|
|
24
|
+
const NOCOOKIE_HOSTS = new Set(['youtube-nocookie.com', 'www.youtube-nocookie.com']);
|
|
25
|
+
const SHORT_HOSTS = new Set(['youtu.be', 'www.youtu.be']);
|
|
26
|
+
/** youtube.com/<이것>/ID 꼴 */
|
|
27
|
+
const PATH_KINDS = new Set(['embed', 'shorts', 'live']);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 시작 시각 글을 초로. "90" · "90s" · "1m30s" · "1h2m3s" (대소문자 무관). 0이나 읽을 수 없으면 undefined
|
|
31
|
+
* @param {string | null | undefined} value
|
|
32
|
+
* @returns {number | undefined}
|
|
33
|
+
*/
|
|
34
|
+
export function parseStart(value) {
|
|
35
|
+
if (typeof value !== 'string') return undefined;
|
|
36
|
+
const v = value.trim().toLowerCase();
|
|
37
|
+
let seconds;
|
|
38
|
+
if (/^\d+s?$/.test(v)) seconds = Number.parseInt(v, 10);
|
|
39
|
+
else {
|
|
40
|
+
const m = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(v);
|
|
41
|
+
if (!m || (!m[1] && !m[2] && !m[3])) return undefined;
|
|
42
|
+
seconds = Number(m[1] ?? 0) * 3600 + Number(m[2] ?? 0) * 60 + Number(m[3] ?? 0);
|
|
43
|
+
}
|
|
44
|
+
return Number.isSafeInteger(seconds) && seconds > 0 ? seconds : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* YouTube 주소에서 영상 ID · 시작 시각(초)을 읽는다. YouTube 영상 주소가 아니면 null
|
|
49
|
+
* @param {string | null | undefined} input
|
|
50
|
+
* @returns {{ videoId: string, start?: number } | null}
|
|
51
|
+
*/
|
|
52
|
+
export function parseYouTubeUrl(input) {
|
|
53
|
+
if (typeof input !== 'string') return null;
|
|
54
|
+
const text = input.trim();
|
|
55
|
+
if (text === '' || /\s/.test(text)) return null;
|
|
56
|
+
let url;
|
|
57
|
+
try {
|
|
58
|
+
url = new URL(
|
|
59
|
+
/^[a-z][a-z0-9+.-]*:/i.test(text) ? text : `https://${text.replace(/^\/\//, '')}`
|
|
60
|
+
);
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') return null;
|
|
65
|
+
if (url.username || url.password || (url.port && url.port !== '443' && url.port !== '80'))
|
|
66
|
+
return null;
|
|
67
|
+
const host = url.hostname.toLowerCase();
|
|
68
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
69
|
+
|
|
70
|
+
let videoId = null;
|
|
71
|
+
if (SHORT_HOSTS.has(host)) {
|
|
72
|
+
if (segments.length === 1) videoId = segments[0];
|
|
73
|
+
} else if (NOCOOKIE_HOSTS.has(host)) {
|
|
74
|
+
if (segments.length === 2 && segments[0] === 'embed') videoId = segments[1];
|
|
75
|
+
} else if (WATCH_HOSTS.has(host)) {
|
|
76
|
+
if (segments.length === 1 && segments[0] === 'watch') videoId = url.searchParams.get('v');
|
|
77
|
+
else if (host !== 'music.youtube.com' && segments.length === 2 && PATH_KINDS.has(segments[0]))
|
|
78
|
+
videoId = segments[1];
|
|
79
|
+
}
|
|
80
|
+
if (!videoId || !VIDEO_ID.test(videoId)) return null;
|
|
81
|
+
|
|
82
|
+
// 시작 시각: 검색 인자 t · start, 없으면 #t=…
|
|
83
|
+
const hash = new URLSearchParams(url.hash.replace(/^#/, ''));
|
|
84
|
+
const start =
|
|
85
|
+
parseStart(url.searchParams.get('t')) ??
|
|
86
|
+
parseStart(url.searchParams.get('start')) ??
|
|
87
|
+
parseStart(hash.get('t'));
|
|
88
|
+
return start ? { videoId, start } : { videoId };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 플레이어(iframe) 주소. rel=0: 끝난 뒤 관련 영상을 같은 채널 것으로, playsinline=1: iOS에서 화면 안 재생
|
|
93
|
+
* @param {string} videoId
|
|
94
|
+
* @param {number} [start] 시작 초
|
|
95
|
+
*/
|
|
96
|
+
export function embedUrl(videoId, start) {
|
|
97
|
+
const params = new URLSearchParams({ rel: '0', playsinline: '1' });
|
|
98
|
+
if (start) params.set('start', String(start));
|
|
99
|
+
return `${EMBED_BASE}${encodeURIComponent(videoId)}?${params}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* YouTube에서 보기 주소 (새 탭 · 앱 브라우저로 열림)
|
|
104
|
+
* @param {string} videoId
|
|
105
|
+
* @param {number} [start] 시작 초
|
|
106
|
+
*/
|
|
107
|
+
export function watchUrl(videoId, start) {
|
|
108
|
+
const params = new URLSearchParams({ v: videoId });
|
|
109
|
+
if (start) params.set('t', `${start}s`);
|
|
110
|
+
return `https://www.youtube.com/watch?${params}`;
|
|
111
|
+
}
|
|
@@ -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>
|