tablefilter 0.7.4 → 0.7.5

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 (75) hide show
  1. package/.gitattributes +16 -0
  2. package/.github/workflows/build-deploy.yml +30 -2
  3. package/.github/workflows/opencode-review.yml +104 -0
  4. package/.github/workflows/opencode.yml +34 -0
  5. package/ROADMAP/README.md +6 -1
  6. package/ROADMAP/content-projection-parity.md +162 -0
  7. package/ROADMAP/hybrid-migration-strategy.md +48 -7
  8. package/ROADMAP/key-decisions-review.md +5 -3
  9. package/ROADMAP/preliminary-and-milestone-0.8.0-plan.md +11 -12
  10. package/ROADMAP/v1-webcomponents-investigation.md +6 -1
  11. package/dist/starter.html +2 -2
  12. package/dist/tablefilter/style/colsVisibility.css +1 -1
  13. package/dist/tablefilter/style/filtersVisibility.css +1 -1
  14. package/dist/tablefilter/style/tablefilter.css +1 -1
  15. package/dist/tablefilter/style/themes/default/default.css +1 -1
  16. package/dist/tablefilter/style/themes/mytheme/mytheme.css +1 -1
  17. package/dist/tablefilter/style/themes/skyblue/skyblue.css +1 -1
  18. package/dist/tablefilter/style/themes/transparent/transparent.css +1 -1
  19. package/dist/tablefilter/tablefilter.js +1 -1
  20. package/dist/tablefilter/tablefilter.vite.js +4 -0
  21. package/dist/tablefilter/tf-1-a5c3a73bd559e47dd5a2.js +1 -0
  22. package/dist/tablefilter/tf-2-3a936d22b849361acff5.js +6 -0
  23. package/dist/tablefilter.cjs.js +4 -0
  24. package/dist/tablefilter.esm.js +7278 -0
  25. package/dist/tablefilter.umd.js +4 -0
  26. package/package.json +12 -5
  27. package/playwright.config.js +25 -0
  28. package/scripts/check-css-tokens.js +65 -0
  29. package/src/components/table-filter.js +243 -0
  30. package/src/components/tf-clear-button.js +95 -0
  31. package/src/components/tf-rows-counter.js +82 -0
  32. package/src/components/tf-status.js +106 -0
  33. package/src/modules/clearButton.js +65 -11
  34. package/src/modules/rowsCounter.js +48 -25
  35. package/src/modules/statusBar.js +62 -30
  36. package/src/sanitize.js +25 -0
  37. package/static/style/active-header.styl +2 -2
  38. package/static/style/alternating-rows.styl +2 -2
  39. package/static/style/config.styl +18 -18
  40. package/static/style/custom-properties.styl +43 -0
  41. package/static/style/ezedittable.styl +12 -12
  42. package/static/style/filter-checklist.styl +3 -3
  43. package/static/style/filters.styl +8 -8
  44. package/static/style/grid-layout.styl +9 -9
  45. package/static/style/help.styl +9 -9
  46. package/static/style/keyword.styl +1 -1
  47. package/static/style/loader.styl +3 -3
  48. package/static/style/noresults.styl +1 -1
  49. package/static/style/paging.styl +1 -1
  50. package/static/style/rows-counter.styl +1 -1
  51. package/static/style/status-bar.styl +1 -4
  52. package/static/style/tablefilter.styl +1 -0
  53. package/static/style/themes/skyblue/skyblue.styl +2 -2
  54. package/static/style/themes/transparent/transparent.styl +2 -2
  55. package/static/style/toolbar.styl +1 -1
  56. package/static/templates/table-filter.html +40 -0
  57. package/test/playwright/axe.baseline.spec.js +34 -0
  58. package/test/playwright/axe.statusbar.spec.js +35 -0
  59. package/test/playwright/axeScan.js +42 -0
  60. package/test/playwright/ce-bridge.spec.js +167 -0
  61. package/test/playwright/qunit.all.spec.js +10 -0
  62. package/test/playwright/qunit.single.spec.js +14 -0
  63. package/test/playwright/qunitSuite.js +56 -0
  64. package/test/playwright/table-filter.config.spec.js +265 -0
  65. package/test/playwright/table-filter.demo.spec.js +60 -0
  66. package/test/playwright/table-filter.element.spec.js +477 -0
  67. package/test/playwright/tf-clear-button.spec.js +135 -0
  68. package/test/playwright/tf-rows-counter.spec.js +172 -0
  69. package/test/playwright/tf-status.spec.js +258 -0
  70. package/test/test-clear-button.js +1 -0
  71. package/test/test-rows-counter.js +2 -0
  72. package/test/test-status-bar.js +3 -0
  73. package/vite.config.js +71 -0
  74. package/webpack.config.js +12 -0
  75. package/dist/tablefilter/tf-1-d2360db09a424b1ed633.js +0 -1
