A platform for community discussion. Free, open, simple.
FEATURE: inline event editor for the rich editor (#36675)
Renato Atilio12429ac36590
diff --git a/frontend/discourse/app/components/expanding-text-area.gjs b/frontend/discourse/app/components/expanding-text-area.gjsindex ea9e2151c37..bd461475d12 100644--- a/frontend/discourse/app/components/expanding-text-area.gjs+++ b/frontend/discourse/app/components/expanding-text-area.gjs@@ -1,27 +1,84 @@+import Component from "@glimmer/component";import { on } from "@ember/modifier";-import autosize from "autosize";-import { modifier as modifierFn } from "ember-modifier";+import { action } from "@ember/object";+import { modifier } from "ember-modifier";import autoFocus from "discourse/modifiers/auto-focus";-const resize = modifierFn((element) => {- autosize(element);- return () => autosize.destroy(element);-});--const ExpandingTextArea = <template>- <textarea- {{autoFocus}}- {{resize}}- {{! deprecated args: }}- autocorrect={{@autocorrect}}- class={{@class}}- maxlength={{@maxlength}}- name={{@name}}- rows={{@rows}}- value={{@value}}- {{(if @input (modifier on "input" @input))}}- ...attributes- ></textarea>-</template>;--export default ExpandingTextArea;+export default class ExpandingTextArea extends Component {+ setTextarea = modifier((element) => {+ this.#textarea = element;++ const placeholderObserver = new MutationObserver((mutations) => {+ mutations.forEach((mutation) => {+ if (+ mutation.type === "attributes" &&+ mutation.attributeName === "placeholder"+ ) {+ this.autoResize();+ }+ });+ });++ placeholderObserver.observe(element, {+ attributes: true,+ attributeFilter: ["placeholder"],+ });++ const handleResize = () => this.autoResize();+ window.addEventListener("resize", handleResize);++ this.autoResize();++ return () => {+ placeholderObserver.disconnect();+ window.removeEventListener("resize", handleResize);+ this.#textarea = null;+ };+ });++ #textarea;++ @action+ autoResize() {+ setTimeout(() => {+ if (!this.#textarea) {+ return;+ }++ this.#textarea.style.height = "auto";+ this.#textarea.style.height = this.#textarea.scrollHeight + "px";++ // Get the max-height value from CSS (30vh)+ const maxHeight = parseInt(+ getComputedStyle(this.#textarea).maxHeight,+ 10+ );++ // Only enable scrolling if content exceeds max-height+ if (this.#textarea.scrollHeight > maxHeight) {+ this.#textarea.style.overflowY = "auto";+ } else {+ this.#textarea.style.overflowY = "hidden";+ }+ }, 50);+ }++ <template>+ <textarea+ {{this.setTextarea}}+ {{(if @autoFocus autoFocus)}}+ {{! deprecated args: }}+ autocorrect={{@autocorrect}}+ class={{@class}}+ maxlength={{@maxlength}}+ name={{@name}}+ rows={{@rows}}+ value={{@value}}+ {{(if @input (modifier on "input" @input))}}+ {{on "input" this.autoResize}}+ {{on "focus" this.autoResize}}+ {{on "blur" this.autoResize}}+ ...attributes+ ></textarea>+ </template>+}diff --git a/frontend/discourse/app/lib/composer/rich-editor-extensions.js b/frontend/discourse/app/lib/composer/rich-editor-extensions.jsindex 81cc9b56706..04150df20c9 100644--- a/frontend/discourse/app/lib/composer/rich-editor-extensions.js+++ b/frontend/discourse/app/lib/composer/rich-editor-extensions.js@@ -119,8 +119,8 @@* Markdown-it token parse definition* @property {PluginsProperty} [plugins]* ProseMirror plugins - can be a function returning plugin spec or plugin spec object- * @property {Record<string, NodeViewConstructor | ((params: PluginParams) => NodeViewConstructor)>} [nodeViews]- * ProseMirror node views - can be direct NodeView constructors or functions that take params and return constructors+ * @property {Record<string, NodeViewConstructor | ((params: PluginParams) => NodeViewConstructor) | { component: any, name?: string }>} [nodeViews]+ * ProseMirror node views. Can be a NodeViewConstructor or an object with { component, name } for automatic Glimmer component wrapping* @property {RichKeymap} [keymap]* Additional keymap definitions* @property {(params: PluginParams) => Record<string, import('prosemirror-state').Command>} [commands]diff --git a/frontend/discourse/app/static/prosemirror/core/plugin.js b/frontend/discourse/app/static/prosemirror/core/plugin.jsindex 3a9dfc01ced..98e80ad312f 100644--- a/frontend/discourse/app/static/prosemirror/core/plugin.js+++ b/frontend/discourse/app/static/prosemirror/core/plugin.js@@ -1,7 +1,8 @@import { Plugin } from "prosemirror-state";+import GlimmerNodeView from "../lib/glimmer-node-view";/*- There are 3 ways to define a node view:+ There are 4 ways to define a node view:Setting a node view class directly (e.g. code-block)`nodeViews: { nodeName: NodeViewClass }`@@ -11,6 +12,9 @@ import { Plugin } from "prosemirror-state";Setting a node view instance as returned by a function, when plugin params are needed (e.g. image)`nodeViews: { nodeName: (pluginParams) => (...args) => nodeViewInstance }`++ Setting a Glimmer component with auto-wrapping (new)+ `nodeViews: { nodeName: { component: GlimmerComponent, name: "nodeName" } }`*/export function extractNodeViews(extensions, pluginParams) {/** @type {Record<string, import('prosemirror-view').NodeViewConstructor>} */@@ -18,6 +22,21 @@ export function extractNodeViews(extensions, pluginParams) {for (const { nodeViews } of extensions) {if (nodeViews) {for (let [name, nodeView] of Object.entries(nodeViews)) {+ // Check if nodeView is a Glimmer component descriptor+ if (nodeView && typeof nodeView === "object" && nodeView.component) {+ allNodeViews[name] = (node, view, getPos) => {+ return new GlimmerNodeView({+ node,+ view,+ getPos,+ getContext: pluginParams.getContext,+ component: nodeView.component,+ name: nodeView.name || name,+ });+ };+ continue;+ }+// node view can be a function, to which we pass pluginParamsif (!nodeView.toString().startsWith("class")) {nodeView = nodeView(pluginParams);diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjsindex 64482295179..f2fd3f50221 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs@@ -190,6 +190,48 @@ export default class DiscoursePostEventMoreMenu extends Component {this.modal.show(PostEventBuilder, {model: {event: this.args.event,+ onDelete: async (event) => {+ const post = await this.store.find("post", event.id);+ const raw = post.raw;++ const eventRegex = new RegExp(+ `\\[event\\s(.*?)\\]\\n\\[\\/event\\]`,+ "m"+ );+ const newRaw = raw.replace(eventRegex, "");++ const props = {+ raw: newRaw,+ edit_reason: i18n("discourse_post_event.destroy_event"),+ };++ const cooked = await cook(newRaw);+ props.cooked = cooked.string;++ return await post.save(props);+ },+ onUpdate: async (startsAt, endsAt, event, siteSettings) => {+ const post = await this.store.find("post", event.id);+ const raw = post.raw;+ const eventParams = buildParams(+ startsAt,+ endsAt,+ event,+ siteSettings+ );+ const newRaw = replaceRaw(eventParams, raw);+ if (newRaw) {+ const props = {+ raw: newRaw,+ edit_reason: i18n("discourse_post_event.edit_reason"),+ };++ const cooked = await cook(newRaw);+ props.cooked = cooked.string;++ return await post.save(props);+ }+ },},});}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjsnew file mode 100644index 00000000000..a541c9df2d2--- /dev/null+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjs@@ -0,0 +1,644 @@+import Component from "@glimmer/component";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+import { next } from "@ember/runloop";+import { service } from "@ember/service";+import DButton from "discourse/components/d-button";+import ExpandingTextArea from "discourse/components/expanding-text-area";+import concatClass from "discourse/helpers/concat-class";+import icon from "discourse/helpers/d-icon";+import { i18n } from "discourse-i18n";+import PostEventBuilder from "discourse/plugins/discourse-calendar/discourse/components/modal/post-event-builder";+import guessDateFormat from "discourse/plugins/discourse-calendar/discourse/lib/guess-best-date-format";+import {+ buildParams,+ camelCase,+} from "discourse/plugins/discourse-calendar/discourse/lib/raw-event-helper";+import DiscoursePostEventEvent from "discourse/plugins/discourse-calendar/discourse/models/discourse-post-event-event";++export default class EventNodeView extends Component {+ @service composer;+ @service currentUser;+ @service modal;+ @service siteSettings;+ @service capabilities;++ constructor() {+ super(...arguments);+ this.args.onSetup?.(this);+ }++ updateNodeAttribute(attributeName, value) {+ if (!this.args.getPos || !this.args.view) {+ return;+ }++ // Schedule the update on the next runloop to avoid Ember tracking conflicts+ next(() => {+ const { view } = this.args;+ const pos = this.args.getPos();+ const node = view.state.doc.nodeAt(pos);++ if (!node) {+ return;+ }++ const newAttrs = { ...node.attrs, [attributeName]: value };+ const tr = view.state.tr.setNodeMarkup(pos, null, newAttrs);+ view.dispatch(tr);+ });+ }++ updateNodeContent(content) {+ if (!this.args.getPos || !this.args.view) {+ return;+ }++ next(() => {+ const { view } = this.args;+ const pos = this.args.getPos();+ const node = view.state.doc.nodeAt(pos);++ if (!node) {+ return;+ }++ const tr = view.state.tr;+ const startPos = pos + 1; // Start inside the node+ const endPos = pos + node.nodeSize - 1; // End inside the node++ // Replace the content+ if (content.trim()) {+ const textNode = view.state.schema.text(content);+ tr.replaceWith(startPos, endPos, textNode);+ } else {+ // Clear content if empty+ tr.delete(startPos, endPos);+ }++ view.dispatch(tr);+ });+ }++ get eventData() {+ return this.args.node.attrs;+ }++ get eventDescription() {+ return this.args.view.state.doc.textBetween(+ this.args.getPos() + 1,+ this.args.getPos() + this.args.node.nodeSize - 1,+ "\n",+ "\n"+ );+ }++ get resolvedTimezone() {+ return this.eventData.timezone || "UTC";+ }++ get userTimezone() {+ return this.currentUser?.user_option?.timezone || moment.tz.guess();+ }++ parseDateWithTimezone(dateString) {+ if (!dateString) {+ return null;+ }++ const date = moment.tz(dateString, this.resolvedTimezone);++ if (!date.isValid()) {+ return moment.tz(this.userTimezone);+ }++ return date;+ }++ get startsAt() {+ return this.parseDateWithTimezone(this.eventData.start);+ }++ get endsAt() {+ return this.parseDateWithTimezone(this.eventData.end);+ }++ get displayTime() {+ if (!this.startsAt) {+ return null;+ }++ if (this.eventData.showLocalTime) {+ return this.startsAt;+ } else {+ return this.startsAt.tz(this.userTimezone);+ }+ }++ get displayEndTime() {+ if (!this.endsAt) {+ return null;+ }++ if (this.eventData.showLocalTime) {+ return this.endsAt;+ } else {+ return this.endsAt.tz(this.userTimezone);+ }+ }++ get dateFormat() {+ return guessDateFormat(this.startsAt, this.endsAt);+ }++ get formattedStartDate() {+ return this.displayTime.format(this.dateFormat);+ }++ get hasStartDate() {+ return this.eventData.start && this.eventData.start.trim();+ }++ get hasEndDate() {+ return this.eventData.end && this.eventData.end.trim();+ }++ get hasAnyDate() {+ return this.hasStartDate || this.hasEndDate;+ }++ get formattedEndDate() {+ if (!this.displayEndTime) {+ return "";+ }+ return this.displayEndTime.format(this.dateFormat);+ }++ get formattedStartDisplay() {+ return this.displayTime.format(i18n("dates.long_no_year"));+ }++ get formattedEndDisplay() {+ if (!this.displayEndTime) {+ return i18n("discourse_post_event.composer.end_date_placeholder");+ }+ return this.displayEndTime.format(i18n("dates.long_no_year"));+ }++ get startsAtMonth() {+ if (!this.displayTime) {+ // Show current month if no start date is set+ const now = moment.tz(this.userTimezone);+ return now.format("MMM");+ }+ return this.displayTime.format("MMM");+ }++ get startsAtDay() {+ if (!this.displayTime) {+ // Show current day if no start date is set+ const now = moment.tz(this.userTimezone);+ return now.format("D");+ }+ return this.displayTime.format("D");+ }++ get statusText() {+ return i18n(+ `discourse_post_event.models.event.status.${this.eventData.status || "public"}.title`+ );+ }++ get eventName() {+ return this.eventData.name;+ }++ get eventNamePlaceholder() {+ return this.composer?.get("model.title") || "Event";+ }++ get hasLocation() {+ return this.eventData.location && this.eventData.location.trim();+ }++ get isLocationUrl() {+ if (!this.hasLocation) {+ return false;+ }+ const location = this.eventData.location.trim();+ return (+ location.includes("://") ||+ location.includes("mailto:") ||+ location.startsWith("www.") ||+ /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(location)+ );+ }++ get locationIcon() {+ return this.isLocationUrl ? "link" : "location-pin";+ }++ get displayLocation() {+ if (!this.hasLocation) {+ return null;+ }+ if (this.isLocationUrl) {+ const location = this.eventData.location.trim();+ // Add protocol if missing for proper links+ if (+ location.startsWith("www.") ||+ /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(location)+ ) {+ return location.includes("://") || location.includes("mailto:")+ ? location+ : `https://${location}`;+ }+ return location;+ }+ return this.eventData.location;+ }++ get hasDescription() {+ return this.eventDescription && this.eventDescription.length > 0;+ }++ get formattedStartTime() {+ if (!this.displayTime) {+ const now = moment.tz(this.userTimezone);+ return now.format("HH:mm");+ }+ return this.displayTime.format("HH:mm");+ }++ get formattedEndTime() {+ if (!this.displayEndTime) {+ return "";+ }+ return this.displayEndTime.format("HH:mm");+ }++ formatDateTimeLocal(dateString) {+ if (!dateString) {+ return "";+ }++ const date = moment(dateString);+ if (!date.isValid()) {+ if (dateString.trim()) {+ const today = moment.tz(this.userTimezone);+ return today.format("YYYY-MM-DDTHH:mm");+ }+ return "";+ }+ return date.format("YYYY-MM-DDTHH:mm");+ }++ get formattedStartDateTime() {+ return this.formatDateTimeLocal(this.eventData.start);+ }++ get formattedEndDateTime() {+ return this.formatDateTimeLocal(this.eventData.end);+ }++ @action+ updateEventName(event) {+ event.target.value = event.target.value.replace(/\n/g, "");+ const newName = event.target.value.trim();+ this.updateNodeAttribute("name", newName);+ }++ @action+ updateEventLocation(event) {+ const newLocation = event.target.value.trim();+ this.updateNodeAttribute("location", newLocation || null);+ }++ @action+ updateEventDescription(event) {+ const newDescription = event.target.value.trim();+ this.updateNodeContent(newDescription);+ }++ @action+ updateEventStartDate(event) {+ const newDateTime = event.target.value;+ const eventTz = this.eventData.timezone || "UTC";+ if (newDateTime) {+ const dt = moment.tz(newDateTime, eventTz);+ this.updateNodeAttribute("start", dt.format("YYYY-MM-DD HH:mm"));+ } else {+ this.updateNodeAttribute(+ "start",+ moment().tz(eventTz).format("YYYY-MM-DD HH:mm")+ );+ }+ }++ @action+ updateEventEndDate(event) {+ const newDateTime = event.target.value;+ const eventTz = this.eventData.timezone || "UTC";+ if (newDateTime) {+ const dt = moment.tz(newDateTime, eventTz);+ this.updateNodeAttribute("end", dt.format("YYYY-MM-DD HH:mm"));+ } else {+ this.updateNodeAttribute("end", null);+ }+ }++ /**+ * Parses reminder string back to array format for DiscoursePostEventEvent+ * @param {string|Array} reminders - Either comma-separated string or array+ * @returns {Array} Array of reminder objects+ */+ parseReminders(reminders) {+ if (!reminders) {+ return [];+ }++ // If it's already an array, return as-is+ if (Array.isArray(reminders)) {+ return reminders;+ }++ // Parse string format: "type.value.unit,type.value.unit"+ return reminders.split(",").map((reminderStr) => {+ const [type, value, unit] = reminderStr.split(".");+ const numericValue = Math.abs(parseInt(value, 10));++ return {+ type: type || "notification",+ value: numericValue,+ unit: unit || "hours",+ period: parseInt(value, 10) < 0 ? "after" : "before",+ };+ });+ }++ /**+ * Reconstructs customFields object from individual node attributes+ * @returns {Object} Custom fields object+ */+ parseCustomFields() {+ const customFields = {};+ const allowedCustomFields =+ this.siteSettings.discourse_post_event_allowed_custom_fields+ .split("|")+ .filter(Boolean);++ // Convert each custom field back from camelCase to original name+ allowedCustomFields.forEach((fieldName) => {+ const camelCaseName = camelCase(fieldName);+ if (typeof this.eventData[camelCaseName] !== "undefined") {+ customFields[fieldName] = this.eventData[camelCaseName];+ }+ });++ return customFields;+ }++ @action+ updateEventMaxAttendees(event) {+ const newMax = parseInt(event.target.value, 10);+ const validMax = Number.isFinite(newMax) && newMax > 0 ? newMax : null;+ event.target.value = validMax || "";+ this.updateNodeAttribute("maxAttendees", validMax);+ }++ @action+ focusDateInput(event) {+ next(() => event.target.showPicker());+ }++ @action+ handleTextInputFocus(event) {+ if (this.capabilities.isIOS) {+ setTimeout(() => {+ event.target.scrollIntoView({ block: "center", behavior: "smooth" });+ }, 400);+ }+ }++ convertNodeToEvent() {+ const timezone = this.eventData.timezone || "UTC";++ return {+ name: this.eventData.name,+ location: this.eventData.location,+ description: this.eventDescription,+ timezone,+ status: this.eventData.status || "public",+ max_attendees: this.eventData.maxAttendees,+ show_local_time: this.eventData.showLocalTime,+ chat_enabled: this.eventData.chatEnabled,+ minimal: this.eventData.minimal,+ reminders: this.parseReminders(this.eventData.reminders) || [],+ raw_invitees: this.eventData.allowedGroups?.split(",") || [],+ custom_fields: this.parseCustomFields(),+ starts_at: this.eventData.start+ ? moment(this.eventData.start).tz(timezone)+ : moment.tz(timezone),+ ends_at: this.eventData.end+ ? moment(this.eventData.end).tz(timezone)+ : null,+ };+ }++ @action+ openEventBuilder() {+ const eventData = this.convertNodeToEvent();++ this.modal.show(PostEventBuilder, {+ model: {+ event: DiscoursePostEventEvent.create(eventData),+ onDelete: () => {+ // Remove the event node from the document+ if (!this.args.getPos || !this.args.view) {+ return;+ }++ const { view } = this.args;+ const pos = this.args.getPos();+ const node = view.state.doc.nodeAt(pos);++ if (!node) {+ return;+ }++ const tr = view.state.tr.delete(pos, pos + node.nodeSize);+ view.dispatch(tr);++ return true;+ },+ onUpdate: (startsAt, endsAt, event) => {+ // Use buildParams to get properly formatted parameters including reminders+ const params = buildParams(+ startsAt,+ endsAt,+ event,+ this.siteSettings+ );++ // Update node attributes with the built parameters+ for (const [field, value] of Object.entries(params)) {+ if (field === "description") {+ this.updateNodeContent(value);+ } else {+ this.updateNodeAttribute(field, value);+ }+ }+ },+ },+ });+ }++ selectNode() {+ this.args.dom.classList.add("ProseMirror-selectednode");+ }++ deselectNode() {+ this.args.dom.classList.remove("ProseMirror-selectednode");+ }++ stopEvent(event) {+ return event.target.matches("input, textarea, button");+ }++ <template>+ <header class="composer-event__header">+ <div class="composer-event__date">+ <div class="composer-event__month">{{this.startsAtMonth}}</div>+ <div class="composer-event__day">{{this.startsAtDay}}</div>+ </div>++ <div class="composer-event__info">+ <ExpandingTextArea+ rows="1"+ value={{this.eventName}}+ class="composer-event__name-input"+ placeholder={{this.eventNamePlaceholder}}+ {{on "input" this.updateEventName}}+ {{on "focus" this.handleTextInputFocus}}+ />++ <div class="composer-event__status">+ {{this.statusText}}+ </div>+ </div>++ <div class="composer-event__more-dropdown">+ <DButton+ @icon="gear"+ @action={{this.openEventBuilder}}+ @title="discourse_post_event.edit_event"+ class="btn-flat"+ />+ </div>+ </header>++ <section class="composer-event__dates">+ {{icon "clock"}}+ <div+ class="composer-event__date-range{{if+ this.hasAnyDate+ ' composer-event__date-range--has-values'+ }}"+ >+ <div class="composer-event__date-wrapper">+ <input+ type="datetime-local"+ value={{this.formattedStartDateTime}}+ class="composer-event__date-input"+ {{on "change" this.updateEventStartDate}}+ {{on "focus" this.focusDateInput}}+ />+ <span class="composer-event__date-display">+ {{this.formattedStartDisplay}}+ </span>+ </div>+ <span class="composer-event__date-separator">-</span>+ <div class="composer-event__date-wrapper">+ <input+ type="datetime-local"+ value={{this.formattedEndDateTime}}+ class="composer-event__date-input"+ {{on "change" this.updateEventEndDate}}+ {{on "focus" this.focusDateInput}}+ />+ <span+ class={{concatClass+ "composer-event__date-display"+ (unless this.hasEndDate "--empty")+ }}+ >+ {{this.formattedEndDisplay}}+ </span>+ </div>+ </div>+ </section>++ <section class="composer-event__location">+ {{icon this.locationIcon}}+ <div class="composer-event__location-content">+ <input+ type="text"+ value={{this.eventData.location}}+ class="composer-event__location-input"+ placeholder={{i18n+ "discourse_post_event.composer.location_placeholder"+ }}+ {{on "input" this.updateEventLocation}}+ {{on "focus" this.handleTextInputFocus}}+ />+ {{#if this.isLocationUrl}}+ <a+ class="composer-event__location-external-link"+ href={{this.displayLocation}}+ target="_blank"+ rel="noopener noreferrer"+ title="Visit {{this.eventData.location}}"+ >+ {{icon "up-right-from-square"}}+ </a>+ {{/if}}+ </div>+ </section>++ <section class="composer-event__attendees">+ {{icon "users"}}+ <input+ type="number"+ inputmode="numeric"+ min="1"+ step="1"+ value={{this.eventData.maxAttendees}}+ placeholder={{i18n+ "discourse_post_event.composer.max_attendees_placeholder"+ }}+ class="composer-event__max-attendees-input"+ {{on "input" this.updateEventMaxAttendees}}+ />+ {{#if this.eventData.maxAttendees}}+ <span class="composer-event__max-attendees-display">+ Max+ {{this.eventData.maxAttendees}}+ attendees+ </span>+ {{/if}}+ </section>++ <section class="composer-event__description">+ <ExpandingTextArea+ class="composer-event__description-textarea"+ placeholder={{i18n+ "discourse_post_event.composer.description_placeholder"+ }}+ value={{this.eventDescription}}+ rows="1"+ {{on "input" this.updateEventDescription}}+ {{on "focus" this.handleTextInputFocus}}+ />+ </section>+ </template>+}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjsindex ae638084107..9ce8bbec070 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs@@ -14,19 +14,17 @@ import PluginOutlet from "discourse/components/plugin-outlet";import RadioButton from "discourse/components/radio-button";import lazyHash from "discourse/helpers/lazy-hash";import { extractError } from "discourse/lib/ajax-error";-import { cook } from "discourse/lib/text";import Group from "discourse/models/group";import ComboBox from "discourse/select-kit/components/combo-box";import TimezoneInput from "discourse/select-kit/components/timezone-input";import { eq } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";-import { buildParams, replaceRaw } from "../../lib/raw-event-helper";+import { buildParams } from "../../lib/raw-event-helper";import EventField from "../event-field";export default class PostEventBuilder extends Component {@service dialog;@service siteSettings;- @service store;@service currentUser;@tracked flash = null;@@ -42,6 +40,10 @@ export default class PostEventBuilder extends Component {this.event.endsAt &&moment(this.event.endsAt).tz(this.event.timezone || "UTC");+ get isEditing() {+ return this.args.model.event.id || this.args.model.onUpdate;+ }+get recurrenceUntil() {return (this.event.recurrenceUntil &&@@ -293,18 +295,7 @@ export default class PostEventBuilder extends Component {});if (confirmResult) {- const post = await this.store.find("post", this.event.id);- const raw = post.raw;- const newRaw = this._removeRawEvent(raw);- const props = {- raw: newRaw,- edit_reason: "Destroy event",- };-- const cooked = await cook(newRaw);- props.cooked = cooked.string;-- const result = await post.save(props);+ const result = await this.args.model.onDelete();if (result) {this.args.closeModal();}@@ -350,29 +341,14 @@ export default class PostEventBuilder extends Component {try {this.isSaving = true;- const post = await this.store.find("post", this.event.id);- const raw = post.raw;- const eventParams = buildParams(+ await this.args.model.onUpdate(this.startsAt,this.endsAt,this.event,this.siteSettings);- const newRaw = replaceRaw(eventParams, raw);- if (newRaw) {- const props = {- raw: newRaw,- edit_reason: i18n("discourse_post_event.edit_reason"),- };-- const cooked = await cook(newRaw);- props.cooked = cooked.string;- const result = await post.save(props);- if (result) {- this.args.closeModal();- }- }+ this.args.closeModal();} catch (e) {this.flash = extractError(e);} finally {@@ -380,17 +356,12 @@ export default class PostEventBuilder extends Component {}}- _removeRawEvent(raw) {- const eventRegex = new RegExp(`\\[event\\s(.*?)\\]\\n\\[\\/event\\]`, "m");- return raw.replace(eventRegex, "");- }-<template><DModal@title={{i18n(concat"discourse_post_event.builder_modal."- (if @model.event.id "update_event_title" "create_event_title")+ (if this.isEditing "update_event_title" "create_event_title"))}}@closeModal={{@closeModal}}@@ -751,7 +722,7 @@ export default class PostEventBuilder extends Component {</ConditionalLoadingSection></:body><:footer>- {{#if @model.event.id}}+ {{#if @model.onUpdate}}<DButtonclass="btn-primary"@label="discourse_post_event.builder_modal.update"diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.js b/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.jsindex b58539cdf82..e8ed47d5d3f 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.js@@ -13,19 +13,19 @@ export function buildParams(startsAt, endsAt, event, siteSettings) {params.status = event.status;}- if (event.name) {+ if (event.name && event.name.trim()) {params.name = event.name;}- if (event.location) {+ if (event.location && event.location.trim()) {params.location = event.location;}- if (event.description) {+ if (event.description && event.description.trim()) {params.description = event.description;}- if (event.url) {+ if (event.url && event.url.trim()) {params.url = event.url;}@@ -112,7 +112,7 @@ export function replaceRaw(params, raw) {Object.keys(params).forEach((param) => {const value = params[param];- if (value && value.length) {+ if (value != null && value !== "" && String(value).trim() !== "") {markdownParams.push(`${param}="${value.replace(/"/g, "")}"`);}});@@ -126,7 +126,7 @@ export function replaceRaw(params, raw) {return false;}-function camelCase(input) {+export function camelCase(input) {return input.toLowerCase().replace(/-/g, "_")diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js b/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.jsindex 5b3d1fc3e0c..9642aa6cd0d 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js@@ -1,12 +1,15 @@import { camelize } from "@ember/string";import { withPluginApi } from "discourse/lib/plugin-api";import { buildBBCodeAttrs } from "discourse/lib/text";+import EventNodeView from "../components/event-node-view";import { buildEventPreview } from "../initializers/discourse-post-event-decorator";-const EVENT_ATTRIBUTES = {+export const EVENT_ATTRIBUTES = {name: { default: null },start: { default: null },end: { default: null },+ location: { default: null },+ maxAttendees: { default: null },reminders: { default: null },minimal: { default: null },closed: { default: null },@@ -17,11 +20,17 @@ const EVENT_ATTRIBUTES = {recurrence: { default: null },recurrenceUntil: { default: null },chatEnabled: { default: null },- chatChannelId: { default: null },};/** @type {RichEditorExtension} */const extension = {+ nodeViews: {+ event: {+ component: EventNodeView,+ name: "event",+ },+ },+nodeSpec: {event: {attrs: EVENT_ATTRIBUTES,@@ -93,6 +102,29 @@ const extension = {state.write("[/event]\n");},},+ inputRules: ({ utils: { convertFromMarkdown }, getContext }) => ({+ match: /^\[event([^\]]*)]$/,+ handler: (state, match, start, end) => {+ const currentUser = getContext().currentUser;+ const timezone = currentUser?.user_option?.timezone || moment.tz.guess();++ const userInput = match[1].trim();+ let eventMarkdown;++ if (userInput) {+ eventMarkdown = `[event ${userInput}]\n[/event]`;+ } else {+ const now = moment.tz(moment(), timezone);+ const defaults = `start="${now.format("YYYY-MM-DD HH:mm")}" status="public" timezone="${timezone}"`;+ eventMarkdown = `[event ${defaults}]\n[/event]`;+ }++ const doc = convertFromMarkdown(eventMarkdown);+ return doc.content.firstChild+ ? state.tr.replaceWith(start, end, doc.content.firstChild)+ : null;+ },+ }),};export default {diff --git a/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scss b/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scssnew file mode 100644index 00000000000..904454952c0--- /dev/null+++ b/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scss@@ -0,0 +1,292 @@+@use "lib/viewport";++.composer-event-node {+ display: flex;+ padding: var(--space-3);+ gap: var(--space-1);+ background: var(--secondary);+ flex-direction: column;+ flex: 1 0 auto;+ max-width: 100%;+ box-sizing: border-box;+ box-shadow: 0 0 0 3px var(--primary-100);+ border: 1px solid var(--primary-300);+ border-radius: var(--d-border-radius);+ white-space: normal;++ input,+ textarea {+ border: none;+ margin-bottom: 0;+ opacity: 0.8;++ &::placeholder {+ font-style: italic;+ color: var(--primary-medium);+ }++ &:hover {+ opacity: 1;+ background: var(--primary-very-low);+ cursor: pointer;+ }++ &:focus {+ opacity: 1;+ background: var(--primary-very-low);+ cursor: text;+ outline-color: var(--d-input-focused-color);++ &::placeholder {+ overflow: hidden;+ opacity: 0;+ height: 0;+ }+ }++ @include viewport.until(sm) {+ background: var(--primary-very-low);+ }+ }++ input:not(:focus)::-webkit-outer-spin-button,+ input:not(:focus)::-webkit-inner-spin-button {+ appearance: none;+ }++ input:not(:focus)::-webkit-calendar-picker-indicator {+ display: none;+ }++ input[type="number"] {+ appearance: textfield;++ &:focus {+ appearance: auto;+ }+ }++ &.ProseMirror-selectednode {+ border-color: var(--tertiary);+ box-shadow: 0 0 0 1px var(--tertiary);+ }++ .composer-event__header {+ column-gap: var(--space-4);+ display: flex;+ align-items: flex-start;+ margin-bottom: var(--space-2);++ .composer-event__more-dropdown {+ margin-left: auto;+ align-self: flex-start;+ }+ }++ .composer-event__date {+ display: flex;+ flex-shrink: 0;+ align-items: center;+ justify-content: center;+ width: 3em;+ height: 3em;+ margin: 0;+ padding: 0;+ border: 1px solid var(--primary-low);+ border-radius: var(--d-border-radius);+ flex-direction: column;+ align-self: flex-start;++ .composer-event__month {+ text-align: center;+ color: red;+ font-size: var(--font-down-2);+ font-weight: 400;+ text-transform: uppercase;+ }++ .composer-event__day {+ text-align: center;+ font-size: var(--font-up-1);+ font-weight: 400;+ }+ }++ .composer-event__info {+ display: flex;+ flex: 1;+ flex-direction: column;+ justify-content: center;++ .composer-event__status {+ color: var(--primary-medium);+ font-size: var(--font-down-1);+ margin: 0;+ }+ }++ .composer-event__dates,+ .composer-event__location,+ .composer-event__attendees {+ position: relative;+ display: grid;+ grid-template-columns: 3em 1fr;+ column-gap: var(--space-2);+ align-items: center;+ min-height: 2em;++ &:first-child {+ border-top: 1px solid var(--primary-low);+ }++ > .d-icon {+ color: var(--primary-high);+ margin: 0 auto;+ padding: 0;+ }+ }++ .composer-event__description {+ display: grid;+ grid-template-columns: 1fr;+ }++ .composer-event__date-range {+ display: flex;+ align-items: center;+ flex-wrap: wrap;+ margin-right: calc(-1 * var(--space-6));+ gap: var(--space-half);++ .composer-event__date-separator {+ color: var(--primary-medium);+ }+ }+}++.composer-event__name-input {+ border-radius: var(--d-border-radius);+ margin-top: calc(-1 * var(--space-2));+ margin-left: calc(-1 * var(--space-2));+ margin-bottom: calc(-1 * var(--space-1));+ font-size: var(--font-up-2) !important;+ font-weight: 400;+ color: var(--primary);+ font-family: inherit;+ padding: var(--space-2) !important;+ cursor: text;+ width: 100%;+ resize: none;+}++.composer-event__date-wrapper {+ position: relative;+ display: flex;+}++.composer-event__date-display {+ position: absolute;+ pointer-events: none;+ width: 100%;+ left: var(--space-3);+ right: 0;+ top: 50%;+ transform: translateY(-50%);++ &.--empty {+ font-style: italic;+ color: var(--primary-low-mid);+ }+}++.composer-event__date-input {+ padding: var(--space-half) var(--space-1);+ min-height: 2.25rem;+ cursor: pointer;+ color: transparent !important;+ text-overflow: ellipsis;+ white-space: nowrap;+ overflow: hidden;+ flex: 1;+ min-width: 0;+ width: 9rem;++ &:focus {+ @include viewport.from(sm) {+ color: inherit !important;+ width: auto;+ }+ }+}++@include viewport.from(sm) {+ .composer-event__date-input:focus + .composer-event__date-display {+ display: none;+ }+}++.composer-event__location-input {+ width: 100%;+ cursor: text;+}++.composer-event__max-attendees-input {+ width: 100%;+ max-width: 13rem;+ cursor: text;+ color: transparent !important;++ &:focus {+ color: inherit !important;+ }++ &::placeholder {+ color: var(--primary-medium);+ }+}++.composer-event__max-attendees-input:focus+ + .composer-event__max-attendees-display {+ display: none;+}++.composer-event__max-attendees-display {+ position: absolute;+ pointer-events: none;+ margin-left: var(--space-half);+ left: 4em;+}++.composer-event__description-textarea {+ border-radius: var(--d-border-radius);+ padding: var(--space-2);+ width: 100%;+ cursor: text;+ resize: none;+}++.composer-event__location-content {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ width: 100%;+}++.composer-event__location-external-link {+ color: var(--primary-medium);+ text-decoration: none;+ display: flex;+ align-items: center;+ padding: 0.25rem;+ border-radius: var(--d-border-radius);+ flex-shrink: 0;++ &:hover {+ color: var(--tertiary);+ background: var(--primary-very-low);+ }++ .d-icon {+ font-size: var(--font-down-1);+ }+}diff --git a/plugins/discourse-calendar/config/locales/client.en.yml b/plugins/discourse-calendar/config/locales/client.en.ymlindex aaa9e6b3944..35e6c63c516 100644--- a/plugins/discourse-calendar/config/locales/client.en.yml+++ b/plugins/discourse-calendar/config/locales/client.en.yml@@ -345,6 +345,7 @@ en:bulk_invite: "Bulk Invite"close_event: "Close event"open_event: "Open event"+ destroy_event: "Destroy event"invitees_modal:title_invited: "Event Participation"title_participated: "List of users who participated"@@ -421,6 +422,12 @@ en:private:title: "Private"description: "A private event can only be joined by invited users."+ composer:+ end_date_placeholder: "Set end date"+ location_placeholder: "Add location or URL"+ max_attendees_placeholder: "Set max attendees"+ description_placeholder: "Add event description"+builder_modal:custom_fields:label: "Custom Fields"diff --git a/plugins/discourse-calendar/plugin.rb b/plugins/discourse-calendar/plugin.rbindex 523f9e214da..7cf86b22347 100644--- a/plugins/discourse-calendar/plugin.rb+++ b/plugins/discourse-calendar/plugin.rb@@ -24,6 +24,7 @@ register_asset "stylesheets/common/discourse-post-event.scss"register_asset "stylesheets/common/discourse-post-event-preview.scss"register_asset "stylesheets/common/post-event-builder.scss"register_asset "stylesheets/common/discourse-post-event-invitees.scss"+register_asset "stylesheets/common/composer-event-node-view.scss"register_asset "stylesheets/common/discourse-post-event-core-ext.scss"register_asset "stylesheets/mobile/discourse-post-event-core-ext.scss", :mobileregister_asset "stylesheets/common/discourse-post-event-bulk-invite-modal.scss"diff --git a/plugins/discourse-calendar/spec/system/composer/prosemirror_event_spec.rb b/plugins/discourse-calendar/spec/system/composer/prosemirror_event_spec.rbnew file mode 100644index 00000000000..a53be42eebe--- /dev/null+++ b/plugins/discourse-calendar/spec/system/composer/prosemirror_event_spec.rb@@ -0,0 +1,258 @@+# frozen_string_literal: true++describe "Composer - ProseMirror - Event Editor", type: :system do+ include_context "with prosemirror editor"++ before do+ SiteSetting.calendar_enabled = true+ SiteSetting.discourse_post_event_enabled = true+ SiteSetting.rich_editor = true+ end++ describe "event rendering" do+ it "renders event node with basic attributes" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event name=\"Team Meeting\" location=\"Conference Room\" maxAttendees=\"50\" start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ expect(rich).to have_css(".composer-event-node")+ expect(rich).to have_css(".composer-event__status", text: "Public")+ expect(rich.find(".composer-event__name-input").value).to eq("Team Meeting")+ expect(rich.find(".composer-event__location-input").value).to eq("Conference Room")+ expect(rich.find(".composer-event__max-attendees-input").value).to eq("50")+ end++ it "displays formatted dates correctly" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event start=\"2024-12-20T14:00:00Z\" end=\"2024-12-20T16:00:00Z\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ expect(rich).to have_css(".composer-event__month", text: "DEC")+ expect(rich).to have_css(".composer-event__day", text: "20")+ expect(rich).to have_css(".composer-event__date-range--has-values")+ end+ end++ describe "field interactions" do+ it "shows placeholders and handles external link detection" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ location_input = rich.find(".composer-event__location-input")+ expect(location_input["placeholder"]).to include("location")++ # Test URL detection+ location_input.fill_in(with: "https://zoom.us/meeting")+ expect(rich).to have_css(".composer-event__location-external-link")++ # Test regular location+ location_input.fill_in(with: "Conference Room A")+ expect(rich).to have_no_css(".composer-event__location-external-link")+ end++ it "loads all field values correctly from markdown" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event name=\"Team Standup\" location=\"https://meet.google.com/abc-defg-hij\" maxAttendees=\"15\" start=\"2024-12-20T14:00:00Z\" end=\"2024-12-20T16:00:00Z\" status=\"private\" timezone=\"Europe/Paris\"]\nDaily standup meeting\n[/event]",+ )+ composer.toggle_rich_editor++ # Verify all field values are loaded correctly+ expect(rich.find(".composer-event__name-input").value).to eq("Team Standup")+ expect(rich.find(".composer-event__location-input").value).to eq(+ "https://meet.google.com/abc-defg-hij",+ )+ expect(rich.find(".composer-event__max-attendees-input").value).to eq("15")+ expect(rich.find(".composer-event__description-textarea").value).to eq(+ "Daily standup meeting",+ )+ expect(rich).to have_css(".composer-event__status", text: "Private")+ expect(rich).to have_css(".composer-event__location-external-link")++ # Verify date inputs have values+ start_input = rich.find("input[type='datetime-local']", match: :first)+ end_input = rich.all("input[type='datetime-local']").last+ expect(start_input.value).not_to be_empty+ expect(end_input.value).not_to be_empty+ end++ it "allows editing name field and persists to markdown" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event name=\"Original Name\" start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ rich.find(".composer-event__name-input").fill_in(with: "Updated Meeting Name")++ composer.toggle_rich_editor+ markdown_content = find(".d-editor-input").value+ expect(markdown_content).to include("Updated Meeting Name")+ end++ it "allows editing location field and persists to markdown" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event location=\"Old Room\" start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ rich.find(".composer-event__location-input").fill_in(with: "New Conference Room")++ composer.toggle_rich_editor+ markdown_content = find(".d-editor-input").value+ expect(markdown_content).to include("New Conference Room")+ end++ it "allows editing description field and persists to markdown" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\nOld description content\n[/event]",+ )+ composer.toggle_rich_editor++ rich.find(".composer-event__description-textarea").fill_in(with: "New description content")++ composer.toggle_rich_editor+ markdown_content = find(".d-editor-input").value+ expect(markdown_content).to include("New description content")+ end++ it "allows editing max attendees field and persists to markdown" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event maxAttendees=\"10\" start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ rich.find(".composer-event__max-attendees-input").fill_in(with: "25")++ composer.toggle_rich_editor+ markdown_content = find(".d-editor-input").value+ expect(markdown_content).to include("maxAttendees=25")+ end++ it "allows editing event dates and persists to markdown" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ start_input = rich.find("input[type='datetime-local']", match: :first)+ start_input.fill_in(with: "2024-12-20T14:00")++ end_input = rich.all("input[type='datetime-local']").last+ end_input.fill_in(with: "2024-12-20T16:00")++ expect(rich).to have_css(".composer-event__date-range--has-values")++ composer.toggle_rich_editor+ markdown_content = find(".d-editor-input").value+ expect(markdown_content).to include("2024-12-20 14:00")+ expect(markdown_content).to include("2024-12-20 16:00")+ end+ end++ describe "validation" do+ it "validates max attendees input" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ max_attendees_input = rich.find(".composer-event__max-attendees-input")++ # Valid input+ max_attendees_input.fill_in(with: "25")+ expect(max_attendees_input.value).to eq("25")++ # Invalid input gets cleared+ max_attendees_input.fill_in(with: "-10")+ expect(max_attendees_input.value).to eq("")++ max_attendees_input.fill_in(with: "0")+ expect(max_attendees_input.value).to eq("")+ end++ it "requires start date for event rendering" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content("[event start=\"2025-03-21 15:41\" timezone=\"UTC\"]\n[/event]")+ composer.toggle_rich_editor++ expect(rich).to have_css(".composer-event-node")+ expect(rich.find(".composer-event__name-input").value).to be_empty++ # Test that events without start date don't render+ composer.toggle_rich_editor+ composer.fill_content("[event]\n[/event]")+ composer.toggle_rich_editor+ expect(rich).to have_no_css(".composer-event-node")+ end+ end++ describe "advanced features" do+ it "handles fully populated event with all features" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event name=\"Team Meeting\" location=\"Conference Room A\" maxAttendees=\"25\" start=\"2024-12-20T14:00:00Z\" end=\"2024-12-20T16:00:00Z\" status=\"private\" timezone=\"Europe/Paris\"]\nDetailed meeting description\n[/event]",+ )+ composer.toggle_rich_editor++ expect(rich.find(".composer-event__name-input").value).to eq("Team Meeting")+ expect(rich.find(".composer-event__location-input").value).to eq("Conference Room A")+ expect(rich.find(".composer-event__max-attendees-input").value).to eq("25")+ expect(rich.find(".composer-event__description-textarea").value).to eq(+ "Detailed meeting description",+ )+ expect(rich).to have_css(".composer-event__status", text: "Private")+ end++ it "handles special characters and long values" do+ long_name = "A" * 100+ special_location = "Room #1 @ Building Main"++ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event name=\"#{long_name}\" location=\"#{special_location}\" start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ expect(rich).to have_css(".composer-event-node")+ expect(rich.find(".composer-event__name-input").value).to eq(long_name)+ expect(rich.find(".composer-event__location-input").value).to eq(special_location)+ end++ it "integrates with event builder modal" do+ open_composer+ composer.toggle_rich_editor+ composer.fill_content(+ "[event name=\"Meeting\" start=\"2025-03-21 15:41\" status=\"public\" timezone=\"Europe/Paris\"]\n[/event]",+ )+ composer.toggle_rich_editor++ expect(rich).to have_css(".composer-event__more-dropdown")+ end+ end+enddiff --git a/plugins/discourse-calendar/test/javascripts/integration/components/rich-editor-extension-test.js b/plugins/discourse-calendar/test/javascripts/integration/components/rich-editor-extension-test.jsindex f3e48fae6df..eeb1619fb7a 100644--- a/plugins/discourse-calendar/test/javascripts/integration/components/rich-editor-extension-test.js+++ b/plugins/discourse-calendar/test/javascripts/integration/components/rich-editor-extension-test.js@@ -9,21 +9,48 @@ module("Integration | Component | rich-editor-extension", function (hooks) {"event alone": [[`[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris"]\n[/event]\n`,- `<div class="discourse-post-event discourse-post-event-preview" data-start="2025-03-21 15:41" data-status="public" data-timezone="Europe/Paris" contenteditable="false" draggable="true"><div class="event-preview-status">Public</div><div class="event-preview-dates"><span class="start">March 21, 2025 2:41 PM</span></div></div>`,+ (assert) => {+ assert+ .dom(".composer-event-node")+ .exists("Event node should be rendered");+ assert+ .dom(".composer-event__status")+ .hasText("Public", "Status should be displayed");+ assert+ .dom(".composer-event__date-display")+ .exists("Date should be displayed");+ },`[event start="2025-03-21 15:41" status=public timezone=Europe/Paris]\n[/event]\n`,],],"event with content around": [[`Hello world\n\n[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris"]\n[/event]\nGoodbye world`,- `<p>Hello world</p><div class="discourse-post-event discourse-post-event-preview" data-start="2025-03-21 15:41" data-status="public" data-timezone="Europe/Paris" contenteditable="false" draggable="true"><div class="event-preview-status">Public</div><div class="event-preview-dates"><span class="start">March 21, 2025 2:41 PM</span></div></div><p>Goodbye world</p>`,+ (assert) => {+ assert+ .dom("p")+ .exists({ count: 2 }, "Should have paragraphs around event");+ assert+ .dom(".composer-event-node")+ .exists("Event node should be rendered");+ assert+ .dom(".composer-event__status")+ .hasText("Public", "Status should be displayed");+ },`Hello world\n\n[event start="2025-03-21 15:41" status=public timezone=Europe/Paris]\n[/event]\nGoodbye world`,],],"event with content inside": [[`[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris"]\ntest\n[/event]\n`,- `<div class="discourse-post-event discourse-post-event-preview" data-start="2025-03-21 15:41" data-status="public" data-timezone="Europe/Paris" contenteditable="false" draggable="true"><div class="event-preview-status">Public</div><div class="event-preview-dates"><span class="start">March 21, 2025 2:41 PM</span></div></div>`,+ (assert) => {+ assert+ .dom(".composer-event-node")+ .exists("Event node should be rendered");+ assert+ .dom(".composer-event__status")+ .hasText("Public", "Status should be displayed");+ },`[event start="2025-03-21 15:41" status=public timezone=Europe/Paris]\ntest\n\n[/event]\n`,],],diff --git a/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.js b/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.jsindex a7dc92d750a..adfbcacfb07 100644--- a/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.js+++ b/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.js@@ -31,5 +31,23 @@ module("Unit | Lib | raw-event-helper", function () {"[event ]\n[/event]","handles empty params object");++ assert.strictEqual(+ replaceRaw(+ { name: "", location: "Paris" },+ '[event original="value"]\n[/event]'+ ),+ '[event location="Paris"]\n[/event]',+ "omits empty name parameter"+ );++ assert.strictEqual(+ replaceRaw(+ { name: " ", location: "Berlin" },+ '[event original="value"]\n[/event]'+ ),+ '[event location="Berlin"]\n[/event]',+ "omits whitespace-only name parameter"+ );});});