Skip to content

Commit

Permalink
Fixed to adjust message position if it is placed outside the Grid. (#418
Browse files Browse the repository at this point in the history
)

* Fixed to adjust message position if the is is placed outside the Grid.

* update
  • Loading branch information
ota-meshi authored Feb 28, 2024
1 parent 0e00324 commit bb08d46
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"vue"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"[markdown]": {
"editor.formatOnSave": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/cheetah-grid/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true,
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit"
},
"editor.codeActionsOnSaveTimeout": 10000,
}
2 changes: 1 addition & 1 deletion packages/cheetah-grid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cheetah-grid",
"version": "1.13.1",
"version": "1.13.2",
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
"keywords": [
"spreadsheet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CLASSNAME = "cheetah-grid__message-element";
const MESSAGE_CLASSNAME = `${CLASSNAME}__message`;
const HIDDEN_CLASSNAME = `${CLASSNAME}--hidden`;
const SHOWN_CLASSNAME = `${CLASSNAME}--shown`;
const LEFT_DIFF_CSS_PROP_NAME = "--cheetah-grid-message-element-left-diff";

function createMessageDomElement(): HTMLElement {
require("@/columns/message/internal/MessageElement.css");
Expand Down Expand Up @@ -55,6 +56,8 @@ export class MessageElement {
rootElement.classList.remove(HIDDEN_CLASSNAME);

messageElement.textContent = message.message;

this._adjustStyle(grid, col, row);
} else {
this._detach();
}
Expand Down Expand Up @@ -92,31 +95,31 @@ export class MessageElement {
grid.getCellRange(col, frozenRowCount - 1)
);
if (top < frozenRect.bottom) {
return false; //範囲外
return false; // Outside the rectangle.
}
} else {
if (top < 0) {
return false; //範囲外
return false; // Outside the rectangle.
}
}
if (col >= frozenColCount && frozenColCount > 0) {
const { rect: frozenRect } = grid.getAttachCellsArea(
grid.getCellRange(frozenColCount - 1, row)
);
if (left < frozenRect.right) {
return false; //範囲外
return false; // Outside the rectangle.
}
} else {
if (left < 0) {
return false; //範囲外
return false; // Outside the rectangle.
}
}
const { offsetHeight, offsetWidth } = element;
if (offsetHeight < top) {
return false; //範囲外
return false; // Outside the rectangle.
}
if (offsetWidth < left) {
return false; //範囲外
return false; // Outside the rectangle.
}

rootElement.style.top = `${top.toFixed()}px`;
Expand All @@ -127,4 +130,34 @@ export class MessageElement {
}
return true;
}
/**
* If the message is placed outside the Grid, adjust its position.
*/
_adjustStyle<T>(grid: ListGridAPI<T>, col: number, row: number): void {
const rootElement = this._rootElement;
const element = grid.getElement();

const messageRect = rootElement.getBoundingClientRect();
const elementRect = element.getBoundingClientRect();

let messageLeft = messageRect.left;
if (elementRect.right < messageRect.right) {
const overflow = messageRect.right - elementRect.right;
messageLeft -= overflow;
}
if (messageLeft < elementRect.left) {
messageLeft = elementRect.left;
}

if (messageLeft !== messageRect.left) {
const diff = messageRect.left - messageLeft;
const { rect } = grid.getAttachCellsArea(grid.getCellRange(col, row));
rootElement.style.left = `${(rect.left - diff).toFixed()}px`;

const diffCss = `${diff.toFixed()}px`;
rootElement.style.setProperty(LEFT_DIFF_CSS_PROP_NAME, diffCss);
} else {
rootElement.style.removeProperty(LEFT_DIFF_CSS_PROP_NAME);
}
}
}
2 changes: 1 addition & 1 deletion packages/vue-cheetah-grid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-cheetah-grid",
"version": "1.13.1",
"version": "1.13.2",
"description": "Cheetah Grid for Vue.js",
"main": "lib/index.js",
"unpkg": "dist/vueCheetahGrid.js",
Expand Down

0 comments on commit bb08d46

Please sign in to comment.