Skip to content

Commit 8ce79fe

Browse files
committed
update demo
1 parent 186905a commit 8ce79fe

File tree

5 files changed

+92
-15
lines changed

5 files changed

+92
-15
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"@adobe/css-tools": "4.3.3",
2626
"@doubletrade/lit-datepicker": "^1.0.0",
2727
"@fortawesome/fontawesome-free": "^6.5.2",
28-
"@node-projects/base-custom-webcomponent": "0.26.1",
28+
"@node-projects/base-custom-webcomponent": "0.27.6",
2929
"@node-projects/lean-he-esm": "^3.3.0",
3030
"@node-projects/node-html-parser-esm": "^6.2.0",
31-
"@node-projects/web-component-designer": "^0.1.137",
31+
"@node-projects/web-component-designer": "^0.1.146",
3232
"@node-projects/web-component-designer-codeview-monaco": "^0.1.26",
3333
"@node-projects/web-component-designer-htmlparserservice-nodehtmlparser": "^0.1.10",
3434
"@node-projects/web-component-designer-stylesheetservice-css-tools": "^0.1.4",

src/appShell.ts

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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';
22
import createDefaultServiceContainer from '@node-projects/web-component-designer/dist/elements/services/DefaultServiceBootstrap.js';
33

44
import { NodeHtmlParserService } from '@node-projects/web-component-designer-htmlparserservice-nodehtmlparser';
@@ -46,7 +46,7 @@ export class AppShell extends BaseCustomWebComponentConstructorAppend {
4646
private _dockManager: DockManager;
4747
_paletteTree: PaletteTreeView;
4848
_bindableObjectsBrowser: BindableObjectsBrowser
49-
_propertyGrid: PropertyGrid;
49+
_propertyGrid: PropertyGridWithHeader;
5050
_debugView: DebugView;
5151
_treeViewExtended: TreeViewExtended;
5252
_styleEditor: StyleEditor;
@@ -188,7 +188,7 @@ export class AppShell extends BaseCustomWebComponentConstructorAppend {
188188
this._bindableObjectsBrowser = this._getDomElement<BindableObjectsBrowser>('bindableObjectsBrowser');
189189
this._treeViewExtended = this._getDomElement<TreeViewExtended>('treeViewExtended');
190190
this._refactorView = this._getDomElement<RefactorView>('refactorView');
191-
this._propertyGrid = this._getDomElement<PropertyGrid>('propertyGrid');
191+
this._propertyGrid = this._getDomElement<PropertyGridWithHeader>('propertyGrid');
192192
this._debugView = this._getDomElement<DebugView>('debugView');
193193
this._styleEditor = this._getDomElement<StyleEditor>('styleEditor');
194194

@@ -272,13 +272,83 @@ export class AppShell extends BaseCustomWebComponentConstructorAppend {
272272

273273
await this._setupServiceContainer();
274274
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+
};
275304

276305
this.newDocument(false, code, style);
277306

278307
await sleep(200)
279308
this.activateDockById('treeUpper');
280309
}
281310

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+
282352
private async _setupServiceContainer() {
283353
serviceContainer.register('elementsService', new JsonFileElementsService('demo', './dist/elements-demo.json'));
284354
serviceContainer.register('elementsService', new JsonFileElementsService('native', rootDir + '/node_modules/@node-projects/web-component-designer/config/elements-native.json'));

src/services/customPropertiesService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { IProperty, IPropertiesService, IDesignItem, PropertyType, IBinding } from '@node-projects/web-component-designer';
1+
import { IProperty, IDesignItem, PropertyType, IBinding, AbstractPropertiesService } from '@node-projects/web-component-designer';
22
import { BindingTarget } from '@node-projects/web-component-designer/dist/elements/item/BindingTarget';
33
import { RefreshMode } from '@node-projects/web-component-designer/dist/elements/services/propertiesService/IPropertiesService';
44
import { ValueType } from '@node-projects/web-component-designer/dist/elements/services/propertiesService/ValueType';
55

6-
export class CustomPropertiesService implements IPropertiesService {
6+
export class CustomPropertiesService extends AbstractPropertiesService {
77
getRefreshMode(designItem: IDesignItem) {
88
return RefreshMode.full;
99
}
@@ -31,6 +31,7 @@ export class CustomPropertiesService implements IPropertiesService {
3131
}
3232
getValue(designItems: IDesignItem[], property: IProperty) {
3333
// throw new Error("Method not implemented.");
34+
return null;
3435
}
3536

3637
name: string = "custom";

src/styleEditor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ export class StyleEditor extends BaseCustomWebComponentConstructorAppend {
9494
delete() {
9595
this._editor.trigger('', 'editor.action.clipboardDeleteAction', null)
9696
}
97+
98+
public showLine(line: number, column: number, lineEnd: number, columnEnd: number) {
99+
this._editor.setSelection({ startLineNumber: line, startColumn: column, endLineNumber: lineEnd, endColumn: columnEnd });
100+
//@ts-ignore
101+
this._editor.revealRangeAtTop(new monaco.Range(line, column, lineEnd, columnEnd), 1);
102+
}
97103
}
98104

99105
customElements.define('node-projects-style-editor', StyleEditor);

0 commit comments

Comments
 (0)