@onekeyfe/react-native-native-list 6.7.0-57 → 6.7.0-59
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.
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +15 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +60 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +5 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +75 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
- package/docs/ROW_TEMPLATES.md +4 -1
- package/docs/SPEC.md +55 -0
- package/ios/NativeListActivityDetailsView.swift +13 -5
- package/ios/NativeListResolvedText.swift +15 -4
- package/ios/NativeListTextLabel.swift +106 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +270 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +1 -0
- package/lib/module/validation.js +19 -2
- package/lib/module/web/templates/ActivityRowRenderer.js +29 -23
- package/lib/typescript/src/models.d.ts +9 -1
- package/package.json +1 -1
- package/src/models.ts +9 -0
- package/src/validation.ts +34 -0
- package/src/web/templates/ActivityRowRenderer.ts +42 -32
|
@@ -60,6 +60,276 @@ final class NativeListActivityPresentationTests: XCTestCase {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// The description label spans the identity column, so a tap anywhere on its
|
|
64
|
+
// line used to open the description action. Only the action text opens it
|
|
65
|
+
// now; the blank rest of the line belongs to the row press (OK-67219). Where
|
|
66
|
+
// that text starts is the caller's `descriptionActionStart`, never something
|
|
67
|
+
// read out of the string.
|
|
68
|
+
func testDescriptionActionTakesTouchesOnItsTextOnly() throws {
|
|
69
|
+
let details = NativeListActivityDetailsView()
|
|
70
|
+
// Wide enough that the label keeps blank space beside its text even when
|
|
71
|
+
// the amounts take their full half of the row.
|
|
72
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: 600, height: 300))
|
|
73
|
+
details.translatesAutoresizingMaskIntoConstraints = false
|
|
74
|
+
container.addSubview(details)
|
|
75
|
+
NSLayoutConstraint.activate([
|
|
76
|
+
details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
77
|
+
details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
78
|
+
details.topAnchor.constraint(equalTo: container.topAnchor),
|
|
79
|
+
])
|
|
80
|
+
func bind(description: String, actionKey: String?, actionStart: Int? = nil) throws -> NativeListTextLabel {
|
|
81
|
+
var data: [String: Any] = [
|
|
82
|
+
"type": "activity", "key": "tx", "title": "Swap", "description": description,
|
|
83
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
84
|
+
"amounts": [["key": "send", "text": "-1"]],
|
|
85
|
+
]
|
|
86
|
+
if let actionKey { data["descriptionActionKey"] = actionKey }
|
|
87
|
+
if let actionStart { data["descriptionActionStart"] = actionStart }
|
|
88
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
89
|
+
container.layoutIfNeeded()
|
|
90
|
+
func find(_ view: UIView) -> NativeListTextLabel? {
|
|
91
|
+
if let label = view as? NativeListTextLabel, label.text == description { return label }
|
|
92
|
+
return view.subviews.lazy.compactMap(find).first
|
|
93
|
+
}
|
|
94
|
+
return try XCTUnwrap(find(details))
|
|
95
|
+
}
|
|
96
|
+
func hit(_ label: NativeListTextLabel, x: CGFloat) -> Bool {
|
|
97
|
+
label.point(inside: CGPoint(x: x, y: label.bounds.midY), with: nil)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Without a start the whole text is the action, also a label holding the
|
|
101
|
+
// separator a time prefix would use.
|
|
102
|
+
let label = try bind(description: "Router • V2", actionKey: "address-info")
|
|
103
|
+
let labelText = try XCTUnwrap(label.touchableTextRegions.first)
|
|
104
|
+
XCTAssertEqual(label.touchableTextStart, 0)
|
|
105
|
+
XCTAssertEqual(label.touchableTextRegions.count, 1)
|
|
106
|
+
XCTAssertGreaterThan(label.bounds.width, labelText.maxX + 40)
|
|
107
|
+
XCTAssertTrue(hit(label, x: 4))
|
|
108
|
+
XCTAssertTrue(hit(label, x: labelText.maxX - 12))
|
|
109
|
+
XCTAssertFalse(hit(label, x: label.bounds.maxX - 4))
|
|
110
|
+
|
|
111
|
+
// With a start only the text from there on is the action: the time is
|
|
112
|
+
// not, the complete label behind it is.
|
|
113
|
+
let prefix = "08:48 • "
|
|
114
|
+
let timed = try bind(
|
|
115
|
+
description: prefix + "Router • V2", actionKey: "address-info",
|
|
116
|
+
actionStart: (prefix as NSString).length)
|
|
117
|
+
let timedText = try XCTUnwrap(timed.touchableTextRegions.first)
|
|
118
|
+
XCTAssertEqual(timed.touchableTextRegions.count, 1)
|
|
119
|
+
XCTAssertGreaterThan(timed.bounds.width, timedText.maxX + 40)
|
|
120
|
+
// The same label, less the slop on the side where the time is.
|
|
121
|
+
XCTAssertEqual(timedText.width, labelText.width - 8, accuracy: 1)
|
|
122
|
+
XCTAssertFalse(hit(timed, x: 4))
|
|
123
|
+
XCTAssertFalse(hit(timed, x: timedText.minX - 2))
|
|
124
|
+
XCTAssertTrue(hit(timed, x: timedText.minX + 2))
|
|
125
|
+
XCTAssertTrue(hit(timed, x: timedText.maxX - 12))
|
|
126
|
+
XCTAssertFalse(hit(timed, x: timed.bounds.maxX - 4))
|
|
127
|
+
|
|
128
|
+
// The start counts UTF-16 units: the emoji takes two.
|
|
129
|
+
let emojiPrefix = "🕘 08:48 • "
|
|
130
|
+
XCTAssertEqual((emojiPrefix as NSString).length, 11)
|
|
131
|
+
let emoji = try bind(
|
|
132
|
+
description: emojiPrefix + "Router • V2", actionKey: "address-info", actionStart: 11)
|
|
133
|
+
let emojiText = try XCTUnwrap(emoji.touchableTextRegions.first)
|
|
134
|
+
XCTAssertEqual(emojiText.width, labelText.width - 8, accuracy: 1)
|
|
135
|
+
XCTAssertFalse(hit(emoji, x: 4))
|
|
136
|
+
XCTAssertFalse(hit(emoji, x: emojiText.minX - 2))
|
|
137
|
+
XCTAssertTrue(hit(emoji, x: emojiText.minX + 2))
|
|
138
|
+
XCTAssertTrue(hit(emoji, x: emojiText.maxX - 12))
|
|
139
|
+
|
|
140
|
+
// A start at the end of the text, or clamped to it, leaves nothing to tap.
|
|
141
|
+
// 4294967296 is a safe integer past 32 bits; it must clamp, not wrap to 0.
|
|
142
|
+
for start in [(prefix as NSString).length, 99, 4_294_967_296] {
|
|
143
|
+
let ended = try bind(description: prefix, actionKey: "address-info", actionStart: start)
|
|
144
|
+
XCTAssertTrue(ended.touchableTextRegions.isEmpty)
|
|
145
|
+
XCTAssertFalse(ended.isUserInteractionEnabled)
|
|
146
|
+
XCTAssertFalse(hit(ended, x: 4))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The reused view keeps no state: a rebind without a start covers the
|
|
150
|
+
// whole text again, one without the action restores the label's own hit
|
|
151
|
+
// testing even when a start is still supplied, and so does recycling.
|
|
152
|
+
let rebound = try bind(description: "Router • V2", actionKey: "address-info")
|
|
153
|
+
XCTAssertEqual(rebound.touchableTextStart, 0)
|
|
154
|
+
XCTAssertTrue(rebound.isUserInteractionEnabled)
|
|
155
|
+
XCTAssertTrue(hit(rebound, x: 4))
|
|
156
|
+
let plain = try bind(description: "Router • V2", actionKey: nil, actionStart: 3)
|
|
157
|
+
XCTAssertNil(plain.touchableTextStart)
|
|
158
|
+
XCTAssertFalse(plain.isUserInteractionEnabled)
|
|
159
|
+
XCTAssertTrue(hit(plain, x: plain.bounds.maxX - 4))
|
|
160
|
+
let recycled = try bind(
|
|
161
|
+
description: prefix + "Router", actionKey: "address-info",
|
|
162
|
+
actionStart: (prefix as NSString).length)
|
|
163
|
+
XCTAssertEqual(recycled.touchableTextStart, (prefix as NSString).length)
|
|
164
|
+
details.recycle()
|
|
165
|
+
XCTAssertNil(recycled.touchableTextStart)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A narrow column wraps "time • address". The time stays outside the action
|
|
169
|
+
// on its line, while the address is hit on both lines, also at the x the
|
|
170
|
+
// time occupies one line above. The label is sized directly so the wrap does
|
|
171
|
+
// not depend on how the row shares its width.
|
|
172
|
+
func testWrappedDescriptionKeepsTheTimeOutsideTheAction() throws {
|
|
173
|
+
let description = "08:48 • Uniswap Router"
|
|
174
|
+
let label = NativeListTextLabel()
|
|
175
|
+
NativeListResolvedText(
|
|
176
|
+
description, style: nil, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
177
|
+
fonts: NativeListFontFamilies()
|
|
178
|
+
).bind(label)
|
|
179
|
+
label.frame = CGRect(x: 0, y: 0, width: 142, height: 40)
|
|
180
|
+
label.touchableTextStart = ("08:48 • " as NSString).length
|
|
181
|
+
func hit(_ x: CGFloat, _ y: CGFloat) -> Bool {
|
|
182
|
+
label.point(inside: CGPoint(x: x, y: y), with: nil)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let lines = label.touchableTextRegions
|
|
186
|
+
XCTAssertEqual(lines.count, 2)
|
|
187
|
+
guard lines.count == 2 else { return }
|
|
188
|
+
XCTAssertFalse(hit(4, lines[0].midY))
|
|
189
|
+
XCTAssertTrue(hit(lines[0].maxX - 12, lines[0].midY))
|
|
190
|
+
XCTAssertTrue(hit(4, lines[1].midY))
|
|
191
|
+
XCTAssertFalse(hit(label.bounds.maxX - 2, lines[1].midY))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The first line holds only the time, so it takes no touches, and the slop
|
|
195
|
+
// of the address line below it must not reach up into the time.
|
|
196
|
+
func testAddressStartingOnTheSecondLineLeavesTheTimeLineAlone() throws {
|
|
197
|
+
let prefix = "08:48 • "
|
|
198
|
+
let address = "UniswapUniversalRouter"
|
|
199
|
+
func text(_ value: String) -> NativeListResolvedText {
|
|
200
|
+
NativeListResolvedText(
|
|
201
|
+
value, style: nil, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
202
|
+
fonts: NativeListFontFamilies())
|
|
203
|
+
}
|
|
204
|
+
let label = NativeListTextLabel()
|
|
205
|
+
text(prefix + address).bind(label)
|
|
206
|
+
// Wide enough for the address alone, too narrow for the time beside it.
|
|
207
|
+
label.frame = CGRect(x: 0, y: 0, width: text(address).measureWidth() + 4, height: 40)
|
|
208
|
+
label.touchableTextStart = (prefix as NSString).length
|
|
209
|
+
func hit(y: CGFloat) -> Bool { label.point(inside: CGPoint(x: 4, y: y), with: nil) }
|
|
210
|
+
|
|
211
|
+
let line = try XCTUnwrap(label.touchableTextRegions.first)
|
|
212
|
+
XCTAssertEqual(label.touchableTextRegions.count, 1)
|
|
213
|
+
XCTAssertEqual(line.minY, 20, accuracy: 0.5)
|
|
214
|
+
XCTAssertFalse(hit(y: 10))
|
|
215
|
+
XCTAssertFalse(hit(y: line.minY - 2))
|
|
216
|
+
XCTAssertTrue(hit(y: line.minY + 2))
|
|
217
|
+
// The last line of the layout still takes its slop below the text.
|
|
218
|
+
XCTAssertTrue(hit(y: label.bounds.maxY + 4))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private func descriptionText(_ value: String, style: [String: Any]? = nil) -> NativeListResolvedText {
|
|
222
|
+
NativeListResolvedText(
|
|
223
|
+
value, style: style, size: 14, color: .label, lineHeight: 20, lines: 1,
|
|
224
|
+
fonts: NativeListFontFamilies())
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/// Width the description font gives `value` on its own.
|
|
228
|
+
private func descriptionWidth(_ value: String) -> CGFloat {
|
|
229
|
+
descriptionText(value).attributed(direction: .leftToRight).size().width
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private func descriptionLabel(
|
|
233
|
+
_ value: String, start: Int, width: CGFloat = 300, style: [String: Any]? = nil
|
|
234
|
+
) -> NativeListTextLabel {
|
|
235
|
+
let label = NativeListTextLabel()
|
|
236
|
+
descriptionText(value, style: style).bind(label)
|
|
237
|
+
label.frame = CGRect(x: 0, y: 0, width: width, height: 20)
|
|
238
|
+
label.touchableTextStart = start
|
|
239
|
+
return label
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private func hit(_ label: NativeListTextLabel, x: CGFloat) -> Bool {
|
|
243
|
+
label.point(inside: CGPoint(x: x, y: label.bounds.midY), with: nil)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// The slop is for blank space. It stops at plain text beside the action
|
|
247
|
+
// text, or a prefix narrower than the slop, like the "i" of "iRouter", would
|
|
248
|
+
// open an action it is not part of.
|
|
249
|
+
func testSlopStopsAtPlainTextBesideTheActionText() throws {
|
|
250
|
+
let short = descriptionLabel("iRouter", start: 1)
|
|
251
|
+
let i = descriptionWidth("i")
|
|
252
|
+
XCTAssertLessThan(i, 8)
|
|
253
|
+
let region = try XCTUnwrap(short.touchableTextRegions.first)
|
|
254
|
+
XCTAssertEqual(short.touchableTextRegions.count, 1)
|
|
255
|
+
XCTAssertEqual(region.minX, i, accuracy: 0.5)
|
|
256
|
+
XCTAssertFalse(hit(short, x: i / 2))
|
|
257
|
+
XCTAssertFalse(hit(short, x: -3))
|
|
258
|
+
XCTAssertTrue(hit(short, x: i + 2))
|
|
259
|
+
// Into the blank after the text the slop still reaches.
|
|
260
|
+
XCTAssertTrue(hit(short, x: descriptionWidth("iRouter") + 6))
|
|
261
|
+
XCTAssertFalse(hit(short, x: descriptionWidth("iRouter") + 10))
|
|
262
|
+
// And into the blank before a line that starts with the action text.
|
|
263
|
+
XCTAssertTrue(hit(descriptionLabel("Router", start: 0), x: -6))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Mixed-direction text can split one logical suffix into several visual
|
|
267
|
+
// runs. From offset 6 of "ABC אבג XYZ" the suffix is the last Hebrew letter
|
|
268
|
+
// and " XYZ"; the Hebrew run is drawn right to left, so that letter sits
|
|
269
|
+
// left of the two plain ones. Each run is its own region and the plain text
|
|
270
|
+
// between them takes no touches.
|
|
271
|
+
func testMixedDirectionSuffixFollowsTheLaidOutRuns() {
|
|
272
|
+
let label = descriptionLabel("ABC \u{05D0}\u{05D1}\u{05D2} XYZ", start: 6)
|
|
273
|
+
let abc = descriptionWidth("ABC ")
|
|
274
|
+
let last = descriptionWidth("\u{05D2}")
|
|
275
|
+
let plain = descriptionWidth("\u{05D1}\u{05D0}")
|
|
276
|
+
let xyz = descriptionWidth(" XYZ")
|
|
277
|
+
let regions = label.touchableTextRegions.sorted { $0.minX < $1.minX }
|
|
278
|
+
XCTAssertEqual(regions.count, 2)
|
|
279
|
+
guard regions.count == 2 else { return }
|
|
280
|
+
XCTAssertEqual(regions[0].minX, abc, accuracy: 1)
|
|
281
|
+
XCTAssertEqual(regions[0].maxX, abc + last, accuracy: 1)
|
|
282
|
+
XCTAssertEqual(regions[1].minX, abc + last + plain, accuracy: 1)
|
|
283
|
+
XCTAssertFalse(hit(label, x: abc / 2))
|
|
284
|
+
XCTAssertTrue(hit(label, x: abc + last / 2))
|
|
285
|
+
XCTAssertFalse(hit(label, x: abc + last + plain / 2))
|
|
286
|
+
XCTAssertTrue(hit(label, x: abc + last + plain + xyz / 2))
|
|
287
|
+
// Only the outer edge of the last run faces blank space.
|
|
288
|
+
XCTAssertTrue(hit(label, x: abc + last + plain + xyz + 5))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// A one-line description that does not fit ends in an ellipsis. Action text
|
|
292
|
+
// it only shortens stays touchable up to and including the ellipsis. Once it
|
|
293
|
+
// hides the action text altogether the ellipsis also stands for plain text,
|
|
294
|
+
// and nothing is left to touch.
|
|
295
|
+
func testTruncationCanHideTheActionText() throws {
|
|
296
|
+
let cut = descriptionLabel(
|
|
297
|
+
"08:48 • UniswapUniversalRouterWithAVeryLongName", start: 8, width: 150,
|
|
298
|
+
style: ["lines": 1])
|
|
299
|
+
let region = try XCTUnwrap(cut.touchableTextRegions.first)
|
|
300
|
+
XCTAssertEqual(cut.touchableTextRegions.count, 1)
|
|
301
|
+
XCTAssertEqual(region.minX, descriptionWidth("08:48 • "), accuracy: 1)
|
|
302
|
+
XCTAssertFalse(hit(cut, x: 20))
|
|
303
|
+
XCTAssertTrue(hit(cut, x: 100))
|
|
304
|
+
XCTAssertTrue(hit(cut, x: 145))
|
|
305
|
+
|
|
306
|
+
let prefix = "A very long plain prefix that fills the row • "
|
|
307
|
+
let hidden = descriptionLabel(
|
|
308
|
+
prefix + "Router", start: (prefix as NSString).length, width: 150, style: ["lines": 1])
|
|
309
|
+
XCTAssertTrue(hidden.touchableTextRegions.isEmpty)
|
|
310
|
+
XCTAssertFalse(hit(hidden, x: 145))
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// A one-line description folds each line break into one space, so the
|
|
314
|
+
// caller's offset is mapped onto the displayed text and kept inside it.
|
|
315
|
+
func testDescriptionActionStartFollowsTheDisplayedText() {
|
|
316
|
+
let source = "08:48\r\n• Router"
|
|
317
|
+
func text(_ style: [String: Any]?) -> NativeListResolvedText {
|
|
318
|
+
NativeListResolvedText(
|
|
319
|
+
source, style: style, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
320
|
+
fonts: NativeListFontFamilies())
|
|
321
|
+
}
|
|
322
|
+
let oneLine = text(["lines": 1])
|
|
323
|
+
XCTAssertEqual(oneLine.text, "08:48 • Router")
|
|
324
|
+
XCTAssertEqual(oneLine.displayOffset(9, in: source), 8)
|
|
325
|
+
XCTAssertEqual(oneLine.displayOffset(-3, in: source), 0)
|
|
326
|
+
XCTAssertEqual(oneLine.displayOffset(99, in: source), 14)
|
|
327
|
+
let wrapping = text(nil)
|
|
328
|
+
XCTAssertEqual(wrapping.text, source)
|
|
329
|
+
XCTAssertEqual(wrapping.displayOffset(9, in: source), 9)
|
|
330
|
+
XCTAssertEqual(wrapping.displayOffset(99, in: source), 15)
|
|
331
|
+
}
|
|
332
|
+
|
|
63
333
|
func testSmallNumberRunsPreserveBaselineAcrossAmountsFiatAndFee() throws {
|
|
64
334
|
func segments(_ prefix: String, _ suffix: String) -> [[String: Any]] {
|
|
65
335
|
[["text": prefix], ["text": "5", "style": "subscript"], ["text": suffix]]
|
|
@@ -44,6 +44,7 @@ final class NativeListMediaVisibilityTests: XCTestCase {
|
|
|
44
44
|
@MainActor
|
|
45
45
|
final class NativeListMediaFrameCaptureTests: XCTestCase {
|
|
46
46
|
func testVisibleVideoReleasesPlayerAfterCapturingFirstFrame() throws {
|
|
47
|
+
XCTAssertEqual(UIApplication.shared.applicationState, .active, "Video capture requires a foreground app host")
|
|
47
48
|
let url = try writeVideo()
|
|
48
49
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
49
50
|
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
package/lib/module/validation.js
CHANGED
|
@@ -814,12 +814,18 @@ function assertVisual(row, path) {
|
|
|
814
814
|
assertLeadingVisual(visual, `${path}.visual[${index}]`);
|
|
815
815
|
});
|
|
816
816
|
}
|
|
817
|
+
|
|
818
|
+
/** The type half of the `descriptionActionStart` contract; the range needs the row. */
|
|
819
|
+
function isDescriptionActionStart(value) {
|
|
820
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
821
|
+
}
|
|
817
822
|
function assertActivity(row, path) {
|
|
818
823
|
if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean') fail(`${path}.hideLeading`, 'must be boolean');
|
|
819
824
|
assertText(row.title, `${path}.title`);
|
|
820
825
|
assertText(row.description, `${path}.description`);
|
|
821
826
|
if (row.presentation !== undefined && !['stacked', 'table'].includes(row.presentation)) fail(`${path}.presentation`, 'must be stacked or table');
|
|
822
827
|
if (row.descriptionActionKey !== undefined) assertKey(row.descriptionActionKey, `${path}.descriptionActionKey`);
|
|
828
|
+
if (row.descriptionActionStart !== undefined && !isDescriptionActionStart(row.descriptionActionStart)) fail(`${path}.descriptionActionStart`, 'must be a non-negative integer');
|
|
823
829
|
if ((row.amounts?.length ?? 0) > 32) fail(`${path}.amounts`, 'supports at most 32 amount lines');
|
|
824
830
|
const amountKeys = new Set();
|
|
825
831
|
row.amounts?.forEach((amount, index) => {
|
|
@@ -962,6 +968,9 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
962
968
|
break;
|
|
963
969
|
case 'activity':
|
|
964
970
|
assertActivity(row, path);
|
|
971
|
+
// Checked on the complete row only: a patch may carry the offset
|
|
972
|
+
// without the description it points into.
|
|
973
|
+
if ((row.descriptionActionStart ?? 0) > (row.description?.length ?? 0)) fail(`${path}.descriptionActionStart`, 'must not exceed the description length');
|
|
965
974
|
break;
|
|
966
975
|
case 'message':
|
|
967
976
|
if (row.presentation !== undefined && row.presentation !== 'inlineWarning') {
|
|
@@ -1229,7 +1238,7 @@ const ROW_FIELDS = {
|
|
|
1229
1238
|
identity: [...COMMON_ROW_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'presentation', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'titleLines', 'subtitleLines', 'badges', 'trailing', 'draggable'],
|
|
1230
1239
|
walletGroup: [...COMMON_ROW_FIELDS, 'parent', 'children', 'draggable'],
|
|
1231
1240
|
rail: [...COMMON_ROW_FIELDS, 'visual', 'title', 'status', 'badge', 'draggable'],
|
|
1232
|
-
activity: [...COMMON_ROW_FIELDS, 'leading', 'hideLeading', 'secondaryLeading', 'title', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'amounts', 'badges', 'presentation', 'fee', 'descriptionActionKey', 'footerActions'],
|
|
1241
|
+
activity: [...COMMON_ROW_FIELDS, 'leading', 'hideLeading', 'secondaryLeading', 'title', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'amounts', 'badges', 'presentation', 'fee', 'descriptionActionKey', 'descriptionActionStart', 'footerActions'],
|
|
1233
1242
|
message: [...COMMON_ROW_FIELDS, 'presentation', 'unread', 'leading', 'title', 'body', 'bodyLines', 'time', 'thumbnail'],
|
|
1234
1243
|
dataRow: [...COMMON_ROW_FIELDS, 'leading', 'columns', 'trailing', 'checkbox', 'index', 'badge', 'badges', 'favorite', 'favoriteActive'],
|
|
1235
1244
|
market: [...COMMON_ROW_FIELDS, 'variant', 'webTable', 'metrics', 'leadingAction', 'leading', 'title', 'subtitle', 'subtitlePrefix', 'subtitleSegments', 'price', 'priceSegments', 'change', 'badges', 'pressActionKey', 'pressInActionKey', 'longPressActionKey', 'diagnostics'],
|
|
@@ -1244,7 +1253,7 @@ const COMMON_PATCH_FIELDS = ['height', 'heightRounding', 'opacity', 'pressDisabl
|
|
|
1244
1253
|
const PATCH_FIELDS = {
|
|
1245
1254
|
identity: [...COMMON_PATCH_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'subtitleLines', 'badges', 'trailing'],
|
|
1246
1255
|
rail: [...COMMON_PATCH_FIELDS, 'title', 'visual', 'status', 'badge'],
|
|
1247
|
-
activity: [...COMMON_PATCH_FIELDS, 'presentation', 'leading', 'title', 'badges', 'status', 'hideLeading', 'secondaryLeading', 'description', 'primaryAmount', 'secondaryAmount', 'amounts', 'fee', 'descriptionActionKey', 'footerActions'],
|
|
1256
|
+
activity: [...COMMON_PATCH_FIELDS, 'presentation', 'leading', 'title', 'badges', 'status', 'hideLeading', 'secondaryLeading', 'description', 'primaryAmount', 'secondaryAmount', 'amounts', 'fee', 'descriptionActionKey', 'descriptionActionStart', 'footerActions'],
|
|
1248
1257
|
message: [...COMMON_PATCH_FIELDS, 'presentation', 'title', 'unread', 'body', 'bodyLines', 'time', 'thumbnail'],
|
|
1249
1258
|
dataRow: [...COMMON_PATCH_FIELDS, 'leading', 'badges', 'trailing', 'badge', 'columns', 'checkbox', 'index', 'favorite', 'favoriteActive'],
|
|
1250
1259
|
market: [...COMMON_PATCH_FIELDS, 'longPressActionKey', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'subtitle', 'badges', 'webTable', 'metrics', 'price', 'priceSegments', 'change', 'pressActionKey', 'pressInActionKey', 'diagnostics'],
|
|
@@ -1705,6 +1714,11 @@ function sanitizeRowForProduction(row) {
|
|
|
1705
1714
|
delete next[field];
|
|
1706
1715
|
continue;
|
|
1707
1716
|
}
|
|
1717
|
+
if (field === 'descriptionActionStart') {
|
|
1718
|
+
// Renderers clamp an offset past the text; anything else has no meaning.
|
|
1719
|
+
if (!isDescriptionActionStart(value)) delete next[field];
|
|
1720
|
+
continue;
|
|
1721
|
+
}
|
|
1708
1722
|
if (field === 'parent' && isRecord(value)) next[field] = sanitizeRowForProduction(value);else if (field === 'children' && Array.isArray(value)) next[field] = value.map(child => sanitizeRowForProduction(child));else {
|
|
1709
1723
|
const normalized = row.type === 'market' && field === 'metrics' ? sanitizeMarketMetrics(value) : sanitizeDecoration(value, field);
|
|
1710
1724
|
if (normalized === undefined) delete next[field];else next[field] = normalized;
|
|
@@ -2297,6 +2311,9 @@ function mergeAndValidateSingleRow(previous, patch, index) {
|
|
|
2297
2311
|
if (typeof changes.subtitle === 'string' && !('subtitleSegments' in changes) && previous.subtitleSegments !== undefined) changes.subtitleSegments = null;
|
|
2298
2312
|
if (Array.isArray(changes.subtitleSegments) && changes.subtitleSegments.length > 0 && !('subtitle' in changes) && previous.subtitle !== undefined) changes.subtitle = null;
|
|
2299
2313
|
}
|
|
2314
|
+
// The offset points into one specific description string, so a patch that
|
|
2315
|
+
// replaces the description without restating it falls back to the default.
|
|
2316
|
+
if (previous.type === 'activity' && 'description' in changes && changes.description !== previous.description && !('descriptionActionStart' in changes) && previous.descriptionActionStart !== undefined) changes.descriptionActionStart = null;
|
|
2300
2317
|
const merged = {
|
|
2301
2318
|
...previous
|
|
2302
2319
|
};
|
|
@@ -89,6 +89,8 @@ function recycleLegacy(body) {
|
|
|
89
89
|
const histories = new WeakMap();
|
|
90
90
|
const isHistory = row => row.presentation !== undefined || row.amounts !== undefined;
|
|
91
91
|
const ellipsis = 'min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
|
|
92
|
+
/** Width a description prefix always leaves for the action text after it. */
|
|
93
|
+
const descriptionActionReserve = '3em';
|
|
92
94
|
function valueText(node, text, segments, size, line, weight) {
|
|
93
95
|
node.textContent = text ?? '';
|
|
94
96
|
applyTextWeight(node, weight);
|
|
@@ -106,11 +108,10 @@ function createHistory(body, primitives) {
|
|
|
106
108
|
const badges = node('badges');
|
|
107
109
|
const description = node('description');
|
|
108
110
|
description.dataset.nlSlot = 'description';
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
description.append(descriptionTime, descriptionDot, descriptionAddress);
|
|
111
|
+
const descriptionPrefix = createElement(document, 'span');
|
|
112
|
+
const descriptionAction = createElement(document, 'button');
|
|
113
|
+
descriptionAction.type = 'button';
|
|
114
|
+
description.append(descriptionPrefix, descriptionAction);
|
|
114
115
|
const amounts = node('amounts');
|
|
115
116
|
const fee = node('fee');
|
|
116
117
|
const feeLabel = node('fee-label');
|
|
@@ -134,9 +135,8 @@ function createHistory(body, primitives) {
|
|
|
134
135
|
title,
|
|
135
136
|
badges,
|
|
136
137
|
description,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
descriptionAddress,
|
|
138
|
+
descriptionPrefix,
|
|
139
|
+
descriptionAction,
|
|
140
140
|
amounts,
|
|
141
141
|
amountRows: new Map(),
|
|
142
142
|
fee,
|
|
@@ -373,23 +373,29 @@ function bindHistory(body, row, primitives) {
|
|
|
373
373
|
v.badges.style.display = row.badges?.length ? 'flex' : 'none';
|
|
374
374
|
v.description.style.cssText = ellipsis + 'display:flex;max-width:100%;color:var(--nl-secondary);font-family:inherit;font-size:14px;line-height:20px;font-weight:400;font-variant-numeric:tabular-nums;';
|
|
375
375
|
applyTextWeight(v.description, 400);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
v.
|
|
376
|
+
// The caller states where the action text starts; the string is not parsed.
|
|
377
|
+
const description = row.description ?? '';
|
|
378
|
+
const actionStart = row.descriptionActionKey ? Math.min(Math.max(row.descriptionActionStart ?? 0, 0), description.length) : 0;
|
|
379
|
+
const actionText = description.slice(actionStart);
|
|
380
|
+
const boundAction = row.descriptionActionKey && actionText ? row.descriptionActionKey : '';
|
|
381
|
+
// `pre` keeps the space a prefix ends with; a line break stays a space.
|
|
382
|
+
v.descriptionPrefix.textContent = description.slice(0, actionStart).replace(/\r\n|[\r\n]/g, ' ');
|
|
383
|
+
// The prefix keeps its width and the action truncates first, as the tail of
|
|
384
|
+
// the one native label does. A prefix wider than the row is capped instead,
|
|
385
|
+
// or it would squeeze the action to nothing and leave no pointer target.
|
|
386
|
+
v.descriptionPrefix.style.cssText = `${ellipsis}flex-shrink:0;max-width:${actionText ? `calc(100% - ${descriptionActionReserve})` : '100%'};white-space:pre;display:${actionStart > 0 ? 'block' : 'none'}`;
|
|
387
|
+
v.descriptionAction.style.cssText = `${ellipsis}appearance:none;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;display:${actionText ? 'block' : 'none'};`;
|
|
388
|
+
v.descriptionAction.textContent = actionText;
|
|
383
389
|
v.description.style.display = row.description ? 'flex' : 'none';
|
|
384
|
-
v.
|
|
385
|
-
if (
|
|
386
|
-
v.
|
|
387
|
-
markActionAnchorSource(v.
|
|
388
|
-
v.
|
|
390
|
+
v.descriptionAction.tabIndex = boundAction ? 0 : -1;
|
|
391
|
+
if (boundAction) {
|
|
392
|
+
v.descriptionAction.dataset.nativeListAction = boundAction;
|
|
393
|
+
markActionAnchorSource(v.descriptionAction, 'description');
|
|
394
|
+
v.descriptionAction.style.cursor = 'pointer';
|
|
389
395
|
} else {
|
|
390
|
-
delete v.
|
|
391
|
-
delete v.
|
|
392
|
-
v.
|
|
396
|
+
delete v.descriptionAction.dataset.nativeListAction;
|
|
397
|
+
delete v.descriptionAction.dataset.nativeListAnchorSource;
|
|
398
|
+
v.descriptionAction.style.cursor = 'inherit';
|
|
393
399
|
}
|
|
394
400
|
if (row.style?.description) primitives.textStyle(v.description, row.style.description);
|
|
395
401
|
v.description.style.display = row.description ? 'flex' : 'none';
|
|
@@ -493,6 +493,14 @@ export type ActivityRow = RowBase & Readonly<{
|
|
|
493
493
|
hidden?: boolean;
|
|
494
494
|
}>;
|
|
495
495
|
descriptionActionKey?: string;
|
|
496
|
+
/**
|
|
497
|
+
* UTF-16 offset into `description` where the text that opens
|
|
498
|
+
* `descriptionActionKey` starts; the text before it stays plain. An integer
|
|
499
|
+
* in `0...description.length`: `0`, the default, makes the whole
|
|
500
|
+
* description the action and `description.length` leaves no action text.
|
|
501
|
+
* Ignored without `descriptionActionKey`.
|
|
502
|
+
*/
|
|
503
|
+
descriptionActionStart?: number;
|
|
496
504
|
footerActions?: readonly FooterAction[];
|
|
497
505
|
style?: ActivityRowStyle;
|
|
498
506
|
}>;
|
|
@@ -888,7 +896,7 @@ export type RowPatch = Readonly<{
|
|
|
888
896
|
}> | Readonly<{
|
|
889
897
|
type: 'activity';
|
|
890
898
|
key: string;
|
|
891
|
-
changes: PatchClearableChanges<ActivityRow, CommonPatchFields | 'title' | 'description' | 'status' | 'amounts' | 'badges' | 'presentation' | 'fee' | 'descriptionActionKey' | 'primaryAmount' | 'secondaryAmount' | 'leading' | 'hideLeading' | 'secondaryLeading' | 'footerActions'>;
|
|
899
|
+
changes: PatchClearableChanges<ActivityRow, CommonPatchFields | 'title' | 'description' | 'status' | 'amounts' | 'badges' | 'presentation' | 'fee' | 'descriptionActionKey' | 'descriptionActionStart' | 'primaryAmount' | 'secondaryAmount' | 'leading' | 'hideLeading' | 'secondaryLeading' | 'footerActions'>;
|
|
892
900
|
}> | Readonly<{
|
|
893
901
|
type: 'message';
|
|
894
902
|
key: string;
|
package/package.json
CHANGED
package/src/models.ts
CHANGED
|
@@ -616,6 +616,14 @@ export type ActivityRow = RowBase &
|
|
|
616
616
|
hidden?: boolean;
|
|
617
617
|
}>;
|
|
618
618
|
descriptionActionKey?: string;
|
|
619
|
+
/**
|
|
620
|
+
* UTF-16 offset into `description` where the text that opens
|
|
621
|
+
* `descriptionActionKey` starts; the text before it stays plain. An integer
|
|
622
|
+
* in `0...description.length`: `0`, the default, makes the whole
|
|
623
|
+
* description the action and `description.length` leaves no action text.
|
|
624
|
+
* Ignored without `descriptionActionKey`.
|
|
625
|
+
*/
|
|
626
|
+
descriptionActionStart?: number;
|
|
619
627
|
footerActions?: readonly FooterAction[];
|
|
620
628
|
style?: ActivityRowStyle;
|
|
621
629
|
}>;
|
|
@@ -1131,6 +1139,7 @@ export type RowPatch =
|
|
|
1131
1139
|
| 'presentation'
|
|
1132
1140
|
| 'fee'
|
|
1133
1141
|
| 'descriptionActionKey'
|
|
1142
|
+
| 'descriptionActionStart'
|
|
1134
1143
|
| 'primaryAmount'
|
|
1135
1144
|
| 'secondaryAmount'
|
|
1136
1145
|
| 'leading'
|
package/src/validation.ts
CHANGED
|
@@ -1621,6 +1621,11 @@ function assertVisual(row: RowModel, path: string): void {
|
|
|
1621
1621
|
});
|
|
1622
1622
|
}
|
|
1623
1623
|
|
|
1624
|
+
/** The type half of the `descriptionActionStart` contract; the range needs the row. */
|
|
1625
|
+
function isDescriptionActionStart(value: unknown): value is number {
|
|
1626
|
+
return Number.isSafeInteger(value) && (value as number) >= 0;
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1624
1629
|
function assertActivity(row: Partial<ActivityRow>, path: string): void {
|
|
1625
1630
|
if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean')
|
|
1626
1631
|
fail(`${path}.hideLeading`, 'must be boolean');
|
|
@@ -1633,6 +1638,11 @@ function assertActivity(row: Partial<ActivityRow>, path: string): void {
|
|
|
1633
1638
|
fail(`${path}.presentation`, 'must be stacked or table');
|
|
1634
1639
|
if (row.descriptionActionKey !== undefined)
|
|
1635
1640
|
assertKey(row.descriptionActionKey, `${path}.descriptionActionKey`);
|
|
1641
|
+
if (
|
|
1642
|
+
row.descriptionActionStart !== undefined &&
|
|
1643
|
+
!isDescriptionActionStart(row.descriptionActionStart)
|
|
1644
|
+
)
|
|
1645
|
+
fail(`${path}.descriptionActionStart`, 'must be a non-negative integer');
|
|
1636
1646
|
if ((row.amounts?.length ?? 0) > 32)
|
|
1637
1647
|
fail(`${path}.amounts`, 'supports at most 32 amount lines');
|
|
1638
1648
|
const amountKeys = new Set<string>();
|
|
@@ -1899,6 +1909,13 @@ function assertRow(
|
|
|
1899
1909
|
break;
|
|
1900
1910
|
case 'activity':
|
|
1901
1911
|
assertActivity(row, path);
|
|
1912
|
+
// Checked on the complete row only: a patch may carry the offset
|
|
1913
|
+
// without the description it points into.
|
|
1914
|
+
if ((row.descriptionActionStart ?? 0) > (row.description?.length ?? 0))
|
|
1915
|
+
fail(
|
|
1916
|
+
`${path}.descriptionActionStart`,
|
|
1917
|
+
'must not exceed the description length'
|
|
1918
|
+
);
|
|
1902
1919
|
break;
|
|
1903
1920
|
case 'message':
|
|
1904
1921
|
if (
|
|
@@ -2449,6 +2466,7 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
2449
2466
|
'presentation',
|
|
2450
2467
|
'fee',
|
|
2451
2468
|
'descriptionActionKey',
|
|
2469
|
+
'descriptionActionStart',
|
|
2452
2470
|
'footerActions',
|
|
2453
2471
|
],
|
|
2454
2472
|
message: [
|
|
@@ -2616,6 +2634,7 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
2616
2634
|
'amounts',
|
|
2617
2635
|
'fee',
|
|
2618
2636
|
'descriptionActionKey',
|
|
2637
|
+
'descriptionActionStart',
|
|
2619
2638
|
'footerActions',
|
|
2620
2639
|
],
|
|
2621
2640
|
message: [
|
|
@@ -3931,6 +3950,11 @@ function sanitizeRowForProduction(row: RowModel): RowModel {
|
|
|
3931
3950
|
delete next[field];
|
|
3932
3951
|
continue;
|
|
3933
3952
|
}
|
|
3953
|
+
if (field === 'descriptionActionStart') {
|
|
3954
|
+
// Renderers clamp an offset past the text; anything else has no meaning.
|
|
3955
|
+
if (!isDescriptionActionStart(value)) delete next[field];
|
|
3956
|
+
continue;
|
|
3957
|
+
}
|
|
3934
3958
|
if (field === 'parent' && isRecord(value))
|
|
3935
3959
|
next[field] = sanitizeRowForProduction(value as unknown as RowModel);
|
|
3936
3960
|
else if (field === 'children' && Array.isArray(value))
|
|
@@ -4862,6 +4886,16 @@ function mergeAndValidateSingleRow(
|
|
|
4862
4886
|
)
|
|
4863
4887
|
changes.subtitle = null;
|
|
4864
4888
|
}
|
|
4889
|
+
// The offset points into one specific description string, so a patch that
|
|
4890
|
+
// replaces the description without restating it falls back to the default.
|
|
4891
|
+
if (
|
|
4892
|
+
previous.type === 'activity' &&
|
|
4893
|
+
'description' in changes &&
|
|
4894
|
+
changes.description !== previous.description &&
|
|
4895
|
+
!('descriptionActionStart' in changes) &&
|
|
4896
|
+
previous.descriptionActionStart !== undefined
|
|
4897
|
+
)
|
|
4898
|
+
changes.descriptionActionStart = null;
|
|
4865
4899
|
const merged = { ...previous } as unknown as Record<string, unknown>;
|
|
4866
4900
|
for (const [field, value] of Object.entries(changes)) {
|
|
4867
4901
|
if (value === null) delete merged[field];
|