/
index.js
146 lines (117 loc) · 3.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
/** @typedef {import('../../index').BlockEditorSettings} BlockEditorSettings */
function getMenu( current, defaultMenu ) {
if ( current === false ) {
return false;
}
return defaultMenu;
}
/**
* Apply default settings to the user supplied settings, ensuring we have a full and valid set of settings
*
* @param {BlockEditorSettings} settings - Settings
* @return {BlockEditorSettings}
*/
export default function applyDefaultSettings( settings ) {
const { iso, editor } = settings;
return {
iso: {
// No preferences or persistence
preferencesKey: iso?.preferencesKey ?? null,
persistenceKey: iso?.persistenceKey ?? null,
// No disallowed embeds
disallowEmbed: iso?.disallowEmbed ?? [],
customStores: iso?.customStores ?? [],
// Default to all blocks
blocks: { allowBlocks: iso?.blocks?.allowBlocks ?? [], disallowBlocks: iso?.blocks?.disallowBlocks ?? [] },
// Inserter, undo, and inspector is on, everything else is off
toolbar: {
// @ts-ignore */}
inserter: true,
// @ts-ignore */}
inspector: false,
// @ts-ignore */}
navigation: false,
// @ts-ignore */}
documentInspector: false,
// @ts-ignore */}
undo: true,
// @ts-ignore */}
selectorTool: false,
...( iso?.toolbar ?? {} ),
},
header: iso?.header ?? true,
sidebar: {
inserter: false,
inspector: false,
...( iso?.sidebar ?? {} ),
},
footer: iso?.footer ?? false,
// Nothing appears in the 'more menu'
moreMenu: getMenu( iso?.moreMenu, {
editor: false,
fullscreen: false,
preview: false,
topToolbar: false,
...( iso?.moreMenu ?? {} ),
} ),
// No link menu
linkMenu: iso?.linkMenu ?? [],
// Default to top toolbar
defaultPreferences: {
...( iso?.defaultPreferences ?? {} ),
},
allowApi: iso?.allowApi ?? false,
disableCanvasAnimations: iso?.disableCanvasAnimations ?? false,
// No default pattern
currentPattern: iso?.currentPattern ?? null,
// No patterns
patterns: iso?.patterns ?? [],
},
editor: {
alignWide: true,
disableCustomColors: false,
disableCustomFontSizes: false,
disablePostFormats: true,
titlePlaceholder: __( 'Add title' ),
isRTL: false,
autosaveInterval: 60,
maxUploadFileSize: 0,
// @ts-ignore */}
allowedMimeTypes: [],
styles: [
{
baseURL: '',
__unstableType: 'theme',
css: "body { font-family: 'Noto Serif' }",
},
],
imageSizes: [],
richEditingEnabled: true,
codeEditingEnabled: false,
// @ts-ignore */}
allowedBlockTypes: true,
__experimentalCanUserUseUnfilteredHTML: false,
// Default to no patterns, reusable blocks
__experimentalBlockPatterns: [],
// @ts-ignore */}
reusableBlocks: [],
// Default to fixed top toolbar
fixedToolbar: true,
...editor,
bodyPlaceholder: editor?.bodyPlaceholder ?? __( 'Start writing or type / to choose a block' ),
// @ts-ignore */}
availableLegacyWidgets: {},
hasPermissionsToManageWidgets: false,
// Default to no link suggestions
// @ts-ignore */}
fetchLinkSuggestions: editor?.fetchLinkSuggestions ?? editor?.__experimentalFetchLinkSuggestions
? // @ts-ignore */}
editor?.fetchLinkSuggestions ?? editor?.__experimentalFetchLinkSuggestions
: () => [],
},
};
}