activeadmin-tom_select 4.1.0 → 4.1.1

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/fix-tests.md +1 -1
  3. data/.github/workflows/ci.yml +3 -4
  4. data/.github/workflows/npm-publish.yml +3 -3
  5. data/.rubocop.yml +1 -1
  6. data/AGENTS.md +2 -2
  7. data/CHANGELOG.md +19 -1
  8. data/Gemfile.lock +85 -79
  9. data/README.md +20 -18
  10. data/activeadmin-tom_select.gemspec +3 -3
  11. data/docs/guide-update-your-app.md +198 -25
  12. data/docs/update-tom-select.md +322 -158
  13. data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +11 -11
  14. data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +66 -64
  15. data/lib/activeadmin/inputs/filters/searchable_select_input.rb +5 -12
  16. data/lib/activeadmin/inputs/filters/tom_select_input.rb +19 -0
  17. data/lib/activeadmin/inputs/searchable_select_input.rb +5 -11
  18. data/lib/activeadmin/inputs/tom_select_input.rb +16 -0
  19. data/lib/activeadmin/tom_select/engine.rb +3 -1
  20. data/lib/activeadmin/tom_select/option_collection.rb +1 -1
  21. data/lib/activeadmin/tom_select/resource_dsl_extension.rb +1 -1
  22. data/lib/activeadmin/tom_select/resource_extension.rb +1 -1
  23. data/lib/activeadmin/tom_select/select_input_extension.rb +14 -5
  24. data/lib/activeadmin/tom_select/version.rb +2 -2
  25. data/lib/activeadmin/tom_select.rb +3 -3
  26. data/lib/generators/active_admin/tom_select/install/install_generator.rb +5 -5
  27. data/npm-package/package-lock.json +2 -2
  28. data/npm-package/package.json +2 -2
  29. data/npm-package/src/index.js +1 -3
  30. data/npm-package/src/tom-select-tailwind.css +26 -20
  31. data/sonar-project.properties +5 -4
  32. data/spec/features/form_input_spec.rb +2 -2
  33. data/spec/features/inline_ajax_setting_spec.rb +1 -1
  34. data/spec/internal/Gemfile.lock +1 -1
  35. data/spec/internal/app/admin/articles.rb +28 -0
  36. data/spec/internal/app/assets/config/manifest.js +2 -1
  37. data/spec/internal/app/assets/stylesheets/active_admin.tailwind.css +1 -1
  38. data/spec/internal/app/assets/stylesheets/application.tailwind.css +0 -15
  39. data/spec/internal/app/javascript/active_admin.js +2 -4
  40. data/spec/internal/db/schema.rb +3 -1
  41. data/spec/internal/db/seeds.rb +4 -7
  42. data/spec/internal/package-lock.json +3 -3
  43. data/spec/internal/package.json +1 -1
  44. data/spec/internal/yarn.lock +1 -1
  45. data/spec/support/reset_settings.rb +1 -1
  46. metadata +5 -2
@@ -12,7 +12,10 @@ echo "gem 'activeadmin-tom_select', '~> 4.1.0'" >> Gemfile
12
12
  bundle install
13
13
 
14
14
  # Install NPM packages
15
- npm install @rocket-sensei/activeadmin-tom_select tom-select
15
+ npm install activeadmin-tom_select tom-select
16
+
17
+ # Install PostCSS plugins (REQUIRED for CSS imports to work)
18
+ npm install postcss postcss-import postcss-nesting autoprefixer
16
19
 
17
20
  # Then follow Step 3 and onward below
