@portabletext/editor 2.3.2 → 2.3.4

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.
Files changed (38) hide show
  1. package/lib/_chunks-dts/behavior.types.action.d.cts +5 -142
  2. package/lib/_chunks-dts/behavior.types.action.d.ts +55 -192
  3. package/lib/index.cjs +43 -279
  4. package/lib/index.cjs.map +1 -1
  5. package/lib/index.js +5 -245
  6. package/lib/index.js.map +1 -1
  7. package/lib/utils/index.d.cts +2 -2
  8. package/lib/utils/index.d.ts +2 -2
  9. package/package.json +7 -5
  10. package/src/converters/converter.portable-text.deserialize.test.ts +6 -4
  11. package/src/converters/converter.text-html.deserialize.test.ts +15 -15
  12. package/src/converters/converter.text-html.serialize.test.ts +8 -8
  13. package/src/converters/converter.text-plain.test.ts +8 -8
  14. package/src/editor/create-editor.ts +12 -10
  15. package/src/editor/editor-schema.ts +2 -312
  16. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +2 -2
  17. package/src/editor.ts +1 -1
  18. package/src/index.ts +3 -3
  19. package/src/internal-utils/__tests__/values.test.ts +2 -3
  20. package/src/internal-utils/apply-operation-to-portable-text.test.ts +2 -3
  21. package/src/internal-utils/build-index-maps.test.ts +2 -3
  22. package/src/internal-utils/create-test-snapshot.ts +2 -4
  23. package/src/internal-utils/drag-selection.test.ts +2 -5
  24. package/src/internal-utils/operation-to-patches.test.ts +5 -7
  25. package/src/internal-utils/parse-blocks.test.ts +21 -30
  26. package/src/internal-utils/selection-text.ts +2 -3
  27. package/src/internal-utils/terse-pt.test.ts +2 -3
  28. package/src/internal-utils/test-editor.tsx +1 -4
  29. package/src/internal-utils/to-slate-range.test.ts +2 -3
  30. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +1 -1
  31. package/src/plugins/plugin.markdown.test.tsx +1 -1
  32. package/src/selectors/selector.get-selection-text.test.ts +2 -3
  33. package/src/selectors/selector.get-trimmed-selection.test.ts +2 -3
  34. package/src/utils/util.block-offset.test.ts +2 -3
  35. package/src/utils/util.slice-blocks.test.ts +2 -3
  36. package/src/utils/util.slice-text-block.test.ts +2 -3
  37. package/src/editor/editor-schema-definition.ts +0 -105
  38. package/src/editor/legacy-schema.ts +0 -115
