@veltra/sheet 4.1.2 → 4.1.3

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.
@@ -1,3 +1,4 @@
1
+ import { BUILTIN_TOOLS } from "./builtin.js";
1
2
  import { TypedEventEmitter } from "infinitable/sheet";
2
3
  //#region src/tools/registry.ts
3
4
  /** 缺省分组名 */
@@ -6,6 +7,10 @@ var ToolRegistry = class {
6
7
  entries = /* @__PURE__ */ new Map();
7
8
  seq = 0;
8
9
  emitter = new TypedEventEmitter();
10
+ /** 装入初始工具(仍经 register 校验);缺省空表 */
11
+ constructor(tools = []) {
12
+ for (const tool of tools) this.register(tool);
13
+ }
9
14
  /** 注册工具;同 id 重复注册 = 替换定义并保留原注册位置 */
10
15
  register(tool) {
11
16
  if (!tool.id) throw new Error("工具注册失败:id 不能为空");
@@ -59,10 +64,10 @@ var ToolRegistry = class {
59
64
  }
60
65
  };
61
66
  /**
62
- * 全局默认注册表(USheet 默认渲染这里的工具;内置工具也注册于此)。
67
+ * 全局默认注册表(USheet 默认渲染这里的工具;内置工具在构造时装入)。
63
68
  * 工具是应用级扩展:注册一次,所有 USheet 实例共享。
64
69
  */
65
- const defaultToolRegistry = new ToolRegistry();
70
+ const defaultToolRegistry = new ToolRegistry(BUILTIN_TOOLS);
66
71
  /** 注册工具到默认注册表 */
67
72
  function registerTool(tool) {
68
73
  defaultToolRegistry.register(tool);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/sheet",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "homepage": "https://github.com/cabinet-fe/ultra-ui#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/cabinet-fe/ultra-ui/issues"
@@ -18,10 +18,8 @@
18
18
  "sideEffects": [
19
19
  "src/**/style.ts",
20
20
  "src/**/*.scss",
21
- "src/tools/builtin.ts",
22
21
  "dist/**/style.js",
23
- "dist/**/*.css",
24
- "dist/tools/builtin.js"
22
+ "dist/**/*.css"
25
23
  ],
26
24
  "exports": {
27
25
  ".": {
@@ -40,7 +38,7 @@
40
38
  "@veltra/icons": "^1.5.0",
41
39
  "@veltra/styles": "^1.7.14",
42
40
  "@veltra/utils": "^1.7.14",
43
- "infinitable": "^0.2.2",
44
- "vue": ">=3.5.43"
41
+ "infinitable": "^0.2.3",
42
+ "vue": ">=3.5.44"
45
43
  }
46
44
  }
@@ -33,8 +33,10 @@ function createContext2dMock(canvas: HTMLCanvasElement): Context2dMock {
33
33
  })
34
34
  }
35
35
 
36
- /** 补丁 HTMLCanvasElement,使 getContext('2d') 返回可用 mock */
36
+ /** 补丁 HTMLCanvasElement,使 getContext('2d') 返回可用 mock;node 环境无该全局,直接跳过 */
37
37
  export function setupCanvasMock(): void {
38
+ if (typeof HTMLCanvasElement === 'undefined') return
39
+
38
40
  const getContext = function (this: HTMLCanvasElement, contextId: string): unknown {
39
41
  if (contextId !== '2d') return null
40
42
  return createContext2dMock(this)
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
2
4
  import { createApp, h, nextTick, type App } from 'vue'
3
5
 
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { parseRange } from 'infinitable/sheet'
2
4
  import { Workbook } from 'infinitable/sheet'
3
5
  import type { SheetGrid } from 'infinitable/sheet'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  /**
2
4
  * 公式能力可达性(spec 第 4 项 / 下游 meta 报表合计场景):
3
5
  * 写公式(setCellFormula / setCellValue '=' 前缀)、读公式(getCellData().f)、
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { listFormulaFunctions, registerFormulaFunction } from 'infinitable'
2
4
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
3
5
  import { createApp, h, nextTick, type App } from 'vue'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
2
4
  import { createApp, h, type App } from 'vue'
3
5
 
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import type { Sheet } from 'infinitable/sheet'
2
4
  import { Workbook } from 'infinitable/sheet'
3
5
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { ContextmenuRootDIKey } from '@veltra/desktop'
2
4
  import { describe, expect, it, vi } from 'vite-plus/test'
3
5
  import { createApp, h, nextTick } from 'vue'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { Sheet } from 'infinitable/sheet'
2
4
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
3
5
  import { createApp, h, type App } from 'vue'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { Sheet } from 'infinitable/sheet'
2
4
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
3
5
 
@@ -1,12 +1,15 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import type { FloatObject, SceneEvent } from 'infinitable'
2
4
  import { createRange } from 'infinitable/sheet'
3
5
  import { Workbook } from 'infinitable/sheet'
4
6
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
5
7
  import { createApp, h, nextTick, ref, type App, type Component } from 'vue'
6
8
 
7
- import { USheet } from '../../../index'
8
9
  import { registerTool, unregisterTool } from '../../../tools/registry'
9
10
  import type { FloatContextMenuPayload, SheetExposed } from '../../../types'
11
+ // 从组件目录导入:内置工具由注册表构造时装入,不依赖包入口副作用
12
+ import { USheet } from '../index'
10
13
  import { buildColHeaderMenus, buildRowHeaderMenus } from '../sheet-context-menu'
11
14
  // 引擎指针事件模拟与画布几何(cellX/cellY):setup 已跨包引用同目录 setup.ts
12
15
  import { cellX, cellY, fire, gridEventTarget } from './grid-test-utils'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { Workbook } from 'infinitable/sheet'
2
4
  import { afterEach, describe, expect, it } from 'vite-plus/test'
3
5
  import { createApp, h, nextTick, ref, type App } from 'vue'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { Workbook } from 'infinitable/sheet'
2
4
  import { afterEach, describe, expect, it } from 'vite-plus/test'
3
5
  import { createApp, h, nextTick, ref, type App } from 'vue'
@@ -1,3 +1,5 @@
1
+ // @vitest-environment happy-dom
2
+
1
3
  import { currentTheme, lightTheme } from '@veltra/styles/theme'
2
4
  import { Workbook } from 'infinitable/sheet'
3
5
  import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import './tools/builtin'
2
-
3
1
  // SheetContextOptions:createSheetContext(公共导出)的第三参类型——导出函数
4
2
  // 签名引用的稳定类型须随函数可达(无头场景宿主需引用该类型),不属引擎符号
5
3
  export { createSheetContext, type SheetContext, type SheetContextOptions } from './tools/context'
@@ -13,6 +11,6 @@ export {
13
11
  type SheetToolGroup
14
12
  } from './tools/registry'
15
13
 
16
- export { type SheetProps, type SheetEmits, type SheetExposed } from './types'
14
+ export type { SheetProps, SheetEmits, SheetExposed } from './types'
17
15
 
18
16
  export { USheet } from './components/sheet'
@@ -1,6 +1,6 @@
1
- import { createRange } from 'infinitable/sheet'
1
+ // @vitest-environment happy-dom
2
2
 
3
- import '../builtin'
3
+ import { createRange } from 'infinitable/sheet'
4
4
  import { Sheet } from 'infinitable/sheet'
5
5
  import { Workbook } from 'infinitable/sheet'
6
6
  import { describe, expect, it, vi } from 'vite-plus/test'