Update view on model change at downcast dispatcherPassing parameters from Command to ConverterCKEditor5 view-model position and range conversionRefreshing a CKEditor5 widget upon model changesCKEditor 5 how to get the click, update and deleted events from any widget/Model/Viewwriter.setAttribute don't trigger a view downcastStop operation in change()Elegant way to change view schema in CKEditor5In ckeditor5, how can I change entermode br instead of p?How to display text written in SPAN element in CKEditor 5?Any side effects of changing a parameter in modifyselection of CKEditor 5?
Recursive search on Node Tree with Linq and Queue
How to deal with making design decisions
Why can't a country print its own money to spend it only abroad?
Has Iron Man made any suit for underwater combat?
Counterexample finite intersection property
Is there a guide to help me transition from PSTricks to TikZ?
Has Peter Parker ever eaten bugs?
Do I care if the housing market has gone up or down, if I'm moving from one house to another?
How can I deal with someone that wants to kill something that isn't supposed to be killed?
Would using carbon dioxide as fuel work to reduce the greenhouse effect?
Should I practice til I "get it" or until I'm sick of it?
Magic is the twist
Is it better to merge "often" or only after completion do a big merge of feature branches?
Calculating Fibonacci sequence in several different ways
Impact of throwing away fruit waste on a peak > 3200 m above a glacier
Why are the phonemes of Tutankhamun's throne name transliterated out of order?
What does the following chess proverb mean: "Chess is a sea where a gnat may drink from and an elephant may bathe in."
What is a "staved" town, like in "Staverton"?
My current job follows "worst practices". How can I talk about my experience in an interview without giving off red flags?
How to handle not being able to attend as often as I'd like
Function pointer parameter without asterisk
I have a domain, static IP and many devices I'd like to access outside my house. How to route them?
Reissue US, UK, Canada visas in stolen passports
Can someone clarify when a Trigger executes on a single record vs. multiple in one context?
Update view on model change at downcast dispatcher
Passing parameters from Command to ConverterCKEditor5 view-model position and range conversionRefreshing a CKEditor5 widget upon model changesCKEditor 5 how to get the click, update and deleted events from any widget/Model/Viewwriter.setAttribute don't trigger a view downcastStop operation in change()Elegant way to change view schema in CKEditor5In ckeditor5, how can I change entermode br instead of p?How to display text written in SPAN element in CKEditor 5?Any side effects of changing a parameter in modifyselection of CKEditor 5?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to add 'id' attr to heading elements witch don't have it.
I try to do so
conversion.for('upcast').elementToElement(
model: (viewElement, modelWriter) =>
const attrs = ;
const id = viewElement.getAttribute('id');
if (id)
attrs['id'] = id;
return modelWriter.createElement('heading1', attrs);
,
view:
name: 'h1'
,
converterPriority: 'low' + 1
);
conversion.for('downcast').add(dispatcher =>
dispatcher.on('insert:heading1', (evt, data, conversionApi) =>
if (!data.item.getAttribute('id'))
conversionApi.writer.setAttribute('id', generateUID(), data.item)
);
);
conversion.for('downcast').attributeToAttribute(
model:
name: 'heading1',
key: 'id'
,
view:
name: 'h1',
key: 'id'
);
editor.conversion.elementToElement(option);
modelElements.push(option.model);
and it's changed the model with
<$root>
<heading1 id="ykuqo5" >some text</heading1>
</$root>
but view still don't have 'id' attr.
I expect html tag in editor would be have id attr same to model. Thanks for help, sorry for my english
ckeditor5
add a comment |
I need to add 'id' attr to heading elements witch don't have it.
I try to do so
conversion.for('upcast').elementToElement(
model: (viewElement, modelWriter) =>
const attrs = ;
const id = viewElement.getAttribute('id');
if (id)
attrs['id'] = id;
return modelWriter.createElement('heading1', attrs);
,
view:
name: 'h1'
,
converterPriority: 'low' + 1
);
conversion.for('downcast').add(dispatcher =>
dispatcher.on('insert:heading1', (evt, data, conversionApi) =>
if (!data.item.getAttribute('id'))
conversionApi.writer.setAttribute('id', generateUID(), data.item)
);
);
conversion.for('downcast').attributeToAttribute(
model:
name: 'heading1',
key: 'id'
,
view:
name: 'h1',
key: 'id'
);
editor.conversion.elementToElement(option);
modelElements.push(option.model);
and it's changed the model with
<$root>
<heading1 id="ykuqo5" >some text</heading1>
</$root>
but view still don't have 'id' attr.
I expect html tag in editor would be have id attr same to model. Thanks for help, sorry for my english
ckeditor5
add a comment |
I need to add 'id' attr to heading elements witch don't have it.
I try to do so
conversion.for('upcast').elementToElement(
model: (viewElement, modelWriter) =>
const attrs = ;
const id = viewElement.getAttribute('id');
if (id)
attrs['id'] = id;
return modelWriter.createElement('heading1', attrs);
,
view:
name: 'h1'
,
converterPriority: 'low' + 1
);
conversion.for('downcast').add(dispatcher =>
dispatcher.on('insert:heading1', (evt, data, conversionApi) =>
if (!data.item.getAttribute('id'))
conversionApi.writer.setAttribute('id', generateUID(), data.item)
);
);
conversion.for('downcast').attributeToAttribute(
model:
name: 'heading1',
key: 'id'
,
view:
name: 'h1',
key: 'id'
);
editor.conversion.elementToElement(option);
modelElements.push(option.model);
and it's changed the model with
<$root>
<heading1 id="ykuqo5" >some text</heading1>
</$root>
but view still don't have 'id' attr.
I expect html tag in editor would be have id attr same to model. Thanks for help, sorry for my english
ckeditor5
I need to add 'id' attr to heading elements witch don't have it.
I try to do so
conversion.for('upcast').elementToElement(
model: (viewElement, modelWriter) =>
const attrs = ;
const id = viewElement.getAttribute('id');
if (id)
attrs['id'] = id;
return modelWriter.createElement('heading1', attrs);
,
view:
name: 'h1'
,
converterPriority: 'low' + 1
);
conversion.for('downcast').add(dispatcher =>
dispatcher.on('insert:heading1', (evt, data, conversionApi) =>
if (!data.item.getAttribute('id'))
conversionApi.writer.setAttribute('id', generateUID(), data.item)
);
);
conversion.for('downcast').attributeToAttribute(
model:
name: 'heading1',
key: 'id'
,
view:
name: 'h1',
key: 'id'
);
editor.conversion.elementToElement(option);
modelElements.push(option.model);
and it's changed the model with
<$root>
<heading1 id="ykuqo5" >some text</heading1>
</$root>
but view still don't have 'id' attr.
I expect html tag in editor would be have id attr same to model. Thanks for help, sorry for my english
ckeditor5
ckeditor5
asked Mar 26 at 13:35
Miha CMiha C
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
c. There are few minor issues:
- The conversion process might be simplified to the two-way converter
conversion.attributeToAttribute()
. - You should allow
id
attribute on all headings either by extending their definitions or by adding an attribute check to the schema. - Enforcing model state should be done by adding a model's document post-fixer.
class HeadingIdAttribute extends Plugin
init()
const editor = this.editor;
const model = editor.model;
const conversion = editor.conversion;
// Allow 'id' attribute on heading* elements:
// Either by extending each heading definition:
// editor.model.schema.extend( 'heading1', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading2', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading3', allowAttributes: [ 'id' ] );
// or by adding a more general attribute check:
model.schema.addAttributeCheck( ( schemaContext, attribute ) =>
if ( attribute == 'id' && isHeading( schemaContext.last.name ) )
return true;
);
// Then the conversion might be a two way attribute-to-attribute:
conversion.attributeToAttribute(
model: 'id',
view: 'id'
);
// Register a model post-fixer to add missing id attribute
// to the heading* element.
model.document.registerPostFixer( writer =>
let wasChanged = false;
// Get changes
const changes = model.document.differ.getChanges();
for ( const change of changes )
// Check heading nodes on insert.
if ( change.type == 'insert' && isHeading( change.name ) )
const heading = change.position.nodeAfter;
// Set 'id' attribute when it is missing in the model.
if ( !heading.hasAttribute( 'id' ) )
writer.setAttribute( 'id', uid(), heading );
// Return true to notify that model was altered.
wasChanged = true;
return wasChanged;
);
// Helper method for checking if name is any heading element.
// Detects default headings: 'heading1', 'heading2', ... 'heading6'.
function isHeading( name )
return name.slice( 0, -1 ) == 'heading';
And add this plugin to your editor (remember to add also other plugins):
ClassicEditor
.create( document.querySelector( '#editor' ),
plugins: [ Enter, Typing, Undo, Heading, Paragraph, HeadingIdAttribute ],
toolbar: [ 'heading', ' )
.then( editor =>
window.editor = editor;
)
.catch( err =>
console.error( err.stack );
);
It will create an id attribute to the view as well:
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55358513%2fupdate-view-on-model-change-at-downcast-dispatcher%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
c. There are few minor issues:
- The conversion process might be simplified to the two-way converter
conversion.attributeToAttribute()
. - You should allow
id
attribute on all headings either by extending their definitions or by adding an attribute check to the schema. - Enforcing model state should be done by adding a model's document post-fixer.
class HeadingIdAttribute extends Plugin
init()
const editor = this.editor;
const model = editor.model;
const conversion = editor.conversion;
// Allow 'id' attribute on heading* elements:
// Either by extending each heading definition:
// editor.model.schema.extend( 'heading1', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading2', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading3', allowAttributes: [ 'id' ] );
// or by adding a more general attribute check:
model.schema.addAttributeCheck( ( schemaContext, attribute ) =>
if ( attribute == 'id' && isHeading( schemaContext.last.name ) )
return true;
);
// Then the conversion might be a two way attribute-to-attribute:
conversion.attributeToAttribute(
model: 'id',
view: 'id'
);
// Register a model post-fixer to add missing id attribute
// to the heading* element.
model.document.registerPostFixer( writer =>
let wasChanged = false;
// Get changes
const changes = model.document.differ.getChanges();
for ( const change of changes )
// Check heading nodes on insert.
if ( change.type == 'insert' && isHeading( change.name ) )
const heading = change.position.nodeAfter;
// Set 'id' attribute when it is missing in the model.
if ( !heading.hasAttribute( 'id' ) )
writer.setAttribute( 'id', uid(), heading );
// Return true to notify that model was altered.
wasChanged = true;
return wasChanged;
);
// Helper method for checking if name is any heading element.
// Detects default headings: 'heading1', 'heading2', ... 'heading6'.
function isHeading( name )
return name.slice( 0, -1 ) == 'heading';
And add this plugin to your editor (remember to add also other plugins):
ClassicEditor
.create( document.querySelector( '#editor' ),
plugins: [ Enter, Typing, Undo, Heading, Paragraph, HeadingIdAttribute ],
toolbar: [ 'heading', ' )
.then( editor =>
window.editor = editor;
)
.catch( err =>
console.error( err.stack );
);
It will create an id attribute to the view as well:
add a comment |
c. There are few minor issues:
- The conversion process might be simplified to the two-way converter
conversion.attributeToAttribute()
. - You should allow
id
attribute on all headings either by extending their definitions or by adding an attribute check to the schema. - Enforcing model state should be done by adding a model's document post-fixer.
class HeadingIdAttribute extends Plugin
init()
const editor = this.editor;
const model = editor.model;
const conversion = editor.conversion;
// Allow 'id' attribute on heading* elements:
// Either by extending each heading definition:
// editor.model.schema.extend( 'heading1', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading2', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading3', allowAttributes: [ 'id' ] );
// or by adding a more general attribute check:
model.schema.addAttributeCheck( ( schemaContext, attribute ) =>
if ( attribute == 'id' && isHeading( schemaContext.last.name ) )
return true;
);
// Then the conversion might be a two way attribute-to-attribute:
conversion.attributeToAttribute(
model: 'id',
view: 'id'
);
// Register a model post-fixer to add missing id attribute
// to the heading* element.
model.document.registerPostFixer( writer =>
let wasChanged = false;
// Get changes
const changes = model.document.differ.getChanges();
for ( const change of changes )
// Check heading nodes on insert.
if ( change.type == 'insert' && isHeading( change.name ) )
const heading = change.position.nodeAfter;
// Set 'id' attribute when it is missing in the model.
if ( !heading.hasAttribute( 'id' ) )
writer.setAttribute( 'id', uid(), heading );
// Return true to notify that model was altered.
wasChanged = true;
return wasChanged;
);
// Helper method for checking if name is any heading element.
// Detects default headings: 'heading1', 'heading2', ... 'heading6'.
function isHeading( name )
return name.slice( 0, -1 ) == 'heading';
And add this plugin to your editor (remember to add also other plugins):
ClassicEditor
.create( document.querySelector( '#editor' ),
plugins: [ Enter, Typing, Undo, Heading, Paragraph, HeadingIdAttribute ],
toolbar: [ 'heading', ' )
.then( editor =>
window.editor = editor;
)
.catch( err =>
console.error( err.stack );
);
It will create an id attribute to the view as well:
add a comment |
c. There are few minor issues:
- The conversion process might be simplified to the two-way converter
conversion.attributeToAttribute()
. - You should allow
id
attribute on all headings either by extending their definitions or by adding an attribute check to the schema. - Enforcing model state should be done by adding a model's document post-fixer.
class HeadingIdAttribute extends Plugin
init()
const editor = this.editor;
const model = editor.model;
const conversion = editor.conversion;
// Allow 'id' attribute on heading* elements:
// Either by extending each heading definition:
// editor.model.schema.extend( 'heading1', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading2', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading3', allowAttributes: [ 'id' ] );
// or by adding a more general attribute check:
model.schema.addAttributeCheck( ( schemaContext, attribute ) =>
if ( attribute == 'id' && isHeading( schemaContext.last.name ) )
return true;
);
// Then the conversion might be a two way attribute-to-attribute:
conversion.attributeToAttribute(
model: 'id',
view: 'id'
);
// Register a model post-fixer to add missing id attribute
// to the heading* element.
model.document.registerPostFixer( writer =>
let wasChanged = false;
// Get changes
const changes = model.document.differ.getChanges();
for ( const change of changes )
// Check heading nodes on insert.
if ( change.type == 'insert' && isHeading( change.name ) )
const heading = change.position.nodeAfter;
// Set 'id' attribute when it is missing in the model.
if ( !heading.hasAttribute( 'id' ) )
writer.setAttribute( 'id', uid(), heading );
// Return true to notify that model was altered.
wasChanged = true;
return wasChanged;
);
// Helper method for checking if name is any heading element.
// Detects default headings: 'heading1', 'heading2', ... 'heading6'.
function isHeading( name )
return name.slice( 0, -1 ) == 'heading';
And add this plugin to your editor (remember to add also other plugins):
ClassicEditor
.create( document.querySelector( '#editor' ),
plugins: [ Enter, Typing, Undo, Heading, Paragraph, HeadingIdAttribute ],
toolbar: [ 'heading', ' )
.then( editor =>
window.editor = editor;
)
.catch( err =>
console.error( err.stack );
);
It will create an id attribute to the view as well:
c. There are few minor issues:
- The conversion process might be simplified to the two-way converter
conversion.attributeToAttribute()
. - You should allow
id
attribute on all headings either by extending their definitions or by adding an attribute check to the schema. - Enforcing model state should be done by adding a model's document post-fixer.
class HeadingIdAttribute extends Plugin
init()
const editor = this.editor;
const model = editor.model;
const conversion = editor.conversion;
// Allow 'id' attribute on heading* elements:
// Either by extending each heading definition:
// editor.model.schema.extend( 'heading1', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading2', allowAttributes: [ 'id' ] );
// editor.model.schema.extend( 'heading3', allowAttributes: [ 'id' ] );
// or by adding a more general attribute check:
model.schema.addAttributeCheck( ( schemaContext, attribute ) =>
if ( attribute == 'id' && isHeading( schemaContext.last.name ) )
return true;
);
// Then the conversion might be a two way attribute-to-attribute:
conversion.attributeToAttribute(
model: 'id',
view: 'id'
);
// Register a model post-fixer to add missing id attribute
// to the heading* element.
model.document.registerPostFixer( writer =>
let wasChanged = false;
// Get changes
const changes = model.document.differ.getChanges();
for ( const change of changes )
// Check heading nodes on insert.
if ( change.type == 'insert' && isHeading( change.name ) )
const heading = change.position.nodeAfter;
// Set 'id' attribute when it is missing in the model.
if ( !heading.hasAttribute( 'id' ) )
writer.setAttribute( 'id', uid(), heading );
// Return true to notify that model was altered.
wasChanged = true;
return wasChanged;
);
// Helper method for checking if name is any heading element.
// Detects default headings: 'heading1', 'heading2', ... 'heading6'.
function isHeading( name )
return name.slice( 0, -1 ) == 'heading';
And add this plugin to your editor (remember to add also other plugins):
ClassicEditor
.create( document.querySelector( '#editor' ),
plugins: [ Enter, Typing, Undo, Heading, Paragraph, HeadingIdAttribute ],
toolbar: [ 'heading', ' )
.then( editor =>
window.editor = editor;
)
.catch( err =>
console.error( err.stack );
);
It will create an id attribute to the view as well:
answered Mar 28 at 10:54
jodatorjodator
2,23012 silver badges23 bronze badges
2,23012 silver badges23 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55358513%2fupdate-view-on-model-change-at-downcast-dispatcher%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown