Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions phoenix-builder-mcp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src-mdviewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions src/JSUtils/ModalBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
define(function() {
const Item = Object.freeze({
modal: "modal",
modalContent: "content",
buttonsContainer: "buttons"
});

class ModalBuilder {
constructor(document) {
this.document = document;
this.modal = this.document.createElement('div');
this.modalContent = this.document.createElement('div');
this.buttonsContainer = this.document.createElement('div');
}

addStyle(item, style) {
switch (item) {
case Item.modal:
Object.assign(this.modal.style, style);
break;
case Item.modalContent:
Object.assign(this.modalContent.style, style);
break;
case Item.buttonsContainer:
Object.assign(this.buttonsContainer.style, style);
break;

default:
break;
}
return this;
}

addTitle(title, color) {
this.title = this.document.createElement('h2');
this.title.textContent = title;
this.title.style.color = color;
return this;
}

addMessage(message) {
this.modalMessage = document.createElement('p');
message.split('\n').forEach((part, index, array) => {
this.modalMessage.appendChild(document.createTextNode(part));
if (index < array.length - 1) { // Don't add a break on the last element
this.modalMessage.appendChild(document.createElement('br'));
}
});
return this;
}

addButton(title) {
const button = this.document.createElement('button');
button.textContent = title;
this.buttonsContainer.appendChild(button);
return button;
}

addButton(title, style) {

Check warning on line 59 in src/JSUtils/ModalBuilder.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Duplicate name 'addButton'.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xId3RkC5tmjiW2-&open=AaE31xId3RkC5tmjiW2-&pullRequest=3279
const button = this.addButton(title);
Object.assign(button.style, style);
return button;
}

addButton(title, style, onclick) {

Check warning on line 65 in src/JSUtils/ModalBuilder.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Duplicate name 'addButton'.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xId3RkC5tmjiW2_&open=AaE31xId3RkC5tmjiW2_&pullRequest=3279
const button = this.addButton(title, style);
button.onclick = onclick;
return button;
}

build() {
this.modalContent.appendChild(this.title);
this.modalContent.appendChild(this.message);
this.modalContent.appendChild(this.buttonsContainer);
this.modal.appendChild(this.modalContent);
return this.modal;
}
}

return ModalBuilder;
});
70 changes: 70 additions & 0 deletions src/JSUtils/SelectorStrategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
define(function (require) {
const Strings = require('strings');
const HTMLUtils = require('language/HTMLUtils');

const strategies = [];

const TagSelectorStrategy = {
isMatch: (tokenType) =>
tokenType === HTMLUtils.TAG_NAME || tokenType === HTMLUtils.CLOSING_TAG,

resolve: (tagInfo) => ({
selectorName: tagInfo.tagName,
reason: null
})
};

const ClassSelectorStrategy = {
isMatch: (tokenType, attrName) =>
(tokenType === HTMLUtils.ATTR_NAME || tokenType === HTMLUtils.ATTR_VALUE) && attrName === "class",

resolve: (tagInfo) => {
var attributeValue = tagInfo.attr.value;

Check failure on line 22 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW22&open=AaE31xDT3RkC5tmjiW22&pullRequest=3279
if (!/\S/.test(attributeValue)) {
return { selectorName: "", reason: Strings.ERROR_CSSQUICKEDIT_CLASSNOTFOUND };
}

var startIndex = attributeValue.substr(0, tagInfo.position.offset).lastIndexOf(" ");

Check failure on line 27 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW23&open=AaE31xDT3RkC5tmjiW23&pullRequest=3279
var endIndex = attributeValue.indexOf(" ", tagInfo.position.offset);

Check failure on line 28 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW24&open=AaE31xDT3RkC5tmjiW24&pullRequest=3279
let selectorName = "." +
attributeValue.substring(
startIndex === -1 ? 0 : startIndex + 1,
endIndex === -1 ? attributeValue.length : endIndex
);

if (selectorName === ".") {
return { selectorName: "", reason: Strings.ERROR_CSSQUICKEDIT_BETWEENCLASSES };
}
return { selectorName, reason: null };
}
};
const IdSelectorStrategy = {
isMatch: (tokenType, attrName) =>
(tokenType === HTMLUtils.ATTR_NAME || tokenType === HTMLUtils.ATTR_VALUE) && attrName === "id",

resolve: (tagInfo) => {
var trimmedVal = tagInfo.attr.value.trim();

Check failure on line 46 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW25&open=AaE31xDT3RkC5tmjiW25&pullRequest=3279
if (trimmedVal) {
return { selectorName: "#" + trimmedVal, reason: null};
}
return { selectorName: "", reason: Strings.ERROR_CSSQUICKEDIT_IDNOTFOUND };
}
};

const ErrorSelectorStrategy = {
isMatch: () => true,
resolve: () => { return { selectorName: "", reason: Strings.ERROR_CSSQUICKEDIT_UNSUPPORTEDATTR }; }
};

strategies.push(TagSelectorStrategy);
strategies.push(ClassSelectorStrategy);

Check warning on line 60 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not call `Array#push()` multiple times.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW26&open=AaE31xDT3RkC5tmjiW26&pullRequest=3279
strategies.push(IdSelectorStrategy);

Check warning on line 61 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not call `Array#push()` multiple times.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW27&open=AaE31xDT3RkC5tmjiW27&pullRequest=3279
strategies.push(ErrorSelectorStrategy);

Check warning on line 62 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not call `Array#push()` multiple times.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW28&open=AaE31xDT3RkC5tmjiW28&pullRequest=3279

function getStrategy(tagInfo) {
const strategy = strategies.find(s => s.isMatch(tagInfo.position.tokenType, tagInfo.attr.name));
return strategy ? strategy : null;

Check warning on line 66 in src/JSUtils/SelectorStrategy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unnecessary use of conditional expression for default assignment.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaE31xDT3RkC5tmjiW29&open=AaE31xDT3RkC5tmjiW29&pullRequest=3279
}

return getStrategy;
});
Loading