@ggraphic/editor 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
@@ -2,5 +2,5 @@ import * as Y from 'yjs';
2
2
  export declare function useYjsPageStateSync(options: {
3
3
  pageYMap: Y.Map<unknown> | null;
4
4
  isSynced: boolean;
5
- onRemoteState: (partial: Record<string, unknown>, base: Record<string, unknown>) => void;
5
+ onRemoteState: (partial: Record<string, unknown>, base: Record<string, unknown>, own: boolean) => void;
6
6
  }): void;
@@ -28,7 +28,10 @@ import { PAGES_STATE_ORIGIN } from './useYjsPages.js';
28
28
  *
29
29
  * Own writes with another origin (a deck op, a deck undo's restore, a version
30
30
  * lift) reach the canvas like remote ones: another stack owns them or they
31
- * are not undoable, so the canvas history takes them in.
31
+ * are not undoable, so the canvas history takes them in. They are reported
32
+ * with `own: true` (a local Yjs transaction): the history takes them in only
33
+ * where it still holds the value they replaced, so undoing a deck op leaves
34
+ * the steps before it undoable.
32
35
  */
33
36
  /** Own values kept per key, to name the one a remote write started from. */
34
37
  const OWN_VALUES_PER_KEY = 32;
@@ -109,7 +112,7 @@ export function useYjsPageStateSync(options) {
109
112
  }
110
113
  }
111
114
  if (Object.keys(partial).length > 0)
112
- onRemoteStateRef.current(partial, base);
115
+ onRemoteStateRef.current(partial, base, events[0].transaction.local);
113
116
  };
114
117
  pageYMap.observeDeep(handler);
