tablefilter 0.7.13 → 0.7.14

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.
@@ -17717,6 +17717,7 @@
17717
17717
  };
17718
17718
  //#endregion
17719
17719
  //#region src/modules/noResults.js
17720
+ var TOGGLE_EVENTS = ["initialized", "after-filtering"];
17720
17721
  /**
17721
17722
  * UI when filtering yields no matches
17722
17723
  * @export
@@ -17740,18 +17741,18 @@
17740
17741
  * Custom container DOM element
17741
17742
  * @type {DOMElement}
17742
17743
  */
17743
- this.customContainer = defaultsStr(f.custom_container, null);
17744
+ this.customContainer = f.custom_container && typeof f.custom_container.appendChild === "function" ? f.custom_container : null;
17744
17745
  /**
17745
17746
  * ID of custom container element
17746
17747
  * @type {String}
17747
17748
  */
17748
17749
  this.customContainerId = defaultsStr(f.custom_container_id, null);
17749
17750
  /**
17750
- * Indicates if UI is contained in a external element
17751
+ * True when a container element is present or a container id is set
17751
17752
  * @type {Boolean}
17752
17753
  * @private
17753
17754
  */
17754
- this.isExternal = !isEmpty(this.customContainer) || !isEmpty(this.customContainerId);
17755
+ this.isExternal = Boolean(this.customContainer) || Boolean(this.customContainerId);
17755
17756
  /**
17756
17757
  * Css class assigned to container element
17757
17758
  * @type {String}
@@ -17782,23 +17783,67 @@
17782
17783
  * @type {Function}
17783
17784
  */
17784
17785
  this.onAfterHide = defaultsFn(f.on_after_hide_msg, EMPTY_FN);
17786
+ /**
17787
+ * Subscribed toggle handler
17788
+ * @type {Function|null}
17789
+ * @private
17790
+ */
17791
+ this.boundToggle = null;
17785
17792
  }
17786
17793
  /**
17787
17794
  * Initializes NoResults instance
17788
17795
  */
17789
17796
  init() {
17790
17797
  if (this.initialized) return;
17791
- let tf = this.tf;
17792
- let target = this.customContainer || elm(this.customContainerId) || tf.dom();
17798
+ let targetEl = this.isExternal ? this.customContainer || elm(this.customContainerId) : null;
17799
+ if (this.canUseCE(targetEl)) this.initCE(targetEl);
17800
+ else this.initLegacy(targetEl);
17801
+ this.boundToggle = () => this.toggle();
17802
+ this.emitter.on(TOGGLE_EVENTS, this.boundToggle);
17803
+ /** @inherited */
17804
+ this.initialized = true;
17805
+ }
17806
+ /**
17807
+ * Whether the feature renders through `<tf-no-results>`.
17808
+ * @param {DOMElement} targetEl Resolved external container, if any
17809
+ * @returns {Boolean} True when the registered element exposes `setText`
17810
+ * and no external container is configured, or the container resolves
17811
+ * @private
17812
+ */
17813
+ canUseCE(targetEl) {
17814
+ const NoResultsElement = typeof customElements === "undefined" ? null : customElements.get("tf-no-results");
17815
+ return Boolean(NoResultsElement) && typeof NoResultsElement.prototype.setText === "function" && (!this.isExternal || Boolean(targetEl && typeof targetEl.appendChild === "function"));
17816
+ }
17817
+ /**
17818
+ * Initialize using the <tf-no-results> custom element
17819
+ * @param {DOMElement} targetEl External container element
17820
+ * @private
17821
+ */
17822
+ initCE(targetEl) {
17823
+ const host = document.createElement("tf-no-results");
17824
+ host.className = this.cssClass;
17825
+ host.setText("");
17826
+ host.innerHTML = sanitizeHtml(this.content);
17827
+ if (this.isExternal) targetEl.appendChild(host);
17828
+ else {
17829
+ const dom = this.tf.dom();
17830
+ dom.parentNode.insertBefore(host, dom.nextSibling);
17831
+ }
17832
+ this.cont = host;
17833
+ }
17834
+ /**
17835
+ * Initialize using the legacy div container
17836
+ * @param {DOMElement} targetEl External container element
17837
+ * @private
17838
+ */
17839
+ initLegacy(targetEl) {
17840
+ let target = targetEl || this.tf.dom();
17793
17841
  let cont = createElm("div");
17794
17842
  cont.className = this.cssClass;
17795
17843
  cont.innerHTML = this.content;
17796
17844
  if (this.isExternal) target.appendChild(cont);
17797
17845
  else target.parentNode.insertBefore(cont, target.nextSibling);
17798
17846
  this.cont = cont;
17799
- this.emitter.on(["initialized", "after-filtering"], () => this.toggle());
17800
- /** @inherited */
17801
- this.initialized = true;
17802
17847
  }
17803
17848
  /**
17804
17849
  * Toggle no results message
@@ -17841,9 +17886,12 @@
17841
17886
  /** Remove feature */
17842
17887
  destroy() {
17843
17888
  if (!this.initialized) return;
17844
- removeElm(this.cont);
17889
+ if (this.cont && this.cont.parentNode) removeElm(this.cont);
17845
17890
  this.cont = null;
17846
- this.emitter.off(["after-filtering"], () => this.toggle());
17891
+ if (this.boundToggle) {
17892
+ this.emitter.off(TOGGLE_EVENTS, this.boundToggle);
17893
+ this.boundToggle = null;
17894
+ }
17847
17895
  this.initialized = false;
17848
17896
  }
17849
17897
  };
@@ -18737,7 +18785,7 @@
18737
18785
  * Current version
18738
18786
  * @type {String}
18739
18787
  */
18740
- this.version = "0.7.13";
18788
+ this.version = "0.7.14";
18741
18789
  /**
18742
18790
  * Current year
18743
18791
  * @type {Number}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tablefilter",
3
- "version": "0.7.13",
3
+ "version": "0.7.14",
4
4
  "description": "A Javascript library making HTML tables filterable and a bit more",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -31,11 +31,11 @@
31
31
  "scripts": {
32
32
  "lint": "eslint src/**/*.js test/*.js test/playwright/*.js *.js",
33
33
  "lint:css-tokens": "node scripts/check-css-tokens.js",
34
- "dev": "node scripts/with-legacy-openssl.js webpack --colors --config webpack.dev.config.js",
35
- "build": "node scripts/with-legacy-openssl.js webpack --colors --config webpack.config.js",
34
+ "dev": "node scripts/with-legacy-openssl.js webpack --color --config webpack.dev.config.js",
35
+ "build": "node scripts/with-legacy-openssl.js webpack --color --config webpack.config.js",
36
36
  "build:css": "stylus -c static/style/tablefilter.styl -o dist/tablefilter/style && stylus -c static/style/extensions -o dist/tablefilter/style && stylus -c static/style/themes/default -o dist/tablefilter/style/themes/default && stylus -c static/style/themes/mytheme -o dist/tablefilter/style/themes/mytheme && stylus -c static/style/themes/skyblue -o dist/tablefilter/style/themes/skyblue && stylus -c static/style/themes/transparent -o dist/tablefilter/style/themes/transparent",
37
37
  "build:demos": "grunt build-demos",
38
- "build:test": "node scripts/with-legacy-openssl.js webpack --colors --config webpack.test.config.js",
38
+ "build:test": "node scripts/with-legacy-openssl.js webpack --color --config webpack.test.config.js",
39
39
  "build:vite": "vite build",
40
40
  "serve:vite": "npm run build:vite && vite --port 8080 --strictPort",
41
41
  "server": "node scripts/with-legacy-openssl.js webpack-dev-server --colors --hot --config ./webpack.dev.config.js",
@@ -83,7 +83,7 @@
83
83
  "uglifyjs-webpack-plugin": "2.2.0",
84
84
  "vite": "8.3.4",
85
85
  "webpack": "^4.38.0",
86
- "webpack-cli": "^3.0.8",
86
+ "webpack-cli": "^4.10.0",
87
87
  "webpack-dev-server": "^4.15.2"
88
88
  },
89
89
  "bugs": {
@@ -0,0 +1,94 @@
1
+ /**
2
+ * `<tf-no-results>` custom element: polite no-results announcement.
3
+ *
4
+ * An open shadow root exposes the `message-slot` and `message` parts.
5
+ * Consumer markup (`no_results_message.content`,
6
+ * ROADMAP/content-projection-parity.md) renders through the default slot;
7
+ * the `text` attribute is the plain-text fallback rendered as text into
8
+ * `message`, which hides while slotted content is present.
9
+ *
10
+ * `connectedCallback()` applies the shared live-region contract to the host.
11
+ * The bridge sanitises configured markup with `sanitizeHtml()` before
12
+ * projecting it (P7, ROADMAP/content-projection-parity.md). The configurable
13
+ * message class (`no_results_message.css_class`), external containers
14
+ * (`custom_container`/`custom_container_id`) and show/hide callbacks stay in
15
+ * the bridge (#919). The look comes from the stylesheet and themes.
16
+ *
17
+ * Importing this module registers the element. Consumers load this module
18
+ * directly; #965 tracks the legacy webpack bundle.
19
+ */
20
+
21
+ import {applyLiveRegion} from './attributes.js';
22
+
23
+ const TEMPLATE = document.createElement('template');
24
+ TEMPLATE.innerHTML = `
25
+ <slot part="message-slot"></slot>
26
+ <span part="message"></span>
27
+ `;
28
+
29
+ export class TfNoResultsElement extends HTMLElement {
30
+ constructor() {
31
+ super();
32
+ this.attachShadow({ mode: 'open' });
33
+ this.shadowRoot.appendChild(TEMPLATE.content.cloneNode(true));
34
+ this._messageSlot =
35
+ this.shadowRoot.querySelector('[part="message-slot"]');
36
+ this._messageEl = this.shadowRoot.querySelector('[part="message"]');
37
+
38
+ this._messageSlot.addEventListener(
39
+ 'slotchange', () => this._syncLayout());
40
+ }
41
+
42
+ static get observedAttributes() {
43
+ return ['text'];
44
+ }
45
+
46
+ connectedCallback() {
47
+ applyLiveRegion(this);
48
+ this._update();
49
+ this._syncLayout();
50
+ }
51
+
52
+ attributeChangedCallback() {
53
+ this._update();
54
+ }
55
+
56
+ /**
57
+ * Set the fallback message text. Values are coerced to strings; 0
58
+ * renders as '0'.
59
+ * @param {String} text Message text
60
+ */
61
+ setText(text) {
62
+ this.setAttribute('text', text == null ? '' : String(text));
63
+ }
64
+
65
+ /**
66
+ * Render the `text` attribute as text into the `message` part.
67
+ */
68
+ _update() {
69
+ if (this._messageEl) {
70
+ this._messageEl.textContent = this.getAttribute('text') || '';
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Hide the message part while the default slot carries an element or a
76
+ * non-whitespace text node.
77
+ */
78
+ _syncLayout() {
79
+ if (!this._messageEl) {
80
+ return;
81
+ }
82
+ this._messageEl.hidden = this._messageSlot
83
+ .assignedNodes({ flatten: true })
84
+ .some((node) => node.nodeType === 1 ||
85
+ (node.nodeType === 3 && node.textContent.trim() !== ''));
86
+ }
87
+ }
88
+
89
+ // Register once: loading this module twice, or on a page that already
90
+ // defined the element, keeps the existing definition.
91
+ if (typeof customElements !== 'undefined' &&
92
+ !customElements.get('tf-no-results')) {
93
+ customElements.define('tf-no-results', TfNoResultsElement);
94
+ }
@@ -1,8 +1,11 @@
1
1
  import {Feature} from '../feature';
2
2
  import {createElm, elm, removeElm} from '../dom';
3
- import {isEmpty, EMPTY_FN} from '../types';
3
+ import {EMPTY_FN} from '../types';
4
4
  import {NONE} from '../const';
5
5
  import {defaultsStr, defaultsFn} from '../settings';
6
+ import {sanitizeHtml} from '../sanitize';
7
+
8
+ const TOGGLE_EVENTS = ['initialized', 'after-filtering'];
6
9
 
7
10
  /**
8
11
  * UI when filtering yields no matches
@@ -32,7 +35,9 @@ export class NoResults extends Feature {
32
35
  * Custom container DOM element
33
36
  * @type {DOMElement}
34
37
  */
35
- this.customContainer = defaultsStr(f.custom_container, null);
38
+ this.customContainer = f.custom_container &&
39
+ typeof f.custom_container.appendChild === 'function' ?
40
+ f.custom_container : null;
36
41
 
37
42
  /**
38
43
  * ID of custom container element
@@ -41,12 +46,12 @@ export class NoResults extends Feature {
41
46
  this.customContainerId = defaultsStr(f.custom_container_id, null);
42
47
 
43
48
  /**
44
- * Indicates if UI is contained in a external element
49
+ * True when a container element is present or a container id is set
45
50
  * @type {Boolean}
46
51
  * @private
47
52
  */
48
- this.isExternal = !isEmpty(this.customContainer) ||
49
- !isEmpty(this.customContainerId);
53
+ this.isExternal = Boolean(this.customContainer) ||
54
+ Boolean(this.customContainerId);
50
55
 
51
56
  /**
52
57
  * Css class assigned to container element
@@ -83,6 +88,13 @@ export class NoResults extends Feature {
83
88
  * @type {Function}
84
89
  */
85
90
  this.onAfterHide = defaultsFn(f.on_after_hide_msg, EMPTY_FN);
91
+
92
+ /**
93
+ * Subscribed toggle handler
94
+ * @type {Function|null}
95
+ * @private
96
+ */
97
+ this.boundToggle = null;
86
98
  }
87
99
 
88
100
  /**
@@ -92,11 +104,66 @@ export class NoResults extends Feature {
92
104
  if (this.initialized) {
93
105
  return;
94
106
  }
95
- let tf = this.tf;
96
- let target = this.customContainer || elm(this.customContainerId) ||
97
- tf.dom();
107
+ let targetEl = this.isExternal ?
108
+ this.customContainer || elm(this.customContainerId) : null;
109
+
110
+ // TODO(#965): remove once the legacy webpack pipeline is retired.
111
+ if (this.canUseCE(targetEl)) {
112
+ this.initCE(targetEl);
113
+ } else {
114
+ this.initLegacy(targetEl);
115
+ }
116
+
117
+ this.boundToggle = () => this.toggle();
118
+ this.emitter.on(TOGGLE_EVENTS, this.boundToggle);
119
+
120
+ /** @inherited */
121
+ this.initialized = true;
122
+ }
123
+
124
+ /**
125
+ * Whether the feature renders through `<tf-no-results>`.
126
+ * @param {DOMElement} targetEl Resolved external container, if any
127
+ * @returns {Boolean} True when the registered element exposes `setText`
128
+ * and no external container is configured, or the container resolves
129
+ * @private
130
+ */
131
+ canUseCE(targetEl) {
132
+ const NoResultsElement = typeof customElements === 'undefined' ?
133
+ null : customElements.get('tf-no-results');
134
+ return Boolean(NoResultsElement) &&
135
+ typeof NoResultsElement.prototype.setText === 'function' &&
136
+ (!this.isExternal || Boolean(targetEl &&
137
+ typeof targetEl.appendChild === 'function'));
138
+ }
98
139
 
