waibu-bootstrap 2.2.3 → 2.3.0

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.
@@ -156,7 +156,7 @@ export async function buildFormSelect (group, params) {
156
156
  html = items.join('\n')
157
157
  }
158
158
  attr = omit(attr, ['size', 'type', 'options', 'value'])
159
- return await this.component.buildTag({ tag: 'select', attr, html })
159
+ return await this.component.buildTag({ tag: attr.tag ?? 'select', attr, html })
160
160
  }
161
161
 
162
162
  export async function buildFormRange (group, params) {
@@ -1,13 +1,10 @@
1
- import { inlineCss, css, scripts } from './form-select-ext.js'
1
+ import { css, scripts } from './form-select-ext.js'
2
2
 
3
3
  async function formSelectCountry () {
4
4
  return class FormSelectCountry extends this.app.baseClass.MpaWidget {
5
5
  static css = [...super.css, css]
6
-
7
6
  static scripts = [...super.scripts, scripts]
8
7
 
9
- static inlineCss = inlineCss
10
-
11
8
  constructor (options) {
12
9
  super(options)
13
10
  this.params.noTag = true
@@ -1,47 +1,16 @@
1
1
  import { buildFormSelect } from './_lib.js'
2
2
  import { build } from './form-input.js'
3
3
 
4
- // TODO: load default values from remote
5
- export const inlineCss = `
6
- .ts-dropdown {
7
- min-width: 242px;
8
- }
9
- .ts-control {
10
- padding-top: 0px;
11
- }
12
- .ts-wrapper {
13
- margin-left: calc(var(--bs-border-width) * -1) !important;
14
- border-top-left-radius: var(--bs-border-radius) !important;
15
- border-bottom-left-radius: var(--bs-border-radius) !important;
16
- white-space: nowrap !important;
17
- }
18
- .ts-control, .ts-control input, .ts-dropdown {
19
- color: inherit;
20
- }
21
- .form-floating > .ts-wrapper {
22
- padding-top: 1.625rem !important;
23
- }
24
-
25
- .ts-wrapper.focus {
26
- border-color: #86b7fe;
27
- outline: 0;
28
- box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
29
- }
30
-
31
- .focus .ts-control {
32
- box-shadow: none;
33
- border: none;
34
- box-shadow: none;
35
- }
36
- `
37
- export const css = 'waibuExtra.virtual:/tom-select/css/tom-select.bootstrap5.min.css'
4
+ export const css = [
5
+ 'waibuExtra.virtual:/tom-select/css/tom-select.bootstrap5.min.css',
6
+ 'waibuBootstrap.asset:/css/widget.css'
7
+ ]
38
8
  export const scripts = 'waibuExtra.virtual:/tom-select/js/tom-select.complete.min.js'
39
9
 
40
10
  async function formSelectExt () {
41
11
  return class FormSelectExt extends this.app.baseClass.MpaWidget {
42
12
  static css = [...super.css, css]
43
13
  static scripts = [...super.scripts, scripts]
44
- static inlineCss = inlineCss
45
14
 
46
15
  build = async () => {
47
16
  const { generateId } = this.app.lib.aneka
@@ -54,14 +23,13 @@ async function formSelectExt () {
54
23
  const xref = this.params.attr['x-ref'] ?? 'select'
55
24
  this.params.attr.id = this.params.attr.id ?? generateId('alpha')
56
25
  this.params.attr['x-ref'] = xref
57
- this.params.attr['x-data'] = `{
58
- instance: null
59
- }`
26
+ const xData = ['instance: null', 'value: null']
60
27
  const plugins = ['drag_drop']
61
28
  if (!this.params.attr.noDropdownInput) plugins.push('dropdown_input')
62
29
  if (this.params.attr.removeBtn) plugins.push('remove_button')
63
30
  if (this.params.attr.clearBtn) plugins.push('clear_button')
64
31
  if (this.params.attr.optgroupColumns) plugins.push('optgroup_columns')
32
+ if (this.params.attr.noCaret) this.params.attr.class.push('no-caret') // TODO: no caret remove caret on ALL instances, need to make it instance specific
65
33
  let options = []
66
34
  if (this.params.attr.options) {
67
35
  try {
@@ -92,7 +60,7 @@ async function formSelectExt () {
92
60
  if (group.remote.apiKey === true) fetchOpts.headers.Authorization = `Bearer ${apiKey}` // TODO: get it from wmpa
93
61
  else fetchOpts.headers.Authorization = `Bearer ${group.remote.apiKey}`
94
62
  }
95
- opts = `{
63
+ opts = opts.slice(0, -1) + `,
96
64
  searchField: '${group.remote.searchField}',
97
65
  labelField: '${group.remote.labelField}',
98
66
  valueField: '${group.remote.valueField}',
@@ -117,26 +85,52 @@ async function formSelectExt () {
117
85
  }
118
86
  }`
119
87
  }
120
-
121
- this.params.attr['@load.window'] = `
88
+ let text = `onLoad () {
122
89
  const opts = ${opts}
123
- instance = new TomSelect($refs.${xref}, opts)
90
+ this.instance = new TomSelect($refs.${xref}, opts)
124
91
  const val = $refs.${xref}.dataset.value
92
+ if (!_.isEmpty(val)) {
93
+ this.value = val.split('|')
94
+ }
125
95
  `
96
+ if (this.params.attr.valueStore) {
97
+ const [store, key] = this.params.attr.valueStore.split(':')
98
+ text += `
99
+ this.value = Alpine.store('${store}').${key}
100
+ this.instance.on('change', value => {
101
+ this.value = _.cloneDeep(value)
102
+ Alpine.store('${store}').${key} = this.value
103
+ })
104
+ `
105
+ }
126
106
  if (group.remote) {
127
- this.params.attr['@load.window'] += `
128
- if (!_.isEmpty(val)) {
129
- fetch('${group.remote.url}?query=${group.remote.valueField}:' + val, ${jsonStringify(fetchOpts, true)})
107
+ text += `
108
+ if (!_.isEmpty(this.value)) {
109
+ if (!_.isArray(this.value)) this.value = [this.value]
110
+ let query = '${group.remote.valueField}:['
111
+ let q = ''
112
+ for (const v of this.value) {
113
+ q += ',' + v
114
+ }
115
+ query += q.slice(1) + ']'
116
+ fetch('${group.remote.url}?query=' + query, ${jsonStringify(fetchOpts, true)})
130
117
  .then(resp => resp.json())
131
118
  .then(json => {
132
119
  if (json.data.length === 0) return
133
- const opt = _.pick(json.data[0], ['${group.remote.valueField}', '${group.remote.labelField}'])
134
- instance.addOption(opt)
135
- instance.setValue(opt.${group.remote.valueField})
120
+ for (const d of json.data) {
121
+ const opt = _.pick(d, ['${group.remote.valueField}', '${group.remote.labelField}'])
122
+ this.instance.addOption(opt)
123
+ }
124
+ this.instance.setValue(json.data.map(item => item.${group.remote.valueField}))
136
125
  })
137
126
  }
138
127
  `
139
128
  }
129
+ text += '}'
130
+ xData.push(text)
131
+ this.params.attr['x-data'] = `{ ${xData.join(',\n')} }`
132
+ // this.params.attr['@load.window'] = 'onLoad()'
133
+ this.params.attr['x-init'] = 'onLoad()'
140
134
  this.params.attr.options = options
141
135
  this.params.attr = omit(this.params.attr, ['noDropdownInput', 'removeBtn', 'clearBtn', 'c-opts', 'remoteUrl', 'remoteSearchField', 'remoteLabelField', 'remoteValueField'])
142
136
  await build.call(this, buildFormSelect, this.params)
@@ -0,0 +1,34 @@
1
+ .ts-dropdown {
2
+ min-width: 242px;
3
+ }
4
+ .ts-control {
5
+ padding-top: 0px;
6
+ }
7
+ .ts-wrapper {
8
+ margin-left: calc(var(--bs-border-width) * -1) !important;
9
+ border-top-left-radius: var(--bs-border-radius) !important;
10
+ border-bottom-left-radius: var(--bs-border-radius) !important;
11
+ white-space: nowrap !important;
12
+ }
13
+ .ts-control, .ts-control input, .ts-dropdown {
14
+ color: inherit;
15
+ }
16
+ .form-floating > .ts-wrapper {
17
+ padding-top: 1.625rem !important;
18
+ }
19
+
20
+ .ts-wrapper.focus {
21
+ border-color: #86b7fe;
22
+ outline: 0;
23
+ box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
24
+ }
25
+
26
+ .focus .ts-control {
27
+ box-shadow: none;
28
+ border: none;
29
+ box-shadow: none;
30
+ }
31
+
32
+ .form-select.no-caret {
33
+ --bs-form-select-bg-img: none !important;
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-bootstrap",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "Bootstrap suport for Waibu Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-02-15
4
+
5
+ - [2.3.0] Add capability to use custom tag on ```select```
6
+ - [2.3.0] Now you can hide caret on ```<c:form-select-ext />``` with ```no-caret``` attribute
7
+ - [2.3.0] Add ```value-store="name:key"``` to read/write value to Alpine's store
8
+
3
9
  ## 2026-02-11
4
10
 
5
11
  - [2.2.3] Bug fix on widget attribute ```rounded```