waibu-mpa 2.13.2 → 2.14.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.
@@ -1,7 +1,8 @@
1
1
  import path from 'path'
2
2
 
3
3
  async function widgetFactory () {
4
- const { kebabCase } = this.app.lib._
4
+ const { kebabCase, get } = this.app.lib._
5
+
5
6
  class MpaWidget extends this.app.baseClass.MpaTools {
6
7
  static scripts = []
7
8
  static css = []
@@ -21,6 +22,9 @@ async function widgetFactory () {
21
22
  this.params = params
22
23
  this.block = {}
23
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'}`, {})
24
28
  }
25
29
 
26
30
  _parseBase64Attr = (text, defValue = {}) => {
@@ -93,6 +97,56 @@ async function widgetFactory () {
93
97
  if (!escape) return content
94
98
  return content.replaceAll("'", "\\'")
95
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) refName = this.getRefName(field)
112
+ const key = refName ?? this.params.attr.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, find } = this.app.lib._
129
+ const prop = find(this.schema.properties ?? [], p => p.name === field) ?? {}
130
+ if (!prop.ref) return
131
+ const keys = Object.keys(prop.ref)
132
+ let refName = get(this.schema, `view.widget.${field}.attr.refName`, this.params.attr.refName)
133
+ if (!refName) {
134
+ if (keys.includes(field)) refName = field
135
+ else if (field.endsWith('Id')) {
136
+ refName = field.slice(0, -2)
137
+ refName = keys.includes(refName) ? refName : undefined
138
+ }
139
+ }
140
+ return refName
141
+ }
142
+
143
+ getSetting = (key, defValue) => {
144
+ const { get, camelCase } = this.app.lib._
145
+ const widgetName = camelCase(this.constructor.name)
146
+ key = key.replaceAll('{self}', widgetName)
147
+ const cfg = this.app.waibu.getSetting(`${this.plugin.ns}:${key}`, { defValue, req: this.component.req })
148
+ return get(this.schema, `view.${key}`, cfg)
149
+ }
96
150
  }
97
151
 
98
152
  this.app.baseClass.MpaWidget = MpaWidget
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-mpa",
3
- "version": "2.13.2",
3
+ "version": "2.14.1",
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-18
4
+
5
+ - [2.14.1] Bug fix in ```getRef()``` in ```MpaWidget```
6
+ - [2.14.1] Bug fix in ```getRefName()``` in ```MpaWidget```
7
+
8
+ ## 2026-04-17
9
+
10
+ - [2.14.0] Add data binding properties to ```Widget``` base class
11
+ - [2.14.0] Add ```Widget.getRef()```
12
+ - [2.14.0] Add ```Widget.getRefValue()```
13
+ - [2.14.0] Add ```Widget.getRefName()```
14
+ - [2.14.0] Add ```Widget.getSetting()```
15
+
3
16
  ## 2026-04-11
4
17
 
5
18
  - [2.13.2] Bug fix in ```Wmpa.parseValue()```