@makeswift/runtime 0.28.10-canary.11 → 0.28.10-canary.12

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 (53) hide show
  1. package/dist/cjs/api/graphql-api-client.js +1 -1
  2. package/dist/cjs/api/rest-api-client.js +1 -1
  3. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +23 -12
  5. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  6. package/dist/cjs/controls/serialization/base/visitor.js +5 -3
  7. package/dist/cjs/controls/serialization/base/visitor.js.map +1 -1
  8. package/dist/cjs/controls/visitors/merge-translations-visitor.js +1 -1
  9. package/dist/cjs/controls/visitors/merge-translations-visitor.js.map +1 -1
  10. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +13 -4
  11. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
  12. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js +1 -7
  13. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js.map +1 -1
  14. package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +1 -1
  15. package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
  16. package/dist/cjs/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js +6 -2
  17. package/dist/cjs/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js.map +1 -1
  18. package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js +2 -2
  19. package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js.map +1 -1
  20. package/dist/esm/api/graphql-api-client.js +1 -1
  21. package/dist/esm/api/rest-api-client.js +1 -1
  22. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  23. package/dist/esm/controls/rich-text-v2/rich-text-v2.js +23 -12
  24. package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  25. package/dist/esm/controls/serialization/base/visitor.js +5 -3
  26. package/dist/esm/controls/serialization/base/visitor.js.map +1 -1
  27. package/dist/esm/controls/visitors/merge-translations-visitor.js +1 -1
  28. package/dist/esm/controls/visitors/merge-translations-visitor.js.map +1 -1
  29. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +16 -4
  30. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
  31. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js +2 -3
  32. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js.map +1 -1
  33. package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +2 -1
  34. package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
  35. package/dist/esm/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js +6 -2
  36. package/dist/esm/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js.map +1 -1
  37. package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js +2 -2
  38. package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js.map +1 -1
  39. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +160 -23
  40. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  41. package/dist/types/controls/serialization/base/visitor.d.ts.map +1 -1
  42. package/dist/types/{controls/__tests__/slot.test.d.ts → runtimes/react/controls/__tests__/react-node-controls.test.d.ts} +1 -1
  43. package/dist/types/runtimes/react/controls/__tests__/react-node-controls.test.d.ts.map +1 -0
  44. package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts +4 -4
  45. package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
  46. package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts +2 -3
  47. package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts.map +1 -1
  48. package/dist/types/runtimes/react/controls/rich-text-v2/render-rich-text-v2.d.ts +5 -1
  49. package/dist/types/runtimes/react/controls/rich-text-v2/render-rich-text-v2.d.ts.map +1 -1
  50. package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2-value.d.ts +4 -4
  51. package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2-value.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/types/controls/__tests__/slot.test.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/controls/rich-text-v2/rich-text-v2.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport { z } from 'zod'\n// @ts-expect-error: there are no types for 'corporate-ipsum'\nimport ipsum from 'corporate-ipsum'\n\nimport {\n RichTextDefinition as BaseRichTextDefinition,\n isNotNil,\n ControlDefinition,\n SerializationSchema,\n StableValue,\n type Data,\n type Resolvable,\n type ControlInstanceArgs,\n type DeserializedRecord,\n type SchemaType,\n type SchemaTypeAny,\n type RichTextPluginControl,\n type ResourceResolver,\n type Stylesheet,\n type RichTextMode,\n} from '@makeswift/controls'\n\nimport { LinkPlugin } from '../../slate/LinkPlugin'\nimport { InlinePlugin } from '../../slate/InlinePlugin'\nimport { TextAlignPlugin } from '../../slate/TextAlignPlugin'\nimport { BlockPlugin } from '../../slate/BlockPlugin'\nimport { TypographyPlugin } from '../../slate/TypographyPlugin'\nimport { InlineModePlugin } from '../../slate/InlineModePlugin'\nimport { toText } from '../../slate/utils'\n\nimport { renderRichTextV2 } from '../../runtimes/react/controls/rich-text-v2'\n\nimport { RichTextV2Plugin, Plugin } from './plugin'\nimport { RichTextV2Control } from './control'\nimport { getTranslatableData } from './translations/get-translations'\n\ntype DataType = z.infer<typeof Definition.schema.data>\ntype DataV2Type = z.infer<typeof Definition.schema.dataV2>\ntype InstanceType = RichTextV2Control\ntype UserConfig = z.infer<typeof Definition.schema.userConfig>\ntype Config = UserConfig & {\n defaultValue: string\n plugins: RichTextV2Plugin[]\n}\n\nclass Definition extends BaseRichTextDefinition<ReactNode, Config, InstanceType> {\n constructor({ mode, defaultValue }: UserConfig, plugins?: RichTextV2Plugin[]) {\n super({\n mode,\n defaultValue:\n defaultValue ??\n (mode === Definition.Mode.Inline ? 'Edit this text' : Definition.generateParagraph()),\n plugins:\n plugins ??\n (mode === Definition.Mode.Inline\n ? [InlineModePlugin()]\n : [BlockPlugin(), TypographyPlugin(), TextAlignPlugin(), InlinePlugin(), LinkPlugin()]),\n })\n }\n\n static generateParagraph(): string {\n return ipsum(3)\n }\n\n static deserialize(\n data: DeserializedRecord,\n deserializeCallback: (r: DeserializedRecord) => ControlDefinition,\n ): RichTextV2Definition {\n if (data.type !== Definition.type) {\n throw new Error(`RichText: expected type ${Definition.type}, got ${data.type}`)\n }\n\n const { config } = Definition.fullSchema({\n pluginDef: SerializationSchema.deserializedRecord,\n }).definition.parse(data)\n\n const { plugins, ...userConfig } = config\n\n return new RichTextV2Definition(\n userConfig,\n plugins.map(({ control }) =>\n control ? { control: { definition: deserializeCallback(control?.definition) } } : {},\n ),\n )\n }\n\n static fullSchema<S extends SchemaTypeAny>({ pluginDef }: { pluginDef: S }) {\n const baseSchema = super.schema\n const plugin = z.object({\n control: z\n .object({\n definition: pluginDef,\n })\n .optional(),\n })\n\n const config = baseSchema.userConfig.extend({\n defaultValue: z.string(),\n plugins: z.array(plugin),\n })\n\n return {\n ...baseSchema,\n config,\n definition: z.object({\n type: baseSchema.type,\n config,\n }),\n }\n }\n\n get configSchema(): SchemaType<Config> {\n return Definition.fullSchema({ pluginDef: z.any() as SchemaType<ControlDefinition> }).config\n }\n\n createInstance(args: ControlInstanceArgs) {\n return new RichTextV2Control(this, args)\n }\n\n resolveValue(\n data: DataType | undefined,\n _resolver: ResourceResolver,\n _stylesheet: Stylesheet,\n control?: InstanceType,\n ): Resolvable<ReactNode | undefined> {\n const stableValue = StableValue({\n name: Definition.type,\n read: () => renderRichTextV2(data, this.config, control ?? null),\n })\n\n return {\n ...stableValue,\n triggerResolve: async () => {},\n }\n }\n\n getTranslatableData(data: DataType | undefined): Data {\n if (data == null) return null\n return getTranslatableData(Definition.dataToNodes(data), this.config.plugins)\n }\n\n get pluginControls(): RichTextPluginControl[] {\n return this.config.plugins.map(plugin => plugin.control).filter(isNotNil)\n }\n\n pluginControlAt(index: number): RichTextPluginControl | undefined {\n return this.pluginControls[index]\n }\n\n toText(data: DataType | undefined): string {\n if (data == null) return ''\n return toText(Definition.dataToNodes(data), this.config.mode ?? Definition.Mode.Block)\n }\n}\n\nexport class RichTextV2Definition extends Definition {}\n\nexport function RichText(config?: UserConfig): RichTextV2Definition {\n return new RichTextV2Definition(config ?? {})\n}\n\nRichText.Mode = Definition.Mode\nRichText.isV1Data = Definition.isV1Data\nRichText.dataToNodes = Definition.dataToNodes\nRichText.Plugin = Plugin\n\nexport { RichTextMode as RichTextV2Mode, type DataV2Type as RichTextDataV2, RichTextV2Control }\n"],"mappings":"AACA,SAAS,SAAS;AAElB,OAAO,WAAW;AAElB;AAAA,EACE,sBAAsB;AAAA,EACtB;AAAA,EAEA;AAAA,EACA;AAAA,OAWK;AAEP,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,cAAc;AAEvB,SAAS,wBAAwB;AAEjC,SAA2B,cAAc;AACzC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AAWpC,MAAM,mBAAmB,uBAAwD;AAAA,EAC/E,YAAY,EAAE,MAAM,aAAa,GAAe,SAA8B;AAC5E,UAAM;AAAA,MACJ;AAAA,MACA,cACE,iBACC,SAAS,WAAW,KAAK,SAAS,mBAAmB,WAAW,kBAAkB;AAAA,MACrF,SACE,YACC,SAAS,WAAW,KAAK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C,EAAE;AAAA,EACxF;AAAA,EAEA,eAAe,MAA2B;AACxC,WAAO,IAAI,kBAAkB,MAAM,IAAI;AAAA,EACzC;AAAA,EAEA,aACE,MACA,WACA,aACA,SACmC;AACnC,UAAM,cAAc,YAAY;AAAA,MAC9B,MAAM,WAAW;AAAA,MACjB,MAAM,MAAM,iBAAiB,MAAM,KAAK,QAAQ,WAAW,IAAI;AAAA,IACjE,CAAC;AAED,WAAO;AAAA,MACL,GAAG;AAAA,MACH,gBAAgB,YAAY;AAAA,MAAC;AAAA,IAC/B;AAAA,EACF;AAAA,EAEA,oBAAoB,MAAkC;AACpD,QAAI,QAAQ;AAAM,aAAO;AACzB,WAAO,oBAAoB,WAAW,YAAY,IAAI,GAAG,KAAK,OAAO,OAAO;AAAA,EAC9E;AAAA,EAEA,IAAI,iBAA0C;AAC5C,WAAO,KAAK,OAAO,QAAQ,IAAI,YAAU,OAAO,OAAO,EAAE,OAAO,QAAQ;AAAA,EAC1E;AAAA,EAEA,gBAAgB,OAAkD;AAChE,WAAO,KAAK,eAAe,KAAK;AAAA,EAClC;AAAA,EAEA,OAAO,MAAoC;AACzC,QAAI,QAAQ;AAAM,aAAO;AACzB,WAAO,OAAO,WAAW,YAAY,IAAI,GAAG,KAAK,OAAO,QAAQ,WAAW,KAAK,KAAK;AAAA,EACvF;AACF;AAEO,MAAM,6BAA6B,WAAW;AAAC;AAE/C,SAAS,SAAS,QAA2C;AAClE,SAAO,IAAI,qBAAqB,UAAU,CAAC,CAAC;AAC9C;AAEA,SAAS,OAAO,WAAW;AAC3B,SAAS,WAAW,WAAW;AAC/B,SAAS,cAAc,WAAW;AAClC,SAAS,SAAS;","names":[]}
