@cratis/scene.engine 4.1.1 → 4.2.1
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/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resolveStrings.js +72 -0
- package/dist/cjs/resolveStrings.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resolveStrings.d.ts +6 -0
- package/dist/esm/resolveStrings.d.ts.map +1 -0
- package/dist/esm/resolveStrings.js +68 -0
- package/dist/esm/resolveStrings.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +5 -4
- package/resolveStrings.ts +84 -0
- package/dist/esm/for_aggregateContributions/when_aggregating_by_contribution_point.d.ts +0 -2
- package/dist/esm/for_aggregateContributions/when_aggregating_by_contribution_point.d.ts.map +0 -1
- package/dist/esm/for_aggregateContributions/when_aggregating_by_contribution_point.js +0 -23
- package/dist/esm/for_aggregateContributions/when_aggregating_by_contribution_point.js.map +0 -1
- package/dist/esm/for_buildStarterProfile/when_checking_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_buildStarterProfile/when_checking_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_buildStarterProfile/when_checking_against_the_shared_fixture_corpus.js +0 -16
- package/dist/esm/for_buildStarterProfile/when_checking_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_computeSizeClass/when_computing_the_size_class.d.ts +0 -2
- package/dist/esm/for_computeSizeClass/when_computing_the_size_class.d.ts.map +0 -1
- package/dist/esm/for_computeSizeClass/when_computing_the_size_class.js +0 -17
- package/dist/esm/for_computeSizeClass/when_computing_the_size_class.js.map +0 -1
- package/dist/esm/for_evaluateFlowArrangement/when_evaluating_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_evaluateFlowArrangement/when_evaluating_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_evaluateFlowArrangement/when_evaluating_against_the_shared_fixture_corpus.js +0 -43
- package/dist/esm/for_evaluateFlowArrangement/when_evaluating_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_evaluateFreeformArrangement/when_evaluating_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_evaluateFreeformArrangement/when_evaluating_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_evaluateFreeformArrangement/when_evaluating_against_the_shared_fixture_corpus.js +0 -46
- package/dist/esm/for_evaluateFreeformArrangement/when_evaluating_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_evaluateFreeformSlotArrangement/when_evaluating_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_evaluateFreeformSlotArrangement/when_evaluating_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_evaluateFreeformSlotArrangement/when_evaluating_against_the_shared_fixture_corpus.js +0 -25
- package/dist/esm/for_evaluateFreeformSlotArrangement/when_evaluating_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_incompatibleStarterThemes/when_checking_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_incompatibleStarterThemes/when_checking_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_incompatibleStarterThemes/when_checking_against_the_shared_fixture_corpus.js +0 -17
- package/dist/esm/for_incompatibleStarterThemes/when_checking_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_packageCatalog/when_querying_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_packageCatalog/when_querying_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_packageCatalog/when_querying_against_the_shared_fixture_corpus.js +0 -22
- package/dist/esm/for_packageCatalog/when_querying_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_packageDependencies/fixtures.d.ts +0 -38
- package/dist/esm/for_packageDependencies/fixtures.d.ts.map +0 -1
- package/dist/esm/for_packageDependencies/fixtures.js +0 -5
- package/dist/esm/for_packageDependencies/fixtures.js.map +0 -1
- package/dist/esm/for_packageDependencies/when_resolving_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_packageDependencies/when_resolving_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_packageDependencies/when_resolving_against_the_shared_fixture_corpus.js +0 -29
- package/dist/esm/for_packageDependencies/when_resolving_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_packageVersionRange/when_checking_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_packageVersionRange/when_checking_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_packageVersionRange/when_checking_against_the_shared_fixture_corpus.js +0 -10
- package/dist/esm/for_packageVersionRange/when_checking_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_panelKind/when_telling_the_panels_apart.d.ts +0 -2
- package/dist/esm/for_panelKind/when_telling_the_panels_apart.d.ts.map +0 -1
- package/dist/esm/for_panelKind/when_telling_the_panels_apart.js +0 -38
- package/dist/esm/for_panelKind/when_telling_the_panels_apart.js.map +0 -1
- package/dist/esm/for_renderElement/when_rendering_a_mixed_tree.d.ts +0 -2
- package/dist/esm/for_renderElement/when_rendering_a_mixed_tree.d.ts.map +0 -1
- package/dist/esm/for_renderElement/when_rendering_a_mixed_tree.js +0 -46
- package/dist/esm/for_renderElement/when_rendering_a_mixed_tree.js.map +0 -1
- package/dist/esm/for_resolveBehaviors/when_resolving_additive_attachments.d.ts +0 -2
- package/dist/esm/for_resolveBehaviors/when_resolving_additive_attachments.d.ts.map +0 -1
- package/dist/esm/for_resolveBehaviors/when_resolving_additive_attachments.js +0 -68
- package/dist/esm/for_resolveBehaviors/when_resolving_additive_attachments.js.map +0 -1
- package/dist/esm/for_resolveComponentName/when_resolving_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_resolveComponentName/when_resolving_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_resolveComponentName/when_resolving_against_the_shared_fixture_corpus.js +0 -20
- package/dist/esm/for_resolveComponentName/when_resolving_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_resolveScreenTemplates/when_resolving_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_resolveScreenTemplates/when_resolving_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_resolveScreenTemplates/when_resolving_against_the_shared_fixture_corpus.js +0 -30
- package/dist/esm/for_resolveScreenTemplates/when_resolving_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_runActions/given/a_recording_dispatcher.d.ts +0 -21
- package/dist/esm/for_runActions/given/a_recording_dispatcher.d.ts.map +0 -1
- package/dist/esm/for_runActions/given/a_recording_dispatcher.js +0 -45
- package/dist/esm/for_runActions/given/a_recording_dispatcher.js.map +0 -1
- package/dist/esm/for_runActions/when_running_a_sequence_of_actions.d.ts +0 -2
- package/dist/esm/for_runActions/when_running_a_sequence_of_actions.d.ts.map +0 -1
- package/dist/esm/for_runActions/when_running_a_sequence_of_actions.js +0 -126
- package/dist/esm/for_runActions/when_running_a_sequence_of_actions.js.map +0 -1
- package/dist/esm/for_runActions/when_running_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_runActions/when_running_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_runActions/when_running_against_the_shared_fixture_corpus.js +0 -61
- package/dist/esm/for_runActions/when_running_against_the_shared_fixture_corpus.js.map +0 -1
- package/dist/esm/for_themeCompatibility/when_checking_against_the_shared_fixture_corpus.d.ts +0 -2
- package/dist/esm/for_themeCompatibility/when_checking_against_the_shared_fixture_corpus.d.ts.map +0 -1
- package/dist/esm/for_themeCompatibility/when_checking_against_the_shared_fixture_corpus.js +0 -18
- package/dist/esm/for_themeCompatibility/when_checking_against_the_shared_fixture_corpus.js.map +0 -1
- package/for_aggregateContributions/when_aggregating_by_contribution_point.ts +0 -31
- package/for_buildStarterProfile/when_checking_against_the_shared_fixture_corpus.ts +0 -32
- package/for_computeSizeClass/when_computing_the_size_class.ts +0 -23
- package/for_evaluateFlowArrangement/when_evaluating_against_the_shared_fixture_corpus.ts +0 -67
- package/for_evaluateFreeformArrangement/when_evaluating_against_the_shared_fixture_corpus.ts +0 -68
- package/for_evaluateFreeformSlotArrangement/when_evaluating_against_the_shared_fixture_corpus.ts +0 -47
- package/for_incompatibleStarterThemes/when_checking_against_the_shared_fixture_corpus.ts +0 -34
- package/for_packageCatalog/when_querying_against_the_shared_fixture_corpus.ts +0 -26
- package/for_packageDependencies/fixtures.ts +0 -44
- package/for_packageDependencies/when_resolving_against_the_shared_fixture_corpus.ts +0 -39
- package/for_packageVersionRange/when_checking_against_the_shared_fixture_corpus.ts +0 -13
- package/for_panelKind/when_telling_the_panels_apart.ts +0 -47
- package/for_renderElement/when_rendering_a_mixed_tree.ts +0 -58
- package/for_resolveBehaviors/when_resolving_additive_attachments.ts +0 -100
- package/for_resolveComponentName/when_resolving_against_the_shared_fixture_corpus.ts +0 -36
- package/for_resolveScreenTemplates/when_resolving_against_the_shared_fixture_corpus.ts +0 -49
- package/for_runActions/given/a_recording_dispatcher.ts +0 -72
- package/for_runActions/when_running_a_sequence_of_actions.ts +0 -226
- package/for_runActions/when_running_against_the_shared_fixture_corpus.ts +0 -124
- package/for_themeCompatibility/when_checking_against_the_shared_fixture_corpus.ts +0 -37
package/dist/cjs/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var buildStarterProfile = require('./buildStarterProfile.js');
|
|
|
20
20
|
var incompatibleStarterThemes = require('./incompatibleStarterThemes.js');
|
|
21
21
|
var runActions = require('./runActions.js');
|
|
22
22
|
var resolveBehaviors = require('./resolveBehaviors.js');
|
|
23
|
+
var resolveStrings = require('./resolveStrings.js');
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
|
|
@@ -71,4 +72,7 @@ exports.resolveApplicationTriggerBehaviors = resolveBehaviors.resolveApplication
|
|
|
71
72
|
exports.resolveBehaviors = resolveBehaviors.resolveBehaviors;
|
|
72
73
|
exports.resolveEventBehaviors = resolveBehaviors.resolveEventBehaviors;
|
|
73
74
|
exports.resolveIntervalBehaviors = resolveBehaviors.resolveIntervalBehaviors;
|
|
75
|
+
exports.isStringsReference = resolveStrings.isStringsReference;
|
|
76
|
+
exports.resolveStringsInElement = resolveStrings.resolveStringsInElement;
|
|
77
|
+
exports.resolveStringsValue = resolveStrings.resolveStringsValue;
|
|
74
78
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var elementKind = require('./elementKind.js');
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
6
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
7
|
+
const referencePrefix = '$strings.';
|
|
8
|
+
/**
|
|
9
|
+
* Whether a property value is a `$strings.<key>` reference rather than a literal value.
|
|
10
|
+
*
|
|
11
|
+
* A document prints `$strings.<key>` unquoted - see Screenplay's internationalization documentation - so
|
|
12
|
+
* the reference survives into a compiled element's properties as this exact string shape, indistinguishable
|
|
13
|
+
* from any other string property until something resolves it.
|
|
14
|
+
*/ function isStringsReference(value) {
|
|
15
|
+
return typeof value === 'string' && value.startsWith(referencePrefix);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolves a single property value against a locale's dictionary.
|
|
19
|
+
*
|
|
20
|
+
* A value that is not a `$strings.` reference passes through unchanged - resolving is a no-op on anything
|
|
21
|
+
* else a screen might put in the same property. A reference whose key is missing from the dictionary is
|
|
22
|
+
* left as the literal `$strings.<key>` text rather than blanked out - the same failure mode the frontend
|
|
23
|
+
* already had before resolution existed, and one an author notices immediately rather than a silently
|
|
24
|
+
* empty label.
|
|
25
|
+
*/ function resolveStringsValue(value, dictionary) {
|
|
26
|
+
if (!isStringsReference(value)) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
const key = value.slice(referencePrefix.length);
|
|
30
|
+
return Object.hasOwn(dictionary, key) ? dictionary[key] : value;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolves every `$strings.` reference in an element tree's `properties` against a locale's dictionary,
|
|
34
|
+
* returning a new tree - the input is never mutated, so a caller holding the original (a cached scene,
|
|
35
|
+
* a Studio design-time fixture) keeps seeing the unresolved symbolic form.
|
|
36
|
+
*
|
|
37
|
+
* Walks every shape an element tree actually nests content in: an `ExternalComponent`'s named `slots`, a
|
|
38
|
+
* `ContentControl`'s single `content`, an `ItemsControl`'s `itemTemplate`, and a `Panel`'s `children`. This
|
|
39
|
+
* is the same set {@link isExternalComponent}/{@link isContentControl}/{@link isItemsControl}/{@link isPanel}
|
|
40
|
+
* already distinguish elsewhere in this package, so a new element kind that starts nesting content a new
|
|
41
|
+
* way needs a matching type guard there before it can be walked here too.
|
|
42
|
+
*/ function resolveStringsInElement(element, dictionary) {
|
|
43
|
+
const properties = Object.fromEntries(Object.entries(element.properties ?? {}).map(([key, value])=>[
|
|
44
|
+
key,
|
|
45
|
+
resolveStringsValue(value, dictionary)
|
|
46
|
+
]));
|
|
47
|
+
const resolved = {
|
|
48
|
+
...element,
|
|
49
|
+
properties
|
|
50
|
+
};
|
|
51
|
+
if (elementKind.isExternalComponent(resolved)) {
|
|
52
|
+
resolved.slots = Object.fromEntries(Object.entries(resolved.slots ?? {}).map(([slotName, children])=>[
|
|
53
|
+
slotName,
|
|
54
|
+
children.map((child)=>resolveStringsInElement(child, dictionary))
|
|
55
|
+
]));
|
|
56
|
+
}
|
|
57
|
+
if (elementKind.isContentControl(resolved) && resolved.content) {
|
|
58
|
+
resolved.content = resolveStringsInElement(resolved.content, dictionary);
|
|
59
|
+
}
|
|
60
|
+
if (elementKind.isItemsControl(resolved) && resolved.itemTemplate) {
|
|
61
|
+
resolved.itemTemplate = resolveStringsInElement(resolved.itemTemplate, dictionary);
|
|
62
|
+
}
|
|
63
|
+
if (elementKind.isPanel(resolved)) {
|
|
64
|
+
resolved.children = resolved.children.map((child)=>resolveStringsInElement(child, dictionary));
|
|
65
|
+
}
|
|
66
|
+
return resolved;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.isStringsReference = isStringsReference;
|
|
70
|
+
exports.resolveStringsInElement = resolveStringsInElement;
|
|
71
|
+
exports.resolveStringsValue = resolveStringsValue;
|
|
72
|
+
//# sourceMappingURL=resolveStrings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStrings.js","sources":["../../resolveStrings.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneElement } from '@cratis/scene.model';\nimport { isContentControl, isExternalComponent, isItemsControl, isPanel } from './elementKind';\n\n/**\n * A locale's flat key -> value table, as `.strings` files parse to: dotted keys such as `invoice.title`\n * mapped to their localized text.\n */\nexport type StringsDictionary = Record<string, string>;\n\nconst referencePrefix = '$strings.';\n\n/**\n * Whether a property value is a `$strings.<key>` reference rather than a literal value.\n *\n * A document prints `$strings.<key>` unquoted - see Screenplay's internationalization documentation - so\n * the reference survives into a compiled element's properties as this exact string shape, indistinguishable\n * from any other string property until something resolves it.\n */\nexport function isStringsReference(value: unknown): value is string {\n return typeof value === 'string' && value.startsWith(referencePrefix);\n}\n\n/**\n * Resolves a single property value against a locale's dictionary.\n *\n * A value that is not a `$strings.` reference passes through unchanged - resolving is a no-op on anything\n * else a screen might put in the same property. A reference whose key is missing from the dictionary is\n * left as the literal `$strings.<key>` text rather than blanked out - the same failure mode the frontend\n * already had before resolution existed, and one an author notices immediately rather than a silently\n * empty label.\n */\nexport function resolveStringsValue(value: unknown, dictionary: StringsDictionary): unknown {\n if (!isStringsReference(value)) {\n return value;\n }\n\n const key = value.slice(referencePrefix.length);\n return Object.hasOwn(dictionary, key) ? dictionary[key] : value;\n}\n\n/**\n * Resolves every `$strings.` reference in an element tree's `properties` against a locale's dictionary,\n * returning a new tree - the input is never mutated, so a caller holding the original (a cached scene,\n * a Studio design-time fixture) keeps seeing the unresolved symbolic form.\n *\n * Walks every shape an element tree actually nests content in: an `ExternalComponent`'s named `slots`, a\n * `ContentControl`'s single `content`, an `ItemsControl`'s `itemTemplate`, and a `Panel`'s `children`. This\n * is the same set {@link isExternalComponent}/{@link isContentControl}/{@link isItemsControl}/{@link isPanel}\n * already distinguish elsewhere in this package, so a new element kind that starts nesting content a new\n * way needs a matching type guard there before it can be walked here too.\n */\nexport function resolveStringsInElement(element: SceneElement, dictionary: StringsDictionary): SceneElement {\n const properties = Object.fromEntries(\n Object.entries(element.properties ?? {}).map(([key, value]) => [key, resolveStringsValue(value, dictionary)]),\n );\n\n const resolved: SceneElement = { ...element, properties };\n\n if (isExternalComponent(resolved)) {\n resolved.slots = Object.fromEntries(\n Object.entries(resolved.slots ?? {}).map(([slotName, children]) => [\n slotName,\n children.map(child => resolveStringsInElement(child, dictionary)),\n ]),\n );\n }\n\n if (isContentControl(resolved) && resolved.content) {\n resolved.content = resolveStringsInElement(resolved.content, dictionary);\n }\n\n if (isItemsControl(resolved) && resolved.itemTemplate) {\n resolved.itemTemplate = resolveStringsInElement(resolved.itemTemplate, dictionary);\n }\n\n if (isPanel(resolved)) {\n resolved.children = resolved.children.map(child => resolveStringsInElement(child, dictionary));\n }\n\n return resolved;\n}\n"],"names":["referencePrefix","isStringsReference","value","startsWith","resolveStringsValue","dictionary","key","slice","length","Object","hasOwn","resolveStringsInElement","element","properties","fromEntries","entries","map","resolved","isExternalComponent","slots","slotName","children","child","isContentControl","content","isItemsControl","itemTemplate","isPanel"],"mappings":";;;;AAAA;AACA;AAWA,MAAMA,eAAAA,GAAkB,WAAA;AAExB;;;;;;IAOO,SAASC,kBAAAA,CAAmBC,KAAc,EAAA;AAC7C,IAAA,OAAO,OAAOA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,CAAMC,UAAU,CAACH,eAAAA,CAAAA;AACzD;AAEA;;;;;;;;AAQC,IACM,SAASI,mBAAAA,CAAoBF,KAAc,EAAEG,UAA6B,EAAA;IAC7E,IAAI,CAACJ,mBAAmBC,KAAAA,CAAAA,EAAQ;QAC5B,OAAOA,KAAAA;AACX,IAAA;AAEA,IAAA,MAAMI,GAAAA,GAAMJ,KAAAA,CAAMK,KAAK,CAACP,gBAAgBQ,MAAM,CAAA;IAC9C,OAAOC,MAAAA,CAAOC,MAAM,CAACL,UAAAA,EAAYC,OAAOD,UAAU,CAACC,IAAI,GAAGJ,KAAAA;AAC9D;AAEA;;;;;;;;;;AAUC,IACM,SAASS,uBAAAA,CAAwBC,OAAqB,EAAEP,UAA6B,EAAA;AACxF,IAAA,MAAMQ,aAAaJ,MAAAA,CAAOK,WAAW,CACjCL,MAAAA,CAAOM,OAAO,CAACH,OAAAA,CAAQC,UAAU,IAAI,IAAIG,GAAG,CAAC,CAAC,CAACV,GAAAA,EAAKJ,MAAM,GAAK;AAACI,YAAAA,GAAAA;AAAKF,YAAAA,mBAAAA,CAAoBF,KAAAA,EAAOG,UAAAA;AAAY,SAAA,CAAA,CAAA;AAGhH,IAAA,MAAMY,QAAAA,GAAyB;AAAE,QAAA,GAAGL,OAAO;AAAEC,QAAAA;AAAW,KAAA;AAExD,IAAA,IAAIK,gCAAoBD,QAAAA,CAAAA,EAAW;AAC/BA,QAAAA,QAAAA,CAASE,KAAK,GAAGV,MAAAA,CAAOK,WAAW,CAC/BL,MAAAA,CAAOM,OAAO,CAACE,QAAAA,CAASE,KAAK,IAAI,IAAIH,GAAG,CAAC,CAAC,CAACI,QAAAA,EAAUC,SAAS,GAAK;AAC/DD,gBAAAA,QAAAA;AACAC,gBAAAA,QAAAA,CAASL,GAAG,CAACM,CAAAA,KAAAA,GAASX,wBAAwBW,KAAAA,EAAOjB,UAAAA,CAAAA;AACxD,aAAA,CAAA,CAAA;AAET,IAAA;AAEA,IAAA,IAAIkB,4BAAAA,CAAiBN,QAAAA,CAAAA,IAAaA,QAAAA,CAASO,OAAO,EAAE;AAChDP,QAAAA,QAAAA,CAASO,OAAO,GAAGb,uBAAAA,CAAwBM,QAAAA,CAASO,OAAO,EAAEnB,UAAAA,CAAAA;AACjE,IAAA;AAEA,IAAA,IAAIoB,0BAAAA,CAAeR,QAAAA,CAAAA,IAAaA,QAAAA,CAASS,YAAY,EAAE;AACnDT,QAAAA,QAAAA,CAASS,YAAY,GAAGf,uBAAAA,CAAwBM,QAAAA,CAASS,YAAY,EAAErB,UAAAA,CAAAA;AAC3E,IAAA;AAEA,IAAA,IAAIsB,oBAAQV,QAAAA,CAAAA,EAAW;QACnBA,QAAAA,CAASI,QAAQ,GAAGJ,QAAAA,CAASI,QAAQ,CAACL,GAAG,CAACM,CAAAA,KAAAA,GAASX,uBAAAA,CAAwBW,KAAAA,EAAOjB,UAAAA,CAAAA,CAAAA;AACtF,IAAA;IAEA,OAAOY,QAAAA;AACX;;;;"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CA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+18,5 @@ export { buildStarterProfile } from './buildStarterProfile.js';
|
|
|
18
18
|
export { incompatibleStarterThemes } from './incompatibleStarterThemes.js';
|
|
19
19
|
export { InteractionStop, runActions, runBindings } from './runActions.js';
|
|
20
20
|
export { resolveApplicationTriggerBehaviors, resolveBehaviors, resolveEventBehaviors, resolveIntervalBehaviors } from './resolveBehaviors.js';
|
|
21
|
+
export { isStringsReference, resolveStringsInElement, resolveStringsValue } from './resolveStrings.js';
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SceneElement } from '@cratis/scene.model';
|
|
2
|
+
export type StringsDictionary = Record<string, string>;
|
|
3
|
+
export declare function isStringsReference(value: unknown): value is string;
|
|
4
|
+
export declare function resolveStringsValue(value: unknown, dictionary: StringsDictionary): unknown;
|
|
5
|
+
export declare function resolveStringsInElement(element: SceneElement, dictionary: StringsDictionary): SceneElement;
|
|
6
|
+
//# sourceMappingURL=resolveStrings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStrings.d.ts","sourceRoot":"","sources":["../../resolveStrings.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOnD,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAWvD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAElE;AAWD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAO1F;AAaD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,GAAG,YAAY,CA6B1G"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isExternalComponent, isContentControl, isItemsControl, isPanel } from './elementKind.js';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
const referencePrefix = '$strings.';
|
|
6
|
+
/**
|
|
7
|
+
* Whether a property value is a `$strings.<key>` reference rather than a literal value.
|
|
8
|
+
*
|
|
9
|
+
* A document prints `$strings.<key>` unquoted - see Screenplay's internationalization documentation - so
|
|
10
|
+
* the reference survives into a compiled element's properties as this exact string shape, indistinguishable
|
|
11
|
+
* from any other string property until something resolves it.
|
|
12
|
+
*/ function isStringsReference(value) {
|
|
13
|
+
return typeof value === 'string' && value.startsWith(referencePrefix);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a single property value against a locale's dictionary.
|
|
17
|
+
*
|
|
18
|
+
* A value that is not a `$strings.` reference passes through unchanged - resolving is a no-op on anything
|
|
19
|
+
* else a screen might put in the same property. A reference whose key is missing from the dictionary is
|
|
20
|
+
* left as the literal `$strings.<key>` text rather than blanked out - the same failure mode the frontend
|
|
21
|
+
* already had before resolution existed, and one an author notices immediately rather than a silently
|
|
22
|
+
* empty label.
|
|
23
|
+
*/ function resolveStringsValue(value, dictionary) {
|
|
24
|
+
if (!isStringsReference(value)) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
const key = value.slice(referencePrefix.length);
|
|
28
|
+
return Object.hasOwn(dictionary, key) ? dictionary[key] : value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves every `$strings.` reference in an element tree's `properties` against a locale's dictionary,
|
|
32
|
+
* returning a new tree - the input is never mutated, so a caller holding the original (a cached scene,
|
|
33
|
+
* a Studio design-time fixture) keeps seeing the unresolved symbolic form.
|
|
34
|
+
*
|
|
35
|
+
* Walks every shape an element tree actually nests content in: an `ExternalComponent`'s named `slots`, a
|
|
36
|
+
* `ContentControl`'s single `content`, an `ItemsControl`'s `itemTemplate`, and a `Panel`'s `children`. This
|
|
37
|
+
* is the same set {@link isExternalComponent}/{@link isContentControl}/{@link isItemsControl}/{@link isPanel}
|
|
38
|
+
* already distinguish elsewhere in this package, so a new element kind that starts nesting content a new
|
|
39
|
+
* way needs a matching type guard there before it can be walked here too.
|
|
40
|
+
*/ function resolveStringsInElement(element, dictionary) {
|
|
41
|
+
const properties = Object.fromEntries(Object.entries(element.properties ?? {}).map(([key, value])=>[
|
|
42
|
+
key,
|
|
43
|
+
resolveStringsValue(value, dictionary)
|
|
44
|
+
]));
|
|
45
|
+
const resolved = {
|
|
46
|
+
...element,
|
|
47
|
+
properties
|
|
48
|
+
};
|
|
49
|
+
if (isExternalComponent(resolved)) {
|
|
50
|
+
resolved.slots = Object.fromEntries(Object.entries(resolved.slots ?? {}).map(([slotName, children])=>[
|
|
51
|
+
slotName,
|
|
52
|
+
children.map((child)=>resolveStringsInElement(child, dictionary))
|
|
53
|
+
]));
|
|
54
|
+
}
|
|
55
|
+
if (isContentControl(resolved) && resolved.content) {
|
|
56
|
+
resolved.content = resolveStringsInElement(resolved.content, dictionary);
|
|
57
|
+
}
|
|
58
|
+
if (isItemsControl(resolved) && resolved.itemTemplate) {
|
|
59
|
+
resolved.itemTemplate = resolveStringsInElement(resolved.itemTemplate, dictionary);
|
|
60
|
+
}
|
|
61
|
+
if (isPanel(resolved)) {
|
|
62
|
+
resolved.children = resolved.children.map((child)=>resolveStringsInElement(child, dictionary));
|
|
63
|
+
}
|
|
64
|
+
return resolved;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { isStringsReference, resolveStringsInElement, resolveStringsValue };
|
|
68
|
+
//# sourceMappingURL=resolveStrings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStrings.js","sources":["../../resolveStrings.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneElement } from '@cratis/scene.model';\nimport { isContentControl, isExternalComponent, isItemsControl, isPanel } from './elementKind';\n\n/**\n * A locale's flat key -> value table, as `.strings` files parse to: dotted keys such as `invoice.title`\n * mapped to their localized text.\n */\nexport type StringsDictionary = Record<string, string>;\n\nconst referencePrefix = '$strings.';\n\n/**\n * Whether a property value is a `$strings.<key>` reference rather than a literal value.\n *\n * A document prints `$strings.<key>` unquoted - see Screenplay's internationalization documentation - so\n * the reference survives into a compiled element's properties as this exact string shape, indistinguishable\n * from any other string property until something resolves it.\n */\nexport function isStringsReference(value: unknown): value is string {\n return typeof value === 'string' && value.startsWith(referencePrefix);\n}\n\n/**\n * Resolves a single property value against a locale's dictionary.\n *\n * A value that is not a `$strings.` reference passes through unchanged - resolving is a no-op on anything\n * else a screen might put in the same property. A reference whose key is missing from the dictionary is\n * left as the literal `$strings.<key>` text rather than blanked out - the same failure mode the frontend\n * already had before resolution existed, and one an author notices immediately rather than a silently\n * empty label.\n */\nexport function resolveStringsValue(value: unknown, dictionary: StringsDictionary): unknown {\n if (!isStringsReference(value)) {\n return value;\n }\n\n const key = value.slice(referencePrefix.length);\n return Object.hasOwn(dictionary, key) ? dictionary[key] : value;\n}\n\n/**\n * Resolves every `$strings.` reference in an element tree's `properties` against a locale's dictionary,\n * returning a new tree - the input is never mutated, so a caller holding the original (a cached scene,\n * a Studio design-time fixture) keeps seeing the unresolved symbolic form.\n *\n * Walks every shape an element tree actually nests content in: an `ExternalComponent`'s named `slots`, a\n * `ContentControl`'s single `content`, an `ItemsControl`'s `itemTemplate`, and a `Panel`'s `children`. This\n * is the same set {@link isExternalComponent}/{@link isContentControl}/{@link isItemsControl}/{@link isPanel}\n * already distinguish elsewhere in this package, so a new element kind that starts nesting content a new\n * way needs a matching type guard there before it can be walked here too.\n */\nexport function resolveStringsInElement(element: SceneElement, dictionary: StringsDictionary): SceneElement {\n const properties = Object.fromEntries(\n Object.entries(element.properties ?? {}).map(([key, value]) => [key, resolveStringsValue(value, dictionary)]),\n );\n\n const resolved: SceneElement = { ...element, properties };\n\n if (isExternalComponent(resolved)) {\n resolved.slots = Object.fromEntries(\n Object.entries(resolved.slots ?? {}).map(([slotName, children]) => [\n slotName,\n children.map(child => resolveStringsInElement(child, dictionary)),\n ]),\n );\n }\n\n if (isContentControl(resolved) && resolved.content) {\n resolved.content = resolveStringsInElement(resolved.content, dictionary);\n }\n\n if (isItemsControl(resolved) && resolved.itemTemplate) {\n resolved.itemTemplate = resolveStringsInElement(resolved.itemTemplate, dictionary);\n }\n\n if (isPanel(resolved)) {\n resolved.children = resolved.children.map(child => resolveStringsInElement(child, dictionary));\n }\n\n return resolved;\n}\n"],"names":["referencePrefix","isStringsReference","value","startsWith","resolveStringsValue","dictionary","key","slice","length","Object","hasOwn","resolveStringsInElement","element","properties","fromEntries","entries","map","resolved","isExternalComponent","slots","slotName","children","child","isContentControl","content","isItemsControl","itemTemplate","isPanel"],"mappings":";;AAAA;AACA;AAWA,MAAMA,eAAAA,GAAkB,WAAA;AAExB;;;;;;IAOO,SAASC,kBAAAA,CAAmBC,KAAc,EAAA;AAC7C,IAAA,OAAO,OAAOA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,CAAMC,UAAU,CAACH,eAAAA,CAAAA;AACzD;AAEA;;;;;;;;AAQC,IACM,SAASI,mBAAAA,CAAoBF,KAAc,EAAEG,UAA6B,EAAA;IAC7E,IAAI,CAACJ,mBAAmBC,KAAAA,CAAAA,EAAQ;QAC5B,OAAOA,KAAAA;AACX,IAAA;AAEA,IAAA,MAAMI,GAAAA,GAAMJ,KAAAA,CAAMK,KAAK,CAACP,gBAAgBQ,MAAM,CAAA;IAC9C,OAAOC,MAAAA,CAAOC,MAAM,CAACL,UAAAA,EAAYC,OAAOD,UAAU,CAACC,IAAI,GAAGJ,KAAAA;AAC9D;AAEA;;;;;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