silkio-flowchart 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,15 +1,21 @@
1
- ISC License
2
-
3
- Copyright (c) 2026 silker contributors
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted, provided that the above
7
- copyright notice and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 silkio-flowchart contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,38 +1,38 @@
1
- # flowchart
2
-
3
- 基于 [silkor](../) 画布内核的 流程图 场景包,包名 `silkio-flowchart`。
4
-
5
- ## 安装
6
-
7
- ```sh
8
- pnpm add silkio-flowchart
9
- ```
10
-
11
- `@silkor/core` 与 `@silkor/preset` 会作为依赖一并安装。
12
-
13
- ## 使用
14
-
15
- 便捷模式:场景内部通过 `@silkor/preset` 的 `officialPlugins()` 自动完成插件装配,开箱即用;也支持宿主自建 `App` 的显式装配。
16
-
17
- 对外导出见 `src/index.ts`。`examples/demo-flowchart` 是可运行的 Astro + Vue 演示。
18
-
19
- ## 开发
20
-
21
- ```sh
22
- pnpm install
23
- pnpm check:deps # 边界守护:禁止直连插件、禁止依赖另一个场景仓
24
- pnpm build
25
- pnpm test
26
- ```
27
-
28
- `pnpm check:deps` 会把「场景包只依赖 core + preset」这条规则机械化。官方插件清单以 `@silkor/preset` 的 `officialPlugins()` 为单一事实来源,本仓不得直接依赖 `@silkor/plugin-*`。
29
-
30
- > 依赖的 `@silkor/core` / `@silkor/preset` 固定从 npm 安装正式版本,不再链接本地源码。需要改内核时在 `silkor` 仓开发并发布,再升级本仓的依赖版本号。
31
-
32
- ## 版本约定
33
-
34
- 依赖的 `@silkor/core` / `@silkor/preset` 版本号必须与 `silkor` 仓当前发布的版本族一致。能力键常量在 core、实现在插件,版本错配会到 `app.require(...)` 运行时才暴露。
35
-
36
- ## License
37
-
38
- ISC
1
+ # flowchart
2
+
3
+ 基于 [silkor](../) 画布内核的 流程图 场景包,包名 `silkio-flowchart`。
4
+
5
+ ## 安装
6
+
7
+ ```sh
8
+ pnpm add silkio-flowchart
9
+ ```
10
+
11
+ `@silkor/core` 与 `@silkor/preset` 会作为依赖一并安装。
12
+
13
+ ## 使用
14
+
15
+ 便捷模式:场景内部通过 `@silkor/preset` 的 `officialPlugins()` 自动完成插件装配,开箱即用;也支持宿主自建 `App` 的显式装配。
16
+
17
+ 对外导出见 `src/index.ts`。`examples/demo-flowchart` 是可运行的 Astro + Vue 演示。
18
+
19
+ ## 开发
20
+
21
+ ```sh
22
+ pnpm install
23
+ pnpm check:deps # 边界守护:禁止直连插件、禁止依赖另一个场景仓
24
+ pnpm build
25
+ pnpm test
26
+ ```
27
+
28
+ `pnpm check:deps` 会把「场景包只依赖 core + preset」这条规则机械化。官方插件清单以 `@silkor/preset` 的 `officialPlugins()` 为单一事实来源,本仓不得直接依赖 `@silkor/plugin-*`。
29
+
30
+ > 依赖的 `@silkor/core` / `@silkor/preset` 固定从 npm 安装正式版本,不再链接本地源码。需要改内核时在 `silkor` 仓开发并发布,再升级本仓的依赖版本号。
31
+
32
+ ## 版本约定
33
+
34
+ 依赖的 `@silkor/core` / `@silkor/preset` 版本号必须与 `silkor` 仓当前发布的版本族一致。能力键常量在 core、实现在插件,版本错配会到 `app.require(...)` 运行时才暴露。
35
+
36
+ ## License
37
+
38
+ MIT
@@ -492,8 +492,9 @@ export function parseAIFlowResponse(raw) {
492
492
  }
