diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index a1045ebeb5..19e10261c6 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -5345,7 +5345,7 @@ packages: version: 0.0.0 '@rush-temp/survey-resources@file:projects/survey-resources.tgz': - resolution: {integrity: sha512-GcIw9MyT6uttWSxYSZOdu9Kln2eLlum64WfLRrHoA0/Z6zxXdlKn6IgZwRdwo2iQBbws9Vz3sfEvoa89XCm6dw==, tarball: file:projects/survey-resources.tgz} + resolution: {integrity: sha512-OKGMUZJzuG7+t/0yBujRPBsJPraZFObMn+gF0hOPlgUeBwmFhh5fUKhodNvqAQhmaikyUI8wqf1Zt8roq1fMUg==, tarball: file:projects/survey-resources.tgz} version: 0.0.0 '@rush-temp/survey@file:projects/survey.tgz': @@ -25234,6 +25234,7 @@ snapshots: eslint-plugin-n: 15.7.0(eslint@8.56.0) eslint-plugin-promise: 6.1.1(eslint@8.56.0) eslint-plugin-svelte: 2.35.1(eslint@8.56.0)(svelte@4.2.19)(ts-node@10.9.2(@types/node@20.11.19)(typescript@5.3.3)) + fast-equals: 5.2.2 jest: 29.7.0(@types/node@20.11.19)(ts-node@10.9.2(@types/node@20.11.19)(typescript@5.3.3)) prettier: 3.2.5 prettier-plugin-svelte: 3.2.2(prettier@3.2.5)(svelte@4.2.19) diff --git a/packages/ui/src/utils.ts b/packages/ui/src/utils.ts index 1d3c88fd81..f091f01a7a 100644 --- a/packages/ui/src/utils.ts +++ b/packages/ui/src/utils.ts @@ -302,6 +302,23 @@ export class ThrottledCaller { } } +/** + * @public + */ +export class DebouncedCaller { + timeout?: any + constructor (readonly delay: number = 50) {} + call (op: () => void): void { + if (this.timeout !== undefined) { + clearTimeout(this.timeout) + } + this.timeout = setTimeout(() => { + op() + this.timeout = undefined + }, this.delay) + } +} + export const testing = (localStorage.getItem('#platform.testing.enabled') ?? 'false') === 'true' export const rootBarExtensions = writable< diff --git a/plugins/survey-resources/package.json b/plugins/survey-resources/package.json index c98f64f489..76b4d1c342 100644 --- a/plugins/survey-resources/package.json +++ b/plugins/survey-resources/package.json @@ -46,6 +46,7 @@ "@hcengineering/view": "^0.6.13", "@hcengineering/view-resources": "^0.6.0", "@hcengineering/ui": "^0.6.15", - "svelte": "^4.2.19" + "svelte": "^4.2.19", + "fast-equals": "^5.2.2" } } diff --git a/plugins/survey-resources/src/components/EditPoll.svelte b/plugins/survey-resources/src/components/EditPoll.svelte index f225d162b9..1ac5aa18b2 100644 --- a/plugins/survey-resources/src/components/EditPoll.svelte +++ b/plugins/survey-resources/src/components/EditPoll.svelte @@ -15,12 +15,12 @@ // --> @@ -68,13 +66,13 @@ {/if} - {#each object.questions ?? [] as question, index} + {#each object.questions ?? [] as question, index (index)} {#if isQuestionValid(question)} handleQuestionChange(index, e.detail)} {question} /> {/if} diff --git a/plugins/survey-resources/src/components/EditPollPanel.svelte b/plugins/survey-resources/src/components/EditPollPanel.svelte index 7e41322e0a..29c76adef6 100644 --- a/plugins/survey-resources/src/components/EditPollPanel.svelte +++ b/plugins/survey-resources/src/components/EditPollPanel.svelte @@ -17,34 +17,55 @@ + {#if object}
- + { + handleChange(e.detail) + }} + />
{/if} diff --git a/plugins/survey-resources/src/components/EditQuestion.svelte b/plugins/survey-resources/src/components/EditQuestion.svelte index a4e1b35d90..9370aa4d64 100644 --- a/plugins/survey-resources/src/components/EditQuestion.svelte +++ b/plugins/survey-resources/src/components/EditQuestion.svelte @@ -15,8 +15,7 @@ // --> - + {/if} { - haveNameChanges = true + bind:value={inputName} + on:change={() => { + handleChange({ name: inputName }) }} - on:change={handleNameChange} /> {#if !isNewQuestion} {#if question.hasCustomOption && question.kind !== QuestionKind.STRING} @@ -423,18 +368,18 @@ {/if} {#if !isNewQuestion && question.kind !== QuestionKind.STRING} - {#each options as option, index (index)} + {#each inputOptions as option, index (index)}
{ - dragOver(ev, index) + onOptionDragOver(ev, index) }} on:dragleave={(ev) => { - dragLeave(ev, index) + onOptionDragLeave(ev, index) }} - on:drop={dragDrop} + on:drop={onOptionDrop} class:is-dragged={index === draggedIndex} class:dragged-over={draggedIndex !== undefined && draggedOverIndex === index && @@ -445,9 +390,9 @@ role="presentation" draggable={!readonly} on:dragstart={(ev) => { - dragStart(ev, index) + onOptionDragStart(ev, index) }} - on:dragend={dragEnd} + on:dragend={onOptionDragEnd} > { - await changeOption(index) + bind:value={inputOptions[index]} + on:change={() => { + changeOption(index) }} />
@@ -475,16 +420,20 @@ class="flex-row-center flex-gap-3 option" role="listitem" on:dragover={(ev) => { - dragOver(ev, options.length) + onOptionDragOver(ev, question.options?.length ?? 0) }} on:dragleave={(ev) => { - dragLeave(ev, options.length) + onOptionDragLeave(ev, question.options?.length ?? 0) }} - on:drop={dragDrop} - class:dragged-over={draggedOverIndex === options.length && draggedIndex !== options.length - 1} + on:drop={onOptionDrop} + class:dragged-over={draggedOverIndex === inputOptions.length && draggedIndex !== inputOptions.length - 1} > - + {/if} {/if} diff --git a/plugins/survey-resources/src/components/EditSurvey.svelte b/plugins/survey-resources/src/components/EditSurvey.svelte index 0a202f7a3c..fce06aa6d9 100644 --- a/plugins/survey-resources/src/components/EditSurvey.svelte +++ b/plugins/survey-resources/src/components/EditSurvey.svelte @@ -15,34 +15,76 @@ // --> @@ -95,7 +129,9 @@ placeholder={survey.string.Name} bind:value={object.name} kind={'large-style'} - on:change={nameChange} + on:input={() => { + handleChange({ name: object.name }) + }} />
@@ -103,7 +139,9 @@ disabled={readonly} placeholder={survey.string.PromptPlaceholder} bind:value={object.prompt} - on:change={promptChange} + on:input={() => { + handleChange({ prompt: object.prompt }) + }} />
@@ -115,42 +153,48 @@
- {#each questionEditSlots as question, index} + {#each questionList as question, index (index)} + {@const isNewQuestion = index === questionList.length - 1}
{ - dragOver(ev, index) + onQuestionDragOver(ev, index) }} on:dragleave={(ev) => { - dragLeave(ev, index) + onQuestionDragLeave(ev, index) }} - on:drop={dragDrop} + on:drop={onQuestionDrop} class:dragged-over={draggedIndex !== undefined && draggedOverIndex === index && draggedOverIndex !== draggedIndex && draggedOverIndex !== draggedIndex + 1} > - {#key index} - { - draggedIndex = index - }} - on:dragEnd={() => { - draggedIndex = undefined - draggedOverIndex = undefined - }} - /> - {/key} + { + deleteQuestion(index) + }} + on:change={(e) => { + isNewQuestion ? handleNewQuestionChange(e.detail) : handleQuestionChange(index, e.detail) + }} + {readonly} + on:dragStart={() => { + draggedIndex = index + }} + on:dragEnd={() => { + draggedIndex = undefined + draggedOverIndex = undefined + }} + />
{/each} {/if}