From 7b5d8448d9b6d70713a4b3921a8224890c56f93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=92=E6=B1=9F=E5=AD=A4=E5=BD=B1?= Date: Wed, 12 Aug 2026 15:02:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=B8=BA=E9=A2=9C=E8=89=B2=E5=92=8C?= =?UTF-8?q?=E5=AD=97=E4=BD=93=E5=B1=9E=E6=80=A7=E6=B7=BB=E5=8A=A0=E6=98=BE?= =?UTF-8?q?=E5=BC=8F=E7=B1=BB=E5=9E=8B=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 UIColor 和 UIFont 的静态属性调用添加显式类型前缀,避免与 SwiftUI 类型产生歧义。 --- .../STMarkdown/Core/STMarkdownPreset.swift | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Sources/STMarkdown/Core/STMarkdownPreset.swift b/Sources/STMarkdown/Core/STMarkdownPreset.swift index e221f2f..aa5ef9e 100644 --- a/Sources/STMarkdown/Core/STMarkdownPreset.swift +++ b/Sources/STMarkdown/Core/STMarkdownPreset.swift @@ -32,25 +32,25 @@ public enum STMarkdownPresets { } public static let article = STMarkdownStyle( - font: .st_systemFont(ofSize: 17, weight: .regular), - textColor: .label, + font: UIFont.st_systemFont(ofSize: 17, weight: .regular), + textColor: UIColor.label, lineHeight: 26, kern: 0.1, paragraphSpacing: 10, bodyLineSpacing: 3, - headingTextColor: .label, - linkColor: .systemBlue, - inlineCodeTextColor: .secondaryLabel, - codeBlockTextColor: .label, - codeBlockHeaderTextColor: .secondaryLabel, + headingTextColor: UIColor.label, + linkColor: UIColor.systemBlue, + inlineCodeTextColor: UIColor.secondaryLabel, + codeBlockTextColor: UIColor.label, + codeBlockHeaderTextColor: UIColor.secondaryLabel, codeBlockBackgroundColor: UIColor.secondarySystemBackground, - tableTextColor: .label, - tableHeaderTextColor: .label, + tableTextColor: UIColor.label, + tableHeaderTextColor: UIColor.label, tableBorderColor: UIColor.separator, tableBackgroundColor: UIColor.secondarySystemBackground, - imagePlaceholderTextColor: .label, + imagePlaceholderTextColor: UIColor.label, imagePlaceholderBackgroundColor: UIColor.tertiarySystemBackground, - imagePlaceholderCaptionColor: .secondaryLabel, + imagePlaceholderCaptionColor: UIColor.secondaryLabel, horizontalRuleColor: UIColor.separator, horizontalRuleLength: 24, listItemSpacing: 10, @@ -59,25 +59,25 @@ public enum STMarkdownPresets { ) public static let compact = STMarkdownStyle( - font: .st_systemFont(ofSize: 14, weight: .regular), - textColor: .label, + font: UIFont.st_systemFont(ofSize: 14, weight: UIFont.Weight.regular), + textColor: UIColor.label, lineHeight: 20, kern: 0.08, paragraphSpacing: 6, bodyLineSpacing: 1, - headingTextColor: .label, - linkColor: .systemBlue, - inlineCodeTextColor: .secondaryLabel, - codeBlockTextColor: .label, - codeBlockHeaderTextColor: .secondaryLabel, + headingTextColor: UIColor.label, + linkColor: UIColor.systemBlue, + inlineCodeTextColor: UIColor.secondaryLabel, + codeBlockTextColor: UIColor.label, + codeBlockHeaderTextColor: UIColor.secondaryLabel, codeBlockBackgroundColor: UIColor.secondarySystemBackground, - tableTextColor: .label, - tableHeaderTextColor: .label, + tableTextColor: UIColor.label, + tableHeaderTextColor: UIColor.label, tableBorderColor: UIColor.separator, tableBackgroundColor: UIColor.secondarySystemBackground, - imagePlaceholderTextColor: .label, + imagePlaceholderTextColor: UIColor.label, imagePlaceholderBackgroundColor: UIColor.tertiarySystemBackground, - imagePlaceholderCaptionColor: .secondaryLabel, + imagePlaceholderCaptionColor: UIColor.secondaryLabel, horizontalRuleColor: UIColor.separator, horizontalRuleLength: 18, listItemSpacing: 6, From b4917b62447ec48a59d0ecec78a2f1dc40a90b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=92=E6=B1=9F=E5=AD=A4=E5=BD=B1?= Date: Wed, 12 Aug 2026 15:10:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(stmarkdown):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=A4=B4=E9=83=A8=E9=A1=B9=E4=B8=BA=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 STMarkdownTableHeaderItem 从 STMarkdownTableView.swift 迁移至独立文件,并将 handler 闭包重命名为 action,工厂方法改为静态属性 defaultItems 和 copyItem()。 --- Sources/STMarkdown/Core/STMarkdownStyle.swift | 2 +- .../Table/STMarkdownTableView.swift | 58 ++----------------- 2 files changed, 6 insertions(+), 54 deletions(-) diff --git a/Sources/STMarkdown/Core/STMarkdownStyle.swift b/Sources/STMarkdown/Core/STMarkdownStyle.swift index a119bbe..a422685 100644 --- a/Sources/STMarkdown/Core/STMarkdownStyle.swift +++ b/Sources/STMarkdown/Core/STMarkdownStyle.swift @@ -315,7 +315,7 @@ public struct STMarkdownStyle: @unchecked Sendable { } public static let `default` = STMarkdownStyle( - font: .st_systemFont(ofSize: 16, weight: .regular), + font: UIFont.st_systemFont(ofSize: 16, weight: .regular), textColor: .label, lineHeight: 24, kern: 0.12 diff --git a/Sources/STMarkdown/Table/STMarkdownTableView.swift b/Sources/STMarkdown/Table/STMarkdownTableView.swift index 25ce80e..5e53150 100644 --- a/Sources/STMarkdown/Table/STMarkdownTableView.swift +++ b/Sources/STMarkdown/Table/STMarkdownTableView.swift @@ -8,55 +8,7 @@ import UIKit // MARK: - STMarkdownTableHeaderItem - -/// 顶部工具条的单个按钮描述。外界可组合内置工厂方法或自定义,赋给 `STMarkdownTableView.headerItems`。 -public struct STMarkdownTableHeaderItem { - public let identifier: String - public let image: UIImage? - /// handler 在主线程调用,参数为触发按钮的 tableView,便于访问数据或调用 renderFullTableImage()。 - public let handler: (STMarkdownTableView) -> Void - - public init(identifier: String, image: UIImage?, handler: @escaping (STMarkdownTableView) -> Void) { - self.identifier = identifier - self.image = image - self.handler = handler - } - - /// 复制按钮:将表格纯文本写入剪贴板,并触发 onCopyTable 回调。 - public static func copy() -> STMarkdownTableHeaderItem { - STMarkdownTableHeaderItem( - identifier: "copy", - image: UIImage(systemName: "doc.on.doc") - ) { tableView in - guard let tableData = tableView.tableData else { return } - UIPasteboard.general.string = tableData.plainText() - tableView.onCopyTable?() - tableView.showCopyFeedback() - } - } - - /// 下载按钮:触发 onDownloadTable 回调,由宿主实现具体保存逻辑。 - public static func download() -> STMarkdownTableHeaderItem { - STMarkdownTableHeaderItem( - identifier: "download", - image: UIImage(systemName: "square.and.arrow.down") - ) { tableView in - guard let tableData = tableView.tableData else { return } - tableView.onDownloadTable?(tableData) - } - } - - /// 全屏按钮:触发 onExpandTable 回调,与长按展开行为一致。 - public static func fullscreen() -> STMarkdownTableHeaderItem { - STMarkdownTableHeaderItem( - identifier: "fullscreen", - image: UIImage(systemName: "arrow.up.left.and.arrow.down.right") - ) { tableView in - guard let tableData = tableView.tableData else { return } - tableView.onExpandTable?(tableData) - } - } -} +// 类型定义见 STMarkdownTableHeaderItem.swift(含 action / defaultItems / copyItem() 等),本文件不再重复声明。 // MARK: - STMarkdownTableView @@ -164,7 +116,7 @@ open class STMarkdownTableView: UIView { self.gridLayout.minimumRowHeight = style.tableMinimumRowHeight self.setupCollectionView() self.setupHeader() - self.headerItems = style.tableHeaderItems ?? self.makeDefaultHeaderItems() + self.headerItems = style.tableHeaderItems ?? STMarkdownTableHeaderItem.defaultItems self.rebuildButtonStack() self.applyStyle() } @@ -267,7 +219,7 @@ open class STMarkdownTableView: UIView { button.accessibilityIdentifier = item.identifier button.addAction(UIAction { [weak self] _ in guard let self else { return } - item.handler(self) + item.action(self) }, for: .touchUpInside) if item.identifier == "copy" { self.copyButtonRef = button @@ -302,9 +254,9 @@ open class STMarkdownTableView: UIView { } } - /// style 变更时同步按钮项(优先用 style.tableHeaderItems,否则 makeDefaultHeaderItems)。 + /// style 变更时同步按钮项(优先用 style.tableHeaderItems,否则 defaultItems)。 private func applyStyleHeaderItems() { - self.headerItems = self.style.tableHeaderItems ?? self.makeDefaultHeaderItems() + self.headerItems = self.style.tableHeaderItems ?? STMarkdownTableHeaderItem.defaultItems } public override func layoutSubviews() {