@univerjs/sheets-graphics 0.20.1 → 0.21.0
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/lib/cjs/index.js +202 -1
- package/lib/es/index.js +190 -1
- package/lib/index.js +190 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,202 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
|
|
4
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
5
|
+
|
|
6
|
+
//#region src/common/const.ts
|
|
7
|
+
/**
|
|
8
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const UNIQUE_KEY = "SheetGraphicsExtension";
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
26
|
+
function _typeof(o) {
|
|
27
|
+
"@babel/helpers - typeof";
|
|
28
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
29
|
+
return typeof o;
|
|
30
|
+
} : function(o) {
|
|
31
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
32
|
+
}, _typeof(o);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
37
|
+
function toPrimitive(t, r) {
|
|
38
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
39
|
+
var e = t[Symbol.toPrimitive];
|
|
40
|
+
if (void 0 !== e) {
|
|
41
|
+
var i = e.call(t, r || "default");
|
|
42
|
+
if ("object" != _typeof(i)) return i;
|
|
43
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
44
|
+
}
|
|
45
|
+
return ("string" === r ? String : Number)(t);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
50
|
+
function toPropertyKey(t) {
|
|
51
|
+
var i = toPrimitive(t, "string");
|
|
52
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
57
|
+
function _defineProperty(e, r, t) {
|
|
58
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
59
|
+
value: t,
|
|
60
|
+
enumerable: !0,
|
|
61
|
+
configurable: !0,
|
|
62
|
+
writable: !0
|
|
63
|
+
}) : e[r] = t, e;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/views/extensions/graphics.extension.ts
|
|
68
|
+
var Graphics = class Graphics extends _univerjs_engine_render.SheetExtension {
|
|
69
|
+
constructor(..._args) {
|
|
70
|
+
super(..._args);
|
|
71
|
+
_defineProperty(this, "uKey", UNIQUE_KEY);
|
|
72
|
+
_defineProperty(this, "Z_INDEX", 35);
|
|
73
|
+
_defineProperty(this, "_graphicsRenderMap", /* @__PURE__ */ new Map());
|
|
74
|
+
}
|
|
75
|
+
registerRenderer(key, renderer) {
|
|
76
|
+
this._graphicsRenderMap.set(key, renderer);
|
|
77
|
+
}
|
|
78
|
+
draw(ctx, _parentScale, skeleton, diffBounds, { viewRanges }) {
|
|
79
|
+
const featureTypes = Array.from(this._graphicsRenderMap.keys());
|
|
80
|
+
viewRanges.forEach((range) => {
|
|
81
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
82
|
+
const cellPosition = skeleton.getCellByIndexWithNoHeader(row, col);
|
|
83
|
+
if (!cellPosition) return;
|
|
84
|
+
featureTypes.forEach((featureType) => {
|
|
85
|
+
const renderer = this._graphicsRenderMap.get(featureType);
|
|
86
|
+
renderer === null || renderer === void 0 || renderer(ctx, skeleton, cellPosition);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
dispose() {
|
|
92
|
+
this._graphicsRenderMap.clear();
|
|
93
|
+
}
|
|
94
|
+
copy() {
|
|
95
|
+
const newGraphics = new Graphics();
|
|
96
|
+
this._graphicsRenderMap.forEach((renderer, key) => {
|
|
97
|
+
newGraphics.registerRenderer(key, renderer);
|
|
98
|
+
});
|
|
99
|
+
return newGraphics;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
105
|
+
function __decorateParam(paramIndex, decorator) {
|
|
106
|
+
return function(target, key) {
|
|
107
|
+
decorator(target, key, paramIndex);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
113
|
+
function __decorate(decorators, target, key, desc) {
|
|
114
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
115
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
116
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
117
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/controllers/graphics-render.controller.ts
|
|
122
|
+
let SheetGraphicsRenderController = class SheetGraphicsRenderController extends _univerjs_core.Disposable {
|
|
123
|
+
constructor(_context, _sheetPrintInterceptorService) {
|
|
124
|
+
super();
|
|
125
|
+
this._context = _context;
|
|
126
|
+
this._sheetPrintInterceptorService = _sheetPrintInterceptorService;
|
|
127
|
+
_defineProperty(this, "_graphicsExtensionInstance", null);
|
|
128
|
+
this._initRender();
|
|
129
|
+
this._initPrinting();
|
|
130
|
+
}
|
|
131
|
+
_initRender() {
|
|
132
|
+
const spreadsheet = this._context.mainComponent;
|
|
133
|
+
if (spreadsheet && !spreadsheet.getExtensionByKey("SheetGraphicsExtension")) {
|
|
134
|
+
this._graphicsExtensionInstance = new Graphics();
|
|
135
|
+
spreadsheet.register(this._graphicsExtensionInstance);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_initPrinting() {
|
|
139
|
+
this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (component, context, next) => {
|
|
140
|
+
const { spreadsheet } = context;
|
|
141
|
+
if (this._graphicsExtensionInstance) spreadsheet.register(this._graphicsExtensionInstance.copy());
|
|
142
|
+
return next(component);
|
|
143
|
+
} }));
|
|
144
|
+
}
|
|
145
|
+
registerRenderer(key, renderer) {
|
|
146
|
+
var _this$_graphicsExtens;
|
|
147
|
+
(_this$_graphicsExtens = this._graphicsExtensionInstance) === null || _this$_graphicsExtens === void 0 || _this$_graphicsExtens.registerRenderer(key, renderer);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
SheetGraphicsRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetPrintInterceptorService))], SheetGraphicsRenderController);
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region package.json
|
|
154
|
+
var name = "@univerjs/sheets-graphics";
|
|
155
|
+
var version = "0.21.0";
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/config/config.ts
|
|
159
|
+
const PLUGIN_CONFIG_KEY = "graphics.config";
|
|
160
|
+
const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
|
|
161
|
+
const defaultPluginConfig = {};
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/plugin.ts
|
|
165
|
+
let UniverSheetsGraphicsPlugin = class UniverSheetsGraphicsPlugin extends _univerjs_core.Plugin {
|
|
166
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerService) {
|
|
167
|
+
super();
|
|
168
|
+
this._config = _config;
|
|
169
|
+
this._injector = _injector;
|
|
170
|
+
this._configService = _configService;
|
|
171
|
+
this._renderManagerService = _renderManagerService;
|
|
172
|
+
const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
173
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
174
|
+
}
|
|
175
|
+
onRendered() {
|
|
176
|
+
[[SheetGraphicsRenderController]].forEach((dep) => {
|
|
177
|
+
this._renderManagerService.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SHEET, dep);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "pluginName", "UNIVER_SHEET_DRAWING_PLUGIN");
|
|
182
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "packageName", name);
|
|
183
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "version", version);
|
|
184
|
+
UniverSheetsGraphicsPlugin = __decorate([
|
|
185
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
186
|
+
__decorateParam(2, _univerjs_core.IConfigService),
|
|
187
|
+
__decorateParam(3, _univerjs_engine_render.IRenderManagerService)
|
|
188
|
+
], UniverSheetsGraphicsPlugin);
|
|
189
|
+
|
|
190
|
+
//#endregion
|
|
191
|
+
Object.defineProperty(exports, 'SheetGraphicsRenderController', {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
get: function () {
|
|
194
|
+
return SheetGraphicsRenderController;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(exports, 'UniverSheetsGraphicsPlugin', {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () {
|
|
200
|
+
return UniverSheetsGraphicsPlugin;
|
|
201
|
+
}
|
|
202
|
+
});
|
package/lib/es/index.js
CHANGED
|
@@ -1 +1,190 @@
|
|
|
1
|
-
import{Disposable
|
|
1
|
+
import { Disposable, IConfigService, Inject, Injector, Plugin, Range, UniverInstanceType, merge } from "@univerjs/core";
|
|
2
|
+
import { SheetPrintInterceptorService } from "@univerjs/sheets-ui";
|
|
3
|
+
import { IRenderManagerService, SheetExtension } from "@univerjs/engine-render";
|
|
4
|
+
|
|
5
|
+
//#region src/common/const.ts
|
|
6
|
+
/**
|
|
7
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
const UNIQUE_KEY = "SheetGraphicsExtension";
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
25
|
+
function _typeof(o) {
|
|
26
|
+
"@babel/helpers - typeof";
|
|
27
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
28
|
+
return typeof o;
|
|
29
|
+
} : function(o) {
|
|
30
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
31
|
+
}, _typeof(o);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
36
|
+
function toPrimitive(t, r) {
|
|
37
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
38
|
+
var e = t[Symbol.toPrimitive];
|
|
39
|
+
if (void 0 !== e) {
|
|
40
|
+
var i = e.call(t, r || "default");
|
|
41
|
+
if ("object" != _typeof(i)) return i;
|
|
42
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
43
|
+
}
|
|
44
|
+
return ("string" === r ? String : Number)(t);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
49
|
+
function toPropertyKey(t) {
|
|
50
|
+
var i = toPrimitive(t, "string");
|
|
51
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
56
|
+
function _defineProperty(e, r, t) {
|
|
57
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
58
|
+
value: t,
|
|
59
|
+
enumerable: !0,
|
|
60
|
+
configurable: !0,
|
|
61
|
+
writable: !0
|
|
62
|
+
}) : e[r] = t, e;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/views/extensions/graphics.extension.ts
|
|
67
|
+
var Graphics = class Graphics extends SheetExtension {
|
|
68
|
+
constructor(..._args) {
|
|
69
|
+
super(..._args);
|
|
70
|
+
_defineProperty(this, "uKey", UNIQUE_KEY);
|
|
71
|
+
_defineProperty(this, "Z_INDEX", 35);
|
|
72
|
+
_defineProperty(this, "_graphicsRenderMap", /* @__PURE__ */ new Map());
|
|
73
|
+
}
|
|
74
|
+
registerRenderer(key, renderer) {
|
|
75
|
+
this._graphicsRenderMap.set(key, renderer);
|
|
76
|
+
}
|
|
77
|
+
draw(ctx, _parentScale, skeleton, diffBounds, { viewRanges }) {
|
|
78
|
+
const featureTypes = Array.from(this._graphicsRenderMap.keys());
|
|
79
|
+
viewRanges.forEach((range) => {
|
|
80
|
+
Range.foreach(range, (row, col) => {
|
|
81
|
+
const cellPosition = skeleton.getCellByIndexWithNoHeader(row, col);
|
|
82
|
+
if (!cellPosition) return;
|
|
83
|
+
featureTypes.forEach((featureType) => {
|
|
84
|
+
const renderer = this._graphicsRenderMap.get(featureType);
|
|
85
|
+
renderer === null || renderer === void 0 || renderer(ctx, skeleton, cellPosition);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
dispose() {
|
|
91
|
+
this._graphicsRenderMap.clear();
|
|
92
|
+
}
|
|
93
|
+
copy() {
|
|
94
|
+
const newGraphics = new Graphics();
|
|
95
|
+
this._graphicsRenderMap.forEach((renderer, key) => {
|
|
96
|
+
newGraphics.registerRenderer(key, renderer);
|
|
97
|
+
});
|
|
98
|
+
return newGraphics;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
104
|
+
function __decorateParam(paramIndex, decorator) {
|
|
105
|
+
return function(target, key) {
|
|
106
|
+
decorator(target, key, paramIndex);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
112
|
+
function __decorate(decorators, target, key, desc) {
|
|
113
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
114
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
115
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
116
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/controllers/graphics-render.controller.ts
|
|
121
|
+
let SheetGraphicsRenderController = class SheetGraphicsRenderController extends Disposable {
|
|
122
|
+
constructor(_context, _sheetPrintInterceptorService) {
|
|
123
|
+
super();
|
|
124
|
+
this._context = _context;
|
|
125
|
+
this._sheetPrintInterceptorService = _sheetPrintInterceptorService;
|
|
126
|
+
_defineProperty(this, "_graphicsExtensionInstance", null);
|
|
127
|
+
this._initRender();
|
|
128
|
+
this._initPrinting();
|
|
129
|
+
}
|
|
130
|
+
_initRender() {
|
|
131
|
+
const spreadsheet = this._context.mainComponent;
|
|
132
|
+
if (spreadsheet && !spreadsheet.getExtensionByKey("SheetGraphicsExtension")) {
|
|
133
|
+
this._graphicsExtensionInstance = new Graphics();
|
|
134
|
+
spreadsheet.register(this._graphicsExtensionInstance);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
_initPrinting() {
|
|
138
|
+
this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (component, context, next) => {
|
|
139
|
+
const { spreadsheet } = context;
|
|
140
|
+
if (this._graphicsExtensionInstance) spreadsheet.register(this._graphicsExtensionInstance.copy());
|
|
141
|
+
return next(component);
|
|
142
|
+
} }));
|
|
143
|
+
}
|
|
144
|
+
registerRenderer(key, renderer) {
|
|
145
|
+
var _this$_graphicsExtens;
|
|
146
|
+
(_this$_graphicsExtens = this._graphicsExtensionInstance) === null || _this$_graphicsExtens === void 0 || _this$_graphicsExtens.registerRenderer(key, renderer);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
SheetGraphicsRenderController = __decorate([__decorateParam(1, Inject(SheetPrintInterceptorService))], SheetGraphicsRenderController);
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region package.json
|
|
153
|
+
var name = "@univerjs/sheets-graphics";
|
|
154
|
+
var version = "0.21.0";
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/config/config.ts
|
|
158
|
+
const PLUGIN_CONFIG_KEY = "graphics.config";
|
|
159
|
+
const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
|
|
160
|
+
const defaultPluginConfig = {};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/plugin.ts
|
|
164
|
+
let UniverSheetsGraphicsPlugin = class UniverSheetsGraphicsPlugin extends Plugin {
|
|
165
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerService) {
|
|
166
|
+
super();
|
|
167
|
+
this._config = _config;
|
|
168
|
+
this._injector = _injector;
|
|
169
|
+
this._configService = _configService;
|
|
170
|
+
this._renderManagerService = _renderManagerService;
|
|
171
|
+
const { ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
172
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
173
|
+
}
|
|
174
|
+
onRendered() {
|
|
175
|
+
[[SheetGraphicsRenderController]].forEach((dep) => {
|
|
176
|
+
this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, dep);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "pluginName", "UNIVER_SHEET_DRAWING_PLUGIN");
|
|
181
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "packageName", name);
|
|
182
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "version", version);
|
|
183
|
+
UniverSheetsGraphicsPlugin = __decorate([
|
|
184
|
+
__decorateParam(1, Inject(Injector)),
|
|
185
|
+
__decorateParam(2, IConfigService),
|
|
186
|
+
__decorateParam(3, IRenderManagerService)
|
|
187
|
+
], UniverSheetsGraphicsPlugin);
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
export { SheetGraphicsRenderController, UniverSheetsGraphicsPlugin };
|
package/lib/index.js
CHANGED
|
@@ -1 +1,190 @@
|
|
|
1
|
-
import{Disposable
|
|
1
|
+
import { Disposable, IConfigService, Inject, Injector, Plugin, Range, UniverInstanceType, merge } from "@univerjs/core";
|
|
2
|
+
import { SheetPrintInterceptorService } from "@univerjs/sheets-ui";
|
|
3
|
+
import { IRenderManagerService, SheetExtension } from "@univerjs/engine-render";
|
|
4
|
+
|
|
5
|
+
//#region src/common/const.ts
|
|
6
|
+
/**
|
|
7
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
const UNIQUE_KEY = "SheetGraphicsExtension";
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
25
|
+
function _typeof(o) {
|
|
26
|
+
"@babel/helpers - typeof";
|
|
27
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
28
|
+
return typeof o;
|
|
29
|
+
} : function(o) {
|
|
30
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
31
|
+
}, _typeof(o);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
36
|
+
function toPrimitive(t, r) {
|
|
37
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
38
|
+
var e = t[Symbol.toPrimitive];
|
|
39
|
+
if (void 0 !== e) {
|
|
40
|
+
var i = e.call(t, r || "default");
|
|
41
|
+
if ("object" != _typeof(i)) return i;
|
|
42
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
43
|
+
}
|
|
44
|
+
return ("string" === r ? String : Number)(t);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
49
|
+
function toPropertyKey(t) {
|
|
50
|
+
var i = toPrimitive(t, "string");
|
|
51
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
56
|
+
function _defineProperty(e, r, t) {
|
|
57
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
58
|
+
value: t,
|
|
59
|
+
enumerable: !0,
|
|
60
|
+
configurable: !0,
|
|
61
|
+
writable: !0
|
|
62
|
+
}) : e[r] = t, e;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/views/extensions/graphics.extension.ts
|
|
67
|
+
var Graphics = class Graphics extends SheetExtension {
|
|
68
|
+
constructor(..._args) {
|
|
69
|
+
super(..._args);
|
|
70
|
+
_defineProperty(this, "uKey", UNIQUE_KEY);
|
|
71
|
+
_defineProperty(this, "Z_INDEX", 35);
|
|
72
|
+
_defineProperty(this, "_graphicsRenderMap", /* @__PURE__ */ new Map());
|
|
73
|
+
}
|
|
74
|
+
registerRenderer(key, renderer) {
|
|
75
|
+
this._graphicsRenderMap.set(key, renderer);
|
|
76
|
+
}
|
|
77
|
+
draw(ctx, _parentScale, skeleton, diffBounds, { viewRanges }) {
|
|
78
|
+
const featureTypes = Array.from(this._graphicsRenderMap.keys());
|
|
79
|
+
viewRanges.forEach((range) => {
|
|
80
|
+
Range.foreach(range, (row, col) => {
|
|
81
|
+
const cellPosition = skeleton.getCellByIndexWithNoHeader(row, col);
|
|
82
|
+
if (!cellPosition) return;
|
|
83
|
+
featureTypes.forEach((featureType) => {
|
|
84
|
+
const renderer = this._graphicsRenderMap.get(featureType);
|
|
85
|
+
renderer === null || renderer === void 0 || renderer(ctx, skeleton, cellPosition);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
dispose() {
|
|
91
|
+
this._graphicsRenderMap.clear();
|
|
92
|
+
}
|
|
93
|
+
copy() {
|
|
94
|
+
const newGraphics = new Graphics();
|
|
95
|
+
this._graphicsRenderMap.forEach((renderer, key) => {
|
|
96
|
+
newGraphics.registerRenderer(key, renderer);
|
|
97
|
+
});
|
|
98
|
+
return newGraphics;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
104
|
+
function __decorateParam(paramIndex, decorator) {
|
|
105
|
+
return function(target, key) {
|
|
106
|
+
decorator(target, key, paramIndex);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
112
|
+
function __decorate(decorators, target, key, desc) {
|
|
113
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
114
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
115
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
116
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/controllers/graphics-render.controller.ts
|
|
121
|
+
let SheetGraphicsRenderController = class SheetGraphicsRenderController extends Disposable {
|
|
122
|
+
constructor(_context, _sheetPrintInterceptorService) {
|
|
123
|
+
super();
|
|
124
|
+
this._context = _context;
|
|
125
|
+
this._sheetPrintInterceptorService = _sheetPrintInterceptorService;
|
|
126
|
+
_defineProperty(this, "_graphicsExtensionInstance", null);
|
|
127
|
+
this._initRender();
|
|
128
|
+
this._initPrinting();
|
|
129
|
+
}
|
|
130
|
+
_initRender() {
|
|
131
|
+
const spreadsheet = this._context.mainComponent;
|
|
132
|
+
if (spreadsheet && !spreadsheet.getExtensionByKey("SheetGraphicsExtension")) {
|
|
133
|
+
this._graphicsExtensionInstance = new Graphics();
|
|
134
|
+
spreadsheet.register(this._graphicsExtensionInstance);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
_initPrinting() {
|
|
138
|
+
this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (component, context, next) => {
|
|
139
|
+
const { spreadsheet } = context;
|
|
140
|
+
if (this._graphicsExtensionInstance) spreadsheet.register(this._graphicsExtensionInstance.copy());
|
|
141
|
+
return next(component);
|
|
142
|
+
} }));
|
|
143
|
+
}
|
|
144
|
+
registerRenderer(key, renderer) {
|
|
145
|
+
var _this$_graphicsExtens;
|
|
146
|
+
(_this$_graphicsExtens = this._graphicsExtensionInstance) === null || _this$_graphicsExtens === void 0 || _this$_graphicsExtens.registerRenderer(key, renderer);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
SheetGraphicsRenderController = __decorate([__decorateParam(1, Inject(SheetPrintInterceptorService))], SheetGraphicsRenderController);
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region package.json
|
|
153
|
+
var name = "@univerjs/sheets-graphics";
|
|
154
|
+
var version = "0.21.0";
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/config/config.ts
|
|
158
|
+
const PLUGIN_CONFIG_KEY = "graphics.config";
|
|
159
|
+
const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
|
|
160
|
+
const defaultPluginConfig = {};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/plugin.ts
|
|
164
|
+
let UniverSheetsGraphicsPlugin = class UniverSheetsGraphicsPlugin extends Plugin {
|
|
165
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerService) {
|
|
166
|
+
super();
|
|
167
|
+
this._config = _config;
|
|
168
|
+
this._injector = _injector;
|
|
169
|
+
this._configService = _configService;
|
|
170
|
+
this._renderManagerService = _renderManagerService;
|
|
171
|
+
const { ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
172
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
173
|
+
}
|
|
174
|
+
onRendered() {
|
|
175
|
+
[[SheetGraphicsRenderController]].forEach((dep) => {
|
|
176
|
+
this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, dep);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "pluginName", "UNIVER_SHEET_DRAWING_PLUGIN");
|
|
181
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "packageName", name);
|
|
182
|
+
_defineProperty(UniverSheetsGraphicsPlugin, "version", version);
|
|
183
|
+
UniverSheetsGraphicsPlugin = __decorate([
|
|
184
|
+
__decorateParam(1, Inject(Injector)),
|
|
185
|
+
__decorateParam(2, IConfigService),
|
|
186
|
+
__decorateParam(3, IRenderManagerService)
|
|
187
|
+
], UniverSheetsGraphicsPlugin);
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
export { SheetGraphicsRenderController, UniverSheetsGraphicsPlugin };
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-ui`),require(`@univerjs/engine-render`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-ui`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsGraphics={},e.UniverCore,e.UniverSheetsUi,e.UniverEngineRender))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class e extends r.SheetExtension{constructor(...e){super(...e),s(this,`uKey`,`SheetGraphicsExtension`),s(this,`Z_INDEX`,35),s(this,`_graphicsRenderMap`,new Map)}registerRenderer(e,t){this._graphicsRenderMap.set(e,t)}draw(e,n,r,i,{viewRanges:a}){let o=Array.from(this._graphicsRenderMap.keys());a.forEach(n=>{t.Range.foreach(n,(t,n)=>{let i=r.getCellByIndexWithNoHeader(t,n);i&&o.forEach(t=>{let n=this._graphicsRenderMap.get(t);n==null||n(e,r,i)})})})}dispose(){this._graphicsRenderMap.clear()}copy(){let t=new e;return this._graphicsRenderMap.forEach((e,n)=>{t.registerRenderer(n,e)}),t}};function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends t.Disposable{constructor(e,t){super(),this._context=e,this._sheetPrintInterceptorService=t,s(this,`_graphicsExtensionInstance`,null),this._initRender(),this._initPrinting()}_initRender(){let e=this._context.mainComponent;e&&!e.getExtensionByKey(`SheetGraphicsExtension`)&&(this._graphicsExtensionInstance=new c,e.register(this._graphicsExtensionInstance))}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,t,n)=>{let{spreadsheet:r}=t;return this._graphicsExtensionInstance&&r.register(this._graphicsExtensionInstance.copy()),n(e)}}))}registerRenderer(e,t){var n;(n=this._graphicsExtensionInstance)==null||n.registerRenderer(e,t)}};d=u([l(1,(0,t.Inject)(n.SheetPrintInterceptorService))],d);var f=`@univerjs/sheets-graphics`,p=`0.
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-ui`),require(`@univerjs/engine-render`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-ui`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsGraphics={},e.UniverCore,e.UniverSheetsUi,e.UniverEngineRender))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class e extends r.SheetExtension{constructor(...e){super(...e),s(this,`uKey`,`SheetGraphicsExtension`),s(this,`Z_INDEX`,35),s(this,`_graphicsRenderMap`,new Map)}registerRenderer(e,t){this._graphicsRenderMap.set(e,t)}draw(e,n,r,i,{viewRanges:a}){let o=Array.from(this._graphicsRenderMap.keys());a.forEach(n=>{t.Range.foreach(n,(t,n)=>{let i=r.getCellByIndexWithNoHeader(t,n);i&&o.forEach(t=>{let n=this._graphicsRenderMap.get(t);n==null||n(e,r,i)})})})}dispose(){this._graphicsRenderMap.clear()}copy(){let t=new e;return this._graphicsRenderMap.forEach((e,n)=>{t.registerRenderer(n,e)}),t}};function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends t.Disposable{constructor(e,t){super(),this._context=e,this._sheetPrintInterceptorService=t,s(this,`_graphicsExtensionInstance`,null),this._initRender(),this._initPrinting()}_initRender(){let e=this._context.mainComponent;e&&!e.getExtensionByKey(`SheetGraphicsExtension`)&&(this._graphicsExtensionInstance=new c,e.register(this._graphicsExtensionInstance))}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,t,n)=>{let{spreadsheet:r}=t;return this._graphicsExtensionInstance&&r.register(this._graphicsExtensionInstance.copy()),n(e)}}))}registerRenderer(e,t){var n;(n=this._graphicsExtensionInstance)==null||n.registerRenderer(e,t)}};d=u([l(1,(0,t.Inject)(n.SheetPrintInterceptorService))],d);var f=`@univerjs/sheets-graphics`,p=`0.21.0`;let m=`graphics.config`;Symbol(m);let h={},g=class extends t.Plugin{constructor(e=h,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerService=i;let{...a}=(0,t.merge)({},h,this._config);this._configService.setConfig(m,a)}onRendered(){[[d]].forEach(e=>{this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e)})}};s(g,`pluginName`,`UNIVER_SHEET_DRAWING_PLUGIN`),s(g,`packageName`,f),s(g,`version`,p),g=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.IConfigService),l(3,r.IRenderManagerService)],g),Object.defineProperty(e,`SheetGraphicsRenderController`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,`UniverSheetsGraphicsPlugin`,{enumerable:!0,get:function(){return g}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-graphics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Drawing graphics for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"lib"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@univerjs/
|
|
47
|
-
"@univerjs/
|
|
48
|
-
"@univerjs/
|
|
46
|
+
"@univerjs/engine-render": "0.21.0",
|
|
47
|
+
"@univerjs/sheets-ui": "0.21.0",
|
|
48
|
+
"@univerjs/core": "0.21.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"typescript": "^6.0.2",
|
|
52
|
-
"vitest": "^4.1.
|
|
53
|
-
"@univerjs-infra/shared": "0.
|
|
52
|
+
"vitest": "^4.1.4",
|
|
53
|
+
"@univerjs-infra/shared": "0.21.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"test": "vitest run",
|