99
- //container
140
+ /**
141
+ * Initialize using the <tf-no-results> custom element
142
+ * @param {DOMElement} targetEl External container element
143
+ * @private
144
+ */
145
+ initCE(targetEl) {
146
+ const host = document.createElement('tf-no-results');
147
+ host.className = this.cssClass;
148
+ host.setText('');
149
+ host.innerHTML = sanitizeHtml(this.content);
150
+
151
+ if (this.isExternal) {
152
+ targetEl.appendChild(host);
153
+ } else {
154
+ const dom = this.tf.dom();
155
+ dom.parentNode.insertBefore(host, dom.nextSibling);
156
+ }
157
+ this.cont = host;
158
+ }
159
+
160
+ /**
161
+ * Initialize using the legacy div container
162
+ * @param {DOMElement} targetEl External container element
163
+ * @private
164
+ */
165
+ initLegacy(targetEl) {
166
+ let target = targetEl || this.tf.dom();
100
167
  let cont = createElm('div');
101
168
  cont.className = this.cssClass;
102
169
  cont.innerHTML = this.content;
@@ -108,15 +175,6 @@ export class NoResults extends Feature {
108
175
  }
109
176
 
110
177
  this.cont = cont;
111
-
112
- // subscribe to after-filtering event
113
- this.emitter.on(
114
- ['initialized', 'after-filtering'],
115
- () => this.toggle()
116
- );
117
-
118
- /** @inherited */
119
- this.initialized = true;
120
178
  }
121
179
 
122
180
  /**
@@ -183,10 +241,14 @@ export class NoResults extends Feature {
183
241
  if (!this.initialized) {
184
242
  return;
185
243
  }
186
- removeElm(this.cont);
244
+ if (this.cont && this.cont.parentNode) {
245
+ removeElm(this.cont);
246
+ }
187
247
  this.cont = null;
188
- // unsubscribe to after-filtering event
189
- this.emitter.off(['after-filtering'], () => this.toggle());
248
+ if (this.boundToggle) {
249
+ this.emitter.off(TOGGLE_EVENTS, this.boundToggle);
250
+ this.boundToggle = null;
251
+ }
190
252
 
191
253
  this.initialized = false;
192
254
  }