@templatical/core 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Block, BlockDefaults, BlockLock, BlockLockHolder, BlockType, CollaborationActor, CollaborationConflictCode, CollaborationConnectionState, CollaborationMember, CollaborationProvider, CollaborationRemoteChange, Comment, CommentAuthor, CommentInput, CommentPatch, CommentsListParams, CommentsProvider, CustomBlock, CustomBlockDefinition, MediaProvider, Operation, OperationError, SavedBlock, SavedBlockPatch, SavedBlocksListParams, SavedBlocksProvider, Template, TemplateContent, TemplateDefaults, TemplateSaveTrigger, TemplateSettings, TemplateVersion, TemplatesProvider, UiTheme, VersionHistoryListParams, VersionHistoryProvider, ViewportSize, invertOperations } from "@templatical/types";
1
+ import { Block, BlockDefaults, BlockLock, BlockLockHolder, BlockType, CollaborationActor, CollaborationConflictCode, CollaborationConnectionState, CollaborationMember, CollaborationProvider, CollaborationRemoteChange, Comment, CommentAuthor, CommentInput, CommentPatch, CommentsListParams, CommentsProvider, CustomBlock, CustomBlockDefinition, MediaProvider, Operation, OperationError, SavedBlock, SavedBlockPatch, SavedBlocksListParams, SavedBlocksProvider, SetDefaultLocaleOperation, Template, TemplateContent, TemplateDefaults, TemplateSaveTrigger, TemplateSettings, TemplateVersion, TemplatesProvider, UiTheme, VersionHistoryListParams, VersionHistoryProvider, ViewportSize, invertOperations } from "@templatical/types";
2
2
  import { ComputedRef, DeepReadonly, Ref } from "@vue/reactivity";
3
3
  import { ComputedRef as ComputedRef$1, Ref as Ref$1 } from "vue";
