@doyosi/laraisy 1.0.2 → 1.0.3

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 (51) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +1 -1
  3. package/src/CodeInput.js +48 -48
  4. package/src/DSAlert.js +352 -352
  5. package/src/DSAvatar.js +207 -207
  6. package/src/DSDelete.js +274 -274
  7. package/src/DSForm.js +568 -568
  8. package/src/DSGridOrTable.js +453 -453
  9. package/src/DSLocaleSwitcher.js +239 -239
  10. package/src/DSLogout.js +293 -293
  11. package/src/DSNotifications.js +365 -365
  12. package/src/DSRestore.js +181 -181
  13. package/src/DSSelect.js +1071 -1071
  14. package/src/DSSelectBox.js +563 -563
  15. package/src/DSSimpleSlider.js +517 -517
  16. package/src/DSSvgFetch.js +69 -69
  17. package/src/DSTable/DSTableExport.js +68 -68
  18. package/src/DSTable/DSTableFilter.js +224 -224
  19. package/src/DSTable/DSTablePagination.js +136 -136
  20. package/src/DSTable/DSTableSearch.js +40 -40
  21. package/src/DSTable/DSTableSelection.js +192 -192
  22. package/src/DSTable/DSTableSort.js +58 -58
  23. package/src/DSTable.js +353 -353
  24. package/src/DSTabs.js +488 -488
  25. package/src/DSUpload.js +887 -887
  26. package/dist/CodeInput.d.ts +0 -10
  27. package/dist/DSAlert.d.ts +0 -112
  28. package/dist/DSAvatar.d.ts +0 -45
  29. package/dist/DSDelete.d.ts +0 -61
  30. package/dist/DSForm.d.ts +0 -151
  31. package/dist/DSGridOrTable/DSGOTRenderer.d.ts +0 -60
  32. package/dist/DSGridOrTable/DSGOTViewToggle.d.ts +0 -26
  33. package/dist/DSGridOrTable.d.ts +0 -296
  34. package/dist/DSLocaleSwitcher.d.ts +0 -71
  35. package/dist/DSLogout.d.ts +0 -76
  36. package/dist/DSNotifications.d.ts +0 -54
  37. package/dist/DSRestore.d.ts +0 -56
  38. package/dist/DSSelect.d.ts +0 -221
  39. package/dist/DSSelectBox.d.ts +0 -123
  40. package/dist/DSSimpleSlider.d.ts +0 -136
  41. package/dist/DSSvgFetch.d.ts +0 -17
  42. package/dist/DSTable/DSTableExport.d.ts +0 -11
  43. package/dist/DSTable/DSTableFilter.d.ts +0 -40
  44. package/dist/DSTable/DSTablePagination.d.ts +0 -12
  45. package/dist/DSTable/DSTableSearch.d.ts +0 -8
  46. package/dist/DSTable/DSTableSelection.d.ts +0 -46
  47. package/dist/DSTable/DSTableSort.d.ts +0 -8
  48. package/dist/DSTable.d.ts +0 -116
  49. package/dist/DSTabs.d.ts +0 -156
  50. package/dist/DSUpload.d.ts +0 -220
  51. package/dist/index.d.ts +0 -17