115
118
  return () => {
@@ -165,11 +165,11 @@ function GenericCanvasWithRef(props) {
165
165
  // is measured from the values its writer started from, not from this
166
166
  // canvas: an own value not yet written, or one the write overrode, is no
167
167
  // part of the other client's edit.
168
- const handleRemotePageState = useCallback((partial, base) => {
168
+ const handleRemotePageState = useCallback((partial, base, own) => {
169
169
  const committed = committedStateRef.current;
170
170
  store
171
171
  .getState()
172
- .rebaseHistory(config.createInitialState({ ...committed, ...base }), config.createInitialState({ ...committed, ...partial }));
172
+ .rebaseHistory(config.createInitialState({ ...committed, ...base }), config.createInitialState({ ...committed, ...partial }), own);
173
173
  setStateRaw((prev) => config.createInitialState({ ...prev, ...partial }));
174
174
  setRemoteStateCount((n) => n + 1);
175
175
  }, [store, config]);
@@ -66,7 +66,7 @@ brand?: BrandPack): {
66
66
  };
67
67
  export declare function createAdditionalTextActions<TState extends {
68
68
  additionalTexts: AdditionalText[];
69
- }>(getState: () => TState, setState: StateSetter<TState>, saveToHistory: HistorySaver<TState>, debouncedSaveToHistory: HistorySaver<TState>, canvasWidth: number, canvasHeight: number, fontColor?: string, insertScale?: number,
69
+ }>(getState: () => TState, setState: StateSetter<TState>, saveToHistory: HistorySaver<TState>, debouncedSaveToHistory: HistorySaver<TState>, canvasWidth: number, canvasHeight: number, fontColor?: string,
70
70
  /** The pack of the page's document; the active brand by default. */
71
71
  brand?: BrandPack): {
72
72
  addHeader: () => void;
@@ -139,7 +139,7 @@ history?: CanvasActionHistory): {
139
139
  removeUserImage: (id: string) => void;
140
140
  };
141
141
  export declare function createElementActions<TState extends BaseCanvasState>(getState: () => TState, setState: StateSetter<TState>, saveToHistory: HistorySaver<TState>, debouncedSaveToHistory: HistorySaver<TState>, canvasWidth: number, canvasHeight: number, fontColor?: string, chartColors?: readonly string[],
142
- /** Startgröße neuer Elemente (`insertScaleFor`); 1 = Sharepic-Werte. */
142
+ /** Startgröße neuer Elemente außer Text (`insertScaleFor`); 1 = Sharepic-Werte. Text wächst selbst mit der Seitenbreite. */
143
143
  insertScale?: number,
144
144
  /**
145
145
  * The pack of the page's document (`FullCanvasConfig.brand`): what new elements take their
@@ -237,39 +237,45 @@ brand = activeBrand()) {
237
237
  // ============================================================================
238
238
  // ADDITIONAL TEXT ACTIONS
239
239
  // ============================================================================
240
+ /** The page width the text presets are set for; 80 % of it is a preset's width. */
241
+ const TEXT_PRESET_PAGE_WIDTH = 1080;
242
+ const TEXT_PRESET_WIDTH = TEXT_PRESET_PAGE_WIDTH * 0.8;
240
243
  // Read per call, not at import: the brand packs are registered after the modules load.
241
244
  // Every text is born bound to the brand font its family stands for, so a brand change takes it along.
242
245
  function additionalTextDefaults(brand) {
243
246
  const { fonts } = brand;
244
247
  return {
245
248
  header: {
246
- fontSize: 48,
249
+ fontSize: 120,
247
250
  fontFamily: `${fonts.headline}, Arial, sans-serif`,
248
251
  bind: { fontFamily: { ref: 'font.headline', value: fonts.headline } },
249
252
  fontStyle: 'normal',
250
- width: 400,
253
+ width: TEXT_PRESET_WIDTH,
251
254
  },
252
255
  subheader: {
253
- fontSize: 36,
256
+ fontSize: 72,
254
257
  fontFamily: `${fonts.headline}, Arial, sans-serif`,
255
258
  bind: { fontFamily: { ref: 'font.headline', value: fonts.headline } },
256
259
  fontStyle: 'normal',
257
- width: 400,
260
+ width: TEXT_PRESET_WIDTH,
258
261
  },
259
262
  body: {
260
- fontSize: 32,
263
+ fontSize: 56,
261
264
  fontFamily: `${fonts.body}, Arial, sans-serif`,
262
265
  bind: { fontFamily: { ref: 'font.body', value: fonts.body } },
263
- width: 400,
266
+ width: TEXT_PRESET_WIDTH,
264
267
  },
265
268
  };
266
269
  }
267
270
  /**
268
- * Voreinstellung einer Textart, mit `insertScale` vergrößert; zentriert über
269
- * der Seitenmitte. Bei 1 genau die Sharepic-Werte.
271
+ * Voreinstellung einer Textart, mit der Seitenbreite skaliert — auf jedem
272
+ * Format, nicht nur auf Folien (ein Text, der kleiner startet als die
273
+ * Überschriften der Vorlagen, wirkt wie nicht eingefügt); zentriert über der
274
+ * Seitenmitte. Bei 1080 px genau die Werte oben.
270
275
  */
271
- function textPreset(type, canvasWidth, s, brand) {
276
+ function textPreset(type, canvasWidth, brand) {
272
277
  const preset = additionalTextDefaults(brand)[type];
278
+ const s = canvasWidth / TEXT_PRESET_PAGE_WIDTH;
273
279
  const width = preset.width * s;
274
280
  return {
275
281
  ...preset,
@@ -278,7 +284,7 @@ function textPreset(type, canvasWidth, s, brand) {
278
284
  x: canvasWidth / 2 - width / 2,
279
285
  };
280
286
  }
281
- export function createAdditionalTextActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, fontColor = '#ffffff', insertScale = 1,
287
+ export function createAdditionalTextActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, fontColor = '#ffffff',
282
288
  /** The pack of the page's document; the active brand by default. */
283
289
  brand = activeBrand()) {
284
290
  return {
@@ -288,7 +294,7 @@ brand = activeBrand()) {
288
294
  text: messages().sidebar.text.defaultHeader,
289
295
  type: 'header',
290
296
  y: canvasHeight / 3,
291
- ...textPreset('header', canvasWidth, insertScale, brand),
297
+ ...textPreset('header', canvasWidth, brand),
292
298
  fill: fontColor,
293
299
  };
294
300
  setState((prev) => ({
@@ -303,7 +309,7 @@ brand = activeBrand()) {
303
309
  text: messages().sidebar.text.defaultSubheader,
304
310
  type: 'subheader',
305
311
  y: canvasHeight * 0.4,
306
- ...textPreset('subheader', canvasWidth, insertScale, brand),
312
+ ...textPreset('subheader', canvasWidth, brand),
307
313
  fill: fontColor,
308
314
  };
309
315
  setState((prev) => ({
@@ -318,7 +324,7 @@ brand = activeBrand()) {
318
324
  text: messages().sidebar.text.defaultBody,
319
325
  type: 'body',
320
326
  y: canvasHeight / 2,
321
- ...textPreset('body', canvasWidth, insertScale, brand),
327
+ ...textPreset('body', canvasWidth, brand),
322
328
  fill: fontColor,
323
329
  };
324
330
  setState((prev) => ({
@@ -337,7 +343,7 @@ brand = activeBrand()) {
337
343
  text: content,
338
344
  type: 'body',
339
345
  y: canvasHeight / 2,
340
- ...textPreset('body', canvasWidth, insertScale, brand),
346
+ ...textPreset('body', canvasWidth, brand),
341
347
  fill: fontColor,
342
348
  };
343
349
  setState((prev) => ({
@@ -615,7 +621,7 @@ history) {
615
621
  // COMBINED BASE ACTIONS
616
622
  // ============================================================================
617
623
  export function createElementActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, fontColor, chartColors,
618
- /** Startgröße neuer Elemente (`insertScaleFor`); 1 = Sharepic-Werte. */
624
+ /** Startgröße neuer Elemente außer Text (`insertScaleFor`); 1 = Sharepic-Werte. Text wächst selbst mit der Seitenbreite. */
619
625
  insertScale = 1,
620
626
  /**
621
627
  * The pack of the page's document (`FullCanvasConfig.brand`): what new elements take their
@@ -634,7 +640,7 @@ history) {
634
640
  { defaultColor: fontColor, defaultScale: insertScale }),
635
641
  ...createShapeActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, undefined, insertScale, brand),
636
642
  ...createIllustrationActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, brand),
637
- ...createAdditionalTextActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, fontColor, insertScale, brand),
643
+ ...createAdditionalTextActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, fontColor, brand),
638
644
  ...createPillBadgeActions(getState, setState, saveToHistory, debouncedSaveToHistory, brand),
639
645
  ...createCircleBadgeActions(getState, setState, saveToHistory, debouncedSaveToHistory, brand),
640
646
  ...createChartActions(getState, setState, saveToHistory, debouncedSaveToHistory, canvasWidth, canvasHeight, chartColors, insertScale, brand),
@@ -99,9 +99,10 @@ export declare function getCanvasFormat(id: string): CanvasFormat | null;
99
99
  /** The one place that answers: is this a slide deck? A host's slide format joins the `slides` group. */
100
100
  export declare function isSlideFormat(format: CanvasFormat): boolean;
101
101
  /**
102
- * Startgröße neu eingefügter Elemente (Text, Formen, Icons, Grafiken,
103
- * Diagramme): die Voreinstellungen sind für 1080 px breite Sharepics gemacht,
104
- * auf einer Folie wachsen sie mit der Breite. Alle anderen Formate: 1.
102
+ * Startgröße neu eingefügter Elemente (Formen, Icons, Grafiken, Diagramme):
103
+ * die Voreinstellungen sind für 1080 px breite Sharepics gemacht, auf einer
104
+ * Folie wachsen sie mit der Breite. Alle anderen Formate: 1. Text skaliert
105
+ * auf jedem Format mit der Seitenbreite (`textPreset`).
105
106
  */
106
107
  export declare function insertScaleFor(format: CanvasFormat): number;
107
108
  export declare function isPrintFormat(format: CanvasFormat): format is PrintCanvasFormat;
@@ -154,9 +154,10 @@ export function isSlideFormat(format) {
154
154
  return format.group === 'slides';
155
155
  }
156
156
  /**
157
- * Startgröße neu eingefügter Elemente (Text, Formen, Icons, Grafiken,
158
- * Diagramme): die Voreinstellungen sind für 1080 px breite Sharepics gemacht,
159
- * auf einer Folie wachsen sie mit der Breite. Alle anderen Formate: 1.
157
+ * Startgröße neu eingefügter Elemente (Formen, Icons, Grafiken, Diagramme):
158
+ * die Voreinstellungen sind für 1080 px breite Sharepics gemacht, auf einer
159
+ * Folie wachsen sie mit der Breite. Alle anderen Formate: 1. Text skaliert
160
+ * auf jedem Format mit der Seitenbreite (`textPreset`).
160
161
  */
161
162
  export function insertScaleFor(format) {
162
163
  return isSlideFormat(format) ? format.width / 1080 : 1;
@@ -79,9 +79,12 @@ export interface CanvasEditorActions<TComponentState extends Record<string, unkn
79
79
  /**
80
80
  * Another client changed the page from `prev` to `next`: write that change
81
81
  * into every entry, so undo and redo only ever revert this client's own
82
- * steps (#160).
82
+ * steps (#160). With `own`, the write is this client's own from another
83
+ * stack (a deck op or its undo): it reaches only the entries that still hold
84
+ * the replaced value, so its inverse restores every entry and the steps
85
+ * before it stay undoable.
83
86
  */
84
- rebaseHistory: (prev: TComponentState, next: TComponentState) => void;
87
+ rebaseHistory: (prev: TComponentState, next: TComponentState, own?: boolean) => void;
85
88
  undo: () => void;
86
89
  redo: () => void;
87
90
  /** Merkt den aktuellen Verlaufsstand als Beginn einer Sitzung; `null` ohne Verlauf. */
@@ -13,7 +13,7 @@ import { immer } from 'zustand/middleware/immer';
13
13
  import { createStore } from 'zustand/vanilla';
14
14
  import { activeBrand } from '../brand/brandRegistry.js';
15
15
  import { nextHistoryStamp } from '../utils/historyStamp.js';
16
- import { applyHistoryRebase, planHistoryRebase } from '../utils/rebaseHistoryState.js';
16
+ import { applyHistoryRebase, applyOwnWrite, planHistoryRebase, } from '../utils/rebaseHistoryState.js';
17
17
  import { DEFAULT_FORMAT_ID, getCanvasFormatOrDefault } from '../formats/index.js';
18
18
  // Einzige Stelle, die die Auswahl schreibt: `selectedElement` ist genau dann
19
19
  // gesetzt, wenn ein einziges Element ausgewählt ist. Alle Einzel-Oberflächen
@@ -141,12 +141,16 @@ export function createCanvasEditorStore() {
141
141
  state.historyIndex++;
142
142
  }
143
143
  }),
144
- rebaseHistory: (prev, next) => {
145
- const plan = planHistoryRebase(prev, next);
146
- if (plan.length === 0)
144
+ rebaseHistory: (prev, next, own = false) => {
145
+ const plan = own ? null : planHistoryRebase(prev, next);
146
+ if (plan?.length === 0)
147
147
  return;
148
148
  const { history } = get();
149
- const rebased = history.map((entry) => entry.componentState ? applyHistoryRebase(entry.componentState, plan) : null);
149
+ const rebased = history.map((entry) => !entry.componentState
150
+ ? null
151
+ : plan
152
+ ? applyHistoryRebase(entry.componentState, plan)
153
+ : applyOwnWrite(entry.componentState, prev, next));
150
154
  if (rebased.every((componentState, i) => componentState === history[i].componentState))
151
155
  return;
152
156
  set((state) => {
@@ -68,4 +68,13 @@ export type HistoryRebase = KeyPlan[];
68
68
  export declare function planHistoryRebase(prev: Rec, next: Rec): HistoryRebase;
69
69
  /** `entry` with the planned change applied; `entry` itself when the change does not reach it. */
70
70
  export declare function applyHistoryRebase(entry: Rec, plan: HistoryRebase): Rec;
71
+ /**
72
+ * `entry` with an own write from another stack applied (a deck op, its undo
73
+ * by the page-level Y.UndoManager, a version lift): per key, only where the
74
+ * entry still holds the value the write replaced. An entry that holds another
75
+ * value predates an own step, and that step stays undoable. Applied twice,
76
+ * once for the write and once for its exact inverse, every entry is back
77
+ * where it was. `entry` itself when the write does not reach it.
78
+ */
79
+ export declare function applyOwnWrite(entry: Rec, prev: Rec, next: Rec): Rec;
71
80
  export {};
@@ -206,3 +206,29 @@ export function applyHistoryRebase(entry, plan) {
206
206
  }
207
207
  return result ?? entry;
208
208
  }
209
+ /**
210
+ * `entry` with an own write from another stack applied (a deck op, its undo
211
+ * by the page-level Y.UndoManager, a version lift): per key, only where the
212
+ * entry still holds the value the write replaced. An entry that holds another
213
+ * value predates an own step, and that step stays undoable. Applied twice,
214
+ * once for the write and once for its exact inverse, every entry is back
215
+ * where it was. `entry` itself when the write does not reach it.
216
+ */
217
+ export function applyOwnWrite(entry, prev, next) {
218
+ let result = null;
219
+ for (const key of new Set([...Object.keys(prev), ...Object.keys(next)])) {
220
+ if (jsonEqual(prev[key], next[key]))
221
+ continue;
222
+ const holdsPrev = Object.hasOwn(prev, key)
223
+ ? Object.hasOwn(entry, key) && jsonEqual(entry[key], prev[key])
224
+ : !Object.hasOwn(entry, key);
225
+ if (!holdsPrev)
226
+ continue;
227
+ result ??= { ...entry };
228
+ if (Object.hasOwn(next, key))
229
+ result[key] = next[key];
230
+ else
231
+ delete result[key];
232
+ }
233
+ return result ?? entry;
234
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ggraphic/editor",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.5",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",