markupeditor 0.9.36 → 0.9.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35623,6 +35623,19 @@ function insertLinkCommand(url) {
35623
35623
  return commandAdapter;
35624
35624
  }
35625
35625
 
35626
+ /**
35627
+ * Insert a link to the header identified by hTag ('H1'-'H6') and index (its position among
35628
+ * headers with that tag), assigning the header a unique id if it doesn't already have one.
35629
+ *
35630
+ * @param {string} hTag One of the strings `H1`-`H6`
35631
+ * @param {number} index Within existing elements with tag `hTag`, this is the index into them that is identified
35632
+ */
35633
+ function insertInternalLink(hTag, index) {
35634
+ const view = activeView();
35635
+ let command = insertInternalLinkCommand(hTag, index);
35636
+ let result = command(view.state, view.dispatch, view);
35637
+ return result
35638
+ }
35626
35639
  function insertInternalLinkCommand(hTag, index) {
35627
35640
  const commandAdapter = (state, dispatch, view) => {
35628
35641
  // Find the node matching hTag that is index into the nodes matching hTag
@@ -35737,12 +35750,42 @@ function headerMatching(hTag, index, state) {
35737
35750
  }
35738
35751
  }
35739
35752
 
35753
+ /**
35754
+ * Return a JSON-stringified array describing every non-empty header in the document, in document
35755
+ * order within each level. Each entry is `{hTag, index, text, id}`, where `hTag` and `index` identify
35756
+ * the header the same way `insertInternalLink(hTag, index)` and `idForInternalLinkCommand(hTag, index)`
35757
+ * do, and `id` is the header's current id attribute (null if it hasn't been assigned one yet).
35758
+ *
35759
+ * An empty header is omitted -- it can't form a usable id, so there's nothing to link to -- but
35760
+ * `index` still reflects its true position among ALL headers at that level (empty ones included),
35761
+ * matching what `headerMatching` expects; it's only the reported entries that skip empty headers,
35762
+ * not the numbering.
35763
+ *
35764
+ * @returns {string} JSON-stringified array of `{hTag, index, text, id}`
35765
+ */
35766
+ function getHeaders() {
35767
+ const view = activeView();
35768
+ const headersByLevel = headers(view.state);
35769
+ let result = [];
35770
+ for (let level = 1; level < 7; level++) {
35771
+ let hNodes = headersByLevel[level];
35772
+ if (hNodes) {
35773
+ hNodes.forEach((h, index) => {
35774
+ const text = h.node.textContent;
35775
+ if (text.trim().length === 0) return
35776
+ result.push({hTag: 'H' + level.toString(), index: index, text: text, id: h.node.attrs.id ?? null});
35777
+ });
35778
+ }
35779
+ }
35780
+ return JSON.stringify(result)
35781
+ }
35782
+
35740
35783
  /**
35741
35784
  * Return all the headers that exist in `state.doc` as arrays keyed by level.
35742
- *
35785
+ *
35743
35786
  * @ignore
35744
35787
  * @param {EditorState} state The state of the ProseMirror editor
35745
- */
35788
+ */
35746
35789
  function headers(state) {
35747
35790
  let headers = {};
35748
35791
  let hType = state.schema.nodes.heading;
@@ -42749,6 +42792,7 @@ const MU = {
42749
42792
  getDataImages,
42750
42793
  getLocalImages,
42751
42794
  getHTML,
42795
+ getHeaders,
42752
42796
  getHeight,
42753
42797
  getImageAttributes,
42754
42798
  getLinkAttributes,
@@ -42756,6 +42800,7 @@ const MU = {
42756
42800
  getTestHTML,
42757
42801
  indent: indent$1,
42758
42802
  insertImage: insertImage$1,
42803
+ insertInternalLink,
42759
42804
  insertLink: insertLink$1,
42760
42805
  insertTable,
42761
42806
  insertHRule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markupeditor",
3
- "version": "0.9.36",
3
+ "version": "0.9.38",
4
4
  "description": "A web component and API for WYSIWYG HTML editing.",
5
5
  "keywords": [
6
6
  "wysiwyg",