Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/extending/property-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ mw.hook( 'neowiki.registration' ).add( ( registrar ) => {
```

The registration object's shape is defined by
[`PropertyTypeRegistration.ts`](https://github.com/ProfessionalWiki/NeoWiki/blob/master/resources/ext.neowiki/src/domain/PropertyTypeRegistration.ts); every field is required, including
`attributesEditor` even for a type with no configurable attributes. `typeName` must equal the backend
[`PropertyTypeRegistration.ts`](https://github.com/ProfessionalWiki/NeoWiki/blob/master/resources/ext.neowiki/src/domain/PropertyTypeRegistration.ts); every field is required but
`displayAttributesEditor`, including `attributesEditor` even for a type with no configurable attributes. `typeName` must equal the backend
`PropertyType::getTypeName()`; `createPropertyDefinitionFromJson( base, json )` extends the common definition `base`
with the type-specific fields your `PropertyDefinition` class serializes; `label` is a message key your module
registers. The components conform to
[`ValueDisplayContract.ts`](https://github.com/ProfessionalWiki/NeoWiki/blob/master/resources/ext.neowiki/src/components/Value/ValueDisplayContract.ts),
[`ValueInputContract.ts`](https://github.com/ProfessionalWiki/NeoWiki/blob/master/resources/ext.neowiki/src/components/Value/ValueInputContract.ts), and
[`AttributesEditorContract.ts`](https://github.com/ProfessionalWiki/NeoWiki/blob/master/resources/ext.neowiki/src/components/SchemaEditor/Property/AttributesEditorContract.ts).
A `displayAttributesEditor` sets the type's Display Attributes for one Layout, in the Layout editor, and conforms to
[`DisplayAttributesEditorContract.ts`](https://github.com/ProfessionalWiki/NeoWiki/blob/master/resources/ext.neowiki/src/components/LayoutEditor/DisplayAttributes/DisplayAttributesEditorContract.ts);
a type without one offers no Display Attributes to set there.

`icon` is a Codex `Icon`: a stock icon from the
[gallery](https://doc.wikimedia.org/codex/latest/icons/all-icons.html), declared via `CodexModule::getIcons` as
Expand Down
13 changes: 10 additions & 3 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@
"cdxIconDatabase",
"cdxIconSettings",
"cdxIconNext",
"cdxIconReload"
"cdxIconReload",
"cdxIconUndo"
]
}
],
Expand Down Expand Up @@ -943,8 +944,14 @@
"neowiki-layout-editor-description",
"neowiki-layout-editor-description-placeholder",
"neowiki-layout-editor-view-type",
"neowiki-layout-editor-show-all-properties",
"neowiki-layout-editor-shown-count",
"neowiki-layout-editor-show-all",
"neowiki-layout-editor-shown",
"neowiki-layout-editor-hidden",
"neowiki-layout-editor-back-to-properties",
"neowiki-display-attribute-precision-description",
"neowiki-display-attribute-precision-from-schema",
"neowiki-display-attribute-precision-as-entered",
"neowiki-display-attribute-reset",
"neowiki-layout-editor-show-property",
"neowiki-layout-editor-hide-property",
"neowiki-layout-editor-keep-one-shown",
Expand Down
3 changes: 1 addition & 2 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@
"neowiki-layout-editor-description": "Beschreibung",
"neowiki-layout-editor-description-placeholder": "Beschreibung für das Layout eingeben",
"neowiki-layout-editor-view-type": "Ansichtstyp",
"neowiki-layout-editor-show-all-properties": "Alle Eigenschaften anzeigen",
"neowiki-layout-editor-shown-count": "$1 von $2 angezeigt",
"neowiki-layout-editor-show-all": "Alle anzeigen",
"neowiki-layout-editor-show-property": "Eigenschaft anzeigen",
"neowiki-layout-editor-hide-property": "Eigenschaft ausblenden",
"neowiki-layout-editor-keep-one-shown": "Mindestens eine Eigenschaft muss angezeigt werden",
Expand Down
10 changes: 8 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,14 @@
"neowiki-layout-editor-description": "Description",
"neowiki-layout-editor-description-placeholder": "Enter a description for the layout",
"neowiki-layout-editor-view-type": "View type",
"neowiki-layout-editor-show-all-properties": "Show all properties",
"neowiki-layout-editor-shown-count": "$1 of $2 shown",
"neowiki-layout-editor-show-all": "Show all",
"neowiki-layout-editor-shown": "Shown",
"neowiki-layout-editor-hidden": "Hidden",
"neowiki-layout-editor-back-to-properties": "Back to properties",
"neowiki-display-attribute-precision-description": "Digits after the decimal point.",
"neowiki-display-attribute-precision-from-schema": "Empty uses the Schema's precision, $1.",
"neowiki-display-attribute-precision-as-entered": "Empty shows numbers as entered, as the Schema does.",
"neowiki-display-attribute-reset": "Use the Schema's setting",
"neowiki-layout-editor-show-property": "Show property",
"neowiki-layout-editor-hide-property": "Hide property",
"neowiki-layout-editor-keep-one-shown": "At least one property must be shown",
Expand Down
10 changes: 8 additions & 2 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,14 @@
"neowiki-layout-editor-description": "Label for the description field in the layout editor.",
"neowiki-layout-editor-description-placeholder": "Placeholder text for the description field in the layout editor.",
"neowiki-layout-editor-view-type": "Label for the read-only view type field in the layout editor.",
"neowiki-layout-editor-show-all-properties": "Label for the button that reveals all hidden properties, keeping the existing order of the shown ones.",
"neowiki-layout-editor-shown-count": "Header in the display rule editor showing how many properties are visible. $1 is the number shown; $2 is the total number of properties.",
"neowiki-layout-editor-show-all": "Label for the button that reveals all hidden properties, keeping the existing order of the shown ones.",
"neowiki-layout-editor-shown": "Heading in the Layout editor over the properties the Layout shows, followed by how many there are.",
"neowiki-layout-editor-hidden": "Heading in the Layout editor over the properties the Layout leaves out, followed by how many there are.",
"neowiki-layout-editor-back-to-properties": "Label and tooltip of the icon button in the Layout editor that leaves a property's Display Attributes for the list of properties.",
"neowiki-display-attribute-precision-description": "Description of the precision field in the Layout editor, which sets how many digits a Number shows after the decimal point.",
"neowiki-display-attribute-precision-from-schema": "Help text of the precision field in the Layout editor when the property's Schema sets a precision. $1 is that precision.",
"neowiki-display-attribute-precision-as-entered": "Help text of the precision field in the Layout editor when the property's Schema sets no precision, so that numbers show as entered.",
"neowiki-display-attribute-reset": "Label and tooltip of the icon button beside a Display Attribute field in the Layout editor that drops the Layout's own value, so the Schema's applies.",
"neowiki-layout-editor-show-property": "Aria label for the per-row toggle button that makes a hidden property visible in the display rule editor.",
"neowiki-layout-editor-hide-property": "Aria label for the per-row toggle button that hides a visible property in the display rule editor.",
"neowiki-layout-editor-keep-one-shown": "Tooltip on the disabled visibility toggle of the last shown property, explaining that at least one property must remain shown.",
Expand Down
2 changes: 2 additions & 0 deletions resources/ext.neowiki/src/NeoWikiExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import UnregisteredTypeAttributesEditor from '@/components/SchemaEditor/Property
import TextAttributesEditor from '@/components/SchemaEditor/Property/TextAttributesEditor.vue';
import MonolingualTextAttributesEditor from '@/components/SchemaEditor/Property/MonolingualTextAttributesEditor.vue';
import NumberAttributesEditor from '@/components/SchemaEditor/Property/NumberAttributesEditor.vue';
import NumberDisplayAttributesEditor from '@/components/LayoutEditor/DisplayAttributes/NumberDisplayAttributesEditor.vue';
import SelectAttributesEditor from '@/components/SchemaEditor/Property/SelectAttributesEditor.vue';
import UrlAttributesEditor from '@/components/SchemaEditor/Property/UrlAttributesEditor.vue';
import RelationAttributesEditor from '@/components/SchemaEditor/Property/RelationAttributesEditor.vue';
Expand Down Expand Up @@ -123,6 +124,7 @@ export class NeoWikiExtension {
valueDisplayComponent: NumberDisplay,
valueEditor: NumberInput,
attributesEditor: NumberAttributesEditor,
displayAttributesEditor: NumberDisplayAttributesEditor,
label: 'neowiki-property-type-number',
icon: cdxIconMathematics,
} );
Expand Down
9 changes: 9 additions & 0 deletions resources/ext.neowiki/src/TypeSpecificComponentRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface TypeSpecificStuff {
valueDisplayComponent: Component;
valueEditor: Component;
attributesEditor: Component;
displayAttributesEditor?: Component;
label: string;
icon: Icon;
}
Expand Down Expand Up @@ -69,6 +70,14 @@ export class TypeSpecificComponentRegistry {
return this.resolveType( propertyType ).attributesEditor;
}

/**
* Returns a Component following DisplayAttributesEditorContract.ts.
* The builder of the Component is responsible for providing a PropertyDefinition of the correct type.
*/
public getDisplayAttributesEditor( propertyType: string ): Component | undefined {
return this.resolveType( propertyType ).displayAttributesEditor;
}

public getPropertyTypes(): string[] {
return Array.from( this.typeMap.keys() );
}
Expand Down
12 changes: 12 additions & 0 deletions resources/ext.neowiki/src/assets/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,15 @@
.ext-neowiki-editor-dialog-height( @stack-shrink );
max-width: calc( @size-5600 - @stack-shrink );
}

/*
* Pulls a list out of a dialog body's padding to the dialog's edges, for rows that hold the dialog's gutter
* themselves, as EditorListItem's do, so that their hover and selected backgrounds reach the edge.
*/
.ext-neowiki-edge-to-edge-in-dialog() {
margin-inline: -@spacing-100;

@media ( min-width: @min-width-breakpoint-desktop ) {
margin-inline: -@spacing-150;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { PropertyDefinition } from '@/domain/PropertyDefinition';

/**
* An editor gets a new instance for each property it is opened for, so it may take what its fields start with from
* its props once.
*/
export interface DisplayAttributesEditorProps<
T extends PropertyDefinition,
A extends Record<string, unknown> = Record<string, unknown>,
> {
/** The property as its Schema defines it: its Display Attributes apply where the Layout sets none. */
property: T;
/** The Display Attributes the Layout sets for the property. */
displayAttributes: A;
}

export type DisplayAttributesEditorEmits<A extends Record<string, unknown> = Record<string, unknown>> = {
/**
* The Display Attributes to change: a value sets one for the Layout, undefined drops it so that the Schema's
* applies, and one left out stays as it is.
*/
'update:displayAttributes': [ Partial<A> ];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<template>
<CdxField
class="ext-neowiki-number-display-attributes"
:status="message === null ? 'default' : 'error'"
:messages="message === null ? {} : { error: message }"
>
<template #label>
{{ $i18n( 'neowiki-property-editor-precision' ).text() }}
</template>
<template #description>
{{ $i18n( 'neowiki-display-attribute-precision-description' ).text() }}
</template>
<div
ref="inputRow"
class="ext-neowiki-number-display-attributes__input"
>
<NeoNativeInput
:key="resets"
:model-value="precisionInput"
input-type="number"
min="0"
:placeholder="property.precision?.toString()"
@update:model-value="updatePrecision"
@unparseable-change="precisionUnparseable = $event"
/>
<CdxButton
v-if="displayAttributes.precision !== undefined"
weight="quiet"
:aria-label="$i18n( 'neowiki-display-attribute-reset' ).text()"
:title="$i18n( 'neowiki-display-attribute-reset' ).text()"
@click="resetPrecision"
>
<CdxIcon :icon="cdxIconUndo" />
</CdxButton>
</div>
<template #help-text>
<template v-if="property.precision === undefined">
{{ $i18n( 'neowiki-display-attribute-precision-as-entered' ).text() }}
</template>
<template v-else>
{{ $i18n( 'neowiki-display-attribute-precision-from-schema', property.precision ).text() }}
</template>
</template>
</CdxField>
</template>

<script setup lang="ts">
import { computed, nextTick, ref } from 'vue';
import { CdxButton, CdxField, CdxIcon } from '@wikimedia/codex';
import { cdxIconUndo } from '@wikimedia/codex-icons';
import type { NumberProperty } from '@/domain/propertyTypes/Number.ts';
import type { DisplayAttributesEditorEmits, DisplayAttributesEditorProps } from './DisplayAttributesEditorContract.ts';
import NeoNativeInput from '@/components/common/NeoNativeInput.vue';
import { focusFirstValueControl } from '@/components/common/valueControlFocus.ts';

type NumberDisplayAttributes = { precision?: number };

const props = defineProps<DisplayAttributesEditorProps<NumberProperty, NumberDisplayAttributes>>();
const emit = defineEmits<DisplayAttributesEditorEmits<NumberDisplayAttributes>>();

const precisionInput = computed( () => props.displayAttributes.precision?.toString() ?? '' );
const precisionError = ref<string | null>( null );
const precisionUnparseable = ref<string | null>( null );
const message = computed( () => precisionUnparseable.value ?? precisionError.value );

// Text the field cannot read stays in it when the value is emptied, so a reset gives it a new field.
const resets = ref( 0 );
const inputRow = ref<HTMLElement | null>( null );

function updatePrecision( text: string ): void {
if ( text === '' ) {
precisionError.value = null;
emit( 'update:displayAttributes', { precision: undefined } );
return;
}

const precision = Number( text );

if ( precision < 0 ) {
precisionError.value = mw.message( 'neowiki-property-editor-precision-non-negative' ).text();
return;
}

precisionError.value = null;
emit( 'update:displayAttributes', { precision } );
}

async function resetPrecision(): Promise<void> {
precisionUnparseable.value = null;
resets.value++;
updatePrecision( '' );

await nextTick();
focusFirstValueControl( inputRow.value! );
}
</script>

<style lang="less">
@import ( reference ) '@wikimedia/codex-design-tokens/theme-wikimedia-ui.less';

.ext-neowiki-number-display-attributes__input {
display: flex;
align-items: center;
gap: @spacing-50;

.cdx-text-input {
max-width: @size-800;
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<div class="ext-neowiki-display-rule-editor">
<div class="ext-neowiki-display-rule-editor__heading">
<CdxButton
class="ext-neowiki-display-rule-editor__back"
weight="quiet"
:aria-label="$i18n( 'neowiki-layout-editor-back-to-properties' ).text()"
:title="$i18n( 'neowiki-layout-editor-back-to-properties' ).text()"
@click="emit( 'back' )"
>
<CdxIcon :icon="cdxIconArrowPrevious" />
</CdxButton>
<h3 class="ext-neowiki-display-rule-editor__name">
{{ property.name.toString() }}
</h3>
</div>

<div ref="fields">
<component
:is="componentRegistry.getDisplayAttributesEditor( property.type )"
:key="property.name.toString()"
:property="property"
:display-attributes="displayAttributes"
@update:display-attributes="emit( 'update:displayAttributes', $event )"
/>
</div>
</div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CdxButton, CdxIcon } from '@wikimedia/codex';
import { cdxIconArrowPrevious } from '@wikimedia/codex-icons';
import type { PropertyDefinition } from '@/domain/PropertyDefinition.ts';
import { NeoWikiServices } from '@/NeoWikiServices.ts';
import { focusFirstValueControl } from '@/components/common/valueControlFocus.ts';

defineProps<{
property: PropertyDefinition;
displayAttributes: Record<string, unknown>;
}>();

const emit = defineEmits<{
'update:displayAttributes': [ patch: Record<string, unknown> ];
'back': [];
}>();

const componentRegistry = NeoWikiServices.getComponentRegistry();

const fields = ref<HTMLElement | null>( null );

export interface DisplayRuleEditorExposes {
focusFirstField: () => void;
}

defineExpose( {
focusFirstField(): void {
focusFirstValueControl( fields.value! );
}
} );
</script>

<style lang="less">
@import ( reference ) '@wikimedia/codex-design-tokens/theme-wikimedia-ui.less';

.ext-neowiki-display-rule-editor {
display: flex;
flex-direction: column;
gap: @spacing-100;

&__heading {
display: flex;
align-items: center;
gap: @spacing-25;
}

&__name {
margin: 0;
padding: 0;
font-size: @font-size-medium;
font-weight: @font-weight-bold;
}
}
</style>
Loading
Loading