本文整理汇总了TypeScript中@ephox/mcagar.ApiChains.cSetContent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ApiChains.cSetContent方法的具体用法?TypeScript ApiChains.cSetContent怎么用?TypeScript ApiChains.cSetContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/mcagar.ApiChains
的用法示例。
在下文中一共展示了ApiChains.cSetContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: table
TinyLoader.setup(function (editor, onSuccess, onFailure) {
Pipeline.async({}, [
Logger.t('FakeCaret before/after table', GeneralSteps.sequence(browser.isEdge() || browser.isFirefox() ? [
Logger.t('Move fake caret left before table', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 0),
ApiChains.cAssertContentStructure(buildBody([ table('1') ])),
ActionChains.cContentKeystroke(Keys.left()),
ApiChains.cAssertContentStructure(buildBody([ caretBefore(), table('1'), visualCaretBefore() ])),
ApiChains.cAssertSelection([0], 0, [0], 0)
])),
Logger.t('Move fake caret right after table', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 1),
ApiChains.cAssertContentStructure(buildBody([ table('1') ])),
ActionChains.cContentKeystroke(Keys.right()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretAfter(), visualCaretAfter() ])),
ApiChains.cAssertSelection([1], 0, [1], 0)
])),
Logger.t('Move fake caret right after table then right again before other table', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table><table><tbody><tr><td>2</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 1),
ApiChains.cAssertContentStructure(buildBody([ table('1'), table('2') ])),
ActionChains.cContentKeystroke(Keys.right()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretAfter(), table('2'), visualCaretAfter() ])),
ApiChains.cAssertSelection([1], 0, [1], 0),
ActionChains.cContentKeystroke(Keys.right()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretBefore(), table('2'), visualCaretBefore() ])),
ApiChains.cAssertSelection([1], 0, [1], 0)
])),
Logger.t('Move fake caret left before table then left again after other table', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table><table><tbody><tr><td>2</td></tr></tbody></table>'),
ApiChains.cSetCursor([1, 0, 0, 0, 0], 0),
ApiChains.cAssertContentStructure(buildBody([ table('1'), table('2') ])),
ActionChains.cContentKeystroke(Keys.left()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretBefore(), table('2'), visualCaretBefore() ])),
ApiChains.cAssertSelection([1], 0, [1], 0),
ActionChains.cContentKeystroke(Keys.left()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretAfter(), table('2'), visualCaretAfter() ])),
ApiChains.cAssertSelection([1], 0, [1], 0)
])),
Logger.t('Move fake up for when table is first element', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 0),
ApiChains.cAssertContentStructure(buildBody([ table('1') ])),
ActionChains.cContentKeystroke(Keys.up()),
ApiChains.cAssertContentStructure(buildBody([ caretBefore(), table('1'), visualCaretBefore() ])),
ApiChains.cAssertSelection([0], 0, [0], 0)
])),
Logger.t('Move fake down for when table is last element', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 1),
ApiChains.cAssertContentStructure(buildBody([ table('1') ])),
ActionChains.cContentKeystroke(Keys.down()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretAfter(), visualCaretAfter() ])),
ApiChains.cAssertSelection([1], 0, [1], 0)
])),
Logger.t('Move fake up for when table is first element but not when caret is not as start', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 1),
ApiChains.cAssertContentStructure(buildBody([ table('1') ])),
ActionChains.cContentKeystroke(Keys.up()),
ApiChains.cAssertContentStructure(buildBody([ caretBefore(), table('1'), visualCaretBefore() ])),
ApiChains.cAssertSelection([0], 0, [0], 0)
])),
Logger.t('Move fake down for when table is last element but not when caret is not as end', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent('<table><tbody><tr><td>1</td></tr></tbody></table>'),
ApiChains.cSetCursor([0, 0, 0, 0, 0], 0),
ApiChains.cAssertContentStructure(buildBody([ table('1') ])),
ActionChains.cContentKeystroke(Keys.down()),
ApiChains.cAssertContentStructure(buildBody([ table('1'), caretAfter(), visualCaretAfter() ])),
ApiChains.cAssertSelection([1], 0, [1], 0)
]))] : []
)),
Logger.t('Table cell navigation', GeneralSteps.sequence([
Logger.t('Should move to the cell above the current cell on key up', Chain.asStep(editor, [
ApiChains.cFocus,
ApiChains.cSetContent(`
<table>
<tbody>
<tr><td>1</td><td>2</td></tr>
<tr><td>2</td><td>3</td></tr>
</tbody>
</table>
`),
ApiChains.cSetCursor([0, 0, 1, 1, 0], 0),
ActionChains.cContentKeystroke(Keys.up()),
ApiChains.cAssertSelection([0, 0, 0, 1, 0], 0, [0, 0, 0, 1, 0], 0)
])),
Logger.t('Should move to the cell below the current cell on key down', Chain.asStep(editor, [
ApiChains.cFocus,
//.........这里部分代码省略.........
示例2: Plugin
UnitTest.asynctest('browser.tinymce.plugins.table.ResizeTableTest', (success, failure) => {
const lastObjectResizeStartEvent = Cell<any>(null);
const lastObjectResizedEvent = Cell<any>(null);
Plugin();
SilverTheme();
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', TableTestUtils.cInsertTable(5, 2), 'element'),
NamedChain.write('widthBefore', TableTestUtils.cGetWidth),
NamedChain.read('element', Mouse.cTrueClick),
NamedChain.read('editor', TableTestUtils.cDragHandle('se', -100, 0)),
NamedChain.write('widthAfter', TableTestUtils.cGetWidth),
NamedChain.write('events', cUnbindResizeEvents),
NamedChain.merge(['widthBefore', 'widthAfter'], 'widths'),
NamedChain.output('widths')
]);
const cAssertWidthsShouldBe = (unit: string) => Chain.op((input: any) => {
const expectingPercent = (unit === '%');
Assertions.assertEq(`table width before resizing is in ${unit}`, expectingPercent, input.widthBefore.isPercent);
Assertions.assertEq(`table width after resizing is in ${unit}`, expectingPercent, input.widthAfter.isPercent);
});
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);
});
NamedChain.pipeline([
NamedChain.write('editor', Editor.cFromSettings({
plugins: 'table',
width: 400,
theme: 'silver',
base_url: '/project/tinymce/js/tinymce',
})),
// when table is resized by one of the handlers it should retain the dimension units after the resize, be it px or %
cClearResizeEventData,
NamedChain.direct('editor', cTableInsertResizeMeasure, 'widths'),
NamedChain.read('widths', cAssertWidths),
cAssertEventData(lastObjectResizeStartEvent, 'objectresizestart'),
cAssertEventData(lastObjectResizedEvent, 'objectresized'),
// using configuration option [table_responsive_width=true] we are able to control the default units of the table
cClearResizeEventData,
NamedChain.read('editor', ApiChains.cSetContent('')),
NamedChain.direct('editor', cTableInsertResizeMeasure, 'widths'),
NamedChain.read('widths', cAssertWidthsShouldBe('%')),
cAssertEventData(lastObjectResizeStartEvent, 'objectresizestart'),
cAssertEventData(lastObjectResizedEvent, 'objectresized'),
cClearResizeEventData,
//.........这里部分代码省略.........
示例3: Plugin
//.........这里部分代码省略.........
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'),
NamedChain.output('widths')
]);
const cAssertWidthsShouldBe = (unit: string) => Chain.op((input: any) => {
const expectingPercent = (unit === '%');
Assertions.assertEq(`table width before resizing is in ${unit}`, expectingPercent, input.widthBefore.isPercent);
Assertions.assertEq(`table width after resizing is in ${unit}`, expectingPercent, input.widthAfter.isPercent);
});
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);
});
NamedChain.pipeline([
NamedChain.write('editor', Editor.cFromSettings({
plugins: 'table',
width: 400,
skin_url: '/project/js/tinymce/skins/lightgray'
})),
// when table is resized by one of the handlers it should retain the dimension units after the resize, be it px or %
cClearResizeEventData,
NamedChain.direct('editor', cTableInsertResizeMeasure, 'widths'),
NamedChain.read('widths', cAssertWidths),
cAssertEventData(lastObjectResizeStartEvent, 'objectresizestart'),
cAssertEventData(lastObjectResizedEvent, 'objectresized'),
// using configuration option [table_responsive_width=true] we are able to control the default units of the table
cClearResizeEventData,
NamedChain.read('editor', ApiChains.cSetContent('')),
NamedChain.direct('editor', cTableInsertResizeMeasure, 'widths'),
NamedChain.read('widths', cAssertWidthsShouldBe('%')),
cAssertEventData(lastObjectResizeStartEvent, 'objectresizestart'),
cAssertEventData(lastObjectResizedEvent, 'objectresized'),
cClearResizeEventData,
NamedChain.read('editor', ApiChains.cSetContent('')),
NamedChain.read('editor', ApiChains.cSetSetting('table_responsive_width', false)),
NamedChain.direct('editor', cTableInsertResizeMeasure, 'widths'),
NamedChain.read('widths', cAssertWidthsShouldBe('px')),
cAssertEventData(lastObjectResizeStartEvent, 'objectresizestart'),
cAssertEventData(lastObjectResizedEvent, 'objectresized'),
NamedChain.read('editor', Editor.cRemove)
], function () {
success();
}, failure, TestLogs.init());
});