wpxp123456 5 years ago
parent
commit
606e0548dc
  1. 346
      src/controllers/inlineString.js
  2. 9
      src/controllers/keyboard.js
  3. 24
      src/controllers/menuButton.js
  4. 13
      src/controllers/sheetBar.js
  5. 56
      src/global/cursorPos.js
  6. 4
      src/global/draw.js
  7. 141
      src/global/formula.js
  8. 65
      src/global/getRowlen.js
  9. 38
      src/global/getdata.js
  10. 1
      src/store/index.js

346
src/controllers/inlineString.js

@ -1,9 +1,12 @@
import {getFontStyleByCell, textTrim} from "../global/getdata";
import {selectTextContent,selectTextContentCross,selectTextContentCollapse} from '../global/cursorPos';
import locale from '../locale/locale';
import Store from '../store';
export const inlineStyleAffectAttribute = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1};
export function isInlineStringCell(cell){
let isIs = cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
let isIs = cell && cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
return isIs;
}
@ -13,27 +16,28 @@ export function isInlineStringCT(ct){
}
export function updateInlineStringFormat(cell, attr, value, $input){
let s = Store.inlineStringEditCache;
// let s = Store.inlineStringEditCache;
var w = window.getSelection();
var range = w.getRangeAt(0);
if(range.collapsed===true){
return;
}
if(isInlineStringCell(cell)){
if(Store.inlineStringEditCache==null){
Store.inlineStringEditCache = JSON.parse(JSON.stringify(cell.ct.s));
}
var range;
if(w.type=="None"){
range = Store.inlineStringEditRange;
}
else{
Store.inlineStringEditCache = [{
v:cell.v
}];
range = w.getRangeAt(0);
}
// if(isInlineStringCell(cell)){
// if(Store.inlineStringEditCache==null){
// Store.inlineStringEditCache = JSON.parse(JSON.stringify(cell.ct.s));
// }
// }
// else{
// Store.inlineStringEditCache = [{
// v:cell.v
// }];
// }
let cac = range.commonAncestorContainer;
let $textEditor;
if(cac.id=="luckysheet-rich-text-editor"){
@ -44,13 +48,29 @@ export function updateInlineStringFormat(cell, attr, value, $input){
}
let $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
if($textEditor.length==0 && $functionbox.length==0 && Store.inlineStringEditRange!=null){
range = Store.inlineStringEditRange;
cac = range.commonAncestorContainer;
if(cac.id=="luckysheet-rich-text-editor"){
$textEditor = $(cac);
}
else{
$textEditor = $(cac).closest("#luckysheet-rich-text-editor");
}
$functionbox = $(cac).closest("#luckysheet-functionbox-cell");
}
if(range.collapsed===true){
return;
}
let endContainer = range.endContainer, startContainer = range.startContainer;
let endOffset = range.endOffset, startOffset = range.startOffset;
if($textEditor.length>0){
if(startContainer===endContainer){
if(startContainer.parentNode.tagName=="SPAN"){
let span = startContainer.parentNode;
let span = startContainer.parentNode, spanIndex;
let content = span.innerHTML;
let left="" , mid="" , right="";
let s1=0, s2=startOffset, s3 = endOffset, s4=content.length;
@ -64,27 +84,117 @@ export function updateInlineStringFormat(cell, attr, value, $input){
}
if(mid!=""){
let styleObj = {};
styleObj[attr] = value;
let s = getFontStyleByCell(styleObj);
let ukey = textTrim(s.substr(0, s.indexOf(':')));
let uvalue = textTrim(s.substr(s.indexOf(':')+1));
uvalue = uvalue.substr(0, uvalue.length-1);
cont += "<span style='"+ upsetClassWithCss(span.style.cssText, ukey, uvalue) +"'>" + mid + "</span>";
// let styleObj = {};
// styleObj[attr] = value;
// let s = getFontStyleByCell(styleObj, undefined, undefined, false);
// let ukey = textTrim(s.substr(0, s.indexOf(':')));
// let uvalue = textTrim(s.substr(s.indexOf(':')+1));
// uvalue = uvalue.substr(0, uvalue.length-1);
// let cssText = span.style.cssText;
// cssText = removeClassWidthCss(cssText, attr);
let cssText = getCssText(span.style.cssText, attr, value);
cont += "<span style='"+ cssText +"'>" + mid + "</span>";
}
if(right!=""){
cont += "<span style='"+ span.style.cssText +"'>" + right + "</span>";
}
if(startContainer.parentNode.tagName=="SPAN"){
spanIndex = $textEditor.find("span").index(span);
$(span).replaceWith(cont);
}
else{
spanIndex = 0;
$(span).html(cont);
}
let seletedNodeIndex = 0;
if(s1==s2){
seletedNodeIndex = spanIndex;
}
else{
seletedNodeIndex = spanIndex+1;
}
selectTextContent($textEditor.find("span").get(seletedNodeIndex));
}
else{
if(startContainer.parentNode.tagName=="SPAN" && endContainer.parentNode.tagName=="SPAN"){
let startSpan = startContainer.parentNode, startSpanIndex;
let endSpan = endContainer.parentNode, endSpanIndex;
startSpanIndex = $textEditor.find("span").index(startSpan);
endSpanIndex = $textEditor.find("span").index(endSpan);
let startContent = startSpan.innerHTML, endContent = endSpan.innerHTML;
let sleft="" , sright="", eleft="" , eright="";
let s1=0, s2=startOffset, s3 = endOffset, s4=endContent.length;
sleft = startContent.substring(s1, s2);
sright = startContent.substring(s2, startContent.length);
eleft = endContent.substring(0, s3);
eright = endContent.substring(s3, s4);
let spans = $textEditor.find("span");
let replaceSpans = spans.slice(startSpanIndex, endSpanIndex+1);
let cont = "";
for(let i=0;i<startSpanIndex;i++){
let span = spans.get(i), content = span.innerHTML;
cont += "<span style='"+ span.style.cssText +"'>" + content + "</span>";
}
if(sleft!=""){
cont += "<span style='"+ startSpan.style.cssText +"'>" + sleft + "</span>";
}
if(sright!=""){
let cssText = getCssText(startSpan.style.cssText, attr, value);
cont += "<span style='"+ cssText +"'>" + sright + "</span>";
}
if(startSpanIndex<endSpanIndex){
for(let i=startSpanIndex+1;i<endSpanIndex;i++){
let span = spans.get(i), content = span.innerHTML;
cont += "<span style='"+ span.style.cssText +"'>" + content + "</span>";
}
}
if(eleft!=""){
let cssText = getCssText(endSpan.style.cssText, attr, value);
cont += "<span style='"+ cssText +"'>" + eleft + "</span>";
}
if(eright!=""){
cont += "<span style='"+ endSpan.style.cssText +"'>" + eright + "</span>";
}
for(let i=endSpanIndex+1;i<spans.length;i++){
let span = spans.get(i), content = span.innerHTML;
cont += "<span style='"+ span.style.cssText +"'>" + content + "</span>";
}
$textEditor.html(cont);
// console.log(replaceSpans, cont);
// replaceSpans.replaceWith(cont);
let startSeletedNodeIndex, endSeletedNodeIndex;
if(s1==s2){
startSeletedNodeIndex = startSpanIndex;
endSeletedNodeIndex = endSpanIndex;
}
else{
startSeletedNodeIndex = startSpanIndex+1;
endSeletedNodeIndex = endSpanIndex+1;
}
spans = $textEditor.find("span");
selectTextContentCross(spans.get(startSeletedNodeIndex), spans.get(endSeletedNodeIndex));
}
}
}
else if($functionbox.length>0){
@ -92,6 +202,94 @@ export function updateInlineStringFormat(cell, attr, value, $input){
}
}
export function enterKeyControll(){
var w = window.getSelection();
if(w.type=="None"){
return
}
var range = w.getRangeAt(0);
let cac = range.commonAncestorContainer;
let $textEditor;
if(cac.id=="luckysheet-rich-text-editor"){
$textEditor = $(cac);
}
else{
$textEditor = $(cac).closest("#luckysheet-rich-text-editor");
}
let $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
// if(range.collapsed===true){
// return;
// }
let endContainer = range.endContainer, startContainer = range.startContainer;
let endOffset = range.endOffset, startOffset = range.startOffset;
if($textEditor.length>0){
let startSpan = startContainer.parentNode;
let startSpanIndex = $textEditor.find("span").index(startSpan);
if(range.collapsed===false){
range.deleteContents();
}
let startContent = startSpan.innerHTML;
let sleft="" , sright="";
let s1=0, s2=startOffset;
sleft = startContent.substring(s1, s2);
sright = startContent.substring(s2, startContent.length);
let cont = "<span style='"+ startSpan.style.cssText +"'>" + sleft + "\n" + sright + "</span>";
let spanIndex;
if(startContainer.parentNode.tagName=="SPAN"){
spanIndex = $textEditor.find("span").index(startSpan);
$(startSpan).replaceWith(cont);
}
else{
spanIndex = 0;
$(startSpan).html(cont);
}
selectTextContentCollapse($textEditor.find("span").get(spanIndex), startOffset+1);
}
else if($functionbox.length>0){
}
}
export function updateInlineStringFormatOutside(cell, key, value){
let s = cell.ct.s;
for(let i=0;i<s.length;i++){
let item = s[i];
item[key] = value;
}
}
export function convertSpanToShareString($dom){
let styles = [], preStyleList, preStyleListString=null;
for(let i=0;i<$dom.length;i++){
let span = $dom.get(i);
let styleList = convertCssToStyleList(span.style.cssText);
let curStyleListString = JSON.stringify(styleList);
let v = span.innerHTML;
v = v.replace(/\n/g, "\r\n");
if(curStyleListString==preStyleListString){
preStyleList.v += v;
}
else{
styleList.v = v;
styles.push(styleList);
preStyleListString = curStyleListString;
preStyleList = styleList;
}
}
return styles;
}
export function convertCssToStyleList(cssText){
if(cssText==null || cssText.length==0){
@ -153,18 +351,12 @@ export function convertCssToStyleList(cssText){
}
if(key=="text-decoration"){
if(value=="line-through"){
styleList["cl"] = 1;
}
else{
if(value=="underline"){
if(key=="border-bottom"){
styleList["un"] = 1;
}
else{
styleList["cl"] = 0;
}
}
}
if(key=="lucky-strike"){
styleList["cl"] = value;
@ -179,50 +371,124 @@ export function convertCssToStyleList(cssText){
return styleList;
}
const luckyToCssName = {
"bl":"font-weight",
"it":"font-style",
"ff":"font-family",
"fs":"font-size",
"fc":"color",
"cl":"text-decoration",
"un":"border-bottom",
}
function getClassWithcss(cssText, ukey){
let cssTextArray = cssText.split(";");
if(ukey==null || ukey.length==0){
return cssText;
}
if(cssText.indexOf(ukey)>-1){
for(let i=0;i<cssTextArray.length;i++){
let s = cssTextArray[i];
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(key==ukey){
return value;
}
}
}
return "";
}
function upsetClassWithCss(cssText, ukey, uvalue){
let cssTextArray = cssText.split(";");
let newCss = "";
if(ukey==null || ukey.length==0){
return cssText;
}
if(cssText.indexOf(ukey)>-1){
for(let i=0;i<cssTextArray.length;i++){
let s = cssTextArray[i];
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(ukey==key){
if(key==ukey){
newCss += key + ":" + uvalue + ";";
}
else{
else if(key.length>0){
newCss += key + ":" + value + ";";
}
}
}
else{
else if(ukey.length>0){
cssText += ukey + ":" + uvalue + ";";
newCss = cssText;
}
return cssText;
return newCss;
}
function removeClassWidthCss(cssText, ukey){
let cssTextArray = cssText.split(";");
let newCss = "";
let oUkey = ukey;
if(ukey==null || ukey.length==0){
return cssText;
}
if(ukey in luckyToCssName){
ukey = luckyToCssName[ukey];
}
if(cssText.indexOf(ukey)>-1){
for(let i=0;i<cssTextArray.length;i++){
let s = cssTextArray[i];
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(ukey==key){
if(key==ukey || (oUkey=="cl" && key=="lucky-strike") || (oUkey=="un" && key=="lucky-underline") ){
continue;
}
else{
else if(key.length>0){
newCss += key + ":" + value + ";";
}
}
}
else{
newCss = cssText;
}
return newCss;
}
function getCssText(cssText, attr, value){
let styleObj = {};
styleObj[attr] = value;
if(attr=="un"){
let fontColor = getClassWithcss(cssText,"color");
if(fontColor==""){
fontColor = "#000000";
}
let fs = getClassWithcss(cssText,"font-size");
if(fs==""){
fs = 11;
}
fs = parseInt(fs);
styleObj["_fontSize"] = fs;
styleObj["_color"] = fontColor;
}
let s = getFontStyleByCell(styleObj, undefined, undefined, false);
let ukey = textTrim(s.substr(0, s.indexOf(':')));
let uvalue = textTrim(s.substr(s.indexOf(':')+1));
uvalue = uvalue.substr(0, uvalue.length-1);
// let cssText = span.style.cssText;
cssText = removeClassWidthCss(cssText, attr);
cssText = upsetClassWithCss(cssText, ukey, uvalue);
return cssText;
}

9
src/controllers/keyboard.js

@ -25,6 +25,7 @@ import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
import locale from '../locale/locale';
import {enterKeyControll} from './inlineString';
import Store from '../store';
@ -301,9 +302,15 @@ export function keyboardInitial(){
return;
}
let $inputbox = $("#luckysheet-input-box");
if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) {
if((altKey || event.metaKey) && kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0){
enterKeyControll();
event.preventDefault();
}
else if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) {
if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) {
formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active"));
}

24
src/controllers/menuButton.js

@ -31,7 +31,7 @@ import { countfunc } from '../global/count';
import { hideMenuByCancel } from '../global/cursorPos';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
import { setluckysheetfile } from '../methods/set';
import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList} from './inlineString';
import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList,inlineStyleAffectAttribute,updateInlineStringFormatOutside} from './inlineString';
import { replaceHtml, getObjType, rgbTohex, mouseclickposition, luckysheetfontformat,luckysheetContainerFocus } from '../utils/util';
import Store from '../store';
import locale from '../locale/locale';
@ -798,6 +798,15 @@ const menuButton = {
//字体大小
let luckysheet_fs_setTimeout = null;
$("#luckysheet-icon-font-size").mousedown(function(e){
if (parseInt($("#luckysheet-input-box").css("top")) > 0){
let w = window.getSelection();
if(w.type!="None"){
let range = w.getRangeAt(0);
if(!range.collapsed){
Store.inlineStringEditRange = range.cloneRange();
}
}
}
hideMenuByCancel(e);
e.stopPropagation();
}).click(function(){
@ -861,6 +870,8 @@ const menuButton = {
menuleft = menuleft - tlen + userlen;
}
mouseclickposition($menuButton, menuleft, $(this).offset().top + 25, "lefttop");
})
.find("input.luckysheet-toolbar-textinput").keydown(function(e){
hideMenuByCancel(e);
@ -2835,7 +2846,7 @@ const menuButton = {
let canvasElement = document.createElement('canvas');
let canvas = canvasElement.getContext("2d");
if(attr in {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1} ){
if(attr in inlineStyleAffectAttribute ){
if (parseInt($("#luckysheet-input-box").css("top")) > 0 ) {
let value = $("#luckysheet-input-box").text();
if(value.substr(0,1)!="="){
@ -2968,8 +2979,14 @@ const menuButton = {
let value = d[r][c];
if (getObjType(value) == "object") {
if(attr in inlineStyleAffectAttribute && isInlineStringCell(value)){
updateInlineStringFormatOutside(value, attr, foucsStatus);
}
else{
d[r][c][attr] = foucsStatus;
}
}
else{
d[r][c] = { v: value };
d[r][c][attr] = foucsStatus;
@ -2982,8 +2999,10 @@ const menuButton = {
}
}
if(attr == "tb" || attr == "tr" || attr == "fs"){
cfg = rowlenByRange(d, row_st, row_ed, cfg);
}
}
let allParam = {};
if(attr == "tb" || attr == "tr" || attr == "fs"){
@ -3355,6 +3374,7 @@ const menuButton = {
var w = window.getSelection();
var range = w.getRangeAt(0);
let startContainer = range.startContainer;
Store.inlineStringEditRange = null;
const _locale = locale();
if(startContainer.parentNode.tagName=="SPAN"){
let cssText = startContainer.parentNode.style.cssText;

13
src/controllers/sheetBar.js

@ -11,6 +11,8 @@ import { isEditMode } from '../global/validate';
import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
selectTextDom
import {selectTextDom} from '../global/cursorPos';
import locale from '../locale/locale';
import Store from '../store';
@ -206,16 +208,7 @@ export function initialSheetBar(){
$t.attr("contenteditable", "true").addClass("luckysheet-mousedown-cancel").data("oldtxt", $t.text());
setTimeout(function () {
if (document.selection) {
let range = document.body.createTextRange();
range.moveToElementText($t.get(0));
range.select();
} else if (window.getSelection) {
let range = document.createRange();
range.selectNodeContents($t.get(0));
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
selectTextDom($t.get(0));
}, 1);
}

56
src/global/cursorPos.js

@ -60,8 +60,64 @@ function hideMenuByCancel(event){
}
}
function selectTextDom(ele){
if (window.getSelection) {
let range = document.createRange();
range.selectNodeContents(ele);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
else if (document.selection) {
let range = document.body.createTextRange();
range.moveToElementText(ele);
range.select();
}
}
function selectTextContent(ele){
if (window.getSelection) {
let range = document.createRange();
var content=ele.firstChild;
range.setStart(content,0);
range.setEnd(content,content.length);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
else if (document.selection) {
let range = document.body.createTextRange();
range.moveToElementText(ele);
range.select();
}
}
function selectTextContentCross(sEle, eEle){
if (window.getSelection) {
let range = document.createRange();
var sContent=sEle.firstChild, eContent=eEle.firstChild;
range.setStart(sContent,0);
range.setEnd(eContent,eContent.length);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
}
function selectTextContentCollapse(sEle, index){
if (window.getSelection) {
let range = document.createRange();
var sContent=sEle.firstChild;
range.setStart(sContent,index);
range.collapse(true);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
}
export {
luckysheetRangeLast,
getCursortPosition,
hideMenuByCancel,
selectTextContent,
selectTextDom,
selectTextContentCross,
selectTextContentCollapse
}

4
src/global/draw.js

@ -2169,7 +2169,7 @@ function cellTextRender(textInfo, ctx, option){
Math.floor((pos_x +c.endX)/Store.zoomRatio)+0.5 ,
Math.floor((pos_y+c.endY)/Store.zoomRatio)+0.5 ,
);
ctx.lineWidth = 1;
ctx.lineWidth = Math.floor(c.fs/9);
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();
@ -2188,7 +2188,7 @@ function cellTextRender(textInfo, ctx, option){
Math.floor((pos_x +item.endX)/Store.zoomRatio)+0.5,
Math.floor((pos_y+ item.endY)/Store.zoomRatio)+0.5
);
ctx.lineWidth = 1;
ctx.lineWidth = Math.floor(item.fs/9);
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();

141
src/global/formula.js

@ -9,7 +9,7 @@ import luckysheetFreezen from '../controllers/freezen';
import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/select';
import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate';
import { isdatetime, isdatatype } from './datecontroll';
import { getCellTextSplitArr } from '../global/getRowlen';
import { getCellTextSplitArr,getCellTextInfo } from '../global/getRowlen';
import { getcellvalue,getcellFormula,getInlineStringNoStyle } from './getdata';
import { setcellvalue } from './setdata';
import { genarate, valueShowEs } from './format';
@ -18,7 +18,7 @@ import tooltip from './tooltip';
import { rowLocation, colLocation, colLocationByIndex, mouseposition } from './location';
import { luckysheetRangeLast } from './cursorPos';
import { jfrefreshgrid } from './refresh';
import { isInlineStringCell } from '../controllers/inlineString';
import { isInlineStringCell,convertSpanToShareString } from '../controllers/inlineString';
// import luckysheet_function from '../function/luckysheet_function';
// import functionlist from '../function/functionlist';
import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check } from '../function/func';
@ -1197,16 +1197,44 @@ const luckysheetformula = {
let _this = this;
let $input = $("#luckysheet-rich-text-editor");
let inputText = $input.text(), inputHtml = $input.html();
// API, we get value from user
value = value || $input.text();
if (_this.rangetosheet != null && _this.rangetosheet != Store.currentSheetIndex) {
sheetmanage.changeSheetExec(_this.rangetosheet);
}
let curv = Store.flowdata[r][c];
let isPrevInline = isInlineStringCell(curv);
let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.indexOf("span")>-1);
if(!value && !isCurInline && isPrevInline){
delete curv.ct.s;
curv.ct.t = "g";
curv.ct.fa = "General";
}
else if(isCurInline){
if (getObjType(curv) != "object") {
curv = {};
}
delete curv.f;
delete curv.v;
delete curv.m;
if(curv.ct==null){
curv.ct = {};
curv.ct.fa = "General";
}
curv.ct.t = "inlineStr";
curv.ct.s = convertSpanToShareString($input.find("span"));
}
// API, we get value from user
value = value || $input.text();
if(!isCurInline){
if(isRealNull(value)){
if(curv == null || (isRealNull(curv.v) && curv.spl == null)){
_this.cancelNormalSelected();
@ -1234,6 +1262,7 @@ const luckysheetformula = {
delete curv.spl; //删除单元格的sparklines的配置串
}
}
}
window.luckysheet_getcelldata_cache = null;
@ -1243,6 +1272,9 @@ const luckysheetformula = {
let dynamicArrayItem = null; //动态数组
if (getObjType(curv) == "object") {
if(!isCurInline){
if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
let v = _this.execfunction(value, r, c, true);
@ -1271,6 +1303,36 @@ const luckysheetformula = {
else if(getObjType(value) == "object"){
let valueFunction = value.f;
if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
let v = _this.execfunction(valueFunction, r, c, true);
// get v/m/ct
curv = _this.execFunctionGroupData[r][c];
curv.f = v[2];
//打进单元格的sparklines的配置串, 报错需要单独处理。
if(v.length == 4 && v[3].type == "sparklines"){
delete curv.m;
delete curv.v;
let curCalv = v[3].data;
if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
curv.v = curCalv[0];
}
else{
curv.spl = v[3].data;
}
}
else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
dynamicArrayItem = v[3].data;
}
}
// from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
else if(getObjType(value) == "object"){
let valueFunction = value.f;
if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
let v = _this.execfunction(valueFunction, r, c, true);
@ -1300,9 +1362,8 @@ const luckysheetformula = {
curv.spl = v[3].data;
}
}
else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
dynamicArrayItem = v[3].data;
}
}
}
@ -1323,7 +1384,7 @@ const luckysheetformula = {
}
}
}
}
value = curv;
}
else {
@ -1400,44 +1461,64 @@ const luckysheetformula = {
cfg["rowlen"] = {};
}
if(d[r][c].tb == "2" && d[r][c].v != null){//自动换行
let defaultrowlen = 19;
if((d[r][c].tb == "2" && d[r][c].v != null) || isInlineStringCell(d[r][c])){//自动换行
let defaultrowlen = Store.defaultrowlen;;
let canvas = $("#luckysheetTableContent").get(0).getContext("2d");
// offlinecanvas.textBaseline = 'top'; //textBaseline以top计算
// let fontset = luckysheetfontformat(d[r][c]);
// offlinecanvas.font = fontset;
let offlinecanvas = $("#luckysheetTableContentF").get(0).getContext("2d");
offlinecanvas.textBaseline = 'top'; //textBaseline以top计算
if(cfg["customHeight"] && cfg["customHeight"][r]==1){
}
else{
// let currentRowLen = defaultrowlen;
// if(cfg["rowlen"][r] != null){
// currentRowLen = cfg["rowlen"][r];
// }
let fontset = luckysheetfontformat(d[r][c]);
offlinecanvas.font = fontset;
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
let textInfo = getCellTextInfo(d[r][c], canvas,{
r:r,
c:c,
cellWidth:cellWidth
});
let currentRowLen = defaultrowlen;
if(cfg["rowlen"][r] != null){
currentRowLen = cfg["rowlen"][r];
// console.log("rowlen", textInfo);
if(textInfo!=null){
currentRowLen = textInfo.textHeightAll+2;
}
let strValue = getcellvalue(r, c, d).toString();
let measureText = offlinecanvas.measureText(strValue);
// let strValue = getcellvalue(r, c, d).toString();
// let measureText = offlinecanvas.measureText(strValue);
let textMetrics = measureText.width;
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;
// let textMetrics = measureText.width;
// let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
// let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;
if(textMetrics > cellWidth){
let strArr = [];//文本截断数组
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);
// if(textMetrics > cellWidth){
// let strArr = [];//文本截断数组
// strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);
let computeRowlen = oneLineTextHeight * strArr.length + 4;
//比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){
currentRowLen = computeRowlen;
}
}
// let computeRowlen = oneLineTextHeight * strArr.length + 4;
// //比较计算高度和当前高度取最大高度
// if(computeRowlen > currentRowLen){
// currentRowLen = computeRowlen;
// }
// }
if(currentRowLen != defaultrowlen){
if(currentRowLen > defaultrowlen){
cfg["rowlen"][r] = currentRowLen;
RowlChange = true;
}
}
}
//动态数组
let dynamicArray = null;
if(!!dynamicArrayItem){

65
src/global/getRowlen.js

@ -43,7 +43,7 @@ function rowlenByRange(d, r1, r2, cfg) {
continue;
}
if(cell != null && cell.v != null){
if(cell != null && (cell.v != null || isInlineStringCell(cell)) ){
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
let textInfo = getCellTextInfo(cell, canvas,{
@ -55,7 +55,7 @@ function rowlenByRange(d, r1, r2, cfg) {
let computeRowlen = 0;
// console.log("rowlen", textInfo);
if(textInfo!=null){
computeRowlen = textInfo.textHeightAll;
computeRowlen = textInfo.textHeightAll+2;
}
// let fontset = luckysheetfontformat(cell);
@ -326,13 +326,13 @@ function getCellTextInfo(cell , ctx, option){
let textContent = {};
textContent.values = [];
let fontset, cancelLine="0", underLine="0", isInline=false, value, inlineStringArr=[];
let fontset, cancelLine="0", underLine="0", fontSize=11, isInline=false, value, inlineStringArr=[];
if(isInlineStringCell(cell)){
let sharedStrings = cell.ct.s, similarIndex = 0;
for(let i=0;i<sharedStrings.length;i++){
let shareCell = sharedStrings[i];
let scfontset = luckysheetfontformat(shareCell);
let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v;
let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v, fs=shareCell.fs;
v = v.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_");
let splitArr = v.split("_x000D_"), preNewValue=null;
for(let x=0;x<splitArr.length;x++){
@ -344,7 +344,8 @@ function getCellTextInfo(cell , ctx, option){
fc:fc==null?"#000":fc,
cl:cl==null?0:cl,
un:un==null?0:un,
wrap:true
wrap:true,
fs:fs==null?11:fs,
});
similarIndex++;
}
@ -359,18 +360,20 @@ function getCellTextInfo(cell , ctx, option){
cl:cl==null?0:cl,
un:un==null?0:un,
v: nv,
si:similarIndex
si:similarIndex,
fs:fs==null?11:fs,
});
}
if(x!=splitArr.length-1 && preNewValue!=""){
if(x!=splitArr.length-1 && !(preNewValue=="" && newValue=="") ){
inlineStringArr.push({
fontset:scfontset,
fc:fc==null?"#000":fc,
cl:cl==null?0:cl,
un:un==null?0:un,
wrap:true
wrap:true,
fs:fs==null?11:fs,
});
similarIndex++;
}
@ -391,6 +394,7 @@ function getCellTextInfo(cell , ctx, option){
cancelLine = checkstatusByCell(cell ,"cl");//cancelLine
underLine = checkstatusByCell(cell ,"un");//underLine
fontSize = checkstatusByCell(cell ,"fs");
if(cell instanceof Object){
value = cell.m;
@ -609,7 +613,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top+word.height-space_height,
asc:word.height,
desc:0
desc:0,
fs:fontSize
});
textContent.values.push(word);
@ -662,6 +667,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
}
// if(rt!=0){//rotate
@ -691,6 +697,7 @@ function getCellTextInfo(cell , ctx, option){
desc:measureText.actualBoundingBoxDescent,
inline:true,
wrap:true,
fs:sc.fs
});
}
@ -738,6 +745,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
@ -761,6 +769,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
break;
@ -790,6 +799,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
@ -813,6 +823,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
@ -857,7 +868,8 @@ function getCellTextInfo(cell , ctx, option){
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
@ -876,7 +888,8 @@ function getCellTextInfo(cell , ctx, option){
height:textHeight,
width:textWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
break;
}
@ -901,7 +914,8 @@ function getCellTextInfo(cell , ctx, option){
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
@ -919,7 +933,8 @@ function getCellTextInfo(cell , ctx, option){
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
break;
@ -1095,7 +1110,8 @@ function getCellTextInfo(cell , ctx, option){
left:left-wordGroup.width,
top:top,
asc:size.asc,
desc:size.desc
desc:size.desc,
fs:wordGroup.fs
});
textContent.values.push(wordGroup);
@ -1178,7 +1194,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:size.asc,
desc:size.desc
desc:size.desc,
fs:wordGroup.fs
});
}
@ -1208,7 +1225,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:size.asc,
desc:size.desc
desc:size.desc,
fs:wordGroup.fs
});
}
@ -1356,7 +1374,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
textContent.values.push(wordGroup);
@ -1376,7 +1395,7 @@ function getCellTextInfo(cell , ctx, option){
function drawLineInfo(wordGroup, cancelLine,underLine,option){
let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc;
let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc,fs = option.fs;
if(wordGroup.wrap===true){
return;
@ -1395,6 +1414,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
wordGroup.cancelLine.endX = left + width;
wordGroup.cancelLine.endY = top-asc/2+1;
wordGroup.cancelLine.fs = fs;
}
if(underLine!="0"){
@ -1407,6 +1428,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top;
item.fs = fs;
wordGroup.underLine.push(item);
}
@ -1418,6 +1441,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc;
item.fs = fs;
wordGroup.underLine.push(item);
}
@ -1429,6 +1454,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc;
item.fs = fs;
wordGroup.underLine.push(item);
}
@ -1440,6 +1467,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc+2;
item.fs = fs;
wordGroup.underLine.push(item);
}
}

38
src/global/getdata.js

@ -1,11 +1,11 @@
import { getObjType } from '../utils/util';
import { getObjType,rgbTohex } from '../utils/util';
import { getSheetIndex } from '../methods/get';
import server from '../controllers/server';
import formula from './formula';
import editor from './editor';
import { dynamicArrayCompute } from './dynamicArray';
import sheetmanage from '../controllers/sheetmanage';
import { isInlineStringCT,isInlineStringCell } from '../controllers/inlineString';
import { isInlineStringCT,isInlineStringCell,convertCssToStyleList } from '../controllers/inlineString';
import locale from '../locale/locale';
import Store from '../store';
@ -317,7 +317,7 @@ export function getInlineStringStyle(r, c, data){
return "";
}
export function getFontStyleByCell(cell,checksAF,checksCF){
export function getFontStyleByCell(cell,checksAF,checksCF, isCheck=true){
if(cell==null){
return;
}
@ -325,7 +325,10 @@ export function getFontStyleByCell(cell,checksAF,checksCF){
const _locale = locale();
const locale_fontarray = _locale.fontarray;
for(let key in cell){
let value = checkstatusByCell(cell, key);
let value = cell[key];
if(isCheck){
value = checkstatusByCell(cell, key);
}
if(key == "bl" && value != "0"){
style += "font-weight: bold;";
}
@ -366,7 +369,15 @@ export function getFontStyleByCell(cell,checksAF,checksCF){
}
if(key == "un" && (value == "1" || value == "3")){
style += "text-decoration: underline;";
let color = cell["_color"];
if(color==null){
color = cell["fc"];
}
let fs = cell["_fontSize"];
if(fs==null){
fs = cell["fs"];
}
style += "border-bottom: "+ Math.floor(fs/9) +"px solid "+ color +";";
}
}
@ -377,18 +388,31 @@ export function checkstatusByCell(cell, a){
let foucsStatus =cell;
let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
if(a in tf){
if(a in tf || (a=="fs" && isInlineStringCell(cell)) ){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
var w = window.getSelection(), isInlineEdit=false;
if(w.type!="None"){
var range = w.getRangeAt(0);
let startContainer = range.startContainer;
if (parseInt($("#luckysheet-input-box").css("top")) > 0 && startContainer.parentNode.tagName=="SPAN" && !range.collapsed) {
let span = startContainer.parentNode;
let styleList = convertCssToStyleList(span.style.cssText);
foucsStatus = styleList[a];
isInlineEdit = true;
}
}
if(!isInlineEdit){
if(isInlineStringCell(cell)){
foucsStatus = cell.ct.s[0][a];
}
else{
foucsStatus = foucsStatus[a];
}
}
if(foucsStatus == null){
foucsStatus = "0";

1
src/store/index.js

@ -127,6 +127,7 @@ const Store = {
showGridLines:true,
inlineStringEditCache:null,
inlineStringEditRange:null,
}

Loading…
Cancel
Save