Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const commenceIfNecessary = (context: AutocompleteContext) => {
if (!isActive()) {
// Create the wrapper
const wrapper = AutocompleteTag.create(editor, context.range);
// store the element/context
activeAutocompleter.set(Option.some({
triggerChar: context.triggerChar,
element: wrapper,
matchLength: context.text.length
}));
processingAction.set(false);
}
};
Objects.readOptFrom(scopes.lookupTable, e.toolbarKey).each((ctx) => {
launchContext(ctx, e.target === editor ? Option.none() : Option.some(e as DomElement));
// Forms launched via this way get immediate focus
InlineView.getContent(contextbar).each(Keying.focusIn);
});
});
const getTouch = (event): Option => {
if (event.touches === undefined || event.touches.length !== 1) {
return Option.none();
}
return Option.some(event.touches[0]);
};
const createButton = (innerHtml: string, icon: string, disabled: boolean, action: (button: AlloyComponent) => void, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
return renderIconButton({
name: innerHtml,
icon: Option.some(icon),
disabled,
tooltip: Option.some(innerHtml),
primary: false
}, action, providersBackstage);
};
});
};
const updateSelectMenuText = (parents: Element[], comp: AlloyComponent) => {
const detectedFormat = getMatchingValue(parents);
const text = detectedFormat.fold(() => 'Paragraph', (fmt) => fmt.title);
AlloyTriggers.emitWith(comp, updateMenuText, {
text
});
};
const nodeChangeHandler = Option.some((comp: AlloyComponent) => {
return (e) => updateSelectMenuText(e.parents, comp);
});
const setInitialValue = Option.some((comp: AlloyComponent) => {
const parents = getCurrentSelectionParents(editor);
updateSelectMenuText(parents, comp);
});
const dataset = buildBasicSettingsDataset(editor, 'block_formats', defaultBlocks, Delimiter.SemiColon);
return {
tooltip: 'Blocks',
icon: Option.none(),
isSelectedFor,
getCurrentValue: Fun.constant(Option.none()),
getPreviewFor,
onAction: onActionToggleFormat(editor),
setInitialValue,
nodeChangeHandler,
dataset,
const getRawOrComputed = function (isRoot, rawStart) {
const optStart = Node.isElement(rawStart) ? Option.some(rawStart) : Traverse.parent(rawStart).filter(Node.isElement);
return optStart.map(function (start) {
const inline = PredicateFind.closest(start, (elem) => Css.getRaw(elem, 'font-size').isSome(), isRoot)
.bind((elem) => Css.getRaw(elem, 'font-size'));
return inline.getOrThunk(function () {
return Css.get(start, 'font-size');
});
}).getOr('');
};
const memFooterClose = Memento.record(
renderFooterButton({
name: 'close-alert',
text: 'OK',
primary: true,
align: 'end',
disabled: false,
icon: Option.none()
}, 'cancel', extras.backstage)
);
const alertDialog = GuiFactory.build(
Dialogs.renderDialog({
lazySink: () => sharedBackstage.getSink(),
headerOverride: Option.some(Dialogs.hiddenHeader),
partSpecs: {
title: Dialogs.pUntitled(),
close: Dialogs.pClose(() => {
closeDialog();
}, sharedBackstage.providers),
body: Dialogs.pBodyMessage(message, sharedBackstage.providers),
footer: Dialogs.pFooter(Dialogs.pFooterGroup([], [
memFooterClose.asSpec()
]))
},
onCancel: () => closeDialog(),
onSubmit: Fun.noop,
extraClasses: [ 'tox-alert-dialog' ]
})
);
const extractFromAnchor = (editor: Editor, anchor: HTMLAnchorElement) => {
const dom = editor.dom;
const onlyText = Utils.isOnlyTextSelected(editor.selection.getContent());
const text: Option = onlyText ? Option.some(Utils.getAnchorText(editor.selection, anchor)) : Option.none();
const url: Option = anchor ? Option.some(dom.getAttrib(anchor, 'href')) : Option.none();
const target: Option = anchor ? Option.from(dom.getAttrib(anchor, 'target')) : Option.none();
const rel = nonEmptyAttr(dom, anchor, 'rel');
const linkClass = nonEmptyAttr(dom, anchor, 'class');
const title = nonEmptyAttr(dom, anchor, 'title');
return {
url,
text,
title,
target,
rel,
linkClass
};
};
const getEndNode = function (rng) {
const ec = rng.endContainer, eo = rng.endOffset;
if (NodeType.isText(ec)) {
return eo === ec.data.length ? Option.some(Element.fromDom(ec)) : Option.none();
} else {
return Option.from(ec.childNodes[eo - 1]).map(Element.fromDom);
}
};
return Option.some(pos).filter(hasNbsp).bind((pos) => {
const container = pos.container() as Text;
const normalized = normalizeNbspAtStart(root, container) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container);
return normalized ? Option.some(pos) : Option.none();
});
};