@nocode-factory/sanity-kit 2.33.3 → 2.34.0
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/dist/index.d.ts +7 -6
- package/dist/index.js +135 -45
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/tools/presentation/PresentationHeader.tsx +101 -45
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocode-factory/sanity-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.34.0",
|
|
4
4
|
"description": "Outils Studio de NoCode Factory : Pages (liste + board), Composants, Historique",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"next": ">=15",
|
|
63
63
|
"react": "^19.2",
|
|
64
|
-
"sanity": "^6.0.0"
|
|
64
|
+
"sanity": "^6.0.0",
|
|
65
|
+
"react-dom": "^19.2"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"@sanity/pkg-utils": "13.0.1",
|
|
@@ -73,7 +74,8 @@
|
|
|
73
74
|
"sanity": "6.15.0",
|
|
74
75
|
"styled-components": "^6.1.18",
|
|
75
76
|
"typescript": "^5.9.3",
|
|
76
|
-
"vitest": "^4.1.11"
|
|
77
|
+
"vitest": "^4.1.11",
|
|
78
|
+
"@types/react-dom": "^19.2.3"
|
|
77
79
|
},
|
|
78
80
|
"publishConfig": {
|
|
79
81
|
"registry": "https://registry.npmjs.org",
|
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
import {useEffect, useRef, useState} from 'react'
|
|
2
|
-
import {
|
|
1
|
+
import {useEffect, useLayoutEffect, useRef, useState} from 'react'
|
|
2
|
+
import {createPortal} from 'react-dom'
|
|
3
|
+
import {Box, Button, Flex} from '@sanity/ui'
|
|
4
|
+
import {Menu, MenuButton, MenuDivider, MenuItem} from '@sanity/ui/menu'
|
|
3
5
|
import {TabletDeviceIcon} from '@sanity/icons/TabletDevice'
|
|
4
6
|
import {PanelRightIcon} from '@sanity/icons/PanelRight'
|
|
5
7
|
import type {PreviewHeaderProps} from 'sanity/presentation'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
+
/** Appareils proposés (dimensions CSS de l'écran, portrait). */
|
|
10
|
+
export const PREVIEW_DEVICES = [
|
|
11
|
+
{id: 'iphone-se', label: 'iPhone SE', width: 375, height: 667},
|
|
12
|
+
{id: 'iphone-12-pro', label: 'iPhone 12 Pro', width: 390, height: 844},
|
|
13
|
+
{id: 'iphone-15-pro-max', label: 'iPhone 15 Pro Max', width: 430, height: 932},
|
|
14
|
+
{id: 'pixel-7', label: 'Pixel 7', width: 412, height: 915},
|
|
15
|
+
{id: 'galaxy-s20', label: 'Galaxy S20', width: 360, height: 800},
|
|
16
|
+
{id: 'ipad-mini', label: 'iPad Mini', width: 768, height: 1024},
|
|
17
|
+
{id: 'ipad-air', label: 'iPad Air', width: 820, height: 1180},
|
|
18
|
+
{id: 'ipad-pro-11', label: 'iPad Pro 11"', width: 834, height: 1194},
|
|
19
|
+
{id: 'ipad-pro-13', label: 'iPad Pro 12.9"', width: 1024, height: 1366},
|
|
20
|
+
] as const
|
|
21
|
+
type DeviceId = (typeof PREVIEW_DEVICES)[number]['id']
|
|
22
|
+
|
|
23
|
+
const KEY_DEVICE = 'ncf.presentation.device'
|
|
9
24
|
const KEY_HIDE = 'ncf.presentation.hideForm'
|
|
10
25
|
|
|
11
|
-
const
|
|
26
|
+
const read = (key: string): string | null => {
|
|
12
27
|
try {
|
|
13
|
-
return window.localStorage.getItem(key)
|
|
28
|
+
return window.localStorage.getItem(key)
|
|
14
29
|
} catch {
|
|
15
|
-
return
|
|
30
|
+
return null
|
|
16
31
|
}
|
|
17
32
|
}
|
|
18
|
-
const
|
|
33
|
+
const write = (key: string, value: string | null) => {
|
|
19
34
|
try {
|
|
20
|
-
window.localStorage.
|
|
35
|
+
if (value === null) window.localStorage.removeItem(key)
|
|
36
|
+
else window.localStorage.setItem(key, value)
|
|
21
37
|
} catch {
|
|
22
38
|
/* stockage indisponible : le choix vaut pour la session */
|
|
23
39
|
}
|
|
@@ -29,29 +45,52 @@ const previewPanel = () => document.getElementById('presentation-narrow-panel-pr
|
|
|
29
45
|
const contentPanel = () => document.getElementById('presentation-narrow-panel-content')
|
|
30
46
|
|
|
31
47
|
/**
|
|
32
|
-
* En-tête de l'aperçu (Presentation) : la barre
|
|
33
|
-
* -
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
48
|
+
* En-tête de l'aperçu (Presentation) : la barre native, plus
|
|
49
|
+
* - un menu d'APPAREILS, posé juste à côté du bouton mobile natif : iPhone 12 Pro
|
|
50
|
+
* (390×844), iPad Air (820×1180)... L'aperçu prend les dimensions de l'appareil,
|
|
51
|
+
* affichées à côté de l'icône ;
|
|
52
|
+
* - « Hide edit panel » : masque le formulaire à droite (la liste des pages reste).
|
|
53
|
+
* Choix mémorisés dans le navigateur. Seulement l'affichage : aucune donnée touchée.
|
|
37
54
|
*/
|
|
38
55
|
export function NcfPresentationHeader(props: PreviewHeaderProps) {
|
|
39
56
|
const ref = useRef<HTMLDivElement>(null)
|
|
40
|
-
const [
|
|
41
|
-
const [hideForm, setHideForm] = useState(() =>
|
|
57
|
+
const [deviceId, setDeviceId] = useState<DeviceId | null>(() => (read(KEY_DEVICE) as DeviceId | null) ?? null)
|
|
58
|
+
const [hideForm, setHideForm] = useState(() => read(KEY_HIDE) === '1')
|
|
59
|
+
const [slot, setSlot] = useState<HTMLElement | null>(null)
|
|
60
|
+
const device = PREVIEW_DEVICES.find((d) => d.id === deviceId) ?? null
|
|
42
61
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
// Emplacement juste après le bouton mobile / ordinateur natif de Presentation.
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
const root = ref.current
|
|
65
|
+
const icon = root?.querySelector('[data-sanity-icon="mobile-device"], [data-sanity-icon="desktop"]')
|
|
66
|
+
const button = icon?.closest('button') ?? null
|
|
67
|
+
if (!button) return
|
|
68
|
+
let target = root?.querySelector<HTMLElement>('[data-ncf-device-slot]') ?? null
|
|
69
|
+
if (!target) {
|
|
70
|
+
target = document.createElement('span')
|
|
71
|
+
target.setAttribute('data-ncf-device-slot', '')
|
|
72
|
+
target.style.display = 'inline-flex'
|
|
73
|
+
button.insertAdjacentElement('afterend', target)
|
|
52
74
|
}
|
|
75
|
+
if (target !== slot) setSlot(target)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// Appareil : l'iframe de l'aperçu prend ses dimensions (dans la place disponible).
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const iframe = previewPanel()?.querySelector('iframe') ?? null
|
|
81
|
+
if (!iframe || !device) return
|
|
82
|
+
const set: [string, string][] = [
|
|
83
|
+
['width', `${device.width}px`],
|
|
84
|
+
['max-width', '100%'],
|
|
85
|
+
['height', `${device.height}px`],
|
|
86
|
+
['margin-left', 'auto'],
|
|
87
|
+
['margin-right', 'auto'],
|
|
88
|
+
['display', 'block'],
|
|
89
|
+
['flex', 'none'],
|
|
90
|
+
]
|
|
91
|
+
for (const [p, v] of set) iframe.style.setProperty(p, v, 'important')
|
|
53
92
|
return () => {
|
|
54
|
-
for (const p of
|
|
93
|
+
for (const [p] of set) iframe.style.removeProperty(p)
|
|
55
94
|
}
|
|
56
95
|
})
|
|
57
96
|
|
|
@@ -60,18 +99,14 @@ export function NcfPresentationHeader(props: PreviewHeaderProps) {
|
|
|
60
99
|
const panel = previewPanel()
|
|
61
100
|
const content = contentPanel()
|
|
62
101
|
if (!content || !hideForm) return
|
|
63
|
-
// Le panneau d'édition et sa poignée de redimensionnement (juste avant lui).
|
|
64
102
|
const hidden: HTMLElement[] = [content]
|
|
65
103
|
const handle = content.previousElementSibling as HTMLElement | null
|
|
66
104
|
if (handle && handle !== panel && !handle.id) hidden.push(handle)
|
|
67
|
-
// Seulement masquer : jamais toucher aux largeurs gérées par Presentation
|
|
68
|
-
// forcer puis les rendre faussait la répartition au réaffichage).
|
|
105
|
+
// Seulement masquer : jamais toucher aux largeurs gérées par Presentation.
|
|
69
106
|
const apply = () => {
|
|
70
107
|
for (const h of hidden) if (h.style.getPropertyValue('display') !== 'none') h.style.setProperty('display', 'none', 'important')
|
|
71
108
|
}
|
|
72
109
|
apply()
|
|
73
|
-
// Presentation réécrit le style de ses panneaux (redimensionnement) : on
|
|
74
|
-
// réapplique, sans boucle (rien n'est réécrit si c'est déjà en place).
|
|
75
110
|
const observer = new MutationObserver(apply)
|
|
76
111
|
for (const el of hidden) observer.observe(el, {attributes: true, attributeFilter: ['style']})
|
|
77
112
|
return () => {
|
|
@@ -80,24 +115,45 @@ export function NcfPresentationHeader(props: PreviewHeaderProps) {
|
|
|
80
115
|
}
|
|
81
116
|
})
|
|
82
117
|
|
|
118
|
+
const choose = (id: DeviceId | null) => {
|
|
119
|
+
setDeviceId(id)
|
|
120
|
+
write(KEY_DEVICE, id)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const deviceMenu = (
|
|
124
|
+
<MenuButton
|
|
125
|
+
id="ncf-preview-device"
|
|
126
|
+
button={
|
|
127
|
+
<Button
|
|
128
|
+
icon={TabletDeviceIcon}
|
|
129
|
+
text={device ? `${device.width}×${device.height}` : undefined}
|
|
130
|
+
mode={device ? 'default' : 'bleed'}
|
|
131
|
+
tone={device ? 'primary' : 'default'}
|
|
132
|
+
padding={2}
|
|
133
|
+
fontSize={1}
|
|
134
|
+
title={device ? `${device.label} (${device.width}×${device.height})` : 'Preview on a device'}
|
|
135
|
+
/>
|
|
136
|
+
}
|
|
137
|
+
menu={
|
|
138
|
+
<Menu>
|
|
139
|
+
<MenuItem text="Full width" pressed={!device} onClick={() => choose(null)} />
|
|
140
|
+
<MenuDivider />
|
|
141
|
+
{PREVIEW_DEVICES.map((d) => (
|
|
142
|
+
<MenuItem key={d.id} text={`${d.label} ${d.width}×${d.height}`} pressed={d.id === deviceId} onClick={() => choose(d.id)} />
|
|
143
|
+
))}
|
|
144
|
+
</Menu>
|
|
145
|
+
}
|
|
146
|
+
popover={{portal: true, placement: 'bottom-end'}}
|
|
147
|
+
/>
|
|
148
|
+
)
|
|
149
|
+
|
|
83
150
|
return (
|
|
84
151
|
<Flex ref={ref} align="center" gap={1} style={{width: '100%'}}>
|
|
85
152
|
<Box flex={1} style={{minWidth: 0}}>
|
|
86
153
|
{props.renderDefault(props)}
|
|
87
154
|
</Box>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
mode={tablet ? 'default' : 'bleed'}
|
|
91
|
-
tone={tablet ? 'primary' : 'default'}
|
|
92
|
-
padding={2}
|
|
93
|
-
fontSize={1}
|
|
94
|
-
title={tablet ? 'Back to full width' : `Tablet (${TABLET_WIDTH}px)`}
|
|
95
|
-
aria-pressed={tablet}
|
|
96
|
-
onClick={() => {
|
|
97
|
-
setTablet(!tablet)
|
|
98
|
-
save(KEY_TABLET, !tablet)
|
|
99
|
-
}}
|
|
100
|
-
/>
|
|
155
|
+
{/* À côté du bouton mobile natif ; à défaut (mise en page de Sanity changée), ici. */}
|
|
156
|
+
{slot ? createPortal(deviceMenu, slot) : deviceMenu}
|
|
101
157
|
<Button
|
|
102
158
|
icon={PanelRightIcon}
|
|
103
159
|
mode={hideForm ? 'default' : 'bleed'}
|
|
@@ -108,7 +164,7 @@ export function NcfPresentationHeader(props: PreviewHeaderProps) {
|
|
|
108
164
|
aria-pressed={hideForm}
|
|
109
165
|
onClick={() => {
|
|
110
166
|
setHideForm(!hideForm)
|
|
111
|
-
|
|
167
|
+
write(KEY_HIDE, !hideForm ? '1' : '0')
|
|
112
168
|
}}
|
|
113
169
|
/>
|
|
114
170
|
</Flex>
|
package/src/version.ts
CHANGED