18
21
  ```
@@ -21,11 +24,11 @@ npm install @rocket-sensei/activeadmin-tom_select tom-select
21
24
 
22
25
  Our fork provides:
23
26
  - ✅ Full ActiveAdmin 4.0 support
24
- - ✅ Rails 8 and Propshaft compatibility
27
+ - ✅ Rails 8 and Propshaft compatibility
25
28
  - ✅ Modern JavaScript bundler support (esbuild/webpack/importmap)
26
29
  - ✅ **Tom Select** instead of Select2 (no jQuery dependency!)
27
30
  - ✅ Virtual scroll for large datasets with pagination
28
- - ✅ Proper NPM package distribution under @rocket-sensei scope
31
+ - ✅ Proper NPM package distribution as activeadmin-tom_select
29
32
  - ✅ Improved test suite with static ActiveAdmin registrations
30
33
  - ✅ Active maintenance and support
31
34
 
@@ -67,12 +70,19 @@ Remove old packages and install the new ones:
67
70
 
68
71
  ```bash
69
72
  # Remove old packages if present
70
- npm uninstall @codevise/activeadmin-searchable_select @rocket-sensei/activeadmin-searchable_select jquery select2
73
+ npm uninstall @codevise/activeadmin-searchable_select activeadmin-searchable_select jquery select2
71
74
 
72
75
  # Install new packages (Tom Select instead of Select2)
73
- npm install @rocket-sensei/activeadmin-tom_select tom-select
76
+ npm install activeadmin-tom_select tom-select
77
+
78
+ # CRITICAL: Install PostCSS plugins for CSS imports to work
79
+ npm install postcss postcss-import postcss-nesting autoprefixer
74
80
  ```
75
81
 
82
+ **Note:** The `activeadmin-tom_select` package includes both JavaScript and CSS files:
83
+ - JavaScript: Auto-initialization and helper functions
84
+ - CSS: Tailwind-optimized Tom Select styles at `activeadmin-tom_select/src/tom-select-tailwind.css`
85
+
76
86
  ### Step 3: Update JavaScript Imports
77
87
 
78
88
  Update your `app/javascript/active_admin.js`:
@@ -87,7 +97,7 @@ import TomSelect from 'tom-select';
87
97
  window.TomSelect = TomSelect;
88
98
 
89
99
  // Import and auto-initialize searchable selects
90
- import { setupAutoInit } from '@rocket-sensei/activeadmin-tom_select';
100
+ import { setupAutoInit } from 'activeadmin-tom_select';
91
101
  setupAutoInit();
92
102
  ```
93
103
 
@@ -101,7 +111,7 @@ import TomSelect from 'tom-select';
101
111
  window.TomSelect = TomSelect;
102
112
 
103
113
  // Import the initialization function
104
- import { initSearchableSelects } from '@rocket-sensei/activeadmin-tom_select';
114
+ import { initSearchableSelects } from 'activeadmin-tom_select';
105
115
 
106
116
  // Initialize manually when needed
