@nocode-factory/sanity-kit 2.16.0 → 2.17.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 +1 -1
- package/dist/index.js +150 -63
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/undo.ts +91 -0
- package/src/tools/history/DiffPanel.tsx +87 -37
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1303,7 +1303,7 @@ export declare function ActorName(props: {
|
|
|
1303
1303
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1304
1304
|
* le vérifie.
|
|
1305
1305
|
*/
|
|
1306
|
-
export declare const KIT_VERSION = "2.
|
|
1306
|
+
export declare const KIT_VERSION = "2.17.0";
|
|
1307
1307
|
/**
|
|
1308
1308
|
* Données de la page proposées comme colonnes.
|
|
1309
1309
|
*
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ import "@xyflow/react/dist/style.css";
|
|
|
34
34
|
import { TrashIcon } from "@sanity/icons/Trash";
|
|
35
35
|
import { RefreshIcon } from "@sanity/icons/Refresh";
|
|
36
36
|
import { RestoreIcon } from "@sanity/icons/Restore";
|
|
37
|
+
import { UndoIcon } from "@sanity/icons/Undo";
|
|
37
38
|
import { Tooltip } from "@sanity/ui/tooltip";
|
|
38
39
|
const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFAULT_TITLE_FIELD = "title", DEFAULT_NOINDEX_FIELDS = ["seo.noindex", "noindex"], DEFAULT_I18N = {
|
|
39
40
|
field: "language",
|
|
@@ -1361,7 +1362,7 @@ function explainGrantError(error) {
|
|
|
1361
1362
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1362
1363
|
* le vérifie.
|
|
1363
1364
|
*/
|
|
1364
|
-
const KIT_VERSION = "2.
|
|
1365
|
+
const KIT_VERSION = "2.17.0";
|
|
1365
1366
|
/**
|
|
1366
1367
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1367
1368
|
*
|
|
@@ -1688,7 +1689,7 @@ function useKitUpdate() {
|
|
|
1688
1689
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1689
1690
|
}).catch(() => {}), () => controller.abort();
|
|
1690
1691
|
}, []);
|
|
1691
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1692
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.17.0") > 0);
|
|
1692
1693
|
return {
|
|
1693
1694
|
current: KIT_VERSION,
|
|
1694
1695
|
latest,
|
|
@@ -6696,13 +6697,13 @@ function useHistory(documentId) {
|
|
|
6696
6697
|
* noierait les vraies modifications sous du bruit. `_id` et `_type` ne
|
|
6697
6698
|
* changent pas sans que ce soit un autre document.
|
|
6698
6699
|
*/
|
|
6699
|
-
const SYSTEM_KEYS = /* @__PURE__ */ new Set([
|
|
6700
|
+
const SYSTEM_KEYS$1 = /* @__PURE__ */ new Set([
|
|
6700
6701
|
"_rev",
|
|
6701
6702
|
"_updatedAt",
|
|
6702
6703
|
"_createdAt",
|
|
6703
6704
|
"_id",
|
|
6704
6705
|
"_type"
|
|
6705
|
-
]), NOISE_KEYS = /* @__PURE__ */ new Set(["_key"]), isObject = (value) => typeof value == "object" && !!value && !Array.isArray(value);
|
|
6706
|
+
]), NOISE_KEYS = /* @__PURE__ */ new Set(["_key"]), isObject$1 = (value) => typeof value == "object" && !!value && !Array.isArray(value);
|
|
6706
6707
|
/**
|
|
6707
6708
|
* Aplatit un document en chemins terminaux.
|
|
6708
6709
|
*
|
|
@@ -6712,9 +6713,9 @@ const SYSTEM_KEYS = /* @__PURE__ */ new Set([
|
|
|
6712
6713
|
*/
|
|
6713
6714
|
function flatten(value, prefix = "", out = /* @__PURE__ */ new Map()) {
|
|
6714
6715
|
if (Array.isArray(value)) return value.forEach((item, index) => {
|
|
6715
|
-
flatten(item, `${prefix}[${isObject(item) && typeof item._key == "string" ? item._key : String(index)}]`, out);
|
|
6716
|
+
flatten(item, `${prefix}[${isObject$1(item) && typeof item._key == "string" ? item._key : String(index)}]`, out);
|
|
6716
6717
|
}), out;
|
|
6717
|
-
if (isObject(value)) {
|
|
6718
|
+
if (isObject$1(value)) {
|
|
6718
6719
|
let keys = Object.keys(value).filter((key) => !NOISE_KEYS.has(key));
|
|
6719
6720
|
keys.length === 0 && prefix && out.set(prefix, {});
|
|
6720
6721
|
for (let key of keys) flatten(value[key], prefix ? `${prefix}.${key}` : key, out);
|
|
@@ -6722,7 +6723,7 @@ function flatten(value, prefix = "", out = /* @__PURE__ */ new Map()) {
|
|
|
6722
6723
|
}
|
|
6723
6724
|
return prefix && out.set(prefix, value), out;
|
|
6724
6725
|
}
|
|
6725
|
-
const same = (a, b) => a === b || Number.isNaN(a) && Number.isNaN(b) || JSON.stringify(a) === JSON.stringify(b);
|
|
6726
|
+
const same$1 = (a, b) => a === b || Number.isNaN(a) && Number.isNaN(b) || JSON.stringify(a) === JSON.stringify(b);
|
|
6726
6727
|
/**
|
|
6727
6728
|
* Modifications entre deux états, triées par chemin.
|
|
6728
6729
|
*
|
|
@@ -6735,7 +6736,7 @@ function diffDocuments(before, after) {
|
|
|
6735
6736
|
for (let path of paths) {
|
|
6736
6737
|
let had = left.has(path), has = right.has(path), valueBefore = left.get(path), valueAfter = right.get(path);
|
|
6737
6738
|
if (had && has) {
|
|
6738
|
-
same(valueBefore, valueAfter) || changes.push({
|
|
6739
|
+
same$1(valueBefore, valueAfter) || changes.push({
|
|
6739
6740
|
path,
|
|
6740
6741
|
kind: "changed",
|
|
6741
6742
|
before: valueBefore,
|
|
@@ -6760,7 +6761,7 @@ function diffDocuments(before, after) {
|
|
|
6760
6761
|
/** Un chemin système, à la racine comme au fond d'un tableau. */
|
|
6761
6762
|
function isSystemPath(path) {
|
|
6762
6763
|
let last = path.split(".").pop() ?? "";
|
|
6763
|
-
return SYSTEM_KEYS.has(last);
|
|
6764
|
+
return SYSTEM_KEYS$1.has(last);
|
|
6764
6765
|
}
|
|
6765
6766
|
/**
|
|
6766
6767
|
* Résumé d'un changement en une ligne.
|
|
@@ -6812,7 +6813,55 @@ function diffWords(before, after, limit = 400) {
|
|
|
6812
6813
|
return segments;
|
|
6813
6814
|
}
|
|
6814
6815
|
/** Une comparaison mot à mot n'a de sens qu'entre deux textes. */
|
|
6815
|
-
const isTextChange = (before, after) => typeof before == "string" && typeof after == "string",
|
|
6816
|
+
const isTextChange = (before, after) => typeof before == "string" && typeof after == "string", SYSTEM_KEYS = /* @__PURE__ */ new Set([
|
|
6817
|
+
"_rev",
|
|
6818
|
+
"_updatedAt",
|
|
6819
|
+
"_createdAt",
|
|
6820
|
+
"_id",
|
|
6821
|
+
"_type"
|
|
6822
|
+
]), isObject = (v) => typeof v == "object" && !!v && !Array.isArray(v), same = (a, b) => JSON.stringify(a) === JSON.stringify(b), keyed = (v) => Array.isArray(v) && v.every((item) => isObject(item) && typeof item._key == "string"), ABSENT = Symbol("absent");
|
|
6823
|
+
function revert(current, before, after, path, out) {
|
|
6824
|
+
if (same(before, after)) return current;
|
|
6825
|
+
if (same(current, after)) return out.reverted++, before;
|
|
6826
|
+
if (isObject(current) && isObject(before) && isObject(after)) {
|
|
6827
|
+
let result = { ...current };
|
|
6828
|
+
for (let key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
6829
|
+
if (SYSTEM_KEYS.has(key)) continue;
|
|
6830
|
+
let v = revert(key in current ? current[key] : ABSENT, key in before ? before[key] : ABSENT, key in after ? after[key] : ABSENT, path ? `${path}.${key}` : key, out);
|
|
6831
|
+
v === ABSENT ? delete result[key] : result[key] = v;
|
|
6832
|
+
}
|
|
6833
|
+
return result;
|
|
6834
|
+
}
|
|
6835
|
+
if (keyed(current) && keyed(before) && keyed(after)) {
|
|
6836
|
+
let result = [...current], at = (list, key) => list.findIndex((item) => item._key === key);
|
|
6837
|
+
for (let key of /* @__PURE__ */ new Set([...before.map((i) => i._key), ...after.map((i) => i._key)])) {
|
|
6838
|
+
let b = before[at(before, key)], a = after[at(after, key)], index = at(result, key), label = `${path}[${key}]`;
|
|
6839
|
+
if (index >= 0) {
|
|
6840
|
+
let v = revert(result[index], b ?? ABSENT, a ?? ABSENT, label, out);
|
|
6841
|
+
v === ABSENT ? result.splice(index, 1) : result[index] = v;
|
|
6842
|
+
} else b && !a ? (result.splice(Math.min(at(before, key), result.length), 0, b), out.reverted++) : b && a && !same(a, b) && out.conflicts.push(label);
|
|
6843
|
+
}
|
|
6844
|
+
return result;
|
|
6845
|
+
}
|
|
6846
|
+
return out.conflicts.push(path || "(document)"), current;
|
|
6847
|
+
}
|
|
6848
|
+
/**
|
|
6849
|
+
* Annule l'événement `before` → `after` dans `current` (brouillon ou version
|
|
6850
|
+
* publiée actuelle). `current` absent (document supprimé depuis) : l'état
|
|
6851
|
+
* d'avant l'événement.
|
|
6852
|
+
*/
|
|
6853
|
+
function undoChange(current, before, after) {
|
|
6854
|
+
let out = {
|
|
6855
|
+
conflicts: [],
|
|
6856
|
+
reverted: 0
|
|
6857
|
+
}, document = revert(current ?? after ?? {}, before ?? {}, after ?? {}, "", out);
|
|
6858
|
+
return {
|
|
6859
|
+
document: isObject(document) ? document : {},
|
|
6860
|
+
conflicts: out.conflicts,
|
|
6861
|
+
reverted: out.reverted
|
|
6862
|
+
};
|
|
6863
|
+
}
|
|
6864
|
+
const MARK = {
|
|
6816
6865
|
removed: {
|
|
6817
6866
|
sign: "−",
|
|
6818
6867
|
line: DIFF.removedLine,
|
|
@@ -6929,11 +6978,11 @@ function ActorName(props) {
|
|
|
6929
6978
|
* client, et une restauration reste attribuée à qui l'a demandée.
|
|
6930
6979
|
*/
|
|
6931
6980
|
function DiffPanel(props) {
|
|
6932
|
-
let { event, onClose } = props, config = useKitConfig(), client = useKitClient(), [detail, setDetail] = useState(null), [loading, setLoading] = useState(!0), [error, setError] = useState(null), [restoring, setRestoring] = useState(!1), [restored, setRestored] = useState(null);
|
|
6981
|
+
let { event, onClose } = props, config = useKitConfig(), client = useKitClient(), [detail, setDetail] = useState(null), [loading, setLoading] = useState(!0), [error, setError] = useState(null), [restoring, setRestoring] = useState(!1), [restored, setRestored] = useState(null), [conflicts, setConflicts] = useState([]);
|
|
6933
6982
|
useEffect(() => {
|
|
6934
6983
|
if (!config.history) return;
|
|
6935
6984
|
let controller = new AbortController();
|
|
6936
|
-
return setLoading(!0), setError(null), setRestored(null), fetchDetail(config.history.endpoint, config.history.projectKey, event.id, controller.signal).then((result) => {
|
|
6985
|
+
return setLoading(!0), setError(null), setRestored(null), setConflicts([]), fetchDetail(config.history.endpoint, config.history.projectKey, event.id, controller.signal).then((result) => {
|
|
6937
6986
|
controller.signal.aborted || setDetail(result);
|
|
6938
6987
|
}).catch(() => {
|
|
6939
6988
|
controller.signal.aborted || setError("Ce détail n'a pas pu être chargé.");
|
|
@@ -6941,23 +6990,29 @@ function DiffPanel(props) {
|
|
|
6941
6990
|
controller.signal.aborted || setLoading(!1);
|
|
6942
6991
|
}), () => controller.abort();
|
|
6943
6992
|
}, [config.history, event.id]);
|
|
6944
|
-
let snapshot = detail?.current.snapshot ?? null, changes = detail ? diffDocuments(detail.previous?.snapshot ?? null, snapshot) : [],
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6993
|
+
let snapshot = detail?.current.snapshot ?? null, changes = detail ? diffDocuments(detail.previous?.snapshot ?? null, snapshot) : [], base = event.document_id.replace(/^drafts\./, ""), writeDraft = async (content) => {
|
|
6994
|
+
let { _rev, _createdAt, _updatedAt, ...rest } = content;
|
|
6995
|
+
await client.createOrReplace({
|
|
6996
|
+
...rest,
|
|
6997
|
+
_id: `drafts.${base}`,
|
|
6998
|
+
_type: event.document_type
|
|
6999
|
+
}), setRestored(base);
|
|
7000
|
+
}, run = async (action) => {
|
|
7001
|
+
setRestoring(!0), setError(null), setConflicts([]);
|
|
7002
|
+
try {
|
|
7003
|
+
await action();
|
|
7004
|
+
} catch (cause) {
|
|
7005
|
+
setError(explainRestore(cause));
|
|
7006
|
+
} finally {
|
|
7007
|
+
setRestoring(!1);
|
|
6959
7008
|
}
|
|
6960
|
-
}
|
|
7009
|
+
}, undo = () => run(async () => {
|
|
7010
|
+
if (!detail) return;
|
|
7011
|
+
let result = undoChange(await client.getDocument(`drafts.${base}`) ?? await client.getDocument(base) ?? null, detail.previous?.snapshot ?? null, snapshot ?? null);
|
|
7012
|
+
await writeDraft(result.document), setConflicts(result.conflicts);
|
|
7013
|
+
}), restore = () => run(async () => {
|
|
7014
|
+
snapshot && await writeDraft(snapshot);
|
|
7015
|
+
});
|
|
6961
7016
|
return /* @__PURE__ */ jsx(Card, {
|
|
6962
7017
|
radius: 3,
|
|
6963
7018
|
shadow: 1,
|
|
@@ -7029,28 +7084,41 @@ function DiffPanel(props) {
|
|
|
7029
7084
|
tone: "positive",
|
|
7030
7085
|
children: /* @__PURE__ */ jsxs(Stack, {
|
|
7031
7086
|
gap: 3,
|
|
7032
|
-
children: [
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7087
|
+
children: [
|
|
7088
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
7089
|
+
size: 1,
|
|
7090
|
+
children: [
|
|
7091
|
+
"Fait ",
|
|
7092
|
+
/* @__PURE__ */ jsx("b", { children: "en brouillon" }),
|
|
7093
|
+
". Rien n'est encore en ligne : ouvrez le document, vérifiez, puis ",
|
|
7094
|
+
/* @__PURE__ */ jsx("b", { children: "publiez" }),
|
|
7095
|
+
"."
|
|
7096
|
+
]
|
|
7097
|
+
}),
|
|
7098
|
+
conflicts.length > 0 && /* @__PURE__ */ jsxs(Text, {
|
|
7099
|
+
size: 1,
|
|
7100
|
+
children: [
|
|
7101
|
+
"Non annulé, car modifié depuis : ",
|
|
7102
|
+
conflicts.join(", "),
|
|
7103
|
+
"."
|
|
7104
|
+
]
|
|
7105
|
+
}),
|
|
7106
|
+
/* @__PURE__ */ jsx(IntentLink, {
|
|
7107
|
+
intent: "edit",
|
|
7108
|
+
params: {
|
|
7109
|
+
id: restored,
|
|
7110
|
+
type: event.document_type
|
|
7111
|
+
},
|
|
7112
|
+
style: { textDecoration: "none" },
|
|
7113
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
7114
|
+
mode: "ghost",
|
|
7115
|
+
fontSize: 1,
|
|
7116
|
+
padding: 2,
|
|
7117
|
+
text: "Ouvrir le brouillon",
|
|
7118
|
+
as: "span"
|
|
7119
|
+
})
|
|
7052
7120
|
})
|
|
7053
|
-
|
|
7121
|
+
]
|
|
7054
7122
|
})
|
|
7055
7123
|
}),
|
|
7056
7124
|
!loading && detail && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -7090,20 +7158,39 @@ function DiffPanel(props) {
|
|
|
7090
7158
|
paddingTop: 12
|
|
7091
7159
|
},
|
|
7092
7160
|
children: /* @__PURE__ */ jsxs(Stack, {
|
|
7093
|
-
gap:
|
|
7094
|
-
children: [/* @__PURE__ */
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7161
|
+
gap: 3,
|
|
7162
|
+
children: [detail.previous && changes.length > 0 && /* @__PURE__ */ jsxs(Stack, {
|
|
7163
|
+
gap: 2,
|
|
7164
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
7165
|
+
mode: "default",
|
|
7166
|
+
tone: "primary",
|
|
7167
|
+
fontSize: 1,
|
|
7168
|
+
padding: 3,
|
|
7169
|
+
icon: UndoIcon,
|
|
7170
|
+
text: restoring ? "Annulation…" : "Annuler cette modification",
|
|
7171
|
+
disabled: restoring,
|
|
7172
|
+
onClick: undo
|
|
7173
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
7174
|
+
size: 0,
|
|
7175
|
+
muted: !0,
|
|
7176
|
+
children: "Remet les valeurs d'avant cette modification, et seulement elles : ce qui a été modifié ensuite est conservé. Le résultat va dans le brouillon : publiez-le pour le mettre en ligne."
|
|
7177
|
+
})]
|
|
7178
|
+
}), /* @__PURE__ */ jsxs(Stack, {
|
|
7179
|
+
gap: 2,
|
|
7180
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
7181
|
+
mode: "ghost",
|
|
7182
|
+
tone: "caution",
|
|
7183
|
+
fontSize: 1,
|
|
7184
|
+
padding: 3,
|
|
7185
|
+
icon: RestoreIcon,
|
|
7186
|
+
text: restoring ? "Restauration…" : "Restaurer le document tel qu’après cette modification",
|
|
7187
|
+
disabled: restoring,
|
|
7188
|
+
onClick: restore
|
|
7189
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
7190
|
+
size: 0,
|
|
7191
|
+
muted: !0,
|
|
7192
|
+
children: "Remet le document ENTIER dans l'état qui a suivi cette modification (les modifications plus récentes sont perdues), dans le brouillon. La version en ligne n'est pas touchée tant que vous ne publiez pas."
|
|
7193
|
+
})]
|
|
7107
7194
|
})]
|
|
7108
7195
|
})
|
|
7109
7196
|
})
|