@ckeditor/ckeditor5-link 48.3.1 → 48.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1146,6 +1146,11 @@ var LinkFormView = class extends View {
1146
1146
  */
1147
1147
  saveButtonView;
1148
1148
  /**
1149
+ * A button that opens the {@link module:link/ui/linkpropertiesview~LinkPropertiesView} allowing the user to
1150
+ * configure manual decorators for the link handled by this form.
1151
+ */
1152
+ manualDecoratorsButtonView;
1153
+ /**
1149
1154
  * The "Displayed text" input view.
1150
1155
  */
1151
1156
  displayedTextInputView;
@@ -1186,6 +1191,7 @@ var LinkFormView = class extends View {
1186
1191
  this._validators = validators;
1187
1192
  this.backButtonView = this._createBackButton();
1188
1193
  this.saveButtonView = this._createSaveButton();
1194
+ this.manualDecoratorsButtonView = this._createManualDecoratorsButton();
1189
1195
  this.displayedTextInputView = this._createDisplayedTextInput();
1190
1196
  this.urlInputView = this._createUrlInput();
1191
1197
  this.providersListChildren = this.createCollection();
@@ -1226,6 +1232,7 @@ var LinkFormView = class extends View {
1226
1232
  submitHandler({ view: this });
1227
1233
  [
1228
1234
  this.urlInputView,
1235
+ this.manualDecoratorsButtonView,
1229
1236
  this.saveButtonView,
1230
1237
  ...this.providersListChildren,
1231
1238
  this.backButtonView,
@@ -1304,6 +1311,21 @@ var LinkFormView = class extends View {
1304
1311
  return saveButton;
1305
1312
  }
1306
1313
  /**
1314
+ * Creates a button that opens the link properties view.
1315
+ */
1316
+ _createManualDecoratorsButton() {
1317
+ const t = this.locale.t;
1318
+ const button = new ButtonView(this.locale);
1319
+ button.set({
1320
+ label: t("Link properties"),
1321
+ icon: IconSettings,
1322
+ tooltip: true,
1323
+ isVisible: false
1324
+ });
1325
+ button.delegate("execute").to(this, "showDecorators");
1326
+ return button;
1327
+ }
1328
+ /**
1307
1329
  * Creates a header view for the form.
1308
1330
  */
1309
1331
  _createHeaderView() {
@@ -1357,7 +1379,11 @@ var LinkFormView = class extends View {
1357
1379
  class: ["ck-form__row_large-top-padding"]
1358
1380
  }));
1359
1381
  this.children.add(new FormRowView(this.locale, {
1360
- children: [this.urlInputView, this.saveButtonView],
1382
+ children: [
1383
+ this.urlInputView,
1384
+ this.manualDecoratorsButtonView,
1385
+ this.saveButtonView
1386
+ ],
1361
1387
  class: [
1362
1388
  "ck-form__row_with-submit",
1363
1389
  "ck-form__row_large-top-padding",
@@ -1919,6 +1945,10 @@ var LinkUI = class extends Plugin {
1919
1945
  cancel();
1920
1946
  });
1921
1947
  formView.providersListChildren.bindTo(this._linksProviders).using((provider) => this._createLinksListProviderButton(provider));
1948
+ formView.manualDecoratorsButtonView.isVisible = linkCommand.manualDecorators.length > 0;
1949
+ this.listenTo(formView, "showDecorators", () => {
1950
+ this._addPropertiesView();
1951
+ });
1922
1952
  return formView;
1923
1953
  }
1924
1954
  /**
@@ -1968,8 +1998,13 @@ var LinkUI = class extends Plugin {
1968
1998
  const linkCommand = this.editor.commands.get("link");
1969
1999
  const view = new (CssTransitionDisablerMixin(LinkPropertiesView))(editor.locale);
1970
2000
  this.listenTo(view, "back", () => {
1971
- editor.editing.view.focus();
1972
- this._removePropertiesView();
2001
+ if (this._isFormInPanel) {
2002
+ this._removePropertiesView();
2003
+ this.formView.focus();
2004
+ } else {
2005
+ editor.editing.view.focus();
2006
+ this._removePropertiesView();
2007
+ }
1973
2008
  });
1974
2009
  view.listChildren.bindTo(linkCommand.manualDecorators).using((manualDecorator) => {
1975
2010
  const button = new SwitchButtonView(editor.locale);
@@ -1981,10 +2016,12 @@ var LinkUI = class extends Plugin {
1981
2016
  return commandValue === void 0 && decoratorValue === void 0 ? !!manualDecorator.defaultValue : !!decoratorValue;
1982
2017
  });
1983
2018
  button.on("execute", () => {
1984
- editor.execute("link", linkCommand.value, {
2019
+ const newValue = !button.isOn;
2020
+ if (linkCommand.value !== void 0) editor.execute("link", linkCommand.value, {
1985
2021
  ...this._getDecoratorSwitchesState(),
1986
- [manualDecorator.id]: !button.isOn
2022
+ [manualDecorator.id]: newValue
1987
2023
  });
2024
+ else this._togglePendingManualDecorator(manualDecorator, newValue);
1988
2025
  });
1989
2026
  return button;
1990
2027
  });
@@ -2004,6 +2041,37 @@ var LinkUI = class extends Plugin {
2004
2041
  }, {});
2005
2042
  }
2006
2043
  /**
2044
+ * Toggles the state of a manual decorator while a new link is being created, that is, before it is
2045
+ * inserted into the document. Since there is no link (and no command value) to execute the `'link'`
2046
+ * command against yet, the new state is kept on the decorator's own observable
2047
+ * {@link module:link/utils/manualdecorator~LinkManualDecorator#value} instead of the model.
2048
+ */
2049
+ _togglePendingManualDecorator(manualDecorator, newValue) {
2050
+ const linkCommand = this.editor.commands.get("link");
2051
+ const allDecorators = Array.from(linkCommand.manualDecorators);
2052
+ const decoratorStates = this._getDecoratorSwitchesState();
2053
+ const previousDecoratorStates = allDecorators.map((decorator) => ({
2054
+ id: decorator.id,
2055
+ attributes: decorator.attributes,
2056
+ styles: decorator.styles,
2057
+ value: decoratorStates[decorator.id]
2058
+ }));
2059
+ decoratorStates[manualDecorator.id] = newValue;
2060
+ const resolvedStates = resolveConflictingDecorators({
2061
+ decoratorStates,
2062
+ allDecorators: previousDecoratorStates
2063
+ });
2064
+ for (const decorator of allDecorators) decorator.value = resolvedStates[decorator.id];
2065
+ }
2066
+ /**
2067
+ * Clears the state of all manual decorators that may have been toggled while creating a link that,
2068
+ * in the end, was never inserted into the document (for example, the user canceled the form).
2069
+ */
2070
+ _resetPendingManualDecoratorsState() {
2071
+ const linkCommand = this.editor.commands.get("link");
2072
+ for (const manualDecorator of linkCommand.manualDecorators) manualDecorator.value = void 0;
2073
+ }
2074
+ /**
2007
2075
  * Registers listeners used in editing plugin, used to open links.
2008
2076
  */
2009
2077
  _registerEditingOpeners() {
@@ -2120,7 +2188,7 @@ var LinkUI = class extends Plugin {
2120
2188
  icon: IconSettings,
2121
2189
  tooltip: true
2122
2190
  });
2123
- button.bind("isEnabled").to(linkCommand, "isEnabled", linkCommand, "value", linkCommand, "manualDecorators", (isEnabled, href, manualDecorators) => isEnabled && !!href && manualDecorators.length > 0);
2191
+ button.bind("isEnabled").to(linkCommand, "isEnabled", linkCommand, "value", linkCommand, "manualDecorators", (isEnabled, href, manualDecorators) => isEnabled && href !== void 0 && manualDecorators.length > 0);
2124
2192
  this.listenTo(button, "execute", () => {
2125
2193
  this._addPropertiesView();
2126
2194
  });
@@ -2302,9 +2370,11 @@ var LinkUI = class extends Plugin {
2302
2370
  */
2303
2371
  _removeFormView(updateFocus = true) {
2304
2372
  if (this._isFormInPanel) {
2373
+ const linkCommand = this.editor.commands.get("link");
2305
2374
  this.formView.saveButtonView.focus();
2306
2375
  this.formView.displayedTextInputView.fieldView.reset();
2307
2376
  this.formView.urlInputView.fieldView.reset();
2377
+ if (linkCommand.value === void 0) this._resetPendingManualDecoratorsState();
2308
2378
  this._balloon.remove(this.formView);
2309
2379
  if (updateFocus) this.editor.editing.view.focus();
2310
2380
  this._hideFakeVisualSelection();