本文整理汇总了TypeScript中@ephox/agar.Chain类的典型用法代码示例。如果您正苦于以下问题:TypeScript Chain类的具体用法?TypeScript Chain怎么用?TypeScript Chain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Chain类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
return input.each(function (b) {
return next(Chain.wrap(SelectionBookmark.validate(root, b)));
});
示例2: function
UnitTest.asynctest('browser.tinymce.core.focus.EditorFocusTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const viewBlock = ViewBlock();
Theme();
const cCreateInlineEditor = function (html) {
return Chain.on(function (viewBlock, next, die) {
viewBlock.update(html);
EditorManager.init({
selector: '.tinymce-editor',
inline: true,
skin_url: '/project/js/tinymce/skins/lightgray',
setup (editor) {
editor.on('SkinLoaded', function () {
next(Chain.wrap(editor));
});
}
});
});
};
const cFocusEditor = Chain.op(function (editor) {
EditorFocus.focus(editor, false);
});
const cFocusElement = function (elementPath) {
return Chain.op(function (editor) {
const element = Hierarchy.follow(Element.fromDom(editor.getBody()), elementPath).getOrDie();
element.dom().focus();
});
};
const cSetSelection = function (startPath, startOffset, endPath, endOffset) {
return Chain.op(function (editor) {
const startContainer = Hierarchy.follow(Element.fromDom(editor.getBody()), startPath).getOrDie();
const endContainer = Hierarchy.follow(Element.fromDom(editor.getBody()), endPath).getOrDie();
const rng = editor.dom.createRng();
rng.setStart(startContainer.dom(), startOffset);
rng.setEnd(endContainer.dom(), endOffset);
editor.selection.setRng(rng);
});
};
const cAssertSelection = function (startPath, startOffset, endPath, endOffset) {
return Chain.op(function (editor) {
const startContainer = Hierarchy.follow(Element.fromDom(editor.getBody()), startPath).getOrDie();
const endContainer = Hierarchy.follow(Element.fromDom(editor.getBody()), endPath).getOrDie();
const rng = editor.selection.getRng();
Assertions.assertDomEq('Should be expected from start container', startContainer, Element.fromDom(rng.startContainer));
Assertions.assertEq('Should be expected from start offset', startOffset, rng.startOffset);
Assertions.assertDomEq('Should be expected end container', endContainer, Element.fromDom(rng.endContainer));
Assertions.assertEq('Should be expected end offset', endOffset, rng.endOffset);
});
};
const cAssertHasFocus = function (elementPath) {
return Chain.op(function (editor) {
const element = Hierarchy.follow(Element.fromDom(editor.getBody()), elementPath).getOrDie();
Assertions.assertEq('Should have focus on the editor', true, EditorFocus.hasFocus(editor));
Assertions.assertDomEq('Should be the expected activeElement', element, Focus.active().getOrDie());
});
};
const cRemoveEditor = Chain.op(function (editor) {
editor.remove();
});
viewBlock.attach();
Pipeline.async({}, [
Logger.t('Focus editor', GeneralSteps.sequence([
Logger.t('Focus editor initialized on a table', Chain.asStep(viewBlock, [
cCreateInlineEditor('<table class="tinymce-editor"><tbody><tr><td>a</td></tr></tbody></table>'),
cFocusEditor,
cAssertSelection([0, 0, 0, 0], 0, [0, 0, 0, 0], 0),
cRemoveEditor
])),
Logger.t('Focus editor initialized on a div with p', Chain.asStep(viewBlock, [
cCreateInlineEditor('<div class="tinymce-editor"><p>a</p></div>'),
cFocusEditor,
cAssertSelection([0, 0], 0, [0, 0], 0),
cRemoveEditor
])),
Logger.t('Focus editor initialized on a list', Chain.asStep(viewBlock, [
cCreateInlineEditor('<ul class="tinymce-editor"><li>a</li></ul>'),
cFocusEditor,
cAssertSelection([0, 0], 0, [0, 0], 0),
cRemoveEditor
]))
])),
Logger.t('hasFocus', GeneralSteps.sequence([
Logger.t('Focus on normal paragraph', Chain.asStep(viewBlock, [
cCreateInlineEditor('<div class="tinymce-editor"><p>a</p></div>'),
cFocusEditor,
cAssertHasFocus([]),
//.........这里部分代码省略.........
示例3: Plugin
UnitTest.asynctest('browser.tinymce.plugins.table.ResizeTableTest', (success, failure) => {
const lastObjectResizeStartEvent = Cell<any>(null);
const lastObjectResizedEvent = Cell<any>(null);
Plugin();
Theme();
const cGetBody = Chain.mapper(function (editor: any) {
return TinyDom.fromDom(editor.getBody());
});
const cInsertTable = function (cols, rows) {
return Chain.mapper(function (editor: any) {
return TinyDom.fromDom(editor.plugins.table.insertTable(cols, rows));
});
};
const cDragHandle = function (id, deltaH, deltaV) {
return NamedChain.asChain([
NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
NamedChain.direct('editor', cGetBody, 'editorBody'),
NamedChain.read('editorBody', Chain.control(
UiFinder.cFindIn('#mceResizeHandle' + id),
Guard.tryUntil('wait for resize handlers', 100, 40000)
)),
NamedChain.read('editorBody', Chain.fromChains([
UiFinder.cFindIn('#mceResizeHandle' + id),
Mouse.cMouseDown,
Mouse.cMouseMoveTo(deltaH, deltaV),
Mouse.cMouseUp
])),
NamedChain.outputInput
]);
};
const cGetWidth = Chain.mapper(function (input: any) {
const editor = input.editor;
const elm = input.element.dom();
const rawWidth = editor.dom.getStyle(elm, 'width');
const pxWidth = editor.dom.getStyle(elm, 'width', true);
return {
raw: parseFloat(rawWidth),
px: parseInt(pxWidth, 10),
isPercent: /%$/.test(rawWidth)
};
});
const assertWithin = function (value, min, max) {
Assertions.assertEq('asserting if value falls within a certain range', true, value >= min && value <= max);
};
const cAssertWidths = Chain.op(function (input: any) {
const expectedPx = input.widthBefore.px - 100;
const expectedPercent = input.widthAfter.px / input.widthBefore.px * 100;
// not able to match the percent exactly - there's always a difference in fractions, so lets assert a small range instead
assertWithin(input.widthAfter.px, expectedPx - 1, expectedPx + 1);
Assertions.assertEq('table width should be in percents', true, input.widthAfter.isPercent);
assertWithin(input.widthAfter.raw, expectedPercent - 1, expectedPercent + 1);
});
const cBindResizeEvents = Chain.mapper(function (input: any) {
const objectResizeStart = (e) => {
lastObjectResizeStartEvent.set(e);
};
const objectResized = (e) => {
lastObjectResizedEvent.set(e);
};
input.editor.on('ObjectResizeStart', objectResizeStart);
input.editor.on('ObjectResized', objectResized);
return {
objectResizeStart,
objectResized
};
});
const cUnbindResizeEvents = Chain.mapper(function (input: any) {
input.editor.off('ObjectResizeStart', input.events.objectResizeStart);
input.editor.off('ObjectResized', input.events.objectResized);
return {};
});
const cClearResizeEventData = Chain.op(() => {
lastObjectResizeStartEvent.set(null);
lastObjectResizedEvent.set(null);
});
const cTableInsertResizeMeasure = NamedChain.asChain([
NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
NamedChain.write('events', cBindResizeEvents),
NamedChain.direct('editor', cInsertTable(5, 2), 'element'),
NamedChain.write('widthBefore', cGetWidth),
NamedChain.read('element', Mouse.cTrueClick),
NamedChain.read('editor', cDragHandle('se', -100, 0)),
NamedChain.write('widthAfter', cGetWidth),
NamedChain.write('events', cUnbindResizeEvents),
NamedChain.merge(['widthBefore', 'widthAfter'], 'widths'),
//.........这里部分代码省略.........
示例4: function
const sSetFieldValue = function (value) {
return Chain.asStep({ }, [
cGetFocused,
UiControls.cSetValue(value)
]);
};
示例5: TinyApis
TinyLoader.setup(function (editor, onSuccess, onFailure) {
const tinyApis = TinyApis(editor);
const inlineFormat = [{ inline: 'b' }];
const blockFormat = [{ block: 'div' }];
const selectorFormat = [{ selector: 'div', classes: 'b' }];
const selectorFormatCollapsed = [{ selector: 'div', classes: 'b', collapsed: true }];
Pipeline.async({}, [
tinyApis.sFocus,
Logger.t('Expand inline format words', GeneralSteps.sequence([
Logger.t('In middle of single word in paragraph', Chain.asStep(editor, [
cSetRawContent('<p>ab</p>'),
cExpandRng([0, 0], 1, [0, 0], 1, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('In middle of single word in paragraph with paragraph siblings', Chain.asStep(editor, [
cSetRawContent('<p>a</p><p>bc</p><p>de</p>'),
cExpandRng([1, 0], 1, [1, 0], 1, inlineFormat, false),
cAssertRange(editor, [], 1, [], 2)
])),
Logger.t('In middle of single word wrapped in b', Chain.asStep(editor, [
cSetRawContent('<p><b>ab</b></p>'),
cExpandRng([0, 0, 0], 1, [0, 0, 0], 1, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('In middle of first word', Chain.asStep(editor, [
cSetRawContent('<p>ab cd</p>'),
cExpandRng([0, 0], 1, [0, 0], 1, inlineFormat, false),
cAssertRange(editor, [], 0, [0, 0], 2)
])),
Logger.t('In middle of last word', Chain.asStep(editor, [
cSetRawContent('<p>ab cd</p>'),
cExpandRng([0, 0], 4, [0, 0], 4, inlineFormat, false),
cAssertRange(editor, [0, 0], 3, [], 1)
])),
Logger.t('In middle of middle word', Chain.asStep(editor, [
cSetRawContent('<p>ab cd ef</p>'),
cExpandRng([0, 0], 4, [0, 0], 4, inlineFormat, false),
cAssertRange(editor, [0, 0], 3, [0, 0], 5)
])),
Logger.t('In middle of word with bold siblings expand to sibling spaces', Chain.asStep(editor, [
cSetRawContent('<p><b>ab </b>cd<b> ef</b></p>'),
cExpandRng([0, 1], 1, [0, 1], 1, inlineFormat, false),
cAssertRange(editor, [0, 0, 0], 3, [0, 2, 0], 0)
])),
Logger.t('In middle of word with block sibling and inline sibling expand to sibling space to the right', Chain.asStep(editor, [
cSetRawContent('<div><p>ab </p>cd<b> ef</b></div>'),
cExpandRng([0, 1], 1, [0, 1], 1, inlineFormat, false),
cAssertRange(editor, [0, 1], 0, [0, 2, 0], 0)
])),
Logger.t('In middle of word with block sibling and inline sibling expand to sibling space to the left', Chain.asStep(editor, [
cSetRawContent('<div><b>ab </b>cd<p> ef</p></div>'),
cExpandRng([0, 1], 1, [0, 1], 1, inlineFormat, false),
cAssertRange(editor, [0, 0, 0], 3, [0, 1], 2)
])),
Logger.t('In middle of middle word separated by nbsp characters', Chain.asStep(editor, [
cSetRawContent('<p>ab\u00a0cd\u00a0ef</p>'),
cExpandRng([0, 0], 4, [0, 0], 4, inlineFormat, false),
cAssertRange(editor, [0, 0], 3, [0, 0], 5)
])),
Logger.t('In empty paragraph', Chain.asStep(editor, [
cSetRawContent('<p><br></p>'),
cExpandRng([0], 0, [0], 0, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('Fully selected word', Chain.asStep(editor, [
cSetRawContent('<p>ab</p>'),
cExpandRng([0, 0], 0, [0, 0], 2, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('Partially selected word', Chain.asStep(editor, [
cSetRawContent('<p>abc</p>'),
cExpandRng([0, 0], 1, [0, 0], 2, inlineFormat, false),
cAssertRange(editor, [0, 0], 1, [0, 0], 2)
])),
Logger.t('Whole word selected wrapped in multiple inlines', Chain.asStep(editor, [
cSetRawContent('<p><b><i>c</i></b></p>'),
cExpandRng([0, 0, 0, 0], 0, [0, 0, 0, 0], 1, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('Whole word inside td', Chain.asStep(editor, [
cSetRawContent('<table><tbody><tr><td>a</td></tr></tbody></table>'),
cExpandRng([0, 0, 0, 0, 0], 0, [0, 0, 0, 0, 0], 1, inlineFormat, false),
cAssertRange(editor, [0, 0, 0], 0, [0, 0, 0], 1)
])),
Logger.t('In middle of single word in paragraph (index based)', Chain.asStep(editor, [
cSetRawContent('<p>ab</p>'),
cExpandRng([0], 0, [0], 1, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('In middle of single word wrapped in bold in paragraph (index based)', Chain.asStep(editor, [
cSetRawContent('<p><b>ab</b></p>'),
cExpandRng([0], 0, [0], 1, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
])),
Logger.t('In middle of word inside bookmark then exclude bookmark', Chain.asStep(editor, [
cSetRawContent('<p><span data-mce-type="bookmark">ab cd ef</span></p>'),
cExpandRng([0, 0, 0], 3, [0, 0, 0], 5, inlineFormat, false),
cAssertRange(editor, [], 0, [], 1)
]))
//.........这里部分代码省略.........
示例6:
const cAssertEventData = (state, expectedEventName) => Chain.op((_) => {
Assertions.assertEq('Should be table element', 'TABLE', state.get().target.nodeName);
Assertions.assertEq('Should be expected resize event', expectedEventName, state.get().type);
Assertions.assertEq('Should have width', 'number', typeof state.get().width);
Assertions.assertEq('Should have height', 'number', typeof state.get().height);
});
示例7:
const cAssertTextareaDisplayStyle = (expected) => Chain.op((editor: any) => {
const textareaElement = editor.getElement();
RawAssertions.assertEq('element does not have the expected style', expected, textareaElement.style.display);
});
示例8: Theme
UnitTest.asynctest('browser.tinymce.core.EditorRemoveTest', (success, failure) => {
Theme();
const settings = {
skin_url: '/project/js/tinymce/skins/lightgray'
};
const cAssertTextareaDisplayStyle = (expected) => Chain.op((editor: any) => {
const textareaElement = editor.getElement();
RawAssertions.assertEq('element does not have the expected style', expected, textareaElement.style.display);
});
const cCreateEditor = Chain.mapper(() => new Editor('editor', {}, EditorManager));
const cRemoveEditor = Chain.op((editor: any) => editor.remove());
Pipeline.async({}, [
Logger.t('remove editor without initializing it', Chain.asStep({}, [
cCreateEditor,
cRemoveEditor,
])),
Logger.t('remove editor where the body has been removed', Chain.asStep({}, [
McEditor.cFromHtml('<textarea></textarea>', settings),
Chain.mapper((value) => {
const body = value.getBody();
body.parentNode.removeChild(body);
return value;
}),
McEditor.cRemove
])),
Logger.t('init editor with no display style', Chain.asStep({}, [
McEditor.cFromHtml('<textarea id="tinymce"></textarea>', settings),
cAssertTextareaDisplayStyle('none'),
cRemoveEditor,
cAssertTextareaDisplayStyle(''),
Chain.op((editor) => EditorManager.init({ selector: '#tinymce' })),
cAssertTextareaDisplayStyle(''),
McEditor.cRemove
])),
Logger.t('init editor with display: none', Chain.asStep({}, [
McEditor.cFromHtml('<textarea id="tinymce" style="display: none;"></textarea>', settings),
cAssertTextareaDisplayStyle('none'),
cRemoveEditor,
cAssertTextareaDisplayStyle('none'),
Chain.op((editor) => EditorManager.init({ selector: '#tinymce' })),
cAssertTextareaDisplayStyle('none'),
McEditor.cRemove
])),
Logger.t('init editor with display: block', Chain.asStep({}, [
McEditor.cFromHtml('<textarea id="tinymce" style="display: block;"></textarea>', settings),
cAssertTextareaDisplayStyle('none'),
cRemoveEditor,
cAssertTextareaDisplayStyle('block'),
Chain.op((editor) => EditorManager.init({ selector: '#tinymce' })),
cAssertTextareaDisplayStyle('block'),
McEditor.cRemove
]))
], () => {
success();
}, failure);
});
示例9: function
UnitTest.asynctest('browser.tinymce.core.keyboard.InlineUtilsTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const ZWSP = Zwsp.ZWSP;
const cCreateElement = function (html) {
return Chain.mapper(function (_) {
return Element.fromHtml(html);
});
};
const cNormalizePosition = function (forward, path, offset) {
return Chain.mapper(function (elm) {
const container = Hierarchy.follow(elm, path).getOrDie();
const pos = new CaretPosition(container.dom(), offset);
return { pos: InlineUtils.normalizePosition(forward, pos), elm };
});
};
const cAssertPosition = function (path, expectedOffset) {
return Chain.mapper(function (elmPos) {
const expectedContainer = Hierarchy.follow(elmPos.elm, path).getOrDie();
Assertions.assertDomEq('Should be expected container', Element.fromDom(elmPos.pos.container()), expectedContainer);
Assertions.assertEq('Should be expected offset', elmPos.pos.offset(), expectedOffset);
return {};
});
};
const cSplitAt = function (path, offset) {
return Chain.mapper(function (elm) {
const textNode = Hierarchy.follow(elm, path).getOrDie();
textNode.dom().splitText(offset);
return elm;
});
};
const createFakeEditor = function (settings) {
return {
settings
};
};
Pipeline.async({}, [
Logger.t('isInlineTarget with various editor settings', Step.sync(function () {
Assertions.assertEq('Links should be inline target', true, InlineUtils.isInlineTarget(createFakeEditor({ }), Element.fromHtml('<a href="a">').dom()));
Assertions.assertEq('Code should be inline target', true, InlineUtils.isInlineTarget(createFakeEditor({ }), Element.fromHtml('<code>').dom()));
Assertions.assertEq('None link anchor should not be inline target', false, InlineUtils.isInlineTarget(createFakeEditor({ }), Element.fromHtml('<a>').dom()));
Assertions.assertEq('Bold should not be inline target', false, InlineUtils.isInlineTarget(createFakeEditor({ }), Element.fromHtml('<b>').dom()));
Assertions.assertEq('Bold should be inline target if configured', true, InlineUtils.isInlineTarget(createFakeEditor({
inline_boundaries_selector: 'b'
}), Element.fromHtml('<b>').dom()));
Assertions.assertEq('Italic should be inline target if configured', true, InlineUtils.isInlineTarget(createFakeEditor({
inline_boundaries_selector: 'b,i'
}), Element.fromHtml('<i>').dom()));
})),
Logger.t('normalizePosition on text forwards', GeneralSteps.sequence([
Logger.t('normalizePosition start of zwsp before text', Chain.asStep({}, [
cCreateElement('<p>' + ZWSP + 'a</p>'),
cNormalizePosition(true, [0], 0),
cAssertPosition([0], 1)
])),
Logger.t('normalizePosition end of zwsp before text', Chain.asStep({}, [
cCreateElement('<p>' + ZWSP + 'a</p>'),
cNormalizePosition(true, [0], 1),
cAssertPosition([0], 1)
])),
Logger.t('normalizePosition start of zwsp after text', Chain.asStep({}, [
cCreateElement('<p>a' + ZWSP + '</p>'),
cNormalizePosition(true, [0], 1),
cAssertPosition([0], 2)
])),
Logger.t('normalizePosition end of zwsp after text', Chain.asStep({}, [
cCreateElement('<p>a' + ZWSP + '</p>'),
cNormalizePosition(true, [0], 2),
cAssertPosition([0], 2)
]))
])),
Logger.t('normalizePosition on text backwards', GeneralSteps.sequence([
Logger.t('normalizePosition end of zwsp after text', Chain.asStep({}, [
cCreateElement('<p>a' + ZWSP + '</p>'),
cNormalizePosition(false, [0], 2),
cAssertPosition([0], 1)
])),
Logger.t('normalizePosition start of zwsp after text', Chain.asStep({}, [
cCreateElement('<p>a' + ZWSP + '</p>'),
cNormalizePosition(false, [0], 1),
cAssertPosition([0], 1)
])),
Logger.t('normalizePosition end of zwsp before text', Chain.asStep({}, [
cCreateElement('<p>' + ZWSP + 'a</p>'),
cNormalizePosition(false, [0], 1),
cAssertPosition([0], 0)
])),
Logger.t('normalizePosition start of zwsp before text', Chain.asStep({}, [
cCreateElement('<p>' + ZWSP + 'a</p>'),
cNormalizePosition(false, [0], 0),
cAssertPosition([0], 0)
]))
//.........这里部分代码省略.........