Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Sources/STMarkdown/Core/STMarkdownPreset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Sources/STMarkdown/Core/STMarkdownStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 5 additions & 53 deletions Sources/STMarkdown/Table/STMarkdownTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Loading