Skip to content

Commit 560a074

Browse files
committed
Refactor fold controls for improved UI and functionality
Refactor fold controls for improved UI and functionality - Updated the fold controls to use larger, clearer double-chevron icons. - Ensured the fold control column is reserved whenever `__FOLD_START__` markers are present in the content. - Fixed misalignment/overlap when folding programmatically generated code.
1 parent a8c0cc4 commit 560a074

5 files changed

Lines changed: 263 additions & 79 deletions

File tree

RELEASE_NOTES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
## NEXT RELEASE
44

5+
### Features
6+
7+
- **Fold markers `${fold}``${/fold}`**: collapsible sections are now expressed as content markers (mirroring the block-comment `${key}…${/key}` pattern, no companion binding needed). `${fold}` starts collapsed, `${fold:open}` starts expanded. They work in any language and — unlike the previous attribute — both inside a `<textarea>` **and** via the `code` property (programmatic content). Marker lines are removed from the output and from copy/download.
8+
- **Escaping `\${...}`**: write `\${...}` to render the literal `${...}` instead of interpreting it (binding, block comment or fold) — useful for documenting the syntax with the component itself.
9+
10+
### Improvements
11+
12+
- **Collapsible UI polish**: the collapsed band uses a larger double-chevron "unfold" icon (clearer than a caret), its whole row is clickable to expand, and its layout is overlap-proof (the `⋯ N lines` text can no longer overlap the icon). All fold chevrons are crisp SVGs.
13+
14+
### Breaking changes
15+
16+
- **Removed `collapsible` / `collapsed` `<textarea>` attributes** (introduced in 1.1.0) in favor of the `${fold}` markers above. Migrate `<textarea collapsible collapsed>…</textarea>` to a `${fold}``${/fold}` block (and `collapsible` without `collapsed` to `${fold:open}`).
17+
518
---
619

720
## 1.1.0

demo/index.html

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ <h2>Theme & Color Scheme</h2>
502502
<textarea>${useTheme}<link rel="stylesheet" href="https://unpkg.com/@softwarity/interactive-code/themes/${theme}.css"></textarea>
503503
<code-binding key="useTheme" type="comment" value="true"
504504
onchange="loadThemeCSS(e.detail ? this.closest('interactive-code').querySelector('[key=theme]').value : '')"></code-binding>
505-
<code-binding key="theme" type="select" options="vscode,github,solarized,catppuccin" value="catppuccin"
505+
<code-binding key="theme" type="select" carousel options="vscode,github,solarized,catppuccin" value="catppuccin"
506506
onchange="var c=this.closest('interactive-code').querySelector('[key=useTheme]'); if(String(c.value)!=='false') loadThemeCSS(e.detail)"></code-binding>
507507
</interactive-code>
508508

@@ -1043,24 +1043,28 @@ <h3>JSON Type</h3>
10431043
</div>
10441044
</article>
10451045

1046-
<!-- Collapsible Sections -->
1046+
<!-- Fold Sections -->
10471047
<article class="doc-section">
10481048
<h3>Collapsible Sections</h3>
1049-
<p>Add <code>collapsible</code> on a <code>&lt;textarea&gt;</code> to fold a range of non-interactive lines (GitHub-diff style). Add <code>collapsed</code> to start folded. Folding is purely visual copy/download still export the full content:</p>
1049+
<p>Wrap a range of lines in <code>${fold}</code> <code>${/fold}</code> markers to make it foldable (GitHub-diff style). Collapsed by default; use <code>${fold:open}</code> to start expanded. The marker lines are removed from the output — folding is purely visual, and copy/download still export the full content. Works inside a <code>&lt;textarea&gt;</code> or via the <code>code</code> property, in any language. Bindings <strong>inside</strong> a fold stay fully interactive — they're just hidden until expanded (here <code>trace</code> and <code>buffer</code> are editable once you open the block).</p>
10501050

10511051
<div class="code-header"><span>Written by developer</span></div>
10521052
<interactive-code class="inline-code" language="html" show-copy>
10531053
<textarea><interactive-code language="json" ${show-line-numbers} ${show-copy}>
10541054
<textarea>{
1055-
"id": "${id}",&lt;/textarea>
1056-
<textarea collapsible collapsed> "_internal": {
1057-
"trace": true,
1055+
"id": "${id}",
1056+
\${fold}
1057+
"_internal": {
1058+
"trace": ${trace},
10581059
"verbose": false,
1059-
"buffer": 4096
1060-
},&lt;/textarea>
1061-
<textarea> "enabled": ${enabled}
1060+
"buffer": ${buffer}
1061+
},
1062+
\${/fold}
1063+
"enabled": ${enabled}
10621064
}&lt;/textarea>
10631065
<code-binding key="id" type="string" value="api"></code-binding>
1066+
<code-binding key="trace" type="boolean" value="true"></code-binding>
1067+
<code-binding key="buffer" type="number" value="4096" min="512" max="8192" step="512"></code-binding>
10641068
<code-binding key="enabled" type="boolean" value="true"></code-binding>
10651069
</interactive-code></textarea>
10661070
<code-binding key="show-line-numbers" type="attribute" value="true"
@@ -1070,25 +1074,31 @@ <h3>Collapsible Sections</h3>
10701074
</interactive-code>
10711075

