@portabletext/editor 1.44.12 → 1.44.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.44.12",
3
+ "version": "1.44.13",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -93,10 +93,10 @@
93
93
  "@types/debug": "^4.1.12",
94
94
  "@types/lodash": "^4.17.13",
95
95
  "@types/lodash.startcase": "^4.4.9",
96
- "@types/react": "^19.0.12",
97
- "@types/react-dom": "^19.0.4",
98
- "@typescript-eslint/eslint-plugin": "^8.26.1",
99
- "@typescript-eslint/parser": "^8.26.1",
96
+ "@types/react": "^19.1.0",
97
+ "@types/react-dom": "^19.1.1",
98
+ "@typescript-eslint/eslint-plugin": "^8.29.0",
99
+ "@typescript-eslint/parser": "^8.29.0",
100
100
  "@vitejs/plugin-react": "^4.3.4",
101
101
  "@vitest/browser": "^3.1.1",
102
102
  "@vitest/coverage-istanbul": "^3.1.1",
@@ -109,7 +109,7 @@
109
109
  "react-dom": "^19.1.0",
110
110
  "rxjs": "^7.8.2",
111
111
  "typescript": "5.8.2",
112
- "vite": "^6.2.0",
112
+ "vite": "^6.2.5",
113
113
  "vitest": "^3.1.1",
114
114
  "vitest-browser-react": "^0.1.1",
115
115
  "racejar": "1.2.3"
@@ -3,6 +3,7 @@ import {defineField, defineType, type ObjectSchemaType} from '@sanity/types'
3
3
  import startCase from 'lodash.startcase'
4
4
  import type {PortableTextMemberSchemaTypes} from '../types/editor'
5
5
  import {createEditorSchema} from './create-editor-schema'
6
+ import {defaultKeyGenerator} from './key-generator'
6
7
 
7
8
  /**
8
9
  * @public
@@ -55,6 +56,24 @@ export function defineSchema<const TSchemaDefinition extends SchemaDefinition>(
55
56
  return definition
56
57
  }
57
58
 
59
+ const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`
60
+ const temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`
61
+
62
+ const temporaryObjectNames: Record<string, string> = {
63
+ image: temporaryImageName,
64
+ url: temporaryUrlName,
65
+ }
66
+
67
+ const objectNames: Record<string, string> = {
68
+ [temporaryImageName]: 'image',
69
+ [temporaryUrlName]: 'url',
70
+ }
71
+
72
+ const defaultObjectTitles: Record<string, string> = {
73
+ image: 'Image',
74
+ url: 'URL',
75
+ }
76
+
58
77
  /**
59
78
  * @public
60
79
  */
@@ -68,21 +87,30 @@ export function compileSchemaDefinition<
68
87
  defineType({
69
88
  type: 'object',
70
89
  // Very naive way to work around `SanitySchema.compile` adding default
71
- // fields to objects with the name `image`
72
- name: blockObject.name === 'image' ? 'tmp-image' : blockObject.name,
90
+ // fields to objects with certain names.
91
+ name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
73
92
  title:
74
- blockObject.name === 'image' && blockObject.title === undefined
75
- ? 'Image'
93
+ blockObject.title === undefined
94
+ ? // This avoids the default title which is a title case of the object name
95
+ defaultObjectTitles[blockObject.name]
76
96
  : blockObject.title,
77
97
  fields: [],
78
98
  }),
79
99
  ) ?? []
100
+
80
101
  const inlineObjects =
81
102
  definition?.inlineObjects?.map((inlineObject) =>
82
103
  defineType({
83
104
  type: 'object',
84
- name: inlineObject.name,
85
- title: inlineObject.title,
105
+ // Very naive way to work around `SanitySchema.compile` adding default
106
+ // fields to objects with certain names.
107
+ name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
108
+
109
+ title:
110
+ inlineObject.title === undefined
111
+ ? // This avoids the default title which is a title case of the object name
112
+ defaultObjectTitles[inlineObject.name]
113
+ : inlineObject.title,
86
114
  fields: [],
87
115
  }),
88
116
  ) ?? []
@@ -132,16 +160,24 @@ export function compileSchemaDefinition<
132
160
  return {
133
161
  ...pteSchema,
134
162
  blockObjects: pteSchema.blockObjects.map((blockObject) =>
135
- blockObject.name === 'tmp-image'
163
+ objectNames[blockObject.name] !== undefined
136
164
  ? ({
137
165
  ...blockObject,
138
- name: 'image',
166
+ name: objectNames[blockObject.name],
139
167
  type: {
140
168
  ...blockObject.type,
141
- name: 'image',
169
+ name: objectNames[blockObject.name],
142
170
  },
143
171
  } as ObjectSchemaType)
144
172
  : blockObject,
145
173
  ),
174
+ inlineObjects: pteSchema.inlineObjects.map((inlineObject) =>
175
+ objectNames[inlineObject.name] !== undefined
176
+ ? ({
177
+ ...inlineObject,
178
+ name: objectNames[inlineObject.name],
179
+ } as ObjectSchemaType)
180
+ : inlineObject,
181
+ ),
146
182
  } satisfies EditorSchema
147
183
  }