Enlighten 1.0

Enlighten 1.0

Chris Zielinski维护。




Enlighten💡

Platform Pod Version Carthage compatible Swift Version GitHub license


一个基于Spotlight的集成登录和帮助库,用于macOS,用Swift编写。


寻找...

  • macOS的浮动操作按钮?查看Fab.🛒.
  • macOS的扩展气泡文本字段?查看BubbleTextField💬.

功能

  • 使用spotlight集成导入,并渲染CommonMark Markdown字符串/文件。

  • 一个帮助按钮,显示包含应用程序特定帮助文档的弹出窗,文档是从CommonMark Markdown字符串/文件渲染的。

  • 使用CommonMark Markdown字符串/文件作为工具提示。

  • 支持深色模式。

    Light Dark Mode Supported

安装

Enlighten 可使用CocoaPods或Carthage安装。

使用Carthage

github "chriszielinski/Enlighten"

使用CocoaPods

pod "Enlighten"

要求

  • macOS 10.12+(10.13+ 用于自定义 URL 框架处理程序)

术语

  • 阶段 —— 未来映像的“单独步骤”。它由显示在弹出窗口中的 Markdown 字符串组成。

  • 虹膜 —— 一个封装特定视图(或虹膜)的 spotlight 行为的类。它包含至少一个阶段;可选项。所有虹膜的阶段共享虹膜的配置,除非它们覆盖了适当的属性(例如 popoverMaxWidth 属性)。焦点/非焦点动画分组/方法在展示虹膜的第一个阶段和离开虹膜的最后一个阶段时调用。

  • 追光 —— 在从一个视图(或虹膜)切换到下一个视图时使用的 更宽、更全面的 spotlight。

    Followspot
  • 轮廓闪光灯 —— 用于吸引特定视图(或虹膜)注意力的 更窄、“更小”的 focused spotlight。

    Profile Spot

组件

示例项目提供了一个集成和配置 Enlightenment 库各种组件的全方位、文档化的例子。

高光控制器

有两个高光控制器可供使用

  • EnlightenSpotlightController — 显示按添加顺序排列的百叶窗控制器。
  • EnlightenKeyedSpotlightController — 允许通过符合 EnlightenSpotlightControllerKeys 枚举的顺序指定百叶窗的显示顺序。

无键高光控制器快速入门

以下代码将创建一个包含两个百叶窗的四个阶段 EnlightenSpotlightController。它展示了创建/添加百叶窗和阶段的各种方式。

📣 注意: 百叶窗将按照添加到高光控制器的顺序显示。在这个例子中,firstIris(以及其阶段)将首先显示,然后是 secondIris

// Create the controller.
let spotlightController = EnlightenSpotlightController()

// Create an iris with a single stage.
let firstIris = EnlightenIris(view: aView, markdownString: "This is a `NSView`.")
// Add another stage to the iris.
firstIris.addAdditionalStage(using: "This is the iris' second stage.")
// Create a third stage.
let thirdStage = EnlightenIrisStage(markdownString: "This is the **third** stage!")
// Add the third stage to the iris.
firstIris.addAdditional(stage: thirdStage)
// Add the iris to the spotlight controller.
spotlightController.addSpotlight(iris: firstIris)

// This is a convenience method for creating and adding an iris to the controller.
let secondIris = spotlightController.addSpotlight(view: anotherView, markdownString: "This is another `NSView`.")

键控高光控制器快速入门

上述方法也适用于 EnlightenKeyedSpotlightController,其中只有少数需要额外的参数——密钥。但首先,我们必须定义一个密钥枚举,其案例声明顺序将直接对应于拥有百叶窗的显示顺序。

🎡 尝试:更改 SpotlightKey 案例的顺序以更改显示顺序。

// The keys that define the presentation order of the keyed spotlight controller's irises. The keys can also be used for identification purposes.
enum SpotlightKey: String, EnlightenSpotlightControllerKeys {
    // The controller will begin with the iris that corresponds to this key.
    case firstView
    // And finish with the iris that corresponds to this key.
    case secondView
}

/// Create a keyed spotlight controller using the `SpotlightKey` enum to specify the presentation order.
let keyedSpotlightController = EnlightenKeyedSpotlightController(keys: SpotlightKey.self)

// Create a keyed iris with a single stage.
let firstIris = EnlightenKeyedIris(presentationOrderKey: SpotlightKey.firstView,
                                   view: aView,
                                   markdownString: "This is a `NSView`.")
// Add another stage to the keyed iris.
firstIris.addAdditionalStage(using: "This is the iris' second stage.")
// Create a third stage.
let thirdStage = EnlightenIrisStage(markdownString: "This is the **third** stage!")
// Add the third stage to the keyed iris.
firstIris.addAdditional(stage: thirdStage)
// Add the keyed iris to the keyed spotlight controller.
keyedSpotlightController.addSpotlight(iris: firstIris)

// This is a convenience method for creating and adding a keyed iris to the keyed controller.
let secondIris = keyedSpotlightController.addSpotlight(presentationOrderKey: .secondView,
                                                       view: anotherView,
                                                       markdownString: "This is another `NSView`.")

