waibu-mpa 2.13.1 → 2.14.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.
@@ -309,7 +309,8 @@ class Wmpa {
309
309
 
310
310
  parseValue = (value, type) => {
311
311
  try {
312
- if (['integer', 'smallint'].includes(type)) value = parseInt(value)
312
+ if (type === 'boolean') value = value === 'true'
313
+ else if (['integer', 'smallint'].includes(type)) value = parseInt(value)
313
314
  else if (['float', 'double'].includes(type)) value = parseFloat(value)
314
315
  else if (['datetime', 'date', 'time'].includes(type)) value = new Date(Date.parse(value))
315
316
  else if (['array', 'object'].includes(type)) value = JSON.parse(value)
@@ -27,11 +27,11 @@ async function meta (options) {
27
27
  await runHook(`${this.ns}.${theme.name}:afterInjectMeta`, { meta: theme.meta, items, req })
28
28
  }
29
29
  // title
30
- const formatter = get(this, 'app.waibuMpa.pageTitleFormat', '%s : %s')
30
+ const format = get(this, 'app.waibuMpa.pageTitleFormat', '%s : %s')
31
31
  const title = page.fullTitle ?? page.title
32
32
  let pageTitle
33
- if (isFunction(formatter)) pageTitle = await formatter.call(this, locals)
34
- else pageTitle = sprintf(formatter, title, this.app.waibuMpa.getAppTitle(req))
33
+ if (isFunction(format)) pageTitle = await format.call(this, locals)
34
+ else pageTitle = sprintf(format, title, this.app.waibuMpa.getAppTitle(req))
35
35
  $('head').append(`<title>${pageTitle}</title>`)
36
36
  // favicon
37
37
  const favicon = this.app.waibuMpa.config.favicon
@@ -1,6 +1,8 @@
1
1
  import path from 'path'
2
2
 
3
3
  async function widgetFactory () {
4
+ const { kebabCase, get } = this.app.lib._
5
+
4
6
  class MpaWidget extends this.app.baseClass.MpaTools {
5
7
  static scripts = []
6
8
  static css = []
@@ -10,10 +12,19 @@ async function widgetFactory () {
10
12
 
11
13
  constructor ({ component = {}, params = {} } = {}) {
12
14
  super(component.plugin)
15
+ const names = kebabCase(this.constructor.name).split('-')
16
+ const alias = names.length > 1 ? names[0] : 'wbs'
17
+ let plugin = this.app.bajo.getPlugin(alias, true)
18
+ if (!plugin) plugin = this.app.waibuBootstrap
19
+ this.plugin = plugin
20
+ this.app = plugin.app
13
21
  this.component = component
14
22
  this.params = params
15
23
  this.block = {}
16
24
  this.setting = this._parseBase64Attr(this.params.attr.setting)
25
+ this.formData = get(this, `component.locals.${this.params.attr.keyLocals ?? 'form'}`, {})
26
+ this.oldData = get(this, `component.locals.${this.params.attr.keyOldData ?? 'oldData'}`, {})
27
+ this.schema = get(this, `component.locals.${this.params.attr.keySchema ?? 'schema'}`, {})
17
28
  }
18
29
 
19
30
  _parseBase64Attr = (text, defValue = {}) => {
@@ -86,6 +97,47 @@ async function widgetFactory () {
86
97
  if (!escape) return content
87
98
  return content.replaceAll("'", "\\'")
88
99
  }
100
+
101
+ getProp = (name) => {
102
+ const { find } = this.app.lib._
103
+ const prop = find(this.schema.properties ?? [], { name }) ?? {}
104
+ return prop
105
+ }
106
+
107
+ getRef = ({ field, refName, returning } = {}) => {
108
+ const { get, find } = this.app.lib._
109
+ const prop = find(this.schema.properties ?? [], p => p.name === field)
110
+ if (!prop) return {}
111
+ if (!refName && field.endsWith('Id')) refName = field.slice(0, -2)
112
+ const key = this.params.attr.refName ?? refName
113
+ const ref = get(prop, `ref.${key}`, {})
114
+ if (returning === 'all') return { ref, key }
115
+ else if (returning === 'key') return key
116
+ return ref
117
+ }
118
+
119
+ getRefValue = ({ field, data, labelField, refName } = {}) => {
120
+ const { get, isEmpty } = this.app.lib._
121
+ const { ref, key } = this.getRef({ field, refName, returning: 'all' })
122
+ if (isEmpty(ref)) return undefined
123
+ labelField = labelField ?? ref.labelField ?? 'id'
124
+ return (get(data ?? this.formData, `_ref.${key}.${labelField}`))
125
+ }
126
+
127
+ getRefName = (field) => {
128
+ const { get } = this.app.lib._
129
+ let refName = get(this.schema, `view.widget.${field}.attr.ref-name`, this.params.attr.refName)
130
+ if (!refName && this.params.attr[field] && this.params.attr[field].endsWith('Id')) refName = this.params.attr[field].slice(0, -2)
131
+ return refName
132
+ }
133
+
134
+ getSetting = (key, defValue) => {
135
+ const { get, camelCase } = this.app.lib._
136
+ const widgetName = camelCase(this.constructor.name)
137
+ key = key.replaceAll('{self}', widgetName)
138
+ const cfg = this.app.waibu.getSetting(`${this.plugin.ns}:${key}`, { defValue, req: this.component.req })
139
+ return get(this.schema, `view.${key}`, cfg)
140
+ }
89
141
  }
90
142
 
91
143
  this.app.baseClass.MpaWidget = MpaWidget
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-mpa",
3
- "version": "2.13.1",
3
+ "version": "2.14.0",
4
4
  "description": "MPA support for Waibu Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-04-17
4
+
5
+ - [2.14.0] Add data binding properties to ```Widget``` base class
6
+ - [2.14.0] Add ```Widget.getRef()```
7
+ - [2.14.0] Add ```Widget.getRefValue()```
8
+ - [2.14.0] Add ```Widget.getRefName()```
9
+ - [2.14.0] Add ```Widget.getSetting()```
10
+
11
+ ## 2026-04-11
12
+
13
+ - [2.13.2] Bug fix in ```Wmpa.parseValue()```
14
+ - [2.13.2] Bug fix in ```Widget.plugin``` now match the right plugin
15
+
3
16
  ## 2026-04-07
4
17
 
5
18
  - [2.13.0] Bug fix in ```component.buildOptions()```