@wildwinter/app-shell 0.48.0 → 0.49.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.
package/dist/index.cjs CHANGED
@@ -3120,6 +3120,85 @@ function mountLinkStatus(host, opts) {
3120
3120
  };
3121
3121
  }
3122
3122
 
3123
+ // src/value-control.ts
3124
+ function fallbackText(decl) {
3125
+ const d = decl.default;
3126
+ if (d !== void 0 && d !== null) {
3127
+ if (typeof d === "boolean") return d ? "True" : "False";
3128
+ if (Array.isArray(d)) return d.length === 0 ? "none" : d.join(", ");
3129
+ return d === "" ? "none" : String(d);
3130
+ }
3131
+ switch (decl.type) {
3132
+ case "boolean":
3133
+ return "False";
3134
+ case "number":
3135
+ return "0";
3136
+ case "enum":
3137
+ return decl.values?.[0] ?? "none";
3138
+ case "quality":
3139
+ return decl.stages?.[0] ?? "first stage";
3140
+ case "flags":
3141
+ return "none";
3142
+ default:
3143
+ return "empty";
3144
+ }
3145
+ }
3146
+ var defaultLabel = (decl) => `default (${fallbackText(decl)})`;
3147
+ function stageGateNote(gates) {
3148
+ if (gates <= 0) return "";
3149
+ return gates === 1 ? "1 gate compares against this ladder, and it now reads the new order." : `${gates} gates compare against this ladder, and each now reads the new order.`;
3150
+ }
3151
+ function rungStrip(opts) {
3152
+ const make = opts.doc === void 0 ? el : (tag, props) => {
3153
+ const node2 = opts.doc.createElement(tag);
3154
+ node2.className = props.className;
3155
+ if (props.text !== void 0) node2.textContent = props.text;
3156
+ if (props.tip !== void 0) {
3157
+ node2.title = props.tip;
3158
+ node2.setAttribute("aria-label", props.tip);
3159
+ }
3160
+ if (props.onClick) node2.addEventListener("click", props.onClick);
3161
+ if (tag === "button") node2.type = "button";
3162
+ return node2;
3163
+ };
3164
+ const strip = make("span", { className: "seg shell-rungs" });
3165
+ const decl = opts.decl ?? { type: "quality", stages: opts.stages };
3166
+ const unset = opts.value === void 0;
3167
+ const fallback = typeof decl.default === "string" && opts.stages.includes(decl.default) ? decl.default : opts.stages[0];
3168
+ const readOnly = opts.onPick === void 0;
3169
+ if (opts.onClear) {
3170
+ strip.append(make("button", {
3171
+ className: `seg-opt shell-rung shell-rung-default${unset ? " on" : ""}`,
3172
+ text: defaultLabel(decl),
3173
+ tip: unset ? "Not set here: the declared default holds" : "Clear the value, back to the default",
3174
+ onClick: () => {
3175
+ if (!unset) opts.onClear();
3176
+ }
3177
+ }));
3178
+ }
3179
+ for (const stage of opts.stages) {
3180
+ const current3 = opts.value === stage;
3181
+ const falls = unset && stage === fallback;
3182
+ const rung = make(readOnly ? "span" : "button", {
3183
+ className: `seg-opt shell-rung${current3 ? " on" : ""}${falls ? " fallback" : ""}`,
3184
+ text: stage,
3185
+ tip: current3 ? "The current stage" : falls ? "The stage it falls back to" : readOnly ? stage : opts.pickTip?.(stage) ?? `Set to "${stage}"`,
3186
+ ...readOnly ? {} : { onClick: () => {
3187
+ if (!current3) opts.onPick(stage);
3188
+ } }
3189
+ });
3190
+ strip.append(rung);
3191
+ }
3192
+ if (!unset && !opts.stages.includes(opts.value)) {
3193
+ strip.append(make("span", {
3194
+ className: "seg-opt shell-rung stray on",
3195
+ text: opts.value,
3196
+ tip: `"${opts.value}" is not one of the stages: pick the one it belongs at now`
3197
+ }));
3198
+ }
3199
+ return strip;
3200
+ }
3201
+
3123
3202
  // src/property-list.ts
