Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'mobiledoc-kit' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
function triggerKeyCommand(editor, string, modifiers=[]) {
if (typeof modifiers === "number") {
modifiers = [modifiers]; // convert singular to array
}
let charCode = (KEY_CODES[string] || string.toUpperCase().charCodeAt(0));
let keyCode = charCode;
let keyEvent = createMockEvent('keydown', editor.element, {
charCode,
keyCode,
shiftKey: contains(modifiers, MODIFIERS.SHIFT),
metaKey: contains(modifiers, MODIFIERS.META),
ctrlKey: contains(modifiers, MODIFIERS.CTRL)
});
_triggerEditorEvent(editor, keyEvent);
}
_initEditorWithEventEmitters () {
this.$emit('willCreateEditor')
this.editor = new Mobiledoc.Editor(this.editorOptions)
if (this.enableEditing === false) this.toggleEditMode()
this.$emit('didCreateEditor', this.editor)
this.editor.inputModeDidChange(() => {
this._updateActiveMarkupTags()
this._updateActiveSectionTags()
})
this.editor.postDidChange(() => {
// serialize the editor's post to the mobiledoc version format
// any cards or atoms present in doc, will be ommited
const mobiledoc = this.editor.serialize(this.serializeVersion)
this.$emit('postWasUpdated', mobiledoc)
})
&& isListSection
&& tagName !== lastSection.tagName;
if (
isNewListSection ||
(isListSection && !isNestedListSection) ||
isMarkupSection ||
isListItem
) {
// don't break out of the list for list items that contain a single <p>.
// deals with typical case of </p><li><p>Text</p></li><li><p>Text</p></li>
if (
this.state.section.isListItem &&
tagName === 'p' &&
!node.nextSibling &&
contains(VALID_LIST_ITEM_TAGNAMES, normalizeTagName(node.parentElement.tagName))
) {
this.parseElementNode(node);
return;
}
// avoid creating empty paragraphs due to wrapper elements around
// section-creating elements
if (this.state.section.isMarkerable && !this.state.text && this.state.section.markers.length === 0) {
this.state.section = null;
} else {
this._closeCurrentSection();
}
this._updateStateFromElement(node);
}
parseNode(node) {
if (!this.state.section) {
this._updateStateFromElement(node);
}
let nodeFinished = this.runPlugins(node);
if (nodeFinished) {
return;
}
// handle closing the current section and starting a new one if we hit a
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection && this.state.section.isListItem;
let lastSection = this.sections[this.sections.length - 1];
// we can hit a list item after parsing a nested list, when that happens
// and the lists are of different types we need to make sure we switch
// the list type back
if (isListItem && lastSection && lastSection.isListSection) {
let parentElement = node.parentElement;
let parentElementTagName = normalizeTagName(parentElement.tagName);
if (parentElementTagName !== lastSection.tagName) {
this._closeCurrentSection();
this._updateStateFromElement(parentElement);
}
}
parseNode(node) {
if (!this.state.section) {
this._updateStateFromElement(node);
}
let nodeFinished = this.runPlugins(node);
if (nodeFinished) {
return;
}
// handle closing the current section and starting a new one if we hit a
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection && this.state.section.isListItem;
let lastSection = this.sections[this.sections.length - 1];
// we can hit a list item after parsing a nested list, when that happens
// and the lists are of different types we need to make sure we switch
// the list type back
if (isListItem && lastSection && lastSection.isListSection) {
let parentElement = node.parentElement;
let parentElementTagName = normalizeTagName(parentElement.tagName);
if (parentElementTagName !== lastSection.tagName) {
this._closeCurrentSection();
this._updateStateFromElement(parentElement);
}
}
if (!this.state.section) {
this._updateStateFromElement(node);
}
let nodeFinished = this.runPlugins(node);
if (nodeFinished) {
return;
}
// handle closing the current section and starting a new one if we hit a
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection && this.state.section.isListItem;
let lastSection = this.sections[this.sections.length - 1];
// we can hit a list item after parsing a nested list, when that happens
// and the lists are of different types we need to make sure we switch
// the list type back
if (isListItem && lastSection && lastSection.isListSection) {
let parentElement = node.parentElement;
let parentElementTagName = normalizeTagName(parentElement.tagName);
if (parentElementTagName !== lastSection.tagName) {
this._closeCurrentSection();
this._updateStateFromElement(parentElement);
}
}
// if we've broken out of a list due to nested section-level elements we
parseNode(node) {
if (!this.state.section) {
this._updateStateFromElement(node);
}
let nodeFinished = this.runPlugins(node);
if (nodeFinished) {
return;
}
// handle closing the current section and starting a new one if we hit a
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection && this.state.section.isListItem;
let lastSection = this.sections[this.sections.length - 1];
// we can hit a list item after parsing a nested list, when that happens
// and the lists are of different types we need to make sure we switch
// the list type back
if (isListItem && lastSection && lastSection.isListSection) {
let parentElement = node.parentElement;
let parentElementTagName = normalizeTagName(parentElement.tagName);
if (parentElementTagName !== lastSection.tagName) {
this._closeCurrentSection();
this._updateStateFromElement(parentElement);
}
}
if (!this.state.section) {
this._updateStateFromElement(node);
}
let nodeFinished = this.runPlugins(node);
if (nodeFinished) {
return;
}
// handle closing the current section and starting a new one if we hit a
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection && this.state.section.isListItem;
let lastSection = this.sections[this.sections.length - 1];
// we can hit a list item after parsing a nested list, when that happens
// and the lists are of different types we need to make sure we switch
// the list type back
if (isListItem && lastSection && lastSection.isListSection) {
let parentElement = node.parentElement;
let parentElementTagName = normalizeTagName(parentElement.tagName);
if (parentElementTagName !== lastSection.tagName) {
this._closeCurrentSection();
this._updateStateFromElement(parentElement);
}
}
// if we've broken out of a list due to nested section-level elements we
function getEventTargetMatchingTag(tagName, target, container) {
tagName = normalizeTagName(tagName);
// Traverses up DOM from an event target to find the node matching specifed tag
while (target && target !== container) {
if (normalizeTagName(target.tagName) === tagName) {
return target;
}
target = target.parentNode;
}
}
parseNode(node) {
if (!this.state.section) {
this._updateStateFromElement(node);
}
let nodeFinished = this.runPlugins(node);
if (nodeFinished) {
return;
}
// handle closing the current section and starting a new one if we hit a
// new-section-creating element.
if (this.state.section && !isTextNode(node) && node.tagName) {
let tagName = normalizeTagName(node.tagName);
let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
let isNestedListSection = isListSection && this.state.section.isListItem;
let lastSection = this.sections[this.sections.length - 1];
// we can hit a list item after parsing a nested list, when that happens
// and the lists are of different types we need to make sure we switch
// the list type back
if (isListItem && lastSection && lastSection.isListSection) {
let parentElement = node.parentElement;
let parentElementTagName = normalizeTagName(parentElement.tagName);
if (parentElementTagName !== lastSection.tagName) {
this._closeCurrentSection();
this._updateStateFromElement(parentElement);
}