create-songloft-plugin 2.13.2 → 2.13.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.
@@ -0,0 +1,316 @@
1
+ /*
2
+ * WebF 插件样式 —— 一份「WebF 可用 CSS 子集」示例。
3
+ *
4
+ * ── 与宿主注入层的边界 ───────────────────────────────────────────────────────
5
+ *
6
+ * 色板(--md-*)、reset、body、字体、安全区变量(--sl-safe-*)、圆角/阴影令牌全部来自
7
+ * 宿主注入的 theme.css,这里不重复定义。**色板由宿主在运行时下推真实 ColorScheme**
8
+ * (含用户自定义主题)覆盖静态兜底值 —— 本页配色自动跟随主程序主题,本文件无需做任何事。
9
+ *
10
+ * 直接复用宿主 components.css 的组件类(本文件不重定义):
11
+ * .card 卡片
12
+ * .btn / .btn-filled / .btn-outlined / .btn-text 按钮(SlButton)
13
+ * .switch / .switch-track / .switch-thumb 开关(SlSwitch)
14
+ * .material-symbols-outlined 图标字体(SlIcon)
15
+ *
16
+ * 想用 JS 读色(喂原生控件属性)必须调 `SongloftPlugin.getColorScheme()`:WebF 的
17
+ * getComputedStyle 对自定义属性一律返回空串。本模板已无此需求(都走 CSS var())。
18
+ *
19
+ * ── WebF 相关的硬约束(都有实测依据,别当成观感偏好改掉)──────────────────────
20
+ *
21
+ * ① 列表/单元文本必须 `white-space: nowrap` + ellipsis。可换行的 CJK 文本在 WebF 的
22
+ * 若干测量路径上会被按「每字一行」估高。
23
+ * ② 不用 `position: sticky`(WebF 下不生效,页面级也一样)。
24
+ * ③ 不用 `transform` 位移 `position: fixed` 元素。
25
+ * ④ 隐藏元素用 v-if 条件渲染,不用 `display: none`(后者仍挂 0 尺寸盒子)。
26
+ * ⑤ `.sl-listview` 必须有**确定 height**(不能 max-height,否则 `Infinity or NaN toInt`)。
27
+ * ⑥ 不用 max()/min()(WebF 未实现);clamp() 可用且参数里能塞 var()。
28
+ * ⑦ `flex-wrap: wrap` 容器的子项必须给**显式 width**,否则每项独占一行。
29
+ * ⑧ **flex 容器里不套 flex 容器**(否则整个子树静默不绘制)。竖向堆叠一律块流
30
+ * (display:block + margin),不用 flex-direction:column。横向 flex 行本身没问题。
31
+ */
32
+
33
+ :root {
34
+ /* 列表高度兜底值(约束 ⑤:首帧就得有确定高度)。权威值由 layout.js measureListHeight
35
+ * 实测覆盖成内联 height —— 这里只保证首帧不崩。整条表达式放进变量避免 calc 里嵌 var 解析失败。 */
36
+ --sl-list-h: clamp(200px, calc(100vh - 220px), 720px);
37
+ }
38
+
39
+ /* ── 布局 ─────────────────────────────────────────────────────────────────── */
40
+
41
+ /* 竖向堆叠靠 margin(约束 ⑧,不用 flex column + gap)。padding-bottom 被 layout.js 读解析值
42
+ * 参与列表高度核算。 */
43
+ .sl-container {
44
+ max-width: 800px;
45
+ margin: 0 auto;
46
+ padding: 16px;
47
+ padding-bottom: calc(16px + var(--sl-safe-bottom, 0px));
48
+ }
49
+
50
+ /* 自绘页头(tab / browser 模式,fullscreen 下宿主已有 AppBar)。横向 flex 行合规。 */
51
+ .sl-appbar {
52
+ display: flex;
53
+ align-items: center;
54
+ height: 56px;
55
+ margin-bottom: 8px;
56
+ }
57
+ .sl-appbar-title {
58
+ flex: 1;
59
+ min-width: 0;
60
+ font-size: 20px;
61
+ font-weight: 600;
62
+ color: var(--md-on-surface);
63
+ white-space: nowrap;
64
+ overflow: hidden;
65
+ text-overflow: ellipsis;
66
+ }
67
+
68
+ .sl-card {
69
+ margin-bottom: 16px;
70
+ }
71
+ .sl-card-body {
72
+ padding: 16px;
73
+ }
74
+
75
+ .sl-section-title {
76
+ font-size: 13px;
77
+ font-weight: 600;
78
+ color: var(--md-on-surface-variant);
79
+ margin-bottom: 8px;
80
+ }
81
+
82
+ /* ── 表单控件包装(对应 ui/Sl*.vue)──────────────────────────────────────────── */
83
+
84
+ /* HTML 回落分支的 input / select(浏览器 / 系统 WebView)。 */
85
+ .sl-input,
86
+ .sl-select {
87
+ width: 100%;
88
+ box-sizing: border-box;
89
+ height: 40px;
90
+ padding: 0 12px;
91
+ border: 1px solid var(--md-outline);
92
+ border-radius: var(--md-radius-sm);
93
+ font-family: inherit;
94
+ font-size: 14px;
95
+ color: var(--md-on-surface);
96
+ background: var(--md-surface);
97
+ outline: none;
98
+ }
99
+ .sl-input:focus,
100
+ .sl-select:focus {
101
+ border-color: var(--md-primary);
102
+ }
103
+
104
+ /* WebF cupertino input(SlInput 原生分支):**只给尺寸,装饰交给 widget 自己画**
105
+ * (加 border/background 会画出内外两个框)。 */
106
+ .sl-input-native {
107
+ display: block;
108
+ width: 100%;
109
+ height: 40px;
110
+ }
111
+
112
+ /*
113
+ * 下拉的 WebF 分支:触发按钮 + 绝对定位浮层(自绘)。触发按钮形制对齐原生 <select>:
114
+ * 矩形盒 + sm 圆角 + 左对齐 label + 右端 chevron。带 `.sl-select-wrap` 前缀抬 specificity
115
+ * 稳压宿主 .btn-outlined。display:block(非 .btn 的 inline-flex):布局交给内层 .sl-btn-inner,
116
+ * 且 block>flex 不触发约束 ⑧。
117
+ */
118
+ .sl-select-wrap {
119
+ position: relative;
120
+ }
121
+ .sl-select-wrap .sl-select-btn {
122
+ display: block;
123
+ width: 100%;
124
+ box-sizing: border-box;
125
+ height: 40px;
126
+ padding: 0 12px;
127
+ border: 1px solid var(--md-outline);
128
+ border-radius: var(--md-radius-sm);
129
+ background: var(--md-surface);
130
+ color: var(--md-on-surface);
131
+ }
132
+ .sl-select-wrap .sl-select-btn:hover {
133
+ background: var(--md-surface-container-high);
134
+ border-color: var(--md-outline);
135
+ }
136
+ .sl-select-btn .sl-btn-inner {
137
+ display: flex;
138
+ width: 100%;
139
+ height: 100%;
140
+ align-items: center;
141
+ justify-content: space-between;
142
+ gap: 8px;
143
+ }
144
+ .sl-select-btn .sl-btn-label {
145
+ flex: 1;
146
+ min-width: 0;
147
+ text-align: left;
148
+ font-weight: 400;
149
+ overflow: hidden;
150
+ text-overflow: ellipsis;
151
+ }
152
+ .sl-select-btn .sl-icon {
153
+ flex-shrink: 0;
154
+ color: var(--md-on-surface-variant);
155
+ }
156
+
157
+ /*
158
+ * 浮层面板。宽度必须是**显式 width**(width:100% 与 left/right+auto 都会因 shrink-to-fit
159
+ * 退回 auto,选中行背景只染文字宽)。box-sizing:border-box 让 1px 边框不撑宽。
160
+ * 祖先链不能有 overflow:hidden(否则面板被切)。max-height + overflow-y 是降级保护。
161
+ */
162
+ .sl-select-panel {
163
+ position: absolute;
164
+ top: calc(100% + 4px);
165
+ left: 0;
166
+ width: 100%;
167
+ box-sizing: border-box;
168
+ z-index: 20;
169
+ max-height: 320px;
170
+ overflow-y: auto;
171
+ border: 1px solid var(--md-outline-variant);
172
+ border-radius: var(--md-radius-sm);
173
+ background: var(--md-surface-container);
174
+ box-shadow: var(--md-shadow-2);
175
+ padding: 4px 0;
176
+ }
177
+ .sl-select-option {
178
+ padding: 10px 12px;
179
+ font-size: 14px;
180
+ color: var(--md-on-surface);
181
+ white-space: nowrap;
182
+ overflow: hidden;
183
+ text-overflow: ellipsis;
184
+ }
185
+ .sl-select-option-on {
186
+ color: var(--md-on-secondary-container);
187
+ background: var(--md-secondary-container);
188
+ }
189
+
190
+ /* ── 按钮内部(SlButton 内)───────────────────────────────────────────────────
191
+ * ⚠️ **必须 inline-flex 不能 flex**(约束 ⑦):写 flex 时按钮宽度变整个 viewport 宽,
192
+ * flex 容器里每个按钮各占一行。 */
193
+ .sl-btn-inner {
194
+ display: inline-flex;
195
+ align-items: center;
196
+ justify-content: center;
197
+ gap: 8px;
198
+ }
199
+ .sl-btn-label {
200
+ white-space: nowrap; /* 约束 ①:可换行 CJK 会量出「一字一行」的又窄又高的按钮 */
201
+ font-size: 14px;
202
+ font-weight: 500;
203
+ }
204
+ /* HTML 回落分支的 disabled(宿主 components.css 无 :disabled 规则)。 */
205
+ .btn:disabled {
206
+ background: var(--md-surface-variant);
207
+ color: var(--md-on-surface-variant);
208
+ border-color: transparent;
209
+ box-shadow: none;
210
+ cursor: not-allowed;
211
+ }
212
+ /* 约束 ⑧ 修补:宿主 `.btn` 是 inline-flex,落在页头这个 flex 容器里就是 flex 套 flex →
213
+ * 整个子树静默不绘制。降级 inline-block(内容排版由 .sl-btn-inner 承担)。 */
214
+ .sl-appbar .btn {
215
+ display: inline-block;
216
+ line-height: 40px;
217
+ }
218
+ .sl-appbar .btn > .sl-btn-inner {
219
+ vertical-align: middle;
220
+ }
221
+ /* 图标按钮(页头齿轮 / 返回箭头)。**刻意不挂宿主 `.btn`**:那是 inline-flex,落点是 flex
222
+ * 容器 → 触发约束 ⑧。inline-block 不是 flex 容器且 shrink-to-fit。垂直居中靠 line-height。 */
223
+ .sl-btn-icon {
224
+ display: inline-block;
225
+ width: 40px;
226
+ height: 40px;
227
+ padding: 0;
228
+ border: none;
229
+ background: transparent;
230
+ border-radius: var(--md-radius-full);
231
+ color: var(--md-on-surface-variant);
232
+ font-family: inherit;
233
+ cursor: pointer;
234
+ text-align: center;
235
+ line-height: 40px;
236
+ }
237
+ .sl-btn-icon .sl-btn-inner {
238
+ vertical-align: middle;
239
+ }
240
+ .sl-icon {
241
+ font-size: 18px;
242
+ line-height: 1;
243
+ }
244
+
245
+ /* ── 开关行(对齐 SwitchListTile:左标题+副标题,右开关)───────────────────────── */
246
+ .sl-switch-row {
247
+ display: flex;
248
+ align-items: center;
249
+ min-height: 48px;
250
+ }
251
+ .sl-switch-row .sl-switch-label {
252
+ flex: 1;
253
+ min-width: 0;
254
+ white-space: nowrap;
255
+ overflow: hidden;
256
+ text-overflow: ellipsis;
257
+ }
258
+
259
+ /* 表单字段(竖排:标签在上、控件在下,用块流不用 flex column —— 约束 ⑧)。 */
260
+ .sl-field {
261
+ margin-bottom: 12px;
262
+ }
263
+ .sl-field-label {
264
+ display: block;
265
+ margin-bottom: 6px;
266
+ font-size: 13px;
267
+ color: var(--md-on-surface-variant);
268
+ }
269
+
270
+ /* ── 列表 ─────────────────────────────────────────────────────────────────────
271
+ * 列表容器高度必须确定(约束 ⑤)。兜底值 --sl-list-h,权威值由 layout.js measureListHeight
272
+ * 实测覆盖成内联 height。不能用 max-height / flex:1。 */
273
+ .sl-listview {
274
+ display: block;
275
+ height: var(--sl-list-h);
276
+ border: 1px solid var(--md-outline-variant);
277
+ border-radius: var(--md-radius-sm);
278
+ }
279
+ /* overflow-y 只给 HTML 回落分支的 div;<webf-list-view> 自己就是滚动容器。 */
280
+ div.sl-listview {
281
+ overflow-y: auto;
282
+ }
283
+
284
+ /* 列表行:横向 flex 行合规;行内竖排两层文本是**块流**(约束 ⑧)。 */
285
+ .sl-row {
286
+ display: flex;
287
+ align-items: center;
288
+ min-height: 56px;
289
+ padding: 8px 16px;
290
+ border-bottom: 1px solid var(--md-outline-variant);
291
+ }
292
+ .sl-row-main {
293
+ flex: 1;
294
+ min-width: 0;
295
+ }
296
+ .sl-title,
297
+ .sl-sub {
298
+ display: block; /* 块流两层,不用竖向 flex(约束 ⑧) */
299
+ white-space: nowrap; /* 约束 ① */
300
+ overflow: hidden;
301
+ text-overflow: ellipsis;
302
+ }
303
+ .sl-title {
304
+ font-size: 15px;
305
+ color: var(--md-on-surface);
306
+ }
307
+ .sl-sub {
308
+ font-size: 13px;
309
+ color: var(--md-on-surface-variant);
310
+ }
311
+
312
+ .sl-empty {
313
+ padding: 32px 16px;
314
+ text-align: center; /* 整体块流 + text-align:center,不是竖向 flex(约束 ⑧) */
315
+ color: var(--md-on-surface-variant);
316
+ }
@@ -0,0 +1,50 @@
1
+ <script setup>
2
+ import { computed } from 'vue';
3
+ import SlIcon from './SlIcon.vue';
4
+
5
+ // **单一 HTML 实现**:不走 <flutter-cupertino-button> 双分支,统一用宿主 components.css
6
+ // 的 M3 按钮类(.btn / .btn-filled / .btn-outlined / .btn-text),与主程序
7
+ // FilledButton / OutlinedButton / TextButton 一致,自动跟随主题。
8
+ //
9
+ // ⚠️ WebF 约束(见 style.css 文件头 ⑦⑧):
10
+ // · 图标按钮落点(页头 / 工具栏)多是 flex 容器,`.btn` 是 inline-flex,flex 里套
11
+ // flex 会整个子树不绘制 → 图标按钮改用 `.sl-btn-icon`(inline-block)。
12
+ // · 按钮内容层 `.sl-btn-inner` 必须 inline-flex(不能 flex),否则宽度撑满整行。
13
+ const props = defineProps({
14
+ /** 'filled' | 'tinted' | 'plain' */
15
+ variant: { type: String, default: 'plain' },
16
+ disabled: { type: Boolean, default: false },
17
+ /** 按钮文字;iconOnly 时当 aria-label 用 */
18
+ label: { type: String, required: true },
19
+ /** 可选前置图标,取值见 SlIcon 的 MAP */
20
+ icon: { type: String, default: '' },
21
+ /** 可选后置图标(文字之后) */
22
+ trailingIcon: { type: String, default: '' },
23
+ /** 只画图标、不画文字(页头齿轮 / 返回箭头),label 仍必填当 aria-label */
24
+ iconOnly: { type: Boolean, default: false },
25
+ });
26
+
27
+ // tinted 映射到描边按钮(OutlinedButton),语义与 M3 一致。
28
+ const VARIANT_CLASS = {
29
+ filled: 'btn btn-filled',
30
+ tinted: 'btn btn-outlined',
31
+ plain: 'btn btn-text',
32
+ };
33
+
34
+ const btnClass = computed(() => {
35
+ // 图标按钮刻意不带宿主 `.btn`:`.btn` 是 inline-flex,落在 flex 容器里会触发约束 ⑧。
36
+ // `.sl-btn-icon` 是 inline-block,安全。
37
+ if (props.iconOnly) return 'sl-btn-icon';
38
+ return VARIANT_CLASS[props.variant] || VARIANT_CLASS.plain;
39
+ });
40
+ </script>
41
+
42
+ <template>
43
+ <button type="button" :class="btnClass" :disabled="disabled" :aria-label="label">
44
+ <span class="sl-btn-inner">
45
+ <SlIcon v-if="icon" :name="icon" />
46
+ <span v-if="!iconOnly" class="sl-btn-label">{{ label }}</span>
47
+ <SlIcon v-if="trailingIcon" :name="trailingIcon" />
48
+ </span>
49
+ </button>
50
+ </template>
@@ -0,0 +1,46 @@
1
+ <script setup>
2
+ import { ref } from 'vue';
3
+ import { useNativeUI } from '../engine.js';
4
+ import { bindNativeProps } from './native-props.js';
5
+
6
+ const props = defineProps({
7
+ modelValue: { type: Boolean, default: false },
8
+ disabled: { type: Boolean, default: false },
9
+ ariaLabel: { type: String, default: '' },
10
+ });
11
+ const emit = defineEmits(['update:modelValue']);
12
+
13
+ const el = ref(null);
14
+ // 布尔属性走命令式赋值(见 native-props.js)。cupertino checkbox 的 aria 入口是
15
+ // semanticLabel(HTML 属性名 semantic-label)。
16
+ bindNativeProps(el, () => ({
17
+ checked: props.modelValue,
18
+ disabled: props.disabled,
19
+ semanticLabel: props.ariaLabel || null,
20
+ }));
21
+
22
+ function onNativeChange(e) {
23
+ emit('update:modelValue', !!e.detail);
24
+ }
25
+ function onHtmlChange(e) {
26
+ emit('update:modelValue', e.target.checked);
27
+ }
28
+ </script>
29
+
30
+ <template>
31
+ <flutter-cupertino-checkbox
32
+ v-if="useNativeUI"
33
+ ref="el"
34
+ class="sl-cb-native"
35
+ @change="onNativeChange"
36
+ />
37
+ <input
38
+ v-else
39
+ type="checkbox"
40
+ class="sl-cb"
41
+ :checked="modelValue"
42
+ :disabled="disabled"
43
+ :aria-label="ariaLabel || undefined"
44
+ @change="onHtmlChange"
45
+ />
46
+ </template>
@@ -0,0 +1,32 @@
1
+ <script setup>
2
+ import { computed } from 'vue';
3
+
4
+ // 图标:语义名 → Material Symbols ligature。
5
+ //
6
+ // **单一 HTML 实现**:不走 <flutter-cupertino-icon> 双分支。Material Symbols 在 WebF 下
7
+ // 也可用 —— 宿主用 Flutter FontLoader 预注册了 'Material Symbols Outlined'(绕开 WebF
8
+ // 加载 woff2 失败的上游缺陷),字体由宿主提供的完整可变字体渲染,不会退化成字面文字。
9
+ // 尺寸/颜色由 CSS(.sl-icon + 落点的 color/font-size)控制。
10
+ //
11
+ // 在 MAP 里登记你需要的图标(值取 https://fonts.google.com/icons 的 ligature 名)。
12
+ const MAP = {
13
+ settings: 'settings',
14
+ refresh: 'refresh',
15
+ download: 'download',
16
+ chevron: 'expand_more',
17
+ back: 'arrow_back',
18
+ check: 'check',
19
+ error: 'error_outline',
20
+ music: 'music_note',
21
+ };
22
+
23
+ const props = defineProps({
24
+ name: { type: String, required: true },
25
+ });
26
+
27
+ const glyph = computed(() => MAP[props.name] || 'help');
28
+ </script>
29
+
30
+ <template>
31
+ <span class="material-symbols-outlined sl-icon" aria-hidden="true">{{ glyph }}</span>
32
+ </template>
@@ -0,0 +1,76 @@
1
+ <script setup>
2
+ import { ref } from 'vue';
3
+ import { useNativeUI } from '../engine.js';
4
+ import { bindNativeProps } from './native-props.js';
5
+
6
+ const props = defineProps({
7
+ /**
8
+ * 值。**必须是字符串**,不要传数字。
9
+ *
10
+ * ⚠️ 两条渲染分支对它的用法**不对称**:
11
+ * - HTML 分支:受控(`:value="modelValue"`)。浏览器 / WebView 没有下面这条崩溃链。
12
+ * - 原生分支:**只作挂载初值,挂载后永不回写**(非受控)。
13
+ * `<flutter-cupertino-input>` 是受控 widget,任何落到已挂载元素上的 `val` 回写都会
14
+ * 触发 RenderEditable 重排;若同一帧鼠标正停在输入框上做 hit test,会撞
15
+ * `Text layout not available` 断言 → 之后每帧刷断言 → 整页白屏(已实测)。
16
+ * 外部确实需要改显示值时,调用方改 `:key` 让本组件**重挂载**(新值走 mount 而非 update)。
17
+ * 数字字段请在 store 里存字符串、提交时才 parseInt。
18
+ */
19
+ modelValue: { type: String, default: '' },
20
+ placeholder: { type: String, default: '' },
21
+ /** 'text' | 'password' | 'number' | 'tel' | 'email' | 'url' */
22
+ type: { type: String, default: 'text' },
23
+ disabled: { type: Boolean, default: false },
24
+ clearable: { type: Boolean, default: false },
25
+ ariaLabel: { type: String, default: '' },
26
+ });
27
+ const emit = defineEmits(['update:modelValue', 'change']);
28
+
29
+ // 挂载初值快照。**刻意不是响应式**:只在 setup 时取一次 —— 这正是「非受控」的实现,
30
+ // 于是永远不会有第二次 `val` 写入落到已挂载的原生元素上,上面那条崩溃链从构造上消失。
31
+ // 输入事件照常 emit(store 仍是实时的)。重挂载(换 `:key`)会重跑 setup、重新快照。
32
+ const initialValue = props.modelValue;
33
+
34
+ const el = ref(null);
35
+ bindNativeProps(el, () => ({
36
+ disabled: props.disabled,
37
+ clearable: props.clearable,
38
+ }));
39
+
40
+ // cupertino input 的 input 事件:CustomEvent('input', detail: string)
41
+ function onNativeInput(e) {
42
+ emit('update:modelValue', e.detail == null ? '' : String(e.detail));
43
+ }
44
+ function onHtmlInput(e) {
45
+ emit('update:modelValue', e.target.value);
46
+ }
47
+ </script>
48
+
49
+ <template>
50
+ <!--
51
+ 原生分支:`:val` 绑的是**常量快照** initialValue 而不是 modelValue,理由见上。
52
+ 属性名是 `val` 而不是 `value`。cupertino input **没有 change 事件**,只有
53
+ input/submit/blur —— 「change 即保存」由调用方在 blur 或 input 去抖后自己触发。
54
+ -->
55
+ <flutter-cupertino-input
56
+ v-if="useNativeUI"
57
+ ref="el"
58
+ class="sl-input-native"
59
+ :val="initialValue"
60
+ :placeholder="placeholder"
61
+ :type="type"
62
+ @input="onNativeInput"
63
+ @blur="emit('change')"
64
+ />
65
+ <input
66
+ v-else
67
+ class="sl-input"
68
+ :value="modelValue"
69
+ :placeholder="placeholder"
70
+ :type="type"
71
+ :disabled="disabled"
72
+ :aria-label="ariaLabel || undefined"
73
+ @input="onHtmlInput"
74
+ @change="emit('change')"
75
+ />
76
+ </template>
@@ -0,0 +1,37 @@
1
+ <script setup>
2
+ // 纵向滚动列表容器。
3
+ //
4
+ // WebF 分支用 <webf-list-view> —— 它是 **webf 包内建**的元素(不依赖 webf_cupertino_ui),
5
+ // 直接映射到 Flutter 的 ListView,自带 view 回收。走 ListView 后行高由 Flutter 排版决定,
6
+ // 绕开了 CSS grid `auto` 行高在 CJK 下被按「每字一行」测量、以及 position:sticky 全局失效
7
+ // 这两个最难缠的坑。
8
+ //
9
+ // ⚠️ 两条硬约束:
10
+ //
11
+ // ① **列表项必须是本元素的直接子节点** —— Flutter ListView 靠此做回收。
12
+ // Vue 的 <slot/> 不产生包裹元素,所以 `<SlListView><Row v-for=.../></SlListView>`
13
+ // 是对的;**不要**在中间套 div。
14
+ //
15
+ // ② **shrink-wrap 默认是 true,必须显式关掉**。true 时列表高度等于内容总高、不在内部
16
+ // 滚动,几百行会一路撑下去。关掉后必须给它**确定的高度**(见 style.css 的 .sl-listview,
17
+ // 权威值由 layout.js measureListHeight 实测覆盖),不能留无界约束 —— WebF 在无界约束
18
+ // 下解析 flex 会触发 `Infinity or NaN toInt`。
19
+ //
20
+ // 若要做分页加载,onLoadMore 里**必须**调 finishLoad('success'|'noMore'|'fail'),否则加载
21
+ // 指示器会永久转圈。
22
+ import { useNativeListView } from '../engine.js';
23
+ </script>
24
+
25
+ <template>
26
+ <webf-list-view
27
+ v-if="useNativeListView"
28
+ class="sl-listview"
29
+ shrink-wrap="false"
30
+ scroll-direction="vertical"
31
+ >
32
+ <slot />
33
+ </webf-list-view>
34
+ <div v-else class="sl-listview">
35
+ <slot />
36
+ </div>
37
+ </template>
@@ -0,0 +1,117 @@
1
+ <script setup>
2
+ // 下拉选择。**这是唯一一处「WebF 下必须换实现」的控件。**
3
+ //
4
+ // ── 为什么 `<select>` 在 WebF 下不能用 ───────────────────────────────────────
5
+ //
6
+ // WebF 的 HTMLSelectElement 是一个 WidgetElement,只把 value / selectedIndex /
7
+ // disabled / multiple / required 暴露给 JS,**没有 `options`**。而 Vue 的 `v-model`
8
+ // 走 vModelSelect 指令,那个指令整个建立在 `el.options` 上(`filter.call(el.options, …)`),
9
+ // `filter.call(undefined, …)` 直接抛 TypeError —— **任何框架**的 `<select>` 双向绑定都会踩。
10
+ // 绕开 v-model、改显式 `@change` 读 `el.value` 之后实测仍不通(断点在 Dart 侧)。结论:不要碰。
11
+ //
12
+ // ⚠️ 判据陷阱:「下拉的标签显示更新了」**不能**当成「数据通了」。WebF 的 select 显示文字由
13
+ // Flutter 侧维护,与 JS 收不收到值无关。
14
+ //
15
+ // ── 现在的实现 ──────────────────────────────────────────────────────────────
16
+ //
17
+ // 触发按钮(SlButton)+ **绝对定位的浮层面板**(v-if 展开,普通 <div> 行)。选中值从头到尾
18
+ // 只在我们自己的 JS 里流动:点哪一行就 emit 那一行的 value,不读写任何 WebF 元素属性。
19
+ // 选项行是普通 <div>(不嵌 webf-list-view,避免赌 tap 穿过 Flutter ListView 的手势竞技场),
20
+ // 面板长时靠页面自身滚动。层叠/命中判据见 style.css 的 .sl-select-panel 注释。
21
+ //
22
+ // 非 WebF 路径(浏览器 / 系统 WebView / Web iframe)继续用原生 `<select>` —— 在真浏览器里
23
+ // 它完全正常,且是无障碍与键盘操作最好的形态。
24
+ //
25
+ // ⚠️ 闸门是 `isWebFRuntime` 而**不是** `useNativeUI`:`<select>` 在**所有** WebF 上都坏
26
+ // (缺 options,值传不回),不只 cupertino 客户端。用 useNativeUI 当闸门会让
27
+ // 「WebF + 老客户端(无 cupertino)」落到原生 `<select>` 分支而踩坑。
28
+
29
+ import { computed, onUnmounted } from 'vue';
30
+ import { isWebFRuntime } from '../engine.js';
31
+ import SlButton from './SlButton.vue';
32
+ import { openToken, nextSelectToken } from './select-open-state.js';
33
+
34
+ /*
35
+ * 同时只允许一个面板展开:展开状态不是每实例的 `open` 布尔(那样多个下拉能同时张开),
36
+ * 而是共享的「当前归属于谁」(见 select-open-state.js,必须放独立模块)。
37
+ * 刻意**不做**「点面板外收起」:WebF 的 DOM click 由全局唯一 tap recognizer 派发,
38
+ * document 级监听与触发按钮自身 click 的先后顺序未验证,少一个可能自锁的交互更稳。
39
+ */
40
+
41
+ const props = defineProps({
42
+ modelValue: { type: String, default: '' },
43
+ /** [{ value, label }],不含占位项 */
44
+ options: { type: Array, default: () => [] },
45
+ /** 空值那一项的文案 */
46
+ placeholder: { type: String, default: '全部' },
47
+ ariaLabel: { type: String, default: '' },
48
+ });
49
+ const emit = defineEmits(['update:modelValue']);
50
+
51
+ const currentLabel = computed(() => {
52
+ const hit = props.options.find((o) => o.value === props.modelValue);
53
+ return hit ? hit.label : props.placeholder;
54
+ });
55
+
56
+ const rows = computed(() => [{ value: '', label: props.placeholder }, ...props.options]);
57
+
58
+ const myToken = nextSelectToken();
59
+ const open = computed(() => openToken.value === myToken);
60
+
61
+ onUnmounted(() => {
62
+ if (openToken.value === myToken) openToken.value = null;
63
+ });
64
+
65
+ function toggle() {
66
+ // 赋 token 而不是翻布尔:展开自己的同时把别人收起来,是同一个动作。
67
+ openToken.value = open.value ? null : myToken;
68
+ }
69
+
70
+ function pick(row) {
71
+ openToken.value = null;
72
+ emit('update:modelValue', row.value);
73
+ }
74
+
75
+ // HTML 回落分支:原生 <select>
76
+ function onChange(e) {
77
+ const node = e && e.target;
78
+ if (node) emit('update:modelValue', node.value == null ? '' : node.value);
79
+ }
80
+ </script>
81
+
82
+ <template>
83
+ <div v-if="isWebFRuntime" class="sl-select-wrap">
84
+ <SlButton
85
+ class="sl-select-btn"
86
+ variant="tinted"
87
+ :label="currentLabel"
88
+ trailing-icon="chevron"
89
+ @click="toggle"
90
+ />
91
+ <!--
92
+ 面板用 v-if 而不是 CSS 隐藏:WebF 里 display:none 的元素仍会挂一个 0 尺寸盒子。
93
+ 选项行是普通 div(不嵌 webf-list-view,见文件头注释)。
94
+ -->
95
+ <div v-if="open" class="sl-select-panel">
96
+ <div
97
+ v-for="row in rows"
98
+ :key="row.value"
99
+ class="sl-select-option"
100
+ :class="{ 'sl-select-option-on': row.value === modelValue }"
101
+ @click="pick(row)"
102
+ >
103
+ {{ row.label }}
104
+ </div>
105
+ </div>
106
+ </div>
107
+ <select
108
+ v-else
109
+ class="sl-select"
110
+ :value="modelValue"
111
+ :aria-label="ariaLabel || undefined"
112
+ @change="onChange"
113
+ >
114
+ <option value="">{{ placeholder }}</option>
115
+ <option v-for="o in options" :key="o.value" :value="o.value">{{ o.label }}</option>
116
+ </select>
117
+ </template>