mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Convert topic-title to glimmer/gjs (#26808)
This reverts commit 5d568d0bab
. (reland of #26775)
Now with removed unnecessary `?.` operators to workaround a terser/babel/??? issue.
This commit is contained in:
parent
19b7b22627
commit
0548f24208
@ -105,7 +105,7 @@ export default Component.extend({
|
|||||||
const rawTopicLink = this.element.querySelector(".raw-topic-link");
|
const rawTopicLink = this.element.querySelector(".raw-topic-link");
|
||||||
|
|
||||||
rawTopicLink &&
|
rawTopicLink &&
|
||||||
topicTitleDecorators?.forEach((cb) =>
|
topicTitleDecorators.forEach((cb) =>
|
||||||
cb(this.topic, rawTopicLink, "topic-list-item-title")
|
cb(this.topic, rawTopicLink, "topic-list-item-title")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { hash } from "@ember/helper";
|
||||||
|
import { on } from "@ember/modifier";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
||||||
|
import PluginOutlet from "discourse/components/plugin-outlet";
|
||||||
|
import { isiPad } from "discourse/lib/utilities";
|
||||||
|
|
||||||
|
export let topicTitleDecorators = [];
|
||||||
|
|
||||||
|
export function addTopicTitleDecorator(decorator) {
|
||||||
|
topicTitleDecorators.push(decorator);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetTopicTitleDecorators() {
|
||||||
|
topicTitleDecorators.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class TopicTitle extends Component {
|
||||||
|
@action
|
||||||
|
applyDecorators(element) {
|
||||||
|
const fancyTitle = element.querySelector(".fancy-title");
|
||||||
|
|
||||||
|
if (fancyTitle) {
|
||||||
|
topicTitleDecorators.forEach((cb) =>
|
||||||
|
cb(this.args.model, fancyTitle, "topic-title")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
keyDown(e) {
|
||||||
|
if (document.body.classList.contains("modal-open")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
e.preventDefault();
|
||||||
|
this.args.cancelled();
|
||||||
|
} else if (
|
||||||
|
e.key === "Enter" &&
|
||||||
|
(e.ctrlKey || e.metaKey || (isiPad() && e.altKey))
|
||||||
|
) {
|
||||||
|
// Ctrl+Enter or Cmd+Enter
|
||||||
|
// iPad physical keyboard does not offer Command or Ctrl detection
|
||||||
|
// so use Alt+Enter
|
||||||
|
e.preventDefault();
|
||||||
|
this.args.save(undefined, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<template>
|
||||||
|
{{! template-lint-disable no-invalid-interactive }}
|
||||||
|
<div
|
||||||
|
{{didInsert this.applyDecorators}}
|
||||||
|
{{on "keydown" this.keyDown}}
|
||||||
|
id="topic-title"
|
||||||
|
class="container"
|
||||||
|
>
|
||||||
|
<div class="title-wrapper">
|
||||||
|
{{yield}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<PluginOutlet
|
||||||
|
@name="topic-title"
|
||||||
|
@connectorTagName="div"
|
||||||
|
@outletArgs={{hash model=@model}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
<div class="container">
|
|
||||||
<div class="title-wrapper">
|
|
||||||
{{yield}}
|
|
||||||
</div>
|
|
||||||
<span>
|
|
||||||
<PluginOutlet
|
|
||||||
@name="topic-title"
|
|
||||||
@connectorTagName="div"
|
|
||||||
@outletArgs={{hash model=this.model}}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
@ -1,53 +0,0 @@
|
|||||||
import Component from "@ember/component";
|
|
||||||
import { schedule } from "@ember/runloop";
|
|
||||||
import { isiPad } from "discourse/lib/utilities";
|
|
||||||
|
|
||||||
export let topicTitleDecorators = [];
|
|
||||||
|
|
||||||
export function addTopicTitleDecorator(decorator) {
|
|
||||||
topicTitleDecorators.push(decorator);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resetTopicTitleDecorators() {
|
|
||||||
topicTitleDecorators.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Component.extend({
|
|
||||||
elementId: "topic-title",
|
|
||||||
|
|
||||||
didInsertElement() {
|
|
||||||
this._super(...arguments);
|
|
||||||
|
|
||||||
schedule("afterRender", () => {
|
|
||||||
if (this.element && !this.isDestroying && !this.isDestroyed) {
|
|
||||||
const fancyTitle = this.element.querySelector(".fancy-title");
|
|
||||||
|
|
||||||
fancyTitle &&
|
|
||||||
topicTitleDecorators &&
|
|
||||||
topicTitleDecorators.forEach((cb) =>
|
|
||||||
cb(this.model, fancyTitle, "topic-title")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
keyDown(e) {
|
|
||||||
if (document.body.classList.contains("modal-open")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.key === "Escape") {
|
|
||||||
e.preventDefault();
|
|
||||||
this.cancelled();
|
|
||||||
} else if (
|
|
||||||
e.key === "Enter" &&
|
|
||||||
(e.ctrlKey || e.metaKey || (isiPad() && e.altKey))
|
|
||||||
) {
|
|
||||||
// Ctrl+Enter or Cmd+Enter
|
|
||||||
// iPad physical keyboard does not offer Command or Ctrl detection
|
|
||||||
// so use Alt+Enter
|
|
||||||
e.preventDefault();
|
|
||||||
this.save(undefined, e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user