1
+ {"version":3,"sources":["../../../../src/controls/rich-text-v2/rich-text-v2.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport { z } from 'zod'\n// @ts-expect-error: there are no types for 'corporate-ipsum'\nimport ipsum from 'corporate-ipsum'\n\nimport {\n RichTextDefinition as BaseRichTextDefinition,\n isNotNil,\n ControlDefinition,\n SerializationSchema,\n StableValue,\n type Data,\n type Resolvable,\n type ControlInstanceArgs,\n type DeserializedRecord,\n type SchemaType,\n type SchemaTypeAny,\n type RichTextPluginControl,\n type ResourceResolver,\n type Stylesheet,\n type RichTextMode,\n} from '@makeswift/controls'\n\nimport { LinkPlugin } from '../../slate/LinkPlugin'\nimport { InlinePlugin } from '../../slate/InlinePlugin'\nimport { TextAlignPlugin } from '../../slate/TextAlignPlugin'\nimport { BlockPlugin } from '../../slate/BlockPlugin'\nimport { TypographyPlugin } from '../../slate/TypographyPlugin'\nimport { InlineModePlugin } from '../../slate/InlineModePlugin'\nimport { toText } from '../../slate/utils'\n\nimport { renderRichTextV2 } from '../../runtimes/react/controls/rich-text-v2'\n\nimport { RichTextV2Plugin, Plugin } from './plugin'\nimport { RichTextV2Control } from './control'\nimport { getTranslatableData } from './translations/get-translations'\n\ntype DataType = z.infer<typeof Definition.schema.data>\ntype DataV2Type = z.infer<typeof Definition.schema.dataV2>\ntype InstanceType = RichTextV2Control\ntype UserConfig = z.infer<typeof Definition.schema.userConfig>\ntype Config = UserConfig & {\n defaultValue: string\n}\n\nclass Definition extends BaseRichTextDefinition<ReactNode, Config, InstanceType> {\n readonly plugins: RichTextV2Plugin[]\n\n constructor({ mode, defaultValue }: UserConfig, plugins?: RichTextV2Plugin[]) {\n super({\n mode,\n defaultValue:\n defaultValue ??\n (mode === Definition.Mode.Inline ? 'Edit this text' : Definition.generateParagraph()),\n })\n\n // The built-in plugin set is currently determined entirely by `mode` and\n // has remained stable across runtime versions, so it does not need to be\n // stored in the internal config. When that changes, we should:\n // - introduce a plugin registry\n // - have the config carry the IDs of selected plugins\n // - use the current inline and block plugin sets as defaults when\n // deserializing a legacy config that does not include plugin IDs\n this.plugins =\n plugins ??\n (mode === Definition.Mode.Inline\n ? [InlineModePlugin()]\n : [BlockPlugin(), TypographyPlugin(), TextAlignPlugin(), InlinePlugin(), LinkPlugin()])\n }\n\n static generateParagraph(): string {\n return ipsum(3)\n }\n\n static deserialize(\n data: DeserializedRecord,\n deserializeCallback: (r: DeserializedRecord) => ControlDefinition,\n ): RichTextV2Definition {\n if (data.type !== Definition.type) {\n throw new Error(`RichText: expected type ${Definition.type}, got ${data.type}`)\n }\n\n const { config, plugins } = Definition.fullSchema({\n pluginDef: SerializationSchema.deserializedRecord,\n }).definition.parse(data)\n\n const { plugins: configPlugins, ...userConfig } = config\n\n return new RichTextV2Definition(\n userConfig,\n (plugins ?? configPlugins ?? []).map(({ control }) =>\n control ? { control: { definition: deserializeCallback(control?.definition) } } : {},\n ),\n )\n }\n\n static fullSchema<S extends SchemaTypeAny>({ pluginDef }: { pluginDef: S }) {\n const baseSchema = super.schema\n const plugin = z.object({\n control: z\n .object({\n definition: pluginDef,\n })\n .optional(),\n })\n\n const plugins = z.array(plugin)\n\n const config = Definition.configSchema().extend({\n // plugins have been moved from config to the definition itself; keeping\n // the field here as optional so we can deserialize definitions coming from\n // older runtimes\n plugins: plugins.optional(),\n })\n\n return {\n ...baseSchema,\n config,\n definition: z.object({\n type: baseSchema.type,\n // marked as optional for backward compatibility with older runtimes\n plugins: plugins.optional(),\n config,\n }),\n }\n }\n\n static configSchema() {\n return super.schema.userConfig.extend({\n defaultValue: z.string(),\n })\n }\n\n get configSchema(): SchemaType<Config> {\n return Definition.configSchema()\n }\n\n createInstance(args: ControlInstanceArgs) {\n return new RichTextV2Control(this, args)\n }\n\n resolveValue(\n data: DataType | undefined,\n _resolver: ResourceResolver,\n _stylesheet: Stylesheet,\n control?: InstanceType,\n ): Resolvable<ReactNode | undefined> {\n const stableValue = StableValue({\n name: Definition.type,\n read: () => renderRichTextV2({ data, config: this.config, control: control ?? null }),\n })\n\n return {\n ...stableValue,\n triggerResolve: async () => {},\n }\n }\n\n getTranslatableData(data: DataType | undefined): Data {\n if (data == null) return null\n return getTranslatableData(Definition.dataToNodes(data), this.plugins)\n }\n\n get pluginControls(): RichTextPluginControl[] {\n return this.plugins.map(plugin => plugin.control).filter(isNotNil)\n }\n\n pluginControlAt(index: number): RichTextPluginControl | undefined {\n return this.pluginControls[index]\n }\n\n toText(data: DataType | undefined): string {\n if (data == null) return ''\n return toText(Definition.dataToNodes(data), this.config.mode ?? Definition.Mode.Block)\n }\n}\n\nexport class RichTextV2Definition extends Definition {}\n\nexport function RichText(config?: UserConfig): RichTextV2Definition {\n return new RichTextV2Definition(config ?? {})\n}\n\nRichText.Mode = Definition.Mode\nRichText.isV1Data = Definition.isV1Data\nRichText.dataToNodes = Definition.dataToNodes\nRichText.Plugin = Plugin\n\nexport { RichTextMode as RichTextV2Mode, type DataV2Type as RichTextDataV2, RichTextV2Control }\n"],"mappings":"AACA,SAAS,SAAS;AAElB,OAAO,WAAW;AAElB;AAAA,EACE,sBAAsB;AAAA,EACtB;AAAA,EAEA;AAAA,EACA;AAAA,OAWK;AAEP,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,cAAc;AAEvB,SAAS,wBAAwB;AAEjC,SAA2B,cAAc;AACzC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AAUpC,MAAM,mBAAmB,uBAAwD;AAAA,EACtE;AAAA,EAET,YAAY,EAAE,MAAM,aAAa,GAAe,SAA8B;AAC5E,UAAM;AAAA,MACJ;AAAA,MACA,cACE,iBACC,SAAS,WAAW,KAAK,SAAS,mBAAmB,WAAW,kBAAkB;AAAA,IACvF,CAAC;AASD,SAAK,UACH,YACC,SAAS,WAAW,KAAK,SACtB,CAAC,iBAAiB,CAAC,IACnB,CAAC,YAAY,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,aAAa,GAAG,WAAW,CAAC;AAAA,EAC3F;AAAA,EAEA,OAAO,oBAA4B;AACjC,WAAO,MAAM,CAAC;AAAA,EAChB;AAAA,EAEA,OAAO,YACL,MACA,qBACsB;AACtB,QAAI,KAAK,SAAS,WAA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;AAAA,EACzC;AAAA,EAEA,aACE,MACA,WACA,aACA,SACmC;AACnC,UAAM,cAAc,YAAY;AAAA,MAC9B,MAAM,WAAW;AAAA,MACjB,MAAM,MAAM,iBAAiB,EAAE,MAAM,QAAQ,KAAK,QAAQ,SAAS,WAAW,KAAK,CAAC;AAAA,IACtF,CAAC;AAED,WAAO;AAAA,MACL,GAAG;AAAA,MACH,gBAAgB,YAAY;AAAA,MAAC;AAAA,IAC/B;AAAA,EACF;AAAA,EAEA,oBAAoB,MAAkC;AACpD,QAAI,QAAQ;AAAM,aAAO;AACzB,WAAO,oBAAoB,WAAW,YAAY,IAAI,GAAG,KAAK,OAAO;AAAA,EACvE;AAAA,EAEA,IAAI,iBAA0C;AAC5C,WAAO,KAAK,QAAQ,IAAI,YAAU,OAAO,OAAO,EAAE,OAAO,QAAQ;AAAA,EACnE;AAAA,EAEA,gBAAgB,OAAkD;AAChE,WAAO,KAAK,eAAe,KAAK;AAAA,EAClC;AAAA,EAEA,OAAO,MAAoC;AACzC,QAAI,QAAQ;AAAM,aAAO;AACzB,WAAO,OAAO,WAAW,YAAY,IAAI,GAAG,KAAK,OAAO,QAAQ,WAAW,KAAK,KAAK;AAAA,EACvF;AACF;AAEO,MAAM,6BAA6B,WAAW;AAAC;AAE/C,SAAS,SAAS,QAA2C;AAClE,SAAO,IAAI,qBAAqB,UAAU,CAAC,CAAC;AAC9C;AAEA,SAAS,OAAO,WAAW;AAC3B,SAAS,WAAW,WAAW;AAC/B,SAAS,cAAc,WAAW;AAClC,SAAS,SAAS;","names":[]}
@@ -13,8 +13,7 @@ class BaseControlSerializationVisitor extends ControlSerializationVisitor {
13
13
  super([serializeDefinitionPlugin, ...plugins]);
14
14
  }
