u2ui 1.5.4 → 1.5.8

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.
@@ -8,7 +8,6 @@ export class Toolbar {
8
8
  #surfaceController = null;
9
9
  #surface = null;
10
10
  #commands = null;
11
- #dismissed = false;
12
11
  #connected = true;
13
12
 
14
13
  constructor(core, element, {commands, place = null} = {}) {
@@ -39,8 +38,6 @@ export class Toolbar {
39
38
  }, listen);
40
39
  element.addEventListener('click', this.#click, listen);
41
40
  element.addEventListener('change', this.#change, listen);
42
- core.root.addEventListener('focusin', this.#focusIn, {...listen, capture: true});
43
- core.root.addEventListener('focusout', this.#focusOut, {...listen, capture: true});
44
41
  if (!element.hasAttribute('role')) element.setAttribute('role', 'toolbar');
45
42
  element.hidden = true;
46
43
  // Focus landing in a control is still the editor's: without this the core
@@ -66,12 +63,16 @@ export class Toolbar {
66
63
  const commands = surface?.connected ? this.#resolve(surface) : null;
67
64
  if (commands != null && !registry(commands)) throw new TypeError('Toolbar commands must resolve to a command registry');
68
65
  this.#commands = commands || null;
69
- const active = !!commands && !this.#dismissed && surface.config.ui === 'roaming'
70
- && visibleForSelection(surface);
71
- const names = active ? configured(surface.element) : null;
66
+ // One computed style for the settings only this toolbar reads: asking for
67
+ // it three times is three style resolutions on a path every keystroke
68
+ // goes down. The shared ones keep coming from the surface, defaults and
69
+ // validation included.
70
+ const style = commands && getComputedStyle(surface.element);
71
+ const active = !!commands && surface.config.ui === 'roaming' && visibleForSelection(surface, style);
72
+ const names = active ? configured(style) : null;
72
73
  // A host may prefer a toolbar that only ever shows what it can do, at
73
74
  // the cost of a shape that moves with the caret.
74
- const hiding = active && unavailable(surface.element) === 'hide';
75
+ const hiding = active && setting(style, 'toolbar-unavailable') === 'hide';
75
76
  const detail = surface?.selection ? {range: surface.selection.range()} : undefined;
76
77
  let visible = 0;
77
78
  for (const item of this.#items()) {
@@ -138,7 +139,6 @@ export class Toolbar {
138
139
  this.#surfaceController = null;
139
140
  this.#surface = null;
140
141
  this.#commands = null;
141
- this.#dismissed = false;
142
142
  display(this.#element, false);
143
143
  this.#connected = false;
144
144
  }
@@ -154,7 +154,6 @@ export class Toolbar {
154
154
  }
155
155
  this.#surfaceController?.abort();
156
156
  this.#surface = surface || null;
157
- this.#dismissed = false;
158
157
  this.#surfaceController = null;
159
158
  if (surface) {
160
159
  const Controller = this.#element.ownerDocument.defaultView.AbortController;
@@ -194,18 +193,6 @@ export class Toolbar {
194
193
  #disconnect = () => this.#activate(null);
195
194
  #refresh = () => this.refresh();
196
195
 
197
- #focusIn = event => {
198
- if (!this.#dismissed || !this.#ownsFocus(event.composedPath()[0])) return;
199
- this.#dismissed = false;
200
- this.refresh();
201
- };
202
-
203
- #focusOut = event => {
204
- if (!this.#ownsFocus(event.composedPath()[0]) || this.#ownsFocus(event.relatedTarget)) return;
205
- this.#dismissed = true;
206
- display(this.#element, false);
207
- };
208
-
209
196
  // The toolbar is chrome: pointing at it must never move the editor's
210
197
  // selection, not even at a control that currently has nothing to run.
211
198
  // Fields keep their own pointer behaviour so they can be opened and typed in.
@@ -233,18 +220,6 @@ export class Toolbar {
233
220
  }
234
221
  this.#run(command, {value: name});
235
222
  };
236
-
237
-
238
- #ownsFocus(node) {
239
- if (!node || !this.#surface) return false;
240
- // A `focusout` listener outside the toolbar's shadow tree sees its
241
- // related target retargeted to that tree's host, so focus moving into a
242
- // control of its own would otherwise read as focus leaving.
243
- const root = this.#element.getRootNode();
244
- if (root.host && node === root.host) return true;
245
- return node === this.#element || this.#element.contains(node)
246
- || node === this.#surface.element || this.#surface.element.contains(node);
247
- }
248
223
  }
249
224
 
250
225
  function registry(value) {
@@ -254,18 +229,18 @@ function registry(value) {
254
229
  && typeof value?.run === 'function';
255
230
  }
256
231
 
257
- function configured(element) {
258
- const value = getComputedStyle(element).getPropertyValue('--u2-rte-toolbar').trim();
259
- return value ? new Set(value.split(/[\s,]+/).filter(Boolean)) : null;
232
+ function setting(style, name) {
233
+ return style.getPropertyValue(`--u2-rte-${name}`).trim();
260
234
  }
261
235
 
262
- function unavailable(element) {
263
- return getComputedStyle(element).getPropertyValue('--u2-rte-toolbar-unavailable').trim();
236
+ function configured(style) {
237
+ const value = setting(style, 'toolbar');
238
+ return value ? new Set(value.split(/[\s,]+/).filter(Boolean)) : null;
264
239
  }
265
240
 
266
- function visibleForSelection(surface) {
267
- const value = getComputedStyle(surface.element).getPropertyValue('--u2-rte-toolbar-when').trim();
268
- return value !== 'selection' || !!surface.selection && !surface.selection.collapsed;
241
+ function visibleForSelection(surface, style) {
242
+ return setting(style, 'toolbar-when') !== 'selection'
243
+ || !!surface.selection && !surface.selection.collapsed;
269
244
  }
270
245
 
271
246
  function state(item, value, disabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u2ui",
3
- "version": "1.5.4",
3
+ "version": "1.5.8",
4
4
  "description": "HTML Advanced: More Capabilities, Same Feel, Same Simplicity",
5
5
  "keywords": ["web-components","pattern-library","component-library","ui-toolkit","design-system"],
6
6
  "author": "Tobias Buschor",