UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

49 lines 1.6 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any var ADFTraversor = /*#__PURE__*/function () { // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any function ADFTraversor(doc) { _classCallCheck(this, ADFTraversor); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any _defineProperty(this, "subscribers", new Map()); this.doc = doc; } return _createClass(ADFTraversor, [{ key: "subscribe", value: function subscribe(type, callback) { var callbacks = this.subscribers.get(type); if (!callbacks) { this.subscribers.set(type, [callback]); } else { callbacks.push(callback); } } }, { key: "exec", value: function exec() { if (!this.doc || !Array.isArray(this.doc.content)) { return; } var candidates = this.doc.content.slice(0); while (candidates.length) { var _node = candidates.shift(); if (Array.isArray(_node.content)) { candidates = candidates.concat(_node.content); } var callbacks = this.subscribers.get(_node.type); if (!callbacks) { continue; } for (var i = 0; i < callbacks.length; i++) { callbacks[i](_node); } } } }]); }(); export default ADFTraversor;