diff --git a/assets/rich_text_components_definitions.ts b/assets/rich_text_components_definitions.ts index f7585e7c7dae9..b8ead7a0102ab 100644 --- a/assets/rich_text_components_definitions.ts +++ b/assets/rich_text_components_definitions.ts @@ -35,7 +35,6 @@ export default { "schema": { "type": "unicode" }, - "default_value_obtainable_from_highlight": false, "default_value": "Sample Header" }, { "name": "content", @@ -46,7 +45,6 @@ export default { "hide_complex_extensions": true } }, - "default_value_obtainable_from_highlight": false, "default_value": "You have opened the collapsible block." }] }, @@ -68,7 +66,6 @@ export default { "type": "custom", "obj_type": "Filepath" }, - "default_value_obtainable_from_highlight": false, "default_value": "" }, { "name": "caption", @@ -80,7 +77,6 @@ export default { "max_value": 500 }] }, - "default_value_obtainable_from_highlight": false, "default_value": "" }, { "name": "alt", @@ -96,7 +92,6 @@ export default { "rows": 3 } }, - "default_value_obtainable_from_highlight": false, "default_value": "" }] }, @@ -118,7 +113,6 @@ export default { "type": "custom", "obj_type": "SanitizedUrl" }, - "default_value_obtainable_from_highlight": false, "default_value": "" }, { "name": "text", @@ -126,7 +120,6 @@ export default { "schema": { "type": "unicode" }, - "default_value_obtainable_from_highlight": false, "default_value": "" }] }, @@ -148,7 +141,6 @@ export default { "type": "custom", "obj_type": "MathExpressionContent" }, - "default_value_obtainable_from_highlight": false, "default_value": { "raw_latex": "", "svg_filename": "" @@ -175,7 +167,6 @@ export default { "id": "is_nonempty" }] }, - "default_value_obtainable_from_highlight": true, "default_value": "concept card" }, { "name": "skill_id", @@ -184,7 +175,6 @@ export default { "type": "custom", "obj_type": "SkillSelector" }, - "default_value_obtainable_from_highlight": false, "default_value": "" }] }, @@ -206,7 +196,6 @@ export default { "type": "custom", "obj_type": "ListOfTabs" }, - "default_value_obtainable_from_highlight": false, "default_value": [{ "title": "Hint introduction", "content": "This set of tabs shows some hints. Click on the other tabs to display the relevant hints." @@ -233,7 +222,6 @@ export default { "schema": { "type": "unicode" }, - "default_value_obtainable_from_highlight": false, "default_value": "" }, { "name": "start", @@ -245,7 +233,6 @@ export default { "min_value": 0 }] }, - "default_value_obtainable_from_highlight": false, "default_value": 0 }, { "name": "end", @@ -257,7 +244,6 @@ export default { "min_value": 0 }] }, - "default_value_obtainable_from_highlight": false, "default_value": 0 }, { "name": "autoplay", @@ -265,7 +251,6 @@ export default { "schema": { "type": "bool" }, - "default_value_obtainable_from_highlight": false, "default_value": false }] } diff --git a/core/domain/rte_component_registry.py b/core/domain/rte_component_registry.py index 7c6e10284bb0e..2f728da3b7562 100644 --- a/core/domain/rte_component_registry.py +++ b/core/domain/rte_component_registry.py @@ -43,7 +43,6 @@ class CustomizationArgSpecDict(TypedDict): # Here we use type Any because values in schema dictionary can be of # type str, List, Dict and other types too. schema: Dict[str, Any] - default_value_obtainable_from_highlight: bool default_value: Union[str, int, List[str], Dict[str, str]] diff --git a/core/domain/rte_component_registry_test.py b/core/domain/rte_component_registry_test.py index 1e7955505b576..6ffd0bb600f2a 100644 --- a/core/domain/rte_component_registry_test.py +++ b/core/domain/rte_component_registry_test.py @@ -76,8 +76,7 @@ def _validate_customization_arg_specs( """Validates the given customization arg specs.""" for ca_spec in customization_arg_specs: self.assertEqual(set(ca_spec.keys()), set([ - 'name', 'description', 'schema', 'default_value', - 'default_value_obtainable_from_highlight'])) + 'name', 'description', 'schema', 'default_value'])) self.assertTrue( isinstance(ca_spec['name'], str)) diff --git a/core/templates/components/ck-editor-helpers/ck-editor-4-widgets.initializer.ts b/core/templates/components/ck-editor-helpers/ck-editor-4-widgets.initializer.ts index 9663af6c99086..eebeb1f0113d0 100644 --- a/core/templates/components/ck-editor-helpers/ck-editor-4-widgets.initializer.ts +++ b/core/templates/components/ck-editor-helpers/ck-editor-4-widgets.initializer.ts @@ -25,7 +25,6 @@ export interface RteComponentSpecs { backendId: string; customizationArgSpecs: { name: string; value: string; 'default_value': string; - 'default_value_obtainable_from_highlight': boolean; }[]; id: string; iconDataUrl: string; @@ -40,8 +39,8 @@ export interface RteHelperService { getRichTextComponents: () => RteComponentSpecs[]; isInlineComponent: (string) => boolean; openCustomizationModal: ( - componentIsNewlyCreated, customizationArgSpecs, attrsCustomizationArgsDict, - onSubmitCallback, onDismissCallback + customizationArgSpecs, attrsCustomizationArgsDict, onSubmitCallback, + onDismissCallback ) => void; } @@ -108,13 +107,11 @@ export class CkEditorInitializerService { var that = this; var customizationArgs = {}; customizationArgSpecs.forEach(function(spec) { - customizationArgs[spec.name] = that.data[spec.name]; + customizationArgs[spec.name] = that.data[spec.name] || + spec.default_value; }); - const componentIsNewlyCreated: boolean = !that.isReady(); - rteHelperService.openCustomizationModal( - componentIsNewlyCreated, customizationArgSpecs, customizationArgs, function(customizationArgsDict) { @@ -130,7 +127,7 @@ export class CkEditorInitializerService { * has already been inserted into the RTE, we do not * need to finalizeCreation again). */ - if (componentIsNewlyCreated) { + if (!that.isReady()) { // Actually create the widget, if we have not already. editor.widgets.finalizeCreation(container); } @@ -154,38 +151,16 @@ export class CkEditorInitializerService { }, function(widgetShouldBeRemoved) { if (widgetShouldBeRemoved || that.data.isCopied) { - const defaultValueObtainableFromHighlight = ( - customizationArgSpecs - .some(function(spec) { - return spec.default_value_obtainable_from_highlight; - })); - that.data.isCopied = false; var newWidgetSelector = ( '[data-cke-widget-id="' + that.id + '"]'); - if (newWidgetSelector === null) { - return; - } - var widgetElement = editor.editable().findOne( - newWidgetSelector); - - if (!widgetElement) { - return; - } - - /** - * If the component's default value was not obtained from - * a highlighted text or was not newly created, then - * simply remove the component. Otherwise, load the - * initial snapshot to revert back to the original text. - */ - if (!defaultValueObtainableFromHighlight || - !componentIsNewlyCreated) { - widgetElement.remove(); - editor.fire('change'); - } else { - editor.loadSnapshot(that.initialSnapshot); - editor.fire('change'); + if (newWidgetSelector !== null) { + var widgetElement = editor.editable().findOne( + newWidgetSelector); + if (widgetElement) { + widgetElement.remove(); + editor.fire('change'); + } } } }); @@ -227,23 +202,6 @@ export class CkEditorInitializerService { // eslint-disable-next-line max-len index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item.toLowerCase() ); - - /** - * If the component has not been initialized before with data, - * then set the default value or highlighted value as the - * component's data. - */ - const selection = that.editor.getSelection() - .getSelectedText(); - if (!that.data[spec.name]) { - if (spec.default_value_obtainable_from_highlight && - selection) { - that.setData(spec.name, selection); - } else { - that.setData(spec.name, spec.default_value); - } - } - capital.join(''); const customEl = that.element.getChild(0).$; customEl[capital.join('') + 'WithValue'] = ( @@ -262,7 +220,6 @@ export class CkEditorInitializerService { dontUpdate: true }); var that = this; - that.initialSnapshot = editor.getSnapshot(); // On init, read values from component attributes and save them. customizationArgSpecs.forEach(function(spec) { var value = that.element.getChild(0).getAttribute( diff --git a/core/templates/services/rte-helper-modal.component.html b/core/templates/services/rte-helper-modal.component.html index 022b08247e55b..db55f6f8a54a8 100644 --- a/core/templates/services/rte-helper-modal.component.html +++ b/core/templates/services/rte-helper-modal.component.html @@ -26,7 +26,7 @@

Customize This Component