Skip to content

Commit fe412dc

Browse files
committed
fix: modify multiline plug, add sideEffects for prevent treeshaking
1 parent f2c312b commit fe412dc

File tree

2 files changed

+99
-4
lines changed

2 files changed

+99
-4
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,8 @@
8181
"jest": {
8282
"verbose": true,
8383
"testEnvironment": "jsdom"
84-
}
84+
},
85+
"sideEffects": [
86+
"./es6/*"
87+
]
8588
}

src/plugins/jsmind.multiline-text.js

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* @license BSD
3-
* @copyright 2014-2025 [email protected]
3+
* @copyright 2014-2025 UmbraCi
44
*
55
* Project Home:
6-
* https://github.com/hizzgdev/jsmind/
6+
* https://github.com/UmbraCi/jsmind/
77
*/
88

9-
import jsMind from 'jsmind';
9+
import jsMind from '@umbraci/jsmind';
1010

1111
if (!jsMind) {
1212
throw new Error('jsMind is not defined');
@@ -536,6 +536,98 @@ export class MultilineText {
536536
return createTextElement(text, mergedOptions);
537537
}
538538

539+
/**
540+
* Plugin instance method to render text content into an existing DOM element.
541+
*
542+
* This method automatically uses jsMind configuration settings (like support_html)
543+
* and provides a convenient way to render multiline text within custom node renderers.
544+
*
545+
* @param {HTMLElement} element - Target DOM element to render text into
546+
* @param {string} text - Text content to render (supports \n for line breaks)
547+
* @param {Partial<TextRenderOptions>} [options={}] - Additional rendering options
548+
* @returns {HTMLElement} The element with rendered text content
549+
*
550+
* @example
551+
* // In a custom node render function
552+
* customNodeRender(jm, element, node) {
553+
* const wrapper = document.createElement('div');
554+
* wrapper.style.backgroundColor = '#f0f0f0';
555+
* wrapper.style.padding = '4px';
556+
*
557+
* const textElement = document.createElement('span');
558+
* jm.multiline_text.renderMultilineText(textElement, node.topic);
559+
*
560+
* wrapper.appendChild(textElement);
561+
* element.appendChild(wrapper);
562+
* return true;
563+
* }
564+
*/
565+
renderMultilineText(element, text, options = {}) {
566+
// Prepare options with jsMind configuration
567+
const defaultOptions = {
568+
supportHtml: this.jm.view.opts.support_html || false,
569+
};
570+
571+
// Merge with provided options
572+
const mergedOptions = {};
573+
jsMind.util.json.merge(mergedOptions, defaultOptions);
574+
jsMind.util.json.merge(mergedOptions, options);
575+
576+
// Use static function with merged options
577+
return renderTextToElement(element, text, mergedOptions);
578+
}
579+
580+
/**
581+
* Plugin instance method to create a new DOM element with rendered text content.
582+
*
583+
* This method automatically uses jsMind configuration settings and creates a new
584+
* element with properly rendered multiline text. Useful for building complex
585+
* custom node structures.
586+
*
587+
* @param {string} text - Text content to render (supports \n for line breaks)
588+
* @param {Partial<TextRenderOptions>} [options={}] - Additional rendering options
589+
* @returns {HTMLElement} New DOM element with rendered text content
590+
*
591+
* @example
592+
* // Create a text element for insertion into custom structure
593+
* customNodeRender(jm, element, node) {
594+
* const container = document.createElement('div');
595+
* container.className = 'custom-node';
596+
*
597+
* // Add priority indicator
598+
* if (node.data?.priority) {
599+
* const priority = document.createElement('span');
600+
* priority.className = 'priority-badge';
601+
* priority.textContent = node.data.priority;
602+
* container.appendChild(priority);
603+
* }
604+
*
605+
* // Add multiline text content
606+
* const textElement = jm.multiline_text.createMultilineElement(node.topic, {
607+
* tagName: 'div',
608+
* customClasses: ['node-text']
609+
* });
610+
* container.appendChild(textElement);
611+
*
612+
* element.appendChild(container);
613+
* return true;
614+
* }
615+
*/
616+
createMultilineElement(text, options = {}) {
617+
// Prepare options with jsMind configuration
618+
const defaultOptions = {
619+
supportHtml: this.jm.view.opts.support_html || false,
620+
};
621+
622+
// Merge with provided options
623+
const mergedOptions = {};
624+
jsMind.util.json.merge(mergedOptions, defaultOptions);
625+
jsMind.util.json.merge(mergedOptions, options);
626+
627+
// Use static function with merged options
628+
return createTextElement(text, mergedOptions);
629+
}
630+
539631
/**
540632
* Begin editing a node with multiline support.
541633
* @param {import('../jsmind.node.js').Node} node - Node to edit

0 commit comments

Comments
 (0)