Skip to content

Commit bc81d9e

Browse files
committed
wip: ui improvement and bug fixes
1 parent c866ab8 commit bc81d9e

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

diff-tree.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getDiff(ours: Description, theirs: Description) {
2929
diff[key] = { ours: ours[key], theirs: theirs[key] };
3030
else if (Array.isArray(val)) {
3131
const arrayDiff = { ours: [] as string[], theirs: [] as string[] };
32-
const vals = new Set([...ours[key], ...theirs[key]]);
32+
const vals = new Set([...(ours[key] ?? []), ...(theirs[key] ?? [])]);
3333
vals.forEach((val) => {
3434
const inOurs = ours[key]?.includes(val);
3535
const inTheirs = theirs[key]?.includes(val);
@@ -82,9 +82,8 @@ export class DiffTree extends LitElement {
8282
>();
8383
@query("md-icon-button") expandButton!: HTMLElement;
8484

85-
get expanded(): boolean {
86-
return this.expandButton?.hasAttribute("selected");
87-
}
85+
@property({ type: Boolean })
86+
expanded = false;
8887

8988
get ourHasher(): ReturnType<typeof newHasher> | undefined {
9089
return this.ours ? this.hashers.get(this.ours.ownerDocument) : undefined;
@@ -145,11 +144,13 @@ export class DiffTree extends LitElement {
145144
elementDiff[id] ??= {};
146145
elementDiff[id].theirs = element;
147146
});
147+
const expanded = Object.keys(elementDiff).length === 1;
148148
return Object.entries(elementDiff).map(([id, { ours, theirs }]) => {
149149
return html`<diff-tree
150150
.ours=${ours}
151151
.theirs=${theirs}
152152
.hashers=${this.hashers}
153+
.expanded=${expanded}
153154
></diff-tree>`;
154155
});
155156
})}
@@ -170,6 +171,7 @@ export class DiffTree extends LitElement {
170171
<td></td>
171172
<td>${name}</td>
172173
<td>${ours}</td>
174+
<td class="arrow">→</td>
173175
<td>${theirs}</td>
174176
</tr>`,
175177
)}
@@ -180,10 +182,11 @@ export class DiffTree extends LitElement {
180182
<td>${ns}</td>
181183
<td>${k}</td>
182184
<td>${(d as { ours: string }).ours}</td>
185+
<td class="arrow">→</td>
183186
<td>${(d as { theirs: string }).theirs}</td>
184187
</tr>`,
185188
),
186-
)},
189+
)}
187190
</table>`;
188191
}
189192

@@ -194,15 +197,14 @@ export class DiffTree extends LitElement {
194197
renderElement() {
195198
const element = this.ours ?? this.theirs;
196199
if (!element) return nothing;
197-
const id = identity(element);
200+
const id = identity(element) || element.tagName;
198201
const tag = element.tagName;
199202
const description = this.ourDescription ?? this.theirDescription;
200203
const hash = this.ourHash ?? this.theirHash;
201-
return html`<md-icon-button toggle @click=${() => this.requestUpdate()}>
202-
<md-icon>unfold_more</md-icon>
203-
<md-icon slot="selected">unfold_less</md-icon>
204-
</md-icon-button>
205-
<p>${this.ours ? "-" : "+"} ${id}</p>
204+
return html`<a @click=${() => (this.expanded = !this.expanded)}
205+
><md-icon>${this.expanded ? "arrow_drop_down" : "arrow_right"}</md-icon>
206+
${this.ours ? "-" : "+"} ${id}</a
207+
>
206208
${this.expanded ? this.renderDiff() : ""} `;
207209
}
208210

@@ -220,23 +222,17 @@ export class DiffTree extends LitElement {
220222

221223
Object.keys(this.ourDescription ?? {}).forEach((key) => {});
222224

223-
return html`<md-icon-button toggle @click=${() => this.requestUpdate()}>
224-
<md-icon>unfold_more</md-icon>
225-
<md-icon slot="selected">unfold_less</md-icon>
226-
</md-icon-button>
227-
<p>
228-
${identity(this.ours) || this.ours.tagName}
229-
<md-icon style="--md-icon-size: 1em">arrow_forward</md-icon> ${identity(
230-
this.theirs,
231-
) || this.theirs.tagName}
232-
</p>
225+
return html`<a @click=${() => (this.expanded = !this.expanded)}
226+
><md-icon>${this.expanded ? "arrow_drop_down" : "arrow_right"}</md-icon>
227+
${identity(this.ours) || this.ours.tagName}</a
228+
>
233229
${this.expanded ? this.renderDiff() : ""} `;
234230
}
235231

236232
static styles = css`
237-
md-icon-button {
238-
float: left;
239-
transform: scale(0.6);
233+
md-icon {
234+
position: relative;
235+
top: 6px;
240236
}
241237
div {
242238
margin-left: 1em;
@@ -296,7 +292,7 @@ export class DiffTree extends LitElement {
296292
border: 0.25em solid var(--oscd-base2);
297293
table-layout: auto;
298294
border-collapse: collapse;
299-
width: max-content;
295+
max-width: 100%;
300296
margin-left: 1.2em;
301297
margin-bottom: 0.3em;
302298
background: none;

hash.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ describe("hasher", () => {
183183
);
184184
expect(description).property("@Text").to.have.lengthOf(1);
185185
const text = db.Text[description["@Text"][0]];
186+
console.log(JSON.stringify(text, null, 2));
186187
expect(text).to.exist.and.to.have.property(
187188
"xml",
188189
baseEnumType.querySelector("Text")?.outerHTML,

hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ export function hasher(
741741
})
742742
.map(hash)
743743
.sort();
744-
if (hashes.length) description["@" + to] = hashes;
744+
if (hashes.length) description["@" + to.split(">").pop()] = hashes;
745745
});
746746

747747
return description;

oscd-diff.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export default class OscdDiff extends LitElement {
2525
hashers = new WeakMap<XMLDocument, ReturnType<typeof newHasher>>();
2626

2727
render() {
28-
return html`<h1>diff</h1>
29-
<table>
28+
return html`<table>
3029
<tr>
3130
<td>
3231
<select id="doc1">

0 commit comments

Comments
 (0)