@@ -10,15 +10,19 @@ import { getSubTree } from "roamjs-components/util";
1010import getSettingValueFromTree from "roamjs-components/util/getSettingValueFromTree" ;
1111import internalError from "~/utils/internalError" ;
1212import { getSetting } from "~/utils/extensionSettings" ;
13- import discourseConfigRef , {
14- getFormattedConfigTree ,
15- } from "~/utils/discourseConfigRef" ;
13+ import { USE_REIFIED_RELATIONS } from "~/data/userSettings" ;
14+ import discourseConfigRef from "~/utils/discourseConfigRef" ;
1615import { roamNodeToCondition } from "~/utils/parseQuery" ;
1716import type { DiscourseRelation } from "~/utils/getDiscourseRelations" ;
1817import type { DiscourseNode } from "~/utils/getDiscourseNodes" ;
1918import type { Condition } from "~/utils/types" ;
2019import { z } from "zod" ;
21- import { getUidAndBooleanSetting } from "~/utils/getExportSettings" ;
20+ import {
21+ getExportSettingsAndUids ,
22+ getUidAndBooleanSetting ,
23+ getUidAndStringSetting ,
24+ } from "~/utils/getExportSettings" ;
25+ import { getSuggestiveModeConfigAndUids } from "~/utils/getSuggestiveModeConfigSettings" ;
2226import { getLeftSidebarSettings } from "~/utils/getLeftSidebarSettings" ;
2327
2428import {
@@ -36,7 +40,7 @@ import {
3640 type DiscourseNodeSettings ,
3741 type Condition as SchemaCondition ,
3842} from "./zodSchema" ;
39- import { PERSONAL_KEYS , QUERY_KEYS } from "./settingKeys" ;
43+ import { PERSONAL_KEYS , QUERY_KEYS , GLOBAL_KEYS } from "./settingKeys" ;
4044
4145const isRecord = ( value : unknown ) : value is Record < string , unknown > =>
4246 typeof value === "object" && value !== null && ! Array . isArray ( value ) ;
@@ -342,85 +346,90 @@ const getLegacyRelationsSetting = (): Record<string, unknown> => {
342346 ) ;
343347} ;
344348
345- // Reconstructs global settings from getFormattedConfigTree() shape to match block-props schema shape
349+ // Reconstructs global settings from legacy Roam tree to match block-props schema shape
346350const getLegacyGlobalSetting = ( keys : string [ ] ) : unknown => {
347351 if ( keys . length === 0 ) return undefined ;
348352
349- const settings = getFormattedConfigTree ( ) ;
353+ const tree = discourseConfigRef . tree ;
350354 const firstKey = keys [ 0 ] ;
351355
352356 if ( firstKey === "Trigger" ) {
353- return settings . trigger . value || DEFAULT_GLOBAL_SETTINGS . Trigger ;
357+ return (
358+ getUidAndStringSetting ( { tree, text : "trigger" } ) . value ||
359+ DEFAULT_GLOBAL_SETTINGS . Trigger
360+ ) ;
354361 }
355362
356363 if ( firstKey === "Canvas page format" ) {
357364 return (
358- settings . canvasPageFormat . value ||
365+ getUidAndStringSetting ( { tree , text : "Canvas Page Format" } ) . value ||
359366 DEFAULT_GLOBAL_SETTINGS [ "Canvas page format" ]
360367 ) ;
361368 }
362369
363370 if ( firstKey === "Left sidebar" ) {
371+ const sidebar = getLeftSidebarSettings ( tree ) ;
364372 const leftSidebarSettings : Record < string , unknown > = { } ;
365- leftSidebarSettings [ "Children" ] = settings . leftSidebar . global . children . map (
373+ leftSidebarSettings [ "Children" ] = sidebar . global . children . map (
366374 ( c ) => c . text ,
367375 ) ;
368376 const sidebarSettingValues : Record < string , unknown > = { } ;
369377 sidebarSettingValues [ "Collapsable" ] =
370- settings . leftSidebar . global . settings ?. collapsable . value ??
378+ sidebar . global . settings ?. collapsable . value ??
371379 DEFAULT_GLOBAL_SETTINGS [ "Left sidebar" ] . Settings . Collapsable ;
372380 sidebarSettingValues [ "Folded" ] =
373- settings . leftSidebar . global . settings ?. folded . value ??
381+ sidebar . global . settings ?. folded . value ??
374382 DEFAULT_GLOBAL_SETTINGS [ "Left sidebar" ] . Settings . Folded ;
375383 leftSidebarSettings [ "Settings" ] = sidebarSettingValues ;
376384 if ( keys . length === 1 ) return leftSidebarSettings ;
377385 return readPathValue ( leftSidebarSettings , keys . slice ( 1 ) ) ;
378386 }
379387
380388 if ( firstKey === "Export" ) {
389+ const exp = getExportSettingsAndUids ( ) ;
381390 const exportSettings : Record < string , unknown > = { } ;
382391 exportSettings [ "Remove special characters" ] =
383- settings . export . removeSpecialCharacters . value ??
392+ exp . removeSpecialCharacters . value ??
384393 DEFAULT_GLOBAL_SETTINGS . Export [ "Remove special characters" ] ;
385394 exportSettings [ "Resolve block references" ] =
386- settings . export . optsRefs . value ??
395+ exp . optsRefs . value ??
387396 DEFAULT_GLOBAL_SETTINGS . Export [ "Resolve block references" ] ;
388397 exportSettings [ "Resolve block embeds" ] =
389- settings . export . optsEmbeds . value ??
398+ exp . optsEmbeds . value ??
390399 DEFAULT_GLOBAL_SETTINGS . Export [ "Resolve block embeds" ] ;
391400 exportSettings [ "Append referenced node" ] =
392- settings . export . appendRefNodeContext . value ??
401+ exp . appendRefNodeContext . value ??
393402 DEFAULT_GLOBAL_SETTINGS . Export [ "Append referenced node" ] ;
394403 exportSettings [ "Link type" ] =
395- settings . export . linkType . value ||
396- DEFAULT_GLOBAL_SETTINGS . Export [ "Link type" ] ;
404+ exp . linkType . value || DEFAULT_GLOBAL_SETTINGS . Export [ "Link type" ] ;
397405 exportSettings [ "Max filename length" ] =
398- settings . export . maxFilenameLength . value ??
406+ exp . maxFilenameLength . value ??
399407 DEFAULT_GLOBAL_SETTINGS . Export [ "Max filename length" ] ;
400408 exportSettings [ "Frontmatter" ] =
401- settings . export . frontmatter . values ??
402- DEFAULT_GLOBAL_SETTINGS . Export . Frontmatter ;
409+ exp . frontmatter . values ?? DEFAULT_GLOBAL_SETTINGS . Export . Frontmatter ;
403410 if ( keys . length === 1 ) return exportSettings ;
404411 return readPathValue ( exportSettings , keys . slice ( 1 ) ) ;
405412 }
406413
407414 if ( firstKey === "Suggestive mode" ) {
415+ const sm = getSuggestiveModeConfigAndUids ( tree ) ;
408416 const suggestiveModeSettings : Record < string , unknown > = { } ;
409417 suggestiveModeSettings [ "Include current page relations" ] =
410- settings . suggestiveMode . includePageRelations . value ??
418+ sm . includePageRelations . value ??
411419 DEFAULT_GLOBAL_SETTINGS [ "Suggestive mode" ] [
412420 "Include current page relations"
413421 ] ;
414422 suggestiveModeSettings [ "Include parent and child blocks" ] =
415- settings . suggestiveMode . includeParentAndChildren . value ??
423+ sm . includeParentAndChildren . value ??
416424 DEFAULT_GLOBAL_SETTINGS [ "Suggestive mode" ] [
417425 "Include parent and child blocks"
418426 ] ;
419- suggestiveModeSettings [ "Page groups" ] =
420- settings . suggestiveMode . pageGroups . groups . map ( ( group ) => ( {
427+ suggestiveModeSettings [ "Page groups" ] = sm . pageGroups . groups . map (
428+ ( group ) => ( {
421429 name : group . name ,
422430 pages : group . pages . map ( ( page ) => page . name ) ,
423- } ) ) ;
431+ } ) ,
432+ ) ;
424433 if ( keys . length === 1 ) return suggestiveModeSettings ;
425434 return readPathValue ( suggestiveModeSettings , keys . slice ( 1 ) ) ;
426435 }
@@ -728,6 +737,44 @@ export const isNewSettingsStoreEnabled = (): boolean => {
728737 return getFeatureFlag ( "Use new settings store" ) ;
729738} ;
730739
740+ export const readAllLegacyFeatureFlags = ( ) : Partial < FeatureFlags > => {
741+ const flags : Partial < FeatureFlags > = { } ;
742+ for ( const [ key , reader ] of Object . entries ( FEATURE_FLAG_LEGACY_MAP ) ) {
743+ flags [ key as keyof FeatureFlags ] = reader ( ) ;
744+ }
745+ flags [ "Reified relation triples" ] = getSetting < boolean > (
746+ USE_REIFIED_RELATIONS ,
747+ false ,
748+ ) ;
749+ flags [ "Use new settings store" ] = false ;
750+ return flags ;
751+ } ;
752+
753+ export const readAllLegacyGlobalSettings = ( ) : Record < string , unknown > => {
754+ const result : Record < string , unknown > = { } ;
755+ for ( const key of Object . values ( GLOBAL_KEYS ) ) {
756+ result [ key ] = getLegacyGlobalSetting ( [ key ] ) ;
757+ }
758+ return result ;
759+ } ;
760+
761+ export const readAllLegacyPersonalSettings = ( ) : Record < string , unknown > => {
762+ const result : Record < string , unknown > = { } ;
763+ for ( const key of Object . values ( PERSONAL_KEYS ) ) {
764+ result [ key ] = getLegacyPersonalSetting ( [ key ] ) ;
765+ }
766+ return result ;
767+ } ;
768+
769+ export const readAllLegacyDiscourseNodeSettings = (
770+ nodeType : string ,
771+ nodeTitle : string ,
772+ ) : Record < string , unknown > | undefined => {
773+ const raw = getLegacyDiscourseNodeSetting ( nodeType , [ ] ) ;
774+ if ( ! raw || typeof raw !== "object" || Array . isArray ( raw ) ) return undefined ;
775+ return { ...( raw as Record < string , unknown > ) , text : nodeTitle } ;
776+ } ;
777+
731778export const setFeatureFlag = (
732779 key : keyof FeatureFlags ,
733780 value : boolean ,
0 commit comments