15
15
  visitRichTextV2(def) {
16
- const { plugins, ...config } = def.config;
17
- const pluginDefs = plugins.map(
16
+ const pluginDefs = def.plugins.map(
18
17
  ({ control }) => control ? {
19
18
  control: {
20
19
  definition: control.definition,
@@ -27,7 +26,10 @@ class BaseControlSerializationVisitor extends ControlSerializationVisitor {
27
26
  } : {}
28
27
  );
29
28
  const serialized = serializeObject(
30
- { config: { ...config, plugins: pluginDefs } },
29
+ // Continue serializing plugins as part of the config for the time being
30
+ // for builder compatibility; the current runtime accept plugins either in
31
+ // the config or at the definition level -- see `RichTextV2Definition.fullSchema`
32
+ { config: { ...def.config, plugins: pluginDefs } },
31
33
  this.serializationPlugins
32
34
  );
33
35
  return { ...serialized, type: RichTextV2Definition.type };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/controls/serialization/base/visitor.ts"],"sourcesContent":["import {\n ControlDefinition,\n SerializedRecord,\n serializeObject,\n SerializationPlugin,\n ControlSerializationVisitor,\n} from '@makeswift/controls'\n\nimport { RichTextV2Definition } from '../../rich-text-v2'\n\nexport class BaseControlSerializationVisitor extends ControlSerializationVisitor {\n constructor(plugins: SerializationPlugin<any>[]) {\n const serializeDefinitionPlugin: SerializationPlugin<ControlDefinition> = {\n match: (val: unknown) => val instanceof ControlDefinition,\n serialize: (val: ControlDefinition) => val.accept(this),\n }\n\n super([serializeDefinitionPlugin, ...plugins])\n }\n\n visitRichTextV2(def: RichTextV2Definition): SerializedRecord {\n const { plugins, ...config } = def.config\n\n // serialize only the plugin control definition, if any\n const pluginDefs = plugins.map(({ control }) =>\n control\n ? {\n control: {\n definition: control.definition,\n // FIXME: remove getValue/onChange stubs once we released a version of the builder\n // built against the runtime where these can be optional\n getValue: () => undefined,\n onChange: () => {},\n },\n }\n : {},\n )\n\n const serialized = serializeObject(\n { config: { ...config, plugins: pluginDefs } },\n this.serializationPlugins,\n ) as SerializedRecord\n\n return { ...serialized, type: RichTextV2Definition.type }\n }\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,4BAA4B;AAE9B,MAAM,wCAAwC,4BAA4B;AAAA,EAC/E,YAAY,SAAqC;AAC/C,UAAM,4BAAoE;AAAA,MACxE,OAAO,CAAC,QAAiB,eAAe;AAAA,MACxC,WAAW,CAAC,QAA2B,IAAI,OAAO,IAAI;AAAA,IACxD;AAEA,UAAM,CAAC,2BAA2B,GAAG,OAAO,CAAC;AAAA,EAC/C;AAAA,EAEA,gBAAgB,KAA6C;AAC3D,UAAM,EAAE,SAAS,GAAG,OAAO,IAAI,IAAI;AAGnC,UAAM,aAAa,QAAQ;AAAA,MAAI,CAAC,EAAE,QAAQ,MACxC,UACI;AAAA,QACE,SAAS;AAAA,UACP,YAAY,QAAQ;AAAA;AAAA;AAAA,UAGpB,UAAU,MAAM;AAAA,UAChB,UAAU,MAAM;AAAA,UAAC;AAAA,QACnB;AAAA,MACF,IACA,CAAC;AAAA,IACP;AAEA,UAAM,aAAa;AAAA,MACjB,EAAE,QAAQ,EAAE,GAAG,QAAQ,SAAS,WAAW,EAAE;AAAA,MAC7C,KAAK;AAAA,IACP;AAEA,WAAO,EAAE,GAAG,YAAY,MAAM,qBAAqB,KAAK;AAAA,EAC1D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/controls/serialization/base/visitor.ts"],"sourcesContent":["import {\n ControlDefinition,\n SerializedRecord,\n serializeObject,\n SerializationPlugin,\n ControlSerializationVisitor,\n} from '@makeswift/controls'\n\nimport { RichTextV2Definition } from '../../rich-text-v2'\n\nexport class BaseControlSerializationVisitor extends ControlSerializationVisitor {\n constructor(plugins: SerializationPlugin<any>[]) {\n const serializeDefinitionPlugin: SerializationPlugin<ControlDefinition> = {\n match: (val: unknown) => val instanceof ControlDefinition,\n serialize: (val: ControlDefinition) => val.accept(this),\n }\n\n super([serializeDefinitionPlugin, ...plugins])\n }\n\n visitRichTextV2(def: RichTextV2Definition): SerializedRecord {\n // serialize only the plugin control definition, if any\n const pluginDefs = def.plugins.map(({ control }) =>\n control\n ? {\n control: {\n definition: control.definition,\n // FIXME: remove getValue/onChange stubs once we released a version of the builder\n // built against the runtime where these can be optional\n getValue: () => undefined,\n onChange: () => {},\n },\n }\n : {},\n )\n\n const serialized = serializeObject(\n // Continue serializing plugins as part of the config for the time being\n // for builder compatibility; the current runtime accept plugins either in\n // the config or at the definition level -- see `RichTextV2Definition.fullSchema`\n { config: { ...def.config, plugins: pluginDefs } },\n this.serializationPlugins,\n ) as SerializedRecord\n\n return { ...serialized, type: RichTextV2Definition.type }\n }\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,4BAA4B;AAE9B,MAAM,wCAAwC,4BAA4B;AAAA,EAC/E,YAAY,SAAqC;AAC/C,UAAM,4BAAoE;AAAA,MACxE,OAAO,CAAC,QAAiB,eAAe;AAAA,MACxC,WAAW,CAAC,QAA2B,IAAI,OAAO,IAAI;AAAA,IACxD;AAEA,UAAM,CAAC,2BAA2B,GAAG,OAAO,CAAC;AAAA,EAC/C;AAAA,EAEA,gBAAgB,KAA6C;AAE3D,UAAM,aAAa,IAAI,QAAQ;AAAA,MAAI,CAAC,EAAE,QAAQ,MAC5C,UACI;AAAA,QACE,SAAS;AAAA,UACP,YAAY,QAAQ;AAAA;AAAA;AAAA,UAGpB,UAAU,MAAM;AAAA,UAChB,UAAU,MAAM;AAAA,UAAC;AAAA,QACnB;AAAA,MACF,IACA,CAAC;AAAA,IACP;AAEA,UAAM,aAAa;AAAA;AAAA;AAAA;AAAA,MAIjB,EAAE,QAAQ,EAAE,GAAG,IAAI,QAAQ,SAAS,WAAW,EAAE;AAAA,MACjD,KAAK;AAAA,IACP;AAEA,WAAO,EAAE,GAAG,YAAY,MAAM,qBAAqB,KAAK;AAAA,EAC1D;AACF;","names":[]}
@@ -11,7 +11,7 @@ class ReactMergeTranslationsVisitor extends MergeTranslationsVisitor {
11
11
  descendants: mergeTranslatedNodes(
12
12
  descendants,
13
13
  translatedData,
14
- def.config.plugins
14
+ def.plugins
15
15
  )
16
16
  };
17
17
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/controls/visitors/merge-translations-visitor.ts"],"sourcesContent":["import { Data, DataType, MergeTranslationsVisitor } from '@makeswift/controls'\n\nimport { RichTextV2Definition } from '../rich-text-v2'\nimport { RichTextTranslationDto } from '../rich-text-v2/translations/translations-core'\nimport { mergeTranslatedNodes } from '../rich-text-v2/translations/merge-translations'\n\nexport class ReactMergeTranslationsVisitor extends MergeTranslationsVisitor {\n visitRichTextV2(\n def: RichTextV2Definition,\n data: DataType<RichTextV2Definition> | undefined,\n translatedData: Data,\n ): Data {\n if (data == null || translatedData == null) return data\n\n const { descendants, ...rest } = RichTextV2Definition.normalizeData(data)\n\n return {\n ...rest,\n descendants: mergeTranslatedNodes(\n descendants,\n translatedData as RichTextTranslationDto,\n def.config.plugins,\n ),\n }\n }\n}\n"],"mappings":"AAAA,SAAyB,gCAAgC;AAEzD,SAAS,4BAA4B;AAErC,SAAS,4BAA4B;AAE9B,MAAM,sCAAsC,yBAAyB;AAAA,EAC1E,gBACE,KACA,MACA,gBACM;AACN,QAAI,QAAQ,QAAQ,kBAAkB;AAAM,aAAO;AAEnD,UAAM,EAAE,aAAa,GAAG,KAAK,IAAI,qBAAqB,cAAc,IAAI;AAExE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAa;AAAA,QACX;AAAA,QACA;AAAA,QACA,IAAI,OAAO;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/controls/visitors/merge-translations-visitor.ts"],"sourcesContent":["import { Data, DataType, MergeTranslationsVisitor } from '@makeswift/controls'\n\nimport { RichTextV2Definition } from '../rich-text-v2'\nimport { RichTextTranslationDto } from '../rich-text-v2/translations/translations-core'\nimport { mergeTranslatedNodes } from '../rich-text-v2/translations/merge-translations'\n\nexport class ReactMergeTranslationsVisitor extends MergeTranslationsVisitor {\n visitRichTextV2(\n def: RichTextV2Definition,\n data: DataType<RichTextV2Definition> | undefined,\n translatedData: Data,\n ): Data {\n if (data == null || translatedData == null) return data\n\n const { descendants, ...rest } = RichTextV2Definition.normalizeData(data)\n\n return {\n ...rest,\n descendants: mergeTranslatedNodes(\n descendants,\n translatedData as RichTextTranslationDto,\n def.plugins,\n ),\n }\n }\n}\n"],"mappings":"AAAA,SAAyB,gCAAgC;AAEzD,SAAS,4BAA4B;AAErC,SAAS,4BAA4B;AAE9B,MAAM,sCAAsC,yBAAyB;AAAA,EAC1E,gBACE,KACA,MACA,gBACM;AACN,QAAI,QAAQ,QAAQ,kBAAkB;AAAM,aAAO;AAEnD,UAAM,EAAE,aAAa,GAAG,KAAK,IAAI,qBAAqB,cAAc,IAAI;AAExE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAa;AAAA,QACX;AAAA,QACA;AAAA,QACA,IAAI;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import {
4
+ memo,
4
5
  useCallback,
5
6
  useEffect,
6
7
  useMemo,
@@ -16,20 +17,31 @@ import {
16
17
  Editable
17
18
  } from "slate-react";
18
19
  import {
19
- RichText
20
+ RichTextV2Definition,
21
+ RichText,
22
+ RichTextV2Control
20
23
  } from "../../../../../controls/rich-text-v2";
21
24
  import { useBuilderEditMode } from "../../../hooks/use-builder-edit-mode";
25
+ import { useControlInstance } from "../../../hooks/use-control-instance";
22
26
  import { useSlateReset } from "../../use-slate-reset";
23
27
  import { BuilderEditMode } from "../../../../../state/modules/builder-edit-mode";
24
28
  import { pollBoxModel } from "../../../poll-box-model";
25
29
  import { withBuilder, withLocalChanges } from "../../../../../slate";
30
+ import { NodeValue } from "../../node-value";
26
31
  import { useSyncDOMSelection } from "./useSyncDOMSelection";
27
32
  import { RichTextV2Element } from "./render-element";
28
33
  import { RichTextV2Leaf } from "./render-leaf";
29
34
  import { useSyncRemoteChanges } from "./useRemoteChanges";
30
35
  import { defaultValue, usePresetValue } from "./usePresetValue";
31
- function EditableTextV2({ text, config, control }) {
32
- const plugins = useMemo(() => config.plugins, [config]);
36
+ const EditableTextV2Value = memo(function EditableTextV2Value2({
37
+ instanceKey,
38
+ ...props
39
+ }) {
40
+ return /* @__PURE__ */ jsx(NodeValue, { instanceKey, children: /* @__PURE__ */ jsx(EditableTextV2, { instanceKey, ...props }) });
41
+ });
42
+ function EditableTextV2({ text, config, instanceKey }) {
43
+ const plugins = useMemo(() => new RichTextV2Definition(config).plugins, [config]);
44
+ const control = useControlInstance(instanceKey, RichTextV2Control);
33
45
  const [editor] = useState(
34
46
  () => plugins.reduceRight(
35
47
  (editor2, plugin) => plugin?.withPlugin?.(editor2) ?? editor2,
@@ -145,6 +157,6 @@ function EditableTextV2({ text, config, control }) {
145
157
  ) });
146
158
  }
147
159
  export {
148
- EditableTextV2
160
+ EditableTextV2Value
149
161
  };
150
162
  //# sourceMappingURL=editable-text-v2.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["'use client'\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { createEditor } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport {\n withReact,\n ReactEditor,\n RenderElementProps,\n RenderLeafProps,\n Slate,\n Editable,\n} from 'slate-react'\n\nimport { type ConfigType } from '@makeswift/controls'\n\nimport {\n RichTextV2Definition,\n RichText,\n RichTextV2Control,\n type RichTextDataV2,\n} from '../../../../../controls/rich-text-v2'\n\nimport { useBuilderEditMode } from '../../../hooks/use-builder-edit-mode'\nimport { useSlateReset } from '../../use-slate-reset'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { withBuilder, withLocalChanges } from '../../../../../slate'\n\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { RichTextV2Element } from './render-element'\nimport { RichTextV2Leaf } from './render-leaf'\nimport { useSyncRemoteChanges } from './useRemoteChanges'\nimport { defaultValue, usePresetValue } from './usePresetValue'\n\ntype Props = {\n text?: RichTextDataV2\n config: ConfigType<RichTextV2Definition>\n control: RichTextV2Control | null\n}\n\nexport function EditableTextV2({ text, config, control }: Props) {\n const plugins = useMemo(() => config.plugins, [config])\n\n const [editor] = useState(() =>\n plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n withLocalChanges(withBuilder(withReact(createEditor()))),\n ),\n )\n\n useEffect(() => {\n if (control == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeBoxModel(boxModel),\n })\n }, [editor, control])\n\n // ------ Preserving selection ------\n\n const isPreservingFocus = useRef(false)\n useSyncDOMSelection(editor, isPreservingFocus)\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n /**\n * This is required because clicking on the overlay has `relatedTarget` null just like the sidebar, but\n * - in the case of the overlay we switch to BUILD mode\n * - in the case of the sidebar we preserve the selection\n */\n if (editMode !== BuilderEditMode.CONTENT) {\n isPreservingFocus.current = false\n ReactEditor.deselect(editor)\n }\n }, [editMode, editor])\n\n // ------ Syncing remote changes ------\n\n useSyncRemoteChanges(editor, text)\n\n // ------ Default value ------\n\n const presetValue = usePresetValue(config)\n\n const initialValue = useMemo(\n () => (text && RichText.dataToNodes(text)) ?? presetValue,\n [text, presetValue],\n )\n\n useEffect(() => {\n control?.setEditor(editor)\n control?.setDefaultValue(defaultValue)\n }, [control, editor])\n\n /**\n * When initialValue is set to the default value we need to trigger an local change so that the sidebar updates and so the data is saved\n */\n useEffect(() => {\n if (initialValue === presetValue) {\n control?.onLocalUserChange()\n }\n }, [control, initialValue, presetValue])\n\n // ------ Rendering ------\n\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return <RichTextV2Element {...props} plugins={plugins} />\n },\n [plugins],\n )\n\n const renderLeaf = useCallback(\n (props: RenderLeafProps) => {\n return <RichTextV2Leaf {...props} plugins={plugins} />\n },\n [plugins],\n )\n\n // ------ Event handlers ------\n\n const handleFocus = useCallback(() => {\n isPreservingFocus.current = true\n control?.select()\n }, [control])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return control?.redo()\n if (isHotkey('mod+z', e)) return control?.undo()\n if (isHotkey('escape')(e)) {\n isPreservingFocus.current = false\n ReactEditor.blur(editor)\n control?.switchToBuildMode()\n }\n\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n }\n\n plugins.forEach(plugin => plugin?.onKeyDown?.(e, editor))\n },\n [control, plugins, editor, editMode],\n )\n\n const handleKeyUp = useCallback(\n (e: KeyboardEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [editMode],\n )\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [editMode],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // outside of iframe (overlay, sidebar, etc)\n if (e.relatedTarget == null) return\n // another text\n if (e.relatedTarget?.getAttribute('contenteditable') === 'true')\n isPreservingFocus.current = false\n }, [])\n\n const slateReset = useSlateReset()\n\n return (\n <Slate editor={editor} value={initialValue}>\n <Editable\n className={slateReset}\n renderLeaf={renderLeaf}\n renderElement={renderElement}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onClick={handleClick}\n onBlur={handleBlur}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n}\n"],"mappings":";AAuHa;AArHb;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,OAAO,cAAc;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AAIP;AAAA,EAEE;AAAA,OAGK;AAEP,SAAS,0BAA0B;A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aAAa,gBAAgB,SAAS;AACxC,UAAE,gBAAgB;AAClB,UAAE,eAAe;AAAA,MACnB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,aAAa,YAAY,CAAC,MAAkB;AAEhD,QAAI,EAAE,iBAAiB;AAAM;AAE7B,QAAI,EAAE,eAAe,aAAa,iBAAiB,MAAM;AACvD,wBAAkB,UAAU;AAAA,EAChC,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,cAAc;AAEjC,SACE,oBAAC,SAAM,QAAgB,OAAO,cAC5B;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,WAAW;AAAA,MACX,SAAS;AAAA,MACT,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,UAAU,aAAa,gBAAgB;AAAA,MACvC,aAAY;AAAA;AAAA,EACd,GACF;AAEJ;","names":["editor"]}
1
+ {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["'use client'\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n memo,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { createEditor } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport {\n withReact,\n ReactEditor,\n RenderElementProps,\n RenderLeafProps,\n Slate,\n Editable,\n} from 'slate-react'\n\nimport { type ControlInstanceKey, type ConfigType } from '@makeswift/controls'\n\nimport {\n RichTextV2Definition,\n RichText,\n RichTextV2Control,\n type RichTextDataV2,\n} from '../../../../../controls/rich-text-v2'\n\nimport { useBuilderEditMode } from '../../../hooks/use-builder-edit-mode'\nimport { useControlInstance } from '../../../hooks/use-control-instance'\nimport { useSlateReset } from '../../use-slate-reset'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { withBuilder, withLocalChanges } from '../../../../../slate'\nimport { NodeValue } from '../../node-value'\n\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { RichTextV2Element } from './render-element'\nimport { RichTextV2Leaf } from './render-leaf'\nimport { useSyncRemoteChanges } from './useRemoteChanges'\nimport { defaultValue, usePresetValue } from './usePresetValue'\n\ntype Props = {\n text?: RichTextDataV2\n config: ConfigType<RichTextV2Definition>\n instanceKey: ControlInstanceKey | undefined\n}\n\nexport const EditableTextV2Value = memo(function EditableTextV2Value({\n instanceKey,\n ...props\n}: Props): ReactNode {\n return (\n <NodeValue instanceKey={instanceKey}>\n <EditableTextV2 instanceKey={instanceKey} {...props} />\n </NodeValue>\n )\n})\n\nfunction EditableTextV2({ text, config, instanceKey }: Props) {\n const plugins = useMemo(() => new RichTextV2Definition(config).plugins, [config])\n const control = useControlInstance(instanceKey, RichTextV2Control)\n\n const [editor] = useState(() =>\n plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n withLocalChanges(withBuilder(withReact(createEditor()))),\n ),\n )\n\n useEffect(() => {\n if (control == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeBoxModel(boxModel),\n })\n }, [editor, control])\n\n // ------ Preserving selection ------\n\n const isPreservingFocus = useRef(false)\n useSyncDOMSelection(editor, isPreservingFocus)\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n /**\n * This is required because clicking on the overlay has `relatedTarget` null just like the sidebar, but\n * - in the case of the overlay we switch to BUILD mode\n * - in the case of the sidebar we preserve the selection\n */\n if (editMode !== BuilderEditMode.CONTENT) {\n isPreservingFocus.current = false\n ReactEditor.deselect(editor)\n }\n }, [editMode, editor])\n\n // ------ Syncing remote changes ------\n\n useSyncRemoteChanges(editor, text)\n\n // ------ Default value ------\n\n const presetValue = usePresetValue(config)\n\n const initialValue = useMemo(\n () => (text && RichText.dataToNodes(text)) ?? presetValue,\n [text, presetValue],\n )\n\n useEffect(() => {\n control?.setEditor(editor)\n control?.setDefaultValue(defaultValue)\n }, [control, editor])\n\n /**\n * When initialValue is set to the default value we need to trigger an local change so that the sidebar updates and so the data is saved\n */\n useEffect(() => {\n if (initialValue === presetValue) {\n control?.onLocalUserChange()\n }\n }, [control, initialValue, presetValue])\n\n // ------ Rendering ------\n\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return <RichTextV2Element {...props} plugins={plugins} />\n },\n [plugins],\n )\n\n const renderLeaf = useCallback(\n (props: RenderLeafProps) => {\n return <RichTextV2Leaf {...props} plugins={plugins} />\n },\n [plugins],\n )\n\n // ------ Event handlers ------\n\n const handleFocus = useCallback(() => {\n isPreservingFocus.current = true\n control?.select()\n }, [control])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return control?.redo()\n if (isHotkey('mod+z', e)) return control?.undo()\n if (isHotkey('escape')(e)) {\n isPreservingFocus.current = false\n ReactEditor.blur(editor)\n control?.switchToBuildMode()\n }\n\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n }\n\n plugins.forEach(plugin => plugin?.onKeyDown?.(e, editor))\n },\n [control, plugins, editor, editMode],\n )\n\n const handleKeyUp = useCallback(\n (e: KeyboardEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [editMode],\n )\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [editMode],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // outside of iframe (overlay, sidebar, etc)\n if (e.relatedTarget == null) return\n // another text\n if (e.relatedTarget?.getAttribute('contenteditable') === 'true')\n isPreservingFocus.current = false\n }, [])\n\n const slateReset = useSlateReset()\n\n return (\n <Slate editor={editor} value={initialValue}>\n <Editable\n className={slateReset}\n renderLeaf={renderLeaf}\n renderElement={renderElement}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onClick={handleClick}\n onBlur={handleBlur}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n}\n"],"mappings":";AA4DM;AA1DN;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,OAAO,cAAc;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,aAAa,wBAAwB;AAC9C,SAAS,iBAAiB;AAE1B,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,cAAc,sBAAsB;AAQtC,MAAM,sBAAsB,KAAK,SAASA,qBAAoB;AAAA,EACnE;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,SACE,oBAAC,aAAU,aACT,8BAAC,kBAAe,aAA2B,GAAG,OAAO,GACvD;AAEJ,CAAC;AAED,SAAS,eAAe,EAAE,MAAM,QAAQ,YAAY,GAAU;AAC5D,QAAM,UAAU,QAAQ,MAAM,IAAI,qBAAqB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;AAChF,QAAM,UAAU,mBAAmB,aAAa,iBAAiB;AAEjE,QAAM,CAAC,MAAM,IAAI;AAAA,IAAS,MACxB,QAAQ;AAAA,MACN,CAACC,SAAQ,WAAW,QAAQ,aAAaA,OAAM,KAAKA;AAAA,MACpD,iBAAiB,YAAY,UAAU,aAAa,CAAC,CAAC,CAAC;AAAA,IACzD;AAAA,EACF;AAEA,YAAU,MAAM;AACd,QAAI,WAAW;AAAM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AA;AAAA,EACd,GACF;AAEJ;","names":["EditableTextV2Value","editor"]}
@@ -1,6 +1,5 @@
1
- export * from "./editable-text-v2";
2
- import { EditableTextV2 } from "./editable-text-v2";
3
- var EditableTextV2_default = EditableTextV2;
1
+ import { EditableTextV2Value } from "./editable-text-v2";
2
+ var EditableTextV2_default = EditableTextV2Value;
4
3
  export {
5
4
  EditableTextV2_default as default
6
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.tsx"],"sourcesContent":["export * from './editable-text-v2'\nimport { EditableTextV2 } from './editable-text-v2'\nexport default EditableTextV2\n"],"mappings":"AAAA,cAAc;AACd,SAAS,sBAAsB;AAC/B,IAAO,yBAAQ;","names":[]}
1
+ {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.tsx"],"sourcesContent":["import { EditableTextV2Value } from './editable-text-v2'\nexport default EditableTextV2Value\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC,IAAO,yBAAQ;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { Fragment, jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useMemo } from "react";
3
3
  import {
4
+ RichTextV2Definition,
4
5
  RichText
5
6
  } from "../../../../controls/rich-text-v2";
6
7
  import { useStyle } from "../../use-style";
@@ -8,7 +9,7 @@ import { toText } from "../../../../slate/utils";
8
9
  import { ControlValue } from "../control";
9
10
  const ReadOnlyTextV2 = forwardRef(function ReadOnlyText({ text, config }, ref) {
10
11
  const descendants = useMemo(() => text?.descendants ?? [], [text?.descendants]);
11
- const plugins = useMemo(() => config?.plugins ?? [], [config]);
12
+ const plugins = useMemo(() => config ? new RichTextV2Definition(config).plugins : [], [config]);
12
13
  const descendantsAsString = toText(descendants, config?.mode ?? RichText.Mode.Block);
13
14
  return /* @__PURE__ */ jsx(
14
15
  "div",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.tsx"],"sourcesContent":["import { type ReactNode, type ForwardedRef, forwardRef, useMemo } from 'react'\nimport { type Descendant, type Element, type Text } from 'slate'\nimport { type RenderElementProps, type RenderLeafProps } from 'slate-react'\n\nimport { type ConfigType } from '@makeswift/controls'\n\nimport {\n type RichTextDataV2,\n RichTextV2Definition,\n RichText,\n} from '../../../../controls/rich-text-v2'\nimport { useStyle } from '../../use-style'\nimport { toText } from '../../../../slate/utils'\nimport { RichTextV2Plugin } from '../../../../controls/rich-text-v2/plugin'\n\nimport { ControlValue } from '../control'\n\ntype Props = {\n text: RichTextDataV2 | undefined\n config: ConfigType<RichTextV2Definition> | undefined\n}\n\nconst ReadOnlyTextV2 = forwardRef(function ReadOnlyText(\n { text, config }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendants = useMemo(() => text?.descendants ?? [], [text?.descendants])\n const plugins = useMemo(() => config?.plugins ?? [], [config])\n const descendantsAsString = toText(descendants, config?.mode ?? RichText.Mode.Block)\n\n return (\n <div\n ref={ref}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n >\n {descendantsAsString === '' ? (\n <Placeholder />\n ) : (\n <Descendants plugins={plugins} descendants={descendants} />\n )}\n </div>\n )\n})\n\nexport default ReadOnlyTextV2\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\ntype LeafProps = {\n leaf: Text\n plugins: RichTextV2Plugin[]\n}\n\nexport function LeafComponent({ plugins, ...props }: LeafProps) {\n function initialRenderLeaf({ leaf }: RenderLeafProps): ReactNode {\n return <span className={leaf.className}>{leaf.text === '' ? '\\uFEFF' : leaf.text}</span>\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) =>\n function RenderLeafPlugin(props: RenderLeafProps) {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf({ attributes: {} as any, leaf: props.leaf, children: null, text: props.leaf })\n}\n\ntype ElementProps = {\n descendant: Element\n plugins: RichTextV2Plugin[]\n}\n\nfunction ElementComponent({ plugins, ...props }: ElementProps) {\n function initialRenderElement(props: RenderElementProps): ReactNode {\n return <Descendants descendants={props.element.children} plugins={plugins} />\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) =>\n function RenderElementPlugin(props: RenderElementProps) {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue\n definition={control.definition}\n data={control.getElementValue(props.element)}\n >\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement({ attributes: {} as any, children: null, element: props.descendant })\n}\n\n// reimplemented from slate source for code splitting\nfunction isText(node: Descendant): node is Text {\n if (typeof node === 'object' && 'text' in node) return true\n\n return false\n}\n\nfunction Descendants({\n descendants,\n plugins,\n}: {\n plugins: RichTextV2Plugin[]\n descendants: Descendant[]\n}) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (isText(descendant)) {\n return <LeafComponent key={index} plugins={plugins} leaf={descendant} />\n }\n\n return <ElementComponent key={index} descendant={descendant} plugins={plugins} />\n })}\n </>\n )\n}\n"],"mappings":"AA6CQ,S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YAAY;AAAA,EACnB;AAAA,EACA;AACF,GAGG;AACD,SACE,gCACG,sBAAY,IAAI,CAAC,YAAY,UAAU;AACtC,QAAI,OAAO,UAAU,GAAG;AACtB,aAAO,oBAAC,iBAA0B,SAAkB,MAAM,cAA/B,KAA2C;AAAA,IACxE;AAEA,WAAO,oBAAC,oBAA6B,YAAwB,WAA/B,KAAiD;AAAA,EACjF,CAAC,GACH;AAEJ;","names":["props","renderLeaf","renderElement"]}
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.tsx"],"sourcesContent":["import { type ReactNode, type ForwardedRef, forwardRef, useMemo } from 'react'\nimport { type Descendant, type Element, type Text } from 'slate'\nimport { type RenderElementProps, type RenderLeafProps } from 'slate-react'\n\nimport { type ConfigType } from '@makeswift/controls'\n\nimport {\n type RichTextDataV2,\n RichTextV2Definition,\n RichText,\n} from '../../../../controls/rich-text-v2'\nimport { useStyle } from '../../use-style'\nimport { toText } from '../../../../slate/utils'\nimport { RichTextV2Plugin } from '../../../../controls/rich-text-v2/plugin'\n\nimport { ControlValue } from '../control'\n\ntype Props = {\n text: RichTextDataV2 | undefined\n config: ConfigType<RichTextV2Definition> | undefined\n}\n\nconst ReadOnlyTextV2 = forwardRef(function ReadOnlyText(\n { text, config }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendants = useMemo(() => text?.descendants ?? [], [text?.descendants])\n const plugins = useMemo(() => (config ? new RichTextV2Definition(config).plugins : []), [config])\n const descendantsAsString = toText(descendants, config?.mode ?? RichText.Mode.Block)\n\n return (\n <div\n ref={ref}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n >\n {descendantsAsString === '' ? (\n <Placeholder />\n ) : (\n <Descendants plugins={plugins} descendants={descendants} />\n )}\n </div>\n )\n})\n\nexport default ReadOnlyTextV2\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\ntype LeafProps = {\n leaf: Text\n plugins: RichTextV2Plugin[]\n}\n\nexport function LeafComponent({ plugins, ...props }: LeafProps) {\n function initialRenderLeaf({ leaf }: RenderLeafProps): ReactNode {\n return <span className={leaf.className}>{leaf.text === '' ? '\\uFEFF' : leaf.text}</span>\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) =>\n function RenderLeafPlugin(props: RenderLeafProps) {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf({ attributes: {} as any, leaf: props.leaf, children: null, text: props.leaf })\n}\n\ntype ElementProps = {\n descendant: Element\n plugins: RichTextV2Plugin[]\n}\n\nfunction ElementComponent({ plugins, ...props }: ElementProps) {\n function initialRenderElement(props: RenderElementProps): ReactNode {\n return <Descendants descendants={props.element.children} plugins={plugins} />\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) =>\n function RenderElementPlugin(props: RenderElementProps) {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue\n definition={control.definition}\n data={control.getElementValue(props.element)}\n >\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement({ attributes: {} as any, children: null, element: props.descendant })\n}\n\n// reimplemented from slate source for code splitting\nfunction isText(node: Descendant): node is Text {\n if (typeof node === 'object' && 'text' in node) return true\n\n return false\n}\n\nfunction Descendants({\n descendants,\n plugins,\n}: {\n plugins: RichTextV2Plugin[]\n descendants: Descendant[]\n}) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (isText(descendant)) {\n return <LeafComponent key={index} plugins={plugins} leaf={descendant} />\n }\n\n return <ElementComponent key={index} descendant={descendant} plugins={plugins} />\n })}\n </>\n )\n}\n"],"mappings":"AA6CQ,SA2GJ,UA3GI;AA7CR,SAA4C,YAAY,eAAe;AAMvE;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAGvB,SAAS,oBAAoB;AAO7B,MAAM,iBAAiB,WAAW,SAAS,aACzC,EAAE,MAAM,OAAO,GACf,KACA;AACA,QAAM,cAAc,QAAQ,MAAM,MAAM,eAAe,CAAC,GAAG,CAAC,MAAM,WAAW,CAAC;AAC9E,QAAM,UAAU,QAAQ,MAAO,SAAS,IAAI,qBAAqB,MAAM,EAAE,UAAU,CAAC,GAAI,CAAC,MAAM,CAAC;AAChG,QAAM,sBAAsB,OAAO,aAAa,QAAQ,QAAQ,SAAS,KAAK,KAAK;AAEnF,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAML,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAAA,MAEC,kCAAwB,KACvB,oBAAC,eAAY,IAEb,oBAAC,eAAY,SAAkB,aAA0B;AAAA;AAAA,EAE7D;AAEJ,CAAC;AAED,IAAO,yBAAQ;AAEf,SAAS,YAAY,EAAE,OAAO,qBAAqB,GAAsB;AACvE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,SAAS;AAAA,QAClB,SAAS;AAAA,QACT,OAAO;AAAA,QACP,UAAU;AAAA,Q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AA,QAAC;AAAA;AAAA,UACC,YAAY,QAAQ;AAAA,UACpB,MAAM,QAAQ,gBAAgBA,OAAM,OAAO;AAAA,UAE1C,qBAASE,eAAc,UAAU,KAAK,EAAEF,MAAK;AAAA;AAAA,MAChD;AAAA,IAEJ;AAAA,IACF;AAAA,EACF;AAEA,SAAO,cAAc,EAAE,YAAY,CAAC,GAAU,UAAU,MAAM,SAAS,MAAM,WAAW,CAAC;AAC3F;AAGA,SAAS,OAAO,MAAgC;AAC9C,MAAI,OAAO,SAAS,YAAY,UAAU;AAAM,WAAO;AAEvD,SAAO;AACT;AAEA,SAAS,YAAY;AAAA,EACnB;AAAA,EACA;AACF,GAGG;AACD,SACE,gCACG,sBAAY,IAAI,CAAC,YAAY,UAAU;AACtC,QAAI,OAAO,UAAU,GAAG;AACtB,aAAO,oBAAC,iBAA0B,SAAkB,MAAM,cAA/B,KAA2C;AAAA,IACxE;AAEA,WAAO,oBAAC,oBAA6B,YAAwB,WAA/B,KAAiD;AAAA,EACjF,CAAC,GACH;AAEJ;","names":["props","renderLeaf","renderElement"]}
@@ -3,8 +3,12 @@ import { lazy } from "react";
3
3
  import { RichTextV2Definition } from "../../../../controls/rich-text-v2";
4
4
  import { RichTextV2Value } from "./rich-text-v2-value";
5
5
  const ReadOnlyTextV1 = lazy(() => import("../rich-text/ReadOnlyText"));
6
- function renderRichTextV2(data, config, control) {
7
- return RichTextV2Definition.isV1Data(data) ? /* @__PURE__ */ jsx(ReadOnlyTextV1, { text: data }) : /* @__PURE__ */ jsx(RichTextV2Value, { data, config, control });
6
+ function renderRichTextV2({
7
+ data,
8
+ config,
9
+ control
10
+ }) {
11
+ return RichTextV2Definition.isV1Data(data) ? /* @__PURE__ */ jsx(ReadOnlyTextV1, { text: data }) : /* @__PURE__ */ jsx(RichTextV2Value, { data, config, instanceKey: control?.instanceKey });
8
12
  }
9
13
  export {
10
14
  renderRichTextV2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/render-rich-text-v2.tsx"],"sourcesContent":["import { type ReactNode, lazy } from 'react'\n\nimport { type DataType, type ConfigType } from '@makeswift/controls'\n\nimport { RichTextV2Control, RichTextV2Definition } from '../../../../controls/rich-text-v2'\n\nimport { RichTextV2Value } from './rich-text-v2-value'\n\nconst ReadOnlyTextV1 = lazy(() => import('../rich-text/ReadOnlyText'))\n\nexport function renderRichTextV2(\n data: DataType<RichTextV2Definition> | undefined,\n config: ConfigType<RichTextV2Definition>,\n control: RichTextV2Control | null,\n): ReactNode {\n return RichTextV2Definition.isV1Data(data) ? (\n <ReadOnlyTextV1 text={data} />\n ) : (\n <RichTextV2Value data={data} config={config} control={control} />\n )\n}\n"],"mappings":"AAgBI;AAhBJ,SAAyB,YAAY;AAIrC,SAA4B,4BAA4B;AAExD,SAAS,uBAAuB;AAEhC,MAAM,iBAAiB,KAAK,MAAM,OAAO,2BAA2B,CAAC;AAE9D,SAAS,iBACd,MACA,QACA,SACW;AACX,SAAO,qBAAqB,SAAS,IAAI,IACvC,oBAAC,kBAAe,MAAM,MAAM,IAE5B,oBAAC,mBAAgB,MAAY,QAAgB,SAAkB;AAEnE;","names":[]}
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/render-rich-text-v2.tsx"],"sourcesContent":["import { type ReactNode, lazy } from 'react'\n\nimport { type DataType, type ConfigType } from '@makeswift/controls'\n\nimport { RichTextV2Control, RichTextV2Definition } from '../../../../controls/rich-text-v2'\n\nimport { RichTextV2Value } from './rich-text-v2-value'\n\nconst ReadOnlyTextV1 = lazy(() => import('../rich-text/ReadOnlyText'))\n\nexport function renderRichTextV2({\n data,\n config,\n control,\n}: {\n data: DataType<RichTextV2Definition> | undefined\n config: ConfigType<RichTextV2Definition>\n control: RichTextV2Control | null\n}): ReactNode {\n // See `renderSlot` comments\n return RichTextV2Definition.isV1Data(data) ? (\n <ReadOnlyTextV1 text={data} />\n ) : (\n <RichTextV2Value data={data} config={config} instanceKey={control?.instanceKey} />\n )\n}\n"],"mappings":"AAqBI;AArBJ,SAAyB,YAAY;AAIrC,SAA4B,4BAA4B;AAExD,SAAS,uBAAuB;AAEhC,MAAM,iBAAiB,KAAK,MAAM,OAAO,2BAA2B,CAAC;AAE9D,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,GAIc;AAEZ,SAAO,qBAAqB,SAAS,IAAI,IACvC,oBAAC,kBAAe,MAAM,MAAM,IAE5B,oBAAC,mBAAgB,MAAY,QAAgB,aAAa,SAAS,aAAa;AAEpF;","names":[]}
@@ -7,9 +7,9 @@ const ReadOnlyText = lazy(() => import("./ReadOnlyTextV2"));
7
7
  function RichTextV2Value({
8
8
  data,
9
9
  config,
10
- control
10
+ instanceKey
11
11
  }) {
12
- return useIsReadOnly() ? /* @__PURE__ */ jsx(ReadOnlyText, { text: data, config }) : /* @__PURE__ */ jsx(EditableText, { text: data, config, control });
12
+ return useIsReadOnly() ? /* @__PURE__ */ jsx(ReadOnlyText, { text: data, config }) : /* @__PURE__ */ jsx(EditableText, { text: data, config, instanceKey });
13
13
  }
14
14
  export {
15
15
  RichTextV2Value
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/rich-text-v2-value.tsx"],"sourcesContent":["'use client'\n\nimport { lazy } from 'react'\n\nimport { type ConfigType } from '@makeswift/controls'\n\nimport {\n type RichTextDataV2,\n RichTextV2Definition,\n RichTextV2Control,\n} from '../../../../controls/rich-text-v2'\n\nimport { useIsReadOnly } from '../../hooks/use-is-read-only'\n\nconst EditableText = lazy(() => import('./EditableTextV2'))\nconst ReadOnlyText = lazy(() => import('./ReadOnlyTextV2'))\n\nexport function RichTextV2Value({\n data,\n config,\n control,\n}: {\n data: RichTextDataV2 | undefined\n config: ConfigType<RichTextV2Definition>\n control: RichTextV2Control | null\n}) {\n return useIsReadOnly() ? (\n <ReadOnlyText text={data} config={config} />\n ) : (\n <EditableText text={data} config={config} control={control} />\n )\n}\n"],"mappings":";AA2BI;AAzBJ,SAAS,YAAY;AAUrB,SAAS,qBAAqB;AAE9B,MAAM,eAAe,KAAK,MAAM,OAAO,kBAAkB,CAAC;AAC1D,MAAM,eAAe,KAAK,MAAM,OAAO,kBAAkB,CAAC;AAEnD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SAAO,cAAc,IACnB,oBAAC,gBAAa,MAAM,MAAM,QAAgB,IAE1C,oBAAC,gBAAa,MAAM,MAAM,QAAgB,SAAkB;AAEhE;","names":[]}
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/rich-text-v2-value.tsx"],"sourcesContent":["'use client'\n\nimport { lazy } from 'react'\n\nimport { type ControlInstanceKey, type ConfigType } from '@makeswift/controls'\n\nimport { type RichTextDataV2, RichTextV2Definition } from '../../../../controls/rich-text-v2'\n\nimport { useIsReadOnly } from '../../hooks/use-is-read-only'\n\nconst EditableText = lazy(() => import('./EditableTextV2'))\nconst ReadOnlyText = lazy(() => import('./ReadOnlyTextV2'))\n\nexport function RichTextV2Value({\n data,\n config,\n instanceKey,\n}: {\n data: RichTextDataV2 | undefined\n config: ConfigType<RichTextV2Definition>\n instanceKey: ControlInstanceKey | undefined\n}) {\n return useIsReadOnly() ? (\n <ReadOnlyText text={data} config={config} />\n ) : (\n <EditableText text={data} config={config} instanceKey={instanceKey} />\n )\n}\n"],"mappings":";AAuBI;AArBJ,SAAS,YAAY;AAMrB,SAAS,qBAAqB;AAE9B,MAAM,eAAe,KAAK,MAAM,OAAO,kBAAkB,CAAC;AAC1D,MAAM,eAAe,KAAK,MAAM,OAAO,kBAAkB,CAAC;AAEnD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SAAO,cAAc,IACnB,oBAAC,gBAAa,MAAM,MAAM,QAAgB,IAE1C,oBAAC,gBAAa,MAAM,MAAM,QAAgB,aAA0B;AAExE;","names":[]}
@@ -9,9 +9,9 @@ type InstanceType = RichTextV2Control;
9
9
  type UserConfig = z.infer<typeof Definition.schema.userConfig>;
10
10
  type Config = UserConfig & {
11
11
  defaultValue: string;
12
- plugins: RichTextV2Plugin[];
13
12
  };
14
13
  declare class Definition extends BaseRichTextDefinition<ReactNode, Config, InstanceType> {
14
+ readonly plugins: RichTextV2Plugin[];
15
15
  constructor({ mode, defaultValue }: UserConfig, plugins?: RichTextV2Plugin[]);
16
16
  static generateParagraph(): string;
17
17
  static deserialize(data: DeserializedRecord, deserializeCallback: (r: DeserializedRecord) => ControlDefinition): RichTextV2Definition;
@@ -21,7 +21,7 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
21
21
  config: z.ZodObject<{
22
22
  mode: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"makeswift::controls::rich-text-v2::mode::inline">, z.ZodLiteral<"makeswift::controls::rich-text-v2::mode::block">]>>;
23
23
  defaultValue: z.ZodString;
24
- plugins: z.ZodArray<z.ZodObject<{
24
+ plugins: z.ZodOptional<z.ZodArray<z.ZodObject<{
25
25
  control: z.ZodOptional<z.ZodObject<{
26
26
  definition: S;
27
27
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -89,10 +89,11 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
89
89
  }>]: z.baseObjectInputType<{
90
90
  definition: S;
91
91
  }>[k_2]; }>>;
92
- }>[k_2_1]; }>, "many">;
92
+ }>[k_2_1]; }>, "many">>;
93
93
  }, "strip", z.ZodTypeAny, {
94
94
  defaultValue: string;
95
- plugins: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
95
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
96
+ plugins?: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
96
97
  control: z.ZodOptional<z.ZodObject<{
97
98
  definition: S;
98
99
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -124,11 +125,11 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
124
125
  definition: S;
125
126
  }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
126
127
  definition: S;
127
- }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[];
128
- mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
128
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[] | undefined;
129
129
  }, {
130
130
  defaultValue: string;
131
- plugins: { [k_2_1 in keyof z.baseObjectInputType<{
131
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
132
+ plugins?: { [k_2_1 in keyof z.baseObjectInputType<{
132
133
  control: z.ZodOptional<z.ZodObject<{
133
134
  definition: S;
134
135
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -152,15 +153,83 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
152
153
  }>]: z.baseObjectInputType<{
153
154
  definition: S;
154
155
  }>[k_2]; }>>;
155
- }>[k_2_1]; }[];
156
- mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
156
+ }>[k_2_1]; }[] | undefined;
157
157
  }>;
158
158
  definition: z.ZodObject<{
159
159
  type: z.ZodLiteral<"makeswift::controls::rich-text-v2">;
160
+ plugins: z.ZodOptional<z.ZodArray<z.ZodObject<{
161
+ control: z.ZodOptional<z.ZodObject<{
162
+ definition: S;
163
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
164
+ definition: S;
165
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
166
+ definition: S;
167
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
168
+ definition: S;
169
+ }>]: z.baseObjectInputType<{
170
+ definition: S;
171
+ }>[k_2]; }>>;
172
+ }, "strip", z.ZodTypeAny, { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
173
+ control: z.ZodOptional<z.ZodObject<{
174
+ definition: S;
175
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
176
+ definition: S;
177
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
178
+ definition: S;
179
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
180
+ definition: S;
181
+ }>]: z.baseObjectInputType<{
182
+ definition: S;
183
+ }>[k_2]; }>>;
184
+ }>, undefined extends { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
185
+ definition: S;
186
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
187
+ definition: S;
188
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
189
+ control: z.ZodOptional<z.ZodObject<{
190
+ definition: S;
191
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
192
+ definition: S;
193
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
194
+ definition: S;
195
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
196
+ definition: S;
197
+ }>]: z.baseObjectInputType<{
198
+ definition: S;
199
+ }>[k_2]; }>>;
200
+ }>, undefined extends { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
201
+ definition: S;
202
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
203
+ definition: S;
204
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }, { [k_2_1 in keyof z.baseObjectInputType<{
205
+ control: z.ZodOptional<z.ZodObject<{
206
+ definition: S;
207
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
208
+ definition: S;
209
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
210
+ definition: S;
211
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
212
+ definition: S;
213
+ }>]: z.baseObjectInputType<{
214
+ definition: S;
215
+ }>[k_2]; }>>;
216
+ }>]: z.baseObjectInputType<{
217
+ control: z.ZodOptional<z.ZodObject<{
218
+ definition: S;
219
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
220
+ definition: S;
221
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
222
+ definition: S;
223
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
224
+ definition: S;
225
+ }>]: z.baseObjectInputType<{
226
+ definition: S;
227
+ }>[k_2]; }>>;
228
+ }>[k_2_1]; }>, "many">>;
160
229
  config: z.ZodObject<{
161
230
  mode: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"makeswift::controls::rich-text-v2::mode::inline">, z.ZodLiteral<"makeswift::controls::rich-text-v2::mode::block">]>>;
162
231
  defaultValue: z.ZodString;
163
- plugins: z.ZodArray<z.ZodObject<{
232
+ plugins: z.ZodOptional<z.ZodArray<z.ZodObject<{
164
233
  control: z.ZodOptional<z.ZodObject<{
165
234
  definition: S;
166
235
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -228,10 +297,11 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
228
297
  }>]: z.baseObjectInputType<{
229
298
  definition: S;
230
299
  }>[k_2]; }>>;
231
- }>[k_2_1]; }>, "many">;
300
+ }>[k_2_1]; }>, "many">>;
232
301
  }, "strip", z.ZodTypeAny, {
233
302
  defaultValue: string;
234
- plugins: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
303
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
304
+ plugins?: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
235
305
  control: z.ZodOptional<z.ZodObject<{
236
306
  definition: S;
237
307
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -263,11 +333,11 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
263
333
  definition: S;
264
334
  }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
265
335
  definition: S;
266
- }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[];
267
- mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
336
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[] | undefined;
268
337
  }, {
269
338
  defaultValue: string;
270
- plugins: { [k_2_1 in keyof z.baseObjectInputType<{
339
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
340
+ plugins?: { [k_2_1 in keyof z.baseObjectInputType<{
271
341
  control: z.ZodOptional<z.ZodObject<{
272
342
  definition: S;
273
343
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -291,14 +361,14 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
291
361
  }>]: z.baseObjectInputType<{
292
362
  definition: S;
293
363
  }>[k_2]; }>>;
294
- }>[k_2_1]; }[];
295
- mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
364
+ }>[k_2_1]; }[] | undefined;
296
365
  }>;
297
366
  }, "strip", z.ZodTypeAny, {
298
367
  type: "makeswift::controls::rich-text-v2";
299
368
  config: {
300
369
  defaultValue: string;
301
- plugins: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
370
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
371
+ plugins?: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
302
372
  control: z.ZodOptional<z.ZodObject<{
303
373
  definition: S;
304
374
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -330,14 +400,47 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
330
400
  definition: S;
331
401
  }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
332
402
  definition: S;
333
- }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[];
334
- mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
403
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[] | undefined;
335
404
  };
