Skip to content

Commit 13059ea

Browse files
committed
refactor: delete elemnt as lp plugin
1 parent 1b28ec9 commit 13059ea

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function RemoteFunctions(config = {}) {
106106

107107
const _moreOptionsHandlers = new Map();
108108
function registerNodeMoreOptionsHandler(handlerName, handler) {
109-
if(_moreOptionsHandlers[handlerName]) {
109+
if(_moreOptionsHandlers.get(handlerName)) {
110110
console.error(`lp: More options handler '${handlerName}' already registered. Ignoring new registration`);
111111
return;
112112
}
@@ -358,28 +358,6 @@ function RemoteFunctions(config = {}) {
358358
});
359359
}
360360

361-
/**
362-
* This function gets called when the delete button is clicked
363-
* it sends a message to the editor using postMessage to delete the element from the source code
364-
* @param {Event} event
365-
* @param {DOMElement} element - the HTML DOM element that was clicked.
366-
*/
367-
function _handleDeleteOptionClick(event, element) {
368-
if (LivePreviewView.isElementEditable(element)) {
369-
const tagId = element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
370-
371-
window._Brackets_MessageBroker.send({
372-
livePreviewEditEnabled: true,
373-
element: element,
374-
event: event,
375-
tagId: Number(tagId),
376-
delete: true
377-
});
378-
} else {
379-
console.error("The TagID might be unavailable or the element tag is directly body or html");
380-
}
381-
}
382-
383361
/**
384362
* this is for cut button, when user clicks on cut button we copy the element's source code
385363
* into the clipboard and remove it from the src code. read `_cutElementToClipboard` in `LivePreviewEdit.js`
@@ -482,8 +460,6 @@ function RemoteFunctions(config = {}) {
482460
_handleSelectParentOptionClick(e, element);
483461
} else if (action === "edit-text") {
484462
startEditing(element);
485-
} else if (action === "delete") {
486-
_handleDeleteOptionClick(e, element);
487463
} else if (action === "cut") {
488464
_handleCutOptionClick(e, element);
489465
} else if (action === "copy") {
@@ -939,11 +915,8 @@ function RemoteFunctions(config = {}) {
939915
</span>`;
940916
}
941917

942-
// Always include delete options
918+
// Always include more option ellipses at the end
943919
content += `
944-
<span data-action="delete" title="${strings.delete}">
945-
${icons.trash}
946-
</span>
947920
<span data-action="more-options" title="${strings.moreOptions}">
948921
${icons.verticalEllipsis}
949922
</span>

src/extensionsIntegrated/phoenix-pro/browser-context/generic-tools.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/*global GLOBALS, LivePreviewView, cssStyles, strings, icons, proConstants*/
77

8-
8+
// duplicate option
99
/**
1010
* this is for duplicate button. Read '_handleDeleteOptionClick' jsdoc to understand more on how this works
1111
* returns tru as we need to keep the exiting node highlighted.
@@ -33,17 +33,52 @@ function _renderDuplicateIcon(element, shadow) {
3333
if (element) {
3434
return {
3535
listOrder: proConstants.TOOLBOX_ORDERING.DUPLICATE,
36-
htmlContent: `<span data-action="duplicate" title="${strings.duplicate}">
37-
${icons.duplicate}
38-
</span>`
36+
htmlContent: `<span data-action="duplicate" title="${strings.duplicate}">${icons.duplicate}</span>`
3937
};
4038
}
4139
return '';
4240
}
4341

44-
4542
// Register with LivePreviewView
4643
LivePreviewView.registerNodeMoreOptionsHandler("duplicate", {
4744
renderToolBoxItem: _renderDuplicateIcon,
4845
handleClick: _handleDuplicateOptionClick
4946
});
47+
48+
// delete option
49+
/**
50+
* This function gets called when the delete button is clicked
51+
* it sends a message to the editor using postMessage to delete the element from the source code
52+
* @param {Event} event
53+
* @param {DOMElement} element - the HTML DOM element that was clicked.
54+
*/
55+
function _handleDeleteOptionClick(event, element) {
56+
if (LivePreviewView.isElementEditable(element)) {
57+
const tagId = element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
58+
59+
window._Brackets_MessageBroker.send({
60+
livePreviewEditEnabled: true,
61+
element: element,
62+
event: event,
63+
tagId: Number(tagId),
64+
delete: true
65+
});
66+
} else {
67+
console.error("The TagID might be unavailable or the element tag is directly body or html");
68+
}
69+
}
70+
71+
function _renderDeleteIcon(element, shadow) {
72+
if (element) {
73+
return {
74+
listOrder: proConstants.TOOLBOX_ORDERING.DELETE,
75+
htmlContent: `<span data-action="delete" title="${strings.delete}">${icons.trash}</span>`
76+
};
77+
}
78+
return '';
79+
}
80+
81+
LivePreviewView.registerNodeMoreOptionsHandler("delete", {
82+
renderToolBoxItem: _renderDeleteIcon,
83+
handleClick: _handleDeleteOptionClick
84+
});

0 commit comments

Comments
 (0)