refactor: consolidate all Node.js development into lib package
- Move scripts/ to lib/scripts/ and convert to ESM modules - Consolidate dependencies: add live-server to lib/package.json - Remove root package.json and node_modules split - Preserve CLI integration via existing rebuild-library.sh - Add development quickstart guide for new unified workflow - Clean up outdated file references and duplicate assets
This commit is contained in:
@@ -15,7 +15,7 @@ var Insertr = (function () {
|
||||
|
||||
// Find all enhanced elements on the page
|
||||
findEnhancedElements() {
|
||||
return document.querySelectorAll('[data-insertr-enhanced="true"]');
|
||||
return document.querySelectorAll('.insertr');
|
||||
}
|
||||
|
||||
// Get element metadata
|
||||
@@ -608,7 +608,7 @@ var Insertr = (function () {
|
||||
background-color: rgba(0, 124, 186, 0.05) !important;
|
||||
}
|
||||
|
||||
[data-insertr-enhanced="true"]:hover::after {
|
||||
.insertr:hover::after {
|
||||
content: "✏️ " attr(data-content-type);
|
||||
position: absolute;
|
||||
top: -25px;
|
||||
@@ -1142,16 +1142,16 @@ var Insertr = (function () {
|
||||
}
|
||||
|
||||
/* Hide editing interface when not in edit mode */
|
||||
body:not(.insertr-edit-mode) [data-insertr-enhanced]:hover::after {
|
||||
body:not(.insertr-edit-mode) .insertr:hover::after {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Only show editing features when in edit mode */
|
||||
.insertr-authenticated.insertr-edit-mode [data-insertr-enhanced] {
|
||||
.insertr-authenticated.insertr-edit-mode .insertr {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.insertr-authenticated.insertr-edit-mode [data-insertr-enhanced]:hover {
|
||||
.insertr-authenticated.insertr-edit-mode .insertr:hover {
|
||||
outline: 2px dashed #007cba !important;
|
||||
outline-offset: 2px !important;
|
||||
background-color: rgba(0, 124, 186, 0.05) !important;
|
||||
@@ -1203,25 +1203,25 @@ var Insertr = (function () {
|
||||
core: null,
|
||||
editor: null,
|
||||
auth: null,
|
||||
|
||||
|
||||
// Initialize the library
|
||||
init(options = {}) {
|
||||
console.log('🔧 Insertr v1.0.0 initializing... (Hot Reload Ready)');
|
||||
|
||||
|
||||
this.core = new InsertrCore(options);
|
||||
this.auth = new InsertrAuth(options);
|
||||
this.editor = new InsertrEditor(this.core, this.auth, options);
|
||||
|
||||
|
||||
// Auto-initialize if DOM is ready
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => this.start());
|
||||
} else {
|
||||
this.start();
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
// Start the system - only creates the minimal trigger
|
||||
start() {
|
||||
if (this.auth) {
|
||||
@@ -1236,37 +1236,36 @@ var Insertr = (function () {
|
||||
this.editor.start();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// Public API methods
|
||||
login() {
|
||||
return this.auth ? this.auth.toggleAuthentication() : null;
|
||||
},
|
||||
|
||||
|
||||
logout() {
|
||||
if (this.auth && this.auth.isAuthenticated()) {
|
||||
this.auth.toggleAuthentication();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
toggleEditMode() {
|
||||
return this.auth ? this.auth.toggleEditMode() : null;
|
||||
},
|
||||
|
||||
|
||||
isAuthenticated() {
|
||||
return this.auth ? this.auth.isAuthenticated() : false;
|
||||
},
|
||||
|
||||
|
||||
isEditMode() {
|
||||
return this.auth ? this.auth.isEditMode() : false;
|
||||
},
|
||||
|
||||
// Version info
|
||||
version: '1.0.0'
|
||||
|
||||
// TODO: Version info based on package.json?
|
||||
};
|
||||
|
||||
// Auto-initialize in development mode with proper DOM ready handling
|
||||
function autoInitialize() {
|
||||
if (document.querySelector('[data-insertr-enhanced="true"]')) {
|
||||
if (document.querySelector('.insertr')) {
|
||||
window.Insertr.init();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -126,11 +126,11 @@ func (i *Injector) injectLinkContent(node *html.Node, content string) {
|
||||
i.injectTextContent(node, content)
|
||||
}
|
||||
|
||||
// addContentAttributes adds necessary data attributes for editor functionality
|
||||
// addContentAttributes adds necessary data attributes and insertr class for editor functionality
|
||||
func (i *Injector) addContentAttributes(node *html.Node, contentID string, contentType string) {
|
||||
i.setAttribute(node, "data-content-id", contentID)
|
||||
i.setAttribute(node, "data-content-type", contentType)
|
||||
i.setAttribute(node, "data-insertr-enhanced", "true")
|
||||
i.addClass(node, "insertr")
|
||||
}
|
||||
|
||||
// InjectEditorAssets adds editor JavaScript and CSS to HTML document
|
||||
@@ -193,6 +193,48 @@ func (i *Injector) setAttribute(node *html.Node, key, value string) {
|
||||
})
|
||||
}
|
||||
|
||||
// addClass safely adds a class to an HTML node
|
||||
func (i *Injector) addClass(node *html.Node, className string) {
|
||||
var classAttr *html.Attribute
|
||||
var classIndex int = -1
|
||||
|
||||
// Find existing class attribute
|
||||
for idx, attr := range node.Attr {
|
||||
if attr.Key == "class" {
|
||||
classAttr = &attr
|
||||
classIndex = idx
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var classes []string
|
||||
if classAttr != nil {
|
||||
classes = strings.Fields(classAttr.Val)
|
||||
}
|
||||
|
||||
// Check if class already exists
|
||||
for _, class := range classes {
|
||||
if class == className {
|
||||
return // Class already exists
|
||||
}
|
||||
}
|
||||
|
||||
// Add new class
|
||||
classes = append(classes, className)
|
||||
newClassValue := strings.Join(classes, " ")
|
||||
|
||||
if classIndex >= 0 {
|
||||
// Update existing class attribute
|
||||
node.Attr[classIndex].Val = newClassValue
|
||||
} else {
|
||||
// Add new class attribute
|
||||
node.Attr = append(node.Attr, html.Attribute{
|
||||
Key: "class",
|
||||
Val: newClassValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Element represents a parsed HTML element with metadata
|
||||
type Element struct {
|
||||
Node *html.Node
|
||||
|
||||
Reference in New Issue
Block a user