|
1 | 1 | /** |
2 | 2 | * @license BSD |
3 | | - * @copyright 2014-2025 [email protected] |
| 3 | + * @copyright 2014-2025 UmbraCi |
4 | 4 | * |
5 | 5 | * Project Home: |
6 | | - * https://github.com/hizzgdev/jsmind/ |
| 6 | + * https://github.com/UmbraCi/jsmind/ |
7 | 7 | */ |
8 | 8 |
|
9 | | -import jsMind from 'jsmind'; |
| 9 | +import jsMind from '@umbraci/jsmind'; |
10 | 10 |
|
11 | 11 | if (!jsMind) { |
12 | 12 | throw new Error('jsMind is not defined'); |
@@ -536,6 +536,98 @@ export class MultilineText { |
536 | 536 | return createTextElement(text, mergedOptions); |
537 | 537 | } |
538 | 538 |
|
| 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 | + |
539 | 631 | /** |
540 | 632 | * Begin editing a node with multiline support. |
541 | 633 | * @param {import('../jsmind.node.js').Node} node - Node to edit |
|
0 commit comments