Skip to content

Commit

Permalink
ContentModel: Set readonly for new entity (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Dec 6, 2023
1 parent a7bdb43 commit 6e5f30c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ class EntityPlugin implements PluginWithState<EntityPluginState> {
entity.entityFormat.id = this.ensureUniqueId(entityType, id ?? '', wrapper);
wrapper.className = generateEntityClassNames(entity.entityFormat);

if (entity.entityFormat.isReadonly) {
wrapper.contentEditable = 'false';
}

const eventResult = this.triggerEvent(editor, wrapper, operation, rawEvent);

this.state.entityMap[entity.entityFormat.id] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('EntityPlugin', () => {
},
});
expect(wrapper.outerHTML).toBe(
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1"></div>'
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('EntityPlugin', () => {
},
});
expect(wrapper.outerHTML).toBe(
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1"></div>'
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('EntityPlugin', () => {
},
});
expect(wrapper.outerHTML).toBe(
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1"></div>'
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('EntityPlugin', () => {
},
});
expect(wrapper.outerHTML).toBe(
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1"></div>'
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('EntityPlugin', () => {
},
});
expect(wrapper.outerHTML).toBe(
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1"></div>'
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(2);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('EntityPlugin', () => {
},
});
expect(wrapper.outerHTML).toBe(
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1"></div>'
'<div class="_Entity _EType_Entity1 _EId_Entity1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('EntityPlugin', () => {
'<div class="_Entity _EType_E1 _EId_E1 _EReadonly_1"></div>'
);
expect(wrapper2.outerHTML).toBe(
'<div class="_Entity _EType_E2 _EId_E2 _EReadonly_1"></div>'
'<div class="_Entity _EType_E2 _EId_E2 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(2);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('EntityPlugin', () => {
'<div class="_Entity _EType_E1 _EId_E1 _EReadonly_1"></div>'
);
expect(wrapper2.outerHTML).toBe(
'<div class="_Entity _EType_E2 _EId_E1_1 _EReadonly_1"></div>'
'<div class="_Entity _EType_E2 _EId_E1_1 _EReadonly_1" contenteditable="false"></div>'
);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
expect(triggerPluginEventSpy).toHaveBeenCalledWith(PluginEventType.EntityOperation, {
Expand Down

0 comments on commit 6e5f30c

Please sign in to comment.