dsh-workbench-salary 0.4.14 → 0.4.16

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/lib/client.js CHANGED
@@ -4197,873 +4197,6 @@ var require_records = __commonJS({
4197
4197
  }
4198
4198
  });
4199
4199
 
4200
- // packages/addons/lib/highlight.cjs
4201
- var require_highlight = __commonJS({
4202
- "packages/addons/lib/highlight.cjs"(exports2, module2) {
4203
- "use strict";
4204
- module2.exports = function(React) {
4205
- var h = React.createElement;
4206
- function sourceOf(keyword) {
4207
- var pattern = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4208
- return pattern.replace(/[a-zA-Z]/g, function(letter) {
4209
- return "[" + letter.toLowerCase() + letter.toUpperCase() + "]";
4210
- });
4211
- }
4212
- return function createHighlight(prefix) {
4213
- var className = String(prefix || "wb") + "-hit";
4214
- function hit(rawText, rawKeyword) {
4215
- var text = rawText == null ? "" : String(rawText);
4216
- var keyword = rawKeyword == null ? "" : String(rawKeyword);
4217
- if (!keyword) return text;
4218
- var matcher, match, end = 0, parts = [];
4219
- try {
4220
- matcher = new RegExp(sourceOf(keyword), "g");
4221
- } catch (error) {
4222
- return text;
4223
- }
4224
- while (match = matcher.exec(text)) {
4225
- if (match.index > end) parts.push(text.slice(end, match.index));
4226
- parts.push(h("mark", { className, key: match.index }, match[0]));
4227
- end = match.index + match[0].length;
4228
- if (!match[0]) matcher.lastIndex += 1;
4229
- }
4230
- if (!parts.length) return text;
4231
- if (end < text.length) parts.push(text.slice(end));
4232
- return parts;
4233
- }
4234
- function Highlight(props) {
4235
- return hit(props.text, props.keyword);
4236
- }
4237
- Highlight.hit = hit;
4238
- return Highlight;
4239
- };
4240
- };
4241
- }
4242
- });
4243
-
4244
- // node_modules/.pnpm/lucide-react@1.70.0_react@19.2.0/node_modules/lucide-react/dist/esm/icons/chevron-right.mjs
4245
- var chevron_right_exports = {};
4246
- __export(chevron_right_exports, {
4247
- __iconData: () => __iconData6,
4248
- default: () => ChevronRight
4249
- });
4250
- var __iconData6, ChevronRight;
4251
- var init_chevron_right = __esm({
4252
- "node_modules/.pnpm/lucide-react@1.70.0_react@19.2.0/node_modules/lucide-react/dist/esm/icons/chevron-right.mjs"() {
4253
- init_createLucideIcon();
4254
- __iconData6 = {
4255
- name: "chevron-right",
4256
- size: 24,
4257
- node: [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]]
4258
- };
4259
- __iconData6.node;
4260
- ChevronRight = createLucideIcon(__iconData6);
4261
- }
4262
- });
4263
-
4264
- // packages/addons/lib/disclosure-styles.cjs
4265
- var require_disclosure_styles = __commonJS({
4266
- "packages/addons/lib/disclosure-styles.cjs"(exports2, module2) {
4267
- "use strict";
4268
- module2.exports = [
4269
- ".wb-disc{min-width:0;border:0;padding:0;margin:0}",
4270
- // 原生 details/summary 保留键盘与无障碍语义,这里只接管观感:去掉默认三角并铺满整行。
4271
- ".wb-disc>summary{display:flex;align-items:center;gap:6px;cursor:pointer;font-size:12.5px;font-weight:600;line-height:1.6;color:inherit;user-select:none;list-style:none;padding:2px 8px 2px 2px;margin:-2px -8px -2px -2px;border-radius:7px}",
4272
- ".wb-disc>summary::-webkit-details-marker{display:none}",
4273
- '.wb-disc>summary::marker{content:""}',
4274
- ".wb-disc>summary:hover{background:color-mix(in oklab,currentColor 6%,transparent)}",
4275
- ".wb-disc>summary:focus-visible{outline:2px solid var(--wb-accent,var(--dsw-alias-brand-primary,Highlight));outline-offset:2px}",
4276
- ".wb-disc-chev{flex:0 0 auto;width:14px;height:14px;transition:transform 160ms ease}",
4277
- ".wb-disc[open]>summary .wb-disc-chev{transform:rotate(90deg)}",
4278
- ".wb-disc-title{min-width:0;overflow-wrap:anywhere}",
4279
- ".wb-disc-meta{font-weight:400;font-size:12px;color:var(--wb-muted,var(--dsw-alias-label-tertiary,GrayText))}",
4280
- ".wb-disc-body{margin-top:8px;min-width:0;animation:wb-disc-in 160ms ease}",
4281
- "@keyframes wb-disc-in{from{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}",
4282
- "@media(prefers-reduced-motion:reduce){.wb-disc-chev{transition:none}.wb-disc-body{animation:none}}"
4283
- ].join("\n");
4284
- }
4285
- });
4286
-
4287
- // packages/addons/lib/disclosure.cjs
4288
- var require_disclosure = __commonJS({
4289
- "packages/addons/lib/disclosure.cjs"(exports2, module2) {
4290
- "use strict";
4291
- var ChevronRight2 = (init_chevron_right(), __toCommonJS(chevron_right_exports)).default;
4292
- function createDisclosure(React) {
4293
- var h = React.createElement;
4294
- function Disclosure(props) {
4295
- var attrs = Object.assign({ className: ("wb-disc " + (props.className || "")).trim() }, props.attrs || {});
4296
- if (props.open !== void 0) attrs.open = !!props.open;
4297
- else if (props.defaultOpen !== void 0) attrs.open = !!props.defaultOpen;
4298
- if (props.onToggle) attrs.onToggle = props.onToggle;
4299
- return h(
4300
- "details",
4301
- attrs,
4302
- h(
4303
- "summary",
4304
- null,
4305
- h(ChevronRight2, { className: "wb-disc-chev", "aria-hidden": true, focusable: false }),
4306
- h("span", { className: "wb-disc-title" }, props.title),
4307
- props.meta != null && props.meta !== "" ? h("span", { className: "wb-disc-meta" }, props.meta) : null
4308
- ),
4309
- h("div", { className: "wb-disc-body" }, props.children)
4310
- );
4311
- }
4312
- return { Disclosure, css: require_disclosure_styles() };
4313
- }
4314
- module2.exports = { createDisclosure, css: require_disclosure_styles() };
4315
- }
4316
- });
4317
-
4318
- // packages/addons/lib/action-schema-style.cjs
4319
- var require_action_schema_style = __commonJS({
4320
- "packages/addons/lib/action-schema-style.cjs"(exports2, module2) {
4321
- "use strict";
4322
- module2.exports = function(PREFIX, DOMAIN) {
4323
- var P = PREFIX + "-as";
4324
- var hairline = "1px solid color-mix(in oklab,currentColor 8%,transparent)";
4325
- var CSS = [
4326
- "." + P + "{display:flex;flex-direction:column;gap:12px;width:100%;min-width:0;font-size:13px;color:inherit}",
4327
- "." + P + "-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
4328
- "." + P + "-title{font-size:15px;font-weight:660;margin:0}",
4329
- "." + P + "-badge{display:inline-flex;align-items:center;gap:4px;max-width:100%;border:1px solid var(--wb-border,#e3e5e9);border-radius:999px;padding:1px 8px;font-size:11px;color:var(--dsw-alias-label-secondary,currentColor);font-variant-numeric:tabular-nums;overflow-wrap:anywhere}",
4330
- "." + P + "-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px}",
4331
- "." + P + "-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
4332
- "." + P + "-search{position:relative;flex:1 1 220px;min-width:0;display:flex;align-items:center}",
4333
- "." + P + "-search input{width:100%;border:1px solid var(--wb-border,#e3e5e9);border-radius:8px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));color:inherit;font:inherit;padding:6px 10px 6px 30px}",
4334
- "." + P + "-search input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}",
4335
- "." + P + "-search .wbi-svg{position:absolute;left:10px;top:50%;transform:translateY(-50%);color:var(--dsw-alias-label-tertiary,inherit)}",
4336
- "." + P + " select{border:1px solid var(--wb-border,#e3e5e9);border-radius:8px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));color:inherit;font:inherit;padding:6px 8px;max-width:100%}",
4337
- "." + P + " select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}",
4338
- "." + P + "-list{display:flex;flex-direction:column;gap:8px}",
4339
- "." + P + "-card{border:1px solid var(--wb-border,#e3e5e9);border-radius:10px;padding:10px 12px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));display:flex;flex-direction:column;gap:8px;min-width:0}",
4340
- "." + P + "-cardhead{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:8px}",
4341
- "." + P + "-cardmeta{display:flex;align-items:center;flex-wrap:wrap;gap:8px;min-width:0;min-height:24px}",
4342
- "." + P + "-cardhead code{font-weight:640;overflow-wrap:anywhere;min-width:0}",
4343
- "." + P + "-hintline{margin:0;color:var(--dsw-alias-label-tertiary,inherit);font-size:11.5px;line-height:1.5}",
4344
- "." + P + "-origins{display:inline-flex;align-items:center;gap:10px;flex-wrap:wrap;justify-content:flex-end;min-width:0}",
4345
- "." + P + "-origins-label{font-size:11px;color:var(--wb-muted);white-space:nowrap}",
4346
- "." + P + "-origin{display:inline-flex;align-items:center;gap:4px;font-size:11.5px;color:var(--wb-muted);cursor:pointer;user-select:none}",
4347
- // 该 action 本身不支持的来源:整项置灰、不可点,示意「不是没开,是开不了」。
4348
- "." + P + "-origin-off{opacity:.55;cursor:not-allowed}",
4349
- "." + P + "-origin input[type=checkbox]{width:13px;height:13px;margin:0;accent-color:var(--wb-accent);cursor:inherit}",
4350
- "." + P + "-origin input[type=checkbox]:focus-visible{outline:2px solid var(--wb-accent);outline-offset:2px}",
4351
- "." + P + "-locked{border-color:var(--wb-warn,#b7791f);color:var(--wb-warn,#b7791f)}",
4352
- "." + P + "-desc{margin:0;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55;font-size:12.5px;overflow-wrap:anywhere}",
4353
- // 搜索命中:用品牌色透明度叠加而不是写死浅色,深浅主题都可读;继承文字颜色、不覆盖 ::selection。
4354
- "." + P + " mark." + P + "-hit{background:color-mix(in oklab,var(--dsw-alias-brand-primary,#4f6ef7) 22%,transparent);color:inherit;border-radius:2px;padding:0;font:inherit;box-decoration-break:clone;-webkit-box-decoration-break:clone}",
4355
- "." + P + "-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}",
4356
- "." + P + "-table th{text-align:left;font-weight:620;font-size:11px;letter-spacing:.4px;text-transform:uppercase;color:var(--dsw-alias-label-tertiary,inherit);padding:4px 8px 4px 0;white-space:nowrap}",
4357
- "." + P + "-table td{padding:4px 8px 4px 0;vertical-align:top;border-top:" + hairline + ";line-height:1.5;overflow-wrap:anywhere}",
4358
- "." + P + "-req{color:var(--dsw-alias-state-error-primary,#d9534f);font-weight:620}",
4359
- "." + P + "-opt{color:var(--dsw-alias-label-tertiary,inherit)}",
4360
- "." + P + "-none{color:var(--dsw-alias-label-tertiary,inherit);font-size:12px}",
4361
- "." + P + "-example{position:relative;display:flex;flex-direction:column;gap:4px;min-width:0}",
4362
- "." + P + "-examplehead{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap}",
4363
- "." + P + "-pre{margin:0;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-skeleton,#f2f3f5);color:inherit;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:1.5;overflow:auto;max-height:280px;white-space:pre-wrap;word-break:break-word}",
4364
- "." + P + "-copy{border:1px solid var(--wb-border,#e3e5e9);border-radius:7px;background:transparent;color:inherit;font:inherit;font-size:11.5px;padding:2px 8px;cursor:pointer}",
4365
- "." + P + "-copy:hover{background:var(--dsw-alias-interactive-bg-hover,color-mix(in oklab,currentColor 5%,transparent))}",
4366
- "." + P + "-copy:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:2px}",
4367
- // 折叠头观感已收口到共享控件 disclosure-styles.cjs(.wb-disc),这里不再重复定义 details>summary。
4368
- "." + P + "-params{min-width:0}",
4369
- "." + P + "-empty{padding:24px;text-align:center;border:1px dashed var(--wb-border,#e3e5e9);border-radius:10px;color:var(--dsw-alias-label-tertiary,inherit)}",
4370
- "." + P + "-error{padding:12px;border:1px solid var(--dsw-alias-state-error-primary,#d9534f);border-radius:10px;color:var(--dsw-alias-state-error-primary,#d9534f);display:flex;gap:10px;align-items:center;flex-wrap:wrap;overflow-wrap:anywhere}",
4371
- "." + P + "-toast{position:sticky;bottom:8px;align-self:flex-start;border-radius:999px;padding:3px 10px;background:var(--dsw-alias-bg-skeleton,#f2f3f5);font-size:11.5px;max-width:100%}",
4372
- // 窄屏:五列参数表压成一列会丢失列名、且 table 布局按最小内容宽度撑破容器,
4373
- // 这里整体改成块级网格:每行 = 名称 / 类型 / 必填 + 约束行 + 说明行,行间用细线分隔。
4374
- "@media(max-width:760px){." + P + "-toolbar{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;align-items:end}." + P + "-search{grid-column:1/-1}." + P + "-toolbar>label{display:flex;flex-direction:column;align-items:stretch;gap:4px;min-width:0}." + P + "-toolbar select{width:100%;min-width:0}." + P + "-cardhead{grid-template-columns:minmax(0,1fr);row-gap:6px}." + P + "-origins{justify-content:flex-start}." + P + "-table{display:block}." + P + "-table thead{display:none}." + P + "-table tbody{display:block}." + P + '-table tr{display:grid;grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"name type need" "extra extra extra" "desc desc desc";column-gap:8px;padding:9px 0;border-top:' + hairline + "}." + P + "-table tr:first-child{border-top:0;padding-top:2px}." + P + "-table tr:last-child{padding-bottom:2px}." + P + "-table td{display:block;border:0;padding:0;min-width:0}." + P + "-table td:empty{display:none}." + P + "-pname{grid-area:name;font-weight:640}." + P + "-ptype{grid-area:type;justify-self:start;align-self:center;color:var(--dsw-alias-label-tertiary,inherit)}." + P + "-pneed{grid-area:need;justify-self:end;align-self:center;font-size:11px;line-height:1.6;white-space:nowrap}." + P + "-pextra{grid-area:extra;margin-top:3px;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55}." + P + "-pdesc{grid-area:desc;margin-top:3px;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55}}",
4375
- // 中等宽度(521–760px)三个筛选项正好排成一行,避免第三项独占一行显得参差。
4376
- "@media(min-width:521px) and (max-width:760px){." + P + "-toolbar{grid-template-columns:repeat(3,minmax(0,1fr))}}",
4377
- "@media(max-width:420px){." + P + "-toolbar{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}." + P + "-card{padding:10px}." + P + "-table tr{padding:8px 0}}"
4378
- ].join("\n") + "\n" + require_disclosure_styles();
4379
- return function injectCss() {
4380
- if (typeof document === "undefined") return;
4381
- var id = "wb-addon-" + DOMAIN + "-actions-css";
4382
- var old = document.getElementById(id);
4383
- if (old) {
4384
- old.textContent = CSS;
4385
- return;
4386
- }
4387
- var style = document.createElement("style");
4388
- style.id = id;
4389
- style.setAttribute("data-wb-addon", "wb-addon-" + DOMAIN);
4390
- style.textContent = CSS;
4391
- document.head.appendChild(style);
4392
- };
4393
- };
4394
- }
4395
- });
4396
-
4397
- // packages/addons/lib/action-schema-view.cjs
4398
- var require_action_schema_view = __commonJS({
4399
- "packages/addons/lib/action-schema-view.cjs"(exports2, module2) {
4400
- "use strict";
4401
- var React = require("react");
4402
- var createHighlight = require_highlight()(React);
4403
- var Disclosure = require_disclosure().createDisclosure(React).Disclosure;
4404
- var h = React.createElement;
4405
- var COPY = {
4406
- zh: {
4407
- title: "Action",
4408
- hint: "\u8FD0\u884C\u65F6\u6CE8\u518C \xB7 \u53EA\u8BFB",
4409
- switchHint: "\u5141\u8BB8\u6765\u6E90\u843D\u672C\u673A\u3001\u5373\u6539\u5373\u751F\u6548\uFF1A\u52FE\u4E0A\u7684\u6765\u6E90\u624D\u80FD\u8C03\u7528\u8BE5 action\uFF0C\u5176\u4F59\u4F1A\u88AB ACTION_ORIGIN_DENIED \u62E6\u4E0B\u3002",
4410
- hostHint: "\u5BBF\u4E3B action \u7684\u5141\u8BB8\u6765\u6E90\uFF1B\u6807\u300C\u6765\u6E90\u56FA\u5B9A\u300D\u7684\u4E0D\u53EF\u4FEE\u6539\u3002",
4411
- originsLabel: "\u5141\u8BB8\u6765\u6E90",
4412
- originUi: "\u754C\u9762",
4413
- originPlugin: "\u63D2\u4EF6",
4414
- originAgent: "agent",
4415
- originSync: "\u540C\u6B65",
4416
- originsSaving: "\u4FDD\u5B58\u4E2D\u2026",
4417
- originsToast: "\u5DF2\u66F4\u65B0\u5141\u8BB8\u6765\u6E90",
4418
- originsFail: "\u66F4\u65B0\u5141\u8BB8\u6765\u6E90\u5931\u8D25",
4419
- originsEmpty: "\u81F3\u5C11\u8981\u4FDD\u7559\u4E00\u4E2A\u6765\u6E90",
4420
- originsUnsupported: "\u8BE5 action \u672C\u8EAB\u4E0D\u652F\u6301\u8FD9\u4E2A\u6765\u6E90",
4421
- originsPinned: "\u6765\u6E90\u56FA\u5B9A",
4422
- originsPinnedHint: "\u8BE5 action \u7684\u5141\u8BB8\u6765\u6E90\u88AB\u56FA\u5B9A\uFF08\u5B89\u5168\u7EA6\u675F\uFF09\uFF0C\u4E0D\u80FD\u4FEE\u6539",
4423
- domain: "\u57DF",
4424
- versionLabel: "\u7248\u672C",
4425
- shell: "\u5BBF\u4E3B",
4426
- count: function(shown, total) {
4427
- return shown + " / " + total + " \u4E2A action";
4428
- },
4429
- search: "\u641C\u7D22\u540D\u79F0\u3001\u63CF\u8FF0\u3001\u53C2\u6570\uFF08\u547D\u4E2D\u5904\u9AD8\u4EAE\uFF09",
4430
- filterReq: "\u5FC5\u586B\u7B5B\u9009",
4431
- all: "\u5168\u90E8",
4432
- onlyRequired: "\u542B\u5FC5\u586B\u9879",
4433
- onlyOptional: "\u65E0\u5FC5\u586B\u9879",
4434
- filterType: "\u53C2\u6570\u7C7B\u578B",
4435
- allTypes: "\u5168\u90E8\u7C7B\u578B",
4436
- filterOrigin: "\u5141\u8BB8\u6765\u6E90",
4437
- allOrigins: "\u5168\u90E8\u6765\u6E90",
4438
- colName: "\u53C2\u6570",
4439
- colType: "\u7C7B\u578B",
4440
- colReq: "\u5FC5\u586B",
4441
- colExtra: "\u9ED8\u8BA4 / \u679A\u4E3E / \u7EA6\u675F",
4442
- colDesc: "\u8BF4\u660E",
4443
- required: "\u5FC5\u586B",
4444
- optional: "\u53EF\u9009",
4445
- noParams: "\u65E0\u53C2\u6570",
4446
- paramCount: function(n) {
4447
- return n + " \u4E2A\u53C2\u6570";
4448
- },
4449
- params: "\u53C2\u6570",
4450
- requiredCount: function(n) {
4451
- return "\u5FC5\u586B " + n;
4452
- },
4453
- examples: "\u793A\u4F8B",
4454
- noExamples: "\u65E0\u793A\u4F8B",
4455
- copy: "\u590D\u5236",
4456
- copied: "\u5DF2\u590D\u5236",
4457
- raw: "\u539F\u59CB JSON Schema",
4458
- loading: "\u8F7D\u5165\u4E2D\u2026",
4459
- loadFail: "\u8BFB\u53D6 action schema \u5931\u8D25",
4460
- retry: "\u91CD\u8BD5",
4461
- empty: "\u6CA1\u6709\u5339\u914D\u7684 action",
4462
- emptyRegistry: "\u8BE5\u57DF\u6CA1\u6709\u6CE8\u518C action",
4463
- envelope: "\u9ED8\u8BA4",
4464
- enumLabel: "\u679A\u4E3E",
4465
- range: "\u8303\u56F4",
4466
- length: "\u957F\u5EA6",
4467
- pattern: "\u6B63\u5219",
4468
- format: "\u683C\u5F0F",
4469
- items: "\u5143\u7D20\u6570"
4470
- },
4471
- en: {
4472
- title: "Actions",
4473
- hint: "runtime registry \xB7 read-only",
4474
- switchHint: "Allowed origins are stored locally and apply immediately: only checked origins may call the action; others get ACTION_ORIGIN_DENIED.",
4475
- hostHint: "Allowed origins for host actions; items marked pinned cannot be changed.",
4476
- originsLabel: "Origins",
4477
- originUi: "UI",
4478
- originPlugin: "Plugin",
4479
- originAgent: "Agent",
4480
- originSync: "Sync",
4481
- originsSaving: "Saving\u2026",
4482
- originsToast: "Allowed origins updated",
4483
- originsFail: "Failed to update allowed origins",
4484
- originsEmpty: "Keep at least one origin",
4485
- originsUnsupported: "This action does not support this origin",
4486
- originsPinned: "Pinned",
4487
- originsPinnedHint: "Allowed origins are pinned for this action (security constraint) and cannot be changed",
4488
- originsDefaultOn: "Allowed by default",
4489
- originsDefaultOff: "Off by default, can be enabled",
4490
- domain: "Domain",
4491
- versionLabel: "Version",
4492
- shell: "Host",
4493
- count: function(shown, total) {
4494
- return shown + " / " + total + " actions";
4495
- },
4496
- search: "Search name, description, params (matches highlighted)",
4497
- filterReq: "Required",
4498
- all: "All",
4499
- onlyRequired: "Has required",
4500
- onlyOptional: "No required",
4501
- filterType: "Param type",
4502
- allTypes: "All types",
4503
- filterOrigin: "Origins",
4504
- allOrigins: "All origins",
4505
- colName: "Param",
4506
- colType: "Type",
4507
- colReq: "Required",
4508
- colExtra: "Default / enum / constraints",
4509
- colDesc: "Description",
4510
- required: "required",
4511
- optional: "optional",
4512
- noParams: "No parameters",
4513
- paramCount: function(n) {
4514
- return n + " params";
4515
- },
4516
- params: "Parameters",
4517
- requiredCount: function(n) {
4518
- return n + " required";
4519
- },
4520
- examples: "Examples",
4521
- noExamples: "No examples",
4522
- copy: "Copy",
4523
- copied: "Copied",
4524
- raw: "Raw JSON Schema",
4525
- loading: "Loading\u2026",
4526
- loadFail: "Failed to read action schema",
4527
- retry: "Retry",
4528
- empty: "No matching action",
4529
- emptyRegistry: "This domain has no registered action",
4530
- envelope: "Default",
4531
- enumLabel: "Enum",
4532
- range: "Range",
4533
- length: "Length",
4534
- pattern: "Pattern",
4535
- format: "Format",
4536
- items: "Items"
4537
- }
4538
- };
4539
- function typeLabel(schema) {
4540
- if (!schema || typeof schema !== "object") return "";
4541
- if (Array.isArray(schema.type)) return schema.type.join(" | ");
4542
- if (typeof schema.type === "string") {
4543
- if (schema.type === "array" && schema.items) {
4544
- var inner = typeLabel(schema.items);
4545
- return inner ? inner + "[]" : "array";
4546
- }
4547
- return schema.type;
4548
- }
4549
- if (Array.isArray(schema.oneOf)) return schema.oneOf.map(typeLabel).filter(Boolean).join(" | ");
4550
- if (Array.isArray(schema.anyOf)) return schema.anyOf.map(typeLabel).filter(Boolean).join(" | ");
4551
- return "";
4552
- }
4553
- function typeNames(schema) {
4554
- var label = typeLabel(schema);
4555
- if (!label) return [];
4556
- return label.split("|").map(function(x) {
4557
- return x.trim().replace(/\[\]$/, "");
4558
- }).filter(Boolean);
4559
- }
4560
- function scalar(value) {
4561
- if (typeof value === "string") return JSON.stringify(value);
4562
- return String(value);
4563
- }
4564
- function extraText(schema, t) {
4565
- if (!schema || typeof schema !== "object") return "";
4566
- var parts = [];
4567
- if (Object.prototype.hasOwnProperty.call(schema, "default")) {
4568
- parts.push(t.envelope + " " + scalar(schema.default));
4569
- }
4570
- if (Array.isArray(schema.enum)) {
4571
- parts.push(t.enumLabel + " " + schema.enum.map(scalar).join(" / "));
4572
- }
4573
- if (typeof schema.minimum === "number" || typeof schema.maximum === "number") {
4574
- var lo = typeof schema.minimum === "number" ? schema.minimum : null;
4575
- var hi = typeof schema.maximum === "number" ? schema.maximum : null;
4576
- if (lo !== null && hi !== null) parts.push(t.range + " \u2265" + lo + " \u4E14 \u2264" + hi);
4577
- else if (lo !== null) parts.push(t.range + " \u2265" + lo);
4578
- else parts.push(t.range + " \u2264" + hi);
4579
- }
4580
- if (typeof schema.minLength === "number" || typeof schema.maxLength === "number") {
4581
- parts.push(t.length + " " + (schema.minLength ?? 0) + "\u2013" + (schema.maxLength ?? "\u221E"));
4582
- }
4583
- if (typeof schema.minItems === "number" || typeof schema.maxItems === "number") {
4584
- parts.push(t.items + " " + (schema.minItems ?? 0) + "\u2013" + (schema.maxItems ?? "\u221E"));
4585
- }
4586
- if (typeof schema.pattern === "string") parts.push(t.pattern + " " + schema.pattern);
4587
- if (typeof schema.format === "string") parts.push(t.format + " " + schema.format);
4588
- return parts.join(" \xB7 ");
4589
- }
4590
- function paramRows(action) {
4591
- var input = action && action.input && typeof action.input === "object" ? action.input : {};
4592
- var props = input.properties && typeof input.properties === "object" ? input.properties : {};
4593
- var required = Array.isArray(input.required) ? input.required : [];
4594
- return Object.keys(props).map(function(key) {
4595
- var schema = props[key] && typeof props[key] === "object" ? props[key] : {};
4596
- return {
4597
- name: key,
4598
- schema,
4599
- type: typeLabel(schema),
4600
- types: typeNames(schema),
4601
- required: required.indexOf(key) >= 0,
4602
- description: typeof schema.description === "string" ? schema.description : ""
4603
- };
4604
- });
4605
- }
4606
- module2.exports = function createActionSchemaView(options) {
4607
- var raw = String(options.domain || "");
4608
- var SOURCE = options.source === "actions.list" ? "actions.list" : "actionSchema";
4609
- var DOMAIN = SOURCE === "actions.list" ? raw : raw.indexOf("wb-addon-") === 0 ? raw : "wb-addon-" + raw;
4610
- var LIST_DOMAIN = options.listDomain ? String(options.listDomain) : DOMAIN;
4611
- var prefix = options.prefix;
4612
- var P = prefix + "-as";
4613
- var Icon2 = options.Icon || null;
4614
- var injectCss = require_action_schema_style()(prefix, DOMAIN);
4615
- var Highlight = createHighlight(P);
4616
- function icon(name, size) {
4617
- return Icon2 ? h(Icon2, { name, size: size || 14 }) : null;
4618
- }
4619
- function plainCopy(text) {
4620
- if (typeof document === "undefined") return;
4621
- var area = document.createElement("textarea");
4622
- area.value = text;
4623
- area.setAttribute("readonly", "readonly");
4624
- area.style.position = "fixed";
4625
- area.style.opacity = "0";
4626
- document.body.appendChild(area);
4627
- area.select();
4628
- try {
4629
- document.execCommand("copy");
4630
- } catch (e) {
4631
- }
4632
- document.body.removeChild(area);
4633
- }
4634
- function ActionSchemaView(props) {
4635
- var lang = props.lang === "en" ? "en" : "zh";
4636
- var t = COPY[lang];
4637
- var api = props.api;
4638
- var snapState = React.useState(null);
4639
- var snap = snapState[0], setSnap = snapState[1];
4640
- var errState = React.useState("");
4641
- var err = errState[0], setErr = errState[1];
4642
- var loadingState = React.useState(true);
4643
- var loading = loadingState[0], setLoading = loadingState[1];
4644
- var reloadState = React.useState(0);
4645
- var reload = reloadState[0], setReload = reloadState[1];
4646
- var queryState = React.useState("");
4647
- var query = queryState[0], setQuery = queryState[1];
4648
- var reqState = React.useState("all");
4649
- var reqMode = reqState[0], setReqMode = reqState[1];
4650
- var typeState = React.useState("");
4651
- var typePick = typeState[0], setTypePick = typeState[1];
4652
- var originFilterState = React.useState("");
4653
- var originPick = originFilterState[0], setOriginPick = originFilterState[1];
4654
- var toastState = React.useState("");
4655
- var toast = toastState[0], setToast = toastState[1];
4656
- var savingState = React.useState("");
4657
- var saving = savingState[0], setSaving = savingState[1];
4658
- var foldsState = React.useState({});
4659
- var folds = foldsState[0], setFolds = foldsState[1];
4660
- React.useEffect(function() {
4661
- injectCss();
4662
- }, []);
4663
- React.useEffect(function() {
4664
- var alive = true;
4665
- setLoading(true);
4666
- setErr("");
4667
- var pending;
4668
- var actionName = SOURCE === "actions.list" ? "actions.list" : DOMAIN.replace(/^wb-addon-/, "") + ".actionSchema";
4669
- var callArgs = SOURCE === "actions.list" ? { detail: true, domain: LIST_DOMAIN } : void 0;
4670
- if (api && typeof api.call === "function") {
4671
- pending = Promise.resolve(api.call(actionName, callArgs)).then(function(r) {
4672
- if (r && r.ok === false) return r;
4673
- return r && r.result || r;
4674
- });
4675
- } else {
4676
- pending = Promise.reject(new Error("no call api"));
4677
- }
4678
- Promise.resolve(pending).then(function(r) {
4679
- if (!alive) return;
4680
- if (!r || r.ok === false) {
4681
- setSnap(null);
4682
- setErr(String(r && (r.error || r.text) || t.loadFail));
4683
- } else {
4684
- setSnap(r);
4685
- }
4686
- setLoading(false);
4687
- }, function(e) {
4688
- if (!alive) return;
4689
- setSnap(null);
4690
- setErr(String(e && e.message || e || t.loadFail));
4691
- setLoading(false);
4692
- });
4693
- return function() {
4694
- alive = false;
4695
- };
4696
- }, [reload]);
4697
- function copy(text) {
4698
- var done = function() {
4699
- setToast(t.copied);
4700
- };
4701
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
4702
- navigator.clipboard.writeText(text).then(done, function() {
4703
- plainCopy(text);
4704
- done();
4705
- });
4706
- return;
4707
- }
4708
- plainCopy(text);
4709
- done();
4710
- }
4711
- var ORIGINS = ["ui", "plugin", "agent", "sync"];
4712
- var originText = { ui: t.originUi, plugin: t.originPlugin, agent: t.originAgent, sync: t.originSync };
4713
- function setOrigins(action, origin) {
4714
- var name = action.name;
4715
- var current = Array.isArray(action.origins) ? action.origins.slice() : [];
4716
- var index = current.indexOf(origin);
4717
- var next = index >= 0 ? current.filter(function(o) {
4718
- return o !== origin;
4719
- }) : current.concat([origin]);
4720
- if (next.length === 0) {
4721
- setToast(t.originsEmpty);
4722
- return;
4723
- }
4724
- next = ORIGINS.filter(function(o) {
4725
- return next.indexOf(o) >= 0;
4726
- });
4727
- setSaving(name);
4728
- setToast("");
4729
- var fail = function(e) {
4730
- setSaving("");
4731
- setToast(t.originsFail + "\uFF1A" + String(e && e.message || e || ""));
4732
- };
4733
- var done = function(r) {
4734
- setSaving("");
4735
- var payload = r && typeof r === "object" && Object.prototype.hasOwnProperty.call(r, "result") ? r.result : r;
4736
- if (r && r.ok === false) {
4737
- setToast(t.originsFail + "\uFF1A" + String(r.error || r.text || ""));
4738
- return;
4739
- }
4740
- var value = payload && Array.isArray(payload.origins) ? payload.origins : next;
4741
- var source = payload && typeof payload.source === "string" ? payload.source : action.originsSource;
4742
- setSnap(function(prev) {
4743
- if (!prev || !Array.isArray(prev.actions)) return prev;
4744
- return Object.assign({}, prev, {
4745
- actions: prev.actions.map(function(a) {
4746
- if (!a || a.name !== name) return a;
4747
- return Object.assign({}, a, { origins: value, originsSource: source });
4748
- })
4749
- });
4750
- });
4751
- setToast(t.originsToast);
4752
- };
4753
- if (!api || typeof api.call !== "function") {
4754
- fail(new Error("no call api"));
4755
- return;
4756
- }
4757
- Promise.resolve(api.call("actions.setActionOrigins", { action: name, origins: next })).then(done, fail);
4758
- }
4759
- function paramsOpen(action) {
4760
- if (Object.prototype.hasOwnProperty.call(folds, action.name)) return folds[action.name] === true;
4761
- return Boolean(String(query || "").trim()) || reqMode !== "all" || Boolean(typePick);
4762
- }
4763
- function resetFolds() {
4764
- setFolds(function(prev) {
4765
- return Object.keys(prev).length ? {} : prev;
4766
- });
4767
- }
4768
- var all = snap && Array.isArray(snap.actions) ? snap.actions.filter(function(a) {
4769
- return a && a.domain === DOMAIN;
4770
- }) : [];
4771
- var info = snap && Array.isArray(snap.domains) ? snap.domains.filter(function(d) {
4772
- return d && d.id === DOMAIN;
4773
- })[0] || null : null;
4774
- var typeOptions = [];
4775
- all.forEach(function(a) {
4776
- paramRows(a).forEach(function(row) {
4777
- row.types.forEach(function(name) {
4778
- if (typeOptions.indexOf(name) < 0) typeOptions.push(name);
4779
- });
4780
- });
4781
- });
4782
- typeOptions.sort();
4783
- var kw = String(query || "").trim();
4784
- var q = kw.toLowerCase();
4785
- var visible = all.filter(function(a) {
4786
- var rows = paramRows(a);
4787
- if (q) {
4788
- var hay = [a.name || "", a.description || ""].concat(rows.map(function(row) {
4789
- return row.name + " " + row.type + " " + row.description;
4790
- })).join(" ").toLowerCase();
4791
- if (hay.indexOf(q) < 0) return false;
4792
- }
4793
- var hasRequired = rows.some(function(row) {
4794
- return row.required;
4795
- });
4796
- if (reqMode === "required" && !hasRequired) return false;
4797
- if (reqMode === "optional" && hasRequired) return false;
4798
- if (typePick && !rows.some(function(row) {
4799
- return row.types.indexOf(typePick) >= 0;
4800
- })) return false;
4801
- if (originPick && (!Array.isArray(a.origins) || a.origins.indexOf(originPick) < 0)) return false;
4802
- return true;
4803
- });
4804
- function paramRow(row) {
4805
- var extra = extraText(row.schema, t);
4806
- return h(
4807
- "tr",
4808
- { key: row.name },
4809
- h("td", { className: P + "-mono " + P + "-pname" }, Highlight.hit(row.name, kw)),
4810
- h("td", { className: P + "-mono " + P + "-ptype" }, Highlight.hit(row.type, kw)),
4811
- h(
4812
- "td",
4813
- { className: row.required ? P + "-req " + P + "-pneed" : P + "-opt " + P + "-pneed" },
4814
- row.required ? t.required : t.optional
4815
- ),
4816
- // extra(默认 / 枚举 / 约束)不在过滤 haystack 里,因此也不高亮,保持「显示即命中」口径。
4817
- h("td", { className: P + "-mono " + P + "-pextra" }, extra),
4818
- h("td", { className: P + "-pdesc" }, Highlight.hit(row.description, kw))
4819
- );
4820
- }
4821
- function originsChips(action) {
4822
- if (!Array.isArray(action.origins)) return null;
4823
- if (action.originsSource === "invalid") {
4824
- return h("span", { className: P + "-badge " + P + "-locked", title: t.originsPinnedHint, "data-origins-invalid": action.name }, t.originsPinned);
4825
- }
4826
- var busy = saving === action.name;
4827
- var pinned = action.name === "actions.setActionOrigins";
4828
- var supported = Array.isArray(action.originsDeclared) ? action.originsDeclared : action.origins;
4829
- return h(
4830
- "div",
4831
- { className: P + "-origins", "data-origins-row": action.name },
4832
- h("span", { className: P + "-origins-label" }, t.originsLabel),
4833
- ORIGINS.map(function(origin) {
4834
- var on = action.origins.indexOf(origin) >= 0;
4835
- var allowed = supported.indexOf(origin) >= 0;
4836
- var preset = Array.isArray(action.originsDefault) ? action.originsDefault : supported;
4837
- var byDefault = preset.indexOf(origin) >= 0;
4838
- return h(
4839
- "label",
4840
- {
4841
- key: origin,
4842
- className: P + "-origin" + (allowed ? "" : " " + P + "-origin-off"),
4843
- title: pinned ? t.originsPinnedHint : !allowed ? t.originsUnsupported : originText[origin] + " \xB7 " + action.name + " \xB7 " + (byDefault ? t.originsDefaultOn : t.originsDefaultOff)
4844
- },
4845
- h("input", {
4846
- type: "checkbox",
4847
- checked: on,
4848
- disabled: busy || pinned || !allowed,
4849
- "data-origin": origin,
4850
- "data-origin-row": action.name,
4851
- "data-origin-supported": allowed ? "1" : "0",
4852
- onChange: function() {
4853
- setOrigins(action, origin);
4854
- }
4855
- }),
4856
- h("span", null, originText[origin])
4857
- );
4858
- }),
4859
- busy ? h("span", { className: P + "-origins-label" }, t.originsSaving) : null
4860
- );
4861
- }
4862
- function card(action) {
4863
- var rows = paramRows(action);
4864
- var required = rows.filter(function(row) {
4865
- return row.required;
4866
- }).length;
4867
- var open = paramsOpen(action);
4868
- var examples = Array.isArray(action.examples) ? action.examples : [];
4869
- return h(
4870
- "div",
4871
- { className: P + "-card", key: action.name },
4872
- h(
4873
- "div",
4874
- { className: P + "-cardhead" },
4875
- h(
4876
- "div",
4877
- { className: P + "-cardmeta" },
4878
- h("code", { className: P + "-mono" }, Highlight.hit(action.name, kw)),
4879
- h("span", { className: P + "-badge" }, rows.length ? t.paramCount(rows.length) : t.noParams),
4880
- rows.some(function(row) {
4881
- return row.required;
4882
- }) ? h("span", { className: P + "-badge " + P + "-req" }, t.required) : null
4883
- ),
4884
- originsChips(action)
4885
- ),
4886
- action.description ? h("p", { className: P + "-desc" }, Highlight.hit(action.description, kw)) : null,
4887
- rows.length ? h(
4888
- Disclosure,
4889
- {
4890
- className: P + "-params",
4891
- title: t.params,
4892
- meta: required ? t.requiredCount(required) : "",
4893
- attrs: { "data-params-fold": action.name },
4894
- open,
4895
- // 原生 details 自带键盘与无障碍语义,这里只记下用户的开合;
4896
- // 筛选变化引起的程序性开合也会触发 toggle,记下的值与当次默认一致,随后由 resetFolds 清掉。
4897
- onToggle: function(e) {
4898
- var next = !!(e && e.currentTarget && e.currentTarget.open);
4899
- setFolds(function(prev) {
4900
- if (prev[action.name] === next) return prev;
4901
- var out = Object.assign({}, prev);
4902
- out[action.name] = next;
4903
- return out;
4904
- });
4905
- }
4906
- },
4907
- h(
4908
- "table",
4909
- { className: P + "-table" },
4910
- h("thead", null, h(
4911
- "tr",
4912
- null,
4913
- h("th", null, t.colName),
4914
- h("th", null, t.colType),
4915
- h("th", null, t.colReq),
4916
- h("th", null, t.colExtra),
4917
- h("th", null, t.colDesc)
4918
- )),
4919
- h("tbody", null, rows.map(paramRow))
4920
- )
4921
- ) : h("div", { className: P + "-none" }, t.noParams),
4922
- h(
4923
- "div",
4924
- { className: P + "-example" },
4925
- h(
4926
- "div",
4927
- { className: P + "-examplehead" },
4928
- h("span", { className: P + "-none" }, t.examples),
4929
- examples.length ? h("button", {
4930
- type: "button",
4931
- className: P + "-copy",
4932
- "data-copy-example": action.name,
4933
- onClick: function() {
4934
- copy(JSON.stringify(examples.length === 1 ? examples[0] : examples, null, 2));
4935
- }
4936
- }, t.copy) : null
4937
- ),
4938
- examples.length ? examples.map(function(example, index) {
4939
- return h("pre", { className: P + "-pre", key: index }, JSON.stringify(example, null, 2));
4940
- }) : h("div", { className: P + "-none" }, t.noExamples)
4941
- ),
4942
- h(
4943
- Disclosure,
4944
- { title: t.raw },
4945
- h("pre", { className: P + "-pre" }, JSON.stringify(action.input || {}, null, 2))
4946
- )
4947
- );
4948
- }
4949
- var body;
4950
- if (loading) {
4951
- body = h("div", { className: P + "-empty", role: "status" }, t.loading);
4952
- } else if (err) {
4953
- body = h(
4954
- "div",
4955
- { className: P + "-error", role: "alert" },
4956
- h("span", null, t.loadFail + "\uFF1A" + err),
4957
- h("button", { type: "button", className: P + "-copy", onClick: function() {
4958
- setReload(reload + 1);
4959
- } }, t.retry)
4960
- );
4961
- } else if (!all.length) {
4962
- body = h("div", { className: P + "-empty" }, t.emptyRegistry);
4963
- } else if (!visible.length) {
4964
- body = h("div", { className: P + "-empty" }, t.empty);
4965
- } else {
4966
- body = h("div", { className: P + "-list" }, visible.map(card));
4967
- }
4968
- return h(
4969
- "div",
4970
- { className: P },
4971
- h(
4972
- "div",
4973
- { className: P + "-head" },
4974
- h("h3", { className: P + "-title" }, t.title),
4975
- h("span", { className: P + "-badge" }, t.domain + " " + DOMAIN),
4976
- info && info.version ? h("span", { className: P + "-badge" }, t.versionLabel + " v" + info.version) : null,
4977
- snap && snap.shellVersion ? h("span", { className: P + "-badge" }, t.shell + " v" + snap.shellVersion) : null,
4978
- h("span", { className: P + "-badge" }, t.count(visible.length, all.length)),
4979
- h("span", { className: P + "-none" }, t.hint)
4980
- ),
4981
- h("p", { className: P + "-hintline" }, SOURCE === "actions.list" ? t.hostHint : t.switchHint),
4982
- snap ? h(
4983
- "div",
4984
- { className: P + "-toolbar" },
4985
- h(
4986
- "label",
4987
- { className: P + "-search" },
4988
- icon("search", 14),
4989
- h("input", {
4990
- type: "search",
4991
- value: query,
4992
- placeholder: t.search,
4993
- "aria-label": t.search,
4994
- onChange: function(e) {
4995
- setQuery(e.target.value);
4996
- resetFolds();
4997
- }
4998
- })
4999
- ),
5000
- h(
5001
- "label",
5002
- { className: P + "-none" },
5003
- t.filterReq + " ",
5004
- h(
5005
- "select",
5006
- { value: reqMode, "aria-label": t.filterReq, onChange: function(e) {
5007
- setReqMode(e.target.value);
5008
- resetFolds();
5009
- } },
5010
- h("option", { value: "all" }, t.all),
5011
- h("option", { value: "required" }, t.onlyRequired),
5012
- h("option", { value: "optional" }, t.onlyOptional)
5013
- )
5014
- ),
5015
- h(
5016
- "label",
5017
- { className: P + "-none" },
5018
- t.filterType + " ",
5019
- h(
5020
- "select",
5021
- { value: typePick, "aria-label": t.filterType, onChange: function(e) {
5022
- setTypePick(e.target.value);
5023
- resetFolds();
5024
- } },
5025
- h("option", { value: "" }, t.allTypes),
5026
- typeOptions.map(function(name) {
5027
- return h("option", { value: name, key: name }, name);
5028
- })
5029
- )
5030
- ),
5031
- h(
5032
- "label",
5033
- { className: P + "-none" },
5034
- t.filterOrigin + " ",
5035
- h(
5036
- "select",
5037
- { value: originPick, "aria-label": t.filterOrigin, "data-origin-filter": "", onChange: function(e) {
5038
- setOriginPick(e.target.value);
5039
- } },
5040
- h("option", { value: "" }, t.allOrigins),
5041
- ORIGINS.map(function(origin) {
5042
- return h("option", { value: origin, key: origin }, originText[origin]);
5043
- })
5044
- )
5045
- )
5046
- ) : null,
5047
- body,
5048
- toast ? h("div", { className: P + "-toast", role: "status" }, toast) : null
5049
- );
5050
- }
5051
- return { ActionSchemaView, DOMAIN, typeLabel, paramRows };
5052
- };
5053
- }
5054
- });
5055
-
5056
- // packages/addons/salary/client/views/actions.cjs
5057
- var require_actions = __commonJS({
5058
- "packages/addons/salary/client/views/actions.cjs"(exports2, module2) {
5059
- "use strict";
5060
- module2.exports = require_action_schema_view()({
5061
- domain: "wb-addon-salary",
5062
- prefix: "wbsal"
5063
- }).ActionSchemaView;
5064
- }
5065
- });
5066
-
5067
4200
  // packages/addons/salary/client/client.src.cjs
