@teleporthq/teleport-plugin-next-data-source 0.43.59 → 0.43.60
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__/_helpers/pagination-widget-fixture.ts +230 -0
- package/__tests__/ecommerce-product-discounts.test.ts +196 -0
- package/__tests__/infinite-scroll.test.ts +143 -0
- package/__tests__/numbered-pagination.test.ts +113 -0
- package/__tests__/page-reset-on-filter-sort.test.ts +182 -0
- package/__tests__/page-url-sync.test.ts +208 -0
- package/__tests__/product-price-sort.ts +313 -0
- package/__tests__/search-url-sync.test.ts +7 -3
- package/dist/cjs/array-mapper-pagination.d.ts +9 -0
- package/dist/cjs/array-mapper-pagination.d.ts.map +1 -1
- package/dist/cjs/array-mapper-pagination.js.map +1 -1
- package/dist/cjs/count-effect.d.ts +42 -0
- package/dist/cjs/count-effect.d.ts.map +1 -0
- package/dist/cjs/count-effect.js +81 -0
- package/dist/cjs/count-effect.js.map +1 -0
- package/dist/cjs/fetchers/postgresql.d.ts.map +1 -1
- package/dist/cjs/fetchers/postgresql.js +2 -1
- package/dist/cjs/fetchers/postgresql.js.map +1 -1
- package/dist/cjs/fetchers/teleport.d.ts.map +1 -1
- package/dist/cjs/fetchers/teleport.js +3 -2
- package/dist/cjs/fetchers/teleport.js.map +1 -1
- package/dist/cjs/infinite-scroll.d.ts +65 -0
- package/dist/cjs/infinite-scroll.d.ts.map +1 -0
- package/dist/cjs/infinite-scroll.js +190 -0
- package/dist/cjs/infinite-scroll.js.map +1 -0
- package/dist/cjs/numbered-pagination.d.ts +42 -0
- package/dist/cjs/numbered-pagination.d.ts.map +1 -0
- package/dist/cjs/numbered-pagination.js +167 -0
- package/dist/cjs/numbered-pagination.js.map +1 -0
- package/dist/cjs/page-reset.d.ts +42 -0
- package/dist/cjs/page-reset.d.ts.map +1 -0
- package/dist/cjs/page-reset.js +116 -0
- package/dist/cjs/page-reset.js.map +1 -0
- package/dist/cjs/page-url-sync.d.ts +42 -0
- package/dist/cjs/page-url-sync.d.ts.map +1 -0
- package/dist/cjs/page-url-sync.js +180 -0
- package/dist/cjs/page-url-sync.js.map +1 -0
- package/dist/cjs/pagination-controls.d.ts +55 -0
- package/dist/cjs/pagination-controls.d.ts.map +1 -0
- package/dist/cjs/pagination-controls.js +159 -0
- package/dist/cjs/pagination-controls.js.map +1 -0
- package/dist/cjs/pagination-plugin.d.ts.map +1 -1
- package/dist/cjs/pagination-plugin.js +506 -160
- package/dist/cjs/pagination-plugin.js.map +1 -1
- package/dist/cjs/product-price-sort.d.ts +116 -0
- package/dist/cjs/product-price-sort.d.ts.map +1 -0
- package/dist/cjs/product-price-sort.js +169 -0
- package/dist/cjs/product-price-sort.js.map +1 -0
- package/dist/cjs/transformations/ecommerce-product.d.ts.map +1 -1
- package/dist/cjs/transformations/ecommerce-product.js +1 -1
- package/dist/cjs/transformations/ecommerce-product.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/array-mapper-pagination.d.ts +9 -0
- package/dist/esm/array-mapper-pagination.d.ts.map +1 -1
- package/dist/esm/array-mapper-pagination.js.map +1 -1
- package/dist/esm/count-effect.d.ts +42 -0
- package/dist/esm/count-effect.d.ts.map +1 -0
- package/dist/esm/count-effect.js +53 -0
- package/dist/esm/count-effect.js.map +1 -0
- package/dist/esm/fetchers/postgresql.d.ts.map +1 -1
- package/dist/esm/fetchers/postgresql.js +2 -1
- package/dist/esm/fetchers/postgresql.js.map +1 -1
- package/dist/esm/fetchers/teleport.d.ts.map +1 -1
- package/dist/esm/fetchers/teleport.js +3 -2
- package/dist/esm/fetchers/teleport.js.map +1 -1
- package/dist/esm/infinite-scroll.d.ts +65 -0
- package/dist/esm/infinite-scroll.d.ts.map +1 -0
- package/dist/esm/infinite-scroll.js +159 -0
- package/dist/esm/infinite-scroll.js.map +1 -0
- package/dist/esm/numbered-pagination.d.ts +42 -0
- package/dist/esm/numbered-pagination.d.ts.map +1 -0
- package/dist/esm/numbered-pagination.js +138 -0
- package/dist/esm/numbered-pagination.js.map +1 -0
- package/dist/esm/page-reset.d.ts +42 -0
- package/dist/esm/page-reset.d.ts.map +1 -0
- package/dist/esm/page-reset.js +87 -0
- package/dist/esm/page-reset.js.map +1 -0
- package/dist/esm/page-url-sync.d.ts +42 -0
- package/dist/esm/page-url-sync.d.ts.map +1 -0
- package/dist/esm/page-url-sync.js +152 -0
- package/dist/esm/page-url-sync.js.map +1 -0
- package/dist/esm/pagination-controls.d.ts +55 -0
- package/dist/esm/pagination-controls.d.ts.map +1 -0
- package/dist/esm/pagination-controls.js +126 -0
- package/dist/esm/pagination-controls.js.map +1 -0
- package/dist/esm/pagination-plugin.d.ts.map +1 -1
- package/dist/esm/pagination-plugin.js +507 -161
- package/dist/esm/pagination-plugin.js.map +1 -1
- package/dist/esm/product-price-sort.d.ts +116 -0
- package/dist/esm/product-price-sort.d.ts.map +1 -0
- package/dist/esm/product-price-sort.js +160 -0
- package/dist/esm/product-price-sort.js.map +1 -0
- package/dist/esm/transformations/ecommerce-product.d.ts.map +1 -1
- package/dist/esm/transformations/ecommerce-product.js +2 -2
- package/dist/esm/transformations/ecommerce-product.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/array-mapper-pagination.ts +10 -0
- package/src/count-effect.ts +137 -0
- package/src/fetchers/postgresql.ts +52 -13
- package/src/fetchers/teleport.ts +53 -13
- package/src/infinite-scroll.ts +401 -0
- package/src/numbered-pagination.ts +292 -0
- package/src/page-reset.ts +162 -0
- package/src/page-url-sync.ts +241 -0
- package/src/pagination-controls.ts +176 -0
- package/src/pagination-plugin.ts +755 -346
- package/src/product-price-sort.ts +204 -0
- package/src/transformations/ecommerce-product.ts +33 -7
- package/dist/cjs/array-mapper-registry.d.ts +0 -85
- package/dist/cjs/array-mapper-registry.d.ts.map +0 -1
- package/dist/cjs/array-mapper-registry.js +0 -296
- package/dist/cjs/array-mapper-registry.js.map +0 -1
- package/dist/cjs/pagination-with-count.d.ts +0 -6
- package/dist/cjs/pagination-with-count.d.ts.map +0 -1
- package/dist/cjs/pagination-with-count.js +0 -63
- package/dist/cjs/pagination-with-count.js.map +0 -1
- package/dist/esm/array-mapper-registry.d.ts +0 -85
- package/dist/esm/array-mapper-registry.d.ts.map +0 -1
- package/dist/esm/array-mapper-registry.js +0 -292
- package/dist/esm/array-mapper-registry.js.map +0 -1
- package/dist/esm/pagination-with-count.d.ts +0 -6
- package/dist/esm/pagination-with-count.d.ts.map +0 -1
- package/dist/esm/pagination-with-count.js +0 -34
- package/dist/esm/pagination-with-count.js.map +0 -1
- package/src/array-mapper-registry.ts +0 -416
- package/src/pagination-with-count.ts +0 -89
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Resetting a paginated list back to page 1 when its FILTER or SORT changes.
|
|
4
|
+
*
|
|
5
|
+
* Without this a visitor on page 5 who picks a category with twelve results
|
|
6
|
+
* fetches page 5 of twelve rows and is shown an empty grid, with only
|
|
7
|
+
* "Previous" to get out of it. The search input never had this bug: its
|
|
8
|
+
* debounce effect REPLACES the whole `{ page, debouncedQuery }` state, and so
|
|
9
|
+
* has always dropped the page back to 1 as a side effect.
|
|
10
|
+
*
|
|
11
|
+
* ⛔ Why the guard is a signature and not the usual `useRef(true)` skip-first:
|
|
12
|
+
* URL-driven dependencies (`router.query.categoryFilter`) are `undefined` on
|
|
13
|
+
* the first render and only take their real value once the router hydrates.
|
|
14
|
+
* A skip-first guard would treat that hydration as a change and reset the page
|
|
15
|
+
* of a deep link like `?page=3&categoryFilter=Rings` back to 1 — the very
|
|
16
|
+
* sharing case the page-in-URL feature exists to support. Comparing a
|
|
17
|
+
* serialised signature instead means the first OBSERVED value is recorded
|
|
18
|
+
* rather than acted on, whatever render it arrives in, and any later genuine
|
|
19
|
+
* change resets exactly once.
|
|
20
|
+
*/
|
|
21
|
+
export interface PageResetDeps {
|
|
22
|
+
/** Bare identifiers: state-bound filter destinations and dynamic-sort deps. */
|
|
23
|
+
stateIds: string[];
|
|
24
|
+
/** Emitted as `props.<id>` — props are never destructured into scope. */
|
|
25
|
+
propIds: string[];
|
|
26
|
+
/** Emitted as `router.query.<key>`. */
|
|
27
|
+
urlSearchParamKeys: string[];
|
|
28
|
+
}
|
|
29
|
+
/** True when there is nothing that could ever change the filtering of this list. */
|
|
30
|
+
export declare const hasNoPageResetDeps: (deps: PageResetDeps) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Builds the reset effect.
|
|
33
|
+
*
|
|
34
|
+
* @param refVar name of the `useRef` holding the last seen signature
|
|
35
|
+
* @param buildResetStatement how this usage writes page 1 — the combined
|
|
36
|
+
* `{ page, debouncedQuery }` state and the standalone
|
|
37
|
+
* page state need different setters
|
|
38
|
+
*/
|
|
39
|
+
export declare const buildFilterSortPageResetEffect: (refVar: string, deps: PageResetDeps, buildResetStatement: () => types.Statement) => types.ExpressionStatement;
|
|
40
|
+
/** `const <refVar> = useRef(null)` — the signature store for the effect above. */
|
|
41
|
+
export declare const buildPageResetRefDeclaration: (refVar: string) => types.VariableDeclaration;
|
|
42
|
+
//# sourceMappingURL=page-reset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-reset.d.ts","sourceRoot":"","sources":["../../src/page-reset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,yEAAyE;IACzE,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,uCAAuC;IACvC,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,SAAU,aAAa,KAAG,OACwC,CAAA;AAuCjG;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,WACjC,MAAM,QACR,aAAa,uBACE,MAAM,MAAM,SAAS,KACzC,MAAM,mBAoER,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,4BAA4B,WAAY,MAAM,KAAG,MAAM,mBAMhE,CAAA"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.buildPageResetRefDeclaration = exports.buildFilterSortPageResetEffect = exports.hasNoPageResetDeps = void 0;
|
|
27
|
+
var types = __importStar(require("@babel/types"));
|
|
28
|
+
/** True when there is nothing that could ever change the filtering of this list. */
|
|
29
|
+
var hasNoPageResetDeps = function (deps) {
|
|
30
|
+
return deps.stateIds.length === 0 && deps.propIds.length === 0 && deps.urlSearchParamKeys.length === 0;
|
|
31
|
+
};
|
|
32
|
+
exports.hasNoPageResetDeps = hasNoPageResetDeps;
|
|
33
|
+
var routerQueryAccess = function (key) {
|
|
34
|
+
return types.memberExpression(types.memberExpression(types.identifier('router'), types.identifier('query')), types.identifier(key));
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The expressions the effect both depends on and hashes into its signature.
|
|
38
|
+
*
|
|
39
|
+
* Kept in one place so the two can never drift: a value in the signature but
|
|
40
|
+
* not the deps would be read stale, and one in the deps but not the signature
|
|
41
|
+
* would re-run the effect without being able to explain why it changed.
|
|
42
|
+
*/
|
|
43
|
+
var buildTrackedExpressions = function (deps) {
|
|
44
|
+
var tracked = [];
|
|
45
|
+
var seen = new Set();
|
|
46
|
+
for (var _i = 0, _a = deps.stateIds; _i < _a.length; _i++) {
|
|
47
|
+
var id = _a[_i];
|
|
48
|
+
if (seen.has(id)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
seen.add(id);
|
|
52
|
+
tracked.push(types.identifier(id));
|
|
53
|
+
}
|
|
54
|
+
for (var _b = 0, _c = deps.propIds; _b < _c.length; _b++) {
|
|
55
|
+
var id = _c[_b];
|
|
56
|
+
var key = "props.".concat(id);
|
|
57
|
+
if (seen.has(key)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
seen.add(key);
|
|
61
|
+
tracked.push(types.memberExpression(types.identifier('props'), types.identifier(id)));
|
|
62
|
+
}
|
|
63
|
+
for (var _d = 0, _e = deps.urlSearchParamKeys; _d < _e.length; _d++) {
|
|
64
|
+
var key = _e[_d];
|
|
65
|
+
tracked.push(routerQueryAccess(key));
|
|
66
|
+
}
|
|
67
|
+
return tracked;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Builds the reset effect.
|
|
71
|
+
*
|
|
72
|
+
* @param refVar name of the `useRef` holding the last seen signature
|
|
73
|
+
* @param buildResetStatement how this usage writes page 1 — the combined
|
|
74
|
+
* `{ page, debouncedQuery }` state and the standalone
|
|
75
|
+
* page state need different setters
|
|
76
|
+
*/
|
|
77
|
+
var buildFilterSortPageResetEffect = function (refVar, deps, buildResetStatement) {
|
|
78
|
+
var body = [];
|
|
79
|
+
var hasRouterDeps = deps.urlSearchParamKeys.length > 0;
|
|
80
|
+
// Reading `router.query` before the router is ready would hash `undefined`
|
|
81
|
+
// for every URL-driven filter and record a signature that is about to change
|
|
82
|
+
// on its own.
|
|
83
|
+
if (hasRouterDeps) {
|
|
84
|
+
body.push(types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('router'), types.identifier('isReady')), true), types.returnStatement()));
|
|
85
|
+
}
|
|
86
|
+
var refCurrent = types.memberExpression(types.identifier(refVar), types.identifier('current'));
|
|
87
|
+
// `?? null` so a missing URL param serialises as `null` rather than dropping
|
|
88
|
+
// out of the array and shifting every later entry.
|
|
89
|
+
var signatureEntries = buildTrackedExpressions(deps).map(function (expr) {
|
|
90
|
+
return expr.type === 'MemberExpression' && expr.object.type === 'MemberExpression'
|
|
91
|
+
? types.logicalExpression('??', expr, types.nullLiteral())
|
|
92
|
+
: expr;
|
|
93
|
+
});
|
|
94
|
+
body.push(types.variableDeclaration('const', [
|
|
95
|
+
types.variableDeclarator(types.identifier('__sig'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.arrayExpression(signatureEntries)])),
|
|
96
|
+
]), types.ifStatement(types.binaryExpression('===', types.cloneNode(refCurrent, true), types.identifier('__sig')), types.returnStatement()), types.variableDeclaration('const', [
|
|
97
|
+
types.variableDeclarator(types.identifier('__first'), types.binaryExpression('===', types.cloneNode(refCurrent, true), types.nullLiteral())),
|
|
98
|
+
]), types.expressionStatement(types.assignmentExpression('=', types.cloneNode(refCurrent, true), types.identifier('__sig'))), types.ifStatement(types.identifier('__first'), types.returnStatement()), buildResetStatement());
|
|
99
|
+
var effectDeps = buildTrackedExpressions(deps);
|
|
100
|
+
if (hasRouterDeps) {
|
|
101
|
+
effectDeps.push(types.memberExpression(types.identifier('router'), types.identifier('isReady')));
|
|
102
|
+
}
|
|
103
|
+
return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
|
|
104
|
+
types.arrowFunctionExpression([], types.blockStatement(body)),
|
|
105
|
+
types.arrayExpression(effectDeps),
|
|
106
|
+
]));
|
|
107
|
+
};
|
|
108
|
+
exports.buildFilterSortPageResetEffect = buildFilterSortPageResetEffect;
|
|
109
|
+
/** `const <refVar> = useRef(null)` — the signature store for the effect above. */
|
|
110
|
+
var buildPageResetRefDeclaration = function (refVar) {
|
|
111
|
+
return types.variableDeclaration('const', [
|
|
112
|
+
types.variableDeclarator(types.identifier(refVar), types.callExpression(types.identifier('useRef'), [types.nullLiteral()])),
|
|
113
|
+
]);
|
|
114
|
+
};
|
|
115
|
+
exports.buildPageResetRefDeclaration = buildPageResetRefDeclaration;
|
|
116
|
+
//# sourceMappingURL=page-reset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-reset.js","sourceRoot":"","sources":["../../src/page-reset.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAqC;AA+BrC,oFAAoF;AAC7E,IAAM,kBAAkB,GAAG,UAAC,IAAmB;IACpD,OAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,KAAK,CAAC;AAA/F,CAA+F,CAAA;AADpF,QAAA,kBAAkB,sBACkE;AAEjG,IAAM,iBAAiB,GAAG,UAAC,GAAW;IACpC,OAAA,KAAK,CAAC,gBAAgB,CACpB,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7E,KAAK,CA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AAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC7D,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC;KAClC,CAAC,CACH,CAAA;AACH,CAAC,CAAA;AAxEY,QAAA,8BAA8B,kCAwE1C;AAED,kFAAkF;AAC3E,IAAM,4BAA4B,GAAG,UAAC,MAAc;IACzD,OAAA,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE;QACjC,KAAK,CAAC,kBAAkB,CACtB,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EACxB,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CACxE;KACF,CAAC;AALF,CAKE,CAAA;AANS,QAAA,4BAA4B,gCAMrC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
/** `const <refVar> = useRef(null)` — the last `?page=` value this effect saw. */
|
|
3
|
+
export declare const buildPageUrlRefDeclaration: (refVar: string) => types.VariableDeclaration;
|
|
4
|
+
export interface PageUrlSyncOptions {
|
|
5
|
+
paramKey: string;
|
|
6
|
+
/** Ref holding the previously seen URL page. */
|
|
7
|
+
refVar: string;
|
|
8
|
+
/** How this usage reads its current page. */
|
|
9
|
+
currentPageExpr: () => types.Expression;
|
|
10
|
+
/** How this usage writes a page back. */
|
|
11
|
+
buildSetPageStatement: (pageExpr: types.Expression) => types.Expression;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Emitted shape (for `?page=`, a combined `{ page, debouncedQuery }` state):
|
|
15
|
+
*
|
|
16
|
+
* useEffect(() => {
|
|
17
|
+
* if (!router.isReady) return
|
|
18
|
+
* const __urlValue = router.query.page
|
|
19
|
+
* const __raw = typeof __urlValue === 'string' ? __urlValue
|
|
20
|
+
* : Array.isArray(__urlValue) ? __urlValue[0] || '' : ''
|
|
21
|
+
* const __urlPage = Math.max(1, parseInt(__raw, 10) || 1)
|
|
22
|
+
* const __statePage = ds_0_state.page
|
|
23
|
+
* const __seenUrlPage = ds_0_pageUrlRef.current
|
|
24
|
+
* if (__tqQuerySyncRef.current.inFlight === 0 &&
|
|
25
|
+
* __seenUrlPage !== __urlPage && __urlPage !== __statePage) {
|
|
26
|
+
* ds_0_pageUrlRef.current = __urlPage
|
|
27
|
+
* setDs_0_state(state => state.page === __urlPage ? state : { ...state, page: __urlPage })
|
|
28
|
+
* return
|
|
29
|
+
* }
|
|
30
|
+
* ds_0_pageUrlRef.current = __urlPage
|
|
31
|
+
* if (__urlPage === __statePage) return
|
|
32
|
+
* __tqWriteQueryParam('page', __statePage <= 1 ? undefined : __statePage)
|
|
33
|
+
* }, [router.query.page, router.isReady, ds_0_state.page])
|
|
34
|
+
*
|
|
35
|
+
* The write goes through `URLQueryWriter` rather than spreading `router.query`
|
|
36
|
+
* here. This effect and a filter's write-back fire in the SAME flush on every
|
|
37
|
+
* filter change (the reset moves the page), and two effects each merging into
|
|
38
|
+
* their own stale snapshot of `router.query` erase each other's keys — see
|
|
39
|
+
* `url-query-writer.ts` for why that then never settles.
|
|
40
|
+
*/
|
|
41
|
+
export declare const buildPageUrlSyncEffect: (options: PageUrlSyncOptions) => types.ExpressionStatement;
|
|
42
|
+
//# sourceMappingURL=page-url-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-url-sync.d.ts","sourceRoot":"","sources":["../../src/page-url-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AA4DrC,iFAAiF;AACjF,eAAO,MAAM,0BAA0B,WAAY,MAAM,KAAG,MAAM,mBAM9D,CAAA;AAEJ,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,eAAe,EAAE,MAAM,KAAK,CAAC,UAAU,CAAA;IACvC,yCAAyC;IACzC,qBAAqB,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU,CAAA;CACxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,sBAAsB,YAAa,kBAAkB,KAAG,MAAM,mBAqI1E,CAAA"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.buildPageUrlSyncEffect = exports.buildPageUrlRefDeclaration = void 0;
|
|
27
|
+
var types = __importStar(require("@babel/types"));
|
|
28
|
+
var teleport_plugin_common_1 = require("@teleporthq/teleport-plugin-common");
|
|
29
|
+
/**
|
|
30
|
+
* Keeping the current page and the `?page=` query in step.
|
|
31
|
+
*
|
|
32
|
+
* ## Why one effect and not the read-back / write-back PAIR
|
|
33
|
+
*
|
|
34
|
+
* Every other URL-bound control (the category dropdown, the sort select, the
|
|
35
|
+
* search box) uses two independent effects from `URLSearchParamSync`, each
|
|
36
|
+
* bailing when the value it would write is already there. That works because
|
|
37
|
+
* both sides start out agreeing: the state is SEEDED from
|
|
38
|
+
* `window.location.search` in its `useState` initializer, so by the time the
|
|
39
|
+
* effects run there is nothing to reconcile.
|
|
40
|
+
*
|
|
41
|
+
* The page cannot be seeded that way, for a reason that only shows up in a
|
|
42
|
+
* browser: a statically generated page is rendered on the server with page 1,
|
|
43
|
+
* and React does NOT repair mismatched ATTRIBUTES when it hydrates — it keeps
|
|
44
|
+
* the server's DOM and warns. A client that seeded page 3 renders "Previous" as
|
|
45
|
+
* enabled, the server rendered it disabled, and the disabled one is what stays
|
|
46
|
+
* on screen. Worse, it stays for good: React's later re-renders diff against the
|
|
47
|
+
* client's own first render, which already said enabled, so nothing ever
|
|
48
|
+
* repaints it. The rows would be page 3's with no way back to page 2.
|
|
49
|
+
*
|
|
50
|
+
* Adopting the URL in an effect instead makes the page change from 1 to 3 a
|
|
51
|
+
* real state transition, which React renders normally. But a naive PAIR of
|
|
52
|
+
* effects then races: on the render where the router becomes ready, the
|
|
53
|
+
* write-back sees page 1, deletes `?page=3` from the URL, and the read-back it
|
|
54
|
+
* was supposed to cooperate with reads back the page it just erased.
|
|
55
|
+
*
|
|
56
|
+
* So one effect owns both directions and decides which side moved:
|
|
57
|
+
*
|
|
58
|
+
* • the URL moved (a deep link, a `<Link>`, browser back/forward) ⇒ adopt it
|
|
59
|
+
* • the page moved (a click, or the filter reset) ⇒ write it
|
|
60
|
+
*
|
|
61
|
+
* The previously seen URL value is what separates the two, so neither direction
|
|
62
|
+
* has to guess. Page 1 is written as the ABSENCE of the key, so an unpaginated
|
|
63
|
+
* visit keeps a clean URL and a filter reset takes `?page=` back off it.
|
|
64
|
+
*
|
|
65
|
+
* ⚠️ A deep-linked page 2+ therefore costs one extra fetch: the provider mounts
|
|
66
|
+
* on page 1 and refetches when this effect adopts the URL. Correctness over the
|
|
67
|
+
* round trip — the alternative leaves a control the visitor cannot use.
|
|
68
|
+
*/
|
|
69
|
+
// Strict JS identifier check, mirroring `URLSearchParamSync`: a key like
|
|
70
|
+
// `foo-bar` has to go through bracket notation or the emitted code is a
|
|
71
|
+
// subtraction.
|
|
72
|
+
var VALID_JS_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
73
|
+
var accessKeyOf = function (object, paramKey) {
|
|
74
|
+
return VALID_JS_IDENTIFIER.test(paramKey)
|
|
75
|
+
? types.memberExpression(object, types.identifier(paramKey))
|
|
76
|
+
: types.memberExpression(object, types.stringLiteral(paramKey), true);
|
|
77
|
+
};
|
|
78
|
+
var routerQueryAccess = function (paramKey) {
|
|
79
|
+
return accessKeyOf(types.memberExpression(types.identifier('router'), types.identifier('query')), paramKey);
|
|
80
|
+
};
|
|
81
|
+
/** `const <refVar> = useRef(null)` — the last `?page=` value this effect saw. */
|
|
82
|
+
var buildPageUrlRefDeclaration = function (refVar) {
|
|
83
|
+
return types.variableDeclaration('const', [
|
|
84
|
+
types.variableDeclarator(types.identifier(refVar), types.callExpression(types.identifier('useRef'), [types.nullLiteral()])),
|
|
85
|
+
]);
|
|
86
|
+
};
|
|
87
|
+
exports.buildPageUrlRefDeclaration = buildPageUrlRefDeclaration;
|
|
88
|
+
/**
|
|
89
|
+
* Emitted shape (for `?page=`, a combined `{ page, debouncedQuery }` state):
|
|
90
|
+
*
|
|
91
|
+
* useEffect(() => {
|
|
92
|
+
* if (!router.isReady) return
|
|
93
|
+
* const __urlValue = router.query.page
|
|
94
|
+
* const __raw = typeof __urlValue === 'string' ? __urlValue
|
|
95
|
+
* : Array.isArray(__urlValue) ? __urlValue[0] || '' : ''
|
|
96
|
+
* const __urlPage = Math.max(1, parseInt(__raw, 10) || 1)
|
|
97
|
+
* const __statePage = ds_0_state.page
|
|
98
|
+
* const __seenUrlPage = ds_0_pageUrlRef.current
|
|
99
|
+
* if (__tqQuerySyncRef.current.inFlight === 0 &&
|
|
100
|
+
* __seenUrlPage !== __urlPage && __urlPage !== __statePage) {
|
|
101
|
+
* ds_0_pageUrlRef.current = __urlPage
|
|
102
|
+
* setDs_0_state(state => state.page === __urlPage ? state : { ...state, page: __urlPage })
|
|
103
|
+
* return
|
|
104
|
+
* }
|
|
105
|
+
* ds_0_pageUrlRef.current = __urlPage
|
|
106
|
+
* if (__urlPage === __statePage) return
|
|
107
|
+
* __tqWriteQueryParam('page', __statePage <= 1 ? undefined : __statePage)
|
|
108
|
+
* }, [router.query.page, router.isReady, ds_0_state.page])
|
|
109
|
+
*
|
|
110
|
+
* The write goes through `URLQueryWriter` rather than spreading `router.query`
|
|
111
|
+
* here. This effect and a filter's write-back fire in the SAME flush on every
|
|
112
|
+
* filter change (the reset moves the page), and two effects each merging into
|
|
113
|
+
* their own stale snapshot of `router.query` erase each other's keys — see
|
|
114
|
+
* `url-query-writer.ts` for why that then never settles.
|
|
115
|
+
*/
|
|
116
|
+
var buildPageUrlSyncEffect = function (options) {
|
|
117
|
+
var refCurrent = function () {
|
|
118
|
+
return types.memberExpression(types.identifier(options.refVar), types.identifier('current'));
|
|
119
|
+
};
|
|
120
|
+
var rememberUrlPage = function () {
|
|
121
|
+
return types.expressionStatement(types.assignmentExpression('=', refCurrent(), types.identifier('__urlPage')));
|
|
122
|
+
};
|
|
123
|
+
var effectBody = types.blockStatement([
|
|
124
|
+
types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('router'), types.identifier('isReady'))), types.returnStatement(null)),
|
|
125
|
+
types.variableDeclaration('const', [
|
|
126
|
+
types.variableDeclarator(types.identifier('__urlValue'), routerQueryAccess(options.paramKey)),
|
|
127
|
+
]),
|
|
128
|
+
// `router.query[key]` is `string | string[] | undefined` in Next's typings.
|
|
129
|
+
types.variableDeclaration('const', [
|
|
130
|
+
types.variableDeclarator(types.identifier('__raw'), types.conditionalExpression(types.binaryExpression('===', types.unaryExpression('typeof', types.identifier('__urlValue')), types.stringLiteral('string')), types.identifier('__urlValue'), types.conditionalExpression(types.callExpression(types.memberExpression(types.identifier('Array'), types.identifier('isArray')), [types.identifier('__urlValue')]), types.logicalExpression('||', types.memberExpression(types.identifier('__urlValue'), types.numericLiteral(0), true), types.stringLiteral('')), types.stringLiteral('')))),
|
|
131
|
+
]),
|
|
132
|
+
// A missing, unparseable or out-of-range param all mean page 1 — which is
|
|
133
|
+
// also the value written as no key at all, so the two sides agree.
|
|
134
|
+
types.variableDeclaration('const', [
|
|
135
|
+
types.variableDeclarator(types.identifier('__urlPage'), types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('max')), [
|
|
136
|
+
types.numericLiteral(1),
|
|
137
|
+
types.logicalExpression('||', types.callExpression(types.identifier('parseInt'), [
|
|
138
|
+
types.identifier('__raw'),
|
|
139
|
+
types.numericLiteral(10),
|
|
140
|
+
]), types.numericLiteral(1)),
|
|
141
|
+
])),
|
|
142
|
+
]),
|
|
143
|
+
types.variableDeclaration('const', [
|
|
144
|
+
types.variableDeclarator(types.identifier('__statePage'), options.currentPageExpr()),
|
|
145
|
+
]),
|
|
146
|
+
types.variableDeclaration('const', [
|
|
147
|
+
types.variableDeclarator(types.identifier('__seenUrlPage'), refCurrent()),
|
|
148
|
+
]),
|
|
149
|
+
// The URL is the side that moved: a deep link (nothing seen yet), a
|
|
150
|
+
// same-path navigation, or browser back/forward.
|
|
151
|
+
types.ifStatement(types.logicalExpression('&&',
|
|
152
|
+
// ⛔ Only when nothing this component asked for is still landing.
|
|
153
|
+
// Mid-flight, `router.query` holds a page the visitor is on their way
|
|
154
|
+
// OUT of (the filter reset writes page 1 while `?page=5` is still in the
|
|
155
|
+
// bar), and adopting it would put them straight back on it.
|
|
156
|
+
teleport_plugin_common_1.URLQueryWriter.buildQuerySettledExpr(), types.logicalExpression('&&', types.binaryExpression('!==', types.identifier('__seenUrlPage'), types.identifier('__urlPage')), types.binaryExpression('!==', types.identifier('__urlPage'), types.identifier('__statePage')))), types.blockStatement([
|
|
157
|
+
rememberUrlPage(),
|
|
158
|
+
types.expressionStatement(options.buildSetPageStatement(types.identifier('__urlPage'))),
|
|
159
|
+
types.returnStatement(null),
|
|
160
|
+
])),
|
|
161
|
+
rememberUrlPage(),
|
|
162
|
+
types.ifStatement(types.binaryExpression('===', types.identifier('__urlPage'), types.identifier('__statePage')), types.returnStatement(null)),
|
|
163
|
+
// The page is the side that moved: a control click, or the filter reset.
|
|
164
|
+
// The write goes through the shared query writer so it merges into the last
|
|
165
|
+
// query this component asked for — the filter's own write-back may still be
|
|
166
|
+
// in flight in this very flush. Page 1 is written as the ABSENCE of the key,
|
|
167
|
+
// which the writer expresses as `undefined`.
|
|
168
|
+
teleport_plugin_common_1.URLQueryWriter.buildQueryWriteCall(options.paramKey, types.conditionalExpression(types.binaryExpression('<=', types.identifier('__statePage'), types.numericLiteral(1)), types.identifier('undefined'), types.identifier('__statePage'))),
|
|
169
|
+
]);
|
|
170
|
+
return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
|
|
171
|
+
types.arrowFunctionExpression([], effectBody),
|
|
172
|
+
types.arrayExpression([
|
|
173
|
+
routerQueryAccess(options.paramKey),
|
|
174
|
+
types.memberExpression(types.identifier('router'), types.identifier('isReady')),
|
|
175
|
+
options.currentPageExpr(),
|
|
176
|
+
]),
|
|
177
|
+
]));
|
|
178
|
+
};
|
|
179
|
+
exports.buildPageUrlSyncEffect = buildPageUrlSyncEffect;
|
|
180
|
+
//# sourceMappingURL=page-url-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-url-sync.js","sourceRoot":"","sources":["../../src/page-url-sync.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAqC;AACrC,6EAAmE;AA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CAAC,CAAC,CAAC,CAAC,EACtF,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAC7B,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAChC,CACF;KACF,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,mBAAmB,CAC9B,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAClD,KAAK,CAAC,uBAAuB,CAAC,EAAE,EAAE,UAAU,CAAC;QAC7C,KAAK,CAAC,eAAe,CAAC;YACpB,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC;YACnC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YAC/E,OAAO,CAAC,eAAe,EAAE;SAC1B,CAAC;KACH,CAAC,CACH,CAAA;AACH,CAAC,CAAA;AArIY,QAAA,sBAAsB,0BAqIlC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* How the generator recognises the pagination controls the builder authored.
|
|
4
|
+
*
|
|
5
|
+
* The marker is a STATIC UIDL attribute, which survives the resolver, the JSX
|
|
6
|
+
* printer and the browser verbatim — unlike `elementType`, which the resolver
|
|
7
|
+
* replaces with the node's `semanticType`, and unlike the class name, which is
|
|
8
|
+
* a side effect of the styling pipeline (`ThqPreviousElm` →
|
|
9
|
+
* `products-list-thq-previous-elm`) and so silently renames whenever a node is
|
|
10
|
+
* renamed. The same attribute is readable from the DOM, which is how the
|
|
11
|
+
* pagination-scroll runtime already identifies its own nodes.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PAGINATION_CONTROL_ATTR = "data-tq-pagination-control";
|
|
14
|
+
/**
|
|
15
|
+
* `'pages'` is the container the page-number buttons are repeated into and
|
|
16
|
+
* `'page'` the single template button inside it. `'ellipsis'` and `'sentinel'`
|
|
17
|
+
* are reserved for an authored gap marker / scroll sentinel; until a builder
|
|
18
|
+
* emits them both runtimes fall back to generating their own.
|
|
19
|
+
*/
|
|
20
|
+
export type PaginationControlKind = 'first' | 'previous' | 'pages' | 'page' | 'ellipsis' | 'next' | 'last' | 'load-more' | 'sentinel';
|
|
21
|
+
export declare function readJSXAttributeString(node: any, attrName: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Depth-first search for one authored pagination control.
|
|
24
|
+
*
|
|
25
|
+
* `legacyClassName` keeps every project generated before the marker existed
|
|
26
|
+
* working: its Previous/Next buttons carry no attribute, so the search falls
|
|
27
|
+
* back to the class-name substring the generator has always matched on. New
|
|
28
|
+
* control kinds have no legacy spelling and are marker-only.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findPaginationControl(root: any, kind: PaginationControlKind, legacyClassName?: string): any;
|
|
31
|
+
/** Every authored control of one kind, in document order (page-number templates aside, callers want one). */
|
|
32
|
+
export declare function findAllPaginationControls(root: any, kind: PaginationControlKind): any[];
|
|
33
|
+
/**
|
|
34
|
+
* Turns an authored control into a real `<button type="button">`.
|
|
35
|
+
*
|
|
36
|
+
* The builders author these as styled containers (a `div` after the resolver),
|
|
37
|
+
* so without this a keyboard user could never reach them and a click would not
|
|
38
|
+
* register as a form-safe activation. An author-supplied `type` is respected.
|
|
39
|
+
*/
|
|
40
|
+
export declare function convertControlToButton(node: any): void;
|
|
41
|
+
/** Replaces (never duplicates) one JSX attribute, appending it last. */
|
|
42
|
+
export declare function setJSXExpressionAttribute(node: any, attrName: string, expression: types.Expression): void;
|
|
43
|
+
/** Drops one JSX attribute if present. */
|
|
44
|
+
export declare function removeJSXAttribute(node: any, attrName: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Removes the controls that belong to a pagination mode this mapper is not in —
|
|
47
|
+
* a numbered strip left in a Previous/Next list would render unwired buttons
|
|
48
|
+
* that look clickable and do nothing.
|
|
49
|
+
*
|
|
50
|
+
* Children carrying NO marker are always kept: they are the author's own
|
|
51
|
+
* additions (a page counter, a spacer) and the generator has no business
|
|
52
|
+
* deciding whether they belong.
|
|
53
|
+
*/
|
|
54
|
+
export declare function dropInactivePaginationControls(paginationNode: any, activeKinds: PaginationControlKind[]): void;
|
|
55
|
+
//# sourceMappingURL=pagination-controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination-controls.d.ts","sourceRoot":"","sources":["../../src/pagination-controls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,+BAA+B,CAAA;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAC7B,OAAO,GACP,UAAU,GACV,OAAO,GACP,MAAM,GACN,UAAU,GACV,MAAM,GACN,MAAM,GACN,WAAW,GACX,UAAU,CAAA;AAOd,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,qBAAqB,EAC3B,eAAe,CAAC,EAAE,MAAM,GACvB,GAAG,CA2BL;AAED,6GAA6G;AAC7G,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,qBAAqB,GAAG,GAAG,EAAE,CAkBvF;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAWtD;AAED,wEAAwE;AACxE,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,KAAK,CAAC,UAAU,GAC3B,IAAI,CAON;AAED,0CAA0C;AAC1C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAIpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,cAAc,EAAE,GAAG,EACnB,WAAW,EAAE,qBAAqB,EAAE,GACnC,IAAI,CAgBN"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.dropInactivePaginationControls = exports.removeJSXAttribute = exports.setJSXExpressionAttribute = exports.convertControlToButton = exports.findAllPaginationControls = exports.findPaginationControl = exports.readJSXAttributeString = exports.PAGINATION_CONTROL_ATTR = void 0;
|
|
27
|
+
var types = __importStar(require("@babel/types"));
|
|
28
|
+
/**
|
|
29
|
+
* How the generator recognises the pagination controls the builder authored.
|
|
30
|
+
*
|
|
31
|
+
* The marker is a STATIC UIDL attribute, which survives the resolver, the JSX
|
|
32
|
+
* printer and the browser verbatim — unlike `elementType`, which the resolver
|
|
33
|
+
* replaces with the node's `semanticType`, and unlike the class name, which is
|
|
34
|
+
* a side effect of the styling pipeline (`ThqPreviousElm` →
|
|
35
|
+
* `products-list-thq-previous-elm`) and so silently renames whenever a node is
|
|
36
|
+
* renamed. The same attribute is readable from the DOM, which is how the
|
|
37
|
+
* pagination-scroll runtime already identifies its own nodes.
|
|
38
|
+
*/
|
|
39
|
+
exports.PAGINATION_CONTROL_ATTR = 'data-tq-pagination-control';
|
|
40
|
+
// tslint:disable:no-any
|
|
41
|
+
// Reads a JSX attribute's literal string value, covering both the plain
|
|
42
|
+
// `attr="value"` form and the `attr={'value'}` container the UIDL printer emits
|
|
43
|
+
// for some static attributes.
|
|
44
|
+
function readJSXAttributeString(node, attrName) {
|
|
45
|
+
var _a, _b, _c, _d, _e;
|
|
46
|
+
var attr = (_b = (_a = node === null || node === void 0 ? void 0 : node.openingElement) === null || _a === void 0 ? void 0 : _a.attributes) === null || _b === void 0 ? void 0 : _b.find(function (candidate) { var _a; return candidate.type === 'JSXAttribute' && ((_a = candidate.name) === null || _a === void 0 ? void 0 : _a.name) === attrName; });
|
|
47
|
+
return ((_c = attr === null || attr === void 0 ? void 0 : attr.value) === null || _c === void 0 ? void 0 : _c.value) || ((_e = (_d = attr === null || attr === void 0 ? void 0 : attr.value) === null || _d === void 0 ? void 0 : _d.expression) === null || _e === void 0 ? void 0 : _e.value) || '';
|
|
48
|
+
}
|
|
49
|
+
exports.readJSXAttributeString = readJSXAttributeString;
|
|
50
|
+
/**
|
|
51
|
+
* Depth-first search for one authored pagination control.
|
|
52
|
+
*
|
|
53
|
+
* `legacyClassName` keeps every project generated before the marker existed
|
|
54
|
+
* working: its Previous/Next buttons carry no attribute, so the search falls
|
|
55
|
+
* back to the class-name substring the generator has always matched on. New
|
|
56
|
+
* control kinds have no legacy spelling and are marker-only.
|
|
57
|
+
*/
|
|
58
|
+
function findPaginationControl(root, kind, legacyClassName) {
|
|
59
|
+
var search = function (node, matches) {
|
|
60
|
+
if (!node) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (node.type === 'JSXElement' && matches(node)) {
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(node.children)) {
|
|
67
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
68
|
+
var child = _a[_i];
|
|
69
|
+
var found = search(child, matches);
|
|
70
|
+
if (found) {
|
|
71
|
+
return found;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
var byMarker = search(root, function (node) { return readJSXAttributeString(node, exports.PAGINATION_CONTROL_ATTR) === kind; });
|
|
78
|
+
if (byMarker || !legacyClassName) {
|
|
79
|
+
return byMarker;
|
|
80
|
+
}
|
|
81
|
+
return search(root, function (node) { return readJSXAttributeString(node, 'className').includes(legacyClassName); });
|
|
82
|
+
}
|
|
83
|
+
exports.findPaginationControl = findPaginationControl;
|
|
84
|
+
/** Every authored control of one kind, in document order (page-number templates aside, callers want one). */
|
|
85
|
+
function findAllPaginationControls(root, kind) {
|
|
86
|
+
var found = [];
|
|
87
|
+
var traverse = function (node) {
|
|
88
|
+
if (!node) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (node.type === 'JSXElement' &&
|
|
92
|
+
readJSXAttributeString(node, exports.PAGINATION_CONTROL_ATTR) === kind) {
|
|
93
|
+
found.push(node);
|
|
94
|
+
}
|
|
95
|
+
if (Array.isArray(node.children)) {
|
|
96
|
+
node.children.forEach(traverse);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
traverse(root);
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
exports.findAllPaginationControls = findAllPaginationControls;
|
|
103
|
+
/**
|
|
104
|
+
* Turns an authored control into a real `<button type="button">`.
|
|
105
|
+
*
|
|
106
|
+
* The builders author these as styled containers (a `div` after the resolver),
|
|
107
|
+
* so without this a keyboard user could never reach them and a click would not
|
|
108
|
+
* register as a form-safe activation. An author-supplied `type` is respected.
|
|
109
|
+
*/
|
|
110
|
+
function convertControlToButton(node) {
|
|
111
|
+
node.openingElement.name.name = 'button';
|
|
112
|
+
if (node.closingElement) {
|
|
113
|
+
node.closingElement.name.name = 'button';
|
|
114
|
+
}
|
|
115
|
+
var hasType = node.openingElement.attributes.some(function (attr) { var _a; return ((_a = attr.name) === null || _a === void 0 ? void 0 : _a.name) === 'type'; });
|
|
116
|
+
if (!hasType) {
|
|
117
|
+
node.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('type'), types.stringLiteral('button')));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.convertControlToButton = convertControlToButton;
|
|
121
|
+
/** Replaces (never duplicates) one JSX attribute, appending it last. */
|
|
122
|
+
function setJSXExpressionAttribute(node, attrName, expression) {
|
|
123
|
+
node.openingElement.attributes = node.openingElement.attributes.filter(function (attr) { var _a; return ((_a = attr.name) === null || _a === void 0 ? void 0 : _a.name) !== attrName; });
|
|
124
|
+
node.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier(attrName), types.jsxExpressionContainer(expression)));
|
|
125
|
+
}
|
|
126
|
+
exports.setJSXExpressionAttribute = setJSXExpressionAttribute;
|
|
127
|
+
/** Drops one JSX attribute if present. */
|
|
128
|
+
function removeJSXAttribute(node, attrName) {
|
|
129
|
+
node.openingElement.attributes = node.openingElement.attributes.filter(function (attr) { var _a; return ((_a = attr.name) === null || _a === void 0 ? void 0 : _a.name) !== attrName; });
|
|
130
|
+
}
|
|
131
|
+
exports.removeJSXAttribute = removeJSXAttribute;
|
|
132
|
+
/**
|
|
133
|
+
* Removes the controls that belong to a pagination mode this mapper is not in —
|
|
134
|
+
* a numbered strip left in a Previous/Next list would render unwired buttons
|
|
135
|
+
* that look clickable and do nothing.
|
|
136
|
+
*
|
|
137
|
+
* Children carrying NO marker are always kept: they are the author's own
|
|
138
|
+
* additions (a page counter, a spacer) and the generator has no business
|
|
139
|
+
* deciding whether they belong.
|
|
140
|
+
*/
|
|
141
|
+
function dropInactivePaginationControls(paginationNode, activeKinds) {
|
|
142
|
+
var active = new Set(activeKinds);
|
|
143
|
+
var prune = function (node) {
|
|
144
|
+
if (!node || !Array.isArray(node.children)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
node.children = node.children.filter(function (child) {
|
|
148
|
+
if ((child === null || child === void 0 ? void 0 : child.type) !== 'JSXElement') {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
var marker = readJSXAttributeString(child, exports.PAGINATION_CONTROL_ATTR);
|
|
152
|
+
return marker === '' || active.has(marker);
|
|
153
|
+
});
|
|
154
|
+
node.children.forEach(prune);
|
|
155
|
+
};
|
|
156
|
+
prune(paginationNode);
|
|
157
|
+
}
|
|
158
|
+
exports.dropInactivePaginationControls = dropInactivePaginationControls;
|
|
159
|
+
//# sourceMappingURL=pagination-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination-controls.js","sourceRoot":"","sources":["../../src/pagination-controls.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAqC;AAErC;;;;;;;;;;GAUG;AACU,QAAA,uBAAuB,GAAG,4BAA4B,CAAA;AAmBnE,wBAAwB;AAExB,wEAAwE;AACxE,gFAAgF;AAChF,8BAA8B;AAC9B,SAAgB,sBAAsB,CAAC,IAAS,EAAE,QAAgB;;IAChE,IAAM,IAAI,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,0CAAE,UAAU,0CAAE,IAAI,CACjD,UAAC,SAAc,YAAK,OAAA,SAAS,CAAC,IAAI,KAAK,cAAc,IAAI,CAAA,MAAA,SAAS,CAAC,IAAI,0CAAE,IAAI,MAAK,QAAQ,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