activeadmin-tom_select 4.1.2 → 4.2.0.beta2

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +2 -2
  3. data/CHANGELOG.md +12 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +146 -102
  6. data/README.md +1 -1
  7. data/activeadmin-tom_select.gemspec +1 -0
  8. data/docs/activeadmin-4-asset-setup.md +171 -0
  9. data/docs/activeadmin-tailwind-4.md +125 -0
  10. data/docs/guide-update-your-app.md +89 -356
  11. data/docs/setup-activeadmin-app.md +69 -492
  12. data/docs/setup-activeadmin-gem.md +83 -449
  13. data/gemfiles/rails_7.x_active_admin_4.x.gemfile +2 -1
  14. data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +158 -116
  15. data/gemfiles/rails_8.x_active_admin_4.x.gemfile +2 -1
  16. data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +145 -101
  17. data/lib/activeadmin/tom_select/option_collection.rb +4 -6
  18. data/lib/activeadmin/tom_select/select_input_extension.rb +15 -7
  19. data/lib/activeadmin/tom_select/version.rb +1 -1
  20. data/npm-package/package.json +1 -1
  21. data/spec/features/end_to_end_spec.rb +2 -2
  22. data/spec/features/input_errors_spec.rb +1 -3
  23. data/spec/features/options_dsl_spec.rb +6 -6
  24. data/spec/internal/Gemfile +1 -0
  25. data/spec/internal/Gemfile.lock +152 -107
  26. data/spec/internal/app/assets/stylesheets/active_admin.tailwind.css +8 -5
  27. data/spec/internal/bin/tailwindcss +27 -0
  28. data/spec/internal/lib/tasks/active_admin.rake +9 -4
  29. data/spec/internal/package-lock.json +15 -1371
  30. data/spec/internal/package.json +1 -2
  31. data/{docs/tailwind-4/tailwind-active_admin.config.js → spec/internal/tailwind-active_admin.config.mjs} +9 -4
  32. data/spec/internal/yarn.lock +128 -728
  33. metadata +21 -23
  34. data/docs/activeadmin-4-detailed-reference.md +0 -932
  35. data/docs/activeadmin-4-gem-migration-guide.md +0 -313
  36. data/docs/combustion.md +0 -213
  37. data/docs/fail.png +0 -0
  38. data/docs/normal.png +0 -0
  39. data/docs/propshaft-readme.md +0 -320
  40. data/docs/propshaft-upgrade.md +0 -484
  41. data/docs/tailwind/blog-page.md +0 -341
  42. data/docs/tailwind/upgrade-guide-enhanced.md +0 -438
  43. data/docs/tailwind/upgrade-guide.md +0 -416
  44. data/docs/tailwind-4/active_admin.rake +0 -38
  45. data/docs/tailwind-4/active_admin.tailwind.css +0 -415
  46. data/docs/test-app-change.md +0 -154
  47. data/docs/test-environment-fixes.md +0 -58
  48. data/docs/update-tom-select.md +0 -348
