@teleporthq/teleport-plugin-next-data-source 0.43.57 → 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.
Files changed (147) hide show
  1. package/__tests__/_helpers/pagination-widget-fixture.ts +230 -0
  2. package/__tests__/ecommerce-product-allow-backorders.test.ts +156 -0
  3. package/__tests__/ecommerce-product-discounts.test.ts +196 -0
  4. package/__tests__/ecommerce-product-model.test.ts +179 -0
  5. package/__tests__/infinite-scroll.test.ts +143 -0
  6. package/__tests__/numbered-pagination.test.ts +113 -0
  7. package/__tests__/page-reset-on-filter-sort.test.ts +182 -0
  8. package/__tests__/page-url-sync.test.ts +208 -0
  9. package/__tests__/product-price-sort.ts +313 -0
  10. package/__tests__/search-url-sync.test.ts +7 -3
  11. package/dist/cjs/array-mapper-pagination.d.ts +9 -0
  12. package/dist/cjs/array-mapper-pagination.d.ts.map +1 -1
  13. package/dist/cjs/array-mapper-pagination.js.map +1 -1
  14. package/dist/cjs/count-effect.d.ts +42 -0
  15. package/dist/cjs/count-effect.d.ts.map +1 -0
  16. package/dist/cjs/count-effect.js +81 -0
  17. package/dist/cjs/count-effect.js.map +1 -0
  18. package/dist/cjs/fetchers/postgresql.d.ts.map +1 -1
  19. package/dist/cjs/fetchers/postgresql.js +2 -1
  20. package/dist/cjs/fetchers/postgresql.js.map +1 -1
  21. package/dist/cjs/fetchers/teleport.d.ts.map +1 -1
  22. package/dist/cjs/fetchers/teleport.js +3 -2
  23. package/dist/cjs/fetchers/teleport.js.map +1 -1
  24. package/dist/cjs/infinite-scroll.d.ts +65 -0
  25. package/dist/cjs/infinite-scroll.d.ts.map +1 -0
  26. package/dist/cjs/infinite-scroll.js +190 -0
  27. package/dist/cjs/infinite-scroll.js.map +1 -0
  28. package/dist/cjs/numbered-pagination.d.ts +42 -0
  29. package/dist/cjs/numbered-pagination.d.ts.map +1 -0
  30. package/dist/cjs/numbered-pagination.js +167 -0
  31. package/dist/cjs/numbered-pagination.js.map +1 -0
  32. package/dist/cjs/page-reset.d.ts +42 -0
  33. package/dist/cjs/page-reset.d.ts.map +1 -0
  34. package/dist/cjs/page-reset.js +116 -0
  35. package/dist/cjs/page-reset.js.map +1 -0
  36. package/dist/cjs/page-url-sync.d.ts +42 -0
  37. package/dist/cjs/page-url-sync.d.ts.map +1 -0
  38. package/dist/cjs/page-url-sync.js +180 -0
  39. package/dist/cjs/page-url-sync.js.map +1 -0
  40. package/dist/cjs/pagination-controls.d.ts +55 -0
  41. package/dist/cjs/pagination-controls.d.ts.map +1 -0
  42. package/dist/cjs/pagination-controls.js +159 -0
  43. package/dist/cjs/pagination-controls.js.map +1 -0
  44. package/dist/cjs/pagination-plugin.d.ts.map +1 -1
  45. package/dist/cjs/pagination-plugin.js +506 -160
  46. package/dist/cjs/pagination-plugin.js.map +1 -1
  47. package/dist/cjs/product-price-sort.d.ts +116 -0
  48. package/dist/cjs/product-price-sort.d.ts.map +1 -0
  49. package/dist/cjs/product-price-sort.js +169 -0
  50. package/dist/cjs/product-price-sort.js.map +1 -0
  51. package/dist/cjs/transformations/ecommerce-product.d.ts +12 -0
  52. package/dist/cjs/transformations/ecommerce-product.d.ts.map +1 -1
  53. package/dist/cjs/transformations/ecommerce-product.js +2 -1
  54. package/dist/cjs/transformations/ecommerce-product.js.map +1 -1
  55. package/dist/cjs/transformations/index.d.ts +2 -1
  56. package/dist/cjs/transformations/index.d.ts.map +1 -1
  57. package/dist/cjs/transformations/index.js +17 -1
  58. package/dist/cjs/transformations/index.js.map +1 -1
  59. package/dist/cjs/transformations/shared-utils.d.ts.map +1 -1
  60. package/dist/cjs/transformations/shared-utils.js +1 -1
  61. package/dist/cjs/transformations/shared-utils.js.map +1 -1
  62. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  63. package/dist/esm/array-mapper-pagination.d.ts +9 -0
  64. package/dist/esm/array-mapper-pagination.d.ts.map +1 -1
  65. package/dist/esm/array-mapper-pagination.js.map +1 -1
  66. package/dist/esm/count-effect.d.ts +42 -0
  67. package/dist/esm/count-effect.d.ts.map +1 -0
  68. package/dist/esm/count-effect.js +53 -0
  69. package/dist/esm/count-effect.js.map +1 -0
  70. package/dist/esm/fetchers/postgresql.d.ts.map +1 -1
  71. package/dist/esm/fetchers/postgresql.js +2 -1
  72. package/dist/esm/fetchers/postgresql.js.map +1 -1
  73. package/dist/esm/fetchers/teleport.d.ts.map +1 -1
  74. package/dist/esm/fetchers/teleport.js +3 -2
  75. package/dist/esm/fetchers/teleport.js.map +1 -1
  76. package/dist/esm/infinite-scroll.d.ts +65 -0
  77. package/dist/esm/infinite-scroll.d.ts.map +1 -0
  78. package/dist/esm/infinite-scroll.js +159 -0
  79. package/dist/esm/infinite-scroll.js.map +1 -0
  80. package/dist/esm/numbered-pagination.d.ts +42 -0
  81. package/dist/esm/numbered-pagination.d.ts.map +1 -0
  82. package/dist/esm/numbered-pagination.js +138 -0
  83. package/dist/esm/numbered-pagination.js.map +1 -0
  84. package/dist/esm/page-reset.d.ts +42 -0
  85. package/dist/esm/page-reset.d.ts.map +1 -0
  86. package/dist/esm/page-reset.js +87 -0
  87. package/dist/esm/page-reset.js.map +1 -0
  88. package/dist/esm/page-url-sync.d.ts +42 -0
  89. package/dist/esm/page-url-sync.d.ts.map +1 -0
  90. package/dist/esm/page-url-sync.js +152 -0
  91. package/dist/esm/page-url-sync.js.map +1 -0
  92. package/dist/esm/pagination-controls.d.ts +55 -0
  93. package/dist/esm/pagination-controls.d.ts.map +1 -0
  94. package/dist/esm/pagination-controls.js +126 -0
  95. package/dist/esm/pagination-controls.js.map +1 -0
  96. package/dist/esm/pagination-plugin.d.ts.map +1 -1
  97. package/dist/esm/pagination-plugin.js +507 -161
  98. package/dist/esm/pagination-plugin.js.map +1 -1
  99. package/dist/esm/product-price-sort.d.ts +116 -0
  100. package/dist/esm/product-price-sort.d.ts.map +1 -0
  101. package/dist/esm/product-price-sort.js +160 -0
  102. package/dist/esm/product-price-sort.js.map +1 -0
  103. package/dist/esm/transformations/ecommerce-product.d.ts +12 -0
  104. package/dist/esm/transformations/ecommerce-product.d.ts.map +1 -1
  105. package/dist/esm/transformations/ecommerce-product.js +3 -2
  106. package/dist/esm/transformations/ecommerce-product.js.map +1 -1
  107. package/dist/esm/transformations/index.d.ts +2 -1
  108. package/dist/esm/transformations/index.d.ts.map +1 -1
  109. package/dist/esm/transformations/index.js +17 -1
  110. package/dist/esm/transformations/index.js.map +1 -1
  111. package/dist/esm/transformations/shared-utils.d.ts.map +1 -1
  112. package/dist/esm/transformations/shared-utils.js +1 -1
  113. package/dist/esm/transformations/shared-utils.js.map +1 -1
  114. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  115. package/package.json +5 -5
  116. package/src/array-mapper-pagination.ts +10 -0
  117. package/src/count-effect.ts +137 -0
  118. package/src/fetchers/postgresql.ts +52 -13
  119. package/src/fetchers/teleport.ts +53 -13
  120. package/src/infinite-scroll.ts +401 -0
  121. package/src/numbered-pagination.ts +292 -0
  122. package/src/page-reset.ts +162 -0
  123. package/src/page-url-sync.ts +241 -0
  124. package/src/pagination-controls.ts +176 -0
  125. package/src/pagination-plugin.ts +755 -346
  126. package/src/product-price-sort.ts +204 -0
  127. package/src/transformations/ecommerce-product.ts +141 -10
  128. package/src/transformations/index.ts +19 -1
  129. package/src/transformations/shared-utils.ts +14 -0
  130. package/dist/cjs/array-mapper-registry.d.ts +0 -85
  131. package/dist/cjs/array-mapper-registry.d.ts.map +0 -1
  132. package/dist/cjs/array-mapper-registry.js +0 -296
  133. package/dist/cjs/array-mapper-registry.js.map +0 -1
  134. package/dist/cjs/pagination-with-count.d.ts +0 -6
  135. package/dist/cjs/pagination-with-count.d.ts.map +0 -1
  136. package/dist/cjs/pagination-with-count.js +0 -63
  137. package/dist/cjs/pagination-with-count.js.map +0 -1
  138. package/dist/esm/array-mapper-registry.d.ts +0 -85
  139. package/dist/esm/array-mapper-registry.d.ts.map +0 -1
  140. package/dist/esm/array-mapper-registry.js +0 -292
  141. package/dist/esm/array-mapper-registry.js.map +0 -1
  142. package/dist/esm/pagination-with-count.d.ts +0 -6
  143. package/dist/esm/pagination-with-count.d.ts.map +0 -1
  144. package/dist/esm/pagination-with-count.js +0 -34
  145. package/dist/esm/pagination-with-count.js.map +0 -1
  146. package/src/array-mapper-registry.ts +0 -416
  147. package/src/pagination-with-count.ts +0 -89
