native-document 1.0.205 → 1.0.206

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.205",
3
+ "version": "1.0.206",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -2,6 +2,7 @@ import type { ValidChild, GlobalAttributes, NdStyleMap } from '../../types/eleme
2
2
  import type { ObservableItem } from '../../types/observable';
3
3
  import type { CssPropertyAccumulator, ClassPropertyAccumulator } from '../../types/property-accumulator';
4
4
  import {BaseComponentEvents} from "./BaseComponentEvents";
5
+ import {RefItem} from "../../types/ref";
5
6
 
6
7
  export type EditableProps = Omit<GlobalAttributes, 'class' | 'style'> & {
7
8
  class: ClassPropertyAccumulator;
@@ -11,7 +12,8 @@ export type EditableProps = Omit<GlobalAttributes, 'class' | 'style'> & {
11
12
  export interface BaseComponent extends BaseComponentEvents {
12
13
  setDescription(description: Record<string, unknown>): this;
13
14
  postBuild(callback: (element: HTMLElement) => void): this;
14
- refSelf(target: Record<string, unknown>, name: string): this;
15
+ refSelf(target: RefItem | Record<string, unknown>, name: string): this;
16
+ ref(target: RefItem | Record<string, unknown>, name: string): this;
15
17
  toNdElement(): HTMLElement | DocumentFragment;
16
18
  node(): HTMLElement | DocumentFragment;
17
19
  toJSON(): Record<string, unknown>;
@@ -42,7 +42,9 @@ export default function FieldCollection(name, props = {}) {
42
42
  fieldBuilder: null,
43
43
  renderItem: null,
44
44
  renderAdd: null,
45
+ layout: null,
45
46
  transition: null,
47
+ label: null,
46
48
  props,
47
49
  };
48
50
 
@@ -109,6 +111,18 @@ FieldCollection.prototype.renderItem = function(fn) {
109
111
  return this;
110
112
  };
111
113
 
114
+ /**
115
+ *
116
+ * @param {NdChild} label
117
+ * @return {this}
118
+ */
119
+ FieldCollection.prototype.label = function(label) {
120
+ this.$description.label = label;
121
+ return this;
122
+ };
123
+
124
+ FieldCollection.prototype.title = FieldCollection.prototype.label;
125
+
112
126
  /**
113
127
  * @param {() => NdChild} fn
114
128
  * @returns {this}
@@ -268,6 +282,16 @@ FieldCollection.prototype.max = function(maxCount, message) {
268
282
  );
269
283
  };
270
284
 
285
+ /**
286
+ *
287
+ * @param {({ button: NdChild, rows: NdChild, label: NdChild})} layoutFn
288
+ * @return {this}
289
+ */
290
+ FieldCollection.prototype.layout = function(layoutFn) {
291
+ this.$description.layout = layoutFn;
292
+ return this;
293
+ };
294
+
271
295
  // Override validate
272
296
  /**
273
297
  * @param {*} [allValues]
@@ -20,7 +20,7 @@ export type FieldCollectionDescription = {
20
20
  props: GlobalAttributes;
21
21
  };
22
22
 
23
- export interface FieldCollectionInterface extends BaseComponent, HasValidation {
23
+ export interface FieldCollectionInterface extends Omit<BaseComponent, 'onChange'> , HasValidation {
24
24
  fields(fieldBuilder: (fields: FieldCollectionInterface, index: number) => ValidChild): this;
25
25
  data(defaultItem: unknown): this;
26
26
  renderItem(fn: (item: unknown, index: number) => ValidChild): this;
@@ -40,6 +40,9 @@ export interface FieldCollectionInterface extends BaseComponent, HasValidation {
40
40
  min(minCount: number, message?: string): this;
41
41
  max(maxCount: number, message?: string): this;
42
42
  render(template: (description: FieldCollectionDescription, instance: FieldCollectionInterface) => ValidChild): this;
43
+ label(label: ValidChild): this;
44
+ title(title: ValidChild): this;
45
+ layout(slots: { button: ValidChild, rows: ValidChild, label: ValidChild }): this;
43
46
  }
44
47
 
45
48
 
@@ -1,6 +1,7 @@
1
1
  import {Div, ForEachArray} from '../../../../elements';
2
2
  import {Button} from '../../../components/button';
3
3
  import { $ } from '../../../core/data/Observable';
4
+ import {H2} from '../../../core/elements';
4
5
 
5
6
  import './field-collection.css';
6
7
 
@@ -106,10 +107,23 @@ export default function FieldCollectionRender($desc, instance) {
106
107
  );
107
108
  };
108
109
 
109
- return Div(instance.resolveProps(), [
110
- Div({class: 'field-collection-list'},
111
- ForEachArray($items, buildItem),
112
- ),
113
- buildAddButton(),
114
- ]);
115
- }
110
+ const layout = $desc.layout ?? defaultLayout;
111
+
112
+ const button = buildAddButton();
113
+ const rows = ForEachArray($items, buildItem);
114
+ const label = $desc.label ? H2($desc.label) : null;
115
+
116
+ return Div(instance.resolveProps(), layout({ button, rows, label }));
117
+ }
118
+
119
+
120
+ const defaultLayout = ({ label, button, rows }) => {
121
+
122
+ return [
123
+ Div({ class: 'field-collection-header' }, [
124
+ label,
125
+ button
126
+ ]),
127
+ Div({class: 'field-collection-list'}, rows),
128
+ ];
129
+ };
@@ -4,6 +4,11 @@
4
4
  gap: var(--space-comfortable);
5
5
  }
6
6
 
7
+ .field-collection-header {
8
+ display: flex;
9
+ justify-content: space-between;
10
+ }
11
+
7
12
  .field-collection-list {
8
13
  display: flex;
9
14
  flex-direction: column;
@@ -12,7 +17,8 @@
12
17
 
13
18
  .field-collection-item {
14
19
  display: flex;
15
- align-items: flex-start;
20
+ justify-content: space-between;
21
+ align-items: center;
16
22
  gap: var(--space-cozy);
17
23
  padding: var(--space-comfortable);
18
24
  border: 1px solid var(--field-input-border);
@@ -1,4 +1,5 @@
1
1
  import {BindingHydrator} from "./template-cloner";
2
+ import {RefItem} from "./ref";
2
3
 
3
4
  type ShadowMode = 'open' | 'closed';
4
5
 
@@ -18,8 +19,8 @@ export interface NDElement {
18
19
  readonly $observer: any;
19
20
  readonly nd: this;
20
21
 
21
- ref(target: any, name: string): this;
22
- refSelf(target: any, name: string): this;
22
+ ref(target: RefItem | Record<string, unknown>, name: string): this;
23
+ refSelf(target: RefItem | Record<string, unknown>, name: string): this;
23
24
  with<T extends MethodsObject>(methods: T): this & ExtractMethods<T>;
24
25
  extend(methods: MethodsObject): NDElement;
25
26
  extend<T extends MethodsObject>(