@contember/bindx-repeater 0.1.10 → 0.1.11
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeater.d.ts","sourceRoot":"","sources":["../../src/components/BlockRepeater.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAW,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAGX,QAAQ,EAIR,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAyC,eAAe,
|
|
1
|
+
{"version":3,"file":"BlockRepeater.d.ts","sourceRoot":"","sources":["../../src/components/BlockRepeater.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAW,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAGX,QAAQ,EAIR,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAyC,eAAe,EAAa,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAClI,OAAO,KAAK,EACX,kBAAkB,EAMlB,MAAM,aAAa,CAAA;AAMpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,aAAa,CAC5B,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,SAAS,GAAG,OAAO,EACnB,MAAM,SAAS,QAAQ,GAAG,QAAQ,EAClC,WAAW,SAAS,MAAM,GAAG,MAAM,EACnC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/D,WAAW,SAAS,MAAM,GAAG,MAAM,EAClC,EACD,KAAK,EACL,mBAAmB,EACnB,UAAU,EACV,MAAM,EACN,QAAQ,GACR,EAAE,kBAAkB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,YAAY,CA+HlG;AAGD,QAAA,MAAM,0BAA0B,EAAoB,OAAO,aAAa,GAAG,iBAAiB,GAAG;IAAE,CAAC,eAAe,CAAC,EAAE,IAAI,CAAA;CAAE,CAAA;AAsF1H,OAAO,EAAE,0BAA0B,IAAI,qBAAqB,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repeater.d.ts","sourceRoot":"","sources":["../../src/components/Repeater.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAW,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAGX,QAAQ,EAGR,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAyC,eAAe,
|
|
1
|
+
{"version":3,"file":"Repeater.d.ts","sourceRoot":"","sources":["../../src/components/Repeater.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAW,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAGX,QAAQ,EAGR,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAyC,eAAe,EAAa,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAClI,OAAO,KAAK,EACX,aAAa,EAMb,MAAM,aAAa,CAAA;AAMpB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,QAAQ,CACvB,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,SAAS,GAAG,OAAO,EACnB,MAAM,SAAS,QAAQ,GAAG,QAAQ,EAClC,WAAW,SAAS,MAAM,GAAG,MAAM,EACnC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9D,EACD,KAAK,EACL,UAAU,EACV,QAAQ,GACR,EAAE,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,GAAG,YAAY,CAuHhF;AAGD,QAAA,MAAM,qBAAqB,EAAe,OAAO,QAAQ,GAAG,iBAAiB,GAAG;IAAE,CAAC,eAAe,CAAC,EAAE,IAAI,CAAA;CAAE,CAAA;AA+E3G,OAAO,EAAE,qBAAqB,IAAI,gBAAgB,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/bindx-repeater",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Repeater components for has-many list management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"react": ">=18.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@contember/bindx": "0.1.
|
|
19
|
-
"@contember/bindx-react": "0.1.
|
|
18
|
+
"@contember/bindx": "0.1.11",
|
|
19
|
+
"@contember/bindx-react": "0.1.11"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
FieldRef,
|
|
9
9
|
} from '@contember/bindx'
|
|
10
10
|
import { SelectionScope, FIELD_REF_META } from '@contember/bindx'
|
|
11
|
-
import { createCollectorProxy, mergeSelections, BINDX_COMPONENT, type SelectionProvider } from '@contember/bindx-react'
|
|
11
|
+
import { createCollectorProxy, mergeSelections, BINDX_COMPONENT, SCOPE_REF, type SelectionProvider } from '@contember/bindx-react'
|
|
12
12
|
import type {
|
|
13
13
|
BlockRepeaterProps,
|
|
14
14
|
BlockRepeaterItems,
|
|
@@ -206,8 +206,13 @@ const blockRepeaterWithSelection = BlockRepeater as typeof BlockRepeater & Selec
|
|
|
206
206
|
blockRepeaterWithSelection.getSelection = (
|
|
207
207
|
props: BlockRepeaterProps<unknown>,
|
|
208
208
|
collectNested: (children: ReactNode) => SelectionMeta,
|
|
209
|
-
): SelectionFieldMeta => {
|
|
210
|
-
|
|
209
|
+
): SelectionFieldMeta | null => {
|
|
210
|
+
// Check if the field is a collector proxy with a scope reference (collection phase).
|
|
211
|
+
// When present, we merge the collected selection directly into the scope tree,
|
|
212
|
+
// which correctly handles deeply nested relations (e.g., page.blocks.items).
|
|
213
|
+
const fieldScope = props.field && typeof props.field === 'object' && SCOPE_REF in props.field
|
|
214
|
+
? (props.field as Record<symbol, unknown>)[SCOPE_REF] as SelectionScope
|
|
215
|
+
: null
|
|
211
216
|
|
|
212
217
|
const scope = new SelectionScope()
|
|
213
218
|
const collectorEntity = createCollectorProxy<unknown>(scope)
|
|
@@ -245,12 +250,31 @@ blockRepeaterWithSelection.getSelection = (
|
|
|
245
250
|
nestedSelection.fields.set(props.discriminationField, {
|
|
246
251
|
fieldName: props.discriminationField,
|
|
247
252
|
alias: props.discriminationField,
|
|
248
|
-
path: [
|
|
253
|
+
path: [props.discriminationField],
|
|
249
254
|
isArray: false,
|
|
250
255
|
isRelation: false,
|
|
251
|
-
nested: { fields: new Map() },
|
|
252
256
|
})
|
|
253
257
|
|
|
258
|
+
// Add sortableBy field to selection if specified
|
|
259
|
+
if (props.sortableBy) {
|
|
260
|
+
nestedSelection.fields.set(props.sortableBy, {
|
|
261
|
+
fieldName: props.sortableBy,
|
|
262
|
+
alias: props.sortableBy,
|
|
263
|
+
path: [props.sortableBy],
|
|
264
|
+
isArray: false,
|
|
265
|
+
isRelation: false,
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// If we have a scope reference, merge directly into the scope tree and return null
|
|
270
|
+
// (no flat SelectionFieldMeta needed — the scope tree captures the full nesting)
|
|
271
|
+
if (fieldScope) {
|
|
272
|
+
fieldScope.mergeFromSelectionMeta(nestedSelection)
|
|
273
|
+
return null
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Fallback: return SelectionFieldMeta for non-collector refs (e.g., explicit selection)
|
|
277
|
+
const meta = props.field[FIELD_REF_META]
|
|
254
278
|
return {
|
|
255
279
|
fieldName: meta.fieldName,
|
|
256
280
|
alias: meta.fieldName,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
SelectionMeta,
|
|
8
8
|
} from '@contember/bindx'
|
|
9
9
|
import { SelectionScope, FIELD_REF_META } from '@contember/bindx'
|
|
10
|
-
import { createCollectorProxy, mergeSelections, BINDX_COMPONENT, type SelectionProvider } from '@contember/bindx-react'
|
|
10
|
+
import { createCollectorProxy, mergeSelections, BINDX_COMPONENT, SCOPE_REF, type SelectionProvider } from '@contember/bindx-react'
|
|
11
11
|
import type {
|
|
12
12
|
RepeaterProps,
|
|
13
13
|
RepeaterItems,
|
|
@@ -186,8 +186,11 @@ const repeaterWithSelection = Repeater as typeof Repeater & SelectionProvider &
|
|
|
186
186
|
repeaterWithSelection.getSelection = (
|
|
187
187
|
props: RepeaterProps<unknown>,
|
|
188
188
|
collectNested: (children: ReactNode) => SelectionMeta,
|
|
189
|
-
): SelectionFieldMeta => {
|
|
190
|
-
|
|
189
|
+
): SelectionFieldMeta | null => {
|
|
190
|
+
// Check if the field is a collector proxy with a scope reference (collection phase).
|
|
191
|
+
const fieldScope = props.field && typeof props.field === 'object' && SCOPE_REF in props.field
|
|
192
|
+
? (props.field as Record<symbol, unknown>)[SCOPE_REF] as SelectionScope
|
|
193
|
+
: null
|
|
191
194
|
|
|
192
195
|
// Create scope and collector proxy
|
|
193
196
|
const scope = new SelectionScope()
|
|
@@ -226,6 +229,25 @@ repeaterWithSelection.getSelection = (
|
|
|
226
229
|
const nestedSelection = scope.toSelectionMeta()
|
|
227
230
|
mergeSelections(nestedSelection, jsxSelection)
|
|
228
231
|
|
|
232
|
+
// Add sortableBy field to selection if specified
|
|
233
|
+
if (props.sortableBy) {
|
|
234
|
+
nestedSelection.fields.set(props.sortableBy, {
|
|
235
|
+
fieldName: props.sortableBy,
|
|
236
|
+
alias: props.sortableBy,
|
|
237
|
+
path: [props.sortableBy],
|
|
238
|
+
isArray: false,
|
|
239
|
+
isRelation: false,
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// If we have a scope reference, merge directly into the scope tree and return null
|
|
244
|
+
if (fieldScope) {
|
|
245
|
+
fieldScope.mergeFromSelectionMeta(nestedSelection)
|
|
246
|
+
return null
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Fallback: return SelectionFieldMeta for non-collector refs
|
|
250
|
+
const meta = props.field[FIELD_REF_META]
|
|
229
251
|
return {
|
|
230
252
|
fieldName: meta.fieldName,
|
|
231
253
|
alias: meta.fieldName,
|