soma-kit 0.1.13 → 0.1.14
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/package.json +3 -3
- package/spec/generated/kit-app.schema.json +14 -0
- package/spec/generated/kit-page.schema.json +25 -0
- package/spec/kit-grammar.json +178 -27
- package/spec/kit-grammar.schema.json +1 -3
- package/src/app/app-config.ts +10 -4
- package/src/app/index.ts +13 -1
- package/src/app/kit-view-context.ts +19 -2
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/base/button.ts +5 -3
- package/src/base/end-edge.ts +14 -2
- package/src/base/gap-value.ts +24 -4
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +5 -0
- package/src/base/menu-button.ts +10 -23
- package/src/base/popover.ts +5 -4
- package/src/base/segmented.ts +14 -4
- package/src/base/shared.ts +11 -13
- package/src/base/state-panel.ts +34 -13
- package/src/base/tag.ts +18 -13
- package/src/base/text.ts +1 -1
- package/src/base/upload.ts +5 -4
- package/src/biz/approval-desk/shell.ts +8 -7
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +3 -2
- package/src/biz/category-crud/shell.ts +4 -3
- package/src/biz/checkout-page/shell.ts +9 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +12 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/master-sub/compile.ts +114 -15
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +3 -2
- package/src/biz/master-sub/shell.ts +95 -63
- package/src/biz/multi-board/compile.ts +164 -9
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +1 -1
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +91 -23
- package/src/biz/notification-center/shell.ts +6 -5
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -2
- package/src/biz/page-templates/sign-in-page/shell.ts +14 -14
- package/src/biz/record-detail/shell.ts +8 -7
- package/src/biz/settings-center/shell.ts +8 -7
- package/src/biz/shared/compile-helpers.ts +82 -3
- package/src/biz/shared/overlay-compile.ts +46 -4
- package/src/biz/shared/overlay-shell.ts +8 -6
- package/src/biz/single-form/shell.ts +6 -4
- package/src/biz/standard-crud/compile.ts +14 -1
- package/src/biz/standard-crud/shell.ts +18 -27
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +11 -9
- package/src/biz/types.ts +6 -1
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/compile-page.ts +15 -4
- package/src/compile/component-candidates.ts +2 -0
- package/src/compile/fragment.ts +11 -0
- package/src/compile/layout-lint/rules-composition.ts +55 -6
- package/src/compile/layout-lint/rules-form.ts +6 -7
- package/src/compile/layout-lint/rules-table.ts +98 -14
- package/src/compile/page-composition.ts +189 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/styles.ts +11 -1
- package/src/compile/types.ts +3 -1
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +3 -1
- package/src/data/approval-flow.ts +4 -1
- package/src/data/assignment-picker.ts +9 -4
- package/src/data/async-result-panel.ts +1 -1
- package/src/data/calendar.ts +7 -2
- package/src/data/carousel.ts +2 -0
- package/src/data/chart.ts +609 -42
- package/src/data/checklist.ts +4 -1
- package/src/data/comment-thread.ts +2 -1
- package/src/data/confirm-dialog.ts +4 -10
- package/src/data/field-mapper.ts +4 -1
- package/src/data/flow-editor.ts +2 -1
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +187 -25
- package/src/data/hero.ts +2 -0
- package/src/data/index.ts +10 -3
- package/src/data/item-list.ts +10 -3
- package/src/data/kanban.ts +3 -1
- package/src/data/matrix.ts +391 -0
- package/src/data/menu.ts +23 -11
- package/src/data/mockup.ts +3 -3
- package/src/data/modal-dialog.ts +118 -18
- package/src/data/navbar.ts +3 -1
- package/src/data/notice-list.ts +52 -19
- package/src/data/object-form.ts +128 -112
- package/src/data/pager.ts +3 -2
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +4 -1
- package/src/data/permission-tree.ts +6 -2
- package/src/data/pricing-table.ts +2 -1
- package/src/data/record-card.ts +18 -6
- package/src/data/resident.ts +8 -0
- package/src/data/row-editor.ts +2 -2
- package/src/data/rule-builder.ts +9 -4
- package/src/data/shape-util.ts +15 -14
- package/src/data/stat-group.ts +313 -69
- package/src/data/static-lazy.ts +4 -0
- package/src/data/static-registry.ts +6 -0
- package/src/data/survey.ts +4 -1
- package/src/data/system-switcher.ts +2 -1
- package/src/data/tour-guide.ts +2 -1
- package/src/data/transfer.ts +6 -2
- package/src/data/tree-table.ts +7 -5
- package/src/data/tree.ts +1 -1
- package/src/data/virtual-rows.ts +5 -4
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +6 -14
- package/src/frames/shared.ts +20 -4
- package/src/frames/tabs-frame/shell.ts +8 -6
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +41 -25
- package/src/generated/kit-grammar-runtime.ts +175 -28
- package/src/i18n/kit-text.ts +27 -0
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +49 -19
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +34 -13
- package/src/object-renderer/collection-table.ts +133 -65
- package/src/object-renderer/collection.ts +72 -59
- package/src/object-renderer/defaults.ts +2 -5
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +116 -63
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +9 -1
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +59 -46
- package/src/object-renderer/table-actions.ts +72 -40
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +51 -20
- package/src/object-renderer/types.ts +7 -7
- package/src/recipes/container.ts +31 -0
- package/src/recipes/control.ts +57 -155
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +23 -0
- package/src/recipes/overlay.ts +46 -1
- package/src/recipes/placeholder.ts +20 -4
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +12 -22
- package/src/recipes/status.ts +8 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +112 -6
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +3 -3
- package/src/recipes/typography.ts +23 -42
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +13 -2
- package/src/theme/kit-theme.tpl +13 -2
- package/src/theme/nine-dim-structure.ts +77 -10
- package/src/theme/surface-layers.ts +6 -1
- package/src/theme/theme-tokens.ts +12 -5
- package/src/theme/typography.ts +21 -17
package/src/data/checklist.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { kitIcon } from '../base/icons';
|
|
|
13
13
|
import { mergeClass } from '../object-renderer/merge-class';
|
|
14
14
|
import { kitStateMarkRecipe } from '../recipes/state';
|
|
15
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
17
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
16
18
|
import {
|
|
17
19
|
actionButton, actionsOf, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, mkProgressBar, PROGRESS_BAR_CLASS_TOKENS, recOf, setProgressBar, rowsOf, shapeToneOf, textOf,
|
|
18
20
|
TONE_SOFT,
|
|
@@ -25,7 +27,7 @@ export type KitCheckStatus = 'done' | 'blocked' | 'pending';
|
|
|
25
27
|
|
|
26
28
|
const ROOT_CLASS = 'flex flex-col gap-3 rounded-lg border border-border-subtle bg-surface p-5 text-sm text-fg';
|
|
27
29
|
const HEAD_CLASS = 'flex flex-wrap items-center gap-2';
|
|
28
|
-
const TITLE_CLASS = '
|
|
30
|
+
const TITLE_CLASS = kitTypographyRecipe('sectionTitle');
|
|
29
31
|
const COUNT_CLASS = 'ms-auto text-xs text-fg-muted';
|
|
30
32
|
const PROGRESS_CLASS = 'block w-full';
|
|
31
33
|
const LIST_CLASS = 'flex flex-col gap-1';
|
|
@@ -158,6 +160,7 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
158
160
|
const items = checkItemsOf(data[m.items], p.item_map, noReason, st.overrides);
|
|
159
161
|
|
|
160
162
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
163
|
+
markKitEdge(root);
|
|
161
164
|
root.textContent = '';
|
|
162
165
|
|
|
163
166
|
const head = mk('div', HEAD_CLASS);
|
|
@@ -11,6 +11,7 @@ import { matchSubmitKey } from 'soma-core/keyboard';
|
|
|
11
11
|
import { bool, createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
13
|
import { setKitFace } from '../recipes';
|
|
14
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
14
15
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
15
16
|
import { AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
|
|
16
17
|
import { CHAT_MAX_LENGTH, CHAT_MAX_MESSAGES, CHAT_STATUSES } from './d9-limits';
|
|
@@ -30,7 +31,7 @@ const CHAT_META = 'flex items-center gap-2 px-1 text-xs text-fg-subtle';
|
|
|
30
31
|
const CHAT_META_FAILED = 'flex items-center gap-2 px-1 text-xs text-danger-on-soft';
|
|
31
32
|
const CHAT_RETRY = 'rounded-md text-danger-on-soft underline transition-colors hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
32
33
|
const CHAT_LIST = 'flex flex-col gap-4 overflow-y-auto';
|
|
33
|
-
const CHAT_ATTACH = '
|
|
34
|
+
const CHAT_ATTACH = kitEmphasisButtonRecipe('button.toolbar');
|
|
34
35
|
const CHAT_CLASS_TOKENS = classTokens(
|
|
35
36
|
CHAT_MSG, CHAT_MSG_MINE, CHAT_COL, CHAT_COL_MINE, CHAT_NAME, CHAT_BUBBLE, CHAT_THEM, CHAT_ME, CHAT_META, CHAT_META_FAILED, CHAT_RETRY,
|
|
36
37
|
CHAT_LIST, CHAT_ATTACH, AVATAR_CLASS_TOKENS,
|
|
@@ -16,14 +16,8 @@ import { nextUid } from '../base/shared';
|
|
|
16
16
|
import { kitText } from '../i18n/kit-text';
|
|
17
17
|
import { setKitFace } from '../recipes';
|
|
18
18
|
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal } from './modal-dialog';
|
|
19
|
-
import { BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
19
|
+
import { ACTION_BUTTON_TONE, BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
20
20
|
|
|
21
|
-
const BUTTON_BASE = 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md px-4 text-sm font-medium transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
22
|
-
const BUTTON_TONE: Readonly<Record<ActionTone, string>> = Object.freeze({
|
|
23
|
-
primary: 'border-0 bg-primary text-primary-fg hover:opacity-90',
|
|
24
|
-
danger: 'border-0 bg-danger text-danger-fg hover:opacity-90',
|
|
25
|
-
neutral: 'border border-button-edge bg-surface text-fg state-layer',
|
|
26
|
-
});
|
|
27
21
|
const BUTTON_DISABLED = 'opacity-60 cursor-not-allowed';
|
|
28
22
|
const MESSAGE_CLASS = 'm-0 whitespace-pre-line text-sm text-fg';
|
|
29
23
|
const IMPACT_CLASS = 'm-0 whitespace-pre-line text-xs text-fg-muted';
|
|
@@ -31,7 +25,7 @@ const PROMPT_CLASS = 'm-0 text-xs text-fg-muted';
|
|
|
31
25
|
const INPUT_CLASS = 'h-8 w-full rounded-md border border-border bg-surface px-3 text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
32
26
|
|
|
33
27
|
export const KIT_CONFIRM_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
34
|
-
|
|
28
|
+
BUTTON_DISABLED, MESSAGE_CLASS, IMPACT_CLASS, PROMPT_CLASS, INPUT_CLASS, BUTTON_CLASS_TOKENS, KIT_MODAL_CLASS_CANDIDATES,
|
|
35
29
|
KIT_CHECK_CLASS_CANDIDATES,
|
|
36
30
|
);
|
|
37
31
|
|
|
@@ -63,7 +57,7 @@ export interface KitConfirmOptions {
|
|
|
63
57
|
function btn(doc: Document, tone: ActionTone, label: string): HTMLButtonElement {
|
|
64
58
|
const b = doc.createElement('button');
|
|
65
59
|
b.type = 'button';
|
|
66
|
-
b.className =
|
|
60
|
+
b.className = ACTION_BUTTON_TONE[tone];
|
|
67
61
|
setKitFace(b, 'raised');
|
|
68
62
|
b.textContent = label;
|
|
69
63
|
return b;
|
|
@@ -145,7 +139,7 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
145
139
|
ok.disabled = !met;
|
|
146
140
|
if (met) ok.removeAttribute('aria-disabled');
|
|
147
141
|
else ok.setAttribute('aria-disabled', 'true');
|
|
148
|
-
ok.className = `${
|
|
142
|
+
ok.className = `${ACTION_BUTTON_TONE[tone]}${met ? '' : ` ${BUTTON_DISABLED}`}`;
|
|
149
143
|
};
|
|
150
144
|
const onGateKey = (e: KeyboardEvent): void => {
|
|
151
145
|
if (gate !== null && confirmKeyAccepts(e, gate, gateInput())) { e.preventDefault(); finish(true); }
|
package/src/data/field-mapper.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { setKitFace } from '../recipes';
|
|
|
19
19
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
20
20
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
21
21
|
import { createKitEmbedBag, mountKitSelectField, type KitSelectField } from './embed';
|
|
22
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
23
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
22
24
|
|
|
23
25
|
// ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
|
|
24
26
|
|
|
@@ -34,7 +36,7 @@ const ARROW_CLASS = 'shrink-0 text-fg-subtle';
|
|
|
34
36
|
const CONTROL_CLASS = 'block h-8 w-48 max-w-full appearance-none autofill-clear rounded-md border border-border bg-surface px-2 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle';
|
|
35
37
|
const REMOVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-sm text-danger-on-soft hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
36
38
|
const ADD_ROW_CLASS = 'flex flex-wrap items-center gap-2 pt-2';
|
|
37
|
-
const BTN_CLASS = '
|
|
39
|
+
const BTN_CLASS = kitEmphasisButtonRecipe('button.toolbar');
|
|
38
40
|
const NOTICE_CLASS = 'rounded-md bg-warning-soft px-3 py-2 text-xs text-warning-on-soft';
|
|
39
41
|
const PREVIEW_TITLE_CLASS = 'text-xs text-fg-muted';
|
|
40
42
|
const PREVIEW_WRAP_CLASS = 'overflow-x-auto rounded-lg border border-border-subtle';
|
|
@@ -391,6 +393,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
391
393
|
previewBox.appendChild(inner);
|
|
392
394
|
inner.appendChild(el('div', PREVIEW_TITLE_CLASS, tx('soma.kit.fm_preview')));
|
|
393
395
|
const wrap = el('div', PREVIEW_WRAP_CLASS);
|
|
396
|
+
markKitEdge(wrap);
|
|
394
397
|
const table = el('table', PREVIEW_TABLE_CLASS);
|
|
395
398
|
const thead = el('thead', '');
|
|
396
399
|
const hr = el('tr', '');
|
package/src/data/flow-editor.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
|
20
20
|
import { applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
21
21
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
22
22
|
import { setKitFace } from '../recipes';
|
|
23
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
23
24
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
24
25
|
import { createInput, KIT_INPUT_CLASS_CANDIDATES } from '../base/input';
|
|
25
26
|
import { createTextarea, KIT_TEXTAREA_CLASS_CANDIDATES } from '../base/textarea';
|
|
@@ -196,7 +197,7 @@ export function fmt(template: string, vars: Record<string, string | number>): st
|
|
|
196
197
|
export const FLOW_CLASS = Object.freeze({
|
|
197
198
|
root: 'flex w-full flex-col gap-2',
|
|
198
199
|
toolbar: 'flex flex-wrap items-center gap-2',
|
|
199
|
-
btn: '
|
|
200
|
+
btn: kitEmphasisButtonRecipe('button.toolbar'),
|
|
200
201
|
btnPrimary: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-primary bg-primary px-3 text-sm text-primary-fg transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
201
202
|
zoomLabel: 'text-xs text-fg-muted',
|
|
202
203
|
row: 'flex w-full items-start gap-2',
|
package/src/data/footer.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
12
12
|
import { createKitController, joinClass } from '../base/shared';
|
|
13
13
|
import { classTokens, mk, rowsOf, textOf, type Rec } from './shape-util';
|
|
14
14
|
import { singleOf, urlOf } from './display-util';
|
|
15
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
15
16
|
|
|
16
17
|
const KEYS = ['brand', 'columns', 'copyright', 'social'] as const;
|
|
17
18
|
|
|
@@ -105,6 +106,7 @@ export function createFooter(): SomaComponentDefinition {
|
|
|
105
106
|
},
|
|
106
107
|
render(root, p) {
|
|
107
108
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
109
|
+
markKitEdge(root);
|
|
108
110
|
root.textContent = '';
|
|
109
111
|
const src = singleOf(p.data, p, KEYS);
|
|
110
112
|
const brand = textOf(src.brand);
|
package/src/data/gantt.ts
CHANGED
|
@@ -21,6 +21,12 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
21
21
|
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
22
22
|
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
23
23
|
import { kitText } from '../i18n/kit-text';
|
|
24
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
25
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
26
|
+
import {
|
|
27
|
+
GANTT_BAR_LABEL_MAX, GANTT_CHART_FALLBACK_PX, GANTT_LABEL_COLUMN_PX, GANTT_NOTE_MAX,
|
|
28
|
+
ganttBarLabelPlace, ganttBaselineBox, ganttIsNarrow, ganttTextWidthPx,
|
|
29
|
+
} from 'soma-foundation/kit-viz';
|
|
24
30
|
|
|
25
31
|
// ── 数据规整纯函数:日期换算、任务解析、时间轴、任务条位置、刻度、行序 ──
|
|
26
32
|
|
|
@@ -34,11 +40,19 @@ export interface KitGanttMap {
|
|
|
34
40
|
deps: string;
|
|
35
41
|
tone: string;
|
|
36
42
|
owner: string;
|
|
43
|
+
/** task(缺省)/ milestone:里程碑起止同日,画菱形与标签,不画进度 */
|
|
44
|
+
kind: string;
|
|
45
|
+
/** 基线幽灵条起止(YYYY-MM-DD):现计划条下方的细灰条,用于「承诺 / AI 建议 vs 现计划」对照 */
|
|
46
|
+
base_start: string;
|
|
47
|
+
base_end: string;
|
|
48
|
+
/** 组标题行附注(取组内第一个非空值) */
|
|
49
|
+
group_note: string;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
export const KIT_GANTT_DEFAULT_MAP: Readonly<KitGanttMap> = Object.freeze({
|
|
40
53
|
id: 'id', title: 'title', start: 'start', end: 'end', progress: 'progress',
|
|
41
54
|
group: 'group', deps: 'deps', tone: 'tone', owner: 'owner',
|
|
55
|
+
kind: 'kind', base_start: 'base_start', base_end: 'base_end', group_note: 'group_note',
|
|
42
56
|
});
|
|
43
57
|
|
|
44
58
|
export type KitGanttTone = 'primary' | 'success' | 'warning' | 'danger' | 'info';
|
|
@@ -53,6 +67,10 @@ export interface KitGanttTask {
|
|
|
53
67
|
deps: string[];
|
|
54
68
|
tone: KitGanttTone;
|
|
55
69
|
owner: string;
|
|
70
|
+
milestone: boolean;
|
|
71
|
+
/** 基线起止(天序号);没有基线为 null */
|
|
72
|
+
base: { from: number; to: number } | null;
|
|
73
|
+
groupNote: string;
|
|
56
74
|
startText: string;
|
|
57
75
|
endText: string;
|
|
58
76
|
raw: unknown;
|
|
@@ -119,8 +137,14 @@ export function parseGanttTasks(data: unknown, map: KitGanttMap): KitGanttTask[]
|
|
|
119
137
|
if (raw === null || typeof raw !== 'object') return;
|
|
120
138
|
const r = raw as Record<string, unknown>;
|
|
121
139
|
const from = ganttDayIndex(r[map.start]);
|
|
122
|
-
const
|
|
140
|
+
const milestone = str(r[map.kind]).trim() === 'milestone';
|
|
141
|
+
// 里程碑只需要一个日期:结束缺失或非法时取开始日
|
|
142
|
+
const rawEnd = ganttDayIndex(r[map.end]);
|
|
143
|
+
const end = milestone ? from : rawEnd;
|
|
123
144
|
if (!Number.isFinite(from) || !Number.isFinite(end)) return;
|
|
145
|
+
const bf = ganttDayIndex(r[map.base_start]);
|
|
146
|
+
const bt = ganttDayIndex(r[map.base_end]);
|
|
147
|
+
const base = !milestone && Number.isFinite(bf) && Number.isFinite(bt) ? { from: Math.min(bf, bt), to: Math.max(bf, bt) } : null;
|
|
124
148
|
let id = str(r[map.id]).trim();
|
|
125
149
|
if (id === '') id = `t${index}`;
|
|
126
150
|
if (seen.has(id)) id = `${id}#${index}`;
|
|
@@ -131,11 +155,14 @@ export function parseGanttTasks(data: unknown, map: KitGanttMap): KitGanttTask[]
|
|
|
131
155
|
title: str(r[map.title]).trim() || id,
|
|
132
156
|
from,
|
|
133
157
|
to: Math.max(from, end),
|
|
134
|
-
progress: pr === null ? 0 : Math.min(100, Math.max(0, pr)),
|
|
158
|
+
progress: milestone || pr === null ? 0 : Math.min(100, Math.max(0, pr)),
|
|
135
159
|
group: str(r[map.group]).trim(),
|
|
136
160
|
deps: Array.isArray(r[map.deps]) ? (r[map.deps] as unknown[]).map((d) => str(d).trim()).filter((d) => d !== '') : [],
|
|
137
161
|
tone: toneOf(r[map.tone]),
|
|
138
162
|
owner: str(r[map.owner]).trim(),
|
|
163
|
+
milestone,
|
|
164
|
+
base,
|
|
165
|
+
groupNote: str(r[map.group_note]).trim().slice(0, GANTT_NOTE_MAX),
|
|
139
166
|
startText: ganttDayText(from),
|
|
140
167
|
endText: ganttDayText(Math.max(from, end)),
|
|
141
168
|
raw,
|
|
@@ -149,8 +176,9 @@ export function ganttAxis(tasks: readonly KitGanttTask[], startDate: unknown, en
|
|
|
149
176
|
const ef = ganttDayIndex(startDate);
|
|
150
177
|
const et = ganttDayIndex(endDate);
|
|
151
178
|
if (tasks.length === 0 && !(Number.isFinite(ef) && Number.isFinite(et))) return null;
|
|
152
|
-
|
|
153
|
-
const
|
|
179
|
+
// 基线条也算进自动轴范围,免得对照条画到轴外
|
|
180
|
+
const from = Number.isFinite(ef) ? ef : Math.min(...tasks.map((t) => Math.min(t.from, t.base?.from ?? t.from)));
|
|
181
|
+
const to = Number.isFinite(et) ? et : Math.max(...tasks.map((t) => Math.max(t.to, t.base?.to ?? t.to)));
|
|
154
182
|
const hi = Math.max(from, to);
|
|
155
183
|
return { from, to: hi, span: hi - from + 1 };
|
|
156
184
|
}
|
|
@@ -169,6 +197,17 @@ export function ganttTicks(axis: KitGanttAxis, count: number): string[] {
|
|
|
169
197
|
return Array.from({ length: n }, (_, i) => ganttDayText(axis.from + Math.round((axis.span * i) / n)));
|
|
170
198
|
}
|
|
171
199
|
|
|
200
|
+
/** 休息日 -> 轴内的连续区段 [首日, 末日](天序号,闭区间):非法日期与轴外的丢弃,重复去重,相邻天合并(纯函数) */
|
|
201
|
+
export function restRuns(raw: unknown, axis: KitGanttAxis): Array<[number, number]> {
|
|
202
|
+
const days = [...new Set((Array.isArray(raw) ? raw : []).map(ganttDayIndex).filter((d) => Number.isFinite(d) && d >= axis.from && d <= axis.to))].sort((a, b) => a - b);
|
|
203
|
+
const runs: Array<[number, number]> = [];
|
|
204
|
+
for (const d of days) {
|
|
205
|
+
const last = runs[runs.length - 1];
|
|
206
|
+
if (last !== undefined && d === last[1] + 1) last[1] = d; else runs.push([d, d]);
|
|
207
|
+
}
|
|
208
|
+
return runs;
|
|
209
|
+
}
|
|
210
|
+
|
|
172
211
|
/** 数值转短文本,避免浮点尾巴把属性写得很长 */
|
|
173
212
|
function fx(n: number): string {
|
|
174
213
|
return String(Math.round(n * 1000) / 1000);
|
|
@@ -178,14 +217,19 @@ interface Row {
|
|
|
178
217
|
kind: 'group' | 'task';
|
|
179
218
|
group: string;
|
|
180
219
|
task?: KitGanttTask;
|
|
220
|
+
/** 组标题行附注(组内第一个非空 group_note) */
|
|
221
|
+
note?: string;
|
|
181
222
|
}
|
|
182
223
|
|
|
183
|
-
/**
|
|
224
|
+
/** 行序:保持数据顺序;组名变化(非空)时在前面插一条分组行(附注取该组内第一个非空 group_note) */
|
|
184
225
|
export function ganttRows(tasks: readonly KitGanttTask[]): Row[] {
|
|
185
226
|
const rows: Row[] = [];
|
|
186
227
|
let last = '';
|
|
187
228
|
for (const task of tasks) {
|
|
188
|
-
if (task.group !== '' && task.group !== last)
|
|
229
|
+
if (task.group !== '' && task.group !== last) {
|
|
230
|
+
const note = tasks.find((t) => t.group === task.group && t.groupNote !== '')?.groupNote ?? '';
|
|
231
|
+
rows.push({ kind: 'group', group: task.group, ...(note !== '' ? { note } : {}) });
|
|
232
|
+
}
|
|
189
233
|
if (task.group !== '') last = task.group;
|
|
190
234
|
rows.push({ kind: 'task', group: task.group, task });
|
|
191
235
|
}
|
|
@@ -197,25 +241,27 @@ export function ganttRows(tasks: readonly KitGanttTask[]): Row[] {
|
|
|
197
241
|
const ROOT_CLASS = 'flex flex-col overflow-x-auto text-sm text-fg';
|
|
198
242
|
const INNER_CLASS = 'flex min-w-160 flex-col';
|
|
199
243
|
const HEAD_CLASS = 'flex border-b border-border-subtle';
|
|
200
|
-
|
|
244
|
+
// 左栏宽 = 真源 dataLimits.gantt.labelColumnMinPx(192 = w-48);行头任务名有最小宽,状态 / 负责人附注截断在自己的上限内
|
|
245
|
+
const CORNER_CLASS = 'w-48 shrink-0 px-2 py-1 text-xs font-medium text-fg-muted';
|
|
201
246
|
const TICKS_CLASS = 'flex flex-1';
|
|
202
247
|
const TICK_CLASS = 'flex-1 border-l border-border-subtle px-1 py-1 text-xs text-fg-muted';
|
|
203
248
|
const BODY_CLASS = 'flex';
|
|
204
|
-
const LABELS_CLASS = 'flex w-
|
|
249
|
+
const LABELS_CLASS = 'flex w-48 shrink-0 flex-col';
|
|
205
250
|
const ROW_BTN_CLASS = 'flex h-8 w-full items-center gap-2 px-2 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
206
|
-
const ROW_TITLE_CLASS = 'min-w-
|
|
207
|
-
const ROW_OWNER_CLASS = '
|
|
208
|
-
const GROUP_ROW_CLASS = 'flex h-8 items-center bg-surface-
|
|
251
|
+
const ROW_TITLE_CLASS = 'min-w-24 flex-1 truncate';
|
|
252
|
+
const ROW_OWNER_CLASS = 'min-w-0 max-w-20 truncate text-xs text-fg-muted';
|
|
253
|
+
const GROUP_ROW_CLASS = 'flex h-8 items-center gap-2 overflow-hidden whitespace-nowrap bg-surface-band px-2 text-xs font-medium text-fg-muted';
|
|
209
254
|
const CHART_CLASS = 'relative flex-1';
|
|
210
255
|
const SVG_CLASS = 'absolute inset-0 h-full w-full';
|
|
211
256
|
const EMPTY_CLASS = 'px-3 py-6 text-center text-fg-muted';
|
|
212
257
|
|
|
258
|
+
// 任务条 = 语义浅色填充、无描边、胶囊圆角(与状态徽标同族);进度段用同语气实心色
|
|
213
259
|
const TRACK_CLASS: Record<KitGanttTone, string> = {
|
|
214
|
-
primary: 'fill-primary-soft
|
|
215
|
-
success: 'fill-success-soft
|
|
216
|
-
warning: 'fill-warning-soft
|
|
217
|
-
danger: 'fill-danger-soft
|
|
218
|
-
info: 'fill-info-soft
|
|
260
|
+
primary: 'fill-primary-soft',
|
|
261
|
+
success: 'fill-success-soft',
|
|
262
|
+
warning: 'fill-warning-soft',
|
|
263
|
+
danger: 'fill-danger-soft',
|
|
264
|
+
info: 'fill-info-soft',
|
|
219
265
|
};
|
|
220
266
|
const DONE_CLASS: Record<KitGanttTone, string> = {
|
|
221
267
|
primary: 'fill-primary',
|
|
@@ -224,17 +270,29 @@ const DONE_CLASS: Record<KitGanttTone, string> = {
|
|
|
224
270
|
danger: 'fill-danger',
|
|
225
271
|
info: 'fill-info',
|
|
226
272
|
};
|
|
227
|
-
const GROUP_BG_CLASS = 'fill-surface-
|
|
273
|
+
const GROUP_BG_CLASS = 'fill-surface-band';
|
|
228
274
|
const GRID_LINE_CLASS = 'stroke-border-subtle';
|
|
229
275
|
const DEP_LINE_CLASS = 'fill-none stroke-fg-subtle';
|
|
230
276
|
const DEP_ARROW_CLASS = 'fill-fg-subtle';
|
|
231
277
|
const TODAY_CLASS = 'stroke-danger';
|
|
278
|
+
/** 休息日底纹 / 基线幽灵条 / 条上文字(条内 / 外置)/ 里程碑字形 / 组附注;文字叠加层是不带 viewBox 的第二张 SVG(文字不随非等比 viewBox 变形) */
|
|
279
|
+
// 颜色自带透明度(fill-x/50),不用 opacity-50:后者是 G101 disabledOpacity 类族(禁用态不透明度),这里是图形底纹
|
|
280
|
+
const REST_DAY_CLASS = 'fill-surface-sunken/50';
|
|
281
|
+
const BASELINE_CLASS = 'fill-fg-subtle/50';
|
|
282
|
+
// 条内文字压在进度实心色 / 浅轨两种底上:用面板色描边做光晕(paint-order 先描边后填充),任何底色上都可读
|
|
283
|
+
const LABEL_IN_CLASS = mergeClass('fill-fg stroke-surface stroke-2', kitTypographyRecipe('deltaSm'));
|
|
284
|
+
const LABEL_OUT_CLASS = mergeClass('fill-fg-muted', kitTypographyRecipe('captionPlain'));
|
|
285
|
+
const MILESTONE_GLYPH_CLASS = kitTypographyRecipe('text');
|
|
286
|
+
const OVERLAY_SVG_CLASS = 'pointer-events-none absolute inset-0 h-full w-full';
|
|
287
|
+
const GROUP_NOTE_CLASS = 'ms-auto min-w-0 truncate font-normal text-fg-subtle';
|
|
288
|
+
const MILESTONE_GLYPH = '◆';
|
|
232
289
|
|
|
233
290
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
234
291
|
export const KIT_GANTT_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
235
292
|
[...new Set([
|
|
236
293
|
ROOT_CLASS, INNER_CLASS, HEAD_CLASS, CORNER_CLASS, TICKS_CLASS, TICK_CLASS, BODY_CLASS, LABELS_CLASS, ROW_BTN_CLASS,
|
|
237
294
|
ROW_TITLE_CLASS, ROW_OWNER_CLASS, GROUP_ROW_CLASS, CHART_CLASS, SVG_CLASS, EMPTY_CLASS,
|
|
295
|
+
REST_DAY_CLASS, BASELINE_CLASS, LABEL_IN_CLASS, LABEL_OUT_CLASS, MILESTONE_GLYPH_CLASS, OVERLAY_SVG_CLASS, GROUP_NOTE_CLASS,
|
|
238
296
|
...Object.values(TRACK_CLASS), ...Object.values(DONE_CLASS),
|
|
239
297
|
GROUP_BG_CLASS, GRID_LINE_CLASS, DEP_LINE_CLASS, DEP_ARROW_CLASS, TODAY_CLASS,
|
|
240
298
|
].flatMap((s) => s.split(/\s+/)).filter((c) => c !== ''))].sort(),
|
|
@@ -258,10 +316,12 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
258
316
|
layer: 'data',
|
|
259
317
|
props: {
|
|
260
318
|
data: { type: 'array', default: [], desc: '任务行 [{ id, title, start, end, progress?, group?, deps?, tone?, owner? }];日期 YYYY-MM-DD' },
|
|
261
|
-
map: { type: 'object', default: {}, desc: '键名对照 { id, title, start, end, progress, group, deps, tone, owner }:组件期望的键 ->
|
|
319
|
+
map: { type: 'object', default: {}, desc: '键名对照 { id, title, start, end, progress, group, deps, tone, owner, kind, base_start, base_end, group_note }:组件期望的键 -> 数据里的键;kind: milestone 画菱形里程碑(只需 start),base_start / base_end 画基线幽灵条,group_note 是组标题行附注' },
|
|
262
320
|
start_date: { type: 'string', default: '', desc: '轴起点(YYYY-MM-DD);空则取任务最早开始' },
|
|
263
321
|
end_date: { type: 'string', default: '', desc: '轴终点(YYYY-MM-DD);空则取任务最晚结束' },
|
|
264
322
|
today: { type: 'string', default: '', desc: '今日线日期(YYYY-MM-DD),由页面显式传入;空或不在轴内则不画' },
|
|
323
|
+
rest_days: { type: 'array', default: [], desc: '休息日(YYYY-MM-DD 数组,业务对象下发):在轴内画浅色底纹,连续的天合并成一块' },
|
|
324
|
+
bar_label: { type: 'string', default: 'none', desc: '条上文字:none(缺省)/ title / owner;条内放得下画在条内,放不下外置到条旁,窄宽(容器 < 窄宽阈值)不画;里程碑始终在菱形旁标出标题' },
|
|
265
325
|
tick_count: { type: 'number', default: DEFAULT_TICKS, desc: '表头刻度段数,2–10' },
|
|
266
326
|
show_progress: { type: 'boolean', default: true, desc: '是否画进度' },
|
|
267
327
|
empty_text: { type: 'string', default: '', desc: '无任务时的空态文案;缺省取内置文案(按页面语言)' },
|
|
@@ -284,7 +344,7 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
284
344
|
return node;
|
|
285
345
|
};
|
|
286
346
|
|
|
287
|
-
const buildChart = (rows: readonly Row[], axis: KitGanttAxis, p: Record<string, unknown
|
|
347
|
+
const buildChart = (rows: readonly Row[], axis: KitGanttAxis, p: Record<string, unknown>, narrow: boolean): SVGElement => {
|
|
288
348
|
const n = rows.length;
|
|
289
349
|
const svg = svgEl('svg', { viewBox: `0 0 100 ${n}`, preserveAspectRatio: 'none', 'aria-hidden': 'true' }, SVG_CLASS);
|
|
290
350
|
const line = (x1: number, y1: number, x2: number, y2: number, cls: string): SVGElement =>
|
|
@@ -293,6 +353,10 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
293
353
|
rows.forEach((row, i) => {
|
|
294
354
|
if (row.kind === 'group') svg.appendChild(svgEl('rect', { x: '0', y: fx(i), width: '100', height: '1' }, GROUP_BG_CLASS));
|
|
295
355
|
});
|
|
356
|
+
// 休息日底纹:轴内的休息日连续合并成一块,铺满全部行(在分隔线与条之下)
|
|
357
|
+
for (const [a, b] of restRuns(p.rest_days, axis)) {
|
|
358
|
+
svg.appendChild(svgEl('rect', { x: fx(((a - axis.from) / axis.span) * 100), y: '0', width: fx(((b - a + 1) / axis.span) * 100), height: fx(n), 'data-kit-rest': '' }, REST_DAY_CLASS));
|
|
359
|
+
}
|
|
296
360
|
for (let i = 1; i < n; i += 1) svg.appendChild(line(0, i, 100, i, GRID_LINE_CLASS));
|
|
297
361
|
// 刻度竖线(与表头的等分段对齐)
|
|
298
362
|
const tickCount = Math.min(10, Math.max(2, Math.floor(num(p.tick_count) ?? DEFAULT_TICKS)));
|
|
@@ -305,10 +369,19 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
305
369
|
const t = row.task;
|
|
306
370
|
const { x, w } = ganttBar(t, axis);
|
|
307
371
|
index.set(t.id, { row: i, x, w });
|
|
372
|
+
// 里程碑没有条:菱形字形与标签画在文字叠加层,这里只登记位置(依赖线仍可接到它)
|
|
373
|
+
if (t.milestone) return;
|
|
308
374
|
const g = svgEl('g', { 'data-kit-bar': t.id });
|
|
309
|
-
|
|
375
|
+
// 基线幽灵条:现计划条下方的细灰条(窄宽降级时不画)
|
|
376
|
+
if (t.base !== null && !narrow) {
|
|
377
|
+
const box = ganttBaselineBox(BAR_TOP, BAR_HEIGHT);
|
|
378
|
+
const bx = ((t.base.from - axis.from) / axis.span) * 100;
|
|
379
|
+
const bw = ((t.base.to - t.base.from + 1) / axis.span) * 100;
|
|
380
|
+
g.appendChild(svgEl('rect', { x: fx(bx), y: fx(i + box.y), width: fx(bw), height: fx(box.h), 'data-kit-baseline': t.id }, BASELINE_CLASS));
|
|
381
|
+
}
|
|
382
|
+
g.appendChild(svgEl('rect', { x: fx(x), y: fx(i + BAR_TOP), width: fx(w), height: fx(BAR_HEIGHT), 'data-kit-pill': '' }, TRACK_CLASS[t.tone]));
|
|
310
383
|
if (showProgress && t.progress > 0) {
|
|
311
|
-
g.appendChild(svgEl('rect', { x: fx(x), y: fx(i + BAR_TOP), width: fx((w * t.progress) / 100), height: fx(BAR_HEIGHT) }, DONE_CLASS[t.tone]));
|
|
384
|
+
g.appendChild(svgEl('rect', { x: fx(x), y: fx(i + BAR_TOP), width: fx((w * t.progress) / 100), height: fx(BAR_HEIGHT), 'data-kit-pill': '' }, DONE_CLASS[t.tone]));
|
|
312
385
|
}
|
|
313
386
|
svg.appendChild(g);
|
|
314
387
|
});
|
|
@@ -345,6 +418,59 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
345
418
|
return svg;
|
|
346
419
|
};
|
|
347
420
|
|
|
421
|
+
/**
|
|
422
|
+
* 文字叠加层:第二张不带 viewBox 的 SVG(坐标全用百分比 + 像素偏移,文字不随主图的非等比 viewBox 变形)。
|
|
423
|
+
* 里程碑 = 菱形字形 + 标题(始终显示);条上文字 = 条内放得下画在条内(嵌套 svg 裁切),放不下外置到条右侧(右侧也放不下则左侧);窄宽不画条上文字。
|
|
424
|
+
*/
|
|
425
|
+
const buildOverlay = (rows: readonly Row[], axis: KitGanttAxis, p: Record<string, unknown>, chartPx: number, narrow: boolean): SVGElement | null => {
|
|
426
|
+
const mode = str(p.bar_label) === 'title' ? 'title' : str(p.bar_label) === 'owner' ? 'owner' : 'none';
|
|
427
|
+
const n = rows.length;
|
|
428
|
+
const svg = svgEl('svg', { 'aria-hidden': 'true' }, OVERLAY_SVG_CLASS);
|
|
429
|
+
let any = false;
|
|
430
|
+
const pct = (v: number): string => `${fx(v)}%`;
|
|
431
|
+
const text = (value: string, attrs: Record<string, string>, cls: string): void => {
|
|
432
|
+
const node = svgEl('text', { 'dominant-baseline': 'central', ...attrs }, cls);
|
|
433
|
+
node.textContent = value;
|
|
434
|
+
svg.appendChild(node);
|
|
435
|
+
any = true;
|
|
436
|
+
};
|
|
437
|
+
// 文字放在条(或菱形)外:右侧放得下用右侧,否则用左侧
|
|
438
|
+
const beside = (value: string, left: number, right: number, y: number, cls: string, extra: Record<string, string> = {}): void => {
|
|
439
|
+
const px = ganttTextWidthPx(value);
|
|
440
|
+
const roomRight = ((100 - right) / 100) * chartPx;
|
|
441
|
+
if (px + 8 <= roomRight || (left / 100) * chartPx < px + 8) text(value, { x: pct(right), y: pct(y), dx: '6', 'text-anchor': 'start', ...extra }, cls);
|
|
442
|
+
else text(value, { x: pct(left), y: pct(y), dx: '-6', 'text-anchor': 'end', ...extra }, cls);
|
|
443
|
+
};
|
|
444
|
+
rows.forEach((row, i) => {
|
|
445
|
+
if (row.kind !== 'task' || !row.task) return;
|
|
446
|
+
const t = row.task;
|
|
447
|
+
const { x, w } = ganttBar(t, axis);
|
|
448
|
+
const y = ((i + 0.5) / n) * 100;
|
|
449
|
+
if (t.milestone) {
|
|
450
|
+
const cx = x + w / 2;
|
|
451
|
+
text(MILESTONE_GLYPH, { x: pct(cx), y: pct(y), 'text-anchor': 'middle', 'data-kit-milestone': t.id }, `${DONE_CLASS[t.tone]} ${MILESTONE_GLYPH_CLASS}`);
|
|
452
|
+
// 菱形字形占约一个字宽:左右各留半字
|
|
453
|
+
const half = (ganttTextWidthPx(MILESTONE_GLYPH) / 2 / Math.max(chartPx, 1)) * 100;
|
|
454
|
+
beside(t.title.slice(0, GANTT_BAR_LABEL_MAX), cx - half, cx + half, y, LABEL_OUT_CLASS);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (mode === 'none' || narrow) return;
|
|
458
|
+
const value = (mode === 'owner' ? t.owner : t.title).slice(0, GANTT_BAR_LABEL_MAX);
|
|
459
|
+
if (value === '') return;
|
|
460
|
+
if (ganttBarLabelPlace(value, (w / 100) * chartPx) === 'inside') {
|
|
461
|
+
const box = svgEl('svg', { x: pct(x), y: pct((i / n) * 100), width: pct(w), height: pct(100 / n), overflow: 'hidden' });
|
|
462
|
+
const node = svgEl('text', { x: '6', y: '50%', 'dominant-baseline': 'central', 'paint-order': 'stroke', 'stroke-linejoin': 'round', 'data-kit-bar-label': t.id }, LABEL_IN_CLASS);
|
|
463
|
+
node.textContent = value;
|
|
464
|
+
box.appendChild(node);
|
|
465
|
+
svg.appendChild(box);
|
|
466
|
+
any = true;
|
|
467
|
+
} else {
|
|
468
|
+
beside(value, x, x + w, y, LABEL_OUT_CLASS, { 'data-kit-bar-label': t.id });
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
return any ? svg : null;
|
|
472
|
+
};
|
|
473
|
+
|
|
348
474
|
const paint = (): void => {
|
|
349
475
|
if (!root) return;
|
|
350
476
|
const p = P();
|
|
@@ -377,7 +503,10 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
377
503
|
const labels = el('div', LABELS_CLASS);
|
|
378
504
|
for (const row of rows) {
|
|
379
505
|
if (row.kind === 'group') {
|
|
380
|
-
|
|
506
|
+
const groupRow = el('div', GROUP_ROW_CLASS, row.group);
|
|
507
|
+
// 组标题行附注(如「共 8.5 人日 · 2 天超载」),取自数据
|
|
508
|
+
if (row.note !== undefined) groupRow.appendChild(el('span', GROUP_NOTE_CLASS, row.note));
|
|
509
|
+
labels.appendChild(groupRow);
|
|
381
510
|
continue;
|
|
382
511
|
}
|
|
383
512
|
const t = row.task!;
|
|
@@ -386,19 +515,41 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
386
515
|
btn.setAttribute('data-kit-task', t.id);
|
|
387
516
|
const pct = showProgress && t.progress > 0 ? kitText('soma.kit.gantt_done', { n: Math.round(t.progress) }, root) : '';
|
|
388
517
|
const ownerPart = t.owner !== '' ? ` ${t.owner}` : '';
|
|
389
|
-
|
|
518
|
+
const baseText = t.base !== null ? kitText('soma.kit.gantt_baseline', { start: ganttDayText(t.base.from), end: ganttDayText(t.base.to) }, root) : '';
|
|
519
|
+
btn.setAttribute('aria-label', t.milestone
|
|
520
|
+
? `${kitText('soma.kit.gantt_milestone', { title: t.title, date: t.startText }, root)}${ownerPart}`
|
|
521
|
+
: `${kitText('soma.kit.gantt_range', { title: t.title, owner: ownerPart, start: t.startText, end: t.endText, pct }, root)}${baseText}`);
|
|
390
522
|
const rowTitle = el('span', ROW_TITLE_CLASS, t.title);
|
|
391
523
|
rowTitle.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
392
524
|
btn.appendChild(rowTitle);
|
|
393
|
-
if (t.owner !== '')
|
|
525
|
+
if (t.owner !== '') {
|
|
526
|
+
const ownerNote = el('span', ROW_OWNER_CLASS, t.owner);
|
|
527
|
+
ownerNote.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
528
|
+
btn.appendChild(ownerNote);
|
|
529
|
+
}
|
|
394
530
|
labels.appendChild(btn);
|
|
395
531
|
}
|
|
396
532
|
body.appendChild(labels);
|
|
397
533
|
const chart = el('div', CHART_CLASS);
|
|
398
|
-
|
|
534
|
+
// 容器宽:窄宽降级(不画条上文字与基线)与条上文字放得下与否的判定都用它;无布局环境(测不到)时用回落宽度
|
|
535
|
+
const rootPx = root.clientWidth;
|
|
536
|
+
const narrow = ganttIsNarrow(rootPx);
|
|
537
|
+
const chartPx = rootPx > 0 ? Math.max(rootPx - GANTT_LABEL_COLUMN_PX, 0) : GANTT_CHART_FALLBACK_PX;
|
|
538
|
+
chart.appendChild(buildChart(rows, axis, p, narrow) as unknown as Node);
|
|
539
|
+
const overlay = buildOverlay(rows, axis, p, chartPx, narrow);
|
|
540
|
+
if (overlay !== null) chart.appendChild(overlay as unknown as Node);
|
|
399
541
|
body.appendChild(chart);
|
|
400
542
|
inner.appendChild(body);
|
|
401
543
|
root.appendChild(inner);
|
|
544
|
+
// 胶囊圆角:主图是非等比 viewBox(x 每单位 = 图宽 / 100,y 每单位 = 一行高),圆角的 rx / ry 按实测折算成同一物理半径(半个条高);无布局环境(测不到)不画圆角
|
|
545
|
+
const rowPx = labels.querySelector('button')?.getBoundingClientRect().height ?? 0;
|
|
546
|
+
const chartW = chart.getBoundingClientRect().width;
|
|
547
|
+
if (rowPx > 0 && chartW > 0) {
|
|
548
|
+
for (const r of chart.querySelectorAll('[data-kit-pill]')) {
|
|
549
|
+
r.setAttribute('ry', fx(BAR_HEIGHT / 2));
|
|
550
|
+
r.setAttribute('rx', fx(((BAR_HEIGHT / 2) * rowPx) / (chartW / 100)));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
402
553
|
if (focused !== null) {
|
|
403
554
|
[...root.querySelectorAll<HTMLElement>('[data-kit-task]')].find((b) => b.getAttribute('data-kit-task') === focused)?.focus();
|
|
404
555
|
}
|
|
@@ -415,8 +566,19 @@ export function createGantt(): SomaComponentDefinition {
|
|
|
415
566
|
if (task) api.emit('pick', { id: task.id, item: task.raw });
|
|
416
567
|
};
|
|
417
568
|
r.addEventListener('click', onClick);
|
|
569
|
+
// 容器宽变化时重画(窄宽降级、条上文字放得下与否都依赖宽度);宽度变化不足 8px 不重画
|
|
570
|
+
let lastWidth = r.clientWidth;
|
|
571
|
+
const obs = typeof ResizeObserver === 'function'
|
|
572
|
+
? new ResizeObserver(() => {
|
|
573
|
+
if (Math.abs(r.clientWidth - lastWidth) < 8) return;
|
|
574
|
+
lastWidth = r.clientWidth;
|
|
575
|
+
paint();
|
|
576
|
+
})
|
|
577
|
+
: null;
|
|
578
|
+
obs?.observe(r);
|
|
418
579
|
return () => {
|
|
419
580
|
r.removeEventListener('click', onClick);
|
|
581
|
+
obs?.disconnect();
|
|
420
582
|
root = null;
|
|
421
583
|
};
|
|
422
584
|
},
|
package/src/data/hero.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
9
9
|
import { createKitController, joinClass, str } from '../base/shared';
|
|
10
10
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, mk, rowsOf, type ShapeAction } from './shape-util';
|
|
11
11
|
import { singleOf, urlOf } from './display-util';
|
|
12
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
12
13
|
|
|
13
14
|
export const KIT_HERO_LAYOUTS = ['center', 'split'] as const;
|
|
14
15
|
export type KitHeroLayout = (typeof KIT_HERO_LAYOUTS)[number];
|
|
@@ -114,6 +115,7 @@ export function createHero(): SomaComponentDefinition {
|
|
|
114
115
|
},
|
|
115
116
|
render(root, p) {
|
|
116
117
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
118
|
+
markKitEdge(root);
|
|
117
119
|
root.textContent = '';
|
|
118
120
|
const model = heroModelOf(p.data, p);
|
|
119
121
|
const split = heroLayoutOf(p.layout) === 'split';
|
package/src/data/index.ts
CHANGED
|
@@ -40,22 +40,25 @@ export { createFieldMapper, parseMapperData, missingTargets, exportMapping, KIT_
|
|
|
40
40
|
export type { KitFieldMapperMap, KitMapperTarget, KitFieldMapping } from './field-mapper';
|
|
41
41
|
export { createGantt, parseGanttTasks, ganttAxis, ganttBar, ganttTicks, ganttRows, ganttDayIndex, ganttDayText, KIT_GANTT_DEFAULT_MAP, KIT_GANTT_CLASS_CANDIDATES } from './gantt';
|
|
42
42
|
export type { KitGanttMap, KitGanttTask, KitGanttAxis, KitGanttTone } from './gantt';
|
|
43
|
+
export { restRuns } from './gantt';
|
|
44
|
+
export { createMatrix, matrixCellClass, matrixCellLabel, KIT_MATRIX_CLASS_CANDIDATES, KIT_MATRIX_TONES, KIT_MATRIX_MARKS } from './matrix';
|
|
43
45
|
export { createFlowEditor, KIT_FLOW_EDITOR_CLASS_CANDIDATES, layeredLayout } from './flow-editor';
|
|
44
46
|
export { createCodeView, codeTextOf, codeVariantsOf, KIT_CODE_VIEW_CLASS_CANDIDATES } from './code-view';
|
|
45
47
|
export type { KitCodeVariant } from './code-view';
|
|
46
|
-
export { mountKitModal, KIT_MODAL_CLASS_CANDIDATES } from './modal-dialog';
|
|
47
|
-
export type { KitModalHandle, KitModalOptions, KitModalSize } from './modal-dialog';
|
|
48
|
+
export { mountKitModal, mountKitDrawer, KIT_MODAL_CLASS_CANDIDATES } from './modal-dialog';
|
|
49
|
+
export type { KitModalHandle, KitModalOptions, KitModalSize, KitDrawerHandle, KitDrawerOptions, KitDrawerWidth } from './modal-dialog';
|
|
48
50
|
export { askKitConfirm, KIT_CONFIRM_CLASS_CANDIDATES } from './confirm-dialog';
|
|
49
51
|
export type { KitConfirmOptions } from './confirm-dialog';
|
|
50
52
|
export { askKitPrompt, KIT_PROMPT_CLASS_CANDIDATES } from './prompt-dialog';
|
|
51
53
|
export type { KitPromptField, KitPromptOptions } from './prompt-dialog';
|
|
52
54
|
export { mountKitComponent, mountKitSelectField, mountKitInputField, mountKitTextareaField, mountKitCheckboxField, createKitEmbedBag } from './embed';
|
|
53
55
|
export type { KitEmitHandlers, KitMount, KitSelectField, KitSelectFieldOptions, KitEmbedBag, KitEmbedHandle } from './embed';
|
|
54
|
-
export { declareKitUses } from './wrapped-candidates';
|
|
56
|
+
export { declareKitUses, declareKitComposition } from './wrapped-candidates';
|
|
55
57
|
export { wrapKitDataComponent, composeKitDataComponents, mapKeys } from './wrap';
|
|
56
58
|
export type { PackProps, WrapDataOptions, WrapOptions, ComposeDataPart, ComposeDataOptions, ComposeEventForward } from './wrap';
|
|
57
59
|
export { createItemList, listItemsOf, KIT_ITEM_LIST_CLASS_CANDIDATES } from './item-list';
|
|
58
60
|
export { createNoticeList, noticeItemsOf, noticeFoldOf, KIT_NOTICE_LIST_CLASS_CANDIDATES } from './notice-list';
|
|
61
|
+
export { createSegmentedSwitch, createMetaAction, createScopeSwitch, KIT_PANEL_HEAD_CLASS_CANDIDATES } from './panel-head';
|
|
59
62
|
export { createSystemSwitcher, systemItemsOf, filterSystems, KIT_SYSTEM_SWITCHER_CLASS_CANDIDATES } from './system-switcher';
|
|
60
63
|
export { createCalendar, calendarEventsOf, calendarRangeOf, calendarStepDate, KIT_CALENDAR_CLASS_CANDIDATES } from './calendar';
|
|
61
64
|
export { createImageViewer, imageEntriesOf, zoomStep, KIT_IMAGE_VIEWER_CLASS_CANDIDATES } from './image-viewer';
|
|
@@ -145,6 +148,7 @@ import { KIT_TRANSFER_CLASS_CANDIDATES } from './transfer';
|
|
|
145
148
|
import { KIT_PERMISSION_MATRIX_CLASS_CANDIDATES } from './permission-matrix';
|
|
146
149
|
import { KIT_FIELD_MAPPER_CLASS_CANDIDATES } from './field-mapper';
|
|
147
150
|
import { KIT_GANTT_CLASS_CANDIDATES } from './gantt';
|
|
151
|
+
import { KIT_MATRIX_CLASS_CANDIDATES } from './matrix';
|
|
148
152
|
import { KIT_KANBAN_CLASS_CANDIDATES } from './kanban';
|
|
149
153
|
import { KIT_MENU_CLASS_CANDIDATES } from './menu';
|
|
150
154
|
import { KIT_NAVBAR_CLASS_CANDIDATES } from './navbar';
|
|
@@ -167,6 +171,7 @@ import { KIT_PRICING_TABLE_CLASS_CANDIDATES } from './pricing-table';
|
|
|
167
171
|
import { KIT_CODE_VIEW_CLASS_CANDIDATES } from './code-view';
|
|
168
172
|
import { KIT_ITEM_LIST_CLASS_CANDIDATES } from './item-list';
|
|
169
173
|
import { KIT_NOTICE_LIST_CLASS_CANDIDATES } from './notice-list';
|
|
174
|
+
import { KIT_PANEL_HEAD_CLASS_CANDIDATES } from './panel-head';
|
|
170
175
|
import { KIT_SYSTEM_SWITCHER_CLASS_CANDIDATES } from './system-switcher';
|
|
171
176
|
import { KIT_CALENDAR_CLASS_CANDIDATES } from './calendar';
|
|
172
177
|
import { KIT_IMAGE_VIEWER_CLASS_CANDIDATES } from './image-viewer';
|
|
@@ -202,6 +207,7 @@ export const KIT_DATA_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
|
202
207
|
...KIT_PERMISSION_MATRIX_CLASS_CANDIDATES,
|
|
203
208
|
...KIT_FIELD_MAPPER_CLASS_CANDIDATES,
|
|
204
209
|
...KIT_GANTT_CLASS_CANDIDATES,
|
|
210
|
+
...KIT_MATRIX_CLASS_CANDIDATES,
|
|
205
211
|
...KIT_KANBAN_CLASS_CANDIDATES,
|
|
206
212
|
...KIT_MENU_CLASS_CANDIDATES,
|
|
207
213
|
...KIT_NAVBAR_CLASS_CANDIDATES,
|
|
@@ -228,6 +234,7 @@ export const KIT_DATA_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
|
228
234
|
...KIT_CODE_VIEW_CLASS_CANDIDATES,
|
|
229
235
|
...KIT_ITEM_LIST_CLASS_CANDIDATES,
|
|
230
236
|
...KIT_NOTICE_LIST_CLASS_CANDIDATES,
|
|
237
|
+
...KIT_PANEL_HEAD_CLASS_CANDIDATES,
|
|
231
238
|
...KIT_SYSTEM_SWITCHER_CLASS_CANDIDATES,
|
|
232
239
|
...KIT_CALENDAR_CLASS_CANDIDATES,
|
|
233
240
|
...KIT_IMAGE_VIEWER_CLASS_CANDIDATES,
|