展示

展示和取消展示高光控制器非常简单。

📣 注意: 当遍历所有阶段时,控制器将取消展示自身。

aSpotlightController.present()
aSpotlightController.dismiss()

跟灯形状

配置跟灯(较大的移动聚光灯)的形状。

spotlightController.followspotShape = .circle

跟灯的形状可以设置为以下值

  • .circle(默认值)

    .circle Followspot Shape
  • .none

    .none Followspot Shape
  • .ellipse

    .ellipse Followspot Shape

使用轮廊聚光灯

当使用圆形或椭圆形的跟灯时,轮廊聚光灯是可选的。您可以通过设置控制器的 usesProfileSpot 属性来指定您的偏好。它的默认值为 true

没有轮廊聚光灯的 .circle 跟灯看起来是这样的。

Circle Followspot with no Profile Spot

委派

您可以将聚光灯控制器的代理设置为一个遵守 EnlightenSpotlightControllerDelegate 协议的类以接收事件。

spotlightController.delegate = self

Enlighten 聚光灯控制器代理可以实现的可选方法集。

/// Invoked before the controller shows a stage.
func spotlightControllerWillShow(stage: Int, in iris: EnlightenIris, navigating: EnlightenSpotlightController.NavigationDirection) {}

/// Invoked when the controller has finished dismissing.
func spotlightControllerDidDismiss() {}

/// Invoked when a Markdown string fails to load, this method optionally returns a replacement.
///
/// If the delegate does not implement this method or returns nil, the spotlight stage is skipped.
///
/// - Note: This delegate method should not be necessary if appropriate testing procedures are employed to ensure
///         that all Markdown strings load successfully (i.e. `EnlightenSpotlightController.validateMarkdownStrings()`
///         testing method).
func spotlightControllerFailedToLoad(markdownString: String, for iris: EnlightenIris, with error: Error) -> String? {}

帮助按钮

一个显示包含从 CommonMark Markdown 字符串渲染的应用特定帮助文档的弹出窗口的帮助按钮。

创建 EnlightenHelpButton 有两种方法:Interface Builder 或编程方式。演示使用的是在 Interface Builder 中创建的多页 EnlightenHelpButton

Enlighten Help Button


编程方式如下。

📣 注意:如果您喜欢在公共 Wi-Fi 网络上通过 HTTP 连接进行金融交易,请继续使用该 try!。您将不得不使用一些非常奇怪的 Markdown 来引发错误。

// The Markdown string to render.
let helpButtonMarkdownString = "**Need help?** – Something that's helpful."
// Create the help button.
let enlightenHelpButton = try! EnlightenHelpButton(markdownString: helpButtonMarkdownString)
// And that's it... you still need to add it to the view hierarchy, of course.

// Optionally, you can have the popover be detachable, which allows the popover to be dragged into its own _floating_ window.
enlightenHelpButton.canDetach = true

委派

您可以将帮助按钮的代理设置为一个遵守 EnlightenPopoverDelegate 协议的类以接收事件。

enlightenHelpButton.enlightenPopoverDelegate = self

Enlighten 弹出窗口代理可以实现的可选方法集。

/// Invoked when an Enlighten URL scheme was clicked in the popover.
func enlightenPopover(didClickEnlighten url: URL) {}

/// Invoked when a Markdown string fails to load, this method optionally returns a replacement.
func enlightenPopoverFailedToLoad(downError: Error) -> String? {}

提示

你可能需要以这种方式构建你的 Spotlight 控制器阶段的 Markdown 内容,以便它们也可以用作纯文本提示。

🔥一石二鸟。

Enlighten Tooltip


您可以将一个 NSView 的提示从 Markdown 字符串中设置如下

📣 注意:如果你喜欢吃生饼干面团,并且引擎开启时给车加油,那就试试吧!你将必须使用一些非常奇特的 Markdown 来引发一个错误。

let helpButtonToolTip = """
    # Need help?

    **This is a Markdown string**, stripped of any _styling_.
    """
try? aView.enlightenTooltip(markdownString: helpButtonToolTip)

并且从位于主捆绑包中的名为 'tooltip.md' 的 Markdown 文件

try? aView.enlightenTooltip(markdownFilename: "tooltip", in: Bundle.main)

文档

还有许多其他可配置属性,可让你的入门体验/帮助文档达到完美。您可以在 这里 查看文档。

// 待办事项

  • 测试。

社区

  • 发现了一个错误?打开一个 问题
  • 有没有功能想法? 打开一个 问题自己完成并完成后提交 PR。😅(或你可以打开一个问题🙄).
  • 想贡献吗?提交一个 pull request

贡献者

框架和库

Enlighten 依赖于 Swift 社区的杰出贡献,具体如下:

  • iwasrobbed/Down —— 基于 cmark 的 Swift 中的 Markdown/CommonMark 锁定渲染,速度极快。
  • realm/jazzy —— 为 Swift & Objective-C 提供灵魂般的文档。
  • realm/SwiftLint —— 一种用于强制执行 Swift 风格和约定的工具。

许可

Enlighten 以 MIT 许可证提供,有关更多信息,请参阅LICENSE 文件。