{"version":3,"sources":["jsdelivr-header.js","/npm/scribe-plugin-intelligent-unlink-command@0.1.6/src/scribe-plugin-intelligent-unlink-command.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,OAAO,IAAI,WAOT,aAEA,OAAO,WACL,OAAO,SAAU,GACf,IAAI,EAAU,EAAO,QAEjB,EAAgB,IAAI,EAAO,IAAI,QAAQ,UAE3C,EAAc,QAAU,WACtB,IAAI,EAAY,IAAI,EAAO,IAAI,UAE3B,EAAU,UAAU,YACtB,EAAO,mBAAmB,KAAI,WAK5B,IAAI,EAAQ,EAAU,eAAc,SAAU,GAC5C,MAAyB,MAAlB,EAAK,QACd,IAEI,IAGF,EAAU,eAGV,EAAQ,OAAO,EAAM,WAAY,GAGjC,EAAU,gBAEd,IAEA,EAAO,IAAI,QAAQ,UAAU,QAAQ,MAAM,KAAM,UAErD,EAEA,EAAc,aAAe,WAC3B,IAAI,EAAY,IAAI,EAAO,IAAI,UAC/B,OAAI,EAAU,UAAU,cACZ,EAAU,eAAc,SAAU,GAC1C,MAAyB,MAAlB,EAAK,QACd,IAEO,EAAO,IAAI,QAAQ,UAAU,aAAa,MAAM,KAAM,UAEjE,EAEA,EAAO,SAAS,OAAS,CAC3B,CACF,CAEF","file":"/npm/scribe-plugin-intelligent-unlink-command@0.1.6/src/scribe-plugin-intelligent-unlink-command.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/scribe-plugin-intelligent-unlink-command@0.1.6/src/scribe-plugin-intelligent-unlink-command.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","define([], function () {\n\n  /**\n   * This plugin modifies the `unlink` command so that, when the user's\n   * selection is collapsed, remove the containing A.\n   */\n\n  'use strict';\n\n  return function () {\n    return function (scribe) {\n      var element = scribe.element;\n      \n      var unlinkCommand = new scribe.api.Command('unlink');\n\n      unlinkCommand.execute = function () {\n        var selection = new scribe.api.Selection();\n\n        if (selection.selection.isCollapsed) {\n          scribe.transactionManager.run(function () {\n            /**\n             * If the selection is collapsed, we can remove the containing anchor.\n             */\n\n            var aNode = selection.getContaining(function (node) {\n              return node.nodeName === 'A';\n            });\n\n            if (aNode) {\n              // we must save and then restore the selection because unwrapping\n              // the anchor loses the current selection\n              selection.placeMarkers();\n\n              // unwrap the A element's children, then remove it\n              element.unwrap(aNode.parentNode, aNode);\n\n              // finally restore selection to the initial position\n              selection.selectMarkers();\n            }\n          });\n        } else {\n          scribe.api.Command.prototype.execute.apply(this, arguments);\n        }\n      };\n\n      unlinkCommand.queryEnabled = function () {\n        var selection = new scribe.api.Selection();\n        if (selection.selection.isCollapsed) {\n          return !! selection.getContaining(function (node) {\n            return node.nodeName === 'A';\n          });\n        } else {\n          return scribe.api.Command.prototype.queryEnabled.apply(this, arguments);\n        }\n      };\n\n      scribe.commands.unlink = unlinkCommand;\n    };\n  };\n\n});\n"]}