@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.
@@ -56,21 +56,58 @@ function resolveEnabledListItems(blockType) {
56
56
  function findBlockType(type) {
57
57
  return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
58
58
  }
59
+ const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
60
+ let table;
61
+ return () => {
62
+ if (table)
63
+ return table;
64
+ table = [];
65
+ for (let i = 0; i < 256; ++i)
66
+ table[i] = (i + 256).toString(16).slice(1);
67
+ return table;
68
+ };
69
+ })();
70
+ function whatwgRNG(length = 16) {
71
+ const rnds8 = new Uint8Array(length);
72
+ return getRandomValues__default.default(rnds8), rnds8;
73
+ }
74
+ function randomKey(length) {
75
+ const table = getByteHexTable();
76
+ return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
77
+ }
59
78
  function defineSchema(definition) {
60
79
  return definition;
61
80
  }
81
+ const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
82
+ image: temporaryImageName,
83
+ url: temporaryUrlName
84
+ }, objectNames = {
85
+ [temporaryImageName]: "image",
86
+ [temporaryUrlName]: "url"
87
+ }, defaultObjectTitles = {
88
+ image: "Image",
89
+ url: "URL"
90
+ };
62
91
  function compileSchemaDefinition(definition) {
63
92
  const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
64
93
  type: "object",
65
94
  // Very naive way to work around `SanitySchema.compile` adding default
66
- // fields to objects with the name `image`
67
- name: blockObject.name === "image" ? "tmp-image" : blockObject.name,
68
- title: blockObject.name === "image" && blockObject.title === void 0 ? "Image" : blockObject.title,
95
+ // fields to objects with certain names.
96
+ name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
97
+ title: blockObject.title === void 0 ? (
98
+ // This avoids the default title which is a title case of the object name
99
+ defaultObjectTitles[blockObject.name]
100
+ ) : blockObject.title,
69
101
  fields: []
70
102
  })) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
71
103
  type: "object",
72
- name: inlineObject.name,
73
- title: inlineObject.title,
104
+ // Very naive way to work around `SanitySchema.compile` adding default
105
+ // fields to objects with certain names.
106
+ name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
107
+ title: inlineObject.title === void 0 ? (
108
+ // This avoids the default title which is a title case of the object name
109
+ defaultObjectTitles[inlineObject.name]
110
+ ) : inlineObject.title,
74
111
  fields: []
75
112
  })) ?? [], portableTextSchema = types.defineField({
76
113
  type: "array",
@@ -108,14 +145,18 @@ function compileSchemaDefinition(definition) {
108
145
  }).get("portable-text"), pteSchema = createEditorSchema(schema$1);
109
146
  return {
110
147
  ...pteSchema,
111
- blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
148
+ blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
112
149
  ...blockObject,
113
- name: "image",
150
+ name: objectNames[blockObject.name],
114
151
  type: {
115
152
  ...blockObject.type,
116
- name: "image"
153
+ name: objectNames[blockObject.name]
117
154
  }
118
- } : blockObject)
155
+ } : blockObject),
156
+ inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
157
+ ...inlineObject,
158
+ name: objectNames[inlineObject.name]
159
+ } : inlineObject)
119
160
  };
120
161
  }
121
162
  const rootName = "sanity-pte:";
@@ -1627,25 +1668,6 @@ function isRedoing(editor) {
1627
1668
  function setIsRedoing(editor, isRedoing2) {
1628
1669
  IS_REDOING.set(editor, isRedoing2);
1629
1670
  }
1630
- const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
1631
- let table;
1632
- return () => {
1633
- if (table)
1634
- return table;
1635
- table = [];
1636
- for (let i = 0; i < 256; ++i)
1637
- table[i] = (i + 256).toString(16).slice(1);
1638
- return table;
1639
- };
1640
- })();
1641
- function whatwgRNG(length = 16) {
1642
- const rnds8 = new Uint8Array(length);
1643
- return getRandomValues__default.default(rnds8), rnds8;
1644
- }
1645
- function randomKey(length) {
1646
- const table = getByteHexTable();
1647
- return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
1648
- }
1649
1671
  const CURRENT_ACTION_ID = /* @__PURE__ */ new WeakMap();
1650
1672
  function withApplyingBehaviorActions(editor, fn) {
1651
1673
  CURRENT_ACTION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_ACTION_ID.set(editor, void 0);