@teleporthq/teleport-plugin-next-data-source 0.43.59 → 0.43.61

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.
Files changed (141) hide show
  1. package/__tests__/_helpers/pagination-widget-fixture.ts +230 -0
  2. package/__tests__/ecommerce-product-discounts.test.ts +196 -0
  3. package/__tests__/infinite-scroll.test.ts +143 -0
  4. package/__tests__/numbered-pagination.test.ts +113 -0
  5. package/__tests__/page-reset-on-filter-sort.test.ts +182 -0
  6. package/__tests__/page-url-sync.test.ts +208 -0
  7. package/__tests__/product-price-sort.ts +313 -0
  8. package/__tests__/search-url-sync.test.ts +7 -3
  9. package/dist/cjs/array-mapper-pagination.d.ts +9 -0
  10. package/dist/cjs/array-mapper-pagination.d.ts.map +1 -1
  11. package/dist/cjs/array-mapper-pagination.js.map +1 -1
  12. package/dist/cjs/cache/ast.d.ts.map +1 -1
  13. package/dist/cjs/cache/ast.js +2 -2
  14. package/dist/cjs/cache/ast.js.map +1 -1
  15. package/dist/cjs/count-effect.d.ts +42 -0
  16. package/dist/cjs/count-effect.d.ts.map +1 -0
  17. package/dist/cjs/count-effect.js +81 -0
  18. package/dist/cjs/count-effect.js.map +1 -0
  19. package/dist/cjs/fetchers/postgresql.d.ts.map +1 -1
  20. package/dist/cjs/fetchers/postgresql.js +2 -1
  21. package/dist/cjs/fetchers/postgresql.js.map +1 -1
  22. package/dist/cjs/fetchers/teleport.d.ts.map +1 -1
  23. package/dist/cjs/fetchers/teleport.js +3 -2
  24. package/dist/cjs/fetchers/teleport.js.map +1 -1
  25. package/dist/cjs/infinite-scroll.d.ts +65 -0
  26. package/dist/cjs/infinite-scroll.d.ts.map +1 -0
  27. package/dist/cjs/infinite-scroll.js +190 -0
  28. package/dist/cjs/infinite-scroll.js.map +1 -0
  29. package/dist/cjs/numbered-pagination.d.ts +42 -0
  30. package/dist/cjs/numbered-pagination.d.ts.map +1 -0
  31. package/dist/cjs/numbered-pagination.js +167 -0
  32. package/dist/cjs/numbered-pagination.js.map +1 -0
  33. package/dist/cjs/page-reset.d.ts +42 -0
  34. package/dist/cjs/page-reset.d.ts.map +1 -0
  35. package/dist/cjs/page-reset.js +116 -0
  36. package/dist/cjs/page-reset.js.map +1 -0
  37. package/dist/cjs/page-url-sync.d.ts +42 -0
  38. package/dist/cjs/page-url-sync.d.ts.map +1 -0
  39. package/dist/cjs/page-url-sync.js +180 -0
  40. package/dist/cjs/page-url-sync.js.map +1 -0
  41. package/dist/cjs/pagination-controls.d.ts +55 -0
  42. package/dist/cjs/pagination-controls.d.ts.map +1 -0
  43. package/dist/cjs/pagination-controls.js +159 -0
  44. package/dist/cjs/pagination-controls.js.map +1 -0
  45. package/dist/cjs/pagination-plugin.d.ts.map +1 -1
  46. package/dist/cjs/pagination-plugin.js +508 -164
  47. package/dist/cjs/pagination-plugin.js.map +1 -1
  48. package/dist/cjs/product-price-sort.d.ts +116 -0
  49. package/dist/cjs/product-price-sort.d.ts.map +1 -0
  50. package/dist/cjs/product-price-sort.js +169 -0
  51. package/dist/cjs/product-price-sort.js.map +1 -0
  52. package/dist/cjs/transformations/ecommerce-product.d.ts.map +1 -1
  53. package/dist/cjs/transformations/ecommerce-product.js +1 -1
  54. package/dist/cjs/transformations/ecommerce-product.js.map +1 -1
  55. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  56. package/dist/cjs/utils.d.ts.map +1 -1
  57. package/dist/cjs/utils.js +5 -7
  58. package/dist/cjs/utils.js.map +1 -1
  59. package/dist/esm/array-mapper-pagination.d.ts +9 -0
  60. package/dist/esm/array-mapper-pagination.d.ts.map +1 -1
  61. package/dist/esm/array-mapper-pagination.js.map +1 -1
  62. package/dist/esm/cache/ast.d.ts.map +1 -1
  63. package/dist/esm/cache/ast.js +2 -2
  64. package/dist/esm/cache/ast.js.map +1 -1
  65. package/dist/esm/count-effect.d.ts +42 -0
  66. package/dist/esm/count-effect.d.ts.map +1 -0
  67. package/dist/esm/count-effect.js +53 -0
  68. package/dist/esm/count-effect.js.map +1 -0
  69. package/dist/esm/fetchers/postgresql.d.ts.map +1 -1
  70. package/dist/esm/fetchers/postgresql.js +2 -1
  71. package/dist/esm/fetchers/postgresql.js.map +1 -1
  72. package/dist/esm/fetchers/teleport.d.ts.map +1 -1
  73. package/dist/esm/fetchers/teleport.js +3 -2
  74. package/dist/esm/fetchers/teleport.js.map +1 -1
  75. package/dist/esm/infinite-scroll.d.ts +65 -0
  76. package/dist/esm/infinite-scroll.d.ts.map +1 -0
  77. package/dist/esm/infinite-scroll.js +159 -0
  78. package/dist/esm/infinite-scroll.js.map +1 -0
  79. package/dist/esm/numbered-pagination.d.ts +42 -0
  80. package/dist/esm/numbered-pagination.d.ts.map +1 -0
  81. package/dist/esm/numbered-pagination.js +138 -0
  82. package/dist/esm/numbered-pagination.js.map +1 -0
  83. package/dist/esm/page-reset.d.ts +42 -0
  84. package/dist/esm/page-reset.d.ts.map +1 -0
  85. package/dist/esm/page-reset.js +87 -0
  86. package/dist/esm/page-reset.js.map +1 -0
  87. package/dist/esm/page-url-sync.d.ts +42 -0
  88. package/dist/esm/page-url-sync.d.ts.map +1 -0
  89. package/dist/esm/page-url-sync.js +152 -0
  90. package/dist/esm/page-url-sync.js.map +1 -0
  91. package/dist/esm/pagination-controls.d.ts +55 -0
  92. package/dist/esm/pagination-controls.d.ts.map +1 -0
  93. package/dist/esm/pagination-controls.js +126 -0
  94. package/dist/esm/pagination-controls.js.map +1 -0
  95. package/dist/esm/pagination-plugin.d.ts.map +1 -1
  96. package/dist/esm/pagination-plugin.js +510 -166
  97. package/dist/esm/pagination-plugin.js.map +1 -1
  98. package/dist/esm/product-price-sort.d.ts +116 -0
  99. package/dist/esm/product-price-sort.d.ts.map +1 -0
  100. package/dist/esm/product-price-sort.js +160 -0
  101. package/dist/esm/product-price-sort.js.map +1 -0
  102. package/dist/esm/transformations/ecommerce-product.d.ts.map +1 -1
  103. package/dist/esm/transformations/ecommerce-product.js +2 -2
  104. package/dist/esm/transformations/ecommerce-product.js.map +1 -1
  105. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  106. package/dist/esm/utils.d.ts.map +1 -1
  107. package/dist/esm/utils.js +6 -8
  108. package/dist/esm/utils.js.map +1 -1
  109. package/package.json +5 -5
  110. package/src/array-mapper-pagination.ts +10 -0
  111. package/src/cache/ast.ts +2 -2
  112. package/src/count-effect.ts +137 -0
  113. package/src/fetchers/postgresql.ts +52 -13
  114. package/src/fetchers/teleport.ts +53 -13
  115. package/src/infinite-scroll.ts +401 -0
  116. package/src/numbered-pagination.ts +292 -0
  117. package/src/page-reset.ts +162 -0
  118. package/src/page-url-sync.ts +241 -0
  119. package/src/pagination-controls.ts +176 -0
  120. package/src/pagination-plugin.ts +758 -351
  121. package/src/product-price-sort.ts +204 -0
  122. package/src/transformations/ecommerce-product.ts +33 -7
  123. package/src/utils.ts +6 -8
  124. package/dist/cjs/array-mapper-registry.d.ts +0 -85
  125. package/dist/cjs/array-mapper-registry.d.ts.map +0 -1
  126. package/dist/cjs/array-mapper-registry.js +0 -296
  127. package/dist/cjs/array-mapper-registry.js.map +0 -1
  128. package/dist/cjs/pagination-with-count.d.ts +0 -6
  129. package/dist/cjs/pagination-with-count.d.ts.map +0 -1
  130. package/dist/cjs/pagination-with-count.js +0 -63
  131. package/dist/cjs/pagination-with-count.js.map +0 -1
  132. package/dist/esm/array-mapper-registry.d.ts +0 -85
  133. package/dist/esm/array-mapper-registry.d.ts.map +0 -1
  134. package/dist/esm/array-mapper-registry.js +0 -292
  135. package/dist/esm/array-mapper-registry.js.map +0 -1
  136. package/dist/esm/pagination-with-count.d.ts +0 -6
  137. package/dist/esm/pagination-with-count.d.ts.map +0 -1
  138. package/dist/esm/pagination-with-count.js +0 -34
  139. package/dist/esm/pagination-with-count.js.map +0 -1
  140. package/src/array-mapper-registry.ts +0 -416
  141. package/src/pagination-with-count.ts +0 -89
