-
Notifications
You must be signed in to change notification settings - Fork 6
Add richtext support to LabelCollector #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // | ||
| // RichContent.swift | ||
| // PingDavinci | ||
| // | ||
| // Copyright (c) 2026 Ping Identity Corporation. All rights reserved. | ||
| // | ||
| // This software may be modified and distributed under the terms | ||
| // of the MIT license. See the LICENSE file for details. | ||
| // | ||
|
|
||
| /// A replacement entry within rich content. | ||
| /// - `value`: The display text for the replacement. | ||
| /// - `href`: The URL for link-type replacements. | ||
| /// - `type`: The type of replacement (e.g., "link"). | ||
| /// - `target`: The link target (e.g., "_self", "_blank"). | ||
| public struct RichContentReplacement: Sendable { | ||
| public let value: String | ||
| public let href: String? | ||
| public let type: String | ||
| public let target: String? | ||
| } | ||
|
|
||
| /// Rich content for a form field, enabling template-based text with embedded links. | ||
| /// - `content`: A template string with `{{placeholder}}` tokens. | ||
| /// - `replacements`: A dictionary mapping placeholder keys to their replacement details. | ||
| public struct RichContent: Sendable { | ||
| public let content: String | ||
| public let replacements: [String: RichContentReplacement] | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both public struct RichContentReplacement: Sendable, Equatable { … }
public struct RichContent: Sendable, Equatable { … } |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // LabelCollector.swift | ||
| // PingDavinci | ||
| // | ||
| // Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| // Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved. | ||
| // | ||
| // This software may be modified and distributed under the terms | ||
| // of the MIT license. See the LICENSE file for details. | ||
|
|
@@ -24,12 +24,31 @@ public class LabelCollector: Collector, @unchecked Sendable { | |
| public private(set) var key: String = "" | ||
| /// The label content. | ||
| public private(set) var content: String = "" | ||
|
|
||
| /// Optional rich content with template text and link replacements. | ||
| public private(set) var richContent: RichContent? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update Davinci readme file to include |
||
|
|
||
| /// Initializes a new instance of `LabelCollector`. | ||
| /// - Parameter json: The json to initialize from. | ||
| public required init(with json: [String : Any]) { | ||
| content = json[Constants.content] as? String ?? "" | ||
| key = json[Constants.key] as? String ?? "" | ||
|
|
||
| if let richContentDict = json[Constants.richContent] as? [String: Any], | ||
| let richContentContent = richContentDict[Constants.content] as? String { | ||
| var replacements: [String: RichContentReplacement] = [:] | ||
| if let replacementsDict = richContentDict[Constants.replacements] as? [String: [String: Any]] { | ||
| for (replacementKey, replacementDict) in replacementsDict { | ||
| let replacement = RichContentReplacement( | ||
| value: replacementDict[Constants.value] as? String ?? "", | ||
| href: replacementDict[Constants.href] as? String, | ||
| type: replacementDict[Constants.type] as? String ?? "", | ||
| target: replacementDict[Constants.target] as? String | ||
| ) | ||
| replacements[replacementKey] = replacement | ||
| } | ||
| } | ||
| self.richContent = RichContent(content: richContentContent, replacements: replacements) | ||
| } | ||
| } | ||
|
|
||
| /// Initializes the `LabelCollector` with the given value. The `LabelCollector` does not hold any value. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RichContent.swiftis placed at the module root (Davinci/Davinci/) while all other collector-supporting types live inDavinci/Davinci/collector/. Consider moving the file...