405
+ plugins?: { [k_1_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
406
+ control: z.ZodOptional<z.ZodObject<{
407
+ definition: S;
408
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
409
+ definition: S;
410
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
411
+ definition: S;
412
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
413
+ definition: S;
414
+ }>]: z.baseObjectInputType<{
415
+ definition: S;
416
+ }>[k_2]; }>>;
417
+ }>, undefined extends { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
418
+ definition: S;
419
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
420
+ definition: S;
421
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
422
+ control: z.ZodOptional<z.ZodObject<{
423
+ definition: S;
424
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
425
+ definition: S;
426
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
427
+ definition: S;
428
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
429
+ definition: S;
430
+ }>]: z.baseObjectInputType<{
431
+ definition: S;
432
+ }>[k_2]; }>>;
433
+ }>, undefined extends { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
434
+ definition: S;
435
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
436
+ definition: S;
437
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; } | undefined ? never : "control">[k_1_1]; }[] | undefined;
336
438
  }, {
337
439
  type: "makeswift::controls::rich-text-v2";
338
440
  config: {
339
441
  defaultValue: string;
340
- plugins: { [k_2_1 in keyof z.baseObjectInputType<{
442
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
443
+ plugins?: { [k_2_1 in keyof z.baseObjectInputType<{
341
444
  control: z.ZodOptional<z.ZodObject<{
342
445
  definition: S;
343
446
  }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
@@ -361,9 +464,33 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
361
464
  }>]: z.baseObjectInputType<{
362
465
  definition: S;
363
466
  }>[k_2]; }>>;
364
- }>[k_2_1]; }[];
365
- mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
467
+ }>[k_2_1]; }[] | undefined;
366
468
  };
