@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
|
+
/** `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,152 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
import { URLQueryWriter } from '@teleporthq/teleport-plugin-common';
|
|
3
|
+
/**
|
|
4
|
+
* Keeping the current page and the `?page=` query in step.
|
|
5
|
+
*
|
|
6
|
+
* ## Why one effect and not the read-back / write-back PAIR
|
|
7
|
+
*
|
|
8
|
+
* Every other URL-bound control (the category dropdown, the sort select, the
|
|
9
|
+
* search box) uses two independent effects from `URLSearchParamSync`, each
|
|
10
|
+
* bailing when the value it would write is already there. That works because
|
|
11
|
+
* both sides start out agreeing: the state is SEEDED from
|
|
12
|
+
* `window.location.search` in its `useState` initializer, so by the time the
|
|
13
|
+
* effects run there is nothing to reconcile.
|
|
14
|
+
*
|
|
15
|
+
* The page cannot be seeded that way, for a reason that only shows up in a
|
|
16
|
+
* browser: a statically generated page is rendered on the server with page 1,
|
|
17
|
+
* and React does NOT repair mismatched ATTRIBUTES when it hydrates — it keeps
|
|
18
|
+
* the server's DOM and warns. A client that seeded page 3 renders "Previous" as
|
|
19
|
+
* enabled, the server rendered it disabled, and the disabled one is what stays
|
|
20
|
+
* on screen. Worse, it stays for good: React's later re-renders diff against the
|
|
21
|
+
* client's own first render, which already said enabled, so nothing ever
|
|
22
|
+
* repaints it. The rows would be page 3's with no way back to page 2.
|
|
23
|
+
*
|
|
24
|
+
* Adopting the URL in an effect instead makes the page change from 1 to 3 a
|
|
25
|
+
* real state transition, which React renders normally. But a naive PAIR of
|
|
26
|
+
* effects then races: on the render where the router becomes ready, the
|
|
27
|
+
* write-back sees page 1, deletes `?page=3` from the URL, and the read-back it
|
|
28
|
+
* was supposed to cooperate with reads back the page it just erased.
|
|
29
|
+
*
|
|
30
|
+
* So one effect owns both directions and decides which side moved:
|
|
31
|
+
*
|
|
32
|
+
* • the URL moved (a deep link, a `<Link>`, browser back/forward) ⇒ adopt it
|
|
33
|
+
* • the page moved (a click, or the filter reset) ⇒ write it
|
|
34
|
+
*
|
|
35
|
+
* The previously seen URL value is what separates the two, so neither direction
|
|
36
|
+
* has to guess. Page 1 is written as the ABSENCE of the key, so an unpaginated
|
|
37
|
+
* visit keeps a clean URL and a filter reset takes `?page=` back off it.
|
|
38
|
+
*
|
|
39
|
+
* ⚠️ A deep-linked page 2+ therefore costs one extra fetch: the provider mounts
|
|
40
|
+
* on page 1 and refetches when this effect adopts the URL. Correctness over the
|
|
41
|
+
* round trip — the alternative leaves a control the visitor cannot use.
|
|
42
|
+
*/
|
|
43
|
+
// Strict JS identifier check, mirroring `URLSearchParamSync`: a key like
|
|
44
|
+
// `foo-bar` has to go through bracket notation or the emitted code is a
|
|
45
|
+
// subtraction.
|
|
46
|
+
var VALID_JS_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
47
|
+
var accessKeyOf = function (object, paramKey) {
|
|
48
|
+
return VALID_JS_IDENTIFIER.test(paramKey)
|
|
49
|
+
? types.memberExpression(object, types.identifier(paramKey))
|
|
50
|
+
: types.memberExpression(object, types.stringLiteral(paramKey), true);
|
|
51
|
+
};
|
|
52
|
+
var routerQueryAccess = function (paramKey) {
|
|
53
|
+
return accessKeyOf(types.memberExpression(types.identifier('router'), types.identifier('query')), paramKey);
|
|
54
|
+
};
|
|
55
|
+
/** `const <refVar> = useRef(null)` — the last `?page=` value this effect saw. */
|
|
56
|
+
export var buildPageUrlRefDeclaration = function (refVar) {
|
|
57
|
+
return types.variableDeclaration('const', [
|
|
58
|
+
types.variableDeclarator(types.identifier(refVar), types.callExpression(types.identifier('useRef'), [types.nullLiteral()])),
|
|
59
|
+
]);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Emitted shape (for `?page=`, a combined `{ page, debouncedQuery }` state):
|
|
63
|
+
*
|
|
64
|
+
* useEffect(() => {
|
|
65
|
+
* if (!router.isReady) return
|
|
66
|
+
* const __urlValue = router.query.page
|
|
67
|
+
* const __raw = typeof __urlValue === 'string' ? __urlValue
|
|
68
|
+
* : Array.isArray(__urlValue) ? __urlValue[0] || '' : ''
|
|
69
|
+
* const __urlPage = Math.max(1, parseInt(__raw, 10) || 1)
|
|
70
|
+
* const __statePage = ds_0_state.page
|
|
71
|
+
* const __seenUrlPage = ds_0_pageUrlRef.current
|
|
72
|
+
* if (__tqQuerySyncRef.current.inFlight === 0 &&
|
|
73
|
+
* __seenUrlPage !== __urlPage && __urlPage !== __statePage) {
|
|
74
|
+
* ds_0_pageUrlRef.current = __urlPage
|
|
75
|
+
* setDs_0_state(state => state.page === __urlPage ? state : { ...state, page: __urlPage })
|
|
76
|
+
* return
|
|
77
|
+
* }
|
|
78
|
+
* ds_0_pageUrlRef.current = __urlPage
|
|
79
|
+
* if (__urlPage === __statePage) return
|
|
80
|
+
* __tqWriteQueryParam('page', __statePage <= 1 ? undefined : __statePage)
|
|
81
|
+
* }, [router.query.page, router.isReady, ds_0_state.page])
|
|
82
|
+
*
|
|
83
|
+
* The write goes through `URLQueryWriter` rather than spreading `router.query`
|
|
84
|
+
* here. This effect and a filter's write-back fire in the SAME flush on every
|
|
85
|
+
* filter change (the reset moves the page), and two effects each merging into
|
|
86
|
+
* their own stale snapshot of `router.query` erase each other's keys — see
|
|
87
|
+
* `url-query-writer.ts` for why that then never settles.
|
|
88
|
+
*/
|
|
89
|
+
export var buildPageUrlSyncEffect = function (options) {
|
|
90
|
+
var refCurrent = function () {
|
|
91
|
+
return types.memberExpression(types.identifier(options.refVar), types.identifier('current'));
|
|
92
|
+
};
|
|
93
|
+
var rememberUrlPage = function () {
|
|
94
|
+
return types.expressionStatement(types.assignmentExpression('=', refCurrent(), types.identifier('__urlPage')));
|
|
95
|
+
};
|
|
96
|
+
var effectBody = types.blockStatement([
|
|
97
|
+
types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('router'), types.identifier('isReady'))), types.returnStatement(null)),
|
|
98
|
+
types.variableDeclaration('const', [
|
|
99
|
+
types.variableDeclarator(types.identifier('__urlValue'), routerQueryAccess(options.paramKey)),
|
|
100
|
+
]),
|
|
101
|
+
// `router.query[key]` is `string | string[] | undefined` in Next's typings.
|
|
102
|
+
types.variableDeclaration('const', [
|
|
103
|
+
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('')))),
|
|
104
|
+
]),
|
|
105
|
+
// A missing, unparseable or out-of-range param all mean page 1 — which is
|
|
106
|
+
// also the value written as no key at all, so the two sides agree.
|
|
107
|
+
types.variableDeclaration('const', [
|
|
108
|
+
types.variableDeclarator(types.identifier('__urlPage'), types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('max')), [
|
|
109
|
+
types.numericLiteral(1),
|
|
110
|
+
types.logicalExpression('||', types.callExpression(types.identifier('parseInt'), [
|
|
111
|
+
types.identifier('__raw'),
|
|
112
|
+
types.numericLiteral(10),
|
|
113
|
+
]), types.numericLiteral(1)),
|
|
114
|
+
])),
|
|
115
|
+
]),
|
|
116
|
+
types.variableDeclaration('const', [
|
|
117
|
+
types.variableDeclarator(types.identifier('__statePage'), options.currentPageExpr()),
|
|
118
|
+
]),
|
|
119
|
+
types.variableDeclaration('const', [
|
|
120
|
+
types.variableDeclarator(types.identifier('__seenUrlPage'), refCurrent()),
|
|
121
|
+
]),
|
|
122
|
+
// The URL is the side that moved: a deep link (nothing seen yet), a
|
|
123
|
+
// same-path navigation, or browser back/forward.
|
|
124
|
+
types.ifStatement(types.logicalExpression('&&',
|
|
125
|
+
// ⛔ Only when nothing this component asked for is still landing.
|
|
126
|
+
// Mid-flight, `router.query` holds a page the visitor is on their way
|
|
127
|
+
// OUT of (the filter reset writes page 1 while `?page=5` is still in the
|
|
128
|
+
// bar), and adopting it would put them straight back on it.
|
|
129
|
+
URLQueryWriter.buildQuerySettledExpr(), types.logicalExpression('&&', types.binaryExpression('!==', types.identifier('__seenUrlPage'), types.identifier('__urlPage')), types.binaryExpression('!==', types.identifier('__urlPage'), types.identifier('__statePage')))), types.blockStatement([
|
|
130
|
+
rememberUrlPage(),
|
|
131
|
+
types.expressionStatement(options.buildSetPageStatement(types.identifier('__urlPage'))),
|
|
132
|
+
types.returnStatement(null),
|
|
133
|
+
])),
|
|
134
|
+
rememberUrlPage(),
|
|
135
|
+
types.ifStatement(types.binaryExpression('===', types.identifier('__urlPage'), types.identifier('__statePage')), types.returnStatement(null)),
|
|
136
|
+
// The page is the side that moved: a control click, or the filter reset.
|
|
137
|
+
// The write goes through the shared query writer so it merges into the last
|
|
138
|
+
// query this component asked for — the filter's own write-back may still be
|
|
139
|
+
// in flight in this very flush. Page 1 is written as the ABSENCE of the key,
|
|
140
|
+
// which the writer expresses as `undefined`.
|
|
141
|
+
URLQueryWriter.buildQueryWriteCall(options.paramKey, types.conditionalExpression(types.binaryExpression('<=', types.identifier('__statePage'), types.numericLiteral(1)), types.identifier('undefined'), types.identifier('__statePage'))),
|
|
142
|
+
]);
|
|
143
|
+
return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
|
|
144
|
+
types.arrowFunctionExpression([], effectBody),
|
|
145
|
+
types.arrayExpression([
|
|
146
|
+
routerQueryAccess(options.paramKey),
|
|
147
|
+
types.memberExpression(types.identifier('router'), types.identifier('isReady')),
|
|
148
|
+
options.currentPageExpr(),
|
|
149
|
+
]),
|
|
150
|
+
]));
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=page-url-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-url-sync.js","sourceRoot":"","sources":["../../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AC,qBAAqB,CACzB,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC,cAAc,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"}
|
|
@@ -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,126 @@
|
|
|
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 var PAGINATION_CONTROL_ATTR = 'data-tq-pagination-control';
|
|
14
|
+
// tslint:disable:no-any
|
|
15
|
+
// Reads a JSX attribute's literal string value, covering both the plain
|
|
16
|
+
// `attr="value"` form and the `attr={'value'}` container the UIDL printer emits
|
|
17
|
+
// for some static attributes.
|
|
18
|
+
export function readJSXAttributeString(node, attrName) {
|
|
19
|
+
var _a, _b, _c, _d, _e;
|
|
20
|
+
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; });
|
|
21
|
+
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) || '';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Depth-first search for one authored pagination control.
|
|
25
|
+
*
|
|
26
|
+
* `legacyClassName` keeps every project generated before the marker existed
|
|
27
|
+
* working: its Previous/Next buttons carry no attribute, so the search falls
|
|
28
|
+
* back to the class-name substring the generator has always matched on. New
|
|
29
|
+
* control kinds have no legacy spelling and are marker-only.
|
|
30
|
+
*/
|
|
31
|
+
export function findPaginationControl(root, kind, legacyClassName) {
|
|
32
|
+
var search = function (node, matches) {
|
|
33
|
+
if (!node) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (node.type === 'JSXElement' && matches(node)) {
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(node.children)) {
|
|
40
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
41
|
+
var child = _a[_i];
|
|
42
|
+
var found = search(child, matches);
|
|
43
|
+
if (found) {
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
var byMarker = search(root, function (node) { return readJSXAttributeString(node, PAGINATION_CONTROL_ATTR) === kind; });
|
|
51
|
+
if (byMarker || !legacyClassName) {
|
|
52
|
+
return byMarker;
|
|
53
|
+
}
|
|
54
|
+
return search(root, function (node) { return readJSXAttributeString(node, 'className').includes(legacyClassName); });
|
|
55
|
+
}
|
|
56
|
+
/** Every authored control of one kind, in document order (page-number templates aside, callers want one). */
|
|
57
|
+
export function findAllPaginationControls(root, kind) {
|
|
58
|
+
var found = [];
|
|
59
|
+
var traverse = function (node) {
|
|
60
|
+
if (!node) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (node.type === 'JSXElement' &&
|
|
64
|
+
readJSXAttributeString(node, PAGINATION_CONTROL_ATTR) === kind) {
|
|
65
|
+
found.push(node);
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(node.children)) {
|
|
68
|
+
node.children.forEach(traverse);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
traverse(root);
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Turns an authored control into a real `<button type="button">`.
|
|
76
|
+
*
|
|
77
|
+
* The builders author these as styled containers (a `div` after the resolver),
|
|
78
|
+
* so without this a keyboard user could never reach them and a click would not
|
|
79
|
+
* register as a form-safe activation. An author-supplied `type` is respected.
|
|
80
|
+
*/
|
|
81
|
+
export function convertControlToButton(node) {
|
|
82
|
+
node.openingElement.name.name = 'button';
|
|
83
|
+
if (node.closingElement) {
|
|
84
|
+
node.closingElement.name.name = 'button';
|
|
85
|
+
}
|
|
86
|
+
var hasType = node.openingElement.attributes.some(function (attr) { var _a; return ((_a = attr.name) === null || _a === void 0 ? void 0 : _a.name) === 'type'; });
|
|
87
|
+
if (!hasType) {
|
|
88
|
+
node.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('type'), types.stringLiteral('button')));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Replaces (never duplicates) one JSX attribute, appending it last. */
|
|
92
|
+
export function setJSXExpressionAttribute(node, attrName, expression) {
|
|
93
|
+
node.openingElement.attributes = node.openingElement.attributes.filter(function (attr) { var _a; return ((_a = attr.name) === null || _a === void 0 ? void 0 : _a.name) !== attrName; });
|
|
94
|
+
node.openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier(attrName), types.jsxExpressionContainer(expression)));
|
|
95
|
+
}
|
|
96
|
+
/** Drops one JSX attribute if present. */
|
|
97
|
+
export function removeJSXAttribute(node, attrName) {
|
|
98
|
+
node.openingElement.attributes = node.openingElement.attributes.filter(function (attr) { var _a; return ((_a = attr.name) === null || _a === void 0 ? void 0 : _a.name) !== attrName; });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Removes the controls that belong to a pagination mode this mapper is not in —
|
|
102
|
+
* a numbered strip left in a Previous/Next list would render unwired buttons
|
|
103
|
+
* that look clickable and do nothing.
|
|
104
|
+
*
|
|
105
|
+
* Children carrying NO marker are always kept: they are the author's own
|
|
106
|
+
* additions (a page counter, a spacer) and the generator has no business
|
|
107
|
+
* deciding whether they belong.
|
|
108
|
+
*/
|
|
109
|
+
export function dropInactivePaginationControls(paginationNode, activeKinds) {
|
|
110
|
+
var active = new Set(activeKinds);
|
|
111
|
+
var prune = function (node) {
|
|
112
|
+
if (!node || !Array.isArray(node.children)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
node.children = node.children.filter(function (child) {
|
|
116
|
+
if ((child === null || child === void 0 ? void 0 : child.type) !== 'JSXElement') {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
var marker = readJSXAttributeString(child, PAGINATION_CONTROL_ATTR);
|
|
120
|
+
return marker === '' || active.has(marker);
|
|
121
|
+
});
|
|
122
|
+
node.children.forEach(prune);
|
|
123
|
+
};
|
|
124
|
+
prune(paginationNode);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=pagination-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination-controls.js","sourceRoot":"","sources":["../../src/pagination-controls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,uBAAuB,GAAG,4BAA4B,CAAA;AAmBnE,wBAAwB;AAExB,wEAAwE;AACxE,gFAAgF;AAChF,8BAA8B;AAC9B,MAAM,UAAU,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,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YACD,IAAM,MAAM,GAAG,sBAAsB,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAA;YACrE,OAAO,MAAM,KAAK,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAC5C,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC,CAAA;IACD,KAAK,CAAC,cAAc,CAAC,CAAA;AACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination-plugin.d.ts","sourceRoot":"","sources":["../../src/pagination-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EAGvB,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"pagination-plugin.d.ts","sourceRoot":"","sources":["../../src/pagination-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EAGvB,MAAM,4BAA4B,CAAA;AA+iCnC,eAAO,MAAM,qCAAqC,EAAE,sBAAsB,CAAC,EAAE,CA40B5E,CAAA"}
|