-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content Model: Fix 221290 Support float for image (#2013)
- Loading branch information
1 parent
aa49e67
commit e8d2536
Showing
9 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
demo/scripts/controls/contentModel/components/format/formatPart/FloatFormatRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createTextFormatRenderer } from '../utils/createTextFormatRenderer'; | ||
import { FloatFormat } from 'roosterjs-content-model-types'; | ||
import { FormatRenderer } from '../utils/FormatRenderer'; | ||
|
||
export const FloatFormatRenderer: FormatRenderer<FloatFormat> = createTextFormatRenderer< | ||
FloatFormat | ||
>( | ||
'Float', | ||
format => format.float, | ||
(format, value) => (format.float = value) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...content-model/roosterjs-content-model-dom/lib/formatHandlers/common/floatFormatHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { FloatFormat } from 'roosterjs-content-model-types'; | ||
import { FormatHandler } from '../FormatHandler'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const floatFormatHandler: FormatHandler<FloatFormat> = { | ||
parse: (format, element) => { | ||
const float = element.style.float || element.getAttribute('align'); | ||
|
||
if (float) { | ||
format.float = float; | ||
} | ||
}, | ||
apply: (format, element) => { | ||
if (format.float) { | ||
element.style.float = format.float; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...nt-model/roosterjs-content-model-dom/test/formatHandlers/common/floatFormatHandlerTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; | ||
import { createModelToDomContext } from '../../../lib/modelToDom/context/createModelToDomContext'; | ||
import { DomToModelContext, FloatFormat, ModelToDomContext } from 'roosterjs-content-model-types'; | ||
import { floatFormatHandler } from '../../../lib/formatHandlers/common/floatFormatHandler'; | ||
|
||
describe('floatFormatHandler.parse', () => { | ||
let div: HTMLElement; | ||
let format: FloatFormat; | ||
let context: DomToModelContext; | ||
|
||
beforeEach(() => { | ||
div = document.createElement('div'); | ||
format = {}; | ||
context = createDomToModelContext(); | ||
}); | ||
|
||
it('No float', () => { | ||
floatFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({}); | ||
}); | ||
|
||
it('Float left', () => { | ||
div.style.float = 'left'; | ||
floatFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({ | ||
float: 'left', | ||
}); | ||
}); | ||
|
||
it('Float left from attribute', () => { | ||
div.setAttribute('align', 'left'); | ||
floatFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({ | ||
float: 'left', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('floatFormatHandler.apply', () => { | ||
let div: HTMLElement; | ||
let format: FloatFormat; | ||
let context: ModelToDomContext; | ||
|
||
beforeEach(() => { | ||
div = document.createElement('div'); | ||
format = {}; | ||
context = createModelToDomContext(); | ||
}); | ||
|
||
it('No float', () => { | ||
floatFormatHandler.apply(format, div, context); | ||
expect(div.outerHTML).toBe('<div></div>'); | ||
}); | ||
|
||
it('Float: left', () => { | ||
format.float = 'left'; | ||
floatFormatHandler.apply(format, div, context); | ||
expect(div.outerHTML).toBe('<div style="float: left;"></div>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages-content-model/roosterjs-content-model-types/lib/format/formatParts/FloatFormat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Format of float | ||
*/ | ||
export type FloatFormat = { | ||
/** | ||
* Float style | ||
*/ | ||
float?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters