-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content Model: Set alignment API #1650
Conversation
@@ -35,7 +35,7 @@ describe('listItemProcessor', () => { | |||
}); | |||
}); | |||
|
|||
it('LI with display:block', () => { | |||
xit('LI with display:block', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need to skip this test?
/** | ||
* The format object for a list item in Content Model | ||
*/ | ||
export type ContentModelListItemFormat = DirectionFormat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to export this type in index.ts
@@ -51,7 +52,7 @@ export interface ContentModelFormatMap { | |||
/** | |||
* Format type for listItem | |||
*/ | |||
listItem: ContentModelListItemLevelFormat; | |||
listItem: ContentModelListItemFormat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I think we need to add a new item here, but not change the existing one.
listItem handles item level format, which is also stored in ContentModelListItemLevelFormat. So the new format is different, need another handler set.
applyFormat(li, context.formatAppliers.segment, listItem.formatHolder.format, context); | ||
applyFormat(li, context.formatAppliers.listItem, level, context); | ||
applyFormat(li, context.formatAppliers.listLevel, level, context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listLevel should be only applied to OL/UL, but not LI.
@@ -8,14 +8,19 @@ import { createSelectionMarker } from './createSelectionMarker'; | |||
*/ | |||
export function createListItem( | |||
levels: ContentModelListItemLevelFormat[], | |||
format?: ContentModelSegmentFormat | |||
format?: ContentModelSegmentFormat, | |||
li?: HTMLLIElement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try avoid passing in DOM element into creator. You can pass in its style value directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this should be done by format handler, but don't handle format directly in creator
@@ -94,7 +94,7 @@ const defaultFormatKeysPerCategory: { | |||
[key in keyof ContentModelFormatMap]: (keyof FormatHandlerTypeMap)[]; | |||
} = { | |||
block: blockFormatHandlers, | |||
listItem: ['listItemThread', 'listItemMetadata'], | |||
listItem: ['listItemThread', 'listItemMetadata', 'direction'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, let's add a new item for direction
@@ -23,12 +23,14 @@ export const listItemProcessor: ElementProcessor<HTMLLIElement> = (group, elemen | |||
context | |||
); | |||
|
|||
const listItem = createListItem(listFormat.levels, context.segmentFormat); | |||
const listItem = createListItem(listFormat.levels, context.segmentFormat, element); | |||
parseFormat(element, context.formatParsers.listItem, listItem.format, context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, use a different format handler set.
listFormat.listParent!.blocks.push(listItem); | ||
|
||
parseFormat( | ||
element, | ||
context.formatParsers.listItem, | ||
context.formatParsers.listLevel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't change this. listItem and listLevel are doing different job.
} else if (block) { | ||
const { format } = block; | ||
format.textAlign = newAligment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this part is the same with line 63. We can merge them
@@ -54,7 +54,7 @@ describe('listItemProcessor', () => { | |||
blockType: 'BlockGroup', | |||
blockGroupType: 'ListItem', | |||
blocks: [], | |||
levels: [{ listType: 'UL', displayForDummyItem: 'block' }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shows the code has regression. displayForDummyItem needs to be 'block' here
…u/juliaroldi/set-alignment-content-model
b9ce59f
to
a6cc71c
Compare
@@ -8,14 +8,19 @@ import { createSelectionMarker } from './createSelectionMarker'; | |||
*/ | |||
export function createListItem( | |||
levels: ContentModelListItemLevelFormat[], | |||
format?: ContentModelSegmentFormat | |||
format?: ContentModelSegmentFormat, | |||
textAlign?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented in another place, this should be done by format handler, but not through a parameter of creator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the reason is, here you allow to pass a string, then later you convert the type to "start|end|center". What if people pass in some other string? We can't detect it and there is no build time error. So that will most likely cause bug. To solve it, people need to convert their string to the type we need. But that is already done in format handler, so it is a dup.
const listItem = createListItem( | ||
listFormat.levels, | ||
context.segmentFormat, | ||
element.style.alignSelf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, leave it to format handler.
export const listItemElementFormatHandler: FormatHandler<ContentModelListItemFormat> = { | ||
parse: (format, element) => { | ||
const alignment = element.style.alignSelf; | ||
if (alignment && ['end', 'start', 'center'].indexOf(alignment) > -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all the logic here is already included in directionFormatHandler, right? Then we don't need this handler at all.
ac523ef
to
56bb98d
Compare
@@ -48,7 +49,7 @@ export interface ContentModelFormatMap { | |||
*/ | |||
tableCell: ContentModelTableCellFormat; | |||
|
|||
/** | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It happened when I was solving conflicts. I'll fix.
Add setModelAlignment api that supports align lists and tables.
![alignment](https://user-images.githubusercontent.com/87443959/219137816-9ef33268-4574-492b-86a1-27eddb368a99.gif)