-
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.
Fix 277159: Content is too Narrow when pasting divs and div is treate…
…d a general block #2661
- Loading branch information
1 parent
ffdb5bd
commit a7299c2
Showing
6 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
packages/roosterjs-content-model-plugins/lib/paste/DefaultSanitizers.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,23 @@ | ||
import type { ValueSanitizer } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const DefaultSanitizers: Record<string, ValueSanitizer> = { | ||
width: divParagraphSanitizer, | ||
height: divParagraphSanitizer, | ||
'inline-size': divParagraphSanitizer, | ||
'block-size': divParagraphSanitizer, | ||
}; | ||
|
||
/** | ||
* @internal | ||
* exported only for unit test | ||
*/ | ||
export function divParagraphSanitizer(value: string, tagName: string): string | null { | ||
const tag = tagName.toLowerCase(); | ||
if (tag == 'div' || tag == 'p') { | ||
return null; | ||
} | ||
return 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
37 changes: 37 additions & 0 deletions
37
packages/roosterjs-content-model-plugins/lib/paste/utils/chainSanitizerCallback.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,37 @@ | ||
import type { ValueSanitizer } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
* Chain all callback for an style sanitizer | ||
* @param map The source callback map | ||
* @param name Name of the property to chain | ||
* @param newCallback A new callback to process the given name on the given map. | ||
*/ | ||
export function chainSanitizerCallback( | ||
map: Record<string, ValueSanitizer>, | ||
name: string, | ||
newCallback: ValueSanitizer | ||
) { | ||
const finalCb = | ||
typeof newCallback == 'function' | ||
? newCallback | ||
: (value: string) => (newCallback ? value : null); | ||
if (!map[name]) { | ||
map[name] = finalCb; | ||
} else { | ||
const originalCallback = map[name]; | ||
map[name] = (value: string, tagName: string) => { | ||
const og = | ||
typeof originalCallback == 'function' | ||
? originalCallback(value, tagName) | ||
: originalCallback | ||
? value | ||
: false; | ||
if (!og) { | ||
return null; | ||
} else { | ||
return finalCb(og, tagName); | ||
} | ||
}; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
packages/roosterjs-content-model-plugins/test/paste/sanitizers/divParagraphSanitizerTest.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,18 @@ | ||
import { divParagraphSanitizer } from '../../../lib/paste/DefaultSanitizers'; | ||
|
||
divParagraphSanitizer; | ||
|
||
describe('divParagraphSanitizer', () => { | ||
it('handle div', () => { | ||
const result = divParagraphSanitizer('100px', 'div'); | ||
expect(result).toBeNull(); | ||
}); | ||
it('handle p', () => { | ||
const result = divParagraphSanitizer('100px', 'p'); | ||
expect(result).toBeNull(); | ||
}); | ||
it('handle image', () => { | ||
const result = divParagraphSanitizer('100px', 'image'); | ||
expect(result).toEqual('100px'); | ||
}); | ||
}); |