package/lib/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), isEqual = require("lodash/isEqual.js"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), types = require("@sanity/types"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
3
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), isEqual = require("lodash/isEqual.js"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), sanityBridge = require("@portabletext/sanity-bridge"), schema = require("@portabletext/schema"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema$1 = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), isPlainObject = require("lodash/isPlainObject.js");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$f), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
7
+ var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$f), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
8
8
  function EditorEventListener(props) {
9
9
  const $ = reactCompilerRuntime.c(4), editor = useEditor.useEditor();
10
10
  let t0, t1;
@@ -1282,7 +1282,7 @@ function createCoreConverters(legacySchema) {
1282
1282
  return [converterJson, converterPortableText, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
1283
1283
  }
1284
1284
  function compileType(rawType) {
1285
- return schema.Schema.compile({
1285
+ return schema$1.Schema.compile({
1286
1286
  name: "blockTypeSchema",
1287
1287
  types: [rawType]
1288
1288
  }).get(rawType.name);
@@ -8444,245 +8444,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
8444
8444
  }
8445
8445
  }
8446
8446
  }
8447
- });
8448
- function createLegacySchema(portableTextType) {
8449
- if (!portableTextType)
8450
- throw new Error("Parameter 'portabletextType' missing (required)");
8451
- const blockType = portableTextType.of?.find(findBlockType);
8452
- if (!blockType)
8453
- throw new Error("Block type is not defined in this schema (required)");
8454
- const childrenField = blockType.fields?.find((field) => field.name === "children");
8455
- if (!childrenField)
8456
- throw new Error("Children field for block type found in schema (required)");
8457
- const ofType = childrenField.type.of;
8458
- if (!ofType)
8459
- throw new Error("Valid types for block children not found in schema (required)");
8460
- const spanType = ofType.find((memberType) => memberType.name === "span");
8461
- if (!spanType)
8462
- throw new Error("Span type not found in schema (required)");
8463
- const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
8464
- return {
8465
- styles: resolveEnabledStyles(blockType),
8466
- decorators: resolveEnabledDecorators(spanType),
8467
- lists: resolveEnabledListItems(blockType),
8468
- block: blockType,
8469
- span: spanType,
8470
- portableText: portableTextType,
8471
- inlineObjects: inlineObjectTypes,
8472
- blockObjects: blockObjectTypes,
8473
- annotations: spanType.annotations
8474
- };
8475
- }
8476
- function resolveEnabledStyles(blockType) {
8477
- const styleField = blockType.fields?.find((btField) => btField.name === "style");
8478
- if (!styleField)
8479
- throw new Error("A field with name 'style' is not defined in the block type (required).");
8480
- const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
8481
- if (!textStyles || textStyles.length === 0)
8482
- throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
8483
- return textStyles;
8484
- }
8485
- function resolveEnabledDecorators(spanType) {
8486
- return spanType.decorators;
8487
- }
8488
- function resolveEnabledListItems(blockType) {
8489
- const listField = blockType.fields?.find((btField) => btField.name === "listItem");
8490
- if (!listField)
8491
- throw new Error("A field with name 'listItem' is not defined in the block type (required).");
8492
- const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
8493
- if (!listItems)
8494
- throw new Error("The list field need at least to be an empty array");
8495
- return listItems;
8496
- }
8497
- function findBlockType(type) {
8498
- return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
8499
- }
8500
- const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
8501
- image: temporaryImageName,
8502
- url: temporaryUrlName
8503
- }, objectNames = {
8504
- [temporaryImageName]: "image",
8505
- [temporaryUrlName]: "url"
8506
- }, defaultObjectTitles = {
8507
- image: "Image",
8508
- url: "URL"
8509
- };
8510
- function legacySchemaToEditorSchema(schema2) {
8511
- return {
8512
- annotations: schema2.annotations.map((annotation) => ({
8513
- name: annotation.name,
8514
- fields: annotation.fields.map((field) => ({
8515
- name: field.name,
8516
- type: field.type.jsonType,
8517
- title: field.type.title
8518
- })),
8519
- title: annotation.title
8520
- })),
8521
- block: {
8522
- name: schema2.block.name
8523
- },
8524
- blockObjects: schema2.blockObjects.map((blockObject) => ({
8525
- name: blockObject.name,
8526
- fields: blockObject.fields.map((field) => ({
8527
- name: field.name,
8528
- type: field.type.jsonType,
8529
- title: field.type.title
8530
- })),
8531
- title: blockObject.title
8532
- })),
8533
- decorators: schema2.decorators.map((decorator) => ({
8534
- name: decorator.value,
8535
- title: decorator.title,
8536
- value: decorator.value
8537
- })),
8538
- inlineObjects: schema2.inlineObjects.map((inlineObject) => ({
8539
- name: inlineObject.name,
8540
- fields: inlineObject.fields.map((field) => ({
8541
- name: field.name,
8542
- type: field.type.jsonType,
8543
- title: field.type.title
8544
- })),
8545
- title: inlineObject.title
8546
- })),
8547
- span: {
8548
- name: schema2.span.name
8549
- },
8550
- styles: schema2.styles.map((style) => ({
8551
- name: style.value,
8552
- title: style.title,
8553
- value: style.value
8554
- })),
8555
- lists: schema2.lists.map((list) => ({
8556
- name: list.value,
8557
- title: list.title,
8558
- value: list.value
8559
- }))
8560
- };
8561
- }
8562
- function compileSchemaDefinition(definition) {
8563
- const styles = (definition.styles ?? []).map((style) => ({
8564
- ...style,
8565
- value: style.name
8566
- }));
8567
- return {
8568
- block: {
8569
- name: "block"
8570
- },
8571
- span: {
8572
- name: "span"
8573
- },
8574
- styles: styles.some((style) => style.value === "normal") ? styles : [{
8575
- value: "normal",
8576
- name: "normal",
8577
- title: "Normal"
8578
- }, ...styles],
8579
- lists: (definition.lists ?? []).map((list) => ({
8580
- ...list,
8581
- value: list.name
8582
- })),
8583
- decorators: (definition.decorators ?? []).map((decorator) => ({
8584
- ...decorator,
8585
- value: decorator.name
8586
- })),
8587
- annotations: (definition.annotations ?? []).map((annotation) => ({
8588
- ...annotation,
8589
- fields: annotation.fields ?? []
8590
- })),
8591
- blockObjects: (definition.blockObjects ?? []).map((blockObject) => ({
8592
- ...blockObject,
8593
- fields: blockObject.fields ?? []
8594
- })),
8595
- inlineObjects: (definition.inlineObjects ?? []).map((inlineObject) => ({
8596
- ...inlineObject,
8597
- fields: inlineObject.fields ?? []
8598
- }))
8599
- };
8600
- }
8601
- function compileSchemaDefinitionToLegacySchema(definition) {
8602
- const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
8603
- type: "object",
8604
- // Very naive way to work around `SanitySchema.compile` adding default
8605
- // fields to objects with certain names.
8606
- name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
8607
- title: blockObject.title === void 0 ? (
8608
- // This avoids the default title which is a title case of the object name
8609
- defaultObjectTitles[blockObject.name]
8610
- ) : blockObject.title,
8611
- fields: blockObject.fields?.map((field) => ({
8612
- name: field.name,
8613
- type: field.type,
8614
- title: field.title ?? startCase__default.default(field.name)
8615
- })) ?? []
8616
- })) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
8617
- type: "object",
8618
- // Very naive way to work around `SanitySchema.compile` adding default
8619
- // fields to objects with certain names.
8620
- name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
8621
- title: inlineObject.title === void 0 ? (
8622
- // This avoids the default title which is a title case of the object name
8623
- defaultObjectTitles[inlineObject.name]
8624
- ) : inlineObject.title,
8625
- fields: inlineObject.fields?.map((field) => ({
8626
- name: field.name,
8627
- type: field.type,
8628
- title: field.title ?? startCase__default.default(field.name)
8629
- })) ?? []
8630
- })) ?? [], portableTextSchema = types.defineField({
8631
- type: "array",
8632
- name: "portable-text",
8633
- of: [...blockObjects.map((blockObject) => ({
8634
- type: blockObject.name
8635
- })), {
8636
- type: "block",
8637
- name: "block",
8638
- of: inlineObjects.map((inlineObject) => ({
8639
- type: inlineObject.name
8640
- })),
8641
- marks: {
8642
- decorators: definition?.decorators?.map((decorator) => ({
8643
- title: decorator.title ?? startCase__default.default(decorator.name),
8644
- value: decorator.name
8645
- })) ?? [],
8646
- annotations: definition?.annotations?.map((annotation) => ({
8647
- name: annotation.name,
8648
- type: "object",
8649
- title: annotation.title,
8650
- fields: annotation.fields?.map((field) => ({
8651
- name: field.name,
8652
- title: field.title ?? startCase__default.default(field.name),
8653
- type: field.type
8654
- })) ?? []
8655
- })) ?? []
8656
- },
8657
- lists: definition?.lists?.map((list) => ({
8658
- value: list.name,
8659
- title: list.title ?? startCase__default.default(list.name)
8660
- })) ?? [],
8661
- styles: definition?.styles?.map((style) => ({
8662
- value: style.name,
8663
- title: style.title ?? startCase__default.default(style.name)
8664
- })) ?? []
8665
- }]
8666
- }), schema$1 = schema.Schema.compile({
8667
- types: [portableTextSchema, ...blockObjects, ...inlineObjects]
8668
- }).get("portable-text"), pteSchema = createLegacySchema(schema$1);
8669
- return {
8670
- ...pteSchema,
8671
- blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
8672
- ...blockObject,
8673
- name: objectNames[blockObject.name],
8674
- type: {
8675
- ...blockObject.type,
8676
- name: objectNames[blockObject.name]
8677
- }
8678
- } : blockObject),
8679
- inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
8680
- ...inlineObject,
8681
- name: objectNames[inlineObject.name]
8682
- } : inlineObject)
8683
- };
8684
- }
8685
- const debug$6 = debugWithName("mutation-machine"), mutationMachine = xstate.setup({
8447
+ }), debug$6 = debugWithName("mutation-machine"), mutationMachine = xstate.setup({
8686
8448
  types: {
8687
8449
  context: {},
8688
8450
  events: {},
@@ -8915,7 +8677,7 @@ const debug$6 = debugWithName("mutation-machine"), mutationMachine = xstate.setu
8915
8677
  }
8916
8678
  }), debug$5 = debugWithName("API:editable");
