1+ import { settings } from "../settings.ts" ;
12import { dictionary as globalDictionary } from "./global_dictionary.ts" ;
2- import { Definition , Dictionary } from "./type.ts" ;
3+ import { Definition , Dictionary , Entry } from "./type.ts" ;
34
45// all of these global constants are mutable
56
7+ let sandbox = false ;
8+
69const customDictionary : Dictionary = new Map ( ) ;
710export const dictionary : Dictionary = new Map ( ) ;
811
@@ -15,6 +18,12 @@ export const tokiPonaWordSet: Set<string> = new Set();
1518
1619update ( ) ;
1720
21+ export function updateSandboxInclusion ( ) : void {
22+ if ( sandbox !== settings . sandbox ) {
23+ sandbox = settings . sandbox ;
24+ update ( ) ;
25+ }
26+ }
1827export function loadCustomDictionary ( dictionary : Dictionary ) : void {
1928 customDictionary . clear ( ) ;
2029 for ( const [ key , value ] of dictionary ) {
@@ -24,10 +33,14 @@ export function loadCustomDictionary(dictionary: Dictionary): void {
2433}
2534function update ( ) {
2635 dictionary . clear ( ) ;
27- const words = new Set ( [
28- ...globalDictionary . keys ( ) ,
29- ...customDictionary . keys ( ) ,
30- ] ) ;
36+ const words = new Set (
37+ [
38+ ...globalDictionary . entries ( ) ,
39+ ...customDictionary . entries ( ) ,
40+ ]
41+ . filter ( ( [ _ , entry ] ) => ! entry . sandbox || settings . sandbox )
42+ . map ( ( [ word ] ) => word ) ,
43+ ) ;
3144 for ( const word of words ) {
3245 const entry = customDictionary . get ( word ) ?? globalDictionary . get ( word ) ! ;
3346 if ( entry . definitions . length > 0 ) {
0 commit comments