Skip to content

Commit f2e515d

Browse files
authored
Merge pull request #12 from i-stack/merge_release_1.5.0_to_main
Add explicit type prefixes for UIColor and UIFont properties
2 parents 4ecf781 + 50ac0c5 commit f2e515d

3 files changed

Lines changed: 28 additions & 76 deletions

File tree

‎Sources/STMarkdown/Core/STMarkdownPreset.swift‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ public enum STMarkdownPresets {
3232
}
3333

3434
public static let article = STMarkdownStyle(
35-
font: .st_systemFont(ofSize: 17, weight: .regular),
36-
textColor: .label,
35+
font: UIFont.st_systemFont(ofSize: 17, weight: .regular),
36+
textColor: UIColor.label,
3737
lineHeight: 26,
3838
kern: 0.1,
3939
paragraphSpacing: 10,
4040
bodyLineSpacing: 3,
41-
headingTextColor: .label,
42-
linkColor: .systemBlue,
43-
inlineCodeTextColor: .secondaryLabel,
44-
codeBlockTextColor: .label,
45-
codeBlockHeaderTextColor: .secondaryLabel,
41+
headingTextColor: UIColor.label,
42+
linkColor: UIColor.systemBlue,
43+
inlineCodeTextColor: UIColor.secondaryLabel,
44+
codeBlockTextColor: UIColor.label,
45+
codeBlockHeaderTextColor: UIColor.secondaryLabel,
4646
codeBlockBackgroundColor: UIColor.secondarySystemBackground,
47-
tableTextColor: .label,
48-
tableHeaderTextColor: .label,
47+
tableTextColor: UIColor.label,
48+
tableHeaderTextColor: UIColor.label,
4949
tableBorderColor: UIColor.separator,
5050
tableBackgroundColor: UIColor.secondarySystemBackground,
51-
imagePlaceholderTextColor: .label,
51+
imagePlaceholderTextColor: UIColor.label,
5252
imagePlaceholderBackgroundColor: UIColor.tertiarySystemBackground,
53-
imagePlaceholderCaptionColor: .secondaryLabel,
53+
imagePlaceholderCaptionColor: UIColor.secondaryLabel,
5454
horizontalRuleColor: UIColor.separator,
5555
horizontalRuleLength: 24,
5656
listItemSpacing: 10,
@@ -59,25 +59,25 @@ public enum STMarkdownPresets {
5959
)
6060

6161
public static let compact = STMarkdownStyle(
62-
font: .st_systemFont(ofSize: 14, weight: .regular),
63-
textColor: .label,
62+
font: UIFont.st_systemFont(ofSize: 14, weight: UIFont.Weight.regular),
63+
textColor: UIColor.label,
6464
lineHeight: 20,
6565
kern: 0.08,
6666
paragraphSpacing: 6,
6767
bodyLineSpacing: 1,
68-
headingTextColor: .label,
69-
linkColor: .systemBlue,
70-
inlineCodeTextColor: .secondaryLabel,
71-
codeBlockTextColor: .label,
72-
codeBlockHeaderTextColor: .secondaryLabel,
68+
headingTextColor: UIColor.label,
69+
linkColor: UIColor.systemBlue,
70+
inlineCodeTextColor: UIColor.secondaryLabel,
71+
codeBlockTextColor: UIColor.label,
72+
codeBlockHeaderTextColor: UIColor.secondaryLabel,
7373
codeBlockBackgroundColor: UIColor.secondarySystemBackground,
74-
tableTextColor: .label,
75-
tableHeaderTextColor: .label,
74+
tableTextColor: UIColor.label,
75+
tableHeaderTextColor: UIColor.label,
7676
tableBorderColor: UIColor.separator,
7777
tableBackgroundColor: UIColor.secondarySystemBackground,
78-
imagePlaceholderTextColor: .label,
78+
imagePlaceholderTextColor: UIColor.label,
7979
imagePlaceholderBackgroundColor: UIColor.tertiarySystemBackground,
80-
imagePlaceholderCaptionColor: .secondaryLabel,
80+
imagePlaceholderCaptionColor: UIColor.secondaryLabel,
8181
horizontalRuleColor: UIColor.separator,
8282
horizontalRuleLength: 18,
8383
listItemSpacing: 6,

‎Sources/STMarkdown/Core/STMarkdownStyle.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public struct STMarkdownStyle: @unchecked Sendable {
315315
}
316316

317317
public static let `default` = STMarkdownStyle(
318-
font: .st_systemFont(ofSize: 16, weight: .regular),
318+
font: UIFont.st_systemFont(ofSize: 16, weight: .regular),
319319
textColor: .label,
320320
lineHeight: 24,
321321
kern: 0.12

‎Sources/STMarkdown/Table/STMarkdownTableView.swift‎

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,7 @@
88
import UIKit
99

1010
// MARK: - STMarkdownTableHeaderItem
11-
12-
/// 顶部工具条的单个按钮描述。外界可组合内置工厂方法或自定义,赋给 `STMarkdownTableView.headerItems`。
13-
public struct STMarkdownTableHeaderItem {
14-
public let identifier: String
15-
public let image: UIImage?
16-
/// handler 在主线程调用,参数为触发按钮的 tableView,便于访问数据或调用 renderFullTableImage()。
17-
public let handler: (STMarkdownTableView) -> Void
18-
19-
public init(identifier: String, image: UIImage?, handler: @escaping (STMarkdownTableView) -> Void) {
20-
self.identifier = identifier
21-
self.image = image
22-
self.handler = handler
23-
}
24-
25-
/// 复制按钮:将表格纯文本写入剪贴板,并触发 onCopyTable 回调。
26-
public static func copy() -> STMarkdownTableHeaderItem {
27-
STMarkdownTableHeaderItem(
28-
identifier: "copy",
29-
image: UIImage(systemName: "doc.on.doc")
30-
) { tableView in
31-
guard let tableData = tableView.tableData else { return }
32-
UIPasteboard.general.string = tableData.plainText()
33-
tableView.onCopyTable?()
34-
tableView.showCopyFeedback()
35-
}
36-
}
37-
38-
/// 下载按钮:触发 onDownloadTable 回调,由宿主实现具体保存逻辑。
39-
public static func download() -> STMarkdownTableHeaderItem {
40-
STMarkdownTableHeaderItem(
41-
identifier: "download",
42-
image: UIImage(systemName: "square.and.arrow.down")
43-
) { tableView in
44-
guard let tableData = tableView.tableData else { return }
45-
tableView.onDownloadTable?(tableData)
46-
}
47-
}
48-
49-
/// 全屏按钮:触发 onExpandTable 回调,与长按展开行为一致。
50-
public static func fullscreen() -> STMarkdownTableHeaderItem {
51-
STMarkdownTableHeaderItem(
52-
identifier: "fullscreen",
53-
image: UIImage(systemName: "arrow.up.left.and.arrow.down.right")
54-
) { tableView in
55-
guard let tableData = tableView.tableData else { return }
56-
tableView.onExpandTable?(tableData)
57-
}
58-
}
59-
}
11+
// 类型定义见 STMarkdownTableHeaderItem.swift(含 action / defaultItems / copyItem() 等),本文件不再重复声明。
6012

6113
// MARK: - STMarkdownTableView
6214

@@ -164,7 +116,7 @@ open class STMarkdownTableView: UIView {
164116
self.gridLayout.minimumRowHeight = style.tableMinimumRowHeight
165117
self.setupCollectionView()
166118
self.setupHeader()
167-
self.headerItems = style.tableHeaderItems ?? self.makeDefaultHeaderItems()
119+
self.headerItems = style.tableHeaderItems ?? STMarkdownTableHeaderItem.defaultItems
168120
self.rebuildButtonStack()
169121
self.applyStyle()
170122
}
@@ -267,7 +219,7 @@ open class STMarkdownTableView: UIView {
267219
button.accessibilityIdentifier = item.identifier
268220
button.addAction(UIAction { [weak self] _ in
269221
guard let self else { return }
270-
item.handler(self)
222+
item.action(self)
271223
}, for: .touchUpInside)
272224
if item.identifier == "copy" {
273225
self.copyButtonRef = button
@@ -302,9 +254,9 @@ open class STMarkdownTableView: UIView {
302254
}
303255
}
304256

305-
/// style 变更时同步按钮项(优先用 style.tableHeaderItems,否则 makeDefaultHeaderItems)。
257+
/// style 变更时同步按钮项(优先用 style.tableHeaderItems,否则 defaultItems)。
306258
private func applyStyleHeaderItems() {
307-
self.headerItems = self.style.tableHeaderItems ?? self.makeDefaultHeaderItems()
259+
self.headerItems = self.style.tableHeaderItems ?? STMarkdownTableHeaderItem.defaultItems
308260
}
309261

310262
public override func layoutSubviews() {

0 commit comments

Comments
 (0)