|
1 | | -import { NpmPackageLoader, BaseCustomWebcomponentBindingsService, JsonFileElementsService, PropertyGrid, DocumentContainer, CopyPasteAsJsonService, DebugView, UnkownElementsPropertiesService, sleep, RefactorView, BindingsRefactorService, TextRefactorService, SeperatorContextMenu, IDesignItem, DomConverter } from '@node-projects/web-component-designer'; |
| 1 | +import { NpmPackageLoader, BaseCustomWebcomponentBindingsService, JsonFileElementsService, DocumentContainer, CopyPasteAsJsonService, DebugView, UnkownElementsPropertiesService, sleep, RefactorView, BindingsRefactorService, TextRefactorService, SeperatorContextMenu, IDesignItem, DomConverter, PropertyGridWithHeader, DesignItem, ValueType } from '@node-projects/web-component-designer'; |
2 | 2 | import createDefaultServiceContainer from '@node-projects/web-component-designer/dist/elements/services/DefaultServiceBootstrap.js'; |
3 | 3 |
|
4 | 4 | import { NodeHtmlParserService } from '@node-projects/web-component-designer-htmlparserservice-nodehtmlparser'; |
@@ -46,7 +46,7 @@ export class AppShell extends BaseCustomWebComponentConstructorAppend { |
46 | 46 | private _dockManager: DockManager; |
47 | 47 | _paletteTree: PaletteTreeView; |
48 | 48 | _bindableObjectsBrowser: BindableObjectsBrowser |
49 | | - _propertyGrid: PropertyGrid; |
| 49 | + _propertyGrid: PropertyGridWithHeader; |
50 | 50 | _debugView: DebugView; |
51 | 51 | _treeViewExtended: TreeViewExtended; |
52 | 52 | _styleEditor: StyleEditor; |
@@ -188,7 +188,7 @@ export class AppShell extends BaseCustomWebComponentConstructorAppend { |
188 | 188 | this._bindableObjectsBrowser = this._getDomElement<BindableObjectsBrowser>('bindableObjectsBrowser'); |
189 | 189 | this._treeViewExtended = this._getDomElement<TreeViewExtended>('treeViewExtended'); |
190 | 190 | this._refactorView = this._getDomElement<RefactorView>('refactorView'); |
191 | | - this._propertyGrid = this._getDomElement<PropertyGrid>('propertyGrid'); |
| 191 | + this._propertyGrid = this._getDomElement<PropertyGridWithHeader>('propertyGrid'); |
192 | 192 | this._debugView = this._getDomElement<DebugView>('debugView'); |
193 | 193 | this._styleEditor = this._getDomElement<StyleEditor>('styleEditor'); |
194 | 194 |
|
@@ -272,13 +272,83 @@ export class AppShell extends BaseCustomWebComponentConstructorAppend { |
272 | 272 |
|
273 | 273 | await this._setupServiceContainer(); |
274 | 274 | this._bindableObjectsBrowser.initialize(serviceContainer); |
| 275 | + //@ts-ignore |
| 276 | + this._propertyGrid.propertyGrid.propertyGroupHover = (group) => group.properties?.[0]?.styleDeclaration; |
| 277 | + this._propertyGrid.propertyGrid.propertyContextMenuProvider = (designItems, property) => { |
| 278 | + const ctxMenuItems = property.service.getContextMenu(designItems, property); |
| 279 | + if (property.service.isSet(designItems, property) == ValueType.fromStylesheet) { |
| 280 | + ctxMenuItems.push(...[ |
| 281 | + { title: '-' }, |
| 282 | + { |
| 283 | + title: 'jump to declaration', action: () => { |
| 284 | + //@ts-ignore |
| 285 | + let styleDeclaration = property.styleDeclaration; |
| 286 | + if (!styleDeclaration) |
| 287 | + styleDeclaration = designItems[0].getAllStyles().filter(x => x.selector != null).flatMap(x => x.declarations).find(x => x.name == property.name); |
| 288 | + if (styleDeclaration) |
| 289 | + //@ts-ignore |
| 290 | + this.jumpToCss(styleDeclaration.ast, styleDeclaration.stylesheet); |
| 291 | + } |
| 292 | + } |
| 293 | + ]); |
| 294 | + }; |
| 295 | + return ctxMenuItems; |
| 296 | + } |
| 297 | + this._propertyGrid.propertyGrid.propertyGroupClick = (group, mode) => { |
| 298 | + //@ts-ignore |
| 299 | + if (group.properties?.[0]?.styleDeclaration?.ast?.parent) |
| 300 | + //@ts-ignore |
| 301 | + this.jumpToCss(group.properties?.[0]?.styleDeclaration?.ast?.parent, group.properties?.[0]?.styleDeclaration?.stylesheet); |
| 302 | + //} |
| 303 | + }; |
275 | 304 |
|
276 | 305 | this.newDocument(false, code, style); |
277 | 306 |
|
278 | 307 | await sleep(200) |
279 | 308 | this.activateDockById('treeUpper'); |
280 | 309 | } |
281 | 310 |
|
| 311 | + private jumpToCss(styleDeclaration, stylesheet) { |
| 312 | + //@ts-ignore |
| 313 | + const line = styleDeclaration.position?.start?.line; |
| 314 | + //@ts-ignore |
| 315 | + const column = styleDeclaration.position?.start?.column; |
| 316 | + //@ts-ignore |
| 317 | + const lineEnd = styleDeclaration.position?.end?.line; |
| 318 | + //@ts-ignore |
| 319 | + const columnEnd = styleDeclaration.position?.end?.column; |
| 320 | + //@ts-ignore |
| 321 | + if (stylesheet?.designItem) { |
| 322 | + //@ts-ignore |
| 323 | + const di: DesignItem = stylesheet?.designItem; |
| 324 | + let switched = false; |
| 325 | + if (di.instanceServiceContainer.documentContainer.currentView != 'code' && |
| 326 | + di.instanceServiceContainer.documentContainer.currentView != 'split') { |
| 327 | + switched = true; |
| 328 | + di.instanceServiceContainer.documentContainer.currentView = 'split'; |
| 329 | + } |
| 330 | + |
| 331 | + setTimeout(() => { |
| 332 | + let startPos = column; |
| 333 | + let endPos = columnEnd; |
| 334 | + //@ts-ignore |
| 335 | + const cssCode: string = stylesheet?.content; |
| 336 | + const lines = cssCode.split('\n') |
| 337 | + for (let n = 0; n < lineEnd - 1; n++) { |
| 338 | + if (n < line - 1) |
| 339 | + startPos += lines[n].length + 1; |
| 340 | + endPos += lines[n].length + 1; |
| 341 | + } |
| 342 | + const selectionPosition = di.instanceServiceContainer.designItemDocumentPositionService.getPosition(di); |
| 343 | + //TODO: style tag could contain attributes |
| 344 | + const styleLength = '<style>'.length |
| 345 | + di.instanceServiceContainer.documentContainer.codeView.setSelection({ start: startPos + styleLength + selectionPosition.start - 1, length: endPos - startPos }); |
| 346 | + }, switched ? 250 : 0); |
| 347 | + } else { |
| 348 | + this._styleEditor.showLine(line, column, lineEnd, columnEnd); |
| 349 | + } |
| 350 | + } |
| 351 | + |
282 | 352 | private async _setupServiceContainer() { |
283 | 353 | serviceContainer.register('elementsService', new JsonFileElementsService('demo', './dist/elements-demo.json')); |
284 | 354 | serviceContainer.register('elementsService', new JsonFileElementsService('native', rootDir + '/node_modules/@node-projects/web-component-designer/config/elements-native.json')); |
|
0 commit comments