@sealcode/jdd-editor 0.1.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/.arcconfig +12 -0
- package/.arclint +18 -0
- package/.eslintrc.js +37 -0
- package/.mocharc.js +6 -0
- package/.nycrc +6 -0
- package/.prettierrc +14 -0
- package/@types/component-preview-actions.d.ts +43 -0
- package/@types/components.sreact.d.ts +48 -0
- package/@types/controllers/autogrow-textarea.stimulus.d.ts +5 -0
- package/@types/controllers/component-debugger.stimulus.d.ts +28 -0
- package/@types/controllers/exportable-textarea.stimulus.d.ts +7 -0
- package/@types/controllers/input-image-preview.stimulus.d.ts +5 -0
- package/@types/controllers/jdd-table-paste.stimulus.d.ts +8 -0
- package/@types/controllers/json-editor.stimulus.d.ts +9 -0
- package/@types/controllers/markdown-textarea.stimulus.d.ts +20 -0
- package/@types/controllers/refresh-on-ts-changes.stimulus.d.ts +6 -0
- package/@types/controllers/refresh-styles.stimulus.d.ts +6 -0
- package/@types/controllers/submit-on-input.stimulus.d.ts +7 -0
- package/@types/controllers/toast.stimulus.d.ts +4 -0
- package/@types/edit-jdd-field.d.ts +22 -0
- package/@types/index.d.ts +2 -0
- package/@types/inputs/component-input-enum.d.ts +8 -0
- package/@types/inputs/component-input-image.d.ts +15 -0
- package/@types/inputs/component-input-list.d.ts +15 -0
- package/@types/inputs/component-input-single-reference.d.ts +11 -0
- package/@types/inputs/component-input-structured.d.ts +15 -0
- package/@types/inputs/component-input-table.d.ts +15 -0
- package/@types/inputs/component-input.d.ts +16 -0
- package/@types/inputs/print-arg-path.d.ts +1 -0
- package/@types/jdd-creator.d.ts +49 -0
- package/@types/jdd-page.d.ts +85 -0
- package/assets/icons/table-add-column-right.svg +1 -0
- package/assets/icons/table-add-row-below.svg +1 -0
- package/assets/icons/table-add-row-header-below.svg +1 -0
- package/assets/icons/table-delete-column.svg +1 -0
- package/assets/icons/table-delete-row.svg +1 -0
- package/assets/icons/table-move-column-right.svg +1 -0
- package/assets/icons/table-move-row-down.svg +1 -0
- package/assets/icons/table-move-row-up.svg +1 -0
- package/assets/styles/component-admin-table.jdd-page.css +11 -0
- package/assets/styles/component-debugger.jdd-page.css +71 -0
- package/assets/styles/components.jdd-page.css +286 -0
- package/assets/styles/grow-wrap.css +33 -0
- package/assets/styles/markdown-editor.css +42 -0
- package/dist/src/autogrow-textarea.stimulus.js +13 -0
- package/dist/src/autogrow-textarea.stimulus.js.map +7 -0
- package/dist/src/component-debugger.stimulus.js +190 -0
- package/dist/src/component-debugger.stimulus.js.map +7 -0
- package/dist/src/component-preview-actions.js +439 -0
- package/dist/src/component-preview-actions.js.map +7 -0
- package/dist/src/components.sreact.js +93 -0
- package/dist/src/components.sreact.js.map +7 -0
- package/dist/src/controllers/autogrow-textarea.stimulus.js +13 -0
- package/dist/src/controllers/autogrow-textarea.stimulus.js.map +7 -0
- package/dist/src/controllers/component-debugger.stimulus.js +193 -0
- package/dist/src/controllers/component-debugger.stimulus.js.map +7 -0
- package/dist/src/controllers/exportable-textarea.stimulus.js +71 -0
- package/dist/src/controllers/exportable-textarea.stimulus.js.map +7 -0
- package/dist/src/controllers/input-image-preview.stimulus.js +30 -0
- package/dist/src/controllers/input-image-preview.stimulus.js.map +7 -0
- package/dist/src/controllers/jdd-table-paste.stimulus.js +78 -0
- package/dist/src/controllers/jdd-table-paste.stimulus.js.map +7 -0
- package/dist/src/controllers/json-editor.stimulus.js +114 -0
- package/dist/src/controllers/json-editor.stimulus.js.map +7 -0
- package/dist/src/controllers/markdown-textarea.stimulus.js +174 -0
- package/dist/src/controllers/markdown-textarea.stimulus.js.map +7 -0
- package/dist/src/controllers/refresh-on-ts-changes.stimulus.js +90 -0
- package/dist/src/controllers/refresh-on-ts-changes.stimulus.js.map +7 -0
- package/dist/src/controllers/refresh-styles.stimulus.js +67 -0
- package/dist/src/controllers/refresh-styles.stimulus.js.map +7 -0
- package/dist/src/controllers/submit-on-input.stimulus.js +55 -0
- package/dist/src/controllers/submit-on-input.stimulus.js.map +7 -0
- package/dist/src/controllers/toast.stimulus.js +19 -0
- package/dist/src/controllers/toast.stimulus.js.map +7 -0
- package/dist/src/edit-jdd-field.js +94 -0
- package/dist/src/edit-jdd-field.js.map +7 -0
- package/dist/src/exportable-textarea.stimulus.js +71 -0
- package/dist/src/exportable-textarea.stimulus.js.map +7 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +7 -0
- package/dist/src/input-image-preview.stimulus.js +30 -0
- package/dist/src/input-image-preview.stimulus.js.map +7 -0
- package/dist/src/inputs/component-input-enum.js +30 -0
- package/dist/src/inputs/component-input-enum.js.map +7 -0
- package/dist/src/inputs/component-input-image.js +58 -0
- package/dist/src/inputs/component-input-image.js.map +7 -0
- package/dist/src/inputs/component-input-list.js +74 -0
- package/dist/src/inputs/component-input-list.js.map +7 -0
- package/dist/src/inputs/component-input-single-reference.js +31 -0
- package/dist/src/inputs/component-input-single-reference.js.map +7 -0
- package/dist/src/inputs/component-input-structured.js +36 -0
- package/dist/src/inputs/component-input-structured.js.map +7 -0
- package/dist/src/inputs/component-input-table.js +228 -0
- package/dist/src/inputs/component-input-table.js.map +7 -0
- package/dist/src/inputs/component-input.js +129 -0
- package/dist/src/inputs/component-input.js.map +7 -0
- package/dist/src/inputs/print-arg-path.js +7 -0
- package/dist/src/inputs/print-arg-path.js.map +7 -0
- package/dist/src/jdd-creator.js +131 -0
- package/dist/src/jdd-creator.js.map +7 -0
- package/dist/src/jdd-page.js +339 -0
- package/dist/src/jdd-page.js.map +7 -0
- package/dist/src/jdd-table-paste.stimulus.js +78 -0
- package/dist/src/jdd-table-paste.stimulus.js.map +7 -0
- package/dist/src/json-editor.stimulus.js +114 -0
- package/dist/src/json-editor.stimulus.js.map +7 -0
- package/dist/src/markdown-textarea.stimulus.js +174 -0
- package/dist/src/markdown-textarea.stimulus.js.map +7 -0
- package/dist/src/submit-on-input.stimulus.js +55 -0
- package/dist/src/submit-on-input.stimulus.js.map +7 -0
- package/dist/src/toast.stimulus.js +19 -0
- package/dist/src/toast.stimulus.js.map +7 -0
- package/esbuild.cjs +20 -0
- package/esbuild.js +23 -0
- package/jenkins.sanity.sh +3 -0
- package/lib/component-preview-actions.js +286 -0
- package/lib/component-preview-actions.js.map +1 -0
- package/lib/components.sreact.js +102 -0
- package/lib/components.sreact.js.map +1 -0
- package/lib/controllers/autogrow-textarea.stimulus.js +15 -0
- package/lib/controllers/autogrow-textarea.stimulus.js.map +1 -0
- package/lib/controllers/component-debugger.stimulus.js +188 -0
- package/lib/controllers/component-debugger.stimulus.js.map +1 -0
- package/lib/controllers/exportable-textarea.stimulus.js +79 -0
- package/lib/controllers/exportable-textarea.stimulus.js.map +1 -0
- package/lib/controllers/input-image-preview.stimulus.js +28 -0
- package/lib/controllers/input-image-preview.stimulus.js.map +1 -0
- package/lib/controllers/jdd-table-paste.stimulus.js +84 -0
- package/lib/controllers/jdd-table-paste.stimulus.js.map +1 -0
- package/lib/controllers/json-editor.stimulus.js +134 -0
- package/lib/controllers/json-editor.stimulus.js.map +1 -0
- package/lib/controllers/markdown-textarea.stimulus.js +186 -0
- package/lib/controllers/markdown-textarea.stimulus.js.map +1 -0
- package/lib/controllers/refresh-on-ts-changes.stimulus.js +123 -0
- package/lib/controllers/refresh-on-ts-changes.stimulus.js.map +1 -0
- package/lib/controllers/refresh-styles.stimulus.js +66 -0
- package/lib/controllers/refresh-styles.stimulus.js.map +1 -0
- package/lib/controllers/submit-on-input.stimulus.js +48 -0
- package/lib/controllers/submit-on-input.stimulus.js.map +1 -0
- package/lib/controllers/toast.stimulus.js +16 -0
- package/lib/controllers/toast.stimulus.js.map +1 -0
- package/lib/edit-jdd-field.js +102 -0
- package/lib/edit-jdd-field.js.map +1 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/inputs/component-input-enum.js +25 -0
- package/lib/inputs/component-input-enum.js.map +1 -0
- package/lib/inputs/component-input-image.js +47 -0
- package/lib/inputs/component-input-image.js.map +1 -0
- package/lib/inputs/component-input-list.js +61 -0
- package/lib/inputs/component-input-list.js.map +1 -0
- package/lib/inputs/component-input-single-reference.js +36 -0
- package/lib/inputs/component-input-single-reference.js.map +1 -0
- package/lib/inputs/component-input-structured.js +42 -0
- package/lib/inputs/component-input-structured.js.map +1 -0
- package/lib/inputs/component-input-table.js +184 -0
- package/lib/inputs/component-input-table.js.map +1 -0
- package/lib/inputs/component-input.js +133 -0
- package/lib/inputs/component-input.js.map +1 -0
- package/lib/inputs/print-arg-path.js +7 -0
- package/lib/inputs/print-arg-path.js.map +1 -0
- package/lib/jdd-creator.js +113 -0
- package/lib/jdd-creator.js.map +1 -0
- package/lib/jdd-page.js +310 -0
- package/lib/jdd-page.js.map +1 -0
- package/package.json +61 -0
- package/src/component-preview-actions.ts +520 -0
- package/src/components.sreact.ts +100 -0
- package/src/controllers/autogrow-textarea.stimulus.ts +13 -0
- package/src/controllers/component-debugger.stimulus.ts +247 -0
- package/src/controllers/exportable-textarea.stimulus.ts +77 -0
- package/src/controllers/input-image-preview.stimulus.ts +29 -0
- package/src/controllers/jdd-table-paste.stimulus.ts +89 -0
- package/src/controllers/json-editor.stimulus.ts +127 -0
- package/src/controllers/markdown-textarea.stimulus.ts +198 -0
- package/src/controllers/refresh-on-ts-changes.stimulus.ts +112 -0
- package/src/controllers/refresh-styles.stimulus.ts +70 -0
- package/src/controllers/submit-on-input.stimulus.ts +66 -0
- package/src/controllers/toast.stimulus.ts +15 -0
- package/src/edit-jdd-field.ts +127 -0
- package/src/index.ts +2 -0
- package/src/inputs/component-input-enum.ts +36 -0
- package/src/inputs/component-input-image.ts +70 -0
- package/src/inputs/component-input-list.ts +91 -0
- package/src/inputs/component-input-single-reference.ts +45 -0
- package/src/inputs/component-input-structured.ts +51 -0
- package/src/inputs/component-input-table.ts +262 -0
- package/src/inputs/component-input.ts +158 -0
- package/src/inputs/print-arg-path.ts +3 -0
- package/src/jdd-creator.ts +151 -0
- package/src/jdd-page.ts +439 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Controller } from "stimulus";
|
|
2
|
+
function download(data, filename, type) {
|
|
3
|
+
const file = new Blob([data], { type });
|
|
4
|
+
const a = document.createElement("a"), url = URL.createObjectURL(file);
|
|
5
|
+
a.href = url;
|
|
6
|
+
a.download = filename;
|
|
7
|
+
document.body.appendChild(a);
|
|
8
|
+
a.click();
|
|
9
|
+
setTimeout(function() {
|
|
10
|
+
document.body.removeChild(a);
|
|
11
|
+
window.URL.revokeObjectURL(url);
|
|
12
|
+
}, 0);
|
|
13
|
+
}
|
|
14
|
+
class ExportableTextarea extends Controller {
|
|
15
|
+
connect() {
|
|
16
|
+
console.log("exportable", this.element);
|
|
17
|
+
this.element.removeAttribute("open");
|
|
18
|
+
this.element.addEventListener(
|
|
19
|
+
"turbo:before-morph-attribute",
|
|
20
|
+
(event) => {
|
|
21
|
+
if (event.target == this.element && event.detail.attributeName == "open") {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
async copy(e) {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
const textarea = this.element.querySelector("textarea");
|
|
30
|
+
if (!textarea) {
|
|
31
|
+
throw new Error("Couldn't find the textarea");
|
|
32
|
+
}
|
|
33
|
+
await navigator.clipboard.writeText(textarea.value);
|
|
34
|
+
e.target.textContent = "Copied";
|
|
35
|
+
await sleep(1e3);
|
|
36
|
+
e.target.textContent = "Copy";
|
|
37
|
+
}
|
|
38
|
+
async download(e) {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
const textarea = this.element.querySelector("textarea");
|
|
41
|
+
if (!textarea) {
|
|
42
|
+
throw new Error("Couldn't find the textarea");
|
|
43
|
+
}
|
|
44
|
+
download(
|
|
45
|
+
textarea.value,
|
|
46
|
+
String(Date.now()) + ".json",
|
|
47
|
+
"application/json"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
async import(e) {
|
|
51
|
+
var _a;
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
const file_input = this.element.querySelector(
|
|
54
|
+
"input[type='file']"
|
|
55
|
+
);
|
|
56
|
+
const file = (_a = file_input.files) == null ? void 0 : _a[0];
|
|
57
|
+
if (file) {
|
|
58
|
+
const text = await file.text();
|
|
59
|
+
const textarea = this.element.querySelector("textarea");
|
|
60
|
+
textarea.innerHTML = text.replaceAll("<", "<");
|
|
61
|
+
textarea.dispatchEvent(new Event("change"));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function sleep(n) {
|
|
66
|
+
return new Promise((resolve) => setTimeout(resolve, n));
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
ExportableTextarea as default
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=exportable-textarea.stimulus.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/exportable-textarea.stimulus.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport { Controller } from \"stimulus\";\n\nfunction download(data: string, filename: string, type: string) {\n\tconst file = new Blob([data], { type: type });\n\tconst a = document.createElement(\"a\"),\n\t\turl = URL.createObjectURL(file);\n\ta.href = url;\n\ta.download = filename;\n\tdocument.body.appendChild(a);\n\ta.click();\n\tsetTimeout(function () {\n\t\tdocument.body.removeChild(a);\n\t\twindow.URL.revokeObjectURL(url);\n\t}, 0);\n}\n\nexport default class ExportableTextarea extends Controller<HTMLDetailsElement> {\n\tconnect() {\n\t\tconsole.log(\"exportable\", this.element);\n\t\tthis.element.removeAttribute(\"open\");\n\t\tthis.element.addEventListener(\n\t\t\t\"turbo:before-morph-attribute\",\n\t\t\t(event: CustomEvent<{ attributeName: string }>) => {\n\t\t\t\tif (\n\t\t\t\t\tevent.target == this.element &&\n\t\t\t\t\tevent.detail.attributeName == \"open\"\n\t\t\t\t) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\tasync copy(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tconst textarea = this.element.querySelector(\"textarea\");\n\t\tif (!textarea) {\n\t\t\tthrow new Error(\"Couldn't find the textarea\");\n\t\t}\n\t\tawait navigator.clipboard.writeText(textarea.value);\n\t\t(e.target as HTMLButtonElement).textContent = \"Copied\";\n\t\tawait sleep(1000);\n\t\t(e.target as HTMLButtonElement).textContent = \"Copy\";\n\t}\n\n\tasync download(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tconst textarea = this.element.querySelector(\"textarea\");\n\t\tif (!textarea) {\n\t\t\tthrow new Error(\"Couldn't find the textarea\");\n\t\t}\n\t\tdownload(\n\t\t\ttextarea.value,\n\t\t\tString(Date.now()) + \".json\",\n\t\t\t\"application/json\"\n\t\t);\n\t}\n\n\tasync import(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tconst file_input = this.element.querySelector(\n\t\t\t\"input[type='file']\"\n\t\t) as HTMLInputElement;\n\t\tconst file = file_input.files?.[0];\n\t\tif (file) {\n\t\t\tconst text = await file.text();\n\t\t\tconst textarea = this.element.querySelector(\"textarea\");\n\t\t\ttextarea!.innerHTML = text.replaceAll(\"<\", \"<\");\n\t\t\ttextarea!.dispatchEvent(new Event(\"change\"));\n\t\t}\n\t}\n}\n\nfunction sleep(n: number) {\n\treturn new Promise((resolve) => setTimeout(resolve, n));\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,kBAAkB;AAE3B,SAAS,SAAS,MAAc,UAAkB,MAAc;AAC/D,QAAM,OAAO,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,KAAW,CAAC;AAC5C,QAAM,IAAI,SAAS,cAAc,GAAG,GACnC,MAAM,IAAI,gBAAgB,IAAI;AAC/B,IAAE,OAAO;AACT,IAAE,WAAW;AACb,WAAS,KAAK,YAAY,CAAC;AAC3B,IAAE,MAAM;AACR,aAAW,WAAY;AACtB,aAAS,KAAK,YAAY,CAAC;AAC3B,WAAO,IAAI,gBAAgB,GAAG;AAAA,EAC/B,GAAG,CAAC;AACL;AAEA,MAAO,2BAAyC,WAA+B;AAAA,EAC9E,UAAU;AACT,YAAQ,IAAI,cAAc,KAAK,OAAO;AACtC,SAAK,QAAQ,gBAAgB,MAAM;AACnC,SAAK,QAAQ;AAAA,MACZ;AAAA,MACA,CAAC,UAAkD;AAClD,YACC,MAAM,UAAU,KAAK,WACrB,MAAM,OAAO,iBAAiB,QAC7B;AACD,gBAAM,eAAe;AAAA,QACtB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,KAAK,GAAe;AACzB,MAAE,eAAe;AACjB,UAAM,WAAW,KAAK,QAAQ,cAAc,UAAU;AACtD,QAAI,CAAC,UAAU;AACd,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC7C;AACA,UAAM,UAAU,UAAU,UAAU,SAAS,KAAK;AAClD,IAAC,EAAE,OAA6B,cAAc;AAC9C,UAAM,MAAM,GAAI;AAChB,IAAC,EAAE,OAA6B,cAAc;AAAA,EAC/C;AAAA,EAEA,MAAM,SAAS,GAAe;AAC7B,MAAE,eAAe;AACjB,UAAM,WAAW,KAAK,QAAQ,cAAc,UAAU;AACtD,QAAI,CAAC,UAAU;AACd,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC7C;AACA;AAAA,MACC,SAAS;AAAA,MACT,OAAO,KAAK,IAAI,CAAC,IAAI;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,OAAO,GAAe;AA3D7B;AA4DE,MAAE,eAAe;AACjB,UAAM,aAAa,KAAK,QAAQ;AAAA,MAC/B;AAAA,IACD;AACA,UAAM,QAAO,gBAAW,UAAX,mBAAmB;AAChC,QAAI,MAAM;AACT,YAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,YAAM,WAAW,KAAK,QAAQ,cAAc,UAAU;AACtD,eAAU,YAAY,KAAK,WAAW,KAAK,MAAM;AACjD,eAAU,cAAc,IAAI,MAAM,QAAQ,CAAC;AAAA,IAC5C;AAAA,EACD;AACD;AAEA,SAAS,MAAM,GAAW;AACzB,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,CAAC,CAAC;AACvD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Controller } from "stimulus";
|
|
2
|
+
class InputImagePreview extends Controller {
|
|
3
|
+
handleChange() {
|
|
4
|
+
var _a, _b, _c, _d;
|
|
5
|
+
let img = this.element.querySelector("img");
|
|
6
|
+
if (!img) {
|
|
7
|
+
img = document.createElement("img");
|
|
8
|
+
img.setAttribute("style", "height: 40px; width: 40px");
|
|
9
|
+
(_a = this.element.querySelector(".image-preview-container")) == null ? void 0 : _a.appendChild(img);
|
|
10
|
+
}
|
|
11
|
+
window.URL.revokeObjectURL(img.src);
|
|
12
|
+
const file = (_c = (_b = this.element.querySelector("input")) == null ? void 0 : _b.files) == null ? void 0 : _c[0];
|
|
13
|
+
if (!file) {
|
|
14
|
+
console.warn("No file");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const new_url = window.URL.createObjectURL(file);
|
|
18
|
+
img.src = new_url;
|
|
19
|
+
img.parentNode;
|
|
20
|
+
(_d = img.parentElement) == null ? void 0 : _d.querySelectorAll("source").forEach((e) => {
|
|
21
|
+
var _a2;
|
|
22
|
+
return (_a2 = e.parentNode) == null ? void 0 : _a2.removeChild(e);
|
|
23
|
+
});
|
|
24
|
+
img.style.aspectRatio = "1";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
InputImagePreview as default
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=input-image-preview.stimulus.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/input-image-preview.stimulus.ts"],
|
|
4
|
+
"sourcesContent": ["import { Controller } from \"stimulus\";\n\nexport default class InputImagePreview extends Controller {\n\tid: string;\n\n\thandleChange() {\n\t\tlet img = this.element.querySelector(\"img\");\n\t\tif (!img) {\n\t\t\timg = document.createElement(\"img\");\n\t\t\timg.setAttribute(\"style\", \"height: 40px; width: 40px\");\n\t\t\tthis.element\n\t\t\t\t.querySelector(\".image-preview-container\")\n\t\t\t\t?.appendChild(img);\n\t\t}\n\t\twindow.URL.revokeObjectURL(img.src);\n\t\tconst file = this.element.querySelector(\"input\")?.files?.[0];\n\t\tif (!file) {\n\t\t\tconsole.warn(\"No file\");\n\t\t\treturn;\n\t\t}\n\t\tconst new_url = window.URL.createObjectURL(file);\n\t\timg.src = new_url;\n\t\timg.parentNode;\n\t\timg.parentElement\n\t\t\t?.querySelectorAll(\"source\")\n\t\t\t.forEach((e) => e.parentNode?.removeChild(e));\n\t\timg.style.aspectRatio = \"1\";\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAE3B,MAAO,0BAAwC,WAAW;AAAA,EAGzD,eAAe;AALhB;AAME,QAAI,MAAM,KAAK,QAAQ,cAAc,KAAK;AAC1C,QAAI,CAAC,KAAK;AACT,YAAM,SAAS,cAAc,KAAK;AAClC,UAAI,aAAa,SAAS,2BAA2B;AACrD,iBAAK,QACH,cAAc,0BAA0B,MAD1C,mBAEG,YAAY;AAAA,IAChB;AACA,WAAO,IAAI,gBAAgB,IAAI,GAAG;AAClC,UAAM,QAAO,gBAAK,QAAQ,cAAc,OAAO,MAAlC,mBAAqC,UAArC,mBAA6C;AAC1D,QAAI,CAAC,MAAM;AACV,cAAQ,KAAK,SAAS;AACtB;AAAA,IACD;AACA,UAAM,UAAU,OAAO,IAAI,gBAAgB,IAAI;AAC/C,QAAI,MAAM;AACV,QAAI;AACJ,cAAI,kBAAJ,mBACG,iBAAiB,UAClB,QAAQ,CAAC,MAAG;AAzBhB,UAAAA;AAyBmB,cAAAA,MAAA,EAAE,eAAF,gBAAAA,IAAc,YAAY;AAAA;AAC3C,QAAI,MAAM,cAAc;AAAA,EACzB;AACD;",
|
|
6
|
+
"names": ["_a"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { printArgPath } from "./print-arg-path.js";
|
|
2
|
+
function ComponentInputEnum({
|
|
3
|
+
arg_path,
|
|
4
|
+
arg,
|
|
5
|
+
value,
|
|
6
|
+
onchange
|
|
7
|
+
}) {
|
|
8
|
+
return `<div id=${`component-input-enum-${arg_path.join("-")}`}>
|
|
9
|
+
<label>
|
|
10
|
+
${arg_path.at(-1) || ""}
|
|
11
|
+
<select
|
|
12
|
+
name="${`$${printArgPath(arg_path)}`}"
|
|
13
|
+
onchange="${onchange || ""}"
|
|
14
|
+
>
|
|
15
|
+
${arg.values.map(
|
|
16
|
+
(v) => `<option
|
|
17
|
+
value="${v}"
|
|
18
|
+
${value == v ? "selected" : ""}
|
|
19
|
+
>
|
|
20
|
+
${v}
|
|
21
|
+
</option>`
|
|
22
|
+
).join("")}
|
|
23
|
+
</select>
|
|
24
|
+
</label>
|
|
25
|
+
</div>`;
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
ComponentInputEnum
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=component-input-enum.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/inputs/component-input-enum.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Enum } from \"@sealcode/jdd\";\nimport { printArgPath } from \"./print-arg-path.js\";\n\nexport function ComponentInputEnum<State, S extends string, T extends Enum<S>>({\n\targ_path,\n\targ,\n\tvalue,\n\tonchange,\n}: {\n\tstate: State;\n\targ_path: string[];\n\targ: T;\n\tvalue: string;\n\tonchange?: string;\n}) {\n\treturn /* HTML */ `<div id=${`component-input-enum-${arg_path.join(\"-\")}`}>\n\t\t<label>\n\t\t\t${arg_path.at(-1) || \"\"}\n\t\t\t<select\n\t\t\t\tname=\"${`$${printArgPath(arg_path)}`}\"\n\t\t\t\tonchange=\"${onchange || \"\"}\"\n\t\t\t>\n\t\t\t\t${arg.values\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(v: S) => /* HTML */ `<option\n\t\t\t\t\t\t\tvalue=\"${v}\"\n\t\t\t\t\t\t\t${value == v ? \"selected\" : \"\"}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t${v}\n\t\t\t\t\t\t</option>`\n\t\t\t\t\t)\n\t\t\t\t\t.join(\"\")}\n\t\t\t</select>\n\t\t</label>\n\t</div>`;\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAEtB,SAAS,mBAA+D;AAAA,EAC9E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,SAAkB,WAAW,wBAAwB,SAAS,KAAK,GAAG;AAAA;AAAA,KAElE,SAAS,GAAG,EAAE,KAAK;AAAA;AAAA,YAEZ,IAAI,aAAa,QAAQ;AAAA,gBACrB,YAAY;AAAA;AAAA,MAEtB,IAAI,OACJ;AAAA,IACA,CAAC,MAAoB;AAAA,gBACX;AAAA,SACP,SAAS,IAAI,aAAa;AAAA;AAAA,SAE1B;AAAA;AAAA,EAEJ,EACC,KAAK,EAAE;AAAA;AAAA;AAAA;AAIb;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { tempstream } from "tempstream";
|
|
2
|
+
import { printArgPath } from "./print-arg-path.js";
|
|
3
|
+
function ComponentInputImage({
|
|
4
|
+
arg_path,
|
|
5
|
+
arg,
|
|
6
|
+
value,
|
|
7
|
+
ctx,
|
|
8
|
+
page,
|
|
9
|
+
state,
|
|
10
|
+
makeJDDContext
|
|
11
|
+
}) {
|
|
12
|
+
const jdd_context = makeJDDContext(ctx);
|
|
13
|
+
return tempstream`<div style="margin-bottom: 10px">
|
|
14
|
+
<label
|
|
15
|
+
style="display: flex; align-items: center; column-gap: 10px;"
|
|
16
|
+
data-controller="input-image-preview"
|
|
17
|
+
>
|
|
18
|
+
${arg_path.at(-1) || ""}
|
|
19
|
+
<div class="image-preview-container">
|
|
20
|
+
${value && jdd_context.render_image(value, {
|
|
21
|
+
container: {
|
|
22
|
+
width: 40,
|
|
23
|
+
height: 40,
|
|
24
|
+
objectFit: "cover"
|
|
25
|
+
},
|
|
26
|
+
crop: { width: 40, height: 40 },
|
|
27
|
+
style: "height: 40px; width: 40px;",
|
|
28
|
+
alt: ""
|
|
29
|
+
})}
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<input
|
|
33
|
+
type="file"
|
|
34
|
+
name="${`$${printArgPath(arg_path)}.new`}"
|
|
35
|
+
value=""
|
|
36
|
+
autocomplete="off"
|
|
37
|
+
data-action="change->input-image-preview#handleChange"
|
|
38
|
+
${arg.hasParent("list") ? "multiple" : ""}
|
|
39
|
+
/>
|
|
40
|
+
</label>
|
|
41
|
+
<div>
|
|
42
|
+
<input type="hidden" name="${`$${printArgPath(arg_path)}.old`}"
|
|
43
|
+
value={value?.token || ""} autocomplete="off" />
|
|
44
|
+
</div>
|
|
45
|
+
${page.makeActionButton(
|
|
46
|
+
state,
|
|
47
|
+
{
|
|
48
|
+
action: "remove_file",
|
|
49
|
+
label: "\u274C"
|
|
50
|
+
},
|
|
51
|
+
arg_path
|
|
52
|
+
)}
|
|
53
|
+
</div>`;
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
ComponentInputImage
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=component-input-image.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/inputs/component-input-image.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Context } from \"koa\";\nimport type { FilePointer } from \"@sealcode/file-manager\";\nimport type { Image, JDDContext } from \"@sealcode/jdd\";\nimport type { StatefulPage } from \"@sealcode/sealgen\";\nimport type { ComponentPreviewActions } from \"../component-preview-actions.js\";\nimport type { JDDPageState } from \"../jdd-page.js\";\nimport { tempstream } from \"tempstream\";\nimport { printArgPath } from \"./print-arg-path.js\";\n\nexport function ComponentInputImage<State extends JDDPageState>({\n\targ_path,\n\targ,\n\tvalue,\n\tctx,\n\tpage,\n\tstate,\n\tmakeJDDContext,\n}: {\n\tstate: State;\n\targ_path: string[];\n\targ: Image;\n\tvalue: FilePointer | null;\n\tpage: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;\n\tctx: Context;\n\tmakeJDDContext: (ctx: Context) => JDDContext;\n}): JSX.Element {\n\tconst jdd_context = makeJDDContext(ctx);\n\treturn tempstream/* HTML */ `<div style=\"margin-bottom: 10px\">\n\t\t<label\n\t\t\tstyle=\"display: flex; align-items: center; column-gap: 10px;\"\n\t\t\tdata-controller=\"input-image-preview\"\n\t\t>\n\t\t\t${arg_path.at(-1) || \"\"}\n\t\t\t<div class=\"image-preview-container\">\n\t\t\t\t${value &&\n\t\t\t\tjdd_context.render_image(value, {\n\t\t\t\t\tcontainer: {\n\t\t\t\t\t\twidth: 40,\n\t\t\t\t\t\theight: 40,\n\t\t\t\t\t\tobjectFit: \"cover\",\n\t\t\t\t\t},\n\t\t\t\t\tcrop: { width: 40, height: 40 },\n\t\t\t\t\tstyle: \"height: 40px; width: 40px;\",\n\t\t\t\t\talt: \"\",\n\t\t\t\t})}\n\t\t\t</div>\n\n\t\t\t<input\n\t\t\t\ttype=\"file\"\n\t\t\t\tname=\"${`$${printArgPath(arg_path)}.new`}\"\n\t\t\t\tvalue=\"\"\n\t\t\t\tautocomplete=\"off\"\n\t\t\t\tdata-action=\"change->input-image-preview#handleChange\"\n\t\t\t\t${arg.hasParent(\"list\") ? \"multiple\" : \"\"}\n\t\t\t/>\n\t\t</label>\n\t\t<div>\n\t\t\t<input type=\"hidden\" name=\"${`$${printArgPath(arg_path)}.old`}\"\n\t\t\tvalue={value?.token || \"\"} autocomplete=\"off\" />\n\t\t</div>\n\t\t${page.makeActionButton(\n\t\t\tstate,\n\t\t\t{\n\t\t\t\taction: \"remove_file\",\n\t\t\t\tlabel: \"\u274C\",\n\t\t\t},\n\t\t\targ_path\n\t\t)}\n\t</div>`;\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAEtB,SAAS,oBAAgD;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAQgB;AACf,QAAM,cAAc,eAAe,GAAG;AACtC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA,KAKH,SAAS,GAAG,EAAE,KAAK;AAAA;AAAA,MAElB,SACF,YAAY,aAAa,OAAO;AAAA,IAC/B,WAAW;AAAA,MACV,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,WAAW;AAAA,IACZ;AAAA,IACA,MAAM,EAAE,OAAO,IAAI,QAAQ,GAAG;AAAA,IAC9B,OAAO;AAAA,IACP,KAAK;AAAA,EACN,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,YAKO,IAAI,aAAa,QAAQ;AAAA;AAAA;AAAA;AAAA,MAI/B,IAAI,UAAU,MAAM,IAAI,aAAa;AAAA;AAAA;AAAA;AAAA,gCAIX,IAAI,aAAa,QAAQ;AAAA;AAAA;AAAA,IAGrD,KAAK;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ;AAAA,MACR,OAAO;AAAA,IACR;AAAA,IACA;AAAA,EACD;AAAA;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ComponentInput } from "./component-input.js";
|
|
2
|
+
import { tempstream } from "tempstream";
|
|
3
|
+
async function ComponentInputList({
|
|
4
|
+
state,
|
|
5
|
+
ctx,
|
|
6
|
+
arg_path,
|
|
7
|
+
arg,
|
|
8
|
+
value,
|
|
9
|
+
page,
|
|
10
|
+
makeJDDContext,
|
|
11
|
+
...rest
|
|
12
|
+
}) {
|
|
13
|
+
if (!value) {
|
|
14
|
+
value = [];
|
|
15
|
+
}
|
|
16
|
+
return tempstream`<fieldset
|
|
17
|
+
id="${`component-input-list-${arg_path.join("-")}`}"
|
|
18
|
+
>
|
|
19
|
+
<legend>${arg_path.at(-1)}</legend>
|
|
20
|
+
${value.map(
|
|
21
|
+
(value2, i, all_values) => tempstream`<div style="display: flex">
|
|
22
|
+
${ComponentInput({
|
|
23
|
+
...rest,
|
|
24
|
+
ctx,
|
|
25
|
+
state,
|
|
26
|
+
arg_path: [...arg_path, i.toString()],
|
|
27
|
+
arg: arg.item_type,
|
|
28
|
+
value: value2,
|
|
29
|
+
page,
|
|
30
|
+
makeJDDContext
|
|
31
|
+
})}
|
|
32
|
+
${page.makeActionButton(
|
|
33
|
+
state,
|
|
34
|
+
{
|
|
35
|
+
action: "move_array_item_down",
|
|
36
|
+
label: "\u2193",
|
|
37
|
+
disabled: i == all_values.length - 1
|
|
38
|
+
},
|
|
39
|
+
arg_path,
|
|
40
|
+
i
|
|
41
|
+
)}
|
|
42
|
+
${page.makeActionButton(
|
|
43
|
+
state,
|
|
44
|
+
{
|
|
45
|
+
action: "move_array_item_up",
|
|
46
|
+
label: "\u2191",
|
|
47
|
+
disabled: i == 0
|
|
48
|
+
},
|
|
49
|
+
arg_path,
|
|
50
|
+
i
|
|
51
|
+
)}
|
|
52
|
+
|
|
53
|
+
${page.makeActionButton(
|
|
54
|
+
state,
|
|
55
|
+
{ action: "remove_array_item", label: "\u274C" },
|
|
56
|
+
arg_path,
|
|
57
|
+
i
|
|
58
|
+
)}
|
|
59
|
+
</div>`
|
|
60
|
+
)}
|
|
61
|
+
${page.makeActionButton(
|
|
62
|
+
state,
|
|
63
|
+
{
|
|
64
|
+
action: "add_array_item",
|
|
65
|
+
label: "\u2795"
|
|
66
|
+
},
|
|
67
|
+
arg_path
|
|
68
|
+
)}
|
|
69
|
+
</fieldset>`;
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
ComponentInputList
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=component-input-list.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/inputs/component-input-list.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport type { Context } from \"koa\";\nimport type { ComponentArgument, JDDContext, List } from \"@sealcode/jdd\";\nimport type { JDDPageState } from \"../jdd-page.js\";\nimport type { StatefulPage } from \"@sealcode/sealgen\";\nimport { ComponentInput } from \"./component-input.js\";\nimport type { ComponentPreviewActions } from \"../component-preview-actions.js\";\nimport { tempstream } from \"tempstream\";\n\nexport async function ComponentInputList<\n\tState extends JDDPageState,\n\tT extends ComponentArgument<unknown>\n>({\n\tstate,\n\tctx,\n\targ_path,\n\targ,\n\tvalue,\n\tpage,\n\tmakeJDDContext,\n\t...rest\n}: {\n\tstate: State;\n\tctx: Context;\n\targ_path: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\targ: List<T, any>;\n\tvalue: T[];\n\tpage: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;\n\tmakeJDDContext: (ctx: Context) => JDDContext;\n\tmakeAssetURL: (asset: string) => string;\n}): Promise<string> {\n\tif (!value) {\n\t\tvalue = [];\n\t}\n\treturn tempstream/* HTML */ `<fieldset\n\t\tid=\"${`component-input-list-${arg_path.join(\"-\")}`}\"\n\t>\n\t\t<legend>${arg_path.at(-1)!}</legend>\n\t\t${value.map(\n\t\t\t(value, i, all_values) =>\n\t\t\t\ttempstream`<div style=\"display: flex\">\n\t\t\t\t\t${ComponentInput({\n\t\t\t\t\t\t...rest,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\targ_path: [...arg_path, i.toString()],\n\t\t\t\t\t\targ: arg.item_type,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpage,\n\t\t\t\t\t\tmakeJDDContext,\n\t\t\t\t\t})}\n\t\t\t\t\t${page.makeActionButton(\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taction: \"move_array_item_down\",\n\t\t\t\t\t\t\tlabel: \"\u2193\",\n\t\t\t\t\t\t\tdisabled: i == all_values.length - 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\targ_path,\n\t\t\t\t\t\ti\n\t\t\t\t\t)}\n\t\t\t\t\t${page.makeActionButton(\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taction: \"move_array_item_up\",\n\t\t\t\t\t\t\tlabel: \"\u2191\",\n\t\t\t\t\t\t\tdisabled: i == 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t\targ_path,\n\t\t\t\t\t\ti\n\t\t\t\t\t)}\n\n\t\t\t\t\t${page.makeActionButton(\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\t{ action: \"remove_array_item\", label: \"\u274C\" },\n\t\t\t\t\t\targ_path,\n\t\t\t\t\t\ti\n\t\t\t\t\t)}\n\t\t\t\t</div>`\n\t\t)}\n\t\t${page.makeActionButton(\n\t\t\tstate,\n\t\t\t{\n\t\t\t\taction: \"add_array_item\",\n\t\t\t\tlabel: \"\u2795\",\n\t\t\t},\n\t\t\targ_path\n\t\t)}\n\t</fieldset>`;\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB;AAE3B,eAAsB,mBAGpB;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,KACG;AACJ,GAUoB;AACnB,MAAI,CAAC,OAAO;AACX,YAAQ,CAAC;AAAA,EACV;AACA,SAAO;AAAA,QACA,wBAAwB,SAAS,KAAK,GAAG;AAAA;AAAA,YAErC,SAAS,GAAG,EAAE;AAAA,IACtB,MAAM;AAAA,IACP,CAACA,QAAO,GAAG,eACV;AAAA,OACG,eAAe;AAAA,MAChB,GAAG;AAAA,MACH;AAAA,MACA;AAAA,MACA,UAAU,CAAC,GAAG,UAAU,EAAE,SAAS,CAAC;AAAA,MACpC,KAAK,IAAI;AAAA,MACT,OAAAA;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAC;AAAA,OACC,KAAK;AAAA,MACN;AAAA,MACA;AAAA,QACC,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,UAAU,KAAK,WAAW,SAAS;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,OACE,KAAK;AAAA,MACN;AAAA,MACA;AAAA,QACC,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,UAAU,KAAK;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA;AAAA,OAEE,KAAK;AAAA,MACN;AAAA,MACA,EAAE,QAAQ,qBAAqB,OAAO,SAAI;AAAA,MAC1C;AAAA,MACA;AAAA,IACD;AAAA;AAAA,EAEH;AAAA,IACE,KAAK;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ;AAAA,MACR,OAAO;AAAA,IACR;AAAA,IACA;AAAA,EACD;AAAA;AAEF;",
|
|
6
|
+
"names": ["value"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { printArgPath } from "./print-arg-path.js";
|
|
2
|
+
async function ComponentInputSingleReference({
|
|
3
|
+
ctx,
|
|
4
|
+
arg_path,
|
|
5
|
+
arg,
|
|
6
|
+
value,
|
|
7
|
+
onchange,
|
|
8
|
+
makeJDDContext
|
|
9
|
+
}) {
|
|
10
|
+
const values = await arg.getValues(makeJDDContext(ctx));
|
|
11
|
+
const ret = `<div>
|
|
12
|
+
<label>
|
|
13
|
+
${arg_path.at(-1) || ""}
|
|
14
|
+
<select name="${`$${printArgPath(arg_path)}`}" onchange="${onchange}">
|
|
15
|
+
${values.sort((v1, v2) => v1.label > v2.label ? 1 : -1).map(
|
|
16
|
+
(v) => `<option
|
|
17
|
+
value="${v.value}"
|
|
18
|
+
${value == v.value ? "selected" : ""}
|
|
19
|
+
>
|
|
20
|
+
${v.label}
|
|
21
|
+
</option>`
|
|
22
|
+
).join("")}
|
|
23
|
+
</select>
|
|
24
|
+
</label>
|
|
25
|
+
</div>`;
|
|
26
|
+
return ret;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
ComponentInputSingleReference
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=component-input-single-reference.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/inputs/component-input-single-reference.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Context } from \"koa\";\nimport type { JDDContext, SingleReference } from \"@sealcode/jdd\";\nimport { printArgPath } from \"./print-arg-path.js\";\n\nexport async function ComponentInputSingleReference<\n\tState,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tT extends SingleReference<any>\n>({\n\tctx,\n\targ_path,\n\targ,\n\tvalue,\n\tonchange,\n\tmakeJDDContext,\n}: {\n\tctx: Context;\n\tstate: State;\n\targ_path: string[];\n\targ: T;\n\tvalue: string;\n\tonchange?: string;\n\tmakeJDDContext: (ctx: Context) => JDDContext;\n}): Promise<string> {\n\tconst values = await arg.getValues(makeJDDContext(ctx));\n\tconst ret = `<div>\n\t\t\t<label>\n\t\t\t\t${arg_path.at(-1) || \"\"}\n\t\t\t\t<select name=\"${`$${printArgPath(arg_path)}`}\" onchange=\"${onchange}\">\n\t\t\t\t\t${values\n\t\t\t\t\t\t.sort((v1, v2) => (v1.label > v2.label ? 1 : -1))\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(v) => /* HTML */ `<option\n\t\t\t\t\t\t\t\tvalue=\"${v.value}\"\n\t\t\t\t\t\t\t\t${value == v.value ? \"selected\" : \"\"}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t${v.label}\n\t\t\t\t\t\t\t</option>`\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"\")}\n\t\t\t\t</select>\n\t\t\t</label>\n\t\t</div>`;\n\treturn ret;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,oBAAoB;AAE7B,eAAsB,8BAIpB;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAQoB;AACnB,QAAM,SAAS,MAAM,IAAI,UAAU,eAAe,GAAG,CAAC;AACtD,QAAM,MAAM;AAAA;AAAA,MAEP,SAAS,GAAG,EAAE,KAAK;AAAA,oBACL,IAAI,aAAa,QAAQ,kBAAkB;AAAA,OACxD,OACA,KAAK,CAAC,IAAI,OAAQ,GAAG,QAAQ,GAAG,QAAQ,IAAI,EAAG,EAC/C;AAAA,IACA,CAAC,MAAiB;AAAA,iBACR,EAAE;AAAA,UACT,SAAS,EAAE,QAAQ,aAAa;AAAA;AAAA,UAEhC,EAAE;AAAA;AAAA,EAEN,EACC,KAAK,EAAE;AAAA;AAAA;AAAA;AAIb,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComponentInput } from "./component-input.js";
|
|
2
|
+
async function ComponentInputStructured({
|
|
3
|
+
state,
|
|
4
|
+
ctx,
|
|
5
|
+
arg_path,
|
|
6
|
+
arg,
|
|
7
|
+
value,
|
|
8
|
+
page,
|
|
9
|
+
...rest
|
|
10
|
+
}) {
|
|
11
|
+
return `<fieldset
|
|
12
|
+
id="${`component-input-structured-${arg_path.join("-")}`}"
|
|
13
|
+
>
|
|
14
|
+
<legend>{arg_path.at(-1)}</legend>
|
|
15
|
+
${(await Promise.all(
|
|
16
|
+
Object.entries(arg.structure).map(async ([arg_name, arg2]) => {
|
|
17
|
+
const ret = `<div>
|
|
18
|
+
${await ComponentInput({
|
|
19
|
+
ctx,
|
|
20
|
+
state,
|
|
21
|
+
arg_path: [...arg_path, arg_name],
|
|
22
|
+
arg: arg2,
|
|
23
|
+
value: value[arg_name],
|
|
24
|
+
page,
|
|
25
|
+
...rest
|
|
26
|
+
})}
|
|
27
|
+
</div>`;
|
|
28
|
+
return ret;
|
|
29
|
+
})
|
|
30
|
+
)).join("")}
|
|
31
|
+
</fieldset>`;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
ComponentInputStructured
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=component-input-structured.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/inputs/component-input-structured.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Context } from \"koa\";\nimport type { ComponentArgument, JDDContext, Structured } from \"@sealcode/jdd\";\nimport type { StatefulPage } from \"@sealcode/sealgen\";\nimport { ComponentInput } from \"./component-input.js\";\nimport type { JDDPageState } from \"../jdd-page.js\";\nimport type { ComponentPreviewActions } from \"../component-preview-actions.js\";\n\nexport async function ComponentInputStructured<\n\tT extends Structured<Record<string, ComponentArgument<unknown>>>\n>({\n\tstate,\n\tctx,\n\targ_path,\n\targ,\n\tvalue,\n\tpage,\n\t...rest\n}: {\n\tstate: JDDPageState;\n\tctx: Context;\n\targ_path: string[];\n\targ: T;\n\tvalue: Record<string, unknown>;\n\tpage: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;\n\tmakeJDDContext: (ctx: Context) => JDDContext;\n\tmakeAssetURL: (asset: string) => string;\n}) {\n\treturn /* HTML */ `<fieldset\n\t\tid=\"${`component-input-structured-${arg_path.join(\"-\")}`}\"\n\t>\n\t\t<legend>{arg_path.at(-1)}</legend>\n\t\t${(\n\t\t\tawait Promise.all(\n\t\t\t\tObject.entries(arg.structure).map(async ([arg_name, arg]) => {\n\t\t\t\t\tconst ret = `<div>\n\t\t\t\t\t\t${await ComponentInput({\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\tstate,\n\t\t\t\t\t\t\targ_path: [...arg_path, arg_name],\n\t\t\t\t\t\t\targ,\n\t\t\t\t\t\t\tvalue: value[arg_name],\n\t\t\t\t\t\t\tpage,\n\t\t\t\t\t\t\t...rest,\n\t\t\t\t\t\t})}\n\t\t\t\t\t</div>`;\n\t\t\t\t\treturn ret;\n\t\t\t\t})\n\t\t\t)\n\t\t).join(\"\")}\n\t</fieldset>`;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,sBAAsB;AAI/B,eAAsB,yBAEpB;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,KACG;AACJ,GASG;AACF,SAAkB;AAAA,QACX,8BAA8B,SAAS,KAAK,GAAG;AAAA;AAAA;AAAA,KAIpD,MAAM,QAAQ;AAAA,IACb,OAAO,QAAQ,IAAI,SAAS,EAAE,IAAI,OAAO,CAAC,UAAUA,IAAG,MAAM;AAC5D,YAAM,MAAM;AAAA,QACT,MAAM,eAAe;AAAA,QACtB;AAAA,QACA;AAAA,QACA,UAAU,CAAC,GAAG,UAAU,QAAQ;AAAA,QAChC,KAAAA;AAAA,QACA,OAAO,MAAM;AAAA,QACb;AAAA,QACA,GAAG;AAAA,MACJ,CAAC;AAAA;AAEF,aAAO;AAAA,IACR,CAAC;AAAA,EACF,GACC,KAAK,EAAE;AAAA;AAEX;",
|
|
6
|
+
"names": ["arg"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Markdown } from "@sealcode/jdd";
|
|
2
|
+
import { isTableHeader } from "@sealcode/jdd";
|
|
3
|
+
import { tempstream } from "tempstream";
|
|
4
|
+
import { ComponentInput } from "./component-input.js";
|
|
5
|
+
async function ComponentInputTable({
|
|
6
|
+
state,
|
|
7
|
+
arg_path,
|
|
8
|
+
ctx,
|
|
9
|
+
arg,
|
|
10
|
+
value,
|
|
11
|
+
page,
|
|
12
|
+
makeJDDContext,
|
|
13
|
+
makeAssetURL
|
|
14
|
+
}) {
|
|
15
|
+
if (!value) {
|
|
16
|
+
value = await arg.getEmptyValue(makeJDDContext(ctx));
|
|
17
|
+
}
|
|
18
|
+
const show_paste = arg.cell_type instanceof Markdown && arg.header_type instanceof Markdown;
|
|
19
|
+
return tempstream`<fieldset>
|
|
20
|
+
<legend>${arg_path.at(-1)}</legend>
|
|
21
|
+
<div>
|
|
22
|
+
${show_paste ? `<input
|
|
23
|
+
type="button"
|
|
24
|
+
value="paste"
|
|
25
|
+
placeholder="paste table here"
|
|
26
|
+
data-jdd-table-paste-argpath-value="${arg_path.join(
|
|
27
|
+
"."
|
|
28
|
+
)}"
|
|
29
|
+
data-controller="jdd-table-paste"
|
|
30
|
+
/>` : ""}
|
|
31
|
+
<table
|
|
32
|
+
class="jdd-component-input--table"
|
|
33
|
+
style="position: relative; /* necessary for sticky th*/"
|
|
34
|
+
>
|
|
35
|
+
<tbody>
|
|
36
|
+
<tr>
|
|
37
|
+
<td></td>
|
|
38
|
+
${[...Array(arg.getColumnsCount(value)).keys()].map(
|
|
39
|
+
(column_index) => `<th
|
|
40
|
+
class="sticky sticky--top subdued"
|
|
41
|
+
>
|
|
42
|
+
${page.makeActionButton(
|
|
43
|
+
state,
|
|
44
|
+
{
|
|
45
|
+
action: "remove_table_column",
|
|
46
|
+
label: "Remove column",
|
|
47
|
+
content: `<img
|
|
48
|
+
width="20"
|
|
49
|
+
height="20"
|
|
50
|
+
src="${makeAssetURL(
|
|
51
|
+
"icons/table-delete-column.svg"
|
|
52
|
+
)}"
|
|
53
|
+
/>`
|
|
54
|
+
},
|
|
55
|
+
arg_path,
|
|
56
|
+
column_index
|
|
57
|
+
)}
|
|
58
|
+
${column_index >= arg.getColumnsCount(value) - 1 ? "" : page.makeActionButton(
|
|
59
|
+
state,
|
|
60
|
+
{
|
|
61
|
+
action: "move_table_column_right",
|
|
62
|
+
label: "Move column to the right",
|
|
63
|
+
content: `<img
|
|
64
|
+
width="20"
|
|
65
|
+
height="20"
|
|
66
|
+
src="${makeAssetURL(
|
|
67
|
+
"icons/table-move-column-right.svg"
|
|
68
|
+
)}"
|
|
69
|
+
/>`
|
|
70
|
+
},
|
|
71
|
+
arg_path,
|
|
72
|
+
column_index
|
|
73
|
+
)}
|
|
74
|
+
</th>`
|
|
75
|
+
).join("")}
|
|
76
|
+
</tr>
|
|
77
|
+
${value.rows.map(
|
|
78
|
+
(row, row_index) => tempstream`<tr>
|
|
79
|
+
<td class="sticky sticky--left subdued">
|
|
80
|
+
<div
|
|
81
|
+
style="display: flex; flex-flow: column; row-gap: 5px;"
|
|
82
|
+
>
|
|
83
|
+
${page.makeActionButton(
|
|
84
|
+
state,
|
|
85
|
+
{
|
|
86
|
+
action: "remove_table_row",
|
|
87
|
+
label: "Remove row",
|
|
88
|
+
content: `<img
|
|
89
|
+
width="20"
|
|
90
|
+
height="20"
|
|
91
|
+
src="${makeAssetURL(
|
|
92
|
+
"icons/table-delete-row.svg"
|
|
93
|
+
)}"
|
|
94
|
+
/>`
|
|
95
|
+
},
|
|
96
|
+
arg_path,
|
|
97
|
+
row_index
|
|
98
|
+
)}
|
|
99
|
+
${page.makeActionButton(
|
|
100
|
+
state,
|
|
101
|
+
{
|
|
102
|
+
action: "move_table_row_down",
|
|
103
|
+
label: "Move this row down",
|
|
104
|
+
content: `<img
|
|
105
|
+
width="20"
|
|
106
|
+
height="20"
|
|
107
|
+
src="${makeAssetURL(
|
|
108
|
+
"icons/table-move-row-down.svg"
|
|
109
|
+
)}"
|
|
110
|
+
/>`
|
|
111
|
+
},
|
|
112
|
+
arg_path,
|
|
113
|
+
row_index
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
</td>
|
|
117
|
+
${isTableHeader(row) ? tempstream`<th
|
|
118
|
+
colspan="${arg.getColumnsCount(value).toString()}"
|
|
119
|
+
>
|
|
120
|
+
${ComponentInput({
|
|
121
|
+
state,
|
|
122
|
+
ctx,
|
|
123
|
+
arg_path: [
|
|
124
|
+
...arg_path,
|
|
125
|
+
"rows",
|
|
126
|
+
row_index.toString(),
|
|
127
|
+
"header_content"
|
|
128
|
+
],
|
|
129
|
+
arg: arg.header_type,
|
|
130
|
+
value: row.header_content,
|
|
131
|
+
page,
|
|
132
|
+
makeJDDContext,
|
|
133
|
+
makeAssetURL
|
|
134
|
+
})}
|
|
135
|
+
</th>` : row.cells.map(
|
|
136
|
+
(cell, cell_index) => tempstream`<td>
|
|
137
|
+
${ComponentInput({
|
|
138
|
+
ctx,
|
|
139
|
+
state,
|
|
140
|
+
arg_path: [
|
|
141
|
+
...arg_path,
|
|
142
|
+
"rows",
|
|
143
|
+
row_index.toString(),
|
|
144
|
+
"cells",
|
|
145
|
+
cell_index.toString()
|
|
146
|
+
],
|
|
147
|
+
arg: arg.cell_type,
|
|
148
|
+
value: cell,
|
|
149
|
+
page,
|
|
150
|
+
makeJDDContext,
|
|
151
|
+
makeAssetURL
|
|
152
|
+
})}
|
|
153
|
+
</td>`
|
|
154
|
+
)}
|
|
155
|
+
${row_index == 0 ? `<td
|
|
156
|
+
class="subdued"
|
|
157
|
+
rowspan="${value.rows.length.toString()}"
|
|
158
|
+
>
|
|
159
|
+
${page.makeActionButton(
|
|
160
|
+
state,
|
|
161
|
+
{
|
|
162
|
+
action: "add_table_column",
|
|
163
|
+
label: "Add column",
|
|
164
|
+
content: `<img
|
|
165
|
+
width="20"
|
|
166
|
+
height="20"
|
|
167
|
+
src="${makeAssetURL(
|
|
168
|
+
"icons/table-add-column-right.svg"
|
|
169
|
+
)}"
|
|
170
|
+
/>`
|
|
171
|
+
},
|
|
172
|
+
arg_path
|
|
173
|
+
)}
|
|
174
|
+
</td>` : ""}
|
|
175
|
+
</tr>`
|
|
176
|
+
)}
|
|
177
|
+
<tr>
|
|
178
|
+
<td
|
|
179
|
+
class="subdued"
|
|
180
|
+
colspan="{(arg.getColumnsCount(value)"
|
|
181
|
+
+
|
|
182
|
+
1).toString()}
|
|
183
|
+
>
|
|
184
|
+
${page.makeActionButton(
|
|
185
|
+
state,
|
|
186
|
+
{
|
|
187
|
+
action: "add_table_row",
|
|
188
|
+
label: "Add table row",
|
|
189
|
+
content: `<img
|
|
190
|
+
width="20"
|
|
191
|
+
height="20"
|
|
192
|
+
src="${makeAssetURL(
|
|
193
|
+
"icons/table-add-row-below.svg"
|
|
194
|
+
)}"
|
|
195
|
+
/>`
|
|
196
|
+
},
|
|
197
|
+
arg_path,
|
|
198
|
+
arg.getColumnsCount(value),
|
|
199
|
+
void 0
|
|
200
|
+
)}
|
|
201
|
+
${page.makeActionButton(
|
|
202
|
+
state,
|
|
203
|
+
{
|
|
204
|
+
action: "add_table_row",
|
|
205
|
+
label: "Add table header",
|
|
206
|
+
content: `<img
|
|
207
|
+
width="20"
|
|
208
|
+
height="20"
|
|
209
|
+
src="${makeAssetURL(
|
|
210
|
+
"icons/table-add-column-header-below.svg"
|
|
211
|
+
)}"
|
|
212
|
+
/>`
|
|
213
|
+
},
|
|
214
|
+
arg_path,
|
|
215
|
+
arg.getColumnsCount(value),
|
|
216
|
+
"header"
|
|
217
|
+
)}
|
|
218
|
+
</td>
|
|
219
|
+
</tr>
|
|
220
|
+
</tbody>
|
|
221
|
+
</table>
|
|
222
|
+
</div>
|
|
223
|
+
</fieldset>`;
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
ComponentInputTable
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=component-input-table.js.map
|