@teleporthq/teleport-plugin-common 0.43.42 → 0.43.46
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__/node-handlers/node-to-jsx/utils.ts +55 -0
- package/__tests__/utils/url-search-param-sync.ts +42 -0
- package/dist/cjs/node-handlers/node-to-html/utils.js +24 -11
- 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 +117 -4
- package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.js +41 -22
- 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.map +1 -1
- package/dist/cjs/utils/ast-utils.js +36 -0
- package/dist/cjs/utils/ast-utils.js.map +1 -1
- package/dist/cjs/utils/url-search-param-sync.d.ts +2 -2
- package/dist/cjs/utils/url-search-param-sync.d.ts.map +1 -1
- package/dist/cjs/utils/url-search-param-sync.js +38 -6
- package/dist/cjs/utils/url-search-param-sync.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/utils.js +24 -11
- 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 +115 -5
- package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.js +41 -22
- 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.map +1 -1
- package/dist/esm/utils/ast-utils.js +36 -0
- package/dist/esm/utils/ast-utils.js.map +1 -1
- package/dist/esm/utils/url-search-param-sync.d.ts +2 -2
- package/dist/esm/utils/url-search-param-sync.d.ts.map +1 -1
- package/dist/esm/utils/url-search-param-sync.js +38 -6
- package/dist/esm/utils/url-search-param-sync.js.map +1 -1
- package/package.json +4 -4
- package/src/node-handlers/node-to-html/utils.ts +33 -11
- package/src/node-handlers/node-to-jsx/index.ts +190 -22
- package/src/node-handlers/node-to-jsx/utils.ts +63 -30
- package/src/utils/ast-utils.ts +39 -0
- package/src/utils/url-search-param-sync.ts +50 -10
|
@@ -110,6 +110,61 @@ describe('createBinaryExpression', () => {
|
|
|
110
110
|
prefix: true,
|
|
111
111
|
})
|
|
112
112
|
})
|
|
113
|
+
|
|
114
|
+
// A rendering condition exists to HIDE a node — it must never be able to throw.
|
|
115
|
+
// The bound value is nullish far more often than it looks (an optional CMS
|
|
116
|
+
// column, a category with no image, an unhydrated state), and a bare
|
|
117
|
+
// `x.length` / `x.includes(...)` took whole pages down with
|
|
118
|
+
// "Cannot read properties of null (reading 'length')".
|
|
119
|
+
describe('collection operators are null-safe', () => {
|
|
120
|
+
const codeOf = (
|
|
121
|
+
condition: { operation: string; operand?: string; containsField?: string },
|
|
122
|
+
type = 'array'
|
|
123
|
+
) => generate(createBinaryExpression(condition, { key: 'imageUrl', type }) as types.Node).code
|
|
124
|
+
|
|
125
|
+
it('isNotEmpty / isEmpty coerce a nullish value to an empty collection', () => {
|
|
126
|
+
expect(codeOf({ operation: 'isNotEmpty' })).toBe('(imageUrl || []).length > 0')
|
|
127
|
+
expect(codeOf({ operation: 'isEmpty' })).toBe('(imageUrl || []).length === 0')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('objects go through Object.keys on a non-null target', () => {
|
|
131
|
+
expect(codeOf({ operation: 'isNotEmpty' }, 'object')).toBe(
|
|
132
|
+
'Object.keys(imageUrl || {}).length > 0'
|
|
133
|
+
)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('length comparisons guard the same way', () => {
|
|
137
|
+
expect(codeOf({ operation: 'lengthGreaterThan', operand: '2' })).toBe(
|
|
138
|
+
'(imageUrl || []).length > 2'
|
|
139
|
+
)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('contains / notContains guard the receiver of includes()', () => {
|
|
143
|
+
expect(codeOf({ operation: 'contains', operand: 'a' })).toBe('(imageUrl || []).includes("a")')
|
|
144
|
+
expect(codeOf({ operation: 'notContains', operand: 'a' })).toBe(
|
|
145
|
+
'!(imageUrl || []).includes("a")'
|
|
146
|
+
)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('hasKey passes a non-null receiver to hasOwnProperty', () => {
|
|
150
|
+
expect(codeOf({ operation: 'hasKey', operand: 'a' }, 'object')).toBe(
|
|
151
|
+
'Object.prototype.hasOwnProperty.call(imageUrl || {}, "a")'
|
|
152
|
+
)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('a non-empty string still reads as non-empty (string semantics preserved)', () => {
|
|
156
|
+
// eslint-disable-next-line no-eval
|
|
157
|
+
const evaluate = (expr: string, imageUrl: unknown) =>
|
|
158
|
+
// tslint:disable-next-line function-constructor
|
|
159
|
+
new Function('imageUrl', `return ${expr}`)(imageUrl)
|
|
160
|
+
|
|
161
|
+
const expression = codeOf({ operation: 'isNotEmpty' })
|
|
162
|
+
expect(evaluate(expression, 'https://cdn/x.png')).toBe(true)
|
|
163
|
+
expect(evaluate(expression, '')).toBe(false)
|
|
164
|
+
expect(evaluate(expression, null)).toBe(false)
|
|
165
|
+
expect(evaluate(expression, undefined)).toBe(false)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
113
168
|
})
|
|
114
169
|
|
|
115
170
|
describe('createConditionIdentifier', () => {
|
|
@@ -65,6 +65,30 @@ describe('URLSearchParamSync.buildUrlWriteBackEffect', () => {
|
|
|
65
65
|
expect(code).toContain('__nextQuery["search-keyword"] = String(q)')
|
|
66
66
|
expect(code).not.toContain('__nextQuery.search-keyword')
|
|
67
67
|
})
|
|
68
|
+
|
|
69
|
+
it('also deletes the key when the value equals a non-empty default (clean canonical URL)', () => {
|
|
70
|
+
const effect = buildUrlWriteBackEffect(
|
|
71
|
+
'sortBy',
|
|
72
|
+
types.identifier('sortBy'),
|
|
73
|
+
types.identifier('sortBy'),
|
|
74
|
+
types.stringLiteral('name-asc')
|
|
75
|
+
)
|
|
76
|
+
const code = codeOf(effect)
|
|
77
|
+
|
|
78
|
+
// The default now also routes to the delete branch, so loading the page at
|
|
79
|
+
// its default sort never writes a sticky `?sortBy=name-asc`.
|
|
80
|
+
expect(code).toContain('if (sortBy === "" || sortBy == null || sortBy === "name-asc")')
|
|
81
|
+
expect(code).toContain('delete __nextQuery.sortBy')
|
|
82
|
+
expect(code).toContain('__nextQuery.sortBy = String(sortBy)')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('omits the default clause when no default is supplied (byte-identical fallback)', () => {
|
|
86
|
+
const withoutDefault = codeOf(
|
|
87
|
+
buildUrlWriteBackEffect('sortBy', types.identifier('sortBy'), types.identifier('sortBy'))
|
|
88
|
+
)
|
|
89
|
+
expect(withoutDefault).toContain('if (sortBy === "" || sortBy == null)')
|
|
90
|
+
expect(withoutDefault).not.toContain('=== "name-asc"')
|
|
91
|
+
})
|
|
68
92
|
})
|
|
69
93
|
|
|
70
94
|
describe('URLSearchParamSync.buildUrlReadBackEffect', () => {
|
|
@@ -89,4 +113,22 @@ describe('URLSearchParamSync.buildUrlReadBackEffect', () => {
|
|
|
89
113
|
expect(code).toContain('const __urlValue = router.query["search-keyword"]')
|
|
90
114
|
expect(code).toContain('}, [router.query["search-keyword"], router.isReady])')
|
|
91
115
|
})
|
|
116
|
+
|
|
117
|
+
it('resolves an absent/empty URL value to a non-empty default rather than ""', () => {
|
|
118
|
+
const effect = buildUrlReadBackEffect('sortBy', 'setSortBy', types.stringLiteral('name-asc'))
|
|
119
|
+
const code = codeOf(effect)
|
|
120
|
+
|
|
121
|
+
// The normalized (string | string[] | undefined) value falls through to the
|
|
122
|
+
// default when empty — this is what stops the default from being clobbered
|
|
123
|
+
// to "" on first load (which forced an extra unsorted fetch).
|
|
124
|
+
expect(code).toContain('|| "name-asc"')
|
|
125
|
+
expect(code).toContain('setSortBy(prev => prev === __nextValue ? prev : __nextValue)')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('emits no default fallback when none is supplied (byte-identical fallback)', () => {
|
|
129
|
+
const code = codeOf(buildUrlReadBackEffect('sortBy', 'setSortBy'))
|
|
130
|
+
expect(code).not.toContain('name-asc')
|
|
131
|
+
// The bare normalized expression still ends in the "" missing-key fallback.
|
|
132
|
+
expect(code).toContain('const __nextValue =')
|
|
133
|
+
})
|
|
92
134
|
})
|
|
@@ -185,42 +185,55 @@ var stringifyOperandValue = function (value) {
|
|
|
185
185
|
}
|
|
186
186
|
return String(value);
|
|
187
187
|
};
|
|
188
|
+
/**
|
|
189
|
+
* Collection operators dereference `.length` / `.includes` on the bound value,
|
|
190
|
+
* which is nullish far more often than it looks (an optional CMS column, a
|
|
191
|
+
* category without an image, a not-yet-hydrated state). Coercing to an empty
|
|
192
|
+
* collection first keeps a hide-this-node condition from throwing
|
|
193
|
+
* `Cannot read properties of null` mid-render. A non-empty string stays
|
|
194
|
+
* truthy, so string semantics are preserved. Mirrors `createNullSafeCollection`
|
|
195
|
+
* in the JSX handler — keep the two in sync.
|
|
196
|
+
*/
|
|
197
|
+
var nullSafeCollection = function (identifier, empty) {
|
|
198
|
+
if (empty === void 0) { empty = '[]'; }
|
|
199
|
+
return "(".concat(identifier, " || ").concat(empty, ")");
|
|
200
|
+
};
|
|
188
201
|
var stringifyConditionalExpression = function (identifier, operation, value, containsField) {
|
|
189
202
|
// Array/object operators
|
|
190
203
|
if (operation === 'isEmpty') {
|
|
191
|
-
return "".concat(identifier, ".length === 0");
|
|
204
|
+
return "".concat(nullSafeCollection(identifier), ".length === 0");
|
|
192
205
|
}
|
|
193
206
|
if (operation === 'isNotEmpty') {
|
|
194
|
-
return "".concat(identifier, ".length > 0");
|
|
207
|
+
return "".concat(nullSafeCollection(identifier), ".length > 0");
|
|
195
208
|
}
|
|
196
209
|
if (operation === 'lengthEquals') {
|
|
197
|
-
return "".concat(identifier, ".length === ").concat(stringifyOperandValue(value));
|
|
210
|
+
return "".concat(nullSafeCollection(identifier), ".length === ").concat(stringifyOperandValue(value));
|
|
198
211
|
}
|
|
199
212
|
if (operation === 'lengthGreaterThan') {
|
|
200
|
-
return "".concat(identifier, ".length > ").concat(stringifyOperandValue(value));
|
|
213
|
+
return "".concat(nullSafeCollection(identifier), ".length > ").concat(stringifyOperandValue(value));
|
|
201
214
|
}
|
|
202
215
|
if (operation === 'lengthLessThan') {
|
|
203
|
-
return "".concat(identifier, ".length < ").concat(stringifyOperandValue(value));
|
|
216
|
+
return "".concat(nullSafeCollection(identifier), ".length < ").concat(stringifyOperandValue(value));
|
|
204
217
|
}
|
|
205
218
|
if (operation === 'contains') {
|
|
206
219
|
var operandStr = stringifyOperandValue(value);
|
|
207
220
|
if (containsField) {
|
|
208
|
-
return "".concat(identifier, ".some(item => item.").concat(containsField, " === ").concat(operandStr, ")");
|
|
221
|
+
return "".concat(nullSafeCollection(identifier), ".some(item => item.").concat(containsField, " === ").concat(operandStr, ")");
|
|
209
222
|
}
|
|
210
|
-
return "".concat(identifier, ".includes(").concat(operandStr, ")");
|
|
223
|
+
return "".concat(nullSafeCollection(identifier), ".includes(").concat(operandStr, ")");
|
|
211
224
|
}
|
|
212
225
|
if (operation === 'notContains') {
|
|
213
226
|
var operandStr = stringifyOperandValue(value);
|
|
214
227
|
if (containsField) {
|
|
215
|
-
return "!".concat(identifier, ".some(item => item.").concat(containsField, " === ").concat(operandStr, ")");
|
|
228
|
+
return "!".concat(nullSafeCollection(identifier), ".some(item => item.").concat(containsField, " === ").concat(operandStr, ")");
|
|
216
229
|
}
|
|
217
|
-
return "!".concat(identifier, ".includes(").concat(operandStr, ")");
|
|
230
|
+
return "!".concat(nullSafeCollection(identifier), ".includes(").concat(operandStr, ")");
|
|
218
231
|
}
|
|
219
232
|
if (operation === 'hasKey') {
|
|
220
|
-
return "Object.prototype.hasOwnProperty.call(".concat(identifier, ", ").concat(stringifyOperandValue(value), ")");
|
|
233
|
+
return "Object.prototype.hasOwnProperty.call(".concat(nullSafeCollection(identifier, '{}'), ", ").concat(stringifyOperandValue(value), ")");
|
|
221
234
|
}
|
|
222
235
|
if (operation === 'notHasKey') {
|
|
223
|
-
return "!Object.prototype.hasOwnProperty.call(".concat(identifier, ", ").concat(stringifyOperandValue(value), ")");
|
|
236
|
+
return "!Object.prototype.hasOwnProperty.call(".concat(nullSafeCollection(identifier, '{}'), ", ").concat(stringifyOperandValue(value), ")");
|
|
224
237
|
}
|
|
225
238
|
// Standard operators
|
|
226
239
|
if (typeof value === 'boolean') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/node-handlers/node-to-html/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAmD;AACnD,+DAAoE;AAapE,8DAA6D;AAC7D,iEAAiD;AAE1C,IAAM,eAAe,GAAG,UAC7B,QAAkB,EAClB,WAAmB,EACnB,OAAe,EACf,SAA6B,EAC7B,MAAoC,EACpC,cAAkC,EAClC,IAAqB;IAEb,IAAA,UAAU,GAAK,MAAM,WAAX,CAAW;IAC7B,IAAM,cAAc,GAAG,cAAc,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACjE,QAAQ,SAAS,CAAC,IAAI,EAAE;QACtB,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,cAAc,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC5E,MAAK;QACP,KAAK,YAAY;YACf,SAAS,CAAC,kBAAkB,CAC1B,QAAQ,EACR,OAA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eAAe,EAiBhB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAA+D,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/node-handlers/node-to-jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EACL,eAAe,EAiBhB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAA+D,SAAS,EAAE,MAAM,SAAS,CAAA;AA2oBhG,QAAA,MAAM,mBAAmB,EAAE,SAAS,CAAC,eAAe,EAAE,KAAK,CAAC,UAAU,CAwSrE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -42,6 +42,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
42
42
|
}
|
|
43
43
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
44
44
|
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
45
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
49
|
var types = __importStar(require("@babel/types"));
|
|
47
50
|
var teleport_shared_1 = require("@teleporthq/teleport-shared");
|
|
@@ -50,6 +53,21 @@ var ast_utils_1 = require("../../utils/ast-utils");
|
|
|
50
53
|
var ast_builders_1 = require("../../builders/ast-builders");
|
|
51
54
|
var constants_1 = require("./constants");
|
|
52
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
|
+
};
|
|
53
71
|
// Global references in the UIDL come in two shapes:
|
|
54
72
|
// Shape A: { id: "ecommerce", refPath: ["Cart", "total"] }
|
|
55
73
|
// Shape B: { id: undefined, refPath: ["E-commerce", "Settings", "Delivery", "..."] }
|
|
@@ -140,8 +158,24 @@ var trackGlobalRefsInExpression = function (expression, params) {
|
|
|
140
158
|
}
|
|
141
159
|
}
|
|
142
160
|
};
|
|
161
|
+
// The recognised runtime identifiers a `global` reference's `id` can legitimately
|
|
162
|
+
// already hold (Shape A). Anything else — notably the opaque `TQ_...` node id every
|
|
163
|
+
// dynamic UIDL reference carries for editor bookkeeping — is not a real identifier
|
|
164
|
+
// and must be re-derived from `refPath` (Shape B/C), or code generation would emit
|
|
165
|
+
// an undeclared variable that throws at runtime.
|
|
166
|
+
var KNOWN_GLOBAL_REF_IDS = new Set([
|
|
167
|
+
'locale',
|
|
168
|
+
'locales',
|
|
169
|
+
'currentUser',
|
|
170
|
+
'userIsLoggedIn',
|
|
171
|
+
'ecommerce',
|
|
172
|
+
'cart',
|
|
173
|
+
]);
|
|
143
174
|
var normalizeGlobalRef = function (node) {
|
|
144
|
-
if (
|
|
175
|
+
if (!node.content.refPath || node.content.refPath.length === 0) {
|
|
176
|
+
return node;
|
|
177
|
+
}
|
|
178
|
+
if (node.content.id && KNOWN_GLOBAL_REF_IDS.has(node.content.id)) {
|
|
145
179
|
return node;
|
|
146
180
|
}
|
|
147
181
|
var firstSeg = node.content.refPath[0];
|
|
@@ -410,10 +444,72 @@ var maybeAddFormStoreFieldBinding = function (elementTag, elementName, attrs, pa
|
|
|
410
444
|
elementTag.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onChange'), types.jsxExpressionContainer(handler)));
|
|
411
445
|
}
|
|
412
446
|
};
|
|
447
|
+
// Style plugins (styled-jsx, css-modules, styled-components, react-jss, plugin-css)
|
|
448
|
+
// emit ONE flat, component-scope CSS block/class-map from `element.style`, so a
|
|
449
|
+
// dynamic style value only resolves correctly there when the identifier it needs
|
|
450
|
+
// is reachable from that top-level scope (e.g. `token`/`prop`). A `ctx` reference
|
|
451
|
+
// resolves to the render-prop identifier of the enclosing repeater/data-source —
|
|
452
|
+
// only in scope inside that repeater's own render callback — and other reference
|
|
453
|
+
// types (`state`, `local`, `global`, `globalState`, ...) are never routed through
|
|
454
|
+
// `element.style` by any known UIDL producer either. When one shows up anyway, the
|
|
455
|
+
// only place that still knows the correct enclosing scope is here, while building
|
|
456
|
+
// this exact JSX node, so resolve it into an inline `style` attribute (mirroring
|
|
457
|
+
// how `dynamicStyleBindings` already handles ctx/state-bound styles) and strip it
|
|
458
|
+
// out of `element.style` so no downstream style plugin re-processes — and chokes
|
|
459
|
+
// on — the same entry.
|
|
460
|
+
var resolveScopedDynamicStyleValues = function (style, elementTag, params, options) {
|
|
461
|
+
if (!style) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
var inlineStyleOverrides = {};
|
|
465
|
+
for (var _i = 0, _a = Object.keys(style); _i < _a.length; _i++) {
|
|
466
|
+
var cssProperty = _a[_i];
|
|
467
|
+
var styleValue = style[cssProperty];
|
|
468
|
+
var camelCaseProperty = cssProperty.replace(/-([a-z])/g, function (_, letter) {
|
|
469
|
+
return letter.toUpperCase();
|
|
470
|
+
});
|
|
471
|
+
// A pre-resolved expression style value (e.g. a data-source-bound style whose
|
|
472
|
+
// mapper already produced the full member-access expression). The UIDL style
|
|
473
|
+
// type is narrowed to static|dynamic, so read the discriminator via a cast.
|
|
474
|
+
// Inline the parsed expression and strip it so no CSS/styled-jsx plugin sees it.
|
|
475
|
+
var rawStyleValue = styleValue;
|
|
476
|
+
if (rawStyleValue.type === 'expr') {
|
|
477
|
+
var exprContent = rawStyleValue.content;
|
|
478
|
+
if (typeof exprContent === 'string' && exprContent.length > 0) {
|
|
479
|
+
inlineStyleOverrides[camelCaseProperty] = new parsed_ast_1.default((0, ast_utils_1.parseJSExpressionAsAST)(exprContent));
|
|
480
|
+
delete style[cssProperty];
|
|
481
|
+
}
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
// Skip: `token` → CSS variable (handled by the style plugin); a SIMPLE `prop`
|
|
485
|
+
// (no refPath) → the style plugin's `${props.x}` interpolation. A prop WITH a
|
|
486
|
+
// refPath (an object prop's field, e.g. `product.color`) MUST be inlined here
|
|
487
|
+
// instead — styled-jsx's prop case emits only `props.<id>` and would drop the
|
|
488
|
+
// refPath, producing `props.product` instead of `props.product.color`.
|
|
489
|
+
var isSimpleProp = styleValue.type === 'dynamic' &&
|
|
490
|
+
styleValue.content.referenceType === 'prop' &&
|
|
491
|
+
!(styleValue.content.refPath && styleValue.content.refPath.length > 0);
|
|
492
|
+
if (styleValue.type !== 'dynamic' ||
|
|
493
|
+
styleValue.content.referenceType === 'token' ||
|
|
494
|
+
isSimpleProp) {
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
var resolvedExpr = resolveDynamicReferenceExpression(styleValue, params, options);
|
|
498
|
+
var fallback = styleValue.content.fallback;
|
|
499
|
+
var finalExpr = fallback !== undefined && fallback !== ''
|
|
500
|
+
? types.logicalExpression('||', resolvedExpr, (0, ast_utils_1.convertValueToLiteral)(fallback))
|
|
501
|
+
: resolvedExpr;
|
|
502
|
+
inlineStyleOverrides[camelCaseProperty] = new parsed_ast_1.default(finalExpr);
|
|
503
|
+
delete style[cssProperty];
|
|
504
|
+
}
|
|
505
|
+
if (Object.keys(inlineStyleOverrides).length > 0) {
|
|
506
|
+
(0, ast_utils_1.addAttributeToJSXTag)(elementTag, 'style', inlineStyleOverrides);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
413
509
|
var generateElementNode = function (node, params, jsxOptions) {
|
|
414
510
|
var dependencies = params.dependencies, nodesLookup = params.nodesLookup;
|
|
415
511
|
var options = __assign(__assign({}, constants_1.DEFAULT_JSX_OPTIONS), jsxOptions);
|
|
416
|
-
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;
|
|
512
|
+
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;
|
|
417
513
|
var originalElementName = elementType || 'component';
|
|
418
514
|
var tagName = originalElementName;
|
|
419
515
|
// Check if this is a fragment element - normalize to Fragment before processing
|
|
@@ -459,6 +555,7 @@ var generateElementNode = function (node, params, jsxOptions) {
|
|
|
459
555
|
if (attrs) {
|
|
460
556
|
addAttributesToJSXTag(attrs, elementTag, options, params, node.content.semanticType || elementType);
|
|
461
557
|
}
|
|
558
|
+
resolveScopedDynamicStyleValues(style, elementTag, params, options);
|
|
462
559
|
if (events) {
|
|
463
560
|
Object.keys(events).forEach(function (eventKey) {
|
|
464
561
|
(0, utils_1.addEventHandlerToTag)(elementTag, eventKey, events[eventKey], params, options);
|
|
@@ -1082,7 +1179,7 @@ var generateDataSourceNode = function (node, params, options) {
|
|
|
1082
1179
|
if (property.type === 'static') {
|
|
1083
1180
|
// Special handling for filters array - convert dynamic destinations
|
|
1084
1181
|
if (attrKey === 'filters' && Array.isArray(property.content)) {
|
|
1085
|
-
|
|
1182
|
+
var filterEntries = property.content.map(function (filter) {
|
|
1086
1183
|
return types.objectExpression([
|
|
1087
1184
|
types.objectProperty(types.identifier('source'), types.stringLiteral(filter.source || '')),
|
|
1088
1185
|
types.objectProperty(types.identifier('destination'), __1.ASTUtils.convertFilterDestinationToExpression(filter.destination, {
|
|
@@ -1090,7 +1187,15 @@ var generateDataSourceNode = function (node, params, options) {
|
|
|
1090
1187
|
})),
|
|
1091
1188
|
types.objectProperty(types.identifier('operand'), types.stringLiteral(filter.operand || '')),
|
|
1092
1189
|
]);
|
|
1093
|
-
})
|
|
1190
|
+
});
|
|
1191
|
+
// Drop conditions whose destination resolves to an empty value at
|
|
1192
|
+
// runtime (empty string / null / undefined, or an empty
|
|
1193
|
+
// array-overlap set) so a "show all" reset means no filter rather
|
|
1194
|
+
// than a query that matches zero rows. Mirrors the Next.js pages
|
|
1195
|
+
// path's `buildNonEmptyDestinationPredicate` (kept inline here
|
|
1196
|
+
// because teleport-plugin-common must not depend on the
|
|
1197
|
+
// next-data-source plugin).
|
|
1198
|
+
acc.push(types.objectProperty(types.stringLiteral(attrKey), types.callExpression(types.memberExpression(types.arrayExpression(filterEntries), types.identifier('filter')), [buildNonEmptyFilterDestinationPredicate()])));
|
|
1094
1199
|
}
|
|
1095
1200
|
else {
|
|
1096
1201
|
acc.push(types.objectProperty(types.stringLiteral(attrKey), (0, ast_utils_1.resolveObjectValue)(property)));
|
|
@@ -1211,6 +1316,14 @@ var generateCMSListRepeaterNode = function (node, params, options) {
|
|
|
1211
1316
|
repeaterItemsExpr = types.logicalExpression('||', expr, types.arrayExpression([]));
|
|
1212
1317
|
params.globalReferences.push('ecommerce');
|
|
1213
1318
|
}
|
|
1319
|
+
else if (source === 'ecommerceCategories') {
|
|
1320
|
+
// The `E-Commerce Categories` global (the nested category tree) is baked
|
|
1321
|
+
// onto the ecommerce context as `ecommerce.ecommerceCategories`. Fixed
|
|
1322
|
+
// one-segment path (independent of the item name) → `ecommerce?.ecommerceCategories || []`.
|
|
1323
|
+
var expr = types.optionalMemberExpression(types.identifier('ecommerce'), types.identifier('ecommerceCategories'), false, true);
|
|
1324
|
+
repeaterItemsExpr = types.logicalExpression('||', expr, types.arrayExpression([]));
|
|
1325
|
+
params.globalReferences.push('ecommerce');
|
|
1326
|
+
}
|
|
1214
1327
|
else {
|
|
1215
1328
|
// Resolve any global-state reference encoded in `source` and register it
|
|
1216
1329
|
// so the `next-global-state` component plugin destructures the matching
|