@bpmn-nova/studio 0.3.9-preview → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/canvas.js +97 -25
- package/dist/config.js +13 -0
- package/dist/context-menu.js +41 -32
- package/dist/controller.js +45 -19
- package/dist/index.d.ts +47 -2
- package/dist/index.js +1 -0
- package/dist/interactions.js +6 -1
- package/dist/modules/bpmn-model/index.d.ts +2 -1
- package/dist/modules/bpmn-model/index.js +12 -10
- package/dist/modules/core/gateway.js +16 -13
- package/dist/modules/core/index.d.ts +6 -4
- package/dist/modules/core/model.js +12 -7
- package/dist/modules/designer/index.d.ts +5 -1
- package/dist/modules/designer/index.js +36 -15
- package/dist/modules/export-svg/index.d.ts +12 -5
- package/dist/modules/export-svg/preview.js +34 -24
- package/dist/modules/export-svg/render.js +102 -50
- package/dist/modules/i18n/index.d.ts +647 -0
- package/dist/modules/i18n/index.js +247 -0
- package/dist/modules/i18n/locales/en-US.js +823 -0
- package/dist/modules/i18n/locales/zh-CN.js +805 -0
- package/dist/modules/node-presentation/index.d.ts +3 -2
- package/dist/modules/node-presentation/index.js +14 -11
- package/dist/modules/palette/index.d.ts +6 -1
- package/dist/modules/palette/index.js +26 -8
- package/dist/modules/palette/panel.js +44 -6
- package/dist/modules/properties/index.d.ts +2 -1
- package/dist/modules/properties/index.js +2 -2
- package/dist/modules/properties-activiti/index.js +84 -59
- package/dist/modules/properties-bpmn/index.js +151 -128
- package/dist/modules/properties-core/index.d.ts +9 -3
- package/dist/modules/properties-core/index.js +16 -4
- package/dist/modules/properties-flowable/index.js +55 -34
- package/dist/modules/properties-renderer/index.d.ts +5 -1
- package/dist/modules/properties-renderer/index.js +110 -42
- package/dist/modules/renderer-svg/index.d.ts +6 -2
- package/dist/modules/renderer-svg/index.js +113 -38
- package/dist/modules/runtime/index.d.ts +33 -5
- package/dist/modules/runtime/index.js +97 -73
- package/dist/modules/runtime/time.js +89 -4
- package/dist/modules/runtime/visits.js +6 -4
- package/dist/modules/theme/index.d.ts +5 -2
- package/dist/modules/theme/index.js +8 -4
- package/dist/modules/viewer/index.d.ts +28 -7
- package/dist/modules/viewer/index.js +213 -56
- package/dist/modules/viewer/runtime-content.js +26 -20
- package/dist/modules/viewer/runtime-trace.js +43 -25
- package/dist/modules/viewer/timeline.js +103 -36
- package/dist/shell.js +258 -75
- package/dist/sidebars.js +3 -1
- package/dist/styles.css +3 -2
- package/llms-full.txt +241 -46
- package/llms.txt +4 -4
- package/package.json +2 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
|
|
1
2
|
import { parseRuntimeInstant, formatRuntimeInstant, compareRuntimeOrder, runtimeInstant } from './time.js';
|
|
2
3
|
import { pushDiagnostic } from './diagnostics.js';
|
|
3
4
|
import { groupVisits, markEffectiveVisits, resolveEffectiveStatus, resolveVisitStatus } from './visits.js';
|
|
@@ -7,10 +8,7 @@ export { groupVisits, resolveVisitStatus, resolveEffectiveStatus } from './visit
|
|
|
7
8
|
|
|
8
9
|
const TERMINAL_PROCESS_STATUSES = new Set(['completed', 'terminated']);
|
|
9
10
|
const ABNORMAL_TRANSITION_TYPES = new Set(['reject', 'return']);
|
|
10
|
-
const
|
|
11
|
-
submit: '提交', approve: '通过', reject: '驳回', return: '退回',
|
|
12
|
-
'add-sign': '加签', transfer: '转办', delegate: '委派', withdraw: '撤回', comment: '备注', skip: '跳过',
|
|
13
|
-
};
|
|
11
|
+
const KNOWN_RUNTIME_STATUSES = new Set(['idle', 'active', 'completed', 'failed', 'cancelled', 'skipped', 'rejected', 'returned']);
|
|
14
12
|
const OUTCOME_ACTION_TYPES = {
|
|
15
13
|
submitted: 'submit', approved: 'approve', rejected: 'reject', returned: 'return', skipped: 'skip',
|
|
16
14
|
};
|
|
@@ -114,15 +112,18 @@ function actionText(action) {
|
|
|
114
112
|
return String(action?.content?.plainText || '').trim();
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
function approvalActionLabel(action) {
|
|
118
|
-
return action?.label ||
|
|
115
|
+
function approvalActionLabel(action, i18n = DEFAULT_I18N) {
|
|
116
|
+
return action?.label || i18n.actionLabel(action?.type);
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
function summarizeApprovalActions(actions = []) {
|
|
119
|
+
function summarizeApprovalActions(actions = [], i18n = DEFAULT_I18N) {
|
|
122
120
|
const latestAction = actions.at(-1) || null;
|
|
123
121
|
const latestNonEmptyComment = [...actions].reverse().find((action) => action.plainText || action.assetCount) || null;
|
|
124
122
|
const assetSummary = latestAction
|
|
125
|
-
? [
|
|
123
|
+
? [
|
|
124
|
+
latestAction.imageCount ? i18n.t('runtime.action.imageCount', { count: latestAction.imageCount }) : '',
|
|
125
|
+
latestAction.fileCount ? i18n.t('runtime.action.fileCount', { count: latestAction.fileCount }) : '',
|
|
126
|
+
].filter(Boolean).join(' · ')
|
|
126
127
|
: '';
|
|
127
128
|
return {
|
|
128
129
|
latestAction,
|
|
@@ -149,24 +150,23 @@ function uniqueParticipants(records = []) {
|
|
|
149
150
|
return result;
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
function participantSummary(participants) {
|
|
153
|
+
function participantSummary(participants, i18n = DEFAULT_I18N) {
|
|
153
154
|
if (!participants.length) return '';
|
|
154
|
-
const visible = participants.slice(0, 2).map((item) => item.name).join('
|
|
155
|
+
const visible = participants.slice(0, 2).map((item) => item.name).join(i18n.t('common.listSeparator'));
|
|
155
156
|
return participants.length > 2 ? `${visible} +${participants.length - 2}` : visible;
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
function candidateSummary(node) {
|
|
159
|
+
function candidateSummary(node, i18n = DEFAULT_I18N) {
|
|
159
160
|
const properties = node?.properties || {};
|
|
160
161
|
const candidate = properties.candidateGroups || properties.candidateUsers;
|
|
161
162
|
if (!candidate) return '';
|
|
162
|
-
const value = Array.isArray(candidate) ? candidate.join('
|
|
163
|
-
return value ?
|
|
163
|
+
const value = Array.isArray(candidate) ? candidate.join(i18n.t('common.listSeparator')) : String(candidate);
|
|
164
|
+
return value ? i18n.t('runtime.summary.pendingClaim', { value }) : '';
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
function baseStatusLabel(status) {
|
|
167
|
-
return {
|
|
168
|
-
|
|
169
|
-
}[status] || status;
|
|
167
|
+
function baseStatusLabel(status, i18n = DEFAULT_I18N) {
|
|
168
|
+
if (KNOWN_RUNTIME_STATUSES.has(status)) return i18n.t(`runtime.status.${status}`);
|
|
169
|
+
return status;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
function transitionOrder(transition) {
|
|
@@ -177,7 +177,7 @@ function edgeVisitOrder(visit) {
|
|
|
177
177
|
return stampInstant(visit.occurredAt || visit.time);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
function collectIdentityDiagnostics(runtime, { model = null, diagnostics }) {
|
|
180
|
+
function collectIdentityDiagnostics(runtime, { model = null, diagnostics, i18n = DEFAULT_I18N }) {
|
|
181
181
|
const activityIds = new Set();
|
|
182
182
|
const actionIds = new Set();
|
|
183
183
|
const transitionIds = new Set();
|
|
@@ -189,82 +189,82 @@ function collectIdentityDiagnostics(runtime, { model = null, diagnostics }) {
|
|
|
189
189
|
runtime.activities.forEach((record, index) => {
|
|
190
190
|
const fieldPath = `activities[${index}]`;
|
|
191
191
|
if (record.id) {
|
|
192
|
-
if (activityIds.has(record.id)) pushDiagnostic(diagnostics, { code: 'duplicate-activity-id', level: 'error', message: '
|
|
192
|
+
if (activityIds.has(record.id)) pushDiagnostic(diagnostics, { code: 'duplicate-activity-id', level: 'error', message: i18n.t('runtime.diagnostics.duplicateActivityId'), fieldPath, activityId: record.id, elementId: record.elementId });
|
|
193
193
|
activityIds.add(record.id);
|
|
194
194
|
}
|
|
195
195
|
if (record.visitId) {
|
|
196
196
|
const owner = visitOwners.get(record.visitId);
|
|
197
197
|
if (owner && owner !== record.elementId) {
|
|
198
|
-
pushDiagnostic(diagnostics, { code: 'visit-element-mismatch', level: 'error', message: '
|
|
198
|
+
pushDiagnostic(diagnostics, { code: 'visit-element-mismatch', level: 'error', message: i18n.t('runtime.diagnostics.visitElementMismatch'), fieldPath, visitId: record.visitId, elementId: record.elementId });
|
|
199
199
|
}
|
|
200
200
|
visitOwners.set(record.visitId, record.elementId);
|
|
201
201
|
}
|
|
202
202
|
['startTime', 'endTime'].forEach((field) => {
|
|
203
203
|
const parsed = parseRuntimeInstant(record[field]);
|
|
204
|
-
if (parsed.kind === 'invalid') pushDiagnostic(diagnostics, { code: 'invalid-time', level: 'warning', message: '
|
|
205
|
-
else if (parsed.kind === 'naive') pushDiagnostic(diagnostics, { code: 'naive-time', level: 'info', message: '
|
|
204
|
+
if (parsed.kind === 'invalid') pushDiagnostic(diagnostics, { code: 'invalid-time', level: 'warning', message: i18n.t('runtime.diagnostics.invalidTime'), fieldPath: `${fieldPath}.${field}`, activityId: record.id, elementId: record.elementId });
|
|
205
|
+
else if (parsed.kind === 'naive') pushDiagnostic(diagnostics, { code: 'naive-time', level: 'info', message: i18n.t('runtime.diagnostics.naiveTime'), fieldPath: `${fieldPath}.${field}`, activityId: record.id, elementId: record.elementId });
|
|
206
206
|
});
|
|
207
207
|
if (model && record.elementId && !nodeIds.has(record.elementId)) {
|
|
208
|
-
pushDiagnostic(diagnostics, { code: 'unknown-element', level: 'error', message: '
|
|
208
|
+
pushDiagnostic(diagnostics, { code: 'unknown-element', level: 'error', message: i18n.t('runtime.diagnostics.unknownElement'), fieldPath: `${fieldPath}.elementId`, activityId: record.id, elementId: record.elementId });
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
runtime.actions.forEach((action, index) => {
|
|
213
213
|
const fieldPath = `actions[${index}]`;
|
|
214
|
-
if (actionIds.has(action.id)) pushDiagnostic(diagnostics, { code: 'duplicate-action-id', level: 'error', message: '
|
|
214
|
+
if (actionIds.has(action.id)) pushDiagnostic(diagnostics, { code: 'duplicate-action-id', level: 'error', message: i18n.t('runtime.diagnostics.duplicateActionId'), fieldPath, actionId: action.id, elementId: action.elementId });
|
|
215
215
|
actionIds.add(action.id);
|
|
216
216
|
if (action.activityId && !activityIds.has(action.activityId) && !String(action.id).startsWith('legacy-')) {
|
|
217
|
-
pushDiagnostic(diagnostics, { code: 'unknown-activity', level: 'error', message: '
|
|
217
|
+
pushDiagnostic(diagnostics, { code: 'unknown-activity', level: 'error', message: i18n.t('runtime.diagnostics.unknownActivity'), fieldPath: `${fieldPath}.activityId`, actionId: action.id, activityId: action.activityId, elementId: action.elementId });
|
|
218
218
|
}
|
|
219
219
|
const record = runtime.activities.find((item) => item.id && item.id === action.activityId);
|
|
220
220
|
if (record && ((action.elementId && record.elementId !== action.elementId) || (action.visitId && record.visitId && record.visitId !== action.visitId))) {
|
|
221
|
-
pushDiagnostic(diagnostics, { code: 'action-identity-mismatch', level: 'error', message: '
|
|
221
|
+
pushDiagnostic(diagnostics, { code: 'action-identity-mismatch', level: 'error', message: i18n.t('runtime.diagnostics.actionIdentityMismatch'), fieldPath, actionId: action.id, activityId: action.activityId, elementId: action.elementId, visitId: action.visitId });
|
|
222
222
|
}
|
|
223
223
|
const parsed = parseRuntimeInstant(action.occurredAt);
|
|
224
|
-
if (parsed.kind === 'invalid') pushDiagnostic(diagnostics, { code: 'invalid-time', level: 'warning', message: '
|
|
225
|
-
else if (parsed.kind === 'naive') pushDiagnostic(diagnostics, { code: 'naive-time', level: 'info', message: '
|
|
224
|
+
if (parsed.kind === 'invalid') pushDiagnostic(diagnostics, { code: 'invalid-time', level: 'warning', message: i18n.t('runtime.diagnostics.actionInvalidTime'), fieldPath: `${fieldPath}.occurredAt`, actionId: action.id });
|
|
225
|
+
else if (parsed.kind === 'naive') pushDiagnostic(diagnostics, { code: 'naive-time', level: 'info', message: i18n.t('runtime.diagnostics.actionNaiveTime'), fieldPath: `${fieldPath}.occurredAt`, actionId: action.id });
|
|
226
226
|
else if (parsed.kind === 'missing' && !String(action.id).startsWith('legacy-')) {
|
|
227
|
-
pushDiagnostic(diagnostics, { code: 'missing-time', level: 'warning', message: '
|
|
227
|
+
pushDiagnostic(diagnostics, { code: 'missing-time', level: 'warning', message: i18n.t('runtime.diagnostics.actionMissingTime'), fieldPath: `${fieldPath}.occurredAt`, actionId: action.id });
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
|
|
231
231
|
runtime.transitions.forEach((transition, index) => {
|
|
232
232
|
const fieldPath = `transitions[${index}]`;
|
|
233
233
|
const id = transition.id || `runtime-transition-${index + 1}`;
|
|
234
|
-
if (transitionIds.has(id)) pushDiagnostic(diagnostics, { code: 'duplicate-transition-id', level: 'error', message: '
|
|
234
|
+
if (transitionIds.has(id)) pushDiagnostic(diagnostics, { code: 'duplicate-transition-id', level: 'error', message: i18n.t('runtime.diagnostics.duplicateTransitionId'), fieldPath, transitionId: id });
|
|
235
235
|
transitionIds.add(id);
|
|
236
236
|
if (transition.sourceActivityId && !activityIds.has(transition.sourceActivityId)) {
|
|
237
|
-
pushDiagnostic(diagnostics, { code: 'unknown-activity', level: 'error', message: '
|
|
237
|
+
pushDiagnostic(diagnostics, { code: 'unknown-activity', level: 'error', message: i18n.t('runtime.diagnostics.transitionUnknownActivity'), fieldPath: `${fieldPath}.sourceActivityId`, transitionId: id, activityId: transition.sourceActivityId, elementId: transition.sourceElementId });
|
|
238
238
|
}
|
|
239
239
|
if (transition.actionId && !actionIds.has(transition.actionId) && !String(transition.actionId).startsWith('legacy-')) {
|
|
240
|
-
pushDiagnostic(diagnostics, { code: 'unknown-action', level: 'error', message: '
|
|
240
|
+
pushDiagnostic(diagnostics, { code: 'unknown-action', level: 'error', message: i18n.t('runtime.diagnostics.transitionUnknownAction'), fieldPath: `${fieldPath}.actionId`, transitionId: id, actionId: transition.actionId });
|
|
241
241
|
}
|
|
242
242
|
if (model && transition.sourceElementId && !nodeIds.has(transition.sourceElementId)) {
|
|
243
|
-
pushDiagnostic(diagnostics, { code: 'unknown-element', level: 'error', message: '
|
|
243
|
+
pushDiagnostic(diagnostics, { code: 'unknown-element', level: 'error', message: i18n.t('runtime.diagnostics.transitionUnknownSource'), fieldPath: `${fieldPath}.sourceElementId`, transitionId: id, elementId: transition.sourceElementId });
|
|
244
244
|
}
|
|
245
245
|
if (model && transition.targetElementId && !nodeIds.has(transition.targetElementId)) {
|
|
246
|
-
pushDiagnostic(diagnostics, { code: 'unknown-element', level: 'error', message: '
|
|
246
|
+
pushDiagnostic(diagnostics, { code: 'unknown-element', level: 'error', message: i18n.t('runtime.diagnostics.transitionUnknownTarget'), fieldPath: `${fieldPath}.targetElementId`, transitionId: id, elementId: transition.targetElementId });
|
|
247
247
|
}
|
|
248
248
|
const parsed = parseRuntimeInstant(transition.occurredAt || transition.time);
|
|
249
249
|
if ((transition.occurredAt || transition.time) && parsed.kind === 'invalid') {
|
|
250
|
-
pushDiagnostic(diagnostics, { code: 'invalid-time', level: 'warning', message: '
|
|
250
|
+
pushDiagnostic(diagnostics, { code: 'invalid-time', level: 'warning', message: i18n.t('runtime.diagnostics.transitionInvalidTime'), fieldPath: `${fieldPath}.occurredAt`, transitionId: id });
|
|
251
251
|
} else if (parsed.kind === 'naive') {
|
|
252
|
-
pushDiagnostic(diagnostics, { code: 'naive-time', level: 'info', message: '
|
|
252
|
+
pushDiagnostic(diagnostics, { code: 'naive-time', level: 'info', message: i18n.t('runtime.diagnostics.transitionNaiveTime'), fieldPath: `${fieldPath}.occurredAt`, transitionId: id });
|
|
253
253
|
}
|
|
254
254
|
});
|
|
255
255
|
|
|
256
256
|
runtime.edgeVisits.forEach((visit, index) => {
|
|
257
257
|
if (visit.id) {
|
|
258
|
-
if (edgeVisitIds.has(visit.id)) pushDiagnostic(diagnostics, { code: 'duplicate-edge-visit-id', level: 'error', message: '
|
|
258
|
+
if (edgeVisitIds.has(visit.id)) pushDiagnostic(diagnostics, { code: 'duplicate-edge-visit-id', level: 'error', message: i18n.t('runtime.diagnostics.duplicateEdgeVisitId'), fieldPath: `edgeVisits[${index}]`, edgeId: visit.edgeId });
|
|
259
259
|
edgeVisitIds.add(visit.id);
|
|
260
260
|
}
|
|
261
261
|
if (model && visit.edgeId && !edgeIds.has(visit.edgeId)) {
|
|
262
|
-
pushDiagnostic(diagnostics, { code: 'unknown-edge', level: 'error', message: '
|
|
262
|
+
pushDiagnostic(diagnostics, { code: 'unknown-edge', level: 'error', message: i18n.t('runtime.diagnostics.unknownEdge'), fieldPath: `edgeVisits[${index}].edgeId`, edgeId: visit.edgeId });
|
|
263
263
|
}
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
function resolveInvalidatedElements(transition, { activities, model, diagnostics }) {
|
|
267
|
+
function resolveInvalidatedElements(transition, { activities, model, diagnostics, i18n = DEFAULT_I18N }) {
|
|
268
268
|
const legacy = Array.isArray(transition.invalidatedActivityIds) ? transition.invalidatedActivityIds.map(String) : null;
|
|
269
269
|
const next = Array.isArray(transition.invalidatedElementIds) ? transition.invalidatedElementIds.map(String) : null;
|
|
270
270
|
const activityIds = new Set(activities.map((record) => record.id).filter(Boolean));
|
|
@@ -275,7 +275,7 @@ function resolveInvalidatedElements(transition, { activities, model, diagnostics
|
|
|
275
275
|
pushDiagnostic(diagnostics, {
|
|
276
276
|
code: 'invalidation-work-item-id',
|
|
277
277
|
level: 'warning',
|
|
278
|
-
message: '
|
|
278
|
+
message: i18n.t('runtime.diagnostics.invalidationWorkItemId'),
|
|
279
279
|
fieldPath: `transitions.${transition.id}.${field}`,
|
|
280
280
|
transitionId: transition.id,
|
|
281
281
|
activityId: id,
|
|
@@ -284,7 +284,7 @@ function resolveInvalidatedElements(transition, { activities, model, diagnostics
|
|
|
284
284
|
pushDiagnostic(diagnostics, {
|
|
285
285
|
code: 'unknown-element',
|
|
286
286
|
level: 'error',
|
|
287
|
-
message: '
|
|
287
|
+
message: i18n.t('runtime.diagnostics.invalidationUnknownElement'),
|
|
288
288
|
fieldPath: `transitions.${transition.id}.${field}`,
|
|
289
289
|
transitionId: transition.id,
|
|
290
290
|
elementId: id,
|
|
@@ -298,7 +298,7 @@ function resolveInvalidatedElements(transition, { activities, model, diagnostics
|
|
|
298
298
|
pushDiagnostic(diagnostics, {
|
|
299
299
|
code: 'invalidation-field-conflict',
|
|
300
300
|
level: 'warning',
|
|
301
|
-
message: '
|
|
301
|
+
message: i18n.t('runtime.diagnostics.invalidationFieldConflict'),
|
|
302
302
|
fieldPath: `transitions.${transition.id}.invalidatedElementIds`,
|
|
303
303
|
transitionId: transition.id,
|
|
304
304
|
});
|
|
@@ -311,12 +311,12 @@ function resolveInvalidatedElements(transition, { activities, model, diagnostics
|
|
|
311
311
|
return resolved;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
function inferInvalidatedPath(model, runtime, transition) {
|
|
314
|
+
function inferInvalidatedPath(model, runtime, transition, i18n = DEFAULT_I18N) {
|
|
315
315
|
const source = model?.nodes?.find((node) => node.id === transition.sourceElementId);
|
|
316
316
|
const target = model?.nodes?.find((node) => node.id === transition.targetElementId);
|
|
317
|
-
if (!source || !target) return { activityIds: [], edgeIds: [], issues: ['
|
|
317
|
+
if (!source || !target) return { activityIds: [], edgeIds: [], issues: [i18n.t('runtime.invalidationIssues.missingEndpoints')] };
|
|
318
318
|
const rootScope = model.id;
|
|
319
|
-
if ((source.scopeId || rootScope) !== (target.scopeId || rootScope)) return { activityIds: [], edgeIds: [], issues: ['
|
|
319
|
+
if ((source.scopeId || rootScope) !== (target.scopeId || rootScope)) return { activityIds: [], edgeIds: [], issues: [i18n.t('runtime.invalidationIssues.crossScope')] };
|
|
320
320
|
const visited = new Set(runtime.visitedEdges);
|
|
321
321
|
const edges = (model.edges || []).filter((edge) => visited.has(edge.id) && (edge.scopeId || rootScope) === (source.scopeId || rootScope));
|
|
322
322
|
const outgoing = new Map();
|
|
@@ -340,7 +340,7 @@ function inferInvalidatedPath(model, runtime, transition) {
|
|
|
340
340
|
if (paths.length !== 1) {
|
|
341
341
|
return {
|
|
342
342
|
activityIds: [], edgeIds: [],
|
|
343
|
-
issues: [paths.length ? '
|
|
343
|
+
issues: [paths.length ? i18n.t('runtime.invalidationIssues.multipleCandidatePaths') : i18n.t('runtime.invalidationIssues.pathNotFound')],
|
|
344
344
|
};
|
|
345
345
|
}
|
|
346
346
|
return { activityIds: paths[0].nodeIds.slice(1), edgeIds: paths[0].edgeIds, issues: [] };
|
|
@@ -410,7 +410,7 @@ export function normalizeRuntime(snapshot = {}, options = {}) {
|
|
|
410
410
|
transitions,
|
|
411
411
|
edgeVisits,
|
|
412
412
|
};
|
|
413
|
-
if (diagnostics) collectIdentityDiagnostics(normalized, { model: options.model, diagnostics });
|
|
413
|
+
if (diagnostics) collectIdentityDiagnostics(normalized, { model: options.model, diagnostics, i18n: resolveI18n(options) });
|
|
414
414
|
return normalized;
|
|
415
415
|
}
|
|
416
416
|
|
|
@@ -421,6 +421,7 @@ export function activityState(runtime, elementId, options = {}) {
|
|
|
421
421
|
elementId,
|
|
422
422
|
transitions: runtime.transitions || [],
|
|
423
423
|
diagnostics: options.diagnostics || null,
|
|
424
|
+
i18n: resolveI18n(options),
|
|
424
425
|
});
|
|
425
426
|
const effectiveVisits = visits.filter((visit) => visit.effective);
|
|
426
427
|
const latestRecords = (effectiveVisits.at(-1) || visits.at(-1))?.records || [];
|
|
@@ -440,15 +441,19 @@ export function inspectRuntime(snapshot, options = {}) {
|
|
|
440
441
|
runtime: snapshot,
|
|
441
442
|
appearance: options.appearance || null,
|
|
442
443
|
diagnostics,
|
|
444
|
+
i18n: resolveI18n(options),
|
|
443
445
|
});
|
|
444
446
|
return { runtime: presentation.runtime, diagnostics: presentation.diagnostics };
|
|
445
447
|
}
|
|
446
448
|
|
|
447
|
-
export function createRuntimePresentation({ model, runtime, appearance = null, diagnostics = null } = {}) {
|
|
449
|
+
export function createRuntimePresentation({ model, runtime, appearance = null, diagnostics = null, i18n = null, locale, messages } = {}) {
|
|
450
|
+
const translator = i18n || locale !== undefined || messages !== undefined
|
|
451
|
+
? resolveI18n({ i18n, locale, messages })
|
|
452
|
+
: resolveI18n(appearance?.i18n);
|
|
448
453
|
const collected = diagnostics || [];
|
|
449
|
-
const normalized = normalizeRuntime(runtime, { diagnostics: collected, model });
|
|
454
|
+
const normalized = normalizeRuntime(runtime, { diagnostics: collected, model, i18n: translator });
|
|
450
455
|
const nodes = new Map((model?.nodes || []).map((node) => [node.id, node]));
|
|
451
|
-
const activityStates = new Map((model?.nodes || []).map((node) => [node.id, activityState(normalized, node.id, { diagnostics: collected })]));
|
|
456
|
+
const activityStates = new Map((model?.nodes || []).map((node) => [node.id, activityState(normalized, node.id, { diagnostics: collected, i18n: translator })]));
|
|
452
457
|
const nodePresentations = new Map();
|
|
453
458
|
const actionPresentations = normalized.actions.map((action, index) => {
|
|
454
459
|
const assets = action.content.assets || [];
|
|
@@ -460,7 +465,7 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
460
465
|
const baseAction = {
|
|
461
466
|
...action,
|
|
462
467
|
explicitLabel: action.label || null,
|
|
463
|
-
label: approvalActionLabel(action),
|
|
468
|
+
label: approvalActionLabel(action, translator),
|
|
464
469
|
plainText: action.content.plainText || '',
|
|
465
470
|
images,
|
|
466
471
|
files,
|
|
@@ -483,7 +488,7 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
483
488
|
));
|
|
484
489
|
const transitionPresentations = rawTransitions.map((transition) => {
|
|
485
490
|
const targetName = nodes.get(transition.targetElementId)?.name || transition.targetElementId || '';
|
|
486
|
-
const
|
|
491
|
+
const transitionKey = transition.type === 'reject' ? 'reject' : transition.type === 'return' ? 'return' : transition.type === 'skip' ? 'skip' : 'forward';
|
|
487
492
|
const targetState = activityStates.get(transition.targetElementId);
|
|
488
493
|
const targetRecordsAfter = (targetState?.records || []).filter((record) => isAfter(recordOrder(record), transition.order));
|
|
489
494
|
const targetStatusAfter = resolveVisitStatus(groupVisits(targetRecordsAfter).at(-1)?.records || []);
|
|
@@ -493,19 +498,21 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
493
498
|
const hasExplicitInvalidation = Array.isArray(transition.invalidatedElementIds) || Array.isArray(transition.invalidatedActivityIds) || Array.isArray(transition.invalidatedEdgeIds);
|
|
494
499
|
const invalidation = hasExplicitInvalidation
|
|
495
500
|
? {
|
|
496
|
-
activityIds: resolveInvalidatedElements(transition, { activities: normalized.activities, model, diagnostics: collected }),
|
|
501
|
+
activityIds: resolveInvalidatedElements(transition, { activities: normalized.activities, model, diagnostics: collected, i18n: translator }),
|
|
497
502
|
edgeIds: [...(transition.invalidatedEdgeIds || [])],
|
|
498
503
|
issues: [],
|
|
499
504
|
}
|
|
500
505
|
: ABNORMAL_TRANSITION_TYPES.has(transition.type)
|
|
501
|
-
? inferInvalidatedPath(model, normalized, transition)
|
|
506
|
+
? inferInvalidatedPath(model, normalized, transition, translator)
|
|
502
507
|
: { activityIds: [], edgeIds: [], issues: [] };
|
|
503
508
|
return {
|
|
504
509
|
...transition,
|
|
505
510
|
action: actionMap.get(transition.actionId) || null,
|
|
506
511
|
sourceName: nodes.get(transition.sourceElementId)?.name || transition.sourceElementId || '',
|
|
507
512
|
targetName,
|
|
508
|
-
label: targetName
|
|
513
|
+
label: targetName
|
|
514
|
+
? translator.t(`runtime.transitions.${transitionKey}To`, { target: targetName })
|
|
515
|
+
: translator.t(`runtime.transitions.${transitionKey}Prefix`),
|
|
509
516
|
state,
|
|
510
517
|
visible: ABNORMAL_TRANSITION_TYPES.has(transition.type) && state === 'active',
|
|
511
518
|
resolvedAt: transition.resolvedAt || (state === 'resolved' ? targetRecordsAfter.map((record) => record.endTime).filter(Boolean).at(-1) : undefined),
|
|
@@ -536,7 +543,7 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
536
543
|
pushDiagnostic(collected, {
|
|
537
544
|
code: 'element-invalidation-with-concurrent-visits',
|
|
538
545
|
level: 'warning',
|
|
539
|
-
message: '
|
|
546
|
+
message: translator.t('runtime.diagnostics.elementInvalidationConcurrentVisits'),
|
|
540
547
|
fieldPath: `transitions.${transition.id}.invalidatedElementIds`,
|
|
541
548
|
transitionId: transition.id,
|
|
542
549
|
elementId,
|
|
@@ -556,12 +563,13 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
556
563
|
for (const edgeId of transition.invalidatedEdgeIds) if (!hasEdgeVisitAfter(edgeId, transition)) invalidatedEdges.set(edgeId, transition);
|
|
557
564
|
}
|
|
558
565
|
|
|
566
|
+
const listSeparator = translator.t('common.listSeparator');
|
|
559
567
|
for (const node of model?.nodes || []) {
|
|
560
568
|
const state = activityStates.get(node.id);
|
|
561
569
|
const actions = actionPresentations.filter((action) => action.elementId === node.id);
|
|
562
570
|
const visits = state.visits.map((visit) => {
|
|
563
571
|
const visitActions = actions.filter((action) => action.visitId === visit.id);
|
|
564
|
-
return { ...visit, actions: visitActions, ...summarizeApprovalActions(visitActions) };
|
|
572
|
+
return { ...visit, actions: visitActions, ...summarizeApprovalActions(visitActions, translator) };
|
|
565
573
|
});
|
|
566
574
|
const effectiveVisits = visits.filter((visit) => visit.effective);
|
|
567
575
|
const latestVisit = effectiveVisits.at(-1) || visits.at(-1) || null;
|
|
@@ -586,35 +594,51 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
586
594
|
const superseded = invalidatedNodes.has(node.id);
|
|
587
595
|
const pathStatus = superseded || status === 'rejected' ? 'idle' : status;
|
|
588
596
|
|
|
589
|
-
let statusLabel = baseStatusLabel(status);
|
|
597
|
+
let statusLabel = baseStatusLabel(status, translator);
|
|
590
598
|
const activeVisitCount = effectiveVisits.filter((visit) => resolveVisitStatus(visit.records) === 'active').length;
|
|
591
599
|
if (effectiveVisits.length > 1 && activeVisitCount) {
|
|
592
600
|
statusLabel = activeVisitCount === effectiveVisits.length
|
|
593
|
-
?
|
|
594
|
-
:
|
|
595
|
-
} else if (isReentry && status === 'active') statusLabel = '
|
|
601
|
+
? translator.t('runtime.status.activeVisits', { active: activeVisitCount })
|
|
602
|
+
: translator.t('runtime.status.activeVisitsOfTotal', { active: activeVisitCount, total: effectiveVisits.length });
|
|
603
|
+
} else if (isReentry && status === 'active') statusLabel = translator.t('runtime.status.reentry');
|
|
596
604
|
else if (status === 'active' || status === 'completed') {
|
|
597
|
-
if (approvalMode === 'all')
|
|
598
|
-
|
|
599
|
-
|
|
605
|
+
if (approvalMode === 'all') {
|
|
606
|
+
statusLabel = translator.t(
|
|
607
|
+
multiInstanceMode === 'sequential' ? 'runtime.status.sequentialCountersign' : 'runtime.status.countersign',
|
|
608
|
+
{ completed, total: total || required },
|
|
609
|
+
);
|
|
610
|
+
} else if (approvalMode === 'any') statusLabel = translator.t('runtime.status.orSign', { completed, total: total || required });
|
|
611
|
+
else if (participants.length > 1 && effectiveVisits.length <= 1) statusLabel = translator.t('runtime.status.multiApproval', { completed, total });
|
|
600
612
|
}
|
|
601
613
|
|
|
602
|
-
let summary = participantSummary(participants);
|
|
614
|
+
let summary = participantSummary(participants, translator);
|
|
603
615
|
const isApprovalTask = ['userTask', 'callActivity'].includes(node.type);
|
|
604
616
|
const isAutomatedTask = ['serviceTask', 'scriptTask', 'businessRuleTask', 'sendTask', 'receiveTask'].includes(node.type);
|
|
605
617
|
if (!summary && isApprovalTask) {
|
|
606
|
-
if (status === 'active') summary = candidateSummary(node) || '
|
|
607
|
-
else if (status === 'skipped') summary = '
|
|
608
|
-
else if (!state.records.length)
|
|
618
|
+
if (status === 'active') summary = candidateSummary(node, translator) || translator.t('runtime.summary.pendingAssignee');
|
|
619
|
+
else if (status === 'skipped') summary = translator.t('runtime.summary.branchSkipped');
|
|
620
|
+
else if (!state.records.length) {
|
|
621
|
+
summary = TERMINAL_PROCESS_STATUSES.has(normalized.status)
|
|
622
|
+
? translator.t('runtime.summary.notVisited')
|
|
623
|
+
: translator.t('runtime.summary.notReachedYet');
|
|
624
|
+
}
|
|
609
625
|
} else if (!summary && isAutomatedTask) {
|
|
610
|
-
summary = status === 'active'
|
|
626
|
+
summary = status === 'active'
|
|
627
|
+
? translator.t('runtime.summary.automatedActive')
|
|
628
|
+
: status === 'completed'
|
|
629
|
+
? translator.t('runtime.summary.automatedCompleted')
|
|
630
|
+
: status === 'failed'
|
|
631
|
+
? translator.t('runtime.summary.automatedFailed')
|
|
632
|
+
: status === 'skipped'
|
|
633
|
+
? translator.t('runtime.summary.branchSkipped')
|
|
634
|
+
: translator.t('runtime.summary.automatedWaiting');
|
|
611
635
|
}
|
|
612
636
|
|
|
613
637
|
const relatedTransitions = transitionPresentations.filter((item) => item.sourceElementId === node.id || item.targetElementId === node.id);
|
|
614
|
-
const currentSummary = summarizeApprovalActions(currentActions);
|
|
615
|
-
const historySummary = summarizeApprovalActions(actions);
|
|
638
|
+
const currentSummary = summarizeApprovalActions(currentActions, translator);
|
|
639
|
+
const historySummary = summarizeApprovalActions(actions, translator);
|
|
616
640
|
nodePresentations.set(node.id, {
|
|
617
|
-
elementId: node.id, status, pathStatus, superseded, statusLabel, summary, fullSummary: participants.map((item) => item.name).join(
|
|
641
|
+
elementId: node.id, status, pathStatus, superseded, statusLabel, summary, fullSummary: participants.map((item) => item.name).join(listSeparator) || summary,
|
|
618
642
|
participants, approvalMode, multiInstanceMode, completed, total, required, round: latestVisit?.round || 0,
|
|
619
643
|
records: state.records, latestRecords, visits, effectiveVisits, transitions: relatedTransitions, actions,
|
|
620
644
|
...currentSummary,
|
|
@@ -626,7 +650,7 @@ export function createRuntimePresentation({ model, runtime, appearance = null, d
|
|
|
626
650
|
|
|
627
651
|
const frozenDiagnostics = Object.freeze(collected.slice());
|
|
628
652
|
const emptyNode = (elementId) => ({
|
|
629
|
-
elementId, status: 'idle', pathStatus: 'idle', superseded: false, statusLabel: '
|
|
653
|
+
elementId, status: 'idle', pathStatus: 'idle', superseded: false, statusLabel: translator.t('runtime.status.idle'), summary: '', fullSummary: '', participants: [], approvalMode: null,
|
|
630
654
|
multiInstanceMode: null, completed: 0, total: 0, required: 0, round: 0, records: [], latestRecords: [], visits: [], effectiveVisits: [], transitions: [], actions: [], latestAction: null,
|
|
631
655
|
latestNonEmptyComment: null, actionText: '', actionSummary: '', imageCount: 0, fileCount: 0, assetCount: 0, isReentry: false, hasDetails: false,
|
|
632
656
|
});
|
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
const OFFSET_PATTERN = /(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
2
|
+
const MAX_FORMATTER_CACHE_SIZE = 64;
|
|
3
|
+
const intlFormatterCache = new Map();
|
|
4
|
+
const warnedFormatErrors = new Set();
|
|
5
|
+
|
|
6
|
+
function warnTimeFormatOnce(key, message) {
|
|
7
|
+
if (warnedFormatErrors.has(key)) return;
|
|
8
|
+
warnedFormatErrors.add(key);
|
|
9
|
+
console.warn(message);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function defaultFormatRuntimeInstant(parsed) {
|
|
13
|
+
if (!parsed?.raw) return '';
|
|
14
|
+
return String(parsed.raw).trim().replace('T', ' ');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getCachedIntlFormatter(locale, config) {
|
|
18
|
+
const targetLocale = config.locale || locale || undefined;
|
|
19
|
+
const hasExplicitStyle = Boolean(config.dateStyle || config.timeStyle);
|
|
20
|
+
const intlOptions = {};
|
|
21
|
+
if (config.timeZone) intlOptions.timeZone = config.timeZone;
|
|
22
|
+
if (hasExplicitStyle) {
|
|
23
|
+
if (config.dateStyle) intlOptions.dateStyle = config.dateStyle;
|
|
24
|
+
if (config.timeStyle) intlOptions.timeStyle = config.timeStyle;
|
|
25
|
+
if (typeof config.hour12 === 'boolean') intlOptions.hour12 = config.hour12;
|
|
26
|
+
} else {
|
|
27
|
+
intlOptions.year = 'numeric';
|
|
28
|
+
intlOptions.month = '2-digit';
|
|
29
|
+
intlOptions.day = '2-digit';
|
|
30
|
+
intlOptions.hour = '2-digit';
|
|
31
|
+
intlOptions.minute = '2-digit';
|
|
32
|
+
if (config.hour12 === true) intlOptions.hour12 = true;
|
|
33
|
+
else intlOptions.hourCycle = 'h23';
|
|
34
|
+
}
|
|
35
|
+
const cacheKey = JSON.stringify([targetLocale || '', intlOptions]);
|
|
36
|
+
let formatter = intlFormatterCache.get(cacheKey);
|
|
37
|
+
if (!formatter) {
|
|
38
|
+
formatter = new Intl.DateTimeFormat(targetLocale, intlOptions);
|
|
39
|
+
if (intlFormatterCache.size >= MAX_FORMATTER_CACHE_SIZE) {
|
|
40
|
+
const oldestKey = intlFormatterCache.keys().next().value;
|
|
41
|
+
if (oldestKey !== undefined) intlFormatterCache.delete(oldestKey);
|
|
42
|
+
}
|
|
43
|
+
intlFormatterCache.set(cacheKey, formatter);
|
|
44
|
+
}
|
|
45
|
+
return formatter;
|
|
46
|
+
}
|
|
2
47
|
|
|
3
48
|
export function parseRuntimeInstant(value) {
|
|
4
49
|
if (value == null || value === '') return { instant: null, raw: '', kind: 'missing' };
|
|
@@ -13,10 +58,50 @@ export function parseRuntimeInstant(value) {
|
|
|
13
58
|
return { instant, raw, kind: 'naive' };
|
|
14
59
|
}
|
|
15
60
|
|
|
16
|
-
export function formatRuntimeInstant(value) {
|
|
17
|
-
const parsed = value && typeof value === 'object' && 'raw' in value
|
|
18
|
-
|
|
19
|
-
|
|
61
|
+
export function formatRuntimeInstant(value, options = null) {
|
|
62
|
+
const parsed = value && typeof value === 'object' && 'raw' in value
|
|
63
|
+
? ('kind' in value && 'instant' in value ? value : parseRuntimeInstant(value.raw))
|
|
64
|
+
: parseRuntimeInstant(value);
|
|
65
|
+
if (!parsed || parsed.kind === 'missing' || !parsed.raw) return '';
|
|
66
|
+
if (!options || typeof options !== 'object') return defaultFormatRuntimeInstant(parsed);
|
|
67
|
+
|
|
68
|
+
const locale = options.locale || 'zh-CN';
|
|
69
|
+
if (typeof options.formatRuntimeTime === 'function') {
|
|
70
|
+
const instantArg = { instant: parsed.instant, raw: parsed.raw, kind: parsed.kind };
|
|
71
|
+
const context = {
|
|
72
|
+
surface: options.surface || 'details',
|
|
73
|
+
field: options.field || 'occurred',
|
|
74
|
+
locale,
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
const formatted = options.formatRuntimeTime(instantArg, context);
|
|
78
|
+
if (typeof formatted === 'string') return formatted;
|
|
79
|
+
if (formatted == null) return defaultFormatRuntimeInstant(parsed);
|
|
80
|
+
return String(formatted);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
warnTimeFormatOnce(
|
|
83
|
+
'custom-formatter',
|
|
84
|
+
`[BPMN Nova runtime] formatRuntimeTime threw an error; falling back to default formatting. ${error?.message || ''}`,
|
|
85
|
+
);
|
|
86
|
+
return defaultFormatRuntimeInstant(parsed);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const formatConfig = options.runtimeTimeFormat;
|
|
91
|
+
if (formatConfig && typeof formatConfig === 'object' && parsed.instant != null) {
|
|
92
|
+
try {
|
|
93
|
+
const formatter = getCachedIntlFormatter(locale, formatConfig);
|
|
94
|
+
return formatter.format(new Date(parsed.instant));
|
|
95
|
+
} catch (error) {
|
|
96
|
+
warnTimeFormatOnce(
|
|
97
|
+
`intl:${formatConfig.locale || locale || ''}:${formatConfig.timeZone || ''}:${formatConfig.dateStyle || ''}:${formatConfig.timeStyle || ''}`,
|
|
98
|
+
`[BPMN Nova runtime] runtimeTimeFormat failed; falling back to default formatting. ${error?.message || ''}`,
|
|
99
|
+
);
|
|
100
|
+
return defaultFormatRuntimeInstant(parsed);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return defaultFormatRuntimeInstant(parsed);
|
|
20
105
|
}
|
|
21
106
|
|
|
22
107
|
export function compareRuntimeOrder(left, right) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveI18n } from '../i18n/index.js';
|
|
1
2
|
import { parseRuntimeInstant, compareRuntimeOrder, runtimeInstant } from './time.js';
|
|
2
3
|
import { pushDiagnostic } from './diagnostics.js';
|
|
3
4
|
|
|
@@ -45,7 +46,8 @@ export function groupVisits(records = []) {
|
|
|
45
46
|
.map((visit, index) => ({ id: visit.id, records: visit.records, round: index + 1, index: visit.index }));
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export function markEffectiveVisits(visits = [], { elementId, transitions = [], diagnostics = null } = {}) {
|
|
49
|
+
export function markEffectiveVisits(visits = [], { elementId, transitions = [], diagnostics = null, i18n = null, locale, messages } = {}) {
|
|
50
|
+
const translator = resolveI18n({ i18n, locale, messages });
|
|
49
51
|
if (visits.length <= 1) {
|
|
50
52
|
return visits.map((visit) => ({ ...visit, effective: true, superseded: false }));
|
|
51
53
|
}
|
|
@@ -61,7 +63,7 @@ export function markEffectiveVisits(visits = [], { elementId, transitions = [],
|
|
|
61
63
|
pushDiagnostic(diagnostics, {
|
|
62
64
|
code: 'unknown-superseded-visit',
|
|
63
65
|
level: 'warning',
|
|
64
|
-
message: '
|
|
66
|
+
message: translator.t('runtime.diagnostics.unknownSupersededVisit'),
|
|
65
67
|
fieldPath: `activities.supersedesVisitId`,
|
|
66
68
|
elementId,
|
|
67
69
|
activityId: record.id,
|
|
@@ -85,7 +87,7 @@ export function markEffectiveVisits(visits = [], { elementId, transitions = [],
|
|
|
85
87
|
pushDiagnostic(diagnostics, {
|
|
86
88
|
code: 'concurrent-visits',
|
|
87
89
|
level: 'info',
|
|
88
|
-
message: '
|
|
90
|
+
message: translator.t('runtime.diagnostics.concurrentVisits'),
|
|
89
91
|
fieldPath: 'activities.visitId',
|
|
90
92
|
elementId,
|
|
91
93
|
visitId: earlier.visit.id,
|
|
@@ -104,7 +106,7 @@ export function markEffectiveVisits(visits = [], { elementId, transitions = [],
|
|
|
104
106
|
pushDiagnostic(diagnostics, {
|
|
105
107
|
code: 'ambiguous-visit-order',
|
|
106
108
|
level: 'warning',
|
|
107
|
-
message: '
|
|
109
|
+
message: translator.t('runtime.diagnostics.ambiguousVisitOrder'),
|
|
108
110
|
fieldPath: 'activities.startTime',
|
|
109
111
|
elementId,
|
|
110
112
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { I18nController, NovaI18nOptions } from '../i18n/index.js'
|
|
2
|
+
|
|
1
3
|
export type NovaThemeMode = 'light' | 'dark' | 'auto'
|
|
2
4
|
export type NovaResolvedTheme = 'light' | 'dark'
|
|
3
5
|
|
|
@@ -47,7 +49,7 @@ export interface RuntimeActionAppearance {
|
|
|
47
49
|
tone?: string
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
export interface RuntimeAppearanceOptions {
|
|
52
|
+
export interface RuntimeAppearanceOptions extends NovaI18nOptions {
|
|
51
53
|
statuses?: Record<string, string>
|
|
52
54
|
actions?: Record<string, RuntimeActionAppearance>
|
|
53
55
|
transitions?: Record<string, { tone?: string }>
|
|
@@ -64,6 +66,7 @@ export interface RuntimeAppearanceTransitionInput {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
export interface RuntimeAppearanceResolver {
|
|
69
|
+
readonly i18n?: I18nController
|
|
67
70
|
resolveStatus(status: string): string
|
|
68
71
|
resolveAction(action?: RuntimeAppearanceActionInput): Required<RuntimeActionAppearance>
|
|
69
72
|
resolveTransition(transition?: RuntimeAppearanceTransitionInput): { tone: string }
|
|
@@ -84,7 +87,7 @@ export class ThemeController {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
export function createThemeController(options: ConstructorParameters<typeof ThemeController>[0]): ThemeController
|
|
87
|
-
export function createRuntimeAppearance(options?: RuntimeAppearanceOptions): RuntimeAppearanceResolver
|
|
90
|
+
export function createRuntimeAppearance(options?: RuntimeAppearanceOptions, extra?: NovaI18nOptions | null): RuntimeAppearanceResolver
|
|
88
91
|
export function applyRuntimeTone(element: HTMLElement | SVGElement, tone?: string | null): string
|
|
89
92
|
|
|
90
93
|
export const NOVA_THEME_MODES: readonly NovaThemeMode[]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveI18n } from '../i18n/index.js';
|
|
2
|
+
|
|
1
3
|
const THEME_MODES = new Set(['light', 'dark', 'auto']);
|
|
2
4
|
const TONE_NAME = /^[a-z][a-z0-9-]{0,47}$/;
|
|
3
5
|
|
|
@@ -323,17 +325,19 @@ export class ThemeController {
|
|
|
323
325
|
|
|
324
326
|
export function createThemeController(options) { return new ThemeController(options); }
|
|
325
327
|
|
|
326
|
-
export function createRuntimeAppearance(options = {}) {
|
|
328
|
+
export function createRuntimeAppearance(options = {}, extra = null) {
|
|
329
|
+
const i18n = resolveI18n(extra || options);
|
|
327
330
|
const statuses = { ...DEFAULT_STATUSES, ...(options.statuses || {}) };
|
|
328
|
-
const
|
|
331
|
+
const customActions = options.actions || {};
|
|
329
332
|
const transitions = { ...DEFAULT_TRANSITIONS, ...(options.transitions || {}) };
|
|
330
333
|
return Object.freeze({
|
|
334
|
+
i18n,
|
|
331
335
|
resolveStatus(status) { return normalizeTone(statuses[status], DEFAULT_STATUSES[status] || 'neutral'); },
|
|
332
336
|
resolveAction(action = {}) {
|
|
333
|
-
const configured =
|
|
337
|
+
const configured = customActions[action.type] || {};
|
|
334
338
|
const fallback = DEFAULT_ACTIONS[action.type] || {};
|
|
335
339
|
return Object.freeze({
|
|
336
|
-
label: action.explicitLabel || configured.label || action.label ||
|
|
340
|
+
label: action.explicitLabel || configured.label || action.label || i18n.actionLabel(action.type, fallback.label),
|
|
337
341
|
iconId: configured.iconId || fallback.iconId || 'ui.edit',
|
|
338
342
|
tone: normalizeTone(configured.tone || fallback.tone, 'neutral'),
|
|
339
343
|
});
|