@bpmn-nova/studio 0.3.8-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 +42 -0
- package/dist/context-menu.js +41 -32
- package/dist/controller.js +45 -19
- package/dist/index.d.ts +59 -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 +279 -75
- package/dist/sidebars.js +3 -1
- package/dist/styles.css +6 -3
- package/llms-full.txt +296 -49
- package/llms.txt +4 -4
- package/package.json +2 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { zhCN } from './locales/zh-CN.js';
|
|
2
|
+
import { enUS } from './locales/en-US.js';
|
|
3
|
+
|
|
4
|
+
export { zhCN } from './locales/zh-CN.js';
|
|
5
|
+
export { enUS } from './locales/en-US.js';
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_LOCALE = 'zh-CN';
|
|
8
|
+
|
|
9
|
+
export const BUILTIN_LOCALES = Object.freeze({
|
|
10
|
+
'zh-CN': zhCN,
|
|
11
|
+
'en-US': enUS,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const warnedKeys = new Set();
|
|
15
|
+
|
|
16
|
+
function isDevEnvironment() {
|
|
17
|
+
try {
|
|
18
|
+
if (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'production') return false;
|
|
19
|
+
} catch {
|
|
20
|
+
// Ignore restricted process globals.
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
if (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.PROD === true) return false;
|
|
24
|
+
} catch {
|
|
25
|
+
// Ignore missing import.meta.env.
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function warnOnce(key, message) {
|
|
31
|
+
if (!isDevEnvironment()) return;
|
|
32
|
+
if (warnedKeys.has(key)) return;
|
|
33
|
+
warnedKeys.add(key);
|
|
34
|
+
console.warn(message);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isPlainObject(value) {
|
|
38
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function lookupPath(source, segments) {
|
|
42
|
+
let current = source;
|
|
43
|
+
for (const segment of segments) {
|
|
44
|
+
if (!current || typeof current !== 'object') return undefined;
|
|
45
|
+
if (!Object.prototype.hasOwnProperty.call(current, segment)) return undefined;
|
|
46
|
+
current = current[segment];
|
|
47
|
+
}
|
|
48
|
+
return current;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function deepMergeMessages(base, overrides) {
|
|
52
|
+
if (!isPlainObject(overrides)) return base;
|
|
53
|
+
const output = isPlainObject(base) ? { ...base } : {};
|
|
54
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
55
|
+
if (value === undefined) continue;
|
|
56
|
+
if (isPlainObject(value) && isPlainObject(output[key])) {
|
|
57
|
+
output[key] = deepMergeMessages(output[key], value);
|
|
58
|
+
} else {
|
|
59
|
+
output[key] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function normalizeLocaleTag(locale) {
|
|
66
|
+
if (typeof locale !== 'string') return DEFAULT_LOCALE;
|
|
67
|
+
const cleaned = locale.trim().replace(/_/g, '-');
|
|
68
|
+
if (!cleaned) return DEFAULT_LOCALE;
|
|
69
|
+
const lower = cleaned.toLowerCase();
|
|
70
|
+
if (lower === 'zh-cn' || lower === 'zh' || lower === 'zh-hans' || lower === 'zh-hans-cn') return 'zh-CN';
|
|
71
|
+
if (lower === 'en-us') return 'en-US';
|
|
72
|
+
return cleaned;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function resolveBuiltinLocale(locale) {
|
|
76
|
+
const normalized = normalizeLocaleTag(locale);
|
|
77
|
+
if (Object.prototype.hasOwnProperty.call(BUILTIN_LOCALES, normalized)) return normalized;
|
|
78
|
+
const lower = normalized.toLowerCase();
|
|
79
|
+
if (lower === 'en' || lower.startsWith('en-')) return 'en-US';
|
|
80
|
+
if (lower === 'zh' || lower.startsWith('zh-')) return 'zh-CN';
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getLocaleMessages(locale) {
|
|
85
|
+
const builtin = resolveBuiltinLocale(locale);
|
|
86
|
+
return builtin ? BUILTIN_LOCALES[builtin] : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function formatMessage(entry, params = {}) {
|
|
90
|
+
if (typeof entry === 'function') return String(entry(params || {}));
|
|
91
|
+
if (typeof entry !== 'string') return '';
|
|
92
|
+
if (!params || typeof params !== 'object') return entry;
|
|
93
|
+
return entry.replace(/\{([A-Za-z0-9_]+)\}/g, (match, name) => (
|
|
94
|
+
Object.prototype.hasOwnProperty.call(params, name) && params[name] !== undefined && params[name] !== null
|
|
95
|
+
? String(params[name])
|
|
96
|
+
: match
|
|
97
|
+
));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class I18nController {
|
|
101
|
+
constructor({ locale = DEFAULT_LOCALE, messages = null } = {}) {
|
|
102
|
+
this._locale = normalizeLocaleTag(locale);
|
|
103
|
+
this._resolvedLocale = resolveBuiltinLocale(this._locale) || DEFAULT_LOCALE;
|
|
104
|
+
this._overrides = isPlainObject(messages) ? messages : null;
|
|
105
|
+
this._listeners = new Set();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get locale() { return this._locale; }
|
|
109
|
+
get resolvedLocale() { return this._resolvedLocale; }
|
|
110
|
+
get messages() {
|
|
111
|
+
const base = getLocaleMessages(this._locale) || zhCN;
|
|
112
|
+
return this._overrides ? deepMergeMessages(base, this._overrides) : base;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getState() {
|
|
116
|
+
return Object.freeze({
|
|
117
|
+
locale: this._locale,
|
|
118
|
+
resolvedLocale: this._resolvedLocale,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
hasOverride(key) {
|
|
123
|
+
if (!this._overrides || !key) return false;
|
|
124
|
+
const value = lookupPath(this._overrides, String(key).split('.'));
|
|
125
|
+
return value !== undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
isDefaultZh() {
|
|
129
|
+
return this._locale === 'zh-CN' && !this._overrides;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
setLocale(locale, messages) {
|
|
133
|
+
let changed = false;
|
|
134
|
+
if (locale !== undefined) {
|
|
135
|
+
const nextLocale = locale === null ? DEFAULT_LOCALE : normalizeLocaleTag(locale);
|
|
136
|
+
const nextResolved = resolveBuiltinLocale(nextLocale) || DEFAULT_LOCALE;
|
|
137
|
+
if (nextLocale !== this._locale || nextResolved !== this._resolvedLocale) {
|
|
138
|
+
this._locale = nextLocale;
|
|
139
|
+
this._resolvedLocale = nextResolved;
|
|
140
|
+
changed = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (messages !== undefined) {
|
|
144
|
+
const nextOverrides = isPlainObject(messages) ? messages : null;
|
|
145
|
+
if (nextOverrides !== this._overrides) {
|
|
146
|
+
this._overrides = nextOverrides;
|
|
147
|
+
changed = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const state = this.getState();
|
|
151
|
+
if (changed) {
|
|
152
|
+
for (const listener of [...this._listeners]) {
|
|
153
|
+
try {
|
|
154
|
+
listener(state);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error('BPMN Nova i18n listener failed.', error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return state;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
subscribe(listener) {
|
|
164
|
+
if (typeof listener !== 'function') return () => {};
|
|
165
|
+
this._listeners.add(listener);
|
|
166
|
+
return () => this._listeners.delete(listener);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
t(key, params) {
|
|
170
|
+
const segments = String(key || '').split('.');
|
|
171
|
+
if (this._overrides) {
|
|
172
|
+
const override = lookupPath(this._overrides, segments);
|
|
173
|
+
if (override !== undefined) {
|
|
174
|
+
try {
|
|
175
|
+
return formatMessage(override, params);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
warnOnce(`override-error:${this._locale}:${key}`, `[BPMN Nova i18n] Message formatter for "${key}" failed; falling back to zh-CN. ${error?.message || ''}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const basePack = getLocaleMessages(this._locale);
|
|
182
|
+
if (basePack) {
|
|
183
|
+
const value = lookupPath(basePack, segments);
|
|
184
|
+
if (value !== undefined) {
|
|
185
|
+
try {
|
|
186
|
+
return formatMessage(value, params);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
warnOnce(`pack-error:${this._locale}:${key}`, `[BPMN Nova i18n] Message formatter for "${key}" in "${this._locale}" failed; falling back to zh-CN. ${error?.message || ''}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const fallback = lookupPath(zhCN, segments);
|
|
193
|
+
if (fallback !== undefined) {
|
|
194
|
+
if (this._locale !== DEFAULT_LOCALE) {
|
|
195
|
+
warnOnce(`missing:${this._locale}:${key}`, `[BPMN Nova i18n] Missing translation key "${key}" for locale "${this._locale}"; falling back to ${DEFAULT_LOCALE}.`);
|
|
196
|
+
}
|
|
197
|
+
return formatMessage(fallback, params);
|
|
198
|
+
}
|
|
199
|
+
warnOnce(`unknown:${this._locale}:${key}`, `[BPMN Nova i18n] Unknown translation key "${key}".`);
|
|
200
|
+
return String(key || '');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
elementTypeLabel(nodeType, fallback = '') {
|
|
204
|
+
if (!nodeType) return fallback || this.t('elementTypes.generic');
|
|
205
|
+
const key = `elementTypes.${nodeType}`;
|
|
206
|
+
if (this.hasOverride(key) || lookupPath(zhCN, ['elementTypes', nodeType]) !== undefined) {
|
|
207
|
+
return this.t(key);
|
|
208
|
+
}
|
|
209
|
+
return fallback || String(nodeType);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
edgeTypeLabel(edgeType, fallback = '') {
|
|
213
|
+
const type = edgeType || 'sequenceFlow';
|
|
214
|
+
const key = `edgeTypes.${type}`;
|
|
215
|
+
if (this.hasOverride(key) || lookupPath(zhCN, ['edgeTypes', type]) !== undefined) {
|
|
216
|
+
return this.t(key);
|
|
217
|
+
}
|
|
218
|
+
return fallback || String(type);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
actionLabel(actionType, fallback = '') {
|
|
222
|
+
if (actionType) {
|
|
223
|
+
const key = `actions.${actionType}`;
|
|
224
|
+
if (this.hasOverride(key) || lookupPath(zhCN, ['actions', actionType]) !== undefined) {
|
|
225
|
+
return this.t(key);
|
|
226
|
+
}
|
|
227
|
+
return fallback || String(actionType);
|
|
228
|
+
}
|
|
229
|
+
return fallback || this.t('actions.default');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export const DEFAULT_I18N = Object.freeze(new I18nController({ locale: DEFAULT_LOCALE }));
|
|
234
|
+
|
|
235
|
+
export function createI18n(options = {}) {
|
|
236
|
+
return new I18nController(options);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function resolveI18n(input) {
|
|
240
|
+
if (!input) return DEFAULT_I18N;
|
|
241
|
+
if (input instanceof I18nController) return input;
|
|
242
|
+
if (input.i18n instanceof I18nController) return input.i18n;
|
|
243
|
+
if (input.locale !== undefined || input.messages !== undefined) {
|
|
244
|
+
return new I18nController({ locale: input.locale, messages: input.messages });
|
|
245
|
+
}
|
|
246
|
+
return DEFAULT_I18N;
|
|
247
|
+
}
|