EDITORCLASSBLOGLOGINOpkleOpkle, the Editor for CreatorsInfiniteExpression,In New Forms.New ContentOpkle makes an editor so anyone can build for the web without code, and share it anywhere.Blending text and screen, we build tools that make the web about imagination, not code.Building Opkle Editor: A Spreadsheet for Table Imagesdev17Building Opkle Editor: One Dataset as Table, Board, Calendardev18Building Opkle Editor: A Publisher for Books on the Webdev19Building Opkle Editor: Publishing the Edit View to the Webdev20Building Opkle Editor: How the EPUB Editor Ties It Togetherdev211213141516...17 Building Opkle Editor: A Spreadsheet for Table Images

After building the layout editor, I had to rethink how tables are handled. A table in a publication looks like a single image in the end, but while it is being made, its values, rows and columns, merges, alignment, fonts and borders keep changing. Pixels are only the final sample, and behind them there has to be related data and a set of typesetting rules.

I didn't start by bolting on a feature that draws table images. First I built a calculation model with cells, ranges, types and formulas, and made it regenerate the publishing scene from that state. The source of a table is neither a screen DOM nor an image; it is a sparse document that describes the relationships between coordinates and values. The screen and the output become different projections of that document.

Settling on this structure also made it clear that a plain HTML table isn't enough. Editing needs fast local access, formulas form a dependency graph, saving demands transactions and durability, and output has to compute geometry independent of the browser screen. A table editor is less a grid UI than a small computing environment where a relational model, a type system and sparse matrices meet.

Sparse relation

If a table is treated only like an image object, the very idea of a cell soon falls apart. Changing a single character would mean reinterpreting all the pixels, and sorting or filtering has no meaning on an array of colors. Rows and columns aren't just lines; they are an orthogonal coordinate system of records and attributes. The data came first, and geometry was just one way of showing it.

Mathematically, a sheet can be seen as a partial function defined on the product `R × C` of a row set R and a column set C. Since most cells are empty, a sparse relation that keeps only the coordinates with defined values is more natural than a dense matrix that materializes every coordinate. Cells that carry a style or a formula, not just a value, belong to the support set too. This is why the size of the screen and the size of the actual data are decoupled.

A column is not a mere coordinate but an attribute that shares one domain. A row is a tuple with several attributes, and columns with a role, such as title or date, become part of the schema. The order of rows and columns matters to the user, but it is separate from the identity of the relation. Only if the same tuples and attributes survive a reordering can various projections read the same data.

I also treated a merged cell not as a value duplicated across several slots but as a relation in which a single anchor owns a rectangular region. Merged regions must not overlap, and each region must contain exactly one anchor. Putting such invariants in the data model rather than in geometry lets the screen, the output and pasting all follow the same rules.

Relational document

A living table document fit the relational model well. Cell values, column schema, merges and styles are different relations, but they describe the same document through keys. Instead of rewriting one giant nested object every time, I can update only the tuples that changed, and range selection and sorting can be expressed as selection and ordering operations.

In the schema, I had to be clear about functional dependencies. The cell coordinate `(sheet, row, column)` determines the value and the formula, and the column identity determines the name and type. If two tuples with the same candidate key existed, there would be no telling which value is authoritative. Keys and uniqueness are not storage-technology options; they are part of the document's meaning.

Pushing normalization too far can make joins costly during editing. Conversely, duplicating all information into each cell means that renaming a column or changing a style leaves countless tuples holding different values. Balancing update anomalies against read locality, it made sense to split the relations and keep frequently co-read derived values as a cache projection.

Assets are large values outside the relations, but inside the reference graph they are vertices like any other. Assets owned by the document and assets shared from elsewhere have different lifecycles, and whether something can be deleted is judged by reachability from a root. By looking at relational integrity and graph reachability together, I made sure a change to one table never damages another document's assets.

Gradual type system

A column carries more meaning than a plain coordinate like A, B, C. Numbers, dates, booleans and categorical values allow different operations and have different sort orders. Yet if users had to declare every type up front, the free-form feel of typing into a table would vanish. What I needed was gradual typing, which bridges dynamic input and static schema.

A value whose type isn't settled yet stays as unknown, close to the top type, and a more specific candidate can be inferred from the inputs observed. When combining the types of several values, I look for the least upper bound that accommodates them all. Integers and reals can be merged into number, but dates and arbitrary strings can't be safely narrowed into one. The accidental shape of the first cell must not decide the whole column.

Changing a type is a migration, not an annotation change. I have to tell whether the conversion function `c: A -> B` is a total function defined on every existing value or a partial function that fails on some. Quietly applying a partial coercion leaves a column mixing B with unconverted A. Only by computing the failure set first and letting the user choose does the relationship between schema and actual values stay honest.