@@ -0,0 +1,65 @@
1
+ import * as types from '@babel/types';
2
+ /**
3
+ * Infinite scroll: the list APPENDS pages instead of replacing them.
4
+ *
5
+ * The accumulation lives inside the generated `fetchData` closure rather than
6
+ * around the provider. `DataProvider` renders whatever `fetchData` resolves
7
+ * with, so returning "every page fetched so far, in order" is enough to make it
8
+ * append — no change to the runtime component library, and the existing
9
+ * `persistDataDuringLoading` keeps the rows already on screen while the next
10
+ * page is in flight.
11
+ *
12
+ * A `useRef` holds the pages rather than a state, because writing accumulated
13
+ * rows into state from inside `fetchData` would re-render the provider mid-fetch
14
+ * and re-enter it. The ref is keyed by a SIGNATURE of every fetch param except
15
+ * the page, so a filter, sort or search change starts a fresh list instead of
16
+ * interleaving rows from two different queries.
17
+ */
18
+ export interface InfiniteScrollVars {
19
+ accumRefVar: string;
20
+ hasMoreFlagVar: string;
21
+ setHasMoreFlagVar: string;
22
+ hasMoreVar: string;
23
+ sentinelRefVar: string;
24
+ }
25
+ export declare const getInfiniteScrollVars: (index: number) => InfiniteScrollVars;
26
+ /**
27
+ * The three declarations behind an appending list:
28
+ *
29
+ * const ds_0_accumRef = useRef({ sig: '', pages: {} })
30
+ * const [ds_0_hasMoreFlag, setDs_0_hasMoreFlag] = useState(true)
31
+ * const ds_0_hasMore = ds_0_hasMoreFlag && (ds_0_maxPages === 0 || <page> < ds_0_maxPages)
32
+ *
33
+ * Two independent signals for "is there more", because either can be missing.
34
+ * `hasMoreFlag` comes from the last response being a SHORT page, which is the
35
+ * only end-of-data signal available from a data source that cannot count.
36
+ * `maxPages` comes from the count endpoint and is the one that stops a request
37
+ * being made at all; it is `0` while unknown, hence the explicit escape.
38
+ */
39
+ export declare const buildInfiniteScrollDeclarations: (vars: InfiniteScrollVars, maxPagesVar: string, currentPageExpr: types.Expression, includeSentinel: boolean) => types.Statement[];
40
+ /**
41
+ * The `.then(...)` tail that accumulates a page and reports whether more exist.
42
+ *
43
+ * Returned as the resolved value of `fetchData`, so `DataProvider` stores the
44
+ * whole accumulated list as its data.
45
+ */
46
+ export declare const buildAccumulatingResponseHandler: (vars: InfiniteScrollVars, perPage: number) => types.ArrowFunctionExpression;
47
+ /**
48
+ * The IntersectionObserver that loads the next page when the sentinel scrolls
49
+ * into view. Emitted only in auto mode (no Load More button).
50
+ *
51
+ * `rootMargin` starts the fetch a screenful early so the list rarely shows a
52
+ * gap. The observer is rebuilt whenever `hasMore` or `maxPages` change and
53
+ * disconnected on cleanup; when there is nothing more to load the effect exits
54
+ * before observing, so a finished list costs nothing.
55
+ */
56
+ export declare const buildSentinelObserverEffect: (vars: InfiniteScrollVars, maxPagesVar: string, buildAdvancePageStatement: () => types.Statement) => types.ExpressionStatement;
57
+ /**
58
+ * `<div ref={ds_N_sentinelRef} aria-hidden="true" style={{ height: '1px' }} />`
59
+ *
60
+ * An invisible one-pixel row after the list. It is generated rather than
61
+ * authored because it is not a control — there is nothing to style or click,
62
+ * only a position in the document for the observer to watch.
63
+ */
64
+ export declare const buildSentinelElement: (vars: InfiniteScrollVars) => types.JSXElement;
65
+ //# sourceMappingURL=infinite-scroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infinite-scroll.d.ts","sourceRoot":"","sources":["../../src/infinite-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,MAAM,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,eAAO,MAAM,qBAAqB,UAAW,MAAM,KAAG,kBAMpD,CAAA;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,+BAA+B,SACpC,kBAAkB,eACX,MAAM,mBACF,MAAM,UAAU,mBAChB,OAAO,KACvB,MAAM,SAAS,EAsDjB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,SACrC,kBAAkB,WACf,MAAM,KACd,MAAM,uBAoIR,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,SAChC,kBAAkB,eACX,MAAM,6BACQ,MAAM,MAAM,SAAS,KAC/C,MAAM,mBAoGN,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,SAAU,kBAAkB,KAAG,MAAM,UAwBnE,CAAA"}
@@ -0,0 +1,159 @@
1
+ import * as types from '@babel/types';
2
+ export var getInfiniteScrollVars = function (index) { return ({
3
+ accumRefVar: "ds_".concat(index, "_accumRef"),
4
+ hasMoreFlagVar: "ds_".concat(index, "_hasMoreFlag"),
5
+ setHasMoreFlagVar: "setDs_".concat(index, "_hasMoreFlag"),
6
+ hasMoreVar: "ds_".concat(index, "_hasMore"),
7
+ sentinelRefVar: "ds_".concat(index, "_sentinelRef"),
8
+ }); };
9
+ /**
10
+ * The three declarations behind an appending list:
11
+ *
12
+ * const ds_0_accumRef = useRef({ sig: '', pages: {} })
13
+ * const [ds_0_hasMoreFlag, setDs_0_hasMoreFlag] = useState(true)
14
+ * const ds_0_hasMore = ds_0_hasMoreFlag && (ds_0_maxPages === 0 || <page> < ds_0_maxPages)
15
+ *
16
+ * Two independent signals for "is there more", because either can be missing.
17
+ * `hasMoreFlag` comes from the last response being a SHORT page, which is the
18
+ * only end-of-data signal available from a data source that cannot count.
19
+ * `maxPages` comes from the count endpoint and is the one that stops a request
20
+ * being made at all; it is `0` while unknown, hence the explicit escape.
21
+ */
22
+ export var buildInfiniteScrollDeclarations = function (vars, maxPagesVar, currentPageExpr, includeSentinel) {
23
+ var declarations = [
24
+ types.variableDeclaration('const', [
25
+ types.variableDeclarator(types.identifier(vars.accumRefVar), types.callExpression(types.identifier('useRef'), [
26
+ types.objectExpression([
27
+ types.objectProperty(types.identifier('sig'), types.stringLiteral('')),
28
+ types.objectProperty(types.identifier('pages'), types.objectExpression([])),
29
+ ]),
30
+ ])),
31
+ ]),
32
+ types.variableDeclaration('const', [
33
+ types.variableDeclarator(types.arrayPattern([
34
+ types.identifier(vars.hasMoreFlagVar),
35
+ types.identifier(vars.setHasMoreFlagVar),
36
+ ]), types.callExpression(types.identifier('useState'), [types.booleanLiteral(true)])),
37
+ ]),
38
+ types.variableDeclaration('const', [
39
+ types.variableDeclarator(types.identifier(vars.hasMoreVar), types.logicalExpression('&&', types.identifier(vars.hasMoreFlagVar), types.logicalExpression('||', types.binaryExpression('===', types.identifier(maxPagesVar), types.numericLiteral(0)), types.binaryExpression('<', types.cloneNode(currentPageExpr, true), types.identifier(maxPagesVar))))),
40
+ ]),
41
+ ];
42
+ if (includeSentinel) {
43
+ declarations.push(types.variableDeclaration('const', [
44
+ types.variableDeclarator(types.identifier(vars.sentinelRefVar), types.callExpression(types.identifier('useRef'), [types.nullLiteral()])),
45
+ ]));
46
+ }
47
+ return declarations;
48
+ };
49
+ /**
50
+ * The `.then(...)` tail that accumulates a page and reports whether more exist.
51
+ *
52
+ * Returned as the resolved value of `fetchData`, so `DataProvider` stores the
53
+ * whole accumulated list as its data.
54
+ */
55
+ export var buildAccumulatingResponseHandler = function (vars, perPage) {
56
+ var accumCurrent = function () {
57
+ return types.memberExpression(types.identifier(vars.accumRefVar), types.identifier('current'));
58
+ };
59
+ var accumPages = function () {
60
+ return types.memberExpression(accumCurrent(), types.identifier('pages'));
61
+ };
62
+ return types.arrowFunctionExpression([types.identifier('response')], types.blockStatement([
63
+ types.variableDeclaration('const', [
64
+ types.variableDeclarator(types.identifier('rows'), types.logicalExpression('||', types.optionalMemberExpression(types.identifier('response'), types.identifier('data'), false, true), types.arrayExpression([]))),
65
+ ]),
66
+ types.variableDeclaration('const', [
67
+ types.variableDeclarator(types.identifier('page'), types.logicalExpression('||', types.callExpression(types.identifier('Number'), [
68
+ types.memberExpression(types.identifier('params'), types.identifier('page')),
69
+ ]), types.numericLiteral(1))),
70
+ ]),
71
+ // Everything that identifies the QUERY, with the page zeroed out: two
72
+ // fetches that differ only by page belong to the same accumulated list.
73
+ types.variableDeclaration('const', [
74
+ types.variableDeclarator(types.identifier('sig'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [
75
+ types.objectExpression([
76
+ types.spreadElement(types.identifier('params')),
77
+ types.objectProperty(types.identifier('page'), types.numericLiteral(0)),
78
+ ]),
79
+ ])),
80
+ ]),
81
+ types.ifStatement(types.binaryExpression('!==', types.memberExpression(accumCurrent(), types.identifier('sig')), types.identifier('sig')), types.blockStatement([
82
+ types.expressionStatement(types.assignmentExpression('=', accumCurrent(), types.objectExpression([
83
+ types.objectProperty(types.identifier('sig'), types.identifier('sig'), false, true),
84
+ types.objectProperty(types.identifier('pages'), types.objectExpression([])),
85
+ ]))),
86
+ ])),
87
+ types.expressionStatement(types.assignmentExpression('=', types.memberExpression(accumPages(), types.identifier('page'), true), types.identifier('rows'))),
88
+ // A page that came back short is the last one. This is the only
89
+ // end-of-data signal a data source that cannot count ever gives.
90
+ types.expressionStatement(types.callExpression(types.identifier(vars.setHasMoreFlagVar), [
91
+ types.binaryExpression('>=', types.memberExpression(types.identifier('rows'), types.identifier('length')), types.numericLiteral(perPage)),
92
+ ])),
93
+ // Every page held so far, flattened in page order — a numeric sort, so
94
+ // page 10 does not land between 1 and 2. This is what DataProvider stores
95
+ // as its data, and so what the list renders.
96
+ types.returnStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.identifier('Object'), types.identifier('keys')), [accumPages()]), types.identifier('map')), [types.identifier('Number')]), types.identifier('sort')), [
97
+ types.arrowFunctionExpression([types.identifier('a'), types.identifier('b')], types.binaryExpression('-', types.identifier('a'), types.identifier('b'))),
98
+ ]), types.identifier('reduce')), [
99
+ types.arrowFunctionExpression([types.identifier('acc'), types.identifier('p')], types.callExpression(types.memberExpression(types.identifier('acc'), types.identifier('concat')), [types.memberExpression(accumPages(), types.identifier('p'), true)])),
100
+ types.arrayExpression([]),
101
+ ])),
102
+ ]));
103
+ };
104
+ /**
105
+ * The IntersectionObserver that loads the next page when the sentinel scrolls
106
+ * into view. Emitted only in auto mode (no Load More button).
107
+ *
108
+ * `rootMargin` starts the fetch a screenful early so the list rarely shows a
109
+ * gap. The observer is rebuilt whenever `hasMore` or `maxPages` change and
110
+ * disconnected on cleanup; when there is nothing more to load the effect exits
111
+ * before observing, so a finished list costs nothing.
112
+ */
113
+ export var buildSentinelObserverEffect = function (vars, maxPagesVar, buildAdvancePageStatement) {
114
+ return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
115
+ types.arrowFunctionExpression([], types.blockStatement([
116
+ types.variableDeclaration('const', [
117
+ types.variableDeclarator(types.identifier('el'), types.memberExpression(types.identifier(vars.sentinelRefVar), types.identifier('current'))),
118
+ ]),
119
+ // No element yet, no observer support (older browsers, jsdom), or
120
+ // nothing left to load.
121
+ types.ifStatement(types.logicalExpression('||', types.logicalExpression('||', types.unaryExpression('!', types.identifier('el'), true), types.binaryExpression('===', types.unaryExpression('typeof', types.identifier('IntersectionObserver')), types.stringLiteral('undefined'))), types.unaryExpression('!', types.identifier(vars.hasMoreVar), true)), types.returnStatement()),
122
+ types.variableDeclaration('const', [
123
+ types.variableDeclarator(types.identifier('observer'), types.newExpression(types.identifier('IntersectionObserver'), [
124
+ types.arrowFunctionExpression([types.identifier('entries')], types.blockStatement([
125
+ types.expressionStatement(types.callExpression(types.memberExpression(types.identifier('entries'), types.identifier('forEach')), [
126
+ types.arrowFunctionExpression([types.identifier('entry')], types.blockStatement([
127
+ types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('entry'), types.identifier('isIntersecting')), true), types.returnStatement()),
128
+ buildAdvancePageStatement(),
129
+ ])),
130
+ ])),
131
+ ])),
132
+ types.objectExpression([
133
+ types.objectProperty(types.identifier('rootMargin'), types.stringLiteral('200px')),
134
+ ]),
135
+ ])),
136
+ ]),
137
+ types.expressionStatement(types.callExpression(types.memberExpression(types.identifier('observer'), types.identifier('observe')), [types.identifier('el')])),
138
+ types.returnStatement(types.arrowFunctionExpression([], types.callExpression(types.memberExpression(types.identifier('observer'), types.identifier('disconnect')), []))),
139
+ ])),
140
+ types.arrayExpression([types.identifier(vars.hasMoreVar), types.identifier(maxPagesVar)]),
141
+ ]));
142
+ };
143
+ /**
144
+ * `<div ref={ds_N_sentinelRef} aria-hidden="true" style={{ height: '1px' }} />`
145
+ *
146
+ * An invisible one-pixel row after the list. It is generated rather than
147
+ * authored because it is not a control — there is nothing to style or click,
148
+ * only a position in the document for the observer to watch.
149
+ */
150
+ export var buildSentinelElement = function (vars) {
151
+ return types.jsxElement(types.jsxOpeningElement(types.jsxIdentifier('div'), [
152
+ types.jsxAttribute(types.jsxIdentifier('ref'), types.jsxExpressionContainer(types.identifier(vars.sentinelRefVar))),
153
+ types.jsxAttribute(types.jsxIdentifier('aria-hidden'), types.stringLiteral('true')),
154
+ types.jsxAttribute(types.jsxIdentifier('style'), types.jsxExpressionContainer(types.objectExpression([
155
+ types.objectProperty(types.identifier('height'), types.stringLiteral('1px')),
156
+ ]))),
157
+ ], true), null, [], true);
158
+ };
159
+ //# sourceMappingURL=infinite-scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infinite-scroll.js","sourceRoot":"","sources":["../../src/infinite-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AA6BrC,MAAM,CAAC,IAAM,qBAAqB,GAAG,UAAC,KAAa,IAAyB,OAAA,CAAC;IAC3E,WAAW,EAAE,aAAM,KAAK,cAAW;IACnC,cAAc,EAAE,aAAM,KAAK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C,OAAO,CAAC,EAC5B,KAAK,CAAC,sBAAsB,CAC1B,KAAK,CAAC,gBAAgB,CAAC;YACrB,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;SAC7E,CAAC,CACH,CACF;KACF,EACD,IAAI,CACL,EACD,IAAI,EACJ,EAAE,EACF,IAAI,CACL;AAvBD,CAuBC,CAAA"}
@@ -0,0 +1,42 @@
1
+ import * as types from '@babel/types';
2
+ /**
3
+ * Numbered pagination: First / Prev / 1 … 4 5 6 … 12 / Next / Last.
4
+ *
5
+ * The builder authors ONE page-number button and a container to repeat it into;
6
+ * this module turns that template into a `.map` over a windowed token list, so
7
+ * every number the visitor sees is the author's own styled node rather than
8
+ * something the generator invented.
9
+ */
10
+ /** `ds_N_pageTokens` — the windowed list of page numbers and ellipsis markers. */
11
+ export declare const getPageTokensVar: (index: number) => string;
12
+ /**
13
+ * Builds the `useMemo` that decides which page numbers are visible.
14
+ *
15
+ * The window is deliberately small and fixed (first, last, and one neighbour
16
+ * either side of the current page, so at most seven entries): an unbounded
17
+ * strip is unusable at 300 pages and wraps the layout the author styled. The
18
+ * two ellipsis markers are distinct strings because React needs unique keys and
19
+ * a list can legitimately need a gap on both sides.
20
+ *
21
+ * ⛔ Keep this in step with `computePageWindow` in the editor's renderer — the
22
+ * canvas and the published page must agree on which numbers are shown, or the
23
+ * author styles a strip they will never see.
24
+ */
25
+ export declare const buildPageTokensDeclaration: (index: number, maxPagesVar: string, currentPageExpr: types.Expression) => types.VariableDeclaration;
26
+ export interface NumberedPaginationVars {
27
+ index: number;
28
+ maxPagesVar: string;
29
+ /** How this usage reads its current page (`ds_N_state.page` or `ds_N_page`). */
30
+ currentPageExpr: () => types.Expression;
31
+ /** How it writes a page number back. */
32
+ buildSetPageStatement: (pageExpr: types.Expression) => types.Expression;
33
+ }
34
+ /**
35
+ * Wires the First / Last buttons and expands the page-number template.
36
+ *
37
+ * Prev / Next are left to `wirePaginationButtons`, which already emits them and
38
+ * whose output must stay byte-identical for every project that never switches
39
+ * mode.
40
+ */
41
+ export declare const wireNumberedPagination: (paginationNode: any, vars: NumberedPaginationVars) => void;
42
+ //# sourceMappingURL=numbered-pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbered-pagination.d.ts","sourceRoot":"","sources":["../../src/numbered-pagination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAOrC;;;;;;;GAOG;AAIH,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MAAkC,CAAA;AAEnF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,UAC9B,MAAM,eACA,MAAM,mBACF,MAAM,UAAU,KAChC,MAAM,mBA2GR,CAAA;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,gFAAgF;IAChF,eAAe,EAAE,MAAM,KAAK,CAAC,UAAU,CAAA;IACvC,wCAAwC;IACxC,qBAAqB,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU,CAAA;CACxE;AAQD;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,mBAAoB,GAAG,QAAQ,sBAAsB,KAAG,IA0H1F,CAAA"}
@@ -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,cAAc,CAAA;AACrC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;GAOG;AAEH,wBAAwB;AAExB,kFAAkF;AAClF,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAC,KAAa,IAAa,OAAA,aAAM,KAAK,gBAAa,EAAxB,CAAwB,CAAA;AAEnF;;;;;;;;;;;;GAYG;AACH,M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AAC,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-reset.js","sourceRoot":"","sources":["../../src/page-reset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AA+BrC,oFAAoF;AACpF,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,IAAmB;IACpD,OAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAA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