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
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public enum ThemeFileFormat {
)
}

// The oldest format holding every key the theme sets, so an older TablePro still reads a theme
// that uses none of the newer keys.
// The oldest format holding the theme's keys, so an older build still reads a theme that sets no newer key.
private static func schema(of theme: ThemeDefinition) -> Int {
theme.overrides.keys.reduce(ThemeSchema.oldestReadable) { max($0, $1.introducedInSchema) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ public enum ThemeSlot: String, CaseIterable, Sendable {
}
}

// A file declaring an older format cannot hold the key.
public var introducedInSchema: Int {
switch self {
case .windowBackdrop,
Expand Down
1 change: 0 additions & 1 deletion apple/TablePro/Core/Events/AppEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ final class AppEvents {

let browseContainerChanged = PassthroughSubject<UUID, Never>()

// The connections strip moves its highlight on this.
let visibleContainerChanged = PassthroughSubject<Void, Never>()

let sessionTransactionsChanged = PassthroughSubject<UUID, Never>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ final class TableTransferService: ObservableObject {
// PostgreSQL and DuckDB read a BIT as its digits and MySQL as its number, so 00000101 bound to a MySQL BIT stores 101.
// Read before the row stream opens: a catalog read queued behind the source's own open stream waits for the whole
// table, and behind DuckDB's bounded one never ends. The catalog, because a fresh PostgreSQL session's header names
// a bit column `unknown` and MySQL's drops the width.
// a bit column `unknown` and MySQL's drops the width of a BIT(1).
static func bitColumnKinds(
for object: ExportObjectItem,
source: ExportDataSourceAdapter,
Expand Down
47 changes: 39 additions & 8 deletions apple/TablePro/Core/Services/Formatting/CellDisplayFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// CellDisplayFormatter.swift
// TablePro
//
// Pure formatter that transforms raw cell values into display-ready strings.
// Used by the data grid coordinator's display cache to compute values once per cell.
//

import Foundation
import TableProPluginKit
Expand All @@ -19,7 +16,14 @@ enum CellDisplayFormatter {
displayFormat: ValueDisplayFormat? = nil,
databaseType: DatabaseType? = nil
) -> String? {
display(rawValue, columnType: columnType, displayFormat: displayFormat, databaseType: databaseType).text
resolve(
rawValue,
columnType: columnType,
displayFormat: displayFormat,
databaseType: databaseType,
dates: DateFormattingService.shared.renderer,
checksRendering: false
).text
}

static func format(
Expand All @@ -29,7 +33,14 @@ enum CellDisplayFormatter {
databaseType: DatabaseType?,
dates: DateDisplayRenderer
) -> String? {
display(rawValue, columnType: columnType, displayFormat: displayFormat, databaseType: databaseType, dates: dates).text
resolve(
rawValue,
columnType: columnType,
displayFormat: displayFormat,
databaseType: databaseType,
dates: dates,
checksRendering: false
).text
}

@MainActor
Expand All @@ -39,12 +50,13 @@ enum CellDisplayFormatter {
displayFormat: ValueDisplayFormat?,
databaseType: DatabaseType?
) -> (text: String?, isFormatted: Bool) {
display(
resolve(
rawValue,
columnType: columnType,
displayFormat: displayFormat,
databaseType: databaseType,
dates: DateFormattingService.shared.renderer
dates: DateFormattingService.shared.renderer,
checksRendering: true
)
}

Expand All @@ -55,6 +67,25 @@ enum CellDisplayFormatter {
displayFormat: ValueDisplayFormat?,
databaseType: DatabaseType?,
dates: DateDisplayRenderer
) -> (text: String?, isFormatted: Bool) {
resolve(
rawValue,
columnType: columnType,
displayFormat: displayFormat,
databaseType: databaseType,
dates: dates,
checksRendering: true
)
}

// Find, the value filter and the display order discard the flag, and the JSON and PHP checks read the whole value.
private static func resolve(
_ rawValue: PluginCellValue,
columnType: ColumnType?,
displayFormat: ValueDisplayFormat?,
databaseType: DatabaseType?,
dates: DateDisplayRenderer,
checksRendering: Bool
) -> (text: String?, isFormatted: Bool) {
switch rawValue {
case .null:
Expand All @@ -71,7 +102,7 @@ enum CellDisplayFormatter {
if let displayFormat, displayFormat != .raw,
displayFormat.isApplicable(to: columnType, databaseType: databaseType),
let formatted = ValueDisplayFormatter.apply(value, format: displayFormat, columnType: columnType, dates: dates) {
return (fitToCell(formatted), rendered(formatted, from: value, by: displayFormat))
return (fitToCell(formatted), checksRendering && rendered(formatted, from: value, by: displayFormat))
}
var displayValue = value
if let columnType {
Expand Down
23 changes: 7 additions & 16 deletions apple/TablePro/Core/Services/Highlight/HighlightCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct HighlightCondition {
static let searchLimit = 10_000

private enum ValueKind {
case numeric
case boolean
// A boolean column can hold numbers: MySQL's TINYINT(1) stores any integer from -128 to 127.
case numberOrBoolean
case text
}

Expand Down Expand Up @@ -130,18 +130,16 @@ struct HighlightCondition {

private var prefersNumbers: Bool {
switch valueKind {
case .numeric:
case .numberOrBoolean:
return true
case .boolean:
return false
case .text:
return isOrderingOperator
}
}

private var prefersBooleans: Bool {
switch valueKind {
case .numeric, .boolean:
case .numberOrBoolean:
return true
case .text:
return false
Expand Down Expand Up @@ -194,23 +192,16 @@ struct HighlightCondition {
regularExpression(pattern, ignoresCase: false) != nil
}

/// `searchLimit` caps the haystack in `searchable(_:)`, not the pattern. Capping the pattern
/// looked like a guard against a runaway expression and is not one: cost comes from a pattern's
/// shape rather than its length, and `(a+)+$` compiles in 0.01ms. Measured against this cap,
/// a valid 160,000-unit alternation compiles in 8.85ms, once per rule set rather than per row,
/// so the only thing the cap achieved was to refuse a pattern the user wrote and then report it
/// as invalid. Nil now means the expression will not compile, and nothing else.
// No length cap: cost follows a pattern's shape, and a valid 160,000-unit alternation compiled in 8.85ms.
private static func regularExpression(_ pattern: String, ignoresCase: Bool) -> NSRegularExpression? {
guard !pattern.isEmpty else { return nil }
return try? NSRegularExpression(pattern: pattern, options: ignoresCase ? [.caseInsensitive] : [])
}

private static func valueKind(for columnType: ColumnType?) -> ValueKind {
switch columnType {
case .integer, .decimal:
return .numeric
case .boolean:
return .boolean
case .integer, .decimal, .boolean:
return .numberOrBoolean
case .text, .date, .timestamp, .datetime, .blob, .json, .enumType, .set, .spatial, .vector, .array, .none:
return .text
}
Expand Down
11 changes: 10 additions & 1 deletion apple/TablePro/Core/Services/Masking/MaskingPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ struct MaskingPolicy: Equatable, Sendable {
for rule in rules where Self.matches(rule, table: table, column: column, typeName: typeName) {
return rule.style
}
return nil
// Only after no rule matched as written, so a later column rule keeps beating a type rule that names no width.
guard let typeName else { return nil }
let base = Self.baseTypeName(typeName)
return rules.first { $0.target == .type && MaskingGlob.matches($0.trimmedPattern, base) }?.style
}

func columnMasks(table: String?, columns: [String], typeNames: [String?]) -> ColumnMasks {
Expand Down Expand Up @@ -111,6 +114,12 @@ struct MaskingPolicy: Equatable, Sendable {
return MaskingGlob.matches(tablePattern, String(table[table.index(after: bareStart)...]))
}
}

// A result names `TINYINT(1)`, `BIT(8)` or `Nullable(String)` where the rule says `tinyint`, `bit` or `string`.
private static func baseTypeName(_ typeName: String) -> String {
let unwrapped = ColumnType.unwrappedTypeName(typeName) ?? typeName
return unwrapped.prefix { $0 != "(" }.trimmingCharacters(in: .whitespaces)
}
}

extension MaskingStyle {
Expand Down
23 changes: 17 additions & 6 deletions apple/TablePro/Core/Utilities/SQL/RowSortComparator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@
// RowSortComparator.swift
// TablePro
//
// Type-aware row value comparator for grid sorting.
//

import Foundation

/// Type-aware row value comparator for grid sorting.
/// Uses String.compare with .numeric option and type-specific fast paths for integer/decimal columns.
internal enum RowSortComparator {
internal static func compare(_ lhs: String, _ rhs: String, columnType: ColumnType?) -> ComparisonResult {
if let columnType {
switch columnType {
case .integer:
if let l = Int64(lhs), let r = Int64(rhs) {
return l < r ? .orderedAscending : (l > r ? .orderedDescending : .orderedSame)
return order(l, r)
}
case .decimal:
if let l = Double(lhs), let r = Double(rhs) {
return l < r ? .orderedAscending : (l > r ? .orderedDescending : .orderedSame)
return order(l, r)
}
case .boolean:
// MySQL's TINYINT(1) is a boolean that stores any integer from -128 to 127.
if let l = booleanNumber(lhs), let r = booleanNumber(rhs) {
return order(l, r)
}
default:
break
}
}
return lhs.compare(rhs, options: [.numeric])
}

// One number per value, so `1`, `2` and `true` order the same way whichever pair is compared.
private static func booleanNumber(_ text: String) -> Int64? {
if let number = Int64(text) { return number }
return StoredBoolean.value(of: text).map { $0 ? 1 : 0 }
}

private static func order<Value: Comparable>(_ lhs: Value, _ rhs: Value) -> ComparisonResult {
lhs < rhs ? .orderedAscending : (lhs > rhs ? .orderedDescending : .orderedSame)
}
}
1 change: 0 additions & 1 deletion apple/TablePro/Models/UI/DataGridConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct DataGridConfiguration: Equatable {
// A result's rows, not a list of columns: the Data Grid sort preferences apply.
var appliesRowSortPreferences: Bool = false

// Values typed by the engine draw in their type's theme color; a list of definitions or untyped text stays plain.
var colorsValuesByType: Bool = false

// The theme editor shows a theme's value colors even while Color values by type is off.
Expand Down
18 changes: 9 additions & 9 deletions apple/TablePro/Resources/Themes/tablepro.catppuccin-latte.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
"dataGrid": {
"alternateRow": "#E6E9EF",
"background": "#EFF1F5",
"binary": "#C81F9B",
"boolFalse": "#D20F39",
"boolTrue": "#327D22",
"dateTime": "#1962F5",
"binary": "#B4008A",
"boolFalse": "#C10031",
"boolTrue": "#226E0E",
"dateTime": "#0551E4",
"deleted": "#D20F3926",
"deletedText": "#D20F3980",
"enum": "#8839EF",
"enum": "#7E29E2",
"focusBorder": "#8839EF",
"gridLine": "#BCC0CC",
"headerBackground": "#E6E9EF",
"headerText": "#4C4F69",
"inactiveSelection": "#CCD0DA",
"inserted": "#40A02B26",
"json": "#996214",
"json": "#875400",
"modified": "#DF8E1D26",
"nullValue": "#7C7F93",
"number": "#BF4701",
"number": "#A73D00",
"rowNumber": "#8C8FA1",
"selection": "#CCD0DA",
"selectionText": "#4C4F69",
"string": "#327D22",
"string": "#4653C5",
"text": "#4C4F69",
"uuid": "#137A80"
"uuid": "#006A70"
},
"editor": {
"background": "#EFF1F5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rowNumber": "#7F849C",
"selection": "#313244",
"selectionText": "#CDD6F4",
"string": "#A6E3A1",
"string": "#B4BEFE",
"text": "#CDD6F4",
"uuid": "#94E2D5"
},
Expand Down
12 changes: 6 additions & 6 deletions apple/TablePro/Resources/Themes/tablepro.dracula.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
"dataGrid": {
"alternateRow": "#21222C",
"background": "#282A36",
"binary": "#BD93F9",
"boolFalse": "#FF5555",
"binary": "#9DAFE5",
"boolFalse": "#FF928B",
"boolTrue": "#50FA7B",
"dateTime": "#8BE9FD",
"deleted": "#FF555526",
"deletedText": "#FF555580",
"enum": "#F1FA8C",
"enum": "#A4FFFF",
"focusBorder": "#BD93F9",
"gridLine": "#44475A",
"headerBackground": "#21222C",
"headerText": "#F8F8F2",
"inactiveSelection": "#44475A80",
"inserted": "#50FA7B26",
"json": "#FFB86C",
"modified": "#FFB86C4D",
"modified": "#FFB86C26",
"nullValue": "#6272A4",
"number": "#BD93F9",
"number": "#C59EFF",
"rowNumber": "#6272A4",
"selection": "#44475A",
"selectionText": "#F8F8F2",
"string": "#F1FA8C",
"text": "#F8F8F2",
"uuid": "#FF79C6"
"uuid": "#FF89CB"
},
"editor": {
"background": "#282A36",
Expand Down
2 changes: 1 addition & 1 deletion apple/TablePro/Resources/Themes/tablepro.github-dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"alternateRow": "#161B22",
"background": "#0D1117",
"binary": "#FF9BCE",
"boolFalse": "#F85149",
"boolFalse": "#FF574F",
"boolTrue": "#3FB950",
"dateTime": "#D2A8FF",
"deleted": "#F8514926",
Expand Down
12 changes: 6 additions & 6 deletions apple/TablePro/Resources/Themes/tablepro.github-light.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"dataGrid": {
"alternateRow": "#F6F8FA",
"background": "#FFFFFF",
"binary": "#BF3989",
"boolFalse": "#CF222E",
"boolTrue": "#1A7F37",
"dateTime": "#8250DF",
"binary": "#B93384",
"boolFalse": "#CE212E",
"boolTrue": "#127A33",
"dateTime": "#7D4BD9",
"deleted": "#FF818226",
"deletedText": "#CF222E80",
"enum": "#9A6700",
"enum": "#916000",
"focusBorder": "#0969DA",
"gridLine": "#D0D7DE",
"headerBackground": "#F6F8FA",
Expand All @@ -26,7 +26,7 @@
"selectionText": "#1F2328",
"string": "#0A3069",
"text": "#1F2328",
"uuid": "#0072F0"
"uuid": "#0066D8"
},
"editor": {
"background": "#FFFFFF",
Expand Down
Loading
Loading