A categorical column is like a finite set. A single choice is one element of the set, and a multiple choice is an element of the power set. Renaming an option isn't a simple string replacement; it has to be a bijection that renames an element of the domain. The display color is a projection separate from the value's identity. Keeping type and representation apart let the grid and other views share the same values.

Selection geometry

A cell selection is a region on the integer lattice `Z²`. A single cell is a point, and a rectangular range is a product of closed intervals defined by two endpoints. Separating the pixel rect on screen from the integer coordinates of the data keeps the meaning of a selection intact when zoom and scroll change. The UI overlay is merely the integer region mapped onto the current viewport.

When merged regions exist, a plain rectangular selection becomes a closure operation. If a selection S intersects a merged region M without containing all of M, it is expanded as `S <- bbox(S ∪ M)`, and this repeats as long as the new boundary meets other merges. On a finite sheet S grows monotonically with each iteration, so it reaches a fixed point. The final selection is the smallest rectangle closed under every intersecting merge.

Hidden rows and columns exist in data space but can be treated as intervals of measure zero in display space. By building prefix sums of the cumulative column widths and row heights, I can quickly get a pixel position from a cell coordinate, and conversely find a cell from a pointer position by looking for the lower bound in that cumulative function. Hit testing on a grid with variable sizes was ultimately a search problem on a monotonic array.

Keyboard movement is a state machine with an active point and an anchor. A plain move shifts both together, while extending a range fixes the anchor and changes only the active point. Once text editing begins, the domain of the arrow keys switches from the grid to the string. By making explicit which space the same key operates on in each mode, I kept selection geometry and the text caret from colliding.

Expression state

A cell can hold a displayed value and its original expression at the same time. The formula `=A1+B1` is the source, and the number on screen is the value evaluated against the current dependency graph. If the source were overwritten by the value, the meaning of the next recalculation would be lost. The editing state had to separate the committed expression, the transient input and the evaluated result.

A formula parser turns a string into an abstract syntax tree and resolves cell references into symbols. If each formula cell is a vertex and each reference an edge, the calculation order becomes the topological order of the dependency graph. When a cycle exists, no order can be defined, so it must either be treated as an error or be given explicit iterative semantics. For ordinary spreadsheet calculation, an acyclic graph was the most predictable.

The composing string of a Korean IME is similar to a transient expression. If input that hasn't been finalized is committed to the document source, the same jamo (Korean letter component) can be entered twice, or an intermediate string can slip through to the formula parser. While composing, the value owned by the IME should be shown only on screen, and the source should be updated in a single transaction after the commit transition.

Recalculation can target only the dirty subgraph. When cell x changes, only the dependent set reachable backward from x needs to be re-evaluated, and independent components aren't affected. By binding input commit, graph evaluation and screen projection into one revision boundary, formulas and multilingual input came to live inside the same state model.

Sequence algebra

Copy and fill are operations that map a two-dimensional submatrix to another position. For copying values alone, a translation is enough, but the relative references in a formula have to change with the displacement vector. Once absolute and relative references are distinguished, the coordinate terms of the formula AST can be transformed affinely.

Pasting is the process of merging an external matrix into a typed relation. For each column domain, I have to check that the value belongs to it and that the necessary coercion is total. Whether to reject the whole transaction when some cells fail, or to apply only the parts that can succeed, is an atomicity policy. Making the failure set and the extent of what was applied explicit protects the meaning of the data better than a silent partial success.

Auto-fill is the problem of inferring a generating rule from a short sequence. If the first difference of a numeric sequence `a_n` is constant, I can suspect an arithmetic progression, and if the ratio is constant, a geometric progression. A sequence with a constant second difference can be explained by a quadratic polynomial. But infinitely many generating functions fit a finite sample, so a criterion of Occam's razor is needed to choose the simplest rule.

Dates and text suffixes have their own algebras. Dates differ from plain integer addition because of the calendar's variable month lengths, and strings have to be decomposed into a prefix and a numeric part. When no rule can be inferred, the fill falls back to the most conservative transformation, repetition. Fill is a small automation feature, but it only became a predictable tool once it understood types and the sequence model together.

Sparse style tensor

Cell formatting is data just like values, but most of it is default. It can be seen as a sparse tensor defined on the product `R × C × P` of rows R, columns C and properties P. If only the properties that differ from the default are stored for a given cell, the cost of an empty table doesn't grow with the number of cells. Keeping only the support of a partial function is more natural than duplicating a whole style object.

The final style is obtained by composing the document defaults, the column and row styles and the cell overrides. Each layer is a per-property partial map, and the definition from the nearest scope wins. Identical style sets that recur can be shared like a flyweight, but mutating a shared object directly changes many cells at once. Immutable style values and structural sharing fit well together.

A number format is a function from the original value to a display string. Writing it as `format: Value × Locale × Pattern -> String` means sorting and formulas use the original value, while the screen and the output alone share the same formatter. Reinterpreting the display string as a number loses information because of currency symbols and decimal-point locales. It was a textbook case of separating value from representation.

