@cortexapps/plugin-core

中文文档
3.1.0发布于 2026/04/21MITESM + CJS近 30 天下载 5901

创建 Cortex 插件的核心助手

中文使用文档
文档目录9 节
  1. 克特克斯阿皮语Name
  2. pluginInit
  3. proxyFetch
  4. 使用 proxyFetch 与 缩写
  5. getContext
  6. 构成部分库
  7. 2.x的折旧和迁移
  8. 构成部分详情
  9. 可用组件

semantic-release: angular

@cortexapps/plugin-core

此套件为Cortex插件和Cortex网络应用提供了方便使用的桥梁.

安装它

yarn add @cortexapps/plugin-core

或者说

npm install @cortexapps/plugin-core

克特克斯阿皮语Name

暴露的主要实体是: CortexApi,具有方法 proxyFetch(), (中文(简体) ), getContext() 财务报告和审定财务报表 pluginInit()。 。 。 .

pluginInit

打电话 pluginInit() 尽早触发 iframe 主机将主题样式注入您的插件.

参数

无

回返

void

proxyFetch

页:1: 截至1.3.0,全球 fetch 要调用的方法是猴子补丁 proxyFetch() 在引擎盖下。 这意味着你可以使用 fetch() 您通常会在 Cortex 插件中自动通过 Cortex 代理 .

proxyFetch 为插件提供了一个方法,通过 Cortex 代理来提出API 请求,以避免浏览器 CORS 限制并安全地添加认证. 它的签名与本地浏览器几乎相同 fetch() 方法,但一些属性被平整后可以跨出iframe桥传输.

参数

名称类型说明
投入请求输入见 浏览器获取
资讯请求信息见 浏览器获取

回返

Promise<ShimResponse> - 几乎与浏览器的反应完全相同。 见 源代码 更多细节.

示例

import { CortexApi } from '@cortexapps/plugin-core';

const commentOnPullRequest = async ({
  comment: string,
  owner: string,
  pullNumber: string | number,
  repo: string,
}) => {
  const response = await CortexApi.proxyFetch(
    `https://api.github.com/${owner}/${repo}/pulls/${pullNumber}/comments`,
    {
      body: comment,
      method: 'POST',
    }
  );

  return response.json();
};

使用 proxyFetch 与 缩写

页:1: 截至1.3.0,使用octokit插件(或调整其他库)并不必要,因为全球 fetch 方法默认是shimmed.

使用 octokitPlugin 在 Cortex 插件中方便使用 octokit.

import { CortexApi, octokitPlugin } from '@cortexapps/plugin-core';
import { Octokit, type RestEndpointMethodTypes } from "@octokit/rest";

const CortexOctokit = Octoki.plugin(octokitPlugin);

const getWorkflow = async (options: {
  id: number;
  owner: string;
  repo: string;
}): Promise<
  RestEndpointMethodTypes["actions"]["getWorkflow"]["response"]["data"]
> {
  const { owner, repo, id } = options;
  const octokit = new CortexOctokit({ CortexApi });

  const workflow = await octokit.actions.getWorkflow({
    owner,
    repo,
    workflow_id: id,
  });

  return workflow.data;
};

getContext

页:1: 自1.2.0起,上下文也可通过 useCortexContext 钩.

参数

无

回返

名称类型说明
实体实体?关于该插件相关页面的实体的详细情况,如果适用,则正在提供,否则无效。 见 Cortex 实体 更多细节.
地点插件连接此插件正在提供哪个位置类型 . 地点 更多细节.
用户Cortex 用户见 Cortex 用户 更多细节.

示例

import { CortexApi } from '@cortexapps/plugin-core';

const getCurrentUser = async () => {
  const response = await CortexApi.getContext();
  const resJson = await response.json();

  return resJson.user;
};

构成部分库

2.x的折旧和迁移

组件库被折旧为QQ3.0.0版本,只支持关键修正. 请使用 https://www.npmjs.com/package/@cortexapps/react-plugin-ui 用于React组件和文档.

为了帮助你的移民, plugin-core/components 已转换为使用 react-plugin-ui但是这需要一些 充分移徙的步骤:

  1. 安装两者 @cortexapps/[email protected] 财务报告和审定财务报表 @cortexapps/[email protected] 作为依附关系
  2. 包含 import "@cortexapps/react-plugin-ui/index.css"; 全球样式
  3. 当你的应用靴,打电话 CortexApi.pluginInit(); 更改主题
  4. 确定您的插件正在使用 <PluginProvider> 上下文包装。 这提供了黑暗/ 灯光模式类 <body>

这些步骤应该能使您的组件在暗/ 光模式之间切换, 在视觉上匹配我们的组件样式 .

新的样式将 CSS 重置器应用到基元素( 如 ul编号 :li) - 可能需要一些小的视觉调整 在您的插件中的某些区域,如果它们受到影响.

构成部分详情

以本地操作方式检查故事书中的组件库 yarn storybook。 。 。 .

从 @cortexapps/plugin-core/components 在应用程序中使用它们.

import React from 'react';
import { Button } from '@cortexapps/plugin-core/components';

interface SubmitButtonProps extends React.PropsWithChildren;

const SubmitButton: React.FC<SubmitButtonProps> = ({ children }) => {
  return (
    <Button type="submit">{children}</Button>
  );
};

export default SubmitButton;

可用组件

  • 锁定
  • 徽标
  • 方框
  • 面包屑
  • 按钮
  • 纸牌
  • 复选框
  • 可点击
    • 一个方便的包装 <a> 或一个 <button> (取决于道具) 没有典型的 <a> 或者说 <button> 样式
  • 下坠
  • 奇幻游戏
  • 窗体标签
  • 图标集(恭维 磷酸盐图标(中文(简体) )
  • 投入
  • 标签
  • 线性百分比
  • 列表
  • 装入器
  • 标记
    • 这是Cortex的标志!
  • 模式
  • 药丸
  • 门户
    • 你可能不需要担心这个-- 这是我们内部用来制造模式和相似的
  • 进度栏
  • 堆栈
    • 适用于子女间平分间隔的超有用部分
  • 标签
  • 标记
  • 文本
  • 标题
  • 切换
  • 类型头

详见"打字和故事书".

版本与发布记录

@cortexapps/plugin-core 共发布 41 个版本,首次发布于 2023/04/22;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.0latest2026/04/216 个月前
3.0.02025/04/281.5 年前
3.0.0-beta.5beta2025/04/221.6 年前
3.0.0-beta.42025/04/081.6 年前
3.0.0-beta.32025/04/081.6 年前
3.0.0-beta.22025/04/081.6 年前

其他发布通道:alpha → 3.0.0-alpha.3,beta → 3.0.0-beta.5。

关于 @cortexapps/plugin-core 的常见问题

@cortexapps/plugin-core 是什么?

创建 Cortex 插件的核心助手

如何安装 @cortexapps/plugin-core?

在项目目录运行 npm install @cortexapps/plugin-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cortexapps/plugin-core 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cortexapps__plugin-core 是否存在。

@cortexapps/plugin-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cortexapps/plugin-core 可以商用吗?

@cortexapps/plugin-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cortexapps/plugin-core 的下载量有多少?

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

@cortexapps/plugin-core 还在维护吗?

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