Skip to content

A platform for community discussion. Free, open, simple.

DEV: Vendor-in built-in-components (#34488)

Jarek Radoszc1a54b1d29c4
diff --git a/app/assets/javascripts/discourse/app/components/d-textarea.js b/app/assets/javascripts/discourse/app/components/d-textarea.js
index 05decb860f7..38fc0431be6 100644
--- a/app/assets/javascripts/discourse/app/components/d-textarea.js
+++ b/app/assets/javascripts/discourse/app/components/d-textarea.js
@@ -1,5 +1,5 @@
-import { TextArea } from "@ember/legacy-built-in-components";
import { attributeBindings } from "@ember-decorators/component";
+import TextArea from "./textarea";
@attributeBindings("aria-label")
export default class DTextarea extends TextArea {}
diff --git a/app/assets/javascripts/discourse/app/components/ember-text-field.gjs b/app/assets/javascripts/discourse/app/components/ember-text-field.gjs
new file mode 100644
index 00000000000..7520e7ab757
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/ember-text-field.gjs
@@ -0,0 +1,188 @@
+/* eslint-disable ember/no-classic-components */
+/* eslint-disable ember/no-classic-classes */
+import { MUTABLE_CELL } from "@ember/-internals/views";
+import Component from "@ember/component";
+import { computed, get, set } from "@ember/object";
+
+const inputTypes = Object.create(null);
+function canSetTypeOfInput(type) {
+ if (type in inputTypes) {
+ return inputTypes[type];
+ }
+
+ let inputTypeTestElement = document.createElement("input");
+
+ try {
+ inputTypeTestElement.type = type;
+ } catch {
+ // ignored
+ }
+
+ return (inputTypes[type] = inputTypeTestElement.type === type);
+}
+
+const KEY_EVENTS = {
+ Enter: "insertNewline",
+ Escape: "cancel",
+};
+
+function sendAction(eventName, view, event) {
+ let action = get(view, `attrs.${eventName}`);
+ if (
+ action !== null &&
+ typeof action === "object" &&
+ action[MUTABLE_CELL] === true
+ ) {
+ action = action.value;
+ }
+
+ if (action === undefined) {
+ action = get(view, eventName);
+ }
+
+ let value = view.value;
+
+ if (typeof action === "function") {
+ action(value, event);
+ }
+
+ if (action && !view.bubbles) {
+ event.stopPropagation();
+ }
+}
+
+const TextField = Component.extend({
+ classNames: ["ember-text-field"],
+ tagName: "input",
+
+ attributeBindings: [
+ "accept",
+ "autocomplete",
+ "autosave",
+ "dir",
+ "formaction",
+ "formenctype",
+ "formmethod",
+ "formnovalidate",
+ "formtarget",
+ "height",
+ "inputmode",
+ "lang",
+ "list",
+ "type", // needs to be before min and max. See #15675
+ "max",
+ "min",
+ "multiple",
+ "name",
+ "pattern",
+ "size",
+ "step",
+ "value",
+ "width",
+ "autocapitalize",
+ "autocorrect",
+ "autofocus",
+ "disabled",
+ "form",
+ "maxlength",
+ "minlength",
+ "placeholder",
+ "readonly",
+ "required",
+ "selectionDirection",
+ "spellcheck",
+ "tabindex",
+ "title",
+ ],
+
+ value: "",
+
+ type: computed({
+ get() {
+ return "text";
+ },
+
+ set(_key, value) {
+ let type = "text";
+
+ if (canSetTypeOfInput(value)) {
+ type = value;
+ }
+
+ return type;
+ },
+ }),
+
+ size: null,
+
+ pattern: null,
+
+ min: null,
+
+ max: null,
+
+ placeholder: null,
+ disabled: false,
+ maxlength: null,
+
+ init() {
+ this._super(...arguments);
+ this.on("paste", this, this._elementValueDidChange);
+ this.on("cut", this, this._elementValueDidChange);
+ this.on("input", this, this._elementValueDidChange);
+ },
+
+ bubbles: false,
+
+ interpretKeyEvents(event) {
+ let method = KEY_EVENTS[event.key];
+
+ this._elementValueDidChange();
+ if (method) {
+ return this[method](event);
+ }
+ },
+
+ _elementValueDidChange() {
+ set(this, "value", this.element.value);
+ },
+
+ change(event) {
+ this._elementValueDidChange(event);
+ },
+
+ insertNewline(event) {
+ sendAction("enter", this, event);
+ sendAction("insert-newline", this, event);
+ },
+
+ cancel(event) {
+ sendAction("escape-press", this, event);
+ },
+
+ focusIn(event) {
+ sendAction("focus-in", this, event);
+ },
+
+ focusOut(event) {
+ this._elementValueDidChange(event);
+ sendAction("focus-out", this, event);
+ },
+
+ keyPress(event) {
+ sendAction("key-press", this, event);
+ },
+
+ keyUp(event) {
+ this.interpretKeyEvents(event);
+ sendAction("key-up", this, event);
+ },
+
+ keyDown(event) {
+ sendAction("key-down", this, event);
+ },
+});
+
+TextField.toString = () => "@ember/component/text-field";
+
+export default TextField;
diff --git a/app/assets/javascripts/discourse/app/components/text-field.js b/app/assets/javascripts/discourse/app/components/text-field.js
index c382a3a69ff..3802294dbea 100644
--- a/app/assets/javascripts/discourse/app/components/text-field.js
+++ b/app/assets/javascripts/discourse/app/components/text-field.js
@@ -1,9 +1,9 @@
-import { TextField } from "@ember/legacy-built-in-components";
import { computed } from "@ember/object";
import { cancel, next } from "@ember/runloop";
import { attributeBindings } from "@ember-decorators/component";
import discourseDebounce from "discourse/lib/debounce";
import { i18n } from "discourse-i18n";
+import TextField from "./ember-text-field";
const DEBOUNCE_MS = 500;
diff --git a/app/assets/javascripts/discourse/app/components/textarea.gjs b/app/assets/javascripts/discourse/app/components/textarea.gjs
new file mode 100644
index 00000000000..eb4f952c04a
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/textarea.gjs
@@ -0,0 +1,136 @@
+/* eslint-disable ember/no-classic-components */
+import { MUTABLE_CELL } from "@ember/-internals/views";
+import Component from "@ember/component";
+import { get, set } from "@ember/object";
+
+const KEY_EVENTS = {
+ Enter: "insertNewline",
+ Escape: "cancel",
+};
+
+function sendAction(eventName, view, event) {
+ let action = get(view, `attrs.${eventName}`);
+ if (
+ action !== null &&
+ typeof action === "object" &&
+ action[MUTABLE_CELL] === true
+ ) {
+ action = action.value;
+ }
+
+ if (action === undefined) {
+ action = get(view, eventName);
+ }
+
+ let value = view.value;
+
+ if (typeof action === "function") {
+ action(value, event);
+ }
+
+ if (action && !view.bubbles) {
+ event.stopPropagation();
+ }
+}
+
+// eslint-disable-next-line ember/no-classic-classes
+const TextArea = Component.extend({
+ classNames: ["ember-text-area"],
+
+ tagName: "textarea",
+ attributeBindings: [
+ "rows",
+ "cols",
+ "name",
+ "selectionEnd",
+ "selectionStart",
+ "autocomplete",
+ "wrap",
+ "lang",
+ "dir",
+ "value",
+ "autocapitalize",
+ "autocorrect",
+ "autofocus",
+ "disabled",
+ "form",
+ "maxlength",
+ "minlength",
+ "placeholder",
+ "readonly",
+ "required",
+ "selectionDirection",
+ "spellcheck",
+ "tabindex",
+ "title",
+ ],
+ rows: null,
+ cols: null,
+
+ value: "",
+
+ placeholder: null,
+ disabled: false,
+ maxlength: null,
+
+ init() {
+ this._super(...arguments);
+ this.on("paste", this, this._elementValueDidChange);
+ this.on("cut", this, this._elementValueDidChange);
+ this.on("input", this, this._elementValueDidChange);
+ },
+
+ bubbles: false,
+
+ interpretKeyEvents(event) {
+ let method = KEY_EVENTS[event.key];
+
+ this._elementValueDidChange();
+ if (method) {
+ return this[method](event);
+ }
+ },
+
+ _elementValueDidChange() {
+ set(this, "value", this.element.value);
+ },
+
+ change(event) {
+ this._elementValueDidChange(event);
+ },
+
+ insertNewline(event) {
+ sendAction("enter", this, event);
+ sendAction("insert-newline", this, event);
+ },
+
+ cancel(event) {
+ sendAction("escape-press", this, event);
+ },
+
+ focusIn(event) {
+ sendAction("focus-in", this, event);
+ },
+
+ focusOut(event) {
+ this._elementValueDidChange(event);
+ sendAction("focus-out", this, event);
+ },
+
+ keyPress(event) {
+ sendAction("key-press", this, event);
+ },
+
+ keyUp(event) {
+ this.interpretKeyEvents(event);
+ sendAction("key-up", this, event);
+ },
+
+ keyDown(event) {
+ sendAction("key-down", this, event);
+ },
+});
+
+TextArea.toString = () => "@ember/component/text-area";
+
+export default TextArea;
diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json
index 275157c6a66..98cd080c4d6 100644
--- a/app/assets/javascripts/discourse/package.json
+++ b/app/assets/javascripts/discourse/package.json
@@ -66,7 +66,6 @@
"@colors/colors": "^1.6.0",
"@discourse/itsatrap": "^2.0.10",
"@ember-compat/tracked-built-ins": "^0.9.1",
- "@ember/legacy-built-in-components": "^0.5.0",
"@ember/optional-features": "^2.2.0",
"@ember/render-modifiers": "^3.0.0",
"@ember/string": "^4.0.1",
diff --git a/plugins/automation/admin/assets/javascripts/admin/components/fields/da-message-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-message-field.gjs
index 1a59a09e15f..114db076006 100644
--- a/plugins/automation/admin/assets/javascripts/admin/components/fields/da-message-field.gjs
+++ b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-message-field.gjs
@@ -1,5 +1,5 @@
-import { TextArea } from "@ember/legacy-built-in-components";
import { action } from "@ember/object";
+import TextArea from "discourse/components/textarea";
import PlaceholdersList from "../placeholders-list";
import BaseField from "./da-base-field";
import DAFieldDescription from "./da-field-description";
diff --git a/plugins/discourse-assign/assets/javascripts/discourse/components/assignment.gjs b/plugins/discourse-assign/assets/javascripts/discourse/components/assignment.gjs
index 666b8a96dd5..04bd890be69 100644
--- a/plugins/discourse-assign/assets/javascripts/discourse/components/assignment.gjs
+++ b/plugins/discourse-assign/assets/javascripts/discourse/components/assignment.gjs
@@ -1,10 +1,10 @@
import Component from "@glimmer/component";
import { hash } from "@ember/helper";
-import { TextArea } from "@ember/legacy-built-in-components";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { service } from "@ember/service";
import { not } from "truth-helpers";
+import TextArea from "discourse/components/textarea";
import icon from "discourse/helpers/d-icon";
import { i18n } from "discourse-i18n";
import ComboBox from "select-kit/components/combo-box";
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6f2436dca21..e1ad2c26388 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -396,9 +396,6 @@ importers:
'@ember-compat/tracked-built-ins':
specifier: ^0.9.1
version: 0.9.1(patch_hash=s67qh4jsmpbr3llstdi3a5zeze)
- '@ember/legacy-built-in-components':
- specifier: ^0.5.0
- version: 0.5.0(@glint/[email protected])([email protected](patch_hash=pqnuctuxbp6ekxyjszyhrgmysm)(@glimmer/[email protected](@babel/[email protected]))(@glint/[email protected])([email protected])([email protected](@swc/[email protected])([email protected])))
'@ember/optional-features':
specifier: ^2.2.0
version: 2.2.0
@@ -1843,12 +1840,6 @@ packages:
resolution: {integrity: sha512-VmVq/8saCaPdesQmftPqbFtxJWrzxNGSQ+e8x8LLe3Hjm36pJ04Q8LeORGZkAeOhldoUX9seLGmSaHeXkIqoog==}
- '@ember/[email protected]':
- resolution: {integrity: sha512-hbUCt5rii6CT1L4mheH+aqCDeF1dzp/UjS2g7KFIKYGd9zMqyKU4OEnQGk2/O5tATXkEGPf4Zpj671BddBOrbQ==}
- engines: {node: '>= 16'}
- peerDependencies:
- ember-source: '>= 4.8'
-
resolution: {integrity: sha512-a1OQ+w9vDvMXd9BNA9r779yr8MAPguGaMGbIeTMPWACeWBdD6bACBB5iKE3gNyrJAYKMq2wab6BKmRFS3Qw3hw==}
engines: {node: 10.* || 12.* || >= 14}
@@ -4623,10 +4614,6 @@ packages:
resolution: {integrity: sha512-lo5YArbJzJi5ssvaGqTt6+FnhTALnSvYVuxM7lfyL1UCMudyNJ94ovH5C7n5il7ATd6WsNiAPRUO/v+s5Jq/aA==}
engines: {node: 8.* || >= 10.*}
- resolution: {integrity: sha512-0iKTZ+/wH6UB/VTWKvGuXlmwiE8HSIGcxHamwNhEC5x1mN3z8RfvsFZdQWYUzIWFN2Tek0gmepGRPTwWdBYl/A==}
- engines: {node: 10.* || >= 12.*}
-
resolution: {integrity: sha512-gFA+ZwmsvvFwo2Jz/B9GMduEn+fPoGb69qWGP0Tp3+Tu5xypDtIKVSZ5086I3Cr19cLXD4HkrOR3YQvdUKzAkQ==}
engines: {node: '>= 12.*'}
@@ -10202,17 +10189,6 @@ snapshots:
'@ember/[email protected]': {}
- dependencies:
- '@embroider/macros': 1.16.12(@glint/[email protected])
- ember-cli-babel: 7.26.11
- ember-cli-htmlbars: 5.7.2
- ember-cli-typescript: 4.2.1
- ember-source: 5.12.0(patch_hash=pqnuctuxbp6ekxyjszyhrgmysm)(@glimmer/[email protected](@babel/[email protected]))(@glint/[email protected])([email protected])([email protected](@swc/[email protected])([email protected]))
- transitivePeerDependencies:
- - '@glint/template'
- - supports-color
-
dependencies:
chalk: 4.1.2
@@ -13627,21 +13603,6 @@ snapshots:
- '@babel/core'
- supports-color
- dependencies:
- ansi-to-html: 0.6.15
- broccoli-stew: 3.0.0
- debug: 4.4.1([email protected])
- execa: 4.1.0
- fs-extra: 9.1.0
- resolve: 1.22.10
- rsvp: 4.8.5
- semver: 7.7.2
- stagehand: 1.0.1
- walk-sync: 2.2.0
- transitivePeerDependencies:
- - supports-color
-
dependencies:
ansi-to-html: 0.6.15