Skip to content

Commit

Permalink
Adding missing createEmpty method to all editable properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
ren0v committed Feb 8, 2024
1 parent 27349f4 commit 673fdc2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Pages/Properties/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public static function createUnchecked(): self
return new self($property, false);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Checkbox);

return new self($property, false);
}

public static function fromArray(array $array): self
{
/** @psalm-var CheckboxJson $array */
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public static function create(File ...$files): self
return new self($property, $files);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Files);

return new self($property, []);
}

public static function fromArray(array $array): self
{
/** @psalm-var FilesJson $array */
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/MultiSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ private function __construct(
) {
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::MultiSelect);

return new self($property, []);
}

public static function fromIds(string ...$ids): self
{
$metadata = PropertyMetadata::create("", PropertyType::MultiSelect);
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public static function create(User ...$users): self
return new self($property, $users);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::People);

return new self($property, []);
}

public static function fromArray(array $array): self
{
/** @psalm-var PeopleJson $array */
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public static function create(string ...$pageIds): self
return new self($property, $pageIds);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Relation);

return new self($property, []);
}

public static function fromArray(array $array): self
{
/** @psalm-var RelationJson $array */
Expand Down
9 changes: 8 additions & 1 deletion src/Pages/Properties/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ class Status implements PropertyInterface
{
private function __construct(
private readonly PropertyMetadata $metadata,
public readonly StatusOption $option,
public readonly StatusOption|null $option,
) {
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Status);

return new self($property, null);
}

public static function fromId(string $id): self
{
$metadata = PropertyMetadata::create("", PropertyType::Status);
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ private function __construct(
) {
}

public static function createEmpty(): self
{
$property = PropertyMetadata::create("title", PropertyType::Title);

return new self($property, []);
}

/** @psalm-mutation-free */
public static function fromText(RichText ...$title): self
{
Expand Down

0 comments on commit 673fdc2

Please sign in to comment.