493
493
  // ---- 默认提示词 ----
494
494
  // AI 生成提示词模板:把请求渲染为大模型可直接使用的指令。核心约束是
495
- // 「禁止输出任何几何字段」——坐标与端口方向由程序布局器计算,模型只需描述
496
- // 流程语义;对话类能力(撤销/重做/查历史/看选中)以操作形式表达,由程序执行。
495
+ // 「禁止输出任何几何字段」——坐标由程序布局器计算;每条边的出入端口方向
496
+ // 由模型在 edges[].fromDir/toDir 中明确给出(按绘图规则选边);
497
+ // 对话类能力(撤销/重做/查历史/看选中)以操作形式表达,由程序执行。
497
498
  // 宿主可自行替换提示词,只需遵守上面的语义图与操作协议。
498
499
  export function defaultAIFlowPrompt(req) {
499
500
  const { selection, historyState } = req;
@@ -501,7 +502,7 @@ export function defaultAIFlowPrompt(req) {
501
502
  return [
502
503
  "你是流程图助手。需要生成或修改流程图、撤销/重做、查看历史时,只输出一个 JSON 对象,不要输出解释文字,不要用代码块包裹。",
503
504
  "输出格式(按指令选择一种):",
504
- '1. 改图:{"ops":[{"op":"render","graph":{"nodes":[{"id":"n1","shape":"ellipse","text":"开始"},{"id":"n2","shape":"diamond","text":"校验通过?"}],"edges":[{"from":"n1","to":"n2"},{"from":"n2","to":"n3","text":"是","fromDir":"right"}]}}]}',
505
+ '1. 改图:{"ops":[{"op":"render","graph":{"nodes":[{"id":"n1","shape":"ellipse","text":"开始"},{"id":"n2","shape":"diamond","text":"校验通过?"}],"edges":[{"from":"n1","to":"n2","fromDir":"bottom","toDir":"top"},{"from":"n2","to":"n3","text":"是","fromDir":"right","toDir":"left"}]}}]}',
505
506
  ' 也可以直接输出语义图 {"nodes":[...],"edges":[...]}(等价于一条 render 操作)。',
506
507
  '2. 撤销 / 重做:{"ops":[{"op":"undo"}]} 或 {"ops":[{"op":"redo"}]};可连写多次表示连续撤销/重做,但不能与改图操作写在同一批。',
507
508
  '3. 查看历史:{"ops":[{"op":"history"}]}(只读,程序会把可撤销/可重做的变更列表并入回答)。',
@@ -536,7 +537,7 @@ export function defaultAIFlowPrompt(req) {
536
537
  "- nodes[].shape:只允许 rect(步骤)、diamond(判断)、ellipse(开始/结束)、parallelogram(输入/输出)、hexagon(准备)、database(存储)。也可以用 role 字段代替(start/end/decision/io/process/data),程序会自动推断形状。",
537
538
  "- nodes[].text:节点文字,简短;判断节点写成问句。允许 text 为空字符串(画布上存在无文字的节点,原样保留即可,不要替它虚构文字)。",
538
539
  "- edges[].from / edges[].to:必须是 nodes 中存在的 id。edges[].text 只写分支短标签(是/否、通过/驳回、超时等),普通连线省略。",
539
- "- edges[].fromDir / edges[].toDir(可选):固定这条线从起点哪一侧出(fromDir)与进入终点哪一侧(toDir),取值 top / bottom / left / right。判断节点想固定分支走向(如「是」从右出、「否」从下出)、或用户明确说了出入方向时给出;省略则由程序按布局自动选边。修改现有图时,下方「当前流程图」的边上带有 fromDir/toDir(即当前实际走向):未变更的边必须原样带上这两个字段,只有走向需要变化的边才修改它们。",
540
+ "- edges[].fromDir / edges[].toDir(必填):每条边必须写明从起点哪一侧出(fromDir)与进入终点哪一侧(toDir),取值 top / bottom / left / right。选边规则:默认流程自上而下,普通出边用 bottom、入边用 top;判断节点等多条出边要分散到不同侧(如「是」right「否」bottom,或左右各一);循环/回退边从侧面出侧面回(fromDir 与 toDir 用同一侧,如 right / right);用户明确说了出入方向时按用户说的。修改现有图时,下方「当前流程图」的边上带有 fromDir/toDir(即当前实际走向):未变更的边必须原样带上这两个字段,只有走向需要变化的边才修改它们。",
540
541
  "严格禁止输出 x、y、width、height、坐标、位置等几何字段:布局与坐标由程序自动计算,输出这些字段会导致生成失败。端口方向只允许出现在 edges[].fromDir/toDir 与 updateEdge 操作中,其余位置一律不要输出。",
541
542
  "绘图规则:",
542
543
  "- 有且仅有一个开始节点;判断节点的每条出边都要写分支标签;流程要能走到结束节点。",
@@ -35,6 +35,7 @@ export declare class FlowChart {
35
35
  private disposed;
36
36
  private clipboard;
37
37
  private pasteCount;
38
+ private selectionListeners;
38
39
  constructor(options: FlowChartOptions);
39
40
  private setupEditor;
40
41
  private setupSelection;
@@ -107,6 +108,8 @@ export declare class FlowChart {
107
108
  redo(): boolean;
108
109
  get canUndo(): boolean;
109
110
  get canRedo(): boolean;
111
+ get hasShapeSelection(): boolean;
112
+ onSelectionChange(cb: (hasShapeSelection: boolean) => void): () => void;
110
113
  destroy(): void;
111
114
  private get selShape();
112
115
  private get selEdge();
package/dist/flowchart.js CHANGED
@@ -73,6 +73,8 @@ export class FlowChart {
73
73
  clipboard;
74
74
  // 连续粘贴错开计数(复制时归零):多次粘贴逐次偏移,避免完全重叠
75
75
  pasteCount = 0;
76
+ // 选中变化订阅(onSelectionChange 注册):宿主据此刷新工具条可用态等外部 UI
77
+ selectionListeners = new Set();
76
78
  constructor(options) {
77
79
  this.options = options;
78
80
  this.onChange = options.onChange;
@@ -288,6 +290,12 @@ export class FlowChart {
288
290
  this.app.requestRender();
289
291
  }
290
292
  };
293
+ // 选中变化分发(能力单槽回调 → 多路订阅):hasShape 表示当前是否选中了形状
294
+ selection.onChange = () => {
295
+ const has = selShapesOf(selection).length > 0;
296
+ for (const cb of this.selectionListeners)
297
+ cb(has);
298
+ };
291
299
  return selection;
292
300
  }
293
301
  //#region 公开 API
@@ -1360,6 +1368,19 @@ export class FlowChart {
1360
1368
  get canRedo() {
1361
1369
  return this.history.canRedo;
1362
1370
  }
1371
+ // 是否选中了形状(选中连线或无选中时为 false):替换形状等动作的可用前提
1372
+ get hasShapeSelection() {
1373
+ return selShapesOf(this.sel).length > 0;
1374
+ }
1375
+ // 订阅选中变化(参数为"当前是否选中了形状",注册时先回调一次当前值),
1376
+ // 返回退订函数
1377
+ onSelectionChange(cb) {
1378
+ this.selectionListeners.add(cb);
1379
+ cb(this.hasShapeSelection);
1380
+ return () => {
1381
+ this.selectionListeners.delete(cb);
1382
+ };
1383
+ }
1363
1384
  // 完整拆卸(幂等,页面级销毁或显式装配下重建场景用):
1364
1385
  // 1) 撤销交互监听;2) 复位接线在宿主插件上的场景回调(编辑器/选中可能为
1365
1386
  // 显式装配的宿主所有,避免已销毁门面被插件回调持有);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "silkio-flowchart",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -23,7 +23,11 @@
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
- "license": "ISC",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/kwansen/silkio-flowchart.git"
30
+ },
27
31
  "scripts": {
28
32
  "build": "tsc -p tsconfig.json",
29
33
  "dev": "tsc -p tsconfig.json --watch",