2023-02-14 09:20:15 -05:00
|
|
|
import { chooseDarker, darkLightDiff } from "wizard/lib/preview";
|
2020-08-31 06:14:09 -04:00
|
|
|
import I18n from "I18n";
|
2022-06-04 12:04:00 -04:00
|
|
|
import { bind, observes } from "discourse-common/utils/decorators";
|
2022-06-04 13:19:49 -04:00
|
|
|
import { action } from "@ember/object";
|
2023-02-14 09:20:15 -05:00
|
|
|
import WizardPreviewBaseComponent from "./wizard-preview-base";
|
2020-08-31 06:14:09 -04:00
|
|
|
|
2020-10-05 13:40:41 -04:00
|
|
|
const LOREM = `
|
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing.
|
|
|
|
Nullam eget sem non elit tincidunt rhoncus. Fusce
|
|
|
|
velit nisl, porttitor sed nisl ac, consectetur interdum
|
|
|
|
metus. Fusce in consequat augue, vel facilisis felis.`;
|
|
|
|
|
2023-02-14 09:20:15 -05:00
|
|
|
export default WizardPreviewBaseComponent.extend({
|
|
|
|
width: 628,
|
|
|
|
height: 322,
|
2020-08-31 06:14:09 -04:00
|
|
|
logo: null,
|
|
|
|
avatar: null,
|
2021-08-25 17:10:12 -04:00
|
|
|
previewTopic: true,
|
|
|
|
draggingActive: false,
|
|
|
|
startX: 0,
|
|
|
|
scrollLeft: 0,
|
|
|
|
|
2022-06-04 12:04:00 -04:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.wizard.on("homepageStyleChanged", this.onHomepageStyleChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.wizard.off("homepageStyleChanged", this.onHomepageStyleChange);
|
|
|
|
},
|
|
|
|
|
2022-06-17 08:50:21 -04:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.element.addEventListener("mouseleave", this.handleMouseLeave);
|
|
|
|
this.element.addEventListener("mousemove", this.handleMouseMove);
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.element.removeEventListener("mouseleave", this.handleMouseLeave);
|
|
|
|
this.element.removeEventListener("mousemove", this.handleMouseMove);
|
|
|
|
},
|
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
mouseDown(e) {
|
|
|
|
const slider = this.element.querySelector(".previews");
|
|
|
|
this.setProperties({
|
|
|
|
draggingActive: true,
|
|
|
|
startX: e.pageX - slider.offsetLeft,
|
|
|
|
scrollLeft: slider.scrollLeft,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-06-17 08:50:21 -04:00
|
|
|
@bind
|
|
|
|
handleMouseLeave() {
|
2021-08-25 17:10:12 -04:00
|
|
|
this.set("draggingActive", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseUp() {
|
|
|
|
this.set("draggingActive", false);
|
|
|
|
},
|
|
|
|
|
2022-06-17 08:50:21 -04:00
|
|
|
@bind
|
|
|
|
handleMouseMove(e) {
|
2021-08-25 17:10:12 -04:00
|
|
|
if (!this.draggingActive) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const slider = this.element.querySelector(".previews"),
|
|
|
|
x = e.pageX - slider.offsetLeft,
|
|
|
|
walk = (x - this.startX) * 1.5;
|
|
|
|
|
|
|
|
slider.scrollLeft = this.scrollLeft - walk;
|
|
|
|
|
|
|
|
if (slider.scrollLeft < 50) {
|
|
|
|
this.set("previewTopic", true);
|
|
|
|
}
|
|
|
|
if (slider.scrollLeft > slider.offsetWidth) {
|
|
|
|
this.set("previewTopic", false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
didUpdateAttrs() {
|
|
|
|
this._super(...arguments);
|
2020-08-31 06:14:09 -04:00
|
|
|
|
|
|
|
this.triggerRepaint();
|
2022-06-04 12:04:00 -04:00
|
|
|
},
|
2021-08-25 17:10:12 -04:00
|
|
|
|
2022-06-04 12:04:00 -04:00
|
|
|
@bind
|
|
|
|
onHomepageStyleChange() {
|
|
|
|
this.set("previewTopic", false);
|
2021-08-25 17:10:12 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
@observes("previewTopic")
|
|
|
|
scrollPreviewArea() {
|
|
|
|
const el = this.element.querySelector(".previews");
|
|
|
|
el.scrollTo({
|
|
|
|
top: 0,
|
|
|
|
left: this.previewTopic ? 0 : el.scrollWidth - el.offsetWidth,
|
|
|
|
behavior: "smooth",
|
|
|
|
});
|
2020-08-31 06:14:09 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
images() {
|
|
|
|
return {
|
|
|
|
logo: this.wizard.getLogoUrl(),
|
|
|
|
avatar: "/images/wizard/trout.png",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-10-05 13:40:41 -04:00
|
|
|
paint({ ctx, colors, font, headingFont, width, height }) {
|
2020-08-31 06:14:09 -04:00
|
|
|
const headerHeight = height * 0.3;
|
2020-10-05 13:40:41 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
this.drawFullHeader(colors, headingFont, this.logo);
|
2020-08-31 06:14:09 -04:00
|
|
|
|
2020-11-05 09:55:35 -05:00
|
|
|
const margin = 20;
|
2021-08-25 17:10:12 -04:00
|
|
|
const avatarSize = height * 0.15;
|
|
|
|
const lineHeight = height / 14;
|
2020-08-31 06:14:09 -04:00
|
|
|
|
|
|
|
// Draw a fake topic
|
|
|
|
this.scaleImage(
|
|
|
|
this.avatar,
|
|
|
|
margin,
|
2021-08-25 17:10:12 -04:00
|
|
|
headerHeight + height * 0.09,
|
2020-08-31 06:14:09 -04:00
|
|
|
avatarSize,
|
|
|
|
avatarSize
|
|
|
|
);
|
|
|
|
|
2020-10-05 13:40:41 -04:00
|
|
|
const titleFontSize = headerHeight / 55;
|
2020-08-31 06:14:09 -04:00
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = colors.primary;
|
2020-10-05 13:40:41 -04:00
|
|
|
ctx.font = `bold ${titleFontSize}em '${headingFont}'`;
|
|
|
|
ctx.fillText(I18n.t("wizard.previews.topic_title"), margin, height * 0.3);
|
2020-08-31 06:14:09 -04:00
|
|
|
|
2020-10-05 13:40:41 -04:00
|
|
|
const bodyFontSize = height / 330.0;
|
2020-08-31 06:14:09 -04:00
|
|
|
ctx.font = `${bodyFontSize}em '${font}'`;
|
|
|
|
|
|
|
|
let line = 0;
|
|
|
|
const lines = LOREM.split("\n");
|
2020-10-05 13:40:41 -04:00
|
|
|
for (let i = 0; i < 5; i++) {
|
2020-08-31 06:14:09 -04:00
|
|
|
line = height * 0.35 + i * lineHeight;
|
|
|
|
ctx.fillText(lines[i], margin + avatarSize + margin, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Share Button
|
2020-11-05 09:55:35 -05:00
|
|
|
const shareButtonWidth = I18n.t("wizard.previews.share_button").length * 11;
|
|
|
|
|
2020-08-31 06:14:09 -04:00
|
|
|
ctx.beginPath();
|
2020-11-05 09:55:35 -05:00
|
|
|
ctx.rect(margin, line + lineHeight, shareButtonWidth, height * 0.1);
|
2022-07-26 21:23:01 -04:00
|
|
|
// accounts for hard-set color variables in solarized themes
|
|
|
|
ctx.fillStyle =
|
|
|
|
colors.primary_low ||
|
|
|
|
darkLightDiff(colors.primary, colors.secondary, 90, 65);
|
2020-08-31 06:14:09 -04:00
|
|
|
ctx.fillStyle = chooseDarker(colors.primary, colors.secondary);
|
|
|
|
ctx.font = `${bodyFontSize}em '${font}'`;
|
|
|
|
ctx.fillText(
|
|
|
|
I18n.t("wizard.previews.share_button"),
|
2020-11-05 09:55:35 -05:00
|
|
|
margin + 10,
|
2021-08-25 17:10:12 -04:00
|
|
|
line + lineHeight * 1.9
|
2020-08-31 06:14:09 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
// Reply Button
|
2020-11-05 09:55:35 -05:00
|
|
|
const replyButtonWidth = I18n.t("wizard.previews.reply_button").length * 11;
|
|
|
|
|
2020-08-31 06:14:09 -04:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.rect(
|
2020-11-05 09:55:35 -05:00
|
|
|
shareButtonWidth + margin + 10,
|
2020-08-31 06:14:09 -04:00
|
|
|
line + lineHeight,
|
2020-11-05 09:55:35 -05:00
|
|
|
replyButtonWidth,
|
|
|
|
height * 0.1
|
2020-08-31 06:14:09 -04:00
|
|
|
);
|
|
|
|
ctx.fillStyle = colors.tertiary;
|
|
|
|
ctx.fill();
|
|
|
|
ctx.fillStyle = colors.secondary;
|
|
|
|
ctx.font = `${bodyFontSize}em '${font}'`;
|
|
|
|
ctx.fillText(
|
|
|
|
I18n.t("wizard.previews.reply_button"),
|
2020-11-05 09:55:35 -05:00
|
|
|
shareButtonWidth + margin + 20,
|
2021-08-25 17:10:12 -04:00
|
|
|
line + lineHeight * 1.9
|
2020-08-31 06:14:09 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
// Draw Timeline
|
2020-10-05 13:40:41 -04:00
|
|
|
const timelineX = width * 0.86;
|
2020-08-31 06:14:09 -04:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.strokeStyle = colors.tertiary;
|
|
|
|
ctx.lineWidth = 0.5;
|
|
|
|
ctx.moveTo(timelineX, height * 0.3);
|
|
|
|
ctx.lineTo(timelineX, height * 0.7);
|
|
|
|
ctx.stroke();
|
|
|
|
|
|
|
|
// Timeline
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.strokeStyle = colors.tertiary;
|
|
|
|
ctx.lineWidth = 2;
|
|
|
|
ctx.moveTo(timelineX, height * 0.3);
|
|
|
|
ctx.lineTo(timelineX, height * 0.4);
|
|
|
|
ctx.stroke();
|
|
|
|
|
|
|
|
ctx.font = `Bold ${bodyFontSize}em ${font}`;
|
|
|
|
ctx.fillStyle = colors.primary;
|
|
|
|
ctx.fillText("1 / 20", timelineX + margin, height * 0.3 + margin * 1.5);
|
|
|
|
},
|
2021-08-25 17:10:12 -04:00
|
|
|
|
2022-06-04 13:19:49 -04:00
|
|
|
@action
|
DEV: Remove usage of {{action}} modifiers - Take 2 (#18476)
This PR enables the [`no-action-modifiers`](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-action-modifiers.md) template lint rule and removes all usages of the `{{action}}` modifier in core.
In general, instances of `{{action "x"}}` have been replaced with `{{on "click" (action "x")}}`.
In many cases, such as for `a` elements, we also need to prevent default event handling to avoid unwanted side effects. While the `{{action}}` modifier internally calls `event.preventDefault()`, we need to handle these cases more explicitly. For this purpose, this PR also adds the [ember-event-helpers](https://github.com/buschtoens/ember-event-helpers) dependency so we can use the `prevent-default` handler. For instance:
```
<a href {{on "click" (prevent-default (action "x"))}}>Do X</a>
```
Note that `action` has not in general been refactored away as a helper yet. In general, all event handlers should be methods on the corresponding component and referenced directly (e.g. `{{on "click" this.doSomething}}`). However, the `action` helper is used extensively throughout the codebase and often references methods in the `actions` hash on controllers or routes. Thus this refactor will also be extensive and probably deserves a separate PR.
Note: This work was done to complement #17767 by minimizing the potential impact of the `action` modifier override, which uses private API and arguably should be replaced with an AST transform.
This is a followup to #18333, which had to be reverted because it did not account for the default treatment of modifier keys by the {{action}} modifier.
Commits:
* Enable `no-action-modifiers` template lint rule
* Replace {{action "x"}} with {{on "click" (action "x")}}
* Remove unnecessary action helper usage
* Remove ctl+click tests for user-menu
These tests now break in Chrome when used with addEventListener. As per the comment, they can probably be safely removed.
* Prevent default event handlers to avoid unwanted side effects
Uses `event.preventDefault()` in event handlers to prevent default event handling. This had been done automatically by the `action` modifier, but is not always desirable or necessary.
* Restore UserCardContents#showUser action to avoid regression
By keeping the `showUser` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showUser` argument that's been passed.
* Revert EditCategoryTab#selectTab -> EditCategoryTab#select
Avoid potential breaking change in themes / plugins
* Restore GroupCardContents#showGroup action to avoid regression
By keeping the `showGroup` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showGroup` argument that's been passed.
* Restore SecondFactorAddTotp#showSecondFactorKey action to avoid regression
By keeping the `showSecondFactorKey` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showSecondFactorKey` property that's maintained on the controller.
* Refactor away from `actions` hash in ChooseMessage component
* Modernize EmojiPicker#onCategorySelection usage
* Modernize SearchResultEntry#logClick usage
* Modernize Discovery::Categories#showInserted usage
* Modernize Preferences::Account#resendConfirmationEmail usage
* Modernize MultiSelect::SelectedCategory#onSelectedNameClick usage
* Favor fn over action in SelectedChoice component
* Modernize WizardStep event handlers
* Favor fn over action usage in buttons
* Restore Login#forgotPassword action to avoid possible regression
* Introduce modKeysPressed utility
Returns an array of modifier keys that are pressed during a given `MouseEvent` or `KeyboardEvent`.
* Don't interfere with click events on links with `href` values when modifier keys are pressed
2022-10-05 08:08:54 -04:00
|
|
|
setPreviewHomepage(event) {
|
|
|
|
event?.preventDefault();
|
2022-06-04 13:19:49 -04:00
|
|
|
this.set("previewTopic", false);
|
|
|
|
},
|
2021-08-25 17:10:12 -04:00
|
|
|
|
2022-06-04 13:19:49 -04:00
|
|
|
@action
|
DEV: Remove usage of {{action}} modifiers - Take 2 (#18476)
This PR enables the [`no-action-modifiers`](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-action-modifiers.md) template lint rule and removes all usages of the `{{action}}` modifier in core.
In general, instances of `{{action "x"}}` have been replaced with `{{on "click" (action "x")}}`.
In many cases, such as for `a` elements, we also need to prevent default event handling to avoid unwanted side effects. While the `{{action}}` modifier internally calls `event.preventDefault()`, we need to handle these cases more explicitly. For this purpose, this PR also adds the [ember-event-helpers](https://github.com/buschtoens/ember-event-helpers) dependency so we can use the `prevent-default` handler. For instance:
```
<a href {{on "click" (prevent-default (action "x"))}}>Do X</a>
```
Note that `action` has not in general been refactored away as a helper yet. In general, all event handlers should be methods on the corresponding component and referenced directly (e.g. `{{on "click" this.doSomething}}`). However, the `action` helper is used extensively throughout the codebase and often references methods in the `actions` hash on controllers or routes. Thus this refactor will also be extensive and probably deserves a separate PR.
Note: This work was done to complement #17767 by minimizing the potential impact of the `action` modifier override, which uses private API and arguably should be replaced with an AST transform.
This is a followup to #18333, which had to be reverted because it did not account for the default treatment of modifier keys by the {{action}} modifier.
Commits:
* Enable `no-action-modifiers` template lint rule
* Replace {{action "x"}} with {{on "click" (action "x")}}
* Remove unnecessary action helper usage
* Remove ctl+click tests for user-menu
These tests now break in Chrome when used with addEventListener. As per the comment, they can probably be safely removed.
* Prevent default event handlers to avoid unwanted side effects
Uses `event.preventDefault()` in event handlers to prevent default event handling. This had been done automatically by the `action` modifier, but is not always desirable or necessary.
* Restore UserCardContents#showUser action to avoid regression
By keeping the `showUser` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showUser` argument that's been passed.
* Revert EditCategoryTab#selectTab -> EditCategoryTab#select
Avoid potential breaking change in themes / plugins
* Restore GroupCardContents#showGroup action to avoid regression
By keeping the `showGroup` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showGroup` argument that's been passed.
* Restore SecondFactorAddTotp#showSecondFactorKey action to avoid regression
By keeping the `showSecondFactorKey` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showSecondFactorKey` property that's maintained on the controller.
* Refactor away from `actions` hash in ChooseMessage component
* Modernize EmojiPicker#onCategorySelection usage
* Modernize SearchResultEntry#logClick usage
* Modernize Discovery::Categories#showInserted usage
* Modernize Preferences::Account#resendConfirmationEmail usage
* Modernize MultiSelect::SelectedCategory#onSelectedNameClick usage
* Favor fn over action in SelectedChoice component
* Modernize WizardStep event handlers
* Favor fn over action usage in buttons
* Restore Login#forgotPassword action to avoid possible regression
* Introduce modKeysPressed utility
Returns an array of modifier keys that are pressed during a given `MouseEvent` or `KeyboardEvent`.
* Don't interfere with click events on links with `href` values when modifier keys are pressed
2022-10-05 08:08:54 -04:00
|
|
|
setPreviewTopic(event) {
|
|
|
|
event?.preventDefault();
|
2022-06-04 13:19:49 -04:00
|
|
|
this.set("previewTopic", true);
|
2021-08-25 17:10:12 -04:00
|
|
|
},
|
2020-08-31 06:14:09 -04:00
|
|
|
});
|