4
4
  interface EditorState {
@@ -13,6 +13,7 @@ interface EditorState {
13
13
  */
14
14
  template: Template | null;
15
15
  content: TemplateContent;
16
+ activeLocale: string | null;
16
17
  selectedBlockId: string | null;
17
18
  viewport: ViewportSize;
18
19
  darkMode: boolean;
@@ -26,6 +27,11 @@ interface EditorState {
26
27
  }
27
28
  interface UseEditorOptions {
28
29
  content: TemplateContent;
30
+ localization?: {
31
+ locales: string[];
32
+ };
33
+ onLocaleChange?: (locale: string) => void;
34
+ onStructureChange?: () => void;
29
35
  defaultFontFamily?: string;
30
36
  templateDefaults?: TemplateDefaults;
31
37
  /**
@@ -33,6 +39,10 @@ interface UseEditorOptions {
33
39
  * editor's own mutators leave it alone.
34
40
  */
35
41
  lockedBlocks?: Readonly<Ref<ReadonlyMap<string, unknown>>>;
42
+ /** The language view for property edits and selection; absent or `null` is default. */
43
+ lockLocale?: Readonly<Ref<string | null>>;
44
+ /** This editor's session; its own locks never block local edits. */
45
+ lockSessionId?: string;
36
46
  /**
37
47
  * Storage backend for the template's save/load lifecycle. Omit it and
38
48
  * `create()` / `load()` / `save()` reject — the editor keeps working as a
@@ -51,6 +61,16 @@ interface UseEditorReturn {
51
61
  loadVersion: Readonly<Ref<number>>;
52
62
  content: Ref<TemplateContent>;
53
63
  selectedBlock: Ref<Block | null>;
64
+ activeLocale: Ref<string | null>;
65
+ setActiveLocale: (locale: string | null) => void;
66
+ addLocale: (locale: string) => void;
67
+ removeLocale: (locale: string) => void;
68
+ setBlockHidden: (blockId: string, hidden: boolean) => void;
69
+ resetLocaleFields: (blockId: string, paths?: string[]) => void;
70
+ keepTranslations: (blockId: string, paths: string[]) => void;
71
+ setCustomBlockDefinitions: (defs: readonly CustomBlockDefinition[]) => void;
72
+ /** Captures registered custom text paths for deterministic default-language replay. Pure. */
73
+ createSetDefaultLocaleOperation: (locale: string) => SetDefaultLocaleOperation;
54
74
  setContent: (content: TemplateContent, markDirty?: boolean) => void;
55
75
  selectBlock: (blockId: string | null) => void;
56
76
  setViewport: (viewport: ViewportSize) => void;
@@ -121,6 +141,7 @@ interface UseHistoryReturn {
121
141
  recordDebounced: (blockId: string) => void;
122
142
  clear: () => void;
123
143
  destroy: () => void;
144
+ flushDebounce?: () => void;
124
145
  }
125
146
  export declare function useHistory(options: UseHistoryOptions): UseHistoryReturn;
126
147
  interface UseBlockActionsOptions {
@@ -223,6 +244,12 @@ interface HistoryInterceptorEditor {
223
244
  updateBlock: (blockId: string, updates: Partial<Block>) => void;
224
245
  updateSettings: (updates: Partial<TemplateSettings>) => void;
225
246
  isBlockLocked: (blockId: string) => boolean;
247
+ activeLocale?: Ref<string | null>;
248
+ addLocale?: (locale: string) => void;
249
+ removeLocale?: (locale: string) => void;
250
+ setBlockHidden?: (blockId: string, hidden: boolean) => void;
251
+ resetLocaleFields?: (blockId: string, paths?: string[]) => void;
252
+ keepTranslations?: (blockId: string, paths: string[]) => void;
226
253
  }
227
254
  /**
228
255
  * Wraps editor mutation methods to record history snapshots before each
@@ -249,11 +276,22 @@ export declare function useHistoryInterceptor(editor: HistoryInterceptorEditor,
249
276
  * 5. `columns` shrinkage, once the dropped columns are empty.
250
277
  * 6. Deletion of sections whose surviving blocks have moved out.
251
278
  * 7. Key changes on blocks, then on settings.
279
+ * 8. Added locales, block and settings layers, then removed locales.
252
280
  *
253
281
  * No operation carries `expect`: an ordinary edit applies over anything that
254
282
  * doesn't conflict with it, and locks keep two people off one block.
255
283
  */
256
284
  export declare function diffContent(before: TemplateContent, after: TemplateContent): Operation[];
285
+ /**
286
+ * Turn operations written against `resolveLocale(base, locale)` into
287
+ * operations on `base`: changed translatable text becomes `text` (stamped
288
+ * with the base value's hash), other changed properties become `set`,
289
+ * structure changes go to the shared tree (a new block's values become
290
+ * default values, as a paste in that view does). Throws the engine's
291
+ * OperationError when `ops` don't apply to the projection or include a
292
+ * whole-template `setContent` replacement.
293
+ */
294
+ export declare function mapLocalizedOperations(base: TemplateContent, locale: string, ops: Operation[], definitions?: readonly CustomBlockDefinition[]): Operation[];
257
295
  /** The template fields the controller reads, as the editor's readonly state holds them. */
258
296
  type CollaborationTemplate = DeepReadonly<Pick<Template, "id" | "revision" | "content">>;
259
297
  /** The slice of the editor the controller reads and writes. */
@@ -296,13 +334,13 @@ interface CollaborationRemoteResync {
296
334
  }
297
335
  /** How {@link UseCollaborationReturn.applyOperations} sends a batch. */
298
336
  interface CollaborationApplyOptions {
299
- /** Sent as the batch's `origin`: an AI turn produced it (BY9). */
300
- origin: "ai";
337
+ /** Sent as the batch's `origin` when an AI turn produced it; absent for the session's own edits. */
338
+ origin?: "ai";
301
339
  /**
302
- * The turn the batch belongs to. Batches of one turn share an undo step
303
- * while that step is the newest one.
340
+ * The AI turn the batch belongs to; absent for the session's own edits.
341
+ * Batches of one defined turn share the newest undo step.
304
342
  */
305
- turn: string;
343
+ turn?: string;
306
344
  }
307
345
  /** What {@link UseCollaborationReturn.applyOperations} answers. */
308
346
  type CollaborationApplyResult = {
@@ -348,8 +386,12 @@ interface UseCollaborationReturn {
348
386
  readonly sessionId: string;
349
387
  /** Everyone with the template open, this session included; empty without presence. */
350
388
  members: Readonly<Ref<readonly CollaborationMember[]>>;
351
- /** Blocks other sessions hold, by block id. */
389
+ /** Blocks other sessions hold, keyed by `${blockId}\u0000${locale ?? ""}`. */
352
390
  locks: Readonly<Ref<ReadonlyMap<string, BlockLock>>>;
391
+ locksOf: (blockId: string) => BlockLock[];
392
+ /** The selected language for lock requests; `null` is the default view. */
393
+ lockLocale: Readonly<Ref<string | null>>;
394
+ setLockLocale: (locale: string | null) => void;
353
395
  /** `null` before a realtime join, and for a backend without realtime. */
354
396
  connection: Readonly<Ref<CollaborationConnectionState | null>>;
355
397
  /** The last revision this session confirmed. */
@@ -374,10 +416,10 @@ interface UseCollaborationReturn {
374
416
  /** Whether the block exists in the content the backend confirmed. */
375
417
  hasConfirmedBlock: (blockId: string) => boolean;
376
418
  /**
377
- * Apply a batch this editor was handed (an AI turn's) as this session's
378
- * own: checked against the view with this session's locks, put on the
379
- * canvas, sent with its `origin`, and undone with the rest of its turn. A
380
- * refusal changes nothing and sends nothing.
419
+ * Apply an explicit batch as this session's edit, checking its locks first.
420
+ * Own edits have a separate undo step and no wire origin. AI batches carry
421
+ * their origin and share an undo step within a defined turn. A local refusal
422
+ * changes nothing and sends nothing.
381
423
  */
382
424
  applyOperations: (ops: Operation[], options: CollaborationApplyOptions) => CollaborationApplyResult;
383
425
  destroy: () => void;