-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,115 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
} | ||
|
||
& > .ck-inspector-button { | ||
flex-shrink: 0; | ||
margin-left: .5em; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
export const SET_SCHEMA_CURRENT_DEFINITION_NAME = 'SET_SCHEMA_CURRENT_DEFINITION_NAME'; | ||
|
||
export function setSchemaCurrentDefinitionName( currentSchemaDefinitionName ) { | ||
return { type: SET_SCHEMA_CURRENT_DEFINITION_NAME, currentSchemaDefinitionName }; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { | ||
SET_SCHEMA_CURRENT_DEFINITION_NAME | ||
} from './actions'; | ||
|
||
import { | ||
SET_EDITORS, | ||
SET_CURRENT_EDITOR_NAME, | ||
SET_ACTIVE_INSPECTOR_TAB | ||
} from '../../data/actions'; | ||
|
||
import { | ||
getSchemaTreeDefinition, | ||
getSchemaDefinition | ||
} from './utils'; | ||
|
||
export default function schemaReducer( globalState, schemaState, action ) { | ||
// Performance optimization: don't create the schema state unless necessary. | ||
if ( globalState.ui.activeTab !== 'Schema' ) { | ||
return schemaState; | ||
} | ||
|
||
if ( !schemaState ) { | ||
return getBlankSchemaState( globalState, schemaState ); | ||
} | ||
|
||
switch ( action.type ) { | ||
case SET_SCHEMA_CURRENT_DEFINITION_NAME: | ||
return { | ||
...schemaState, | ||
|
||
currentSchemaDefinition: getSchemaDefinition( globalState, action.currentSchemaDefinitionName ), | ||
currentSchemaDefinitionName: action.currentSchemaDefinitionName | ||
}; | ||
|
||
// * SET_ACTIVE_INSPECTOR_TAB – Because of the performance optimization at the beginning, update the state | ||
// if we're back in the commands tab. | ||
// * UPDATE_MODEL_STATE – An action called by the editorEventObserver for the model document change. | ||
case SET_ACTIVE_INSPECTOR_TAB: | ||
return { | ||
...schemaState, | ||
|
||
currentSchemaDefinition: getSchemaDefinition( globalState, schemaState.currentSchemaDefinitionName ), | ||
treeDefinition: getSchemaTreeDefinition( globalState, schemaState ) | ||
}; | ||
|
||
// Actions related to the external state. | ||
case SET_EDITORS: | ||
case SET_CURRENT_EDITOR_NAME: | ||
return getBlankSchemaState( globalState, schemaState ); | ||
|
||
default: | ||
return schemaState; | ||
} | ||
} | ||
|
||
function getBlankSchemaState( globalState, schemaState = {} ) { | ||
return { | ||
...schemaState, | ||
|
||
currentSchemaDefinitionName: null, | ||
currentSchemaDefinition: null, | ||
treeDefinition: getSchemaTreeDefinition( globalState, schemaState ) | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { | ||
stringifyPropertyList | ||
} from '../../components/utils'; | ||
|
||
const definitionPropertyNames = [ | ||
'isBlock', | ||
'isInline', | ||
'isObject', | ||
'isContent', | ||
'isLimit', | ||
'isSelectable' | ||
]; | ||
|
||
const DOCS_PREFIX_URL = 'https://ckeditor.com/docs/ckeditor5/latest/api/'; | ||
|
||
export function getSchemaDefinition( { editors, currentEditorName }, currentSchemaDefinitionName ) { | ||
if ( !currentSchemaDefinitionName ) { | ||
return null; | ||
} | ||
|
||
const schema = editors.get( currentEditorName ).model.schema; | ||
const definitions = schema.getDefinitions(); | ||
const definition = definitions[ currentSchemaDefinitionName ]; | ||
const properties = {}; | ||
const allowChildren = {}; | ||
const allowIn = {}; | ||
let allowAttributes = {}; | ||
|
||
for ( const propertyName of definitionPropertyNames ) { | ||
// Include only those that are true. | ||
if ( definition[ propertyName ] ) { | ||
properties[ propertyName ] = { | ||
value: definition[ propertyName ] | ||
}; | ||
} | ||
} | ||
|
||
for ( const childName of definition.allowChildren.sort() ) { | ||
allowChildren[ childName ] = { | ||
value: true | ||
}; | ||
} | ||
|
||
for ( const parentName of definition.allowIn.sort() ) { | ||
allowIn[ parentName ] = { | ||
value: true | ||
}; | ||
} | ||
|
||
for ( const attributeName of definition.allowAttributes.sort() ) { | ||
allowAttributes[ attributeName ] = { | ||
value: true | ||
}; | ||
} | ||
|
||
allowAttributes = stringifyPropertyList( allowAttributes ); | ||
|
||
for ( const attributeName in allowAttributes ) { | ||
const attributeProperties = schema.getAttributeProperties( attributeName ); | ||
const subPropertyDefinitions = {}; | ||
|
||
for ( const propertyName in attributeProperties ) { | ||
subPropertyDefinitions[ propertyName ] = { | ||
value: attributeProperties[ propertyName ] | ||
}; | ||
} | ||
|
||
allowAttributes[ attributeName ].subProperties = stringifyPropertyList( subPropertyDefinitions ); | ||
} | ||
|
||
return { | ||
currentSchemaDefinitionName, | ||
type: 'SchemaCompiledItemDefinition', | ||
urls: { | ||
general: DOCS_PREFIX_URL + 'module_engine_model_schema-SchemaCompiledItemDefinition.html', | ||
allowAttributes: DOCS_PREFIX_URL + 'module_engine_model_schema-SchemaItemDefinition.html#member-allowAttributes', | ||
allowChildren: DOCS_PREFIX_URL + 'module_engine_model_schema-SchemaItemDefinition.html#member-allowChildren', | ||
allowIn: DOCS_PREFIX_URL + 'module_engine_model_schema-SchemaItemDefinition.html#member-allowIn' | ||
}, | ||
properties: stringifyPropertyList( properties ), | ||
allowChildren: stringifyPropertyList( allowChildren ), | ||
allowIn: stringifyPropertyList( allowIn ), | ||
allowAttributes, | ||
definition | ||
}; | ||
} | ||
|
||
export function getSchemaTreeDefinition( { editors, currentEditorName } ) { | ||
const editor = editors.get( currentEditorName ); | ||
|
||
if ( !editor ) { | ||
return []; | ||
} | ||
|
||
const list = []; | ||
const definitions = editors.get( currentEditorName ).model.schema.getDefinitions(); | ||
|
||
for ( const definitionName in definitions ) { | ||
list.push( { | ||
name: definitionName, | ||
type: 'element', | ||
children: [], | ||
node: definitionName, | ||
attributes: [], | ||
|
||
presentation: { | ||
isEmpty: true, | ||
cssClass: 'ck-inspector-tree-node_tagless' | ||
} | ||
} ); | ||
} | ||
|
||
return list.sort( ( a, b ) => a.name > b.name ? 1 : -1 ); | ||
} |
Oops, something went wrong.