reinit repo with sources from zipped dir

This commit is contained in:
Louis
2025-11-21 09:35:47 +01:00
parent 53580dd312
commit a2725828f5
82 changed files with 28056 additions and 0 deletions

12
packages/models/.babelrc Normal file
View File

@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}

View File

@@ -0,0 +1,7 @@
# @klx/models
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test @klx/models` to execute the unit tests via [Jest](https://jestjs.io).

View File

@@ -0,0 +1,12 @@
import nx from '@nx/eslint-plugin'
import baseConfig from '../../eslint.config.mjs'
export default [
...baseConfig,
...nx.configs['flat/react'],
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
// Override or add rules here
rules: {},
},
]

View File

@@ -0,0 +1,14 @@
{
"name": "@klx/models",
"version": "0.0.1",
"main": "./src/index.ts",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./src/index.ts",
"default": "./src/index.ts"
},
"./package.json": "./package.json"
}
}

View File

@@ -0,0 +1,142 @@
import {action, makeObservable, observable} from 'mobx'
import {IBoardObject, BoardObjectType, IImageIdea, ITextIdea, IIframeIdea} from './idea.type'
import {ID, Point, Size, User} from '../types'
export class Idea implements IBoardObject {
id: ID
author: User
position: Point
size: Size
title: string
color: string
type: BoardObjectType
constructor(data: {
id: ID
author: User
position: Point
size: Size
title: string
content?: string
color: string
type?: BoardObjectType
}) {
this.id = data.id
this.author = data.author
this.position = data.position
this.size = data.size
this.title = data.title
this.color = data.color
this.type = "text"
makeObservable(this, {
position: observable,
size: observable,
updatePosition: action,
updateSize: action,
})
}
updatePosition(x: number, y: number) {
this.position.x = x
this.position.y = y
}
updateSize(width: number, height: number) {
this.size.width = width
this.size.height = height
}
}
// ✅ Implémente IImageIdea + narrowed type
export class ImageIdea extends Idea implements IImageIdea {
url: string
alt: string
override type = 'image' as const
constructor(data: {
id: ID
author: User
position: Point
size: Size
title: string
color: string
url: string
alt: string
}) {
super({...data, type: 'image'})
this.url = data.url
this.alt = data.alt
makeObservable(this, {
url: observable,
alt: observable,
updateUrl: action,
updateAlt: action,
})
}
updateUrl(url: string) {
this.url = url
}
updateAlt(alt: string) {
this.alt = alt
}
}
// ✅ Implémente ITextIdea + narrowed type
export class TextIdea extends Idea implements ITextIdea {
content: string
override type = 'text' as const
constructor(data: {
id: ID
author: User
position: Point
size: Size
title: string
color: string
content: string
}) {
super({...data, type: 'text'})
this.content = data.content
makeObservable(this, {
content: observable,
updateContent: action,
})
}
updateContent(content: string) {
this.content = content
}
}
// ✅ Implémente IIframeIdea + narrowed type
export class IframeIdea extends Idea implements IIframeIdea {
url: string
override type = 'iframe' as const
constructor(data: {
id: ID
author: User
position: Point
size: Size
title: string
color: string
url: string
}) {
super({...data, type: 'iframe'})
this.url = data.url
makeObservable(this, {
url: observable,
updateUrl: action,
})
}
updateUrl(url: string) {
this.url = url
}
}

View File

@@ -0,0 +1,31 @@
import {BaseObject} from '../types'
export type BoardObjectType = 'text' | 'image' | 'iframe'
export type IBoardObject = BaseObject & {
type: BoardObjectType,
title: string,
color: string,
updatePosition(x: number, y: number): void
updateSize(width: number, height: number): void
}
export type ITextIdea = IBoardObject & {
type: 'text'
content?: string
}
export type IImageIdea = IBoardObject & {
type: 'image'
url: string
alt: string
}
export type IIframeIdea = IBoardObject & {
type: 'iframe'
url: string
}
export type BoardObject = ITextIdea | IImageIdea | IIframeIdea

View File

@@ -0,0 +1,3 @@
export {Idea, TextIdea, ImageIdea, IframeIdea} from './idea/Idea'
export type {IBoardObject, IImageIdea, IIframeIdea, ITextIdea, BoardObject} from './idea/idea.type'
export type {ID, Point, Size, BaseObject, User} from './types'

View File

@@ -0,0 +1,25 @@
export type ID = string
export type Point = {
x: number
y: number
}
export type Size = {
width: number
height: number
}
export type User = {
uuid: string
name: string
email: string
job: string
}
export type BaseObject = {
id: ID
author: User
position: Point
size: Size
}

View File

@@ -0,0 +1,10 @@
{
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
],
"extends": "../../tsconfig.base.json"
}

View File

@@ -0,0 +1,28 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"types": ["node", "@nx/react/typings/cssmodule.d.ts", "@nx/react/typings/image.d.ts"],
"rootDir": "src",
"jsx": "react-jsx",
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo"
},
"exclude": [
"out-tsc",
"dist",
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx",
"eslint.config.js",
"eslint.config.cjs",
"eslint.config.mjs"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"],
"references": []
}