@@ -0,0 +1,172 @@
1
+ // Component gate (#909): the <tf-rows-counter> element registers an
2
+ // open shadow root exposing the `label`/`count` parts and renders the
3
+ // `text`/`count` attributes statically. Per the theming model
4
+ // (--tf-* custom properties + ::part()), it ships structure and hooks
5
+ // only: no invented classes and no baked-in presentational CSS. The
6
+ // RowsCounter bridge (#910) is a separate ticket. Fails CI on regression.
7
+ const { test, expect } = require('@playwright/test');
8
+
9
+ const FIXTURE = '/test/test-emitter.html';
10
+ const COMPONENT = '/src/components/tf-rows-counter.js';
11
+
12
+ test('registers an open shadow root exposing the label/count parts',
13
+ async ({ page }) => {
14
+ await page.goto(FIXTURE);
15
+
16
+ const result = await page.evaluate(async (component) => {
17
+ await import(component);
18
+ const defined = Boolean(customElements.get('tf-rows-counter'));
19
+ const el = document.createElement('tf-rows-counter');
20
+ document.body.appendChild(el);
21
+ const sr = el.shadowRoot;
22
+ const nodes = sr ? Array.from(sr.querySelectorAll('*')) : [];
23
+ return {
24
+ defined,
25
+ hasShadow: Boolean(sr),
26
+ mode: sr && sr.mode,
27
+ parts: sr ? Array.from(sr.querySelectorAll('[part]'))
28
+ .map((n) => n.getAttribute('part')) : [],
29
+ leakedToLightDom: el.querySelector('[part=label]') !== null,
30
+ classless: nodes.every((n) => !n.hasAttribute('class')),
31
+ styleless: nodes.every((n) => n.tagName !== 'STYLE')
32
+ };
33
+ }, COMPONENT);
34
+
35
+ expect(result.defined).toBe(true);
36
+ expect(result.hasShadow).toBe(true);
37
+ expect(result.mode).toBe('open');
38
+ expect(result.parts).toEqual(['label', 'count']);
39
+ expect(result.leakedToLightDom).toBe(false);
40
+ expect(result.classless).toBe(true);
41
+ expect(result.styleless).toBe(true);
42
+ });
43
+
44
+ test('renders the text and count attributes into the shadow parts',
45
+ async ({ page }) => {
46
+ await page.goto(FIXTURE);
47
+
48
+ const result = await page.evaluate(async (component) => {
49
+ await import(component);
50
+ const el = document.createElement('tf-rows-counter');
51
+ el.setAttribute('text', 'Rows:');
52
+ el.setAttribute('count', '7');
53
+ document.body.appendChild(el);
54
+
55
+ const sr = el.shadowRoot;
56
+ const read = () => ({
57
+ label: sr.querySelector('[part=label]').textContent,
58
+ count: sr.querySelector('[part=count]').textContent
59
+ });
60
+ const initial = read();
61
+
62
+ el.setAttribute('count', '4');
63
+ const updated = read();
64
+
65
+ el.removeAttribute('text');
66
+ const cleared = read();
67
+
68
+ return { initial, updated, cleared };
69
+ }, COMPONENT);
70
+
71
+ expect(result.initial).toEqual({ label: 'Rows:', count: '7' });
72
+ expect(result.updated).toEqual({ label: 'Rows:', count: '4' });
73
+ expect(result.cleared).toEqual({ label: '', count: '4' });
74
+ });
75
+
76
+ test('setCount() sets and clears the rendered count', async ({ page }) => {
77
+ await page.goto(FIXTURE);
78
+
79
+ const result = await page.evaluate(async (component) => {
80
+ await import(component);
81
+ const el = document.createElement('tf-rows-counter');
82
+ document.body.appendChild(el);
83
+ const count = () =>
84
+ el.shadowRoot.querySelector('[part=count]').textContent;
85
+
86
+ el.setCount('Filtering...');
87
+ const set = count();
88
+ el.setCount('');
89
+ const empty = count();
90
+ el.setCount();
91
+ const missing = count();
92
+ el.setCount(0);
93
+ const zero = count();
94
+
95
+ return { set, empty, missing, zero };
96
+ }, COMPONENT);
97
+
98
+ expect(result.set).toBe('Filtering...');
99
+ expect(result.empty).toBe('');
100
+ expect(result.missing).toBe('');
101
+ expect(result.zero).toBe('0');
102
+ });
103
+
104
+ test('exposes ::part() styling hooks for theming', async ({ page }) => {
105
+ await page.goto(FIXTURE);
106
+
107
+ const result = await page.evaluate(async (component) => {
108
+ await import(component);
109
+ const el = document.createElement('tf-rows-counter');
110
+ el.setAttribute('text', 'x');
111
+ el.setAttribute('count', 'y');
112
+ document.body.appendChild(el);
113
+
114
+ const style = document.createElement('style');
115
+ style.textContent = `
116
+ tf-rows-counter::part(label) { color: rgb(1, 2, 3); }
117
+ tf-rows-counter::part(count) { color: rgb(9, 8, 7); }
118
+ `;
119
+ document.head.appendChild(style);
120
+
121
+ const label = el.shadowRoot.querySelector('[part=label]');
122
+ const cnt = el.shadowRoot.querySelector('[part=count]');
123
+ return {
124
+ label: getComputedStyle(label).color,
125
+ count: getComputedStyle(cnt).color
126
+ };
127
+ }, COMPONENT);
128
+
129
+ expect(result.label).toBe('rgb(1, 2, 3)');
130
+ expect(result.count).toBe('rgb(9, 8, 7)');
131
+ });
132
+
133
+ // Live region: the counter announces count changes (ROADMAP: live region).
134
+ test('connects as a polite ARIA status live region', async ({ page }) => {
135
+ await page.goto(FIXTURE);
136
+
137
+ const result = await page.evaluate(async (component) => {
138
+ await import(component);
139
+ const el = document.createElement('tf-rows-counter');
140
+ el.setAttribute('aria-live', 'off');
141
+ document.body.appendChild(el);
142
+ return {
143
+ role: el.getAttribute('role'),
144
+ live: el.getAttribute('aria-live'),
145
+ atomic: el.getAttribute('aria-atomic'),
146
+ nestedAria: el.shadowRoot.querySelectorAll(
147
+ '[role], [aria-live], [aria-atomic]'
148
+ ).length
149
+ };
150
+ }, COMPONENT);
151
+
152
+ expect(result.role).toBe('status');
153
+ expect(result.live).toBe('polite');
154
+ expect(result.atomic).toBe('true');
155
+ expect(result.nestedAria).toBe(0);
156
+ });
157
+
158
+ test('is exposed to assistive tech as one status region', async ({ page }) => {
159
+ await page.goto(FIXTURE);
160
+
161
+ await page.evaluate(async (component) => {
162
+ await import(component);
163
+ const el = document.createElement('tf-rows-counter');
164
+ el.setAttribute('text', 'Rows:');
165
+ el.setAttribute('count', '42');
166
+ document.body.appendChild(el);
167
+ }, COMPONENT);
168
+
169
+ await expect(page.locator('tf-rows-counter')).toHaveRole('status');
170
+ const statusRegions = page.getByRole('status');
171
+ await expect(statusRegions).toHaveCount(1);
172
+ });
@@ -0,0 +1,258 @@
1
+ // Component gates (#905 scaffold, #906 live region): the <tf-status>
2
+ // element registers an open shadow root exposing the `label`/`message`
3
+ // parts and renders the `text`/`message` attributes statically, and its
4
+ // host connects as a polite ARIA status region. Per the theming model
5
+ // (--tf-* custom properties + ::part()), it ships structure and hooks
6
+ // only: no invented classes and no baked-in presentational CSS. The
7
+ // StatusBar bridge (#907) is a separate ticket. Fails CI on regression.
8
+ const { test, expect } = require('@playwright/test');
9
+
10
+ const FIXTURE = '/test/test-emitter.html';
11
+ const COMPONENT = '/src/components/tf-status.js';
12
+
13
+ test('registers an open shadow root exposing the label/message parts',
14
+ async ({ page }) => {
15
+ await page.goto(FIXTURE);
16
+
17
+ const result = await page.evaluate(async (component) => {
18
+ await import(component);
19
+ const defined = Boolean(customElements.get('tf-status'));
20
+ const el = document.createElement('tf-status');
21
+ document.body.appendChild(el);
22
+ const sr = el.shadowRoot;
23
+ const nodes = sr ? Array.from(sr.querySelectorAll('*')) : [];
24
+ return {
25
+ defined,
26
+ hasShadow: Boolean(sr),
27
+ mode: sr && sr.mode,
28
+ parts: sr ? Array.from(sr.querySelectorAll('[part]'))
29
+ .map((n) => n.getAttribute('part')) : [],
30
+ leakedToLightDom: el.querySelector('[part=label]') !== null,
31
+ classless: nodes.every((n) => !n.hasAttribute('class')),
32
+ styleless: nodes.every((n) => n.tagName !== 'STYLE')
33
+ };
34
+ }, COMPONENT);
35
+
36
+ expect(result.defined).toBe(true);
37
+ expect(result.hasShadow).toBe(true);
38
+ expect(result.mode).toBe('open');
39
+ expect(result.parts).toEqual(['label', 'message']);
40
+ expect(result.leakedToLightDom).toBe(false);
41
+ // The component ships no classes and no presentational styles;
42
+ // themes style the parts via --tf-* tokens and ::part().
43
+ expect(result.classless).toBe(true);
44
+ expect(result.styleless).toBe(true);
45
+ });
46
+
47
+ test('renders the text and message attributes into the shadow parts',
48
+ async ({ page }) => {
49
+ await page.goto(FIXTURE);
50
+
51
+ const result = await page.evaluate(async (component) => {
52
+ await import(component);
53
+ const el = document.createElement('tf-status');
54
+ el.setAttribute('text', 'Rows:');
55
+ el.setAttribute('message', '1 176');
56
+ document.body.appendChild(el);
57
+
58
+ const sr = el.shadowRoot;
59
+ const read = () => ({
60
+ label: sr.querySelector('[part=label]').textContent,
61
+ message: sr.querySelector('[part=message]').textContent
62
+ });
63
+ const initial = read();
64
+
65
+ el.setAttribute('message', '42');
66
+ const updated = read();
67
+
68
+ el.removeAttribute('text');
69
+ const cleared = read();
70
+
71
+ return { initial, updated, cleared };
72
+ }, COMPONENT);
73
+
74
+ expect(result.initial).toEqual({ label: 'Rows:', message: '1 176' });
75
+ expect(result.updated).toEqual({ label: 'Rows:', message: '42' });
76
+ expect(result.cleared).toEqual({ label: '', message: '42' });
77
+ });
78
+
79
+ test('setMessage() sets and clears the rendered message',
80
+ async ({ page }) => {
81
+ await page.goto(FIXTURE);
82
+
83
+ const result = await page.evaluate(async (component) => {
84
+ await import(component);
85
+ const el = document.createElement('tf-status');
86
+ document.body.appendChild(el);
87
+ const msg = () =>
88
+ el.shadowRoot.querySelector('[part=message]').textContent;
89
+
90
+ el.setMessage('Filtering...');
91
+ const set = msg();
92
+ el.setMessage('');
93
+ const empty = msg();
94
+ el.setMessage();
95
+ const missing = msg();
96
+ // A falsy non-string must render, not be dropped.
97
+ el.setMessage(0);
98
+ const zero = msg();
99
+
100
+ return { set, empty, missing, zero };
101
+ }, COMPONENT);
102
+
103
+ expect(result.set).toBe('Filtering...');
104
+ expect(result.empty).toBe('');
105
+ expect(result.missing).toBe('');
106
+ expect(result.zero).toBe('0');
107
+ });
108
+
109
+ // #1012: legacy StatusBar injected messages with innerHTML
110
+ // (`msgContainer.innerHTML = t`), so configured messages may contain
111
+ // markup. The message part must render it as HTML; the `text` label
112
+ // stays text (legacy used a text node for `text`). Exercises the real
113
+ // consumer entry point, `setMessage()`, not just the attribute.
114
+ test('renders setMessage() as HTML, but text as plain text',
115
+ async ({ page }) => {
116
+ await page.goto(FIXTURE);
117
+
118
+ const result = await page.evaluate(async (component) => {
119
+ await import(component);
120
+ const el = document.createElement('tf-status');
121
+ el.setAttribute('text', '<i>Rows:</i>');
122
+ el.setMessage('Filtering <b>data</b> &amp; more');
123
+ document.body.appendChild(el);
124
+
125
+ const sr = el.shadowRoot;
126
+ const label = sr.querySelector('[part=label]');
127
+ const msg = sr.querySelector('[part=message]');
128
+ return {
129
+ labelHasMarkup: label.querySelector('i') !== null,
130
+ labelText: label.textContent,
131
+ messageBold: msg.querySelector('b') &&
132
+ msg.querySelector('b').textContent,
133
+ messageText: msg.textContent
134
+ };
135
+ }, COMPONENT);
136
+
137
+ // label: markup escaped, rendered as text.
138
+ expect(result.labelHasMarkup).toBe(false);
139
+ expect(result.labelText).toBe('<i>Rows:</i>');
140
+ // message: markup parsed, entities decoded.
141
+ expect(result.messageBold).toBe('data');
142
+ expect(result.messageText).toBe('Filtering data & more');
143
+ });
144
+
145
+ // #1014 review: `message` is injected as HTML, so the config-derived
146
+ // markup is sanitised (DOMPurify) at the boundary. Ordinary markup
147
+ // survives; scripts, event handlers and javascript: URLs do not.
148
+ test('sanitises injected message HTML', async ({ page }) => {
149
+ await page.goto(FIXTURE);
150
+
151
+ const result = await page.evaluate(async (component) => {
152
+ await import(component);
153
+ const el = document.createElement('tf-status');
154
+ el.setMessage(
155
+ '<b>safe</b>' +
156
+ '<img src=x onerror="window.__xss=1">' +
157
+ '<script>window.__xss=2<\/script>' +
158
+ '<a href="javascript:window.__xss=3">link</a>'
159
+ );
160
+ document.body.appendChild(el);
161
+
162
+ const msg = el.shadowRoot.querySelector('[part=message]');
163
+ const img = msg.querySelector('img');
164
+ const link = msg.querySelector('a');
165
+ return {
166
+ xss: window.__xss,
167
+ bold: msg.querySelector('b') && msg.querySelector('b').textContent,
168
+ imgKept: img !== null,
169
+ imgHasHandler: img !== null && img.hasAttribute('onerror'),
170
+ scriptPresent: msg.querySelector('script') !== null,
171
+ linkHref: link && link.getAttribute('href')
172
+ };
173
+ }, COMPONENT);
174
+
175
+ expect(result.xss).toBeUndefined();
176
+ // Benign markup is preserved (BC).
177
+ expect(result.bold).toBe('safe');
178
+ expect(result.imgKept).toBe(true);
179
+ // Dangerous constructs are stripped.
180
+ expect(result.imgHasHandler).toBe(false);
181
+ expect(result.scriptPresent).toBe(false);
182
+ expect(result.linkHref == null ||
183
+ !result.linkHref.startsWith('javascript:')).toBe(true);
184
+ });
185
+
186
+ test('exposes ::part() styling hooks for theming', async ({ page }) => {
187
+ await page.goto(FIXTURE);
188
+
189
+ const result = await page.evaluate(async (component) => {
190
+ await import(component);
191
+ const el = document.createElement('tf-status');
192
+ el.setAttribute('text', 'x');
193
+ el.setAttribute('message', 'y');
194
+ document.body.appendChild(el);
195
+
196
+ const style = document.createElement('style');
197
+ style.textContent = `
198
+ tf-status::part(label) { color: rgb(1, 2, 3); }
199
+ tf-status::part(message) { color: rgb(9, 8, 7); }
200
+ `;
201
+ document.head.appendChild(style);
202
+
203
+ const label = el.shadowRoot.querySelector('[part=label]');
204
+ const msg = el.shadowRoot.querySelector('[part=message]');
205
+ return {
206
+ label: getComputedStyle(label).color,
207
+ message: getComputedStyle(msg).color
208
+ };
209
+ }, COMPONENT);
210
+
211
+ expect(result.label).toBe('rgb(1, 2, 3)');
212
+ expect(result.message).toBe('rgb(9, 8, 7)');
213
+ });
214
+
215
+ // #906: the host is the live region. `role="status"` implies polite and
216
+ // atomic, so they are set (not defaulted) on connect and a consumer's
217
+ // value is corrected; the shadow parts stay ARIA-free so a message
218
+ // change is announced once, not twice.
219
+ test('connects as a polite ARIA status live region', async ({ page }) => {
220
+ await page.goto(FIXTURE);
221
+
222
+ const result = await page.evaluate(async (component) => {
223
+ await import(component);
224
+ const el = document.createElement('tf-status');
225
+ // Enforcement, not a default: a wrong consumer value is fixed.
226
+ el.setAttribute('aria-live', 'off');
227
+ document.body.appendChild(el);
228
+ return {
229
+ role: el.getAttribute('role'),
230
+ live: el.getAttribute('aria-live'),
231
+ atomic: el.getAttribute('aria-atomic'),
232
+ nestedAria: el.shadowRoot.querySelectorAll(
233
+ '[role], [aria-live], [aria-atomic]'
234
+ ).length
235
+ };
236
+ }, COMPONENT);
237
+
238
+ expect(result.role).toBe('status');
239
+ expect(result.live).toBe('polite');
240
+ expect(result.atomic).toBe('true');
241
+ expect(result.nestedAria).toBe(0);
242
+ });
243
+
244
+ test('is exposed to assistive tech as a single status region',
245
+ async ({ page }) => {
246
+ await page.goto(FIXTURE);
247
+
248
+ await page.evaluate(async (component) => {
249
+ await import(component);
250
+ const el = document.createElement('tf-status');
251
+ el.setAttribute('text', 'Rows:');
252
+ el.setAttribute('message', '42');
253
+ document.body.appendChild(el);
254
+ }, COMPONENT);
255
+
256
+ await expect(page.locator('tf-status')).toHaveRole('status');
257
+ await expect(page.getByRole('status')).toHaveCount(1);
258
+ });
@@ -127,6 +127,7 @@ test('Remove UI', function() {
127
127
  clearButton.destroy();
128
128
  var btnResetEl = tf.feature('clearButton').element;
129
129
  deepEqual(btnResetEl, null, 'Clear button is removed');
130
+ deepEqual(clearButton.container, null, 'container removed');
130
131
  });