469
+ plugins?: { [k_2_1 in keyof z.baseObjectInputType<{
470
+ control: z.ZodOptional<z.ZodObject<{
471
+ definition: S;
472
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
473
+ definition: S;
474
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
475
+ definition: S;
476
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
477
+ definition: S;
478
+ }>]: z.baseObjectInputType<{
479
+ definition: S;
480
+ }>[k_2]; }>>;
481
+ }>]: z.baseObjectInputType<{
482
+ control: z.ZodOptional<z.ZodObject<{
483
+ definition: S;
484
+ }, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
485
+ definition: S;
486
+ }>, undefined extends S["_output"] ? never : "definition">]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
487
+ definition: S;
488
+ }>, undefined extends S["_output"] ? never : "definition">[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
489
+ definition: S;
490
+ }>]: z.baseObjectInputType<{
491
+ definition: S;
492
+ }>[k_2]; }>>;
493
+ }>[k_2_1]; }[] | undefined;
367
494
  }>;
368
495
  type: z.ZodLiteral<"makeswift::controls::rich-text-v2">;
369
496
  data: z.ZodUnion<[z.ZodObject<{
@@ -1390,6 +1517,16 @@ declare class Definition extends BaseRichTextDefinition<ReactNode, Config, Insta
1390
1517
  defaultValue?: string | undefined;
1391
1518
  }>;
1392
1519
  };
1520
+ static configSchema(): z.ZodObject<{
1521
+ mode: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"makeswift::controls::rich-text-v2::mode::inline">, z.ZodLiteral<"makeswift::controls::rich-text-v2::mode::block">]>>;
1522
+ defaultValue: z.ZodString;
1523
+ }, "strip", z.ZodTypeAny, {
1524
+ defaultValue: string;
1525
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
1526
+ }, {
1527
+ defaultValue: string;
1528
+ mode?: "makeswift::controls::rich-text-v2::mode::inline" | "makeswift::controls::rich-text-v2::mode::block" | undefined;
1529
+ }>;
1393
1530
  get configSchema(): SchemaType<Config>;
1394
1531
  createInstance(args: ControlInstanceArgs): RichTextV2Control;
1395
1532
  resolveValue(data: DataType | undefined, _resolver: ResourceResolver, _stylesheet: Stylesheet, control?: InstanceType): Resolvable<ReactNode | undefined>;