Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Sep 10, 2024
1 parent 1c50069 commit b5ccc8b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13659,14 +13659,22 @@ function replaceElementByIdWithNewEmptyDiv(id) {
return new_element;
}
class MergeState {
constructor() {
/// `parent_window` is an Element that should contain the element that
/// MergeState will operate in. It will have a CSS class set when the editor
/// transitions to the pinned mode or single-editor mode.
//
// TODO: This will be less messy if we set these CSS classes on an element
// private to the MergeState, and have the caller supply a call-back so that
// it can react to the setting of pinned or single-editor state.
constructor(parent_window) {
__publicField(this, "merge_views");
__publicField(this, "dom_ids");
__publicField(this, "initial_values");
__publicField(this, "parent_window");
this.merge_views = {};
this.dom_ids = {};
this.initial_values = {};
this.parent_window = parent_window;
}
values() {
const result = {};
Expand Down Expand Up @@ -13787,12 +13795,11 @@ class MergeState {
}
let target_element = replaceElementByIdWithNewEmptyDiv(unique_id);
Q(ke`${templates}`, target_element);
const merge_state = new MergeState();
const parent_window = target_element.closest(".app-window");
if (!parent_window) {
throw `Element with id ${unique_id} must be a child of an element with class .app-window`;
}
merge_state.parent_window = parent_window;
const merge_state = new MergeState(parent_window);
for (let k2 in merge_input) {
if (to_error(merge_input[k2]) != null) {
continue;
Expand Down Expand Up @@ -13862,9 +13869,8 @@ class MergeState {
pinButtonEl.onclick = () => this.toggle_pinning(unique_id);
detailsButtonEl.open = false;
detailsButtonEl.ontoggle = () => {
var _a, _b;
if (!detailsButtonEl.open) {
if ((_b = (_a = this.parent_window) == null ? void 0 : _a.classList) == null ? void 0 : _b.contains("pinned-mode")) {
if (this.parent_window.classList.contains("pinned-mode")) {
this.toggle_pinning(unique_id);
}
} else {
Expand Down Expand Up @@ -13918,9 +13924,6 @@ class MergeState {
detailsButtonEl.open = true;
}
toggle_pinning(unique_id) {
if (this.parent_window == void 0) {
throw "Can't toggle pinning for uninitialized MergeState";
}
this.parent_window.classList.toggle("pinned-mode");
for (const merge_view of this.parent_window.getElementsByClassName(
`merge-view`
Expand Down
2 changes: 1 addition & 1 deletion webapp/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Diffedit3</title>
<script type="module" crossorigin src="/assets/index-DTwiRke5.js"></script>
<script type="module" crossorigin src="/assets/index-DZJFz_NH.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DCOZ1_NJ.css">
</head>

Expand Down
20 changes: 12 additions & 8 deletions webapp/src/merge_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ export class MergeState {
protected merge_views: Record<string, MergeView>;
protected dom_ids: Record<string, string>;
protected initial_values: Record<string, SingleFileMergeInput>;
protected parent_window: Element | undefined;
protected parent_window: Element;

protected constructor() {
/// `parent_window` is an Element that should contain the element that
/// MergeState will operate in. It will have a CSS class set when the editor
/// transitions to the pinned mode or single-editor mode.
//
// TODO: This will be less messy if we set these CSS classes on an element
// private to the MergeState, and have the caller supply a call-back so that
// it can react to the setting of pinned or single-editor state.
protected constructor(parent_window: Element) {
this.merge_views = {};
this.dom_ids = {};
this.initial_values = {};
this.parent_window = parent_window;
}

public values(): Record<string, string> {
Expand Down Expand Up @@ -168,12 +176,11 @@ export class MergeState {
// it's not slower?)
lit_html_render(html`${templates}`, target_element);

const merge_state = new MergeState();
const parent_window = target_element.closest(".app-window");
if (!parent_window) {
throw `Element with id ${unique_id} must be a child of an element with class .app-window`;
}
merge_state.parent_window = parent_window;
const merge_state = new MergeState(parent_window);

for (let k in merge_input) {
if (to_error(merge_input[k]) != null) {
Expand Down Expand Up @@ -264,7 +271,7 @@ export class MergeState {
detailsButtonEl.ontoggle = () => {
if (!detailsButtonEl.open) {
// We just closed the details
if (this.parent_window?.classList?.contains("pinned-mode")) {
if (this.parent_window.classList.contains("pinned-mode")) {
this.toggle_pinning(unique_id);
}
} else {
Expand Down Expand Up @@ -335,9 +342,6 @@ export class MergeState {
}

protected toggle_pinning(unique_id: string) {
if (this.parent_window == undefined) {
throw "Can't toggle pinning for uninitialized MergeState";
}
this.parent_window.classList.toggle("pinned-mode");
for (const merge_view of this.parent_window.getElementsByClassName(
`merge-view` /* TODO: Should be this collections's merge views only */,
Expand Down

0 comments on commit b5ccc8b

Please sign in to comment.