@public-ui/hydrate 1.7.2 → 1.7.4

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.
Files changed (2) hide show
  1. package/dist/index.js +126 -24
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -7810,7 +7810,7 @@ const initKoliBri = () => {
7810
7810
  | . ' | .-. | | | ,--. | .-. \\ | .--' ,--.
7811
7811
  | |\\ \\ | '-' | | | | | | '--' / | | | |
7812
7812
  \`--' \`--´ \`---´ \`--' \`--' \`------´ \`--' \`--'
7813
- 🚹 The accessible HTML-Standard | 👉 https://public-ui.github.io | 1.7.2
7813
+ 🚹 The accessible HTML-Standard | 👉 https://public-ui.github.io | 1.7.4
7814
7814
  `, {
7815
7815
  forceLog: true,
7816
7816
  });
@@ -33524,15 +33524,23 @@ class KolTextarea {
33524
33524
  }; }
33525
33525
  }
33526
33526
 
33527
- const toastStatusOptions = ['adding', 'settled', 'removing'];
33528
-
33529
- const defaultStyleCss$2 = "";
33527
+ const defaultStyleCss$2 = "/*!@:host*/.sc-kol-toast-default-h{--a11y-min-size:44px;font-size:inherit}/*!@**/*.sc-kol-toast-default{font-family:Verdana;hyphens:auto;letter-spacing:inherit;word-break:break-word;word-spacing:inherit}/*!@[role='button'],\nbutton:not([role='link']),\nkol-input .input*/[role='button'].sc-kol-toast-default,button.sc-kol-toast-default:not([role='link']),kol-input.sc-kol-toast-default .input.sc-kol-toast-default{min-height:var(--a11y-min-size);min-width:var(--a11y-min-size)}/*!@a,\nbutton,\nh1,\nh2,\nh3,\nh4,\nh5,\nh6,\ninput,\noption,\nselect,\ntextarea*/a.sc-kol-toast-default,button.sc-kol-toast-default,h1.sc-kol-toast-default,h2.sc-kol-toast-default,h3.sc-kol-toast-default,h4.sc-kol-toast-default,h5.sc-kol-toast-default,h6.sc-kol-toast-default,input.sc-kol-toast-default,option.sc-kol-toast-default,select.sc-kol-toast-default,textarea.sc-kol-toast-default{font-family:inherit;font-size:inherit}/*!@:is(a, button)*/.sc-kol-toast-default:is(a,button).sc-kol-toast-default{background-color:transparent;border:none;margin:0;padding:0;width:100%}/*!@:host*/.sc-kol-toast-default-h{max-width:100%}/*!@**/*.sc-kol-toast-default{box-sizing:border-box}/*!@kol-span-wc*/kol-span-wc.sc-kol-toast-default{display:grid;place-items:center}/*!@kol-span-wc > span*/kol-span-wc.sc-kol-toast-default>span.sc-kol-toast-default{display:flex;place-items:center}/*!@a,\nbutton*/a.sc-kol-toast-default,button.sc-kol-toast-default{cursor:pointer}/*!@button,\ninput,\noption,\nselect,\ntextarea*/button.sc-kol-toast-default,input.sc-kol-toast-default,option.sc-kol-toast-default,select.sc-kol-toast-default,textarea.sc-kol-toast-default{font-family:inherit}/*!@.icon-only > kol-span-wc > span > span*/.icon-only.sc-kol-toast-default>kol-span-wc.sc-kol-toast-default>span.sc-kol-toast-default>span.sc-kol-toast-default{display:none}/*!@:host*/.sc-kol-toast-default-h{display:block}/*!@:host > div*/.sc-kol-toast-default-h>div.sc-kol-toast-default{background-color:#fff;height:0;left:0;position:fixed;top:0;width:100%;z-index:200}/*!@:host > div > kol-alert*/.sc-kol-toast-default-h>div.sc-kol-toast-default>kol-alert.sc-kol-toast-default{display:block;margin:auto;max-width:750px}/*!@:host > div > kol-button-wc*/.sc-kol-toast-default-h>div.sc-kol-toast-default>kol-button-wc.sc-kol-toast-default{display:block;margin:auto;position:relative;top:0;width:1em}";
33530
33528
 
