Skip to content

Commit

Permalink
#65 restore the feature of start/end marker lines
Browse files Browse the repository at this point in the history
  • Loading branch information
AgriyaDev5 committed Jan 19, 2021
1 parent 7ea99e4 commit 8c6ad08
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/editor/dialogs/sePromptDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class SePromptDialog extends HTMLElement {
}
break;
default:
// eslint-disable-next-line no-console
console.error('unkonw attr for:', name, 'newValue =', newValue);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/editor/extensions/ext-markers/ext-markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
function setIcon (pos, id) {
if (id.substr(0, 1) !== '\\') { id = '\\textmarker'; }
const ci = '#' + idPrefix + pos + '_' + id.substr(1);
// svgEditor.setIcon('#cur_' + pos + '_marker_list', $(ci).children());
svgEditor.setIcon('#cur_' + pos + '_marker_list', $(ci).children());
$(ci).addClass('current').siblings().removeClass('current');
}

Expand Down Expand Up @@ -508,7 +508,7 @@ export default {
buttons.push({
id: idPrefix + pos + '_' + id,
svgicon: id,
icon: 'markers-' + id + '.png',
icon: id + '.svg',
title,
type: 'context',
events: {click: setArrowFromButton},
Expand Down Expand Up @@ -565,7 +565,7 @@ export default {

return {
name: strings.name,
svgicons: 'markers-icons.xml',
svgicons: '',
callback () {
$('#marker_panel').addClass('toolset').hide();
},
Expand Down
3 changes: 3 additions & 0 deletions src/editor/images/box.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/box_o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/forwardslash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/leftarrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/leftarrow_o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/mcircle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/mcircle_o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/nomarker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/reverseslash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/rightarrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/rightarrow_o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/star_o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/textmarker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/triangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/triangle_o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/verticalslash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/editor/images/xmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/editor/svgedit.css
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,8 @@ ul li.current {
z-index: 20001;
}

/* ------------ */


.dropdown li.tool_button {
width: 24px;
}
75 changes: 43 additions & 32 deletions src/editor/svgedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import './touch.js';
import {isWebkit, isChrome, isMac, isTouch} from '../common/browser.js';
import {isChrome, isMac, isTouch} from '../common/browser.js';
import {convertUnit, isValidUnit} from '../common/units.js';

import SvgCanvas from '../svgcanvas/svgcanvas.js';
Expand Down Expand Up @@ -861,7 +861,6 @@ class Editor extends EditorStartup {
const w = shower.outerWidth();
this.css({left: (left + w) * editor.tool_scale, top});
});
return;
}

/**
Expand All @@ -886,7 +885,6 @@ class Editor extends EditorStartup {
* @param {PlainObject<string, module:SVGEditor.ToolButton>} holders Key is a selector
* @returns {void}
*/
// eslint-disable-next-line class-methods-use-this
setupFlyouts (holders) {
const allHolders = {};
$.each(holders, function (holdSel, btnOpts) {
Expand Down Expand Up @@ -936,7 +934,7 @@ class Editor extends EditorStartup {
});
}
if ($(this).hasClass('disabled')) { return false; }
/* if (toolButtonClick(showSel)) {
/* if (toolButtonClick(showSel)) {
options.fn();
} */
const icon = (options.icon) ? $.getSvgIcon(options.icon, true) : $(options.sel).children().eq(0).clone();
Expand Down Expand Up @@ -1002,16 +1000,15 @@ class Editor extends EditorStartup {
// $('#tools_rect').mouseleave(function () { $('#tools_rect').fadeOut(); });
});
this.setFlyoutTitles();
this.setFlyoutPositions();
console.log("1011 after --->")
// this.setFlyoutPositions();
}

/**
* @param {string} id
* @param {external:jQuery} child
* @returns {external:jQuery}
*/
// eslint-disable-next-line class-methods-use-this
// eslint-disable-next-line class-methods-use-this
makeFlyoutHolder (id, child) {
const div = $('<div>', {
class: 'tools_flyout',
Expand All @@ -1020,6 +1017,23 @@ class Editor extends EditorStartup {
return div;
}

/**
* @function module:SVGEditor.setIcon
* @param {string|Element|external:jQuery} elem
* @param {string|external:jQuery} iconId
* @returns {void}
*/
setIcon (elem, iconId) {
// eslint-disable-next-line max-len
const icon = (typeof iconId === 'string') ? $('<img src="' + this.configObj.curConfig.imgPath + iconId + '">') : iconId.clone();
if (!icon) {
// Todo: Investigate why this still occurs in some cases
console.log('NOTE: Icon image missing: ' + iconId); // eslint-disable-line no-console
return;
}
$(elem).empty().append(icon);
}

/**
* @param {string} elemSel
* @param {string} listSel
Expand All @@ -1031,8 +1045,9 @@ class Editor extends EditorStartup {
* @todo Combine this with `addDropDown` or find other way to optimize.
* @returns {void}
*/
// eslint-disable-next-line class-methods-use-this
addAltDropDown (elemSel, listSel, callback, opts) {
// eslint-disable-next-line no-shadow
const self = this;
const button = $(elemSel);
const {dropUp} = opts;
const list = $(listSel);
Expand All @@ -1041,7 +1056,7 @@ class Editor extends EditorStartup {
}
list.find('li').bind('mouseup', function (...args) {
if (opts.seticon) {
// setIcon('#cur_' + button[0].id, $(this).children());
self.setIcon('#cur_' + button[0].id, $(this).children());
$(this).addClass('current').siblings().removeClass('current');
}
callback.apply(this, ...args);
Expand Down Expand Up @@ -1088,7 +1103,7 @@ class Editor extends EditorStartup {
onButton = true;
});
}
};
}

/**
* @param {external:Window} win
Expand All @@ -1097,6 +1112,7 @@ class Editor extends EditorStartup {
* @returns {Promise<void>|void} Resolves to `undefined`
*/
async extAdded (win, ext) {
// eslint-disable-next-line no-shadow
const self = this;
const btnSelects = [];
if (!ext) {
Expand Down Expand Up @@ -1174,7 +1190,9 @@ class Editor extends EditorStartup {
break;
} case 'button-select': {
html = '<div id="' + tool.id + '" class="dropdown toolset" title="' + tool.title + '">' +
'<div id="cur_' + tool.id + '" class="icon_label"></div><button></button></div>';
'<div id="cur_' + tool.id + '" class="icon_label"></div>' +
'<button><img class="svg_icon" src="./images/arrow_down.svg" alt="icon" width="7" height="7"></button>' +
'</div>';

const list = $('<ul id="' + tool.id + '_opts"></ul>').appendTo('#option_lists');

Expand All @@ -1184,6 +1202,13 @@ class Editor extends EditorStartup {

// Creates the tool, hides & adds it, returns the select element
/* const dropdown = */ $(html).appendTo(panel).children();
btnSelects.push({
elem: ('#' + tool.id),
list: ('#' + tool.id + '_opts'),
title: tool.title,
callback: tool.events.change,
cur: ('#cur_' + tool.id)
});
break;
} case 'input': {
html = '<label' + contId + '>' +
Expand Down Expand Up @@ -1244,20 +1269,18 @@ class Editor extends EditorStartup {
* @property {module:SVGEditor.Key} [key] The key to bind to the button
*/
// Add buttons given by extension
console.log(ext.buttons);
$.each(ext.buttons, function (i, /** @type {module:SVGEditor.Button} */ btn) {
let {id} = btn;
let num = i;
// Give button a unique ID
while ($('#' + id).length) {
id = btn.id + '_' + (++num);
}
console.log(id);

let icon;
if (!svgicons) {
console.log(btn.icon);
icon = $(
'<img src="' + btn.icon +
'<img src="' + self.configObj.curConfig.imgPath + btn.icon +
(btn.title ? '" alt="' + btn.title : '') +
'">'
);
Expand All @@ -1271,7 +1294,6 @@ class Editor extends EditorStartup {
placementObj['#' + id] = svgicon;
}
}
console.log(placementObj);
let cls, parent;

// Set button up according to its type
Expand All @@ -1294,13 +1316,13 @@ class Editor extends EditorStartup {
parent = '#main_menu ul';
break;
}
let flyoutHolder, showBtn, refData, refBtn;
// refData
let flyoutHolder, showBtn, refBtn;
const button = $((btn.list || btn.type === 'app_menu') ? '<li/>' : '<div/>')
.attr('id', id)
.attr('title', btn.title)
.addClass(cls);
if (!btn.includeWith && !btn.list) {
console.log('1306');
if ('position' in btn) {
if ($(parent).children().eq(btn.position).length) {
$(parent).children().eq(btn.position).before(button);
Expand Down Expand Up @@ -1364,19 +1386,15 @@ class Editor extends EditorStartup {
button.append('<div>').append(btn.title);
}
} else if (btn.list) {
console.log('1370');
// Add button to list
button.addClass('push_button');
$('#' + btn.list + '_opts').append(button);
if (btn.isDefault) {
$('#cur_' + btn.list).append(button.children().clone());
const svgicon = btn.svgicon || btn.id;

placementObj['#cur_' + btn.list] = svgicon;
console.log(placementObj);
}
} else if (btn.includeWith) {
console.log('1380');
// Add to flyout menu / make flyout menu
const opts = btn.includeWith;
// opts.button, default, position
Expand Down Expand Up @@ -1424,15 +1442,12 @@ class Editor extends EditorStartup {
} else {
flyoutHolder.append(button);
// curH.reverse();
}
}
}
console.log(svgicons);
if (!svgicons) {
button.append(icon);
}
console.log(btn.list);
if (!btn.list) {
console.log('1436');
// Add given events to button
$.each(btn.events, function (name, func) {
if (name === 'click' && btn.type === 'mode') {
Expand Down Expand Up @@ -1462,15 +1477,11 @@ class Editor extends EditorStartup {
});
}
self.setupFlyouts(holders);
console.log("1471------------->");
});

$.each(btnSelects, function () {
self.addAltDropDown(this.elem, this.list, this.callback, {seticon: true});
});
console.log(svgicons);
if (svgicons) {
console.log(`${this.configObj.curConfig.imgPath}${svgicons}`);
/* if (svgicons) {
return new Promise((resolve, reject) => { // eslint-disable-line promise/avoid-new
$.svgIcons(`${this.configObj.curConfig.imgPath}${svgicons}`, {
w: 24, h: 24,
Expand All @@ -1489,7 +1500,7 @@ class Editor extends EditorStartup {
}
});
});
}
} */
}
if (ext.events) {
this.leftPanelHandlers.add(ext.events.id, ext.events.click);
Expand Down

0 comments on commit 8c6ad08

Please sign in to comment.