@enonic/ui-types

中文文档
0.7.0发布于 2026/11/04Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 2506

Shared TypeScript types and behavioural contracts for Enonic UIs

原始使用文档
文档目录4 节
  1. The mount contract
  2. The form and property contracts
  3. Principals and tasks
  4. The theme

@enonic/ui-types

Types and nothing else: no runtime, no dependencies, no imports.

Two kinds of thing belong here — the base domain types more than one package or application shares (content, principals, schema shapes), and the behavioural contracts between programs that are released separately, where both sides have to agree on a shape they cannot import from each other. A prop type read by one component is not one of those.

pnpm add -D @enonic/ui-types

The mount contract

The contract between a shell and a module it mounts into its page: a screen or a panel shipped by another application, discovered at runtime and rendered into a container the shell owns. The shell creates an open shadow root, hands the module a container inside it and a Host, and calls mount; the module owns everything inside the container, the shell owns the page around it.

TypeWhat it is
Readable<T>get() for the current value, listen for changes — it never calls back on subscribe
ToastToneinfo, success, warning, error — as @enonic/ui's Toast names them
NotifyOptionsautoHide, lifetimeMs
Hostwhat every mount gets: baseUrl, extension, locale, theme, visible, notify
Routedwhat a mount with a url segment adds: path, navigate with NavigateOptions
RoutedHostHost & Routed — what an interface whose mounts own a segment hands over
MountOptions<H>the argument of mount: container and host; H defaults to Host
Unmountwhat mount returns, synchronously; idempotent and must not throw
Mount<H>the function a module's entry exports — annotate it with this
Module<H>what a module's entry exports as a whole

A host declares which type its interface hands over; XP Settings' settings.section hands a RoutedHost. A host whose mounts own no segment hands a Host extended with its own capability, and a module written against RoutedHost is unaffected. The rules the types cannot express are in the TSDoc, where a provider reads them: a module never touches the page outside its container, every string crossing the boundary is localized, one module instance may serve several mounts and Host.extension says which one this is, and a revoked host answers every call with a no-op.

The declarations reference the DOM lib for HTMLElement; a consumer's tsconfig has to include it, which a browser project's does.

The form and property contracts

What XP's own JS libraries serialize a form and a property tree to — lib-content for a content type, lib-schema for a content type, mixin or form fragment, and an application's server for a form it reads from a descriptor, such as an id provider's configuration — and what @enonic/input-types reads them back from. The same dialect @enonic-types/core declares as FormItem, so a server typed against XP's types produces these without a cast; here every field XP omits is optional, inputType is any string and a config value is unknown, because that is what arrives.

TypeWhat it is
FormJsona form: its items in order
FormItemJsonone item — InputJson, ItemSetJson, OptionSetJson, LayoutJson or FormFragmentJson, by formItemType
FormItemTypethe discriminant: Input, ItemSet, OptionSet, Layout, FormFragment
OccurrencesJsonminimum and maximum; a maximum of 0 is unbounded
InputConfigJsonan input type's config as XP's libraries emit it — a scalar, a list or an object under each property
OptionSetOptionJsonone option: name, label, default, its items
PropertyTreeJsona property tree: its arrays
PropertyArrayJsona named array of one ValueTypeName, its values
PropertyValueJsona scalar under v or a nested tree under set
ValueTypeNamethe value types XP knows, as ValueTypes names them

The { Input: { … } } dialect with one wrapper key per item is Content Studio's REST talking to Content Studio's client, and is not here.

How the Settings shell behaves behind these types — keep-alive, what a hidden mount hears, revocation — is documented with the shell, in app-settings' docs/extensions/.

Principals and tasks

What XP itself declares for a principal and a task — @enonic-types/core's PrincipalKey, User, Group and Role, @enonic-types/lib-task's TaskInfo — copied here so that a browser program needs no server package, and pinned by a type test so that a value typed there is assignable here. The fields a server omits for a summary are optional. Reading and building a key and following a task are @enonic/ui-utils' part.

TypeWhat it is
PrincipalTypeuser, group, role — a principal key's own prefix
UserKey, GroupKey, RoleKeyuser:<idProvider>:<id>, group:<idProvider>:<id>, role:<id> — a key is its string
PrincipalKeyany of the three
User, Group, Rolethe record behind a key: type, key, displayName, and what that kind carries
PrincipalUser | Group | Role, narrowed by type
UserRecord, GroupRecord, RoleRecord, PrincipalRecordthe same without type — what a REST layer sends, read into a Principal by toPrincipal from @enonic/ui-utils
TaskStateWAITING, RUNNING, FINISHED, FAILED
TaskProgresscurrent of total, and info — what the task reports, its result once it is done
TaskInfoa task as XP's and Content Studio's task resources answer it

The theme

The theme preference XP's admin applications share through one stored entry. Reading, writing and following that entry is @enonic/ui-utils' part.

TypeWhat it is
Themelight, dark, system — what a user picks; system follows the OS
ResolvedThemelight, dark — what a page paints, and what Host.theme carries

Part of the Enonic UI Toolkit.

版本与发布记录

@enonic/ui-types 共发布 8 个版本,首次发布于 2026/09/07;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/11/049 天前
0.6.02026/10/2222 天前
0.5.22026/10/1530 天前
0.5.12026/10/1430 天前
0.5.02026/10/091 个月前
0.4.02026/09/281 个月前

关于 @enonic/ui-types 的常见问题

@enonic/ui-types 是什么?

Shared TypeScript types and behavioural contracts for Enonic UIs

如何安装 @enonic/ui-types?

在项目目录运行 npm install @enonic/ui-types,或使用 pnpm add / yarn add / bun add。

@enonic/ui-types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@enonic/ui-types 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@enonic/ui-types 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@enonic/ui-types 可以商用吗?

@enonic/ui-types 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@enonic/ui-types 的下载量有多少?

根据 npm 官方下载统计,@enonic/ui-types 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,506 次,日均约 84 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@enonic/ui-types 还在维护吗?

最新版本 0.7.0 发布于 2026/11/04(9 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/09/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。