33531
33529
  class KolToast {
33532
33530
  constructor(hostRef) {
33533
33531
  registerInstance(this, hostRef);
33532
+ this.handleShowAndDuration = () => {
33533
+ if (this.state._show === true && typeof this.state._showDuration === 'number' && this.state._showDuration >= 0) {
33534
+ clearTimeout(this.durationTimeout);
33535
+ this.durationTimeout = setTimeout(() => {
33536
+ this.close();
33537
+ }, this.state._showDuration);
33538
+ }
33539
+ };
33534
33540
  this.close = () => {
33535
33541
  var _a;
33542
+ this._show = false;
33543
+ this.state = Object.assign(Object.assign({}, this.state), { _show: false });
33536
33544
  if (((_a = this._on) === null || _a === void 0 ? void 0 : _a.onClose) !== undefined) {
33537
33545
  this._on.onClose(new Event('Close'));
33538
33546
  }
@@ -33540,42 +33548,76 @@ class KolToast {
33540
33548
  this.on = {
33541
33549
  onClose: this.close,
33542
33550
  };
33551
+ this._alert = true;
33552
+ this._hasCloser = false;
33553
+ this._heading = '';
33543
33554
  this._label = undefined;
33555
+ this._level = 1;
33544
33556
  this._on = undefined;
33545
- this._status = undefined;
33557
+ this._show = true;
33558
+ this._showDuration = 10000;
33546
33559
  this._type = 'default';
33547
33560
  this.state = {
33548
- _label: '...',
33549
- _status: 'adding',
33561
+ _alert: true,
33562
+ _level: 1,
33563
+ _show: true,
33550
33564
  };
33551
33565
  }
33566
+ validateAlert(value) {
33567
+ watchBoolean(this, '_alert', value);
33568
+ }
33569
+ validateHasCloser(value) {
33570
+ validateHasCloser(this, value);
33571
+ }
33572
+ validateHeading(value) {
33573
+ this.validateLabel(value);
33574
+ }
33552
33575
  validateLabel(value) {
33553
33576
  validateLabel(this, value);
33554
33577
  }
33578
+ validateLevel(value) {
33579
+ watchHeadingLevel(this, value);
33580
+ }
33555
33581
  validateOn(value) {
33556
33582
  if (typeof value === 'object' && (typeof (value === null || value === void 0 ? void 0 : value.onClose) === 'function' || value.onClose === true)) {
33557
33583
  setState(this, '_on', { onClose: value.onClose });
33558
33584
  }
33559
33585
  }
33560
- validateStatus(status) {
33561
- watchValidator(this, '_status', (status) => typeof status === 'string' && toastStatusOptions.includes(status), new Set('String {adding, settled, removing}'), status);
33586
+ validateShow(value) {
33587
+ validateShow(this, value, { hooks: { afterPatch: this.handleShowAndDuration } });
33588
+ }
33589
+ validateShowDuration(value) {
33590
+ watchNumber(this, '_showDuration', value, {
33591
+ hooks: {
33592
+ afterPatch: this.handleShowAndDuration,
33593
+ },
33594
+ });
33562
33595
  }
33563
33596
  validateType(value) {
33564
33597
  watchValidator(this, '_type', (value) => typeof value === 'string' && (value === 'default' || value === 'error' || value === 'info' || value === 'success' || value === 'warning'), new Set('String {success, info, warning, error}'), value);
33565
33598
  }
33566
33599
  componentWillLoad() {
33567
- this.validateLabel(this._label);
33600
+ this.validateAlert(this._alert);
33601
+ this.validateHasCloser(this._hasCloser);
33602
+ this.validateLabel(this._label || this._heading);
33603
+ this.validateLevel(this._level);
33568
33604
  this.validateOn(this._on);
33569
- this.validateStatus(this._status);
33605
+ this.validateShow(this._show);
33606
+ this.validateShowDuration(this._showDuration);
33570
33607
  this.validateType(this._type);
33571
33608
  }
33572
33609
  render() {
33573
- return (hAsync("div", { class: `toast ${this.state._status}` }, hAsync("kol-alert", { class: "alert", _alert: true, _label: this.state._label, _level: 0, _hasCloser: true, _type: this.state._type, _variant: "card", _on: this.on }, hAsync("slot", null))));
33610
+ return (hAsync(Host, null, this.state._show && (hAsync("div", null, hAsync("kol-alert", { _alert: this.state._alert, _label: this.state._label, _level: this.state._level, _hasCloser: this.state._hasCloser, _type: this.state._type, _variant: "card", _on: this.on }, hAsync("slot", null))))));
33574
33611
  }
33575
33612
  static get watchers() { return {
33613
+ "_alert": ["validateAlert"],
33614
+ "_hasCloser": ["validateHasCloser"],
33615
+ "_heading": ["validateHeading"],
33576
33616
  "_label": ["validateLabel"],
33617
+ "_level": ["validateLevel"],
33577
33618
  "_on": ["validateOn"],
33578
- "_status": ["validateStatus"],
33619
+ "_show": ["validateShow"],
33620
+ "_showDuration": ["validateShowDuration"],
33579
33621
  "_type": ["validateType"]
33580
33622
  }; }
33581
33623
  static get style() { return {
@@ -33585,19 +33627,35 @@ class KolToast {
33585
33627
  "$flags$": 41,
33586
33628
  "$tagName$": "kol-toast",
33587
33629
  "$members$": {
33630
+ "_alert": [4],
33631
+ "_hasCloser": [4, "_has-closer"],
33632
+ "_heading": [1],
33588
33633
  "_label": [1],
33634
+ "_level": [2],
33589
33635
  "_on": [16],
33590
- "_status": [1],
33636
+ "_show": [1540],
33637
+ "_showDuration": [2, "_show-duration"],
33591
33638
  "_type": [1],
33592
33639
  "state": [32]
33593
33640
  },
33594
33641
  "$listeners$": undefined,
33595
33642
  "$lazyBundleId$": "-",
33596
- "$attrsToReflect$": []
33643
+ "$attrsToReflect$": [["_show", "_show"]]
33597
33644
  }; }
33598
33645
  }
33599
33646
 
33600
- const defaultStyleCss$1 = "/*!@:host*/.sc-kol-toast-container-default-h{display:flex;flex-direction:column;position:fixed;z-index:200}/*!@.close-all*/.close-all.sc-kol-toast-container-default{align-self:flex-end}";
33647
+ const InternalToast = ({ toastState, onClose, key }) => {
33648
+ const handleRef = (element) => {
33649
+ if (typeof toastState.toast.render === 'function' && element) {
33650
+ toastState.toast.render(element, { close: () => onClose() });
33651
+ }
33652
+ };
33653
+ return (hAsync("div", { class: `toast ${toastState.status}`, key: key },
33654
+ hAsync("kol-alert", { class: "alert", _alert: true, _label: toastState.toast.label, _level: 0, _hasCloser: true, _type: toastState.toast.type, _variant: "card", _on: { onClose } },
33655
+ hAsync("div", { ref: handleRef }, typeof toastState.toast.description === 'string' ? toastState.toast.description : null))));
33656
+ };
33657
+
33658
+ const defaultStyleCss$1 = "@layer kol-component {\n\t.sc-kol-toast-container-default-h {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tposition: fixed;\n\t\tz-index: 200;\n\t}\n\n\t.close-all {\n\t\talign-self: flex-end;\n\t}\n}";
33601
33659
 
33602
33660
  const TRANSITION_TIMEOUT = 300;
33603
33661
  class KolToastContainer {
@@ -33637,7 +33695,7 @@ class KolToastContainer {
33637
33695
  }, TRANSITION_TIMEOUT);
33638
33696
  }
33639
33697
  render() {
33640
- return (hAsync(Fragment, null, this.state._toastStates.length > 1 && (hAsync("kol-button", { _label: translate('kol-toast-close-all'), class: "close-all", _on: { onClick: this.handleCloseAllClick.bind(this) } })), this.state._toastStates.map((toastState) => (hAsync("kol-toast", { _label: toastState.toast.label, _status: toastState.status, _type: toastState.toast.type, _on: { onClose: () => this.handleClose(toastState) }, key: toastState.id }, toastState.toast.description)))));
33698
+ return (hAsync(Fragment, null, this.state._toastStates.length > 1 && (hAsync("kol-button", { _label: translate('kol-toast-close-all'), class: "close-all", _on: { onClick: this.handleCloseAllClick.bind(this) } })), this.state._toastStates.map((toastState) => (hAsync(InternalToast, { toastState: toastState, onClose: () => this.handleClose(toastState), key: toastState.id })))));
33641
33699
  }
33642
33700
  static get style() { return {
33643
33701
  default: defaultStyleCss$1
@@ -34090,8 +34148,28 @@ var index = /*#__PURE__*/Object.freeze({
34090
34148
  class ToasterService {
34091
34149
  constructor(document) {
34092
34150
  this.document = document;
34093
- this.toastContainerElement = this.document.createElement('kol-toast-container');
34094
- this.document.body.prepend(this.toastContainerElement);
34151
+ this.queue = new Set();
34152
+ this.isOpen = false;
34153
+ this.toastElement = this.document.createElement('kol-toast');
34154
+ this.toastElement.setAttribute('_level', '0');
34155
+ this.toastElement.setAttribute('_show', 'false');
34156
+ this.toastElement.setAttribute('_show-duration', '-1');
34157
+ this.toastElement.setAttribute('_has-closer', 'true');
34158
+ this.toastElement._on = {
34159
+ onClose: () => {
34160
+ const next = this.queue.values().next();
34161
+ if (next.value) {
34162
+ this.queue.delete(next.value);
34163
+ setTimeout(() => {
34164
+ this.showToast(next.value);
34165
+ }, 200);
34166
+ }
34167
+ else {
34168
+ this.isOpen = false;
34169
+ }
34170
+ },
34171
+ };
34172
+ this.document.body.insertBefore(this.toastElement, this.document.body.firstChild);
34095
34173
  }
34096
34174
  static getInstance(document) {
34097
34175
  let instance = this.instances.get(document);
@@ -34102,18 +34180,42 @@ class ToasterService {
34102
34180
  return instance;
34103
34181
  }
34104
34182
  dispose() {
34105
- const element = this.toastContainerElement;
34183
+ const element = this.toastElement;
34106
34184
  if (element) {
34107
- this.toastContainerElement = undefined;
34185
+ this.toastElement = undefined;
34186
+ this.queue.clear();
34108
34187
  element.remove();
34188
+ const on = element._on;
34189
+ if (on && on.onClose) {
34190
+ on.onClose(new Event('dispose'));
34191
+ }
34109
34192
  }
34110
34193
  else {
34111
34194
  console.warn('Toaster service is already disposed.');
34112
34195
  }
34113
34196
  }
34114
- async enqueue(toast) {
34115
- var _a;
34116
- await ((_a = this.toastContainerElement) === null || _a === void 0 ? void 0 : _a.enqueue(toast));
34197
+ enqueue(data) {
34198
+ if (this.isOpen) {
34199
+ this.queue.add(data);
34200
+ }
34201
+ else {
34202
+ this.showToast(data);
34203
+ }
34204
+ }
34205
+ showToast(data) {
34206
+ const label = data.label || data.heading;
34207
+ if (typeof label === 'undefined') {
34208
+ throw new Error('Toast requires a label.');
34209
+ }
34210
+ if (!this.toastElement) {
34211
+ console.warn('Tried to show a new toast at a disposed toaster service!');
34212
+ return;
34213
+ }
34214
+ this.toastElement.setAttribute('_label', label);
34215
+ this.toastElement.setAttribute('_show', 'true');
34216
+ this.toastElement.setAttribute('_type', data.type);
34217
+ this.toastElement.innerText = data.description;
34218
+ this.isOpen = true;
34117
34219
  }
34118
34220
  }
34119
34221
  ToasterService.instances = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@public-ui/hydrate",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "license": "EUPL-1.2",
5
5
  "homepage": "https://public-ui.github.io",
6
6
  "repository": "https://github.com/public-ui/kolibri",
@@ -42,11 +42,11 @@
42
42
  "hydrate"
43
43
  ],
44
44
  "devDependencies": {
45
- "@public-ui/components": "1.7.2",
45
+ "@public-ui/components": "1.7.4",
46
46
  "rimraf": "3.0.2"
47
47
  },
48
48
  "peerDependencies": {
49
- "@public-ui/components": "1.7.2"
49
+ "@public-ui/components": "1.7.4"
50
50
  },
51
51
  "sideEffects": false,
52
52
  "type": "commonjs",