Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Reuse shared calendar control styles and document component reuse https://github.com/siyuan-note/siyuan/issues/19736

Daniel56a7622a45ee
diff --git a/AGENTS.md b/AGENTS.md
index 7f61cd550d..8f84712f6a 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -110,6 +110,12 @@ SiYuan repository guide. Module path `github.com/siyuan-note/siyuan`, license AG
5. **TypeScript/JavaScript:** Semicolons required, use double quotes, indent with spaces
- When moving or extracting a symbol into another module, update all affected imports to reference its defining module directly. Do not leave forwarding re-exports in the original module merely to avoid updating callers
6. **CSS:** Do not use the `:has()` selector because of its performance impact
+ - Before adding or styling a basic control, inspect and reuse the existing component, markup pattern, and shared styles in `app/src/assets/scss/component/` (for example, `b3-button`, `b3-select`, and `b3-text-field`), including existing modifiers; use `block__icon` for established icon-button patterns
+ - Apply the same reuse-first rule to menus, dialogs, tooltips, and drag interactions: inspect existing implementations and APIs before adding a feature-specific replacement
+ - Feature styles should describe layout (such as placement, width constraints, gaps, and wrapping), rather than duplicate or override basic control appearance (such as height, padding, typography, colors, borders, shadows, and hover/focus/disabled states). Do not use deeper selectors, inline styles, or `!important` merely to restyle a shared control
+ - If existing controls cannot meet a requirement, explain the concrete need and prefer extending a shared component or modifier when the need is reusable. Keep necessary feature-specific exceptions narrowly scoped; use theme variables for appearance and retain keyboard focus and disabled feedback
+ - Reuse components according to their purpose; do not borrow an unrelated component (for example, menu items for a form) and then cancel its styles. Preserve useful feature classes as theme hooks when switching to shared controls
+ - When reviewing control-style changes, check consistency with shared controls, theme overrides through shared classes, light/dark themes, narrow layouts, and large editor fonts. Preserve necessary layout and touch-target constraints; do not remove all feature styles indiscriminately
7. **CSS positioning and scrolling:** When changing `position`, `transform`, `contain`, or `overflow` on a shared container, check the effects on descendant positioning reference frames, overlay coverage, and clipping. Prefer a dedicated container when a local control needs a positioning reference. For settings dialog changes, verify detail overlays, the top drag area, and scrollbar placement at different window widths
8. **Built-in custom attributes:** Use the `custom-sy-` prefix for custom attributes owned by built-in features
diff --git a/app/src/assets/scss/business/_av-calendar.scss b/app/src/assets/scss/business/_av-calendar.scss
index 9c51ca93bb..fb3dd1f74d 100644
--- a/app/src/assets/scss/business/_av-calendar.scss
+++ b/app/src/assets/scss/business/_av-calendar.scss
@@ -31,29 +31,6 @@
align-items: center;
gap: 4px;
margin-left: auto;
-
- .b3-select {
- height: 24px;
- padding-top: 2px;
- padding-bottom: 2px;
- font-size: 12px;
- }
- }
-
- .av__calendar-today {
- padding: 2px 6px;
- border: 0;
- border-radius: var(--b3-border-radius);
- background: transparent;
- color: inherit;
- font: inherit;
- line-height: 20px;
- cursor: pointer;
-
- &:hover,
- &:focus-visible {
- background: var(--b3-list-hover);
- }
}
.av__calendar-source {
@@ -327,24 +304,11 @@
.av__calendar-more {
min-width: 0;
- font-family: inherit;
- font-size: 12px;
- line-height: 20px;
- white-space: nowrap;
+ display: block;
overflow: hidden;
text-overflow: ellipsis;
margin: 3px;
- padding: 2px 6px;
- border: 0;
- border-radius: var(--b3-border-radius);
- background: transparent;
- color: var(--b3-theme-on-surface);
- cursor: pointer;
text-align: left;
-
- &:hover {
- background: var(--b3-list-hover);
- }
}
.av__calendar-empty {
@@ -375,28 +339,20 @@
flex-direction: column;
gap: 12px;
- .b3-menu__item {
- display: grid;
- grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
- align-items: center;
- gap: 16px;
- padding: 0;
- margin: 0;
- background: transparent;
- cursor: default;
- }
-
- .b3-menu__label {
+ .b3-select {
+ width: 100%;
min-width: 0;
- white-space: normal;
}
+ }
- .b3-select {
- width: 100%;
+ .av__calendar-setting {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
+ align-items: center;
+ gap: 16px;
+
+ > span {
min-width: 0;
- height: 36px;
- padding-top: 8px;
- padding-bottom: 8px;
}
}
@@ -412,7 +368,6 @@
.b3-button {
flex: 1 1 140px;
- min-height: 36px;
white-space: normal;
&:first-child {
diff --git a/app/src/protyle/render/av/calendar/render.ts b/app/src/protyle/render/av/calendar/render.ts
index ca3098003a..dbd4f94de8 100644
--- a/app/src/protyle/render/av/calendar/render.ts
+++ b/app/src/protyle/render/av/calendar/render.ts
@@ -276,7 +276,7 @@ export const renderCalendar = async (blockElement: HTMLElement, protyle: IProtyl
}).join("");
const overflow = Array.from({length: 7}, (_, day) => {
const hidden = segments.filter(segment => segment.lane >= rowLimit && segment.column <= day && segment.column + segment.span > day).length;
- return hidden && !expanded ? `<button class="av__calendar-more" data-calendar-expand="${start}" style="grid-column:${day + 1}">${escapeHtml(window.siyuan.languages.calendarMore.replace("${x}", hidden.toString()))}</button>` : "";
+ return hidden && !expanded ? `<button class="b3-button b3-button--cancel b3-button--small av__calendar-more" data-calendar-expand="${start}" style="grid-column:${day + 1}">${escapeHtml(window.siyuan.languages.calendarMore.replace("${x}", hidden.toString()))}</button>` : "";
}).join("");
body += `<div class="av__calendar-week" data-calendar-week="${start}"><div class="av__calendar-days">${dayHeaders}</div>
<div class="av__calendar-events" style="grid-template-rows:repeat(${Math.max(1, maxLane)},auto)">${visible.map(segment => getEventHTML(segment, view, editable)).join("")}</div>
@@ -291,7 +291,7 @@ export const renderCalendar = async (blockElement: HTMLElement, protyle: IProtyl
<span class="av__calendar-label">${escapeHtml(label)}</span>
<div class="av__calendar-controls">
${iconButton("previous", "iconLeft", window.siyuan.languages.previous)}
- <button type="button" class="av__calendar-today" data-calendar-action="today">${window.siyuan.languages.calendarToday}</button>
+ <button type="button" class="b3-button b3-button--cancel av__calendar-today" data-calendar-action="today">${window.siyuan.languages.calendarToday}</button>
${iconButton("next", "iconRight", window.siyuan.languages.next)}
${iconButton("jump", "iconCalendar", window.siyuan.languages.calendarJumpDate)}
<select class="b3-select" data-calendar-mode aria-label="${window.siyuan.languages.calendarView}"><option value="month"${state.mode === "month" ? " selected" : ""}>${window.siyuan.languages.month}</option><option value="week"${state.mode === "week" ? " selected" : ""}>${window.siyuan.languages.week}</option></select>
diff --git a/app/src/protyle/render/av/calendar/settings.ts b/app/src/protyle/render/av/calendar/settings.ts
index 2df2da7340..e876d9cdae 100644
--- a/app/src/protyle/render/av/calendar/settings.ts
+++ b/app/src/protyle/render/av/calendar/settings.ts
@@ -40,7 +40,7 @@ export const getCalendarSettingsHTML = (view: IAVTable, asMenu = false) => getCa
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
</button>`;
}
- return `<label class="b3-menu__item"><span class="b3-menu__label">${item.label}</span>
+ return `<label class="av__calendar-setting"><span>${item.label}</span>
<select class="b3-select" data-calendar-setting="${item.key}" aria-label="${item.label}">
${item.choices.map(choice => `<option value="${escapeAttr(choice.value)}"${choice.value === value ? " selected" : ""}>${escapeHtml(item.key === "dateKeyID" && choice.value === "" ? window.siyuan.languages.calendarSelectDateField : choice.label)}</option>`).join("")}
</select>