@contember/react-block-repeater 2.0.0-alpha.4 → 2.0.0-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-extractor.json +3 -0
- package/dist/development/index.cjs +5 -5
- package/dist/development/index.js +5 -5
- package/dist/{production → development/src}/components/Block.cjs +7 -3
- package/dist/development/src/components/Block.cjs.map +1 -0
- package/dist/{production → development/src}/components/Block.js +7 -3
- package/dist/development/src/components/Block.js.map +1 -0
- package/dist/development/src/components/BlockRepeater.cjs +38 -0
- package/dist/development/src/components/BlockRepeater.cjs.map +1 -0
- package/dist/development/src/components/BlockRepeater.js +38 -0
- package/dist/development/src/components/BlockRepeater.js.map +1 -0
- package/dist/development/src/components/BlockRepeaterAddItemTrigger.cjs +25 -0
- package/dist/development/src/components/BlockRepeaterAddItemTrigger.cjs.map +1 -0
- package/dist/development/src/components/BlockRepeaterAddItemTrigger.js +25 -0
- package/dist/development/src/components/BlockRepeaterAddItemTrigger.js.map +1 -0
- package/dist/development/src/contexts.cjs.map +1 -0
- package/dist/development/src/contexts.js.map +1 -0
- package/dist/development/src/hooks/useBlockRepeaterCurrentBlock.cjs.map +1 -0
- package/dist/development/src/hooks/useBlockRepeaterCurrentBlock.js.map +1 -0
- package/dist/development/src/internal/helpers/staticAnalyzer.cjs.map +1 -0
- package/dist/development/src/internal/helpers/staticAnalyzer.js.map +1 -0
- package/dist/production/index.cjs +5 -5
- package/dist/production/index.js +5 -5
- package/dist/production/src/components/Block.cjs.map +1 -0
- package/dist/production/src/components/Block.js.map +1 -0
- package/dist/{development → production/src}/components/BlockRepeater.cjs +2 -2
- package/dist/production/src/components/BlockRepeater.cjs.map +1 -0
- package/dist/production/src/components/BlockRepeater.js.map +1 -0
- package/dist/{development → production/src}/components/BlockRepeaterAddItemTrigger.cjs +8 -4
- package/dist/production/src/components/BlockRepeaterAddItemTrigger.cjs.map +1 -0
- package/dist/{development → production/src}/components/BlockRepeaterAddItemTrigger.js +8 -4
- package/dist/production/src/components/BlockRepeaterAddItemTrigger.js.map +1 -0
- package/dist/production/src/contexts.cjs.map +1 -0
- package/dist/production/src/contexts.js.map +1 -0
- package/dist/production/src/hooks/useBlockRepeaterCurrentBlock.cjs.map +1 -0
- package/dist/production/src/hooks/useBlockRepeaterCurrentBlock.js.map +1 -0
- package/dist/production/src/internal/helpers/staticAnalyzer.cjs.map +1 -0
- package/dist/production/src/internal/helpers/staticAnalyzer.js.map +1 -0
- package/dist/types/components/Block.d.ts +28 -0
- package/dist/types/components/Block.d.ts.map +1 -1
- package/dist/types/components/BlockRepeater.d.ts +28 -0
- package/dist/types/components/BlockRepeater.d.ts.map +1 -1
- package/dist/types/components/BlockRepeaterAddItemTrigger.d.ts +33 -1
- package/dist/types/components/BlockRepeaterAddItemTrigger.d.ts.map +1 -1
- package/dist/types/contexts.d.ts +5 -2
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/hooks/useBlockRepeaterCurrentBlock.d.ts +5 -1
- package/dist/types/hooks/useBlockRepeaterCurrentBlock.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -18
- package/src/components/Block.tsx +28 -0
- package/src/components/BlockRepeater.tsx +32 -3
- package/src/components/BlockRepeaterAddItemTrigger.tsx +48 -5
- package/src/contexts.ts +4 -0
- package/src/hooks/useBlockRepeaterCurrentBlock.ts +5 -1
- package/tsconfig.json +7 -0
- package/tsdoc.json +6 -0
- package/dist/development/components/Block.cjs.map +0 -1
- package/dist/development/components/Block.js.map +0 -1
- package/dist/development/components/BlockRepeater.cjs.map +0 -1
- package/dist/development/components/BlockRepeater.js.map +0 -1
- package/dist/development/components/BlockRepeaterAddItemTrigger.cjs.map +0 -1
- package/dist/development/components/BlockRepeaterAddItemTrigger.js.map +0 -1
- package/dist/development/contexts.cjs.map +0 -1
- package/dist/development/contexts.js.map +0 -1
- package/dist/development/hooks/useBlockRepeaterCurrentBlock.cjs.map +0 -1
- package/dist/development/hooks/useBlockRepeaterCurrentBlock.js.map +0 -1
- package/dist/development/internal/helpers/staticAnalyzer.cjs.map +0 -1
- package/dist/development/internal/helpers/staticAnalyzer.js.map +0 -1
- package/dist/production/components/Block.cjs.map +0 -1
- package/dist/production/components/Block.js.map +0 -1
- package/dist/production/components/BlockRepeater.cjs +0 -22
- package/dist/production/components/BlockRepeater.cjs.map +0 -1
- package/dist/production/components/BlockRepeater.js +0 -22
- package/dist/production/components/BlockRepeater.js.map +0 -1
- package/dist/production/components/BlockRepeaterAddItemTrigger.cjs +0 -17
- package/dist/production/components/BlockRepeaterAddItemTrigger.cjs.map +0 -1
- package/dist/production/components/BlockRepeaterAddItemTrigger.js +0 -17
- package/dist/production/components/BlockRepeaterAddItemTrigger.js.map +0 -1
- package/dist/production/contexts.cjs.map +0 -1
- package/dist/production/contexts.js.map +0 -1
- package/dist/production/hooks/useBlockRepeaterCurrentBlock.cjs.map +0 -1
- package/dist/production/hooks/useBlockRepeaterCurrentBlock.js.map +0 -1
- package/dist/production/internal/helpers/staticAnalyzer.cjs.map +0 -1
- package/dist/production/internal/helpers/staticAnalyzer.js.map +0 -1
- /package/dist/development/{contexts.cjs → src/contexts.cjs} +0 -0
- /package/dist/development/{contexts.js → src/contexts.js} +0 -0
- /package/dist/development/{hooks → src/hooks}/useBlockRepeaterCurrentBlock.cjs +0 -0
- /package/dist/development/{hooks → src/hooks}/useBlockRepeaterCurrentBlock.js +0 -0
- /package/dist/development/{internal → src/internal}/helpers/staticAnalyzer.cjs +0 -0
- /package/dist/development/{internal → src/internal}/helpers/staticAnalyzer.js +0 -0
- /package/dist/{development → production/src}/components/Block.cjs +0 -0
- /package/dist/{development → production/src}/components/Block.js +0 -0
- /package/dist/{development → production/src}/components/BlockRepeater.js +0 -0
- /package/dist/production/{contexts.cjs → src/contexts.cjs} +0 -0
- /package/dist/production/{contexts.js → src/contexts.js} +0 -0
- /package/dist/production/{hooks → src/hooks}/useBlockRepeaterCurrentBlock.cjs +0 -0
- /package/dist/production/{hooks → src/hooks}/useBlockRepeaterCurrentBlock.js +0 -0
- /package/dist/production/{internal → src/internal}/helpers/staticAnalyzer.cjs +0 -0
- /package/dist/production/{internal → src/internal}/helpers/staticAnalyzer.js +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/react-block-repeater",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.40",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -11,35 +11,30 @@
|
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"development": "./dist/development/index.js",
|
|
13
13
|
"production": "./dist/production/index.js",
|
|
14
|
+
"typescript": "./src/index.ts",
|
|
14
15
|
"default": "./dist/production/index.js"
|
|
15
16
|
},
|
|
16
17
|
"require": {
|
|
17
18
|
"types": "./dist/types/index.d.ts",
|
|
18
19
|
"development": "./dist/development/index.cjs",
|
|
19
20
|
"production": "./dist/production/index.cjs",
|
|
21
|
+
"typescript": "./src/index.ts",
|
|
20
22
|
"default": "./dist/production/index.cjs"
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
},
|
|
24
|
-
"files": [
|
|
25
|
-
"dist/",
|
|
26
|
-
"src/"
|
|
27
|
-
],
|
|
28
26
|
"typings": "./dist/types/index.d.ts",
|
|
29
27
|
"scripts": {
|
|
30
|
-
"build": "yarn build:js:dev && yarn build:js:prod",
|
|
31
|
-
"build:js:dev": "vite build --mode development",
|
|
32
|
-
"build:js:prod": "vite build --mode production",
|
|
33
28
|
"ae:build": "api-extractor run --local",
|
|
34
|
-
"ae:test": "api-extractor run"
|
|
35
|
-
"test": "vitest"
|
|
29
|
+
"ae:test": "api-extractor run"
|
|
36
30
|
},
|
|
37
31
|
"dependencies": {
|
|
38
|
-
"@contember/react-binding": "2.0.0-alpha.
|
|
39
|
-
"@contember/react-multipass-rendering": "2.0.0-alpha.
|
|
40
|
-
"@contember/react-repeater": "2.0.0-alpha.
|
|
41
|
-
"@contember/react-utils": "2.0.0-alpha.
|
|
42
|
-
"@radix-ui/
|
|
32
|
+
"@contember/react-binding": "2.0.0-alpha.40",
|
|
33
|
+
"@contember/react-multipass-rendering": "2.0.0-alpha.40",
|
|
34
|
+
"@contember/react-repeater": "2.0.0-alpha.40",
|
|
35
|
+
"@contember/react-utils": "2.0.0-alpha.40",
|
|
36
|
+
"@radix-ui/primitive": "^1.1.0",
|
|
37
|
+
"@radix-ui/react-slot": "^1.1.0"
|
|
43
38
|
},
|
|
44
39
|
"peerDependencies": {
|
|
45
40
|
"react": "^18 || ^19",
|
|
@@ -53,6 +48,5 @@
|
|
|
53
48
|
"type": "git",
|
|
54
49
|
"url": "https://github.com/contember/interface.git",
|
|
55
50
|
"directory": "packages/react-block-repeater"
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/components/Block.tsx
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import { BindingError, Component } from '@contember/react-binding'
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Props for the {@link Block} component.
|
|
6
|
+
*/
|
|
4
7
|
export interface BlockProps {
|
|
8
|
+
/**
|
|
9
|
+
* The content of the block.
|
|
10
|
+
*/
|
|
5
11
|
children: ReactNode
|
|
12
|
+
/**
|
|
13
|
+
* Identifier of the block.
|
|
14
|
+
*/
|
|
6
15
|
name: string
|
|
16
|
+
/**
|
|
17
|
+
* Optional label for the block.
|
|
18
|
+
*/
|
|
7
19
|
label?: ReactNode
|
|
20
|
+
/**
|
|
21
|
+
* Optional form for the block.
|
|
22
|
+
*/
|
|
8
23
|
form?: ReactNode
|
|
9
24
|
}
|
|
10
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Represents individual blocks within a block repeater.
|
|
28
|
+
*
|
|
29
|
+
* ## Props {@link BlockProps}
|
|
30
|
+
* - name, children, ?label, ?form
|
|
31
|
+
*
|
|
32
|
+
* ## Example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <Block name="text" label="Text">
|
|
35
|
+
* <Field field="content" />
|
|
36
|
+
* </Block>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
11
39
|
export const Block = Component<BlockProps>(props => {
|
|
12
40
|
throw new BindingError('"Block" component is not supposed to be rendered.')
|
|
13
41
|
}, ({ label, children, form }) => {
|
|
@@ -4,13 +4,42 @@ import { useState } from 'react'
|
|
|
4
4
|
import { extractBlocks } from '../internal/helpers/staticAnalyzer'
|
|
5
5
|
import { BlockRepeaterConfigContext } from '../contexts'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Props for the {@link BlockRepeater} component.
|
|
9
|
+
*/
|
|
7
10
|
export type BlockRepeaterProps =
|
|
8
11
|
& {
|
|
12
|
+
/**
|
|
13
|
+
* A field that is used to determine the order of the entities.
|
|
14
|
+
*/
|
|
9
15
|
sortableBy: RepeaterProps['sortableBy']
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Discrimination field is a field that is used to determine which block should be rendered for a given entity.
|
|
19
|
+
*/
|
|
10
20
|
discriminationField: SugaredRelativeSingleField['field']
|
|
11
21
|
}
|
|
12
22
|
& RepeaterProps
|
|
13
23
|
|
|
24
|
+
/**
|
|
25
|
+
* A repeater component that renders different blocks based on the value of a discrimination field.
|
|
26
|
+
* This is headless component that does not impose any UI. Check DefaultBlockRepeater in UI library for a styled version.
|
|
27
|
+
*
|
|
28
|
+
* ## Props {@link BlockRepeaterProps}
|
|
29
|
+
* - field or entities, sortableBy, discriminationField, children
|
|
30
|
+
*
|
|
31
|
+
* ## Example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <BlockRepeater field="blocks" discriminationField="type" sortableBy="order">
|
|
34
|
+
* <Block name="text" label="Text">
|
|
35
|
+
* <Field field="content" />
|
|
36
|
+
* </Block>
|
|
37
|
+
* <Block name="image" label="Image">
|
|
38
|
+
* <ImageField field="image" />
|
|
39
|
+
* </Block>
|
|
40
|
+
* </BlockRepeater>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
14
43
|
export const BlockRepeater = Component<BlockRepeaterProps>(({ children, ...props }, env) => {
|
|
15
44
|
const [blocks] = useState(() => extractBlocks(children, env))
|
|
16
45
|
if (Object.keys(blocks).length === 0) {
|
|
@@ -18,9 +47,9 @@ export const BlockRepeater = Component<BlockRepeaterProps>(({ children, ...props
|
|
|
18
47
|
}
|
|
19
48
|
return (
|
|
20
49
|
<Repeater {...props} initialEntityCount={0}>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
50
|
+
<BlockRepeaterConfigContext.Provider value={{ discriminatedBy: props.discriminationField, blocks }}>
|
|
51
|
+
{children}
|
|
52
|
+
</BlockRepeaterConfigContext.Provider>
|
|
24
53
|
</Repeater>
|
|
25
54
|
)
|
|
26
55
|
}, props => {
|
|
@@ -1,23 +1,66 @@
|
|
|
1
1
|
import { Slot } from '@radix-ui/react-slot'
|
|
2
2
|
import { useBlockRepeaterConfig } from '../contexts'
|
|
3
|
-
import React, { ReactElement, useMemo } from 'react'
|
|
3
|
+
import React, { ReactElement, useCallback, useMemo } from 'react'
|
|
4
4
|
import { EntityAccessor } from '@contember/react-binding'
|
|
5
5
|
import { RepeaterAddItemIndex, useRepeaterMethods } from '@contember/react-repeater'
|
|
6
|
+
import { composeEventHandlers } from '@radix-ui/primitive'
|
|
6
7
|
|
|
8
|
+
|
|
9
|
+
const SlotType = Slot as React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props for the {@link BlockRepeaterAddItemTrigger} component.
|
|
13
|
+
*/
|
|
7
14
|
export interface BlockRepeaterAddItemTriggerProps {
|
|
8
|
-
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The type of the item to add.
|
|
18
|
+
*/
|
|
9
19
|
type: string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The index at which to add the item.
|
|
23
|
+
* Can be one of:
|
|
24
|
+
* - number: Adds the item at the specified index.
|
|
25
|
+
* - `'first'`: Adds the item at the beginning.
|
|
26
|
+
* - undefined or `'last'`: Adds the item at the end.
|
|
27
|
+
*/
|
|
10
28
|
index?: RepeaterAddItemIndex
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A function to preprocess the entity.
|
|
32
|
+
*/
|
|
11
33
|
preprocess?: EntityAccessor.BatchUpdatesHandler
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The button element.
|
|
37
|
+
*/
|
|
38
|
+
children: ReactElement
|
|
12
39
|
}
|
|
13
40
|
|
|
41
|
+
/**
|
|
42
|
+
* A trigger component for adding item of given type to a block repeater.
|
|
43
|
+
*
|
|
44
|
+
* ## Props {@link BlockRepeaterAddItemTriggerProps}
|
|
45
|
+
* - type, ?index, ?preprocess, children
|
|
46
|
+
*
|
|
47
|
+
* ## Example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <BlockRepeaterAddItemTrigger type="image" index="first">
|
|
50
|
+
* <button>Add Image</button>
|
|
51
|
+
* </BlockRepeaterAddItemTrigger>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
14
54
|
export const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }: BlockRepeaterAddItemTriggerProps) => {
|
|
15
55
|
const { discriminatedBy } = useBlockRepeaterConfig()
|
|
16
56
|
|
|
17
57
|
const { addItem } = useRepeaterMethods()
|
|
18
|
-
const
|
|
58
|
+
const doAddItem = useCallback(() => addItem(index, (it, options) => {
|
|
19
59
|
it().getField(discriminatedBy).updateValue(type)
|
|
20
|
-
|
|
60
|
+
preprocess?.(it, options)
|
|
61
|
+
}), [addItem, discriminatedBy, index, preprocess, type])
|
|
62
|
+
|
|
63
|
+
const { onClick, ...otherProps } = props as React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
21
64
|
|
|
22
|
-
return <
|
|
65
|
+
return <SlotType onClick={composeEventHandlers(onClick, doAddItem)} {...otherProps} />
|
|
23
66
|
}
|
package/src/contexts.ts
CHANGED
|
@@ -8,4 +8,8 @@ const BlockRepeaterConfigContext_ = createRequiredContext<{
|
|
|
8
8
|
}>('BlockRepeaterConfigContext')
|
|
9
9
|
/** @internal */
|
|
10
10
|
export const BlockRepeaterConfigContext = BlockRepeaterConfigContext_[0]
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns configuration of the block repeater (discrimination field and blocks map).
|
|
14
|
+
*/
|
|
11
15
|
export const useBlockRepeaterConfig = BlockRepeaterConfigContext_[1]
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { useEntity } from '@contember/react-binding'
|
|
2
2
|
import { useBlockRepeaterConfig } from '../contexts'
|
|
3
|
+
import { BlockProps } from '../components'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current block props (see {@link BlockProps}).
|
|
7
|
+
*/
|
|
8
|
+
export const useBlockRepeaterCurrentBlock = (): BlockProps | undefined => {
|
|
5
9
|
const entity = useEntity()
|
|
6
10
|
const { discriminatedBy, blocks } = useBlockRepeaterConfig()
|
|
7
11
|
const field = entity.getField<string>(discriminatedBy).value
|
package/tsconfig.json
ADDED
package/tsdoc.json
ADDED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Block.cjs","sources":["../../../src/components/Block.tsx"],"sourcesContent":["import { BindingError, Component } from '@contember/react-binding'\nimport { ReactNode } from 'react'\n\nexport interface BlockProps {\n\tchildren: ReactNode\n\tname: string\n\tlabel?: ReactNode\n\tform?: ReactNode\n}\n\nexport const Block = Component<BlockProps>(props => {\n\tthrow new BindingError('\"Block\" component is not supposed to be rendered.')\n}, ({ label, children, form }) => {\n\treturn <>\n\t\t{label}\n\t\t{children}\n\t\t{form}\n\t</>\n})\n"],"names":["Component","BindingError","jsxs","Fragment"],"mappings":";;;;AAUa,MAAA,QAAQA,aAAAA,UAAsB,CAAS,UAAA;AAC7C,QAAA,IAAIC,aAAAA,aAAa,mDAAmD;AAC3E,GAAG,CAAC,EAAE,OAAO,UAAU,WAAW;AACjC,SACEC,2BAAA,KAAAC,qBAAA,EAAA,UAAA;AAAA,IAAA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAA,CAAA;AACD,CAAC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Block.js","sources":["../../../src/components/Block.tsx"],"sourcesContent":["import { BindingError, Component } from '@contember/react-binding'\nimport { ReactNode } from 'react'\n\nexport interface BlockProps {\n\tchildren: ReactNode\n\tname: string\n\tlabel?: ReactNode\n\tform?: ReactNode\n}\n\nexport const Block = Component<BlockProps>(props => {\n\tthrow new BindingError('\"Block\" component is not supposed to be rendered.')\n}, ({ label, children, form }) => {\n\treturn <>\n\t\t{label}\n\t\t{children}\n\t\t{form}\n\t</>\n})\n"],"names":[],"mappings":";;AAUa,MAAA,QAAQ,UAAsB,CAAS,UAAA;AAC7C,QAAA,IAAI,aAAa,mDAAmD;AAC3E,GAAG,CAAC,EAAE,OAAO,UAAU,WAAW;AACjC,SACE,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAA,CAAA;AACD,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeater.cjs","sources":["../../../src/components/BlockRepeater.tsx"],"sourcesContent":["import { Component, Field, SugaredRelativeSingleField } from '@contember/react-binding'\nimport { Repeater, RepeaterProps } from '@contember/react-repeater'\nimport { useState } from 'react'\nimport { extractBlocks } from '../internal/helpers/staticAnalyzer'\nimport { BlockRepeaterConfigContext } from '../contexts'\n\nexport type BlockRepeaterProps =\n\t& {\n\t\tsortableBy: RepeaterProps['sortableBy']\n\t\tdiscriminationField: SugaredRelativeSingleField['field']\n\t}\n\t& RepeaterProps\n\nexport const BlockRepeater = Component<BlockRepeaterProps>(({ children, ...props }, env) => {\n\tconst [blocks] = useState(() => extractBlocks(children, env))\n\tif (Object.keys(blocks).length === 0) {\n\t\tthrow new Error('BlockRepeater must have at least one Block child')\n\t}\n\treturn (\n\t\t<Repeater {...props} initialEntityCount={0}>\n\t\t\t\t<BlockRepeaterConfigContext.Provider value={{ discriminatedBy: props.discriminationField, blocks }}>\n\t\t\t\t\t{children}\n\t\t\t\t</BlockRepeaterConfigContext.Provider>\n\t\t</Repeater>\n\t)\n}, props => {\n\treturn (\n\t\t<Repeater {...props}>\n\t\t\t{props.children}\n\t\t\t<Field field={props.discriminationField} />\n\t\t</Repeater>\n\t)\n})\n"],"names":["Component","useState","extractBlocks","Repeater","BlockRepeaterConfigContext","jsxs","jsx","Field"],"mappings":";;;;;;;;AAaa,MAAA,gBAAgBA,uBAA8B,CAAC,EAAE,UAAU,GAAG,SAAS,QAAQ;AACrF,QAAA,CAAC,MAAM,IAAIC,MAAA,SAAS,MAAMC,eAAAA,cAAc,UAAU,GAAG,CAAC;AAC5D,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAC/B,UAAA,IAAI,MAAM,kDAAkD;AAAA,EACnE;AACA,wCACEC,cAAU,UAAA,EAAA,GAAG,OAAO,oBAAoB,GACvC,yCAACC,SAA2B,2BAAA,UAA3B,EAAoC,OAAO,EAAE,iBAAiB,MAAM,qBAAqB,UACxF,UACF,EACF,CAAA;AAEF,GAAG,CAAS,UAAA;AAEV,SAAAC,2BAAA,KAACF,cAAU,UAAA,EAAA,GAAG,OACZ,UAAA;AAAA,IAAM,MAAA;AAAA,IACNG,2BAAAA,IAAAC,aAAAA,OAAA,EAAM,OAAO,MAAM,oBAAqB,CAAA;AAAA,EAC1C,EAAA,CAAA;AAEF,CAAC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeater.js","sources":["../../../src/components/BlockRepeater.tsx"],"sourcesContent":["import { Component, Field, SugaredRelativeSingleField } from '@contember/react-binding'\nimport { Repeater, RepeaterProps } from '@contember/react-repeater'\nimport { useState } from 'react'\nimport { extractBlocks } from '../internal/helpers/staticAnalyzer'\nimport { BlockRepeaterConfigContext } from '../contexts'\n\nexport type BlockRepeaterProps =\n\t& {\n\t\tsortableBy: RepeaterProps['sortableBy']\n\t\tdiscriminationField: SugaredRelativeSingleField['field']\n\t}\n\t& RepeaterProps\n\nexport const BlockRepeater = Component<BlockRepeaterProps>(({ children, ...props }, env) => {\n\tconst [blocks] = useState(() => extractBlocks(children, env))\n\tif (Object.keys(blocks).length === 0) {\n\t\tthrow new Error('BlockRepeater must have at least one Block child')\n\t}\n\treturn (\n\t\t<Repeater {...props} initialEntityCount={0}>\n\t\t\t\t<BlockRepeaterConfigContext.Provider value={{ discriminatedBy: props.discriminationField, blocks }}>\n\t\t\t\t\t{children}\n\t\t\t\t</BlockRepeaterConfigContext.Provider>\n\t\t</Repeater>\n\t)\n}, props => {\n\treturn (\n\t\t<Repeater {...props}>\n\t\t\t{props.children}\n\t\t\t<Field field={props.discriminationField} />\n\t\t</Repeater>\n\t)\n})\n"],"names":[],"mappings":";;;;;;AAaa,MAAA,gBAAgB,UAA8B,CAAC,EAAE,UAAU,GAAG,SAAS,QAAQ;AACrF,QAAA,CAAC,MAAM,IAAI,SAAS,MAAM,cAAc,UAAU,GAAG,CAAC;AAC5D,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAC/B,UAAA,IAAI,MAAM,kDAAkD;AAAA,EACnE;AACA,6BACE,UAAU,EAAA,GAAG,OAAO,oBAAoB,GACvC,8BAAC,2BAA2B,UAA3B,EAAoC,OAAO,EAAE,iBAAiB,MAAM,qBAAqB,UACxF,UACF,EACF,CAAA;AAEF,GAAG,CAAS,UAAA;AAEV,SAAA,qBAAC,UAAU,EAAA,GAAG,OACZ,UAAA;AAAA,IAAM,MAAA;AAAA,IACN,oBAAA,OAAA,EAAM,OAAO,MAAM,oBAAqB,CAAA;AAAA,EAC1C,EAAA,CAAA;AAEF,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeaterAddItemTrigger.cjs","sources":["../../../src/components/BlockRepeaterAddItemTrigger.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot'\nimport { useBlockRepeaterConfig } from '../contexts'\nimport React, { ReactElement, useMemo } from 'react'\nimport { EntityAccessor } from '@contember/react-binding'\nimport { RepeaterAddItemIndex, useRepeaterMethods } from '@contember/react-repeater'\n\nexport interface BlockRepeaterAddItemTriggerProps {\n\tchildren: ReactElement\n\ttype: string\n\tindex?: RepeaterAddItemIndex\n\tpreprocess?: EntityAccessor.BatchUpdatesHandler\n}\n\nexport const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }: BlockRepeaterAddItemTriggerProps) => {\n\tconst { discriminatedBy } = useBlockRepeaterConfig()\n\n\tconst { addItem } = useRepeaterMethods()\n\tconst onClick = useMemo(() => () => addItem?.(index, it => {\n\t\tit().getField(discriminatedBy).updateValue(type)\n\t}), [addItem, discriminatedBy, index, type])\n\n\treturn <Slot onClick={onClick} {...props} />\n}\n"],"names":["useBlockRepeaterConfig","useRepeaterMethods","useMemo","jsx","Slot"],"mappings":";;;;;;;AAaa,MAAA,8BAA8B,CAAC,EAAE,YAAY,OAAO,MAAM,GAAG,YAA8C;AACjH,QAAA,EAAE,oBAAoBA,SAAAA;AAEtB,QAAA,EAAE,YAAYC,cAAAA;AACpB,QAAM,UAAUC,MAAAA,QAAQ,MAAM,MAAM,UAAU,OAAO,CAAM,OAAA;AAC1D,OAAA,EAAK,SAAS,eAAe,EAAE,YAAY,IAAI;AAAA,EAAA,CAC/C,GAAG,CAAC,SAAS,iBAAiB,OAAO,IAAI,CAAC;AAE3C,SAAQC,2BAAAA,IAAAC,UAAAA,MAAA,EAAK,SAAmB,GAAG,MAAO,CAAA;AAC3C;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeaterAddItemTrigger.js","sources":["../../../src/components/BlockRepeaterAddItemTrigger.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot'\nimport { useBlockRepeaterConfig } from '../contexts'\nimport React, { ReactElement, useMemo } from 'react'\nimport { EntityAccessor } from '@contember/react-binding'\nimport { RepeaterAddItemIndex, useRepeaterMethods } from '@contember/react-repeater'\n\nexport interface BlockRepeaterAddItemTriggerProps {\n\tchildren: ReactElement\n\ttype: string\n\tindex?: RepeaterAddItemIndex\n\tpreprocess?: EntityAccessor.BatchUpdatesHandler\n}\n\nexport const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }: BlockRepeaterAddItemTriggerProps) => {\n\tconst { discriminatedBy } = useBlockRepeaterConfig()\n\n\tconst { addItem } = useRepeaterMethods()\n\tconst onClick = useMemo(() => () => addItem?.(index, it => {\n\t\tit().getField(discriminatedBy).updateValue(type)\n\t}), [addItem, discriminatedBy, index, type])\n\n\treturn <Slot onClick={onClick} {...props} />\n}\n"],"names":[],"mappings":";;;;;AAaa,MAAA,8BAA8B,CAAC,EAAE,YAAY,OAAO,MAAM,GAAG,YAA8C;AACjH,QAAA,EAAE,oBAAoB;AAEtB,QAAA,EAAE,YAAY;AACpB,QAAM,UAAU,QAAQ,MAAM,MAAM,UAAU,OAAO,CAAM,OAAA;AAC1D,OAAA,EAAK,SAAS,eAAe,EAAE,YAAY,IAAI;AAAA,EAAA,CAC/C,GAAG,CAAC,SAAS,iBAAiB,OAAO,IAAI,CAAC;AAE3C,SAAQ,oBAAA,MAAA,EAAK,SAAmB,GAAG,MAAO,CAAA;AAC3C;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.cjs","sources":["../../src/contexts.ts"],"sourcesContent":["import { SugaredRelativeSingleField } from '@contember/react-binding'\nimport { createRequiredContext } from '@contember/react-utils'\nimport { BlocksMap } from './types'\n\nconst BlockRepeaterConfigContext_ = createRequiredContext<{\n\tdiscriminatedBy: SugaredRelativeSingleField['field']\n\tblocks: BlocksMap\n}>('BlockRepeaterConfigContext')\n/** @internal */\nexport const BlockRepeaterConfigContext = BlockRepeaterConfigContext_[0]\nexport const useBlockRepeaterConfig = BlockRepeaterConfigContext_[1]\n"],"names":["createRequiredContext"],"mappings":";;;AAIA,MAAM,8BAA8BA,WAAAA,sBAGjC,4BAA4B;AAElB,MAAA,6BAA6B,4BAA4B,CAAC;AAC1D,MAAA,yBAAyB,4BAA4B,CAAC;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.js","sources":["../../src/contexts.ts"],"sourcesContent":["import { SugaredRelativeSingleField } from '@contember/react-binding'\nimport { createRequiredContext } from '@contember/react-utils'\nimport { BlocksMap } from './types'\n\nconst BlockRepeaterConfigContext_ = createRequiredContext<{\n\tdiscriminatedBy: SugaredRelativeSingleField['field']\n\tblocks: BlocksMap\n}>('BlockRepeaterConfigContext')\n/** @internal */\nexport const BlockRepeaterConfigContext = BlockRepeaterConfigContext_[0]\nexport const useBlockRepeaterConfig = BlockRepeaterConfigContext_[1]\n"],"names":[],"mappings":";AAIA,MAAM,8BAA8B,sBAGjC,4BAA4B;AAElB,MAAA,6BAA6B,4BAA4B,CAAC;AAC1D,MAAA,yBAAyB,4BAA4B,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockRepeaterCurrentBlock.cjs","sources":["../../../src/hooks/useBlockRepeaterCurrentBlock.ts"],"sourcesContent":["import { useEntity } from '@contember/react-binding'\nimport { useBlockRepeaterConfig } from '../contexts'\n\nexport const useBlockRepeaterCurrentBlock = () => {\n\tconst entity = useEntity()\n\tconst { discriminatedBy, blocks } = useBlockRepeaterConfig()\n\tconst field = entity.getField<string>(discriminatedBy).value\n\treturn field ? blocks[field] : undefined\n}\n"],"names":["useEntity","useBlockRepeaterConfig"],"mappings":";;;;AAGO,MAAM,+BAA+B,MAAM;AACjD,QAAM,SAASA,aAAAA;AACf,QAAM,EAAE,iBAAiB,OAAO,IAAIC,SAAuB,uBAAA;AAC3D,QAAM,QAAQ,OAAO,SAAiB,eAAe,EAAE;AAChD,SAAA,QAAQ,OAAO,KAAK,IAAI;AAChC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockRepeaterCurrentBlock.js","sources":["../../../src/hooks/useBlockRepeaterCurrentBlock.ts"],"sourcesContent":["import { useEntity } from '@contember/react-binding'\nimport { useBlockRepeaterConfig } from '../contexts'\n\nexport const useBlockRepeaterCurrentBlock = () => {\n\tconst entity = useEntity()\n\tconst { discriminatedBy, blocks } = useBlockRepeaterConfig()\n\tconst field = entity.getField<string>(discriminatedBy).value\n\treturn field ? blocks[field] : undefined\n}\n"],"names":[],"mappings":";;AAGO,MAAM,+BAA+B,MAAM;AACjD,QAAM,SAAS;AACf,QAAM,EAAE,iBAAiB,OAAO,IAAI,uBAAuB;AAC3D,QAAM,QAAQ,OAAO,SAAiB,eAAe,EAAE;AAChD,SAAA,QAAQ,OAAO,KAAK,IAAI;AAChC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staticAnalyzer.cjs","sources":["../../../../src/internal/helpers/staticAnalyzer.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport { Block, BlockProps } from '../../components'\nimport { Environment } from '@contember/react-binding'\nimport { ChildrenAnalyzer, Leaf } from '@contember/react-multipass-rendering'\n\ntype BlocksMap = Record<string, BlockProps>\nexport const extractBlocks = (children: ReactNode, env: Environment): BlocksMap => {\n\tconst blocks = blockAnalyzer.processChildren(children, env)\n\treturn Object.fromEntries(blocks.map(block => [block.name, block]))\n}\n\nconst columnLeaf = new Leaf(node => node.props, Block)\n\nconst blockAnalyzer = new ChildrenAnalyzer<\n\tBlockProps,\n\tnever,\n\tEnvironment\n>([columnLeaf], {\n\tstaticRenderFactoryName: 'staticRender',\n\tstaticContextFactoryName: 'generateEnvironment',\n\tunhandledNodeErrorMessage: 'Only Block children are supported.',\n})\n"],"names":["Leaf","Block","ChildrenAnalyzer"],"mappings":";;;;AAMa,MAAA,gBAAgB,CAAC,UAAqB,QAAgC;AAClF,QAAM,SAAS,cAAc,gBAAgB,UAAU,GAAG;AACnD,SAAA,OAAO,YAAY,OAAO,IAAI,CAAA,UAAS,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;AACnE;AAEA,MAAM,aAAa,IAAIA,wBAAAA,KAAK,CAAQ,SAAA,KAAK,OAAOC,MAAAA,KAAK;AAErD,MAAM,gBAAgB,IAAIC,wBAAAA,iBAIxB,CAAC,UAAU,GAAG;AAAA,EACf,yBAAyB;AAAA,EACzB,0BAA0B;AAAA,EAC1B,2BAA2B;AAC5B,CAAC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staticAnalyzer.js","sources":["../../../../src/internal/helpers/staticAnalyzer.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport { Block, BlockProps } from '../../components'\nimport { Environment } from '@contember/react-binding'\nimport { ChildrenAnalyzer, Leaf } from '@contember/react-multipass-rendering'\n\ntype BlocksMap = Record<string, BlockProps>\nexport const extractBlocks = (children: ReactNode, env: Environment): BlocksMap => {\n\tconst blocks = blockAnalyzer.processChildren(children, env)\n\treturn Object.fromEntries(blocks.map(block => [block.name, block]))\n}\n\nconst columnLeaf = new Leaf(node => node.props, Block)\n\nconst blockAnalyzer = new ChildrenAnalyzer<\n\tBlockProps,\n\tnever,\n\tEnvironment\n>([columnLeaf], {\n\tstaticRenderFactoryName: 'staticRender',\n\tstaticContextFactoryName: 'generateEnvironment',\n\tunhandledNodeErrorMessage: 'Only Block children are supported.',\n})\n"],"names":[],"mappings":";;AAMa,MAAA,gBAAgB,CAAC,UAAqB,QAAgC;AAClF,QAAM,SAAS,cAAc,gBAAgB,UAAU,GAAG;AACnD,SAAA,OAAO,YAAY,OAAO,IAAI,CAAA,UAAS,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;AACnE;AAEA,MAAM,aAAa,IAAI,KAAK,CAAQ,SAAA,KAAK,OAAO,KAAK;AAErD,MAAM,gBAAgB,IAAI,iBAIxB,CAAC,UAAU,GAAG;AAAA,EACf,yBAAyB;AAAA,EACzB,0BAA0B;AAAA,EAC1B,2BAA2B;AAC5B,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Block.cjs","sources":["../../../src/components/Block.tsx"],"sourcesContent":["import { BindingError, Component } from '@contember/react-binding'\nimport { ReactNode } from 'react'\n\nexport interface BlockProps {\n\tchildren: ReactNode\n\tname: string\n\tlabel?: ReactNode\n\tform?: ReactNode\n}\n\nexport const Block = Component<BlockProps>(props => {\n\tthrow new BindingError('\"Block\" component is not supposed to be rendered.')\n}, ({ label, children, form }) => {\n\treturn <>\n\t\t{label}\n\t\t{children}\n\t\t{form}\n\t</>\n})\n"],"names":["Component","BindingError","jsxs","Fragment"],"mappings":";;;;AAUa,MAAA,QAAQA,aAAAA,UAAsB,CAAS,UAAA;AAC7C,QAAA,IAAIC,aAAAA,aAAa,mDAAmD;AAC3E,GAAG,CAAC,EAAE,OAAO,UAAU,WAAW;AACjC,SACEC,2BAAA,KAAAC,qBAAA,EAAA,UAAA;AAAA,IAAA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAA,CAAA;AACD,CAAC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Block.js","sources":["../../../src/components/Block.tsx"],"sourcesContent":["import { BindingError, Component } from '@contember/react-binding'\nimport { ReactNode } from 'react'\n\nexport interface BlockProps {\n\tchildren: ReactNode\n\tname: string\n\tlabel?: ReactNode\n\tform?: ReactNode\n}\n\nexport const Block = Component<BlockProps>(props => {\n\tthrow new BindingError('\"Block\" component is not supposed to be rendered.')\n}, ({ label, children, form }) => {\n\treturn <>\n\t\t{label}\n\t\t{children}\n\t\t{form}\n\t</>\n})\n"],"names":[],"mappings":";;AAUa,MAAA,QAAQ,UAAsB,CAAS,UAAA;AAC7C,QAAA,IAAI,aAAa,mDAAmD;AAC3E,GAAG,CAAC,EAAE,OAAO,UAAU,WAAW;AACjC,SACE,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAA,CAAA;AACD,CAAC;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const reactBinding = require("@contember/react-binding");
|
|
5
|
-
const reactRepeater = require("@contember/react-repeater");
|
|
6
|
-
const react = require("react");
|
|
7
|
-
const staticAnalyzer = require("../internal/helpers/staticAnalyzer.cjs");
|
|
8
|
-
const contexts = require("../contexts.cjs");
|
|
9
|
-
const BlockRepeater = reactBinding.Component(({ children, ...props }, env) => {
|
|
10
|
-
const [blocks] = react.useState(() => staticAnalyzer.extractBlocks(children, env));
|
|
11
|
-
if (Object.keys(blocks).length === 0) {
|
|
12
|
-
throw new Error("BlockRepeater must have at least one Block child");
|
|
13
|
-
}
|
|
14
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactRepeater.Repeater, { ...props, initialEntityCount: 0, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.BlockRepeaterConfigContext.Provider, { value: { discriminatedBy: props.discriminationField, blocks }, children }) });
|
|
15
|
-
}, (props) => {
|
|
16
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactRepeater.Repeater, { ...props, children: [
|
|
17
|
-
props.children,
|
|
18
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field: props.discriminationField })
|
|
19
|
-
] });
|
|
20
|
-
});
|
|
21
|
-
exports.BlockRepeater = BlockRepeater;
|
|
22
|
-
//# sourceMappingURL=BlockRepeater.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeater.cjs","sources":["../../../src/components/BlockRepeater.tsx"],"sourcesContent":["import { Component, Field, SugaredRelativeSingleField } from '@contember/react-binding'\nimport { Repeater, RepeaterProps } from '@contember/react-repeater'\nimport { useState } from 'react'\nimport { extractBlocks } from '../internal/helpers/staticAnalyzer'\nimport { BlockRepeaterConfigContext } from '../contexts'\n\nexport type BlockRepeaterProps =\n\t& {\n\t\tsortableBy: RepeaterProps['sortableBy']\n\t\tdiscriminationField: SugaredRelativeSingleField['field']\n\t}\n\t& RepeaterProps\n\nexport const BlockRepeater = Component<BlockRepeaterProps>(({ children, ...props }, env) => {\n\tconst [blocks] = useState(() => extractBlocks(children, env))\n\tif (Object.keys(blocks).length === 0) {\n\t\tthrow new Error('BlockRepeater must have at least one Block child')\n\t}\n\treturn (\n\t\t<Repeater {...props} initialEntityCount={0}>\n\t\t\t\t<BlockRepeaterConfigContext.Provider value={{ discriminatedBy: props.discriminationField, blocks }}>\n\t\t\t\t\t{children}\n\t\t\t\t</BlockRepeaterConfigContext.Provider>\n\t\t</Repeater>\n\t)\n}, props => {\n\treturn (\n\t\t<Repeater {...props}>\n\t\t\t{props.children}\n\t\t\t<Field field={props.discriminationField} />\n\t\t</Repeater>\n\t)\n})\n"],"names":["Component","useState","extractBlocks","Repeater","BlockRepeaterConfigContext","jsxs","jsx","Field"],"mappings":";;;;;;;;AAaa,MAAA,gBAAgBA,uBAA8B,CAAC,EAAE,UAAU,GAAG,SAAS,QAAQ;AACrF,QAAA,CAAC,MAAM,IAAIC,MAAA,SAAS,MAAMC,eAAAA,cAAc,UAAU,GAAG,CAAC;AAC5D,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAC/B,UAAA,IAAI,MAAM,kDAAkD;AAAA,EACnE;AACA,wCACEC,cAAU,UAAA,EAAA,GAAG,OAAO,oBAAoB,GACvC,yCAACC,SAA2B,2BAAA,UAA3B,EAAoC,OAAO,EAAE,iBAAiB,MAAM,qBAAqB,UACxF,UACF,EACF,CAAA;AAEF,GAAG,CAAS,UAAA;AAEV,SAAAC,2BAAA,KAACF,cAAU,UAAA,EAAA,GAAG,OACZ,UAAA;AAAA,IAAM,MAAA;AAAA,IACNG,2BAAAA,IAAAC,aAAAA,OAAA,EAAM,OAAO,MAAM,oBAAqB,CAAA;AAAA,EAC1C,EAAA,CAAA;AAEF,CAAC;;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Component, Field } from "@contember/react-binding";
|
|
3
|
-
import { Repeater } from "@contember/react-repeater";
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
import { extractBlocks } from "../internal/helpers/staticAnalyzer.js";
|
|
6
|
-
import { BlockRepeaterConfigContext } from "../contexts.js";
|
|
7
|
-
const BlockRepeater = Component(({ children, ...props }, env) => {
|
|
8
|
-
const [blocks] = useState(() => extractBlocks(children, env));
|
|
9
|
-
if (Object.keys(blocks).length === 0) {
|
|
10
|
-
throw new Error("BlockRepeater must have at least one Block child");
|
|
11
|
-
}
|
|
12
|
-
return /* @__PURE__ */ jsx(Repeater, { ...props, initialEntityCount: 0, children: /* @__PURE__ */ jsx(BlockRepeaterConfigContext.Provider, { value: { discriminatedBy: props.discriminationField, blocks }, children }) });
|
|
13
|
-
}, (props) => {
|
|
14
|
-
return /* @__PURE__ */ jsxs(Repeater, { ...props, children: [
|
|
15
|
-
props.children,
|
|
16
|
-
/* @__PURE__ */ jsx(Field, { field: props.discriminationField })
|
|
17
|
-
] });
|
|
18
|
-
});
|
|
19
|
-
export {
|
|
20
|
-
BlockRepeater
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=BlockRepeater.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeater.js","sources":["../../../src/components/BlockRepeater.tsx"],"sourcesContent":["import { Component, Field, SugaredRelativeSingleField } from '@contember/react-binding'\nimport { Repeater, RepeaterProps } from '@contember/react-repeater'\nimport { useState } from 'react'\nimport { extractBlocks } from '../internal/helpers/staticAnalyzer'\nimport { BlockRepeaterConfigContext } from '../contexts'\n\nexport type BlockRepeaterProps =\n\t& {\n\t\tsortableBy: RepeaterProps['sortableBy']\n\t\tdiscriminationField: SugaredRelativeSingleField['field']\n\t}\n\t& RepeaterProps\n\nexport const BlockRepeater = Component<BlockRepeaterProps>(({ children, ...props }, env) => {\n\tconst [blocks] = useState(() => extractBlocks(children, env))\n\tif (Object.keys(blocks).length === 0) {\n\t\tthrow new Error('BlockRepeater must have at least one Block child')\n\t}\n\treturn (\n\t\t<Repeater {...props} initialEntityCount={0}>\n\t\t\t\t<BlockRepeaterConfigContext.Provider value={{ discriminatedBy: props.discriminationField, blocks }}>\n\t\t\t\t\t{children}\n\t\t\t\t</BlockRepeaterConfigContext.Provider>\n\t\t</Repeater>\n\t)\n}, props => {\n\treturn (\n\t\t<Repeater {...props}>\n\t\t\t{props.children}\n\t\t\t<Field field={props.discriminationField} />\n\t\t</Repeater>\n\t)\n})\n"],"names":[],"mappings":";;;;;;AAaa,MAAA,gBAAgB,UAA8B,CAAC,EAAE,UAAU,GAAG,SAAS,QAAQ;AACrF,QAAA,CAAC,MAAM,IAAI,SAAS,MAAM,cAAc,UAAU,GAAG,CAAC;AAC5D,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAC/B,UAAA,IAAI,MAAM,kDAAkD;AAAA,EACnE;AACA,6BACE,UAAU,EAAA,GAAG,OAAO,oBAAoB,GACvC,8BAAC,2BAA2B,UAA3B,EAAoC,OAAO,EAAE,iBAAiB,MAAM,qBAAqB,UACxF,UACF,EACF,CAAA;AAEF,GAAG,CAAS,UAAA;AAEV,SAAA,qBAAC,UAAU,EAAA,GAAG,OACZ,UAAA;AAAA,IAAM,MAAA;AAAA,IACN,oBAAA,OAAA,EAAM,OAAO,MAAM,oBAAqB,CAAA;AAAA,EAC1C,EAAA,CAAA;AAEF,CAAC;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const reactSlot = require("@radix-ui/react-slot");
|
|
5
|
-
const contexts = require("../contexts.cjs");
|
|
6
|
-
const react = require("react");
|
|
7
|
-
const reactRepeater = require("@contember/react-repeater");
|
|
8
|
-
const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }) => {
|
|
9
|
-
const { discriminatedBy } = contexts.useBlockRepeaterConfig();
|
|
10
|
-
const { addItem } = reactRepeater.useRepeaterMethods();
|
|
11
|
-
const onClick = react.useMemo(() => () => addItem?.(index, (it) => {
|
|
12
|
-
it().getField(discriminatedBy).updateValue(type);
|
|
13
|
-
}), [addItem, discriminatedBy, index, type]);
|
|
14
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactSlot.Slot, { onClick, ...props });
|
|
15
|
-
};
|
|
16
|
-
exports.BlockRepeaterAddItemTrigger = BlockRepeaterAddItemTrigger;
|
|
17
|
-
//# sourceMappingURL=BlockRepeaterAddItemTrigger.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeaterAddItemTrigger.cjs","sources":["../../../src/components/BlockRepeaterAddItemTrigger.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot'\nimport { useBlockRepeaterConfig } from '../contexts'\nimport React, { ReactElement, useMemo } from 'react'\nimport { EntityAccessor } from '@contember/react-binding'\nimport { RepeaterAddItemIndex, useRepeaterMethods } from '@contember/react-repeater'\n\nexport interface BlockRepeaterAddItemTriggerProps {\n\tchildren: ReactElement\n\ttype: string\n\tindex?: RepeaterAddItemIndex\n\tpreprocess?: EntityAccessor.BatchUpdatesHandler\n}\n\nexport const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }: BlockRepeaterAddItemTriggerProps) => {\n\tconst { discriminatedBy } = useBlockRepeaterConfig()\n\n\tconst { addItem } = useRepeaterMethods()\n\tconst onClick = useMemo(() => () => addItem?.(index, it => {\n\t\tit().getField(discriminatedBy).updateValue(type)\n\t}), [addItem, discriminatedBy, index, type])\n\n\treturn <Slot onClick={onClick} {...props} />\n}\n"],"names":["useBlockRepeaterConfig","useRepeaterMethods","useMemo","jsx","Slot"],"mappings":";;;;;;;AAaa,MAAA,8BAA8B,CAAC,EAAE,YAAY,OAAO,MAAM,GAAG,YAA8C;AACjH,QAAA,EAAE,oBAAoBA,SAAAA;AAEtB,QAAA,EAAE,YAAYC,cAAAA;AACpB,QAAM,UAAUC,MAAAA,QAAQ,MAAM,MAAM,UAAU,OAAO,CAAM,OAAA;AAC1D,OAAA,EAAK,SAAS,eAAe,EAAE,YAAY,IAAI;AAAA,EAAA,CAC/C,GAAG,CAAC,SAAS,iBAAiB,OAAO,IAAI,CAAC;AAE3C,SAAQC,2BAAAA,IAAAC,UAAAA,MAAA,EAAK,SAAmB,GAAG,MAAO,CAAA;AAC3C;;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
3
|
-
import { useBlockRepeaterConfig } from "../contexts.js";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
|
-
import { useRepeaterMethods } from "@contember/react-repeater";
|
|
6
|
-
const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }) => {
|
|
7
|
-
const { discriminatedBy } = useBlockRepeaterConfig();
|
|
8
|
-
const { addItem } = useRepeaterMethods();
|
|
9
|
-
const onClick = useMemo(() => () => addItem?.(index, (it) => {
|
|
10
|
-
it().getField(discriminatedBy).updateValue(type);
|
|
11
|
-
}), [addItem, discriminatedBy, index, type]);
|
|
12
|
-
return /* @__PURE__ */ jsx(Slot, { onClick, ...props });
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
BlockRepeaterAddItemTrigger
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=BlockRepeaterAddItemTrigger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockRepeaterAddItemTrigger.js","sources":["../../../src/components/BlockRepeaterAddItemTrigger.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot'\nimport { useBlockRepeaterConfig } from '../contexts'\nimport React, { ReactElement, useMemo } from 'react'\nimport { EntityAccessor } from '@contember/react-binding'\nimport { RepeaterAddItemIndex, useRepeaterMethods } from '@contember/react-repeater'\n\nexport interface BlockRepeaterAddItemTriggerProps {\n\tchildren: ReactElement\n\ttype: string\n\tindex?: RepeaterAddItemIndex\n\tpreprocess?: EntityAccessor.BatchUpdatesHandler\n}\n\nexport const BlockRepeaterAddItemTrigger = ({ preprocess, index, type, ...props }: BlockRepeaterAddItemTriggerProps) => {\n\tconst { discriminatedBy } = useBlockRepeaterConfig()\n\n\tconst { addItem } = useRepeaterMethods()\n\tconst onClick = useMemo(() => () => addItem?.(index, it => {\n\t\tit().getField(discriminatedBy).updateValue(type)\n\t}), [addItem, discriminatedBy, index, type])\n\n\treturn <Slot onClick={onClick} {...props} />\n}\n"],"names":[],"mappings":";;;;;AAaa,MAAA,8BAA8B,CAAC,EAAE,YAAY,OAAO,MAAM,GAAG,YAA8C;AACjH,QAAA,EAAE,oBAAoB;AAEtB,QAAA,EAAE,YAAY;AACpB,QAAM,UAAU,QAAQ,MAAM,MAAM,UAAU,OAAO,CAAM,OAAA;AAC1D,OAAA,EAAK,SAAS,eAAe,EAAE,YAAY,IAAI;AAAA,EAAA,CAC/C,GAAG,CAAC,SAAS,iBAAiB,OAAO,IAAI,CAAC;AAE3C,SAAQ,oBAAA,MAAA,EAAK,SAAmB,GAAG,MAAO,CAAA;AAC3C;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.cjs","sources":["../../src/contexts.ts"],"sourcesContent":["import { SugaredRelativeSingleField } from '@contember/react-binding'\nimport { createRequiredContext } from '@contember/react-utils'\nimport { BlocksMap } from './types'\n\nconst BlockRepeaterConfigContext_ = createRequiredContext<{\n\tdiscriminatedBy: SugaredRelativeSingleField['field']\n\tblocks: BlocksMap\n}>('BlockRepeaterConfigContext')\n/** @internal */\nexport const BlockRepeaterConfigContext = BlockRepeaterConfigContext_[0]\nexport const useBlockRepeaterConfig = BlockRepeaterConfigContext_[1]\n"],"names":["createRequiredContext"],"mappings":";;;AAIA,MAAM,8BAA8BA,WAAAA,sBAGjC,4BAA4B;AAElB,MAAA,6BAA6B,4BAA4B,CAAC;AAC1D,MAAA,yBAAyB,4BAA4B,CAAC;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.js","sources":["../../src/contexts.ts"],"sourcesContent":["import { SugaredRelativeSingleField } from '@contember/react-binding'\nimport { createRequiredContext } from '@contember/react-utils'\nimport { BlocksMap } from './types'\n\nconst BlockRepeaterConfigContext_ = createRequiredContext<{\n\tdiscriminatedBy: SugaredRelativeSingleField['field']\n\tblocks: BlocksMap\n}>('BlockRepeaterConfigContext')\n/** @internal */\nexport const BlockRepeaterConfigContext = BlockRepeaterConfigContext_[0]\nexport const useBlockRepeaterConfig = BlockRepeaterConfigContext_[1]\n"],"names":[],"mappings":";AAIA,MAAM,8BAA8B,sBAGjC,4BAA4B;AAElB,MAAA,6BAA6B,4BAA4B,CAAC;AAC1D,MAAA,yBAAyB,4BAA4B,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockRepeaterCurrentBlock.cjs","sources":["../../../src/hooks/useBlockRepeaterCurrentBlock.ts"],"sourcesContent":["import { useEntity } from '@contember/react-binding'\nimport { useBlockRepeaterConfig } from '../contexts'\n\nexport const useBlockRepeaterCurrentBlock = () => {\n\tconst entity = useEntity()\n\tconst { discriminatedBy, blocks } = useBlockRepeaterConfig()\n\tconst field = entity.getField<string>(discriminatedBy).value\n\treturn field ? blocks[field] : undefined\n}\n"],"names":["useEntity","useBlockRepeaterConfig"],"mappings":";;;;AAGO,MAAM,+BAA+B,MAAM;AACjD,QAAM,SAASA,aAAAA;AACf,QAAM,EAAE,iBAAiB,OAAO,IAAIC,SAAuB,uBAAA;AAC3D,QAAM,QAAQ,OAAO,SAAiB,eAAe,EAAE;AAChD,SAAA,QAAQ,OAAO,KAAK,IAAI;AAChC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockRepeaterCurrentBlock.js","sources":["../../../src/hooks/useBlockRepeaterCurrentBlock.ts"],"sourcesContent":["import { useEntity } from '@contember/react-binding'\nimport { useBlockRepeaterConfig } from '../contexts'\n\nexport const useBlockRepeaterCurrentBlock = () => {\n\tconst entity = useEntity()\n\tconst { discriminatedBy, blocks } = useBlockRepeaterConfig()\n\tconst field = entity.getField<string>(discriminatedBy).value\n\treturn field ? blocks[field] : undefined\n}\n"],"names":[],"mappings":";;AAGO,MAAM,+BAA+B,MAAM;AACjD,QAAM,SAAS;AACf,QAAM,EAAE,iBAAiB,OAAO,IAAI,uBAAuB;AAC3D,QAAM,QAAQ,OAAO,SAAiB,eAAe,EAAE;AAChD,SAAA,QAAQ,OAAO,KAAK,IAAI;AAChC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staticAnalyzer.cjs","sources":["../../../../src/internal/helpers/staticAnalyzer.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport { Block, BlockProps } from '../../components'\nimport { Environment } from '@contember/react-binding'\nimport { ChildrenAnalyzer, Leaf } from '@contember/react-multipass-rendering'\n\ntype BlocksMap = Record<string, BlockProps>\nexport const extractBlocks = (children: ReactNode, env: Environment): BlocksMap => {\n\tconst blocks = blockAnalyzer.processChildren(children, env)\n\treturn Object.fromEntries(blocks.map(block => [block.name, block]))\n}\n\nconst columnLeaf = new Leaf(node => node.props, Block)\n\nconst blockAnalyzer = new ChildrenAnalyzer<\n\tBlockProps,\n\tnever,\n\tEnvironment\n>([columnLeaf], {\n\tstaticRenderFactoryName: 'staticRender',\n\tstaticContextFactoryName: 'generateEnvironment',\n\tunhandledNodeErrorMessage: 'Only Block children are supported.',\n})\n"],"names":["Leaf","Block","ChildrenAnalyzer"],"mappings":";;;;AAMa,MAAA,gBAAgB,CAAC,UAAqB,QAAgC;AAClF,QAAM,SAAS,cAAc,gBAAgB,UAAU,GAAG;AACnD,SAAA,OAAO,YAAY,OAAO,IAAI,CAAA,UAAS,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;AACnE;AAEA,MAAM,aAAa,IAAIA,wBAAAA,KAAK,CAAQ,SAAA,KAAK,OAAOC,MAAAA,KAAK;AAErD,MAAM,gBAAgB,IAAIC,wBAAAA,iBAIxB,CAAC,UAAU,GAAG;AAAA,EACf,yBAAyB;AAAA,EACzB,0BAA0B;AAAA,EAC1B,2BAA2B;AAC5B,CAAC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staticAnalyzer.js","sources":["../../../../src/internal/helpers/staticAnalyzer.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport { Block, BlockProps } from '../../components'\nimport { Environment } from '@contember/react-binding'\nimport { ChildrenAnalyzer, Leaf } from '@contember/react-multipass-rendering'\n\ntype BlocksMap = Record<string, BlockProps>\nexport const extractBlocks = (children: ReactNode, env: Environment): BlocksMap => {\n\tconst blocks = blockAnalyzer.processChildren(children, env)\n\treturn Object.fromEntries(blocks.map(block => [block.name, block]))\n}\n\nconst columnLeaf = new Leaf(node => node.props, Block)\n\nconst blockAnalyzer = new ChildrenAnalyzer<\n\tBlockProps,\n\tnever,\n\tEnvironment\n>([columnLeaf], {\n\tstaticRenderFactoryName: 'staticRender',\n\tstaticContextFactoryName: 'generateEnvironment',\n\tunhandledNodeErrorMessage: 'Only Block children are supported.',\n})\n"],"names":[],"mappings":";;AAMa,MAAA,gBAAgB,CAAC,UAAqB,QAAgC;AAClF,QAAM,SAAS,cAAc,gBAAgB,UAAU,GAAG;AACnD,SAAA,OAAO,YAAY,OAAO,IAAI,CAAA,UAAS,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;AACnE;AAEA,MAAM,aAAa,IAAI,KAAK,CAAQ,SAAA,KAAK,OAAO,KAAK;AAErD,MAAM,gBAAgB,IAAI,iBAIxB,CAAC,UAAU,GAAG;AAAA,EACf,yBAAyB;AAAA,EACzB,0BAA0B;AAAA,EAC1B,2BAA2B;AAC5B,CAAC;"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|