@endora-commerce/mod-cms 0.106.0 → 0.108.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 +1 -0
- package/dist/admin/api/cms-client.d.ts +6 -2
- package/dist/admin/api/cms-client.d.ts.map +1 -1
- package/dist/admin/api/cms-client.js +10 -0
- package/dist/admin/api/cms-client.js.map +1 -1
- package/dist/admin/components/PageBuilderEditor.d.ts +15 -1
- package/dist/admin/components/PageBuilderEditor.d.ts.map +1 -1
- package/dist/admin/components/PageBuilderEditor.js +79 -5
- package/dist/admin/components/PageBuilderEditor.js.map +1 -1
- package/dist/admin/components/PageBuilderTranslateAction.d.ts +83 -0
- package/dist/admin/components/PageBuilderTranslateAction.d.ts.map +1 -0
- package/dist/admin/components/PageBuilderTranslateAction.js +229 -0
- package/dist/admin/components/PageBuilderTranslateAction.js.map +1 -0
- package/dist/admin/components/TranslationNotice.d.ts +27 -0
- package/dist/admin/components/TranslationNotice.d.ts.map +1 -0
- package/dist/admin/components/TranslationNotice.js +23 -0
- package/dist/admin/components/TranslationNotice.js.map +1 -0
- package/dist/admin/editors/BlockEditor.d.ts.map +1 -1
- package/dist/admin/editors/BlockEditor.js +4 -1
- package/dist/admin/editors/BlockEditor.js.map +1 -1
- package/dist/admin/editors/PageEditor.d.ts.map +1 -1
- package/dist/admin/editors/PageEditor.js +4 -1
- package/dist/admin/editors/PageEditor.js.map +1 -1
- package/dist/admin/editors/TemplateEditor.d.ts.map +1 -1
- package/dist/admin/editors/TemplateEditor.js +4 -1
- package/dist/admin/editors/TemplateEditor.js.map +1 -1
- package/dist/admin/zones/CategoryContentEditor.d.ts.map +1 -1
- package/dist/admin/zones/CategoryContentEditor.js +5 -1
- package/dist/admin/zones/CategoryContentEditor.js.map +1 -1
- package/dist/backend/commands/translate-page-builder-content.command.d.ts +35 -0
- package/dist/backend/commands/translate-page-builder-content.command.d.ts.map +1 -0
- package/dist/backend/commands/translate-page-builder-content.command.js +32 -0
- package/dist/backend/commands/translate-page-builder-content.command.js.map +1 -0
- package/dist/backend/index.d.ts +8 -0
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +40 -0
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/plugin.d.ts +11 -0
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/plugin.js +11 -0
- package/dist/backend/plugin.js.map +1 -1
- package/dist/backend/routes.admin.d.ts +2 -0
- package/dist/backend/routes.admin.d.ts.map +1 -1
- package/dist/backend/routes.admin.js +20 -1
- package/dist/backend/routes.admin.js.map +1 -1
- package/dist/backend/services/cms-hook-service.d.ts.map +1 -1
- package/dist/backend/services/cms-hook-service.js +10 -8
- package/dist/backend/services/cms-hook-service.js.map +1 -1
- package/dist/backend/services/page-builder-registry.d.ts +12 -1
- package/dist/backend/services/page-builder-registry.d.ts.map +1 -1
- package/dist/backend/services/page-builder-registry.js +18 -0
- package/dist/backend/services/page-builder-registry.js.map +1 -1
- package/dist/backend/services/translation/capability.d.ts +33 -0
- package/dist/backend/services/translation/capability.d.ts.map +1 -0
- package/dist/backend/services/translation/capability.js +68 -0
- package/dist/backend/services/translation/capability.js.map +1 -0
- package/dist/backend/services/translation/chunk.d.ts +12 -0
- package/dist/backend/services/translation/chunk.d.ts.map +1 -0
- package/dist/backend/services/translation/chunk.js +24 -0
- package/dist/backend/services/translation/chunk.js.map +1 -0
- package/dist/backend/services/translation/extract.d.ts +78 -0
- package/dist/backend/services/translation/extract.d.ts.map +1 -0
- package/dist/backend/services/translation/extract.js +325 -0
- package/dist/backend/services/translation/extract.js.map +1 -0
- package/dist/backend/services/translation/html-codec.d.ts +19 -0
- package/dist/backend/services/translation/html-codec.d.ts.map +1 -0
- package/dist/backend/services/translation/html-codec.js +58 -0
- package/dist/backend/services/translation/html-codec.js.map +1 -0
- package/dist/backend/services/translation/inject.d.ts +17 -0
- package/dist/backend/services/translation/inject.d.ts.map +1 -0
- package/dist/backend/services/translation/inject.js +86 -0
- package/dist/backend/services/translation/inject.js.map +1 -0
- package/dist/backend/services/translation/limits.d.ts +12 -0
- package/dist/backend/services/translation/limits.d.ts.map +1 -0
- package/dist/backend/services/translation/limits.js +12 -0
- package/dist/backend/services/translation/limits.js.map +1 -0
- package/dist/backend/services/translation/max-source-characters-validator.d.ts +9 -0
- package/dist/backend/services/translation/max-source-characters-validator.d.ts.map +1 -0
- package/dist/backend/services/translation/max-source-characters-validator.js +26 -0
- package/dist/backend/services/translation/max-source-characters-validator.js.map +1 -0
- package/dist/backend/services/translation/page-builder-translation.service.d.ts +24 -0
- package/dist/backend/services/translation/page-builder-translation.service.d.ts.map +1 -0
- package/dist/backend/services/translation/page-builder-translation.service.js +95 -0
- package/dist/backend/services/translation/page-builder-translation.service.js.map +1 -0
- package/dist/backend/services/translation/placeholders.d.ts +14 -0
- package/dist/backend/services/translation/placeholders.d.ts.map +1 -0
- package/dist/backend/services/translation/placeholders.js +25 -0
- package/dist/backend/services/translation/placeholders.js.map +1 -0
- package/dist/backend/services/translation/prompt.d.ts +16 -0
- package/dist/backend/services/translation/prompt.d.ts.map +1 -0
- package/dist/backend/services/translation/prompt.js +53 -0
- package/dist/backend/services/translation/prompt.js.map +1 -0
- package/dist/backend/services/translation/provider-error-map.d.ts +10 -0
- package/dist/backend/services/translation/provider-error-map.d.ts.map +1 -0
- package/dist/backend/services/translation/provider-error-map.js +17 -0
- package/dist/backend/services/translation/provider-error-map.js.map +1 -0
- package/dist/backend/services/translation/tiptap-inline-codec.d.ts +45 -0
- package/dist/backend/services/translation/tiptap-inline-codec.d.ts.map +1 -0
- package/dist/backend/services/translation/tiptap-inline-codec.js +129 -0
- package/dist/backend/services/translation/tiptap-inline-codec.js.map +1 -0
- package/dist/backend/services/translation/translation.service.d.ts +61 -0
- package/dist/backend/services/translation/translation.service.d.ts.map +1 -0
- package/dist/backend/services/translation/translation.service.js +148 -0
- package/dist/backend/services/translation/translation.service.js.map +1 -0
- package/dist/manifest.d.ts +17 -3
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +169 -1
- package/dist/manifest.js.map +1 -1
- package/docs/cms/extending-page-builder.md +33 -0
- package/docs/cms/index.md +67 -1
- package/i18n/en.json +57 -1
- package/i18n/pl.json +57 -1
- package/package.json +15 -13
|
@@ -97,6 +97,9 @@ export class PageBuilderRegistry {
|
|
|
97
97
|
: {}),
|
|
98
98
|
...(block.previewIcon !== undefined ? { previewIcon: block.previewIcon } : {}),
|
|
99
99
|
...(block.weight !== undefined ? { weight: block.weight } : {}),
|
|
100
|
+
...(block.translatable !== undefined
|
|
101
|
+
? { translatable: block.translatable.map((entry) => ({ ...entry })) }
|
|
102
|
+
: {}),
|
|
100
103
|
});
|
|
101
104
|
}
|
|
102
105
|
for (const category of (manifest.blockCategories ?? [])) {
|
|
@@ -131,6 +134,20 @@ export class PageBuilderRegistry {
|
|
|
131
134
|
knownNames() {
|
|
132
135
|
return new Set(this.components.keys());
|
|
133
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Feature 151 — what of a block the Page Builder translation may send.
|
|
139
|
+
*
|
|
140
|
+
* `undefined` for a name nobody declared, for a block that made no
|
|
141
|
+
* declaration, **and for a block whose owner is not effectively present**:
|
|
142
|
+
* the translation then leaves the node untouched and reports it, which is
|
|
143
|
+
* the palette's presence answer applied to the one question it asks.
|
|
144
|
+
*/
|
|
145
|
+
translatableFor(name) {
|
|
146
|
+
const registration = this.components.get(name);
|
|
147
|
+
if (!registration || !this.isModulePresent(registration.ownerModule))
|
|
148
|
+
return undefined;
|
|
149
|
+
return registration.translatable;
|
|
150
|
+
}
|
|
134
151
|
getBreakpoints() {
|
|
135
152
|
return { ...this.breakpoints };
|
|
136
153
|
}
|
|
@@ -165,6 +182,7 @@ export class PageBuilderRegistry {
|
|
|
165
182
|
...(reg.defaultProps !== undefined ? { defaultProps: reg.defaultProps } : {}),
|
|
166
183
|
...(reg.responsiveFields !== undefined ? { responsiveFields: reg.responsiveFields } : {}),
|
|
167
184
|
...(reg.weight !== undefined ? { weight: reg.weight } : {}),
|
|
185
|
+
...(reg.translatable !== undefined ? { translatable: reg.translatable } : {}),
|
|
168
186
|
})),
|
|
169
187
|
categories: this.foldCategories(),
|
|
170
188
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-builder-registry.js","sourceRoot":"","sources":["../../../src/backend/services/page-builder-registry.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2CAA2C;AAC3C,EAAE;AACF,6EAA6E;AAC7E,6DAA6D;AAC7D,8EAA8E;AAC9E,0EAA0E;AAC1E,6EAA6E;AAC7E,+EAA+E;AAC/E,qDAAqD;AACrD,iDAAiD;AACjD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,wCAAwC;AACxC,EAAE;AACF,4CAA4C;AAC5C,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,gFAAgF;AAChF,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,gFAAgF;AAChF,2EAA2E;AAC3E,4BAA4B;
|
|
1
|
+
{"version":3,"file":"page-builder-registry.js","sourceRoot":"","sources":["../../../src/backend/services/page-builder-registry.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2CAA2C;AAC3C,EAAE;AACF,6EAA6E;AAC7E,6DAA6D;AAC7D,8EAA8E;AAC9E,0EAA0E;AAC1E,6EAA6E;AAC7E,+EAA+E;AAC/E,qDAAqD;AACrD,iDAAiD;AACjD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,wCAAwC;AACxC,EAAE;AACF,4CAA4C;AAC5C,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,gFAAgF;AAChF,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,gFAAgF;AAChF,2EAA2E;AAC3E,4BAA4B;AAa5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAsD1F;;;;;;;;;;;;;GAaG;A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C,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjE,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpE,WAAW,EAAE,MAAM,CAAC,WAAW;aAChC,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAED,SAAS,2BAA2B,CAAC,CAAsB,EAAE,CAAsB;IACjF,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,iBAAiB,CAAC;IAChD,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,iBAAiB,CAAC;IAChD,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAC9B,OAAO,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CmsPageBuilderTranslationCapability, type LlmProvider, type ResolveResult } from '@endora-commerce/contracts';
|
|
2
|
+
import { type FetchLike, type LlmProviderAdapter } from '@endora-commerce/llm-client';
|
|
3
|
+
/**
|
|
4
|
+
* Feature 151 (research R11, R21, `data-model.md` §1) — is the Translate action
|
|
5
|
+
* ready, and with which model? Derived per request from the three settings and
|
|
6
|
+
* the referenced credential, never stored, so a change to either applies to the
|
|
7
|
+
* next request without a restart (FR-004).
|
|
8
|
+
*
|
|
9
|
+
* Evaluated in order, and the order is the contract: a switched-off function
|
|
10
|
+
* never touches `credentials`.
|
|
11
|
+
*/
|
|
12
|
+
export interface TranslationConfigDeps {
|
|
13
|
+
/** A platform-wide setting value, or `undefined` when it cannot be read. */
|
|
14
|
+
readSetting(code: string): Promise<unknown>;
|
|
15
|
+
isCredentialsPresent(): boolean;
|
|
16
|
+
/** `credentials`' `resolve`, reached through its port per call. */
|
|
17
|
+
resolveCredential(code: string): Promise<ResolveResult>;
|
|
18
|
+
fetchImpl?: FetchLike | undefined;
|
|
19
|
+
}
|
|
20
|
+
export type TranslationConfig = {
|
|
21
|
+
status: 'ready';
|
|
22
|
+
provider: LlmProvider;
|
|
23
|
+
model: string;
|
|
24
|
+
adapter: LlmProviderAdapter;
|
|
25
|
+
maxCharacters: number;
|
|
26
|
+
} | {
|
|
27
|
+
status: 'disabled' | 'not_configured' | 'unavailable';
|
|
28
|
+
maxCharacters: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function resolveTranslationConfig(deps: TranslationConfigDeps): Promise<TranslationConfig>;
|
|
31
|
+
/** The wire answer: provider and model when ready, never the key, code or Base URL. */
|
|
32
|
+
export declare function capabilityOf(config: TranslationConfig): CmsPageBuilderTranslationCapability;
|
|
33
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../../../src/backend/services/translation/capability.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,mCAAmC,EACxC,KAAK,WAAW,EAChB,KAAK,aAAa,EACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,kBAAkB,EACxB,MAAM,6BAA6B,CAAC;AAGrC;;;;;;;;GAQG;AAEH,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,oBAAoB,IAAI,OAAO,CAAC;IAChC,mEAAmE;IACnE,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACxD,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,MAAM,iBAAiB,GACzB;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,kBAAkB,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;CACvB,GACD;IAAE,MAAM,EAAE,UAAU,GAAG,gBAAgB,GAAG,aAAa,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAKrF,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgDtG;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,mCAAmC,CAK3F"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CMS_TRANSLATION_DEFAULT_MAX_SOURCE_CHARACTERS, CMS_TRANSLATION_MAX_SOURCE_CHARACTERS_BOUNDS, LlmProviderSchema, } from '@endora-commerce/contracts';
|
|
3
|
+
import { rethrowIfModuleDisabled } from '@endora-commerce/platform/kernel';
|
|
4
|
+
import { createLlmAdapter, LlmConfigurationError, } from '@endora-commerce/llm-client';
|
|
5
|
+
import { CMS_PAGE_BUILDER_SETTING_CODES } from '../../../manifest.js';
|
|
6
|
+
const { min, max } = CMS_TRANSLATION_MAX_SOURCE_CHARACTERS_BOUNDS;
|
|
7
|
+
const limitSchema = z.number().int().min(min).max(max);
|
|
8
|
+
export async function resolveTranslationConfig(deps) {
|
|
9
|
+
const [enabled, reference, limit] = await Promise.all([
|
|
10
|
+
deps.readSetting(CMS_PAGE_BUILDER_SETTING_CODES.TRANSLATION_ENABLED),
|
|
11
|
+
deps.readSetting(CMS_PAGE_BUILDER_SETTING_CODES.TRANSLATION_LLM_CREDENTIALS),
|
|
12
|
+
deps.readSetting(CMS_PAGE_BUILDER_SETTING_CODES.TRANSLATION_MAX_SOURCE_CHARACTERS),
|
|
13
|
+
]);
|
|
14
|
+
// A stored value outside the bounds — written before the write validator
|
|
15
|
+
// existed, or by hand — is not trusted; the default is.
|
|
16
|
+
const parsedLimit = limitSchema.safeParse(limit);
|
|
17
|
+
const maxCharacters = parsedLimit.success ? parsedLimit.data : CMS_TRANSLATION_DEFAULT_MAX_SOURCE_CHARACTERS;
|
|
18
|
+
if (enabled !== true)
|
|
19
|
+
return { status: 'disabled', maxCharacters };
|
|
20
|
+
if (!deps.isCredentialsPresent())
|
|
21
|
+
return { status: 'unavailable', maxCharacters };
|
|
22
|
+
const code = typeof reference === 'string' ? reference.trim() : '';
|
|
23
|
+
if (code === '')
|
|
24
|
+
return { status: 'not_configured', maxCharacters };
|
|
25
|
+
let resolved;
|
|
26
|
+
try {
|
|
27
|
+
resolved = await deps.resolveCredential(code);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
// Tolerated: an unresolvable reference is a configuration the operator has
|
|
31
|
+
// to fix, which is what `not_configured` tells them. A presence answer is
|
|
32
|
+
// not that, and goes through.
|
|
33
|
+
rethrowIfModuleDisabled(error);
|
|
34
|
+
resolved = null;
|
|
35
|
+
}
|
|
36
|
+
if (!resolved || resolved.status !== 'ok')
|
|
37
|
+
return { status: 'not_configured', maxCharacters };
|
|
38
|
+
const provider = LlmProviderSchema.safeParse(resolved.providerCode);
|
|
39
|
+
const text = (key) => {
|
|
40
|
+
const value = resolved.values[key];
|
|
41
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
42
|
+
};
|
|
43
|
+
const model = text('model');
|
|
44
|
+
const apiKey = text('apiKey');
|
|
45
|
+
if (!provider.success || model === '' || apiKey === '')
|
|
46
|
+
return { status: 'not_configured', maxCharacters };
|
|
47
|
+
try {
|
|
48
|
+
const adapter = createLlmAdapter(provider.data, {
|
|
49
|
+
apiKey,
|
|
50
|
+
baseUrl: text('baseUrl'),
|
|
51
|
+
fetchImpl: deps.fetchImpl,
|
|
52
|
+
});
|
|
53
|
+
return { status: 'ready', provider: provider.data, model, adapter, maxCharacters };
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof LlmConfigurationError)
|
|
57
|
+
return { status: 'not_configured', maxCharacters };
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** The wire answer: provider and model when ready, never the key, code or Base URL. */
|
|
62
|
+
export function capabilityOf(config) {
|
|
63
|
+
if (config.status === 'ready') {
|
|
64
|
+
return { status: 'ready', provider: config.provider, model: config.model, maxCharacters: config.maxCharacters };
|
|
65
|
+
}
|
|
66
|
+
return { status: config.status, maxCharacters: config.maxCharacters };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=capability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../../../src/backend/services/translation/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,6CAA6C,EAC7C,4CAA4C,EAC5C,iBAAiB,GAIlB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EACL,gBAAgB,EAChB,qBAAqB,GAGtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AA+BtE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,4CAA4C,CAAC;AAClE,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,IAA2B;IACxE,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAA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AAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;IAClH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature 151 (research R8) — split the segments of one request into the
|
|
3
|
+
* provider calls that carry them. Order is preserved; a segment longer than the
|
|
4
|
+
* character bound travels alone rather than being cut.
|
|
5
|
+
*/
|
|
6
|
+
export declare function chunkSegments<T extends {
|
|
7
|
+
text: string;
|
|
8
|
+
}>(segments: readonly T[], bounds: {
|
|
9
|
+
maxCharacters: number;
|
|
10
|
+
maxSegments: number;
|
|
11
|
+
}): T[][];
|
|
12
|
+
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../../../src/backend/services/translation/chunk.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EACtD,QAAQ,EAAE,SAAS,CAAC,EAAE,EACtB,MAAM,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACrD,CAAC,EAAE,EAAE,CAgBP"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature 151 (research R8) — split the segments of one request into the
|
|
3
|
+
* provider calls that carry them. Order is preserved; a segment longer than the
|
|
4
|
+
* character bound travels alone rather than being cut.
|
|
5
|
+
*/
|
|
6
|
+
export function chunkSegments(segments, bounds) {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
let current = [];
|
|
9
|
+
let size = 0;
|
|
10
|
+
for (const segment of segments) {
|
|
11
|
+
const length = segment.text.length;
|
|
12
|
+
if (current.length > 0 && (size + length > bounds.maxCharacters || current.length >= bounds.maxSegments)) {
|
|
13
|
+
chunks.push(current);
|
|
14
|
+
current = [];
|
|
15
|
+
size = 0;
|
|
16
|
+
}
|
|
17
|
+
current.push(segment);
|
|
18
|
+
size += length;
|
|
19
|
+
}
|
|
20
|
+
if (current.length > 0)
|
|
21
|
+
chunks.push(current);
|
|
22
|
+
return chunks;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=chunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../../../src/backend/services/translation/chunk.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAsB,EACtB,MAAsD;IAEtD,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,IAAI,OAAO,GAAQ,EAAE,CAAC;IACtB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QACnC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YACzG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,CAAC,CAAC;QACX,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,IAAI,MAAM,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { BlockTranslatableText, CmsPageBuilderTranslationScope } from '@endora-commerce/contracts';
|
|
2
|
+
import { type EncodedInline } from './tiptap-inline-codec.js';
|
|
3
|
+
/**
|
|
4
|
+
* Feature 151 (research R4–R8, R22) — what of a Page Builder document is sent
|
|
5
|
+
* to the model, and where each answer goes back.
|
|
6
|
+
*
|
|
7
|
+
* Pure: it reads the document and the per-block declarations and returns the
|
|
8
|
+
* segments (deduplicated, as sent) and the locations they came from. Nothing
|
|
9
|
+
* here knows about providers, chunks or HTTP.
|
|
10
|
+
*/
|
|
11
|
+
/** A block's declaration, or `undefined` when the platform does not know how to translate it. */
|
|
12
|
+
export type Declarations = (blockName: string) => readonly BlockTranslatableText[] | undefined;
|
|
13
|
+
/** A path from the document root to a value: object keys and array indexes. */
|
|
14
|
+
export type ValuePath = ReadonlyArray<string | number>;
|
|
15
|
+
export interface Segment {
|
|
16
|
+
id: string;
|
|
17
|
+
/** How `text` is encoded: escaped plain text, inline tags (TipTap) or ordered HTML placeholders. */
|
|
18
|
+
kind: 'plain' | 'inline' | 'html';
|
|
19
|
+
/** Exactly what is sent to the model. */
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
export type Location =
|
|
23
|
+
/** A whole string, or — for a text selection — the range `[start, end)` of it. */
|
|
24
|
+
{
|
|
25
|
+
kind: 'plain';
|
|
26
|
+
leaf: ValuePath;
|
|
27
|
+
segmentId: string;
|
|
28
|
+
range?: readonly [number, number];
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'html';
|
|
31
|
+
leaf: ValuePath;
|
|
32
|
+
segmentId: string;
|
|
33
|
+
tags: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/** One textblock of a TipTap document, translated with its inline tags. */
|
|
36
|
+
| {
|
|
37
|
+
kind: 'inline';
|
|
38
|
+
leaf: ValuePath;
|
|
39
|
+
node: readonly number[];
|
|
40
|
+
segmentId: string;
|
|
41
|
+
encoded: EncodedInline;
|
|
42
|
+
}
|
|
43
|
+
/** Part of one text node of a TipTap textblock — a selection inside one formatting run. */
|
|
44
|
+
| {
|
|
45
|
+
kind: 'run';
|
|
46
|
+
leaf: ValuePath;
|
|
47
|
+
node: readonly number[];
|
|
48
|
+
child: number;
|
|
49
|
+
range: readonly [number, number];
|
|
50
|
+
segmentId: string;
|
|
51
|
+
};
|
|
52
|
+
export interface Extraction {
|
|
53
|
+
segments: Segment[];
|
|
54
|
+
locations: Location[];
|
|
55
|
+
/** Blocks with no declaration, by name — reported, never touched (FR-025). */
|
|
56
|
+
untranslatableBlocks: Map<string, number>;
|
|
57
|
+
/** Characters sent: the sum of the segments' encoded lengths. */
|
|
58
|
+
characters: number;
|
|
59
|
+
scope: {
|
|
60
|
+
kind: 'canvas' | 'component' | 'text';
|
|
61
|
+
widened: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** The selected component's block name, when the scope named one (audit metadata). */
|
|
64
|
+
componentType?: string;
|
|
65
|
+
}
|
|
66
|
+
/** The selection's block or text is not in the submitted document (research R22). */
|
|
67
|
+
export declare class SelectionNotFoundError extends Error {
|
|
68
|
+
readonly what: 'component' | 'text';
|
|
69
|
+
readonly name = "SelectionNotFoundError";
|
|
70
|
+
constructor(what: 'component' | 'text');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Extract the segments to translate from `data`, restricted to `scope`
|
|
74
|
+
* (absent = the whole canvas). Throws {@link SelectionNotFoundError} when the
|
|
75
|
+
* scope's component or text is not in the document — before anything is sent.
|
|
76
|
+
*/
|
|
77
|
+
export declare function extract(data: unknown, declarations: Declarations, scope?: CmsPageBuilderTranslationScope): Extraction;
|
|
78
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../src/backend/services/translation/extract.ts"],"names":[],"mappings":"AAAA,OAAO,KA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AAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEN,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,8EAA8E;IAC9E,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IACnE,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qFAAqF;AACrF,qBAAa,sBAAuB,SAAQ,KAAK;IAEnC,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM;IAD/C,SAAkB,IAAI,4BAA4B;gBAC7B,IAAI,EAAE,WAAW,GAAG,MAAM;CAGhD;AA2PD;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,YAAY,EAC1B,KAAK,CAAC,EAAE,8BAA8B,GACrC,UAAU,CAsDZ"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { encodeHtml, visibleHtmlText } from './html-codec.js';
|
|
2
|
+
import { escapeText } from './placeholders.js';
|
|
3
|
+
import { encodeInline, nodeAt, textblockPaths } from './tiptap-inline-codec.js';
|
|
4
|
+
/** The selection's block or text is not in the submitted document (research R22). */
|
|
5
|
+
export class SelectionNotFoundError extends Error {
|
|
6
|
+
what;
|
|
7
|
+
name = 'SelectionNotFoundError';
|
|
8
|
+
constructor(what) {
|
|
9
|
+
super(what === 'component' ? 'The selected component is not in the content.' : 'The selected text is not in the content.');
|
|
10
|
+
this.what = what;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const MAX_DEPTH = 64;
|
|
14
|
+
const LETTER = /\p{L}/u;
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function isComponent(value) {
|
|
19
|
+
return isRecord(value) && typeof value['type'] === 'string' && isRecord(value['props']);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Every component in document order, each before its descendants. Slots are any
|
|
23
|
+
* prop holding an array of components, at any depth inside the props (the
|
|
24
|
+
* deprecated `Row.columnItems[].content` included); legacy `zones` follow
|
|
25
|
+
* `content`. The root is not a component.
|
|
26
|
+
*/
|
|
27
|
+
function componentsOf(data) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const visitList = (list, path, depth) => {
|
|
30
|
+
list.forEach((element, index) => {
|
|
31
|
+
if (isComponent(element))
|
|
32
|
+
visitComponent(element, [...path, index], depth);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const visitComponent = (node, path, depth) => {
|
|
36
|
+
out.push({ node, path });
|
|
37
|
+
if (depth > MAX_DEPTH)
|
|
38
|
+
return;
|
|
39
|
+
for (const [key, value] of Object.entries(node.props))
|
|
40
|
+
searchValue(value, [...path, 'props', key], depth + 1);
|
|
41
|
+
};
|
|
42
|
+
const searchValue = (value, path, depth) => {
|
|
43
|
+
if (depth > MAX_DEPTH)
|
|
44
|
+
return;
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
if (value.length > 0 && value.every(isComponent)) {
|
|
47
|
+
visitList(value, path, depth);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
value.forEach((element, index) => {
|
|
51
|
+
if (isRecord(element))
|
|
52
|
+
searchValue(element, [...path, index], depth + 1);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (isRecord(value) && !isComponent(value)) {
|
|
56
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
57
|
+
if (Array.isArray(inner) || isRecord(inner))
|
|
58
|
+
searchValue(inner, [...path, key], depth + 1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
if (Array.isArray(data['content']))
|
|
63
|
+
visitList(data['content'], ['content'], 0);
|
|
64
|
+
if (isRecord(data['zones'])) {
|
|
65
|
+
for (const [zone, list] of Object.entries(data['zones'])) {
|
|
66
|
+
if (Array.isArray(list))
|
|
67
|
+
visitList(list, ['zones', zone], 0);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function isPrefix(prefix, path) {
|
|
73
|
+
return prefix.length <= path.length && prefix.every((part, index) => path[index] === part);
|
|
74
|
+
}
|
|
75
|
+
/** Resolve one declared path (`items[].title`) against a component's props. */
|
|
76
|
+
function leavesOf(component, declaration) {
|
|
77
|
+
const format = declaration.format ?? 'plain';
|
|
78
|
+
const parts = declaration.path.split('.');
|
|
79
|
+
let frontier = [
|
|
80
|
+
{ value: component.node.props, path: [...component.path, 'props'] },
|
|
81
|
+
];
|
|
82
|
+
for (const part of parts) {
|
|
83
|
+
const iterate = part.endsWith('[]');
|
|
84
|
+
const key = iterate ? part.slice(0, -2) : part;
|
|
85
|
+
const next = [];
|
|
86
|
+
for (const { value, path } of frontier) {
|
|
87
|
+
if (!isRecord(value) || !(key in value))
|
|
88
|
+
continue;
|
|
89
|
+
const inner = value[key];
|
|
90
|
+
if (iterate) {
|
|
91
|
+
if (Array.isArray(inner))
|
|
92
|
+
inner.forEach((element, index) => next.push({ value: element, path: [...path, key, index] }));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
next.push({ value: inner, path: [...path, key] });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
frontier = next;
|
|
99
|
+
}
|
|
100
|
+
return frontier.map(({ value, path }) => ({ value, path, format }));
|
|
101
|
+
}
|
|
102
|
+
function isTiptapDoc(value) {
|
|
103
|
+
return isRecord(value) && Array.isArray(value['content']);
|
|
104
|
+
}
|
|
105
|
+
class SegmentTable {
|
|
106
|
+
segments = [];
|
|
107
|
+
byKey = new Map();
|
|
108
|
+
add(kind, text) {
|
|
109
|
+
const key = `${kind}\u0000${text}`;
|
|
110
|
+
const existing = this.byKey.get(key);
|
|
111
|
+
if (existing)
|
|
112
|
+
return existing;
|
|
113
|
+
const id = `s${this.segments.length + 1}`;
|
|
114
|
+
this.segments.push({ id, kind, text });
|
|
115
|
+
this.byKey.set(key, id);
|
|
116
|
+
return id;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Every location of one leaf, for a whole-leaf translation. */
|
|
120
|
+
function wholeLeaf(leaf, table, locations) {
|
|
121
|
+
if (leaf.format === 'plain') {
|
|
122
|
+
if (typeof leaf.value !== 'string' || !LETTER.test(leaf.value))
|
|
123
|
+
return;
|
|
124
|
+
locations.push({ kind: 'plain', leaf: leaf.path, segmentId: table.add('plain', escapeText(leaf.value)) });
|
|
125
|
+
}
|
|
126
|
+
else if (leaf.format === 'html') {
|
|
127
|
+
if (typeof leaf.value !== 'string' || !LETTER.test(visibleHtmlText(leaf.value)))
|
|
128
|
+
return;
|
|
129
|
+
const encoded = encodeHtml(leaf.value);
|
|
130
|
+
locations.push({ kind: 'html', leaf: leaf.path, segmentId: table.add('html', encoded.text), tags: encoded.tags });
|
|
131
|
+
}
|
|
132
|
+
else if (isTiptapDoc(leaf.value)) {
|
|
133
|
+
for (const nodePath of textblockPaths(leaf.value)) {
|
|
134
|
+
textblock(leaf, leaf.value, nodePath, table, locations);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function textblock(leaf, doc, nodePath, table, locations) {
|
|
139
|
+
const node = nodeAt(doc, nodePath);
|
|
140
|
+
if (!node)
|
|
141
|
+
return;
|
|
142
|
+
const encoded = encodeInline(node);
|
|
143
|
+
const visible = (node.content ?? []).map((c) => (c.type === 'text' ? (c.text ?? '') : '')).join('');
|
|
144
|
+
if (!LETTER.test(visible))
|
|
145
|
+
return;
|
|
146
|
+
locations.push({ kind: 'inline', leaf: leaf.path, node: nodePath, segmentId: table.add('inline', encoded.text), encoded });
|
|
147
|
+
}
|
|
148
|
+
// ── Text selection ────────────────────────────────────────────────────────
|
|
149
|
+
/** Collapse whitespace runs to one space, trimmed; `map[i]` is the original index of normalised char `i`. */
|
|
150
|
+
function normalise(text) {
|
|
151
|
+
let out = '';
|
|
152
|
+
const map = [];
|
|
153
|
+
let pendingSpace = false;
|
|
154
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
155
|
+
const ch = text[i];
|
|
156
|
+
if (/\s/.test(ch)) {
|
|
157
|
+
pendingSpace = out.length > 0;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (pendingSpace) {
|
|
161
|
+
out += ' ';
|
|
162
|
+
map.push(i - 1);
|
|
163
|
+
pendingSpace = false;
|
|
164
|
+
}
|
|
165
|
+
out += ch;
|
|
166
|
+
map.push(i);
|
|
167
|
+
}
|
|
168
|
+
return { text: out, map };
|
|
169
|
+
}
|
|
170
|
+
/** The original `[start, end)` of `needle` (already normalised) in `haystack`, or `null`. */
|
|
171
|
+
function findNormalised(haystack, needle) {
|
|
172
|
+
const hay = normalise(haystack);
|
|
173
|
+
const at = hay.text.indexOf(needle);
|
|
174
|
+
if (at < 0 || needle.length === 0)
|
|
175
|
+
return null;
|
|
176
|
+
return [hay.map[at], hay.map[at + needle.length - 1] + 1];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Locate a selected fragment in one leaf. Returns `null` when the leaf does not
|
|
180
|
+
* hold it; otherwise pushes the locations and returns whether it had to widen.
|
|
181
|
+
*/
|
|
182
|
+
function selectionInLeaf(leaf, needle, table, locations) {
|
|
183
|
+
if (leaf.format === 'plain') {
|
|
184
|
+
if (typeof leaf.value !== 'string')
|
|
185
|
+
return null;
|
|
186
|
+
const range = findNormalised(leaf.value, needle);
|
|
187
|
+
if (!range)
|
|
188
|
+
return null;
|
|
189
|
+
const segmentId = table.add('plain', escapeText(leaf.value.slice(range[0], range[1])));
|
|
190
|
+
locations.push({ kind: 'plain', leaf: leaf.path, segmentId, range });
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (leaf.format === 'html') {
|
|
194
|
+
if (typeof leaf.value !== 'string')
|
|
195
|
+
return null;
|
|
196
|
+
const visible = normalise(visibleHtmlText(leaf.value)).text;
|
|
197
|
+
if (!visible.includes(needle))
|
|
198
|
+
return null;
|
|
199
|
+
// Inside markup the safe unit is the whole value: its tags travel as
|
|
200
|
+
// ordered placeholders and nothing smaller can be re-assembled safely.
|
|
201
|
+
wholeLeaf(leaf, table, locations);
|
|
202
|
+
return visible !== needle;
|
|
203
|
+
}
|
|
204
|
+
if (!isTiptapDoc(leaf.value))
|
|
205
|
+
return null;
|
|
206
|
+
const doc = leaf.value;
|
|
207
|
+
const blocks = textblockPaths(doc);
|
|
208
|
+
for (const nodePath of blocks) {
|
|
209
|
+
const node = nodeAt(doc, nodePath);
|
|
210
|
+
// Visible text with, per character, the inline child it came from.
|
|
211
|
+
let visible = '';
|
|
212
|
+
const owner = [];
|
|
213
|
+
const offset = [];
|
|
214
|
+
(node.content ?? []).forEach((child, index) => {
|
|
215
|
+
const text = child.type === 'text' ? (child.text ?? '') : child.type === 'hardBreak' ? '\n' : '';
|
|
216
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
217
|
+
visible += text[i];
|
|
218
|
+
owner.push(child.type === 'text' ? index : -1);
|
|
219
|
+
offset.push(i);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
const range = findNormalised(visible, needle);
|
|
223
|
+
if (!range)
|
|
224
|
+
continue;
|
|
225
|
+
const first = owner[range[0]];
|
|
226
|
+
const last = owner[range[1] - 1];
|
|
227
|
+
if (first >= 0 && first === last) {
|
|
228
|
+
const child = node.content[first];
|
|
229
|
+
const start = offset[range[0]];
|
|
230
|
+
const end = offset[range[1] - 1] + 1;
|
|
231
|
+
const segmentId = table.add('plain', escapeText((child.text ?? '').slice(start, end)));
|
|
232
|
+
locations.push({ kind: 'run', leaf: leaf.path, node: nodePath, child: first, range: [start, end], segmentId });
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
textblock(leaf, doc, nodePath, table, locations);
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
// Across paragraphs: search the textblocks joined by line breaks, and widen
|
|
239
|
+
// to every one the match touches.
|
|
240
|
+
let joined = '';
|
|
241
|
+
const blockOf = [];
|
|
242
|
+
blocks.forEach((nodePath, blockIndex) => {
|
|
243
|
+
if (blockIndex > 0) {
|
|
244
|
+
joined += '\n';
|
|
245
|
+
blockOf.push(blockIndex);
|
|
246
|
+
}
|
|
247
|
+
const node = nodeAt(doc, nodePath);
|
|
248
|
+
const text = (node.content ?? []).map((c) => (c.type === 'text' ? (c.text ?? '') : c.type === 'hardBreak' ? '\n' : '')).join('');
|
|
249
|
+
joined += text;
|
|
250
|
+
for (let i = 0; i < text.length; i += 1)
|
|
251
|
+
blockOf.push(blockIndex);
|
|
252
|
+
});
|
|
253
|
+
const range = findNormalised(joined, needle);
|
|
254
|
+
if (!range)
|
|
255
|
+
return null;
|
|
256
|
+
for (let blockIndex = blockOf[range[0]]; blockIndex <= blockOf[range[1] - 1]; blockIndex += 1) {
|
|
257
|
+
textblock(leaf, doc, blocks[blockIndex], table, locations);
|
|
258
|
+
}
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
// ── Entry point ───────────────────────────────────────────────────────────
|
|
262
|
+
/**
|
|
263
|
+
* Extract the segments to translate from `data`, restricted to `scope`
|
|
264
|
+
* (absent = the whole canvas). Throws {@link SelectionNotFoundError} when the
|
|
265
|
+
* scope's component or text is not in the document — before anything is sent.
|
|
266
|
+
*/
|
|
267
|
+
export function extract(data, declarations, scope) {
|
|
268
|
+
const document = isRecord(data) ? data : {};
|
|
269
|
+
const table = new SegmentTable();
|
|
270
|
+
const locations = [];
|
|
271
|
+
const untranslatableBlocks = new Map();
|
|
272
|
+
let components = componentsOf(document);
|
|
273
|
+
let componentType;
|
|
274
|
+
if (scope?.componentId) {
|
|
275
|
+
const selected = components.find((c) => c.node.props['id'] === scope.componentId);
|
|
276
|
+
if (!selected)
|
|
277
|
+
throw new SelectionNotFoundError('component');
|
|
278
|
+
componentType = selected.node.type;
|
|
279
|
+
components = components.filter((c) => isPrefix(selected.path, c.path));
|
|
280
|
+
}
|
|
281
|
+
let widened = false;
|
|
282
|
+
if (scope?.kind === 'text') {
|
|
283
|
+
const needle = normalise(scope.selectedText).text;
|
|
284
|
+
let found = false;
|
|
285
|
+
outer: for (const component of components) {
|
|
286
|
+
const declaration = declarations(component.node.type);
|
|
287
|
+
if (!declaration)
|
|
288
|
+
continue;
|
|
289
|
+
for (const entry of declaration) {
|
|
290
|
+
for (const leaf of leavesOf(component, entry)) {
|
|
291
|
+
const result = selectionInLeaf(leaf, needle, table, locations);
|
|
292
|
+
if (result === null)
|
|
293
|
+
continue;
|
|
294
|
+
widened = result;
|
|
295
|
+
found = true;
|
|
296
|
+
break outer;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (!found)
|
|
301
|
+
throw new SelectionNotFoundError('text');
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
for (const component of components) {
|
|
305
|
+
const declaration = declarations(component.node.type);
|
|
306
|
+
if (!declaration) {
|
|
307
|
+
untranslatableBlocks.set(component.node.type, (untranslatableBlocks.get(component.node.type) ?? 0) + 1);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
for (const entry of declaration) {
|
|
311
|
+
for (const leaf of leavesOf(component, entry))
|
|
312
|
+
wholeLeaf(leaf, table, locations);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
segments: table.segments,
|
|
318
|
+
locations,
|
|
319
|
+
untranslatableBlocks,
|
|
320
|
+
characters: table.segments.reduce((sum, segment) => sum + segment.text.length, 0),
|
|
321
|
+
scope: { kind: scope ? scope.kind : 'canvas', widened },
|
|
322
|
+
...(componentType !== undefined ? { componentType } : {}),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=extract.js.map
|