@@ -1,348 +0,0 @@
1
- # Tom Select Migration Guide for ActiveAdmin 4
2
-
3
- ## Overview
4
- This guide documents the complete migration from ActiveAdmin Searchable Select (Select2-based) to Tom Select (vanilla JS, no jQuery) with Tailwind CSS 4 support.
5
-
6
- ## Key Benefits of Migration
7
-
8
- 1. **No jQuery Dependency**: Tom Select is pure vanilla JavaScript, reducing bundle size
9
- 2. **Modern JavaScript**: ES6+ modules, better performance
10
- 3. **ActiveAdmin 4 Compatible**: Full support for latest ActiveAdmin
11
- 4. **Smaller Bundle**: Removed jQuery and Select2 dependencies
12
-
13
- ## Installation Steps
14
-
15
- ### 1. Update Gemfile
16
-
17
- ```ruby
18
- # Remove old gem
19
- # gem 'rs-activeadmin-searchable_select', github: 'glebtv/activeadmin-searchable_select'
20
-
21
- # Add new gem (from RubyGems)
22
- gem 'activeadmin-tom_select'
23
- ```
24
-
25
- ### 2. Update package.json
26
-
27
- ```json
28
- {
29
- "dependencies": {
30
- // Remove these:
31
- // "jquery": "^3.7.1",
32
- // "select2": "^4.1.0-rc.0",
33
- // "@rocket-sensei/activeadmin-searchable_select": "^4.0.1",
34
-
35
- // Add these:
36
- "tom-select": "^2.4.3",
37
- "activeadmin-tom_select": "^4.1.0"
38
- }
39
- }
40
- ```
41
-
42
- ### 3. Update JavaScript (app/js/active_admin.js)
43
-
44
- ```javascript
45
- // Import ActiveAdmin core first - includes all features and Rails UJS
46
- import "@activeadmin/activeadmin";
47
-
48
- // Import Tom Select
49
- import TomSelect from 'tom-select';
50
- window.TomSelect = TomSelect;
51
-
52
- // Import and setup ActiveAdmin Tom Select
53
- import { setupAutoInit, initSearchableSelects } from 'activeadmin-tom_select';
54
- window.initSearchableSelects = initSearchableSelects;
55
- setupAutoInit();
56
-
57
- console.log('ActiveAdmin loaded with Tom Select');
58
- ```
59
-
60
- **Important**: Do NOT include jQuery - it's no longer needed!
61
-
62
- ### 4. Configure CSS (app/assets/stylesheets/active_admin.tailwind.css)
63
-
64
- **CRITICAL**: Use Tailwind's @import syntax instead of @tailwind directives when importing vendor CSS:
65
-
66
- ```css
67
- /* Use @import syntax for proper processing order */
68
- @import "tailwindcss/base";
69
- @import "tailwindcss/components";
70
- @import "tailwindcss/utilities";
71
-
72
- /* Import vendor CSS */
73
- @import 'tom-select/dist/css/tom-select.css';
74
- @import 'activeadmin-tom_select/src/tom-select-tailwind.css';
75
-
76
- /* Your custom styles here */
77
- ```
78
-
79
- **Why @import instead of @tailwind?**
80
- - Tailwind only processes imports at the top of the file
81
- - Using @tailwind directives with vendor CSS imports can cause processing issues
82
- - The @import syntax ensures proper CSS cascade order
83
-
84
- ### 5. Update Build Configuration
85
-
86
- #### esbuild.config.js
87
- ```javascript
88
- #!/usr/bin/env node
89
- const esbuild = require('esbuild');
90
- const path = require('path');
91
-
92
- const config = {
93
- entryPoints: [
94
- 'app/js/active_admin.js'
95
- ],
96
- bundle: true,
97
- sourcemap: true,
98
- format: 'esm',
99
- outdir: 'app/assets/builds',
100
- publicPath: '/assets',
101
- loader: {
102
- '.js': 'js',
103
- '.jsx': 'jsx',
104
- },
105
- define: {
106
- 'global': 'window'
107
- }
108
- };
109
-
110
- // Build logic here...
111
- ```
112
-
113
- #### tailwind-active_admin.config.js
114
- ```javascript
115
- const execSync = require("node:child_process").execSync;
116
- const activeAdminPlugin = require('@activeadmin/activeadmin/plugin');
117
-
118
- const activeAdminPath = execSync("bundle show activeadmin", {
119
- encoding: "utf-8",
120
- }).trim();
121
-
122
- module.exports = {
123
- content: [
124
- `${activeAdminPath}/vendor/javascript/flowbite.js`,
125
- `${activeAdminPath}/plugin.js`,
126
- `${activeAdminPath}/app/views/**/*.{arb,erb,html,rb}`,
127
- "./app/admin/**/*.{arb,erb,html,rb}",
128
- "./app/views/active_admin/**/*.{arb,erb,html,rb}",
129
- "./app/views/admin/**/*.{arb,erb,html,rb}",
130
- "./app/js/**/*.{js,jsx}",
131
- "./app/views/**/*.{erb,html}"
132
- ],
133
- darkMode: "selector",
134
- plugins: [activeAdminPlugin],
135
- safelist: [
136
- // Tom Select classes
137
- 'tom-select-input',
138
- { pattern: /^ts-/ },
139
- // Other ActiveAdmin dynamic classes
140
- 'panel-collapsed',
141
- 'status-tag',
142
- // Add your custom classes here
143
- ]
144
- };
145
- ```
146
-
147
- ### 6. Create Rake Task for CSS Building (lib/tasks/active_admin.rake)
148
-
149
- ```ruby
150
- namespace :active_admin do
151
- desc "Build Active Admin Tailwind stylesheets"
152
- task build: :environment do
153
- command = [
154
- "npx", "tailwindcss",
155
- "-i", Rails.root.join("app/assets/stylesheets/active_admin.tailwind.css").to_s,
156
- "-o", Rails.root.join("app/assets/builds/active_admin.css").to_s,
157
- "-c", Rails.root.join("tailwind-active_admin.config.js").to_s,
158
- "-m"
159
- ]
160
-
161
- puts "Building Active Admin CSS..."
162
- system(*command, exception: true)
163
- end
164
-
165
- desc "Watch Active Admin Tailwind stylesheets"
166
- task watch: :environment do
167
- command = [
168
- "npx", "tailwindcss",
169
- "--watch",
170
- "-i", Rails.root.join("app/assets/stylesheets/active_admin.tailwind.css").to_s,
171
- "-o", Rails.root.join("app/assets/builds/active_admin.css").to_s,
172
- "-c", Rails.root.join("tailwind-active_admin.config.js").to_s,
173
- "-m"
174
- ]
175
-
176
- puts "Watching Active Admin CSS..."
177
- system(*command)
178
- end
179
- end
180
-
181
- Rake::Task["assets:precompile"].enhance(["active_admin:build"]) if Rake::Task.task_defined?("assets:precompile")
182
- ```
183
-
184
- ### 7. Update package.json Scripts
185
-
186
- ```json
187
- {
188
- "scripts": {
189
- "build:js": "node esbuild.config.js",
190
- "build:css": "bundle exec rake active_admin:build",
191
- "build": "npm run build:js && npm run build:css",
192
- "watch:js": "node esbuild.config.js --watch",
193
- "watch:css": "bundle exec rake active_admin:watch",
194
- "dev": "npm run watch:js & npm run watch:css"
195
- }
196
- }
197
- ```
198
-
199
- ## Migration Cleanup
200
-
201
- ### Files to Remove
202
- - `inject-jquery.js` - No longer needed
203
- - Any Select2-specific CSS files
204
- - jQuery-specific initialization code
205
-
206
- ### Update Initializers
207
- ```ruby
208
- # config/initializers/activeadmin_tom_select.rb (rename from activeadmin_searchable_select.rb)
209
- require 'activeadmin-tom_select' if defined?(ActiveAdmin)
210
- ```
211
-
212
- ### Remove jQuery References
213
- - Remove jQuery from package.json
214
- - Remove inject-jquery.js from esbuild config
215
- - Update any custom JavaScript to use vanilla JS instead of jQuery
216
-
217
- ## Usage in ActiveAdmin
218
-
219
- The usage remains the same - no changes needed in your admin files:
220
-
221
- ```ruby
222
- ActiveAdmin.register User do
223
- # In forms
224
- form do |f|
225
- f.input :company, as: :searchable_select
226
- f.input :role, as: :searchable_select,
227
- ajax: { resource: Role }
228
- end
229
-
230
- # In filters
231
- filter :company, as: :searchable_select
232
- filter :created_by, as: :searchable_select,
233
- ajax: { resource: User }
234
- end
235
- ```
236
-
237
- ## CSS Class Changes for Custom Styling
238
-
239
- If you have custom CSS, update these selectors:
240
-
241
- | Old (Select2) | New (Tom Select) |
242
- |--------------|------------------|
243
- | `.select2-container` | `.ts-wrapper` |
244
- | `.select2-dropdown` | `.ts-dropdown` |
245
- | `.select2-results__option` | `.ts-dropdown .option` |
246
- | `.select2-selection` | `.ts-control` |
247
- | `.select2-search__field` | `.ts-control input` |
248
-
249
- ## Troubleshooting
250
-
251
- ### Issue: Tom Select not initializing
252
- **Solution**: Ensure that:
253
- - `window.TomSelect` is defined in browser console
254
- - `setupAutoInit()` is called after importing
255
- - No JavaScript errors in console
256
-
257
- ### Issue: Styles not loading
258
- **Solution**:
259
- - Verify CSS imports are using @import syntax, not @tailwind
260
- - Check that tom-select CSS is in node_modules
261
- - Ensure Tailwind processes the CSS file
262
-
263
- ### Issue: "elements.forEach is not a function" error
264
- **Solution**: The `initSearchableSelects` function expects a NodeList or array, not a jQuery object. Use:
265
- ```javascript
266
- // Correct - vanilla JS
267
- const elements = document.querySelectorAll('.searchable-select-input');
268
-
269
- // Incorrect - jQuery object
270
- const elements = $('.searchable-select-input');
271
- ```
272
-
273
- ### Issue: Build errors with missing files
274
- **Solution**: Run `npm install` and `bundle install` to ensure all dependencies are installed
275
-
276
- ## Performance Improvements
277
-
278
- After migration, you should see:
279
- - **Reduced bundle size**: ~200KB smaller without jQuery
280
- - **Faster initialization**: Tom Select is more performant
281
- - **Better memory usage**: No jQuery overhead
282
- - **Cleaner code**: Pure ES6 modules
283
-
284
- ## Complete Example Configuration
285
-
286
- For a working example, here's the minimal setup:
287
-
288
- **Gemfile:**
289
- ```ruby
290
- gem 'activeadmin', '~> 4.0.0.beta'
291
- gem 'activeadmin-tom_select'
292
- ```
293
-
294
- **package.json:**
295
- ```json
296
- {
297
- "dependencies": {
298
- "@activeadmin/activeadmin": "^4.0.0-beta16",
299
- "tom-select": "^2.4.3",
300
- "activeadmin-tom_select": "^4.1.0"
301
- }
302
- }
303
- ```
304
-
305
- **app/js/active_admin.js:**
306
- ```javascript
307
- import "@activeadmin/activeadmin";
308
- import TomSelect from 'tom-select';
309
- import { setupAutoInit, initSearchableSelects } from 'activeadmin-tom_select';
310
-
311
- window.TomSelect = TomSelect;
312
- window.initSearchableSelects = initSearchableSelects;
313
- setupAutoInit();
314
- ```
315
-
316
- **app/assets/stylesheets/active_admin.tailwind.css:**
317
- ```css
318
- @import "tailwindcss/base";
319
- @import "tailwindcss/components";
320
- @import "tailwindcss/utilities";
321
- @import 'tom-select/dist/css/tom-select.css';
322
- @import 'activeadmin-tom_select/src/tom-select-tailwind.css';
323
- ```
324
-
325
- ## Benefits Achieved
326
-
327
- 1. ✅ **No jQuery Required**: Completely removed jQuery dependency
328
- 2. ✅ **Modern JavaScript**: Using ES6 modules and vanilla JS
329
- 3. ✅ **Smaller Bundle**: Reduced JavaScript bundle by ~200KB
330
- 4. ✅ **Better Performance**: Faster initialization and runtime
331
- 5. ✅ **Future-Proof**: Tom Select is actively maintained
332
- 6. ✅ **ActiveAdmin 4 Ready**: Full compatibility with latest version
333
-
334
- ## Migration Checklist
335
-
336
- - [ ] Update Gemfile with `activeadmin-tom_select`
337
- - [ ] Run `bundle install`
338
- - [ ] Update package.json dependencies
339
- - [ ] Run `npm install`
340
- - [ ] Update JavaScript imports in active_admin.js
341
- - [ ] Update CSS to use @import syntax
342
- - [ ] Create/update rake tasks for CSS building
343
- - [ ] Update build scripts in package.json
344
- - [ ] Remove jQuery and Select2 dependencies
345
- - [ ] Test all searchable selects in development
346
- - [ ] Update any custom CSS selectors
347
- - [ ] Remove old initialization files
348
- - [ ] Deploy and test in production