@@ -0,0 +1,138 @@
1
+ import * as types from '@babel/types';
2
+ import { convertControlToButton, findPaginationControl, setJSXExpressionAttribute, } from './pagination-controls';
3
+ /**
4
+ * Numbered pagination: First / Prev / 1 … 4 5 6 … 12 / Next / Last.
5
+ *
6
+ * The builder authors ONE page-number button and a container to repeat it into;
7
+ * this module turns that template into a `.map` over a windowed token list, so
8
+ * every number the visitor sees is the author's own styled node rather than
9
+ * something the generator invented.
10
+ */
11
+ // tslint:disable:no-any
12
+ /** `ds_N_pageTokens` — the windowed list of page numbers and ellipsis markers. */
13
+ export var getPageTokensVar = function (index) { return "ds_".concat(index, "_pageTokens"); };
14
+ /**
15
+ * Builds the `useMemo` that decides which page numbers are visible.
16
+ *
17
+ * The window is deliberately small and fixed (first, last, and one neighbour
18
+ * either side of the current page, so at most seven entries): an unbounded
19
+ * strip is unusable at 300 pages and wraps the layout the author styled. The
20
+ * two ellipsis markers are distinct strings because React needs unique keys and
21
+ * a list can legitimately need a gap on both sides.
22
+ *
23
+ * ⛔ Keep this in step with `computePageWindow` in the editor's renderer — the
24
+ * canvas and the published page must agree on which numbers are shown, or the
25
+ * author styles a strip they will never see.
26
+ */
27
+ export var buildPageTokensDeclaration = function (index, maxPagesVar, currentPageExpr) {
28
+ var total = types.identifier('total');
29
+ var current = types.identifier('current');
30
+ var tokens = types.identifier('tokens');
31
+ var start = types.identifier('start');
32
+ var end = types.identifier('end');
33
+ var pageVar = types.identifier('p');
34
+ var body = types.blockStatement([
35
+ types.variableDeclaration('const', [
36
+ types.variableDeclarator(total, types.identifier(maxPagesVar)),
37
+ ]),
38
+ types.variableDeclaration('const', [
39
+ types.variableDeclarator(current, types.cloneNode(currentPageExpr, true)),
40
+ ]),
41
+ // Nothing matched at all — the empty branch of the list is what renders.
42
+ types.ifStatement(types.binaryExpression('<=', types.cloneNode(total, true), types.numericLiteral(0)), types.returnStatement(types.arrayExpression([]))),
43
+ types.ifStatement(types.binaryExpression('===', types.cloneNode(total, true), types.numericLiteral(1)), types.returnStatement(types.arrayExpression([types.numericLiteral(1)]))),
44
+ types.variableDeclaration('const', [
45
+ types.variableDeclarator(tokens, types.arrayExpression([types.numericLiteral(1)])),
46
+ ]),
47
+ types.variableDeclaration('const', [
48
+ types.variableDeclarator(start, types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('max')), [
49
+ types.numericLiteral(2),
50
+ types.binaryExpression('-', types.cloneNode(current, true), types.numericLiteral(1)),
51
+ ])),
52
+ ]),
53
+ types.variableDeclaration('const', [
54
+ types.variableDeclarator(end, types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('min')), [
55
+ types.binaryExpression('-', types.cloneNode(total, true), types.numericLiteral(1)),
56
+ types.binaryExpression('+', types.cloneNode(current, true), types.numericLiteral(1)),
57
+ ])),
58
+ ]),
59
+ types.ifStatement(types.binaryExpression('>', types.cloneNode(start, true), types.numericLiteral(2)), types.expressionStatement(types.callExpression(types.memberExpression(types.cloneNode(tokens, true), types.identifier('push')), [types.stringLiteral('start-ellipsis')]))),
60
+ types.forStatement(types.variableDeclaration('let', [
61
+ types.variableDeclarator(pageVar, types.cloneNode(start, true)),
62
+ ]), types.binaryExpression('<=', types.cloneNode(pageVar, true), types.cloneNode(end, true)), types.assignmentExpression('+=', types.cloneNode(pageVar, true), types.numericLiteral(1)), types.expressionStatement(types.callExpression(types.memberExpression(types.cloneNode(tokens, true), types.identifier('push')), [types.cloneNode(pageVar, true)]))),
63
+ types.ifStatement(types.binaryExpression('<', types.cloneNode(end, true), types.binaryExpression('-', types.cloneNode(total, true), types.numericLiteral(1))), types.expressionStatement(types.callExpression(types.memberExpression(types.cloneNode(tokens, true), types.identifier('push')), [types.stringLiteral('end-ellipsis')]))),
64
+ types.expressionStatement(types.callExpression(types.memberExpression(types.cloneNode(tokens, true), types.identifier('push')), [types.cloneNode(total, true)])),
65
+ types.returnStatement(types.cloneNode(tokens, true)),
66
+ ]);
67
+ return types.variableDeclaration('const', [
68
+ types.variableDeclarator(types.identifier(getPageTokensVar(index)), types.callExpression(types.identifier('useMemo'), [
69
+ types.arrowFunctionExpression([], body),
70
+ types.arrayExpression([
71
+ types.identifier(maxPagesVar),
72
+ types.cloneNode(currentPageExpr, true),
73
+ ]),
74
+ ])),
75
+ ]);
76
+ };
77
+ /** `<setter>(<page>)` wrapped so an already-current page does not re-render. */
78
+ var buildJumpHandler = function (vars, targetExpr) { return types.arrowFunctionExpression([], vars.buildSetPageStatement(targetExpr)); };
79
+ /**
80
+ * Wires the First / Last buttons and expands the page-number template.
81
+ *
82
+ * Prev / Next are left to `wirePaginationButtons`, which already emits them and
83
+ * whose output must stay byte-identical for every project that never switches
84
+ * mode.
85
+ */
86
+ export var wireNumberedPagination = function (paginationNode, vars) {
87
+ var firstButton = findPaginationControl(paginationNode, 'first');
88
+ var lastButton = findPaginationControl(paginationNode, 'last');
89
+ var pagesContainer = findPaginationControl(paginationNode, 'pages');
90
+ if (firstButton) {
91
+ convertControlToButton(firstButton);
92
+ setJSXExpressionAttribute(firstButton, 'onClick', buildJumpHandler(vars, types.numericLiteral(1)));
93
+ setJSXExpressionAttribute(firstButton, 'disabled', types.binaryExpression('<=', vars.currentPageExpr(), types.numericLiteral(1)));
94
+ }
95
+ if (lastButton) {
96
+ convertControlToButton(lastButton);
97
+ setJSXExpressionAttribute(lastButton, 'onClick', buildJumpHandler(vars, types.identifier(vars.maxPagesVar)));
98
+ // `maxPages === 0` is "no results", where jumping to the last page would
99
+ // mean jumping to page 0.
100
+ setJSXExpressionAttribute(lastButton, 'disabled', types.logicalExpression('||', types.binaryExpression('===', types.identifier(vars.maxPagesVar), types.numericLiteral(0)), types.binaryExpression('>=', vars.currentPageExpr(), types.identifier(vars.maxPagesVar))));
101
+ }
102
+ if (!pagesContainer) {
103
+ return;
104
+ }
105
+ var template = findPaginationControl(pagesContainer, 'page');
106
+ if (!template) {
107
+ // A container with no template to repeat: leave whatever the author put
108
+ // there alone rather than inventing an unstyled strip.
109
+ return;
110
+ }
111
+ var ellipsisTemplate = findPaginationControl(pagesContainer, 'ellipsis');
112
+ var tokenId = types.identifier('token');
113
+ // The author's own button, cloned per visible page: their class name (and so
114
+ // every style they applied) rides along.
115
+ var numberButton = types.cloneNode(template, true);
116
+ convertControlToButton(numberButton);
117
+ setJSXExpressionAttribute(numberButton, 'onClick', buildJumpHandler(vars, types.cloneNode(tokenId, true)));
118
+ // The current page is marked, not disabled: `[aria-current='page']` is
119
+ // styleable and keeps the button reachable for screen readers.
120
+ setJSXExpressionAttribute(numberButton, 'aria-current', types.conditionalExpression(types.binaryExpression('===', vars.currentPageExpr(), types.cloneNode(tokenId, true)), types.stringLiteral('page'), types.identifier('undefined')));
121
+ setJSXExpressionAttribute(numberButton, 'key', types.templateLiteral([
122
+ types.templateElement({ raw: 'page-', cooked: 'page-' }),
123
+ types.templateElement({ raw: '', cooked: '' }, true),
124
+ ], [types.cloneNode(tokenId, true)]));
125
+ // Whatever label the template carried ('1') is replaced by the real number.
126
+ numberButton.children = [types.jsxExpressionContainer(types.cloneNode(tokenId, true))];
127
+ var gapNode = ellipsisTemplate
128
+ ? types.cloneNode(ellipsisTemplate, true)
129
+ : types.jsxElement(types.jsxOpeningElement(types.jsxIdentifier('span'), [], false), types.jsxClosingElement(types.jsxIdentifier('span')), [types.jsxText('…')], false);
130
+ setJSXExpressionAttribute(gapNode, 'key', types.cloneNode(tokenId, true));
131
+ // {ds_N_pageTokens.map(token => typeof token === 'number' ? <button…> : <span…>)}
132
+ pagesContainer.children = [
133
+ types.jsxExpressionContainer(types.callExpression(types.memberExpression(types.identifier(getPageTokensVar(vars.index)), types.identifier('map')), [
134
+ types.arrowFunctionExpression([types.cloneNode(tokenId, true)], types.conditionalExpression(types.binaryExpression('===', types.unaryExpression('typeof', types.cloneNode(tokenId, true)), types.stringLiteral('number')), numberButton, gapNode)),
135
+ ])),
136
+ ];
137
+ };
138
+ //# sourceMappingURL=numbered-pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbered-pagination.js","sourceRoot":"","sources":["../../src/numbered-pagination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,c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AkF;IAClF,cAAc,CAAC,QAAQ,GAAG;QACxB,KAAK,CAAC,sBAAsB,CAC1B,KAAK,CAAC,cAAc,CAClB,KAAK,CAAC,gBAAgB,CACpB,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAC9C,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CACxB,EACD;YACE,KAAK,CAAC,uBAAuB,CAC3B,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,EAChC,KAAK,CAAC,qBAAqB,CACzB,KAAK,CAAC,gBAAgB,CACpB,KAAK,EACL,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,EAC/D,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAC9B,EACD,YAAY,EACZ,OAAO,CACR,CACF;SACF,CACF,CACF;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -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,87 @@
1
+ import * as types from '@babel/types';
2
+ /** True when there is nothing that could ever change the filtering of this list. */
3
+ export var hasNoPageResetDeps = function (deps) {
4
+ return deps.stateIds.length === 0 && deps.propIds.length === 0 && deps.urlSearchParamKeys.length === 0;
5
+ };
6
+ var routerQueryAccess = function (key) {
7
+ return types.memberExpression(types.memberExpression(types.identifier('router'), types.identifier('query')), types.identifier(key));
8
+ };
9
+ /**
10
+ * The expressions the effect both depends on and hashes into its signature.
11
+ *
12
+ * Kept in one place so the two can never drift: a value in the signature but
13
+ * not the deps would be read stale, and one in the deps but not the signature
14
+ * would re-run the effect without being able to explain why it changed.
15
+ */
16
+ var buildTrackedExpressions = function (deps) {
17
+ var tracked = [];
18
+ var seen = new Set();
19
+ for (var _i = 0, _a = deps.stateIds; _i < _a.length; _i++) {
20
+ var id = _a[_i];
21
+ if (seen.has(id)) {
22
+ continue;
23
+ }
24
+ seen.add(id);
25
+ tracked.push(types.identifier(id));
26
+ }
27
+ for (var _b = 0, _c = deps.propIds; _b < _c.length; _b++) {
28
+ var id = _c[_b];
29
+ var key = "props.".concat(id);
30
+ if (seen.has(key)) {
31
+ continue;
32
+ }
33
+ seen.add(key);
34
+ tracked.push(types.memberExpression(types.identifier('props'), types.identifier(id)));
35
+ }
36
+ for (var _d = 0, _e = deps.urlSearchParamKeys; _d < _e.length; _d++) {
37
+ var key = _e[_d];
38
+ tracked.push(routerQueryAccess(key));
39
+ }
40
+ return tracked;
41
+ };
42
+ /**
43
+ * Builds the reset effect.
44
+ *
45
+ * @param refVar name of the `useRef` holding the last seen signature
46
+ * @param buildResetStatement how this usage writes page 1 — the combined
47
+ * `{ page, debouncedQuery }` state and the standalone
48
+ * page state need different setters
49
+ */
50
+ export var buildFilterSortPageResetEffect = function (refVar, deps, buildResetStatement) {
51
+ var body = [];
52
+ var hasRouterDeps = deps.urlSearchParamKeys.length > 0;
53
+ // Reading `router.query` before the router is ready would hash `undefined`
54
+ // for every URL-driven filter and record a signature that is about to change
55
+ // on its own.
56
+ if (hasRouterDeps) {
57
+ body.push(types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('router'), types.identifier('isReady')), true), types.returnStatement()));
58
+ }
59
+ var refCurrent = types.memberExpression(types.identifier(refVar), types.identifier('current'));
60
+ // `?? null` so a missing URL param serialises as `null` rather than dropping
61
+ // out of the array and shifting every later entry.
62
+ var signatureEntries = buildTrackedExpressions(deps).map(function (expr) {
63
+ return expr.type === 'MemberExpression' && expr.object.type === 'MemberExpression'
64
+ ? types.logicalExpression('??', expr, types.nullLiteral())
65
+ : expr;
66
+ });
67
+ body.push(types.variableDeclaration('const', [
68
+ types.variableDeclarator(types.identifier('__sig'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.arrayExpression(signatureEntries)])),
69
+ ]), types.ifStatement(types.binaryExpression('===', types.cloneNode(refCurrent, true), types.identifier('__sig')), types.returnStatement()), types.variableDeclaration('const', [
70
+ types.variableDeclarator(types.identifier('__first'), types.binaryExpression('===', types.cloneNode(refCurrent, true), types.nullLiteral())),
71
+ ]), types.expressionStatement(types.assignmentExpression('=', types.cloneNode(refCurrent, true), types.identifier('__sig'))), types.ifStatement(types.identifier('__first'), types.returnStatement()), buildResetStatement());
72
+ var effectDeps = buildTrackedExpressions(deps);
73
+ if (hasRouterDeps) {
74
+ effectDeps.push(types.memberExpression(types.identifier('router'), types.identifier('isReady')));
75
+ }
76
+ return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
77
+ types.arrowFunctionExpression([], types.blockStatement(body)),
78
+ types.arrayExpression(effectDeps),
79
+ ]));
80
+ };
81
+ /** `const <refVar> = useRef(null)` — the signature store for the effect above. */
82
+ export var buildPageResetRefDeclaration = function (refVar) {
83
+ return types.variableDeclaration('const', [
84
+ types.variableDeclarator(types.identifier(refVar), types.callExpression(types.identifier('useRef'), [types.nullLiteral()])),
85
+ ]);
86
+ };
87
+ //# sourceMappingURL=page-reset.js.map
@@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,IAAI,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAC9F,EACD,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,eAAe,EAAE,CAAC,EACvE,mBAAmB,EAAE,CACtB,CAAA;IAED,IAAM,UAAU,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IAChD,IAAI,aAAa,EAAE;QACjB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;KACjG;IAED,OAAO,KAAK,CAAC,mBAAmB,CAC9B,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAClD,KAAK,CAAC,uBAAuB,CAAC,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC7D,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC;KAClC,CAAC,CACH,CAAA;AACH,CAAC,CAAA;AAED,kFAAkF;AAClF,MAAM,CAAC,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"}
@@ -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":["../../src/page-url-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,yEAAyE;AACzE,wEAAwE;AACxE,eAAe;AACf,IAAM,mBAAmB,GAAG,4BAA4B,CAAA;AAExD,IAAM,WAAW,GAAG,UAAC,MAAwB,EAAE,QAAgB;IAC7D,OAAA,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAChC,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5D,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;AAFvE,CAEuE,CAAA;AAEzE,IAAM,iBAAiB,GAAG,UAAC,QAAgB;IACzC,OAAA,WAAW,CACT,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7E,QAAQ,CACT;AAHD,CAGC,CAAA;A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vF,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC;SAC5B,CAAC,CACH;QACD,eAAe,EAAE;QACjB,KAAK,CAAC,WAAW,CACf,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,EAC7F,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAC5B;QACD,yEAAyE;QACzE,4EAA4E;QAC5E,4EAA4E;QAC5E,6EAA6E;QAC7E,6CAA6C;QAC7C,cAAc,CAAC,mBAAmB,CAChC,OAAO,CAAC,QAAQ,EAChB,KAAK,CAAC,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"}