131
132
 
132
133
  test('Re-set UI with no icons and text button', function() {
@@ -34,6 +34,8 @@ test('Properties', function() {
34
34
  test('Can destroy', function() {
35
35
  rowsCounter.destroy();
36
36
  deepEqual(rowsCounter.initialized, false, 'not initialised');
37
+ deepEqual(rowsCounter.container, null, 'container removed');
38
+ deepEqual(rowsCounter.label, null, 'label removed');
37
39
  });
38
40
  test('Can reset', function() {
39
41
  rowsCounter.reset();
@@ -76,6 +76,9 @@ test('Properties', function() {
76
76
  test('Can destroy', function() {
77
77
  statusBar.destroy();
78
78
  deepEqual(statusBar.initialized, false, 'not initialised');
79
+ deepEqual(statusBar.container, null, 'container removed');
80
+ deepEqual(statusBar.msgContainer, null, 'message container removed');
81
+ deepEqual(statusBar.labelContainer, null, 'label container removed');
79
82
  });
80
83
  test('Can reset', function() {
81
84
  statusBar.reset();
package/vite.config.js ADDED
@@ -0,0 +1,71 @@
1
+ // Library outputs: ESM (#887), CJS (#888), UMD (#889); legacy layout
2
+ // (#890) copies the UMD bundle to the historic dist/tablefilter/ path.
3
+ // CommonJS because package.json has no "type": "module".
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const pkg = require('./package.json');
7
+
8
+ const srcDir = path.join(__dirname, 'src').replace(/\\/g, '/') + '/';
9
+
10
+ // Same {VERSION}/{AUTHOR} substitution as webpack.config.js
11
+ const replacePlaceholders = () => ({
12
+ name: 'tablefilter-placeholders',
13
+ transform(code, id) {
14
+ if (!id.replace(/\\/g, '/').startsWith(srcDir)) {
15
+ return null;
16
+ }
17
+ return code
18
+ .replace(/{VERSION}/ig, pkg.version)
19
+ .replace(/{AUTHOR}/ig, pkg.author.name);
20
+ }
21
+ });
22
+
23
+ // Stage the Vite UMD bundle next to the webpack output without overwriting
24
+ // it: the published dist/tablefilter/tablefilter.js must stay the webpack
25
+ // flat-global build until consumers migrate to the window.TableFilter
26
+ // namespace. The directory's other assets (style/, chunks) are untouched.
27
+ // TODO(#965): point this copy at tablefilter.js and drop the .vite.js
28
+ // provisional name once tests/demos migrate.
29
+ const copyLegacyDist = () => ({
30
+ name: 'tablefilter-legacy-dist',
31
+ writeBundle(options) {
32
+ if (options.format !== 'umd') {
33
+ return;
34
+ }
35
+ const outDir = path.join(__dirname, 'dist');
36
+ const legacyDir = path.join(outDir, 'tablefilter');
37
+ fs.mkdirSync(legacyDir, {recursive: true});
38
+ fs.copyFileSync(
39
+ path.join(outDir, 'tablefilter.umd.js'),
40
+ path.join(legacyDir, 'tablefilter.vite.js')
41
+ );
42
+ }
43
+ });
44
+
45
+ module.exports = {
46
+ plugins: [replacePlaceholders(), copyLegacyDist()],
47
+ build: {
48
+ lib: {
49
+ entry: path.join(__dirname, 'src/tablefilter.js'),
50
+ // name is required for the UMD build, it sets window.TableFilter
51
+ name: 'TableFilter',
52
+ formats: ['es', 'cjs', 'umd'],
53
+ fileName: (format) => {
54
+ switch (format) {
55
+ case 'es':
56
+ return 'tablefilter.esm.js';
57
+ case 'cjs':
58
+ return 'tablefilter.cjs.js';
59
+ default:
60
+ return 'tablefilter.umd.js';
61
+ }
62
+ }
63
+ },
64
+ // dist/ also holds the webpack build output, do not wipe it
65
+ emptyOutDir: false
66
+ },
67
+ server: {
68
+ host: '0.0.0.0',
69
+ port: 8080
70
+ }
71
+ };
package/webpack.config.js CHANGED
@@ -34,6 +34,18 @@ module.exports = {
34
34
  presets: ['@babel/env']
35
35
  },
36
36
  loader: 'babel-loader'
37
+ }, {
38
+ // DOMPurify (used by the leaf components via src/sanitize.js)
39
+ // ships ES6. webpack builds a context over all of src/ for the
40
+ // dynamic `require` in TableFilter.loadExtension(), which drags
41
+ // it into the legacy bundle, so it must be transpiled to ES5
42
+ // for UglifyJs.
43
+ test: /[\\/]node_modules[\\/]dompurify[\\/].*\.js$/,
44
+ loader: 'babel-loader',
45
+ options: {
46
+ compact: false,
47
+ presets: ['@babel/env']
48
+ }
37
49
  }, {
38
50
  test: path.join(__dirname, 'src'),
39
51
  loader: StringReplacePlugin.replace({