@teleporthq/teleport-plugin-common 0.45.3-alpha.0 → 0.45.13
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/__tests__/builders/html-builders.ts +9 -2
- package/__tests__/builders/style-builders.ts +135 -1
- package/__tests__/node-handlers/node-to-html/index.ts +2 -0
- package/__tests__/node-handlers/node-to-jsx/attribute-value-mapper.ts +77 -0
- package/__tests__/node-handlers/node-to-jsx/calendar-events-reviver.ts +176 -0
- package/__tests__/node-handlers/node-to-jsx/chart-data-guard.ts +101 -0
- package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-ecommerce-source.ts +79 -0
- package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-loading.ts +122 -0
- package/__tests__/node-handlers/node-to-jsx/index.ts +719 -3
- package/__tests__/node-handlers/node-to-jsx/url-search-params-expression.ts +59 -0
- package/__tests__/node-handlers/node-to-jsx/utils.ts +635 -3
- package/__tests__/utils/ast-utils.ts +188 -0
- package/__tests__/utils/content-property-sanitiser.ts +156 -0
- package/__tests__/utils/page-seeds-state-from-data-source.ts +70 -0
- package/__tests__/utils/parse-string-with-template-expressions.ts +82 -0
- package/__tests__/utils/resource-auth-scheme.ts +55 -0
- package/__tests__/utils/route-utils.ts +118 -0
- package/__tests__/utils/style-utils.ts +59 -0
- package/__tests__/utils/template-expression-balance.ts +83 -0
- package/__tests__/utils/url-query-writer.ts +239 -0
- package/__tests__/utils/url-search-param-sync.ts +138 -0
- package/__tests__/utils/url-search-params.ts +48 -0
- package/dist/cjs/builders/ast-builders.d.ts +2 -0
- package/dist/cjs/builders/ast-builders.d.ts.map +1 -1
- package/dist/cjs/builders/ast-builders.js +41 -3
- package/dist/cjs/builders/ast-builders.js.map +1 -1
- package/dist/cjs/builders/hast-builders.d.ts +1 -0
- package/dist/cjs/builders/hast-builders.d.ts.map +1 -1
- package/dist/cjs/builders/hast-builders.js +11 -1
- package/dist/cjs/builders/hast-builders.js.map +1 -1
- package/dist/cjs/builders/style-builders.d.ts +8 -2
- package/dist/cjs/builders/style-builders.d.ts.map +1 -1
- package/dist/cjs/builders/style-builders.js +80 -33
- package/dist/cjs/builders/style-builders.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/constants.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/constants.js +2 -0
- package/dist/cjs/node-handlers/node-to-html/constants.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/index.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/index.js +69 -1
- package/dist/cjs/node-handlers/node-to-html/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/types.d.ts +5 -1
- package/dist/cjs/node-handlers/node-to-html/types.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/utils.d.ts +2 -1
- package/dist/cjs/node-handlers/node-to-html/utils.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/utils.js +174 -13
- package/dist/cjs/node-handlers/node-to-html/utils.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/index.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/index.js +1443 -45
- package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/types.d.ts +60 -6
- package/dist/cjs/node-handlers/node-to-jsx/types.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts +80 -7
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.js +883 -72
- package/dist/cjs/node-handlers/node-to-jsx/utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils/ast-utils.d.ts +163 -11
- package/dist/cjs/utils/ast-utils.d.ts.map +1 -1
- package/dist/cjs/utils/ast-utils.js +1013 -75
- package/dist/cjs/utils/ast-utils.js.map +1 -1
- package/dist/cjs/utils/hast-utils.d.ts +8 -6
- package/dist/cjs/utils/hast-utils.d.ts.map +1 -1
- package/dist/cjs/utils/hast-utils.js +28 -4
- package/dist/cjs/utils/hast-utils.js.map +1 -1
- package/dist/cjs/utils/nested-selector-commas.d.ts +2 -0
- package/dist/cjs/utils/nested-selector-commas.d.ts.map +1 -0
- package/dist/cjs/utils/nested-selector-commas.js +81 -0
- package/dist/cjs/utils/nested-selector-commas.js.map +1 -0
- package/dist/cjs/utils/route-utils.d.ts +117 -0
- package/dist/cjs/utils/route-utils.d.ts.map +1 -0
- package/dist/cjs/utils/route-utils.js +212 -0
- package/dist/cjs/utils/route-utils.js.map +1 -0
- package/dist/cjs/utils/style-utils.d.ts +1 -0
- package/dist/cjs/utils/style-utils.d.ts.map +1 -1
- package/dist/cjs/utils/style-utils.js +181 -2
- package/dist/cjs/utils/style-utils.js.map +1 -1
- package/dist/cjs/utils/template-expression-balance.d.ts +58 -0
- package/dist/cjs/utils/template-expression-balance.d.ts.map +1 -0
- package/dist/cjs/utils/template-expression-balance.js +181 -0
- package/dist/cjs/utils/template-expression-balance.js.map +1 -0
- package/dist/cjs/utils/types.d.ts +3 -0
- package/dist/cjs/utils/types.d.ts.map +1 -0
- package/dist/cjs/utils/types.js +3 -0
- package/dist/cjs/utils/types.js.map +1 -0
- package/dist/cjs/utils/url-query-writer.d.ts +123 -0
- package/dist/cjs/utils/url-query-writer.d.ts.map +1 -0
- package/dist/cjs/utils/url-query-writer.js +260 -0
- package/dist/cjs/utils/url-query-writer.js.map +1 -0
- package/dist/cjs/utils/url-search-param-sync.d.ts +4 -0
- package/dist/cjs/utils/url-search-param-sync.d.ts.map +1 -0
- package/dist/cjs/utils/url-search-param-sync.js +241 -0
- package/dist/cjs/utils/url-search-param-sync.js.map +1 -0
- package/dist/cjs/utils/url-search-params.d.ts +48 -0
- package/dist/cjs/utils/url-search-params.d.ts.map +1 -0
- package/dist/cjs/utils/url-search-params.js +109 -0
- package/dist/cjs/utils/url-search-params.js.map +1 -0
- package/dist/esm/builders/ast-builders.d.ts +2 -0
- package/dist/esm/builders/ast-builders.d.ts.map +1 -1
- package/dist/esm/builders/ast-builders.js +40 -4
- package/dist/esm/builders/ast-builders.js.map +1 -1
- package/dist/esm/builders/hast-builders.d.ts +1 -0
- package/dist/esm/builders/hast-builders.d.ts.map +1 -1
- package/dist/esm/builders/hast-builders.js +9 -0
- package/dist/esm/builders/hast-builders.js.map +1 -1
- package/dist/esm/builders/style-builders.d.ts +8 -2
- package/dist/esm/builders/style-builders.d.ts.map +1 -1
- package/dist/esm/builders/style-builders.js +78 -32
- package/dist/esm/builders/style-builders.js.map +1 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/constants.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/constants.js +2 -0
- package/dist/esm/node-handlers/node-to-html/constants.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/index.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/index.js +71 -3
- package/dist/esm/node-handlers/node-to-html/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/types.d.ts +5 -1
- package/dist/esm/node-handlers/node-to-html/types.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/utils.d.ts +2 -1
- package/dist/esm/node-handlers/node-to-html/utils.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/utils.js +170 -13
- package/dist/esm/node-handlers/node-to-html/utils.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.js +1442 -47
- package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/types.d.ts +60 -6
- package/dist/esm/node-handlers/node-to-jsx/types.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts +80 -7
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.js +875 -70
- package/dist/esm/node-handlers/node-to-jsx/utils.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/ast-utils.d.ts +163 -11
- package/dist/esm/utils/ast-utils.d.ts.map +1 -1
- package/dist/esm/utils/ast-utils.js +989 -75
- package/dist/esm/utils/ast-utils.js.map +1 -1
- package/dist/esm/utils/hast-utils.d.ts +8 -6
- package/dist/esm/utils/hast-utils.d.ts.map +1 -1
- package/dist/esm/utils/hast-utils.js +26 -3
- package/dist/esm/utils/hast-utils.js.map +1 -1
- package/dist/esm/utils/nested-selector-commas.d.ts +2 -0
- package/dist/esm/utils/nested-selector-commas.d.ts.map +1 -0
- package/dist/esm/utils/nested-selector-commas.js +77 -0
- package/dist/esm/utils/nested-selector-commas.js.map +1 -0
- package/dist/esm/utils/route-utils.d.ts +117 -0
- package/dist/esm/utils/route-utils.d.ts.map +1 -0
- package/dist/esm/utils/route-utils.js +179 -0
- package/dist/esm/utils/route-utils.js.map +1 -0
- package/dist/esm/utils/style-utils.d.ts +1 -0
- package/dist/esm/utils/style-utils.d.ts.map +1 -1
- package/dist/esm/utils/style-utils.js +179 -1
- package/dist/esm/utils/style-utils.js.map +1 -1
- package/dist/esm/utils/template-expression-balance.d.ts +58 -0
- package/dist/esm/utils/template-expression-balance.d.ts.map +1 -0
- package/dist/esm/utils/template-expression-balance.js +174 -0
- package/dist/esm/utils/template-expression-balance.js.map +1 -0
- package/dist/esm/utils/types.d.ts +3 -0
- package/dist/esm/utils/types.d.ts.map +1 -0
- package/dist/esm/utils/types.js +2 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/utils/url-query-writer.d.ts +123 -0
- package/dist/esm/utils/url-query-writer.d.ts.map +1 -0
- package/dist/esm/utils/url-query-writer.js +229 -0
- package/dist/esm/utils/url-query-writer.js.map +1 -0
- package/dist/esm/utils/url-search-param-sync.d.ts +4 -0
- package/dist/esm/utils/url-search-param-sync.d.ts.map +1 -0
- package/dist/esm/utils/url-search-param-sync.js +213 -0
- package/dist/esm/utils/url-search-param-sync.js.map +1 -0
- package/dist/esm/utils/url-search-params.d.ts +48 -0
- package/dist/esm/utils/url-search-params.d.ts.map +1 -0
- package/dist/esm/utils/url-search-params.js +81 -0
- package/dist/esm/utils/url-search-params.js.map +1 -0
- package/package.json +4 -4
- package/src/builders/ast-builders.ts +80 -3
- package/src/builders/hast-builders.ts +11 -0
- package/src/builders/style-builders.ts +121 -43
- package/src/index.ts +22 -1
- package/src/node-handlers/node-to-html/constants.ts +2 -0
- package/src/node-handlers/node-to-html/index.ts +126 -6
- package/src/node-handlers/node-to-html/types.ts +6 -0
- package/src/node-handlers/node-to-html/utils.ts +228 -14
- package/src/node-handlers/node-to-jsx/index.ts +2135 -62
- package/src/node-handlers/node-to-jsx/types.ts +75 -32
- package/src/node-handlers/node-to-jsx/utils.ts +1173 -84
- package/src/utils/ast-utils.ts +1316 -127
- package/src/utils/hast-utils.ts +37 -9
- package/src/utils/nested-selector-commas.ts +88 -0
- package/src/utils/route-utils.ts +214 -0
- package/src/utils/style-utils.ts +183 -1
- package/src/utils/template-expression-balance.ts +196 -0
- package/src/utils/types.ts +25 -0
- package/src/utils/url-query-writer.ts +318 -0
- package/src/utils/url-search-param-sync.ts +303 -0
- package/src/utils/url-search-params.ts +122 -0
|
@@ -33,6 +33,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
33
|
__setModuleDefault(result, mod);
|
|
34
34
|
return result;
|
|
35
35
|
};
|
|
36
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
37
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
38
|
+
if (ar || !(i in from)) {
|
|
39
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
40
|
+
ar[i] = from[i];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
44
|
+
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
36
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
49
|
var types = __importStar(require("@babel/types"));
|
|
38
50
|
var teleport_shared_1 = require("@teleporthq/teleport-shared");
|
|
@@ -41,12 +53,531 @@ var ast_utils_1 = require("../../utils/ast-utils");
|
|
|
41
53
|
var ast_builders_1 = require("../../builders/ast-builders");
|
|
42
54
|
var constants_1 = require("./constants");
|
|
43
55
|
var __1 = require("../..");
|
|
56
|
+
var parsed_ast_1 = __importDefault(require("../../utils/parsed-ast"));
|
|
57
|
+
// Runtime predicate that drops a DataProvider filter whose destination
|
|
58
|
+
// resolves to an empty value: `''` / `null` / `undefined`, or an empty
|
|
59
|
+
// array-overlap set (`[]` / `['']`). Selecting a "show all" reset must mean
|
|
60
|
+
// "no filter", not a query that matches zero rows. Kept in sync with the
|
|
61
|
+
// Next.js pages plugin's `buildNonEmptyDestinationPredicate` (duplicated here
|
|
62
|
+
// because teleport-plugin-common must not depend on teleport-plugin-next-data-source).
|
|
63
|
+
var buildNonEmptyFilterDestinationPredicate = function () {
|
|
64
|
+
var f = types.identifier('__f');
|
|
65
|
+
var dest = types.memberExpression(f, types.identifier('destination'));
|
|
66
|
+
var isEmptyArray = types.logicalExpression('&&', types.callExpression(types.memberExpression(types.identifier('Array'), types.identifier('isArray')), [dest]), types.binaryExpression('===', types.memberExpression(types.callExpression(types.memberExpression(dest, types.identifier('filter')), [
|
|
67
|
+
types.identifier('Boolean'),
|
|
68
|
+
]), types.identifier('length')), types.numericLiteral(0)));
|
|
69
|
+
return types.arrowFunctionExpression([f], types.logicalExpression('&&', types.logicalExpression('&&', types.logicalExpression('&&', types.binaryExpression('!==', dest, types.stringLiteral('')), types.binaryExpression('!==', dest, types.nullLiteral())), types.binaryExpression('!==', dest, types.identifier('undefined'))), types.unaryExpression('!', isEmptyArray)));
|
|
70
|
+
};
|
|
71
|
+
// Same idea one level up: a filter entry survives if it is a group that still
|
|
72
|
+
// has children, or a condition whose destination resolved to something real.
|
|
73
|
+
var buildSurvivingFilterNodePredicate = function () {
|
|
74
|
+
var f = types.identifier('__f');
|
|
75
|
+
var emptyDestination = buildNonEmptyFilterDestinationPredicate().body;
|
|
76
|
+
return types.arrowFunctionExpression([f], types.conditionalExpression(types.binaryExpression('===', types.memberExpression(f, types.identifier('type')), types.stringLiteral('group')), types.binaryExpression('>', types.memberExpression(types.memberExpression(f, types.identifier('children')), types.identifier('length')), types.numericLiteral(0)), emptyDestination));
|
|
77
|
+
};
|
|
78
|
+
// The inspector authors filters as a TREE — a root `and` group whose children
|
|
79
|
+
// are conditions or nested `or` groups. Emitting the tree (rather than mapping
|
|
80
|
+
// each entry as if it were a condition, which turned every group into an empty
|
|
81
|
+
// `{ source: '', destination: '', operand: '' }` row that the predicate then
|
|
82
|
+
// dropped) is what lets the data-source runtime honour the filter at all.
|
|
83
|
+
var buildFilterNodeExpression = function (entry, dynamicReferencePrefixMap) {
|
|
84
|
+
if (entry && entry.type === 'group' && Array.isArray(entry.children)) {
|
|
85
|
+
var childExpressions = entry.children.map(function (child) {
|
|
86
|
+
return buildFilterNodeExpression(child, dynamicReferencePrefixMap);
|
|
87
|
+
});
|
|
88
|
+
return types.objectExpression([
|
|
89
|
+
types.objectProperty(types.identifier('type'), types.stringLiteral('group')),
|
|
90
|
+
types.objectProperty(types.identifier('operator'), types.stringLiteral(entry.operator === 'or' ? 'or' : 'and')),
|
|
91
|
+
types.objectProperty(types.identifier('children'), types.callExpression(types.memberExpression(types.arrayExpression(childExpressions), types.identifier('filter')), [buildSurvivingFilterNodePredicate()])),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
return types.objectExpression([
|
|
95
|
+
types.objectProperty(types.identifier('type'), types.stringLiteral('condition')),
|
|
96
|
+
types.objectProperty(types.identifier('source'), types.stringLiteral((entry === null || entry === void 0 ? void 0 : entry.source) || '')),
|
|
97
|
+
types.objectProperty(types.identifier('destination'), __1.ASTUtils.convertFilterDestinationToExpression(entry === null || entry === void 0 ? void 0 : entry.destination, {
|
|
98
|
+
dynamicReferencePrefixMap: dynamicReferencePrefixMap,
|
|
99
|
+
})),
|
|
100
|
+
types.objectProperty(types.identifier('operand'), types.stringLiteral((entry === null || entry === void 0 ? void 0 : entry.operand) || '')),
|
|
101
|
+
]);
|
|
102
|
+
};
|
|
103
|
+
// Global references in the UIDL come in two shapes:
|
|
104
|
+
// Shape A: { id: "ecommerce", refPath: ["Cart", "total"] }
|
|
105
|
+
// Shape B: { id: undefined, refPath: ["E-commerce", "Settings", "Delivery", "..."] }
|
|
106
|
+
// This helper normalizes Shape B into Shape A so downstream code can handle
|
|
107
|
+
// both uniformly. The first refPath segment is mapped to a variable name via
|
|
108
|
+
// GLOBAL_REF_ID_MAP (exported from ast-utils so all sites stay in sync).
|
|
109
|
+
// Expression attributes (UIDLExpressionValue) bypass the dynamic-reference
|
|
110
|
+
// tracking in createDynamicValueExpression. When such an expression mentions
|
|
111
|
+
// a known global (currentUser/ecommerce/cart/locale/userIsLoggedIn) we still
|
|
112
|
+
// Plan v15 Layer 4 — junk-name attribute guard.
|
|
113
|
+
// AI fabrication artefacts emit attributes whose KEY is a JS literal
|
|
114
|
+
// (`true="true"`, `false="false"`, `0="x"`, `null="..."`). They survive JSX
|
|
115
|
+
// parsing (treated as string-valued attrs) but break DOM semantics. The
|
|
116
|
+
// upstream Layer 1–3 pipeline should already strip them; this is the final
|
|
117
|
+
// codegen safety net.
|
|
118
|
+
var CODEGEN_JUNK_ATTR_NAMES = new Set(['true', 'false', 'null', 'undefined']);
|
|
119
|
+
function isJunkAttributeName(name) {
|
|
120
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
var lower = name.toLowerCase();
|
|
124
|
+
if (CODEGEN_JUNK_ATTR_NAMES.has(lower)) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if (/^[0-9]+$/.test(name)) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
function hasCorruptBindingMarkers(value) {
|
|
133
|
+
// Entity-escaped `{` / `}` from upstream serialization that should never
|
|
134
|
+
// reach the JSX output verbatim.
|
|
135
|
+
if (/{|}/.test(value)) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
// Unbalanced `{{` (no matching `}}`).
|
|
139
|
+
var opens = (value.match(/\{\{/g) || []).length;
|
|
140
|
+
var closes = (value.match(/\}\}/g) || []).length;
|
|
141
|
+
if (opens > closes) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
function truncate(value) {
|
|
147
|
+
if (value.length <= 60) {
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
return value.slice(0, 57) + '...';
|
|
151
|
+
}
|
|
152
|
+
// need to push it into params.globalReferences so downstream plugins inject
|
|
153
|
+
// the corresponding `useGlobalContext()` destructuring.
|
|
154
|
+
var GLOBAL_EXPRESSION_IDENTIFIERS = [
|
|
155
|
+
{ pattern: /\bcurrentUser\b/, id: 'currentUser' },
|
|
156
|
+
{ pattern: /\buserIsLoggedIn\b/, id: 'userIsLoggedIn' },
|
|
157
|
+
{ pattern: /\becommerce\b/, id: 'ecommerce' },
|
|
158
|
+
{ pattern: /\bcart\b/, id: 'cart' },
|
|
159
|
+
{ pattern: /\blocales?\b/, id: 'locale' },
|
|
160
|
+
];
|
|
161
|
+
var trackGlobalRefsInExpression = function (expression, params) {
|
|
162
|
+
if (!expression) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
for (var _i = 0, GLOBAL_EXPRESSION_IDENTIFIERS_1 = GLOBAL_EXPRESSION_IDENTIFIERS; _i < GLOBAL_EXPRESSION_IDENTIFIERS_1.length; _i++) {
|
|
166
|
+
var _a = GLOBAL_EXPRESSION_IDENTIFIERS_1[_i], pattern = _a.pattern, id = _a.id;
|
|
167
|
+
if (pattern.test(expression)) {
|
|
168
|
+
params.globalReferences.push(id);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Global-state identifiers behave the same way: an expression-shaped UIDL
|
|
172
|
+
// attribute (e.g. cms-mixed-type `itemData`) bypasses the dynamic-ref
|
|
173
|
+
// pipeline that registers `useGlobalState()` destructuring, so we walk the
|
|
174
|
+
// raw expression text and re-attach any state name we recognise. The
|
|
175
|
+
// matched names are added to `globalStateReferences` and the
|
|
176
|
+
// next-global-state component plugin destructures them at codegen time.
|
|
177
|
+
var definitions = params.globalStateDefinitions;
|
|
178
|
+
if (!definitions || Object.keys(definitions).length === 0) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
for (var _b = 0, _c = Object.values(definitions); _b < _c.length; _b++) {
|
|
182
|
+
var def = _c[_b];
|
|
183
|
+
var name_1 = def === null || def === void 0 ? void 0 : def.name;
|
|
184
|
+
if (!name_1) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
var escaped = name_1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
188
|
+
if (new RegExp("\\b".concat(escaped, "\\b")).test(expression)) {
|
|
189
|
+
params.globalStateReferences.push({ id: def.id, name: name_1 });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
// The recognised runtime identifiers a `global` reference's `id` can legitimately
|
|
194
|
+
// already hold (Shape A). Anything else — notably the opaque `TQ_...` node id every
|
|
195
|
+
// dynamic UIDL reference carries for editor bookkeeping — is not a real identifier
|
|
196
|
+
// and must be re-derived from `refPath` (Shape B/C), or code generation would emit
|
|
197
|
+
// an undeclared variable that throws at runtime.
|
|
198
|
+
var KNOWN_GLOBAL_REF_IDS = new Set([
|
|
199
|
+
'locale',
|
|
200
|
+
'locales',
|
|
201
|
+
'company',
|
|
202
|
+
'currentUser',
|
|
203
|
+
'userIsLoggedIn',
|
|
204
|
+
'ecommerce',
|
|
205
|
+
'cart',
|
|
206
|
+
]);
|
|
207
|
+
var normalizeGlobalRef = function (node) {
|
|
208
|
+
if (!node.content.refPath || node.content.refPath.length === 0) {
|
|
209
|
+
return node;
|
|
210
|
+
}
|
|
211
|
+
if (node.content.id && KNOWN_GLOBAL_REF_IDS.has(node.content.id)) {
|
|
212
|
+
return node;
|
|
213
|
+
}
|
|
214
|
+
var firstSeg = node.content.refPath[0];
|
|
215
|
+
var mappedId = ast_utils_1.GLOBAL_REF_ID_MAP[firstSeg];
|
|
216
|
+
if (!mappedId) {
|
|
217
|
+
return node;
|
|
218
|
+
}
|
|
219
|
+
return __assign(__assign({}, node), { content: __assign(__assign({}, node.content), { id: mappedId, refPath: node.content.refPath.slice(1) }) });
|
|
220
|
+
};
|
|
221
|
+
var getElementType = function (node) {
|
|
222
|
+
if (node.type === 'element' &&
|
|
223
|
+
node.content &&
|
|
224
|
+
typeof node.content === 'object' &&
|
|
225
|
+
'elementType' in node.content) {
|
|
226
|
+
return node.content.elementType;
|
|
227
|
+
}
|
|
228
|
+
if ((node.type === 'data-source-list' || node.type === 'data-source-item') && node.content) {
|
|
229
|
+
return node.content.elementType || 'DataProvider';
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
233
|
+
var getClassName = function (node) {
|
|
234
|
+
if (node.type === 'element' &&
|
|
235
|
+
node.content &&
|
|
236
|
+
typeof node.content === 'object' &&
|
|
237
|
+
'key' in node.content) {
|
|
238
|
+
return node.content.key || null;
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
};
|
|
242
|
+
var REACT_CHARTJS2_CHART_TAGS = new Set([
|
|
243
|
+
'Line',
|
|
244
|
+
'Bar',
|
|
245
|
+
'Doughnut',
|
|
246
|
+
'Pie',
|
|
247
|
+
'Radar',
|
|
248
|
+
'Bubble',
|
|
249
|
+
'PolarArea',
|
|
250
|
+
'Scatter',
|
|
251
|
+
]);
|
|
252
|
+
var isReactChartjs2Chart = function (dependency, elementType) {
|
|
253
|
+
if ((dependency === null || dependency === void 0 ? void 0 : dependency.path) !== 'react-chartjs-2') {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
return REACT_CHARTJS2_CHART_TAGS.has(elementType);
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* A chart whose data did not arrive — a query the data source refused, a
|
|
260
|
+
* state still holding an empty fallback — draws an empty chart instead of
|
|
261
|
+
* taking the page down: react-chartjs-2 reads `data.labels` on its first
|
|
262
|
+
* render, and on the server that throw fails the render of the whole page.
|
|
263
|
+
* Rewrites `data={X}` into
|
|
264
|
+
* data={Array.isArray(X?.datasets) ? X : { labels: [], datasets: [] }}
|
|
265
|
+
* A data object written out in place, or hoisted to a constant of the
|
|
266
|
+
* module, needs no guard and is left as is.
|
|
267
|
+
*/
|
|
268
|
+
var guardReactChartJs2DataAttr = function (chartElement, hoistedConstants) {
|
|
269
|
+
var _a;
|
|
270
|
+
var attr = chartElement.openingElement.attributes.find(function (a) {
|
|
271
|
+
return a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === 'data';
|
|
272
|
+
});
|
|
273
|
+
if (!attr || ((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) !== 'JSXExpressionContainer') {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
var source = attr.value.expression;
|
|
277
|
+
var hoisted = types.isIdentifier(source) && hoistedConstants.some(function (constant) { return constant.name === source.name; });
|
|
278
|
+
if (!types.isExpression(source) || types.isObjectExpression(source) || hoisted) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
attr.value = types.jsxExpressionContainer(types.conditionalExpression(types.callExpression(types.memberExpression(types.identifier('Array'), types.identifier('isArray')), [
|
|
282
|
+
types.optionalMemberExpression(types.cloneNode(source), types.identifier('datasets'), false, true),
|
|
283
|
+
]), types.cloneNode(source), types.objectExpression([
|
|
284
|
+
types.objectProperty(types.identifier('labels'), types.arrayExpression([])),
|
|
285
|
+
types.objectProperty(types.identifier('datasets'), types.arrayExpression([])),
|
|
286
|
+
])));
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Chart.js with maintainAspectRatio:false fills the parent; if height is on the chart
|
|
290
|
+
* component via className, react-chartjs-2 may not apply it to the canvas host correctly
|
|
291
|
+
* inside flex layouts, causing unbounded growth. Wrap in a bounded div and move className
|
|
292
|
+
* to the wrapper; the chart fills with height/width 100%.
|
|
293
|
+
*/
|
|
294
|
+
var wrapReactChartJs2Element = function (chartElement, _node) {
|
|
295
|
+
var attrs = chartElement.openingElement.attributes;
|
|
296
|
+
var kept = [];
|
|
297
|
+
var classNameAttr = null;
|
|
298
|
+
for (var _i = 0, attrs_1 = attrs; _i < attrs_1.length; _i++) {
|
|
299
|
+
var a = attrs_1[_i];
|
|
300
|
+
if (a.type === 'JSXAttribute' &&
|
|
301
|
+
a.name.type === 'JSXIdentifier' &&
|
|
302
|
+
a.name.name === 'className') {
|
|
303
|
+
classNameAttr = a;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
kept.push(a);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
chartElement.openingElement.attributes = kept;
|
|
310
|
+
var hasStyleAttr = kept.some(function (a) { return a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === 'style'; });
|
|
311
|
+
if (!hasStyleAttr) {
|
|
312
|
+
chartElement.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('style'), types.jsxExpressionContainer(types.objectExpression([
|
|
313
|
+
types.objectProperty(types.identifier('height'), types.stringLiteral('100%')),
|
|
314
|
+
types.objectProperty(types.identifier('width'), types.stringLiteral('100%')),
|
|
315
|
+
]))));
|
|
316
|
+
}
|
|
317
|
+
var wrapperStyle = types.objectExpression([
|
|
318
|
+
types.objectProperty(types.identifier('position'), types.stringLiteral('relative')),
|
|
319
|
+
types.objectProperty(types.identifier('minHeight'), types.numericLiteral(0)),
|
|
320
|
+
types.objectProperty(types.identifier('flexShrink'), types.numericLiteral(0)),
|
|
321
|
+
types.objectProperty(types.identifier('overflow'), types.stringLiteral('hidden')),
|
|
322
|
+
]);
|
|
323
|
+
var wrapperAttrs = [
|
|
324
|
+
types.jsxAttribute(types.jsxIdentifier('style'), types.jsxExpressionContainer(wrapperStyle)),
|
|
325
|
+
];
|
|
326
|
+
if (classNameAttr) {
|
|
327
|
+
wrapperAttrs.push(classNameAttr);
|
|
328
|
+
}
|
|
329
|
+
return types.jsxElement(types.jsxOpeningElement(types.jsxIdentifier('div'), wrapperAttrs), types.jsxClosingElement(types.jsxIdentifier('div')), [chartElement], false);
|
|
330
|
+
};
|
|
331
|
+
var isCalendarKitScheduler = function (dependency, elementType) {
|
|
332
|
+
return (dependency === null || dependency === void 0 ? void 0 : dependency.path) === 'calendarkit-basic' && elementType === 'BasicScheduler';
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* calendarkit-basic's BasicScheduler requires `start`/`end` to be Date objects
|
|
336
|
+
* (date-fns internals), but UIDL attrs carry them as ISO strings — both for
|
|
337
|
+
* static event arrays and for state-bound arrays populated by workflows.
|
|
338
|
+
* Rewrites `events={X}` into:
|
|
339
|
+
* events={(Array.isArray(X) ? X : []).map((e) => ({ ...e, start: new Date(e.start), end: new Date(e.end) }))}
|
|
340
|
+
* The Array.isArray guard renders zero events instead of crashing when a
|
|
341
|
+
* binding resolves to a non-array (e.g. an unparsed JSON-string fallback).
|
|
342
|
+
* A missing `events` attr is left as-is — the component defaults it to [].
|
|
343
|
+
*/
|
|
344
|
+
var wrapCalendarKitEventsAttr = function (calendarElement) {
|
|
345
|
+
var _a;
|
|
346
|
+
var attr = calendarElement.openingElement.attributes.find(function (a) {
|
|
347
|
+
return a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === 'events';
|
|
348
|
+
});
|
|
349
|
+
if (!attr || ((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) !== 'JSXExpressionContainer') {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
var source = attr.value.expression;
|
|
353
|
+
if (!types.isExpression(source)) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
// A static array literal needs no runtime guard; dynamic references do.
|
|
357
|
+
var guardedSource = types.isArrayExpression(source)
|
|
358
|
+
? source
|
|
359
|
+
: types.conditionalExpression(types.callExpression(types.memberExpression(types.identifier('Array'), types.identifier('isArray')), [source]), types.cloneNode(source), types.arrayExpression([]));
|
|
360
|
+
var reviveEvent = types.arrowFunctionExpression([types.identifier('e')], types.objectExpression([
|
|
361
|
+
types.spreadElement(types.identifier('e')),
|
|
362
|
+
types.objectProperty(types.identifier('start'), types.newExpression(types.identifier('Date'), [
|
|
363
|
+
types.memberExpression(types.identifier('e'), types.identifier('start')),
|
|
364
|
+
])),
|
|
365
|
+
types.objectProperty(types.identifier('end'), types.newExpression(types.identifier('Date'), [
|
|
366
|
+
types.memberExpression(types.identifier('e'), types.identifier('end')),
|
|
367
|
+
])),
|
|
368
|
+
]));
|
|
369
|
+
attr.value = types.jsxExpressionContainer(types.callExpression(types.memberExpression(guardedSource, types.identifier('map')), [
|
|
370
|
+
reviveEvent,
|
|
371
|
+
]));
|
|
372
|
+
};
|
|
373
|
+
var reorderChildrenForSearch = function (children) {
|
|
374
|
+
var searchNodes = [];
|
|
375
|
+
var dataProviderNodes = [];
|
|
376
|
+
var paginationNodes = [];
|
|
377
|
+
var otherNodes = [];
|
|
378
|
+
children.forEach(function (child) {
|
|
379
|
+
var elementType = getElementType(child);
|
|
380
|
+
var nodeType = child.type;
|
|
381
|
+
var className = getClassName(child);
|
|
382
|
+
// Check for search nodes - use className since elementType is replaced by semanticType
|
|
383
|
+
if (className &&
|
|
384
|
+
(className.includes('data-source-search') || className.includes('search-node'))) {
|
|
385
|
+
searchNodes.push(child);
|
|
386
|
+
}
|
|
387
|
+
// Check for DataProvider nodes - these should appear SECOND
|
|
388
|
+
else if (nodeType === 'data-source-list' ||
|
|
389
|
+
nodeType === 'data-source-item' ||
|
|
390
|
+
elementType === 'DataProvider') {
|
|
391
|
+
dataProviderNodes.push(child);
|
|
392
|
+
}
|
|
393
|
+
// Check for pagination nodes - use className since elementType is replaced by semanticType
|
|
394
|
+
else if ((elementType &&
|
|
395
|
+
(elementType.includes('pagination') || elementType.includes('cms-pagination'))) ||
|
|
396
|
+
(className && (className.includes('pagination') || className.includes('cms-pagination')))) {
|
|
397
|
+
paginationNodes.push(child);
|
|
398
|
+
}
|
|
399
|
+
// Everything else goes in the middle
|
|
400
|
+
else {
|
|
401
|
+
otherNodes.push(child);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
// Only reorder if we have search or pagination nodes alongside a DataProvider
|
|
405
|
+
// This ensures we only reorder when there's an actual pagination/search group
|
|
406
|
+
// If there's no search/pagination, keep original order to preserve DataProvider positions
|
|
407
|
+
var hasSearchOrPagination = searchNodes.length > 0 || paginationNodes.length > 0;
|
|
408
|
+
var hasDataProvider = dataProviderNodes.length > 0;
|
|
409
|
+
if (hasSearchOrPagination && hasDataProvider) {
|
|
410
|
+
// Order: search nodes first, then data providers, then other nodes, then pagination last
|
|
411
|
+
// This ensures: search input -> DataProvider -> content -> pagination buttons
|
|
412
|
+
return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], searchNodes, true), dataProviderNodes, true), otherNodes, true), paginationNodes, true);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
// No reordering needed - preserve original order
|
|
416
|
+
return children;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Extracts autocomplete context from a thq-autocomplete node's children.
|
|
421
|
+
* Returns the input's field name and the dropdown's isOpen state name,
|
|
422
|
+
* so child option/clear elements can wire up onClick handlers.
|
|
423
|
+
*/
|
|
424
|
+
var extractAutocompleteContext = function (children, formStateName) {
|
|
425
|
+
var _a, _b, _c, _d;
|
|
426
|
+
var fieldName = null;
|
|
427
|
+
var inputHtmlId = null;
|
|
428
|
+
var isOpenStateName = null;
|
|
429
|
+
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
|
|
430
|
+
var child = children_1[_i];
|
|
431
|
+
if (child.type === 'element') {
|
|
432
|
+
var content = child.content;
|
|
433
|
+
// Check both original elementType and data-thq attr (elementType may have been resolved)
|
|
434
|
+
var dataThq = (_a = content.attrs) === null || _a === void 0 ? void 0 : _a['data-thq'];
|
|
435
|
+
var thqValue = (dataThq === null || dataThq === void 0 ? void 0 : dataThq.type) === 'static' ? String(dataThq.content) : '';
|
|
436
|
+
if (content.elementType === 'thq-autocomplete-input' ||
|
|
437
|
+
thqValue === 'thq-autocomplete-input') {
|
|
438
|
+
var nameAttr = (_b = content.attrs) === null || _b === void 0 ? void 0 : _b.name;
|
|
439
|
+
if ((nameAttr === null || nameAttr === void 0 ? void 0 : nameAttr.type) === 'static' && typeof nameAttr.content === 'string') {
|
|
440
|
+
fieldName = nameAttr.content;
|
|
441
|
+
}
|
|
442
|
+
var idAttr = (_c = content.attrs) === null || _c === void 0 ? void 0 : _c.id;
|
|
443
|
+
if ((idAttr === null || idAttr === void 0 ? void 0 : idAttr.type) === 'static' && typeof idAttr.content === 'string') {
|
|
444
|
+
inputHtmlId = idAttr.content;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (child.type === 'conditional') {
|
|
449
|
+
var condContent = child.content;
|
|
450
|
+
var ref = (_d = condContent.reference) === null || _d === void 0 ? void 0 : _d.content;
|
|
451
|
+
if ((ref === null || ref === void 0 ? void 0 : ref.referenceType) === 'state' && typeof ref.id === 'string') {
|
|
452
|
+
isOpenStateName = ref.id;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (fieldName && isOpenStateName) {
|
|
457
|
+
return { fieldName: fieldName, inputHtmlId: inputHtmlId || '', formStateName: formStateName, isOpenStateName: isOpenStateName };
|
|
458
|
+
}
|
|
459
|
+
return undefined;
|
|
460
|
+
};
|
|
461
|
+
var maybeAddFormStoreFieldBinding = function (elementTag, elementName, attrs, params, events) {
|
|
462
|
+
var stateKey = params.formStoreStateName;
|
|
463
|
+
if (!stateKey || !attrs) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
var nameAttr = attrs.name;
|
|
467
|
+
if (!nameAttr || nameAttr.type !== 'static' || typeof nameAttr.content !== 'string') {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
var tag = elementName.toLowerCase();
|
|
471
|
+
var isRichTextEditor = tag === 'richtexteditor';
|
|
472
|
+
if (tag !== 'input' && tag !== 'textarea' && tag !== 'select' && !isRichTextEditor) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
// Autocomplete inputs manage their own value through workflows and option onClick handlers.
|
|
476
|
+
// Do NOT bind them to the form store — it causes infinite loops with state-change workflows.
|
|
477
|
+
var dataThq = attrs['data-thq'];
|
|
478
|
+
if ((dataThq === null || dataThq === void 0 ? void 0 : dataThq.type) === 'static' && String(dataThq.content) === 'thq-autocomplete-input') {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
var fieldName = nameAttr.content;
|
|
482
|
+
var stateId = types.identifier(stateKey);
|
|
483
|
+
var fieldAccess = types.memberExpression(stateId, types.stringLiteral(fieldName), true);
|
|
484
|
+
var typeAttr = attrs.type;
|
|
485
|
+
var isCheckbox = (typeAttr === null || typeAttr === void 0 ? void 0 : typeAttr.type) === 'static' && String(typeAttr.content) === 'checkbox';
|
|
486
|
+
var hasValueInAttrs = Object.prototype.hasOwnProperty.call(attrs, 'value');
|
|
487
|
+
var hasCheckedInAttrs = Object.prototype.hasOwnProperty.call(attrs, 'checked');
|
|
488
|
+
if (isRichTextEditor) {
|
|
489
|
+
var valueForEditor = types.logicalExpression('||', fieldAccess, types.stringLiteral(''));
|
|
490
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('value'), types.jsxExpressionContainer(valueForEditor)));
|
|
491
|
+
var setterName = "set".concat(stateKey.charAt(0).toUpperCase()).concat(stateKey.slice(1));
|
|
492
|
+
var richHandler = (0, ast_utils_1.parseJSExpressionAsAST)("(html) => { ".concat(setterName, "(prev => ({ ...prev, ['").concat(fieldName, "']: html })); }"));
|
|
493
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onChange'), types.jsxExpressionContainer(richHandler)));
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (!hasValueInAttrs && !isCheckbox) {
|
|
497
|
+
var valueExpr = types.logicalExpression('??', fieldAccess, types.stringLiteral(''));
|
|
498
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('value'), types.jsxExpressionContainer(valueExpr)));
|
|
499
|
+
}
|
|
500
|
+
else if (isCheckbox && !hasCheckedInAttrs) {
|
|
501
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('checked'), types.jsxExpressionContainer(fieldAccess)));
|
|
502
|
+
}
|
|
503
|
+
var hasUidlOnChange = events && Object.prototype.hasOwnProperty.call(events, 'onChange');
|
|
504
|
+
if (!hasUidlOnChange) {
|
|
505
|
+
var setterName = "set".concat(stateKey.charAt(0).toUpperCase()).concat(stateKey.slice(1));
|
|
506
|
+
var handler = (0, ast_utils_1.parseJSExpressionAsAST)("(e) => { const t = e.target; if (t.name) { ".concat(setterName, "(prev => ({ ...prev, [t.name]: t.type === 'checkbox' ? t.checked : t.value })); } }"));
|
|
507
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onChange'), types.jsxExpressionContainer(handler)));
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
// Style plugins (styled-jsx, css-modules, styled-components, react-jss, plugin-css)
|
|
511
|
+
// emit ONE flat, component-scope CSS block/class-map from `element.style`, so a
|
|
512
|
+
// dynamic style value only resolves correctly there when the identifier it needs
|
|
513
|
+
// is reachable from that top-level scope (e.g. `token`/`prop`). A `ctx` reference
|
|
514
|
+
// resolves to the render-prop identifier of the enclosing repeater/data-source —
|
|
515
|
+
// only in scope inside that repeater's own render callback — and other reference
|
|
516
|
+
// types (`state`, `local`, `global`, `globalState`, ...) are never routed through
|
|
517
|
+
// `element.style` by any known UIDL producer either. When one shows up anyway, the
|
|
518
|
+
// only place that still knows the correct enclosing scope is here, while building
|
|
519
|
+
// this exact JSX node, so resolve it into an inline `style` attribute (mirroring
|
|
520
|
+
// how `dynamicStyleBindings` already handles ctx/state-bound styles) and strip it
|
|
521
|
+
// out of `element.style` so no downstream style plugin re-processes — and chokes
|
|
522
|
+
// on — the same entry.
|
|
523
|
+
var resolveScopedDynamicStyleValues = function (style, elementTag, params, options) {
|
|
524
|
+
if (!style) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
var inlineStyleOverrides = {};
|
|
528
|
+
for (var _i = 0, _a = Object.keys(style); _i < _a.length; _i++) {
|
|
529
|
+
var cssProperty = _a[_i];
|
|
530
|
+
var styleValue = style[cssProperty];
|
|
531
|
+
var camelCaseProperty = teleport_shared_1.StringUtils.cssPropertyToInlineStyleKey(cssProperty);
|
|
532
|
+
// A pre-resolved expression style value (e.g. a data-source-bound style whose
|
|
533
|
+
// mapper already produced the full member-access expression). The UIDL style
|
|
534
|
+
// type is narrowed to static|dynamic, so read the discriminator via a cast.
|
|
535
|
+
// Inline the parsed expression and strip it so no CSS/styled-jsx plugin sees it.
|
|
536
|
+
var rawStyleValue = styleValue;
|
|
537
|
+
if (rawStyleValue.type === 'expr') {
|
|
538
|
+
var exprContent = rawStyleValue.content;
|
|
539
|
+
if (typeof exprContent === 'string' && exprContent.length > 0) {
|
|
540
|
+
inlineStyleOverrides[camelCaseProperty] = new parsed_ast_1.default((0, ast_utils_1.parseJSExpressionAsAST)(exprContent));
|
|
541
|
+
delete style[cssProperty];
|
|
542
|
+
}
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
// Skip: `token` → CSS variable (handled by the style plugin); a SIMPLE `prop`
|
|
546
|
+
// (no refPath) → the style plugin's `${props.x}` interpolation. A prop WITH a
|
|
547
|
+
// refPath (an object prop's field, e.g. `product.color`) MUST be inlined here
|
|
548
|
+
// instead — styled-jsx's prop case emits only `props.<id>` and would drop the
|
|
549
|
+
// refPath, producing `props.product` instead of `props.product.color`.
|
|
550
|
+
var isSimpleProp = styleValue.type === 'dynamic' &&
|
|
551
|
+
styleValue.content.referenceType === 'prop' &&
|
|
552
|
+
!(styleValue.content.refPath && styleValue.content.refPath.length > 0);
|
|
553
|
+
if (styleValue.type !== 'dynamic' ||
|
|
554
|
+
styleValue.content.referenceType === 'token' ||
|
|
555
|
+
isSimpleProp) {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
var resolvedExpr = resolveDynamicReferenceExpression(styleValue, params, options);
|
|
559
|
+
var fallback = styleValue.content.fallback;
|
|
560
|
+
var finalExpr = fallback !== undefined && fallback !== ''
|
|
561
|
+
? types.logicalExpression('||', resolvedExpr, (0, ast_utils_1.convertValueToLiteral)(fallback))
|
|
562
|
+
: resolvedExpr;
|
|
563
|
+
inlineStyleOverrides[camelCaseProperty] = new parsed_ast_1.default(finalExpr);
|
|
564
|
+
delete style[cssProperty];
|
|
565
|
+
}
|
|
566
|
+
if (Object.keys(inlineStyleOverrides).length > 0) {
|
|
567
|
+
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, 'style', inlineStyleOverrides);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
44
570
|
var generateElementNode = function (node, params, jsxOptions) {
|
|
45
|
-
var dependencies = params.dependencies, nodesLookup = params.nodesLookup
|
|
46
|
-
var options = __assign(__assign(
|
|
47
|
-
var
|
|
571
|
+
var dependencies = params.dependencies, nodesLookup = params.nodesLookup;
|
|
572
|
+
var options = __assign(__assign({}, constants_1.DEFAULT_JSX_OPTIONS), jsxOptions);
|
|
573
|
+
var _a = node.content, elementType = _a.elementType, selfClosing = _a.selfClosing, children = _a.children, key = _a.key, attrs = _a.attrs, dependency = _a.dependency, events = _a.events, style = _a.style;
|
|
48
574
|
var originalElementName = elementType || 'component';
|
|
49
575
|
var tagName = originalElementName;
|
|
576
|
+
// Check if this is a fragment element - normalize to Fragment before processing
|
|
577
|
+
var isFragment = tagName.toLowerCase() === 'fragment';
|
|
578
|
+
if (isFragment) {
|
|
579
|
+
tagName = 'Fragment';
|
|
580
|
+
}
|
|
50
581
|
if (dependency) {
|
|
51
582
|
if (options.dependencyHandling === 'import' ||
|
|
52
583
|
(options.dependencyHandling === 'ignore' && (dependency === null || dependency === void 0 ? void 0 : dependency.type) === 'package')) {
|
|
@@ -65,26 +596,187 @@ var generateElementNode = function (node, params, jsxOptions) {
|
|
|
65
596
|
params.windowImports[dependency.path] = dynamicWindowImport;
|
|
66
597
|
}
|
|
67
598
|
}
|
|
599
|
+
else if (isFragment) {
|
|
600
|
+
// If no dependency was provided but this is a fragment, add Fragment dependency
|
|
601
|
+
if (options.dependencyHandling === 'import') {
|
|
602
|
+
dependencies.Fragment = {
|
|
603
|
+
type: 'package',
|
|
604
|
+
path: 'react',
|
|
605
|
+
version: 'latest',
|
|
606
|
+
meta: {
|
|
607
|
+
namedImport: true,
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
}
|
|
68
612
|
var elementName = dependency && dependency.type === 'local' && options.customElementTag
|
|
69
613
|
? options.customElementTag(tagName)
|
|
70
614
|
: tagName;
|
|
71
615
|
var elementTag = selfClosing ? (0, ast_builders_1.createSelfClosingJSXTag)(elementName) : (0, ast_builders_1.createJSXTag)(elementName);
|
|
72
616
|
if (attrs) {
|
|
73
|
-
addAttributesToJSXTag(attrs, elementTag, options);
|
|
617
|
+
addAttributesToJSXTag(attrs, elementTag, options, params, node.content.semanticType || elementType);
|
|
74
618
|
}
|
|
619
|
+
resolveScopedDynamicStyleValues(style, elementTag, params, options);
|
|
75
620
|
if (events) {
|
|
76
621
|
Object.keys(events).forEach(function (eventKey) {
|
|
77
622
|
(0, utils_1.addEventHandlerToTag)(elementTag, eventKey, events[eventKey], params, options);
|
|
78
623
|
});
|
|
79
624
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
625
|
+
// Generate onChange handler for form elements with data-store-values-state
|
|
626
|
+
var childParams = params;
|
|
627
|
+
if (attrs === null || attrs === void 0 ? void 0 : attrs['data-store-values-state']) {
|
|
628
|
+
var storeAttr = attrs['data-store-values-state'];
|
|
629
|
+
if (storeAttr.type === 'static' && typeof storeAttr.content === 'string') {
|
|
630
|
+
var stateName = storeAttr.content;
|
|
631
|
+
childParams = __assign(__assign({}, params), { formStoreStateName: stateName });
|
|
632
|
+
var setterName = "set".concat(stateName.charAt(0).toUpperCase()).concat(stateName.slice(1));
|
|
633
|
+
var handler = (0, ast_utils_1.parseJSExpressionAsAST)("(e) => { const t = e.target; if (t.name && t.getAttribute('data-thq') !== 'thq-autocomplete-input') { ".concat(setterName, "(prev => ({ ...prev, [t.name]: t.type === 'checkbox' ? t.checked : t.value })); } }"));
|
|
634
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onChange'), types.jsxExpressionContainer(handler)));
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
maybeAddFormStoreFieldBinding(elementTag, elementName, attrs, childParams, events);
|
|
638
|
+
// thq-autocomplete-input: make uncontrolled by converting `value` → `defaultValue`
|
|
639
|
+
// A controlled autocomplete input triggers state-change workflows on every keystroke,
|
|
640
|
+
// which normalizes the typed text and prevents free typing for search/filtering.
|
|
641
|
+
var dataThqAttr = attrs === null || attrs === void 0 ? void 0 : attrs['data-thq'];
|
|
642
|
+
var dataThqValue = (dataThqAttr === null || dataThqAttr === void 0 ? void 0 : dataThqAttr.type) === 'static' ? String(dataThqAttr.content) : '';
|
|
643
|
+
if (dataThqValue === 'thq-autocomplete-input') {
|
|
644
|
+
var jsxAttrs = elementTag.openingElement.attributes;
|
|
645
|
+
var valueIdx = jsxAttrs.findIndex(function (a) { return a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === 'value'; });
|
|
646
|
+
if (valueIdx !== -1) {
|
|
647
|
+
// Convert value → defaultValue so the input is uncontrolled but has initial value
|
|
648
|
+
var valueAttr = jsxAttrs[valueIdx];
|
|
649
|
+
jsxAttrs.splice(valueIdx, 1, types.jsxAttribute(types.jsxIdentifier('defaultValue'), valueAttr.value));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
// A controlled form control (`<input>`/`<textarea>`/`<select>` with a `value`,
|
|
653
|
+
// or a checkbox/radio with `checked`) that has NO change handler is FROZEN by
|
|
654
|
+
// React — the user cannot type, and a console warning is emitted. This is the
|
|
655
|
+
// edit-form failure mode: entity-bound fields rendered as
|
|
656
|
+
// `value={props.item?.title}` with no state mirror (the worker deliberately
|
|
657
|
+
// does NOT mirror entity columns into state — see crud-edit-form contract).
|
|
658
|
+
// Render such controls UNCONTROLLED (`defaultValue`/`defaultChecked`) so they
|
|
659
|
+
// are editable AND the DOM value reflects edits, which is exactly what
|
|
660
|
+
// form-submit workflows read (`document.getElementById(id).value`). Controls
|
|
661
|
+
// that ARE controlled (an onChange was attached above — via events, the
|
|
662
|
+
// form-store binding, or a workflow trigger) keep `value`/`checked`, and
|
|
663
|
+
// read-only/disabled display fields are left untouched.
|
|
664
|
+
(0, utils_1.makeControlUncontrolledWhenNoChangeHandler)(elementTag, elementName);
|
|
665
|
+
if (dataThqValue === 'thq-autocomplete' && children) {
|
|
666
|
+
var acCtx = extractAutocompleteContext(children, childParams.formStoreStateName);
|
|
667
|
+
if (acCtx) {
|
|
668
|
+
childParams = __assign(__assign({}, childParams), { autocompleteContext: acCtx });
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// thq-autocomplete-option: add onClick to select the option value
|
|
672
|
+
if (dataThqValue === 'thq-autocomplete-option' && params.autocompleteContext) {
|
|
673
|
+
var _b = params.autocompleteContext, fieldName = _b.fieldName, formStateName = _b.formStateName, isOpenStateName = _b.isOpenStateName, inputHtmlId = _b.inputHtmlId;
|
|
674
|
+
var isOpenSetterName = "set".concat(isOpenStateName.charAt(0).toUpperCase()).concat(isOpenStateName.slice(1));
|
|
675
|
+
var handlerCode
|
|
676
|
+
// The autocomplete input is uncontrolled, so always set the DOM value.
|
|
677
|
+
// If form-store mode, also update the form state for form submission.
|
|
678
|
+
= void 0;
|
|
679
|
+
// The autocomplete input is uncontrolled, so always set the DOM value.
|
|
680
|
+
// If form-store mode, also update the form state for form submission.
|
|
681
|
+
var inputLookup = inputHtmlId
|
|
682
|
+
? "document.getElementById('".concat(inputHtmlId, "')")
|
|
683
|
+
: "e.currentTarget.closest('[data-thq=\"thq-autocomplete\"]').querySelector('[data-thq=\"thq-autocomplete-input\"]')";
|
|
684
|
+
var formStoreUpdate = formStateName
|
|
685
|
+
? "var setter = ".concat("set".concat(formStateName.charAt(0).toUpperCase()).concat(formStateName.slice(1)), "; setter(function(prev) { return Object.assign({}, prev, { ['").concat(fieldName, "']: text }); });")
|
|
686
|
+
: '';
|
|
687
|
+
handlerCode = "(e) => { var text = (e.currentTarget.textContent || '').trim(); var input = ".concat(inputLookup, "; if (input) { input.value = text; } ").concat(formStoreUpdate, " ").concat(isOpenSetterName, "(false); }");
|
|
688
|
+
var handler = (0, ast_utils_1.parseJSExpressionAsAST)(handlerCode);
|
|
689
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onClick'), types.jsxExpressionContainer(handler)));
|
|
690
|
+
}
|
|
691
|
+
// thq-autocomplete-clear: add onClick to clear the input value and close dropdown
|
|
692
|
+
if (dataThqValue === 'thq-autocomplete-clear' && params.autocompleteContext) {
|
|
693
|
+
var _c = params.autocompleteContext, fieldName = _c.fieldName, formStateName = _c.formStateName, isOpenStateName = _c.isOpenStateName, inputHtmlId = _c.inputHtmlId;
|
|
694
|
+
var isOpenSetterName = "set".concat(isOpenStateName.charAt(0).toUpperCase()).concat(isOpenStateName.slice(1));
|
|
695
|
+
var handlerCode = void 0;
|
|
696
|
+
var clearInputLookup = inputHtmlId
|
|
697
|
+
? "document.getElementById('".concat(inputHtmlId, "')")
|
|
698
|
+
: "e.currentTarget.closest('[data-thq=\"thq-autocomplete\"]').querySelector('[data-thq=\"thq-autocomplete-input\"]')";
|
|
699
|
+
var clearFormStoreUpdate = formStateName
|
|
700
|
+
? "var setter = ".concat("set".concat(formStateName.charAt(0).toUpperCase()).concat(formStateName.slice(1)), "; setter(function(prev) { return Object.assign({}, prev, { ['").concat(fieldName, "']: '' }); });")
|
|
701
|
+
: '';
|
|
702
|
+
handlerCode = "(e) => { var input = ".concat(clearInputLookup, "; if (input) { input.value = ''; } ").concat(clearFormStoreUpdate, " ").concat(isOpenSetterName, "(false); }");
|
|
703
|
+
var handler = (0, ast_utils_1.parseJSExpressionAsAST)(handlerCode);
|
|
704
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onClick'), types.jsxExpressionContainer(handler)));
|
|
705
|
+
}
|
|
706
|
+
// A markdown-node can carry its rich-text content as a dynamic/expr child
|
|
707
|
+
// (e.g. CMS-bound rich text) rather than as a `raw` attribute. The raw-attribute
|
|
708
|
+
// path is handled in addAttributesToJSXTag; here we handle the children path so
|
|
709
|
+
// the content is injected as HTML (dangerouslySetInnerHTML) instead of being
|
|
710
|
+
// printed as an escaped raw value by the generic expression handler.
|
|
711
|
+
var isMarkdownNode = node.content.semanticType === 'markdown-node' || originalElementName === 'markdown-node';
|
|
712
|
+
var hasRawAttr = attrs
|
|
713
|
+
? Object.keys(attrs).some(function (attrKey) { var _a; return ((_a = attrs[attrKey]) === null || _a === void 0 ? void 0 : _a.type) === 'raw'; })
|
|
714
|
+
: false;
|
|
715
|
+
var markdownChildrenHandled = false;
|
|
716
|
+
if (isMarkdownNode && !selfClosing && !hasRawAttr && children && children.length > 0) {
|
|
717
|
+
var markdownChild = children.find(function (child) { return child.type === 'expr' || child.type === 'dynamic'; });
|
|
718
|
+
var markdownExpr = void 0;
|
|
719
|
+
if ((markdownChild === null || markdownChild === void 0 ? void 0 : markdownChild.type) === 'expr') {
|
|
720
|
+
markdownExpr = __1.ASTUtils.getExpressionFromUIDLExpressionNode(markdownChild);
|
|
721
|
+
}
|
|
722
|
+
else if ((markdownChild === null || markdownChild === void 0 ? void 0 : markdownChild.type) === 'dynamic') {
|
|
723
|
+
markdownExpr = resolveDynamicReferenceExpression(markdownChild, childParams, options);
|
|
724
|
+
}
|
|
725
|
+
if (markdownExpr) {
|
|
726
|
+
injectMarkdownExpression(elementTag, markdownExpr, '', childParams);
|
|
727
|
+
markdownChildrenHandled = true;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
// A controlled <textarea> — one carrying a `value` (or `defaultValue`) prop —
|
|
731
|
+
// must NOT also render children. React's server renderer throws
|
|
732
|
+
// "If you supply `value` on a <textarea> you must not supply children.", which
|
|
733
|
+
// aborts static export of the whole page. The details-page / entity binder can
|
|
734
|
+
// leave the original text content in place when it adds a `value` binding to a
|
|
735
|
+
// textarea (harmless for <input>, fatal for <textarea>). We still GENERATE the
|
|
736
|
+
// children below so every UIDL node lands in `nodesLookup` (the styled-jsx pass
|
|
737
|
+
// requires it), but we do not attach them to the textarea — the value prop is
|
|
738
|
+
// the single source of truth.
|
|
739
|
+
var isTextArea = originalElementName.toLowerCase() === 'textarea' || node.content.semanticType === 'textarea';
|
|
740
|
+
// The check must run against the JSX opening element (not just UIDL attrs):
|
|
741
|
+
// maybeAddFormStoreFieldBinding injects a `value` attr onto named textareas
|
|
742
|
+
// inside a data-store-values-state form AFTER UIDL attrs are processed, and
|
|
743
|
+
// that injected binding makes the textarea controlled all the same.
|
|
744
|
+
var jsxTagHasControlledValue = elementTag.openingElement.attributes.some(function (attr) {
|
|
745
|
+
return attr.type === 'JSXAttribute' &&
|
|
746
|
+
attr.name.type === 'JSXIdentifier' &&
|
|
747
|
+
(attr.name.name === 'value' || attr.name.name === 'defaultValue');
|
|
748
|
+
});
|
|
749
|
+
var skipAttachingChildren = isTextArea &&
|
|
750
|
+
(jsxTagHasControlledValue ||
|
|
751
|
+
(!!attrs &&
|
|
752
|
+
(Object.prototype.hasOwnProperty.call(attrs, 'value') ||
|
|
753
|
+
Object.prototype.hasOwnProperty.call(attrs, 'defaultValue'))));
|
|
754
|
+
if (!markdownChildrenHandled && !selfClosing && children) {
|
|
755
|
+
// Reorder children to ensure search nodes appear before DataProvider nodes
|
|
756
|
+
var reorderedChildren = reorderChildrenForSearch(children);
|
|
757
|
+
reorderedChildren.forEach(function (child) {
|
|
758
|
+
var childTags = generateNode(child, childParams, options);
|
|
759
|
+
if (skipAttachingChildren) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
83
762
|
childTags.forEach(function (childTag) {
|
|
84
763
|
if (typeof childTag === 'string') {
|
|
85
764
|
(0, ast_utils_1.addChildJSXText)(elementTag, childTag);
|
|
86
765
|
}
|
|
87
766
|
else if (childTag.type === 'JSXExpressionContainer' || childTag.type === 'JSXElement') {
|
|
767
|
+
// Backstop for an UNCONTROLLED <textarea> whose value binding arrived
|
|
768
|
+
// as a child (we only reach here when skipAttachingChildren is false —
|
|
769
|
+
// the textarea has NO value/defaultValue attr). A <textarea> has no
|
|
770
|
+
// value attribute in HTML, so React stringifies an element/expression
|
|
771
|
+
// CHILD to the literal "[object Object]" inside the field (run 97ac2650
|
|
772
|
+
// Add Note). The primary fix hoists the binding to a value= attribute at
|
|
773
|
+
// import time (ai-state-binding-preprocessor.hoistTextareaChildBindingToValue);
|
|
774
|
+
// this net drops any stray dynamic child so it can never render
|
|
775
|
+
// "[object Object]". Static text children (the typeof-string branch
|
|
776
|
+
// above) are untouched.
|
|
777
|
+
if (isTextArea) {
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
88
780
|
(0, ast_utils_1.addChildJSXTag)(elementTag, childTag);
|
|
89
781
|
}
|
|
90
782
|
else {
|
|
@@ -93,61 +785,303 @@ var generateElementNode = function (node, params, jsxOptions) {
|
|
|
93
785
|
});
|
|
94
786
|
});
|
|
95
787
|
}
|
|
788
|
+
if (dependency && isReactChartjs2Chart(dependency, originalElementName)) {
|
|
789
|
+
guardReactChartJs2DataAttr(elementTag, params.hoistedConstants);
|
|
790
|
+
var wrapped = wrapReactChartJs2Element(elementTag, node);
|
|
791
|
+
nodesLookup[key] = wrapped;
|
|
792
|
+
return wrapped;
|
|
793
|
+
}
|
|
794
|
+
if (dependency && isCalendarKitScheduler(dependency, originalElementName)) {
|
|
795
|
+
wrapCalendarKitEventsAttr(elementTag);
|
|
796
|
+
}
|
|
96
797
|
nodesLookup[key] = elementTag;
|
|
97
798
|
return elementTag;
|
|
98
799
|
};
|
|
99
800
|
exports.default = generateElementNode;
|
|
100
|
-
var addAttributesToJSXTag = function (attrs, elementTag, options) {
|
|
101
|
-
Object.keys(attrs).forEach(function (attrKey) {
|
|
801
|
+
var addAttributesToJSXTag = function (attrs, elementTag, options, params, elementName) {
|
|
802
|
+
Object.keys(attrs !== null && attrs !== void 0 ? attrs : {}).forEach(function (attrKey) {
|
|
803
|
+
var _a;
|
|
102
804
|
var attributeValue = attrs[attrKey];
|
|
805
|
+
if (!attributeValue.type) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
// Skip code-gen directives - handled in generateElementNode
|
|
809
|
+
if (attrKey === 'data-store-values-state') {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
// Plan v15 Layer 4 — codegen safety net.
|
|
813
|
+
//
|
|
814
|
+
// Drop attributes that look like AI fabrication artefacts even when the
|
|
815
|
+
// upstream pipeline missed them. These never produce valid DOM/JSX:
|
|
816
|
+
// 1. attr names that are pure JS literals (`true`, `false`, bare
|
|
817
|
+
// numbers, `null`, `undefined`) — e.g. the `true="true"` that
|
|
818
|
+
// shipped with the broken Navigation in the 2026-05-24 run.
|
|
819
|
+
// 2. static string values that contain entity-escaped binding markers
|
|
820
|
+
// (`{` / `}`) — emitting them produces broken DOM text.
|
|
821
|
+
// 3. static string values that contain an UNBALANCED `{{` (no
|
|
822
|
+
// matching `}}`) — always garbage, never valid.
|
|
823
|
+
if (isJunkAttributeName(attrKey)) {
|
|
824
|
+
// eslint-disable-next-line no-console
|
|
825
|
+
console.warn("[codegen safety net] dropping junk-name attribute \"".concat(attrKey, "\" on <").concat(elementName !== null && elementName !== void 0 ? elementName : 'element', ">"));
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (attributeValue.type === 'static') {
|
|
829
|
+
var staticContent = attributeValue.content;
|
|
830
|
+
if (typeof staticContent === 'string' && hasCorruptBindingMarkers(staticContent)) {
|
|
831
|
+
// eslint-disable-next-line no-console
|
|
832
|
+
console.warn("[codegen safety net] dropping attribute \"".concat(attrKey, "\" on <").concat(elementName !== null && elementName !== void 0 ? elementName : 'element', "> \u2014 value has entity-escaped or truncated binding markers (").concat(truncate(staticContent), ")"));
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
// React takes `style` as an object, never as text: a `style="color: red"`
|
|
837
|
+
// attribute (a custom attribute typed in the editor) throws React error #62
|
|
838
|
+
// while the page prerenders and fails the whole build. The text becomes the
|
|
839
|
+
// object it meant; a value that is not plain CSS text is dropped.
|
|
840
|
+
if (attrKey === 'style') {
|
|
841
|
+
var inlineStyle = attributeValue.type === 'static'
|
|
842
|
+
? parseInlineStyleText(attributeValue.content)
|
|
843
|
+
: undefined;
|
|
844
|
+
if (inlineStyle && Object.keys(inlineStyle).length > 0) {
|
|
845
|
+
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, 'style', inlineStyle);
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
// eslint-disable-next-line no-console
|
|
849
|
+
console.warn("[codegen safety net] dropping \"style\" attribute on <".concat(elementName !== null && elementName !== void 0 ? elementName : 'element', "> \u2014 React takes style as an object, and this value is not CSS text"));
|
|
850
|
+
}
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
103
853
|
switch (attributeValue.type) {
|
|
104
854
|
case 'dynamic':
|
|
105
|
-
var
|
|
855
|
+
var dynamicRef = attributeValue;
|
|
856
|
+
var referenceType = dynamicRef.content.referenceType;
|
|
857
|
+
if (referenceType === 'global') {
|
|
858
|
+
var normRef = normalizeGlobalRef(dynamicRef);
|
|
859
|
+
params.globalReferences.push(normRef.content.id);
|
|
860
|
+
// Use the normalized ref to generate the attribute expression
|
|
861
|
+
var globalExpr = (0, utils_1.createDynamicValueExpression)(normRef, options);
|
|
862
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier((0, ast_utils_1.resolveAttributeNameForTag)(elementTag, attrKey)), types.jsxExpressionContainer(globalExpr)));
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
if (referenceType === 'globalState') {
|
|
866
|
+
var gsName = (0, utils_1.resolveGlobalStateName)(dynamicRef.content.id, params.globalStateDefinitions);
|
|
867
|
+
params.globalStateReferences.push({ id: dynamicRef.content.id, name: gsName });
|
|
868
|
+
var expr = (0, utils_1.createGlobalStateExpression)(dynamicRef, params.globalStateDefinitions);
|
|
869
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier((0, ast_utils_1.resolveAttributeNameForTag)(elementTag, attrKey)), types.jsxExpressionContainer(expr)));
|
|
870
|
+
break;
|
|
871
|
+
}
|
|
872
|
+
// A translated attribute (`placeholder`, `alt`, `title`, `aria-label`, …).
|
|
873
|
+
// It cannot be emitted the way a translated CHILD is — that path produces a
|
|
874
|
+
// `<span>` the framework plugin fills through `dangerouslySetInnerHTML`, and
|
|
875
|
+
// an attribute needs a plain string. So the attribute is written with the
|
|
876
|
+
// main-language text (carried on the reference's `fallback`) and recorded on
|
|
877
|
+
// `params.localeAttributeReferences`; the target framework's i18n plugin
|
|
878
|
+
// rewrites the recorded attributes into its own translation lookup — see
|
|
879
|
+
// `createNextInternationalizationPlugin`. A framework without such a plugin
|
|
880
|
+
// keeps the main-language string, which is valid, readable markup.
|
|
881
|
+
if (referenceType === 'locale') {
|
|
882
|
+
var translationKey = dynamicRef.content.id;
|
|
883
|
+
if (!translationKey) {
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
// `fallback` only exists on the plain reference member of the union, and
|
|
887
|
+
// narrowing happened on the destructured `referenceType`, not on the ref.
|
|
888
|
+
var fallback = dynamicRef.content.fallback;
|
|
889
|
+
var attribute = types.jsxAttribute(types.jsxIdentifier((0, ast_utils_1.resolveAttributeNameForTag)(elementTag, attrKey)), types.stringLiteral(teleport_shared_1.StringUtils.encode(fallback === undefined ? '' : String(fallback))));
|
|
890
|
+
elementTag.openingElement.attributes.push(attribute);
|
|
891
|
+
params.localeAttributeReferences.push({ attribute: attribute, key: translationKey });
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
// A value read through a mapper (`aria-pressed` from a filter's state, a
|
|
895
|
+
// formatted date) renders through it, as a text binding does. Emitted as
|
|
896
|
+
// the bare reference, the attribute carried the raw value.
|
|
897
|
+
if ((_a = dynamicRef.content.valueMapper) === null || _a === void 0 ? void 0 : _a.trim()) {
|
|
898
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier((0, ast_utils_1.resolveAttributeNameForTag)(elementTag, attrKey)), types.jsxExpressionContainer((0, utils_1.createDynamicValueExpression)(dynamicRef, options))));
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
106
901
|
switch (referenceType) {
|
|
107
902
|
default:
|
|
108
|
-
var prefix = options.dynamicReferencePrefixMap[referenceType];
|
|
109
|
-
|
|
903
|
+
var prefix = options.dynamicReferencePrefixMap[referenceType] || '';
|
|
904
|
+
var idWithRefPath = teleport_shared_1.UIDLUtils.generateIdWithRefPath(dynamicRef.content.id, dynamicRef.content.refPath);
|
|
905
|
+
(0, ast_utils_1.addDynamicAttributeToJSXTag)(elementTag, attrKey, idWithRefPath, prefix);
|
|
110
906
|
break;
|
|
111
907
|
}
|
|
112
908
|
break;
|
|
113
909
|
case 'import':
|
|
114
910
|
(0, ast_utils_1.addDynamicAttributeToJSXTag)(elementTag, attrKey, attributeValue.content.id);
|
|
115
911
|
break;
|
|
116
|
-
case 'raw':
|
|
912
|
+
case 'raw': {
|
|
913
|
+
var rawValue = attributeValue;
|
|
914
|
+
if (elementName === 'markdown-node') {
|
|
915
|
+
if (rawValue.dynamic) {
|
|
916
|
+
applyDynamicMarkdownInjection(elementTag, rawValue, params, options);
|
|
917
|
+
}
|
|
918
|
+
else {
|
|
919
|
+
applyStaticMarkdownInjection(elementTag, rawValue, params);
|
|
920
|
+
}
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
if (elementName === 'rich-text-editor-node') {
|
|
924
|
+
applyRichTextEditorRawAttribute(elementTag, attrKey, rawValue, params, options);
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
if (rawValue.dynamic) {
|
|
928
|
+
applyDynamicHtmlInjection(elementTag, rawValue, params, options);
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
117
931
|
(0, ast_utils_1.addRawAttributeToJSXTag)(elementTag, attrKey, attributeValue);
|
|
118
932
|
break;
|
|
933
|
+
}
|
|
119
934
|
case 'comp-style':
|
|
120
|
-
case 'static':
|
|
121
935
|
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, attrKey, attributeValue.content);
|
|
122
936
|
break;
|
|
937
|
+
case 'static':
|
|
938
|
+
if (typeof attributeValue.content === 'object' &&
|
|
939
|
+
attributeValue.content !== null &&
|
|
940
|
+
!Array.isArray(attributeValue.content)) {
|
|
941
|
+
var constName = "__staticProp".concat(params.hoistedConstants.length);
|
|
942
|
+
var expression = (0, ast_utils_1.objectToObjectExpression)(attributeValue.content);
|
|
943
|
+
params.hoistedConstants.push({ name: constName, expression: expression });
|
|
944
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier((0, ast_utils_1.resolveAttributeNameForTag)(elementTag, attrKey)), types.jsxExpressionContainer(types.identifier(constName))));
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, attrKey, attributeValue.content);
|
|
948
|
+
}
|
|
949
|
+
break;
|
|
123
950
|
case 'expr':
|
|
124
951
|
(0, ast_utils_1.addDynamicExpressionAttributeToJSXTag)(elementTag, attributeValue, attrKey);
|
|
952
|
+
// Scan the *sanitized* content so any globals introduced by the
|
|
953
|
+
// repair (e.g. `/profile/${}` → `/profile/${currentUser?.id}`) still
|
|
954
|
+
// trigger the downstream useGlobalContext() wiring.
|
|
955
|
+
trackGlobalRefsInExpression((0, ast_utils_1.sanitizeExprContent)(String(attributeValue.content), attrKey), params);
|
|
125
956
|
break;
|
|
957
|
+
case 'element':
|
|
958
|
+
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, attrKey, generateElementNode(attributeValue, params, options));
|
|
959
|
+
break;
|
|
960
|
+
case 'object': {
|
|
961
|
+
var content = attributeValue.content;
|
|
962
|
+
if (typeof content !== 'object') {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
var expression = (0, ast_utils_1.objectToObjectExpression)(content);
|
|
966
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier(attrKey), types.jsxExpressionContainer(expression)));
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
126
969
|
default:
|
|
127
970
|
throw new Error("generateElementNode could not generate code for attribute of type ".concat(JSON.stringify(attributeValue)));
|
|
128
971
|
}
|
|
129
972
|
});
|
|
130
973
|
};
|
|
974
|
+
/**
|
|
975
|
+
* Converts text containing {{ expr }} templates into a mix of JSX text and expression containers.
|
|
976
|
+
* e.g. "x{{ (state.score / 10) || '0' }}" → ["x", JSXExpressionContainer((score / 10) || '0')]
|
|
977
|
+
*
|
|
978
|
+
* Uses parseStringWithTemplateExpressions to parse the template into a TemplateLiteral AST,
|
|
979
|
+
* then converts its quasis (text parts) and expressions into JSX children.
|
|
980
|
+
*/
|
|
981
|
+
var convertTextTemplateToJSX = function (text) {
|
|
982
|
+
try {
|
|
983
|
+
var templateLiteral = (0, ast_utils_1.parseStringWithTemplateExpressions)(text);
|
|
984
|
+
var result = [];
|
|
985
|
+
for (var i = 0; i < templateLiteral.quasis.length; i++) {
|
|
986
|
+
var quasi = templateLiteral.quasis[i];
|
|
987
|
+
var textPart = quasi.value.cooked || quasi.value.raw;
|
|
988
|
+
if (textPart) {
|
|
989
|
+
result.push(teleport_shared_1.StringUtils.encode(textPart));
|
|
990
|
+
}
|
|
991
|
+
if (i < templateLiteral.expressions.length) {
|
|
992
|
+
result.push(types.jsxExpressionContainer(templateLiteral.expressions[i]));
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return result.length > 0 ? result : [teleport_shared_1.StringUtils.encode(text)];
|
|
996
|
+
}
|
|
997
|
+
catch (_a) {
|
|
998
|
+
// If parsing fails, fall back to encoded text
|
|
999
|
+
return [teleport_shared_1.StringUtils.encode(text)];
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
131
1002
|
var generateNode = function (node, params, options) {
|
|
1003
|
+
var _a;
|
|
132
1004
|
switch (node.type) {
|
|
133
1005
|
case 'expr':
|
|
134
1006
|
return [generateExpressionNode(node, params, options)];
|
|
135
|
-
case 'raw':
|
|
1007
|
+
case 'raw': {
|
|
1008
|
+
var rawNode = node;
|
|
1009
|
+
if (rawNode.dynamic) {
|
|
1010
|
+
var dynamicExpr = resolveDynamicReferenceExpression(rawNode.dynamic, params, options);
|
|
1011
|
+
var fallback = rawNode.fallback || rawNode.content;
|
|
1012
|
+
return [__1.ASTBuilders.createDynamicDOMInjectionNode(dynamicExpr, fallback)];
|
|
1013
|
+
}
|
|
136
1014
|
return [
|
|
137
1015
|
options.domHTMLInjection
|
|
138
1016
|
? options.domHTMLInjection(node.content.toString())
|
|
139
1017
|
: node.content.toString(),
|
|
140
1018
|
];
|
|
1019
|
+
}
|
|
141
1020
|
case 'inject':
|
|
142
1021
|
if (node === null || node === void 0 ? void 0 : node.dependency) {
|
|
143
|
-
|
|
144
|
-
params.dependencies['Script'] = node.dependency;
|
|
1022
|
+
params.dependencies.Script = node.dependency;
|
|
145
1023
|
}
|
|
146
1024
|
return [node.content.toString()];
|
|
147
|
-
case 'static':
|
|
148
|
-
|
|
1025
|
+
case 'static': {
|
|
1026
|
+
var textContent = node.content.toString();
|
|
1027
|
+
// Check if the text contains {{ }} template expressions
|
|
1028
|
+
if (/\{\{/.test(textContent)) {
|
|
1029
|
+
return convertTextTemplateToJSX(textContent);
|
|
1030
|
+
}
|
|
1031
|
+
return [teleport_shared_1.StringUtils.encode(textContent)];
|
|
1032
|
+
}
|
|
149
1033
|
case 'dynamic':
|
|
150
|
-
|
|
1034
|
+
switch (node.content.referenceType) {
|
|
1035
|
+
case 'prop': {
|
|
1036
|
+
// If the dynamic node is a prop and has a default value of type UIDLElementNode,
|
|
1037
|
+
// we should use it with a logical expression.
|
|
1038
|
+
var prop = params.propDefinitions[node.content.id];
|
|
1039
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'element' && prop.defaultValue) {
|
|
1040
|
+
var prefix = options.dynamicReferencePrefixMap[node.content.referenceType] || '';
|
|
1041
|
+
var propDefault = prop.defaultValue;
|
|
1042
|
+
var jsxNode = params.nodesLookup[propDefault.content.key];
|
|
1043
|
+
if (jsxNode === undefined) {
|
|
1044
|
+
throw Error("Prop ".concat(node.content.id, " is of type element \n\n The JSXNode of the prop-").concat(node.content.id, " is missing from the nodesLookup"));
|
|
1045
|
+
}
|
|
1046
|
+
return [
|
|
1047
|
+
types.logicalExpression('??', prefix === ''
|
|
1048
|
+
? types.identifier(node.content.id)
|
|
1049
|
+
: types.memberExpression(types.identifier(prefix), types.identifier(node.content.id)), jsxNode),
|
|
1050
|
+
];
|
|
1051
|
+
}
|
|
1052
|
+
return [(0, utils_1.createDynamicValueExpression)(node, options)];
|
|
1053
|
+
}
|
|
1054
|
+
case 'locale': {
|
|
1055
|
+
// Locale is not handled the same in all frameworks.
|
|
1056
|
+
// So, we need to handle it differently using individual plugins for each framework.
|
|
1057
|
+
var emptyExpression = types.jsxEmptyExpression();
|
|
1058
|
+
emptyExpression.innerComments = [
|
|
1059
|
+
{
|
|
1060
|
+
type: 'CommentBlock',
|
|
1061
|
+
value: "locale-".concat(node.content.id),
|
|
1062
|
+
},
|
|
1063
|
+
];
|
|
1064
|
+
var expression = types.jsxExpressionContainer(emptyExpression);
|
|
1065
|
+
var jsxTag = (0, ast_builders_1.createJSXTag)('span');
|
|
1066
|
+
(0, ast_utils_1.addChildJSXTag)(jsxTag, expression);
|
|
1067
|
+
params.localeReferences.push(jsxTag);
|
|
1068
|
+
return [jsxTag];
|
|
1069
|
+
}
|
|
1070
|
+
case 'global': {
|
|
1071
|
+
var globalNode = normalizeGlobalRef(node);
|
|
1072
|
+
params.globalReferences.push(globalNode.content.id);
|
|
1073
|
+
return [(0, utils_1.createDynamicValueExpression)(globalNode, options)];
|
|
1074
|
+
}
|
|
1075
|
+
default:
|
|
1076
|
+
if (node.content.referenceType === 'globalState') {
|
|
1077
|
+
var gsName = (0, utils_1.resolveGlobalStateName)(node.content.id, params.globalStateDefinitions);
|
|
1078
|
+
params.globalStateReferences.push({ id: node.content.id, name: gsName });
|
|
1079
|
+
return [
|
|
1080
|
+
(0, utils_1.createGlobalStateExpression)(node, params.globalStateDefinitions),
|
|
1081
|
+
];
|
|
1082
|
+
}
|
|
1083
|
+
return [(0, utils_1.createDynamicValueExpression)(node, options)];
|
|
1084
|
+
}
|
|
151
1085
|
case 'cms-item':
|
|
152
1086
|
case 'cms-list':
|
|
153
1087
|
return generateCMSNode(node, params, options);
|
|
@@ -155,8 +1089,28 @@ var generateNode = function (node, params, options) {
|
|
|
155
1089
|
return generateCMSListRepeaterNode(node, params, options);
|
|
156
1090
|
case 'cms-mixed-type':
|
|
157
1091
|
return generateCMSMixedTypeNode(node, params, options);
|
|
158
|
-
case '
|
|
159
|
-
|
|
1092
|
+
case 'data-source-item':
|
|
1093
|
+
case 'data-source-list':
|
|
1094
|
+
return generateDataSourceNode(node, params, options);
|
|
1095
|
+
case 'element': {
|
|
1096
|
+
// Check if this element node is wrapping a data-source node
|
|
1097
|
+
if (node.content &&
|
|
1098
|
+
typeof node.content === 'object' &&
|
|
1099
|
+
'type' in node.content &&
|
|
1100
|
+
(node.content.type === 'data-source-item' || node.content.type === 'data-source-list')) {
|
|
1101
|
+
// Treat it as a data-source node
|
|
1102
|
+
// tslint:disable-next-line:no-any
|
|
1103
|
+
return generateDataSourceNode(node.content, params, options);
|
|
1104
|
+
}
|
|
1105
|
+
var elementTag = generateElementNode(node, params, options);
|
|
1106
|
+
var renderingConditions = (_a = node.content) === null || _a === void 0 ? void 0 : _a.renderingConditions;
|
|
1107
|
+
if (renderingConditions) {
|
|
1108
|
+
return [
|
|
1109
|
+
wrapWithConditional(elementTag, renderingConditions.reference, renderingConditions.condition, params, options),
|
|
1110
|
+
];
|
|
1111
|
+
}
|
|
1112
|
+
return [elementTag];
|
|
1113
|
+
}
|
|
160
1114
|
case 'repeat':
|
|
161
1115
|
return generateRepeatNode(node, params, options);
|
|
162
1116
|
case 'conditional':
|
|
@@ -174,7 +1128,9 @@ var generateNode = function (node, params, options) {
|
|
|
174
1128
|
};
|
|
175
1129
|
var generateExpressionNode = function (node) {
|
|
176
1130
|
var expression = __1.ASTUtils.getExpressionFromUIDLExpressionNode(node);
|
|
177
|
-
|
|
1131
|
+
// Wrap expression to safely handle objects/arrays: (typeof val === 'object' && val !== null) ? JSON.stringify(val) : val
|
|
1132
|
+
var safeExpression = types.conditionalExpression(types.logicalExpression('&&', types.binaryExpression('===', types.unaryExpression('typeof', expression, true), types.stringLiteral('object')), types.binaryExpression('!==', expression, types.nullLiteral())), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [expression]), expression);
|
|
1133
|
+
return types.jsxExpressionContainer(safeExpression);
|
|
178
1134
|
};
|
|
179
1135
|
var generateCMSMixedTypeNode = function (node, params, options) {
|
|
180
1136
|
var _a = node.content, _b = _a.nodes, error = _b.error, fallback = _b.fallback, elementType = _a.elementType, renderPropIdentifier = _a.renderPropIdentifier, _c = _a.mappings, mappings = _c === void 0 ? {} : _c, attrs = _a.attrs, dependency = _a.dependency;
|
|
@@ -182,14 +1138,14 @@ var generateCMSMixedTypeNode = function (node, params, options) {
|
|
|
182
1138
|
var cmsMixedNode = __1.ASTBuilders.createJSXTag(jsxTag, [], true);
|
|
183
1139
|
var mappingsObject = [];
|
|
184
1140
|
if (attrs) {
|
|
185
|
-
addAttributesToJSXTag(attrs, cmsMixedNode, options);
|
|
1141
|
+
addAttributesToJSXTag(attrs, cmsMixedNode, options, params);
|
|
186
1142
|
}
|
|
187
1143
|
if (dependency) {
|
|
188
1144
|
params.dependencies[elementType] = dependency;
|
|
189
1145
|
}
|
|
190
1146
|
Object.keys(mappings).forEach(function (key) {
|
|
191
1147
|
var element = generateElementNode(mappings[key], params, options);
|
|
192
|
-
mappingsObject.push(types.objectProperty(types.identifier(key), types.arrowFunctionExpression([types.identifier(renderPropIdentifier)], element)));
|
|
1148
|
+
mappingsObject.push(types.objectProperty(types.identifier("\"".concat(key, "\"")), types.arrowFunctionExpression([types.identifier(renderPropIdentifier)], element)));
|
|
193
1149
|
});
|
|
194
1150
|
cmsMixedNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('mappingConfiguration'), types.jsxExpressionContainer(types.objectExpression(mappingsObject))));
|
|
195
1151
|
if (fallback) {
|
|
@@ -201,8 +1157,9 @@ var generateCMSMixedTypeNode = function (node, params, options) {
|
|
|
201
1157
|
return [cmsMixedNode];
|
|
202
1158
|
};
|
|
203
1159
|
var generateCMSNode = function (node, params, options) {
|
|
204
|
-
var _a
|
|
205
|
-
var
|
|
1160
|
+
var _a;
|
|
1161
|
+
var _b = node.content, initialData = _b.initialData, key = _b.key, renderPropIdentifier = _b.renderPropIdentifier, _c = _b.resource, _d = _c === void 0 ? {} : _c, resourceParams = _d.params, router = _b.router, elementType = _b.elementType, dependency = _b.dependency;
|
|
1162
|
+
var _e = node.content.nodes, loading = _e.loading, error = _e.error, success = _e.success;
|
|
206
1163
|
var jsxTag = teleport_shared_1.StringUtils.dashCaseToUpperCamelCase(elementType);
|
|
207
1164
|
if (router && (options === null || options === void 0 ? void 0 : options.dependencyHandling) === 'import') {
|
|
208
1165
|
params.dependencies.useRouter = router;
|
|
@@ -214,8 +1171,13 @@ var generateCMSNode = function (node, params, options) {
|
|
|
214
1171
|
params.dependencies[elementType] = dependency;
|
|
215
1172
|
}
|
|
216
1173
|
var cmsNode = __1.ASTBuilders.createJSXTag(jsxTag, [], true);
|
|
1174
|
+
var cmsDataNodeIdAttr = (_a = node.content
|
|
1175
|
+
.attrs) === null || _a === void 0 ? void 0 : _a.dataNodeId;
|
|
1176
|
+
if (cmsDataNodeIdAttr === null || cmsDataNodeIdAttr === void 0 ? void 0 : cmsDataNodeIdAttr.content) {
|
|
1177
|
+
(0, ast_utils_1.addAttributeToJSXTag)(cmsNode, 'dataNodeId', cmsDataNodeIdAttr.content);
|
|
1178
|
+
}
|
|
217
1179
|
if (node.type === 'cms-item') {
|
|
218
|
-
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderSuccess'), types.jsxExpressionContainer(types.arrowFunctionExpression([types.identifier(renderPropIdentifier)], generateNode(success, params, options)[0]))));
|
|
1180
|
+
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderSuccess'), types.jsxExpressionContainer(types.arrowFunctionExpression([types.identifier(renderPropIdentifier)], generateNode(success, params, __assign(__assign({}, options), { localIdentifier: renderPropIdentifier }))[0]))));
|
|
219
1181
|
}
|
|
220
1182
|
if (node.type === 'cms-list') {
|
|
221
1183
|
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderSuccess'), types.jsxExpressionContainer(types.arrowFunctionExpression([types.identifier('params')], generateNode(success, params, options)[0]))));
|
|
@@ -229,18 +1191,24 @@ var generateCMSNode = function (node, params, options) {
|
|
|
229
1191
|
if (error) {
|
|
230
1192
|
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderError'), types.jsxExpressionContainer(types.arrowFunctionExpression([], generateNode(error, params, options)[0]))));
|
|
231
1193
|
}
|
|
232
|
-
if (initialData && initialData.content.referenceType
|
|
233
|
-
|
|
1194
|
+
if (initialData && initialData.content.referenceType) {
|
|
1195
|
+
var refType = initialData.content.referenceType;
|
|
1196
|
+
var initialDataExpr = refType === 'prop'
|
|
1197
|
+
? types.memberExpression(types.identifier(options.dynamicReferencePrefixMap[refType]), types.identifier(initialData.content.id))
|
|
1198
|
+
: types.identifier(initialData.content.id);
|
|
1199
|
+
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('initialData'), types.jsxExpressionContainer(initialDataExpr)));
|
|
234
1200
|
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('persistDataDuringLoading'), types.jsxExpressionContainer(types.booleanLiteral(true))));
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
1201
|
+
if (refType === 'prop') {
|
|
1202
|
+
var keyValue = 'props?.pagination?.page';
|
|
1203
|
+
if (node.type === 'cms-item') {
|
|
1204
|
+
var entityKeyProperty = node.content.entityKeyProperty;
|
|
1205
|
+
var entityName = initialData.content.id;
|
|
1206
|
+
keyValue = entityKeyProperty
|
|
1207
|
+
? "props?.".concat(entityName, "?.").concat(entityKeyProperty)
|
|
1208
|
+
: "props?.".concat(entityName, "?.id");
|
|
1209
|
+
}
|
|
1210
|
+
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('key'), types.jsxExpressionContainer(types.identifier(keyValue))));
|
|
242
1211
|
}
|
|
243
|
-
cmsNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('key'), types.jsxExpressionContainer(types.identifier(keyValue))));
|
|
244
1212
|
}
|
|
245
1213
|
if (Object.keys(resourceParams || {}).length > 0) {
|
|
246
1214
|
var nodeParams = Object.keys(resourceParams).reduce(function (acc, attrKey) {
|
|
@@ -264,10 +1232,115 @@ var generateCMSNode = function (node, params, options) {
|
|
|
264
1232
|
params.nodesLookup[key] = cmsNode;
|
|
265
1233
|
return [cmsNode];
|
|
266
1234
|
};
|
|
1235
|
+
var generateDataSourceNode = function (node, params, options) {
|
|
1236
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1237
|
+
var _g = node.content, renderPropIdentifier = _g.renderPropIdentifier, elementType = _g.elementType, dependency = _g.dependency, resourceDefinition = _g.resourceDefinition;
|
|
1238
|
+
var key = node.content.key || "ds-".concat(resourceDefinition.dataSourceId, "-").concat(Date.now());
|
|
1239
|
+
var name = node.content.name || renderPropIdentifier;
|
|
1240
|
+
// tslint:disable-next-line:no-any
|
|
1241
|
+
var children = node.content.children && node.content.children.length > 0
|
|
1242
|
+
? node.content.children
|
|
1243
|
+
: ((_a = node.content.nodes) === null || _a === void 0 ? void 0 : _a.success)
|
|
1244
|
+
? [node.content.nodes.success]
|
|
1245
|
+
: [];
|
|
1246
|
+
var jsxTag = teleport_shared_1.StringUtils.dashCaseToUpperCamelCase(elementType);
|
|
1247
|
+
if (dependency && options.dependencyHandling === 'import') {
|
|
1248
|
+
params.dependencies[elementType] = dependency;
|
|
1249
|
+
}
|
|
1250
|
+
var dataSourceNode = __1.ASTBuilders.createJSXTag(jsxTag, [], true);
|
|
1251
|
+
var dataSourceDataNodeIdAttr = (_b = node.content.attrs) === null || _b === void 0 ? void 0 : _b.dataNodeId;
|
|
1252
|
+
if (dataSourceDataNodeIdAttr === null || dataSourceDataNodeIdAttr === void 0 ? void 0 : dataSourceDataNodeIdAttr.content) {
|
|
1253
|
+
(0, ast_utils_1.addAttributeToJSXTag)(dataSourceNode, 'dataNodeId', dataSourceDataNodeIdAttr.content);
|
|
1254
|
+
}
|
|
1255
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('resourceDefinition'), types.jsxExpressionContainer(types.objectExpression([
|
|
1256
|
+
types.objectProperty(types.stringLiteral('type'), types.stringLiteral('external-data-source')),
|
|
1257
|
+
types.objectProperty(types.stringLiteral('dataSourceId'), types.stringLiteral(resourceDefinition.dataSourceId)),
|
|
1258
|
+
types.objectProperty(types.stringLiteral('tableName'), types.stringLiteral(resourceDefinition.tableName)),
|
|
1259
|
+
types.objectProperty(types.stringLiteral('dataSourceType'), types.stringLiteral(resourceDefinition.dataSourceType)),
|
|
1260
|
+
]))));
|
|
1261
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('name'), types.jsxExpressionContainer(types.stringLiteral(name))));
|
|
1262
|
+
if (children && children.length > 0) {
|
|
1263
|
+
// Pass the render prop identifier as the 'ctx' prefix for data source context references
|
|
1264
|
+
// and as the localIdentifier so conditional nodes resolve local refs correctly
|
|
1265
|
+
var childOptions_1 = __assign(__assign({}, options), { localIdentifier: renderPropIdentifier, dynamicReferencePrefixMap: __assign(__assign({}, options.dynamicReferencePrefixMap), { ctx: renderPropIdentifier }) });
|
|
1266
|
+
var childrenNodes = children.flatMap(function (child) { return generateNode(child, params, childOptions_1); });
|
|
1267
|
+
var renderFunction = types.arrowFunctionExpression([types.identifier(renderPropIdentifier)], types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), childrenNodes));
|
|
1268
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderSuccess'), types.jsxExpressionContainer(renderFunction)));
|
|
1269
|
+
}
|
|
1270
|
+
// tslint:disable-next-line:no-any
|
|
1271
|
+
if ((_c = node.content.nodes) === null || _c === void 0 ? void 0 : _c.loading) {
|
|
1272
|
+
// tslint:disable-next-line:no-any
|
|
1273
|
+
var loadingNode = generateNode(node.content.nodes.loading, params, options)[0];
|
|
1274
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderLoading'), types.jsxExpressionContainer(types.arrowFunctionExpression([], loadingNode))));
|
|
1275
|
+
}
|
|
1276
|
+
// tslint:disable-next-line:no-any
|
|
1277
|
+
if ((_d = node.content.nodes) === null || _d === void 0 ? void 0 : _d.error) {
|
|
1278
|
+
// tslint:disable-next-line:no-any
|
|
1279
|
+
var errorNode = generateNode(node.content.nodes.error, params, options)[0];
|
|
1280
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderError'), types.jsxExpressionContainer(types.arrowFunctionExpression([], errorNode))));
|
|
1281
|
+
}
|
|
1282
|
+
// Add resource params if they exist
|
|
1283
|
+
// tslint:disable-next-line:no-any
|
|
1284
|
+
var resourceParams = (_e = node.content.resource) === null || _e === void 0 ? void 0 : _e.params;
|
|
1285
|
+
if (resourceParams && Object.keys(resourceParams).length > 0) {
|
|
1286
|
+
var nodeParams = Object.keys(resourceParams).reduce(function (acc, attrKey) {
|
|
1287
|
+
var property = resourceParams[attrKey];
|
|
1288
|
+
if (property.type === 'static') {
|
|
1289
|
+
// Special handling for filters array - convert dynamic destinations
|
|
1290
|
+
if (attrKey === 'filters' && Array.isArray(property.content)) {
|
|
1291
|
+
var filterEntries = property.content.map(function (filter) {
|
|
1292
|
+
return buildFilterNodeExpression(filter, options.dynamicReferencePrefixMap);
|
|
1293
|
+
});
|
|
1294
|
+
// Drop conditions whose destination resolves to an empty value at
|
|
1295
|
+
// runtime (empty string / null / undefined, or an empty
|
|
1296
|
+
// array-overlap set) so a "show all" reset means no filter rather
|
|
1297
|
+
// than a query that matches zero rows. Mirrors the Next.js pages
|
|
1298
|
+
// path's `buildNonEmptyDestinationPredicate` (kept inline here
|
|
1299
|
+
// because teleport-plugin-common must not depend on the
|
|
1300
|
+
// next-data-source plugin).
|
|
1301
|
+
// JSON.stringify because these params are handed to
|
|
1302
|
+
// `new URLSearchParams(params)`, which would otherwise stringify the
|
|
1303
|
+
// array to '[object Object]' and lose every filter in transit.
|
|
1304
|
+
acc.push(types.objectProperty(types.stringLiteral(attrKey), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [
|
|
1305
|
+
types.callExpression(types.memberExpression(types.arrayExpression(filterEntries), types.identifier('filter')), [buildSurvivingFilterNodePredicate()]),
|
|
1306
|
+
])));
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
acc.push(types.objectProperty(types.stringLiteral(attrKey), (0, ast_utils_1.resolveObjectValue)(property)));
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (property.type === 'expr') {
|
|
1313
|
+
var expression = __1.ASTUtils.getExpressionFromUIDLExpressionNode(property);
|
|
1314
|
+
acc.push(types.objectProperty(types.stringLiteral(attrKey), expression));
|
|
1315
|
+
}
|
|
1316
|
+
if (property.type === 'dynamic') {
|
|
1317
|
+
var refType = property.content.referenceType;
|
|
1318
|
+
acc.push(types.objectProperty(types.stringLiteral(attrKey), property.content.referenceType === 'prop'
|
|
1319
|
+
? types.memberExpression(types.identifier(options.dynamicReferencePrefixMap[refType]), types.identifier(property.content.id))
|
|
1320
|
+
: types.identifier(property.content.id)));
|
|
1321
|
+
}
|
|
1322
|
+
return acc;
|
|
1323
|
+
}, []);
|
|
1324
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('params'), types.jsxExpressionContainer(types.objectExpression(nodeParams))));
|
|
1325
|
+
}
|
|
1326
|
+
// Add initialData if the UIDL node has it (similar to CMS nodes)
|
|
1327
|
+
// tslint:disable-next-line:no-any
|
|
1328
|
+
var nodeInitialData = node.content.initialData;
|
|
1329
|
+
if (nodeInitialData && ((_f = nodeInitialData.content) === null || _f === void 0 ? void 0 : _f.referenceType)) {
|
|
1330
|
+
var refType = nodeInitialData.content.referenceType;
|
|
1331
|
+
var initialDataExpr = refType === 'prop'
|
|
1332
|
+
? types.memberExpression(types.identifier(options.dynamicReferencePrefixMap[refType]), types.identifier(nodeInitialData.content.id))
|
|
1333
|
+
: types.identifier(nodeInitialData.content.id);
|
|
1334
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('initialData'), types.jsxExpressionContainer(initialDataExpr)));
|
|
1335
|
+
dataSourceNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('persistDataDuringLoading'), types.jsxExpressionContainer(types.booleanLiteral(true))));
|
|
1336
|
+
}
|
|
1337
|
+
params.nodesLookup[key] = dataSourceNode;
|
|
1338
|
+
return [dataSourceNode];
|
|
1339
|
+
};
|
|
267
1340
|
var generateRepeatNode = function (node, params, options) {
|
|
268
1341
|
var _a = node.content, repeatContent = _a.node, dataSource = _a.dataSource, meta = _a.meta;
|
|
269
|
-
var contentASTs = generateNode(repeatContent, params, options);
|
|
270
1342
|
var _b = teleport_shared_1.UIDLUtils.getRepeatIteratorNameAndKey(meta), iteratorName = _b.iteratorName, iteratorKey = _b.iteratorKey;
|
|
1343
|
+
var contentASTs = generateNode(repeatContent, params, __assign(__assign({}, options), { localIdentifier: iteratorName }));
|
|
271
1344
|
var localIteratorPrefix = options.dynamicReferencePrefixMap.local;
|
|
272
1345
|
contentASTs.forEach(function (contentAST) {
|
|
273
1346
|
(0, ast_utils_1.addDynamicAttributeToJSXTag)(contentAST, 'key', iteratorKey, localIteratorPrefix);
|
|
@@ -283,25 +1356,198 @@ var generateRepeatNode = function (node, params, options) {
|
|
|
283
1356
|
]));
|
|
284
1357
|
});
|
|
285
1358
|
};
|
|
1359
|
+
// Tracks a condition reference's global / globalState usage on params and
|
|
1360
|
+
// resolves it to a ConditionalIdentifier. Shared by the top-level reference
|
|
1361
|
+
// and the optional per-entry references of a conditional expression.
|
|
1362
|
+
var trackAndResolveConditionIdentifier = function (reference, params, options) {
|
|
1363
|
+
if (reference.type === 'dynamic' &&
|
|
1364
|
+
'referenceType' in reference.content &&
|
|
1365
|
+
reference.content.referenceType === 'global') {
|
|
1366
|
+
var normCondRef = normalizeGlobalRef(reference);
|
|
1367
|
+
params.globalReferences.push(normCondRef.content.id);
|
|
1368
|
+
}
|
|
1369
|
+
if (reference.type === 'dynamic' &&
|
|
1370
|
+
'referenceType' in reference.content &&
|
|
1371
|
+
reference.content.referenceType === 'globalState') {
|
|
1372
|
+
var gsName = (0, utils_1.resolveGlobalStateName)(reference.content.id, params.globalStateDefinitions);
|
|
1373
|
+
params.globalStateReferences.push({ id: reference.content.id, name: gsName });
|
|
1374
|
+
}
|
|
1375
|
+
var effectiveRef = reference.type === 'dynamic' &&
|
|
1376
|
+
'referenceType' in reference.content &&
|
|
1377
|
+
reference.content.referenceType === 'global'
|
|
1378
|
+
? normalizeGlobalRef(reference)
|
|
1379
|
+
: reference;
|
|
1380
|
+
return (0, utils_1.createConditionIdentifier)(effectiveRef, params, options);
|
|
1381
|
+
};
|
|
1382
|
+
// Shared between UIDLConditionalNode (wraps a child subtree) and the inline
|
|
1383
|
+
// `renderingConditions` property on UIDLElement content. Tracks global and
|
|
1384
|
+
// globalState references on params, resolves the condition identifier — plus
|
|
1385
|
+
// one identifier per entry that carries its own `reference` — and builds the
|
|
1386
|
+
// `condition && <content/>` logical expression.
|
|
1387
|
+
var wrapWithConditional = function (subTree, reference, condition, params, options) {
|
|
1388
|
+
var conditionIdentifier = trackAndResolveConditionIdentifier(reference, params, options);
|
|
1389
|
+
return (0, utils_1.createConditionalJSXExpression)(subTree, condition, conditionIdentifier, {
|
|
1390
|
+
localIdentifier: options.localIdentifier,
|
|
1391
|
+
detailsPageExposeAsName: options.detailsPageExposeAsName || params.detailsPageExposeAsName,
|
|
1392
|
+
// Leaf entries (any nesting depth) with their own left side resolve —
|
|
1393
|
+
// and globals-track — through the same path as the top-level reference.
|
|
1394
|
+
resolveEntryIdentifier: function (conditionEntry) {
|
|
1395
|
+
return conditionEntry.reference
|
|
1396
|
+
? trackAndResolveConditionIdentifier(conditionEntry.reference, params, options)
|
|
1397
|
+
: undefined;
|
|
1398
|
+
},
|
|
1399
|
+
});
|
|
1400
|
+
};
|
|
286
1401
|
var generateConditionalNode = function (node, params, options) {
|
|
287
1402
|
var _a = node.content, reference = _a.reference, value = _a.value;
|
|
288
|
-
var conditionIdentifier = (0, utils_1.createConditionIdentifier)(reference, params, options);
|
|
289
1403
|
var subTrees = generateNode(node.content.node, params, options);
|
|
290
1404
|
var condition = value !== undefined && value !== null
|
|
291
1405
|
? { conditions: [{ operand: value, operation: '===' }] }
|
|
292
1406
|
: node.content.condition;
|
|
293
1407
|
return subTrees.map(function (subTree) {
|
|
294
|
-
return (
|
|
1408
|
+
return wrapWithConditional(subTree, reference, condition, params, options);
|
|
295
1409
|
});
|
|
296
1410
|
};
|
|
1411
|
+
// The repeater renders its `loading` branch INSTEAD of itself when the node
|
|
1412
|
+
// carries an `isLoading` signal. Hence `JSXASTReturnType[]` rather than
|
|
1413
|
+
// `types.JSXElement[]`: that form is a conditional EXPRESSION, which the parent
|
|
1414
|
+
// element loop wraps in a `{ … }` container the same way it already does for a
|
|
1415
|
+
// conditional node's logical expression.
|
|
297
1416
|
var generateCMSListRepeaterNode = function (node, params, options) {
|
|
298
|
-
var _a;
|
|
299
|
-
var
|
|
300
|
-
repeaterNode
|
|
301
|
-
|
|
1417
|
+
var _a, _b, _c;
|
|
1418
|
+
var jsxTag = teleport_shared_1.StringUtils.dashCaseToUpperCamelCase(node.content.elementType);
|
|
1419
|
+
var repeaterNode = __1.ASTBuilders.createJSXTag(jsxTag, [], true);
|
|
1420
|
+
var dataNodeIdAttr = (_a = node.content.attrs) === null || _a === void 0 ? void 0 : _a.dataNodeId;
|
|
1421
|
+
if (dataNodeIdAttr === null || dataNodeIdAttr === void 0 ? void 0 : dataNodeIdAttr.content) {
|
|
1422
|
+
(0, ast_utils_1.addAttributeToJSXTag)(repeaterNode, 'dataNodeId', dataNodeIdAttr.content);
|
|
1423
|
+
}
|
|
1424
|
+
// When the repeater source is a global context like "ecommerce", resolve to
|
|
1425
|
+
// the appropriate array from the ecommerce context based on what the repeater
|
|
1426
|
+
// iterates over (determined by renderPropIdentifier). The editor's mapper
|
|
1427
|
+
// keeps only the global's id, not the array's path, so the identifier is the
|
|
1428
|
+
// whole contract: every e-commerce list the editor builds names its context
|
|
1429
|
+
// after one of these keys.
|
|
1430
|
+
var repeaterItemsExpr;
|
|
1431
|
+
var source = (_b = node.content.source) !== null && _b !== void 0 ? _b : 'params';
|
|
1432
|
+
if (source === 'ecommerce') {
|
|
1433
|
+
var rpId = node.content.renderPropIdentifier || '';
|
|
1434
|
+
// Map renderPropIdentifier to the correct ecommerce context path
|
|
1435
|
+
var ecommercePathMap = {
|
|
1436
|
+
paymentProvider: ['paymentProviders'],
|
|
1437
|
+
// The providers a cart holding a subscription is offered — the checkout's
|
|
1438
|
+
// second method list. Same fallthrough hazard as `shippingMethod`.
|
|
1439
|
+
subscriptionPaymentProvider: ['subscriptionPaymentProviders'],
|
|
1440
|
+
storeLocation: ['storeLocations'],
|
|
1441
|
+
// The checkout's shipping-method list (`Cart.shippingOptions`). Without
|
|
1442
|
+
// this entry it fell to the cart items below and offered the buyer their
|
|
1443
|
+
// own products as shipping methods.
|
|
1444
|
+
shippingMethod: ['Cart', 'shippingOptions'],
|
|
1445
|
+
// The checkout's "Choose your discount" list, in each fulfilment shape.
|
|
1446
|
+
discountOption: ['Cart', 'discountOptions'],
|
|
1447
|
+
discountOptionPickup: ['Cart', 'discountOptionsPickup'],
|
|
1448
|
+
};
|
|
1449
|
+
// Default: cart items for orderItem, cartItem, or any unrecognized identifier
|
|
1450
|
+
var path = ecommercePathMap[rpId] || ['Cart', 'items'];
|
|
1451
|
+
var expr = types.identifier('ecommerce');
|
|
1452
|
+
for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
|
|
1453
|
+
var seg = path_1[_i];
|
|
1454
|
+
expr = types.optionalMemberExpression(expr, types.identifier(seg), false, true);
|
|
1455
|
+
}
|
|
1456
|
+
repeaterItemsExpr = types.logicalExpression('||', expr, types.arrayExpression([]));
|
|
1457
|
+
params.globalReferences.push('ecommerce');
|
|
1458
|
+
}
|
|
1459
|
+
else if (source === 'ecommerceCategories') {
|
|
1460
|
+
// The `E-Commerce Categories` global (the nested category tree) is baked
|
|
1461
|
+
// onto the ecommerce context as `ecommerce.ecommerceCategories`. Fixed
|
|
1462
|
+
// one-segment path (independent of the item name) → `ecommerce?.ecommerceCategories || []`.
|
|
1463
|
+
var expr = types.optionalMemberExpression(types.identifier('ecommerce'), types.identifier('ecommerceCategories'), false, true);
|
|
1464
|
+
repeaterItemsExpr = types.logicalExpression('||', expr, types.arrayExpression([]));
|
|
1465
|
+
params.globalReferences.push('ecommerce');
|
|
1466
|
+
}
|
|
1467
|
+
else if (source === 'blogCategories') {
|
|
1468
|
+
// The `Blog Categories` global. Unlike the store's taxonomy this one is NOT
|
|
1469
|
+
// on a provider context — the generated `@/blog-context` module exposes it
|
|
1470
|
+
// through a memoized `useBlogCategories()` hook, which the component plugin
|
|
1471
|
+
// destructures into a plain `blogCategories` identifier when it sees this
|
|
1472
|
+
// reference. → `blogCategories || []`.
|
|
1473
|
+
repeaterItemsExpr = types.logicalExpression('||', types.identifier('blogCategories'), types.arrayExpression([]));
|
|
1474
|
+
params.globalReferences.push('blogCategories');
|
|
1475
|
+
}
|
|
1476
|
+
else if (source === 'helpCategories') {
|
|
1477
|
+
// The Help Center's taxonomy, exposed by the same module as `useHelpCategories()`.
|
|
1478
|
+
repeaterItemsExpr = types.logicalExpression('||', types.identifier('helpCategories'), types.arrayExpression([]));
|
|
1479
|
+
params.globalReferences.push('helpCategories');
|
|
1480
|
+
}
|
|
1481
|
+
else if (source === 'bookingCategories') {
|
|
1482
|
+
// The `Booking Categories` global, like the blog's: the generated
|
|
1483
|
+
// `@/booking-context` module's `useBookingCategories()` hook, destructured
|
|
1484
|
+
// into a plain `bookingCategories` identifier. → `bookingCategories || []`.
|
|
1485
|
+
repeaterItemsExpr = types.logicalExpression('||', types.identifier('bookingCategories'), types.arrayExpression([]));
|
|
1486
|
+
params.globalReferences.push('bookingCategories');
|
|
1487
|
+
}
|
|
1488
|
+
else {
|
|
1489
|
+
// Resolve any global-state reference encoded in `source` and register it
|
|
1490
|
+
// so the `next-global-state` component plugin destructures the matching
|
|
1491
|
+
// identifier from `useGlobalState()`. Without this, sources emitted as
|
|
1492
|
+
// either `<globalStateName> || []` (modern) or `globalState_<defId>`
|
|
1493
|
+
// (legacy) compile to a `ReferenceError` at render time because the
|
|
1494
|
+
// identifier never enters scope.
|
|
1495
|
+
var resolvedSource = (0, utils_1.resolveAndRegisterGlobalStateSource)(source, params);
|
|
1496
|
+
repeaterItemsExpr = types.identifier(resolvedSource);
|
|
1497
|
+
}
|
|
1498
|
+
repeaterNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('items'), types.jsxExpressionContainer(repeaterItemsExpr)));
|
|
1499
|
+
var listElement = generateNode(node.content.nodes.list, params, __assign(__assign({}, options), { localIdentifier: node.content.renderPropIdentifier, dynamicReferencePrefixMap: __assign(__assign({}, options.dynamicReferencePrefixMap), { ctx: node.content.renderPropIdentifier }) }))[0];
|
|
1500
|
+
// Create key as template literal: `${item?.id}${index}`
|
|
1501
|
+
var keyAttribute = types.jsxAttribute(types.jsxIdentifier('key'), types.jsxExpressionContainer(types.templateLiteral([
|
|
1502
|
+
types.templateElement({ raw: '', cooked: '' }, false),
|
|
1503
|
+
types.templateElement({ raw: '', cooked: '' }, false),
|
|
1504
|
+
types.templateElement({ raw: '', cooked: '' }, true),
|
|
1505
|
+
], [
|
|
1506
|
+
types.optionalMemberExpression(types.identifier(node.content.renderPropIdentifier), types.identifier('id'), false, true),
|
|
1507
|
+
types.identifier('index'),
|
|
1508
|
+
])));
|
|
1509
|
+
listElement.openingElement.attributes.push(keyAttribute);
|
|
1510
|
+
repeaterNode.openingElement.attributes.push(types.jsxAttribute(types.jSXIdentifier('renderItem'), types.jsxExpressionContainer(types.arrowFunctionExpression([types.identifier(node.content.renderPropIdentifier), types.identifier('index')], listElement))));
|
|
302
1511
|
if ('empty' in node.content.nodes) {
|
|
303
1512
|
repeaterNode.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('renderEmpty'), types.jsxExpressionContainer(types.arrowFunctionExpression([], generateNode(node.content.nodes.empty, params, options)[0]))));
|
|
304
1513
|
}
|
|
1514
|
+
// Generated on EVERY repeater for its side effects — `nodesLookup` registration,
|
|
1515
|
+
// style classes, and the head snippets a loading template rides out on (a
|
|
1516
|
+
// skeleton card's `@keyframes`). Whether the result is also RENDERED depends on
|
|
1517
|
+
// `isLoading` below.
|
|
1518
|
+
var loadingElement;
|
|
1519
|
+
if ('loading' in node.content.nodes) {
|
|
1520
|
+
loadingElement = generateNode(node.content.nodes.loading, params, options)[0];
|
|
1521
|
+
}
|
|
1522
|
+
if (((_c = node.content) === null || _c === void 0 ? void 0 : _c.dependency) && options.dependencyHandling === 'import') {
|
|
1523
|
+
params.dependencies[jsxTag] = node.content.dependency;
|
|
1524
|
+
}
|
|
1525
|
+
// A repeater fed by a DATA SOURCE never carries `isLoading`: it sits inside a
|
|
1526
|
+
// `DataProvider` that owns the fetch, and its loading branch is hoisted onto
|
|
1527
|
+
// that provider's `renderLoading` (`hoistLoadingFromRepeaterToDataSource`).
|
|
1528
|
+
// Emitting it here as well would draw the same branch twice. A repeater fed by
|
|
1529
|
+
// a plain STATE has no provider, so this is the only thing that can tell it a
|
|
1530
|
+
// fetch is in flight — without it the `loading` branch is generated and then
|
|
1531
|
+
// thrown away, which is why a state-backed list used to show its EMPTY branch
|
|
1532
|
+
// for the whole duration of the fetch.
|
|
1533
|
+
var isLoading = node.content.isLoading;
|
|
1534
|
+
if (isLoading &&
|
|
1535
|
+
loadingElement &&
|
|
1536
|
+
typeof loadingElement !== 'string' &&
|
|
1537
|
+
// A `JSXExpressionContainer` is only legal as a CHILD, never as a ternary
|
|
1538
|
+
// branch. The loading root is a fragment or an element, so this never fires
|
|
1539
|
+
// in practice — it is here so a future node type cannot emit invalid code.
|
|
1540
|
+
loadingElement.type !== 'JSXExpressionContainer') {
|
|
1541
|
+
// `String(x) === 'true'`, never a bare truthiness test. The flag is a page
|
|
1542
|
+
// state, and a generated string state holds the STRING `'false'` when it is
|
|
1543
|
+
// off — which is truthy. `String()` equally accepts a real boolean.
|
|
1544
|
+
var flag = isLoading.type === 'expr'
|
|
1545
|
+
? __1.ASTUtils.getExpressionFromUIDLExpressionNode(isLoading)
|
|
1546
|
+
: types.stringLiteral(String(isLoading.content));
|
|
1547
|
+
return [
|
|
1548
|
+
types.conditionalExpression(types.binaryExpression('===', types.callExpression(types.identifier('String'), [flag]), types.stringLiteral('true')), loadingElement, repeaterNode),
|
|
1549
|
+
];
|
|
1550
|
+
}
|
|
305
1551
|
return [repeaterNode];
|
|
306
1552
|
};
|
|
307
1553
|
var generatePropsSlotNode = function (node, params, options) {
|
|
@@ -349,4 +1595,156 @@ var generateNativeSlotNode = function (node, params, options) {
|
|
|
349
1595
|
}
|
|
350
1596
|
return slotNode;
|
|
351
1597
|
};
|
|
1598
|
+
var resolveDynamicReferenceExpression = function (dynamicRef, params, options) {
|
|
1599
|
+
var referenceType = dynamicRef.content.referenceType;
|
|
1600
|
+
if (referenceType === 'global') {
|
|
1601
|
+
var normDynRef = normalizeGlobalRef(dynamicRef);
|
|
1602
|
+
params.globalReferences.push(normDynRef.content.id);
|
|
1603
|
+
return (0, utils_1.createDynamicValueExpression)(normDynRef, options);
|
|
1604
|
+
}
|
|
1605
|
+
if (referenceType === 'globalState') {
|
|
1606
|
+
var gsName = (0, utils_1.resolveGlobalStateName)(dynamicRef.content.id, params.globalStateDefinitions);
|
|
1607
|
+
params.globalStateReferences.push({ id: dynamicRef.content.id, name: gsName });
|
|
1608
|
+
return (0, utils_1.createGlobalStateExpression)(dynamicRef, params.globalStateDefinitions);
|
|
1609
|
+
}
|
|
1610
|
+
return (0, utils_1.createDynamicValueExpression)(dynamicRef, options);
|
|
1611
|
+
};
|
|
1612
|
+
var applyDynamicHtmlInjection = function (elementTag, rawValue, params, options) {
|
|
1613
|
+
var dynamicExpr = resolveDynamicReferenceExpression(rawValue.dynamic, params, options);
|
|
1614
|
+
var fallbackContent = rawValue.fallback || rawValue.content;
|
|
1615
|
+
var fallbackExpr = types.stringLiteral(fallbackContent);
|
|
1616
|
+
var valueExpr = types.logicalExpression('||', dynamicExpr, fallbackExpr);
|
|
1617
|
+
elementTag.openingElement.name.name = 'span';
|
|
1618
|
+
if (elementTag.closingElement) {
|
|
1619
|
+
;
|
|
1620
|
+
elementTag.closingElement.name.name = 'span';
|
|
1621
|
+
}
|
|
1622
|
+
elementTag.openingElement.selfClosing = true;
|
|
1623
|
+
elementTag.closingElement = null;
|
|
1624
|
+
elementTag.children = [];
|
|
1625
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('dangerouslySetInnerHTML'), types.jsxExpressionContainer(types.objectExpression([types.objectProperty(types.identifier('__html'), valueExpr)]))));
|
|
1626
|
+
Object.keys(params.dependencies).forEach(function (key) {
|
|
1627
|
+
var _a, _b;
|
|
1628
|
+
if ((_b = (_a = params.dependencies[key]) === null || _a === void 0 ? void 0 : _a.path) === null || _b === void 0 ? void 0 : _b.includes('dangerous-html')) {
|
|
1629
|
+
delete params.dependencies[key];
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
};
|
|
1633
|
+
var applyStaticMarkdownInjection = function (elementTag, rawValue, params) {
|
|
1634
|
+
injectMarkdownExpression(elementTag, types.stringLiteral(rawValue.content || ''), '', params);
|
|
1635
|
+
};
|
|
1636
|
+
var applyDynamicMarkdownInjection = function (elementTag, rawValue, params, options) {
|
|
1637
|
+
var dynamicExpr = resolveDynamicReferenceExpression(rawValue.dynamic, params, options);
|
|
1638
|
+
var fallbackContent = rawValue.fallback || rawValue.content;
|
|
1639
|
+
injectMarkdownExpression(elementTag, dynamicExpr, fallbackContent, params);
|
|
1640
|
+
};
|
|
1641
|
+
/**
|
|
1642
|
+
* Renders a markdown-node's rich-text content through the `markdown-to-jsx` <Markdown>
|
|
1643
|
+
* component (the React generator's mapping for markdown-node).
|
|
1644
|
+
*
|
|
1645
|
+
* markdown-to-jsx parses BOTH markdown syntax AND embedded HTML, so it renders correctly
|
|
1646
|
+
* whether the CMS field returns markdown (`# Heading`) or HTML markup (`<p>…</p>`). A raw
|
|
1647
|
+
* HTML approach (dangerouslySetInnerHTML) would ignore markdown, and a markdown-only
|
|
1648
|
+
* renderer (react-markdown) escapes HTML — markdown-to-jsx covers both at once.
|
|
1649
|
+
*
|
|
1650
|
+
* Shared by every way a markdown-node can carry its content:
|
|
1651
|
+
* - a static `raw` attribute (see applyStaticMarkdownInjection)
|
|
1652
|
+
* - a `raw` attribute holding a dynamic reference (see applyDynamicMarkdownInjection)
|
|
1653
|
+
* - a dynamic/expr child, e.g. CMS-bound rich text (see generateElementNode)
|
|
1654
|
+
*
|
|
1655
|
+
* Produces: <Markdown>{expr || fallback}</Markdown>
|
|
1656
|
+
*/
|
|
1657
|
+
var injectMarkdownExpression = function (elementTag, expression, fallbackContent, params) {
|
|
1658
|
+
// markdown-to-jsx requires a string child; guard dynamic expressions with a fallback so
|
|
1659
|
+
// a nullish CMS value renders as empty rather than throwing. Static literals need no guard.
|
|
1660
|
+
var childExpr = types.isStringLiteral(expression)
|
|
1661
|
+
? expression
|
|
1662
|
+
: types.logicalExpression('||', expression, types.stringLiteral(fallbackContent || ''));
|
|
1663
|
+
elementTag.openingElement.name.name = 'Markdown';
|
|
1664
|
+
elementTag.openingElement.selfClosing = false;
|
|
1665
|
+
if (!elementTag.closingElement) {
|
|
1666
|
+
elementTag.closingElement = types.jsxClosingElement(types.jsxIdentifier('Markdown'));
|
|
1667
|
+
}
|
|
1668
|
+
else {
|
|
1669
|
+
;
|
|
1670
|
+
elementTag.closingElement.name.name = 'Markdown';
|
|
1671
|
+
}
|
|
1672
|
+
elementTag.children = [types.jsxExpressionContainer(childExpr)];
|
|
1673
|
+
params.dependencies.Markdown = {
|
|
1674
|
+
type: 'package',
|
|
1675
|
+
path: 'markdown-to-jsx',
|
|
1676
|
+
version: '7.7.12',
|
|
1677
|
+
};
|
|
1678
|
+
};
|
|
1679
|
+
/**
|
|
1680
|
+
* Handles raw attributes on a rich-text-editor-node element.
|
|
1681
|
+
*
|
|
1682
|
+
* - `html` attribute → becomes a `value` prop (static string or dynamic expression with fallback)
|
|
1683
|
+
* - `quillFormats` attribute → parsed from JSON string into a JS array expression
|
|
1684
|
+
*/
|
|
1685
|
+
var applyRichTextEditorRawAttribute = function (elementTag, attrKey, rawValue, params, options) {
|
|
1686
|
+
if (attrKey === 'html' && params.formStoreStateName) {
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
if (attrKey === 'html') {
|
|
1690
|
+
if (rawValue.dynamic) {
|
|
1691
|
+
var dynamicExpr = resolveDynamicReferenceExpression(rawValue.dynamic, params, options);
|
|
1692
|
+
var fallbackContent = rawValue.fallback || rawValue.content || '';
|
|
1693
|
+
var valueExpr = types.logicalExpression('||', dynamicExpr, types.stringLiteral(fallbackContent));
|
|
1694
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('value'), types.jsxExpressionContainer(valueExpr)));
|
|
1695
|
+
}
|
|
1696
|
+
else {
|
|
1697
|
+
var content = rawValue.content || '';
|
|
1698
|
+
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, 'value', content);
|
|
1699
|
+
}
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
if (attrKey === 'quillFormats') {
|
|
1703
|
+
var formats = null;
|
|
1704
|
+
try {
|
|
1705
|
+
var parsed = JSON.parse(rawValue.content);
|
|
1706
|
+
if (Array.isArray(parsed)) {
|
|
1707
|
+
formats = parsed;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
catch (_a) {
|
|
1711
|
+
// Parsing failed → don't add the attribute; component will use all formats
|
|
1712
|
+
}
|
|
1713
|
+
if (formats === null) {
|
|
1714
|
+
// Parse failure or not an array → omit attribute so component uses all formats
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
var arrayExpr = types.arrayExpression(formats.map(function (f) { return types.stringLiteral(f); }));
|
|
1718
|
+
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('quillFormats'), types.jsxExpressionContainer(arrayExpr)));
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
// Any other raw attribute on rich-text-editor-node: fall through to default handling
|
|
1722
|
+
(0, ast_utils_1.addRawAttributeToJSXTag)(elementTag, attrKey, rawValue);
|
|
1723
|
+
};
|
|
1724
|
+
/**
|
|
1725
|
+
* `color: red; margin-top: 4px` → `{ color: 'red', marginTop: '4px' }`, the
|
|
1726
|
+
* shape React wants for `style`. Custom properties keep their `--name`.
|
|
1727
|
+
*/
|
|
1728
|
+
function parseInlineStyleText(value) {
|
|
1729
|
+
if (typeof value !== 'string') {
|
|
1730
|
+
return undefined;
|
|
1731
|
+
}
|
|
1732
|
+
var inlineStyle = {};
|
|
1733
|
+
value.split(';').forEach(function (declaration) {
|
|
1734
|
+
var separator = declaration.indexOf(':');
|
|
1735
|
+
if (separator < 1) {
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
var property = declaration.slice(0, separator).trim();
|
|
1739
|
+
var propertyValue = declaration.slice(separator + 1).trim();
|
|
1740
|
+
if (!property || !propertyValue) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
var key = property.startsWith('--')
|
|
1744
|
+
? property
|
|
1745
|
+
: teleport_shared_1.StringUtils.cssPropertyToInlineStyleKey(property);
|
|
1746
|
+
inlineStyle[key] = propertyValue;
|
|
1747
|
+
});
|
|
1748
|
+
return inlineStyle;
|
|
1749
|
+
}
|
|
352
1750
|
//# sourceMappingURL=index.js.map
|