5068
4201
  var GLYPHS = require_icons2().ICONS;
5069
4202
  (function() {
@@ -5104,12 +4237,11 @@ var GLYPHS = require_icons2().ICONS;
5104
4237
  ensureStyles();
5105
4238
  host.registerAddon({
5106
4239
  id: "wb-addon-salary",
5107
- version: "0.4.14",
4240
+ version: "0.4.16",
5108
4241
  icon: GLYPHS["wallet"],
5109
4242
  views: [
5110
4243
  { id: "stats", icon: tabIcon("stats"), title: { zh: "\u7EDF\u8BA1", en: "Stats" }, component: withProps(require_stats(), "\u7EDF\u8BA1") },
5111
- { id: "records", icon: tabIcon("records"), title: { zh: "\u8BB0\u5F55", en: "Records" }, component: withProps(require_records(), "\u8BB0\u5F55") },
5112
- { id: "actions", icon: tabIcon("actions"), title: { zh: "Action", en: "Actions" }, component: withProps(require_actions(), "Action") }
4244
+ { id: "records", icon: tabIcon("records"), title: { zh: "\u8BB0\u5F55", en: "Records" }, component: withProps(require_records(), "\u8BB0\u5F55") }
5113
4245
  ]
5114
4246
  });
5115
4247
  module.exports = { name: "dsh-workbench-salary", inject: [], apply: function() {
@@ -176,6 +176,86 @@ export function createSalary({ db, host, log }) {
176
176
  return { deleted: true, id: row.id };
177
177
  }
178
178
 
179
+ // 备份导入:按 id UPSERT,id 对不上再用自然键(发薪日 + 所属期 + 应发 + 实发 + 备注)兜底。
180
+ // 三档策略与 docs/specs/15-数据备份.md 一致;软删的行不参与匹配,也不会被复活。
181
+ const IMPORT_POLICIES = ["newest", "skip", "overwrite"];
182
+ const IMPORT_KEYS = MONEY_FIELDS.map((f) => f.column);
183
+
184
+ function importRow(raw) {
185
+ const payDate = requireDate(raw.payDate, "发薪日期");
186
+ const cycle = normalizeCycle(raw.cycle);
187
+ const employmentType = normalizeEmploymentType(raw.employmentType);
188
+ const period = incomePeriod(raw.incomePeriod, payDate, cycle);
189
+ const money = moneyInput(raw);
190
+ const gross = hasValue(raw.grossPay) ? money.grossPay : derivedTotals(money).gross;
191
+ const net = hasValue(raw.netPay) ? money.netPay : round2(Math.max(gross - sumKeys(money, SOCIAL_KEYS) - money.incomeTax - money.postTaxDeduction, 0));
192
+ const note = String(raw.note === undefined ? "" : raw.note).trim();
193
+ const stamp = {
194
+ created: Number(raw.createdAt) > 0 ? Number(raw.createdAt) : now(),
195
+ updated: Number(raw.updatedAt) > 0 ? Number(raw.updatedAt) : now(),
196
+ rev: Number(raw.rev) > 0 ? Number(raw.rev) : 1,
197
+ };
198
+ const backupId = typeof raw.id === "string" ? raw.id.trim() : "";
199
+ let local = backupId ? one("SELECT * FROM salary_record WHERE id=?", backupId) : null;
200
+ if (!local) {
201
+ local = one(
202
+ `SELECT * FROM salary_record WHERE deleted_at IS NULL AND pay_date=? AND IFNULL(income_period,'')=?
203
+ AND ABS(gross_pay-?)<0.005 AND ABS(net_pay-?)<0.005 AND note=? ORDER BY created_at LIMIT 1`,
204
+ payDate,
205
+ period || "",
206
+ gross,
207
+ net,
208
+ note,
209
+ );
210
+ }
211
+ const values = MONEY_FIELDS.map((f) => (f.key === "grossPay" ? gross : f.key === "netPay" ? net : money[f.key]));
212
+ return {
213
+ local,
214
+ stamp,
215
+ row: [payDate, period, cycle, employmentType, ...values, note],
216
+ };
217
+ }
218
+
219
+ function importRecords(records, policy) {
220
+ const mode = IMPORT_POLICIES.includes(policy) ? policy : "newest";
221
+ const report = { ok: true, imported: 0, skipped: 0, failed: 0, policy: mode };
222
+ const list = Array.isArray(records) ? records : [];
223
+ const columns = ["pay_date", "income_period", "cycle", "employment_type", ...IMPORT_KEYS, "note"];
224
+ const assignments = columns.map((column) => column + "=excluded." + column).join(", ");
225
+ for (const raw of list) {
226
+ try {
227
+ if (!raw || typeof raw !== "object") throw new Error("工资记录格式不正确");
228
+ const { local, stamp, row } = importRow(raw);
229
+ if (local && local.deleted_at !== null && local.deleted_at !== undefined) {
230
+ report.skipped += 1;
231
+ continue;
232
+ }
233
+ if (local) {
234
+ const outdated = mode === "newest" && Number(local.updated_at) >= stamp.updated;
235
+ if (mode === "skip" || outdated) {
236
+ report.skipped += 1;
237
+ continue;
238
+ }
239
+ }
240
+ const id = local ? local.id : (typeof raw.id === "string" && raw.id.trim() ? raw.id.trim() : newId("sal"));
241
+ run(
242
+ `INSERT INTO salary_record (id, ${columns.join(", ")}, created_at, updated_at, rev) VALUES (${Array.from({ length: columns.length + 4 }, () => "?").join(", ")})
243
+ ON CONFLICT(id) DO UPDATE SET ${assignments}, created_at=excluded.created_at, updated_at=excluded.updated_at, rev=excluded.rev, deleted_at=NULL`,
244
+ id,
245
+ ...row,
246
+ stamp.created,
247
+ stamp.updated,
248
+ stamp.rev,
249
+ );
250
+ report.imported += 1;
251
+ } catch {
252
+ report.failed += 1;
253
+ }
254
+ }
255
+ report.ok = report.failed === 0;
256
+ return report;
257
+ }
258
+
179
259
  function breakdown(rows) {
180
260
  const fields = {};
181
261
  for (const field of MONEY_FIELDS) fields[field.key] = round2(rows.reduce((sum, r) => sum + (Number(r[field.key]) || 0), 0));
@@ -335,5 +415,5 @@ export function createSalary({ db, host, log }) {
335
415
  }
336
416
 
337
417
 
338
- return { status, list, get, create, update, remove, stats, dump, record };
418
+ return { status, list, get, create, update, remove, stats, dump, record, importRecords };
339
419
  }
package/lib/index.js CHANGED
@@ -21,7 +21,6 @@ export function setup(api) {
21
21
  const VIEWS = [
22
22
  { id: "records", title: { zh: "工资记录", en: "Records" } },
23
23
  { id: "stats", title: { zh: "统计", en: "Stats" } },
24
- { id: "actions", title: { zh: "Action", en: "Actions" } },
25
24
  ];
26
25
 
27
26
  export function apply(ctx) {
@@ -68,18 +67,14 @@ export function apply(ctx) {
68
67
  ],
69
68
  },
70
69
  exportData: () => ({ records: engine.dump() }),
71
- importData: (payload) => {
70
+ importData: (payload, _ctx, options) => {
72
71
  let data = payload;
73
72
  if (typeof data === "string") {
74
73
  try { data = JSON.parse(data); } catch { data = {}; }
75
74
  }
76
75
  const records = data && Array.isArray(data.records) ? data.records : [];
77
- let imported = 0;
78
- let failed = 0;
79
- for (const item of records) {
80
- try { engine.create({ ...item, incomePeriod: item.incomePeriod ?? null }); imported += 1; } catch { failed += 1; }
81
- }
82
- return { imported, failed };
76
+ // 逐行 UPSERT:同一份备份导入两次不应再长出重复行(importRecords 内部按 policy 处理)。
77
+ return engine.importRecords(records, options && options.policy);
83
78
  },
84
79
  setup,
85
80
  }), "salary-domain");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workbench-salary",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "description": "个人工作台工资插件:按发薪日期记录工资构成、扣款与实发",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -16,15 +16,14 @@
16
16
  "addon": {
17
17
  "id": "wb-addon-salary",
18
18
  "title": "工资",
19
- "version": "0.4.14",
19
+ "version": "0.4.16",
20
20
  "minShell": "0.8.0",
21
21
  "tables": [
22
22
  "salary_record"
23
23
  ],
24
24
  "views": [
25
25
  "records",
26
- "stats",
27
- "actions"
26
+ "stats"
28
27
  ],
29
28
  "toolActions": [
30
29
  "salary.status",
@@ -40,7 +39,7 @@
40
39
  }
41
40
  },
42
41
  "dependencies": {
43
- "dsh-workbench-host": "^0.17.6"
42
+ "dsh-workbench-host": "^0.25.0"
44
43
  },
45
44
  "dsh": {
46
45
  "bundle": {