Skip to content

Commit 4f3dd37

Browse files
authored
feat!: drop standalone legacy browser <script> & window object usage (#461)
* feat!: drop standalone legacy browser <script> & use of `window` object
1 parent 7b7b2f0 commit 4f3dd37

46 files changed

Lines changed: 633 additions & 689 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,29 +140,59 @@ with this code in place, we can now use the following CSP meta tag (which is wha
140140
> [!NOTE]
141141
> in our demo we are only adding `unsafe-inline` simply because we are using Vite (which is not CSP compliant in Dev mode), but the library should work nonetheless without `unsafe-inline`.
142142
143+
## Major Changes
144+
145+
### version 3.0
146+
- remove deprecated options
147+
- new Modern Look by using SVG icons
148+
149+
### version 4.0
150+
- build ESM-Only and drop CJS (CommonJS) build (aka `require()`)
151+
152+
### version 5.0
153+
154+
Locale management has been refactored to remove usage of the global `window` object. Locales are now provided via a modular registry and injected through options. This change affects how you load, switch, and reference locales. Also, the `multiple-select-` prefix has been removed from all locale import paths (single and merged) and no longer exists on the `window` object
155+
156+
**Migration Example:**
157+
158+
```diff
159+
// 1. load every locale individually, it could be import in 2 ways (named import OR import on window object)
160+
- // named import
161+
- import { Spanish } from 'multiple-select-vanilla/dist/locales/multiple-select-es-ES.js';
162+
- // OR default import
163+
- import 'multiple-select-vanilla/dist/locales/multiple-select-es-ES.js';
164+
+ // named import
165+
+ import { Spanish } from 'multiple-select-vanilla/dist/locales/es-ES.js';
166+
+ // OR default import
167+
+ import Spanish from 'multiple-select-vanilla/dist/locales/es-ES.js';
168+
169+
// 2. or load all locales at once
170+
- import 'multiple-select-vanilla/dist/locales/multiple-select-all-locales';
171+
+ // named import
172+
+ import { locales } from 'multiple-select-vanilla/dist/locales/all-locales.js';
173+
+ // OR default import
174+
+ import locales from 'multiple-select-vanilla/dist/locales/all-locales.js';
175+
```
176+
177+
See the [Example09](https://ghiscoding.github.io/multiple-select-vanilla/#/example09) for details on dynamic locale loading.
178+
143179
### Installation / Structure
144180
145-
There are multiple ways to install and use the library, you can see below the folder structure of the distribution files
146-
1. `dist/browser`: Standalone build which assigns `multipleSelect` on the `window.multipleSelect` object
147-
- browser standalone means that you can simply load it with `<script></script>` and then `multipleSelect('#mySelect')`
148-
- only ESM build (`.js`) are provided, you will need to load it with `<script type="module">`
149-
2. `esm`: to use as ESM with `import from 'multiple-select-vanilla'`
181+
The library is now ESM Only, the library does include optional locales that can be loaded through imports or you can use and define your own custom texts as well. Here's the full library structure of the project
150182
151183
```
152184
dist/
153-
browser/
154-
multiple-select.js # ESM build, use with: window.multipleSelect
155185
locales/
156-
multiple-select-all-locales.js # all-in-1 locales
186+
all-locales.js # all-in-1 locales
157187
..
158-
multiple-select-es-ES.js # Spanish locale
159-
multiple-select-fr-FR.js # French locale
188+
es-ES.js # Spanish locale
189+
fr-FR.js # French locale
160190
...
161-
styles/ # CSS and SASS Stylings
191+
styles/ # CSS and SASS Stylings
162192
css/
163193
sass/
164-
index.d.ts # d.ts Type Definitions
165-
multiple-select.js # ESM, used by: import from
194+
index.d.ts # d.ts Type Definitions
195+
index.js # ESM import
166196
```
167197
168198
### Used by
@@ -228,8 +258,4 @@ Before submitting a PR (pull request), please make sure that you followed the st
228258
<span>
229259
<a href="https://github.com/gibson552" class="Link" title="gibson552" target="_blank"><img src="https://avatars.githubusercontent.com/u/84058359?s=52&v=4" width="50" height="50" valign="middle" /></a>
230260
</span>
231-
&nbsp;
232-
<span>
233-
<a href="https://github.com/web-ascender" class="Link" title="Web Ascender" target="_blank"><img src="https://avatars.githubusercontent.com/u/832747?s=200&v=4" width="50" height="50" valign="middle" /></a>
234-
</span>
235261
</div>

packages/demo/src/examples/example09.html

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ <h2 class="bd-title">
1818
</span>
1919
</h2>
2020
<div class="demo-subtitle">
21-
Use <code>locale</code>to set the locale.
21+
Use <code>locale</code>to set the locale. <strong>Please note</strong> that the months themselves aren't being translated, but every
22+
other labels like "Select All", "OK", "Cancel", "Search", etc. are the ones being translated.
2223
</div>
2324
</div>
2425
</div>
2526

2627
<div>
2728
<div class="mb-3 row">
28-
<label class="col-sm-3">Locale Select </label>
29+
<label class="col-sm-4">Locale Select </label>
2930

30-
<div class="col-sm-9">
31+
<div class="col-sm-8">
3132
<select id="locale" class="full-width">
3233
<option value="en-US">English</option>
3334
<option value="fr-FR">French</option>
@@ -43,9 +44,9 @@ <h2 class="bd-title">
4344
</div>
4445

4546
<div class="mb-3 row">
46-
<label class="col-sm-3">Result Select </label>
47+
<label class="col-sm-4">Result Select </label>
4748

48-
<div class="col-sm-9">
49+
<div class="col-sm-8">
4950
<select id="dynamic-select" class="full-width" multiple="multiple">
5051
<option value="1">January</option>
5152
<option value="2">February</option>
@@ -62,13 +63,26 @@ <h2 class="bd-title">
6263
</select>
6364
</div>
6465
</div>
66+
<div class="row">
67+
<div style="background: #f7f7f7; padding: 10px">
68+
<pre>
69+
// ESM named import
70+
<span style="color:#cf222e">import</span> { locales } <span style="color:#cf222e">from</span> <span style="color:#0a3069">'multiple-select-vanilla/dist/locales/all-locales.js'</span>;
71+
<span style="color:#6639ba">multipleSelect</span>(<span style="color:#0a3069">'.select'</span>, {
72+
locales
73+
}</span>);
74+
</pre>
75+
</div>
76+
</div>
6577

6678
<hr>
6779

6880
<div class="my-5 row">
69-
<label class="col-sm-3">named Locale import (i.e. Spanish)</label>
81+
<label class="col-sm-4">
82+
named Locale import (e.g. <code>Spanish</code>)
83+
</label>
7084

71-
<div class="col-sm-9">
85+
<div class="col-sm-8">
7286
<select id="fixed-import" class="full-width" multiple="multiple">
7387
<option value="1">First</option>
7488
<option value="2">Second</option>
@@ -77,4 +91,15 @@ <h2 class="bd-title">
7791
</select>
7892
</div>
7993
</div>
94+
<div class="row">
95+
<div style="background: #f7f7f7; padding: 10px">
96+
<pre>
97+
// ESM named import
98+
<span style="color:#cf222e">import</span> { multipleSelect } <span style="color:#cf222e">from</span> <span style="color:#0a3069">'multiple-select-vanilla'</span>;
99+
<span style="color:#6639ba">multipleSelect</span>(<span style="color:#0a3069">'.select'</span>, {
100+
locale: <span style="color:#105fd7">Spanish</span>
101+
}</span>);
102+
</pre>
103+
</div>
104+
</div>
80105
</div>

packages/demo/src/examples/example09.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { type LocaleKey, type MultipleSelectInstance, multipleSelect } from 'multiple-select-vanilla';
22

33
// 1. load every locale individually, it could be import in 2 ways (named import OR import on window object)
4-
import { Spanish } from 'multiple-select-vanilla/dist/locales/multiple-select-es-ES'; // named import
5-
// import 'multiple-select-vanilla/dist/locales/multiple-select-es-ES'; // locale on window object
4+
import { Spanish } from 'multiple-select-vanilla/dist/locales/es-ES.js'; // named import
5+
// import 'multiple-select-vanilla/dist/locales/es-ES'; // locale on window object
66

77
// 2. or load all locales at once
8-
import 'multiple-select-vanilla/dist/locales/multiple-select-all-locales';
8+
import { locales } from 'multiple-select-vanilla/dist/locales/all-locales.js';
99

1010
export default class Example {
1111
ms0?: MultipleSelectInstance;
@@ -25,6 +25,7 @@ export default class Example {
2525
filter: true,
2626
showOkButton: true,
2727
dataTest: 'select1',
28+
locales,
2829
}) as MultipleSelectInstance;
2930

3031
this.ms2 = multipleSelect('#fixed-import', {

packages/demo/src/getting-started.html

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@ <h5>GitHub <i class="fa fa-link"></i></h5>
1616
<section>
1717
<h5>CDN</h5>
1818
<p>
19-
<a href="https://www.jsdelivr.com/" target="__blank">jsDelivr</a>&nbsp;graciously provide CDNs for many JavaScript libraries including
20-
Multiple-Select-Vanilla. Just use the following CDN links.
21-
</p>
22-
<p>
23-
The project now ships as ESM-Only, if you still wish to use the legacy CommonJS (CJS) format with <code>require()</code>, then use
24-
previous 3.x version.
19+
<a href="https://www.jsdelivr.com/" target="__blank">jsDelivr</a>
20+
graciously provide CDNs for many JavaScript libraries including Multiple-Select-Vanilla. Just use the following CDN links.
2521
</p>
2622

2723
<div style="background: #f7f7f7; padding: 10px">
2824
<pre>
29-
&lt;!-- Get latest compiled and minified CSS --&gt;
30-
&lt;link href=&quot;<span style="color:#0a3069">https://cdn.jsdelivr.net/npm/multiple-select-vanilla@4.3.5/dist/styles/css/multiple-select.css</span>&quot; rel=&quot;<span style="color:#0a3069">stylesheet</span>&quot;&gt;
31-
32-
&lt;!-- ESM import requires <span style="color:#d63384">type=&quot;module&quot;</span>, get latest compiled and minified JavaScript code --&gt;
33-
&lt;script type=&quot;module&quot; src=&quot;<span style="color:#0a3069">https://cdn.jsdelivr.net/npm/multiple-select-vanilla@4.3.5/dist/browser/multiple-select.js</span>&quot;&gt;&lt;/script&gt;
25+
&lt;script <span style="color:#207eb1">type</span>=&quot;<span style="color:#d7742d">module</span>&quot;&gt;
26+
// ESM Module import
27+
<span style="color:#cf222e">import</span> multipleSelect <span style="color:#cf222e">from</span> <span style="color:#0a3069">'https://cdn.jsdelivr.net/npm/multiple-select-vanilla@5.0.0/+esm'</span>;
28+
&lt;/script&gt;
29+
</pre>
3430
</div>
35-
36-
<quote>
37-
<b>Note:</b> the <code>dist/browser</code> location is the only one providing the <code>MultipleSelect</code> on the <code>window</code> object.
38-
</quote>
3931
</section>
4032

4133
<section>
@@ -92,4 +84,9 @@ <h5>CSS / SASS Styling Themes</h5>
9284
</pre>
9385
</div>
9486
</section>
87+
<h5>Legacy Versions</h5>
88+
<p>
89+
The project now ships as ESM-Only, if you still wish to use the legacy <code>&lt;script&gt;</code> standalone IIFE Script on the
90+
<code>window</code> object, then use the previous 4.x version.
91+
</p>
9592
</div>

packages/multiple-select-vanilla/README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { multipleSelect } from 'multiple-select-vanilla';
3737

3838
const ms = multipleSelect('.multiple-select', {
3939
data: ['First', 'Second'] // native string/number/boolean
40-
};
40+
});
4141

4242
const ms = multipleSelect('.multiple-select', {
4343
data: [
@@ -57,3 +57,39 @@ const ms = multipleSelect('.multiple-select', {
5757
## LICENSE
5858

5959
[MIT License](https://github.com/ghiscoding/multiple-select-vanilla/blob/main/LICENSE)
60+
61+
## Major Changes
62+
63+
### version 3.0
64+
- remove deprecated options
65+
- new Modern Look by using SVG icons
66+
67+
### version 4.0
68+
- build ESM-Only and drop CJS (CommonJS) build (aka `require()`)
69+
70+
### version 5.0
71+
72+
Locale management has been refactored to remove usage of the global `window` object. Locales are now provided via a modular registry and injected through options. This change affects how you load, switch, and reference locales. Also, the `multiple-select-` prefix has been removed from all locale import paths (single and merged) and no longer exists on the `window` object
73+
74+
**Migration Example:**
75+
76+
```diff
77+
// 1. load every locale individually, it could be import in 2 ways (named import OR import on window object)
78+
- // named import
79+
- import { Spanish } from 'multiple-select-vanilla/dist/locales/multiple-select-es-ES.js';
80+
- // OR default import
81+
- import 'multiple-select-vanilla/dist/locales/multiple-select-es-ES.js';
82+
+ // named import
83+
+ import { Spanish } from 'multiple-select-vanilla/dist/locales/es-ES.js';
84+
+ // OR default import
85+
+ import Spanish from 'multiple-select-vanilla/dist/locales/es-ES.js';
86+
87+
// 2. or load all locales at once
88+
- import 'multiple-select-vanilla/dist/locales/multiple-select-all-locales';
89+
+ // named import
90+
+ import { locales } from 'multiple-select-vanilla/dist/locales/all-locales.js';
91+
+ // OR default import
92+
+ import locales from 'multiple-select-vanilla/dist/locales/all-locales.js';
93+
```
94+
95+
See the [Example09](https://ghiscoding.github.io/multiple-select-vanilla/#/example09) for details on dynamic locale loading.

packages/multiple-select-vanilla/build-prod.mjs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,31 @@ import { globSync } from 'tinyglobby';
33

44
const buildFormats = ['esm'];
55
const localeFiles = globSync('src/locales/**/*.ts');
6-
const localeEntryPoints = [];
76

87
for (const format of buildFormats) {
98
runBuild({
109
format,
1110
outfile: `dist/index.js`,
1211
});
1312

14-
// build all locales
13+
// build all locales (short names, e.g. "es-ES.ts")
1514
for (const localeFile of localeFiles) {
16-
// eslint-disable-next-line no-unused-vars
17-
const [_, locale] = localeFile.match(/multiple-select-(.*)\.ts$/) || [];
18-
if (locale && locale.length === 5) {
19-
localeEntryPoints.push(`src/locales/multiple-select-${locale}.ts`);
15+
const match = localeFile.match(/src\/locales\/(..-..).ts$/);
16+
if (match?.[1] && !['index', 'all-locales'].includes(match[1])) {
17+
const locale = match[1];
2018
runBuild({
21-
entryPoints: [`src/locales/multiple-select-${locale}.ts`],
19+
entryPoints: [localeFile],
2220
format,
23-
outfile: `dist/locales/multiple-select-${locale}.js`,
21+
outfile: `dist/locales/${locale}.js`,
2422
});
2523
}
2624
}
2725

28-
// also merge all Locales into a single file "multiple-select-all-locales.js"
26+
// also merge all Locales into a single file "all-locales.js" (the registry)
2927
runBuild({
30-
entryPoints: ['./src/locales/all-locales-index.ts'],
28+
entryPoints: ['./src/locales/all-locales.ts'],
3129
format,
32-
outfile: `dist/locales/multiple-select-all-locales.js`,
33-
});
34-
35-
// finally, create a regular bundle as a standalone which will be accessible as MultipleSelect from the global window object
36-
// this file is basically a legacy alternative to import via a <script> tag
37-
runBuild({
38-
format,
39-
globalName: 'MultipleSelect',
40-
outfile: `dist/browser/multiple-select.js`,
30+
outfile: `dist/locales/all-locales.js`,
4131
});
4232
}
4333

packages/multiple-select-vanilla/build-watch.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { exec, execSync } from 'node:child_process';
2+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
23
import path from 'node:path';
3-
import { copyfiles } from 'native-copyfiles';
4+
45
import { buildSync } from 'esbuild';
5-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
6+
import { copyfiles } from 'native-copyfiles';
67
import { compile as sassCompile } from 'sass';
78

89
const env = process.env.NODE_ENV;
@@ -33,11 +34,11 @@ function runBuild(options) {
3334
}
3435

3536
function runMergedLocaleBuild() {
36-
// merge all Locales into a single file "multiple-select-all-locales.js"
37+
// merge all Locales into a single file "all-locales.js"
3738
runBuild({
38-
entryPoints: ['./src/locales/all-locales-index.ts'],
39+
entryPoints: ['./src/locales/all-locales.ts'],
3940
format: 'esm',
40-
outfile: 'dist/locales/multiple-select-all-locales.js',
41+
outfile: 'dist/locales/all-locales.js',
4142
});
4243
}
4344

@@ -57,12 +58,13 @@ async function runCompilation(changedFiles) {
5758
}
5859
if (changedFile.includes('locales')) {
5960
// rebuild changed locale and also merged locale into a single locale
60-
const [_, locale] = changedFile.match(/locales[\\/]multiple-select-(.*)\.ts$/) || [];
61-
if (locale?.length === 5) {
61+
const match = changedFile.match(/locales[\\/](..-..).ts$/);
62+
if (match?.[1] && !['index', 'all-locales'].includes(match[1])) {
63+
const locale = match[1];
6264
runBuild({
63-
entryPoints: [`src/locales/multiple-select-${locale}.ts`],
65+
entryPoints: [`src/locales/${locale}.ts`],
6466
format: 'esm',
65-
outfile: `dist/locales/multiple-select-${locale}.js`,
67+
outfile: `dist/locales/${locale}.js`,
6668
});
6769
}
6870
runMergedLocaleBuild();

packages/multiple-select-vanilla/index.d.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)