@@ -1,239 +1,239 @@
1
- /**
2
- * DSLocaleSwitcher
3
- *
4
- * Manages locale switching for translatable form fields.
5
- * Shows/hides input fields based on selected locale.
6
- */
7
- export class DSLocaleSwitcher {
8
- static instances = new Map();
9
- static instanceCounter = 0;
10
-
11
- /**
12
- * Default configuration
13
- */
14
- static defaults = {
15
- defaultLocale: 'en',
16
- onSwitch: null, // Callback when locale switches
17
- };
18
-
19
- /**
20
- * @param {string|HTMLElement} selector - Container element or selector
21
- * @param {Object} config - Configuration options
22
- */
23
- constructor(selector, config = {}) {
24
- this.instanceId = `ds-locale-switcher-${++DSLocaleSwitcher.instanceCounter}`;
25
-
26
- const el = typeof selector === 'string' ? document.querySelector(selector) : selector;
27
-
28
- if (!el) {
29
- throw new Error('DSLocaleSwitcher: Element not found.');
30
- }
31
-
32
- this.container = el;
33
- this.cfg = { ...DSLocaleSwitcher.defaults, ...config };
34
- this._currentLocale = this.cfg.defaultLocale;
35
- this._boundHandlers = {};
36
-
37
- this._init();
38
-
39
- DSLocaleSwitcher.instances.set(this.instanceId, this);
40
- this.container.dataset.dsLocaleSwitcherId = this.instanceId;
41
- }
42
-
43
- /**
44
- * Static factory
45
- */
46
- static create(selector, config = {}) {
47
- return new DSLocaleSwitcher(selector, config);
48
- }
49
-
50
- /**
51
- * Get instance by element
52
- */
53
- static getInstance(element) {
54
- const el = typeof element === 'string' ? document.querySelector(element) : element;
55
- if (!el) return null;
56
- const container = el.closest('[data-ds-locale-switcher-id]');
57
- if (!container) return null;
58
- return DSLocaleSwitcher.instances.get(container.dataset.dsLocaleSwitcherId);
59
- }
60
-
61
- /**
62
- * Auto-initialize all elements with [data-ds-locale-switcher]
63
- */
64
- static initAll(selector = '[data-ds-locale-switcher]') {
65
- document.querySelectorAll(selector).forEach(el => {
66
- if (!el.dataset.dsLocaleSwitcherId) {
67
- new DSLocaleSwitcher(el);
68
- }
69
- });
70
- }
71
-
72
- // ==================== INITIALIZATION ====================
73
-
74
- _init() {
75
- this._cacheElements();
76
- this._bindEvents();
77
- this._setInitialState();
78
- }
79
-
80
- _cacheElements() {
81
- this.elements = {
82
- trigger: this.container.querySelector('[data-ds-locale-trigger]'),
83
- label: this.container.querySelector('[data-ds-locale-label]'),
84
- options: this.container.querySelectorAll('[data-ds-locale-option]'),
85
- translatables: this.container.querySelectorAll('[data-locale-translatable]'),
86
- };
87
- }
88
-
89
- _bindEvents() {
90
- this._boundHandlers.onOptionClick = this._onOptionClick.bind(this);
91
-
92
- this.elements.options.forEach(option => {
93
- option.addEventListener('click', this._boundHandlers.onOptionClick);
94
- });
95
- }
96
-
97
- _setInitialState() {
98
- // Find the first visible translatable to determine default locale
99
- this.elements.translatables.forEach(el => {
100
- if (el.style.display !== 'none') {
101
- this._currentLocale = el.dataset.localeTranslatable;
102
- }
103
- });
104
-
105
- // Update UI to match current locale
106
- this._updateUI();
107
- }
108
-
109
- // ==================== EVENT HANDLERS ====================
110
-
111
- _onOptionClick(e) {
112
- e.preventDefault();
113
- const locale = e.currentTarget.dataset.dsLocaleOption;
114
- this.switchTo(locale);
115
-
116
- // Close dropdown
117
- document.activeElement?.blur();
118
- }
119
-
120
- // ==================== PUBLIC API ====================
121
-
122
- /**
123
- * Switch to a specific locale
124
- */
125
- switchTo(locale) {
126
- if (locale === this._currentLocale) return;
127
-
128
- const prevLocale = this._currentLocale;
129
- this._currentLocale = locale;
130
-
131
- // Show/hide translatable fields
132
- this.elements.translatables.forEach(el => {
133
- if (el.dataset.localeTranslatable === locale) {
134
- el.style.display = '';
135
- } else {
136
- el.style.display = 'none';
137
- }
138
- });
139
-
140
- // Update dropdown UI
141
- this._updateUI();
142
-
143
- // Callback
144
- if (typeof this.cfg.onSwitch === 'function') {
145
- this.cfg.onSwitch({ locale, prevLocale, instance: this });
146
- }
147
-
148
- // Dispatch event
149
- this.container.dispatchEvent(new CustomEvent('dslocale:switch', {
150
- bubbles: true,
151
- detail: { locale, prevLocale, instance: this }
152
- }));
153
- }
154
-
155
- /**
156
- * Get current locale
157
- */
158
- getCurrentLocale() {
159
- return this._currentLocale;
160
- }
161
-
162
- /**
163
- * Get all values for all locales
164
- */
165
- getValues() {
166
- const values = {};
167
-
168
- this.elements.translatables.forEach(el => {
169
- const locale = el.dataset.localeTranslatable;
170
- const input = el.querySelector('input, textarea');
171
- if (input) {
172
- values[locale] = input.value;
173
- }
174
- });
175
-
176
- return values;
177
- }
178
-
179
- /**
180
- * Set values for all locales
181
- */
182
- setValues(values) {
183
- if (typeof values !== 'object') return;
184
-
185
- this.elements.translatables.forEach(el => {
186
- const locale = el.dataset.localeTranslatable;
187
- const input = el.querySelector('input, textarea');
188
- if (input && values[locale] !== undefined) {
189
- input.value = values[locale];
190
- }
191
- });
192
- }
193
-
194
- /**
195
- * Destroy instance
196
- */
197
- destroy() {
198
- this.elements.options.forEach(option => {
199
- option.removeEventListener('click', this._boundHandlers.onOptionClick);
200
- });
201
-
202
- DSLocaleSwitcher.instances.delete(this.instanceId);
203
- delete this.container.dataset.dsLocaleSwitcherId;
204
- }
205
-
206
- // ==================== PRIVATE METHODS ====================
207
-
208
- _updateUI() {
209
- // Update active state on options
210
- this.elements.options.forEach(option => {
211
- if (option.dataset.dsLocaleOption === this._currentLocale) {
212
- option.classList.add('active');
213
- } else {
214
- option.classList.remove('active');
215
- }
216
- });
217
-
218
- // Update trigger label and flag
219
- const activeOption = this.container.querySelector(`[data-ds-locale-option="${this._currentLocale}"]`);
220
- if (activeOption && this.elements.label) {
221
- this.elements.label.textContent = activeOption.dataset.localeName || this._currentLocale;
222
- }
223
-
224
- // Update trigger flag
225
- if (activeOption && this.elements.trigger) {
226
- const triggerFlag = this.elements.trigger.querySelector('.fi');
227
- if (triggerFlag && activeOption.dataset.localeFlag) {
228
- triggerFlag.className = `fi fi-${activeOption.dataset.localeFlag} text-sm`;
229
- }
230
- }
231
- }
232
- }
233
-
234
- // Auto-initialize on DOM ready
235
- if (typeof document !== 'undefined') {
236
- document.addEventListener('DOMContentLoaded', () => {
237
- DSLocaleSwitcher.initAll();
238
- });
239
- }
1
+ /**
2
+ * DSLocaleSwitcher
3
+ *
4
+ * Manages locale switching for translatable form fields.
5
+ * Shows/hides input fields based on selected locale.
6
+ */
7
+ export class DSLocaleSwitcher {
8
+ static instances = new Map();
9
+ static instanceCounter = 0;
10
+
11
+ /**
12
+ * Default configuration
13
+ */
14
+ static defaults = {
15
+ defaultLocale: 'en',
16
+ onSwitch: null, // Callback when locale switches
17
+ };
18
+
19
+ /**
20
+ * @param {string|HTMLElement} selector - Container element or selector
21
+ * @param {Object} config - Configuration options
22
+ */
23
+ constructor(selector, config = {}) {
24
+ this.instanceId = `ds-locale-switcher-${++DSLocaleSwitcher.instanceCounter}`;
25
+
26
+ const el = typeof selector === 'string' ? document.querySelector(selector) : selector;
27
+
28
+ if (!el) {
29
+ throw new Error('DSLocaleSwitcher: Element not found.');
30
+ }
31
+
32
+ this.container = el;
33
+ this.cfg = { ...DSLocaleSwitcher.defaults, ...config };
34
+ this._currentLocale = this.cfg.defaultLocale;
35
+ this._boundHandlers = {};
36
+
37
+ this._init();
38
+
39
+ DSLocaleSwitcher.instances.set(this.instanceId, this);
40
+ this.container.dataset.dsLocaleSwitcherId = this.instanceId;
41
+ }
42
+
43
+ /**
44
+ * Static factory
45
+ */
46
+ static create(selector, config = {}) {
47
+ return new DSLocaleSwitcher(selector, config);
48
+ }
49
+
50
+ /**
51
+ * Get instance by element
52
+ */
53
+ static getInstance(element) {
54
+ const el = typeof element === 'string' ? document.querySelector(element) : element;
55
+ if (!el) return null;
56
+ const container = el.closest('[data-ds-locale-switcher-id]');
57
+ if (!container) return null;
58
+ return DSLocaleSwitcher.instances.get(container.dataset.dsLocaleSwitcherId);
59
+ }
60
+
61
+ /**
62
+ * Auto-initialize all elements with [data-ds-locale-switcher]
63
+ */
64
+ static initAll(selector = '[data-ds-locale-switcher]') {
65
+ document.querySelectorAll(selector).forEach(el => {
66
+ if (!el.dataset.dsLocaleSwitcherId) {
67
+ new DSLocaleSwitcher(el);
68
+ }
69
+ });
70
+ }
71
+
72
+ // ==================== INITIALIZATION ====================
73
+
74
+ _init() {
75
+ this._cacheElements();
76
+ this._bindEvents();
77
+ this._setInitialState();
78
+ }
79
+
80
+ _cacheElements() {
81
+ this.elements = {
82
+ trigger: this.container.querySelector('[data-ds-locale-trigger]'),
83
+ label: this.container.querySelector('[data-ds-locale-label]'),
84
+ options: this.container.querySelectorAll('[data-ds-locale-option]'),
85
+ translatables: this.container.querySelectorAll('[data-locale-translatable]'),
86
+ };
87
+ }
88
+
89
+ _bindEvents() {
90
+ this._boundHandlers.onOptionClick = this._onOptionClick.bind(this);
91
+
92
+ this.elements.options.forEach(option => {
93
+ option.addEventListener('click', this._boundHandlers.onOptionClick);
94
+ });
95
+ }
96
+
97
+ _setInitialState() {
98
+ // Find the first visible translatable to determine default locale
99
+ this.elements.translatables.forEach(el => {
100
+ if (el.style.display !== 'none') {
101
+ this._currentLocale = el.dataset.localeTranslatable;
102
+ }
103
+ });
104
+
105
+ // Update UI to match current locale
106
+ this._updateUI();
107
+ }
108
+
109
+ // ==================== EVENT HANDLERS ====================
110
+
111
+ _onOptionClick(e) {
112
+ e.preventDefault();
113
+ const locale = e.currentTarget.dataset.dsLocaleOption;
114
+ this.switchTo(locale);
115
+
116
+ // Close dropdown
117
+ document.activeElement?.blur();
118
+ }
119
+
120
+ // ==================== PUBLIC API ====================
121
+
122
+ /**
123
+ * Switch to a specific locale
124
+ */
125
+ switchTo(locale) {
126
+ if (locale === this._currentLocale) return;
127
+
128
+ const prevLocale = this._currentLocale;
129
+ this._currentLocale = locale;
130
+
131
+ // Show/hide translatable fields
132
+ this.elements.translatables.forEach(el => {
133
+ if (el.dataset.localeTranslatable === locale) {
134
+ el.style.display = '';
135
+ } else {
136
+ el.style.display = 'none';
137
+ }
138
+ });
139
+
140
+ // Update dropdown UI
141
+ this._updateUI();
142
+
143
+ // Callback
144
+ if (typeof this.cfg.onSwitch === 'function') {
145
+ this.cfg.onSwitch({ locale, prevLocale, instance: this });
146
+ }
147
+
148
+ // Dispatch event
149
+ this.container.dispatchEvent(new CustomEvent('dslocale:switch', {
150
+ bubbles: true,
151
+ detail: { locale, prevLocale, instance: this }
152
+ }));
153
+ }
154
+
155
+ /**
156
+ * Get current locale
157
+ */
158
+ getCurrentLocale() {
159
+ return this._currentLocale;
160
+ }
161
+
162
+ /**
163
+ * Get all values for all locales
164
+ */
165
+ getValues() {
166
+ const values = {};
167
+
168
+ this.elements.translatables.forEach(el => {
169
+ const locale = el.dataset.localeTranslatable;
170
+ const input = el.querySelector('input, textarea');
171
+ if (input) {
172
+ values[locale] = input.value;
173
+ }
174
+ });
175
+
176
+ return values;
177
+ }
178
+
179
+ /**
180
+ * Set values for all locales
181
+ */
182
+ setValues(values) {
183
+ if (typeof values !== 'object') return;
184
+
185
+ this.elements.translatables.forEach(el => {
186
+ const locale = el.dataset.localeTranslatable;
187
+ const input = el.querySelector('input, textarea');
188
+ if (input && values[locale] !== undefined) {
189
+ input.value = values[locale];
190
+ }
191
+ });
192
+ }
193
+
194
+ /**
195
+ * Destroy instance
196
+ */
197
+ destroy() {
198
+ this.elements.options.forEach(option => {
199
+ option.removeEventListener('click', this._boundHandlers.onOptionClick);
200
+ });
201
+
202
+ DSLocaleSwitcher.instances.delete(this.instanceId);
203
+ delete this.container.dataset.dsLocaleSwitcherId;
204
+ }
205
+
206
+ // ==================== PRIVATE METHODS ====================
207
+
208
+ _updateUI() {
209
+ // Update active state on options
210
+ this.elements.options.forEach(option => {
211
+ if (option.dataset.dsLocaleOption === this._currentLocale) {
212
+ option.classList.add('active');
213
+ } else {
214
+ option.classList.remove('active');
215
+ }
216
+ });
217
+
218
+ // Update trigger label and flag
219
+ const activeOption = this.container.querySelector(`[data-ds-locale-option="${this._currentLocale}"]`);
220
+ if (activeOption && this.elements.label) {
221
+ this.elements.label.textContent = activeOption.dataset.localeName || this._currentLocale;
222
+ }
223
+
224
+ // Update trigger flag
225
+ if (activeOption && this.elements.trigger) {
226
+ const triggerFlag = this.elements.trigger.querySelector('.fi');
227
+ if (triggerFlag && activeOption.dataset.localeFlag) {
228
+ triggerFlag.className = `fi fi-${activeOption.dataset.localeFlag} text-sm`;
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ // Auto-initialize on DOM ready
235
+ if (typeof document !== 'undefined') {
236
+ document.addEventListener('DOMContentLoaded', () => {
237
+ DSLocaleSwitcher.initAll();
238
+ });
239
+ }