8917
8679
  function createEditableAPI(editor, editorActor) {
8918
- const types2 = editorActor.getSnapshot().context.schema;
8680
+ const types = editorActor.getSnapshot().context.schema;
8919
8681
  return {
8920
8682
  focus: () => {
8921
8683
  editorActor.send({
@@ -9006,18 +8768,18 @@ function createEditableAPI(editor, editorActor) {
9006
8768
  if (editor.selection) {
9007
8769
  const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
9008
8770
  if (block)
9009
- return fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
8771
+ return fromSlateValue([block], types.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
9010
8772
  }
9011
8773
  },
9012
8774
  focusChild: () => {
9013
8775
  if (editor.selection) {
9014
8776
  const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
9015
8777
  if (block && editor.isTextBlock(block))
9016
- return fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0].children[editor.selection.focus.path[1]];
8778
+ return fromSlateValue([block], types.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0].children[editor.selection.focus.path[1]];
9017
8779
  }
9018
8780
  },
9019
8781
  insertChild: (type, value) => {
9020
- if (type.name !== types2.span.name)
8782
+ if (type.name !== types.span.name)
9021
8783
  return editorActor.send({
9022
8784
  type: "behavior event",
9023
8785
  behaviorEvent: {
@@ -9037,15 +8799,15 @@ function createEditableAPI(editor, editorActor) {
9037
8799
  throw new Error("The editor has no selection");
9038
8800
  const [focusBlock] = Array.from(slate.Editor.nodes(editor, {
9039
8801
  at: editor.selection.focus.path.slice(0, 1),
9040
- match: (n) => n._type === types2.block.name
8802
+ match: (n) => n._type === types.block.name
9041
8803
  }))[0] || [void 0];
9042
8804
  if (!focusBlock)
9043
8805
  throw new Error("No focused text block");
9044
- if (type.name !== types2.span.name && !types2.inlineObjects.some((t) => t.name === type.name))
8806
+ if (type.name !== types.span.name && !types.inlineObjects.some((t) => t.name === type.name))
9045
8807
  throw new Error("This type cannot be inserted as a child to a text block");
9046
8808
  const child = toSlateValue([{
9047
8809
  _key: editorActor.getSnapshot().context.keyGenerator(),
9048
- _type: types2.block.name,
8810
+ _type: types.block.name,
9049
8811
  children: [{
9050
8812
  _key: editorActor.getSnapshot().context.keyGenerator(),
9051
8813
  _type: type.name,
@@ -9053,8 +8815,8 @@ function createEditableAPI(editor, editorActor) {
9053
8815
  }]
9054
8816
  }], {
9055
8817
  schemaTypes: editorActor.getSnapshot().context.schema
9056
- })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
9057
- return isSpanNode2 && focusNode._type !== types2.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
8818
+ })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types.span.name, focusNode = slate.Node.get(editor, focusChildPath);
8819
+ return isSpanNode2 && focusNode._type !== types.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
9058
8820
  distance: 1,
9059
8821
  unit: "character"
9060
8822
  })), slate.Transforms.insertNodes(editor, child, {
@@ -9102,7 +8864,7 @@ function createEditableAPI(editor, editorActor) {
9102
8864
  return !1;
9103
8865
  }
9104
8866
  },
9105
- isVoid: (element) => ![types2.block.name, types2.span.name].includes(element._type),
8867
+ isVoid: (element) => ![types.block.name, types.span.name].includes(element._type),
9106
8868
  findByPath: (path) => {
9107
8869
  const slatePath = toSlateRange({
9108
8870
  context: {
@@ -9125,10 +8887,10 @@ function createEditableAPI(editor, editorActor) {
9125
8887
  const [block, blockPath] = slate.Editor.node(editor, slatePath.focus.path.slice(0, 1));
9126
8888
  if (block && blockPath && typeof block._key == "string") {
9127
8889
  if (path.length === 1 && slatePath.focus.path.length === 1)
9128
- return [fromSlateValue([block], types2.block.name)[0], [{
8890
+ return [fromSlateValue([block], types.block.name)[0], [{
9129
8891
  _key: block._key
9130
8892
  }]];
9131
- const ptBlock = fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
8893
+ const ptBlock = fromSlateValue([block], types.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
9132
8894
  if (editor.isTextBlock(ptBlock)) {
9133
8895
  const ptChild = ptBlock.children[slatePath.focus.path[1]];
9134
8896
  if (ptChild)
@@ -9188,7 +8950,7 @@ function createEditableAPI(editor, editorActor) {
9188
8950
  paths = addAnnotationOperationImplementation({
9189
8951
  context: {
9190
8952
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
9191
- schema: types2
8953
+ schema: types
9192
8954
  },
9193
8955
  operation: {
9194
8956
  annotation: {
@@ -9228,7 +8990,7 @@ function createEditableAPI(editor, editorActor) {
9228
8990
  })), options?.mode === "children" && (debug$5("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
9229
8991
  at: range,
9230
8992
  voids: !0,
9231
- match: (node) => node._type === types2.span.name || // Text children
8993
+ match: (node) => node._type === types.span.name || // Text children
9232
8994
  !editor.isTextBlock(node) && slate.Element.isElement(node)
9233
8995
  })), editor.children.length === 0) {
9234
8996
  const placeholderBlock = createPlaceholderBlock(editorActor.getSnapshot().context);
@@ -9270,13 +9032,13 @@ function createEditableAPI(editor, editorActor) {
9270
9032
  }
9271
9033
  return ptRange;
9272
9034
  },
9273
- getValue: () => fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
9035
+ getValue: () => fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
9274
9036
  isCollapsedSelection: () => !!editor.selection && slate.Range.isCollapsed(editor.selection),
9275
9037
  isExpandedSelection: () => !!editor.selection && slate.Range.isExpanded(editor.selection),
9276
9038
  insertBreak: () => {
9277
9039
  editor.insertBreak(), editor.onChange();
9278
9040
  },
9279
- getFragment: () => fromSlateValue(editor.getFragment(), types2.block.name),
9041
+ getFragment: () => fromSlateValue(editor.getFragment(), types.block.name),
9280
9042
  isSelectionsOverlapping: (selectionA, selectionB) => {
9281
9043
  const rangeA = toSlateRange({
9282
9044
  context: {
@@ -9354,9 +9116,9 @@ const relayMachine = xstate.setup({
9354
9116
  }
9355
9117
  }
9356
9118
  });
9357
- function validateValue(value, types2, keyGenerator) {
9119
+ function validateValue(value, types, keyGenerator) {
9358
9120
  let resolution = null, valid = !0;
9359
- const validChildTypes = [types2.span.name, ...types2.inlineObjects.map((t) => t.name)], validBlockTypes = [types2.block.name, ...types2.blockObjects.map((t) => t.name)];
9121
+ const validChildTypes = [types.span.name, ...types.inlineObjects.map((t) => t.name)], validBlockTypes = [types.block.name, ...types.blockObjects.map((t) => t.name)];
9360
9122
  return value === void 0 ? {
9361
9123
  valid: !0,
9362
9124
  resolution: null,
@@ -9408,7 +9170,7 @@ function validateValue(value, types2, keyGenerator) {
9408
9170
  }, !0;
9409
9171
  if (!blk._type || !validBlockTypes.includes(blk._type)) {
9410
9172
  if (blk._type === "block") {
9411
- const currentBlockTypeName = types2.block.name;
9173
+ const currentBlockTypeName = types.block.name;
9412
9174
  return resolution = {
9413
9175
  patches: [patches.set({
9414
9176
  ...blk,
@@ -9430,26 +9192,26 @@ function validateValue(value, types2, keyGenerator) {
9430
9192
  }, !0;
9431
9193
  }
9432
9194
  return !blk._type && util_sliceBlocks.isTextBlock({
9433
- schema: types2
9195
+ schema: types
9434
9196
  }, {
9435
9197
  ...blk,
9436
- _type: types2.block.name
9198
+ _type: types.block.name
9437
9199
  }) ? (resolution = {
9438
9200
  patches: [patches.set({
9439
9201
  ...blk,
9440
- _type: types2.block.name
9202
+ _type: types.block.name
9441
9203
  }, [{
9442
9204
  _key: blk._key
9443
9205
  }])],
9444
- description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types2.block.name}'`,
9445
- action: `Use type '${types2.block.name}'`,
9206
+ description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types.block.name}'`,
9207
+ action: `Use type '${types.block.name}'`,
9446
9208
  item: blk,
9447
9209
  i18n: {
9448
9210
  description: "inputs.portable-text.invalid-value.missing-block-type.description",
9449
9211
  action: "inputs.portable-text.invalid-value.missing-block-type.action",
9450
9212
  values: {
9451
9213
  key: blk._key,
9452
- expectedTypeName: types2.block.name
9214
+ expectedTypeName: types.block.name
9453
9215
  }
9454
9216
  }
9455
9217
  }, !0) : blk._type ? (resolution = {
@@ -9483,7 +9245,7 @@ function validateValue(value, types2, keyGenerator) {
9483
9245
  }
9484
9246
  }, !0);
9485
9247
  }
9486
- if (blk._type === types2.block.name) {
9248
+ if (blk._type === types.block.name) {
9487
9249
  const textBlock = blk;
9488
9250
  if (textBlock.children && !Array.isArray(textBlock.children))
9489
9251
  return resolution = {
@@ -9505,7 +9267,7 @@ function validateValue(value, types2, keyGenerator) {
9505
9267
  }, !0;
9506
9268
  if (textBlock.children === void 0 || Array.isArray(textBlock.children) && textBlock.children.length === 0) {
9507
9269
  const newSpan = {
9508
- _type: types2.span.name,
9270
+ _type: types.span.name,
9509
9271
  _key: keyGenerator(),
9510
9272
  text: "",
9511
9273
  marks: []
@@ -9529,7 +9291,7 @@ function validateValue(value, types2, keyGenerator) {
9529
9291
  }
9530
9292
  }, !0;
9531
9293
  }
9532
- const allUsedMarks = uniq__default.default(flatten__default.default(textBlock.children.filter((cld) => cld._type === types2.span.name).map((cld) => cld.marks || [])));
9294
+ const allUsedMarks = uniq__default.default(flatten__default.default(textBlock.children.filter((cld) => cld._type === types.span.name).map((cld) => cld.marks || [])));
9533
9295
  if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
9534
9296
  const unusedMarkDefs = uniq__default.default(blk.markDefs.map((def) => def._key).filter((key) => !allUsedMarks.includes(key)));
9535
9297
  if (unusedMarkDefs.length > 0)
@@ -9553,9 +9315,9 @@ function validateValue(value, types2, keyGenerator) {
9553
9315
  }
9554
9316
  }, !0;
9555
9317
  }
9556
- const orphanedMarks = allUsedMarks.filter((mark) => !types2.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark));
9318
+ const orphanedMarks = allUsedMarks.filter((mark) => !types.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark));
9557
9319
  if (orphanedMarks.length > 0) {
9558
- const spanChildren = textBlock.children.filter((cld) => cld._type === types2.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
9320
+ const spanChildren = textBlock.children.filter((cld) => cld._type === types.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
9559
9321
  if (spanChildren) {
9560
9322
  const orphaned = orphanedMarks.join(", ");
9561
9323
  return resolution = {
@@ -9620,7 +9382,7 @@ function validateValue(value, types2, keyGenerator) {
9620
9382
  }
9621
9383
  }, !0;
9622
9384
  }
9623
- return child._type ? validChildTypes.includes(child._type) ? child._type === types2.span.name && typeof child.text != "string" ? (resolution = {
9385
+ return child._type ? validChildTypes.includes(child._type) ? child._type === types.span.name && typeof child.text != "string" ? (resolution = {
9624
9386
  patches: [patches.set({
9625
9387
  ...child,
9626
9388
  text: ""
@@ -10320,10 +10082,10 @@ function editorConfigToMachineInput(config) {
10320
10082
  };
10321
10083
  }
10322
10084
  function compileSchemasFromEditorConfig(config) {
10323
- const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), schema2 = config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : legacySchemaToEditorSchema(legacySchema);
10085
+ const legacySchema = config.schemaDefinition ? sanityBridge.compileSchemaDefinitionToPortableTextMemberSchemaTypes(config.schemaDefinition) : sanityBridge.createPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), schema$12 = config.schemaDefinition ? schema.compileSchema(config.schemaDefinition) : sanityBridge.portableTextMemberSchemaTypesToSchema(legacySchema);
10324
10086
  return {
10325
10087
  legacySchema,
10326
- schema: schema2
10088
+ schema: schema$12
10327
10089
  };
10328
10090
  }
10329
10091
  function createActors(config) {
@@ -12082,9 +11844,6 @@ function EditorProvider(props) {
12082
11844
  let t7;
12083
11845
  return $[25] !== internalEditor_0.editor || $[26] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(useEditor.EditorContext.Provider, { value: internalEditor_0.editor, children: t6 }), $[25] = internalEditor_0.editor, $[26] = t6, $[27] = t7) : t7 = $[27], t7;
12084
11846
  }
12085
- function defineSchema(definition) {
12086
- return definition;
12087
- }
12088
11847
  const usePortableTextEditorSelection = () => {
12089
11848
  const $ = reactCompilerRuntime.c(3), editorActor = React.useContext(EditorActorContext), [selection, setSelection] = React.useState(null);
12090
11849
  let t0, t1;
@@ -12100,11 +11859,16 @@ const usePortableTextEditorSelection = () => {
12100
11859
  }, t1 = [editorActor], $[0] = editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), React.useEffect(t0, t1), selection;
12101
11860
  };
12102
11861
  exports.useEditor = useEditor.useEditor;
11862
+ Object.defineProperty(exports, "defineSchema", {
11863
+ enumerable: !0,
11864
+ get: function() {
11865
+ return schema.defineSchema;
11866
+ }
11867
+ });
12103
11868
  exports.EditorEventListener = EditorEventListener;
12104
11869
  exports.EditorProvider = EditorProvider;
12105
11870
  exports.PortableTextEditable = PortableTextEditable;
12106
11871
  exports.PortableTextEditor = PortableTextEditor;
12107
- exports.defineSchema = defineSchema;
12108
11872
  exports.keyGenerator = defaultKeyGenerator;
12109
11873
  exports.useEditorSelector = useEditorSelector;
12110
11874
  exports.usePortableTextEditor = usePortableTextEditor;