Skip to content

Commit 1b28ec9

Browse files
committed
refactor: duplicate elemnt as lp plugin
1 parent 7507a41 commit 1b28ec9

File tree

4 files changed

+54
-30
lines changed

4 files changed

+54
-30
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -380,27 +380,6 @@ function RemoteFunctions(config = {}) {
380380
}
381381
}
382382

383-
/**
384-
* this is for duplicate button. Read '_handleDeleteOptionClick' jsdoc to understand more on how this works
385-
* @param {Event} event
386-
* @param {DOMElement} element - the HTML DOM element that was clicked.
387-
*/
388-
function _handleDuplicateOptionClick(event, element) {
389-
if (LivePreviewView.isElementEditable(element)) {
390-
const tagId = element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
391-
392-
window._Brackets_MessageBroker.send({
393-
livePreviewEditEnabled: true,
394-
element: element,
395-
event: event,
396-
tagId: Number(tagId),
397-
duplicate: true
398-
});
399-
} else {
400-
console.error("The TagID might be unavailable or the element tag is directly body or html");
401-
}
402-
}
403-
404383
/**
405384
* this is for cut button, when user clicks on cut button we copy the element's source code
406385
* into the clipboard and remove it from the src code. read `_cutElementToClipboard` in `LivePreviewEdit.js`
@@ -503,9 +482,6 @@ function RemoteFunctions(config = {}) {
503482
_handleSelectParentOptionClick(e, element);
504483
} else if (action === "edit-text") {
505484
startEditing(element);
506-
} else if (action === "duplicate") {
507-
_handleDuplicateOptionClick(e, element);
508-
return true;
509485
} else if (action === "delete") {
510486
_handleDeleteOptionClick(e, element);
511487
} else if (action === "cut") {
@@ -963,10 +939,8 @@ function RemoteFunctions(config = {}) {
963939
</span>`;
964940
}
965941

966-
// Always include duplicate and delete options
967-
content += `<span data-action="duplicate" title="${strings.duplicate}">
968-
${icons.duplicate}
969-
</span>
942+
// Always include delete options
943+
content += `
970944
<span data-action="delete" title="${strings.delete}">
971945
${icons.trash}
972946
</span>
@@ -1022,7 +996,7 @@ function RemoteFunctions(config = {}) {
1022996
}
1023997
} else {
1024998
const keepExitingToolBox = handleOptionClick(event, action, this.element);
1025-
// as we don't want to remove the options box on duplicate button click
999+
// as we don't want to remove the options box on certain items, for eg: duplicate
10261000
if (!keepExitingToolBox) {
10271001
this.remove();
10281002
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
4+
*/
5+
6+
/*global GLOBALS, LivePreviewView, cssStyles, strings, icons, proConstants*/
7+
8+
9+
/**
10+
* this is for duplicate button. Read '_handleDeleteOptionClick' jsdoc to understand more on how this works
11+
* returns tru as we need to keep the exiting node highlighted.
12+
* @param {Event} event
13+
* @param {DOMElement} element - the HTML DOM element that was clicked.
14+
*/
15+
function _handleDuplicateOptionClick(event, element) {
16+
if (LivePreviewView.isElementEditable(element)) {
17+
const tagId = element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
18+
19+
window._Brackets_MessageBroker.send({
20+
livePreviewEditEnabled: true,
21+
element: element,
22+
event: event,
23+
tagId: Number(tagId),
24+
duplicate: true
25+
});
26+
} else {
27+
console.error("The TagID might be unavailable or the element tag is directly body or html");
28+
}
29+
return true;
30+
}
31+
32+
function _renderDuplicateIcon(element, shadow) {
33+
if (element) {
34+
return {
35+
listOrder: proConstants.TOOLBOX_ORDERING.DUPLICATE,
36+
htmlContent: `<span data-action="duplicate" title="${strings.duplicate}">
37+
${icons.duplicate}
38+
</span>`
39+
};
40+
}
41+
return '';
42+
}
43+
44+
45+
// Register with LivePreviewView
46+
LivePreviewView.registerNodeMoreOptionsHandler("duplicate", {
47+
renderToolBoxItem: _renderDuplicateIcon,
48+
handleClick: _handleDuplicateOptionClick
49+
});

src/extensionsIntegrated/phoenix-pro/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define(function (require, exports, module) {
1818
const HyperlinkEditorCode = require("text!./browser-context/hyperlink-editor.js");
1919
const RulerLinesCode = require("text!./browser-context/ruler-lines.js");
2020
const DragAndDropCode = require("text!./browser-context/dragAndDrop.js");
21+
const GenericToolsCode = require("text!./browser-context/generic-tools.js");
2122
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
2223

2324
function _addRemoteScripts() {
@@ -36,6 +37,7 @@ define(function (require, exports, module) {
3637
LiveDevProtocol.addRemoteFunctionScript("HyperlinkEditorCode", HyperlinkEditorCode);
3738
LiveDevProtocol.addRemoteFunctionScript("RulerLinesCode", RulerLinesCode);
3839
LiveDevProtocol.addRemoteFunctionScript("DragAndDrop", DragAndDropCode);
40+
LiveDevProtocol.addRemoteFunctionScript("GenericTools", GenericToolsCode);
3941
}
4042
_addRemoteScripts();
4143
});

src/extensionsIntegrated/phoenix-pro/remote-constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ define(function (require, exports, module) {
5252
DUPLICATE: 40,
5353
DELETE: 50,
5454
IMAGE_GALLERY: 60,
55-
MORE_OPTIONS: 70,
5655
AI: 600 // TBD
5756
};
5857

0 commit comments

Comments
 (0)