-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored whole structure to inherit featurs from other libraries (#51)
- Loading branch information
1 parent
2a07709
commit 7be885d
Showing
55 changed files
with
3,701 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
// swift-tools-version: 5.5 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
// swift-tools-version: 5.9 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "RichEditorSwiftUI", | ||
platforms: [ | ||
//Add supported platforms here | ||
.iOS(.v14), | ||
.iOS(.v15), | ||
.macOS(.v12), | ||
.tvOS(.v15), | ||
.watchOS(.v8), | ||
.visionOS(.v1) | ||
], | ||
products: [ | ||
// Products define the executables and libraries a package produces, making them visible to other packages. | ||
.library( | ||
name: "RichEditorSwiftUI", | ||
targets: ["RichEditorSwiftUI"]), | ||
], | ||
dependencies: [], | ||
targets: [ | ||
// Targets are the basic building blocks of a pack.age, defining a module or a test suite. | ||
// Targets can depend on other targets in this package and products from dependencies. | ||
.target( | ||
name: "RichEditorSwiftUI"), | ||
name: "RichEditorSwiftUI", | ||
dependencies: [], | ||
resources: [], | ||
swiftSettings: [ | ||
.define("macOS", .when(platforms: [.macOS])), | ||
.define("iOS", .when(platforms: [.iOS, .macCatalyst])) | ||
] | ||
), | ||
.testTarget( | ||
name: "RichEditorSwiftUITests", | ||
dependencies: ["RichEditorSwiftUI"]), | ||
dependencies: ["RichEditorSwiftUI"], | ||
swiftSettings: [ | ||
.define("macOS", .when(platforms: [.macOS])), | ||
.define("iOS", .when(platforms: [.iOS, .macCatalyst])) | ||
] | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// RichTextAction.swift | ||
// RichEditorSwiftUI | ||
// | ||
// Created by Divyesh Vekariya on 21/10/24. | ||
// | ||
|
||
import SwiftUI | ||
import Combine | ||
|
||
/** | ||
This enum defines rich text actions that can be executed on | ||
a rich text editor. | ||
|
||
This type also serves as a type namespace for other related | ||
types and views, like ``RichTextAction/Button``. | ||
*/ | ||
public enum RichTextAction: Identifiable, Equatable { | ||
|
||
/// Copy the currently selected text, if any. | ||
case copy | ||
|
||
/// Dismiss any presented software keyboard. | ||
case dismissKeyboard | ||
|
||
/// Paste a single image. | ||
// case pasteImage(RichTextInsertion<ImageRepresentable>) | ||
// | ||
// /// Paste multiple images. | ||
// case pasteImages(RichTextInsertion<[ImageRepresentable]>) | ||
// | ||
// /// Paste plain text. | ||
// case pasteText(RichTextInsertion<String>) | ||
|
||
/// A print command. | ||
case print | ||
|
||
/// Redo the latest undone change. | ||
case redoLatestChange | ||
|
||
/// Select a range. | ||
case selectRange(NSRange) | ||
|
||
/// Set the text alignment. | ||
case setAlignment(_ alignment: RichTextAlignment) | ||
|
||
/// Set the entire attributed string. | ||
case setAttributedString(NSAttributedString) | ||
|
||
// Change background color | ||
case setColor(RichTextColor, ColorRepresentable) | ||
|
||
// Highlighted renge | ||
case setHighlightedRange(NSRange?) | ||
|
||
// Change highlighting style | ||
case setHighlightingStyle(RichTextHighlightingStyle) | ||
|
||
/// Set a certain ``RichTextStyle``. | ||
case setStyle(RichTextStyle, Bool) | ||
|
||
/// Step the font size. | ||
case stepFontSize(points: Int) | ||
|
||
/// Step the indent level. | ||
case stepIndent(points: CGFloat) | ||
|
||
/// Step the line spacing. | ||
case stepLineSpacing(points: CGFloat) | ||
|
||
/// Step the superscript level. | ||
case stepSuperscript(steps: Int) | ||
|
||
/// Toggle a certain style. | ||
case toggleStyle(_ style: RichTextStyle) | ||
|
||
/// Undo the latest change. | ||
case undoLatestChange | ||
|
||
/// Set HeaderStyle. | ||
case setHeaderStyle(_ style: RichTextStyle, range: NSRange) | ||
} | ||
|
||
public extension RichTextAction { | ||
|
||
typealias Publisher = PassthroughSubject<Self, Never> | ||
|
||
/// The action's unique identifier. | ||
var id: String { UUID().uuidString } | ||
|
||
/// The action's standard icon. | ||
|
||
} | ||
|
||
// MARK: - Aliases | ||
|
||
public extension RichTextAction { | ||
|
||
/// A name alias for `.redoLatestChange`. | ||
static var redo: RichTextAction { .redoLatestChange } | ||
|
||
/// A name alias for `.undoLatestChange`. | ||
static var undo: RichTextAction { .undoLatestChange } | ||
} | ||
|
||
public extension CGFloat { | ||
|
||
/// The default rich text indent step size. | ||
static var defaultRichTextIntentStepSize: CGFloat = 30.0 | ||
} | ||
|
||
public extension UInt { | ||
|
||
/// The default rich text indent step size. | ||
static var defaultRichTextIntentStepSize: UInt = 30 | ||
} | ||
|
90 changes: 90 additions & 0 deletions
90
Sources/RichEditorSwiftUI/Alignment/RichTextAlignment.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// RichTextAlignment.swift | ||
// RichEditorSwiftUI | ||
// | ||
// Created by Divyesh Vekariya on 21/10/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/** | ||
This enum defines supported rich text alignments, like left, | ||
right, center, and justified. | ||
*/ | ||
public enum RichTextAlignment: String, CaseIterable, Codable, Equatable, Identifiable { | ||
|
||
/** | ||
Initialize a rich text alignment with a native alignment. | ||
|
||
- Parameters: | ||
- alignment: The native alignment to use. | ||
*/ | ||
public init(_ alignment: NSTextAlignment) { | ||
switch alignment { | ||
case .left: self = .left | ||
case .right: self = .right | ||
case .center: self = .center | ||
case .justified: self = .justified | ||
default: self = .left | ||
} | ||
} | ||
|
||
/// Left text alignment. | ||
case left | ||
|
||
/// Center text alignment. | ||
case center | ||
|
||
/// Justified text alignment. | ||
case justified | ||
|
||
/// Right text alignment. | ||
case right | ||
} | ||
|
||
public extension Collection where Element == RichTextAlignment { | ||
|
||
static var all: [Element] { RichTextAlignment.allCases } | ||
} | ||
|
||
public extension RichTextAlignment { | ||
|
||
/// The unique alignment ID. | ||
var id: String { rawValue } | ||
|
||
/// The standard icon to use for the alignment. | ||
// var icon: Image { nativeAlignment.icon } | ||
|
||
/// The standard title to use for the alignment. | ||
// var title: String { nativeAlignment.title } | ||
|
||
/// The standard title key to use for the alignment. | ||
// var titleKey: RTKL10n { nativeAlignment.titleKey } | ||
|
||
/// The native alignment of the alignment. | ||
var nativeAlignment: NSTextAlignment { | ||
switch self { | ||
case .left: .left | ||
case .right: .right | ||
case .center: .center | ||
case .justified: .justified | ||
} | ||
} | ||
} | ||
|
||
//extension NSTextAlignment: RichTextLabelValue {} | ||
|
||
public extension NSTextAlignment { | ||
|
||
// /// The standard icon to use for the alignment. | ||
// var icon: Image { | ||
// switch self { | ||
// case .left: .richTextAlignmentLeft | ||
// case .right: .richTextAlignmentRight | ||
// case .center: .richTextAlignmentCenter | ||
// case .justified: .richTextAlignmentJustified | ||
// default: .richTextAlignmentLeft | ||
// } | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.