107
117
  document.addEventListener('DOMContentLoaded', function() {
@@ -110,18 +120,45 @@ document.addEventListener('DOMContentLoaded', function() {
110
120
  });
111
121
  ```
112
122
 
113
- ### Step 4: Add Tom Select CSS
123
+ ### Step 4: Configure CSS Build Process (For Tailwind CSS with ActiveAdmin 4)
124
+
125
+ ## ⚠️ CRITICAL CSS SETUP REQUIREMENTS
126
+
127
+ **IMPORTANT**: The CSS build process has very specific requirements that must be followed exactly:
128
+
129
+ 1. **Input file MUST use `.tailwind.css` extension** (not `.css`)
130
+ 2. **MUST have PostCSS configuration with `postcss-import` plugin**
131
+ 3. **MUST NOT use CDN imports** - all CSS must be imported from npm packages
132
+ 4. **The rake task MUST include the `--postcss` flag**
133
+
134
+ ### Required Files Setup
114
135
 
115
- Add to your ActiveAdmin stylesheet (`app/assets/stylesheets/active_admin.css` or `.scss`):
136
+ #### 1. Create PostCSS Configuration (`postcss.config.js`)
137
+
138
+ ```javascript
139
+ module.exports = {
140
+ plugins: [
141
+ require('postcss-import'), // CRITICAL: Required for @import to work
142
+ require('postcss-nesting'), // Optional: For nested CSS
143
+ require('autoprefixer'), // Optional: For browser compatibility
144
+ ],
145
+ }
146
+ ```
147
+
148
+ #### 2. Create Tailwind Input File (`app/assets/stylesheets/active_admin.tailwind.css`)
116
149
 
117
150
  ```css
118
- /* Import Tom Select styles */
119
- @import 'tom-select/dist/css/tom-select.css';
151
+ @import "tailwindcss/base";
152
+ @import "tailwindcss/components";
153
+ @import "tailwindcss/utilities";
154
+
155
+ /* CRITICAL: Import Tom Select styles from npm package, NOT from CDN! */
156
+ @import "@rocket-sensei/activeadmin-tom_select/src/tom-select-tailwind.css";
120
157
 
121
- /* Or if using CDN: */
122
- @import url('https://cdn.jsdelivr.net/npm/tom-select@2.4.3/dist/css/tom-select.css');
158
+ /* Import any custom styles */
159
+ @import "./active_admin_custom.css";
123
160
 
124
- /* Optional: Custom styling for searchable selects */
161
+ /* Custom styling for searchable selects */
125
162
  .searchable-select-input {
126
163
  width: 100%;
127
164
  }
@@ -132,13 +169,122 @@ Add to your ActiveAdmin stylesheet (`app/assets/stylesheets/active_admin.css` or
132
169
  }
133
170
  ```
134
171
 
172
+ #### 3. Create Rake Task (`lib/tasks/active_admin.rake`)
173
+
174
+ ```ruby
175
+ namespace :active_admin do
176
+ desc 'Build Active Admin Tailwind stylesheets'
177
+ task :build do
178
+ require 'fileutils'
179
+
180
+ root = Rails.root
181
+
182
+ # Ensure builds directory exists
183
+ FileUtils.mkdir_p(File.join(root, 'app/assets/builds'))
184
+
185
+ # Build with Tailwind CLI (CRITICAL: include --postcss flag!)
186
+ command = [
187
+ 'npx', 'tailwindcss',
188
+ '-i', File.join(root, 'app/assets/stylesheets/active_admin.tailwind.css'),
189
+ '-o', File.join(root, 'app/assets/builds/active_admin.css'),
190
+ '-c', File.join(root, 'tailwind.config.js'),
191
+ '--postcss', File.join(root, 'postcss.config.js'), # CRITICAL: Must specify PostCSS config
192
+ '-m'
193
+ ]
194
+
195
+ system(*command, exception: true)
196
+
197
+ puts 'Built Active Admin CSS with Tailwind'
198
+ end
199
+
200
+ desc 'Watch Active Admin Tailwind stylesheets'
201
+ task :watch do
202
+ root = Rails.root
203
+
204
+ # Watch for changes
205
+ command = [
206
+ 'npx', 'tailwindcss',
207
+ '--watch',
208
+ '-i', File.join(root, 'app/assets/stylesheets/active_admin.tailwind.css'),
209
+ '-o', File.join(root, 'app/assets/builds/active_admin.css'),
210
+ '-c', File.join(root, 'tailwind.config.js'),
211
+ '--postcss', File.join(root, 'postcss.config.js'), # CRITICAL: Must specify PostCSS config
212
+ '-m'
213
+ ]
214
+
215
+ system(*command)
216
+ end
217
+ end
218
+
219
+ # Enhance existing rake tasks
220
+ if Rake::Task.task_defined?('assets:precompile')
221
+ Rake::Task['assets:precompile'].enhance(['active_admin:build'])
222
+ end
223
+ ```
224
+
225
+ #### 4. Update package.json scripts
226
+
227
+ ```json
228
+ {
229
+ "scripts": {
230
+ "build:js": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
231
+ "build:css": "bundle exec rake active_admin:build",
232
+ "build": "npm run build:js && npm run build:css",
233
+ "watch:css": "bundle exec rake active_admin:watch"
234
+ }
235
+ }
236
+ ```
237
+
238
+ #### 5. Build your CSS
239
+
240
+ ```bash
241
+ # One-time build
242
+ bundle exec rake active_admin:build
243
+
244
+ # Or use npm script
245
+ npm run build:css
246
+
247
+ # For development with watch mode
248
+ bundle exec rake active_admin:watch
249
+ # or
250
+ npm run watch:css
251
+ ```
252
+
253
+ ### Common Build Errors and Solutions
254
+
255
+ #### Tom Select CSS Not Included in Built File
256
+
257
+ **Symptoms**: The built CSS file doesn't contain any Tom Select styles (no `.ts-wrapper`, `.ts-control`, etc. classes)
258
+
259
+ **Causes and Solutions**:
260
+ 1. **Using CDN imports**: CDN imports (`@import url('https://...')`) are NOT processed by Tailwind. You MUST import from npm packages.
261
+ 2. **Wrong file extension**: Input file must be `.tailwind.css`, not `.css`
262
+ 3. **Missing PostCSS config**: Without `postcss-import` plugin, `@import` statements won't work
263
+ 4. **Missing `--postcss` flag**: The rake task must include `--postcss` flag
264
+
265
+ **How to verify CSS is included**:
266
+ ```bash
267
+ # Check if Tom Select classes are in the built file
268
+ grep -c "ts-wrapper\|ts-control\|ts-dropdown" app/assets/builds/active_admin.css
269
+ # Should return a number > 0
270
+ ```
271
+
272
+ ### Option B: Using Regular CSS (without Tailwind) - NOT RECOMMENDED
273
+
274
+ ⚠️ **WARNING**: Using CDN imports or regular CSS imports without a proper build process will likely result in missing styles when using Tailwind CSS build. We strongly recommend using the Tailwind setup above.
275
+
276
+ If you absolutely must use regular CSS without Tailwind, you'll need a different build process that can handle CSS imports, such as:
277
+ - Using Webpack with css-loader
278
+ - Using esbuild with CSS plugins
279
+ - Using a dedicated CSS bundler
280
+
135
281
  ### Step 5: For Importmap Users
136
282
 
137
283
  If you're using importmap instead of esbuild, add to `config/importmap.rb`:
138
284
 
139
285
  ```ruby
140
286
  pin "tom-select", to: "https://ga.jspm.io/npm:tom-select@2.4.3/dist/js/tom-select.complete.min.js"
141
- pin "@rocket-sensei/activeadmin-tom_select", to: "@rocket-sensei--activeadmin-tom_select.js"
287
+ pin "activeadmin-tom_select", to: "activeadmin-tom_select.js"
142
288
  ```
143
289
 
144
290
  And update your `app/javascript/active_admin.js`:
@@ -151,7 +297,7 @@ import TomSelect from "tom-select";
151
297
  window.TomSelect = TomSelect;
152
298
 
153
299
  // Import and auto-initialize searchable selects
154
- import { setupAutoInit } from "@rocket-sensei/activeadmin-tom_select";
300
+ import { setupAutoInit } from "activeadmin-tom_select";
155
301
  setupAutoInit();
156
302
  ```
157
303
 
@@ -194,11 +340,36 @@ This usually happens when Tom Select isn't properly imported. Ensure:
194
340
  2. `window.TomSelect = TomSelect` is set to make it globally available
195
341
  3. The NPM package is installed: `npm install tom-select`
196
342
 
197
- ### Styles Not Loading
343
+ ### Styles Not Loading / CSS Missing
344
+
345
+ This is a common issue when migrating to ActiveAdmin 4 with Tailwind CSS. Here's how to fix it:
346
+
347
+ #### Checklist for Tailwind CSS Users:
348
+
349
+ 1. ✅ **File Extension**: Is your input file named `active_admin.tailwind.css` (NOT `active_admin.css`)?
350
+ 2. ✅ **PostCSS Config**: Do you have `postcss.config.js` with `postcss-import` plugin?
351
+ 3. ✅ **NPM Packages**: Are PostCSS plugins installed? (`npm install postcss postcss-import`)
352
+ 4. ✅ **No CDN Imports**: Are you importing from npm packages, not CDN URLs?
353
+ 5. ✅ **Rake Task**: Does your rake task include `--postcss` flag?
354
+ 6. ✅ **Build Output**: Does `app/assets/builds/active_admin.css` contain Tom Select classes?
355
+
356
+ Run this diagnostic command:
357
+ ```bash
358
+ # Check if everything is set up correctly
359
+ echo "Checking setup..."
360
+ [ -f postcss.config.js ] && echo "✅ PostCSS config exists" || echo "❌ Missing postcss.config.js"
361
+ [ -f app/assets/stylesheets/active_admin.tailwind.css ] && echo "✅ Tailwind CSS file exists" || echo "❌ Missing active_admin.tailwind.css"
362
+ grep -q "postcss-import" postcss.config.js && echo "✅ postcss-import configured" || echo "❌ postcss-import not in config"
363
+ grep -q "@rocket-sensei/activeadmin-tom_select" app/assets/stylesheets/active_admin.tailwind.css && echo "✅ Tom Select import found" || echo "❌ Tom Select import missing"
364
+ grep -q "ts-wrapper" app/assets/builds/active_admin.css 2>/dev/null && echo "✅ Tom Select CSS in built file" || echo "❌ Tom Select CSS NOT in built file"
365
+ ```
366
+
367
+ #### Common CSS Issues:
198
368
 
199
- 1. Verify the Tom Select CSS import is in your stylesheet
200
- 2. Check that your build process includes the stylesheets
201
- 3. Clear your browser cache and restart Rails server
369
+ - **Dropdown not styled**: Missing Tom Select CSS - verify all setup steps above
370
+ - **Width issues**: Add `.ts-wrapper { min-width: 50%; }` to your styles
371
+ - **Z-index problems**: Tom Select dropdowns may need higher z-index in some layouts
372
+ - **Missing icons**: Ensure the Tom Select CSS is fully loaded
202
373
 
203
374
  ### Ajax Options Not Loading
204
375
 
@@ -228,7 +399,7 @@ f.input :tags, as: :searchable_select, ajax: true, multiple: true
228
399
  ## Differences from Original Gem
229
400
 
230
401
  1. **Tom Select instead of Select2**: No jQuery dependency required!
231
- 2. **NPM Scope**: Package is now `@rocket-sensei/activeadmin-tom_select`
402
+ 2. **NPM Package**: Package is now `activeadmin-tom_select` or `@rocket-sensei/activeadmin-tom_select`
232
403
  3. **Gem Name**: Gem is now `activeadmin-tom_select`
233
404
  4. **Virtual Scroll**: Automatic pagination for large datasets
234
405
  5. **Rails 8 Ready**: Full support for Propshaft and modern Rails
@@ -261,10 +432,12 @@ If you're migrating from a Select2-based version to this Tom Select version:
261
432
  ## Need Help?
262
433
 
263
434
  If you encounter issues:
264
- 1. Check that all JavaScript packages are installed
265
- 2. Verify your bundler configuration
266
- 3. Clear browser cache and Rails tmp/cache
267
- 4. Check browser console for errors
435
+ 1. Run the diagnostic command above to check your setup
436
+ 2. Verify all npm packages are installed
437
+ 3. Check that PostCSS config is correct
438
+ 4. Ensure no CDN imports are being used
439
+ 5. Clear browser cache and Rails tmp/cache
440
+ 6. Check browser console for errors
268
441
 
269
442
  For bug reports or questions, please visit:
270
443
  https://github.com/rs-pro/activeadmin-tom_select/issues