Skip to content

Commit 6f2aba1

Browse files
refactor(svelte): cleanup Collapse, Item, List, and RichEditor components
1 parent 610aebd commit 6f2aba1

File tree

4 files changed

+280
-95
lines changed

4 files changed

+280
-95
lines changed

src/components/Collapse.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
height: 100%;
3434
color: rgb(220, 224, 226);
3535
transition: transform 0.2s ease;
36+
transform: rotate(90deg);
3637
}
3738
3839
svg:hover {
3940
color: #333;
4041
}
4142
4243
.collapsed svg {
43-
transform: rotate(90deg);
44+
transform: rotate(0deg);
4445
}
4546
</style>

src/components/Item.svelte

Lines changed: 90 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
$: isCheckboxChecked = /^\[x\]\s/.test(item.text || '')
2424
$: displayText = hasCheckboxSyntax ? item.text.replace(/^\[( |x)\]\s/, '') : item.text
2525
$: hasDescription = !!item.description?.trim()
26+
$: hasChildren = item.children?.length > 0
2627
2728
function handleToggleComplete() {
2829
if (hasCheckboxSyntax) {
@@ -39,6 +40,10 @@
3940
dispatch('delete', { id: item.id })
4041
}
4142
43+
function handleForceDelete() {
44+
dispatch('forcedelete', { id: item.id })
45+
}
46+
4247
function handleNewBullet() {
4348
dispatch('newbullet', { id: item.id })
4449
}
@@ -61,6 +66,14 @@
6166
dispatch('selectdown', { id: item.id })
6267
}
6368
69+
function handleShiftSelectUp() {
70+
dispatch('shiftselectup', { id: item.id })
71+
}
72+
73+
function handleShiftSelectDown() {
74+
dispatch('shiftselectdown', { id: item.id })
75+
}
76+
6477
function handleShowDescription() {
6578
showDescriptionEditor = true
6679
tick().then(() => {
@@ -129,10 +142,9 @@
129142
class="item"
130143
class:completed={item.completed || isCheckboxChecked}
131144
class:selected={isSelected}
132-
class:nochildren={!item.children?.length}
133145
>
134146
<div class="top">
135-
<div class="options">
147+
<div class="left-controls">
136148
<button class="menu-trigger" on:click={handleMenuClick} title="Options">
137149
<svg width="16" height="16" viewBox="0 0 256 256">
138150
<path
@@ -147,63 +159,69 @@
147159
on:close={() => showMenu = false}
148160
/>
149161
{/if}
150-
{#if item.children?.length}
151-
<Collapse
152-
collapsed={!item.open}
153-
on:change={handleToggleOpen}
154-
/>
155-
{/if}
162+
<div class="collapse-slot">
163+
{#if hasChildren}
164+
<Collapse
165+
collapsed={!item.open}
166+
on:change={handleToggleOpen}
167+
/>
168+
{/if}
169+
</div>
156170
</div>
157171
158-
<div class="bullets">
159-
<Bullet
160-
background={!!item.children?.length && !item.open}
161-
on:click={handleZoom}
162-
/>
163-
{#if hasCheckboxSyntax}
164-
<Checkbox
165-
checked={isCheckboxChecked}
166-
on:click={handleToggleComplete}
172+
<div class="content-area">
173+
<div class="bullet-line">
174+
<Bullet
175+
background={hasChildren && !item.open}
176+
on:click={handleZoom}
167177
/>
178+
{#if hasCheckboxSyntax}
179+
<Checkbox
180+
checked={isCheckboxChecked}
181+
on:click={handleToggleComplete}
182+
/>
183+
{/if}
184+
<div class="title-editor">
185+
<RichEditor
186+
bind:this={titleEditorRef}
187+
value={displayText}
188+
showPlaceholder={false}
189+
{highlightPhrase}
190+
on:change={handleTextChange}
191+
on:delete={handleDelete}
192+
on:forcedelete={handleForceDelete}
193+
on:newbullet={handleNewBullet}
194+
on:indent={handleIndent}
195+
on:outdent={handleOutdent}
196+
on:selectup={handleSelectUp}
197+
on:selectdown={handleSelectDown}
198+
on:shiftselectup={handleShiftSelectUp}
199+
on:shiftselectdown={handleShiftSelectDown}
200+
on:togglecomplete={handleToggleComplete}
201+
on:description={handleShowDescription}
202+
on:hashtagclick={handleHashtagClick}
203+
/>
204+
</div>
205+
</div>
206+
207+
{#if hasDescription || showDescriptionEditor}
208+
<div class="description-editor">
209+
<RichEditor
210+
bind:value={item.description}
211+
isDescription={true}
212+
showPlaceholder={false}
213+
{highlightPhrase}
214+
editorClass="editable description"
215+
on:change={handleDescriptionChange}
216+
on:delete={handleExitDescription}
217+
on:exitdescription={handleExitDescription}
218+
on:togglecomplete={handleToggleComplete}
219+
on:hashtagclick={handleHashtagClick}
220+
/>
221+
</div>
168222
{/if}
169223
</div>
170-
171-
<div class="title-editor">
172-
<RichEditor
173-
bind:this={titleEditorRef}
174-
value={displayText}
175-
showPlaceholder={false}
176-
{highlightPhrase}
177-
on:change={handleTextChange}
178-
on:delete={handleDelete}
179-
on:newbullet={handleNewBullet}
180-
on:indent={handleIndent}
181-
on:outdent={handleOutdent}
182-
on:selectup={handleSelectUp}
183-
on:selectdown={handleSelectDown}
184-
on:togglecomplete={handleToggleComplete}
185-
on:description={handleShowDescription}
186-
on:hashtagclick={handleHashtagClick}
187-
/>
188-
</div>
189224
</div>
190-
191-
{#if hasDescription || showDescriptionEditor}
192-
<div class="description-editor">
193-
<RichEditor
194-
bind:value={item.description}
195-
isDescription={true}
196-
showPlaceholder={false}
197-
{highlightPhrase}
198-
editorClass="editable description"
199-
on:change={handleDescriptionChange}
200-
on:delete={handleExitDescription}
201-
on:exitdescription={handleExitDescription}
202-
on:togglecomplete={handleToggleComplete}
203-
on:hashtagclick={handleHashtagClick}
204-
/>
205-
</div>
206-
{/if}
207225
</li>
208226
209227
<style>
@@ -215,17 +233,13 @@
215233
flex-direction: column;
216234
}
217235
218-
.nochildren .options {
219-
min-width: 1rem;
220-
}
221-
222236
.completed :global(.title-editor .editable) {
223237
text-decoration: line-through;
224238
opacity: 0.6;
225239
}
226240
227241
.selected {
228-
background: rgba(73, 186, 242, 0.1);
242+
background: rgba(73, 186, 242, 0.15);
229243
border-radius: 4px;
230244
}
231245
@@ -235,13 +249,20 @@
235249
width: 100%;
236250
}
237251
238-
.options {
252+
.left-controls {
239253
display: flex;
240254
align-items: center;
241-
min-width: 1.8rem;
255+
flex-shrink: 0;
242256
position: relative;
243257
}
244258
259+
.collapse-slot {
260+
width: 1rem;
261+
display: flex;
262+
align-items: center;
263+
justify-content: center;
264+
}
265+
245266
.menu-trigger {
246267
all: unset;
247268
cursor: pointer;
@@ -263,10 +284,16 @@
263284
color: #666 !important;
264285
}
265286
266-
.bullets {
287+
.content-area {
288+
flex: 1;
289+
min-width: 0;
290+
display: flex;
291+
flex-direction: column;
292+
}
293+
294+
.bullet-line {
267295
display: flex;
268296
align-items: center;
269-
flex-shrink: 0;
270297
}
271298
272299
.title-editor {
@@ -275,7 +302,7 @@
275302
}
276303
277304
.description-editor {
278-
margin-left: 2.8rem;
305+
margin-left: 1.3rem;
279306
font-size: 0.85rem;
280307
}
281308
</style>

0 commit comments

Comments
 (0)