@sanity/presets 0.0.2 → 0.1.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 CHANGED
@@ -1,4 +1,12 @@
1
- import * as sanity from "sanity";
2
- declare function presetsComposer(): sanity.PluginOptions;
3
- export { presetsComposer };
1
+ import { PluginOptions, SchemaTypeDefinition } from "sanity";
2
+ interface PresetResult {
3
+ types: SchemaTypeDefinition[];
4
+ }
5
+ declare function presets(...types: PresetResult[]): PluginOptions;
6
+ declare const LINK_TYPE_NAME = "core.presets.link";
7
+ interface LinkTypeConfig {
8
+ internalTypes: string[];
9
+ }
10
+ declare function linkType(config: LinkTypeConfig): PresetResult;
11
+ export { LINK_TYPE_NAME, type LinkTypeConfig, type PresetResult, linkType, presets };
4
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";iBAEgB,eAAA,CAAA,GAAe,MAAA,CAAA,aAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/composer.ts","../src/presets/link-type/constants.ts","../src/presets/link-type/index.ts"],"mappings":";UAEiB,YAAA;EACf,KAAA,EAAO,oBAAA;AAAA;AAAA,iBCkBO,OAAA,CAAA,GAAW,KAAA,EAAO,YAAA,KAAiB,aAAA;AAAA,cCrBtC,cAAA;AAAA,UCKI,cAAA;EACf,aAAA;AAAA;AAAA,iBAGc,QAAA,CAAS,MAAA,EAAQ,cAAA,GAAiB,YAAA"}
package/dist/index.js CHANGED
@@ -1,10 +1,96 @@
1
- import { definePlugin } from "sanity";
2
- function presetsComposer() {
3
- return definePlugin({
4
- name: "@sanity/presets"
5
- })();
1
+ import { defineType, defineField } from "sanity";
2
+ function collectTypes(presets2) {
3
+ const seen = /* @__PURE__ */ new Set();
4
+ return presets2.flatMap((preset) => preset.types.filter((typeDef) => seen.has(typeDef.name) ? (console.warn(`[@sanity/presets] Dropped duplicate type "${typeDef.name}". Keeping first definition.`), !1) : (seen.add(typeDef.name), !0)));
5
+ }
6
+ function presets(...types) {
7
+ return {
8
+ name: "@sanity/presets",
9
+ schema: {
10
+ types: collectTypes(types)
11
+ }
12
+ };
13
+ }
14
+ const LINK_TYPE_NAME = "core.presets.link";
15
+ function createLinkType(internalTypes) {
16
+ const referenceTargets = internalTypes.map((typeName) => ({
17
+ type: typeName
18
+ }));
19
+ return defineType({
20
+ name: LINK_TYPE_NAME,
21
+ type: "object",
22
+ title: "Link",
23
+ fields: [defineField({
24
+ name: "linkType",
25
+ type: "string",
26
+ title: "Link Type",
27
+ initialValue: "internal",
28
+ options: {
29
+ layout: "radio",
30
+ list: [{
31
+ title: "Internal",
32
+ value: "internal"
33
+ }, {
34
+ title: "External",
35
+ value: "external"
36
+ }]
37
+ }
38
+ }), defineField({
39
+ name: "reference",
40
+ type: "reference",
41
+ title: "Internal Link",
42
+ to: referenceTargets,
43
+ hidden: ({
44
+ parent
45
+ }) => parent?.linkType === "external"
46
+ }), defineField({
47
+ name: "url",
48
+ type: "url",
49
+ title: "URL",
50
+ hidden: ({
51
+ parent
52
+ }) => parent?.linkType === "internal",
53
+ validation: (rule) => rule.uri({
54
+ scheme: ["http", "https", "mailto", "tel"]
55
+ })
56
+ }), defineField({
57
+ name: "openInNewTab",
58
+ type: "boolean",
59
+ title: "Open in New Tab",
60
+ initialValue: !1,
61
+ hidden: ({
62
+ parent
63
+ }) => parent?.linkType === "internal"
64
+ })],
65
+ preview: {
66
+ select: {
67
+ linkType: "linkType",
68
+ url: "url",
69
+ referenceTitle: "reference.title"
70
+ },
71
+ prepare({
72
+ linkType: linkType2,
73
+ url,
74
+ referenceTitle
75
+ }) {
76
+ return {
77
+ title: linkType2 === "external" ? url || "No URL" : referenceTitle || "No reference",
78
+ subtitle: linkType2 === "external" ? "External link" : "Internal link"
79
+ };
80
+ }
81
+ }
82
+ });
83
+ }
84
+ function linkType(config) {
85
+ if (config.internalTypes.length === 0)
86
+ throw new Error("[@sanity/presets] linkType requires at least one internalTypes entry.");
87
+ return {
88
+ types: [createLinkType(config.internalTypes)]
89
+ };
6
90
  }
7
91
  export {
8
- presetsComposer
92
+ LINK_TYPE_NAME,
93
+ linkType,
94
+ presets
9
95
  };
10
96
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import {definePlugin} from 'sanity'\n\nexport function presetsComposer() {\n return definePlugin({\n name: '@sanity/presets',\n })()\n}\n"],"names":["presetsComposer","definePlugin","name"],"mappings":";AAEO,SAASA,kBAAkB;AAChC,SAAOC,aAAa;AAAA,IAClBC,MAAM;AAAA,EAAA,CACP,EAAA;AACH;"}
1
+ {"version":3,"file":"index.js","sources":["../src/composer.ts","../src/presets/link-type/constants.ts","../src/presets/link-type/schema.ts","../src/presets/link-type/index.ts"],"sourcesContent":["import {type PluginOptions, type SchemaTypeDefinition} from 'sanity'\n\nimport type {PresetResult} from './types'\n\nexport function collectTypes(presets: PresetResult[]): SchemaTypeDefinition[] {\n const seen = new Set<string>()\n\n return presets.flatMap((preset) =>\n preset.types.filter((typeDef) => {\n if (seen.has(typeDef.name)) {\n console.warn(\n `[@sanity/presets] Dropped duplicate type \"${typeDef.name}\". Keeping first definition.`,\n )\n return false\n }\n seen.add(typeDef.name)\n return true\n }),\n )\n}\n\nexport function presets(...types: PresetResult[]): PluginOptions {\n return {\n name: '@sanity/presets',\n schema: {types: collectTypes(types)},\n }\n}\n","export const LINK_TYPE_NAME = 'core.presets.link'\n","import {defineField, defineType, type SchemaTypeDefinition} from 'sanity'\n\nimport {LINK_TYPE_NAME} from './constants'\n\nexport function createLinkType(internalTypes: string[]): SchemaTypeDefinition {\n const referenceTargets = internalTypes.map((typeName) => ({type: typeName}))\n\n return defineType({\n name: LINK_TYPE_NAME,\n type: 'object',\n title: 'Link',\n fields: [\n defineField({\n name: 'linkType',\n type: 'string',\n title: 'Link Type',\n initialValue: 'internal',\n options: {\n layout: 'radio',\n list: [\n {title: 'Internal', value: 'internal'},\n {title: 'External', value: 'external'},\n ],\n },\n }),\n defineField({\n name: 'reference',\n type: 'reference',\n title: 'Internal Link',\n to: referenceTargets,\n hidden: ({parent}) => parent?.linkType === 'external',\n }),\n defineField({\n name: 'url',\n type: 'url',\n title: 'URL',\n hidden: ({parent}) => parent?.linkType === 'internal',\n validation: (rule) =>\n rule.uri({\n scheme: ['http', 'https', 'mailto', 'tel'],\n }),\n }),\n defineField({\n name: 'openInNewTab',\n type: 'boolean',\n title: 'Open in New Tab',\n initialValue: false,\n hidden: ({parent}) => parent?.linkType === 'internal',\n }),\n ],\n preview: {\n select: {\n linkType: 'linkType',\n url: 'url',\n referenceTitle: 'reference.title',\n },\n prepare({linkType, url, referenceTitle}) {\n const title = linkType === 'external' ? url || 'No URL' : referenceTitle || 'No reference'\n\n return {\n title,\n subtitle: linkType === 'external' ? 'External link' : 'Internal link',\n }\n },\n },\n })\n}\n","import type {PresetResult} from '../../types'\nimport {createLinkType} from './schema'\n\nexport {LINK_TYPE_NAME} from './constants'\n\nexport interface LinkTypeConfig {\n internalTypes: string[]\n}\n\nexport function linkType(config: LinkTypeConfig): PresetResult {\n if (config.internalTypes.length === 0) {\n throw new Error('[@sanity/presets] linkType requires at least one internalTypes entry.')\n }\n\n return {\n types: [createLinkType(config.internalTypes)],\n }\n}\n"],"names":["collectTypes","presets","seen","Set","flatMap","preset","types","filter","typeDef","has","name","console","warn","add","schema","LINK_TYPE_NAME","createLinkType","internalTypes","referenceTargets","map","typeName","type","defineType","title","fields","defineField","initialValue","options","layout","list","value","to","hidden","parent","linkType","validation","rule","uri","scheme","preview","select","url","referenceTitle","prepare","subtitle","config","length","Error"],"mappings":";AAIO,SAASA,aAAaC,UAAiD;AAC5E,QAAMC,2BAAWC,IAAAA;AAEjB,SAAOF,SAAQG,QAASC,CAAAA,WACtBA,OAAOC,MAAMC,OAAQC,CAAAA,YACfN,KA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C1C;AAAA,IAAA,CACJ,GACDb,YAAY;AAAA,MACVf,MAAM;AAAA,MACNW,MAAM;AAAA,MACNE,OAAO;AAAA,MACPG,cAAc;AAAA,MACdM,QAAQA,CAAC;AAAA,QAACC;AAAAA,MAAAA,MAAYA,QAAQC,aAAa;AAAA,IAAA,CAC5C,CAAC;AAAA,IAEJK,SAAS;AAAA,MACPC,QAAQ;AAAA,QACNN,UAAU;AAAA,QACVO,KAAK;AAAA,QACLC,gBAAgB;AAAA,MAAA;AAAA,MAElBC,QAAQ;AAAA,QAACT,UAAAA;AAAAA,QAAUO;AAAAA,QAAKC;AAAAA,MAAAA,GAAiB;AAGvC,eAAO;AAAA,UACLnB,OAHYW,cAAa,aAAaO,OAAO,WAAWC,kBAAkB;AAAA,UAI1EE,UAAUV,cAAa,aAAa,kBAAkB;AAAA,QAAA;AAAA,MAE1D;AAAA,IAAA;AAAA,EACF,CACD;AACH;ACzDO,SAASA,SAASW,QAAsC;AAC7D,MAAIA,OAAO5B,cAAc6B,WAAW;AAClC,UAAM,IAAIC,MAAM,uEAAuE;AAGzF,SAAO;AAAA,IACLzC,OAAO,CAACU,eAAe6B,OAAO5B,aAAa,CAAC;AAAA,EAAA;AAEhD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/presets",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Production ready preset patterns for Sanity Studio",
5
5
  "keywords": [
6
6
  "sanity",
@@ -27,8 +27,8 @@
27
27
  "./package.json": "./package.json"
28
28
  },
29
29
  "devDependencies": {
30
- "@sanity/pkg-utils": "^10.4.9",
31
- "sanity": "^5.16.0",
30
+ "@sanity/pkg-utils": "^10.4.11",
31
+ "sanity": "^5.17.1",
32
32
  "@repo/package.config": "0.0.0",
33
33
  "@repo/tsconfig": "0.0.0"
34
34
  },