3124
3203
  var PROPERTY_TYPES = [
3125
3204
  ["number", "Number"],
@@ -3135,35 +3214,37 @@ var option = (value, label2, selected) => {
3135
3214
  o.selected = selected;
3136
3215
  return o;
3137
3216
  };
3138
- var NONE = "(none)";
3217
+ var NONE_CHOSEN = "\0none";
3139
3218
  function defaultControl(p, onChange, opts = {}) {
3140
3219
  const typed = opts.typed === true;
3141
3220
  const write = (raw) => {
3142
- if (raw === "") {
3143
- if (typed) delete p.default;
3144
- else p.default = "";
3145
- } else if (typed && p.type === "boolean") p.default = raw === "true";
3221
+ if (raw === "") delete p.default;
3222
+ else if (raw === NONE_CHOSEN) p.default = "";
3223
+ else if (typed && p.type === "boolean") p.default = raw === "true";
3146
3224
  else if (typed && p.type === "number") p.default = Number(raw);
3147
3225
  else p.default = raw;
3148
3226
  onChange?.();
3149
3227
  };
3150
3228
  const current3 = p.default === void 0 || p.default === null ? "" : String(p.default);
3229
+ const unsetLabel = opts.unsetLabel ?? defaultLabel({ ...p, default: void 0 });
3151
3230
  if (p.type === "boolean") {
3152
3231
  const sel = el("select", "field set-default");
3153
- sel.append(option("", NONE, current3 === ""), option("true", "True", current3 === "true"), option("false", "False", current3 === "false"));
3232
+ sel.append(option("", unsetLabel, current3 === ""), option("true", "True", current3 === "true"), option("false", "False", current3 === "false"));
3154
3233
  sel.addEventListener("change", () => write(sel.value));
3155
3234
  return sel;
3156
3235
  }
3157
3236
  if (p.type === "enum") {
3158
3237
  const sel = el("select", "field set-default");
3159
- sel.append(option("", NONE, current3 === ""));
3238
+ const none = opts.noneChosen === true && p.default === "";
3239
+ sel.append(option("", unsetLabel, current3 === "" && !none));
3240
+ if (opts.noneChosen) sel.append(option(NONE_CHOSEN, "(none)", none));
3160
3241
  for (const v of p.values ?? []) sel.append(option(v, v, current3 === v));
3161
3242
  sel.addEventListener("change", () => write(sel.value));
3162
3243
  return sel;
3163
3244
  }
3164
3245
  if (p.type === "quality") {
3165
3246
  const sel = el("select", "field set-default");
3166
- sel.append(option("", "(first stage)", current3 === ""));
3247
+ sel.append(option("", unsetLabel, current3 === ""));
3167
3248
  for (const v of p.stages ?? []) sel.append(option(v, v, current3 === v));
3168
3249
  sel.addEventListener("change", () => write(sel.value));
3169
3250
  return sel;
@@ -3175,7 +3256,7 @@ function defaultControl(p, onChange, opts = {}) {
3175
3256
  }
3176
3257
  const input = el("input", "field set-default");
3177
3258
  input.type = p.type === "number" ? "number" : "text";
3178
- input.placeholder = "Default";
3259
+ input.placeholder = p.type === "number" ? `Default (${fallbackText({ type: "number" })})` : "Default";
3179
3260
  input.value = current3;
3180
3261
  input.addEventListener("input", () => write(input.value));
3181
3262
  return input;
@@ -3202,8 +3283,7 @@ function mountPropertyList(host, decls, opts = {}) {
3202
3283
  for (const [v, label2] of types) type.append(option(v, label2, v === p.type));
3203
3284
  type.addEventListener("change", () => {
3204
3285
  p.type = type.value;
3205
- if (opts.typed) delete p.default;
3206
- else p.default = "";
3286
+ delete p.default;
3207
3287
  if (p.type === "enum" || p.type === "flags") p.values ??= [];
3208
3288
  else delete p.values;
3209
3289
  if (p.type === "quality") p.stages ??= [];
@@ -3390,6 +3470,7 @@ exports.createNavHistory = createNavHistory;
3390
3470
  exports.createSaveController = createSaveController;
3391
3471
  exports.debounce = debounce;
3392
3472
  exports.defaultControl = defaultControl;
3473
+ exports.defaultLabel = defaultLabel;
3393
3474
  exports.defaultProblemCopy = defaultProblemCopy;
3394
3475
  exports.describeProblem = describeProblem;
3395
3476
  exports.dialogFrame = dialogFrame;
@@ -3397,6 +3478,7 @@ exports.dismissToast = dismissToast;
3397
3478
  exports.dupGuard = dupGuard;
3398
3479
  exports.el = el;
3399
3480
  exports.expandableRow = expandableRow;
3481
+ exports.fallbackText = fallbackText;
3400
3482
  exports.feedUpdaterDownloadProgress = feedUpdaterDownloadProgress;
3401
3483
  exports.firstIllegalPropertyName = firstIllegalPropertyName;
3402
3484
  exports.focusNewRow = focusNewRow;
@@ -3462,11 +3544,13 @@ exports.renderStepperBar = renderStepperBar;
3462
3544
  exports.revalidatePropertyRefs = revalidatePropertyRefs;
3463
3545
  exports.revealRow = revealRow;
3464
3546
  exports.revealRowWhenReady = revealRowWhenReady;
3547
+ exports.rungStrip = rungStrip;
3465
3548
  exports.saveIndicator = saveIndicator;
3466
3549
  exports.setKeyPlatform = setKeyPlatform;
3467
3550
  exports.showAbout = showAbout;
3468
3551
  exports.showUpdaterDialog = showUpdaterDialog;
3469
3552
  exports.stageChips = stageChips;
3553
+ exports.stageGateNote = stageGateNote;
3470
3554
  exports.staleBar = staleBar;
3471
3555
  exports.tagChips = tagChips;
3472
3556
  exports.tipAt = tipAt;