mirror of
https://github.com/ljcoder2015/obsidian-excel.git
synced 2026-07-22 08:30:28 +00:00
298 lines
10 KiB
Diff
298 lines
10 KiB
Diff
diff --git a/node_modules/x-data-spreadsheet/src/component/event.js b/node_modules/x-data-spreadsheet/src/component/event.js
|
|
index cdbc0fa..cb2a9db 100644
|
|
--- a/node_modules/x-data-spreadsheet/src/component/event.js
|
|
+++ b/node_modules/x-data-spreadsheet/src/component/event.js
|
|
@@ -74,6 +74,7 @@ export function bindTouch(target, { move, end }) {
|
|
starty = pageY;
|
|
}
|
|
evt.preventDefault();
|
|
+ evt.stopPropagation();
|
|
});
|
|
bind(target, 'touchend', (evt) => {
|
|
if (!end) return;
|
|
diff --git a/node_modules/x-data-spreadsheet/src/component/sheet.js b/node_modules/x-data-spreadsheet/src/component/sheet.js
|
|
index 086b8c4..264823c 100644
|
|
--- a/node_modules/x-data-spreadsheet/src/component/sheet.js
|
|
+++ b/node_modules/x-data-spreadsheet/src/component/sheet.js
|
|
@@ -77,11 +77,11 @@ function selectorSet(multiple, ri, ci, indexesUpdated = true, moving = false) {
|
|
const cell = data.getCell(ri, ci);
|
|
if (multiple) {
|
|
selector.setEnd(ri, ci, moving);
|
|
- this.trigger('cells-selected', cell, selector.range);
|
|
+ this.trigger('cells-selected', this.data, selector.range);
|
|
} else {
|
|
// trigger click event
|
|
selector.set(ri, ci, indexesUpdated);
|
|
- this.trigger('cell-selected', cell, ri, ci);
|
|
+ this.trigger('cell-selected', this.data, ri, ci);
|
|
}
|
|
toolbar.reset();
|
|
table.render();
|
|
@@ -854,7 +854,7 @@ function sheetInitEvents() {
|
|
}
|
|
|
|
export default class Sheet {
|
|
- constructor(targetEl, data) {
|
|
+ constructor(targetEl, data, isDark) {
|
|
this.eventMap = createEventEmitter();
|
|
const { view, showToolbar, showContextmenu } = data.settings;
|
|
this.el = h('div', `${cssPrefix}-sheet`);
|
|
@@ -904,7 +904,7 @@ export default class Sheet {
|
|
this.sortFilter.el,
|
|
);
|
|
// table
|
|
- this.table = new Table(this.tableEl.el, data);
|
|
+ this.table = new Table(this.tableEl.el, data, isDark);
|
|
sheetInitEvents.call(this);
|
|
sheetReset.call(this);
|
|
// init selector [0, 0]
|
|
diff --git a/node_modules/x-data-spreadsheet/src/component/table.js b/node_modules/x-data-spreadsheet/src/component/table.js
|
|
index 41e1e14..09ac678 100644
|
|
--- a/node_modules/x-data-spreadsheet/src/component/table.js
|
|
+++ b/node_modules/x-data-spreadsheet/src/component/table.js
|
|
@@ -7,22 +7,23 @@ import { formatm } from '../core/format';
|
|
import {
|
|
Draw, DrawBox, thinLineWidth, npx,
|
|
} from '../canvas/draw';
|
|
+import { idText } from 'typescript';
|
|
// gobal var
|
|
const cellPaddingWidth = 5;
|
|
const tableFixedHeaderCleanStyle = { fillStyle: '#f4f5f8' };
|
|
-const tableGridStyle = {
|
|
+var tableGridStyle = {
|
|
fillStyle: '#fff',
|
|
lineWidth: thinLineWidth,
|
|
strokeStyle: '#e6e6e6',
|
|
};
|
|
-function tableFixedHeaderStyle() {
|
|
+function tableFixedHeaderStyle(isDark) {
|
|
return {
|
|
textAlign: 'center',
|
|
textBaseline: 'middle',
|
|
font: `500 ${npx(12)}px Source Sans Pro`,
|
|
- fillStyle: '#585757',
|
|
+ fillStyle: isDark ? '#dcdcdc' : '#585757',
|
|
lineWidth: thinLineWidth(),
|
|
- strokeStyle: '#e6e6e6',
|
|
+ strokeStyle: isDark ? '#c0c0c0': '#e6e6e6',
|
|
};
|
|
}
|
|
|
|
@@ -184,13 +185,18 @@ function renderSelectedHeaderCell(x, y, w, h) {
|
|
// h: the fixed height of header
|
|
// tx: moving distance on x-axis
|
|
// ty: moving distance on y-axis
|
|
-function renderFixedHeaders(type, viewRange, w, h, tx, ty) {
|
|
+function renderFixedHeaders(type, viewRange, w, h, tx, ty, isDark) {
|
|
const { draw, data } = this;
|
|
const sumHeight = viewRange.h; // rows.sumHeight(viewRange.sri, viewRange.eri + 1);
|
|
const sumWidth = viewRange.w; // cols.sumWidth(viewRange.sci, viewRange.eci + 1);
|
|
const nty = ty + h;
|
|
const ntx = tx + w;
|
|
|
|
+ if (isDark) {
|
|
+ tableFixedHeaderCleanStyle.fillStyle = '#595d88'
|
|
+ tableFixedHeaderCleanStyle.strokeStyle = '#5d5d5d'
|
|
+ }
|
|
+
|
|
draw.save();
|
|
// draw rect background
|
|
draw.attr(tableFixedHeaderCleanStyle);
|
|
@@ -203,7 +209,7 @@ function renderFixedHeaders(type, viewRange, w, h, tx, ty) {
|
|
// console.log(data.selectIndexes);
|
|
// draw text
|
|
// text font, align...
|
|
- draw.attr(tableFixedHeaderStyle());
|
|
+ draw.attr(tableFixedHeaderStyle(isDark));
|
|
// y-header-text
|
|
if (type === 'all' || type === 'left') {
|
|
data.rowEach(viewRange.sri, viewRange.eri, (i, y1, rowHeight) => {
|
|
@@ -247,21 +253,25 @@ function renderFixedHeaders(type, viewRange, w, h, tx, ty) {
|
|
draw.restore();
|
|
}
|
|
|
|
-function renderFixedLeftTopCell(fw, fh) {
|
|
+function renderFixedLeftTopCell(fw, fh, isDark) {
|
|
const { draw } = this;
|
|
draw.save();
|
|
// left-top-cell
|
|
- draw.attr({ fillStyle: '#f4f5f8' })
|
|
+ draw.attr({ fillStyle: isDark ? '#595d88' : '#f4f5f8', strokeStyle: isDark ? '#5d5d5d' : '#e6e6e6' })
|
|
.fillRect(0, 0, fw, fh);
|
|
draw.restore();
|
|
}
|
|
|
|
function renderContentGrid({
|
|
sri, sci, eri, eci, w, h,
|
|
-}, fw, fh, tx, ty) {
|
|
+}, fw, fh, tx, ty, isDark) {
|
|
const { draw, data } = this;
|
|
const { settings } = data;
|
|
|
|
+ if (isDark) {
|
|
+ tableGridStyle.strokeStyle = '#5d5d5d'
|
|
+ }
|
|
+
|
|
draw.save();
|
|
draw.attr(tableGridStyle)
|
|
.translate(fw + tx, fh + ty);
|
|
@@ -300,10 +310,11 @@ function renderFreezeHighlightLine(fw, fh, ftw, fth) {
|
|
|
|
/** end */
|
|
class Table {
|
|
- constructor(el, data) {
|
|
+ constructor(el, data, isDark) {
|
|
this.el = el;
|
|
this.draw = new Draw(el, data.viewWidth(), data.viewHeight());
|
|
this.data = data;
|
|
+ this.isDark = isDark
|
|
}
|
|
|
|
resetData(data) {
|
|
@@ -329,10 +340,10 @@ class Table {
|
|
const ty = data.freezeTotalHeight();
|
|
const { x, y } = data.scroll;
|
|
// 1
|
|
- renderContentGrid.call(this, viewRange, fw, fh, tx, ty);
|
|
+ renderContentGrid.call(this, viewRange, fw, fh, tx, ty, this.isDark);
|
|
renderContent.call(this, viewRange, fw, fh, -x, -y);
|
|
- renderFixedHeaders.call(this, 'all', viewRange, fw, fh, tx, ty);
|
|
- renderFixedLeftTopCell.call(this, fw, fh);
|
|
+ renderFixedHeaders.call(this, 'all', viewRange, fw, fh, tx, ty, this.isDark);
|
|
+ renderFixedLeftTopCell.call(this, fw, fh, this.isDark);
|
|
const [fri, fci] = data.freeze;
|
|
if (fri > 0 || fci > 0) {
|
|
// 2
|
|
@@ -343,7 +354,7 @@ class Table {
|
|
vr.h = ty;
|
|
renderContentGrid.call(this, vr, fw, fh, tx, 0);
|
|
renderContent.call(this, vr, fw, fh, -x, 0);
|
|
- renderFixedHeaders.call(this, 'top', vr, fw, fh, tx, 0);
|
|
+ renderFixedHeaders.call(this, 'top', vr, fw, fh, tx, 0, this.isDark);
|
|
}
|
|
// 3
|
|
if (fci > 0) {
|
|
@@ -352,13 +363,13 @@ class Table {
|
|
vr.eci = fci - 1;
|
|
vr.w = tx;
|
|
renderContentGrid.call(this, vr, fw, fh, 0, ty);
|
|
- renderFixedHeaders.call(this, 'left', vr, fw, fh, 0, ty);
|
|
+ renderFixedHeaders.call(this, 'left', vr, fw, fh, 0, ty, this.isDark);
|
|
renderContent.call(this, vr, fw, fh, 0, -y);
|
|
}
|
|
// 4
|
|
const freezeViewRange = data.freezeViewRange();
|
|
renderContentGrid.call(this, freezeViewRange, fw, fh, 0, 0);
|
|
- renderFixedHeaders.call(this, 'all', freezeViewRange, fw, fh, 0, 0);
|
|
+ renderFixedHeaders.call(this, 'all', freezeViewRange, fw, fh, 0, 0, this.isDark);
|
|
renderContent.call(this, freezeViewRange, fw, fh, 0, 0);
|
|
// 5
|
|
renderFreezeHighlightLine.call(this, fw, fh, tx, ty);
|
|
diff --git a/node_modules/x-data-spreadsheet/src/index.d.ts b/node_modules/x-data-spreadsheet/src/index.d.ts
|
|
index 948a8e9..72fb91e 100644
|
|
--- a/node_modules/x-data-spreadsheet/src/index.d.ts
|
|
+++ b/node_modules/x-data-spreadsheet/src/index.d.ts
|
|
@@ -34,6 +34,7 @@ declare module 'x-data-spreadsheet' {
|
|
italic: false;
|
|
};
|
|
};
|
|
+ isDark: boolean;
|
|
}
|
|
|
|
export type CELL_SELECTED = 'cell-selected';
|
|
@@ -45,18 +46,18 @@ declare module 'x-data-spreadsheet' {
|
|
export interface SpreadsheetEventHandler {
|
|
(
|
|
envt: CELL_SELECTED,
|
|
- callback: (cell: Cell, rowIndex: number, colIndex: number) => void
|
|
+ callback: (sheetData: Record<string, any>, rowIndex: number, colIndex: number) => void
|
|
): void;
|
|
(
|
|
envt: CELLS_SELECTED,
|
|
callback: (
|
|
- cell: Cell,
|
|
+ sheetData: Record<string, any>,
|
|
parameters: { sri: number; sci: number; eri: number; eci: number }
|
|
) => void
|
|
): void;
|
|
(
|
|
evnt: CELL_EDITED,
|
|
- callback: (text: string, rowIndex: number, colIndex: number) => void
|
|
+ callback: (sheetData: Record<string, any>, rowIndex: number, colIndex: number) => void
|
|
): void;
|
|
}
|
|
|
|
@@ -182,6 +183,19 @@ declare module 'x-data-spreadsheet' {
|
|
* @param callback
|
|
*/
|
|
change(callback: (json: Record<string, any>) => void): this;
|
|
+
|
|
+ /**
|
|
+ * 添加sheet监听回调
|
|
+ * @param callback
|
|
+ */
|
|
+ onAddSheet(callback: () => void): this;
|
|
+
|
|
+ /**
|
|
+ * 重命名Sheet
|
|
+ * @param callback
|
|
+ */
|
|
+ onRenameSheet(callback: () => void): this;
|
|
+
|
|
/**
|
|
* set locale
|
|
* @param lang
|
|
diff --git a/node_modules/x-data-spreadsheet/src/index.js b/node_modules/x-data-spreadsheet/src/index.js
|
|
index 479a0b7..ae82d34 100644
|
|
--- a/node_modules/x-data-spreadsheet/src/index.js
|
|
+++ b/node_modules/x-data-spreadsheet/src/index.js
|
|
@@ -11,7 +11,7 @@ import './index.less';
|
|
class Spreadsheet {
|
|
constructor(selectors, options = {}) {
|
|
let targetEl = selectors;
|
|
- this.options = { showBottomBar: true, ...options };
|
|
+ this.options = { isDark: false, showBottomBar: true, ...options };
|
|
this.sheetIndex = 1;
|
|
this.datas = [];
|
|
if (typeof selectors === 'string') {
|
|
@@ -20,6 +20,7 @@ class Spreadsheet {
|
|
this.bottombar = this.options.showBottomBar ? new Bottombar(() => {
|
|
const d = this.addSheet();
|
|
this.sheet.resetData(d);
|
|
+ this.sheet.trigger('add-sheet', "")
|
|
}, (index) => {
|
|
const d = this.datas[index];
|
|
this.sheet.resetData(d);
|
|
@@ -27,13 +28,14 @@ class Spreadsheet {
|
|
this.deleteSheet();
|
|
}, (index, value) => {
|
|
this.datas[index].name = value;
|
|
+ this.sheet.trigger('rename-sheet', value)
|
|
}) : null;
|
|
this.data = this.addSheet();
|
|
const rootEl = h('div', `${cssPrefix}`)
|
|
.on('contextmenu', evt => evt.preventDefault());
|
|
// create canvas element
|
|
targetEl.appendChild(rootEl.el);
|
|
- this.sheet = new Sheet(rootEl, this.data);
|
|
+ this.sheet = new Sheet(rootEl, this.data, options.isDark);
|
|
if (this.bottombar !== null) {
|
|
rootEl.child(this.bottombar.el);
|
|
}
|
|
@@ -120,6 +122,16 @@ class Spreadsheet {
|
|
return this;
|
|
}
|
|
|
|
+ onAddSheet(cb) {
|
|
+ this.sheet.on('add-sheet', cb);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ onRenameSheet(cb) {
|
|
+ this.sheet.on('rename-sheet', cb);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
static locale(lang, message) {
|
|
locale(lang, message);
|
|
}
|