Mathematically, it is more accurate to treat a border as a property of a grid edge than of a cell. Two adjacent cells share only one edge, and if both cells carry their own stroke, conflicts and double lines appear. Seeing the grid as a planar graph and assigning styles to edges lets merges and outlines be described within the same topology.

Ownership graph

Images and fonts are visible inside cells, but they have a different lifecycle from the value itself. Rather than duplicating a large binary into every cell, it is better to create an asset vertex and let cells hold reference edges to it. The same image can be used by several cells, and styles and output can share the same font vertex. The document becomes a combination of a relational table and an asset graph.

Ownership and reference are not the same thing. Just because document B reads an asset made by document A doesn't mean B gets the right to delete it. Only by distinguishing strong ownership edges from borrowed references can I tell which assets disappear along with the root document when it is deleted. Asset lifecycle was a matter of capability and reachability rather than a simple file list.

While undo points to a past revision, an asset that has vanished from the current screen is still reachable. If only the current revision is marked, values needed for redo get collected too early. The live roots must include not only the current document but also the preserved history and any snapshot being exported. The correctness of garbage collection depended on what is defined as a root.

Fonts affect geometry too. If measurement happens with fallback metrics before the asset is ready, row heights and line breaks change. So resolving a font reference isn't preparing a visual decoration; it is settling an input to layout. Only after certain vertices of the asset graph reach the ready state could the typography projection be regarded as the authoritative result.

Serializability

For undo in table editing, restoring cell values alone wasn't enough. When a column type changes, values, formulas and views are all affected, and inserting a row shifts merges and reference coordinates. A single user command changes several relations, so atomicity like that of an ACID transaction is needed. A state in which only some writes are visible is not a valid table.

If two actions read the same previous revision and each writes its result, a lost update can occur. Serializability has to be guaranteed so that the result is equivalent to some sequential order. The simplest way is to commit commands one at a time, and if more parallelism is wanted, I can check whether the read sets and write sets conflict.

Formula recalculation and view projection are work derived from the base transaction. A result computed against base revision r that arrives late on top of r+1 is a stale result. By attaching the source revision to every derived result and discarding it when it differs from the current revision, the screen never slips back to past values. Even asynchronous rendering needed the same time model as snapshot isolation in a database.

History is movement between committed revisions. Snapshots restore quickly but are large, while an operation log is small but sensitive to inverse operations and schema changes. For compound changes to a table, mixing semantic commands with partial snapshots was the right approach. I separated on-screen responsiveness from durable history, while making both point to the same revision graph.

When Saving Is Done

Saving is finished not at the moment the write function is called but at the moment there is proof that a particular revision has become durable. Excluding transient input on screen and derived values still being computed, the committed base state and the asset graph it needs must form one consistent snapshot. The durability boundary had to be defined independently of the UI lifecycle.

A new revision can appear during saving, so the revision r at the start has to be compared with the current revision at completion. Even if r has become durable, when the current revision is r+1 I can't say the latest state has been saved. Rather than letting concurrent writes race, it is easier to explain the ordering by completing r and then checkpointing the newest revision again.

Closing isn't simply an event that removes the screen; it is a state transition that passes through the last input transaction and a durability barrier. If an unfinalized composition or expression remains, it must first be committed or rolled back, and if saving hasn't succeeded, the previous durable revision must remain valid. I separated the UI going away from the end of the data's lifetime.

I repeatedly reviewed cell input, multiple writing systems, formula dependencies and cycles, type migration, bulk matrix operations, merge closure, the asset graph, consecutive undo and new revisions during saving. I confirmed that the relational source state, the screen projection and the durable snapshot all point to the same revision. The spreadsheet engine, which manages the source of publication tables while you edit them directly, was fully implemented and stabilized.

PreviousListNext
CopyrightAll design outputs and videos on this website are copyrighted by Abstract Cloud and protected under copyright law and related regulations. All content, including web, video, text, cover, and interior designs, is the property of the copyright holder. Unauthorized reproduction, distribution, creation of derivative works, or online sharing without prior consent is strictly prohibited. Violations may result in civil and criminal liability under copyright law. Legitimate purchases and copyright protection preserve creators' rights and fuel better works in return.Copyright: Abstract Cloud | CEO: Bae Changkyu
© Abstract Cloud. All Rights Reserved.
HOMEFAQTerms of ServicePrivacy PolicyRefund PolicySeller Informationhelp@opkle.app
+82 10-2747-3403
Business Name :Abstract Cloud  |  CEO :Bae ChangkyuBusiness Registration Number :249-74-00533E-commerce Registration Number :2025-Uijeongbu Songsan-0634Address :402, 108-dong, 49 Buyong-ro, Uijeongbu-si, Gyeonggi-do, Republic of KoreaAll content, designs, and source code on this website
are copyrighted by Opkle.
Opkle