From f96f59bc5b53d729a5a00da1afc40f835c28724a Mon Sep 17 00:00:00 2001 From: Lyssieth Date: Sat, 6 Jan 2024 19:03:05 +0200 Subject: [PATCH] A theoretically working v3. --- README.md | 2 +- package.json | 8 +- pnpm-lock.yaml | 75 +++++++++++++ src/App.svelte | 12 +- src/app.scss | 13 +++ src/lib/Controls.svelte | 164 ++++++++++++++++++++++----- src/lib/EditButton.svelte | 12 ++ src/lib/EditableText.svelte | 41 +++++++ src/lib/ExportBlock.svelte | 14 ++- src/lib/ImportModal.svelte | 93 ++++++++++++++++ src/lib/PermissionModal.svelte | 109 ++++++++++++++++++ src/lib/Question.svelte | 30 ++++- src/lib/Questionnaire.svelte | 121 ++++++++++++++------ src/lib/Section.svelte | 58 +++++++++- src/lib/store.ts | 14 ++- src/lib/template.ts | 90 +++++++-------- src/lib/types/template.ts | 42 +++++++ src/lib/types/template.validator.ts | 165 ++++++++++++++++++++++++++++ todo.md | 2 - 19 files changed, 937 insertions(+), 128 deletions(-) create mode 100644 src/lib/EditButton.svelte create mode 100644 src/lib/EditableText.svelte create mode 100644 src/lib/ImportModal.svelte create mode 100644 src/lib/PermissionModal.svelte create mode 100644 src/lib/types/template.ts create mode 100644 src/lib/types/template.validator.ts diff --git a/README.md b/README.md index c3279e9..cdeb709 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The purpose of this website is to act as a questionnaire for worldbuilding purposes. -Version two of the experiment brings in templates and a more modular approach to the UI. +Version three of the experiment brings editing/saving/loading. ## Current State diff --git a/package.json b/package.json index 4cf7490..c8b4e7b 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^3.0.1", "@tsconfig/svelte": "^5.0.2", + "@types/object-inspect": "^1.8.4", "@typescript-eslint/eslint-plugin": "^6.17.0", "@typescript-eslint/parser": "^6.17.0", + "ajv": "^8.12.0", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.2", @@ -24,11 +26,15 @@ "sass": "^1.69.7", "svelte": "^4.2.8", "svelte-check": "^3.6.2", + "svelte-feather-icons": "^4.1.0", "tslib": "^2.6.2", "typescript": "^5.3.3", "vite": "^5.0.11" }, "dependencies": { - "docx": "^8.5.0" + "docx": "^8.5.0", + "feather-icons": "^4.29.1", + "hash-wasm": "^4.11.0", + "object-inspect": "^1.13.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5ea9c8e..bb1d84c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,15 @@ dependencies: docx: specifier: ^8.5.0 version: 8.5.0 + feather-icons: + specifier: ^4.29.1 + version: 4.29.1 + hash-wasm: + specifier: ^4.11.0 + version: 4.11.0 + object-inspect: + specifier: ^1.13.1 + version: 1.13.1 devDependencies: '@sveltejs/vite-plugin-svelte': @@ -16,12 +25,18 @@ devDependencies: '@tsconfig/svelte': specifier: ^5.0.2 version: 5.0.2 + '@types/object-inspect': + specifier: ^1.8.4 + version: 1.8.4 '@typescript-eslint/eslint-plugin': specifier: ^6.17.0 version: 6.17.0(@typescript-eslint/parser@6.17.0)(eslint@8.56.0)(typescript@5.3.3) '@typescript-eslint/parser': specifier: ^6.17.0 version: 6.17.0(eslint@8.56.0)(typescript@5.3.3) + ajv: + specifier: ^8.12.0 + version: 8.12.0 eslint: specifier: ^8.56.0 version: 8.56.0 @@ -49,6 +64,9 @@ devDependencies: svelte-check: specifier: ^3.6.2 version: 3.6.2(postcss@8.4.33)(sass@1.69.7)(svelte@4.2.8) + svelte-feather-icons: + specifier: ^4.1.0 + version: 4.1.0 tslib: specifier: ^2.6.2 version: 2.6.2 @@ -552,6 +570,10 @@ packages: undici-types: 5.26.5 dev: false + /@types/object-inspect@1.8.4: + resolution: {integrity: sha512-2yh72JxmDney1h7LQvkyO8p8FOmNMQXGs8HjuXS3SXvE/dLydLLjBqKCdHqcTUo66CQVHfn7yFR680bvi9jlVw==} + dev: true + /@types/pug@2.0.10: resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==} dev: true @@ -719,6 +741,15 @@ packages: uri-js: 4.4.1 dev: true + /ajv@8.12.0: + resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==} + dependencies: + fast-deep-equal: 3.1.3 + json-schema-traverse: 1.0.0 + require-from-string: 2.0.2 + uri-js: 4.4.1 + dev: true + /ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} @@ -821,6 +852,10 @@ packages: fsevents: 2.3.3 dev: true + /classnames@2.5.1: + resolution: {integrity: sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==} + dev: false + /code-red@1.0.4: resolution: {integrity: sha512-7qJWqItLA8/VPVlKJlFXU+NBlo/qyfs39aJcuMT/2ere32ZqvF5OSxgdM5xOfJJ7O429gg2HM47y8v9P+9wrNw==} dependencies: @@ -846,6 +881,11 @@ packages: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} dev: true + /core-js@3.35.0: + resolution: {integrity: sha512-ntakECeqg81KqMueeGJ79Q5ZgQNR+6eaE8sxGCx62zMbAIj65q+uYvatToew3m6eAGdU4gNZwpZ34NMe4GYswg==} + requiresBuild: true + dev: false + /core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} dev: false @@ -1169,6 +1209,13 @@ packages: reusify: 1.0.4 dev: true + /feather-icons@4.29.1: + resolution: {integrity: sha512-P1we61haGTds6lKWe6CCVPsNULb8tHr1y6S9gXEpU+lNR1Ja7GdV0A1l2hTNmzXv+0Stix/3YMWMAn7n1Qtd6A==} + dependencies: + classnames: 2.5.1 + core-js: 3.35.0 + dev: false + /file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -1273,6 +1320,10 @@ packages: engines: {node: '>=8'} dev: true + /hash-wasm@4.11.0: + resolution: {integrity: sha512-HVusNXlVqHe0fzIzdQOGolnFN6mX/fqcrSAOcTBXdvzrXVHwTz11vXeKRmkR5gTuwVpvHZEIyKoePDvuAR+XwQ==} + dev: false + /ignore@5.3.0: resolution: {integrity: sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==} engines: {node: '>= 4'} @@ -1367,6 +1418,10 @@ packages: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} dev: true + /json-schema-traverse@1.0.0: + resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} + dev: true + /json-stable-stringify-without-jsonify@1.0.1: resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} dev: true @@ -1519,6 +1574,10 @@ packages: engines: {node: '>=0.10.0'} dev: true + /object-inspect@1.13.1: + resolution: {integrity: sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==} + dev: false + /once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: @@ -1711,6 +1770,11 @@ packages: picomatch: 2.3.1 dev: true + /require-from-string@2.0.2: + resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} + engines: {node: '>=0.10.0'} + dev: true + /resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} @@ -1918,6 +1982,12 @@ packages: svelte: 4.2.8 dev: true + /svelte-feather-icons@4.1.0: + resolution: {integrity: sha512-fcTL4VzEN4BoccQJjKiui0b9DWEsmO6zGpI0tQTJbthRtNrYheoU487zyA1BD8rj9kj6jbKGmGVo7zbSdRvMvA==} + dependencies: + svelte: 3.59.2 + dev: true + /svelte-hmr@0.15.3(svelte@4.2.8): resolution: {integrity: sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==} engines: {node: ^12.20 || ^14.13.1 || >= 16} @@ -1976,6 +2046,11 @@ packages: typescript: 5.3.3 dev: true + /svelte@3.59.2: + resolution: {integrity: sha512-vzSyuGr3eEoAtT/A6bmajosJZIUWySzY2CzB3w2pgPvnkUjGqlDnsNnA0PMO+mMAhuyMul6C2uuZzY6ELSkzyA==} + engines: {node: '>= 8'} + dev: true + /svelte@4.2.8: resolution: {integrity: sha512-hU6dh1MPl8gh6klQZwK/n73GiAHiR95IkFsesLPbMeEZi36ydaXL/ZAb4g9sayT0MXzpxyZjR28yderJHxcmYA==} engines: {node: '>=16'} diff --git a/src/App.svelte b/src/App.svelte index e50e45b..048fd03 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,6 +1,8 @@
- - +
+ + + +
+ {#if $editMode} +
+ + + + + +
+ {/if}
diff --git a/src/lib/PermissionModal.svelte b/src/lib/PermissionModal.svelte new file mode 100644 index 0000000..81bd187 --- /dev/null +++ b/src/lib/PermissionModal.svelte @@ -0,0 +1,109 @@ + + + +
+

+ To save/load custom templates, this website requires the use of LocalStorage. This is a feature of your browser that allows websites to store data on + your computer. This data is only accessible by this website, and is not + shared with anyone else. +

+

+ However, if you do not want anything stored, simply say no. You will still + be able to edit, export, and import templates, but won't be able to save + them without saying yes. +

+

+ To my knowledge, this isn't a security issue, but I'm not an expert, and + you don't know what you don't know. +

+

+ Note that you will have to hit 'Save'/'Load' again, this is a limitation + of v3 of the experiment, and might not remain in the final version. +

+
+ + +
+
+
+ + diff --git a/src/lib/Question.svelte b/src/lib/Question.svelte index 58f94c4..d75dbf1 100644 --- a/src/lib/Question.svelte +++ b/src/lib/Question.svelte @@ -1,6 +1,8 @@ -{#if template == null} +

Note: the sections are collapsible :3

+{#if $editMode} +

+ When in edit mode, questions will not display the answer box, instead + displaying a selection box for their type and an editable text for their + placeholder. Clicking outside of, or hitting enter inside of, the text boxes + that appear will save the changes. +

+{/if} +{#if $current == null}

No template is currently selected. Please remain calm and select one:3

{:else} - {#key template} -

{template.name}

- {#if template.author} - - {#if template.author instanceof Object} -
- by {template.author.name} + +
+ {#if $current.author} + + {#if $current.author instanceof Object} +
+ by {$current.author.name} +
+ {:else} +
+ by +
+ {/if} + {/if} +

+ +

+
+ {#if $editMode} + + {/if} + {#if $current.sections.length > 0} + {#each $current.sections as section, i} +
+ {#if $editMode} + + {/if} +
+ {#if i !== $current.sections.length - 1} +
{/if} - {/if} -

- {template.description} + {/each} + {:else} +

+ There are no sections in this template. You can add more once I implement + this feature.

-
- {#if template.sections.length > 0} - {#each template.sections as section, i} -
- {#if i !== template.sections.length - 1} -
- {/if} - {/each} - {:else} -

- There are no sections in this template. You can add more once I - implement this feature. -

- {/if} - {/key} + {/if} {/if}