valueDraftFor method

CatalogValueDraft valueDraftFor(
  1. CatalogRow row,
  2. String locale
)

Implementation

CatalogValueDraft valueDraftFor(CatalogRow row, String locale) {
  final key = _draftKey(row.keyPath, locale);
  final existing = _valueDrafts[key];
  final sourceValue = row.valuesByLocale[_queue.meta?.sourceLocale];
  final editorMode = detectEditorMode(
    serverValue: row.valuesByLocale[locale],
    sourceValue: sourceValue,
    rawPinned: existing?.rawPinned ?? false,
  );
  final initialValue = buildInitialCatalogValue(
    serverValue: row.valuesByLocale[locale],
    sourceValue: sourceValue,
    editorMode: editorMode,
  );
  if (existing == null) {
    final draft = CatalogValueDraft(
      keyPath: row.keyPath,
      locale: locale,
      baseValue: cloneCatalogValue(row.valuesByLocale[locale]),
      value: cloneCatalogValue(initialValue),
      editorMode: editorMode,
      rawPinned: editorMode == CatalogEditorMode.raw,
      rawText: prettyCatalogJson(initialValue),
    );
    _valueDrafts[key] = draft;
    return draft;
  }

  if (existing.syncState == CatalogDraftSyncState.clean || existing.syncState == CatalogDraftSyncState.saved) {
    existing.baseValue = cloneCatalogValue(row.valuesByLocale[locale]);
    existing.value = cloneCatalogValue(initialValue);
    existing.editorMode = editorMode;
    existing.rawPinned = editorMode == CatalogEditorMode.raw;
    existing.rawText = prettyCatalogJson(initialValue);
    existing.rawError = null;
    existing.errorMessage = null;
    existing.touched = false;
  }
  return existing;
}