@brandup/ui-textbox 1.0.39 → 1.0.41

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/package.json CHANGED
@@ -24,15 +24,15 @@
24
24
  "email": "it@brandup.online"
25
25
  },
26
26
  "license": "Apache-2.0",
27
- "version": "1.0.39",
27
+ "version": "1.0.41",
28
28
  "main": "source/index.ts",
29
29
  "types": "source/index.ts",
30
30
  "dependencies": {
31
31
  "@brandup/ui": "^2.0.7",
32
32
  "@brandup/ui-helpers": "^2.0.7",
33
- "@brandup/ui-input": "^1.0.39",
34
- "@brandup/ui-kit": "^1.0.39",
35
- "@brandup/ui-richeditor": "^1.0.39"
33
+ "@brandup/ui-input": "^1.0.41",
34
+ "@brandup/ui-kit": "^1.0.41",
35
+ "@brandup/ui-richeditor": "^1.0.41"
36
36
  },
37
37
  "files": [
38
38
  "source",
@@ -49,26 +49,7 @@
49
49
  z-index: 2;
50
50
  margin-right: 5px;
51
51
  padding-right: calc(var(--input-padding-lr) - 5px);
52
- scrollbar-width: 6px;
53
- overflow-y: auto;
54
-
55
- &::-webkit-scrollbar {
56
- width: 6px;
57
- background: none;
58
- }
59
-
60
- &::-webkit-scrollbar-track {
61
- border-radius: 3px;
62
- background-color: transparent;
63
- margin: 6px 0;
64
- cursor: default;
65
- }
66
-
67
- &::-webkit-scrollbar-thumb {
68
- background-color: #8696a0;
69
- border-radius: 3px;
70
- cursor: default;
71
- }
52
+ overflow-y: auto; // полоса прокрутки — общая, от .ui-scrollable кита
72
53
  }
73
54
 
74
55
  // редактор (@brandup/ui-richeditor) — занимает доступное место; внутреннее оформление в richeditor.less
package/source/textbox.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./textbox.less"; // стили компонента
2
2
 
3
3
  import { InputControl } from "@brandup/ui-input";
4
- import { IS_TOUCH_DEVICE } from "@brandup/ui-kit";
4
+ import { IS_TOUCH_DEVICE, SCROLLABLE_CLASS } from "@brandup/ui-kit";
5
5
  import { DOM } from "@brandup/ui";
6
6
  import { FuncHelper } from "@brandup/ui-helpers";
7
7
  import RichEditor, {
@@ -102,15 +102,16 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
102
102
  // форматирование доступно только для обычного текстового ввода
103
103
  const format = type === "text" && valueElem.hasAttribute("data-format");
104
104
  const formatStorage: FormatStorage =
105
- valueElem.getAttribute("data-format-storage") === "markdown" ? "markdown" : "html";
106
- const formatTools = format ? parseFormatTools(valueElem.getAttribute("data-format-tools")) : [];
105
+ valueElem.dataset.formatStorage === "markdown" ? "markdown" : "html";
106
+ const formatTools = format ? parseFormatTools(valueElem.dataset.formatTools ?? null) : [];
107
107
  // кнопки действий панели (очистка формата, отмена, повтор) — подключаются явно
108
- const editorActions = format ? parseEditorActions(valueElem.getAttribute("data-editor-actions")) : [];
108
+ const editorActions = format ? parseEditorActions(valueElem.dataset.editorActions ?? null) : [];
109
109
 
110
110
  // markdown-маркеры с дефолтами, переопределяются атрибутами data-format-md-<tool>
111
111
  const formatMarkers = defaultFormatMarkers();
112
112
  if (format) {
113
113
  for (const tool of Object.keys(formatMarkers) as FormatTool[]) {
114
+ // имя атрибута собирается на ходу: у dataset оно потребовало бы ручного camelCase
114
115
  const marker = valueElem.getAttribute(`data-format-md-${tool}`)?.trim();
115
116
  if (marker) formatMarkers[tool] = marker;
116
117
  }
@@ -122,7 +123,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
122
123
 
123
124
  const container = DOM.tag("div", { class: ROOT_CLASS }, [
124
125
  DOM.tag("div", { class: "decorator" }),
125
- DOM.tag("div", { class: "editor" }, [inputElem, symbolsCountElem]),
126
+ DOM.tag("div", { class: ["editor", SCROLLABLE_CLASS] }, [inputElem, symbolsCountElem]),
126
127
  actionsElem,
127
128
  ]);
128
129
 
@@ -139,7 +140,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
139
140
  // команда объявляется атрибутом data-command — по нему её ищет обработчик @brandup/ui
140
141
  const buttonElem = DOM.tag(
141
142
  "button",
142
- { "data-command": "copy-text", title: "Скопировать в буфер обмена" },
143
+ { command: "copy-text", title: "Скопировать в буфер обмена" },
143
144
  copyIcon
144
145
  );
145
146
  if (disabled) buttonElem.disabled = true;
@@ -189,7 +190,7 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
189
190
  toolbarContainer: container,
190
191
  value: valueElem.value,
191
192
  onReject: () => this.__toIncorrect(),
192
- onEnter: () => this.__submitForm(),
193
+ onEnter: () => this.__requestSubmit(),
193
194
  };
194
195
 
195
196
  // допустим ли вводимый символ по типу.
@@ -328,6 +329,23 @@ export default class TextBox extends InputControl<HTMLInputElement | HTMLTextAre
328
329
  // валидация, отправка формы, сбор FormData.
329
330
  protected override __syncValue(): void {
330
331
  this.__editor.flushChange();
332
+ this.__refreshValidity();
333
+ }
334
+
335
+ /**
336
+ * Собственное ограничение контрола объявляем полю через setCustomValidity — дальше всё
337
+ * делает браузер, как с нативными `required` и `pattern`: блокирует отправку и поднимает
338
+ * invalid. Иначе правило работало бы только в нашем validate(), а форма уезжала бы.
339
+ *
340
+ * Длину меряем по видимому тексту, а не по значению: при format/html в нём теги, в multiline —
341
+ * разделители абзацев. Нативный maxLength здесь не помощник: он ограничивает набор, но не
342
+ * помечает значение, выставленное из кода.
343
+ */
344
+ private __refreshValidity(): void {
345
+ if (this.maxlength <= 0) return;
346
+
347
+ const tooLong = this.maxlength < this.__editor.getLength();
348
+ this.__valueElem.setCustomValidity(tooLong ? `Не больше ${this.maxlength} символов.` : "");
331
349
  }
332
350
 
333
351
  private __toIncorrect() {