10721076
<div class="preview-wrapper">
1073-
<div class="preview-label">Seen by user (click the band to expand, copy to get the full JSON)</div>
1077+
<div class="preview-label">Seen by user (expand the band, then edit the values inside the fold)</div>
10741078
<div class="user-view">
10751079
<interactive-code language="json" show-line-numbers show-copy>
10761080
<textarea>{
1077-
"id": "${id}",</textarea>
1078-
<textarea collapsible collapsed> "_internal": {
1079-
"trace": true,
1081+
"id": "${id}",
1082+
${fold}
1083+
"_internal": {
1084+
"trace": ${trace},
10801085
"verbose": false,
1081-
"buffer": 4096
1082-
},</textarea>
1083-
<textarea> "enabled": ${enabled}
1086+
"buffer": ${buffer}
1087+
},
1088+
${/fold}
1089+
"enabled": ${enabled}
10841090
}</textarea>
10851091
<code-binding key="id" type="string" value="api"
10861092
onchange="updateFoldPreview(this)"></code-binding>
1093+
<code-binding key="trace" type="boolean" value="true"
1094+
onchange="updateFoldPreview(this)"></code-binding>
1095+
<code-binding key="buffer" type="number" value="4096" min="512" max="8192" step="512"
1096+
onchange="updateFoldPreview(this)"></code-binding>
10871097
<code-binding key="enabled" type="boolean" value="true"
10881098
onchange="updateFoldPreview(this)"></code-binding>
10891099
</interactive-code>
10901100
<div class="live-element">
1091-
<div id="preview-fold" class="preview-card" style="border-color: var(--accent-purple);">id: api &middot; enabled: true</div>
1101+
<div id="preview-fold" class="preview-card" style="border-color: var(--accent-purple);">id: api &middot; trace: true &middot; buffer: 4096 &middot; enabled: true</div>
10921102
</div>
10931103
</div>
10941104
</div>
@@ -1336,9 +1346,8 @@ <h4>Content</h4>
13361346
<ul class="feature-list">
13371347
<li><code>condition="key"</code> - Show when binding value is truthy</li>
13381348
<li><code>condition="!key"</code> - Show when binding value is falsy</li>
1339-
<li><code>collapsible</code> - Make the section foldable (band shows the hidden line count)</li>
1340-
<li><code>collapsed</code> - Start the section folded (requires <code>collapsible</code>)</li>
13411349
</ul>
1350+
<p>Fold a range of lines with <code>${fold}</code><code>${/fold}</code> markers (collapsed by default) or <code>${fold:open}</code><code>${/fold}</code> (expanded). The band shows the hidden line count; folding is visual only (copy/download stay complete).</p>
13421351
</article>
13431352

13441353
<!-- API - CodeBindingElement -->
@@ -1550,12 +1559,12 @@ <h3>Features</h3>
15501559
'theme: ' + theme + ' · ' + fontSize + 'px · ' + (notif ? '🔔 on' : '🔕 off');
15511560
}
15521561

1553-
// Collapsible demo: reflect id/enabled into the live element
1562+
// Collapsible demo: reflect values (including the ones inside the fold) into the live element
15541563
function updateFoldPreview(binding) {
15551564
var ic = binding.closest('interactive-code');
1556-
var id = ic.querySelector('code-binding[key=id]').value;
1557-
var enabled = ic.querySelector('code-binding[key=enabled]').value;
1558-
document.getElementById('preview-fold').textContent = 'id: ' + id + ' · enabled: ' + enabled;
1565+
var get = function(k) { var b = ic.querySelector('code-binding[key=' + k + ']'); return b ? b.value : ''; };
1566+
document.getElementById('preview-fold').textContent =
1567+
'id: ' + get('id') + ' · trace: ' + get('trace') + ' · buffer: ' + get('buffer') + ' · enabled: ' + get('enabled');
15591568
}
15601569

15611570
// Apply initial interactive style (hand-drawn)

0 commit comments

Comments
 (0)